Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6
authorLinus Torvalds <torvalds@woody.linux-foundation.org>
Fri, 8 Feb 2008 17:29:39 +0000 (09:29 -0800)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Fri, 8 Feb 2008 17:29:39 +0000 (09:29 -0800)
* git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6:
  [SPARC64]: Make use of the new fs/compat_binfmt_elf.c
  [SPARC64]: Make use of compat_sys_ptrace()

Manually fixed trivial delete/modift conflict in arch/sparc64/kernel/binfmt_elf32.c

991 files changed:
Documentation/DocBook/scsi.tmpl
Documentation/accounting/getdelays.c
Documentation/aoe/mkdevs.sh
Documentation/aoe/udev-install.sh
Documentation/aoe/udev.txt
Documentation/feature-removal-schedule.txt
Documentation/filesystems/isofs.txt
Documentation/filesystems/vfs.txt
Documentation/hwmon/ads7828 [new file with mode: 0644]
Documentation/hwmon/it87
Documentation/hwmon/lm78
Documentation/hwmon/lm87
Documentation/hwmon/userspace-tools
Documentation/hwmon/w83627ehf
Documentation/hwmon/w83627hf
Documentation/hwmon/w83781d
Documentation/hwmon/w83l786ng [new file with mode: 0644]
Documentation/i2c/busses/i2c-piix4
Documentation/kernel-parameters.txt
Documentation/mn10300/ABI.txt [new file with mode: 0644]
Documentation/mn10300/compartmentalisation.txt [new file with mode: 0644]
Documentation/scsi/ChangeLog.arcmsr
Documentation/scsi/scsi_mid_low_api.txt
Documentation/thermal/sysfs-api.txt
Documentation/vm/slabinfo.c
MAINTAINERS
arch/alpha/Kconfig
arch/alpha/kernel/osf_sys.c
arch/alpha/kernel/process.c
arch/alpha/kernel/setup.c
arch/arm/Kconfig
arch/arm/kernel/process.c
arch/avr32/kernel/ocd.c
arch/avr32/mach-at32ap/at32ap700x.c
arch/blackfin/kernel/process.c
arch/blackfin/kernel/setup.c
arch/cris/Kconfig
arch/cris/kernel/setup.c
arch/frv/Kconfig
arch/frv/kernel/setup.c
arch/frv/mm/pgalloc.c
arch/h8300/Kconfig
arch/h8300/kernel/setup.c
arch/ia64/kernel/time.c
arch/m32r/Kconfig
arch/m32r/kernel/setup.c
arch/m68k/Kconfig
arch/m68k/kernel/process.c
arch/m68k/kernel/setup.c
arch/m68k/kernel/traps.c
arch/m68knommu/Kconfig
arch/m68knommu/kernel/setup.c
arch/mips/kernel/i8259.c
arch/mips/kernel/irixelf.c
arch/mips/kernel/irixsig.c
arch/mips/kernel/irq.c
arch/mips/kernel/sysirix.c
arch/mn10300/Kconfig [new file with mode: 0644]
arch/mn10300/Kconfig.debug [new file with mode: 0644]
arch/mn10300/Makefile [new file with mode: 0644]
arch/mn10300/boot/.gitignore [new file with mode: 0644]
arch/mn10300/boot/Makefile [new file with mode: 0644]
arch/mn10300/boot/compressed/Makefile [new file with mode: 0644]
arch/mn10300/boot/compressed/head.S [new file with mode: 0644]
arch/mn10300/boot/compressed/misc.c [new file with mode: 0644]
arch/mn10300/boot/compressed/misc.h [new file with mode: 0644]
arch/mn10300/boot/compressed/vmlinux.lds [new file with mode: 0644]
arch/mn10300/boot/install.sh [new file with mode: 0644]
arch/mn10300/boot/tools/build.c [new file with mode: 0644]
arch/mn10300/configs/asb2303_defconfig [new file with mode: 0644]
arch/mn10300/kernel/Makefile [new file with mode: 0644]
arch/mn10300/kernel/asm-offsets.c [new file with mode: 0644]
arch/mn10300/kernel/entry.S [new file with mode: 0644]
arch/mn10300/kernel/fpu-low.S [new file with mode: 0644]
arch/mn10300/kernel/fpu.c [new file with mode: 0644]
arch/mn10300/kernel/gdb-cache.S [new file with mode: 0644]
arch/mn10300/kernel/gdb-io-serial-low.S [new file with mode: 0644]
arch/mn10300/kernel/gdb-io-serial.c [new file with mode: 0644]
arch/mn10300/kernel/gdb-io-ttysm-low.S [new file with mode: 0644]
arch/mn10300/kernel/gdb-io-ttysm.c [new file with mode: 0644]
arch/mn10300/kernel/gdb-low.S [new file with mode: 0644]
arch/mn10300/kernel/gdb-stub.c [new file with mode: 0644]
arch/mn10300/kernel/head.S [new file with mode: 0644]
arch/mn10300/kernel/init_task.c [new file with mode: 0644]
arch/mn10300/kernel/internal.h [new file with mode: 0644]
arch/mn10300/kernel/io.c [new file with mode: 0644]
arch/mn10300/kernel/irq.c [new file with mode: 0644]
arch/mn10300/kernel/kernel_execve.S [new file with mode: 0644]
arch/mn10300/kernel/kprobes.c [new file with mode: 0644]
arch/mn10300/kernel/kthread.S [new file with mode: 0644]
arch/mn10300/kernel/mn10300-debug.c [new file with mode: 0644]
arch/mn10300/kernel/mn10300-serial-low.S [new file with mode: 0644]
arch/mn10300/kernel/mn10300-serial.c [new file with mode: 0644]
arch/mn10300/kernel/mn10300-serial.h [new file with mode: 0644]
arch/mn10300/kernel/mn10300-watchdog-low.S [new file with mode: 0644]
arch/mn10300/kernel/mn10300-watchdog.c [new file with mode: 0644]
arch/mn10300/kernel/mn10300_ksyms.c [new file with mode: 0644]
arch/mn10300/kernel/module.c [new file with mode: 0644]
arch/mn10300/kernel/process.c [new file with mode: 0644]
arch/mn10300/kernel/profile-low.S [new file with mode: 0644]
arch/mn10300/kernel/profile.c [new file with mode: 0644]
arch/mn10300/kernel/ptrace.c [new file with mode: 0644]
arch/mn10300/kernel/rtc.c [new file with mode: 0644]
arch/mn10300/kernel/semaphore.c [new file with mode: 0644]
arch/mn10300/kernel/setup.c [new file with mode: 0644]
arch/mn10300/kernel/sigframe.h [new file with mode: 0644]
arch/mn10300/kernel/signal.c [new file with mode: 0644]
arch/mn10300/kernel/switch_to.S [new file with mode: 0644]
arch/mn10300/kernel/sys_mn10300.c [new file with mode: 0644]
arch/mn10300/kernel/time.c [new file with mode: 0644]
arch/mn10300/kernel/traps.c [new file with mode: 0644]
arch/mn10300/kernel/vmlinux.lds.S [new file with mode: 0644]
arch/mn10300/lib/Makefile [new file with mode: 0644]
arch/mn10300/lib/__ashldi3.S [new file with mode: 0644]
arch/mn10300/lib/__ashrdi3.S [new file with mode: 0644]
arch/mn10300/lib/__lshrdi3.S [new file with mode: 0644]
arch/mn10300/lib/ashrdi3.c [new file with mode: 0644]
arch/mn10300/lib/bitops.c [new file with mode: 0644]
arch/mn10300/lib/checksum.c [new file with mode: 0644]
arch/mn10300/lib/delay.c [new file with mode: 0644]
arch/mn10300/lib/do_csum.S [new file with mode: 0644]
arch/mn10300/lib/internal.h [new file with mode: 0644]
arch/mn10300/lib/lshrdi3.c [new file with mode: 0644]
arch/mn10300/lib/memcpy.S [new file with mode: 0644]
arch/mn10300/lib/memmove.S [new file with mode: 0644]
arch/mn10300/lib/memset.S [new file with mode: 0644]
arch/mn10300/lib/negdi2.c [new file with mode: 0644]
arch/mn10300/lib/usercopy.c [new file with mode: 0644]
arch/mn10300/mm/Makefile [new file with mode: 0644]
arch/mn10300/mm/cache-flush-mn10300.S [new file with mode: 0644]
arch/mn10300/mm/cache-mn10300.S [new file with mode: 0644]
arch/mn10300/mm/cache.c [new file with mode: 0644]
arch/mn10300/mm/dma-alloc.c [new file with mode: 0644]
arch/mn10300/mm/extable.c [new file with mode: 0644]
arch/mn10300/mm/fault.c [new file with mode: 0644]
arch/mn10300/mm/init.c [new file with mode: 0644]
arch/mn10300/mm/misalignment.c [new file with mode: 0644]
arch/mn10300/mm/mmu-context.c [new file with mode: 0644]
arch/mn10300/mm/pgtable.c [new file with mode: 0644]
arch/mn10300/mm/tlb-mn10300.S [new file with mode: 0644]
arch/mn10300/oprofile/Kconfig [new file with mode: 0644]
arch/mn10300/oprofile/Makefile [new file with mode: 0644]
arch/mn10300/oprofile/op_model_null.c [new file with mode: 0644]
arch/mn10300/proc-mn103e010/Makefile [new file with mode: 0644]
arch/mn10300/proc-mn103e010/proc-init.c [new file with mode: 0644]
arch/mn10300/unit-asb2303/Makefile [new file with mode: 0644]
arch/mn10300/unit-asb2303/flash.c [new file with mode: 0644]
arch/mn10300/unit-asb2303/leds.c [new file with mode: 0644]
arch/mn10300/unit-asb2303/smc91111.c [new file with mode: 0644]
arch/mn10300/unit-asb2303/unit-init.c [new file with mode: 0644]
arch/mn10300/unit-asb2305/Makefile [new file with mode: 0644]
arch/mn10300/unit-asb2305/leds.c [new file with mode: 0644]
arch/mn10300/unit-asb2305/pci-asb2305.c [new file with mode: 0644]
arch/mn10300/unit-asb2305/pci-asb2305.h [new file with mode: 0644]
arch/mn10300/unit-asb2305/pci-iomap.c [new file with mode: 0644]
arch/mn10300/unit-asb2305/pci-irq.c [new file with mode: 0644]
arch/mn10300/unit-asb2305/pci.c [new file with mode: 0644]
arch/mn10300/unit-asb2305/unit-init.c [new file with mode: 0644]
arch/parisc/Kconfig
arch/parisc/kernel/setup.c
arch/powerpc/kernel/asm-offsets.c
arch/powerpc/mm/pgtable_32.c
arch/powerpc/platforms/cell/spufs/file.c
arch/powerpc/platforms/cell/spufs/inode.c
arch/ppc/kernel/setup.c
arch/ppc/mm/pgtable.c
arch/s390/kernel/traps.c
arch/s390/mm/pgtable.c
arch/sh/Kconfig
arch/sh/kernel/cpu/sh4/sq.c
arch/sparc/Kconfig
arch/sparc/kernel/process.c
arch/sparc/kernel/setup.c
arch/sparc/kernel/sparc_ksyms.c
arch/sparc/mm/loadmmu.c
arch/sparc/mm/srmmu.c
arch/sparc/mm/sun4c.c
arch/sparc64/Kconfig
arch/sparc64/kernel/binfmt_aout32.c
arch/sparc64/kernel/irq.c
arch/sparc64/kernel/process.c
arch/sparc64/kernel/setup.c
arch/sparc64/kernel/sparc64_ksyms.c
arch/sparc64/kernel/sys_sparc.c
arch/sparc64/kernel/sys_sparc32.c
arch/sparc64/solaris/misc.c
arch/um/Kconfig
arch/um/Kconfig.i386
arch/um/Kconfig.x86_64
arch/um/Makefile
arch/um/defconfig
arch/um/include/as-layout.h
arch/um/include/os.h
arch/um/include/tempfile.h [deleted file]
arch/um/include/um_mmu.h
arch/um/kernel/exec.c
arch/um/kernel/ksyms.c
arch/um/kernel/mem.c
arch/um/kernel/process.c
arch/um/kernel/skas/mmu.c
arch/um/kernel/um_arch.c
arch/um/os-Linux/aio.c
arch/um/os-Linux/drivers/ethertap_kern.c
arch/um/os-Linux/drivers/tuntap_kern.c
arch/um/os-Linux/include/file.h
arch/um/os-Linux/mem.c
arch/um/os-Linux/process.c
arch/um/os-Linux/signal.c
arch/um/os-Linux/skas/process.c
arch/um/os-Linux/sys-i386/Makefile
arch/um/os-Linux/sys-i386/registers.c
arch/um/os-Linux/sys-i386/task_size.c [new file with mode: 0644]
arch/um/os-Linux/sys-x86_64/Makefile
arch/um/os-Linux/sys-x86_64/registers.c
arch/um/os-Linux/sys-x86_64/task_size.c [new file with mode: 0644]
arch/um/os-Linux/uaccess.c
arch/um/os-Linux/user_syms.c
arch/um/os-Linux/util.c
arch/v850/Kconfig
arch/v850/kernel/procfs.c
arch/x86/Kconfig
arch/x86/kernel/process_32.c
arch/x86/kernel/process_64.c
arch/x86/kernel/setup_64.c
arch/x86/kernel/time_64.c
arch/x86/mm/pgtable_32.c
arch/xtensa/Kconfig
arch/xtensa/kernel/setup.c
drivers/acpi/Kconfig
drivers/acpi/blacklist.c
drivers/acpi/osl.c
drivers/acpi/processor_perflib.c
drivers/block/Kconfig
drivers/block/Makefile
drivers/block/aoe/aoe.h
drivers/block/aoe/aoeblk.c
drivers/block/aoe/aoechr.c
drivers/block/aoe/aoecmd.c
drivers/block/aoe/aoedev.c
drivers/block/aoe/aoemain.c
drivers/block/aoe/aoenet.c
drivers/block/brd.c [new file with mode: 0644]
drivers/block/nbd.c
drivers/block/rd.c [deleted file]
drivers/char/applicom.c
drivers/char/moxa.c
drivers/char/n_tty.c
drivers/char/pcmcia/Kconfig
drivers/char/pcmcia/Makefile
drivers/char/pcmcia/ipwireless/Makefile [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/hardware.c [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/hardware.h [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/main.c [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/main.h [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/network.c [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/network.h [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/setup_protocol.h [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/tty.c [new file with mode: 0644]
drivers/char/pcmcia/ipwireless/tty.h [new file with mode: 0644]
drivers/char/rocket.c
drivers/char/tty_audit.c
drivers/char/tty_io.c
drivers/char/tty_ioctl.c
drivers/firmware/dmi_scan.c
drivers/hwmon/Kconfig
drivers/hwmon/Makefile
drivers/hwmon/abituguru3.c
drivers/hwmon/adm1021.c
drivers/hwmon/adm1025.c
drivers/hwmon/adm1026.c
drivers/hwmon/adm1031.c
drivers/hwmon/adm9240.c
drivers/hwmon/ads7828.c [new file with mode: 0644]
drivers/hwmon/adt7470.c
drivers/hwmon/asb100.c
drivers/hwmon/dme1737.c
drivers/hwmon/ds1621.c
drivers/hwmon/f71805f.c
drivers/hwmon/f71882fg.c
drivers/hwmon/fscher.c
drivers/hwmon/fschmd.c
drivers/hwmon/fscpos.c
drivers/hwmon/gl518sm.c
drivers/hwmon/gl520sm.c
drivers/hwmon/it87.c
drivers/hwmon/lm75.c
drivers/hwmon/lm77.c
drivers/hwmon/lm78.c
drivers/hwmon/lm80.c
drivers/hwmon/lm83.c
drivers/hwmon/lm85.c
drivers/hwmon/lm87.c
drivers/hwmon/lm90.c
drivers/hwmon/lm92.c
drivers/hwmon/pc87360.c
drivers/hwmon/pc87427.c
drivers/hwmon/smsc47b397.c
drivers/hwmon/smsc47m1.c
drivers/hwmon/smsc47m192.c
drivers/hwmon/vt1211.c
drivers/hwmon/vt8231.c
drivers/hwmon/w83627ehf.c
drivers/hwmon/w83627hf.c
drivers/hwmon/w83781d.c
drivers/hwmon/w83791d.c
drivers/hwmon/w83793.c
drivers/hwmon/w83l785ts.c
drivers/hwmon/w83l786ng.c [new file with mode: 0644]
drivers/i2c/chips/eeprom.c
drivers/i2c/chips/pcf8574.c
drivers/i2c/chips/pcf8591.c
drivers/ide/ppc/mpc8xx.c
drivers/input/joystick/analog.c
drivers/isdn/capi/capifs.c
drivers/isdn/hisax/amd7930_fn.c
drivers/leds/Kconfig
drivers/leds/Makefile
drivers/leds/leds-atmel-pwm.c [new file with mode: 0644]
drivers/lguest/lguest_device.c
drivers/md/Kconfig
drivers/md/dm-crypt.c
drivers/md/dm-exception-store.c
drivers/md/dm-ioctl.c
drivers/md/dm-log.c
drivers/md/dm-mpath.c
drivers/md/dm-raid1.c
drivers/md/dm-snap.c
drivers/md/dm-snap.h
drivers/md/dm-stripe.c
drivers/md/dm-table.c
drivers/md/dm.c
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/atmel_pwm.c [new file with mode: 0644]
drivers/misc/enclosure.c [new file with mode: 0644]
drivers/net/Kconfig
drivers/net/smc91x.h
drivers/parport/Kconfig
drivers/parport/ieee1284_ops.c
drivers/pci/Makefile
drivers/pci/intel-iommu.c
drivers/pci/intel-iommu.h
drivers/scsi/Kconfig
drivers/scsi/Makefile
drivers/scsi/NCR53C9x.c [deleted file]
drivers/scsi/NCR53C9x.h [deleted file]
drivers/scsi/aacraid/aachba.c
drivers/scsi/aacraid/commctrl.c
drivers/scsi/aacraid/linit.c
drivers/scsi/advansys.c
drivers/scsi/arcmsr/arcmsr.h
drivers/scsi/arcmsr/arcmsr_hba.c
drivers/scsi/arm/acornscsi.c
drivers/scsi/arm/scsi.h
drivers/scsi/blz1230.c [deleted file]
drivers/scsi/blz2060.c [deleted file]
drivers/scsi/cyberstorm.c [deleted file]
drivers/scsi/cyberstormII.c [deleted file]
drivers/scsi/dc395x.c
drivers/scsi/dec_esp.c [deleted file]
drivers/scsi/fastlane.c [deleted file]
drivers/scsi/iscsi_tcp.c
drivers/scsi/libiscsi.c
drivers/scsi/mac_esp.c [deleted file]
drivers/scsi/mca_53c9x.c [deleted file]
drivers/scsi/oktagon_esp.c [deleted file]
drivers/scsi/oktagon_io.S [deleted file]
drivers/scsi/ps3rom.c
drivers/scsi/qla2xxx/qla_attr.c
drivers/scsi/qla2xxx/qla_def.h
drivers/scsi/qla2xxx/qla_gbl.h
drivers/scsi/qla2xxx/qla_init.c
drivers/scsi/qla2xxx/qla_inline.h
drivers/scsi/qla2xxx/qla_isr.c
drivers/scsi/qla2xxx/qla_mbx.c
drivers/scsi/qla2xxx/qla_os.c
drivers/scsi/qla2xxx/qla_sup.c
drivers/scsi/qla2xxx/qla_version.h
drivers/scsi/qla4xxx/ql4_init.c
drivers/scsi/qla4xxx/ql4_os.c
drivers/scsi/scsi.c
drivers/scsi/scsi_lib.c
drivers/scsi/scsi_transport_iscsi.c
drivers/scsi/sd.c
drivers/scsi/ses.c [new file with mode: 0644]
drivers/scsi/sg.c
drivers/scsi/sr.c
drivers/scsi/sr.h
drivers/scsi/sr_ioctl.c
drivers/scsi/sun3x_esp.c
drivers/scsi/sym53c8xx_2/sym_hipd.c
drivers/scsi/u14-34f.c
drivers/serial/8250.c
drivers/serial/8250_early.c
drivers/serial/8250_gsc.c
drivers/serial/8250_hp300.c
drivers/serial/8250_hub6.c
drivers/serial/8250_pci.c
drivers/serial/Kconfig
drivers/serial/atmel_serial.c
drivers/serial/serial_core.c
drivers/thermal/Kconfig
drivers/thermal/thermal.c
drivers/usb/gadget/net2280.c
drivers/video/console/Kconfig
fs/Kconfig
fs/Kconfig.binfmt
fs/adfs/super.c
fs/affs/super.c
fs/afs/security.c
fs/afs/super.c
fs/aio.c
fs/autofs/inode.c
fs/autofs4/inode.c
fs/befs/linuxvfs.c
fs/binfmt_aout.c
fs/binfmt_elf.c
fs/binfmt_flat.c
fs/binfmt_som.c
fs/buffer.c
fs/char_dev.c
fs/compat_ioctl.c
fs/debugfs/file.c
fs/devpts/inode.c
fs/exec.c
fs/ext2/ext2.h
fs/ext2/super.c
fs/ext3/balloc.c
fs/ext3/ialloc.c
fs/ext3/resize.c
fs/ext3/super.c
fs/ext3/xattr.c
fs/fat/inode.c
fs/fcntl.c
fs/file_table.c
fs/fs-writeback.c
fs/fuse/inode.c
fs/hfsplus/unicode.c
fs/hostfs/hostfs_kern.c
fs/hpfs/super.c
fs/hugetlbfs/inode.c
fs/inotify_user.c
fs/isofs/inode.c
fs/isofs/isofs.h
fs/jbd/commit.c
fs/libfs.c
fs/locks.c
fs/namei.c
fs/namespace.c
fs/ncpfs/inode.c
fs/nfs/write.c
fs/ocfs2/cluster/endian.h [deleted file]
fs/ocfs2/cluster/nodemanager.c
fs/ocfs2/dlm/dlmast.c
fs/ocfs2/endian.h [deleted file]
fs/ocfs2/ocfs2.h
fs/open.c
fs/pipe.c
fs/proc/array.c
fs/proc/base.c
fs/proc/generic.c
fs/proc/inode.c
fs/proc/internal.h
fs/proc/kcore.c
fs/proc/nommu.c
fs/proc/proc_misc.c
fs/proc/proc_net.c
fs/proc/proc_sysctl.c
fs/proc/proc_tty.c
fs/proc/root.c
fs/proc/task_mmu.c
fs/proc/task_nommu.c
fs/proc/vmcore.c
fs/read_write.c
fs/reiserfs/procfs.c
fs/reiserfs/super.c
fs/splice.c
fs/super.c
fs/udf/balloc.c
fs/udf/crc.c
fs/udf/dir.c
fs/udf/directory.c
fs/udf/file.c
fs/udf/ialloc.c
fs/udf/inode.c
fs/udf/misc.c
fs/udf/namei.c
fs/udf/partition.c
fs/udf/super.c
fs/udf/symlink.c
fs/udf/truncate.c
fs/udf/udf_i.h
fs/udf/udf_sb.h
fs/udf/udfdecl.h
fs/udf/udftime.c
fs/udf/unicode.c
fs/ufs/balloc.c
fs/ufs/cylinder.c
fs/ufs/dir.c
fs/ufs/file.c
fs/ufs/ialloc.c
fs/ufs/inode.c
fs/ufs/namei.c
fs/ufs/super.c
fs/ufs/symlink.c
fs/ufs/truncate.c
fs/ufs/ufs_fs.h [moved from include/linux/ufs_fs.h with 99% similarity]
fs/ufs/util.c
fs/xfs/Makefile-linux-2.6
fs/xfs/linux-2.6/spin.h [deleted file]
fs/xfs/linux-2.6/xfs_aops.c
fs/xfs/linux-2.6/xfs_buf.c
fs/xfs/linux-2.6/xfs_buf.h
fs/xfs/linux-2.6/xfs_export.c
fs/xfs/linux-2.6/xfs_file.c
fs/xfs/linux-2.6/xfs_globals.c
fs/xfs/linux-2.6/xfs_ioctl.c
fs/xfs/linux-2.6/xfs_ioctl32.c
fs/xfs/linux-2.6/xfs_iops.c
fs/xfs/linux-2.6/xfs_linux.h
fs/xfs/linux-2.6/xfs_lrw.c
fs/xfs/linux-2.6/xfs_lrw.h
fs/xfs/linux-2.6/xfs_super.c
fs/xfs/linux-2.6/xfs_vnode.c
fs/xfs/linux-2.6/xfs_vnode.h
fs/xfs/quota/xfs_dquot.c
fs/xfs/quota/xfs_dquot.h
fs/xfs/quota/xfs_dquot_item.c
fs/xfs/quota/xfs_qm.c
fs/xfs/quota/xfs_qm.h
fs/xfs/quota/xfs_qm_syscalls.c
fs/xfs/support/debug.c
fs/xfs/support/ktrace.c
fs/xfs/support/ktrace.h
fs/xfs/support/uuid.c
fs/xfs/xfs.h
fs/xfs/xfs_acl.c
fs/xfs/xfs_acl.h
fs/xfs/xfs_ag.h
fs/xfs/xfs_alloc.c
fs/xfs/xfs_attr.c
fs/xfs/xfs_attr_leaf.c
fs/xfs/xfs_bit.c
fs/xfs/xfs_bit.h
fs/xfs/xfs_bmap.c
fs/xfs/xfs_bmap.h
fs/xfs/xfs_bmap_btree.c
fs/xfs/xfs_btree.h
fs/xfs/xfs_buf_item.c
fs/xfs/xfs_buf_item.h
fs/xfs/xfs_da_btree.c
fs/xfs/xfs_da_btree.h
fs/xfs/xfs_dfrag.c
fs/xfs/xfs_dinode.h
fs/xfs/xfs_dir2.c
fs/xfs/xfs_error.c
fs/xfs/xfs_error.h
fs/xfs/xfs_extfree_item.c
fs/xfs/xfs_filestream.c
fs/xfs/xfs_fs.h
fs/xfs/xfs_fsops.c
fs/xfs/xfs_ialloc_btree.h
fs/xfs/xfs_iget.c
fs/xfs/xfs_inode.c
fs/xfs/xfs_inode.h
fs/xfs/xfs_inode_item.c
fs/xfs/xfs_iocore.c [deleted file]
fs/xfs/xfs_iomap.c
fs/xfs/xfs_iomap.h
fs/xfs/xfs_itable.c
fs/xfs/xfs_log.c
fs/xfs/xfs_log.h
fs/xfs/xfs_log_priv.h
fs/xfs/xfs_log_recover.c
fs/xfs/xfs_mount.c
fs/xfs/xfs_mount.h
fs/xfs/xfs_mru_cache.c
fs/xfs/xfs_qmops.c
fs/xfs/xfs_rename.c
fs/xfs/xfs_rtalloc.c
fs/xfs/xfs_rtalloc.h
fs/xfs/xfs_rw.h
fs/xfs/xfs_trans.c
fs/xfs/xfs_trans.h
fs/xfs/xfs_trans_ail.c
fs/xfs/xfs_trans_item.c
fs/xfs/xfs_trans_priv.h
fs/xfs/xfs_utils.c
fs/xfs/xfs_utils.h
fs/xfs/xfs_vfsops.c
fs/xfs/xfs_vfsops.h
fs/xfs/xfs_vnodeops.c
fs/xfs/xfs_vnodeops.h
include/asm-alpha/a.out-core.h [new file with mode: 0644]
include/asm-alpha/a.out.h
include/asm-alpha/page.h
include/asm-alpha/param.h
include/asm-alpha/pgalloc.h
include/asm-alpha/processor.h
include/asm-arm/a.out-core.h [new file with mode: 0644]
include/asm-arm/a.out.h
include/asm-arm/mutex.h
include/asm-arm/page.h
include/asm-arm/pgalloc.h
include/asm-arm/posix_types.h
include/asm-arm/processor.h
include/asm-avr32/a.out.h
include/asm-avr32/arch-at32ap/board.h
include/asm-avr32/page.h
include/asm-avr32/pgalloc.h
include/asm-avr32/posix_types.h
include/asm-avr32/processor.h
include/asm-blackfin/a.out.h
include/asm-blackfin/posix_types.h
include/asm-blackfin/processor.h
include/asm-cris/a.out.h
include/asm-cris/page.h
include/asm-cris/param.h
include/asm-cris/pgalloc.h
include/asm-cris/posix_types.h
include/asm-cris/processor.h
include/asm-frv/a.out.h [deleted file]
include/asm-frv/page.h
include/asm-frv/param.h
include/asm-frv/pgalloc.h
include/asm-frv/posix_types.h
include/asm-generic/Kbuild.asm
include/asm-generic/iomap.h
include/asm-generic/mutex-dec.h
include/asm-generic/mutex-xchg.h
include/asm-generic/termios.h
include/asm-h8300/a.out.h
include/asm-h8300/param.h
include/asm-h8300/posix_types.h
include/asm-h8300/processor.h
include/asm-ia64/a.out.h
include/asm-ia64/page.h
include/asm-ia64/pgalloc.h
include/asm-m32r/a.out.h
include/asm-m32r/page.h
include/asm-m32r/param.h
include/asm-m32r/pgalloc.h
include/asm-m32r/posix_types.h
include/asm-m32r/processor.h
include/asm-m68k/a.out-core.h [new file with mode: 0644]
include/asm-m68k/a.out.h
include/asm-m68k/motorola_pgalloc.h
include/asm-m68k/page.h
include/asm-m68k/param.h
include/asm-m68k/posix_types.h
include/asm-m68k/processor.h
include/asm-m68k/sun3_pgalloc.h
include/asm-m68knommu/param.h
include/asm-mips/a.out.h
include/asm-mips/page.h
include/asm-mips/pgalloc.h
include/asm-mips/posix_types.h
include/asm-mips/processor.h
include/asm-mn10300/.gitignore [new file with mode: 0644]
include/asm-mn10300/Kbuild [new file with mode: 0644]
include/asm-mn10300/atomic.h [new file with mode: 0644]
include/asm-mn10300/auxvec.h [new file with mode: 0644]
include/asm-mn10300/bitops.h [new file with mode: 0644]
include/asm-mn10300/bug.h [new file with mode: 0644]
include/asm-mn10300/bugs.h [new file with mode: 0644]
include/asm-mn10300/busctl-regs.h [new file with mode: 0644]
include/asm-mn10300/byteorder.h [new file with mode: 0644]
include/asm-mn10300/cache.h [new file with mode: 0644]
include/asm-mn10300/cacheflush.h [new file with mode: 0644]
include/asm-mn10300/checksum.h [new file with mode: 0644]
include/asm-mn10300/cpu-regs.h [new file with mode: 0644]
include/asm-mn10300/cputime.h [new file with mode: 0644]
include/asm-mn10300/current.h [new file with mode: 0644]
include/asm-mn10300/delay.h [new file with mode: 0644]
include/asm-mn10300/device.h [new file with mode: 0644]
include/asm-mn10300/div64.h [new file with mode: 0644]
include/asm-mn10300/dma-mapping.h [new file with mode: 0644]
include/asm-mn10300/dma.h [new file with mode: 0644]
include/asm-mn10300/dmactl-regs.h [new file with mode: 0644]
include/asm-mn10300/elf.h [new file with mode: 0644]
include/asm-mn10300/emergency-restart.h [new file with mode: 0644]
include/asm-mn10300/errno.h [new file with mode: 0644]
include/asm-mn10300/exceptions.h [new file with mode: 0644]
include/asm-mn10300/fb.h [new file with mode: 0644]
include/asm-mn10300/fcntl.h [new file with mode: 0644]
include/asm-mn10300/fpu.h [new file with mode: 0644]
include/asm-mn10300/frame.inc [new file with mode: 0644]
include/asm-mn10300/futex.h [new file with mode: 0644]
include/asm-mn10300/gdb-stub.h [new file with mode: 0644]
include/asm-mn10300/hardirq.h [new file with mode: 0644]
include/asm-mn10300/highmem.h [new file with mode: 0644]
include/asm-mn10300/hw_irq.h [new file with mode: 0644]
include/asm-mn10300/ide.h [new file with mode: 0644]
include/asm-mn10300/intctl-regs.h [new file with mode: 0644]
include/asm-mn10300/io.h [new file with mode: 0644]
include/asm-mn10300/ioctl.h [new file with mode: 0644]
include/asm-mn10300/ioctls.h [new file with mode: 0644]
include/asm-mn10300/ipc.h [new file with mode: 0644]
include/asm-mn10300/ipcbuf.h [new file with mode: 0644]
include/asm-mn10300/irq.h [new file with mode: 0644]
include/asm-mn10300/irq_regs.h [new file with mode: 0644]
include/asm-mn10300/kdebug.h [new file with mode: 0644]
include/asm-mn10300/kmap_types.h [new file with mode: 0644]
include/asm-mn10300/kprobes.h [new file with mode: 0644]
include/asm-mn10300/linkage.h [new file with mode: 0644]
include/asm-mn10300/local.h [new file with mode: 0644]
include/asm-mn10300/mc146818rtc.h [new file with mode: 0644]
include/asm-mn10300/mman.h [new file with mode: 0644]
include/asm-mn10300/mmu.h [new file with mode: 0644]
include/asm-mn10300/mmu_context.h [new file with mode: 0644]
include/asm-mn10300/module.h [new file with mode: 0644]
include/asm-mn10300/msgbuf.h [new file with mode: 0644]
include/asm-mn10300/mutex.h [new file with mode: 0644]
include/asm-mn10300/namei.h [new file with mode: 0644]
include/asm-mn10300/nmi.h [new file with mode: 0644]
include/asm-mn10300/page.h [new file with mode: 0644]
include/asm-mn10300/page_offset.h [new file with mode: 0644]
include/asm-mn10300/param.h [new file with mode: 0644]
include/asm-mn10300/pci.h [new file with mode: 0644]
include/asm-mn10300/percpu.h [new file with mode: 0644]
include/asm-mn10300/pgalloc.h [new file with mode: 0644]
include/asm-mn10300/pgtable.h [new file with mode: 0644]
include/asm-mn10300/pio-regs.h [new file with mode: 0644]
include/asm-mn10300/poll.h [new file with mode: 0644]
include/asm-mn10300/posix_types.h [new file with mode: 0644]
include/asm-mn10300/proc-mn103e010/cache.h [new file with mode: 0644]
include/asm-mn10300/proc-mn103e010/clock.h [new file with mode: 0644]
include/asm-mn10300/proc-mn103e010/irq.h [new file with mode: 0644]
include/asm-mn10300/proc-mn103e010/proc.h [new file with mode: 0644]
include/asm-mn10300/processor.h [new file with mode: 0644]
include/asm-mn10300/ptrace.h [new file with mode: 0644]
include/asm-mn10300/reset-regs.h [new file with mode: 0644]
include/asm-mn10300/resource.h [new file with mode: 0644]
include/asm-mn10300/rtc-regs.h [new file with mode: 0644]
include/asm-mn10300/rtc.h [new file with mode: 0644]
include/asm-mn10300/scatterlist.h [new file with mode: 0644]
include/asm-mn10300/sections.h [new file with mode: 0644]
include/asm-mn10300/semaphore.h [new file with mode: 0644]
include/asm-mn10300/sembuf.h [new file with mode: 0644]
include/asm-mn10300/serial-regs.h [new file with mode: 0644]
include/asm-mn10300/serial.h [new file with mode: 0644]
include/asm-mn10300/setup.h [new file with mode: 0644]
include/asm-mn10300/shmbuf.h [new file with mode: 0644]
include/asm-mn10300/shmparam.h [new file with mode: 0644]
include/asm-mn10300/sigcontext.h [new file with mode: 0644]
include/asm-mn10300/siginfo.h [new file with mode: 0644]
include/asm-mn10300/signal.h [new file with mode: 0644]
include/asm-mn10300/smp.h [new file with mode: 0644]
include/asm-mn10300/socket.h [new file with mode: 0644]
include/asm-mn10300/sockios.h [new file with mode: 0644]
include/asm-mn10300/spinlock.h [new file with mode: 0644]
include/asm-mn10300/stat.h [new file with mode: 0644]
include/asm-mn10300/statfs.h [new file with mode: 0644]
include/asm-mn10300/string.h [new file with mode: 0644]
include/asm-mn10300/system.h [new file with mode: 0644]
include/asm-mn10300/termbits.h [new file with mode: 0644]
include/asm-mn10300/termios.h [new file with mode: 0644]
include/asm-mn10300/thread_info.h [new file with mode: 0644]
include/asm-mn10300/timer-regs.h [new file with mode: 0644]
include/asm-mn10300/timex.h [new file with mode: 0644]
include/asm-mn10300/tlb.h [new file with mode: 0644]
include/asm-mn10300/tlbflush.h [new file with mode: 0644]
include/asm-mn10300/topology.h [new file with mode: 0644]
include/asm-mn10300/types.h [new file with mode: 0644]
include/asm-mn10300/uaccess.h [new file with mode: 0644]
include/asm-mn10300/ucontext.h [new file with mode: 0644]
include/asm-mn10300/unaligned.h [new file with mode: 0644]
include/asm-mn10300/unistd.h [new file with mode: 0644]
include/asm-mn10300/unit-asb2303/clock.h [new file with mode: 0644]
include/asm-mn10300/unit-asb2303/leds.h [new file with mode: 0644]
include/asm-mn10300/unit-asb2303/serial.h [new file with mode: 0644]
include/asm-mn10300/unit-asb2303/smc91111.h [new file with mode: 0644]
include/asm-mn10300/unit-asb2303/timex.h [new file with mode: 0644]
include/asm-mn10300/unit-asb2305/clock.h [new file with mode: 0644]
include/asm-mn10300/unit-asb2305/leds.h [new file with mode: 0644]
include/asm-mn10300/unit-asb2305/serial.h [new file with mode: 0644]
include/asm-mn10300/unit-asb2305/timex.h [new file with mode: 0644]
include/asm-mn10300/user.h [new file with mode: 0644]
include/asm-mn10300/vga.h [new file with mode: 0644]
include/asm-mn10300/xor.h [new file with mode: 0644]
include/asm-parisc/a.out.h
include/asm-parisc/page.h
include/asm-parisc/pgalloc.h
include/asm-parisc/posix_types.h
include/asm-parisc/processor.h
include/asm-powerpc/a.out.h
include/asm-powerpc/page.h
include/asm-powerpc/pgalloc-32.h
include/asm-powerpc/pgalloc-64.h
include/asm-powerpc/posix_types.h
include/asm-powerpc/processor.h
include/asm-ppc/pgalloc.h
include/asm-s390/a.out.h
include/asm-s390/ioctls.h
include/asm-s390/page.h
include/asm-s390/pgalloc.h
include/asm-s390/processor.h
include/asm-s390/termbits.h
include/asm-s390/termios.h
include/asm-s390/tlb.h
include/asm-sh/a.out.h
include/asm-sh/page.h
include/asm-sh/pgalloc.h
include/asm-sh/processor_32.h
include/asm-sh/processor_64.h
include/asm-sparc/a.out-core.h [new file with mode: 0644]
include/asm-sparc/a.out.h
include/asm-sparc/page.h
include/asm-sparc/param.h
include/asm-sparc/pgalloc.h
include/asm-sparc/posix_types.h
include/asm-sparc/processor.h
include/asm-sparc/uaccess.h
include/asm-sparc64/a.out-core.h [new file with mode: 0644]
include/asm-sparc64/a.out.h
include/asm-sparc64/page.h
include/asm-sparc64/pgalloc.h
include/asm-sparc64/posix_types.h
include/asm-sparc64/processor.h
include/asm-sparc64/uaccess.h
include/asm-sparc64/user.h
include/asm-um/a.out-core.h [new file with mode: 0644]
include/asm-um/a.out.h
include/asm-um/fixmap.h
include/asm-um/page.h
include/asm-um/pgalloc.h
include/asm-um/processor-generic.h
include/asm-um/processor-x86_64.h
include/asm-v850/anna.h
include/asm-v850/as85ep1.h
include/asm-v850/fpga85e2c.h
include/asm-v850/param.h
include/asm-v850/posix_types.h
include/asm-v850/rte_cb.h
include/asm-v850/sim.h
include/asm-v850/sim85e2.h
include/asm-x86/a.out-core.h [new file with mode: 0644]
include/asm-x86/a.out.h
include/asm-x86/page_32.h
include/asm-x86/page_64.h
include/asm-x86/pgalloc_32.h
include/asm-x86/pgalloc_64.h
include/asm-x86/posix_types_32.h
include/asm-x86/processor.h
include/asm-xtensa/a.out.h
include/asm-xtensa/page.h
include/asm-xtensa/param.h
include/asm-xtensa/pgalloc.h
include/asm-xtensa/posix_types.h
include/asm-xtensa/processor.h
include/linux/Kbuild
include/linux/a.out.h
include/linux/atmel_pwm.h [new file with mode: 0644]
include/linux/byteorder/generic.h
include/linux/cpuset.h
include/linux/device-mapper.h
include/linux/dm-ioctl.h
include/linux/dmar.h
include/linux/dmi.h
include/linux/elf-em.h
include/linux/enclosure.h [new file with mode: 0644]
include/linux/fs.h
include/linux/hrtimer.h
include/linux/hugetlb.h
include/linux/i2c-id.h
include/linux/ipc.h
include/linux/ipc_namespace.h [new file with mode: 0644]
include/linux/irq.h
include/linux/jiffies.h
include/linux/kernel.h
include/linux/ktime.h
include/linux/mm.h
include/linux/mm_types.h
include/linux/module.h
include/linux/mutex.h
include/linux/nbd.h
include/linux/pfkeyv2.h
include/linux/pid.h
include/linux/pid_namespace.h
include/linux/preempt.h
include/linux/proc_fs.h
include/linux/ptrace.h
include/linux/rcupreempt.h
include/linux/reiserfs_fs.h
include/linux/sched.h
include/linux/serial_core.h
include/linux/shmem_fs.h
include/linux/signal.h
include/linux/slub_def.h
include/linux/spinlock.h
include/linux/time.h
include/linux/timer.h
include/linux/types.h
include/linux/udf_fs.h
include/linux/udf_fs_sb.h
include/linux/utsname.h
include/net/ip6_fib.h
include/net/ip6_route.h
include/net/netfilter/nf_conntrack_extend.h
include/net/tipc/tipc_msg.h
include/scsi/iscsi_proto.h
include/scsi/libiscsi.h
include/scsi/scsi.h
include/scsi/scsi_host.h
include/scsi/scsi_transport_iscsi.h
init/Kconfig
init/main.c
ipc/Makefile
ipc/ipc_sysctl.c
ipc/mqueue.c
ipc/msg.c
ipc/namespace.c [new file with mode: 0644]
ipc/sem.c
ipc/shm.c
ipc/util.c
ipc/util.h
kernel/Makefile
kernel/cpu.c
kernel/cpuset.c
kernel/exit.c
kernel/fork.c
kernel/irq/chip.c
kernel/irq/handle.c
kernel/itimer.c
kernel/module.c
kernel/mutex-debug.c
kernel/mutex.c
kernel/nsproxy.c
kernel/params.c
kernel/pid.c
kernel/pid_namespace.c [new file with mode: 0644]
kernel/posix-cpu-timers.c
kernel/posix-timers.c
kernel/printk.c
kernel/profile.c
kernel/ptrace.c
kernel/rtmutex-debug.c
kernel/rtmutex_common.h
kernel/sched.c
kernel/signal.c
kernel/softirq.c
kernel/sys.c
kernel/sysctl.c
kernel/sysctl_check.c
kernel/time.c
kernel/time/clockevents.c
kernel/time/clocksource.c
kernel/time/tick-sched.c
kernel/time/timekeeping.c
kernel/timeconst.pl [new file with mode: 0644]
kernel/timer.c
kernel/user.c
kernel/user_namespace.c
kernel/wait.c
kernel/workqueue.c
lib/Kconfig.debug
lib/fault-inject.c
lib/iomap.c
lib/rwsem-spinlock.c
lib/semaphore-sleepers.c
lib/vsprintf.c
mm/filemap.c
mm/filemap_xip.c
mm/hugetlb.c
mm/memory.c
mm/page_alloc.c
mm/shmem.c
mm/slub.c
mm/vmalloc.c
net/Kconfig
net/can/af_can.c
net/can/raw.c
net/core/flow.c
net/decnet/dn_route.c
net/ipv4/netfilter/nf_nat_core.c
net/ipv4/route.c
net/iucv/af_iucv.c
net/iucv/iucv.c
net/netfilter/nf_conntrack_extend.c
net/netfilter/nf_conntrack_proto_tcp.c
net/netfilter/xt_iprange.c
net/sched/em_meta.c
net/tipc/addr.h
net/tipc/bcast.h
net/tipc/msg.h
net/tipc/socket.c
net/xfrm/xfrm_algo.c
scripts/checkpatch.pl
sound/oss/swarm_cs4297a.c
sound/oss/trident.c
virt/kvm/kvm_main.c

index f299ab182bbe0551e6f2c5bf9bb1cd4b1910d7d9..10a150ae2a7e383557c6d7c39be70353f500494f 100644 (file)
@@ -12,7 +12,7 @@
         <surname>Bottomley</surname>
         <affiliation>
           <address>
-            <email>James.Bottomley@steeleye.com</email>
+            <email>James.Bottomley@hansenpartnership.com</email>
           </address>
         </affiliation>
       </author>
index d6cb1a86fd61ebcdf05b95d95e5517a891b2e63c..40121b5cca14cab3993000c53078ef2d8484f001 100644 (file)
@@ -168,7 +168,7 @@ int get_family_id(int sd)
                char buf[256];
        } ans;
 
-       int id, rc;
+       int id = 0, rc;
        struct nlattr *na;
        int rep_len;
 
@@ -209,7 +209,7 @@ void print_delayacct(struct taskstats *t)
 void task_context_switch_counts(struct taskstats *t)
 {
        printf("\n\nTask   %15s%15s\n"
-              "       %15lu%15lu\n",
+              "       %15llu%15llu\n",
               "voluntary", "nonvoluntary",
               t->nvcsw, t->nivcsw);
 }
@@ -399,7 +399,7 @@ int main(int argc, char *argv[])
                        goto done;
                }
 
-               PRINTF("nlmsghdr size=%d, nlmsg_len=%d, rep_len=%d\n",
+               PRINTF("nlmsghdr size=%zu, nlmsg_len=%d, rep_len=%d\n",
                       sizeof(struct nlmsghdr), msg.n.nlmsg_len, rep_len);
 
 
index 97374aacacb29120b5dfc8f788e4a9516584c8ed..44c0ab7024328d4229ef7609c2ae34aa4e730a1f 100644 (file)
@@ -29,6 +29,8 @@ rm -f $dir/interfaces
 mknod -m 0200 $dir/interfaces c $MAJOR 4
 rm -f $dir/revalidate
 mknod -m 0200 $dir/revalidate c $MAJOR 5
+rm -f $dir/flush
+mknod -m 0200 $dir/flush c $MAJOR 6
 
 export n_partitions
 mkshelf=`echo $0 | sed 's!mkdevs!mkshelf!'`
index 6449911c6a717d1b9ab8117c078e4f5f833b8557..15e86f58c0365974f8e550b74632010c951a1972 100644 (file)
@@ -23,7 +23,10 @@ fi
 # /etc/udev/rules.d
 #
 rules_d="`sed -n '/^udev_rules=/{ s!udev_rules=!!; s!\"!!g; p; }' $conf`"
-if test -z "$rules_d" || test ! -d "$rules_d"; then
+if test -z "$rules_d" ; then
+       rules_d=/etc/udev/rules.d
+fi
+if test ! -d "$rules_d"; then
        echo "$me Error: cannot find udev rules directory" 1>&2
        exit 1
 fi
index a7ed1dc4f331150e38793cd07439d80e7b1f643f..8686e789542ed0b6f3ccce8f54b1ef794c2f7fe4 100644 (file)
@@ -1,6 +1,7 @@
 # These rules tell udev what device nodes to create for aoe support.
-# They may be installed along the following lines (adjusted to what
-# you see on your system).
+# They may be installed along the following lines.  Check the section
+# 8 udev manpage to see whether your udev supports SUBSYSTEM, and
+# whether it uses one or two equal signs for SUBSYSTEM and KERNEL.
 # 
 #   ecashin@makki ~$ su
 #   Password:
 #  
 
 # aoe char devices
-SUBSYSTEM="aoe", KERNEL="discover",    NAME="etherd/%k", GROUP="disk", MODE="0220"
-SUBSYSTEM="aoe", KERNEL="err",         NAME="etherd/%k", GROUP="disk", MODE="0440"
-SUBSYSTEM="aoe", KERNEL="interfaces",  NAME="etherd/%k", GROUP="disk", MODE="0220"
-SUBSYSTEM="aoe", KERNEL="revalidate",  NAME="etherd/%k", GROUP="disk", MODE="0220"
+SUBSYSTEM=="aoe", KERNEL=="discover",  NAME="etherd/%k", GROUP="disk", MODE="0220"
+SUBSYSTEM=="aoe", KERNEL=="err",       NAME="etherd/%k", GROUP="disk", MODE="0440"
+SUBSYSTEM=="aoe", KERNEL=="interfaces",        NAME="etherd/%k", GROUP="disk", MODE="0220"
+SUBSYSTEM=="aoe", KERNEL=="revalidate",        NAME="etherd/%k", GROUP="disk", MODE="0220"
+SUBSYSTEM=="aoe", KERNEL=="flush",     NAME="etherd/%k", GROUP="disk", MODE="0220"
 
 # aoe block devices     
-KERNEL="etherd*",       NAME="%k", GROUP="disk"
+KERNEL=="etherd*",       NAME="%k", GROUP="disk"
index 17b1659bd3f8d6975245e9a99caddfda31aef7da..ce9503c892b525ea69ff41a5aec2f9c16cd65c71 100644 (file)
@@ -99,17 +99,6 @@ Who: Eric Biederman <ebiederm@xmission.com>
 
 ---------------------------
 
-What:  a.out interpreter support for ELF executables
-When:  2.6.25
-Files: fs/binfmt_elf.c
-Why:   Using a.out interpreters for ELF executables was a feature for
-       transition from a.out to ELF. But now it is unlikely to be still
-       needed anymore and removing it would simplify the hairy ELF
-       loader code.
-Who:   Andi Kleen <ak@suse.de>
-
----------------------------
-
 What:  remove EXPORT_SYMBOL(kernel_thread)
 When:  August 2006
 Files: arch/*/kernel/*_ksyms.c
@@ -192,14 +181,6 @@ Who:       Len Brown <len.brown@intel.com>
 
 ---------------------------
 
-What:  'time' kernel boot parameter
-When:  January 2008
-Why:   replaced by 'printk.time=<value>' so that printk timestamps can be
-       enabled or disabled as needed
-Who:   Randy Dunlap <randy.dunlap@oracle.com>
-
----------------------------
-
 What: libata spindown skipping and warning
 When: Dec 2008
 Why:  Some halt(8) implementations synchronize caches for and spin
index 758e50401c1635654fa073d9f9bcc8931ad8b9af..6973b980ca2a004ec9b5b7436ca1521fc5df9c67 100644 (file)
@@ -24,6 +24,7 @@ Mount options unique to the isofs filesystem.
   map=normal    Map non-Rock Ridge filenames to lower case
   map=acorn     As map=normal but also apply Acorn extensions if present
   mode=xxx      Sets the permissions on files to xxx
+  dmode=xxx     Sets the permissions on directories to xxx
   nojoliet      Ignore Joliet extensions if they are present.
   norock        Ignore Rock Ridge extensions if they are present.
   hide         Completely strip hidden files from the file system.
index bd55038b56f5464df637c618abe0a06318f39e72..81e5be6e6e356e8ab3feb4e92b972fd0862db1a9 100644 (file)
@@ -151,7 +151,7 @@ The get_sb() method has the following arguments:
   const char *dev_name: the device name we are mounting.
 
   void *data: arbitrary mount options, usually comes as an ASCII
-       string
+       string (see "Mount Options" section)
 
   struct vfsmount *mnt: a vfs-internal representation of a mount point
 
@@ -182,7 +182,7 @@ A fill_super() method implementation has the following arguments:
        must initialize this properly.
 
   void *data: arbitrary mount options, usually comes as an ASCII
-       string
+       string (see "Mount Options" section)
 
   int silent: whether or not to be silent on error
 
@@ -291,7 +291,8 @@ or bottom half).
 
   umount_begin: called when the VFS is unmounting a filesystem.
 
-  show_options: called by the VFS to show mount options for /proc/<pid>/mounts.
+  show_options: called by the VFS to show mount options for
+       /proc/<pid>/mounts.  (see "Mount Options" section)
 
   quota_read: called by the VFS to read from filesystem quota file.
 
@@ -969,6 +970,49 @@ manipulate dentries:
 For further information on dentry locking, please refer to the document
 Documentation/filesystems/dentry-locking.txt.
 
+Mount Options
+=============
+
+Parsing options
+---------------
+
+On mount and remount the filesystem is passed a string containing a
+comma separated list of mount options.  The options can have either of
+these forms:
+
+  option
+  option=value
+
+The <linux/parser.h> header defines an API that helps parse these
+options.  There are plenty of examples on how to use it in existing
+filesystems.
+
+Showing options
+---------------
+
+If a filesystem accepts mount options, it must define show_options()
+to show all the currently active options.  The rules are:
+
+  - options MUST be shown which are not default or their values differ
+    from the default
+
+  - options MAY be shown which are enabled by default or have their
+    default value
+
+Options used only internally between a mount helper and the kernel
+(such as file descriptors), or which only have an effect during the
+mounting (such as ones controlling the creation of a journal) are exempt
+from the above rules.
+
+The underlying reason for the above rules is to make sure, that a
+mount can be accurately replicated (e.g. umounting and mounting again)
+based on the information found in /proc/mounts.
+
+A simple method of saving options at mount/remount time and showing
+them is provided with the save_mount_options() and
+generic_show_options() helper functions.  Please note, that using
+these may have drawbacks.  For more info see header comments for these
+functions in fs/namespace.c.
 
 Resources
 =========
diff --git a/Documentation/hwmon/ads7828 b/Documentation/hwmon/ads7828
new file mode 100644 (file)
index 0000000..75bc4be
--- /dev/null
@@ -0,0 +1,36 @@
+Kernel driver ads7828
+=====================
+
+Supported chips:
+  * Texas Instruments/Burr-Brown ADS7828
+    Prefix: 'ads7828'
+    Addresses scanned: I2C 0x48, 0x49, 0x4a, 0x4b
+    Datasheet: Publicly available at the Texas Instruments website :
+               http://focus.ti.com/lit/ds/symlink/ads7828.pdf
+
+Authors:
+        Steve Hardy <steve@linuxrealtime.co.uk>
+
+Module Parameters
+-----------------
+
+* se_input: bool (default Y)
+  Single ended operation - set to N for differential mode
+* int_vref: bool (default Y)
+  Operate with the internal 2.5V reference - set to N for external reference
+* vref_mv: int (default 2500)
+  If using an external reference, set this to the reference voltage in mV
+
+Description
+-----------
+
+This driver implements support for the Texas Instruments ADS7828.
+
+This device is a 12-bit 8-channel A-D converter.
+
+It can operate in single ended mode (8 +ve inputs) or in differential mode,
+where 4 differential pairs can be measured.
+
+The chip also has the facility to use an external voltage reference.  This
+may be required if your hardware supplies the ADS7828 from a 5V supply, see
+the datasheet for more details.
index 5b704a40256b63a2ba896568db72c464e2ab788d..f4ce1fdbeff664b88bd35c735968d977f6d14efd 100644 (file)
@@ -30,7 +30,7 @@ Supported chips:
     Datasheet: No longer be available
 
 Authors:
-    Christophe Gauthron <chrisg@0-in.com>
+    Christophe Gauthron
     Jean Delvare <khali@linux-fr.org>
 
 
index dfc318a60fd46dbce33bcdfdb78f2e7639a0fe6f..60932e26abaaafb28f5aeb199d1a0f80d9c6a492 100644 (file)
@@ -4,12 +4,12 @@ Kernel driver lm78
 Supported chips:
   * National Semiconductor LM78 / LM78-J
     Prefix: 'lm78'
-    Addresses scanned: I2C 0x20 - 0x2f, ISA 0x290 (8 I/O ports)
+    Addresses scanned: I2C 0x28 - 0x2f, ISA 0x290 (8 I/O ports)
     Datasheet: Publicly available at the National Semiconductor website
                http://www.national.com/
   * National Semiconductor LM79
     Prefix: 'lm79'
-    Addresses scanned: I2C 0x20 - 0x2f, ISA 0x290 (8 I/O ports)
+    Addresses scanned: I2C 0x28 - 0x2f, ISA 0x290 (8 I/O ports)
     Datasheet: Publicly available at the National Semiconductor website
                http://www.national.com/
 
index c952c57f0e11cb86230e7c9dcbd6c8b7e09dfd16..ec27aa1b94cbc327337ea3a8477fc032eb36bcd2 100644 (file)
@@ -4,8 +4,12 @@ Kernel driver lm87
 Supported chips:
   * National Semiconductor LM87
     Prefix: 'lm87'
-    Addresses scanned: I2C 0x2c - 0x2f
+    Addresses scanned: I2C 0x2c - 0x2e
     Datasheet: http://www.national.com/pf/LM/LM87.html
+  * Analog Devices ADM1024
+    Prefix: 'adm1024'
+    Addresses scanned: I2C 0x2c - 0x2e
+    Datasheet: http://www.analog.com/en/prod/0,2877,ADM1024,00.html
 
 Authors:
         Frodo Looijaard <frodol@dds.nl>,
@@ -19,11 +23,12 @@ Authors:
 Description
 -----------
 
-This driver implements support for the National Semiconductor LM87.
+This driver implements support for the National Semiconductor LM87
+and the Analog Devices ADM1024.
 
 The LM87 implements up to three temperature sensors, up to two fan
 rotation speed sensors, up to seven voltage sensors, alarms, and some
-miscellaneous stuff.
+miscellaneous stuff. The ADM1024 is fully compatible.
 
 Temperatures are measured in degrees Celsius. Each input has a high
 and low alarm settings. A high limit produces an alarm when the value
index 19900a8fe6794b1f9df2354c2f7126b26107146e..9865aeedc58fff5c2051e0d3cb97449c6adb304c 100644 (file)
@@ -14,7 +14,7 @@ Lm-sensors
 
 Core set of utilities that will allow you to obtain health information,
 setup monitoring limits etc. You can get them on their homepage
-http://www.lm-sensors.nu/ or as a package from your Linux distribution.
+http://www.lm-sensors.org/ or as a package from your Linux distribution.
 
 If from website:
 Get lm-sensors from project web site. Please note, you need only userspace
index ccc2bcb610686aaf44a0d38c5f67db44e8985e82..d6e1ae30fa6e61f3da3e523befa708dcfbedb627 100644 (file)
@@ -23,8 +23,9 @@ W83627DHG super I/O chips. We will refer to them collectively as Winbond chips.
 
 The chips implement three temperature sensors, five fan rotation
 speed sensors, ten analog voltage sensors (only nine for the 627DHG), one
-VID (6 pins), alarms with beep warnings (control unimplemented), and
-some automatic fan regulation strategies (plus manual fan control mode).
+VID (6 pins for the 627EHF/EHG, 8 pins for the 627DHG), alarms with beep
+warnings (control unimplemented), and some automatic fan regulation
+strategies (plus manual fan control mode).
 
 Temperatures are measured in degrees Celsius and measurement resolution is 1
 degC for temp1 and 0.5 degC for temp2 and temp3. An alarm is triggered when
index 7922319212413c5e3a32be74495b18f339fc1e25..880a59f53da91d5f24d212945b2f0b6658b0531e 100644 (file)
@@ -73,5 +73,4 @@ doesn't help, you may just ignore the bogus VID reading with no harm done.
 
 For further information on this driver see the w83781d driver documentation.
 
-[1] http://www2.lm-sensors.nu/~lm78/cvs/browse.cgi/lm_sensors2/doc/vid
-
+[1] http://www.lm-sensors.org/browser/lm-sensors/trunk/doc/vid
index b1e9f80098ee55af95aab64d26564f7fdfefa7f0..6f800a0283e9454a8788ba375b310d544faba803 100644 (file)
@@ -4,20 +4,16 @@ Kernel driver w83781d
 Supported chips:
   * Winbond W83781D
     Prefix: 'w83781d'
-    Addresses scanned: I2C 0x20 - 0x2f, ISA 0x290 (8 I/O ports)
+    Addresses scanned: I2C 0x28 - 0x2f, ISA 0x290 (8 I/O ports)
     Datasheet: http://www.winbond-usa.com/products/winbond_products/pdfs/PCIC/w83781d.pdf
   * Winbond W83782D
     Prefix: 'w83782d'
-    Addresses scanned: I2C 0x20 - 0x2f, ISA 0x290 (8 I/O ports)
+    Addresses scanned: I2C 0x28 - 0x2f, ISA 0x290 (8 I/O ports)
     Datasheet: http://www.winbond.com/PDF/sheet/w83782d.pdf
   * Winbond W83783S
     Prefix: 'w83783s'
     Addresses scanned: I2C 0x2d
     Datasheet: http://www.winbond-usa.com/products/winbond_products/pdfs/PCIC/w83783s.pdf
-  * Winbond W83627HF
-    Prefix: 'w83627hf'
-    Addresses scanned: I2C 0x20 - 0x2f, ISA 0x290 (8 I/O ports)
-    Datasheet: http://www.winbond.com/PDF/sheet/w83627hf.pdf
   * Asus AS99127F
     Prefix: 'as99127f'
     Addresses scanned: I2C 0x28 - 0x2f
@@ -50,20 +46,18 @@ force_subclients=bus,caddr,saddr,saddr
 Description
 -----------
 
-This driver implements support for the Winbond W83781D, W83782D, W83783S,
-W83627HF chips, and the Asus AS99127F chips. We will refer to them
-collectively as W8378* chips.
+This driver implements support for the Winbond W83781D, W83782D, W83783S
+chips, and the Asus AS99127F chips. We will refer to them collectively as
+W8378* chips.
 
 There is quite some difference between these chips, but they are similar
 enough that it was sensible to put them together in one driver.
-The W83627HF chip is assumed to be identical to the ISA W83782D.
 The Asus chips are similar to an I2C-only W83782D.
 
 Chip        #vin    #fanin  #pwm    #temp   wchipid vendid  i2c     ISA
 as99127f    7       3       0       3       0x31    0x12c3  yes     no
 as99127f rev.2 (type_name = as99127f)       0x31    0x5ca3  yes     no
 w83781d     7       3       0       3       0x10-1  0x5ca3  yes     yes
-w83627hf    9       3       2       3       0x21    0x5ca3  yes     yes(LPC)
 w83782d     9       3       2-4     3       0x30    0x5ca3  yes     yes
 w83783s     5-6     3       2       1-2     0x40    0x5ca3  yes     no
 
@@ -143,9 +137,9 @@ Individual alarm and beep bits:
 0x000400: in6
 0x000800: fan3
 0x001000: chassis
-0x002000: temp3 (W83782D and W83627HF only)
-0x010000: in7 (W83782D and W83627HF only)
-0x020000: in8 (W83782D and W83627HF only)
+0x002000: temp3 (W83782D only)
+0x010000: in7 (W83782D only)
+0x020000: in8 (W83782D only)
 
 If an alarm triggers, it will remain triggered until the hardware register
 is read at least once. This means that the cause for the alarm may
diff --git a/Documentation/hwmon/w83l786ng b/Documentation/hwmon/w83l786ng
new file mode 100644 (file)
index 0000000..d8f55d7
--- /dev/null
@@ -0,0 +1,54 @@
+Kernel driver w83l786ng
+=====================
+
+Supported chips:
+  * Winbond W83L786NG/W83L786NR
+    Prefix: 'w83l786ng'
+    Addresses scanned: I2C 0x2e - 0x2f
+    Datasheet: http://www.winbond-usa.com/products/winbond_products/pdfs/PCIC/W83L786NRNG09.pdf
+
+Author: Kevin Lo <kevlo@kevlo.org>
+
+
+Module Parameters
+-----------------
+
+* reset boolean
+  (default 0)
+  Use 'reset=1' to reset the chip (via index 0x40, bit 7). The default
+  behavior is no chip reset to preserve BIOS settings
+
+
+Description
+-----------
+
+This driver implements support for Winbond W83L786NG/W83L786NR chips.
+
+The driver implements two temperature sensors, two fan rotation speed
+sensors, and three voltage sensors.
+
+Temperatures are measured in degrees Celsius and measurement resolution is 1
+degC for temp1 and temp2.
+
+Fan rotation speeds are reported in RPM (rotations per minute). Fan readings
+readings can be divided by a programmable divider (1, 2, 4, 8, 16, 32, 64
+or 128 for fan 1/2) to give the readings more range or accuracy.
+
+Voltage sensors (also known as IN sensors) report their values in millivolts.
+An alarm is triggered if the voltage has crossed a programmable minimum
+or maximum limit.
+
+/sys files
+----------
+
+pwm[1-2] - this file stores PWM duty cycle or DC value (fan speed) in range:
+           0 (stop) to 255 (full)
+pwm[1-2]_enable - this file controls mode of fan/temperature control:
+            * 0 Manual Mode
+            * 1 Thermal Cruise
+            * 2 Smart Fan II
+            * 4 FAN_SET
+pwm[1-2]_mode - Select PWM of DC mode
+            * 0 DC
+            * 1 PWM
+tolerance[1-2] - Value in degrees of Celsius (degC) for +- T
index cf6b6cb02aa15e8975fb191486e56493f3a06aa3..ef1efa79b1df82dbbd4f7b0a96dcda6021769a4c 100644 (file)
@@ -95,4 +95,4 @@ of all affected systems, so the only safe solution was to prevent access to
 the SMBus on all IBM systems (detected using DMI data.)
 
 For additional information, read:
-http://www2.lm-sensors.nu/~lm78/cvs/lm_sensors2/README.thinkpad
+http://www.lm-sensors.org/browser/lm-sensors/trunk/README.thinkpad
index 0dcbd266b44280188b8b3469d49c4c62b40e6934..a4fc7fc21439404c27a12bf718592bf0bf75c3d4 100644 (file)
@@ -1973,9 +1973,6 @@ and is between 256 and 4096 characters. It is defined in the file
                        <deci-seconds>: poll all this frequency
                        0: no polling (default)
 
-       time            Show timing data prefixed to each printk message line
-                       [deprecated, see 'printk.time']
-
        tipar.timeout=  [HW,PPT]
                        Set communications timeout in tenths of a second
                        (default 15).
diff --git a/Documentation/mn10300/ABI.txt b/Documentation/mn10300/ABI.txt
new file mode 100644 (file)
index 0000000..1fef1f0
--- /dev/null
@@ -0,0 +1,149 @@
+                          =========================
+                          MN10300 FUNCTION CALL ABI
+                          =========================
+
+=======
+GENERAL
+=======
+
+The MN10300/AM33 kernel runs in little-endian mode; big-endian mode is not
+supported.
+
+The stack grows downwards, and should always be 32-bit aligned. There are
+separate stack pointer registers for userspace and the kernel.
+
+
+================
+ARGUMENT PASSING
+================
+
+The first two arguments (assuming up to 32-bits per argument) to a function are
+passed in the D0 and D1 registers respectively; all other arguments are passed
+on the stack.
+
+If 64-bit arguments are being passed, then they are never split between
+registers and the stack. If the first argument is a 64-bit value, it will be
+passed in D0:D1. If the first argument is not a 64-bit value, but the second
+is, the second will be passed entirely on the stack and D1 will be unused.
+
+Arguments smaller than 32-bits are not coelesced within a register or a stack
+word. For example, two byte-sized arguments will always be passed in separate
+registers or word-sized stack slots.
+
+
+=================
+CALLING FUNCTIONS
+=================
+
+The caller must allocate twelve bytes on the stack for the callee's use before
+it inserts a CALL instruction. The CALL instruction will write into the TOS
+word, but won't actually modify the stack pointer; similarly, the RET
+instruction reads from the TOS word of the stack, but doesn't move the stack
+pointer beyond it.
+
+
+       Stack:
+       |               |
+       |               |
+       |---------------| SP+20
+       | 4th Arg       |
+       |---------------| SP+16
+       | 3rd Arg       |
+       |---------------| SP+12
+       | D1 Save Slot  |
+       |---------------| SP+8
+       | D0 Save Slot  |
+       |---------------| SP+4
+       | Return Addr   |
+       |---------------| SP
+       |               |
+       |               |
+
+
+The caller must leave space on the stack (hence an allocation of twelve bytes)
+in which the callee may store the first two arguments.
+
+
+============
+RETURN VALUE
+============
+
+The return value is passed in D0 for an integer (or D0:D1 for a 64-bit value),
+or A0 for a pointer.
+
+If the return value is a value larger than 64-bits, or is a structure or an
+array, then a hidden first argument will be passed to the callee by the caller:
+this will point to a piece of memory large enough to hold the result of the
+function. In this case, the callee will return the value in that piece of
+memory, and no value will be returned in D0 or A0.
+
+
+===================
+REGISTER CLOBBERING
+===================
+
+The values in certain registers may be clobbered by the callee, and other
+values must be saved:
+
+       Clobber:        D0-D1, A0-A1, E0-E3
+       Save:           D2-D3, A2-A3, E4-E7, SP
+
+All other non-supervisor-only registers are clobberable (such as MDR, MCRL,
+MCRH).
+
+
+=================
+SPECIAL REGISTERS
+=================
+
+Certain ordinary registers may carry special usage for the compiler:
+
+       A3:     Frame pointer
+       E2:     TLS pointer
+
+
+==========
+KERNEL ABI
+==========
+
+The kernel may use a slightly different ABI internally.
+
+ (*) E2
+
+     If CONFIG_MN10300_CURRENT_IN_E2 is defined, then the current task pointer
+     will be kept in the E2 register, and that register will be marked
+     unavailable for the compiler to use as a scratch register.
+
+     Normally the kernel uses something like:
+
+       MOV     SP,An
+       AND     0xFFFFE000,An
+       MOV     (An),Rm         // Rm holds current
+       MOV     (yyy,Rm)        // Access current->yyy
+
+     To find the address of current; but since this option permits current to
+     be carried globally in an register, it can use:
+
+       MOV     (yyy,E2)        // Access current->yyy
+
+     instead.
+
+
+===============
+SYSTEM CALL ABI
+===============
+
+System calls are called with the following convention:
+
+       REGISTER        ENTRY                   EXIT
+       =============== ======================= =======================
+       D0              Syscall number          Return value
+       A0              1st syscall argument    Saved
+       D1              2nd syscall argument    Saved
+       A3              3rd syscall argument    Saved
+       A2              4th syscall argument    Saved
+       D3              5th syscall argument    Saved
+       D2              6th syscall argument    Saved
+
+All other registers are saved.  The layout is a consequence of the way the MOVM
+instruction stores registers onto the stack.
diff --git a/Documentation/mn10300/compartmentalisation.txt b/Documentation/mn10300/compartmentalisation.txt
new file mode 100644 (file)
index 0000000..8958b51
--- /dev/null
@@ -0,0 +1,60 @@
+                  =========================================
+                  PART-SPECIFIC SOURCE COMPARTMENTALISATION
+                  =========================================
+
+The sources for various parts are compartmentalised at two different levels:
+
+ (1) Processor level
+
+     The "processor level" is a CPU core plus the other on-silicon
+     peripherals.
+
+     Processor-specific header files are divided among directories in a similar
+     way to the CPU level:
+
+       (*) include/asm-mn10300/proc-mn103e010/
+
+           Support for the AM33v2 CPU core.
+
+     The appropriate processor is selected by a CONFIG_MN10300_PROC_YYYY option
+     from the "Processor support" choice menu in the arch/mn10300/Kconfig file.
+
+
+ (2) Unit level
+
+     The "unit level" is a processor plus all the external peripherals
+     controlled by that processor.
+
+     Unit-specific header files are divided among directories in a similar way
+     to the CPU level; not only that, but specific sources may also be
+     segregated into separate directories under the arch directory:
+
+       (*) include/asm-mn10300/unit-asb2303/
+       (*) arch/mn10300/unit-asb2303/
+
+           Support for the ASB2303 board with an ASB2308 daughter board.
+
+       (*) include/asm-mn10300/unit-asb2305/
+       (*) arch/mn10300/unit-asb2305/
+
+           Support for the ASB2305 board.
+
+     The appropriate processor is selected by a CONFIG_MN10300_UNIT_ZZZZ option
+     from the "Unit type" choice menu in the arch/mn10300/Kconfig file.
+
+
+============
+COMPILE TIME
+============
+
+When the kernel is compiled, symbolic links will be made in the asm header file
+directory for this arch:
+
+       include/asm-mn10300/proc => include/asm-mn10300/proc-YYYY/
+       include/asm-mn10300/unit => include/asm-mn10300/unit-ZZZZ/
+
+So that the header files contained in those directories can be accessed without
+lots of #ifdef-age.
+
+The appropriate arch/mn10300/unit-ZZZZ directory will also be entered by the
+compilation process; all other unit-specific directories will be ignored.
index cd8403a33ee64ad118000bbfe816611ae39dfeb6..de2bcacfa870a6f1e3bc94369fda343db1e8b4a7 100644 (file)
 **                                             2. modify the arcmsr_pci_slot_reset function
 **                                             3. modify the arcmsr_pci_ers_disconnect_forepart function
 **                                             4. modify the arcmsr_pci_ers_need_reset_forepart function
+** 1.20.00.15   09/27/2007      Erich Chen & Nick Cheng
+**                                             1. add arcmsr_enable_eoi_mode() on adapter Type B
+**                                             2. add readl(reg->iop2drv_doorbell_reg) in arcmsr_handle_hbb_isr()
+**                                             in case of the doorbell interrupt clearance is cached
+** 1.20.00.15   10/01/2007      Erich Chen & Nick Cheng
+**                                             1. modify acb->devstate[i][j]
+**                                             as ARECA_RAID_GOOD instead of
+**                                             ARECA_RAID_GONE in arcmsr_alloc_ccb_pool
+** 1.20.00.15   11/06/2007       Erich Chen & Nick Cheng
+**                                             1. add conditional declaration for
+**                                             arcmsr_pci_error_detected() and
+**                                             arcmsr_pci_slot_reset
+** 1.20.00.15  11/23/2007       Erich Chen & Nick Cheng
+**                                             1.check if the sg list member number
+**                                             exceeds arcmsr default limit in arcmsr_build_ccb()
+**                                             2.change the returned value type of arcmsr_build_ccb()
+**                                             from "void" to "int"
+**                                             3.add the conditional check if arcmsr_build_ccb()
+**                                             returns FAILED
+** 1.20.00.15  12/04/2007       Erich Chen & Nick Cheng
+**                                             1. modify arcmsr_drain_donequeue() to ignore unknown
+**                                             command and let kernel process command timeout.
+**                                             This could handle IO request violating max. segments
+**                                             while Linux XFS over DM-CRYPT.
+**                                             Thanks to Milan Broz's comments <mbroz@redhat.com>
+** 1.20.00.15  12/24/2007       Erich Chen & Nick Cheng
+**                                             1.fix the portability problems
+**                                             2.fix type B where we should _not_ iounmap() acb->pmu;
+**                                             it's not ioremapped.
+**                                             3.add return -ENOMEM if ioremap() fails
+**                                             4.transfer IS_SG64_ADDR w/ cpu_to_le32()
+**                                             in arcmsr_build_ccb
+**                                             5. modify acb->devstate[i][j] as ARECA_RAID_GONE instead of
+**                                             ARECA_RAID_GOOD in arcmsr_alloc_ccb_pool()
+**                                             6.fix arcmsr_cdb->Context as (unsigned long)arcmsr_cdb
+**                                             7.add the checking state of
+**                                             (outbound_intstatus & ARCMSR_MU_OUTBOUND_HANDLE_INT) == 0
+**                                             in arcmsr_handle_hba_isr
+**                                             8.replace pci_alloc_consistent()/pci_free_consistent() with kmalloc()/kfree() in arcmsr_iop_message_xfer()
+**                                             9. fix the release of dma memory for type B in arcmsr_free_ccb_pool()
+**                                             10.fix the arcmsr_polling_hbb_ccbdone()
 **************************************************************************
index 6f70f2b9327e1f0db7bc05bdbf2d6ce3b2fcbdcf..a6d5354639b2ac73e98abe5b297da5dad6f330f2 100644 (file)
@@ -1407,7 +1407,7 @@ Credits
 =======
 The following people have contributed to this document:
         Mike Anderson <andmike at us dot ibm dot com>
-        James Bottomley <James dot Bottomley at steeleye dot com> 
+        James Bottomley <James dot Bottomley at hansenpartnership dot com>
         Patrick Mansfield <patmans at us dot ibm dot com> 
         Christoph Hellwig <hch at infradead dot org>
         Doug Ledford <dledford at redhat dot com>
index 5776e090359d028e614d251b7a72d727bb95d063..ba9c2da5a8c200fbb6a27b84c7a2f85a441e979d 100644 (file)
@@ -14,7 +14,7 @@ The generic thermal sysfs provides a set of interfaces for thermal zone devices
 and thermal cooling devices (fan, processor...) to register with the thermal management
 solution and to be a part of it.
 
-This how-to focusses on enabling new thermal zone and cooling devices to participate
+This how-to focuses on enabling new thermal zone and cooling devices to participate
 in thermal management.
 This solution is platform independent and any type of thermal zone devices and
 cooling devices should be able to make use of the infrastructure.
@@ -41,9 +41,9 @@ and throttle appropriate devices.
        name: the thermal zone name.
        trips: the total number of trip points this thermal zone supports.
        devdata: device private data
-       ops: thermal zone device callbacks.
+       ops: thermal zone device call-backs.
                .bind: bind the thermal zone device with a thermal cooling device.
-               .unbind: unbing the thermal zone device with a thermal cooling device.
+               .unbind: unbind the thermal zone device with a thermal cooling device.
                .get_temp: get the current temperature of the thermal zone.
                .get_mode: get the current mode (user/kernel) of the thermal zone.
                           "kernel" means thermal management is done in kernel.
@@ -69,7 +69,7 @@ and throttle appropriate devices.
        It tries to bind itself to all the thermal zone devices register at the same time.
        name: the cooling device name.
        devdata: device private data.
-       ops: thermal cooling devices callbacks.
+       ops: thermal cooling devices call-backs.
                .get_max_state: get the Maximum throttle state of the cooling device.
                .get_cur_state: get the Current throttle state of the cooling device.
                .set_cur_state: set the Current throttle state of the cooling device.
@@ -109,7 +109,6 @@ RO  read only value
 RW     read/write value
 
 All thermal sysfs attributes will be represented under /sys/class/thermal
-/sys/class/thermal/
 
 Thermal zone device sys I/F, created once it's registered:
 |thermal_zone[0-*]:
@@ -129,7 +128,7 @@ Thermal cooling device sys I/F, created once it's registered:
 These two dynamic attributes are created/removed in pairs.
 They represent the relationship between a thermal zone and its associated cooling device.
 They are created/removed for each
-thermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device successful exection.
+thermal_zone_bind_cooling_device/thermal_zone_unbind_cooling_device successful execution.
 
 |thermal_zone[0-*]
        |-----cdev[0-*]:                The [0-*]th cooling device in the current thermal zone
@@ -147,11 +146,11 @@ type                              Strings which represent the thermal zone type.
                                Optional
 
 temp                           Current temperature as reported by thermal zone (sensor)
-                               Unit: degree celsius
+                               Unit: degree Celsius
                                RO
                                Required
 
-mode                           One of the predifned values in [kernel, user]
+mode                           One of the predefined values in [kernel, user]
                                This file gives information about the algorithm
                                that is currently managing the thermal zone.
                                It can be either default kernel based algorithm
@@ -164,12 +163,12 @@ mode                              One of the predifned values in [kernel, user]
                                          charge of the thermal management.
 
 trip_point_[0-*]_temp          The temperature above which trip point will be fired
-                               Unit: degree celsius
+                               Unit: degree Celsius
                                RO
                                Optional
 
 trip_point_[0-*]_type          Strings which indicate the type of the trip point
-                               Eg. it can be one of critical, hot, passive,
+                               E.g. it can be one of critical, hot, passive,
                                    active[0-*] for ACPI thermal zone.
                                RO
                                Optional
@@ -179,7 +178,7 @@ cdev[0-*]                   Sysfs link to the thermal cooling device node where the sys I/F
                                RO
                                Optional
 
-cdev[0-*]_trip_point           The trip point with which cdev[0-*] is assocated in this thermal zone
+cdev[0-*]_trip_point           The trip point with which cdev[0-*] is associated in this thermal zone
                                -1 means the cooling device is not associated with any trip point.
                                RO
                                Optional
@@ -211,7 +210,7 @@ cur_state                   The current cooling state of this cooling device.
 
 ACPI thermal zone may support multiple trip points like critical/hot/passive/active.
 If an ACPI thermal zone supports critical, passive, active[0] and active[1] at the same time,
-it may register itself as a thermale_zone_device (thermal_zone1) with 4 trip points in all.
+it may register itself as a thermal_zone_device (thermal_zone1) with 4 trip points in all.
 It has one processor and one fan, which are both registered as thermal_cooling_device.
 If the processor is listed in _PSL method, and the fan is listed in _AL0 method,
 the sys I/F structure will be built like this:
index 488c1f31b99249b75a9686cf42f08329bea896c9..7123fee708ca9fa3f08c102f6e82247f7a60fbae 100644 (file)
@@ -32,6 +32,13 @@ struct slabinfo {
        int sanity_checks, slab_size, store_user, trace;
        int order, poison, reclaim_account, red_zone;
        unsigned long partial, objects, slabs;
+       unsigned long alloc_fastpath, alloc_slowpath;
+       unsigned long free_fastpath, free_slowpath;
+       unsigned long free_frozen, free_add_partial, free_remove_partial;
+       unsigned long alloc_from_partial, alloc_slab, free_slab, alloc_refill;
+       unsigned long cpuslab_flush, deactivate_full, deactivate_empty;
+       unsigned long deactivate_to_head, deactivate_to_tail;
+       unsigned long deactivate_remote_frees;
        int numa[MAX_NODES];
        int numa_partial[MAX_NODES];
 } slabinfo[MAX_SLABS];
@@ -64,8 +71,10 @@ int show_inverted = 0;
 int show_single_ref = 0;
 int show_totals = 0;
 int sort_size = 0;
+int sort_active = 0;
 int set_debug = 0;
 int show_ops = 0;
+int show_activity = 0;
 
 /* Debug options */
 int sanity = 0;
@@ -93,8 +102,10 @@ void usage(void)
        printf("slabinfo 5/7/2007. (c) 2007 sgi. clameter@sgi.com\n\n"
                "slabinfo [-ahnpvtsz] [-d debugopts] [slab-regexp]\n"
                "-a|--aliases           Show aliases\n"
+               "-A|--activity          Most active slabs first\n"
                "-d<options>|--debug=<options> Set/Clear Debug options\n"
-               "-e|--empty             Show empty slabs\n"
+               "-D|--display-active    Switch line format to activity\n"
+               "-e|--empty             Show empty slabs\n"
                "-f|--first-alias       Show first alias\n"
                "-h|--help              Show usage information\n"
                "-i|--inverted          Inverted list\n"
@@ -281,8 +292,11 @@ int line = 0;
 
 void first_line(void)
 {
-       printf("Name                   Objects Objsize    Space "
-               "Slabs/Part/Cpu  O/S O %%Fr %%Ef Flg\n");
+       if (show_activity)
+               printf("Name                   Objects    Alloc     Free   %%Fast\n");
+       else
+               printf("Name                   Objects Objsize    Space "
+                       "Slabs/Part/Cpu  O/S O %%Fr %%Ef Flg\n");
 }
 
 /*
@@ -309,6 +323,12 @@ unsigned long slab_size(struct slabinfo *s)
        return  s->slabs * (page_size << s->order);
 }
 
+unsigned long slab_activity(struct slabinfo *s)
+{
+       return  s->alloc_fastpath + s->free_fastpath +
+               s->alloc_slowpath + s->free_slowpath;
+}
+
 void slab_numa(struct slabinfo *s, int mode)
 {
        int node;
@@ -392,6 +412,71 @@ const char *onoff(int x)
        return "Off";
 }
 
+void slab_stats(struct slabinfo *s)
+{
+       unsigned long total_alloc;
+       unsigned long total_free;
+       unsigned long total;
+
+       if (!s->alloc_slab)
+               return;
+
+       total_alloc = s->alloc_fastpath + s->alloc_slowpath;
+       total_free = s->free_fastpath + s->free_slowpath;
+
+       if (!total_alloc)
+               return;
+
+       printf("\n");
+       printf("Slab Perf Counter       Alloc     Free %%Al %%Fr\n");
+       printf("--------------------------------------------------\n");
+       printf("Fastpath             %8lu %8lu %3lu %3lu\n",
+               s->alloc_fastpath, s->free_fastpath,
+               s->alloc_fastpath * 100 / total_alloc,
+               s->free_fastpath * 100 / total_free);
+       printf("Slowpath             %8lu %8lu %3lu %3lu\n",
+               total_alloc - s->alloc_fastpath, s->free_slowpath,
+               (total_alloc - s->alloc_fastpath) * 100 / total_alloc,
+               s->free_slowpath * 100 / total_free);
+       printf("Page Alloc           %8lu %8lu %3lu %3lu\n",
+               s->alloc_slab, s->free_slab,
+               s->alloc_slab * 100 / total_alloc,
+               s->free_slab * 100 / total_free);
+       printf("Add partial          %8lu %8lu %3lu %3lu\n",
+               s->deactivate_to_head + s->deactivate_to_tail,
+               s->free_add_partial,
+               (s->deactivate_to_head + s->deactivate_to_tail) * 100 / total_alloc,
+               s->free_add_partial * 100 / total_free);
+       printf("Remove partial       %8lu %8lu %3lu %3lu\n",
+               s->alloc_from_partial, s->free_remove_partial,
+               s->alloc_from_partial * 100 / total_alloc,
+               s->free_remove_partial * 100 / total_free);
+
+       printf("RemoteObj/SlabFrozen %8lu %8lu %3lu %3lu\n",
+               s->deactivate_remote_frees, s->free_frozen,
+               s->deactivate_remote_frees * 100 / total_alloc,
+               s->free_frozen * 100 / total_free);
+
+       printf("Total                %8lu %8lu\n\n", total_alloc, total_free);
+
+       if (s->cpuslab_flush)
+               printf("Flushes %8lu\n", s->cpuslab_flush);
+
+       if (s->alloc_refill)
+               printf("Refill %8lu\n", s->alloc_refill);
+
+       total = s->deactivate_full + s->deactivate_empty +
+                       s->deactivate_to_head + s->deactivate_to_tail;
+
+       if (total)
+               printf("Deactivate Full=%lu(%lu%%) Empty=%lu(%lu%%) "
+                       "ToHead=%lu(%lu%%) ToTail=%lu(%lu%%)\n",
+                       s->deactivate_full, (s->deactivate_full * 100) / total,
+                       s->deactivate_empty, (s->deactivate_empty * 100) / total,
+                       s->deactivate_to_head, (s->deactivate_to_head * 100) / total,
+                       s->deactivate_to_tail, (s->deactivate_to_tail * 100) / total);
+}
+
 void report(struct slabinfo *s)
 {
        if (strcmp(s->name, "*") == 0)
@@ -430,6 +515,7 @@ void report(struct slabinfo *s)
        ops(s);
        show_tracking(s);
        slab_numa(s, 1);
+       slab_stats(s);
 }
 
 void slabcache(struct slabinfo *s)
@@ -479,13 +565,27 @@ void slabcache(struct slabinfo *s)
                *p++ = 'T';
 
        *p = 0;
-       printf("%-21s %8ld %7d %8s %14s %4d %1d %3ld %3ld %s\n",
-               s->name, s->objects, s->object_size, size_str, dist_str,
-               s->objs_per_slab, s->order,
-               s->slabs ? (s->partial * 100) / s->slabs : 100,
-               s->slabs ? (s->objects * s->object_size * 100) /
-                       (s->slabs * (page_size << s->order)) : 100,
-               flags);
+       if (show_activity) {
+               unsigned long total_alloc;
+               unsigned long total_free;
+
+               total_alloc = s->alloc_fastpath + s->alloc_slowpath;
+               total_free = s->free_fastpath + s->free_slowpath;
+
+               printf("%-21s %8ld %8ld %8ld %3ld %3ld \n",
+                       s->name, s->objects,
+                       total_alloc, total_free,
+                       total_alloc ? (s->alloc_fastpath * 100 / total_alloc) : 0,
+                       total_free ? (s->free_fastpath * 100 / total_free) : 0);
+       }
+       else
+               printf("%-21s %8ld %7d %8s %14s %4d %1d %3ld %3ld %s\n",
+                       s->name, s->objects, s->object_size, size_str, dist_str,
+                       s->objs_per_slab, s->order,
+                       s->slabs ? (s->partial * 100) / s->slabs : 100,
+                       s->slabs ? (s->objects * s->object_size * 100) /
+                               (s->slabs * (page_size << s->order)) : 100,
+                       flags);
 }
 
 /*
@@ -892,6 +992,8 @@ void sort_slabs(void)
 
                        if (sort_size)
                                result = slab_size(s1) < slab_size(s2);
+                       else if (sort_active)
+                               result = slab_activity(s1) < slab_activity(s2);
                        else
                                result = strcasecmp(s1->name, s2->name);
 
@@ -1074,6 +1176,23 @@ void read_slab_dir(void)
                        free(t);
                        slab->store_user = get_obj("store_user");
                        slab->trace = get_obj("trace");
+                       slab->alloc_fastpath = get_obj("alloc_fastpath");
+                       slab->alloc_slowpath = get_obj("alloc_slowpath");
+                       slab->free_fastpath = get_obj("free_fastpath");
+                       slab->free_slowpath = get_obj("free_slowpath");
+                       slab->free_frozen= get_obj("free_frozen");
+                       slab->free_add_partial = get_obj("free_add_partial");
+                       slab->free_remove_partial = get_obj("free_remove_partial");
+                       slab->alloc_from_partial = get_obj("alloc_from_partial");
+                       slab->alloc_slab = get_obj("alloc_slab");
+                       slab->alloc_refill = get_obj("alloc_refill");
+                       slab->free_slab = get_obj("free_slab");
+                       slab->cpuslab_flush = get_obj("cpuslab_flush");
+                       slab->deactivate_full = get_obj("deactivate_full");
+                       slab->deactivate_empty = get_obj("deactivate_empty");
+                       slab->deactivate_to_head = get_obj("deactivate_to_head");
+                       slab->deactivate_to_tail = get_obj("deactivate_to_tail");
+                       slab->deactivate_remote_frees = get_obj("deactivate_remote_frees");
                        chdir("..");
                        if (slab->name[0] == ':')
                                alias_targets++;
@@ -1124,7 +1243,9 @@ void output_slabs(void)
 
 struct option opts[] = {
        { "aliases", 0, NULL, 'a' },
+       { "activity", 0, NULL, 'A' },
        { "debug", 2, NULL, 'd' },
+       { "display-activity", 0, NULL, 'D' },
        { "empty", 0, NULL, 'e' },
        { "first-alias", 0, NULL, 'f' },
        { "help", 0, NULL, 'h' },
@@ -1149,7 +1270,7 @@ int main(int argc, char *argv[])
 
        page_size = getpagesize();
 
-       while ((c = getopt_long(argc, argv, "ad::efhil1noprstvzTS",
+       while ((c = getopt_long(argc, argv, "aAd::Defhil1noprstvzTS",
                                                opts, NULL)) != -1)
                switch (c) {
                case '1':
@@ -1158,11 +1279,17 @@ int main(int argc, char *argv[])
                case 'a':
                        show_alias = 1;
                        break;
+               case 'A':
+                       sort_active = 1;
+                       break;
                case 'd':
                        set_debug = 1;
                        if (!debug_opt_scan(optarg))
                                fatal("Invalid debug option '%s'\n", optarg);
                        break;
+               case 'D':
+                       show_activity = 1;
+                       break;
                case 'e':
                        show_empty = 1;
                        break;
index aefd23f892bae93d58fed6db9d20b1e601fcea5f..a24631f4eab186236001b7b4b3b90798236206e2 100644 (file)
@@ -688,6 +688,12 @@ W: http://www.atmel.com/products/AT91/
 W:     http://www.at91.com/
 S:     Maintained
 
+ATMEL AT91 / AT32 SERIAL DRIVER
+P:     Haavard Skinnemoen
+M:     hskinnemoen@atmel.com
+L:     linux-kernel@vger.kernel.org
+S:     Supported
+
 ATMEL LCDFB DRIVER
 P:     Nicolas Ferre
 M:     nicolas.ferre@atmel.com
@@ -2150,6 +2156,14 @@ M:       acme@ghostprotocols.net
 L:     netdev@vger.kernel.org
 S:     Maintained
 
+IPWIRELES DRIVER
+P:     Jiri Kosina
+M:     jkosina@suse.cz
+P:     David Sterba
+M:     dsterba@suse.cz
+S:     Maintained
+T:     git://git.kernel.org/pub/scm/linux/kernel/git/jikos/ipwireless_cs.git
+
 IRDA SUBSYSTEM
 P:     Samuel Ortiz
 M:     samuel@sortiz.org
@@ -2606,6 +2620,15 @@ L:       linux-kernel@vger.kernel.org
 W:     http://www.linux-mm.org
 S:     Maintained
 
+MEI MN10300/AM33 PORT
+P:     David Howells
+M:     dhowells@redhat.com
+P:     Koichi Yasutake
+M:     yasutake.koichi@jp.panasonic.com
+L:     linux-am33-list@redhat.com
+W:     ftp://ftp.redhat.com/pub/redhat/gnupro/AM33/
+S:     Maintained
+
 MEMORY TECHNOLOGY DEVICES (MTD)
 P:     David Woodhouse
 M:     dwmw2@infradead.org
@@ -3237,6 +3260,11 @@ W:       http://rt2x00.serialmonkey.com/
 S:     Maintained
 F:     drivers/net/wireless/rt2x00/
 
+RAMDISK RAM BLOCK DEVICE DRIVER
+P:     Nick Piggin
+M:     npiggin@suse.de
+S:     Maintained
+
 RANDOM NUMBER DRIVER
 P:     Matt Mackall
 M:     mpm@selenic.com
@@ -3873,8 +3901,8 @@ L:        linux-scsi@vger.kernel.org
 S:     Maintained
 
 UDF FILESYSTEM
-P:     Ben Fennema
-M:     bfennema@falcon.csc.calpoly.edu
+P:     Jan Kara
+M:     jack@suse.cz
 W:     http://linux-udf.sourceforge.net
 S:     Maintained
 
index 01b10ab588a630b36c0290448ffa53d29bf03dfc..5b7dcd5a0e75b663e709b093bc2f4f21fb3d49b8 100644 (file)
@@ -67,6 +67,9 @@ config AUTO_IRQ_AFFINITY
        depends on SMP
        default y
 
+config ARCH_SUPPORTS_AOUT
+       def_bool y
+
 source "init/Kconfig"
 
 
@@ -612,6 +615,11 @@ config VERBOSE_MCHECK_ON
 
          Take the default (1) unless you want more control or more info.
 
+config HZ
+       int
+       default 1200 if ALPHA_RAWHIDE
+       default 1024
+
 source "drivers/pci/Kconfig"
 source "drivers/eisa/Kconfig"
 
index 72f9a619a66d8055b03df676979b0645879c7160..973c5c3705e3f08d2669d08f1a15ae0df44c85b8 100644 (file)
@@ -22,7 +22,6 @@
 #include <linux/ptrace.h>
 #include <linux/slab.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/utsname.h>
 #include <linux/time.h>
 #include <linux/timex.h>
index 92b61629fe3f5787fe11c2ed2eb319619524ebcb..96ed82fd9eef94b775de953ff41872cbdc266f3e 100644 (file)
@@ -19,7 +19,6 @@
 #include <linux/ptrace.h>
 #include <linux/slab.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/utsname.h>
 #include <linux/time.h>
 #include <linux/major.h>
@@ -317,68 +316,6 @@ copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
        return 0;
 }
 
-/*
- * Fill in the user structure for an ECOFF core dump.
- */
-void
-dump_thread(struct pt_regs * pt, struct user * dump)
-{
-       /* switch stack follows right below pt_regs: */
-       struct switch_stack * sw = ((struct switch_stack *) pt) - 1;
-
-       dump->magic = CMAGIC;
-       dump->start_code  = current->mm->start_code;
-       dump->start_data  = current->mm->start_data;
-       dump->start_stack = rdusp() & ~(PAGE_SIZE - 1);
-       dump->u_tsize = ((current->mm->end_code - dump->start_code)
-                        >> PAGE_SHIFT);
-       dump->u_dsize = ((current->mm->brk + PAGE_SIZE-1 - dump->start_data)
-                        >> PAGE_SHIFT);
-       dump->u_ssize = (current->mm->start_stack - dump->start_stack
-                        + PAGE_SIZE-1) >> PAGE_SHIFT;
-
-       /*
-        * We store the registers in an order/format that is
-        * compatible with DEC Unix/OSF/1 as this makes life easier
-        * for gdb.
-        */
-       dump->regs[EF_V0]  = pt->r0;
-       dump->regs[EF_T0]  = pt->r1;
-       dump->regs[EF_T1]  = pt->r2;
-       dump->regs[EF_T2]  = pt->r3;
-       dump->regs[EF_T3]  = pt->r4;
-       dump->regs[EF_T4]  = pt->r5;
-       dump->regs[EF_T5]  = pt->r6;
-       dump->regs[EF_T6]  = pt->r7;
-       dump->regs[EF_T7]  = pt->r8;
-       dump->regs[EF_S0]  = sw->r9;
-       dump->regs[EF_S1]  = sw->r10;
-       dump->regs[EF_S2]  = sw->r11;
-       dump->regs[EF_S3]  = sw->r12;
-       dump->regs[EF_S4]  = sw->r13;
-       dump->regs[EF_S5]  = sw->r14;
-       dump->regs[EF_S6]  = sw->r15;
-       dump->regs[EF_A3]  = pt->r19;
-       dump->regs[EF_A4]  = pt->r20;
-       dump->regs[EF_A5]  = pt->r21;
-       dump->regs[EF_T8]  = pt->r22;
-       dump->regs[EF_T9]  = pt->r23;
-       dump->regs[EF_T10] = pt->r24;
-       dump->regs[EF_T11] = pt->r25;
-       dump->regs[EF_RA]  = pt->r26;
-       dump->regs[EF_T12] = pt->r27;
-       dump->regs[EF_AT]  = pt->r28;
-       dump->regs[EF_SP]  = rdusp();
-       dump->regs[EF_PS]  = pt->ps;
-       dump->regs[EF_PC]  = pt->pc;
-       dump->regs[EF_GP]  = pt->gp;
-       dump->regs[EF_A0]  = pt->r16;
-       dump->regs[EF_A1]  = pt->r17;
-       dump->regs[EF_A2]  = pt->r18;
-       memcpy((char *)dump->regs + EF_SIZE, sw->fp, 32 * 8);
-}
-EXPORT_SYMBOL(dump_thread);
-
 /*
  * Fill in the user structure for a ELF core dump.
  */
index 74c3466256586800730be7e19c94421a2050b877..a449e999027c8e663af133f956996c94a70197fc 100644 (file)
@@ -18,7 +18,6 @@
 #include <linux/ptrace.h>
 #include <linux/slab.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/screen_info.h>
 #include <linux/delay.h>
 #include <linux/mc146818rtc.h>
@@ -1472,7 +1471,7 @@ c_stop(struct seq_file *f, void *v)
 {
 }
 
-struct seq_operations cpuinfo_op = {
+const struct seq_operations cpuinfo_op = {
        .start  = c_start,
        .next   = c_next,
        .stop   = c_stop,
index e19e7744e366a3a8d14bbb7aa7fb5ab4d0d13986..4127af93c5f373fdf31e81f4d748bf60decc514a 100644 (file)
@@ -126,6 +126,9 @@ config GENERIC_CALIBRATE_DELAY
        bool
        default y
 
+config ARCH_SUPPORTS_AOUT
+       def_bool y
+
 config ARCH_MAY_HAVE_PC_FDC
        bool
 
index 4f1a03124a74ae4a543df710a8c3e6af3d0200ad..46bf2ede612840b84eb3f7994c4cc85ae0d4c076 100644 (file)
@@ -18,7 +18,6 @@
 #include <linux/unistd.h>
 #include <linux/slab.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/delay.h>
 #include <linux/reboot.h>
 #include <linux/interrupt.h>
@@ -367,35 +366,6 @@ int dump_fpu (struct pt_regs *regs, struct user_fp *fp)
 }
 EXPORT_SYMBOL(dump_fpu);
 
-/*
- * fill in the user structure for a core dump..
- */
-void dump_thread(struct pt_regs * regs, struct user * dump)
-{
-       struct task_struct *tsk = current;
-
-       dump->magic = CMAGIC;
-       dump->start_code = tsk->mm->start_code;
-       dump->start_stack = regs->ARM_sp & ~(PAGE_SIZE - 1);
-
-       dump->u_tsize = (tsk->mm->end_code - tsk->mm->start_code) >> PAGE_SHIFT;
-       dump->u_dsize = (tsk->mm->brk - tsk->mm->start_data + PAGE_SIZE - 1) >> PAGE_SHIFT;
-       dump->u_ssize = 0;
-
-       dump->u_debugreg[0] = tsk->thread.debug.bp[0].address;
-       dump->u_debugreg[1] = tsk->thread.debug.bp[1].address;
-       dump->u_debugreg[2] = tsk->thread.debug.bp[0].insn.arm;
-       dump->u_debugreg[3] = tsk->thread.debug.bp[1].insn.arm;
-       dump->u_debugreg[4] = tsk->thread.debug.nsaved;
-
-       if (dump->start_stack < 0x04000000)
-               dump->u_ssize = (0x04000000 - dump->start_stack) >> PAGE_SHIFT;
-
-       dump->regs = *regs;
-       dump->u_fpvalid = dump_fpu (regs, &dump->u_fp);
-}
-EXPORT_SYMBOL(dump_thread);
-
 /*
  * Shuffle the argument into the correct register before calling the
  * thread function.  r1 is the thread argument, r2 is the pointer to
index c4f023294d750659e992b93afc1d22ca456065f6..1b0245d4e0ca6937292770d72cdeb410a20b8d7e 100644 (file)
@@ -90,25 +90,29 @@ static struct dentry *ocd_debugfs_DC;
 static struct dentry *ocd_debugfs_DS;
 static struct dentry *ocd_debugfs_count;
 
-static u64 ocd_DC_get(void *data)
+static int ocd_DC_get(void *data, u64 *val)
 {
-       return ocd_read(DC);
+       *val = ocd_read(DC);
+       return 0;
 }
-static void ocd_DC_set(void *data, u64 val)
+static int ocd_DC_set(void *data, u64 val)
 {
        ocd_write(DC, val);
+       return 0;
 }
 DEFINE_SIMPLE_ATTRIBUTE(fops_DC, ocd_DC_get, ocd_DC_set, "0x%08llx\n");
 
-static u64 ocd_DS_get(void *data)
+static int ocd_DS_get(void *data, u64 *val)
 {
-       return ocd_read(DS);
+       *val = ocd_read(DS);
+       return 0;
 }
 DEFINE_SIMPLE_ATTRIBUTE(fops_DS, ocd_DS_get, NULL, "0x%08llx\n");
 
-static u64 ocd_count_get(void *data)
+static int ocd_count_get(void *data, u64 *val)
 {
-       return ocd_count;
+       *val = ocd_count;
+       return 0;
 }
 DEFINE_SIMPLE_ATTRIBUTE(fops_count, ocd_count_get, NULL, "%lld\n");
 
index 14e61f05e1f6a4366a9992f70535c301108a97ed..7678fee9a885ecc8fc0d041dfe5cb14427fc7a75 100644 (file)
@@ -1185,6 +1185,59 @@ err_dup_modedb:
 }
 #endif
 
+/* --------------------------------------------------------------------
+ *  PWM
+ * -------------------------------------------------------------------- */
+static struct resource atmel_pwm0_resource[] __initdata = {
+       PBMEM(0xfff01400),
+       IRQ(24),
+};
+static struct clk atmel_pwm0_mck = {
+       .name           = "mck",
+       .parent         = &pbb_clk,
+       .mode           = pbb_clk_mode,
+       .get_rate       = pbb_clk_get_rate,
+       .index          = 5,
+};
+
+struct platform_device *__init at32_add_device_pwm(u32 mask)
+{
+       struct platform_device *pdev;
+
+       if (!mask)
+               return NULL;
+
+       pdev = platform_device_alloc("atmel_pwm", 0);
+       if (!pdev)
+               return NULL;
+
+       if (platform_device_add_resources(pdev, atmel_pwm0_resource,
+                               ARRAY_SIZE(atmel_pwm0_resource)))
+               goto out_free_pdev;
+
+       if (platform_device_add_data(pdev, &mask, sizeof(mask)))
+               goto out_free_pdev;
+
+       if (mask & (1 << 0))
+               select_peripheral(PA(28), PERIPH_A, 0);
+       if (mask & (1 << 1))
+               select_peripheral(PA(29), PERIPH_A, 0);
+       if (mask & (1 << 2))
+               select_peripheral(PA(21), PERIPH_B, 0);
+       if (mask & (1 << 3))
+               select_peripheral(PA(22), PERIPH_B, 0);
+
+       atmel_pwm0_mck.dev = &pdev->dev;
+
+       platform_device_add(pdev);
+
+       return pdev;
+
+out_free_pdev:
+       platform_device_put(pdev);
+       return NULL;
+}
+
 /* --------------------------------------------------------------------
  *  SSC
  * -------------------------------------------------------------------- */
@@ -1646,6 +1699,7 @@ struct clk *at32_clock_list[] = {
        &atmel_usart1_usart,
        &atmel_usart2_usart,
        &atmel_usart3_usart,
+       &atmel_pwm0_mck,
 #if defined(CONFIG_CPU_AT32AP7000)
        &macb0_hclk,
        &macb0_pclk,
index 023dc80af1875864d8f350334fd5858e0ea78799..6b8459c661631b1ce9364bb50a6da36c3103766a 100644 (file)
@@ -31,7 +31,6 @@
 #include <linux/smp_lock.h>
 #include <linux/unistd.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/uaccess.h>
 #include <linux/fs.h>
 #include <linux/err.h>
index 6e106b3d7729f2f8832107babf496d69ed6c4c91..289ea9d7fcdbb72763cb17b0136061ffefb0c3f3 100644 (file)
@@ -700,7 +700,7 @@ static void c_stop(struct seq_file *m, void *v)
 {
 }
 
-struct seq_operations cpuinfo_op = {
+const struct seq_operations cpuinfo_op = {
        .start = c_start,
        .next = c_next,
        .stop = c_stop,
index 27b082ac7f11e25e8d6b292b54af2c932f259217..ff078e60e76da8f2b9ef0753287b8407d44d277f 100644 (file)
@@ -55,6 +55,10 @@ config CRIS
        bool
        default y
 
+config HZ
+       int
+       default 100
+
 source "init/Kconfig"
 
 menu "General setup"
index 4da042e100a0ab3a61b22eb069a8013a04a92b1b..c34fb235b09f9214e243a44005ef42bbc555ac30 100644 (file)
@@ -180,7 +180,7 @@ static void c_stop(struct seq_file *m, void *v)
 
 extern int show_cpuinfo(struct seq_file *m, void *v);
 
-struct seq_operations cpuinfo_op = {
+const struct seq_operations cpuinfo_op = {
        .start = c_start,
        .next  = c_next,
        .stop  = c_stop,
index 96f7d70f4473681dc3f155b31c00215a55267257..9e561ede0925b6928bb44907c1bcde6ee4139d43 100644 (file)
@@ -57,6 +57,10 @@ config ARCH_HAS_ILOG2_U64
        bool
        default y
 
+config HZ
+       int
+       default 1000
+
 mainmenu "Fujitsu FR-V Kernel Configuration"
 
 source "init/Kconfig"
index 6c01464db699419a2b5e8068325c1791ad356188..0669e13823831d5b994ac6daa439bd346f8943b1 100644 (file)
@@ -1113,7 +1113,7 @@ static void c_stop(struct seq_file *m, void *v)
 {
 }
 
-struct seq_operations cpuinfo_op = {
+const struct seq_operations cpuinfo_op = {
        .start  = c_start,
        .next   = c_next,
        .stop   = c_stop,
index 1a2e5c8d03a9c7e639ab354705a08cb0916bb443..66f616fb4860a779d5cc1eafa68d48d41b4db0e2 100644 (file)
@@ -28,7 +28,7 @@ pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
        return pte;
 }
 
-struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
+pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
 {
        struct page *page;
 
@@ -37,9 +37,11 @@ struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
 #else
        page = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0);
 #endif
-       if (page)
+       if (page) {
                clear_highpage(page);
-       flush_dcache_page(page);
+               pgtable_page_ctor(page);
+               flush_dcache_page(page);
+       }
        return page;
 }
 
index dc61222e11207b1d802481aa4dfdd4fd788e20b8..f69e5ea385588d0c554fe5f0d3ca2ff82f8c2138 100644 (file)
@@ -65,6 +65,9 @@ config TIME_LOW_RES
        bool
        default y
 
+config ARCH_SUPPORTS_AOUT
+       def_bool y
+
 config NO_IOPORT
        def_bool y
 
@@ -79,6 +82,10 @@ config PCI
        bool
        default n
 
+config HZ
+       int
+       default 100
+
 source "init/Kconfig"
 
 source "arch/h8300/Kconfig.cpu"
index cd3734614d9df93cd21787e4adca354ef2a8ecc6..b1f25c20a5dbdb8f6c1a2c4a29e61546499ce3e7 100644 (file)
@@ -236,7 +236,7 @@ static void c_stop(struct seq_file *m, void *v)
 {
 }
 
-struct seq_operations cpuinfo_op = {
+const struct seq_operations cpuinfo_op = {
        .start  = c_start,
        .next   = c_next,
        .stop   = c_stop,
index 3ab04272097031c19f5000bb07c9e606412df2f7..17fda5293c6716392d17a62bc24329e759df8415 100644 (file)
@@ -49,13 +49,13 @@ EXPORT_SYMBOL(last_cli_ip);
 #endif
 
 static struct clocksource clocksource_itc = {
-        .name           = "itc",
-        .rating         = 350,
-        .read           = itc_get_cycles,
-        .mask           = CLOCKSOURCE_MASK(64),
-        .mult           = 0, /*to be caluclated*/
-        .shift          = 16,
-        .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
+       .name           = "itc",
+       .rating         = 350,
+       .read           = itc_get_cycles,
+       .mask           = CLOCKSOURCE_MASK(64),
+       .mult           = 0, /*to be calculated*/
+       .shift          = 16,
+       .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 static struct clocksource *itc_clocksource;
 
index 795180b8fd8e6199e56d118fec12f09a3079eb35..d4679ab55b969c3fe8bfc4f88dfef02d618e1877 100644 (file)
@@ -35,6 +35,13 @@ config NO_IOPORT
 config NO_DMA
        def_bool y
 
+config ARCH_SUPPORTS_AOUT
+       def_bool y
+
+config HZ
+       int
+       default 100
+
 source "init/Kconfig"
 
 
index f1f5db0c40846b3b39e65368996dea3c80a952b7..0392112a5d702cd2859245967a7357640bada5e9 100644 (file)
@@ -369,7 +369,7 @@ static void c_stop(struct seq_file *m, void *v)
 {
 }
 
-struct seq_operations cpuinfo_op = {
+const struct seq_operations cpuinfo_op = {
        .start = c_start,
        .next = c_next,
        .stop = c_stop,
index ffabd01c45eb1e4309680210cd30821cf4591864..2b0ed89cd173728ddda8ad3ea201977c5ee0484c 100644 (file)
@@ -52,6 +52,13 @@ config NO_IOPORT
 config NO_DMA
        def_bool SUN3
 
+config ARCH_SUPPORTS_AOUT
+       def_bool y
+
+config HZ
+       int
+       default 100
+
 mainmenu "Linux/68k Kernel Configuration"
 
 source "init/Kconfig"
index 3ee918695215791b10f01ca19e9095b094cf35f5..5de4e4ed76abd4daf3f2483c2df36d2ede861d74 100644 (file)
@@ -23,7 +23,6 @@
 #include <linux/ptrace.h>
 #include <linux/slab.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/reboot.h>
 #include <linux/init_task.h>
 #include <linux/mqueue.h>
@@ -315,53 +314,6 @@ int dump_fpu (struct pt_regs *regs, struct user_m68kfp_struct *fpu)
 }
 EXPORT_SYMBOL(dump_fpu);
 
-/*
- * fill in the user structure for a core dump..
- */
-void dump_thread(struct pt_regs * regs, struct user * dump)
-{
-       struct switch_stack *sw;
-
-/* changed the size calculations - should hopefully work better. lbt */
-       dump->magic = CMAGIC;
-       dump->start_code = 0;
-       dump->start_stack = rdusp() & ~(PAGE_SIZE - 1);
-       dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
-       dump->u_dsize = ((unsigned long) (current->mm->brk +
-                                         (PAGE_SIZE-1))) >> PAGE_SHIFT;
-       dump->u_dsize -= dump->u_tsize;
-       dump->u_ssize = 0;
-
-       if (dump->start_stack < TASK_SIZE)
-               dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
-
-       dump->u_ar0 = (struct user_regs_struct *)((int)&dump->regs - (int)dump);
-       sw = ((struct switch_stack *)regs) - 1;
-       dump->regs.d1 = regs->d1;
-       dump->regs.d2 = regs->d2;
-       dump->regs.d3 = regs->d3;
-       dump->regs.d4 = regs->d4;
-       dump->regs.d5 = regs->d5;
-       dump->regs.d6 = sw->d6;
-       dump->regs.d7 = sw->d7;
-       dump->regs.a0 = regs->a0;
-       dump->regs.a1 = regs->a1;
-       dump->regs.a2 = regs->a2;
-       dump->regs.a3 = sw->a3;
-       dump->regs.a4 = sw->a4;
-       dump->regs.a5 = sw->a5;
-       dump->regs.a6 = sw->a6;
-       dump->regs.d0 = regs->d0;
-       dump->regs.orig_d0 = regs->orig_d0;
-       dump->regs.stkadj = regs->stkadj;
-       dump->regs.sr = regs->sr;
-       dump->regs.pc = regs->pc;
-       dump->regs.fmtvec = (regs->format << 12) | regs->vector;
-       /* dump floating point stuff */
-       dump->u_fpvalid = dump_fpu (regs, &dump->m68kfp);
-}
-EXPORT_SYMBOL(dump_thread);
-
 /*
  * sys_execve() executes a new program.
  */
index 9a06c48edcb3c47468a0db8163d116eaaa9d032c..bba650312fd9fa65ac73d3408017cee1e3fb2dce 100644 (file)
@@ -450,7 +450,7 @@ static void *c_next(struct seq_file *m, void *v, loff_t *pos)
 static void c_stop(struct seq_file *m, void *v)
 {
 }
-struct seq_operations cpuinfo_op = {
+const struct seq_operations cpuinfo_op = {
        .start  = c_start,
        .next   = c_next,
        .stop   = c_stop,
index 97f556fa493290822dea1673986d1b269c23bcfe..fd4858e2dd638d456636dee4dcdc9b9134c34b3c 100644 (file)
@@ -23,7 +23,6 @@
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/module.h>
-#include <linux/a.out.h>
 #include <linux/user.h>
 #include <linux/string.h>
 #include <linux/linkage.h>
index 6abbbb8aac5ebc733f7e4eb8cc8df3df6ef3959c..548a7b321633c670b358f190e2a92a54a694ba45 100644 (file)
@@ -64,6 +64,9 @@ config TIME_LOW_RES
 config NO_IOPORT
        def_bool y
 
+config ARCH_SUPPORTS_AOUT
+       def_bool y
+
 source "init/Kconfig"
 
 menu "Processor type and features"
@@ -522,6 +525,11 @@ config 4KSTACKS
          running more threads on a system and also reduces the pressure
          on the VM subsystem for higher order allocations.
 
+config HZ
+       int
+       default 1000 if CLEOPATRA
+       default 100
+
 comment "RAM configuration"
 
 config RAMBASE
index 156c6c662c7e87fa3feabf82cc83c6b9c10e6e7e..d6f0200316febaa7f8f1fb76c09c0b96e91b0ad1 100644 (file)
@@ -260,7 +260,7 @@ static void c_stop(struct seq_file *m, void *v)
 {
 }
 
-struct seq_operations cpuinfo_op = {
+const struct seq_operations cpuinfo_op = {
        .start  = c_start,
        .next   = c_next,
        .stop   = c_stop,
index 197d7977de356e603465f62e780f945eb3dbe16f..413bd1d37f5499171e4337b78ee62f387152d811 100644 (file)
@@ -338,8 +338,10 @@ void __init init_i8259_irqs(void)
 
        init_8259A(0);
 
-       for (i = I8259A_IRQ_BASE; i < I8259A_IRQ_BASE + 16; i++)
+       for (i = I8259A_IRQ_BASE; i < I8259A_IRQ_BASE + 16; i++) {
                set_irq_chip_and_handler(i, &i8259A_chip, handle_level_irq);
+               set_irq_probe(i);
+       }
 
        setup_irq(I8259A_IRQ_BASE + PIC_CASCADE_IR, &irq2);
 }
index 7852c7cdf29e7e5d575d049d5367a57ed4f21fe5..290d8e3a664d71bd71e2fb582dd004025a06b34d 100644 (file)
@@ -591,9 +591,9 @@ static void irix_map_prda_page(void)
                return;
 
        pp = (struct prda *) v;
-       pp->prda_sys.t_pid  = current->pid;
+       pp->prda_sys.t_pid  = task_pid_vnr(current);
        pp->prda_sys.t_prid = read_c0_prid();
-       pp->prda_sys.t_rpid = current->pid;
+       pp->prda_sys.t_rpid = task_pid_vnr(current);
 
        /* We leave the rest set to zero */
 }
@@ -1170,11 +1170,11 @@ static int irix_core_dump(long signr, struct pt_regs *regs, struct file *file, u
        prstatus.pr_info.si_signo = prstatus.pr_cursig = signr;
        prstatus.pr_sigpend = current->pending.signal.sig[0];
        prstatus.pr_sighold = current->blocked.sig[0];
-       psinfo.pr_pid = prstatus.pr_pid = current->pid;
-       psinfo.pr_ppid = prstatus.pr_ppid = current->parent->pid;
-       psinfo.pr_pgrp = prstatus.pr_pgrp = task_pgrp_nr(current);
-       psinfo.pr_sid = prstatus.pr_sid = task_session_nr(current);
-       if (current->pid == current->tgid) {
+       psinfo.pr_pid = prstatus.pr_pid = task_pid_vnr(current);
+       psinfo.pr_ppid = prstatus.pr_ppid = task_pid_vnr(current->parent);
+       psinfo.pr_pgrp = prstatus.pr_pgrp = task_pgrp_vnr(current);
+       psinfo.pr_sid = prstatus.pr_sid = task_session_vnr(current);
+       if (thread_group_leader(current)) {
                /*
                 * This is the record for the group leader.  Add in the
                 * cumulative times of previous dead threads.  This total
index 5b10ac133ec837b4ccd91844a42321d6a68769fd..0215c805a592849cf3bc529e5e3b1020a82e7dc5 100644 (file)
@@ -578,10 +578,11 @@ out:
 
 #define W_MASK      (W_EXITED | W_TRAPPED | W_STOPPED | W_CONT | W_NOHANG)
 
-asmlinkage int irix_waitsys(int type, int pid,
+asmlinkage int irix_waitsys(int type, int upid,
        struct irix5_siginfo __user *info, int options,
        struct rusage __user *ru)
 {
+       struct pid *pid = NULL;
        int flag, retval;
        DECLARE_WAITQUEUE(wait, current);
        struct task_struct *tsk;
@@ -604,6 +605,8 @@ asmlinkage int irix_waitsys(int type, int pid,
        if (type != IRIX_P_PID && type != IRIX_P_PGID && type != IRIX_P_ALL)
                return -EINVAL;
 
+       if (type != IRIX_P_ALL)
+               pid = find_get_pid(upid);
        add_wait_queue(&current->signal->wait_chldexit, &wait);
 repeat:
        flag = 0;
@@ -612,9 +615,9 @@ repeat:
        tsk = current;
        list_for_each(_p, &tsk->children) {
                p = list_entry(_p, struct task_struct, sibling);
-               if ((type == IRIX_P_PID) && p->pid != pid)
+               if ((type == IRIX_P_PID) && task_pid(p) != pid)
                        continue;
-               if ((type == IRIX_P_PGID) && task_pgrp_nr(p) != pid)
+               if ((type == IRIX_P_PGID) && task_pgrp(p) != pid)
                        continue;
                if ((p->exit_signal != SIGCHLD))
                        continue;
@@ -639,7 +642,7 @@ repeat:
 
                        retval = __put_user(SIGCHLD, &info->sig);
                        retval |= __put_user(0, &info->code);
-                       retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
+                       retval |= __put_user(task_pid_vnr(p), &info->stuff.procinfo.pid);
                        retval |= __put_user((p->exit_code >> 8) & 0xff,
                                   &info->stuff.procinfo.procdata.child.status);
                        retval |= __put_user(p->utime, &info->stuff.procinfo.procdata.child.utime);
@@ -657,7 +660,7 @@ repeat:
                                getrusage(p, RUSAGE_BOTH, ru);
                        retval = __put_user(SIGCHLD, &info->sig);
                        retval |= __put_user(1, &info->code);      /* CLD_EXITED */
-                       retval |= __put_user(p->pid, &info->stuff.procinfo.pid);
+                       retval |= __put_user(task_pid_vnr(p), &info->stuff.procinfo.pid);
                        retval |= __put_user((p->exit_code >> 8) & 0xff,
                                   &info->stuff.procinfo.procdata.child.status);
                        retval |= __put_user(p->utime,
@@ -665,7 +668,7 @@ repeat:
                        retval |= __put_user(p->stime,
                                   &info->stuff.procinfo.procdata.child.stime);
                        if (retval)
-                               return retval;
+                               goto end_waitsys;
 
                        if (p->real_parent != p->parent) {
                                write_lock_irq(&tasklist_lock);
@@ -698,6 +701,7 @@ repeat:
 end_waitsys:
        current->state = TASK_RUNNING;
        remove_wait_queue(&current->signal->wait_chldexit, &wait);
+       put_pid(pid);
 
        return retval;
 }
index d06e9c9af7909f15637c081883cb282f482a90f7..e3309ff9ece402867d86d8fcaa03187c45c6ca00 100644 (file)
@@ -145,6 +145,11 @@ __setup("nokgdb", nokgdb);
 
 void __init init_IRQ(void)
 {
+       int i;
+
+       for (i = 0; i < NR_IRQS; i++)
+               set_irq_noprobe(i);
+
        arch_init_irq();
 
 #ifdef CONFIG_KGDB
index 22fd41e946b28c3d9e2a8a853c4951bcada5b629..d70c4e0e85fb3e81a86d4d77eade217b52007eac 100644 (file)
@@ -582,8 +582,8 @@ out:
 
 asmlinkage int irix_getpid(struct pt_regs *regs)
 {
-       regs->regs[3] = current->real_parent->pid;
-       return current->pid;
+       regs->regs[3] = task_pid_vnr(current->real_parent);
+       return task_pid_vnr(current);
 }
 
 asmlinkage int irix_getuid(struct pt_regs *regs)
@@ -763,11 +763,11 @@ asmlinkage int irix_setpgrp(int flags)
        printk("[%s:%d] setpgrp(%d) ", current->comm, current->pid, flags);
 #endif
        if(!flags)
-               error = task_pgrp_nr(current);
+               error = task_pgrp_vnr(current);
        else
                error = sys_setsid();
 #ifdef DEBUG_PROCGRPS
-       printk("returning %d\n", task_pgrp_nr(current));
+       printk("returning %d\n", error);
 #endif
 
        return error;
@@ -1093,10 +1093,10 @@ asmlinkage int irix_BSDsetpgrp(int pid, int pgrp)
               pid, pgrp);
 #endif
        if(!pid)
-               pid = current->pid;
+               pid = task_pid_vnr(current);
 
        /* Wheee, weird sysv thing... */
-       if ((pgrp == 0) && (pid == current->pid))
+       if ((pgrp == 0) && (pid == task_pid_vnr(current)))
                error = sys_setsid();
        else
                error = sys_setpgid(pid, pgrp);
diff --git a/arch/mn10300/Kconfig b/arch/mn10300/Kconfig
new file mode 100644 (file)
index 0000000..eedc3a5
--- /dev/null
@@ -0,0 +1,381 @@
+#
+# For a description of the syntax of this configuration file,
+# see Documentation/kbuild/kconfig-language.txt.
+#
+
+mainmenu "Linux Kernel Configuration"
+
+config MN10300
+       def_bool y
+
+config AM33
+       def_bool y
+
+config MMU
+       def_bool y
+
+config HIGHMEM
+       def_bool n
+
+config NUMA
+       def_bool n
+
+config UID16
+       def_bool y
+
+config RWSEM_GENERIC_SPINLOCK
+       def_bool y
+
+config RWSEM_XCHGADD_ALGORITHM
+       bool
+
+config GENERIC_HARDIRQS_NO__DO_IRQ
+       def_bool y
+
+config GENERIC_CALIBRATE_DELAY
+       def_bool y
+
+config GENERIC_FIND_NEXT_BIT
+       def_bool y
+
+config GENERIC_HWEIGHT
+       def_bool y
+
+config GENERIC_TIME
+       def_bool y
+
+config GENERIC_BUG
+       def_bool y
+
+config QUICKLIST
+       def_bool y
+
+config ARCH_HAS_ILOG2_U32
+       def_bool y
+
+config ARCH_SUPPORTS_AOUT
+       def_bool n
+
+# Use the generic interrupt handling code in kernel/irq/
+config GENERIC_HARDIRQS
+       def_bool y
+
+config HOTPLUG_CPU
+       def_bool n
+
+mainmenu "Matsushita MN10300/AM33 Kernel Configuration"
+
+source "init/Kconfig"
+
+
+menu "Matsushita MN10300 system setup"
+
+choice
+       prompt "Unit type"
+       default MN10300_UNIT_ASB2303
+       help
+         This option specifies board for which the kernel will be
+         compiled. It affects the external peripherals catered for.
+
+config MN10300_UNIT_ASB2303
+       bool "ASB2303"
+
+config MN10300_UNIT_ASB2305
+       bool "ASB2305"
+
+endchoice
+
+choice
+       prompt "Processor support"
+       default MN10300_PROC_MN103E010
+       help
+         This option specifies the processor for which the kernel will be
+         compiled. It affects the on-chip peripherals catered for.
+
+config MN10300_PROC_MN103E010
+       bool "MN103E010"
+       depends on MN10300_UNIT_ASB2303 || MN10300_UNIT_ASB2305
+       select MN10300_PROC_HAS_TTYSM0
+       select MN10300_PROC_HAS_TTYSM1
+       select MN10300_PROC_HAS_TTYSM2
+
+endchoice
+
+choice
+       prompt "Processor core support"
+       default MN10300_CPU_AM33V2
+       help
+         This option specifies the processor core for which the kernel will be
+         compiled. It affects the instruction set used.
+
+config MN10300_CPU_AM33V2
+       bool "AM33v2"
+
+endchoice
+
+config FPU
+       bool "FPU present"
+       default y
+       depends on MN10300_PROC_MN103E010
+
+choice
+       prompt "CPU Caching mode"
+       default MN10300_CACHE_WBACK
+       help
+         This option determines the caching mode for the kernel.
+
+         Write-Back caching mode involves the all reads and writes causing
+         the affected cacheline to be read into the cache first before being
+         operated upon. Memory is not then updated by a write until the cache
+         is filled and a cacheline needs to be displaced from the cache to
+         make room. Only at that point is it written back.
+
+         Write-Through caching only fetches cachelines from memory on a
+         read. Writes always get written directly to memory. If the affected
+         cacheline is also in cache, it will be updated too.
+
+         The final option is to turn of caching entirely.
+
+config MN10300_CACHE_WBACK
+       bool "Write-Back"
+
+config MN10300_CACHE_WTHRU
+       bool "Write-Through"
+
+config MN10300_CACHE_DISABLED
+       bool "Disabled"
+
+endchoice
+
+menu "Memory layout options"
+
+config KERNEL_RAM_BASE_ADDRESS
+       hex "Base address of kernel RAM"
+       default "0x90000000"
+
+config INTERRUPT_VECTOR_BASE
+       hex "Base address of vector table"
+       default "0x90000000"
+       help
+         The base address of the vector table will be programmed into
+          the TBR register. It must be on 16MiB address boundary.
+
+config KERNEL_TEXT_ADDRESS
+       hex "Base address of kernel"
+       default "0x90001000"
+
+config KERNEL_ZIMAGE_BASE_ADDRESS
+       hex "Base address of compressed vmlinux image"
+       default "0x90700000"
+
+endmenu
+
+config PREEMPT
+       bool "Preemptible Kernel"
+       help
+         This option reduces the latency of the kernel when reacting to
+         real-time or interactive events by allowing a low priority process to
+         be preempted even if it is in kernel mode executing a system call.
+         This allows applications to run more reliably even when the system is
+         under load.
+
+         Say Y here if you are building a kernel for a desktop, embedded
+         or real-time system.  Say N if you are unsure.
+
+config PREEMPT_BKL
+       bool "Preempt The Big Kernel Lock"
+       depends on PREEMPT
+       default y
+       help
+         This option reduces the latency of the kernel by making the
+         big kernel lock preemptible.
+
+         Say Y here if you are building a kernel for a desktop system.
+         Say N if you are unsure.
+
+config MN10300_CURRENT_IN_E2
+       bool "Hold current task address in E2 register"
+       default y
+       help
+         This option removes the E2/R2 register from the set available to gcc
+         for normal use and instead uses it to store the address of the
+         current process's task_struct whilst in the kernel.
+
+         This means the kernel doesn't need to calculate the address each time
+         "current" is used (take SP, AND with mask and dereference pointer
+         just to get the address), and instead can just use E2+offset
+         addressing each time.
+
+         This has no effect on userspace.
+
+config MN10300_USING_JTAG
+       bool "Using JTAG to debug kernel"
+       default y
+       help
+         This options indicates that JTAG will be used to debug the kernel. It
+         suppresses the use of certain hardware debugging features, such as
+         single-stepping, which are taken over completely by the JTAG unit.
+
+config MN10300_RTC
+       bool "Using MN10300 RTC"
+       depends on MN10300_PROC_MN103E010
+       default n
+       help
+
+         This option enables support for the RTC, thus enabling time to be
+         tracked, even when system is powered down. This is available on-chip
+         on the MN103E010.
+
+config MN10300_WD_TIMER
+       bool "Using MN10300 watchdog timer"
+       default y
+       help
+         This options indicates that the watchdog timer will be used.
+
+config PCI
+       bool "Use PCI"
+       depends on MN10300_UNIT_ASB2305
+       default y
+       help
+         Some systems (such as the ASB2305) have PCI onboard. If you have one
+         of these boards and you wish to use the PCI facilities, say Y here.
+
+         The PCI-HOWTO, available from
+         <http://www.tldp.org/docs.html#howto>, contains valuable
+         information about which PCI hardware does work under Linux and which
+         doesn't.
+
+source "drivers/pci/Kconfig"
+
+source "drivers/pcmcia/Kconfig"
+
+menu "MN10300 internal serial options"
+
+config MN10300_PROC_HAS_TTYSM0
+       bool
+       default n
+
+config MN10300_PROC_HAS_TTYSM1
+       bool
+       default n
+
+config MN10300_PROC_HAS_TTYSM2
+       bool
+       default n
+
+config MN10300_TTYSM
+       bool "Support for ttySM serial ports"
+       depends on MN10300
+       default y
+       select SERIAL_CORE
+       help
+         This option enables support for the on-chip serial ports that the
+         MN10300 has available.
+
+config MN10300_TTYSM_CONSOLE
+       bool "Support for console on ttySM serial ports"
+       depends on MN10300_TTYSM
+       select SERIAL_CORE_CONSOLE
+       help
+         This option enables support for a console on the on-chip serial ports
+         that the MN10300 has available.
+
+#
+# /dev/ttySM0
+#
+config MN10300_TTYSM0
+       bool "Enable SIF0 (/dev/ttySM0)"
+       depends on MN10300_TTYSM && MN10300_PROC_HAS_TTYSM0
+       help
+         Enable access to SIF0 through /dev/ttySM0 or gdb-stub
+
+choice
+       prompt "Select the timer to supply the clock for SIF0"
+       default MN10300_TTYSM0_TIMER8
+       depends on MN10300_TTYSM0
+
+config MN10300_TTYSM0_TIMER8
+       bool "Use timer 8 (16-bit)"
+
+config MN10300_TTYSM0_TIMER2
+       bool "Use timer 2 (8-bit)"
+
+endchoice
+
+#
+# /dev/ttySM1
+#
+config MN10300_TTYSM1
+       bool "Enable SIF1 (/dev/ttySM1)"
+       depends on MN10300_TTYSM && MN10300_PROC_HAS_TTYSM1
+       help
+         Enable access to SIF1 through /dev/ttySM1 or gdb-stub
+
+choice
+       prompt "Select the timer to supply the clock for SIF1"
+       default MN10300_TTYSM0_TIMER9
+       depends on MN10300_TTYSM1
+
+config MN10300_TTYSM1_TIMER9
+       bool "Use timer 9 (16-bit)"
+
+config MN10300_TTYSM1_TIMER3
+       bool "Use timer 3 (8-bit)"
+
+endchoice
+
+#
+# /dev/ttySM2
+#
+config MN10300_TTYSM2
+       bool "Enable SIF2 (/dev/ttySM2)"
+       depends on MN10300_TTYSM && MN10300_PROC_HAS_TTYSM2
+       help
+         Enable access to SIF2 through /dev/ttySM2 or gdb-stub
+
+choice
+       prompt "Select the timer to supply the clock for SIF2"
+       default MN10300_TTYSM0_TIMER10
+       depends on MN10300_TTYSM2
+
+config MN10300_TTYSM2_TIMER10
+       bool "Use timer 10 (16-bit)"
+
+endchoice
+
+config MN10300_TTYSM2_CTS
+       bool "Enable the use of the CTS line /dev/ttySM2"
+       depends on MN10300_TTYSM2
+
+endmenu
+
+source "mm/Kconfig"
+
+menu "Power management options"
+source kernel/power/Kconfig
+endmenu
+
+endmenu
+
+
+menu "Executable formats"
+
+source "fs/Kconfig.binfmt"
+
+endmenu
+
+source "net/Kconfig"
+
+source "drivers/Kconfig"
+
+source "fs/Kconfig"
+
+source "arch/mn10300/Kconfig.debug"
+
+source "security/Kconfig"
+
+source "crypto/Kconfig"
+
+source "lib/Kconfig"
+
+source "arch/mn10300/oprofile/Kconfig"
diff --git a/arch/mn10300/Kconfig.debug b/arch/mn10300/Kconfig.debug
new file mode 100644 (file)
index 0000000..524e338
--- /dev/null
@@ -0,0 +1,135 @@
+menu "Kernel hacking"
+
+source "lib/Kconfig.debug"
+
+config DEBUG_STACKOVERFLOW
+       bool "Check for stack overflows"
+       depends on DEBUG_KERNEL
+
+config DEBUG_DECOMPRESS_KERNEL
+       bool "Using serial port during decompressing kernel"
+       depends on DEBUG_KERNEL
+       default n
+       help
+         If you say Y here you will confirm the start and the end of
+         decompressing Linux seeing "Uncompressing Linux... " and
+         "Ok, booting the kernel.\n" on console.
+
+config KPROBES
+       bool "Kprobes"
+       depends on DEBUG_KERNEL
+       help
+         Kprobes allows you to trap at almost any kernel address and
+         execute a callback function.  register_kprobe() establishes
+         a probepoint and specifies the callback.  Kprobes is useful
+         for kernel debugging, non-intrusive instrumentation and testing.
+         If in doubt, say "N".
+
+config GDBSTUB
+       bool "Remote GDB kernel debugging"
+       depends on DEBUG_KERNEL
+       select DEBUG_INFO
+       select FRAME_POINTER
+       help
+         If you say Y here, it will be possible to remotely debug the kernel
+         using gdb. This enlarges your kernel ELF image disk size by several
+         megabytes and requires a machine with more than 16 MB, better 32 MB
+         RAM to avoid excessive linking time. This is only useful for kernel
+         hackers. If unsure, say N.
+
+config GDBSTUB_IMMEDIATE
+       bool "Break into GDB stub immediately"
+       depends on GDBSTUB
+       help
+         If you say Y here, GDB stub will break into the program as soon as
+         possible, leaving the program counter at the beginning of
+         start_kernel() in init/main.c.
+
+config GDB_CONSOLE
+       bool "Console output to GDB"
+       depends on GDBSTUB
+       help
+         If you are using GDB for remote debugging over a serial port and
+         would like kernel messages to be formatted into GDB $O packets so
+         that GDB prints them as program output, say 'Y'.
+
+config GDBSTUB_DEBUGGING
+       bool "Debug GDB stub by messages to serial port"
+       depends on GDBSTUB
+       help
+         This causes debugging messages to be displayed at various points
+         during execution of the GDB stub routines. Such messages will be
+         displayed on ttyS0 if that isn't the GDB stub's port, or ttySM0
+         otherwise.
+
+config GDBSTUB_DEBUG_ENTRY
+       bool "Debug GDB stub entry"
+       depends on GDBSTUB_DEBUGGING
+       help
+         This option causes information to be displayed about entry to or exit
+         from the main GDB stub routine.
+
+config GDBSTUB_DEBUG_PROTOCOL
+       bool "Debug GDB stub protocol"
+       depends on GDBSTUB_DEBUGGING
+       help
+         This option causes information to be displayed about the GDB remote
+         protocol messages generated exchanged with GDB.
+
+config GDBSTUB_DEBUG_IO
+       bool "Debug GDB stub I/O"
+       depends on GDBSTUB_DEBUGGING
+       help
+         This option causes information to be displayed about GDB stub's
+         low-level I/O.
+
+config GDBSTUB_DEBUG_BREAKPOINT
+       bool "Debug GDB stub breakpoint management"
+       depends on GDBSTUB_DEBUGGING
+       help
+         This option causes information to be displayed about GDB stub's
+         breakpoint management.
+
+choice
+       prompt "GDB stub port"
+       default GDBSTUB_TTYSM0
+       depends on GDBSTUB
+       help
+         Select the serial port used for GDB-stub.
+
+config GDBSTUB_ON_TTYSM0
+       bool "/dev/ttySM0 [SIF0]"
+       depends on MN10300_TTYSM0
+       select GDBSTUB_ON_TTYSMx
+
+config GDBSTUB_ON_TTYSM1
+       bool "/dev/ttySM1 [SIF1]"
+       depends on MN10300_TTYSM1
+       select GDBSTUB_ON_TTYSMx
+
+config GDBSTUB_ON_TTYSM2
+       bool "/dev/ttySM2 [SIF2]"
+       depends on MN10300_TTYSM2
+       select GDBSTUB_ON_TTYSMx
+
+config GDBSTUB_ON_TTYS0
+       bool "/dev/ttyS0"
+       select GDBSTUB_ON_TTYSx
+
+config GDBSTUB_ON_TTYS1
+       bool "/dev/ttyS1"
+       select GDBSTUB_ON_TTYSx
+
+endchoice
+
+config GDBSTUB_ON_TTYSMx
+       bool
+       depends on GDBSTUB_ON_TTYSM0 || GDBSTUB_ON_TTYSM1 || GDBSTUB_ON_TTYSM2
+       default y
+
+config GDBSTUB_ON_TTYSx
+       bool
+       depends on GDBSTUB_ON_TTYS0 || GDBSTUB_ON_TTYS1
+       default y
+
+endmenu
diff --git a/arch/mn10300/Makefile b/arch/mn10300/Makefile
new file mode 100644 (file)
index 0000000..6673a28
--- /dev/null
@@ -0,0 +1,135 @@
+###############################################################################
+#
+# MN10300 Kernel makefile system specifications
+#
+# Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+# Modified by David Howells (dhowells@redhat.com)
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public Licence
+# as published by the Free Software Foundation; either version
+# 2 of the Licence, or (at your option) any later version.
+#
+###############################################################################
+
+KBUILD_DEFCONFIG := asb2303_defconfig
+
+CCSPECS        := $(shell $(CC) -v 2>&1 | grep "^Reading specs from " | head -1 | cut -c20-)
+CCDIR  := $(strip $(patsubst %/specs,%,$(CCSPECS)))
+KBUILD_CPPFLAGS += -nostdinc -I$(CCDIR)/include
+
+LDFLAGS                :=
+OBJCOPYFLAGS   := -O binary -R .note -R .comment -S
+#LDFLAGS_vmlinux := -Map linkmap.txt
+CHECKFLAGS     +=
+
+PROCESSOR      := unset
+UNIT           := unset
+
+KBUILD_CFLAGS  += -mam33 -mmem-funcs -DCPU=AM33
+KBUILD_AFLAGS  += -mam33 -DCPU=AM33
+
+ifeq ($(CONFIG_MN10300_CURRENT_IN_E2),y)
+KBUILD_CFLAGS  += -ffixed-e2 -fcall-saved-e5
+endif
+
+ifeq ($(CONFIG_MN10300_PROC_MN103E010),y)
+PROCESSOR      := mn103e010
+endif
+
+ifeq ($(CONFIG_MN10300_UNIT_ASB2303),y)
+UNIT           := asb2303
+endif
+ifeq ($(CONFIG_MN10300_UNIT_ASB2305),y)
+UNIT           := asb2305
+endif
+
+
+head-y         := arch/mn10300/kernel/head.o arch/mn10300/kernel/init_task.o
+
+core-y         += arch/mn10300/kernel/ arch/mn10300/mm/
+
+ifneq ($(PROCESSOR),unset)
+core-y         += arch/mn10300/proc-$(PROCESSOR)/
+endif
+ifneq ($(UNIT),unset)
+core-y         += arch/mn10300/unit-$(UNIT)/
+endif
+libs-y         += arch/mn10300/lib/
+
+drivers-$(CONFIG_OPROFILE)     += arch/mn10300/oprofile/
+
+boot := arch/mn10300/boot
+
+.PHONY: zImage
+
+KBUILD_IMAGE := $(boot)/zImage
+CLEAN_FILES += $(boot)/zImage
+CLEAN_FILES += $(boot)/compressed/vmlinux
+CLEAN_FILES += $(boot)/compressed/vmlinux.bin
+CLEAN_FILES += $(boot)/compressed/vmlinux.bin.gz
+
+zImage: vmlinux
+       $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
+
+all: zImage
+
+bootstrap:
+       $(Q)$(MAKEBOOT) bootstrap
+
+archclean:
+       $(Q)$(MAKE) $(clean)=arch/mn10300/proc-mn103e010
+       $(Q)$(MAKE) $(clean)=arch/mn10300/unit-asb2303
+       $(Q)$(MAKE) $(clean)=arch/mn10300/unit-asb2305
+
+define archhelp
+  echo  '* zImage        - Compressed kernel image (arch/$(ARCH)/boot/zImage)'
+endef
+
+# If you make sure the .S files get compiled with debug info,
+# uncomment the following to disable optimisations
+# that are unhelpful whilst debugging.
+ifdef CONFIG_DEBUG_INFO
+#KBUILD_CFLAGS += -O1
+KBUILD_AFLAGS  += -Wa,--gdwarf2
+endif
+
+###################################################################################################
+#
+# juggle some symlinks in the MN10300 asm include dir
+#
+#      Update machine proc and unit symlinks if something which affects
+#      them changed.  We use .proc / .unit to indicate when they were
+#      updated last, otherwise make uses the target directory mtime.
+#
+###################################################################################################
+
+# processor specific definitions
+include/asm-mn10300/.proc: $(wildcard include/config/proc/*.h) include/config/auto.conf
+       @echo '  SYMLINK include/asm-mn10300/proc -> include/asm-mn10300/proc-$(PROCESSOR)'
+ifneq ($(KBUILD_SRC),)
+       $(Q)mkdir -p include/asm-mn10300
+       $(Q)ln -fsn $(srctree)/include/asm-mn10300/proc-$(PROCESSOR) include/asm-mn10300/proc
+else
+       $(Q)ln -fsn proc-$(PROCESSOR) include/asm-mn10300/proc
+endif
+       @touch $@
+
+CLEAN_FILES += include/asm-mn10300/proc include/asm-mn10300/.proc
+
+prepare: include/asm-mn10300/.proc
+
+# unit specific definitions
+include/asm-mn10300/.unit: $(wildcard include/config/unit/*.h) include/config/auto.conf
+       @echo '  SYMLINK include/asm-mn10300/unit -> include/asm-mn10300/unit-$(UNIT)'
+ifneq ($(KBUILD_SRC),)
+       $(Q)mkdir -p include/asm-mn10300
+       $(Q)ln -fsn $(srctree)/include/asm-mn10300/unit-$(UNIT) include/asm-mn10300/unit
+else
+       $(Q)ln -fsn unit-$(UNIT) include/asm-mn10300/unit
+endif
+       @touch $@
+
+CLEAN_FILES += include/asm-mn10300/unit include/asm-mn10300/.unit
+
+prepare: include/asm-mn10300/.unit
diff --git a/arch/mn10300/boot/.gitignore b/arch/mn10300/boot/.gitignore
new file mode 100644 (file)
index 0000000..b6718de
--- /dev/null
@@ -0,0 +1 @@
+zImage
diff --git a/arch/mn10300/boot/Makefile b/arch/mn10300/boot/Makefile
new file mode 100644 (file)
index 0000000..36c9caf
--- /dev/null
@@ -0,0 +1,28 @@
+# MN10300 kernel compressor and wrapper
+#
+# Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+# Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+# Written by David Howells (dhowells@redhat.com)
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public Licence
+# as published by the Free Software Foundation; either version
+# 2 of the Licence, or (at your option) any later version.
+#
+
+targets                := vmlinux.bin zImage
+
+subdir-        := compressed
+
+# ---------------------------------------------------------------------------
+
+
+$(obj)/zImage: $(obj)/compressed/vmlinux FORCE
+       $(call if_changed,objcopy)
+       @echo 'Kernel: $@ is ready'
+
+$(obj)/vmlinux.bin: $(obj)/compressed/vmlinux FORCE
+       $(call if_changed,objcopy)
+
+$(obj)/compressed/vmlinux: FORCE
+       $(Q)$(MAKE) $(build)=$(obj)/compressed IMAGE_OFFSET=$(IMAGE_OFFSET) $@
diff --git a/arch/mn10300/boot/compressed/Makefile b/arch/mn10300/boot/compressed/Makefile
new file mode 100644 (file)
index 0000000..08a95e1
--- /dev/null
@@ -0,0 +1,22 @@
+#
+# Create a compressed vmlinux image from the original vmlinux
+#
+
+targets                := vmlinux vmlinux.bin vmlinux.bin.gz head.o misc.o piggy.o
+
+LDFLAGS_vmlinux := -Ttext $(CONFIG_KERNEL_ZIMAGE_BASE_ADDRESS) -e startup_32
+
+$(obj)/vmlinux: $(obj)/head.o $(obj)/misc.o $(obj)/piggy.o FORCE
+       $(call if_changed,ld)
+       @:
+
+$(obj)/vmlinux.bin: vmlinux FORCE
+       $(call if_changed,objcopy)
+
+$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
+       $(call if_changed,gzip)
+
+LDFLAGS_piggy.o := -r --format binary --oformat elf32-am33lin -T
+
+$(obj)/piggy.o: $(obj)/vmlinux.lds $(obj)/vmlinux.bin.gz FORCE
+       $(call if_changed,ld)
diff --git a/arch/mn10300/boot/compressed/head.S b/arch/mn10300/boot/compressed/head.S
new file mode 100644 (file)
index 0000000..502e1eb
--- /dev/null
@@ -0,0 +1,86 @@
+/* Boot entry point for a compressed MN10300 kernel
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+       .section        .text
+
+#define DEBUG
+
+#include <linux/linkage.h>
+#include <asm/cpu-regs.h>
+
+       .globl startup_32
+startup_32:
+       # first save off parameters from bootloader
+       mov     param_save_area,a0
+       mov     d0,(a0)
+       mov     d1,(4,a0)
+       mov     d2,(8,a0)
+
+       mov     sp,a3
+       mov     decomp_stack+0x2000-4,a0
+       mov     a0,sp
+
+       # invalidate and enable both of the caches
+       mov     CHCTR,a0
+       clr     d0
+       movhu   d0,(a0)                                 # turn off first
+       mov     CHCTR_ICINV|CHCTR_DCINV,d0
+       movhu   d0,(a0)
+       setlb
+       mov     (a0),d0
+       btst    CHCTR_ICBUSY|CHCTR_DCBUSY,d0            # wait till not busy
+       lne
+       mov     CHCTR_ICEN|CHCTR_DCEN|CHCTR_DCWTMD,d0   # writethru dcache
+       movhu   d0,(a0)                                 # enable
+
+       # clear the BSS area
+       mov     __bss_start,a0
+       mov     _end,a1
+       clr     d0
+bssclear:
+       cmp     a1,a0
+       bge     bssclear_end
+       movbu   d0,(a0)
+       inc     a0
+       bra     bssclear
+bssclear_end:
+
+       # decompress the kernel
+       call    decompress_kernel[],0
+
+       # disable caches again
+       mov     CHCTR,a0
+       clr     d0
+       movhu   d0,(a0)
+       setlb
+       mov     (a0),d0
+       btst    CHCTR_ICBUSY|CHCTR_DCBUSY,d0            # wait till not busy
+       lne
+
+       mov     param_save_area,a0
+       mov     (a0),d0
+       mov     (4,a0),d1
+       mov     (8,a0),d2
+
+       mov     a3,sp
+       mov     CONFIG_KERNEL_TEXT_ADDRESS,a0
+       jmp     (a0)
+
+       .data
+       .align          4
+param_save_area:
+       .rept 3
+       .word           0
+       .endr
+
+       .section        .bss
+       .align          4
+decomp_stack:
+       .space          0x2000
diff --git a/arch/mn10300/boot/compressed/misc.c b/arch/mn10300/boot/compressed/misc.c
new file mode 100644 (file)
index 0000000..ded207e
--- /dev/null
@@ -0,0 +1,429 @@
+/* MN10300 Miscellaneous helper routines for kernel decompressor
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Modified by David Howells (dhowells@redhat.com)
+ * - Derived from arch/x86/boot/compressed/misc_32.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/compiler.h>
+#include <asm/serial-regs.h>
+#include "misc.h"
+
+#ifndef CONFIG_GDBSTUB_ON_TTYSx
+/* display 'Uncompressing Linux... ' messages on ttyS0 or ttyS1 */
+#if 1  /* ttyS0 */
+#define CYG_DEV_BASE   0xA6FB0000
+#else   /* ttyS1 */
+#define CYG_DEV_BASE   0xA6FC0000
+#endif
+
+#define CYG_DEV_THR    (*((volatile __u8*)(CYG_DEV_BASE + 0x00)))
+#define CYG_DEV_MCR    (*((volatile __u8*)(CYG_DEV_BASE + 0x10)))
+#define SIO_MCR_DTR    0x01
+#define SIO_MCR_RTS    0x02
+#define CYG_DEV_LSR    (*((volatile __u8*)(CYG_DEV_BASE + 0x14)))
+#define SIO_LSR_THRE   0x20            /* transmitter holding register empty */
+#define SIO_LSR_TEMT   0x40            /* transmitter register empty */
+#define CYG_DEV_MSR    (*((volatile __u8*)(CYG_DEV_BASE + 0x18)))
+#define SIO_MSR_CTS    0x10            /* clear to send */
+#define SIO_MSR_DSR    0x20            /* data set ready */
+
+#define LSR_WAIT_FOR(STATE) \
+       do { while (!(CYG_DEV_LSR & SIO_LSR_##STATE)) {} } while (0)
+#define FLOWCTL_QUERY(LINE) \
+       ({ CYG_DEV_MSR & SIO_MSR_##LINE; })
+#define FLOWCTL_WAIT_FOR(LINE) \
+       do { while (!(CYG_DEV_MSR & SIO_MSR_##LINE)) {} } while (0)
+#define FLOWCTL_CLEAR(LINE) \
+       do { CYG_DEV_MCR &= ~SIO_MCR_##LINE; } while (0)
+#define FLOWCTL_SET(LINE) \
+       do { CYG_DEV_MCR |= SIO_MCR_##LINE; } while (0)
+#endif
+
+/*
+ * gzip declarations
+ */
+
+#define OF(args)  args
+#define STATIC static
+
+#undef memset
+#undef memcpy
+
+static inline void *memset(const void *s, int c, size_t n)
+{
+       int i;
+       char *ss = (char *) s;
+
+       for (i = 0; i < n; i++)
+               ss[i] = c;
+       return (void *)s;
+}
+
+#define memzero(s, n) memset((s), 0, (n))
+
+static inline void *memcpy(void *__dest, const void *__src, size_t __n)
+{
+       int i;
+       const char *s = __src;
+       char *d = __dest;
+
+       for (i = 0; i < __n; i++)
+               d[i] = s[i];
+       return __dest;
+}
+
+typedef unsigned char  uch;
+typedef unsigned short ush;
+typedef unsigned long  ulg;
+
+#define WSIZE 0x8000   /* Window size must be at least 32k, and a power of
+                        * two */
+
+static uch *inbuf;     /* input buffer */
+static uch window[WSIZE]; /* sliding window buffer */
+
+static unsigned insize;        /* valid bytes in inbuf */
+static unsigned inptr; /* index of next byte to be processed in inbuf */
+static unsigned outcnt;        /* bytes in output buffer */
+
+/* gzip flag byte */
+#define ASCII_FLAG   0x01 /* bit 0 set: file probably ASCII text */
+#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */
+#define EXTRA_FIELD  0x04 /* bit 2 set: extra field present */
+#define ORIG_NAME    0x08 /* bit 3 set: original file name present */
+#define COMMENT      0x10 /* bit 4 set: file comment present */
+#define ENCRYPTED    0x20 /* bit 5 set: file is encrypted */
+#define RESERVED     0xC0 /* bit 6,7:   reserved */
+
+/* Diagnostic functions */
+#ifdef DEBUG
+#  define Assert(cond, msg) { if (!(cond)) error(msg); }
+#  define Trace(x)     fprintf x
+#  define Tracev(x)    { if (verbose) fprintf x ; }
+#  define Tracevv(x)   { if (verbose > 1) fprintf x ; }
+#  define Tracec(c, x) { if (verbose && (c)) fprintf x ; }
+#  define Tracecv(c, x)        { if (verbose > 1 && (c)) fprintf x ; }
+#else
+#  define Assert(cond, msg)
+#  define Trace(x)
+#  define Tracev(x)
+#  define Tracevv(x)
+#  define Tracec(c, x)
+#  define Tracecv(c, x)
+#endif
+
+static int  fill_inbuf(void);
+static void flush_window(void);
+static void error(const char *) __attribute__((noreturn));
+static void kputs(const char *);
+
+static inline unsigned char get_byte(void)
+{
+       unsigned char ch = inptr < insize ? inbuf[inptr++] : fill_inbuf();
+
+#if 0
+       char hex[3];
+       hex[0] = ((ch & 0x0f) > 9) ?
+               ((ch & 0x0f) + 'A' - 0xa) : ((ch & 0x0f) + '0');
+       hex[1] = ((ch >> 4) > 9) ?
+               ((ch >> 4) + 'A' - 0xa) : ((ch >> 4) + '0');
+       hex[2] = 0;
+       kputs(hex);
+#endif
+       return ch;
+}
+
+/*
+ * This is set up by the setup-routine at boot-time
+ */
+#define EXT_MEM_K (*(unsigned short *)0x90002)
+#ifndef STANDARD_MEMORY_BIOS_CALL
+#define ALT_MEM_K (*(unsigned long *) 0x901e0)
+#endif
+#define SCREEN_INFO (*(struct screen_info *)0x90000)
+
+static long bytes_out;
+static uch *output_data;
+static unsigned long output_ptr;
+
+
+static void *malloc(int size);
+
+static inline void free(void *where)
+{      /* Don't care */
+}
+
+static unsigned long free_mem_ptr = (unsigned long) &end;
+static unsigned long free_mem_end_ptr = (unsigned long) &end + 0x90000;
+
+static inline void gzip_mark(void **ptr)
+{
+       kputs(".");
+       *ptr = (void *) free_mem_ptr;
+}
+
+static inline void gzip_release(void **ptr)
+{
+       free_mem_ptr = (unsigned long) *ptr;
+}
+
+#define INPLACE_MOVE_ROUTINE   0x1000
+#define LOW_BUFFER_START       0x2000
+#define LOW_BUFFER_END         0x90000
+#define LOW_BUFFER_SIZE                (LOW_BUFFER_END - LOW_BUFFER_START)
+#define HEAP_SIZE              0x3000
+static int high_loaded;
+static uch *high_buffer_start /* = (uch *)(((ulg)&end) + HEAP_SIZE)*/;
+
+static char *vidmem = (char *)0xb8000;
+static int lines, cols;
+
+#include "../../../../lib/inflate.c"
+
+static void *malloc(int size)
+{
+       void *p;
+
+       if (size < 0)
+               error("Malloc error\n");
+       if (!free_mem_ptr)
+               error("Memory error\n");
+
+       free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
+
+       p = (void *) free_mem_ptr;
+       free_mem_ptr += size;
+
+       if (free_mem_ptr >= free_mem_end_ptr)
+               error("\nOut of memory\n");
+
+       return p;
+}
+
+static inline void scroll(void)
+{
+       int i;
+
+       memcpy(vidmem, vidmem + cols * 2, (lines - 1) * cols * 2);
+       for (i = (lines - 1) * cols * 2; i < lines * cols * 2; i += 2)
+               vidmem[i] = ' ';
+}
+
+static inline void kputchar(unsigned char ch)
+{
+#ifdef CONFIG_MN10300_UNIT_ASB2305
+       while (SC0STR & SC01STR_TBF)
+               continue;
+
+       if (ch == 0x0a) {
+               SC0TXB = 0x0d;
+               while (SC0STR & SC01STR_TBF)
+                       continue;
+       }
+
+       SC0TXB = ch;
+
+#else
+       while (SC1STR & SC01STR_TBF)
+               continue;
+
+       if (ch == 0x0a) {
+               SC1TXB = 0x0d;
+               while (SC1STR & SC01STR_TBF)
+                       continue;
+       }
+
+       SC1TXB = ch;
+
+#endif
+}
+
+static void kputs(const char *s)
+{
+#ifdef CONFIG_DEBUG_DECOMPRESS_KERNEL
+#ifndef CONFIG_GDBSTUB_ON_TTYSx
+       char ch;
+
+       FLOWCTL_SET(DTR);
+
+       while (*s) {
+               LSR_WAIT_FOR(THRE);
+
+               ch = *s++;
+               if (ch == 0x0a) {
+                       CYG_DEV_THR = 0x0d;
+                       LSR_WAIT_FOR(THRE);
+               }
+               CYG_DEV_THR = ch;
+       }
+
+       FLOWCTL_CLEAR(DTR);
+#else
+
+       for (; *s; s++)
+               kputchar(*s);
+
+#endif
+#endif /* CONFIG_DEBUG_DECOMPRESS_KERNEL */
+}
+
+/* ===========================================================================
+ * Fill the input buffer. This is called only when the buffer is empty
+ * and at least one byte is really needed.
+ */
+static int fill_inbuf()
+{
+       if (insize != 0)
+               error("ran out of input data\n");
+
+       inbuf = input_data;
+       insize = input_len;
+       inptr = 1;
+       return inbuf[0];
+}
+
+/* ===========================================================================
+ * Write the output window window[0..outcnt-1] and update crc and bytes_out.
+ * (Used for the decompressed data only.)
+ */
+static void flush_window_low(void)
+{
+    ulg c = crc;         /* temporary variable */
+    unsigned n;
+    uch *in, *out, ch;
+
+    in = window;
+    out = &output_data[output_ptr];
+    for (n = 0; n < outcnt; n++) {
+           ch = *out++ = *in++;
+           c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
+    }
+    crc = c;
+    bytes_out += (ulg)outcnt;
+    output_ptr += (ulg)outcnt;
+    outcnt = 0;
+}
+
+static void flush_window_high(void)
+{
+    ulg c = crc;         /* temporary variable */
+    unsigned n;
+    uch *in,  ch;
+    in = window;
+    for (n = 0; n < outcnt; n++) {
+       ch = *output_data++ = *in++;
+       if ((ulg) output_data == LOW_BUFFER_END)
+               output_data = high_buffer_start;
+       c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
+    }
+    crc = c;
+    bytes_out += (ulg)outcnt;
+    outcnt = 0;
+}
+
+static void flush_window(void)
+{
+       if (high_loaded)
+               flush_window_high();
+       else
+               flush_window_low();
+}
+
+static void error(const char *x)
+{
+       kputs("\n\n");
+       kputs(x);
+       kputs("\n\n -- System halted");
+
+       while (1)
+               /* Halt */;
+}
+
+#define STACK_SIZE (4096)
+
+long user_stack[STACK_SIZE];
+
+struct {
+       long *a;
+       short b;
+} stack_start = { &user_stack[STACK_SIZE], 0 };
+
+void setup_normal_output_buffer(void)
+{
+#ifdef STANDARD_MEMORY_BIOS_CALL
+       if (EXT_MEM_K < 1024)
+               error("Less than 2MB of memory.\n");
+#else
+       if ((ALT_MEM_K > EXT_MEM_K ? ALT_MEM_K : EXT_MEM_K) < 1024)
+               error("Less than 2MB of memory.\n");
+#endif
+       output_data = (char *) 0x100000; /* Points to 1M */
+}
+
+struct moveparams {
+       uch *low_buffer_start;
+       int lcount;
+       uch *high_buffer_start;
+       int hcount;
+};
+
+void setup_output_buffer_if_we_run_high(struct moveparams *mv)
+{
+       high_buffer_start = (uch *)(((ulg) &end) + HEAP_SIZE);
+#ifdef STANDARD_MEMORY_BIOS_CALL
+       if (EXT_MEM_K < (3 * 1024))
+               error("Less than 4MB of memory.\n");
+#else
+       if ((ALT_MEM_K > EXT_MEM_K ? ALT_MEM_K : EXT_MEM_K) < (3 * 1024))
+               error("Less than 4MB of memory.\n");
+#endif
+       mv->low_buffer_start = output_data = (char *) LOW_BUFFER_START;
+       high_loaded = 1;
+       free_mem_end_ptr = (long) high_buffer_start;
+       if (0x100000 + LOW_BUFFER_SIZE > (ulg) high_buffer_start) {
+               high_buffer_start = (uch *)(0x100000 + LOW_BUFFER_SIZE);
+               mv->hcount = 0; /* say: we need not to move high_buffer */
+       } else {
+               mv->hcount = -1;
+       }
+       mv->high_buffer_start = high_buffer_start;
+}
+
+void close_output_buffer_if_we_run_high(struct moveparams *mv)
+{
+       mv->lcount = bytes_out;
+       if (bytes_out > LOW_BUFFER_SIZE) {
+               mv->lcount = LOW_BUFFER_SIZE;
+               if (mv->hcount)
+                       mv->hcount = bytes_out - LOW_BUFFER_SIZE;
+       } else {
+               mv->hcount = 0;
+       }
+}
+
+#undef DEBUGFLAG
+#ifdef DEBUGFLAG
+int debugflag;
+#endif
+
+int decompress_kernel(struct moveparams *mv)
+{
+#ifdef DEBUGFLAG
+       while (!debugflag)
+               barrier();
+#endif
+
+       output_data = (char *) CONFIG_KERNEL_TEXT_ADDRESS;
+
+       makecrc();
+       kputs("Uncompressing Linux... ");
+       gunzip();
+       kputs("Ok, booting the kernel.\n");
+       return 0;
+}
diff --git a/arch/mn10300/boot/compressed/misc.h b/arch/mn10300/boot/compressed/misc.h
new file mode 100644 (file)
index 0000000..da921cd
--- /dev/null
@@ -0,0 +1,18 @@
+/* Internal definitions for the MN10300 kernel decompressor
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+extern int end;
+
+/*
+ * vmlinux.lds
+ */
+extern char input_data[];
+extern int input_len;
diff --git a/arch/mn10300/boot/compressed/vmlinux.lds b/arch/mn10300/boot/compressed/vmlinux.lds
new file mode 100644 (file)
index 0000000..a084903
--- /dev/null
@@ -0,0 +1,9 @@
+SECTIONS
+{
+  .data : {
+       input_len = .;
+       LONG(input_data_end - input_data) input_data = .;
+       *(.data)
+       input_data_end = .;
+       }
+}
diff --git a/arch/mn10300/boot/install.sh b/arch/mn10300/boot/install.sh
new file mode 100644 (file)
index 0000000..072951c
--- /dev/null
@@ -0,0 +1,67 @@
+#!/bin/sh
+#
+# arch/mn10300/boot/install -c.sh
+#
+# This file is subject to the terms and conditions of the GNU General Public
+# Licence.  See the file "COPYING" in the main directory of this archive
+# for more details.
+#
+# Copyright (C) 1995 by Linus Torvalds
+#
+# Adapted from code in arch/i386/boot/Makefile by H. Peter Anvin
+#
+# "make install -c" script for i386 architecture
+#
+# Arguments:
+#   $1 - kernel version
+#   $2 - kernel image file
+#   $3 - kernel map file
+#   $4 - default install -c path (blank if root directory)
+#   $5 - boot rom file
+#
+
+# User may have a custom install -c script
+
+rm -fr $4/../usr/include/linux $4/../usr/include/asm
+install -c -m 0755 $2 $4/vmlinuz
+install -c -m 0755 $5 $4/boot.rom
+install -c -m 0755 -d $4/../usr/include/linux
+cd $TOPDIR/include/linux
+for i in `find . -maxdepth 1 -name '*.h' -print`; do
+  install -c -m 0644 $i $4/../usr/include/linux
+done
+install -c -m 0755 -d $4/../usr/include/linux/byteorder
+cd $TOPDIR/include/linux/byteorder
+for i in `find . -name '*.h' -print`; do
+  install -c -m 0644 $i $4/../usr/include/linux/byteorder
+done
+install -c -m 0755 -d $4/../usr/include/linux/lockd
+cd $TOPDIR/include/linux/lockd
+for i in `find . -name '*.h' -print`; do
+  install -c -m 0644 $i $4/../usr/include/linux/lockd
+done
+install -c -m 0755 -d $4/../usr/include/linux/netfilter_ipv4
+cd $TOPDIR/include/linux/netfilter_ipv4
+for i in `find . -name '*.h' -print`; do
+  install -c -m 0644 $i $4/../usr/include/linux/netfilter_ipv4
+done
+install -c -m 0755 -d $4/../usr/include/linux/nfsd
+cd $TOPDIR/include/linux/nfsd
+for i in `find . -name '*.h' -print`; do
+  install -c -m 0644 $i $4/../usr/include/linux/nfsd/$i
+done
+install -c -m 0755 -d $4/../usr/include/linux/raid
+cd $TOPDIR/include/linux/raid
+for i in `find . -name '*.h' -print`; do
+  install -c -m 0644 $i $4/../usr/include/linux/raid
+done
+install -c -m 0755 -d $4/../usr/include/linux/sunrpc
+cd $TOPDIR/include/linux/sunrpc
+for i in `find . -name '*.h' -print`; do
+  install -c -m 0644 $i $4/../usr/include/linux/sunrpc
+done
+install -c -m 0755 -d $4/../usr/include/asm
+cd $TOPDIR/include/asm
+for i in `find . -name '*.h' -print`; do
+  install -c -m 0644 $i $4/../usr/include/asm
+done
diff --git a/arch/mn10300/boot/tools/build.c b/arch/mn10300/boot/tools/build.c
new file mode 100644 (file)
index 0000000..4f552ea
--- /dev/null
@@ -0,0 +1,190 @@
+/*
+ *  Copyright (C) 1991, 1992  Linus Torvalds
+ *  Copyright (C) 1997 Martin Mares
+ */
+
+/*
+ * This file builds a disk-image from three different files:
+ *
+ * - bootsect: exactly 512 bytes of 8086 machine code, loads the rest
+ * - setup: 8086 machine code, sets up system parm
+ * - system: 80386 code for actual system
+ *
+ * It does some checking that all files are of the correct type, and
+ * just writes the result to stdout, removing headers and padding to
+ * the right amount. It also writes some system data to stderr.
+ */
+
+/*
+ * Changes by tytso to allow root device specification
+ * High loaded stuff by Hans Lermen & Werner Almesberger, Feb. 1996
+ * Cross compiling fixes by Gertjan van Wingerde, July 1996
+ * Rewritten by Martin Mares, April 1997
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/sysmacros.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <asm/boot.h>
+
+#define DEFAULT_MAJOR_ROOT 0
+#define DEFAULT_MINOR_ROOT 0
+
+/* Minimal number of setup sectors (see also bootsect.S) */
+#define SETUP_SECTS 4
+
+uint8_t buf[1024];
+int fd;
+int is_big_kernel;
+
+__attribute__((noreturn))
+void die(const char *str, ...)
+{
+       va_list args;
+       va_start(args, str);
+       vfprintf(stderr, str, args);
+       fputc('\n', stderr);
+       exit(1);
+}
+
+void file_open(const char *name)
+{
+       fd = open(name, O_RDONLY, 0);
+       if (fd < 0)
+               die("Unable to open `%s': %m", name);
+}
+
+__attribute__((noreturn))
+void usage(void)
+{
+       die("Usage: build [-b] bootsect setup system [rootdev] [> image]");
+}
+
+int main(int argc, char **argv)
+{
+       unsigned int i, c, sz, setup_sectors;
+       uint32_t sys_size;
+       uint8_t major_root, minor_root;
+       struct stat sb;
+
+       if (argc > 2 && !strcmp(argv[1], "-b")) {
+               is_big_kernel = 1;
+               argc--, argv++;
+       }
+       if ((argc < 4) || (argc > 5))
+               usage();
+       if (argc > 4) {
+               if (!strcmp(argv[4], "CURRENT")) {
+                       if (stat("/", &sb)) {
+                               perror("/");
+                               die("Couldn't stat /");
+                       }
+                       major_root = major(sb.st_dev);
+                       minor_root = minor(sb.st_dev);
+               } else if (strcmp(argv[4], "FLOPPY")) {
+                       if (stat(argv[4], &sb)) {
+                               perror(argv[4]);
+                               die("Couldn't stat root device.");
+                       }
+                       major_root = major(sb.st_rdev);
+                       minor_root = minor(sb.st_rdev);
+               } else {
+                       major_root = 0;
+                       minor_root = 0;
+               }
+       } else {
+               major_root = DEFAULT_MAJOR_ROOT;
+               minor_root = DEFAULT_MINOR_ROOT;
+       }
+       fprintf(stderr, "Root device is (%d, %d)\n", major_root, minor_root);
+
+       file_open(argv[1]);
+       i = read(fd, buf, sizeof(buf));
+       fprintf(stderr, "Boot sector %d bytes.\n", i);
+       if (i != 512)
+               die("Boot block must be exactly 512 bytes");
+       if (buf[510] != 0x55 || buf[511] != 0xaa)
+               die("Boot block hasn't got boot flag (0xAA55)");
+       buf[508] = minor_root;
+       buf[509] = major_root;
+       if (write(1, buf, 512) != 512)
+               die("Write call failed");
+       close(fd);
+
+       /* Copy the setup code */
+       file_open(argv[2]);
+       for (i = 0; (c = read(fd, buf, sizeof(buf))) > 0; i += c)
+               if (write(1, buf, c) != c)
+                       die("Write call failed");
+       if (c != 0)
+               die("read-error on `setup'");
+       close(fd);
+
+       /* Pad unused space with zeros */
+       setup_sectors = (i + 511) / 512;
+       /* for compatibility with ancient versions of LILO. */
+       if (setup_sectors < SETUP_SECTS)
+               setup_sectors = SETUP_SECTS;
+       fprintf(stderr, "Setup is %d bytes.\n", i);
+       memset(buf, 0, sizeof(buf));
+       while (i < setup_sectors * 512) {
+               c = setup_sectors * 512 - i;
+               if (c > sizeof(buf))
+                       c = sizeof(buf);
+               if (write(1, buf, c) != c)
+                       die("Write call failed");
+               i += c;
+       }
+
+       file_open(argv[3]);
+       if (fstat(fd, &sb))
+               die("Unable to stat `%s': %m", argv[3]);
+       sz = sb.st_size;
+       fprintf(stderr, "System is %d kB\n", sz / 1024);
+       sys_size = (sz + 15) / 16;
+       /* 0x28000*16 = 2.5 MB, conservative estimate for the current maximum */
+       if (sys_size > (is_big_kernel ? 0x28000 : DEF_SYSSIZE))
+               die("System is too big. Try using %smodules.",
+                       is_big_kernel ? "" : "bzImage or ");
+       if (sys_size > 0xffff)
+               fprintf(stderr,
+                       "warning: kernel is too big for standalone boot "
+                       "from floppy\n");
+       while (sz > 0) {
+               int l, n;
+
+               l = (sz > sizeof(buf)) ? sizeof(buf) : sz;
+               n = read(fd, buf, l);
+               if (n != l) {
+                       if (n < 0)
+                               die("Error reading %s: %m", argv[3]);
+                       else
+                               die("%s: Unexpected EOF", argv[3]);
+               }
+               if (write(1, buf, l) != l)
+                       die("Write failed");
+               sz -= l;
+       }
+       close(fd);
+
+       /* Write sizes to the bootsector */
+       if (lseek(1, 497, SEEK_SET) != 497)
+               die("Output: seek failed");
+       buf[0] = setup_sectors;
+       if (write(1, buf, 1) != 1)
+               die("Write of setup sector count failed");
+       if (lseek(1, 500, SEEK_SET) != 500)
+               die("Output: seek failed");
+       buf[0] = (sys_size & 0xff);
+       buf[1] = ((sys_size >> 8) & 0xff);
+       if (write(1, buf, 2) != 2)
+               die("Write of image length failed");
+
+       return 0;
+}
diff --git a/arch/mn10300/configs/asb2303_defconfig b/arch/mn10300/configs/asb2303_defconfig
new file mode 100644 (file)
index 0000000..ca9876a
--- /dev/null
@@ -0,0 +1,558 @@
+#
+# Automatically generated make config: don't edit
+# Linux kernel version: 2.6.24-rc2
+# Fri Nov 16 13:36:38 2007
+#
+CONFIG_MN10300=y
+CONFIG_AM33=y
+CONFIG_MMU=y
+# CONFIG_HIGHMEM is not set
+# CONFIG_NUMA is not set
+CONFIG_UID16=y
+CONFIG_RWSEM_GENERIC_SPINLOCK=y
+CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
+CONFIG_GENERIC_CALIBRATE_DELAY=y
+CONFIG_GENERIC_FIND_NEXT_BIT=y
+CONFIG_GENERIC_HWEIGHT=y
+CONFIG_GENERIC_TIME=y
+CONFIG_GENERIC_BUG=y
+CONFIG_QUICKLIST=y
+CONFIG_ARCH_HAS_ILOG2_U32=y
+# CONFIG_ARCH_SUPPORTS_AOUT is not set
+CONFIG_GENERIC_HARDIRQS=y
+# CONFIG_HOTPLUG_CPU is not set
+CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
+
+#
+# General setup
+#
+CONFIG_EXPERIMENTAL=y
+CONFIG_BROKEN_ON_SMP=y
+CONFIG_LOCK_KERNEL=y
+CONFIG_INIT_ENV_ARG_LIMIT=32
+CONFIG_LOCALVERSION=""
+CONFIG_LOCALVERSION_AUTO=y
+CONFIG_SYSVIPC=y
+CONFIG_SYSVIPC_SYSCTL=y
+# CONFIG_POSIX_MQUEUE is not set
+CONFIG_BSD_PROCESS_ACCT=y
+# CONFIG_BSD_PROCESS_ACCT_V3 is not set
+# CONFIG_TASKSTATS is not set
+# CONFIG_USER_NS is not set
+# CONFIG_PID_NS is not set
+# CONFIG_AUDIT is not set
+# CONFIG_IKCONFIG is not set
+CONFIG_LOG_BUF_SHIFT=14
+# CONFIG_CGROUPS is not set
+# CONFIG_FAIR_GROUP_SCHED is not set
+# CONFIG_SYSFS_DEPRECATED is not set
+# CONFIG_RELAY is not set
+# CONFIG_BLK_DEV_INITRD is not set
+# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
+CONFIG_SYSCTL=y
+CONFIG_EMBEDDED=y
+CONFIG_SYSCTL_SYSCALL=y
+# CONFIG_KALLSYMS is not set
+# CONFIG_HOTPLUG is not set
+CONFIG_PRINTK=y
+CONFIG_BUG=y
+CONFIG_ELF_CORE=y
+CONFIG_BASE_FULL=y
+CONFIG_FUTEX=y
+CONFIG_ANON_INODES=y
+CONFIG_EPOLL=y
+CONFIG_SIGNALFD=y
+CONFIG_EVENTFD=y
+CONFIG_SHMEM=y
+# CONFIG_VM_EVENT_COUNTERS is not set
+CONFIG_SLAB=y
+# CONFIG_SLUB is not set
+# CONFIG_SLOB is not set
+CONFIG_RT_MUTEXES=y
+# CONFIG_TINY_SHMEM is not set
+CONFIG_BASE_SMALL=0
+# CONFIG_MODULES is not set
+# CONFIG_BLOCK is not set
+
+#
+# Matsushita MN10300 system setup
+#
+CONFIG_MN10300_UNIT_ASB2303=y
+# CONFIG_MN10300_UNIT_ASB2305 is not set
+CONFIG_MN10300_PROC_MN103E010=y
+CONFIG_MN10300_CPU_AM33V2=y
+CONFIG_FPU=y
+CONFIG_MN10300_CACHE_WBACK=y
+# CONFIG_MN10300_CACHE_WTHRU is not set
+# CONFIG_MN10300_CACHE_DISABLED is not set
+
+#
+# Memory layout options
+#
+CONFIG_KERNEL_RAM_BASE_ADDRESS=0x90000000
+CONFIG_INTERRUPT_VECTOR_BASE=0x90000000
+CONFIG_KERNEL_TEXT_ADDRESS=0x90001000
+CONFIG_KERNEL_ZIMAGE_BASE_ADDRESS=0x90700000
+CONFIG_PREEMPT=y
+CONFIG_PREEMPT_BKL=y
+CONFIG_MN10300_CURRENT_IN_E2=y
+CONFIG_MN10300_USING_JTAG=y
+CONFIG_MN10300_RTC=y
+CONFIG_MN10300_WD_TIMER=y
+# CONFIG_ARCH_SUPPORTS_MSI is not set
+
+#
+# MN10300 internal serial options
+#
+CONFIG_MN10300_PROC_HAS_TTYSM0=y
+CONFIG_MN10300_PROC_HAS_TTYSM1=y
+CONFIG_MN10300_PROC_HAS_TTYSM2=y
+CONFIG_MN10300_TTYSM=y
+CONFIG_MN10300_TTYSM_CONSOLE=y
+CONFIG_MN10300_TTYSM0=y
+CONFIG_MN10300_TTYSM0_TIMER8=y
+# CONFIG_MN10300_TTYSM0_TIMER2 is not set
+CONFIG_MN10300_TTYSM1=y
+CONFIG_MN10300_TTYSM1_TIMER9=y
+# CONFIG_MN10300_TTYSM1_TIMER3 is not set
+# CONFIG_MN10300_TTYSM2 is not set
+CONFIG_SELECT_MEMORY_MODEL=y
+CONFIG_FLATMEM_MANUAL=y
+# CONFIG_DISCONTIGMEM_MANUAL is not set
+# CONFIG_SPARSEMEM_MANUAL is not set
+CONFIG_FLATMEM=y
+CONFIG_FLAT_NODE_MEM_MAP=y
+# CONFIG_SPARSEMEM_STATIC is not set
+# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
+CONFIG_SPLIT_PTLOCK_CPUS=4
+# CONFIG_RESOURCES_64BIT is not set
+CONFIG_ZONE_DMA_FLAG=0
+CONFIG_NR_QUICK=1
+CONFIG_VIRT_TO_BUS=y
+
+#
+# Power management options
+#
+# CONFIG_PM is not set
+
+#
+# Executable formats
+#
+CONFIG_BINFMT_ELF=y
+# CONFIG_BINFMT_MISC is not set
+
+#
+# Networking
+#
+CONFIG_NET=y
+
+#
+# Networking options
+#
+CONFIG_PACKET=y
+CONFIG_PACKET_MMAP=y
+CONFIG_UNIX=y
+# CONFIG_NET_KEY is not set
+CONFIG_INET=y
+CONFIG_IP_MULTICAST=y
+# CONFIG_IP_ADVANCED_ROUTER is not set
+CONFIG_IP_FIB_HASH=y
+CONFIG_IP_PNP=y
+# CONFIG_IP_PNP_DHCP is not set
+CONFIG_IP_PNP_BOOTP=y
+# CONFIG_IP_PNP_RARP is not set
+# CONFIG_NET_IPIP is not set
+# CONFIG_NET_IPGRE is not set
+# CONFIG_IP_MROUTE is not set
+# CONFIG_ARPD is not set
+# CONFIG_SYN_COOKIES is not set
+# CONFIG_INET_AH is not set
+# CONFIG_INET_ESP is not set
+# CONFIG_INET_IPCOMP is not set
+# CONFIG_INET_XFRM_TUNNEL is not set
+# CONFIG_INET_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
+# CONFIG_INET_XFRM_MODE_TUNNEL is not set
+# CONFIG_INET_XFRM_MODE_BEET is not set
+# CONFIG_INET_LRO is not set
+# CONFIG_INET_DIAG is not set
+# CONFIG_TCP_CONG_ADVANCED is not set
+CONFIG_TCP_CONG_CUBIC=y
+CONFIG_DEFAULT_TCP_CONG="cubic"
+# CONFIG_TCP_MD5SIG is not set
+# CONFIG_IPV6 is not set
+# CONFIG_INET6_XFRM_TUNNEL is not set
+# CONFIG_INET6_TUNNEL is not set
+# CONFIG_NETWORK_SECMARK is not set
+# CONFIG_NETFILTER is not set
+# CONFIG_IP_DCCP is not set
+# CONFIG_IP_SCTP is not set
+# CONFIG_TIPC is not set
+# CONFIG_ATM is not set
+# CONFIG_BRIDGE is not set
+# CONFIG_VLAN_8021Q is not set
+# CONFIG_DECNET is not set
+# CONFIG_LLC2 is not set
+# CONFIG_IPX is not set
+# CONFIG_ATALK is not set
+# CONFIG_X25 is not set
+# CONFIG_LAPB is not set
+# CONFIG_ECONET is not set
+# CONFIG_WAN_ROUTER is not set
+# CONFIG_NET_SCHED is not set
+
+#
+# Network testing
+#
+# CONFIG_NET_PKTGEN is not set
+# CONFIG_HAMRADIO is not set
+# CONFIG_IRDA is not set
+# CONFIG_BT is not set
+# CONFIG_AF_RXRPC is not set
+
+#
+# Wireless
+#
+# CONFIG_CFG80211 is not set
+# CONFIG_WIRELESS_EXT is not set
+# CONFIG_MAC80211 is not set
+# CONFIG_IEEE80211 is not set
+# CONFIG_RFKILL is not set
+# CONFIG_NET_9P is not set
+
+#
+# Device Drivers
+#
+
+#
+# Generic Driver Options
+#
+CONFIG_STANDALONE=y
+CONFIG_PREVENT_FIRMWARE_BUILD=y
+# CONFIG_SYS_HYPERVISOR is not set
+# CONFIG_CONNECTOR is not set
+CONFIG_MTD=y
+CONFIG_MTD_DEBUG=y
+CONFIG_MTD_DEBUG_VERBOSE=0
+# CONFIG_MTD_CONCAT is not set
+CONFIG_MTD_PARTITIONS=y
+CONFIG_MTD_REDBOOT_PARTS=y
+CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1
+CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED=y
+# CONFIG_MTD_REDBOOT_PARTS_READONLY is not set
+# CONFIG_MTD_CMDLINE_PARTS is not set
+
+#
+# User Modules And Translation Layers
+#
+CONFIG_MTD_CHAR=y
+# CONFIG_MTD_OOPS is not set
+
+#
+# RAM/ROM/Flash chip drivers
+#
+CONFIG_MTD_CFI=y
+CONFIG_MTD_JEDECPROBE=y
+CONFIG_MTD_GEN_PROBE=y
+CONFIG_MTD_CFI_ADV_OPTIONS=y
+CONFIG_MTD_CFI_NOSWAP=y
+# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
+# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
+CONFIG_MTD_CFI_GEOMETRY=y
+CONFIG_MTD_MAP_BANK_WIDTH_1=y
+CONFIG_MTD_MAP_BANK_WIDTH_2=y
+CONFIG_MTD_MAP_BANK_WIDTH_4=y
+# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
+# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
+CONFIG_MTD_CFI_I1=y
+CONFIG_MTD_CFI_I2=y
+CONFIG_MTD_CFI_I4=y
+# CONFIG_MTD_CFI_I8 is not set
+# CONFIG_MTD_OTP is not set
+# CONFIG_MTD_CFI_INTELEXT is not set
+CONFIG_MTD_CFI_AMDSTD=y
+# CONFIG_MTD_CFI_STAA is not set
+CONFIG_MTD_CFI_UTIL=y
+# CONFIG_MTD_RAM is not set
+# CONFIG_MTD_ROM is not set
+# CONFIG_MTD_ABSENT is not set
+
+#
+# Mapping drivers for chip access
+#
+# CONFIG_MTD_COMPLEX_MAPPINGS is not set
+CONFIG_MTD_PHYSMAP=y
+CONFIG_MTD_PHYSMAP_START=0x8000000
+CONFIG_MTD_PHYSMAP_LEN=0x0
+CONFIG_MTD_PHYSMAP_BANKWIDTH=2
+# CONFIG_MTD_PLATRAM is not set
+
+#
+# Self-contained MTD device drivers
+#
+# CONFIG_MTD_SLRAM is not set
+# CONFIG_MTD_PHRAM is not set
+# CONFIG_MTD_MTDRAM is not set
+
+#
+# Disk-On-Chip Device Drivers
+#
+# CONFIG_MTD_DOC2000 is not set
+# CONFIG_MTD_DOC2001 is not set
+# CONFIG_MTD_DOC2001PLUS is not set
+# CONFIG_MTD_NAND is not set
+# CONFIG_MTD_ONENAND is not set
+
+#
+# UBI - Unsorted block images
+#
+# CONFIG_MTD_UBI is not set
+# CONFIG_PARPORT is not set
+CONFIG_MISC_DEVICES=y
+# CONFIG_EEPROM_93CX6 is not set
+
+#
+# SCSI device support
+#
+# CONFIG_SCSI_DMA is not set
+# CONFIG_SCSI_NETLINK is not set
+CONFIG_NETDEVICES=y
+# CONFIG_NETDEVICES_MULTIQUEUE is not set
+# CONFIG_DUMMY is not set
+# CONFIG_BONDING is not set
+# CONFIG_MACVLAN is not set
+# CONFIG_EQUALIZER is not set
+# CONFIG_TUN is not set
+# CONFIG_VETH is not set
+# CONFIG_PHYLIB is not set
+CONFIG_NET_ETHERNET=y
+CONFIG_MII=y
+CONFIG_SMC91X=y
+# CONFIG_IBM_NEW_EMAC_ZMII is not set
+# CONFIG_IBM_NEW_EMAC_RGMII is not set
+# CONFIG_IBM_NEW_EMAC_TAH is not set
+# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
+# CONFIG_B44 is not set
+# CONFIG_NETDEV_1000 is not set
+# CONFIG_NETDEV_10000 is not set
+
+#
+# Wireless LAN
+#
+# CONFIG_WLAN_PRE80211 is not set
+# CONFIG_WLAN_80211 is not set
+# CONFIG_WAN is not set
+# CONFIG_PPP is not set
+# CONFIG_SLIP is not set
+# CONFIG_SHAPER is not set
+# CONFIG_NETCONSOLE is not set
+# CONFIG_NETPOLL is not set
+# CONFIG_NET_POLL_CONTROLLER is not set
+# CONFIG_ISDN is not set
+# CONFIG_PHONE is not set
+
+#
+# Input device support
+#
+# CONFIG_INPUT is not set
+
+#
+# Hardware I/O ports
+#
+# CONFIG_SERIO is not set
+# CONFIG_GAMEPORT is not set
+
+#
+# Character devices
+#
+# CONFIG_VT is not set
+# CONFIG_SERIAL_NONSTANDARD is not set
+
+#
+# Serial drivers
+#
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_8250_NR_UARTS=4
+CONFIG_SERIAL_8250_RUNTIME_UARTS=4
+CONFIG_SERIAL_8250_EXTENDED=y
+# CONFIG_SERIAL_8250_MANY_PORTS is not set
+CONFIG_SERIAL_8250_SHARE_IRQ=y
+# CONFIG_SERIAL_8250_DETECT_IRQ is not set
+# CONFIG_SERIAL_8250_RSA is not set
+
+#
+# Non-8250 serial port support
+#
+CONFIG_SERIAL_CORE=y
+CONFIG_SERIAL_CORE_CONSOLE=y
+CONFIG_UNIX98_PTYS=y
+CONFIG_LEGACY_PTYS=y
+CONFIG_LEGACY_PTY_COUNT=256
+# CONFIG_IPMI_HANDLER is not set
+# CONFIG_HW_RANDOM is not set
+CONFIG_RTC=y
+# CONFIG_R3964 is not set
+# CONFIG_TCG_TPM is not set
+# CONFIG_I2C is not set
+
+#
+# SPI support
+#
+# CONFIG_SPI is not set
+# CONFIG_SPI_MASTER is not set
+# CONFIG_W1 is not set
+# CONFIG_POWER_SUPPLY is not set
+# CONFIG_HWMON is not set
+# CONFIG_WATCHDOG is not set
+
+#
+# Sonics Silicon Backplane
+#
+CONFIG_SSB_POSSIBLE=y
+# CONFIG_SSB is not set
+
+#
+# Multifunction device drivers
+#
+# CONFIG_MFD_SM501 is not set
+
+#
+# Multimedia devices
+#
+# CONFIG_VIDEO_DEV is not set
+# CONFIG_DVB_CORE is not set
+# CONFIG_DAB is not set
+
+#
+# Graphics support
+#
+# CONFIG_VGASTATE is not set
+# CONFIG_VIDEO_OUTPUT_CONTROL is not set
+# CONFIG_FB is not set
+# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
+
+#
+# Display device support
+#
+# CONFIG_DISPLAY_SUPPORT is not set
+
+#
+# Sound
+#
+# CONFIG_SOUND is not set
+# CONFIG_USB_SUPPORT is not set
+# CONFIG_MMC is not set
+# CONFIG_NEW_LEDS is not set
+# CONFIG_RTC_CLASS is not set
+
+#
+# Userspace I/O
+#
+# CONFIG_UIO is not set
+
+#
+# File systems
+#
+CONFIG_INOTIFY=y
+CONFIG_INOTIFY_USER=y
+# CONFIG_QUOTA is not set
+CONFIG_DNOTIFY=y
+# CONFIG_AUTOFS_FS is not set
+# CONFIG_AUTOFS4_FS is not set
+# CONFIG_FUSE_FS is not set
+
+#
+# Pseudo filesystems
+#
+CONFIG_PROC_FS=y
+CONFIG_PROC_KCORE=y
+CONFIG_PROC_SYSCTL=y
+CONFIG_SYSFS=y
+CONFIG_TMPFS=y
+# CONFIG_TMPFS_POSIX_ACL is not set
+# CONFIG_HUGETLB_PAGE is not set
+# CONFIG_CONFIGFS_FS is not set
+
+#
+# Miscellaneous filesystems
+#
+CONFIG_JFFS2_FS=y
+CONFIG_JFFS2_FS_DEBUG=0
+CONFIG_JFFS2_FS_WRITEBUFFER=y
+# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
+# CONFIG_JFFS2_SUMMARY is not set
+# CONFIG_JFFS2_FS_XATTR is not set
+# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
+CONFIG_JFFS2_ZLIB=y
+# CONFIG_JFFS2_LZO is not set
+CONFIG_JFFS2_RTIME=y
+# CONFIG_JFFS2_RUBIN is not set
+CONFIG_NETWORK_FILESYSTEMS=y
+CONFIG_NFS_FS=y
+CONFIG_NFS_V3=y
+# CONFIG_NFS_V3_ACL is not set
+# CONFIG_NFS_V4 is not set
+# CONFIG_NFS_DIRECTIO is not set
+# CONFIG_NFSD is not set
+CONFIG_ROOT_NFS=y
+CONFIG_LOCKD=y
+CONFIG_LOCKD_V4=y
+CONFIG_NFS_COMMON=y
+CONFIG_SUNRPC=y
+# CONFIG_SUNRPC_BIND34 is not set
+# CONFIG_RPCSEC_GSS_KRB5 is not set
+# CONFIG_RPCSEC_GSS_SPKM3 is not set
+# CONFIG_SMB_FS is not set
+# CONFIG_CIFS is not set
+# CONFIG_NCP_FS is not set
+# CONFIG_CODA_FS is not set
+# CONFIG_AFS_FS is not set
+# CONFIG_NLS is not set
+# CONFIG_DLM is not set
+
+#
+# Kernel hacking
+#
+# CONFIG_PRINTK_TIME is not set
+CONFIG_ENABLE_WARN_DEPRECATED=y
+CONFIG_ENABLE_MUST_CHECK=y
+CONFIG_MAGIC_SYSRQ=y
+# CONFIG_UNUSED_SYMBOLS is not set
+# CONFIG_DEBUG_FS is not set
+# CONFIG_HEADERS_CHECK is not set
+# CONFIG_DEBUG_KERNEL is not set
+# CONFIG_DEBUG_BUGVERBOSE is not set
+# CONFIG_SAMPLES is not set
+
+#
+# Security options
+#
+# CONFIG_KEYS is not set
+# CONFIG_SECURITY is not set
+# CONFIG_SECURITY_FILE_CAPABILITIES is not set
+# CONFIG_CRYPTO is not set
+
+#
+# Library routines
+#
+CONFIG_BITREVERSE=y
+# CONFIG_CRC_CCITT is not set
+# CONFIG_CRC16 is not set
+# CONFIG_CRC_ITU_T is not set
+CONFIG_CRC32=y
+# CONFIG_CRC7 is not set
+# CONFIG_LIBCRC32C is not set
+CONFIG_ZLIB_INFLATE=y
+CONFIG_ZLIB_DEFLATE=y
+CONFIG_PLIST=y
+CONFIG_HAS_IOMEM=y
+CONFIG_HAS_IOPORT=y
+CONFIG_HAS_DMA=y
+
+#
+# Profiling support
+#
+CONFIG_PROFILING=y
+CONFIG_OPROFILE=y
diff --git a/arch/mn10300/kernel/Makefile b/arch/mn10300/kernel/Makefile
new file mode 100644 (file)
index 0000000..ef07c95
--- /dev/null
@@ -0,0 +1,27 @@
+#
+# Makefile for the MN10300-specific core kernel code
+#
+extra-y := head.o init_task.o vmlinux.lds
+
+obj-y   := process.o semaphore.o signal.o entry.o fpu.o traps.o irq.o \
+          ptrace.o setup.o time.o sys_mn10300.o io.o kthread.o \
+          switch_to.o mn10300_ksyms.o kernel_execve.o
+
+obj-$(CONFIG_MN10300_WD_TIMER) += mn10300-watchdog.o mn10300-watchdog-low.o
+
+obj-$(CONFIG_FPU) += fpu-low.o
+
+obj-$(CONFIG_MN10300_TTYSM) += mn10300-serial.o mn10300-serial-low.o \
+                              mn10300-debug.o
+obj-$(CONFIG_GDBSTUB) += gdb-stub.o gdb-low.o
+obj-$(CONFIG_GDBSTUB_ON_TTYSx) += gdb-io-serial.o gdb-io-serial-low.o
+obj-$(CONFIG_GDBSTUB_ON_TTYSMx) += gdb-io-ttysm.o gdb-io-ttysm-low.o
+
+ifneq ($(CONFIG_MN10300_CACHE_DISABLED),y)
+obj-$(CONFIG_GDBSTUB) += gdb-cache.o
+endif
+
+obj-$(CONFIG_MN10300_RTC) += rtc.o
+obj-$(CONFIG_PROFILE) += profile.o profile-low.o
+obj-$(CONFIG_MODULES) += module.o
+obj-$(CONFIG_KPROBES) += kprobes.o
diff --git a/arch/mn10300/kernel/asm-offsets.c b/arch/mn10300/kernel/asm-offsets.c
new file mode 100644 (file)
index 0000000..ee2d9f8
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Generate definitions needed by assembly language modules.
+ * This code generates raw asm output which is post-processed
+ * to extract and format the required data.
+ */
+
+#include <linux/sched.h>
+#include <linux/signal.h>
+#include <linux/personality.h>
+#include <asm/ucontext.h>
+#include <asm/processor.h>
+#include <asm/thread_info.h>
+#include <asm/ptrace.h>
+#include "sigframe.h"
+#include "mn10300-serial.h"
+
+#define DEFINE(sym, val) \
+       asm volatile("\n->" #sym " %0 " #val : : "i" (val))
+
+#define BLANK() asm volatile("\n->")
+
+#define OFFSET(sym, str, mem) \
+       DEFINE(sym, offsetof(struct str, mem));
+
+void foo(void)
+{
+       OFFSET(SIGCONTEXT_d0, sigcontext, d0);
+       OFFSET(SIGCONTEXT_d1, sigcontext, d1);
+       BLANK();
+
+       OFFSET(TI_task,                 thread_info, task);
+       OFFSET(TI_exec_domain,          thread_info, exec_domain);
+       OFFSET(TI_flags,                thread_info, flags);
+       OFFSET(TI_cpu,                  thread_info, cpu);
+       OFFSET(TI_preempt_count,        thread_info, preempt_count);
+       OFFSET(TI_addr_limit,           thread_info, addr_limit);
+       OFFSET(TI_restart_block,        thread_info, restart_block);
+       BLANK();
+
+       OFFSET(REG_D0,                  pt_regs, d0);
+       OFFSET(REG_D1,                  pt_regs, d1);
+       OFFSET(REG_D2,                  pt_regs, d2);
+       OFFSET(REG_D3,                  pt_regs, d3);
+       OFFSET(REG_A0,                  pt_regs, a0);
+       OFFSET(REG_A1,                  pt_regs, a1);
+       OFFSET(REG_A2,                  pt_regs, a2);
+       OFFSET(REG_A3,                  pt_regs, a3);
+       OFFSET(REG_E0,                  pt_regs, e0);
+       OFFSET(REG_E1,                  pt_regs, e1);
+       OFFSET(REG_E2,                  pt_regs, e2);
+       OFFSET(REG_E3,                  pt_regs, e3);
+       OFFSET(REG_E4,                  pt_regs, e4);
+       OFFSET(REG_E5,                  pt_regs, e5);
+       OFFSET(REG_E6,                  pt_regs, e6);
+       OFFSET(REG_E7,                  pt_regs, e7);
+       OFFSET(REG_SP,                  pt_regs, sp);
+       OFFSET(REG_EPSW,                pt_regs, epsw);
+       OFFSET(REG_PC,                  pt_regs, pc);
+       OFFSET(REG_LAR,                 pt_regs, lar);
+       OFFSET(REG_LIR,                 pt_regs, lir);
+       OFFSET(REG_MDR,                 pt_regs, mdr);
+       OFFSET(REG_MCVF,                pt_regs, mcvf);
+       OFFSET(REG_MCRL,                pt_regs, mcrl);
+       OFFSET(REG_MCRH,                pt_regs, mcrh);
+       OFFSET(REG_MDRQ,                pt_regs, mdrq);
+       OFFSET(REG_ORIG_D0,             pt_regs, orig_d0);
+       OFFSET(REG_NEXT,                pt_regs, next);
+       DEFINE(REG__END,                sizeof(struct pt_regs));
+       BLANK();
+
+       OFFSET(THREAD_UREGS,            thread_struct, uregs);
+       OFFSET(THREAD_PC,               thread_struct, pc);
+       OFFSET(THREAD_SP,               thread_struct, sp);
+       OFFSET(THREAD_A3,               thread_struct, a3);
+       OFFSET(THREAD_USP,              thread_struct, usp);
+       OFFSET(THREAD_FRAME,            thread_struct, __frame);
+       BLANK();
+
+       DEFINE(CLONE_VM_asm,            CLONE_VM);
+       DEFINE(CLONE_FS_asm,            CLONE_FS);
+       DEFINE(CLONE_FILES_asm,         CLONE_FILES);
+       DEFINE(CLONE_SIGHAND_asm,       CLONE_SIGHAND);
+       DEFINE(CLONE_UNTRACED_asm,      CLONE_UNTRACED);
+       DEFINE(SIGCHLD_asm,             SIGCHLD);
+       BLANK();
+
+       OFFSET(EXEC_DOMAIN_handler,     exec_domain, handler);
+       OFFSET(RT_SIGFRAME_sigcontext,  rt_sigframe, uc.uc_mcontext);
+
+       DEFINE(PAGE_SIZE_asm,           PAGE_SIZE);
+
+       OFFSET(__rx_buffer,             mn10300_serial_port, rx_buffer);
+       OFFSET(__rx_inp,                mn10300_serial_port, rx_inp);
+       OFFSET(__rx_outp,               mn10300_serial_port, rx_outp);
+       OFFSET(__tx_info_buffer,        mn10300_serial_port, uart.info);
+       OFFSET(__tx_xchar,              mn10300_serial_port, tx_xchar);
+       OFFSET(__tx_break,              mn10300_serial_port, tx_break);
+       OFFSET(__intr_flags,            mn10300_serial_port, intr_flags);
+       OFFSET(__rx_icr,                mn10300_serial_port, rx_icr);
+       OFFSET(__tx_icr,                mn10300_serial_port, tx_icr);
+       OFFSET(__tm_icr,                mn10300_serial_port, _tmicr);
+       OFFSET(__iobase,                mn10300_serial_port, _iobase);
+
+       DEFINE(__UART_XMIT_SIZE,        UART_XMIT_SIZE);
+       OFFSET(__xmit_buffer,           uart_info, xmit.buf);
+       OFFSET(__xmit_head,             uart_info, xmit.head);
+       OFFSET(__xmit_tail,             uart_info, xmit.tail);
+}
diff --git a/arch/mn10300/kernel/entry.S b/arch/mn10300/kernel/entry.S
new file mode 100644 (file)
index 0000000..11de360
--- /dev/null
@@ -0,0 +1,721 @@
+###############################################################################
+#
+# MN10300 Exception and interrupt entry points
+#
+# Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+# Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+# Modified by David Howells (dhowells@redhat.com)
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public Licence
+# as published by the Free Software Foundation; either version
+# 2 of the Licence, or (at your option) any later version.
+#
+###############################################################################
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/smp.h>
+#include <asm/system.h>
+#include <asm/thread_info.h>
+#include <asm/intctl-regs.h>
+#include <asm/busctl-regs.h>
+#include <asm/timer-regs.h>
+#include <asm/unit/leds.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
+#include <asm/errno.h>
+#include <asm/asm-offsets.h>
+#include <asm/frame.inc>
+
+#ifdef CONFIG_PREEMPT
+#define preempt_stop           __cli
+#else
+#define preempt_stop
+#define resume_kernel          restore_all
+#endif
+
+       .macro __cli
+       and     ~EPSW_IM,epsw
+       or      EPSW_IE|MN10300_CLI_LEVEL,epsw
+       nop
+       nop
+       nop
+       .endm
+       .macro __sti
+       or      EPSW_IE|EPSW_IM_7,epsw
+       .endm
+
+
+       .am33_2
+
+###############################################################################
+#
+# the return path for a forked child
+# - on entry, D0 holds the address of the previous task to run
+#
+###############################################################################
+ENTRY(ret_from_fork)
+       call    schedule_tail[],0
+       GET_THREAD_INFO a2
+
+       # return 0 to indicate child process
+       clr     d0
+       mov     d0,(REG_D0,fp)
+       jmp     syscall_exit
+
+###############################################################################
+#
+# system call handler
+#
+###############################################################################
+ENTRY(system_call)
+       add     -4,sp
+       SAVE_ALL
+       mov     d0,(REG_ORIG_D0,fp)
+       GET_THREAD_INFO a2
+       cmp     nr_syscalls,d0
+       bcc     syscall_badsys
+       btst    _TIF_SYSCALL_TRACE,(TI_flags,a2)
+       bne     syscall_trace_entry
+syscall_call:
+       add     d0,d0,a1
+       add     a1,a1
+       mov     (REG_A0,fp),d0
+       mov     (sys_call_table,a1),a0
+       calls   (a0)
+       mov     d0,(REG_D0,fp)
+syscall_exit:
+       # make sure we don't miss an interrupt setting need_resched or
+       # sigpending between sampling and the rti
+       __cli
+       mov     (TI_flags,a2),d2
+       btst    _TIF_ALLWORK_MASK,d2
+       bne     syscall_exit_work
+restore_all:
+       RESTORE_ALL
+
+###############################################################################
+#
+# perform work that needs to be done immediately before resumption and syscall
+# tracing
+#
+###############################################################################
+       ALIGN
+syscall_exit_work:
+       btst    _TIF_SYSCALL_TRACE,d2
+       beq     work_pending
+       __sti                           # could let do_syscall_trace() call
+                                       # schedule() instead
+       mov     fp,d0
+       mov     1,d1
+       call    do_syscall_trace[],0    # do_syscall_trace(regs,entryexit)
+       jmp     resume_userspace
+
+       ALIGN
+work_pending:
+       btst    _TIF_NEED_RESCHED,d2
+       beq     work_notifysig
+
+work_resched:
+       call    schedule[],0
+
+       # make sure we don't miss an interrupt setting need_resched or
+       # sigpending between sampling and the rti
+       __cli
+
+       # is there any work to be done other than syscall tracing?
+       mov     (TI_flags,a2),d2
+       btst    _TIF_WORK_MASK,d2
+       beq     restore_all
+       btst    _TIF_NEED_RESCHED,d2
+       bne     work_resched
+
+       # deal with pending signals and notify-resume requests
+work_notifysig:
+       mov     fp,d0
+       mov     d2,d1
+       call    do_notify_resume[],0
+       jmp     resume_userspace
+
+       # perform syscall entry tracing
+syscall_trace_entry:
+       mov     -ENOSYS,d0
+       mov     d0,(REG_D0,fp)
+       mov     fp,d0
+       clr     d1
+       call    do_syscall_trace[],0
+       mov     (REG_ORIG_D0,fp),d0
+       mov     (REG_D1,fp),d1
+       cmp     nr_syscalls,d0
+       bcs     syscall_call
+       jmp     syscall_exit
+
+syscall_badsys:
+       mov     -ENOSYS,d0
+       mov     d0,(REG_D0,fp)
+       jmp     resume_userspace
+
+       # userspace resumption stub bypassing syscall exit tracing
+       .globl  ret_from_exception, ret_from_intr
+       ALIGN
+ret_from_exception:
+       preempt_stop
+ret_from_intr:
+       GET_THREAD_INFO a2
+       mov     (REG_EPSW,fp),d0        # need to deliver signals before
+                                       # returning to userspace
+       and     EPSW_nSL,d0
+       beq     resume_kernel           # returning to supervisor mode
+
+ENTRY(resume_userspace)
+       # make sure we don't miss an interrupt setting need_resched or
+       # sigpending between sampling and the rti
+       __cli
+
+       # is there any work to be done on int/exception return?
+       mov     (TI_flags,a2),d2
+       btst    _TIF_WORK_MASK,d2
+       bne     work_pending
+       jmp     restore_all
+
+#ifdef CONFIG_PREEMPT
+ENTRY(resume_kernel)
+       mov     (TI_preempt_count,a2),d0        # non-zero preempt_count ?
+       cmp     0,d0
+       bne     restore_all
+
+need_resched:
+       btst    _TIF_NEED_RESCHED,(TI_flags,a2)
+       beq     restore_all
+       mov     (REG_EPSW,fp),d0
+       and     EPSW_IM,d0
+       cmp     EPSW_IM_7,d0            # interrupts off (exception path) ?
+       beq     restore_all
+       call    preempt_schedule_irq[],0
+       jmp     need_resched
+#endif
+
+
+###############################################################################
+#
+# IRQ handler entry point
+# - intended to be entered at multiple priorities
+#
+###############################################################################
+ENTRY(irq_handler)
+       add     -4,sp
+       SAVE_ALL
+
+       # it's not a syscall
+       mov     0xffffffff,d0
+       mov     d0,(REG_ORIG_D0,fp)
+
+       mov     fp,d0
+       call    do_IRQ[],0                      # do_IRQ(regs)
+
+       jmp     ret_from_intr
+
+###############################################################################
+#
+# Monitor Signal handler entry point
+#
+###############################################################################
+ENTRY(monitor_signal)
+       movbu   (0xae000001),d1
+       cmp     1,d1
+       beq     monsignal
+       ret     [],0
+
+monsignal:
+       or      EPSW_NMID,epsw
+       mov     d0,a0
+       mov     a0,sp
+       mov     (REG_EPSW,fp),d1
+       and     ~EPSW_nSL,d1
+       mov     d1,(REG_EPSW,fp)
+       movm    (sp),[d2,d3,a2,a3,exreg0,exreg1,exother]
+       mov     (sp),a1
+       mov     a1,usp
+       movm    (sp),[other]
+       add     4,sp
+here:  jmp     0x8e000008-here+0x8e000008
+
+###############################################################################
+#
+# Double Fault handler entry point
+# - note that there will not be a stack, D0/A0 will hold EPSW/PC as were
+#
+###############################################################################
+       .section .bss
+       .balign THREAD_SIZE
+       .space  THREAD_SIZE
+__df_stack:
+       .previous
+
+ENTRY(double_fault)
+       mov     a0,(__df_stack-4)       # PC as was
+       mov     d0,(__df_stack-8)       # EPSW as was
+       mn10300_set_dbfleds             # display 'db-f' on the LEDs
+       mov     0xaa55aa55,d0
+       mov     d0,(__df_stack-12)      # no ORIG_D0
+       mov     sp,a0                   # save corrupted SP
+       mov     __df_stack-12,sp        # emergency supervisor stack
+       SAVE_ALL
+       mov     a0,(REG_A0,fp)          # save corrupted SP as A0 (which got
+                                       # clobbered by the CPU)
+       mov     fp,d0
+       calls   do_double_fault
+double_fault_loop:
+       bra     double_fault_loop
+
+###############################################################################
+#
+# Bus Error handler entry point
+# - handle external (async) bus errors separately
+#
+###############################################################################
+ENTRY(raw_bus_error)
+       add     -4,sp
+       mov     d0,(sp)
+       mov     (BCBERR),d0             # what
+       btst    BCBERR_BEMR_DMA,d0      # see if it was an external bus error
+       beq     __common_exception_aux  # it wasn't
+
+       SAVE_ALL
+       mov     (BCBEAR),d1             # destination of erroneous access
+
+       mov     (REG_ORIG_D0,fp),d2
+       mov     d2,(REG_D0,fp)
+       mov     -1,d2
+       mov     d2,(REG_ORIG_D0,fp)
+
+       add     -4,sp
+       mov     fp,(12,sp)              # frame pointer
+       call    io_bus_error[],0
+       jmp     restore_all
+
+###############################################################################
+#
+# Miscellaneous exception entry points
+#
+###############################################################################
+ENTRY(nmi_handler)
+       add     -4,sp
+       mov     d0,(sp)
+       mov     (TBR),d0
+       bra     __common_exception_nonmi
+
+ENTRY(__common_exception)
+       add     -4,sp
+       mov     d0,(sp)
+
+__common_exception_aux:
+       mov     (TBR),d0
+       and     ~EPSW_NMID,epsw         # turn NMIs back on if not NMI
+       or      EPSW_IE,epsw
+
+__common_exception_nonmi:
+       and     0x0000FFFF,d0           # turn the exception code into a vector
+                                       # table index
+
+       btst    0x00000007,d0
+       bne     1f
+       cmp     0x00000400,d0
+       bge     1f
+
+       SAVE_ALL                        # build the stack frame
+
+       mov     (REG_D0,fp),a2          # get the exception number
+       mov     (REG_ORIG_D0,fp),d0
+       mov     d0,(REG_D0,fp)
+       mov     -1,d0
+       mov     d0,(REG_ORIG_D0,fp)
+
+#ifdef CONFIG_GDBSTUB
+       btst    0x01,(gdbstub_busy)
+       beq     2f
+       and     ~EPSW_IE,epsw
+       mov     fp,d0
+       mov     a2,d1
+       call    gdbstub_exception[],0   # gdbstub itself caused an exception
+       bra     restore_all
+2:
+#endif
+
+       mov     fp,d0                   # arg 0: stacked register file
+       mov     a2,d1                   # arg 1: exception number
+       lsr     1,a2
+
+       mov     (exception_table,a2),a2
+       calls   (a2)
+       jmp     ret_from_exception
+
+1:     pi                              # BUG() equivalent
+
+###############################################################################
+#
+# Exception handler functions table
+#
+###############################################################################
+       .data
+ENTRY(exception_table)
+       .rept   0x400>>1
+        .long  uninitialised_exception
+       .endr
+       .previous
+
+###############################################################################
+#
+# Change an entry in the exception table
+# - D0 exception code, D1 handler
+#
+###############################################################################
+ENTRY(set_excp_vector)
+       lsr     1,d0
+       add     exception_table,d0
+       mov     d1,(d0)
+       mov     4,d1
+#if defined(CONFIG_MN10300_CACHE_WBACK)
+       jmp     mn10300_dcache_flush_inv_range2
+#else
+       ret     [],0
+#endif
+
+###############################################################################
+#
+# System call table
+#
+###############################################################################
+       .data
+ENTRY(sys_call_table)
+       .long sys_restart_syscall       /* 0 */
+       .long sys_exit
+       .long sys_fork
+       .long sys_read
+       .long sys_write
+       .long sys_open          /* 5 */
+       .long sys_close
+       .long sys_waitpid
+       .long sys_creat
+       .long sys_link
+       .long sys_unlink        /* 10 */
+       .long sys_execve
+       .long sys_chdir
+       .long sys_time
+       .long sys_mknod
+       .long sys_chmod         /* 15 */
+       .long sys_lchown16
+       .long sys_ni_syscall    /* old break syscall holder */
+       .long sys_stat
+       .long sys_lseek
+       .long sys_getpid        /* 20 */
+       .long sys_mount
+       .long sys_oldumount
+       .long sys_setuid16
+       .long sys_getuid16
+       .long sys_stime         /* 25 */
+       .long sys_ptrace
+       .long sys_alarm
+       .long sys_fstat
+       .long sys_pause
+       .long sys_utime         /* 30 */
+       .long sys_ni_syscall    /* old stty syscall holder */
+       .long sys_ni_syscall    /* old gtty syscall holder */
+       .long sys_access
+       .long sys_nice
+       .long sys_ni_syscall    /* 35 - old ftime syscall holder */
+       .long sys_sync
+       .long sys_kill
+       .long sys_rename
+       .long sys_mkdir
+       .long sys_rmdir         /* 40 */
+       .long sys_dup
+       .long sys_pipe
+       .long sys_times
+       .long sys_ni_syscall    /* old prof syscall holder */
+       .long sys_brk           /* 45 */
+       .long sys_setgid16
+       .long sys_getgid16
+       .long sys_signal
+       .long sys_geteuid16
+       .long sys_getegid16     /* 50 */
+       .long sys_acct
+       .long sys_umount        /* recycled never used phys() */
+       .long sys_ni_syscall    /* old lock syscall holder */
+       .long sys_ioctl
+       .long sys_fcntl         /* 55 */
+       .long sys_ni_syscall    /* old mpx syscall holder */
+       .long sys_setpgid
+       .long sys_ni_syscall    /* old ulimit syscall holder */
+       .long sys_ni_syscall    /* old sys_olduname */
+       .long sys_umask         /* 60 */
+       .long sys_chroot
+       .long sys_ustat
+       .long sys_dup2
+       .long sys_getppid
+       .long sys_getpgrp       /* 65 */
+       .long sys_setsid
+       .long sys_sigaction
+       .long sys_sgetmask
+       .long sys_ssetmask
+       .long sys_setreuid16    /* 70 */
+       .long sys_setregid16
+       .long sys_sigsuspend
+       .long sys_sigpending
+       .long sys_sethostname
+       .long sys_setrlimit     /* 75 */
+       .long sys_old_getrlimit
+       .long sys_getrusage
+       .long sys_gettimeofday
+       .long sys_settimeofday
+       .long sys_getgroups16   /* 80 */
+       .long sys_setgroups16
+       .long old_select
+       .long sys_symlink
+       .long sys_lstat
+       .long sys_readlink      /* 85 */
+       .long sys_uselib
+       .long sys_swapon
+       .long sys_reboot
+       .long old_readdir
+       .long old_mmap          /* 90 */
+       .long sys_munmap
+       .long sys_truncate
+       .long sys_ftruncate
+       .long sys_fchmod
+       .long sys_fchown16      /* 95 */
+       .long sys_getpriority
+       .long sys_setpriority
+       .long sys_ni_syscall    /* old profil syscall holder */
+       .long sys_statfs
+       .long sys_fstatfs       /* 100 */
+       .long sys_ni_syscall    /* ioperm */
+       .long sys_socketcall
+       .long sys_syslog
+       .long sys_setitimer
+       .long sys_getitimer     /* 105 */
+       .long sys_newstat
+       .long sys_newlstat
+       .long sys_newfstat
+       .long sys_ni_syscall    /* old sys_uname */
+       .long sys_ni_syscall    /* 110 - iopl */
+       .long sys_vhangup
+       .long sys_ni_syscall    /* old "idle" system call */
+       .long sys_ni_syscall    /* vm86old */
+       .long sys_wait4
+       .long sys_swapoff       /* 115 */
+       .long sys_sysinfo
+       .long sys_ipc
+       .long sys_fsync
+       .long sys_sigreturn
+       .long sys_clone         /* 120 */
+       .long sys_setdomainname
+       .long sys_newuname
+       .long sys_ni_syscall    /* modify_ldt */
+       .long sys_adjtimex
+       .long sys_mprotect      /* 125 */
+       .long sys_sigprocmask
+       .long sys_ni_syscall    /* old "create_module" */
+       .long sys_init_module
+       .long sys_delete_module
+       .long sys_ni_syscall    /* 130: old "get_kernel_syms" */
+       .long sys_quotactl
+       .long sys_getpgid
+       .long sys_fchdir
+       .long sys_bdflush
+       .long sys_sysfs         /* 135 */
+       .long sys_personality
+       .long sys_ni_syscall    /* reserved for afs_syscall */
+       .long sys_setfsuid16
+       .long sys_setfsgid16
+       .long sys_llseek        /* 140 */
+       .long sys_getdents
+       .long sys_select
+       .long sys_flock
+       .long sys_msync
+       .long sys_readv         /* 145 */
+       .long sys_writev
+       .long sys_getsid
+       .long sys_fdatasync
+       .long sys_sysctl
+       .long sys_mlock         /* 150 */
+       .long sys_munlock
+       .long sys_mlockall
+       .long sys_munlockall
+       .long sys_sched_setparam
+       .long sys_sched_getparam   /* 155 */
+       .long sys_sched_setscheduler
+       .long sys_sched_getscheduler
+       .long sys_sched_yield
+       .long sys_sched_get_priority_max
+       .long sys_sched_get_priority_min  /* 160 */
+       .long sys_sched_rr_get_interval
+       .long sys_nanosleep
+       .long sys_mremap
+       .long sys_setresuid16
+       .long sys_getresuid16   /* 165 */
+       .long sys_ni_syscall    /* vm86 */
+       .long sys_ni_syscall    /* Old sys_query_module */
+       .long sys_poll
+       .long sys_nfsservctl
+       .long sys_setresgid16   /* 170 */
+       .long sys_getresgid16
+       .long sys_prctl
+       .long sys_rt_sigreturn
+       .long sys_rt_sigaction
+       .long sys_rt_sigprocmask        /* 175 */
+       .long sys_rt_sigpending
+       .long sys_rt_sigtimedwait
+       .long sys_rt_sigqueueinfo
+       .long sys_rt_sigsuspend
+       .long sys_pread64       /* 180 */
+       .long sys_pwrite64
+       .long sys_chown16
+       .long sys_getcwd
+       .long sys_capget
+       .long sys_capset        /* 185 */
+       .long sys_sigaltstack
+       .long sys_sendfile
+       .long sys_ni_syscall    /* reserved for streams1 */
+       .long sys_ni_syscall    /* reserved for streams2 */
+       .long sys_vfork         /* 190 */
+       .long sys_getrlimit
+       .long sys_mmap2
+       .long sys_truncate64
+       .long sys_ftruncate64
+       .long sys_stat64        /* 195 */
+       .long sys_lstat64
+       .long sys_fstat64
+       .long sys_lchown
+       .long sys_getuid
+       .long sys_getgid        /* 200 */
+       .long sys_geteuid
+       .long sys_getegid
+       .long sys_setreuid
+       .long sys_setregid
+       .long sys_getgroups     /* 205 */
+       .long sys_setgroups
+       .long sys_fchown
+       .long sys_setresuid
+       .long sys_getresuid
+       .long sys_setresgid     /* 210 */
+       .long sys_getresgid
+       .long sys_chown
+       .long sys_setuid
+       .long sys_setgid
+       .long sys_setfsuid      /* 215 */
+       .long sys_setfsgid
+       .long sys_pivot_root
+       .long sys_mincore
+       .long sys_madvise
+       .long sys_getdents64    /* 220 */
+       .long sys_fcntl64
+       .long sys_ni_syscall    /* reserved for TUX */
+       .long sys_ni_syscall
+       .long sys_gettid
+       .long sys_readahead     /* 225 */
+       .long sys_setxattr
+       .long sys_lsetxattr
+       .long sys_fsetxattr
+       .long sys_getxattr
+       .long sys_lgetxattr     /* 230 */
+       .long sys_fgetxattr
+       .long sys_listxattr
+       .long sys_llistxattr
+       .long sys_flistxattr
+       .long sys_removexattr   /* 235 */
+       .long sys_lremovexattr
+       .long sys_fremovexattr
+       .long sys_tkill
+       .long sys_sendfile64
+       .long sys_futex         /* 240 */
+       .long sys_sched_setaffinity
+       .long sys_sched_getaffinity
+       .long sys_ni_syscall    /* sys_set_thread_area */
+       .long sys_ni_syscall    /* sys_get_thread_area */
+       .long sys_io_setup      /* 245 */
+       .long sys_io_destroy
+       .long sys_io_getevents
+       .long sys_io_submit
+       .long sys_io_cancel
+       .long sys_fadvise64     /* 250 */
+       .long sys_ni_syscall
+       .long sys_exit_group
+       .long sys_lookup_dcookie
+       .long sys_epoll_create
+       .long sys_epoll_ctl     /* 255 */
+       .long sys_epoll_wait
+       .long sys_remap_file_pages
+       .long sys_set_tid_address
+       .long sys_timer_create
+       .long sys_timer_settime         /* 260 */
+       .long sys_timer_gettime
+       .long sys_timer_getoverrun
+       .long sys_timer_delete
+       .long sys_clock_settime
+       .long sys_clock_gettime         /* 265 */
+       .long sys_clock_getres
+       .long sys_clock_nanosleep
+       .long sys_statfs64
+       .long sys_fstatfs64
+       .long sys_tgkill                /* 270 */
+       .long sys_utimes
+       .long sys_fadvise64_64
+       .long sys_ni_syscall    /* sys_vserver */
+       .long sys_mbind
+       .long sys_get_mempolicy         /* 275 */
+       .long sys_set_mempolicy
+       .long sys_mq_open
+       .long sys_mq_unlink
+       .long sys_mq_timedsend
+       .long sys_mq_timedreceive       /* 280 */
+       .long sys_mq_notify
+       .long sys_mq_getsetattr
+       .long sys_kexec_load
+       .long sys_waitid
+       .long sys_ni_syscall            /* 285 */ /* available */
+       .long sys_add_key
+       .long sys_request_key
+       .long sys_keyctl
+       .long sys_cacheflush
+       .long sys_ioprio_set            /* 290 */
+       .long sys_ioprio_get
+       .long sys_inotify_init
+       .long sys_inotify_add_watch
+       .long sys_inotify_rm_watch
+       .long sys_migrate_pages         /* 295 */
+       .long sys_openat
+       .long sys_mkdirat
+       .long sys_mknodat
+       .long sys_fchownat
+       .long sys_futimesat             /* 300 */
+       .long sys_fstatat64
+       .long sys_unlinkat
+       .long sys_renameat
+       .long sys_linkat
+       .long sys_symlinkat             /* 305 */
+       .long sys_readlinkat
+       .long sys_fchmodat
+       .long sys_faccessat
+       .long sys_pselect6
+       .long sys_ppoll                 /* 310 */
+       .long sys_unshare
+       .long sys_set_robust_list
+       .long sys_get_robust_list
+       .long sys_splice
+       .long sys_sync_file_range       /* 315 */
+       .long sys_tee
+       .long sys_vmsplice
+       .long sys_move_pages
+       .long sys_getcpu
+       .long sys_epoll_pwait           /* 320 */
+       .long sys_utimensat
+       .long sys_signalfd
+       .long sys_timerfd_create
+       .long sys_eventfd
+       .long sys_fallocate             /* 325 */
+       .long sys_timerfd_settime
+       .long sys_timerfd_gettime
+
+
+nr_syscalls=(.-sys_call_table)/4
diff --git a/arch/mn10300/kernel/fpu-low.S b/arch/mn10300/kernel/fpu-low.S
new file mode 100644 (file)
index 0000000..96cfd47
--- /dev/null
@@ -0,0 +1,197 @@
+/* MN10300 Low level FPU management operations
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <asm/cpu-regs.h>
+
+###############################################################################
+#
+# void fpu_init_state(void)
+# - initialise the FPU
+#
+###############################################################################
+       .globl  fpu_init_state
+       .type   fpu_init_state,@function
+fpu_init_state:
+       mov     epsw,d0
+       or      EPSW_FE,epsw
+
+#ifdef CONFIG_MN10300_PROC_MN103E010
+       nop
+       nop
+       nop
+#endif
+       fmov    0,fs0
+       fmov    fs0,fs1
+       fmov    fs0,fs2
+       fmov    fs0,fs3
+       fmov    fs0,fs4
+       fmov    fs0,fs5
+       fmov    fs0,fs6
+       fmov    fs0,fs7
+       fmov    fs0,fs8
+       fmov    fs0,fs9
+       fmov    fs0,fs10
+       fmov    fs0,fs11
+       fmov    fs0,fs12
+       fmov    fs0,fs13
+       fmov    fs0,fs14
+       fmov    fs0,fs15
+       fmov    fs0,fs16
+       fmov    fs0,fs17
+       fmov    fs0,fs18
+       fmov    fs0,fs19
+       fmov    fs0,fs20
+       fmov    fs0,fs21
+       fmov    fs0,fs22
+       fmov    fs0,fs23
+       fmov    fs0,fs24
+       fmov    fs0,fs25
+       fmov    fs0,fs26
+       fmov    fs0,fs27
+       fmov    fs0,fs28
+       fmov    fs0,fs29
+       fmov    fs0,fs30
+       fmov    fs0,fs31
+       fmov    FPCR_INIT,fpcr
+
+#ifdef CONFIG_MN10300_PROC_MN103E010
+       nop
+       nop
+       nop
+#endif
+       mov     d0,epsw
+       ret     [],0
+
+       .size   fpu_init_state,.-fpu_init_state
+
+###############################################################################
+#
+# void fpu_save(struct fpu_state_struct *)
+# - save the fpu state
+# - note that an FPU Operational exception might occur during this process
+#
+###############################################################################
+       .globl  fpu_save
+       .type   fpu_save,@function
+fpu_save:
+       mov     epsw,d1
+       or      EPSW_FE,epsw            /* enable the FPU so we can access it */
+
+#ifdef CONFIG_MN10300_PROC_MN103E010
+       nop
+       nop
+#endif
+       mov     d0,a0
+       fmov    fs0,(a0+)
+       fmov    fs1,(a0+)
+       fmov    fs2,(a0+)
+       fmov    fs3,(a0+)
+       fmov    fs4,(a0+)
+       fmov    fs5,(a0+)
+       fmov    fs6,(a0+)
+       fmov    fs7,(a0+)
+       fmov    fs8,(a0+)
+       fmov    fs9,(a0+)
+       fmov    fs10,(a0+)
+       fmov    fs11,(a0+)
+       fmov    fs12,(a0+)
+       fmov    fs13,(a0+)
+       fmov    fs14,(a0+)
+       fmov    fs15,(a0+)
+       fmov    fs16,(a0+)
+       fmov    fs17,(a0+)
+       fmov    fs18,(a0+)
+       fmov    fs19,(a0+)
+       fmov    fs20,(a0+)
+       fmov    fs21,(a0+)
+       fmov    fs22,(a0+)
+       fmov    fs23,(a0+)
+       fmov    fs24,(a0+)
+       fmov    fs25,(a0+)
+       fmov    fs26,(a0+)
+       fmov    fs27,(a0+)
+       fmov    fs28,(a0+)
+       fmov    fs29,(a0+)
+       fmov    fs30,(a0+)
+       fmov    fs31,(a0+)
+       fmov    fpcr,d0
+       mov     d0,(a0)
+#ifdef CONFIG_MN10300_PROC_MN103E010
+       nop
+       nop
+#endif
+
+       mov     d1,epsw
+       ret     [],0
+
+       .size   fpu_save,.-fpu_save
+
+###############################################################################
+#
+# void fpu_restore(struct fpu_state_struct *)
+# - restore the fpu state
+# - note that an FPU Operational exception might occur during this process
+#
+###############################################################################
+       .globl  fpu_restore
+       .type   fpu_restore,@function
+fpu_restore:
+       mov     epsw,d1
+       or      EPSW_FE,epsw            /* enable the FPU so we can access it */
+
+#ifdef CONFIG_MN10300_PROC_MN103E010
+       nop
+       nop
+#endif
+       mov     d0,a0
+       fmov    (a0+),fs0
+       fmov    (a0+),fs1
+       fmov    (a0+),fs2
+       fmov    (a0+),fs3
+       fmov    (a0+),fs4
+       fmov    (a0+),fs5
+       fmov    (a0+),fs6
+       fmov    (a0+),fs7
+       fmov    (a0+),fs8
+       fmov    (a0+),fs9
+       fmov    (a0+),fs10
+       fmov    (a0+),fs11
+       fmov    (a0+),fs12
+       fmov    (a0+),fs13
+       fmov    (a0+),fs14
+       fmov    (a0+),fs15
+       fmov    (a0+),fs16
+       fmov    (a0+),fs17
+       fmov    (a0+),fs18
+       fmov    (a0+),fs19
+       fmov    (a0+),fs20
+       fmov    (a0+),fs21
+       fmov    (a0+),fs22
+       fmov    (a0+),fs23
+       fmov    (a0+),fs24
+       fmov    (a0+),fs25
+       fmov    (a0+),fs26
+       fmov    (a0+),fs27
+       fmov    (a0+),fs28
+       fmov    (a0+),fs29
+       fmov    (a0+),fs30
+       fmov    (a0+),fs31
+       mov     (a0),d0
+       fmov    d0,fpcr
+#ifdef CONFIG_MN10300_PROC_MN103E010
+       nop
+       nop
+       nop
+#endif
+
+       mov     d1,epsw
+       ret     [],0
+
+       .size   fpu_restore,.-fpu_restore
diff --git a/arch/mn10300/kernel/fpu.c b/arch/mn10300/kernel/fpu.c
new file mode 100644 (file)
index 0000000..e705f25
--- /dev/null
@@ -0,0 +1,223 @@
+/* MN10300 FPU management
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <asm/uaccess.h>
+#include <asm/fpu.h>
+#include <asm/elf.h>
+#include <asm/exceptions.h>
+
+struct task_struct *fpu_state_owner;
+
+/*
+ * handle an exception due to the FPU being disabled
+ */
+asmlinkage void fpu_disabled(struct pt_regs *regs, enum exception_code code)
+{
+       struct task_struct *tsk = current;
+
+       if (!user_mode(regs))
+               die_if_no_fixup("An FPU Disabled exception happened in"
+                               " kernel space\n",
+                               regs, code);
+
+#ifdef CONFIG_FPU
+       preempt_disable();
+
+       /* transfer the last process's FPU state to memory */
+       if (fpu_state_owner) {
+               fpu_save(&fpu_state_owner->thread.fpu_state);
+               fpu_state_owner->thread.uregs->epsw &= ~EPSW_FE;
+       }
+
+       /* the current process now owns the FPU state */
+       fpu_state_owner = tsk;
+       regs->epsw |= EPSW_FE;
+
+       /* load the FPU with the current process's FPU state or invent a new
+        * clean one if the process doesn't have one */
+       if (is_using_fpu(tsk)) {
+               fpu_restore(&tsk->thread.fpu_state);
+       } else {
+               fpu_init_state();
+               set_using_fpu(tsk);
+       }
+
+       preempt_enable();
+#else
+       {
+               siginfo_t info;
+
+               info.si_signo = SIGFPE;
+               info.si_errno = 0;
+               info.si_addr = (void *) tsk->thread.uregs->pc;
+               info.si_code = FPE_FLTINV;
+
+               force_sig_info(SIGFPE, &info, tsk);
+       }
+#endif  /* CONFIG_FPU */
+}
+
+/*
+ * handle an FPU operational exception
+ * - there's a possibility that if the FPU is asynchronous, the signal might
+ *   be meant for a process other than the current one
+ */
+asmlinkage void fpu_exception(struct pt_regs *regs, enum exception_code code)
+{
+       struct task_struct *tsk = fpu_state_owner;
+       siginfo_t info;
+
+       if (!user_mode(regs))
+               die_if_no_fixup("An FPU Operation exception happened in"
+                               " kernel space\n",
+                               regs, code);
+
+       if (!tsk)
+               die_if_no_fixup("An FPU Operation exception happened,"
+                               " but the FPU is not in use",
+                               regs, code);
+
+       info.si_signo = SIGFPE;
+       info.si_errno = 0;
+       info.si_addr = (void *) tsk->thread.uregs->pc;
+       info.si_code = FPE_FLTINV;
+
+#ifdef CONFIG_FPU
+       {
+               u32 fpcr;
+
+               /* get FPCR (we need to enable the FPU whilst we do this) */
+               asm volatile("  or      %1,epsw         \n"
+#ifdef CONFIG_MN10300_PROC_MN103E010
+                            "  nop                     \n"
+                            "  nop                     \n"
+                            "  nop                     \n"
+#endif
+                            "  fmov    fpcr,%0         \n"
+#ifdef CONFIG_MN10300_PROC_MN103E010
+                            "  nop                     \n"
+                            "  nop                     \n"
+                            "  nop                     \n"
+#endif
+                            "  and     %2,epsw         \n"
+                            : "=&d"(fpcr)
+                            : "i"(EPSW_FE), "i"(~EPSW_FE)
+                            );
+
+               if (fpcr & FPCR_EC_Z)
+                       info.si_code = FPE_FLTDIV;
+               else if (fpcr & FPCR_EC_O)
+                       info.si_code = FPE_FLTOVF;
+               else if (fpcr & FPCR_EC_U)
+                       info.si_code = FPE_FLTUND;
+               else if (fpcr & FPCR_EC_I)
+                       info.si_code = FPE_FLTRES;
+       }
+#endif
+
+       force_sig_info(SIGFPE, &info, tsk);
+}
+
+/*
+ * save the FPU state to a signal context
+ */
+int fpu_setup_sigcontext(struct fpucontext *fpucontext)
+{
+#ifdef CONFIG_FPU
+       struct task_struct *tsk = current;
+
+       if (!is_using_fpu(tsk))
+               return 0;
+
+       /* transfer the current FPU state to memory and cause fpu_init() to be
+        * triggered by the next attempted FPU operation by the current
+        * process.
+        */
+       preempt_disable();
+
+       if (fpu_state_owner == tsk) {
+               fpu_save(&tsk->thread.fpu_state);
+               fpu_state_owner->thread.uregs->epsw &= ~EPSW_FE;
+               fpu_state_owner = NULL;
+       }
+
+       preempt_enable();
+
+       /* we no longer have a valid current FPU state */
+       clear_using_fpu(tsk);
+
+       /* transfer the saved FPU state onto the userspace stack */
+       if (copy_to_user(fpucontext,
+                        &tsk->thread.fpu_state,
+                        min(sizeof(struct fpu_state_struct),
+                            sizeof(struct fpucontext))))
+               return -1;
+
+       return 1;
+#else
+       return 0;
+#endif
+}
+
+/*
+ * kill a process's FPU state during restoration after signal handling
+ */
+void fpu_kill_state(struct task_struct *tsk)
+{
+#ifdef CONFIG_FPU
+       /* disown anything left in the FPU */
+       preempt_disable();
+
+       if (fpu_state_owner == tsk) {
+               fpu_state_owner->thread.uregs->epsw &= ~EPSW_FE;
+               fpu_state_owner = NULL;
+       }
+
+       preempt_enable();
+#endif
+       /* we no longer have a valid current FPU state */
+       clear_using_fpu(tsk);
+}
+
+/*
+ * restore the FPU state from a signal context
+ */
+int fpu_restore_sigcontext(struct fpucontext *fpucontext)
+{
+       struct task_struct *tsk = current;
+       int ret;
+
+       /* load up the old FPU state */
+       ret = copy_from_user(&tsk->thread.fpu_state,
+                            fpucontext,
+                            min(sizeof(struct fpu_state_struct),
+                                sizeof(struct fpucontext)));
+       if (!ret)
+               set_using_fpu(tsk);
+
+       return ret;
+}
+
+/*
+ * fill in the FPU structure for a core dump
+ */
+int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpreg)
+{
+       struct task_struct *tsk = current;
+       int fpvalid;
+
+       fpvalid = is_using_fpu(tsk);
+       if (fpvalid) {
+               unlazy_fpu(tsk);
+               memcpy(fpreg, &tsk->thread.fpu_state, sizeof(*fpreg));
+       }
+
+       return fpvalid;
+}
diff --git a/arch/mn10300/kernel/gdb-cache.S b/arch/mn10300/kernel/gdb-cache.S
new file mode 100644 (file)
index 0000000..1108bad
--- /dev/null
@@ -0,0 +1,105 @@
+###############################################################################
+#
+# MN10300 Low-level cache purging routines for gdbstub
+#
+# Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+# Written by David Howells (dhowells@redhat.com)
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public Licence
+# as published by the Free Software Foundation; either version
+# 2 of the Licence, or (at your option) any later version.
+#
+###############################################################################
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/smp.h>
+#include <asm/cache.h>
+#include <asm/cpu-regs.h>
+#include <asm/exceptions.h>
+#include <asm/frame.inc>
+#include <asm/serial-regs.h>
+
+       .text
+
+###############################################################################
+#
+# GDB stub cache purge
+#
+###############################################################################
+       .type   gdbstub_purge_cache,@function
+ENTRY(gdbstub_purge_cache)
+       #######################################################################
+       # read the addresses tagged in the cache's tag RAM and attempt to flush
+       # those addresses specifically
+       # - we rely on the hardware to filter out invalid tag entry addresses
+       mov     DCACHE_TAG(0,0),a0              # dcache tag RAM access address
+       mov     DCACHE_PURGE(0,0),a1            # dcache purge request address
+       mov     L1_CACHE_NWAYS*L1_CACHE_NENTRIES,d1  # total number of entries
+
+mn10300_dcache_flush_loop:
+       mov     (a0),d0
+       and     L1_CACHE_TAG_ADDRESS|L1_CACHE_TAG_ENTRY,d0
+       or      L1_CACHE_TAG_VALID,d0           # retain valid entries in the
+                                               # cache
+       mov     d0,(a1)                         # conditional purge
+
+mn10300_dcache_flush_skip:
+       add     L1_CACHE_BYTES,a0
+       add     L1_CACHE_BYTES,a1
+       add     -1,d1
+       bne     mn10300_dcache_flush_loop
+
+;;     # unconditionally flush and invalidate the dcache
+;;     mov     DCACHE_PURGE(0,0),a1            # dcache purge request address
+;;     mov     L1_CACHE_NWAYS*L1_CACHE_NENTRIES,d1     # total number of
+;;                                                     # entries
+;;
+;; gdbstub_purge_cache__dcache_loop:
+;;     mov     (a1),d0                         # unconditional purge
+;;
+;;     add     L1_CACHE_BYTES,a1
+;;     add     -1,d1
+;;     bne     gdbstub_purge_cache__dcache_loop
+
+       #######################################################################
+       # now invalidate the icache
+       mov     CHCTR,a0
+       movhu   (a0),a1
+
+       mov     epsw,d1
+       and     ~EPSW_IE,epsw
+       nop
+       nop
+
+       # disable the icache
+       and     ~CHCTR_ICEN,d0
+       movhu   d0,(a0)
+
+       # and wait for it to calm down
+       setlb
+       movhu   (a0),d0
+       btst    CHCTR_ICBUSY,d0
+       lne
+
+       # invalidate
+       or      CHCTR_ICINV,d0
+       movhu   d0,(a0)
+
+       # wait for the cache to finish
+       mov     CHCTR,a0
+       setlb
+       movhu   (a0),d0
+       btst    CHCTR_ICBUSY,d0
+       lne
+
+       # and reenable it
+       movhu   a1,(a0)
+       movhu   (a0),d0                 # read back to flush
+                                       # (SIGILLs all over without this)
+
+       mov     d1,epsw
+
+       ret     [],0
+
+       .size   gdbstub_purge_cache,.-gdbstub_purge_cache
diff --git a/arch/mn10300/kernel/gdb-io-serial-low.S b/arch/mn10300/kernel/gdb-io-serial-low.S
new file mode 100644 (file)
index 0000000..c68dcd0
--- /dev/null
@@ -0,0 +1,90 @@
+###############################################################################
+#
+# 16550 serial Rx interrupt handler for gdbstub I/O
+#
+# Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+# Written by David Howells (dhowells@redhat.com)
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public Licence
+# as published by the Free Software Foundation; either version
+# 2 of the Licence, or (at your option) any later version.
+#
+###############################################################################
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/smp.h>
+#include <asm/cpu-regs.h>
+#include <asm/thread_info.h>
+#include <asm/frame.inc>
+#include <asm/intctl-regs.h>
+#include <asm/unit/serial.h>
+
+       .text
+
+###############################################################################
+#
+# GDB stub serial receive interrupt entry point
+# - intended to run at interrupt priority 0
+#
+###############################################################################
+       .globl  gdbstub_io_rx_handler
+       .type   gdbstub_io_rx_handler,@function
+gdbstub_io_rx_handler:
+       movm    [d2,d3,a2,a3],(sp)
+
+#if 1
+       movbu   (GDBPORT_SERIAL_IIR),d2
+#endif
+
+       mov     (gdbstub_rx_inp),a3
+gdbstub_io_rx_more:
+       mov     a3,a2
+       add     2,a3
+       and     0x00000fff,a3
+       mov     (gdbstub_rx_outp),d3
+       cmp     a3,d3
+       beq     gdbstub_io_rx_overflow
+
+       movbu   (GDBPORT_SERIAL_LSR),d3
+       btst    UART_LSR_DR,d3
+       beq     gdbstub_io_rx_done
+       movbu   (GDBPORT_SERIAL_RX),d2
+       movbu   d3,(gdbstub_rx_buffer+1,a2)
+       movbu   d2,(gdbstub_rx_buffer,a2)
+       mov     a3,(gdbstub_rx_inp)
+       bra     gdbstub_io_rx_more
+
+gdbstub_io_rx_done:
+       mov     GxICR_DETECT,d2
+       movbu   d2,(XIRQxICR(GDBPORT_SERIAL_IRQ))       # ACK the interrupt
+       movhu   (XIRQxICR(GDBPORT_SERIAL_IRQ)),d2       # flush
+       movm    (sp),[d2,d3,a2,a3]
+       bset    0x01,(gdbstub_busy)
+       beq     gdbstub_io_rx_enter
+       rti
+
+gdbstub_io_rx_overflow:
+       bset    0x01,(gdbstub_rx_overflow)
+       bra     gdbstub_io_rx_done
+
+gdbstub_io_rx_enter:
+       or      EPSW_IE|EPSW_IM_1,epsw
+       add     -4,sp
+       SAVE_ALL
+
+       mov     0xffffffff,d0
+       mov     d0,(REG_ORIG_D0,fp)
+       mov     0x280,d1
+
+       mov     fp,d0
+       call    gdbstub_rx_irq[],0      # gdbstub_rx_irq(regs,excep)
+
+       and     ~EPSW_IE,epsw
+       bclr    0x01,(gdbstub_busy)
+
+       .globl gdbstub_return
+gdbstub_return:
+       RESTORE_ALL
+
+       .size   gdbstub_io_rx_handler,.-gdbstub_io_rx_handler
diff --git a/arch/mn10300/kernel/gdb-io-serial.c b/arch/mn10300/kernel/gdb-io-serial.c
new file mode 100644 (file)
index 0000000..9a6d4e8
--- /dev/null
@@ -0,0 +1,155 @@
+/* 16550 serial driver for gdbstub I/O
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/string.h>
+#include <linux/kernel.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/console.h>
+#include <linux/init.h>
+#include <linux/nmi.h>
+
+#include <asm/pgtable.h>
+#include <asm/system.h>
+#include <asm/gdb-stub.h>
+#include <asm/exceptions.h>
+#include <asm/serial-regs.h>
+#include <asm/unit/serial.h>
+
+/*
+ * initialise the GDB stub
+ */
+void gdbstub_io_init(void)
+{
+       u16 tmp;
+
+       /* set up the serial port */
+       GDBPORT_SERIAL_LCR = UART_LCR_WLEN8; /* 1N8 */
+       GDBPORT_SERIAL_FCR = (UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
+                             UART_FCR_CLEAR_XMIT);
+
+       FLOWCTL_CLEAR(DTR);
+       FLOWCTL_SET(RTS);
+
+       gdbstub_io_set_baud(115200);
+
+       /* we want to get serial receive interrupts */
+       XIRQxICR(GDBPORT_SERIAL_IRQ) = 0;
+       tmp = XIRQxICR(GDBPORT_SERIAL_IRQ);
+
+       IVAR0 = EXCEP_IRQ_LEVEL0;
+       set_intr_stub(EXCEP_IRQ_LEVEL0, gdbstub_io_rx_handler);
+
+       XIRQxICR(GDBPORT_SERIAL_IRQ) &= ~GxICR_REQUEST;
+       XIRQxICR(GDBPORT_SERIAL_IRQ) = GxICR_ENABLE | GxICR_LEVEL_0;
+       tmp = XIRQxICR(GDBPORT_SERIAL_IRQ);
+
+       GDBPORT_SERIAL_IER = UART_IER_RDI | UART_IER_RLSI;
+
+       /* permit level 0 IRQs to take place */
+       asm volatile(
+               "       and %0,epsw     \n"
+               "       or %1,epsw      \n"
+               :
+               : "i"(~EPSW_IM), "i"(EPSW_IE | EPSW_IM_1)
+               );
+}
+
+/*
+ * set up the GDB stub serial port baud rate timers
+ */
+void gdbstub_io_set_baud(unsigned baud)
+{
+       unsigned value;
+       u8 lcr;
+
+       value = 18432000 / 16 / baud;
+
+       lcr = GDBPORT_SERIAL_LCR;
+       GDBPORT_SERIAL_LCR |= UART_LCR_DLAB;
+       GDBPORT_SERIAL_DLL = value & 0xff;
+       GDBPORT_SERIAL_DLM = (value >> 8) & 0xff;
+       GDBPORT_SERIAL_LCR = lcr;
+}
+
+/*
+ * wait for a character to come from the debugger
+ */
+int gdbstub_io_rx_char(unsigned char *_ch, int nonblock)
+{
+       unsigned ix;
+       u8 ch, st;
+
+       *_ch = 0xff;
+
+       if (gdbstub_rx_unget) {
+               *_ch = gdbstub_rx_unget;
+               gdbstub_rx_unget = 0;
+               return 0;
+       }
+
+ try_again:
+       /* pull chars out of the buffer */
+       ix = gdbstub_rx_outp;
+       if (ix == gdbstub_rx_inp) {
+               if (nonblock)
+                       return -EAGAIN;
+#ifdef CONFIG_MN10300_WD_TIMER
+               watchdog_alert_counter = 0;
+#endif /* CONFIG_MN10300_WD_TIMER */
+               goto try_again;
+       }
+
+       ch = gdbstub_rx_buffer[ix++];
+       st = gdbstub_rx_buffer[ix++];
+       gdbstub_rx_outp = ix & 0x00000fff;
+
+       if (st & UART_LSR_BI) {
+               gdbstub_proto("### GDB Rx Break Detected ###\n");
+               return -EINTR;
+       } else if (st & (UART_LSR_FE | UART_LSR_OE | UART_LSR_PE)) {
+               gdbstub_proto("### GDB Rx Error (st=%02x) ###\n", st);
+               return -EIO;
+       } else {
+               gdbstub_proto("### GDB Rx %02x (st=%02x) ###\n", ch, st);
+               *_ch = ch & 0x7f;
+               return 0;
+       }
+}
+
+/*
+ * send a character to the debugger
+ */
+void gdbstub_io_tx_char(unsigned char ch)
+{
+       FLOWCTL_SET(DTR);
+       LSR_WAIT_FOR(THRE);
+       /* FLOWCTL_WAIT_FOR(CTS); */
+
+       if (ch == 0x0a) {
+               GDBPORT_SERIAL_TX = 0x0d;
+               LSR_WAIT_FOR(THRE);
+               /* FLOWCTL_WAIT_FOR(CTS); */
+       }
+       GDBPORT_SERIAL_TX = ch;
+
+       FLOWCTL_CLEAR(DTR);
+}
+
+/*
+ * send a character to the debugger
+ */
+void gdbstub_io_tx_flush(void)
+{
+       LSR_WAIT_FOR(TEMT);
+       LSR_WAIT_FOR(THRE);
+       FLOWCTL_CLEAR(DTR);
+}
diff --git a/arch/mn10300/kernel/gdb-io-ttysm-low.S b/arch/mn10300/kernel/gdb-io-ttysm-low.S
new file mode 100644 (file)
index 0000000..677c787
--- /dev/null
@@ -0,0 +1,93 @@
+###############################################################################
+#
+# MN10300 On-chip serial Rx interrupt handler for GDB stub I/O
+#
+# Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+# Written by David Howells (dhowells@redhat.com)
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public Licence
+# as published by the Free Software Foundation; either version
+# 2 of the Licence, or (at your option) any later version.
+#
+###############################################################################
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/smp.h>
+#include <asm/thread_info.h>
+#include <asm/cpu-regs.h>
+#include <asm/frame.inc>
+#include <asm/intctl-regs.h>
+#include <asm/unit/serial.h>
+#include "mn10300-serial.h"
+
+       .text
+
+###############################################################################
+#
+# GDB stub serial receive interrupt entry point
+# - intended to run at interrupt priority 0
+#
+###############################################################################
+       .globl  gdbstub_io_rx_handler
+       .type   gdbstub_io_rx_handler,@function
+gdbstub_io_rx_handler:
+       movm    [d2,d3,a2,a3],(sp)
+
+       mov     (gdbstub_rx_inp),a3
+gdbstub_io_rx_more:
+       mov     a3,a2
+       add     2,a3
+       and     PAGE_SIZE_asm-1,a3
+       mov     (gdbstub_rx_outp),d3
+       cmp     a3,d3
+       beq     gdbstub_io_rx_overflow
+
+       movbu   (SCgSTR),d3
+       btst    SC01STR_RBF,d3
+       beq     gdbstub_io_rx_done
+       movbu   (SCgRXB),d2
+       movbu   d3,(gdbstub_rx_buffer+1,a2)
+       movbu   d2,(gdbstub_rx_buffer,a2)
+       mov     a3,(gdbstub_rx_inp)
+       bra     gdbstub_io_rx_more
+
+gdbstub_io_rx_done:
+       mov     GxICR_DETECT,d2
+       movbu   d2,(GxICR(SCgRXIRQ))    # ACK the interrupt
+       movhu   (GxICR(SCgRXIRQ)),d2    # flush
+
+       movm    (sp),[d2,d3,a2,a3]
+       bset    0x01,(gdbstub_busy)
+       beq     gdbstub_io_rx_enter
+       rti
+
+gdbstub_io_rx_overflow:
+       bset    0x01,(gdbstub_rx_overflow)
+       bra     gdbstub_io_rx_done
+
+###############################################################################
+#
+# debugging interrupt - enter the GDB stub proper
+#
+###############################################################################
+gdbstub_io_rx_enter:
+       or      EPSW_IE|EPSW_IM_1,epsw
+       add     -4,sp
+       SAVE_ALL
+
+       mov     0xffffffff,d0
+       mov     d0,(REG_ORIG_D0,fp)
+       mov     0x280,d1
+
+       mov     fp,d0
+       call    gdbstub_rx_irq[],0      # gdbstub_io_rx_irq(regs,excep)
+
+       and     ~EPSW_IE,epsw
+       bclr    0x01,(gdbstub_busy)
+
+       .globl gdbstub_return
+gdbstub_return:
+       RESTORE_ALL
+
+       .size   gdbstub_io_rx_handler,.-gdbstub_io_rx_handler
diff --git a/arch/mn10300/kernel/gdb-io-ttysm.c b/arch/mn10300/kernel/gdb-io-ttysm.c
new file mode 100644 (file)
index 0000000..c545159
--- /dev/null
@@ -0,0 +1,299 @@
+/* MN10300 On-chip serial driver for gdbstub I/O
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/string.h>
+#include <linux/kernel.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/console.h>
+#include <linux/init.h>
+#include <linux/tty.h>
+#include <asm/pgtable.h>
+#include <asm/system.h>
+#include <asm/gdb-stub.h>
+#include <asm/exceptions.h>
+#include <asm/unit/clock.h>
+#include "mn10300-serial.h"
+
+#if defined(CONFIG_GDBSTUB_ON_TTYSM0)
+struct mn10300_serial_port *const gdbstub_port = &mn10300_serial_port_sif0;
+#elif defined(CONFIG_GDBSTUB_ON_TTYSM1)
+struct mn10300_serial_port *const gdbstub_port = &mn10300_serial_port_sif1;
+#else
+struct mn10300_serial_port *const gdbstub_port = &mn10300_serial_port_sif2;
+#endif
+
+
+/*
+ * initialise the GDB stub I/O routines
+ */
+void __init gdbstub_io_init(void)
+{
+       uint16_t scxctr;
+       int tmp;
+
+       switch (gdbstub_port->clock_src) {
+       case MNSCx_CLOCK_SRC_IOCLK:
+               gdbstub_port->ioclk = MN10300_IOCLK;
+               break;
+
+#ifdef MN10300_IOBCLK
+       case MNSCx_CLOCK_SRC_IOBCLK:
+               gdbstub_port->ioclk = MN10300_IOBCLK;
+               break;
+#endif
+       default:
+               BUG();
+       }
+
+       /* set up the serial port */
+       gdbstub_io_set_baud(115200);
+
+       /* we want to get serial receive interrupts */
+       set_intr_level(gdbstub_port->rx_irq, GxICR_LEVEL_0);
+       set_intr_level(gdbstub_port->tx_irq, GxICR_LEVEL_0);
+       set_intr_stub(EXCEP_IRQ_LEVEL0, gdbstub_io_rx_handler);
+
+       *gdbstub_port->rx_icr |= GxICR_ENABLE;
+       tmp = *gdbstub_port->rx_icr;
+
+       /* enable the device */
+       scxctr = SC01CTR_CLN_8BIT;      /* 1N8 */
+       switch (gdbstub_port->div_timer) {
+       case MNSCx_DIV_TIMER_16BIT:
+               scxctr |= SC0CTR_CK_TM8UFLOW_8; /* == SC1CTR_CK_TM9UFLOW_8
+                                                  == SC2CTR_CK_TM10UFLOW_8 */
+               break;
+
+       case MNSCx_DIV_TIMER_8BIT:
+               scxctr |= SC0CTR_CK_TM2UFLOW_8;
+               break;
+       }
+
+       scxctr |= SC01CTR_TXE | SC01CTR_RXE;
+
+       *gdbstub_port->_control = scxctr;
+       tmp = *gdbstub_port->_control;
+
+       /* permit level 0 IRQs only */
+       asm volatile(
+               "       and %0,epsw     \n"
+               "       or %1,epsw      \n"
+               :
+               : "i"(~EPSW_IM), "i"(EPSW_IE|EPSW_IM_1)
+               );
+}
+
+/*
+ * set up the GDB stub serial port baud rate timers
+ */
+void gdbstub_io_set_baud(unsigned baud)
+{
+       const unsigned bits = 10; /* 1 [start] + 8 [data] + 0 [parity] +
+                                  * 1 [stop] */
+       unsigned long ioclk = gdbstub_port->ioclk;
+       unsigned xdiv, tmp;
+       uint16_t tmxbr;
+       uint8_t tmxmd;
+
+       if (!baud) {
+               baud = 9600;
+       } else if (baud == 134) {
+               baud = 269;     /* 134 is really 134.5 */
+               xdiv = 2;
+       }
+
+try_alternative:
+       xdiv = 1;
+
+       switch (gdbstub_port->div_timer) {
+       case MNSCx_DIV_TIMER_16BIT:
+               tmxmd = TM8MD_SRC_IOCLK;
+               tmxbr = tmp = (ioclk / (baud * xdiv) + 4) / 8 - 1;
+               if (tmp > 0 && tmp <= 65535)
+                       goto timer_okay;
+
+               tmxmd = TM8MD_SRC_IOCLK_8;
+               tmxbr = tmp = (ioclk / (baud * 8 * xdiv) + 4) / 8 - 1;
+               if (tmp > 0 && tmp <= 65535)
+                       goto timer_okay;
+
+               tmxmd = TM8MD_SRC_IOCLK_32;
+               tmxbr = tmp = (ioclk / (baud * 32 * xdiv) + 4) / 8 - 1;
+               if (tmp > 0 && tmp <= 65535)
+                       goto timer_okay;
+
+               break;
+
+       case MNSCx_DIV_TIMER_8BIT:
+               tmxmd = TM2MD_SRC_IOCLK;
+               tmxbr = tmp = (ioclk / (baud * xdiv) + 4) / 8 - 1;
+               if (tmp > 0 && tmp <= 255)
+                       goto timer_okay;
+
+               tmxmd = TM2MD_SRC_IOCLK_8;
+               tmxbr = tmp = (ioclk / (baud * 8 * xdiv) + 4) / 8 - 1;
+               if (tmp > 0 && tmp <= 255)
+                       goto timer_okay;
+
+               tmxmd = TM2MD_SRC_IOCLK_32;
+               tmxbr = tmp = (ioclk / (baud * 32 * xdiv) + 4) / 8 - 1;
+               if (tmp > 0 && tmp <= 255)
+                       goto timer_okay;
+               break;
+       }
+
+       /* as a last resort, if the quotient is zero, default to 9600 bps */
+       baud = 9600;
+       goto try_alternative;
+
+timer_okay:
+       gdbstub_port->uart.timeout = (2 * bits * HZ) / baud;
+       gdbstub_port->uart.timeout += HZ / 50;
+
+       /* set the timer to produce the required baud rate */
+       switch (gdbstub_port->div_timer) {
+       case MNSCx_DIV_TIMER_16BIT:
+               *gdbstub_port->_tmxmd = 0;
+               *gdbstub_port->_tmxbr = tmxbr;
+               *gdbstub_port->_tmxmd = TM8MD_INIT_COUNTER;
+               *gdbstub_port->_tmxmd = tmxmd | TM8MD_COUNT_ENABLE;
+               break;
+
+       case MNSCx_DIV_TIMER_8BIT:
+               *gdbstub_port->_tmxmd = 0;
+               *(volatile u8 *) gdbstub_port->_tmxbr = (u8)tmxbr;
+               *gdbstub_port->_tmxmd = TM2MD_INIT_COUNTER;
+               *gdbstub_port->_tmxmd = tmxmd | TM2MD_COUNT_ENABLE;
+               break;
+       }
+}
+
+/*
+ * wait for a character to come from the debugger
+ */
+int gdbstub_io_rx_char(unsigned char *_ch, int nonblock)
+{
+       unsigned ix;
+       u8 ch, st;
+
+       *_ch = 0xff;
+
+       if (gdbstub_rx_unget) {
+               *_ch = gdbstub_rx_unget;
+               gdbstub_rx_unget = 0;
+               return 0;
+       }
+
+try_again:
+       /* pull chars out of the buffer */
+       ix = gdbstub_rx_outp;
+       if (ix == gdbstub_rx_inp) {
+               if (nonblock)
+                       return -EAGAIN;
+#ifdef CONFIG_MN10300_WD_TIMER
+               watchdog_alert_counter = 0;
+#endif /* CONFIG_MN10300_WD_TIMER */
+               goto try_again;
+       }
+
+       ch = gdbstub_rx_buffer[ix++];
+       st = gdbstub_rx_buffer[ix++];
+       gdbstub_rx_outp = ix & (PAGE_SIZE - 1);
+
+       st &= SC01STR_RXF | SC01STR_RBF | SC01STR_FEF | SC01STR_PEF |
+               SC01STR_OEF;
+
+       /* deal with what we've got
+        * - note that the UART doesn't do BREAK-detection for us
+        */
+       if (st & SC01STR_FEF && ch == 0) {
+               switch (gdbstub_port->rx_brk) {
+               case 0: gdbstub_port->rx_brk = 1;       goto try_again;
+               case 1: gdbstub_port->rx_brk = 2;       goto try_again;
+               case 2:
+                       gdbstub_port->rx_brk = 3;
+                       gdbstub_proto("### GDB MNSERIAL Rx Break Detected"
+                                     " ###\n");
+                       return -EINTR;
+               default:
+                       goto try_again;
+               }
+       } else if (st & SC01STR_FEF) {
+               if (gdbstub_port->rx_brk)
+                       goto try_again;
+
+               gdbstub_proto("### GDB MNSERIAL Framing Error ###\n");
+               return -EIO;
+       } else if (st & SC01STR_OEF) {
+               if (gdbstub_port->rx_brk)
+                       goto try_again;
+
+               gdbstub_proto("### GDB MNSERIAL Overrun Error ###\n");
+               return -EIO;
+       } else if (st & SC01STR_PEF) {
+               if (gdbstub_port->rx_brk)
+                       goto try_again;
+
+               gdbstub_proto("### GDB MNSERIAL Parity Error ###\n");
+               return -EIO;
+       } else {
+               /* look for the tail-end char on a break run */
+               if (gdbstub_port->rx_brk == 3) {
+                       switch (ch) {
+                       case 0xFF:
+                       case 0xFE:
+                       case 0xFC:
+                       case 0xF8:
+                       case 0xF0:
+                       case 0xE0:
+                       case 0xC0:
+                       case 0x80:
+                       case 0x00:
+                               gdbstub_port->rx_brk = 0;
+                               goto try_again;
+                       default:
+                               break;
+                       }
+               }
+
+               gdbstub_port->rx_brk = 0;
+               gdbstub_io("### GDB Rx %02x (st=%02x) ###\n", ch, st);
+               *_ch = ch & 0x7f;
+               return 0;
+       }
+}
+
+/*
+ * send a character to the debugger
+ */
+void gdbstub_io_tx_char(unsigned char ch)
+{
+       while (*gdbstub_port->_status & SC01STR_TBF)
+               continue;
+
+       if (ch == 0x0a) {
+               *(u8 *) gdbstub_port->_txb = 0x0d;
+               while (*gdbstub_port->_status & SC01STR_TBF)
+                       continue;
+       }
+
+       *(u8 *) gdbstub_port->_txb = ch;
+}
+
+/*
+ * flush the transmission buffers
+ */
+void gdbstub_io_tx_flush(void)
+{
+       while (*gdbstub_port->_status & (SC01STR_TBF | SC01STR_TXF))
+               continue;
+}
diff --git a/arch/mn10300/kernel/gdb-low.S b/arch/mn10300/kernel/gdb-low.S
new file mode 100644 (file)
index 0000000..e272555
--- /dev/null
@@ -0,0 +1,115 @@
+###############################################################################
+#
+# MN10300 Low-level gdbstub routines
+#
+# Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+# Written by David Howells (dhowells@redhat.com)
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public Licence
+# as published by the Free Software Foundation; either version
+# 2 of the Licence, or (at your option) any later version.
+#
+###############################################################################
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/smp.h>
+#include <asm/cache.h>
+#include <asm/cpu-regs.h>
+#include <asm/exceptions.h>
+#include <asm/frame.inc>
+#include <asm/serial-regs.h>
+
+       .text
+
+###############################################################################
+#
+# GDB stub read memory with guard
+# - D0 holds the memory address to read
+# - D1 holds the address to store the byte into
+#
+###############################################################################
+       .globl gdbstub_read_byte_guard
+       .globl gdbstub_read_byte_cont
+ENTRY(gdbstub_read_byte)
+       mov     d0,a0
+       mov     d1,a1
+       clr     d0
+gdbstub_read_byte_guard:
+       movbu   (a0),d1
+gdbstub_read_byte_cont:
+       movbu   d1,(a1)
+       ret     [],0
+
+       .globl gdbstub_read_word_guard
+       .globl gdbstub_read_word_cont
+ENTRY(gdbstub_read_word)
+       mov     d0,a0
+       mov     d1,a1
+       clr     d0
+gdbstub_read_word_guard:
+       movhu   (a0),d1
+gdbstub_read_word_cont:
+       movhu   d1,(a1)
+       ret     [],0
+
+       .globl gdbstub_read_dword_guard
+       .globl gdbstub_read_dword_cont
+ENTRY(gdbstub_read_dword)
+       mov     d0,a0
+       mov     d1,a1
+       clr     d0
+gdbstub_read_dword_guard:
+       mov     (a0),d1
+gdbstub_read_dword_cont:
+       mov     d1,(a1)
+       ret     [],0
+
+###############################################################################
+#
+# GDB stub write memory with guard
+# - D0 holds the byte to store
+# - D1 holds the memory address to write
+#
+###############################################################################
+       .globl gdbstub_write_byte_guard
+       .globl gdbstub_write_byte_cont
+ENTRY(gdbstub_write_byte)
+       mov     d0,a0
+       mov     d1,a1
+       clr     d0
+gdbstub_write_byte_guard:
+       movbu   a0,(a1)
+gdbstub_write_byte_cont:
+       ret     [],0
+
+       .globl gdbstub_write_word_guard
+       .globl gdbstub_write_word_cont
+ENTRY(gdbstub_write_word)
+       mov     d0,a0
+       mov     d1,a1
+       clr     d0
+gdbstub_write_word_guard:
+       movhu   a0,(a1)
+gdbstub_write_word_cont:
+       ret     [],0
+
+       .globl gdbstub_write_dword_guard
+       .globl gdbstub_write_dword_cont
+ENTRY(gdbstub_write_dword)
+       mov     d0,a0
+       mov     d1,a1
+       clr     d0
+gdbstub_write_dword_guard:
+       mov     a0,(a1)
+gdbstub_write_dword_cont:
+       ret     [],0
+
+###############################################################################
+#
+# GDB stub BUG() trap
+#
+###############################################################################
+ENTRY(__gdbstub_bug_trap)
+       .byte   0xF7,0xF7       # don't use 0xFF as the JTAG unit preempts that
+       ret     [],0
diff --git a/arch/mn10300/kernel/gdb-stub.c b/arch/mn10300/kernel/gdb-stub.c
new file mode 100644 (file)
index 0000000..21891c7
--- /dev/null
@@ -0,0 +1,1947 @@
+/* MN10300 GDB stub
+ *
+ * Originally written by Glenn Engel, Lake Stevens Instrument Division
+ *
+ * Contributed by HP Systems
+ *
+ * Modified for SPARC by Stu Grossman, Cygnus Support.
+ *
+ * Modified for Linux/MIPS (and MIPS in general) by Andreas Busse
+ * Send complaints, suggestions etc. to <andy@waldorf-gmbh.de>
+ *
+ * Copyright (C) 1995 Andreas Busse
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Modified for Linux/mn10300 by David Howells <dhowells@redhat.com>
+ */
+
+/*
+ *  To enable debugger support, two things need to happen.  One, a
+ *  call to set_debug_traps() is necessary in order to allow any breakpoints
+ *  or error conditions to be properly intercepted and reported to gdb.
+ *  Two, a breakpoint needs to be generated to begin communication.  This
+ *  is most easily accomplished by a call to breakpoint().  Breakpoint()
+ *  simulates a breakpoint by executing a BREAK instruction.
+ *
+ *
+ *    The following gdb commands are supported:
+ *
+ * command          function                               Return value
+ *
+ *    g             return the value of the CPU registers  hex data or ENN
+ *    G             set the value of the CPU registers     OK or ENN
+ *
+ *    mAA..AA,LLLL  Read LLLL bytes at address AA..AA      hex data or ENN
+ *    MAA..AA,LLLL: Write LLLL bytes at address AA.AA      OK or ENN
+ *
+ *    c             Resume at current address              SNN   ( signal NN)
+ *    cAA..AA       Continue at address AA..AA             SNN
+ *
+ *    s             Step one instruction                   SNN
+ *    sAA..AA       Step one instruction from AA..AA       SNN
+ *
+ *    k             kill
+ *
+ *    ?             What was the last sigval ?             SNN   (signal NN)
+ *
+ *    bBB..BB      Set baud rate to BB..BB                OK or BNN, then sets
+ *                                                        baud rate
+ *
+ * All commands and responses are sent with a packet which includes a
+ * checksum.  A packet consists of
+ *
+ * $<packet info>#<checksum>.
+ *
+ * where
+ * <packet info> :: <characters representing the command or response>
+ * <checksum>    :: < two hex digits computed as modulo 256 sum of <packetinfo>>
+ *
+ * When a packet is received, it is first acknowledged with either '+' or '-'.
+ * '+' indicates a successful transfer.  '-' indicates a failed transfer.
+ *
+ * Example:
+ *
+ * Host:                  Reply:
+ * $m0,10#2a               +$00010203040506070809101112131415#42
+ *
+ *
+ *  ==============
+ *  MORE EXAMPLES:
+ *  ==============
+ *
+ *  For reference -- the following are the steps that one
+ *  company took (RidgeRun Inc) to get remote gdb debugging
+ *  going. In this scenario the host machine was a PC and the
+ *  target platform was a Galileo EVB64120A MIPS evaluation
+ *  board.
+ *
+ *  Step 1:
+ *  First download gdb-5.0.tar.gz from the internet.
+ *  and then build/install the package.
+ *
+ *  Example:
+ *    $ tar zxf gdb-5.0.tar.gz
+ *    $ cd gdb-5.0
+ *    $ ./configure --target=am33_2.0-linux-gnu
+ *    $ make
+ *    $ install
+ *    am33_2.0-linux-gnu-gdb
+ *
+ *  Step 2:
+ *  Configure linux for remote debugging and build it.
+ *
+ *  Example:
+ *    $ cd ~/linux
+ *    $ make menuconfig <go to "Kernel Hacking" and turn on remote debugging>
+ *    $ make dep; make vmlinux
+ *
+ *  Step 3:
+ *  Download the kernel to the remote target and start
+ *  the kernel running. It will promptly halt and wait
+ *  for the host gdb session to connect. It does this
+ *  since the "Kernel Hacking" option has defined
+ *  CONFIG_REMOTE_DEBUG which in turn enables your calls
+ *  to:
+ *     set_debug_traps();
+ *     breakpoint();
+ *
+ *  Step 4:
+ *  Start the gdb session on the host.
+ *
+ *  Example:
+ *    $ am33_2.0-linux-gnu-gdb vmlinux
+ *    (gdb) set remotebaud 115200
+ *    (gdb) target remote /dev/ttyS1
+ *    ...at this point you are connected to
+ *       the remote target and can use gdb
+ *       in the normal fasion. Setting
+ *       breakpoints, single stepping,
+ *       printing variables, etc.
+ *
+ */
+
+#include <linux/string.h>
+#include <linux/kernel.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/console.h>
+#include <linux/init.h>
+#include <linux/bug.h>
+
+#include <asm/pgtable.h>
+#include <asm/system.h>
+#include <asm/gdb-stub.h>
+#include <asm/exceptions.h>
+#include <asm/cacheflush.h>
+#include <asm/serial-regs.h>
+#include <asm/busctl-regs.h>
+#include <asm/unit/leds.h>
+#include <asm/unit/serial.h>
+
+/* define to use F7F7 rather than FF which is subverted by JTAG debugger */
+#undef GDBSTUB_USE_F7F7_AS_BREAKPOINT
+
+/*
+ * BUFMAX defines the maximum number of characters in inbound/outbound buffers
+ * at least NUMREGBYTES*2 are needed for register packets
+ */
+#define BUFMAX 2048
+
+static const char gdbstub_banner[] =
+       "Linux/MN10300 GDB Stub (c) RedHat 2007\n";
+
+u8     gdbstub_rx_buffer[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
+u32    gdbstub_rx_inp;
+u32    gdbstub_rx_outp;
+u8     gdbstub_busy;
+u8     gdbstub_rx_overflow;
+u8     gdbstub_rx_unget;
+
+static u8      gdbstub_flush_caches;
+static char    input_buffer[BUFMAX];
+static char    output_buffer[BUFMAX];
+static char    trans_buffer[BUFMAX];
+
+static const char hexchars[] = "0123456789abcdef";
+
+struct gdbstub_bkpt {
+       u8      *addr;          /* address of breakpoint */
+       u8      len;            /* size of breakpoint */
+       u8      origbytes[7];   /* original bytes */
+};
+
+static struct gdbstub_bkpt gdbstub_bkpts[256];
+
+/*
+ * local prototypes
+ */
+static void getpacket(char *buffer);
+static int putpacket(char *buffer);
+static int computeSignal(enum exception_code excep);
+static int hex(unsigned char ch);
+static int hexToInt(char **ptr, int *intValue);
+static unsigned char *mem2hex(const void *mem, char *buf, int count,
+                             int may_fault);
+static const char *hex2mem(const char *buf, void *_mem, int count,
+                          int may_fault);
+
+/*
+ * Convert ch from a hex digit to an int
+ */
+static int hex(unsigned char ch)
+{
+       if (ch >= 'a' && ch <= 'f')
+               return ch - 'a' + 10;
+       if (ch >= '0' && ch <= '9')
+               return ch - '0';
+       if (ch >= 'A' && ch <= 'F')
+               return ch - 'A' + 10;
+       return -1;
+}
+
+#ifdef CONFIG_GDBSTUB_DEBUGGING
+
+void debug_to_serial(const char *p, int n)
+{
+       __debug_to_serial(p, n);
+       /* gdbstub_console_write(NULL, p, n); */
+}
+
+void gdbstub_printk(const char *fmt, ...)
+{
+       va_list args;
+       int len;
+
+       /* Emit the output into the temporary buffer */
+       va_start(args, fmt);
+       len = vsnprintf(trans_buffer, sizeof(trans_buffer), fmt, args);
+       va_end(args);
+       debug_to_serial(trans_buffer, len);
+}
+
+#endif
+
+static inline char *gdbstub_strcpy(char *dst, const char *src)
+{
+       int loop = 0;
+       while ((dst[loop] = src[loop]))
+              loop++;
+       return dst;
+}
+
+/*
+ * scan for the sequence $<data>#<checksum>
+ */
+static void getpacket(char *buffer)
+{
+       unsigned char checksum;
+       unsigned char xmitcsum;
+       unsigned char ch;
+       int count, i, ret, error;
+
+       for (;;) {
+               /*
+                * wait around for the start character,
+                * ignore all other characters
+                */
+               do {
+                       gdbstub_io_rx_char(&ch, 0);
+               } while (ch != '$');
+
+               checksum = 0;
+               xmitcsum = -1;
+               count = 0;
+               error = 0;
+
+               /*
+                * now, read until a # or end of buffer is found
+                */
+               while (count < BUFMAX) {
+                       ret = gdbstub_io_rx_char(&ch, 0);
+                       if (ret < 0)
+                               error = ret;
+
+                       if (ch == '#')
+                               break;
+                       checksum += ch;
+                       buffer[count] = ch;
+                       count++;
+               }
+
+               if (error == -EIO) {
+                       gdbstub_proto("### GDB Rx Error - Skipping packet"
+                                     " ###\n");
+                       gdbstub_proto("### GDB Tx NAK\n");
+                       gdbstub_io_tx_char('-');
+                       continue;
+               }
+
+               if (count >= BUFMAX || error)
+                       continue;
+
+               buffer[count] = 0;
+
+               /* read the checksum */
+               ret = gdbstub_io_rx_char(&ch, 0);
+               if (ret < 0)
+                       error = ret;
+               xmitcsum = hex(ch) << 4;
+
+               ret = gdbstub_io_rx_char(&ch, 0);
+               if (ret < 0)
+                       error = ret;
+               xmitcsum |= hex(ch);
+
+               if (error) {
+                       if (error == -EIO)
+                               gdbstub_io("### GDB Rx Error -"
+                                          " Skipping packet\n");
+                       gdbstub_io("### GDB Tx NAK\n");
+                       gdbstub_io_tx_char('-');
+                       continue;
+               }
+
+               /* check the checksum */
+               if (checksum != xmitcsum) {
+                       gdbstub_io("### GDB Tx NAK\n");
+                       gdbstub_io_tx_char('-');        /* failed checksum */
+                       continue;
+               }
+
+               gdbstub_proto("### GDB Rx '$%s#%02x' ###\n", buffer, checksum);
+               gdbstub_io("### GDB Tx ACK\n");
+               gdbstub_io_tx_char('+'); /* successful transfer */
+
+               /*
+                * if a sequence char is present,
+                * reply the sequence ID
+                */
+               if (buffer[2] == ':') {
+                       gdbstub_io_tx_char(buffer[0]);
+                       gdbstub_io_tx_char(buffer[1]);
+
+                       /*
+                        * remove sequence chars from buffer
+                        */
+                       count = 0;
+                       while (buffer[count])
+                               count++;
+                       for (i = 3; i <= count; i++)
+                               buffer[i - 3] = buffer[i];
+               }
+
+               break;
+       }
+}
+
+/*
+ * send the packet in buffer.
+ * - return 0 if successfully ACK'd
+ * - return 1 if abandoned due to new incoming packet
+ */
+static int putpacket(char *buffer)
+{
+       unsigned char checksum;
+       unsigned char ch;
+       int count;
+
+       /*
+        * $<packet info>#<checksum>.
+        */
+       gdbstub_proto("### GDB Tx $'%s'#?? ###\n", buffer);
+
+       do {
+               gdbstub_io_tx_char('$');
+               checksum = 0;
+               count = 0;
+
+               while ((ch = buffer[count]) != 0) {
+                       gdbstub_io_tx_char(ch);
+                       checksum += ch;
+                       count += 1;
+               }
+
+               gdbstub_io_tx_char('#');
+               gdbstub_io_tx_char(hexchars[checksum >> 4]);
+               gdbstub_io_tx_char(hexchars[checksum & 0xf]);
+
+       } while (gdbstub_io_rx_char(&ch, 0),
+                ch == '-' && (gdbstub_io("### GDB Rx NAK\n"), 0),
+                ch != '-' && ch != '+' &&
+                (gdbstub_io("### GDB Rx ??? %02x\n", ch), 0),
+                ch != '+' && ch != '$');
+
+       if (ch == '+') {
+               gdbstub_io("### GDB Rx ACK\n");
+               return 0;
+       }
+
+       gdbstub_io("### GDB Tx Abandoned\n");
+       gdbstub_rx_unget = ch;
+       return 1;
+}
+
+/*
+ * While we find nice hex chars, build an int.
+ * Return number of chars processed.
+ */
+static int hexToInt(char **ptr, int *intValue)
+{
+       int numChars = 0;
+       int hexValue;
+
+       *intValue = 0;
+
+       while (**ptr) {
+               hexValue = hex(**ptr);
+               if (hexValue < 0)
+                       break;
+
+               *intValue = (*intValue << 4) | hexValue;
+               numChars++;
+
+               (*ptr)++;
+       }
+
+       return (numChars);
+}
+
+/*
+ * We single-step by setting breakpoints. When an exception
+ * is handled, we need to restore the instructions hoisted
+ * when the breakpoints were set.
+ *
+ * This is where we save the original instructions.
+ */
+static struct gdb_bp_save {
+       u8      *addr;
+       u8      opcode[2];
+} step_bp[2];
+
+static const unsigned char gdbstub_insn_sizes[256] =
+{
+       /* 1  2  3  4  5  6  7  8  9  a  b  c  d  e  f */
+       1, 3, 3, 3, 1, 3, 3, 3, 1, 3, 3, 3, 1, 3, 3, 3, /* 0 */
+       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 1 */
+       2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, /* 2 */
+       3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, /* 3 */
+       1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, /* 4 */
+       1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, /* 5 */
+       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6 */
+       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 7 */
+       2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, /* 8 */
+       2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, /* 9 */
+       2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, /* a */
+       2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, /* b */
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 2, /* c */
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* d */
+       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* e */
+       0, 2, 2, 2, 2, 2, 2, 4, 0, 3, 0, 4, 0, 6, 7, 1  /* f */
+};
+
+static int __gdbstub_mark_bp(u8 *addr, int ix)
+{
+       if (addr < (u8 *) 0x70000000UL)
+               return 0;
+       /* 70000000-7fffffff: vmalloc area */
+       if (addr < (u8 *) 0x80000000UL)
+               goto okay;
+       if (addr < (u8 *) 0x8c000000UL)
+               return 0;
+       /* 8c000000-93ffffff: SRAM, SDRAM */
+       if (addr < (u8 *) 0x94000000UL)
+               goto okay;
+       return 0;
+
+okay:
+       if (gdbstub_read_byte(addr + 0, &step_bp[ix].opcode[0]) < 0 ||
+           gdbstub_read_byte(addr + 1, &step_bp[ix].opcode[1]) < 0)
+               return 0;
+
+       step_bp[ix].addr = addr;
+       return 1;
+}
+
+static inline void __gdbstub_restore_bp(void)
+{
+#ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
+       if (step_bp[0].addr) {
+               gdbstub_write_byte(step_bp[0].opcode[0], step_bp[0].addr + 0);
+               gdbstub_write_byte(step_bp[0].opcode[1], step_bp[0].addr + 1);
+       }
+       if (step_bp[1].addr) {
+               gdbstub_write_byte(step_bp[1].opcode[0], step_bp[1].addr + 0);
+               gdbstub_write_byte(step_bp[1].opcode[1], step_bp[1].addr + 1);
+       }
+#else
+       if (step_bp[0].addr)
+               gdbstub_write_byte(step_bp[0].opcode[0], step_bp[0].addr + 0);
+       if (step_bp[1].addr)
+               gdbstub_write_byte(step_bp[1].opcode[0], step_bp[1].addr + 0);
+#endif
+
+       gdbstub_flush_caches = 1;
+
+       step_bp[0].addr         = NULL;
+       step_bp[0].opcode[0]    = 0;
+       step_bp[0].opcode[1]    = 0;
+       step_bp[1].addr         = NULL;
+       step_bp[1].opcode[0]    = 0;
+       step_bp[1].opcode[1]    = 0;
+}
+
+/*
+ * emulate single stepping by means of breakpoint instructions
+ */
+static int gdbstub_single_step(struct pt_regs *regs)
+{
+       unsigned size;
+       uint32_t x;
+       uint8_t cur, *pc, *sp;
+
+       step_bp[0].addr         = NULL;
+       step_bp[0].opcode[0]    = 0;
+       step_bp[0].opcode[1]    = 0;
+       step_bp[1].addr         = NULL;
+       step_bp[1].opcode[0]    = 0;
+       step_bp[1].opcode[1]    = 0;
+       x = 0;
+
+       pc = (u8 *) regs->pc;
+       sp = (u8 *) (regs + 1);
+       if (gdbstub_read_byte(pc, &cur) < 0)
+               return -EFAULT;
+
+       gdbstub_bkpt("Single Step from %p { %02x }\n", pc, cur);
+
+       gdbstub_flush_caches = 1;
+
+       size = gdbstub_insn_sizes[cur];
+       if (size > 0) {
+               if (!__gdbstub_mark_bp(pc + size, 0))
+                       goto fault;
+       } else {
+               switch (cur) {
+                       /* Bxx (d8,PC) */
+               case 0xc0:
+               case 0xc1:
+               case 0xc2:
+               case 0xc3:
+               case 0xc4:
+               case 0xc5:
+               case 0xc6:
+               case 0xc7:
+               case 0xc8:
+               case 0xc9:
+               case 0xca:
+                       if (gdbstub_read_byte(pc + 1, (u8 *) &x) < 0)
+                               goto fault;
+                       if (!__gdbstub_mark_bp(pc + 2, 0))
+                               goto fault;
+                       if ((x < 0 || x > 2) &&
+                           !__gdbstub_mark_bp(pc + (s8) x, 1))
+                               goto fault;
+                       break;
+
+                       /* LXX (d8,PC) */
+               case 0xd0:
+               case 0xd1:
+               case 0xd2:
+               case 0xd3:
+               case 0xd4:
+               case 0xd5:
+               case 0xd6:
+               case 0xd7:
+               case 0xd8:
+               case 0xd9:
+               case 0xda:
+                       if (!__gdbstub_mark_bp(pc + 1, 0))
+                               goto fault;
+                       if (regs->pc != regs->lar &&
+                           !__gdbstub_mark_bp((u8 *) regs->lar, 1))
+                               goto fault;
+                       break;
+
+                       /* SETLB - loads the next for bytes into the LIR
+                        * register */
+               case 0xdb:
+                       if (!__gdbstub_mark_bp(pc + 1, 0))
+                               goto fault;
+                       break;
+
+                       /* JMP (d16,PC) or CALL (d16,PC) */
+               case 0xcc:
+               case 0xcd:
+                       if (gdbstub_read_byte(pc + 1, ((u8 *) &x) + 0) < 0 ||
+                           gdbstub_read_byte(pc + 2, ((u8 *) &x) + 1) < 0)
+                               goto fault;
+                       if (!__gdbstub_mark_bp(pc + (s16) x, 0))
+                               goto fault;
+                       break;
+
+                       /* JMP (d32,PC) or CALL (d32,PC) */
+               case 0xdc:
+               case 0xdd:
+                       if (gdbstub_read_byte(pc + 1, ((u8 *) &x) + 0) < 0 ||
+                           gdbstub_read_byte(pc + 2, ((u8 *) &x) + 1) < 0 ||
+                           gdbstub_read_byte(pc + 3, ((u8 *) &x) + 2) < 0 ||
+                           gdbstub_read_byte(pc + 4, ((u8 *) &x) + 3) < 0)
+                               goto fault;
+                       if (!__gdbstub_mark_bp(pc + (s32) x, 0))
+                               goto fault;
+                       break;
+
+                       /* RETF */
+               case 0xde:
+                       if (!__gdbstub_mark_bp((u8 *) regs->mdr, 0))
+                               goto fault;
+                       break;
+
+                       /* RET */
+               case 0xdf:
+                       if (gdbstub_read_byte(pc + 2, (u8 *) &x) < 0)
+                               goto fault;
+                       sp += (s8)x;
+                       if (gdbstub_read_byte(sp + 0, ((u8 *) &x) + 0) < 0 ||
+                           gdbstub_read_byte(sp + 1, ((u8 *) &x) + 1) < 0 ||
+                           gdbstub_read_byte(sp + 2, ((u8 *) &x) + 2) < 0 ||
+                           gdbstub_read_byte(sp + 3, ((u8 *) &x) + 3) < 0)
+                               goto fault;
+                       if (!__gdbstub_mark_bp((u8 *) x, 0))
+                               goto fault;
+                       break;
+
+               case 0xf0:
+                       if (gdbstub_read_byte(pc + 1, &cur) < 0)
+                               goto fault;
+
+                       if (cur >= 0xf0 && cur <= 0xf7) {
+                               /* JMP (An) / CALLS (An) */
+                               switch (cur & 3) {
+                               case 0: x = regs->a0; break;
+                               case 1: x = regs->a1; break;
+                               case 2: x = regs->a2; break;
+                               case 3: x = regs->a3; break;
+                               }
+                               if (!__gdbstub_mark_bp((u8 *) x, 0))
+                                       goto fault;
+                       } else if (cur == 0xfc) {
+                               /* RETS */
+                               if (gdbstub_read_byte(
+                                           sp + 0, ((u8 *) &x) + 0) < 0 ||
+                                   gdbstub_read_byte(
+                                           sp + 1, ((u8 *) &x) + 1) < 0 ||
+                                   gdbstub_read_byte(
+                                           sp + 2, ((u8 *) &x) + 2) < 0 ||
+                                   gdbstub_read_byte(
+                                           sp + 3, ((u8 *) &x) + 3) < 0)
+                                       goto fault;
+                               if (!__gdbstub_mark_bp((u8 *) x, 0))
+                                       goto fault;
+                       } else if (cur == 0xfd) {
+                               /* RTI */
+                               if (gdbstub_read_byte(
+                                           sp + 4, ((u8 *) &x) + 0) < 0 ||
+                                   gdbstub_read_byte(
+                                           sp + 5, ((u8 *) &x) + 1) < 0 ||
+                                   gdbstub_read_byte(
+                                           sp + 6, ((u8 *) &x) + 2) < 0 ||
+                                   gdbstub_read_byte(
+                                           sp + 7, ((u8 *) &x) + 3) < 0)
+                                       goto fault;
+                               if (!__gdbstub_mark_bp((u8 *) x, 0))
+                                       goto fault;
+                       } else {
+                               if (!__gdbstub_mark_bp(pc + 2, 0))
+                                       goto fault;
+                       }
+
+                       break;
+
+                       /* potential 3-byte conditional branches */
+               case 0xf8:
+                       if (gdbstub_read_byte(pc + 1, &cur) < 0)
+                               goto fault;
+                       if (!__gdbstub_mark_bp(pc + 3, 0))
+                               goto fault;
+
+                       if (cur >= 0xe8 && cur <= 0xeb) {
+                               if (gdbstub_read_byte(
+                                           pc + 2, ((u8 *) &x) + 0) < 0)
+                                       goto fault;
+                               if ((x < 0 || x > 3) &&
+                                   !__gdbstub_mark_bp(pc + (s8) x, 1))
+                                       goto fault;
+                       }
+                       break;
+
+               case 0xfa:
+                       if (gdbstub_read_byte(pc + 1, &cur) < 0)
+                               goto fault;
+
+                       if (cur == 0xff) {
+                               /* CALLS (d16,PC) */
+                               if (gdbstub_read_byte(
+                                           pc + 2, ((u8 *) &x) + 0) < 0 ||
+                                   gdbstub_read_byte(
+                                           pc + 3, ((u8 *) &x) + 1) < 0)
+                                       goto fault;
+                               if (!__gdbstub_mark_bp(pc + (s16) x, 0))
+                                       goto fault;
+                       } else {
+                               if (!__gdbstub_mark_bp(pc + 4, 0))
+                                       goto fault;
+                       }
+                       break;
+
+               case 0xfc:
+                       if (gdbstub_read_byte(pc + 1, &cur) < 0)
+                               goto fault;
+                       if (cur == 0xff) {
+                               /* CALLS (d32,PC) */
+                               if (gdbstub_read_byte(
+                                           pc + 2, ((u8 *) &x) + 0) < 0 ||
+                                   gdbstub_read_byte(
+                                           pc + 3, ((u8 *) &x) + 1) < 0 ||
+                                   gdbstub_read_byte(
+                                           pc + 4, ((u8 *) &x) + 2) < 0 ||
+                                   gdbstub_read_byte(
+                                           pc + 5, ((u8 *) &x) + 3) < 0)
+                                       goto fault;
+                               if (!__gdbstub_mark_bp(
+                                           pc + (s32) x, 0))
+                                       goto fault;
+                       } else {
+                               if (!__gdbstub_mark_bp(
+                                           pc + 6, 0))
+                                       goto fault;
+                       }
+                       break;
+
+               }
+       }
+
+       gdbstub_bkpt("Step: %02x at %p; %02x at %p\n",
+                    step_bp[0].opcode[0], step_bp[0].addr,
+                    step_bp[1].opcode[0], step_bp[1].addr);
+
+       if (step_bp[0].addr) {
+#ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
+               if (gdbstub_write_byte(0xF7, step_bp[0].addr + 0) < 0 ||
+                   gdbstub_write_byte(0xF7, step_bp[0].addr + 1) < 0)
+                       goto fault;
+#else
+               if (gdbstub_write_byte(0xFF, step_bp[0].addr + 0) < 0)
+                       goto fault;
+#endif
+       }
+
+       if (step_bp[1].addr) {
+#ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
+               if (gdbstub_write_byte(0xF7, step_bp[1].addr + 0) < 0 ||
+                   gdbstub_write_byte(0xF7, step_bp[1].addr + 1) < 0)
+                       goto fault;
+#else
+               if (gdbstub_write_byte(0xFF, step_bp[1].addr + 0) < 0)
+                       goto fault;
+#endif
+       }
+
+       return 0;
+
+ fault:
+       /* uh-oh - silly address alert, try and restore things */
+       __gdbstub_restore_bp();
+       return -EFAULT;
+}
+
+#ifdef CONFIG_GDBSTUB_CONSOLE
+
+void gdbstub_console_write(struct console *con, const char *p, unsigned n)
+{
+       static const char gdbstub_cr[] = { 0x0d };
+       char outbuf[26];
+       int qty;
+       u8 busy;
+
+       busy = gdbstub_busy;
+       gdbstub_busy = 1;
+
+       outbuf[0] = 'O';
+
+       while (n > 0) {
+               qty = 1;
+
+               while (n > 0 && qty < 20) {
+                       mem2hex(p, outbuf + qty, 2, 0);
+                       qty += 2;
+                       if (*p == 0x0a) {
+                               mem2hex(gdbstub_cr, outbuf + qty, 2, 0);
+                               qty += 2;
+                       }
+                       p++;
+                       n--;
+               }
+
+               outbuf[qty] = 0;
+               putpacket(outbuf);
+       }
+
+       gdbstub_busy = busy;
+}
+
+static kdev_t gdbstub_console_dev(struct console *con)
+{
+       return MKDEV(1, 3); /* /dev/null */
+}
+
+static struct console gdbstub_console = {
+       .name   = "gdb",
+       .write  = gdbstub_console_write,
+       .device = gdbstub_console_dev,
+       .flags  = CON_PRINTBUFFER,
+       .index  = -1,
+};
+
+#endif
+
+/*
+ * Convert the memory pointed to by mem into hex, placing result in buf.
+ * - if successful, return a pointer to the last char put in buf (NUL)
+ * - in case of mem fault, return NULL
+ * may_fault is non-zero if we are reading from arbitrary memory, but is
+ * currently not used.
+ */
+static
+unsigned char *mem2hex(const void *_mem, char *buf, int count, int may_fault)
+{
+       const u8 *mem = _mem;
+       u8 ch[4];
+
+       if ((u32) mem & 1 && count >= 1) {
+               if (gdbstub_read_byte(mem, ch) != 0)
+                       return 0;
+               *buf++ = hexchars[ch[0] >> 4];
+               *buf++ = hexchars[ch[0] & 0xf];
+               mem++;
+               count--;
+       }
+
+       if ((u32) mem & 3 && count >= 2) {
+               if (gdbstub_read_word(mem, ch) != 0)
+                       return 0;
+               *buf++ = hexchars[ch[0] >> 4];
+               *buf++ = hexchars[ch[0] & 0xf];
+               *buf++ = hexchars[ch[1] >> 4];
+               *buf++ = hexchars[ch[1] & 0xf];
+               mem += 2;
+               count -= 2;
+       }
+
+       while (count >= 4) {
+               if (gdbstub_read_dword(mem, ch) != 0)
+                       return 0;
+               *buf++ = hexchars[ch[0] >> 4];
+               *buf++ = hexchars[ch[0] & 0xf];
+               *buf++ = hexchars[ch[1] >> 4];
+               *buf++ = hexchars[ch[1] & 0xf];
+               *buf++ = hexchars[ch[2] >> 4];
+               *buf++ = hexchars[ch[2] & 0xf];
+               *buf++ = hexchars[ch[3] >> 4];
+               *buf++ = hexchars[ch[3] & 0xf];
+               mem += 4;
+               count -= 4;
+       }
+
+       if (count >= 2) {
+               if (gdbstub_read_word(mem, ch) != 0)
+                       return 0;
+               *buf++ = hexchars[ch[0] >> 4];
+               *buf++ = hexchars[ch[0] & 0xf];
+               *buf++ = hexchars[ch[1] >> 4];
+               *buf++ = hexchars[ch[1] & 0xf];
+               mem += 2;
+               count -= 2;
+       }
+
+       if (count >= 1) {
+               if (gdbstub_read_byte(mem, ch) != 0)
+                       return 0;
+               *buf++ = hexchars[ch[0] >> 4];
+               *buf++ = hexchars[ch[0] & 0xf];
+       }
+
+       *buf = 0;
+       return buf;
+}
+
+/*
+ * convert the hex array pointed to by buf into binary to be placed in mem
+ * return a pointer to the character AFTER the last byte written
+ * may_fault is non-zero if we are reading from arbitrary memory, but is
+ * currently not used.
+ */
+static
+const char *hex2mem(const char *buf, void *_mem, int count, int may_fault)
+{
+       u8 *mem = _mem;
+       union {
+               u32 val;
+               u8 b[4];
+       } ch;
+
+       if ((u32) mem & 1 && count >= 1) {
+               ch.b[0]  = hex(*buf++) << 4;
+               ch.b[0] |= hex(*buf++);
+               if (gdbstub_write_byte(ch.val, mem) != 0)
+                       return 0;
+               mem++;
+               count--;
+       }
+
+       if ((u32) mem & 3 && count >= 2) {
+               ch.b[0]  = hex(*buf++) << 4;
+               ch.b[0] |= hex(*buf++);
+               ch.b[1]  = hex(*buf++) << 4;
+               ch.b[1] |= hex(*buf++);
+               if (gdbstub_write_word(ch.val, mem) != 0)
+                       return 0;
+               mem += 2;
+               count -= 2;
+       }
+
+       while (count >= 4) {
+               ch.b[0]  = hex(*buf++) << 4;
+               ch.b[0] |= hex(*buf++);
+               ch.b[1]  = hex(*buf++) << 4;
+               ch.b[1] |= hex(*buf++);
+               ch.b[2]  = hex(*buf++) << 4;
+               ch.b[2] |= hex(*buf++);
+               ch.b[3]  = hex(*buf++) << 4;
+               ch.b[3] |= hex(*buf++);
+               if (gdbstub_write_dword(ch.val, mem) != 0)
+                       return 0;
+               mem += 4;
+               count -= 4;
+       }
+
+       if (count >= 2) {
+               ch.b[0]  = hex(*buf++) << 4;
+               ch.b[0] |= hex(*buf++);
+               ch.b[1]  = hex(*buf++) << 4;
+               ch.b[1] |= hex(*buf++);
+               if (gdbstub_write_word(ch.val, mem) != 0)
+                       return 0;
+               mem += 2;
+               count -= 2;
+       }
+
+       if (count >= 1) {
+               ch.b[0]  = hex(*buf++) << 4;
+               ch.b[0] |= hex(*buf++);
+               if (gdbstub_write_byte(ch.val, mem) != 0)
+                       return 0;
+       }
+
+       return buf;
+}
+
+/*
+ * This table contains the mapping between MN10300 exception codes, and
+ * signals, which are primarily what GDB understands.  It also indicates
+ * which hardware traps we need to commandeer when initializing the stub.
+ */
+static const struct excep_to_sig_map {
+       enum exception_code     excep;  /* MN10300 exception code */
+       unsigned char           signo;  /* Signal that we map this into */
+} excep_to_sig_map[] = {
+       { EXCEP_ITLBMISS,       SIGSEGV         },
+       { EXCEP_DTLBMISS,       SIGSEGV         },
+       { EXCEP_TRAP,           SIGTRAP         },
+       { EXCEP_ISTEP,          SIGTRAP         },
+       { EXCEP_IBREAK,         SIGTRAP         },
+       { EXCEP_OBREAK,         SIGTRAP         },
+       { EXCEP_UNIMPINS,       SIGILL          },
+       { EXCEP_UNIMPEXINS,     SIGILL          },
+       { EXCEP_MEMERR,         SIGSEGV         },
+       { EXCEP_MISALIGN,       SIGSEGV         },
+       { EXCEP_BUSERROR,       SIGBUS          },
+       { EXCEP_ILLINSACC,      SIGSEGV         },
+       { EXCEP_ILLDATACC,      SIGSEGV         },
+       { EXCEP_IOINSACC,       SIGSEGV         },
+       { EXCEP_PRIVINSACC,     SIGSEGV         },
+       { EXCEP_PRIVDATACC,     SIGSEGV         },
+       { EXCEP_FPU_DISABLED,   SIGFPE          },
+       { EXCEP_FPU_UNIMPINS,   SIGFPE          },
+       { EXCEP_FPU_OPERATION,  SIGFPE          },
+       { EXCEP_WDT,            SIGALRM         },
+       { EXCEP_NMI,            SIGQUIT         },
+       { EXCEP_IRQ_LEVEL0,     SIGINT          },
+       { EXCEP_IRQ_LEVEL1,     SIGINT          },
+       { EXCEP_IRQ_LEVEL2,     SIGINT          },
+       { EXCEP_IRQ_LEVEL3,     SIGINT          },
+       { EXCEP_IRQ_LEVEL4,     SIGINT          },
+       { EXCEP_IRQ_LEVEL5,     SIGINT          },
+       { EXCEP_IRQ_LEVEL6,     SIGINT          },
+       { 0, 0}
+};
+
+/*
+ * convert the MN10300 exception code into a UNIX signal number
+ */
+static int computeSignal(enum exception_code excep)
+{
+       const struct excep_to_sig_map *map;
+
+       for (map = excep_to_sig_map; map->signo; map++)
+               if (map->excep == excep)
+                       return map->signo;
+
+       return SIGHUP; /* default for things we don't know about */
+}
+
+static u32 gdbstub_fpcr, gdbstub_fpufs_array[32];
+
+/*
+ *
+ */
+static void gdbstub_store_fpu(void)
+{
+#ifdef CONFIG_FPU
+
+       asm volatile(
+               "or %2,epsw\n"
+#ifdef CONFIG_MN10300_PROC_MN103E010
+               "nop\n"
+               "nop\n"
+#endif
+               "mov %1, a1\n"
+               "fmov fs0,  (a1+)\n"
+               "fmov fs1,  (a1+)\n"
+               "fmov fs2,  (a1+)\n"
+               "fmov fs3,  (a1+)\n"
+               "fmov fs4,  (a1+)\n"
+               "fmov fs5,  (a1+)\n"
+               "fmov fs6,  (a1+)\n"
+               "fmov fs7,  (a1+)\n"
+               "fmov fs8,  (a1+)\n"
+               "fmov fs9,  (a1+)\n"
+               "fmov fs10, (a1+)\n"
+               "fmov fs11, (a1+)\n"
+               "fmov fs12, (a1+)\n"
+               "fmov fs13, (a1+)\n"
+               "fmov fs14, (a1+)\n"
+               "fmov fs15, (a1+)\n"
+               "fmov fs16, (a1+)\n"
+               "fmov fs17, (a1+)\n"
+               "fmov fs18, (a1+)\n"
+               "fmov fs19, (a1+)\n"
+               "fmov fs20, (a1+)\n"
+               "fmov fs21, (a1+)\n"
+               "fmov fs22, (a1+)\n"
+               "fmov fs23, (a1+)\n"
+               "fmov fs24, (a1+)\n"
+               "fmov fs25, (a1+)\n"
+               "fmov fs26, (a1+)\n"
+               "fmov fs27, (a1+)\n"
+               "fmov fs28, (a1+)\n"
+               "fmov fs29, (a1+)\n"
+               "fmov fs30, (a1+)\n"
+               "fmov fs31, (a1+)\n"
+               "fmov fpcr, %0\n"
+               : "=d"(gdbstub_fpcr)
+               : "g" (&gdbstub_fpufs_array), "i"(EPSW_FE)
+               : "a1"
+               );
+#endif
+}
+
+/*
+ *
+ */
+static void gdbstub_load_fpu(void)
+{
+#ifdef CONFIG_FPU
+
+       asm volatile(
+               "or %1,epsw\n"
+#ifdef CONFIG_MN10300_PROC_MN103E010
+               "nop\n"
+               "nop\n"
+#endif
+               "mov %0, a1\n"
+               "fmov (a1+), fs0\n"
+               "fmov (a1+), fs1\n"
+               "fmov (a1+), fs2\n"
+               "fmov (a1+), fs3\n"
+               "fmov (a1+), fs4\n"
+               "fmov (a1+), fs5\n"
+               "fmov (a1+), fs6\n"
+               "fmov (a1+), fs7\n"
+               "fmov (a1+), fs8\n"
+               "fmov (a1+), fs9\n"
+               "fmov (a1+), fs10\n"
+               "fmov (a1+), fs11\n"
+               "fmov (a1+), fs12\n"
+               "fmov (a1+), fs13\n"
+               "fmov (a1+), fs14\n"
+               "fmov (a1+), fs15\n"
+               "fmov (a1+), fs16\n"
+               "fmov (a1+), fs17\n"
+               "fmov (a1+), fs18\n"
+               "fmov (a1+), fs19\n"
+               "fmov (a1+), fs20\n"
+               "fmov (a1+), fs21\n"
+               "fmov (a1+), fs22\n"
+               "fmov (a1+), fs23\n"
+               "fmov (a1+), fs24\n"
+               "fmov (a1+), fs25\n"
+               "fmov (a1+), fs26\n"
+               "fmov (a1+), fs27\n"
+               "fmov (a1+), fs28\n"
+               "fmov (a1+), fs29\n"
+               "fmov (a1+), fs30\n"
+               "fmov (a1+), fs31\n"
+               "fmov %2, fpcr\n"
+               :
+               : "g" (&gdbstub_fpufs_array), "i"(EPSW_FE), "d"(gdbstub_fpcr)
+               : "a1"
+       );
+#endif
+}
+
+/*
+ * set a software breakpoint
+ */
+int gdbstub_set_breakpoint(u8 *addr, int len)
+{
+       int bkpt, loop, xloop;
+
+#ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
+       len = (len + 1) & ~1;
+#endif
+
+       gdbstub_bkpt("setbkpt(%p,%d)\n", addr, len);
+
+       for (bkpt = 255; bkpt >= 0; bkpt--)
+               if (!gdbstub_bkpts[bkpt].addr)
+                       break;
+       if (bkpt < 0)
+               return -ENOSPC;
+
+       for (loop = 0; loop < len; loop++)
+               if (gdbstub_read_byte(&addr[loop],
+                                     &gdbstub_bkpts[bkpt].origbytes[loop]
+                                     ) < 0)
+                       return -EFAULT;
+
+       gdbstub_flush_caches = 1;
+
+#ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
+       for (loop = 0; loop < len; loop++)
+               if (gdbstub_write_byte(0xF7, &addr[loop]) < 0)
+                       goto restore;
+#else
+       for (loop = 0; loop < len; loop++)
+               if (gdbstub_write_byte(0xFF, &addr[loop]) < 0)
+                       goto restore;
+#endif
+
+       gdbstub_bkpts[bkpt].addr = addr;
+       gdbstub_bkpts[bkpt].len = len;
+
+       gdbstub_bkpt("Set BKPT[%02x]: %p-%p {%02x%02x%02x%02x%02x%02x%02x}\n",
+                    bkpt,
+                    gdbstub_bkpts[bkpt].addr,
+                    gdbstub_bkpts[bkpt].addr + gdbstub_bkpts[bkpt].len - 1,
+                    gdbstub_bkpts[bkpt].origbytes[0],
+                    gdbstub_bkpts[bkpt].origbytes[1],
+                    gdbstub_bkpts[bkpt].origbytes[2],
+                    gdbstub_bkpts[bkpt].origbytes[3],
+                    gdbstub_bkpts[bkpt].origbytes[4],
+                    gdbstub_bkpts[bkpt].origbytes[5],
+                    gdbstub_bkpts[bkpt].origbytes[6]
+                    );
+
+       return 0;
+
+restore:
+       for (xloop = 0; xloop < loop; xloop++)
+               gdbstub_write_byte(gdbstub_bkpts[bkpt].origbytes[xloop],
+                                  addr + xloop);
+       return -EFAULT;
+}
+
+/*
+ * clear a software breakpoint
+ */
+int gdbstub_clear_breakpoint(u8 *addr, int len)
+{
+       int bkpt, loop;
+
+#ifdef GDBSTUB_USE_F7F7_AS_BREAKPOINT
+       len = (len + 1) & ~1;
+#endif
+
+       gdbstub_bkpt("clearbkpt(%p,%d)\n", addr, len);
+
+       for (bkpt = 255; bkpt >= 0; bkpt--)
+               if (gdbstub_bkpts[bkpt].addr == addr &&
+                   gdbstub_bkpts[bkpt].len == len)
+                       break;
+       if (bkpt < 0)
+               return -ENOENT;
+
+       gdbstub_bkpts[bkpt].addr = NULL;
+
+       gdbstub_flush_caches = 1;
+
+       for (loop = 0; loop < len; loop++)
+               if (gdbstub_write_byte(gdbstub_bkpts[bkpt].origbytes[loop],
+                                      addr + loop) < 0)
+                       return -EFAULT;
+
+       return 0;
+}
+
+/*
+ * This function does all command processing for interfacing to gdb
+ * - returns 1 if the exception should be skipped, 0 otherwise.
+ */
+static int gdbstub(struct pt_regs *regs, enum exception_code excep)
+{
+       unsigned long *stack;
+       unsigned long epsw, mdr;
+       uint32_t zero, ssp;
+       uint8_t broke;
+       char *ptr;
+       int sigval;
+       int addr;
+       int length;
+       int loop;
+
+       if (excep == EXCEP_FPU_DISABLED)
+               return 0;
+
+       gdbstub_flush_caches = 0;
+
+       mn10300_set_gdbleds(1);
+
+       asm volatile("mov mdr,%0" : "=d"(mdr));
+       asm volatile("mov epsw,%0" : "=d"(epsw));
+       asm volatile("mov %0,epsw"
+                    :: "d"((epsw & ~EPSW_IM) | EPSW_IE | EPSW_IM_1));
+
+       gdbstub_store_fpu();
+
+#ifdef CONFIG_GDBSTUB_IMMEDIATE
+       /* skip the initial pause loop */
+       if (regs->pc == (unsigned long) __gdbstub_pause)
+               regs->pc = (unsigned long) start_kernel;
+#endif
+
+       /* if we were single stepping, restore the opcodes hoisted for the
+        * breakpoint[s] */
+       broke = 0;
+       if ((step_bp[0].addr && step_bp[0].addr == (u8 *) regs->pc) ||
+           (step_bp[1].addr && step_bp[1].addr == (u8 *) regs->pc))
+               broke = 1;
+
+       __gdbstub_restore_bp();
+
+       if (gdbstub_rx_unget) {
+               sigval = SIGINT;
+               if (gdbstub_rx_unget != 3)
+                       goto packet_waiting;
+               gdbstub_rx_unget = 0;
+       }
+
+       stack = (unsigned long *) regs->sp;
+       sigval = broke ? SIGTRAP : computeSignal(excep);
+
+       /* send information about a BUG() */
+       if (!user_mode(regs) && excep == EXCEP_SYSCALL15) {
+               const struct bug_entry *bug;
+
+               bug = find_bug(regs->pc);
+               if (bug)
+                       goto found_bug;
+               length = snprintf(trans_buffer, sizeof(trans_buffer),
+                                 "BUG() at address %lx\n", regs->pc);
+               goto send_bug_pkt;
+
+       found_bug:
+               length = snprintf(trans_buffer, sizeof(trans_buffer),
+                                 "BUG() at address %lx (%s:%d)\n",
+                                 regs->pc, bug->file, bug->line);
+
+       send_bug_pkt:
+               ptr = output_buffer;
+               *ptr++ = 'O';
+               ptr = mem2hex(trans_buffer, ptr, length, 0);
+               *ptr = 0;
+               putpacket(output_buffer);
+
+               regs->pc -= 2;
+               sigval = SIGABRT;
+       } else if (regs->pc == (unsigned long) __gdbstub_bug_trap) {
+               regs->pc = regs->mdr;
+               sigval = SIGABRT;
+       }
+
+       /*
+        * send a message to the debugger's user saying what happened if it may
+        * not be clear cut (we can't map exceptions onto signals properly)
+        */
+       if (sigval != SIGINT && sigval != SIGTRAP && sigval != SIGILL) {
+               static const char title[] = "Excep ", tbcberr[] = "BCBERR ";
+               static const char crlf[] = "\r\n";
+               char hx;
+               u32 bcberr = BCBERR;
+
+               ptr = output_buffer;
+               *ptr++ = 'O';
+               ptr = mem2hex(title, ptr, sizeof(title) - 1, 0);
+
+               hx = hexchars[(excep & 0xf000) >> 12];
+               *ptr++ = hexchars[hx >> 4];     *ptr++ = hexchars[hx & 0xf];
+               hx = hexchars[(excep & 0x0f00) >> 8];
+               *ptr++ = hexchars[hx >> 4];     *ptr++ = hexchars[hx & 0xf];
+               hx = hexchars[(excep & 0x00f0) >> 4];
+               *ptr++ = hexchars[hx >> 4];     *ptr++ = hexchars[hx & 0xf];
+               hx = hexchars[(excep & 0x000f)];
+               *ptr++ = hexchars[hx >> 4];     *ptr++ = hexchars[hx & 0xf];
+
+               ptr = mem2hex(crlf, ptr, sizeof(crlf) - 1, 0);
+               *ptr = 0;
+               putpacket(output_buffer);       /* send it off... */
+
+               /* BCBERR */
+               ptr = output_buffer;
+               *ptr++ = 'O';
+               ptr = mem2hex(tbcberr, ptr, sizeof(tbcberr) - 1, 0);
+
+               hx = hexchars[(bcberr & 0xf0000000) >> 28];
+               *ptr++ = hexchars[hx >> 4];     *ptr++ = hexchars[hx & 0xf];
+               hx = hexchars[(bcberr & 0x0f000000) >> 24];
+               *ptr++ = hexchars[hx >> 4];     *ptr++ = hexchars[hx & 0xf];
+               hx = hexchars[(bcberr & 0x00f00000) >> 20];
+               *ptr++ = hexchars[hx >> 4];     *ptr++ = hexchars[hx & 0xf];
+               hx = hexchars[(bcberr & 0x000f0000) >> 16];
+               *ptr++ = hexchars[hx >> 4];     *ptr++ = hexchars[hx & 0xf];
+               hx = hexchars[(bcberr & 0x0000f000) >> 12];
+               *ptr++ = hexchars[hx >> 4];     *ptr++ = hexchars[hx & 0xf];
+               hx = hexchars[(bcberr & 0x00000f00) >> 8];
+               *ptr++ = hexchars[hx >> 4];     *ptr++ = hexchars[hx & 0xf];
+               hx = hexchars[(bcberr & 0x000000f0) >> 4];
+               *ptr++ = hexchars[hx >> 4];     *ptr++ = hexchars[hx & 0xf];
+               hx = hexchars[(bcberr & 0x0000000f)];
+               *ptr++ = hexchars[hx >> 4];     *ptr++ = hexchars[hx & 0xf];
+
+               ptr = mem2hex(crlf, ptr, sizeof(crlf) - 1, 0);
+               *ptr = 0;
+               putpacket(output_buffer);       /* send it off... */
+       }
+
+       /*
+        * tell the debugger that an exception has occurred
+        */
+       ptr = output_buffer;
+
+       /*
+        * Send trap type (converted to signal)
+        */
+       *ptr++ = 'T';
+       *ptr++ = hexchars[sigval >> 4];
+       *ptr++ = hexchars[sigval & 0xf];
+
+       /*
+        * Send Error PC
+        */
+       *ptr++ = hexchars[GDB_REGID_PC >> 4];
+       *ptr++ = hexchars[GDB_REGID_PC & 0xf];
+       *ptr++ = ':';
+       ptr = mem2hex(&regs->pc, ptr, 4, 0);
+       *ptr++ = ';';
+
+       /*
+        * Send frame pointer
+        */
+       *ptr++ = hexchars[GDB_REGID_FP >> 4];
+       *ptr++ = hexchars[GDB_REGID_FP & 0xf];
+       *ptr++ = ':';
+       ptr = mem2hex(&regs->a3, ptr, 4, 0);
+       *ptr++ = ';';
+
+       /*
+        * Send stack pointer
+        */
+       ssp = (unsigned long) (regs + 1);
+       *ptr++ = hexchars[GDB_REGID_SP >> 4];
+       *ptr++ = hexchars[GDB_REGID_SP & 0xf];
+       *ptr++ = ':';
+       ptr = mem2hex(&ssp, ptr, 4, 0);
+       *ptr++ = ';';
+
+       *ptr++ = 0;
+       putpacket(output_buffer);       /* send it off... */
+
+packet_waiting:
+       /*
+        * Wait for input from remote GDB
+        */
+       while (1) {
+               output_buffer[0] = 0;
+               getpacket(input_buffer);
+
+               switch (input_buffer[0]) {
+                       /* request repeat of last signal number */
+               case '?':
+                       output_buffer[0] = 'S';
+                       output_buffer[1] = hexchars[sigval >> 4];
+                       output_buffer[2] = hexchars[sigval & 0xf];
+                       output_buffer[3] = 0;
+                       break;
+
+               case 'd':
+                       /* toggle debug flag */
+                       break;
+
+                       /*
+                        * Return the value of the CPU registers
+                        */
+               case 'g':
+                       zero = 0;
+                       ssp = (u32) (regs + 1);
+                       ptr = output_buffer;
+                       ptr = mem2hex(&regs->d0, ptr, 4, 0);
+                       ptr = mem2hex(&regs->d1, ptr, 4, 0);
+                       ptr = mem2hex(&regs->d2, ptr, 4, 0);
+                       ptr = mem2hex(&regs->d3, ptr, 4, 0);
+                       ptr = mem2hex(&regs->a0, ptr, 4, 0);
+                       ptr = mem2hex(&regs->a1, ptr, 4, 0);
+                       ptr = mem2hex(&regs->a2, ptr, 4, 0);
+                       ptr = mem2hex(&regs->a3, ptr, 4, 0);
+
+                       ptr = mem2hex(&ssp, ptr, 4, 0);         /* 8 */
+                       ptr = mem2hex(&regs->pc, ptr, 4, 0);
+                       ptr = mem2hex(&regs->mdr, ptr, 4, 0);
+                       ptr = mem2hex(&regs->epsw, ptr, 4, 0);
+                       ptr = mem2hex(&regs->lir, ptr, 4, 0);
+                       ptr = mem2hex(&regs->lar, ptr, 4, 0);
+                       ptr = mem2hex(&regs->mdrq, ptr, 4, 0);
+
+                       ptr = mem2hex(&regs->e0, ptr, 4, 0);    /* 15 */
+                       ptr = mem2hex(&regs->e1, ptr, 4, 0);
+                       ptr = mem2hex(&regs->e2, ptr, 4, 0);
+                       ptr = mem2hex(&regs->e3, ptr, 4, 0);
+                       ptr = mem2hex(&regs->e4, ptr, 4, 0);
+                       ptr = mem2hex(&regs->e5, ptr, 4, 0);
+                       ptr = mem2hex(&regs->e6, ptr, 4, 0);
+                       ptr = mem2hex(&regs->e7, ptr, 4, 0);
+
+                       ptr = mem2hex(&ssp, ptr, 4, 0);
+                       ptr = mem2hex(&regs, ptr, 4, 0);
+                       ptr = mem2hex(&regs->sp, ptr, 4, 0);
+                       ptr = mem2hex(&regs->mcrh, ptr, 4, 0);  /* 26 */
+                       ptr = mem2hex(&regs->mcrl, ptr, 4, 0);
+                       ptr = mem2hex(&regs->mcvf, ptr, 4, 0);
+
+                       ptr = mem2hex(&gdbstub_fpcr, ptr, 4, 0); /* 29 - FPCR */
+                       ptr = mem2hex(&zero, ptr, 4, 0);
+                       ptr = mem2hex(&zero, ptr, 4, 0);
+                       for (loop = 0; loop < 32; loop++)
+                               ptr = mem2hex(&gdbstub_fpufs_array[loop],
+                                             ptr, 4, 0); /* 32 - FS0-31 */
+
+                       break;
+
+                       /*
+                        * set the value of the CPU registers - return OK
+                        */
+               case 'G':
+               {
+                       const char *ptr;
+
+                       ptr = &input_buffer[1];
+                       ptr = hex2mem(ptr, &regs->d0, 4, 0);
+                       ptr = hex2mem(ptr, &regs->d1, 4, 0);
+                       ptr = hex2mem(ptr, &regs->d2, 4, 0);
+                       ptr = hex2mem(ptr, &regs->d3, 4, 0);
+                       ptr = hex2mem(ptr, &regs->a0, 4, 0);
+                       ptr = hex2mem(ptr, &regs->a1, 4, 0);
+                       ptr = hex2mem(ptr, &regs->a2, 4, 0);
+                       ptr = hex2mem(ptr, &regs->a3, 4, 0);
+
+                       ptr = hex2mem(ptr, &ssp, 4, 0);         /* 8 */
+                       ptr = hex2mem(ptr, &regs->pc, 4, 0);
+                       ptr = hex2mem(ptr, &regs->mdr, 4, 0);
+                       ptr = hex2mem(ptr, &regs->epsw, 4, 0);
+                       ptr = hex2mem(ptr, &regs->lir, 4, 0);
+                       ptr = hex2mem(ptr, &regs->lar, 4, 0);
+                       ptr = hex2mem(ptr, &regs->mdrq, 4, 0);
+
+                       ptr = hex2mem(ptr, &regs->e0, 4, 0);    /* 15 */
+                       ptr = hex2mem(ptr, &regs->e1, 4, 0);
+                       ptr = hex2mem(ptr, &regs->e2, 4, 0);
+                       ptr = hex2mem(ptr, &regs->e3, 4, 0);
+                       ptr = hex2mem(ptr, &regs->e4, 4, 0);
+                       ptr = hex2mem(ptr, &regs->e5, 4, 0);
+                       ptr = hex2mem(ptr, &regs->e6, 4, 0);
+                       ptr = hex2mem(ptr, &regs->e7, 4, 0);
+
+                       ptr = hex2mem(ptr, &ssp, 4, 0);
+                       ptr = hex2mem(ptr, &zero, 4, 0);
+                       ptr = hex2mem(ptr, &regs->sp, 4, 0);
+                       ptr = hex2mem(ptr, &regs->mcrh, 4, 0);  /* 26 */
+                       ptr = hex2mem(ptr, &regs->mcrl, 4, 0);
+                       ptr = hex2mem(ptr, &regs->mcvf, 4, 0);
+
+                       ptr = hex2mem(ptr, &zero, 4, 0);        /* 29 - FPCR */
+                       ptr = hex2mem(ptr, &zero, 4, 0);
+                       ptr = hex2mem(ptr, &zero, 4, 0);
+                       for (loop = 0; loop < 32; loop++)     /* 32 - FS0-31 */
+                               ptr = hex2mem(ptr, &zero, 4, 0);
+
+#if 0
+                       /*
+                        * See if the stack pointer has moved. If so, then copy
+                        * the saved locals and ins to the new location.
+                        */
+                       unsigned long *newsp = (unsigned long *) registers[SP];
+                       if (sp != newsp)
+                               sp = memcpy(newsp, sp, 16 * 4);
+#endif
+
+                       gdbstub_strcpy(output_buffer, "OK");
+               }
+               break;
+
+               /*
+                * mAA..AA,LLLL  Read LLLL bytes at address AA..AA
+                */
+               case 'm':
+                       ptr = &input_buffer[1];
+
+                       if (hexToInt(&ptr, &addr) &&
+                           *ptr++ == ',' &&
+                           hexToInt(&ptr, &length)
+                           ) {
+                               if (mem2hex((char *) addr, output_buffer,
+                                           length, 1))
+                                       break;
+                               gdbstub_strcpy(output_buffer, "E03");
+                       } else {
+                               gdbstub_strcpy(output_buffer, "E01");
+                       }
+                       break;
+
+                       /*
+                        * MAA..AA,LLLL: Write LLLL bytes at address AA.AA
+                        * return OK
+                        */
+               case 'M':
+                       ptr = &input_buffer[1];
+
+                       if (hexToInt(&ptr, &addr) &&
+                           *ptr++ == ',' &&
+                           hexToInt(&ptr, &length) &&
+                           *ptr++ == ':'
+                           ) {
+                               if (hex2mem(ptr, (char *) addr, length, 1))
+                                       gdbstub_strcpy(output_buffer, "OK");
+                               else
+                                       gdbstub_strcpy(output_buffer, "E03");
+
+                               gdbstub_flush_caches = 1;
+                       } else {
+                               gdbstub_strcpy(output_buffer, "E02");
+                       }
+                       break;
+
+                       /*
+                        * cAA..AA    Continue at address AA..AA(optional)
+                        */
+               case 'c':
+                       /* try to read optional parameter, pc unchanged if no
+                        * parm */
+
+                       ptr = &input_buffer[1];
+                       if (hexToInt(&ptr, &addr))
+                               regs->pc = addr;
+                       goto done;
+
+                       /*
+                        * kill the program
+                        */
+               case 'k' :
+                       goto done;      /* just continue */
+
+                       /*
+                        * Reset the whole machine (FIXME: system dependent)
+                        */
+               case 'r':
+                       break;
+
+                       /*
+                        * Step to next instruction
+                        */
+               case 's':
+                       /*
+                        * using the T flag doesn't seem to perform single
+                        * stepping (it seems to wind up being caught by the
+                        * JTAG unit), so we have to use breakpoints and
+                        * continue instead.
+                        */
+                       if (gdbstub_single_step(regs) < 0)
+                               /* ignore any fault error for now */
+                               gdbstub_printk("unable to set single-step"
+                                              " bp\n");
+                       goto done;
+
+                       /*
+                        * Set baud rate (bBB)
+                        */
+               case 'b':
+                       do {
+                               int baudrate;
+
+                               ptr = &input_buffer[1];
+                               if (!hexToInt(&ptr, &baudrate)) {
+                                       gdbstub_strcpy(output_buffer, "B01");
+                                       break;
+                               }
+
+                               if (baudrate) {
+                                       /* ACK before changing speed */
+                                       putpacket("OK");
+                                       gdbstub_io_set_baud(baudrate);
+                               }
+                       } while (0);
+                       break;
+
+                       /*
+                        * Set breakpoint
+                        */
+               case 'Z':
+                       ptr = &input_buffer[1];
+
+                       if (!hexToInt(&ptr, &loop) || *ptr++ != ',' ||
+                           !hexToInt(&ptr, &addr) || *ptr++ != ',' ||
+                           !hexToInt(&ptr, &length)
+                           ) {
+                               gdbstub_strcpy(output_buffer, "E01");
+                               break;
+                       }
+
+                       /* only support software breakpoints */
+                       gdbstub_strcpy(output_buffer, "E03");
+                       if (loop != 0 ||
+                           length < 1 ||
+                           length > 7 ||
+                           (unsigned long) addr < 4096)
+                               break;
+
+                       if (gdbstub_set_breakpoint((u8 *) addr, length) < 0)
+                               break;
+
+                       gdbstub_strcpy(output_buffer, "OK");
+                       break;
+
+                       /*
+                        * Clear breakpoint
+                        */
+               case 'z':
+                       ptr = &input_buffer[1];
+
+                       if (!hexToInt(&ptr, &loop) || *ptr++ != ',' ||
+                           !hexToInt(&ptr, &addr) || *ptr++ != ',' ||
+                           !hexToInt(&ptr, &length)
+                           ) {
+                               gdbstub_strcpy(output_buffer, "E01");
+                               break;
+                       }
+
+                       /* only support software breakpoints */
+                       gdbstub_strcpy(output_buffer, "E03");
+                       if (loop != 0 ||
+                           length < 1 ||
+                           length > 7 ||
+                           (unsigned long) addr < 4096)
+                               break;
+
+                       if (gdbstub_clear_breakpoint((u8 *) addr, length) < 0)
+                               break;
+
+                       gdbstub_strcpy(output_buffer, "OK");
+                       break;
+
+               default:
+                       gdbstub_proto("### GDB Unsupported Cmd '%s'\n",
+                                     input_buffer);
+                       break;
+               }
+
+               /* reply to the request */
+               putpacket(output_buffer);
+       }
+
+done:
+       /*
+        * Need to flush the instruction cache here, as we may
+        * have deposited a breakpoint, and the icache probably
+        * has no way of knowing that a data ref to some location
+        * may have changed something that is in the instruction
+        * cache.
+        * NB: We flush both caches, just to be sure...
+        */
+       if (gdbstub_flush_caches)
+               gdbstub_purge_cache();
+
+       gdbstub_load_fpu();
+       mn10300_set_gdbleds(0);
+       if (excep == EXCEP_NMI)
+               NMICR = NMICR_NMIF;
+
+       touch_softlockup_watchdog();
+
+       local_irq_restore(epsw);
+       return 1;
+}
+
+/*
+ * handle event interception
+ */
+asmlinkage int gdbstub_intercept(struct pt_regs *regs,
+                                enum exception_code excep)
+{
+       static u8 notfirst = 1;
+       int ret;
+
+       if (gdbstub_busy)
+               gdbstub_printk("--> gdbstub reentered itself\n");
+       gdbstub_busy = 1;
+
+       if (notfirst) {
+               unsigned long mdr;
+               asm("mov mdr,%0" : "=d"(mdr));
+
+               gdbstub_entry(
+                       "--> gdbstub_intercept(%p,%04x) [MDR=%lx PC=%lx]\n",
+                       regs, excep, mdr, regs->pc);
+
+               gdbstub_entry(
+                       "PC:  %08lx EPSW:  %08lx  SSP: %08lx mode: %s\n",
+                       regs->pc, regs->epsw, (unsigned long) &ret,
+                       user_mode(regs) ? "User" : "Super");
+               gdbstub_entry(
+                       "d0:  %08lx   d1:  %08lx   d2: %08lx   d3: %08lx\n",
+                       regs->d0, regs->d1, regs->d2, regs->d3);
+               gdbstub_entry(
+                       "a0:  %08lx   a1:  %08lx   a2: %08lx   a3: %08lx\n",
+                       regs->a0, regs->a1, regs->a2, regs->a3);
+               gdbstub_entry(
+                       "e0:  %08lx   e1:  %08lx   e2: %08lx   e3: %08lx\n",
+                       regs->e0, regs->e1, regs->e2, regs->e3);
+               gdbstub_entry(
+                       "e4:  %08lx   e5:  %08lx   e6: %08lx   e7: %08lx\n",
+                       regs->e4, regs->e5, regs->e6, regs->e7);
+               gdbstub_entry(
+                       "lar: %08lx   lir: %08lx  mdr: %08lx  usp: %08lx\n",
+                       regs->lar, regs->lir, regs->mdr, regs->sp);
+               gdbstub_entry(
+                       "cvf: %08lx   crl: %08lx  crh: %08lx  drq: %08lx\n",
+                       regs->mcvf, regs->mcrl, regs->mcrh, regs->mdrq);
+               gdbstub_entry(
+                       "threadinfo=%p task=%p)\n",
+                       current_thread_info(), current);
+       } else {
+               notfirst = 1;
+       }
+
+       ret = gdbstub(regs, excep);
+
+       gdbstub_entry("<-- gdbstub_intercept()\n");
+       gdbstub_busy = 0;
+       return ret;
+}
+
+/*
+ * handle the GDB stub itself causing an exception
+ */
+asmlinkage void gdbstub_exception(struct pt_regs *regs,
+                                 enum exception_code excep)
+{
+       unsigned long mdr;
+
+       asm("mov mdr,%0" : "=d"(mdr));
+       gdbstub_entry("--> gdbstub exception({%p},%04x) [MDR=%lx]\n",
+                     regs, excep, mdr);
+
+       while ((unsigned long) regs == 0xffffffff) {}
+
+       /* handle guarded memory accesses where we know it might fault */
+       if (regs->pc == (unsigned) gdbstub_read_byte_guard) {
+               regs->pc = (unsigned) gdbstub_read_byte_cont;
+               goto fault;
+       }
+
+       if (regs->pc == (unsigned) gdbstub_read_word_guard) {
+               regs->pc = (unsigned) gdbstub_read_word_cont;
+               goto fault;
+       }
+
+       if (regs->pc == (unsigned) gdbstub_read_dword_guard) {
+               regs->pc = (unsigned) gdbstub_read_dword_cont;
+               goto fault;
+       }
+
+       if (regs->pc == (unsigned) gdbstub_write_byte_guard) {
+               regs->pc = (unsigned) gdbstub_write_byte_cont;
+               goto fault;
+       }
+
+       if (regs->pc == (unsigned) gdbstub_write_word_guard) {
+               regs->pc = (unsigned) gdbstub_write_word_cont;
+               goto fault;
+       }
+
+       if (regs->pc == (unsigned) gdbstub_write_dword_guard) {
+               regs->pc = (unsigned) gdbstub_write_dword_cont;
+               goto fault;
+       }
+
+       gdbstub_printk("\n### GDB stub caused an exception ###\n");
+
+       /* something went horribly wrong */
+       console_verbose();
+       show_registers(regs);
+
+       panic("GDB Stub caused an unexpected exception - can't continue\n");
+
+       /* we caught an attempt by the stub to access silly memory */
+fault:
+       gdbstub_entry("<-- gdbstub exception() = EFAULT\n");
+       regs->d0 = -EFAULT;
+       return;
+}
+
+/*
+ * send an exit message to GDB
+ */
+void gdbstub_exit(int status)
+{
+       unsigned char checksum;
+       unsigned char ch;
+       int count;
+
+       gdbstub_busy = 1;
+       output_buffer[0] = 'W';
+       output_buffer[1] = hexchars[(status >> 4) & 0x0F];
+       output_buffer[2] = hexchars[status & 0x0F];
+       output_buffer[3] = 0;
+
+       gdbstub_io_tx_char('$');
+       checksum = 0;
+       count = 0;
+
+       while ((ch = output_buffer[count]) != 0) {
+               gdbstub_io_tx_char(ch);
+               checksum += ch;
+               count += 1;
+       }
+
+       gdbstub_io_tx_char('#');
+       gdbstub_io_tx_char(hexchars[checksum >> 4]);
+       gdbstub_io_tx_char(hexchars[checksum & 0xf]);
+
+       /* make sure the output is flushed, or else RedBoot might clobber it */
+       gdbstub_io_tx_flush();
+
+       gdbstub_busy = 0;
+}
+
+/*
+ * initialise the GDB stub
+ */
+asmlinkage void __init gdbstub_init(void)
+{
+#ifdef CONFIG_GDBSTUB_IMMEDIATE
+       unsigned char ch;
+       int ret;
+#endif
+
+       gdbstub_busy = 1;
+
+       printk(KERN_INFO "%s", gdbstub_banner);
+
+       gdbstub_io_init();
+
+       gdbstub_entry("--> gdbstub_init\n");
+
+       /* try to talk to GDB (or anyone insane enough to want to type GDB
+        * protocol by hand) */
+       gdbstub_io("### GDB Tx ACK\n");
+       gdbstub_io_tx_char('+'); /* 'hello world' */
+
+#ifdef CONFIG_GDBSTUB_IMMEDIATE
+       gdbstub_printk("GDB Stub waiting for packet\n");
+
+       /* in case GDB is started before us, ACK any packets that are already
+        * sitting there (presumably "$?#xx")
+        */
+       do { gdbstub_io_rx_char(&ch, 0); } while (ch != '$');
+       do { gdbstub_io_rx_char(&ch, 0); } while (ch != '#');
+       /* eat first csum byte */
+       do { ret = gdbstub_io_rx_char(&ch, 0); } while (ret != 0);
+       /* eat second csum byte */
+       do { ret = gdbstub_io_rx_char(&ch, 0); } while (ret != 0);
+
+       gdbstub_io("### GDB Tx NAK\n");
+       gdbstub_io_tx_char('-'); /* NAK it */
+
+#else
+       printk("GDB Stub ready\n");
+#endif
+
+       gdbstub_busy = 0;
+       gdbstub_entry("<-- gdbstub_init\n");
+}
+
+/*
+ * register the console at a more appropriate time
+ */
+#ifdef CONFIG_GDBSTUB_CONSOLE
+static int __init gdbstub_postinit(void)
+{
+       printk(KERN_NOTICE "registering console\n");
+       register_console(&gdbstub_console);
+       return 0;
+}
+
+__initcall(gdbstub_postinit);
+#endif
+
+/*
+ * handle character reception on GDB serial port
+ * - jump into the GDB stub if BREAK is detected on the serial line
+ */
+asmlinkage void gdbstub_rx_irq(struct pt_regs *regs, enum exception_code excep)
+{
+       char ch;
+       int ret;
+
+       gdbstub_entry("--> gdbstub_rx_irq\n");
+
+       do {
+               ret = gdbstub_io_rx_char(&ch, 1);
+               if (ret != -EIO && ret != -EAGAIN) {
+                       if (ret != -EINTR)
+                               gdbstub_rx_unget = ch;
+                       gdbstub(regs, excep);
+               }
+       } while (ret != -EAGAIN);
+
+       gdbstub_entry("<-- gdbstub_rx_irq\n");
+}
diff --git a/arch/mn10300/kernel/head.S b/arch/mn10300/kernel/head.S
new file mode 100644 (file)
index 0000000..606bd8c
--- /dev/null
@@ -0,0 +1,255 @@
+/* Boot entry point for MN10300 kernel
+ *
+ * Copyright (C) 2005 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <linux/threads.h>
+#include <linux/linkage.h>
+#include <linux/serial_reg.h>
+#include <asm/thread_info.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
+#include <asm/frame.inc>
+#include <asm/param.h>
+#include <asm/unit/serial.h>
+
+       .section .text.head,"ax"
+
+###############################################################################
+#
+# bootloader entry point
+#
+###############################################################################
+       .globl  _start
+       .type   _start,@function
+_start:
+       # save commandline pointer
+       mov     d0,a3
+
+       # preload the PGD pointer register
+       mov     swapper_pg_dir,d0
+       mov     d0,(PTBR)
+
+       # turn on the TLBs
+       mov     MMUCTR_IIV|MMUCTR_DIV,d0
+       mov     d0,(MMUCTR)
+       mov     MMUCTR_ITE|MMUCTR_DTE|MMUCTR_CE,d0
+       mov     d0,(MMUCTR)
+
+       # turn on AM33v2 exception handling mode and set the trap table base
+       movhu   (CPUP),d0
+       or      CPUP_EXM_AM33V2,d0
+       movhu   d0,(CPUP)
+       mov     CONFIG_INTERRUPT_VECTOR_BASE,d0
+       mov     d0,(TBR)
+
+       # invalidate and enable both of the caches
+       mov     CHCTR,a0
+       clr     d0
+       movhu   d0,(a0)                                 # turn off first
+       mov     CHCTR_ICINV|CHCTR_DCINV,d0
+       movhu   d0,(a0)
+       setlb
+       mov     (a0),d0
+       btst    CHCTR_ICBUSY|CHCTR_DCBUSY,d0            # wait till not busy
+       lne
+
+#ifndef CONFIG_MN10300_CACHE_DISABLED
+#ifdef CONFIG_MN10300_CACHE_WBACK
+#ifndef CONFIG_MN10300_CACHE_WBACK_NOWRALLOC
+       mov     CHCTR_ICEN|CHCTR_DCEN|CHCTR_DCWTMD_WRBACK,d0
+#else
+       mov     CHCTR_ICEN|CHCTR_DCEN|CHCTR_DCWTMD_WRBACK|CHCTR_DCALMD,d0
+#endif /* CACHE_DISABLED */
+#else
+       mov     CHCTR_ICEN|CHCTR_DCEN|CHCTR_DCWTMD_WRTHROUGH,d0
+#endif /* WBACK */
+       movhu   d0,(a0)                                 # enable
+#endif /* NOWRALLOC */
+
+       # turn on RTS on the debug serial port if applicable
+#ifdef CONFIG_MN10300_UNIT_ASB2305
+       bset    UART_MCR_RTS,(ASB2305_DEBUG_MCR)
+#endif
+
+       # clear the BSS area
+       mov     __bss_start,a0
+       mov     __bss_stop,a1
+       clr     d0
+bssclear:
+       cmp     a1,a0
+       bge     bssclear_end
+       mov     d0,(a0)
+       inc4    a0
+       bra     bssclear
+bssclear_end:
+
+       # retrieve the parameters (including command line) before we overwrite
+       # them
+       cmp     0xabadcafe,d1
+       bne     __no_parameters
+
+__copy_parameters:
+       mov     redboot_command_line,a0
+       mov     a0,a1
+       add     COMMAND_LINE_SIZE,a1
+1:
+       movbu   (a3),d0
+       inc     a3
+       movbu   d0,(a0)
+       inc     a0
+       cmp     a1,a0
+       blt     1b
+
+       mov     redboot_platform_name,a0
+       mov     a0,a1
+       add     COMMAND_LINE_SIZE,a1
+       mov     d2,a3
+1:
+       movbu   (a3),d0
+       inc     a3
+       movbu   d0,(a0)
+       inc     a0
+       cmp     a1,a0
+       blt     1b
+
+__no_parameters:
+
+       # set up the registers with recognisable rubbish in them
+       mov     init_thread_union+THREAD_SIZE-12,sp
+
+       mov     0xea01eaea,d0
+       mov     d0,(4,sp)               # EPSW save area
+       mov     0xea02eaea,d0
+       mov     d0,(8,sp)               # PC save area
+
+       mov     0xeb0060ed,d0
+       mov     d0,mdr
+       mov     0xeb0061ed,d0
+       mov     d0,mdrq
+       mov     0xeb0062ed,d0
+       mov     d0,mcrh
+       mov     0xeb0063ed,d0
+       mov     d0,mcrl
+       mov     0xeb0064ed,d0
+       mov     d0,mcvf
+       mov     0xed0065ed,a3
+       mov     a3,usp
+
+       mov     0xed00e0ed,e0
+       mov     0xed00e1ed,e1
+       mov     0xed00e2ed,e2
+       mov     0xed00e3ed,e3
+       mov     0xed00e4ed,e4
+       mov     0xed00e5ed,e5
+       mov     0xed00e6ed,e6
+       mov     0xed00e7ed,e7
+
+       mov     0xed00d0ed,d0
+       mov     0xed00d1ed,d1
+       mov     0xed00d2ed,d2
+       mov     0xed00d3ed,d3
+       mov     0xed00a0ed,a0
+       mov     0xed00a1ed,a1
+       mov     0xed00a2ed,a2
+       mov     0,a3
+
+       # set up the initial kernel stack
+       SAVE_ALL
+       mov     0xffffffff,d0
+       mov     d0,(REG_ORIG_D0,fp)
+
+       # put different recognisable rubbish in the regs
+       mov     0xfb0060ed,d0
+       mov     d0,mdr
+       mov     0xfb0061ed,d0
+       mov     d0,mdrq
+       mov     0xfb0062ed,d0
+       mov     d0,mcrh
+       mov     0xfb0063ed,d0
+       mov     d0,mcrl
+       mov     0xfb0064ed,d0
+       mov     d0,mcvf
+       mov     0xfd0065ed,a0
+       mov     a0,usp
+
+       mov     0xfd00e0ed,e0
+       mov     0xfd00e1ed,e1
+       mov     0xfd00e2ed,e2
+       mov     0xfd00e3ed,e3
+       mov     0xfd00e4ed,e4
+       mov     0xfd00e5ed,e5
+       mov     0xfd00e6ed,e6
+       mov     0xfd00e7ed,e7
+
+       mov     0xfd00d0ed,d0
+       mov     0xfd00d1ed,d1
+       mov     0xfd00d2ed,d2
+       mov     0xfd00d3ed,d3
+       mov     0xfd00a0ed,a0
+       mov     0xfd00a1ed,a1
+       mov     0xfd00a2ed,a2
+
+       # we may be holding current in E2
+#ifdef CONFIG_MN10300_CURRENT_IN_E2
+       mov     init_task,e2
+#endif
+
+       # initialise the processor and the unit
+       call    processor_init[],0
+       call    unit_init[],0
+
+#ifdef CONFIG_GDBSTUB
+       call    gdbstub_init[],0
+
+#ifdef CONFIG_GDBSTUB_IMMEDIATE
+       .globl  __gdbstub_pause
+__gdbstub_pause:
+       bra     __gdbstub_pause
+#endif
+#endif
+
+       jmp     start_kernel
+       .size   _start, _start-.
+ENTRY(__head_end)
+
+/*
+ * This is initialized to disallow all access to the low 2G region
+ * - the high 2G region is managed directly by the MMU
+ * - range 0x70000000-0x7C000000 are initialised for use by VMALLOC
+ */
+       .section .bss
+       .balign PAGE_SIZE
+ENTRY(swapper_pg_dir)
+        .space PTRS_PER_PGD*4
+
+/*
+ * The page tables are initialized to only 8MB here - the final page
+ * tables are set up later depending on memory size.
+ */
+
+       .balign PAGE_SIZE
+ENTRY(empty_zero_page)
+       .space PAGE_SIZE
+
+       .balign PAGE_SIZE
+ENTRY(empty_bad_page)
+       .space PAGE_SIZE
+
+       .balign PAGE_SIZE
+ENTRY(empty_bad_pte_table)
+       .space PAGE_SIZE
+
+       .balign PAGE_SIZE
+ENTRY(large_page_table)
+       .space PAGE_SIZE
+
+       .balign PAGE_SIZE
+ENTRY(kernel_vmalloc_ptes)
+       .space ((VMALLOC_END-VMALLOC_START)/PAGE_SIZE)*4
diff --git a/arch/mn10300/kernel/init_task.c b/arch/mn10300/kernel/init_task.c
new file mode 100644 (file)
index 0000000..39fe688
--- /dev/null
@@ -0,0 +1,45 @@
+/* MN10300 Initial task definitions
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/init.h>
+#include <linux/init_task.h>
+#include <linux/fs.h>
+#include <linux/mqueue.h>
+#include <asm/uaccess.h>
+#include <asm/pgtable.h>
+
+static struct fs_struct init_fs = INIT_FS;
+static struct files_struct init_files = INIT_FILES;
+static struct signal_struct init_signals = INIT_SIGNALS(init_signals);
+static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
+struct mm_struct init_mm = INIT_MM(init_mm);
+EXPORT_SYMBOL(init_mm);
+
+/*
+ * Initial thread structure.
+ *
+ * We need to make sure that this is THREAD_SIZE aligned due to the
+ * way process stacks are handled. This is done by having a special
+ * "init_task" linker map entry..
+ */
+union thread_union init_thread_union
+       __attribute__((__section__(".data.init_task"))) =
+               { INIT_THREAD_INFO(init_task) };
+
+/*
+ * Initial task structure.
+ *
+ * All other task structs will be allocated on slabs in fork.c
+ */
+struct task_struct init_task = INIT_TASK(init_task);
+EXPORT_SYMBOL(init_task);
diff --git a/arch/mn10300/kernel/internal.h b/arch/mn10300/kernel/internal.h
new file mode 100644 (file)
index 0000000..eee2eee
--- /dev/null
@@ -0,0 +1,20 @@
+/* Internal definitions for the arch part of the core kernel
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+/*
+ * kthread.S
+ */
+extern int kernel_thread_helper(int);
+
+/*
+ * entry.S
+ */
+extern void ret_from_fork(struct task_struct *) __attribute__((noreturn));
diff --git a/arch/mn10300/kernel/io.c b/arch/mn10300/kernel/io.c
new file mode 100644 (file)
index 0000000..e96fdf6
--- /dev/null
@@ -0,0 +1,30 @@
+/* MN10300 Misaligned multibyte-word I/O
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/kernel.h>
+#include <asm/io.h>
+
+/*
+ * output data from a potentially misaligned buffer
+ */
+void __outsl(unsigned long addr, const void *buffer, int count)
+{
+       const unsigned char *buf = buffer;
+       unsigned long val;
+
+       while (count--) {
+               memcpy(&val, buf, 4);
+               outl(val, addr);
+               buf += 4;
+       }
+}
+EXPORT_SYMBOL(__outsl);
diff --git a/arch/mn10300/kernel/irq.c b/arch/mn10300/kernel/irq.c
new file mode 100644 (file)
index 0000000..761c434
--- /dev/null
@@ -0,0 +1,235 @@
+/* MN10300 Arch-specific interrupt handling
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/kernel_stat.h>
+#include <linux/seq_file.h>
+#include <asm/setup.h>
+
+unsigned long __mn10300_irq_enabled_epsw = EPSW_IE | EPSW_IM_7;
+EXPORT_SYMBOL(__mn10300_irq_enabled_epsw);
+
+atomic_t irq_err_count;
+
+/*
+ * MN10300 INTC controller operations
+ */
+static void mn10300_cpupic_disable(unsigned int irq)
+{
+       u16 tmp = GxICR(irq);
+       GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_DETECT;
+       tmp = GxICR(irq);
+}
+
+static void mn10300_cpupic_enable(unsigned int irq)
+{
+       u16 tmp = GxICR(irq);
+       GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE;
+       tmp = GxICR(irq);
+}
+
+static void mn10300_cpupic_ack(unsigned int irq)
+{
+       u16 tmp;
+       *(volatile u8 *) &GxICR(irq) = GxICR_DETECT;
+       tmp = GxICR(irq);
+}
+
+static void mn10300_cpupic_mask(unsigned int irq)
+{
+       u16 tmp = GxICR(irq);
+       GxICR(irq) = (tmp & GxICR_LEVEL);
+       tmp = GxICR(irq);
+}
+
+static void mn10300_cpupic_mask_ack(unsigned int irq)
+{
+       u16 tmp = GxICR(irq);
+       GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_DETECT;
+       tmp = GxICR(irq);
+}
+
+static void mn10300_cpupic_unmask(unsigned int irq)
+{
+       u16 tmp = GxICR(irq);
+       GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE | GxICR_DETECT;
+       tmp = GxICR(irq);
+}
+
+static void mn10300_cpupic_end(unsigned int irq)
+{
+       u16 tmp = GxICR(irq);
+       GxICR(irq) = (tmp & GxICR_LEVEL) | GxICR_ENABLE;
+       tmp = GxICR(irq);
+}
+
+static struct irq_chip mn10300_cpu_pic = {
+       .name           = "cpu",
+       .disable        = mn10300_cpupic_disable,
+       .enable         = mn10300_cpupic_enable,
+       .ack            = mn10300_cpupic_ack,
+       .mask           = mn10300_cpupic_mask,
+       .mask_ack       = mn10300_cpupic_mask_ack,
+       .unmask         = mn10300_cpupic_unmask,
+       .end            = mn10300_cpupic_end,
+};
+
+/*
+ * 'what should we do if we get a hw irq event on an illegal vector'.
+ * each architecture has to answer this themselves.
+ */
+void ack_bad_irq(int irq)
+{
+       printk(KERN_WARNING "unexpected IRQ trap at vector %02x\n", irq);
+}
+
+/*
+ * change the level at which an IRQ executes
+ * - must not be called whilst interrupts are being processed!
+ */
+void set_intr_level(int irq, u16 level)
+{
+       u16 tmp;
+
+       if (in_interrupt())
+               BUG();
+
+       tmp = GxICR(irq);
+       GxICR(irq) = (tmp & GxICR_ENABLE) | level;
+       tmp = GxICR(irq);
+}
+
+/*
+ * mark an interrupt to be ACK'd after interrupt handlers have been run rather
+ * than before
+ * - see Documentation/mn10300/features.txt
+ */
+void set_intr_postackable(int irq)
+{
+       set_irq_handler(irq, handle_level_irq);
+}
+
+/*
+ * initialise the interrupt system
+ */
+void __init init_IRQ(void)
+{
+       int irq;
+
+       for (irq = 0; irq < NR_IRQS; irq++)
+               if (irq_desc[irq].chip == &no_irq_type)
+                       set_irq_chip_and_handler(irq, &mn10300_cpu_pic,
+                                                handle_edge_irq);
+       unit_init_IRQ();
+}
+
+/*
+ * handle normal device IRQs
+ */
+asmlinkage void do_IRQ(void)
+{
+       unsigned long sp, epsw, irq_disabled_epsw, old_irq_enabled_epsw;
+       int irq;
+
+       sp = current_stack_pointer();
+       if (sp - (sp & ~(THREAD_SIZE - 1)) < STACK_WARN)
+               BUG();
+
+       /* make sure local_irq_enable() doesn't muck up the interrupt priority
+        * setting in EPSW */
+       old_irq_enabled_epsw = __mn10300_irq_enabled_epsw;
+       local_save_flags(epsw);
+       __mn10300_irq_enabled_epsw = EPSW_IE | (EPSW_IM & epsw);
+       irq_disabled_epsw = EPSW_IE | MN10300_CLI_LEVEL;
+
+       __IRQ_STAT(smp_processor_id(), __irq_count)++;
+
+       irq_enter();
+
+       for (;;) {
+               /* ask the interrupt controller for the next IRQ to process
+                * - the result we get depends on EPSW.IM
+                */
+               irq = IAGR & IAGR_GN;
+               if (!irq)
+                       break;
+
+               local_irq_restore(irq_disabled_epsw);
+
+               generic_handle_irq(irq >> 2);
+
+               /* restore IRQ controls for IAGR access */
+               local_irq_restore(epsw);
+       }
+
+       __mn10300_irq_enabled_epsw = old_irq_enabled_epsw;
+
+       irq_exit();
+}
+
+/*
+ * Display interrupt management information through /proc/interrupts
+ */
+int show_interrupts(struct seq_file *p, void *v)
+{
+       int i = *(loff_t *) v, j, cpu;
+       struct irqaction *action;
+       unsigned long flags;
+
+       switch (i) {
+               /* display column title bar naming CPUs */
+       case 0:
+               seq_printf(p, "           ");
+               for (j = 0; j < NR_CPUS; j++)
+                       if (cpu_online(j))
+                               seq_printf(p, "CPU%d       ", j);
+               seq_putc(p, '\n');
+               break;
+
+               /* display information rows, one per active CPU */
+       case 1 ... NR_IRQS - 1:
+               spin_lock_irqsave(&irq_desc[i].lock, flags);
+
+               action = irq_desc[i].action;
+               if (action) {
+                       seq_printf(p, "%3d: ", i);
+                       for_each_present_cpu(cpu)
+                               seq_printf(p, "%10u ", kstat_cpu(cpu).irqs[i]);
+                       seq_printf(p, " %14s.%u", irq_desc[i].chip->name,
+                                  (GxICR(i) & GxICR_LEVEL) >>
+                                  GxICR_LEVEL_SHIFT);
+                       seq_printf(p, "  %s", action->name);
+
+                       for (action = action->next;
+                            action;
+                            action = action->next)
+                               seq_printf(p, ", %s", action->name);
+
+                       seq_putc(p, '\n');
+               }
+
+               spin_unlock_irqrestore(&irq_desc[i].lock, flags);
+               break;
+
+               /* polish off with NMI and error counters */
+       case NR_IRQS:
+               seq_printf(p, "NMI: ");
+               for (j = 0; j < NR_CPUS; j++)
+                       if (cpu_online(j))
+                               seq_printf(p, "%10u ", nmi_count(j));
+               seq_putc(p, '\n');
+
+               seq_printf(p, "ERR: %10u\n", atomic_read(&irq_err_count));
+               break;
+       }
+
+       return 0;
+}
diff --git a/arch/mn10300/kernel/kernel_execve.S b/arch/mn10300/kernel/kernel_execve.S
new file mode 100644 (file)
index 0000000..86039f1
--- /dev/null
@@ -0,0 +1,37 @@
+/* MN10300 In-kernel program execution
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/linkage.h>
+#include <asm/unistd.h>
+
+###############################################################################
+#
+# Do a system call from kernel instead of calling sys_execve so we end up with
+# proper pt_regs.
+#
+# int kernel_execve(const char *filename, char *const argv[],
+#                  char *const envp[])
+#
+# On entry: D0/D1/8(SP): arguments to function
+# On return: D0: syscall return.
+#
+###############################################################################
+       .globl          kernel_execve
+       .type           kernel_execve,@function
+kernel_execve:
+       mov             a3,a1
+       mov             d0,a0
+       mov             (12,sp),a3
+       mov             +__NR_execve,d0
+       syscall         0
+       mov             a1,a3
+       rets
+
+       .size           kernel_execve,.-kernel_execve
diff --git a/arch/mn10300/kernel/kprobes.c b/arch/mn10300/kernel/kprobes.c
new file mode 100644 (file)
index 0000000..dacafab
--- /dev/null
@@ -0,0 +1,653 @@
+/* MN10300 Kernel probes implementation
+ *
+ * Copyright (C) 2005 Red Hat, Inc. All Rights Reserved.
+ * Written by Mark Salter (msalter@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public Licence as published by
+ * the Free Software Foundation; either version 2 of the Licence, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public Licence for more details.
+ *
+ * You should have received a copy of the GNU General Public Licence
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+#include <linux/kprobes.h>
+#include <linux/ptrace.h>
+#include <linux/spinlock.h>
+#include <linux/preempt.h>
+#include <linux/kdebug.h>
+#include <asm/cacheflush.h>
+
+struct kretprobe_blackpoint kretprobe_blacklist[] = { { NULL, NULL } };
+const int kretprobe_blacklist_size = ARRAY_SIZE(kretprobe_blacklist);
+
+/* kprobe_status settings */
+#define KPROBE_HIT_ACTIVE      0x00000001
+#define KPROBE_HIT_SS          0x00000002
+
+static struct kprobe *current_kprobe;
+static unsigned long current_kprobe_orig_pc;
+static unsigned long current_kprobe_next_pc;
+static int current_kprobe_ss_flags;
+static unsigned long kprobe_status;
+static kprobe_opcode_t current_kprobe_ss_buf[MAX_INSN_SIZE + 2];
+static unsigned long current_kprobe_bp_addr;
+
+DEFINE_PER_CPU(struct kprobe *, current_kprobe) = NULL;
+
+
+/* singlestep flag bits */
+#define SINGLESTEP_BRANCH 1
+#define SINGLESTEP_PCREL  2
+
+#define READ_BYTE(p, valp) \
+       do { *(u8 *)(valp) = *(u8 *)(p); } while (0)
+
+#define READ_WORD16(p, valp)                                   \
+       do {                                                    \
+               READ_BYTE((p), (valp));                         \
+               READ_BYTE((u8 *)(p) + 1, (u8 *)(valp) + 1);     \
+       } while (0)
+
+#define READ_WORD32(p, valp)                                   \
+       do {                                                    \
+               READ_BYTE((p), (valp));                         \
+               READ_BYTE((u8 *)(p) + 1, (u8 *)(valp) + 1);     \
+               READ_BYTE((u8 *)(p) + 2, (u8 *)(valp) + 2);     \
+               READ_BYTE((u8 *)(p) + 3, (u8 *)(valp) + 3);     \
+       } while (0)
+
+
+static const u8 mn10300_insn_sizes[256] =
+{
+       /* 1  2  3  4  5  6  7  8  9  a  b  c  d  e  f */
+       1, 3, 3, 3, 1, 3, 3, 3, 1, 3, 3, 3, 1, 3, 3, 3, /* 0 */
+       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 1 */
+       2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, /* 2 */
+       3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, /* 3 */
+       1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, /* 4 */
+       1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, /* 5 */
+       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6 */
+       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 7 */
+       2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, /* 8 */
+       2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, /* 9 */
+       2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, /* a */
+       2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, /* b */
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 2, /* c */
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* d */
+       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* e */
+       0, 2, 2, 2, 2, 2, 2, 4, 0, 3, 0, 4, 0, 6, 7, 1  /* f */
+};
+
+#define LT (1 << 0)
+#define GT (1 << 1)
+#define GE (1 << 2)
+#define LE (1 << 3)
+#define CS (1 << 4)
+#define HI (1 << 5)
+#define CC (1 << 6)
+#define LS (1 << 7)
+#define EQ (1 << 8)
+#define NE (1 << 9)
+#define RA (1 << 10)
+#define VC (1 << 11)
+#define VS (1 << 12)
+#define NC (1 << 13)
+#define NS (1 << 14)
+
+static const u16 cond_table[] = {
+       /*  V  C  N  Z  */
+       /*  0  0  0  0  */ (NE | NC | CC | VC | GE | GT | HI),
+       /*  0  0  0  1  */ (EQ | NC | CC | VC | GE | LE | LS),
+       /*  0  0  1  0  */ (NE | NS | CC | VC | LT | LE | HI),
+       /*  0  0  1  1  */ (EQ | NS | CC | VC | LT | LE | LS),
+       /*  0  1  0  0  */ (NE | NC | CS | VC | GE | GT | LS),
+       /*  0  1  0  1  */ (EQ | NC | CS | VC | GE | LE | LS),
+       /*  0  1  1  0  */ (NE | NS | CS | VC | LT | LE | LS),
+       /*  0  1  1  1  */ (EQ | NS | CS | VC | LT | LE | LS),
+       /*  1  0  0  0  */ (NE | NC | CC | VS | LT | LE | HI),
+       /*  1  0  0  1  */ (EQ | NC | CC | VS | LT | LE | LS),
+       /*  1  0  1  0  */ (NE | NS | CC | VS | GE | GT | HI),
+       /*  1  0  1  1  */ (EQ | NS | CC | VS | GE | LE | LS),
+       /*  1  1  0  0  */ (NE | NC | CS | VS | LT | LE | LS),
+       /*  1  1  0  1  */ (EQ | NC | CS | VS | LT | LE | LS),
+       /*  1  1  1  0  */ (NE | NS | CS | VS | GE | GT | LS),
+       /*  1  1  1  1  */ (EQ | NS | CS | VS | GE | LE | LS),
+};
+
+/*
+ * Calculate what the PC will be after executing next instruction
+ */
+static unsigned find_nextpc(struct pt_regs *regs, int *flags)
+{
+       unsigned size;
+       s8  x8;
+       s16 x16;
+       s32 x32;
+       u8 opc, *pc, *sp, *next;
+
+       next = 0;
+       *flags = SINGLESTEP_PCREL;
+
+       pc = (u8 *) regs->pc;
+       sp = (u8 *) (regs + 1);
+       opc = *pc;
+
+       size = mn10300_insn_sizes[opc];
+       if (size > 0) {
+               next = pc + size;
+       } else {
+               switch (opc) {
+                       /* Bxx (d8,PC) */
+               case 0xc0 ... 0xca:
+                       x8 = 2;
+                       if (cond_table[regs->epsw & 0xf] & (1 << (opc & 0xf)))
+                               x8 = (s8)pc[1];
+                       next = pc + x8;
+                       *flags |= SINGLESTEP_BRANCH;
+                       break;
+
+                       /* JMP (d16,PC) or CALL (d16,PC) */
+               case 0xcc:
+               case 0xcd:
+                       READ_WORD16(pc + 1, &x16);
+                       next = pc + x16;
+                       *flags |= SINGLESTEP_BRANCH;
+                       break;
+
+                       /* JMP (d32,PC) or CALL (d32,PC) */
+               case 0xdc:
+               case 0xdd:
+                       READ_WORD32(pc + 1, &x32);
+                       next = pc + x32;
+                       *flags |= SINGLESTEP_BRANCH;
+                       break;
+
+                       /* RETF */
+               case 0xde:
+                       next = (u8 *)regs->mdr;
+                       *flags &= ~SINGLESTEP_PCREL;
+                       *flags |= SINGLESTEP_BRANCH;
+                       break;
+
+                       /* RET */
+               case 0xdf:
+                       sp += pc[2];
+                       READ_WORD32(sp, &x32);
+                       next = (u8 *)x32;
+                       *flags &= ~SINGLESTEP_PCREL;
+                       *flags |= SINGLESTEP_BRANCH;
+                       break;
+
+               case 0xf0:
+                       next = pc + 2;
+                       opc = pc[1];
+                       if (opc >= 0xf0 && opc <= 0xf7) {
+                               /* JMP (An) / CALLS (An) */
+                               switch (opc & 3) {
+                               case 0:
+                                       next = (u8 *)regs->a0;
+                                       break;
+                               case 1:
+                                       next = (u8 *)regs->a1;
+                                       break;
+                               case 2:
+                                       next = (u8 *)regs->a2;
+                                       break;
+                               case 3:
+                                       next = (u8 *)regs->a3;
+                                       break;
+                               }
+                               *flags &= ~SINGLESTEP_PCREL;
+                               *flags |= SINGLESTEP_BRANCH;
+                       } else if (opc == 0xfc) {
+                               /* RETS */
+                               READ_WORD32(sp, &x32);
+                               next = (u8 *)x32;
+                               *flags &= ~SINGLESTEP_PCREL;
+                               *flags |= SINGLESTEP_BRANCH;
+                       } else if (opc == 0xfd) {
+                               /* RTI */
+                               READ_WORD32(sp + 4, &x32);
+                               next = (u8 *)x32;
+                               *flags &= ~SINGLESTEP_PCREL;
+                               *flags |= SINGLESTEP_BRANCH;
+                       }
+                       break;
+
+                       /* potential 3-byte conditional branches */
+               case 0xf8:
+                       next = pc + 3;
+                       opc = pc[1];
+                       if (opc >= 0xe8 && opc <= 0xeb &&
+                           (cond_table[regs->epsw & 0xf] &
+                            (1 << ((opc & 0xf) + 3)))
+                           ) {
+                               READ_BYTE(pc+2, &x8);
+                               next = pc + x8;
+                               *flags |= SINGLESTEP_BRANCH;
+                       }
+                       break;
+
+               case 0xfa:
+                       if (pc[1] == 0xff) {
+                               /* CALLS (d16,PC) */
+                               READ_WORD16(pc + 2, &x16);
+                               next = pc + x16;
+                       } else
+                               next = pc + 4;
+                       *flags |= SINGLESTEP_BRANCH;
+                       break;
+
+               case 0xfc:
+                       x32 = 6;
+                       if (pc[1] == 0xff) {
+                               /* CALLS (d32,PC) */
+                               READ_WORD32(pc + 2, &x32);
+                       }
+                       next = pc + x32;
+                       *flags |= SINGLESTEP_BRANCH;
+                       break;
+                       /* LXX (d8,PC) */
+                       /* SETLB - loads the next four bytes into the LIR reg */
+               case 0xd0 ... 0xda:
+               case 0xdb:
+                       panic("Can't singlestep Lxx/SETLB\n");
+                       break;
+               }
+       }
+       return (unsigned)next;
+
+}
+
+/*
+ * set up out of place singlestep of some branching instructions
+ */
+static unsigned __kprobes singlestep_branch_setup(struct pt_regs *regs)
+{
+       u8 opc, *pc, *sp, *next;
+
+       next = NULL;
+       pc = (u8 *) regs->pc;
+       sp = (u8 *) (regs + 1);
+
+       switch (pc[0]) {
+       case 0xc0 ... 0xca:     /* Bxx (d8,PC) */
+       case 0xcc:              /* JMP (d16,PC) */
+       case 0xdc:              /* JMP (d32,PC) */
+       case 0xf8:              /* Bxx (d8,PC)  3-byte version */
+               /* don't really need to do anything except cause trap  */
+               next = pc;
+               break;
+
+       case 0xcd:              /* CALL (d16,PC) */
+               pc[1] = 5;
+               pc[2] = 0;
+               next = pc + 5;
+               break;
+
+       case 0xdd:              /* CALL (d32,PC) */
+               pc[1] = 7;
+               pc[2] = 0;
+               pc[3] = 0;
+               pc[4] = 0;
+               next = pc + 7;
+               break;
+
+       case 0xde:              /* RETF */
+               next = pc + 3;
+               regs->mdr = (unsigned) next;
+               break;
+
+       case 0xdf:              /* RET */
+               sp += pc[2];
+               next = pc + 3;
+               *(unsigned *)sp = (unsigned) next;
+               break;
+
+       case 0xf0:
+               next = pc + 2;
+               opc = pc[1];
+               if (opc >= 0xf0 && opc <= 0xf3) {
+                       /* CALLS (An) */
+                       /* use CALLS (d16,PC) to avoid mucking with An */
+                       pc[0] = 0xfa;
+                       pc[1] = 0xff;
+                       pc[2] = 4;
+                       pc[3] = 0;
+                       next = pc + 4;
+               } else if (opc >= 0xf4 && opc <= 0xf7) {
+                       /* JMP (An) */
+                       next = pc;
+               } else if (opc == 0xfc) {
+                       /* RETS */
+                       next = pc + 2;
+                       *(unsigned *) sp = (unsigned) next;
+               } else if (opc == 0xfd) {
+                       /* RTI */
+                       next = pc + 2;
+                       *(unsigned *)(sp + 4) = (unsigned) next;
+               }
+               break;
+
+       case 0xfa:      /* CALLS (d16,PC) */
+               pc[2] = 4;
+               pc[3] = 0;
+               next = pc + 4;
+               break;
+
+       case 0xfc:      /* CALLS (d32,PC) */
+               pc[2] = 6;
+               pc[3] = 0;
+               pc[4] = 0;
+               pc[5] = 0;
+               next = pc + 6;
+               break;
+
+       case 0xd0 ... 0xda:     /* LXX (d8,PC) */
+       case 0xdb:              /* SETLB */
+               panic("Can't singlestep Lxx/SETLB\n");
+       }
+
+       return (unsigned) next;
+}
+
+int __kprobes arch_prepare_kprobe(struct kprobe *p)
+{
+       return 0;
+}
+
+void __kprobes arch_copy_kprobe(struct kprobe *p)
+{
+       memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE);
+}
+
+void __kprobes arch_arm_kprobe(struct kprobe *p)
+{
+       *p->addr = BREAKPOINT_INSTRUCTION;
+       flush_icache_range((unsigned long) p->addr,
+                          (unsigned long) p->addr + sizeof(kprobe_opcode_t));
+}
+
+void __kprobes arch_disarm_kprobe(struct kprobe *p)
+{
+       mn10300_dcache_flush();
+       mn10300_icache_inv();
+}
+
+void arch_remove_kprobe(struct kprobe *p)
+{
+}
+
+static inline
+void __kprobes disarm_kprobe(struct kprobe *p, struct pt_regs *regs)
+{
+       *p->addr = p->opcode;
+       regs->pc = (unsigned long) p->addr;
+       mn10300_dcache_flush();
+       mn10300_icache_inv();
+}
+
+static inline
+void __kprobes prepare_singlestep(struct kprobe *p, struct pt_regs *regs)
+{
+       unsigned long nextpc;
+
+       current_kprobe_orig_pc = regs->pc;
+       memcpy(current_kprobe_ss_buf, &p->ainsn.insn[0], MAX_INSN_SIZE);
+       regs->pc = (unsigned long) current_kprobe_ss_buf;
+
+       nextpc = find_nextpc(regs, &current_kprobe_ss_flags);
+       if (current_kprobe_ss_flags & SINGLESTEP_PCREL)
+               current_kprobe_next_pc =
+                       current_kprobe_orig_pc + (nextpc - regs->pc);
+       else
+               current_kprobe_next_pc = nextpc;
+
+       /* branching instructions need special handling */
+       if (current_kprobe_ss_flags & SINGLESTEP_BRANCH)
+               nextpc = singlestep_branch_setup(regs);
+
+       current_kprobe_bp_addr = nextpc;
+
+       *(u8 *) nextpc = BREAKPOINT_INSTRUCTION;
+       mn10300_dcache_flush_range2((unsigned) current_kprobe_ss_buf,
+                                   sizeof(current_kprobe_ss_buf));
+       mn10300_icache_inv();
+}
+
+static inline int __kprobes kprobe_handler(struct pt_regs *regs)
+{
+       struct kprobe *p;
+       int ret = 0;
+       unsigned int *addr = (unsigned int *) regs->pc;
+
+       /* We're in an interrupt, but this is clear and BUG()-safe. */
+       preempt_disable();
+
+       /* Check we're not actually recursing */
+       if (kprobe_running()) {
+               /* We *are* holding lock here, so this is safe.
+                  Disarm the probe we just hit, and ignore it. */
+               p = get_kprobe(addr);
+               if (p) {
+                       disarm_kprobe(p, regs);
+                       ret = 1;
+               } else {
+                       p = current_kprobe;
+                       if (p->break_handler && p->break_handler(p, regs))
+                               goto ss_probe;
+               }
+               /* If it's not ours, can't be delete race, (we hold lock). */
+               goto no_kprobe;
+       }
+
+       p = get_kprobe(addr);
+       if (!p) {
+               if (*addr != BREAKPOINT_INSTRUCTION) {
+                       /* The breakpoint instruction was removed right after
+                        * we hit it.  Another cpu has removed either a
+                        * probepoint or a debugger breakpoint at this address.
+                        * In either case, no further handling of this
+                        * interrupt is appropriate.
+                        */
+                       ret = 1;
+               }
+               /* Not one of ours: let kernel handle it */
+               goto no_kprobe;
+       }
+
+       kprobe_status = KPROBE_HIT_ACTIVE;
+       current_kprobe = p;
+       if (p->pre_handler(p, regs)) {
+               /* handler has already set things up, so skip ss setup */
+               return 1;
+       }
+
+ss_probe:
+       prepare_singlestep(p, regs);
+       kprobe_status = KPROBE_HIT_SS;
+       return 1;
+
+no_kprobe:
+       preempt_enable_no_resched();
+       return ret;
+}
+
+/*
+ * Called after single-stepping.  p->addr is the address of the
+ * instruction whose first byte has been replaced by the "breakpoint"
+ * instruction.  To avoid the SMP problems that can occur when we
+ * temporarily put back the original opcode to single-step, we
+ * single-stepped a copy of the instruction.  The address of this
+ * copy is p->ainsn.insn.
+ */
+static void __kprobes resume_execution(struct kprobe *p, struct pt_regs *regs)
+{
+       /* we may need to fixup regs/stack after singlestepping a call insn */
+       if (current_kprobe_ss_flags & SINGLESTEP_BRANCH) {
+               regs->pc = current_kprobe_orig_pc;
+               switch (p->ainsn.insn[0]) {
+               case 0xcd:      /* CALL (d16,PC) */
+                       *(unsigned *) regs->sp = regs->mdr = regs->pc + 5;
+                       break;
+               case 0xdd:      /* CALL (d32,PC) */
+                       /* fixup mdr and return address on stack */
+                       *(unsigned *) regs->sp = regs->mdr = regs->pc + 7;
+                       break;
+               case 0xf0:
+                       if (p->ainsn.insn[1] >= 0xf0 &&
+                           p->ainsn.insn[1] <= 0xf3) {
+                               /* CALLS (An) */
+                               /* fixup MDR and return address on stack */
+                               regs->mdr = regs->pc + 2;
+                               *(unsigned *) regs->sp = regs->mdr;
+                       }
+                       break;
+
+               case 0xfa:      /* CALLS (d16,PC) */
+                       /* fixup MDR and return address on stack */
+                       *(unsigned *) regs->sp = regs->mdr = regs->pc + 4;
+                       break;
+
+               case 0xfc:      /* CALLS (d32,PC) */
+                       /* fixup MDR and return address on stack */
+                       *(unsigned *) regs->sp = regs->mdr = regs->pc + 6;
+                       break;
+               }
+       }
+
+       regs->pc = current_kprobe_next_pc;
+       current_kprobe_bp_addr = 0;
+}
+
+static inline int __kprobes post_kprobe_handler(struct pt_regs *regs)
+{
+       if (!kprobe_running())
+               return 0;
+
+       if (current_kprobe->post_handler)
+               current_kprobe->post_handler(current_kprobe, regs, 0);
+
+       resume_execution(current_kprobe, regs);
+       reset_current_kprobe();
+       preempt_enable_no_resched();
+       return 1;
+}
+
+/* Interrupts disabled, kprobe_lock held. */
+static inline
+int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
+{
+       if (current_kprobe->fault_handler &&
+           current_kprobe->fault_handler(current_kprobe, regs, trapnr))
+               return 1;
+
+       if (kprobe_status & KPROBE_HIT_SS) {
+               resume_execution(current_kprobe, regs);
+               reset_current_kprobe();
+               preempt_enable_no_resched();
+       }
+       return 0;
+}
+
+/*
+ * Wrapper routine to for handling exceptions.
+ */
+int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
+                                      unsigned long val, void *data)
+{
+       struct die_args *args = data;
+
+       switch (val) {
+       case DIE_BREAKPOINT:
+               if (current_kprobe_bp_addr != args->regs->pc) {
+                       if (kprobe_handler(args->regs))
+                               return NOTIFY_STOP;
+               } else {
+                       if (post_kprobe_handler(args->regs))
+                               return NOTIFY_STOP;
+               }
+               break;
+       case DIE_GPF:
+               if (kprobe_running() &&
+                   kprobe_fault_handler(args->regs, args->trapnr))
+                       return NOTIFY_STOP;
+               break;
+       default:
+               break;
+       }
+       return NOTIFY_DONE;
+}
+
+/* Jprobes support.  */
+static struct pt_regs jprobe_saved_regs;
+static struct pt_regs *jprobe_saved_regs_location;
+static kprobe_opcode_t jprobe_saved_stack[MAX_STACK_SIZE];
+
+int __kprobes setjmp_pre_handler(struct kprobe *p, struct pt_regs *regs)
+{
+       struct jprobe *jp = container_of(p, struct jprobe, kp);
+
+       jprobe_saved_regs_location = regs;
+       memcpy(&jprobe_saved_regs, regs, sizeof(struct pt_regs));
+
+       /* Save a whole stack frame, this gets arguments
+        * pushed onto the stack after using up all the
+        * arg registers.
+        */
+       memcpy(&jprobe_saved_stack, regs + 1, sizeof(jprobe_saved_stack));
+
+       /* setup return addr to the jprobe handler routine */
+       regs->pc = (unsigned long) jp->entry;
+       return 1;
+}
+
+void __kprobes jprobe_return(void)
+{
+       void *orig_sp = jprobe_saved_regs_location + 1;
+
+       preempt_enable_no_resched();
+       asm volatile("          mov     %0,sp\n"
+                    ".globl    jprobe_return_bp_addr\n"
+                    "jprobe_return_bp_addr:\n\t"
+                    "          .byte   0xff\n"
+                    : : "d" (orig_sp));
+}
+
+extern void jprobe_return_bp_addr(void);
+
+int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
+{
+       u8 *addr = (u8 *) regs->pc;
+
+       if (addr == (u8 *) jprobe_return_bp_addr) {
+               if (jprobe_saved_regs_location != regs) {
+                       printk(KERN_ERR"JPROBE:"
+                              " Current regs (%p) does not match saved regs"
+                              " (%p).\n",
+                              regs, jprobe_saved_regs_location);
+                       BUG();
+               }
+
+               /* Restore old register state.
+                */
+               memcpy(regs, &jprobe_saved_regs, sizeof(struct pt_regs));
+
+               memcpy(regs + 1, &jprobe_saved_stack,
+                      sizeof(jprobe_saved_stack));
+               return 1;
+       }
+       return 0;
+}
+
+int __init arch_init_kprobes(void)
+{
+       return 0;
+}
diff --git a/arch/mn10300/kernel/kthread.S b/arch/mn10300/kernel/kthread.S
new file mode 100644 (file)
index 0000000..b5ae467
--- /dev/null
@@ -0,0 +1,31 @@
+/* MN10300 Kernel thread trampoline function
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by Mark Salter (msalter@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+       .text
+
+###############################################################################
+#
+# kernel_thread_helper - trampoline for kernel_thread()
+#
+# On entry:
+#   A2 = address of function to call
+#   D2 = function argument
+#
+###############################################################################
+       .globl  kernel_thread_helper
+       .type   kernel_thread_helper,@function
+kernel_thread_helper:
+       mov     do_exit,d1
+       mov     d1,(sp)
+       mov     d1,mdr
+       mov     d2,d0
+       jmp     (a2)
+
+       .size   kernel_thread_helper,.-kernel_thread_helper
diff --git a/arch/mn10300/kernel/mn10300-debug.c b/arch/mn10300/kernel/mn10300-debug.c
new file mode 100644 (file)
index 0000000..bd81964
--- /dev/null
@@ -0,0 +1,58 @@
+/* Debugging stuff for the MN10300-based processors
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/sched.h>
+#include <asm/serial-regs.h>
+
+#undef MN10300_CONSOLE_ON_SERIO
+
+/*
+ * write a string directly through one of the serial ports on-board the MN10300
+ */
+#ifdef MN10300_CONSOLE_ON_SERIO
+void debug_to_serial_mnser(const char *p, int n)
+{
+       char ch;
+
+       for (; n > 0; n--) {
+               ch = *p++;
+
+#if MN10300_CONSOLE_ON_SERIO == 0
+               while (SC0STR & (SC01STR_TBF)) continue;
+               SC0TXB = ch;
+               while (SC0STR & (SC01STR_TBF)) continue;
+               if (ch == 0x0a) {
+                       SC0TXB = 0x0d;
+                       while (SC0STR & (SC01STR_TBF)) continue;
+               }
+
+#elif MN10300_CONSOLE_ON_SERIO == 1
+               while (SC1STR & (SC01STR_TBF)) continue;
+               SC1TXB = ch;
+               while (SC1STR & (SC01STR_TBF)) continue;
+               if (ch == 0x0a) {
+                       SC1TXB = 0x0d;
+                       while (SC1STR & (SC01STR_TBF)) continue;
+               }
+
+#elif MN10300_CONSOLE_ON_SERIO == 2
+               while (SC2STR & (SC2STR_TBF)) continue;
+               SC2TXB = ch;
+               while (SC2STR & (SC2STR_TBF)) continue;
+               if (ch == 0x0a) {
+                       SC2TXB = 0x0d;
+                       while (SC2STR & (SC2STR_TBF)) continue;
+               }
+
+#endif
+       }
+}
+#endif
+
diff --git a/arch/mn10300/kernel/mn10300-serial-low.S b/arch/mn10300/kernel/mn10300-serial-low.S
new file mode 100644 (file)
index 0000000..ef3f4c1
--- /dev/null
@@ -0,0 +1,191 @@
+###############################################################################
+#
+# Virtual DMA driver for MN10300 serial ports
+#
+# Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+# Written by David Howells (dhowells@redhat.com)
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public Licence
+# as published by the Free Software Foundation; either version
+# 2 of the Licence, or (at your option) any later version.
+#
+###############################################################################
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/page.h>
+#include <asm/smp.h>
+#include <asm/cpu-regs.h>
+#include <asm/frame.inc>
+#include <asm/timer-regs.h>
+#include <asm/proc/cache.h>
+#include <asm/unit/timex.h>
+#include "mn10300-serial.h"
+
+#define        SCxCTR  0x00
+#define        SCxICR  0x04
+#define        SCxTXB  0x08
+#define        SCxRXB  0x09
+#define        SCxSTR  0x0c
+#define        SCxTIM  0x0d
+
+       .text
+
+###############################################################################
+#
+# serial port interrupt virtual DMA entry point
+# - intended to run at interrupt priority 1 (not affected by local_irq_disable)
+#
+###############################################################################
+       .balign L1_CACHE_BYTES
+ENTRY(mn10300_serial_vdma_interrupt)
+       or      EPSW_IE,psw                     # permit overriding by
+                                               # debugging interrupts
+       movm    [d2,d3,a2,a3,exreg0],(sp)
+
+       movhu   (IAGR),a2                       # see if which interrupt is
+                                               # pending
+       and     IAGR_GN,a2
+       add     a2,a2
+       add     mn10300_serial_int_tbl,a2
+
+       mov     (a2+),a3
+       mov     (__iobase,a3),e2
+       mov     (a2),a2
+       jmp     (a2)
+
+###############################################################################
+#
+# serial port receive interrupt virtual DMA entry point
+# - intended to run at interrupt priority 1 (not affected by local_irq_disable)
+# - stores data/status byte pairs in the ring buffer
+# - induces a scheduler tick timer interrupt when done, which we then subvert
+# on entry:
+#      A3      struct mn10300_serial_port *
+#      E2      I/O port base
+#
+###############################################################################
+ENTRY(mn10300_serial_vdma_rx_handler)
+       mov     (__rx_icr,a3),e3
+       mov     GxICR_DETECT,d2
+       movbu   d2,(e3)                         # ACK the interrupt
+       movhu   (e3),d2                         # flush
+
+       mov     (__rx_inp,a3),d3
+       mov     d3,a2
+       add     2,d3
+       and     MNSC_BUFFER_SIZE-1,d3
+       mov     (__rx_outp,a3),d2
+       cmp     d3,d2
+       beq     mnsc_vdma_rx_overflow
+
+       mov     (__rx_buffer,a3),d2
+       add     d2,a2
+       movhu   (SCxSTR,e2),d2
+       movbu   d2,(1,a2)
+       movbu   (SCxRXB,e2),d2
+       movbu   d2,(a2)
+       mov     d3,(__rx_inp,a3)
+       bset    MNSCx_RX_AVAIL,(__intr_flags,a3)
+
+mnsc_vdma_rx_done:
+       mov     (__tm_icr,a3),a2
+       mov     GxICR_LEVEL_6|GxICR_ENABLE|GxICR_REQUEST|GxICR_DETECT,d2
+       movhu   d2,(a2)                         # request a slow interrupt
+       movhu   (a2),d2                         # flush
+
+       movm    (sp),[d2,d3,a2,a3,exreg0]
+       rti
+
+mnsc_vdma_rx_overflow:
+       bset    MNSCx_RX_OVERF,(__intr_flags,a3)
+       bra     mnsc_vdma_rx_done
+
+###############################################################################
+#
+# serial port transmit interrupt virtual DMA entry point
+# - intended to run at interrupt priority 1 (not affected by local_irq_disable)
+# - retrieves data bytes from the ring buffer and passes them to the serial port
+# - induces a scheduler tick timer interrupt when done, which we then subvert
+#      A3      struct mn10300_serial_port *
+#      E2      I/O port base
+#
+###############################################################################
+       .balign L1_CACHE_BYTES
+ENTRY(mn10300_serial_vdma_tx_handler)
+       mov     (__tx_icr,a3),e3
+       mov     GxICR_DETECT,d2
+       movbu   d2,(e3)                 # ACK the interrupt
+       movhu   (e3),d2                 # flush
+
+       btst    0x01,(__tx_break,a3)    # handle transmit break request
+       bne     mnsc_vdma_tx_break
+
+       movbu   (SCxSTR,e2),d2          # don't try and transmit a char if the
+                                       # buffer is not empty
+       btst    SC01STR_TBF,d2          # (may have tried to jumpstart)
+       bne     mnsc_vdma_tx_noint
+
+       movbu   (__tx_xchar,a3),d2      # handle hi-pri XON/XOFF
+       or      d2,d2
+       bne     mnsc_vdma_tx_xchar
+
+       mov     (__tx_info_buffer,a3),a2 # get the uart_info struct for Tx
+       mov     (__xmit_tail,a2),d3
+       mov     (__xmit_head,a2),d2
+       cmp     d3,d2
+       beq     mnsc_vdma_tx_empty
+
+       mov     (__xmit_buffer,a2),d2   # get a char from the buffer and
+                                       # transmit it
+       movbu   (d3,d2),d2
+       movbu   d2,(SCxTXB,e2)          # Tx
+
+       inc     d3                      # advance the buffer pointer
+       and     __UART_XMIT_SIZE-1,d3
+       mov     (__xmit_head,a2),d2
+       mov     d3,(__xmit_tail,a2)
+
+       sub     d3,d2                   # see if we've written everything
+       beq     mnsc_vdma_tx_empty
+
+       and     __UART_XMIT_SIZE-1,d2   # see if we just made a hole
+       cmp     __UART_XMIT_SIZE-2,d2
+       beq     mnsc_vdma_tx_made_hole
+
+mnsc_vdma_tx_done:
+       mov     (__tm_icr,a3),a2
+       mov     GxICR_LEVEL_6|GxICR_ENABLE|GxICR_REQUEST|GxICR_DETECT,d2
+       movhu   d2,(a2)                 # request a slow interrupt
+       movhu   (a2),d2                 # flush
+
+mnsc_vdma_tx_noint:
+       movm    (sp),[d2,d3,a2,a3,exreg0]
+       rti
+
+mnsc_vdma_tx_empty:
+       mov     +(GxICR_LEVEL_1|GxICR_DETECT),d2
+       movhu   d2,(e3)                 # disable the interrupt
+       movhu   (e3),d2                 # flush
+
+       bset    MNSCx_TX_EMPTY,(__intr_flags,a3)
+       bra     mnsc_vdma_tx_done
+
+mnsc_vdma_tx_break:
+       movhu   (SCxCTR,e2),d2          # turn on break mode
+       or      SC01CTR_BKE,d2
+       movhu   d2,(SCxCTR,e2)
+       mov     +(GxICR_LEVEL_1|GxICR_DETECT),d2
+       movhu   d2,(e3)                 # disable transmit interrupts on this
+                                       # channel
+       movhu   (e3),d2                 # flush
+       bra     mnsc_vdma_tx_noint
+
+mnsc_vdma_tx_xchar:
+       bclr    0xff,(__tx_xchar,a3)
+       movbu   d2,(SCxTXB,e2)
+       bra     mnsc_vdma_tx_done
+
+mnsc_vdma_tx_made_hole:
+       bset    MNSCx_TX_SPACE,(__intr_flags,a3)
+       bra     mnsc_vdma_tx_done
diff --git a/arch/mn10300/kernel/mn10300-serial.c b/arch/mn10300/kernel/mn10300-serial.c
new file mode 100644 (file)
index 0000000..b9c268c
--- /dev/null
@@ -0,0 +1,1480 @@
+/* MN10300 On-chip serial port UART driver
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+static const char serial_name[] = "MN10300 Serial driver";
+static const char serial_version[] = "mn10300_serial-1.0";
+static const char serial_revdate[] = "2007-11-06";
+
+#if defined(CONFIG_MN10300_TTYSM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
+#define SUPPORT_SYSRQ
+#endif
+
+#include <linux/version.h>
+#include <linux/module.h>
+#include <linux/serial.h>
+#include <linux/circ_buf.h>
+#include <linux/errno.h>
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/timer.h>
+#include <linux/interrupt.h>
+#include <linux/tty.h>
+#include <linux/tty_flip.h>
+#include <linux/major.h>
+#include <linux/string.h>
+#include <linux/ioport.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/console.h>
+#include <linux/sysrq.h>
+
+#include <asm/system.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/bitops.h>
+#include <asm/serial-regs.h>
+#include <asm/unit/timex.h>
+#include "mn10300-serial.h"
+
+static inline __attribute__((format(printf, 1, 2)))
+void no_printk(const char *fmt, ...)
+{
+}
+
+#define kenter(FMT, ...) \
+       printk(KERN_DEBUG "-->%s(" FMT ")\n", __func__, ##__VA_ARGS__)
+#define _enter(FMT, ...) \
+       no_printk(KERN_DEBUG "-->%s(" FMT ")\n", __func__, ##__VA_ARGS__)
+#define kdebug(FMT, ...) \
+       printk(KERN_DEBUG "--- " FMT "\n", ##__VA_ARGS__)
+#define _debug(FMT, ...) \
+       no_printk(KERN_DEBUG "--- " FMT "\n", ##__VA_ARGS__)
+#define kproto(FMT, ...) \
+       printk(KERN_DEBUG "### MNSERIAL " FMT " ###\n", ##__VA_ARGS__)
+#define _proto(FMT, ...) \
+       no_printk(KERN_DEBUG "### MNSERIAL " FMT " ###\n", ##__VA_ARGS__)
+
+#define NR_UARTS 3
+
+#ifdef CONFIG_MN10300_TTYSM_CONSOLE
+static void mn10300_serial_console_write(struct console *co,
+                                          const char *s, unsigned count);
+static int __init mn10300_serial_console_setup(struct console *co,
+                                                char *options);
+
+static struct uart_driver mn10300_serial_driver;
+static struct console mn10300_serial_console = {
+       .name           = "ttySM",
+       .write          = mn10300_serial_console_write,
+       .device         = uart_console_device,
+       .setup          = mn10300_serial_console_setup,
+       .flags          = CON_PRINTBUFFER,
+       .index          = -1,
+       .data           = &mn10300_serial_driver,
+};
+#endif
+
+static struct uart_driver mn10300_serial_driver = {
+       .owner          = NULL,
+       .driver_name    = "mn10300-serial",
+       .dev_name       = "ttySM",
+       .major          = TTY_MAJOR,
+       .minor          = 128,
+       .nr             = NR_UARTS,
+#ifdef CONFIG_MN10300_TTYSM_CONSOLE
+       .cons           = &mn10300_serial_console,
+#endif
+};
+
+static unsigned int mn10300_serial_tx_empty(struct uart_port *);
+static void mn10300_serial_set_mctrl(struct uart_port *, unsigned int mctrl);
+static unsigned int mn10300_serial_get_mctrl(struct uart_port *);
+static void mn10300_serial_stop_tx(struct uart_port *);
+static void mn10300_serial_start_tx(struct uart_port *);
+static void mn10300_serial_send_xchar(struct uart_port *, char ch);
+static void mn10300_serial_stop_rx(struct uart_port *);
+static void mn10300_serial_enable_ms(struct uart_port *);
+static void mn10300_serial_break_ctl(struct uart_port *, int ctl);
+static int mn10300_serial_startup(struct uart_port *);
+static void mn10300_serial_shutdown(struct uart_port *);
+static void mn10300_serial_set_termios(struct uart_port *,
+                                        struct ktermios *new,
+                                        struct ktermios *old);
+static const char *mn10300_serial_type(struct uart_port *);
+static void mn10300_serial_release_port(struct uart_port *);
+static int mn10300_serial_request_port(struct uart_port *);
+static void mn10300_serial_config_port(struct uart_port *, int);
+static int mn10300_serial_verify_port(struct uart_port *,
+                                       struct serial_struct *);
+
+static const struct uart_ops mn10300_serial_ops = {
+       .tx_empty       = mn10300_serial_tx_empty,
+       .set_mctrl      = mn10300_serial_set_mctrl,
+       .get_mctrl      = mn10300_serial_get_mctrl,
+       .stop_tx        = mn10300_serial_stop_tx,
+       .start_tx       = mn10300_serial_start_tx,
+       .send_xchar     = mn10300_serial_send_xchar,
+       .stop_rx        = mn10300_serial_stop_rx,
+       .enable_ms      = mn10300_serial_enable_ms,
+       .break_ctl      = mn10300_serial_break_ctl,
+       .startup        = mn10300_serial_startup,
+       .shutdown       = mn10300_serial_shutdown,
+       .set_termios    = mn10300_serial_set_termios,
+       .type           = mn10300_serial_type,
+       .release_port   = mn10300_serial_release_port,
+       .request_port   = mn10300_serial_request_port,
+       .config_port    = mn10300_serial_config_port,
+       .verify_port    = mn10300_serial_verify_port,
+};
+
+static irqreturn_t mn10300_serial_interrupt(int irq, void *dev_id);
+
+/*
+ * the first on-chip serial port: ttySM0 (aka SIF0)
+ */
+#ifdef CONFIG_MN10300_TTYSM0
+struct mn10300_serial_port mn10300_serial_port_sif0 = {
+       .uart.ops       = &mn10300_serial_ops,
+       .uart.membase   = (void __iomem *) &SC0CTR,
+       .uart.mapbase   = (unsigned long) &SC0CTR,
+       .uart.iotype    = UPIO_MEM,
+       .uart.irq       = 0,
+       .uart.uartclk   = 0, /* MN10300_IOCLK, */
+       .uart.fifosize  = 1,
+       .uart.flags     = UPF_BOOT_AUTOCONF,
+       .uart.line      = 0,
+       .uart.type      = PORT_MN10300,
+       .uart.lock      =
+       __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif0.uart.lock),
+       .name           = "ttySM0",
+       ._iobase        = &SC0CTR,
+       ._control       = &SC0CTR,
+       ._status        = (volatile u8 *) &SC0STR,
+       ._intr          = &SC0ICR,
+       ._rxb           = &SC0RXB,
+       ._txb           = &SC0TXB,
+       .rx_name        = "ttySM0/Rx",
+       .tx_name        = "ttySM0/Tx",
+#ifdef CONFIG_MN10300_TTYSM0_TIMER8
+       .tm_name        = "ttySM0/Timer8",
+       ._tmxmd         = &TM8MD,
+       ._tmxbr         = &TM8BR,
+       ._tmicr         = &TM8ICR,
+       .tm_irq         = TM8IRQ,
+       .div_timer      = MNSCx_DIV_TIMER_16BIT,
+#else /* CONFIG_MN10300_TTYSM0_TIMER2 */
+       .tm_name        = "ttySM0/Timer2",
+       ._tmxmd         = &TM2MD,
+       ._tmxbr         = (volatile u16 *) &TM2BR,
+       ._tmicr         = &TM2ICR,
+       .tm_irq         = TM2IRQ,
+       .div_timer      = MNSCx_DIV_TIMER_8BIT,
+#endif
+       .rx_irq         = SC0RXIRQ,
+       .tx_irq         = SC0TXIRQ,
+       .rx_icr         = &GxICR(SC0RXIRQ),
+       .tx_icr         = &GxICR(SC0TXIRQ),
+       .clock_src      = MNSCx_CLOCK_SRC_IOCLK,
+       .options        = 0,
+#ifdef CONFIG_GDBSTUB_ON_TTYSM0
+       .gdbstub        = 1,
+#endif
+};
+#endif /* CONFIG_MN10300_TTYSM0 */
+
+/*
+ * the second on-chip serial port: ttySM1 (aka SIF1)
+ */
+#ifdef CONFIG_MN10300_TTYSM1
+struct mn10300_serial_port mn10300_serial_port_sif1 = {
+       .uart.ops       = &mn10300_serial_ops,
+       .uart.membase   = (void __iomem *) &SC1CTR,
+       .uart.mapbase   = (unsigned long) &SC1CTR,
+       .uart.iotype    = UPIO_MEM,
+       .uart.irq       = 0,
+       .uart.uartclk   = 0, /* MN10300_IOCLK, */
+       .uart.fifosize  = 1,
+       .uart.flags     = UPF_BOOT_AUTOCONF,
+       .uart.line      = 1,
+       .uart.type      = PORT_MN10300,
+       .uart.lock      =
+       __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif1.uart.lock),
+       .name           = "ttySM1",
+       ._iobase        = &SC1CTR,
+       ._control       = &SC1CTR,
+       ._status        = (volatile u8 *) &SC1STR,
+       ._intr          = &SC1ICR,
+       ._rxb           = &SC1RXB,
+       ._txb           = &SC1TXB,
+       .rx_name        = "ttySM1/Rx",
+       .tx_name        = "ttySM1/Tx",
+#ifdef CONFIG_MN10300_TTYSM1_TIMER9
+       .tm_name        = "ttySM1/Timer9",
+       ._tmxmd         = &TM9MD,
+       ._tmxbr         = &TM9BR,
+       ._tmicr         = &TM9ICR,
+       .tm_irq         = TM9IRQ,
+       .div_timer      = MNSCx_DIV_TIMER_16BIT,
+#else /* CONFIG_MN10300_TTYSM1_TIMER3 */
+       .tm_name        = "ttySM1/Timer3",
+       ._tmxmd         = &TM3MD,
+       ._tmxbr         = (volatile u16 *) &TM3BR,
+       ._tmicr         = &TM3ICR,
+       .tm_irq         = TM3IRQ,
+       .div_timer      = MNSCx_DIV_TIMER_8BIT,
+#endif
+       .rx_irq         = SC1RXIRQ,
+       .tx_irq         = SC1TXIRQ,
+       .rx_icr         = &GxICR(SC1RXIRQ),
+       .tx_icr         = &GxICR(SC1TXIRQ),
+       .clock_src      = MNSCx_CLOCK_SRC_IOCLK,
+       .options        = 0,
+#ifdef CONFIG_GDBSTUB_ON_TTYSM1
+       .gdbstub        = 1,
+#endif
+};
+#endif /* CONFIG_MN10300_TTYSM1 */
+
+/*
+ * the third on-chip serial port: ttySM2 (aka SIF2)
+ */
+#ifdef CONFIG_MN10300_TTYSM2
+struct mn10300_serial_port mn10300_serial_port_sif2 = {
+       .uart.ops       = &mn10300_serial_ops,
+       .uart.membase   = (void __iomem *) &SC2CTR,
+       .uart.mapbase   = (unsigned long) &SC2CTR,
+       .uart.iotype    = UPIO_MEM,
+       .uart.irq       = 0,
+       .uart.uartclk   = 0, /* MN10300_IOCLK, */
+       .uart.fifosize  = 1,
+       .uart.flags     = UPF_BOOT_AUTOCONF,
+       .uart.line      = 2,
+#ifdef CONFIG_MN10300_TTYSM2_CTS
+       .uart.type      = PORT_MN10300_CTS,
+#else
+       .uart.type      = PORT_MN10300,
+#endif
+       .uart.lock      =
+       __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif2.uart.lock),
+       .name           = "ttySM2",
+       .rx_name        = "ttySM2/Rx",
+       .tx_name        = "ttySM2/Tx",
+       .tm_name        = "ttySM2/Timer10",
+       ._iobase        = &SC2CTR,
+       ._control       = &SC2CTR,
+       ._status        = &SC2STR,
+       ._intr          = &SC2ICR,
+       ._rxb           = &SC2RXB,
+       ._txb           = &SC2TXB,
+       ._tmxmd         = &TM10MD,
+       ._tmxbr         = &TM10BR,
+       ._tmicr         = &TM10ICR,
+       .tm_irq         = TM10IRQ,
+       .div_timer      = MNSCx_DIV_TIMER_16BIT,
+       .rx_irq         = SC2RXIRQ,
+       .tx_irq         = SC2TXIRQ,
+       .rx_icr         = &GxICR(SC2RXIRQ),
+       .tx_icr         = &GxICR(SC2TXIRQ),
+       .clock_src      = MNSCx_CLOCK_SRC_IOCLK,
+#ifdef CONFIG_MN10300_TTYSM2_CTS
+       .options        = MNSCx_OPT_CTS,
+#else
+       .options        = 0,
+#endif
+#ifdef CONFIG_GDBSTUB_ON_TTYSM2
+       .gdbstub        = 1,
+#endif
+};
+#endif /* CONFIG_MN10300_TTYSM2 */
+
+
+/*
+ * list of available serial ports
+ */
+struct mn10300_serial_port *mn10300_serial_ports[NR_UARTS + 1] = {
+#ifdef CONFIG_MN10300_TTYSM0
+       [0]     = &mn10300_serial_port_sif0,
+#endif
+#ifdef CONFIG_MN10300_TTYSM1
+       [1]     = &mn10300_serial_port_sif1,
+#endif
+#ifdef CONFIG_MN10300_TTYSM2
+       [2]     = &mn10300_serial_port_sif2,
+#endif
+       [NR_UARTS] = NULL,
+};
+
+
+/*
+ * we abuse the serial ports' baud timers' interrupt lines to get the ability
+ * to deliver interrupts to userspace as we use the ports' interrupt lines to
+ * do virtual DMA on account of the ports having no hardware FIFOs
+ *
+ * we can generate an interrupt manually in the assembly stubs by writing to
+ * the enable and detect bits in the interrupt control register, so all we need
+ * to do here is disable the interrupt line
+ *
+ * note that we can't just leave the line enabled as the baud rate timer *also*
+ * generates interrupts
+ */
+static void mn10300_serial_mask_ack(unsigned int irq)
+{
+       u16 tmp;
+       GxICR(irq) = GxICR_LEVEL_6;
+       tmp = GxICR(irq); /* flush write buffer */
+}
+
+static void mn10300_serial_nop(unsigned int irq)
+{
+}
+
+static struct irq_chip mn10300_serial_pic = {
+       .name           = "mnserial",
+       .ack            = mn10300_serial_mask_ack,
+       .mask           = mn10300_serial_mask_ack,
+       .mask_ack       = mn10300_serial_mask_ack,
+       .unmask         = mn10300_serial_nop,
+       .end            = mn10300_serial_nop,
+};
+
+
+/*
+ * serial virtual DMA interrupt jump table
+ */
+struct mn10300_serial_int mn10300_serial_int_tbl[NR_IRQS];
+
+static void mn10300_serial_dis_tx_intr(struct mn10300_serial_port *port)
+{
+       u16 x;
+       *port->tx_icr = GxICR_LEVEL_1 | GxICR_DETECT;
+       x = *port->tx_icr;
+}
+
+static void mn10300_serial_en_tx_intr(struct mn10300_serial_port *port)
+{
+       u16 x;
+       *port->tx_icr = GxICR_LEVEL_1 | GxICR_ENABLE;
+       x = *port->tx_icr;
+}
+
+static void mn10300_serial_dis_rx_intr(struct mn10300_serial_port *port)
+{
+       u16 x;
+       *port->rx_icr = GxICR_LEVEL_1 | GxICR_DETECT;
+       x = *port->rx_icr;
+}
+
+/*
+ * multi-bit equivalent of test_and_clear_bit()
+ */
+static int mask_test_and_clear(volatile u8 *ptr, u8 mask)
+{
+       u32 epsw;
+       asm volatile("  bclr    %1,(%2)         \n"
+                    "  mov     epsw,%0         \n"
+                    : "=d"(epsw) : "d"(mask), "a"(ptr));
+       return !(epsw & EPSW_FLAG_Z);
+}
+
+/*
+ * receive chars from the ring buffer for this serial port
+ * - must do break detection here (not done in the UART)
+ */
+static void mn10300_serial_receive_interrupt(struct mn10300_serial_port *port)
+{
+       struct uart_icount *icount = &port->uart.icount;
+       struct tty_struct *tty = port->uart.info->tty;
+       unsigned ix;
+       int count;
+       u8 st, ch, push, status, overrun;
+
+       _enter("%s", port->name);
+
+       push = 0;
+
+       count = CIRC_CNT(port->rx_inp, port->rx_outp, MNSC_BUFFER_SIZE);
+       count = tty_buffer_request_room(tty, count);
+       if (count == 0) {
+               if (!tty->low_latency)
+                       tty_flip_buffer_push(tty);
+               return;
+       }
+
+try_again:
+       /* pull chars out of the hat */
+       ix = port->rx_outp;
+       if (ix == port->rx_inp) {
+               if (push && !tty->low_latency)
+                       tty_flip_buffer_push(tty);
+               return;
+       }
+
+       ch = port->rx_buffer[ix++];
+       st = port->rx_buffer[ix++];
+       smp_rmb();
+       port->rx_outp = ix & (MNSC_BUFFER_SIZE - 1);
+       port->uart.icount.rx++;
+
+       st &= SC01STR_FEF | SC01STR_PEF | SC01STR_OEF;
+       status = 0;
+       overrun = 0;
+
+       /* the UART doesn't detect BREAK, so we have to do that ourselves
+        * - it starts as a framing error on a NUL character
+        * - then we count another two NUL characters before issuing TTY_BREAK
+        * - then we end on a normal char or one that has all the bottom bits
+        *   zero and the top bits set
+        */
+       switch (port->rx_brk) {
+       case 0:
+               /* not breaking at the moment */
+               break;
+
+       case 1:
+               if (st & SC01STR_FEF && ch == 0) {
+                       port->rx_brk = 2;
+                       goto try_again;
+               }
+               goto not_break;
+
+       case 2:
+               if (st & SC01STR_FEF && ch == 0) {
+                       port->rx_brk = 3;
+                       _proto("Rx Break Detected");
+                       icount->brk++;
+                       if (uart_handle_break(&port->uart))
+                               goto ignore_char;
+                       status |= 1 << TTY_BREAK;
+                       goto insert;
+               }
+               goto not_break;
+
+       default:
+               if (st & (SC01STR_FEF | SC01STR_PEF | SC01STR_OEF))
+                       goto try_again; /* still breaking */
+
+               port->rx_brk = 0; /* end of the break */
+
+               switch (ch) {
+               case 0xFF:
+               case 0xFE:
+               case 0xFC:
+               case 0xF8:
+               case 0xF0:
+               case 0xE0:
+               case 0xC0:
+               case 0x80:
+               case 0x00:
+                       /* discard char at probable break end */
+                       goto try_again;
+               }
+               break;
+       }
+
+process_errors:
+       /* handle framing error */
+       if (st & SC01STR_FEF) {
+               if (ch == 0) {
+                       /* framing error with NUL char is probably a BREAK */
+                       port->rx_brk = 1;
+                       goto try_again;
+               }
+
+               _proto("Rx Framing Error");
+               icount->frame++;
+               status |= 1 << TTY_FRAME;
+       }
+
+       /* handle parity error */
+       if (st & SC01STR_PEF) {
+               _proto("Rx Parity Error");
+               icount->parity++;
+               status = TTY_PARITY;
+       }
+
+       /* handle normal char */
+       if (status == 0) {
+               if (uart_handle_sysrq_char(&port->uart, ch))
+                       goto ignore_char;
+               status = (1 << TTY_NORMAL);
+       }
+
+       /* handle overrun error */
+       if (st & SC01STR_OEF) {
+               if (port->rx_brk)
+                       goto try_again;
+
+               _proto("Rx Overrun Error");
+               icount->overrun++;
+               overrun = 1;
+       }
+
+insert:
+       status &= port->uart.read_status_mask;
+
+       if (!overrun && !(status & port->uart.ignore_status_mask)) {
+               int flag;
+
+               if (status & (1 << TTY_BREAK))
+                       flag = TTY_BREAK;
+               else if (status & (1 << TTY_PARITY))
+                       flag = TTY_PARITY;
+               else if (status & (1 << TTY_FRAME))
+                       flag = TTY_FRAME;
+               else
+                       flag = TTY_NORMAL;
+
+               tty_insert_flip_char(tty, ch, flag);
+       }
+
+       /* overrun is special, since it's reported immediately, and doesn't
+        * affect the current character
+        */
+       if (overrun)
+               tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+
+       count--;
+       if (count <= 0) {
+               if (!tty->low_latency)
+                       tty_flip_buffer_push(tty);
+               return;
+       }
+
+ignore_char:
+       push = 1;
+       goto try_again;
+
+not_break:
+       port->rx_brk = 0;
+       goto process_errors;
+}
+
+/*
+ * handle an interrupt from the serial transmission "virtual DMA" driver
+ * - note: the interrupt routine will disable its own interrupts when the Tx
+ *   buffer is empty
+ */
+static void mn10300_serial_transmit_interrupt(struct mn10300_serial_port *port)
+{
+       _enter("%s", port->name);
+
+       if (uart_tx_stopped(&port->uart) ||
+           uart_circ_empty(&port->uart.info->xmit))
+               mn10300_serial_dis_tx_intr(port);
+
+       if (uart_circ_chars_pending(&port->uart.info->xmit) < WAKEUP_CHARS)
+               uart_write_wakeup(&port->uart);
+}
+
+/*
+ * deal with a change in the status of the CTS line
+ */
+static void mn10300_serial_cts_changed(struct mn10300_serial_port *port, u8 st)
+{
+       u16 ctr;
+
+       port->tx_cts = st;
+       port->uart.icount.cts++;
+
+       /* flip the CTS state selector flag to interrupt when it changes
+        * back */
+       ctr = *port->_control;
+       ctr ^= SC2CTR_TWS;
+       *port->_control = ctr;
+
+       uart_handle_cts_change(&port->uart, st & SC2STR_CTS);
+       wake_up_interruptible(&port->uart.info->delta_msr_wait);
+}
+
+/*
+ * handle a virtual interrupt generated by the lower level "virtual DMA"
+ * routines (irq is the baud timer interrupt)
+ */
+static irqreturn_t mn10300_serial_interrupt(int irq, void *dev_id)
+{
+       struct mn10300_serial_port *port = dev_id;
+       u8 st;
+
+       spin_lock(&port->uart.lock);
+
+       if (port->intr_flags) {
+               _debug("INT %s: %x", port->name, port->intr_flags);
+
+               if (mask_test_and_clear(&port->intr_flags, MNSCx_RX_AVAIL))
+                       mn10300_serial_receive_interrupt(port);
+
+               if (mask_test_and_clear(&port->intr_flags,
+                                       MNSCx_TX_SPACE | MNSCx_TX_EMPTY))
+                       mn10300_serial_transmit_interrupt(port);
+       }
+
+       /* the only modem control line amongst the whole lot is CTS on
+        * serial port 2 */
+       if (port->type == PORT_MN10300_CTS) {
+               st = *port->_status;
+               if ((port->tx_cts ^ st) & SC2STR_CTS)
+                       mn10300_serial_cts_changed(port, st);
+       }
+
+       spin_unlock(&port->uart.lock);
+
+       return IRQ_HANDLED;
+}
+
+/*
+ * return indication of whether the hardware transmit buffer is empty
+ */
+static unsigned int mn10300_serial_tx_empty(struct uart_port *_port)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       _enter("%s", port->name);
+
+       return (*port->_status & (SC01STR_TXF | SC01STR_TBF)) ?
+               0 : TIOCSER_TEMT;
+}
+
+/*
+ * set the modem control lines (we don't have any)
+ */
+static void mn10300_serial_set_mctrl(struct uart_port *_port,
+                                    unsigned int mctrl)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       _enter("%s,%x", port->name, mctrl);
+}
+
+/*
+ * get the modem control line statuses
+ */
+static unsigned int mn10300_serial_get_mctrl(struct uart_port *_port)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       _enter("%s", port->name);
+
+       if (port->type == PORT_MN10300_CTS && !(*port->_status & SC2STR_CTS))
+               return TIOCM_CAR | TIOCM_DSR;
+
+       return TIOCM_CAR | TIOCM_CTS | TIOCM_DSR;
+}
+
+/*
+ * stop transmitting characters
+ */
+static void mn10300_serial_stop_tx(struct uart_port *_port)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       _enter("%s", port->name);
+
+       /* disable the virtual DMA */
+       mn10300_serial_dis_tx_intr(port);
+}
+
+/*
+ * start transmitting characters
+ * - jump-start transmission if it has stalled
+ *   - enable the serial Tx interrupt (used by the virtual DMA controller)
+ *   - force an interrupt to happen if necessary
+ */
+static void mn10300_serial_start_tx(struct uart_port *_port)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       u16 x;
+
+       _enter("%s{%lu}",
+              port->name,
+              CIRC_CNT(&port->uart.info->xmit.head,
+                       &port->uart.info->xmit.tail,
+                       UART_XMIT_SIZE));
+
+       /* kick the virtual DMA controller */
+       x = *port->tx_icr;
+       x |= GxICR_ENABLE;
+
+       if (*port->_status & SC01STR_TBF)
+               x &= ~(GxICR_REQUEST | GxICR_DETECT);
+       else
+               x |= GxICR_REQUEST | GxICR_DETECT;
+
+       _debug("CTR=%04hx ICR=%02hx STR=%04x TMD=%02hx TBR=%04hx ICR=%04hx",
+              *port->_control, *port->_intr, *port->_status,
+              *port->_tmxmd, *port->_tmxbr, *port->tx_icr);
+
+       *port->tx_icr = x;
+       x = *port->tx_icr;
+}
+
+/*
+ * transmit a high-priority XON/XOFF character
+ */
+static void mn10300_serial_send_xchar(struct uart_port *_port, char ch)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       _enter("%s,%02x", port->name, ch);
+
+       if (likely(port->gdbstub)) {
+               port->tx_xchar = ch;
+               if (ch)
+                       mn10300_serial_en_tx_intr(port);
+       }
+}
+
+/*
+ * stop receiving characters
+ * - called whilst the port is being closed
+ */
+static void mn10300_serial_stop_rx(struct uart_port *_port)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       u16 ctr;
+
+       _enter("%s", port->name);
+
+       ctr = *port->_control;
+       ctr &= ~SC01CTR_RXE;
+       *port->_control = ctr;
+
+       mn10300_serial_dis_rx_intr(port);
+}
+
+/*
+ * enable modem status interrupts
+ */
+static void mn10300_serial_enable_ms(struct uart_port *_port)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       u16 ctr, cts;
+
+       _enter("%s", port->name);
+
+       if (port->type == PORT_MN10300_CTS) {
+               /* want to interrupt when CTS goes low if CTS is now high and
+                * vice versa
+                */
+               port->tx_cts = *port->_status;
+
+               cts = (port->tx_cts & SC2STR_CTS) ?
+                       SC2CTR_TWE : SC2CTR_TWE | SC2CTR_TWS;
+
+               ctr = *port->_control;
+               ctr &= ~SC2CTR_TWS;
+               ctr |= cts;
+               *port->_control = ctr;
+
+               mn10300_serial_en_tx_intr(port);
+       }
+}
+
+/*
+ * transmit or cease transmitting a break signal
+ */
+static void mn10300_serial_break_ctl(struct uart_port *_port, int ctl)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       _enter("%s,%d", port->name, ctl);
+
+       if (ctl) {
+               /* tell the virtual DMA handler to assert BREAK */
+               port->tx_break = 1;
+               mn10300_serial_en_tx_intr(port);
+       } else {
+               port->tx_break = 0;
+               *port->_control &= ~SC01CTR_BKE;
+               mn10300_serial_en_tx_intr(port);
+       }
+}
+
+/*
+ * grab the interrupts and enable the port for reception
+ */
+static int mn10300_serial_startup(struct uart_port *_port)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+       struct mn10300_serial_int *pint;
+
+       _enter("%s{%d}", port->name, port->gdbstub);
+
+       if (unlikely(port->gdbstub))
+               return -EBUSY;
+
+       /* allocate an Rx buffer for the virtual DMA handler */
+       port->rx_buffer = kmalloc(MNSC_BUFFER_SIZE, GFP_KERNEL);
+       if (!port->rx_buffer)
+               return -ENOMEM;
+
+       port->rx_inp = port->rx_outp = 0;
+
+       /* finally, enable the device */
+       *port->_intr = SC01ICR_TI;
+       *port->_control |= SC01CTR_TXE | SC01CTR_RXE;
+
+       pint = &mn10300_serial_int_tbl[port->rx_irq];
+       pint->port = port;
+       pint->vdma = mn10300_serial_vdma_rx_handler;
+       pint = &mn10300_serial_int_tbl[port->tx_irq];
+       pint->port = port;
+       pint->vdma = mn10300_serial_vdma_tx_handler;
+
+       set_intr_level(port->rx_irq, GxICR_LEVEL_1);
+       set_intr_level(port->tx_irq, GxICR_LEVEL_1);
+       set_irq_chip(port->tm_irq, &mn10300_serial_pic);
+
+       if (request_irq(port->rx_irq, mn10300_serial_interrupt,
+                       IRQF_DISABLED, port->rx_name, port) < 0)
+               goto error;
+
+       if (request_irq(port->tx_irq, mn10300_serial_interrupt,
+                       IRQF_DISABLED, port->tx_name, port) < 0)
+               goto error2;
+
+       if (request_irq(port->tm_irq, mn10300_serial_interrupt,
+                       IRQF_DISABLED, port->tm_name, port) < 0)
+               goto error3;
+       mn10300_serial_mask_ack(port->tm_irq);
+
+       return 0;
+
+error3:
+       free_irq(port->tx_irq, port);
+error2:
+       free_irq(port->rx_irq, port);
+error:
+       kfree(port->rx_buffer);
+       port->rx_buffer = NULL;
+       return -EBUSY;
+}
+
+/*
+ * shutdown the port and release interrupts
+ */
+static void mn10300_serial_shutdown(struct uart_port *_port)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       _enter("%s", port->name);
+
+       /* disable the serial port and its baud rate timer */
+       port->tx_break = 0;
+       *port->_control &= ~(SC01CTR_TXE | SC01CTR_RXE | SC01CTR_BKE);
+       *port->_tmxmd = 0;
+
+       if (port->rx_buffer) {
+               void *buf = port->rx_buffer;
+               port->rx_buffer = NULL;
+               kfree(buf);
+       }
+
+       /* disable all intrs */
+       free_irq(port->tm_irq, port);
+       free_irq(port->rx_irq, port);
+       free_irq(port->tx_irq, port);
+
+       *port->rx_icr = GxICR_LEVEL_1;
+       *port->tx_icr = GxICR_LEVEL_1;
+}
+
+/*
+ * this routine is called to set the UART divisor registers to match the
+ * specified baud rate for a serial port.
+ */
+static void mn10300_serial_change_speed(struct mn10300_serial_port *port,
+                                         struct ktermios *new,
+                                         struct ktermios *old)
+{
+       unsigned long flags;
+       unsigned long ioclk = port->ioclk;
+       unsigned cflag;
+       int baud, bits, xdiv, tmp;
+       u16 tmxbr, scxctr;
+       u8 tmxmd, battempt;
+       u8 div_timer = port->div_timer;
+
+       _enter("%s{%lu}", port->name, ioclk);
+
+       /* byte size and parity */
+       cflag = new->c_cflag;
+       switch (cflag & CSIZE) {
+       case CS7: scxctr = SC01CTR_CLN_7BIT; bits = 9;  break;
+       case CS8: scxctr = SC01CTR_CLN_8BIT; bits = 10; break;
+       default:  scxctr = SC01CTR_CLN_8BIT; bits = 10; break;
+       }
+
+       if (cflag & CSTOPB) {
+               scxctr |= SC01CTR_STB_2BIT;
+               bits++;
+       }
+
+       if (cflag & PARENB) {
+               bits++;
+               if (cflag & PARODD)
+                       scxctr |= SC01CTR_PB_ODD;
+#ifdef CMSPAR
+               else if (cflag & CMSPAR)
+                       scxctr |= SC01CTR_PB_FIXED0;
+#endif
+               else
+                       scxctr |= SC01CTR_PB_EVEN;
+       }
+
+       /* Determine divisor based on baud rate */
+       battempt = 0;
+
+       if (div_timer == MNSCx_DIV_TIMER_16BIT)
+               scxctr |= SC0CTR_CK_TM8UFLOW_8; /* ( == SC1CTR_CK_TM9UFLOW_8
+                                                *   == SC2CTR_CK_TM10UFLOW) */
+       else if (div_timer == MNSCx_DIV_TIMER_8BIT)
+               scxctr |= SC0CTR_CK_TM2UFLOW_8;
+
+try_alternative:
+       baud = uart_get_baud_rate(&port->uart, new, old, 0,
+                                 port->ioclk / 8);
+
+       _debug("ALT %d [baud %d]", battempt, baud);
+
+       if (!baud)
+               baud = 9600;    /* B0 transition handled in rs_set_termios */
+       xdiv = 1;
+       if (baud == 134) {
+               baud = 269;     /* 134 is really 134.5 */
+               xdiv = 2;
+       }
+
+       if (baud == 38400 &&
+           (port->uart.flags & UPF_SPD_MASK) == UPF_SPD_CUST
+           ) {
+               _debug("CUSTOM %u", port->uart.custom_divisor);
+
+               if (div_timer == MNSCx_DIV_TIMER_16BIT) {
+                       if (port->uart.custom_divisor <= 65535) {
+                               tmxmd = TM8MD_SRC_IOCLK;
+                               tmxbr = port->uart.custom_divisor;
+                               port->uart.uartclk = ioclk;
+                               goto timer_okay;
+                       }
+                       if (port->uart.custom_divisor / 8 <= 65535) {
+                               tmxmd = TM8MD_SRC_IOCLK_8;
+                               tmxbr = port->uart.custom_divisor / 8;
+                               port->uart.custom_divisor = tmxbr * 8;
+                               port->uart.uartclk = ioclk / 8;
+                               goto timer_okay;
+                       }
+                       if (port->uart.custom_divisor / 32 <= 65535) {
+                               tmxmd = TM8MD_SRC_IOCLK_32;
+                               tmxbr = port->uart.custom_divisor / 32;
+                               port->uart.custom_divisor = tmxbr * 32;
+                               port->uart.uartclk = ioclk / 32;
+                               goto timer_okay;
+                       }
+
+               } else if (div_timer == MNSCx_DIV_TIMER_8BIT) {
+                       if (port->uart.custom_divisor <= 255) {
+                               tmxmd = TM2MD_SRC_IOCLK;
+                               tmxbr = port->uart.custom_divisor;
+                               port->uart.uartclk = ioclk;
+                               goto timer_okay;
+                       }
+                       if (port->uart.custom_divisor / 8 <= 255) {
+                               tmxmd = TM2MD_SRC_IOCLK_8;
+                               tmxbr = port->uart.custom_divisor / 8;
+                               port->uart.custom_divisor = tmxbr * 8;
+                               port->uart.uartclk = ioclk / 8;
+                               goto timer_okay;
+                       }
+                       if (port->uart.custom_divisor / 32 <= 255) {
+                               tmxmd = TM2MD_SRC_IOCLK_32;
+                               tmxbr = port->uart.custom_divisor / 32;
+                               port->uart.custom_divisor = tmxbr * 32;
+                               port->uart.uartclk = ioclk / 32;
+                               goto timer_okay;
+                       }
+               }
+       }
+
+       switch (div_timer) {
+       case MNSCx_DIV_TIMER_16BIT:
+               port->uart.uartclk = ioclk;
+               tmxmd = TM8MD_SRC_IOCLK;
+               tmxbr = tmp = (ioclk / (baud * xdiv) + 4) / 8 - 1;
+               if (tmp > 0 && tmp <= 65535)
+                       goto timer_okay;
+
+               port->uart.uartclk = ioclk / 8;
+               tmxmd = TM8MD_SRC_IOCLK_8;
+               tmxbr = tmp = (ioclk / (baud * 8 * xdiv) + 4) / 8 - 1;
+               if (tmp > 0 && tmp <= 65535)
+                       goto timer_okay;
+
+               port->uart.uartclk = ioclk / 32;
+               tmxmd = TM8MD_SRC_IOCLK_32;
+               tmxbr = tmp = (ioclk / (baud * 32 * xdiv) + 4) / 8 - 1;
+               if (tmp > 0 && tmp <= 65535)
+                       goto timer_okay;
+               break;
+
+       case MNSCx_DIV_TIMER_8BIT:
+               port->uart.uartclk = ioclk;
+               tmxmd = TM2MD_SRC_IOCLK;
+               tmxbr = tmp = (ioclk / (baud * xdiv) + 4) / 8 - 1;
+               if (tmp > 0 && tmp <= 255)
+                       goto timer_okay;
+
+               port->uart.uartclk = ioclk / 8;
+               tmxmd = TM2MD_SRC_IOCLK_8;
+               tmxbr = tmp = (ioclk / (baud * 8 * xdiv) + 4) / 8 - 1;
+               if (tmp > 0 && tmp <= 255)
+                       goto timer_okay;
+
+               port->uart.uartclk = ioclk / 32;
+               tmxmd = TM2MD_SRC_IOCLK_32;
+               tmxbr = tmp = (ioclk / (baud * 32 * xdiv) + 4) / 8 - 1;
+               if (tmp > 0 && tmp <= 255)
+                       goto timer_okay;
+               break;
+
+       default:
+               BUG();
+               return;
+       }
+
+       /* refuse to change to a baud rate we can't support */
+       _debug("CAN'T SUPPORT");
+
+       switch (battempt) {
+       case 0:
+               if (old) {
+                       new->c_cflag &= ~CBAUD;
+                       new->c_cflag |= (old->c_cflag & CBAUD);
+                       battempt = 1;
+                       goto try_alternative;
+               }
+
+       case 1:
+               /* as a last resort, if the quotient is zero, default to 9600
+                * bps */
+               new->c_cflag &= ~CBAUD;
+               new->c_cflag |= B9600;
+               battempt = 2;
+               goto try_alternative;
+
+       default:
+               /* hmmm... can't seem to support 9600 either
+                * - we could try iterating through the speeds we know about to
+                *   find the lowest
+                */
+               new->c_cflag &= ~CBAUD;
+               new->c_cflag |= B0;
+
+               if (div_timer == MNSCx_DIV_TIMER_16BIT)
+                       tmxmd = TM8MD_SRC_IOCLK_32;
+               else if (div_timer == MNSCx_DIV_TIMER_8BIT)
+                       tmxmd = TM2MD_SRC_IOCLK_32;
+               tmxbr = 1;
+
+               port->uart.uartclk = ioclk / 32;
+               break;
+       }
+timer_okay:
+
+       _debug("UARTCLK: %u / %hu", port->uart.uartclk, tmxbr);
+
+       /* make the changes */
+       spin_lock_irqsave(&port->uart.lock, flags);
+
+       uart_update_timeout(&port->uart, new->c_cflag, baud);
+
+       /* set the timer to produce the required baud rate */
+       switch (div_timer) {
+       case MNSCx_DIV_TIMER_16BIT:
+               *port->_tmxmd = 0;
+               *port->_tmxbr = tmxbr;
+               *port->_tmxmd = TM8MD_INIT_COUNTER;
+               *port->_tmxmd = tmxmd | TM8MD_COUNT_ENABLE;
+               break;
+
+       case MNSCx_DIV_TIMER_8BIT:
+               *port->_tmxmd = 0;
+               *(volatile u8 *) port->_tmxbr = (u8) tmxbr;
+               *port->_tmxmd = TM2MD_INIT_COUNTER;
+               *port->_tmxmd = tmxmd | TM2MD_COUNT_ENABLE;
+               break;
+       }
+
+       /* CTS flow control flag and modem status interrupts */
+       scxctr &= ~(SC2CTR_TWE | SC2CTR_TWS);
+
+       if (port->type == PORT_MN10300_CTS && cflag & CRTSCTS) {
+               /* want to interrupt when CTS goes low if CTS is now
+                * high and vice versa
+                */
+               port->tx_cts = *port->_status;
+
+               if (port->tx_cts & SC2STR_CTS)
+                       scxctr |= SC2CTR_TWE;
+               else
+                       scxctr |= SC2CTR_TWE | SC2CTR_TWS;
+       }
+
+       /* set up parity check flag */
+       port->uart.read_status_mask = (1 << TTY_NORMAL) | (1 << TTY_OVERRUN);
+       if (new->c_iflag & INPCK)
+               port->uart.read_status_mask |=
+                       (1 << TTY_PARITY) | (1 << TTY_FRAME);
+       if (new->c_iflag & (BRKINT | PARMRK))
+               port->uart.read_status_mask |= (1 << TTY_BREAK);
+
+       /* characters to ignore */
+       port->uart.ignore_status_mask = 0;
+       if (new->c_iflag & IGNPAR)
+               port->uart.ignore_status_mask |=
+                       (1 << TTY_PARITY) | (1 << TTY_FRAME);
+       if (new->c_iflag & IGNBRK) {
+               port->uart.ignore_status_mask |= (1 << TTY_BREAK);
+               /*
+                * If we're ignoring parity and break indicators,
+                * ignore overruns to (for real raw support).
+                */
+               if (new->c_iflag & IGNPAR)
+                       port->uart.ignore_status_mask |= (1 << TTY_OVERRUN);
+       }
+
+       /* Ignore all characters if CREAD is not set */
+       if ((new->c_cflag & CREAD) == 0)
+               port->uart.ignore_status_mask |= (1 << TTY_NORMAL);
+
+       scxctr |= *port->_control & (SC01CTR_TXE | SC01CTR_RXE | SC01CTR_BKE);
+       *port->_control = scxctr;
+
+       spin_unlock_irqrestore(&port->uart.lock, flags);
+}
+
+/*
+ * set the terminal I/O parameters
+ */
+static void mn10300_serial_set_termios(struct uart_port *_port,
+                                        struct ktermios *new,
+                                        struct ktermios *old)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       _enter("%s,%p,%p", port->name, new, old);
+
+       mn10300_serial_change_speed(port, new, old);
+
+       /* handle turning off CRTSCTS */
+       if (!(new->c_cflag & CRTSCTS)) {
+               u16 ctr = *port->_control;
+               ctr &= ~SC2CTR_TWE;
+               *port->_control = ctr;
+       }
+}
+
+/*
+ * return description of port type
+ */
+static const char *mn10300_serial_type(struct uart_port *_port)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       if (port->uart.type == PORT_MN10300_CTS)
+               return "MN10300 SIF_CTS";
+
+       return "MN10300 SIF";
+}
+
+/*
+ * release I/O and memory regions in use by port
+ */
+static void mn10300_serial_release_port(struct uart_port *_port)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       _enter("%s", port->name);
+
+       release_mem_region((unsigned long) port->_iobase, 16);
+}
+
+/*
+ * request I/O and memory regions for port
+ */
+static int mn10300_serial_request_port(struct uart_port *_port)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       _enter("%s", port->name);
+
+       request_mem_region((unsigned long) port->_iobase, 16, port->name);
+       return 0;
+}
+
+/*
+ * configure the type and reserve the ports
+ */
+static void mn10300_serial_config_port(struct uart_port *_port, int type)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+
+       _enter("%s", port->name);
+
+       port->uart.type = PORT_MN10300;
+
+       if (port->options & MNSCx_OPT_CTS)
+               port->uart.type = PORT_MN10300_CTS;
+
+       mn10300_serial_request_port(_port);
+}
+
+/*
+ * verify serial parameters are suitable for this port type
+ */
+static int mn10300_serial_verify_port(struct uart_port *_port,
+                                       struct serial_struct *ss)
+{
+       struct mn10300_serial_port *port =
+               container_of(_port, struct mn10300_serial_port, uart);
+       void *mapbase = (void *) (unsigned long) port->uart.mapbase;
+
+       _enter("%s", port->name);
+
+       /* these things may not be changed */
+       if (ss->irq             != port->uart.irq       ||
+           ss->port            != port->uart.iobase    ||
+           ss->io_type         != port->uart.iotype    ||
+           ss->iomem_base      != mapbase ||
+           ss->iomem_reg_shift != port->uart.regshift  ||
+           ss->hub6            != port->uart.hub6      ||
+           ss->xmit_fifo_size  != port->uart.fifosize)
+               return -EINVAL;
+
+       /* type may be changed on a port that supports CTS */
+       if (ss->type != port->uart.type) {
+               if (!(port->options & MNSCx_OPT_CTS))
+                       return -EINVAL;
+
+               if (ss->type != PORT_MN10300 &&
+                   ss->type != PORT_MN10300_CTS)
+                       return -EINVAL;
+       }
+
+       return 0;
+}
+
+/*
+ * initialise the MN10300 on-chip UARTs
+ */
+static int __init mn10300_serial_init(void)
+{
+       struct mn10300_serial_port *port;
+       int ret, i;
+
+       printk(KERN_INFO "%s version %s (%s)\n",
+              serial_name, serial_version, serial_revdate);
+
+#ifdef CONFIG_MN10300_TTYSM2
+       SC2TIM = 8; /* make the baud base of timer 2 IOCLK/8 */
+#endif
+
+       set_intr_stub(EXCEP_IRQ_LEVEL1, mn10300_serial_vdma_interrupt);
+
+       ret = uart_register_driver(&mn10300_serial_driver);
+       if (!ret) {
+               for (i = 0 ; i < NR_PORTS ; i++) {
+                       port = mn10300_serial_ports[i];
+                       if (!port || port->gdbstub)
+                               continue;
+
+                       switch (port->clock_src) {
+                       case MNSCx_CLOCK_SRC_IOCLK:
+                               port->ioclk = MN10300_IOCLK;
+                               break;
+
+#ifdef MN10300_IOBCLK
+                       case MNSCx_CLOCK_SRC_IOBCLK:
+                               port->ioclk = MN10300_IOBCLK;
+                               break;
+#endif
+                       default:
+                               BUG();
+                       }
+
+                       ret = uart_add_one_port(&mn10300_serial_driver,
+                                               &port->uart);
+
+                       if (ret < 0) {
+                               _debug("ERROR %d", -ret);
+                               break;
+                       }
+               }
+
+               if (ret)
+                       uart_unregister_driver(&mn10300_serial_driver);
+       }
+
+       return ret;
+}
+
+__initcall(mn10300_serial_init);
+
+
+#ifdef CONFIG_MN10300_TTYSM_CONSOLE
+
+/*
+ * print a string to the serial port without disturbing the real user of the
+ * port too much
+ * - the console must be locked by the caller
+ */
+static void mn10300_serial_console_write(struct console *co,
+                                          const char *s, unsigned count)
+{
+       struct mn10300_serial_port *port;
+       unsigned i;
+       u16 scxctr, txicr, tmp;
+       u8 tmxmd;
+
+       port = mn10300_serial_ports[co->index];
+
+       /* firstly hijack the serial port from the "virtual DMA" controller */
+       txicr = *port->tx_icr;
+       *port->tx_icr = GxICR_LEVEL_1;
+       tmp = *port->tx_icr;
+
+       /* the transmitter may be disabled */
+       scxctr = *port->_control;
+       if (!(scxctr & SC01CTR_TXE)) {
+               /* restart the UART clock */
+               tmxmd = *port->_tmxmd;
+
+               switch (port->div_timer) {
+               case MNSCx_DIV_TIMER_16BIT:
+                       *port->_tmxmd = 0;
+                       *port->_tmxmd = TM8MD_INIT_COUNTER;
+                       *port->_tmxmd = tmxmd | TM8MD_COUNT_ENABLE;
+                       break;
+
+               case MNSCx_DIV_TIMER_8BIT:
+                       *port->_tmxmd = 0;
+                       *port->_tmxmd = TM2MD_INIT_COUNTER;
+                       *port->_tmxmd = tmxmd | TM2MD_COUNT_ENABLE;
+                       break;
+               }
+
+               /* enable the transmitter */
+               *port->_control = (scxctr & ~SC01CTR_BKE) | SC01CTR_TXE;
+
+       } else if (scxctr & SC01CTR_BKE) {
+               /* stop transmitting BREAK */
+               *port->_control = (scxctr & ~SC01CTR_BKE);
+       }
+
+       /* send the chars into the serial port (with LF -> LFCR conversion) */
+       for (i = 0; i < count; i++) {
+               char ch = *s++;
+
+               while (*port->_status & SC01STR_TBF)
+                       continue;
+               *(u8 *) port->_txb = ch;
+
+               if (ch == 0x0a) {
+                       while (*port->_status & SC01STR_TBF)
+                               continue;
+                       *(u8 *) port->_txb = 0xd;
+               }
+       }
+
+       /* can't let the transmitter be turned off if it's actually
+        * transmitting */
+       while (*port->_status & (SC01STR_TXF | SC01STR_TBF))
+               continue;
+
+       /* disable the transmitter if we re-enabled it */
+       if (!(scxctr & SC01CTR_TXE))
+               *port->_control = scxctr;
+
+       *port->tx_icr = txicr;
+       tmp = *port->tx_icr;
+}
+
+/*
+ * set up a serial port as a console
+ * - construct a cflag setting for the first rs_open()
+ * - initialize the serial port
+ * - return non-zero if we didn't find a serial port.
+ */
+static int __init mn10300_serial_console_setup(struct console *co,
+                                                char *options)
+{
+       struct mn10300_serial_port *port;
+       int i, parity = 'n', baud = 9600, bits = 8, flow = 0;
+
+       for (i = 0 ; i < NR_PORTS ; i++) {
+               port = mn10300_serial_ports[i];
+               if (port && !port->gdbstub && port->uart.line == co->index)
+                       goto found_device;
+       }
+
+       return -ENODEV;
+
+found_device:
+       switch (port->clock_src) {
+       case MNSCx_CLOCK_SRC_IOCLK:
+               port->ioclk = MN10300_IOCLK;
+               break;
+
+#ifdef MN10300_IOBCLK
+       case MNSCx_CLOCK_SRC_IOBCLK:
+               port->ioclk = MN10300_IOBCLK;
+               break;
+#endif
+       default:
+               BUG();
+       }
+
+       if (options)
+               uart_parse_options(options, &baud, &parity, &bits, &flow);
+
+       return uart_set_options(&port->uart, co, baud, parity, bits, flow);
+}
+
+/*
+ * register console
+ */
+static int __init mn10300_serial_console_init(void)
+{
+       register_console(&mn10300_serial_console);
+       return 0;
+}
+
+console_initcall(mn10300_serial_console_init);
+#endif
diff --git a/arch/mn10300/kernel/mn10300-serial.h b/arch/mn10300/kernel/mn10300-serial.h
new file mode 100644 (file)
index 0000000..6796499
--- /dev/null
@@ -0,0 +1,126 @@
+/* MN10300 On-chip serial port driver definitions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _MN10300_SERIAL_H
+#define _MN10300_SERIAL_H
+
+#ifndef __ASSEMBLY__
+#include <linux/serial_core.h>
+#include <linux/termios.h>
+#endif
+
+#include <asm/page.h>
+#include <asm/serial-regs.h>
+
+#define NR_PORTS               3               /* should be set 3 or 9 or 16 */
+
+#define MNSC_BUFFER_SIZE       +(PAGE_SIZE / 2)
+
+/* intr_flags bits */
+#define MNSCx_RX_AVAIL         0x01
+#define MNSCx_RX_OVERF         0x02
+#define MNSCx_TX_SPACE         0x04
+#define MNSCx_TX_EMPTY         0x08
+
+#ifndef __ASSEMBLY__
+
+struct mn10300_serial_port {
+       char                    *rx_buffer;     /* reception buffer base */
+       unsigned                rx_inp;         /* pointer to rx input offset */
+       unsigned                rx_outp;        /* pointer to rx output offset */
+       u8                      tx_xchar;       /* high-priority XON/XOFF buffer */
+       u8                      tx_break;       /* transmit break request */
+       u8                      intr_flags;     /* interrupt flags */
+       volatile u16            *rx_icr;        /* Rx interrupt control register */
+       volatile u16            *tx_icr;        /* Tx interrupt control register */
+       int                     rx_irq;         /* reception IRQ */
+       int                     tx_irq;         /* transmission IRQ */
+       int                     tm_irq;         /* timer IRQ */
+
+       const char              *name;          /* name of serial port */
+       const char              *rx_name;       /* Rx interrupt handler name of serial port */
+       const char              *tx_name;       /* Tx interrupt handler name of serial port */
+       const char              *tm_name;       /* Timer interrupt handler name */
+       unsigned short          type;           /* type of serial port */
+       unsigned char           isconsole;      /* T if it's a console */
+       volatile void           *_iobase;       /* pointer to base of I/O control regs */
+       volatile u16            *_control;      /* control register pointer */
+       volatile u8             *_status;       /* status register pointer */
+       volatile u8             *_intr;         /* interrupt register pointer */
+       volatile void           *_rxb;          /* receive buffer register pointer */
+       volatile void           *_txb;          /* transmit buffer register pointer */
+       volatile u16            *_tmicr;        /* timer interrupt control register */
+       volatile u8             *_tmxmd;        /* baud rate timer mode register */
+       volatile u16            *_tmxbr;        /* baud rate timer base register */
+
+       /* this must come down here so that assembly can use BSET to access the
+        * above fields */
+       struct uart_port        uart;
+
+       unsigned short          rx_brk;         /* current break reception status */
+       u16                     tx_cts;         /* current CTS status */
+       int                     gdbstub;        /* preemptively stolen by GDB stub */
+
+       u8                      clock_src;      /* clock source */
+#define MNSCx_CLOCK_SRC_IOCLK  0
+#define MNSCx_CLOCK_SRC_IOBCLK 1
+
+       u8                      div_timer;      /* timer used as divisor */
+#define MNSCx_DIV_TIMER_16BIT  0
+#define MNSCx_DIV_TIMER_8BIT   1
+
+       u16                     options;        /* options */
+#define MNSCx_OPT_CTS          0x0001
+
+       unsigned long           ioclk;          /* base clock rate */
+};
+
+#ifdef CONFIG_MN10300_TTYSM0
+extern struct mn10300_serial_port mn10300_serial_port_sif0;
+#endif
+
+#ifdef CONFIG_MN10300_TTYSM1
+extern struct mn10300_serial_port mn10300_serial_port_sif1;
+#endif
+
+#ifdef CONFIG_MN10300_TTYSM2
+extern struct mn10300_serial_port mn10300_serial_port_sif2;
+#endif
+
+extern struct mn10300_serial_port *mn10300_serial_ports[];
+
+struct mn10300_serial_int {
+       struct mn10300_serial_port *port;
+       asmlinkage void (*vdma)(void);
+};
+
+extern struct mn10300_serial_int mn10300_serial_int_tbl[];
+
+extern asmlinkage void mn10300_serial_vdma_interrupt(void);
+extern asmlinkage void mn10300_serial_vdma_rx_handler(void);
+extern asmlinkage void mn10300_serial_vdma_tx_handler(void);
+
+#endif /* __ASSEMBLY__ */
+
+#if defined(CONFIG_GDBSTUB_ON_TTYSM0)
+#define SCgSTR SC0STR
+#define SCgRXB SC0RXB
+#define SCgRXIRQ SC0RXIRQ
+#elif defined(CONFIG_GDBSTUB_ON_TTYSM1)
+#define SCgSTR SC1STR
+#define SCgRXB SC1RXB
+#define SCgRXIRQ SC1RXIRQ
+#elif defined(CONFIG_GDBSTUB_ON_TTYSM2)
+#define SCgSTR SC2STR
+#define SCgRXB SC2RXB
+#define SCgRXIRQ SC2RXIRQ
+#endif
+
+#endif /* _MN10300_SERIAL_H */
diff --git a/arch/mn10300/kernel/mn10300-watchdog-low.S b/arch/mn10300/kernel/mn10300-watchdog-low.S
new file mode 100644 (file)
index 0000000..9962447
--- /dev/null
@@ -0,0 +1,59 @@
+###############################################################################
+#
+# MN10300 Watchdog interrupt handler
+#
+# Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+# Written by David Howells (dhowells@redhat.com)
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public Licence
+# as published by the Free Software Foundation; either version
+# 2 of the Licence, or (at your option) any later version.
+#
+###############################################################################
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/intctl-regs.h>
+#include <asm/timer-regs.h>
+#include <asm/frame.inc>
+
+       .text
+
+###############################################################################
+#
+# Watchdog handler entry point
+# - special non-maskable interrupt
+#
+###############################################################################
+       .globl  watchdog_handler
+       .type   watchdog_handler,@function
+watchdog_handler:
+       add     -4,sp
+       SAVE_ALL
+
+       mov     0xffffffff,d0
+       mov     d0,(REG_ORIG_D0,fp)
+
+       mov     fp,d0
+       lsr     2,d1
+       call    watchdog_interrupt[],0          # watchdog_interrupt(regs,irq)
+
+       jmp     ret_from_intr
+
+       .size   watchdog_handler,.-watchdog_handler
+
+###############################################################################
+#
+# Watchdog touch entry point
+# - kept to absolute minimum (unfortunately, it's prototyped in linux/nmi.h so
+#   we can't inline it)
+#
+###############################################################################
+       .globl  touch_nmi_watchdog
+       .type   touch_nmi_watchdog,@function
+touch_nmi_watchdog:
+       clr     d0
+       mov     d0,(watchdog_alert_counter)
+       ret     [],0
+
+       .size   touch_nmi_watchdog,.-touch_nmi_watchdog
diff --git a/arch/mn10300/kernel/mn10300-watchdog.c b/arch/mn10300/kernel/mn10300-watchdog.c
new file mode 100644 (file)
index 0000000..10811e9
--- /dev/null
@@ -0,0 +1,183 @@
+/* MN10300 Watchdog timer
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ * - Derived from arch/i386/kernel/nmi.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/kernel_stat.h>
+#include <linux/nmi.h>
+#include <asm/processor.h>
+#include <asm/system.h>
+#include <asm/atomic.h>
+#include <asm/intctl-regs.h>
+#include <asm/rtc-regs.h>
+#include <asm/div64.h>
+#include <asm/smp.h>
+#include <asm/gdb-stub.h>
+#include <asm/proc/clock.h>
+
+static DEFINE_SPINLOCK(watchdog_print_lock);
+static unsigned int watchdog;
+static unsigned int watchdog_hz = 1;
+unsigned int watchdog_alert_counter;
+
+EXPORT_SYMBOL(touch_nmi_watchdog);
+
+/*
+ * the best way to detect whether a CPU has a 'hard lockup' problem
+ * is to check its timer makes IRQ counts. If they are not
+ * changing then that CPU has some problem.
+ *
+ * as these watchdog NMI IRQs are generated on every CPU, we only
+ * have to check the current processor.
+ *
+ * since NMIs dont listen to _any_ locks, we have to be extremely
+ * careful not to rely on unsafe variables. The printk might lock
+ * up though, so we have to break up any console locks first ...
+ * [when there will be more tty-related locks, break them up
+ *  here too!]
+ */
+static unsigned int last_irq_sums[NR_CPUS];
+
+int __init check_watchdog(void)
+{
+       irq_cpustat_t tmp[1];
+
+       printk(KERN_INFO "Testing Watchdog... ");
+
+       memcpy(tmp, irq_stat, sizeof(tmp));
+       local_irq_enable();
+       mdelay((10 * 1000) / watchdog_hz); /* wait 10 ticks */
+       local_irq_disable();
+
+       if (nmi_count(0) - tmp[0].__nmi_count <= 5) {
+               printk(KERN_WARNING "CPU#%d: Watchdog appears to be stuck!\n",
+                      0);
+               return -1;
+       }
+
+       printk(KERN_INFO "OK.\n");
+
+       /* now that we know it works we can reduce NMI frequency to
+        * something more reasonable; makes a difference in some configs
+        */
+       watchdog_hz = 1;
+
+       return 0;
+}
+
+static int __init setup_watchdog(char *str)
+{
+       unsigned tmp;
+       int opt;
+       u8 ctr;
+
+       get_option(&str, &opt);
+       if (opt != 1)
+               return 0;
+
+       watchdog = opt;
+       if (watchdog) {
+               set_intr_stub(EXCEP_WDT, watchdog_handler);
+               ctr = WDCTR_WDCK_65536th;
+               WDCTR = WDCTR_WDRST | ctr;
+               WDCTR = ctr;
+               tmp = WDCTR;
+
+               tmp = __muldiv64u(1 << (16 + ctr * 2), 1000000, MN10300_WDCLK);
+               tmp = 1000000000 / tmp;
+               watchdog_hz = (tmp + 500) / 1000;
+       }
+
+       return 1;
+}
+
+__setup("watchdog=", setup_watchdog);
+
+void __init watchdog_go(void)
+{
+       u8 wdt;
+
+       if (watchdog) {
+               printk(KERN_INFO "Watchdog: running at %uHz\n", watchdog_hz);
+               wdt = WDCTR & ~WDCTR_WDCNE;
+               WDCTR = wdt | WDCTR_WDRST;
+               wdt = WDCTR;
+               WDCTR = wdt | WDCTR_WDCNE;
+               wdt = WDCTR;
+
+               check_watchdog();
+       }
+}
+
+asmlinkage
+void watchdog_interrupt(struct pt_regs *regs, enum exception_code excep)
+{
+
+       /*
+        * Since current-> is always on the stack, and we always switch
+        * the stack NMI-atomically, it's safe to use smp_processor_id().
+        */
+       int sum, cpu = smp_processor_id();
+       u8 wdt, tmp;
+
+       wdt = WDCTR & ~WDCTR_WDCNE;
+       WDCTR = wdt;
+       tmp = WDCTR;
+       NMICR = NMICR_WDIF;
+
+       nmi_count(cpu)++;
+       kstat_this_cpu.irqs[NMIIRQ]++;
+       sum = irq_stat[cpu].__irq_count;
+
+       if (last_irq_sums[cpu] == sum) {
+               /*
+                * Ayiee, looks like this CPU is stuck ...
+                * wait a few IRQs (5 seconds) before doing the oops ...
+                */
+               watchdog_alert_counter++;
+               if (watchdog_alert_counter == 5 * watchdog_hz) {
+                       spin_lock(&watchdog_print_lock);
+                       /*
+                        * We are in trouble anyway, lets at least try
+                        * to get a message out.
+                        */
+                       bust_spinlocks(1);
+                       printk(KERN_ERR
+                              "NMI Watchdog detected LOCKUP on CPU%d,"
+                              " pc %08lx, registers:\n",
+                              cpu, regs->pc);
+                       show_registers(regs);
+                       printk("console shuts up ...\n");
+                       console_silent();
+                       spin_unlock(&watchdog_print_lock);
+                       bust_spinlocks(0);
+#ifdef CONFIG_GDBSTUB
+                       if (gdbstub_busy)
+                               gdbstub_exception(regs, excep);
+                       else
+                               gdbstub_intercept(regs, excep);
+#endif
+                       do_exit(SIGSEGV);
+               }
+       } else {
+               last_irq_sums[cpu] = sum;
+               watchdog_alert_counter = 0;
+       }
+
+       WDCTR = wdt | WDCTR_WDRST;
+       tmp = WDCTR;
+       WDCTR = wdt | WDCTR_WDCNE;
+       tmp = WDCTR;
+}
diff --git a/arch/mn10300/kernel/mn10300_ksyms.c b/arch/mn10300/kernel/mn10300_ksyms.c
new file mode 100644 (file)
index 0000000..6d19628
--- /dev/null
@@ -0,0 +1,37 @@
+/* MN10300 Miscellaneous and library kernel exports
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/module.h>
+#include <asm/uaccess.h>
+
+
+EXPORT_SYMBOL(change_bit);
+EXPORT_SYMBOL(test_and_change_bit);
+
+EXPORT_SYMBOL(memcpy);
+EXPORT_SYMBOL(memmove);
+EXPORT_SYMBOL(memset);
+
+EXPORT_SYMBOL(strncpy_from_user);
+EXPORT_SYMBOL(__strncpy_from_user);
+EXPORT_SYMBOL(clear_user);
+EXPORT_SYMBOL(__clear_user);
+EXPORT_SYMBOL(__generic_copy_from_user);
+EXPORT_SYMBOL(__generic_copy_to_user);
+EXPORT_SYMBOL(strnlen_user);
+
+extern u64 __ashrdi3(u64, unsigned);
+extern u64 __ashldi3(u64, unsigned);
+extern u64 __lshrdi3(u64, unsigned);
+extern s64 __negdi2(s64);
+EXPORT_SYMBOL(__ashrdi3);
+EXPORT_SYMBOL(__ashldi3);
+EXPORT_SYMBOL(__lshrdi3);
+EXPORT_SYMBOL(__negdi2);
diff --git a/arch/mn10300/kernel/module.c b/arch/mn10300/kernel/module.c
new file mode 100644 (file)
index 0000000..0e4d2f6
--- /dev/null
@@ -0,0 +1,206 @@
+/* MN10300 Kernel module helper routines
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by Mark Salter (msalter@redhat.com)
+ * - Derived from arch/i386/kernel/module.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public Licence as published by
+ * the Free Software Foundation; either version 2 of the Licence, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public Licence for more details.
+ *
+ * You should have received a copy of the GNU General Public Licence
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#include <linux/moduleloader.h>
+#include <linux/elf.h>
+#include <linux/vmalloc.h>
+#include <linux/fs.h>
+#include <linux/string.h>
+#include <linux/kernel.h>
+
+#if 0
+#define DEBUGP printk
+#else
+#define DEBUGP(fmt, ...)
+#endif
+
+/*
+ * allocate storage for a module
+ */
+void *module_alloc(unsigned long size)
+{
+       if (size == 0)
+               return NULL;
+       return vmalloc_exec(size);
+}
+
+/*
+ * free memory returned from module_alloc()
+ */
+void module_free(struct module *mod, void *module_region)
+{
+       vfree(module_region);
+       /* FIXME: If module_region == mod->init_region, trim exception
+        * table entries. */
+}
+
+/*
+ * allow the arch to fix up the section table
+ * - we don't need anything special
+ */
+int module_frob_arch_sections(Elf_Ehdr *hdr,
+                             Elf_Shdr *sechdrs,
+                             char *secstrings,
+                             struct module *mod)
+{
+       return 0;
+}
+
+static uint32_t reloc_get16(uint8_t *p)
+{
+       return p[0] | (p[1] << 8);
+}
+
+static uint32_t reloc_get24(uint8_t *p)
+{
+       return reloc_get16(p) | (p[2] << 16);
+}
+
+static uint32_t reloc_get32(uint8_t *p)
+{
+       return reloc_get16(p) | (reloc_get16(p+2) << 16);
+}
+
+static void reloc_put16(uint8_t *p, uint32_t val)
+{
+       p[0] = val & 0xff;
+       p[1] = (val >> 8) & 0xff;
+}
+
+static void reloc_put24(uint8_t *p, uint32_t val)
+{
+       reloc_put16(p, val);
+       p[2] = (val >> 16) & 0xff;
+}
+
+static void reloc_put32(uint8_t *p, uint32_t val)
+{
+       reloc_put16(p, val);
+       reloc_put16(p+2, val >> 16);
+}
+
+/*
+ * apply a REL relocation
+ */
+int apply_relocate(Elf32_Shdr *sechdrs,
+                  const char *strtab,
+                  unsigned int symindex,
+                  unsigned int relsec,
+                  struct module *me)
+{
+       printk(KERN_ERR "module %s: RELOCATION unsupported\n",
+              me->name);
+       return -ENOEXEC;
+}
+
+/*
+ * apply a RELA relocation
+ */
+int apply_relocate_add(Elf32_Shdr *sechdrs,
+                      const char *strtab,
+                      unsigned int symindex,
+                      unsigned int relsec,
+                      struct module *me)
+{
+       unsigned int i;
+       Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
+       Elf32_Sym *sym;
+       Elf32_Addr relocation;
+       uint8_t *location;
+       uint32_t value;
+
+       DEBUGP("Applying relocate section %u to %u\n",
+              relsec, sechdrs[relsec].sh_info);
+
+       for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
+               /* this is where to make the change */
+               location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
+                       + rel[i].r_offset;
+
+               /* this is the symbol the relocation is referring to (note that
+                * all undefined symbols have been resolved by the caller) */
+               sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
+                       + ELF32_R_SYM(rel[i].r_info);
+
+               /* this is the adjustment to be made */
+               relocation = sym->st_value + rel[i].r_addend;
+
+               switch (ELF32_R_TYPE(rel[i].r_info)) {
+                       /* for the first four relocation types, we add the
+                        * adjustment into the value at the location given */
+               case R_MN10300_32:
+                       value = reloc_get32(location);
+                       value += relocation;
+                       reloc_put32(location, value);
+                       break;
+               case R_MN10300_24:
+                       value = reloc_get24(location);
+                       value += relocation;
+                       reloc_put24(location, value);
+                       break;
+               case R_MN10300_16:
+                       value = reloc_get16(location);
+                       value += relocation;
+                       reloc_put16(location, value);
+                       break;
+               case R_MN10300_8:
+                       *location += relocation;
+                       break;
+
+                       /* for the next three relocation types, we write the
+                        * adjustment with the address subtracted over the
+                        * value at the location given */
+               case R_MN10300_PCREL32:
+                       value = relocation - (uint32_t) location;
+                       reloc_put32(location, value);
+                       break;
+               case R_MN10300_PCREL16:
+                       value = relocation - (uint32_t) location;
+                       reloc_put16(location, value);
+                       break;
+               case R_MN10300_PCREL8:
+                       *location = relocation - (uint32_t) location;
+                       break;
+
+               default:
+                       printk(KERN_ERR "module %s: Unknown relocation: %u\n",
+                              me->name, ELF32_R_TYPE(rel[i].r_info));
+                       return -ENOEXEC;
+               }
+       }
+       return 0;
+}
+
+/*
+ * finish loading the module
+ */
+int module_finalize(const Elf_Ehdr *hdr,
+                   const Elf_Shdr *sechdrs,
+                   struct module *me)
+{
+       return 0;
+}
+
+/*
+ * finish clearing the module
+ */
+void module_arch_cleanup(struct module *mod)
+{
+}
diff --git a/arch/mn10300/kernel/process.c b/arch/mn10300/kernel/process.c
new file mode 100644 (file)
index 0000000..3b0d579
--- /dev/null
@@ -0,0 +1,297 @@
+/* MN10300  Process handling code
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/smp_lock.h>
+#include <linux/stddef.h>
+#include <linux/unistd.h>
+#include <linux/ptrace.h>
+#include <linux/slab.h>
+#include <linux/user.h>
+#include <linux/a.out.h>
+#include <linux/interrupt.h>
+#include <linux/delay.h>
+#include <linux/reboot.h>
+#include <linux/percpu.h>
+#include <linux/err.h>
+#include <linux/fs.h>
+#include <asm/uaccess.h>
+#include <asm/pgtable.h>
+#include <asm/system.h>
+#include <asm/io.h>
+#include <asm/processor.h>
+#include <asm/mmu_context.h>
+#include <asm/fpu.h>
+#include <asm/reset-regs.h>
+#include <asm/gdb-stub.h>
+#include "internal.h"
+
+/*
+ * power management idle function, if any..
+ */
+void (*pm_idle)(void);
+EXPORT_SYMBOL(pm_idle);
+
+/*
+ * return saved PC of a blocked thread.
+ */
+unsigned long thread_saved_pc(struct task_struct *tsk)
+{
+       return ((unsigned long *) tsk->thread.sp)[3];
+}
+
+/*
+ * power off function, if any
+ */
+void (*pm_power_off)(void);
+EXPORT_SYMBOL(pm_power_off);
+
+/*
+ * we use this if we don't have any better idle routine
+ */
+static void default_idle(void)
+{
+       local_irq_disable();
+       if (!need_resched())
+               safe_halt();
+       else
+               local_irq_enable();
+}
+
+/*
+ * the idle thread
+ * - there's no useful work to be done, so just try to conserve power and have
+ *   a low exit latency (ie sit in a loop waiting for somebody to say that
+ *   they'd like to reschedule)
+ */
+void cpu_idle(void)
+{
+       int cpu = smp_processor_id();
+
+       /* endless idle loop with no priority at all */
+       for (;;) {
+               while (!need_resched()) {
+                       void (*idle)(void);
+
+                       smp_rmb();
+                       idle = pm_idle;
+                       if (!idle)
+                               idle = default_idle;
+
+                       irq_stat[cpu].idle_timestamp = jiffies;
+                       idle();
+               }
+
+               preempt_enable_no_resched();
+               schedule();
+               preempt_disable();
+       }
+}
+
+void release_segments(struct mm_struct *mm)
+{
+}
+
+void machine_restart(char *cmd)
+{
+#ifdef CONFIG_GDBSTUB
+       gdbstub_exit(0);
+#endif
+
+#ifdef mn10300_unit_hard_reset
+       mn10300_unit_hard_reset();
+#else
+       mn10300_proc_hard_reset();
+#endif
+}
+
+void machine_halt(void)
+{
+#ifdef CONFIG_GDBSTUB
+       gdbstub_exit(0);
+#endif
+}
+
+void machine_power_off(void)
+{
+#ifdef CONFIG_GDBSTUB
+       gdbstub_exit(0);
+#endif
+}
+
+void show_regs(struct pt_regs *regs)
+{
+}
+
+/*
+ * create a kernel thread
+ */
+int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
+{
+       struct pt_regs regs;
+
+       memset(&regs, 0, sizeof(regs));
+
+       regs.a2 = (unsigned long) fn;
+       regs.d2 = (unsigned long) arg;
+       regs.pc = (unsigned long) kernel_thread_helper;
+       local_save_flags(regs.epsw);
+       regs.epsw |= EPSW_IE | EPSW_IM_7;
+
+       /* Ok, create the new process.. */
+       return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, &regs, 0,
+                      NULL, NULL);
+}
+
+/*
+ * free current thread data structures etc..
+ */
+void exit_thread(void)
+{
+       exit_fpu();
+}
+
+void flush_thread(void)
+{
+       flush_fpu();
+}
+
+void release_thread(struct task_struct *dead_task)
+{
+}
+
+/*
+ * we do not have to muck with descriptors here, that is
+ * done in switch_mm() as needed.
+ */
+void copy_segments(struct task_struct *p, struct mm_struct *new_mm)
+{
+}
+
+/*
+ * this gets called before we allocate a new thread and copy the current task
+ * into it so that we can store lazy state into memory
+ */
+void prepare_to_copy(struct task_struct *tsk)
+{
+       unlazy_fpu(tsk);
+}
+
+/*
+ * set up the kernel stack for a new thread and copy arch-specific thread
+ * control information
+ */
+int copy_thread(int nr, unsigned long clone_flags,
+               unsigned long c_usp, unsigned long ustk_size,
+               struct task_struct *p, struct pt_regs *kregs)
+{
+       struct pt_regs *c_uregs, *c_kregs, *uregs;
+       unsigned long c_ksp;
+
+       uregs = current->thread.uregs;
+
+       c_ksp = (unsigned long) task_stack_page(p) + THREAD_SIZE;
+
+       /* allocate the userspace exception frame and set it up */
+       c_ksp -= sizeof(struct pt_regs);
+       c_uregs = (struct pt_regs *) c_ksp;
+
+       p->thread.uregs = c_uregs;
+       *c_uregs = *uregs;
+       c_uregs->sp = c_usp;
+       c_uregs->epsw &= ~EPSW_FE; /* my FPU */
+
+       c_ksp -= 12; /* allocate function call ABI slack */
+
+       /* the new TLS pointer is passed in as arg #5 to sys_clone() */
+       if (clone_flags & CLONE_SETTLS)
+               c_uregs->e2 = __frame->d3;
+
+       /* set up the return kernel frame if called from kernel_thread() */
+       c_kregs = c_uregs;
+       if (kregs != uregs) {
+               c_ksp -= sizeof(struct pt_regs);
+               c_kregs = (struct pt_regs *) c_ksp;
+               *c_kregs = *kregs;
+               c_kregs->sp = c_usp;
+               c_kregs->next = c_uregs;
+#ifdef CONFIG_MN10300_CURRENT_IN_E2
+               c_kregs->e2 = (unsigned long) p; /* current */
+#endif
+
+               c_ksp -= 12; /* allocate function call ABI slack */
+       }
+
+       /* set up things up so the scheduler can start the new task */
+       p->thread.__frame = c_kregs;
+       p->thread.a3    = (unsigned long) c_kregs;
+       p->thread.sp    = c_ksp;
+       p->thread.pc    = (unsigned long) ret_from_fork;
+       p->thread.wchan = (unsigned long) ret_from_fork;
+       p->thread.usp   = c_usp;
+
+       return 0;
+}
+
+/*
+ * clone a process
+ * - tlsptr is retrieved by copy_thread() from __frame->d3
+ */
+asmlinkage long sys_clone(unsigned long clone_flags, unsigned long newsp,
+                         int __user *parent_tidptr, int __user *child_tidptr,
+                         int __user *tlsptr)
+{
+       return do_fork(clone_flags, newsp ?: __frame->sp, __frame, 0,
+                      parent_tidptr, child_tidptr);
+}
+
+asmlinkage long sys_fork(void)
+{
+       return do_fork(SIGCHLD, __frame->sp, __frame, 0, NULL, NULL);
+}
+
+asmlinkage long sys_vfork(void)
+{
+       return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, __frame->sp, __frame,
+                      0, NULL, NULL);
+}
+
+asmlinkage long sys_execve(char __user *name,
+                          char __user * __user *argv,
+                          char __user * __user *envp)
+{
+       char *filename;
+       int error;
+
+       lock_kernel();
+
+       filename = getname(name);
+       error = PTR_ERR(filename);
+       if (!IS_ERR(filename)) {
+               error = do_execve(filename, argv, envp, __frame);
+               if (error == 0)
+                       current->ptrace &= ~PT_DTRACE;
+
+               putname(filename);
+       }
+
+       unlock_kernel();
+       return error;
+}
+
+unsigned long get_wchan(struct task_struct *p)
+{
+       return p->thread.wchan;
+}
diff --git a/arch/mn10300/kernel/profile-low.S b/arch/mn10300/kernel/profile-low.S
new file mode 100644 (file)
index 0000000..94ffac1
--- /dev/null
@@ -0,0 +1,72 @@
+###############################################################################
+#
+# Fast profiling interrupt handler
+#
+# Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+# Written by David Howells (dhowells@redhat.com)
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public Licence
+# as published by the Free Software Foundation; either version
+# 2 of the Licence, or (at your option) any later version.
+#
+###############################################################################
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/segment.h>
+#include <asm/smp.h>
+#include <asm/intctl-regs.h>
+#include <asm/timer-regs.h>
+
+#define pi break
+
+       .balign 4
+counter:
+       .long   -1
+
+###############################################################################
+#
+# Profiling interrupt entry point
+# - intended to run at interrupt priority 1
+#
+###############################################################################
+ENTRY(profile_handler)
+       movm    [d2,d3,a2],(sp)
+
+       # ignore userspace
+       mov     (12,sp),d2
+       and     EPSW_nSL,d2
+       bne     out
+
+       # do nothing if there's no buffer
+       mov     (prof_buffer),a2
+       and     a2,a2
+       beq     out
+       or      0x20000000,a2
+
+       # calculate relative position in text segment
+       mov     (16,sp),d2
+       sub     _stext,d2
+       mov     (prof_shift),d3
+       lsr     d3,d2
+       mov     (prof_len),d3
+       cmp     d3,d2
+       bcc     outside_text
+
+       # increment the appropriate profile bucket
+do_inc:
+       asl2    d2
+       mov     (a2,d2),d3
+       inc     d3
+       mov     d3,(a2,d2)
+out:
+       mov     GxICR_DETECT,d2
+       movbu   d2,(TM11ICR)            # ACK the interrupt
+       movbu   (TM11ICR),d2
+       movm    (sp),[d2,d3,a2]
+       rti
+
+outside_text:
+       sub     1,d3
+       mov     d3,d2
+       bra     do_inc
diff --git a/arch/mn10300/kernel/profile.c b/arch/mn10300/kernel/profile.c
new file mode 100644 (file)
index 0000000..20d7d03
--- /dev/null
@@ -0,0 +1,51 @@
+/* MN10300 Profiling setup
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+/*
+ * initialise the profiling if enabled
+ * - using with gdbstub will give anomalous results
+ * - can't be used with gdbstub if running at IRQ priority 0
+ */
+static __init int profile_init(void)
+{
+       u16 tmp;
+
+       if (!prof_buffer)
+               return 0;
+
+       /* use timer 11 to drive the profiling interrupts */
+       set_intr_stub(EXCEP_IRQ_LEVEL0, profile_handler);
+
+       /* set IRQ priority at which to run */
+       set_intr_level(TM11IRQ, GxICR_LEVEL_0);
+
+       /* set up timer 11
+        * - source: (IOCLK 33MHz)*2 = 66MHz
+        * - frequency: (33330000*2) / 8 / 20625 = 202Hz
+        */
+       TM11BR = 20625 - 1;
+       TM11MD = TM8MD_SRC_IOCLK_8;
+       TM11MD |= TM8MD_INIT_COUNTER;
+       TM11MD &= ~TM8MD_INIT_COUNTER;
+       TM11MD |= TM8MD_COUNT_ENABLE;
+
+       TM11ICR |= GxICR_ENABLE;
+       tmp = TM11ICR;
+
+       printk(KERN_INFO "Profiling initiated on timer 11, priority 0, %uHz\n",
+              mn10300_ioclk / 8 / (TM11BR + 1));
+       printk(KERN_INFO "Profile histogram stored %p-%p\n",
+              prof_buffer, (u8 *)(prof_buffer + prof_len) - 1);
+
+       return 0;
+}
+
+__initcall(profile_init);
diff --git a/arch/mn10300/kernel/ptrace.c b/arch/mn10300/kernel/ptrace.c
new file mode 100644 (file)
index 0000000..d6d6cdc
--- /dev/null
@@ -0,0 +1,379 @@
+/* MN10300 Process tracing
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Modified by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/smp_lock.h>
+#include <linux/errno.h>
+#include <linux/ptrace.h>
+#include <linux/user.h>
+#include <asm/uaccess.h>
+#include <asm/pgtable.h>
+#include <asm/system.h>
+#include <asm/processor.h>
+#include <asm/cacheflush.h>
+#include <asm/fpu.h>
+#include <asm/asm-offsets.h>
+
+/*
+ * translate ptrace register IDs into struct pt_regs offsets
+ */
+static const u8 ptrace_regid_to_frame[] = {
+       [PT_A3 << 2]            = REG_A3,
+       [PT_A2 << 2]            = REG_A2,
+       [PT_D3 << 2]            = REG_D3,
+       [PT_D2 << 2]            = REG_D2,
+       [PT_MCVF << 2]          = REG_MCVF,
+       [PT_MCRL << 2]          = REG_MCRL,
+       [PT_MCRH << 2]          = REG_MCRH,
+       [PT_MDRQ << 2]          = REG_MDRQ,
+       [PT_E1 << 2]            = REG_E1,
+       [PT_E0 << 2]            = REG_E0,
+       [PT_E7 << 2]            = REG_E7,
+       [PT_E6 << 2]            = REG_E6,
+       [PT_E5 << 2]            = REG_E5,
+       [PT_E4 << 2]            = REG_E4,
+       [PT_E3 << 2]            = REG_E3,
+       [PT_E2 << 2]            = REG_E2,
+       [PT_SP << 2]            = REG_SP,
+       [PT_LAR << 2]           = REG_LAR,
+       [PT_LIR << 2]           = REG_LIR,
+       [PT_MDR << 2]           = REG_MDR,
+       [PT_A1 << 2]            = REG_A1,
+       [PT_A0 << 2]            = REG_A0,
+       [PT_D1 << 2]            = REG_D1,
+       [PT_D0 << 2]            = REG_D0,
+       [PT_ORIG_D0 << 2]       = REG_ORIG_D0,
+       [PT_EPSW << 2]          = REG_EPSW,
+       [PT_PC << 2]            = REG_PC,
+};
+
+static inline int get_stack_long(struct task_struct *task, int offset)
+{
+       return *(unsigned long *)
+               ((unsigned long) task->thread.uregs + offset);
+}
+
+/*
+ * this routine will put a word on the processes privileged stack.
+ * the offset is how far from the base addr as stored in the TSS.
+ * this routine assumes that all the privileged stacks are in our
+ * data space.
+ */
+static inline
+int put_stack_long(struct task_struct *task, int offset, unsigned long data)
+{
+       unsigned long stack;
+
+       stack = (unsigned long) task->thread.uregs + offset;
+       *(unsigned long *) stack = data;
+       return 0;
+}
+
+static inline unsigned long get_fpregs(struct fpu_state_struct *buf,
+                                      struct task_struct *tsk)
+{
+       return __copy_to_user(buf, &tsk->thread.fpu_state,
+                             sizeof(struct fpu_state_struct));
+}
+
+static inline unsigned long set_fpregs(struct task_struct *tsk,
+                                      struct fpu_state_struct *buf)
+{
+       return __copy_from_user(&tsk->thread.fpu_state, buf,
+                               sizeof(struct fpu_state_struct));
+}
+
+static inline void fpsave_init(struct task_struct *task)
+{
+       memset(&task->thread.fpu_state, 0, sizeof(struct fpu_state_struct));
+}
+
+/*
+ * make sure the single step bit is not set
+ */
+void ptrace_disable(struct task_struct *child)
+{
+#ifndef CONFIG_MN10300_USING_JTAG
+       struct user *dummy = NULL;
+       long tmp;
+
+       tmp = get_stack_long(child, (unsigned long) &dummy->regs.epsw);
+       tmp &= ~EPSW_T;
+       put_stack_long(child, (unsigned long) &dummy->regs.epsw, tmp);
+#endif
+}
+
+/*
+ * set the single step bit
+ */
+void ptrace_enable(struct task_struct *child)
+{
+#ifndef CONFIG_MN10300_USING_JTAG
+       struct user *dummy = NULL;
+       long tmp;
+
+       tmp = get_stack_long(child, (unsigned long) &dummy->regs.epsw);
+       tmp |= EPSW_T;
+       put_stack_long(child, (unsigned long) &dummy->regs.epsw, tmp);
+#endif
+}
+
+/*
+ * handle the arch-specific side of process tracing
+ */
+long arch_ptrace(struct task_struct *child, long request, long addr, long data)
+{
+       struct fpu_state_struct fpu_state;
+       int i, ret;
+
+       switch (request) {
+       /* read the word at location addr. */
+       case PTRACE_PEEKTEXT: {
+               unsigned long tmp;
+               int copied;
+
+               copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
+               ret = -EIO;
+               if (copied != sizeof(tmp))
+                       break;
+               ret = put_user(tmp, (unsigned long *) data);
+               break;
+       }
+
+       /* read the word at location addr. */
+       case PTRACE_PEEKDATA: {
+               unsigned long tmp;
+               int copied;
+
+               copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
+               ret = -EIO;
+               if (copied != sizeof(tmp))
+                       break;
+               ret = put_user(tmp, (unsigned long *) data);
+               break;
+       }
+
+       /* read the word at location addr in the USER area. */
+       case PTRACE_PEEKUSR: {
+               unsigned long tmp;
+
+               ret = -EIO;
+               if ((addr & 3) || addr < 0 ||
+                   addr > sizeof(struct user) - 3)
+                       break;
+
+               tmp = 0;  /* Default return condition */
+               if (addr < NR_PTREGS << 2)
+                       tmp = get_stack_long(child,
+                                            ptrace_regid_to_frame[addr]);
+               ret = put_user(tmp, (unsigned long *) data);
+               break;
+       }
+
+       /* write the word at location addr. */
+       case PTRACE_POKETEXT:
+       case PTRACE_POKEDATA:
+               if (access_process_vm(child, addr, &data, sizeof(data), 1) ==
+                   sizeof(data))
+                       ret = 0;
+               else
+                       ret = -EIO;
+               break;
+
+               /* write the word at location addr in the USER area */
+       case PTRACE_POKEUSR:
+               ret = -EIO;
+               if ((addr & 3) || addr < 0 ||
+                   addr > sizeof(struct user) - 3)
+                       break;
+
+               ret = 0;
+               if (addr < NR_PTREGS << 2)
+                       ret = put_stack_long(child, ptrace_regid_to_frame[addr],
+                                            data);
+               break;
+
+               /* continue and stop at next (return from) syscall */
+       case PTRACE_SYSCALL:
+               /* restart after signal. */
+       case PTRACE_CONT:
+               ret = -EIO;
+               if ((unsigned long) data > _NSIG)
+                       break;
+               if (request == PTRACE_SYSCALL)
+                       set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
+               else
+                       clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
+               child->exit_code = data;
+               ptrace_disable(child);
+               wake_up_process(child);
+               ret = 0;
+               break;
+
+               /*
+                * make the child exit
+                * - the best I can do is send it a sigkill
+                * - perhaps it should be put in the status that it wants to
+                *   exit
+                */
+       case PTRACE_KILL:
+               ret = 0;
+               if (child->exit_state == EXIT_ZOMBIE)   /* already dead */
+                       break;
+               child->exit_code = SIGKILL;
+               clear_tsk_thread_flag(child, TIF_SINGLESTEP);
+               ptrace_disable(child);
+               wake_up_process(child);
+               break;
+
+       case PTRACE_SINGLESTEP: /* set the trap flag. */
+#ifndef CONFIG_MN10300_USING_JTAG
+               ret = -EIO;
+               if ((unsigned long) data > _NSIG)
+                       break;
+               clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
+               ptrace_enable(child);
+               child->exit_code = data;
+               wake_up_process(child);
+               ret = 0;
+#else
+               ret = -EINVAL;
+#endif
+               break;
+
+       case PTRACE_DETACH:     /* detach a process that was attached. */
+               ret = ptrace_detach(child, data);
+               break;
+
+               /* Get all gp regs from the child. */
+       case PTRACE_GETREGS: {
+               unsigned long tmp;
+
+               if (!access_ok(VERIFY_WRITE, (unsigned *) data, NR_PTREGS << 2)) {
+                       ret = -EIO;
+                       break;
+               }
+
+               for (i = 0; i < NR_PTREGS << 2; i += 4) {
+                       tmp = get_stack_long(child, ptrace_regid_to_frame[i]);
+                       __put_user(tmp, (unsigned long *) data);
+                       data += sizeof(tmp);
+               }
+               ret = 0;
+               break;
+       }
+
+       case PTRACE_SETREGS: { /* Set all gp regs in the child. */
+               unsigned long tmp;
+
+               if (!access_ok(VERIFY_READ, (unsigned long *)data,
+                              sizeof(struct pt_regs))) {
+                       ret = -EIO;
+                       break;
+               }
+
+               for (i = 0; i < NR_PTREGS << 2; i += 4) {
+                       __get_user(tmp, (unsigned long *) data);
+                       put_stack_long(child, ptrace_regid_to_frame[i], tmp);
+                       data += sizeof(tmp);
+               }
+               ret = 0;
+               break;
+       }
+
+       case PTRACE_GETFPREGS: { /* Get the child FPU state. */
+               if (is_using_fpu(child)) {
+                       unlazy_fpu(child);
+                       fpu_state = child->thread.fpu_state;
+               } else {
+                       memset(&fpu_state, 0, sizeof(fpu_state));
+               }
+
+               ret = -EIO;
+               if (copy_to_user((void *) data, &fpu_state,
+                                sizeof(fpu_state)) == 0)
+                       ret = 0;
+               break;
+       }
+
+       case PTRACE_SETFPREGS: { /* Set the child FPU state. */
+               ret = -EFAULT;
+               if (copy_from_user(&fpu_state, (const void *) data,
+                                  sizeof(fpu_state)) == 0) {
+                       fpu_kill_state(child);
+                       child->thread.fpu_state = fpu_state;
+                       set_using_fpu(child);
+                       ret = 0;
+               }
+               break;
+       }
+
+       case PTRACE_SETOPTIONS: {
+               if (data & PTRACE_O_TRACESYSGOOD)
+                       child->ptrace |= PT_TRACESYSGOOD;
+               else
+                       child->ptrace &= ~PT_TRACESYSGOOD;
+               ret = 0;
+               break;
+       }
+
+       default:
+               ret = -EIO;
+               break;
+       }
+
+       return ret;
+}
+
+/*
+ * notification of system call entry/exit
+ * - triggered by current->work.syscall_trace
+ */
+asmlinkage void do_syscall_trace(struct pt_regs *regs, int entryexit)
+{
+#if 0
+       /* just in case... */
+       printk(KERN_DEBUG "[%d] syscall_%lu(%lx,%lx,%lx,%lx) = %lx\n",
+              current->pid,
+              regs->orig_d0,
+              regs->a0,
+              regs->d1,
+              regs->a3,
+              regs->a2,
+              regs->d0);
+       return;
+#endif
+
+       if (!test_thread_flag(TIF_SYSCALL_TRACE) &&
+           !test_thread_flag(TIF_SINGLESTEP))
+               return;
+       if (!(current->ptrace & PT_PTRACED))
+               return;
+
+       /* the 0x80 provides a way for the tracing parent to distinguish
+          between a syscall stop and SIGTRAP delivery */
+       ptrace_notify(SIGTRAP |
+                     ((current->ptrace & PT_TRACESYSGOOD) &&
+                      !test_thread_flag(TIF_SINGLESTEP) ? 0x80 : 0));
+
+       /*
+        * this isn't the same as continuing with a signal, but it will do
+        * for normal use.  strace only continues with a signal if the
+        * stopping signal is not SIGTRAP.  -brl
+        */
+       if (current->exit_code) {
+               send_sig(current->exit_code, current, 1);
+               current->exit_code = 0;
+       }
+}
diff --git a/arch/mn10300/kernel/rtc.c b/arch/mn10300/kernel/rtc.c
new file mode 100644 (file)
index 0000000..042f792
--- /dev/null
@@ -0,0 +1,173 @@
+/* MN10300 RTC management
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/mc146818rtc.h>
+#include <linux/bcd.h>
+#include <linux/timex.h>
+#include <asm/rtc-regs.h>
+#include <asm/rtc.h>
+
+DEFINE_SPINLOCK(rtc_lock);
+EXPORT_SYMBOL(rtc_lock);
+
+/* last time the RTC got updated */
+static long last_rtc_update;
+
+/* time for RTC to update itself in ioclks */
+static unsigned long mn10300_rtc_update_period;
+
+/*
+ * read the current RTC time
+ */
+unsigned long __init get_initial_rtc_time(void)
+{
+       struct rtc_time tm;
+
+       get_rtc_time(&tm);
+
+       return mktime(tm.tm_year, tm.tm_mon, tm.tm_mday,
+                     tm.tm_hour, tm.tm_min, tm.tm_sec);
+}
+
+/*
+ * In order to set the CMOS clock precisely, set_rtc_mmss has to be called 500
+ * ms after the second nowtime has started, because when nowtime is written
+ * into the registers of the CMOS clock, it will jump to the next second
+ * precisely 500 ms later.  Check the Motorola MC146818A or Dallas DS12887 data
+ * sheet for details.
+ *
+ * BUG: This routine does not handle hour overflow properly; it just
+ *      sets the minutes. Usually you'll only notice that after reboot!
+ */
+static int set_rtc_mmss(unsigned long nowtime)
+{
+       unsigned char save_control, save_freq_select;
+       int retval = 0;
+       int real_seconds, real_minutes, cmos_minutes;
+
+       /* gets recalled with irq locally disabled */
+       spin_lock(&rtc_lock);
+       save_control = CMOS_READ(RTC_CONTROL); /* tell the clock it's being
+                                               * set */
+       CMOS_WRITE(save_control | RTC_SET, RTC_CONTROL);
+
+       save_freq_select = CMOS_READ(RTC_FREQ_SELECT); /* stop and reset
+                                                       * prescaler */
+       CMOS_WRITE(save_freq_select | RTC_DIV_RESET2, RTC_FREQ_SELECT);
+
+       cmos_minutes = CMOS_READ(RTC_MINUTES);
+       if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD)
+               BCD_TO_BIN(cmos_minutes);
+
+       /*
+        * since we're only adjusting minutes and seconds,
+        * don't interfere with hour overflow. This avoids
+        * messing with unknown time zones but requires your
+        * RTC not to be off by more than 15 minutes
+        */
+       real_seconds = nowtime % 60;
+       real_minutes = nowtime / 60;
+       if (((abs(real_minutes - cmos_minutes) + 15) / 30) & 1)
+               /* correct for half hour time zone */
+               real_minutes += 30;
+       real_minutes %= 60;
+
+       if (abs(real_minutes - cmos_minutes) < 30) {
+               if (!(save_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) {
+                       BIN_TO_BCD(real_seconds);
+                       BIN_TO_BCD(real_minutes);
+               }
+               CMOS_WRITE(real_seconds, RTC_SECONDS);
+               CMOS_WRITE(real_minutes, RTC_MINUTES);
+       } else {
+               printk(KERN_WARNING
+                      "set_rtc_mmss: can't update from %d to %d\n",
+                      cmos_minutes, real_minutes);
+               retval = -1;
+       }
+
+       /* The following flags have to be released exactly in this order,
+        * otherwise the DS12887 (popular MC146818A clone with integrated
+        * battery and quartz) will not reset the oscillator and will not
+        * update precisely 500 ms later. You won't find this mentioned in
+        * the Dallas Semiconductor data sheets, but who believes data
+        * sheets anyway ...                           -- Markus Kuhn
+        */
+       CMOS_WRITE(save_control, RTC_CONTROL);
+       CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
+       spin_unlock(&rtc_lock);
+
+       return retval;
+}
+
+void check_rtc_time(void)
+{
+       /* the RTC clock just finished ticking over again this second
+        * - if we have an externally synchronized Linux clock, then update
+        *   RTC clock accordingly every ~11 minutes. set_rtc_mmss() has to be
+        *   called as close as possible to 500 ms before the new second starts.
+        */
+       if ((time_status & STA_UNSYNC) == 0 &&
+           xtime.tv_sec > last_rtc_update + 660 &&
+           xtime.tv_nsec / 1000 >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
+           xtime.tv_nsec / 1000 <= 500000 + ((unsigned) TICK_SIZE) / 2
+           ) {
+               if (set_rtc_mmss(xtime.tv_sec) == 0)
+                       last_rtc_update = xtime.tv_sec;
+               else
+                       /* do it again in 60s */
+                       last_rtc_update = xtime.tv_sec - 600;
+       }
+}
+
+/*
+ * calibrate the TSC clock against the RTC
+ */
+void __init calibrate_clock(void)
+{
+       unsigned long count0, counth, count1;
+       unsigned char status;
+
+       /* make sure the RTC is running and is set to operate in 24hr mode */
+       status = RTSRC;
+       RTCRB |= RTCRB_SET;
+       RTCRB |= RTCRB_TM_24HR;
+       RTCRA |= RTCRA_DVR;
+       RTCRA &= ~RTCRA_DVR;
+       RTCRB &= ~RTCRB_SET;
+
+       /* work out the clock speed by counting clock cycles between ends of
+        * the RTC update cycle - track the RTC through one complete update
+        * cycle (1 second)
+        */
+       startup_timestamp_counter();
+
+       while (!(RTCRA & RTCRA_UIP)) {}
+       while ((RTCRA & RTCRA_UIP)) {}
+
+       count0 = TMTSCBC;
+
+       while (!(RTCRA & RTCRA_UIP)) {}
+
+       counth = TMTSCBC;
+
+       while ((RTCRA & RTCRA_UIP)) {}
+
+       count1 = TMTSCBC;
+
+       shutdown_timestamp_counter();
+
+       MN10300_TSCCLK = count0 - count1; /* the timers count down */
+       mn10300_rtc_update_period = counth - count1;
+       MN10300_TSC_PER_HZ = MN10300_TSCCLK / HZ;
+}
diff --git a/arch/mn10300/kernel/semaphore.c b/arch/mn10300/kernel/semaphore.c
new file mode 100644 (file)
index 0000000..9153c40
--- /dev/null
@@ -0,0 +1,149 @@
+/* MN10300 Semaphore implementation
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/sched.h>
+#include <linux/module.h>
+#include <asm/semaphore.h>
+
+struct sem_waiter {
+       struct list_head        list;
+       struct task_struct      *task;
+};
+
+#if SEMAPHORE_DEBUG
+void semtrace(struct semaphore *sem, const char *str)
+{
+       if (sem->debug)
+               printk(KERN_DEBUG "[%d] %s({%d,%d})\n",
+                      current->pid,
+                      str,
+                      atomic_read(&sem->count),
+                      list_empty(&sem->wait_list) ? 0 : 1);
+}
+#else
+#define semtrace(SEM, STR) do { } while (0)
+#endif
+
+/*
+ * wait for a token to be granted from a semaphore
+ * - entered with lock held and interrupts disabled
+ */
+void __down(struct semaphore *sem, unsigned long flags)
+{
+       struct task_struct *tsk = current;
+       struct sem_waiter waiter;
+
+       semtrace(sem, "Entering __down");
+
+       /* set up my own style of waitqueue */
+       waiter.task = tsk;
+       get_task_struct(tsk);
+
+       list_add_tail(&waiter.list, &sem->wait_list);
+
+       /* we don't need to touch the semaphore struct anymore */
+       spin_unlock_irqrestore(&sem->wait_lock, flags);
+
+       /* wait to be given the semaphore */
+       set_task_state(tsk, TASK_UNINTERRUPTIBLE);
+
+       for (;;) {
+               if (!waiter.task)
+                       break;
+               schedule();
+               set_task_state(tsk, TASK_UNINTERRUPTIBLE);
+       }
+
+       tsk->state = TASK_RUNNING;
+       semtrace(sem, "Leaving __down");
+}
+EXPORT_SYMBOL(__down);
+
+/*
+ * interruptibly wait for a token to be granted from a semaphore
+ * - entered with lock held and interrupts disabled
+ */
+int __down_interruptible(struct semaphore *sem, unsigned long flags)
+{
+       struct task_struct *tsk = current;
+       struct sem_waiter waiter;
+       int ret;
+
+       semtrace(sem, "Entering __down_interruptible");
+
+       /* set up my own style of waitqueue */
+       waiter.task = tsk;
+       get_task_struct(tsk);
+
+       list_add_tail(&waiter.list, &sem->wait_list);
+
+       /* we don't need to touch the semaphore struct anymore */
+       set_task_state(tsk, TASK_INTERRUPTIBLE);
+
+       spin_unlock_irqrestore(&sem->wait_lock, flags);
+
+       /* wait to be given the semaphore */
+       ret = 0;
+       for (;;) {
+               if (!waiter.task)
+                       break;
+               if (unlikely(signal_pending(current)))
+                       goto interrupted;
+               schedule();
+               set_task_state(tsk, TASK_INTERRUPTIBLE);
+       }
+
+ out:
+       tsk->state = TASK_RUNNING;
+       semtrace(sem, "Leaving __down_interruptible");
+       return ret;
+
+ interrupted:
+       spin_lock_irqsave(&sem->wait_lock, flags);
+       list_del(&waiter.list);
+       spin_unlock_irqrestore(&sem->wait_lock, flags);
+
+       ret = 0;
+       if (!waiter.task) {
+               put_task_struct(current);
+               ret = -EINTR;
+       }
+       goto out;
+}
+EXPORT_SYMBOL(__down_interruptible);
+
+/*
+ * release a single token back to a semaphore
+ * - entered with lock held and interrupts disabled
+ */
+void __up(struct semaphore *sem)
+{
+       struct task_struct *tsk;
+       struct sem_waiter *waiter;
+
+       semtrace(sem, "Entering __up");
+
+       /* grant the token to the process at the front of the queue */
+       waiter = list_entry(sem->wait_list.next, struct sem_waiter, list);
+
+       /* We must be careful not to touch 'waiter' after we set ->task = NULL.
+        * It is an allocated on the waiter's stack and may become invalid at
+        * any time after that point (due to a wakeup from another source).
+        */
+       list_del_init(&waiter->list);
+       tsk = waiter->task;
+       smp_mb();
+       waiter->task = NULL;
+       wake_up_process(tsk);
+       put_task_struct(tsk);
+
+       semtrace(sem, "Leaving __up");
+}
+EXPORT_SYMBOL(__up);
diff --git a/arch/mn10300/kernel/setup.c b/arch/mn10300/kernel/setup.c
new file mode 100644 (file)
index 0000000..6b7ce26
--- /dev/null
@@ -0,0 +1,298 @@
+/* MN10300 Arch-specific initialisation
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/stddef.h>
+#include <linux/unistd.h>
+#include <linux/ptrace.h>
+#include <linux/slab.h>
+#include <linux/user.h>
+#include <linux/a.out.h>
+#include <linux/tty.h>
+#include <linux/ioport.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/bootmem.h>
+#include <linux/seq_file.h>
+#include <asm/processor.h>
+#include <linux/console.h>
+#include <asm/uaccess.h>
+#include <asm/system.h>
+#include <asm/setup.h>
+#include <asm/io.h>
+#include <asm/smp.h>
+#include <asm/proc/proc.h>
+#include <asm/busctl-regs.h>
+#include <asm/fpu.h>
+#include <asm/sections.h>
+
+struct mn10300_cpuinfo boot_cpu_data;
+
+/* For PCI or other memory-mapped resources */
+unsigned long pci_mem_start = 0x18000000;
+
+char redboot_command_line[COMMAND_LINE_SIZE] =
+       "console=ttyS0,115200 root=/dev/mtdblock3 rw";
+
+char __initdata redboot_platform_name[COMMAND_LINE_SIZE];
+
+static struct resource code_resource = {
+       .start  = 0x100000,
+       .end    = 0,
+       .name   = "Kernel code",
+};
+
+static struct resource data_resource = {
+       .start  = 0,
+       .end    = 0,
+       .name   = "Kernel data",
+};
+
+static unsigned long __initdata phys_memory_base;
+static unsigned long __initdata phys_memory_end;
+static unsigned long __initdata memory_end;
+unsigned long memory_size;
+
+struct thread_info *__current_ti = &init_thread_union.thread_info;
+struct task_struct *__current = &init_task;
+
+#define mn10300_known_cpus 3
+static const char *const mn10300_cputypes[] = {
+       "am33v1",
+       "am33v2",
+       "am34v1",
+       "unknown"
+};
+
+/*
+ *
+ */
+static void __init parse_mem_cmdline(char **cmdline_p)
+{
+       char *from, *to, c;
+
+       /* save unparsed command line copy for /proc/cmdline */
+       strcpy(boot_command_line, redboot_command_line);
+
+       /* see if there's an explicit memory size option */
+       from = redboot_command_line;
+       to = redboot_command_line;
+       c = ' ';
+
+       for (;;) {
+               if (c == ' ' && !memcmp(from, "mem=", 4)) {
+                       if (to != redboot_command_line)
+                               to--;
+                       memory_size = memparse(from + 4, &from);
+               }
+
+               c = *(from++);
+               if (!c)
+                       break;
+
+               *(to++) = c;
+       }
+
+       *to = '\0';
+       *cmdline_p = redboot_command_line;
+
+       if (memory_size == 0)
+               panic("Memory size not known\n");
+
+       memory_end = (unsigned long) CONFIG_KERNEL_RAM_BASE_ADDRESS +
+               memory_size;
+       if (memory_end > phys_memory_end)
+               memory_end = phys_memory_end;
+}
+
+/*
+ * architecture specific setup
+ */
+void __init setup_arch(char **cmdline_p)
+{
+       unsigned long bootmap_size;
+       unsigned long kstart_pfn, start_pfn, free_pfn, end_pfn;
+
+       cpu_init();
+       unit_setup();
+       parse_mem_cmdline(cmdline_p);
+
+       init_mm.start_code = (unsigned long)&_text;
+       init_mm.end_code = (unsigned long) &_etext;
+       init_mm.end_data = (unsigned long) &_edata;
+       init_mm.brk = (unsigned long) &_end;
+
+       code_resource.start = virt_to_bus(&_text);
+       code_resource.end = virt_to_bus(&_etext)-1;
+       data_resource.start = virt_to_bus(&_etext);
+       data_resource.end = virt_to_bus(&_edata)-1;
+
+#define PFN_UP(x)      (((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
+#define PFN_DOWN(x)    ((x) >> PAGE_SHIFT)
+#define PFN_PHYS(x)    ((x) << PAGE_SHIFT)
+
+       start_pfn = (CONFIG_KERNEL_RAM_BASE_ADDRESS >> PAGE_SHIFT);
+       kstart_pfn = PFN_UP(__pa(&_text));
+       free_pfn = PFN_UP(__pa(&_end));
+       end_pfn = PFN_DOWN(__pa(memory_end));
+
+       bootmap_size = init_bootmem_node(&contig_page_data,
+                                        free_pfn,
+                                        start_pfn,
+                                        end_pfn);
+
+       if (kstart_pfn > start_pfn)
+               free_bootmem(PFN_PHYS(start_pfn),
+                            PFN_PHYS(kstart_pfn - start_pfn));
+
+       free_bootmem(PFN_PHYS(free_pfn),
+                    PFN_PHYS(end_pfn - free_pfn));
+
+       /* If interrupt vector table is in main ram, then we need to
+          reserve the page it is occupying. */
+       if (CONFIG_INTERRUPT_VECTOR_BASE >= CONFIG_KERNEL_RAM_BASE_ADDRESS &&
+           CONFIG_INTERRUPT_VECTOR_BASE < memory_end)
+               reserve_bootmem(CONFIG_INTERRUPT_VECTOR_BASE, 1,
+                               BOOTMEM_DEFAULT);
+
+       reserve_bootmem(PAGE_ALIGN(PFN_PHYS(free_pfn)), bootmap_size,
+                       BOOTMEM_DEFAULT);
+
+#ifdef CONFIG_VT
+#if defined(CONFIG_VGA_CONSOLE)
+       conswitchp = &vga_con;
+#elif defined(CONFIG_DUMMY_CONSOLE)
+       conswitchp = &dummy_con;
+#endif
+#endif
+
+       paging_init();
+}
+
+/*
+ * perform CPU initialisation
+ */
+void __init cpu_init(void)
+{
+       unsigned long cpurev = CPUREV, type;
+       unsigned long base, size;
+
+       type = (CPUREV & CPUREV_TYPE) >> CPUREV_TYPE_S;
+       if (type > mn10300_known_cpus)
+               type = mn10300_known_cpus;
+
+       printk(KERN_INFO "Matsushita %s, rev %ld\n",
+              mn10300_cputypes[type],
+              (cpurev & CPUREV_REVISION) >> CPUREV_REVISION_S);
+
+       /* determine the memory size and base from the memory controller regs */
+       memory_size = 0;
+
+       base = SDBASE(0);
+       if (base & SDBASE_CE) {
+               size = (base & SDBASE_CBAM) << SDBASE_CBAM_SHIFT;
+               size = ~size + 1;
+               base &= SDBASE_CBA;
+
+               printk(KERN_INFO "SDRAM[0]: %luMb @%08lx\n", size >> 20, base);
+               memory_size += size;
+               phys_memory_base = base;
+       }
+
+       base = SDBASE(1);
+       if (base & SDBASE_CE) {
+               size = (base & SDBASE_CBAM) << SDBASE_CBAM_SHIFT;
+               size = ~size + 1;
+               base &= SDBASE_CBA;
+
+               printk(KERN_INFO "SDRAM[1]: %luMb @%08lx\n", size >> 20, base);
+               memory_size += size;
+               if (phys_memory_base == 0)
+                       phys_memory_base = base;
+       }
+
+       phys_memory_end = phys_memory_base + memory_size;
+
+#ifdef CONFIG_FPU
+       fpu_init_state();
+#endif
+}
+
+/*
+ * Get CPU information for use by the procfs.
+ */
+static int show_cpuinfo(struct seq_file *m, void *v)
+{
+       unsigned long cpurev = CPUREV, type, icachesz, dcachesz;
+
+       type = (CPUREV & CPUREV_TYPE) >> CPUREV_TYPE_S;
+       if (type > mn10300_known_cpus)
+               type = mn10300_known_cpus;
+
+       icachesz =
+               ((cpurev & CPUREV_ICWAY ) >> CPUREV_ICWAY_S)  *
+               ((cpurev & CPUREV_ICSIZE) >> CPUREV_ICSIZE_S) *
+               1024;
+
+       dcachesz =
+               ((cpurev & CPUREV_DCWAY ) >> CPUREV_DCWAY_S)  *
+               ((cpurev & CPUREV_DCSIZE) >> CPUREV_DCSIZE_S) *
+               1024;
+
+       seq_printf(m,
+                  "processor  : 0\n"
+                  "vendor_id  : Matsushita\n"
+                  "cpu core   : %s\n"
+                  "cpu rev    : %lu\n"
+                  "model name : " PROCESSOR_MODEL_NAME         "\n"
+                  "icache size: %lu\n"
+                  "dcache size: %lu\n",
+                  mn10300_cputypes[type],
+                  (cpurev & CPUREV_REVISION) >> CPUREV_REVISION_S,
+                  icachesz,
+                  dcachesz
+                  );
+
+       seq_printf(m,
+                  "ioclk speed: %lu.%02luMHz\n"
+                  "bogomips   : %lu.%02lu\n\n",
+                  MN10300_IOCLK / 1000000,
+                  (MN10300_IOCLK / 10000) % 100,
+                  loops_per_jiffy / (500000 / HZ),
+                  (loops_per_jiffy / (5000 / HZ)) % 100
+                  );
+
+       return 0;
+}
+
+static void *c_start(struct seq_file *m, loff_t *pos)
+{
+       return *pos < NR_CPUS ? cpu_data + *pos : NULL;
+}
+
+static void *c_next(struct seq_file *m, void *v, loff_t *pos)
+{
+       ++*pos;
+       return c_start(m, pos);
+}
+
+static void c_stop(struct seq_file *m, void *v)
+{
+}
+
+struct seq_operations cpuinfo_op = {
+       .start  = c_start,
+       .next   = c_next,
+       .stop   = c_stop,
+       .show   = show_cpuinfo,
+};
diff --git a/arch/mn10300/kernel/sigframe.h b/arch/mn10300/kernel/sigframe.h
new file mode 100644 (file)
index 0000000..0decba2
--- /dev/null
@@ -0,0 +1,33 @@
+/* MN10300 Signal frame definitions
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+struct sigframe
+{
+       void (*pretcode)(void);
+       int sig;
+       struct sigcontext *psc;
+       struct sigcontext sc;
+       struct fpucontext fpuctx;
+       unsigned long extramask[_NSIG_WORDS-1];
+       char retcode[8];
+};
+
+struct rt_sigframe
+{
+       void (*pretcode)(void);
+       int sig;
+       struct siginfo *pinfo;
+       void *puc;
+       struct siginfo info;
+       struct ucontext uc;
+       struct fpucontext fpuctx;
+       char retcode[8];
+};
diff --git a/arch/mn10300/kernel/signal.c b/arch/mn10300/kernel/signal.c
new file mode 100644 (file)
index 0000000..841ca99
--- /dev/null
@@ -0,0 +1,564 @@
+/* MN10300 Signal handling
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/smp_lock.h>
+#include <linux/kernel.h>
+#include <linux/signal.h>
+#include <linux/errno.h>
+#include <linux/wait.h>
+#include <linux/ptrace.h>
+#include <linux/unistd.h>
+#include <linux/stddef.h>
+#include <linux/tty.h>
+#include <linux/personality.h>
+#include <linux/suspend.h>
+#include <asm/cacheflush.h>
+#include <asm/ucontext.h>
+#include <asm/uaccess.h>
+#include <asm/fpu.h>
+#include "sigframe.h"
+
+#define DEBUG_SIG 0
+
+#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
+
+/*
+ * atomically swap in the new signal mask, and wait for a signal.
+ */
+asmlinkage long sys_sigsuspend(int history0, int history1, old_sigset_t mask)
+{
+       mask &= _BLOCKABLE;
+       spin_lock_irq(&current->sighand->siglock);
+       current->saved_sigmask = current->blocked;
+       siginitset(&current->blocked, mask);
+       recalc_sigpending();
+       spin_unlock_irq(&current->sighand->siglock);
+
+       current->state = TASK_INTERRUPTIBLE;
+       schedule();
+       set_thread_flag(TIF_RESTORE_SIGMASK);
+       return -ERESTARTNOHAND;
+}
+
+/*
+ * set signal action syscall
+ */
+asmlinkage long sys_sigaction(int sig,
+                             const struct old_sigaction __user *act,
+                             struct old_sigaction __user *oact)
+{
+       struct k_sigaction new_ka, old_ka;
+       int ret;
+
+       if (act) {
+               old_sigset_t mask;
+               if (verify_area(VERIFY_READ, act, sizeof(*act)) ||
+                   __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
+                   __get_user(new_ka.sa.sa_restorer, &act->sa_restorer))
+                       return -EFAULT;
+               __get_user(new_ka.sa.sa_flags, &act->sa_flags);
+               __get_user(mask, &act->sa_mask);
+               siginitset(&new_ka.sa.sa_mask, mask);
+       }
+
+       ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
+
+       if (!ret && oact) {
+               if (verify_area(VERIFY_WRITE, oact, sizeof(*oact)) ||
+                   __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
+                   __put_user(old_ka.sa.sa_restorer, &oact->sa_restorer))
+                       return -EFAULT;
+               __put_user(old_ka.sa.sa_flags, &oact->sa_flags);
+               __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
+       }
+
+       return ret;
+}
+
+/*
+ * set alternate signal stack syscall
+ */
+asmlinkage long sys_sigaltstack(const stack_t __user *uss, stack_t *uoss)
+{
+       return do_sigaltstack(uss, uoss, __frame->sp);
+}
+
+/*
+ * do a signal return; undo the signal stack.
+ */
+static int restore_sigcontext(struct pt_regs *regs,
+                             struct sigcontext __user *sc, long *_d0)
+{
+       unsigned int err = 0;
+
+       if (is_using_fpu(current))
+               fpu_kill_state(current);
+
+#define COPY(x) err |= __get_user(regs->x, &sc->x)
+       COPY(d1); COPY(d2); COPY(d3);
+       COPY(a0); COPY(a1); COPY(a2); COPY(a3);
+       COPY(e0); COPY(e1); COPY(e2); COPY(e3);
+       COPY(e4); COPY(e5); COPY(e6); COPY(e7);
+       COPY(lar); COPY(lir);
+       COPY(mdr); COPY(mdrq);
+       COPY(mcvf); COPY(mcrl); COPY(mcrh);
+       COPY(sp); COPY(pc);
+#undef COPY
+
+       {
+               unsigned int tmpflags;
+#ifndef CONFIG_MN10300_USING_JTAG
+#define USER_EPSW (EPSW_FLAG_Z | EPSW_FLAG_N | EPSW_FLAG_C | EPSW_FLAG_V | \
+                  EPSW_T | EPSW_nAR)
+#else
+#define USER_EPSW (EPSW_FLAG_Z | EPSW_FLAG_N | EPSW_FLAG_C | EPSW_FLAG_V | \
+                  EPSW_nAR)
+#endif
+               err |= __get_user(tmpflags, &sc->epsw);
+               regs->epsw = (regs->epsw & ~USER_EPSW) |
+                 (tmpflags & USER_EPSW);
+               regs->orig_d0 = -1;             /* disable syscall checks */
+       }
+
+       {
+               struct fpucontext *buf;
+               err |= __get_user(buf, &sc->fpucontext);
+               if (buf) {
+                       if (verify_area(VERIFY_READ, buf, sizeof(*buf)))
+                               goto badframe;
+                       err |= fpu_restore_sigcontext(buf);
+               }
+       }
+
+       err |= __get_user(*_d0, &sc->d0);
+       return err;
+
+badframe:
+       return 1;
+}
+
+/*
+ * standard signal return syscall
+ */
+asmlinkage long sys_sigreturn(void)
+{
+       struct sigframe __user *frame = (struct sigframe __user *) __frame->sp;
+       sigset_t set;
+       long d0;
+
+       if (verify_area(VERIFY_READ, frame, sizeof(*frame)))
+               goto badframe;
+       if (__get_user(set.sig[0], &frame->sc.oldmask))
+               goto badframe;
+
+       if (_NSIG_WORDS > 1 &&
+           __copy_from_user(&set.sig[1], &frame->extramask,
+                            sizeof(frame->extramask)))
+               goto badframe;
+
+       sigdelsetmask(&set, ~_BLOCKABLE);
+       spin_lock_irq(&current->sighand->siglock);
+       current->blocked = set;
+       recalc_sigpending();
+       spin_unlock_irq(&current->sighand->siglock);
+
+       if (restore_sigcontext(__frame, &frame->sc, &d0))
+               goto badframe;
+
+       return d0;
+
+badframe:
+       force_sig(SIGSEGV, current);
+       return 0;
+}
+
+/*
+ * realtime signal return syscall
+ */
+asmlinkage long sys_rt_sigreturn(void)
+{
+       struct rt_sigframe __user *frame =
+               (struct rt_sigframe __user *) __frame->sp;
+       sigset_t set;
+       unsigned long d0;
+
+       if (verify_area(VERIFY_READ, frame, sizeof(*frame)))
+               goto badframe;
+       if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
+               goto badframe;
+
+       sigdelsetmask(&set, ~_BLOCKABLE);
+       spin_lock_irq(&current->sighand->siglock);
+       current->blocked = set;
+       recalc_sigpending();
+       spin_unlock_irq(&current->sighand->siglock);
+
+       if (restore_sigcontext(__frame, &frame->uc.uc_mcontext, &d0))
+               goto badframe;
+
+       if (do_sigaltstack(&frame->uc.uc_stack, NULL, __frame->sp) == -EFAULT)
+               goto badframe;
+
+       return d0;
+
+badframe:
+       force_sig(SIGSEGV, current);
+       return 0;
+}
+
+/*
+ * store the userspace context into a signal frame
+ */
+static int setup_sigcontext(struct sigcontext __user *sc,
+                           struct fpucontext *fpuctx,
+                           struct pt_regs *regs,
+                           unsigned long mask)
+{
+       int tmp, err = 0;
+
+#define COPY(x) err |= __put_user(regs->x, &sc->x)
+       COPY(d0); COPY(d1); COPY(d2); COPY(d3);
+       COPY(a0); COPY(a1); COPY(a2); COPY(a3);
+       COPY(e0); COPY(e1); COPY(e2); COPY(e3);
+       COPY(e4); COPY(e5); COPY(e6); COPY(e7);
+       COPY(lar); COPY(lir);
+       COPY(mdr); COPY(mdrq);
+       COPY(mcvf); COPY(mcrl); COPY(mcrh);
+       COPY(sp); COPY(epsw); COPY(pc);
+#undef COPY
+
+       tmp = fpu_setup_sigcontext(fpuctx);
+       if (tmp < 0)
+               err = 1;
+       else
+               err |= __put_user(tmp ? fpuctx : NULL, &sc->fpucontext);
+
+       /* non-iBCS2 extensions.. */
+       err |= __put_user(mask, &sc->oldmask);
+
+       return err;
+}
+
+/*
+ * determine which stack to use..
+ */
+static inline void __user *get_sigframe(struct k_sigaction *ka,
+                                       struct pt_regs *regs,
+                                       size_t frame_size)
+{
+       unsigned long sp;
+
+       /* default to using normal stack */
+       sp = regs->sp;
+
+       /* this is the X/Open sanctioned signal stack switching.  */
+       if (ka->sa.sa_flags & SA_ONSTACK) {
+               if (!on_sig_stack(sp))
+                       sp = current->sas_ss_sp + current->sas_ss_size;
+       }
+
+       return (void __user *) ((sp - frame_size) & ~7UL);
+}
+
+/*
+ * set up a normal signal frame
+ */
+static int setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
+                      struct pt_regs *regs)
+{
+       struct sigframe __user *frame;
+       int rsig;
+
+       frame = get_sigframe(ka, regs, sizeof(*frame));
+
+       if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
+               goto give_sigsegv;
+
+       rsig = sig;
+       if (sig < 32 &&
+           current_thread_info()->exec_domain &&
+           current_thread_info()->exec_domain->signal_invmap)
+               rsig = current_thread_info()->exec_domain->signal_invmap[sig];
+
+       if (__put_user(rsig, &frame->sig) < 0 ||
+           __put_user(&frame->sc, &frame->psc) < 0)
+               goto give_sigsegv;
+
+       if (setup_sigcontext(&frame->sc, &frame->fpuctx, regs, set->sig[0]))
+               goto give_sigsegv;
+
+       if (_NSIG_WORDS > 1) {
+               if (__copy_to_user(frame->extramask, &set->sig[1],
+                                  sizeof(frame->extramask)))
+                       goto give_sigsegv;
+       }
+
+       /* set up to return from userspace.  If provided, use a stub already in
+        * userspace */
+       if (ka->sa.sa_flags & SA_RESTORER) {
+               if (__put_user(ka->sa.sa_restorer, &frame->pretcode))
+                       goto give_sigsegv;
+       } else {
+               if (__put_user((void (*)(void))frame->retcode,
+                              &frame->pretcode))
+                       goto give_sigsegv;
+               /* this is mov $,d0; syscall 0 */
+               if (__put_user(0x2c, (char *)(frame->retcode + 0)) ||
+                   __put_user(__NR_sigreturn, (char *)(frame->retcode + 1)) ||
+                   __put_user(0x00, (char *)(frame->retcode + 2)) ||
+                   __put_user(0xf0, (char *)(frame->retcode + 3)) ||
+                   __put_user(0xe0, (char *)(frame->retcode + 4)))
+                       goto give_sigsegv;
+               flush_icache_range((unsigned long) frame->retcode,
+                                  (unsigned long) frame->retcode + 5);
+       }
+
+       /* set up registers for signal handler */
+       regs->sp = (unsigned long) frame;
+       regs->pc = (unsigned long) ka->sa.sa_handler;
+       regs->d0 = sig;
+       regs->d1 = (unsigned long) &frame->sc;
+
+       set_fs(USER_DS);
+
+       /* the tracer may want to single-step inside the handler */
+       if (test_thread_flag(TIF_SINGLESTEP))
+               ptrace_notify(SIGTRAP);
+
+#if DEBUG_SIG
+       printk(KERN_DEBUG "SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
+              sig, current->comm, current->pid, frame, regs->pc,
+              frame->pretcode);
+#endif
+
+       return 0;
+
+give_sigsegv:
+       force_sig(SIGSEGV, current);
+       return -EFAULT;
+}
+
+/*
+ * set up a realtime signal frame
+ */
+static int setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
+                         sigset_t *set, struct pt_regs *regs)
+{
+       struct rt_sigframe __user *frame;
+       int rsig;
+
+       frame = get_sigframe(ka, regs, sizeof(*frame));
+
+       if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
+               goto give_sigsegv;
+
+       rsig = sig;
+       if (sig < 32 &&
+           current_thread_info()->exec_domain &&
+           current_thread_info()->exec_domain->signal_invmap)
+               rsig = current_thread_info()->exec_domain->signal_invmap[sig];
+
+       if (__put_user(rsig, &frame->sig) ||
+           __put_user(&frame->info, &frame->pinfo) ||
+           __put_user(&frame->uc, &frame->puc) ||
+           copy_siginfo_to_user(&frame->info, info))
+               goto give_sigsegv;
+
+       /* create the ucontext.  */
+       if (__put_user(0, &frame->uc.uc_flags) ||
+           __put_user(0, &frame->uc.uc_link) ||
+           __put_user((void *)current->sas_ss_sp, &frame->uc.uc_stack.ss_sp) ||
+           __put_user(sas_ss_flags(regs->sp), &frame->uc.uc_stack.ss_flags) ||
+           __put_user(current->sas_ss_size, &frame->uc.uc_stack.ss_size) ||
+           setup_sigcontext(&frame->uc.uc_mcontext,
+                            &frame->fpuctx, regs, set->sig[0]) ||
+           __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)))
+               goto give_sigsegv;
+
+       /* set up to return from userspace.  If provided, use a stub already in
+        * userspace */
+       if (ka->sa.sa_flags & SA_RESTORER) {
+               if (__put_user(ka->sa.sa_restorer, &frame->pretcode))
+                       goto give_sigsegv;
+       } else {
+               if (__put_user((void(*)(void))frame->retcode,
+                              &frame->pretcode) ||
+                   /* This is mov $,d0; syscall 0 */
+                   __put_user(0x2c, (char *)(frame->retcode + 0)) ||
+                   __put_user(__NR_rt_sigreturn,
+                              (char *)(frame->retcode + 1)) ||
+                   __put_user(0x00, (char *)(frame->retcode + 2)) ||
+                   __put_user(0xf0, (char *)(frame->retcode + 3)) ||
+                   __put_user(0xe0, (char *)(frame->retcode + 4)))
+                       goto give_sigsegv;
+
+               flush_icache_range((u_long) frame->retcode,
+                                  (u_long) frame->retcode + 5);
+       }
+
+       /* Set up registers for signal handler */
+       regs->sp = (unsigned long) frame;
+       regs->pc = (unsigned long) ka->sa.sa_handler;
+       regs->d0 = sig;
+       regs->d1 = (long) &frame->info;
+
+       set_fs(USER_DS);
+
+       /* the tracer may want to single-step inside the handler */
+       if (test_thread_flag(TIF_SINGLESTEP))
+               ptrace_notify(SIGTRAP);
+
+#if DEBUG_SIG
+       printk(KERN_DEBUG "SIG deliver %d (%s:%d): sp=%p pc=%lx ra=%p\n",
+              sig, current->comm, current->pid, frame, regs->pc,
+              frame->pretcode);
+#endif
+
+       return 0;
+
+give_sigsegv:
+       force_sig(SIGSEGV, current);
+       return -EFAULT;
+}
+
+/*
+ * handle the actual delivery of a signal to userspace
+ */
+static int handle_signal(int sig,
+                        siginfo_t *info, struct k_sigaction *ka,
+                        sigset_t *oldset, struct pt_regs *regs)
+{
+       int ret;
+
+       /* Are we from a system call? */
+       if (regs->orig_d0 >= 0) {
+               /* If so, check system call restarting.. */
+               switch (regs->d0) {
+               case -ERESTART_RESTARTBLOCK:
+               case -ERESTARTNOHAND:
+                       regs->d0 = -EINTR;
+                       break;
+
+               case -ERESTARTSYS:
+                       if (!(ka->sa.sa_flags & SA_RESTART)) {
+                               regs->d0 = -EINTR;
+                               break;
+                       }
+
+                       /* fallthrough */
+               case -ERESTARTNOINTR:
+                       regs->d0 = regs->orig_d0;
+                       regs->pc -= 2;
+               }
+       }
+
+       /* Set up the stack frame */
+       if (ka->sa.sa_flags & SA_SIGINFO)
+               ret = setup_rt_frame(sig, ka, info, oldset, regs);
+       else
+               ret = setup_frame(sig, ka, oldset, regs);
+
+       if (ret == 0) {
+               spin_lock_irq(&current->sighand->siglock);
+               sigorsets(&current->blocked, &current->blocked,
+                         &ka->sa.sa_mask);
+               if (!(ka->sa.sa_flags & SA_NODEFER))
+                       sigaddset(&current->blocked, sig);
+               recalc_sigpending();
+               spin_unlock_irq(&current->sighand->siglock);
+       }
+
+       return ret;
+}
+
+/*
+ * handle a potential signal
+ */
+static void do_signal(struct pt_regs *regs)
+{
+       struct k_sigaction ka;
+       siginfo_t info;
+       sigset_t *oldset;
+       int signr;
+
+       /* we want the common case to go fast, which is why we may in certain
+        * cases get here from kernel mode */
+       if (!user_mode(regs))
+               return;
+
+       if (test_thread_flag(TIF_RESTORE_SIGMASK))
+               oldset = &current->saved_sigmask;
+       else
+               oldset = &current->blocked;
+
+       signr = get_signal_to_deliver(&info, &ka, regs, NULL);
+       if (signr > 0) {
+               if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
+                       /* a signal was successfully delivered; the saved
+                        * sigmask will have been stored in the signal frame,
+                        * and will be restored by sigreturn, so we can simply
+                        * clear the TIF_RESTORE_SIGMASK flag */
+                       if (test_thread_flag(TIF_RESTORE_SIGMASK))
+                               clear_thread_flag(TIF_RESTORE_SIGMASK);
+               }
+
+               return;
+       }
+
+       /* did we come from a system call? */
+       if (regs->orig_d0 >= 0) {
+               /* restart the system call - no handlers present */
+               switch (regs->d0) {
+               case -ERESTARTNOHAND:
+               case -ERESTARTSYS:
+               case -ERESTARTNOINTR:
+                       regs->d0 = regs->orig_d0;
+                       regs->pc -= 2;
+                       break;
+
+               case -ERESTART_RESTARTBLOCK:
+                       regs->d0 = __NR_restart_syscall;
+                       regs->pc -= 2;
+                       break;
+               }
+       }
+
+       /* if there's no signal to deliver, we just put the saved sigmask
+        * back */
+       if (test_thread_flag(TIF_RESTORE_SIGMASK)) {
+               clear_thread_flag(TIF_RESTORE_SIGMASK);
+               sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
+       }
+}
+
+/*
+ * notification of userspace execution resumption
+ * - triggered by current->work.notify_resume
+ */
+asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags)
+{
+       /* Pending single-step? */
+       if (thread_info_flags & _TIF_SINGLESTEP) {
+#ifndef CONFIG_MN10300_USING_JTAG
+               regs->epsw |= EPSW_T;
+               clear_thread_flag(TIF_SINGLESTEP);
+#else
+               BUG(); /* no h/w single-step if using JTAG unit */
+#endif
+       }
+
+       /* deal with pending signal delivery */
+       if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
+               do_signal(regs);
+}
diff --git a/arch/mn10300/kernel/switch_to.S b/arch/mn10300/kernel/switch_to.S
new file mode 100644 (file)
index 0000000..630aad7
--- /dev/null
@@ -0,0 +1,71 @@
+###############################################################################
+#
+# MN10300 Context switch operation
+#
+# Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+# Written by David Howells (dhowells@redhat.com)
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public Licence
+# as published by the Free Software Foundation; either version
+# 2 of the Licence, or (at your option) any later version.
+#
+###############################################################################
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/thread_info.h>
+#include <asm/cpu-regs.h>
+
+       .text
+
+###############################################################################
+#
+# struct task_struct *__switch_to(struct thread_struct *prev,
+#                                struct thread_struct *next,
+#                                struct task_struct *prev_task)
+#
+###############################################################################
+ENTRY(__switch_to)
+       movm    [d2,d3,a2,a3,exreg1],(sp)
+       or      EPSW_NMID,epsw
+
+       mov     (44,sp),d2
+
+       mov     d0,a0
+       mov     d1,a1
+
+       # save prev context
+       mov     (__frame),d0
+       mov     d0,(THREAD_FRAME,a0)
+       mov     __switch_back,d0
+       mov     d0,(THREAD_PC,a0)
+       mov     sp,a2
+       mov     a2,(THREAD_SP,a0)
+       mov     a3,(THREAD_A3,a0)
+
+       mov     (THREAD_A3,a1),a3
+       mov     (THREAD_SP,a1),a2
+
+       # switch
+       mov     a2,sp
+
+       # load next context
+       GET_THREAD_INFO a2
+       mov     a2,(__current_ti)
+       mov     (TI_task,a2),a2
+       mov     a2,(__current)
+#ifdef CONFIG_MN10300_CURRENT_IN_E2
+       mov     a2,e2
+#endif
+
+       mov     (THREAD_FRAME,a1),a2
+       mov     a2,(__frame)
+       mov     (THREAD_PC,a1),a2
+       mov     d2,d0                   # for ret_from_fork
+       mov     d0,a0                   # for __switch_to
+
+       jmp     (a2)
+
+__switch_back:
+       and     ~EPSW_NMID,epsw
+       ret     [d2,d3,a2,a3,exreg1],32
diff --git a/arch/mn10300/kernel/sys_mn10300.c b/arch/mn10300/kernel/sys_mn10300.c
new file mode 100644 (file)
index 0000000..5f17a1e
--- /dev/null
@@ -0,0 +1,193 @@
+/* MN10300 Weird system calls
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/syscalls.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/smp_lock.h>
+#include <linux/sem.h>
+#include <linux/msg.h>
+#include <linux/shm.h>
+#include <linux/stat.h>
+#include <linux/mman.h>
+#include <linux/file.h>
+#include <linux/utsname.h>
+#include <linux/syscalls.h>
+#include <linux/tty.h>
+
+#include <asm/uaccess.h>
+
+#define MIN_MAP_ADDR   PAGE_SIZE       /* minimum fixed mmap address */
+
+/*
+ * sys_pipe() is the normal C calling standard for creating
+ * a pipe. It's not the way Unix traditionally does this, though.
+ */
+asmlinkage long sys_pipe(unsigned long __user *fildes)
+{
+       int fd[2];
+       int error;
+
+       error = do_pipe(fd);
+       if (!error) {
+               if (copy_to_user(fildes, fd, 2 * sizeof(int)))
+                       error = -EFAULT;
+       }
+       return error;
+}
+
+/*
+ * memory mapping syscall
+ */
+asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
+                         unsigned long prot, unsigned long flags,
+                         unsigned long fd, unsigned long pgoff)
+{
+       struct file *file = NULL;
+       long error = -EINVAL;
+
+       flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
+
+       if (flags & MAP_FIXED && addr < MIN_MAP_ADDR)
+               goto out;
+
+       error = -EBADF;
+       if (!(flags & MAP_ANONYMOUS)) {
+               file = fget(fd);
+               if (!file)
+                       goto out;
+       }
+
+       down_write(&current->mm->mmap_sem);
+       error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
+       up_write(&current->mm->mmap_sem);
+
+       if (file)
+               fput(file);
+out:
+       return error;
+}
+
+asmlinkage long old_mmap(unsigned long addr, unsigned long len,
+                        unsigned long prot, unsigned long flags,
+                        unsigned long fd, unsigned long offset)
+{
+       if (offset & ~PAGE_MASK)
+               return -EINVAL;
+       return sys_mmap2(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
+}
+
+struct sel_arg_struct {
+       unsigned long n;
+       fd_set *inp;
+       fd_set *outp;
+       fd_set *exp;
+       struct timeval *tvp;
+};
+
+asmlinkage int old_select(struct sel_arg_struct __user *arg)
+{
+       struct sel_arg_struct a;
+
+       if (copy_from_user(&a, arg, sizeof(a)))
+               return -EFAULT;
+       /* sys_select() does the appropriate kernel locking */
+       return sys_select(a.n, a.inp, a.outp, a.exp, a.tvp);
+}
+
+/*
+ * sys_ipc() is the de-multiplexer for the SysV IPC calls..
+ *
+ * This is really horribly ugly.
+ */
+asmlinkage long sys_ipc(uint call, int first, int second,
+                       int third, void __user *ptr, long fifth)
+{
+       int version, ret;
+
+       version = call >> 16; /* hack for backward compatibility */
+       call &= 0xffff;
+
+       switch (call) {
+       case SEMOP:
+               return sys_semtimedop(first, (struct sembuf __user *)ptr,
+                                     second, NULL);
+       case SEMTIMEDOP:
+               return sys_semtimedop(first, (struct sembuf __user *)ptr,
+                                     second,
+                                     (const struct timespec __user *)fifth);
+       case SEMGET:
+               return sys_semget(first, second, third);
+       case SEMCTL: {
+               union semun fourth;
+               if (!ptr)
+                       return -EINVAL;
+               if (get_user(fourth.__pad, (void __user * __user *) ptr))
+                       return -EFAULT;
+               return sys_semctl(first, second, third, fourth);
+       }
+
+       case MSGSND:
+               return sys_msgsnd(first, (struct msgbuf __user *) ptr,
+                                 second, third);
+       case MSGRCV:
+               switch (version) {
+               case 0: {
+                       struct ipc_kludge tmp;
+                       if (!ptr)
+                               return -EINVAL;
+
+                       if (copy_from_user(&tmp,
+                                          (struct ipc_kludge __user *) ptr,
+                                          sizeof(tmp)))
+                               return -EFAULT;
+                       return sys_msgrcv(first, tmp.msgp, second,
+                                         tmp.msgtyp, third);
+               }
+               default:
+                       return sys_msgrcv(first,
+                                         (struct msgbuf __user *) ptr,
+                                          second, fifth, third);
+               }
+       case MSGGET:
+               return sys_msgget((key_t) first, second);
+       case MSGCTL:
+               return sys_msgctl(first, second,
+                                  (struct msqid_ds __user *) ptr);
+
+       case SHMAT:
+               switch (version) {
+               default: {
+                       ulong raddr;
+                       ret = do_shmat(first, (char __user *) ptr, second,
+                                      &raddr);
+                       if (ret)
+                               return ret;
+                       return put_user(raddr, (ulong *) third);
+               }
+               case 1: /* iBCS2 emulator entry point */
+                       if (!segment_eq(get_fs(), get_ds()))
+                               return -EINVAL;
+                       return do_shmat(first, (char __user *) ptr, second,
+                                       (ulong *) third);
+               }
+       case SHMDT:
+               return sys_shmdt((char __user *)ptr);
+       case SHMGET:
+               return sys_shmget(first, second, third);
+       case SHMCTL:
+               return sys_shmctl(first, second,
+                                 (struct shmid_ds __user *) ptr);
+       default:
+               return -EINVAL;
+       }
+}
diff --git a/arch/mn10300/kernel/time.c b/arch/mn10300/kernel/time.c
new file mode 100644 (file)
index 0000000..ff492e3
--- /dev/null
@@ -0,0 +1,129 @@
+/* MN10300 Low level time management
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ * - Derived from arch/i386/kernel/time.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/interrupt.h>
+#include <linux/time.h>
+#include <linux/init.h>
+#include <linux/smp.h>
+#include <linux/profile.h>
+#include <asm/irq.h>
+#include <asm/div64.h>
+#include <asm/processor.h>
+#include <asm/intctl-regs.h>
+#include <asm/rtc.h>
+
+#ifdef CONFIG_MN10300_RTC
+unsigned long mn10300_ioclk;           /* system I/O clock frequency */
+unsigned long mn10300_iobclk;          /* system I/O clock frequency */
+unsigned long mn10300_tsc_per_HZ;      /* number of ioclks per jiffy */
+#endif /* CONFIG_MN10300_RTC */
+
+static unsigned long mn10300_last_tsc; /* time-stamp counter at last time
+                                        * interrupt occurred */
+
+static irqreturn_t timer_interrupt(int irq, void *dev_id);
+
+static struct irqaction timer_irq = {
+       .handler        = timer_interrupt,
+       .flags          = IRQF_DISABLED | IRQF_SHARED | IRQF_TIMER,
+       .mask           = CPU_MASK_NONE,
+       .name           = "timer",
+};
+
+/*
+ * scheduler clock - returns current time in nanosec units.
+ */
+unsigned long long sched_clock(void)
+{
+       union {
+               unsigned long long l;
+               u32 w[2];
+       } quot;
+
+       quot.w[0] = mn10300_last_tsc - get_cycles();
+       quot.w[1] = 1000000000;
+
+       asm("mulu %2,%3,%0,%1"
+           : "=r"(quot.w[1]), "=r"(quot.w[0])
+           : "0"(quot.w[1]), "1"(quot.w[0])
+           : "cc");
+
+       do_div(quot.l, MN10300_TSCCLK);
+
+       return quot.l;
+}
+
+/*
+ * advance the kernel's time keeping clocks (xtime and jiffies)
+ * - we use Timer 0 & 1 cascaded as a clock to nudge us the next time
+ *   there's a need to update
+ */
+static irqreturn_t timer_interrupt(int irq, void *dev_id)
+{
+       unsigned tsc, elapse;
+
+       write_seqlock(&xtime_lock);
+
+       while (tsc = get_cycles(),
+              elapse = mn10300_last_tsc - tsc, /* time elapsed since last
+                                                * tick */
+              elapse > MN10300_TSC_PER_HZ
+              ) {
+               mn10300_last_tsc -= MN10300_TSC_PER_HZ;
+
+               /* advance the kernel's time tracking system */
+               profile_tick(CPU_PROFILING);
+               do_timer(1);
+               update_process_times(user_mode(get_irq_regs()));
+               check_rtc_time();
+       }
+
+       write_sequnlock(&xtime_lock);
+       return IRQ_HANDLED;
+}
+
+/*
+ * initialise the various timers used by the main part of the kernel
+ */
+void __init time_init(void)
+{
+       /* we need the prescalar running to be able to use IOCLK/8
+        * - IOCLK runs at 1/4 (ST5 open) or 1/8 (ST5 closed) internal CPU clock
+        * - IOCLK runs at Fosc rate (crystal speed)
+        */
+       TMPSCNT |= TMPSCNT_ENABLE;
+
+       startup_timestamp_counter();
+
+       printk(KERN_INFO
+              "timestamp counter I/O clock running at %lu.%02lu"
+              " (calibrated against RTC)\n",
+              MN10300_TSCCLK / 1000000, (MN10300_TSCCLK / 10000) % 100);
+
+       xtime.tv_sec = get_initial_rtc_time();
+       xtime.tv_nsec = 0;
+
+       mn10300_last_tsc = TMTSCBC;
+
+       /* use timer 0 & 1 cascaded to tick at as close to HZ as possible */
+       setup_irq(TMJCIRQ, &timer_irq);
+
+       set_intr_level(TMJCIRQ, TMJCICR_LEVEL);
+
+       startup_jiffies_counter();
+
+#ifdef CONFIG_MN10300_WD_TIMER
+       /* start the watchdog timer */
+       watchdog_go();
+#endif
+}
diff --git a/arch/mn10300/kernel/traps.c b/arch/mn10300/kernel/traps.c
new file mode 100644 (file)
index 0000000..8b9dc6d
--- /dev/null
@@ -0,0 +1,619 @@
+/* MN10300 Exception handling
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Modified by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/ptrace.h>
+#include <linux/timer.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/smp_lock.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/spinlock.h>
+#include <linux/interrupt.h>
+#include <linux/kallsyms.h>
+#include <linux/pci.h>
+#include <linux/kdebug.h>
+#include <linux/bug.h>
+#include <linux/irq.h>
+#include <asm/processor.h>
+#include <asm/system.h>
+#include <asm/uaccess.h>
+#include <asm/io.h>
+#include <asm/atomic.h>
+#include <asm/smp.h>
+#include <asm/pgalloc.h>
+#include <asm/cacheflush.h>
+#include <asm/cpu-regs.h>
+#include <asm/busctl-regs.h>
+#include <asm/unit/leds.h>
+#include <asm/fpu.h>
+#include <asm/gdb-stub.h>
+#include <asm/sections.h>
+
+#if (CONFIG_INTERRUPT_VECTOR_BASE & 0xffffff)
+#error "INTERRUPT_VECTOR_BASE not aligned to 16MiB boundary!"
+#endif
+
+struct pt_regs *__frame; /* current frame pointer */
+EXPORT_SYMBOL(__frame);
+
+int kstack_depth_to_print = 24;
+
+spinlock_t die_lock = __SPIN_LOCK_UNLOCKED(die_lock);
+
+ATOMIC_NOTIFIER_HEAD(mn10300_die_chain);
+
+/*
+ * These constants are for searching for possible module text
+ * segments. MODULE_RANGE is a guess of how much space is likely
+ * to be vmalloced.
+ */
+#define MODULE_RANGE (8 * 1024 * 1024)
+
+#define DO_ERROR(signr, prologue, str, name)                   \
+asmlinkage void name(struct pt_regs *regs, u32 intcode)                \
+{                                                              \
+       prologue;                                               \
+       if (die_if_no_fixup(str, regs, intcode))                \
+               return;                                         \
+       force_sig(signr, current);                              \
+}
+
+#define DO_EINFO(signr, prologue, str, name, sicode)                   \
+asmlinkage void name(struct pt_regs *regs, u32 intcode)                        \
+{                                                                      \
+       siginfo_t info;                                                 \
+       prologue;                                                       \
+       if (die_if_no_fixup(str, regs, intcode))                        \
+               return;                                                 \
+       info.si_signo = signr;                                          \
+       if (signr == SIGILL && sicode == ILL_ILLOPC) {                  \
+               uint8_t opcode;                                         \
+               if (get_user(opcode, (uint8_t __user *)regs->pc) == 0)  \
+                       if (opcode == 0xff)                             \
+                               info.si_signo = SIGTRAP;                \
+       }                                                               \
+       info.si_errno = 0;                                              \
+       info.si_code = sicode;                                          \
+       info.si_addr = (void *) regs->pc;                               \
+       force_sig_info(info.si_signo, &info, current);                  \
+}
+
+DO_ERROR(SIGTRAP, {}, "trap",                  trap);
+DO_ERROR(SIGSEGV, {}, "ibreak",                        ibreak);
+DO_ERROR(SIGSEGV, {}, "obreak",                        obreak);
+DO_EINFO(SIGSEGV, {}, "access error",          access_error,   SEGV_ACCERR);
+DO_EINFO(SIGSEGV, {}, "insn access error",     insn_acc_error, SEGV_ACCERR);
+DO_EINFO(SIGSEGV, {}, "data access error",     data_acc_error, SEGV_ACCERR);
+DO_EINFO(SIGILL,  {}, "privileged opcode",     priv_op,        ILL_PRVOPC);
+DO_EINFO(SIGILL,  {}, "invalid opcode",                invalid_op,     ILL_ILLOPC);
+DO_EINFO(SIGILL,  {}, "invalid ex opcode",     invalid_exop,   ILL_ILLOPC);
+DO_EINFO(SIGBUS,  {}, "invalid address",       mem_error,      BUS_ADRERR);
+DO_EINFO(SIGBUS,  {}, "bus error",             bus_error,      BUS_ADRERR);
+DO_EINFO(SIGILL,  {}, "FPU invalid opcode",    fpu_invalid_op, ILL_COPROC);
+
+DO_ERROR(SIGTRAP,
+#ifndef CONFIG_MN10300_USING_JTAG
+        DCR &= ~0x0001,
+#else
+        {},
+#endif
+        "single step", istep);
+
+/*
+ * handle NMI
+ */
+asmlinkage void nmi(struct pt_regs *regs, enum exception_code code)
+{
+       /* see if gdbstub wants to deal with it */
+#ifdef CONFIG_GDBSTUB
+       if (gdbstub_intercept(regs, code))
+               return;
+#endif
+
+       printk(KERN_WARNING "--- Register Dump ---\n");
+       show_registers(regs);
+       printk(KERN_WARNING "---------------------\n");
+}
+
+/*
+ * show a stack trace from the specified stack pointer
+ */
+void show_trace(unsigned long *sp)
+{
+       unsigned long *stack, addr, module_start, module_end;
+       int i;
+
+       printk(KERN_EMERG "\n"
+              KERN_EMERG "Call Trace:");
+
+       stack = sp;
+       i = 0;
+       module_start = VMALLOC_START;
+       module_end = VMALLOC_END;
+
+       while (((long) stack & (THREAD_SIZE - 1)) != 0) {
+               addr = *stack++;
+               if (__kernel_text_address(addr)) {
+#if 1
+                       printk(" [<%08lx>]", addr);
+                       print_symbol(" %s", addr);
+                       printk("\n");
+#else
+                       if ((i % 6) == 0)
+                               printk("\n" KERN_EMERG "  ");
+                       printk("[<%08lx>] ", addr);
+                       i++;
+#endif
+               }
+       }
+
+       printk("\n");
+}
+
+/*
+ * show the raw stack from the specified stack pointer
+ */
+void show_stack(struct task_struct *task, unsigned long *sp)
+{
+       unsigned long *stack;
+       int i;
+
+       if (!sp)
+               sp = (unsigned long *) &sp;
+
+       stack = sp;
+       printk(KERN_EMERG "Stack:");
+       for (i = 0; i < kstack_depth_to_print; i++) {
+               if (((long) stack & (THREAD_SIZE - 1)) == 0)
+                       break;
+               if ((i % 8) == 0)
+                       printk("\n" KERN_EMERG "  ");
+               printk("%08lx ", *stack++);
+       }
+
+       show_trace(sp);
+}
+
+/*
+ * the architecture-independent dump_stack generator
+ */
+void dump_stack(void)
+{
+       unsigned long stack;
+
+       show_stack(current, &stack);
+}
+EXPORT_SYMBOL(dump_stack);
+
+/*
+ * dump the register file in the specified exception frame
+ */
+void show_registers_only(struct pt_regs *regs)
+{
+       unsigned long ssp;
+
+       ssp = (unsigned long) regs + sizeof(*regs);
+
+       printk(KERN_EMERG "PC:  %08lx EPSW:  %08lx  SSP: %08lx mode: %s\n",
+              regs->pc, regs->epsw, ssp, user_mode(regs) ? "User" : "Super");
+       printk(KERN_EMERG "d0:  %08lx   d1:  %08lx   d2: %08lx   d3: %08lx\n",
+              regs->d0, regs->d1, regs->d2, regs->d3);
+       printk(KERN_EMERG "a0:  %08lx   a1:  %08lx   a2: %08lx   a3: %08lx\n",
+              regs->a0, regs->a1, regs->a2, regs->a3);
+       printk(KERN_EMERG "e0:  %08lx   e1:  %08lx   e2: %08lx   e3: %08lx\n",
+              regs->e0, regs->e1, regs->e2, regs->e3);
+       printk(KERN_EMERG "e4:  %08lx   e5:  %08lx   e6: %08lx   e7: %08lx\n",
+              regs->e4, regs->e5, regs->e6, regs->e7);
+       printk(KERN_EMERG "lar: %08lx   lir: %08lx  mdr: %08lx  usp: %08lx\n",
+              regs->lar, regs->lir, regs->mdr, regs->sp);
+       printk(KERN_EMERG "cvf: %08lx   crl: %08lx  crh: %08lx  drq: %08lx\n",
+              regs->mcvf, regs->mcrl, regs->mcrh, regs->mdrq);
+       printk(KERN_EMERG "threadinfo=%p task=%p)\n",
+              current_thread_info(), current);
+
+       if ((unsigned long) current >= 0x90000000UL &&
+           (unsigned long) current < 0x94000000UL)
+               printk(KERN_EMERG "Process %s (pid: %d)\n",
+                      current->comm, current->pid);
+
+       printk(KERN_EMERG "CPUP:   %04hx\n", CPUP);
+       printk(KERN_EMERG "TBR:    %08x\n", TBR);
+       printk(KERN_EMERG "DEAR:   %08x\n", DEAR);
+       printk(KERN_EMERG "sISR:   %08x\n", sISR);
+       printk(KERN_EMERG "NMICR:  %04hx\n", NMICR);
+       printk(KERN_EMERG "BCBERR: %08x\n", BCBERR);
+       printk(KERN_EMERG "BCBEAR: %08x\n", BCBEAR);
+       printk(KERN_EMERG "MMUFCR: %08x\n", MMUFCR);
+       printk(KERN_EMERG "IPTEU : %08x  IPTEL2: %08x\n", IPTEU, IPTEL2);
+       printk(KERN_EMERG "DPTEU:  %08x  DPTEL2: %08x\n", DPTEU, DPTEL2);
+}
+
+/*
+ * dump the registers and the stack
+ */
+void show_registers(struct pt_regs *regs)
+{
+       unsigned long sp;
+       int i;
+
+       show_registers_only(regs);
+
+       if (!user_mode(regs))
+               sp = (unsigned long) regs + sizeof(*regs);
+       else
+               sp = regs->sp;
+
+       /* when in-kernel, we also print out the stack and code at the
+        * time of the fault..
+        */
+       if (!user_mode(regs)) {
+               printk(KERN_EMERG "\n");
+               show_stack(current, (unsigned long *) sp);
+
+#if 0
+               printk(KERN_EMERG "\n"
+                      KERN_EMERG "Code: ");
+               if (regs->pc < PAGE_OFFSET)
+                       goto bad;
+
+               for (i = 0; i < 20; i++) {
+                       unsigned char c;
+                       if (__get_user(c, &((unsigned char *) regs->pc)[i]))
+                               goto bad;
+                       printk("%02x ", c);
+               }
+#else
+               i = 0;
+#endif
+       }
+
+       printk("\n");
+       return;
+
+#if 0
+bad:
+       printk(KERN_EMERG " Bad PC value.");
+       break;
+#endif
+}
+
+/*
+ *
+ */
+void show_trace_task(struct task_struct *tsk)
+{
+       unsigned long sp = tsk->thread.sp;
+
+       /* User space on another CPU? */
+       if ((sp ^ (unsigned long) tsk) & (PAGE_MASK << 1))
+               return;
+
+       show_trace((unsigned long *) sp);
+}
+
+/*
+ * note the untimely death of part of the kernel
+ */
+void die(const char *str, struct pt_regs *regs, enum exception_code code)
+{
+       console_verbose();
+       spin_lock_irq(&die_lock);
+       printk(KERN_EMERG "\n"
+              KERN_EMERG "%s: %04x\n",
+              str, code & 0xffff);
+       show_registers(regs);
+
+       if (regs->pc >= 0x02000000 && regs->pc < 0x04000000 &&
+           (regs->epsw & (EPSW_IM | EPSW_IE)) != (EPSW_IM | EPSW_IE)) {
+               printk(KERN_EMERG "Exception in usermode interrupt handler\n");
+               printk(KERN_EMERG "\n"
+                      KERN_EMERG "  Please connect to kernel debugger !!\n");
+               asm volatile ("0: bra 0b");
+       }
+
+       spin_unlock_irq(&die_lock);
+       do_exit(SIGSEGV);
+}
+
+/*
+ * see if there's a fixup handler we can force a jump to when an exception
+ * happens due to something kernel code did
+ */
+int die_if_no_fixup(const char *str, struct pt_regs *regs,
+                   enum exception_code code)
+{
+       if (user_mode(regs))
+               return 0;
+
+       peripheral_leds_display_exception(code);
+
+       switch (code) {
+               /* see if we can fixup the kernel accessing memory */
+       case EXCEP_ITLBMISS:
+       case EXCEP_DTLBMISS:
+       case EXCEP_IAERROR:
+       case EXCEP_DAERROR:
+       case EXCEP_MEMERR:
+       case EXCEP_MISALIGN:
+       case EXCEP_BUSERROR:
+       case EXCEP_ILLDATACC:
+       case EXCEP_IOINSACC:
+       case EXCEP_PRIVINSACC:
+       case EXCEP_PRIVDATACC:
+       case EXCEP_DATINSACC:
+               if (fixup_exception(regs))
+                       return 1;
+       case EXCEP_UNIMPINS:
+               if (regs->pc && *(uint8_t *)regs->pc == 0xff)
+                       if (notify_die(DIE_BREAKPOINT, str, regs, code, 0, 0))
+                               return 1;
+               break;
+       default:
+               break;
+       }
+
+       /* see if gdbstub wants to deal with it */
+#ifdef CONFIG_GDBSTUB
+       if (gdbstub_intercept(regs, code))
+               return 1;
+#endif
+
+       if (notify_die(DIE_GPF, str, regs, code, 0, 0))
+               return 1;
+
+       /* make the process die as the last resort */
+       die(str, regs, code);
+}
+
+/*
+ * handle unsupported syscall instructions (syscall 1-15)
+ */
+static asmlinkage void unsupported_syscall(struct pt_regs *regs,
+                                          enum exception_code code)
+{
+       struct task_struct *tsk = current;
+       siginfo_t info;
+
+       /* catch a kernel BUG() */
+       if (code == EXCEP_SYSCALL15 && !user_mode(regs)) {
+               if (report_bug(regs->pc, regs) == BUG_TRAP_TYPE_BUG) {
+#ifdef CONFIG_GDBSTUB
+                       __gdbstub_bug_trap();
+#endif
+               }
+       }
+
+       regs->pc -= 2; /* syscall return addr is _after_ the instruction */
+
+       die_if_no_fixup("An unsupported syscall insn was used by the kernel\n",
+                       regs, code);
+
+       info.si_signo   = SIGILL;
+       info.si_errno   = ENOSYS;
+       info.si_code    = ILL_ILLTRP;
+       info.si_addr    = (void *) regs->pc;
+       force_sig_info(SIGILL, &info, tsk);
+}
+
+/*
+ * display the register file when the stack pointer gets clobbered
+ */
+asmlinkage void do_double_fault(struct pt_regs *regs)
+{
+       struct task_struct *tsk = current;
+
+       strcpy(tsk->comm, "emergency tsk");
+       tsk->pid = 0;
+       console_verbose();
+       printk(KERN_EMERG "--- double fault ---\n");
+       show_registers(regs);
+}
+
+/*
+ * asynchronous bus error (external, usually I/O DMA)
+ */
+asmlinkage void io_bus_error(u32 bcberr, u32 bcbear, struct pt_regs *regs)
+{
+       console_verbose();
+
+       printk(KERN_EMERG "\n"
+              KERN_EMERG "Asynchronous I/O Bus Error\n"
+              KERN_EMERG "==========================\n");
+
+       if (bcberr & BCBERR_BEME)
+               printk(KERN_EMERG "- Multiple recorded errors\n");
+
+       printk(KERN_EMERG "- Faulting Buses:%s%s%s\n",
+              bcberr & BCBERR_BEMR_CI  ? " CPU-Ins-Fetch" : "",
+              bcberr & BCBERR_BEMR_CD  ? " CPU-Data" : "",
+              bcberr & BCBERR_BEMR_DMA ? " DMA" : "");
+
+       printk(KERN_EMERG "- %s %s access made to %s at address %08x\n",
+              bcberr & BCBERR_BEBST ? "Burst" : "Single",
+              bcberr & BCBERR_BERW ? "Read" : "Write",
+              bcberr & BCBERR_BESB_MON  ? "Monitor Space" :
+              bcberr & BCBERR_BESB_IO   ? "Internal CPU I/O Space" :
+              bcberr & BCBERR_BESB_EX   ? "External I/O Bus" :
+              bcberr & BCBERR_BESB_OPEX ? "External Memory Bus" :
+              "On Chip Memory",
+              bcbear
+              );
+
+       printk(KERN_EMERG "- Detected by the %s\n",
+              bcberr&BCBERR_BESD ? "Bus Control Unit" : "Slave Bus");
+
+#ifdef CONFIG_PCI
+#define BRIDGEREGB(X) (*(volatile __u8  *)(0xBE040000 + (X)))
+#define BRIDGEREGW(X) (*(volatile __u16 *)(0xBE040000 + (X)))
+#define BRIDGEREGL(X) (*(volatile __u32 *)(0xBE040000 + (X)))
+
+       printk(KERN_EMERG "- PCI Memory Paging Reg:         %08x\n",
+              *(volatile __u32 *) (0xBFFFFFF4));
+       printk(KERN_EMERG "- PCI Bridge Base Address 0:     %08x\n",
+              BRIDGEREGL(PCI_BASE_ADDRESS_0));
+       printk(KERN_EMERG "- PCI Bridge AMPCI Base Address: %08x\n",
+              BRIDGEREGL(0x48));
+       printk(KERN_EMERG "- PCI Bridge Command:                %04hx\n",
+              BRIDGEREGW(PCI_COMMAND));
+       printk(KERN_EMERG "- PCI Bridge Status:                 %04hx\n",
+              BRIDGEREGW(PCI_STATUS));
+       printk(KERN_EMERG "- PCI Bridge Int Status:         %08hx\n",
+              BRIDGEREGL(0x4c));
+#endif
+
+       printk(KERN_EMERG "\n");
+       show_registers(regs);
+
+       panic("Halted due to asynchronous I/O Bus Error\n");
+}
+
+/*
+ * handle an exception for which a handler has not yet been installed
+ */
+asmlinkage void uninitialised_exception(struct pt_regs *regs,
+                                       enum exception_code code)
+{
+
+       /* see if gdbstub wants to deal with it */
+#ifdef CONFIG_GDBSTUB
+       if (gdbstub_intercept(regs, code))
+               return;
+#endif
+
+       peripheral_leds_display_exception(code);
+       printk(KERN_EMERG "Uninitialised Exception 0x%04x\n", code & 0xFFFF);
+       show_registers(regs);
+
+       for (;;)
+               continue;
+}
+
+/*
+ * set an interrupt stub to jump to a handler
+ * ! NOTE: this does *not* flush the caches
+ */
+void __init __set_intr_stub(enum exception_code code, void *handler)
+{
+       unsigned long addr;
+       u8 *vector = (u8 *)(CONFIG_INTERRUPT_VECTOR_BASE + code);
+
+       addr = (unsigned long) handler - (unsigned long) vector;
+       vector[0] = 0xdc;               /* JMP handler */
+       vector[1] = addr;
+       vector[2] = addr >> 8;
+       vector[3] = addr >> 16;
+       vector[4] = addr >> 24;
+       vector[5] = 0xcb;
+       vector[6] = 0xcb;
+       vector[7] = 0xcb;
+}
+
+/*
+ * set an interrupt stub to jump to a handler
+ */
+void __init set_intr_stub(enum exception_code code, void *handler)
+{
+       unsigned long addr;
+       u8 *vector = (u8 *)(CONFIG_INTERRUPT_VECTOR_BASE + code);
+
+       addr = (unsigned long) handler - (unsigned long) vector;
+       vector[0] = 0xdc;               /* JMP handler */
+       vector[1] = addr;
+       vector[2] = addr >> 8;
+       vector[3] = addr >> 16;
+       vector[4] = addr >> 24;
+       vector[5] = 0xcb;
+       vector[6] = 0xcb;
+       vector[7] = 0xcb;
+
+       mn10300_dcache_flush_inv();
+       mn10300_icache_inv();
+}
+
+/*
+ * set an interrupt stub to invoke the JTAG unit and then jump to a handler
+ */
+void __init set_jtag_stub(enum exception_code code, void *handler)
+{
+       unsigned long addr;
+       u8 *vector = (u8 *)(CONFIG_INTERRUPT_VECTOR_BASE + code);
+
+       addr = (unsigned long) handler - ((unsigned long) vector + 1);
+       vector[0] = 0xff;               /* PI to jump into JTAG debugger */
+       vector[1] = 0xdc;               /* jmp handler */
+       vector[2] = addr;
+       vector[3] = addr >> 8;
+       vector[4] = addr >> 16;
+       vector[5] = addr >> 24;
+       vector[6] = 0xcb;
+       vector[7] = 0xcb;
+
+       mn10300_dcache_flush_inv();
+       flush_icache_range((unsigned long) vector, (unsigned long) vector + 8);
+}
+
+/*
+ * initialise the exception table
+ */
+void __init trap_init(void)
+{
+       set_excp_vector(EXCEP_TRAP,             trap);
+       set_excp_vector(EXCEP_ISTEP,            istep);
+       set_excp_vector(EXCEP_IBREAK,           ibreak);
+       set_excp_vector(EXCEP_OBREAK,           obreak);
+
+       set_excp_vector(EXCEP_PRIVINS,          priv_op);
+       set_excp_vector(EXCEP_UNIMPINS,         invalid_op);
+       set_excp_vector(EXCEP_UNIMPEXINS,       invalid_exop);
+       set_excp_vector(EXCEP_MEMERR,           mem_error);
+       set_excp_vector(EXCEP_MISALIGN,         misalignment);
+       set_excp_vector(EXCEP_BUSERROR,         bus_error);
+       set_excp_vector(EXCEP_ILLINSACC,        insn_acc_error);
+       set_excp_vector(EXCEP_ILLDATACC,        data_acc_error);
+       set_excp_vector(EXCEP_IOINSACC,         insn_acc_error);
+       set_excp_vector(EXCEP_PRIVINSACC,       insn_acc_error);
+       set_excp_vector(EXCEP_PRIVDATACC,       data_acc_error);
+       set_excp_vector(EXCEP_DATINSACC,        insn_acc_error);
+       set_excp_vector(EXCEP_FPU_DISABLED,     fpu_disabled);
+       set_excp_vector(EXCEP_FPU_UNIMPINS,     fpu_invalid_op);
+       set_excp_vector(EXCEP_FPU_OPERATION,    fpu_exception);
+
+       set_excp_vector(EXCEP_NMI,              nmi);
+
+       set_excp_vector(EXCEP_SYSCALL1,         unsupported_syscall);
+       set_excp_vector(EXCEP_SYSCALL2,         unsupported_syscall);
+       set_excp_vector(EXCEP_SYSCALL3,         unsupported_syscall);
+       set_excp_vector(EXCEP_SYSCALL4,         unsupported_syscall);
+       set_excp_vector(EXCEP_SYSCALL5,         unsupported_syscall);
+       set_excp_vector(EXCEP_SYSCALL6,         unsupported_syscall);
+       set_excp_vector(EXCEP_SYSCALL7,         unsupported_syscall);
+       set_excp_vector(EXCEP_SYSCALL8,         unsupported_syscall);
+       set_excp_vector(EXCEP_SYSCALL9,         unsupported_syscall);
+       set_excp_vector(EXCEP_SYSCALL10,        unsupported_syscall);
+       set_excp_vector(EXCEP_SYSCALL11,        unsupported_syscall);
+       set_excp_vector(EXCEP_SYSCALL12,        unsupported_syscall);
+       set_excp_vector(EXCEP_SYSCALL13,        unsupported_syscall);
+       set_excp_vector(EXCEP_SYSCALL14,        unsupported_syscall);
+       set_excp_vector(EXCEP_SYSCALL15,        unsupported_syscall);
+}
+
+/*
+ * determine if a program counter value is a valid bug address
+ */
+int is_valid_bugaddr(unsigned long pc)
+{
+       return pc >= PAGE_OFFSET;
+}
diff --git a/arch/mn10300/kernel/vmlinux.lds.S b/arch/mn10300/kernel/vmlinux.lds.S
new file mode 100644 (file)
index 0000000..a3e80f4
--- /dev/null
@@ -0,0 +1,159 @@
+/* MN10300 Main kernel linker script
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#define __VMLINUX_LDS__
+#include <asm-generic/vmlinux.lds.h>
+#include <asm/thread_info.h>
+
+OUTPUT_FORMAT("elf32-am33lin", "elf32-am33lin", "elf32-am33lin")
+OUTPUT_ARCH(mn10300)
+ENTRY(_start)
+jiffies = jiffies_64;
+#ifndef CONFIG_MN10300_CURRENT_IN_E2
+current = __current;
+#endif
+SECTIONS
+{
+  . = CONFIG_KERNEL_TEXT_ADDRESS;
+  /* read-only */
+  _stext = .;
+  _text = .;                   /* Text and read-only data */
+  .text : {
+       *(
+       .text.head
+       .text
+       )
+       TEXT_TEXT
+       SCHED_TEXT
+       LOCK_TEXT
+       KPROBES_TEXT
+       *(.fixup)
+       *(.gnu.warning)
+       } = 0xcb
+
+  _etext = .;                  /* End of text section */
+
+  . = ALIGN(16);               /* Exception table */
+  __start___ex_table = .;
+  __ex_table : { *(__ex_table) }
+  __stop___ex_table = .;
+
+  BUG_TABLE
+
+  RODATA
+
+  /* writeable */
+  .data : {                    /* Data */
+       DATA_DATA
+       CONSTRUCTORS
+       }
+
+  . = ALIGN(4096);
+  __nosave_begin = .;
+  .data_nosave : { *(.data.nosave) }
+  . = ALIGN(4096);
+  __nosave_end = .;
+
+  . = ALIGN(4096);
+  .data.page_aligned : { *(.data.idt) }
+
+  . = ALIGN(32);
+  .data.cacheline_aligned : { *(.data.cacheline_aligned) }
+
+  /* rarely changed data like cpu maps */
+  . = ALIGN(32);
+  .data.read_mostly : AT(ADDR(.data.read_mostly)) {
+       *(.data.read_mostly)
+       _edata = .;             /* End of data section */
+  }
+
+  . = ALIGN(THREAD_SIZE);      /* init_task */
+  .data.init_task : { *(.data.init_task) }
+
+  /* might get freed after init */
+  . = ALIGN(4096);
+  .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
+       __smp_locks = .;
+       *(.smp_locks)
+       __smp_locks_end = .;
+  }
+
+  /* will be freed after init */
+  . = ALIGN(4096);             /* Init code and data */
+  __init_begin = .;
+  .init.text : {
+       _sinittext = .;
+       *(.init.text)
+       _einittext = .;
+  }
+  .init.data : { *(.init.data) }
+  . = ALIGN(16);
+  __setup_start = .;
+  .setup.init : { KEEP(*(.init.setup)) }
+  __setup_end = .;
+
+  __initcall_start = .;
+  .initcall.init : {
+       INITCALLS
+  }
+  __initcall_end = .;
+  __con_initcall_start = .;
+  .con_initcall.init : { *(.con_initcall.init) }
+  __con_initcall_end = .;
+
+  SECURITY_INIT
+  . = ALIGN(4);
+  __alt_instructions = .;
+  .altinstructions : { *(.altinstructions) }
+  __alt_instructions_end = .;
+ .altinstr_replacement : { *(.altinstr_replacement) }
+  /* .exit.text is discard at runtime, not link time, to deal with references
+     from .altinstructions and .eh_frame */
+  .exit.text : { *(.exit.text) }
+  .exit.data : { *(.exit.data) }
+
+#ifdef CONFIG_BLK_DEV_INITRD
+  . = ALIGN(4096);
+  __initramfs_start = .;
+  .init.ramfs : { *(.init.ramfs) }
+  __initramfs_end = .;
+#endif
+
+  . = ALIGN(32);
+  __per_cpu_start = .;
+  .data.percpu  : { *(.data.percpu) }
+  __per_cpu_end = .;
+  . = ALIGN(4096);
+  __init_end = .;
+  /* freed after init ends here */
+
+  __bss_start = .;             /* BSS */
+  .bss : {
+       *(.bss.page_aligned)
+       *(.bss)
+  }
+  . = ALIGN(4);
+  __bss_stop = .;
+
+  _end = . ;
+
+  /* This is where the kernel creates the early boot page tables */
+  . = ALIGN(4096);
+  pg0 = .;
+
+  /* Sections to be discarded */
+  /DISCARD/ : {
+       *(.exitcall.exit)
+       }
+
+  STABS_DEBUG
+
+  DWARF_DEBUG
+}
diff --git a/arch/mn10300/lib/Makefile b/arch/mn10300/lib/Makefile
new file mode 100644 (file)
index 0000000..fdfa9ec
--- /dev/null
@@ -0,0 +1,7 @@
+#
+# Makefile for the MN10300-specific library files..
+#
+
+lib-y = delay.o usercopy.o checksum.o bitops.o memcpy.o memmove.o memset.o
+lib-y += do_csum.o
+lib-y += __ashldi3.o __ashrdi3.o __lshrdi3.o negdi2.o
diff --git a/arch/mn10300/lib/__ashldi3.S b/arch/mn10300/lib/__ashldi3.S
new file mode 100644 (file)
index 0000000..a51a950
--- /dev/null
@@ -0,0 +1,51 @@
+/* MN10300 64-bit arithmetic left shift
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <asm/cache.h>
+
+        .text
+        .balign        L1_CACHE_BYTES
+
+###############################################################################
+#
+# unsigned long long __ashldi3(unsigned long long value [D1:D0],
+#                             unsigned by [(12,SP)])
+#
+###############################################################################
+        .globl __ashldi3
+        .type  __ashldi3,@function
+__ashldi3:
+       mov     (12,sp),a0
+       and     +63,a0
+       beq     __ashldi3_zero
+
+       cmp     +31,a0
+       bhi     __ashldi3_32plus
+
+       # the count is in the range 1-31
+       asl     a0,d1
+
+       mov     +32,a1
+       sub     a0,a1,a1                        # a1 = 32 - count
+       lsr     a1,d0,a1                        # get overflow from LSW -> MSW
+
+       or_asl  a1,d1,a0,d0                     # insert overflow into MSW and
+                                               # shift the LSW
+       rets
+
+       .balign L1_CACHE_BYTES
+       # the count is in the range 32-63
+__ashldi3_32plus:
+       asl     a0,d0,d1
+       clr     d0
+__ashldi3_zero:
+       rets
+
+       .size   __ashldi3, .-__ashldi3
diff --git a/arch/mn10300/lib/__ashrdi3.S b/arch/mn10300/lib/__ashrdi3.S
new file mode 100644 (file)
index 0000000..6f42382
--- /dev/null
@@ -0,0 +1,52 @@
+/* MN10300 64-bit arithmetic right shift
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <asm/cache.h>
+
+        .text
+        .balign        L1_CACHE_BYTES
+
+###############################################################################
+#
+# unsigned long long __ashrdi3(unsigned long long value [D1:D0],
+#                             unsigned by [(12,SP)])
+#
+###############################################################################
+        .globl __ashrdi3
+        .type  __ashrdi3,@function
+__ashrdi3:
+       mov     (12,sp),a0
+       and     +63,a0
+       beq     __ashrdi3_zero
+
+       cmp     +31,a0
+       bhi     __ashrdi3_32plus
+
+       # the count is in the range 1-31
+       lsr     a0,d0
+
+       mov     +32,a1
+       sub     a0,a1,a1                        # a1 = 32 - count
+       asl     a1,d1,a1                        # get underflow from MSW -> LSW
+
+       or_asr  a1,d0,a0,d1                     # insert underflow into LSW and
+                                               # shift the MSW
+       rets
+
+       .balign L1_CACHE_BYTES
+       # the count is in the range 32-63
+__ashrdi3_32plus:
+       asr     a0,d1,d0
+       ext     d0                              # sign-extend result through MDR
+       mov     mdr,d1
+__ashrdi3_zero:
+       rets
+
+       .size   __ashrdi3, .-__ashrdi3
diff --git a/arch/mn10300/lib/__lshrdi3.S b/arch/mn10300/lib/__lshrdi3.S
new file mode 100644 (file)
index 0000000..a686aef
--- /dev/null
@@ -0,0 +1,52 @@
+/* MN10300 64-bit logical right shift
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <asm/cache.h>
+
+        .text
+        .balign        L1_CACHE_BYTES
+
+###############################################################################
+#
+# unsigned long long __lshrdi3(unsigned long long value [D1:D0],
+#                             unsigned by [(12,SP)])
+#
+###############################################################################
+        .globl __lshrdi3
+        .type  __lshrdi3,@function
+__lshrdi3:
+       mov     (12,sp),a0
+       and     +63,a0
+       beq     __lshrdi3_zero
+
+       cmp     +31,a0
+       bhi     __lshrdi3_32plus
+
+       # the count is in the range 1-31
+       lsr     a0,d0
+
+       mov     +32,a1
+       sub     a0,a1,a1                        # a1 = 32 - count
+       asl     a1,d1,a1                        # get underflow from MSW -> LSW
+
+       or_lsr  a1,d0,a0,d1                     # insert underflow into LSW and
+                                               # shift the MSW
+       rets
+
+       .balign L1_CACHE_BYTES
+       # the count is in the range 32-63
+__lshrdi3_32plus:
+       lsr     a0,d1,d0
+       clr     d1
+__lshrdi3_zero:
+       rets
+
+       .size   __lshrdi3, .-__lshrdi3
diff --git a/arch/mn10300/lib/ashrdi3.c b/arch/mn10300/lib/ashrdi3.c
new file mode 100644 (file)
index 0000000..c54f61d
--- /dev/null
@@ -0,0 +1,61 @@
+/* ashrdi3.c extracted from gcc-2.7.2/libgcc2.c which is: */
+/* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+
+This file is part of GNU CC.
+
+GNU CC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public Licence as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU CC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public Licence for more details.
+
+You should have received a copy of the GNU General Public Licence
+along with GNU CC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define BITS_PER_UNIT 8
+
+typedef         int SItype     __attribute__((mode(SI)));
+typedef unsigned int USItype   __attribute__((mode(SI)));
+typedef                 int DItype     __attribute__((mode(DI)));
+typedef                 int word_type  __attribute__((mode(__word__)));
+
+struct DIstruct {
+       SItype low;
+       SItype high;
+};
+
+union DIunion {
+       struct DIstruct s;
+       DItype          ll;
+};
+
+DItype __ashrdi3(DItype u, word_type b)
+{
+       union DIunion w;
+       union DIunion uu;
+       word_type bm;
+
+       if (b == 0)
+               return u;
+
+       uu.ll = u;
+
+       bm = (sizeof(SItype) * BITS_PER_UNIT) - b;
+       if (bm <= 0) {
+               /* w.s.high = 1..1 or 0..0 */
+               w.s.high = uu.s.high >> (sizeof(SItype) * BITS_PER_UNIT - 1);
+               w.s.low = uu.s.high >> -bm;
+       } else {
+               USItype carries = (USItype)uu.s.high << bm;
+               w.s.high = uu.s.high >> b;
+               w.s.low = ((USItype)uu.s.low >> b) | carries;
+       }
+
+       return w.ll;
+}
diff --git a/arch/mn10300/lib/bitops.c b/arch/mn10300/lib/bitops.c
new file mode 100644 (file)
index 0000000..440a7dc
--- /dev/null
@@ -0,0 +1,51 @@
+/* MN10300 Non-trivial bit operations
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/module.h>
+#include <asm/bitops.h>
+#include <asm/system.h>
+
+/*
+ * try flipping a bit using BSET and BCLR
+ */
+void change_bit(int nr, volatile void *addr)
+{
+       if (test_bit(nr, addr))
+               goto try_clear_bit;
+
+try_set_bit:
+       if (!test_and_set_bit(nr, addr))
+               return;
+
+try_clear_bit:
+       if (test_and_clear_bit(nr, addr))
+               return;
+
+       goto try_set_bit;
+}
+
+/*
+ * try flipping a bit using BSET and BCLR and returning the old value
+ */
+int test_and_change_bit(int nr, volatile void *addr)
+{
+       if (test_bit(nr, addr))
+               goto try_clear_bit;
+
+try_set_bit:
+       if (!test_and_set_bit(nr, addr))
+               return 0;
+
+try_clear_bit:
+       if (test_and_clear_bit(nr, addr))
+               return 1;
+
+       goto try_set_bit;
+}
diff --git a/arch/mn10300/lib/checksum.c b/arch/mn10300/lib/checksum.c
new file mode 100644 (file)
index 0000000..274f29e
--- /dev/null
@@ -0,0 +1,99 @@
+/* MN10300 Optimised checksumming wrappers
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <asm/byteorder.h>
+#include <asm/uaccess.h>
+#include <asm/checksum.h>
+#include "internal.h"
+
+static inline unsigned short from32to16(__wsum sum)
+{
+       asm("   add     %1,%0           \n"
+           "   addc    0xffff,%0       \n"
+           : "=r" (sum)
+           : "r" (sum << 16), "0" (sum & 0xffff0000)
+           );
+       return sum >> 16;
+}
+
+__sum16 ip_fast_csum(const void *iph, unsigned int ihl)
+{
+       return ~do_csum(iph, ihl * 4);
+}
+EXPORT_SYMBOL(ip_fast_csum);
+
+__wsum csum_partial(const void *buff, int len, __wsum sum)
+{
+       __wsum result;
+
+       result = do_csum(buff, len);
+       result += sum;
+       if (sum > result)
+               result++;
+       return result;
+}
+EXPORT_SYMBOL(csum_partial);
+
+__sum16 ip_compute_csum(const void *buff, int len)
+{
+       return ~from32to16(do_csum(buff, len));
+}
+EXPORT_SYMBOL(ip_compute_csum);
+
+__wsum csum_partial_copy(const void *src, void *dst, int len, __wsum sum)
+{
+       copy_from_user(dst, src, len);
+       return csum_partial(dst, len, sum);
+}
+EXPORT_SYMBOL(csum_partial_copy);
+
+__wsum csum_partial_copy_nocheck(const void *src, void *dst,
+                                int len, __wsum sum)
+{
+       sum = csum_partial(src, len, sum);
+       memcpy(dst, src, len);
+       return sum;
+}
+EXPORT_SYMBOL(csum_partial_copy_nocheck);
+
+__wsum csum_partial_copy_from_user(const void *src, void *dst,
+                                  int len, __wsum sum,
+                                  int *err_ptr)
+{
+       int missing;
+
+       missing = copy_from_user(dst, src, len);
+       if (missing) {
+               memset(dst + len - missing, 0, missing);
+               *err_ptr = -EFAULT;
+       }
+
+       return csum_partial(dst, len, sum);
+}
+EXPORT_SYMBOL(csum_partial_copy_from_user);
+
+__wsum csum_and_copy_to_user(const void *src, void *dst,
+                            int len, __wsum sum,
+                            int *err_ptr)
+{
+       int missing;
+
+       missing = copy_to_user(dst, src, len);
+       if (missing) {
+               memset(dst + len - missing, 0, missing);
+               *err_ptr = -EFAULT;
+       }
+
+       return csum_partial(src, len, sum);
+}
+EXPORT_SYMBOL(csum_and_copy_to_user);
diff --git a/arch/mn10300/lib/delay.c b/arch/mn10300/lib/delay.c
new file mode 100644 (file)
index 0000000..cce66bc
--- /dev/null
@@ -0,0 +1,50 @@
+/* MN10300 Short delay interpolation routines
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/delay.h>
+#include <asm/div64.h>
+
+/*
+ * basic delay loop
+ */
+void __delay(unsigned long loops)
+{
+       int d0;
+
+       asm volatile(
+               "       bra     1f      \n"
+               "       .align  4       \n"
+               "1:     bra     2f      \n"
+               "       .align  4       \n"
+               "2:     add     -1,%0   \n"
+               "       bne     2b      \n"
+               : "=&d" (d0)
+               : "0" (loops));
+}
+EXPORT_SYMBOL(__delay);
+
+/*
+ * handle a delay specified in terms of microseconds
+ */
+void __udelay(unsigned long usecs)
+{
+       signed long ioclk, stop;
+
+       /* usecs * CLK / 1E6 */
+       stop = __muldiv64u(usecs, MN10300_TSCCLK, 1000000);
+       stop = TMTSCBC - stop;
+
+       do {
+               ioclk = TMTSCBC;
+       } while (stop < ioclk);
+}
+EXPORT_SYMBOL(__udelay);
diff --git a/arch/mn10300/lib/do_csum.S b/arch/mn10300/lib/do_csum.S
new file mode 100644 (file)
index 0000000..e138994
--- /dev/null
@@ -0,0 +1,162 @@
+/* Optimised simple memory checksum
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <asm/cache.h>
+
+        .section .text
+        .balign        L1_CACHE_BYTES
+
+###############################################################################
+#
+# unsigned int do_csum(const unsigned char *buff, size_t len)
+#
+###############################################################################
+       .globl  do_csum
+        .type  do_csum,@function
+do_csum:
+       movm    [d2,d3],(sp)
+       mov     d0,(12,sp)
+       mov     d1,(16,sp)
+       mov     d1,d2                           # count
+       mov     d0,a0                           # buff
+       clr     d1                              # accumulator
+
+       cmp     +0,d2
+       beq     do_csum_done                    # return if zero-length buffer
+
+       # 4-byte align the buffer pointer
+       btst    +3,a0
+       beq     do_csum_now_4b_aligned
+
+       btst    +1,a0
+       beq     do_csum_addr_not_odd
+       movbu   (a0),d0
+       inc     a0
+       asl     +8,d0
+       add     d0,d1
+       addc    +0,d1
+       add     -1,d2
+do_csum_addr_not_odd:
+
+       cmp     +2,d2
+       bcs     do_csum_fewer_than_4
+       btst    +2,a0
+       beq     do_csum_now_4b_aligned
+       movhu   (a0+),d0
+       add     d0,d1
+       addc    +0,d1
+       add     -2,d2
+       cmp     +4,d2
+       bcs     do_csum_fewer_than_4
+
+do_csum_now_4b_aligned:
+       # we want to checksum as much as we can in chunks of 32 bytes
+       cmp     +31,d2
+       bls     do_csum_remainder               # 4-byte aligned remainder
+
+       add     -32,d2
+       mov     +32,d3
+
+do_csum_loop:
+       mov     (a0+),d0
+       add     d0,d1
+       mov     (a0+),e0
+       addc    e0,d1
+       mov     (a0+),e1
+       addc    e1,d1
+       mov     (a0+),e3
+       addc    e3,d1
+       mov     (a0+),d0
+       addc    d0,d1
+       mov     (a0+),e0
+       addc    e0,d1
+       mov     (a0+),e1
+       addc    e1,d1
+       mov     (a0+),e3
+       addc    e3,d1
+       addc    +0,d1
+
+       sub     d3,d2
+       bcc     do_csum_loop
+
+       add     d3,d2
+       beq     do_csum_done
+
+do_csum_remainder:
+       # cut 16-31 bytes down to 0-15
+       cmp     +16,d2
+       bcs     do_csum_fewer_than_16
+       mov     (a0+),d0
+       add     d0,d1
+       mov     (a0+),e0
+       addc    e0,d1
+       mov     (a0+),e1
+       addc    e1,d1
+       mov     (a0+),e3
+       addc    e3,d1
+       addc    +0,d1
+       add     -16,d2
+       beq     do_csum_done
+
+do_csum_fewer_than_16:
+       # copy the remaining whole words
+       cmp     +4,d2
+       bcs     do_csum_fewer_than_4
+       cmp     +8,d2
+       bcs     do_csum_one_word
+       cmp     +12,d2
+       bcs     do_csum_two_words
+       mov     (a0+),d0
+       add     d0,d1
+       addc    +0,d1
+do_csum_two_words:
+       mov     (a0+),d0
+       add     d0,d1
+       addc    +0,d1
+do_csum_one_word:
+       mov     (a0+),d0
+       add     d0,d1
+       addc    +0,d1
+
+do_csum_fewer_than_4:
+       and     +3,d2
+       beq     do_csum_done
+       xor_cmp d0,d0,+2,d2
+       bcs     do_csum_fewer_than_2
+       movhu   (a0+),d0
+do_csum_fewer_than_2:
+       and     +1,d2
+       beq     do_csum_add_last_bit
+       movbu   (a0),d3
+       add     d3,d0
+do_csum_add_last_bit:
+       add     d0,d1
+       addc    +0,d1
+
+do_csum_done:
+       # compress the checksum down to 16 bits
+       mov     +0xffff0000,d2
+       and     d1,d2
+       asl     +16,d1
+       add     d2,d1,d0
+       addc    +0xffff,d0
+       lsr     +16,d0
+
+       # flip the halves of the word result if the buffer was oddly aligned
+       mov     (12,sp),d1
+       and     +1,d1
+       beq     do_csum_not_oddly_aligned
+       swaph   d0,d0                           # exchange bits 15:8 with 7:0
+
+do_csum_not_oddly_aligned:
+       ret     [d2,d3],8
+
+do_csum_end:
+       .size   do_csum, do_csum_end-do_csum
diff --git a/arch/mn10300/lib/internal.h b/arch/mn10300/lib/internal.h
new file mode 100644 (file)
index 0000000..0014eee
--- /dev/null
@@ -0,0 +1,15 @@
+/* Internal definitions for the arch part of the kernel library
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+/*
+ * do_csum.S
+ */
+extern unsigned int do_csum(const unsigned char *, size_t);
diff --git a/arch/mn10300/lib/lshrdi3.c b/arch/mn10300/lib/lshrdi3.c
new file mode 100644 (file)
index 0000000..e05e64e
--- /dev/null
@@ -0,0 +1,60 @@
+/* lshrdi3.c extracted from gcc-2.7.2/libgcc2.c which is: */
+/* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+
+This file is part of GNU CC.
+
+GNU CC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public Licence as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU CC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public Licence for more details.
+
+You should have received a copy of the GNU General Public Licence
+along with GNU CC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+#define BITS_PER_UNIT 8
+
+typedef         int SItype     __attribute__((mode(SI)));
+typedef unsigned int USItype   __attribute__((mode(SI)));
+typedef                 int DItype     __attribute__((mode(DI)));
+typedef                 int word_type  __attribute__((mode(__word__)));
+
+struct DIstruct {
+       SItype  low;
+       SItype  high;
+};
+
+union DIunion {
+       struct DIstruct s;
+       DItype          ll;
+};
+
+DItype __lshrdi3(DItype u, word_type b)
+{
+       union DIunion w;
+       word_type bm;
+       union DIunion uu;
+
+       if (b == 0)
+               return u;
+
+       uu.ll = u;
+
+       bm = (sizeof(SItype) * BITS_PER_UNIT) - b;
+       if (bm <= 0) {
+               w.s.high = 0;
+               w.s.low = (USItype) uu.s.high >> -bm;
+       } else {
+               USItype carries = (USItype) uu.s.high << bm;
+               w.s.high = (USItype) uu.s.high >> b;
+               w.s.low = ((USItype) uu.s.low >> b) | carries;
+       }
+
+       return w.ll;
+}
diff --git a/arch/mn10300/lib/memcpy.S b/arch/mn10300/lib/memcpy.S
new file mode 100644 (file)
index 0000000..25fb9bb
--- /dev/null
@@ -0,0 +1,135 @@
+/* MN10300 Optimised simple memory to memory copy
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <asm/cache.h>
+
+        .section .text
+        .balign        L1_CACHE_BYTES
+
+###############################################################################
+#
+# void *memcpy(void *dst, const void *src, size_t n)
+#
+###############################################################################
+       .globl  memcpy
+        .type  memcpy,@function
+memcpy:
+       movm    [d2,d3],(sp)
+       mov     d0,(12,sp)
+       mov     d1,(16,sp)
+       mov     (20,sp),d2                      # count
+       mov     d0,a0                           # dst
+       mov     d1,a1                           # src
+       mov     d0,e3                           # the return value
+
+       cmp     +0,d2
+       beq     memcpy_done                     # return if zero-length copy
+
+       # see if the three parameters are all four-byte aligned
+       or      d0,d1,d3
+       or      d2,d3
+       and     +3,d3
+       bne     memcpy_1                        # jump if not
+
+       # we want to transfer as much as we can in chunks of 32 bytes
+       cmp     +31,d2
+       bls     memcpy_4_remainder              # 4-byte aligned remainder
+
+       movm    [exreg1],(sp)
+       add     -32,d2
+       mov     +32,d3
+
+memcpy_4_loop:
+       mov     (a1+),d0
+       mov     (a1+),d1
+       mov     (a1+),e0
+       mov     (a1+),e1
+       mov     (a1+),e4
+       mov     (a1+),e5
+       mov     (a1+),e6
+       mov     (a1+),e7
+       mov     d0,(a0+)
+       mov     d1,(a0+)
+       mov     e0,(a0+)
+       mov     e1,(a0+)
+       mov     e4,(a0+)
+       mov     e5,(a0+)
+       mov     e6,(a0+)
+       mov     e7,(a0+)
+
+       sub     d3,d2
+       bcc     memcpy_4_loop
+
+       movm    (sp),[exreg1]
+       add     d3,d2
+       beq     memcpy_4_no_remainder
+
+memcpy_4_remainder:
+       # cut 4-7 words down to 0-3
+       cmp     +16,d2
+       bcs     memcpy_4_three_or_fewer_words
+       mov     (a1+),d0
+       mov     (a1+),d1
+       mov     (a1+),e0
+       mov     (a1+),e1
+       mov     d0,(a0+)
+       mov     d1,(a0+)
+       mov     e0,(a0+)
+       mov     e1,(a0+)
+       add     -16,d2
+       beq     memcpy_4_no_remainder
+
+       # copy the remaining 1, 2 or 3 words
+memcpy_4_three_or_fewer_words:
+       cmp     +8,d2
+       bcs     memcpy_4_one_word
+       beq     memcpy_4_two_words
+       mov     (a1+),d0
+       mov     d0,(a0+)
+memcpy_4_two_words:
+       mov     (a1+),d0
+       mov     d0,(a0+)
+memcpy_4_one_word:
+       mov     (a1+),d0
+       mov     d0,(a0+)
+
+memcpy_4_no_remainder:
+       # check we copied the correct amount
+       # TODO: REMOVE CHECK
+       sub     e3,a0,d2
+       mov     (20,sp),d1
+       cmp     d2,d1
+       beq     memcpy_done
+       break
+       break
+       break
+
+memcpy_done:
+       mov     e3,a0
+       ret     [d2,d3],8
+
+       # handle misaligned copying
+memcpy_1:
+       add     -1,d2
+       mov     +1,d3
+       setlb                                   # setlb requires the next insns
+                                               # to occupy exactly 4 bytes
+
+       sub     d3,d2
+       movbu   (a1),d0
+       movbu   d0,(a0)
+       add_add d3,a1,d3,a0
+       lcc
+
+       mov     e3,a0
+       ret     [d2,d3],8
+
+memcpy_end:
+       .size   memcpy, memcpy_end-memcpy
diff --git a/arch/mn10300/lib/memmove.S b/arch/mn10300/lib/memmove.S
new file mode 100644 (file)
index 0000000..20b07b6
--- /dev/null
@@ -0,0 +1,160 @@
+/* MN10300 Optimised simple memory to memory copy, with support for overlapping
+ * regions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <asm/cache.h>
+
+        .section .text
+        .balign        L1_CACHE_BYTES
+
+###############################################################################
+#
+# void *memmove(void *dst, const void *src, size_t n)
+#
+###############################################################################
+       .globl  memmove
+        .type  memmove,@function
+memmove:
+       # fall back to memcpy if dst < src to work bottom up
+       cmp     d1,d0
+       bcs     memmove_memcpy
+
+       # work top down
+       movm    [d2,d3],(sp)
+       mov     d0,(12,sp)
+       mov     d1,(16,sp)
+       mov     (20,sp),d2                      # count
+       add     d0,d2,a0                        # dst end
+       add     d1,d2,a1                        # src end
+       mov     d0,e3                           # the return value
+
+       cmp     +0,d2
+       beq     memmove_done                    # return if zero-length copy
+
+       # see if the three parameters are all four-byte aligned
+       or      d0,d1,d3
+       or      d2,d3
+       and     +3,d3
+       bne     memmove_1                       # jump if not
+
+       # we want to transfer as much as we can in chunks of 32 bytes
+       add     -4,a1
+       cmp     +31,d2
+       bls     memmove_4_remainder             # 4-byte aligned remainder
+
+       add     -32,d2
+       mov     +32,d3
+
+memmove_4_loop:
+       mov     (a1),d0
+       sub_sub +4,a1,+4,a0
+       mov     d0,(a0)
+       mov     (a1),d1
+       sub_sub +4,a1,+4,a0
+       mov     d1,(a0)
+
+       mov     (a1),d0
+       sub_sub +4,a1,+4,a0
+       mov     d0,(a0)
+       mov     (a1),d1
+       sub_sub +4,a1,+4,a0
+       mov     d1,(a0)
+
+       mov     (a1),d0
+       sub_sub +4,a1,+4,a0
+       mov     d0,(a0)
+       mov     (a1),d1
+       sub_sub +4,a1,+4,a0
+       mov     d1,(a0)
+
+       mov     (a1),d0
+       sub_sub +4,a1,+4,a0
+       mov     d0,(a0)
+       mov     (a1),d1
+       sub_sub +4,a1,+4,a0
+       mov     d1,(a0)
+
+       sub     d3,d2
+       bcc     memmove_4_loop
+
+       add     d3,d2
+       beq     memmove_4_no_remainder
+
+memmove_4_remainder:
+       # cut 4-7 words down to 0-3
+       cmp     +16,d2
+       bcs     memmove_4_three_or_fewer_words
+       mov     (a1),d0
+       sub_sub +4,a1,+4,a0
+       mov     d0,(a0)
+       mov     (a1),d1
+       sub_sub +4,a1,+4,a0
+       mov     d1,(a0)
+       mov     (a1),e0
+       sub_sub +4,a1,+4,a0
+       mov     e0,(a0)
+       mov     (a1),e1
+       sub_sub +4,a1,+4,a0
+       mov     e1,(a0)
+       add     -16,d2
+       beq     memmove_4_no_remainder
+
+       # copy the remaining 1, 2 or 3 words
+memmove_4_three_or_fewer_words:
+       cmp     +8,d2
+       bcs     memmove_4_one_word
+       beq     memmove_4_two_words
+       mov     (a1),d0
+       sub_sub +4,a1,+4,a0
+       mov     d0,(a0)
+memmove_4_two_words:
+       mov     (a1),d0
+       sub_sub +4,a1,+4,a0
+       mov     d0,(a0)
+memmove_4_one_word:
+       mov     (a1),d0
+       sub_sub +4,a1,+4,a0
+       mov     d0,(a0)
+
+memmove_4_no_remainder:
+       # check we copied the correct amount
+       # TODO: REMOVE CHECK
+       sub     e3,a0,d2
+       beq     memmove_done
+       break
+       break
+       break
+
+memmove_done:
+       mov     e3,a0
+       ret     [d2,d3],8
+
+       # handle misaligned copying
+memmove_1:
+       add     -1,a1
+       add     -1,d2
+       mov     +1,d3
+       setlb                                   # setlb requires the next insns
+                                               # to occupy exactly 4 bytes
+
+       sub     d3,d2
+       movbu   (a1),d0
+       sub_sub d3,a1,d3,a0
+       movbu   d0,(a0)
+       lcc
+
+       mov     e3,a0
+       ret     [d2,d3],8
+
+memmove_memcpy:
+       jmp     memcpy
+
+memmove_end:
+       .size   memmove, memmove_end-memmove
diff --git a/arch/mn10300/lib/memset.S b/arch/mn10300/lib/memset.S
new file mode 100644 (file)
index 0000000..bc02e39
--- /dev/null
@@ -0,0 +1,121 @@
+/* Optimised simple memory fill
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <asm/cache.h>
+
+        .section .text
+        .balign        L1_CACHE_BYTES
+
+###############################################################################
+#
+# void *memset(void *dst, int c, size_t n)
+#
+###############################################################################
+       .globl  memset
+        .type  memset,@function
+memset:
+       movm    [d2,d3],(sp)
+       mov     d0,(12,sp)
+       mov     d1,(16,sp)
+       mov     (20,sp),d2                      # count
+       mov     d0,a0                           # dst
+       mov     d0,e3                           # the return value
+
+       cmp     +0,d2
+       beq     memset_done                     # return if zero-length fill
+
+       # see if the region parameters are four-byte aligned
+       or      d0,d2,d3
+       and     +3,d3
+       bne     memset_1                        # jump if not
+
+       extbu   d1
+       mov_asl d1,d3,8,d1
+       or_asl  d1,d3,8,d1
+       or_asl  d1,d3,8,d1
+       or      d3,d1
+
+       # we want to transfer as much as we can in chunks of 32 bytes
+       cmp     +31,d2
+       bls     memset_4_remainder              # 4-byte aligned remainder
+
+       add     -32,d2
+       mov     +32,d3
+
+memset_4_loop:
+       mov     d1,(a0+)
+       mov     d1,(a0+)
+       mov     d1,(a0+)
+       mov     d1,(a0+)
+       mov     d1,(a0+)
+       mov     d1,(a0+)
+       mov     d1,(a0+)
+       mov     d1,(a0+)
+
+       sub     d3,d2
+       bcc     memset_4_loop
+
+       add     d3,d2
+       beq     memset_4_no_remainder
+
+memset_4_remainder:
+       # cut 4-7 words down to 0-3
+       cmp     +16,d2
+       bcs     memset_4_three_or_fewer_words
+       mov     d1,(a0+)
+       mov     d1,(a0+)
+       mov     d1,(a0+)
+       mov     d1,(a0+)
+       add     -16,d2
+       beq     memset_4_no_remainder
+
+       # copy the remaining 1, 2 or 3 words
+memset_4_three_or_fewer_words:
+       cmp     +8,d2
+       bcs     memset_4_one_word
+       beq     memset_4_two_words
+       mov     d1,(a0+)
+memset_4_two_words:
+       mov     d1,(a0+)
+memset_4_one_word:
+       mov     d1,(a0+)
+
+memset_4_no_remainder:
+       # check we set the correct amount
+       # TODO: REMOVE CHECK
+       sub     e3,a0,d2
+       mov     (20,sp),d1
+       cmp     d2,d1
+       beq     memset_done
+       break
+       break
+       break
+
+memset_done:
+       mov     e3,a0
+       ret     [d2,d3],8
+
+       # handle misaligned copying
+memset_1:
+       add     -1,d2
+       mov     +1,d3
+       setlb                                   # setlb requires the next insns
+                                               # to occupy exactly 4 bytes
+
+       sub     d3,d2
+       movbu   d1,(a0)
+       inc     a0
+       lcc
+
+       mov     e3,a0
+       ret     [d2,d3],8
+
+memset_end:
+       .size   memset, memset_end-memset
diff --git a/arch/mn10300/lib/negdi2.c b/arch/mn10300/lib/negdi2.c
new file mode 100644 (file)
index 0000000..eae4ecd
--- /dev/null
@@ -0,0 +1,57 @@
+/* More subroutines needed by GCC output code on some machines.  */
+/* Compile this one with gcc.  */
+/* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+   2000, 2001  Free Software Foundation, Inc.
+
+This file is part of GNU CC.
+
+GNU CC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public Licence as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+In addition to the permissions in the GNU General Public Licence, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file.  (The General Public Licence restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GNU CC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public Licence for more details.
+
+You should have received a copy of the GNU General Public Licence
+along with GNU CC; see the file COPYING.  If not, write to
+the Free Software Foundation, 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+/* It is incorrect to include config.h here, because this file is being
+   compiled for the target, and hence definitions concerning only the host
+   do not apply.  */
+
+#include <linux/types.h>
+
+union DWunion {
+       s64 ll;
+       struct {
+               s32 low;
+               s32 high;
+       } s;
+};
+
+s64 __negdi2(s64 u)
+{
+       union DWunion w;
+       union DWunion uu;
+
+       uu.ll = u;
+
+       w.s.low = -uu.s.low;
+       w.s.high = -uu.s.high - ((u32) w.s.low > 0);
+
+       return w.ll;
+}
diff --git a/arch/mn10300/lib/usercopy.c b/arch/mn10300/lib/usercopy.c
new file mode 100644 (file)
index 0000000..a75b203
--- /dev/null
@@ -0,0 +1,166 @@
+/* MN10300 Userspace accessor functions
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <asm/uaccess.h>
+
+unsigned long
+__generic_copy_to_user(void *to, const void *from, unsigned long n)
+{
+       if (access_ok(VERIFY_WRITE, to, n))
+               __copy_user(to, from, n);
+       return n;
+}
+
+unsigned long
+__generic_copy_from_user(void *to, const void *from, unsigned long n)
+{
+       if (access_ok(VERIFY_READ, from, n))
+               __copy_user_zeroing(to, from, n);
+       return n;
+}
+
+/*
+ * Copy a null terminated string from userspace.
+ */
+#define __do_strncpy_from_user(dst, src, count, res)           \
+do {                                                           \
+       int w;                                                  \
+       asm volatile(                                           \
+               "       mov     %1,%0\n"                        \
+               "       cmp     0,%1\n"                         \
+               "       beq     2f\n"                           \
+               "0:\n"                                          \
+               "       movbu   (%5),%2\n"                      \
+               "1:\n"                                          \
+               "       movbu   %2,(%6)\n"                      \
+               "       inc     %5\n"                           \
+               "       inc     %6\n"                           \
+               "       cmp     0,%2\n"                         \
+               "       beq     2f\n"                           \
+               "       add     -1,%1\n"                        \
+               "       bne     0b\n"                           \
+               "2:\n"                                          \
+               "       sub     %1,%0\n"                        \
+               "3:\n"                                          \
+               "       .section .fixup,\"ax\"\n"               \
+               "4:\n"                                          \
+               "       mov     %3,%0\n"                        \
+               "       jmp     3b\n"                           \
+               "       .previous\n"                            \
+               "       .section __ex_table,\"a\"\n"            \
+               "       .balign 4\n"                            \
+               "       .long 0b,4b\n"                          \
+               "       .long 1b,4b\n"                          \
+               "       .previous"                              \
+               :"=&r"(res), "=r"(count), "=&r"(w)              \
+               :"i"(-EFAULT), "1"(count), "a"(src), "a"(dst)   \
+               :"memory");                                     \
+} while (0)
+
+long
+__strncpy_from_user(char *dst, const char *src, long count)
+{
+       long res;
+       __do_strncpy_from_user(dst, src, count, res);
+       return res;
+}
+
+long
+strncpy_from_user(char *dst, const char *src, long count)
+{
+       long res = -EFAULT;
+       if (access_ok(VERIFY_READ, src, 1))
+               __do_strncpy_from_user(dst, src, count, res);
+       return res;
+}
+
+
+/*
+ * Clear a userspace memory
+ */
+#define __do_clear_user(addr, size)            \
+do {                                           \
+       int w;                                  \
+       asm volatile(                           \
+               "       cmp 0,%0\n"             \
+               "       beq 1f\n"               \
+               "       clr %1\n"               \
+               "0:     movbu %1,(%3,%2)\n"     \
+               "       inc %3\n"               \
+               "       cmp %0,%3\n"            \
+               "       bne 0b\n"               \
+               "1:\n"                          \
+               "       sub %3,%0\n"            \
+               "2:\n"                          \
+               ".section .fixup,\"ax\"\n"      \
+               "3:     jmp 2b\n"               \
+               ".previous\n"                   \
+               ".section __ex_table,\"a\"\n"   \
+               "       .balign 4\n"            \
+               "       .long 0b,3b\n"          \
+               ".previous\n"                   \
+               : "+r"(size), "=&r"(w)          \
+               : "a"(addr), "d"(0)             \
+               : "memory");                    \
+} while (0)
+
+unsigned long
+__clear_user(void *to, unsigned long n)
+{
+       __do_clear_user(to, n);
+       return n;
+}
+
+unsigned long
+clear_user(void *to, unsigned long n)
+{
+       if (access_ok(VERIFY_WRITE, to, n))
+               __do_clear_user(to, n);
+       return n;
+}
+
+/*
+ * Return the size of a string (including the ending 0)
+ *
+ * Return 0 on exception, a value greater than N if too long
+ */
+long strnlen_user(const char *s, long n)
+{
+       unsigned long res, w;
+
+       if (!__addr_ok(s))
+               return 0;
+
+       if (n < 0 || n + (u_long) s > current_thread_info()->addr_limit.seg)
+               n = current_thread_info()->addr_limit.seg - (u_long)s;
+
+       asm volatile(
+               "0:     cmp %4,%0\n"
+               "       beq 2f\n"
+               "1:     movbu (%0,%3),%1\n"
+               "       inc %0\n"
+               "       cmp 0,%1\n"
+               "       beq 3f\n"
+               "       bra 0b\n"
+               "2:     clr %0\n"
+               "3:\n"
+               ".section .fixup,\"ax\"\n"
+               "4:     jmp 2b\n"
+               ".previous\n"
+               ".section __ex_table,\"a\"\n"
+               "       .balign 4\n"
+               "       .long 1b,4b\n"
+               ".previous\n"
+               :"=d"(res), "=&r"(w)
+               :"0"(0), "a"(s), "r"(n)
+               :"memory");
+       return res;
+}
diff --git a/arch/mn10300/mm/Makefile b/arch/mn10300/mm/Makefile
new file mode 100644 (file)
index 0000000..28b9d98
--- /dev/null
@@ -0,0 +1,14 @@
+#
+# Makefile for the MN10300-specific memory management code
+#
+
+obj-y := \
+       init.o fault.o pgtable.o extable.o tlb-mn10300.o mmu-context.o \
+       misalignment.o dma-alloc.o
+
+ifneq ($(CONFIG_MN10300_CACHE_DISABLED),y)
+obj-y  += cache.o cache-mn10300.o
+ifeq ($(CONFIG_MN10300_CACHE_WBACK),y)
+obj-y  += cache-flush-mn10300.o
+endif
+endif
diff --git a/arch/mn10300/mm/cache-flush-mn10300.S b/arch/mn10300/mm/cache-flush-mn10300.S
new file mode 100644 (file)
index 0000000..c8ed1cb
--- /dev/null
@@ -0,0 +1,192 @@
+/* MN10300 CPU core caching routines
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/smp.h>
+#include <asm/page.h>
+#include <asm/cache.h>
+
+       .am33_2
+       .globl mn10300_dcache_flush
+       .globl mn10300_dcache_flush_page
+       .globl mn10300_dcache_flush_range
+       .globl mn10300_dcache_flush_range2
+       .globl mn10300_dcache_flush_inv
+       .globl mn10300_dcache_flush_inv_page
+       .globl mn10300_dcache_flush_inv_range
+       .globl mn10300_dcache_flush_inv_range2
+
+###############################################################################
+#
+# void mn10300_dcache_flush(void)
+# Flush the entire data cache back to RAM
+#
+###############################################################################
+       ALIGN
+mn10300_dcache_flush:
+       movhu   (CHCTR),d0
+       btst    CHCTR_DCEN,d0
+       beq     mn10300_dcache_flush_end
+
+       # read the addresses tagged in the cache's tag RAM and attempt to flush
+       # those addresses specifically
+       # - we rely on the hardware to filter out invalid tag entry addresses
+       mov     DCACHE_TAG(0,0),a0              # dcache tag RAM access address
+       mov     DCACHE_PURGE(0,0),a1            # dcache purge request address
+       mov     L1_CACHE_NWAYS*L1_CACHE_NENTRIES,d1  # total number of entries
+
+mn10300_dcache_flush_loop:
+       mov     (a0),d0
+       and     L1_CACHE_TAG_ADDRESS|L1_CACHE_TAG_ENTRY,d0
+       or      L1_CACHE_TAG_VALID,d0           # retain valid entries in the
+                                               # cache
+       mov     d0,(a1)                         # conditional purge
+
+mn10300_dcache_flush_skip:
+       add     L1_CACHE_BYTES,a0
+       add     L1_CACHE_BYTES,a1
+       add     -1,d1
+       bne     mn10300_dcache_flush_loop
+
+mn10300_dcache_flush_end:
+       ret     [],0
+
+###############################################################################
+#
+# void mn10300_dcache_flush_page(unsigned start)
+# void mn10300_dcache_flush_range(unsigned start, unsigned end)
+# void mn10300_dcache_flush_range2(unsigned start, unsigned size)
+# Flush a range of addresses on a page in the dcache
+#
+###############################################################################
+       ALIGN
+mn10300_dcache_flush_page:
+       mov     PAGE_SIZE,d1
+mn10300_dcache_flush_range2:
+       add     d0,d1
+mn10300_dcache_flush_range:
+       movm    [d2,d3],(sp)
+
+       movhu   (CHCTR),d2
+       btst    CHCTR_DCEN,d2
+       beq     mn10300_dcache_flush_range_end
+
+       # round start addr down
+       and     L1_CACHE_TAG_ADDRESS|L1_CACHE_TAG_ENTRY,d0
+       mov     d0,a1
+
+       add     L1_CACHE_BYTES,d1                       # round end addr up
+       and     L1_CACHE_TAG_ADDRESS|L1_CACHE_TAG_ENTRY,d1
+
+       # write a request to flush all instances of an address from the cache
+       mov     DCACHE_PURGE(0,0),a0
+       mov     a1,d0
+       and     L1_CACHE_TAG_ENTRY,d0
+       add     d0,a0                           # starting dcache purge control
+                                               # reg address
+
+       sub     a1,d1
+       lsr     L1_CACHE_SHIFT,d1               # total number of entries to
+                                               # examine
+
+       or      L1_CACHE_TAG_VALID,a1           # retain valid entries in the
+                                               # cache
+
+mn10300_dcache_flush_range_loop:
+       mov     a1,(L1_CACHE_WAYDISP*0,a0)      # conditionally purge this line
+                                               # all ways
+
+       add     L1_CACHE_BYTES,a0
+       add     L1_CACHE_BYTES,a1
+       and     ~L1_CACHE_WAYDISP,a0            # make sure way stay on way 0
+       add     -1,d1
+       bne     mn10300_dcache_flush_range_loop
+
+mn10300_dcache_flush_range_end:
+       ret     [d2,d3],8
+
+###############################################################################
+#
+# void mn10300_dcache_flush_inv(void)
+# Flush the entire data cache and invalidate all entries
+#
+###############################################################################
+       ALIGN
+mn10300_dcache_flush_inv:
+       movhu   (CHCTR),d0
+       btst    CHCTR_DCEN,d0
+       beq     mn10300_dcache_flush_inv_end
+
+       # hit each line in the dcache with an unconditional purge
+       mov     DCACHE_PURGE(0,0),a1            # dcache purge request address
+       mov     L1_CACHE_NWAYS*L1_CACHE_NENTRIES,d1  # total number of entries
+
+mn10300_dcache_flush_inv_loop:
+       mov     (a1),d0                         # unconditional purge
+
+       add     L1_CACHE_BYTES,a1
+       add     -1,d1
+       bne     mn10300_dcache_flush_inv_loop
+
+mn10300_dcache_flush_inv_end:
+       ret     [],0
+
+###############################################################################
+#
+# void mn10300_dcache_flush_inv_page(unsigned start)
+# void mn10300_dcache_flush_inv_range(unsigned start, unsigned end)
+# void mn10300_dcache_flush_inv_range2(unsigned start, unsigned size)
+# Flush and invalidate a range of addresses on a page in the dcache
+#
+###############################################################################
+       ALIGN
+mn10300_dcache_flush_inv_page:
+       mov     PAGE_SIZE,d1
+mn10300_dcache_flush_inv_range2:
+       add     d0,d1
+mn10300_dcache_flush_inv_range:
+       movm    [d2,d3],(sp)
+       movhu   (CHCTR),d2
+       btst    CHCTR_DCEN,d2
+       beq     mn10300_dcache_flush_inv_range_end
+
+       and     L1_CACHE_TAG_ADDRESS|L1_CACHE_TAG_ENTRY,d0      # round start
+                                                               # addr down
+       mov     d0,a1
+
+       add     L1_CACHE_BYTES,d1                       # round end addr up
+       and     L1_CACHE_TAG_ADDRESS|L1_CACHE_TAG_ENTRY,d1
+
+       # write a request to flush and invalidate all instances of an address
+       # from the cache
+       mov     DCACHE_PURGE(0,0),a0
+       mov     a1,d0
+       and     L1_CACHE_TAG_ENTRY,d0
+       add     d0,a0                           # starting dcache purge control
+                                               # reg address
+
+       sub     a1,d1
+       lsr     L1_CACHE_SHIFT,d1               # total number of entries to
+                                               # examine
+
+mn10300_dcache_flush_inv_range_loop:
+       mov     a1,(L1_CACHE_WAYDISP*0,a0)      # conditionally purge this line
+                                               # in all ways
+
+       add     L1_CACHE_BYTES,a0
+       add     L1_CACHE_BYTES,a1
+       and     ~L1_CACHE_WAYDISP,a0            # make sure way stay on way 0
+       add     -1,d1
+       bne     mn10300_dcache_flush_inv_range_loop
+
+mn10300_dcache_flush_inv_range_end:
+       ret     [d2,d3],8
diff --git a/arch/mn10300/mm/cache-mn10300.S b/arch/mn10300/mm/cache-mn10300.S
new file mode 100644 (file)
index 0000000..e839d0a
--- /dev/null
@@ -0,0 +1,289 @@
+/* MN10300 CPU core caching routines
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/smp.h>
+#include <asm/page.h>
+#include <asm/cache.h>
+
+#define mn10300_dcache_inv_range_intr_interval \
+       +((1 << MN10300_DCACHE_INV_RANGE_INTR_LOG2_INTERVAL) - 1)
+
+#if mn10300_dcache_inv_range_intr_interval > 0xff
+#error MN10300_DCACHE_INV_RANGE_INTR_LOG2_INTERVAL must be 8 or less
+#endif
+
+       .am33_2
+
+       .globl mn10300_icache_inv
+       .globl mn10300_dcache_inv
+       .globl mn10300_dcache_inv_range
+       .globl mn10300_dcache_inv_range2
+       .globl mn10300_dcache_inv_page
+
+###############################################################################
+#
+# void mn10300_icache_inv(void)
+# Invalidate the entire icache
+#
+###############################################################################
+       ALIGN
+mn10300_icache_inv:
+       mov     CHCTR,a0
+
+       movhu   (a0),d0
+       btst    CHCTR_ICEN,d0
+       beq     mn10300_icache_inv_end
+
+       mov     epsw,d1
+       and     ~EPSW_IE,epsw
+       nop
+       nop
+
+       # disable the icache
+       and     ~CHCTR_ICEN,d0
+       movhu   d0,(a0)
+
+       # and wait for it to calm down
+       setlb
+       movhu   (a0),d0
+       btst    CHCTR_ICBUSY,d0
+       lne
+
+       # invalidate
+       or      CHCTR_ICINV,d0
+       movhu   d0,(a0)
+
+       # wait for the cache to finish
+       mov     CHCTR,a0
+       setlb
+       movhu   (a0),d0
+       btst    CHCTR_ICBUSY,d0
+       lne
+
+       # and reenable it
+       and     ~CHCTR_ICINV,d0
+       or      CHCTR_ICEN,d0
+       movhu   d0,(a0)
+       movhu   (a0),d0
+
+       mov     d1,epsw
+
+mn10300_icache_inv_end:
+       ret     [],0
+
+###############################################################################
+#
+# void mn10300_dcache_inv(void)
+# Invalidate the entire dcache
+#
+###############################################################################
+       ALIGN
+mn10300_dcache_inv:
+       mov     CHCTR,a0
+
+       movhu   (a0),d0
+       btst    CHCTR_DCEN,d0
+       beq     mn10300_dcache_inv_end
+
+       mov     epsw,d1
+       and     ~EPSW_IE,epsw
+       nop
+       nop
+
+       # disable the dcache
+       and     ~CHCTR_DCEN,d0
+       movhu   d0,(a0)
+
+       # and wait for it to calm down
+       setlb
+       movhu   (a0),d0
+       btst    CHCTR_DCBUSY,d0
+       lne
+
+       # invalidate
+       or      CHCTR_DCINV,d0
+       movhu   d0,(a0)
+
+       # wait for the cache to finish
+       mov     CHCTR,a0
+       setlb
+       movhu   (a0),d0
+       btst    CHCTR_DCBUSY,d0
+       lne
+
+       # and reenable it
+       and     ~CHCTR_DCINV,d0
+       or      CHCTR_DCEN,d0
+       movhu   d0,(a0)
+       movhu   (a0),d0
+
+       mov     d1,epsw
+
+mn10300_dcache_inv_end:
+       ret     [],0
+
+###############################################################################
+#
+# void mn10300_dcache_inv_range(unsigned start, unsigned end)
+# void mn10300_dcache_inv_range2(unsigned start, unsigned size)
+# void mn10300_dcache_inv_page(unsigned start)
+# Invalidate a range of addresses on a page in the dcache
+#
+###############################################################################
+       ALIGN
+mn10300_dcache_inv_page:
+       mov     PAGE_SIZE,d1
+mn10300_dcache_inv_range2:
+       add     d0,d1
+mn10300_dcache_inv_range:
+       movm    [d2,d3,a2],(sp)
+       mov     CHCTR,a2
+
+       movhu   (a2),d2
+       btst    CHCTR_DCEN,d2
+       beq     mn10300_dcache_inv_range_end
+
+       and     L1_CACHE_TAG_ADDRESS|L1_CACHE_TAG_ENTRY,d0      # round start
+                                                               # addr down
+       mov     d0,a1
+
+       add     L1_CACHE_BYTES,d1                       # round end addr up
+       and     L1_CACHE_TAG_ADDRESS|L1_CACHE_TAG_ENTRY,d1
+
+       clr     d2                              # we're going to clear tag ram
+                                               # entries
+
+       # read the tags from the tag RAM, and if they indicate a valid dirty
+       # cache line then invalidate that line
+       mov     DCACHE_TAG(0,0),a0
+       mov     a1,d0
+       and     L1_CACHE_TAG_ENTRY,d0
+       add     d0,a0                           # starting dcache tag RAM
+                                               # access address
+
+       sub     a1,d1
+       lsr     L1_CACHE_SHIFT,d1               # total number of entries to
+                                               # examine
+
+       and     ~(L1_CACHE_DISPARITY-1),a1      # determine comparator base
+
+mn10300_dcache_inv_range_outer_loop:
+       # disable interrupts
+       mov     epsw,d3
+       and     ~EPSW_IE,epsw
+       nop                                     # note that reading CHCTR and
+                                               # AND'ing D0 occupy two delay
+                                               # slots after disabling
+                                               # interrupts
+
+       # disable the dcache
+       movhu   (a2),d0
+       and     ~CHCTR_DCEN,d0
+       movhu   d0,(a2)
+
+       # and wait for it to calm down
+       setlb
+       movhu   (a2),d0
+       btst    CHCTR_DCBUSY,d0
+       lne
+
+mn10300_dcache_inv_range_loop:
+
+       # process the way 0 slot
+       mov     (L1_CACHE_WAYDISP*0,a0),d0      # read the tag in the way 0 slot
+       btst    L1_CACHE_TAG_VALID,d0
+       beq     mn10300_dcache_inv_range_skip_0 # jump if this cacheline is not
+                                               # valid
+
+       xor     a1,d0
+       lsr     12,d0
+       bne     mn10300_dcache_inv_range_skip_0 # jump if not this cacheline
+
+       mov     d2,(a0)                         # kill the tag
+
+mn10300_dcache_inv_range_skip_0:
+
+       # process the way 1 slot
+       mov     (L1_CACHE_WAYDISP*1,a0),d0      # read the tag in the way 1 slot
+       btst    L1_CACHE_TAG_VALID,d0
+       beq     mn10300_dcache_inv_range_skip_1 # jump if this cacheline is not
+                                               # valid
+
+       xor     a1,d0
+       lsr     12,d0
+       bne     mn10300_dcache_inv_range_skip_1 # jump if not this cacheline
+
+       mov     d2,(a0)                         # kill the tag
+
+mn10300_dcache_inv_range_skip_1:
+
+       # process the way 2 slot
+       mov     (L1_CACHE_WAYDISP*2,a0),d0      # read the tag in the way 2 slot
+       btst    L1_CACHE_TAG_VALID,d0
+       beq     mn10300_dcache_inv_range_skip_2 # jump if this cacheline is not
+                                               # valid
+
+       xor     a1,d0
+       lsr     12,d0
+       bne     mn10300_dcache_inv_range_skip_2 # jump if not this cacheline
+
+       mov     d2,(a0)                         # kill the tag
+
+mn10300_dcache_inv_range_skip_2:
+
+       # process the way 3 slot
+       mov     (L1_CACHE_WAYDISP*3,a0),d0      # read the tag in the way 3 slot
+       btst    L1_CACHE_TAG_VALID,d0
+       beq     mn10300_dcache_inv_range_skip_3 # jump if this cacheline is not
+                                               # valid
+
+       xor     a1,d0
+       lsr     12,d0
+       bne     mn10300_dcache_inv_range_skip_3 # jump if not this cacheline
+
+       mov     d2,(a0)                         # kill the tag
+
+mn10300_dcache_inv_range_skip_3:
+
+       # approx every N steps we re-enable the cache and see if there are any
+       # interrupts to be processed
+       # we also break out if we've reached the end of the loop
+       # (the bottom nibble of the count is zero in both cases)
+       add     L1_CACHE_BYTES,a0
+       add     L1_CACHE_BYTES,a1
+       add     -1,d1
+       btst    mn10300_dcache_inv_range_intr_interval,d1
+       bne     mn10300_dcache_inv_range_loop
+
+       # wait for the cache to finish what it's doing
+       setlb
+       movhu   (a2),d0
+       btst    CHCTR_DCBUSY,d0
+       lne
+
+       # and reenable it
+       or      CHCTR_DCEN,d0
+       movhu   d0,(a2)
+       movhu   (a2),d0
+
+       # re-enable interrupts
+       # - we don't bother with delay NOPs as we'll have enough instructions
+       #   before we disable interrupts again to give the interrupts a chance
+       #   to happen
+       mov     d3,epsw
+
+       # go around again if the counter hasn't yet reached zero
+       add     0,d1
+       bne     mn10300_dcache_inv_range_outer_loop
+
+mn10300_dcache_inv_range_end:
+       ret     [d2,d3,a2],12
diff --git a/arch/mn10300/mm/cache.c b/arch/mn10300/mm/cache.c
new file mode 100644 (file)
index 0000000..1b76719
--- /dev/null
@@ -0,0 +1,121 @@
+/* MN10300 Cache flushing routines
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/module.h>
+#include <linux/mm.h>
+#include <linux/mman.h>
+#include <linux/threads.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
+#include <asm/processor.h>
+#include <asm/cacheflush.h>
+#include <asm/io.h>
+#include <asm/uaccess.h>
+
+EXPORT_SYMBOL(mn10300_icache_inv);
+EXPORT_SYMBOL(mn10300_dcache_inv);
+EXPORT_SYMBOL(mn10300_dcache_inv_range);
+EXPORT_SYMBOL(mn10300_dcache_inv_range2);
+EXPORT_SYMBOL(mn10300_dcache_inv_page);
+
+#ifdef CONFIG_MN10300_CACHE_WBACK
+EXPORT_SYMBOL(mn10300_dcache_flush);
+EXPORT_SYMBOL(mn10300_dcache_flush_inv);
+EXPORT_SYMBOL(mn10300_dcache_flush_inv_range);
+EXPORT_SYMBOL(mn10300_dcache_flush_inv_range2);
+EXPORT_SYMBOL(mn10300_dcache_flush_inv_page);
+EXPORT_SYMBOL(mn10300_dcache_flush_range);
+EXPORT_SYMBOL(mn10300_dcache_flush_range2);
+EXPORT_SYMBOL(mn10300_dcache_flush_page);
+#endif
+
+/*
+ * write a page back from the dcache and invalidate the icache so that we can
+ * run code from it that we've just written into it
+ */
+void flush_icache_page(struct vm_area_struct *vma, struct page *page)
+{
+       mn10300_dcache_flush_page(page_to_phys(page));
+       mn10300_icache_inv();
+}
+EXPORT_SYMBOL(flush_icache_page);
+
+/*
+ * write some code we've just written back from the dcache and invalidate the
+ * icache so that we can run that code
+ */
+void flush_icache_range(unsigned long start, unsigned long end)
+{
+#ifdef CONFIG_MN10300_CACHE_WBACK
+       unsigned long addr, size, off;
+       struct page *page;
+       pgd_t *pgd;
+       pud_t *pud;
+       pmd_t *pmd;
+       pte_t *ppte, pte;
+
+       for (; start < end; start += size) {
+               /* work out how much of the page to flush */
+               off = start & (PAGE_SIZE - 1);
+
+               size = end - start;
+               if (size > PAGE_SIZE - off)
+                       size = PAGE_SIZE - off;
+
+               /* get the physical address the page is mapped to from the page
+                * tables */
+               pgd = pgd_offset(current->mm, start);
+               if (!pgd || !pgd_val(*pgd))
+                       continue;
+
+               pud = pud_offset(pgd, start);
+               if (!pud || !pud_val(*pud))
+                       continue;
+
+               pmd = pmd_offset(pud, start);
+               if (!pmd || !pmd_val(*pmd))
+                       continue;
+
+               ppte = pte_offset_map(pmd, start);
+               if (!ppte)
+                       continue;
+               pte = *ppte;
+               pte_unmap(ppte);
+
+               if (pte_none(pte))
+                       continue;
+
+               page = pte_page(pte);
+               if (!page)
+                       continue;
+
+               addr = page_to_phys(page);
+
+               /* flush the dcache and invalidate the icache coverage on that
+                * region */
+               mn10300_dcache_flush_range2(addr + off, size);
+       }
+#endif
+
+       mn10300_icache_inv();
+}
+EXPORT_SYMBOL(flush_icache_range);
+
+/*
+ * allow userspace to flush the instruction cache
+ */
+asmlinkage long sys_cacheflush(unsigned long start, unsigned long end)
+{
+       if (end < start)
+               return -EINVAL;
+
+       flush_icache_range(start, end);
+       return 0;
+}
diff --git a/arch/mn10300/mm/dma-alloc.c b/arch/mn10300/mm/dma-alloc.c
new file mode 100644 (file)
index 0000000..f3649d8
--- /dev/null
@@ -0,0 +1,56 @@
+/* MN10300 Dynamic DMA mapping support
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ * Derived from: arch/i386/kernel/pci-dma.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <linux/types.h>
+#include <linux/mm.h>
+#include <linux/string.h>
+#include <linux/pci.h>
+#include <asm/io.h>
+
+void *dma_alloc_coherent(struct device *dev, size_t size,
+                        dma_addr_t *dma_handle, int gfp)
+{
+       unsigned long addr;
+       void *ret;
+
+       /* ignore region specifiers */
+       gfp &= ~(__GFP_DMA | __GFP_HIGHMEM);
+
+       if (dev == NULL || dev->coherent_dma_mask < 0xffffffff)
+               gfp |= GFP_DMA;
+
+       addr = __get_free_pages(gfp, get_order(size));
+       if (!addr)
+               return NULL;
+
+       /* map the coherent memory through the uncached memory window */
+       ret = (void *) (addr | 0x20000000);
+
+       /* fill the memory with obvious rubbish */
+       memset((void *) addr, 0xfb, size);
+
+       /* write back and evict all cache lines covering this region */
+       mn10300_dcache_flush_inv_range2(virt_to_phys((void *) addr), PAGE_SIZE);
+
+       *dma_handle = virt_to_bus((void *) addr);
+       return ret;
+}
+EXPORT_SYMBOL(dma_alloc_coherent);
+
+void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
+                      dma_addr_t dma_handle)
+{
+       unsigned long addr = (unsigned long) vaddr & ~0x20000000;
+
+       free_pages(addr, get_order(size));
+}
+EXPORT_SYMBOL(dma_free_coherent);
diff --git a/arch/mn10300/mm/extable.c b/arch/mn10300/mm/extable.c
new file mode 100644 (file)
index 0000000..25e5485
--- /dev/null
@@ -0,0 +1,26 @@
+/* MN10300 In-kernel exception handling
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/module.h>
+#include <linux/spinlock.h>
+#include <asm/uaccess.h>
+
+int fixup_exception(struct pt_regs *regs)
+{
+       const struct exception_table_entry *fixup;
+
+       fixup = search_exception_tables(regs->pc);
+       if (fixup) {
+               regs->pc = fixup->fixup;
+               return 1;
+       }
+
+       return 0;
+}
diff --git a/arch/mn10300/mm/fault.c b/arch/mn10300/mm/fault.c
new file mode 100644 (file)
index 0000000..78f092c
--- /dev/null
@@ -0,0 +1,405 @@
+/* MN10300 MMU Fault handler
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Modified by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/types.h>
+#include <linux/ptrace.h>
+#include <linux/mman.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/smp_lock.h>
+#include <linux/interrupt.h>
+#include <linux/init.h>
+#include <linux/vt_kern.h>             /* For unblank_screen() */
+
+#include <asm/system.h>
+#include <asm/uaccess.h>
+#include <asm/pgalloc.h>
+#include <asm/hardirq.h>
+#include <asm/gdb-stub.h>
+#include <asm/cpu-regs.h>
+
+/*
+ * Unlock any spinlocks which will prevent us from getting the
+ * message out
+ */
+void bust_spinlocks(int yes)
+{
+       if (yes) {
+               oops_in_progress = 1;
+#ifdef CONFIG_SMP
+               /* Many serial drivers do __global_cli() */
+               global_irq_lock = 0;
+#endif
+       } else {
+               int loglevel_save = console_loglevel;
+#ifdef CONFIG_VT
+               unblank_screen();
+#endif
+               oops_in_progress = 0;
+               /*
+                * OK, the message is on the console.  Now we call printk()
+                * without oops_in_progress set so that printk will give klogd
+                * a poke.  Hold onto your hats...
+                */
+               console_loglevel = 15;  /* NMI oopser may have shut the console
+                                        * up */
+               printk(" ");
+               console_loglevel = loglevel_save;
+       }
+}
+
+void do_BUG(const char *file, int line)
+{
+       bust_spinlocks(1);
+       printk(KERN_EMERG "------------[ cut here ]------------\n");
+       printk(KERN_EMERG "kernel BUG at %s:%d!\n", file, line);
+}
+
+#if 0
+static void print_pagetable_entries(pgd_t *pgdir, unsigned long address)
+{
+       pgd_t *pgd;
+       pmd_t *pmd;
+       pte_t *pte;
+
+       pgd = pgdir + __pgd_offset(address);
+       printk(KERN_DEBUG "pgd entry %p: %016Lx\n",
+              pgd, (long long) pgd_val(*pgd));
+
+       if (!pgd_present(*pgd)) {
+               printk(KERN_DEBUG "... pgd not present!\n");
+               return;
+       }
+       pmd = pmd_offset(pgd, address);
+       printk(KERN_DEBUG "pmd entry %p: %016Lx\n",
+              pmd, (long long)pmd_val(*pmd));
+
+       if (!pmd_present(*pmd)) {
+               printk(KERN_DEBUG "... pmd not present!\n");
+               return;
+       }
+       pte = pte_offset(pmd, address);
+       printk(KERN_DEBUG "pte entry %p: %016Lx\n",
+              pte, (long long) pte_val(*pte));
+
+       if (!pte_present(*pte))
+               printk(KERN_DEBUG "... pte not present!\n");
+}
+#endif
+
+asmlinkage void monitor_signal(struct pt_regs *);
+
+/*
+ * This routine handles page faults.  It determines the address,
+ * and the problem, and then passes it off to one of the appropriate
+ * routines.
+ *
+ * fault_code:
+ * - LSW: either MMUFCR_IFC or MMUFCR_DFC as appropriate
+ * - MSW: 0 if data access, 1 if instruction access
+ * - bit 0: TLB miss flag
+ * - bit 1: initial write
+ * - bit 2: page invalid
+ * - bit 3: protection violation
+ * - bit 4: accessor (0=user 1=kernel)
+ * - bit 5: 0=read 1=write
+ * - bit 6-8: page protection spec
+ * - bit 9: illegal address
+ * - bit 16: 0=data 1=ins
+ *
+ */
+asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long fault_code,
+                             unsigned long address)
+{
+       struct vm_area_struct *vma;
+       struct task_struct *tsk;
+       struct mm_struct *mm;
+       unsigned long page;
+       siginfo_t info;
+       int write, fault;
+
+#ifdef CONFIG_GDBSTUB
+       /* handle GDB stub causing a fault */
+       if (gdbstub_busy) {
+               gdbstub_exception(regs, TBR & TBR_INT_CODE);
+               return;
+       }
+#endif
+
+#if 0
+       printk(KERN_DEBUG "--- do_page_fault(%p,%s:%04lx,%08lx)\n",
+              regs,
+              fault_code & 0x10000 ? "ins" : "data",
+              fault_code & 0xffff, address);
+#endif
+
+       tsk = current;
+
+       /*
+        * We fault-in kernel-space virtual memory on-demand. The
+        * 'reference' page table is init_mm.pgd.
+        *
+        * NOTE! We MUST NOT take any locks for this case. We may
+        * be in an interrupt or a critical region, and should
+        * only copy the information from the master page table,
+        * nothing more.
+        *
+        * This verifies that the fault happens in kernel space
+        * and that the fault was a page not present (invalid) error
+        */
+       if (address >= VMALLOC_START && address < VMALLOC_END &&
+           (fault_code & MMUFCR_xFC_ACCESS) == MMUFCR_xFC_ACCESS_SR &&
+           (fault_code & MMUFCR_xFC_PGINVAL) == MMUFCR_xFC_PGINVAL
+           )
+               goto vmalloc_fault;
+
+       mm = tsk->mm;
+       info.si_code = SEGV_MAPERR;
+
+       /*
+        * If we're in an interrupt or have no user
+        * context, we must not take the fault..
+        */
+       if (in_interrupt() || !mm)
+               goto no_context;
+
+       down_read(&mm->mmap_sem);
+
+       vma = find_vma(mm, address);
+       if (!vma)
+               goto bad_area;
+       if (vma->vm_start <= address)
+               goto good_area;
+       if (!(vma->vm_flags & VM_GROWSDOWN))
+               goto bad_area;
+
+       if ((fault_code & MMUFCR_xFC_ACCESS) == MMUFCR_xFC_ACCESS_USR) {
+               /* accessing the stack below the stack pointer is always a
+                * bug */
+               if ((address & PAGE_MASK) + 2 * PAGE_SIZE < regs->sp) {
+#if 0
+                       printk(KERN_WARNING
+                              "[%d] ### Access below stack @%lx (sp=%lx)\n",
+                              current->pid, address, regs->sp);
+                       printk(KERN_WARNING
+                              "vma [%08x - %08x]\n",
+                              vma->vm_start, vma->vm_end);
+                       show_registers(regs);
+                       printk(KERN_WARNING
+                              "[%d] ### Code: [%08lx]"
+                              " %02x %02x %02x %02x %02x %02x %02x %02x\n",
+                              current->pid,
+                              regs->pc,
+                              ((u8 *) regs->pc)[0],
+                              ((u8 *) regs->pc)[1],
+                              ((u8 *) regs->pc)[2],
+                              ((u8 *) regs->pc)[3],
+                              ((u8 *) regs->pc)[4],
+                              ((u8 *) regs->pc)[5],
+                              ((u8 *) regs->pc)[6],
+                              ((u8 *) regs->pc)[7]
+                              );
+#endif
+                       goto bad_area;
+               }
+       }
+
+       if (expand_stack(vma, address))
+               goto bad_area;
+
+/*
+ * Ok, we have a good vm_area for this memory access, so
+ * we can handle it..
+ */
+good_area:
+       info.si_code = SEGV_ACCERR;
+       write = 0;
+       switch (fault_code & (MMUFCR_xFC_PGINVAL|MMUFCR_xFC_TYPE)) {
+       default:        /* 3: write, present */
+       case MMUFCR_xFC_TYPE_WRITE:
+#ifdef TEST_VERIFY_AREA
+               if ((fault_code & MMUFCR_xFC_ACCESS) == MMUFCR_xFC_ACCESS_SR)
+                       printk(KERN_DEBUG "WP fault at %08lx\n", regs->pc);
+#endif
+               /* write to absent page */
+       case MMUFCR_xFC_PGINVAL | MMUFCR_xFC_TYPE_WRITE:
+               if (!(vma->vm_flags & VM_WRITE))
+                       goto bad_area;
+               write++;
+               break;
+
+               /* read from protected page */
+       case MMUFCR_xFC_TYPE_READ:
+               goto bad_area;
+
+               /* read from absent page present */
+       case MMUFCR_xFC_PGINVAL | MMUFCR_xFC_TYPE_READ:
+               if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
+                       goto bad_area;
+               break;
+       }
+
+       /*
+        * If for any reason at all we couldn't handle the fault,
+        * make sure we exit gracefully rather than endlessly redo
+        * the fault.
+        */
+       fault = handle_mm_fault(mm, vma, address, write);
+       if (unlikely(fault & VM_FAULT_ERROR)) {
+               if (fault & VM_FAULT_OOM)
+                       goto out_of_memory;
+               else if (fault & VM_FAULT_SIGBUS)
+                       goto do_sigbus;
+               BUG();
+       }
+       if (fault & VM_FAULT_MAJOR)
+               current->maj_flt++;
+       else
+               current->min_flt++;
+
+       up_read(&mm->mmap_sem);
+       return;
+
+/*
+ * Something tried to access memory that isn't in our memory map..
+ * Fix it, but check if it's kernel or user first..
+ */
+bad_area:
+       up_read(&mm->mmap_sem);
+       monitor_signal(regs);
+
+       /* User mode accesses just cause a SIGSEGV */
+       if ((fault_code & MMUFCR_xFC_ACCESS) == MMUFCR_xFC_ACCESS_USR) {
+               info.si_signo = SIGSEGV;
+               info.si_errno = 0;
+               /* info.si_code has been set above */
+               info.si_addr = (void *)address;
+               force_sig_info(SIGSEGV, &info, tsk);
+               return;
+       }
+
+no_context:
+       monitor_signal(regs);
+       /* Are we prepared to handle this kernel fault?  */
+       if (fixup_exception(regs))
+               return;
+
+/*
+ * Oops. The kernel tried to access some bad page. We'll have to
+ * terminate things with extreme prejudice.
+ */
+
+       bust_spinlocks(1);
+
+       if (address < PAGE_SIZE)
+               printk(KERN_ALERT
+                      "Unable to handle kernel NULL pointer dereference");
+       else
+               printk(KERN_ALERT
+                      "Unable to handle kernel paging request");
+       printk(" at virtual address %08lx\n", address);
+       printk(" printing pc:\n");
+       printk(KERN_ALERT "%08lx\n", regs->pc);
+
+#ifdef CONFIG_GDBSTUB
+       gdbstub_intercept(
+               regs, fault_code & 0x00010000 ? EXCEP_IAERROR : EXCEP_DAERROR);
+#endif
+
+       page = PTBR;
+       page = ((unsigned long *) __va(page))[address >> 22];
+       printk(KERN_ALERT "*pde = %08lx\n", page);
+       if (page & 1) {
+               page &= PAGE_MASK;
+               address &= 0x003ff000;
+               page = ((unsigned long *) __va(page))[address >> PAGE_SHIFT];
+               printk(KERN_ALERT "*pte = %08lx\n", page);
+       }
+
+       die("Oops", regs, fault_code);
+       do_exit(SIGKILL);
+
+/*
+ * We ran out of memory, or some other thing happened to us that made
+ * us unable to handle the page fault gracefully.
+ */
+out_of_memory:
+       up_read(&mm->mmap_sem);
+       monitor_signal(regs);
+       printk(KERN_ALERT "VM: killing process %s\n", tsk->comm);
+       if ((fault_code & MMUFCR_xFC_ACCESS) == MMUFCR_xFC_ACCESS_USR)
+               do_exit(SIGKILL);
+       goto no_context;
+
+do_sigbus:
+       up_read(&mm->mmap_sem);
+       monitor_signal(regs);
+
+       /*
+        * Send a sigbus, regardless of whether we were in kernel
+        * or user mode.
+        */
+       info.si_signo = SIGBUS;
+       info.si_errno = 0;
+       info.si_code = BUS_ADRERR;
+       info.si_addr = (void *)address;
+       force_sig_info(SIGBUS, &info, tsk);
+
+       /* Kernel mode? Handle exceptions or die */
+       if ((fault_code & MMUFCR_xFC_ACCESS) == MMUFCR_xFC_ACCESS_SR)
+               goto no_context;
+       return;
+
+vmalloc_fault:
+       {
+               /*
+                * Synchronize this task's top level page-table
+                * with the 'reference' page table.
+                *
+                * Do _not_ use "tsk" here. We might be inside
+                * an interrupt in the middle of a task switch..
+                */
+               int index = pgd_index(address);
+               pgd_t *pgd, *pgd_k;
+               pud_t *pud, *pud_k;
+               pmd_t *pmd, *pmd_k;
+               pte_t *pte_k;
+
+               pgd_k = init_mm.pgd + index;
+
+               if (!pgd_present(*pgd_k))
+                       goto no_context;
+
+               pud_k = pud_offset(pgd_k, address);
+               if (!pud_present(*pud_k))
+                       goto no_context;
+
+               pmd_k = pmd_offset(pud_k, address);
+               if (!pmd_present(*pmd_k))
+                       goto no_context;
+
+               pgd = (pgd_t *) PTBR + index;
+               pud = pud_offset(pgd, address);
+               pmd = pmd_offset(pud, address);
+               set_pmd(pmd, *pmd_k);
+
+               pte_k = pte_offset_kernel(pmd_k, address);
+               if (!pte_present(*pte_k))
+                       goto no_context;
+               return;
+       }
+}
diff --git a/arch/mn10300/mm/init.c b/arch/mn10300/mm/init.c
new file mode 100644 (file)
index 0000000..8c5d88c
--- /dev/null
@@ -0,0 +1,160 @@
+/* MN10300 Memory management initialisation
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Modified by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/signal.h>
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/types.h>
+#include <linux/ptrace.h>
+#include <linux/mman.h>
+#include <linux/slab.h>
+#include <linux/fs.h>
+#include <linux/mm.h>
+#include <linux/swap.h>
+#include <linux/smp.h>
+#include <linux/init.h>
+#include <linux/initrd.h>
+#include <linux/highmem.h>
+#include <linux/pagemap.h>
+#include <linux/bootmem.h>
+
+#include <asm/processor.h>
+#include <asm/system.h>
+#include <asm/uaccess.h>
+#include <asm/pgtable.h>
+#include <asm/pgalloc.h>
+#include <asm/dma.h>
+#include <asm/tlb.h>
+#include <asm/sections.h>
+
+DEFINE_PER_CPU(struct mmu_gather, mmu_gathers);
+
+unsigned long highstart_pfn, highend_pfn;
+
+/*
+ * set up paging
+ */
+void __init paging_init(void)
+{
+       unsigned long zones_size[MAX_NR_ZONES] = {0,};
+       pte_t *ppte;
+       int loop;
+
+       /* main kernel space -> RAM mapping is handled as 1:1 transparent by
+        * the MMU */
+       memset(swapper_pg_dir, 0, sizeof(swapper_pg_dir));
+       memset(kernel_vmalloc_ptes, 0, sizeof(kernel_vmalloc_ptes));
+
+       /* load the VMALLOC area PTE table addresses into the kernel PGD */
+       ppte = kernel_vmalloc_ptes;
+       for (loop = VMALLOC_START / (PAGE_SIZE * PTRS_PER_PTE);
+            loop < VMALLOC_END / (PAGE_SIZE * PTRS_PER_PTE);
+            loop++
+            ) {
+               set_pgd(swapper_pg_dir + loop, __pgd(__pa(ppte) | _PAGE_TABLE));
+               ppte += PAGE_SIZE / sizeof(pte_t);
+       }
+
+       /* declare the sizes of the RAM zones (only use the normal zone) */
+       zones_size[ZONE_NORMAL] =
+               (contig_page_data.bdata->node_low_pfn) -
+               (contig_page_data.bdata->node_boot_start >> PAGE_SHIFT);
+
+       /* pass the memory from the bootmem allocator to the main allocator */
+       free_area_init(zones_size);
+
+       __flush_tlb_all();
+}
+
+/*
+ * transfer all the memory from the bootmem allocator to the runtime allocator
+ */
+void __init mem_init(void)
+{
+       int codesize, reservedpages, datasize, initsize;
+       int tmp;
+
+       if (!mem_map)
+               BUG();
+
+#define START_PFN      (contig_page_data.bdata->node_boot_start >> PAGE_SHIFT)
+#define MAX_LOW_PFN    (contig_page_data.bdata->node_low_pfn)
+
+       max_mapnr = num_physpages = MAX_LOW_PFN - START_PFN;
+       high_memory = (void *) __va(MAX_LOW_PFN * PAGE_SIZE);
+
+       /* clear the zero-page */
+       memset(empty_zero_page, 0, PAGE_SIZE);
+
+       /* this will put all low memory onto the freelists */
+       totalram_pages += free_all_bootmem();
+
+       reservedpages = 0;
+       for (tmp = 0; tmp < num_physpages; tmp++)
+               if (PageReserved(&mem_map[tmp]))
+                       reservedpages++;
+
+       codesize =  (unsigned long) &_etext - (unsigned long) &_stext;
+       datasize =  (unsigned long) &_edata - (unsigned long) &_etext;
+       initsize =  (unsigned long) &__init_end - (unsigned long) &__init_begin;
+
+       printk(KERN_INFO
+              "Memory: %luk/%luk available"
+              " (%dk kernel code, %dk reserved, %dk data, %dk init,"
+              " %ldk highmem)\n",
+              (unsigned long) nr_free_pages() << (PAGE_SHIFT - 10),
+              max_mapnr << (PAGE_SHIFT - 10),
+              codesize >> 10,
+              reservedpages << (PAGE_SHIFT - 10),
+              datasize >> 10,
+              initsize >> 10,
+              (unsigned long) (totalhigh_pages << (PAGE_SHIFT - 10))
+              );
+}
+
+/*
+ *
+ */
+void free_init_pages(char *what, unsigned long begin, unsigned long end)
+{
+       unsigned long addr;
+
+       for (addr = begin; addr < end; addr += PAGE_SIZE) {
+               ClearPageReserved(virt_to_page(addr));
+               init_page_count(virt_to_page(addr));
+               memset((void *) addr, 0xcc, PAGE_SIZE);
+               free_page(addr);
+               totalram_pages++;
+       }
+       printk(KERN_INFO "Freeing %s: %ldk freed\n", what, (end - begin) >> 10);
+}
+
+/*
+ * recycle memory containing stuff only required for initialisation
+ */
+void free_initmem(void)
+{
+       free_init_pages("unused kernel memory",
+                       (unsigned long) &__init_begin,
+                       (unsigned long) &__init_end);
+}
+
+/*
+ * dispose of the memory on which the initial ramdisk resided
+ */
+#ifdef CONFIG_BLK_DEV_INITRD
+void free_initrd_mem(unsigned long start, unsigned long end)
+{
+       free_init_pages("initrd memory", start, end);
+}
+#endif
diff --git a/arch/mn10300/mm/misalignment.c b/arch/mn10300/mm/misalignment.c
new file mode 100644 (file)
index 0000000..32aa89d
--- /dev/null
@@ -0,0 +1,661 @@
+/* MN10300 Misalignment fixup handler
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/errno.h>
+#include <linux/ptrace.h>
+#include <linux/timer.h>
+#include <linux/mm.h>
+#include <linux/smp.h>
+#include <linux/smp_lock.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/spinlock.h>
+#include <linux/interrupt.h>
+#include <linux/pci.h>
+#include <asm/processor.h>
+#include <asm/system.h>
+#include <asm/uaccess.h>
+#include <asm/io.h>
+#include <asm/atomic.h>
+#include <asm/smp.h>
+#include <asm/pgalloc.h>
+#include <asm/cpu-regs.h>
+#include <asm/busctl-regs.h>
+#include <asm/fpu.h>
+#include <asm/gdb-stub.h>
+#include <asm/asm-offsets.h>
+
+#if 0
+#define kdebug(FMT, ...) printk(KERN_DEBUG FMT, ##__VA_ARGS__)
+#else
+#define kdebug(FMT, ...) do {} while (0)
+#endif
+
+static int misalignment_addr(unsigned long *registers, unsigned params,
+                            unsigned opcode, unsigned disp,
+                            void **_address, unsigned long **_postinc);
+
+static int misalignment_reg(unsigned long *registers, unsigned params,
+                           unsigned opcode, unsigned disp,
+                           unsigned long **_register);
+
+static inline unsigned int_log2(unsigned x)
+{
+       unsigned y;
+       asm("bsch %1,%0" : "=r"(y) : "r"(x), "0"(0));
+       return y;
+}
+#define log2(x) int_log2(x)
+
+static const unsigned Dreg_index[] = {
+       REG_D0 >> 2, REG_D1 >> 2, REG_D2 >> 2, REG_D3 >> 2
+};
+
+static const unsigned Areg_index[] = {
+       REG_A0 >> 2, REG_A1 >> 2, REG_A2 >> 2, REG_A3 >> 2
+};
+
+static const unsigned Rreg_index[] = {
+       REG_E0 >> 2, REG_E1 >> 2, REG_E2 >> 2, REG_E3 >> 2,
+       REG_E4 >> 2, REG_E5 >> 2, REG_E6 >> 2, REG_E7 >> 2,
+       REG_A0 >> 2, REG_A1 >> 2, REG_A2 >> 2, REG_A3 >> 2,
+       REG_D0 >> 2, REG_D1 >> 2, REG_D2 >> 2, REG_D3 >> 2
+};
+
+enum format_id {
+       FMT_S0,
+       FMT_S1,
+       FMT_S2,
+       FMT_S4,
+       FMT_D0,
+       FMT_D1,
+       FMT_D2,
+       FMT_D4,
+       FMT_D6,
+       FMT_D7,
+       FMT_D8,
+       FMT_D9,
+};
+
+struct {
+       u_int8_t opsz, dispsz;
+} format_tbl[16] = {
+       [FMT_S0]        = { 8,  0       },
+       [FMT_S1]        = { 8,  8       },
+       [FMT_S2]        = { 8,  16      },
+       [FMT_S4]        = { 8,  32      },
+       [FMT_D0]        = { 16, 0       },
+       [FMT_D1]        = { 16, 8       },
+       [FMT_D2]        = { 16, 16      },
+       [FMT_D4]        = { 16, 32      },
+       [FMT_D6]        = { 24, 0       },
+       [FMT_D7]        = { 24, 8       },
+       [FMT_D8]        = { 24, 24      },
+       [FMT_D9]        = { 24, 32      },
+};
+
+enum value_id {
+       DM0,            /* data reg in opcode in bits 0-1 */
+       DM1,            /* data reg in opcode in bits 2-3 */
+       DM2,            /* data reg in opcode in bits 4-5 */
+       AM0,            /* addr reg in opcode in bits 0-1 */
+       AM1,            /* addr reg in opcode in bits 2-3 */
+       AM2,            /* addr reg in opcode in bits 4-5 */
+       RM0,            /* reg in opcode in bits 0-3 */
+       RM1,            /* reg in opcode in bits 2-5 */
+       RM2,            /* reg in opcode in bits 4-7 */
+       RM4,            /* reg in opcode in bits 8-11 */
+       RM6,            /* reg in opcode in bits 12-15 */
+
+       RD0,            /* reg in displacement in bits 0-3 */
+       RD2,            /* reg in displacement in bits 4-7 */
+
+       SP,             /* stack pointer */
+
+       SD8,            /* 8-bit signed displacement */
+       SD16,           /* 16-bit signed displacement */
+       SD24,           /* 24-bit signed displacement */
+       SIMM4_2,        /* 4-bit signed displacement in opcode bits 4-7 */
+       SIMM8,          /* 8-bit signed immediate */
+       IMM24,          /* 24-bit unsigned immediate */
+       IMM32,          /* 32-bit unsigned immediate */
+       IMM32_HIGH8,    /* 32-bit unsigned immediate, high 8-bits in opcode */
+
+       DN0     = DM0,
+       DN1     = DM1,
+       DN2     = DM2,
+       AN0     = AM0,
+       AN1     = AM1,
+       AN2     = AM2,
+       RN0     = RM0,
+       RN1     = RM1,
+       RN2     = RM2,
+       RN4     = RM4,
+       RN6     = RM6,
+       DI      = DM1,
+       RI      = RM2,
+
+};
+
+struct mn10300_opcode {
+       const char      *name;
+       u_int32_t       opcode;
+       u_int32_t       opmask;
+       unsigned        exclusion;
+
+       enum format_id  format;
+
+       unsigned        cpu_mask;
+#define AM33   330
+
+       unsigned        params[2];
+#define MEM(ADDR)              (0x80000000 | (ADDR))
+#define MEM2(ADDR1, ADDR2)     (0x80000000 | (ADDR1) << 8 | (ADDR2))
+#define MEMINC(ADDR)           (0x81000000 | (ADDR))
+#define MEMINC2(ADDR, INC)     (0x81000000 | (ADDR) << 8 | (INC))
+};
+
+/* LIBOPCODES EXCERPT
+   Assemble Matsushita MN10300 instructions.
+   Copyright 1996, 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public Licence as published by
+   the Free Software Foundation; either version 2 of the Licence, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public Licence for more details.
+
+   You should have received a copy of the GNU General Public Licence
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+static const struct mn10300_opcode mn10300_opcodes[] = {
+{ "mov",       0x60,        0xf0,        0,    FMT_S0, 0,      {DM1, MEM(AN0)}},
+{ "mov",       0x70,        0xf0,        0,    FMT_S0, 0,      {MEM(AM0), DN1}},
+{ "mov",       0xf000,      0xfff0,      0,    FMT_D0, 0,      {MEM(AM0), AN1}},
+{ "mov",       0xf010,      0xfff0,      0,    FMT_D0, 0,      {AM1, MEM(AN0)}},
+{ "mov",       0xf300,      0xffc0,      0,    FMT_D0, 0,      {MEM2(DI, AM0), DN2}},
+{ "mov",       0xf340,      0xffc0,      0,    FMT_D0, 0,      {DM2, MEM2(DI, AN0)}},
+{ "mov",       0xf380,      0xffc0,      0,    FMT_D0, 0,      {MEM2(DI, AM0), AN2}},
+{ "mov",       0xf3c0,      0xffc0,      0,    FMT_D0, 0,      {AM2, MEM2(DI, AN0)}},
+{ "mov",       0xf80000,    0xfff000,    0,    FMT_D1, 0,      {MEM2(SD8, AM0), DN1}},
+{ "mov",       0xf81000,    0xfff000,    0,    FMT_D1, 0,      {DM1, MEM2(SD8, AN0)}},
+{ "mov",       0xf82000,    0xfff000,    0,    FMT_D1, 0,      {MEM2(SD8,AM0), AN1}},
+{ "mov",       0xf83000,    0xfff000,    0,    FMT_D1, 0,      {AM1, MEM2(SD8, AN0)}},
+{ "mov",       0xf8f000,    0xfffc00,    0,    FMT_D1, AM33,   {MEM2(SD8, AM0), SP}},
+{ "mov",       0xf8f400,    0xfffc00,    0,    FMT_D1, AM33,   {SP, MEM2(SD8, AN0)}},
+{ "mov",       0xf90a00,    0xffff00,    0,    FMT_D6, AM33,   {MEM(RM0), RN2}},
+{ "mov",       0xf91a00,    0xffff00,    0,    FMT_D6, AM33,   {RM2, MEM(RN0)}},
+{ "mov",       0xf96a00,    0xffff00,    0x12, FMT_D6, AM33,   {MEMINC(RM0), RN2}},
+{ "mov",       0xf97a00,    0xffff00,    0,    FMT_D6, AM33,   {RM2, MEMINC(RN0)}},
+{ "mov",       0xfa000000,  0xfff00000,  0,    FMT_D2, 0,      {MEM2(SD16, AM0), DN1}},
+{ "mov",       0xfa100000,  0xfff00000,  0,    FMT_D2, 0,      {DM1, MEM2(SD16, AN0)}},
+{ "mov",       0xfa200000,  0xfff00000,  0,    FMT_D2, 0,      {MEM2(SD16, AM0), AN1}},
+{ "mov",       0xfa300000,  0xfff00000,  0,    FMT_D2, 0,      {AM1, MEM2(SD16, AN0)}},
+{ "mov",       0xfb0a0000,  0xffff0000,  0,    FMT_D7, AM33,   {MEM2(SD8, RM0), RN2}},
+{ "mov",       0xfb1a0000,  0xffff0000,  0,    FMT_D7, AM33,   {RM2, MEM2(SD8, RN0)}},
+{ "mov",       0xfb6a0000,  0xffff0000,  0x22, FMT_D7, AM33,   {MEMINC2 (RM0, SIMM8), RN2}},
+{ "mov",       0xfb7a0000,  0xffff0000,  0,    FMT_D7, AM33,   {RM2, MEMINC2 (RN0, SIMM8)}},
+{ "mov",       0xfb8e0000,  0xffff000f,  0,    FMT_D7, AM33,   {MEM2(RI, RM0), RD2}},
+{ "mov",       0xfb9e0000,  0xffff000f,  0,    FMT_D7, AM33,   {RD2, MEM2(RI, RN0)}},
+{ "mov",       0xfc000000,  0xfff00000,  0,    FMT_D4, 0,      {MEM2(IMM32,AM0), DN1}},
+{ "mov",       0xfc100000,  0xfff00000,  0,    FMT_D4, 0,      {DM1, MEM2(IMM32,AN0)}},
+{ "mov",       0xfc200000,  0xfff00000,  0,    FMT_D4, 0,      {MEM2(IMM32,AM0), AN1}},
+{ "mov",       0xfc300000,  0xfff00000,  0,    FMT_D4, 0,      {AM1, MEM2(IMM32,AN0)}},
+{ "mov",       0xfd0a0000,  0xffff0000,  0,    FMT_D8, AM33,   {MEM2(SD24, RM0), RN2}},
+{ "mov",       0xfd1a0000,  0xffff0000,  0,    FMT_D8, AM33,   {RM2, MEM2(SD24, RN0)}},
+{ "mov",       0xfd6a0000,  0xffff0000,  0x22, FMT_D8, AM33,   {MEMINC2 (RM0, IMM24), RN2}},
+{ "mov",       0xfd7a0000,  0xffff0000,  0,    FMT_D8, AM33,   {RM2, MEMINC2 (RN0, IMM24)}},
+{ "mov",       0xfe0a0000,  0xffff0000,  0,    FMT_D9, AM33,   {MEM2(IMM32_HIGH8,RM0), RN2}},
+{ "mov",       0xfe1a0000,  0xffff0000,  0,    FMT_D9, AM33,   {RM2, MEM2(IMM32_HIGH8, RN0)}},
+{ "mov",       0xfe6a0000,  0xffff0000,  0x22, FMT_D9, AM33,   {MEMINC2 (RM0, IMM32_HIGH8), RN2}},
+{ "mov",       0xfe7a0000,  0xffff0000,  0,    FMT_D9, AM33,   {RN2, MEMINC2 (RM0, IMM32_HIGH8)}},
+
+{ "movhu",     0xf060,      0xfff0,      0,    FMT_D0, 0,      {MEM(AM0), DN1}},
+{ "movhu",     0xf070,      0xfff0,      0,    FMT_D0, 0,      {DM1, MEM(AN0)}},
+{ "movhu",     0xf480,      0xffc0,      0,    FMT_D0, 0,      {MEM2(DI, AM0), DN2}},
+{ "movhu",     0xf4c0,      0xffc0,      0,    FMT_D0, 0,      {DM2, MEM2(DI, AN0)}},
+{ "movhu",     0xf86000,    0xfff000,    0,    FMT_D1, 0,      {MEM2(SD8, AM0), DN1}},
+{ "movhu",     0xf87000,    0xfff000,    0,    FMT_D1, 0,      {DM1, MEM2(SD8, AN0)}},
+{ "movhu",     0xf94a00,    0xffff00,    0,    FMT_D6, AM33,   {MEM(RM0), RN2}},
+{ "movhu",     0xf95a00,    0xffff00,    0,    FMT_D6, AM33,   {RM2, MEM(RN0)}},
+{ "movhu",     0xf9ea00,    0xffff00,    0x12, FMT_D6, AM33,   {MEMINC(RM0), RN2}},
+{ "movhu",     0xf9fa00,    0xffff00,    0,    FMT_D6, AM33,   {RM2, MEMINC(RN0)}},
+{ "movhu",     0xfa600000,  0xfff00000,  0,    FMT_D2, 0,      {MEM2(SD16, AM0), DN1}},
+{ "movhu",     0xfa700000,  0xfff00000,  0,    FMT_D2, 0,      {DM1, MEM2(SD16, AN0)}},
+{ "movhu",     0xfb4a0000,  0xffff0000,  0,    FMT_D7, AM33,   {MEM2(SD8, RM0), RN2}},
+{ "movhu",     0xfb5a0000,  0xffff0000,  0,    FMT_D7, AM33,   {RM2, MEM2(SD8, RN0)}},
+{ "movhu",     0xfbce0000,  0xffff000f,  0,    FMT_D7, AM33,   {MEM2(RI, RM0), RD2}},
+{ "movhu",     0xfbde0000,  0xffff000f,  0,    FMT_D7, AM33,   {RD2, MEM2(RI, RN0)}},
+{ "movhu",     0xfbea0000,  0xffff0000,  0x22, FMT_D7, AM33,   {MEMINC2 (RM0, SIMM8), RN2}},
+{ "movhu",     0xfbfa0000,  0xffff0000,  0,    FMT_D7, AM33,   {RM2, MEMINC2 (RN0, SIMM8)}},
+{ "movhu",     0xfc600000,  0xfff00000,  0,    FMT_D4, 0,      {MEM2(IMM32,AM0), DN1}},
+{ "movhu",     0xfc700000,  0xfff00000,  0,    FMT_D4, 0,      {DM1, MEM2(IMM32,AN0)}},
+{ "movhu",     0xfd4a0000,  0xffff0000,  0,    FMT_D8, AM33,   {MEM2(SD24, RM0), RN2}},
+{ "movhu",     0xfd5a0000,  0xffff0000,  0,    FMT_D8, AM33,   {RM2, MEM2(SD24, RN0)}},
+{ "movhu",     0xfdea0000,  0xffff0000,  0x22, FMT_D8, AM33,   {MEMINC2 (RM0, IMM24), RN2}},
+{ "movhu",     0xfdfa0000,  0xffff0000,  0,    FMT_D8, AM33,   {RM2, MEMINC2 (RN0, IMM24)}},
+{ "movhu",     0xfe4a0000,  0xffff0000,  0,    FMT_D9, AM33,   {MEM2(IMM32_HIGH8,RM0), RN2}},
+{ "movhu",     0xfe5a0000,  0xffff0000,  0,    FMT_D9, AM33,   {RM2, MEM2(IMM32_HIGH8, RN0)}},
+{ "movhu",     0xfeea0000,  0xffff0000,  0x22, FMT_D9, AM33,   {MEMINC2 (RM0, IMM32_HIGH8), RN2}},
+{ "movhu",     0xfefa0000,  0xffff0000,  0,    FMT_D9, AM33,   {RN2, MEMINC2 (RM0, IMM32_HIGH8)}},
+{ 0, 0, 0, 0, 0, 0, {0}},
+};
+
+/*
+ * fix up misalignment problems where possible
+ */
+asmlinkage void misalignment(struct pt_regs *regs, enum exception_code code)
+{
+       const struct exception_table_entry *fixup;
+       const struct mn10300_opcode *pop;
+       unsigned long *registers = (unsigned long *) regs;
+       unsigned long data, *store, *postinc;
+       mm_segment_t seg;
+       siginfo_t info;
+       uint32_t opcode, disp, noc, xo, xm;
+       uint8_t *pc, byte;
+       void *address;
+       unsigned tmp, npop;
+
+       kdebug("MISALIGN at %lx\n", regs->pc);
+
+       if (in_interrupt())
+               die("Misalignment trap in interrupt context", regs, code);
+
+       if (regs->epsw & EPSW_IE)
+               asm volatile("or %0,epsw" : : "i"(EPSW_IE));
+
+       seg = get_fs();
+       set_fs(KERNEL_DS);
+
+       fixup = search_exception_tables(regs->pc);
+
+       /* first thing to do is to match the opcode */
+       pc = (u_int8_t *) regs->pc;
+
+       if (__get_user(byte, pc) != 0)
+               goto fetch_error;
+       opcode = byte;
+       noc = 8;
+
+       for (pop = mn10300_opcodes; pop->name; pop++) {
+               npop = log2(pop->opcode | pop->opmask);
+               if (npop <= 0 || npop > 31)
+                       continue;
+               npop = (npop + 8) & ~7;
+
+       got_more_bits:
+               if (npop == noc) {
+                       if ((opcode & pop->opmask) == pop->opcode)
+                               goto found_opcode;
+               } else if (npop > noc) {
+                       xo = pop->opcode >> (npop - noc);
+                       xm = pop->opmask >> (npop - noc);
+
+                       if ((opcode & xm) != xo)
+                               continue;
+
+                       /* we've got a partial match (an exact match on the
+                        * first N bytes), so we need to get some more data */
+                       pc++;
+                       if (__get_user(byte, pc) != 0)
+                               goto fetch_error;
+                       opcode = opcode << 8 | byte;
+                       noc += 8;
+                       goto got_more_bits;
+               } else {
+                       /* there's already been a partial match as long as the
+                        * complete match we're now considering, so this one
+                        * should't match */
+                       continue;
+               }
+       }
+
+       /* didn't manage to find a fixup */
+       if (!user_mode(regs))
+               printk(KERN_CRIT "MISALIGN: %lx: unsupported instruction %x\n",
+                      regs->pc, opcode);
+
+failed:
+       set_fs(seg);
+       if (die_if_no_fixup("misalignment error", regs, code))
+               return;
+
+       info.si_signo   = SIGBUS;
+       info.si_errno   = 0;
+       info.si_code    = BUS_ADRALN;
+       info.si_addr    = (void *) regs->pc;
+       force_sig_info(SIGBUS, &info, current);
+       return;
+
+       /* error reading opcodes */
+fetch_error:
+       if (!user_mode(regs))
+               printk(KERN_CRIT
+                      "MISALIGN: %p: fault whilst reading instruction data\n",
+                      pc);
+       goto failed;
+
+bad_addr_mode:
+       if (!user_mode(regs))
+               printk(KERN_CRIT
+                      "MISALIGN: %lx: unsupported addressing mode %x\n",
+                      regs->pc, opcode);
+       goto failed;
+
+bad_reg_mode:
+       if (!user_mode(regs))
+               printk(KERN_CRIT
+                      "MISALIGN: %lx: unsupported register mode %x\n",
+                      regs->pc, opcode);
+       goto failed;
+
+unsupported_instruction:
+       if (!user_mode(regs))
+               printk(KERN_CRIT
+                      "MISALIGN: %lx: unsupported instruction %x (%s)\n",
+                      regs->pc, opcode, pop->name);
+       goto failed;
+
+transfer_failed:
+       set_fs(seg);
+       if (fixup) {
+               regs->pc = fixup->fixup;
+               return;
+       }
+       if (die_if_no_fixup("misalignment fixup", regs, code))
+               return;
+
+       info.si_signo   = SIGSEGV;
+       info.si_errno   = 0;
+       info.si_code    = 0;
+       info.si_addr    = (void *) regs->pc;
+       force_sig_info(SIGSEGV, &info, current);
+       return;
+
+       /* we matched the opcode */
+found_opcode:
+       kdebug("MISALIGN: %lx: %x==%x { %x, %x }\n",
+              regs->pc, opcode, pop->opcode, pop->params[0], pop->params[1]);
+
+       tmp = format_tbl[pop->format].opsz;
+       if (tmp > noc)
+               BUG(); /* match was less complete than it ought to have been */
+
+       if (tmp < noc) {
+               tmp = noc - tmp;
+               opcode >>= tmp;
+               pc -= tmp >> 3;
+       }
+
+       /* grab the extra displacement (note it's LSB first) */
+       disp = 0;
+       tmp = format_tbl[pop->format].dispsz >> 3;
+       while (tmp > 0) {
+               tmp--;
+               disp <<= 8;
+
+               pc++;
+               if (__get_user(byte, pc) != 0)
+                       goto fetch_error;
+               disp |= byte;
+       }
+
+       set_fs(KERNEL_XDS);
+       if (fixup || regs->epsw & EPSW_nSL)
+               set_fs(seg);
+
+       tmp = (pop->params[0] ^ pop->params[1]) & 0x80000000;
+       if (!tmp) {
+               if (!user_mode(regs))
+                       printk(KERN_CRIT
+                              "MISALIGN: %lx:"
+                              " insn not move to/from memory %x\n",
+                              regs->pc, opcode);
+               goto failed;
+       }
+
+       if (pop->params[0] & 0x80000000) {
+               /* move memory to register */
+               if (!misalignment_addr(registers, pop->params[0], opcode, disp,
+                                      &address, &postinc))
+                       goto bad_addr_mode;
+
+               if (!misalignment_reg(registers, pop->params[1], opcode, disp,
+                                     &store))
+                       goto bad_reg_mode;
+
+               if (strcmp(pop->name, "mov") == 0) {
+                       kdebug("FIXUP: mov (%p),DARn\n", address);
+                       if (copy_from_user(&data, (void *) address, 4) != 0)
+                               goto transfer_failed;
+                       if (pop->params[0] & 0x1000000)
+                               *postinc += 4;
+               } else if (strcmp(pop->name, "movhu") == 0) {
+                       kdebug("FIXUP: movhu (%p),DARn\n", address);
+                       data = 0;
+                       if (copy_from_user(&data, (void *) address, 2) != 0)
+                               goto transfer_failed;
+                       if (pop->params[0] & 0x1000000)
+                               *postinc += 2;
+               } else {
+                       goto unsupported_instruction;
+               }
+
+               *store = data;
+       } else {
+               /* move register to memory */
+               if (!misalignment_reg(registers, pop->params[0], opcode, disp,
+                                     &store))
+                       goto bad_reg_mode;
+
+               if (!misalignment_addr(registers, pop->params[1], opcode, disp,
+                                      &address, &postinc))
+                       goto bad_addr_mode;
+
+               data = *store;
+
+               if (strcmp(pop->name, "mov") == 0) {
+                       kdebug("FIXUP: mov %lx,(%p)\n", data, address);
+                       if (copy_to_user((void *) address, &data, 4) != 0)
+                               goto transfer_failed;
+                       if (pop->params[1] & 0x1000000)
+                               *postinc += 4;
+               } else if (strcmp(pop->name, "movhu") == 0) {
+                       kdebug("FIXUP: movhu %hx,(%p)\n",
+                              (uint16_t) data, address);
+                       if (copy_to_user((void *) address, &data, 2) != 0)
+                               goto transfer_failed;
+                       if (pop->params[1] & 0x1000000)
+                               *postinc += 2;
+               } else {
+                       goto unsupported_instruction;
+               }
+       }
+
+       tmp = format_tbl[pop->format].opsz + format_tbl[pop->format].dispsz;
+       regs->pc += tmp >> 3;
+
+       set_fs(seg);
+       return;
+}
+
+/*
+ * determine the address that was being accessed
+ */
+static int misalignment_addr(unsigned long *registers, unsigned params,
+                            unsigned opcode, unsigned disp,
+                            void **_address, unsigned long **_postinc)
+{
+       unsigned long *postinc = NULL, address = 0, tmp;
+
+       params &= 0x7fffffff;
+
+       do {
+               switch (params & 0xff) {
+               case DM0:
+                       postinc = &registers[Dreg_index[opcode & 0x03]];
+                       address += *postinc;
+                       break;
+               case DM1:
+                       postinc = &registers[Dreg_index[opcode >> 2 & 0x0c]];
+                       address += *postinc;
+                       break;
+               case DM2:
+                       postinc = &registers[Dreg_index[opcode >> 4 & 0x30]];
+                       address += *postinc;
+                       break;
+               case AM0:
+                       postinc = &registers[Areg_index[opcode & 0x03]];
+                       address += *postinc;
+                       break;
+               case AM1:
+                       postinc = &registers[Areg_index[opcode >> 2 & 0x0c]];
+                       address += *postinc;
+                       break;
+               case AM2:
+                       postinc = &registers[Areg_index[opcode >> 4 & 0x30]];
+                       address += *postinc;
+                       break;
+               case RM0:
+                       postinc = &registers[Rreg_index[opcode & 0x0f]];
+                       address += *postinc;
+                       break;
+               case RM1:
+                       postinc = &registers[Rreg_index[opcode >> 2 & 0x0f]];
+                       address += *postinc;
+                       break;
+               case RM2:
+                       postinc = &registers[Rreg_index[opcode >> 4 & 0x0f]];
+                       address += *postinc;
+                       break;
+               case RM4:
+                       postinc = &registers[Rreg_index[opcode >> 8 & 0x0f]];
+                       address += *postinc;
+                       break;
+               case RM6:
+                       postinc = &registers[Rreg_index[opcode >> 12 & 0x0f]];
+                       address += *postinc;
+                       break;
+               case RD0:
+                       postinc = &registers[Rreg_index[disp & 0x0f]];
+                       address += *postinc;
+                       break;
+               case RD2:
+                       postinc = &registers[Rreg_index[disp >> 4 & 0x0f]];
+                       address += *postinc;
+                       break;
+
+               case SD8:
+               case SIMM8:
+                       address += (int32_t) (int8_t) (disp & 0xff);
+                       break;
+               case SD16:
+                       address += (int32_t) (int16_t) (disp & 0xffff);
+                       break;
+               case SD24:
+                       tmp = disp << 8;
+                       asm("asr 8,%0" : "=r"(tmp) : "0"(tmp));
+                       address += tmp;
+                       break;
+               case SIMM4_2:
+                       tmp = opcode >> 4 & 0x0f;
+                       tmp <<= 28;
+                       asm("asr 28,%0" : "=r"(tmp) : "0"(tmp));
+                       address += tmp;
+                       break;
+               case IMM24:
+                       address += disp & 0x00ffffff;
+                       break;
+               case IMM32:
+               case IMM32_HIGH8:
+                       address += disp;
+                       break;
+               default:
+                       return 0;
+               }
+       } while ((params >>= 8));
+
+       *_address = (void *) address;
+       *_postinc = postinc;
+       return 1;
+}
+
+/*
+ * determine the register that is acting as source/dest
+ */
+static int misalignment_reg(unsigned long *registers, unsigned params,
+                           unsigned opcode, unsigned disp,
+                           unsigned long **_register)
+{
+       params &= 0x7fffffff;
+
+       if (params & 0xffffff00)
+               return 0;
+
+       switch (params & 0xff) {
+       case DM0:
+               *_register = &registers[Dreg_index[opcode & 0x03]];
+               break;
+       case DM1:
+               *_register = &registers[Dreg_index[opcode >> 2 & 0x03]];
+               break;
+       case DM2:
+               *_register = &registers[Dreg_index[opcode >> 4 & 0x03]];
+               break;
+       case AM0:
+               *_register = &registers[Areg_index[opcode & 0x03]];
+               break;
+       case AM1:
+               *_register = &registers[Areg_index[opcode >> 2 & 0x03]];
+               break;
+       case AM2:
+               *_register = &registers[Areg_index[opcode >> 4 & 0x03]];
+               break;
+       case RM0:
+               *_register = &registers[Rreg_index[opcode & 0x0f]];
+               break;
+       case RM1:
+               *_register = &registers[Rreg_index[opcode >> 2 & 0x0f]];
+               break;
+       case RM2:
+               *_register = &registers[Rreg_index[opcode >> 4 & 0x0f]];
+               break;
+       case RM4:
+               *_register = &registers[Rreg_index[opcode >> 8 & 0x0f]];
+               break;
+       case RM6:
+               *_register = &registers[Rreg_index[opcode >> 12 & 0x0f]];
+               break;
+       case RD0:
+               *_register = &registers[Rreg_index[disp & 0x0f]];
+               break;
+       case RD2:
+               *_register = &registers[Rreg_index[disp >> 4 & 0x0f]];
+               break;
+       case SP:
+               *_register = &registers[REG_SP >> 2];
+               break;
+
+       default:
+               return 0;
+       }
+
+       return 1;
+}
diff --git a/arch/mn10300/mm/mmu-context.c b/arch/mn10300/mm/mmu-context.c
new file mode 100644 (file)
index 0000000..31c9d27
--- /dev/null
@@ -0,0 +1,80 @@
+/* MN10300 MMU context allocation and management
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <asm/mmu_context.h>
+#include <asm/tlbflush.h>
+
+/*
+ * list of the MMU contexts last allocated on each CPU
+ */
+unsigned long mmu_context_cache[NR_CPUS] = {
+       [0 ... NR_CPUS - 1] = MMU_CONTEXT_FIRST_VERSION * 2 - 1,
+};
+
+/*
+ * flush the specified TLB entry
+ */
+void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr)
+{
+       unsigned long pteu, cnx, flags;
+
+       addr &= PAGE_MASK;
+
+       /* make sure the context doesn't migrate and defend against
+        * interference from vmalloc'd regions */
+       local_irq_save(flags);
+
+       cnx = mm_context(vma->vm_mm);
+
+       if (cnx != MMU_NO_CONTEXT) {
+               pteu = addr | (cnx & 0x000000ffUL);
+               IPTEU = pteu;
+               DPTEU = pteu;
+               if (IPTEL & xPTEL_V)
+                       IPTEL = 0;
+               if (DPTEL & xPTEL_V)
+                       DPTEL = 0;
+       }
+
+       local_irq_restore(flags);
+}
+
+/*
+ * preemptively set a TLB entry
+ */
+void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, pte_t pte)
+{
+       unsigned long pteu, ptel, cnx, flags;
+
+       addr &= PAGE_MASK;
+       ptel = pte_val(pte) & ~(xPTEL_UNUSED1 | xPTEL_UNUSED2);
+
+       /* make sure the context doesn't migrate and defend against
+        * interference from vmalloc'd regions */
+       local_irq_save(flags);
+
+       cnx = mm_context(vma->vm_mm);
+
+       if (cnx != MMU_NO_CONTEXT) {
+               pteu = addr | (cnx & 0x000000ffUL);
+               if (!(pte_val(pte) & _PAGE_NX)) {
+                       IPTEU = pteu;
+                       if (IPTEL & xPTEL_V)
+                               IPTEL = ptel;
+               }
+               DPTEU = pteu;
+               if (DPTEL & xPTEL_V)
+                       DPTEL = ptel;
+       }
+
+       local_irq_restore(flags);
+}
diff --git a/arch/mn10300/mm/pgtable.c b/arch/mn10300/mm/pgtable.c
new file mode 100644 (file)
index 0000000..a477038
--- /dev/null
@@ -0,0 +1,197 @@
+/* MN10300 Page table management
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Modified by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/sched.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/mm.h>
+#include <linux/swap.h>
+#include <linux/smp.h>
+#include <linux/highmem.h>
+#include <linux/slab.h>
+#include <linux/pagemap.h>
+#include <linux/spinlock.h>
+#include <linux/quicklist.h>
+
+#include <asm/system.h>
+#include <asm/pgtable.h>
+#include <asm/pgalloc.h>
+#include <asm/tlb.h>
+#include <asm/tlbflush.h>
+
+void show_mem(void)
+{
+       unsigned long i;
+       int free = 0, total = 0, reserved = 0, shared = 0;
+
+       int cached = 0;
+       printk(KERN_INFO "Mem-info:\n");
+       show_free_areas();
+       i = max_mapnr;
+       while (i-- > 0) {
+               total++;
+               if (PageReserved(mem_map + i))
+                       reserved++;
+               else if (PageSwapCache(mem_map + i))
+                       cached++;
+               else if (!page_count(mem_map + i))
+                       free++;
+               else
+                       shared += page_count(mem_map + i) - 1;
+       }
+       printk(KERN_INFO "%d pages of RAM\n", total);
+       printk(KERN_INFO "%d free pages\n", free);
+       printk(KERN_INFO "%d reserved pages\n", reserved);
+       printk(KERN_INFO "%d pages shared\n", shared);
+       printk(KERN_INFO "%d pages swap cached\n", cached);
+}
+
+/*
+ * Associate a large virtual page frame with a given physical page frame
+ * and protection flags for that frame. pfn is for the base of the page,
+ * vaddr is what the page gets mapped to - both must be properly aligned.
+ * The pmd must already be instantiated. Assumes PAE mode.
+ */
+void set_pmd_pfn(unsigned long vaddr, unsigned long pfn, pgprot_t flags)
+{
+       pgd_t *pgd;
+       pud_t *pud;
+       pmd_t *pmd;
+
+       if (vaddr & (PMD_SIZE-1)) {             /* vaddr is misaligned */
+               printk(KERN_ERR "set_pmd_pfn: vaddr misaligned\n");
+               return; /* BUG(); */
+       }
+       if (pfn & (PTRS_PER_PTE-1)) {           /* pfn is misaligned */
+               printk(KERN_ERR "set_pmd_pfn: pfn misaligned\n");
+               return; /* BUG(); */
+       }
+       pgd = swapper_pg_dir + pgd_index(vaddr);
+       if (pgd_none(*pgd)) {
+               printk(KERN_ERR "set_pmd_pfn: pgd_none\n");
+               return; /* BUG(); */
+       }
+       pud = pud_offset(pgd, vaddr);
+       pmd = pmd_offset(pud, vaddr);
+       set_pmd(pmd, pfn_pmd(pfn, flags));
+       /*
+        * It's enough to flush this one mapping.
+        * (PGE mappings get flushed as well)
+        */
+       __flush_tlb_one(vaddr);
+}
+
+pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
+{
+       pte_t *pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT);
+       if (pte)
+               clear_page(pte);
+       return pte;
+}
+
+struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
+{
+       struct page *pte;
+
+#ifdef CONFIG_HIGHPTE
+       pte = alloc_pages(GFP_KERNEL|__GFP_HIGHMEM|__GFP_REPEAT, 0);
+#else
+       pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0);
+#endif
+       if (pte)
+               clear_highpage(pte);
+       return pte;
+}
+
+/*
+ * List of all pgd's needed for non-PAE so it can invalidate entries
+ * in both cached and uncached pgd's; not needed for PAE since the
+ * kernel pmd is shared. If PAE were not to share the pmd a similar
+ * tactic would be needed. This is essentially codepath-based locking
+ * against pageattr.c; it is the unique case in which a valid change
+ * of kernel pagetables can't be lazily synchronized by vmalloc faults.
+ * vmalloc faults work because attached pagetables are never freed.
+ * If the locking proves to be non-performant, a ticketing scheme with
+ * checks at dup_mmap(), exec(), and other mmlist addition points
+ * could be used. The locking scheme was chosen on the basis of
+ * manfred's recommendations and having no core impact whatsoever.
+ * -- wli
+ */
+DEFINE_SPINLOCK(pgd_lock);
+struct page *pgd_list;
+
+static inline void pgd_list_add(pgd_t *pgd)
+{
+       struct page *page = virt_to_page(pgd);
+       page->index = (unsigned long) pgd_list;
+       if (pgd_list)
+               set_page_private(pgd_list, (unsigned long) &page->index);
+       pgd_list = page;
+       set_page_private(page, (unsigned long) &pgd_list);
+}
+
+static inline void pgd_list_del(pgd_t *pgd)
+{
+       struct page *next, **pprev, *page = virt_to_page(pgd);
+       next = (struct page *) page->index;
+       pprev = (struct page **) page_private(page);
+       *pprev = next;
+       if (next)
+               set_page_private(next, (unsigned long) pprev);
+}
+
+void pgd_ctor(void *pgd)
+{
+       unsigned long flags;
+
+       if (PTRS_PER_PMD == 1)
+               spin_lock_irqsave(&pgd_lock, flags);
+
+       memcpy((pgd_t *)pgd + USER_PTRS_PER_PGD,
+                       swapper_pg_dir + USER_PTRS_PER_PGD,
+                       (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
+
+       if (PTRS_PER_PMD > 1)
+               return;
+
+       pgd_list_add(pgd);
+       spin_unlock_irqrestore(&pgd_lock, flags);
+       memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
+}
+
+/* never called when PTRS_PER_PMD > 1 */
+void pgd_dtor(void *pgd)
+{
+       unsigned long flags; /* can be called from interrupt context */
+
+       spin_lock_irqsave(&pgd_lock, flags);
+       pgd_list_del(pgd);
+       spin_unlock_irqrestore(&pgd_lock, flags);
+}
+
+pgd_t *pgd_alloc(struct mm_struct *mm)
+{
+       return quicklist_alloc(0, GFP_KERNEL, pgd_ctor);
+}
+
+void pgd_free(struct mm_struct *mm, pgd_t *pgd)
+{
+       quicklist_free(0, pgd_dtor, pgd);
+}
+
+void __init pgtable_cache_init(void)
+{
+}
+
+void check_pgt_cache(void)
+{
+       quicklist_trim(0, pgd_dtor, 25, 16);
+}
diff --git a/arch/mn10300/mm/tlb-mn10300.S b/arch/mn10300/mm/tlb-mn10300.S
new file mode 100644 (file)
index 0000000..7892080
--- /dev/null
@@ -0,0 +1,207 @@
+###############################################################################
+#
+# TLB loading functions
+#
+# Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+# Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+# Modified by David Howells (dhowells@redhat.com)
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public Licence
+# as published by the Free Software Foundation; either version
+# 2 of the Licence, or (at your option) any later version.
+#
+###############################################################################
+#include <linux/sys.h>
+#include <linux/linkage.h>
+#include <asm/smp.h>
+#include <asm/intctl-regs.h>
+#include <asm/frame.inc>
+#include <asm/page.h>
+#include <asm/pgtable.h>
+
+###############################################################################
+#
+# Instruction TLB Miss handler entry point
+#
+###############################################################################
+       .type   itlb_miss,@function
+ENTRY(itlb_miss)
+       and     ~EPSW_NMID,epsw
+#ifdef CONFIG_GDBSTUB
+       movm    [d2,d3,a2],(sp)
+#else
+       or      EPSW_nAR,epsw           # switch D0-D3 & A0-A3 to the alternate
+                                       # register bank
+       nop
+       nop
+       nop
+#endif
+
+       mov     (IPTEU),d3
+       mov     (PTBR),a2
+       mov     d3,d2
+       and     0xffc00000,d2
+       lsr     20,d2
+       mov     (a2,d2),a2              # PTD *ptd = PGD[addr 31..22]
+       btst    _PAGE_VALID,a2
+       beq     itlb_miss_fault         # jump if doesn't point anywhere
+
+       and     ~(PAGE_SIZE-1),a2
+       mov     d3,d2
+       and     0x003ff000,d2
+       lsr     10,d2
+       add     d2,a2
+       mov     (a2),d2                 # get pte from PTD[addr 21..12]
+       btst    _PAGE_VALID,d2
+       beq     itlb_miss_fault         # jump if doesn't point to a page
+                                       # (might be a swap id)
+       bset    _PAGE_ACCESSED,(0,a2)
+       and     ~(xPTEL_UNUSED1|xPTEL_UNUSED2),d2
+itlb_miss_set:
+       mov     d2,(IPTEL)              # change the TLB
+#ifdef CONFIG_GDBSTUB
+       movm    (sp),[d2,d3,a2]
+#endif
+       rti
+
+itlb_miss_fault:
+       mov     _PAGE_VALID,d2          # force address error handler to be
+                                       # invoked
+       bra     itlb_miss_set
+
+       .size   itlb_miss, . - itlb_miss
+
+###############################################################################
+#
+# Data TLB Miss handler entry point
+#
+###############################################################################
+       .type   dtlb_miss,@function
+ENTRY(dtlb_miss)
+       and     ~EPSW_NMID,epsw
+#ifdef CONFIG_GDBSTUB
+       movm    [d2,d3,a2],(sp)
+#else
+       or      EPSW_nAR,epsw           # switch D0-D3 & A0-A3 to the alternate
+                                       # register bank
+       nop
+       nop
+       nop
+#endif
+
+       mov     (DPTEU),d3
+       mov     (PTBR),a2
+       mov     d3,d2
+       and     0xffc00000,d2
+       lsr     20,d2
+       mov     (a2,d2),a2              # PTD *ptd = PGD[addr 31..22]
+       btst    _PAGE_VALID,a2
+       beq     dtlb_miss_fault         # jump if doesn't point anywhere
+
+       and     ~(PAGE_SIZE-1),a2
+       mov     d3,d2
+       and     0x003ff000,d2
+       lsr     10,d2
+       add     d2,a2
+       mov     (a2),d2                 # get pte from PTD[addr 21..12]
+       btst    _PAGE_VALID,d2
+       beq     dtlb_miss_fault         # jump if doesn't point to a page
+                                       # (might be a swap id)
+       bset    _PAGE_ACCESSED,(0,a2)
+       and     ~(xPTEL_UNUSED1|xPTEL_UNUSED2),d2
+dtlb_miss_set:
+       mov     d2,(DPTEL)              # change the TLB
+#ifdef CONFIG_GDBSTUB
+       movm    (sp),[d2,d3,a2]
+#endif
+       rti
+
+dtlb_miss_fault:
+       mov     _PAGE_VALID,d2          # force address error handler to be
+                                       # invoked
+       bra     dtlb_miss_set
+       .size   dtlb_miss, . - dtlb_miss
+
+###############################################################################
+#
+# Instruction TLB Address Error handler entry point
+#
+###############################################################################
+       .type   itlb_aerror,@function
+ENTRY(itlb_aerror)
+       and     ~EPSW_NMID,epsw
+       add     -4,sp
+       SAVE_ALL
+       add     -4,sp                           # need to pass three params
+
+       # calculate the fault code
+       movhu   (MMUFCR_IFC),d1
+       or      0x00010000,d1                   # it's an instruction fetch
+
+       # determine the page address
+       mov     (IPTEU),a2
+       mov     a2,d0
+       and     PAGE_MASK,d0
+       mov     d0,(12,sp)
+
+       clr     d0
+       mov     d0,(IPTEL)
+
+       and     ~EPSW_NMID,epsw
+       or      EPSW_IE,epsw
+       mov     fp,d0
+       call    do_page_fault[],0               # do_page_fault(regs,code,addr
+
+       jmp     ret_from_exception
+       .size   itlb_aerror, . - itlb_aerror
+
+###############################################################################
+#
+# Data TLB Address Error handler entry point
+#
+###############################################################################
+       .type   dtlb_aerror,@function
+ENTRY(dtlb_aerror)
+       and     ~EPSW_NMID,epsw
+       add     -4,sp
+       mov     d1,(sp)
+
+       movhu   (MMUFCR_DFC),d1                 # is it the initial valid write
+                                               # to this page?
+       and     MMUFCR_xFC_INITWR,d1
+       beq     dtlb_pagefault                  # jump if not
+
+       mov     (DPTEL),d1                      # set the dirty bit
+                                               # (don't replace with BSET!)
+       or      _PAGE_DIRTY,d1
+       mov     d1,(DPTEL)
+       mov     (sp),d1
+       add     4,sp
+       rti
+
+       ALIGN
+dtlb_pagefault:
+       mov     (sp),d1
+       SAVE_ALL
+       add     -4,sp                           # need to pass three params
+
+       # calculate the fault code
+       movhu   (MMUFCR_DFC),d1
+
+       # determine the page address
+       mov     (DPTEU),a2
+       mov     a2,d0
+       and     PAGE_MASK,d0
+       mov     d0,(12,sp)
+
+       clr     d0
+       mov     d0,(DPTEL)
+
+       and     ~EPSW_NMID,epsw
+       or      EPSW_IE,epsw
+       mov     fp,d0
+       call    do_page_fault[],0               # do_page_fault(regs,code,addr
+
+       jmp     ret_from_exception
+       .size   dtlb_aerror, . - dtlb_aerror
diff --git a/arch/mn10300/oprofile/Kconfig b/arch/mn10300/oprofile/Kconfig
new file mode 100644 (file)
index 0000000..19d3773
--- /dev/null
@@ -0,0 +1,23 @@
+
+menu "Profiling support"
+       depends on EXPERIMENTAL
+
+config PROFILING
+       bool "Profiling support (EXPERIMENTAL)"
+       help
+         Say Y here to enable the extended profiling support mechanisms used
+         by profilers such as OProfile.
+
+
+config OPROFILE
+       tristate "OProfile system profiling (EXPERIMENTAL)"
+       depends on PROFILING
+       help
+         OProfile is a profiling system capable of profiling the
+         whole system, include the kernel, kernel modules, libraries,
+         and applications.
+
+         If unsure, say N.
+
+endmenu
+
diff --git a/arch/mn10300/oprofile/Makefile b/arch/mn10300/oprofile/Makefile
new file mode 100644 (file)
index 0000000..918dbe6
--- /dev/null
@@ -0,0 +1,13 @@
+#
+# Makefile for the MN10300-specific profiling code
+#
+obj-$(CONFIG_OPROFILE) += oprofile.o
+
+DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \
+               oprof.o cpu_buffer.o buffer_sync.o \
+               event_buffer.o oprofile_files.o \
+               oprofilefs.o oprofile_stats.o \
+               timer_int.o )
+
+oprofile-y                             := $(DRIVER_OBJS) op_model_null.o
+
diff --git a/arch/mn10300/oprofile/op_model_null.c b/arch/mn10300/oprofile/op_model_null.c
new file mode 100644 (file)
index 0000000..cd4ab37
--- /dev/null
@@ -0,0 +1,22 @@
+/* Null profiling driver
+ *
+ * Copyright (C) 2003  Paul Mundt
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * Licence.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+#include <linux/kernel.h>
+#include <linux/oprofile.h>
+#include <linux/init.h>
+#include <linux/errno.h>
+
+int __init oprofile_arch_init(struct oprofile_operations *ops)
+{
+       return -ENODEV;
+}
+
+void oprofile_arch_exit(void)
+{
+}
+
diff --git a/arch/mn10300/proc-mn103e010/Makefile b/arch/mn10300/proc-mn103e010/Makefile
new file mode 100644 (file)
index 0000000..ac2c978
--- /dev/null
@@ -0,0 +1,5 @@
+#
+# Makefile for the MN103E010 processor chip specific code
+#
+obj-y   := proc-init.o
+
diff --git a/arch/mn10300/proc-mn103e010/proc-init.c b/arch/mn10300/proc-mn103e010/proc-init.c
new file mode 100644 (file)
index 0000000..9a482ef
--- /dev/null
@@ -0,0 +1,75 @@
+/* MN103E010 Processor initialisation
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/kernel.h>
+#include <asm/rtc.h>
+
+/*
+ * initialise the on-silicon processor peripherals
+ */
+asmlinkage void __init processor_init(void)
+{
+       int loop;
+
+       /* set up the exception table first */
+       for (loop = 0x000; loop < 0x400; loop += 8)
+               __set_intr_stub(loop, __common_exception);
+
+       __set_intr_stub(EXCEP_ITLBMISS,         itlb_miss);
+       __set_intr_stub(EXCEP_DTLBMISS,         dtlb_miss);
+       __set_intr_stub(EXCEP_IAERROR,          itlb_aerror);
+       __set_intr_stub(EXCEP_DAERROR,          dtlb_aerror);
+       __set_intr_stub(EXCEP_BUSERROR,         raw_bus_error);
+       __set_intr_stub(EXCEP_DOUBLE_FAULT,     double_fault);
+       __set_intr_stub(EXCEP_SYSCALL0,         system_call);
+
+       __set_intr_stub(EXCEP_NMI,              nmi_handler);
+       __set_intr_stub(EXCEP_WDT,              nmi_handler);
+       __set_intr_stub(EXCEP_IRQ_LEVEL0,       irq_handler);
+       __set_intr_stub(EXCEP_IRQ_LEVEL1,       irq_handler);
+       __set_intr_stub(EXCEP_IRQ_LEVEL2,       irq_handler);
+       __set_intr_stub(EXCEP_IRQ_LEVEL3,       irq_handler);
+       __set_intr_stub(EXCEP_IRQ_LEVEL4,       irq_handler);
+       __set_intr_stub(EXCEP_IRQ_LEVEL5,       irq_handler);
+       __set_intr_stub(EXCEP_IRQ_LEVEL6,       irq_handler);
+
+       IVAR0 = EXCEP_IRQ_LEVEL0;
+       IVAR1 = EXCEP_IRQ_LEVEL1;
+       IVAR2 = EXCEP_IRQ_LEVEL2;
+       IVAR3 = EXCEP_IRQ_LEVEL3;
+       IVAR4 = EXCEP_IRQ_LEVEL4;
+       IVAR5 = EXCEP_IRQ_LEVEL5;
+       IVAR6 = EXCEP_IRQ_LEVEL6;
+
+       mn10300_dcache_flush_inv();
+       mn10300_icache_inv();
+
+       /* disable all interrupts and set to priority 6 (lowest) */
+       for (loop = 0; loop < NR_IRQS; loop++)
+               GxICR(loop) = GxICR_LEVEL_6 | GxICR_DETECT;
+
+       /* clear the timers */
+       TM0MD   = 0;
+       TM1MD   = 0;
+       TM2MD   = 0;
+       TM3MD   = 0;
+       TM4MD   = 0;
+       TM5MD   = 0;
+       TM6MD   = 0;
+       TM6MDA  = 0;
+       TM6MDB  = 0;
+       TM7MD   = 0;
+       TM8MD   = 0;
+       TM9MD   = 0;
+       TM10MD  = 0;
+       TM11MD  = 0;
+
+       calibrate_clock();
+}
diff --git a/arch/mn10300/unit-asb2303/Makefile b/arch/mn10300/unit-asb2303/Makefile
new file mode 100644 (file)
index 0000000..38a5bb4
--- /dev/null
@@ -0,0 +1,6 @@
+###############################################################################
+#
+# Makefile for the ASB2303 board
+#
+###############################################################################
+obj-y   := unit-init.o smc91111.o flash.o leds.o
diff --git a/arch/mn10300/unit-asb2303/flash.c b/arch/mn10300/unit-asb2303/flash.c
new file mode 100644 (file)
index 0000000..17fe083
--- /dev/null
@@ -0,0 +1,100 @@
+/* Handle mapping of the flash on the ASB2303 board
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/mtd/partitions.h>
+#include <linux/mtd/physmap.h>
+
+#define ASB2303_PROM_ADDR      0xA0000000      /* Boot PROM */
+#define ASB2303_PROM_SIZE      (2 * 1024 * 1024)
+#define ASB2303_FLASH_ADDR     0xA4000000      /* System Flash */
+#define ASB2303_FLASH_SIZE     (32 * 1024 * 1024)
+#define ASB2303_CONFIG_ADDR    0xA6000000      /* System Config EEPROM */
+#define ASB2303_CONFIG_SIZE    (8 * 1024)
+
+/*
+ * default MTD partition table for both main flash devices, expected to be
+ * overridden by RedBoot
+ */
+static struct mtd_partition asb2303_partitions[] = {
+       {
+               .name           = "Bootloader",
+               .size           = 0x00040000,
+               .offset         = 0,
+               .mask_flags     = MTD_CAP_ROM /* force read-only */
+       }, {
+               .name           = "Kernel",
+               .size           = 0x00400000,
+               .offset         = 0x00040000,
+       }, {
+               .name           = "Filesystem",
+               .size           = MTDPART_SIZ_FULL,
+               .offset         = 0x00440000
+       }
+};
+
+/*
+ * the ASB2303 Boot PROM definition
+ */
+static struct physmap_flash_data asb2303_bootprom_data = {
+       .width          = 2,
+       .nr_parts       = 1,
+       .parts          = asb2303_partitions,
+};
+
+static struct resource asb2303_bootprom_resource = {
+       .start          = ASB2303_PROM_ADDR,
+       .end            = ASB2303_PROM_ADDR + ASB2303_PROM_SIZE,
+       .flags          = IORESOURCE_MEM,
+};
+
+static struct platform_device asb2303_bootprom = {
+       .name           = "physmap-flash",
+       .id             = 0,
+       .dev.platform_data = &asb2303_bootprom_data,
+       .num_resources  = 1,
+       .resource       = &asb2303_bootprom_resource,
+};
+
+/*
+ * the ASB2303 System Flash definition
+ */
+static struct physmap_flash_data asb2303_sysflash_data = {
+       .width          = 4,
+       .nr_parts       = 1,
+       .parts          = asb2303_partitions,
+};
+
+static struct resource asb2303_sysflash_resource = {
+       .start          = ASB2303_FLASH_ADDR,
+       .end            = ASB2303_FLASH_ADDR + ASB2303_FLASH_SIZE,
+       .flags          = IORESOURCE_MEM,
+};
+
+static struct platform_device asb2303_sysflash = {
+       .name           = "physmap-flash",
+       .id             = 1,
+       .dev.platform_data = &asb2303_sysflash_data,
+       .num_resources  = 1,
+       .resource       = &asb2303_sysflash_resource,
+};
+
+/*
+ * register the ASB2303 flashes
+ */
+static int __init asb2303_mtd_init(void)
+{
+       platform_device_register(&asb2303_bootprom);
+       platform_device_register(&asb2303_sysflash);
+       return 0;
+}
+
+module_init(asb2303_mtd_init);
diff --git a/arch/mn10300/unit-asb2303/leds.c b/arch/mn10300/unit-asb2303/leds.c
new file mode 100644 (file)
index 0000000..cd4bc78
--- /dev/null
@@ -0,0 +1,52 @@
+/* ASB2303 peripheral 7-segment LEDs x1 support
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/kernel.h>
+#include <linux/param.h>
+#include <linux/init.h>
+
+#include <asm/io.h>
+#include <asm/processor.h>
+#include <asm/intctl-regs.h>
+#include <asm/rtc-regs.h>
+#include <asm/unit/leds.h>
+
+#if 0
+static const u8 asb2303_led_hex_tbl[16] = {
+       0x80, 0xf2, 0x48, 0x60, 0x32, 0x24, 0x04, 0xf0,
+       0x00, 0x20, 0x10, 0x06, 0x8c, 0x42, 0x0c, 0x1c
+};
+#endif
+
+static const u8 asb2303_led_chase_tbl[6] = {
+       ~0x02,  /* top          - segA */
+       ~0x04,  /* right top    - segB */
+       ~0x08,  /* right bottom - segC */
+       ~0x10,  /* bottom       - segD */
+       ~0x20,  /* left bottom  - segE */
+       ~0x40,  /* left top     - segF */
+};
+
+static unsigned asb2303_led_chase;
+
+void peripheral_leds_display_exception(enum exception_code code)
+{
+       ASB2303_GPIO0DEF = 0x5555;      /* configure as an output port */
+       ASB2303_7SEGLEDS = 0x6d;        /* triple horizontal bar */
+}
+
+void peripheral_leds_led_chase(void)
+{
+       ASB2303_GPIO0DEF = 0x5555;      /* configure as an output port */
+       ASB2303_7SEGLEDS = asb2303_led_chase_tbl[asb2303_led_chase];
+       asb2303_led_chase++;
+       if (asb2303_led_chase >= 6)
+               asb2303_led_chase = 0;
+}
diff --git a/arch/mn10300/unit-asb2303/smc91111.c b/arch/mn10300/unit-asb2303/smc91111.c
new file mode 100644 (file)
index 0000000..30875dd
--- /dev/null
@@ -0,0 +1,52 @@
+/* ASB2303 initialisation
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/param.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+
+#include <asm/io.h>
+#include <asm/timex.h>
+#include <asm/processor.h>
+#include <asm/intctl-regs.h>
+#include <asm/unit/smc91111.h>
+
+static struct resource smc91c111_resources[] = {
+       [0] = {
+               .start          = SMC91111_BASE,
+               .end            = SMC91111_BASE_END,
+               .flags          = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start          = SMC91111_IRQ,
+               .end            = SMC91111_IRQ,
+               .flags          = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device smc91c111_device = {
+       .name           = "smc91x",
+       .id             = 0,
+       .num_resources  = ARRAY_SIZE(smc91c111_resources),
+       .resource       = smc91c111_resources,
+};
+
+/*
+ * add platform devices
+ */
+static int __init unit_device_init(void)
+{
+       platform_device_register(&smc91c111_device);
+       return 0;
+}
+
+device_initcall(unit_device_init);
diff --git a/arch/mn10300/unit-asb2303/unit-init.c b/arch/mn10300/unit-asb2303/unit-init.c
new file mode 100644 (file)
index 0000000..14b2c81
--- /dev/null
@@ -0,0 +1,60 @@
+/* ASB2303 initialisation
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#include <linux/kernel.h>
+#include <linux/param.h>
+#include <linux/init.h>
+#include <linux/device.h>
+
+#include <asm/io.h>
+#include <asm/setup.h>
+#include <asm/processor.h>
+#include <asm/irq.h>
+#include <asm/intctl-regs.h>
+
+/*
+ * initialise some of the unit hardware before gdbstub is set up
+ */
+asmlinkage void __init unit_init(void)
+{
+       /* set up the external interrupts */
+       SET_XIRQ_TRIGGER(0, XIRQ_TRIGGER_HILEVEL);
+       SET_XIRQ_TRIGGER(2, XIRQ_TRIGGER_LOWLEVEL);
+       SET_XIRQ_TRIGGER(3, XIRQ_TRIGGER_HILEVEL);
+       SET_XIRQ_TRIGGER(4, XIRQ_TRIGGER_LOWLEVEL);
+       SET_XIRQ_TRIGGER(5, XIRQ_TRIGGER_LOWLEVEL);
+}
+
+/*
+ * initialise the rest of the unit hardware after gdbstub is ready
+ */
+void __init unit_setup(void)
+{
+}
+
+/*
+ * initialise the external interrupts used by a unit of this type
+ */
+void __init unit_init_IRQ(void)
+{
+       unsigned int extnum;
+
+       for (extnum = 0; extnum < NR_XIRQS; extnum++) {
+               switch (GET_XIRQ_TRIGGER(extnum)) {
+               case XIRQ_TRIGGER_HILEVEL:
+               case XIRQ_TRIGGER_LOWLEVEL:
+                       set_irq_handler(XIRQ2IRQ(extnum), handle_level_irq);
+                       break;
+               default:
+                       break;
+               }
+       }
+}
diff --git a/arch/mn10300/unit-asb2305/Makefile b/arch/mn10300/unit-asb2305/Makefile
new file mode 100644 (file)
index 0000000..0551022
--- /dev/null
@@ -0,0 +1,8 @@
+###############################################################################
+#
+# Makefile for the ASB2305 board
+#
+###############################################################################
+obj-y   := unit-init.o leds.o
+
+obj-$(CONFIG_PCI) += pci.o pci-asb2305.o pci-irq.o pci-iomap.o
diff --git a/arch/mn10300/unit-asb2305/leds.c b/arch/mn10300/unit-asb2305/leds.c
new file mode 100644 (file)
index 0000000..e99dcc9
--- /dev/null
@@ -0,0 +1,124 @@
+/* ASB2305 Peripheral 7-segment LEDs x4 support
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/kernel.h>
+#include <linux/param.h>
+#include <linux/init.h>
+#include <asm/io.h>
+#include <asm/processor.h>
+#include <asm/cpu/intctl-regs.h>
+#include <asm/cpu/rtc-regs.h>
+#include <asm/unit/leds.h>
+
+static const u8 asb2305_led_hex_tbl[16] = {
+       0x80, 0xf2, 0x48, 0x60, 0x32, 0x24, 0x04, 0xf0,
+       0x00, 0x20, 0x10, 0x06, 0x8c, 0x42, 0x0c, 0x1c
+};
+
+static const u32 asb2305_led_chase_tbl[6] = {
+       ~0x02020202,    /* top          - segA */
+       ~0x04040404,    /* right top    - segB */
+       ~0x08080808,    /* right bottom - segC */
+       ~0x10101010,    /* bottom       - segD */
+       ~0x20202020,    /* left bottom  - segE */
+       ~0x40404040,    /* left top     - segF */
+};
+
+static unsigned asb2305_led_chase;
+
+void peripheral_leds7x4_display_dec(unsigned int val, unsigned int points)
+{
+       u32 leds;
+
+       leds = asb2305_led_hex_tbl[(val/1000) % 10];
+       leds <<= 8;
+       leds |= asb2305_led_hex_tbl[(val/100) % 10];
+       leds <<= 8;
+       leds |= asb2305_led_hex_tbl[(val/10) % 10];
+       leds <<= 8;
+       leds |= asb2305_led_hex_tbl[val % 10];
+       leds |= points^0x01010101;
+
+       ASB2305_7SEGLEDS = leds;
+}
+
+void peripheral_leds7x4_display_hex(unsigned int val, unsigned int points)
+{
+       u32 leds;
+
+       leds = asb2305_led_hex_tbl[(val/1000) % 10];
+       leds <<= 8;
+       leds |= asb2305_led_hex_tbl[(val/100) % 10];
+       leds <<= 8;
+       leds |= asb2305_led_hex_tbl[(val/10) % 10];
+       leds <<= 8;
+       leds |= asb2305_led_hex_tbl[val % 10];
+       leds |= points^0x01010101;
+
+       ASB2305_7SEGLEDS = leds;
+}
+
+void peripheral_leds_display_exception(enum exception_code code)
+{
+       u32 leds;
+
+       leds = asb2305_led_hex_tbl[(code/0x100) % 0x10];
+       leds <<= 8;
+       leds |= asb2305_led_hex_tbl[(code/0x10) % 0x10];
+       leds <<= 8;
+       leds |= asb2305_led_hex_tbl[code % 0x10];
+       leds |= 0x6d010101;
+
+       ASB2305_7SEGLEDS = leds;
+}
+
+void peripheral_leds7x4_display_minssecs(unsigned int time, unsigned int points)
+{
+       u32 leds;
+
+       leds = asb2305_led_hex_tbl[(time/600) % 6];
+       leds <<= 8;
+       leds |= asb2305_led_hex_tbl[(time/60) % 10];
+       leds <<= 8;
+       leds |= asb2305_led_hex_tbl[(time/10) % 6];
+       leds <<= 8;
+       leds |= asb2305_led_hex_tbl[time % 10];
+       leds |= points^0x01010101;
+
+       ASB2305_7SEGLEDS = leds;
+}
+
+void peripheral_leds7x4_display_rtc(void)
+{
+       unsigned int clock;
+       u8 mins, secs;
+
+       mins = RTMCR;
+       secs = RTSCR;
+
+       clock = ((mins & 0xf0) >> 4);
+       clock *= 10;
+       clock += (mins & 0x0f);
+       clock *= 6;
+
+       clock += ((secs & 0xf0) >> 4);
+       clock *= 10;
+       clock += (secs & 0x0f);
+
+       peripheral_leds7x4_display_minssecs(clock, 0);
+}
+
+void peripheral_leds_led_chase(void)
+{
+       ASB2305_7SEGLEDS = asb2305_led_chase_tbl[asb2305_led_chase];
+       asb2305_led_chase++;
+       if (asb2305_led_chase >= 6)
+               asb2305_led_chase = 0;
+}
diff --git a/arch/mn10300/unit-asb2305/pci-asb2305.c b/arch/mn10300/unit-asb2305/pci-asb2305.c
new file mode 100644 (file)
index 0000000..d100ca7
--- /dev/null
@@ -0,0 +1,303 @@
+/* ASB2305 PCI resource stuff
+ *
+ * Copyright (C) 2001 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ * - Derived from arch/i386/pci-i386.c
+ *   - Copyright 1997--2000 Martin Mares <mj@suse.cz>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/errno.h>
+#include "pci-asb2305.h"
+
+/*
+ * We need to avoid collisions with `mirrored' VGA ports
+ * and other strange ISA hardware, so we always want the
+ * addresses to be allocated in the 0x000-0x0ff region
+ * modulo 0x400.
+ *
+ * Why? Because some silly external IO cards only decode
+ * the low 10 bits of the IO address. The 0x00-0xff region
+ * is reserved for motherboard devices that decode all 16
+ * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
+ * but we want to try to avoid allocating at 0x2900-0x2bff
+ * which might have be mirrored at 0x0100-0x03ff..
+ */
+void pcibios_align_resource(void *data, struct resource *res,
+                           resource_size_t size, resource_size_t align)
+{
+#if 0
+       struct pci_dev *dev = data;
+
+       printk(KERN_DEBUG
+              "### PCIBIOS_ALIGN_RESOURCE(%s,,{%08lx-%08lx,%08lx},%lx)\n",
+              pci_name(dev),
+              res->start,
+              res->end,
+              res->flags,
+              size
+              );
+#endif
+
+       if (res->flags & IORESOURCE_IO) {
+               unsigned long start = res->start;
+
+               if (start & 0x300) {
+                       start = (start + 0x3ff) & ~0x3ff;
+                       res->start = start;
+               }
+       }
+}
+
+
+/*
+ *  Handle resources of PCI devices.  If the world were perfect, we could
+ *  just allocate all the resource regions and do nothing more.  It isn't.
+ *  On the other hand, we cannot just re-allocate all devices, as it would
+ *  require us to know lots of host bridge internals.  So we attempt to
+ *  keep as much of the original configuration as possible, but tweak it
+ *  when it's found to be wrong.
+ *
+ *  Known BIOS problems we have to work around:
+ *     - I/O or memory regions not configured
+ *     - regions configured, but not enabled in the command register
+ *     - bogus I/O addresses above 64K used
+ *     - expansion ROMs left enabled (this may sound harmless, but given
+ *       the fact the PCI specs explicitly allow address decoders to be
+ *       shared between expansion ROMs and other resource regions, it's
+ *       at least dangerous)
+ *
+ *  Our solution:
+ *     (1) Allocate resources for all buses behind PCI-to-PCI bridges.
+ *         This gives us fixed barriers on where we can allocate.
+ *     (2) Allocate resources for all enabled devices.  If there is
+ *         a collision, just mark the resource as unallocated. Also
+ *         disable expansion ROMs during this step.
+ *     (3) Try to allocate resources for disabled devices.  If the
+ *         resources were assigned correctly, everything goes well,
+ *         if they weren't, they won't disturb allocation of other
+ *         resources.
+ *     (4) Assign new addresses to resources which were either
+ *         not configured at all or misconfigured.  If explicitly
+ *         requested by the user, configure expansion ROM address
+ *         as well.
+ */
+static void __init pcibios_allocate_bus_resources(struct list_head *bus_list)
+{
+       struct pci_bus *bus;
+       struct pci_dev *dev;
+       int idx;
+       struct resource *r, *pr;
+
+       /* Depth-First Search on bus tree */
+       list_for_each_entry(bus, bus_list, node) {
+               dev = bus->self;
+               if (dev) {
+                       for (idx = PCI_BRIDGE_RESOURCES;
+                            idx < PCI_NUM_RESOURCES;
+                            idx++) {
+                               r = &dev->resource[idx];
+                               if (!r->flags)
+                                       continue;
+                               pr = pci_find_parent_resource(dev, r);
+                               if (!r->start ||
+                                   !pr ||
+                                   request_resource(pr, r) < 0) {
+                                       printk(KERN_ERR "PCI:"
+                                              " Cannot allocate resource"
+                                              " region %d of bridge %s\n",
+                                              idx, pci_name(dev));
+                                       /* Something is wrong with the region.
+                                        * Invalidate the resource to prevent
+                                        * child resource allocations in this
+                                        * range. */
+                                       r->flags = 0;
+                               }
+                       }
+               }
+               pcibios_allocate_bus_resources(&bus->children);
+       }
+}
+
+static void __init pcibios_allocate_resources(int pass)
+{
+       struct pci_dev *dev = NULL;
+       int idx, disabled;
+       u16 command;
+       struct resource *r, *pr;
+
+       for_each_pci_dev(dev) {
+               pci_read_config_word(dev, PCI_COMMAND, &command);
+               for (idx = 0; idx < 6; idx++) {
+                       r = &dev->resource[idx];
+                       if (r->parent)          /* Already allocated */
+                               continue;
+                       if (!r->start)          /* Address not assigned */
+                               continue;
+                       if (r->flags & IORESOURCE_IO)
+                               disabled = !(command & PCI_COMMAND_IO);
+                       else
+                               disabled = !(command & PCI_COMMAND_MEMORY);
+                       if (pass == disabled) {
+                               DBG("PCI[%s]: Resource %08lx-%08lx"
+                                   " (f=%lx, d=%d, p=%d)\n",
+                                   pci_name(dev), r->start, r->end, r->flags,
+                                   disabled, pass);
+                               pr = pci_find_parent_resource(dev, r);
+                               if (!pr || request_resource(pr, r) < 0) {
+                                       printk(KERN_ERR "PCI:"
+                                              " Cannot allocate resource"
+                                              " region %d of device %s\n",
+                                              idx, pci_name(dev));
+                                       /* We'll assign a new address later */
+                                       r->end -= r->start;
+                                       r->start = 0;
+                               }
+                       }
+               }
+               if (!pass) {
+                       r = &dev->resource[PCI_ROM_RESOURCE];
+                       if (r->flags & IORESOURCE_ROM_ENABLE) {
+                               /* Turn the ROM off, leave the resource region,
+                                * but keep it unregistered. */
+                               u32 reg;
+                               DBG("PCI: Switching off ROM of %s\n",
+                                   pci_name(dev));
+                               r->flags &= ~IORESOURCE_ROM_ENABLE;
+                               pci_read_config_dword(
+                                       dev, dev->rom_base_reg, &reg);
+                               pci_write_config_dword(
+                                       dev, dev->rom_base_reg,
+                                       reg & ~PCI_ROM_ADDRESS_ENABLE);
+                       }
+               }
+       }
+}
+
+static int __init pcibios_assign_resources(void)
+{
+       struct pci_dev *dev = NULL;
+       struct resource *r, *pr;
+
+       if (!(pci_probe & PCI_ASSIGN_ROMS)) {
+               /* Try to use BIOS settings for ROMs, otherwise let
+                  pci_assign_unassigned_resources() allocate the new
+                  addresses. */
+               for_each_pci_dev(dev) {
+                       r = &dev->resource[PCI_ROM_RESOURCE];
+                       if (!r->flags || !r->start)
+                               continue;
+                       pr = pci_find_parent_resource(dev, r);
+                       if (!pr || request_resource(pr, r) < 0) {
+                               r->end -= r->start;
+                               r->start = 0;
+                       }
+               }
+       }
+
+       pci_assign_unassigned_resources();
+
+       return 0;
+}
+
+fs_initcall(pcibios_assign_resources);
+
+void __init pcibios_resource_survey(void)
+{
+       DBG("PCI: Allocating resources\n");
+       pcibios_allocate_bus_resources(&pci_root_buses);
+       pcibios_allocate_resources(0);
+       pcibios_allocate_resources(1);
+}
+
+int pcibios_enable_resources(struct pci_dev *dev, int mask)
+{
+       u16 cmd, old_cmd;
+       int idx;
+       struct resource *r;
+
+       pci_read_config_word(dev, PCI_COMMAND, &cmd);
+       old_cmd = cmd;
+
+       for (idx = 0; idx < 6; idx++) {
+               /* Only set up the requested stuff */
+               if (!(mask & (1 << idx)))
+                       continue;
+
+               r = &dev->resource[idx];
+
+               if (!r->start && r->end) {
+                       printk(KERN_ERR
+                              "PCI: Device %s not available because of"
+                              " resource collisions\n",
+                              pci_name(dev));
+                       return -EINVAL;
+               }
+
+               if (r->flags & IORESOURCE_IO)
+                       cmd |= PCI_COMMAND_IO;
+               if (r->flags & IORESOURCE_MEM)
+                       cmd |= PCI_COMMAND_MEMORY;
+       }
+
+       if (dev->resource[PCI_ROM_RESOURCE].start)
+               cmd |= PCI_COMMAND_MEMORY;
+
+       if (cmd != old_cmd)
+               pci_write_config_word(dev, PCI_COMMAND, cmd);
+
+       return 0;
+}
+
+/*
+ *  If we set up a device for bus mastering, we need to check the latency
+ *  timer as certain crappy BIOSes forget to set it properly.
+ */
+unsigned int pcibios_max_latency = 255;
+
+void pcibios_set_master(struct pci_dev *dev)
+{
+       u8 lat;
+
+       pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
+
+       if (lat < 16)
+               lat = (64 <= pcibios_max_latency) ? 64 : pcibios_max_latency;
+       else if (lat > pcibios_max_latency)
+               lat = pcibios_max_latency;
+       else
+               return;
+
+       pci_write_config_byte(dev, PCI_LATENCY_TIMER, lat);
+}
+
+int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
+                       enum pci_mmap_state mmap_state, int write_combine)
+{
+       unsigned long prot;
+
+       /* Leave vm_pgoff as-is, the PCI space address is the physical
+        * address on this platform.
+        */
+       vma->vm_flags |= VM_LOCKED | VM_IO;
+
+       prot = pgprot_val(vma->vm_page_prot);
+       prot &= ~_PAGE_CACHE;
+       vma->vm_page_prot = __pgprot(prot);
+
+       /* Write-combine setting is ignored */
+       if (io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
+                              vma->vm_end - vma->vm_start,
+                              vma->vm_page_prot))
+               return -EAGAIN;
+
+       return 0;
+}
diff --git a/arch/mn10300/unit-asb2305/pci-asb2305.h b/arch/mn10300/unit-asb2305/pci-asb2305.h
new file mode 100644 (file)
index 0000000..84634fa
--- /dev/null
@@ -0,0 +1,82 @@
+/* ASB2305 Arch-specific PCI declarations
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ * Derived from: arch/i386/kernel/pci-i386.h: (c) 1999 Martin Mares <mj@ucw.cz>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _PCI_ASB2305_H
+#define _PCI_ASB2305_H
+
+#undef DEBUG
+
+#ifdef DEBUG
+#define DBG(x...) printk(x)
+#else
+#define DBG(x...)
+#endif
+
+#define PCI_PROBE_BIOS 1
+#define PCI_PROBE_CONF1 2
+#define PCI_PROBE_CONF2 4
+#define PCI_NO_SORT 0x100
+#define PCI_BIOS_SORT 0x200
+#define PCI_NO_CHECKS 0x400
+#define PCI_ASSIGN_ROMS 0x1000
+#define PCI_BIOS_IRQ_SCAN 0x2000
+
+extern unsigned int pci_probe;
+
+/* pci-asb2305.c */
+
+extern unsigned int pcibios_max_latency;
+
+extern void pcibios_resource_survey(void);
+extern int pcibios_enable_resources(struct pci_dev *dev, int mask);
+
+/* pci.c */
+
+extern int pcibios_last_bus;
+extern struct pci_bus *pci_root_bus;
+extern struct pci_ops *pci_root_ops;
+
+extern struct irq_routing_table *pcibios_get_irq_routing_table(void);
+extern int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
+
+/* pci-irq.c */
+
+struct irq_info {
+       u8 bus, devfn;                  /* Bus, device and function */
+       struct {
+               u8 link;                /* IRQ line ID, chipset dependent,
+                                        * 0=not routed */
+               u16 bitmap;             /* Available IRQs */
+       } __attribute__((packed)) irq[4];
+       u8 slot;                        /* Slot number, 0=onboard */
+       u8 rfu;
+} __attribute__((packed));
+
+struct irq_routing_table {
+       u32 signature;                  /* PIRQ_SIGNATURE should be here */
+       u16 version;                    /* PIRQ_VERSION */
+       u16 size;                       /* Table size in bytes */
+       u8 rtr_bus, rtr_devfn;          /* Where the interrupt router lies */
+       u16 exclusive_irqs;             /* IRQs devoted exclusively to PCI usage */
+       u16 rtr_vendor, rtr_device;     /* Vendor and device ID of interrupt router */
+       u32 miniport_data;              /* Crap */
+       u8 rfu[11];
+       u8 checksum;                    /* Modulo 256 checksum must give zero */
+       struct irq_info slots[0];
+} __attribute__((packed));
+
+extern unsigned int pcibios_irq_mask;
+
+extern void pcibios_irq_init(void);
+extern void pcibios_fixup_irqs(void);
+extern void pcibios_enable_irq(struct pci_dev *dev);
+
+#endif /* PCI_ASB2305_H */
diff --git a/arch/mn10300/unit-asb2305/pci-iomap.c b/arch/mn10300/unit-asb2305/pci-iomap.c
new file mode 100644 (file)
index 0000000..dbceae4
--- /dev/null
@@ -0,0 +1,31 @@
+/* ASB2305 PCI I/O mapping handler
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/pci.h>
+#include <linux/module.h>
+
+/*
+ * Create a virtual mapping cookie for a PCI BAR (memory or IO)
+ */
+void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
+{
+       unsigned long start = pci_resource_start(dev, bar);
+       unsigned long len = pci_resource_len(dev, bar);
+       unsigned long flags = pci_resource_flags(dev, bar);
+
+       if (!len || !start)
+               return NULL;
+
+       if ((flags & IORESOURCE_IO) || (flags & IORESOURCE_MEM))
+               return (void __iomem *) start;
+
+       return NULL;
+}
+EXPORT_SYMBOL(pci_iomap);
diff --git a/arch/mn10300/unit-asb2305/pci-irq.c b/arch/mn10300/unit-asb2305/pci-irq.c
new file mode 100644 (file)
index 0000000..58cfb44
--- /dev/null
@@ -0,0 +1,51 @@
+/* PCI IRQ routing on the MN103E010 based ASB2305
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ *
+ * This is simple: All PCI interrupts route through the CPU's XIRQ1 pin [IRQ 35]
+ */
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <asm/io.h>
+#include <asm/smp.h>
+#include "pci-asb2305.h"
+
+void __init pcibios_irq_init(void)
+{
+}
+
+void __init pcibios_fixup_irqs(void)
+{
+       struct pci_dev *dev = NULL;
+       u8 line, pin;
+
+       while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) {
+               pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
+               if (pin) {
+                       dev->irq = XIRQ1;
+                       pci_write_config_byte(dev, PCI_INTERRUPT_LINE,
+                                             dev->irq);
+               }
+               pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &line);
+       }
+}
+
+void __init pcibios_penalize_isa_irq(int irq)
+{
+}
+
+void pcibios_enable_irq(struct pci_dev *dev)
+{
+       pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
+}
diff --git a/arch/mn10300/unit-asb2305/pci.c b/arch/mn10300/unit-asb2305/pci.c
new file mode 100644 (file)
index 0000000..1a86425
--- /dev/null
@@ -0,0 +1,545 @@
+/* ASB2305 PCI support
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ * Derived from arch/i386/kernel/pci-pc.c
+ *     (c) 1999--2000 Martin Mares <mj@suse.cz>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/pci.h>
+#include <linux/init.h>
+#include <linux/ioport.h>
+#include <linux/delay.h>
+#include <asm/io.h>
+#include "pci-asb2305.h"
+
+unsigned int pci_probe = 1;
+
+int pcibios_last_bus = -1;
+struct pci_bus *pci_root_bus;
+struct pci_ops *pci_root_ops;
+
+/*
+ * Functions for accessing PCI configuration space
+ */
+
+#define CONFIG_CMD(bus, devfn, where) \
+       (0x80000000 | (bus->number << 16) | (devfn << 8) | (where & ~3))
+
+#define MEM_PAGING_REG (*(volatile __u32 *) 0xBFFFFFF4)
+#define CONFIG_ADDRESS (*(volatile __u32 *) 0xBFFFFFF8)
+#define CONFIG_DATAL(X)        (*(volatile __u32 *) 0xBFFFFFFC)
+#define CONFIG_DATAW(X)        (*(volatile __u16 *) (0xBFFFFFFC + ((X) & 2)))
+#define CONFIG_DATAB(X)        (*(volatile __u8  *) (0xBFFFFFFC + ((X) & 3)))
+
+#define BRIDGEREGB(X)  (*(volatile __u8  *) (0xBE040000 + (X)))
+#define BRIDGEREGW(X)  (*(volatile __u16 *) (0xBE040000 + (X)))
+#define BRIDGEREGL(X)  (*(volatile __u32 *) (0xBE040000 + (X)))
+
+static inline int __query(const struct pci_bus *bus, unsigned int devfn)
+{
+#if 0
+       return bus->number == 0 && (devfn == PCI_DEVFN(0, 0));
+       return bus->number == 1;
+       return bus->number == 0 &&
+               (devfn == PCI_DEVFN(2, 0) || devfn == PCI_DEVFN(3, 0));
+#endif
+       return 1;
+}
+
+/*
+ * translate Linuxcentric addresses to PCI bus addresses
+ */
+void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
+                            struct resource *res)
+{
+       if (res->flags & IORESOURCE_IO) {
+               region->start = (res->start & 0x00ffffff);
+               region->end   = (res->end   & 0x00ffffff);
+       }
+
+       if (res->flags & IORESOURCE_MEM) {
+               region->start = (res->start & 0x03ffffff) | MEM_PAGING_REG;
+               region->end   = (res->end   & 0x03ffffff) | MEM_PAGING_REG;
+       }
+
+#if 0
+       printk(KERN_DEBUG "RES->BUS: %lx-%lx => %lx-%lx\n",
+              res->start, res->end, region->start, region->end);
+#endif
+}
+EXPORT_SYMBOL(pcibios_resource_to_bus);
+
+/*
+ * translate PCI bus addresses to Linuxcentric addresses
+ */
+void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
+                            struct pci_bus_region *region)
+{
+       if (res->flags & IORESOURCE_IO) {
+               res->start = (region->start & 0x00ffffff) | 0xbe000000;
+               res->end   = (region->end   & 0x00ffffff) | 0xbe000000;
+       }
+
+       if (res->flags & IORESOURCE_MEM) {
+               res->start = (region->start & 0x03ffffff) | 0xb8000000;
+               res->end   = (region->end   & 0x03ffffff) | 0xb8000000;
+       }
+
+#if 0
+       printk(KERN_INFO "BUS->RES: %lx-%lx => %lx-%lx\n",
+              region->start, region->end, res->start, res->end);
+#endif
+}
+EXPORT_SYMBOL(pcibios_bus_to_resource);
+
+/*
+ *
+ */
+static int pci_ampci_read_config_byte(struct pci_bus *bus, unsigned int devfn,
+                                     int where, u32 *_value)
+{
+       u32 rawval, value;
+
+       if (bus->number == 0 && devfn == PCI_DEVFN(0, 0)) {
+               value = BRIDGEREGB(where);
+               __pcbdebug("=> %02hx", &BRIDGEREGL(where), value);
+       } else {
+               CONFIG_ADDRESS = CONFIG_CMD(bus, devfn, where);
+               rawval = CONFIG_ADDRESS;
+               value = CONFIG_DATAB(where);
+               if (__query(bus, devfn))
+                       __pcidebug("=> %02hx", bus, devfn, where, value);
+       }
+
+       *_value = value;
+       return PCIBIOS_SUCCESSFUL;
+}
+
+static int pci_ampci_read_config_word(struct pci_bus *bus, unsigned int devfn,
+                                     int where, u32 *_value)
+{
+       u32 rawval, value;
+
+       if (bus->number == 0 && devfn == PCI_DEVFN(0, 0)) {
+               value = BRIDGEREGW(where);
+               __pcbdebug("=> %04hx", &BRIDGEREGL(where), value);
+       } else {
+               CONFIG_ADDRESS = CONFIG_CMD(bus, devfn, where);
+               rawval = CONFIG_ADDRESS;
+               value = CONFIG_DATAW(where);
+               if (__query(bus, devfn))
+                       __pcidebug("=> %04hx", bus, devfn, where, value);
+       }
+
+       *_value = value;
+       return PCIBIOS_SUCCESSFUL;
+}
+
+static int pci_ampci_read_config_dword(struct pci_bus *bus, unsigned int devfn,
+                                      int where, u32 *_value)
+{
+       u32 rawval, value;
+
+       if (bus->number == 0 && devfn == PCI_DEVFN(0, 0)) {
+               value = BRIDGEREGL(where);
+               __pcbdebug("=> %08x", &BRIDGEREGL(where), value);
+       } else {
+               CONFIG_ADDRESS = CONFIG_CMD(bus, devfn, where);
+               rawval = CONFIG_ADDRESS;
+               value = CONFIG_DATAL(where);
+               if (__query(bus, devfn))
+                       __pcidebug("=> %08x", bus, devfn, where, value);
+       }
+
+       *_value = value;
+       return PCIBIOS_SUCCESSFUL;
+}
+
+static int pci_ampci_write_config_byte(struct pci_bus *bus, unsigned int devfn,
+                                      int where, u8 value)
+{
+       u32 rawval;
+
+       if (bus->number == 0 && devfn == PCI_DEVFN(0, 0)) {
+               __pcbdebug("<= %02x", &BRIDGEREGB(where), value);
+               BRIDGEREGB(where) = value;
+       } else {
+               if (bus->number == 0 &&
+                   (devfn == PCI_DEVFN(2, 0) && devfn == PCI_DEVFN(3, 0))
+                   )
+                       __pcidebug("<= %02x", bus, devfn, where, value);
+               CONFIG_ADDRESS = CONFIG_CMD(bus, devfn, where);
+               rawval = CONFIG_ADDRESS;
+               CONFIG_DATAB(where) = value;
+       }
+       return PCIBIOS_SUCCESSFUL;
+}
+
+static int pci_ampci_write_config_word(struct pci_bus *bus, unsigned int devfn,
+                                      int where, u16 value)
+{
+       u32 rawval;
+
+       if (bus->number == 0 && devfn == PCI_DEVFN(0, 0)) {
+               __pcbdebug("<= %04hx", &BRIDGEREGW(where), value);
+               BRIDGEREGW(where) = value;
+       } else {
+               if (__query(bus, devfn))
+                       __pcidebug("<= %04hx", bus, devfn, where, value);
+               CONFIG_ADDRESS = CONFIG_CMD(bus, devfn, where);
+               rawval = CONFIG_ADDRESS;
+               CONFIG_DATAW(where) = value;
+       }
+       return PCIBIOS_SUCCESSFUL;
+}
+
+static int pci_ampci_write_config_dword(struct pci_bus *bus, unsigned int devfn,
+                                       int where, u32 value)
+{
+       u32 rawval;
+
+       if (bus->number == 0 && devfn == PCI_DEVFN(0, 0)) {
+               __pcbdebug("<= %08x", &BRIDGEREGL(where), value);
+               BRIDGEREGL(where) = value;
+       } else {
+               if (__query(bus, devfn))
+                       __pcidebug("<= %08x", bus, devfn, where, value);
+               CONFIG_ADDRESS = CONFIG_CMD(bus, devfn, where);
+               rawval = CONFIG_ADDRESS;
+               CONFIG_DATAL(where) = value;
+       }
+       return PCIBIOS_SUCCESSFUL;
+}
+
+static int pci_ampci_read_config(struct pci_bus *bus, unsigned int devfn,
+                                int where, int size, u32 *val)
+{
+       switch (size) {
+       case 1:
+               return pci_ampci_read_config_byte(bus, devfn, where, val);
+       case 2:
+               return pci_ampci_read_config_word(bus, devfn, where, val);
+       case 4:
+               return pci_ampci_read_config_dword(bus, devfn, where, val);
+       default:
+               BUG();
+               return -EOPNOTSUPP;
+       }
+}
+
+static int pci_ampci_write_config(struct pci_bus *bus, unsigned int devfn,
+                                 int where, int size, u32 val)
+{
+       switch (size) {
+       case 1:
+               return pci_ampci_write_config_byte(bus, devfn, where, val);
+       case 2:
+               return pci_ampci_write_config_word(bus, devfn, where, val);
+       case 4:
+               return pci_ampci_write_config_dword(bus, devfn, where, val);
+       default:
+               BUG();
+               return -EOPNOTSUPP;
+       }
+}
+
+static struct pci_ops pci_direct_ampci = {
+       pci_ampci_read_config,
+       pci_ampci_write_config,
+};
+
+/*
+ * Before we decide to use direct hardware access mechanisms, we try to do some
+ * trivial checks to ensure it at least _seems_ to be working -- we just test
+ * whether bus 00 contains a host bridge (this is similar to checking
+ * techniques used in XFree86, but ours should be more reliable since we
+ * attempt to make use of direct access hints provided by the PCI BIOS).
+ *
+ * This should be close to trivial, but it isn't, because there are buggy
+ * chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
+ */
+static int __init pci_sanity_check(struct pci_ops *o)
+{
+       struct pci_bus bus;             /* Fake bus and device */
+       u32 x;
+
+       bus.number = 0;
+
+       if ((!o->read(&bus, 0, PCI_CLASS_DEVICE, 2, &x) &&
+            (x == PCI_CLASS_BRIDGE_HOST || x == PCI_CLASS_DISPLAY_VGA)) ||
+           (!o->read(&bus, 0, PCI_VENDOR_ID, 2, &x) &&
+            (x == PCI_VENDOR_ID_INTEL || x == PCI_VENDOR_ID_COMPAQ)))
+               return 1;
+
+       printk(KERN_ERROR "PCI: Sanity check failed\n");
+       return 0;
+}
+
+static int __init pci_check_direct(void)
+{
+       unsigned long flags;
+
+       local_irq_save(flags);
+
+       /*
+        * Check if access works.
+        */
+       if (pci_sanity_check(&pci_direct_ampci)) {
+               local_irq_restore(flags);
+               printk(KERN_INFO "PCI: Using configuration ampci\n");
+               request_mem_region(0xBE040000, 256, "AMPCI bridge");
+               request_mem_region(0xBFFFFFF4, 12, "PCI ampci");
+               return 0;
+       }
+
+       local_irq_restore(flags);
+       return -ENODEV;
+}
+
+static int __devinit is_valid_resource(struct pci_dev *dev, int idx)
+{
+       unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM;
+       struct resource *devr = &dev->resource[idx];
+
+       if (dev->bus) {
+               for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
+                       struct resource *busr = dev->bus->resource[i];
+
+                       if (!busr || (busr->flags ^ devr->flags) & type_mask)
+                               continue;
+
+                       if (devr->start &&
+                           devr->start >= busr->start &&
+                           devr->end <= busr->end)
+                               return 1;
+               }
+       }
+
+       return 0;
+}
+
+static void __devinit pcibios_fixup_device_resources(struct pci_dev *dev)
+{
+       struct pci_bus_region region;
+       int i;
+       int limit;
+
+       if (dev->bus->number != 0)
+               return;
+
+       limit = (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) ?
+               PCI_BRIDGE_RESOURCES : PCI_NUM_RESOURCES;
+
+       for (i = 0; i < limit; i++) {
+               if (!dev->resource[i].flags)
+                       continue;
+
+               region.start = dev->resource[i].start;
+               region.end = dev->resource[i].end;
+               pcibios_bus_to_resource(dev, &dev->resource[i], &region);
+               if (is_valid_resource(dev, i))
+                       pci_claim_resource(dev, i);
+       }
+}
+
+/*
+ *  Called after each bus is probed, but before its children
+ *  are examined.
+ */
+void __devinit pcibios_fixup_bus(struct pci_bus *bus)
+{
+       struct pci_dev *dev;
+
+       if (bus->self) {
+               pci_read_bridge_bases(bus);
+               pcibios_fixup_device_resources(bus->self);
+       }
+
+       list_for_each_entry(dev, &bus->devices, bus_list)
+               pcibios_fixup_device_resources(dev);
+}
+
+/*
+ * Initialization. Try all known PCI access methods. Note that we support
+ * using both PCI BIOS and direct access: in such cases, we use I/O ports
+ * to access config space, but we still keep BIOS order of cards to be
+ * compatible with 2.0.X. This should go away some day.
+ */
+static int __init pcibios_init(void)
+{
+       ioport_resource.start   = 0xA0000000;
+       ioport_resource.end     = 0xDFFFFFFF;
+       iomem_resource.start    = 0xA0000000;
+       iomem_resource.end      = 0xDFFFFFFF;
+
+       if (!pci_probe)
+               return 0;
+
+       if (pci_check_direct() < 0) {
+               printk(KERN_WARNING "PCI: No PCI bus detected\n");
+               return 0;
+       }
+
+       printk(KERN_INFO "PCI: Probing PCI hardware [mempage %08x]\n",
+              MEM_PAGING_REG);
+
+       {
+#if 0
+               static struct pci_bus am33_root_bus = {
+                       .children  = LIST_HEAD_INIT(am33_root_bus.children),
+                       .devices   = LIST_HEAD_INIT(am33_root_bus.devices),
+                       .number    = 0,
+                       .secondary = 0,
+                       .resource = { &ioport_resource, &iomem_resource },
+               };
+
+               am33_root_bus.ops = pci_root_ops;
+               list_add_tail(&am33_root_bus.node, &pci_root_buses);
+
+               am33_root_bus.subordinate = pci_do_scan_bus(0);
+
+               pci_root_bus = &am33_root_bus;
+#else
+               pci_root_bus = pci_scan_bus(0, &pci_direct_ampci, NULL);
+#endif
+       }
+
+       pcibios_irq_init();
+       pcibios_fixup_irqs();
+#if 0
+       pcibios_resource_survey();
+#endif
+       return 0;
+}
+
+arch_initcall(pcibios_init);
+
+char *__init pcibios_setup(char *str)
+{
+       if (!strcmp(str, "off")) {
+               pci_probe = 0;
+               return NULL;
+
+       } else if (!strncmp(str, "lastbus=", 8)) {
+               pcibios_last_bus = simple_strtol(str+8, NULL, 0);
+               return NULL;
+       }
+
+       return str;
+}
+
+int pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+       int err;
+
+       err = pcibios_enable_resources(dev, mask);
+       if (err == 0)
+               pcibios_enable_irq(dev);
+       return err;
+}
+
+/*
+ * disable the ethernet chipset
+ */
+static void __init unit_disable_pcnet(struct pci_bus *bus, struct pci_ops *o)
+{
+       u32 x;
+
+       bus->number = 0;
+
+       o->read (bus, PCI_DEVFN(2, 0), PCI_COMMAND,             2, &x);
+       x |= PCI_COMMAND_MASTER |
+               PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
+               PCI_COMMAND_SERR | PCI_COMMAND_PARITY;
+       o->write(bus, PCI_DEVFN(2, 0), PCI_COMMAND,             2, x);
+       o->read (bus, PCI_DEVFN(2, 0), PCI_COMMAND,             2, &x);
+       o->write(bus, PCI_DEVFN(2, 0), PCI_BASE_ADDRESS_0,      4, 0x00030001);
+       o->read (bus, PCI_DEVFN(2, 0), PCI_BASE_ADDRESS_0,      4, &x);
+
+#define RDP (*(volatile u32 *) 0xBE030010)
+#define RAP (*(volatile u32 *) 0xBE030014)
+#define __set_RAP(X) do { RAP = (X); x = RAP; } while (0)
+#define __set_RDP(X) do { RDP = (X); x = RDP; } while (0)
+#define __get_RDP() ({ RDP & 0xffff; })
+
+       __set_RAP(0);
+       __set_RDP(0x0004);      /* CSR0 = STOP */
+
+       __set_RAP(88);          /* check CSR88 indicates an Am79C973 */
+       BUG_ON(__get_RDP() != 0x5003);
+
+       for (x = 0; x < 100; x++)
+               asm volatile("nop");
+
+       __set_RDP(0x0004);      /* CSR0 = STOP */
+}
+
+/*
+ * initialise the unit hardware
+ */
+asmlinkage void __init unit_pci_init(void)
+{
+       struct pci_bus bus;             /* Fake bus and device */
+       struct pci_ops *o = &pci_direct_ampci;
+       u32 x;
+
+       set_intr_level(XIRQ1, GxICR_LEVEL_3);
+
+       memset(&bus, 0, sizeof(bus));
+
+       MEM_PAGING_REG = 0xE8000000;
+
+       /* we need to set up the bridge _now_ or we won't be able to access the
+        * PCI config registers
+        */
+       BRIDGEREGW(PCI_COMMAND) |=
+               PCI_COMMAND_SERR | PCI_COMMAND_PARITY |
+               PCI_COMMAND_MEMORY | PCI_COMMAND_IO | PCI_COMMAND_MASTER;
+       BRIDGEREGW(PCI_STATUS)          = 0xF800;
+       BRIDGEREGB(PCI_LATENCY_TIMER)   = 0x10;
+       BRIDGEREGL(PCI_BASE_ADDRESS_0)  = 0x80000000;
+       BRIDGEREGB(PCI_INTERRUPT_LINE)  = 1;
+       BRIDGEREGL(0x48)                = 0x98000000;   /* AMPCI base addr */
+       BRIDGEREGB(0x41)                = 0x00;         /* secondary bus
+                                                        * number */
+       BRIDGEREGB(0x42)                = 0x01;         /* subordinate bus
+                                                        * number */
+       BRIDGEREGB(0x44)                = 0x01;
+       BRIDGEREGL(0x50)                = 0x00000001;
+       BRIDGEREGL(0x58)                = 0x00001002;
+       BRIDGEREGL(0x5C)                = 0x00000011;
+
+       /* we also need to set up the PCI-PCI bridge */
+       bus.number = 0;
+
+       /* IO: 0x00000000-0x00020000 */
+       o->read (&bus, PCI_DEVFN(3, 0), PCI_COMMAND,            2, &x);
+       x |= PCI_COMMAND_MASTER |
+               PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
+               PCI_COMMAND_SERR | PCI_COMMAND_PARITY;
+       o->write(&bus, PCI_DEVFN(3, 0), PCI_COMMAND,            2, x);
+
+       o->read (&bus, PCI_DEVFN(3, 0), PCI_IO_BASE,            1, &x);
+       o->read (&bus, PCI_DEVFN(3, 0), PCI_IO_BASE_UPPER16,    4, &x);
+       o->read (&bus, PCI_DEVFN(3, 0), PCI_MEMORY_BASE,        4, &x);
+       o->read (&bus, PCI_DEVFN(3, 0), PCI_PREF_MEMORY_BASE,   4, &x);
+
+       o->write(&bus, PCI_DEVFN(3, 0), PCI_IO_BASE,            1, 0x01);
+       o->read (&bus, PCI_DEVFN(3, 0), PCI_IO_BASE,            1, &x);
+       o->write(&bus, PCI_DEVFN(3, 0), PCI_IO_BASE_UPPER16,    4, 0x00020000);
+       o->read (&bus, PCI_DEVFN(3, 0), PCI_IO_BASE_UPPER16,    4, &x);
+       o->write(&bus, PCI_DEVFN(3, 0), PCI_MEMORY_BASE,        4, 0xEBB0EA00);
+       o->read (&bus, PCI_DEVFN(3, 0), PCI_MEMORY_BASE,        4, &x);
+       o->write(&bus, PCI_DEVFN(3, 0), PCI_PREF_MEMORY_BASE,   4, 0xE9F0E800);
+       o->read (&bus, PCI_DEVFN(3, 0), PCI_PREF_MEMORY_BASE,   4, &x);
+
+       unit_disable_pcnet(&bus, o);
+}
diff --git a/arch/mn10300/unit-asb2305/unit-init.c b/arch/mn10300/unit-asb2305/unit-init.c
new file mode 100644 (file)
index 0000000..6a35241
--- /dev/null
@@ -0,0 +1,61 @@
+/* ASB2305 Initialisation
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#include <linux/kernel.h>
+#include <linux/param.h>
+#include <linux/init.h>
+#include <linux/pci.h>
+#include <asm/io.h>
+#include <asm/setup.h>
+#include <asm/processor.h>
+#include <asm/cpu/intctl-regs.h>
+#include <asm/cpu/rtc-regs.h>
+#include <asm/cpu/serial-regs.h>
+#include <asm/unit/serial.h>
+
+/*
+ * initialise some of the unit hardware before gdbstub is set up
+ */
+asmlinkage void __init unit_init(void)
+{
+#ifndef CONFIG_GDBSTUB_ON_TTYSx
+       /* set the 16550 interrupt line to level 3 if not being used for GDB */
+       set_intr_level(XIRQ0, GxICR_LEVEL_3);
+#endif
+}
+
+/*
+ * initialise the rest of the unit hardware after gdbstub is ready
+ */
+void __init unit_setup(void)
+{
+#ifdef CONFIG_PCI
+       unit_pci_init();
+#endif
+}
+
+/*
+ * initialise the external interrupts used by a unit of this type
+ */
+void __init unit_init_IRQ(void)
+{
+       unsigned int extnum;
+
+       for (extnum = 0; extnum < NR_XIRQS; extnum++) {
+               switch (GET_XIRQ_TRIGGER(extnum)) {
+               case XIRQ_TRIGGER_HILEVEL:
+               case XIRQ_TRIGGER_LOWLEVEL:
+                       set_irq_handler(XIRQ2IRQ(extnum), handle_level_irq);
+                       break;
+               default:
+                       break;
+               }
+       }
+}
index 028d8a0fdbfd2b3213c183a5f6a371211fe55833..d929ac84f25a1fcd5a636249d24c5921508d483d 100644 (file)
@@ -75,6 +75,9 @@ config IRQ_PER_CPU
        bool
        default y
 
+config ARCH_SUPPORTS_AOUT
+       def_bool y
+
 # unless you want to implement ACPI on PA-RISC ... ;-)
 config PM
        bool
index c44b8c51f5d1ef82f542f8f35e56d7fb2d9ec7a3..39e7c5a5946a8981deee1afa1296efc7cff9eadc 100644 (file)
@@ -190,7 +190,7 @@ c_stop (struct seq_file *m, void *v)
 {
 }
 
-struct seq_operations cpuinfo_op = {
+const struct seq_operations cpuinfo_op = {
        .start  = c_start,
        .next   = c_next,
        .stop   = c_stop,
index e6e49289f7882dd11494d9208168e253f806de21..4b749c41646441b70b0216beddfeab7409a661ce 100644 (file)
@@ -313,7 +313,7 @@ int main(void)
        DEFINE(CLOCK_REALTIME, CLOCK_REALTIME);
        DEFINE(CLOCK_MONOTONIC, CLOCK_MONOTONIC);
        DEFINE(NSEC_PER_SEC, NSEC_PER_SEC);
-       DEFINE(CLOCK_REALTIME_RES, (KTIME_MONOTONIC_RES).tv64);
+       DEFINE(CLOCK_REALTIME_RES, MONOTONIC_RES_NSEC);
 
 #ifdef CONFIG_BUG
        DEFINE(BUG_ENTRY_SIZE, sizeof(struct bug_entry));
index f80f90c4d58be2b277dd6bb6d602b43678b6dbad..ac3390f81900c64192c70a14e1a10258201c7090 100644 (file)
@@ -107,19 +107,20 @@ __init_refok pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long add
        return pte;
 }
 
-struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
+pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
 {
        struct page *ptepage;
 
 #ifdef CONFIG_HIGHPTE
-       gfp_t flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_REPEAT;
+       gfp_t flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_REPEAT | __GFP_ZERO;
 #else
-       gfp_t flags = GFP_KERNEL | __GFP_REPEAT;
+       gfp_t flags = GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO;
 #endif
 
        ptepage = alloc_pages(flags, 0);
-       if (ptepage)
-               clear_highpage(ptepage);
+       if (!ptepage)
+               return NULL;
+       pgtable_page_ctor(ptepage);
        return ptepage;
 }
 
@@ -131,11 +132,12 @@ void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        free_page((unsigned long)pte);
 }
 
-void pte_free(struct mm_struct *mm, struct page *ptepage)
+void pte_free(struct mm_struct *mm, pgtable_t ptepage)
 {
 #ifdef CONFIG_SMP
        hash_page_sync();
 #endif
+       pgtable_page_dtor(ptepage);
        __free_page(ptepage);
 }
 
index 1018acd1746b76f7ac99ef91b62092d4d45529d6..e393144d533dcf06f988fe841c8a8b527569973a 100644 (file)
@@ -460,7 +460,7 @@ static int spufs_cntl_open(struct inode *inode, struct file *file)
        if (!i->i_openers++)
                ctx->cntl = inode->i_mapping;
        mutex_unlock(&ctx->mapping_lock);
-       return spufs_attr_open(inode, file, spufs_cntl_get,
+       return simple_attr_open(inode, file, spufs_cntl_get,
                                        spufs_cntl_set, "0x%08lx");
 }
 
@@ -470,7 +470,7 @@ spufs_cntl_release(struct inode *inode, struct file *file)
        struct spufs_inode_info *i = SPUFS_I(inode);
        struct spu_context *ctx = i->i_ctx;
 
-       spufs_attr_release(inode, file);
+       simple_attr_release(inode, file);
 
        mutex_lock(&ctx->mapping_lock);
        if (!--i->i_openers)
@@ -482,8 +482,8 @@ spufs_cntl_release(struct inode *inode, struct file *file)
 static const struct file_operations spufs_cntl_fops = {
        .open = spufs_cntl_open,
        .release = spufs_cntl_release,
-       .read = spufs_attr_read,
-       .write = spufs_attr_write,
+       .read = simple_attr_read,
+       .write = simple_attr_write,
        .mmap = spufs_cntl_mmap,
 };
 
index 90784c029f25096ae46963e6fc035c9eaad6c1d5..e6e6559c55ed5be7abfde887bb90cec1ce1501bd 100644 (file)
@@ -755,8 +755,11 @@ spufs_fill_super(struct super_block *sb, void *data, int silent)
                .statfs = simple_statfs,
                .delete_inode = spufs_delete_inode,
                .drop_inode = generic_delete_inode,
+               .show_options = generic_show_options,
        };
 
+       save_mount_options(sb, data);
+
        sb->s_maxbytes = MAX_LFS_FILESIZE;
        sb->s_blocksize = PAGE_CACHE_SIZE;
        sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
index d51368d72e390c6faaf40956b82f208b12be2c74..294055902f0c16b73a3635e0bbb44fdc2749d1ab 100644 (file)
@@ -275,7 +275,7 @@ static void c_stop(struct seq_file *m, void *v)
 {
 }
 
-struct seq_operations cpuinfo_op = {
+const struct seq_operations cpuinfo_op = {
        .start =c_start,
        .next = c_next,
        .stop = c_stop,
index 409fcaa4994a598736ec082218dacde0709f2d9a..03a79bff1271fee749e842d56ca21df176e2674d 100644 (file)
@@ -95,7 +95,7 @@ __init_refok pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long add
        return pte;
 }
 
-struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
+pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
 {
        struct page *ptepage;
 
@@ -106,8 +106,10 @@ struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
 #endif
 
        ptepage = alloc_pages(flags, 0);
-       if (ptepage)
+       if (ptepage) {
                clear_highpage(ptepage);
+               pgtable_page_ctor(ptepage);
+       }
        return ptepage;
 }
 
@@ -119,11 +121,12 @@ void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        free_page((unsigned long)pte);
 }
 
-void pte_free(struct mm_struct *mm, struct page *ptepage)
+void pte_free(struct mm_struct *mm, pgtable_t ptepage)
 {
 #ifdef CONFIG_SMP
        hash_page_sync();
 #endif
+       pgtable_page_dtor(ptepage);
        __free_page(ptepage);
 }
 
index 1a2fdb6991df0e6905c8640c71025d8ca54c1bf6..a4d29025ddbd9b178197495d955877486b0101f3 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/smp.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
+#include <linux/seq_file.h>
 #include <linux/delay.h>
 #include <linux/module.h>
 #include <linux/kdebug.h>
@@ -218,41 +219,40 @@ void show_registers(struct pt_regs *regs)
 }      
 
 /* This is called from fs/proc/array.c */
-char *task_show_regs(struct task_struct *task, char *buffer)
+void task_show_regs(struct seq_file *m, struct task_struct *task)
 {
        struct pt_regs *regs;
 
        regs = task_pt_regs(task);
-       buffer += sprintf(buffer, "task: %p, ksp: %p\n",
+       seq_printf(m, "task: %p, ksp: %p\n",
                       task, (void *)task->thread.ksp);
-       buffer += sprintf(buffer, "User PSW : %p %p\n",
+       seq_printf(m, "User PSW : %p %p\n",
                       (void *) regs->psw.mask, (void *)regs->psw.addr);
 
-       buffer += sprintf(buffer, "User GPRS: " FOURLONG,
+       seq_printf(m, "User GPRS: " FOURLONG,
                          regs->gprs[0], regs->gprs[1],
                          regs->gprs[2], regs->gprs[3]);
-       buffer += sprintf(buffer, "           " FOURLONG,
+       seq_printf(m, "           " FOURLONG,
                          regs->gprs[4], regs->gprs[5],
                          regs->gprs[6], regs->gprs[7]);
-       buffer += sprintf(buffer, "           " FOURLONG,
+       seq_printf(m, "           " FOURLONG,
                          regs->gprs[8], regs->gprs[9],
                          regs->gprs[10], regs->gprs[11]);
-       buffer += sprintf(buffer, "           " FOURLONG,
+       seq_printf(m, "           " FOURLONG,
                          regs->gprs[12], regs->gprs[13],
                          regs->gprs[14], regs->gprs[15]);
-       buffer += sprintf(buffer, "User ACRS: %08x %08x %08x %08x\n",
+       seq_printf(m, "User ACRS: %08x %08x %08x %08x\n",
                          task->thread.acrs[0], task->thread.acrs[1],
                          task->thread.acrs[2], task->thread.acrs[3]);
-       buffer += sprintf(buffer, "           %08x %08x %08x %08x\n",
+       seq_printf(m, "           %08x %08x %08x %08x\n",
                          task->thread.acrs[4], task->thread.acrs[5],
                          task->thread.acrs[6], task->thread.acrs[7]);
-       buffer += sprintf(buffer, "           %08x %08x %08x %08x\n",
+       seq_printf(m, "           %08x %08x %08x %08x\n",
                          task->thread.acrs[8], task->thread.acrs[9],
                          task->thread.acrs[10], task->thread.acrs[11]);
-       buffer += sprintf(buffer, "           %08x %08x %08x %08x\n",
+       seq_printf(m, "           %08x %08x %08x %08x\n",
                          task->thread.acrs[12], task->thread.acrs[13],
                          task->thread.acrs[14], task->thread.acrs[15]);
-       return buffer;
 }
 
 static DEFINE_SPINLOCK(die_lock);
index e60e0ae134025f4ef0b4bcbab65c48ca32cb6f60..019f518cd5a0c014c2e12db2e96274c5f65066d2 100644 (file)
@@ -78,6 +78,7 @@ unsigned long *page_table_alloc(int noexec)
                clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE);
                page->index = (addr_t) table;
        }
+       pgtable_page_ctor(page);
        table = (unsigned long *) page_to_phys(page);
        clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE);
        return table;
@@ -87,6 +88,7 @@ void page_table_free(unsigned long *table)
 {
        unsigned long *shadow = get_shadow_pte(table);
 
+       pgtable_page_dtor(virt_to_page(table));
        if (shadow)
                free_page((unsigned long) shadow);
        free_page((unsigned long) table);
index 1c3a90835c7e00caf0cb6960c4da7a75f603ea51..6e035d1cf7895663f5c51eed1b4167f16dd1d759 100644 (file)
@@ -89,6 +89,9 @@ config ARCH_HAS_ILOG2_U64
 config ARCH_NO_VIRT_TO_BUS
        def_bool y
 
+config ARCH_SUPPORTS_AOUT
+       def_bool y
+
 source "init/Kconfig"
 
 menu "System type"
index 3008c00eea6b6c269e7fa6bde3e2e43ca4d0f4b8..8250e017bd4eaac43989cfa037be64b4c59688fe 100644 (file)
@@ -263,7 +263,7 @@ struct sq_sysfs_attr {
        ssize_t (*store)(const char *buf, size_t count);
 };
 
-#define to_sq_sysfs_attr(attr) container_of(attr, struct sq_sysfs_attr, attr)
+#define to_sq_sysfs_attr(a)    container_of(a, struct sq_sysfs_attr, attr)
 
 static ssize_t sq_sysfs_show(struct kobject *kobj, struct attribute *attr,
                             char *buf)
index 99f8971716d2226a53a27c3e5c19e99c32b6f135..7c674a3503b66c8aa2ced1896bc3df6e2a6e7999 100644 (file)
@@ -27,6 +27,13 @@ config ARCH_NO_VIRT_TO_BUS
 config OF
        def_bool y
 
+config ARCH_SUPPORTS_AOUT
+       def_bool y
+
+config HZ
+       int
+       default 100
+
 source "init/Kconfig"
 
 menu "General machine setup"
index 77460e316a039ee5cda15d06ebc61bb33e0b3712..19186ce8850d15768e8b322a8d3b5a2d79e1728b 100644 (file)
@@ -20,7 +20,6 @@
 #include <linux/ptrace.h>
 #include <linux/slab.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/smp.h>
 #include <linux/reboot.h>
 #include <linux/delay.h>
@@ -566,38 +565,6 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
        return 0;
 }
 
-/*
- * fill in the user structure for a core dump..
- */
-void dump_thread(struct pt_regs * regs, struct user * dump)
-{
-       unsigned long first_stack_page;
-
-       dump->magic = SUNOS_CORE_MAGIC;
-       dump->len = sizeof(struct user);
-       dump->regs.psr = regs->psr;
-       dump->regs.pc = regs->pc;
-       dump->regs.npc = regs->npc;
-       dump->regs.y = regs->y;
-       /* fuck me plenty */
-       memcpy(&dump->regs.regs[0], &regs->u_regs[1], (sizeof(unsigned long) * 15));
-       dump->uexec = current->thread.core_exec;
-       dump->u_tsize = (((unsigned long) current->mm->end_code) -
-               ((unsigned long) current->mm->start_code)) & ~(PAGE_SIZE - 1);
-       dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1)));
-       dump->u_dsize -= dump->u_tsize;
-       dump->u_dsize &= ~(PAGE_SIZE - 1);
-       first_stack_page = (regs->u_regs[UREG_FP] & ~(PAGE_SIZE - 1));
-       dump->u_ssize = (TASK_SIZE - first_stack_page) & ~(PAGE_SIZE - 1);
-       memcpy(&dump->fpu.fpstatus.fregs.regs[0], &current->thread.float_regs[0], (sizeof(unsigned long) * 32));
-       dump->fpu.fpstatus.fsr = current->thread.fsr;
-       dump->fpu.fpstatus.flags = dump->fpu.fpstatus.extra = 0;
-       dump->fpu.fpstatus.fpq_count = current->thread.fpqdepth;
-       memcpy(&dump->fpu.fpstatus.fpq[0], &current->thread.fpqueue[0],
-              ((sizeof(unsigned long) * 2) * 16));
-       dump->sigcode = 0;
-}
-
 /*
  * fill in the fpu structure for a core dump.
  */
index d07bc74773aa4c2bfa063a8090a0b0efe95dda52..3cf78f160846bf68432f762285fab8a7644e8e3c 100644 (file)
@@ -16,7 +16,6 @@
 #include <linux/initrd.h>
 #include <asm/smp.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/screen_info.h>
 #include <linux/delay.h>
 #include <linux/fs.h>
index ef647acc479e4cdc00cf5f3009667454ed47a0fc..c1025e5516507c5246f48f5b0c67144cc07161fd 100644 (file)
@@ -51,7 +51,6 @@
 #ifdef CONFIG_PCI
 #include <asm/ebus.h>
 #endif
-#include <asm/a.out.h>
 #include <asm/io-unit.h>
 #include <asm/bug.h>
 
@@ -214,8 +213,6 @@ EXPORT_SYMBOL(kunmap_atomic);
 EXPORT_SYMBOL(svr4_setcontext);
 EXPORT_SYMBOL(svr4_getcontext);
 
-EXPORT_SYMBOL(dump_thread);
-
 /* prom symbols */
 EXPORT_SYMBOL(idprom);
 EXPORT_SYMBOL(prom_root_node);
index 36b4d24988f8f64c75cbfdca09b7b9ca499cd730..2d9cd65160a4297321289bec9df441715c28a8cc 100644 (file)
@@ -14,7 +14,6 @@
 #include <asm/system.h>
 #include <asm/page.h>
 #include <asm/pgtable.h>
-#include <asm/a.out.h>
 #include <asm/mmu_context.h>
 #include <asm/oplib.h>
 
index 17b485f2825c94345432e4fecb88b9903d4e94e7..23d3291a3e81e65736c862e03e3b24e3047ffa22 100644 (file)
@@ -34,7 +34,6 @@
 #include <asm/sbus.h>
 #include <asm/asi.h>
 #include <asm/msi.h>
-#include <asm/a.out.h>
 #include <asm/mmu_context.h>
 #include <asm/io-unit.h>
 #include <asm/cacheflush.h>
@@ -490,14 +489,17 @@ srmmu_pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
        return (pte_t *)srmmu_get_nocache(PTE_SIZE, PTE_SIZE);
 }
 
-static struct page *
+static pgtable_t
 srmmu_pte_alloc_one(struct mm_struct *mm, unsigned long address)
 {
        unsigned long pte;
+       struct page *page;
 
        if ((pte = (unsigned long)srmmu_pte_alloc_one_kernel(mm, address)) == 0)
                return NULL;
-       return pfn_to_page( __nocache_pa(pte) >> PAGE_SHIFT );
+       page = pfn_to_page( __nocache_pa(pte) >> PAGE_SHIFT );
+       pgtable_page_ctor(page);
+       return page;
 }
 
 static void srmmu_free_pte_fast(pte_t *pte)
@@ -505,10 +507,11 @@ static void srmmu_free_pte_fast(pte_t *pte)
        srmmu_free_nocache((unsigned long)pte, PTE_SIZE);
 }
 
-static void srmmu_pte_free(struct page *pte)
+static void srmmu_pte_free(pgtable_t pte)
 {
        unsigned long p;
 
+       pgtable_page_dtor(pte);
        p = (unsigned long)page_address(pte);   /* Cached address (for test) */
        if (p == 0)
                BUG();
index 0729305f2f594a83ff6259ec1e5e223ba51ab30c..c0442e8c4b1548a784037d1dbe223e996dcefd95 100644 (file)
@@ -1947,12 +1947,17 @@ static pte_t *sun4c_pte_alloc_one_kernel(struct mm_struct *mm, unsigned long add
        return pte;
 }
 
-static struct page *sun4c_pte_alloc_one(struct mm_struct *mm, unsigned long address)
+static pgtable_t sun4c_pte_alloc_one(struct mm_struct *mm, unsigned long address)
 {
-       pte_t *pte = sun4c_pte_alloc_one_kernel(mm, address);
+       pte_t *pte;
+       struct page *page;
+
+       pte = sun4c_pte_alloc_one_kernel(mm, address);
        if (pte == NULL)
                return NULL;
-       return virt_to_page(pte);
+       page = virt_to_page(pte);
+       pgtable_page_ctor(page);
+       return page;
 }
 
 static inline void sun4c_free_pte_fast(pte_t *pte)
@@ -1962,8 +1967,9 @@ static inline void sun4c_free_pte_fast(pte_t *pte)
        pgtable_cache_size++;
 }
 
-static void sun4c_pte_free(struct page *pte)
+static void sun4c_pte_free(pgtable_t pte)
 {
+       pgtable_page_dtor(pte);
        sun4c_free_pte_fast(page_address(pte));
 }
 
index 565404ddcdc415247d92e576b8bec9ee2a8e1825..b810f2b7526a605b1f783c021190bc8304c7ac0f 100644 (file)
@@ -81,6 +81,9 @@ config GENERIC_HARDIRQS_NO__DO_IRQ
        bool
        def_bool y
 
+config ARCH_SUPPORTS_AOUT
+       def_bool y
+
 choice
        prompt "Kernel page size"
        default SPARC64_PAGE_SIZE_8KB
@@ -384,7 +387,7 @@ config COMPAT
 
 config BINFMT_AOUT32
        bool "Kernel support for 32-bit (ie. SunOS) a.out binaries"
-       depends on SPARC32_COMPAT
+       depends on SPARC32_COMPAT && ARCH_SUPPORTS_AOUT
        help
          This allows you to run 32-bit a.out format binaries on your Ultra.
          If you want to run SunOS binaries (see SunOS binary emulation below)
index 92c1b36a2e16bee668aa11fd414243d8ad0028f2..9877f2d7672d05442acf400bee5db41c61f5b2a3 100644 (file)
@@ -32,6 +32,7 @@
 #include <asm/uaccess.h>
 #include <asm/pgalloc.h>
 #include <asm/mmu_context.h>
+#include <asm/a.out-core.h>
 
 static int load_aout32_binary(struct linux_binprm *, struct pt_regs * regs);
 static int load_aout32_library(struct file*);
@@ -101,7 +102,7 @@ static int aout32_core_dump(long signr, struct pt_regs *regs, struct file *file,
        current->flags |= PF_DUMPCORE;
                strncpy(dump.u_comm, current->comm, sizeof(dump.u_comm));
        dump.signal = signr;
-       dump_thread(regs, &dump);
+       aout_dump_thread(regs, &dump);
 
 /* If the size of the dump file exceeds the rlimit, then see what would happen
    if we wrote the stack, but not the data area.  */
index 30431bd24e1efbe7ea2153043d2d06605433febe..5ec06c8c7feaa53dd162980c133f274a6637afdf 100644 (file)
@@ -522,7 +522,7 @@ static struct irq_chip sun4v_virq = {
        .set_affinity   = sun4v_virt_set_affinity,
 };
 
-static void fastcall pre_flow_handler(unsigned int virt_irq,
+static void pre_flow_handler(unsigned int virt_irq,
                                      struct irq_desc *desc)
 {
        struct irq_handler_data *data = get_irq_chip_data(virt_irq);
index ca7cdfd55f72084c901a1dfcc3c35e507422ddf7..1b23791749883ded9994463012181930be49bade 100644 (file)
@@ -24,7 +24,6 @@
 #include <linux/ptrace.h>
 #include <linux/slab.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/reboot.h>
 #include <linux/delay.h>
 #include <linux/compat.h>
@@ -725,17 +724,6 @@ pid_t kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
        return retval;
 }
 
-/*
- * fill in the user structure for a core dump..
- */
-void dump_thread(struct pt_regs * regs, struct user * dump)
-{
-       /* Only should be used for SunOS and ancient a.out
-        * SparcLinux binaries...  Not worth implementing.
-        */
-       memset(dump, 0, sizeof(struct user));
-}
-
 typedef struct {
        union {
                unsigned int    pr_regs[32];
index a813441b358f1355d9a732a530e7ef5160dcfba9..5964d8653ade61bba45ebd492c02bf2b664502a9 100644 (file)
@@ -15,7 +15,6 @@
 #include <linux/slab.h>
 #include <asm/smp.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/screen_info.h>
 #include <linux/delay.h>
 #include <linux/fs.h>
index 8649635d6d74f67e2b184903c3c1d3241fe3c47b..68db089303996498283df1cfe3466e0a71eaa6a8 100644 (file)
@@ -53,7 +53,6 @@
 #include <asm/ebus.h>
 #include <asm/isa.h>
 #endif
-#include <asm/a.out.h>
 #include <asm/ns87303.h>
 #include <asm/timer.h>
 #include <asm/cpudata.h>
index c56573a10eee60d2080dbbd674acd6bf6f1bdd53..134d801579f92e5ce10a274e1de080b5702ca113 100644 (file)
@@ -28,7 +28,6 @@
 #include <asm/uaccess.h>
 #include <asm/utrap.h>
 #include <asm/perfctr.h>
-#include <asm/a.out.h>
 #include <asm/unistd.h>
 
 /* #define DEBUG_UNIMP_SYSCALL */
index 98c468803ce35d345e72439280485fe546906ad2..deaba2bd0535fe10a372486a165fad134a5dccd4 100644 (file)
@@ -57,7 +57,6 @@
 #include <asm/fpumacro.h>
 #include <asm/semaphore.h>
 #include <asm/mmu_context.h>
-#include <asm/a.out.h>
 #include <asm/compat_signal.h>
 
 asmlinkage long sys32_chown16(const char __user * filename, u16 user, u16 group)
index c86cb3091a8ea8f28201f9afc66b718f230a107a..d3e48e9701bf33b35047cda9ebda3eb9e5546316 100644 (file)
@@ -415,7 +415,7 @@ asmlinkage int solaris_procids(int cmd, s32 pid, s32 pgid)
        
        switch (cmd) {
        case 0: /* getpgrp */
-               return task_pgrp_nr(current);
+               return task_pgrp_vnr(current);
        case 1: /* setpgrp */
                {
                        int (*sys_setpgid)(pid_t,pid_t) =
@@ -426,7 +426,7 @@ asmlinkage int solaris_procids(int cmd, s32 pid, s32 pgid)
                        ret = sys_setpgid(0, 0);
                        if (ret) return ret;
                        proc_clear_tty(current);
-                       return task_pgrp_nr(current);
+                       return task_pgrp_vnr(current);
                }
        case 2: /* getsid */
                {
index 99e51d059a02286bb0a80fc25c05f48f64d10058..dba8e05f028794540313535b0a06499d7f3271ae 100644 (file)
@@ -203,17 +203,6 @@ config NR_CPUS
        depends on SMP
        default "32"
 
-config NEST_LEVEL
-       int "Nesting level"
-       default "0"
-       help
-          This is set to the number of layers of UMLs that this UML will be run
-          in.  Normally, this is zero, meaning that it will run directly on the
-          host.  Setting it to one will build a UML that can run inside a UML
-          that is running on the host.  Generally, if you intend this UML to run
-          inside another UML, set CONFIG_NEST_LEVEL to one more than the host
-          UML.
-
 config HIGHMEM
        bool "Highmem support (EXPERIMENTAL)"
        depends on !64BIT && EXPERIMENTAL
index 717f5d3440e3bc89c784fa1cd1d930fbbde78844..3cd8a04d66d8101d629780d7c84e6ef9b5c903f0 100644 (file)
@@ -23,43 +23,6 @@ config SEMAPHORE_SLEEPERS
        bool
        default y
 
-choice
-       prompt "Host memory split"
-       default HOST_VMSPLIT_3G
-       help
-        This is needed when the host kernel on which you run has a non-default
-       (like 2G/2G) memory split, instead of the customary 3G/1G. If you did
-       not recompile your own kernel but use the default distro's one, you can
-       safely accept the "Default split" option.
-
-       It can be enabled on recent (>=2.6.16-rc2) vanilla kernels via
-       CONFIG_VM_SPLIT_*, or on previous kernels with special patches (-ck
-       patchset by Con Kolivas, or other ones) - option names match closely the
-       host CONFIG_VM_SPLIT_* ones.
-
-       A lower setting (where 1G/3G is lowest and 3G/1G is higher) will
-       tolerate even more "normal" host kernels, but an higher setting will be
-       stricter.
-
-       So, if you do not know what to do here, say 'Default split'.
-
-config HOST_VMSPLIT_3G
-       bool "Default split (3G/1G user/kernel host split)"
-config HOST_VMSPLIT_3G_OPT
-       bool "3G/1G user/kernel host split (for full 1G low memory)"
-config HOST_VMSPLIT_2G
-       bool "2G/2G user/kernel host split"
-config HOST_VMSPLIT_1G
-       bool "1G/3G user/kernel host split"
-endchoice
-
-config TOP_ADDR
-       hex
-       default 0xB0000000 if HOST_VMSPLIT_3G_OPT
-       default 0x78000000 if HOST_VMSPLIT_2G
-       default 0x40000000 if HOST_VMSPLIT_1G
-       default 0xC0000000
-
 config 3_LEVEL_PGTABLES
        bool "Three-level pagetables (EXPERIMENTAL)"
        default n
@@ -84,3 +47,5 @@ config GENERIC_HWEIGHT
        bool
        default y
 
+config ARCH_SUPPORTS_AOUT
+       def_bool y
index d632e9a89cc3d671ab69730cb5d0e457457e30d9..6533b349f06190eb31ea7960ad9e65fbc36475b8 100644 (file)
@@ -15,10 +15,6 @@ config SEMAPHORE_SLEEPERS
        bool
        default y
 
-config TOP_ADDR
-       hex
-       default 0x7fc0000000
-
 config 3_LEVEL_PGTABLES
        bool
        default y
@@ -39,3 +35,5 @@ config GENERIC_HWEIGHT
        bool
        default y
 
+config ARCH_SUPPORTS_AOUT
+       def_bool y
index cb4af9bf20747bf06b572c669589e1dd0d543c87..dbeab15e7bb7c160db7dda887a4c9d14982f742c 100644 (file)
@@ -79,13 +79,6 @@ KERNEL_DEFINES = $(strip -Derrno=kernel_errno -Dsigprocmask=kernel_sigprocmask \
 KBUILD_CFLAGS += $(KERNEL_DEFINES)
 KBUILD_CFLAGS += $(call cc-option,-fno-unit-at-a-time,)
 
-# These are needed for clean and mrproper, since in that case .config is not
-# included; the values here are meaningless
-
-CONFIG_NEST_LEVEL ?= 0
-
-SIZE = ($(CONFIG_NEST_LEVEL) * 0x20000000)
-
 PHONY += linux
 
 all: linux
@@ -120,10 +113,6 @@ CFLAGS_NO_HARDENING := $(call cc-option, -fno-PIC,) $(call cc-option, -fno-pic,)
 CONFIG_KERNEL_STACK_ORDER ?= 2
 STACK_SIZE := $(shell echo $$[ 4096 * (1 << $(CONFIG_KERNEL_STACK_ORDER)) ] )
 
-ifndef START
-  START = $(shell echo $$[ $(TOP_ADDR) - $(SIZE) ] )
-endif
-
 CPPFLAGS_vmlinux.lds = -U$(SUBARCH) -DSTART=$(START) -DELF_ARCH=$(ELF_ARCH) \
        -DELF_FORMAT="$(ELF_FORMAT)" -DKERNEL_STACK_SIZE=$(STACK_SIZE)
 
index 86db2862f2226eea9fc6a94f0220bb8db0a48dff..59215bc264ef8340a0e00ede70e4f0276f64ee29 100644 (file)
@@ -56,8 +56,6 @@ CONFIG_X86_TSC=y
 CONFIG_UML_X86=y
 # CONFIG_64BIT is not set
 CONFIG_SEMAPHORE_SLEEPERS=y
-# CONFIG_HOST_2G_2G is not set
-CONFIG_TOP_ADDR=0xc0000000
 # CONFIG_3_LEVEL_PGTABLES is not set
 CONFIG_ARCH_HAS_SC_SIGNALS=y
 CONFIG_ARCH_REUSE_HOST_VSYSCALL_AREA=y
@@ -81,7 +79,6 @@ CONFIG_HOSTFS=y
 # CONFIG_HPPFS is not set
 CONFIG_MCONSOLE=y
 CONFIG_MAGIC_SYSRQ=y
-CONFIG_NEST_LEVEL=0
 # CONFIG_HIGHMEM is not set
 CONFIG_KERNEL_STACK_ORDER=0
 
index 606bb5c7fdf6a2714d68111cf96c0c7a72eed012..cac542d8ff70783d10a153b6dd342852004cdf25 100644 (file)
@@ -57,6 +57,8 @@ extern unsigned long _stext, _etext, _sdata, _edata, __bss_start, _end;
 extern unsigned long _unprotected_end;
 extern unsigned long brk_start;
 
+extern unsigned long host_task_size;
+
 extern int linux_main(int argc, char **argv);
 
 extern void (*sig_info[])(int, struct uml_pt_regs *);
index 0b6b6273330392122c82dc1e9b845f5d03bff3b2..32c799e3a495729cad00c48f7bc5da0cd03b925c 100644 (file)
@@ -295,6 +295,9 @@ extern void maybe_sigio_broken(int fd, int read);
 extern int os_arch_prctl(int pid, int code, unsigned long *addr);
 
 /* tty.c */
-int get_pty(void);
+extern int get_pty(void);
+
+/* sys-$ARCH/task_size.c */
+extern unsigned long os_get_task_size(void);
 
 #endif
diff --git a/arch/um/include/tempfile.h b/arch/um/include/tempfile.h
deleted file mode 100644 (file)
index d441eac..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-/* 
- * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
- * Licensed under the GPL
- */
-
-#ifndef __TEMPFILE_H__
-#define __TEMPFILE_H__
-
-extern int make_tempfile(const char *template, char **tempname, int do_unlink);
-
-#endif
index 82865fcf6872eb0e7347d17ecd64cfc408240a02..f575ff91f2a01796951c90090542b18344e6998b 100644 (file)
@@ -13,6 +13,7 @@
 typedef struct mm_context {
        struct mm_id id;
        struct uml_ldt ldt;
+       struct page **stub_pages;
 } mm_context_t;
 
 extern void __switch_mm(struct mm_id * mm_idp);
index 76a62c0cb2bc89692e72df74a096df83f33487e5..f5d7f4569ba726f51fc92ef1b3b7e0ccdcb4e230 100644 (file)
@@ -25,7 +25,7 @@ void flush_thread(void)
 
        ret = unmap(&current->mm->context.id, 0, STUB_START, 0, &data);
        ret = ret || unmap(&current->mm->context.id, STUB_END,
-                          TASK_SIZE - STUB_END, 1, &data);
+                          host_task_size - STUB_END, 1, &data);
        if (ret) {
                printk(KERN_ERR "flush_thread - clearing address space failed, "
                       "err = %d\n", ret);
index 5311ee93ede3851c3ad311d134f911ec9c483188..66e2a305a8d6b4e13169b4280dafbff20e7cf42b 100644 (file)
@@ -5,7 +5,6 @@
 
 #include "linux/module.h"
 #include "linux/syscalls.h"
-#include "asm/a.out.h"
 #include "asm/tlbflush.h"
 #include "asm/uaccess.h"
 #include "as-layout.h"
@@ -60,7 +59,6 @@ EXPORT_SYMBOL(os_accept_connection);
 EXPORT_SYMBOL(os_rcv_fd);
 EXPORT_SYMBOL(run_helper);
 EXPORT_SYMBOL(start_thread);
-EXPORT_SYMBOL(dump_thread);
 
 #ifdef CONFIG_SMP
 
index d872fdce1d7ec76e9d4b37782b2a9ac9dd108395..2627ce82e918887f2fdf4ad9d9031fd4d6ac26ad 100644 (file)
@@ -354,11 +354,13 @@ pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
        return pte;
 }
 
-struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
+pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
 {
        struct page *pte;
 
        pte = alloc_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
+       if (pte)
+               pgtable_page_ctor(pte);
        return pte;
 }
 
index c07961bedb75ea7a379176275022c3cca26bae53..fc50d2f959d12f44bc6c41171f3cc030d6ad38fa 100644 (file)
@@ -258,10 +258,6 @@ void cpu_idle(void)
        default_idle();
 }
 
-void dump_thread(struct pt_regs *regs, struct user *u)
-{
-}
-
 int __cant_sleep(void) {
        return in_atomic() || irqs_disabled() || in_interrupt();
        /* Is in_interrupt() really needed? */
index 78b3e9f69d57d6a81d9ac446e9f6edc16586e5fe..0cd9a7a05e777bf79447af2338a9f6aaa784281d 100644 (file)
@@ -91,6 +91,8 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm)
                goto out_free;
        }
 
+       to_mm->stub_pages = NULL;
+
        return 0;
 
  out_free:
@@ -126,6 +128,7 @@ void arch_dup_mmap(struct mm_struct *oldmm, struct mm_struct *mm)
 
        pages[0] = virt_to_page(&__syscall_stub_start);
        pages[1] = virt_to_page(mm->context.id.stack);
+       mm->context.stub_pages = pages;
 
        /* dup_mmap already holds mmap_sem */
        err = install_special_mapping(mm, STUB_START, STUB_END - STUB_START,
@@ -147,6 +150,8 @@ void arch_exit_mmap(struct mm_struct *mm)
 {
        pte_t *pte;
 
+       if (mm->context.stub_pages != NULL)
+               kfree(mm->context.stub_pages);
        pte = virt_to_pte(mm, STUB_CODE);
        if (pte != NULL)
                pte_clear(mm, STUB_CODE, pte);
index 468aba990dbd1652add865bb88f1006ece3a7d16..a6c1dd1cf5a17a7806401e7b6fb97c3e2ceacd26 100644 (file)
@@ -241,6 +241,11 @@ static struct notifier_block panic_exit_notifier = {
 };
 
 /* Set during early boot */
+unsigned long task_size;
+EXPORT_SYMBOL(task_size);
+
+unsigned long host_task_size;
+
 unsigned long brk_start;
 unsigned long end_iomem;
 EXPORT_SYMBOL(end_iomem);
@@ -267,6 +272,13 @@ int __init linux_main(int argc, char **argv)
        if (have_root == 0)
                add_arg(DEFAULT_COMMAND_LINE);
 
+       host_task_size = os_get_task_size();
+       /*
+        * TASK_SIZE needs to be PGDIR_SIZE aligned or else exit_mmap craps
+        * out
+        */
+       task_size = host_task_size & PGDIR_MASK;
+
        /* OS sanity checks that need to happen before the kernel runs */
        os_early_checks();
 
@@ -303,7 +315,7 @@ int __init linux_main(int argc, char **argv)
 
        highmem = 0;
        iomem_size = (iomem_size + PAGE_SIZE - 1) & PAGE_MASK;
-       max_physmem = CONFIG_TOP_ADDR - uml_physmem - iomem_size - MIN_VMALLOC;
+       max_physmem = TASK_SIZE - uml_physmem - iomem_size - MIN_VMALLOC;
 
        /*
         * Zones have to begin on a 1 << MAX_ORDER page boundary,
@@ -335,7 +347,7 @@ int __init linux_main(int argc, char **argv)
        }
 
        virtmem_size = physmem_size;
-       avail = CONFIG_TOP_ADDR - start_vm;
+       avail = TASK_SIZE - start_vm;
        if (physmem_size > avail)
                virtmem_size = avail;
        end_vm = start_vm + virtmem_size;
index b8d8c9ca8d4afa48d3374520615fc5fdf8c2d8df..57e3d46c989cf0ba4ec4546d6e613e969537be3e 100644 (file)
@@ -142,7 +142,7 @@ static int do_not_aio(struct aio_thread_req *req)
        if (actual != req->offset)
                return -errno;
 
-       switch(req->type) {
+       switch (req->type) {
        case AIO_READ:
                n = read(req->io_fd, req->buf, req->len);
                break;
index 04f11b9f1ac09dbb6a882a7a1e0f270225bc13a7..046a131f61046260c293e12111f30a53266084fd 100644 (file)
@@ -6,7 +6,7 @@
  * Licensed under the GPL.
  */
 
-#include "linux/init.h"
+#include <linux/init.h>
 #include <linux/netdevice.h>
 #include "etap.h"
 #include "net_kern.h"
@@ -30,10 +30,10 @@ static void etap_init(struct net_device *dev, void *data)
        epri->control_fd = -1;
        epri->dev = dev;
 
-       printk("ethertap backend - %s", epri->dev_name);
+       printk(KERN_INFO "ethertap backend - %s", epri->dev_name);
        if (epri->gate_addr != NULL)
-               printk(", IP = %s", epri->gate_addr);
-       printk("\n");
+               printk(KERN_CONT ", IP = %s", epri->gate_addr);
+       printk(KERN_CONT "\n");
 }
 
 static int etap_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
index 9d384807b0775db5a5c31a7d8ea73c743562da35..6b9e33d5de20688d639ace827c57013e76b970ff 100644 (file)
@@ -29,10 +29,10 @@ static void tuntap_init(struct net_device *dev, void *data)
        tpri->fd = -1;
        tpri->dev = dev;
 
-       printk("TUN/TAP backend - ");
+       printk(KERN_INFO "TUN/TAP backend - ");
        if (tpri->gate_addr != NULL)
-               printk("IP = %s", tpri->gate_addr);
-       printk("\n");
+               printk(KERN_CONT "IP = %s", tpri->gate_addr);
+       printk(KERN_CONT "\n");
 }
 
 static int tuntap_read(int fd, struct sk_buff *skb, struct uml_net_private *lp)
index d82711efacfadf2a5a50e27fcd2af31a61c3e6a3..fe71be24bd59d68aaf8e62a080eb59250bbd646a 100644 (file)
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
@@ -9,14 +9,3 @@
 #define DEV_NULL "/dev/null"
 
 #endif
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only.  This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
index eedc2d88ef8a5a3d6b00e87e88a8a05e7c77ab89..93a11d7edfa0505a7acfd9bd99a0266aec97f933 100644 (file)
@@ -1,22 +1,21 @@
+/*
+ * Copyright (C) 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
+ * Licensed under the GPL
+ */
+
 #include <stdio.h>
-#include <stdlib.h>
 #include <stddef.h>
-#include <stdarg.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
-#include <string.h>
 #include <fcntl.h>
-#include <sys/types.h>
+#include <string.h>
 #include <sys/mman.h>
-#include <sys/statfs.h>
-#include "user.h"
-#include "mem_user.h"
+#include <sys/param.h>
 #include "init.h"
-#include "os.h"
-#include "tempfile.h"
 #include "kern_constants.h"
-
-#include <sys/param.h>
+#include "os.h"
+#include "user.h"
 
 /* Modified by which_tmpdir, which is called during early boot */
 static char *default_tmpdir = "/tmp";
@@ -33,18 +32,19 @@ static void __init find_tempdir(void)
        int i;
        char *dir = NULL;
 
-       if(tempdir != NULL) /* We've already been called */
+       if (tempdir != NULL)
+               /* We've already been called */
                return;
-       for(i = 0; dirs[i]; i++){
+       for (i = 0; dirs[i]; i++) {
                dir = getenv(dirs[i]);
-               if((dir != NULL) && (*dir != '\0'))
+               if ((dir != NULL) && (*dir != '\0'))
                        break;
        }
-       if((dir == NULL) || (*dir == '\0'))
+       if ((dir == NULL) || (*dir == '\0'))
                dir = default_tmpdir;
 
        tempdir = malloc(strlen(dir) + 2);
-       if(tempdir == NULL){
+       if (tempdir == NULL) {
                fprintf(stderr, "Failed to malloc tempdir, "
                        "errno = %d\n", errno);
                return;
@@ -53,7 +53,8 @@ static void __init find_tempdir(void)
        strcat(tempdir, "/");
 }
 
-/* This will return 1, with the first character in buf being the
+/*
+ * This will return 1, with the first character in buf being the
  * character following the next instance of c in the file.  This will
  * read the file as needed.  If there's an error, -errno is returned;
  * if the end of the file is reached, 0 is returned.
@@ -64,11 +65,11 @@ static int next(int fd, char *buf, size_t size, char c)
        size_t len;
        char *ptr;
 
-       while((ptr = strchr(buf, c)) == NULL){
+       while ((ptr = strchr(buf, c)) == NULL) {
                n = read(fd, buf, size - 1);
-               if(n == 0)
+               if (n == 0)
                        return 0;
-               else if(n < 0)
+               else if (n < 0)
                        return -errno;
 
                buf[n] = '\0';
@@ -78,11 +79,12 @@ static int next(int fd, char *buf, size_t size, char c)
        len = strlen(ptr);
        memmove(buf, ptr, len + 1);
 
-       /* Refill the buffer so that if there's a partial string that we care
+       /*
+        * Refill the buffer so that if there's a partial string that we care
         * about, it will be completed, and we can recognize it.
         */
        n = read(fd, &buf[len], size - len - 1);
-       if(n < 0)
+       if (n < 0)
                return -errno;
 
        buf[len + n] = '\0';
@@ -92,7 +94,8 @@ static int next(int fd, char *buf, size_t size, char c)
 /* which_tmpdir is called only during early boot */
 static int checked_tmpdir = 0;
 
-/* Look for a tmpfs mounted at /dev/shm.  I couldn't find a cleaner
+/*
+ * Look for a tmpfs mounted at /dev/shm.  I couldn't find a cleaner
  * way to do this than to parse /proc/mounts.  statfs will return the
  * same filesystem magic number and fs id for both /dev and /dev/shm
  * when they are both tmpfs, so you can't tell if they are different
@@ -107,7 +110,7 @@ static void which_tmpdir(void)
        int fd, found;
        char buf[128] = { '\0' };
 
-       if(checked_tmpdir)
+       if (checked_tmpdir)
                return;
 
        checked_tmpdir = 1;
@@ -115,28 +118,28 @@ static void which_tmpdir(void)
        printf("Checking for tmpfs mount on /dev/shm...");
 
        fd = open("/proc/mounts", O_RDONLY);
-       if(fd < 0){
+       if (fd < 0) {
                printf("failed to open /proc/mounts, errno = %d\n", errno);
                return;
        }
 
-       while(1){
+       while (1) {
                found = next(fd, buf, ARRAY_SIZE(buf), ' ');
-               if(found != 1)
+               if (found != 1)
                        break;
 
-               if(!strncmp(buf, "/dev/shm", strlen("/dev/shm")))
+               if (!strncmp(buf, "/dev/shm", strlen("/dev/shm")))
                        goto found;
 
                found = next(fd, buf, ARRAY_SIZE(buf), '\n');
-               if(found != 1)
+               if (found != 1)
                        break;
        }
 
 err:
-       if(found == 0)
+       if (found == 0)
                printf("nothing mounted on /dev/shm\n");
-       else if(found < 0)
+       else if (found < 0)
                printf("read returned errno %d\n", -found);
 
 out:
@@ -146,10 +149,10 @@ out:
 
 found:
        found = next(fd, buf, ARRAY_SIZE(buf), ' ');
-       if(found != 1)
+       if (found != 1)
                goto err;
 
-       if(strncmp(buf, "tmpfs", strlen("tmpfs"))){
+       if (strncmp(buf, "tmpfs", strlen("tmpfs"))) {
                printf("not tmpfs\n");
                goto out;
        }
@@ -159,43 +162,40 @@ found:
        goto out;
 }
 
-/*
- * This proc still used in tt-mode
- * (file: kernel/tt/ptproxy/proxy.c, proc: start_debugger).
- * So it isn't 'static' yet.
- */
-int __init make_tempfile(const char *template, char **out_tempname,
-                        int do_unlink)
+static int __init make_tempfile(const char *template, char **out_tempname,
+                               int do_unlink)
 {
        char *tempname;
        int fd;
 
        which_tmpdir();
        tempname = malloc(MAXPATHLEN);
-       if (!tempname)
-               goto out;
+       if (tempname == NULL)
+               return -1;
 
        find_tempdir();
+       if ((tempdir == NULL) || (strlen(tempdir) >= MAXPATHLEN))
+               return -1;
+
        if (template[0] != '/')
                strcpy(tempname, tempdir);
        else
                tempname[0] = '\0';
        strncat(tempname, template, MAXPATHLEN-1-strlen(tempname));
        fd = mkstemp(tempname);
-       if(fd < 0){
+       if (fd < 0) {
                fprintf(stderr, "open - cannot create %s: %s\n", tempname,
                        strerror(errno));
                goto out;
        }
-       if(do_unlink && (unlink(tempname) < 0)){
+       if (do_unlink && (unlink(tempname) < 0)) {
                perror("unlink");
                goto out;
        }
-       if(out_tempname){
+       if (out_tempname) {
                *out_tempname = tempname;
-       } else {
+       } else
                free(tempname);
-       }
        return fd;
 out:
        free(tempname);
@@ -204,27 +204,23 @@ out:
 
 #define TEMPNAME_TEMPLATE "vm_file-XXXXXX"
 
-/*
- * This proc is used in start_up.c
- * So it isn't 'static'.
- */
-int __init create_tmp_file(unsigned long long len)
+static int __init create_tmp_file(unsigned long long len)
 {
        int fd, err;
        char zero;
 
        fd = make_tempfile(TEMPNAME_TEMPLATE, NULL, 1);
-       if(fd < 0) {
+       if (fd < 0)
                exit(1);
-       }
 
        err = fchmod(fd, 0777);
-       if(err < 0){
+       if (err < 0) {
                perror("fchmod");
                exit(1);
        }
 
-       /* Seek to len - 1 because writing a character there will
+       /*
+        * Seek to len - 1 because writing a character there will
         * increase the file size by one byte, to the desired length.
         */
        if (lseek64(fd, len - 1, SEEK_SET) < 0) {
@@ -235,7 +231,7 @@ int __init create_tmp_file(unsigned long long len)
        zero = 0;
 
        err = write(fd, &zero, 1);
-       if(err != 1){
+       if (err != 1) {
                perror("write");
                exit(1);
        }
@@ -250,7 +246,7 @@ int __init create_mem_file(unsigned long long len)
        fd = create_tmp_file(len);
 
        err = os_set_exec_close(fd);
-       if(err < 0){
+       if (err < 0) {
                errno = -err;
                perror("exec_close");
        }
@@ -267,11 +263,11 @@ void __init check_tmpexec(void)
                    PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0);
        printf("Checking PROT_EXEC mmap in %s...",tempdir);
        fflush(stdout);
-       if(addr == MAP_FAILED){
+       if (addr == MAP_FAILED) {
                err = errno;
                perror("failed");
                close(fd);
-               if(err == EPERM)
+               if (err == EPERM)
                        printf("%s must be not mounted noexec\n",tempdir);
                exit(1);
        }
index abf6beae3df1bec14f60943754e54ba9e4d32f16..e0477c3ee89448f72320b01a493a97cb280ecad6 100644 (file)
@@ -224,7 +224,7 @@ int __init can_drop_memory(void)
                goto out_unmap;
        }
 
-       printk("OK\n");
+       printk(UM_KERN_CONT "OK\n");
        ok = 1;
 
 out_unmap:
index 0fb0cc8d47577c34d842a25a75f2e477dfc6d2c3..3f1694b134cb2606efa628deb4291c5813a549c0 100644 (file)
@@ -237,7 +237,7 @@ void unblock_signals(void)
         * interrupts may have arrived and we need to re-enable them and
         * recheck signals_pending.
         */
-       while(1) {
+       while (1) {
                /*
                 * Save and reset save_pending after enabling signals.  This
                 * way, signals_pending won't be changed while we're reading it.
index d36c89c24a45c5df05a652f88dc26901577bb19b..b14829469faefdf99a2511beede3ea6515c21927 100644 (file)
@@ -341,7 +341,7 @@ void userspace(struct uml_pt_regs *regs)
        int local_using_sysemu;
 
        if (getitimer(ITIMER_VIRTUAL, &timer))
-               printk("Failed to get itimer, errno = %d\n", errno);
+               printk(UM_KERN_ERR "Failed to get itimer, errno = %d\n", errno);
        nsecs = timer.it_value.tv_sec * UM_NSEC_PER_SEC +
                timer.it_value.tv_usec * UM_NSEC_PER_USEC;
        nsecs += os_nsecs();
@@ -388,7 +388,7 @@ void userspace(struct uml_pt_regs *regs)
 
                if (WIFSTOPPED(status)) {
                        int sig = WSTOPSIG(status);
-                       switch(sig) {
+                       switch (sig) {
                        case SIGSEGV:
                                if (PTRACE_FULL_FAULTINFO ||
                                    !ptrace_faultinfo) {
@@ -641,7 +641,7 @@ int start_idle_thread(void *stack, jmp_buf *switch_buf)
         * after returning to the jumper.
         */
        n = setjmp(initial_jmpbuf);
-       switch(n) {
+       switch (n) {
        case INIT_JMP_NEW_THREAD:
                (*switch_buf)[0].JB_IP = (unsigned long) new_thread_handler;
                (*switch_buf)[0].JB_SP = (unsigned long) stack +
index a841262c594a442acdbe3bfaaef6dc0ffdd7d136..b4bc6ac4f30bc5f5781a7a901a8b1665e81b9923 100644 (file)
@@ -3,7 +3,7 @@
 # Licensed under the GPL
 #
 
-obj-y = registers.o signal.o tls.o
+obj-y = registers.o signal.o task_size.o tls.o
 
 USER_OBJS := $(obj-y)
 
index d1997ca76e5cbd182a6ce606b609516cfcdbbcc6..f74d853a0ee02372af46d4ab4ae244242a19ea4f 100644 (file)
@@ -62,10 +62,10 @@ void arch_init_registers(int pid)
        int err;
 
        err = ptrace(PTRACE_GETFPXREGS, pid, 0, fpx_regs);
-       if(!err)
+       if (!err)
                return;
 
-       if(errno != EIO)
+       if (errno != EIO)
                panic("check_ptrace : PTRACE_GETFPXREGS failed, errno = %d",
                      errno);
 
diff --git a/arch/um/os-Linux/sys-i386/task_size.c b/arch/um/os-Linux/sys-i386/task_size.c
new file mode 100644 (file)
index 0000000..48d211b
--- /dev/null
@@ -0,0 +1,120 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/mman.h>
+#include "longjmp.h"
+#include "kern_constants.h"
+
+static jmp_buf buf;
+
+static void segfault(int sig)
+{
+       longjmp(buf, 1);
+}
+
+static int page_ok(unsigned long page)
+{
+       unsigned long *address = (unsigned long *) (page << UM_KERN_PAGE_SHIFT);
+       unsigned long n = ~0UL;
+       void *mapped = NULL;
+       int ok = 0;
+
+       /*
+        * First see if the page is readable.  If it is, it may still
+        * be a VDSO, so we go on to see if it's writable.  If not
+        * then try mapping memory there.  If that fails, then we're
+        * still in the kernel area.  As a sanity check, we'll fail if
+        * the mmap succeeds, but gives us an address different from
+        * what we wanted.
+        */
+       if (setjmp(buf) == 0)
+               n = *address;
+       else {
+               mapped = mmap(address, UM_KERN_PAGE_SIZE,
+                             PROT_READ | PROT_WRITE,
+                             MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+               if (mapped == MAP_FAILED)
+                       return 0;
+               if (mapped != address)
+                       goto out;
+       }
+
+       /*
+        * Now, is it writeable?  If so, then we're in user address
+        * space.  If not, then try mprotecting it and try the write
+        * again.
+        */
+       if (setjmp(buf) == 0) {
+               *address = n;
+               ok = 1;
+               goto out;
+       } else if (mprotect(address, UM_KERN_PAGE_SIZE,
+                           PROT_READ | PROT_WRITE) != 0)
+               goto out;
+
+       if (setjmp(buf) == 0) {
+               *address = n;
+               ok = 1;
+       }
+
+ out:
+       if (mapped != NULL)
+               munmap(mapped, UM_KERN_PAGE_SIZE);
+       return ok;
+}
+
+unsigned long os_get_task_size(void)
+{
+       struct sigaction sa, old;
+       unsigned long bottom = 0;
+       /*
+        * A 32-bit UML on a 64-bit host gets confused about the VDSO at
+        * 0xffffe000.  It is mapped, is readable, can be reprotected writeable
+        * and written.  However, exec discovers later that it can't be
+        * unmapped.  So, just set the highest address to be checked to just
+        * below it.  This might waste some address space on 4G/4G 32-bit
+        * hosts, but shouldn't hurt otherwise.
+        */
+       unsigned long top = 0xffffd000 >> UM_KERN_PAGE_SHIFT;
+       unsigned long test;
+
+       printf("Locating the top of the address space ... ");
+       fflush(stdout);
+
+       /*
+        * We're going to be longjmping out of the signal handler, so
+        * SA_DEFER needs to be set.
+        */
+       sa.sa_handler = segfault;
+       sigemptyset(&sa.sa_mask);
+       sa.sa_flags = SA_NODEFER;
+       sigaction(SIGSEGV, &sa, &old);
+
+       if (!page_ok(bottom)) {
+               fprintf(stderr, "Address 0x%x no good?\n",
+                       bottom << UM_KERN_PAGE_SHIFT);
+               exit(1);
+       }
+
+       /* This could happen with a 4G/4G split */
+       if (page_ok(top))
+               goto out;
+
+       do {
+               test = bottom + (top - bottom) / 2;
+               if (page_ok(test))
+                       bottom = test;
+               else
+                       top = test;
+       } while (top - bottom > 1);
+
+out:
+       /* Restore the old SIGSEGV handling */
+       sigaction(SIGSEGV, &old, NULL);
+
+       top <<= UM_KERN_PAGE_SHIFT;
+       printf("0x%x\n", top);
+       fflush(stdout);
+
+       return top;
+}
index a42a4ef02e1e5e7f33ef6df81dbbaa20a9618e5a..a44a47f8f57b85c43d58c07916dcbfb98f983e8c 100644 (file)
@@ -3,7 +3,7 @@
 # Licensed under the GPL
 #
 
-obj-y = registers.o prctl.o signal.o
+obj-y = registers.o prctl.o signal.o task_size.o
 
 USER_OBJS := $(obj-y)
 
index 9bfa789992dec6ce7c23f532aa9de69bbfc143f3..a375853337a703d7764dded31549725cf17376e8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
+ * Copyright (C) 2006 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
@@ -7,31 +7,36 @@
 #include <sys/ptrace.h>
 #define __FRAME_OFFSETS
 #include <asm/ptrace.h>
+#include "kern_constants.h"
 #include "longjmp.h"
 #include "user.h"
 
 int save_fp_registers(int pid, unsigned long *fp_regs)
 {
-       if(ptrace(PTRACE_GETFPREGS, pid, 0, fp_regs) < 0)
+       if (ptrace(PTRACE_GETFPREGS, pid, 0, fp_regs) < 0)
                return -errno;
        return 0;
 }
 
 int restore_fp_registers(int pid, unsigned long *fp_regs)
 {
-       if(ptrace(PTRACE_SETFPREGS, pid, 0, fp_regs) < 0)
+       if (ptrace(PTRACE_SETFPREGS, pid, 0, fp_regs) < 0)
                return -errno;
        return 0;
 }
 
 unsigned long get_thread_reg(int reg, jmp_buf *buf)
 {
-       switch(reg){
-       case RIP: return buf[0]->__rip;
-       case RSP: return buf[0]->__rsp;
-       case RBP: return buf[0]->__rbp;
+       switch (reg) {
+       case RIP:
+               return buf[0]->__rip;
+       case RSP:
+               return buf[0]->__rsp;
+       case RBP:
+               return buf[0]->__rbp;
        default:
-               printk("get_thread_regs - unknown register %d\n", reg);
+               printk(UM_KERN_ERR "get_thread_regs - unknown register %d\n",
+                      reg);
                return 0;
        }
 }
diff --git a/arch/um/os-Linux/sys-x86_64/task_size.c b/arch/um/os-Linux/sys-x86_64/task_size.c
new file mode 100644 (file)
index 0000000..fad6f57
--- /dev/null
@@ -0,0 +1,5 @@
+unsigned long os_get_task_size(unsigned long shift)
+{
+       /* The old value of CONFIG_TOP_ADDR */
+       return 0x7fc0000000;
+}
index 8d27b6d1df91c58b69685fce86c2f4ae4ea9134e..087ed74ffca55081ab7052d51d74103f34d3c7f5 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2001 Chris Emerson (cemerson@chiark.greenend.org.uk)
- * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
@@ -16,7 +16,7 @@ unsigned long __do_user_copy(void *to, const void *from, int n,
 
        jmp_buf jbuf;
        *fault_catcher = &jbuf;
-       if(UML_SETJMP(&jbuf) == 0){
+       if (UML_SETJMP(&jbuf) == 0) {
                (*op)(to, from, n);
                ret = 0;
                *faulted_out = 0;
index 4c37b1b1d0b588d7a9c822a69d976a6a2ed26644..74f49bb9b125ed8728de851780b489895f2f4ac2 100644 (file)
@@ -34,8 +34,8 @@ EXPORT_SYMBOL(printf);
  * good; so the versions of these symbols will always match
  */
 #define EXPORT_SYMBOL_PROTO(sym)       \
-       int sym(void);                  \
-       EXPORT_SYMBOL(sym);
+       int sym(void);                  \
+       EXPORT_SYMBOL(sym);
 
 extern void readdir64(void) __attribute__((weak));
 EXPORT_SYMBOL(readdir64);
index a6f31d476993cd0314c8c6adbf9dad0c7c796f15..6ea77979531c95e1bf005eb0cc3e4a87fa6c913d 100644 (file)
@@ -1,39 +1,24 @@
 /*
- * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
+ * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
  * Licensed under the GPL
  */
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
-#include <limits.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/utsname.h>
-#include <sys/param.h>
-#include <sys/time.h>
-#include "asm/types.h"
-#include <ctype.h>
-#include <signal.h>
-#include <wait.h>
 #include <errno.h>
-#include <stdarg.h>
-#include <sched.h>
-#include <termios.h>
+#include <signal.h>
 #include <string.h>
-#include "kern_util.h"
-#include "user.h"
-#include "mem_user.h"
-#include "init.h"
-#include "ptrace_user.h"
-#include "uml-config.h"
-#include "os.h"
-#include "longjmp.h"
+#include <termios.h>
+#include <wait.h>
+#include <sys/mman.h>
+#include <sys/utsname.h>
 #include "kern_constants.h"
+#include "os.h"
+#include "user.h"
 
 void stack_protections(unsigned long address)
 {
-       if(mprotect((void *) address, UM_THREAD_SIZE,
+       if (mprotect((void *) address, UM_THREAD_SIZE,
                    PROT_READ | PROT_WRITE | PROT_EXEC) < 0)
                panic("protecting stack failed, errno = %d", errno);
 }
@@ -44,17 +29,19 @@ int raw(int fd)
        int err;
 
        CATCH_EINTR(err = tcgetattr(fd, &tt));
-       if(err < 0)
+       if (err < 0)
                return -errno;
 
        cfmakeraw(&tt);
 
        CATCH_EINTR(err = tcsetattr(fd, TCSADRAIN, &tt));
-       if(err < 0)
+       if (err < 0)
                return -errno;
 
-       /* XXX tcsetattr could have applied only some changes
-        * (and cfmakeraw() is a set of changes) */
+       /*
+        * XXX tcsetattr could have applied only some changes
+        * (and cfmakeraw() is a set of changes)
+        */
        return 0;
 }
 
index ace479ab273ff329cc387ce536e8598f171054b4..7b6d3716efca4a0f370ef848ac8cecbfa0e39eb6 100644 (file)
@@ -53,6 +53,9 @@ config ARCH_HAS_ILOG2_U64
        bool
        default n
 
+config ARCH_SUPPORTS_AOUT
+       def_bool y
+
 # Turn off some random 386 crap that can affect device config
 config ISA
        bool
@@ -212,6 +215,13 @@ menu "Processor type and features"
          bool
          default !V850E_CACHE && !V850E2_CACHE
 
+   # HZ depends on the platform
+   config HZ
+         int
+         default 24  if V850E_SIM || V850E2_SIM85E2
+         default 122 if V850E2_FPGA85E2C
+         default 100
+
    #### Misc config
 
    config ROM_KERNEL
index e6f9d060ad5bb7e40b799e21a64a2be55585b6b0..e433cde789b4d24dba12582d20f501f71fd03dc7 100644 (file)
@@ -59,7 +59,7 @@ static void cpuinfo_stop (struct seq_file *m, void *v)
 {
 }
 
-struct seq_operations cpuinfo_op = {
+const struct seq_operations cpuinfo_op = {
        .start  = cpuinfo_start,
        .next   = cpuinfo_next,
        .stop   = cpuinfo_stop,
index c95482b6b6dd2f064701000db87519ec9bb621a7..65a70b777c12e149d14c95a9775896abbe720964 100644 (file)
@@ -52,6 +52,10 @@ config HAVE_LATENCYTOP_SUPPORT
 config SEMAPHORE_SLEEPERS
        def_bool y
 
+config FAST_CMPXCHG_LOCAL
+       bool
+       default y
+
 config MMU
        def_bool y
 
@@ -132,6 +136,9 @@ config AUDIT_ARCH
        bool
        default X86_64
 
+config ARCH_SUPPORTS_AOUT
+       def_bool y
+
 # Use the generic interrupt handling code in kernel/irq/:
 config GENERIC_HARDIRQS
        bool
@@ -1573,7 +1580,7 @@ config IA32_EMULATION
 
 config IA32_AOUT
        tristate "IA32 a.out support"
-       depends on IA32_EMULATION
+       depends on IA32_EMULATION && ARCH_SUPPORTS_AOUT
        help
          Support old a.out binaries in the 32bit emulation.
 
index dabdbeff1f778685af46cb66b465ec0e36c71a02..a7d50a547dc2a8a1be9f2af87a52226d95c6438c 100644 (file)
@@ -23,7 +23,6 @@
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/interrupt.h>
 #include <linux/utsname.h>
 #include <linux/delay.h>
@@ -539,55 +538,6 @@ int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
        return err;
 }
 
-/*
- * fill in the user structure for a core dump..
- */
-void dump_thread(struct pt_regs * regs, struct user * dump)
-{
-       u16 gs;
-
-/* changed the size calculations - should hopefully work better. lbt */
-       dump->magic = CMAGIC;
-       dump->start_code = 0;
-       dump->start_stack = regs->sp & ~(PAGE_SIZE - 1);
-       dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
-       dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> PAGE_SHIFT;
-       dump->u_dsize -= dump->u_tsize;
-       dump->u_ssize = 0;
-       dump->u_debugreg[0] = current->thread.debugreg0;
-       dump->u_debugreg[1] = current->thread.debugreg1;
-       dump->u_debugreg[2] = current->thread.debugreg2;
-       dump->u_debugreg[3] = current->thread.debugreg3;
-       dump->u_debugreg[4] = 0;
-       dump->u_debugreg[5] = 0;
-       dump->u_debugreg[6] = current->thread.debugreg6;
-       dump->u_debugreg[7] = current->thread.debugreg7;
-
-       if (dump->start_stack < TASK_SIZE)
-               dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
-
-       dump->regs.bx = regs->bx;
-       dump->regs.cx = regs->cx;
-       dump->regs.dx = regs->dx;
-       dump->regs.si = regs->si;
-       dump->regs.di = regs->di;
-       dump->regs.bp = regs->bp;
-       dump->regs.ax = regs->ax;
-       dump->regs.ds = (u16)regs->ds;
-       dump->regs.es = (u16)regs->es;
-       dump->regs.fs = (u16)regs->fs;
-       savesegment(gs,gs);
-       dump->regs.orig_ax = regs->orig_ax;
-       dump->regs.ip = regs->ip;
-       dump->regs.cs = (u16)regs->cs;
-       dump->regs.flags = regs->flags;
-       dump->regs.sp = regs->sp;
-       dump->regs.ss = (u16)regs->ss;
-
-       dump->u_fpvalid = dump_fpu (regs, &dump->i387);
-}
-EXPORT_SYMBOL(dump_thread);
-
 #ifdef CONFIG_SECCOMP
 static void hard_disable_TSC(void)
 {
index 137a86171c393ac64fd0e6df392d40caad951b9f..b0cc8f0136d8096e9e4cdad316787f89d4f55a8c 100644 (file)
@@ -26,7 +26,6 @@
 #include <linux/smp.h>
 #include <linux/slab.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/interrupt.h>
 #include <linux/utsname.h>
 #include <linux/delay.h>
index a49f5f734a5e09d68f9fd1859e6c076405fb7059..c0d8208af12a2d92e4e5bee3baf6b52dadb3efd6 100644 (file)
@@ -15,7 +15,6 @@
 #include <linux/ptrace.h>
 #include <linux/slab.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/screen_info.h>
 #include <linux/ioport.h>
 #include <linux/delay.h>
index 0380795121a601e620d41e4b83eb5838c7d6ad8b..c737849e2ef7a46b66cce8bc63e230d5a4200da8 100644 (file)
@@ -77,7 +77,7 @@ unsigned long __init native_calculate_cpu_khz(void)
                reserve_evntsel_nmi(MSR_K7_EVNTSEL0 + i);
        }
        local_irq_save(flags);
-       /* start meauring cycles, incrementing from 0 */
+       /* start measuring cycles, incrementing from 0 */
        wrmsrl(MSR_K7_PERFCTR0 + i, 0);
        wrmsrl(MSR_K7_EVNTSEL0 + i, 1 << 22 | 3 << 16 | 0x76);
        rdtscl(tsc_start);
index 6c1914622a88344456f571d2cbf06e58921f451b..73aba7125203764b41a3cb3af48ac6d5d5cee5a4 100644 (file)
@@ -183,7 +183,7 @@ pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
        return (pte_t *)__get_free_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
 }
 
-struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
+pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
 {
        struct page *pte;
 
@@ -192,6 +192,8 @@ struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
 #else
        pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0);
 #endif
+       if (pte)
+               pgtable_page_ctor(pte);
        return pte;
 }
 
@@ -365,6 +367,7 @@ void check_pgt_cache(void)
 
 void __pte_free_tlb(struct mmu_gather *tlb, struct page *pte)
 {
+       pgtable_page_dtor(pte);
        paravirt_release_pt(page_to_pfn(pte));
        tlb_remove_page(tlb, pte);
 }
index 5d5546ce88fe90b02ff376a633a4933b22639685..fd36764d7fb72358a65a3551ad9a0faf7b4a70e1 100644 (file)
@@ -49,6 +49,10 @@ config ARCH_HAS_ILOG2_U64
 config NO_IOPORT
        def_bool y
 
+config HZ
+       int
+       default 100
+
 source "init/Kconfig"
 
 menu "Processor type and features"
index 2e8d398cf19627aef6db11a8e6d723ae7b106fa7..b80f2cb1b4fb1c9883473c8dae6d63261874fb15 100644 (file)
@@ -469,7 +469,7 @@ c_stop(struct seq_file *f, void *v)
 {
 }
 
-struct seq_operations cpuinfo_op =
+const struct seq_operations cpuinfo_op =
 {
        start:  c_start,
        next:   c_next,
index 7ef172c2a1d64cd3c641b631efff4e5946cc75b1..f688c214be0c67110df1d039be5566d3c7f59bfe 100644 (file)
@@ -204,13 +204,25 @@ config ACPI_NUMA
 
 config ACPI_WMI
        tristate "WMI (EXPERIMENTAL)"
+       depends on X86
        depends on EXPERIMENTAL
        help
-         This driver adds support for the ACPI-WMI mapper device (PNP0C14)
-         found on some systems.
+         This driver adds support for the ACPI-WMI (Windows Management
+         Instrumentation) mapper device (PNP0C14) found on some systems.
+
+         ACPI-WMI is a proprietary extension to ACPI to expose parts of the
+         ACPI firmware to userspace - this is done through various vendor
+         defined methods and data blocks in a PNP0C14 device, which are then
+         made available for userspace to call.
+
+         The implementation of this in Linux currently only exposes this to
+         other kernel space drivers.
+
+         This driver is a required dependency to build the firmware specific
+         drivers needed on many machines, including Acer and HP laptops.
 
-         NOTE: You will need another driver or userspace application on top of
-         this to actually use anything defined in the ACPI-WMI mapper.
+         It is safe to enable this driver even if your DSDT doesn't define
+         any ACPI-WMI devices.
 
 config ACPI_ASUS
         tristate "ASUS/Medion Laptop Extras"
index 6dbaa2d15fe0fb1b698cb6c8e1d11841f76b813e..9ce983ed60f00f762af1c950455f5088ecc64161 100644 (file)
@@ -445,6 +445,8 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
         * DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad T61"),
         * _OSI(Linux) is a NOP:
         * DMI_MATCH(DMI_PRODUCT_VERSION, "3000 N100"),
+        * _OSI(Linux) effect unknown
+        * DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X61"),
         */
        {
        .callback = dmi_enable_osi_linux,
@@ -464,6 +466,14 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
        },
        {
        .callback = dmi_unknown_osi_linux,
+       .ident = "Lenovo ThinkPad X61",
+       .matches = {
+                    DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
+                    DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad X61"),
+               },
+       },
+       {
+       .callback = dmi_unknown_osi_linux,
        .ident = "Lenovo 3000 V100",
        .matches = {
                     DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
@@ -505,6 +515,16 @@ static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
                     DMI_MATCH(DMI_PRODUCT_NAME, "NEC VERSA M360"),
                },
        },
+       /* Panasonic */
+       {
+       .callback = dmi_unknown_osi_linux,
+       .ident = "Panasonic",
+       .matches = {
+                    DMI_MATCH(DMI_SYS_VENDOR, "Matsushita"),
+                       /* Toughbook CF-52 */
+                    DMI_MATCH(DMI_PRODUCT_NAME, "CF-52CCABVBG"),
+               },
+       },
        /*
         * Disable OSI(Linux) warnings on all "Samsung Electronics"
         *
index 27ccd68b8f462de790a7243219197e4631b8fcf9..a14501c98f40908f7b415e18490914320c720d4e 100644 (file)
@@ -343,7 +343,7 @@ struct acpi_table_header *acpi_find_dsdt_initrd(void)
        struct kstat stat;
        char *ramfs_dsdt_name = "/DSDT.aml";
 
-       printk(KERN_INFO PREFIX "Checking initramfs for custom DSDT");
+       printk(KERN_INFO PREFIX "Checking initramfs for custom DSDT\n");
 
        /*
         * Never do this at home, only the user-space is allowed to open a file.
index f32010bee4d5650a6896624bab290a4d560e916c..b477a4be8a698fde564465278cf7c09321f9b00b 100644 (file)
@@ -50,6 +50,10 @@ ACPI_MODULE_NAME("processor_perflib");
 
 static DEFINE_MUTEX(performance_mutex);
 
+/* Use cpufreq debug layer for _PPC changes. */
+#define cpufreq_printk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, \
+                                               "cpufreq-core", msg)
+
 /*
  * _PPC support is implemented as a CPUfreq policy notifier:
  * This means each time a CPUfreq driver registered also with
@@ -131,6 +135,9 @@ static int acpi_processor_get_platform_limit(struct acpi_processor *pr)
                return -ENODEV;
        }
 
+       cpufreq_printk("CPU %d: _PPC is %d - frequency %s limited\n", pr->id,
+                      (int)ppc, ppc ? "" : "not");
+
        pr->performance_platform_limit = (int)ppc;
 
        return 0;
index 64e5148d82bc8cce2018012f6bf5587570ba2267..b6d230b3209f24567be22208be6d8236af88282d 100644 (file)
@@ -322,7 +322,7 @@ config BLK_DEV_UB
          If unsure, say N.
 
 config BLK_DEV_RAM
-       tristate "RAM disk support"
+       tristate "RAM block device support"
        ---help---
          Saying Y here will allow you to use a portion of your RAM memory as
          a block device, so that you can make file systems on it, read and
@@ -357,15 +357,15 @@ config BLK_DEV_RAM_SIZE
          The default value is 4096 kilobytes. Only change this if you know
          what you are doing.
 
-config BLK_DEV_RAM_BLOCKSIZE
-       int "Default RAM disk block size (bytes)"
+config BLK_DEV_XIP
+       bool "Support XIP filesystems on RAM block device"
        depends on BLK_DEV_RAM
-       default "1024"
+       default n
        help
-         The default value is 1024 bytes.  PAGE_SIZE is a much more
-         efficient choice however.  The default is kept to ensure initrd
-         setups function - apparently needed by the rd_load_image routine
-         that supposes the filesystem in the image uses a 1024 blocksize.
+         Support XIP filesystems (such as ext2 with XIP support on) on
+         top of block ram device. This will slightly enlarge the kernel, and
+         will prevent RAM block device backing store memory from being
+         allocated from highmem (only a problem for highmem systems).
 
 config CDROM_PKTCDVD
        tristate "Packet writing on CD/DVD media"
index 7691505a2e12ee8621d93a5c0b78f3a4b8e6dcc1..01c972415cb29c8ed5fcfae76972d622e4833b0c 100644 (file)
@@ -11,7 +11,7 @@ obj-$(CONFIG_AMIGA_FLOPPY)    += amiflop.o
 obj-$(CONFIG_PS3_DISK)         += ps3disk.o
 obj-$(CONFIG_ATARI_FLOPPY)     += ataflop.o
 obj-$(CONFIG_AMIGA_Z2RAM)      += z2ram.o
-obj-$(CONFIG_BLK_DEV_RAM)      += rd.o
+obj-$(CONFIG_BLK_DEV_RAM)      += brd.o
 obj-$(CONFIG_BLK_DEV_LOOP)     += loop.o
 obj-$(CONFIG_BLK_DEV_PS2)      += ps2esdi.o
 obj-$(CONFIG_BLK_DEV_XD)       += xd.o
index 07f02f855ab5562e8faea4600ebd28fc92145d4a..280e71ee744ca659e164cdb0d266b11efb3383ba 100644 (file)
@@ -1,5 +1,5 @@
-/* Copyright (c) 2006 Coraid, Inc.  See COPYING for GPL terms. */
-#define VERSION "32"
+/* Copyright (c) 2007 Coraid, Inc.  See COPYING for GPL terms. */
+#define VERSION "47"
 #define AOE_MAJOR 152
 #define DEVICE_NAME "aoe"
 
@@ -76,10 +76,8 @@ enum {
        DEVFL_EXT = (1<<2),     /* device accepts lba48 commands */
        DEVFL_CLOSEWAIT = (1<<3), /* device is waiting for all closes to revalidate */
        DEVFL_GDALLOC = (1<<4), /* need to alloc gendisk */
-       DEVFL_PAUSE = (1<<5),
+       DEVFL_KICKME = (1<<5),  /* slow polling network card catch */
        DEVFL_NEWSIZE = (1<<6), /* need to update dev size in block layer */
-       DEVFL_MAXBCNT = (1<<7), /* d->maxbcnt is not changeable */
-       DEVFL_KICKME = (1<<8),
 
        BUFFL_FAIL = 1,
 };
@@ -88,17 +86,25 @@ enum {
        DEFAULTBCNT = 2 * 512,  /* 2 sectors */
        NPERSHELF = 16,         /* number of slots per shelf address */
        FREETAG = -1,
-       MIN_BUFS = 8,
+       MIN_BUFS = 16,
+       NTARGETS = 8,
+       NAOEIFS = 8,
+       NSKBPOOLMAX = 128,
+
+       TIMERTICK = HZ / 10,
+       MINTIMER = HZ >> 2,
+       MAXTIMER = HZ << 1,
+       HELPWAIT = 20,
 };
 
 struct buf {
        struct list_head bufs;
-       ulong start_time;       /* for disk stats */
+       ulong stime;    /* for disk stats */
        ulong flags;
        ulong nframesout;
-       char *bufaddr;
        ulong resid;
        ulong bv_resid;
+       ulong bv_off;
        sector_t sector;
        struct bio *bio;
        struct bio_vec *bv;
@@ -114,19 +120,38 @@ struct frame {
        struct sk_buff *skb;
 };
 
+struct aoeif {
+       struct net_device *nd;
+       unsigned char lost;
+       unsigned char lostjumbo;
+       ushort maxbcnt;
+};
+
+struct aoetgt {
+       unsigned char addr[6];
+       ushort nframes;
+       struct frame *frames;
+       struct aoeif ifs[NAOEIFS];
+       struct aoeif *ifp;      /* current aoeif in use */
+       ushort nout;
+       ushort maxout;
+       u16 lasttag;            /* last tag sent */
+       u16 useme;
+       ulong lastwadj;         /* last window adjustment */
+       int wpkts, rpkts;
+       int dataref;
+};
+
 struct aoedev {
        struct aoedev *next;
-       unsigned char addr[6];  /* remote mac addr */
-       ushort flags;
        ulong sysminor;
        ulong aoemajor;
-       ulong aoeminor;
+       u16 aoeminor;
+       u16 flags;
        u16 nopen;              /* (bd_openers isn't available without sleeping) */
-       u16 lasttag;            /* last tag sent */
        u16 rttavg;             /* round trip average of requests/responses */
        u16 mintimer;
        u16 fw_ver;             /* version of blade's firmware */
-       u16 maxbcnt;
        struct work_struct work;/* disk create work struct */
        struct gendisk *gd;
        struct request_queue blkq;
@@ -134,15 +159,17 @@ struct aoedev {
        sector_t ssize;
        struct timer_list timer;
        spinlock_t lock;
-       struct net_device *ifp; /* interface ed is attached to */
        struct sk_buff *sendq_hd; /* packets needing to be sent, list head */
        struct sk_buff *sendq_tl;
+       struct sk_buff *skbpool_hd;
+       struct sk_buff *skbpool_tl;
+       int nskbpool;
        mempool_t *bufpool;     /* for deadlock-free Buf allocation */
        struct list_head bufq;  /* queue of bios to work on */
        struct buf *inprocess;  /* the one we're currently working on */
-       ushort lostjumbo;
-       ushort nframes;         /* number of frames below */
-       struct frame *frames;
+       struct aoetgt *targets[NTARGETS];
+       struct aoetgt **tgt;    /* target in use when working */
+       struct aoetgt **htgt;   /* target needing rexmit assistance */
 };
 
 
@@ -160,14 +187,16 @@ void aoecmd_cfg(ushort aoemajor, unsigned char aoeminor);
 void aoecmd_ata_rsp(struct sk_buff *);
 void aoecmd_cfg_rsp(struct sk_buff *);
 void aoecmd_sleepwork(struct work_struct *);
-struct sk_buff *new_skb(ulong);
+void aoecmd_cleanslate(struct aoedev *);
+struct sk_buff *aoecmd_ata_id(struct aoedev *);
 
 int aoedev_init(void);
 void aoedev_exit(void);
 struct aoedev *aoedev_by_aoeaddr(int maj, int min);
-struct aoedev *aoedev_by_sysminor_m(ulong sysminor, ulong bufcnt);
+struct aoedev *aoedev_by_sysminor_m(ulong sysminor);
 void aoedev_downdev(struct aoedev *d);
 int aoedev_isbusy(struct aoedev *d);
+int aoedev_flush(const char __user *str, size_t size);
 
 int aoenet_init(void);
 void aoenet_exit(void);
@@ -175,4 +204,4 @@ void aoenet_xmit(struct sk_buff *);
 int is_aoe_netif(struct net_device *ifp);
 int set_aoe_iflist(const char __user *str, size_t size);
 
-u64 mac_addr(char addr[6]);
+unsigned long long mac_addr(char addr[6]);
index 826d12381e21f546c099be3079604ca5412868f0..0c39782b26600f5d89d83e3f38c964aac9a28fbd 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006 Coraid, Inc.  See COPYING for GPL terms. */
+/* Copyright (c) 2007 Coraid, Inc.  See COPYING for GPL terms. */
 /*
  * aoeblk.c
  * block device routines
@@ -24,7 +24,7 @@ static ssize_t aoedisk_show_state(struct device *dev,
        return snprintf(page, PAGE_SIZE,
                        "%s%s\n",
                        (d->flags & DEVFL_UP) ? "up" : "down",
-                       (d->flags & DEVFL_PAUSE) ? ",paused" :
+                       (d->flags & DEVFL_KICKME) ? ",kickme" :
                        (d->nopen && !(d->flags & DEVFL_UP)) ? ",closewait" : "");
        /* I'd rather see nopen exported so we can ditch closewait */
 }
@@ -33,17 +33,48 @@ static ssize_t aoedisk_show_mac(struct device *dev,
 {
        struct gendisk *disk = dev_to_disk(dev);
        struct aoedev *d = disk->private_data;
+       struct aoetgt *t = d->targets[0];
 
-       return snprintf(page, PAGE_SIZE, "%012llx\n",
-                       (unsigned long long)mac_addr(d->addr));
+       if (t == NULL)
+               return snprintf(page, PAGE_SIZE, "none\n");
+       return snprintf(page, PAGE_SIZE, "%012llx\n", mac_addr(t->addr));
 }
 static ssize_t aoedisk_show_netif(struct device *dev,
                                  struct device_attribute *attr, char *page)
 {
        struct gendisk *disk = dev_to_disk(dev);
        struct aoedev *d = disk->private_data;
+       struct net_device *nds[8], **nd, **nnd, **ne;
+       struct aoetgt **t, **te;
+       struct aoeif *ifp, *e;
+       char *p;
+
+       memset(nds, 0, sizeof nds);
+       nd = nds;
+       ne = nd + ARRAY_SIZE(nds);
+       t = d->targets;
+       te = t + NTARGETS;
+       for (; t < te && *t; t++) {
+               ifp = (*t)->ifs;
+               e = ifp + NAOEIFS;
+               for (; ifp < e && ifp->nd; ifp++) {
+                       for (nnd = nds; nnd < nd; nnd++)
+                               if (*nnd == ifp->nd)
+                                       break;
+                       if (nnd == nd && nd != ne)
+                               *nd++ = ifp->nd;
+               }
+       }
 
-       return snprintf(page, PAGE_SIZE, "%s\n", d->ifp->name);
+       ne = nd;
+       nd = nds;
+       if (*nd == NULL)
+               return snprintf(page, PAGE_SIZE, "none\n");
+       for (p = page; nd < ne; nd++)
+               p += snprintf(p, PAGE_SIZE - (p-page), "%s%s",
+                       p == page ? "" : ",", (*nd)->name);
+       p += snprintf(p, PAGE_SIZE - (p-page), "\n");
+       return p-page;
 }
 /* firmware version */
 static ssize_t aoedisk_show_fwver(struct device *dev,
@@ -134,7 +165,23 @@ aoeblk_make_request(struct request_queue *q, struct bio *bio)
 
        blk_queue_bounce(q, &bio);
 
+       if (bio == NULL) {
+               printk(KERN_ERR "aoe: bio is NULL\n");
+               BUG();
+               return 0;
+       }
        d = bio->bi_bdev->bd_disk->private_data;
+       if (d == NULL) {
+               printk(KERN_ERR "aoe: bd_disk->private_data is NULL\n");
+               BUG();
+               bio_endio(bio, -ENXIO);
+               return 0;
+       } else if (bio->bi_io_vec == NULL) {
+               printk(KERN_ERR "aoe: bi_io_vec is NULL\n");
+               BUG();
+               bio_endio(bio, -ENXIO);
+               return 0;
+       }
        buf = mempool_alloc(d->bufpool, GFP_NOIO);
        if (buf == NULL) {
                printk(KERN_INFO "aoe: buf allocation failure\n");
@@ -143,19 +190,19 @@ aoeblk_make_request(struct request_queue *q, struct bio *bio)
        }
        memset(buf, 0, sizeof(*buf));
        INIT_LIST_HEAD(&buf->bufs);
-       buf->start_time = jiffies;
+       buf->stime = jiffies;
        buf->bio = bio;
        buf->resid = bio->bi_size;
        buf->sector = bio->bi_sector;
        buf->bv = &bio->bi_io_vec[bio->bi_idx];
-       WARN_ON(buf->bv->bv_len == 0);
        buf->bv_resid = buf->bv->bv_len;
-       buf->bufaddr = page_address(buf->bv->bv_page) + buf->bv->bv_offset;
+       WARN_ON(buf->bv_resid == 0);
+       buf->bv_off = buf->bv->bv_offset;
 
        spin_lock_irqsave(&d->lock, flags);
 
        if ((d->flags & DEVFL_UP) == 0) {
-               printk(KERN_INFO "aoe: device %ld.%ld is not up\n",
+               printk(KERN_INFO "aoe: device %ld.%d is not up\n",
                        d->aoemajor, d->aoeminor);
                spin_unlock_irqrestore(&d->lock, flags);
                mempool_free(buf, d->bufpool);
@@ -208,14 +255,15 @@ aoeblk_gdalloc(void *vp)
 
        gd = alloc_disk(AOE_PARTITIONS);
        if (gd == NULL) {
-               printk(KERN_ERR "aoe: cannot allocate disk structure for %ld.%ld\n",
+               printk(KERN_ERR
+                       "aoe: cannot allocate disk structure for %ld.%d\n",
                        d->aoemajor, d->aoeminor);
                goto err;
        }
 
        d->bufpool = mempool_create_slab_pool(MIN_BUFS, buf_pool_cache);
        if (d->bufpool == NULL) {
-               printk(KERN_ERR "aoe: cannot allocate bufpool for %ld.%ld\n",
+               printk(KERN_ERR "aoe: cannot allocate bufpool for %ld.%d\n",
                        d->aoemajor, d->aoeminor);
                goto err_disk;
        }
@@ -229,7 +277,7 @@ aoeblk_gdalloc(void *vp)
        gd->fops = &aoe_bdops;
        gd->private_data = d;
        gd->capacity = d->ssize;
-       snprintf(gd->disk_name, sizeof gd->disk_name, "etherd/e%ld.%ld",
+       snprintf(gd->disk_name, sizeof gd->disk_name, "etherd/e%ld.%d",
                d->aoemajor, d->aoeminor);
 
        gd->queue = &d->blkq;
index d5480e34cb22fbc27b88275a3cfec71ca3714484..e8e60e7a2e70eb31b17670537dc3291283d9f408 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006 Coraid, Inc.  See COPYING for GPL terms. */
+/* Copyright (c) 2007 Coraid, Inc.  See COPYING for GPL terms. */
 /*
  * aoechr.c
  * AoE character device driver
@@ -6,6 +6,7 @@
 
 #include <linux/hdreg.h>
 #include <linux/blkdev.h>
+#include <linux/delay.h>
 #include "aoe.h"
 
 enum {
@@ -14,6 +15,7 @@ enum {
        MINOR_DISCOVER,
        MINOR_INTERFACES,
        MINOR_REVALIDATE,
+       MINOR_FLUSH,
        MSGSZ = 2048,
        NMSG = 100,             /* message backlog to retain */
 };
@@ -42,6 +44,7 @@ static struct aoe_chardev chardevs[] = {
        { MINOR_DISCOVER, "discover" },
        { MINOR_INTERFACES, "interfaces" },
        { MINOR_REVALIDATE, "revalidate" },
+       { MINOR_FLUSH, "flush" },
 };
 
 static int
@@ -68,6 +71,7 @@ revalidate(const char __user *str, size_t size)
        int major, minor, n;
        ulong flags;
        struct aoedev *d;
+       struct sk_buff *skb;
        char buf[16];
 
        if (size >= sizeof buf)
@@ -85,13 +89,20 @@ revalidate(const char __user *str, size_t size)
        d = aoedev_by_aoeaddr(major, minor);
        if (!d)
                return -EINVAL;
-
        spin_lock_irqsave(&d->lock, flags);
-       d->flags &= ~DEVFL_MAXBCNT;
-       d->flags |= DEVFL_PAUSE;
+       aoecmd_cleanslate(d);
+loop:
+       skb = aoecmd_ata_id(d);
        spin_unlock_irqrestore(&d->lock, flags);
+       /* try again if we are able to sleep a bit,
+        * otherwise give up this revalidation
+        */
+       if (!skb && !msleep_interruptible(200)) {
+               spin_lock_irqsave(&d->lock, flags);
+               goto loop;
+       }
+       aoenet_xmit(skb);
        aoecmd_cfg(major, minor);
-
        return 0;
 }
 
@@ -149,6 +160,9 @@ aoechr_write(struct file *filp, const char __user *buf, size_t cnt, loff_t *offp
                break;
        case MINOR_REVALIDATE:
                ret = revalidate(buf, cnt);
+               break;
+       case MINOR_FLUSH:
+               ret = aoedev_flush(buf, cnt);
        }
        if (ret == 0)
                ret = cnt;
@@ -185,52 +199,51 @@ aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off)
        ulong flags;
 
        n = (unsigned long) filp->private_data;
-       switch (n) {
-       case MINOR_ERR:
-               spin_lock_irqsave(&emsgs_lock, flags);
-loop:
-               em = emsgs + emsgs_head_idx;
-               if ((em->flags & EMFL_VALID) == 0) {
-                       if (filp->f_flags & O_NDELAY) {
-                               spin_unlock_irqrestore(&emsgs_lock, flags);
-                               return -EAGAIN;
-                       }
-                       nblocked_emsgs_readers++;
+       if (n != MINOR_ERR)
+               return -EFAULT;
+
+       spin_lock_irqsave(&emsgs_lock, flags);
 
+       for (;;) {
+               em = emsgs + emsgs_head_idx;
+               if ((em->flags & EMFL_VALID) != 0)
+                       break;
+               if (filp->f_flags & O_NDELAY) {
                        spin_unlock_irqrestore(&emsgs_lock, flags);
+                       return -EAGAIN;
+               }
+               nblocked_emsgs_readers++;
 
-                       n = down_interruptible(&emsgs_sema);
+               spin_unlock_irqrestore(&emsgs_lock, flags);
+
+               n = down_interruptible(&emsgs_sema);
 
-                       spin_lock_irqsave(&emsgs_lock, flags);
+               spin_lock_irqsave(&emsgs_lock, flags);
 
-                       nblocked_emsgs_readers--;
+               nblocked_emsgs_readers--;
 
-                       if (n) {
-                               spin_unlock_irqrestore(&emsgs_lock, flags);
-                               return -ERESTARTSYS;
-                       }
-                       goto loop;
-               }
-               if (em->len > cnt) {
+               if (n) {
                        spin_unlock_irqrestore(&emsgs_lock, flags);
-                       return -EAGAIN;
+                       return -ERESTARTSYS;
                }
-               mp = em->msg;
-               len = em->len;
-               em->msg = NULL;
-               em->flags &= ~EMFL_VALID;
+       }
+       if (em->len > cnt) {
+               spin_unlock_irqrestore(&emsgs_lock, flags);
+               return -EAGAIN;
+       }
+       mp = em->msg;
+       len = em->len;
+       em->msg = NULL;
+       em->flags &= ~EMFL_VALID;
 
-               emsgs_head_idx++;
-               emsgs_head_idx %= ARRAY_SIZE(emsgs);
+       emsgs_head_idx++;
+       emsgs_head_idx %= ARRAY_SIZE(emsgs);
 
-               spin_unlock_irqrestore(&emsgs_lock, flags);
+       spin_unlock_irqrestore(&emsgs_lock, flags);
 
-               n = copy_to_user(buf, mp, len);
-               kfree(mp);
-               return n == 0 ? len : -EFAULT;
-       default:
-               return -EFAULT;
-       }
+       n = copy_to_user(buf, mp, len);
+       kfree(mp);
+       return n == 0 ? len : -EFAULT;
 }
 
 static const struct file_operations aoe_fops = {
index 4d59d5057734ab41686a37a7abb148ab361ee285..44beb17e8090cbd1bf20953e0e1f604a1d5e3e06 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006 Coraid, Inc.  See COPYING for GPL terms. */
+/* Copyright (c) 2007 Coraid, Inc.  See COPYING for GPL terms. */
 /*
  * aoecmd.c
  * Filesystem request handling methods
@@ -9,19 +9,21 @@
 #include <linux/skbuff.h>
 #include <linux/netdevice.h>
 #include <linux/genhd.h>
+#include <linux/moduleparam.h>
 #include <net/net_namespace.h>
 #include <asm/unaligned.h>
 #include "aoe.h"
 
-#define TIMERTICK (HZ / 10)
-#define MINTIMER (2 * TIMERTICK)
-#define MAXTIMER (HZ << 1)
-
 static int aoe_deadsecs = 60 * 3;
 module_param(aoe_deadsecs, int, 0644);
 MODULE_PARM_DESC(aoe_deadsecs, "After aoe_deadsecs seconds, give up and fail dev.");
 
-struct sk_buff *
+static int aoe_maxout = 16;
+module_param(aoe_maxout, int, 0644);
+MODULE_PARM_DESC(aoe_maxout,
+       "Only aoe_maxout outstanding packets for every MAC on eX.Y.");
+
+static struct sk_buff *
 new_skb(ulong len)
 {
        struct sk_buff *skb;
@@ -43,12 +45,12 @@ new_skb(ulong len)
 }
 
 static struct frame *
-getframe(struct aoedev *d, int tag)
+getframe(struct aoetgt *t, int tag)
 {
        struct frame *f, *e;
 
-       f = d->frames;
-       e = f + d->nframes;
+       f = t->frames;
+       e = f + t->nframes;
        for (; f<e; f++)
                if (f->tag == tag)
                        return f;
@@ -61,21 +63,21 @@ getframe(struct aoedev *d, int tag)
  * This driver reserves tag -1 to mean "unused frame."
  */
 static int
-newtag(struct aoedev *d)
+newtag(struct aoetgt *t)
 {
        register ulong n;
 
        n = jiffies & 0xffff;
-       return n |= (++d->lasttag & 0x7fff) << 16;
+       return n |= (++t->lasttag & 0x7fff) << 16;
 }
 
 static int
-aoehdr_atainit(struct aoedev *d, struct aoe_hdr *h)
+aoehdr_atainit(struct aoedev *d, struct aoetgt *t, struct aoe_hdr *h)
 {
-       u32 host_tag = newtag(d);
+       u32 host_tag = newtag(t);
 
-       memcpy(h->src, d->ifp->dev_addr, sizeof h->src);
-       memcpy(h->dst, d->addr, sizeof h->dst);
+       memcpy(h->src, t->ifp->nd->dev_addr, sizeof h->src);
+       memcpy(h->dst, t->addr, sizeof h->dst);
        h->type = __constant_cpu_to_be16(ETH_P_AOE);
        h->verfl = AOE_HVER;
        h->major = cpu_to_be16(d->aoemajor);
@@ -98,42 +100,162 @@ put_lba(struct aoe_atahdr *ah, sector_t lba)
 }
 
 static void
-aoecmd_ata_rw(struct aoedev *d, struct frame *f)
+ifrotate(struct aoetgt *t)
+{
+       t->ifp++;
+       if (t->ifp >= &t->ifs[NAOEIFS] || t->ifp->nd == NULL)
+               t->ifp = t->ifs;
+       if (t->ifp->nd == NULL) {
+               printk(KERN_INFO "aoe: no interface to rotate to\n");
+               BUG();
+       }
+}
+
+static void
+skb_pool_put(struct aoedev *d, struct sk_buff *skb)
+{
+       if (!d->skbpool_hd)
+               d->skbpool_hd = skb;
+       else
+               d->skbpool_tl->next = skb;
+       d->skbpool_tl = skb;
+}
+
+static struct sk_buff *
+skb_pool_get(struct aoedev *d)
+{
+       struct sk_buff *skb;
+
+       skb = d->skbpool_hd;
+       if (skb && atomic_read(&skb_shinfo(skb)->dataref) == 1) {
+               d->skbpool_hd = skb->next;
+               skb->next = NULL;
+               return skb;
+       }
+       if (d->nskbpool < NSKBPOOLMAX
+       && (skb = new_skb(ETH_ZLEN))) {
+               d->nskbpool++;
+               return skb;
+       }
+       return NULL;
+}
+
+/* freeframe is where we do our load balancing so it's a little hairy. */
+static struct frame *
+freeframe(struct aoedev *d)
+{
+       struct frame *f, *e, *rf;
+       struct aoetgt **t;
+       struct sk_buff *skb;
+
+       if (d->targets[0] == NULL) {    /* shouldn't happen, but I'm paranoid */
+               printk(KERN_ERR "aoe: NULL TARGETS!\n");
+               return NULL;
+       }
+       t = d->tgt;
+       t++;
+       if (t >= &d->targets[NTARGETS] || !*t)
+               t = d->targets;
+       for (;;) {
+               if ((*t)->nout < (*t)->maxout
+               && t != d->htgt
+               && (*t)->ifp->nd) {
+                       rf = NULL;
+                       f = (*t)->frames;
+                       e = f + (*t)->nframes;
+                       for (; f < e; f++) {
+                               if (f->tag != FREETAG)
+                                       continue;
+                               skb = f->skb;
+                               if (!skb
+                               && !(f->skb = skb = new_skb(ETH_ZLEN)))
+                                       continue;
+                               if (atomic_read(&skb_shinfo(skb)->dataref)
+                                       != 1) {
+                                       if (!rf)
+                                               rf = f;
+                                       continue;
+                               }
+gotone:                                skb_shinfo(skb)->nr_frags = skb->data_len = 0;
+                               skb_trim(skb, 0);
+                               d->tgt = t;
+                               ifrotate(*t);
+                               return f;
+                       }
+                       /* Work can be done, but the network layer is
+                          holding our precious packets.  Try to grab
+                          one from the pool. */
+                       f = rf;
+                       if (f == NULL) {        /* more paranoia */
+                               printk(KERN_ERR
+                                       "aoe: freeframe: %s.\n",
+                                       "unexpected null rf");
+                               d->flags |= DEVFL_KICKME;
+                               return NULL;
+                       }
+                       skb = skb_pool_get(d);
+                       if (skb) {
+                               skb_pool_put(d, f->skb);
+                               f->skb = skb;
+                               goto gotone;
+                       }
+                       (*t)->dataref++;
+                       if ((*t)->nout == 0)
+                               d->flags |= DEVFL_KICKME;
+               }
+               if (t == d->tgt)        /* we've looped and found nada */
+                       break;
+               t++;
+               if (t >= &d->targets[NTARGETS] || !*t)
+                       t = d->targets;
+       }
+       return NULL;
+}
+
+static int
+aoecmd_ata_rw(struct aoedev *d)
 {
+       struct frame *f;
        struct aoe_hdr *h;
        struct aoe_atahdr *ah;
        struct buf *buf;
+       struct bio_vec *bv;
+       struct aoetgt *t;
        struct sk_buff *skb;
        ulong bcnt;
-       register sector_t sector;
        char writebit, extbit;
 
        writebit = 0x10;
        extbit = 0x4;
 
+       f = freeframe(d);
+       if (f == NULL)
+               return 0;
+       t = *d->tgt;
        buf = d->inprocess;
-
-       sector = buf->sector;
-       bcnt = buf->bv_resid;
-       if (bcnt > d->maxbcnt)
-               bcnt = d->maxbcnt;
-
+       bv = buf->bv;
+       bcnt = t->ifp->maxbcnt;
+       if (bcnt == 0)
+               bcnt = DEFAULTBCNT;
+       if (bcnt > buf->bv_resid)
+               bcnt = buf->bv_resid;
        /* initialize the headers & frame */
        skb = f->skb;
        h = (struct aoe_hdr *) skb_mac_header(skb);
        ah = (struct aoe_atahdr *) (h+1);
        skb_put(skb, sizeof *h + sizeof *ah);
        memset(h, 0, skb->len);
-       f->tag = aoehdr_atainit(d, h);
+       f->tag = aoehdr_atainit(d, t, h);
+       t->nout++;
        f->waited = 0;
        f->buf = buf;
-       f->bufaddr = buf->bufaddr;
+       f->bufaddr = page_address(bv->bv_page) + buf->bv_off;
        f->bcnt = bcnt;
-       f->lba = sector;
+       f->lba = buf->sector;
 
        /* set up ata header */
        ah->scnt = bcnt >> 9;
-       put_lba(ah, sector);
+       put_lba(ah, buf->sector);
        if (d->flags & DEVFL_EXT) {
                ah->aflags |= AOEAFL_EXT;
        } else {
@@ -141,14 +263,14 @@ aoecmd_ata_rw(struct aoedev *d, struct frame *f)
                ah->lba3 &= 0x0f;
                ah->lba3 |= 0xe0;       /* LBA bit + obsolete 0xa0 */
        }
-
        if (bio_data_dir(buf->bio) == WRITE) {
-               skb_fill_page_desc(skb, 0, virt_to_page(f->bufaddr),
-                       offset_in_page(f->bufaddr), bcnt);
+               skb_fill_page_desc(skb, 0, bv->bv_page, buf->bv_off, bcnt);
                ah->aflags |= AOEAFL_WRITE;
                skb->len += bcnt;
                skb->data_len = bcnt;
+               t->wpkts++;
        } else {
+               t->rpkts++;
                writebit = 0;
        }
 
@@ -156,29 +278,29 @@ aoecmd_ata_rw(struct aoedev *d, struct frame *f)
 
        /* mark all tracking fields and load out */
        buf->nframesout += 1;
-       buf->bufaddr += bcnt;
+       buf->bv_off += bcnt;
        buf->bv_resid -= bcnt;
-/* printk(KERN_DEBUG "aoe: bv_resid=%ld\n", buf->bv_resid); */
        buf->resid -= bcnt;
        buf->sector += bcnt >> 9;
        if (buf->resid == 0) {
                d->inprocess = NULL;
        } else if (buf->bv_resid == 0) {
-               buf->bv++;
-               WARN_ON(buf->bv->bv_len == 0);
-               buf->bv_resid = buf->bv->bv_len;
-               buf->bufaddr = page_address(buf->bv->bv_page) + buf->bv->bv_offset;
+               buf->bv = ++bv;
+               buf->bv_resid = bv->bv_len;
+               WARN_ON(buf->bv_resid == 0);
+               buf->bv_off = bv->bv_offset;
        }
 
-       skb->dev = d->ifp;
+       skb->dev = t->ifp->nd;
        skb = skb_clone(skb, GFP_ATOMIC);
-       if (skb == NULL)
-               return;
-       if (d->sendq_hd)
-               d->sendq_tl->next = skb;
-       else
-               d->sendq_hd = skb;
-       d->sendq_tl = skb;
+       if (skb) {
+               if (d->sendq_hd)
+                       d->sendq_tl->next = skb;
+               else
+                       d->sendq_hd = skb;
+               d->sendq_tl = skb;
+       }
+       return 1;
 }
 
 /* some callers cannot sleep, and they can call this function,
@@ -232,62 +354,8 @@ cont:
        return sl;
 }
 
-static struct frame *
-freeframe(struct aoedev *d)
-{
-       struct frame *f, *e;
-       int n = 0;
-
-       f = d->frames;
-       e = f + d->nframes;
-       for (; f<e; f++) {
-               if (f->tag != FREETAG)
-                       continue;
-               if (atomic_read(&skb_shinfo(f->skb)->dataref) == 1) {
-                       skb_shinfo(f->skb)->nr_frags = f->skb->data_len = 0;
-                       skb_trim(f->skb, 0);
-                       return f;
-               }
-               n++;
-       }
-       if (n == d->nframes)    /* wait for network layer */
-               d->flags |= DEVFL_KICKME;
-
-       return NULL;
-}
-
-/* enters with d->lock held */
-void
-aoecmd_work(struct aoedev *d)
-{
-       struct frame *f;
-       struct buf *buf;
-
-       if (d->flags & DEVFL_PAUSE) {
-               if (!aoedev_isbusy(d))
-                       d->sendq_hd = aoecmd_cfg_pkts(d->aoemajor,
-                                               d->aoeminor, &d->sendq_tl);
-               return;
-       }
-
-loop:
-       f = freeframe(d);
-       if (f == NULL)
-               return;
-       if (d->inprocess == NULL) {
-               if (list_empty(&d->bufq))
-                       return;
-               buf = container_of(d->bufq.next, struct buf, bufs);
-               list_del(d->bufq.next);
-/*printk(KERN_DEBUG "aoe: bi_size=%ld\n", buf->bio->bi_size); */
-               d->inprocess = buf;
-       }
-       aoecmd_ata_rw(d, f);
-       goto loop;
-}
-
 static void
-rexmit(struct aoedev *d, struct frame *f)
+resend(struct aoedev *d, struct aoetgt *t, struct frame *f)
 {
        struct sk_buff *skb;
        struct aoe_hdr *h;
@@ -295,41 +363,46 @@ rexmit(struct aoedev *d, struct frame *f)
        char buf[128];
        u32 n;
 
-       n = newtag(d);
+       ifrotate(t);
+       n = newtag(t);
+       skb = f->skb;
+       h = (struct aoe_hdr *) skb_mac_header(skb);
+       ah = (struct aoe_atahdr *) (h+1);
 
        snprintf(buf, sizeof buf,
-               "%15s e%ld.%ld oldtag=%08x@%08lx newtag=%08x\n",
-               "retransmit",
-               d->aoemajor, d->aoeminor, f->tag, jiffies, n);
+               "%15s e%ld.%d oldtag=%08x@%08lx newtag=%08x "
+               "s=%012llx d=%012llx nout=%d\n",
+               "retransmit", d->aoemajor, d->aoeminor, f->tag, jiffies, n,
+               mac_addr(h->src),
+               mac_addr(h->dst), t->nout);
        aoechr_error(buf);
 
-       skb = f->skb;
-       h = (struct aoe_hdr *) skb_mac_header(skb);
-       ah = (struct aoe_atahdr *) (h+1);
        f->tag = n;
        h->tag = cpu_to_be32(n);
-       memcpy(h->dst, d->addr, sizeof h->dst);
-       memcpy(h->src, d->ifp->dev_addr, sizeof h->src);
-
-       n = DEFAULTBCNT / 512;
-       if (ah->scnt > n) {
-               ah->scnt = n;
+       memcpy(h->dst, t->addr, sizeof h->dst);
+       memcpy(h->src, t->ifp->nd->dev_addr, sizeof h->src);
+
+       switch (ah->cmdstat) {
+       default:
+               break;
+       case WIN_READ:
+       case WIN_READ_EXT:
+       case WIN_WRITE:
+       case WIN_WRITE_EXT:
+               put_lba(ah, f->lba);
+
+               n = f->bcnt;
+               if (n > DEFAULTBCNT)
+                       n = DEFAULTBCNT;
+               ah->scnt = n >> 9;
                if (ah->aflags & AOEAFL_WRITE) {
                        skb_fill_page_desc(skb, 0, virt_to_page(f->bufaddr),
-                               offset_in_page(f->bufaddr), DEFAULTBCNT);
-                       skb->len = sizeof *h + sizeof *ah + DEFAULTBCNT;
-                       skb->data_len = DEFAULTBCNT;
-               }
-               if (++d->lostjumbo > (d->nframes << 1))
-               if (d->maxbcnt != DEFAULTBCNT) {
-                       printk(KERN_INFO "aoe: e%ld.%ld: too many lost jumbo on %s - using 1KB frames.\n",
-                               d->aoemajor, d->aoeminor, d->ifp->name);
-                       d->maxbcnt = DEFAULTBCNT;
-                       d->flags |= DEVFL_MAXBCNT;
+                               offset_in_page(f->bufaddr), n);
+                       skb->len = sizeof *h + sizeof *ah + n;
+                       skb->data_len = n;
                }
        }
-
-       skb->dev = d->ifp;
+       skb->dev = t->ifp->nd;
        skb = skb_clone(skb, GFP_ATOMIC);
        if (skb == NULL)
                return;
@@ -352,10 +425,92 @@ tsince(int tag)
        return n;
 }
 
+static struct aoeif *
+getif(struct aoetgt *t, struct net_device *nd)
+{
+       struct aoeif *p, *e;
+
+       p = t->ifs;
+       e = p + NAOEIFS;
+       for (; p < e; p++)
+               if (p->nd == nd)
+                       return p;
+       return NULL;
+}
+
+static struct aoeif *
+addif(struct aoetgt *t, struct net_device *nd)
+{
+       struct aoeif *p;
+
+       p = getif(t, NULL);
+       if (!p)
+               return NULL;
+       p->nd = nd;
+       p->maxbcnt = DEFAULTBCNT;
+       p->lost = 0;
+       p->lostjumbo = 0;
+       return p;
+}
+
+static void
+ejectif(struct aoetgt *t, struct aoeif *ifp)
+{
+       struct aoeif *e;
+       ulong n;
+
+       e = t->ifs + NAOEIFS - 1;
+       n = (e - ifp) * sizeof *ifp;
+       memmove(ifp, ifp+1, n);
+       e->nd = NULL;
+}
+
+static int
+sthtith(struct aoedev *d)
+{
+       struct frame *f, *e, *nf;
+       struct sk_buff *skb;
+       struct aoetgt *ht = *d->htgt;
+
+       f = ht->frames;
+       e = f + ht->nframes;
+       for (; f < e; f++) {
+               if (f->tag == FREETAG)
+                       continue;
+               nf = freeframe(d);
+               if (!nf)
+                       return 0;
+               skb = nf->skb;
+               *nf = *f;
+               f->skb = skb;
+               f->tag = FREETAG;
+               nf->waited = 0;
+               ht->nout--;
+               (*d->tgt)->nout++;
+               resend(d, *d->tgt, nf);
+       }
+       /* he's clean, he's useless.  take away his interfaces */
+       memset(ht->ifs, 0, sizeof ht->ifs);
+       d->htgt = NULL;
+       return 1;
+}
+
+static inline unsigned char
+ata_scnt(unsigned char *packet) {
+       struct aoe_hdr *h;
+       struct aoe_atahdr *ah;
+
+       h = (struct aoe_hdr *) packet;
+       ah = (struct aoe_atahdr *) (h+1);
+       return ah->scnt;
+}
+
 static void
 rexmit_timer(ulong vp)
 {
        struct aoedev *d;
+       struct aoetgt *t, **tt, **te;
+       struct aoeif *ifp;
        struct frame *f, *e;
        struct sk_buff *sl;
        register long timeout;
@@ -374,31 +529,79 @@ rexmit_timer(ulong vp)
                spin_unlock_irqrestore(&d->lock, flags);
                return;
        }
-       f = d->frames;
-       e = f + d->nframes;
-       for (; f<e; f++) {
-               if (f->tag != FREETAG && tsince(f->tag) >= timeout) {
+       tt = d->targets;
+       te = tt + NTARGETS;
+       for (; tt < te && *tt; tt++) {
+               t = *tt;
+               f = t->frames;
+               e = f + t->nframes;
+               for (; f < e; f++) {
+                       if (f->tag == FREETAG
+                       || tsince(f->tag) < timeout)
+                               continue;
                        n = f->waited += timeout;
                        n /= HZ;
-                       if (n > aoe_deadsecs) { /* waited too long for response */
+                       if (n > aoe_deadsecs) {
+                               /* waited too long.  device failure. */
                                aoedev_downdev(d);
                                break;
                        }
-                       rexmit(d, f);
+
+                       if (n > HELPWAIT /* see if another target can help */
+                       && (tt != d->targets || d->targets[1]))
+                               d->htgt = tt;
+
+                       if (t->nout == t->maxout) {
+                               if (t->maxout > 1)
+                                       t->maxout--;
+                               t->lastwadj = jiffies;
+                       }
+
+                       ifp = getif(t, f->skb->dev);
+                       if (ifp && ++ifp->lost > (t->nframes << 1)
+                       && (ifp != t->ifs || t->ifs[1].nd)) {
+                               ejectif(t, ifp);
+                               ifp = NULL;
+                       }
+
+                       if (ata_scnt(skb_mac_header(f->skb)) > DEFAULTBCNT / 512
+                       && ifp && ++ifp->lostjumbo > (t->nframes << 1)
+                       && ifp->maxbcnt != DEFAULTBCNT) {
+                               printk(KERN_INFO
+                                       "aoe: e%ld.%d: "
+                                       "too many lost jumbo on "
+                                       "%s:%012llx - "
+                                       "falling back to %d frames.\n",
+                                       d->aoemajor, d->aoeminor,
+                                       ifp->nd->name, mac_addr(t->addr),
+                                       DEFAULTBCNT);
+                               ifp->maxbcnt = 0;
+                       }
+                       resend(d, t, f);
+               }
+
+               /* window check */
+               if (t->nout == t->maxout
+               && t->maxout < t->nframes
+               && (jiffies - t->lastwadj)/HZ > 10) {
+                       t->maxout++;
+                       t->lastwadj = jiffies;
                }
        }
-       if (d->flags & DEVFL_KICKME) {
+
+       if (d->sendq_hd) {
+               n = d->rttavg <<= 1;
+               if (n > MAXTIMER)
+                       d->rttavg = MAXTIMER;
+       }
+
+       if (d->flags & DEVFL_KICKME || d->htgt) {
                d->flags &= ~DEVFL_KICKME;
                aoecmd_work(d);
        }
 
        sl = d->sendq_hd;
        d->sendq_hd = d->sendq_tl = NULL;
-       if (sl) {
-               n = d->rttavg <<= 1;
-               if (n > MAXTIMER)
-                       d->rttavg = MAXTIMER;
-       }
 
        d->timer.expires = jiffies + TIMERTICK;
        add_timer(&d->timer);
@@ -408,6 +611,25 @@ rexmit_timer(ulong vp)
        aoenet_xmit(sl);
 }
 
+/* enters with d->lock held */
+void
+aoecmd_work(struct aoedev *d)
+{
+       struct buf *buf;
+loop:
+       if (d->htgt && !sthtith(d))
+               return;
+       if (d->inprocess == NULL) {
+               if (list_empty(&d->bufq))
+                       return;
+               buf = container_of(d->bufq.next, struct buf, bufs);
+               list_del(d->bufq.next);
+               d->inprocess = buf;
+       }
+       if (aoecmd_ata_rw(d))
+               goto loop;
+}
+
 /* this function performs work that has been deferred until sleeping is OK
  */
 void
@@ -440,7 +662,7 @@ aoecmd_sleepwork(struct work_struct *work)
 }
 
 static void
-ataid_complete(struct aoedev *d, unsigned char *id)
+ataid_complete(struct aoedev *d, struct aoetgt *t, unsigned char *id)
 {
        u64 ssize;
        u16 n;
@@ -475,24 +697,20 @@ ataid_complete(struct aoedev *d, unsigned char *id)
        }
 
        if (d->ssize != ssize)
-               printk(KERN_INFO "aoe: %012llx e%lu.%lu v%04x has %llu sectors\n",
-                       (unsigned long long)mac_addr(d->addr),
+               printk(KERN_INFO
+                       "aoe: %012llx e%ld.%d v%04x has %llu sectors\n",
+                       mac_addr(t->addr),
                        d->aoemajor, d->aoeminor,
                        d->fw_ver, (long long)ssize);
        d->ssize = ssize;
        d->geo.start = 0;
+       if (d->flags & (DEVFL_GDALLOC|DEVFL_NEWSIZE))
+               return;
        if (d->gd != NULL) {
                d->gd->capacity = ssize;
                d->flags |= DEVFL_NEWSIZE;
-       } else {
-               if (d->flags & DEVFL_GDALLOC) {
-                       printk(KERN_ERR "aoe: can't schedule work for e%lu.%lu, %s\n",
-                              d->aoemajor, d->aoeminor,
-                              "it's already on!  This shouldn't happen.\n");
-                       return;
-               }
+       } else
                d->flags |= DEVFL_GDALLOC;
-       }
        schedule_work(&d->work);
 }
 
@@ -519,6 +737,31 @@ calc_rttavg(struct aoedev *d, int rtt)
        d->rttavg += n >> 2;
 }
 
+static struct aoetgt *
+gettgt(struct aoedev *d, char *addr)
+{
+       struct aoetgt **t, **e;
+
+       t = d->targets;
+       e = t + NTARGETS;
+       for (; t < e && *t; t++)
+               if (memcmp((*t)->addr, addr, sizeof((*t)->addr)) == 0)
+                       return *t;
+       return NULL;
+}
+
+static inline void
+diskstats(struct gendisk *disk, struct bio *bio, ulong duration)
+{
+       unsigned long n_sect = bio->bi_size >> 9;
+       const int rw = bio_data_dir(bio);
+
+       disk_stat_inc(disk, ios[rw]);
+       disk_stat_add(disk, ticks[rw], duration);
+       disk_stat_add(disk, sectors[rw], n_sect);
+       disk_stat_add(disk, io_ticks, duration);
+}
+
 void
 aoecmd_ata_rsp(struct sk_buff *skb)
 {
@@ -528,6 +771,8 @@ aoecmd_ata_rsp(struct sk_buff *skb)
        struct frame *f;
        struct buf *buf;
        struct sk_buff *sl;
+       struct aoetgt *t;
+       struct aoeif *ifp;
        register long n;
        ulong flags;
        char ebuf[128];
@@ -547,7 +792,14 @@ aoecmd_ata_rsp(struct sk_buff *skb)
        spin_lock_irqsave(&d->lock, flags);
 
        n = be32_to_cpu(get_unaligned(&hin->tag));
-       f = getframe(d, n);
+       t = gettgt(d, hin->src);
+       if (t == NULL) {
+               printk(KERN_INFO "aoe: can't find target e%ld.%d:%012llx\n",
+                       d->aoemajor, d->aoeminor, mac_addr(hin->src));
+               spin_unlock_irqrestore(&d->lock, flags);
+               return;
+       }
+       f = getframe(t, n);
        if (f == NULL) {
                calc_rttavg(d, -tsince(n));
                spin_unlock_irqrestore(&d->lock, flags);
@@ -569,24 +821,24 @@ aoecmd_ata_rsp(struct sk_buff *skb)
        ahout = (struct aoe_atahdr *) (hout+1);
        buf = f->buf;
 
-       if (ahout->cmdstat == WIN_IDENTIFY)
-               d->flags &= ~DEVFL_PAUSE;
        if (ahin->cmdstat & 0xa9) {     /* these bits cleared on success */
                printk(KERN_ERR
-                       "aoe: ata error cmd=%2.2Xh stat=%2.2Xh from e%ld.%ld\n",
+                       "aoe: ata error cmd=%2.2Xh stat=%2.2Xh from e%ld.%d\n",
                        ahout->cmdstat, ahin->cmdstat,
                        d->aoemajor, d->aoeminor);
                if (buf)
                        buf->flags |= BUFFL_FAIL;
        } else {
+               if (d->htgt && t == *d->htgt) /* I'll help myself, thank you. */
+                       d->htgt = NULL;
                n = ahout->scnt << 9;
                switch (ahout->cmdstat) {
                case WIN_READ:
                case WIN_READ_EXT:
                        if (skb->len - sizeof *hin - sizeof *ahin < n) {
                                printk(KERN_ERR
-                                       "aoe: runt data size in read.  skb->len=%d\n",
-                                       skb->len);
+                                       "aoe: %s.  skb->len=%d need=%ld\n",
+                                       "runt data size in read", skb->len, n);
                                /* fail frame f?  just returning will rexmit. */
                                spin_unlock_irqrestore(&d->lock, flags);
                                return;
@@ -594,32 +846,18 @@ aoecmd_ata_rsp(struct sk_buff *skb)
                        memcpy(f->bufaddr, ahin+1, n);
                case WIN_WRITE:
                case WIN_WRITE_EXT:
+                       ifp = getif(t, skb->dev);
+                       if (ifp) {
+                               ifp->lost = 0;
+                               if (n > DEFAULTBCNT)
+                                       ifp->lostjumbo = 0;
+                       }
                        if (f->bcnt -= n) {
-                               skb = f->skb;
+                               f->lba += n >> 9;
                                f->bufaddr += n;
-                               put_lba(ahout, f->lba += ahout->scnt);
-                               n = f->bcnt;
-                               if (n > DEFAULTBCNT)
-                                       n = DEFAULTBCNT;
-                               ahout->scnt = n >> 9;
-                               if (ahout->aflags & AOEAFL_WRITE) {
-                                       skb_fill_page_desc(skb, 0,
-                                               virt_to_page(f->bufaddr),
-                                               offset_in_page(f->bufaddr), n);
-                                       skb->len = sizeof *hout + sizeof *ahout + n;
-                                       skb->data_len = n;
-                               }
-                               f->tag = newtag(d);
-                               hout->tag = cpu_to_be32(f->tag);
-                               skb->dev = d->ifp;
-                               skb = skb_clone(skb, GFP_ATOMIC);
-                               spin_unlock_irqrestore(&d->lock, flags);
-                               if (skb)
-                                       aoenet_xmit(skb);
-                               return;
+                               resend(d, t, f);
+                               goto xmit;
                        }
-                       if (n > DEFAULTBCNT)
-                               d->lostjumbo = 0;
                        break;
                case WIN_IDENTIFY:
                        if (skb->len - sizeof *hin - sizeof *ahin < 512) {
@@ -629,7 +867,7 @@ aoecmd_ata_rsp(struct sk_buff *skb)
                                spin_unlock_irqrestore(&d->lock, flags);
                                return;
                        }
-                       ataid_complete(d, (char *) (ahin+1));
+                       ataid_complete(d, t, (char *) (ahin+1));
                        break;
                default:
                        printk(KERN_INFO
@@ -640,28 +878,19 @@ aoecmd_ata_rsp(struct sk_buff *skb)
                }
        }
 
-       if (buf) {
-               buf->nframesout -= 1;
-               if (buf->nframesout == 0 && buf->resid == 0) {
-                       unsigned long duration = jiffies - buf->start_time;
-                       unsigned long n_sect = buf->bio->bi_size >> 9;
-                       struct gendisk *disk = d->gd;
-                       const int rw = bio_data_dir(buf->bio);
-
-                       disk_stat_inc(disk, ios[rw]);
-                       disk_stat_add(disk, ticks[rw], duration);
-                       disk_stat_add(disk, sectors[rw], n_sect);
-                       disk_stat_add(disk, io_ticks, duration);
-                       n = (buf->flags & BUFFL_FAIL) ? -EIO : 0;
-                       bio_endio(buf->bio, n);
-                       mempool_free(buf, d->bufpool);
-               }
+       if (buf && --buf->nframesout == 0 && buf->resid == 0) {
+               diskstats(d->gd, buf->bio, jiffies - buf->stime);
+               n = (buf->flags & BUFFL_FAIL) ? -EIO : 0;
+               bio_endio(buf->bio, n);
+               mempool_free(buf, d->bufpool);
        }
 
        f->buf = NULL;
        f->tag = FREETAG;
+       t->nout--;
 
        aoecmd_work(d);
+xmit:
        sl = d->sendq_hd;
        d->sendq_hd = d->sendq_tl = NULL;
 
@@ -679,23 +908,20 @@ aoecmd_cfg(ushort aoemajor, unsigned char aoeminor)
        aoenet_xmit(sl);
 }
  
-/*
- * Since we only call this in one place (and it only prepares one frame)
- * we just return the skb.  Usually we'd chain it up to the aoedev sendq.
- */
-static struct sk_buff *
+struct sk_buff *
 aoecmd_ata_id(struct aoedev *d)
 {
        struct aoe_hdr *h;
        struct aoe_atahdr *ah;
        struct frame *f;
        struct sk_buff *skb;
+       struct aoetgt *t;
 
        f = freeframe(d);
-       if (f == NULL) {
-               printk(KERN_ERR "aoe: can't get a frame. This shouldn't happen.\n");
+       if (f == NULL)
                return NULL;
-       }
+
+       t = *d->tgt;
 
        /* initialize the headers & frame */
        skb = f->skb;
@@ -703,7 +929,8 @@ aoecmd_ata_id(struct aoedev *d)
        ah = (struct aoe_atahdr *) (h+1);
        skb_put(skb, sizeof *h + sizeof *ah);
        memset(h, 0, skb->len);
-       f->tag = aoehdr_atainit(d, h);
+       f->tag = aoehdr_atainit(d, t, h);
+       t->nout++;
        f->waited = 0;
 
        /* set up ata header */
@@ -711,7 +938,7 @@ aoecmd_ata_id(struct aoedev *d)
        ah->cmdstat = WIN_IDENTIFY;
        ah->lba3 = 0xa0;
 
-       skb->dev = d->ifp;
+       skb->dev = t->ifp->nd;
 
        d->rttavg = MAXTIMER;
        d->timer.function = rexmit_timer;
@@ -719,15 +946,52 @@ aoecmd_ata_id(struct aoedev *d)
        return skb_clone(skb, GFP_ATOMIC);
 }
  
+static struct aoetgt *
+addtgt(struct aoedev *d, char *addr, ulong nframes)
+{
+       struct aoetgt *t, **tt, **te;
+       struct frame *f, *e;
+
+       tt = d->targets;
+       te = tt + NTARGETS;
+       for (; tt < te && *tt; tt++)
+               ;
+
+       if (tt == te) {
+               printk(KERN_INFO
+                       "aoe: device addtgt failure; too many targets\n");
+               return NULL;
+       }
+       t = kcalloc(1, sizeof *t, GFP_ATOMIC);
+       f = kcalloc(nframes, sizeof *f, GFP_ATOMIC);
+       if (!t || !f) {
+               kfree(f);
+               kfree(t);
+               printk(KERN_INFO "aoe: cannot allocate memory to add target\n");
+               return NULL;
+       }
+
+       t->nframes = nframes;
+       t->frames = f;
+       e = f + nframes;
+       for (; f < e; f++)
+               f->tag = FREETAG;
+       memcpy(t->addr, addr, sizeof t->addr);
+       t->ifp = t->ifs;
+       t->maxout = t->nframes;
+       return *tt = t;
+}
+
 void
 aoecmd_cfg_rsp(struct sk_buff *skb)
 {
        struct aoedev *d;
        struct aoe_hdr *h;
        struct aoe_cfghdr *ch;
+       struct aoetgt *t;
+       struct aoeif *ifp;
        ulong flags, sysminor, aoemajor;
        struct sk_buff *sl;
-       enum { MAXFRAMES = 16 };
        u16 n;
 
        h = (struct aoe_hdr *) skb_mac_header(skb);
@@ -752,10 +1016,10 @@ aoecmd_cfg_rsp(struct sk_buff *skb)
        }
 
        n = be16_to_cpu(ch->bufcnt);
-       if (n > MAXFRAMES)      /* keep it reasonable */
-               n = MAXFRAMES;
+       if (n > aoe_maxout)     /* keep it reasonable */
+               n = aoe_maxout;
 
-       d = aoedev_by_sysminor_m(sysminor, n);
+       d = aoedev_by_sysminor_m(sysminor);
        if (d == NULL) {
                printk(KERN_INFO "aoe: device sysminor_m failure\n");
                return;
@@ -763,38 +1027,74 @@ aoecmd_cfg_rsp(struct sk_buff *skb)
 
        spin_lock_irqsave(&d->lock, flags);
 
-       /* permit device to migrate mac and network interface */
-       d->ifp = skb->dev;
-       memcpy(d->addr, h->src, sizeof d->addr);
-       if (!(d->flags & DEVFL_MAXBCNT)) {
-               n = d->ifp->mtu;
+       t = gettgt(d, h->src);
+       if (!t) {
+               t = addtgt(d, h->src, n);
+               if (!t) {
+                       spin_unlock_irqrestore(&d->lock, flags);
+                       return;
+               }
+       }
+       ifp = getif(t, skb->dev);
+       if (!ifp) {
+               ifp = addif(t, skb->dev);
+               if (!ifp) {
+                       printk(KERN_INFO
+                               "aoe: device addif failure; "
+                               "too many interfaces?\n");
+                       spin_unlock_irqrestore(&d->lock, flags);
+                       return;
+               }
+       }
+       if (ifp->maxbcnt) {
+               n = ifp->nd->mtu;
                n -= sizeof (struct aoe_hdr) + sizeof (struct aoe_atahdr);
                n /= 512;
                if (n > ch->scnt)
                        n = ch->scnt;
                n = n ? n * 512 : DEFAULTBCNT;
-               if (n != d->maxbcnt) {
+               if (n != ifp->maxbcnt) {
                        printk(KERN_INFO
-                               "aoe: e%ld.%ld: setting %d byte data frames on %s\n",
-                               d->aoemajor, d->aoeminor, n, d->ifp->name);
-                       d->maxbcnt = n;
+                               "aoe: e%ld.%d: setting %d%s%s:%012llx\n",
+                               d->aoemajor, d->aoeminor, n,
+                               " byte data frames on ", ifp->nd->name,
+                               mac_addr(t->addr));
+                       ifp->maxbcnt = n;
                }
        }
 
        /* don't change users' perspective */
-       if (d->nopen && !(d->flags & DEVFL_PAUSE)) {
+       if (d->nopen) {
                spin_unlock_irqrestore(&d->lock, flags);
                return;
        }
-       d->flags |= DEVFL_PAUSE;        /* force pause */
-       d->mintimer = MINTIMER;
        d->fw_ver = be16_to_cpu(ch->fwver);
 
-       /* check for already outstanding ataid */
-       sl = aoedev_isbusy(d) == 0 ? aoecmd_ata_id(d) : NULL;
+       sl = aoecmd_ata_id(d);
 
        spin_unlock_irqrestore(&d->lock, flags);
 
        aoenet_xmit(sl);
 }
 
+void
+aoecmd_cleanslate(struct aoedev *d)
+{
+       struct aoetgt **t, **te;
+       struct aoeif *p, *e;
+
+       d->mintimer = MINTIMER;
+
+       t = d->targets;
+       te = t + NTARGETS;
+       for (; t < te && *t; t++) {
+               (*t)->maxout = (*t)->nframes;
+               p = (*t)->ifs;
+               e = p + NAOEIFS;
+               for (; p < e; p++) {
+                       p->lostjumbo = 0;
+                       p->lost = 0;
+                       p->maxbcnt = DEFAULTBCNT;
+               }
+       }
+}
index 51f50710e5fcf1b6a2755bdf5ff0069447f974fc..f9a1cd9edb77e156e5a7f81c389f26ea21161f41 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006 Coraid, Inc.  See COPYING for GPL terms. */
+/* Copyright (c) 2007 Coraid, Inc.  See COPYING for GPL terms. */
 /*
  * aoedev.c
  * AoE device utility functions; maintains device list.
@@ -7,23 +7,32 @@
 #include <linux/hdreg.h>
 #include <linux/blkdev.h>
 #include <linux/netdevice.h>
+#include <linux/delay.h>
 #include "aoe.h"
 
+static void dummy_timer(ulong);
+static void aoedev_freedev(struct aoedev *);
+static void freetgt(struct aoedev *d, struct aoetgt *t);
+static void skbpoolfree(struct aoedev *d);
+
 static struct aoedev *devlist;
-static spinlock_t devlist_lock;
+static DEFINE_SPINLOCK(devlist_lock);
 
 int
 aoedev_isbusy(struct aoedev *d)
 {
+       struct aoetgt **t, **te;
        struct frame *f, *e;
 
-       f = d->frames;
-       e = f + d->nframes;
-       do {
-               if (f->tag != FREETAG)
-                       return 1;
-       } while (++f < e);
-
+       t = d->targets;
+       te = t + NTARGETS;
+       for (; t < te && *t; t++) {
+               f = (*t)->frames;
+               e = f + (*t)->nframes;
+               for (; f < e; f++)
+                       if (f->tag != FREETAG)
+                               return 1;
+       }
        return 0;
 }
 
@@ -55,75 +64,41 @@ dummy_timer(ulong vp)
        add_timer(&d->timer);
 }
 
-/* called with devlist lock held */
-static struct aoedev *
-aoedev_newdev(ulong nframes)
-{
-       struct aoedev *d;
-       struct frame *f, *e;
-
-       d = kzalloc(sizeof *d, GFP_ATOMIC);
-       f = kcalloc(nframes, sizeof *f, GFP_ATOMIC);
-       switch (!d || !f) {
-       case 0:
-               d->nframes = nframes;
-               d->frames = f;
-               e = f + nframes;
-               for (; f<e; f++) {
-                       f->tag = FREETAG;
-                       f->skb = new_skb(ETH_ZLEN);
-                       if (!f->skb)
-                               break;
-               }
-               if (f == e)
-                       break;
-               while (f > d->frames) {
-                       f--;
-                       dev_kfree_skb(f->skb);
-               }
-       default:
-               if (f)
-                       kfree(f);
-               if (d)
-                       kfree(d);
-               return NULL;
-       }
-       INIT_WORK(&d->work, aoecmd_sleepwork);
-       spin_lock_init(&d->lock);
-       init_timer(&d->timer);
-       d->timer.data = (ulong) d;
-       d->timer.function = dummy_timer;
-       d->timer.expires = jiffies + HZ;
-       add_timer(&d->timer);
-       d->bufpool = NULL;      /* defer to aoeblk_gdalloc */
-       INIT_LIST_HEAD(&d->bufq);
-       d->next = devlist;
-       devlist = d;
-
-       return d;
-}
-
 void
 aoedev_downdev(struct aoedev *d)
 {
+       struct aoetgt **t, **te;
        struct frame *f, *e;
        struct buf *buf;
        struct bio *bio;
 
-       f = d->frames;
-       e = f + d->nframes;
-       for (; f<e; f->tag = FREETAG, f->buf = NULL, f++) {
-               if (f->tag == FREETAG || f->buf == NULL)
-                       continue;
-               buf = f->buf;
-               bio = buf->bio;
-               if (--buf->nframesout == 0) {
-                       mempool_free(buf, d->bufpool);
-                       bio_endio(bio, -EIO);
+       t = d->targets;
+       te = t + NTARGETS;
+       for (; t < te && *t; t++) {
+               f = (*t)->frames;
+               e = f + (*t)->nframes;
+               for (; f < e; f->tag = FREETAG, f->buf = NULL, f++) {
+                       if (f->tag == FREETAG || f->buf == NULL)
+                               continue;
+                       buf = f->buf;
+                       bio = buf->bio;
+                       if (--buf->nframesout == 0
+                       && buf != d->inprocess) {
+                               mempool_free(buf, d->bufpool);
+                               bio_endio(bio, -EIO);
+                       }
                }
-               skb_shinfo(f->skb)->nr_frags = f->skb->data_len = 0;
+               (*t)->maxout = (*t)->nframes;
+               (*t)->nout = 0;
+       }
+       buf = d->inprocess;
+       if (buf) {
+               bio = buf->bio;
+               mempool_free(buf, d->bufpool);
+               bio_endio(bio, -EIO);
        }
        d->inprocess = NULL;
+       d->htgt = NULL;
 
        while (!list_empty(&d->bufq)) {
                buf = container_of(d->bufq.next, struct buf, bufs);
@@ -136,12 +111,114 @@ aoedev_downdev(struct aoedev *d)
        if (d->gd)
                d->gd->capacity = 0;
 
-       d->flags &= ~(DEVFL_UP | DEVFL_PAUSE);
+       d->flags &= ~DEVFL_UP;
+}
+
+static void
+aoedev_freedev(struct aoedev *d)
+{
+       struct aoetgt **t, **e;
+
+       if (d->gd) {
+               aoedisk_rm_sysfs(d);
+               del_gendisk(d->gd);
+               put_disk(d->gd);
+       }
+       t = d->targets;
+       e = t + NTARGETS;
+       for (; t < e && *t; t++)
+               freetgt(d, *t);
+       if (d->bufpool)
+               mempool_destroy(d->bufpool);
+       skbpoolfree(d);
+       kfree(d);
+}
+
+int
+aoedev_flush(const char __user *str, size_t cnt)
+{
+       ulong flags;
+       struct aoedev *d, **dd;
+       struct aoedev *rmd = NULL;
+       char buf[16];
+       int all = 0;
+
+       if (cnt >= 3) {
+               if (cnt > sizeof buf)
+                       cnt = sizeof buf;
+               if (copy_from_user(buf, str, cnt))
+                       return -EFAULT;
+               all = !strncmp(buf, "all", 3);
+       }
+
+       flush_scheduled_work();
+       spin_lock_irqsave(&devlist_lock, flags);
+       dd = &devlist;
+       while ((d = *dd)) {
+               spin_lock(&d->lock);
+               if ((!all && (d->flags & DEVFL_UP))
+               || (d->flags & (DEVFL_GDALLOC|DEVFL_NEWSIZE))
+               || d->nopen) {
+                       spin_unlock(&d->lock);
+                       dd = &d->next;
+                       continue;
+               }
+               *dd = d->next;
+               aoedev_downdev(d);
+               d->flags |= DEVFL_TKILL;
+               spin_unlock(&d->lock);
+               d->next = rmd;
+               rmd = d;
+       }
+       spin_unlock_irqrestore(&devlist_lock, flags);
+       while ((d = rmd)) {
+               rmd = d->next;
+               del_timer_sync(&d->timer);
+               aoedev_freedev(d);      /* must be able to sleep */
+       }
+       return 0;
+}
+
+/* I'm not really sure that this is a realistic problem, but if the
+network driver goes gonzo let's just leak memory after complaining. */
+static void
+skbfree(struct sk_buff *skb)
+{
+       enum { Sms = 100, Tms = 3*1000};
+       int i = Tms / Sms;
+
+       if (skb == NULL)
+               return;
+       while (atomic_read(&skb_shinfo(skb)->dataref) != 1 && i-- > 0)
+               msleep(Sms);
+       if (i <= 0) {
+               printk(KERN_ERR
+                       "aoe: %s holds ref: %s\n",
+                       skb->dev ? skb->dev->name : "netif",
+                       "cannot free skb -- memory leaked.");
+               return;
+       }
+       skb_shinfo(skb)->nr_frags = skb->data_len = 0;
+       skb_trim(skb, 0);
+       dev_kfree_skb(skb);
+}
+
+static void
+skbpoolfree(struct aoedev *d)
+{
+       struct sk_buff *skb;
+
+       while ((skb = d->skbpool_hd)) {
+               d->skbpool_hd = skb->next;
+               skb->next = NULL;
+               skbfree(skb);
+       }
+       d->skbpool_tl = NULL;
 }
 
 /* find it or malloc it */
 struct aoedev *
-aoedev_by_sysminor_m(ulong sysminor, ulong bufcnt)
+aoedev_by_sysminor_m(ulong sysminor)
 {
        struct aoedev *d;
        ulong flags;
@@ -151,43 +228,43 @@ aoedev_by_sysminor_m(ulong sysminor, ulong bufcnt)
        for (d=devlist; d; d=d->next)
                if (d->sysminor == sysminor)
                        break;
-
-       if (d == NULL) {
-               d = aoedev_newdev(bufcnt);
-               if (d == NULL) {
-                       spin_unlock_irqrestore(&devlist_lock, flags);
-                       printk(KERN_INFO "aoe: aoedev_newdev failure.\n");
-                       return NULL;
-               }
-               d->sysminor = sysminor;
-               d->aoemajor = AOEMAJOR(sysminor);
-               d->aoeminor = AOEMINOR(sysminor);
-       }
-
+       if (d)
+               goto out;
+       d = kcalloc(1, sizeof *d, GFP_ATOMIC);
+       if (!d)
+               goto out;
+       INIT_WORK(&d->work, aoecmd_sleepwork);
+       spin_lock_init(&d->lock);
+       init_timer(&d->timer);
+       d->timer.data = (ulong) d;
+       d->timer.function = dummy_timer;
+       d->timer.expires = jiffies + HZ;
+       add_timer(&d->timer);
+       d->bufpool = NULL;      /* defer to aoeblk_gdalloc */
+       d->tgt = d->targets;
+       INIT_LIST_HEAD(&d->bufq);
+       d->sysminor = sysminor;
+       d->aoemajor = AOEMAJOR(sysminor);
+       d->aoeminor = AOEMINOR(sysminor);
+       d->mintimer = MINTIMER;
+       d->next = devlist;
+       devlist = d;
+ out:
        spin_unlock_irqrestore(&devlist_lock, flags);
        return d;
 }
 
 static void
-aoedev_freedev(struct aoedev *d)
+freetgt(struct aoedev *d, struct aoetgt *t)
 {
        struct frame *f, *e;
 
-       if (d->gd) {
-               aoedisk_rm_sysfs(d);
-               del_gendisk(d->gd);
-               put_disk(d->gd);
-       }
-       f = d->frames;
-       e = f + d->nframes;
-       for (; f<e; f++) {
-               skb_shinfo(f->skb)->nr_frags = 0;
-               dev_kfree_skb(f->skb);
-       }
-       kfree(d->frames);
-       if (d->bufpool)
-               mempool_destroy(d->bufpool);
-       kfree(d);
+       f = t->frames;
+       e = f + t->nframes;
+       for (; f < e; f++)
+               skbfree(f->skb);
+       kfree(t->frames);
+       kfree(t);
 }
 
 void
@@ -214,7 +291,5 @@ aoedev_exit(void)
 int __init
 aoedev_init(void)
 {
-       spin_lock_init(&devlist_lock);
        return 0;
 }
-
index a04b7d613299dfc3ae73ba6ec456acdf187d2626..7b15a5e9cec070a049af569fea2cb9ec51995244 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006 Coraid, Inc.  See COPYING for GPL terms. */
+/* Copyright (c) 2007 Coraid, Inc.  See COPYING for GPL terms. */
 /*
  * aoemain.c
  * Module initialization routines, discover timer
index 4e6deb7f5c24e2b5ff5e748ef65cef798ce3e861..8460ef736d560405318a62d7737f8afdc1db9ece 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006 Coraid, Inc.  See COPYING for GPL terms. */
+/* Copyright (c) 2007 Coraid, Inc.  See COPYING for GPL terms. */
 /*
  * aoenet.c
  * Ethernet portion of AoE driver
@@ -83,7 +83,7 @@ set_aoe_iflist(const char __user *user_str, size_t size)
        return 0;
 }
 
-u64
+unsigned long long
 mac_addr(char addr[6])
 {
        __be64 n = 0;
@@ -91,7 +91,7 @@ mac_addr(char addr[6])
 
        memcpy(p + 2, addr, 6); /* (sizeof addr != 6) */
 
-       return __be64_to_cpu(n);
+       return (unsigned long long) __be64_to_cpu(n);
 }
 
 void
@@ -137,9 +137,12 @@ aoenet_rcv(struct sk_buff *skb, struct net_device *ifp, struct packet_type *pt,
                if (n > NECODES)
                        n = 0;
                if (net_ratelimit())
-                       printk(KERN_ERR "aoe: error packet from %d.%d; ecode=%d '%s'\n",
-                              be16_to_cpu(get_unaligned(&h->major)), h->minor,
-                              h->err, aoe_errlist[n]);
+                       printk(KERN_ERR
+                               "%s%d.%d@%s; ecode=%d '%s'\n",
+                               "aoe: error packet from ",
+                               be16_to_cpu(get_unaligned(&h->major)),
+                               h->minor, skb->dev->name,
+                               h->err, aoe_errlist[n]);
                goto exit;
        }
 
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
new file mode 100644 (file)
index 0000000..8536480
--- /dev/null
@@ -0,0 +1,583 @@
+/*
+ * Ram backed block device driver.
+ *
+ * Copyright (C) 2007 Nick Piggin
+ * Copyright (C) 2007 Novell Inc.
+ *
+ * Parts derived from drivers/block/rd.c, and drivers/block/loop.c, copyright
+ * of their respective owners.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/major.h>
+#include <linux/blkdev.h>
+#include <linux/bio.h>
+#include <linux/highmem.h>
+#include <linux/gfp.h>
+#include <linux/radix-tree.h>
+#include <linux/buffer_head.h> /* invalidate_bh_lrus() */
+
+#include <asm/uaccess.h>
+
+#define SECTOR_SHIFT           9
+#define PAGE_SECTORS_SHIFT     (PAGE_SHIFT - SECTOR_SHIFT)
+#define PAGE_SECTORS           (1 << PAGE_SECTORS_SHIFT)
+
+/*
+ * Each block ramdisk device has a radix_tree brd_pages of pages that stores
+ * the pages containing the block device's contents. A brd page's ->index is
+ * its offset in PAGE_SIZE units. This is similar to, but in no way connected
+ * with, the kernel's pagecache or buffer cache (which sit above our block
+ * device).
+ */
+struct brd_device {
+       int             brd_number;
+       int             brd_refcnt;
+       loff_t          brd_offset;
+       loff_t          brd_sizelimit;
+       unsigned        brd_blocksize;
+
+       struct request_queue    *brd_queue;
+       struct gendisk          *brd_disk;
+       struct list_head        brd_list;
+
+       /*
+        * Backing store of pages and lock to protect it. This is the contents
+        * of the block device.
+        */
+       spinlock_t              brd_lock;
+       struct radix_tree_root  brd_pages;
+};
+
+/*
+ * Look up and return a brd's page for a given sector.
+ */
+static struct page *brd_lookup_page(struct brd_device *brd, sector_t sector)
+{
+       pgoff_t idx;
+       struct page *page;
+
+       /*
+        * The page lifetime is protected by the fact that we have opened the
+        * device node -- brd pages will never be deleted under us, so we
+        * don't need any further locking or refcounting.
+        *
+        * This is strictly true for the radix-tree nodes as well (ie. we
+        * don't actually need the rcu_read_lock()), however that is not a
+        * documented feature of the radix-tree API so it is better to be
+        * safe here (we don't have total exclusion from radix tree updates
+        * here, only deletes).
+        */
+       rcu_read_lock();
+       idx = sector >> PAGE_SECTORS_SHIFT; /* sector to page index */
+       page = radix_tree_lookup(&brd->brd_pages, idx);
+       rcu_read_unlock();
+
+       BUG_ON(page && page->index != idx);
+
+       return page;
+}
+
+/*
+ * Look up and return a brd's page for a given sector.
+ * If one does not exist, allocate an empty page, and insert that. Then
+ * return it.
+ */
+static struct page *brd_insert_page(struct brd_device *brd, sector_t sector)
+{
+       pgoff_t idx;
+       struct page *page;
+       gfp_t gfp_flags;
+
+       page = brd_lookup_page(brd, sector);
+       if (page)
+               return page;
+
+       /*
+        * Must use NOIO because we don't want to recurse back into the
+        * block or filesystem layers from page reclaim.
+        *
+        * Cannot support XIP and highmem, because our ->direct_access
+        * routine for XIP must return memory that is always addressable.
+        * If XIP was reworked to use pfns and kmap throughout, this
+        * restriction might be able to be lifted.
+        */
+       gfp_flags = GFP_NOIO | __GFP_ZERO;
+#ifndef CONFIG_BLK_DEV_XIP
+       gfp_flags |= __GFP_HIGHMEM;
+#endif
+       page = alloc_page(GFP_NOIO | __GFP_HIGHMEM | __GFP_ZERO);
+       if (!page)
+               return NULL;
+
+       if (radix_tree_preload(GFP_NOIO)) {
+               __free_page(page);
+               return NULL;
+       }
+
+       spin_lock(&brd->brd_lock);
+       idx = sector >> PAGE_SECTORS_SHIFT;
+       if (radix_tree_insert(&brd->brd_pages, idx, page)) {
+               __free_page(page);
+               page = radix_tree_lookup(&brd->brd_pages, idx);
+               BUG_ON(!page);
+               BUG_ON(page->index != idx);
+       } else
+               page->index = idx;
+       spin_unlock(&brd->brd_lock);
+
+       radix_tree_preload_end();
+
+       return page;
+}
+
+/*
+ * Free all backing store pages and radix tree. This must only be called when
+ * there are no other users of the device.
+ */
+#define FREE_BATCH 16
+static void brd_free_pages(struct brd_device *brd)
+{
+       unsigned long pos = 0;
+       struct page *pages[FREE_BATCH];
+       int nr_pages;
+
+       do {
+               int i;
+
+               nr_pages = radix_tree_gang_lookup(&brd->brd_pages,
+                               (void **)pages, pos, FREE_BATCH);
+
+               for (i = 0; i < nr_pages; i++) {
+                       void *ret;
+
+                       BUG_ON(pages[i]->index < pos);
+                       pos = pages[i]->index;
+                       ret = radix_tree_delete(&brd->brd_pages, pos);
+                       BUG_ON(!ret || ret != pages[i]);
+                       __free_page(pages[i]);
+               }
+
+               pos++;
+
+               /*
+                * This assumes radix_tree_gang_lookup always returns as
+                * many pages as possible. If the radix-tree code changes,
+                * so will this have to.
+                */
+       } while (nr_pages == FREE_BATCH);
+}
+
+/*
+ * copy_to_brd_setup must be called before copy_to_brd. It may sleep.
+ */
+static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n)
+{
+       unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT;
+       size_t copy;
+
+       copy = min_t(size_t, n, PAGE_SIZE - offset);
+       if (!brd_insert_page(brd, sector))
+               return -ENOMEM;
+       if (copy < n) {
+               sector += copy >> SECTOR_SHIFT;
+               if (!brd_insert_page(brd, sector))
+                       return -ENOMEM;
+       }
+       return 0;
+}
+
+/*
+ * Copy n bytes from src to the brd starting at sector. Does not sleep.
+ */
+static void copy_to_brd(struct brd_device *brd, const void *src,
+                       sector_t sector, size_t n)
+{
+       struct page *page;
+       void *dst;
+       unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT;
+       size_t copy;
+
+       copy = min_t(size_t, n, PAGE_SIZE - offset);
+       page = brd_lookup_page(brd, sector);
+       BUG_ON(!page);
+
+       dst = kmap_atomic(page, KM_USER1);
+       memcpy(dst + offset, src, copy);
+       kunmap_atomic(dst, KM_USER1);
+
+       if (copy < n) {
+               src += copy;
+               sector += copy >> SECTOR_SHIFT;
+               copy = n - copy;
+               page = brd_lookup_page(brd, sector);
+               BUG_ON(!page);
+
+               dst = kmap_atomic(page, KM_USER1);
+               memcpy(dst, src, copy);
+               kunmap_atomic(dst, KM_USER1);
+       }
+}
+
+/*
+ * Copy n bytes to dst from the brd starting at sector. Does not sleep.
+ */
+static void copy_from_brd(void *dst, struct brd_device *brd,
+                       sector_t sector, size_t n)
+{
+       struct page *page;
+       void *src;
+       unsigned int offset = (sector & (PAGE_SECTORS-1)) << SECTOR_SHIFT;
+       size_t copy;
+
+       copy = min_t(size_t, n, PAGE_SIZE - offset);
+       page = brd_lookup_page(brd, sector);
+       if (page) {
+               src = kmap_atomic(page, KM_USER1);
+               memcpy(dst, src + offset, copy);
+               kunmap_atomic(src, KM_USER1);
+       } else
+               memset(dst, 0, copy);
+
+       if (copy < n) {
+               dst += copy;
+               sector += copy >> SECTOR_SHIFT;
+               copy = n - copy;
+               page = brd_lookup_page(brd, sector);
+               if (page) {
+                       src = kmap_atomic(page, KM_USER1);
+                       memcpy(dst, src, copy);
+                       kunmap_atomic(src, KM_USER1);
+               } else
+                       memset(dst, 0, copy);
+       }
+}
+
+/*
+ * Process a single bvec of a bio.
+ */
+static int brd_do_bvec(struct brd_device *brd, struct page *page,
+                       unsigned int len, unsigned int off, int rw,
+                       sector_t sector)
+{
+       void *mem;
+       int err = 0;
+
+       if (rw != READ) {
+               err = copy_to_brd_setup(brd, sector, len);
+               if (err)
+                       goto out;
+       }
+
+       mem = kmap_atomic(page, KM_USER0);
+       if (rw == READ) {
+               copy_from_brd(mem + off, brd, sector, len);
+               flush_dcache_page(page);
+       } else
+               copy_to_brd(brd, mem + off, sector, len);
+       kunmap_atomic(mem, KM_USER0);
+
+out:
+       return err;
+}
+
+static int brd_make_request(struct request_queue *q, struct bio *bio)
+{
+       struct block_device *bdev = bio->bi_bdev;
+       struct brd_device *brd = bdev->bd_disk->private_data;
+       int rw;
+       struct bio_vec *bvec;
+       sector_t sector;
+       int i;
+       int err = -EIO;
+
+       sector = bio->bi_sector;
+       if (sector + (bio->bi_size >> SECTOR_SHIFT) >
+                                               get_capacity(bdev->bd_disk))
+               goto out;
+
+       rw = bio_rw(bio);
+       if (rw == READA)
+               rw = READ;
+
+       bio_for_each_segment(bvec, bio, i) {
+               unsigned int len = bvec->bv_len;
+               err = brd_do_bvec(brd, bvec->bv_page, len,
+                                       bvec->bv_offset, rw, sector);
+               if (err)
+                       break;
+               sector += len >> SECTOR_SHIFT;
+       }
+
+out:
+       bio_endio(bio, err);
+
+       return 0;
+}
+
+#ifdef CONFIG_BLK_DEV_XIP
+static int brd_direct_access (struct block_device *bdev, sector_t sector,
+                       unsigned long *data)
+{
+       struct brd_device *brd = bdev->bd_disk->private_data;
+       struct page *page;
+
+       if (!brd)
+               return -ENODEV;
+       if (sector & (PAGE_SECTORS-1))
+               return -EINVAL;
+       if (sector + PAGE_SECTORS > get_capacity(bdev->bd_disk))
+               return -ERANGE;
+       page = brd_insert_page(brd, sector);
+       if (!page)
+               return -ENOMEM;
+       *data = (unsigned long)page_address(page);
+
+       return 0;
+}
+#endif
+
+static int brd_ioctl(struct inode *inode, struct file *file,
+                       unsigned int cmd, unsigned long arg)
+{
+       int error;
+       struct block_device *bdev = inode->i_bdev;
+       struct brd_device *brd = bdev->bd_disk->private_data;
+
+       if (cmd != BLKFLSBUF)
+               return -ENOTTY;
+
+       /*
+        * ram device BLKFLSBUF has special semantics, we want to actually
+        * release and destroy the ramdisk data.
+        */
+       mutex_lock(&bdev->bd_mutex);
+       error = -EBUSY;
+       if (bdev->bd_openers <= 1) {
+               /*
+                * Invalidate the cache first, so it isn't written
+                * back to the device.
+                *
+                * Another thread might instantiate more buffercache here,
+                * but there is not much we can do to close that race.
+                */
+               invalidate_bh_lrus();
+               truncate_inode_pages(bdev->bd_inode->i_mapping, 0);
+               brd_free_pages(brd);
+               error = 0;
+       }
+       mutex_unlock(&bdev->bd_mutex);
+
+       return error;
+}
+
+static struct block_device_operations brd_fops = {
+       .owner =                THIS_MODULE,
+       .ioctl =                brd_ioctl,
+#ifdef CONFIG_BLK_DEV_XIP
+       .direct_access =        brd_direct_access,
+#endif
+};
+
+/*
+ * And now the modules code and kernel interface.
+ */
+static int rd_nr;
+int rd_size = CONFIG_BLK_DEV_RAM_SIZE;
+module_param(rd_nr, int, 0);
+MODULE_PARM_DESC(rd_nr, "Maximum number of brd devices");
+module_param(rd_size, int, 0);
+MODULE_PARM_DESC(rd_size, "Size of each RAM disk in kbytes.");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS_BLOCKDEV_MAJOR(RAMDISK_MAJOR);
+
+#ifndef MODULE
+/* Legacy boot options - nonmodular */
+static int __init ramdisk_size(char *str)
+{
+       rd_size = simple_strtol(str, NULL, 0);
+       return 1;
+}
+static int __init ramdisk_size2(char *str)
+{
+       return ramdisk_size(str);
+}
+__setup("ramdisk=", ramdisk_size);
+__setup("ramdisk_size=", ramdisk_size2);
+#endif
+
+/*
+ * The device scheme is derived from loop.c. Keep them in synch where possible
+ * (should share code eventually).
+ */
+static LIST_HEAD(brd_devices);
+static DEFINE_MUTEX(brd_devices_mutex);
+
+static struct brd_device *brd_alloc(int i)
+{
+       struct brd_device *brd;
+       struct gendisk *disk;
+
+       brd = kzalloc(sizeof(*brd), GFP_KERNEL);
+       if (!brd)
+               goto out;
+       brd->brd_number         = i;
+       spin_lock_init(&brd->brd_lock);
+       INIT_RADIX_TREE(&brd->brd_pages, GFP_ATOMIC);
+
+       brd->brd_queue = blk_alloc_queue(GFP_KERNEL);
+       if (!brd->brd_queue)
+               goto out_free_dev;
+       blk_queue_make_request(brd->brd_queue, brd_make_request);
+       blk_queue_max_sectors(brd->brd_queue, 1024);
+       blk_queue_bounce_limit(brd->brd_queue, BLK_BOUNCE_ANY);
+
+       disk = brd->brd_disk = alloc_disk(1);
+       if (!disk)
+               goto out_free_queue;
+       disk->major             = RAMDISK_MAJOR;
+       disk->first_minor       = i;
+       disk->fops              = &brd_fops;
+       disk->private_data      = brd;
+       disk->queue             = brd->brd_queue;
+       sprintf(disk->disk_name, "ram%d", i);
+       set_capacity(disk, rd_size * 2);
+
+       return brd;
+
+out_free_queue:
+       blk_cleanup_queue(brd->brd_queue);
+out_free_dev:
+       kfree(brd);
+out:
+       return NULL;
+}
+
+static void brd_free(struct brd_device *brd)
+{
+       put_disk(brd->brd_disk);
+       blk_cleanup_queue(brd->brd_queue);
+       brd_free_pages(brd);
+       kfree(brd);
+}
+
+static struct brd_device *brd_init_one(int i)
+{
+       struct brd_device *brd;
+
+       list_for_each_entry(brd, &brd_devices, brd_list) {
+               if (brd->brd_number == i)
+                       goto out;
+       }
+
+       brd = brd_alloc(i);
+       if (brd) {
+               add_disk(brd->brd_disk);
+               list_add_tail(&brd->brd_list, &brd_devices);
+       }
+out:
+       return brd;
+}
+
+static void brd_del_one(struct brd_device *brd)
+{
+       list_del(&brd->brd_list);
+       del_gendisk(brd->brd_disk);
+       brd_free(brd);
+}
+
+static struct kobject *brd_probe(dev_t dev, int *part, void *data)
+{
+       struct brd_device *brd;
+       struct kobject *kobj;
+
+       mutex_lock(&brd_devices_mutex);
+       brd = brd_init_one(dev & MINORMASK);
+       kobj = brd ? get_disk(brd->brd_disk) : ERR_PTR(-ENOMEM);
+       mutex_unlock(&brd_devices_mutex);
+
+       *part = 0;
+       return kobj;
+}
+
+static int __init brd_init(void)
+{
+       int i, nr;
+       unsigned long range;
+       struct brd_device *brd, *next;
+
+       /*
+        * brd module now has a feature to instantiate underlying device
+        * structure on-demand, provided that there is an access dev node.
+        * However, this will not work well with user space tool that doesn't
+        * know about such "feature".  In order to not break any existing
+        * tool, we do the following:
+        *
+        * (1) if rd_nr is specified, create that many upfront, and this
+        *     also becomes a hard limit.
+        * (2) if rd_nr is not specified, create 1 rd device on module
+        *     load, user can further extend brd device by create dev node
+        *     themselves and have kernel automatically instantiate actual
+        *     device on-demand.
+        */
+       if (rd_nr > 1UL << MINORBITS)
+               return -EINVAL;
+
+       if (rd_nr) {
+               nr = rd_nr;
+               range = rd_nr;
+       } else {
+               nr = CONFIG_BLK_DEV_RAM_COUNT;
+               range = 1UL << MINORBITS;
+       }
+
+       if (register_blkdev(RAMDISK_MAJOR, "ramdisk"))
+               return -EIO;
+
+       for (i = 0; i < nr; i++) {
+               brd = brd_alloc(i);
+               if (!brd)
+                       goto out_free;
+               list_add_tail(&brd->brd_list, &brd_devices);
+       }
+
+       /* point of no return */
+
+       list_for_each_entry(brd, &brd_devices, brd_list)
+               add_disk(brd->brd_disk);
+
+       blk_register_region(MKDEV(RAMDISK_MAJOR, 0), range,
+                                 THIS_MODULE, brd_probe, NULL, NULL);
+
+       printk(KERN_INFO "brd: module loaded\n");
+       return 0;
+
+out_free:
+       list_for_each_entry_safe(brd, next, &brd_devices, brd_list) {
+               list_del(&brd->brd_list);
+               brd_free(brd);
+       }
+
+       unregister_blkdev(RAMDISK_MAJOR, "brd");
+       return -ENOMEM;
+}
+
+static void __exit brd_exit(void)
+{
+       unsigned long range;
+       struct brd_device *brd, *next;
+
+       range = rd_nr ? rd_nr :  1UL << MINORBITS;
+
+       list_for_each_entry_safe(brd, next, &brd_devices, brd_list)
+               brd_del_one(brd);
+
+       blk_unregister_region(MKDEV(RAMDISK_MAJOR, 0), range);
+       unregister_blkdev(RAMDISK_MAJOR, "ramdisk");
+}
+
+module_init(brd_init);
+module_exit(brd_exit);
+
index ae3106045ee599d6072b6073fc674061a0d4c4e0..018753c59b8e7d22a6e7afbe634e5a4c94986a11 100644 (file)
@@ -54,7 +54,7 @@ static unsigned int debugflags;
 #endif /* NDEBUG */
 
 static unsigned int nbds_max = 16;
-static struct nbd_device nbd_dev[MAX_NBD];
+static struct nbd_device *nbd_dev;
 
 /*
  * Use just one lock (or at most 1 per NIC). Two arguments for this:
@@ -649,11 +649,9 @@ static int __init nbd_init(void)
 
        BUILD_BUG_ON(sizeof(struct nbd_request) != 28);
 
-       if (nbds_max > MAX_NBD) {
-               printk(KERN_CRIT "nbd: cannot allocate more than %u nbds; %u requested.\n", MAX_NBD,
-                               nbds_max);
-               return -EINVAL;
-       }
+       nbd_dev = kcalloc(nbds_max, sizeof(*nbd_dev), GFP_KERNEL);
+       if (!nbd_dev)
+               return -ENOMEM;
 
        for (i = 0; i < nbds_max; i++) {
                struct gendisk *disk = alloc_disk(1);
diff --git a/drivers/block/rd.c b/drivers/block/rd.c
deleted file mode 100644 (file)
index 06e23be..0000000
+++ /dev/null
@@ -1,537 +0,0 @@
-/*
- * ramdisk.c - Multiple RAM disk driver - gzip-loading version - v. 0.8 beta.
- *
- * (C) Chad Page, Theodore Ts'o, et. al, 1995.
- *
- * This RAM disk is designed to have filesystems created on it and mounted
- * just like a regular floppy disk.
- *
- * It also does something suggested by Linus: use the buffer cache as the
- * RAM disk data.  This makes it possible to dynamically allocate the RAM disk
- * buffer - with some consequences I have to deal with as I write this.
- *
- * This code is based on the original ramdisk.c, written mostly by
- * Theodore Ts'o (TYT) in 1991.  The code was largely rewritten by
- * Chad Page to use the buffer cache to store the RAM disk data in
- * 1995; Theodore then took over the driver again, and cleaned it up
- * for inclusion in the mainline kernel.
- *
- * The original CRAMDISK code was written by Richard Lyons, and
- * adapted by Chad Page to use the new RAM disk interface.  Theodore
- * Ts'o rewrote it so that both the compressed RAM disk loader and the
- * kernel decompressor uses the same inflate.c codebase.  The RAM disk
- * loader now also loads into a dynamic (buffer cache based) RAM disk,
- * not the old static RAM disk.  Support for the old static RAM disk has
- * been completely removed.
- *
- * Loadable module support added by Tom Dyas.
- *
- * Further cleanups by Chad Page (page0588@sundance.sjsu.edu):
- *     Cosmetic changes in #ifdef MODULE, code movement, etc.
- *     When the RAM disk module is removed, free the protected buffers
- *     Default RAM disk size changed to 2.88 MB
- *
- *  Added initrd: Werner Almesberger & Hans Lermen, Feb '96
- *
- * 4/25/96 : Made RAM disk size a parameter (default is now 4 MB)
- *             - Chad Page
- *
- * Add support for fs images split across >1 disk, Paul Gortmaker, Mar '98
- *
- * Make block size and block size shift for RAM disks a global macro
- * and set blk_size for -ENOSPC,     Werner Fink <werner@suse.de>, Apr '99
- */
-
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <asm/atomic.h>
-#include <linux/bio.h>
-#include <linux/module.h>
-#include <linux/moduleparam.h>
-#include <linux/init.h>
-#include <linux/pagemap.h>
-#include <linux/blkdev.h>
-#include <linux/genhd.h>
-#include <linux/buffer_head.h>         /* for invalidate_bdev() */
-#include <linux/backing-dev.h>
-#include <linux/blkpg.h>
-#include <linux/writeback.h>
-#include <linux/log2.h>
-
-#include <asm/uaccess.h>
-
-/* Various static variables go here.  Most are used only in the RAM disk code.
- */
-
-static struct gendisk *rd_disks[CONFIG_BLK_DEV_RAM_COUNT];
-static struct block_device *rd_bdev[CONFIG_BLK_DEV_RAM_COUNT];/* Protected device data */
-static struct request_queue *rd_queue[CONFIG_BLK_DEV_RAM_COUNT];
-
-/*
- * Parameters for the boot-loading of the RAM disk.  These are set by
- * init/main.c (from arguments to the kernel command line) or from the
- * architecture-specific setup routine (from the stored boot sector
- * information).
- */
-int rd_size = CONFIG_BLK_DEV_RAM_SIZE;         /* Size of the RAM disks */
-/*
- * It would be very desirable to have a soft-blocksize (that in the case
- * of the ramdisk driver is also the hardblocksize ;) of PAGE_SIZE because
- * doing that we'll achieve a far better MM footprint. Using a rd_blocksize of
- * BLOCK_SIZE in the worst case we'll make PAGE_SIZE/BLOCK_SIZE buffer-pages
- * unfreeable. With a rd_blocksize of PAGE_SIZE instead we are sure that only
- * 1 page will be protected. Depending on the size of the ramdisk you
- * may want to change the ramdisk blocksize to achieve a better or worse MM
- * behaviour. The default is still BLOCK_SIZE (needed by rd_load_image that
- * supposes the filesystem in the image uses a BLOCK_SIZE blocksize).
- */
-static int rd_blocksize = CONFIG_BLK_DEV_RAM_BLOCKSIZE;
-
-/*
- * Copyright (C) 2000 Linus Torvalds.
- *               2000 Transmeta Corp.
- * aops copied from ramfs.
- */
-
-/*
- * If a ramdisk page has buffers, some may be uptodate and some may be not.
- * To bring the page uptodate we zero out the non-uptodate buffers.  The
- * page must be locked.
- */
-static void make_page_uptodate(struct page *page)
-{
-       if (page_has_buffers(page)) {
-               struct buffer_head *bh = page_buffers(page);
-               struct buffer_head *head = bh;
-
-               do {
-                       if (!buffer_uptodate(bh)) {
-                               memset(bh->b_data, 0, bh->b_size);
-                               /*
-                                * akpm: I'm totally undecided about this.  The
-                                * buffer has just been magically brought "up to
-                                * date", but nobody should want to be reading
-                                * it anyway, because it hasn't been used for
-                                * anything yet.  It is still in a "not read
-                                * from disk yet" state.
-                                *
-                                * But non-uptodate buffers against an uptodate
-                                * page are against the rules.  So do it anyway.
-                                */
-                                set_buffer_uptodate(bh);
-                       }
-               } while ((bh = bh->b_this_page) != head);
-       } else {
-               memset(page_address(page), 0, PAGE_CACHE_SIZE);
-       }
-       flush_dcache_page(page);
-       SetPageUptodate(page);
-}
-
-static int ramdisk_readpage(struct file *file, struct page *page)
-{
-       if (!PageUptodate(page))
-               make_page_uptodate(page);
-       unlock_page(page);
-       return 0;
-}
-
-static int ramdisk_prepare_write(struct file *file, struct page *page,
-                               unsigned offset, unsigned to)
-{
-       if (!PageUptodate(page))
-               make_page_uptodate(page);
-       return 0;
-}
-
-static int ramdisk_commit_write(struct file *file, struct page *page,
-                               unsigned offset, unsigned to)
-{
-       set_page_dirty(page);
-       return 0;
-}
-
-/*
- * ->writepage to the blockdev's mapping has to redirty the page so that the
- * VM doesn't go and steal it.  We return AOP_WRITEPAGE_ACTIVATE so that the VM
- * won't try to (pointlessly) write the page again for a while.
- *
- * Really, these pages should not be on the LRU at all.
- */
-static int ramdisk_writepage(struct page *page, struct writeback_control *wbc)
-{
-       if (!PageUptodate(page))
-               make_page_uptodate(page);
-       SetPageDirty(page);
-       if (wbc->for_reclaim)
-               return AOP_WRITEPAGE_ACTIVATE;
-       unlock_page(page);
-       return 0;
-}
-
-/*
- * This is a little speedup thing: short-circuit attempts to write back the
- * ramdisk blockdev inode to its non-existent backing store.
- */
-static int ramdisk_writepages(struct address_space *mapping,
-                               struct writeback_control *wbc)
-{
-       return 0;
-}
-
-/*
- * ramdisk blockdev pages have their own ->set_page_dirty() because we don't
- * want them to contribute to dirty memory accounting.
- */
-static int ramdisk_set_page_dirty(struct page *page)
-{
-       if (!TestSetPageDirty(page))
-               return 1;
-       return 0;
-}
-
-/*
- * releasepage is called by pagevec_strip/try_to_release_page if
- * buffers_heads_over_limit is true. Without a releasepage function
- * try_to_free_buffers is called instead. That can unset the dirty
- * bit of our ram disk pages, which will be eventually freed, even
- * if the page is still in use.
- */
-static int ramdisk_releasepage(struct page *page, gfp_t dummy)
-{
-       return 0;
-}
-
-static const struct address_space_operations ramdisk_aops = {
-       .readpage       = ramdisk_readpage,
-       .prepare_write  = ramdisk_prepare_write,
-       .commit_write   = ramdisk_commit_write,
-       .writepage      = ramdisk_writepage,
-       .set_page_dirty = ramdisk_set_page_dirty,
-       .writepages     = ramdisk_writepages,
-       .releasepage    = ramdisk_releasepage,
-};
-
-static int rd_blkdev_pagecache_IO(int rw, struct bio_vec *vec, sector_t sector,
-                               struct address_space *mapping)
-{
-       pgoff_t index = sector >> (PAGE_CACHE_SHIFT - 9);
-       unsigned int vec_offset = vec->bv_offset;
-       int offset = (sector << 9) & ~PAGE_CACHE_MASK;
-       int size = vec->bv_len;
-       int err = 0;
-
-       do {
-               int count;
-               struct page *page;
-               char *src;
-               char *dst;
-
-               count = PAGE_CACHE_SIZE - offset;
-               if (count > size)
-                       count = size;
-               size -= count;
-
-               page = grab_cache_page(mapping, index);
-               if (!page) {
-                       err = -ENOMEM;
-                       goto out;
-               }
-
-               if (!PageUptodate(page))
-                       make_page_uptodate(page);
-
-               index++;
-
-               if (rw == READ) {
-                       src = kmap_atomic(page, KM_USER0) + offset;
-                       dst = kmap_atomic(vec->bv_page, KM_USER1) + vec_offset;
-               } else {
-                       src = kmap_atomic(vec->bv_page, KM_USER0) + vec_offset;
-                       dst = kmap_atomic(page, KM_USER1) + offset;
-               }
-               offset = 0;
-               vec_offset += count;
-
-               memcpy(dst, src, count);
-
-               kunmap_atomic(src, KM_USER0);
-               kunmap_atomic(dst, KM_USER1);
-
-               if (rw == READ)
-                       flush_dcache_page(vec->bv_page);
-               else
-                       set_page_dirty(page);
-               unlock_page(page);
-               put_page(page);
-       } while (size);
-
- out:
-       return err;
-}
-
-/*
- *  Basically, my strategy here is to set up a buffer-head which can't be
- *  deleted, and make that my Ramdisk.  If the request is outside of the
- *  allocated size, we must get rid of it...
- *
- * 19-JAN-1998  Richard Gooch <rgooch@atnf.csiro.au>  Added devfs support
- *
- */
-static int rd_make_request(struct request_queue *q, struct bio *bio)
-{
-       struct block_device *bdev = bio->bi_bdev;
-       struct address_space * mapping = bdev->bd_inode->i_mapping;
-       sector_t sector = bio->bi_sector;
-       unsigned long len = bio->bi_size >> 9;
-       int rw = bio_data_dir(bio);
-       struct bio_vec *bvec;
-       int ret = 0, i;
-
-       if (sector + len > get_capacity(bdev->bd_disk))
-               goto fail;
-
-       if (rw==READA)
-               rw=READ;
-
-       bio_for_each_segment(bvec, bio, i) {
-               ret |= rd_blkdev_pagecache_IO(rw, bvec, sector, mapping);
-               sector += bvec->bv_len >> 9;
-       }
-       if (ret)
-               goto fail;
-
-       bio_endio(bio, 0);
-       return 0;
-fail:
-       bio_io_error(bio);
-       return 0;
-} 
-
-static int rd_ioctl(struct inode *inode, struct file *file,
-                       unsigned int cmd, unsigned long arg)
-{
-       int error;
-       struct block_device *bdev = inode->i_bdev;
-
-       if (cmd != BLKFLSBUF)
-               return -ENOTTY;
-
-       /*
-        * special: we want to release the ramdisk memory, it's not like with
-        * the other blockdevices where this ioctl only flushes away the buffer
-        * cache
-        */
-       error = -EBUSY;
-       mutex_lock(&bdev->bd_mutex);
-       if (bdev->bd_openers <= 2) {
-               truncate_inode_pages(bdev->bd_inode->i_mapping, 0);
-               error = 0;
-       }
-       mutex_unlock(&bdev->bd_mutex);
-       return error;
-}
-
-/*
- * This is the backing_dev_info for the blockdev inode itself.  It doesn't need
- * writeback and it does not contribute to dirty memory accounting.
- */
-static struct backing_dev_info rd_backing_dev_info = {
-       .ra_pages       = 0,    /* No readahead */
-       .capabilities   = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK | BDI_CAP_MAP_COPY,
-       .unplug_io_fn   = default_unplug_io_fn,
-};
-
-/*
- * This is the backing_dev_info for the files which live atop the ramdisk
- * "device".  These files do need writeback and they do contribute to dirty
- * memory accounting.
- */
-static struct backing_dev_info rd_file_backing_dev_info = {
-       .ra_pages       = 0,    /* No readahead */
-       .capabilities   = BDI_CAP_MAP_COPY,     /* Does contribute to dirty memory */
-       .unplug_io_fn   = default_unplug_io_fn,
-};
-
-static int rd_open(struct inode *inode, struct file *filp)
-{
-       unsigned unit = iminor(inode);
-
-       if (rd_bdev[unit] == NULL) {
-               struct block_device *bdev = inode->i_bdev;
-               struct address_space *mapping;
-               unsigned bsize;
-               gfp_t gfp_mask;
-
-               inode = igrab(bdev->bd_inode);
-               rd_bdev[unit] = bdev;
-               bdev->bd_openers++;
-               bsize = bdev_hardsect_size(bdev);
-               bdev->bd_block_size = bsize;
-               inode->i_blkbits = blksize_bits(bsize);
-               inode->i_size = get_capacity(bdev->bd_disk)<<9;
-
-               mapping = inode->i_mapping;
-               mapping->a_ops = &ramdisk_aops;
-               mapping->backing_dev_info = &rd_backing_dev_info;
-               bdev->bd_inode_backing_dev_info = &rd_file_backing_dev_info;
-
-               /*
-                * Deep badness.  rd_blkdev_pagecache_IO() needs to allocate
-                * pagecache pages within a request_fn.  We cannot recur back
-                * into the filesystem which is mounted atop the ramdisk, because
-                * that would deadlock on fs locks.  And we really don't want
-                * to reenter rd_blkdev_pagecache_IO when we're already within
-                * that function.
-                *
-                * So we turn off __GFP_FS and __GFP_IO.
-                *
-                * And to give this thing a hope of working, turn on __GFP_HIGH.
-                * Hopefully, there's enough regular memory allocation going on
-                * for the page allocator emergency pools to keep the ramdisk
-                * driver happy.
-                */
-               gfp_mask = mapping_gfp_mask(mapping);
-               gfp_mask &= ~(__GFP_FS|__GFP_IO);
-               gfp_mask |= __GFP_HIGH;
-               mapping_set_gfp_mask(mapping, gfp_mask);
-       }
-
-       return 0;
-}
-
-static struct block_device_operations rd_bd_op = {
-       .owner =        THIS_MODULE,
-       .open =         rd_open,
-       .ioctl =        rd_ioctl,
-};
-
-/*
- * Before freeing the module, invalidate all of the protected buffers!
- */
-static void __exit rd_cleanup(void)
-{
-       int i;
-
-       for (i = 0; i < CONFIG_BLK_DEV_RAM_COUNT; i++) {
-               struct block_device *bdev = rd_bdev[i];
-               rd_bdev[i] = NULL;
-               if (bdev) {
-                       invalidate_bdev(bdev);
-                       blkdev_put(bdev);
-               }
-               del_gendisk(rd_disks[i]);
-               put_disk(rd_disks[i]);
-               blk_cleanup_queue(rd_queue[i]);
-       }
-       unregister_blkdev(RAMDISK_MAJOR, "ramdisk");
-
-       bdi_destroy(&rd_file_backing_dev_info);
-       bdi_destroy(&rd_backing_dev_info);
-}
-
-/*
- * This is the registration and initialization section of the RAM disk driver
- */
-static int __init rd_init(void)
-{
-       int i;
-       int err;
-
-       err = bdi_init(&rd_backing_dev_info);
-       if (err)
-               goto out2;
-
-       err = bdi_init(&rd_file_backing_dev_info);
-       if (err) {
-               bdi_destroy(&rd_backing_dev_info);
-               goto out2;
-       }
-
-       err = -ENOMEM;
-
-       if (rd_blocksize > PAGE_SIZE || rd_blocksize < 512 ||
-                       !is_power_of_2(rd_blocksize)) {
-               printk("RAMDISK: wrong blocksize %d, reverting to defaults\n",
-                      rd_blocksize);
-               rd_blocksize = BLOCK_SIZE;
-       }
-
-       for (i = 0; i < CONFIG_BLK_DEV_RAM_COUNT; i++) {
-               rd_disks[i] = alloc_disk(1);
-               if (!rd_disks[i])
-                       goto out;
-
-               rd_queue[i] = blk_alloc_queue(GFP_KERNEL);
-               if (!rd_queue[i]) {
-                       put_disk(rd_disks[i]);
-                       goto out;
-               }
-       }
-
-       if (register_blkdev(RAMDISK_MAJOR, "ramdisk")) {
-               err = -EIO;
-               goto out;
-       }
-
-       for (i = 0; i < CONFIG_BLK_DEV_RAM_COUNT; i++) {
-               struct gendisk *disk = rd_disks[i];
-
-               blk_queue_make_request(rd_queue[i], &rd_make_request);
-               blk_queue_hardsect_size(rd_queue[i], rd_blocksize);
-
-               /* rd_size is given in kB */
-               disk->major = RAMDISK_MAJOR;
-               disk->first_minor = i;
-               disk->fops = &rd_bd_op;
-               disk->queue = rd_queue[i];
-               disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO;
-               sprintf(disk->disk_name, "ram%d", i);
-               set_capacity(disk, rd_size * 2);
-               add_disk(rd_disks[i]);
-       }
-
-       /* rd_size is given in kB */
-       printk("RAMDISK driver initialized: "
-               "%d RAM disks of %dK size %d blocksize\n",
-               CONFIG_BLK_DEV_RAM_COUNT, rd_size, rd_blocksize);
-
-       return 0;
-out:
-       while (i--) {
-               put_disk(rd_disks[i]);
-               blk_cleanup_queue(rd_queue[i]);
-       }
-       bdi_destroy(&rd_backing_dev_info);
-       bdi_destroy(&rd_file_backing_dev_info);
-out2:
-       return err;
-}
-
-module_init(rd_init);
-module_exit(rd_cleanup);
-
-/* options - nonmodular */
-#ifndef MODULE
-static int __init ramdisk_size(char *str)
-{
-       rd_size = simple_strtol(str,NULL,0);
-       return 1;
-}
-static int __init ramdisk_blocksize(char *str)
-{
-       rd_blocksize = simple_strtol(str,NULL,0);
-       return 1;
-}
-__setup("ramdisk_size=", ramdisk_size);
-__setup("ramdisk_blocksize=", ramdisk_blocksize);
-#endif
-
-/* options - modular */
-module_param(rd_size, int, 0);
-MODULE_PARM_DESC(rd_size, "Size of each RAM disk in kbytes.");
-module_param(rd_blocksize, int, 0);
-MODULE_PARM_DESC(rd_blocksize, "Blocksize of each RAM disk in bytes.");
-MODULE_ALIAS_BLOCKDEV_MAJOR(RAMDISK_MAJOR);
-
-MODULE_LICENSE("GPL");
index 1f0b752e5de1810f05ec96c943072f5c367f212c..a7c4990b5b6bf0f3929bad97d5957aad0e134ce6 100644 (file)
@@ -57,7 +57,6 @@
 #define PCI_DEVICE_ID_APPLICOM_PCI2000IBS_CAN 0x0002
 #define PCI_DEVICE_ID_APPLICOM_PCI2000PFB     0x0003
 #endif
-#define MAX_PCI_DEVICE_NUM 3
 
 static char *applicom_pci_devnames[] = {
        "PCI board",
@@ -66,12 +65,9 @@ static char *applicom_pci_devnames[] = {
 };
 
 static struct pci_device_id applicom_pci_tbl[] = {
-       { PCI_VENDOR_ID_APPLICOM, PCI_DEVICE_ID_APPLICOM_PCIGENERIC,
-         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
-       { PCI_VENDOR_ID_APPLICOM, PCI_DEVICE_ID_APPLICOM_PCI2000IBS_CAN,
-         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
-       { PCI_VENDOR_ID_APPLICOM, PCI_DEVICE_ID_APPLICOM_PCI2000PFB,
-         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
+       { PCI_VDEVICE(APPLICOM, PCI_DEVICE_ID_APPLICOM_PCIGENERIC) },
+       { PCI_VDEVICE(APPLICOM, PCI_DEVICE_ID_APPLICOM_PCI2000IBS_CAN) },
+       { PCI_VDEVICE(APPLICOM, PCI_DEVICE_ID_APPLICOM_PCI2000PFB) },
        { 0 }
 };
 MODULE_DEVICE_TABLE(pci, applicom_pci_tbl);
@@ -197,31 +193,29 @@ static int __init applicom_init(void)
 
        while ( (dev = pci_get_class(PCI_CLASS_OTHERS << 16, dev))) {
 
-               if (dev->vendor != PCI_VENDOR_ID_APPLICOM)
-                       continue;
-               
-               if (dev->device  > MAX_PCI_DEVICE_NUM || dev->device == 0)
+               if (!pci_match_id(applicom_pci_tbl, dev))
                        continue;
                
                if (pci_enable_device(dev))
                        return -EIO;
 
-               RamIO = ioremap(dev->resource[0].start, LEN_RAM_IO);
+               RamIO = ioremap(pci_resource_start(dev, 0), LEN_RAM_IO);
 
                if (!RamIO) {
                        printk(KERN_INFO "ac.o: Failed to ioremap PCI memory "
                                "space at 0x%llx\n",
-                               (unsigned long long)dev->resource[0].start);
+                               (unsigned long long)pci_resource_start(dev, 0));
                        pci_disable_device(dev);
                        return -EIO;
                }
 
                printk(KERN_INFO "Applicom %s found at mem 0x%llx, irq %d\n",
                       applicom_pci_devnames[dev->device-1],
-                          (unsigned long long)dev->resource[0].start,
+                          (unsigned long long)pci_resource_start(dev, 0),
                       dev->irq);
 
-               boardno = ac_register_board(dev->resource[0].start, RamIO,0);
+               boardno = ac_register_board(pci_resource_start(dev, 0),
+                               RamIO, 0);
                if (!boardno) {
                        printk(KERN_INFO "ac.o: PCI Applicom device doesn't have correct signature.\n");
                        iounmap(RamIO);
index 2fc255a21486321acc7c70fb40c40e814bf10918..64b7b2b18352526d92e0ebf83f6bda424aed7d1c 100644 (file)
@@ -207,7 +207,7 @@ static int moxa_tiocmget(struct tty_struct *tty, struct file *file);
 static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
                         unsigned int set, unsigned int clear);
 static void moxa_poll(unsigned long);
-static void moxa_set_tty_param(struct tty_struct *);
+static void moxa_set_tty_param(struct tty_struct *, struct ktermios *);
 static int moxa_block_till_ready(struct tty_struct *, struct file *,
                            struct moxa_port *);
 static void moxa_setup_empty_event(struct tty_struct *);
@@ -500,7 +500,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
        ch->tty = tty;
        if (!(ch->asyncflags & ASYNC_INITIALIZED)) {
                ch->statusflags = 0;
-               moxa_set_tty_param(tty);
+               moxa_set_tty_param(tty, tty->termios);
                MoxaPortLineCtrl(ch->port, 1, 1);
                MoxaPortEnable(ch->port);
                ch->asyncflags |= ASYNC_INITIALIZED;
@@ -803,7 +803,7 @@ static void moxa_set_termios(struct tty_struct *tty,
 
        if (ch == NULL)
                return;
-       moxa_set_tty_param(tty);
+       moxa_set_tty_param(tty, old_termios);
        if (!(old_termios->c_cflag & CLOCAL) &&
            (tty->termios->c_cflag & CLOCAL))
                wake_up_interruptible(&ch->open_wait);
@@ -903,11 +903,11 @@ static void moxa_poll(unsigned long ignored)
 
 /******************************************************************************/
 
-static void moxa_set_tty_param(struct tty_struct *tty)
+static void moxa_set_tty_param(struct tty_struct *tty, struct ktermios *old_termios)
 {
        register struct ktermios *ts;
        struct moxa_port *ch;
-       int rts, cts, txflow, rxflow, xany;
+       int rts, cts, txflow, rxflow, xany, baud;
 
        ch = (struct moxa_port *) tty->driver_data;
        ts = tty->termios;
@@ -924,8 +924,15 @@ static void moxa_set_tty_param(struct tty_struct *tty)
                rxflow = 1;
        if (ts->c_iflag & IXANY)
                xany = 1;
+
+       /* Clear the features we don't support */
+       ts->c_cflag &= ~CMSPAR;
        MoxaPortFlowCtrl(ch->port, rts, cts, txflow, rxflow, xany);
-       MoxaPortSetTermio(ch->port, ts, tty_get_baud_rate(tty));
+       baud = MoxaPortSetTermio(ch->port, ts, tty_get_baud_rate(tty));
+       if (baud == -1)
+               baud = tty_termios_baud_rate(old_termios);
+       /* Not put the baud rate into the termios data */
+       tty_encode_baud_rate(tty, baud, baud);
 }
 
 static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
@@ -2065,7 +2072,7 @@ int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud)
                if (baud >= 921600L)
                        return (-1);
        }
-       MoxaPortSetBaud(port, baud);
+       baud = MoxaPortSetBaud(port, baud);
 
        if (termio->c_iflag & (IXON | IXOFF | IXANY)) {
                writeb(termio->c_cc[VSTART], ofsAddr + FuncArg);
@@ -2074,7 +2081,7 @@ int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud)
                moxa_wait_finish(ofsAddr);
 
        }
-       return (0);
+       return (baud);
 }
 
 int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState)
index 90c3969012a3ce5f5ddb941561a813c6a9a3349b..46b2a1cc8b54af4caf14971ca24ac95be101a390 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * n_tty.c --- implements the N_TTY line discipline.
- * 
+ *
  * This code used to be in tty_io.c, but things are getting hairy
  * enough that it made sense to split things off.  (The N_TTY
  * processing has changed so much that it's hardly recognizable,
@@ -8,19 +8,19 @@
  *
  * Note that the open routine for N_TTY is guaranteed never to return
  * an error.  This is because Linux will fall back to setting a line
- * to N_TTY if it can not switch to any other line discipline.  
+ * to N_TTY if it can not switch to any other line discipline.
  *
  * Written by Theodore Ts'o, Copyright 1994.
- * 
+ *
  * This file also contains code originally written by Linus Torvalds,
  * Copyright 1991, 1992, 1993, and by Julian Cowley, Copyright 1994.
- * 
+ *
  * This file may be redistributed under the terms of the GNU General Public
  * License.
  *
  * Reduced memory usage for older ARM systems  - Russell King.
  *
- * 2000/01/20   Fixed SMP locking on put_tty_queue using bits of 
+ * 2000/01/20   Fixed SMP locking on put_tty_queue using bits of
  *             the patch by Andrew J. Kroll <ag784@freenet.buffalo.edu>
  *             who actually finally proved there really was a race.
  *
@@ -144,11 +144,11 @@ static void put_tty_queue(unsigned char c, struct tty_struct *tty)
  *     Can sleep, may be called under the atomic_read_lock mutex but
  *     this is not guaranteed.
  */
-static void check_unthrottle(struct tty_struct * tty)
+
+static void check_unthrottle(struct tty_struct *tty)
 {
        if (tty->count &&
-           test_and_clear_bit(TTY_THROTTLED, &tty->flags) && 
+           test_and_clear_bit(TTY_THROTTLED, &tty->flags) &&
            tty->driver->unthrottle)
                tty->driver->unthrottle(tty);
 }
@@ -157,7 +157,7 @@ static void check_unthrottle(struct tty_struct * tty)
  *     reset_buffer_flags      -       reset buffer state
  *     @tty: terminal to reset
  *
- *     Reset the read buffer counters, clear the flags, 
+ *     Reset the read buffer counters, clear the flags,
  *     and make sure the driver is unthrottled. Called
  *     from n_tty_open() and n_tty_flush_buffer().
  */
@@ -186,12 +186,12 @@ static void reset_buffer_flags(struct tty_struct *tty)
  *     FIXME: tty->ctrl_status is not spinlocked and relies on
  *     lock_kernel() still.
  */
-static void n_tty_flush_buffer(struct tty_struct * tty)
+
+static void n_tty_flush_buffer(struct tty_struct *tty)
 {
        /* clear everything and unthrottle the driver */
        reset_buffer_flags(tty);
-       
+
        if (!tty->link)
                return;
 
@@ -206,9 +206,9 @@ static void n_tty_flush_buffer(struct tty_struct * tty)
  *     @tty: tty device
  *
  *     Report the number of characters buffered to be delivered to user
- *     at this instant in time. 
+ *     at this instant in time.
  */
+
 static ssize_t n_tty_chars_in_buffer(struct tty_struct *tty)
 {
        unsigned long flags;
@@ -234,7 +234,7 @@ static ssize_t n_tty_chars_in_buffer(struct tty_struct *tty)
  *     character. We use this to correctly compute the on screen size
  *     of the character when printing
  */
+
 static inline int is_utf8_continuation(unsigned char c)
 {
        return (c & 0xc0) == 0x80;
@@ -247,7 +247,7 @@ static inline int is_utf8_continuation(unsigned char c)
  *     Returns true if the utf8 character 'c' is a multibyte continuation
  *     character and the terminal is in unicode mode.
  */
+
 static inline int is_continuation(unsigned char c, struct tty_struct *tty)
 {
        return I_IUTF8(tty) && is_utf8_continuation(c);
@@ -266,7 +266,7 @@ static inline int is_continuation(unsigned char c, struct tty_struct *tty)
  *     Called from both the receive and transmit sides and can be called
  *     re-entrantly. Relies on lock_kernel() still.
  */
+
 static int opost(unsigned char c, struct tty_struct *tty)
 {
        int     space, spaces;
@@ -339,9 +339,9 @@ static int opost(unsigned char c, struct tty_struct *tty)
  *
  *     Called from write_chan under the tty layer write lock.
  */
-static ssize_t opost_block(struct tty_struct * tty,
-                      const unsigned char * buf, unsigned int nr)
+
+static ssize_t opost_block(struct tty_struct *tty,
+                      const unsigned char *buf, unsigned int nr)
 {
        int     space;
        int     i;
@@ -386,7 +386,7 @@ static ssize_t opost_block(struct tty_struct * tty,
 break_out:
        if (tty->driver->flush_chars)
                tty->driver->flush_chars(tty);
-       i = tty->driver->write(tty, buf, i);    
+       i = tty->driver->write(tty, buf, i);
        return i;
 }
 
@@ -398,7 +398,7 @@ break_out:
  *
  *     Queue a byte to the driver layer for output
  */
+
 static inline void put_char(unsigned char c, struct tty_struct *tty)
 {
        tty->driver->put_char(tty, c);
@@ -409,7 +409,7 @@ static inline void put_char(unsigned char c, struct tty_struct *tty)
  *     @c: unicode byte to echo
  *     @tty: terminal device
  *
- *     Echo user input back onto the screen. This must be called only when 
+ *     Echo user input back onto the screen. This must be called only when
  *     L_ECHO(tty) is true. Called from the driver receive_buf path.
  */
 
@@ -441,7 +441,7 @@ static inline void finish_erasing(struct tty_struct *tty)
  *     present in the stream from the driver layer. Handles the complexities
  *     of UTF-8 multibyte symbols.
  */
+
 static void eraser(unsigned char c, struct tty_struct *tty)
 {
        enum { ERASE, WERASE, KILL } kill_type;
@@ -541,7 +541,7 @@ static void eraser(unsigned char c, struct tty_struct *tty)
 
                                /* should never happen */
                                if (tty->column > 0x80000000)
-                                       tty->column = 0; 
+                                       tty->column = 0;
 
                                /* Now backup to that column. */
                                while (tty->column > col) {
@@ -585,7 +585,7 @@ static void eraser(unsigned char c, struct tty_struct *tty)
  *     settings and character used. Called from the driver receive_buf
  *     path so serialized.
  */
+
 static inline void isig(int sig, struct tty_struct *tty, int flush)
 {
        if (tty->pgrp)
@@ -606,7 +606,7 @@ static inline void isig(int sig, struct tty_struct *tty, int flush)
  *
  *     Called from the receive_buf path so single threaded.
  */
+
 static inline void n_tty_receive_break(struct tty_struct *tty)
 {
        if (I_IGNBRK(tty))
@@ -635,7 +635,7 @@ static inline void n_tty_receive_break(struct tty_struct *tty)
  *     need locking as num_overrun and overrun_time are function
  *     private.
  */
+
 static inline void n_tty_receive_overrun(struct tty_struct *tty)
 {
        char buf[64];
@@ -662,9 +662,8 @@ static inline void n_tty_receive_overrun(struct tty_struct *tty)
 static inline void n_tty_receive_parity_error(struct tty_struct *tty,
                                              unsigned char c)
 {
-       if (I_IGNPAR(tty)) {
+       if (I_IGNPAR(tty))
                return;
-       }
        if (I_PARMRK(tty)) {
                put_tty_queue('\377', tty);
                put_tty_queue('\0', tty);
@@ -682,7 +681,7 @@ static inline void n_tty_receive_parity_error(struct tty_struct *tty,
  *     @c: character
  *
  *     Process an individual character of input received from the driver.
- *     This is serialized with respect to itself by the rules for the 
+ *     This is serialized with respect to itself by the rules for the
  *     driver above.
  */
 
@@ -694,7 +693,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
                put_tty_queue(c, tty);
                return;
        }
-       
+
        if (I_ISTRIP(tty))
                c &= 0x7f;
        if (I_IUCLC(tty) && L_IEXTEN(tty))
@@ -739,7 +738,7 @@ static inline void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
                put_tty_queue(c, tty);
                return;
        }
-               
+
        if (c == '\r') {
                if (I_IGNCR(tty))
                        return;
@@ -825,8 +824,8 @@ send_signal:
                        goto handle_newline;
                }
                if (c == EOF_CHAR(tty)) {
-                       if (tty->canon_head != tty->read_head)
-                               set_bit(TTY_PUSH, &tty->flags);
+                       if (tty->canon_head != tty->read_head)
+                               set_bit(TTY_PUSH, &tty->flags);
                        c = __DISABLED_CHAR;
                        goto handle_newline;
                }
@@ -850,7 +849,7 @@ send_signal:
                        if (I_PARMRK(tty) && c == (unsigned char) '\377')
                                put_tty_queue(c, tty);
 
-               handle_newline:
+handle_newline:
                        spin_lock_irqsave(&tty->read_lock, flags);
                        set_bit(tty->read_head, tty->read_flags);
                        put_tty_queue_nolock(c, tty);
@@ -863,7 +862,7 @@ send_signal:
                        return;
                }
        }
-       
+
        finish_erasing(tty);
        if (L_ECHO(tty)) {
                if (tty->read_cnt >= N_TTY_BUF_SIZE-1) {
@@ -884,7 +883,7 @@ send_signal:
                put_tty_queue(c, tty);
 
        put_tty_queue(c, tty);
-}      
+}
 
 
 /**
@@ -898,12 +897,10 @@ send_signal:
 
 static void n_tty_write_wakeup(struct tty_struct *tty)
 {
-       if (tty->fasync)
-       {
-               set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
+       if (tty->fasync) {
+               set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
                kill_fasync(&tty->fasync, SIGIO, POLL_OUT);
        }
-       return;
 }
 
 /**
@@ -918,7 +915,7 @@ static void n_tty_write_wakeup(struct tty_struct *tty)
  *     not from interrupt context. The driver is responsible for making
  *     calls one at a time and in order (or using flush_to_ldisc)
  */
+
 static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
                              char *fp, int count)
 {
@@ -950,7 +947,7 @@ static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
                tty->read_cnt += i;
                spin_unlock_irqrestore(&tty->read_lock, cpuflags);
        } else {
-               for (i=count, p = cp, f = fp; i; i--, p++) {
+               for (i = count, p = cp, f = fp; i; i--, p++) {
                        if (f)
                                flags = *f++;
                        switch (flags) {
@@ -968,7 +965,7 @@ static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
                                n_tty_receive_overrun(tty);
                                break;
                        default:
-                               printk("%s: unknown flag %d\n",
+                               printk(KERN_ERR "%s: unknown flag %d\n",
                                       tty_name(tty, buf), flags);
                                break;
                        }
@@ -1001,7 +998,7 @@ static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
 int is_ignored(int sig)
 {
        return (sigismember(&current->blocked, sig) ||
-               current->sighand->action[sig-1].sa.sa_handler == SIG_IGN);
+               current->sighand->action[sig-1].sa.sa_handler == SIG_IGN);
 }
 
 /**
@@ -1011,16 +1008,16 @@ int is_ignored(int sig)
  *
  *     Called by the tty layer when the user changes termios flags so
  *     that the line discipline can plan ahead. This function cannot sleep
- *     and is protected from re-entry by the tty layer. The user is 
+ *     and is protected from re-entry by the tty layer. The user is
  *     guaranteed that this function will not be re-entered or in progress
  *     when the ldisc is closed.
  */
-static void n_tty_set_termios(struct tty_struct *tty, struct ktermios * old)
+
+static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
 {
        if (!tty)
                return;
-       
+
        tty->icanon = (L_ICANON(tty) != 0);
        if (test_bit(TTY_HW_COOK_IN, &tty->flags)) {
                tty->raw = 1;
@@ -1085,12 +1082,12 @@ static void n_tty_set_termios(struct tty_struct *tty, struct ktermios * old)
  *     n_tty_close             -       close the ldisc for this tty
  *     @tty: device
  *
- *     Called from the terminal layer when this line discipline is 
- *     being shut down, either because of a close or becsuse of a 
+ *     Called from the terminal layer when this line discipline is
+ *     being shut down, either because of a close or becsuse of a
  *     discipline change. The function will not be called while other
  *     ldisc methods are in progress.
  */
+
 static void n_tty_close(struct tty_struct *tty)
 {
        n_tty_flush_buffer(tty);
@@ -1104,7 +1101,7 @@ static void n_tty_close(struct tty_struct *tty)
  *     n_tty_open              -       open an ldisc
  *     @tty: terminal to open
  *
- *     Called when this line discipline is being attached to the 
+ *     Called when this line discipline is being attached to the
  *     terminal device. Can sleep. Called serialized so that no
  *     other events will occur in parallel. No further open will occur
  *     until a close.
@@ -1157,7 +1154,7 @@ static inline int input_available_p(struct tty_struct *tty, int amt)
  *     Called under the tty->atomic_read_lock sem
  *
  */
+
 static int copy_from_read_buf(struct tty_struct *tty,
                                      unsigned char __user **b,
                                      size_t *nr)
@@ -1186,7 +1183,8 @@ static int copy_from_read_buf(struct tty_struct *tty,
        return retval;
 }
 
-extern ssize_t redirected_tty_write(struct file *,const char *,size_t,loff_t *);
+extern ssize_t redirected_tty_write(struct file *, const char *,
+                                                       size_t, loff_t *);
 
 /**
  *     job_control             -       check job control
@@ -1194,10 +1192,10 @@ extern ssize_t redirected_tty_write(struct file *,const char *,size_t,loff_t *);
  *     @file: file handle
  *
  *     Perform job control management checks on this file/tty descriptor
- *     and if appropriate send any needed signals and return a negative 
+ *     and if appropriate send any needed signals and return a negative
  *     error code if action should be taken.
  */
+
 static int job_control(struct tty_struct *tty, struct file *file)
 {
        /* Job control check -- must be done at start and after
@@ -1208,7 +1206,7 @@ static int job_control(struct tty_struct *tty, struct file *file)
        if (file->f_op->write != redirected_tty_write &&
            current->signal->tty == tty) {
                if (!tty->pgrp)
-                       printk("read_chan: no tty->pgrp!\n");
+                       printk(KERN_ERR "read_chan: no tty->pgrp!\n");
                else if (task_pgrp(current) != tty->pgrp) {
                        if (is_ignored(SIGTTIN) ||
                            is_current_pgrp_orphaned())
@@ -1220,7 +1218,7 @@ static int job_control(struct tty_struct *tty, struct file *file)
        }
        return 0;
 }
+
 
 /**
  *     read_chan               -       read function for tty
@@ -1236,7 +1234,7 @@ static int job_control(struct tty_struct *tty, struct file *file)
  *
  *     This code must be sure never to sleep through a hangup.
  */
+
 static ssize_t read_chan(struct tty_struct *tty, struct file *file,
                         unsigned char __user *buf, size_t nr)
 {
@@ -1252,14 +1250,14 @@ static ssize_t read_chan(struct tty_struct *tty, struct file *file,
 do_it_again:
 
        if (!tty->read_buf) {
-               printk("n_tty_read_chan: called with read_buf == NULL?!?\n");
+               printk(KERN_ERR "n_tty_read_chan: read_buf == NULL?!?\n");
                return -EIO;
        }
 
        c = job_control(tty, file);
-       if(c < 0)
+       if (c < 0)
                return c;
-       
+
        minimum = time = 0;
        timeout = MAX_SCHEDULE_TIMEOUT;
        if (!tty->icanon) {
@@ -1287,8 +1285,7 @@ do_it_again:
        if (file->f_flags & O_NONBLOCK) {
                if (!mutex_trylock(&tty->atomic_read_lock))
                        return -EAGAIN;
-       }
-       else {
+       } else {
                if (mutex_lock_interruptible(&tty->atomic_read_lock))
                        return -ERESTARTSYS;
        }
@@ -1314,11 +1311,11 @@ do_it_again:
                   so that any interrupt will set the state back to
                   TASK_RUNNING. */
                set_current_state(TASK_INTERRUPTIBLE);
-               
+
                if (((minimum - (b - buf)) < tty->minimum_to_wake) &&
                    ((minimum - (b - buf)) >= 1))
                        tty->minimum_to_wake = (minimum - (b - buf));
-               
+
                if (!input_available_p(tty, 0)) {
                        if (test_bit(TTY_OTHER_CLOSED, &tty->flags)) {
                                retval = -EIO;
@@ -1355,7 +1352,7 @@ do_it_again:
                if (tty->icanon) {
                        /* N.B. avoid overrun if nr == 0 */
                        while (nr && tty->read_cnt) {
-                               int eol;
+                               int eol;
 
                                eol = test_and_clear_bit(tty->read_tail,
                                                tty->read_flags);
@@ -1427,7 +1424,7 @@ do_it_again:
        if (size) {
                retval = size;
                if (nr)
-                       clear_bit(TTY_PUSH, &tty->flags);
+                       clear_bit(TTY_PUSH, &tty->flags);
        } else if (test_and_clear_bit(TTY_PUSH, &tty->flags))
                 goto do_it_again;
 
@@ -1450,9 +1447,9 @@ do_it_again:
  *
  *     This code must be sure never to sleep through a hangup.
  */
-static ssize_t write_chan(struct tty_struct * tty, struct file * file,
-                         const unsigned char * buf, size_t nr)
+
+static ssize_t write_chan(struct tty_struct *tty, struct file *file,
+                         const unsigned char *buf, size_t nr)
 {
        const unsigned char *b = buf;
        DECLARE_WAITQUEUE(wait, current);
@@ -1542,8 +1539,9 @@ break_out:
  *     recompute the new limits. Possibly set_termios should issue
  *     a read wakeup to fix this bug.
  */
-static unsigned int normal_poll(struct tty_struct * tty, struct file * file, poll_table *wait)
+
+static unsigned int normal_poll(struct tty_struct *tty, struct file *file,
+                                                       poll_table *wait)
 {
        unsigned int mask = 0;
 
index f25facd97bb45a7af74e1268c45dec99f2cb04a0..00b8a84b03195535d1ef68fe74e1dea13b9510e6 100644 (file)
@@ -43,5 +43,14 @@ config CARDMAN_4040
          (http://www.omnikey.com/), or a current development version of OpenCT
          (http://www.opensc.org/).
 
+config IPWIRELESS
+       tristate "IPWireless 3G UMTS PCMCIA card support"
+       depends on PCMCIA
+       select PPP
+       help
+         This is a driver for 3G UMTS PCMCIA card from IPWireless company. In
+         some countries (for example Czech Republic, T-Mobile ISP) this card
+         is shipped for service called UMTS 4G.
+
 endmenu
 
index 0aae20985d5732059700e7fb50dec7d6573682a2..be8f287aa398f0a9697f9af30d4cda25b95ea1f0 100644 (file)
@@ -4,6 +4,8 @@
 # Makefile for the Linux PCMCIA char device drivers.
 #
 
+obj-y += ipwireless/
+
 obj-$(CONFIG_SYNCLINK_CS) += synclink_cs.o
 obj-$(CONFIG_CARDMAN_4000) += cm4000_cs.o
 obj-$(CONFIG_CARDMAN_4040) += cm4040_cs.o
diff --git a/drivers/char/pcmcia/ipwireless/Makefile b/drivers/char/pcmcia/ipwireless/Makefile
new file mode 100644 (file)
index 0000000..b71eb59
--- /dev/null
@@ -0,0 +1,10 @@
+#
+# drivers/char/pcmcia/ipwireless/Makefile
+#
+# Makefile for the IPWireless driver
+#
+
+obj-$(CONFIG_IPWIRELESS) += ipwireless.o
+
+ipwireless-objs := hardware.o main.o network.o tty.o
+
diff --git a/drivers/char/pcmcia/ipwireless/hardware.c b/drivers/char/pcmcia/ipwireless/hardware.c
new file mode 100644 (file)
index 0000000..1f978ff
--- /dev/null
@@ -0,0 +1,1787 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/slab.h>
+
+#include "hardware.h"
+#include "setup_protocol.h"
+#include "network.h"
+#include "main.h"
+
+static void ipw_send_setup_packet(struct ipw_hardware *hw);
+static void handle_received_SETUP_packet(struct ipw_hardware *ipw,
+                                        unsigned int address,
+                                        unsigned char *data, int len,
+                                        int is_last);
+static void ipwireless_setup_timer(unsigned long data);
+static void handle_received_CTRL_packet(struct ipw_hardware *hw,
+               unsigned int channel_idx, unsigned char *data, int len);
+
+/*#define TIMING_DIAGNOSTICS*/
+
+#ifdef TIMING_DIAGNOSTICS
+
+static struct timing_stats {
+       unsigned long last_report_time;
+       unsigned long read_time;
+       unsigned long write_time;
+       unsigned long read_bytes;
+       unsigned long write_bytes;
+       unsigned long start_time;
+};
+
+static void start_timing(void)
+{
+       timing_stats.start_time = jiffies;
+}
+
+static void end_read_timing(unsigned length)
+{
+       timing_stats.read_time += (jiffies - start_time);
+       timing_stats.read_bytes += length + 2;
+       report_timing();
+}
+
+static void end_write_timing(unsigned length)
+{
+       timing_stats.write_time += (jiffies - start_time);
+       timing_stats.write_bytes += length + 2;
+       report_timing();
+}
+
+static void report_timing(void)
+{
+       unsigned long since = jiffies - timing_stats.last_report_time;
+
+       /* If it's been more than one second... */
+       if (since >= HZ) {
+               int first = (timing_stats.last_report_time == 0);
+
+               timing_stats.last_report_time = jiffies;
+               if (!first)
+                       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                              ": %u us elapsed - read %lu bytes in %u us, "
+                              "wrote %lu bytes in %u us\n",
+                              jiffies_to_usecs(since),
+                              timing_stats.read_bytes,
+                              jiffies_to_usecs(timing_stats.read_time),
+                              timing_stats.write_bytes,
+                              jiffies_to_usecs(timing_stats.write_time));
+
+               timing_stats.read_time = 0;
+               timing_stats.write_time = 0;
+               timing_stats.read_bytes = 0;
+               timing_stats.write_bytes = 0;
+       }
+}
+#else
+static void start_timing(void) { }
+static void end_read_timing(unsigned length) { }
+static void end_write_timing(unsigned length) { }
+#endif
+
+/* Imported IPW definitions */
+
+#define LL_MTU_V1 318
+#define LL_MTU_V2 250
+#define LL_MTU_MAX (LL_MTU_V1 > LL_MTU_V2 ? LL_MTU_V1 : LL_MTU_V2)
+
+#define PRIO_DATA  2
+#define PRIO_CTRL  1
+#define PRIO_SETUP 0
+
+/* Addresses */
+#define ADDR_SETUP_PROT 0
+
+/* Protocol ids */
+enum {
+       /* Identifier for the Com Data protocol */
+       TL_PROTOCOLID_COM_DATA = 0,
+
+       /* Identifier for the Com Control protocol */
+       TL_PROTOCOLID_COM_CTRL = 1,
+
+       /* Identifier for the Setup protocol */
+       TL_PROTOCOLID_SETUP = 2
+};
+
+/* Number of bytes in NL packet header (cannot do
+ * sizeof(nl_packet_header) since it's a bitfield) */
+#define NL_FIRST_PACKET_HEADER_SIZE        3
+
+/* Number of bytes in NL packet header (cannot do
+ * sizeof(nl_packet_header) since it's a bitfield) */
+#define NL_FOLLOWING_PACKET_HEADER_SIZE    1
+
+struct nl_first_packet_header {
+#if defined(__BIG_ENDIAN_BITFIELD)
+       unsigned char packet_rank:2;
+       unsigned char address:3;
+       unsigned char protocol:3;
+#else
+       unsigned char protocol:3;
+       unsigned char address:3;
+       unsigned char packet_rank:2;
+#endif
+       unsigned char length_lsb;
+       unsigned char length_msb;
+};
+
+struct nl_packet_header {
+#if defined(__BIG_ENDIAN_BITFIELD)
+       unsigned char packet_rank:2;
+       unsigned char address:3;
+       unsigned char protocol:3;
+#else
+       unsigned char protocol:3;
+       unsigned char address:3;
+       unsigned char packet_rank:2;
+#endif
+};
+
+/* Value of 'packet_rank' above */
+#define NL_INTERMEDIATE_PACKET    0x0
+#define NL_LAST_PACKET            0x1
+#define NL_FIRST_PACKET           0x2
+
+union nl_packet {
+       /* Network packet header of the first packet (a special case) */
+       struct nl_first_packet_header hdr_first;
+       /* Network packet header of the following packets (if any) */
+       struct nl_packet_header hdr;
+       /* Complete network packet (header + data) */
+       unsigned char rawpkt[LL_MTU_MAX];
+} __attribute__ ((__packed__));
+
+#define HW_VERSION_UNKNOWN -1
+#define HW_VERSION_1 1
+#define HW_VERSION_2 2
+
+/* IPW I/O ports */
+#define IOIER 0x00             /* Interrupt Enable Register */
+#define IOIR  0x02             /* Interrupt Source/ACK register */
+#define IODCR 0x04             /* Data Control Register */
+#define IODRR 0x06             /* Data Read Register */
+#define IODWR 0x08             /* Data Write Register */
+#define IOESR 0x0A             /* Embedded Driver Status Register */
+#define IORXR 0x0C             /* Rx Fifo Register (Host to Embedded) */
+#define IOTXR 0x0E             /* Tx Fifo Register (Embedded to Host) */
+
+/* I/O ports and bit definitions for version 1 of the hardware */
+
+/* IER bits*/
+#define IER_RXENABLED   0x1
+#define IER_TXENABLED   0x2
+
+/* ISR bits */
+#define IR_RXINTR       0x1
+#define IR_TXINTR       0x2
+
+/* DCR bits */
+#define DCR_RXDONE      0x1
+#define DCR_TXDONE      0x2
+#define DCR_RXRESET     0x4
+#define DCR_TXRESET     0x8
+
+/* I/O ports and bit definitions for version 2 of the hardware */
+
+struct MEMCCR {
+       unsigned short reg_config_option;       /* PCCOR: Configuration Option Register */
+       unsigned short reg_config_and_status;   /* PCCSR: Configuration and Status Register */
+       unsigned short reg_pin_replacement;     /* PCPRR: Pin Replacemant Register */
+       unsigned short reg_socket_and_copy;     /* PCSCR: Socket and Copy Register */
+       unsigned short reg_ext_status;          /* PCESR: Extendend Status Register */
+       unsigned short reg_io_base;             /* PCIOB: I/O Base Register */
+};
+
+struct MEMINFREG {
+       unsigned short memreg_tx_old;   /* TX Register (R/W) */
+       unsigned short pad1;
+       unsigned short memreg_rx_done;  /* RXDone Register (R/W) */
+       unsigned short pad2;
+       unsigned short memreg_rx;       /* RX Register (R/W) */
+       unsigned short pad3;
+       unsigned short memreg_pc_interrupt_ack; /* PC intr Ack Register (W) */
+       unsigned short pad4;
+       unsigned long memreg_card_present;/* Mask for Host to check (R) for
+                                          * CARD_PRESENT_VALUE */
+       unsigned short memreg_tx_new;   /* TX2 (new) Register (R/W) */
+};
+
+#define IODMADPR 0x00          /* DMA Data Port Register (R/W) */
+
+#define CARD_PRESENT_VALUE (0xBEEFCAFEUL)
+
+#define MEMTX_TX                       0x0001
+#define MEMRX_RX                       0x0001
+#define MEMRX_RX_DONE                  0x0001
+#define MEMRX_PCINTACKK                0x0001
+#define MEMRX_MEMSPURIOUSINT           0x0001
+
+#define NL_NUM_OF_PRIORITIES       3
+#define NL_NUM_OF_PROTOCOLS        3
+#define NL_NUM_OF_ADDRESSES        NO_OF_IPW_CHANNELS
+
+struct ipw_hardware {
+       unsigned int base_port;
+       short hw_version;
+       unsigned short ll_mtu;
+       spinlock_t spinlock;
+
+       int initializing;
+       int init_loops;
+       struct timer_list setup_timer;
+
+       int tx_ready;
+       struct list_head tx_queue[NL_NUM_OF_PRIORITIES];
+       /* True if any packets are queued for transmission */
+       int tx_queued;
+
+       int rx_bytes_queued;
+       struct list_head rx_queue;
+       /* Pool of rx_packet structures that are not currently used. */
+       struct list_head rx_pool;
+       int rx_pool_size;
+       /* True if reception of data is blocked while userspace processes it. */
+       int blocking_rx;
+       /* True if there is RX data ready on the hardware. */
+       int rx_ready;
+       unsigned short last_memtx_serial;
+       /*
+        * Newer versions of the V2 card firmware send serial numbers in the
+        * MemTX register. 'serial_number_detected' is set true when we detect
+        * a non-zero serial number (indicating the new firmware).  Thereafter,
+        * the driver can safely ignore the Timer Recovery re-sends to avoid
+        * out-of-sync problems.
+        */
+       int serial_number_detected;
+       struct work_struct work_rx;
+
+       /* True if we are to send the set-up data to the hardware. */
+       int to_setup;
+
+       /* Card has been removed */
+       int removed;
+       /* Saved irq value when we disable the interrupt. */
+       int irq;
+       /* True if this driver is shutting down. */
+       int shutting_down;
+       /* Modem control lines */
+       unsigned int control_lines[NL_NUM_OF_ADDRESSES];
+       struct ipw_rx_packet *packet_assembler[NL_NUM_OF_ADDRESSES];
+
+       struct tasklet_struct tasklet;
+
+       /* The handle for the network layer, for the sending of events to it. */
+       struct ipw_network *network;
+       struct MEMINFREG __iomem *memory_info_regs;
+       struct MEMCCR __iomem *memregs_CCR;
+       void (*reboot_callback) (void *data);
+       void *reboot_callback_data;
+
+       unsigned short __iomem *memreg_tx;
+};
+
+/*
+ * Packet info structure for tx packets.
+ * Note: not all the fields defined here are required for all protocols
+ */
+struct ipw_tx_packet {
+       struct list_head queue;
+       /* channel idx + 1 */
+       unsigned char dest_addr;
+       /* SETUP, CTRL or DATA */
+       unsigned char protocol;
+       /* Length of data block, which starts at the end of this structure */
+       unsigned short length;
+       /* Sending state */
+       /* Offset of where we've sent up to so far */
+       unsigned long offset;
+       /* Count of packet fragments, starting at 0 */
+       int fragment_count;
+
+       /* Called after packet is sent and before is freed */
+       void (*packet_callback) (void *cb_data, unsigned int packet_length);
+       void *callback_data;
+};
+
+/* Signals from DTE */
+#define COMCTRL_RTS    0
+#define COMCTRL_DTR    1
+
+/* Signals from DCE */
+#define COMCTRL_CTS    2
+#define COMCTRL_DCD    3
+#define COMCTRL_DSR    4
+#define COMCTRL_RI     5
+
+struct ipw_control_packet_body {
+       /* DTE signal or DCE signal */
+       unsigned char sig_no;
+       /* 0: set signal, 1: clear signal */
+       unsigned char value;
+} __attribute__ ((__packed__));
+
+struct ipw_control_packet {
+       struct ipw_tx_packet header;
+       struct ipw_control_packet_body body;
+};
+
+struct ipw_rx_packet {
+       struct list_head queue;
+       unsigned int capacity;
+       unsigned int length;
+       unsigned int protocol;
+       unsigned int channel_idx;
+};
+
+#ifdef IPWIRELESS_STATE_DEBUG
+int ipwireless_dump_hardware_state(char *p, size_t limit,
+                                  struct ipw_hardware *hw)
+{
+       return snprintf(p, limit,
+                       "debug: initializing=%d\n"
+                       "debug: tx_ready=%d\n"
+                       "debug: tx_queued=%d\n"
+                       "debug: rx_ready=%d\n"
+                       "debug: rx_bytes_queued=%d\n"
+                       "debug: blocking_rx=%d\n"
+                       "debug: removed=%d\n"
+                       "debug: hardware.shutting_down=%d\n"
+                       "debug: to_setup=%d\n",
+                       hw->initializing,
+                       hw->tx_ready,
+                       hw->tx_queued,
+                       hw->rx_ready,
+                       hw->rx_bytes_queued,
+                       hw->blocking_rx,
+                       hw->removed,
+                       hw->shutting_down,
+                       hw->to_setup);
+}
+#endif
+
+static char *data_type(const unsigned char *buf, unsigned length)
+{
+       struct nl_packet_header *hdr = (struct nl_packet_header *) buf;
+
+       if (length == 0)
+               return "     ";
+
+       if (hdr->packet_rank & NL_FIRST_PACKET) {
+               switch (hdr->protocol) {
+               case TL_PROTOCOLID_COM_DATA:    return "DATA ";
+               case TL_PROTOCOLID_COM_CTRL:    return "CTRL ";
+               case TL_PROTOCOLID_SETUP:       return "SETUP";
+               default: return "???? ";
+               }
+       } else
+               return "     ";
+}
+
+#define DUMP_MAX_BYTES 64
+
+static void dump_data_bytes(const char *type, const unsigned char *data,
+                           unsigned length)
+{
+       char prefix[56];
+
+       sprintf(prefix, IPWIRELESS_PCCARD_NAME ": %s %s ",
+                       type, data_type(data, length));
+       print_hex_dump_bytes(prefix, 0, (void *)data,
+                       length < DUMP_MAX_BYTES ? length : DUMP_MAX_BYTES);
+}
+
+static int do_send_fragment(struct ipw_hardware *hw, const unsigned char *data,
+                           unsigned length)
+{
+       int i;
+       unsigned long flags;
+
+       start_timing();
+
+       if (length == 0)
+               return 0;
+
+       if (length > hw->ll_mtu)
+               return -1;
+
+       if (ipwireless_debug)
+               dump_data_bytes("send", data, length);
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+
+       if (hw->hw_version == HW_VERSION_1) {
+               outw((unsigned short) length, hw->base_port + IODWR);
+
+               for (i = 0; i < length; i += 2) {
+                       unsigned short d = data[i];
+                       __le16 raw_data;
+
+                       if (likely(i + 1 < length))
+                               d |= data[i + 1] << 8;
+                       raw_data = cpu_to_le16(d);
+                       outw(raw_data, hw->base_port + IODWR);
+               }
+
+               outw(DCR_TXDONE, hw->base_port + IODCR);
+       } else if (hw->hw_version == HW_VERSION_2) {
+               outw((unsigned short) length, hw->base_port + IODMADPR);
+
+               for (i = 0; i < length; i += 2) {
+                       unsigned short d = data[i];
+                       __le16 raw_data;
+
+                       if ((i + 1 < length))
+                               d |= data[i + 1] << 8;
+                       raw_data = cpu_to_le16(d);
+                       outw(raw_data, hw->base_port + IODMADPR);
+               }
+               while ((i & 3) != 2) {
+                       outw((unsigned short) 0xDEAD, hw->base_port + IODMADPR);
+                       i += 2;
+               }
+               writew(MEMRX_RX, &hw->memory_info_regs->memreg_rx);
+       }
+
+       spin_unlock_irqrestore(&hw->spinlock, flags);
+
+       end_write_timing(length);
+
+       return 0;
+}
+
+static int do_send_packet(struct ipw_hardware *hw, struct ipw_tx_packet *packet)
+{
+       unsigned short fragment_data_len;
+       unsigned short data_left = packet->length - packet->offset;
+       unsigned short header_size;
+       union nl_packet pkt;
+
+       header_size =
+           (packet->fragment_count == 0)
+           ? NL_FIRST_PACKET_HEADER_SIZE
+           : NL_FOLLOWING_PACKET_HEADER_SIZE;
+       fragment_data_len = hw->ll_mtu - header_size;
+       if (data_left < fragment_data_len)
+               fragment_data_len = data_left;
+
+       pkt.hdr_first.protocol = packet->protocol;
+       pkt.hdr_first.address = packet->dest_addr;
+       pkt.hdr_first.packet_rank = 0;
+
+       /* First packet? */
+       if (packet->fragment_count == 0) {
+               pkt.hdr_first.packet_rank |= NL_FIRST_PACKET;
+               pkt.hdr_first.length_lsb = (unsigned char) packet->length;
+               pkt.hdr_first.length_msb =
+                       (unsigned char) (packet->length >> 8);
+       }
+
+       memcpy(pkt.rawpkt + header_size,
+              ((unsigned char *) packet) + sizeof(struct ipw_tx_packet) +
+              packet->offset, fragment_data_len);
+       packet->offset += fragment_data_len;
+       packet->fragment_count++;
+
+       /* Last packet? (May also be first packet.) */
+       if (packet->offset == packet->length)
+               pkt.hdr_first.packet_rank |= NL_LAST_PACKET;
+       do_send_fragment(hw, pkt.rawpkt, header_size + fragment_data_len);
+
+       /* If this packet has unsent data, then re-queue it. */
+       if (packet->offset < packet->length) {
+               /*
+                * Re-queue it at the head of the highest priority queue so
+                * it goes before all other packets
+                */
+               unsigned long flags;
+
+               spin_lock_irqsave(&hw->spinlock, flags);
+               list_add(&packet->queue, &hw->tx_queue[0]);
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+       } else {
+               if (packet->packet_callback)
+                       packet->packet_callback(packet->callback_data,
+                                       packet->length);
+               kfree(packet);
+       }
+
+       return 0;
+}
+
+static void ipw_setup_hardware(struct ipw_hardware *hw)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+       if (hw->hw_version == HW_VERSION_1) {
+               /* Reset RX FIFO */
+               outw(DCR_RXRESET, hw->base_port + IODCR);
+               /* SB: Reset TX FIFO */
+               outw(DCR_TXRESET, hw->base_port + IODCR);
+
+               /* Enable TX and RX interrupts. */
+               outw(IER_TXENABLED | IER_RXENABLED, hw->base_port + IOIER);
+       } else {
+               /*
+                * Set INTRACK bit (bit 0), which means we must explicitly
+                * acknowledge interrupts by clearing bit 2 of reg_config_and_status.
+                */
+               unsigned short csr = readw(&hw->memregs_CCR->reg_config_and_status);
+
+               csr |= 1;
+               writew(csr, &hw->memregs_CCR->reg_config_and_status);
+       }
+       spin_unlock_irqrestore(&hw->spinlock, flags);
+}
+
+/*
+ * If 'packet' is NULL, then this function allocates a new packet, setting its
+ * length to 0 and ensuring it has the specified minimum amount of free space.
+ *
+ * If 'packet' is not NULL, then this function enlarges it if it doesn't
+ * have the specified minimum amount of free space.
+ *
+ */
+static struct ipw_rx_packet *pool_allocate(struct ipw_hardware *hw,
+                                          struct ipw_rx_packet *packet,
+                                          int minimum_free_space)
+{
+
+       if (!packet) {
+               unsigned long flags;
+
+               /*
+                * If this is the first fragment, then we will need to fetch a
+                * packet to put it in.
+                */
+               spin_lock_irqsave(&hw->spinlock, flags);
+               /* If we have one in our pool, then pull it out. */
+               if (!list_empty(&hw->rx_pool)) {
+                       packet = list_first_entry(&hw->rx_pool,
+                                       struct ipw_rx_packet, queue);
+                       list_del(&packet->queue);
+                       hw->rx_pool_size--;
+                       spin_unlock_irqrestore(&hw->spinlock, flags);
+               } else {
+                       /* Otherwise allocate a new one. */
+                       static int min_capacity = 256;
+                       int new_capacity;
+
+                       spin_unlock_irqrestore(&hw->spinlock, flags);
+                       new_capacity =
+                           minimum_free_space > min_capacity
+                           ? minimum_free_space
+                           : min_capacity;
+                       packet = kmalloc(sizeof(struct ipw_rx_packet)
+                                       + new_capacity, GFP_ATOMIC);
+                       if (!packet)
+                               return NULL;
+                       packet->capacity = new_capacity;
+               }
+               packet->length = 0;
+       }
+
+       /*
+        * If this packet does not have sufficient capacity for the data we
+        * want to add, then make it bigger.
+        */
+       if (packet->length + minimum_free_space > packet->capacity) {
+               struct ipw_rx_packet *old_packet = packet;
+
+               packet = kmalloc(sizeof(struct ipw_rx_packet) +
+                               old_packet->length + minimum_free_space,
+                               GFP_ATOMIC);
+               if (!packet)
+                       return NULL;
+               memcpy(packet, old_packet,
+                               sizeof(struct ipw_rx_packet)
+                                       + old_packet->length);
+               packet->capacity = old_packet->length + minimum_free_space;
+               kfree(old_packet);
+       }
+
+       return packet;
+}
+
+static void pool_free(struct ipw_hardware *hw, struct ipw_rx_packet *packet)
+{
+       if (hw->rx_pool_size > 6)
+               kfree(packet);
+       else {
+               hw->rx_pool_size++;
+               list_add_tail(&packet->queue, &hw->rx_pool);
+       }
+}
+
+static void queue_received_packet(struct ipw_hardware *hw,
+                                 unsigned int protocol, unsigned int address,
+                                 unsigned char *data, int length, int is_last)
+{
+       unsigned int channel_idx = address - 1;
+       struct ipw_rx_packet *packet = NULL;
+       unsigned long flags;
+
+       /* Discard packet if channel index is out of range. */
+       if (channel_idx >= NL_NUM_OF_ADDRESSES) {
+               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                      ": data packet has bad address %u\n", address);
+               return;
+       }
+
+       /*
+        * ->packet_assembler is safe to touch unlocked, this is the only place
+        */
+       if (protocol == TL_PROTOCOLID_COM_DATA) {
+               struct ipw_rx_packet **assem =
+                       &hw->packet_assembler[channel_idx];
+
+               /*
+                * Create a new packet, or assembler already contains one
+                * enlarge it by 'length' bytes.
+                */
+               (*assem) = pool_allocate(hw, *assem, length);
+               if (!(*assem)) {
+                       printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                               ": no memory for incomming data packet, dropped!\n");
+                       return;
+               }
+               (*assem)->protocol = protocol;
+               (*assem)->channel_idx = channel_idx;
+
+               /* Append this packet data onto existing data. */
+               memcpy((unsigned char *)(*assem) +
+                              sizeof(struct ipw_rx_packet)
+                               + (*assem)->length, data, length);
+               (*assem)->length += length;
+               if (is_last) {
+                       packet = *assem;
+                       *assem = NULL;
+                       /* Count queued DATA bytes only */
+                       spin_lock_irqsave(&hw->spinlock, flags);
+                       hw->rx_bytes_queued += packet->length;
+                       spin_unlock_irqrestore(&hw->spinlock, flags);
+               }
+       } else {
+               /* If it's a CTRL packet, don't assemble, just queue it. */
+               packet = pool_allocate(hw, NULL, length);
+               if (!packet) {
+                       printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                               ": no memory for incomming ctrl packet, dropped!\n");
+                       return;
+               }
+               packet->protocol = protocol;
+               packet->channel_idx = channel_idx;
+               memcpy((unsigned char *)packet + sizeof(struct ipw_rx_packet),
+                               data, length);
+               packet->length = length;
+       }
+
+       /*
+        * If this is the last packet, then send the assembled packet on to the
+        * network layer.
+        */
+       if (packet) {
+               spin_lock_irqsave(&hw->spinlock, flags);
+               list_add_tail(&packet->queue, &hw->rx_queue);
+               /* Block reception of incoming packets if queue is full. */
+               hw->blocking_rx =
+                       hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE;
+
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+               schedule_work(&hw->work_rx);
+       }
+}
+
+/*
+ * Workqueue callback
+ */
+static void ipw_receive_data_work(struct work_struct *work_rx)
+{
+       struct ipw_hardware *hw =
+           container_of(work_rx, struct ipw_hardware, work_rx);
+       unsigned long flags;
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+       while (!list_empty(&hw->rx_queue)) {
+               struct ipw_rx_packet *packet =
+                       list_first_entry(&hw->rx_queue,
+                                       struct ipw_rx_packet, queue);
+
+               if (hw->shutting_down)
+                       break;
+               list_del(&packet->queue);
+
+               /*
+                * Note: ipwireless_network_packet_received must be called in a
+                * process context (i.e. via schedule_work) because the tty
+                * output code can sleep in the tty_flip_buffer_push call.
+                */
+               if (packet->protocol == TL_PROTOCOLID_COM_DATA) {
+                       if (hw->network != NULL) {
+                               /* If the network hasn't been disconnected. */
+                               spin_unlock_irqrestore(&hw->spinlock, flags);
+                               /*
+                                * This must run unlocked due to tty processing
+                                * and mutex locking
+                                */
+                               ipwireless_network_packet_received(
+                                               hw->network,
+                                               packet->channel_idx,
+                                               (unsigned char *)packet
+                                               + sizeof(struct ipw_rx_packet),
+                                               packet->length);
+                               spin_lock_irqsave(&hw->spinlock, flags);
+                       }
+                       /* Count queued DATA bytes only */
+                       hw->rx_bytes_queued -= packet->length;
+               } else {
+                       /*
+                        * This is safe to be called locked, callchain does
+                        * not block
+                        */
+                       handle_received_CTRL_packet(hw, packet->channel_idx,
+                                       (unsigned char *)packet
+                                       + sizeof(struct ipw_rx_packet),
+                                       packet->length);
+               }
+               pool_free(hw, packet);
+               /*
+                * Unblock reception of incoming packets if queue is no longer
+                * full.
+                */
+               hw->blocking_rx =
+                       hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE;
+               if (hw->shutting_down)
+                       break;
+       }
+       spin_unlock_irqrestore(&hw->spinlock, flags);
+}
+
+static void handle_received_CTRL_packet(struct ipw_hardware *hw,
+                                       unsigned int channel_idx,
+                                       unsigned char *data, int len)
+{
+       struct ipw_control_packet_body *body =
+               (struct ipw_control_packet_body *) data;
+       unsigned int changed_mask;
+
+       if (len != sizeof(struct ipw_control_packet_body)) {
+               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                      ": control packet was %d bytes - wrong size!\n",
+                      len);
+               return;
+       }
+
+       switch (body->sig_no) {
+       case COMCTRL_CTS:
+               changed_mask = IPW_CONTROL_LINE_CTS;
+               break;
+       case COMCTRL_DCD:
+               changed_mask = IPW_CONTROL_LINE_DCD;
+               break;
+       case COMCTRL_DSR:
+               changed_mask = IPW_CONTROL_LINE_DSR;
+               break;
+       case COMCTRL_RI:
+               changed_mask = IPW_CONTROL_LINE_RI;
+               break;
+       default:
+               changed_mask = 0;
+       }
+
+       if (changed_mask != 0) {
+               if (body->value)
+                       hw->control_lines[channel_idx] |= changed_mask;
+               else
+                       hw->control_lines[channel_idx] &= ~changed_mask;
+               if (hw->network)
+                       ipwireless_network_notify_control_line_change(
+                                       hw->network,
+                                       channel_idx,
+                                       hw->control_lines[channel_idx],
+                                       changed_mask);
+       }
+}
+
+static void handle_received_packet(struct ipw_hardware *hw,
+                                  union nl_packet *packet,
+                                  unsigned short len)
+{
+       unsigned int protocol = packet->hdr.protocol;
+       unsigned int address = packet->hdr.address;
+       unsigned int header_length;
+       unsigned char *data;
+       unsigned int data_len;
+       int is_last = packet->hdr.packet_rank & NL_LAST_PACKET;
+
+       if (packet->hdr.packet_rank & NL_FIRST_PACKET)
+               header_length = NL_FIRST_PACKET_HEADER_SIZE;
+       else
+               header_length = NL_FOLLOWING_PACKET_HEADER_SIZE;
+
+       data = packet->rawpkt + header_length;
+       data_len = len - header_length;
+       switch (protocol) {
+       case TL_PROTOCOLID_COM_DATA:
+       case TL_PROTOCOLID_COM_CTRL:
+               queue_received_packet(hw, protocol, address, data, data_len,
+                               is_last);
+               break;
+       case TL_PROTOCOLID_SETUP:
+               handle_received_SETUP_packet(hw, address, data, data_len,
+                               is_last);
+               break;
+       }
+}
+
+static void acknowledge_data_read(struct ipw_hardware *hw)
+{
+       if (hw->hw_version == HW_VERSION_1)
+               outw(DCR_RXDONE, hw->base_port + IODCR);
+       else
+               writew(MEMRX_PCINTACKK,
+                               &hw->memory_info_regs->memreg_pc_interrupt_ack);
+}
+
+/*
+ * Retrieve a packet from the IPW hardware.
+ */
+static void do_receive_packet(struct ipw_hardware *hw)
+{
+       unsigned len;
+       unsigned int i;
+       unsigned char pkt[LL_MTU_MAX];
+
+       start_timing();
+
+       if (hw->hw_version == HW_VERSION_1) {
+               len = inw(hw->base_port + IODRR);
+               if (len > hw->ll_mtu) {
+                       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                              ": received a packet of %u bytes - "
+                              "longer than the MTU!\n", len);
+                       outw(DCR_RXDONE | DCR_RXRESET, hw->base_port + IODCR);
+                       return;
+               }
+
+               for (i = 0; i < len; i += 2) {
+                       __le16 raw_data = inw(hw->base_port + IODRR);
+                       unsigned short data = le16_to_cpu(raw_data);
+
+                       pkt[i] = (unsigned char) data;
+                       pkt[i + 1] = (unsigned char) (data >> 8);
+               }
+       } else {
+               len = inw(hw->base_port + IODMADPR);
+               if (len > hw->ll_mtu) {
+                       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                              ": received a packet of %u bytes - "
+                              "longer than the MTU!\n", len);
+                       writew(MEMRX_PCINTACKK,
+                               &hw->memory_info_regs->memreg_pc_interrupt_ack);
+                       return;
+               }
+
+               for (i = 0; i < len; i += 2) {
+                       __le16 raw_data = inw(hw->base_port + IODMADPR);
+                       unsigned short data = le16_to_cpu(raw_data);
+
+                       pkt[i] = (unsigned char) data;
+                       pkt[i + 1] = (unsigned char) (data >> 8);
+               }
+
+               while ((i & 3) != 2) {
+                       inw(hw->base_port + IODMADPR);
+                       i += 2;
+               }
+       }
+
+       acknowledge_data_read(hw);
+
+       if (ipwireless_debug)
+               dump_data_bytes("recv", pkt, len);
+
+       handle_received_packet(hw, (union nl_packet *) pkt, len);
+
+       end_read_timing(len);
+}
+
+static int get_current_packet_priority(struct ipw_hardware *hw)
+{
+       /*
+        * If we're initializing, don't send anything of higher priority than
+        * PRIO_SETUP.  The network layer therefore need not care about
+        * hardware initialization - any of its stuff will simply be queued
+        * until setup is complete.
+        */
+       return (hw->to_setup || hw->initializing
+                       ? PRIO_SETUP + 1 :
+                       NL_NUM_OF_PRIORITIES);
+}
+
+/*
+ * return 1 if something has been received from hw
+ */
+static int get_packets_from_hw(struct ipw_hardware *hw)
+{
+       int received = 0;
+       unsigned long flags;
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+       while (hw->rx_ready && !hw->blocking_rx) {
+               received = 1;
+               hw->rx_ready--;
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+
+               do_receive_packet(hw);
+
+               spin_lock_irqsave(&hw->spinlock, flags);
+       }
+       spin_unlock_irqrestore(&hw->spinlock, flags);
+
+       return received;
+}
+
+/*
+ * Send pending packet up to given priority, prioritize SETUP data until
+ * hardware is fully setup.
+ *
+ * return 1 if more packets can be sent
+ */
+static int send_pending_packet(struct ipw_hardware *hw, int priority_limit)
+{
+       int more_to_send = 0;
+       unsigned long flags;
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+       if (hw->tx_queued && hw->tx_ready != 0) {
+               int priority;
+               struct ipw_tx_packet *packet = NULL;
+
+               hw->tx_ready--;
+
+               /* Pick a packet */
+               for (priority = 0; priority < priority_limit; priority++) {
+                       if (!list_empty(&hw->tx_queue[priority])) {
+                               packet = list_first_entry(
+                                               &hw->tx_queue[priority],
+                                               struct ipw_tx_packet,
+                                               queue);
+
+                               list_del(&packet->queue);
+
+                               break;
+                       }
+               }
+               if (!packet) {
+                       hw->tx_queued = 0;
+                       spin_unlock_irqrestore(&hw->spinlock, flags);
+                       return 0;
+               }
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+
+               /* Send */
+               do_send_packet(hw, packet);
+
+               /* Check if more to send */
+               spin_lock_irqsave(&hw->spinlock, flags);
+               for (priority = 0; priority < priority_limit; priority++)
+                       if (!list_empty(&hw->tx_queue[priority])) {
+                               more_to_send = 1;
+                               break;
+                       }
+
+               if (!more_to_send)
+                       hw->tx_queued = 0;
+       }
+       spin_unlock_irqrestore(&hw->spinlock, flags);
+
+       return more_to_send;
+}
+
+/*
+ * Send and receive all queued packets.
+ */
+static void ipwireless_do_tasklet(unsigned long hw_)
+{
+       struct ipw_hardware *hw = (struct ipw_hardware *) hw_;
+       unsigned long flags;
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+       if (hw->shutting_down) {
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+               return;
+       }
+
+       if (hw->to_setup == 1) {
+               /*
+                * Initial setup data sent to hardware
+                */
+               hw->to_setup = 2;
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+
+               ipw_setup_hardware(hw);
+               ipw_send_setup_packet(hw);
+
+               send_pending_packet(hw, PRIO_SETUP + 1);
+               get_packets_from_hw(hw);
+       } else {
+               int priority_limit = get_current_packet_priority(hw);
+               int again;
+
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+
+               do {
+                       again = send_pending_packet(hw, priority_limit);
+                       again |= get_packets_from_hw(hw);
+               } while (again);
+       }
+}
+
+/*
+ * return true if the card is physically present.
+ */
+static int is_card_present(struct ipw_hardware *hw)
+{
+       if (hw->hw_version == HW_VERSION_1)
+               return inw(hw->base_port + IOIR) != 0xFFFF;
+       else
+               return readl(&hw->memory_info_regs->memreg_card_present) ==
+                   CARD_PRESENT_VALUE;
+}
+
+static irqreturn_t ipwireless_handle_v1_interrupt(int irq,
+                                                 struct ipw_hardware *hw)
+{
+       unsigned short irqn;
+
+       irqn = inw(hw->base_port + IOIR);
+
+       /* Check if card is present */
+       if (irqn == 0xFFFF)
+               return IRQ_NONE;
+       else if (irqn != 0) {
+               unsigned short ack = 0;
+               unsigned long flags;
+
+               /* Transmit complete. */
+               if (irqn & IR_TXINTR) {
+                       ack |= IR_TXINTR;
+                       spin_lock_irqsave(&hw->spinlock, flags);
+                       hw->tx_ready++;
+                       spin_unlock_irqrestore(&hw->spinlock, flags);
+               }
+               /* Received data */
+               if (irqn & IR_RXINTR) {
+                       ack |= IR_RXINTR;
+                       spin_lock_irqsave(&hw->spinlock, flags);
+                       hw->rx_ready++;
+                       spin_unlock_irqrestore(&hw->spinlock, flags);
+               }
+               if (ack != 0) {
+                       outw(ack, hw->base_port + IOIR);
+                       tasklet_schedule(&hw->tasklet);
+               }
+               return IRQ_HANDLED;
+       }
+       return IRQ_NONE;
+}
+
+static void acknowledge_pcmcia_interrupt(struct ipw_hardware *hw)
+{
+       unsigned short csr = readw(&hw->memregs_CCR->reg_config_and_status);
+
+       csr &= 0xfffd;
+       writew(csr, &hw->memregs_CCR->reg_config_and_status);
+}
+
+static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
+                                                    struct ipw_hardware *hw)
+{
+       int tx = 0;
+       int rx = 0;
+       int rx_repeat = 0;
+       int try_mem_tx_old;
+       unsigned long flags;
+
+       do {
+
+       unsigned short memtx = readw(hw->memreg_tx);
+       unsigned short memtx_serial;
+       unsigned short memrxdone =
+               readw(&hw->memory_info_regs->memreg_rx_done);
+
+       try_mem_tx_old = 0;
+
+       /* check whether the interrupt was generated by ipwireless card */
+       if (!(memtx & MEMTX_TX) && !(memrxdone & MEMRX_RX_DONE)) {
+
+               /* check if the card uses memreg_tx_old register */
+               if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
+                       memtx = readw(&hw->memory_info_regs->memreg_tx_old);
+                       if (memtx & MEMTX_TX) {
+                               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                                       ": Using memreg_tx_old\n");
+                               hw->memreg_tx =
+                                       &hw->memory_info_regs->memreg_tx_old;
+                       } else {
+                               return IRQ_NONE;
+                       }
+               } else {
+                       return IRQ_NONE;
+               }
+       }
+
+       /*
+        * See if the card is physically present. Note that while it is
+        * powering up, it appears not to be present.
+        */
+       if (!is_card_present(hw)) {
+               acknowledge_pcmcia_interrupt(hw);
+               return IRQ_HANDLED;
+       }
+
+       memtx_serial = memtx & (unsigned short) 0xff00;
+       if (memtx & MEMTX_TX) {
+               writew(memtx_serial, hw->memreg_tx);
+
+               if (hw->serial_number_detected) {
+                       if (memtx_serial != hw->last_memtx_serial) {
+                               hw->last_memtx_serial = memtx_serial;
+                               spin_lock_irqsave(&hw->spinlock, flags);
+                               hw->rx_ready++;
+                               spin_unlock_irqrestore(&hw->spinlock, flags);
+                               rx = 1;
+                       } else
+                               /* Ignore 'Timer Recovery' duplicates. */
+                               rx_repeat = 1;
+               } else {
+                       /*
+                        * If a non-zero serial number is seen, then enable
+                        * serial number checking.
+                        */
+                       if (memtx_serial != 0) {
+                               hw->serial_number_detected = 1;
+                               printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
+                                       ": memreg_tx serial num detected\n");
+
+                               spin_lock_irqsave(&hw->spinlock, flags);
+                               hw->rx_ready++;
+                               spin_unlock_irqrestore(&hw->spinlock, flags);
+                       }
+                       rx = 1;
+               }
+       }
+       if (memrxdone & MEMRX_RX_DONE) {
+               writew(0, &hw->memory_info_regs->memreg_rx_done);
+               spin_lock_irqsave(&hw->spinlock, flags);
+               hw->tx_ready++;
+               spin_unlock_irqrestore(&hw->spinlock, flags);
+               tx = 1;
+       }
+       if (tx)
+               writew(MEMRX_PCINTACKK,
+                               &hw->memory_info_regs->memreg_pc_interrupt_ack);
+
+       acknowledge_pcmcia_interrupt(hw);
+
+       if (tx || rx)
+               tasklet_schedule(&hw->tasklet);
+       else if (!rx_repeat) {
+               if (hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
+                       if (hw->serial_number_detected)
+                               printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
+                                       ": spurious interrupt - new_tx mode\n");
+                       else {
+                               printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
+                                       ": no valid memreg_tx value - "
+                                       "switching to the old memreg_tx\n");
+                               hw->memreg_tx =
+                                       &hw->memory_info_regs->memreg_tx_old;
+                               try_mem_tx_old = 1;
+                       }
+               } else
+                       printk(KERN_WARNING IPWIRELESS_PCCARD_NAME
+                                       ": spurious interrupt - old_tx mode\n");
+       }
+
+       } while (try_mem_tx_old == 1);
+
+       return IRQ_HANDLED;
+}
+
+irqreturn_t ipwireless_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+{
+       struct ipw_hardware *hw = dev_id;
+
+       if (hw->hw_version == HW_VERSION_1)
+               return ipwireless_handle_v1_interrupt(irq, hw);
+       else
+               return ipwireless_handle_v2_v3_interrupt(irq, hw);
+}
+
+static void flush_packets_to_hw(struct ipw_hardware *hw)
+{
+       int priority_limit;
+       unsigned long flags;
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+       priority_limit = get_current_packet_priority(hw);
+       spin_unlock_irqrestore(&hw->spinlock, flags);
+
+       while (send_pending_packet(hw, priority_limit));
+}
+
+static void send_packet(struct ipw_hardware *hw, int priority,
+                       struct ipw_tx_packet *packet)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&hw->spinlock, flags);
+       list_add_tail(&packet->queue, &hw->tx_queue[priority]);
+       hw->tx_queued = 1;
+       spin_unlock_irqrestore(&hw->spinlock, flags);
+
+       flush_packets_to_hw(hw);
+}
+
+/* Create data packet, non-atomic allocation */
+static void *alloc_data_packet(int data_size,
+                               unsigned char dest_addr,
+                               unsigned char protocol)
+{
+       struct ipw_tx_packet *packet = kzalloc(
+                       sizeof(struct ipw_tx_packet) + data_size,
+                       GFP_ATOMIC);
+
+       if (!packet)
+               return NULL;
+
+       INIT_LIST_HEAD(&packet->queue);
+       packet->dest_addr = dest_addr;
+       packet->protocol = protocol;
+       packet->length = data_size;
+
+       return packet;
+}
+
+static void *alloc_ctrl_packet(int header_size,
+                              unsigned char dest_addr,
+                              unsigned char protocol,
+                              unsigned char sig_no)
+{
+       /*
+        * sig_no is located right after ipw_tx_packet struct in every
+        * CTRL or SETUP packets, we can use ipw_control_packet as a
+        * common struct
+        */
+       struct ipw_control_packet *packet = kzalloc(header_size, GFP_ATOMIC);
+
+       if (!packet)
+               return NULL;
+
+       INIT_LIST_HEAD(&packet->header.queue);
+       packet->header.dest_addr = dest_addr;
+       packet->header.protocol = protocol;
+       packet->header.length = header_size - sizeof(struct ipw_tx_packet);
+       packet->body.sig_no = sig_no;
+
+       return packet;
+}
+
+int ipwireless_send_packet(struct ipw_hardware *hw, unsigned int channel_idx,
+                           unsigned char *data, unsigned int length,
+                           void (*callback) (void *cb, unsigned int length),
+                           void *callback_data)
+{
+       struct ipw_tx_packet *packet;
+
+       packet = alloc_data_packet(length,
+                              (unsigned char) (channel_idx + 1),
+                              TL_PROTOCOLID_COM_DATA);
+       if (!packet)
+               return -ENOMEM;
+       packet->packet_callback = callback;
+       packet->callback_data = callback_data;
+       memcpy((unsigned char *) packet +
+                       sizeof(struct ipw_tx_packet), data, length);
+
+       send_packet(hw, PRIO_DATA, packet);
+       return 0;
+}
+
+static int set_control_line(struct ipw_hardware *hw, int prio,
+                          unsigned int channel_idx, int line, int state)
+{
+       struct ipw_control_packet *packet;
+       int protocolid = TL_PROTOCOLID_COM_CTRL;
+
+       if (prio == PRIO_SETUP)
+               protocolid = TL_PROTOCOLID_SETUP;
+
+       packet = alloc_ctrl_packet(sizeof(struct ipw_control_packet),
+                       (unsigned char) (channel_idx + 1),
+                       protocolid, line);
+       if (!packet)
+               return -ENOMEM;
+       packet->header.length = sizeof(struct ipw_control_packet_body);
+       packet->body.value = (unsigned char) (state == 0 ? 0 : 1);
+       send_packet(hw, prio, &packet->header);
+       return 0;
+}
+
+
+static int set_DTR(struct ipw_hardware *hw, int priority,
+                  unsigned int channel_idx, int state)
+{
+       if (state != 0)
+               hw->control_lines[channel_idx] |= IPW_CONTROL_LINE_DTR;
+       else
+               hw->control_lines[channel_idx] &= ~IPW_CONTROL_LINE_DTR;
+
+       return set_control_line(hw, priority, channel_idx, COMCTRL_DTR, state);
+}
+
+static int set_RTS(struct ipw_hardware *hw, int priority,
+                  unsigned int channel_idx, int state)
+{
+       if (state != 0)
+               hw->control_lines[channel_idx] |= IPW_CONTROL_LINE_RTS;
+       else
+               hw->control_lines[channel_idx] &= ~IPW_CONTROL_LINE_RTS;
+
+       return set_control_line(hw, priority, channel_idx, COMCTRL_RTS, state);
+}
+
+int ipwireless_set_DTR(struct ipw_hardware *hw, unsigned int channel_idx,
+                      int state)
+{
+       return set_DTR(hw, PRIO_CTRL, channel_idx, state);
+}
+
+int ipwireless_set_RTS(struct ipw_hardware *hw, unsigned int channel_idx,
+                      int state)
+{
+       return set_RTS(hw, PRIO_CTRL, channel_idx, state);
+}
+
+struct ipw_setup_get_version_query_packet {
+       struct ipw_tx_packet header;
+       struct tl_setup_get_version_qry body;
+};
+
+struct ipw_setup_config_packet {
+       struct ipw_tx_packet header;
+       struct tl_setup_config_msg body;
+};
+
+struct ipw_setup_config_done_packet {
+       struct ipw_tx_packet header;
+       struct tl_setup_config_done_msg body;
+};
+
+struct ipw_setup_open_packet {
+       struct ipw_tx_packet header;
+       struct tl_setup_open_msg body;
+};
+
+struct ipw_setup_info_packet {
+       struct ipw_tx_packet header;
+       struct tl_setup_info_msg body;
+};
+
+struct ipw_setup_reboot_msg_ack {
+       struct ipw_tx_packet header;
+       struct TlSetupRebootMsgAck body;
+};
+
+/* This handles the actual initialization of the card */
+static void __handle_setup_get_version_rsp(struct ipw_hardware *hw)
+{
+       struct ipw_setup_config_packet *config_packet;
+       struct ipw_setup_config_done_packet *config_done_packet;
+       struct ipw_setup_open_packet *open_packet;
+       struct ipw_setup_info_packet *info_packet;
+       int port;
+       unsigned int channel_idx;
+
+       /* generate config packet */
+       for (port = 1; port <= NL_NUM_OF_ADDRESSES; port++) {
+               config_packet = alloc_ctrl_packet(
+                               sizeof(struct ipw_setup_config_packet),
+                               ADDR_SETUP_PROT,
+                               TL_PROTOCOLID_SETUP,
+                               TL_SETUP_SIGNO_CONFIG_MSG);
+               if (!config_packet)
+                       goto exit_nomem;
+               config_packet->header.length = sizeof(struct tl_setup_config_msg);
+               config_packet->body.port_no = port;
+               config_packet->body.prio_data = PRIO_DATA;
+               config_packet->body.prio_ctrl = PRIO_CTRL;
+               send_packet(hw, PRIO_SETUP, &config_packet->header);
+       }
+       config_done_packet = alloc_ctrl_packet(
+                       sizeof(struct ipw_setup_config_done_packet),
+                       ADDR_SETUP_PROT,
+                       TL_PROTOCOLID_SETUP,
+                       TL_SETUP_SIGNO_CONFIG_DONE_MSG);
+       if (!config_done_packet)
+               goto exit_nomem;
+       config_done_packet->header.length = sizeof(struct tl_setup_config_done_msg);
+       send_packet(hw, PRIO_SETUP, &config_done_packet->header);
+
+       /* generate open packet */
+       for (port = 1; port <= NL_NUM_OF_ADDRESSES; port++) {
+               open_packet = alloc_ctrl_packet(
+                               sizeof(struct ipw_setup_open_packet),
+                               ADDR_SETUP_PROT,
+                               TL_PROTOCOLID_SETUP,
+                               TL_SETUP_SIGNO_OPEN_MSG);
+               if (!open_packet)
+                       goto exit_nomem;
+               open_packet->header.length = sizeof(struct tl_setup_open_msg);
+               open_packet->body.port_no = port;
+               send_packet(hw, PRIO_SETUP, &open_packet->header);
+       }
+       for (channel_idx = 0;
+                       channel_idx < NL_NUM_OF_ADDRESSES; channel_idx++) {
+               int ret;
+
+               ret = set_DTR(hw, PRIO_SETUP, channel_idx,
+                       (hw->control_lines[channel_idx] &
+                        IPW_CONTROL_LINE_DTR) != 0);
+               if (ret) {
+                       printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                                       ": error setting DTR (%d)\n", ret);
+                       return;
+               }
+
+               set_RTS(hw, PRIO_SETUP, channel_idx,
+                       (hw->control_lines [channel_idx] &
+                        IPW_CONTROL_LINE_RTS) != 0);
+               if (ret) {
+                       printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                                       ": error setting RTS (%d)\n", ret);
+                       return;
+               }
+       }
+       /*
+        * For NDIS we assume that we are using sync PPP frames, for COM async.
+        * This driver uses NDIS mode too. We don't bother with translation
+        * from async -> sync PPP.
+        */
+       info_packet = alloc_ctrl_packet(sizeof(struct ipw_setup_info_packet),
+                       ADDR_SETUP_PROT,
+                       TL_PROTOCOLID_SETUP,
+                       TL_SETUP_SIGNO_INFO_MSG);
+       if (!info_packet)
+               goto exit_nomem;
+       info_packet->header.length = sizeof(struct tl_setup_info_msg);
+       info_packet->body.driver_type = NDISWAN_DRIVER;
+       info_packet->body.major_version = NDISWAN_DRIVER_MAJOR_VERSION;
+       info_packet->body.minor_version = NDISWAN_DRIVER_MINOR_VERSION;
+       send_packet(hw, PRIO_SETUP, &info_packet->header);
+
+       /* Initialization is now complete, so we clear the 'to_setup' flag */
+       hw->to_setup = 0;
+
+       return;
+
+exit_nomem:
+       printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                       ": not enough memory to alloc control packet\n");
+       hw->to_setup = -1;
+}
+
+static void handle_setup_get_version_rsp(struct ipw_hardware *hw,
+               unsigned char vers_no)
+{
+       del_timer(&hw->setup_timer);
+       hw->initializing = 0;
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": card is ready.\n");
+
+       if (vers_no == TL_SETUP_VERSION)
+               __handle_setup_get_version_rsp(hw);
+       else
+               printk(KERN_ERR
+                               IPWIRELESS_PCCARD_NAME
+                               ": invalid hardware version no %u\n",
+                               (unsigned int) vers_no);
+}
+
+static void ipw_send_setup_packet(struct ipw_hardware *hw)
+{
+       struct ipw_setup_get_version_query_packet *ver_packet;
+
+       ver_packet = alloc_ctrl_packet(
+                       sizeof(struct ipw_setup_get_version_query_packet),
+                       ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP,
+                       TL_SETUP_SIGNO_GET_VERSION_QRY);
+       ver_packet->header.length = sizeof(struct tl_setup_get_version_qry);
+
+       /*
+        * Response is handled in handle_received_SETUP_packet
+        */
+       send_packet(hw, PRIO_SETUP, &ver_packet->header);
+}
+
+static void handle_received_SETUP_packet(struct ipw_hardware *hw,
+                                        unsigned int address,
+                                        unsigned char *data, int len,
+                                        int is_last)
+{
+       union ipw_setup_rx_msg *rx_msg = (union ipw_setup_rx_msg *) data;
+
+       if (address != ADDR_SETUP_PROT) {
+               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                      ": setup packet has bad address %d\n", address);
+               return;
+       }
+
+       switch (rx_msg->sig_no) {
+       case TL_SETUP_SIGNO_GET_VERSION_RSP:
+               if (hw->to_setup)
+                       handle_setup_get_version_rsp(hw,
+                                       rx_msg->version_rsp_msg.version);
+               break;
+
+       case TL_SETUP_SIGNO_OPEN_MSG:
+               if (ipwireless_debug) {
+                       unsigned int channel_idx = rx_msg->open_msg.port_no - 1;
+
+                       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                              ": OPEN_MSG [channel %u] reply received\n",
+                              channel_idx);
+               }
+               break;
+
+       case TL_SETUP_SIGNO_INFO_MSG_ACK:
+               if (ipwireless_debug)
+                       printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
+                              ": card successfully configured as NDISWAN\n");
+               break;
+
+       case TL_SETUP_SIGNO_REBOOT_MSG:
+               if (hw->to_setup)
+                       printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
+                              ": Setup not completed - ignoring reboot msg\n");
+               else {
+                       struct ipw_setup_reboot_msg_ack *packet;
+
+                       printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
+                              ": Acknowledging REBOOT message\n");
+                       packet = alloc_ctrl_packet(
+                                       sizeof(struct ipw_setup_reboot_msg_ack),
+                                       ADDR_SETUP_PROT, TL_PROTOCOLID_SETUP,
+                                       TL_SETUP_SIGNO_REBOOT_MSG_ACK);
+                       packet->header.length =
+                               sizeof(struct TlSetupRebootMsgAck);
+                       send_packet(hw, PRIO_SETUP, &packet->header);
+                       if (hw->reboot_callback)
+                               hw->reboot_callback(hw->reboot_callback_data);
+               }
+               break;
+
+       default:
+               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                      ": unknown setup message %u received\n",
+                      (unsigned int) rx_msg->sig_no);
+       }
+}
+
+static void do_close_hardware(struct ipw_hardware *hw)
+{
+       unsigned int irqn;
+
+       if (hw->hw_version == HW_VERSION_1) {
+               /* Disable TX and RX interrupts. */
+               outw(0, hw->base_port + IOIER);
+
+               /* Acknowledge any outstanding interrupt requests */
+               irqn = inw(hw->base_port + IOIR);
+               if (irqn & IR_TXINTR)
+                       outw(IR_TXINTR, hw->base_port + IOIR);
+               if (irqn & IR_RXINTR)
+                       outw(IR_RXINTR, hw->base_port + IOIR);
+
+               synchronize_irq(hw->irq);
+       }
+}
+
+struct ipw_hardware *ipwireless_hardware_create(void)
+{
+       int i;
+       struct ipw_hardware *hw =
+               kzalloc(sizeof(struct ipw_hardware), GFP_KERNEL);
+
+       if (!hw)
+               return NULL;
+
+       hw->irq = -1;
+       hw->initializing = 1;
+       hw->tx_ready = 1;
+       hw->rx_bytes_queued = 0;
+       hw->rx_pool_size = 0;
+       hw->last_memtx_serial = (unsigned short) 0xffff;
+       for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
+               INIT_LIST_HEAD(&hw->tx_queue[i]);
+
+       INIT_LIST_HEAD(&hw->rx_queue);
+       INIT_LIST_HEAD(&hw->rx_pool);
+       spin_lock_init(&hw->spinlock);
+       tasklet_init(&hw->tasklet, ipwireless_do_tasklet, (unsigned long) hw);
+       INIT_WORK(&hw->work_rx, ipw_receive_data_work);
+       setup_timer(&hw->setup_timer, ipwireless_setup_timer,
+                       (unsigned long) hw);
+
+       return hw;
+}
+
+void ipwireless_init_hardware_v1(struct ipw_hardware *hw,
+               unsigned int base_port,
+               void __iomem *attr_memory,
+               void __iomem *common_memory,
+               int is_v2_card,
+               void (*reboot_callback) (void *data),
+               void *reboot_callback_data)
+{
+       if (hw->removed) {
+               hw->removed = 0;
+               enable_irq(hw->irq);
+       }
+       hw->base_port = base_port;
+       hw->hw_version = is_v2_card ? HW_VERSION_2 : HW_VERSION_1;
+       hw->ll_mtu = hw->hw_version == HW_VERSION_1 ? LL_MTU_V1 : LL_MTU_V2;
+       hw->memregs_CCR = (struct MEMCCR __iomem *)
+                       ((unsigned short __iomem *) attr_memory + 0x200);
+       hw->memory_info_regs = (struct MEMINFREG __iomem *) common_memory;
+       hw->memreg_tx = &hw->memory_info_regs->memreg_tx_new;
+       hw->reboot_callback = reboot_callback;
+       hw->reboot_callback_data = reboot_callback_data;
+}
+
+void ipwireless_init_hardware_v2_v3(struct ipw_hardware *hw)
+{
+       hw->initializing = 1;
+       hw->init_loops = 0;
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+              ": waiting for card to start up...\n");
+       ipwireless_setup_timer((unsigned long) hw);
+}
+
+static void ipwireless_setup_timer(unsigned long data)
+{
+       struct ipw_hardware *hw = (struct ipw_hardware *) data;
+
+       hw->init_loops++;
+
+       if (hw->init_loops == TL_SETUP_MAX_VERSION_QRY &&
+                       hw->hw_version == HW_VERSION_2 &&
+                       hw->memreg_tx == &hw->memory_info_regs->memreg_tx_new) {
+               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                               ": failed to startup using TX2, trying TX\n");
+
+               hw->memreg_tx = &hw->memory_info_regs->memreg_tx_old;
+               hw->init_loops = 0;
+       }
+       /* Give up after a certain number of retries */
+       if (hw->init_loops == TL_SETUP_MAX_VERSION_QRY) {
+               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                      ": card failed to start up!\n");
+               hw->initializing = 0;
+       } else {
+               /* Do not attempt to write to the board if it is not present. */
+               if (is_card_present(hw)) {
+                       unsigned long flags;
+
+                       spin_lock_irqsave(&hw->spinlock, flags);
+                       hw->to_setup = 1;
+                       hw->tx_ready = 1;
+                       spin_unlock_irqrestore(&hw->spinlock, flags);
+                       tasklet_schedule(&hw->tasklet);
+               }
+
+               mod_timer(&hw->setup_timer,
+                       jiffies + msecs_to_jiffies(TL_SETUP_VERSION_QRY_TMO));
+       }
+}
+
+/*
+ * Stop any interrupts from executing so that, once this function returns,
+ * other layers of the driver can be sure they won't get any more callbacks.
+ * Thus must be called on a proper process context.
+ */
+void ipwireless_stop_interrupts(struct ipw_hardware *hw)
+{
+       if (!hw->shutting_down) {
+               /* Tell everyone we are going down. */
+               hw->shutting_down = 1;
+               del_timer(&hw->setup_timer);
+
+               /* Prevent the hardware from sending any more interrupts */
+               do_close_hardware(hw);
+       }
+}
+
+void ipwireless_hardware_free(struct ipw_hardware *hw)
+{
+       int i;
+       struct ipw_rx_packet *rp, *rq;
+       struct ipw_tx_packet *tp, *tq;
+
+       ipwireless_stop_interrupts(hw);
+
+       flush_scheduled_work();
+
+       for (i = 0; i < NL_NUM_OF_ADDRESSES; i++)
+               if (hw->packet_assembler[i] != NULL)
+                       kfree(hw->packet_assembler[i]);
+
+       for (i = 0; i < NL_NUM_OF_PRIORITIES; i++)
+               list_for_each_entry_safe(tp, tq, &hw->tx_queue[i], queue) {
+                       list_del(&tp->queue);
+                       kfree(tp);
+               }
+
+       list_for_each_entry_safe(rp, rq, &hw->rx_queue, queue) {
+               list_del(&rp->queue);
+               kfree(rp);
+       }
+
+       list_for_each_entry_safe(rp, rq, &hw->rx_pool, queue) {
+               list_del(&rp->queue);
+               kfree(rp);
+       }
+       kfree(hw);
+}
+
+/*
+ * Associate the specified network with this hardware, so it will receive events
+ * from it.
+ */
+void ipwireless_associate_network(struct ipw_hardware *hw,
+                                 struct ipw_network *network)
+{
+       hw->network = network;
+}
diff --git a/drivers/char/pcmcia/ipwireless/hardware.h b/drivers/char/pcmcia/ipwireless/hardware.h
new file mode 100644 (file)
index 0000000..c83190f
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#ifndef _IPWIRELESS_CS_HARDWARE_H_
+#define _IPWIRELESS_CS_HARDWARE_H_
+
+#include <linux/types.h>
+#include <linux/sched.h>
+#include <linux/interrupt.h>
+
+#define IPW_CONTROL_LINE_CTS 0x0001
+#define IPW_CONTROL_LINE_DCD 0x0002
+#define IPW_CONTROL_LINE_DSR 0x0004
+#define IPW_CONTROL_LINE_RI  0x0008
+#define IPW_CONTROL_LINE_DTR 0x0010
+#define IPW_CONTROL_LINE_RTS 0x0020
+
+struct ipw_hardware;
+struct ipw_network;
+
+struct ipw_hardware *ipwireless_hardware_create(void);
+void ipwireless_hardware_free(struct ipw_hardware *hw);
+irqreturn_t ipwireless_interrupt(int irq, void *dev_id, struct pt_regs *regs);
+int ipwireless_set_DTR(struct ipw_hardware *hw, unsigned int channel_idx,
+               int state);
+int ipwireless_set_RTS(struct ipw_hardware *hw, unsigned int channel_idx,
+               int state);
+int ipwireless_send_packet(struct ipw_hardware *hw,
+                           unsigned int channel_idx,
+                           unsigned char *data,
+                           unsigned int length,
+                           void (*packet_sent_callback) (void *cb,
+                                                         unsigned int length),
+                           void *sent_cb_data);
+void ipwireless_associate_network(struct ipw_hardware *hw,
+               struct ipw_network *net);
+void ipwireless_stop_interrupts(struct ipw_hardware *hw);
+void ipwireless_init_hardware_v1(struct ipw_hardware *hw,
+                                unsigned int base_port,
+                                void __iomem *attr_memory,
+                                void __iomem *common_memory,
+                                int is_v2_card,
+                                void (*reboot_cb) (void *data),
+                                void *reboot_cb_data);
+void ipwireless_init_hardware_v2_v3(struct ipw_hardware *hw);
+void ipwireless_sleep(unsigned int tenths);
+int ipwireless_dump_hardware_state(char *p, size_t limit,
+                                  struct ipw_hardware *hw);
+
+#endif
diff --git a/drivers/char/pcmcia/ipwireless/main.c b/drivers/char/pcmcia/ipwireless/main.c
new file mode 100644 (file)
index 0000000..00c7f84
--- /dev/null
@@ -0,0 +1,501 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#include "hardware.h"
+#include "network.h"
+#include "main.h"
+#include "tty.h"
+
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+
+#include <pcmcia/version.h>
+#include <pcmcia/cisreg.h>
+#include <pcmcia/device_id.h>
+#include <pcmcia/ss.h>
+#include <pcmcia/ds.h>
+#include <pcmcia/cs.h>
+
+static struct pcmcia_device_id ipw_ids[] = {
+       PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0100),
+       PCMCIA_DEVICE_MANF_CARD(0x02f2, 0x0200),
+       PCMCIA_DEVICE_NULL
+};
+MODULE_DEVICE_TABLE(pcmcia, ipw_ids);
+
+static void ipwireless_detach(struct pcmcia_device *link);
+
+/*
+ * Module params
+ */
+/* Debug mode: more verbose, print sent/recv bytes */
+int ipwireless_debug;
+int ipwireless_loopback;
+int ipwireless_out_queue = 1;
+
+module_param_named(debug, ipwireless_debug, int, 0);
+module_param_named(loopback, ipwireless_loopback, int, 0);
+module_param_named(out_queue, ipwireless_out_queue, int, 0);
+MODULE_PARM_DESC(debug, "switch on debug messages [0]");
+MODULE_PARM_DESC(loopback,
+               "debug: enable ras_raw channel [0]");
+MODULE_PARM_DESC(out_queue, "debug: set size of outgoing queue [1]");
+
+/* Executes in process context. */
+static void signalled_reboot_work(struct work_struct *work_reboot)
+{
+       struct ipw_dev *ipw = container_of(work_reboot, struct ipw_dev,
+                       work_reboot);
+       struct pcmcia_device *link = ipw->link;
+       int ret = pccard_reset_card(link->socket);
+
+       if (ret != CS_SUCCESS)
+               cs_error(link, ResetCard, ret);
+}
+
+static void signalled_reboot_callback(void *callback_data)
+{
+       struct ipw_dev *ipw = (struct ipw_dev *) callback_data;
+
+       /* Delegate to process context. */
+       schedule_work(&ipw->work_reboot);
+}
+
+static int config_ipwireless(struct ipw_dev *ipw)
+{
+       struct pcmcia_device *link = ipw->link;
+       int ret;
+       config_info_t conf;
+       tuple_t tuple;
+       unsigned short buf[64];
+       cisparse_t parse;
+       unsigned short cor_value;
+       win_req_t request_attr_memory;
+       win_req_t request_common_memory;
+       memreq_t memreq_attr_memory;
+       memreq_t memreq_common_memory;
+
+       ipw->is_v2_card = 0;
+
+       tuple.Attributes = 0;
+       tuple.TupleData = (cisdata_t *) buf;
+       tuple.TupleDataMax = sizeof(buf);
+       tuple.TupleOffset = 0;
+
+       tuple.DesiredTuple = RETURN_FIRST_TUPLE;
+
+       ret = pcmcia_get_first_tuple(link, &tuple);
+
+       while (ret == 0) {
+               ret = pcmcia_get_tuple_data(link, &tuple);
+
+               if (ret != CS_SUCCESS) {
+                       cs_error(link, GetTupleData, ret);
+                       goto exit0;
+               }
+               ret = pcmcia_get_next_tuple(link, &tuple);
+       }
+
+       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
+
+       ret = pcmcia_get_first_tuple(link, &tuple);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetFirstTuple, ret);
+               goto exit0;
+       }
+
+       ret = pcmcia_get_tuple_data(link, &tuple);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetTupleData, ret);
+               goto exit0;
+       }
+
+       ret = pcmcia_parse_tuple(link, &tuple, &parse);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, ParseTuple, ret);
+               goto exit0;
+       }
+
+       link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
+       link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
+       link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
+       link->io.IOAddrLines = 16;
+
+       link->irq.IRQInfo1 = parse.cftable_entry.irq.IRQInfo1;
+
+       /* 0x40 causes it to generate level mode interrupts. */
+       /* 0x04 enables IREQ pin. */
+       cor_value = parse.cftable_entry.index | 0x44;
+       link->conf.ConfigIndex = cor_value;
+
+       /* IRQ and I/O settings */
+       tuple.DesiredTuple = CISTPL_CONFIG;
+
+       ret = pcmcia_get_first_tuple(link, &tuple);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetFirstTuple, ret);
+               goto exit0;
+       }
+
+       ret = pcmcia_get_tuple_data(link, &tuple);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetTupleData, ret);
+               goto exit0;
+       }
+
+       ret = pcmcia_parse_tuple(link, &tuple, &parse);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetTupleData, ret);
+               goto exit0;
+       }
+       link->conf.Attributes = CONF_ENABLE_IRQ;
+       link->conf.ConfigBase = parse.config.base;
+       link->conf.Present = parse.config.rmask[0];
+       link->conf.IntType = INT_MEMORY_AND_IO;
+
+       link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING | IRQ_HANDLE_PRESENT;
+       link->irq.Handler = ipwireless_interrupt;
+       link->irq.Instance = ipw->hardware;
+
+       ret = pcmcia_request_io(link, &link->io);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, RequestIO, ret);
+               goto exit0;
+       }
+
+       /* memory settings */
+
+       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
+
+       ret = pcmcia_get_first_tuple(link, &tuple);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetFirstTuple, ret);
+               goto exit1;
+       }
+
+       ret = pcmcia_get_tuple_data(link, &tuple);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetTupleData, ret);
+               goto exit1;
+       }
+
+       ret = pcmcia_parse_tuple(link, &tuple, &parse);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, ParseTuple, ret);
+               goto exit1;
+       }
+
+       if (parse.cftable_entry.mem.nwin > 0) {
+               request_common_memory.Attributes =
+                       WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_CM | WIN_ENABLE;
+               request_common_memory.Base =
+                       parse.cftable_entry.mem.win[0].host_addr;
+               request_common_memory.Size = parse.cftable_entry.mem.win[0].len;
+               if (request_common_memory.Size < 0x1000)
+                       request_common_memory.Size = 0x1000;
+               request_common_memory.AccessSpeed = 0;
+
+               ret = pcmcia_request_window(&link, &request_common_memory,
+                               &ipw->handle_common_memory);
+
+               if (ret != CS_SUCCESS) {
+                       cs_error(link, RequestWindow, ret);
+                       goto exit1;
+               }
+
+               memreq_common_memory.CardOffset =
+                       parse.cftable_entry.mem.win[0].card_addr;
+               memreq_common_memory.Page = 0;
+
+               ret = pcmcia_map_mem_page(ipw->handle_common_memory,
+                               &memreq_common_memory);
+
+               if (ret != CS_SUCCESS) {
+                       cs_error(link, MapMemPage, ret);
+                       goto exit1;
+               }
+
+               ipw->is_v2_card =
+                       parse.cftable_entry.mem.win[0].len == 0x100;
+
+               ipw->common_memory = ioremap(request_common_memory.Base,
+                               request_common_memory.Size);
+
+               request_attr_memory.Attributes =
+                       WIN_DATA_WIDTH_16 | WIN_MEMORY_TYPE_AM | WIN_ENABLE;
+               request_attr_memory.Base = 0;
+               request_attr_memory.Size = 0;   /* this used to be 0x1000 */
+               request_attr_memory.AccessSpeed = 0;
+
+               ret = pcmcia_request_window(&link, &request_attr_memory,
+                               &ipw->handle_attr_memory);
+
+               if (ret != CS_SUCCESS) {
+                       cs_error(link, RequestWindow, ret);
+                       goto exit2;
+               }
+
+               memreq_attr_memory.CardOffset = 0;
+               memreq_attr_memory.Page = 0;
+
+               ret = pcmcia_map_mem_page(ipw->handle_attr_memory,
+                               &memreq_attr_memory);
+
+               if (ret != CS_SUCCESS) {
+                       cs_error(link, MapMemPage, ret);
+                       goto exit2;
+               }
+
+               ipw->attr_memory = ioremap(request_attr_memory.Base,
+                               request_attr_memory.Size);
+       }
+
+       INIT_WORK(&ipw->work_reboot, signalled_reboot_work);
+
+       ipwireless_init_hardware_v1(ipw->hardware, link->io.BasePort1,
+                                   ipw->attr_memory, ipw->common_memory,
+                                   ipw->is_v2_card, signalled_reboot_callback,
+                                   ipw);
+
+       ret = pcmcia_request_irq(link, &link->irq);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, RequestIRQ, ret);
+               goto exit3;
+       }
+
+       /* Look up current Vcc */
+
+       ret = pcmcia_get_configuration_info(link, &conf);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, GetConfigurationInfo, ret);
+               goto exit4;
+       }
+
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n",
+                       ipw->is_v2_card ? "V2/V3" : "V1");
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                       ": I/O ports 0x%04x-0x%04x, irq %d\n",
+                       (unsigned int) link->io.BasePort1,
+                       (unsigned int) (link->io.BasePort1 +
+                               link->io.NumPorts1 - 1),
+                       (unsigned int) link->irq.AssignedIRQ);
+       if (ipw->attr_memory && ipw->common_memory)
+               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                               ": attr memory 0x%08lx-0x%08lx, "
+                               "common memory 0x%08lx-0x%08lx\n",
+                               request_attr_memory.Base,
+                               request_attr_memory.Base
+                               + request_attr_memory.Size - 1,
+                               request_common_memory.Base,
+                               request_common_memory.Base
+                               + request_common_memory.Size - 1);
+
+       ipw->network = ipwireless_network_create(ipw->hardware);
+       if (!ipw->network)
+               goto exit3;
+
+       ipw->tty = ipwireless_tty_create(ipw->hardware, ipw->network,
+                       ipw->nodes);
+       if (!ipw->tty)
+               goto exit3;
+
+       ipwireless_init_hardware_v2_v3(ipw->hardware);
+
+       /*
+        * Do the RequestConfiguration last, because it enables interrupts.
+        * Then we don't get any interrupts before we're ready for them.
+        */
+       ret = pcmcia_request_configuration(link, &link->conf);
+
+       if (ret != CS_SUCCESS) {
+               cs_error(link, RequestConfiguration, ret);
+               goto exit4;
+       }
+
+       link->dev_node = &ipw->nodes[0];
+
+       return 0;
+
+exit4:
+       pcmcia_disable_device(link);
+exit3:
+       if (ipw->attr_memory) {
+               iounmap(ipw->attr_memory);
+               pcmcia_release_window(ipw->handle_attr_memory);
+               pcmcia_disable_device(link);
+       }
+exit2:
+       if (ipw->common_memory) {
+               iounmap(ipw->common_memory);
+               pcmcia_release_window(ipw->handle_common_memory);
+       }
+exit1:
+       pcmcia_disable_device(link);
+exit0:
+       return -1;
+}
+
+static void release_ipwireless(struct ipw_dev *ipw)
+{
+       struct pcmcia_device *link = ipw->link;
+
+       pcmcia_disable_device(link);
+
+       if (ipw->common_memory)
+               iounmap(ipw->common_memory);
+       if (ipw->attr_memory)
+               iounmap(ipw->attr_memory);
+       if (ipw->common_memory)
+               pcmcia_release_window(ipw->handle_common_memory);
+       if (ipw->attr_memory)
+               pcmcia_release_window(ipw->handle_attr_memory);
+       pcmcia_disable_device(link);
+}
+
+/*
+ * ipwireless_attach() creates an "instance" of the driver, allocating
+ * local data structures for one device (one interface).  The device
+ * is registered with Card Services.
+ *
+ * The pcmcia_device structure is initialized, but we don't actually
+ * configure the card at this point -- we wait until we receive a
+ * card insertion event.
+ */
+static int ipwireless_attach(struct pcmcia_device *link)
+{
+       struct ipw_dev *ipw;
+       int ret;
+
+       ipw = kzalloc(sizeof(struct ipw_dev), GFP_KERNEL);
+       if (!ipw)
+               return -ENOMEM;
+
+       ipw->link = link;
+       link->priv = ipw;
+       link->irq.Instance = ipw;
+
+       /* Link this device into our device list. */
+       link->dev_node = &ipw->nodes[0];
+
+       ipw->hardware = ipwireless_hardware_create();
+       if (!ipw->hardware) {
+               kfree(ipw);
+               return -ENOMEM;
+       }
+       /* RegisterClient will call config_ipwireless */
+
+       ret = config_ipwireless(ipw);
+
+       if (ret != 0) {
+               cs_error(link, RegisterClient, ret);
+               ipwireless_detach(link);
+               return ret;
+       }
+
+       return 0;
+}
+
+/*
+ * This deletes a driver "instance".  The device is de-registered with
+ * Card Services.  If it has been released, all local data structures
+ * are freed.  Otherwise, the structures will be freed when the device
+ * is released.
+ */
+static void ipwireless_detach(struct pcmcia_device *link)
+{
+       struct ipw_dev *ipw = link->priv;
+
+       release_ipwireless(ipw);
+
+       /* Break the link with Card Services */
+       if (link)
+               pcmcia_disable_device(link);
+
+       if (ipw->tty != NULL)
+               ipwireless_tty_free(ipw->tty);
+       if (ipw->network != NULL)
+               ipwireless_network_free(ipw->network);
+       if (ipw->hardware != NULL)
+               ipwireless_hardware_free(ipw->hardware);
+       kfree(ipw);
+}
+
+static struct pcmcia_driver me = {
+       .owner          = THIS_MODULE,
+       .probe          = ipwireless_attach,
+       .remove         = ipwireless_detach,
+       .drv = { .name  = IPWIRELESS_PCCARD_NAME },
+       .id_table       = ipw_ids
+};
+
+/*
+ * Module insertion : initialisation of the module.
+ * Register the card with cardmgr...
+ */
+static int __init init_ipwireless(void)
+{
+       int ret;
+
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
+              IPWIRELESS_PCMCIA_VERSION " by " IPWIRELESS_PCMCIA_AUTHOR "\n");
+
+       ret = ipwireless_tty_init();
+       if (ret != 0)
+               return ret;
+
+       ret = pcmcia_register_driver(&me);
+       if (ret != 0)
+               ipwireless_tty_release();
+
+       return ret;
+}
+
+/*
+ * Module removal
+ */
+static void __exit exit_ipwireless(void)
+{
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME " "
+                       IPWIRELESS_PCMCIA_VERSION " removed\n");
+
+       pcmcia_unregister_driver(&me);
+       ipwireless_tty_release();
+}
+
+module_init(init_ipwireless);
+module_exit(exit_ipwireless);
+
+MODULE_AUTHOR(IPWIRELESS_PCMCIA_AUTHOR);
+MODULE_DESCRIPTION(IPWIRELESS_PCCARD_NAME " " IPWIRELESS_PCMCIA_VERSION);
+MODULE_LICENSE("GPL");
diff --git a/drivers/char/pcmcia/ipwireless/main.h b/drivers/char/pcmcia/ipwireless/main.h
new file mode 100644 (file)
index 0000000..1bfdcc8
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#ifndef _IPWIRELESS_CS_H_
+#define _IPWIRELESS_CS_H_
+
+#include <linux/sched.h>
+#include <linux/types.h>
+
+#include <pcmcia/cs_types.h>
+#include <pcmcia/cs.h>
+#include <pcmcia/cistpl.h>
+#include <pcmcia/ds.h>
+
+#include "hardware.h"
+
+#define IPWIRELESS_PCCARD_NAME         "ipwireless"
+#define IPWIRELESS_PCMCIA_VERSION      "1.1"
+#define IPWIRELESS_PCMCIA_AUTHOR        \
+       "Stephen Blackheath, Ben Martel, Jiri Kosina and David Sterba"
+
+#define IPWIRELESS_TX_QUEUE_SIZE  262144
+#define IPWIRELESS_RX_QUEUE_SIZE  262144
+
+#define IPWIRELESS_STATE_DEBUG
+
+struct ipw_hardware;
+struct ipw_network;
+struct ipw_tty;
+
+struct ipw_dev {
+       struct pcmcia_device *link;
+       int is_v2_card;
+       window_handle_t handle_attr_memory;
+       void __iomem *attr_memory;
+       window_handle_t handle_common_memory;
+       void __iomem *common_memory;
+       dev_node_t nodes[2];
+       /* Reference to attribute memory, containing CIS data */
+       void *attribute_memory;
+
+       /* Hardware context */
+       struct ipw_hardware *hardware;
+       /* Network layer context */
+       struct ipw_network *network;
+       /* TTY device context */
+       struct ipw_tty *tty;
+       struct work_struct work_reboot;
+};
+
+/* Module parametres */
+extern int ipwireless_debug;
+extern int ipwireless_loopback;
+extern int ipwireless_out_queue;
+
+#endif
diff --git a/drivers/char/pcmcia/ipwireless/network.c b/drivers/char/pcmcia/ipwireless/network.c
new file mode 100644 (file)
index 0000000..ff35230
--- /dev/null
@@ -0,0 +1,512 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/mutex.h>
+#include <linux/netdevice.h>
+#include <linux/ppp_channel.h>
+#include <linux/ppp_defs.h>
+#include <linux/if_ppp.h>
+#include <linux/skbuff.h>
+
+#include "network.h"
+#include "hardware.h"
+#include "main.h"
+#include "tty.h"
+
+#define MAX_OUTGOING_PACKETS_QUEUED   ipwireless_out_queue
+#define MAX_ASSOCIATED_TTYS 2
+
+#define SC_RCV_BITS     (SC_RCV_B7_1|SC_RCV_B7_0|SC_RCV_ODDP|SC_RCV_EVNP)
+
+struct ipw_network {
+       /* Hardware context, used for calls to hardware layer. */
+       struct ipw_hardware *hardware;
+       /* Context for kernel 'generic_ppp' functionality */
+       struct ppp_channel *ppp_channel;
+       /* tty context connected with IPW console */
+       struct ipw_tty *associated_ttys[NO_OF_IPW_CHANNELS][MAX_ASSOCIATED_TTYS];
+       /* True if ppp needs waking up once we're ready to xmit */
+       int ppp_blocked;
+       /* Number of packets queued up in hardware module. */
+       int outgoing_packets_queued;
+       /* Spinlock to avoid interrupts during shutdown */
+       spinlock_t spinlock;
+       struct mutex close_lock;
+
+       /* PPP ioctl data, not actually used anywere */
+       unsigned int flags;
+       unsigned int rbits;
+       u32 xaccm[8];
+       u32 raccm;
+       int mru;
+
+       int shutting_down;
+       unsigned int ras_control_lines;
+
+       struct work_struct work_go_online;
+       struct work_struct work_go_offline;
+};
+
+
+#ifdef IPWIRELESS_STATE_DEBUG
+int ipwireless_dump_network_state(char *p, size_t limit,
+                                 struct ipw_network *network)
+{
+       return snprintf(p, limit,
+                       "debug: ppp_blocked=%d\n"
+                       "debug: outgoing_packets_queued=%d\n"
+                       "debug: network.shutting_down=%d\n",
+                       network->ppp_blocked,
+                       network->outgoing_packets_queued,
+                       network->shutting_down);
+}
+#endif
+
+static void notify_packet_sent(void *callback_data, unsigned int packet_length)
+{
+       struct ipw_network *network = callback_data;
+       unsigned long flags;
+
+       spin_lock_irqsave(&network->spinlock, flags);
+       network->outgoing_packets_queued--;
+       if (network->ppp_channel != NULL) {
+               if (network->ppp_blocked) {
+                       network->ppp_blocked = 0;
+                       spin_unlock_irqrestore(&network->spinlock, flags);
+                       ppp_output_wakeup(network->ppp_channel);
+                       if (ipwireless_debug)
+                               printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+                                      ": ppp unblocked\n");
+               } else
+                       spin_unlock_irqrestore(&network->spinlock, flags);
+       } else
+               spin_unlock_irqrestore(&network->spinlock, flags);
+}
+
+/*
+ * Called by the ppp system when it has a packet to send to the hardware.
+ */
+static int ipwireless_ppp_start_xmit(struct ppp_channel *ppp_channel,
+                                    struct sk_buff *skb)
+{
+       struct ipw_network *network = ppp_channel->private;
+       unsigned long flags;
+
+       spin_lock_irqsave(&network->spinlock, flags);
+       if (network->outgoing_packets_queued < MAX_OUTGOING_PACKETS_QUEUED) {
+               unsigned char *buf;
+               static unsigned char header[] = {
+                       PPP_ALLSTATIONS, /* 0xff */
+                       PPP_UI,          /* 0x03 */
+               };
+               int ret;
+
+               network->outgoing_packets_queued++;
+               spin_unlock_irqrestore(&network->spinlock, flags);
+
+               /*
+                * If we have the requested amount of headroom in the skb we
+                * were handed, then we can add the header efficiently.
+                */
+               if (skb_headroom(skb) >= 2) {
+                       memcpy(skb_push(skb, 2), header, 2);
+                       ret = ipwireless_send_packet(network->hardware,
+                                              IPW_CHANNEL_RAS, skb->data,
+                                              skb->len,
+                                              notify_packet_sent,
+                                              network);
+                       if (ret == -1) {
+                               skb_pull(skb, 2);
+                               return 0;
+                       }
+               } else {
+                       /* Otherwise (rarely) we do it inefficiently. */
+                       buf = kmalloc(skb->len + 2, GFP_ATOMIC);
+                       if (!buf)
+                               return 0;
+                       memcpy(buf + 2, skb->data, skb->len);
+                       memcpy(buf, header, 2);
+                       ret = ipwireless_send_packet(network->hardware,
+                                              IPW_CHANNEL_RAS, buf,
+                                              skb->len + 2,
+                                              notify_packet_sent,
+                                              network);
+                       kfree(buf);
+                       if (ret == -1)
+                               return 0;
+               }
+               kfree_skb(skb);
+               return 1;
+       } else {
+               /*
+                * Otherwise reject the packet, and flag that the ppp system
+                * needs to be unblocked once we are ready to send.
+                */
+               network->ppp_blocked = 1;
+               spin_unlock_irqrestore(&network->spinlock, flags);
+               return 0;
+       }
+}
+
+/* Handle an ioctl call that has come in via ppp. (copy of ppp_async_ioctl() */
+static int ipwireless_ppp_ioctl(struct ppp_channel *ppp_channel,
+                               unsigned int cmd, unsigned long arg)
+{
+       struct ipw_network *network = ppp_channel->private;
+       int err, val;
+       u32 accm[8];
+       int __user *user_arg = (int __user *) arg;
+
+       err = -EFAULT;
+       switch (cmd) {
+       case PPPIOCGFLAGS:
+               val = network->flags | network->rbits;
+               if (put_user(val, user_arg))
+                       break;
+               err = 0;
+               break;
+
+       case PPPIOCSFLAGS:
+               if (get_user(val, user_arg))
+                       break;
+               network->flags = val & ~SC_RCV_BITS;
+               network->rbits = val & SC_RCV_BITS;
+               err = 0;
+               break;
+
+       case PPPIOCGASYNCMAP:
+               if (put_user(network->xaccm[0], user_arg))
+                       break;
+               err = 0;
+               break;
+
+       case PPPIOCSASYNCMAP:
+               if (get_user(network->xaccm[0], user_arg))
+                       break;
+               err = 0;
+               break;
+
+       case PPPIOCGRASYNCMAP:
+               if (put_user(network->raccm, user_arg))
+                       break;
+               err = 0;
+               break;
+
+       case PPPIOCSRASYNCMAP:
+               if (get_user(network->raccm, user_arg))
+                       break;
+               err = 0;
+               break;
+
+       case PPPIOCGXASYNCMAP:
+               if (copy_to_user((void __user *) arg, network->xaccm,
+                                       sizeof(network->xaccm)))
+                       break;
+               err = 0;
+               break;
+
+       case PPPIOCSXASYNCMAP:
+               if (copy_from_user(accm, (void __user *) arg, sizeof(accm)))
+                       break;
+               accm[2] &= ~0x40000000U;        /* can't escape 0x5e */
+               accm[3] |= 0x60000000U; /* must escape 0x7d, 0x7e */
+               memcpy(network->xaccm, accm, sizeof(network->xaccm));
+               err = 0;
+               break;
+
+       case PPPIOCGMRU:
+               if (put_user(network->mru, user_arg))
+                       break;
+               err = 0;
+               break;
+
+       case PPPIOCSMRU:
+               if (get_user(val, user_arg))
+                       break;
+               if (val < PPP_MRU)
+                       val = PPP_MRU;
+               network->mru = val;
+               err = 0;
+               break;
+
+       default:
+               err = -ENOTTY;
+       }
+
+       return err;
+}
+
+static struct ppp_channel_ops ipwireless_ppp_channel_ops = {
+       .start_xmit = ipwireless_ppp_start_xmit,
+       .ioctl      = ipwireless_ppp_ioctl
+};
+
+static void do_go_online(struct work_struct *work_go_online)
+{
+       struct ipw_network *network =
+               container_of(work_go_online, struct ipw_network,
+                               work_go_online);
+       unsigned long flags;
+
+       spin_lock_irqsave(&network->spinlock, flags);
+       if (!network->ppp_channel) {
+               struct ppp_channel *channel;
+
+               spin_unlock_irqrestore(&network->spinlock, flags);
+               channel = kzalloc(sizeof(struct ppp_channel), GFP_KERNEL);
+               if (!channel) {
+                       printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                                       ": unable to allocate PPP channel\n");
+                       return;
+               }
+               channel->private = network;
+               channel->mtu = 16384;   /* Wild guess */
+               channel->hdrlen = 2;
+               channel->ops = &ipwireless_ppp_channel_ops;
+
+               network->flags = 0;
+               network->rbits = 0;
+               network->mru = PPP_MRU;
+               memset(network->xaccm, 0, sizeof(network->xaccm));
+               network->xaccm[0] = ~0U;
+               network->xaccm[3] = 0x60000000U;
+               network->raccm = ~0U;
+               ppp_register_channel(channel);
+               spin_lock_irqsave(&network->spinlock, flags);
+               network->ppp_channel = channel;
+       }
+       spin_unlock_irqrestore(&network->spinlock, flags);
+}
+
+static void do_go_offline(struct work_struct *work_go_offline)
+{
+       struct ipw_network *network =
+               container_of(work_go_offline, struct ipw_network,
+                               work_go_offline);
+       unsigned long flags;
+
+       mutex_lock(&network->close_lock);
+       spin_lock_irqsave(&network->spinlock, flags);
+       if (network->ppp_channel != NULL) {
+               struct ppp_channel *channel = network->ppp_channel;
+
+               network->ppp_channel = NULL;
+               spin_unlock_irqrestore(&network->spinlock, flags);
+               mutex_unlock(&network->close_lock);
+               ppp_unregister_channel(channel);
+       } else {
+               spin_unlock_irqrestore(&network->spinlock, flags);
+               mutex_unlock(&network->close_lock);
+       }
+}
+
+void ipwireless_network_notify_control_line_change(struct ipw_network *network,
+                                                  unsigned int channel_idx,
+                                                  unsigned int control_lines,
+                                                  unsigned int changed_mask)
+{
+       int i;
+
+       if (channel_idx == IPW_CHANNEL_RAS)
+               network->ras_control_lines = control_lines;
+
+       for (i = 0; i < MAX_ASSOCIATED_TTYS; i++) {
+               struct ipw_tty *tty =
+                       network->associated_ttys[channel_idx][i];
+
+               /*
+                * If it's associated with a tty (other than the RAS channel
+                * when we're online), then send the data to that tty.  The RAS
+                * channel's data is handled above - it always goes through
+                * ppp_generic.
+                */
+               if (tty)
+                       ipwireless_tty_notify_control_line_change(tty,
+                                                                 channel_idx,
+                                                                 control_lines,
+                                                                 changed_mask);
+       }
+}
+
+/*
+ * Some versions of firmware stuff packets with 0xff 0x03 (PPP: ALLSTATIONS, UI)
+ * bytes, which are required on sent packet, but not always present on received
+ * packets
+ */
+static struct sk_buff *ipw_packet_received_skb(unsigned char *data,
+                                              unsigned int length)
+{
+       struct sk_buff *skb;
+
+       if (length > 2 && data[0] == PPP_ALLSTATIONS && data[1] == PPP_UI) {
+               length -= 2;
+               data += 2;
+       }
+
+       skb = dev_alloc_skb(length + 4);
+       skb_reserve(skb, 2);
+       memcpy(skb_put(skb, length), data, length);
+
+       return skb;
+}
+
+void ipwireless_network_packet_received(struct ipw_network *network,
+                                       unsigned int channel_idx,
+                                       unsigned char *data,
+                                       unsigned int length)
+{
+       int i;
+       unsigned long flags;
+
+       for (i = 0; i < MAX_ASSOCIATED_TTYS; i++) {
+               struct ipw_tty *tty = network->associated_ttys[channel_idx][i];
+
+               /*
+                * If it's associated with a tty (other than the RAS channel
+                * when we're online), then send the data to that tty.  The RAS
+                * channel's data is handled above - it always goes through
+                * ppp_generic.
+                */
+               if (tty && channel_idx == IPW_CHANNEL_RAS
+                               && (network->ras_control_lines &
+                                       IPW_CONTROL_LINE_DCD) != 0
+                               && ipwireless_tty_is_modem(tty)) {
+                       /*
+                        * If data came in on the RAS channel and this tty is
+                        * the modem tty, and we are online, then we send it to
+                        * the PPP layer.
+                        */
+                       mutex_lock(&network->close_lock);
+                       spin_lock_irqsave(&network->spinlock, flags);
+                       if (network->ppp_channel != NULL) {
+                               struct sk_buff *skb;
+
+                               spin_unlock_irqrestore(&network->spinlock,
+                                               flags);
+
+                               /* Send the data to the ppp_generic module. */
+                               skb = ipw_packet_received_skb(data, length);
+                               ppp_input(network->ppp_channel, skb);
+                       } else
+                               spin_unlock_irqrestore(&network->spinlock,
+                                               flags);
+                       mutex_unlock(&network->close_lock);
+               }
+               /* Otherwise we send it out the tty. */
+               else
+                       ipwireless_tty_received(tty, data, length);
+       }
+}
+
+struct ipw_network *ipwireless_network_create(struct ipw_hardware *hw)
+{
+       struct ipw_network *network =
+               kzalloc(sizeof(struct ipw_network), GFP_ATOMIC);
+
+       if (!network)
+               return NULL;
+
+       spin_lock_init(&network->spinlock);
+       mutex_init(&network->close_lock);
+
+       network->hardware = hw;
+
+       INIT_WORK(&network->work_go_online, do_go_online);
+       INIT_WORK(&network->work_go_offline, do_go_offline);
+
+       ipwireless_associate_network(hw, network);
+
+       return network;
+}
+
+void ipwireless_network_free(struct ipw_network *network)
+{
+       network->shutting_down = 1;
+
+       ipwireless_ppp_close(network);
+       flush_scheduled_work();
+
+       ipwireless_stop_interrupts(network->hardware);
+       ipwireless_associate_network(network->hardware, NULL);
+
+       kfree(network);
+}
+
+void ipwireless_associate_network_tty(struct ipw_network *network,
+                                     unsigned int channel_idx,
+                                     struct ipw_tty *tty)
+{
+       int i;
+
+       for (i = 0; i < MAX_ASSOCIATED_TTYS; i++)
+               if (network->associated_ttys[channel_idx][i] == NULL) {
+                       network->associated_ttys[channel_idx][i] = tty;
+                       break;
+               }
+}
+
+void ipwireless_disassociate_network_ttys(struct ipw_network *network,
+                                         unsigned int channel_idx)
+{
+       int i;
+
+       for (i = 0; i < MAX_ASSOCIATED_TTYS; i++)
+               network->associated_ttys[channel_idx][i] = NULL;
+}
+
+void ipwireless_ppp_open(struct ipw_network *network)
+{
+       if (ipwireless_debug)
+               printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME ": online\n");
+       schedule_work(&network->work_go_online);
+}
+
+void ipwireless_ppp_close(struct ipw_network *network)
+{
+       /* Disconnect from the wireless network. */
+       if (ipwireless_debug)
+               printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME ": offline\n");
+       schedule_work(&network->work_go_offline);
+}
+
+int ipwireless_ppp_channel_index(struct ipw_network *network)
+{
+       int ret = -1;
+       unsigned long flags;
+
+       spin_lock_irqsave(&network->spinlock, flags);
+       if (network->ppp_channel != NULL)
+               ret = ppp_channel_index(network->ppp_channel);
+       spin_unlock_irqrestore(&network->spinlock, flags);
+
+       return ret;
+}
+
+int ipwireless_ppp_unit_number(struct ipw_network *network)
+{
+       int ret = -1;
+       unsigned long flags;
+
+       spin_lock_irqsave(&network->spinlock, flags);
+       if (network->ppp_channel != NULL)
+               ret = ppp_unit_number(network->ppp_channel);
+       spin_unlock_irqrestore(&network->spinlock, flags);
+
+       return ret;
+}
diff --git a/drivers/char/pcmcia/ipwireless/network.h b/drivers/char/pcmcia/ipwireless/network.h
new file mode 100644 (file)
index 0000000..b0e1e95
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#ifndef _IPWIRELESS_CS_NETWORK_H_
+#define _IPWIRELESS_CS_NETWORK_H_
+
+#include <linux/types.h>
+
+struct ipw_network;
+struct ipw_tty;
+struct ipw_hardware;
+
+/* Definitions of the different channels on the PCMCIA UE */
+#define IPW_CHANNEL_RAS      0
+#define IPW_CHANNEL_DIALLER  1
+#define IPW_CHANNEL_CONSOLE  2
+#define NO_OF_IPW_CHANNELS   5
+
+void ipwireless_network_notify_control_line_change(struct ipw_network *net,
+               unsigned int channel_idx, unsigned int control_lines,
+               unsigned int control_mask);
+void ipwireless_network_packet_received(struct ipw_network *net,
+               unsigned int channel_idx, unsigned char *data,
+               unsigned int length);
+struct ipw_network *ipwireless_network_create(struct ipw_hardware *hw);
+void ipwireless_network_free(struct ipw_network *net);
+void ipwireless_associate_network_tty(struct ipw_network *net,
+               unsigned int channel_idx, struct ipw_tty *tty);
+void ipwireless_disassociate_network_ttys(struct ipw_network *net,
+               unsigned int channel_idx);
+
+void ipwireless_ppp_open(struct ipw_network *net);
+
+void ipwireless_ppp_close(struct ipw_network *net);
+int ipwireless_ppp_channel_index(struct ipw_network *net);
+int ipwireless_ppp_unit_number(struct ipw_network *net);
+
+int ipwireless_dump_network_state(char *p, size_t limit,
+                                 struct ipw_network *net);
+
+#endif
diff --git a/drivers/char/pcmcia/ipwireless/setup_protocol.h b/drivers/char/pcmcia/ipwireless/setup_protocol.h
new file mode 100644 (file)
index 0000000..9d6bcc7
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#ifndef _IPWIRELESS_CS_SETUP_PROTOCOL_H_
+#define _IPWIRELESS_CS_SETUP_PROTOCOL_H_
+
+/* Version of the setup protocol and transport protocols */
+#define TL_SETUP_VERSION               1
+
+#define TL_SETUP_VERSION_QRY_TMO       1000
+#define TL_SETUP_MAX_VERSION_QRY       30
+
+/* Message numbers 0-9 are obsoleted and must not be reused! */
+#define TL_SETUP_SIGNO_GET_VERSION_QRY 10
+#define TL_SETUP_SIGNO_GET_VERSION_RSP 11
+#define TL_SETUP_SIGNO_CONFIG_MSG      12
+#define TL_SETUP_SIGNO_CONFIG_DONE_MSG 13
+#define TL_SETUP_SIGNO_OPEN_MSG                14
+#define TL_SETUP_SIGNO_CLOSE_MSG       15
+
+#define TL_SETUP_SIGNO_INFO_MSG     20
+#define TL_SETUP_SIGNO_INFO_MSG_ACK 21
+
+#define TL_SETUP_SIGNO_REBOOT_MSG      22
+#define TL_SETUP_SIGNO_REBOOT_MSG_ACK  23
+
+/* Synchronous start-messages */
+struct tl_setup_get_version_qry {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_GET_VERSION_QRY */
+} __attribute__ ((__packed__));
+
+struct tl_setup_get_version_rsp {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_GET_VERSION_RSP */
+       unsigned char version;          /* TL_SETUP_VERSION */
+} __attribute__ ((__packed__));
+
+struct tl_setup_config_msg {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_CONFIG_MSG */
+       unsigned char port_no;
+       unsigned char prio_data;
+       unsigned char prio_ctrl;
+} __attribute__ ((__packed__));
+
+struct tl_setup_config_done_msg {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_CONFIG_DONE_MSG */
+} __attribute__ ((__packed__));
+
+/* Asyncronous messages */
+struct tl_setup_open_msg {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_OPEN_MSG */
+       unsigned char port_no;
+} __attribute__ ((__packed__));
+
+struct tl_setup_close_msg {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_CLOSE_MSG */
+       unsigned char port_no;
+} __attribute__ ((__packed__));
+
+/* Driver type  - for use in tl_setup_info_msg.driver_type */
+#define COMM_DRIVER     0
+#define NDISWAN_DRIVER  1
+#define NDISWAN_DRIVER_MAJOR_VERSION  2
+#define NDISWAN_DRIVER_MINOR_VERSION  0
+
+/*
+ * It should not matter when this message comes over as we just store the
+ * results and send the ACK.
+ */
+struct tl_setup_info_msg {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_INFO_MSG */
+       unsigned char driver_type;
+       unsigned char major_version;
+       unsigned char minor_version;
+} __attribute__ ((__packed__));
+
+struct tl_setup_info_msgAck {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_INFO_MSG_ACK */
+} __attribute__ ((__packed__));
+
+struct TlSetupRebootMsgAck {
+       unsigned char sig_no;           /* TL_SETUP_SIGNO_REBOOT_MSG_ACK */
+} __attribute__ ((__packed__));
+
+/* Define a union of all the msgs that the driver can receive from the card.*/
+union ipw_setup_rx_msg {
+       unsigned char sig_no;
+       struct tl_setup_get_version_rsp version_rsp_msg;
+       struct tl_setup_open_msg open_msg;
+       struct tl_setup_close_msg close_msg;
+       struct tl_setup_info_msg InfoMsg;
+       struct tl_setup_info_msgAck info_msg_ack;
+} __attribute__ ((__packed__));
+
+#endif                         /* _IPWIRELESS_CS_SETUP_PROTOCOL_H_ */
diff --git a/drivers/char/pcmcia/ipwireless/tty.c b/drivers/char/pcmcia/ipwireless/tty.c
new file mode 100644 (file)
index 0000000..42f3815
--- /dev/null
@@ -0,0 +1,688 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/ppp_defs.h>
+#include <linux/if.h>
+#include <linux/if_ppp.h>
+#include <linux/sched.h>
+#include <linux/serial.h>
+#include <linux/slab.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/tty_flip.h>
+#include <linux/uaccess.h>
+#include <linux/version.h>
+
+#include "tty.h"
+#include "network.h"
+#include "hardware.h"
+#include "main.h"
+
+#define IPWIRELESS_PCMCIA_START        (0)
+#define IPWIRELESS_PCMCIA_MINORS       (24)
+#define IPWIRELESS_PCMCIA_MINOR_RANGE  (8)
+
+#define TTYTYPE_MODEM    (0)
+#define TTYTYPE_MONITOR  (1)
+#define TTYTYPE_RAS_RAW  (2)
+
+struct ipw_tty {
+       int index;
+       struct ipw_hardware *hardware;
+       unsigned int channel_idx;
+       unsigned int secondary_channel_idx;
+       int tty_type;
+       struct ipw_network *network;
+       struct tty_struct *linux_tty;
+       int open_count;
+       unsigned int control_lines;
+       struct mutex ipw_tty_mutex;
+       int tx_bytes_queued;
+       int closing;
+};
+
+static struct ipw_tty *ttys[IPWIRELESS_PCMCIA_MINORS];
+
+static struct tty_driver *ipw_tty_driver;
+
+static char *tty_type_name(int tty_type)
+{
+       static char *channel_names[] = {
+               "modem",
+               "monitor",
+               "RAS-raw"
+       };
+
+       return channel_names[tty_type];
+}
+
+static void report_registering(struct ipw_tty *tty)
+{
+       char *iftype = tty_type_name(tty->tty_type);
+
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+              ": registering %s device ttyIPWp%d\n", iftype, tty->index);
+}
+
+static void report_deregistering(struct ipw_tty *tty)
+{
+       char *iftype = tty_type_name(tty->tty_type);
+
+       printk(KERN_INFO IPWIRELESS_PCCARD_NAME
+              ": deregistering %s device ttyIPWp%d\n", iftype,
+              tty->index);
+}
+
+static struct ipw_tty *get_tty(int minor)
+{
+       if (minor < ipw_tty_driver->minor_start
+                       || minor >= ipw_tty_driver->minor_start +
+                       IPWIRELESS_PCMCIA_MINORS)
+               return NULL;
+       else {
+               int minor_offset = minor - ipw_tty_driver->minor_start;
+
+               /*
+                * The 'ras_raw' channel is only available when 'loopback' mode
+                * is enabled.
+                * Number of minor starts with 16 (_RANGE * _RAS_RAW).
+                */
+               if (!ipwireless_loopback &&
+                               minor_offset >=
+                                IPWIRELESS_PCMCIA_MINOR_RANGE * TTYTYPE_RAS_RAW)
+                       return NULL;
+
+               return ttys[minor_offset];
+       }
+}
+
+static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
+{
+       int minor = linux_tty->index;
+       struct ipw_tty *tty = get_tty(minor);
+
+       if (!tty)
+               return -ENODEV;
+
+       mutex_lock(&tty->ipw_tty_mutex);
+
+       if (tty->closing) {
+               mutex_unlock(&tty->ipw_tty_mutex);
+               return -ENODEV;
+       }
+       if (tty->open_count == 0)
+               tty->tx_bytes_queued = 0;
+
+       tty->open_count++;
+
+       tty->linux_tty = linux_tty;
+       linux_tty->driver_data = tty;
+       linux_tty->low_latency = 1;
+
+       if (tty->tty_type == TTYTYPE_MODEM)
+               ipwireless_ppp_open(tty->network);
+
+       mutex_unlock(&tty->ipw_tty_mutex);
+
+       return 0;
+}
+
+static void do_ipw_close(struct ipw_tty *tty)
+{
+       tty->open_count--;
+
+       if (tty->open_count == 0) {
+               struct tty_struct *linux_tty = tty->linux_tty;
+
+               if (linux_tty != NULL) {
+                       tty->linux_tty = NULL;
+                       linux_tty->driver_data = NULL;
+
+                       if (tty->tty_type == TTYTYPE_MODEM)
+                               ipwireless_ppp_close(tty->network);
+               }
+       }
+}
+
+static void ipw_hangup(struct tty_struct *linux_tty)
+{
+       struct ipw_tty *tty = linux_tty->driver_data;
+
+       if (!tty)
+               return;
+
+       mutex_lock(&tty->ipw_tty_mutex);
+       if (tty->open_count == 0) {
+               mutex_unlock(&tty->ipw_tty_mutex);
+               return;
+       }
+
+       do_ipw_close(tty);
+
+       mutex_unlock(&tty->ipw_tty_mutex);
+}
+
+static void ipw_close(struct tty_struct *linux_tty, struct file *filp)
+{
+       ipw_hangup(linux_tty);
+}
+
+/* Take data received from hardware, and send it out the tty */
+void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
+                       unsigned int length)
+{
+       struct tty_struct *linux_tty;
+       int work = 0;
+
+       mutex_lock(&tty->ipw_tty_mutex);
+       linux_tty = tty->linux_tty;
+       if (linux_tty == NULL) {
+               mutex_unlock(&tty->ipw_tty_mutex);
+               return;
+       }
+
+       if (!tty->open_count) {
+               mutex_unlock(&tty->ipw_tty_mutex);
+               return;
+       }
+       mutex_unlock(&tty->ipw_tty_mutex);
+
+       work = tty_insert_flip_string(linux_tty, data, length);
+
+       if (work != length)
+               printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
+                               ": %d chars not inserted to flip buffer!\n",
+                               length - work);
+
+       /*
+        * This may sleep if ->low_latency is set
+        */
+       if (work)
+               tty_flip_buffer_push(linux_tty);
+}
+
+static void ipw_write_packet_sent_callback(void *callback_data,
+                                          unsigned int packet_length)
+{
+       struct ipw_tty *tty = callback_data;
+
+       /*
+        * Packet has been sent, so we subtract the number of bytes from our
+        * tally of outstanding TX bytes.
+        */
+       tty->tx_bytes_queued -= packet_length;
+}
+
+static int ipw_write(struct tty_struct *linux_tty,
+                    const unsigned char *buf, int count)
+{
+       struct ipw_tty *tty = linux_tty->driver_data;
+       int room, ret;
+
+       if (!tty)
+               return -ENODEV;
+
+       mutex_lock(&tty->ipw_tty_mutex);
+       if (!tty->open_count) {
+               mutex_unlock(&tty->ipw_tty_mutex);
+               return -EINVAL;
+       }
+
+       room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
+       if (room < 0)
+               room = 0;
+       /* Don't allow caller to write any more than we have room for */
+       if (count > room)
+               count = room;
+
+       if (count == 0) {
+               mutex_unlock(&tty->ipw_tty_mutex);
+               return 0;
+       }
+
+       ret = ipwireless_send_packet(tty->hardware, IPW_CHANNEL_RAS,
+                              (unsigned char *) buf, count,
+                              ipw_write_packet_sent_callback, tty);
+       if (ret == -1) {
+               mutex_unlock(&tty->ipw_tty_mutex);
+               return 0;
+       }
+
+       tty->tx_bytes_queued += count;
+       mutex_unlock(&tty->ipw_tty_mutex);
+
+       return count;
+}
+
+static int ipw_write_room(struct tty_struct *linux_tty)
+{
+       struct ipw_tty *tty = linux_tty->driver_data;
+       int room;
+
+       if (!tty)
+               return -ENODEV;
+
+       if (!tty->open_count)
+               return -EINVAL;
+
+       room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
+       if (room < 0)
+               room = 0;
+
+       return room;
+}
+
+static int ipwireless_get_serial_info(struct ipw_tty *tty,
+                                     struct serial_struct __user *retinfo)
+{
+       struct serial_struct tmp;
+
+       if (!retinfo)
+               return (-EFAULT);
+
+       memset(&tmp, 0, sizeof(tmp));
+       tmp.type = PORT_UNKNOWN;
+       tmp.line = tty->index;
+       tmp.port = 0;
+       tmp.irq = 0;
+       tmp.flags = 0;
+       tmp.baud_base = 115200;
+       tmp.close_delay = 0;
+       tmp.closing_wait = 0;
+       tmp.custom_divisor = 0;
+       tmp.hub6 = 0;
+       if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
+               return -EFAULT;
+
+       return 0;
+}
+
+static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
+{
+       struct ipw_tty *tty = linux_tty->driver_data;
+
+       if (!tty)
+               return -ENODEV;
+
+       if (!tty->open_count)
+               return -EINVAL;
+
+       return tty->tx_bytes_queued;
+}
+
+static int get_control_lines(struct ipw_tty *tty)
+{
+       unsigned int my = tty->control_lines;
+       unsigned int out = 0;
+
+       if (my & IPW_CONTROL_LINE_RTS)
+               out |= TIOCM_RTS;
+       if (my & IPW_CONTROL_LINE_DTR)
+               out |= TIOCM_DTR;
+       if (my & IPW_CONTROL_LINE_CTS)
+               out |= TIOCM_CTS;
+       if (my & IPW_CONTROL_LINE_DSR)
+               out |= TIOCM_DSR;
+       if (my & IPW_CONTROL_LINE_DCD)
+               out |= TIOCM_CD;
+
+       return out;
+}
+
+static int set_control_lines(struct ipw_tty *tty, unsigned int set,
+                            unsigned int clear)
+{
+       int ret;
+
+       if (set & TIOCM_RTS) {
+               ret = ipwireless_set_RTS(tty->hardware, tty->channel_idx, 1);
+               if (ret)
+                       return ret;
+               if (tty->secondary_channel_idx != -1) {
+                       ret = ipwireless_set_RTS(tty->hardware,
+                                         tty->secondary_channel_idx, 1);
+                       if (ret)
+                               return ret;
+               }
+       }
+       if (set & TIOCM_DTR) {
+               ret = ipwireless_set_DTR(tty->hardware, tty->channel_idx, 1);
+               if (ret)
+                       return ret;
+               if (tty->secondary_channel_idx != -1) {
+                       ret = ipwireless_set_DTR(tty->hardware,
+                                         tty->secondary_channel_idx, 1);
+                       if (ret)
+                               return ret;
+               }
+       }
+       if (clear & TIOCM_RTS) {
+               ret = ipwireless_set_RTS(tty->hardware, tty->channel_idx, 0);
+               if (tty->secondary_channel_idx != -1) {
+                       ret = ipwireless_set_RTS(tty->hardware,
+                                         tty->secondary_channel_idx, 0);
+                       if (ret)
+                               return ret;
+               }
+       }
+       if (clear & TIOCM_DTR) {
+               ret = ipwireless_set_DTR(tty->hardware, tty->channel_idx, 0);
+               if (tty->secondary_channel_idx != -1) {
+                       ret = ipwireless_set_DTR(tty->hardware,
+                                         tty->secondary_channel_idx, 0);
+                       if (ret)
+                               return ret;
+               }
+       }
+       return 0;
+}
+
+static int ipw_tiocmget(struct tty_struct *linux_tty, struct file *file)
+{
+       struct ipw_tty *tty = linux_tty->driver_data;
+
+       if (!tty)
+               return -ENODEV;
+
+       if (!tty->open_count)
+               return -EINVAL;
+
+       return get_control_lines(tty);
+}
+
+static int
+ipw_tiocmset(struct tty_struct *linux_tty, struct file *file,
+            unsigned int set, unsigned int clear)
+{
+       struct ipw_tty *tty = linux_tty->driver_data;
+
+       if (!tty)
+               return -ENODEV;
+
+       if (!tty->open_count)
+               return -EINVAL;
+
+       return set_control_lines(tty, set, clear);
+}
+
+static int ipw_ioctl(struct tty_struct *linux_tty, struct file *file,
+                    unsigned int cmd, unsigned long arg)
+{
+       struct ipw_tty *tty = linux_tty->driver_data;
+
+       if (!tty)
+               return -ENODEV;
+
+       if (!tty->open_count)
+               return -EINVAL;
+
+       switch (cmd) {
+       case TIOCGSERIAL:
+               return ipwireless_get_serial_info(tty, (void __user *) arg);
+
+       case TIOCSSERIAL:
+               return 0;       /* Keeps the PCMCIA scripts happy. */
+       }
+
+       if (tty->tty_type == TTYTYPE_MODEM) {
+               switch (cmd) {
+               case PPPIOCGCHAN:
+                       {
+                               int chan = ipwireless_ppp_channel_index(
+                                                       tty->network);
+
+                               if (chan < 0)
+                                       return -ENODEV;
+                               if (put_user(chan, (int __user *) arg))
+                                       return -EFAULT;
+                       }
+                       return 0;
+
+               case PPPIOCGUNIT:
+                       {
+                               int unit = ipwireless_ppp_unit_number(
+                                               tty->network);
+
+                               if (unit < 0)
+                                       return -ENODEV;
+                               if (put_user(unit, (int __user *) arg))
+                                       return -EFAULT;
+                       }
+                       return 0;
+
+               case TCGETS:
+               case TCGETA:
+                       return n_tty_ioctl(linux_tty, file, cmd, arg);
+
+               case TCFLSH:
+                       return n_tty_ioctl(linux_tty, file, cmd, arg);
+
+               case FIONREAD:
+                       {
+                               int val = 0;
+
+                               if (put_user(val, (int __user *) arg))
+                                       return -EFAULT;
+                       }
+                       return 0;
+               }
+       }
+
+       return -ENOIOCTLCMD;
+}
+
+static int add_tty(dev_node_t *nodesp, int j,
+                   struct ipw_hardware *hardware,
+                   struct ipw_network *network, int channel_idx,
+                   int secondary_channel_idx, int tty_type)
+{
+       ttys[j] = kzalloc(sizeof(struct ipw_tty), GFP_KERNEL);
+       if (!ttys[j])
+               return -ENOMEM;
+       ttys[j]->index = j;
+       ttys[j]->hardware = hardware;
+       ttys[j]->channel_idx = channel_idx;
+       ttys[j]->secondary_channel_idx = secondary_channel_idx;
+       ttys[j]->network = network;
+       ttys[j]->tty_type = tty_type;
+       mutex_init(&ttys[j]->ipw_tty_mutex);
+
+       tty_register_device(ipw_tty_driver, j, NULL);
+       ipwireless_associate_network_tty(network, channel_idx, ttys[j]);
+
+       if (secondary_channel_idx != -1)
+               ipwireless_associate_network_tty(network,
+                                                secondary_channel_idx,
+                                                ttys[j]);
+       if (nodesp != NULL) {
+               sprintf(nodesp->dev_name, "ttyIPWp%d", j);
+               nodesp->major = ipw_tty_driver->major;
+               nodesp->minor = j + ipw_tty_driver->minor_start;
+       }
+       if (get_tty(j + ipw_tty_driver->minor_start) == ttys[j])
+               report_registering(ttys[j]);
+       return 0;
+}
+
+struct ipw_tty *ipwireless_tty_create(struct ipw_hardware *hardware,
+                                     struct ipw_network *network,
+                                     dev_node_t *nodes)
+{
+       int i, j;
+
+       for (i = 0; i < IPWIRELESS_PCMCIA_MINOR_RANGE; i++) {
+               int allfree = 1;
+
+               for (j = i; j < IPWIRELESS_PCMCIA_MINORS;
+                               j += IPWIRELESS_PCMCIA_MINOR_RANGE)
+                       if (ttys[j] != NULL) {
+                               allfree = 0;
+                               break;
+                       }
+
+               if (allfree) {
+                       j = i;
+
+                       if (add_tty(&nodes[0], j, hardware, network,
+                                       IPW_CHANNEL_DIALLER, IPW_CHANNEL_RAS,
+                                       TTYTYPE_MODEM))
+                               return NULL;
+
+                       j += IPWIRELESS_PCMCIA_MINOR_RANGE;
+                       if (add_tty(&nodes[1], j, hardware, network,
+                                       IPW_CHANNEL_DIALLER, -1,
+                                       TTYTYPE_MONITOR))
+                               return NULL;
+
+                       j += IPWIRELESS_PCMCIA_MINOR_RANGE;
+                       if (add_tty(NULL, j, hardware, network,
+                                       IPW_CHANNEL_RAS, -1,
+                                       TTYTYPE_RAS_RAW))
+                               return NULL;
+
+                       nodes[0].next = &nodes[1];
+                       nodes[1].next = NULL;
+
+                       return ttys[i];
+               }
+       }
+       return NULL;
+}
+
+/*
+ * Must be called before ipwireless_network_free().
+ */
+void ipwireless_tty_free(struct ipw_tty *tty)
+{
+       int j;
+       struct ipw_network *network = ttys[tty->index]->network;
+
+       for (j = tty->index; j < IPWIRELESS_PCMCIA_MINORS;
+                       j += IPWIRELESS_PCMCIA_MINOR_RANGE) {
+               struct ipw_tty *ttyj = ttys[j];
+
+               if (ttyj) {
+                       mutex_lock(&ttyj->ipw_tty_mutex);
+                       if (get_tty(j + ipw_tty_driver->minor_start) == ttyj)
+                               report_deregistering(ttyj);
+                       ttyj->closing = 1;
+                       if (ttyj->linux_tty != NULL) {
+                               mutex_unlock(&ttyj->ipw_tty_mutex);
+                               tty_hangup(ttyj->linux_tty);
+                               /* Wait till the tty_hangup has completed */
+                               flush_scheduled_work();
+                               mutex_lock(&ttyj->ipw_tty_mutex);
+                       }
+                       while (ttyj->open_count)
+                               do_ipw_close(ttyj);
+                       ipwireless_disassociate_network_ttys(network,
+                                                            ttyj->channel_idx);
+                       tty_unregister_device(ipw_tty_driver, j);
+                       ttys[j] = NULL;
+                       mutex_unlock(&ttyj->ipw_tty_mutex);
+                       kfree(ttyj);
+               }
+       }
+}
+
+static struct tty_operations tty_ops = {
+       .open = ipw_open,
+       .close = ipw_close,
+       .hangup = ipw_hangup,
+       .write = ipw_write,
+       .write_room = ipw_write_room,
+       .ioctl = ipw_ioctl,
+       .chars_in_buffer = ipw_chars_in_buffer,
+       .tiocmget = ipw_tiocmget,
+       .tiocmset = ipw_tiocmset,
+};
+
+int ipwireless_tty_init(void)
+{
+       int result;
+
+       ipw_tty_driver = alloc_tty_driver(IPWIRELESS_PCMCIA_MINORS);
+       if (!ipw_tty_driver)
+               return -ENOMEM;
+
+       ipw_tty_driver->owner = THIS_MODULE;
+       ipw_tty_driver->driver_name = IPWIRELESS_PCCARD_NAME;
+       ipw_tty_driver->name = "ttyIPWp";
+       ipw_tty_driver->major = 0;
+       ipw_tty_driver->minor_start = IPWIRELESS_PCMCIA_START;
+       ipw_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
+       ipw_tty_driver->subtype = SERIAL_TYPE_NORMAL;
+       ipw_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
+       ipw_tty_driver->init_termios = tty_std_termios;
+       ipw_tty_driver->init_termios.c_cflag =
+           B9600 | CS8 | CREAD | HUPCL | CLOCAL;
+       ipw_tty_driver->init_termios.c_ispeed = 9600;
+       ipw_tty_driver->init_termios.c_ospeed = 9600;
+       tty_set_operations(ipw_tty_driver, &tty_ops);
+       result = tty_register_driver(ipw_tty_driver);
+       if (result) {
+               printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                      ": failed to register tty driver\n");
+               put_tty_driver(ipw_tty_driver);
+               return result;
+       }
+
+       return 0;
+}
+
+void ipwireless_tty_release(void)
+{
+       int ret;
+
+       ret = tty_unregister_driver(ipw_tty_driver);
+       put_tty_driver(ipw_tty_driver);
+       if (ret != 0)
+               printk(KERN_ERR IPWIRELESS_PCCARD_NAME
+                       ": tty_unregister_driver failed with code %d\n", ret);
+}
+
+int ipwireless_tty_is_modem(struct ipw_tty *tty)
+{
+       return tty->tty_type == TTYTYPE_MODEM;
+}
+
+void
+ipwireless_tty_notify_control_line_change(struct ipw_tty *tty,
+                                         unsigned int channel_idx,
+                                         unsigned int control_lines,
+                                         unsigned int changed_mask)
+{
+       unsigned int old_control_lines = tty->control_lines;
+
+       tty->control_lines = (tty->control_lines & ~changed_mask)
+               | (control_lines & changed_mask);
+
+       /*
+        * If DCD is de-asserted, we close the tty so pppd can tell that we
+        * have gone offline.
+        */
+       if ((old_control_lines & IPW_CONTROL_LINE_DCD)
+                       && !(tty->control_lines & IPW_CONTROL_LINE_DCD)
+                       && tty->linux_tty) {
+               tty_hangup(tty->linux_tty);
+       }
+}
+
diff --git a/drivers/char/pcmcia/ipwireless/tty.h b/drivers/char/pcmcia/ipwireless/tty.h
new file mode 100644 (file)
index 0000000..b0deb91
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * IPWireless 3G PCMCIA Network Driver
+ *
+ * Original code
+ *   by Stephen Blackheath <stephen@blacksapphire.com>,
+ *      Ben Martel <benm@symmetric.co.nz>
+ *
+ * Copyrighted as follows:
+ *   Copyright (C) 2004 by Symmetric Systems Ltd (NZ)
+ *
+ * Various driver changes and rewrites, port to new kernels
+ *   Copyright (C) 2006-2007 Jiri Kosina
+ *
+ * Misc code cleanups and updates
+ *   Copyright (C) 2007 David Sterba
+ */
+
+#ifndef _IPWIRELESS_CS_TTY_H_
+#define _IPWIRELESS_CS_TTY_H_
+
+#include <linux/types.h>
+#include <linux/sched.h>
+
+#include <pcmcia/cs_types.h>
+#include <pcmcia/cs.h>
+#include <pcmcia/cistpl.h>
+#include <pcmcia/ds.h>
+
+struct ipw_tty;
+struct ipw_network;
+struct ipw_hardware;
+
+int ipwireless_tty_init(void);
+void ipwireless_tty_release(void);
+
+struct ipw_tty *ipwireless_tty_create(struct ipw_hardware *hw,
+                                     struct ipw_network *net,
+                                     dev_node_t *nodes);
+void ipwireless_tty_free(struct ipw_tty *tty);
+void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
+                            unsigned int length);
+int ipwireless_tty_is_modem(struct ipw_tty *tty);
+void ipwireless_tty_notify_control_line_change(struct ipw_tty *tty,
+                                              unsigned int channel_idx,
+                                              unsigned int control_lines,
+                                              unsigned int changed_mask);
+
+#endif
index 68c289fe2dc2c67ef49e4541ba22278f94a15f94..72f289279d8ff0af1c2601d0fb68197faaede9f4 100644 (file)
@@ -715,11 +715,10 @@ static void configure_r_port(struct r_port *info,
        unsigned rocketMode;
        int bits, baud, divisor;
        CHANNEL_t *cp;
+       struct ktermios *t = info->tty->termios;
 
-       if (!info->tty || !info->tty->termios)
-               return;
        cp = &info->channel;
-       cflag = info->tty->termios->c_cflag;
+       cflag = t->c_cflag;
 
        /* Byte size and parity */
        if ((cflag & CSIZE) == CS8) {
@@ -754,10 +753,7 @@ static void configure_r_port(struct r_port *info,
                baud = 9600;
        divisor = ((rp_baud_base[info->board] + (baud >> 1)) / baud) - 1;
        if ((divisor >= 8192 || divisor < 0) && old_termios) {
-               info->tty->termios->c_cflag &= ~CBAUD;
-               info->tty->termios->c_cflag |=
-                   (old_termios->c_cflag & CBAUD);
-               baud = tty_get_baud_rate(info->tty);
+               baud = tty_termios_baud_rate(old_termios);
                if (!baud)
                        baud = 9600;
                divisor = (rp_baud_base[info->board] / baud) - 1;
@@ -769,6 +765,9 @@ static void configure_r_port(struct r_port *info,
        info->cps = baud / bits;
        sSetBaud(cp, divisor);
 
+       /* FIXME: Should really back compute a baud rate from the divisor */
+       tty_encode_baud_rate(info->tty, baud, baud);
+
        if (cflag & CRTSCTS) {
                info->intmask |= DELTA_CTS;
                sEnCTSFlowCtl(cp);
@@ -1202,15 +1201,14 @@ static void rp_set_termios(struct tty_struct *tty,
 
        cflag = tty->termios->c_cflag;
 
-       if (cflag == old_termios->c_cflag)
-               return;
-
        /*
         * This driver doesn't support CS5 or CS6
         */
        if (((cflag & CSIZE) == CS5) || ((cflag & CSIZE) == CS6))
                tty->termios->c_cflag =
                    ((cflag & ~CSIZE) | (old_termios->c_cflag & CSIZE));
+       /* Or CMSPAR */
+       tty->termios->c_cflag &= ~CMSPAR;
 
        configure_r_port(info, old_termios);
 
@@ -1401,6 +1399,9 @@ static int reset_rm2(struct r_port *info, void __user *arg)
 {
        int reset;
 
+       if (!capable(CAP_SYS_ADMIN))
+               return -EPERM;
+
        if (copy_from_user(&reset, arg, sizeof (int)))
                return -EFAULT;
        if (reset)
index bacded0eefabcb76aab68de33bea773bd4e8e21f..7722466e052faedeb2ec999ba0b2f67f8b300e3e 100644 (file)
@@ -27,7 +27,7 @@ static struct tty_audit_buf *tty_audit_buf_alloc(int major, int minor,
 {
        struct tty_audit_buf *buf;
 
-       buf = kmalloc(sizeof (*buf), GFP_KERNEL);
+       buf = kmalloc(sizeof(*buf), GFP_KERNEL);
        if (!buf)
                goto err;
        if (PAGE_SIZE != N_TTY_BUF_SIZE)
index 79c86c47947f4da921051be399b028f176f18ad9..613ec816ce606c004c07c24038bd169d90840c85 100644 (file)
@@ -19,7 +19,7 @@
  * Also restructured routines so that there is more of a separation
  * between the high-level tty routines (tty_io.c and tty_ioctl.c) and
  * the low-level tty routines (serial.c, pty.c, console.c).  This
- * makes for cleaner and more compact code.  -TYT, 9/17/92 
+ * makes for cleaner and more compact code.  -TYT, 9/17/92
  *
  * Modified by Fred N. van Kempen, 01/29/93, to add line disciplines
  * which can be dynamically activated and de-activated by the line
@@ -41,7 +41,7 @@
  *
  * New TIOCLINUX variants added.
  *     -- mj@k332.feld.cvut.cz, 19-Nov-95
- * 
+ *
  * Restrict vt switching via ioctl()
  *      -- grif@cs.ucr.edu, 5-Dec-95
  *
@@ -62,7 +62,8 @@
  *      -- Russell King <rmk@arm.linux.org.uk>
  *
  * Move do_SAK() into process context.  Less stack use in devfs functions.
- * alloc_tty_struct() always uses kmalloc() -- Andrew Morton <andrewm@uow.edu.eu> 17Mar01
+ * alloc_tty_struct() always uses kmalloc()
+ *                      -- Andrew Morton <andrewm@uow.edu.eu> 17Mar01
  */
 
 #include <linux/types.h>
@@ -126,7 +127,7 @@ EXPORT_SYMBOL(tty_std_termios);
 /* This list gets poked at by procfs and various bits of boot up code. This
    could do with some rationalisation such as pulling the tty proc function
    into this file */
-   
+
 LIST_HEAD(tty_drivers);                        /* linked list of tty drivers */
 
 /* Mutex to protect creating and releasing a tty. This is shared with
@@ -136,7 +137,7 @@ EXPORT_SYMBOL(tty_mutex);
 
 #ifdef CONFIG_UNIX98_PTYS
 extern struct tty_driver *ptm_driver;  /* Unix98 pty masters; for /dev/ptmx */
-extern int pty_limit;          /* Config limit on Unix98 ptys */
+extern int pty_limit;                  /* Config limit on Unix98 ptys */
 static DEFINE_IDR(allocated_ptys);
 static DEFINE_MUTEX(allocated_ptys_lock);
 static int ptmx_open(struct inode *, struct file *);
@@ -146,19 +147,20 @@ static void initialize_tty_struct(struct tty_struct *tty);
 
 static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
 static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
-ssize_t redirected_tty_write(struct file *, const char __user *, size_t, loff_t *);
+ssize_t redirected_tty_write(struct file *, const char __user *,
+                                                       size_t, loff_t *);
 static unsigned int tty_poll(struct file *, poll_table *);
 static int tty_open(struct inode *, struct file *);
 static int tty_release(struct inode *, struct file *);
-int tty_ioctl(struct inode * inode, struct file * file,
+int tty_ioctl(struct inode *inode, struct file *file,
              unsigned int cmd, unsigned long arg);
 #ifdef CONFIG_COMPAT
-static long tty_compat_ioctl(struct file * file, unsigned int cmd,
+static long tty_compat_ioctl(struct file *file, unsigned int cmd,
                                unsigned long arg);
 #else
 #define tty_compat_ioctl NULL
 #endif
-static int tty_fasync(int fd, struct file * filp, int on);
+static int tty_fasync(int fd, struct file *filp, int on);
 static void release_tty(struct tty_struct *tty, int idx);
 static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
 static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
@@ -244,7 +246,7 @@ static int check_tty_count(struct tty_struct *tty, const char *routine)
 #ifdef CHECK_TTY_COUNT
        struct list_head *p;
        int count = 0;
-       
+
        file_list_lock();
        list_for_each(p, &tty->tty_files) {
                count++;
@@ -281,11 +283,11 @@ static int check_tty_count(struct tty_struct *tty, const char *routine)
 static void tty_buffer_free_all(struct tty_struct *tty)
 {
        struct tty_buffer *thead;
-       while((thead = tty->buf.head) != NULL) {
+       while ((thead = tty->buf.head) != NULL) {
                tty->buf.head = thead->next;
                kfree(thead);
        }
-       while((thead = tty->buf.free) != NULL) {
+       while ((thead = tty->buf.free) != NULL) {
                tty->buf.free = thead->next;
                kfree(thead);
        }
@@ -331,7 +333,7 @@ static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size)
        if (tty->buf.memory_used + size > 65536)
                return NULL;
        p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC);
-       if(p == NULL)
+       if (p == NULL)
                return NULL;
        p->used = 0;
        p->size = size;
@@ -361,7 +363,7 @@ static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b)
        tty->buf.memory_used -= b->size;
        WARN_ON(tty->buf.memory_used < 0);
 
-       if(b->size >= 512)
+       if (b->size >= 512)
                kfree(b);
        else {
                b->next = tty->buf.free;
@@ -384,7 +386,7 @@ static void __tty_buffer_flush(struct tty_struct *tty)
 {
        struct tty_buffer *thead;
 
-       while((thead = tty->buf.head) != NULL) {
+       while ((thead = tty->buf.head) != NULL) {
                tty->buf.head = thead->next;
                tty_buffer_free(tty, thead);
        }
@@ -436,9 +438,9 @@ static void tty_buffer_flush(struct tty_struct *tty)
 static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
 {
        struct tty_buffer **tbh = &tty->buf.free;
-       while((*tbh) != NULL) {
+       while ((*tbh) != NULL) {
                struct tty_buffer *t = *tbh;
-               if(t->size >= size) {
+               if (t->size >= size) {
                        *tbh = t->next;
                        t->next = NULL;
                        t->used = 0;
@@ -450,7 +452,7 @@ static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
                tbh = &((*tbh)->next);
        }
        /* Round the buffer size out */
-       size = (size + 0xFF) & ~ 0xFF;
+       size = (size + 0xFF) & ~0xFF;
        return tty_buffer_alloc(tty, size);
        /* Should possibly check if this fails for the largest buffer we
           have queued and recycle that ? */
@@ -520,7 +522,7 @@ int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars,
                int space = tty_buffer_request_room(tty, size - copied);
                struct tty_buffer *tb = tty->buf.tail;
                /* If there is no space then tb may be NULL */
-               if(unlikely(space == 0))
+               if (unlikely(space == 0))
                        break;
                memcpy(tb->char_buf_ptr + tb->used, chars, space);
                memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space);
@@ -556,7 +558,7 @@ int tty_insert_flip_string_flags(struct tty_struct *tty,
                int space = tty_buffer_request_room(tty, size - copied);
                struct tty_buffer *tb = tty->buf.tail;
                /* If there is no space then tb may be NULL */
-               if(unlikely(space == 0))
+               if (unlikely(space == 0))
                        break;
                memcpy(tb->char_buf_ptr + tb->used, chars, space);
                memcpy(tb->flag_buf_ptr + tb->used, flags, space);
@@ -608,7 +610,8 @@ EXPORT_SYMBOL(tty_schedule_flip);
  *     Locking: May call functions taking tty->buf.lock
  */
 
-int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars, size_t size)
+int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars,
+                                                               size_t size)
 {
        int space = tty_buffer_request_room(tty, size);
        if (likely(space)) {
@@ -638,7 +641,8 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
  *     Locking: May call functions taking tty->buf.lock
  */
 
-int tty_prepare_flip_string_flags(struct tty_struct *tty, unsigned char **chars, char **flags, size_t size)
+int tty_prepare_flip_string_flags(struct tty_struct *tty,
+                       unsigned char **chars, char **flags, size_t size)
 {
        int space = tty_buffer_request_room(tty, size);
        if (likely(space)) {
@@ -660,12 +664,12 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
  *     @num: line discipline number
  *
  *     This is probably overkill for real world processors but
- *     they are not on hot paths so a little discipline won't do 
+ *     they are not on hot paths so a little discipline won't do
  *     any harm.
  *
  *     Locking: takes termios_mutex
  */
+
 static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
 {
        mutex_lock(&tty->termios_mutex);
@@ -678,10 +682,11 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
  *     must be taken with irqs off because there are hangup path
  *     callers who will do ldisc lookups and cannot sleep.
  */
+
 static DEFINE_SPINLOCK(tty_ldisc_lock);
 static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait);
-static struct tty_ldisc tty_ldiscs[NR_LDISCS]; /* line disc dispatch table */
+/* Line disc dispatch table */
+static struct tty_ldisc tty_ldiscs[NR_LDISCS];
 
 /**
  *     tty_register_ldisc      -       install a line discipline
@@ -700,17 +705,17 @@ int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc)
 {
        unsigned long flags;
        int ret = 0;
-       
+
        if (disc < N_TTY || disc >= NR_LDISCS)
                return -EINVAL;
-       
+
        spin_lock_irqsave(&tty_ldisc_lock, flags);
        tty_ldiscs[disc] = *new_ldisc;
        tty_ldiscs[disc].num = disc;
        tty_ldiscs[disc].flags |= LDISC_FLAG_DEFINED;
        tty_ldiscs[disc].refcount = 0;
        spin_unlock_irqrestore(&tty_ldisc_lock, flags);
-       
+
        return ret;
 }
 EXPORT_SYMBOL(tty_register_ldisc);
@@ -766,20 +771,18 @@ struct tty_ldisc *tty_ldisc_get(int disc)
 
        if (disc < N_TTY || disc >= NR_LDISCS)
                return NULL;
-       
+
        spin_lock_irqsave(&tty_ldisc_lock, flags);
 
        ld = &tty_ldiscs[disc];
        /* Check the entry is defined */
-       if(ld->flags & LDISC_FLAG_DEFINED)
-       {
+       if (ld->flags & LDISC_FLAG_DEFINED) {
                /* If the module is being unloaded we can't use it */
                if (!try_module_get(ld->owner))
-                       ld = NULL;
+                       ld = NULL;
                else /* lock it */
                        ld->refcount++;
-       }
-       else
+       } else
                ld = NULL;
        spin_unlock_irqrestore(&tty_ldisc_lock, flags);
        return ld;
@@ -802,9 +805,9 @@ void tty_ldisc_put(int disc)
 {
        struct tty_ldisc *ld;
        unsigned long flags;
-       
+
        BUG_ON(disc < N_TTY || disc >= NR_LDISCS);
-               
+
        spin_lock_irqsave(&tty_ldisc_lock, flags);
        ld = &tty_ldiscs[disc];
        BUG_ON(ld->refcount == 0);
@@ -812,7 +815,7 @@ void tty_ldisc_put(int disc)
        module_put(ld->owner);
        spin_unlock_irqrestore(&tty_ldisc_lock, flags);
 }
-       
+
 EXPORT_SYMBOL_GPL(tty_ldisc_put);
 
 /**
@@ -851,11 +854,10 @@ static int tty_ldisc_try(struct tty_struct *tty)
        unsigned long flags;
        struct tty_ldisc *ld;
        int ret = 0;
-       
+
        spin_lock_irqsave(&tty_ldisc_lock, flags);
        ld = &tty->ldisc;
-       if(test_bit(TTY_LDISC, &tty->flags))
-       {
+       if (test_bit(TTY_LDISC, &tty->flags)) {
                ld->refcount++;
                ret = 1;
        }
@@ -867,8 +869,8 @@ static int tty_ldisc_try(struct tty_struct *tty)
  *     tty_ldisc_ref_wait      -       wait for the tty ldisc
  *     @tty: tty device
  *
- *     Dereference the line discipline for the terminal and take a 
- *     reference to it. If the line discipline is in flux then 
+ *     Dereference the line discipline for the terminal and take a
+ *     reference to it. If the line discipline is in flux then
  *     wait patiently until it changes.
  *
  *     Note: Must not be called from an IRQ/timer context. The caller
@@ -878,12 +880,12 @@ static int tty_ldisc_try(struct tty_struct *tty)
  *
  *     Locking: call functions take tty_ldisc_lock
  */
+
 struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
 {
        /* wait_event is a macro */
        wait_event(tty_ldisc_wait, tty_ldisc_try(tty));
-       if(tty->ldisc.refcount == 0)
+       if (tty->ldisc.refcount == 0)
                printk(KERN_ERR "tty_ldisc_ref_wait\n");
        return &tty->ldisc;
 }
@@ -894,16 +896,16 @@ EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
  *     tty_ldisc_ref           -       get the tty ldisc
  *     @tty: tty device
  *
- *     Dereference the line discipline for the terminal and take a 
- *     reference to it. If the line discipline is in flux then 
+ *     Dereference the line discipline for the terminal and take a
+ *     reference to it. If the line discipline is in flux then
  *     return NULL. Can be called from IRQ and timer functions.
  *
  *     Locking: called functions take tty_ldisc_lock
  */
+
 struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty)
 {
-       if(tty_ldisc_try(tty))
+       if (tty_ldisc_try(tty))
                return &tty->ldisc;
        return NULL;
 }
@@ -919,19 +921,19 @@ EXPORT_SYMBOL_GPL(tty_ldisc_ref);
  *
  *     Locking: takes tty_ldisc_lock
  */
+
 void tty_ldisc_deref(struct tty_ldisc *ld)
 {
        unsigned long flags;
 
        BUG_ON(ld == NULL);
-               
+
        spin_lock_irqsave(&tty_ldisc_lock, flags);
-       if(ld->refcount == 0)
+       if (ld->refcount == 0)
                printk(KERN_ERR "tty_ldisc_deref: no references.\n");
        else
                ld->refcount--;
-       if(ld->refcount == 0)
+       if (ld->refcount == 0)
                wake_up(&tty_ldisc_wait);
        spin_unlock_irqrestore(&tty_ldisc_lock, flags);
 }
@@ -954,7 +956,7 @@ static void tty_ldisc_enable(struct tty_struct *tty)
        set_bit(TTY_LDISC, &tty->flags);
        wake_up(&tty_ldisc_wait);
 }
-       
+
 /**
  *     tty_set_ldisc           -       set line discipline
  *     @tty: the terminal to set
@@ -966,7 +968,7 @@ static void tty_ldisc_enable(struct tty_struct *tty)
  *     Locking: takes tty_ldisc_lock.
  *              called functions take termios_mutex
  */
+
 static int tty_set_ldisc(struct tty_struct *tty, int ldisc)
 {
        int retval = 0;
@@ -1022,7 +1024,7 @@ restart:
 
        spin_lock_irqsave(&tty_ldisc_lock, flags);
        if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) {
-               if(tty->ldisc.refcount) {
+               if (tty->ldisc.refcount) {
                        /* Free the new ldisc we grabbed. Must drop the lock
                           first. */
                        spin_unlock_irqrestore(&tty_ldisc_lock, flags);
@@ -1031,14 +1033,14 @@ restart:
                         * There are several reasons we may be busy, including
                         * random momentary I/O traffic. We must therefore
                         * retry. We could distinguish between blocking ops
-                        * and retries if we made tty_ldisc_wait() smarter. That
-                        * is up for discussion.
+                        * and retries if we made tty_ldisc_wait() smarter.
+                        * That is up for discussion.
                         */
                        if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0)
                                return -ERESTARTSYS;
                        goto restart;
                }
-               if(o_tty && o_tty->ldisc.refcount) {
+               if (o_tty && o_tty->ldisc.refcount) {
                        spin_unlock_irqrestore(&tty_ldisc_lock, flags);
                        tty_ldisc_put(ldisc);
                        if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount == 0) < 0)
@@ -1046,9 +1048,10 @@ restart:
                        goto restart;
                }
        }
-
-       /* if the TTY_LDISC bit is set, then we are racing against another ldisc change */
-
+       /*
+        *      If the TTY_LDISC bit is set, then we are racing against
+        *      another ldisc change
+        */
        if (!test_bit(TTY_LDISC, &tty->flags)) {
                spin_unlock_irqrestore(&tty_ldisc_lock, flags);
                tty_ldisc_put(ldisc);
@@ -1072,7 +1075,6 @@ restart:
        /*
         * Wait for ->hangup_work and ->buf.work handlers to terminate
         */
-        
        flush_scheduled_work();
        /* Shutdown the current discipline. */
        if (tty->ldisc.close)
@@ -1106,21 +1108,21 @@ restart:
        /* At this point we hold a reference to the new ldisc and a
           a reference to the old ldisc. If we ended up flipping back
           to the existing ldisc we have two references to it */
-       
+
        if (tty->ldisc.num != o_ldisc.num && tty->driver->set_ldisc)
                tty->driver->set_ldisc(tty);
-               
+
        tty_ldisc_put(o_ldisc.num);
-       
+
        /*
         *      Allow ldisc referencing to occur as soon as the driver
         *      ldisc callback completes.
         */
-        
+
        tty_ldisc_enable(tty);
        if (o_tty)
                tty_ldisc_enable(o_tty);
-       
+
        /* Restart it in case no characters kick it off. Safe if
           already running */
        if (work)
@@ -1164,7 +1166,7 @@ static struct tty_driver *get_tty_driver(dev_t device, int *index)
  *     Locking: none
  */
 
-int tty_check_change(struct tty_struct * tty)
+int tty_check_change(struct tty_struct *tty)
 {
        if (current->signal->tty != tty)
                return 0;
@@ -1185,31 +1187,31 @@ int tty_check_change(struct tty_struct * tty)
 
 EXPORT_SYMBOL(tty_check_change);
 
-static ssize_t hung_up_tty_read(struct file * file, char __user * buf,
+static ssize_t hung_up_tty_read(struct file *file, char __user *buf,
                                size_t count, loff_t *ppos)
 {
        return 0;
 }
 
-static ssize_t hung_up_tty_write(struct file * file, const char __user * buf,
+static ssize_t hung_up_tty_write(struct file *file, const char __user *buf,
                                 size_t count, loff_t *ppos)
 {
        return -EIO;
 }
 
 /* No kernel lock held - none needed ;) */
-static unsigned int hung_up_tty_poll(struct file * filp, poll_table * wait)
+static unsigned int hung_up_tty_poll(struct file *filp, poll_table *wait)
 {
        return POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDNORM | POLLWRNORM;
 }
 
-static int hung_up_tty_ioctl(struct inode * inode, struct file * file,
+static int hung_up_tty_ioctl(struct inode *inode, struct file *file,
                             unsigned int cmd, unsigned long arg)
 {
        return cmd == TIOCSPGRP ? -ENOTTY : -EIO;
 }
 
-static long hung_up_tty_compat_ioctl(struct file * file,
+static long hung_up_tty_compat_ioctl(struct file *file,
                                     unsigned int cmd, unsigned long arg)
 {
        return cmd == TIOCSPGRP ? -ENOTTY : -EIO;
@@ -1274,15 +1276,15 @@ static struct file *redirect;
  *     informs the line discipline if present that the driver is ready
  *     to receive more output data.
  */
+
 void tty_wakeup(struct tty_struct *tty)
 {
        struct tty_ldisc *ld;
-       
+
        if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) {
                ld = tty_ldisc_ref(tty);
-               if(ld) {
-                       if(ld->write_wakeup)
+               if (ld) {
+                       if (ld->write_wakeup)
                                ld->write_wakeup(tty);
                        tty_ldisc_deref(ld);
                }
@@ -1299,12 +1301,12 @@ EXPORT_SYMBOL_GPL(tty_wakeup);
  *     Flush the line discipline queue (if any) for this tty. If there
  *     is no line discipline active this is a no-op.
  */
+
 void tty_ldisc_flush(struct tty_struct *tty)
 {
        struct tty_ldisc *ld = tty_ldisc_ref(tty);
-       if(ld) {
-               if(ld->flush_buffer)
+       if (ld) {
+               if (ld->flush_buffer)
                        ld->flush_buffer(tty);
                tty_ldisc_deref(ld);
        }
@@ -1328,7 +1330,7 @@ static void tty_reset_termios(struct tty_struct *tty)
        tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
        mutex_unlock(&tty->termios_mutex);
 }
-       
+
 /**
  *     do_tty_hangup           -       actual handler for hangup events
  *     @work: tty device
@@ -1355,7 +1357,7 @@ static void do_tty_hangup(struct work_struct *work)
 {
        struct tty_struct *tty =
                container_of(work, struct tty_struct, hangup_work);
-       struct file * cons_filp = NULL;
+       struct file *cons_filp = NULL;
        struct file *filp, *f = NULL;
        struct task_struct *p;
        struct tty_ldisc *ld;
@@ -1373,7 +1375,7 @@ static void do_tty_hangup(struct work_struct *work)
                redirect = NULL;
        }
        spin_unlock(&redirect_lock);
-       
+
        check_tty_count(tty, "do_tty_hangup");
        file_list_lock();
        /* This breaks for file handles being sent over AF_UNIX sockets ? */
@@ -1387,13 +1389,14 @@ static void do_tty_hangup(struct work_struct *work)
                filp->f_op = &hung_up_tty_fops;
        }
        file_list_unlock();
-       
-       /* FIXME! What are the locking issues here? This may me overdoing things..
-        * this question is especially important now that we've removed the irqlock. */
-
+       /*
+        * FIXME! What are the locking issues here? This may me overdoing
+        * things... This question is especially important now that we've
+        * removed the irqlock.
+        */
        ld = tty_ldisc_ref(tty);
-       if(ld != NULL)  /* We may have no line discipline at this point */
-       {
+       if (ld != NULL) {
+               /* We may have no line discipline at this point */
                if (ld->flush_buffer)
                        ld->flush_buffer(tty);
                if (tty->driver->flush_buffer)
@@ -1404,26 +1407,24 @@ static void do_tty_hangup(struct work_struct *work)
                if (ld->hangup)
                        ld->hangup(tty);
        }
-
-       /* FIXME: Once we trust the LDISC code better we can wait here for
-          ldisc completion and fix the driver call race */
-          
+       /*
+        * FIXME: Once we trust the LDISC code better we can wait here for
+        * ldisc completion and fix the driver call race
+        */
        wake_up_interruptible(&tty->write_wait);
        wake_up_interruptible(&tty->read_wait);
-
        /*
         * Shutdown the current line discipline, and reset it to
         * N_TTY.
         */
        if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS)
                tty_reset_termios(tty);
-       
        /* Defer ldisc switch */
        /* tty_deferred_ldisc_switch(N_TTY);
-       
+
          This should get done automatically when the port closes and
          tty_release is called */
-       
+
        read_lock(&tasklist_lock);
        if (tty->session) {
                do_each_pid_task(tty->session, PIDTYPE_SID, p) {
@@ -1451,10 +1452,10 @@ static void do_tty_hangup(struct work_struct *work)
        tty->pgrp = NULL;
        tty->ctrl_status = 0;
        /*
-        *      If one of the devices matches a console pointer, we
-        *      cannot just call hangup() because that will cause
-        *      tty->count and state->count to go out of sync.
-        *      So we just call close() the right number of times.
+        * If one of the devices matches a console pointer, we
+        * cannot just call hangup() because that will cause
+        * tty->count and state->count to go out of sync.
+        * So we just call close() the right number of times.
         */
        if (cons_filp) {
                if (tty->driver->close)
@@ -1462,12 +1463,12 @@ static void do_tty_hangup(struct work_struct *work)
                                tty->driver->close(tty, cons_filp);
        } else if (tty->driver->hangup)
                (tty->driver->hangup)(tty);
-               
-       /* We don't want to have driver/ldisc interactions beyond
-          the ones we did here. The driver layer expects no
-          calls after ->hangup() from the ldisc side. However we
-          can't yet guarantee all that */
-
+       /*
+        * We don't want to have driver/ldisc interactions beyond
+        * the ones we did here. The driver layer expects no
+        * calls after ->hangup() from the ldisc side. However we
+        * can't yet guarantee all that.
+        */
        set_bit(TTY_HUPPED, &tty->flags);
        if (ld) {
                tty_ldisc_enable(tty);
@@ -1486,11 +1487,10 @@ static void do_tty_hangup(struct work_struct *work)
  *     schedule a hangup sequence to run after this event.
  */
 
-void tty_hangup(struct tty_struct * tty)
+void tty_hangup(struct tty_struct *tty)
 {
 #ifdef TTY_DEBUG_HANGUP
        char    buf[64];
-       
        printk(KERN_DEBUG "%s hangup...\n", tty_name(tty, buf));
 #endif
        schedule_work(&tty->hangup_work);
@@ -1507,7 +1507,7 @@ EXPORT_SYMBOL(tty_hangup);
  *     is complete. That guarantee is necessary for security reasons.
  */
 
-void tty_vhangup(struct tty_struct * tty)
+void tty_vhangup(struct tty_struct *tty)
 {
 #ifdef TTY_DEBUG_HANGUP
        char    buf[64];
@@ -1516,6 +1516,7 @@ void tty_vhangup(struct tty_struct * tty)
 #endif
        do_tty_hangup(&tty->hangup_work);
 }
+
 EXPORT_SYMBOL(tty_vhangup);
 
 /**
@@ -1526,7 +1527,7 @@ EXPORT_SYMBOL(tty_vhangup);
  *     loss
  */
 
-int tty_hung_up_p(struct file * filp)
+int tty_hung_up_p(struct file *filp)
 {
        return (filp->f_op == &hung_up_tty_fops);
 }
@@ -1534,8 +1535,12 @@ int tty_hung_up_p(struct file * filp)
 EXPORT_SYMBOL(tty_hung_up_p);
 
 /**
- * is_tty      -       checker whether file is a TTY
+ *     is_tty  -       checker whether file is a TTY
+ *     @filp:          file handle that may be a tty
+ *
+ *     Check if the file handle is a tty handle.
  */
+
 int is_tty(struct file *filp)
 {
        return filp->f_op->read == tty_read
@@ -1601,7 +1606,7 @@ void disassociate_ctty(int on_exit)
                        put_pid(old_pgrp);
                }
                mutex_unlock(&tty_mutex);
-               unlock_kernel();        
+               unlock_kernel();
                return;
        }
        if (tty_pgrp) {
@@ -1711,7 +1716,6 @@ void start_tty(struct tty_struct *tty)
        }
        if (tty->driver->start)
                (tty->driver->start)(tty);
-
        /* If we have a running line discipline it may need kicking */
        tty_wakeup(tty);
 }
@@ -1735,11 +1739,11 @@ EXPORT_SYMBOL(start_tty);
  *     in new code. Multiple read calls may be outstanding in parallel.
  */
 
-static ssize_t tty_read(struct file * file, char __user * buf, size_t count, 
+static ssize_t tty_read(struct file *file, char __user *buf, size_t count,
                        loff_t *ppos)
 {
        int i;
-       struct tty_struct * tty;
+       struct tty_struct *tty;
        struct inode *inode;
        struct tty_ldisc *ld;
 
@@ -1755,7 +1759,7 @@ static ssize_t tty_read(struct file * file, char __user * buf, size_t count,
        ld = tty_ldisc_ref_wait(tty);
        lock_kernel();
        if (ld->read)
-               i = (ld->read)(tty,file,buf,count);
+               i = (ld->read)(tty, file, buf, count);
        else
                i = -EIO;
        tty_ldisc_deref(ld);
@@ -1795,7 +1799,7 @@ static inline ssize_t do_tty_write(
 {
        ssize_t ret, written = 0;
        unsigned int chunk;
-       
+
        ret = tty_write_lock(tty, file->f_flags & O_NDELAY);
        if (ret < 0)
                return ret;
@@ -1891,21 +1895,22 @@ out:
  *     kernel lock for historical reasons. New code should not rely on this.
  */
 
-static ssize_t tty_write(struct file * file, const char __user * buf, size_t count,
-                        loff_t *ppos)
+static ssize_t tty_write(struct file *file, const char __user *buf,
+                                               size_t count, loff_t *ppos)
 {
-       struct tty_struct * tty;
+       struct tty_struct *tty;
        struct inode *inode = file->f_path.dentry->d_inode;
        ssize_t ret;
        struct tty_ldisc *ld;
-       
+
        tty = (struct tty_struct *)file->private_data;
        if (tty_paranoia_check(tty, inode, "tty_write"))
                return -EIO;
-       if (!tty || !tty->driver->write || (test_bit(TTY_IO_ERROR, &tty->flags)))
-               return -EIO;
+       if (!tty || !tty->driver->write ||
+               (test_bit(TTY_IO_ERROR, &tty->flags)))
+                       return -EIO;
 
-       ld = tty_ldisc_ref_wait(tty);           
+       ld = tty_ldisc_ref_wait(tty);
        if (!ld->write)
                ret = -EIO;
        else
@@ -1914,8 +1919,8 @@ static ssize_t tty_write(struct file * file, const char __user * buf, size_t cou
        return ret;
 }
 
-ssize_t redirected_tty_write(struct file * file, const char __user * buf, size_t count,
-                        loff_t *ppos)
+ssize_t redirected_tty_write(struct file *file, const char __user *buf,
+                                               size_t count, loff_t *ppos)
 {
        struct file *p = NULL;
 
@@ -1932,7 +1937,6 @@ ssize_t redirected_tty_write(struct file * file, const char __user * buf, size_t
                fput(p);
                return res;
        }
-
        return tty_write(file, buf, count, ppos);
 }
 
@@ -1954,8 +1958,8 @@ static void pty_line_name(struct tty_driver *driver, int index, char *p)
        int i = index + driver->name_base;
        /* ->name is initialized to "ttyp", but "tty" is expected */
        sprintf(p, "%s%c%x",
-                       driver->subtype == PTY_TYPE_SLAVE ? "tty" : driver->name,
-                       ptychar[i >> 4 & 0xf], i & 0xf);
+               driver->subtype == PTY_TYPE_SLAVE ? "tty" : driver->name,
+               ptychar[i >> 4 & 0xf], i & 0xf);
 }
 
 /**
@@ -2034,7 +2038,7 @@ static int init_dev(struct tty_driver *driver, int idx,
         * First time open is complex, especially for PTY devices.
         * This code guarantees that either everything succeeds and the
         * TTY is ready for operation, or else the table slots are vacated
-        * and the allocated memory released.  (Except that the termios 
+        * and the allocated memory released.  (Except that the termios
         * and locked termios may be retained.)
         */
 
@@ -2048,7 +2052,7 @@ static int init_dev(struct tty_driver *driver, int idx,
        ltp = o_ltp = NULL;
 
        tty = alloc_tty_struct();
-       if(!tty)
+       if (!tty)
                goto fail_no_mem;
        initialize_tty_struct(tty);
        tty->driver = driver;
@@ -2109,9 +2113,8 @@ static int init_dev(struct tty_driver *driver, int idx,
                /*
                 * Everything allocated ... set up the o_tty structure.
                 */
-               if (!(driver->other->flags & TTY_DRIVER_DEVPTS_MEM)) {
+               if (!(driver->other->flags & TTY_DRIVER_DEVPTS_MEM))
                        driver->other->ttys[idx] = o_tty;
-               }
                if (!*o_tp_loc)
                        *o_tp_loc = o_tp;
                if (!*o_ltp_loc)
@@ -2127,15 +2130,14 @@ static int init_dev(struct tty_driver *driver, int idx,
                o_tty->link = tty;
        }
 
-       /* 
+       /*
         * All structures have been allocated, so now we install them.
         * Failures after this point use release_tty to clean up, so
         * there's no need to null out the local pointers.
         */
-       if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM)) {
+       if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM))
                driver->ttys[idx] = tty;
-       }
-       
+
        if (!*tp_loc)
                *tp_loc = tp;
        if (!*ltp_loc)
@@ -2148,7 +2150,7 @@ static int init_dev(struct tty_driver *driver, int idx,
        driver->refcount++;
        tty->count++;
 
-       /* 
+       /*
         * Structures all installed ... call the ldisc open routines.
         * If we fail here just call release_tty to clean up.  No need
         * to decrement the use counts, as release_tty doesn't care.
@@ -2185,7 +2187,7 @@ fast_track:
        if (driver->type == TTY_DRIVER_TYPE_PTY &&
            driver->subtype == PTY_TYPE_MASTER) {
                /*
-                * special case for PTY masters: only one open permitted, 
+                * special case for PTY masters: only one open permitted,
                 * and the slave side open count is incremented as well.
                 */
                if (tty->count) {
@@ -2198,11 +2200,11 @@ fast_track:
        tty->driver = driver; /* N.B. why do this every time?? */
 
        /* FIXME */
-       if(!test_bit(TTY_LDISC, &tty->flags))
+       if (!test_bit(TTY_LDISC, &tty->flags))
                printk(KERN_ERR "init_dev but no ldisc\n");
 success:
        *ret_tty = tty;
-       
+
        /* All paths come through here to release the mutex */
 end_init:
        return retval;
@@ -2304,7 +2306,7 @@ static void release_tty(struct tty_struct *tty, int idx)
  * WSH 09/09/97: rewritten to avoid some nasty race conditions that could
  * lead to double frees or releasing memory still in use.
  */
-static void release_dev(struct file * filp)
+static void release_dev(struct file *filp)
 {
        struct tty_struct *tty, *o_tty;
        int     pty_master, tty_closing, o_tty_closing, do_sleep;
@@ -2312,9 +2314,10 @@ static void release_dev(struct file * filp)
        int     idx;
        char    buf[64];
        unsigned long flags;
-       
+
        tty = (struct tty_struct *)filp->private_data;
-       if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "release_dev"))
+       if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode,
+                                                       "release_dev"))
                return;
 
        check_tty_count(tty, "release_dev");
@@ -2374,7 +2377,7 @@ static void release_dev(struct file * filp)
                               idx, tty->name);
                        return;
                }
-               if (o_tty->termios_locked != 
+               if (o_tty->termios_locked !=
                      tty->driver->other->termios_locked[idx]) {
                        printk(KERN_DEBUG "release_dev: other->termios_locked["
                                          "%d] not o_termios_locked for (%s)\n",
@@ -2410,7 +2413,7 @@ static void release_dev(struct file * filp)
        while (1) {
                /* Guard against races with tty->count changes elsewhere and
                   opens on /dev/tty */
-                  
+
                mutex_lock(&tty_mutex);
                tty_closing = tty->count <= 1;
                o_tty_closing = o_tty &&
@@ -2444,11 +2447,11 @@ static void release_dev(struct file * filp)
                                    "active!\n", tty_name(tty, buf));
                mutex_unlock(&tty_mutex);
                schedule();
-       }       
+       }
 
        /*
-        * The closing flags are now consistent with the open counts on 
-        * both sides, and we've completed the last operation that could 
+        * The closing flags are now consistent with the open counts on
+        * both sides, and we've completed the last operation that could
         * block, so it's safe to proceed with closing.
         */
        if (pty_master) {
@@ -2464,7 +2467,7 @@ static void release_dev(struct file * filp)
                       tty->count, tty_name(tty, buf));
                tty->count = 0;
        }
-       
+
        /*
         * We've decremented tty->count, so we need to remove this file
         * descriptor off the tty->tty_files list; this serves two
@@ -2484,9 +2487,9 @@ static void release_dev(struct file * filp)
         * case of a pty we may have to wait around for the other side
         * to close, and TTY_CLOSING makes sure we can't be reopened.
         */
-       if(tty_closing)
+       if (tty_closing)
                set_bit(TTY_CLOSING, &tty->flags);
-       if(o_tty_closing)
+       if (o_tty_closing)
                set_bit(TTY_CLOSING, &o_tty->flags);
 
        /*
@@ -2507,7 +2510,7 @@ static void release_dev(struct file * filp)
        /* check whether both sides are closing ... */
        if (!tty_closing || (o_tty && !o_tty_closing))
                return;
-       
+
 #ifdef TTY_DEBUG_HANGUP
        printk(KERN_DEBUG "freeing tty structure...");
 #endif
@@ -2522,17 +2525,16 @@ static void release_dev(struct file * filp)
        /*
         * Wait for ->hangup_work and ->buf.work handlers to terminate
         */
-        
+
        flush_scheduled_work();
-       
+
        /*
         * Wait for any short term users (we know they are just driver
         * side waiters as the file is closing so user count on the file
         * side is zero.
         */
        spin_lock_irqsave(&tty_ldisc_lock, flags);
-       while(tty->ldisc.refcount)
-       {
+       while (tty->ldisc.refcount) {
                spin_unlock_irqrestore(&tty_ldisc_lock, flags);
                wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0);
                spin_lock_irqsave(&tty_ldisc_lock, flags);
@@ -2547,12 +2549,12 @@ static void release_dev(struct file * filp)
        if (tty->ldisc.close)
                (tty->ldisc.close)(tty);
        tty_ldisc_put(tty->ldisc.num);
-       
+
        /*
         *      Switch the line discipline back
         */
        tty_ldisc_assign(tty, tty_ldisc_get(N_TTY));
-       tty_set_termios_ldisc(tty,N_TTY); 
+       tty_set_termios_ldisc(tty, N_TTY);
        if (o_tty) {
                /* FIXME: could o_tty be in setldisc here ? */
                clear_bit(TTY_LDISC, &o_tty->flags);
@@ -2560,7 +2562,7 @@ static void release_dev(struct file * filp)
                        (o_tty->ldisc.close)(o_tty);
                tty_ldisc_put(o_tty->ldisc.num);
                tty_ldisc_assign(o_tty, tty_ldisc_get(N_TTY));
-               tty_set_termios_ldisc(o_tty,N_TTY); 
+               tty_set_termios_ldisc(o_tty, N_TTY);
        }
        /*
         * The release_tty function takes care of the details of clearing
@@ -2600,7 +2602,7 @@ static void release_dev(struct file * filp)
  *              ->siglock protects ->signal/->sighand
  */
 
-static int tty_open(struct inode * inode, struct file * filp)
+static int tty_open(struct inode *inode, struct file *filp)
 {
        struct tty_struct *tty;
        int noctty, retval;
@@ -2610,15 +2612,15 @@ static int tty_open(struct inode * inode, struct file * filp)
        unsigned short saved_flags = filp->f_flags;
 
        nonseekable_open(inode, filp);
-       
+
 retry_open:
        noctty = filp->f_flags & O_NOCTTY;
        index  = -1;
        retval = 0;
-       
+
        mutex_lock(&tty_mutex);
 
-       if (device == MKDEV(TTYAUX_MAJOR,0)) {
+       if (device == MKDEV(TTYAUX_MAJOR, 0)) {
                tty = get_current_tty();
                if (!tty) {
                        mutex_unlock(&tty_mutex);
@@ -2631,7 +2633,7 @@ retry_open:
                goto got_driver;
        }
 #ifdef CONFIG_VT
-       if (device == MKDEV(TTY_MAJOR,0)) {
+       if (device == MKDEV(TTY_MAJOR, 0)) {
                extern struct tty_driver *console_driver;
                driver = console_driver;
                index = fg_console;
@@ -2639,7 +2641,7 @@ retry_open:
                goto got_driver;
        }
 #endif
-       if (device == MKDEV(TTYAUX_MAJOR,1)) {
+       if (device == MKDEV(TTYAUX_MAJOR, 1)) {
                driver = console_device(&index);
                if (driver) {
                        /* Don't let /dev/console block */
@@ -2679,7 +2681,8 @@ got_driver:
        }
        filp->f_flags = saved_flags;
 
-       if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN))
+       if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) &&
+                                               !capable(CAP_SYS_ADMIN))
                retval = -EBUSY;
 
        if (retval) {
@@ -2723,11 +2726,11 @@ got_driver:
  *     Allocate a unix98 pty master device from the ptmx driver.
  *
  *     Locking: tty_mutex protects theinit_dev work. tty->count should
              protect the rest.
*             protect the rest.
  *             allocated_ptys_lock handles the list of free pty numbers
  */
 
-static int ptmx_open(struct inode * inode, struct file * filp)
+static int ptmx_open(struct inode *inode, struct file *filp)
 {
        struct tty_struct *tty;
        int retval;
@@ -2759,7 +2762,7 @@ static int ptmx_open(struct inode * inode, struct file * filp)
        mutex_lock(&tty_mutex);
        retval = init_dev(ptm_driver, index, &tty);
        mutex_unlock(&tty_mutex);
-       
+
        if (retval)
                goto out;
 
@@ -2800,7 +2803,7 @@ out:
  *             Takes bkl. See release_dev
  */
 
-static int tty_release(struct inode * inode, struct file * filp)
+static int tty_release(struct inode *inode, struct file *filp)
 {
        lock_kernel();
        release_dev(filp);
@@ -2820,16 +2823,16 @@ static int tty_release(struct inode * inode, struct file * filp)
  *     may be re-entered freely by other callers.
  */
 
-static unsigned int tty_poll(struct file * filp, poll_table * wait)
+static unsigned int tty_poll(struct file *filp, poll_table *wait)
 {
-       struct tty_struct * tty;
+       struct tty_struct *tty;
        struct tty_ldisc *ld;
        int ret = 0;
 
        tty = (struct tty_struct *)filp->private_data;
        if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_poll"))
                return 0;
-               
+
        ld = tty_ldisc_ref_wait(tty);
        if (ld->poll)
                ret = (ld->poll)(tty, filp, wait);
@@ -2837,15 +2840,15 @@ static unsigned int tty_poll(struct file * filp, poll_table * wait)
        return ret;
 }
 
-static int tty_fasync(int fd, struct file * filp, int on)
+static int tty_fasync(int fd, struct file *filp, int on)
 {
-       struct tty_struct * tty;
+       struct tty_struct *tty;
        int retval;
 
        tty = (struct tty_struct *)filp->private_data;
        if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_fasync"))
                return 0;
-       
+
        retval = fasync_helper(fd, filp, on, &tty->fasync);
        if (retval <= 0)
                return retval;
@@ -2893,7 +2896,7 @@ static int tiocsti(struct tty_struct *tty, char __user *p)
 {
        char ch, mbz = 0;
        struct tty_ldisc *ld;
-       
+
        if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
                return -EPERM;
        if (get_user(ch, p))
@@ -2915,7 +2918,7 @@ static int tiocsti(struct tty_struct *tty, char __user *p)
  *             is consistent.
  */
 
-static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg)
+static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg)
 {
        int err;
 
@@ -2944,7 +2947,7 @@ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user * arg)
  */
 
 static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
-       struct winsize __user * arg)
+       struct winsize __user *arg)
 {
        struct winsize tmp_ws;
 
@@ -2960,7 +2963,7 @@ static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
                if (vc_lock_resize(tty->driver_data, tmp_ws.ws_col,
                                        tmp_ws.ws_row)) {
                        mutex_unlock(&tty->termios_mutex);
-                       return -ENXIO;
+                       return -ENXIO;
                }
        }
 #endif
@@ -3070,7 +3073,7 @@ static int tiocsctty(struct tty_struct *tty, int arg)
                 * This tty is already the controlling
                 * tty for another session group!
                 */
-               if ((arg == 1) && capable(CAP_SYS_ADMIN)) {
+               if (arg == 1 && capable(CAP_SYS_ADMIN)) {
                        /*
                         * Steal it away
                         */
@@ -3303,14 +3306,14 @@ static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int
 /*
  * Split this up, as gcc can choke on it otherwise..
  */
-int tty_ioctl(struct inode * inode, struct file * file,
+int tty_ioctl(struct inode *inode, struct file *file,
              unsigned int cmd, unsigned long arg)
 {
        struct tty_struct *tty, *real_tty;
        void __user *p = (void __user *)arg;
        int retval;
        struct tty_ldisc *ld;
-       
+
        tty = (struct tty_struct *)file->private_data;
        if (tty_paranoia_check(tty, inode, "tty_ioctl"))
                return -EINVAL;
@@ -3326,13 +3329,13 @@ int tty_ioctl(struct inode * inode, struct file * file,
         * Break handling by driver
         */
        if (!tty->driver->break_ctl) {
-               switch(cmd) {
+               switch (cmd) {
                case TIOCSBRK:
                case TIOCCBRK:
                        if (tty->driver->ioctl)
                                return tty->driver->ioctl(tty, file, cmd, arg);
                        return -EINVAL;
-                       
+
                /* These two ioctl's always return success; even if */
                /* the driver doesn't support them. */
                case TCSBRK:
@@ -3354,7 +3357,7 @@ int tty_ioctl(struct inode * inode, struct file * file,
        case TIOCSBRK:
        case TIOCCBRK:
        case TCSBRK:
-       case TCSBRKP:                   
+       case TCSBRKP:
                retval = tty_check_change(tty);
                if (retval)
                        return retval;
@@ -3367,81 +3370,80 @@ int tty_ioctl(struct inode * inode, struct file * file,
        }
 
        switch (cmd) {
-               case TIOCSTI:
-                       return tiocsti(tty, p);
-               case TIOCGWINSZ:
-                       return tiocgwinsz(tty, p);
-               case TIOCSWINSZ:
-                       return tiocswinsz(tty, real_tty, p);
-               case TIOCCONS:
-                       return real_tty!=tty ? -EINVAL : tioccons(file);
-               case FIONBIO:
-                       return fionbio(file, p);
-               case TIOCEXCL:
-                       set_bit(TTY_EXCLUSIVE, &tty->flags);
-                       return 0;
-               case TIOCNXCL:
-                       clear_bit(TTY_EXCLUSIVE, &tty->flags);
-                       return 0;
-               case TIOCNOTTY:
-                       if (current->signal->tty != tty)
-                               return -ENOTTY;
-                       no_tty();
-                       return 0;
-               case TIOCSCTTY:
-                       return tiocsctty(tty, arg);
-               case TIOCGPGRP:
-                       return tiocgpgrp(tty, real_tty, p);
-               case TIOCSPGRP:
-                       return tiocspgrp(tty, real_tty, p);
-               case TIOCGSID:
-                       return tiocgsid(tty, real_tty, p);
-               case TIOCGETD:
-                       /* FIXME: check this is ok */
-                       return put_user(tty->ldisc.num, (int __user *)p);
-               case TIOCSETD:
-                       return tiocsetd(tty, p);
+       case TIOCSTI:
+               return tiocsti(tty, p);
+       case TIOCGWINSZ:
+               return tiocgwinsz(tty, p);
+       case TIOCSWINSZ:
+               return tiocswinsz(tty, real_tty, p);
+       case TIOCCONS:
+               return real_tty != tty ? -EINVAL : tioccons(file);
+       case FIONBIO:
+               return fionbio(file, p);
+       case TIOCEXCL:
+               set_bit(TTY_EXCLUSIVE, &tty->flags);
+               return 0;
+       case TIOCNXCL:
+               clear_bit(TTY_EXCLUSIVE, &tty->flags);
+               return 0;
+       case TIOCNOTTY:
+               if (current->signal->tty != tty)
+                       return -ENOTTY;
+               no_tty();
+               return 0;
+       case TIOCSCTTY:
+               return tiocsctty(tty, arg);
+       case TIOCGPGRP:
+               return tiocgpgrp(tty, real_tty, p);
+       case TIOCSPGRP:
+               return tiocspgrp(tty, real_tty, p);
+       case TIOCGSID:
+               return tiocgsid(tty, real_tty, p);
+       case TIOCGETD:
+               /* FIXME: check this is ok */
+               return put_user(tty->ldisc.num, (int __user *)p);
+       case TIOCSETD:
+               return tiocsetd(tty, p);
 #ifdef CONFIG_VT
-               case TIOCLINUX:
-                       return tioclinux(tty, arg);
+       case TIOCLINUX:
+               return tioclinux(tty, arg);
 #endif
-               /*
-                * Break handling
-                */
-               case TIOCSBRK:  /* Turn break on, unconditionally */
-                       tty->driver->break_ctl(tty, -1);
-                       return 0;
-                       
-               case TIOCCBRK:  /* Turn break off, unconditionally */
-                       tty->driver->break_ctl(tty, 0);
-                       return 0;
-               case TCSBRK:   /* SVID version: non-zero arg --> no break */
-                       /* non-zero arg means wait for all output data
-                        * to be sent (performed above) but don't send break.
-                        * This is used by the tcdrain() termios function.
-                        */
-                       if (!arg)
-                               return send_break(tty, 250);
-                       return 0;
-               case TCSBRKP:   /* support for POSIX tcsendbreak() */   
-                       return send_break(tty, arg ? arg*100 : 250);
-
-               case TIOCMGET:
-                       return tty_tiocmget(tty, file, p);
+       /*
+        * Break handling
+        */
+       case TIOCSBRK:  /* Turn break on, unconditionally */
+               tty->driver->break_ctl(tty, -1);
+               return 0;
 
-               case TIOCMSET:
-               case TIOCMBIC:
-               case TIOCMBIS:
-                       return tty_tiocmset(tty, file, cmd, p);
-               case TCFLSH:
-                       switch (arg) {
-                       case TCIFLUSH:
-                       case TCIOFLUSH:
-                               /* flush tty buffer and allow ldisc to process ioctl */
-                               tty_buffer_flush(tty);
-                               break;
-                       }
+       case TIOCCBRK:  /* Turn break off, unconditionally */
+               tty->driver->break_ctl(tty, 0);
+               return 0;
+       case TCSBRK:   /* SVID version: non-zero arg --> no break */
+               /* non-zero arg means wait for all output data
+                * to be sent (performed above) but don't send break.
+                * This is used by the tcdrain() termios function.
+                */
+               if (!arg)
+                       return send_break(tty, 250);
+               return 0;
+       case TCSBRKP:   /* support for POSIX tcsendbreak() */
+               return send_break(tty, arg ? arg*100 : 250);
+
+       case TIOCMGET:
+               return tty_tiocmget(tty, file, p);
+       case TIOCMSET:
+       case TIOCMBIC:
+       case TIOCMBIS:
+               return tty_tiocmset(tty, file, cmd, p);
+       case TCFLSH:
+               switch (arg) {
+               case TCIFLUSH:
+               case TCIOFLUSH:
+               /* flush tty buffer and allow ldisc to process ioctl */
+                       tty_buffer_flush(tty);
                        break;
+               }
+               break;
        }
        if (tty->driver->ioctl) {
                retval = (tty->driver->ioctl)(tty, file, cmd, arg);
@@ -3460,7 +3462,7 @@ int tty_ioctl(struct inode * inode, struct file * file,
 }
 
 #ifdef CONFIG_COMPAT
-static long tty_compat_ioctl(struct file * file, unsigned int cmd,
+static long tty_compat_ioctl(struct file *file, unsigned int cmd,
                                unsigned long arg)
 {
        struct inode *inode = file->f_dentry->d_inode;
@@ -3491,7 +3493,7 @@ static long tty_compat_ioctl(struct file * file, unsigned int cmd,
  * prevent trojan horses by killing all processes associated with this
  * tty when the user hits the "Secure Attention Key".  Required for
  * super-paranoid applications --- see the Orange Book for more details.
- * 
+ *
  * This code could be nicer; ideally it should send a HUP, wait a few
  * seconds, then send a INT, and then a KILL signal.  But you then
  * have to coordinate with the init process, since all processes associated
@@ -3515,16 +3517,16 @@ void __do_SAK(struct tty_struct *tty)
        int             i;
        struct file     *filp;
        struct fdtable *fdt;
-       
+
        if (!tty)
                return;
        session = tty->session;
-       
+
        tty_ldisc_flush(tty);
 
        if (tty->driver->flush_buffer)
                tty->driver->flush_buffer(tty);
-       
+
        read_lock(&tasklist_lock);
        /* Kill the entire session */
        do_each_pid_task(session, PIDTYPE_SID, p) {
@@ -3552,7 +3554,7 @@ void __do_SAK(struct tty_struct *tty)
                         */
                        spin_lock(&p->files->file_lock);
                        fdt = files_fdtable(p->files);
-                       for (i=0; i < fdt->max_fds; i++) {
+                       for (i = 0; i < fdt->max_fds; i++) {
                                filp = fcheck_files(p->files, i);
                                if (!filp)
                                        continue;
@@ -3606,7 +3608,7 @@ EXPORT_SYMBOL(do_SAK);
  *     while invoking the line discipline receive_buf method. The
  *     receive_buf method is single threaded for each tty instance.
  */
+
 static void flush_to_ldisc(struct work_struct *work)
 {
        struct tty_struct *tty =
@@ -3622,7 +3624,8 @@ static void flush_to_ldisc(struct work_struct *work)
                return;
 
        spin_lock_irqsave(&tty->buf.lock, flags);
-       set_bit(TTY_FLUSHING, &tty->flags);     /* So we know a flush is running */
+       /* So we know a flush is running */
+       set_bit(TTY_FLUSHING, &tty->flags);
        head = tty->buf.head;
        if (head != NULL) {
                tty->buf.head = NULL;
@@ -3795,7 +3798,8 @@ struct device *tty_register_device(struct tty_driver *driver, unsigned index,
 
 void tty_unregister_device(struct tty_driver *driver, unsigned index)
 {
-       device_destroy(tty_class, MKDEV(driver->major, driver->minor_start) + index);
+       device_destroy(tty_class,
+               MKDEV(driver->major, driver->minor_start) + index);
 }
 
 EXPORT_SYMBOL(tty_register_device);
@@ -3859,7 +3863,7 @@ EXPORT_SYMBOL(tty_set_operations);
 int tty_register_driver(struct tty_driver *driver)
 {
        int error;
-        int i;
+       int i;
        dev_t dev;
        void **p = NULL;
 
@@ -3873,8 +3877,8 @@ int tty_register_driver(struct tty_driver *driver)
        }
 
        if (!driver->major) {
-               error = alloc_chrdev_region(&dev, driver->minor_start, driver->num,
-                                               driver->name);
+               error = alloc_chrdev_region(&dev, driver->minor_start,
+                                               driver->num, driver->name);
                if (!error) {
                        driver->major = MAJOR(dev);
                        driver->minor_start = MINOR(dev);
@@ -3891,7 +3895,8 @@ int tty_register_driver(struct tty_driver *driver)
        if (p) {
                driver->ttys = (struct tty_struct **)p;
                driver->termios = (struct ktermios **)(p + driver->num);
-               driver->termios_locked = (struct ktermios **)(p + driver->num * 2);
+               driver->termios_locked = (struct ktermios **)
+                                                       (p + driver->num * 2);
        } else {
                driver->ttys = NULL;
                driver->termios = NULL;
@@ -3911,13 +3916,13 @@ int tty_register_driver(struct tty_driver *driver)
 
        if (!driver->put_char)
                driver->put_char = tty_default_put_char;
-       
+
        mutex_lock(&tty_mutex);
        list_add(&driver->tty_drivers, &tty_drivers);
        mutex_unlock(&tty_mutex);
-       
-       if ( !(driver->flags & TTY_DRIVER_DYNAMIC_DEV) ) {
-               for(i = 0; i < driver->num; i++)
+
+       if (!(driver->flags & TTY_DRIVER_DYNAMIC_DEV)) {
+               for (i = 0; i < driver->num; i++)
                    tty_register_device(driver, i, NULL);
        }
        proc_tty_register_driver(driver);
@@ -4037,7 +4042,7 @@ void __init console_init(void)
        (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY);
 
        /*
-        * set up the console device so that later boot sequences can 
+        * set up the console device so that later boot sequences can
         * inform about problems etc..
         */
        call = __con_initcall_start;
index d4b6d64e858b5e4ec18255a992ce0e57a0cbd92b..f95a80b2265fdf0f42829f750c0c19f491eec044 100644 (file)
  *     Locking: none
  */
 
-void tty_wait_until_sent(struct tty_struct * tty, long timeout)
+void tty_wait_until_sent(struct tty_struct *tty, long timeout)
 {
 #ifdef TTY_DEBUG_WAIT_UNTIL_SENT
        char buf[64];
-       
+
        printk(KERN_DEBUG "%s wait until sent...\n", tty_name(tty, buf));
 #endif
        if (!tty->driver->chars_in_buffer)
@@ -67,7 +67,6 @@ void tty_wait_until_sent(struct tty_struct * tty, long timeout)
        if (tty->driver->wait_until_sent)
                tty->driver->wait_until_sent(tty, timeout);
 }
-
 EXPORT_SYMBOL(tty_wait_until_sent);
 
 static void unset_locked_termios(struct ktermios *termios,
@@ -75,8 +74,8 @@ static void unset_locked_termios(struct ktermios *termios,
                                 struct ktermios *locked)
 {
        int     i;
-       
-#define NOSET_MASK(x,y,z) (x = ((x) & ~(z)) | ((y) & (z)))
+
+#define NOSET_MASK(x, y, z) (x = ((x) & ~(z)) | ((y) & (z)))
 
        if (!locked) {
                printk(KERN_WARNING "Warning?!? termios_locked is NULL.\n");
@@ -88,7 +87,7 @@ static void unset_locked_termios(struct ktermios *termios,
        NOSET_MASK(termios->c_cflag, old->c_cflag, locked->c_cflag);
        NOSET_MASK(termios->c_lflag, old->c_lflag, locked->c_lflag);
        termios->c_line = locked->c_line ? old->c_line : termios->c_line;
-       for (i=0; i < NCCS; i++)
+       for (i = 0; i < NCCS; i++)
                termios->c_cc[i] = locked->c_cc[i] ?
                        old->c_cc[i] : termios->c_cc[i];
        /* FIXME: What should we do for i/ospeed */
@@ -163,7 +162,6 @@ speed_t tty_termios_baud_rate(struct ktermios *termios)
        }
        return baud_table[cbaud];
 }
-
 EXPORT_SYMBOL(tty_termios_baud_rate);
 
 /**
@@ -203,7 +201,6 @@ speed_t tty_termios_input_baud_rate(struct ktermios *termios)
        return tty_termios_baud_rate(termios);
 #endif
 }
-
 EXPORT_SYMBOL(tty_termios_input_baud_rate);
 
 /**
@@ -338,7 +335,6 @@ speed_t tty_get_baud_rate(struct tty_struct *tty)
 
        return baud;
 }
-
 EXPORT_SYMBOL(tty_get_baud_rate);
 
 /**
@@ -361,7 +357,6 @@ void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old)
        new->c_ispeed = old->c_ispeed;
        new->c_ospeed = old->c_ospeed;
 }
-
 EXPORT_SYMBOL(tty_termios_copy_hw);
 
 /**
@@ -395,16 +390,16 @@ EXPORT_SYMBOL(tty_termios_hw_change);
  *     Locking: termios_sem
  */
 
-static void change_termios(struct tty_struct * tty, struct ktermios * new_termios)
+static void change_termios(struct tty_struct *tty, struct ktermios *new_termios)
 {
        int canon_change;
        struct ktermios old_termios = *tty->termios;
        struct tty_ldisc *ld;
-       
+
        /*
         *      Perform the actual termios internal changes under lock.
         */
-        
+
 
        /* FIXME: we need to decide on some locking/ordering semantics
           for the set_termios notification eventually */
@@ -419,7 +414,7 @@ static void change_termios(struct tty_struct * tty, struct ktermios * new_termio
                tty->canon_data = 0;
                tty->erasing = 0;
        }
-       
+
        /* This bit should be in the ldisc code */
        if (canon_change && !L_ICANON(tty) && tty->read_cnt)
                /* Get characters left over from canonical mode. */
@@ -442,7 +437,7 @@ static void change_termios(struct tty_struct * tty, struct ktermios * new_termio
                        wake_up_interruptible(&tty->link->read_wait);
                }
        }
-          
+
        if (tty->driver->set_termios)
                (*tty->driver->set_termios)(tty, &old_termios);
        else
@@ -470,7 +465,7 @@ static void change_termios(struct tty_struct * tty, struct ktermios * new_termio
  *             Called functions take ldisc and termios_sem locks
  */
 
-static int set_termios(struct tty_struct * tty, void __user *arg, int opt)
+static int set_termios(struct tty_struct *tty, void __user *arg, int opt)
 {
        struct ktermios tmp_termios;
        struct tty_ldisc *ld;
@@ -501,19 +496,19 @@ static int set_termios(struct tty_struct * tty, void __user *arg, int opt)
                return -EFAULT;
 #endif
 
-       /* If old style Bfoo values are used then load c_ispeed/c_ospeed with the real speed
-          so its unconditionally usable */
+       /* If old style Bfoo values are used then load c_ispeed/c_ospeed
+        * with the real speed so its unconditionally usable */
        tmp_termios.c_ispeed = tty_termios_input_baud_rate(&tmp_termios);
        tmp_termios.c_ospeed = tty_termios_baud_rate(&tmp_termios);
 
        ld = tty_ldisc_ref(tty);
-       
+
        if (ld != NULL) {
                if ((opt & TERMIOS_FLUSH) && ld->flush_buffer)
                        ld->flush_buffer(tty);
                tty_ldisc_deref(ld);
        }
-       
+
        if (opt & TERMIOS_WAIT) {
                tty_wait_until_sent(tty, 0);
                if (signal_pending(current))
@@ -529,14 +524,14 @@ static int set_termios(struct tty_struct * tty, void __user *arg, int opt)
        return 0;
 }
 
-static int get_termio(struct tty_struct * tty, struct termio __user * termio)
+static int get_termio(struct tty_struct *tty, struct termio __user *termio)
 {
        if (kernel_termios_to_user_termio(termio, tty->termios))
                return -EFAULT;
        return 0;
 }
 
-static unsigned long inq_canon(struct tty_struct * tty)
+static unsigned long inq_canon(struct tty_struct *tty)
 {
        int nr, head, tail;
 
@@ -561,7 +556,7 @@ static unsigned long inq_canon(struct tty_struct * tty)
  *
  * The "sg_flags" translation is a joke..
  */
-static int get_sgflags(struct tty_struct * tty)
+static int get_sgflags(struct tty_struct *tty)
 {
        int flags = 0;
 
@@ -579,7 +574,7 @@ static int get_sgflags(struct tty_struct * tty)
        return flags;
 }
 
-static int get_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
+static int get_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb)
 {
        struct sgttyb tmp;
 
@@ -590,11 +585,11 @@ static int get_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
        tmp.sg_kill = tty->termios->c_cc[VKILL];
        tmp.sg_flags = get_sgflags(tty);
        mutex_unlock(&tty->termios_mutex);
-       
+
        return copy_to_user(sgttyb, &tmp, sizeof(tmp)) ? -EFAULT : 0;
 }
 
-static void set_sgflags(struct ktermios * termios, int flags)
+static void set_sgflags(struct ktermios *termios, int flags)
 {
        termios->c_iflag = ICRNL | IXON;
        termios->c_oflag = 0;
@@ -631,7 +626,7 @@ static void set_sgflags(struct ktermios * termios, int flags)
  *     Locking: termios_sem
  */
 
-static int set_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
+static int set_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb)
 {
        int retval;
        struct sgttyb tmp;
@@ -640,7 +635,7 @@ static int set_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
        retval = tty_check_change(tty);
        if (retval)
                return retval;
-       
+
        if (copy_from_user(&tmp, sgttyb, sizeof(tmp)))
                return -EFAULT;
 
@@ -651,7 +646,8 @@ static int set_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
        set_sgflags(&termios, tmp.sg_flags);
        /* Try and encode into Bfoo format */
 #ifdef BOTHER
-       tty_termios_encode_baud_rate(&termios, termios.c_ispeed, termios.c_ospeed);
+       tty_termios_encode_baud_rate(&termios, termios.c_ispeed,
+                                               termios.c_ospeed);
 #endif
        mutex_unlock(&tty->termios_mutex);
        change_termios(tty, &termios);
@@ -660,7 +656,7 @@ static int set_sgttyb(struct tty_struct * tty, struct sgttyb __user * sgttyb)
 #endif
 
 #ifdef TIOCGETC
-static int get_tchars(struct tty_struct * tty, struct tchars __user * tchars)
+static int get_tchars(struct tty_struct *tty, struct tchars __user *tchars)
 {
        struct tchars tmp;
 
@@ -673,7 +669,7 @@ static int get_tchars(struct tty_struct * tty, struct tchars __user * tchars)
        return copy_to_user(tchars, &tmp, sizeof(tmp)) ? -EFAULT : 0;
 }
 
-static int set_tchars(struct tty_struct * tty, struct tchars __user * tchars)
+static int set_tchars(struct tty_struct *tty, struct tchars __user *tchars)
 {
        struct tchars tmp;
 
@@ -690,20 +686,22 @@ static int set_tchars(struct tty_struct * tty, struct tchars __user * tchars)
 #endif
 
 #ifdef TIOCGLTC
-static int get_ltchars(struct tty_struct * tty, struct ltchars __user * ltchars)
+static int get_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars)
 {
        struct ltchars tmp;
 
        tmp.t_suspc = tty->termios->c_cc[VSUSP];
-       tmp.t_dsuspc = tty->termios->c_cc[VSUSP];       /* what is dsuspc anyway? */
+       /* what is dsuspc anyway? */
+       tmp.t_dsuspc = tty->termios->c_cc[VSUSP];
        tmp.t_rprntc = tty->termios->c_cc[VREPRINT];
-       tmp.t_flushc = tty->termios->c_cc[VEOL2];       /* what is flushc anyway? */
+       /* what is flushc anyway? */
+       tmp.t_flushc = tty->termios->c_cc[VEOL2];
        tmp.t_werasc = tty->termios->c_cc[VWERASE];
        tmp.t_lnextc = tty->termios->c_cc[VLNEXT];
        return copy_to_user(ltchars, &tmp, sizeof(tmp)) ? -EFAULT : 0;
 }
 
-static int set_ltchars(struct tty_struct * tty, struct ltchars __user * ltchars)
+static int set_ltchars(struct tty_struct *tty, struct ltchars __user *ltchars)
 {
        struct ltchars tmp;
 
@@ -711,9 +709,11 @@ static int set_ltchars(struct tty_struct * tty, struct ltchars __user * ltchars)
                return -EFAULT;
 
        tty->termios->c_cc[VSUSP] = tmp.t_suspc;
-       tty->termios->c_cc[VEOL2] = tmp.t_dsuspc;       /* what is dsuspc anyway? */
+       /* what is dsuspc anyway? */
+       tty->termios->c_cc[VEOL2] = tmp.t_dsuspc;
        tty->termios->c_cc[VREPRINT] = tmp.t_rprntc;
-       tty->termios->c_cc[VEOL2] = tmp.t_flushc;       /* what is flushc anyway? */
+       /* what is flushc anyway? */
+       tty->termios->c_cc[VEOL2] = tmp.t_flushc;
        tty->termios->c_cc[VWERASE] = tmp.t_werasc;
        tty->termios->c_cc[VLNEXT] = tmp.t_lnextc;
        return 0;
@@ -761,10 +761,10 @@ static int send_prio_char(struct tty_struct *tty, char ch)
  *     consistent mode setting.
  */
 
-int tty_mode_ioctl(struct tty_struct * tty, struct file *file,
+int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
                        unsigned int cmd, unsigned long arg)
 {
-       struct tty_struct * real_tty;
+       struct tty_struct *real_tty;
        void __user *p = (void __user *)arg;
 
        if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
@@ -775,100 +775,100 @@ int tty_mode_ioctl(struct tty_struct * tty, struct file *file,
 
        switch (cmd) {
 #ifdef TIOCGETP
-               case TIOCGETP:
-                       return get_sgttyb(real_tty, (struct sgttyb __user *) arg);
-               case TIOCSETP:
-               case TIOCSETN:
-                       return set_sgttyb(real_tty, (struct sgttyb __user *) arg);
+       case TIOCGETP:
+               return get_sgttyb(real_tty, (struct sgttyb __user *) arg);
+       case TIOCSETP:
+       case TIOCSETN:
+               return set_sgttyb(real_tty, (struct sgttyb __user *) arg);
 #endif
 #ifdef TIOCGETC
-               case TIOCGETC:
-                       return get_tchars(real_tty, p);
-               case TIOCSETC:
-                       return set_tchars(real_tty, p);
+       case TIOCGETC:
+               return get_tchars(real_tty, p);
+       case TIOCSETC:
+               return set_tchars(real_tty, p);
 #endif
 #ifdef TIOCGLTC
-               case TIOCGLTC:
-                       return get_ltchars(real_tty, p);
-               case TIOCSLTC:
-                       return set_ltchars(real_tty, p);
+       case TIOCGLTC:
+               return get_ltchars(real_tty, p);
+       case TIOCSLTC:
+               return set_ltchars(real_tty, p);
 #endif
-               case TCSETSF:
-                       return set_termios(real_tty, p,  TERMIOS_FLUSH | TERMIOS_WAIT | TERMIOS_OLD);
-               case TCSETSW:
-                       return set_termios(real_tty, p, TERMIOS_WAIT | TERMIOS_OLD);
-               case TCSETS:
-                       return set_termios(real_tty, p, TERMIOS_OLD);
+       case TCSETSF:
+               return set_termios(real_tty, p,  TERMIOS_FLUSH | TERMIOS_WAIT | TERMIOS_OLD);
+       case TCSETSW:
+               return set_termios(real_tty, p, TERMIOS_WAIT | TERMIOS_OLD);
+       case TCSETS:
+               return set_termios(real_tty, p, TERMIOS_OLD);
 #ifndef TCGETS2
-               case TCGETS:
-                       if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios))
-                               return -EFAULT;
-                       return 0;
+       case TCGETS:
+               if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios))
+                       return -EFAULT;
+               return 0;
 #else
-               case TCGETS:
-                       if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios))
-                               return -EFAULT;
-                       return 0;
-               case TCGETS2:
-                       if (kernel_termios_to_user_termios((struct termios2 __user *)arg, real_tty->termios))
-                               return -EFAULT;
-                       return 0;
-               case TCSETSF2:
-                       return set_termios(real_tty, p,  TERMIOS_FLUSH | TERMIOS_WAIT);
-               case TCSETSW2:
-                       return set_termios(real_tty, p, TERMIOS_WAIT);
-               case TCSETS2:
-                       return set_termios(real_tty, p, 0);
+       case TCGETS:
+               if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios))
+                       return -EFAULT;
+               return 0;
+       case TCGETS2:
+               if (kernel_termios_to_user_termios((struct termios2 __user *)arg, real_tty->termios))
+                       return -EFAULT;
+               return 0;
+       case TCSETSF2:
+               return set_termios(real_tty, p,  TERMIOS_FLUSH | TERMIOS_WAIT);
+       case TCSETSW2:
+               return set_termios(real_tty, p, TERMIOS_WAIT);
+       case TCSETS2:
+               return set_termios(real_tty, p, 0);
 #endif
-               case TCGETA:
-                       return get_termio(real_tty, p);
-               case TCSETAF:
-                       return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT | TERMIOS_TERMIO);
-               case TCSETAW:
-                       return set_termios(real_tty, p, TERMIOS_WAIT | TERMIOS_TERMIO);
-               case TCSETA:
-                       return set_termios(real_tty, p, TERMIOS_TERMIO);
+       case TCGETA:
+               return get_termio(real_tty, p);
+       case TCSETAF:
+               return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT | TERMIOS_TERMIO);
+       case TCSETAW:
+               return set_termios(real_tty, p, TERMIOS_WAIT | TERMIOS_TERMIO);
+       case TCSETA:
+               return set_termios(real_tty, p, TERMIOS_TERMIO);
 #ifndef TCGETS2
-               case TIOCGLCKTRMIOS:
-                       if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios_locked))
-                               return -EFAULT;
-                       return 0;
-
-               case TIOCSLCKTRMIOS:
-                       if (!capable(CAP_SYS_ADMIN))
-                               return -EPERM;
-                       if (user_termios_to_kernel_termios(real_tty->termios_locked, (struct termios __user *) arg))
-                               return -EFAULT;
-                       return 0;
+       case TIOCGLCKTRMIOS:
+               if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios_locked))
+                       return -EFAULT;
+               return 0;
+       case TIOCSLCKTRMIOS:
+               if (!capable(CAP_SYS_ADMIN))
+                       return -EPERM;
+               if (user_termios_to_kernel_termios(real_tty->termios_locked,
+                                              (struct termios __user *) arg))
+                       return -EFAULT;
+               return 0;
 #else
-               case TIOCGLCKTRMIOS:
-                       if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios_locked))
-                               return -EFAULT;
-                       return 0;
-
-               case TIOCSLCKTRMIOS:
-                       if (!capable(CAP_SYS_ADMIN))
-                               return -EPERM;
-                       if (user_termios_to_kernel_termios_1(real_tty->termios_locked, (struct termios __user *) arg))
-                               return -EFAULT;
+       case TIOCGLCKTRMIOS:
+               if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios_locked))
+                       return -EFAULT;
+               return 0;
+       case TIOCSLCKTRMIOS:
+               if (!capable(CAP_SYS_ADMIN))
+                       return -EPERM;
+               if (user_termios_to_kernel_termios_1(real_tty->termios_locked,
+                                              (struct termios __user *) arg))
+                       return -EFAULT;
                        return 0;
 #endif
-               case TIOCGSOFTCAR:
-                       return put_user(C_CLOCAL(tty) ? 1 : 0, (int __user *)arg);
-               case TIOCSSOFTCAR:
-                       if (get_user(arg, (unsigned int __user *) arg))
-                               return -EFAULT;
-                       mutex_lock(&tty->termios_mutex);
-                       tty->termios->c_cflag =
-                               ((tty->termios->c_cflag & ~CLOCAL) |
-                                (arg ? CLOCAL : 0));
-                       mutex_unlock(&tty->termios_mutex);
-                       return 0;
-               default:
-                       return -ENOIOCTLCMD;
+       case TIOCGSOFTCAR:
+               return put_user(C_CLOCAL(tty) ? 1 : 0,
+                                               (int __user *)arg);
+       case TIOCSSOFTCAR:
+               if (get_user(arg, (unsigned int __user *) arg))
+                       return -EFAULT;
+               mutex_lock(&tty->termios_mutex);
+               tty->termios->c_cflag =
+                       ((tty->termios->c_cflag & ~CLOCAL) |
+                        (arg ? CLOCAL : 0));
+               mutex_unlock(&tty->termios_mutex);
+               return 0;
+       default:
+               return -ENOIOCTLCMD;
        }
 }
-
 EXPORT_SYMBOL_GPL(tty_mode_ioctl);
 
 int tty_perform_flush(struct tty_struct *tty, unsigned long arg)
@@ -899,13 +899,12 @@ int tty_perform_flush(struct tty_struct *tty, unsigned long arg)
        tty_ldisc_deref(ld);
        return 0;
 }
-
 EXPORT_SYMBOL_GPL(tty_perform_flush);
 
-int n_tty_ioctl(struct tty_struct * tty, struct file * file,
+int n_tty_ioctl(struct tty_struct *tty, struct file *file,
                       unsigned int cmd, unsigned long arg)
 {
-       struct tty_struct * real_tty;
+       struct tty_struct *real_tty;
        int retval;
 
        if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
@@ -915,68 +914,67 @@ int n_tty_ioctl(struct tty_struct * tty, struct file * file,
                real_tty = tty;
 
        switch (cmd) {
-               case TCXONC:
-                       retval = tty_check_change(tty);
-                       if (retval)
-                               return retval;
-                       switch (arg) {
-                       case TCOOFF:
-                               if (!tty->flow_stopped) {
-                                       tty->flow_stopped = 1;
-                                       stop_tty(tty);
-                               }
-                               break;
-                       case TCOON:
-                               if (tty->flow_stopped) {
-                                       tty->flow_stopped = 0;
-                                       start_tty(tty);
-                               }
-                               break;
-                       case TCIOFF:
-                               if (STOP_CHAR(tty) != __DISABLED_CHAR)
-                                       return send_prio_char(tty, STOP_CHAR(tty));
-                               break;
-                       case TCION:
-                               if (START_CHAR(tty) != __DISABLED_CHAR)
-                                       return send_prio_char(tty, START_CHAR(tty));
-                               break;
-                       default:
-                               return -EINVAL;
+       case TCXONC:
+               retval = tty_check_change(tty);
+               if (retval)
+                       return retval;
+               switch (arg) {
+               case TCOOFF:
+                       if (!tty->flow_stopped) {
+                               tty->flow_stopped = 1;
+                               stop_tty(tty);
                        }
-                       return 0;
-               case TCFLSH:
-                       return tty_perform_flush(tty, arg);
-               case TIOCOUTQ:
-                       return put_user(tty->driver->chars_in_buffer ?
-                                       tty->driver->chars_in_buffer(tty) : 0,
-                                       (int __user *) arg);
-               case TIOCINQ:
-                       retval = tty->read_cnt;
-                       if (L_ICANON(tty))
-                               retval = inq_canon(tty);
-                       return put_user(retval, (unsigned int __user *) arg);
-               case TIOCPKT:
-               {
-                       int pktmode;
-
-                       if (tty->driver->type != TTY_DRIVER_TYPE_PTY ||
-                           tty->driver->subtype != PTY_TYPE_MASTER)
-                               return -ENOTTY;
-                       if (get_user(pktmode, (int __user *) arg))
-                               return -EFAULT;
-                       if (pktmode) {
-                               if (!tty->packet) {
-                                       tty->packet = 1;
-                                       tty->link->ctrl_status = 0;
-                               }
-                       } else
-                               tty->packet = 0;
-                       return 0;
-               }
+                       break;
+               case TCOON:
+                       if (tty->flow_stopped) {
+                               tty->flow_stopped = 0;
+                               start_tty(tty);
+                       }
+                       break;
+               case TCIOFF:
+                       if (STOP_CHAR(tty) != __DISABLED_CHAR)
+                               return send_prio_char(tty, STOP_CHAR(tty));
+                       break;
+               case TCION:
+                       if (START_CHAR(tty) != __DISABLED_CHAR)
+                               return send_prio_char(tty, START_CHAR(tty));
+                       break;
                default:
-                       /* Try the mode commands */
-                       return tty_mode_ioctl(tty, file, cmd, arg);
+                       return -EINVAL;
                }
+               return 0;
+       case TCFLSH:
+               return tty_perform_flush(tty, arg);
+       case TIOCOUTQ:
+               return put_user(tty->driver->chars_in_buffer ?
+                               tty->driver->chars_in_buffer(tty) : 0,
+                               (int __user *) arg);
+       case TIOCINQ:
+               retval = tty->read_cnt;
+               if (L_ICANON(tty))
+                       retval = inq_canon(tty);
+               return put_user(retval, (unsigned int __user *) arg);
+       case TIOCPKT:
+       {
+               int pktmode;
+
+               if (tty->driver->type != TTY_DRIVER_TYPE_PTY ||
+                   tty->driver->subtype != PTY_TYPE_MASTER)
+                       return -ENOTTY;
+               if (get_user(pktmode, (int __user *) arg))
+                       return -EFAULT;
+               if (pktmode) {
+                       if (!tty->packet) {
+                               tty->packet = 1;
+                               tty->link->ctrl_status = 0;
+                       }
+               } else
+                       tty->packet = 0;
+               return 0;
+       }
+       default:
+               /* Try the mode commands */
+               return tty_mode_ioctl(tty, file, cmd, arg);
+       }
 }
-
 EXPORT_SYMBOL(n_tty_ioctl);
index e0bade732376555214e04831d7a27b45a3f3ee89..653265a40b7f9721eed8fcf1c08d6f75cdfdba3d 100644 (file)
@@ -43,18 +43,12 @@ static char * __init dmi_string(const struct dmi_header *dm, u8 s)
  *     We have to be cautious here. We have seen BIOSes with DMI pointers
  *     pointing to completely the wrong place for example
  */
-static int __init dmi_table(u32 base, int len, int num,
-                           void (*decode)(const struct dmi_header *))
+static void dmi_table(u8 *buf, int len, int num,
+                     void (*decode)(const struct dmi_header *))
 {
-       u8 *buf, *data;
+       u8 *data = buf;
        int i = 0;
 
-       buf = dmi_ioremap(base, len);
-       if (buf == NULL)
-               return -1;
-
-       data = buf;
-
        /*
         *      Stop when we see all the items the table claimed to have
         *      OR we run off the end of the table (also happens)
@@ -75,7 +69,23 @@ static int __init dmi_table(u32 base, int len, int num,
                data += 2;
                i++;
        }
-       dmi_iounmap(buf, len);
+}
+
+static u32 dmi_base;
+static u16 dmi_len;
+static u16 dmi_num;
+
+static int __init dmi_walk_early(void (*decode)(const struct dmi_header *))
+{
+       u8 *buf;
+
+       buf = dmi_ioremap(dmi_base, dmi_len);
+       if (buf == NULL)
+               return -1;
+
+       dmi_table(buf, dmi_len, dmi_num, decode);
+
+       dmi_iounmap(buf, dmi_len);
        return 0;
 }
 
@@ -240,6 +250,28 @@ static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
        list_add(&dev->list, &dmi_devices);
 }
 
+static void __init dmi_save_extended_devices(const struct dmi_header *dm)
+{
+       const u8 *d = (u8*) dm + 5;
+       struct dmi_device *dev;
+
+       /* Skip disabled device */
+       if ((*d & 0x80) == 0)
+               return;
+
+       dev = dmi_alloc(sizeof(*dev));
+       if (!dev) {
+               printk(KERN_ERR "dmi_save_extended_devices: out of memory.\n");
+               return;
+       }
+
+       dev->type = *d-- & 0x7f;
+       dev->name = dmi_string(dm, *d);
+       dev->device_data = NULL;
+
+       list_add(&dev->list, &dmi_devices);
+}
+
 /*
  *     Process a DMI table entry. Right now all we care about are the BIOS
  *     and machine entries. For 2.5 we should pull the smbus controller info
@@ -282,6 +314,9 @@ static void __init dmi_decode(const struct dmi_header *dm)
                break;
        case 38:        /* IPMI Device Information */
                dmi_save_ipmi_device(dm);
+               break;
+       case 41:        /* Onboard Devices Extended Information */
+               dmi_save_extended_devices(dm);
        }
 }
 
@@ -291,9 +326,9 @@ static int __init dmi_present(const char __iomem *p)
 
        memcpy_fromio(buf, p, 15);
        if ((memcmp(buf, "_DMI_", 5) == 0) && dmi_checksum(buf)) {
-               u16 num = (buf[13] << 8) | buf[12];
-               u16 len = (buf[7] << 8) | buf[6];
-               u32 base = (buf[11] << 24) | (buf[10] << 16) |
+               dmi_num = (buf[13] << 8) | buf[12];
+               dmi_len = (buf[7] << 8) | buf[6];
+               dmi_base = (buf[11] << 24) | (buf[10] << 16) |
                        (buf[9] << 8) | buf[8];
 
                /*
@@ -305,7 +340,7 @@ static int __init dmi_present(const char __iomem *p)
                               buf[14] >> 4, buf[14] & 0xF);
                else
                        printk(KERN_INFO "DMI present.\n");
-               if (dmi_table(base,len, num, dmi_decode) == 0)
+               if (dmi_walk_early(dmi_decode) == 0)
                        return 0;
        }
        return 1;
@@ -489,3 +524,27 @@ int dmi_get_year(int field)
 
        return year;
 }
+
+/**
+ *     dmi_walk - Walk the DMI table and get called back for every record
+ *     @decode: Callback function
+ *
+ *     Returns -1 when the DMI table can't be reached, 0 on success.
+ */
+int dmi_walk(void (*decode)(const struct dmi_header *))
+{
+       u8 *buf;
+
+       if (!dmi_available)
+               return -1;
+
+       buf = ioremap(dmi_base, dmi_len);
+       if (buf == NULL)
+               return -1;
+
+       dmi_table(buf, dmi_len, dmi_num, decode);
+
+       iounmap(buf);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(dmi_walk);
index a0445bea9f75ade0411a2949fe0ff43f1ad75b32..410ffe4e9d80ad0f155244d03ebc19eb66feb3f9 100644 (file)
@@ -433,12 +433,12 @@ config SENSORS_LM85
          will be called lm85.
 
 config SENSORS_LM87
-       tristate "National Semiconductor LM87"
+       tristate "National Semiconductor LM87 and compatibles"
        depends on I2C
        select HWMON_VID
        help
          If you say yes here you get support for National Semiconductor LM87
-         sensor chips.
+         and Analog Devices ADM1024 sensor chips.
 
          This driver can also be built as a module.  If so, the module
          will be called lm87.
@@ -588,6 +588,16 @@ config SENSORS_SMSC47B397
          This driver can also be built as a module.  If so, the module
          will be called smsc47b397.
 
+config SENSORS_ADS7828
+       tristate "Texas Instruments ADS7828"
+       depends on I2C
+       help
+         If you say yes here you get support for Texas Instruments ADS7828
+         12-bit 8-channel ADC device.
+
+         This driver can also be built as a module.  If so, the module
+         will be called ads7828.
+
 config SENSORS_THMC50
        tristate "Texas Instruments THMC50 / Analog Devices ADM1022"
        depends on I2C && EXPERIMENTAL
@@ -631,13 +641,13 @@ config SENSORS_VT8231
          will be called vt8231.
 
 config SENSORS_W83781D
-       tristate "Winbond W83781D, W83782D, W83783S, W83627HF, Asus AS99127F"
+       tristate "Winbond W83781D, W83782D, W83783S, Asus AS99127F"
        depends on I2C
        select HWMON_VID
        help
          If you say yes here you get support for the Winbond W8378x series
-         of sensor chips: the W83781D, W83782D, W83783S and W83627HF,
-         and the similar Asus AS99127F.
+         of sensor chips: the W83781D, W83782D and W83783S, and the similar
+         Asus AS99127F.
 
          This driver can also be built as a module.  If so, the module
          will be called w83781d.
@@ -683,6 +693,16 @@ config SENSORS_W83L785TS
          This driver can also be built as a module.  If so, the module
          will be called w83l785ts.
 
+config SENSORS_W83L786NG
+       tristate "Winbond W83L786NG, W83L786NR"
+       depends on I2C && EXPERIMENTAL
+       help
+         If you say yes here you get support for the Winbond W83L786NG
+         and W83L786NR sensor chips.
+
+         This driver can also be built as a module.  If so, the module
+         will be called w83l786ng.
+
 config SENSORS_W83627HF
        tristate "Winbond W83627HF, W83627THF, W83637HF, W83687THF, W83697HF"
        select HWMON_VID
index 55595f6e1aa632a8ecb05eb1306540905ac5a729..824161337f1c8ea128d733bd11b72e9ff42f90f9 100644 (file)
@@ -22,6 +22,7 @@ obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
 obj-$(CONFIG_SENSORS_ADM1029)  += adm1029.o
 obj-$(CONFIG_SENSORS_ADM1031)  += adm1031.o
 obj-$(CONFIG_SENSORS_ADM9240)  += adm9240.o
+obj-$(CONFIG_SENSORS_ADS7828)  += ads7828.o
 obj-$(CONFIG_SENSORS_ADT7470)  += adt7470.o
 obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o
 obj-$(CONFIG_SENSORS_AMS)      += ams/
@@ -68,6 +69,7 @@ obj-$(CONFIG_SENSORS_VT1211)  += vt1211.o
 obj-$(CONFIG_SENSORS_VT8231)   += vt8231.o
 obj-$(CONFIG_SENSORS_W83627EHF)        += w83627ehf.o
 obj-$(CONFIG_SENSORS_W83L785TS)        += w83l785ts.o
+obj-$(CONFIG_SENSORS_W83L786NG)        += w83l786ng.o
 
 ifeq ($(CONFIG_HWMON_DEBUG_CHIP),y)
 EXTRA_CFLAGS += -DDEBUG
index d9f04ce903273e7b214eac1659f0086186550d7e..ed33fddc4dee5689e8fae75e7b339692e9fcf6a1 100644 (file)
@@ -528,6 +528,7 @@ static const struct abituguru3_motherboard_info abituguru3_motherboards[] = {
                { "AUX1 Fan",           33, 2, 60, 1, 0 },
                { "AUX2 Fan",           35, 2, 60, 1, 0 },
                { "AUX3 Fan",           36, 2, 60, 1, 0 },
+               { "AUX4 Fan",           37, 2, 60, 1, 0 },
                { NULL, 0, 0, 0, 0, 0 } }
        },
        { 0x001B, "unknown", {
index ebdc6d7db2318c295a84deca0db123b04091bd11..b96be772e498c82528657ae7ea969fb2c8268da5 100644 (file)
@@ -115,7 +115,6 @@ static struct i2c_driver adm1021_driver = {
        .driver = {
                .name   = "adm1021",
        },
-       .id             = I2C_DRIVERID_ADM1021,
        .attach_adapter = adm1021_attach_adapter,
        .detach_client  = adm1021_detach_client,
 };
index 041ecb0bdf484d08b4accbfe26e8df8050a95f4d..e96c3725203d80c6841e9b3012d41bca14d2adbc 100644 (file)
@@ -51,6 +51,7 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
 #include <linux/hwmon-vid.h>
 #include <linux/err.h>
 #include <linux/mutex.h>
@@ -74,7 +75,7 @@ I2C_CLIENT_INSMOD_2(adm1025, ne1619);
  */
 
 #define ADM1025_REG_MAN_ID             0x3E
-#define ADM1025_REG_CHIP_ID            0x3F
+#define ADM1025_REG_CHIP_ID            0x3F
 #define ADM1025_REG_CONFIG             0x40
 #define ADM1025_REG_STATUS1            0x41
 #define ADM1025_REG_STATUS2            0x42
@@ -92,7 +93,7 @@ I2C_CLIENT_INSMOD_2(adm1025, ne1619);
  * The ADM1025 uses signed 8-bit values for temperatures.
  */
 
-static int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
+static const int in_scale[6] = { 2500, 2250, 3300, 5000, 12000, 3300 };
 
 #define IN_FROM_REG(reg,scale) (((reg) * (scale) + 96) / 192)
 #define IN_TO_REG(val,scale)   ((val) <= 0 ? 0 : \
@@ -122,7 +123,6 @@ static struct i2c_driver adm1025_driver = {
        .driver = {
                .name   = "adm1025",
        },
-       .id             = I2C_DRIVERID_ADM1025,
        .attach_adapter = adm1025_attach_adapter,
        .detach_client  = adm1025_detach_client,
 };
@@ -153,86 +153,96 @@ struct adm1025_data {
  * Sysfs stuff
  */
 
-#define show_in(offset) \
-static ssize_t show_in##offset(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct adm1025_data *data = adm1025_update_device(dev); \
-       return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \
-                      in_scale[offset])); \
-} \
-static ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct adm1025_data *data = adm1025_update_device(dev); \
-       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \
-                      in_scale[offset])); \
-} \
-static ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct adm1025_data *data = adm1025_update_device(dev); \
-       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \
-                      in_scale[offset])); \
-} \
-static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL);
-show_in(0);
-show_in(1);
-show_in(2);
-show_in(3);
-show_in(4);
-show_in(5);
-
-#define show_temp(offset) \
-static ssize_t show_temp##offset(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct adm1025_data *data = adm1025_update_device(dev); \
-       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \
-} \
-static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct adm1025_data *data = adm1025_update_device(dev); \
-       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \
-} \
-static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct adm1025_data *data = adm1025_update_device(dev); \
-       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \
-}\
-static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp##offset, NULL);
-show_temp(1);
-show_temp(2);
+static ssize_t
+show_in(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct adm1025_data *data = adm1025_update_device(dev);
+       return sprintf(buf, "%u\n", IN_FROM_REG(data->in[index],
+                      in_scale[index]));
+}
+
+static ssize_t
+show_in_min(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct adm1025_data *data = adm1025_update_device(dev);
+       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[index],
+                      in_scale[index]));
+}
+
+static ssize_t
+show_in_max(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct adm1025_data *data = adm1025_update_device(dev);
+       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[index],
+                      in_scale[index]));
+}
+
+static ssize_t
+show_temp(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct adm1025_data *data = adm1025_update_device(dev);
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[index]));
+}
+
+static ssize_t
+show_temp_min(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct adm1025_data *data = adm1025_update_device(dev);
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[index]));
+}
+
+static ssize_t
+show_temp_max(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct adm1025_data *data = adm1025_update_device(dev);
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[index]));
+}
+
+static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
+                         const char *buf, size_t count)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adm1025_data *data = i2c_get_clientdata(client);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->in_min[index] = IN_TO_REG(val, in_scale[index]);
+       i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(index),
+                                 data->in_min[index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
+static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
+                         const char *buf, size_t count)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adm1025_data *data = i2c_get_clientdata(client);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->in_max[index] = IN_TO_REG(val, in_scale[index]);
+       i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(index),
+                                 data->in_max[index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
 
 #define set_in(offset) \
-static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct adm1025_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       mutex_lock(&data->update_lock); \
-       data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \
-       i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \
-                                 data->in_min[offset]); \
-       mutex_unlock(&data->update_lock); \
-       return count; \
-} \
-static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct adm1025_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       mutex_lock(&data->update_lock); \
-       data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \
-       i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \
-                                 data->in_max[offset]); \
-       mutex_unlock(&data->update_lock); \
-       return count; \
-} \
-static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
-       show_in##offset##_min, set_in##offset##_min); \
-static DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
-       show_in##offset##_max, set_in##offset##_max);
+static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
+       show_in, NULL, offset); \
+static SENSOR_DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
+       show_in_min, set_in_min, offset); \
+static SENSOR_DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
+       show_in_max, set_in_max, offset)
 set_in(0);
 set_in(1);
 set_in(2);
@@ -240,65 +250,91 @@ set_in(3);
 set_in(4);
 set_in(5);
 
+static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
+                           const char *buf, size_t count)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adm1025_data *data = i2c_get_clientdata(client);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->temp_min[index] = TEMP_TO_REG(val);
+       i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(index),
+                                 data->temp_min[index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
+static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
+       const char *buf, size_t count)
+{
+       int index = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct adm1025_data *data = i2c_get_clientdata(client);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->temp_max[index] = TEMP_TO_REG(val);
+       i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(index),
+                                 data->temp_max[index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
 #define set_temp(offset) \
-static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct adm1025_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       mutex_lock(&data->update_lock); \
-       data->temp_min[offset-1] = TEMP_TO_REG(val); \
-       i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \
-                                 data->temp_min[offset-1]); \
-       mutex_unlock(&data->update_lock); \
-       return count; \
-} \
-static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct adm1025_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       mutex_lock(&data->update_lock); \
-       data->temp_max[offset-1] = TEMP_TO_REG(val); \
-       i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \
-                                 data->temp_max[offset-1]); \
-       mutex_unlock(&data->update_lock); \
-       return count; \
-} \
-static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
-       show_temp##offset##_min, set_temp##offset##_min); \
-static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
-       show_temp##offset##_max, set_temp##offset##_max);
+static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
+       show_temp, NULL, offset - 1); \
+static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
+       show_temp_min, set_temp_min, offset - 1); \
+static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
+       show_temp_max, set_temp_max, offset - 1)
 set_temp(1);
 set_temp(2);
 
-static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t
+show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1025_data *data = adm1025_update_device(dev);
        return sprintf(buf, "%u\n", data->alarms);
 }
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
 
-static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t
+show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       struct adm1025_data *data = adm1025_update_device(dev);
+       return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
+}
+static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
+static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
+static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 5);
+static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 4);
+static SENSOR_DEVICE_ATTR(temp1_fault, S_IRUGO, show_alarm, NULL, 14);
+
+static ssize_t
+show_vid(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1025_data *data = adm1025_update_device(dev);
        return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
 }
 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
 
-static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t
+show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1025_data *data = dev_get_drvdata(dev);
        return sprintf(buf, "%u\n", data->vrm);
 }
-static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
+                      const char *buf, size_t count)
 {
-       struct i2c_client *client = to_i2c_client(dev);
-       struct adm1025_data *data = i2c_get_clientdata(client);
+       struct adm1025_data *data = dev_get_drvdata(dev);
        data->vrm = simple_strtoul(buf, NULL, 10);
        return count;
 }
@@ -316,27 +352,35 @@ static int adm1025_attach_adapter(struct i2c_adapter *adapter)
 }
 
 static struct attribute *adm1025_attributes[] = {
-       &dev_attr_in0_input.attr,
-       &dev_attr_in1_input.attr,
-       &dev_attr_in2_input.attr,
-       &dev_attr_in3_input.attr,
-       &dev_attr_in5_input.attr,
-       &dev_attr_in0_min.attr,
-       &dev_attr_in1_min.attr,
-       &dev_attr_in2_min.attr,
-       &dev_attr_in3_min.attr,
-       &dev_attr_in5_min.attr,
-       &dev_attr_in0_max.attr,
-       &dev_attr_in1_max.attr,
-       &dev_attr_in2_max.attr,
-       &dev_attr_in3_max.attr,
-       &dev_attr_in5_max.attr,
-       &dev_attr_temp1_input.attr,
-       &dev_attr_temp2_input.attr,
-       &dev_attr_temp1_min.attr,
-       &dev_attr_temp2_min.attr,
-       &dev_attr_temp1_max.attr,
-       &dev_attr_temp2_max.attr,
+       &sensor_dev_attr_in0_input.dev_attr.attr,
+       &sensor_dev_attr_in1_input.dev_attr.attr,
+       &sensor_dev_attr_in2_input.dev_attr.attr,
+       &sensor_dev_attr_in3_input.dev_attr.attr,
+       &sensor_dev_attr_in5_input.dev_attr.attr,
+       &sensor_dev_attr_in0_min.dev_attr.attr,
+       &sensor_dev_attr_in1_min.dev_attr.attr,
+       &sensor_dev_attr_in2_min.dev_attr.attr,
+       &sensor_dev_attr_in3_min.dev_attr.attr,
+       &sensor_dev_attr_in5_min.dev_attr.attr,
+       &sensor_dev_attr_in0_max.dev_attr.attr,
+       &sensor_dev_attr_in1_max.dev_attr.attr,
+       &sensor_dev_attr_in2_max.dev_attr.attr,
+       &sensor_dev_attr_in3_max.dev_attr.attr,
+       &sensor_dev_attr_in5_max.dev_attr.attr,
+       &sensor_dev_attr_in0_alarm.dev_attr.attr,
+       &sensor_dev_attr_in1_alarm.dev_attr.attr,
+       &sensor_dev_attr_in2_alarm.dev_attr.attr,
+       &sensor_dev_attr_in3_alarm.dev_attr.attr,
+       &sensor_dev_attr_in5_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_input.dev_attr.attr,
+       &sensor_dev_attr_temp2_input.dev_attr.attr,
+       &sensor_dev_attr_temp1_min.dev_attr.attr,
+       &sensor_dev_attr_temp2_min.dev_attr.attr,
+       &sensor_dev_attr_temp1_max.dev_attr.attr,
+       &sensor_dev_attr_temp2_max.dev_attr.attr,
+       &sensor_dev_attr_temp1_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp2_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_fault.dev_attr.attr,
        &dev_attr_alarms.attr,
        &dev_attr_cpu0_vid.attr,
        &dev_attr_vrm.attr,
@@ -347,15 +391,16 @@ static const struct attribute_group adm1025_group = {
        .attrs = adm1025_attributes,
 };
 
-static struct attribute *adm1025_attributes_opt[] = {
-       &dev_attr_in4_input.attr,
-       &dev_attr_in4_min.attr,
-       &dev_attr_in4_max.attr,
+static struct attribute *adm1025_attributes_in4[] = {
+       &sensor_dev_attr_in4_input.dev_attr.attr,
+       &sensor_dev_attr_in4_min.dev_attr.attr,
+       &sensor_dev_attr_in4_max.dev_attr.attr,
+       &sensor_dev_attr_in4_alarm.dev_attr.attr,
        NULL
 };
 
-static const struct attribute_group adm1025_group_opt = {
-       .attrs = adm1025_attributes_opt,
+static const struct attribute_group adm1025_group_in4 = {
+       .attrs = adm1025_attributes_in4,
 };
 
 /*
@@ -364,7 +409,7 @@ static const struct attribute_group adm1025_group_opt = {
  */
 static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
 {
-       struct i2c_client *new_client;
+       struct i2c_client *client;
        struct adm1025_data *data;
        int err = 0;
        const char *name = "";
@@ -378,14 +423,11 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
                goto exit;
        }
 
-       /* The common I2C client data is placed right before the
-          ADM1025-specific data. */
-       new_client = &data->client;
-       i2c_set_clientdata(new_client, data);
-       new_client->addr = address;
-       new_client->adapter = adapter;
-       new_client->driver = &adm1025_driver;
-       new_client->flags = 0;
+       client = &data->client;
+       i2c_set_clientdata(client, data);
+       client->addr = address;
+       client->adapter = adapter;
+       client->driver = &adm1025_driver;
 
        /*
         * Now we do the remaining detection. A negative kind means that
@@ -397,12 +439,12 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
         * requested, so both the detection and the identification steps
         * are skipped.
         */
-       config = i2c_smbus_read_byte_data(new_client, ADM1025_REG_CONFIG);
+       config = i2c_smbus_read_byte_data(client, ADM1025_REG_CONFIG);
        if (kind < 0) { /* detection */
                if ((config & 0x80) != 0x00
-                || (i2c_smbus_read_byte_data(new_client,
+                || (i2c_smbus_read_byte_data(client,
                     ADM1025_REG_STATUS1) & 0xC0) != 0x00
-                || (i2c_smbus_read_byte_data(new_client,
+                || (i2c_smbus_read_byte_data(client,
                     ADM1025_REG_STATUS2) & 0xBC) != 0x00) {
                        dev_dbg(&adapter->dev,
                                "ADM1025 detection failed at 0x%02x.\n",
@@ -414,11 +456,9 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
        if (kind <= 0) { /* identification */
                u8 man_id, chip_id;
 
-               man_id = i2c_smbus_read_byte_data(new_client,
-                        ADM1025_REG_MAN_ID);
-               chip_id = i2c_smbus_read_byte_data(new_client,
-                         ADM1025_REG_CHIP_ID);
-               
+               man_id = i2c_smbus_read_byte_data(client, ADM1025_REG_MAN_ID);
+               chip_id = i2c_smbus_read_byte_data(client, ADM1025_REG_CHIP_ID);
+
                if (man_id == 0x41) { /* Analog Devices */
                        if ((chip_id & 0xF0) == 0x20) { /* ADM1025/ADM1025A */
                                kind = adm1025;
@@ -446,33 +486,28 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
        }
 
        /* We can fill in the remaining client fields */
-       strlcpy(new_client->name, name, I2C_NAME_SIZE);
-       data->valid = 0;
+       strlcpy(client->name, name, I2C_NAME_SIZE);
        mutex_init(&data->update_lock);
 
        /* Tell the I2C layer a new client has arrived */
-       if ((err = i2c_attach_client(new_client)))
+       if ((err = i2c_attach_client(client)))
                goto exit_free;
 
        /* Initialize the ADM1025 chip */
-       adm1025_init_client(new_client);
+       adm1025_init_client(client);
 
        /* Register sysfs hooks */
-       if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1025_group)))
+       if ((err = sysfs_create_group(&client->dev.kobj, &adm1025_group)))
                goto exit_detach;
 
        /* Pin 11 is either in4 (+12V) or VID4 */
        if (!(config & 0x20)) {
-               if ((err = device_create_file(&new_client->dev,
-                                       &dev_attr_in4_input))
-                || (err = device_create_file(&new_client->dev,
-                                       &dev_attr_in4_min))
-                || (err = device_create_file(&new_client->dev,
-                                       &dev_attr_in4_max)))
+               if ((err = sysfs_create_group(&client->dev.kobj,
+                                             &adm1025_group_in4)))
                        goto exit_remove;
        }
 
-       data->hwmon_dev = hwmon_device_register(&new_client->dev);
+       data->hwmon_dev = hwmon_device_register(&client->dev);
        if (IS_ERR(data->hwmon_dev)) {
                err = PTR_ERR(data->hwmon_dev);
                goto exit_remove;
@@ -481,10 +516,10 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
        return 0;
 
 exit_remove:
-       sysfs_remove_group(&new_client->dev.kobj, &adm1025_group);
-       sysfs_remove_group(&new_client->dev.kobj, &adm1025_group_opt);
+       sysfs_remove_group(&client->dev.kobj, &adm1025_group);
+       sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
 exit_detach:
-       i2c_detach_client(new_client);
+       i2c_detach_client(client);
 exit_free:
        kfree(data);
 exit:
@@ -540,7 +575,7 @@ static int adm1025_detach_client(struct i2c_client *client)
 
        hwmon_device_unregister(data->hwmon_dev);
        sysfs_remove_group(&client->dev.kobj, &adm1025_group);
-       sysfs_remove_group(&client->dev.kobj, &adm1025_group_opt);
+       sysfs_remove_group(&client->dev.kobj, &adm1025_group_in4);
 
        if ((err = i2c_detach_client(client)))
                return err;
index 3e63c148677095dc38ce5e67dab90355a40fda8d..8002f68240c4e47c1dc2d7492fbbfb38d6f7752c 100644 (file)
@@ -40,8 +40,8 @@ static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
 /* Insmod parameters */
 I2C_CLIENT_INSMOD_1(adm1026);
 
-static int gpio_input[17]  = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
-                               -1, -1, -1, -1, -1, -1, -1, -1 }; 
+static int gpio_input[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
+                               -1, -1, -1, -1, -1, -1, -1, -1 };
 static int gpio_output[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
                                -1, -1, -1, -1, -1, -1, -1, -1 };
 static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -49,46 +49,49 @@ static int gpio_inverted[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
 static int gpio_normal[17] = { -1, -1, -1, -1, -1, -1, -1, -1, -1,
                                -1, -1, -1, -1, -1, -1, -1, -1 };
 static int gpio_fan[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
-module_param_array(gpio_input,int,NULL,0);
-MODULE_PARM_DESC(gpio_input,"List of GPIO pins (0-16) to program as inputs");
-module_param_array(gpio_output,int,NULL,0);
-MODULE_PARM_DESC(gpio_output,"List of GPIO pins (0-16) to program as "
+module_param_array(gpio_input, int, NULL, 0);
+MODULE_PARM_DESC(gpio_input, "List of GPIO pins (0-16) to program as inputs");
+module_param_array(gpio_output, int, NULL, 0);
+MODULE_PARM_DESC(gpio_output, "List of GPIO pins (0-16) to program as "
        "outputs");
-module_param_array(gpio_inverted,int,NULL,0);
-MODULE_PARM_DESC(gpio_inverted,"List of GPIO pins (0-16) to program as "
+module_param_array(gpio_inverted, int, NULL, 0);
+MODULE_PARM_DESC(gpio_inverted, "List of GPIO pins (0-16) to program as "
        "inverted");
-module_param_array(gpio_normal,int,NULL,0);
-MODULE_PARM_DESC(gpio_normal,"List of GPIO pins (0-16) to program as "
+module_param_array(gpio_normal, int, NULL, 0);
+MODULE_PARM_DESC(gpio_normal, "List of GPIO pins (0-16) to program as "
        "normal/non-inverted");
-module_param_array(gpio_fan,int,NULL,0);
-MODULE_PARM_DESC(gpio_fan,"List of GPIO pins (0-7) to program as fan tachs");
+module_param_array(gpio_fan, int, NULL, 0);
+MODULE_PARM_DESC(gpio_fan, "List of GPIO pins (0-7) to program as fan tachs");
 
 /* Many ADM1026 constants specified below */
 
 /* The ADM1026 registers */
-#define ADM1026_REG_CONFIG1  0x00
-#define CFG1_MONITOR     0x01
-#define CFG1_INT_ENABLE  0x02
-#define CFG1_INT_CLEAR   0x04
-#define CFG1_AIN8_9      0x08
-#define CFG1_THERM_HOT   0x10
-#define CFG1_DAC_AFC     0x20
-#define CFG1_PWM_AFC     0x40
-#define CFG1_RESET       0x80
-#define ADM1026_REG_CONFIG2  0x01
+#define ADM1026_REG_CONFIG1    0x00
+#define CFG1_MONITOR           0x01
+#define CFG1_INT_ENABLE                0x02
+#define CFG1_INT_CLEAR         0x04
+#define CFG1_AIN8_9            0x08
+#define CFG1_THERM_HOT         0x10
+#define CFG1_DAC_AFC           0x20
+#define CFG1_PWM_AFC           0x40
+#define CFG1_RESET             0x80
+
+#define ADM1026_REG_CONFIG2    0x01
 /* CONFIG2 controls FAN0/GPIO0 through FAN7/GPIO7 */
-#define ADM1026_REG_CONFIG3  0x07
-#define CFG3_GPIO16_ENABLE  0x01
-#define CFG3_CI_CLEAR  0x02
-#define CFG3_VREF_250  0x04
-#define CFG3_GPIO16_DIR  0x40
-#define CFG3_GPIO16_POL  0x80
-#define ADM1026_REG_E2CONFIG  0x13
-#define E2CFG_READ  0x01
-#define E2CFG_WRITE  0x02
-#define E2CFG_ERASE  0x04
-#define E2CFG_ROM  0x08
-#define E2CFG_CLK_EXT  0x80
+
+#define ADM1026_REG_CONFIG3    0x07
+#define CFG3_GPIO16_ENABLE     0x01
+#define CFG3_CI_CLEAR          0x02
+#define CFG3_VREF_250          0x04
+#define CFG3_GPIO16_DIR                0x40
+#define CFG3_GPIO16_POL                0x80
+
+#define ADM1026_REG_E2CONFIG   0x13
+#define E2CFG_READ             0x01
+#define E2CFG_WRITE            0x02
+#define E2CFG_ERASE            0x04
+#define E2CFG_ROM              0x08
+#define E2CFG_CLK_EXT          0x80
 
 /* There are 10 general analog inputs and 7 dedicated inputs
  * They are:
@@ -129,48 +132,48 @@ static u16 ADM1026_REG_TEMP_TMIN[] = { 0x10, 0x11, 0x12 };
 static u16 ADM1026_REG_TEMP_THERM[] = { 0x0d, 0x0e, 0x0f };
 static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
 
-#define ADM1026_REG_FAN(nr) (0x38 + (nr))
-#define ADM1026_REG_FAN_MIN(nr) (0x60 + (nr))
-#define ADM1026_REG_FAN_DIV_0_3 0x02
-#define ADM1026_REG_FAN_DIV_4_7 0x03
+#define ADM1026_REG_FAN(nr)            (0x38 + (nr))
+#define ADM1026_REG_FAN_MIN(nr)                (0x60 + (nr))
+#define ADM1026_REG_FAN_DIV_0_3                0x02
+#define ADM1026_REG_FAN_DIV_4_7                0x03
 
-#define ADM1026_REG_DAC  0x04
-#define ADM1026_REG_PWM  0x05
+#define ADM1026_REG_DAC                        0x04
+#define ADM1026_REG_PWM                        0x05
 
-#define ADM1026_REG_GPIO_CFG_0_3 0x08
-#define ADM1026_REG_GPIO_CFG_4_7 0x09
-#define ADM1026_REG_GPIO_CFG_8_11 0x0a
-#define ADM1026_REG_GPIO_CFG_12_15 0x0b
+#define ADM1026_REG_GPIO_CFG_0_3       0x08
+#define ADM1026_REG_GPIO_CFG_4_7       0x09
+#define ADM1026_REG_GPIO_CFG_8_11      0x0a
+#define ADM1026_REG_GPIO_CFG_12_15     0x0b
 /* CFG_16 in REG_CFG3 */
-#define ADM1026_REG_GPIO_STATUS_0_7 0x24
-#define ADM1026_REG_GPIO_STATUS_8_15 0x25
+#define ADM1026_REG_GPIO_STATUS_0_7    0x24
+#define ADM1026_REG_GPIO_STATUS_8_15   0x25
 /* STATUS_16 in REG_STATUS4 */
-#define ADM1026_REG_GPIO_MASK_0_7 0x1c
-#define ADM1026_REG_GPIO_MASK_8_15 0x1d
+#define ADM1026_REG_GPIO_MASK_0_7      0x1c
+#define ADM1026_REG_GPIO_MASK_8_15     0x1d
 /* MASK_16 in REG_MASK4 */
 
-#define ADM1026_REG_COMPANY 0x16
-#define ADM1026_REG_VERSTEP 0x17
+#define ADM1026_REG_COMPANY            0x16
+#define ADM1026_REG_VERSTEP            0x17
 /* These are the recognized values for the above regs */
-#define ADM1026_COMPANY_ANALOG_DEV 0x41
-#define ADM1026_VERSTEP_GENERIC 0x40
-#define ADM1026_VERSTEP_ADM1026 0x44
+#define ADM1026_COMPANY_ANALOG_DEV     0x41
+#define ADM1026_VERSTEP_GENERIC                0x40
+#define ADM1026_VERSTEP_ADM1026                0x44
 
-#define ADM1026_REG_MASK1 0x18
-#define ADM1026_REG_MASK2 0x19
-#define ADM1026_REG_MASK3 0x1a
-#define ADM1026_REG_MASK4 0x1b
+#define ADM1026_REG_MASK1              0x18
+#define ADM1026_REG_MASK2              0x19
+#define ADM1026_REG_MASK3              0x1a
+#define ADM1026_REG_MASK4              0x1b
 
-#define ADM1026_REG_STATUS1 0x20
-#define ADM1026_REG_STATUS2 0x21
-#define ADM1026_REG_STATUS3 0x22
-#define ADM1026_REG_STATUS4 0x23
+#define ADM1026_REG_STATUS1            0x20
+#define ADM1026_REG_STATUS2            0x21
+#define ADM1026_REG_STATUS3            0x22
+#define ADM1026_REG_STATUS4            0x23
 
 #define ADM1026_FAN_ACTIVATION_TEMP_HYST -6
-#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
-#define ADM1026_PWM_MAX 255
+#define ADM1026_FAN_CONTROL_TEMP_RANGE 20
+#define ADM1026_PWM_MAX                        255
 
-/* Conversions. Rounding and limit checking is only done on the TO_REG 
+/* Conversions. Rounding and limit checking is only done on the TO_REG
  * variants. Note that you should be a bit careful with which arguments
  * these macros are called: arguments may be evaluated more than once.
  */
@@ -186,52 +189,49 @@ static u16 ADM1026_REG_TEMP_OFFSET[] = { 0x1e, 0x6e, 0x6f };
  * The values in this table are based on Table II, page 15 of the
  *    datasheet.
  */
-static int adm1026_scaling[] = {  /* .001 Volts */
-               2250, 2250, 2250, 2250, 2250, 2250, 
-               1875, 1875, 1875, 1875, 3000, 3330, 
+static int adm1026_scaling[] = { /* .001 Volts */
+               2250, 2250, 2250, 2250, 2250, 2250,
+               1875, 1875, 1875, 1875, 3000, 3330,
                3330, 4995, 2250, 12000, 13875
        };
 #define NEG12_OFFSET  16000
-#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
-#define INS_TO_REG(n,val)  (SENSORS_LIMIT(SCALE(val,adm1026_scaling[n],192),\
-       0,255))
-#define INS_FROM_REG(n,val) (SCALE(val,192,adm1026_scaling[n]))
+#define SCALE(val, from, to) (((val)*(to) + ((from)/2))/(from))
+#define INS_TO_REG(n, val)  (SENSORS_LIMIT(SCALE(val, adm1026_scaling[n], 192),\
+       0, 255))
+#define INS_FROM_REG(n, val) (SCALE(val, 192, adm1026_scaling[n]))
 
 /* FAN speed is measured using 22.5kHz clock and counts for 2 pulses
  *   and we assume a 2 pulse-per-rev fan tach signal
  *      22500 kHz * 60 (sec/min) * 2 (pulse) / 2 (pulse/rev) == 1350000
  */
-#define FAN_TO_REG(val,div)  ((val)<=0 ? 0xff : SENSORS_LIMIT(1350000/((val)*\
-       (div)),1,254)) 
-#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==0xff ? 0 : 1350000/((val)*\
-       (div)))
+#define FAN_TO_REG(val, div)  ((val) <= 0 ? 0xff : \
+                               SENSORS_LIMIT(1350000/((val)*(div)), 1, 254))
+#define FAN_FROM_REG(val, div) ((val) == 0 ? -1:(val) == 0xff ? 0 : \
+                               1350000/((val)*(div)))
 #define DIV_FROM_REG(val) (1<<(val))
-#define DIV_TO_REG(val) ((val)>=8 ? 3 : (val)>=4 ? 2 : (val)>=2 ? 1 : 0)
+#define DIV_TO_REG(val) ((val) >= 8 ? 3 : (val) >= 4 ? 2 : (val) >= 2 ? 1 : 0)
 
 /* Temperature is reported in 1 degC increments */
 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-       -127,127))
+       -127, 127))
 #define TEMP_FROM_REG(val) ((val) * 1000)
 #define OFFSET_TO_REG(val) (SENSORS_LIMIT(((val)+((val)<0 ? -500 : 500))/1000,\
-       -127,127))
+       -127, 127))
 #define OFFSET_FROM_REG(val) ((val) * 1000)
 
-#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
+#define PWM_TO_REG(val) (SENSORS_LIMIT(val, 0, 255))
 #define PWM_FROM_REG(val) (val)
 
 #define PWM_MIN_TO_REG(val) ((val) & 0xf0)
 #define PWM_MIN_FROM_REG(val) (((val) & 0xf0) + ((val) >> 4))
 
-/* Analog output is a voltage, and scaled to millivolts.  The datasheet 
- *   indicates that the DAC could be used to drive the fans, but in our 
+/* Analog output is a voltage, and scaled to millivolts.  The datasheet
+ *   indicates that the DAC could be used to drive the fans, but in our
  *   example board (Arima HDAMA) it isn't connected to the fans at all.
  */
-#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500),0,255)) 
+#define DAC_TO_REG(val) (SENSORS_LIMIT(((((val)*255)+500)/2500), 0, 255))
 #define DAC_FROM_REG(val) (((val)*2500)/255)
 
-/* Typically used with systems using a v9.1 VRM spec ? */
-#define ADM1026_INIT_VRM  91
-
 /* Chip sampling rates
  *
  * Some sensors are not updated more frequently than once per second
@@ -243,8 +243,8 @@ static int adm1026_scaling[] = {  /* .001 Volts */
  *    So, we keep the config data up to date in the cache
  *    when it is written and only sample it once every 5 *minutes*
  */
-#define ADM1026_DATA_INTERVAL  (1 * HZ)
-#define ADM1026_CONFIG_INTERVAL  (5 * 60 * HZ)
+#define ADM1026_DATA_INTERVAL          (1 * HZ)
+#define ADM1026_CONFIG_INTERVAL                (5 * 60 * HZ)
 
 /* We allow for multiple chips in a single system.
  *
@@ -261,37 +261,36 @@ struct pwm_data {
 struct adm1026_data {
        struct i2c_client client;
        struct device *hwmon_dev;
-       enum chips type;
 
        struct mutex update_lock;
        int valid;              /* !=0 if following fields are valid */
        unsigned long last_reading;     /* In jiffies */
        unsigned long last_config;      /* In jiffies */
 
-       u8 in[17];              /* Register value */
-       u8 in_max[17];          /* Register value */
-       u8 in_min[17];          /* Register value */
-       s8 temp[3];             /* Register value */
-       s8 temp_min[3];         /* Register value */
-       s8 temp_max[3];         /* Register value */
-       s8 temp_tmin[3];        /* Register value */
-       s8 temp_crit[3];        /* Register value */
-       s8 temp_offset[3];      /* Register value */
-       u8 fan[8];              /* Register value */
-       u8 fan_min[8];          /* Register value */
-       u8 fan_div[8];          /* Decoded value */
-       struct pwm_data pwm1;   /* Pwm control values */
-       int vid;                /* Decoded value */
-       u8 vrm;                 /* VRM version */
+       u8 in[17];              /* Register value */
+       u8 in_max[17];          /* Register value */
+       u8 in_min[17];          /* Register value */
+       s8 temp[3];             /* Register value */
+       s8 temp_min[3];         /* Register value */
+       s8 temp_max[3];         /* Register value */
+       s8 temp_tmin[3];        /* Register value */
+       s8 temp_crit[3];        /* Register value */
+       s8 temp_offset[3];      /* Register value */
+       u8 fan[8];              /* Register value */
+       u8 fan_min[8];          /* Register value */
+       u8 fan_div[8];          /* Decoded value */
+       struct pwm_data pwm1;   /* Pwm control values */
+       int vid;                /* Decoded value */
+       u8 vrm;                 /* VRM version */
        u8 analog_out;          /* Register value (DAC) */
-       long alarms;            /* Register encoding, combined */
-       long alarm_mask;        /* Register encoding, combined */
-       long gpio;              /* Register encoding, combined */
-       long gpio_mask;         /* Register encoding, combined */
-       u8 gpio_config[17];     /* Decoded value */
-       u8 config1;             /* Register value */
-       u8 config2;             /* Register value */
-       u8 config3;             /* Register value */
+       long alarms;            /* Register encoding, combined */
+       long alarm_mask;        /* Register encoding, combined */
+       long gpio;              /* Register encoding, combined */
+       long gpio_mask;         /* Register encoding, combined */
+       u8 gpio_config[17];     /* Decoded value */
+       u8 config1;             /* Register value */
+       u8 config2;             /* Register value */
+       u8 config3;             /* Register value */
 };
 
 static int adm1026_attach_adapter(struct i2c_adapter *adapter);
@@ -301,7 +300,7 @@ static int adm1026_detach_client(struct i2c_client *client);
 static int adm1026_read_value(struct i2c_client *client, u8 reg);
 static int adm1026_write_value(struct i2c_client *client, u8 reg, int value);
 static void adm1026_print_gpio(struct i2c_client *client);
-static void adm1026_fixup_gpio(struct i2c_client *client); 
+static void adm1026_fixup_gpio(struct i2c_client *client);
 static struct adm1026_data *adm1026_update_device(struct device *dev);
 static void adm1026_init_client(struct i2c_client *client);
 
@@ -311,7 +310,7 @@ static struct i2c_driver adm1026_driver = {
                .name   = "adm1026",
        },
        .attach_adapter = adm1026_attach_adapter,
-       .detach_client  = adm1026_detach_client,
+       .detach_client  = adm1026_detach_client,
 };
 
 static int adm1026_attach_adapter(struct i2c_adapter *adapter)
@@ -355,7 +354,7 @@ static void adm1026_init_client(struct i2c_client *client)
        int value, i;
        struct adm1026_data *data = i2c_get_clientdata(client);
 
-        dev_dbg(&client->dev, "Initializing device\n");
+       dev_dbg(&client->dev, "Initializing device\n");
        /* Read chip config */
        data->config1 = adm1026_read_value(client, ADM1026_REG_CONFIG1);
        data->config2 = adm1026_read_value(client, ADM1026_REG_CONFIG2);
@@ -384,7 +383,6 @@ static void adm1026_init_client(struct i2c_client *client)
                        "and temp limits enabled.\n");
        }
 
-       value = data->config3;
        if (data->config3 & CFG3_GPIO16_ENABLE) {
                dev_dbg(&client->dev, "GPIO16 enabled.  THERM "
                        "pin disabled.\n");
@@ -426,10 +424,10 @@ static void adm1026_init_client(struct i2c_client *client)
         *   configured, we don't want to mess with them.
         *   If they weren't, the default is 100% PWM, no
         *   control and will suffice until 'sensors -s'
-        *   can be run by the user.  We DO set the default 
+        *   can be run by the user.  We DO set the default
         *   value for pwm1.auto_pwm_min to its maximum
         *   so that enabling automatic pwm fan control
-        *   without first setting a value for pwm1.auto_pwm_min 
+        *   without first setting a value for pwm1.auto_pwm_min
         *   will not result in potentially dangerous fan speed decrease.
         */
        data->pwm1.auto_pwm_min=255;
@@ -453,7 +451,7 @@ static void adm1026_init_client(struct i2c_client *client)
 static void adm1026_print_gpio(struct i2c_client *client)
 {
        struct adm1026_data *data = i2c_get_clientdata(client);
-       int  i;
+       int i;
 
        dev_dbg(&client->dev, "GPIO config is:");
        for (i = 0;i <= 7;++i) {
@@ -477,7 +475,7 @@ static void adm1026_print_gpio(struct i2c_client *client)
                        data->gpio_config[16] & 0x02 ? "" : "!",
                        data->gpio_config[16] & 0x01 ? "OUT" : "IN");
        } else {
-               /* GPIO16 is THERM  */
+               /* GPIO16 is THERM */
                dev_dbg(&client->dev, "\tTHERM\n");
        }
 }
@@ -485,8 +483,8 @@ static void adm1026_print_gpio(struct i2c_client *client)
 static void adm1026_fixup_gpio(struct i2c_client *client)
 {
        struct adm1026_data *data = i2c_get_clientdata(client);
-       int  i;
-       int  value;
+       int i;
+       int value;
 
        /* Make the changes requested. */
        /* We may need to unlock/stop monitoring or soft-reset the
@@ -516,14 +514,14 @@ static void adm1026_fixup_gpio(struct i2c_client *client)
                }
        }
 
-       /* Inverted  */
+       /* Inverted */
        for (i = 0;i <= 16;++i) {
                if (gpio_inverted[i] >= 0 && gpio_inverted[i] <= 16) {
                        data->gpio_config[gpio_inverted[i]] &= ~ 0x02;
                }
        }
 
-       /* Normal overrides inverted  */
+       /* Normal overrides inverted */
        for (i = 0;i <= 16;++i) {
                if (gpio_normal[i] >= 0 && gpio_normal[i] <= 16) {
                        data->gpio_config[gpio_normal[i]] |= 0x02;
@@ -569,7 +567,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
        if (!data->valid
            || time_after(jiffies, data->last_reading + ADM1026_DATA_INTERVAL)) {
                /* Things that change quickly */
-               dev_dbg(&client->dev,"Reading sensor values\n");
+               dev_dbg(&client->dev, "Reading sensor values\n");
                for (i = 0;i <= 16;++i) {
                        data->in[i] =
                            adm1026_read_value(client, ADM1026_REG_IN[i]);
@@ -582,18 +580,18 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
 
                for (i = 0;i <= 2;++i) {
                        /* NOTE: temp[] is s8 and we assume 2's complement
-                        *   "conversion" in the assignment   */
+                        *   "conversion" in the assignment */
                        data->temp[i] =
                            adm1026_read_value(client, ADM1026_REG_TEMP[i]);
                }
 
-               data->pwm1.pwm = adm1026_read_value(client, 
+               data->pwm1.pwm = adm1026_read_value(client,
                        ADM1026_REG_PWM);
-               data->analog_out = adm1026_read_value(client, 
+               data->analog_out = adm1026_read_value(client,
                        ADM1026_REG_DAC);
                /* GPIO16 is MSbit of alarms, move it to gpio */
                alarms = adm1026_read_value(client, ADM1026_REG_STATUS4);
-               gpio = alarms & 0x80 ? 0x0100 : 0;  /* GPIO16 */
+               gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
                alarms &= 0x7f;
                alarms <<= 8;
                alarms |= adm1026_read_value(client, ADM1026_REG_STATUS3);
@@ -604,24 +602,24 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
                data->alarms = alarms;
 
                /* Read the GPIO values */
-               gpio |= adm1026_read_value(client, 
+               gpio |= adm1026_read_value(client,
                        ADM1026_REG_GPIO_STATUS_8_15);
                gpio <<= 8;
-               gpio |= adm1026_read_value(client, 
+               gpio |= adm1026_read_value(client,
                        ADM1026_REG_GPIO_STATUS_0_7);
                data->gpio = gpio;
 
                data->last_reading = jiffies;
-       };  /* last_reading */
+       }; /* last_reading */
 
        if (!data->valid ||
            time_after(jiffies, data->last_config + ADM1026_CONFIG_INTERVAL)) {
                /* Things that don't change often */
                dev_dbg(&client->dev, "Reading config values\n");
                for (i = 0;i <= 16;++i) {
-                       data->in_min[i] = adm1026_read_value(client, 
+                       data->in_min[i] = adm1026_read_value(client,
                                ADM1026_REG_IN_MIN[i]);
-                       data->in_max[i] = adm1026_read_value(client, 
+                       data->in_max[i] = adm1026_read_value(client,
                                ADM1026_REG_IN_MAX[i]);
                }
 
@@ -629,32 +627,32 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
                        | (adm1026_read_value(client, ADM1026_REG_FAN_DIV_4_7)
                        << 8);
                for (i = 0;i <= 7;++i) {
-                       data->fan_min[i] = adm1026_read_value(client, 
+                       data->fan_min[i] = adm1026_read_value(client,
                                ADM1026_REG_FAN_MIN(i));
                        data->fan_div[i] = DIV_FROM_REG(value & 0x03);
                        value >>= 2;
                }
 
                for (i = 0; i <= 2; ++i) {
-                       /* NOTE: temp_xxx[] are s8 and we assume 2's 
+                       /* NOTE: temp_xxx[] are s8 and we assume 2's
                         *    complement "conversion" in the assignment
                         */
-                       data->temp_min[i] = adm1026_read_value(client, 
+                       data->temp_min[i] = adm1026_read_value(client,
                                ADM1026_REG_TEMP_MIN[i]);
-                       data->temp_max[i] = adm1026_read_value(client, 
+                       data->temp_max[i] = adm1026_read_value(client,
                                ADM1026_REG_TEMP_MAX[i]);
-                       data->temp_tmin[i] = adm1026_read_value(client, 
+                       data->temp_tmin[i] = adm1026_read_value(client,
                                ADM1026_REG_TEMP_TMIN[i]);
-                       data->temp_crit[i] = adm1026_read_value(client, 
+                       data->temp_crit[i] = adm1026_read_value(client,
                                ADM1026_REG_TEMP_THERM[i]);
-                       data->temp_offset[i] = adm1026_read_value(client, 
+                       data->temp_offset[i] = adm1026_read_value(client,
                                ADM1026_REG_TEMP_OFFSET[i]);
                }
 
                /* Read the STATUS/alarm masks */
-               alarms  = adm1026_read_value(client, ADM1026_REG_MASK4);
-               gpio    = alarms & 0x80 ? 0x0100 : 0;  /* GPIO16 */
-               alarms  = (alarms & 0x7f) << 8;
+               alarms = adm1026_read_value(client, ADM1026_REG_MASK4);
+               gpio = alarms & 0x80 ? 0x0100 : 0; /* GPIO16 */
+               alarms = (alarms & 0x7f) << 8;
                alarms |= adm1026_read_value(client, ADM1026_REG_MASK3);
                alarms <<= 8;
                alarms |= adm1026_read_value(client, ADM1026_REG_MASK2);
@@ -663,24 +661,24 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
                data->alarm_mask = alarms;
 
                /* Read the GPIO values */
-               gpio |= adm1026_read_value(client, 
+               gpio |= adm1026_read_value(client,
                        ADM1026_REG_GPIO_MASK_8_15);
                gpio <<= 8;
                gpio |= adm1026_read_value(client, ADM1026_REG_GPIO_MASK_0_7);
                data->gpio_mask = gpio;
 
                /* Read various values from CONFIG1 */
-               data->config1 = adm1026_read_value(client, 
+               data->config1 = adm1026_read_value(client,
                        ADM1026_REG_CONFIG1);
                if (data->config1 & CFG1_PWM_AFC) {
                        data->pwm1.enable = 2;
-                       data->pwm1.auto_pwm_min = 
+                       data->pwm1.auto_pwm_min =
                                PWM_MIN_FROM_REG(data->pwm1.pwm);
                }
                /* Read the GPIO config */
-               data->config2 = adm1026_read_value(client, 
+               data->config2 = adm1026_read_value(client,
                        ADM1026_REG_CONFIG2);
-               data->config3 = adm1026_read_value(client, 
+               data->config3 = adm1026_read_value(client,
                        ADM1026_REG_CONFIG3);
                data->gpio_config[16] = (data->config3 >> 6) & 0x03;
 
@@ -695,7 +693,7 @@ static struct adm1026_data *adm1026_update_device(struct device *dev)
                }
 
                data->last_config = jiffies;
-       };  /* last_config */
+       }; /* last_config */
 
        dev_dbg(&client->dev, "Setting VID from GPIO11-15.\n");
        data->vid = (data->gpio >> 11) & 0x1f;
@@ -710,15 +708,15 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in[nr]));
+       return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in[nr]));
 }
 static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
                char *buf)
 {
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
-       struct adm1026_data *data = adm1026_update_device(dev); 
-       return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_min[nr]));
+       struct adm1026_data *data = adm1026_update_device(dev);
+       return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_min[nr]));
 }
 static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
@@ -733,7 +731,7 @@ static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
        data->in_min[nr] = INS_TO_REG(nr, val);
        adm1026_write_value(client, ADM1026_REG_IN_MIN[nr], data->in_min[nr]);
        mutex_unlock(&data->update_lock);
-       return count; 
+       return count;
 }
 static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
                char *buf)
@@ -741,7 +739,7 @@ static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", INS_FROM_REG(nr, data->in_max[nr]));
+       return sprintf(buf, "%d\n", INS_FROM_REG(nr, data->in_max[nr]));
 }
 static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
@@ -788,13 +786,13 @@ in_reg(15);
 static ssize_t show_in16(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in[16]) -
+       return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in[16]) -
                NEG12_OFFSET);
 }
 static ssize_t show_in16_min(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       struct adm1026_data *data = adm1026_update_device(dev); 
-       return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_min[16])
+       struct adm1026_data *data = adm1026_update_device(dev);
+       return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_min[16])
                - NEG12_OFFSET);
 }
 static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
@@ -807,12 +805,12 @@ static ssize_t set_in16_min(struct device *dev, struct device_attribute *attr, c
        data->in_min[16] = INS_TO_REG(16, val + NEG12_OFFSET);
        adm1026_write_value(client, ADM1026_REG_IN_MIN[16], data->in_min[16]);
        mutex_unlock(&data->update_lock);
-       return count; 
+       return count;
 }
 static ssize_t show_in16_max(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", INS_FROM_REG(16, data->in_max[16])
+       return sprintf(buf, "%d\n", INS_FROM_REG(16, data->in_max[16])
                        - NEG12_OFFSET);
 }
 static ssize_t set_in16_max(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
@@ -843,7 +841,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
+       return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
                data->fan_div[nr]));
 }
 static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
@@ -852,7 +850,7 @@ static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
+       return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
                data->fan_div[nr]));
 }
 static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
@@ -872,10 +870,10 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
        return count;
 }
 
-#define fan_offset(offset)                                                     \
-static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan, NULL,        \
-               offset - 1);                                                    \
-static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR,                \
+#define fan_offset(offset)                                             \
+static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan, NULL,        \
+               offset - 1);                                            \
+static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR,                \
                show_fan_min, set_fan_min, offset - 1);
 
 fan_offset(1);
@@ -892,8 +890,8 @@ static void fixup_fan_min(struct device *dev, int fan, int old_div)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1026_data *data = i2c_get_clientdata(client);
-       int    new_min;
-       int    new_div = data->fan_div[fan];
+       int new_min;
+       int new_div = data->fan_div[fan];
 
        /* 0 and 0xff are special.  Don't adjust them */
        if (data->fan_min[fan] == 0 || data->fan_min[fan] == 0xff) {
@@ -913,7 +911,7 @@ static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", data->fan_div[nr]);
+       return sprintf(buf, "%d\n", data->fan_div[nr]);
 }
 static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
@@ -922,10 +920,10 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
        int nr = sensor_attr->index;
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1026_data *data = i2c_get_clientdata(client);
-       int    val,orig_div,new_div,shift;
+       int val, orig_div, new_div, shift;
 
        val = simple_strtol(buf, NULL, 10);
-       new_div = DIV_TO_REG(val); 
+       new_div = DIV_TO_REG(val);
        if (new_div == 0) {
                return -EINVAL;
        }
@@ -946,14 +944,14 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
        }
 
        if (data->fan_div[nr] != orig_div) {
-               fixup_fan_min(dev,nr,orig_div);
+               fixup_fan_min(dev, nr, orig_div);
        }
        mutex_unlock(&data->update_lock);
        return count;
 }
 
-#define fan_offset_div(offset)                                          \
-static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR,         \
+#define fan_offset_div(offset)                                         \
+static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR,                \
                show_fan_div, set_fan_div, offset - 1);
 
 fan_offset_div(1);
@@ -972,7 +970,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp[nr]));
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
 }
 static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
                char *buf)
@@ -980,7 +978,7 @@ static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_min[nr]));
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
 }
 static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
@@ -1004,7 +1002,7 @@ static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_max[nr]));
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
 }
 static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
@@ -1024,7 +1022,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
 }
 
 #define temp_reg(offset)                                               \
-static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp,    \
+static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp,    \
                NULL, offset - 1);                                      \
 static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR,       \
                show_temp_min, set_temp_min, offset - 1);               \
@@ -1042,7 +1040,7 @@ static ssize_t show_temp_offset(struct device *dev,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_offset[nr]));
 }
 static ssize_t set_temp_offset(struct device *dev,
                struct device_attribute *attr, const char *buf,
@@ -1076,7 +1074,7 @@ static ssize_t show_temp_auto_point1_temp_hyst(struct device *dev,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(
                ADM1026_FAN_ACTIVATION_TEMP_HYST + data->temp_tmin[nr]));
 }
 static ssize_t show_temp_auto_point2_temp(struct device *dev,
@@ -1085,7 +1083,7 @@ static ssize_t show_temp_auto_point2_temp(struct device *dev,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_tmin[nr] +
                ADM1026_FAN_CONTROL_TEMP_RANGE));
 }
 static ssize_t show_temp_auto_point1_temp(struct device *dev,
@@ -1094,7 +1092,7 @@ static ssize_t show_temp_auto_point1_temp(struct device *dev,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_tmin[nr]));
 }
 static ssize_t set_temp_auto_point1_temp(struct device *dev,
                struct device_attribute *attr, const char *buf, size_t count)
@@ -1113,13 +1111,13 @@ static ssize_t set_temp_auto_point1_temp(struct device *dev,
        return count;
 }
 
-#define temp_auto_point(offset)                                                        \
-static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp, S_IRUGO | S_IWUSR,  \
-               show_temp_auto_point1_temp, set_temp_auto_point1_temp,          \
-               offset - 1);                                                    \
-static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO,       \
-               show_temp_auto_point1_temp_hyst, NULL, offset - 1);             \
-static SENSOR_DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO,            \
+#define temp_auto_point(offset)                                                \
+static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp,             \
+               S_IRUGO | S_IWUSR, show_temp_auto_point1_temp,          \
+               set_temp_auto_point1_temp, offset - 1);                 \
+static SENSOR_DEVICE_ATTR(temp##offset##_auto_point1_temp_hyst, S_IRUGO,\
+               show_temp_auto_point1_temp_hyst, NULL, offset - 1);     \
+static SENSOR_DEVICE_ATTR(temp##offset##_auto_point2_temp, S_IRUGO,    \
                show_temp_auto_point2_temp, NULL, offset - 1);
 
 temp_auto_point(1);
@@ -1130,7 +1128,7 @@ static ssize_t show_temp_crit_enable(struct device *dev,
                struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
+       return sprintf(buf, "%d\n", (data->config1 & CFG1_THERM_HOT) >> 4);
 }
 static ssize_t set_temp_crit_enable(struct device *dev,
                struct device_attribute *attr, const char *buf, size_t count)
@@ -1142,7 +1140,7 @@ static ssize_t set_temp_crit_enable(struct device *dev,
        if ((val == 1) || (val==0)) {
                mutex_lock(&data->update_lock);
                data->config1 = (data->config1 & ~CFG1_THERM_HOT) | (val << 4);
-               adm1026_write_value(client, ADM1026_REG_CONFIG1, 
+               adm1026_write_value(client, ADM1026_REG_CONFIG1,
                        data->config1);
                mutex_unlock(&data->update_lock);
        }
@@ -1163,7 +1161,7 @@ static ssize_t show_temp_crit(struct device *dev,
        struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
        int nr = sensor_attr->index;
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
 }
 static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
@@ -1193,7 +1191,7 @@ temp_crit_reg(3);
 static ssize_t show_analog_out_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", DAC_FROM_REG(data->analog_out));
+       return sprintf(buf, "%d\n", DAC_FROM_REG(data->analog_out));
 }
 static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *attr, const char *buf,
                size_t count)
@@ -1209,26 +1207,25 @@ static ssize_t set_analog_out_reg(struct device *dev, struct device_attribute *a
        return count;
 }
 
-static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg, 
+static DEVICE_ATTR(analog_out, S_IRUGO | S_IWUSR, show_analog_out_reg,
        set_analog_out_reg);
 
 static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
+       return sprintf(buf, "%d\n", vid_from_reg(data->vid & 0x3f, data->vrm));
 }
 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
 
 static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = dev_get_drvdata(dev);
-       return sprintf(buf,"%d\n", data->vrm);
+       return sprintf(buf, "%d\n", data->vrm);
 }
 static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf,
                size_t count)
 {
-       struct i2c_client *client = to_i2c_client(dev);
-       struct adm1026_data *data = i2c_get_clientdata(client);
+       struct adm1026_data *data = dev_get_drvdata(dev);
 
        data->vrm = simple_strtol(buf, NULL, 10);
        return count;
@@ -1239,15 +1236,52 @@ static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
 static ssize_t show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf, "%ld\n", (long) (data->alarms));
+       return sprintf(buf, "%ld\n", data->alarms);
 }
 
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
 
+static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
+                         char *buf)
+{
+       struct adm1026_data *data = adm1026_update_device(dev);
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       return sprintf(buf, "%ld\n", (data->alarms >> bitnr) & 1);
+}
+
+static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(in11_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(in12_alarm, S_IRUGO, show_alarm, NULL, 3);
+static SENSOR_DEVICE_ATTR(in13_alarm, S_IRUGO, show_alarm, NULL, 4);
+static SENSOR_DEVICE_ATTR(in14_alarm, S_IRUGO, show_alarm, NULL, 5);
+static SENSOR_DEVICE_ATTR(in15_alarm, S_IRUGO, show_alarm, NULL, 6);
+static SENSOR_DEVICE_ATTR(in16_alarm, S_IRUGO, show_alarm, NULL, 7);
+static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
+static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
+static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
+static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
+static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
+static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
+static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
+static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 16);
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 17);
+static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 18);
+static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 19);
+static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 20);
+static SENSOR_DEVICE_ATTR(fan6_alarm, S_IRUGO, show_alarm, NULL, 21);
+static SENSOR_DEVICE_ATTR(fan7_alarm, S_IRUGO, show_alarm, NULL, 22);
+static SENSOR_DEVICE_ATTR(fan8_alarm, S_IRUGO, show_alarm, NULL, 23);
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 24);
+static SENSOR_DEVICE_ATTR(in10_alarm, S_IRUGO, show_alarm, NULL, 25);
+static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 26);
+
 static ssize_t show_alarm_mask(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%ld\n", data->alarm_mask);
+       return sprintf(buf, "%ld\n", data->alarm_mask);
 }
 static ssize_t set_alarm_mask(struct device *dev, struct device_attribute *attr, const char *buf,
                size_t count)
@@ -1283,7 +1317,7 @@ static DEVICE_ATTR(alarm_mask, S_IRUGO | S_IWUSR, show_alarm_mask,
 static ssize_t show_gpio(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%ld\n", data->gpio);
+       return sprintf(buf, "%ld\n", data->gpio);
 }
 static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const char *buf,
                size_t count)
@@ -1291,16 +1325,16 @@ static ssize_t set_gpio(struct device *dev, struct device_attribute *attr, const
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1026_data *data = i2c_get_clientdata(client);
        int val = simple_strtol(buf, NULL, 10);
-       long   gpio;
+       long gpio;
 
        mutex_lock(&data->update_lock);
        data->gpio = val & 0x1ffff;
        gpio = data->gpio;
-       adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7,gpio & 0xff);
+       adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_0_7, gpio & 0xff);
        gpio >>= 8;
-       adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15,gpio & 0xff);
+       adm1026_write_value(client, ADM1026_REG_GPIO_STATUS_8_15, gpio & 0xff);
        gpio = ((gpio >> 1) & 0x80) | (data->alarms >> 24 & 0x7f);
-       adm1026_write_value(client, ADM1026_REG_STATUS4,gpio & 0xff);
+       adm1026_write_value(client, ADM1026_REG_STATUS4, gpio & 0xff);
        mutex_unlock(&data->update_lock);
        return count;
 }
@@ -1311,7 +1345,7 @@ static DEVICE_ATTR(gpio, S_IRUGO | S_IWUSR, show_gpio, set_gpio);
 static ssize_t show_gpio_mask(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%ld\n", data->gpio_mask);
+       return sprintf(buf, "%ld\n", data->gpio_mask);
 }
 static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr, const char *buf,
                size_t count)
@@ -1319,16 +1353,16 @@ static ssize_t set_gpio_mask(struct device *dev, struct device_attribute *attr,
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1026_data *data = i2c_get_clientdata(client);
        int val = simple_strtol(buf, NULL, 10);
-       long   mask;
+       long mask;
 
        mutex_lock(&data->update_lock);
        data->gpio_mask = val & 0x1ffff;
        mask = data->gpio_mask;
-       adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7,mask & 0xff);
+       adm1026_write_value(client, ADM1026_REG_GPIO_MASK_0_7, mask & 0xff);
        mask >>= 8;
-       adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15,mask & 0xff);
+       adm1026_write_value(client, ADM1026_REG_GPIO_MASK_8_15, mask & 0xff);
        mask = ((mask >> 1) & 0x80) | (data->alarm_mask >> 24 & 0x7f);
-       adm1026_write_value(client, ADM1026_REG_MASK1,mask & 0xff);
+       adm1026_write_value(client, ADM1026_REG_MASK1, mask & 0xff);
        mutex_unlock(&data->update_lock);
        return count;
 }
@@ -1338,7 +1372,7 @@ static DEVICE_ATTR(gpio_mask, S_IRUGO | S_IWUSR, show_gpio_mask, set_gpio_mask);
 static ssize_t show_pwm_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", PWM_FROM_REG(data->pwm1.pwm));
+       return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm1.pwm));
 }
 static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, const char *buf,
                size_t count)
@@ -1359,7 +1393,7 @@ static ssize_t set_pwm_reg(struct device *dev, struct device_attribute *attr, co
 static ssize_t show_auto_pwm_min(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", data->pwm1.auto_pwm_min);
+       return sprintf(buf, "%d\n", data->pwm1.auto_pwm_min);
 }
 static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *attr, const char *buf,
                size_t count)
@@ -1369,10 +1403,10 @@ static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *att
        int val = simple_strtol(buf, NULL, 10);
 
        mutex_lock(&data->update_lock);
-       data->pwm1.auto_pwm_min = SENSORS_LIMIT(val,0,255);
+       data->pwm1.auto_pwm_min = SENSORS_LIMIT(val, 0, 255);
        if (data->pwm1.enable == 2) { /* apply immediately */
                data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
-                       PWM_MIN_TO_REG(data->pwm1.auto_pwm_min)); 
+                       PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
                adm1026_write_value(client, ADM1026_REG_PWM, data->pwm1.pwm);
        }
        mutex_unlock(&data->update_lock);
@@ -1380,12 +1414,12 @@ static ssize_t set_auto_pwm_min(struct device *dev, struct device_attribute *att
 }
 static ssize_t show_auto_pwm_max(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       return sprintf(buf,"%d\n", ADM1026_PWM_MAX);
+       return sprintf(buf, "%d\n", ADM1026_PWM_MAX);
 }
 static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct adm1026_data *data = adm1026_update_device(dev);
-       return sprintf(buf,"%d\n", data->pwm1.enable);
+       return sprintf(buf, "%d\n", data->pwm1.enable);
 }
 static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr, const char *buf,
                size_t count)
@@ -1393,7 +1427,7 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1026_data *data = i2c_get_clientdata(client);
        int val = simple_strtol(buf, NULL, 10);
-       int     old_enable;
+       int old_enable;
 
        if ((val >= 0) && (val < 3)) {
                mutex_lock(&data->update_lock);
@@ -1403,15 +1437,15 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
                                | ((val == 2) ? CFG1_PWM_AFC : 0);
                adm1026_write_value(client, ADM1026_REG_CONFIG1,
                        data->config1);
-               if (val == 2) {  /* apply pwm1_auto_pwm_min to pwm1 */
+               if (val == 2) { /* apply pwm1_auto_pwm_min to pwm1 */
                        data->pwm1.pwm = PWM_TO_REG((data->pwm1.pwm & 0x0f) |
-                               PWM_MIN_TO_REG(data->pwm1.auto_pwm_min)); 
-                       adm1026_write_value(client, ADM1026_REG_PWM, 
+                               PWM_MIN_TO_REG(data->pwm1.auto_pwm_min));
+                       adm1026_write_value(client, ADM1026_REG_PWM,
                                data->pwm1.pwm);
                } else if (!((old_enable == 1) && (val == 1))) {
                        /* set pwm to safe value */
                        data->pwm1.pwm = 255;
-                       adm1026_write_value(client, ADM1026_REG_PWM, 
+                       adm1026_write_value(client, ADM1026_REG_PWM,
                                data->pwm1.pwm);
                }
                mutex_unlock(&data->update_lock);
@@ -1420,20 +1454,20 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute *attr,
 }
 
 /* enable PWM fan control */
-static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg); 
-static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg); 
-static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg); 
-static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
+static DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm_reg, set_pwm_reg);
+static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
        set_pwm_enable);
-static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
+static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
        set_pwm_enable);
-static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable, 
+static DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable,
        set_pwm_enable);
-static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR, 
+static DEVICE_ATTR(temp1_auto_point1_pwm, S_IRUGO | S_IWUSR,
        show_auto_pwm_min, set_auto_pwm_min);
-static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR, 
+static DEVICE_ATTR(temp2_auto_point1_pwm, S_IRUGO | S_IWUSR,
        show_auto_pwm_min, set_auto_pwm_min);
-static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR, 
+static DEVICE_ATTR(temp3_auto_point1_pwm, S_IRUGO | S_IWUSR,
        show_auto_pwm_min, set_auto_pwm_min);
 
 static DEVICE_ATTR(temp1_auto_point2_pwm, S_IRUGO, show_auto_pwm_max, NULL);
@@ -1444,105 +1478,115 @@ static struct attribute *adm1026_attributes[] = {
        &sensor_dev_attr_in0_input.dev_attr.attr,
        &sensor_dev_attr_in0_max.dev_attr.attr,
        &sensor_dev_attr_in0_min.dev_attr.attr,
+       &sensor_dev_attr_in0_alarm.dev_attr.attr,
        &sensor_dev_attr_in1_input.dev_attr.attr,
        &sensor_dev_attr_in1_max.dev_attr.attr,
        &sensor_dev_attr_in1_min.dev_attr.attr,
+       &sensor_dev_attr_in1_alarm.dev_attr.attr,
        &sensor_dev_attr_in2_input.dev_attr.attr,
        &sensor_dev_attr_in2_max.dev_attr.attr,
        &sensor_dev_attr_in2_min.dev_attr.attr,
+       &sensor_dev_attr_in2_alarm.dev_attr.attr,
        &sensor_dev_attr_in3_input.dev_attr.attr,
        &sensor_dev_attr_in3_max.dev_attr.attr,
        &sensor_dev_attr_in3_min.dev_attr.attr,
+       &sensor_dev_attr_in3_alarm.dev_attr.attr,
        &sensor_dev_attr_in4_input.dev_attr.attr,
        &sensor_dev_attr_in4_max.dev_attr.attr,
        &sensor_dev_attr_in4_min.dev_attr.attr,
+       &sensor_dev_attr_in4_alarm.dev_attr.attr,
        &sensor_dev_attr_in5_input.dev_attr.attr,
        &sensor_dev_attr_in5_max.dev_attr.attr,
        &sensor_dev_attr_in5_min.dev_attr.attr,
+       &sensor_dev_attr_in5_alarm.dev_attr.attr,
        &sensor_dev_attr_in6_input.dev_attr.attr,
        &sensor_dev_attr_in6_max.dev_attr.attr,
        &sensor_dev_attr_in6_min.dev_attr.attr,
+       &sensor_dev_attr_in6_alarm.dev_attr.attr,
        &sensor_dev_attr_in7_input.dev_attr.attr,
        &sensor_dev_attr_in7_max.dev_attr.attr,
        &sensor_dev_attr_in7_min.dev_attr.attr,
-       &sensor_dev_attr_in8_input.dev_attr.attr,
-       &sensor_dev_attr_in8_max.dev_attr.attr,
-       &sensor_dev_attr_in8_min.dev_attr.attr,
-       &sensor_dev_attr_in9_input.dev_attr.attr,
-       &sensor_dev_attr_in9_max.dev_attr.attr,
-       &sensor_dev_attr_in9_min.dev_attr.attr,
+       &sensor_dev_attr_in7_alarm.dev_attr.attr,
        &sensor_dev_attr_in10_input.dev_attr.attr,
        &sensor_dev_attr_in10_max.dev_attr.attr,
        &sensor_dev_attr_in10_min.dev_attr.attr,
+       &sensor_dev_attr_in10_alarm.dev_attr.attr,
        &sensor_dev_attr_in11_input.dev_attr.attr,
        &sensor_dev_attr_in11_max.dev_attr.attr,
        &sensor_dev_attr_in11_min.dev_attr.attr,
+       &sensor_dev_attr_in11_alarm.dev_attr.attr,
        &sensor_dev_attr_in12_input.dev_attr.attr,
        &sensor_dev_attr_in12_max.dev_attr.attr,
        &sensor_dev_attr_in12_min.dev_attr.attr,
+       &sensor_dev_attr_in12_alarm.dev_attr.attr,
        &sensor_dev_attr_in13_input.dev_attr.attr,
        &sensor_dev_attr_in13_max.dev_attr.attr,
        &sensor_dev_attr_in13_min.dev_attr.attr,
+       &sensor_dev_attr_in13_alarm.dev_attr.attr,
        &sensor_dev_attr_in14_input.dev_attr.attr,
        &sensor_dev_attr_in14_max.dev_attr.attr,
        &sensor_dev_attr_in14_min.dev_attr.attr,
+       &sensor_dev_attr_in14_alarm.dev_attr.attr,
        &sensor_dev_attr_in15_input.dev_attr.attr,
        &sensor_dev_attr_in15_max.dev_attr.attr,
        &sensor_dev_attr_in15_min.dev_attr.attr,
+       &sensor_dev_attr_in15_alarm.dev_attr.attr,
        &sensor_dev_attr_in16_input.dev_attr.attr,
        &sensor_dev_attr_in16_max.dev_attr.attr,
        &sensor_dev_attr_in16_min.dev_attr.attr,
+       &sensor_dev_attr_in16_alarm.dev_attr.attr,
        &sensor_dev_attr_fan1_input.dev_attr.attr,
        &sensor_dev_attr_fan1_div.dev_attr.attr,
        &sensor_dev_attr_fan1_min.dev_attr.attr,
+       &sensor_dev_attr_fan1_alarm.dev_attr.attr,
        &sensor_dev_attr_fan2_input.dev_attr.attr,
        &sensor_dev_attr_fan2_div.dev_attr.attr,
        &sensor_dev_attr_fan2_min.dev_attr.attr,
+       &sensor_dev_attr_fan2_alarm.dev_attr.attr,
        &sensor_dev_attr_fan3_input.dev_attr.attr,
        &sensor_dev_attr_fan3_div.dev_attr.attr,
        &sensor_dev_attr_fan3_min.dev_attr.attr,
+       &sensor_dev_attr_fan3_alarm.dev_attr.attr,
        &sensor_dev_attr_fan4_input.dev_attr.attr,
        &sensor_dev_attr_fan4_div.dev_attr.attr,
        &sensor_dev_attr_fan4_min.dev_attr.attr,
+       &sensor_dev_attr_fan4_alarm.dev_attr.attr,
        &sensor_dev_attr_fan5_input.dev_attr.attr,
        &sensor_dev_attr_fan5_div.dev_attr.attr,
        &sensor_dev_attr_fan5_min.dev_attr.attr,
+       &sensor_dev_attr_fan5_alarm.dev_attr.attr,
        &sensor_dev_attr_fan6_input.dev_attr.attr,
        &sensor_dev_attr_fan6_div.dev_attr.attr,
        &sensor_dev_attr_fan6_min.dev_attr.attr,
+       &sensor_dev_attr_fan6_alarm.dev_attr.attr,
        &sensor_dev_attr_fan7_input.dev_attr.attr,
        &sensor_dev_attr_fan7_div.dev_attr.attr,
        &sensor_dev_attr_fan7_min.dev_attr.attr,
+       &sensor_dev_attr_fan7_alarm.dev_attr.attr,
        &sensor_dev_attr_fan8_input.dev_attr.attr,
        &sensor_dev_attr_fan8_div.dev_attr.attr,
        &sensor_dev_attr_fan8_min.dev_attr.attr,
+       &sensor_dev_attr_fan8_alarm.dev_attr.attr,
        &sensor_dev_attr_temp1_input.dev_attr.attr,
        &sensor_dev_attr_temp1_max.dev_attr.attr,
        &sensor_dev_attr_temp1_min.dev_attr.attr,
+       &sensor_dev_attr_temp1_alarm.dev_attr.attr,
        &sensor_dev_attr_temp2_input.dev_attr.attr,
        &sensor_dev_attr_temp2_max.dev_attr.attr,
        &sensor_dev_attr_temp2_min.dev_attr.attr,
-       &sensor_dev_attr_temp3_input.dev_attr.attr,
-       &sensor_dev_attr_temp3_max.dev_attr.attr,
-       &sensor_dev_attr_temp3_min.dev_attr.attr,
+       &sensor_dev_attr_temp2_alarm.dev_attr.attr,
        &sensor_dev_attr_temp1_offset.dev_attr.attr,
        &sensor_dev_attr_temp2_offset.dev_attr.attr,
-       &sensor_dev_attr_temp3_offset.dev_attr.attr,
        &sensor_dev_attr_temp1_auto_point1_temp.dev_attr.attr,
        &sensor_dev_attr_temp2_auto_point1_temp.dev_attr.attr,
-       &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
        &sensor_dev_attr_temp1_auto_point1_temp_hyst.dev_attr.attr,
        &sensor_dev_attr_temp2_auto_point1_temp_hyst.dev_attr.attr,
-       &sensor_dev_attr_temp3_auto_point1_temp_hyst.dev_attr.attr,
        &sensor_dev_attr_temp1_auto_point2_temp.dev_attr.attr,
        &sensor_dev_attr_temp2_auto_point2_temp.dev_attr.attr,
-       &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
        &sensor_dev_attr_temp1_crit.dev_attr.attr,
        &sensor_dev_attr_temp2_crit.dev_attr.attr,
-       &sensor_dev_attr_temp3_crit.dev_attr.attr,
        &dev_attr_temp1_crit_enable.attr,
        &dev_attr_temp2_crit_enable.attr,
-       &dev_attr_temp3_crit_enable.attr,
        &dev_attr_cpu0_vid.attr,
        &dev_attr_vrm.attr,
        &dev_attr_alarms.attr,
@@ -1557,10 +1601,8 @@ static struct attribute *adm1026_attributes[] = {
        &dev_attr_pwm3_enable.attr,
        &dev_attr_temp1_auto_point1_pwm.attr,
        &dev_attr_temp2_auto_point1_pwm.attr,
-       &dev_attr_temp3_auto_point1_pwm.attr,
        &dev_attr_temp1_auto_point2_pwm.attr,
        &dev_attr_temp2_auto_point2_pwm.attr,
-       &dev_attr_temp3_auto_point2_pwm.attr,
        &dev_attr_analog_out.attr,
        NULL
 };
@@ -1569,11 +1611,45 @@ static const struct attribute_group adm1026_group = {
        .attrs = adm1026_attributes,
 };
 
+static struct attribute *adm1026_attributes_temp3[] = {
+       &sensor_dev_attr_temp3_input.dev_attr.attr,
+       &sensor_dev_attr_temp3_max.dev_attr.attr,
+       &sensor_dev_attr_temp3_min.dev_attr.attr,
+       &sensor_dev_attr_temp3_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp3_offset.dev_attr.attr,
+       &sensor_dev_attr_temp3_auto_point1_temp.dev_attr.attr,
+       &sensor_dev_attr_temp3_auto_point1_temp_hyst.dev_attr.attr,
+       &sensor_dev_attr_temp3_auto_point2_temp.dev_attr.attr,
+       &sensor_dev_attr_temp3_crit.dev_attr.attr,
+       &dev_attr_temp3_crit_enable.attr,
+       &dev_attr_temp3_auto_point1_pwm.attr,
+       &dev_attr_temp3_auto_point2_pwm.attr,
+};
+
+static const struct attribute_group adm1026_group_temp3 = {
+       .attrs = adm1026_attributes_temp3,
+};
+
+static struct attribute *adm1026_attributes_in8_9[] = {
+       &sensor_dev_attr_in8_input.dev_attr.attr,
+       &sensor_dev_attr_in8_max.dev_attr.attr,
+       &sensor_dev_attr_in8_min.dev_attr.attr,
+       &sensor_dev_attr_in8_alarm.dev_attr.attr,
+       &sensor_dev_attr_in9_input.dev_attr.attr,
+       &sensor_dev_attr_in9_max.dev_attr.attr,
+       &sensor_dev_attr_in9_min.dev_attr.attr,
+       &sensor_dev_attr_in9_alarm.dev_attr.attr,
+};
+
+static const struct attribute_group adm1026_group_in8_9 = {
+       .attrs = adm1026_attributes_in8_9,
+};
+
 static int adm1026_detect(struct i2c_adapter *adapter, int address,
                          int kind)
 {
        int company, verstep;
-       struct i2c_client *new_client;
+       struct i2c_client *client;
        struct adm1026_data *data;
        int err = 0;
        const char *type_name = "";
@@ -1592,26 +1668,25 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address,
                goto exit;
        }
 
-       new_client = &data->client;
-       i2c_set_clientdata(new_client, data);
-       new_client->addr = address;
-       new_client->adapter = adapter;
-       new_client->driver = &adm1026_driver;
-       new_client->flags = 0;
+       client = &data->client;
+       i2c_set_clientdata(client, data);
+       client->addr = address;
+       client->adapter = adapter;
+       client->driver = &adm1026_driver;
 
        /* Now, we do the remaining detection. */
 
-       company = adm1026_read_value(new_client, ADM1026_REG_COMPANY);
-       verstep = adm1026_read_value(new_client, ADM1026_REG_VERSTEP);
+       company = adm1026_read_value(client, ADM1026_REG_COMPANY);
+       verstep = adm1026_read_value(client, ADM1026_REG_VERSTEP);
 
-       dev_dbg(&new_client->dev, "Detecting device at %d,0x%02x with"
+       dev_dbg(&client->dev, "Detecting device at %d,0x%02x with"
                " COMPANY: 0x%02x and VERSTEP: 0x%02x\n",
-               i2c_adapter_id(new_client->adapter), new_client->addr,
+               i2c_adapter_id(client->adapter), client->addr,
                company, verstep);
 
        /* If auto-detecting, Determine the chip type. */
        if (kind <= 0) {
-               dev_dbg(&new_client->dev, "Autodetecting device at %d,0x%02x "
+               dev_dbg(&client->dev, "Autodetecting device at %d,0x%02x "
                        "...\n", i2c_adapter_id(adapter), address);
                if (company == ADM1026_COMPANY_ANALOG_DEV
                    && verstep == ADM1026_VERSTEP_ADM1026) {
@@ -1627,16 +1702,15 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address,
                                verstep);
                        kind = any_chip;
                } else {
-                       dev_dbg(&new_client->dev, ": Autodetection "
+                       dev_dbg(&client->dev, ": Autodetection "
                                "failed\n");
                        /* Not an ADM1026 ... */
-                       if (kind == 0)  { /* User used force=x,y */
+                       if (kind == 0) { /* User used force=x,y */
                                dev_err(&adapter->dev, "Generic ADM1026 not "
                                        "found at %d,0x%02x.  Try "
                                        "force_adm1026.\n",
                                        i2c_adapter_id(adapter), address);
                        }
-                       err = 0;
                        goto exitfree;
                }
        }
@@ -1655,28 +1729,34 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address,
                err = -EFAULT;
                goto exitfree;
        }
-       strlcpy(new_client->name, type_name, I2C_NAME_SIZE);
+       strlcpy(client->name, type_name, I2C_NAME_SIZE);
 
        /* Fill in the remaining client fields */
-       data->type = kind;
-       data->valid = 0;
        mutex_init(&data->update_lock);
 
        /* Tell the I2C layer a new client has arrived */
-       if ((err = i2c_attach_client(new_client)))
+       if ((err = i2c_attach_client(client)))
                goto exitfree;
 
        /* Set the VRM version */
        data->vrm = vid_which_vrm();
 
        /* Initialize the ADM1026 chip */
-       adm1026_init_client(new_client);
+       adm1026_init_client(client);
 
        /* Register sysfs hooks */
-       if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1026_group)))
+       if ((err = sysfs_create_group(&client->dev.kobj, &adm1026_group)))
                goto exitdetach;
+       if (data->config1 & CFG1_AIN8_9)
+               err = sysfs_create_group(&client->dev.kobj,
+                                        &adm1026_group_in8_9);
+       else
+               err = sysfs_create_group(&client->dev.kobj,
+                                        &adm1026_group_temp3);
+       if (err)
+               goto exitremove;
 
-       data->hwmon_dev = hwmon_device_register(&new_client->dev);
+       data->hwmon_dev = hwmon_device_register(&client->dev);
        if (IS_ERR(data->hwmon_dev)) {
                err = PTR_ERR(data->hwmon_dev);
                goto exitremove;
@@ -1686,9 +1766,13 @@ static int adm1026_detect(struct i2c_adapter *adapter, int address,
 
        /* Error out and cleanup code */
 exitremove:
-       sysfs_remove_group(&new_client->dev.kobj, &adm1026_group);
+       sysfs_remove_group(&client->dev.kobj, &adm1026_group);
+       if (data->config1 & CFG1_AIN8_9)
+               sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9);
+       else
+               sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3);
 exitdetach:
-       i2c_detach_client(new_client);
+       i2c_detach_client(client);
 exitfree:
        kfree(data);
 exit:
@@ -1700,6 +1784,10 @@ static int adm1026_detach_client(struct i2c_client *client)
        struct adm1026_data *data = i2c_get_clientdata(client);
        hwmon_device_unregister(data->hwmon_dev);
        sysfs_remove_group(&client->dev.kobj, &adm1026_group);
+       if (data->config1 & CFG1_AIN8_9)
+               sysfs_remove_group(&client->dev.kobj, &adm1026_group_in8_9);
+       else
+               sysfs_remove_group(&client->dev.kobj, &adm1026_group_temp3);
        i2c_detach_client(client);
        kfree(data);
        return 0;
@@ -1710,14 +1798,14 @@ static int __init sm_adm1026_init(void)
        return i2c_add_driver(&adm1026_driver);
 }
 
-static void  __exit sm_adm1026_exit(void)
+static void __exit sm_adm1026_exit(void)
 {
        i2c_del_driver(&adm1026_driver);
 }
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Philip Pokorny <ppokorny@penguincomputing.com>, "
-              "Justin Thiessen <jthiessen@penguincomputing.com>");
+             "Justin Thiessen <jthiessen@penguincomputing.com>");
 MODULE_DESCRIPTION("ADM1026 driver");
 
 module_init(sm_adm1026_init);
index 37cfc101da5e9e10532173b0ea1a3fb2cee5625d..5aaad3636c9876f489a2a41c11a1e1d78bdb8dce 100644 (file)
@@ -5,7 +5,7 @@
   Supports adm1030 / adm1031
   Copyright (C) 2004 Alexandre d'Alton <alex@alexdalton.org>
   Reworked by Jean Delvare <khali@linux-fr.org>
-  
+
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
 #include <linux/err.h>
 #include <linux/mutex.h>
 
 /* Following macros takes channel parameter starting from 0 to 2 */
 #define ADM1031_REG_FAN_SPEED(nr)      (0x08 + (nr))
-#define ADM1031_REG_FAN_DIV(nr)                (0x20  + (nr))
+#define ADM1031_REG_FAN_DIV(nr)                (0x20 + (nr))
 #define ADM1031_REG_PWM                        (0x22)
 #define ADM1031_REG_FAN_MIN(nr)                (0x10 + (nr))
 
-#define ADM1031_REG_TEMP_MAX(nr)       (0x14  + 4*(nr))
-#define ADM1031_REG_TEMP_MIN(nr)       (0x15  + 4*(nr))
-#define ADM1031_REG_TEMP_CRIT(nr)      (0x16  + 4*(nr))
+#define ADM1031_REG_TEMP_MAX(nr)       (0x14 + 4 * (nr))
+#define ADM1031_REG_TEMP_MIN(nr)       (0x15 + 4 * (nr))
+#define ADM1031_REG_TEMP_CRIT(nr)      (0x16 + 4 * (nr))
 
-#define ADM1031_REG_TEMP(nr)           (0xa + (nr))
+#define ADM1031_REG_TEMP(nr)           (0x0a + (nr))
 #define ADM1031_REG_AUTO_TEMP(nr)      (0x24 + (nr))
 
 #define ADM1031_REG_STATUS(nr)         (0x2 + (nr))
 
-#define ADM1031_REG_CONF1              0x0
-#define ADM1031_REG_CONF2              0x1
-#define ADM1031_REG_EXT_TEMP           0x6
+#define ADM1031_REG_CONF1              0x00
+#define ADM1031_REG_CONF2              0x01
+#define ADM1031_REG_EXT_TEMP           0x06
 
 #define ADM1031_CONF1_MONITOR_ENABLE   0x01    /* Monitoring enable */
 #define ADM1031_CONF1_PWM_INVERT       0x08    /* PWM Invert */
@@ -78,7 +79,7 @@ struct adm1031_data {
        /* The chan_select_table contains the possible configurations for
         * auto fan control.
         */
-       auto_chan_table_t *chan_select_table;
+       const auto_chan_table_t *chan_select_table;
        u16 alarm;
        u8 conf1;
        u8 conf2;
@@ -181,25 +182,25 @@ static int AUTO_TEMP_MAX_TO_REG(int val, int reg, int pwm)
 #define GET_FAN_AUTO_BITFIELD(data, idx)       \
        (*(data)->chan_select_table)[FAN_CHAN_FROM_REG((data)->conf1)][idx%2]
 
-/* The tables below contains the possible values for the auto fan 
+/* The tables below contains the possible values for the auto fan
  * control bitfields. the index in the table is the register value.
  * MSb is the auto fan control enable bit, so the four first entries
  * in the table disables auto fan control when both bitfields are zero.
  */
-static auto_chan_table_t auto_channel_select_table_adm1031 = {
-       {0, 0}, {0, 0}, {0, 0}, {0, 0},
-       {2 /*0b010 */ , 4 /*0b100 */ },
-       {2 /*0b010 */ , 2 /*0b010 */ },
-       {4 /*0b100 */ , 4 /*0b100 */ },
-       {7 /*0b111 */ , 7 /*0b111 */ },
+static const auto_chan_table_t auto_channel_select_table_adm1031 = {
+       { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+       { 2 /* 0b010 */ , 4 /* 0b100 */ },
+       { 2 /* 0b010 */ , 2 /* 0b010 */ },
+       { 4 /* 0b100 */ , 4 /* 0b100 */ },
+       { 7 /* 0b111 */ , 7 /* 0b111 */ },
 };
 
-static auto_chan_table_t auto_channel_select_table_adm1030 = {
-       {0, 0}, {0, 0}, {0, 0}, {0, 0},
-       {2 /*0b10 */            , 0},
-       {0xff /*invalid */      , 0},
-       {0xff /*invalid */      , 0},
-       {3 /*0b11 */            , 0},
+static const auto_chan_table_t auto_channel_select_table_adm1030 = {
+       { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 },
+       { 2 /* 0b10 */          , 0 },
+       { 0xff /* invalid */    , 0 },
+       { 0xff /* invalid */    , 0 },
+       { 3 /* 0b11 */          , 0 },
 };
 
 /* That function checks if a bitfield is valid and returns the other bitfield
@@ -228,8 +229,8 @@ get_fan_auto_nearest(struct adm1031_data *data,
                        break;
                } else if (val == (*data->chan_select_table)[i][chan] &&
                           first_match == -1) {
-                       /* Save the first match in case of an exact match has not been
-                        * found 
+                       /* Save the first match in case of an exact match has
+                        * not been found
                         */
                        first_match = i;
                }
@@ -245,17 +246,21 @@ get_fan_auto_nearest(struct adm1031_data *data,
        return 0;
 }
 
-static ssize_t show_fan_auto_channel(struct device *dev, char *buf, int nr)
+static ssize_t show_fan_auto_channel(struct device *dev,
+                                    struct device_attribute *attr, char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct adm1031_data *data = adm1031_update_device(dev);
        return sprintf(buf, "%d\n", GET_FAN_AUTO_BITFIELD(data, nr));
 }
 
 static ssize_t
-set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
+set_fan_auto_channel(struct device *dev, struct device_attribute *attr,
+                    const char *buf, size_t count)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1031_data *data = i2c_get_clientdata(client);
+       int nr = to_sensor_dev_attr(attr)->index;
        int val = simple_strtol(buf, NULL, 10);
        u8 reg;
        int ret;
@@ -264,16 +269,17 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
        old_fan_mode = data->conf1;
 
        mutex_lock(&data->update_lock);
-       
+
        if ((ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg))) {
                mutex_unlock(&data->update_lock);
                return ret;
        }
-       if (((data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1)) & ADM1031_CONF1_AUTO_MODE) ^ 
+       data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1);
+       if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^
            (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) {
                if (data->conf1 & ADM1031_CONF1_AUTO_MODE){
-                       /* Switch to Auto Fan Mode 
-                        * Save PWM registers 
+                       /* Switch to Auto Fan Mode
+                        * Save PWM registers
                         * Set PWM registers to 33% Both */
                        data->old_pwm[0] = data->pwm[0];
                        data->old_pwm[1] = data->pwm[1];
@@ -283,7 +289,7 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
                        data->pwm[0] = data->old_pwm[0];
                        data->pwm[1] = data->old_pwm[1];
                        /* Restore PWM registers */
-                       adm1031_write_value(client, ADM1031_REG_PWM, 
+                       adm1031_write_value(client, ADM1031_REG_PWM,
                                            data->pwm[0] | (data->pwm[1] << 4));
                }
        }
@@ -293,41 +299,35 @@ set_fan_auto_channel(struct device *dev, const char *buf, size_t count, int nr)
        return count;
 }
 
-#define fan_auto_channel_offset(offset)                                                \
-static ssize_t show_fan_auto_channel_##offset (struct device *dev, struct device_attribute *attr, char *buf)   \
-{                                                                              \
-       return show_fan_auto_channel(dev, buf, offset - 1);                     \
-}                                                                              \
-static ssize_t set_fan_auto_channel_##offset (struct device *dev, struct device_attribute *attr,               \
-       const char *buf, size_t count)                                          \
-{                                                                              \
-       return set_fan_auto_channel(dev, buf, count, offset - 1);               \
-}                                                                              \
-static DEVICE_ATTR(auto_fan##offset##_channel, S_IRUGO | S_IWUSR,              \
-                  show_fan_auto_channel_##offset,                              \
-                  set_fan_auto_channel_##offset)
-
-fan_auto_channel_offset(1);
-fan_auto_channel_offset(2);
+static SENSOR_DEVICE_ATTR(auto_fan1_channel, S_IRUGO | S_IWUSR,
+               show_fan_auto_channel, set_fan_auto_channel, 0);
+static SENSOR_DEVICE_ATTR(auto_fan2_channel, S_IRUGO | S_IWUSR,
+               show_fan_auto_channel, set_fan_auto_channel, 1);
 
 /* Auto Temps */
-static ssize_t show_auto_temp_off(struct device *dev, char *buf, int nr)
+static ssize_t show_auto_temp_off(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct adm1031_data *data = adm1031_update_device(dev);
-       return sprintf(buf, "%d\n", 
+       return sprintf(buf, "%d\n",
                       AUTO_TEMP_OFF_FROM_REG(data->auto_temp[nr]));
 }
-static ssize_t show_auto_temp_min(struct device *dev, char *buf, int nr)
+static ssize_t show_auto_temp_min(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct adm1031_data *data = adm1031_update_device(dev);
        return sprintf(buf, "%d\n",
                       AUTO_TEMP_MIN_FROM_REG(data->auto_temp[nr]));
 }
 static ssize_t
-set_auto_temp_min(struct device *dev, const char *buf, size_t count, int nr)
+set_auto_temp_min(struct device *dev, struct device_attribute *attr,
+                 const char *buf, size_t count)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1031_data *data = i2c_get_clientdata(client);
+       int nr = to_sensor_dev_attr(attr)->index;
        int val = simple_strtol(buf, NULL, 10);
 
        mutex_lock(&data->update_lock);
@@ -337,17 +337,21 @@ set_auto_temp_min(struct device *dev, const char *buf, size_t count, int nr)
        mutex_unlock(&data->update_lock);
        return count;
 }
-static ssize_t show_auto_temp_max(struct device *dev, char *buf, int nr)
+static ssize_t show_auto_temp_max(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct adm1031_data *data = adm1031_update_device(dev);
        return sprintf(buf, "%d\n",
                       AUTO_TEMP_MAX_FROM_REG(data->auto_temp[nr]));
 }
 static ssize_t
-set_auto_temp_max(struct device *dev, const char *buf, size_t count, int nr)
+set_auto_temp_max(struct device *dev, struct device_attribute *attr,
+                 const char *buf, size_t count)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1031_data *data = i2c_get_clientdata(client);
+       int nr = to_sensor_dev_attr(attr)->index;
        int val = simple_strtol(buf, NULL, 10);
 
        mutex_lock(&data->update_lock);
@@ -358,56 +362,37 @@ set_auto_temp_max(struct device *dev, const char *buf, size_t count, int nr)
        return count;
 }
 
-#define auto_temp_reg(offset)                                                  \
-static ssize_t show_auto_temp_##offset##_off (struct device *dev, struct device_attribute *attr, char *buf)    \
-{                                                                              \
-       return show_auto_temp_off(dev, buf, offset - 1);                        \
-}                                                                              \
-static ssize_t show_auto_temp_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf)    \
-{                                                                              \
-       return show_auto_temp_min(dev, buf, offset - 1);                        \
-}                                                                              \
-static ssize_t show_auto_temp_##offset##_max (struct device *dev, struct device_attribute *attr, char *buf)    \
-{                                                                              \
-       return show_auto_temp_max(dev, buf, offset - 1);                        \
-}                                                                              \
-static ssize_t set_auto_temp_##offset##_min (struct device *dev, struct device_attribute *attr,                \
-                                            const char *buf, size_t count)     \
-{                                                                              \
-       return set_auto_temp_min(dev, buf, count, offset - 1);          \
-}                                                                              \
-static ssize_t set_auto_temp_##offset##_max (struct device *dev, struct device_attribute *attr,                \
-                                            const char *buf, size_t count)     \
-{                                                                              \
-       return set_auto_temp_max(dev, buf, count, offset - 1);          \
-}                                                                              \
-static DEVICE_ATTR(auto_temp##offset##_off, S_IRUGO,                           \
-                  show_auto_temp_##offset##_off, NULL);                        \
-static DEVICE_ATTR(auto_temp##offset##_min, S_IRUGO | S_IWUSR,                 \
-                  show_auto_temp_##offset##_min, set_auto_temp_##offset##_min);\
-static DEVICE_ATTR(auto_temp##offset##_max, S_IRUGO | S_IWUSR,                 \
-                  show_auto_temp_##offset##_max, set_auto_temp_##offset##_max)
+#define auto_temp_reg(offset)                                          \
+static SENSOR_DEVICE_ATTR(auto_temp##offset##_off, S_IRUGO,            \
+               show_auto_temp_off, NULL, offset - 1);                  \
+static SENSOR_DEVICE_ATTR(auto_temp##offset##_min, S_IRUGO | S_IWUSR,  \
+               show_auto_temp_min, set_auto_temp_min, offset - 1);     \
+static SENSOR_DEVICE_ATTR(auto_temp##offset##_max, S_IRUGO | S_IWUSR,  \
+               show_auto_temp_max, set_auto_temp_max, offset - 1)
 
 auto_temp_reg(1);
 auto_temp_reg(2);
 auto_temp_reg(3);
 
 /* pwm */
-static ssize_t show_pwm(struct device *dev, char *buf, int nr)
+static ssize_t show_pwm(struct device *dev,
+                       struct device_attribute *attr, char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct adm1031_data *data = adm1031_update_device(dev);
        return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr]));
 }
-static ssize_t
-set_pwm(struct device *dev, const char *buf, size_t count, int nr)
+static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
+                      const char *buf, size_t count)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1031_data *data = i2c_get_clientdata(client);
+       int nr = to_sensor_dev_attr(attr)->index;
        int val = simple_strtol(buf, NULL, 10);
        int reg;
 
        mutex_lock(&data->update_lock);
-       if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) && 
+       if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) &&
            (((val>>4) & 0xf) != 5)) {
                /* In automatic mode, the only PWM accepted is 33% */
                mutex_unlock(&data->update_lock);
@@ -422,21 +407,12 @@ set_pwm(struct device *dev, const char *buf, size_t count, int nr)
        return count;
 }
 
-#define pwm_reg(offset)                                                        \
-static ssize_t show_pwm_##offset (struct device *dev, struct device_attribute *attr, char *buf)        \
-{                                                                      \
-       return show_pwm(dev, buf, offset - 1);                  \
-}                                                                      \
-static ssize_t set_pwm_##offset (struct device *dev, struct device_attribute *attr,                    \
-                                const char *buf, size_t count)         \
-{                                                                      \
-       return set_pwm(dev, buf, count, offset - 1);            \
-}                                                                      \
-static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR,                     \
-                  show_pwm_##offset, set_pwm_##offset)
-
-pwm_reg(1);
-pwm_reg(2);
+static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
+static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
+static SENSOR_DEVICE_ATTR(auto_fan1_min_pwm, S_IRUGO | S_IWUSR,
+               show_pwm, set_pwm, 0);
+static SENSOR_DEVICE_ATTR(auto_fan2_min_pwm, S_IRUGO | S_IWUSR,
+               show_pwm, set_pwm, 1);
 
 /* Fans */
 
@@ -471,7 +447,7 @@ static int trust_fan_readings(struct adm1031_data *data, int chan)
                            AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[0])
                            || data->temp[1] >=
                            AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[1])
-                           || (data->chip_type == adm1031 
+                           || (data->chip_type == adm1031
                                && data->temp[2] >=
                                AUTO_TEMP_MIN_FROM_REG_DEG(data->auto_temp[2]));
                        break;
@@ -483,8 +459,10 @@ static int trust_fan_readings(struct adm1031_data *data, int chan)
 }
 
 
-static ssize_t show_fan(struct device *dev, char *buf, int nr)
+static ssize_t show_fan(struct device *dev,
+                       struct device_attribute *attr, char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct adm1031_data *data = adm1031_update_device(dev);
        int value;
 
@@ -493,28 +471,33 @@ static ssize_t show_fan(struct device *dev, char *buf, int nr)
        return sprintf(buf, "%d\n", value);
 }
 
-static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
+static ssize_t show_fan_div(struct device *dev,
+                           struct device_attribute *attr, char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct adm1031_data *data = adm1031_update_device(dev);
        return sprintf(buf, "%d\n", FAN_DIV_FROM_REG(data->fan_div[nr]));
 }
-static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
+static ssize_t show_fan_min(struct device *dev,
+                           struct device_attribute *attr, char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct adm1031_data *data = adm1031_update_device(dev);
        return sprintf(buf, "%d\n",
                       FAN_FROM_REG(data->fan_min[nr],
                                    FAN_DIV_FROM_REG(data->fan_div[nr])));
 }
-static ssize_t
-set_fan_min(struct device *dev, const char *buf, size_t count, int nr)
+static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
+                          const char *buf, size_t count)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1031_data *data = i2c_get_clientdata(client);
+       int nr = to_sensor_dev_attr(attr)->index;
        int val = simple_strtol(buf, NULL, 10);
 
        mutex_lock(&data->update_lock);
        if (val) {
-               data->fan_min[nr] = 
+               data->fan_min[nr] =
                        FAN_TO_REG(val, FAN_DIV_FROM_REG(data->fan_div[nr]));
        } else {
                data->fan_min[nr] = 0xff;
@@ -523,11 +506,12 @@ set_fan_min(struct device *dev, const char *buf, size_t count, int nr)
        mutex_unlock(&data->update_lock);
        return count;
 }
-static ssize_t
-set_fan_div(struct device *dev, const char *buf, size_t count, int nr)
+static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
+                          const char *buf, size_t count)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1031_data *data = i2c_get_clientdata(client);
+       int nr = to_sensor_dev_attr(attr)->index;
        int val = simple_strtol(buf, NULL, 10);
        u8 tmp;
        int old_div;
@@ -535,68 +519,53 @@ set_fan_div(struct device *dev, const char *buf, size_t count, int nr)
 
        tmp = val == 8 ? 0xc0 :
              val == 4 ? 0x80 :
-             val == 2 ? 0x40 : 
-             val == 1 ? 0x00 :  
+             val == 2 ? 0x40 :
+             val == 1 ? 0x00 :
              0xff;
        if (tmp == 0xff)
                return -EINVAL;
-       
+
        mutex_lock(&data->update_lock);
+       /* Get fresh readings */
+       data->fan_div[nr] = adm1031_read_value(client,
+                                              ADM1031_REG_FAN_DIV(nr));
+       data->fan_min[nr] = adm1031_read_value(client,
+                                              ADM1031_REG_FAN_MIN(nr));
+
+       /* Write the new clock divider and fan min */
        old_div = FAN_DIV_FROM_REG(data->fan_div[nr]);
-       data->fan_div[nr] = (tmp & 0xC0) | (0x3f & data->fan_div[nr]);
-       new_min = data->fan_min[nr] * old_div / 
-               FAN_DIV_FROM_REG(data->fan_div[nr]);
+       data->fan_div[nr] = tmp | (0x3f & data->fan_div[nr]);
+       new_min = data->fan_min[nr] * old_div / val;
        data->fan_min[nr] = new_min > 0xff ? 0xff : new_min;
-       data->fan[nr] = data->fan[nr] * old_div / 
-               FAN_DIV_FROM_REG(data->fan_div[nr]);
 
-       adm1031_write_value(client, ADM1031_REG_FAN_DIV(nr), 
+       adm1031_write_value(client, ADM1031_REG_FAN_DIV(nr),
                            data->fan_div[nr]);
-       adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr), 
+       adm1031_write_value(client, ADM1031_REG_FAN_MIN(nr),
                            data->fan_min[nr]);
+
+       /* Invalidate the cache: fan speed is no longer valid */
+       data->valid = 0;
        mutex_unlock(&data->update_lock);
        return count;
 }
 
 #define fan_offset(offset)                                             \
-static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf)        \
-{                                                                      \
-       return show_fan(dev, buf, offset - 1);                  \
-}                                                                      \
-static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf)  \
-{                                                                      \
-       return show_fan_min(dev, buf, offset - 1);                      \
-}                                                                      \
-static ssize_t show_fan_##offset##_div (struct device *dev, struct device_attribute *attr, char *buf)  \
-{                                                                      \
-       return show_fan_div(dev, buf, offset - 1);                      \
-}                                                                      \
-static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr,              \
-       const char *buf, size_t count)                                  \
-{                                                                      \
-       return set_fan_min(dev, buf, count, offset - 1);                \
-}                                                                      \
-static ssize_t set_fan_##offset##_div (struct device *dev, struct device_attribute *attr,              \
-       const char *buf, size_t count)                                  \
-{                                                                      \
-       return set_fan_div(dev, buf, count, offset - 1);                \
-}                                                                      \
-static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset,    \
-                  NULL);                                               \
-static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR,               \
-                  show_fan_##offset##_min, set_fan_##offset##_min);    \
-static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR,               \
-                  show_fan_##offset##_div, set_fan_##offset##_div);    \
-static DEVICE_ATTR(auto_fan##offset##_min_pwm, S_IRUGO | S_IWUSR,      \
-                  show_pwm_##offset, set_pwm_##offset)
+static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO,                        \
+               show_fan, NULL, offset - 1);                            \
+static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR,                \
+               show_fan_min, set_fan_min, offset - 1);                 \
+static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR,                \
+               show_fan_div, set_fan_div, offset - 1)
 
 fan_offset(1);
 fan_offset(2);
 
 
 /* Temps */
-static ssize_t show_temp(struct device *dev, char *buf, int nr)
+static ssize_t show_temp(struct device *dev,
+                        struct device_attribute *attr, char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct adm1031_data *data = adm1031_update_device(dev);
        int ext;
        ext = nr == 0 ?
@@ -604,26 +573,33 @@ static ssize_t show_temp(struct device *dev, char *buf, int nr)
            (((data->ext_temp[nr] >> ((nr - 1) * 3)) & 7));
        return sprintf(buf, "%d\n", TEMP_FROM_REG_EXT(data->temp[nr], ext));
 }
-static ssize_t show_temp_min(struct device *dev, char *buf, int nr)
+static ssize_t show_temp_min(struct device *dev,
+                            struct device_attribute *attr, char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct adm1031_data *data = adm1031_update_device(dev);
        return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[nr]));
 }
-static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
+static ssize_t show_temp_max(struct device *dev,
+                            struct device_attribute *attr, char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct adm1031_data *data = adm1031_update_device(dev);
        return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[nr]));
 }
-static ssize_t show_temp_crit(struct device *dev, char *buf, int nr)
+static ssize_t show_temp_crit(struct device *dev,
+                             struct device_attribute *attr, char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct adm1031_data *data = adm1031_update_device(dev);
        return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[nr]));
 }
-static ssize_t
-set_temp_min(struct device *dev, const char *buf, size_t count, int nr)
+static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
+                           const char *buf, size_t count)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1031_data *data = i2c_get_clientdata(client);
+       int nr = to_sensor_dev_attr(attr)->index;
        int val;
 
        val = simple_strtol(buf, NULL, 10);
@@ -635,11 +611,12 @@ set_temp_min(struct device *dev, const char *buf, size_t count, int nr)
        mutex_unlock(&data->update_lock);
        return count;
 }
-static ssize_t
-set_temp_max(struct device *dev, const char *buf, size_t count, int nr)
+static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
+                           const char *buf, size_t count)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1031_data *data = i2c_get_clientdata(client);
+       int nr = to_sensor_dev_attr(attr)->index;
        int val;
 
        val = simple_strtol(buf, NULL, 10);
@@ -651,11 +628,12 @@ set_temp_max(struct device *dev, const char *buf, size_t count, int nr)
        mutex_unlock(&data->update_lock);
        return count;
 }
-static ssize_t
-set_temp_crit(struct device *dev, const char *buf, size_t count, int nr)
+static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
+                            const char *buf, size_t count)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct adm1031_data *data = i2c_get_clientdata(client);
+       int nr = to_sensor_dev_attr(attr)->index;
        int val;
 
        val = simple_strtol(buf, NULL, 10);
@@ -668,46 +646,15 @@ set_temp_crit(struct device *dev, const char *buf, size_t count, int nr)
        return count;
 }
 
-#define temp_reg(offset)                                                       \
-static ssize_t show_temp_##offset (struct device *dev, struct device_attribute *attr, char *buf)               \
-{                                                                              \
-       return show_temp(dev, buf, offset - 1);                         \
-}                                                                              \
-static ssize_t show_temp_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf)         \
-{                                                                              \
-       return show_temp_min(dev, buf, offset - 1);                             \
-}                                                                              \
-static ssize_t show_temp_##offset##_max (struct device *dev, struct device_attribute *attr, char *buf)         \
-{                                                                              \
-       return show_temp_max(dev, buf, offset - 1);                             \
-}                                                                              \
-static ssize_t show_temp_##offset##_crit (struct device *dev, struct device_attribute *attr, char *buf)        \
-{                                                                              \
-       return show_temp_crit(dev, buf, offset - 1);                    \
-}                                                                              \
-static ssize_t set_temp_##offset##_min (struct device *dev, struct device_attribute *attr,                     \
-                                       const char *buf, size_t count)          \
-{                                                                              \
-       return set_temp_min(dev, buf, count, offset - 1);                       \
-}                                                                              \
-static ssize_t set_temp_##offset##_max (struct device *dev, struct device_attribute *attr,                     \
-                                       const char *buf, size_t count)          \
-{                                                                              \
-       return set_temp_max(dev, buf, count, offset - 1);                       \
-}                                                                              \
-static ssize_t set_temp_##offset##_crit (struct device *dev, struct device_attribute *attr,                    \
-                                        const char *buf, size_t count)         \
-{                                                                              \
-       return set_temp_crit(dev, buf, count, offset - 1);                      \
-}                                                                              \
-static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp_##offset,          \
-                  NULL);                                                       \
-static DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR,                      \
-                  show_temp_##offset##_min, set_temp_##offset##_min);          \
-static DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR,                      \
-                  show_temp_##offset##_max, set_temp_##offset##_max);          \
-static DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR,                     \
-                  show_temp_##offset##_crit, set_temp_##offset##_crit)
+#define temp_reg(offset)                                               \
+static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO,               \
+               show_temp, NULL, offset - 1);                           \
+static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR,       \
+               show_temp_min, set_temp_min, offset - 1);               \
+static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR,       \
+               show_temp_max, set_temp_max, offset - 1);               \
+static SENSOR_DEVICE_ATTR(temp##offset##_crit, S_IRUGO | S_IWUSR,      \
+               show_temp_crit, set_temp_crit, offset - 1)
 
 temp_reg(1);
 temp_reg(2);
@@ -722,6 +669,29 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
 
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
 
+static ssize_t show_alarm(struct device *dev,
+                         struct device_attribute *attr, char *buf)
+{
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       struct adm1031_data *data = adm1031_update_device(dev);
+       return sprintf(buf, "%d\n", (data->alarm >> bitnr) & 1);
+}
+
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(fan1_fault, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(temp2_max_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(temp2_min_alarm, S_IRUGO, show_alarm, NULL, 3);
+static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 4);
+static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 5);
+static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 6);
+static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 7);
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 8);
+static SENSOR_DEVICE_ATTR(fan2_fault, S_IRUGO, show_alarm, NULL, 9);
+static SENSOR_DEVICE_ATTR(temp3_max_alarm, S_IRUGO, show_alarm, NULL, 10);
+static SENSOR_DEVICE_ATTR(temp3_min_alarm, S_IRUGO, show_alarm, NULL, 11);
+static SENSOR_DEVICE_ATTR(temp3_crit_alarm, S_IRUGO, show_alarm, NULL, 12);
+static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 13);
+static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 14);
 
 static int adm1031_attach_adapter(struct i2c_adapter *adapter)
 {
@@ -731,29 +701,38 @@ static int adm1031_attach_adapter(struct i2c_adapter *adapter)
 }
 
 static struct attribute *adm1031_attributes[] = {
-       &dev_attr_fan1_input.attr,
-       &dev_attr_fan1_div.attr,
-       &dev_attr_fan1_min.attr,
-       &dev_attr_pwm1.attr,
-       &dev_attr_auto_fan1_channel.attr,
-       &dev_attr_temp1_input.attr,
-       &dev_attr_temp1_min.attr,
-       &dev_attr_temp1_max.attr,
-       &dev_attr_temp1_crit.attr,
-       &dev_attr_temp2_input.attr,
-       &dev_attr_temp2_min.attr,
-       &dev_attr_temp2_max.attr,
-       &dev_attr_temp2_crit.attr,
-
-       &dev_attr_auto_temp1_off.attr,
-       &dev_attr_auto_temp1_min.attr,
-       &dev_attr_auto_temp1_max.attr,
-
-       &dev_attr_auto_temp2_off.attr,
-       &dev_attr_auto_temp2_min.attr,
-       &dev_attr_auto_temp2_max.attr,
-
-       &dev_attr_auto_fan1_min_pwm.attr,
+       &sensor_dev_attr_fan1_input.dev_attr.attr,
+       &sensor_dev_attr_fan1_div.dev_attr.attr,
+       &sensor_dev_attr_fan1_min.dev_attr.attr,
+       &sensor_dev_attr_fan1_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan1_fault.dev_attr.attr,
+       &sensor_dev_attr_pwm1.dev_attr.attr,
+       &sensor_dev_attr_auto_fan1_channel.dev_attr.attr,
+       &sensor_dev_attr_temp1_input.dev_attr.attr,
+       &sensor_dev_attr_temp1_min.dev_attr.attr,
+       &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_max.dev_attr.attr,
+       &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_crit.dev_attr.attr,
+       &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp2_input.dev_attr.attr,
+       &sensor_dev_attr_temp2_min.dev_attr.attr,
+       &sensor_dev_attr_temp2_min_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp2_max.dev_attr.attr,
+       &sensor_dev_attr_temp2_max_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp2_crit.dev_attr.attr,
+       &sensor_dev_attr_temp2_crit_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp2_fault.dev_attr.attr,
+
+       &sensor_dev_attr_auto_temp1_off.dev_attr.attr,
+       &sensor_dev_attr_auto_temp1_min.dev_attr.attr,
+       &sensor_dev_attr_auto_temp1_max.dev_attr.attr,
+
+       &sensor_dev_attr_auto_temp2_off.dev_attr.attr,
+       &sensor_dev_attr_auto_temp2_min.dev_attr.attr,
+       &sensor_dev_attr_auto_temp2_max.dev_attr.attr,
+
+       &sensor_dev_attr_auto_fan1_min_pwm.dev_attr.attr,
 
        &dev_attr_alarms.attr,
 
@@ -765,19 +744,25 @@ static const struct attribute_group adm1031_group = {
 };
 
 static struct attribute *adm1031_attributes_opt[] = {
-       &dev_attr_fan2_input.attr,
-       &dev_attr_fan2_div.attr,
-       &dev_attr_fan2_min.attr,
-       &dev_attr_pwm2.attr,
-       &dev_attr_auto_fan2_channel.attr,
-       &dev_attr_temp3_input.attr,
-       &dev_attr_temp3_min.attr,
-       &dev_attr_temp3_max.attr,
-       &dev_attr_temp3_crit.attr,
-       &dev_attr_auto_temp3_off.attr,
-       &dev_attr_auto_temp3_min.attr,
-       &dev_attr_auto_temp3_max.attr,
-       &dev_attr_auto_fan2_min_pwm.attr,
+       &sensor_dev_attr_fan2_input.dev_attr.attr,
+       &sensor_dev_attr_fan2_div.dev_attr.attr,
+       &sensor_dev_attr_fan2_min.dev_attr.attr,
+       &sensor_dev_attr_fan2_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan2_fault.dev_attr.attr,
+       &sensor_dev_attr_pwm2.dev_attr.attr,
+       &sensor_dev_attr_auto_fan2_channel.dev_attr.attr,
+       &sensor_dev_attr_temp3_input.dev_attr.attr,
+       &sensor_dev_attr_temp3_min.dev_attr.attr,
+       &sensor_dev_attr_temp3_min_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp3_max.dev_attr.attr,
+       &sensor_dev_attr_temp3_max_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp3_crit.dev_attr.attr,
+       &sensor_dev_attr_temp3_crit_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp3_fault.dev_attr.attr,
+       &sensor_dev_attr_auto_temp3_off.dev_attr.attr,
+       &sensor_dev_attr_auto_temp3_min.dev_attr.attr,
+       &sensor_dev_attr_auto_temp3_max.dev_attr.attr,
+       &sensor_dev_attr_auto_fan2_min_pwm.dev_attr.attr,
        NULL
 };
 
@@ -788,7 +773,7 @@ static const struct attribute_group adm1031_group_opt = {
 /* This function is called by i2c_probe */
 static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
 {
-       struct i2c_client *new_client;
+       struct i2c_client *client;
        struct adm1031_data *data;
        int err = 0;
        const char *name = "";
@@ -801,17 +786,16 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
                goto exit;
        }
 
-       new_client = &data->client;
-       i2c_set_clientdata(new_client, data);
-       new_client->addr = address;
-       new_client->adapter = adapter;
-       new_client->driver = &adm1031_driver;
-       new_client->flags = 0;
+       client = &data->client;
+       i2c_set_clientdata(client, data);
+       client->addr = address;
+       client->adapter = adapter;
+       client->driver = &adm1031_driver;
 
        if (kind < 0) {
                int id, co;
-               id = i2c_smbus_read_byte_data(new_client, 0x3d);
-               co = i2c_smbus_read_byte_data(new_client, 0x3e);
+               id = i2c_smbus_read_byte_data(client, 0x3d);
+               co = i2c_smbus_read_byte_data(client, 0x3e);
 
                if (!((id == 0x31 || id == 0x30) && co == 0x41))
                        goto exit_free;
@@ -832,28 +816,27 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
        }
        data->chip_type = kind;
 
-       strlcpy(new_client->name, name, I2C_NAME_SIZE);
-       data->valid = 0;
+       strlcpy(client->name, name, I2C_NAME_SIZE);
        mutex_init(&data->update_lock);
 
        /* Tell the I2C layer a new client has arrived */
-       if ((err = i2c_attach_client(new_client)))
+       if ((err = i2c_attach_client(client)))
                goto exit_free;
 
        /* Initialize the ADM1031 chip */
-       adm1031_init_client(new_client);
+       adm1031_init_client(client);
 
        /* Register sysfs hooks */
-       if ((err = sysfs_create_group(&new_client->dev.kobj, &adm1031_group)))
+       if ((err = sysfs_create_group(&client->dev.kobj, &adm1031_group)))
                goto exit_detach;
 
        if (kind == adm1031) {
-               if ((err = sysfs_create_group(&new_client->dev.kobj,
+               if ((err = sysfs_create_group(&client->dev.kobj,
                                                &adm1031_group_opt)))
                        goto exit_remove;
        }
 
-       data->hwmon_dev = hwmon_device_register(&new_client->dev);
+       data->hwmon_dev = hwmon_device_register(&client->dev);
        if (IS_ERR(data->hwmon_dev)) {
                err = PTR_ERR(data->hwmon_dev);
                goto exit_remove;
@@ -862,10 +845,10 @@ static int adm1031_detect(struct i2c_adapter *adapter, int address, int kind)
        return 0;
 
 exit_remove:
-       sysfs_remove_group(&new_client->dev.kobj, &adm1031_group);
-       sysfs_remove_group(&new_client->dev.kobj, &adm1031_group_opt);
+       sysfs_remove_group(&client->dev.kobj, &adm1031_group);
+       sysfs_remove_group(&client->dev.kobj, &adm1031_group_opt);
 exit_detach:
-       i2c_detach_client(new_client);
+       i2c_detach_client(client);
 exit_free:
        kfree(data);
 exit:
@@ -897,7 +880,7 @@ static void adm1031_init_client(struct i2c_client *client)
        if (data->chip_type == adm1031) {
                mask |= (ADM1031_CONF2_PWM2_ENABLE |
                        ADM1031_CONF2_TACH2_ENABLE);
-       } 
+       }
        /* Initialize the ADM1031 chip (enables fan speed reading ) */
        read_val = adm1031_read_value(client, ADM1031_REG_CONF2);
        if ((read_val | mask) != read_val) {
@@ -976,7 +959,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
                if (data->chip_type == adm1030) {
                        data->alarm &= 0xc0ff;
                }
-               
+
                for (chan=0; chan<(data->chip_type == adm1030 ? 1 : 2); chan++) {
                        data->fan_div[chan] =
                            adm1031_read_value(client, ADM1031_REG_FAN_DIV(chan));
@@ -985,7 +968,7 @@ static struct adm1031_data *adm1031_update_device(struct device *dev)
                        data->fan[chan] =
                            adm1031_read_value(client, ADM1031_REG_FAN_SPEED(chan));
                        data->pwm[chan] =
-                           0xf & (adm1031_read_value(client, ADM1031_REG_PWM) >> 
+                           0xf & (adm1031_read_value(client, ADM1031_REG_PWM) >>
                                   (4*chan));
                }
                data->last_updated = jiffies;
index c17d0b6b3283f306677b9107c711b2e02574ce69..7671d2bf780042c1d264cf03454c68bce9d204cd 100644 (file)
@@ -141,7 +141,6 @@ static struct i2c_driver adm9240_driver = {
        .driver = {
                .name   = "adm9240",
        },
-       .id             = I2C_DRIVERID_ADM9240,
        .attach_adapter = adm9240_attach_adapter,
        .detach_client  = adm9240_detach_client,
 };
@@ -415,6 +414,23 @@ static ssize_t show_alarms(struct device *dev,
 }
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
 
+static ssize_t show_alarm(struct device *dev,
+               struct device_attribute *attr, char *buf)
+{
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       struct adm9240_data *data = adm9240_update_device(dev);
+       return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
+}
+static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
+static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
+static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
+
 /* vid */
 static ssize_t show_vid(struct device *dev,
                struct device_attribute *attr, char *buf)
@@ -469,30 +485,39 @@ static struct attribute *adm9240_attributes[] = {
        &sensor_dev_attr_in0_input.dev_attr.attr,
        &sensor_dev_attr_in0_min.dev_attr.attr,
        &sensor_dev_attr_in0_max.dev_attr.attr,
+       &sensor_dev_attr_in0_alarm.dev_attr.attr,
        &sensor_dev_attr_in1_input.dev_attr.attr,
        &sensor_dev_attr_in1_min.dev_attr.attr,
        &sensor_dev_attr_in1_max.dev_attr.attr,
+       &sensor_dev_attr_in1_alarm.dev_attr.attr,
        &sensor_dev_attr_in2_input.dev_attr.attr,
        &sensor_dev_attr_in2_min.dev_attr.attr,
        &sensor_dev_attr_in2_max.dev_attr.attr,
+       &sensor_dev_attr_in2_alarm.dev_attr.attr,
        &sensor_dev_attr_in3_input.dev_attr.attr,
        &sensor_dev_attr_in3_min.dev_attr.attr,
        &sensor_dev_attr_in3_max.dev_attr.attr,
+       &sensor_dev_attr_in3_alarm.dev_attr.attr,
        &sensor_dev_attr_in4_input.dev_attr.attr,
        &sensor_dev_attr_in4_min.dev_attr.attr,
        &sensor_dev_attr_in4_max.dev_attr.attr,
+       &sensor_dev_attr_in4_alarm.dev_attr.attr,
        &sensor_dev_attr_in5_input.dev_attr.attr,
        &sensor_dev_attr_in5_min.dev_attr.attr,
        &sensor_dev_attr_in5_max.dev_attr.attr,
+       &sensor_dev_attr_in5_alarm.dev_attr.attr,
        &dev_attr_temp1_input.attr,
        &sensor_dev_attr_temp1_max.dev_attr.attr,
        &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
+       &sensor_dev_attr_temp1_alarm.dev_attr.attr,
        &sensor_dev_attr_fan1_input.dev_attr.attr,
        &sensor_dev_attr_fan1_div.dev_attr.attr,
        &sensor_dev_attr_fan1_min.dev_attr.attr,
+       &sensor_dev_attr_fan1_alarm.dev_attr.attr,
        &sensor_dev_attr_fan2_input.dev_attr.attr,
        &sensor_dev_attr_fan2_div.dev_attr.attr,
        &sensor_dev_attr_fan2_min.dev_attr.attr,
+       &sensor_dev_attr_fan2_alarm.dev_attr.attr,
        &dev_attr_alarms.attr,
        &dev_attr_aout_output.attr,
        &dev_attr_chassis_clear.attr,
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
new file mode 100644 (file)
index 0000000..6b8a73e
--- /dev/null
@@ -0,0 +1,297 @@
+/*
+       ads7828.c - lm_sensors driver for ads7828 12-bit 8-channel ADC
+       (C) 2007 EADS Astrium
+
+       This driver is based on the lm75 and other lm_sensors/hwmon drivers
+
+       Written by Steve Hardy <steve@linuxrealtime.co.uk>
+
+       Datasheet available at: http://focus.ti.com/lit/ds/symlink/ads7828.pdf
+
+       This program is free software; you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation; either version 2 of the License, or
+       (at your option) any later version.
+
+       This program is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with this program; if not, write to the Free Software
+       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+
+/* The ADS7828 registers */
+#define ADS7828_NCH 8 /* 8 channels of 12-bit A-D supported */
+#define ADS7828_CMD_SD_SE 0x80 /* Single ended inputs */
+#define ADS7828_CMD_SD_DIFF 0x00 /* Differential inputs */
+#define ADS7828_CMD_PD0 0x0 /* Power Down between A-D conversions */
+#define ADS7828_CMD_PD1 0x04 /* Internal ref OFF && A-D ON */
+#define ADS7828_CMD_PD2 0x08 /* Internal ref ON && A-D OFF */
+#define ADS7828_CMD_PD3 0x0C /* Internal ref ON && A-D ON */
+#define ADS7828_INT_VREF_MV 2500 /* Internal vref is 2.5V, 2500mV */
+
+/* Addresses to scan */
+static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b,
+       I2C_CLIENT_END };
+
+/* Insmod parameters */
+I2C_CLIENT_INSMOD_1(ads7828);
+
+/* Other module parameters */
+static int se_input = 1; /* Default is SE, 0 == diff */
+static int int_vref = 1; /* Default is internal ref ON */
+static int vref_mv = ADS7828_INT_VREF_MV; /* set if vref != 2.5V */
+module_param(se_input, bool, S_IRUGO);
+module_param(int_vref, bool, S_IRUGO);
+module_param(vref_mv, int, S_IRUGO);
+
+/* Global Variables */
+static u8 ads7828_cmd_byte; /* cmd byte without channel bits */
+static unsigned int ads7828_lsb_resol; /* resolution of the ADC sample lsb */
+
+/* Each client has this additional data */
+struct ads7828_data {
+       struct i2c_client client;
+       struct device *hwmon_dev;
+       struct mutex update_lock; /* mutex protect updates */
+       char valid; /* !=0 if following fields are valid */
+       unsigned long last_updated; /* In jiffies */
+       u16 adc_input[ADS7828_NCH]; /* ADS7828_NCH 12-bit samples */
+};
+
+/* Function declaration - necessary due to function dependencies */
+static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind);
+
+/* The ADS7828 returns the 12-bit sample in two bytes,
+       these are read as a word then byte-swapped */
+static u16 ads7828_read_value(struct i2c_client *client, u8 reg)
+{
+       return swab16(i2c_smbus_read_word_data(client, reg));
+}
+
+static inline u8 channel_cmd_byte(int ch)
+{
+       /* cmd byte C2,C1,C0 - see datasheet */
+       u8 cmd = (((ch>>1) | (ch&0x01)<<2)<<4);
+       cmd |= ads7828_cmd_byte;
+       return cmd;
+}
+
+/* Update data for the device (all 8 channels) */
+static struct ads7828_data *ads7828_update_device(struct device *dev)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+       struct ads7828_data *data = i2c_get_clientdata(client);
+
+       mutex_lock(&data->update_lock);
+
+       if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
+                       || !data->valid) {
+               unsigned int ch;
+               dev_dbg(&client->dev, "Starting ads7828 update\n");
+
+               for (ch = 0; ch < ADS7828_NCH; ch++) {
+                       u8 cmd = channel_cmd_byte(ch);
+                       data->adc_input[ch] = ads7828_read_value(client, cmd);
+               }
+               data->last_updated = jiffies;
+               data->valid = 1;
+       }
+
+       mutex_unlock(&data->update_lock);
+
+       return data;
+}
+
+/* sysfs callback function */
+static ssize_t show_in(struct device *dev, struct device_attribute *da,
+       char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
+       struct ads7828_data *data = ads7828_update_device(dev);
+       /* Print value (in mV as specified in sysfs-interface documentation) */
+       return sprintf(buf, "%d\n", (data->adc_input[attr->index] *
+               ads7828_lsb_resol)/1000);
+}
+
+#define in_reg(offset)\
+static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in,\
+       NULL, offset)
+
+in_reg(0);
+in_reg(1);
+in_reg(2);
+in_reg(3);
+in_reg(4);
+in_reg(5);
+in_reg(6);
+in_reg(7);
+
+static struct attribute *ads7828_attributes[] = {
+       &sensor_dev_attr_in0_input.dev_attr.attr,
+       &sensor_dev_attr_in1_input.dev_attr.attr,
+       &sensor_dev_attr_in2_input.dev_attr.attr,
+       &sensor_dev_attr_in3_input.dev_attr.attr,
+       &sensor_dev_attr_in4_input.dev_attr.attr,
+       &sensor_dev_attr_in5_input.dev_attr.attr,
+       &sensor_dev_attr_in6_input.dev_attr.attr,
+       &sensor_dev_attr_in7_input.dev_attr.attr,
+       NULL
+};
+
+static const struct attribute_group ads7828_group = {
+       .attrs = ads7828_attributes,
+};
+
+static int ads7828_attach_adapter(struct i2c_adapter *adapter)
+{
+       if (!(adapter->class & I2C_CLASS_HWMON))
+               return 0;
+       return i2c_probe(adapter, &addr_data, ads7828_detect);
+}
+
+static int ads7828_detach_client(struct i2c_client *client)
+{
+       struct ads7828_data *data = i2c_get_clientdata(client);
+       hwmon_device_unregister(data->hwmon_dev);
+       sysfs_remove_group(&client->dev.kobj, &ads7828_group);
+       i2c_detach_client(client);
+       kfree(i2c_get_clientdata(client));
+       return 0;
+}
+
+/* This is the driver that will be inserted */
+static struct i2c_driver ads7828_driver = {
+       .driver = {
+               .name = "ads7828",
+       },
+       .attach_adapter = ads7828_attach_adapter,
+       .detach_client = ads7828_detach_client,
+};
+
+/* This function is called by i2c_probe */
+static int ads7828_detect(struct i2c_adapter *adapter, int address, int kind)
+{
+       struct i2c_client *client;
+       struct ads7828_data *data;
+       int err = 0;
+       const char *name = "";
+
+       /* Check we have a valid client */
+       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA))
+               goto exit;
+
+       /* OK. For now, we presume we have a valid client. We now create the
+       client structure, even though we cannot fill it completely yet.
+       But it allows us to access ads7828_read_value. */
+       data = kzalloc(sizeof(struct ads7828_data), GFP_KERNEL);
+       if (!data) {
+               err = -ENOMEM;
+               goto exit;
+       }
+
+       client = &data->client;
+       i2c_set_clientdata(client, data);
+       client->addr = address;
+       client->adapter = adapter;
+       client->driver = &ads7828_driver;
+
+       /* Now, we do the remaining detection. There is no identification
+       dedicated register so attempt to sanity check using knowledge of
+       the chip
+       - Read from the 8 channel addresses
+       - Check the top 4 bits of each result are not set (12 data bits)
+       */
+       if (kind < 0) {
+               int ch;
+               for (ch = 0; ch < ADS7828_NCH; ch++) {
+                       u16 in_data;
+                       u8 cmd = channel_cmd_byte(ch);
+                       in_data = ads7828_read_value(client, cmd);
+                       if (in_data & 0xF000) {
+                               printk(KERN_DEBUG
+                               "%s : Doesn't look like an ads7828 device\n",
+                               __FUNCTION__);
+                               goto exit_free;
+                       }
+               }
+       }
+
+       /* Determine the chip type - only one kind supported! */
+       if (kind <= 0)
+               kind = ads7828;
+
+       if (kind == ads7828)
+               name = "ads7828";
+
+       /* Fill in the remaining client fields, put it into the global list */
+       strlcpy(client->name, name, I2C_NAME_SIZE);
+
+       mutex_init(&data->update_lock);
+
+       /* Tell the I2C layer a new client has arrived */
+       err = i2c_attach_client(client);
+       if (err)
+               goto exit_free;
+
+       /* Register sysfs hooks */
+       err = sysfs_create_group(&client->dev.kobj, &ads7828_group);
+       if (err)
+               goto exit_detach;
+
+       data->hwmon_dev = hwmon_device_register(&client->dev);
+       if (IS_ERR(data->hwmon_dev)) {
+               err = PTR_ERR(data->hwmon_dev);
+               goto exit_remove;
+       }
+
+       return 0;
+
+exit_remove:
+       sysfs_remove_group(&client->dev.kobj, &ads7828_group);
+exit_detach:
+       i2c_detach_client(client);
+exit_free:
+       kfree(data);
+exit:
+       return err;
+}
+
+static int __init sensors_ads7828_init(void)
+{
+       /* Initialize the command byte according to module parameters */
+       ads7828_cmd_byte = se_input ?
+               ADS7828_CMD_SD_SE : ADS7828_CMD_SD_DIFF;
+       ads7828_cmd_byte |= int_vref ?
+               ADS7828_CMD_PD3 : ADS7828_CMD_PD1;
+
+       /* Calculate the LSB resolution */
+       ads7828_lsb_resol = (vref_mv*1000)/4096;
+
+       return i2c_add_driver(&ads7828_driver);
+}
+
+static void __exit sensors_ads7828_exit(void)
+{
+       i2c_del_driver(&ads7828_driver);
+}
+
+MODULE_AUTHOR("Steve Hardy <steve@linuxrealtime.co.uk>");
+MODULE_DESCRIPTION("ADS7828 driver");
+MODULE_LICENSE("GPL");
+
+module_init(sensors_ads7828_init);
+module_exit(sensors_ads7828_exit);
index 9810aaa0489d44619e677e6808fc920569a32b64..747693ab2ff110a97fe2a5fd4224fbe47ab879ea 100644 (file)
@@ -48,7 +48,22 @@ I2C_CLIENT_INSMOD_1(adt7470);
 #define ADT7470_REG_CFG                                0x40
 #define                ADT7470_FSPD_MASK               0x04
 #define ADT7470_REG_ALARM1                     0x41
+#define                ADT7470_R1T_ALARM               0x01
+#define                ADT7470_R2T_ALARM               0x02
+#define                ADT7470_R3T_ALARM               0x04
+#define                ADT7470_R4T_ALARM               0x08
+#define                ADT7470_R5T_ALARM               0x10
+#define                ADT7470_R6T_ALARM               0x20
+#define                ADT7470_R7T_ALARM               0x40
+#define                ADT7470_OOL_ALARM               0x80
 #define ADT7470_REG_ALARM2                     0x42
+#define                ADT7470_R8T_ALARM               0x01
+#define                ADT7470_R9T_ALARM               0x02
+#define                ADT7470_R10T_ALARM              0x04
+#define                ADT7470_FAN1_ALARM              0x10
+#define                ADT7470_FAN2_ALARM              0x20
+#define                ADT7470_FAN3_ALARM              0x40
+#define                ADT7470_FAN4_ALARM              0x80
 #define ADT7470_REG_TEMP_LIMITS_BASE_ADDR      0x44
 #define ADT7470_REG_TEMP_LIMITS_MAX_ADDR       0x57
 #define ADT7470_REG_FAN_MIN_BASE_ADDR          0x58
@@ -97,6 +112,8 @@ I2C_CLIENT_INSMOD_1(adt7470);
 #define ADT7470_REG_PWM_AUTO_TEMP(x)   (ADT7470_REG_PWM_AUTO_TEMP_BASE_ADDR + \
                                        ((x) / 2))
 
+#define ALARM2(x)              ((x) << 8)
+
 #define ADT7470_VENDOR         0x41
 #define ADT7470_DEVICE         0x70
 /* datasheet only mentions a revision 2 */
@@ -114,8 +131,6 @@ I2C_CLIENT_INSMOD_1(adt7470);
 /* sleep 1s while gathering temperature data */
 #define TEMP_COLLECTION_TIME   1000
 
-#define power_of_2(x)  (((x) & ((x) - 1)) == 0)
-
 /* datasheet says to divide this number by the fan reading to get fan rpm */
 #define FAN_PERIOD_TO_RPM(x)   ((90000 * 60) / (x))
 #define FAN_RPM_TO_PERIOD      FAN_PERIOD_TO_RPM
@@ -138,7 +153,8 @@ struct adt7470_data {
        u16                     fan[ADT7470_FAN_COUNT];
        u16                     fan_min[ADT7470_FAN_COUNT];
        u16                     fan_max[ADT7470_FAN_COUNT];
-       u16                     alarms, alarms_mask;
+       u16                     alarm;
+       u16                     alarms_mask;
        u8                      force_pwm_max;
        u8                      pwm[ADT7470_PWM_COUNT];
        u8                      pwm_max[ADT7470_PWM_COUNT];
@@ -262,7 +278,10 @@ static struct adt7470_data *adt7470_update_device(struct device *dev)
        else
                data->force_pwm_max = 0;
 
-       data->alarms = adt7470_read_word_data(client, ADT7470_REG_ALARM1);
+       data->alarm = i2c_smbus_read_byte_data(client, ADT7470_REG_ALARM1);
+       if (data->alarm & ADT7470_OOL_ALARM)
+               data->alarm |= ALARM2(i2c_smbus_read_byte_data(client,
+                                                       ADT7470_REG_ALARM2));
        data->alarms_mask = adt7470_read_word_data(client,
                                                   ADT7470_REG_ALARM1_MASK);
 
@@ -370,17 +389,13 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
        return sprintf(buf, "%d\n", 1000 * data->temp[attr->index]);
 }
 
-static ssize_t show_alarms(struct device *dev,
+static ssize_t show_alarm_mask(struct device *dev,
                           struct device_attribute *devattr,
                           char *buf)
 {
-       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
        struct adt7470_data *data = adt7470_update_device(dev);
 
-       if (attr->index)
-               return sprintf(buf, "%x\n", data->alarms);
-       else
-               return sprintf(buf, "%x\n", data->alarms_mask);
+       return sprintf(buf, "%x\n", data->alarms_mask);
 }
 
 static ssize_t show_fan_max(struct device *dev,
@@ -677,7 +692,7 @@ static int cvt_auto_temp(int input)
 {
        if (input == ADT7470_PWM_ALL_TEMPS)
                return 0;
-       if (input < 1 || !power_of_2(input))
+       if (input < 1 || !is_power_of_2(input))
                return -EINVAL;
        return ilog2(input) + 1;
 }
@@ -715,8 +730,20 @@ static ssize_t set_pwm_auto_temp(struct device *dev,
        return count;
 }
 
-static SENSOR_DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL, 0);
-static SENSOR_DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarms, NULL, 1);
+static ssize_t show_alarm(struct device *dev,
+                         struct device_attribute *devattr,
+                         char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct adt7470_data *data = adt7470_update_device(dev);
+
+       if (data->alarm & attr->index)
+               return sprintf(buf, "1\n");
+       else
+               return sprintf(buf, "0\n");
+}
+
+static DEVICE_ATTR(alarm_mask, S_IRUGO, show_alarm_mask, NULL);
 
 static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max,
                    set_temp_max, 0);
@@ -771,6 +798,27 @@ static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO, show_temp, NULL, 7);
 static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO, show_temp, NULL, 8);
 static SENSOR_DEVICE_ATTR(temp10_input, S_IRUGO, show_temp, NULL, 9);
 
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7470_R1T_ALARM);
+static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7470_R2T_ALARM);
+static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7470_R3T_ALARM);
+static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7470_R4T_ALARM);
+static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7470_R5T_ALARM);
+static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7470_R6T_ALARM);
+static SENSOR_DEVICE_ATTR(temp7_alarm, S_IRUGO, show_alarm, NULL,
+                         ADT7470_R7T_ALARM);
+static SENSOR_DEVICE_ATTR(temp8_alarm, S_IRUGO, show_alarm, NULL,
+                         ALARM2(ADT7470_R8T_ALARM));
+static SENSOR_DEVICE_ATTR(temp9_alarm, S_IRUGO, show_alarm, NULL,
+                         ALARM2(ADT7470_R9T_ALARM));
+static SENSOR_DEVICE_ATTR(temp10_alarm, S_IRUGO, show_alarm, NULL,
+                         ALARM2(ADT7470_R10T_ALARM));
+
 static SENSOR_DEVICE_ATTR(fan1_max, S_IWUSR | S_IRUGO, show_fan_max,
                    set_fan_max, 0);
 static SENSOR_DEVICE_ATTR(fan2_max, S_IWUSR | S_IRUGO, show_fan_max,
@@ -794,6 +842,15 @@ static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
 static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
 static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3);
 
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL,
+                         ALARM2(ADT7470_FAN1_ALARM));
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL,
+                         ALARM2(ADT7470_FAN2_ALARM));
+static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL,
+                         ALARM2(ADT7470_FAN3_ALARM));
+static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL,
+                         ALARM2(ADT7470_FAN4_ALARM));
+
 static SENSOR_DEVICE_ATTR(force_pwm_max, S_IWUSR | S_IRUGO,
                    show_force_pwm_max, set_force_pwm_max, 0);
 
@@ -858,8 +915,7 @@ static SENSOR_DEVICE_ATTR(pwm4_auto_channels_temp, S_IWUSR | S_IRUGO,
 
 static struct attribute *adt7470_attr[] =
 {
-       &sensor_dev_attr_alarms.dev_attr.attr,
-       &sensor_dev_attr_alarm_mask.dev_attr.attr,
+       &dev_attr_alarm_mask.attr,
        &sensor_dev_attr_temp1_max.dev_attr.attr,
        &sensor_dev_attr_temp2_max.dev_attr.attr,
        &sensor_dev_attr_temp3_max.dev_attr.attr,
@@ -890,6 +946,16 @@ static struct attribute *adt7470_attr[] =
        &sensor_dev_attr_temp8_input.dev_attr.attr,
        &sensor_dev_attr_temp9_input.dev_attr.attr,
        &sensor_dev_attr_temp10_input.dev_attr.attr,
+       &sensor_dev_attr_temp1_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp2_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp3_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp4_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp5_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp6_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp7_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp8_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp9_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp10_alarm.dev_attr.attr,
        &sensor_dev_attr_fan1_max.dev_attr.attr,
        &sensor_dev_attr_fan2_max.dev_attr.attr,
        &sensor_dev_attr_fan3_max.dev_attr.attr,
@@ -902,6 +968,10 @@ static struct attribute *adt7470_attr[] =
        &sensor_dev_attr_fan2_input.dev_attr.attr,
        &sensor_dev_attr_fan3_input.dev_attr.attr,
        &sensor_dev_attr_fan4_input.dev_attr.attr,
+       &sensor_dev_attr_fan1_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan2_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan3_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan4_alarm.dev_attr.attr,
        &sensor_dev_attr_force_pwm_max.dev_attr.attr,
        &sensor_dev_attr_pwm1.dev_attr.attr,
        &sensor_dev_attr_pwm2.dev_attr.attr,
index 9460dba4cf74ff0bd0dbc1575f516d89d34c7d9d..950cea8d1d650bf4834a1b44564355b4c5005b63 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/slab.h>
 #include <linux/i2c.h>
 #include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
 #include <linux/hwmon-vid.h>
 #include <linux/err.h>
 #include <linux/init.h>
 #include <linux/mutex.h>
 #include "lm75.h"
 
-/*
-       HISTORY:
-       2003-12-29      1.0.0   Ported from lm_sensors project for kernel 2.6
-*/
-#define ASB100_VERSION "1.0.0"
-
 /* I2C addresses to scan */
 static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END };
 
@@ -221,15 +216,16 @@ static struct i2c_driver asb100_driver = {
        .driver = {
                .name   = "asb100",
        },
-       .id             = I2C_DRIVERID_ASB100,
        .attach_adapter = asb100_attach_adapter,
        .detach_client  = asb100_detach_client,
 };
 
 /* 7 Voltages */
 #define show_in_reg(reg) \
-static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
+static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
+               char *buf) \
 { \
+       int nr = to_sensor_dev_attr(attr)->index; \
        struct asb100_data *data = asb100_update_device(dev); \
        return sprintf(buf, "%d\n", IN_FROM_REG(data->reg[nr])); \
 }
@@ -239,9 +235,10 @@ show_in_reg(in_min)
 show_in_reg(in_max)
 
 #define set_in_reg(REG, reg) \
-static ssize_t set_in_##reg(struct device *dev, const char *buf, \
-               size_t count, int nr) \
+static ssize_t set_in_##reg(struct device *dev, struct device_attribute *attr, \
+               const char *buf, size_t count) \
 { \
+       int nr = to_sensor_dev_attr(attr)->index; \
        struct i2c_client *client = to_i2c_client(dev); \
        struct asb100_data *data = i2c_get_clientdata(client); \
        unsigned long val = simple_strtoul(buf, NULL, 10); \
@@ -258,37 +255,12 @@ set_in_reg(MIN, min)
 set_in_reg(MAX, max)
 
 #define sysfs_in(offset) \
-static ssize_t \
-       show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       return show_in(dev, buf, offset); \
-} \
-static DEVICE_ATTR(in##offset##_input, S_IRUGO, \
-               show_in##offset, NULL); \
-static ssize_t \
-       show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       return show_in_min(dev, buf, offset); \
-} \
-static ssize_t \
-       show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       return show_in_max(dev, buf, offset); \
-} \
-static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \
-               const char *buf, size_t count) \
-{ \
-       return set_in_min(dev, buf, count, offset); \
-} \
-static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \
-               const char *buf, size_t count) \
-{ \
-       return set_in_max(dev, buf, count, offset); \
-} \
-static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
-               show_in##offset##_min, set_in##offset##_min); \
-static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
-               show_in##offset##_max, set_in##offset##_max);
+static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
+               show_in, NULL, offset); \
+static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
+               show_in_min, set_in_min, offset); \
+static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
+               show_in_max, set_in_max, offset)
 
 sysfs_in(0);
 sysfs_in(1);
@@ -299,29 +271,36 @@ sysfs_in(5);
 sysfs_in(6);
 
 /* 3 Fans */
-static ssize_t show_fan(struct device *dev, char *buf, int nr)
+static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
+               char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct asb100_data *data = asb100_update_device(dev);
        return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
                DIV_FROM_REG(data->fan_div[nr])));
 }
 
-static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
+static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
+               char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct asb100_data *data = asb100_update_device(dev);
        return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
                DIV_FROM_REG(data->fan_div[nr])));
 }
 
-static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
+static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
+               char *buf)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct asb100_data *data = asb100_update_device(dev);
        return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
 }
 
-static ssize_t set_fan_min(struct device *dev, const char *buf,
-                               size_t count, int nr)
+static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct i2c_client *client = to_i2c_client(dev);
        struct asb100_data *data = i2c_get_clientdata(client);
        u32 val = simple_strtoul(buf, NULL, 10);
@@ -337,22 +316,23 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
    determined in part by the fan divisor.  This follows the principle of
    least surprise; the user doesn't expect the fan minimum to change just
    because the divisor changed. */
-static ssize_t set_fan_div(struct device *dev, const char *buf,
-                               size_t count, int nr)
+static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct i2c_client *client = to_i2c_client(dev);
        struct asb100_data *data = i2c_get_clientdata(client);
        unsigned long min;
        unsigned long val = simple_strtoul(buf, NULL, 10);
        int reg;
-       
+
        mutex_lock(&data->update_lock);
 
        min = FAN_FROM_REG(data->fan_min[nr],
                        DIV_FROM_REG(data->fan_div[nr]));
        data->fan_div[nr] = DIV_TO_REG(val);
 
-       switch(nr) {
+       switch (nr) {
        case 0: /* fan 1 */
                reg = asb100_read_value(client, ASB100_REG_VID_FANDIV);
                reg = (reg & 0xcf) | (data->fan_div[0] << 4);
@@ -382,34 +362,12 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
 }
 
 #define sysfs_fan(offset) \
-static ssize_t show_fan##offset(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       return show_fan(dev, buf, offset - 1); \
-} \
-static ssize_t show_fan##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       return show_fan_min(dev, buf, offset - 1); \
-} \
-static ssize_t show_fan##offset##_div(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       return show_fan_div(dev, buf, offset - 1); \
-} \
-static ssize_t set_fan##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
-                                       size_t count) \
-{ \
-       return set_fan_min(dev, buf, count, offset - 1); \
-} \
-static ssize_t set_fan##offset##_div(struct device *dev, struct device_attribute *attr, const char *buf, \
-                                       size_t count) \
-{ \
-       return set_fan_div(dev, buf, count, offset - 1); \
-} \
-static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
-               show_fan##offset, NULL); \
-static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
-               show_fan##offset##_min, set_fan##offset##_min); \
-static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
-               show_fan##offset##_div, set_fan##offset##_div);
+static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
+               show_fan, NULL, offset - 1); \
+static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
+               show_fan_min, set_fan_min, offset - 1); \
+static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
+               show_fan_div, set_fan_div, offset - 1)
 
 sysfs_fan(1);
 sysfs_fan(2);
@@ -430,10 +388,12 @@ static int sprintf_temp_from_reg(u16 reg, char *buf, int nr)
        }
        return ret;
 }
-                       
+
 #define show_temp_reg(reg) \
-static ssize_t show_##reg(struct device *dev, char *buf, int nr) \
+static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
+               char *buf) \
 { \
+       int nr = to_sensor_dev_attr(attr)->index; \
        struct asb100_data *data = asb100_update_device(dev); \
        return sprintf_temp_from_reg(data->reg[nr], buf, nr); \
 }
@@ -443,9 +403,10 @@ show_temp_reg(temp_max);
 show_temp_reg(temp_hyst);
 
 #define set_temp_reg(REG, reg) \
-static ssize_t set_##reg(struct device *dev, const char *buf, \
-                       size_t count, int nr) \
+static ssize_t set_##reg(struct device *dev, struct device_attribute *attr, \
+               const char *buf, size_t count) \
 { \
+       int nr = to_sensor_dev_attr(attr)->index; \
        struct i2c_client *client = to_i2c_client(dev); \
        struct asb100_data *data = i2c_get_clientdata(client); \
        long val = simple_strtol(buf, NULL, 10); \
@@ -469,33 +430,12 @@ set_temp_reg(MAX, temp_max);
 set_temp_reg(HYST, temp_hyst);
 
 #define sysfs_temp(num) \
-static ssize_t show_temp##num(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       return show_temp(dev, buf, num-1); \
-} \
-static DEVICE_ATTR(temp##num##_input, S_IRUGO, show_temp##num, NULL); \
-static ssize_t show_temp_max##num(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       return show_temp_max(dev, buf, num-1); \
-} \
-static ssize_t set_temp_max##num(struct device *dev, struct device_attribute *attr, const char *buf, \
-                                       size_t count) \
-{ \
-       return set_temp_max(dev, buf, count, num-1); \
-} \
-static DEVICE_ATTR(temp##num##_max, S_IRUGO | S_IWUSR, \
-               show_temp_max##num, set_temp_max##num); \
-static ssize_t show_temp_hyst##num(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       return show_temp_hyst(dev, buf, num-1); \
-} \
-static ssize_t set_temp_hyst##num(struct device *dev, struct device_attribute *attr, const char *buf, \
-                                       size_t count) \
-{ \
-       return set_temp_hyst(dev, buf, count, num-1); \
-} \
-static DEVICE_ATTR(temp##num##_max_hyst, S_IRUGO | S_IWUSR, \
-               show_temp_hyst##num, set_temp_hyst##num);
+static SENSOR_DEVICE_ATTR(temp##num##_input, S_IRUGO, \
+               show_temp, NULL, num - 1); \
+static SENSOR_DEVICE_ATTR(temp##num##_max, S_IRUGO | S_IWUSR, \
+               show_temp_max, set_temp_max, num - 1); \
+static SENSOR_DEVICE_ATTR(temp##num##_max_hyst, S_IRUGO | S_IWUSR, \
+               show_temp_hyst, set_temp_hyst, num - 1)
 
 sysfs_temp(1);
 sysfs_temp(2);
@@ -503,7 +443,8 @@ sysfs_temp(3);
 sysfs_temp(4);
 
 /* VID */
-static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t show_vid(struct device *dev, struct device_attribute *attr,
+               char *buf)
 {
        struct asb100_data *data = asb100_update_device(dev);
        return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm));
@@ -512,25 +453,26 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char
 static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
 
 /* VRM */
-static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
+               char *buf)
 {
        struct asb100_data *data = dev_get_drvdata(dev);
        return sprintf(buf, "%d\n", data->vrm);
 }
 
-static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count)
 {
-       struct i2c_client *client = to_i2c_client(dev);
-       struct asb100_data *data = i2c_get_clientdata(client);
-       unsigned long val = simple_strtoul(buf, NULL, 10);
-       data->vrm = val;
+       struct asb100_data *data = dev_get_drvdata(dev);
+       data->vrm = simple_strtoul(buf, NULL, 10);
        return count;
 }
 
 /* Alarms */
 static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
 
-static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
+               char *buf)
 {
        struct asb100_data *data = asb100_update_device(dev);
        return sprintf(buf, "%u\n", data->alarms);
@@ -538,14 +480,35 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
 
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
 
+static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
+               char *buf)
+{
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       struct asb100_data *data = asb100_update_device(dev);
+       return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
+}
+static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
+static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
+static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11);
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
+static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
+static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13);
+
 /* 1 PWM */
-static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t show_pwm1(struct device *dev, struct device_attribute *attr,
+               char *buf)
 {
        struct asb100_data *data = asb100_update_device(dev);
        return sprintf(buf, "%d\n", ASB100_PWM_FROM_REG(data->pwm & 0x0f));
 }
 
-static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct asb100_data *data = i2c_get_clientdata(client);
@@ -559,14 +522,15 @@ static ssize_t set_pwm1(struct device *dev, struct device_attribute *attr, const
        return count;
 }
 
-static ssize_t show_pwm_enable1(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t show_pwm_enable1(struct device *dev,
+               struct device_attribute *attr, char *buf)
 {
        struct asb100_data *data = asb100_update_device(dev);
        return sprintf(buf, "%d\n", (data->pwm & 0x80) ? 1 : 0);
 }
 
-static ssize_t set_pwm_enable1(struct device *dev, struct device_attribute *attr, const char *buf,
-                               size_t count)
+static ssize_t set_pwm_enable1(struct device *dev,
+               struct device_attribute *attr, const char *buf, size_t count)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct asb100_data *data = i2c_get_clientdata(client);
@@ -585,50 +549,62 @@ static DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
                show_pwm_enable1, set_pwm_enable1);
 
 static struct attribute *asb100_attributes[] = {
-       &dev_attr_in0_input.attr,
-       &dev_attr_in0_min.attr,
-       &dev_attr_in0_max.attr,
-       &dev_attr_in1_input.attr,
-       &dev_attr_in1_min.attr,
-       &dev_attr_in1_max.attr,
-       &dev_attr_in2_input.attr,
-       &dev_attr_in2_min.attr,
-       &dev_attr_in2_max.attr,
-       &dev_attr_in3_input.attr,
-       &dev_attr_in3_min.attr,
-       &dev_attr_in3_max.attr,
-       &dev_attr_in4_input.attr,
-       &dev_attr_in4_min.attr,
-       &dev_attr_in4_max.attr,
-       &dev_attr_in5_input.attr,
-       &dev_attr_in5_min.attr,
-       &dev_attr_in5_max.attr,
-       &dev_attr_in6_input.attr,
-       &dev_attr_in6_min.attr,
-       &dev_attr_in6_max.attr,
-
-       &dev_attr_fan1_input.attr,
-       &dev_attr_fan1_min.attr,
-       &dev_attr_fan1_div.attr,
-       &dev_attr_fan2_input.attr,
-       &dev_attr_fan2_min.attr,
-       &dev_attr_fan2_div.attr,
-       &dev_attr_fan3_input.attr,
-       &dev_attr_fan3_min.attr,
-       &dev_attr_fan3_div.attr,
-
-       &dev_attr_temp1_input.attr,
-       &dev_attr_temp1_max.attr,
-       &dev_attr_temp1_max_hyst.attr,
-       &dev_attr_temp2_input.attr,
-       &dev_attr_temp2_max.attr,
-       &dev_attr_temp2_max_hyst.attr,
-       &dev_attr_temp3_input.attr,
-       &dev_attr_temp3_max.attr,
-       &dev_attr_temp3_max_hyst.attr,
-       &dev_attr_temp4_input.attr,
-       &dev_attr_temp4_max.attr,
-       &dev_attr_temp4_max_hyst.attr,
+       &sensor_dev_attr_in0_input.dev_attr.attr,
+       &sensor_dev_attr_in0_min.dev_attr.attr,
+       &sensor_dev_attr_in0_max.dev_attr.attr,
+       &sensor_dev_attr_in1_input.dev_attr.attr,
+       &sensor_dev_attr_in1_min.dev_attr.attr,
+       &sensor_dev_attr_in1_max.dev_attr.attr,
+       &sensor_dev_attr_in2_input.dev_attr.attr,
+       &sensor_dev_attr_in2_min.dev_attr.attr,
+       &sensor_dev_attr_in2_max.dev_attr.attr,
+       &sensor_dev_attr_in3_input.dev_attr.attr,
+       &sensor_dev_attr_in3_min.dev_attr.attr,
+       &sensor_dev_attr_in3_max.dev_attr.attr,
+       &sensor_dev_attr_in4_input.dev_attr.attr,
+       &sensor_dev_attr_in4_min.dev_attr.attr,
+       &sensor_dev_attr_in4_max.dev_attr.attr,
+       &sensor_dev_attr_in5_input.dev_attr.attr,
+       &sensor_dev_attr_in5_min.dev_attr.attr,
+       &sensor_dev_attr_in5_max.dev_attr.attr,
+       &sensor_dev_attr_in6_input.dev_attr.attr,
+       &sensor_dev_attr_in6_min.dev_attr.attr,
+       &sensor_dev_attr_in6_max.dev_attr.attr,
+
+       &sensor_dev_attr_fan1_input.dev_attr.attr,
+       &sensor_dev_attr_fan1_min.dev_attr.attr,
+       &sensor_dev_attr_fan1_div.dev_attr.attr,
+       &sensor_dev_attr_fan2_input.dev_attr.attr,
+       &sensor_dev_attr_fan2_min.dev_attr.attr,
+       &sensor_dev_attr_fan2_div.dev_attr.attr,
+       &sensor_dev_attr_fan3_input.dev_attr.attr,
+       &sensor_dev_attr_fan3_min.dev_attr.attr,
+       &sensor_dev_attr_fan3_div.dev_attr.attr,
+
+       &sensor_dev_attr_temp1_input.dev_attr.attr,
+       &sensor_dev_attr_temp1_max.dev_attr.attr,
+       &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
+       &sensor_dev_attr_temp2_input.dev_attr.attr,
+       &sensor_dev_attr_temp2_max.dev_attr.attr,
+       &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
+       &sensor_dev_attr_temp3_input.dev_attr.attr,
+       &sensor_dev_attr_temp3_max.dev_attr.attr,
+       &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
+       &sensor_dev_attr_temp4_input.dev_attr.attr,
+       &sensor_dev_attr_temp4_max.dev_attr.attr,
+       &sensor_dev_attr_temp4_max_hyst.dev_attr.attr,
+
+       &sensor_dev_attr_in0_alarm.dev_attr.attr,
+       &sensor_dev_attr_in1_alarm.dev_attr.attr,
+       &sensor_dev_attr_in2_alarm.dev_attr.attr,
+       &sensor_dev_attr_in3_alarm.dev_attr.attr,
+       &sensor_dev_attr_in4_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan1_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan2_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan3_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp2_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp3_alarm.dev_attr.attr,
 
        &dev_attr_cpu0_vid.attr,
        &dev_attr_vrm.attr,
@@ -656,10 +632,10 @@ static int asb100_attach_adapter(struct i2c_adapter *adapter)
 }
 
 static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
-               int kind, struct i2c_client *new_client)
+               int kind, struct i2c_client *client)
 {
        int i, id, err;
-       struct asb100_data *data = i2c_get_clientdata(new_client);
+       struct asb100_data *data = i2c_get_clientdata(client);
 
        data->lm75[0] = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
        if (!(data->lm75[0])) {
@@ -679,26 +655,26 @@ static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
                for (i = 2; i <= 3; i++) {
                        if (force_subclients[i] < 0x48 ||
                            force_subclients[i] > 0x4f) {
-                               dev_err(&new_client->dev, "invalid subclient "
+                               dev_err(&client->dev, "invalid subclient "
                                        "address %d; must be 0x48-0x4f\n",
                                        force_subclients[i]);
                                err = -ENODEV;
                                goto ERROR_SC_2;
                        }
                }
-               asb100_write_value(new_client, ASB100_REG_I2C_SUBADDR,
+               asb100_write_value(client, ASB100_REG_I2C_SUBADDR,
                                        (force_subclients[2] & 0x07) |
-                                       ((force_subclients[3] & 0x07) <<4));
+                                       ((force_subclients[3] & 0x07) << 4));
                data->lm75[0]->addr = force_subclients[2];
                data->lm75[1]->addr = force_subclients[3];
        } else {
-               int val = asb100_read_value(new_client, ASB100_REG_I2C_SUBADDR);
+               int val = asb100_read_value(client, ASB100_REG_I2C_SUBADDR);
                data->lm75[0]->addr = 0x48 + (val & 0x07);
                data->lm75[1]->addr = 0x48 + ((val >> 4) & 0x07);
        }
 
-       if(data->lm75[0]->addr == data->lm75[1]->addr) {
-               dev_err(&new_client->dev, "duplicate addresses 0x%x "
+       if (data->lm75[0]->addr == data->lm75[1]->addr) {
+               dev_err(&client->dev, "duplicate addresses 0x%x "
                                "for subclients\n", data->lm75[0]->addr);
                err = -ENODEV;
                goto ERROR_SC_2;
@@ -708,18 +684,17 @@ static int asb100_detect_subclients(struct i2c_adapter *adapter, int address,
                i2c_set_clientdata(data->lm75[i], NULL);
                data->lm75[i]->adapter = adapter;
                data->lm75[i]->driver = &asb100_driver;
-               data->lm75[i]->flags = 0;
                strlcpy(data->lm75[i]->name, "asb100 subclient", I2C_NAME_SIZE);
        }
 
        if ((err = i2c_attach_client(data->lm75[0]))) {
-               dev_err(&new_client->dev, "subclient %d registration "
+               dev_err(&client->dev, "subclient %d registration "
                        "at address 0x%x failed.\n", i, data->lm75[0]->addr);
                goto ERROR_SC_2;
        }
 
        if ((err = i2c_attach_client(data->lm75[1]))) {
-               dev_err(&new_client->dev, "subclient %d registration "
+               dev_err(&client->dev, "subclient %d registration "
                        "at address 0x%x failed.\n", i, data->lm75[1]->addr);
                goto ERROR_SC_3;
        }
@@ -740,7 +715,7 @@ ERROR_SC_0:
 static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
 {
        int err;
-       struct i2c_client *new_client;
+       struct i2c_client *client;
        struct asb100_data *data;
 
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
@@ -760,13 +735,12 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
                goto ERROR0;
        }
 
-       new_client = &data->client;
+       client = &data->client;
        mutex_init(&data->lock);
-       i2c_set_clientdata(new_client, data);
-       new_client->addr = address;
-       new_client->adapter = adapter;
-       new_client->driver = &asb100_driver;
-       new_client->flags = 0;
+       i2c_set_clientdata(client, data);
+       client->addr = address;
+       client->adapter = adapter;
+       client->driver = &asb100_driver;
 
        /* Now, we do the remaining detection. */
 
@@ -776,15 +750,15 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
           bank. */
        if (kind < 0) {
 
-               int val1 = asb100_read_value(new_client, ASB100_REG_BANK);
-               int val2 = asb100_read_value(new_client, ASB100_REG_CHIPMAN);
+               int val1 = asb100_read_value(client, ASB100_REG_BANK);
+               int val2 = asb100_read_value(client, ASB100_REG_CHIPMAN);
 
                /* If we're in bank 0 */
-               if ( (!(val1 & 0x07)) &&
+               if ((!(val1 & 0x07)) &&
                                /* Check for ASB100 ID (low byte) */
-                               ( ((!(val1 & 0x80)) && (val2 != 0x94)) ||
+                               (((!(val1 & 0x80)) && (val2 != 0x94)) ||
                                /* Check for ASB100 ID (high byte ) */
-                               ((val1 & 0x80) && (val2 != 0x06)) ) ) {
+                               ((val1 & 0x80) && (val2 != 0x06)))) {
                        pr_debug("asb100.o: detect failed, "
                                        "bad chip id 0x%02x!\n", val2);
                        err = -ENODEV;
@@ -795,19 +769,19 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
 
        /* We have either had a force parameter, or we have already detected
           Winbond. Put it now into bank 0 and Vendor ID High Byte */
-       asb100_write_value(new_client, ASB100_REG_BANK,
-               (asb100_read_value(new_client, ASB100_REG_BANK) & 0x78) | 0x80);
+       asb100_write_value(client, ASB100_REG_BANK,
+               (asb100_read_value(client, ASB100_REG_BANK) & 0x78) | 0x80);
 
        /* Determine the chip type. */
        if (kind <= 0) {
-               int val1 = asb100_read_value(new_client, ASB100_REG_WCHIPID);
-               int val2 = asb100_read_value(new_client, ASB100_REG_CHIPMAN);
+               int val1 = asb100_read_value(client, ASB100_REG_WCHIPID);
+               int val2 = asb100_read_value(client, ASB100_REG_CHIPMAN);
 
                if ((val1 == 0x31) && (val2 == 0x06))
                        kind = asb100;
                else {
                        if (kind == 0)
-                               dev_warn(&new_client->dev, "ignoring "
+                               dev_warn(&client->dev, "ignoring "
                                        "'force' parameter for unknown chip "
                                        "at adapter %d, address 0x%02x.\n",
                                        i2c_adapter_id(adapter), address);
@@ -817,34 +791,32 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
        }
 
        /* Fill in remaining client fields and put it into the global list */
-       strlcpy(new_client->name, "asb100", I2C_NAME_SIZE);
+       strlcpy(client->name, "asb100", I2C_NAME_SIZE);
        data->type = kind;
-
-       data->valid = 0;
        mutex_init(&data->update_lock);
 
        /* Tell the I2C layer a new client has arrived */
-       if ((err = i2c_attach_client(new_client)))
+       if ((err = i2c_attach_client(client)))
                goto ERROR1;
 
        /* Attach secondary lm75 clients */
        if ((err = asb100_detect_subclients(adapter, address, kind,
-                       new_client)))
+                       client)))
                goto ERROR2;
 
        /* Initialize the chip */
-       asb100_init_client(new_client);
+       asb100_init_client(client);
 
        /* A few vars need to be filled upon startup */
-       data->fan_min[0] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(0));
-       data->fan_min[1] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(1));
-       data->fan_min[2] = asb100_read_value(new_client, ASB100_REG_FAN_MIN(2));
+       data->fan_min[0] = asb100_read_value(client, ASB100_REG_FAN_MIN(0));
+       data->fan_min[1] = asb100_read_value(client, ASB100_REG_FAN_MIN(1));
+       data->fan_min[2] = asb100_read_value(client, ASB100_REG_FAN_MIN(2));
 
        /* Register sysfs hooks */
-       if ((err = sysfs_create_group(&new_client->dev.kobj, &asb100_group)))
+       if ((err = sysfs_create_group(&client->dev.kobj, &asb100_group)))
                goto ERROR3;
 
-       data->hwmon_dev = hwmon_device_register(&new_client->dev);
+       data->hwmon_dev = hwmon_device_register(&client->dev);
        if (IS_ERR(data->hwmon_dev)) {
                err = PTR_ERR(data->hwmon_dev);
                goto ERROR4;
@@ -853,14 +825,14 @@ static int asb100_detect(struct i2c_adapter *adapter, int address, int kind)
        return 0;
 
 ERROR4:
-       sysfs_remove_group(&new_client->dev.kobj, &asb100_group);
+       sysfs_remove_group(&client->dev.kobj, &asb100_group);
 ERROR3:
        i2c_detach_client(data->lm75[1]);
        i2c_detach_client(data->lm75[0]);
        kfree(data->lm75[1]);
        kfree(data->lm75[0]);
 ERROR2:
-       i2c_detach_client(new_client);
+       i2c_detach_client(client);
 ERROR1:
        kfree(data);
 ERROR0:
@@ -916,17 +888,17 @@ static int asb100_read_value(struct i2c_client *client, u16 reg)
                /* convert from ISA to LM75 I2C addresses */
                switch (reg & 0xff) {
                case 0x50: /* TEMP */
-                       res = swab16(i2c_smbus_read_word_data (cl, 0));
+                       res = swab16(i2c_smbus_read_word_data(cl, 0));
                        break;
                case 0x52: /* CONFIG */
                        res = i2c_smbus_read_byte_data(cl, 1);
                        break;
                case 0x53: /* HYST */
-                       res = swab16(i2c_smbus_read_word_data (cl, 2));
+                       res = swab16(i2c_smbus_read_word_data(cl, 2));
                        break;
                case 0x55: /* MAX */
                default:
-                       res = swab16(i2c_smbus_read_word_data (cl, 3));
+                       res = swab16(i2c_smbus_read_word_data(cl, 3));
                        break;
                }
        }
@@ -989,7 +961,7 @@ static void asb100_init_client(struct i2c_client *client)
        vid = vid_from_reg(vid, data->vrm);
 
        /* Start monitoring */
-       asb100_write_value(client, ASB100_REG_CONFIG, 
+       asb100_write_value(client, ASB100_REG_CONFIG,
                (asb100_read_value(client, ASB100_REG_CONFIG) & 0xf7) | 0x01);
 }
 
@@ -1078,4 +1050,3 @@ MODULE_LICENSE("GPL");
 
 module_init(asb100_init);
 module_exit(asb100_exit);
-
index a878c98e252e5a13f5f87d4ec840eb8b40251f25..ddddd9f34c1955769017cc107d7e5e2678686604 100644 (file)
@@ -44,6 +44,10 @@ static int force_start;
 module_param(force_start, bool, 0);
 MODULE_PARM_DESC(force_start, "Force the chip to start monitoring inputs");
 
+static unsigned short force_id;
+module_param(force_id, ushort, 0);
+MODULE_PARM_DESC(force_id, "Override the detected device ID");
+
 /* Addresses to scan */
 static unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END};
 
@@ -279,14 +283,21 @@ static inline int TEMP_HYST_TO_REG(int val, int ix, int reg)
 /* Fan input RPM */
 static inline int FAN_FROM_REG(int reg, int tpc)
 {
-       return (reg == 0 || reg == 0xffff) ? 0 :
-               (tpc == 0) ? 90000 * 60 / reg : tpc * reg;
+       if (tpc) {
+               return tpc * reg;
+       } else {
+               return (reg == 0 || reg == 0xffff) ? 0 : 90000 * 60 / reg;
+       }
 }
 
 static inline int FAN_TO_REG(int val, int tpc)
 {
-       return SENSORS_LIMIT((tpc == 0) ? 90000 * 60 / val : val / tpc,
-                            0, 0xffff);
+       if (tpc) {
+               return SENSORS_LIMIT(val / tpc, 0, 0xffff);
+       } else {
+               return (val <= 0) ? 0xffff :
+                       SENSORS_LIMIT(90000 * 60 / val, 0, 0xfffe);
+       }
 }
 
 /* Fan TPC (tach pulse count)
@@ -2019,7 +2030,7 @@ static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data)
 
        /* Check device ID
         * The DME1737 can return either 0x78 or 0x77 as its device ID. */
-       reg = dme1737_sio_inb(sio_cip, 0x20);
+       reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20);
        if (!(reg == 0x77 || reg == 0x78)) {
                err = -ENODEV;
                goto exit;
@@ -2191,7 +2202,7 @@ static int __init dme1737_isa_detect(int sio_cip, unsigned short *addr)
        /* Check device ID
         * We currently know about SCH3112 (0x7c), SCH3114 (0x7d), and
         * SCH3116 (0x7f). */
-       reg = dme1737_sio_inb(sio_cip, 0x20);
+       reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20);
        if (!(reg == 0x7c || reg == 0x7d || reg == 0x7f)) {
                err = -ENODEV;
                goto exit;
index b7bd000b130f4a76e2316f3036ec4817fc55437f..3f5163de13c1b9f0db29c7a98d7c2f19f7c65559 100644 (file)
@@ -94,7 +94,6 @@ static struct i2c_driver ds1621_driver = {
        .driver = {
                .name   = "ds1621",
        },
-       .id             = I2C_DRIVERID_DS1621,
        .attach_adapter = ds1621_attach_adapter,
        .detach_client  = ds1621_detach_client,
 };
index 5d9d5cc816a24d1a2e871deb5da53bf59d950f3d..7a14a2dbb752e8835fcc652f97d9f57277f53783 100644 (file)
 #include <linux/ioport.h>
 #include <asm/io.h>
 
+static unsigned short force_id;
+module_param(force_id, ushort, 0);
+MODULE_PARM_DESC(force_id, "Override the detected device ID");
+
 static struct platform_device *pdev;
 
 #define DRVNAME "f71805f"
@@ -1497,7 +1501,7 @@ static int __init f71805f_find(int sioaddr, unsigned short *address,
        if (devid != SIO_FINTEK_ID)
                goto exit;
 
-       devid = superio_inw(sioaddr, SIO_REG_DEVID);
+       devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
        switch (devid) {
        case SIO_F71805F_ID:
                sio_data->kind = f71805f;
index 6db74434a02e98ecb00d1067c2236b23863ad9f5..cbeb4984b5c7177e2c8fc90c8f22afe85cf30e64 100644 (file)
 
 #define FAN_MIN_DETECT                 366 /* Lowest detectable fanspeed */
 
+static unsigned short force_id;
+module_param(force_id, ushort, 0);
+MODULE_PARM_DESC(force_id, "Override the detected device ID");
+
 static struct platform_device *f71882fg_pdev = NULL;
 
 /* Super-I/O Function prototypes */
@@ -843,7 +847,7 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address)
                goto exit;
        }
 
-       devid = superio_inw(sioaddr, SIO_REG_DEVID);
+       devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
        if (devid != SIO_F71882_ID) {
                printk(KERN_INFO DRVNAME ": Unsupported Fintek device\n");
                goto exit;
index e67c36953b2d8d2f46c9af5825be753f16da1855..721c70177b17c71c967d4d4d3fc5108b978e046e 100644 (file)
@@ -123,7 +123,6 @@ static struct i2c_driver fscher_driver = {
        .driver = {
                .name   = "fscher",
        },
-       .id             = I2C_DRIVERID_FSCHER,
        .attach_adapter = fscher_attach_adapter,
        .detach_client  = fscher_detach_client,
 };
index 63a4df0580db78f44fb030056336b699155508a4..b7c9eef0f9283fe0d77c3b19086dcf8462302d0c 100644 (file)
@@ -41,6 +41,7 @@
 #include <linux/err.h>
 #include <linux/mutex.h>
 #include <linux/sysfs.h>
+#include <linux/dmi.h>
 
 /* Addresses to scan */
 static unsigned short normal_i2c[] = { 0x73, I2C_CLIENT_END };
@@ -133,7 +134,7 @@ static const u8 FSCHMD_REG_TEMP_STATE[5][5] = {
        { 0x71, 0x81, 0x91 },                           /* her */
        { 0x71, 0xd1, 0x81, 0x91 },                     /* scy */
        { 0x71, 0x81, 0x91 },                           /* hrc */
-       { 0x71, 0x81, 0x91, 0xd1, 0xe1 },               /* hmd */
+       { 0x71, 0x81, 0x91, 0xd1, 0xe1 },               /* hmd */
 };
 
 /* temperature high limit registers, FSC does not document these. Proven to be
@@ -146,7 +147,7 @@ static const u8 FSCHMD_REG_TEMP_LIMIT[5][5] = {
        { 0x76, 0x86, 0x96 },                           /* her */
        { 0x76, 0xd6, 0x86, 0x96 },                     /* scy */
        { 0x76, 0x86, 0x96 },                           /* hrc */
-       { 0x76, 0x86, 0x96, 0xd6, 0xe6 },               /* hmd */
+       { 0x76, 0x86, 0x96, 0xd6, 0xe6 },               /* hmd */
 };
 
 /* These were found through experimenting with an fscher, currently they are
@@ -210,6 +211,13 @@ struct fschmd_data {
        u8 fan_ripple[6];       /* divider for rps */
 };
 
+/* Global variables to hold information read from special DMI tables, which are
+   available on FSC machines with an fscher or later chip. */
+static int dmi_mult[3] = { 490, 200, 100 };
+static int dmi_offset[3] = { 0, 0, 0 };
+static int dmi_vref = -1;
+
+
 /*
  * Sysfs attr show / store functions
  */
@@ -221,8 +229,13 @@ static ssize_t show_in_value(struct device *dev,
        int index = to_sensor_dev_attr(devattr)->index;
        struct fschmd_data *data = fschmd_update_device(dev);
 
-       return sprintf(buf, "%d\n", (data->volt[index] *
-               max_reading[index] + 128) / 255);
+       /* fscher / fschrc - 1 as data->kind is an array index, not a chips */
+       if (data->kind == (fscher - 1) || data->kind >= (fschrc - 1))
+               return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref *
+                       dmi_mult[index]) / 255 + dmi_offset[index]);
+       else
+               return sprintf(buf, "%d\n", (data->volt[index] *
+                       max_reading[index] + 128) / 255);
 }
 
 
@@ -525,6 +538,68 @@ static struct sensor_device_attribute fschmd_fan_attr[] = {
  * Real code
  */
 
+/* DMI decode routine to read voltage scaling factors from special DMI tables,
+   which are available on FSC machines with an fscher or later chip. */
+static void fschmd_dmi_decode(const struct dmi_header *header)
+{
+       int i, mult[3] = { 0 }, offset[3] = { 0 }, vref = 0, found = 0;
+
+       /* dmi code ugliness, we get passed the address of the contents of
+          a complete DMI record, but in the form of a dmi_header pointer, in
+          reality this address holds header->length bytes of which the header
+          are the first 4 bytes */
+       u8 *dmi_data = (u8 *)header;
+
+       /* We are looking for OEM-specific type 185 */
+       if (header->type != 185)
+               return;
+
+       /* we are looking for what Siemens calls "subtype" 19, the subtype
+          is stored in byte 5 of the dmi block */
+       if (header->length < 5 || dmi_data[4] != 19)
+               return;
+
+       /* After the subtype comes 1 unknown byte and then blocks of 5 bytes,
+          consisting of what Siemens calls an "Entity" number, followed by
+          2 16-bit words in LSB first order */
+       for (i = 6; (i + 4) < header->length; i += 5) {
+               /* entity 1 - 3: voltage multiplier and offset */
+               if (dmi_data[i] >= 1 && dmi_data[i] <= 3) {
+                       /* Our in sensors order and the DMI order differ */
+                       const int shuffle[3] = { 1, 0, 2 };
+                       int in = shuffle[dmi_data[i] - 1];
+
+                       /* Check for twice the same entity */
+                       if (found & (1 << in))
+                               return;
+
+                       mult[in] = dmi_data[i + 1] | (dmi_data[i + 2] << 8);
+                       offset[in] = dmi_data[i + 3] | (dmi_data[i + 4] << 8);
+
+                       found |= 1 << in;
+               }
+
+               /* entity 7: reference voltage */
+               if (dmi_data[i] == 7) {
+                       /* Check for twice the same entity */
+                       if (found & 0x08)
+                               return;
+
+                       vref = dmi_data[i + 1] | (dmi_data[i + 2] << 8);
+
+                       found |= 0x08;
+               }
+       }
+
+       if (found == 0x0F) {
+               for (i = 0; i < 3; i++) {
+                       dmi_mult[i] = mult[i] * 10;
+                       dmi_offset[i] = offset[i] * 10;
+               }
+               dmi_vref = vref;
+       }
+}
+
 static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind)
 {
        struct i2c_client *client;
@@ -586,6 +661,17 @@ static int fschmd_detect(struct i2c_adapter *adapter, int address, int kind)
                data->temp_max[2] = 50 + 128;
        }
 
+       /* Read the special DMI table for fscher and newer chips */
+       if (kind == fscher || kind >= fschrc) {
+               dmi_walk(fschmd_dmi_decode);
+               if (dmi_vref == -1) {
+                       printk(KERN_WARNING FSCHMD_NAME
+                               ": Couldn't get voltage scaling factors from "
+                               "BIOS DMI table, using builtin defaults\n");
+                       dmi_vref = 33;
+               }
+       }
+
        /* i2c kind goes from 1-5, we want from 0-4 to address arrays */
        data->kind = kind - 1;
        strlcpy(client->name, client_names[data->kind], I2C_NAME_SIZE);
index 92c9703d0ac0d16ee0d576f796f626a4fac170c3..2f1075323a1e2f6b976f9077bb566e03f2d0e788 100644 (file)
@@ -105,7 +105,6 @@ static struct i2c_driver fscpos_driver = {
        .driver = {
                .name   = "fscpos",
        },
-       .id             = I2C_DRIVERID_FSCPOS,
        .attach_adapter = fscpos_attach_adapter,
        .detach_client  = fscpos_detach_client,
 };
index bb58d9866a3774b996481b224f8ec7e81075b5ba..3b1ac48fce230795b257a4a9ef8228af80581d19 100644 (file)
  * We did not keep that part of the original driver in the Linux 2.6
  * version, since it was making the driver significantly more complex
  * with no real benefit.
- *
- * History:
- * 2004-01-28  Original port. (Hong-Gunn Chew)
- * 2004-01-31  Code review and approval. (Jean Delvare)
  */
 
 #include <linux/module.h>
@@ -42,6 +38,7 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
 #include <linux/err.h>
 #include <linux/mutex.h>
 #include <linux/sysfs.h>
@@ -99,10 +96,10 @@ static inline u8 FAN_TO_REG(long rpm, int div)
        long rpmdiv;
        if (rpm == 0)
                return 0;
-       rpmdiv = SENSORS_LIMIT(rpm, 1, 1920000) * div;
-       return SENSORS_LIMIT((960000 + rpmdiv / 2) / rpmdiv, 1, 255);
+       rpmdiv = SENSORS_LIMIT(rpm, 1, 960000) * div;
+       return SENSORS_LIMIT((480000 + rpmdiv / 2) / rpmdiv, 1, 255);
 }
-#define FAN_FROM_REG(val,div)  ((val)==0 ? 0 : (960000/((val)*(div))))
+#define FAN_FROM_REG(val,div)  ((val)==0 ? 0 : (480000/((val)*(div))))
 
 #define IN_TO_REG(val)         (SENSORS_LIMIT((((val)+9)/19),0,255))
 #define IN_FROM_REG(val)       ((val)*19)
@@ -110,7 +107,6 @@ static inline u8 FAN_TO_REG(long rpm, int div)
 #define VDD_TO_REG(val)                (SENSORS_LIMIT((((val)*4+47)/95),0,255))
 #define VDD_FROM_REG(val)      (((val)*95+2)/4)
 
-#define DIV_TO_REG(val)                ((val)==4?2:(val)==2?1:(val)==1?0:3)
 #define DIV_FROM_REG(val)      (1 << (val))
 
 #define BEEP_MASK_TO_REG(val)  ((val) & 0x7f & data->alarm_mask)
@@ -129,7 +125,6 @@ struct gl518_data {
        u8 voltage_in[4];       /* Register values; [0] = VDD */
        u8 voltage_min[4];      /* Register values; [0] = VDD */
        u8 voltage_max[4];      /* Register values; [0] = VDD */
-       u8 iter_voltage_in[4];  /* Register values; [0] = VDD */
        u8 fan_in[2];
        u8 fan_min[2];
        u8 fan_div[2];          /* Register encoding, shifted right */
@@ -138,7 +133,7 @@ struct gl518_data {
        u8 temp_max;            /* Register values */
        u8 temp_hyst;           /* Register values */
        u8 alarms;              /* Register value */
-       u8 alarm_mask;          /* Register value */
+       u8 alarm_mask;
        u8 beep_mask;           /* Register value */
        u8 beep_enable;         /* Boolean */
 };
@@ -156,7 +151,6 @@ static struct i2c_driver gl518_driver = {
        .driver = {
                .name   = "gl518sm",
        },
-       .id             = I2C_DRIVERID_GL518,
        .attach_adapter = gl518_attach_adapter,
        .detach_client  = gl518_detach_client,
 };
@@ -172,24 +166,10 @@ static ssize_t show_##suffix(struct device *dev, struct device_attribute *attr,
        return sprintf(buf, "%d\n", type##_FROM_REG(data->value));      \
 }
 
-#define show_fan(suffix, value, index)                                 \
-static ssize_t show_##suffix(struct device *dev, struct device_attribute *attr, char *buf)             \
-{                                                                      \
-       struct gl518_data *data = gl518_update_device(dev);             \
-       return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[index],    \
-               DIV_FROM_REG(data->fan_div[index])));                   \
-}
-
 show(TEMP, temp_input1, temp_in);
 show(TEMP, temp_max1, temp_max);
 show(TEMP, temp_hyst1, temp_hyst);
 show(BOOL, fan_auto1, fan_auto1);
-show_fan(fan_input1, fan_in, 0);
-show_fan(fan_input2, fan_in, 1);
-show_fan(fan_min1, fan_min, 0);
-show_fan(fan_min2, fan_min, 1);
-show(DIV, fan_div1, fan_div[0]);
-show(DIV, fan_div2, fan_div[1]);
 show(VDD, in_input0, voltage_in[0]);
 show(IN, in_input1, voltage_in[1]);
 show(IN, in_input2, voltage_in[2]);
@@ -206,6 +186,32 @@ show(RAW, alarms, alarms);
 show(BOOL, beep_enable, beep_enable);
 show(BEEP_MASK, beep_mask, beep_mask);
 
+static ssize_t show_fan_input(struct device *dev,
+                             struct device_attribute *attr, char *buf)
+{
+       int nr = to_sensor_dev_attr(attr)->index;
+       struct gl518_data *data = gl518_update_device(dev);
+       return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_in[nr],
+                                       DIV_FROM_REG(data->fan_div[nr])));
+}
+
+static ssize_t show_fan_min(struct device *dev,
+                           struct device_attribute *attr, char *buf)
+{
+       int nr = to_sensor_dev_attr(attr)->index;
+       struct gl518_data *data = gl518_update_device(dev);
+       return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
+                                       DIV_FROM_REG(data->fan_div[nr])));
+}
+
+static ssize_t show_fan_div(struct device *dev,
+                           struct device_attribute *attr, char *buf)
+{
+       int nr = to_sensor_dev_attr(attr)->index;
+       struct gl518_data *data = gl518_update_device(dev);
+       return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
+}
+
 #define set(type, suffix, value, reg)                                  \
 static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, const char *buf,        \
        size_t count)                                                   \
@@ -247,8 +253,6 @@ static ssize_t set_##suffix(struct device *dev, struct device_attribute *attr, c
 set(TEMP, temp_max1, temp_max, GL518_REG_TEMP_MAX);
 set(TEMP, temp_hyst1, temp_hyst, GL518_REG_TEMP_HYST);
 set_bits(BOOL, fan_auto1, fan_auto1, GL518_REG_MISC, 0x08, 3);
-set_bits(DIV, fan_div1, fan_div[0], GL518_REG_MISC, 0xc0, 6);
-set_bits(DIV, fan_div2, fan_div[1], GL518_REG_MISC, 0x30, 4);
 set_low(VDD, in_min0, voltage_min[0], GL518_REG_VDD_LIMIT);
 set_low(IN, in_min1, voltage_min[1], GL518_REG_VIN1_LIMIT);
 set_low(IN, in_min2, voltage_min[2], GL518_REG_VIN2_LIMIT);
@@ -260,25 +264,27 @@ set_high(IN, in_max3, voltage_max[3], GL518_REG_VIN3_LIMIT);
 set_bits(BOOL, beep_enable, beep_enable, GL518_REG_CONF, 0x04, 2);
 set(BEEP_MASK, beep_mask, beep_mask, GL518_REG_ALARM);
 
-static ssize_t set_fan_min1(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
+                          const char *buf, size_t count)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct gl518_data *data = i2c_get_clientdata(client);
+       int nr = to_sensor_dev_attr(attr)->index;
        int regvalue;
        unsigned long val = simple_strtoul(buf, NULL, 10);
 
        mutex_lock(&data->update_lock);
        regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT);
-       data->fan_min[0] = FAN_TO_REG(val,
-               DIV_FROM_REG(data->fan_div[0]));
-       regvalue = (regvalue & 0x00ff) | (data->fan_min[0] << 8);
+       data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
+       regvalue = (regvalue & (0xff << (8 * nr)))
+                | (data->fan_min[nr] << (8 * (1 - nr)));
        gl518_write_value(client, GL518_REG_FAN_LIMIT, regvalue);
 
        data->beep_mask = gl518_read_value(client, GL518_REG_ALARM);
-       if (data->fan_min[0] == 0)
-               data->alarm_mask &= ~0x20;
+       if (data->fan_min[nr] == 0)
+               data->alarm_mask &= ~(0x20 << nr);
        else
-               data->alarm_mask |= 0x20;
+               data->alarm_mask |= (0x20 << nr);
        data->beep_mask &= data->alarm_mask;
        gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
 
@@ -286,28 +292,32 @@ static ssize_t set_fan_min1(struct device *dev, struct device_attribute *attr, c
        return count;
 }
 
-static ssize_t set_fan_min2(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
+                          const char *buf, size_t count)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct gl518_data *data = i2c_get_clientdata(client);
+       int nr = to_sensor_dev_attr(attr)->index;
        int regvalue;
        unsigned long val = simple_strtoul(buf, NULL, 10);
 
-       mutex_lock(&data->update_lock);
-       regvalue = gl518_read_value(client, GL518_REG_FAN_LIMIT);
-       data->fan_min[1] = FAN_TO_REG(val,
-               DIV_FROM_REG(data->fan_div[1]));
-       regvalue = (regvalue & 0xff00) | data->fan_min[1];
-       gl518_write_value(client, GL518_REG_FAN_LIMIT, regvalue);
-
-       data->beep_mask = gl518_read_value(client, GL518_REG_ALARM);
-       if (data->fan_min[1] == 0)
-               data->alarm_mask &= ~0x40;
-       else
-               data->alarm_mask |= 0x40;
-       data->beep_mask &= data->alarm_mask;
-       gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
+       switch (val) {
+       case 1: val = 0; break;
+       case 2: val = 1; break;
+       case 4: val = 2; break;
+       case 8: val = 3; break;
+       default:
+               dev_err(dev, "Invalid fan clock divider %lu, choose one "
+                       "of 1, 2, 4 or 8\n", val);
+               return -EINVAL;
+       }
 
+       mutex_lock(&data->update_lock);
+       regvalue = gl518_read_value(client, GL518_REG_MISC);
+       data->fan_div[nr] = val;
+       regvalue = (regvalue & ~(0xc0 >> (2 * nr)))
+                | (data->fan_div[nr] << (6 - 2 * nr));
+       gl518_write_value(client, GL518_REG_MISC, regvalue);
        mutex_unlock(&data->update_lock);
        return count;
 }
@@ -317,12 +327,16 @@ static DEVICE_ATTR(temp1_max, S_IWUSR|S_IRUGO, show_temp_max1, set_temp_max1);
 static DEVICE_ATTR(temp1_max_hyst, S_IWUSR|S_IRUGO,
        show_temp_hyst1, set_temp_hyst1);
 static DEVICE_ATTR(fan1_auto, S_IWUSR|S_IRUGO, show_fan_auto1, set_fan_auto1);
-static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input1, NULL);
-static DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input2, NULL);
-static DEVICE_ATTR(fan1_min, S_IWUSR|S_IRUGO, show_fan_min1, set_fan_min1);
-static DEVICE_ATTR(fan2_min, S_IWUSR|S_IRUGO, show_fan_min2, set_fan_min2);
-static DEVICE_ATTR(fan1_div, S_IWUSR|S_IRUGO, show_fan_div1, set_fan_div1);
-static DEVICE_ATTR(fan2_div, S_IWUSR|S_IRUGO, show_fan_div2, set_fan_div2);
+static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0);
+static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1);
+static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR|S_IRUGO,
+       show_fan_min, set_fan_min, 0);
+static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR|S_IRUGO,
+       show_fan_min, set_fan_min, 1);
+static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR|S_IRUGO,
+       show_fan_div, set_fan_div, 0);
+static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR|S_IRUGO,
+       show_fan_div, set_fan_div, 1);
 static DEVICE_ATTR(in0_input, S_IRUGO, show_in_input0, NULL);
 static DEVICE_ATTR(in1_input, S_IRUGO, show_in_input1, NULL);
 static DEVICE_ATTR(in2_input, S_IRUGO, show_in_input2, NULL);
@@ -341,10 +355,62 @@ static DEVICE_ATTR(beep_enable, S_IWUSR|S_IRUGO,
 static DEVICE_ATTR(beep_mask, S_IWUSR|S_IRUGO,
        show_beep_mask, set_beep_mask);
 
+static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
+                         char *buf)
+{
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       struct gl518_data *data = gl518_update_device(dev);
+       return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
+}
+
+static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 5);
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 6);
+
+static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
+                         char *buf)
+{
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       struct gl518_data *data = gl518_update_device(dev);
+       return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
+}
+
+static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
+                       const char *buf, size_t count)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+       struct gl518_data *data = i2c_get_clientdata(client);
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       unsigned long bit;
+
+       bit = simple_strtoul(buf, NULL, 10);
+       if (bit & ~1)
+               return -EINVAL;
+
+       mutex_lock(&data->update_lock);
+       data->beep_mask = gl518_read_value(client, GL518_REG_ALARM);
+       if (bit)
+               data->beep_mask |= (1 << bitnr);
+       else
+               data->beep_mask &= ~(1 << bitnr);
+       gl518_write_value(client, GL518_REG_ALARM, data->beep_mask);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
+static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 0);
+static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 1);
+static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 2);
+static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 3);
+static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 4);
+static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 5);
+static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO|S_IWUSR, show_beep, set_beep, 6);
+
 static struct attribute *gl518_attributes[] = {
-       &dev_attr_in0_input.attr,
-       &dev_attr_in1_input.attr,
-       &dev_attr_in2_input.attr,
        &dev_attr_in3_input.attr,
        &dev_attr_in0_min.attr,
        &dev_attr_in1_min.attr,
@@ -354,18 +420,32 @@ static struct attribute *gl518_attributes[] = {
        &dev_attr_in1_max.attr,
        &dev_attr_in2_max.attr,
        &dev_attr_in3_max.attr,
+       &sensor_dev_attr_in0_alarm.dev_attr.attr,
+       &sensor_dev_attr_in1_alarm.dev_attr.attr,
+       &sensor_dev_attr_in2_alarm.dev_attr.attr,
+       &sensor_dev_attr_in3_alarm.dev_attr.attr,
+       &sensor_dev_attr_in0_beep.dev_attr.attr,
+       &sensor_dev_attr_in1_beep.dev_attr.attr,
+       &sensor_dev_attr_in2_beep.dev_attr.attr,
+       &sensor_dev_attr_in3_beep.dev_attr.attr,
 
        &dev_attr_fan1_auto.attr,
-       &dev_attr_fan1_input.attr,
-       &dev_attr_fan2_input.attr,
-       &dev_attr_fan1_min.attr,
-       &dev_attr_fan2_min.attr,
-       &dev_attr_fan1_div.attr,
-       &dev_attr_fan2_div.attr,
+       &sensor_dev_attr_fan1_input.dev_attr.attr,
+       &sensor_dev_attr_fan2_input.dev_attr.attr,
+       &sensor_dev_attr_fan1_min.dev_attr.attr,
+       &sensor_dev_attr_fan2_min.dev_attr.attr,
+       &sensor_dev_attr_fan1_div.dev_attr.attr,
+       &sensor_dev_attr_fan2_div.dev_attr.attr,
+       &sensor_dev_attr_fan1_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan2_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan1_beep.dev_attr.attr,
+       &sensor_dev_attr_fan2_beep.dev_attr.attr,
 
        &dev_attr_temp1_input.attr,
        &dev_attr_temp1_max.attr,
        &dev_attr_temp1_max_hyst.attr,
+       &sensor_dev_attr_temp1_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_beep.dev_attr.attr,
 
        &dev_attr_alarms.attr,
        &dev_attr_beep_enable.attr,
@@ -377,6 +457,17 @@ static const struct attribute_group gl518_group = {
        .attrs = gl518_attributes,
 };
 
+static struct attribute *gl518_attributes_r80[] = {
+       &dev_attr_in0_input.attr,
+       &dev_attr_in1_input.attr,
+       &dev_attr_in2_input.attr,
+       NULL
+};
+
+static const struct attribute_group gl518_group_r80 = {
+       .attrs = gl518_attributes_r80,
+};
+
 /*
  * Real code
  */
@@ -391,7 +482,7 @@ static int gl518_attach_adapter(struct i2c_adapter *adapter)
 static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
 {
        int i;
-       struct i2c_client *new_client;
+       struct i2c_client *client;
        struct gl518_data *data;
        int err = 0;
 
@@ -408,25 +499,24 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
                goto exit;
        }
 
-       new_client = &data->client;
-       i2c_set_clientdata(new_client, data);
+       client = &data->client;
+       i2c_set_clientdata(client, data);
 
-       new_client->addr = address;
-       new_client->adapter = adapter;
-       new_client->driver = &gl518_driver;
-       new_client->flags = 0;
+       client->addr = address;
+       client->adapter = adapter;
+       client->driver = &gl518_driver;
 
        /* Now, we do the remaining detection. */
 
        if (kind < 0) {
-               if ((gl518_read_value(new_client, GL518_REG_CHIP_ID) != 0x80)
-                || (gl518_read_value(new_client, GL518_REG_CONF) & 0x80))
+               if ((gl518_read_value(client, GL518_REG_CHIP_ID) != 0x80)
+                || (gl518_read_value(client, GL518_REG_CONF) & 0x80))
                        goto exit_free;
        }
 
        /* Determine the chip type. */
        if (kind <= 0) {
-               i = gl518_read_value(new_client, GL518_REG_REVISION);
+               i = gl518_read_value(client, GL518_REG_REVISION);
                if (i == 0x00) {
                        kind = gl518sm_r00;
                } else if (i == 0x80) {
@@ -442,25 +532,27 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
        }
 
        /* Fill in the remaining client fields */
-       strlcpy(new_client->name, "gl518sm", I2C_NAME_SIZE);
+       strlcpy(client->name, "gl518sm", I2C_NAME_SIZE);
        data->type = kind;
-       data->valid = 0;
        mutex_init(&data->update_lock);
 
        /* Tell the I2C layer a new client has arrived */
-       if ((err = i2c_attach_client(new_client)))
+       if ((err = i2c_attach_client(client)))
                goto exit_free;
 
        /* Initialize the GL518SM chip */
        data->alarm_mask = 0xff;
-       data->voltage_in[0]=data->voltage_in[1]=data->voltage_in[2]=0;
-       gl518_init_client((struct i2c_client *) new_client);
+       gl518_init_client(client);
 
        /* Register sysfs hooks */
-       if ((err = sysfs_create_group(&new_client->dev.kobj, &gl518_group)))
+       if ((err = sysfs_create_group(&client->dev.kobj, &gl518_group)))
                goto exit_detach;
+       if (data->type == gl518sm_r80)
+               if ((err = sysfs_create_group(&client->dev.kobj,
+                                             &gl518_group_r80)))
+                       goto exit_remove_files;
 
-       data->hwmon_dev = hwmon_device_register(&new_client->dev);
+       data->hwmon_dev = hwmon_device_register(&client->dev);
        if (IS_ERR(data->hwmon_dev)) {
                err = PTR_ERR(data->hwmon_dev);
                goto exit_remove_files;
@@ -469,9 +561,11 @@ static int gl518_detect(struct i2c_adapter *adapter, int address, int kind)
        return 0;
 
 exit_remove_files:
-       sysfs_remove_group(&new_client->dev.kobj, &gl518_group);
+       sysfs_remove_group(&client->dev.kobj, &gl518_group);
+       if (data->type == gl518sm_r80)
+               sysfs_remove_group(&client->dev.kobj, &gl518_group_r80);
 exit_detach:
-       i2c_detach_client(new_client);
+       i2c_detach_client(client);
 exit_free:
        kfree(data);
 exit:
@@ -504,6 +598,8 @@ static int gl518_detach_client(struct i2c_client *client)
 
        hwmon_device_unregister(data->hwmon_dev);
        sysfs_remove_group(&client->dev.kobj, &gl518_group);
+       if (data->type == gl518sm_r80)
+               sysfs_remove_group(&client->dev.kobj, &gl518_group_r80);
 
        if ((err = i2c_detach_client(client)))
                return err;
@@ -512,9 +608,9 @@ static int gl518_detach_client(struct i2c_client *client)
        return 0;
 }
 
-/* Registers 0x07 to 0x0c are word-sized, others are byte-sized 
+/* Registers 0x07 to 0x0c are word-sized, others are byte-sized
    GL518 uses a high-byte first convention, which is exactly opposite to
-   the usual practice. */
+   the SMBus standard. */
 static int gl518_read_value(struct i2c_client *client, u8 reg)
 {
        if ((reg >= 0x07) && (reg <= 0x0c))
@@ -523,9 +619,6 @@ static int gl518_read_value(struct i2c_client *client, u8 reg)
                return i2c_smbus_read_byte_data(client, reg);
 }
 
-/* Registers 0x07 to 0x0c are word-sized, others are byte-sized 
-   GL518 uses a high-byte first convention, which is exactly opposite to
-   the usual practice. */
 static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value)
 {
        if ((reg >= 0x07) && (reg <= 0x0c))
index 2d39d8fc2389fbc904fbc1c93632981efa7d1be5..03ecdc334764c7e7e1084be8e0072a19ed35f7c1 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
 #include <linux/hwmon-vid.h>
 #include <linux/err.h>
 #include <linux/mutex.h>
@@ -43,9 +44,9 @@ static unsigned short normal_i2c[] = { 0x2c, 0x2d, I2C_CLIENT_END };
 /* Insmod parameters */
 I2C_CLIENT_INSMOD_1(gl520sm);
 
-/* Many GL520 constants specified below 
+/* Many GL520 constants specified below
 One of the inputs can be configured as either temp or voltage.
-That's why _TEMP2 and _IN4 access the same register 
+That's why _TEMP2 and _IN4 access the same register
 */
 
 /* The GL520 registers */
@@ -56,37 +57,14 @@ That's why _TEMP2 and _IN4 access the same register
 
 #define GL520_REG_VID_INPUT            0x02
 
-#define GL520_REG_IN0_INPUT            0x15
-#define GL520_REG_IN0_LIMIT            0x0c
-#define GL520_REG_IN0_MIN              GL520_REG_IN0_LIMIT
-#define GL520_REG_IN0_MAX              GL520_REG_IN0_LIMIT
+static const u8 GL520_REG_IN_INPUT[]   = { 0x15, 0x14, 0x13, 0x0d, 0x0e };
+static const u8 GL520_REG_IN_LIMIT[]   = { 0x0c, 0x09, 0x0a, 0x0b };
+static const u8 GL520_REG_IN_MIN[]     = { 0x0c, 0x09, 0x0a, 0x0b, 0x18 };
+static const u8 GL520_REG_IN_MAX[]     = { 0x0c, 0x09, 0x0a, 0x0b, 0x17 };
 
-#define GL520_REG_IN1_INPUT            0x14
-#define GL520_REG_IN1_LIMIT            0x09
-#define GL520_REG_IN1_MIN              GL520_REG_IN1_LIMIT
-#define GL520_REG_IN1_MAX              GL520_REG_IN1_LIMIT
-
-#define GL520_REG_IN2_INPUT            0x13
-#define GL520_REG_IN2_LIMIT            0x0a
-#define GL520_REG_IN2_MIN              GL520_REG_IN2_LIMIT
-#define GL520_REG_IN2_MAX              GL520_REG_IN2_LIMIT
-
-#define GL520_REG_IN3_INPUT            0x0d
-#define GL520_REG_IN3_LIMIT            0x0b
-#define GL520_REG_IN3_MIN              GL520_REG_IN3_LIMIT
-#define GL520_REG_IN3_MAX              GL520_REG_IN3_LIMIT
-
-#define GL520_REG_IN4_INPUT            0x0e
-#define GL520_REG_IN4_MAX              0x17
-#define GL520_REG_IN4_MIN              0x18
-
-#define GL520_REG_TEMP1_INPUT          0x04
-#define GL520_REG_TEMP1_MAX            0x05
-#define GL520_REG_TEMP1_MAX_HYST       0x06
-
-#define GL520_REG_TEMP2_INPUT          0x0e
-#define GL520_REG_TEMP2_MAX            0x17
-#define GL520_REG_TEMP2_MAX_HYST       0x18
+static const u8 GL520_REG_TEMP_INPUT[]         = { 0x04, 0x0e };
+static const u8 GL520_REG_TEMP_MAX[]           = { 0x05, 0x17 };
+static const u8 GL520_REG_TEMP_MAX_HYST[]      = { 0x06, 0x18 };
 
 #define GL520_REG_FAN_INPUT            0x07
 #define GL520_REG_FAN_MIN              0x08
@@ -114,7 +92,6 @@ static struct i2c_driver gl520_driver = {
        .driver = {
                .name   = "gl520sm",
        },
-       .id             = I2C_DRIVERID_GL520,
        .attach_adapter = gl520_attach_adapter,
        .detach_client  = gl520_detach_client,
 };
@@ -150,93 +127,13 @@ struct gl520_data {
  * Sysfs stuff
  */
 
-#define sysfs_r(type, n, item, reg) \
-static ssize_t get_##type##item (struct gl520_data *, char *, int); \
-static ssize_t get_##type##n##item (struct device *, struct device_attribute *attr, char *); \
-static ssize_t get_##type##n##item (struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct gl520_data *data = gl520_update_device(dev); \
-       return get_##type##item(data, buf, (n)); \
-}
-
-#define sysfs_w(type, n, item, reg) \
-static ssize_t set_##type##item (struct i2c_client *, struct gl520_data *, const char *, size_t, int, int); \
-static ssize_t set_##type##n##item (struct device *, struct device_attribute *attr, const char *, size_t); \
-static ssize_t set_##type##n##item (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct gl520_data *data = i2c_get_clientdata(client); \
-       return set_##type##item(client, data, buf, count, (n), reg); \
-}
-
-#define sysfs_rw_n(type, n, item, reg) \
-sysfs_r(type, n, item, reg) \
-sysfs_w(type, n, item, reg) \
-static DEVICE_ATTR(type##n##item, S_IRUGO | S_IWUSR, get_##type##n##item, set_##type##n##item);
-
-#define sysfs_ro_n(type, n, item, reg) \
-sysfs_r(type, n, item, reg) \
-static DEVICE_ATTR(type##n##item, S_IRUGO, get_##type##n##item, NULL);
-
-#define sysfs_rw(type, item, reg) \
-sysfs_r(type, 0, item, reg) \
-sysfs_w(type, 0, item, reg) \
-static DEVICE_ATTR(type##item, S_IRUGO | S_IWUSR, get_##type##0##item, set_##type##0##item);
-
-#define sysfs_ro(type, item, reg) \
-sysfs_r(type, 0, item, reg) \
-static DEVICE_ATTR(type##item, S_IRUGO, get_##type##0##item, NULL);
-
-
-#define sysfs_vid(n) \
-sysfs_ro_n(cpu, n, _vid, GL520_REG_VID_INPUT)
-
-#define sysfs_in(n) \
-sysfs_ro_n(in, n, _input, GL520_REG_IN##n##INPUT) \
-sysfs_rw_n(in, n, _min, GL520_REG_IN##n##_MIN) \
-sysfs_rw_n(in, n, _max, GL520_REG_IN##n##_MAX) \
-
-#define sysfs_fan(n) \
-sysfs_ro_n(fan, n, _input, GL520_REG_FAN_INPUT) \
-sysfs_rw_n(fan, n, _min, GL520_REG_FAN_MIN) \
-sysfs_rw_n(fan, n, _div, GL520_REG_FAN_DIV)
-
-#define sysfs_fan_off(n) \
-sysfs_rw_n(fan, n, _off, GL520_REG_FAN_OFF) \
-
-#define sysfs_temp(n) \
-sysfs_ro_n(temp, n, _input, GL520_REG_TEMP##n##_INPUT) \
-sysfs_rw_n(temp, n, _max, GL520_REG_TEMP##n##_MAX) \
-sysfs_rw_n(temp, n, _max_hyst, GL520_REG_TEMP##n##_MAX_HYST)
-
-#define sysfs_alarms() \
-sysfs_ro(alarms, , GL520_REG_ALARMS) \
-sysfs_rw(beep_enable, , GL520_REG_BEEP_ENABLE) \
-sysfs_rw(beep_mask, , GL520_REG_BEEP_MASK)
-
-
-sysfs_vid(0)
-
-sysfs_in(0)
-sysfs_in(1)
-sysfs_in(2)
-sysfs_in(3)
-sysfs_in(4)
-
-sysfs_fan(1)
-sysfs_fan(2)
-sysfs_fan_off(1)
-
-sysfs_temp(1)
-sysfs_temp(2)
-
-sysfs_alarms()
-
-
-static ssize_t get_cpu_vid(struct gl520_data *data, char *buf, int n)
+static ssize_t get_cpu_vid(struct device *dev, struct device_attribute *attr,
+                          char *buf)
 {
+       struct gl520_data *data = gl520_update_device(dev);
        return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
 }
+static DEVICE_ATTR(cpu0_vid, S_IRUGO, get_cpu_vid, NULL);
 
 #define VDD_FROM_REG(val) (((val)*95+2)/4)
 #define VDD_TO_REG(val) (SENSORS_LIMIT((((val)*4+47)/95),0,255))
@@ -244,8 +141,11 @@ static ssize_t get_cpu_vid(struct gl520_data *data, char *buf, int n)
 #define IN_FROM_REG(val) ((val)*19)
 #define IN_TO_REG(val) (SENSORS_LIMIT((((val)+9)/19),0,255))
 
-static ssize_t get_in_input(struct gl520_data *data, char *buf, int n)
+static ssize_t get_in_input(struct device *dev, struct device_attribute *attr,
+                           char *buf)
 {
+       int n = to_sensor_dev_attr(attr)->index;
+       struct gl520_data *data = gl520_update_device(dev);
        u8 r = data->in_input[n];
 
        if (n == 0)
@@ -254,8 +154,11 @@ static ssize_t get_in_input(struct gl520_data *data, char *buf, int n)
                return sprintf(buf, "%d\n", IN_FROM_REG(r));
 }
 
-static ssize_t get_in_min(struct gl520_data *data, char *buf, int n)
+static ssize_t get_in_min(struct device *dev, struct device_attribute *attr,
+                         char *buf)
 {
+       int n = to_sensor_dev_attr(attr)->index;
+       struct gl520_data *data = gl520_update_device(dev);
        u8 r = data->in_min[n];
 
        if (n == 0)
@@ -264,8 +167,11 @@ static ssize_t get_in_min(struct gl520_data *data, char *buf, int n)
                return sprintf(buf, "%d\n", IN_FROM_REG(r));
 }
 
-static ssize_t get_in_max(struct gl520_data *data, char *buf, int n)
+static ssize_t get_in_max(struct device *dev, struct device_attribute *attr,
+                         char *buf)
 {
+       int n = to_sensor_dev_attr(attr)->index;
+       struct gl520_data *data = gl520_update_device(dev);
        u8 r = data->in_max[n];
 
        if (n == 0)
@@ -274,8 +180,12 @@ static ssize_t get_in_max(struct gl520_data *data, char *buf, int n)
                return sprintf(buf, "%d\n", IN_FROM_REG(r));
 }
 
-static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
+static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
+                         const char *buf, size_t count)
 {
+       struct i2c_client *client = to_i2c_client(dev);
+       struct gl520_data *data = i2c_get_clientdata(client);
+       int n = to_sensor_dev_attr(attr)->index;
        long v = simple_strtol(buf, NULL, 10);
        u8 r;
 
@@ -289,16 +199,22 @@ static ssize_t set_in_min(struct i2c_client *client, struct gl520_data *data, co
        data->in_min[n] = r;
 
        if (n < 4)
-               gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff) | r);
+               gl520_write_value(client, GL520_REG_IN_MIN[n],
+                                 (gl520_read_value(client, GL520_REG_IN_MIN[n])
+                                  & ~0xff) | r);
        else
-               gl520_write_value(client, reg, r);
+               gl520_write_value(client, GL520_REG_IN_MIN[n], r);
 
        mutex_unlock(&data->update_lock);
        return count;
 }
 
-static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
+static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
+                         const char *buf, size_t count)
 {
+       struct i2c_client *client = to_i2c_client(dev);
+       struct gl520_data *data = i2c_get_clientdata(client);
+       int n = to_sensor_dev_attr(attr)->index;
        long v = simple_strtol(buf, NULL, 10);
        u8 r;
 
@@ -312,57 +228,109 @@ static ssize_t set_in_max(struct i2c_client *client, struct gl520_data *data, co
        data->in_max[n] = r;
 
        if (n < 4)
-               gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff00) | (r << 8));
+               gl520_write_value(client, GL520_REG_IN_MAX[n],
+                                 (gl520_read_value(client, GL520_REG_IN_MAX[n])
+                                  & ~0xff00) | (r << 8));
        else
-               gl520_write_value(client, reg, r);
+               gl520_write_value(client, GL520_REG_IN_MAX[n], r);
 
        mutex_unlock(&data->update_lock);
        return count;
 }
 
+static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, get_in_input, NULL, 0);
+static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, get_in_input, NULL, 1);
+static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, get_in_input, NULL, 2);
+static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, get_in_input, NULL, 3);
+static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, get_in_input, NULL, 4);
+static SENSOR_DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR,
+               get_in_min, set_in_min, 0);
+static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO | S_IWUSR,
+               get_in_min, set_in_min, 1);
+static SENSOR_DEVICE_ATTR(in2_min, S_IRUGO | S_IWUSR,
+               get_in_min, set_in_min, 2);
+static SENSOR_DEVICE_ATTR(in3_min, S_IRUGO | S_IWUSR,
+               get_in_min, set_in_min, 3);
+static SENSOR_DEVICE_ATTR(in4_min, S_IRUGO | S_IWUSR,
+               get_in_min, set_in_min, 4);
+static SENSOR_DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR,
+               get_in_max, set_in_max, 0);
+static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR,
+               get_in_max, set_in_max, 1);
+static SENSOR_DEVICE_ATTR(in2_max, S_IRUGO | S_IWUSR,
+               get_in_max, set_in_max, 2);
+static SENSOR_DEVICE_ATTR(in3_max, S_IRUGO | S_IWUSR,
+               get_in_max, set_in_max, 3);
+static SENSOR_DEVICE_ATTR(in4_max, S_IRUGO | S_IWUSR,
+               get_in_max, set_in_max, 4);
+
 #define DIV_FROM_REG(val) (1 << (val))
 #define FAN_FROM_REG(val,div) ((val)==0 ? 0 : (480000/((val) << (div))))
 #define FAN_TO_REG(val,div) ((val)<=0?0:SENSORS_LIMIT((480000 + ((val) << ((div)-1))) / ((val) << (div)), 1, 255));
 
-static ssize_t get_fan_input(struct gl520_data *data, char *buf, int n)
+static ssize_t get_fan_input(struct device *dev, struct device_attribute *attr,
+                            char *buf)
 {
-       return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_input[n - 1], data->fan_div[n - 1]));
+       int n = to_sensor_dev_attr(attr)->index;
+       struct gl520_data *data = gl520_update_device(dev);
+
+       return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_input[n],
+                                                data->fan_div[n]));
 }
 
-static ssize_t get_fan_min(struct gl520_data *data, char *buf, int n)
+static ssize_t get_fan_min(struct device *dev, struct device_attribute *attr,
+                          char *buf)
 {
-       return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[n - 1], data->fan_div[n - 1]));
+       int n = to_sensor_dev_attr(attr)->index;
+       struct gl520_data *data = gl520_update_device(dev);
+
+       return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[n],
+                                                data->fan_div[n]));
 }
 
-static ssize_t get_fan_div(struct gl520_data *data, char *buf, int n)
+static ssize_t get_fan_div(struct device *dev, struct device_attribute *attr,
+                          char *buf)
 {
-       return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[n - 1]));
+       int n = to_sensor_dev_attr(attr)->index;
+       struct gl520_data *data = gl520_update_device(dev);
+
+       return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[n]));
 }
 
-static ssize_t get_fan_off(struct gl520_data *data, char *buf, int n)
+static ssize_t get_fan_off(struct device *dev, struct device_attribute *attr,
+                          char *buf)
 {
+       struct gl520_data *data = gl520_update_device(dev);
        return sprintf(buf, "%d\n", data->fan_off);
 }
 
-static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
+static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
+                          const char *buf, size_t count)
 {
+       struct i2c_client *client = to_i2c_client(dev);
+       struct gl520_data *data = i2c_get_clientdata(client);
+       int n = to_sensor_dev_attr(attr)->index;
        unsigned long v = simple_strtoul(buf, NULL, 10);
        u8 r;
 
        mutex_lock(&data->update_lock);
-       r = FAN_TO_REG(v, data->fan_div[n - 1]);
-       data->fan_min[n - 1] = r;
+       r = FAN_TO_REG(v, data->fan_div[n]);
+       data->fan_min[n] = r;
 
-       if (n == 1)
-               gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff00) | (r << 8));
+       if (n == 0)
+               gl520_write_value(client, GL520_REG_FAN_MIN,
+                                 (gl520_read_value(client, GL520_REG_FAN_MIN)
+                                  & ~0xff00) | (r << 8));
        else
-               gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xff) | r);
+               gl520_write_value(client, GL520_REG_FAN_MIN,
+                                 (gl520_read_value(client, GL520_REG_FAN_MIN)
+                                  & ~0xff) | r);
 
        data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
-       if (data->fan_min[n - 1] == 0)
-               data->alarm_mask &= (n == 1) ? ~0x20 : ~0x40;
+       if (data->fan_min[n] == 0)
+               data->alarm_mask &= (n == 0) ? ~0x20 : ~0x40;
        else
-               data->alarm_mask |= (n == 1) ? 0x20 : 0x40;
+               data->alarm_mask |= (n == 0) ? 0x20 : 0x40;
        data->beep_mask &= data->alarm_mask;
        gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
 
@@ -370,8 +338,12 @@ static ssize_t set_fan_min(struct i2c_client *client, struct gl520_data *data, c
        return count;
 }
 
-static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
+static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
+                          const char *buf, size_t count)
 {
+       struct i2c_client *client = to_i2c_client(dev);
+       struct gl520_data *data = i2c_get_clientdata(client);
+       int n = to_sensor_dev_attr(attr)->index;
        unsigned long v = simple_strtoul(buf, NULL, 10);
        u8 r;
 
@@ -386,133 +358,282 @@ static ssize_t set_fan_div(struct i2c_client *client, struct gl520_data *data, c
        }
 
        mutex_lock(&data->update_lock);
-       data->fan_div[n - 1] = r;
+       data->fan_div[n] = r;
 
-       if (n == 1)
-               gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0xc0) | (r << 6));
+       if (n == 0)
+               gl520_write_value(client, GL520_REG_FAN_DIV,
+                                 (gl520_read_value(client, GL520_REG_FAN_DIV)
+                                  & ~0xc0) | (r << 6));
        else
-               gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x30) | (r << 4));
+               gl520_write_value(client, GL520_REG_FAN_DIV,
+                                 (gl520_read_value(client, GL520_REG_FAN_DIV)
+                                  & ~0x30) | (r << 4));
 
        mutex_unlock(&data->update_lock);
        return count;
 }
 
-static ssize_t set_fan_off(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
+static ssize_t set_fan_off(struct device *dev, struct device_attribute *attr,
+                          const char *buf, size_t count)
 {
+       struct i2c_client *client = to_i2c_client(dev);
+       struct gl520_data *data = i2c_get_clientdata(client);
        u8 r = simple_strtoul(buf, NULL, 10)?1:0;
 
        mutex_lock(&data->update_lock);
        data->fan_off = r;
-       gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x0c) | (r << 2));
+       gl520_write_value(client, GL520_REG_FAN_OFF,
+                         (gl520_read_value(client, GL520_REG_FAN_OFF)
+                          & ~0x0c) | (r << 2));
        mutex_unlock(&data->update_lock);
        return count;
 }
 
+static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, get_fan_input, NULL, 0);
+static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, get_fan_input, NULL, 1);
+static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR,
+               get_fan_min, set_fan_min, 0);
+static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO | S_IWUSR,
+               get_fan_min, set_fan_min, 1);
+static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
+               get_fan_div, set_fan_div, 0);
+static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
+               get_fan_div, set_fan_div, 1);
+static DEVICE_ATTR(fan1_off, S_IRUGO | S_IWUSR,
+               get_fan_off, set_fan_off);
+
 #define TEMP_FROM_REG(val) (((val) - 130) * 1000)
 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((((val)<0?(val)-500:(val)+500) / 1000)+130),0,255))
 
-static ssize_t get_temp_input(struct gl520_data *data, char *buf, int n)
+static ssize_t get_temp_input(struct device *dev, struct device_attribute *attr,
+                             char *buf)
 {
-       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_input[n - 1]));
+       int n = to_sensor_dev_attr(attr)->index;
+       struct gl520_data *data = gl520_update_device(dev);
+
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_input[n]));
 }
 
-static ssize_t get_temp_max(struct gl520_data *data, char *buf, int n)
+static ssize_t get_temp_max(struct device *dev, struct device_attribute *attr,
+                           char *buf)
 {
-       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[n - 1]));
+       int n = to_sensor_dev_attr(attr)->index;
+       struct gl520_data *data = gl520_update_device(dev);
+
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[n]));
 }
 
-static ssize_t get_temp_max_hyst(struct gl520_data *data, char *buf, int n)
+static ssize_t get_temp_max_hyst(struct device *dev, struct device_attribute
+                                *attr, char *buf)
 {
-       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[n - 1]));
+       int n = to_sensor_dev_attr(attr)->index;
+       struct gl520_data *data = gl520_update_device(dev);
+
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max_hyst[n]));
 }
 
-static ssize_t set_temp_max(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
+static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
+                           const char *buf, size_t count)
 {
+       struct i2c_client *client = to_i2c_client(dev);
+       struct gl520_data *data = i2c_get_clientdata(client);
+       int n = to_sensor_dev_attr(attr)->index;
        long v = simple_strtol(buf, NULL, 10);
 
        mutex_lock(&data->update_lock);
-       data->temp_max[n - 1] = TEMP_TO_REG(v);
-       gl520_write_value(client, reg, data->temp_max[n - 1]);
+       data->temp_max[n] = TEMP_TO_REG(v);
+       gl520_write_value(client, GL520_REG_TEMP_MAX[n], data->temp_max[n]);
        mutex_unlock(&data->update_lock);
        return count;
 }
 
-static ssize_t set_temp_max_hyst(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
+static ssize_t set_temp_max_hyst(struct device *dev, struct device_attribute
+                                *attr, const char *buf, size_t count)
 {
+       struct i2c_client *client = to_i2c_client(dev);
+       struct gl520_data *data = i2c_get_clientdata(client);
+       int n = to_sensor_dev_attr(attr)->index;
        long v = simple_strtol(buf, NULL, 10);
 
        mutex_lock(&data->update_lock);
-       data->temp_max_hyst[n - 1] = TEMP_TO_REG(v);
-       gl520_write_value(client, reg, data->temp_max_hyst[n - 1]);
+       data->temp_max_hyst[n] = TEMP_TO_REG(v);
+       gl520_write_value(client, GL520_REG_TEMP_MAX_HYST[n],
+                         data->temp_max_hyst[n]);
        mutex_unlock(&data->update_lock);
        return count;
 }
 
-static ssize_t get_alarms(struct gl520_data *data, char *buf, int n)
+static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, get_temp_input, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, get_temp_input, NULL, 1);
+static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR,
+               get_temp_max, set_temp_max, 0);
+static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR,
+               get_temp_max, set_temp_max, 1);
+static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
+               get_temp_max_hyst, set_temp_max_hyst, 0);
+static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR,
+               get_temp_max_hyst, set_temp_max_hyst, 1);
+
+static ssize_t get_alarms(struct device *dev, struct device_attribute *attr,
+                         char *buf)
 {
+       struct gl520_data *data = gl520_update_device(dev);
        return sprintf(buf, "%d\n", data->alarms);
 }
 
-static ssize_t get_beep_enable(struct gl520_data *data, char *buf, int n)
+static ssize_t get_beep_enable(struct device *dev, struct device_attribute
+                              *attr, char *buf)
 {
+       struct gl520_data *data = gl520_update_device(dev);
        return sprintf(buf, "%d\n", data->beep_enable);
 }
 
-static ssize_t get_beep_mask(struct gl520_data *data, char *buf, int n)
+static ssize_t get_beep_mask(struct device *dev, struct device_attribute *attr,
+                            char *buf)
 {
+       struct gl520_data *data = gl520_update_device(dev);
        return sprintf(buf, "%d\n", data->beep_mask);
 }
 
-static ssize_t set_beep_enable(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
+static ssize_t set_beep_enable(struct device *dev, struct device_attribute
+                              *attr, const char *buf, size_t count)
 {
+       struct i2c_client *client = to_i2c_client(dev);
+       struct gl520_data *data = i2c_get_clientdata(client);
        u8 r = simple_strtoul(buf, NULL, 10)?0:1;
 
        mutex_lock(&data->update_lock);
        data->beep_enable = !r;
-       gl520_write_value(client, reg, (gl520_read_value(client, reg) & ~0x04) | (r << 2));
+       gl520_write_value(client, GL520_REG_BEEP_ENABLE,
+                         (gl520_read_value(client, GL520_REG_BEEP_ENABLE)
+                          & ~0x04) | (r << 2));
        mutex_unlock(&data->update_lock);
        return count;
 }
 
-static ssize_t set_beep_mask(struct i2c_client *client, struct gl520_data *data, const char *buf, size_t count, int n, int reg)
+static ssize_t set_beep_mask(struct device *dev, struct device_attribute *attr,
+                            const char *buf, size_t count)
 {
+       struct i2c_client *client = to_i2c_client(dev);
+       struct gl520_data *data = i2c_get_clientdata(client);
        u8 r = simple_strtoul(buf, NULL, 10);
-       
+
        mutex_lock(&data->update_lock);
        r &= data->alarm_mask;
        data->beep_mask = r;
-       gl520_write_value(client, reg, r);
+       gl520_write_value(client, GL520_REG_BEEP_MASK, r);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
+static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL);
+static DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
+               get_beep_enable, set_beep_enable);
+static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR,
+               get_beep_mask, set_beep_mask);
+
+static ssize_t get_alarm(struct device *dev, struct device_attribute *attr,
+                        char *buf)
+{
+       int bit_nr = to_sensor_dev_attr(attr)->index;
+       struct gl520_data *data = gl520_update_device(dev);
+
+       return sprintf(buf, "%d\n", (data->alarms >> bit_nr) & 1);
+}
+
+static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, get_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, get_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, get_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, get_alarm, NULL, 3);
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, get_alarm, NULL, 4);
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, get_alarm, NULL, 5);
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, get_alarm, NULL, 6);
+static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, get_alarm, NULL, 7);
+static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, get_alarm, NULL, 7);
+
+static ssize_t get_beep(struct device *dev, struct device_attribute *attr,
+                       char *buf)
+{
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       struct gl520_data *data = gl520_update_device(dev);
+
+       return sprintf(buf, "%d\n", (data->beep_mask >> bitnr) & 1);
+}
+
+static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
+                       const char *buf, size_t count)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+       struct gl520_data *data = i2c_get_clientdata(client);
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       unsigned long bit;
+
+       bit = simple_strtoul(buf, NULL, 10);
+       if (bit & ~1)
+               return -EINVAL;
+
+       mutex_lock(&data->update_lock);
+       data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
+       if (bit)
+               data->beep_mask |= (1 << bitnr);
+       else
+               data->beep_mask &= ~(1 << bitnr);
+       gl520_write_value(client, GL520_REG_BEEP_MASK, data->beep_mask);
        mutex_unlock(&data->update_lock);
        return count;
 }
 
+static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 0);
+static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 1);
+static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 2);
+static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 3);
+static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 4);
+static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 5);
+static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 6);
+static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 7);
+static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO | S_IWUSR, get_beep, set_beep, 7);
+
 static struct attribute *gl520_attributes[] = {
        &dev_attr_cpu0_vid.attr,
 
-       &dev_attr_in0_input.attr,
-       &dev_attr_in0_min.attr,
-       &dev_attr_in0_max.attr,
-       &dev_attr_in1_input.attr,
-       &dev_attr_in1_min.attr,
-       &dev_attr_in1_max.attr,
-       &dev_attr_in2_input.attr,
-       &dev_attr_in2_min.attr,
-       &dev_attr_in2_max.attr,
-       &dev_attr_in3_input.attr,
-       &dev_attr_in3_min.attr,
-       &dev_attr_in3_max.attr,
-
-       &dev_attr_fan1_input.attr,
-       &dev_attr_fan1_min.attr,
-       &dev_attr_fan1_div.attr,
+       &sensor_dev_attr_in0_input.dev_attr.attr,
+       &sensor_dev_attr_in0_min.dev_attr.attr,
+       &sensor_dev_attr_in0_max.dev_attr.attr,
+       &sensor_dev_attr_in0_alarm.dev_attr.attr,
+       &sensor_dev_attr_in0_beep.dev_attr.attr,
+       &sensor_dev_attr_in1_input.dev_attr.attr,
+       &sensor_dev_attr_in1_min.dev_attr.attr,
+       &sensor_dev_attr_in1_max.dev_attr.attr,
+       &sensor_dev_attr_in1_alarm.dev_attr.attr,
+       &sensor_dev_attr_in1_beep.dev_attr.attr,
+       &sensor_dev_attr_in2_input.dev_attr.attr,
+       &sensor_dev_attr_in2_min.dev_attr.attr,
+       &sensor_dev_attr_in2_max.dev_attr.attr,
+       &sensor_dev_attr_in2_alarm.dev_attr.attr,
+       &sensor_dev_attr_in2_beep.dev_attr.attr,
+       &sensor_dev_attr_in3_input.dev_attr.attr,
+       &sensor_dev_attr_in3_min.dev_attr.attr,
+       &sensor_dev_attr_in3_max.dev_attr.attr,
+       &sensor_dev_attr_in3_alarm.dev_attr.attr,
+       &sensor_dev_attr_in3_beep.dev_attr.attr,
+
+       &sensor_dev_attr_fan1_input.dev_attr.attr,
+       &sensor_dev_attr_fan1_min.dev_attr.attr,
+       &sensor_dev_attr_fan1_div.dev_attr.attr,
+       &sensor_dev_attr_fan1_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan1_beep.dev_attr.attr,
        &dev_attr_fan1_off.attr,
-       &dev_attr_fan2_input.attr,
-       &dev_attr_fan2_min.attr,
-       &dev_attr_fan2_div.attr,
-
-       &dev_attr_temp1_input.attr,
-       &dev_attr_temp1_max.attr,
-       &dev_attr_temp1_max_hyst.attr,
+       &sensor_dev_attr_fan2_input.dev_attr.attr,
+       &sensor_dev_attr_fan2_min.dev_attr.attr,
+       &sensor_dev_attr_fan2_div.dev_attr.attr,
+       &sensor_dev_attr_fan2_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan2_beep.dev_attr.attr,
+
+       &sensor_dev_attr_temp1_input.dev_attr.attr,
+       &sensor_dev_attr_temp1_max.dev_attr.attr,
+       &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
+       &sensor_dev_attr_temp1_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_beep.dev_attr.attr,
 
        &dev_attr_alarms.attr,
        &dev_attr_beep_enable.attr,
@@ -525,13 +646,17 @@ static const struct attribute_group gl520_group = {
 };
 
 static struct attribute *gl520_attributes_opt[] = {
-       &dev_attr_in4_input.attr,
-       &dev_attr_in4_min.attr,
-       &dev_attr_in4_max.attr,
-
-       &dev_attr_temp2_input.attr,
-       &dev_attr_temp2_max.attr,
-       &dev_attr_temp2_max_hyst.attr,
+       &sensor_dev_attr_in4_input.dev_attr.attr,
+       &sensor_dev_attr_in4_min.dev_attr.attr,
+       &sensor_dev_attr_in4_max.dev_attr.attr,
+       &sensor_dev_attr_in4_alarm.dev_attr.attr,
+       &sensor_dev_attr_in4_beep.dev_attr.attr,
+
+       &sensor_dev_attr_temp2_input.dev_attr.attr,
+       &sensor_dev_attr_temp2_max.dev_attr.attr,
+       &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
+       &sensor_dev_attr_temp2_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp2_beep.dev_attr.attr,
        NULL
 };
 
@@ -553,7 +678,7 @@ static int gl520_attach_adapter(struct i2c_adapter *adapter)
 
 static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
 {
-       struct i2c_client *new_client;
+       struct i2c_client *client;
        struct gl520_data *data;
        int err = 0;
 
@@ -570,59 +695,65 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
                goto exit;
        }
 
-       new_client = &data->client;
-       i2c_set_clientdata(new_client, data);
-       new_client->addr = address;
-       new_client->adapter = adapter;
-       new_client->driver = &gl520_driver;
-       new_client->flags = 0;
+       client = &data->client;
+       i2c_set_clientdata(client, data);
+       client->addr = address;
+       client->adapter = adapter;
+       client->driver = &gl520_driver;
 
        /* Determine the chip type. */
        if (kind < 0) {
-               if ((gl520_read_value(new_client, GL520_REG_CHIP_ID) != 0x20) ||
-                   ((gl520_read_value(new_client, GL520_REG_REVISION) & 0x7f) != 0x00) ||
-                   ((gl520_read_value(new_client, GL520_REG_CONF) & 0x80) != 0x00)) {
-                       dev_dbg(&new_client->dev, "Unknown chip type, skipping\n");
+               if ((gl520_read_value(client, GL520_REG_CHIP_ID) != 0x20) ||
+                   ((gl520_read_value(client, GL520_REG_REVISION) & 0x7f) != 0x00) ||
+                   ((gl520_read_value(client, GL520_REG_CONF) & 0x80) != 0x00)) {
+                       dev_dbg(&client->dev, "Unknown chip type, skipping\n");
                        goto exit_free;
                }
        }
 
        /* Fill in the remaining client fields */
-       strlcpy(new_client->name, "gl520sm", I2C_NAME_SIZE);
-       data->valid = 0;
+       strlcpy(client->name, "gl520sm", I2C_NAME_SIZE);
        mutex_init(&data->update_lock);
 
        /* Tell the I2C layer a new client has arrived */
-       if ((err = i2c_attach_client(new_client)))
+       if ((err = i2c_attach_client(client)))
                goto exit_free;
 
        /* Initialize the GL520SM chip */
-       gl520_init_client(new_client);
+       gl520_init_client(client);
 
        /* Register sysfs hooks */
-       if ((err = sysfs_create_group(&new_client->dev.kobj, &gl520_group)))
+       if ((err = sysfs_create_group(&client->dev.kobj, &gl520_group)))
                goto exit_detach;
 
        if (data->two_temps) {
-               if ((err = device_create_file(&new_client->dev,
-                                             &dev_attr_temp2_input))
-                || (err = device_create_file(&new_client->dev,
-                                             &dev_attr_temp2_max))
-                || (err = device_create_file(&new_client->dev,
-                                             &dev_attr_temp2_max_hyst)))
+               if ((err = device_create_file(&client->dev,
+                               &sensor_dev_attr_temp2_input.dev_attr))
+                || (err = device_create_file(&client->dev,
+                               &sensor_dev_attr_temp2_max.dev_attr))
+                || (err = device_create_file(&client->dev,
+                               &sensor_dev_attr_temp2_max_hyst.dev_attr))
+                || (err = device_create_file(&client->dev,
+                               &sensor_dev_attr_temp2_alarm.dev_attr))
+                || (err = device_create_file(&client->dev,
+                               &sensor_dev_attr_temp2_beep.dev_attr)))
                        goto exit_remove_files;
        } else {
-               if ((err = device_create_file(&new_client->dev,
-                                             &dev_attr_in4_input))
-                || (err = device_create_file(&new_client->dev,
-                                             &dev_attr_in4_min))
-                || (err = device_create_file(&new_client->dev,
-                                             &dev_attr_in4_max)))
+               if ((err = device_create_file(&client->dev,
+                               &sensor_dev_attr_in4_input.dev_attr))
+                || (err = device_create_file(&client->dev,
+                               &sensor_dev_attr_in4_min.dev_attr))
+                || (err = device_create_file(&client->dev,
+                               &sensor_dev_attr_in4_max.dev_attr))
+                || (err = device_create_file(&client->dev,
+                               &sensor_dev_attr_in4_alarm.dev_attr))
+                || (err = device_create_file(&client->dev,
+                               &sensor_dev_attr_in4_beep.dev_attr)))
                        goto exit_remove_files;
        }
 
 
-       data->hwmon_dev = hwmon_device_register(&new_client->dev);
+       data->hwmon_dev = hwmon_device_register(&client->dev);
        if (IS_ERR(data->hwmon_dev)) {
                err = PTR_ERR(data->hwmon_dev);
                goto exit_remove_files;
@@ -631,10 +762,10 @@ static int gl520_detect(struct i2c_adapter *adapter, int address, int kind)
        return 0;
 
 exit_remove_files:
-       sysfs_remove_group(&new_client->dev.kobj, &gl520_group);
-       sysfs_remove_group(&new_client->dev.kobj, &gl520_group_opt);
+       sysfs_remove_group(&client->dev.kobj, &gl520_group);
+       sysfs_remove_group(&client->dev.kobj, &gl520_group_opt);
 exit_detach:
-       i2c_detach_client(new_client);
+       i2c_detach_client(client);
 exit_free:
        kfree(data);
 exit:
@@ -697,7 +828,7 @@ static int gl520_detach_client(struct i2c_client *client)
 }
 
 
-/* Registers 0x07 to 0x0c are word-sized, others are byte-sized 
+/* Registers 0x07 to 0x0c are word-sized, others are byte-sized
    GL520 uses a high-byte first convention */
 static int gl520_read_value(struct i2c_client *client, u8 reg)
 {
@@ -720,7 +851,7 @@ static struct gl520_data *gl520_update_device(struct device *dev)
 {
        struct i2c_client *client = to_i2c_client(dev);
        struct gl520_data *data = i2c_get_clientdata(client);
-       int val;
+       int val, i;
 
        mutex_lock(&data->update_lock);
 
@@ -732,18 +863,13 @@ static struct gl520_data *gl520_update_device(struct device *dev)
                data->beep_mask = gl520_read_value(client, GL520_REG_BEEP_MASK);
                data->vid = gl520_read_value(client, GL520_REG_VID_INPUT) & 0x1f;
 
-               val = gl520_read_value(client, GL520_REG_IN0_LIMIT);
-               data->in_min[0] = val & 0xff;
-               data->in_max[0] = (val >> 8) & 0xff;
-               val = gl520_read_value(client, GL520_REG_IN1_LIMIT);
-               data->in_min[1] = val & 0xff;
-               data->in_max[1] = (val >> 8) & 0xff;
-               val = gl520_read_value(client, GL520_REG_IN2_LIMIT);
-               data->in_min[2] = val & 0xff;
-               data->in_max[2] = (val >> 8) & 0xff;
-               val = gl520_read_value(client, GL520_REG_IN3_LIMIT);
-               data->in_min[3] = val & 0xff;
-               data->in_max[3] = (val >> 8) & 0xff;
+               for (i = 0; i < 4; i++) {
+                       data->in_input[i] = gl520_read_value(client,
+                                                       GL520_REG_IN_INPUT[i]);
+                       val = gl520_read_value(client, GL520_REG_IN_LIMIT[i]);
+                       data->in_min[i] = val & 0xff;
+                       data->in_max[i] = (val >> 8) & 0xff;
+               }
 
                val = gl520_read_value(client, GL520_REG_FAN_INPUT);
                data->fan_input[0] = (val >> 8) & 0xff;
@@ -753,9 +879,12 @@ static struct gl520_data *gl520_update_device(struct device *dev)
                data->fan_min[0] = (val >> 8) & 0xff;
                data->fan_min[1] = val & 0xff;
 
-               data->temp_input[0] = gl520_read_value(client, GL520_REG_TEMP1_INPUT);
-               data->temp_max[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX);
-               data->temp_max_hyst[0] = gl520_read_value(client, GL520_REG_TEMP1_MAX_HYST);
+               data->temp_input[0] = gl520_read_value(client,
+                                               GL520_REG_TEMP_INPUT[0]);
+               data->temp_max[0] = gl520_read_value(client,
+                                               GL520_REG_TEMP_MAX[0]);
+               data->temp_max_hyst[0] = gl520_read_value(client,
+                                               GL520_REG_TEMP_MAX_HYST[0]);
 
                val = gl520_read_value(client, GL520_REG_FAN_DIV);
                data->fan_div[0] = (val >> 6) & 0x03;
@@ -767,20 +896,21 @@ static struct gl520_data *gl520_update_device(struct device *dev)
                val = gl520_read_value(client, GL520_REG_CONF);
                data->beep_enable = !((val >> 2) & 1);
 
-               data->in_input[0] = gl520_read_value(client, GL520_REG_IN0_INPUT);
-               data->in_input[1] = gl520_read_value(client, GL520_REG_IN1_INPUT);
-               data->in_input[2] = gl520_read_value(client, GL520_REG_IN2_INPUT);
-               data->in_input[3] = gl520_read_value(client, GL520_REG_IN3_INPUT);
-
                /* Temp1 and Vin4 are the same input */
                if (data->two_temps) {
-                       data->temp_input[1] = gl520_read_value(client, GL520_REG_TEMP2_INPUT);
-                       data->temp_max[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX);
-                       data->temp_max_hyst[1] = gl520_read_value(client, GL520_REG_TEMP2_MAX_HYST);
+                       data->temp_input[1] = gl520_read_value(client,
+                                               GL520_REG_TEMP_INPUT[1]);
+                       data->temp_max[1] = gl520_read_value(client,
+                                               GL520_REG_TEMP_MAX[1]);
+                       data->temp_max_hyst[1] = gl520_read_value(client,
+                                               GL520_REG_TEMP_MAX_HYST[1]);
                } else {
-                       data->in_input[4] = gl520_read_value(client, GL520_REG_IN4_INPUT);
-                       data->in_min[4] = gl520_read_value(client, GL520_REG_IN4_MIN);
-                       data->in_max[4] = gl520_read_value(client, GL520_REG_IN4_MAX);
+                       data->in_input[4] = gl520_read_value(client,
+                                               GL520_REG_IN_INPUT[4]);
+                       data->in_min[4] = gl520_read_value(client,
+                                               GL520_REG_IN_MIN[4]);
+                       data->in_max[4] = gl520_read_value(client,
+                                               GL520_REG_IN_MAX[4]);
                }
 
                data->last_updated = jiffies;
index ad6c8a319903eeb8bf9fcd08950b0b58ddeba605..e12c132ff83a446ea0b40ca723c7a98f19570c81 100644 (file)
@@ -17,8 +17,8 @@
               IT8726F  Super I/O chip w/LPC interface
               Sis950   A clone of the IT8705F
 
-    Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com> 
-    Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org>
+    Copyright (C) 2001 Chris Gauthron
+    Copyright (C) 2005-2007 Jean Delvare <khali@linux-fr.org>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
 
 enum chips { it87, it8712, it8716, it8718 };
 
+static unsigned short force_id;
+module_param(force_id, ushort, 0);
+MODULE_PARM_DESC(force_id, "Override the detected device ID");
+
 static struct platform_device *pdev;
 
 #define        REG     0x2e    /* The register to read/write */
@@ -776,6 +780,30 @@ static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, ch
 }
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
 
+static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
+               char *buf)
+{
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       struct it87_data *data = it87_update_device(dev);
+       return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
+}
+static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
+static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
+static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
+static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
+static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
+static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
+static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
+static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
+static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
+static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
+static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
+
 static ssize_t
 show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
 {
@@ -837,6 +865,14 @@ static struct attribute *it87_attributes[] = {
        &sensor_dev_attr_in5_max.dev_attr.attr,
        &sensor_dev_attr_in6_max.dev_attr.attr,
        &sensor_dev_attr_in7_max.dev_attr.attr,
+       &sensor_dev_attr_in0_alarm.dev_attr.attr,
+       &sensor_dev_attr_in1_alarm.dev_attr.attr,
+       &sensor_dev_attr_in2_alarm.dev_attr.attr,
+       &sensor_dev_attr_in3_alarm.dev_attr.attr,
+       &sensor_dev_attr_in4_alarm.dev_attr.attr,
+       &sensor_dev_attr_in5_alarm.dev_attr.attr,
+       &sensor_dev_attr_in6_alarm.dev_attr.attr,
+       &sensor_dev_attr_in7_alarm.dev_attr.attr,
 
        &sensor_dev_attr_temp1_input.dev_attr.attr,
        &sensor_dev_attr_temp2_input.dev_attr.attr,
@@ -850,6 +886,9 @@ static struct attribute *it87_attributes[] = {
        &sensor_dev_attr_temp1_type.dev_attr.attr,
        &sensor_dev_attr_temp2_type.dev_attr.attr,
        &sensor_dev_attr_temp3_type.dev_attr.attr,
+       &sensor_dev_attr_temp1_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp2_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp3_alarm.dev_attr.attr,
 
        &dev_attr_alarms.attr,
        &dev_attr_name.attr,
@@ -882,12 +921,21 @@ static struct attribute *it87_attributes_opt[] = {
        &sensor_dev_attr_fan3_min.dev_attr.attr,
        &sensor_dev_attr_fan3_div.dev_attr.attr,
 
+       &sensor_dev_attr_fan1_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan2_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan3_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan4_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan5_alarm.dev_attr.attr,
+
        &sensor_dev_attr_pwm1_enable.dev_attr.attr,
        &sensor_dev_attr_pwm2_enable.dev_attr.attr,
        &sensor_dev_attr_pwm3_enable.dev_attr.attr,
        &sensor_dev_attr_pwm1.dev_attr.attr,
        &sensor_dev_attr_pwm2.dev_attr.attr,
        &sensor_dev_attr_pwm3.dev_attr.attr,
+       &dev_attr_pwm1_freq.attr,
+       &dev_attr_pwm2_freq.attr,
+       &dev_attr_pwm3_freq.attr,
 
        &dev_attr_vrm.attr,
        &dev_attr_cpu0_vid.attr,
@@ -906,7 +954,7 @@ static int __init it87_find(unsigned short *address,
        u16 chip_type;
 
        superio_enter();
-       chip_type = superio_inw(DEVID);
+       chip_type = force_id ? force_id : superio_inw(DEVID);
 
        switch (chip_type) {
        case IT8705F_DEVID:
@@ -1027,35 +1075,45 @@ static int __devinit it87_probe(struct platform_device *pdev)
                        if ((err = device_create_file(dev,
                             &sensor_dev_attr_fan1_input16.dev_attr))
                         || (err = device_create_file(dev,
-                            &sensor_dev_attr_fan1_min16.dev_attr)))
+                            &sensor_dev_attr_fan1_min16.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan1_alarm.dev_attr)))
                                goto ERROR4;
                }
                if (data->has_fan & (1 << 1)) {
                        if ((err = device_create_file(dev,
                             &sensor_dev_attr_fan2_input16.dev_attr))
                         || (err = device_create_file(dev,
-                            &sensor_dev_attr_fan2_min16.dev_attr)))
+                            &sensor_dev_attr_fan2_min16.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan2_alarm.dev_attr)))
                                goto ERROR4;
                }
                if (data->has_fan & (1 << 2)) {
                        if ((err = device_create_file(dev,
                             &sensor_dev_attr_fan3_input16.dev_attr))
                         || (err = device_create_file(dev,
-                            &sensor_dev_attr_fan3_min16.dev_attr)))
+                            &sensor_dev_attr_fan3_min16.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan3_alarm.dev_attr)))
                                goto ERROR4;
                }
                if (data->has_fan & (1 << 3)) {
                        if ((err = device_create_file(dev,
                             &sensor_dev_attr_fan4_input16.dev_attr))
                         || (err = device_create_file(dev,
-                            &sensor_dev_attr_fan4_min16.dev_attr)))
+                            &sensor_dev_attr_fan4_min16.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan4_alarm.dev_attr)))
                                goto ERROR4;
                }
                if (data->has_fan & (1 << 4)) {
                        if ((err = device_create_file(dev,
                             &sensor_dev_attr_fan5_input16.dev_attr))
                         || (err = device_create_file(dev,
-                            &sensor_dev_attr_fan5_min16.dev_attr)))
+                            &sensor_dev_attr_fan5_min16.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan5_alarm.dev_attr)))
                                goto ERROR4;
                }
        } else {
@@ -1066,7 +1124,9 @@ static int __devinit it87_probe(struct platform_device *pdev)
                         || (err = device_create_file(dev,
                             &sensor_dev_attr_fan1_min.dev_attr))
                         || (err = device_create_file(dev,
-                            &sensor_dev_attr_fan1_div.dev_attr)))
+                            &sensor_dev_attr_fan1_div.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan1_alarm.dev_attr)))
                                goto ERROR4;
                }
                if (data->has_fan & (1 << 1)) {
@@ -1075,7 +1135,9 @@ static int __devinit it87_probe(struct platform_device *pdev)
                         || (err = device_create_file(dev,
                             &sensor_dev_attr_fan2_min.dev_attr))
                         || (err = device_create_file(dev,
-                            &sensor_dev_attr_fan2_div.dev_attr)))
+                            &sensor_dev_attr_fan2_div.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan2_alarm.dev_attr)))
                                goto ERROR4;
                }
                if (data->has_fan & (1 << 2)) {
@@ -1084,7 +1146,9 @@ static int __devinit it87_probe(struct platform_device *pdev)
                         || (err = device_create_file(dev,
                             &sensor_dev_attr_fan3_min.dev_attr))
                         || (err = device_create_file(dev,
-                            &sensor_dev_attr_fan3_div.dev_attr)))
+                            &sensor_dev_attr_fan3_div.dev_attr))
+                        || (err = device_create_file(dev,
+                            &sensor_dev_attr_fan3_alarm.dev_attr)))
                                goto ERROR4;
                }
        }
@@ -1488,7 +1552,7 @@ static void __exit sm_it87_exit(void)
 }
 
 
-MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>, "
+MODULE_AUTHOR("Chris Gauthron, "
              "Jean Delvare <khali@linux-fr.org>");
 MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8726F, SiS950 driver");
 module_param(update_vbat, bool, 0);
index 37a8cc032ffa9a0b535ac26b9d07d37edb78bd3e..e5c35a355a571b023b04cefe6a6c57671e01875d 100644 (file)
@@ -74,7 +74,6 @@ static struct i2c_driver lm75_driver = {
        .driver = {
                .name   = "lm75",
        },
-       .id             = I2C_DRIVERID_LM75,
        .attach_adapter = lm75_attach_adapter,
        .detach_client  = lm75_detach_client,
 };
index cee5c2e8cfad29f3a4c6fc21d9d7abed8910219e..459b70ad6bee1a2d218d0f046bf2e9a8f221f2cc 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
 #include <linux/err.h>
 #include <linux/mutex.h>
 
@@ -113,7 +114,6 @@ show(temp_input);
 show(temp_crit);
 show(temp_min);
 show(temp_max);
-show(alarms);
 
 /* read routines for hysteresis values */
 static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute *attr, char *buf)
@@ -186,6 +186,14 @@ static ssize_t set_temp_crit(struct device *dev, struct device_attribute *attr,
        return count;
 }
 
+static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
+                         char *buf)
+{
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       struct lm77_data *data = lm77_update_device(dev);
+       return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
+}
+
 static DEVICE_ATTR(temp1_input, S_IRUGO,
                   show_temp_input, NULL);
 static DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO,
@@ -202,8 +210,9 @@ static DEVICE_ATTR(temp1_min_hyst, S_IRUGO,
 static DEVICE_ATTR(temp1_max_hyst, S_IRUGO,
                   show_temp_max_hyst, NULL);
 
-static DEVICE_ATTR(alarms, S_IRUGO,
-                  show_alarms, NULL);
+static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(temp1_min_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 1);
 
 static int lm77_attach_adapter(struct i2c_adapter *adapter)
 {
@@ -220,8 +229,9 @@ static struct attribute *lm77_attributes[] = {
        &dev_attr_temp1_crit_hyst.attr,
        &dev_attr_temp1_min_hyst.attr,
        &dev_attr_temp1_max_hyst.attr,
-       &dev_attr_alarms.attr,
-
+       &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_min_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
        NULL
 };
 
index 3f7055ee679fab746a40902f10b5ad54ba2728c5..0a9eb1f6f4e4a7028177ca235f6b6e5a6973bc41 100644 (file)
 static struct platform_device *pdev;
 
 /* Addresses to scan */
-static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24,
-                                       0x25, 0x26, 0x27, 0x28, 0x29,
-                                       0x2a, 0x2b, 0x2c, 0x2d, 0x2e,
-                                       0x2f, I2C_CLIENT_END };
+static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
+                                      0x2e, 0x2f, I2C_CLIENT_END };
 static unsigned short isa_address = 0x290;
 
 /* Insmod parameters */
@@ -170,7 +168,6 @@ static struct i2c_driver lm78_driver = {
        .driver = {
                .name   = "lm78",
        },
-       .id             = I2C_DRIVERID_LM78,
        .attach_adapter = lm78_attach_adapter,
        .detach_client  = lm78_detach_client,
 };
index 063cdba00a884c5eab975101d61d3b58a24a0ddb..a2ca055f3922f7132b63301313262d7cf9445b34 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/jiffies.h>
 #include <linux/i2c.h>
 #include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
 #include <linux/err.h>
 #include <linux/mutex.h>
 
@@ -127,7 +128,7 @@ struct lm80_data {
        u16 alarms;             /* Register encoding, combined */
 };
 
-/* 
+/*
  * Functions declaration
  */
 
@@ -147,7 +148,6 @@ static struct i2c_driver lm80_driver = {
        .driver = {
                .name   = "lm80",
        },
-       .id             = I2C_DRIVERID_LM80,
        .attach_adapter = lm80_attach_adapter,
        .detach_client  = lm80_detach_client,
 };
@@ -159,105 +159,74 @@ static struct i2c_driver lm80_driver = {
 #define show_in(suffix, value) \
 static ssize_t show_in_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \
 { \
+       int nr = to_sensor_dev_attr(attr)->index; \
        struct lm80_data *data = lm80_update_device(dev); \
-       return sprintf(buf, "%d\n", IN_FROM_REG(data->value)); \
+       return sprintf(buf, "%d\n", IN_FROM_REG(data->value[nr])); \
 }
-show_in(min0, in_min[0]);
-show_in(min1, in_min[1]);
-show_in(min2, in_min[2]);
-show_in(min3, in_min[3]);
-show_in(min4, in_min[4]);
-show_in(min5, in_min[5]);
-show_in(min6, in_min[6]);
-show_in(max0, in_max[0]);
-show_in(max1, in_max[1]);
-show_in(max2, in_max[2]);
-show_in(max3, in_max[3]);
-show_in(max4, in_max[4]);
-show_in(max5, in_max[5]);
-show_in(max6, in_max[6]);
-show_in(input0, in[0]);
-show_in(input1, in[1]);
-show_in(input2, in[2]);
-show_in(input3, in[3]);
-show_in(input4, in[4]);
-show_in(input5, in[5]);
-show_in(input6, in[6]);
+show_in(min, in_min)
+show_in(max, in_max)
+show_in(input, in)
 
 #define set_in(suffix, value, reg) \
 static ssize_t set_in_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \
        size_t count) \
 { \
+       int nr = to_sensor_dev_attr(attr)->index; \
        struct i2c_client *client = to_i2c_client(dev); \
        struct lm80_data *data = i2c_get_clientdata(client); \
        long val = simple_strtol(buf, NULL, 10); \
  \
        mutex_lock(&data->update_lock);\
-       data->value = IN_TO_REG(val); \
-       lm80_write_value(client, reg, data->value); \
+       data->value[nr] = IN_TO_REG(val); \
+       lm80_write_value(client, reg(nr), data->value[nr]); \
        mutex_unlock(&data->update_lock);\
        return count; \
 }
-set_in(min0, in_min[0], LM80_REG_IN_MIN(0));
-set_in(min1, in_min[1], LM80_REG_IN_MIN(1));
-set_in(min2, in_min[2], LM80_REG_IN_MIN(2));
-set_in(min3, in_min[3], LM80_REG_IN_MIN(3));
-set_in(min4, in_min[4], LM80_REG_IN_MIN(4));
-set_in(min5, in_min[5], LM80_REG_IN_MIN(5));
-set_in(min6, in_min[6], LM80_REG_IN_MIN(6));
-set_in(max0, in_max[0], LM80_REG_IN_MAX(0));
-set_in(max1, in_max[1], LM80_REG_IN_MAX(1));
-set_in(max2, in_max[2], LM80_REG_IN_MAX(2));
-set_in(max3, in_max[3], LM80_REG_IN_MAX(3));
-set_in(max4, in_max[4], LM80_REG_IN_MAX(4));
-set_in(max5, in_max[5], LM80_REG_IN_MAX(5));
-set_in(max6, in_max[6], LM80_REG_IN_MAX(6));
-
-#define show_fan(suffix, value, div) \
+set_in(min, in_min, LM80_REG_IN_MIN)
+set_in(max, in_max, LM80_REG_IN_MAX)
+
+#define show_fan(suffix, value) \
 static ssize_t show_fan_##suffix(struct device *dev, struct device_attribute *attr, char *buf) \
 { \
+       int nr = to_sensor_dev_attr(attr)->index; \
        struct lm80_data *data = lm80_update_device(dev); \
-       return sprintf(buf, "%d\n", FAN_FROM_REG(data->value, \
-                      DIV_FROM_REG(data->div))); \
+       return sprintf(buf, "%d\n", FAN_FROM_REG(data->value[nr], \
+                      DIV_FROM_REG(data->fan_div[nr]))); \
 }
-show_fan(min1, fan_min[0], fan_div[0]);
-show_fan(min2, fan_min[1], fan_div[1]);
-show_fan(input1, fan[0], fan_div[0]);
-show_fan(input2, fan[1], fan_div[1]);
+show_fan(min, fan_min)
+show_fan(input, fan)
 
-#define show_fan_div(suffix, value) \
-static ssize_t show_fan_div##suffix(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct lm80_data *data = lm80_update_device(dev); \
-       return sprintf(buf, "%d\n", DIV_FROM_REG(data->value)); \
+static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
+       char *buf)
+{
+       int nr = to_sensor_dev_attr(attr)->index;
+       struct lm80_data *data = lm80_update_device(dev);
+       return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
 }
-show_fan_div(1, fan_div[0]);
-show_fan_div(2, fan_div[1]);
 
-#define set_fan(suffix, value, reg, div) \
-static ssize_t set_fan_##suffix(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct lm80_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtoul(buf, NULL, 10); \
- \
-       mutex_lock(&data->update_lock);\
-       data->value = FAN_TO_REG(val, DIV_FROM_REG(data->div)); \
-       lm80_write_value(client, reg, data->value); \
-       mutex_unlock(&data->update_lock);\
-       return count; \
+static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
+       const char *buf, size_t count)
+{
+       int nr = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct lm80_data *data = i2c_get_clientdata(client);
+       long val = simple_strtoul(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
+       lm80_write_value(client, LM80_REG_FAN_MIN(nr + 1), data->fan_min[nr]);
+       mutex_unlock(&data->update_lock);
+       return count;
 }
-set_fan(min1, fan_min[0], LM80_REG_FAN_MIN(1), fan_div[0]);
-set_fan(min2, fan_min[1], LM80_REG_FAN_MIN(2), fan_div[1]);
 
 /* Note: we save and restore the fan minimum here, because its value is
    determined in part by the fan divisor.  This follows the principle of
    least surprise; the user doesn't expect the fan minimum to change just
    because the divisor changed. */
-static ssize_t set_fan_div(struct device *dev, const char *buf,
-       size_t count, int nr)
+static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
+       const char *buf, size_t count)
 {
+       int nr = to_sensor_dev_attr(attr)->index;
        struct i2c_client *client = to_i2c_client(dev);
        struct lm80_data *data = i2c_get_clientdata(client);
        unsigned long min, val = simple_strtoul(buf, NULL, 10);
@@ -292,15 +261,6 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
        return count;
 }
 
-#define set_fan_div(number) \
-static ssize_t set_fan_div##number(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       return set_fan_div(dev, buf, count, number - 1); \
-}
-set_fan_div(1);
-set_fan_div(2);
-
 static ssize_t show_temp_input1(struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct lm80_data *data = lm80_update_device(dev);
@@ -337,41 +297,66 @@ set_temp(hot_hyst, temp_hot_hyst, LM80_REG_TEMP_HOT_HYST);
 set_temp(os_max, temp_os_max, LM80_REG_TEMP_OS_MAX);
 set_temp(os_hyst, temp_os_hyst, LM80_REG_TEMP_OS_HYST);
 
-static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
+static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
+                          char *buf)
 {
        struct lm80_data *data = lm80_update_device(dev);
        return sprintf(buf, "%u\n", data->alarms);
 }
 
-static DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min0, set_in_min0);
-static DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min1, set_in_min1);
-static DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min2, set_in_min2);
-static DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min3, set_in_min3);
-static DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min4, set_in_min4);
-static DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min5, set_in_min5);
-static DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min6, set_in_min6);
-static DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max0, set_in_max0);
-static DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max1, set_in_max1);
-static DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max2, set_in_max2);
-static DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max3, set_in_max3);
-static DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max4, set_in_max4);
-static DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max5, set_in_max5);
-static DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max6, set_in_max6);
-static DEVICE_ATTR(in0_input, S_IRUGO, show_in_input0, NULL);
-static DEVICE_ATTR(in1_input, S_IRUGO, show_in_input1, NULL);
-static DEVICE_ATTR(in2_input, S_IRUGO, show_in_input2, NULL);
-static DEVICE_ATTR(in3_input, S_IRUGO, show_in_input3, NULL);
-static DEVICE_ATTR(in4_input, S_IRUGO, show_in_input4, NULL);
-static DEVICE_ATTR(in5_input, S_IRUGO, show_in_input5, NULL);
-static DEVICE_ATTR(in6_input, S_IRUGO, show_in_input6, NULL);
-static DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min1,
-    set_fan_min1);
-static DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min2,
-    set_fan_min2);
-static DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input1, NULL);
-static DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input2, NULL);
-static DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO, show_fan_div1, set_fan_div1);
-static DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO, show_fan_div2, set_fan_div2);
+static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
+                         char *buf)
+{
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       struct lm80_data *data = lm80_update_device(dev);
+       return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
+}
+
+static SENSOR_DEVICE_ATTR(in0_min, S_IWUSR | S_IRUGO,
+               show_in_min, set_in_min, 0);
+static SENSOR_DEVICE_ATTR(in1_min, S_IWUSR | S_IRUGO,
+               show_in_min, set_in_min, 1);
+static SENSOR_DEVICE_ATTR(in2_min, S_IWUSR | S_IRUGO,
+               show_in_min, set_in_min, 2);
+static SENSOR_DEVICE_ATTR(in3_min, S_IWUSR | S_IRUGO,
+               show_in_min, set_in_min, 3);
+static SENSOR_DEVICE_ATTR(in4_min, S_IWUSR | S_IRUGO,
+               show_in_min, set_in_min, 4);
+static SENSOR_DEVICE_ATTR(in5_min, S_IWUSR | S_IRUGO,
+               show_in_min, set_in_min, 5);
+static SENSOR_DEVICE_ATTR(in6_min, S_IWUSR | S_IRUGO,
+               show_in_min, set_in_min, 6);
+static SENSOR_DEVICE_ATTR(in0_max, S_IWUSR | S_IRUGO,
+               show_in_max, set_in_max, 0);
+static SENSOR_DEVICE_ATTR(in1_max, S_IWUSR | S_IRUGO,
+               show_in_max, set_in_max, 1);
+static SENSOR_DEVICE_ATTR(in2_max, S_IWUSR | S_IRUGO,
+               show_in_max, set_in_max, 2);
+static SENSOR_DEVICE_ATTR(in3_max, S_IWUSR | S_IRUGO,
+               show_in_max, set_in_max, 3);
+static SENSOR_DEVICE_ATTR(in4_max, S_IWUSR | S_IRUGO,
+               show_in_max, set_in_max, 4);
+static SENSOR_DEVICE_ATTR(in5_max, S_IWUSR | S_IRUGO,
+               show_in_max, set_in_max, 5);
+static SENSOR_DEVICE_ATTR(in6_max, S_IWUSR | S_IRUGO,
+               show_in_max, set_in_max, 6);
+static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, show_in_input, NULL, 0);
+static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in_input, NULL, 1);
+static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in_input, NULL, 2);
+static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in_input, NULL, 3);
+static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in_input, NULL, 4);
+static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in_input, NULL, 5);
+static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in_input, NULL, 6);
+static SENSOR_DEVICE_ATTR(fan1_min, S_IWUSR | S_IRUGO,
+               show_fan_min, set_fan_min, 0);
+static SENSOR_DEVICE_ATTR(fan2_min, S_IWUSR | S_IRUGO,
+               show_fan_min, set_fan_min, 1);
+static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0);
+static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1);
+static SENSOR_DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO,
+               show_fan_div, set_fan_div, 0);
+static SENSOR_DEVICE_ATTR(fan2_div, S_IWUSR | S_IRUGO,
+               show_fan_div, set_fan_div, 1);
 static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input1, NULL);
 static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_hot_max,
     set_temp_hot_max);
@@ -382,6 +367,17 @@ static DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_temp_os_max,
 static DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_temp_os_hyst,
     set_temp_os_hyst);
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
+static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
+static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 4);
+static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 5);
+static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6);
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 10);
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 11);
+static SENSOR_DEVICE_ATTR(temp1_max_alarm, S_IRUGO, show_alarm, NULL, 8);
+static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 13);
 
 /*
  * Real code
@@ -395,40 +391,50 @@ static int lm80_attach_adapter(struct i2c_adapter *adapter)
 }
 
 static struct attribute *lm80_attributes[] = {
-       &dev_attr_in0_min.attr,
-       &dev_attr_in1_min.attr,
-       &dev_attr_in2_min.attr,
-       &dev_attr_in3_min.attr,
-       &dev_attr_in4_min.attr,
-       &dev_attr_in5_min.attr,
-       &dev_attr_in6_min.attr,
-       &dev_attr_in0_max.attr,
-       &dev_attr_in1_max.attr,
-       &dev_attr_in2_max.attr,
-       &dev_attr_in3_max.attr,
-       &dev_attr_in4_max.attr,
-       &dev_attr_in5_max.attr,
-       &dev_attr_in6_max.attr,
-       &dev_attr_in0_input.attr,
-       &dev_attr_in1_input.attr,
-       &dev_attr_in2_input.attr,
-       &dev_attr_in3_input.attr,
-       &dev_attr_in4_input.attr,
-       &dev_attr_in5_input.attr,
-       &dev_attr_in6_input.attr,
-       &dev_attr_fan1_min.attr,
-       &dev_attr_fan2_min.attr,
-       &dev_attr_fan1_input.attr,
-       &dev_attr_fan2_input.attr,
-       &dev_attr_fan1_div.attr,
-       &dev_attr_fan2_div.attr,
+       &sensor_dev_attr_in0_min.dev_attr.attr,
+       &sensor_dev_attr_in1_min.dev_attr.attr,
+       &sensor_dev_attr_in2_min.dev_attr.attr,
+       &sensor_dev_attr_in3_min.dev_attr.attr,
+       &sensor_dev_attr_in4_min.dev_attr.attr,
+       &sensor_dev_attr_in5_min.dev_attr.attr,
+       &sensor_dev_attr_in6_min.dev_attr.attr,
+       &sensor_dev_attr_in0_max.dev_attr.attr,
+       &sensor_dev_attr_in1_max.dev_attr.attr,
+       &sensor_dev_attr_in2_max.dev_attr.attr,
+       &sensor_dev_attr_in3_max.dev_attr.attr,
+       &sensor_dev_attr_in4_max.dev_attr.attr,
+       &sensor_dev_attr_in5_max.dev_attr.attr,
+       &sensor_dev_attr_in6_max.dev_attr.attr,
+       &sensor_dev_attr_in0_input.dev_attr.attr,
+       &sensor_dev_attr_in1_input.dev_attr.attr,
+       &sensor_dev_attr_in2_input.dev_attr.attr,
+       &sensor_dev_attr_in3_input.dev_attr.attr,
+       &sensor_dev_attr_in4_input.dev_attr.attr,
+       &sensor_dev_attr_in5_input.dev_attr.attr,
+       &sensor_dev_attr_in6_input.dev_attr.attr,
+       &sensor_dev_attr_fan1_min.dev_attr.attr,
+       &sensor_dev_attr_fan2_min.dev_attr.attr,
+       &sensor_dev_attr_fan1_input.dev_attr.attr,
+       &sensor_dev_attr_fan2_input.dev_attr.attr,
+       &sensor_dev_attr_fan1_div.dev_attr.attr,
+       &sensor_dev_attr_fan2_div.dev_attr.attr,
        &dev_attr_temp1_input.attr,
        &dev_attr_temp1_max.attr,
        &dev_attr_temp1_max_hyst.attr,
        &dev_attr_temp1_crit.attr,
        &dev_attr_temp1_crit_hyst.attr,
        &dev_attr_alarms.attr,
-
+       &sensor_dev_attr_in0_alarm.dev_attr.attr,
+       &sensor_dev_attr_in1_alarm.dev_attr.attr,
+       &sensor_dev_attr_in2_alarm.dev_attr.attr,
+       &sensor_dev_attr_in3_alarm.dev_attr.attr,
+       &sensor_dev_attr_in4_alarm.dev_attr.attr,
+       &sensor_dev_attr_in5_alarm.dev_attr.attr,
+       &sensor_dev_attr_in6_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan1_alarm.dev_attr.attr,
+       &sensor_dev_attr_fan2_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_max_alarm.dev_attr.attr,
+       &sensor_dev_attr_temp1_crit_alarm.dev_attr.attr,
        NULL
 };
 
@@ -439,7 +445,7 @@ static const struct attribute_group lm80_group = {
 static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
 {
        int i, cur;
-       struct i2c_client *new_client;
+       struct i2c_client *client;
        struct lm80_data *data;
        int err = 0;
        const char *name;
@@ -455,21 +461,20 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
                goto exit;
        }
 
-       new_client = &data->client;
-       i2c_set_clientdata(new_client, data);
-       new_client->addr = address;
-       new_client->adapter = adapter;
-       new_client->driver = &lm80_driver;
-       new_client->flags = 0;
+       client = &data->client;
+       i2c_set_clientdata(client, data);
+       client->addr = address;
+       client->adapter = adapter;
+       client->driver = &lm80_driver;
 
        /* Now, we do the remaining detection. It is lousy. */
-       if (lm80_read_value(new_client, LM80_REG_ALARM2) & 0xc0)
+       if (lm80_read_value(client, LM80_REG_ALARM2) & 0xc0)
                goto error_free;
        for (i = 0x2a; i <= 0x3d; i++) {
-               cur = i2c_smbus_read_byte_data(new_client, i);
-               if ((i2c_smbus_read_byte_data(new_client, i + 0x40) != cur)
-                || (i2c_smbus_read_byte_data(new_client, i + 0x80) != cur)
-                || (i2c_smbus_read_byte_data(new_client, i + 0xc0) != cur))
+               cur = i2c_smbus_read_byte_data(client, i);
+               if ((i2c_smbus_read_byte_data(client, i + 0x40) != cur)
+                || (i2c_smbus_read_byte_data(client, i + 0x80) != cur)
+                || (i2c_smbus_read_byte_data(client, i + 0xc0) != cur))
                    goto error_free;
        }
 
@@ -477,27 +482,26 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
        kind = lm80;
        name = "lm80";
 
-       /* Fill in the remaining client fields and put it into the global list */
-       strlcpy(new_client->name, name, I2C_NAME_SIZE);
-       data->valid = 0;
+       /* Fill in the remaining client fields */
+       strlcpy(client->name, name, I2C_NAME_SIZE);
        mutex_init(&data->update_lock);
 
        /* Tell the I2C layer a new client has arrived */
-       if ((err = i2c_attach_client(new_client)))
+       if ((err = i2c_attach_client(client)))
                goto error_free;
 
        /* Initialize the LM80 chip */
-       lm80_init_client(new_client);
+       lm80_init_client(client);
 
        /* A few vars need to be filled upon startup */
-       data->fan_min[0] = lm80_read_value(new_client, LM80_REG_FAN_MIN(1));
-       data->fan_min[1] = lm80_read_value(new_client, LM80_REG_FAN_MIN(2));
+       data->fan_min[0] = lm80_read_value(client, LM80_REG_FAN_MIN(1));
+       data->fan_min[1] = lm80_read_value(client, LM80_REG_FAN_MIN(2));
 
        /* Register sysfs hooks */
-       if ((err = sysfs_create_group(&new_client->dev.kobj, &lm80_group)))
+       if ((err = sysfs_create_group(&client->dev.kobj, &lm80_group)))
                goto error_detach;
 
-       data->hwmon_dev = hwmon_device_register(&new_client->dev);
+       data->hwmon_dev = hwmon_device_register(&client->dev);
        if (IS_ERR(data->hwmon_dev)) {
                err = PTR_ERR(data->hwmon_dev);
                goto error_remove;
@@ -506,9 +510,9 @@ static int lm80_detect(struct i2c_adapter *adapter, int address, int kind)
        return 0;
 
 error_remove:
-       sysfs_remove_group(&new_client->dev.kobj, &lm80_group);
+       sysfs_remove_group(&client->dev.kobj, &lm80_group);
 error_detach:
-       i2c_detach_client(new_client);
+       i2c_detach_client(client);
 error_free:
        kfree(data);
 exit:
index 0336b4572a61bd8001d909b78d1c69979e7e9889..6e8903a6e902c38a1a686aedac5413159585a29e 100644 (file)
@@ -133,7 +133,6 @@ static struct i2c_driver lm83_driver = {
        .driver = {
                .name   = "lm83",
        },
-       .id             = I2C_DRIVERID_LM83,
        .attach_adapter = lm83_attach_adapter,
        .detach_client  = lm83_detach_client,
 };
index a02480be65f24db5e2c4fdca873d3b5682f92b10..4bb0f291a6b875afbf0ca4fdd9df5e6bbda72d34 100644 (file)
@@ -367,7 +367,6 @@ static struct i2c_driver lm85_driver = {
        .driver = {
                .name   = "lm85",
        },
-       .id             = I2C_DRIVERID_LM85,
        .attach_adapter = lm85_attach_adapter,
        .detach_client  = lm85_detach_client,
 };
@@ -444,12 +443,8 @@ static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, c
 
 static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
-       struct i2c_client *client = to_i2c_client(dev);
-       struct lm85_data *data = i2c_get_clientdata(client);
-       u32 val;
-
-       val = simple_strtoul(buf, NULL, 10);
-       data->vrm = val;
+       struct lm85_data *data = dev_get_drvdata(dev);
+       data->vrm = simple_strtoul(buf, NULL, 10);
        return count;
 }
 
@@ -519,17 +514,64 @@ static ssize_t show_pwm_enable(struct device *dev, struct device_attribute
 {
        int nr = to_sensor_dev_attr(attr)->index;
        struct lm85_data *data = lm85_update_device(dev);
-       int     pwm_zone;
+       int pwm_zone, enable;
 
        pwm_zone = ZONE_FROM_REG(data->autofan[nr].config);
-       return sprintf(buf,"%d\n", (pwm_zone != 0 && pwm_zone != -1) );
+       switch (pwm_zone) {
+       case -1:        /* PWM is always at 100% */
+               enable = 0;
+               break;
+       case 0:         /* PWM is always at 0% */
+       case -2:        /* PWM responds to manual control */
+               enable = 1;
+               break;
+       default:        /* PWM in automatic mode */
+               enable = 2;
+       }
+       return sprintf(buf, "%d\n", enable);
+}
+
+static ssize_t set_pwm_enable(struct device *dev, struct device_attribute
+               *attr, const char *buf, size_t count)
+{
+       int nr = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct lm85_data *data = i2c_get_clientdata(client);
+       long val = simple_strtol(buf, NULL, 10);
+       u8 config;
+
+       switch (val) {
+       case 0:
+               config = 3;
+               break;
+       case 1:
+               config = 7;
+               break;
+       case 2:
+               /* Here we have to choose arbitrarily one of the 5 possible
+                  configurations; I go for the safest */
+               config = 6;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       mutex_lock(&data->update_lock);
+       data->autofan[nr].config = lm85_read_value(client,
+               LM85_REG_AFAN_CONFIG(nr));
+       data->autofan[nr].config = (data->autofan[nr].config & ~0xe0)
+               | (config << 5);
+       lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr),
+               data->autofan[nr].config);
+       mutex_unlock(&data->update_lock);
+       return count;
 }
 
 #define show_pwm_reg(offset)                                           \
 static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR,              \
                show_pwm, set_pwm, offset - 1);                         \
-static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO,               \
-               show_pwm_enable, NULL, offset - 1)
+static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR,     \
+               show_pwm_enable, set_pwm_enable, offset - 1)
 
 show_pwm_reg(1);
 show_pwm_reg(2);
index 28cdff0c556b35eb9dba9f20ed3e9256ea26ac5b..8ee07c5c97a1df5b504dd8abaff0cd7b54e78709 100644 (file)
@@ -5,7 +5,7 @@
  *                          Philip Edelbrock <phil@netroedge.com>
  *                          Stephen Rousset <stephen.rousset@rocketlogix.com>
  *                          Dan Eaton <dan.eaton@rocketlogix.com>
- * Copyright (C) 2004       Jean Delvare <khali@linux-fr.org>
+ * Copyright (C) 2004,2007  Jean Delvare <khali@linux-fr.org>
  *
  * Original port to Linux 2.6 by Jeff Oliver.
  *
  * instead. The LM87 is the only hardware monitoring chipset I know of
  * which uses amplitude modulation. Be careful when using this feature.
  *
+ * This driver also supports the ADM1024, a sensor chip made by Analog
+ * Devices. That chip is fully compatible with the LM87. Complete
+ * datasheet can be obtained from Analog's website at:
+ *   http://www.analog.com/en/prod/0,2877,ADM1024,00.html
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -74,7 +79,7 @@ static unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, I2C_CLIENT_END };
  * Insmod parameters
  */
 
-I2C_CLIENT_INSMOD_1(lm87);
+I2C_CLIENT_INSMOD_2(lm87, adm1024);
 
 /*
  * The LM87 registers
@@ -166,7 +171,6 @@ static struct i2c_driver lm87_driver = {
        .driver = {
                .name   = "lm87",
        },
-       .id             = I2C_DRIVERID_LM87,
        .attach_adapter = lm87_attach_adapter,
        .detach_client  = lm87_detach_client,
 };
@@ -506,8 +510,7 @@ static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char
 }
 static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
-       struct i2c_client *client = to_i2c_client(dev);
-       struct lm87_data *data = i2c_get_clientdata(client);
+       struct lm87_data *data = dev_get_drvdata(dev);
        data->vrm = simple_strtoul(buf, NULL, 10);
        return count;
 }
@@ -662,6 +665,7 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
        struct i2c_client *new_client;
        struct lm87_data *data;
        int err = 0;
+       static const char *names[] = { "lm87", "adm1024" };
 
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
                goto exit;
@@ -686,11 +690,18 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
 
        /* Now, we do the remaining detection. */
        if (kind < 0) {
+               u8 cid = lm87_read_value(new_client, LM87_REG_COMPANY_ID);
                u8 rev = lm87_read_value(new_client, LM87_REG_REVISION);
 
-               if (rev < 0x01 || rev > 0x08
-                || (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80)
-                || lm87_read_value(new_client, LM87_REG_COMPANY_ID) != 0x02) {
+               if (cid == 0x02                 /* National Semiconductor */
+                && (rev >= 0x01 && rev <= 0x08))
+                       kind = lm87;
+               else if (cid == 0x41            /* Analog Devices */
+                     && (rev & 0xf0) == 0x10)
+                       kind = adm1024;
+
+               if (kind < 0
+                || (lm87_read_value(new_client, LM87_REG_CONFIG) & 0x80)) {
                        dev_dbg(&adapter->dev,
                                "LM87 detection failed at 0x%02x.\n",
                                address);
@@ -699,7 +710,7 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
        }
 
        /* We can fill in the remaining client fields */
-       strlcpy(new_client->name, "lm87", I2C_NAME_SIZE);
+       strlcpy(new_client->name, names[kind - 1], I2C_NAME_SIZE);
        data->valid = 0;
        mutex_init(&data->update_lock);
 
index 960df9fa75afe16cc4d0ecad7bf6130f4cb665e4..f7ec95bedbf6a5c294c0f17c6b97063aa3bd4da5 100644 (file)
@@ -204,7 +204,6 @@ static struct i2c_driver lm90_driver = {
        .driver = {
                .name   = "lm90",
        },
-       .id             = I2C_DRIVERID_LM90,
        .attach_adapter = lm90_attach_adapter,
        .detach_client  = lm90_detach_client,
 };
@@ -531,24 +530,24 @@ static int lm90_detect(struct i2c_adapter *adapter, int address, int kind)
                kind = lm90;
 
        if (kind < 0) { /* detection and identification */
-               u8 man_id, chip_id, reg_config1, reg_convrate;
-
-               if (lm90_read_reg(new_client, LM90_REG_R_MAN_ID,
-                                 &man_id) < 0
-                || lm90_read_reg(new_client, LM90_REG_R_CHIP_ID,
-                                 &chip_id) < 0
-                || lm90_read_reg(new_client, LM90_REG_R_CONFIG1,
-                                 &reg_config1) < 0
-                || lm90_read_reg(new_client, LM90_REG_R_CONVRATE,
-                                 &reg_convrate) < 0)
+               int man_id, chip_id, reg_config1, reg_convrate;
+
+               if ((man_id = i2c_smbus_read_byte_data(new_client,
+                                               LM90_REG_R_MAN_ID)) < 0
+                || (chip_id = i2c_smbus_read_byte_data(new_client,
+                                               LM90_REG_R_CHIP_ID)) < 0
+                || (reg_config1 = i2c_smbus_read_byte_data(new_client,
+                                               LM90_REG_R_CONFIG1)) < 0
+                || (reg_convrate = i2c_smbus_read_byte_data(new_client,
+                                               LM90_REG_R_CONVRATE)) < 0)
                        goto exit_free;
                
                if ((address == 0x4C || address == 0x4D)
                 && man_id == 0x01) { /* National Semiconductor */
-                       u8 reg_config2;
+                       int reg_config2;
 
-                       if (lm90_read_reg(new_client, LM90_REG_R_CONFIG2,
-                                         &reg_config2) < 0)
+                       if ((reg_config2 = i2c_smbus_read_byte_data(new_client,
+                                               LM90_REG_R_CONFIG2)) < 0)
                                goto exit_free;
 
                        if ((reg_config1 & 0x2A) == 0x00
index 61d1bd1d5b6e971d9e6a2f89bb885c36c3079951..af5c77d568fea208b9730c0e37a4ad8552df2e47 100644 (file)
@@ -428,7 +428,6 @@ static struct i2c_driver lm92_driver = {
        .driver = {
                .name   = "lm92",
        },
-       .id             = I2C_DRIVERID_LM92,
        .attach_adapter = lm92_attach_adapter,
        .detach_client  = lm92_detach_client,
 };
index 9d660133d517302535c1d42ef6e0ee79097b9acc..9b462bb13fa33b3b9cc67d66e884628a7e2043ba 100644 (file)
@@ -59,6 +59,10 @@ MODULE_PARM_DESC(init,
  " 2: Forcibly enable all voltage and temperature channels, except in9\n"
  " 3: Forcibly enable all voltage and temperature channels, including in9");
 
+static unsigned short force_id;
+module_param(force_id, ushort, 0);
+MODULE_PARM_DESC(force_id, "Override the detected device ID");
+
 /*
  * Super-I/O registers and operations
  */
@@ -826,7 +830,7 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
        /* No superio_enter */
 
        /* Identify device */
-       val = superio_inb(sioaddr, DEVID);
+       val = force_id ? force_id : superio_inb(sioaddr, DEVID);
        switch (val) {
        case 0xE1: /* PC87360 */
        case 0xE8: /* PC87363 */
index d40509ad6ae6233dc0a702f9887de6f11edde5fb..7265f22ae5cd1d6762822c67756e8f1f8967d422 100644 (file)
 #include <linux/ioport.h>
 #include <asm/io.h>
 
+static unsigned short force_id;
+module_param(force_id, ushort, 0);
+MODULE_PARM_DESC(force_id, "Override the detected device ID");
+
 static struct platform_device *pdev;
 
 #define DRVNAME "pc87427"
@@ -555,7 +559,7 @@ static int __init pc87427_find(int sioaddr, unsigned short *address)
        int i, err = 0;
 
        /* Identify device */
-       val = superio_inb(sioaddr, SIOREG_DEVID);
+       val = force_id ? force_id : superio_inb(sioaddr, SIOREG_DEVID);
        if (val != 0xf2) {      /* PC87427 */
                err = -ENODEV;
                goto exit;
index 0b57d2ea2cf714493dc9174e614190036b04ca09..f61d8f4185b243efcf7bd3fb0f10fa6284dde6d2 100644 (file)
 #include <linux/mutex.h>
 #include <asm/io.h>
 
+static unsigned short force_id;
+module_param(force_id, ushort, 0);
+MODULE_PARM_DESC(force_id, "Override the detected device ID");
+
 static struct platform_device *pdev;
 
 #define DRVNAME "smsc47b397"
@@ -333,7 +337,7 @@ static int __init smsc47b397_find(unsigned short *addr)
        u8 id, rev;
 
        superio_enter();
-       id = superio_inb(SUPERIO_REG_DEVID);
+       id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
 
        if ((id != 0x6f) && (id != 0x81) && (id != 0x85)) {
                superio_exit();
index a10a380868e2640b6d424e682e7400988a3e8ede..0d7f0c4d06bb5ef0e0e705a1a6c1d9a9026c83d3 100644 (file)
 #include <linux/sysfs.h>
 #include <asm/io.h>
 
+static unsigned short force_id;
+module_param(force_id, ushort, 0);
+MODULE_PARM_DESC(force_id, "Override the detected device ID");
+
 static struct platform_device *pdev;
 
 #define DRVNAME "smsc47m1"
@@ -399,7 +403,7 @@ static int __init smsc47m1_find(unsigned short *addr,
        u8 val;
 
        superio_enter();
-       val = superio_inb(SUPERIO_REG_DEVID);
+       val = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
 
        /*
         * SMSC LPC47M10x/LPC47M112/LPC47M13x (device id 0x59), LPC47M14x
index b87552652588ba3e411c0e50e3d3c3442c13f761..8b0c188e60f689624fd3701f201f0c7f8868c6d6 100644 (file)
@@ -341,8 +341,7 @@ static ssize_t show_vrm(struct device *dev, struct device_attribute *attr,
 static ssize_t set_vrm(struct device *dev, struct device_attribute *attr,
                const char *buf, size_t count)
 {
-       struct i2c_client *client = to_i2c_client(dev);
-       struct smsc47m192_data *data = i2c_get_clientdata(client);
+       struct smsc47m192_data *data = dev_get_drvdata(dev);
        data->vrm = simple_strtoul(buf, NULL, 10);
        return count;
 }
index 7dfcc8dd316dcadceb4362b13aaf877f9e0e7d79..12b43590fa53e7a5aa80e325b409437277be8dc1 100644 (file)
@@ -42,6 +42,10 @@ static int int_mode = -1;
 module_param(int_mode, int, 0);
 MODULE_PARM_DESC(int_mode, "Force the temperature interrupt mode");
 
+static unsigned short force_id;
+module_param(force_id, ushort, 0);
+MODULE_PARM_DESC(force_id, "Override the detected device ID");
+
 static struct platform_device *pdev;
 
 #define DRVNAME "vt1211"
@@ -1280,10 +1284,12 @@ EXIT:
 static int __init vt1211_find(int sio_cip, unsigned short *address)
 {
        int err = -ENODEV;
+       int devid;
 
        superio_enter(sio_cip);
 
-       if (superio_inb(sio_cip, SIO_VT1211_DEVID) != SIO_VT1211_ID) {
+       devid = force_id ? force_id : superio_inb(sio_cip, SIO_VT1211_DEVID);
+       if (devid != SIO_VT1211_ID) {
                goto EXIT;
        }
 
index 2196a84603f5b700178f6157dffbead54999d333..f87661775fe075ce6e42948e2efa6c5e51fb8176 100644 (file)
@@ -504,7 +504,7 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
        case 4: data->fan_div[nr] = 2; break;
        case 8: data->fan_div[nr] = 3; break;
        default:
-               dev_err(dev, "fan_div value %ld not supported."
+               dev_err(dev, "fan_div value %ld not supported. "
                        "Choose one of 1, 2, 4 or 8!\n", val);
                mutex_unlock(&data->update_lock);
                return -EINVAL;
index d5aa25ce5dbdc8251d05d384391c418070f80d9b..075164dd65a7a6716965538ac56d7b0320e14541 100644 (file)
@@ -59,6 +59,10 @@ static const char * w83627ehf_device_names[] = {
        "w83627dhg",
 };
 
+static unsigned short force_id;
+module_param(force_id, ushort, 0);
+MODULE_PARM_DESC(force_id, "Override the detected device ID");
+
 #define DRVNAME "w83627ehf"
 
 /*
@@ -1198,8 +1202,7 @@ static void w83627ehf_device_remove_files(struct device *dev)
                device_remove_file(dev, &sda_temp[i].dev_attr);
 
        device_remove_file(dev, &dev_attr_name);
-       if (data->vid != 0x3f)
-               device_remove_file(dev, &dev_attr_cpu0_vid);
+       device_remove_file(dev, &dev_attr_cpu0_vid);
 }
 
 /* Get the monitoring functions started */
@@ -1299,11 +1302,16 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
                        }
                }
 
-               data->vid = superio_inb(sio_data->sioreg, SIO_REG_VID_DATA) & 0x3f;
+               data->vid = superio_inb(sio_data->sioreg, SIO_REG_VID_DATA);
+               if (sio_data->kind == w83627ehf) /* 6 VID pins only */
+                       data->vid &= 0x3f;
+
+               err = device_create_file(dev, &dev_attr_cpu0_vid);
+               if (err)
+                       goto exit_release;
        } else {
                dev_info(dev, "VID pins in output mode, CPU VID not "
                         "available\n");
-               data->vid = 0x3f;
        }
 
        /* fan4 and fan5 share some pins with the GPIO and serial flash */
@@ -1386,12 +1394,6 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
        if (err)
                goto exit_remove;
 
-       if (data->vid != 0x3f) {
-               err = device_create_file(dev, &dev_attr_cpu0_vid);
-               if (err)
-                       goto exit_remove;
-       }
-
        data->hwmon_dev = hwmon_device_register(dev);
        if (IS_ERR(data->hwmon_dev)) {
                err = PTR_ERR(data->hwmon_dev);
@@ -1445,8 +1447,11 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
 
        superio_enter(sioaddr);
 
-       val = (superio_inb(sioaddr, SIO_REG_DEVID) << 8)
-           | superio_inb(sioaddr, SIO_REG_DEVID + 1);
+       if (force_id)
+               val = force_id;
+       else
+               val = (superio_inb(sioaddr, SIO_REG_DEVID) << 8)
+                   | superio_inb(sioaddr, SIO_REG_DEVID + 1);
        switch (val & SIO_ID_MASK) {
        case SIO_W83627EHF_ID:
                sio_data->kind = w83627ehf;
index 879d0a6544ccfb865ef0c6ddeead32e542f3a0bd..9564fb069957e958b1e115383605694c7219a624 100644 (file)
@@ -75,6 +75,10 @@ static int init = 1;
 module_param(init, bool, 0);
 MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
 
+static unsigned short force_id;
+module_param(force_id, ushort, 0);
+MODULE_PARM_DESC(force_id, "Override the detected device ID");
+
 /* modified from kernel/include/traps.c */
 static int REG;                /* The register to read/write */
 #define        DEV     0x07    /* Register: Logical device select */
@@ -319,10 +323,8 @@ static inline u8 pwm_freq_to_reg(unsigned long val)
                return (0x80 | (180000UL / (val << 8)));
 }
 
-#define BEEP_MASK_FROM_REG(val)                 (val)
-#define BEEP_MASK_TO_REG(val)          ((val) & 0xffffff)
-#define BEEP_ENABLE_TO_REG(val)                ((val)?1:0)
-#define BEEP_ENABLE_FROM_REG(val)      ((val)?1:0)
+#define BEEP_MASK_FROM_REG(val)                ((val) & 0xff7fff)
+#define BEEP_MASK_TO_REG(val)          ((val) & 0xff7fff)
 
 #define DIV_FROM_REG(val) (1 << (val))
 
@@ -363,7 +365,6 @@ struct w83627hf_data {
        u8 vid;                 /* Register encoding, combined */
        u32 alarms;             /* Register encoding, combined */
        u32 beep_mask;          /* Register encoding, combined */
-       u8 beep_enable;         /* Boolean */
        u8 pwm[3];              /* Register value */
        u8 pwm_freq[3];         /* Register value */
        u16 sens[3];            /* 1 = pentium diode; 2 = 3904 diode;
@@ -713,65 +714,151 @@ show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
 }
 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
 
-#define show_beep_reg(REG, reg) \
-static ssize_t show_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct w83627hf_data *data = w83627hf_update_device(dev); \
-       return sprintf(buf,"%ld\n", \
-                     (long)BEEP_##REG##_FROM_REG(data->beep_##reg)); \
+static ssize_t
+show_alarm(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct w83627hf_data *data = w83627hf_update_device(dev);
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
 }
-show_beep_reg(ENABLE, enable)
-show_beep_reg(MASK, mask)
+static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
+static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
+static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
+static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
+static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
+static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
+static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 10);
+static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16);
+static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17);
+static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
+static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
+static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11);
+static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
+static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
+static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13);
 
-#define BEEP_ENABLE                    0       /* Store beep_enable */
-#define BEEP_MASK                      1       /* Store beep_mask */
+static ssize_t
+show_beep_mask(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct w83627hf_data *data = w83627hf_update_device(dev);
+       return sprintf(buf, "%ld\n",
+                     (long)BEEP_MASK_FROM_REG(data->beep_mask));
+}
 
 static ssize_t
-store_beep_reg(struct device *dev, const char *buf, size_t count,
-              int update_mask)
+store_beep_mask(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count)
 {
        struct w83627hf_data *data = dev_get_drvdata(dev);
-       u32 val, val2;
+       unsigned long val;
 
        val = simple_strtoul(buf, NULL, 10);
 
        mutex_lock(&data->update_lock);
 
-       if (update_mask == BEEP_MASK) { /* We are storing beep_mask */
-               data->beep_mask = BEEP_MASK_TO_REG(val);
-               w83627hf_write_value(data, W83781D_REG_BEEP_INTS1,
-                                   data->beep_mask & 0xff);
-               w83627hf_write_value(data, W83781D_REG_BEEP_INTS3,
-                                   ((data->beep_mask) >> 16) & 0xff);
-               val2 = (data->beep_mask >> 8) & 0x7f;
-       } else {                /* We are storing beep_enable */
-               val2 =
-                   w83627hf_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f;
-               data->beep_enable = BEEP_ENABLE_TO_REG(val);
-       }
-
+       /* preserve beep enable */
+       data->beep_mask = (data->beep_mask & 0x8000)
+                       | BEEP_MASK_TO_REG(val);
+       w83627hf_write_value(data, W83781D_REG_BEEP_INTS1,
+                           data->beep_mask & 0xff);
+       w83627hf_write_value(data, W83781D_REG_BEEP_INTS3,
+                           ((data->beep_mask) >> 16) & 0xff);
        w83627hf_write_value(data, W83781D_REG_BEEP_INTS2,
-                           val2 | data->beep_enable << 7);
+                           (data->beep_mask >> 8) & 0xff);
 
        mutex_unlock(&data->update_lock);
        return count;
 }
 
-#define sysfs_beep(REG, reg) \
-static ssize_t show_regs_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       return show_beep_##reg(dev, attr, buf); \
-} \
-static ssize_t \
-store_regs_beep_##reg (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
-{ \
-       return store_beep_reg(dev, buf, count, BEEP_##REG); \
-} \
-static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, \
-                 show_regs_beep_##reg, store_regs_beep_##reg);
+static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR,
+                  show_beep_mask, store_beep_mask);
+
+static ssize_t
+show_beep(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct w83627hf_data *data = w83627hf_update_device(dev);
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
+}
+
+static ssize_t
+store_beep(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count)
+{
+       struct w83627hf_data *data = dev_get_drvdata(dev);
+       int bitnr = to_sensor_dev_attr(attr)->index;
+       unsigned long bit;
+       u8 reg;
+
+       bit = simple_strtoul(buf, NULL, 10);
+       if (bit & ~1)
+               return -EINVAL;
+
+       mutex_lock(&data->update_lock);
+       if (bit)
+               data->beep_mask |= (1 << bitnr);
+       else
+               data->beep_mask &= ~(1 << bitnr);
+
+       if (bitnr < 8) {
+               reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS1);
+               if (bit)
+                       reg |= (1 << bitnr);
+               else
+                       reg &= ~(1 << bitnr);
+               w83627hf_write_value(data, W83781D_REG_BEEP_INTS1, reg);
+       } else if (bitnr < 16) {
+               reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2);
+               if (bit)
+                       reg |= (1 << (bitnr - 8));
+               else
+                       reg &= ~(1 << (bitnr - 8));
+               w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, reg);
+       } else {
+               reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS3);
+               if (bit)
+                       reg |= (1 << (bitnr - 16));
+               else
+                       reg &= ~(1 << (bitnr - 16));
+               w83627hf_write_value(data, W83781D_REG_BEEP_INTS3, reg);
+       }
+       mutex_unlock(&data->update_lock);
+
+       return count;
+}
 
-sysfs_beep(ENABLE, enable);
-sysfs_beep(MASK, mask);
+static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 0);
+static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 1);
+static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 2);
+static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 3);
+static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 8);
+static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 9);
+static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 10);
+static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 16);
+static SENSOR_DEVICE_ATTR(in8_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 17);
+static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 6);
+static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 7);
+static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 11);
+static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 4);
+static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 5);
+static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 13);
+static SENSOR_DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
+                       show_beep, store_beep, 15);
 
 static ssize_t
 show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf)
@@ -1014,7 +1101,7 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr,
        VAL = sioaddr + 1;
 
        superio_enter();
-       val= superio_inb(DEVID);
+       val = force_id ? force_id : superio_inb(DEVID);
        switch (val) {
        case W627_DEVID:
                sio_data->type = w83627hf;
@@ -1073,23 +1160,31 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr,
 #define VIN_UNIT_ATTRS(_X_)    \
        &sensor_dev_attr_in##_X_##_input.dev_attr.attr,         \
        &sensor_dev_attr_in##_X_##_min.dev_attr.attr,           \
-       &sensor_dev_attr_in##_X_##_max.dev_attr.attr
+       &sensor_dev_attr_in##_X_##_max.dev_attr.attr,           \
+       &sensor_dev_attr_in##_X_##_alarm.dev_attr.attr,         \
+       &sensor_dev_attr_in##_X_##_beep.dev_attr.attr
 
 #define FAN_UNIT_ATTRS(_X_)    \
        &sensor_dev_attr_fan##_X_##_input.dev_attr.attr,        \
        &sensor_dev_attr_fan##_X_##_min.dev_attr.attr,          \
-       &sensor_dev_attr_fan##_X_##_div.dev_attr.attr
+       &sensor_dev_attr_fan##_X_##_div.dev_attr.attr,          \
+       &sensor_dev_attr_fan##_X_##_alarm.dev_attr.attr,        \
+       &sensor_dev_attr_fan##_X_##_beep.dev_attr.attr
 
 #define TEMP_UNIT_ATTRS(_X_)   \
        &sensor_dev_attr_temp##_X_##_input.dev_attr.attr,       \
        &sensor_dev_attr_temp##_X_##_max.dev_attr.attr,         \
        &sensor_dev_attr_temp##_X_##_max_hyst.dev_attr.attr,    \
-       &sensor_dev_attr_temp##_X_##_type.dev_attr.attr
+       &sensor_dev_attr_temp##_X_##_type.dev_attr.attr,        \
+       &sensor_dev_attr_temp##_X_##_alarm.dev_attr.attr,       \
+       &sensor_dev_attr_temp##_X_##_beep.dev_attr.attr
 
 static struct attribute *w83627hf_attributes[] = {
        &dev_attr_in0_input.attr,
        &dev_attr_in0_min.attr,
        &dev_attr_in0_max.attr,
+       &sensor_dev_attr_in0_alarm.dev_attr.attr,
+       &sensor_dev_attr_in0_beep.dev_attr.attr,
        VIN_UNIT_ATTRS(2),
        VIN_UNIT_ATTRS(3),
        VIN_UNIT_ATTRS(4),
@@ -1103,7 +1198,7 @@ static struct attribute *w83627hf_attributes[] = {
        TEMP_UNIT_ATTRS(2),
 
        &dev_attr_alarms.attr,
-       &dev_attr_beep_enable.attr,
+       &sensor_dev_attr_beep_enable.dev_attr.attr,
        &dev_attr_beep_mask.attr,
 
        &sensor_dev_attr_pwm1.dev_attr.attr,
@@ -1192,12 +1287,20 @@ static int __devinit w83627hf_probe(struct platform_device *pdev)
                                &sensor_dev_attr_in5_min.dev_attr))
                 || (err = device_create_file(dev,
                                &sensor_dev_attr_in5_max.dev_attr))
+                || (err = device_create_file(dev,
+                               &sensor_dev_attr_in5_alarm.dev_attr))
+                || (err = device_create_file(dev,
+                               &sensor_dev_attr_in5_beep.dev_attr))
                 || (err = device_create_file(dev,
                                &sensor_dev_attr_in6_input.dev_attr))
                 || (err = device_create_file(dev,
                                &sensor_dev_attr_in6_min.dev_attr))
                 || (err = device_create_file(dev,
                                &sensor_dev_attr_in6_max.dev_attr))
+                || (err = device_create_file(dev,
+                               &sensor_dev_attr_in6_alarm.dev_attr))
+                || (err = device_create_file(dev,
+                               &sensor_dev_attr_in6_beep.dev_attr))
                 || (err = device_create_file(dev,
                                &sensor_dev_attr_pwm1_freq.dev_attr))
                 || (err = device_create_file(dev,
@@ -1211,18 +1314,30 @@ static int __devinit w83627hf_probe(struct platform_device *pdev)
                                &sensor_dev_attr_in1_min.dev_attr))
                 || (err = device_create_file(dev,
                                &sensor_dev_attr_in1_max.dev_attr))
+                || (err = device_create_file(dev,
+                               &sensor_dev_attr_in1_alarm.dev_attr))
+                || (err = device_create_file(dev,
+                               &sensor_dev_attr_in1_beep.dev_attr))
                 || (err = device_create_file(dev,
                                &sensor_dev_attr_fan3_input.dev_attr))
                 || (err = device_create_file(dev,
                                &sensor_dev_attr_fan3_min.dev_attr))
                 || (err = device_create_file(dev,
                                &sensor_dev_attr_fan3_div.dev_attr))
+                || (err = device_create_file(dev,
+                               &sensor_dev_attr_fan3_alarm.dev_attr))
+                || (err = device_create_file(dev,
+                               &sensor_dev_attr_fan3_beep.dev_attr))
                 || (err = device_create_file(dev,
                                &sensor_dev_attr_temp3_input.dev_attr))
                 || (err = device_create_file(dev,
                                &sensor_dev_attr_temp3_max.dev_attr))
                 || (err = device_create_file(dev,
                                &sensor_dev_attr_temp3_max_hyst.dev_attr))
+                || (err = device_create_file(dev,
+                               &sensor_dev_attr_temp3_alarm.dev_attr))
+                || (err = device_create_file(dev,
+                               &sensor_dev_attr_temp3_beep.dev_attr))
                 || (err = device_create_file(dev,
                                &sensor_dev_attr_temp3_type.dev_attr)))
                        goto ERROR4;
@@ -1511,6 +1626,11 @@ static void __devinit w83627hf_init_device(struct platform_device *pdev)
                            (w83627hf_read_value(data,
                                                W83781D_REG_CONFIG) & 0xf7)
                            | 0x01);
+
+       /* Enable VBAT monitoring if needed */
+       tmp = w83627hf_read_value(data, W83781D_REG_VBAT);
+       if (!(tmp & 0x01))
+               w83627hf_write_value(data, W83781D_REG_VBAT, tmp | 0x01);
 }
 
 static void w83627hf_update_fan_div(struct w83627hf_data *data)
@@ -1603,8 +1723,7 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
                    (w83627hf_read_value(data, W83781D_REG_ALARM2) << 8) |
                    (w83627hf_read_value(data, W83781D_REG_ALARM3) << 16);
                i = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2);
-               data->beep_enable = i >> 7;
-               data->beep_mask = ((i & 0x7f) << 8) |
+               data->beep_mask = (i << 8) |
                    w83627hf_read_value(data, W83781D_REG_BEEP_INTS1) |
                    w83627hf_read_value(data, W83781D_REG_BEEP_INTS3) << 16;
                data->last_updated = jiffies;
index e0fa7520400d8c565f0b7c77034a6c0e35cf4a1a..7421f6ea53e1f8adf0afc7dd51c63c95acda76bb 100644 (file)
@@ -28,7 +28,6 @@
     as99127f   7       3       0       3       0x31    0x12c3  yes     no
     as99127f rev.2 (type_name = as99127f)      0x31    0x5ca3  yes     no
     w83781d    7       3       0       3       0x10-1  0x5ca3  yes     yes
-    w83627hf   9       3       2       3       0x21    0x5ca3  yes     yes(LPC)
     w83782d    9       3       2-4     3       0x30    0x5ca3  yes     yes
     w83783s    5-6     3       2       1-2     0x40    0x5ca3  yes     no
 
 static struct platform_device *pdev;
 
 /* Addresses to scan */
-static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
-                                       0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
-                                       0x2c, 0x2d, 0x2e, 0x2f, I2C_CLIENT_END };
+static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
+                                      0x2e, 0x2f, I2C_CLIENT_END };
 static unsigned short isa_address = 0x290;
 
 /* Insmod parameters */
-I2C_CLIENT_INSMOD_5(w83781d, w83782d, w83783s, w83627hf, as99127f);
+I2C_CLIENT_INSMOD_4(w83781d, w83782d, w83783s, as99127f);
 I2C_CLIENT_MODULE_PARM(force_subclients, "List of subclient addresses: "
                    "{bus, clientaddr, subclientaddr1, subclientaddr2}");
 
@@ -114,7 +112,7 @@ MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
 #define W83781D_REG_ALARM1             0x41
 #define W83781D_REG_ALARM2             0x42
 
-/* Real-time status (W83782D, W83783S, W83627HF) */
+/* Real-time status (W83782D, W83783S) */
 #define W83782D_REG_ALARM1             0x459
 #define W83782D_REG_ALARM2             0x45A
 #define W83782D_REG_ALARM3             0x45B
@@ -153,10 +151,6 @@ static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 };
 
 #define W83781D_DEFAULT_BETA           3435
 
-/* RT Table registers */
-#define W83781D_REG_RT_IDX             0x50
-#define W83781D_REG_RT_VAL             0x51
-
 /* Conversions */
 #define IN_TO_REG(val)                 SENSORS_LIMIT(((val) + 8) / 16, 0, 255)
 #define IN_FROM_REG(val)               ((val) * 16)
@@ -271,7 +265,6 @@ static struct i2c_driver w83781d_driver = {
        .driver = {
                .name = "w83781d",
        },
-       .id = I2C_DRIVERID_W83781D,
        .attach_adapter = w83781d_attach_adapter,
        .detach_client = w83781d_detach_client,
 };
@@ -696,7 +689,7 @@ store_fan_div(struct device *dev, struct device_attribute *da,
        unsigned long val = simple_strtoul(buf, NULL, 10);
 
        mutex_lock(&data->update_lock);
-       
+
        /* Save fan_min */
        min = FAN_FROM_REG(data->fan_min[nr],
                           DIV_FROM_REG(data->fan_div[nr]));
@@ -963,8 +956,6 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
                client_name = "w83782d subclient";
        else if (kind == w83783s)
                client_name = "w83783s subclient";
-       else if (kind == w83627hf)
-               client_name = "w83627hf subclient";
        else if (kind == as99127f)
                client_name = "as99127f subclient";
 
@@ -1004,7 +995,7 @@ ERROR_SC_0:
 #define IN_UNIT_ATTRS(X)                                       \
        &sensor_dev_attr_in##X##_input.dev_attr.attr,           \
        &sensor_dev_attr_in##X##_min.dev_attr.attr,             \
-       &sensor_dev_attr_in##X##_max.dev_attr.attr,             \
+       &sensor_dev_attr_in##X##_max.dev_attr.attr,             \
        &sensor_dev_attr_in##X##_alarm.dev_attr.attr,           \
        &sensor_dev_attr_in##X##_beep.dev_attr.attr
 
@@ -1268,9 +1259,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
                        kind = w83782d;
                else if (val1 == 0x40 && vendid == winbond && address == 0x2d)
                        kind = w83783s;
-               else if (val1 == 0x21 && vendid == winbond)
-                       kind = w83627hf;
-               else if (val1 == 0x31 && address >= 0x28)
+               else if (val1 == 0x31)
                        kind = as99127f;
                else {
                        if (kind == 0)
@@ -1288,8 +1277,6 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
                client_name = "w83782d";
        } else if (kind == w83783s) {
                client_name = "w83783s";
-       } else if (kind == w83627hf) {
-               client_name = "w83627hf";
        } else if (kind == as99127f) {
                client_name = "as99127f";
        }
@@ -1396,10 +1383,6 @@ w83781d_isa_probe(struct platform_device *pdev)
 
        reg = w83781d_read_value(data, W83781D_REG_WCHIPID);
        switch (reg) {
-       case 0x21:
-               data->type = w83627hf;
-               name = "w83627hf";
-               break;
        case 0x30:
                data->type = w83782d;
                name = "w83782d";
@@ -1453,9 +1436,9 @@ w83781d_isa_remove(struct platform_device *pdev)
 }
 
 /* The SMBus locks itself, usually, but nothing may access the Winbond between
-   bank switches. ISA access must always be locked explicitly! 
+   bank switches. ISA access must always be locked explicitly!
    We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks,
-   would slow down the W83781D access and should not be necessary. 
+   would slow down the W83781D access and should not be necessary.
    There are some ugly typecasts here, but the good news is - they should
    nowhere else be necessary! */
 static int
@@ -1599,11 +1582,6 @@ w83781d_init_device(struct device *dev)
        int type = data->type;
        u8 tmp;
 
-       if (type == w83627hf)
-               dev_info(dev, "The W83627HF chip is better supported by the "
-                        "w83627hf driver, support will be dropped from the "
-                        "w83781d driver soon\n");
-
        if (reset && type != as99127f) { /* this resets registers we don't have
                                           documentation for on the as99127f */
                /* Resetting the chip has been the default for a long time,
@@ -1717,8 +1695,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
                            w83781d_read_value(data, W83781D_REG_IN_MIN(i));
                        data->in_max[i] =
                            w83781d_read_value(data, W83781D_REG_IN_MAX(i));
-                       if ((data->type != w83782d)
-                           && (data->type != w83627hf) && (i == 6))
+                       if ((data->type != w83782d) && (i == 6))
                                break;
                }
                for (i = 0; i < 3; i++) {
@@ -1776,7 +1753,7 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
                        data->fan_div[1] |= (i >> 4) & 0x04;
                        data->fan_div[2] |= (i >> 5) & 0x04;
                }
-               if ((data->type == w83782d) || (data->type == w83627hf)) {
+               if (data->type == w83782d) {
                        data->alarms = w83781d_read_value(data,
                                                W83782D_REG_ALARM1)
                                     | (w83781d_read_value(data,
@@ -1886,13 +1863,11 @@ w83781d_isa_found(unsigned short address)
        outb_p(W83781D_REG_WCHIPID, address + W83781D_ADDR_REG_OFFSET);
        val = inb_p(address + W83781D_DATA_REG_OFFSET);
        if ((val & 0xfe) == 0x10        /* W83781D */
-        || val == 0x30                 /* W83782D */
-        || val == 0x21)                /* W83627HF */
+        || val == 0x30)                /* W83782D */
                found = 1;
 
        if (found)
                pr_info("w83781d: Found a %s chip at %#x\n",
-                       val == 0x21 ? "W83627HF" :
                        val == 0x30 ? "W83782D" : "W83781D", (int)address);
 
  release:
index a9c01a6f00571d0f39b9a0d6e2dbf3e483e54c5e..85bd21ee3298f7cbcc95eb7b63b8698000f0cbef 100644 (file)
@@ -840,14 +840,12 @@ static ssize_t store_vrm_reg(struct device *dev,
                                struct device_attribute *attr,
                                const char *buf, size_t count)
 {
-       struct i2c_client *client = to_i2c_client(dev);
-       struct w83791d_data *data = i2c_get_clientdata(client);
-       unsigned long val = simple_strtoul(buf, NULL, 10);
+       struct w83791d_data *data = dev_get_drvdata(dev);
 
        /* No lock needed as vrm is internal to the driver
           (not read from a chip register) and so is not
           updated in w83791d_update_device() */
-       data->vrm = val;
+       data->vrm = simple_strtoul(buf, NULL, 10);
 
        return count;
 }
index 48599e1cc554a829826939cc0285bbe58d1a751a..3ba1d6b334730e06a5ac30c7fddd54f4e97f7a78 100644 (file)
@@ -131,6 +131,7 @@ static u8 scale_in_add[] = { 0, 0, 0, 0, 0, 0, 0, 150, 150, 0 };
 #define PWM_DUTY                       0
 #define PWM_START                      1
 #define PWM_NONSTOP                    2
+#define PWM_STOP_TIME                  3
 #define W83793_REG_PWM(index, nr)      (((nr) == 0 ? 0xb3 : \
                                         (nr) == 1 ? 0x220 : 0x218) + (index))
 
@@ -242,9 +243,7 @@ static struct i2c_driver w83793_driver = {
 static ssize_t
 show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       struct i2c_client *client = to_i2c_client(dev);
-       struct w83793_data *data = i2c_get_clientdata(client);
-
+       struct w83793_data *data = dev_get_drvdata(dev);
        return sprintf(buf, "%d\n", data->vrm);
 }
 
@@ -263,9 +262,7 @@ static ssize_t
 store_vrm(struct device *dev, struct device_attribute *attr,
          const char *buf, size_t count)
 {
-       struct i2c_client *client = to_i2c_client(dev);
-       struct w83793_data *data = i2c_get_clientdata(client);
-
+       struct w83793_data *data = dev_get_drvdata(dev);
        data->vrm = simple_strtoul(buf, NULL, 10);
        return count;
 }
@@ -407,10 +404,6 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
        return count;
 }
 
-#define PWM_DUTY                       0
-#define PWM_START                      1
-#define PWM_NONSTOP                    2
-#define PWM_STOP_TIME                  3
 static ssize_t
 show_pwm(struct device *dev, struct device_attribute *attr, char *buf)
 {
index b5db354e2f198952a095d4ccf8e7632f9d591dc6..1d6259d29e74dc4b32e0926653f5ff27a1d45f91 100644 (file)
@@ -96,7 +96,6 @@ static struct i2c_driver w83l785ts_driver = {
        .driver = {
                .name   = "w83l785ts",
        },
-       .id             = I2C_DRIVERID_W83L785TS,
        .attach_adapter = w83l785ts_attach_adapter,
        .detach_client  = w83l785ts_detach_client,
 };
diff --git a/drivers/hwmon/w83l786ng.c b/drivers/hwmon/w83l786ng.c
new file mode 100644 (file)
index 0000000..1dbee4f
--- /dev/null
@@ -0,0 +1,821 @@
+/*
+    w83l786ng.c - Linux kernel driver for hardware monitoring
+    Copyright (c) 2007 Kevin Lo <kevlo@kevlo.org>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation - version 2.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+    02110-1301 USA.
+*/
+
+/*
+    Supports following chips:
+
+    Chip       #vin    #fanin  #pwm    #temp   wchipid vendid  i2c     ISA
+    w83l786ng  3       2       2       2       0x7b    0x5ca3  yes     no
+*/
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-vid.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+
+/* Addresses to scan */
+static unsigned short normal_i2c[] = { 0x2e, 0x2f, I2C_CLIENT_END };
+
+/* Insmod parameters */
+I2C_CLIENT_INSMOD_1(w83l786ng);
+
+static int reset;
+module_param(reset, bool, 0);
+MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended");
+
+#define W83L786NG_REG_IN_MIN(nr)       (0x2C + (nr) * 2)
+#define W83L786NG_REG_IN_MAX(nr)       (0x2B + (nr) * 2)
+#define W83L786NG_REG_IN(nr)           ((nr) + 0x20)
+
+#define W83L786NG_REG_FAN(nr)          ((nr) + 0x28)
+#define W83L786NG_REG_FAN_MIN(nr)      ((nr) + 0x3B)
+
+#define W83L786NG_REG_CONFIG           0x40
+#define W83L786NG_REG_ALARM1           0x41
+#define W83L786NG_REG_ALARM2           0x42
+#define W83L786NG_REG_GPIO_EN          0x47
+#define W83L786NG_REG_MAN_ID2          0x4C
+#define W83L786NG_REG_MAN_ID1          0x4D
+#define W83L786NG_REG_CHIP_ID          0x4E
+
+#define W83L786NG_REG_DIODE            0x53
+#define W83L786NG_REG_FAN_DIV          0x54
+#define W83L786NG_REG_FAN_CFG          0x80
+
+#define W83L786NG_REG_TOLERANCE                0x8D
+
+static const u8 W83L786NG_REG_TEMP[2][3] = {
+       { 0x25,         /* TEMP 0 in DataSheet */
+         0x35,         /* TEMP 0 Over in DataSheet */
+         0x36 },       /* TEMP 0 Hyst in DataSheet */
+       { 0x26,         /* TEMP 1 in DataSheet */
+         0x37,         /* TEMP 1 Over in DataSheet */
+         0x38 }        /* TEMP 1 Hyst in DataSheet */
+};
+
+static const u8 W83L786NG_PWM_MODE_SHIFT[] = {6, 7};
+static const u8 W83L786NG_PWM_ENABLE_SHIFT[] = {2, 4};
+
+/* FAN Duty Cycle, be used to control */
+static const u8 W83L786NG_REG_PWM[] = {0x81, 0x87};
+
+
+static inline u8
+FAN_TO_REG(long rpm, int div)
+{
+       if (rpm == 0)
+               return 255;
+       rpm = SENSORS_LIMIT(rpm, 1, 1000000);
+       return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
+}
+
+#define FAN_FROM_REG(val,div)  ((val) == 0   ? -1 : \
+                               ((val) == 255 ? 0 : \
+                               1350000 / ((val) * (div))))
+
+/* for temp */
+#define TEMP_TO_REG(val)       (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \
+                                   : (val)) / 1000, 0, 0xff))
+#define TEMP_FROM_REG(val)     (((val) & 0x80 ? (val)-0x100 : (val)) * 1000)
+
+/* The analog voltage inputs have 8mV LSB. Since the sysfs output is
+   in mV as would be measured on the chip input pin, need to just
+   multiply/divide by 8 to translate from/to register values. */
+#define IN_TO_REG(val)          (SENSORS_LIMIT((((val) + 4) / 8), 0, 255))
+#define IN_FROM_REG(val)       ((val) * 8)
+
+#define DIV_FROM_REG(val)      (1 << (val))
+
+static inline u8
+DIV_TO_REG(long val)
+{
+       int i;
+       val = SENSORS_LIMIT(val, 1, 128) >> 1;
+       for (i = 0; i < 7; i++) {
+               if (val == 0)
+                       break;
+               val >>= 1;
+       }
+       return ((u8) i);
+}
+
+struct w83l786ng_data {
+       struct i2c_client client;
+       struct device *hwmon_dev;
+       struct mutex update_lock;
+       char valid;                     /* !=0 if following fields are valid */
+       unsigned long last_updated;     /* In jiffies */
+       unsigned long last_nonvolatile; /* In jiffies, last time we update the
+                                          nonvolatile registers */
+
+       u8 in[3];
+       u8 in_max[3];
+       u8 in_min[3];
+       u8 fan[2];
+       u8 fan_div[2];
+       u8 fan_min[2];
+       u8 temp_type[2];
+       u8 temp[2][3];
+       u8 pwm[2];
+       u8 pwm_mode[2]; /* 0->DC variable voltage
+                          1->PWM variable duty cycle */
+
+       u8 pwm_enable[2]; /* 1->manual
+                            2->thermal cruise (also called SmartFan I) */
+       u8 tolerance[2];
+};
+
+static int w83l786ng_attach_adapter(struct i2c_adapter *adapter);
+static int w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind);
+static int w83l786ng_detach_client(struct i2c_client *client);
+static void w83l786ng_init_client(struct i2c_client *client);
+static struct w83l786ng_data *w83l786ng_update_device(struct device *dev);
+
+static struct i2c_driver w83l786ng_driver = {
+       .driver = {
+                  .name = "w83l786ng",
+       },
+       .attach_adapter = w83l786ng_attach_adapter,
+       .detach_client = w83l786ng_detach_client,
+};
+
+static u8
+w83l786ng_read_value(struct i2c_client *client, u8 reg)
+{
+       return i2c_smbus_read_byte_data(client, reg);
+}
+
+static int
+w83l786ng_write_value(struct i2c_client *client, u8 reg, u8 value)
+{
+       return i2c_smbus_write_byte_data(client, reg, value);
+}
+
+/* following are the sysfs callback functions */
+#define show_in_reg(reg) \
+static ssize_t \
+show_##reg(struct device *dev, struct device_attribute *attr, \
+           char *buf) \
+{ \
+       int nr = to_sensor_dev_attr(attr)->index; \
+       struct w83l786ng_data *data = w83l786ng_update_device(dev); \
+       return sprintf(buf,"%d\n", IN_FROM_REG(data->reg[nr])); \
+}
+
+show_in_reg(in)
+show_in_reg(in_min)
+show_in_reg(in_max)
+
+#define store_in_reg(REG, reg) \
+static ssize_t \
+store_in_##reg (struct device *dev, struct device_attribute *attr, \
+               const char *buf, size_t count) \
+{ \
+       int nr = to_sensor_dev_attr(attr)->index; \
+       struct i2c_client *client = to_i2c_client(dev); \
+       struct w83l786ng_data *data = i2c_get_clientdata(client); \
+       unsigned long val = simple_strtoul(buf, NULL, 10); \
+       mutex_lock(&data->update_lock); \
+       data->in_##reg[nr] = IN_TO_REG(val); \
+       w83l786ng_write_value(client, W83L786NG_REG_IN_##REG(nr), \
+                             data->in_##reg[nr]); \
+       mutex_unlock(&data->update_lock); \
+       return count; \
+}
+
+store_in_reg(MIN, min)
+store_in_reg(MAX, max)
+
+static struct sensor_device_attribute sda_in_input[] = {
+       SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0),
+       SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1),
+       SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
+};
+
+static struct sensor_device_attribute sda_in_min[] = {
+       SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 0),
+       SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 1),
+       SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 2),
+};
+
+static struct sensor_device_attribute sda_in_max[] = {
+       SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 0),
+       SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 1),
+       SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2),
+};
+
+#define show_fan_reg(reg) \
+static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
+                         char *buf) \
+{ \
+       int nr = to_sensor_dev_attr(attr)->index; \
+       struct w83l786ng_data *data = w83l786ng_update_device(dev); \
+        return sprintf(buf,"%d\n", \
+                FAN_FROM_REG(data->fan[nr], DIV_FROM_REG(data->fan_div[nr]))); \
+}
+
+show_fan_reg(fan);
+show_fan_reg(fan_min);
+
+static ssize_t
+store_fan_min(struct device *dev, struct device_attribute *attr,
+             const char *buf, size_t count)
+{
+       int nr = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct w83l786ng_data *data = i2c_get_clientdata(client);
+       u32 val;
+
+       val = simple_strtoul(buf, NULL, 10);
+       mutex_lock(&data->update_lock);
+       data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
+       w83l786ng_write_value(client, W83L786NG_REG_FAN_MIN(nr),
+                             data->fan_min[nr]);
+       mutex_unlock(&data->update_lock);
+
+       return count;
+}
+
+static ssize_t
+show_fan_div(struct device *dev, struct device_attribute *attr,
+            char *buf)
+{
+       int nr = to_sensor_dev_attr(attr)->index;
+       struct w83l786ng_data *data = w83l786ng_update_device(dev);
+       return sprintf(buf, "%u\n", DIV_FROM_REG(data->fan_div[nr]));
+}
+
+/* Note: we save and restore the fan minimum here, because its value is
+   determined in part by the fan divisor.  This follows the principle of
+   least surprise; the user doesn't expect the fan minimum to change just
+   because the divisor changed. */
+static ssize_t
+store_fan_div(struct device *dev, struct device_attribute *attr,
+             const char *buf, size_t count)
+{
+       int nr = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct w83l786ng_data *data = i2c_get_clientdata(client);
+
+       unsigned long min;
+       u8 tmp_fan_div;
+       u8 fan_div_reg;
+       u8 keep_mask = 0;
+       u8 new_shift = 0;
+
+       /* Save fan_min */
+       mutex_lock(&data->update_lock);
+       min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
+
+       data->fan_div[nr] = DIV_TO_REG(simple_strtoul(buf, NULL, 10));
+
+       switch (nr) {
+       case 0:
+               keep_mask = 0xf8;
+               new_shift = 0;
+               break;
+       case 1:
+               keep_mask = 0x8f;
+               new_shift = 4;
+               break;
+       }
+
+       fan_div_reg = w83l786ng_read_value(client, W83L786NG_REG_FAN_DIV)
+                                          & keep_mask;
+
+       tmp_fan_div = (data->fan_div[nr] << new_shift) & ~keep_mask;
+
+       w83l786ng_write_value(client, W83L786NG_REG_FAN_DIV,
+                             fan_div_reg | tmp_fan_div);
+
+       /* Restore fan_min */
+       data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
+       w83l786ng_write_value(client, W83L786NG_REG_FAN_MIN(nr),
+                             data->fan_min[nr]);
+       mutex_unlock(&data->update_lock);
+
+       return count;
+}
+
+static struct sensor_device_attribute sda_fan_input[] = {
+       SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0),
+       SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1),
+};
+
+static struct sensor_device_attribute sda_fan_min[] = {
+       SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min,
+                   store_fan_min, 0),
+       SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min,
+                   store_fan_min, 1),
+};
+
+static struct sensor_device_attribute sda_fan_div[] = {
+       SENSOR_ATTR(fan1_div, S_IWUSR | S_IRUGO, show_fan_div,
+                   store_fan_div, 0),
+       SENSOR_ATTR(fan2_div, S_IWUSR | S_IRUGO, show_fan_div,
+                   store_fan_div, 1),
+};
+
+
+/* read/write the temperature, includes measured value and limits */
+
+static ssize_t
+show_temp(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       struct sensor_device_attribute_2 *sensor_attr =
+           to_sensor_dev_attr_2(attr);
+       int nr = sensor_attr->nr;
+       int index = sensor_attr->index;
+       struct w83l786ng_data *data = w83l786ng_update_device(dev);
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index]));
+}
+
+static ssize_t
+store_temp(struct device *dev, struct device_attribute *attr,
+          const char *buf, size_t count)
+{
+       struct sensor_device_attribute_2 *sensor_attr =
+           to_sensor_dev_attr_2(attr);
+       int nr = sensor_attr->nr;
+       int index = sensor_attr->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct w83l786ng_data *data = i2c_get_clientdata(client);
+       s32 val;
+
+       val = simple_strtol(buf, NULL, 10);
+       mutex_lock(&data->update_lock);
+       data->temp[nr][index] = TEMP_TO_REG(val);
+       w83l786ng_write_value(client, W83L786NG_REG_TEMP[nr][index],
+                             data->temp[nr][index]);
+       mutex_unlock(&data->update_lock);
+
+        return count;
+}
+
+static struct sensor_device_attribute_2 sda_temp_input[] = {
+       SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
+       SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0),
+};
+
+static struct sensor_device_attribute_2 sda_temp_max[] = {
+       SENSOR_ATTR_2(temp1_max, S_IRUGO | S_IWUSR,
+                     show_temp, store_temp, 0, 1),
+       SENSOR_ATTR_2(temp2_max, S_IRUGO | S_IWUSR,
+                     show_temp, store_temp, 1, 1),
+};
+
+static struct sensor_device_attribute_2 sda_temp_max_hyst[] = {
+       SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO | S_IWUSR,
+                     show_temp, store_temp, 0, 2),
+       SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO | S_IWUSR,
+                     show_temp, store_temp, 1, 2),
+};
+
+#define show_pwm_reg(reg) \
+static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \
+                          char *buf) \
+{ \
+       struct w83l786ng_data *data = w83l786ng_update_device(dev); \
+       int nr = to_sensor_dev_attr(attr)->index; \
+       return sprintf(buf, "%d\n", data->reg[nr]); \
+}
+
+show_pwm_reg(pwm_mode)
+show_pwm_reg(pwm_enable)
+show_pwm_reg(pwm)
+
+static ssize_t
+store_pwm_mode(struct device *dev, struct device_attribute *attr,
+              const char *buf, size_t count)
+{
+       int nr = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct w83l786ng_data *data = i2c_get_clientdata(client);
+       u32 val = simple_strtoul(buf, NULL, 10);
+       u8 reg;
+
+       if (val > 1)
+               return -EINVAL;
+       mutex_lock(&data->update_lock);
+       data->pwm_mode[nr] = val;
+       reg = w83l786ng_read_value(client, W83L786NG_REG_FAN_CFG);
+       reg &= ~(1 << W83L786NG_PWM_MODE_SHIFT[nr]);
+       if (!val)
+               reg |= 1 << W83L786NG_PWM_MODE_SHIFT[nr];
+       w83l786ng_write_value(client, W83L786NG_REG_FAN_CFG, reg);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
+static ssize_t
+store_pwm(struct device *dev, struct device_attribute *attr,
+         const char *buf, size_t count)
+{
+       int nr = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct w83l786ng_data *data = i2c_get_clientdata(client);
+       u32 val = SENSORS_LIMIT(simple_strtoul(buf, NULL, 10), 0, 255);
+
+       mutex_lock(&data->update_lock);
+       data->pwm[nr] = val;
+       w83l786ng_write_value(client, W83L786NG_REG_PWM[nr], val);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
+static ssize_t
+store_pwm_enable(struct device *dev, struct device_attribute *attr,
+                const char *buf, size_t count)
+{
+       int nr = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct w83l786ng_data *data = i2c_get_clientdata(client);
+       u32 val = simple_strtoul(buf, NULL, 10);
+
+       u8 reg;
+
+       if (!val || (val > 2))  /* only modes 1 and 2 are supported */
+               return -EINVAL;
+
+       mutex_lock(&data->update_lock);
+       reg = w83l786ng_read_value(client, W83L786NG_REG_FAN_CFG);
+       data->pwm_enable[nr] = val;
+       reg &= ~(0x02 << W83L786NG_PWM_ENABLE_SHIFT[nr]);
+       reg |= (val - 1) << W83L786NG_PWM_ENABLE_SHIFT[nr];
+       w83l786ng_write_value(client, W83L786NG_REG_FAN_CFG, reg);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
+static struct sensor_device_attribute sda_pwm[] = {
+       SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0),
+       SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1),
+};
+
+static struct sensor_device_attribute sda_pwm_mode[] = {
+       SENSOR_ATTR(pwm1_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
+                   store_pwm_mode, 0),
+       SENSOR_ATTR(pwm2_mode, S_IWUSR | S_IRUGO, show_pwm_mode,
+                   store_pwm_mode, 1),
+};
+
+static struct sensor_device_attribute sda_pwm_enable[] = {
+       SENSOR_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
+                   store_pwm_enable, 0),
+       SENSOR_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_enable,
+                   store_pwm_enable, 1),
+};
+
+/* For Smart Fan I/Thermal Cruise and Smart Fan II */
+static ssize_t
+show_tolerance(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       int nr = to_sensor_dev_attr(attr)->index;
+       struct w83l786ng_data *data = w83l786ng_update_device(dev);
+       return sprintf(buf, "%ld\n", (long)data->tolerance[nr]);
+}
+
+static ssize_t
+store_tolerance(struct device *dev, struct device_attribute *attr,
+               const char *buf, size_t count)
+{
+       int nr = to_sensor_dev_attr(attr)->index;
+       struct i2c_client *client = to_i2c_client(dev);
+       struct w83l786ng_data *data = i2c_get_clientdata(client);
+       u32 val;
+       u8 tol_tmp, tol_mask;
+
+       val = simple_strtoul(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       tol_mask = w83l786ng_read_value(client,
+           W83L786NG_REG_TOLERANCE) & ((nr == 1) ? 0x0f : 0xf0);
+       tol_tmp = SENSORS_LIMIT(val, 0, 15);
+       tol_tmp &= 0x0f;
+       data->tolerance[nr] = tol_tmp;
+       if (nr == 1) {
+               tol_tmp <<= 4;
+       }
+
+       w83l786ng_write_value(client, W83L786NG_REG_TOLERANCE,
+                             tol_mask | tol_tmp);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
+static struct sensor_device_attribute sda_tolerance[] = {
+       SENSOR_ATTR(pwm1_tolerance, S_IWUSR | S_IRUGO,
+                   show_tolerance, store_tolerance, 0),
+       SENSOR_ATTR(pwm2_tolerance, S_IWUSR | S_IRUGO,
+                   show_tolerance, store_tolerance, 1),
+};
+
+
+#define IN_UNIT_ATTRS(X)       \
+       &sda_in_input[X].dev_attr.attr,         \
+       &sda_in_min[X].dev_attr.attr,           \
+       &sda_in_max[X].dev_attr.attr
+
+#define FAN_UNIT_ATTRS(X)      \
+       &sda_fan_input[X].dev_attr.attr,        \
+       &sda_fan_min[X].dev_attr.attr,          \
+       &sda_fan_div[X].dev_attr.attr
+
+#define TEMP_UNIT_ATTRS(X)     \
+       &sda_temp_input[X].dev_attr.attr,       \
+       &sda_temp_max[X].dev_attr.attr,         \
+       &sda_temp_max_hyst[X].dev_attr.attr
+
+#define PWM_UNIT_ATTRS(X)      \
+       &sda_pwm[X].dev_attr.attr,              \
+       &sda_pwm_mode[X].dev_attr.attr,         \
+       &sda_pwm_enable[X].dev_attr.attr
+
+#define TOLERANCE_UNIT_ATTRS(X)        \
+       &sda_tolerance[X].dev_attr.attr
+
+static struct attribute *w83l786ng_attributes[] = {
+       IN_UNIT_ATTRS(0),
+       IN_UNIT_ATTRS(1),
+       IN_UNIT_ATTRS(2),
+       FAN_UNIT_ATTRS(0),
+       FAN_UNIT_ATTRS(1),
+       TEMP_UNIT_ATTRS(0),
+       TEMP_UNIT_ATTRS(1),
+       PWM_UNIT_ATTRS(0),
+       PWM_UNIT_ATTRS(1),
+       TOLERANCE_UNIT_ATTRS(0),
+       TOLERANCE_UNIT_ATTRS(1),
+       NULL
+};
+
+static const struct attribute_group w83l786ng_group = {
+       .attrs = w83l786ng_attributes,
+};
+
+static int
+w83l786ng_attach_adapter(struct i2c_adapter *adapter)
+{
+       if (!(adapter->class & I2C_CLASS_HWMON))
+               return 0;
+       return i2c_probe(adapter, &addr_data, w83l786ng_detect);
+}
+
+static int
+w83l786ng_detect(struct i2c_adapter *adapter, int address, int kind)
+{
+       struct i2c_client *client;
+       struct device *dev;
+       struct w83l786ng_data *data;
+       int i, err = 0;
+       u8 reg_tmp;
+
+       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
+               goto exit;
+       }
+
+       /* OK. For now, we presume we have a valid client. We now create the
+          client structure, even though we cannot fill it completely yet.
+          But it allows us to access w83l786ng_{read,write}_value. */
+
+       if (!(data = kzalloc(sizeof(struct w83l786ng_data), GFP_KERNEL))) {
+               err = -ENOMEM;
+               goto exit;
+       }
+
+       client = &data->client;
+       dev = &client->dev;
+       i2c_set_clientdata(client, data);
+       client->addr = address;
+       client->adapter = adapter;
+       client->driver = &w83l786ng_driver;
+
+       /*
+        * Now we do the remaining detection. A negative kind means that
+        * the driver was loaded with no force parameter (default), so we
+        * must both detect and identify the chip (actually there is only
+        * one possible kind of chip for now, W83L786NG). A zero kind means
+        * that the driver was loaded with the force parameter, the detection
+        * step shall be skipped. A positive kind means that the driver
+        * was loaded with the force parameter and a given kind of chip is
+        * requested, so both the detection and the identification steps
+        * are skipped.
+        */
+       if (kind < 0) { /* detection */
+               if (((w83l786ng_read_value(client,
+                   W83L786NG_REG_CONFIG) & 0x80) != 0x00)) {
+                       dev_dbg(&adapter->dev,
+                               "W83L786NG detection failed at 0x%02x.\n",
+                               address);
+                       goto exit_free;
+               }
+       }
+
+       if (kind <= 0) { /* identification */
+               u16 man_id;
+               u8 chip_id;
+
+               man_id = (w83l786ng_read_value(client,
+                   W83L786NG_REG_MAN_ID1) << 8) +
+                   w83l786ng_read_value(client, W83L786NG_REG_MAN_ID2);
+               chip_id = w83l786ng_read_value(client, W83L786NG_REG_CHIP_ID);
+
+               if (man_id == 0x5CA3) { /* Winbond */
+                       if (chip_id == 0x80) { /* W83L786NG */
+                               kind = w83l786ng;
+                       }
+               }
+
+               if (kind <= 0) { /* identification failed */
+                       dev_info(&adapter->dev,
+                           "Unsupported chip (man_id=0x%04X, "
+                           "chip_id=0x%02X).\n", man_id, chip_id);
+                       goto exit_free;
+               }
+       }
+
+       /* Fill in the remaining client fields and put into the global list */
+       strlcpy(client->name, "w83l786ng", I2C_NAME_SIZE);
+       mutex_init(&data->update_lock);
+
+       /* Tell the I2C layer a new client has arrived */
+       if ((err = i2c_attach_client(client)))
+               goto exit_free;
+
+       /* Initialize the chip */
+       w83l786ng_init_client(client);
+
+       /* A few vars need to be filled upon startup */
+       for (i = 0; i < 2; i++) {
+               data->fan_min[i] = w83l786ng_read_value(client,
+                   W83L786NG_REG_FAN_MIN(i));
+       }
+
+       /* Update the fan divisor */
+       reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_FAN_DIV);
+       data->fan_div[0] = reg_tmp & 0x07;
+       data->fan_div[1] = (reg_tmp >> 4) & 0x07;
+
+       /* Register sysfs hooks */
+       if ((err = sysfs_create_group(&client->dev.kobj, &w83l786ng_group)))
+               goto exit_remove;
+
+       data->hwmon_dev = hwmon_device_register(dev);
+       if (IS_ERR(data->hwmon_dev)) {
+               err = PTR_ERR(data->hwmon_dev);
+               goto exit_remove;
+       }
+
+       return 0;
+
+       /* Unregister sysfs hooks */
+
+exit_remove:
+       sysfs_remove_group(&client->dev.kobj, &w83l786ng_group);
+       i2c_detach_client(client);
+exit_free:
+       kfree(data);
+exit:
+       return err;
+}
+
+static int
+w83l786ng_detach_client(struct i2c_client *client)
+{
+       struct w83l786ng_data *data = i2c_get_clientdata(client);
+       int err;
+
+       hwmon_device_unregister(data->hwmon_dev);
+       sysfs_remove_group(&client->dev.kobj, &w83l786ng_group);
+
+       if ((err = i2c_detach_client(client)))
+               return err;
+
+       kfree(data);
+
+       return 0;
+}
+
+static void
+w83l786ng_init_client(struct i2c_client *client)
+{
+       u8 tmp;
+
+       if (reset)
+               w83l786ng_write_value(client, W83L786NG_REG_CONFIG, 0x80);
+
+       /* Start monitoring */
+       tmp = w83l786ng_read_value(client, W83L786NG_REG_CONFIG);
+       if (!(tmp & 0x01))
+               w83l786ng_write_value(client, W83L786NG_REG_CONFIG, tmp | 0x01);
+}
+
+static struct w83l786ng_data *w83l786ng_update_device(struct device *dev)
+{
+       struct i2c_client *client = to_i2c_client(dev);
+       struct w83l786ng_data *data = i2c_get_clientdata(client);
+       int i, j;
+       u8 reg_tmp, pwmcfg;
+
+       mutex_lock(&data->update_lock);
+       if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
+           || !data->valid) {
+               dev_dbg(&client->dev, "Updating w83l786ng data.\n");
+
+               /* Update the voltages measured value and limits */
+               for (i = 0; i < 3; i++) {
+                       data->in[i] = w83l786ng_read_value(client,
+                           W83L786NG_REG_IN(i));
+                       data->in_min[i] = w83l786ng_read_value(client,
+                           W83L786NG_REG_IN_MIN(i));
+                       data->in_max[i] = w83l786ng_read_value(client,
+                           W83L786NG_REG_IN_MAX(i));
+               }
+
+               /* Update the fan counts and limits */
+               for (i = 0; i < 2; i++) {
+                       data->fan[i] = w83l786ng_read_value(client,
+                           W83L786NG_REG_FAN(i));
+                       data->fan_min[i] = w83l786ng_read_value(client,
+                           W83L786NG_REG_FAN_MIN(i));
+               }
+
+               /* Update the fan divisor */
+               reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_FAN_DIV);
+               data->fan_div[0] = reg_tmp & 0x07;
+               data->fan_div[1] = (reg_tmp >> 4) & 0x07;
+
+               pwmcfg = w83l786ng_read_value(client, W83L786NG_REG_FAN_CFG);
+               for (i = 0; i < 2; i++) {
+                       data->pwm_mode[i] =
+                           ((pwmcfg >> W83L786NG_PWM_MODE_SHIFT[i]) & 1)
+                           ? 0 : 1;
+                       data->pwm_enable[i] =
+                           ((pwmcfg >> W83L786NG_PWM_ENABLE_SHIFT[i]) & 2) + 1;
+                       data->pwm[i] = w83l786ng_read_value(client,
+                           W83L786NG_REG_PWM[i]);
+               }
+
+
+               /* Update the temperature sensors */
+               for (i = 0; i < 2; i++) {
+                       for (j = 0; j < 3; j++) {
+                               data->temp[i][j] = w83l786ng_read_value(client,
+                                   W83L786NG_REG_TEMP[i][j]);
+                       }
+               }
+
+               /* Update Smart Fan I/II tolerance */
+               reg_tmp = w83l786ng_read_value(client, W83L786NG_REG_TOLERANCE);
+               data->tolerance[0] = reg_tmp & 0x0f;
+               data->tolerance[1] = (reg_tmp >> 4) & 0x0f;
+
+               data->last_updated = jiffies;
+               data->valid = 1;
+
+       }
+
+       mutex_unlock(&data->update_lock);
+
+       return data;
+}
+
+static int __init
+sensors_w83l786ng_init(void)
+{
+       return i2c_add_driver(&w83l786ng_driver);
+}
+
+static void __exit
+sensors_w83l786ng_exit(void)
+{
+       i2c_del_driver(&w83l786ng_driver);
+}
+
+MODULE_AUTHOR("Kevin Lo");
+MODULE_DESCRIPTION("w83l786ng driver");
+MODULE_LICENSE("GPL");
+
+module_init(sensors_w83l786ng_init);
+module_exit(sensors_w83l786ng_exit);
index fde297b21ad72b8dc36eddcc2d2e65ae0f5b4954..7dee001e5133bc7df391bc187e28ae082b9315d2 100644 (file)
@@ -71,7 +71,6 @@ static struct i2c_driver eeprom_driver = {
        .driver = {
                .name   = "eeprom",
        },
-       .id             = I2C_DRIVERID_EEPROM,
        .attach_adapter = eeprom_attach_adapter,
        .detach_client  = eeprom_detach_client,
 };
index b3b830ccf209ec7e0b1aac96f14bc8d5e8797943..e5b31329b56e146e1022be115c0d7e0cbdc88ede 100644 (file)
@@ -67,7 +67,6 @@ static struct i2c_driver pcf8574_driver = {
        .driver = {
                .name   = "pcf8574",
        },
-       .id             = I2C_DRIVERID_PCF8574,
        .attach_adapter = pcf8574_attach_adapter,
        .detach_client  = pcf8574_detach_client,
 };
index 865f4409c06bd343ee3c5f66b8595a17170a9318..66c7c3bb9429754bbe7f6c31737feefdda750fa0 100644 (file)
@@ -92,7 +92,6 @@ static struct i2c_driver pcf8591_driver = {
        .driver = {
                .name   = "pcf8591",
        },
-       .id             = I2C_DRIVERID_PCF8591,
        .attach_adapter = pcf8591_attach_adapter,
        .detach_client  = pcf8591_detach_client,
 };
index 06190b1c4ec5ef5e310223c2dbbee6414a5726b7..38fbfb8d5445fe8ee0c1d9825691186f58ef0957 100644 (file)
@@ -17,7 +17,6 @@
 #include <linux/ptrace.h>
 #include <linux/slab.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/tty.h>
 #include <linux/major.h>
 #include <linux/interrupt.h>
index f32e031dcb27f53a04f1c774b283ce2381dadd4d..708c5ae13b24f33cb6b8b323996c2332d84520b7 100644 (file)
@@ -1,6 +1,4 @@
 /*
- * $Id: analog.c,v 1.68 2002/01/22 20:18:32 vojtech Exp $
- *
  *  Copyright (c) 1996-2001 Vojtech Pavlik
  */
 
@@ -164,6 +162,10 @@ static unsigned int get_time_pit(void)
 #define GET_TIME(x)    do { x = get_cycles(); } while (0)
 #define DELTA(x,y)     ((y)-(x))
 #define TIME_NAME      "PCC"
+#elif defined(CONFIG_MN10300)
+#define GET_TIME(x)    do { x = get_cycles(); } while (0)
+#define DELTA(x, y)    ((x) - (y))
+#define TIME_NAME      "TSC"
 #else
 #define FAKE_TIME
 static unsigned long analog_faketime = 0;
index 2dd1b57b0ba4959ab9578eb9de478410225e7094..6d7c47ec0367aa39026c358ad3948200893fe19c 100644 (file)
@@ -52,6 +52,7 @@ static int capifs_remount(struct super_block *s, int *flags, char *data)
        gid_t gid = 0;
        umode_t mode = 0600;
        char *this_char;
+       char *new_opt = kstrdup(data, GFP_KERNEL);
 
        this_char = NULL;
        while ((this_char = strsep(&data, ",")) != NULL) {
@@ -72,11 +73,16 @@ static int capifs_remount(struct super_block *s, int *flags, char *data)
                        return -EINVAL;
                }
        }
+
+       kfree(s->s_options);
+       s->s_options = new_opt;
+
        config.setuid  = setuid;
        config.setgid  = setgid;
        config.uid     = uid;
        config.gid     = gid;
        config.mode    = mode;
+
        return 0;
 }
 
@@ -84,6 +90,7 @@ static struct super_operations capifs_sops =
 {
        .statfs         = simple_statfs,
        .remount_fs     = capifs_remount,
+       .show_options   = generic_show_options,
 };
 
 
index c0d7036404a5920a7404a1d7c8acd9bc591df93d..341faf58a65c5d76cdaa1ab252bb54186f5d9780 100644 (file)
@@ -744,8 +744,7 @@ dbusy_timer_handler(struct IsdnCardState *cs)
 
 
 
-void __devinit
-Amd7930_init(struct IsdnCardState *cs)
+void Amd7930_init(struct IsdnCardState *cs)
 {
     WORD *ptr;
     BYTE cmd, cnt;
index 851a3b01781e71e05a1bb1fa7d5cdc1e05cc7187..859814f62cb07e5f1e14ea71c012a70560e988e9 100644 (file)
@@ -18,6 +18,13 @@ config LEDS_CLASS
 
 comment "LED drivers"
 
+config LEDS_ATMEL_PWM
+       tristate "LED Support using Atmel PWM outputs"
+       depends on LEDS_CLASS && ATMEL_PWM
+       help
+         This option enables support for LEDs driven using outputs
+         of the dedicated PWM controller found on newer Atmel SOCs.
+
 config LEDS_CORGI
        tristate "LED Support for the Sharp SL-C7x0 series"
        depends on LEDS_CLASS && PXA_SHARP_C7xx
index bc6afc8dcb278d8be7e3b71cfe65412649da6c32..84ced3b1a13d0d85b9082255e38bc7b75d2426fe 100644 (file)
@@ -5,6 +5,7 @@ obj-$(CONFIG_LEDS_CLASS)                += led-class.o
 obj-$(CONFIG_LEDS_TRIGGERS)            += led-triggers.o
 
 # LED Platform Drivers
+obj-$(CONFIG_LEDS_ATMEL_PWM)           += leds-atmel-pwm.o
 obj-$(CONFIG_LEDS_CORGI)               += leds-corgi.o
 obj-$(CONFIG_LEDS_LOCOMO)              += leds-locomo.o
 obj-$(CONFIG_LEDS_SPITZ)               += leds-spitz.o
diff --git a/drivers/leds/leds-atmel-pwm.c b/drivers/leds/leds-atmel-pwm.c
new file mode 100644 (file)
index 0000000..af61f55
--- /dev/null
@@ -0,0 +1,157 @@
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/leds.h>
+#include <linux/io.h>
+#include <linux/atmel_pwm.h>
+
+
+struct pwmled {
+       struct led_classdev     cdev;
+       struct pwm_channel      pwmc;
+       struct gpio_led         *desc;
+       u32                     mult;
+       u8                      active_low;
+};
+
+
+/*
+ * For simplicity, we use "brightness" as if it were a linear function
+ * of PWM duty cycle.  However, a logarithmic function of duty cycle is
+ * probably a better match for perceived brightness: two is half as bright
+ * as four, four is half as bright as eight, etc
+ */
+static void pwmled_brightness(struct led_classdev *cdev, enum led_brightness b)
+{
+       struct pwmled            *led;
+
+       /* update the duty cycle for the *next* period */
+       led = container_of(cdev, struct pwmled, cdev);
+       pwm_channel_writel(&led->pwmc, PWM_CUPD, led->mult * (unsigned) b);
+}
+
+/*
+ * NOTE:  we reuse the platform_data structure of GPIO leds,
+ * but repurpose its "gpio" number as a PWM channel number.
+ */
+static int __init pwmled_probe(struct platform_device *pdev)
+{
+       const struct gpio_led_platform_data     *pdata;
+       struct pwmled                           *leds;
+       unsigned                                i;
+       int                                     status;
+
+       pdata = pdev->dev.platform_data;
+       if (!pdata || pdata->num_leds < 1)
+               return -ENODEV;
+
+       leds = kcalloc(pdata->num_leds, sizeof(*leds), GFP_KERNEL);
+       if (!leds)
+               return -ENOMEM;
+
+       for (i = 0; i < pdata->num_leds; i++) {
+               struct pwmled           *led = leds + i;
+               const struct gpio_led   *dat = pdata->leds + i;
+               u32                     tmp;
+
+               led->cdev.name = dat->name;
+               led->cdev.brightness = LED_OFF;
+               led->cdev.brightness_set = pwmled_brightness;
+               led->cdev.default_trigger = dat->default_trigger;
+
+               led->active_low = dat->active_low;
+
+               status = pwm_channel_alloc(dat->gpio, &led->pwmc);
+               if (status < 0)
+                       goto err;
+
+               /*
+                * Prescale clock by 2^x, so PWM counts in low MHz.
+                * Start each cycle with the LED active, so increasing
+                * the duty cycle gives us more time on (== brighter).
+                */
+               tmp = 5;
+               if (!led->active_low)
+                       tmp |= PWM_CPR_CPOL;
+               pwm_channel_writel(&led->pwmc, PWM_CMR, tmp);
+
+               /*
+                * Pick a period so PWM cycles at 100+ Hz; and a multiplier
+                * for scaling duty cycle:  brightness * mult.
+                */
+               tmp = (led->pwmc.mck / (1 << 5)) / 100;
+               tmp /= 255;
+               led->mult = tmp;
+               pwm_channel_writel(&led->pwmc, PWM_CDTY,
+                               led->cdev.brightness * 255);
+               pwm_channel_writel(&led->pwmc, PWM_CPRD,
+                               LED_FULL * tmp);
+
+               pwm_channel_enable(&led->pwmc);
+
+               /* Hand it over to the LED framework */
+               status = led_classdev_register(&pdev->dev, &led->cdev);
+               if (status < 0) {
+                       pwm_channel_free(&led->pwmc);
+                       goto err;
+               }
+       }
+
+       platform_set_drvdata(pdev, leds);
+       return 0;
+
+err:
+       if (i > 0) {
+               for (i = i - 1; i >= 0; i--) {
+                       led_classdev_unregister(&leds[i].cdev);
+                       pwm_channel_free(&leds[i].pwmc);
+               }
+       }
+       kfree(leds);
+
+       return status;
+}
+
+static int __exit pwmled_remove(struct platform_device *pdev)
+{
+       const struct gpio_led_platform_data     *pdata;
+       struct pwmled                           *leds;
+       unsigned                                i;
+
+       pdata = pdev->dev.platform_data;
+       leds = platform_get_drvdata(pdev);
+
+       for (i = 0; i < pdata->num_leds; i++) {
+               struct pwmled           *led = leds + i;
+
+               led_classdev_unregister(&led->cdev);
+               pwm_channel_free(&led->pwmc);
+       }
+
+       kfree(leds);
+       platform_set_drvdata(pdev, NULL);
+       return 0;
+}
+
+static struct platform_driver pwmled_driver = {
+       .driver = {
+               .name =         "leds-atmel-pwm",
+               .owner =        THIS_MODULE,
+       },
+       /* REVISIT add suspend() and resume() methods */
+       .remove =       __exit_p(pwmled_remove),
+};
+
+static int __init modinit(void)
+{
+       return platform_driver_probe(&pwmled_driver, pwmled_probe);
+}
+module_init(modinit);
+
+static void __exit modexit(void)
+{
+       platform_driver_unregister(&pwmled_driver);
+}
+module_exit(modexit);
+
+MODULE_DESCRIPTION("Driver for LEDs with PWM-controlled brightness");
+MODULE_LICENSE("GPL");
index 84f85e23cca7a65a86b3ffa3647953373c5339b3..1b2ec0bf5eb11d9fedfeb65b035e89efe683d013 100644 (file)
@@ -47,7 +47,7 @@ struct lguest_device {
 /* Since the virtio infrastructure hands us a pointer to the virtio_device all
  * the time, it helps to have a curt macro to get a pointer to the struct
  * lguest_device it's enclosed in.  */
-#define to_lgdev(vdev) container_of(vdev, struct lguest_device, vdev)
+#define to_lgdev(vd) container_of(vd, struct lguest_device, vdev)
 
 /*D:130
  * Device configurations
index 3fa7c77d9bd91479c619ee9bced6a6c42d63a654..610af916891ec2328ef14e20bacf99d9475fefb9 100644 (file)
@@ -204,7 +204,7 @@ config BLK_DEV_DM
 
 config DM_DEBUG
        boolean "Device mapper debugging support"
-       depends on BLK_DEV_DM && EXPERIMENTAL
+       depends on BLK_DEV_DM
        ---help---
          Enable this for messages that may help debug device-mapper problems.
 
@@ -212,7 +212,7 @@ config DM_DEBUG
 
 config DM_CRYPT
        tristate "Crypt target support"
-       depends on BLK_DEV_DM && EXPERIMENTAL
+       depends on BLK_DEV_DM
        select CRYPTO
        select CRYPTO_CBC
        ---help---
@@ -230,34 +230,34 @@ config DM_CRYPT
          If unsure, say N.
 
 config DM_SNAPSHOT
-       tristate "Snapshot target (EXPERIMENTAL)"
-       depends on BLK_DEV_DM && EXPERIMENTAL
+       tristate "Snapshot target"
+       depends on BLK_DEV_DM
        ---help---
          Allow volume managers to take writable snapshots of a device.
 
 config DM_MIRROR
-       tristate "Mirror target (EXPERIMENTAL)"
-       depends on BLK_DEV_DM && EXPERIMENTAL
+       tristate "Mirror target"
+       depends on BLK_DEV_DM
        ---help---
          Allow volume managers to mirror logical volumes, also
          needed for live data migration tools such as 'pvmove'.
 
 config DM_ZERO
-       tristate "Zero target (EXPERIMENTAL)"
-       depends on BLK_DEV_DM && EXPERIMENTAL
+       tristate "Zero target"
+       depends on BLK_DEV_DM
        ---help---
          A target that discards writes, and returns all zeroes for
          reads.  Useful in some recovery situations.
 
 config DM_MULTIPATH
-       tristate "Multipath target (EXPERIMENTAL)"
-       depends on BLK_DEV_DM && EXPERIMENTAL
+       tristate "Multipath target"
+       depends on BLK_DEV_DM
        ---help---
          Allow volume managers to support multipath hardware.
 
 config DM_MULTIPATH_EMC
-       tristate "EMC CX/AX multipath support (EXPERIMENTAL)"
-       depends on DM_MULTIPATH && BLK_DEV_DM && EXPERIMENTAL
+       tristate "EMC CX/AX multipath support"
+       depends on DM_MULTIPATH && BLK_DEV_DM
        ---help---
          Multipath support for EMC CX/AX series hardware.
 
index 6b66ee46b87d5b44e0023ef3248656b3a9e7ed36..b04f98df94ea310db726b91be82eacf090a71ae1 100644 (file)
@@ -1,11 +1,12 @@
 /*
  * Copyright (C) 2003 Christophe Saout <christophe@saout.de>
  * Copyright (C) 2004 Clemens Fruhwirth <clemens@endorphin.org>
- * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2006-2007 Red Hat, Inc. All rights reserved.
  *
  * This file is released under the GPL.
  */
 
+#include <linux/completion.h>
 #include <linux/err.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #define DM_MSG_PREFIX "crypt"
 #define MESG_STR(x) x, sizeof(x)
 
-/*
- * per bio private data
- */
-struct dm_crypt_io {
-       struct dm_target *target;
-       struct bio *base_bio;
-       struct work_struct work;
-       atomic_t pending;
-       int error;
-};
-
 /*
  * context holding the current state of a multi-part conversion
  */
 struct convert_context {
+       struct completion restart;
        struct bio *bio_in;
        struct bio *bio_out;
        unsigned int offset_in;
@@ -49,7 +40,27 @@ struct convert_context {
        unsigned int idx_in;
        unsigned int idx_out;
        sector_t sector;
-       int write;
+       atomic_t pending;
+};
+
+/*
+ * per bio private data
+ */
+struct dm_crypt_io {
+       struct dm_target *target;
+       struct bio *base_bio;
+       struct work_struct work;
+
+       struct convert_context ctx;
+
+       atomic_t pending;
+       int error;
+       sector_t sector;
+};
+
+struct dm_crypt_request {
+       struct scatterlist sg_in;
+       struct scatterlist sg_out;
 };
 
 struct crypt_config;
@@ -72,10 +83,11 @@ struct crypt_config {
        sector_t start;
 
        /*
-        * pool for per bio private data and
-        * for encryption buffer pages
+        * pool for per bio private data, crypto requests and
+        * encryption requeusts/buffer pages
         */
        mempool_t *io_pool;
+       mempool_t *req_pool;
        mempool_t *page_pool;
        struct bio_set *bs;
 
@@ -93,9 +105,25 @@ struct crypt_config {
        sector_t iv_offset;
        unsigned int iv_size;
 
+       /*
+        * Layout of each crypto request:
+        *
+        *   struct ablkcipher_request
+        *      context
+        *      padding
+        *   struct dm_crypt_request
+        *      padding
+        *   IV
+        *
+        * The padding is added so that dm_crypt_request and the IV are
+        * correctly aligned.
+        */
+       unsigned int dmreq_start;
+       struct ablkcipher_request *req;
+
        char cipher[CRYPTO_MAX_ALG_NAME];
        char chainmode[CRYPTO_MAX_ALG_NAME];
-       struct crypto_blkcipher *tfm;
+       struct crypto_ablkcipher *tfm;
        unsigned long flags;
        unsigned int key_size;
        u8 key[0];
@@ -108,6 +136,7 @@ struct crypt_config {
 static struct kmem_cache *_crypt_io_pool;
 
 static void clone_init(struct dm_crypt_io *, struct bio *);
+static void kcryptd_queue_crypt(struct dm_crypt_io *io);
 
 /*
  * Different IV generation algorithms:
@@ -188,7 +217,7 @@ static int crypt_iv_essiv_ctr(struct crypt_config *cc, struct dm_target *ti,
                return PTR_ERR(essiv_tfm);
        }
        if (crypto_cipher_blocksize(essiv_tfm) !=
-           crypto_blkcipher_ivsize(cc->tfm)) {
+           crypto_ablkcipher_ivsize(cc->tfm)) {
                ti->error = "Block size of ESSIV cipher does "
                            "not match IV size of block cipher";
                crypto_free_cipher(essiv_tfm);
@@ -225,7 +254,7 @@ static int crypt_iv_essiv_gen(struct crypt_config *cc, u8 *iv, sector_t sector)
 static int crypt_iv_benbi_ctr(struct crypt_config *cc, struct dm_target *ti,
                              const char *opts)
 {
-       unsigned int bs = crypto_blkcipher_blocksize(cc->tfm);
+       unsigned bs = crypto_ablkcipher_blocksize(cc->tfm);
        int log = ilog2(bs);
 
        /* we need to calculate how far we must shift the sector count
@@ -289,42 +318,10 @@ static struct crypt_iv_operations crypt_iv_null_ops = {
        .generator = crypt_iv_null_gen
 };
 
-static int
-crypt_convert_scatterlist(struct crypt_config *cc, struct scatterlist *out,
-                          struct scatterlist *in, unsigned int length,
-                          int write, sector_t sector)
-{
-       u8 iv[cc->iv_size] __attribute__ ((aligned(__alignof__(u64))));
-       struct blkcipher_desc desc = {
-               .tfm = cc->tfm,
-               .info = iv,
-               .flags = CRYPTO_TFM_REQ_MAY_SLEEP,
-       };
-       int r;
-
-       if (cc->iv_gen_ops) {
-               r = cc->iv_gen_ops->generator(cc, iv, sector);
-               if (r < 0)
-                       return r;
-
-               if (write)
-                       r = crypto_blkcipher_encrypt_iv(&desc, out, in, length);
-               else
-                       r = crypto_blkcipher_decrypt_iv(&desc, out, in, length);
-       } else {
-               if (write)
-                       r = crypto_blkcipher_encrypt(&desc, out, in, length);
-               else
-                       r = crypto_blkcipher_decrypt(&desc, out, in, length);
-       }
-
-       return r;
-}
-
 static void crypt_convert_init(struct crypt_config *cc,
                               struct convert_context *ctx,
                               struct bio *bio_out, struct bio *bio_in,
-                              sector_t sector, int write)
+                              sector_t sector)
 {
        ctx->bio_in = bio_in;
        ctx->bio_out = bio_out;
@@ -333,7 +330,79 @@ static void crypt_convert_init(struct crypt_config *cc,
        ctx->idx_in = bio_in ? bio_in->bi_idx : 0;
        ctx->idx_out = bio_out ? bio_out->bi_idx : 0;
        ctx->sector = sector + cc->iv_offset;
-       ctx->write = write;
+       init_completion(&ctx->restart);
+       /*
+        * Crypto operation can be asynchronous,
+        * ctx->pending is increased after request submission.
+        * We need to ensure that we don't call the crypt finish
+        * operation before pending got incremented
+        * (dependent on crypt submission return code).
+        */
+       atomic_set(&ctx->pending, 2);
+}
+
+static int crypt_convert_block(struct crypt_config *cc,
+                              struct convert_context *ctx,
+                              struct ablkcipher_request *req)
+{
+       struct bio_vec *bv_in = bio_iovec_idx(ctx->bio_in, ctx->idx_in);
+       struct bio_vec *bv_out = bio_iovec_idx(ctx->bio_out, ctx->idx_out);
+       struct dm_crypt_request *dmreq;
+       u8 *iv;
+       int r = 0;
+
+       dmreq = (struct dm_crypt_request *)((char *)req + cc->dmreq_start);
+       iv = (u8 *)ALIGN((unsigned long)(dmreq + 1),
+                        crypto_ablkcipher_alignmask(cc->tfm) + 1);
+
+       sg_init_table(&dmreq->sg_in, 1);
+       sg_set_page(&dmreq->sg_in, bv_in->bv_page, 1 << SECTOR_SHIFT,
+                   bv_in->bv_offset + ctx->offset_in);
+
+       sg_init_table(&dmreq->sg_out, 1);
+       sg_set_page(&dmreq->sg_out, bv_out->bv_page, 1 << SECTOR_SHIFT,
+                   bv_out->bv_offset + ctx->offset_out);
+
+       ctx->offset_in += 1 << SECTOR_SHIFT;
+       if (ctx->offset_in >= bv_in->bv_len) {
+               ctx->offset_in = 0;
+               ctx->idx_in++;
+       }
+
+       ctx->offset_out += 1 << SECTOR_SHIFT;
+       if (ctx->offset_out >= bv_out->bv_len) {
+               ctx->offset_out = 0;
+               ctx->idx_out++;
+       }
+
+       if (cc->iv_gen_ops) {
+               r = cc->iv_gen_ops->generator(cc, iv, ctx->sector);
+               if (r < 0)
+                       return r;
+       }
+
+       ablkcipher_request_set_crypt(req, &dmreq->sg_in, &dmreq->sg_out,
+                                    1 << SECTOR_SHIFT, iv);
+
+       if (bio_data_dir(ctx->bio_in) == WRITE)
+               r = crypto_ablkcipher_encrypt(req);
+       else
+               r = crypto_ablkcipher_decrypt(req);
+
+       return r;
+}
+
+static void kcryptd_async_done(struct crypto_async_request *async_req,
+                              int error);
+static void crypt_alloc_req(struct crypt_config *cc,
+                           struct convert_context *ctx)
+{
+       if (!cc->req)
+               cc->req = mempool_alloc(cc->req_pool, GFP_NOIO);
+       ablkcipher_request_set_tfm(cc->req, cc->tfm);
+       ablkcipher_request_set_callback(cc->req, CRYPTO_TFM_REQ_MAY_BACKLOG |
+                                            CRYPTO_TFM_REQ_MAY_SLEEP,
+                                            kcryptd_async_done, ctx);
 }
 
 /*
@@ -346,36 +415,38 @@ static int crypt_convert(struct crypt_config *cc,
 
        while(ctx->idx_in < ctx->bio_in->bi_vcnt &&
              ctx->idx_out < ctx->bio_out->bi_vcnt) {
-               struct bio_vec *bv_in = bio_iovec_idx(ctx->bio_in, ctx->idx_in);
-               struct bio_vec *bv_out = bio_iovec_idx(ctx->bio_out, ctx->idx_out);
-               struct scatterlist sg_in, sg_out;
-
-               sg_init_table(&sg_in, 1);
-               sg_set_page(&sg_in, bv_in->bv_page, 1 << SECTOR_SHIFT, bv_in->bv_offset + ctx->offset_in);
-
-               sg_init_table(&sg_out, 1);
-               sg_set_page(&sg_out, bv_out->bv_page, 1 << SECTOR_SHIFT, bv_out->bv_offset + ctx->offset_out);
 
-               ctx->offset_in += sg_in.length;
-               if (ctx->offset_in >= bv_in->bv_len) {
-                       ctx->offset_in = 0;
-                       ctx->idx_in++;
+               crypt_alloc_req(cc, ctx);
+
+               r = crypt_convert_block(cc, ctx, cc->req);
+
+               switch (r) {
+               case -EBUSY:
+                       wait_for_completion(&ctx->restart);
+                       INIT_COMPLETION(ctx->restart);
+                       /* fall through*/
+               case -EINPROGRESS:
+                       atomic_inc(&ctx->pending);
+                       cc->req = NULL;
+                       r = 0;
+                       /* fall through*/
+               case 0:
+                       ctx->sector++;
+                       continue;
                }
 
-               ctx->offset_out += sg_out.length;
-               if (ctx->offset_out >= bv_out->bv_len) {
-                       ctx->offset_out = 0;
-                       ctx->idx_out++;
-               }
-
-               r = crypt_convert_scatterlist(cc, &sg_out, &sg_in, sg_in.length,
-                                             ctx->write, ctx->sector);
-               if (r < 0)
-                       break;
-
-               ctx->sector++;
+               break;
        }
 
+       /*
+        * If there are pending crypto operation run async
+        * code. Otherwise process return code synchronously.
+        * The step of 2 ensures that async finish doesn't
+        * call crypto finish too early.
+        */
+       if (atomic_sub_return(2, &ctx->pending))
+               return -EINPROGRESS;
+
        return r;
 }
 
@@ -455,18 +526,14 @@ static void crypt_free_buffer_pages(struct crypt_config *cc, struct bio *clone)
  * One of the bios was finished. Check for completion of
  * the whole request and correctly clean up the buffer.
  */
-static void crypt_dec_pending(struct dm_crypt_io *io, int error)
+static void crypt_dec_pending(struct dm_crypt_io *io)
 {
-       struct crypt_config *cc = (struct crypt_config *) io->target->private;
-
-       if (error < 0)
-               io->error = error;
+       struct crypt_config *cc = io->target->private;
 
        if (!atomic_dec_and_test(&io->pending))
                return;
 
        bio_endio(io->base_bio, io->error);
-
        mempool_free(io, cc->io_pool);
 }
 
@@ -484,30 +551,11 @@ static void crypt_dec_pending(struct dm_crypt_io *io, int error)
  * starved by new requests which can block in the first stages due
  * to memory allocation.
  */
-static void kcryptd_do_work(struct work_struct *work);
-static void kcryptd_do_crypt(struct work_struct *work);
-
-static void kcryptd_queue_io(struct dm_crypt_io *io)
-{
-       struct crypt_config *cc = io->target->private;
-
-       INIT_WORK(&io->work, kcryptd_do_work);
-       queue_work(cc->io_queue, &io->work);
-}
-
-static void kcryptd_queue_crypt(struct dm_crypt_io *io)
-{
-       struct crypt_config *cc = io->target->private;
-
-       INIT_WORK(&io->work, kcryptd_do_crypt);
-       queue_work(cc->crypt_queue, &io->work);
-}
-
 static void crypt_endio(struct bio *clone, int error)
 {
        struct dm_crypt_io *io = clone->bi_private;
        struct crypt_config *cc = io->target->private;
-       unsigned read_io = bio_data_dir(clone) == READ;
+       unsigned rw = bio_data_dir(clone);
 
        if (unlikely(!bio_flagged(clone, BIO_UPTODATE) && !error))
                error = -EIO;
@@ -515,21 +563,20 @@ static void crypt_endio(struct bio *clone, int error)
        /*
         * free the processed pages
         */
-       if (!read_io) {
+       if (rw == WRITE)
                crypt_free_buffer_pages(cc, clone);
-               goto out;
+
+       bio_put(clone);
+
+       if (rw == READ && !error) {
+               kcryptd_queue_crypt(io);
+               return;
        }
 
        if (unlikely(error))
-               goto out;
-
-       bio_put(clone);
-       kcryptd_queue_crypt(io);
-       return;
+               io->error = error;
 
-out:
-       bio_put(clone);
-       crypt_dec_pending(io, error);
+       crypt_dec_pending(io);
 }
 
 static void clone_init(struct dm_crypt_io *io, struct bio *clone)
@@ -543,12 +590,11 @@ static void clone_init(struct dm_crypt_io *io, struct bio *clone)
        clone->bi_destructor = dm_crypt_bio_destructor;
 }
 
-static void process_read(struct dm_crypt_io *io)
+static void kcryptd_io_read(struct dm_crypt_io *io)
 {
        struct crypt_config *cc = io->target->private;
        struct bio *base_bio = io->base_bio;
        struct bio *clone;
-       sector_t sector = base_bio->bi_sector - io->target->begin;
 
        atomic_inc(&io->pending);
 
@@ -559,7 +605,8 @@ static void process_read(struct dm_crypt_io *io)
         */
        clone = bio_alloc_bioset(GFP_NOIO, bio_segments(base_bio), cc->bs);
        if (unlikely(!clone)) {
-               crypt_dec_pending(io, -ENOMEM);
+               io->error = -ENOMEM;
+               crypt_dec_pending(io);
                return;
        }
 
@@ -567,25 +614,71 @@ static void process_read(struct dm_crypt_io *io)
        clone->bi_idx = 0;
        clone->bi_vcnt = bio_segments(base_bio);
        clone->bi_size = base_bio->bi_size;
-       clone->bi_sector = cc->start + sector;
+       clone->bi_sector = cc->start + io->sector;
        memcpy(clone->bi_io_vec, bio_iovec(base_bio),
               sizeof(struct bio_vec) * clone->bi_vcnt);
 
        generic_make_request(clone);
 }
 
-static void process_write(struct dm_crypt_io *io)
+static void kcryptd_io_write(struct dm_crypt_io *io)
+{
+       struct bio *clone = io->ctx.bio_out;
+
+       generic_make_request(clone);
+}
+
+static void kcryptd_io(struct work_struct *work)
+{
+       struct dm_crypt_io *io = container_of(work, struct dm_crypt_io, work);
+
+       if (bio_data_dir(io->base_bio) == READ)
+               kcryptd_io_read(io);
+       else
+               kcryptd_io_write(io);
+}
+
+static void kcryptd_queue_io(struct dm_crypt_io *io)
 {
        struct crypt_config *cc = io->target->private;
-       struct bio *base_bio = io->base_bio;
-       struct bio *clone;
-       struct convert_context ctx;
-       unsigned remaining = base_bio->bi_size;
-       sector_t sector = base_bio->bi_sector - io->target->begin;
 
-       atomic_inc(&io->pending);
+       INIT_WORK(&io->work, kcryptd_io);
+       queue_work(cc->io_queue, &io->work);
+}
 
-       crypt_convert_init(cc, &ctx, NULL, base_bio, sector, 1);
+static void kcryptd_crypt_write_io_submit(struct dm_crypt_io *io,
+                                         int error, int async)
+{
+       struct bio *clone = io->ctx.bio_out;
+       struct crypt_config *cc = io->target->private;
+
+       if (unlikely(error < 0)) {
+               crypt_free_buffer_pages(cc, clone);
+               bio_put(clone);
+               io->error = -EIO;
+               return;
+       }
+
+       /* crypt_convert should have filled the clone bio */
+       BUG_ON(io->ctx.idx_out < clone->bi_vcnt);
+
+       clone->bi_sector = cc->start + io->sector;
+       io->sector += bio_sectors(clone);
+
+       if (async)
+               kcryptd_queue_io(io);
+       else {
+               atomic_inc(&io->pending);
+               generic_make_request(clone);
+       }
+}
+
+static void kcryptd_crypt_write_convert_loop(struct dm_crypt_io *io)
+{
+       struct crypt_config *cc = io->target->private;
+       struct bio *clone;
+       unsigned remaining = io->base_bio->bi_size;
+       int r;
 
        /*
         * The allocated buffers can be smaller than the whole bio,
@@ -594,70 +687,110 @@ static void process_write(struct dm_crypt_io *io)
        while (remaining) {
                clone = crypt_alloc_buffer(io, remaining);
                if (unlikely(!clone)) {
-                       crypt_dec_pending(io, -ENOMEM);
+                       io->error = -ENOMEM;
                        return;
                }
 
-               ctx.bio_out = clone;
-               ctx.idx_out = 0;
+               io->ctx.bio_out = clone;
+               io->ctx.idx_out = 0;
 
-               if (unlikely(crypt_convert(cc, &ctx) < 0)) {
-                       crypt_free_buffer_pages(cc, clone);
-                       bio_put(clone);
-                       crypt_dec_pending(io, -EIO);
-                       return;
-               }
-
-               /* crypt_convert should have filled the clone bio */
-               BUG_ON(ctx.idx_out < clone->bi_vcnt);
-
-               clone->bi_sector = cc->start + sector;
                remaining -= clone->bi_size;
-               sector += bio_sectors(clone);
 
-               /* Grab another reference to the io struct
-                * before we kick off the request */
-               if (remaining)
-                       atomic_inc(&io->pending);
+               r = crypt_convert(cc, &io->ctx);
 
-               generic_make_request(clone);
-
-               /* Do not reference clone after this - it
-                * may be gone already. */
+               if (r != -EINPROGRESS) {
+                       kcryptd_crypt_write_io_submit(io, r, 0);
+                       if (unlikely(r < 0))
+                               return;
+               } else
+                       atomic_inc(&io->pending);
 
                /* out of memory -> run queues */
-               if (remaining)
+               if (unlikely(remaining))
                        congestion_wait(WRITE, HZ/100);
        }
 }
 
-static void process_read_endio(struct dm_crypt_io *io)
+static void kcryptd_crypt_write_convert(struct dm_crypt_io *io)
 {
        struct crypt_config *cc = io->target->private;
-       struct convert_context ctx;
 
-       crypt_convert_init(cc, &ctx, io->base_bio, io->base_bio,
-                          io->base_bio->bi_sector - io->target->begin, 0);
+       /*
+        * Prevent io from disappearing until this function completes.
+        */
+       atomic_inc(&io->pending);
+
+       crypt_convert_init(cc, &io->ctx, NULL, io->base_bio, io->sector);
+       kcryptd_crypt_write_convert_loop(io);
 
-       crypt_dec_pending(io, crypt_convert(cc, &ctx));
+       crypt_dec_pending(io);
 }
 
-static void kcryptd_do_work(struct work_struct *work)
+static void kcryptd_crypt_read_done(struct dm_crypt_io *io, int error)
 {
-       struct dm_crypt_io *io = container_of(work, struct dm_crypt_io, work);
+       if (unlikely(error < 0))
+               io->error = -EIO;
+
+       crypt_dec_pending(io);
+}
+
+static void kcryptd_crypt_read_convert(struct dm_crypt_io *io)
+{
+       struct crypt_config *cc = io->target->private;
+       int r = 0;
+
+       atomic_inc(&io->pending);
+
+       crypt_convert_init(cc, &io->ctx, io->base_bio, io->base_bio,
+                          io->sector);
+
+       r = crypt_convert(cc, &io->ctx);
+
+       if (r != -EINPROGRESS)
+               kcryptd_crypt_read_done(io, r);
+
+       crypt_dec_pending(io);
+}
+
+static void kcryptd_async_done(struct crypto_async_request *async_req,
+                              int error)
+{
+       struct convert_context *ctx = async_req->data;
+       struct dm_crypt_io *io = container_of(ctx, struct dm_crypt_io, ctx);
+       struct crypt_config *cc = io->target->private;
+
+       if (error == -EINPROGRESS) {
+               complete(&ctx->restart);
+               return;
+       }
+
+       mempool_free(ablkcipher_request_cast(async_req), cc->req_pool);
+
+       if (!atomic_dec_and_test(&ctx->pending))
+               return;
 
        if (bio_data_dir(io->base_bio) == READ)
-               process_read(io);
+               kcryptd_crypt_read_done(io, error);
+       else
+               kcryptd_crypt_write_io_submit(io, error, 1);
 }
 
-static void kcryptd_do_crypt(struct work_struct *work)
+static void kcryptd_crypt(struct work_struct *work)
 {
        struct dm_crypt_io *io = container_of(work, struct dm_crypt_io, work);
 
        if (bio_data_dir(io->base_bio) == READ)
-               process_read_endio(io);
+               kcryptd_crypt_read_convert(io);
        else
-               process_write(io);
+               kcryptd_crypt_write_convert(io);
+}
+
+static void kcryptd_queue_crypt(struct dm_crypt_io *io)
+{
+       struct crypt_config *cc = io->target->private;
+
+       INIT_WORK(&io->work, kcryptd_crypt);
+       queue_work(cc->crypt_queue, &io->work);
 }
 
 /*
@@ -733,7 +866,7 @@ static int crypt_wipe_key(struct crypt_config *cc)
 static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 {
        struct crypt_config *cc;
-       struct crypto_blkcipher *tfm;
+       struct crypto_ablkcipher *tfm;
        char *tmp;
        char *cipher;
        char *chainmode;
@@ -787,7 +920,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
                goto bad_cipher;
        }
 
-       tfm = crypto_alloc_blkcipher(cc->cipher, 0, CRYPTO_ALG_ASYNC);
+       tfm = crypto_alloc_ablkcipher(cc->cipher, 0, 0);
        if (IS_ERR(tfm)) {
                ti->error = "Error allocating crypto tfm";
                goto bad_cipher;
@@ -821,7 +954,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
            cc->iv_gen_ops->ctr(cc, ti, ivopts) < 0)
                goto bad_ivmode;
 
-       cc->iv_size = crypto_blkcipher_ivsize(tfm);
+       cc->iv_size = crypto_ablkcipher_ivsize(tfm);
        if (cc->iv_size)
                /* at least a 64 bit sector number should fit in our buffer */
                cc->iv_size = max(cc->iv_size,
@@ -841,6 +974,20 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
                goto bad_slab_pool;
        }
 
+       cc->dmreq_start = sizeof(struct ablkcipher_request);
+       cc->dmreq_start += crypto_ablkcipher_reqsize(tfm);
+       cc->dmreq_start = ALIGN(cc->dmreq_start, crypto_tfm_ctx_alignment());
+       cc->dmreq_start += crypto_ablkcipher_alignmask(tfm) &
+                          ~(crypto_tfm_ctx_alignment() - 1);
+
+       cc->req_pool = mempool_create_kmalloc_pool(MIN_IOS, cc->dmreq_start +
+                       sizeof(struct dm_crypt_request) + cc->iv_size);
+       if (!cc->req_pool) {
+               ti->error = "Cannot allocate crypt request mempool";
+               goto bad_req_pool;
+       }
+       cc->req = NULL;
+
        cc->page_pool = mempool_create_page_pool(MIN_POOL_PAGES, 0);
        if (!cc->page_pool) {
                ti->error = "Cannot allocate page mempool";
@@ -853,7 +1000,7 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
                goto bad_bs;
        }
 
-       if (crypto_blkcipher_setkey(tfm, cc->key, key_size) < 0) {
+       if (crypto_ablkcipher_setkey(tfm, cc->key, key_size) < 0) {
                ti->error = "Error setting key";
                goto bad_device;
        }
@@ -914,12 +1061,14 @@ bad_device:
 bad_bs:
        mempool_destroy(cc->page_pool);
 bad_page_pool:
+       mempool_destroy(cc->req_pool);
+bad_req_pool:
        mempool_destroy(cc->io_pool);
 bad_slab_pool:
        if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
                cc->iv_gen_ops->dtr(cc);
 bad_ivmode:
-       crypto_free_blkcipher(tfm);
+       crypto_free_ablkcipher(tfm);
 bad_cipher:
        /* Must zero key material before freeing */
        memset(cc, 0, sizeof(*cc) + cc->key_size * sizeof(u8));
@@ -934,14 +1083,18 @@ static void crypt_dtr(struct dm_target *ti)
        destroy_workqueue(cc->io_queue);
        destroy_workqueue(cc->crypt_queue);
 
+       if (cc->req)
+               mempool_free(cc->req, cc->req_pool);
+
        bioset_free(cc->bs);
        mempool_destroy(cc->page_pool);
+       mempool_destroy(cc->req_pool);
        mempool_destroy(cc->io_pool);
 
        kfree(cc->iv_mode);
        if (cc->iv_gen_ops && cc->iv_gen_ops->dtr)
                cc->iv_gen_ops->dtr(cc);
-       crypto_free_blkcipher(cc->tfm);
+       crypto_free_ablkcipher(cc->tfm);
        dm_put_device(ti, cc->dev);
 
        /* Must zero key material before freeing */
@@ -958,6 +1111,7 @@ static int crypt_map(struct dm_target *ti, struct bio *bio,
        io = mempool_alloc(cc->io_pool, GFP_NOIO);
        io->target = ti;
        io->base_bio = bio;
+       io->sector = bio->bi_sector - ti->begin;
        io->error = 0;
        atomic_set(&io->pending, 0);
 
index 8fe81e1807e0cc9c7e35202990bc419274143335..5bbce29f143ac45f6d358a9b26217b3d30ee1ccd 100644 (file)
@@ -449,7 +449,7 @@ static void persistent_destroy(struct exception_store *store)
 
 static int persistent_read_metadata(struct exception_store *store)
 {
-       int r, new_snapshot;
+       int r, uninitialized_var(new_snapshot);
        struct pstore *ps = get_info(store);
 
        /*
index 9627fa0f9470cfdb4055199e83eb68c7f8a5f18f..b262c0042de3f79394d7ff46c61e36b68da29e48 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/slab.h>
 #include <linux/dm-ioctl.h>
 #include <linux/hdreg.h>
+#include <linux/compat.h>
 
 #include <asm/uaccess.h>
 
@@ -702,7 +703,7 @@ static int dev_rename(struct dm_ioctl *param, size_t param_size)
        int r;
        char *new_name = (char *) param + param->data_start;
 
-       if (new_name < (char *) param->data ||
+       if (new_name < param->data ||
            invalid_str(new_name, (void *) param + param_size)) {
                DMWARN("Invalid new logical volume name supplied.");
                return -EINVAL;
@@ -728,7 +729,7 @@ static int dev_set_geometry(struct dm_ioctl *param, size_t param_size)
        if (!md)
                return -ENXIO;
 
-       if (geostr < (char *) param->data ||
+       if (geostr < param->data ||
            invalid_str(geostr, (void *) param + param_size)) {
                DMWARN("Invalid geometry supplied.");
                goto out;
@@ -1350,10 +1351,10 @@ static int copy_params(struct dm_ioctl __user *user, struct dm_ioctl **param)
 {
        struct dm_ioctl tmp, *dmi;
 
-       if (copy_from_user(&tmp, user, sizeof(tmp)))
+       if (copy_from_user(&tmp, user, sizeof(tmp) - sizeof(tmp.data)))
                return -EFAULT;
 
-       if (tmp.data_size < sizeof(tmp))
+       if (tmp.data_size < (sizeof(tmp) - sizeof(tmp.data)))
                return -EINVAL;
 
        dmi = vmalloc(tmp.data_size);
@@ -1397,13 +1398,11 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
        return 0;
 }
 
-static int ctl_ioctl(struct inode *inode, struct file *file,
-                    uint command, ulong u)
+static int ctl_ioctl(uint command, struct dm_ioctl __user *user)
 {
        int r = 0;
        unsigned int cmd;
-       struct dm_ioctl *param;
-       struct dm_ioctl __user *user = (struct dm_ioctl __user *) u;
+       struct dm_ioctl *uninitialized_var(param);
        ioctl_fn fn = NULL;
        size_t param_size;
 
@@ -1471,8 +1470,23 @@ static int ctl_ioctl(struct inode *inode, struct file *file,
        return r;
 }
 
+static long dm_ctl_ioctl(struct file *file, uint command, ulong u)
+{
+       return (long)ctl_ioctl(command, (struct dm_ioctl __user *)u);
+}
+
+#ifdef CONFIG_COMPAT
+static long dm_compat_ctl_ioctl(struct file *file, uint command, ulong u)
+{
+       return (long)dm_ctl_ioctl(file, command, (ulong) compat_ptr(u));
+}
+#else
+#define dm_compat_ctl_ioctl NULL
+#endif
+
 static const struct file_operations _ctl_fops = {
-       .ioctl   = ctl_ioctl,
+       .unlocked_ioctl  = dm_ctl_ioctl,
+       .compat_ioctl = dm_compat_ctl_ioctl,
        .owner   = THIS_MODULE,
 };
 
index 072ee4353eab329620995aceee14b468a49584a4..2a74b2142f502a6e2ea944e39b598d90cbb96cac 100644 (file)
@@ -41,7 +41,7 @@ int dm_unregister_dirty_log_type(struct dirty_log_type *type)
        return 0;
 }
 
-static struct dirty_log_type *get_type(const char *type_name)
+static struct dirty_log_type *_get_type(const char *type_name)
 {
        struct dirty_log_type *type;
 
@@ -61,6 +61,55 @@ static struct dirty_log_type *get_type(const char *type_name)
        return NULL;
 }
 
+/*
+ * get_type
+ * @type_name
+ *
+ * Attempt to retrieve the dirty_log_type by name.  If not already
+ * available, attempt to load the appropriate module.
+ *
+ * Log modules are named "dm-log-" followed by the 'type_name'.
+ * Modules may contain multiple types.
+ * This function will first try the module "dm-log-<type_name>",
+ * then truncate 'type_name' on the last '-' and try again.
+ *
+ * For example, if type_name was "clustered-disk", it would search
+ * 'dm-log-clustered-disk' then 'dm-log-clustered'.
+ *
+ * Returns: dirty_log_type* on success, NULL on failure
+ */
+static struct dirty_log_type *get_type(const char *type_name)
+{
+       char *p, *type_name_dup;
+       struct dirty_log_type *type;
+
+       type = _get_type(type_name);
+       if (type)
+               return type;
+
+       type_name_dup = kstrdup(type_name, GFP_KERNEL);
+       if (!type_name_dup) {
+               DMWARN("No memory left to attempt log module load for \"%s\"",
+                      type_name);
+               return NULL;
+       }
+
+       while (request_module("dm-log-%s", type_name_dup) ||
+              !(type = _get_type(type_name))) {
+               p = strrchr(type_name_dup, '-');
+               if (!p)
+                       break;
+               p[0] = '\0';
+       }
+
+       if (!type)
+               DMWARN("Module for logging type \"%s\" not found.", type_name);
+
+       kfree(type_name_dup);
+
+       return type;
+}
+
 static void put_type(struct dirty_log_type *type)
 {
        spin_lock(&_lock);
index 24b2b1e32faefc443bf102949a3674689e505b05..e7ee59e655d58a66e53658794e5e0dc2b2042ed3 100644 (file)
@@ -106,7 +106,7 @@ typedef int (*action_fn) (struct pgpath *pgpath);
 
 static struct kmem_cache *_mpio_cache;
 
-struct workqueue_struct *kmultipathd;
+static struct workqueue_struct *kmultipathd;
 static void process_queued_ios(struct work_struct *work);
 static void trigger_event(struct work_struct *work);
 
index 31123d4a6b9cc39dbeec455d50b540b97ac99c06..edc057f5cdccf2b07dc09dcfe83fda5f37a811cb 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "dm.h"
 #include "dm-bio-list.h"
+#include "dm-bio-record.h"
 #include "dm-io.h"
 #include "dm-log.h"
 #include "kcopyd.h"
@@ -20,6 +21,7 @@
 #include <linux/vmalloc.h>
 #include <linux/workqueue.h>
 #include <linux/log2.h>
+#include <linux/hardirq.h>
 
 #define DM_MSG_PREFIX "raid1"
 #define DM_IO_PAGES 64
@@ -113,9 +115,16 @@ struct region {
 /*-----------------------------------------------------------------
  * Mirror set structures.
  *---------------------------------------------------------------*/
+enum dm_raid1_error {
+       DM_RAID1_WRITE_ERROR,
+       DM_RAID1_SYNC_ERROR,
+       DM_RAID1_READ_ERROR
+};
+
 struct mirror {
        struct mirror_set *ms;
        atomic_t error_count;
+       uint32_t error_type;
        struct dm_dev *dev;
        sector_t offset;
 };
@@ -127,21 +136,25 @@ struct mirror_set {
        struct kcopyd_client *kcopyd_client;
        uint64_t features;
 
-       spinlock_t lock;        /* protects the next two lists */
+       spinlock_t lock;        /* protects the lists */
        struct bio_list reads;
        struct bio_list writes;
+       struct bio_list failures;
 
        struct dm_io_client *io_client;
+       mempool_t *read_record_pool;
 
        /* recovery */
        region_t nr_regions;
        int in_sync;
        int log_failure;
+       atomic_t suspend;
 
-       struct mirror *default_mirror;  /* Default mirror */
+       atomic_t default_mirror;        /* Default mirror */
 
        struct workqueue_struct *kmirrord_wq;
        struct work_struct kmirrord_work;
+       struct work_struct trigger_event;
 
        unsigned int nr_mirrors;
        struct mirror mirror[0];
@@ -362,6 +375,16 @@ static void complete_resync_work(struct region *reg, int success)
        struct region_hash *rh = reg->rh;
 
        rh->log->type->set_region_sync(rh->log, reg->key, success);
+
+       /*
+        * Dispatch the bios before we call 'wake_up_all'.
+        * This is important because if we are suspending,
+        * we want to know that recovery is complete and
+        * the work queue is flushed.  If we wake_up_all
+        * before we dispatch_bios (queue bios and call wake()),
+        * then we risk suspending before the work queue
+        * has been properly flushed.
+        */
        dispatch_bios(rh->ms, &reg->delayed_bios);
        if (atomic_dec_and_test(&rh->recovery_in_flight))
                wake_up_all(&_kmirrord_recovery_stopped);
@@ -626,24 +649,101 @@ static void rh_start_recovery(struct region_hash *rh)
        wake(rh->ms);
 }
 
+#define MIN_READ_RECORDS 20
+struct dm_raid1_read_record {
+       struct mirror *m;
+       struct dm_bio_details details;
+};
+
 /*
  * Every mirror should look like this one.
  */
 #define DEFAULT_MIRROR 0
 
 /*
- * This is yucky.  We squirrel the mirror_set struct away inside
- * bi_next for write buffers.  This is safe since the bh
+ * This is yucky.  We squirrel the mirror struct away inside
+ * bi_next for read/write buffers.  This is safe since the bh
  * doesn't get submitted to the lower levels of block layer.
  */
-static struct mirror_set *bio_get_ms(struct bio *bio)
+static struct mirror *bio_get_m(struct bio *bio)
+{
+       return (struct mirror *) bio->bi_next;
+}
+
+static void bio_set_m(struct bio *bio, struct mirror *m)
+{
+       bio->bi_next = (struct bio *) m;
+}
+
+static struct mirror *get_default_mirror(struct mirror_set *ms)
 {
-       return (struct mirror_set *) bio->bi_next;
+       return &ms->mirror[atomic_read(&ms->default_mirror)];
 }
 
-static void bio_set_ms(struct bio *bio, struct mirror_set *ms)
+static void set_default_mirror(struct mirror *m)
 {
-       bio->bi_next = (struct bio *) ms;
+       struct mirror_set *ms = m->ms;
+       struct mirror *m0 = &(ms->mirror[0]);
+
+       atomic_set(&ms->default_mirror, m - m0);
+}
+
+/* fail_mirror
+ * @m: mirror device to fail
+ * @error_type: one of the enum's, DM_RAID1_*_ERROR
+ *
+ * If errors are being handled, record the type of
+ * error encountered for this device.  If this type
+ * of error has already been recorded, we can return;
+ * otherwise, we must signal userspace by triggering
+ * an event.  Additionally, if the device is the
+ * primary device, we must choose a new primary, but
+ * only if the mirror is in-sync.
+ *
+ * This function must not block.
+ */
+static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
+{
+       struct mirror_set *ms = m->ms;
+       struct mirror *new;
+
+       if (!errors_handled(ms))
+               return;
+
+       /*
+        * error_count is used for nothing more than a
+        * simple way to tell if a device has encountered
+        * errors.
+        */
+       atomic_inc(&m->error_count);
+
+       if (test_and_set_bit(error_type, &m->error_type))
+               return;
+
+       if (m != get_default_mirror(ms))
+               goto out;
+
+       if (!ms->in_sync) {
+               /*
+                * Better to issue requests to same failing device
+                * than to risk returning corrupt data.
+                */
+               DMERR("Primary mirror (%s) failed while out-of-sync: "
+                     "Reads may fail.", m->dev->name);
+               goto out;
+       }
+
+       for (new = ms->mirror; new < ms->mirror + ms->nr_mirrors; new++)
+               if (!atomic_read(&new->error_count)) {
+                       set_default_mirror(new);
+                       break;
+               }
+
+       if (unlikely(new == ms->mirror + ms->nr_mirrors))
+               DMWARN("All sides of mirror have failed.");
+
+out:
+       schedule_work(&ms->trigger_event);
 }
 
 /*-----------------------------------------------------------------
@@ -656,15 +756,32 @@ static void bio_set_ms(struct bio *bio, struct mirror_set *ms)
 static void recovery_complete(int read_err, unsigned int write_err,
                              void *context)
 {
-       struct region *reg = (struct region *) context;
+       struct region *reg = (struct region *)context;
+       struct mirror_set *ms = reg->rh->ms;
+       int m, bit = 0;
 
-       if (read_err)
+       if (read_err) {
                /* Read error means the failure of default mirror. */
                DMERR_LIMIT("Unable to read primary mirror during recovery");
+               fail_mirror(get_default_mirror(ms), DM_RAID1_SYNC_ERROR);
+       }
 
-       if (write_err)
+       if (write_err) {
                DMERR_LIMIT("Write error during recovery (error = 0x%x)",
                            write_err);
+               /*
+                * Bits correspond to devices (excluding default mirror).
+                * The default mirror cannot change during recovery.
+                */
+               for (m = 0; m < ms->nr_mirrors; m++) {
+                       if (&ms->mirror[m] == get_default_mirror(ms))
+                               continue;
+                       if (test_bit(bit, &write_err))
+                               fail_mirror(ms->mirror + m,
+                                           DM_RAID1_SYNC_ERROR);
+                       bit++;
+               }
+       }
 
        rh_recovery_end(reg, !(read_err || write_err));
 }
@@ -678,7 +795,7 @@ static int recover(struct mirror_set *ms, struct region *reg)
        unsigned long flags = 0;
 
        /* fill in the source */
-       m = ms->default_mirror;
+       m = get_default_mirror(ms);
        from.bdev = m->dev->bdev;
        from.sector = m->offset + region_to_sector(reg->rh, reg->key);
        if (reg->key == (ms->nr_regions - 1)) {
@@ -694,7 +811,7 @@ static int recover(struct mirror_set *ms, struct region *reg)
 
        /* fill in the destinations */
        for (i = 0, dest = to; i < ms->nr_mirrors; i++) {
-               if (&ms->mirror[i] == ms->default_mirror)
+               if (&ms->mirror[i] == get_default_mirror(ms))
                        continue;
 
                m = ms->mirror + i;
@@ -748,17 +865,105 @@ static void do_recovery(struct mirror_set *ms)
  *---------------------------------------------------------------*/
 static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
 {
-       /* FIXME: add read balancing */
-       return ms->default_mirror;
+       struct mirror *m = get_default_mirror(ms);
+
+       do {
+               if (likely(!atomic_read(&m->error_count)))
+                       return m;
+
+               if (m-- == ms->mirror)
+                       m += ms->nr_mirrors;
+       } while (m != get_default_mirror(ms));
+
+       return NULL;
+}
+
+static int default_ok(struct mirror *m)
+{
+       struct mirror *default_mirror = get_default_mirror(m->ms);
+
+       return !atomic_read(&default_mirror->error_count);
+}
+
+static int mirror_available(struct mirror_set *ms, struct bio *bio)
+{
+       region_t region = bio_to_region(&ms->rh, bio);
+
+       if (ms->rh.log->type->in_sync(ms->rh.log, region, 0))
+               return choose_mirror(ms,  bio->bi_sector) ? 1 : 0;
+
+       return 0;
 }
 
 /*
  * remap a buffer to a particular mirror.
  */
-static void map_bio(struct mirror_set *ms, struct mirror *m, struct bio *bio)
+static sector_t map_sector(struct mirror *m, struct bio *bio)
+{
+       return m->offset + (bio->bi_sector - m->ms->ti->begin);
+}
+
+static void map_bio(struct mirror *m, struct bio *bio)
 {
        bio->bi_bdev = m->dev->bdev;
-       bio->bi_sector = m->offset + (bio->bi_sector - ms->ti->begin);
+       bio->bi_sector = map_sector(m, bio);
+}
+
+static void map_region(struct io_region *io, struct mirror *m,
+                      struct bio *bio)
+{
+       io->bdev = m->dev->bdev;
+       io->sector = map_sector(m, bio);
+       io->count = bio->bi_size >> 9;
+}
+
+/*-----------------------------------------------------------------
+ * Reads
+ *---------------------------------------------------------------*/
+static void read_callback(unsigned long error, void *context)
+{
+       struct bio *bio = context;
+       struct mirror *m;
+
+       m = bio_get_m(bio);
+       bio_set_m(bio, NULL);
+
+       if (likely(!error)) {
+               bio_endio(bio, 0);
+               return;
+       }
+
+       fail_mirror(m, DM_RAID1_READ_ERROR);
+
+       if (likely(default_ok(m)) || mirror_available(m->ms, bio)) {
+               DMWARN_LIMIT("Read failure on mirror device %s.  "
+                            "Trying alternative device.",
+                            m->dev->name);
+               queue_bio(m->ms, bio, bio_rw(bio));
+               return;
+       }
+
+       DMERR_LIMIT("Read failure on mirror device %s.  Failing I/O.",
+                   m->dev->name);
+       bio_endio(bio, -EIO);
+}
+
+/* Asynchronous read. */
+static void read_async_bio(struct mirror *m, struct bio *bio)
+{
+       struct io_region io;
+       struct dm_io_request io_req = {
+               .bi_rw = READ,
+               .mem.type = DM_IO_BVEC,
+               .mem.ptr.bvec = bio->bi_io_vec + bio->bi_idx,
+               .notify.fn = read_callback,
+               .notify.context = bio,
+               .client = m->ms->io_client,
+       };
+
+       map_region(&io, m, bio);
+       bio_set_m(bio, m);
+       (void) dm_io(&io_req, 1, &io, NULL);
 }
 
 static void do_reads(struct mirror_set *ms, struct bio_list *reads)
@@ -769,17 +974,20 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
 
        while ((bio = bio_list_pop(reads))) {
                region = bio_to_region(&ms->rh, bio);
+               m = get_default_mirror(ms);
 
                /*
                 * We can only read balance if the region is in sync.
                 */
-               if (rh_in_sync(&ms->rh, region, 1))
+               if (likely(rh_in_sync(&ms->rh, region, 1)))
                        m = choose_mirror(ms, bio->bi_sector);
-               else
-                       m = ms->default_mirror;
+               else if (m && atomic_read(&m->error_count))
+                       m = NULL;
 
-               map_bio(ms, m, bio);
-               generic_make_request(bio);
+               if (likely(m))
+                       read_async_bio(m, bio);
+               else
+                       bio_endio(bio, -EIO);
        }
 }
 
@@ -793,15 +1001,70 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
  * RECOVERING: delay the io until recovery completes
  * NOSYNC:     increment pending, just write to the default mirror
  *---------------------------------------------------------------*/
+
+/* __bio_mark_nosync
+ * @ms
+ * @bio
+ * @done
+ * @error
+ *
+ * The bio was written on some mirror(s) but failed on other mirror(s).
+ * We can successfully endio the bio but should avoid the region being
+ * marked clean by setting the state RH_NOSYNC.
+ *
+ * This function is _not_ safe in interrupt context!
+ */
+static void __bio_mark_nosync(struct mirror_set *ms,
+                             struct bio *bio, unsigned done, int error)
+{
+       unsigned long flags;
+       struct region_hash *rh = &ms->rh;
+       struct dirty_log *log = ms->rh.log;
+       struct region *reg;
+       region_t region = bio_to_region(rh, bio);
+       int recovering = 0;
+
+       /* We must inform the log that the sync count has changed. */
+       log->type->set_region_sync(log, region, 0);
+       ms->in_sync = 0;
+
+       read_lock(&rh->hash_lock);
+       reg = __rh_find(rh, region);
+       read_unlock(&rh->hash_lock);
+
+       /* region hash entry should exist because write was in-flight */
+       BUG_ON(!reg);
+       BUG_ON(!list_empty(&reg->list));
+
+       spin_lock_irqsave(&rh->region_lock, flags);
+       /*
+        * Possible cases:
+        *   1) RH_DIRTY
+        *   2) RH_NOSYNC: was dirty, other preceeding writes failed
+        *   3) RH_RECOVERING: flushing pending writes
+        * Either case, the region should have not been connected to list.
+        */
+       recovering = (reg->state == RH_RECOVERING);
+       reg->state = RH_NOSYNC;
+       BUG_ON(!list_empty(&reg->list));
+       spin_unlock_irqrestore(&rh->region_lock, flags);
+
+       bio_endio(bio, error);
+       if (recovering)
+               complete_resync_work(reg, 0);
+}
+
 static void write_callback(unsigned long error, void *context)
 {
-       unsigned int i;
-       int uptodate = 1;
+       unsigned i, ret = 0;
        struct bio *bio = (struct bio *) context;
        struct mirror_set *ms;
+       int uptodate = 0;
+       int should_wake = 0;
+       unsigned long flags;
 
-       ms = bio_get_ms(bio);
-       bio_set_ms(bio, NULL);
+       ms = bio_get_m(bio)->ms;
+       bio_set_m(bio, NULL);
 
        /*
         * NOTE: We don't decrement the pending count here,
@@ -809,26 +1072,42 @@ static void write_callback(unsigned long error, void *context)
         * This way we handle both writes to SYNC and NOSYNC
         * regions with the same code.
         */
+       if (likely(!error))
+               goto out;
+
+       for (i = 0; i < ms->nr_mirrors; i++)
+               if (test_bit(i, &error))
+                       fail_mirror(ms->mirror + i, DM_RAID1_WRITE_ERROR);
+               else
+                       uptodate = 1;
 
-       if (error) {
+       if (unlikely(!uptodate)) {
+               DMERR("All replicated volumes dead, failing I/O");
+               /* None of the writes succeeded, fail the I/O. */
+               ret = -EIO;
+       } else if (errors_handled(ms)) {
                /*
-                * only error the io if all mirrors failed.
-                * FIXME: bogus
+                * Need to raise event.  Since raising
+                * events can block, we need to do it in
+                * the main thread.
                 */
-               uptodate = 0;
-               for (i = 0; i < ms->nr_mirrors; i++)
-                       if (!test_bit(i, &error)) {
-                               uptodate = 1;
-                               break;
-                       }
+               spin_lock_irqsave(&ms->lock, flags);
+               if (!ms->failures.head)
+                       should_wake = 1;
+               bio_list_add(&ms->failures, bio);
+               spin_unlock_irqrestore(&ms->lock, flags);
+               if (should_wake)
+                       wake(ms);
+               return;
        }
-       bio_endio(bio, 0);
+out:
+       bio_endio(bio, ret);
 }
 
 static void do_write(struct mirror_set *ms, struct bio *bio)
 {
        unsigned int i;
-       struct io_region io[KCOPYD_MAX_REGIONS+1];
+       struct io_region io[ms->nr_mirrors], *dest = io;
        struct mirror *m;
        struct dm_io_request io_req = {
                .bi_rw = WRITE,
@@ -839,15 +1118,14 @@ static void do_write(struct mirror_set *ms, struct bio *bio)
                .client = ms->io_client,
        };
 
-       for (i = 0; i < ms->nr_mirrors; i++) {
-               m = ms->mirror + i;
-
-               io[i].bdev = m->dev->bdev;
-               io[i].sector = m->offset + (bio->bi_sector - ms->ti->begin);
-               io[i].count = bio->bi_size >> 9;
-       }
+       for (i = 0, m = ms->mirror; i < ms->nr_mirrors; i++, m++)
+               map_region(dest++, m, bio);
 
-       bio_set_ms(bio, ms);
+       /*
+        * Use default mirror because we only need it to retrieve the reference
+        * to the mirror set in write_callback().
+        */
+       bio_set_m(bio, get_default_mirror(ms));
 
        (void) dm_io(&io_req, ms->nr_mirrors, io, NULL);
 }
@@ -900,43 +1178,125 @@ static void do_writes(struct mirror_set *ms, struct bio_list *writes)
        /*
         * Dispatch io.
         */
-       if (unlikely(ms->log_failure))
+       if (unlikely(ms->log_failure)) {
+               spin_lock_irq(&ms->lock);
+               bio_list_merge(&ms->failures, &sync);
+               spin_unlock_irq(&ms->lock);
+       } else
                while ((bio = bio_list_pop(&sync)))
-                       bio_endio(bio, -EIO);
-       else while ((bio = bio_list_pop(&sync)))
-               do_write(ms, bio);
+                       do_write(ms, bio);
 
        while ((bio = bio_list_pop(&recover)))
                rh_delay(&ms->rh, bio);
 
        while ((bio = bio_list_pop(&nosync))) {
-               map_bio(ms, ms->default_mirror, bio);
+               map_bio(get_default_mirror(ms), bio);
                generic_make_request(bio);
        }
 }
 
+static void do_failures(struct mirror_set *ms, struct bio_list *failures)
+{
+       struct bio *bio;
+
+       if (!failures->head)
+               return;
+
+       if (!ms->log_failure) {
+               while ((bio = bio_list_pop(failures)))
+                       __bio_mark_nosync(ms, bio, bio->bi_size, 0);
+               return;
+       }
+
+       /*
+        * If the log has failed, unattempted writes are being
+        * put on the failures list.  We can't issue those writes
+        * until a log has been marked, so we must store them.
+        *
+        * If a 'noflush' suspend is in progress, we can requeue
+        * the I/O's to the core.  This give userspace a chance
+        * to reconfigure the mirror, at which point the core
+        * will reissue the writes.  If the 'noflush' flag is
+        * not set, we have no choice but to return errors.
+        *
+        * Some writes on the failures list may have been
+        * submitted before the log failure and represent a
+        * failure to write to one of the devices.  It is ok
+        * for us to treat them the same and requeue them
+        * as well.
+        */
+       if (dm_noflush_suspending(ms->ti)) {
+               while ((bio = bio_list_pop(failures)))
+                       bio_endio(bio, DM_ENDIO_REQUEUE);
+               return;
+       }
+
+       if (atomic_read(&ms->suspend)) {
+               while ((bio = bio_list_pop(failures)))
+                       bio_endio(bio, -EIO);
+               return;
+       }
+
+       spin_lock_irq(&ms->lock);
+       bio_list_merge(&ms->failures, failures);
+       spin_unlock_irq(&ms->lock);
+
+       wake(ms);
+}
+
+static void trigger_event(struct work_struct *work)
+{
+       struct mirror_set *ms =
+               container_of(work, struct mirror_set, trigger_event);
+
+       dm_table_event(ms->ti->table);
+}
+
 /*-----------------------------------------------------------------
  * kmirrord
  *---------------------------------------------------------------*/
-static void do_mirror(struct work_struct *work)
+static int _do_mirror(struct work_struct *work)
 {
        struct mirror_set *ms =container_of(work, struct mirror_set,
                                            kmirrord_work);
-       struct bio_list reads, writes;
+       struct bio_list reads, writes, failures;
+       unsigned long flags;
 
-       spin_lock(&ms->lock);
+       spin_lock_irqsave(&ms->lock, flags);
        reads = ms->reads;
        writes = ms->writes;
+       failures = ms->failures;
        bio_list_init(&ms->reads);
        bio_list_init(&ms->writes);
-       spin_unlock(&ms->lock);
+       bio_list_init(&ms->failures);
+       spin_unlock_irqrestore(&ms->lock, flags);
 
        rh_update_states(&ms->rh);
        do_recovery(ms);
        do_reads(ms, &reads);
        do_writes(ms, &writes);
+       do_failures(ms, &failures);
+
+       return (ms->failures.head) ? 1 : 0;
 }
 
+static void do_mirror(struct work_struct *work)
+{
+       /*
+        * If _do_mirror returns 1, we give it
+        * another shot.  This helps for cases like
+        * 'suspend' where we call flush_workqueue
+        * and expect all work to be finished.  If
+        * a failure happens during a suspend, we
+        * couldn't issue a 'wake' because it would
+        * not be honored.  Therefore, we return '1'
+        * from _do_mirror, and retry here.
+        */
+       while (_do_mirror(work))
+               schedule();
+}
+
+
 /*-----------------------------------------------------------------
  * Target functions
  *---------------------------------------------------------------*/
@@ -965,11 +1325,23 @@ static struct mirror_set *alloc_context(unsigned int nr_mirrors,
        ms->nr_mirrors = nr_mirrors;
        ms->nr_regions = dm_sector_div_up(ti->len, region_size);
        ms->in_sync = 0;
-       ms->default_mirror = &ms->mirror[DEFAULT_MIRROR];
+       ms->log_failure = 0;
+       atomic_set(&ms->suspend, 0);
+       atomic_set(&ms->default_mirror, DEFAULT_MIRROR);
+
+       len = sizeof(struct dm_raid1_read_record);
+       ms->read_record_pool = mempool_create_kmalloc_pool(MIN_READ_RECORDS,
+                                                          len);
+       if (!ms->read_record_pool) {
+               ti->error = "Error creating mirror read_record_pool";
+               kfree(ms);
+               return NULL;
+       }
 
        ms->io_client = dm_io_client_create(DM_IO_PAGES);
        if (IS_ERR(ms->io_client)) {
                ti->error = "Error creating dm_io client";
+               mempool_destroy(ms->read_record_pool);
                kfree(ms);
                return NULL;
        }
@@ -977,6 +1349,7 @@ static struct mirror_set *alloc_context(unsigned int nr_mirrors,
        if (rh_init(&ms->rh, ms, dl, region_size, ms->nr_regions)) {
                ti->error = "Error creating dirty region hash";
                dm_io_client_destroy(ms->io_client);
+               mempool_destroy(ms->read_record_pool);
                kfree(ms);
                return NULL;
        }
@@ -992,6 +1365,7 @@ static void free_context(struct mirror_set *ms, struct dm_target *ti,
 
        dm_io_client_destroy(ms->io_client);
        rh_exit(&ms->rh);
+       mempool_destroy(ms->read_record_pool);
        kfree(ms);
 }
 
@@ -1019,6 +1393,8 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
        }
 
        ms->mirror[mirror].ms = ms;
+       atomic_set(&(ms->mirror[mirror].error_count), 0);
+       ms->mirror[mirror].error_type = 0;
        ms->mirror[mirror].offset = offset;
 
        return 0;
@@ -1171,6 +1547,7 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
                goto err_free_context;
        }
        INIT_WORK(&ms->kmirrord_work, do_mirror);
+       INIT_WORK(&ms->trigger_event, trigger_event);
 
        r = parse_features(ms, argc, argv, &args_used);
        if (r)
@@ -1220,14 +1597,15 @@ static void mirror_dtr(struct dm_target *ti)
 
 static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw)
 {
+       unsigned long flags;
        int should_wake = 0;
        struct bio_list *bl;
 
        bl = (rw == WRITE) ? &ms->writes : &ms->reads;
-       spin_lock(&ms->lock);
+       spin_lock_irqsave(&ms->lock, flags);
        should_wake = !(bl->head);
        bio_list_add(bl, bio);
-       spin_unlock(&ms->lock);
+       spin_unlock_irqrestore(&ms->lock, flags);
 
        if (should_wake)
                wake(ms);
@@ -1242,10 +1620,11 @@ static int mirror_map(struct dm_target *ti, struct bio *bio,
        int r, rw = bio_rw(bio);
        struct mirror *m;
        struct mirror_set *ms = ti->private;
-
-       map_context->ll = bio_to_region(&ms->rh, bio);
+       struct dm_raid1_read_record *read_record = NULL;
 
        if (rw == WRITE) {
+               /* Save region for mirror_end_io() handler */
+               map_context->ll = bio_to_region(&ms->rh, bio);
                queue_bio(ms, bio, rw);
                return DM_MAPIO_SUBMITTED;
        }
@@ -1255,28 +1634,34 @@ static int mirror_map(struct dm_target *ti, struct bio *bio,
        if (r < 0 && r != -EWOULDBLOCK)
                return r;
 
-       if (r == -EWOULDBLOCK)  /* FIXME: ugly */
-               r = DM_MAPIO_SUBMITTED;
-
        /*
-        * We don't want to fast track a recovery just for a read
-        * ahead.  So we just let it silently fail.
-        * FIXME: get rid of this.
+        * If region is not in-sync queue the bio.
         */
-       if (!r && rw == READA)
-               return -EIO;
+       if (!r || (r == -EWOULDBLOCK)) {
+               if (rw == READA)
+                       return -EWOULDBLOCK;
 
-       if (!r) {
-               /* Pass this io over to the daemon */
                queue_bio(ms, bio, rw);
                return DM_MAPIO_SUBMITTED;
        }
 
+       /*
+        * The region is in-sync and we can perform reads directly.
+        * Store enough information so we can retry if it fails.
+        */
        m = choose_mirror(ms, bio->bi_sector);
-       if (!m)
+       if (unlikely(!m))
                return -EIO;
 
-       map_bio(ms, m, bio);
+       read_record = mempool_alloc(ms->read_record_pool, GFP_NOIO);
+       if (likely(read_record)) {
+               dm_bio_record(&read_record->details, bio);
+               map_context->ptr = read_record;
+               read_record->m = m;
+       }
+
+       map_bio(m, bio);
+
        return DM_MAPIO_REMAPPED;
 }
 
@@ -1285,71 +1670,173 @@ static int mirror_end_io(struct dm_target *ti, struct bio *bio,
 {
        int rw = bio_rw(bio);
        struct mirror_set *ms = (struct mirror_set *) ti->private;
-       region_t region = map_context->ll;
+       struct mirror *m = NULL;
+       struct dm_bio_details *bd = NULL;
+       struct dm_raid1_read_record *read_record = map_context->ptr;
 
        /*
         * We need to dec pending if this was a write.
         */
-       if (rw == WRITE)
-               rh_dec(&ms->rh, region);
+       if (rw == WRITE) {
+               rh_dec(&ms->rh, map_context->ll);
+               return error;
+       }
 
-       return 0;
+       if (error == -EOPNOTSUPP)
+               goto out;
+
+       if ((error == -EWOULDBLOCK) && bio_rw_ahead(bio))
+               goto out;
+
+       if (unlikely(error)) {
+               if (!read_record) {
+                       /*
+                        * There wasn't enough memory to record necessary
+                        * information for a retry or there was no other
+                        * mirror in-sync.
+                        */
+                       DMERR_LIMIT("Mirror read failed from %s.",
+                                   m->dev->name);
+                       return -EIO;
+               }
+               DMERR("Mirror read failed from %s. Trying alternative device.",
+                     m->dev->name);
+
+               m = read_record->m;
+               fail_mirror(m, DM_RAID1_READ_ERROR);
+
+               /*
+                * A failed read is requeued for another attempt using an intact
+                * mirror.
+                */
+               if (default_ok(m) || mirror_available(ms, bio)) {
+                       bd = &read_record->details;
+
+                       dm_bio_restore(bd, bio);
+                       mempool_free(read_record, ms->read_record_pool);
+                       map_context->ptr = NULL;
+                       queue_bio(ms, bio, rw);
+                       return 1;
+               }
+               DMERR("All replicated volumes dead, failing I/O");
+       }
+
+out:
+       if (read_record) {
+               mempool_free(read_record, ms->read_record_pool);
+               map_context->ptr = NULL;
+       }
+
+       return error;
 }
 
-static void mirror_postsuspend(struct dm_target *ti)
+static void mirror_presuspend(struct dm_target *ti)
 {
        struct mirror_set *ms = (struct mirror_set *) ti->private;
        struct dirty_log *log = ms->rh.log;
 
+       atomic_set(&ms->suspend, 1);
+
+       /*
+        * We must finish up all the work that we've
+        * generated (i.e. recovery work).
+        */
        rh_stop_recovery(&ms->rh);
 
-       /* Wait for all I/O we generated to complete */
        wait_event(_kmirrord_recovery_stopped,
                   !atomic_read(&ms->rh.recovery_in_flight));
 
+       if (log->type->presuspend && log->type->presuspend(log))
+               /* FIXME: need better error handling */
+               DMWARN("log presuspend failed");
+
+       /*
+        * Now that recovery is complete/stopped and the
+        * delayed bios are queued, we need to wait for
+        * the worker thread to complete.  This way,
+        * we know that all of our I/O has been pushed.
+        */
+       flush_workqueue(ms->kmirrord_wq);
+}
+
+static void mirror_postsuspend(struct dm_target *ti)
+{
+       struct mirror_set *ms = ti->private;
+       struct dirty_log *log = ms->rh.log;
+
        if (log->type->postsuspend && log->type->postsuspend(log))
                /* FIXME: need better error handling */
-               DMWARN("log suspend failed");
+               DMWARN("log postsuspend failed");
 }
 
 static void mirror_resume(struct dm_target *ti)
 {
-       struct mirror_set *ms = (struct mirror_set *) ti->private;
+       struct mirror_set *ms = ti->private;
        struct dirty_log *log = ms->rh.log;
+
+       atomic_set(&ms->suspend, 0);
        if (log->type->resume && log->type->resume(log))
                /* FIXME: need better error handling */
                DMWARN("log resume failed");
        rh_start_recovery(&ms->rh);
 }
 
+/*
+ * device_status_char
+ * @m: mirror device/leg we want the status of
+ *
+ * We return one character representing the most severe error
+ * we have encountered.
+ *    A => Alive - No failures
+ *    D => Dead - A write failure occurred leaving mirror out-of-sync
+ *    S => Sync - A sychronization failure occurred, mirror out-of-sync
+ *    R => Read - A read failure occurred, mirror data unaffected
+ *
+ * Returns: <char>
+ */
+static char device_status_char(struct mirror *m)
+{
+       if (!atomic_read(&(m->error_count)))
+               return 'A';
+
+       return (test_bit(DM_RAID1_WRITE_ERROR, &(m->error_type))) ? 'D' :
+               (test_bit(DM_RAID1_SYNC_ERROR, &(m->error_type))) ? 'S' :
+               (test_bit(DM_RAID1_READ_ERROR, &(m->error_type))) ? 'R' : 'U';
+}
+
+
 static int mirror_status(struct dm_target *ti, status_type_t type,
                         char *result, unsigned int maxlen)
 {
        unsigned int m, sz = 0;
        struct mirror_set *ms = (struct mirror_set *) ti->private;
+       struct dirty_log *log = ms->rh.log;
+       char buffer[ms->nr_mirrors + 1];
 
        switch (type) {
        case STATUSTYPE_INFO:
                DMEMIT("%d ", ms->nr_mirrors);
-               for (m = 0; m < ms->nr_mirrors; m++)
+               for (m = 0; m < ms->nr_mirrors; m++) {
                        DMEMIT("%s ", ms->mirror[m].dev->name);
+                       buffer[m] = device_status_char(&(ms->mirror[m]));
+               }
+               buffer[m] = '\0';
 
-               DMEMIT("%llu/%llu 0 ",
-                       (unsigned long long)ms->rh.log->type->
-                               get_sync_count(ms->rh.log),
-                       (unsigned long long)ms->nr_regions);
+               DMEMIT("%llu/%llu 1 %s ",
+                     (unsigned long long)log->type->get_sync_count(ms->rh.log),
+                     (unsigned long long)ms->nr_regions, buffer);
 
-               sz += ms->rh.log->type->status(ms->rh.log, type, result+sz, maxlen-sz);
+               sz += log->type->status(ms->rh.log, type, result+sz, maxlen-sz);
 
                break;
 
        case STATUSTYPE_TABLE:
-               sz = ms->rh.log->type->status(ms->rh.log, type, result, maxlen);
+               sz = log->type->status(ms->rh.log, type, result, maxlen);
 
                DMEMIT("%d", ms->nr_mirrors);
                for (m = 0; m < ms->nr_mirrors; m++)
                        DMEMIT(" %s %llu", ms->mirror[m].dev->name,
-                               (unsigned long long)ms->mirror[m].offset);
+                              (unsigned long long)ms->mirror[m].offset);
 
                if (ms->features & DM_RAID1_HANDLE_ERRORS)
                        DMEMIT(" 1 handle_errors");
@@ -1360,12 +1847,13 @@ static int mirror_status(struct dm_target *ti, status_type_t type,
 
 static struct target_type mirror_target = {
        .name    = "mirror",
-       .version = {1, 0, 3},
+       .version = {1, 0, 20},
        .module  = THIS_MODULE,
        .ctr     = mirror_ctr,
        .dtr     = mirror_dtr,
        .map     = mirror_map,
        .end_io  = mirror_end_io,
+       .presuspend = mirror_presuspend,
        .postsuspend = mirror_postsuspend,
        .resume  = mirror_resume,
        .status  = mirror_status,
index cee16fadd9ee70379449ce995ac4043d1ff86e5f..ae24eab8cd811c573b619b4e226244ff372f4119 100644 (file)
@@ -213,11 +213,15 @@ static void unregister_snapshot(struct dm_snapshot *s)
 
 /*
  * Implementation of the exception hash tables.
+ * The lowest hash_shift bits of the chunk number are ignored, allowing
+ * some consecutive chunks to be grouped together.
  */
-static int init_exception_table(struct exception_table *et, uint32_t size)
+static int init_exception_table(struct exception_table *et, uint32_t size,
+                               unsigned hash_shift)
 {
        unsigned int i;
 
+       et->hash_shift = hash_shift;
        et->hash_mask = size - 1;
        et->table = dm_vcalloc(size, sizeof(struct list_head));
        if (!et->table)
@@ -248,7 +252,7 @@ static void exit_exception_table(struct exception_table *et, struct kmem_cache *
 
 static uint32_t exception_hash(struct exception_table *et, chunk_t chunk)
 {
-       return chunk & et->hash_mask;
+       return (chunk >> et->hash_shift) & et->hash_mask;
 }
 
 static void insert_exception(struct exception_table *eh,
@@ -275,7 +279,8 @@ static struct dm_snap_exception *lookup_exception(struct exception_table *et,
 
        slot = &et->table[exception_hash(et, chunk)];
        list_for_each_entry (e, slot, hash_list)
-               if (e->old_chunk == chunk)
+               if (chunk >= e->old_chunk &&
+                   chunk <= e->old_chunk + dm_consecutive_chunk_count(e))
                        return e;
 
        return NULL;
@@ -307,6 +312,49 @@ static void free_pending_exception(struct dm_snap_pending_exception *pe)
        mempool_free(pe, pending_pool);
 }
 
+static void insert_completed_exception(struct dm_snapshot *s,
+                                      struct dm_snap_exception *new_e)
+{
+       struct exception_table *eh = &s->complete;
+       struct list_head *l;
+       struct dm_snap_exception *e = NULL;
+
+       l = &eh->table[exception_hash(eh, new_e->old_chunk)];
+
+       /* Add immediately if this table doesn't support consecutive chunks */
+       if (!eh->hash_shift)
+               goto out;
+
+       /* List is ordered by old_chunk */
+       list_for_each_entry_reverse(e, l, hash_list) {
+               /* Insert after an existing chunk? */
+               if (new_e->old_chunk == (e->old_chunk +
+                                        dm_consecutive_chunk_count(e) + 1) &&
+                   new_e->new_chunk == (dm_chunk_number(e->new_chunk) +
+                                        dm_consecutive_chunk_count(e) + 1)) {
+                       dm_consecutive_chunk_count_inc(e);
+                       free_exception(new_e);
+                       return;
+               }
+
+               /* Insert before an existing chunk? */
+               if (new_e->old_chunk == (e->old_chunk - 1) &&
+                   new_e->new_chunk == (dm_chunk_number(e->new_chunk) - 1)) {
+                       dm_consecutive_chunk_count_inc(e);
+                       e->old_chunk--;
+                       e->new_chunk--;
+                       free_exception(new_e);
+                       return;
+               }
+
+               if (new_e->old_chunk > e->old_chunk)
+                       break;
+       }
+
+out:
+       list_add(&new_e->hash_list, e ? &e->hash_list : l);
+}
+
 int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new)
 {
        struct dm_snap_exception *e;
@@ -316,8 +364,12 @@ int dm_add_exception(struct dm_snapshot *s, chunk_t old, chunk_t new)
                return -ENOMEM;
 
        e->old_chunk = old;
+
+       /* Consecutive_count is implicitly initialised to zero */
        e->new_chunk = new;
-       insert_exception(&s->complete, e);
+
+       insert_completed_exception(s, e);
+
        return 0;
 }
 
@@ -333,16 +385,6 @@ static int calc_max_buckets(void)
        return mem;
 }
 
-/*
- * Rounds a number down to a power of 2.
- */
-static uint32_t round_down(uint32_t n)
-{
-       while (n & (n - 1))
-               n &= (n - 1);
-       return n;
-}
-
 /*
  * Allocate room for a suitable hash table.
  */
@@ -361,9 +403,9 @@ static int init_hash_tables(struct dm_snapshot *s)
        hash_size = min(origin_dev_size, cow_dev_size) >> s->chunk_shift;
        hash_size = min(hash_size, max_buckets);
 
-       /* Round it down to a power of 2 */
-       hash_size = round_down(hash_size);
-       if (init_exception_table(&s->complete, hash_size))
+       hash_size = rounddown_pow_of_two(hash_size);
+       if (init_exception_table(&s->complete, hash_size,
+                                DM_CHUNK_CONSECUTIVE_BITS))
                return -ENOMEM;
 
        /*
@@ -374,7 +416,7 @@ static int init_hash_tables(struct dm_snapshot *s)
        if (hash_size < 64)
                hash_size = 64;
 
-       if (init_exception_table(&s->pending, hash_size)) {
+       if (init_exception_table(&s->pending, hash_size, 0)) {
                exit_exception_table(&s->complete, exception_cache);
                return -ENOMEM;
        }
@@ -733,7 +775,7 @@ static void pending_complete(struct dm_snap_pending_exception *pe, int success)
         * Add a proper exception, and remove the
         * in-flight exception from the list.
         */
-       insert_exception(&s->complete, e);
+       insert_completed_exception(s, e);
 
  out:
        remove_exception(&pe->e);
@@ -867,11 +909,12 @@ __find_pending_exception(struct dm_snapshot *s, struct bio *bio)
 }
 
 static void remap_exception(struct dm_snapshot *s, struct dm_snap_exception *e,
-                           struct bio *bio)
+                           struct bio *bio, chunk_t chunk)
 {
        bio->bi_bdev = s->cow->bdev;
-       bio->bi_sector = chunk_to_sector(s, e->new_chunk) +
-               (bio->bi_sector & s->chunk_mask);
+       bio->bi_sector = chunk_to_sector(s, dm_chunk_number(e->new_chunk) +
+                        (chunk - e->old_chunk)) +
+                        (bio->bi_sector & s->chunk_mask);
 }
 
 static int snapshot_map(struct dm_target *ti, struct bio *bio,
@@ -902,7 +945,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
        /* If the block is already remapped - use that, else remap it */
        e = lookup_exception(&s->complete, chunk);
        if (e) {
-               remap_exception(s, e, bio);
+               remap_exception(s, e, bio, chunk);
                goto out_unlock;
        }
 
@@ -919,7 +962,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio,
                        goto out_unlock;
                }
 
-               remap_exception(s, &pe->e, bio);
+               remap_exception(s, &pe->e, bio, chunk);
                bio_list_add(&pe->snapshot_bios, bio);
 
                r = DM_MAPIO_SUBMITTED;
@@ -1207,7 +1250,7 @@ static int origin_status(struct dm_target *ti, status_type_t type, char *result,
 
 static struct target_type origin_target = {
        .name    = "snapshot-origin",
-       .version = {1, 5, 0},
+       .version = {1, 6, 0},
        .module  = THIS_MODULE,
        .ctr     = origin_ctr,
        .dtr     = origin_dtr,
@@ -1218,7 +1261,7 @@ static struct target_type origin_target = {
 
 static struct target_type snapshot_target = {
        .name    = "snapshot",
-       .version = {1, 5, 0},
+       .version = {1, 6, 0},
        .module  = THIS_MODULE,
        .ctr     = snapshot_ctr,
        .dtr     = snapshot_dtr,
index 650e0f1f51d8a6c312a001c8443cf3bc8064d481..93bce5d49742e3441fd24b5cd511483b8027c846 100644 (file)
 
 struct exception_table {
        uint32_t hash_mask;
+       unsigned hash_shift;
        struct list_head *table;
 };
 
 /*
  * The snapshot code deals with largish chunks of the disk at a
- * time. Typically 64k - 256k.
+ * time. Typically 32k - 512k.
  */
-/* FIXME: can we get away with limiting these to a uint32_t ? */
 typedef sector_t chunk_t;
 
 /*
  * An exception is used where an old chunk of data has been
  * replaced by a new one.
+ * If chunk_t is 64 bits in size, the top 8 bits of new_chunk hold the number
+ * of chunks that follow contiguously.  Remaining bits hold the number of the
+ * chunk within the device.
  */
 struct dm_snap_exception {
        struct list_head hash_list;
@@ -37,6 +40,49 @@ struct dm_snap_exception {
        chunk_t new_chunk;
 };
 
+/*
+ * Funtions to manipulate consecutive chunks
+ */
+#  if defined(CONFIG_LBD) || (BITS_PER_LONG == 64)
+#    define DM_CHUNK_CONSECUTIVE_BITS 8
+#    define DM_CHUNK_NUMBER_BITS 56
+
+static inline chunk_t dm_chunk_number(chunk_t chunk)
+{
+       return chunk & (chunk_t)((1ULL << DM_CHUNK_NUMBER_BITS) - 1ULL);
+}
+
+static inline unsigned dm_consecutive_chunk_count(struct dm_snap_exception *e)
+{
+       return e->new_chunk >> DM_CHUNK_NUMBER_BITS;
+}
+
+static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e)
+{
+       e->new_chunk += (1ULL << DM_CHUNK_NUMBER_BITS);
+
+       BUG_ON(!dm_consecutive_chunk_count(e));
+}
+
+#  else
+#    define DM_CHUNK_CONSECUTIVE_BITS 0
+
+static inline chunk_t dm_chunk_number(chunk_t chunk)
+{
+       return chunk;
+}
+
+static inline unsigned dm_consecutive_chunk_count(struct dm_snap_exception *e)
+{
+       return 0;
+}
+
+static inline void dm_consecutive_chunk_count_inc(struct dm_snap_exception *e)
+{
+}
+
+#  endif
+
 /*
  * Abstraction to handle the meta/layout of exception stores (the
  * COW device).
index 969944a8aba2dd0b06dab4191e8b3136ba08bf58..4de90ab3968b3f9528420281a9398a9bf11ec8e7 100644 (file)
 #include <linux/log2.h>
 
 #define DM_MSG_PREFIX "striped"
+#define DM_IO_ERROR_THRESHOLD 15
 
 struct stripe {
        struct dm_dev *dev;
        sector_t physical_start;
+
+       atomic_t error_count;
 };
 
 struct stripe_c {
@@ -30,9 +33,29 @@ struct stripe_c {
        uint32_t chunk_shift;
        sector_t chunk_mask;
 
+       /* Needed for handling events */
+       struct dm_target *ti;
+
+       /* Work struct used for triggering events*/
+       struct work_struct kstriped_ws;
+
        struct stripe stripe[0];
 };
 
+static struct workqueue_struct *kstriped;
+
+/*
+ * An event is triggered whenever a drive
+ * drops out of a stripe volume.
+ */
+static void trigger_event(struct work_struct *work)
+{
+       struct stripe_c *sc = container_of(work, struct stripe_c, kstriped_ws);
+
+       dm_table_event(sc->ti->table);
+
+}
+
 static inline struct stripe_c *alloc_context(unsigned int stripes)
 {
        size_t len;
@@ -63,6 +86,7 @@ static int get_stripe(struct dm_target *ti, struct stripe_c *sc,
                return -ENXIO;
 
        sc->stripe[stripe].physical_start = start;
+
        return 0;
 }
 
@@ -135,6 +159,11 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
                return -ENOMEM;
        }
 
+       INIT_WORK(&sc->kstriped_ws, trigger_event);
+
+       /* Set pointer to dm target; used in trigger_event */
+       sc->ti = ti;
+
        sc->stripes = stripes;
        sc->stripe_width = width;
        ti->split_io = chunk_size;
@@ -158,9 +187,11 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
                        kfree(sc);
                        return r;
                }
+               atomic_set(&(sc->stripe[i].error_count), 0);
        }
 
        ti->private = sc;
+
        return 0;
 }
 
@@ -172,6 +203,7 @@ static void stripe_dtr(struct dm_target *ti)
        for (i = 0; i < sc->stripes; i++)
                dm_put_device(ti, sc->stripe[i].dev);
 
+       flush_workqueue(kstriped);
        kfree(sc);
 }
 
@@ -190,16 +222,37 @@ static int stripe_map(struct dm_target *ti, struct bio *bio,
        return DM_MAPIO_REMAPPED;
 }
 
+/*
+ * Stripe status:
+ *
+ * INFO
+ * #stripes [stripe_name <stripe_name>] [group word count]
+ * [error count 'A|D' <error count 'A|D'>]
+ *
+ * TABLE
+ * #stripes [stripe chunk size]
+ * [stripe_name physical_start <stripe_name physical_start>]
+ *
+ */
+
 static int stripe_status(struct dm_target *ti,
                         status_type_t type, char *result, unsigned int maxlen)
 {
        struct stripe_c *sc = (struct stripe_c *) ti->private;
+       char buffer[sc->stripes + 1];
        unsigned int sz = 0;
        unsigned int i;
 
        switch (type) {
        case STATUSTYPE_INFO:
-               result[0] = '\0';
+               DMEMIT("%d ", sc->stripes);
+               for (i = 0; i < sc->stripes; i++)  {
+                       DMEMIT("%s ", sc->stripe[i].dev->name);
+                       buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
+                               'D' : 'A';
+               }
+               buffer[i] = '\0';
+               DMEMIT("1 %s", buffer);
                break;
 
        case STATUSTYPE_TABLE:
@@ -213,13 +266,52 @@ static int stripe_status(struct dm_target *ti,
        return 0;
 }
 
+static int stripe_end_io(struct dm_target *ti, struct bio *bio,
+                        int error, union map_info *map_context)
+{
+       unsigned i;
+       char major_minor[16];
+       struct stripe_c *sc = ti->private;
+
+       if (!error)
+               return 0; /* I/O complete */
+
+       if ((error == -EWOULDBLOCK) && bio_rw_ahead(bio))
+               return error;
+
+       if (error == -EOPNOTSUPP)
+               return error;
+
+       memset(major_minor, 0, sizeof(major_minor));
+       sprintf(major_minor, "%d:%d",
+               bio->bi_bdev->bd_disk->major,
+               bio->bi_bdev->bd_disk->first_minor);
+
+       /*
+        * Test to see which stripe drive triggered the event
+        * and increment error count for all stripes on that device.
+        * If the error count for a given device exceeds the threshold
+        * value we will no longer trigger any further events.
+        */
+       for (i = 0; i < sc->stripes; i++)
+               if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
+                       atomic_inc(&(sc->stripe[i].error_count));
+                       if (atomic_read(&(sc->stripe[i].error_count)) <
+                           DM_IO_ERROR_THRESHOLD)
+                               queue_work(kstriped, &sc->kstriped_ws);
+               }
+
+       return error;
+}
+
 static struct target_type stripe_target = {
        .name   = "striped",
-       .version= {1, 0, 2},
+       .version = {1, 1, 0},
        .module = THIS_MODULE,
        .ctr    = stripe_ctr,
        .dtr    = stripe_dtr,
        .map    = stripe_map,
+       .end_io = stripe_end_io,
        .status = stripe_status,
 };
 
@@ -231,6 +323,13 @@ int __init dm_stripe_init(void)
        if (r < 0)
                DMWARN("target registration failed");
 
+       kstriped = create_singlethread_workqueue("kstriped");
+       if (!kstriped) {
+               DMERR("failed to create workqueue kstriped");
+               dm_unregister_target(&stripe_target);
+               return -ENOMEM;
+       }
+
        return r;
 }
 
@@ -239,5 +338,7 @@ void dm_stripe_exit(void)
        if (dm_unregister_target(&stripe_target))
                DMWARN("target unregistration failed");
 
+       destroy_workqueue(kstriped);
+
        return;
 }
index 47818d8249cbf16f125328d39d2be54c0241130a..f16062982383b71b6b74fea80972e8d93047a02a 100644 (file)
@@ -287,9 +287,8 @@ static void free_devices(struct list_head *devices)
 {
        struct list_head *tmp, *next;
 
-       for (tmp = devices->next; tmp != devices; tmp = next) {
+       list_for_each_safe(tmp, next, devices) {
                struct dm_dev *dd = list_entry(tmp, struct dm_dev, list);
-               next = tmp->next;
                kfree(dd);
        }
 }
@@ -476,7 +475,7 @@ static int __table_get_device(struct dm_table *t, struct dm_target *ti,
                              int mode, struct dm_dev **result)
 {
        int r;
-       dev_t dev;
+       dev_t uninitialized_var(dev);
        struct dm_dev *dd;
        unsigned int major, minor;
 
@@ -805,7 +804,7 @@ static int setup_indexes(struct dm_table *t)
                return -ENOMEM;
 
        /* set up internal nodes, bottom-up */
-       for (i = t->depth - 2, total = 0; i >= 0; i--) {
+       for (i = t->depth - 2; i >= 0; i--) {
                t->index[i] = indexes;
                indexes += (KEYS_PER_NODE * t->counts[i]);
                setup_btree_index(i, t);
@@ -993,12 +992,11 @@ int dm_table_resume_targets(struct dm_table *t)
 
 int dm_table_any_congested(struct dm_table *t, int bdi_bits)
 {
-       struct list_head *d, *devices;
+       struct dm_dev *dd;
+       struct list_head *devices = dm_table_get_devices(t);
        int r = 0;
 
-       devices = dm_table_get_devices(t);
-       for (d = devices->next; d != devices; d = d->next) {
-               struct dm_dev *dd = list_entry(d, struct dm_dev, list);
+       list_for_each_entry(dd, devices, list) {
                struct request_queue *q = bdev_get_queue(dd->bdev);
                r |= bdi_congested(&q->backing_dev_info, bdi_bits);
        }
@@ -1008,10 +1006,10 @@ int dm_table_any_congested(struct dm_table *t, int bdi_bits)
 
 void dm_table_unplug_all(struct dm_table *t)
 {
-       struct list_head *d, *devices = dm_table_get_devices(t);
+       struct dm_dev *dd;
+       struct list_head *devices = dm_table_get_devices(t);
 
-       for (d = devices->next; d != devices; d = d->next) {
-               struct dm_dev *dd = list_entry(d, struct dm_dev, list);
+       list_for_each_entry(dd, devices, list) {
                struct request_queue *q = bdev_get_queue(dd->bdev);
 
                blk_unplug(q);
index f2d24eb3208c97e79bdf33b9d8c396f855f55566..6617ce4af09579285a2be1090adde8c9f61a3fb4 100644 (file)
@@ -71,9 +71,22 @@ union map_info *dm_get_mapinfo(struct bio *bio)
 #define DMF_DELETING 4
 #define DMF_NOFLUSH_SUSPENDING 5
 
+/*
+ * Work processed by per-device workqueue.
+ */
+struct dm_wq_req {
+       enum {
+               DM_WQ_FLUSH_ALL,
+               DM_WQ_FLUSH_DEFERRED,
+       } type;
+       struct work_struct work;
+       struct mapped_device *md;
+       void *context;
+};
+
 struct mapped_device {
        struct rw_semaphore io_lock;
-       struct semaphore suspend_lock;
+       struct mutex suspend_lock;
        spinlock_t pushback_lock;
        rwlock_t map_lock;
        atomic_t holders;
@@ -95,6 +108,11 @@ struct mapped_device {
        struct bio_list deferred;
        struct bio_list pushback;
 
+       /*
+        * Processing queue (flush/barriers)
+        */
+       struct workqueue_struct *wq;
+
        /*
         * The current mapping.
         */
@@ -181,7 +199,7 @@ static void local_exit(void)
        DMINFO("cleaned up");
 }
 
-int (*_inits[])(void) __initdata = {
+static int (*_inits[])(void) __initdata = {
        local_init,
        dm_target_init,
        dm_linear_init,
@@ -189,7 +207,7 @@ int (*_inits[])(void) __initdata = {
        dm_interface_init,
 };
 
-void (*_exits[])(void) = {
+static void (*_exits[])(void) = {
        local_exit,
        dm_target_exit,
        dm_linear_exit,
@@ -982,7 +1000,7 @@ static struct mapped_device *alloc_dev(int minor)
        }
 
        if (!try_module_get(THIS_MODULE))
-               goto bad0;
+               goto bad_module_get;
 
        /* get a minor number for the dev */
        if (minor == DM_ANY_MINOR)
@@ -990,11 +1008,11 @@ static struct mapped_device *alloc_dev(int minor)
        else
                r = specific_minor(md, minor);
        if (r < 0)
-               goto bad1;
+               goto bad_minor;
 
        memset(md, 0, sizeof(*md));
        init_rwsem(&md->io_lock);
-       init_MUTEX(&md->suspend_lock);
+       mutex_init(&md->suspend_lock);
        spin_lock_init(&md->pushback_lock);
        rwlock_init(&md->map_lock);
        atomic_set(&md->holders, 1);
@@ -1006,7 +1024,7 @@ static struct mapped_device *alloc_dev(int minor)
 
        md->queue = blk_alloc_queue(GFP_KERNEL);
        if (!md->queue)
-               goto bad1_free_minor;
+               goto bad_queue;
 
        md->queue->queuedata = md;
        md->queue->backing_dev_info.congested_fn = dm_any_congested;
@@ -1017,11 +1035,11 @@ static struct mapped_device *alloc_dev(int minor)
 
        md->io_pool = mempool_create_slab_pool(MIN_IOS, _io_cache);
        if (!md->io_pool)
-               goto bad2;
+               goto bad_io_pool;
 
        md->tio_pool = mempool_create_slab_pool(MIN_IOS, _tio_cache);
        if (!md->tio_pool)
-               goto bad3;
+               goto bad_tio_pool;
 
        md->bs = bioset_create(16, 16);
        if (!md->bs)
@@ -1029,7 +1047,7 @@ static struct mapped_device *alloc_dev(int minor)
 
        md->disk = alloc_disk(1);
        if (!md->disk)
-               goto bad4;
+               goto bad_disk;
 
        atomic_set(&md->pending, 0);
        init_waitqueue_head(&md->wait);
@@ -1044,6 +1062,10 @@ static struct mapped_device *alloc_dev(int minor)
        add_disk(md->disk);
        format_dev_t(md->name, MKDEV(_major, minor));
 
+       md->wq = create_singlethread_workqueue("kdmflush");
+       if (!md->wq)
+               goto bad_thread;
+
        /* Populate the mapping, nobody knows we exist yet */
        spin_lock(&_minor_lock);
        old_md = idr_replace(&_minor_idr, md, minor);
@@ -1053,19 +1075,21 @@ static struct mapped_device *alloc_dev(int minor)
 
        return md;
 
- bad4:
+bad_thread:
+       put_disk(md->disk);
+bad_disk:
        bioset_free(md->bs);
- bad_no_bioset:
+bad_no_bioset:
        mempool_destroy(md->tio_pool);
- bad3:
+bad_tio_pool:
        mempool_destroy(md->io_pool);
- bad2:
+bad_io_pool:
        blk_cleanup_queue(md->queue);
- bad1_free_minor:
+bad_queue:
        free_minor(minor);
- bad1:
+bad_minor:
        module_put(THIS_MODULE);
- bad0:
+bad_module_get:
        kfree(md);
        return NULL;
 }
@@ -1080,6 +1104,7 @@ static void free_dev(struct mapped_device *md)
                unlock_fs(md);
                bdput(md->suspended_bdev);
        }
+       destroy_workqueue(md->wq);
        mempool_destroy(md->tio_pool);
        mempool_destroy(md->io_pool);
        bioset_free(md->bs);
@@ -1259,20 +1284,91 @@ void dm_put(struct mapped_device *md)
 }
 EXPORT_SYMBOL_GPL(dm_put);
 
+static int dm_wait_for_completion(struct mapped_device *md)
+{
+       int r = 0;
+
+       while (1) {
+               set_current_state(TASK_INTERRUPTIBLE);
+
+               smp_mb();
+               if (!atomic_read(&md->pending))
+                       break;
+
+               if (signal_pending(current)) {
+                       r = -EINTR;
+                       break;
+               }
+
+               io_schedule();
+       }
+       set_current_state(TASK_RUNNING);
+
+       return r;
+}
+
 /*
  * Process the deferred bios
  */
-static void __flush_deferred_io(struct mapped_device *md, struct bio *c)
+static void __flush_deferred_io(struct mapped_device *md)
 {
-       struct bio *n;
+       struct bio *c;
 
-       while (c) {
-               n = c->bi_next;
-               c->bi_next = NULL;
+       while ((c = bio_list_pop(&md->deferred))) {
                if (__split_bio(md, c))
                        bio_io_error(c);
-               c = n;
        }
+
+       clear_bit(DMF_BLOCK_IO, &md->flags);
+}
+
+static void __merge_pushback_list(struct mapped_device *md)
+{
+       unsigned long flags;
+
+       spin_lock_irqsave(&md->pushback_lock, flags);
+       clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
+       bio_list_merge_head(&md->deferred, &md->pushback);
+       bio_list_init(&md->pushback);
+       spin_unlock_irqrestore(&md->pushback_lock, flags);
+}
+
+static void dm_wq_work(struct work_struct *work)
+{
+       struct dm_wq_req *req = container_of(work, struct dm_wq_req, work);
+       struct mapped_device *md = req->md;
+
+       down_write(&md->io_lock);
+       switch (req->type) {
+       case DM_WQ_FLUSH_ALL:
+               __merge_pushback_list(md);
+               /* pass through */
+       case DM_WQ_FLUSH_DEFERRED:
+               __flush_deferred_io(md);
+               break;
+       default:
+               DMERR("dm_wq_work: unrecognised work type %d", req->type);
+               BUG();
+       }
+       up_write(&md->io_lock);
+}
+
+static void dm_wq_queue(struct mapped_device *md, int type, void *context,
+                       struct dm_wq_req *req)
+{
+       req->type = type;
+       req->md = md;
+       req->context = context;
+       INIT_WORK(&req->work, dm_wq_work);
+       queue_work(md->wq, &req->work);
+}
+
+static void dm_queue_flush(struct mapped_device *md, int type, void *context)
+{
+       struct dm_wq_req req;
+
+       dm_wq_queue(md, type, context, &req);
+       flush_workqueue(md->wq);
 }
 
 /*
@@ -1282,7 +1378,7 @@ int dm_swap_table(struct mapped_device *md, struct dm_table *table)
 {
        int r = -EINVAL;
 
-       down(&md->suspend_lock);
+       mutex_lock(&md->suspend_lock);
 
        /* device must be suspended */
        if (!dm_suspended(md))
@@ -1297,7 +1393,7 @@ int dm_swap_table(struct mapped_device *md, struct dm_table *table)
        r = __bind(md, table);
 
 out:
-       up(&md->suspend_lock);
+       mutex_unlock(&md->suspend_lock);
        return r;
 }
 
@@ -1346,17 +1442,17 @@ static void unlock_fs(struct mapped_device *md)
 int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
 {
        struct dm_table *map = NULL;
-       unsigned long flags;
        DECLARE_WAITQUEUE(wait, current);
-       struct bio *def;
-       int r = -EINVAL;
+       int r = 0;
        int do_lockfs = suspend_flags & DM_SUSPEND_LOCKFS_FLAG ? 1 : 0;
        int noflush = suspend_flags & DM_SUSPEND_NOFLUSH_FLAG ? 1 : 0;
 
-       down(&md->suspend_lock);
+       mutex_lock(&md->suspend_lock);
 
-       if (dm_suspended(md))
+       if (dm_suspended(md)) {
+               r = -EINVAL;
                goto out_unlock;
+       }
 
        map = dm_get_table(md);
 
@@ -1378,16 +1474,16 @@ int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
                        r = -ENOMEM;
                        goto flush_and_out;
                }
-       }
 
-       /*
-        * Flush I/O to the device.
-        * noflush supersedes do_lockfs, because lock_fs() needs to flush I/Os.
-        */
-       if (do_lockfs && !noflush) {
-               r = lock_fs(md);
-               if (r)
-                       goto out;
+               /*
+                * Flush I/O to the device. noflush supersedes do_lockfs,
+                * because lock_fs() needs to flush I/Os.
+                */
+               if (do_lockfs) {
+                       r = lock_fs(md);
+                       if (r)
+                               goto out;
+               }
        }
 
        /*
@@ -1404,66 +1500,36 @@ int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
                dm_table_unplug_all(map);
 
        /*
-        * Then we wait for the already mapped ios to
-        * complete.
+        * Wait for the already-mapped ios to complete.
         */
-       while (1) {
-               set_current_state(TASK_INTERRUPTIBLE);
-
-               if (!atomic_read(&md->pending) || signal_pending(current))
-                       break;
-
-               io_schedule();
-       }
-       set_current_state(TASK_RUNNING);
+       r = dm_wait_for_completion(md);
 
        down_write(&md->io_lock);
        remove_wait_queue(&md->wait, &wait);
 
-       if (noflush) {
-               spin_lock_irqsave(&md->pushback_lock, flags);
-               clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
-               bio_list_merge_head(&md->deferred, &md->pushback);
-               bio_list_init(&md->pushback);
-               spin_unlock_irqrestore(&md->pushback_lock, flags);
-       }
+       if (noflush)
+               __merge_pushback_list(md);
+       up_write(&md->io_lock);
 
        /* were we interrupted ? */
-       r = -EINTR;
-       if (atomic_read(&md->pending)) {
-               clear_bit(DMF_BLOCK_IO, &md->flags);
-               def = bio_list_get(&md->deferred);
-               __flush_deferred_io(md, def);
-               up_write(&md->io_lock);
+       if (r < 0) {
+               dm_queue_flush(md, DM_WQ_FLUSH_DEFERRED, NULL);
+
                unlock_fs(md);
                goto out; /* pushback list is already flushed, so skip flush */
        }
-       up_write(&md->io_lock);
 
        dm_table_postsuspend_targets(map);
 
        set_bit(DMF_SUSPENDED, &md->flags);
 
-       r = 0;
-
 flush_and_out:
-       if (r && noflush) {
+       if (r && noflush)
                /*
                 * Because there may be already I/Os in the pushback list,
                 * flush them before return.
                 */
-               down_write(&md->io_lock);
-
-               spin_lock_irqsave(&md->pushback_lock, flags);
-               clear_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
-               bio_list_merge_head(&md->deferred, &md->pushback);
-               bio_list_init(&md->pushback);
-               spin_unlock_irqrestore(&md->pushback_lock, flags);
-
-               def = bio_list_get(&md->deferred);
-               __flush_deferred_io(md, def);
-               up_write(&md->io_lock);
-       }
+               dm_queue_flush(md, DM_WQ_FLUSH_ALL, NULL);
 
 out:
        if (r && md->suspended_bdev) {
@@ -1474,17 +1540,16 @@ out:
        dm_table_put(map);
 
 out_unlock:
-       up(&md->suspend_lock);
+       mutex_unlock(&md->suspend_lock);
        return r;
 }
 
 int dm_resume(struct mapped_device *md)
 {
        int r = -EINVAL;
-       struct bio *def;
        struct dm_table *map = NULL;
 
-       down(&md->suspend_lock);
+       mutex_lock(&md->suspend_lock);
        if (!dm_suspended(md))
                goto out;
 
@@ -1496,12 +1561,7 @@ int dm_resume(struct mapped_device *md)
        if (r)
                goto out;
 
-       down_write(&md->io_lock);
-       clear_bit(DMF_BLOCK_IO, &md->flags);
-
-       def = bio_list_get(&md->deferred);
-       __flush_deferred_io(md, def);
-       up_write(&md->io_lock);
+       dm_queue_flush(md, DM_WQ_FLUSH_DEFERRED, NULL);
 
        unlock_fs(md);
 
@@ -1520,7 +1580,7 @@ int dm_resume(struct mapped_device *md)
 
 out:
        dm_table_put(map);
-       up(&md->suspend_lock);
+       mutex_unlock(&md->suspend_lock);
 
        return r;
 }
index 78cd33861766ed1d8ae6b325cc579e6dbe32f803..c143a86c2ea6f03b6379220a20e04d254ecc54be 100644 (file)
@@ -13,6 +13,15 @@ menuconfig MISC_DEVICES
 
 if MISC_DEVICES
 
+config ATMEL_PWM
+       tristate "Atmel AT32/AT91 PWM support"
+       depends on AVR32 || ARCH_AT91
+       help
+         This option enables device driver support for the PWM channels
+         on certain Atmel prcoessors.  Pulse Width Modulation is used for
+         purposes including software controlled power-efficent backlights
+         on LCD displays, motor control, and waveform generation.
+
 config IBM_ASM
        tristate "Device driver for IBM RSA service processor"
        depends on X86 && PCI && INPUT && EXPERIMENTAL
@@ -97,9 +106,9 @@ config ACER_WMI
        depends on X86
        depends on EXPERIMENTAL
        depends on ACPI
-       depends on ACPI_WMI
        depends on LEDS_CLASS
        depends on BACKLIGHT_CLASS_DEVICE
+       select ACPI_WMI
        ---help---
          This is a driver for newer Acer (and Wistron) laptops. It adds
          wireless radio and bluetooth control, and on some laptops,
@@ -146,7 +155,7 @@ config TC1100_WMI
        tristate "HP Compaq TC1100 Tablet WMI Extras"
        depends on X86 && !X86_64
        depends on ACPI
-       depends on ACPI_WMI
+       select ACPI_WMI
        ---help---
          This is a driver for the WMI extensions (wireless and bluetooth power
          control) of the HP Compaq TC1100 tablet.
@@ -279,10 +288,20 @@ config ATMEL_SSC
 config INTEL_MENLOW
        tristate "Thermal Management driver for Intel menlow platform"
        depends on ACPI_THERMAL
+       depends on X86
        ---help---
          ACPI thermal management enhancement driver on
          Intel Menlow platform.
 
          If unsure, say N.
 
+config ENCLOSURE_SERVICES
+       tristate "Enclosure Services"
+       default n
+       help
+         Provides support for intelligent enclosures (bays which
+         contain storage devices).  You also need either a host
+         driver (SCSI/ATA) which supports enclosures
+         or a SCSI enclosure device (SES) to use these services.
+
 endif # MISC_DEVICES
index 1f41654aae4dae7ad85796fc43bfdf01eecafc31..3b12f5da8562d1ca47cc84a20a38a6f7f4dddd4d 100644 (file)
@@ -8,6 +8,7 @@ obj-$(CONFIG_HDPU_FEATURES)     += hdpuftrs/
 obj-$(CONFIG_MSI_LAPTOP)     += msi-laptop.o
 obj-$(CONFIG_ACER_WMI)     += acer-wmi.o
 obj-$(CONFIG_ASUS_LAPTOP)     += asus-laptop.o
+obj-$(CONFIG_ATMEL_PWM)                += atmel_pwm.o
 obj-$(CONFIG_ATMEL_SSC)                += atmel-ssc.o
 obj-$(CONFIG_TC1100_WMI)       += tc1100-wmi.o
 obj-$(CONFIG_LKDTM)            += lkdtm.o
@@ -20,3 +21,4 @@ obj-$(CONFIG_THINKPAD_ACPI)   += thinkpad_acpi.o
 obj-$(CONFIG_FUJITSU_LAPTOP)   += fujitsu-laptop.o
 obj-$(CONFIG_EEPROM_93CX6)     += eeprom_93cx6.o
 obj-$(CONFIG_INTEL_MENLOW)     += intel_menlow.o
+obj-$(CONFIG_ENCLOSURE_SERVICES) += enclosure.o
diff --git a/drivers/misc/atmel_pwm.c b/drivers/misc/atmel_pwm.c
new file mode 100644 (file)
index 0000000..f8d3b9a
--- /dev/null
@@ -0,0 +1,409 @@
+#include <linux/module.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/atmel_pwm.h>
+
+
+/*
+ * This is a simple driver for the PWM controller found in various newer
+ * Atmel SOCs, including the AVR32 series and the AT91sam9263.
+ *
+ * Chips with current Linux ports have only 4 PWM channels, out of max 32.
+ * AT32UC3A and AT32UC3B chips have 7 channels (but currently no Linux).
+ * Docs are inconsistent about the width of the channel counter registers;
+ * it's at least 16 bits, but several places say 20 bits.
+ */
+#define        PWM_NCHAN       4               /* max 32 */
+
+struct pwm {
+       spinlock_t              lock;
+       struct platform_device  *pdev;
+       u32                     mask;
+       int                     irq;
+       void __iomem            *base;
+       struct clk              *clk;
+       struct pwm_channel      *channel[PWM_NCHAN];
+       void                    (*handler[PWM_NCHAN])(struct pwm_channel *);
+};
+
+
+/* global PWM controller registers */
+#define PWM_MR         0x00
+#define PWM_ENA                0x04
+#define PWM_DIS                0x08
+#define PWM_SR         0x0c
+#define PWM_IER                0x10
+#define PWM_IDR                0x14
+#define PWM_IMR                0x18
+#define PWM_ISR                0x1c
+
+static inline void pwm_writel(const struct pwm *p, unsigned offset, u32 val)
+{
+       __raw_writel(val, p->base + offset);
+}
+
+static inline u32 pwm_readl(const struct pwm *p, unsigned offset)
+{
+       return __raw_readl(p->base + offset);
+}
+
+static inline void __iomem *pwmc_regs(const struct pwm *p, int index)
+{
+       return p->base + 0x200 + index * 0x20;
+}
+
+static struct pwm *pwm;
+
+static void pwm_dumpregs(struct pwm_channel *ch, char *tag)
+{
+       struct device   *dev = &pwm->pdev->dev;
+
+       dev_dbg(dev, "%s: mr %08x, sr %08x, imr %08x\n",
+               tag,
+               pwm_readl(pwm, PWM_MR),
+               pwm_readl(pwm, PWM_SR),
+               pwm_readl(pwm, PWM_IMR));
+       dev_dbg(dev,
+               "pwm ch%d - mr %08x, dty %u, prd %u, cnt %u\n",
+               ch->index,
+               pwm_channel_readl(ch, PWM_CMR),
+               pwm_channel_readl(ch, PWM_CDTY),
+               pwm_channel_readl(ch, PWM_CPRD),
+               pwm_channel_readl(ch, PWM_CCNT));
+}
+
+
+/**
+ * pwm_channel_alloc - allocate an unused PWM channel
+ * @index: identifies the channel
+ * @ch: structure to be initialized
+ *
+ * Drivers allocate PWM channels according to the board's wiring, and
+ * matching board-specific setup code.  Returns zero or negative errno.
+ */
+int pwm_channel_alloc(int index, struct pwm_channel *ch)
+{
+       unsigned long   flags;
+       int             status = 0;
+
+       /* insist on PWM init, with this signal pinned out */
+       if (!pwm || !(pwm->mask & 1 << index))
+               return -ENODEV;
+
+       if (index < 0 || index >= PWM_NCHAN || !ch)
+               return -EINVAL;
+       memset(ch, 0, sizeof *ch);
+
+       spin_lock_irqsave(&pwm->lock, flags);
+       if (pwm->channel[index])
+               status = -EBUSY;
+       else {
+               clk_enable(pwm->clk);
+
+               ch->regs = pwmc_regs(pwm, index);
+               ch->index = index;
+
+               /* REVISIT: ap7000 seems to go 2x as fast as we expect!! */
+               ch->mck = clk_get_rate(pwm->clk);
+
+               pwm->channel[index] = ch;
+               pwm->handler[index] = NULL;
+
+               /* channel and irq are always disabled when we return */
+               pwm_writel(pwm, PWM_DIS, 1 << index);
+               pwm_writel(pwm, PWM_IDR, 1 << index);
+       }
+       spin_unlock_irqrestore(&pwm->lock, flags);
+       return status;
+}
+EXPORT_SYMBOL(pwm_channel_alloc);
+
+static int pwmcheck(struct pwm_channel *ch)
+{
+       int             index;
+
+       if (!pwm)
+               return -ENODEV;
+       if (!ch)
+               return -EINVAL;
+       index = ch->index;
+       if (index < 0 || index >= PWM_NCHAN || pwm->channel[index] != ch)
+               return -EINVAL;
+
+       return index;
+}
+
+/**
+ * pwm_channel_free - release a previously allocated channel
+ * @ch: the channel being released
+ *
+ * The channel is completely shut down (counter and IRQ disabled),
+ * and made available for re-use.  Returns zero, or negative errno.
+ */
+int pwm_channel_free(struct pwm_channel *ch)
+{
+       unsigned long   flags;
+       int             t;
+
+       spin_lock_irqsave(&pwm->lock, flags);
+       t = pwmcheck(ch);
+       if (t >= 0) {
+               pwm->channel[t] = NULL;
+               pwm->handler[t] = NULL;
+
+               /* channel and irq are always disabled when we return */
+               pwm_writel(pwm, PWM_DIS, 1 << t);
+               pwm_writel(pwm, PWM_IDR, 1 << t);
+
+               clk_disable(pwm->clk);
+               t = 0;
+       }
+       spin_unlock_irqrestore(&pwm->lock, flags);
+       return t;
+}
+EXPORT_SYMBOL(pwm_channel_free);
+
+int __pwm_channel_onoff(struct pwm_channel *ch, int enabled)
+{
+       unsigned long   flags;
+       int             t;
+
+       /* OMITTED FUNCTIONALITY:  starting several channels in synch */
+
+       spin_lock_irqsave(&pwm->lock, flags);
+       t = pwmcheck(ch);
+       if (t >= 0) {
+               pwm_writel(pwm, enabled ? PWM_ENA : PWM_DIS, 1 << t);
+               t = 0;
+               pwm_dumpregs(ch, enabled ? "enable" : "disable");
+       }
+       spin_unlock_irqrestore(&pwm->lock, flags);
+
+       return t;
+}
+EXPORT_SYMBOL(__pwm_channel_onoff);
+
+/**
+ * pwm_clk_alloc - allocate and configure CLKA or CLKB
+ * @prescale: from 0..10, the power of two used to divide MCK
+ * @div: from 1..255, the linear divisor to use
+ *
+ * Returns PWM_CPR_CLKA, PWM_CPR_CLKB, or negative errno.  The allocated
+ * clock will run with a period of (2^prescale * div) / MCK, or twice as
+ * long if center aligned PWM output is used.  The clock must later be
+ * deconfigured using pwm_clk_free().
+ */
+int pwm_clk_alloc(unsigned prescale, unsigned div)
+{
+       unsigned long   flags;
+       u32             mr;
+       u32             val = (prescale << 8) | div;
+       int             ret = -EBUSY;
+
+       if (prescale >= 10 || div == 0 || div > 255)
+               return -EINVAL;
+
+       spin_lock_irqsave(&pwm->lock, flags);
+       mr = pwm_readl(pwm, PWM_MR);
+       if ((mr & 0xffff) == 0) {
+               mr |= val;
+               ret = PWM_CPR_CLKA;
+       }
+       if ((mr & (0xffff << 16)) == 0) {
+               mr |= val << 16;
+               ret = PWM_CPR_CLKB;
+       }
+       if (ret > 0)
+               pwm_writel(pwm, PWM_MR, mr);
+       spin_unlock_irqrestore(&pwm->lock, flags);
+       return ret;
+}
+EXPORT_SYMBOL(pwm_clk_alloc);
+
+/**
+ * pwm_clk_free - deconfigure and release CLKA or CLKB
+ *
+ * Reverses the effect of pwm_clk_alloc().
+ */
+void pwm_clk_free(unsigned clk)
+{
+       unsigned long   flags;
+       u32             mr;
+
+       spin_lock_irqsave(&pwm->lock, flags);
+       mr = pwm_readl(pwm, PWM_MR);
+       if (clk == PWM_CPR_CLKA)
+               pwm_writel(pwm, PWM_MR, mr & ~(0xffff << 0));
+       if (clk == PWM_CPR_CLKB)
+               pwm_writel(pwm, PWM_MR, mr & ~(0xffff << 16));
+       spin_unlock_irqrestore(&pwm->lock, flags);
+}
+EXPORT_SYMBOL(pwm_clk_free);
+
+/**
+ * pwm_channel_handler - manage channel's IRQ handler
+ * @ch: the channel
+ * @handler: the handler to use, possibly NULL
+ *
+ * If the handler is non-null, the handler will be called after every
+ * period of this PWM channel.  If the handler is null, this channel
+ * won't generate an IRQ.
+ */
+int pwm_channel_handler(struct pwm_channel *ch,
+               void (*handler)(struct pwm_channel *ch))
+{
+       unsigned long   flags;
+       int             t;
+
+       spin_lock_irqsave(&pwm->lock, flags);
+       t = pwmcheck(ch);
+       if (t >= 0) {
+               pwm->handler[t] = handler;
+               pwm_writel(pwm, handler ? PWM_IER : PWM_IDR, 1 << t);
+               t = 0;
+       }
+       spin_unlock_irqrestore(&pwm->lock, flags);
+
+       return t;
+}
+EXPORT_SYMBOL(pwm_channel_handler);
+
+static irqreturn_t pwm_irq(int id, void *_pwm)
+{
+       struct pwm      *p = _pwm;
+       irqreturn_t     handled = IRQ_NONE;
+       u32             irqstat;
+       int             index;
+
+       spin_lock(&p->lock);
+
+       /* ack irqs, then handle them */
+       irqstat = pwm_readl(pwm, PWM_ISR);
+
+       while (irqstat) {
+               struct pwm_channel *ch;
+               void (*handler)(struct pwm_channel *ch);
+
+               index = ffs(irqstat) - 1;
+               irqstat &= ~(1 << index);
+               ch = pwm->channel[index];
+               handler = pwm->handler[index];
+               if (handler && ch) {
+                       spin_unlock(&p->lock);
+                       handler(ch);
+                       spin_lock(&p->lock);
+                       handled = IRQ_HANDLED;
+               }
+       }
+
+       spin_unlock(&p->lock);
+       return handled;
+}
+
+static int __init pwm_probe(struct platform_device *pdev)
+{
+       struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       int irq = platform_get_irq(pdev, 0);
+       u32 *mp = pdev->dev.platform_data;
+       struct pwm *p;
+       int status = -EIO;
+
+       if (pwm)
+               return -EBUSY;
+       if (!r || irq < 0 || !mp || !*mp)
+               return -ENODEV;
+       if (*mp & ~((1<<PWM_NCHAN)-1)) {
+               dev_warn(&pdev->dev, "mask 0x%x ... more than %d channels\n",
+                       *mp, PWM_NCHAN);
+               return -EINVAL;
+       }
+
+       p = kzalloc(sizeof(*p), GFP_KERNEL);
+       if (!p)
+               return -ENOMEM;
+
+       spin_lock_init(&p->lock);
+       p->pdev = pdev;
+       p->mask = *mp;
+       p->irq = irq;
+       p->base = ioremap(r->start, r->end - r->start + 1);
+       if (!p->base)
+               goto fail;
+       p->clk = clk_get(&pdev->dev, "mck");
+       if (IS_ERR(p->clk)) {
+               status = PTR_ERR(p->clk);
+               p->clk = NULL;
+               goto fail;
+       }
+
+       status = request_irq(irq, pwm_irq, 0, pdev->name, p);
+       if (status < 0)
+               goto fail;
+
+       pwm = p;
+       platform_set_drvdata(pdev, p);
+
+       return 0;
+
+fail:
+       if (p->clk)
+               clk_put(p->clk);
+       if (p->base)
+               iounmap(p->base);
+
+       kfree(p);
+       return status;
+}
+
+static int __exit pwm_remove(struct platform_device *pdev)
+{
+       struct pwm *p = platform_get_drvdata(pdev);
+
+       if (p != pwm)
+               return -EINVAL;
+
+       clk_enable(pwm->clk);
+       pwm_writel(pwm, PWM_DIS, (1 << PWM_NCHAN) - 1);
+       pwm_writel(pwm, PWM_IDR, (1 << PWM_NCHAN) - 1);
+       clk_disable(pwm->clk);
+
+       pwm = NULL;
+
+       free_irq(p->irq, p);
+       clk_put(p->clk);
+       iounmap(p->base);
+       kfree(p);
+
+       return 0;
+}
+
+static struct platform_driver atmel_pwm_driver = {
+       .driver = {
+               .name = "atmel_pwm",
+               .owner = THIS_MODULE,
+       },
+       .remove = __exit_p(pwm_remove),
+
+       /* NOTE: PWM can keep running in AVR32 "idle" and "frozen" states;
+        * and all AT91sam9263 states, albeit at reduced clock rate if
+        * MCK becomes the slow clock (i.e. what Linux labels STR).
+        */
+};
+
+static int __init pwm_init(void)
+{
+       return platform_driver_probe(&atmel_pwm_driver, pwm_probe);
+}
+module_init(pwm_init);
+
+static void __exit pwm_exit(void)
+{
+       platform_driver_unregister(&atmel_pwm_driver);
+}
+module_exit(pwm_exit);
+
+MODULE_DESCRIPTION("Driver for AT32/AT91 PWM module");
+MODULE_LICENSE("GPL");
diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c
new file mode 100644 (file)
index 0000000..6fcb0e9
--- /dev/null
@@ -0,0 +1,484 @@
+/*
+ * Enclosure Services
+ *
+ * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com>
+ *
+**-----------------------------------------------------------------------------
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  version 2 as published by the Free Software Foundation.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+**
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+**-----------------------------------------------------------------------------
+*/
+#include <linux/device.h>
+#include <linux/enclosure.h>
+#include <linux/err.h>
+#include <linux/list.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+
+static LIST_HEAD(container_list);
+static DEFINE_MUTEX(container_list_lock);
+static struct class enclosure_class;
+static struct class enclosure_component_class;
+
+/**
+ * enclosure_find - find an enclosure given a device
+ * @dev:       the device to find for
+ *
+ * Looks through the list of registered enclosures to see
+ * if it can find a match for a device.  Returns NULL if no
+ * enclosure is found. Obtains a reference to the enclosure class
+ * device which must be released with class_device_put().
+ */
+struct enclosure_device *enclosure_find(struct device *dev)
+{
+       struct enclosure_device *edev = NULL;
+
+       mutex_lock(&container_list_lock);
+       list_for_each_entry(edev, &container_list, node) {
+               if (edev->cdev.dev == dev) {
+                       class_device_get(&edev->cdev);
+                       mutex_unlock(&container_list_lock);
+                       return edev;
+               }
+       }
+       mutex_unlock(&container_list_lock);
+
+       return NULL;
+}
+EXPORT_SYMBOL_GPL(enclosure_find);
+
+/**
+ * enclosure_for_each_device - calls a function for each enclosure
+ * @fn:                the function to call
+ * @data:      the data to pass to each call
+ *
+ * Loops over all the enclosures calling the function.
+ *
+ * Note, this function uses a mutex which will be held across calls to
+ * @fn, so it must have non atomic context, and @fn may (although it
+ * should not) sleep or otherwise cause the mutex to be held for
+ * indefinite periods
+ */
+int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
+                             void *data)
+{
+       int error = 0;
+       struct enclosure_device *edev;
+
+       mutex_lock(&container_list_lock);
+       list_for_each_entry(edev, &container_list, node) {
+               error = fn(edev, data);
+               if (error)
+                       break;
+       }
+       mutex_unlock(&container_list_lock);
+
+       return error;
+}
+EXPORT_SYMBOL_GPL(enclosure_for_each_device);
+
+/**
+ * enclosure_register - register device as an enclosure
+ *
+ * @dev:       device containing the enclosure
+ * @components:        number of components in the enclosure
+ *
+ * This sets up the device for being an enclosure.  Note that @dev does
+ * not have to be a dedicated enclosure device.  It may be some other type
+ * of device that additionally responds to enclosure services
+ */
+struct enclosure_device *
+enclosure_register(struct device *dev, const char *name, int components,
+                  struct enclosure_component_callbacks *cb)
+{
+       struct enclosure_device *edev =
+               kzalloc(sizeof(struct enclosure_device) +
+                       sizeof(struct enclosure_component)*components,
+                       GFP_KERNEL);
+       int err, i;
+
+       BUG_ON(!cb);
+
+       if (!edev)
+               return ERR_PTR(-ENOMEM);
+
+       edev->components = components;
+
+       edev->cdev.class = &enclosure_class;
+       edev->cdev.dev = get_device(dev);
+       edev->cb = cb;
+       snprintf(edev->cdev.class_id, BUS_ID_SIZE, "%s", name);
+       err = class_device_register(&edev->cdev);
+       if (err)
+               goto err;
+
+       for (i = 0; i < components; i++)
+               edev->component[i].number = -1;
+
+       mutex_lock(&container_list_lock);
+       list_add_tail(&edev->node, &container_list);
+       mutex_unlock(&container_list_lock);
+
+       return edev;
+
+ err:
+       put_device(edev->cdev.dev);
+       kfree(edev);
+       return ERR_PTR(err);
+}
+EXPORT_SYMBOL_GPL(enclosure_register);
+
+static struct enclosure_component_callbacks enclosure_null_callbacks;
+
+/**
+ * enclosure_unregister - remove an enclosure
+ *
+ * @edev:      the registered enclosure to remove;
+ */
+void enclosure_unregister(struct enclosure_device *edev)
+{
+       int i;
+
+       mutex_lock(&container_list_lock);
+       list_del(&edev->node);
+       mutex_unlock(&container_list_lock);
+
+       for (i = 0; i < edev->components; i++)
+               if (edev->component[i].number != -1)
+                       class_device_unregister(&edev->component[i].cdev);
+
+       /* prevent any callbacks into service user */
+       edev->cb = &enclosure_null_callbacks;
+       class_device_unregister(&edev->cdev);
+}
+EXPORT_SYMBOL_GPL(enclosure_unregister);
+
+static void enclosure_release(struct class_device *cdev)
+{
+       struct enclosure_device *edev = to_enclosure_device(cdev);
+
+       put_device(cdev->dev);
+       kfree(edev);
+}
+
+static void enclosure_component_release(struct class_device *cdev)
+{
+       if (cdev->dev)
+               put_device(cdev->dev);
+       class_device_put(cdev->parent);
+}
+
+/**
+ * enclosure_component_register - add a particular component to an enclosure
+ * @edev:      the enclosure to add the component
+ * @num:       the device number
+ * @type:      the type of component being added
+ * @name:      an optional name to appear in sysfs (leave NULL if none)
+ *
+ * Registers the component.  The name is optional for enclosures that
+ * give their components a unique name.  If not, leave the field NULL
+ * and a name will be assigned.
+ *
+ * Returns a pointer to the enclosure component or an error.
+ */
+struct enclosure_component *
+enclosure_component_register(struct enclosure_device *edev,
+                            unsigned int number,
+                            enum enclosure_component_type type,
+                            const char *name)
+{
+       struct enclosure_component *ecomp;
+       struct class_device *cdev;
+       int err;
+
+       if (number >= edev->components)
+               return ERR_PTR(-EINVAL);
+
+       ecomp = &edev->component[number];
+
+       if (ecomp->number != -1)
+               return ERR_PTR(-EINVAL);
+
+       ecomp->type = type;
+       ecomp->number = number;
+       cdev = &ecomp->cdev;
+       cdev->parent = class_device_get(&edev->cdev);
+       cdev->class = &enclosure_component_class;
+       if (name)
+               snprintf(cdev->class_id, BUS_ID_SIZE, "%s", name);
+       else
+               snprintf(cdev->class_id, BUS_ID_SIZE, "%u", number);
+
+       err = class_device_register(cdev);
+       if (err)
+               ERR_PTR(err);
+
+       return ecomp;
+}
+EXPORT_SYMBOL_GPL(enclosure_component_register);
+
+/**
+ * enclosure_add_device - add a device as being part of an enclosure
+ * @edev:      the enclosure device being added to.
+ * @num:       the number of the component
+ * @dev:       the device being added
+ *
+ * Declares a real device to reside in slot (or identifier) @num of an
+ * enclosure.  This will cause the relevant sysfs links to appear.
+ * This function may also be used to change a device associated with
+ * an enclosure without having to call enclosure_remove_device() in
+ * between.
+ *
+ * Returns zero on success or an error.
+ */
+int enclosure_add_device(struct enclosure_device *edev, int component,
+                        struct device *dev)
+{
+       struct class_device *cdev;
+
+       if (!edev || component >= edev->components)
+               return -EINVAL;
+
+       cdev = &edev->component[component].cdev;
+
+       class_device_del(cdev);
+       if (cdev->dev)
+               put_device(cdev->dev);
+       cdev->dev = get_device(dev);
+       return class_device_add(cdev);
+}
+EXPORT_SYMBOL_GPL(enclosure_add_device);
+
+/**
+ * enclosure_remove_device - remove a device from an enclosure
+ * @edev:      the enclosure device
+ * @num:       the number of the component to remove
+ *
+ * Returns zero on success or an error.
+ *
+ */
+int enclosure_remove_device(struct enclosure_device *edev, int component)
+{
+       struct class_device *cdev;
+
+       if (!edev || component >= edev->components)
+               return -EINVAL;
+
+       cdev = &edev->component[component].cdev;
+
+       class_device_del(cdev);
+       if (cdev->dev)
+               put_device(cdev->dev);
+       cdev->dev = NULL;
+       return class_device_add(cdev);
+}
+EXPORT_SYMBOL_GPL(enclosure_remove_device);
+
+/*
+ * sysfs pieces below
+ */
+
+static ssize_t enclosure_show_components(struct class_device *cdev, char *buf)
+{
+       struct enclosure_device *edev = to_enclosure_device(cdev);
+
+       return snprintf(buf, 40, "%d\n", edev->components);
+}
+
+static struct class_device_attribute enclosure_attrs[] = {
+       __ATTR(components, S_IRUGO, enclosure_show_components, NULL),
+       __ATTR_NULL
+};
+
+static struct class enclosure_class = {
+       .name                   = "enclosure",
+       .owner                  = THIS_MODULE,
+       .release                = enclosure_release,
+       .class_dev_attrs        = enclosure_attrs,
+};
+
+static const char *const enclosure_status [] = {
+       [ENCLOSURE_STATUS_UNSUPPORTED] = "unsupported",
+       [ENCLOSURE_STATUS_OK] = "OK",
+       [ENCLOSURE_STATUS_CRITICAL] = "critical",
+       [ENCLOSURE_STATUS_NON_CRITICAL] = "non-critical",
+       [ENCLOSURE_STATUS_UNRECOVERABLE] = "unrecoverable",
+       [ENCLOSURE_STATUS_NOT_INSTALLED] = "not installed",
+       [ENCLOSURE_STATUS_UNKNOWN] = "unknown",
+       [ENCLOSURE_STATUS_UNAVAILABLE] = "unavailable",
+};
+
+static const char *const enclosure_type [] = {
+       [ENCLOSURE_COMPONENT_DEVICE] = "device",
+       [ENCLOSURE_COMPONENT_ARRAY_DEVICE] = "array device",
+};
+
+static ssize_t get_component_fault(struct class_device *cdev, char *buf)
+{
+       struct enclosure_device *edev = to_enclosure_device(cdev->parent);
+       struct enclosure_component *ecomp = to_enclosure_component(cdev);
+
+       if (edev->cb->get_fault)
+               edev->cb->get_fault(edev, ecomp);
+       return snprintf(buf, 40, "%d\n", ecomp->fault);
+}
+
+static ssize_t set_component_fault(struct class_device *cdev, const char *buf,
+                                  size_t count)
+{
+       struct enclosure_device *edev = to_enclosure_device(cdev->parent);
+       struct enclosure_component *ecomp = to_enclosure_component(cdev);
+       int val = simple_strtoul(buf, NULL, 0);
+
+       if (edev->cb->set_fault)
+               edev->cb->set_fault(edev, ecomp, val);
+       return count;
+}
+
+static ssize_t get_component_status(struct class_device *cdev, char *buf)
+{
+       struct enclosure_device *edev = to_enclosure_device(cdev->parent);
+       struct enclosure_component *ecomp = to_enclosure_component(cdev);
+
+       if (edev->cb->get_status)
+               edev->cb->get_status(edev, ecomp);
+       return snprintf(buf, 40, "%s\n", enclosure_status[ecomp->status]);
+}
+
+static ssize_t set_component_status(struct class_device *cdev, const char *buf,
+                                  size_t count)
+{
+       struct enclosure_device *edev = to_enclosure_device(cdev->parent);
+       struct enclosure_component *ecomp = to_enclosure_component(cdev);
+       int i;
+
+       for (i = 0; enclosure_status[i]; i++) {
+               if (strncmp(buf, enclosure_status[i],
+                           strlen(enclosure_status[i])) == 0 &&
+                   (buf[strlen(enclosure_status[i])] == '\n' ||
+                    buf[strlen(enclosure_status[i])] == '\0'))
+                       break;
+       }
+
+       if (enclosure_status[i] && edev->cb->set_status) {
+               edev->cb->set_status(edev, ecomp, i);
+               return count;
+       } else
+               return -EINVAL;
+}
+
+static ssize_t get_component_active(struct class_device *cdev, char *buf)
+{
+       struct enclosure_device *edev = to_enclosure_device(cdev->parent);
+       struct enclosure_component *ecomp = to_enclosure_component(cdev);
+
+       if (edev->cb->get_active)
+               edev->cb->get_active(edev, ecomp);
+       return snprintf(buf, 40, "%d\n", ecomp->active);
+}
+
+static ssize_t set_component_active(struct class_device *cdev, const char *buf,
+                                  size_t count)
+{
+       struct enclosure_device *edev = to_enclosure_device(cdev->parent);
+       struct enclosure_component *ecomp = to_enclosure_component(cdev);
+       int val = simple_strtoul(buf, NULL, 0);
+
+       if (edev->cb->set_active)
+               edev->cb->set_active(edev, ecomp, val);
+       return count;
+}
+
+static ssize_t get_component_locate(struct class_device *cdev, char *buf)
+{
+       struct enclosure_device *edev = to_enclosure_device(cdev->parent);
+       struct enclosure_component *ecomp = to_enclosure_component(cdev);
+
+       if (edev->cb->get_locate)
+               edev->cb->get_locate(edev, ecomp);
+       return snprintf(buf, 40, "%d\n", ecomp->locate);
+}
+
+static ssize_t set_component_locate(struct class_device *cdev, const char *buf,
+                                  size_t count)
+{
+       struct enclosure_device *edev = to_enclosure_device(cdev->parent);
+       struct enclosure_component *ecomp = to_enclosure_component(cdev);
+       int val = simple_strtoul(buf, NULL, 0);
+
+       if (edev->cb->set_locate)
+               edev->cb->set_locate(edev, ecomp, val);
+       return count;
+}
+
+static ssize_t get_component_type(struct class_device *cdev, char *buf)
+{
+       struct enclosure_component *ecomp = to_enclosure_component(cdev);
+
+       return snprintf(buf, 40, "%s\n", enclosure_type[ecomp->type]);
+}
+
+
+static struct class_device_attribute enclosure_component_attrs[] = {
+       __ATTR(fault, S_IRUGO | S_IWUSR, get_component_fault,
+              set_component_fault),
+       __ATTR(status, S_IRUGO | S_IWUSR, get_component_status,
+              set_component_status),
+       __ATTR(active, S_IRUGO | S_IWUSR, get_component_active,
+              set_component_active),
+       __ATTR(locate, S_IRUGO | S_IWUSR, get_component_locate,
+              set_component_locate),
+       __ATTR(type, S_IRUGO, get_component_type, NULL),
+       __ATTR_NULL
+};
+
+static struct class enclosure_component_class =  {
+       .name                   = "enclosure_component",
+       .owner                  = THIS_MODULE,
+       .class_dev_attrs        = enclosure_component_attrs,
+       .release                = enclosure_component_release,
+};
+
+static int __init enclosure_init(void)
+{
+       int err;
+
+       err = class_register(&enclosure_class);
+       if (err)
+               return err;
+       err = class_register(&enclosure_component_class);
+       if (err)
+               goto err_out;
+
+       return 0;
+ err_out:
+       class_unregister(&enclosure_class);
+
+       return err;
+}
+
+static void __exit enclosure_exit(void)
+{
+       class_unregister(&enclosure_component_class);
+       class_unregister(&enclosure_class);
+}
+
+module_init(enclosure_init);
+module_exit(enclosure_exit);
+
+MODULE_AUTHOR("James Bottomley");
+MODULE_DESCRIPTION("Enclosure Services");
+MODULE_LICENSE("GPL v2");
index 9cc25fd80b605c742411b3042c27808976199453..50c2b60e1fee42e43661f1b9b544a7662053a593 100644 (file)
@@ -879,7 +879,8 @@ config SMC91X
        tristate "SMC 91C9x/91C1xxx support"
        select CRC32
        select MII
-       depends on ARM || REDWOOD_5 || REDWOOD_6 || M32R || SUPERH || SOC_AU1X00 || BLACKFIN
+       depends on ARM || REDWOOD_5 || REDWOOD_6 || M32R || SUPERH || \
+               SOC_AU1X00 || BLACKFIN || MN10300
        help
          This is a driver for SMC's 91x series of Ethernet chipsets,
          including the SMC91C94 and the SMC91C111. Say Y if you want it
index 271c28dc9baae1057681ce326ea4bc81e50e8756..51d4134b37b196307bf98480fd786e64d983e897 100644 (file)
@@ -450,8 +450,20 @@ static inline void LPD7_SMC_outsw (unsigned char* a, int r,
 #define SMC_outsl(a, r, p, l)  writesl((a) + (r), p, l)
 #define SMC_IRQ_FLAGS          (-1)    /* from resource */
 
+#elif defined(CONFIG_MN10300)
+
+/*
+ * MN10300/AM33 configuration
+ */
+
+#include <asm/unit/smc91111.h>
+
 #else
 
+/*
+ * Default configuration
+ */
+
 #define SMC_CAN_USE_8BIT       1
 #define SMC_CAN_USE_16BIT      1
 #define SMC_CAN_USE_32BIT      1
index d449b150930ea7aedeb0b8ad0cb43a1140575391..b7bcdcc5c724e0f441faa4bbb94cb53d06a2e448 100644 (file)
@@ -35,7 +35,8 @@ if PARPORT
 
 config PARPORT_PC
        tristate "PC-style hardware"
-       depends on (!SPARC64 || PCI) && !SPARC32 && !M32R && !FRV && (!M68K || ISA)
+       depends on (!SPARC64 || PCI) && !SPARC32 && !M32R && !FRV && \
+               (!M68K || ISA) && !MN10300
        ---help---
          You should say Y here if you have a PC-style parallel port. All
          IBM PC compatible computers and some Alphas have PC-style
index 525312f2fe9c4658e1116990d095325e9dfdc5e3..2e21af43d91ea26bcdfbe7ec3cc8354be086749c 100644 (file)
@@ -888,7 +888,7 @@ size_t parport_ieee1284_epp_read_addr (struct parport *port,
 
                /* Event 59: set nSelectIn (nAStrb) high */
                parport_frob_control (port, PARPORT_CONTROL_SELECT,
-                                     PARPORT_CONTROL_SELECT);
+                                     0);
 
                /* Event 60: wait for Busy to go low */
                if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, 
index 9f04d17576d6fb37e1f58368dfa5326264369208..4d1ce2e7361e41cfee2b35b5da3025f7641e2e4b 100644 (file)
@@ -38,6 +38,7 @@ obj-$(CONFIG_PPC32) += setup-irq.o
 obj-$(CONFIG_PPC) += setup-bus.o
 obj-$(CONFIG_MIPS) += setup-bus.o setup-irq.o
 obj-$(CONFIG_X86_VISWS) += setup-irq.o
+obj-$(CONFIG_MN10300) += setup-bus.o
 
 #
 # ACPI Related PCI FW Functions
index 31fa6c92aa5ef04142dc30b5dc9277a35f46f150..a4c3089f892a5bcf912e3e12740368f9dd09a0b9 100644 (file)
@@ -692,6 +692,23 @@ static int iommu_flush_iotlb_psi(struct intel_iommu *iommu, u16 did,
                DMA_TLB_PSI_FLUSH, non_present_entry_flush);
 }
 
+static void iommu_disable_protect_mem_regions(struct intel_iommu *iommu)
+{
+       u32 pmen;
+       unsigned long flags;
+
+       spin_lock_irqsave(&iommu->register_lock, flags);
+       pmen = readl(iommu->reg + DMAR_PMEN_REG);
+       pmen &= ~DMA_PMEN_EPM;
+       writel(pmen, iommu->reg + DMAR_PMEN_REG);
+
+       /* wait for the protected region status bit to clear */
+       IOMMU_WAIT_OP(iommu, DMAR_PMEN_REG,
+               readl, !(pmen & DMA_PMEN_PRS), pmen);
+
+       spin_unlock_irqrestore(&iommu->register_lock, flags);
+}
+
 static int iommu_enable_translation(struct intel_iommu *iommu)
 {
        u32 sts;
@@ -728,7 +745,7 @@ static int iommu_disable_translation(struct intel_iommu *iommu)
 
 /* iommu interrupt handling. Most stuff are MSI-like. */
 
-static char *fault_reason_strings[] =
+static const char *fault_reason_strings[] =
 {
        "Software",
        "Present bit in root entry is clear",
@@ -743,14 +760,13 @@ static char *fault_reason_strings[] =
        "non-zero reserved fields in RTP",
        "non-zero reserved fields in CTP",
        "non-zero reserved fields in PTE",
-       "Unknown"
 };
-#define MAX_FAULT_REASON_IDX   ARRAY_SIZE(fault_reason_strings) - 1
+#define MAX_FAULT_REASON_IDX   (ARRAY_SIZE(fault_reason_strings) - 1)
 
-char *dmar_get_fault_reason(u8 fault_reason)
+const char *dmar_get_fault_reason(u8 fault_reason)
 {
-       if (fault_reason >= MAX_FAULT_REASON_IDX)
-               return fault_reason_strings[MAX_FAULT_REASON_IDX - 1];
+       if (fault_reason > MAX_FAULT_REASON_IDX)
+               return "Unknown";
        else
                return fault_reason_strings[fault_reason];
 }
@@ -808,7 +824,7 @@ void dmar_msi_read(int irq, struct msi_msg *msg)
 static int iommu_page_fault_do_one(struct intel_iommu *iommu, int type,
                u8 fault_reason, u16 source_id, u64 addr)
 {
-       char *reason;
+       const char *reason;
 
        reason = dmar_get_fault_reason(fault_reason);
 
@@ -1730,6 +1746,8 @@ int __init init_dmars(void)
                iommu_flush_context_global(iommu, 0);
                iommu_flush_iotlb_global(iommu, 0);
 
+               iommu_disable_protect_mem_regions(iommu);
+
                ret = iommu_enable_translation(iommu);
                if (ret)
                        goto error;
index 0e4862675ad23450787577713e31331c078fa826..07f5f6353bda9780e703bb77a99927b1625d0294 100644 (file)
@@ -140,6 +140,10 @@ static inline void dmar_writeq(void __iomem *addr, u64 val)
 #define DMA_TLB_IH_NONLEAF (((u64)1) << 6)
 #define DMA_TLB_MAX_SIZE (0x3f)
 
+/* PMEN_REG */
+#define DMA_PMEN_EPM (((u32)1)<<31)
+#define DMA_PMEN_PRS (((u32)1)<<0)
+
 /* GCMD_REG */
 #define DMA_GCMD_TE (((u32)1) << 31)
 #define DMA_GCMD_SRTP (((u32)1) << 30)
index 14fc7f39e83e0be1ad26267daad4853544775223..a5f0aaaf0dd443863b6d0752e580cc6c5ffad515 100644 (file)
@@ -179,7 +179,15 @@ config CHR_DEV_SCH
          say M here and read <file:Documentation/kbuild/modules.txt> and
          <file:Documentation/scsi/scsi.txt>. The module will be called ch.o.
          If unsure, say N.
-       
+
+config SCSI_ENCLOSURE
+       tristate "SCSI Enclosure Support"
+       depends on SCSI && ENCLOSURE_SERVICES
+       help
+         Enclosures are devices sitting on or in SCSI backplanes that
+         manage devices.  If you have a disk cage, the chances are that
+         it has an enclosure device.  Selecting this option will just allow
+         certain enclosure conditions to be reported and is not required.
 
 comment "Some SCSI devices (e.g. CD jukebox) support multiple LUNs"
        depends on SCSI
@@ -350,17 +358,6 @@ config SGIWD93_SCSI
          If you have a Western Digital WD93 SCSI controller on
          an SGI MIPS system, say Y.  Otherwise, say N.
 
-config SCSI_DECNCR
-       tristate "DEC NCR53C94 Scsi Driver"
-       depends on MACH_DECSTATION && SCSI && TC
-       help
-         Say Y here to support the NCR53C94 SCSI controller chips on IOASIC
-         based TURBOchannel DECstations and TURBOchannel PMAZ-A cards.
-
-config SCSI_DECSII
-       tristate "DEC SII Scsi Driver"
-       depends on MACH_DECSTATION && SCSI && 32BIT
-
 config BLK_DEV_3W_XXXX_RAID
        tristate "3ware 5/6/7/8xxx ATA-RAID support"
        depends on PCI && SCSI
@@ -1263,17 +1260,6 @@ config SCSI_NCR53C8XX_NO_DISCONNECT
          not allow targets to disconnect is not reasonable if there is more
          than 1 device on a SCSI bus. The normal answer therefore is N.
 
-config SCSI_MCA_53C9X
-       tristate "NCR MCA 53C9x SCSI support"
-       depends on MCA_LEGACY && SCSI && BROKEN_ON_SMP
-       help
-         Some MicroChannel machines, notably the NCR 35xx line, use a SCSI
-         controller based on the NCR 53C94.  This driver will allow use of
-         the controller on the 3550, and very possibly others.
-
-         To compile this driver as a module, choose M here: the
-         module will be called mca_53c9x.
-
 config SCSI_PAS16
        tristate "PAS16 SCSI support"
        depends on ISA && SCSI
@@ -1600,45 +1586,6 @@ config GVP11_SCSI
          To compile this driver as a module, choose M here: the
          module will be called gvp11.
 
-config CYBERSTORM_SCSI
-       tristate "CyberStorm SCSI support"
-       depends on ZORRO && SCSI
-       help
-         If you have an Amiga with an original (MkI) Phase5 Cyberstorm
-         accelerator board and the optional Cyberstorm SCSI controller,
-         answer Y. Otherwise, say N.
-
-config CYBERSTORMII_SCSI
-       tristate "CyberStorm Mk II SCSI support"
-       depends on ZORRO && SCSI
-       help
-         If you have an Amiga with a Phase5 Cyberstorm MkII accelerator board
-         and the optional Cyberstorm SCSI controller, say Y. Otherwise,
-         answer N.
-
-config BLZ2060_SCSI
-       tristate "Blizzard 2060 SCSI support"
-       depends on ZORRO && SCSI
-       help
-         If you have an Amiga with a Phase5 Blizzard 2060 accelerator board
-         and want to use the onboard SCSI controller, say Y. Otherwise,
-         answer N.
-
-config BLZ1230_SCSI
-       tristate "Blizzard 1230IV/1260 SCSI support"
-       depends on ZORRO && SCSI
-       help
-         If you have an Amiga 1200 with a Phase5 Blizzard 1230IV or Blizzard
-         1260 accelerator, and the optional SCSI module, say Y. Otherwise,
-         say N.
-
-config FASTLANE_SCSI
-       tristate "Fastlane SCSI support"
-       depends on ZORRO && SCSI
-       help
-         If you have the Phase5 Fastlane Z3 SCSI controller, or plan to use
-         one in the near future, say Y to this question. Otherwise, say N.
-
 config SCSI_A4000T
        tristate "A4000T NCR53c710 SCSI support (EXPERIMENTAL)"
        depends on AMIGA && SCSI && EXPERIMENTAL
@@ -1666,15 +1613,6 @@ config SCSI_ZORRO7XX
              accelerator card for the Amiga 1200,
            - the SCSI controller on the GVP Turbo 040/060 accelerator.
 
-config OKTAGON_SCSI
-       tristate "BSC Oktagon SCSI support (EXPERIMENTAL)"
-       depends on ZORRO && SCSI && EXPERIMENTAL
-       help
-         If you have the BSC Oktagon SCSI disk controller for the Amiga, say
-         Y to this question.  If you're in doubt about whether you have one,
-         see the picture at
-         <http://amiga.resource.cx/exp/search.pl?product=oktagon>.
-
 config ATARI_SCSI
        tristate "Atari native SCSI support"
        depends on ATARI && SCSI
@@ -1727,18 +1665,6 @@ config MAC_SCSI
          SCSI-HOWTO, available from
          <http://www.tldp.org/docs.html#howto>.
 
-config SCSI_MAC_ESP
-       tristate "Macintosh NCR53c9[46] SCSI"
-       depends on MAC && SCSI
-       help
-         This is the NCR 53c9x SCSI controller found on most of the 68040
-         based Macintoshes.  If you have one of these say Y and read the
-         SCSI-HOWTO, available from
-         <http://www.tldp.org/docs.html#howto>.
-
-         To compile this driver as a module, choose M here: the
-         module will be called mac_esp.
-
 config MVME147_SCSI
        bool "WD33C93 SCSI driver for MVME147"
        depends on MVME147 && SCSI=y
@@ -1779,6 +1705,7 @@ config SUN3_SCSI
 config SUN3X_ESP
        bool "Sun3x ESP SCSI"
        depends on SUN3X && SCSI=y
+       select SCSI_SPI_ATTRS
        help
          The ESP was an on-board SCSI controller used on Sun 3/80
          machines.  Say Y here to compile in support for it.
index 93e1428d03fc54efc5adb9ca7231adfb037a03fb..925c26b4fff910069810c17d86cac850e3f16a2b 100644 (file)
@@ -44,15 +44,8 @@ obj-$(CONFIG_A2091_SCSI)     += a2091.o      wd33c93.o
 obj-$(CONFIG_GVP11_SCSI)       += gvp11.o      wd33c93.o
 obj-$(CONFIG_MVME147_SCSI)     += mvme147.o    wd33c93.o
 obj-$(CONFIG_SGIWD93_SCSI)     += sgiwd93.o    wd33c93.o
-obj-$(CONFIG_CYBERSTORM_SCSI)  += NCR53C9x.o   cyberstorm.o
-obj-$(CONFIG_CYBERSTORMII_SCSI)        += NCR53C9x.o   cyberstormII.o
-obj-$(CONFIG_BLZ2060_SCSI)     += NCR53C9x.o   blz2060.o
-obj-$(CONFIG_BLZ1230_SCSI)     += NCR53C9x.o   blz1230.o
-obj-$(CONFIG_FASTLANE_SCSI)    += NCR53C9x.o   fastlane.o
-obj-$(CONFIG_OKTAGON_SCSI)     += NCR53C9x.o   oktagon_esp_mod.o
 obj-$(CONFIG_ATARI_SCSI)       += atari_scsi.o
 obj-$(CONFIG_MAC_SCSI)         += mac_scsi.o
-obj-$(CONFIG_SCSI_MAC_ESP)     += mac_esp.o    NCR53C9x.o
 obj-$(CONFIG_SUN3_SCSI)                += sun3_scsi.o  sun3_scsi_vme.o
 obj-$(CONFIG_MVME16x_SCSI)     += 53c700.o     mvme16x_scsi.o
 obj-$(CONFIG_BVME6000_SCSI)    += 53c700.o     bvme6000_scsi.o
@@ -95,7 +88,6 @@ obj-$(CONFIG_SCSI_SYM53C8XX_2)        += sym53c8xx_2/
 obj-$(CONFIG_SCSI_ZALON)       += zalon7xx.o
 obj-$(CONFIG_SCSI_EATA_PIO)    += eata_pio.o
 obj-$(CONFIG_SCSI_7000FASST)   += wd7000.o
-obj-$(CONFIG_SCSI_MCA_53C9X)   += NCR53C9x.o   mca_53c9x.o
 obj-$(CONFIG_SCSI_IBMMCA)      += ibmmca.o
 obj-$(CONFIG_SCSI_EATA)                += eata.o
 obj-$(CONFIG_SCSI_DC395x)      += dc395x.o
@@ -112,13 +104,12 @@ obj-$(CONFIG_SCSI_QLOGICPTI)      += qlogicpti.o
 obj-$(CONFIG_BLK_DEV_IDESCSI)  += ide-scsi.o
 obj-$(CONFIG_SCSI_MESH)                += mesh.o
 obj-$(CONFIG_SCSI_MAC53C94)    += mac53c94.o
-obj-$(CONFIG_SCSI_DECNCR)      += NCR53C9x.o   dec_esp.o
 obj-$(CONFIG_BLK_DEV_3W_XXXX_RAID) += 3w-xxxx.o
 obj-$(CONFIG_SCSI_3W_9XXX)     += 3w-9xxx.o
 obj-$(CONFIG_SCSI_PPA)         += ppa.o
 obj-$(CONFIG_SCSI_IMM)         += imm.o
 obj-$(CONFIG_JAZZ_ESP)         += esp_scsi.o   jazz_esp.o
-obj-$(CONFIG_SUN3X_ESP)                += NCR53C9x.o   sun3x_esp.o
+obj-$(CONFIG_SUN3X_ESP)                += esp_scsi.o   sun3x_esp.o
 obj-$(CONFIG_SCSI_LASI700)     += 53c700.o lasi700.o
 obj-$(CONFIG_SCSI_SNI_53C710)  += 53c700.o sni_53c710.o
 obj-$(CONFIG_SCSI_NSP32)       += nsp32.o
@@ -138,6 +129,7 @@ obj-$(CONFIG_BLK_DEV_SD)    += sd_mod.o
 obj-$(CONFIG_BLK_DEV_SR)       += sr_mod.o
 obj-$(CONFIG_CHR_DEV_SG)       += sg.o
 obj-$(CONFIG_CHR_DEV_SCH)      += ch.o
+obj-$(CONFIG_SCSI_ENCLOSURE)   += ses.o
 
 # This goes last, so that "real" scsi devices probe earlier
 obj-$(CONFIG_SCSI_DEBUG)       += scsi_debug.o
diff --git a/drivers/scsi/NCR53C9x.c b/drivers/scsi/NCR53C9x.c
deleted file mode 100644 (file)
index 5b0efc9..0000000
+++ /dev/null
@@ -1,3654 +0,0 @@
-/* NCR53C9x.c:  Generic SCSI driver code for NCR53C9x chips.
- *
- * Originally esp.c : EnhancedScsiProcessor Sun SCSI driver code.
- *
- * Copyright (C) 1995, 1998 David S. Miller (davem@caip.rutgers.edu)
- *
- * Most DMA dependencies put in driver specific files by 
- * Jesper Skov (jskov@cygnus.co.uk)
- *
- * Set up to use esp_read/esp_write (preprocessor macros in NCR53c9x.h) by
- * Tymm Twillman (tymm@coe.missouri.edu)
- */
-
-/* TODO:
- *
- * 1) Maybe disable parity checking in config register one for SCSI1
- *    targets.  (Gilmore says parity error on the SBus can lock up
- *    old sun4c's)
- * 2) Add support for DMA2 pipelining.
- * 3) Add tagged queueing.
- * 4) Maybe change use of "esp" to something more "NCR"'ish.
- */
-
-#include <linux/module.h>
-
-#include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/types.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <linux/blkdev.h>
-#include <linux/interrupt.h>
-#include <linux/proc_fs.h>
-#include <linux/stat.h>
-#include <linux/init.h>
-
-#include "scsi.h"
-#include <scsi/scsi_host.h>
-#include "NCR53C9x.h"
-
-#include <asm/system.h>
-#include <asm/ptrace.h>
-#include <asm/pgtable.h>
-#include <asm/io.h>
-#include <asm/irq.h>
-
-/* Command phase enumeration. */
-enum {
-       not_issued    = 0x00,  /* Still in the issue_SC queue.          */
-
-       /* Various forms of selecting a target. */
-#define in_slct_mask    0x10
-       in_slct_norm  = 0x10,  /* ESP is arbitrating, normal selection  */
-       in_slct_stop  = 0x11,  /* ESP will select, then stop with IRQ   */
-       in_slct_msg   = 0x12,  /* select, then send a message           */
-       in_slct_tag   = 0x13,  /* select and send tagged queue msg      */
-       in_slct_sneg  = 0x14,  /* select and acquire sync capabilities  */
-
-       /* Any post selection activity. */
-#define in_phases_mask  0x20
-       in_datain     = 0x20,  /* Data is transferring from the bus     */
-       in_dataout    = 0x21,  /* Data is transferring to the bus       */
-       in_data_done  = 0x22,  /* Last DMA data operation done (maybe)  */
-       in_msgin      = 0x23,  /* Eating message from target            */
-       in_msgincont  = 0x24,  /* Eating more msg bytes from target     */
-       in_msgindone  = 0x25,  /* Decide what to do with what we got    */
-       in_msgout     = 0x26,  /* Sending message to target             */
-       in_msgoutdone = 0x27,  /* Done sending msg out                  */
-       in_cmdbegin   = 0x28,  /* Sending cmd after abnormal selection  */
-       in_cmdend     = 0x29,  /* Done sending slow cmd                 */
-       in_status     = 0x2a,  /* Was in status phase, finishing cmd    */
-       in_freeing    = 0x2b,  /* freeing the bus for cmd cmplt or disc */
-       in_the_dark   = 0x2c,  /* Don't know what bus phase we are in   */
-
-       /* Special states, ie. not normal bus transitions... */
-#define in_spec_mask    0x80
-       in_abortone   = 0x80,  /* Aborting one command currently        */
-       in_abortall   = 0x81,  /* Blowing away all commands we have     */
-       in_resetdev   = 0x82,  /* SCSI target reset in progress         */
-       in_resetbus   = 0x83,  /* SCSI bus reset in progress            */
-       in_tgterror   = 0x84,  /* Target did something stupid           */
-};
-
-enum {
-       /* Zero has special meaning, see skipahead[12]. */
-/*0*/  do_never,
-
-/*1*/  do_phase_determine,
-/*2*/  do_reset_bus,
-/*3*/  do_reset_complete,
-/*4*/  do_work_bus,
-/*5*/  do_intr_end
-};
-
-/* The master ring of all esp hosts we are managing in this driver. */
-static struct NCR_ESP *espchain;
-int nesps = 0, esps_in_use = 0, esps_running = 0;
-EXPORT_SYMBOL(nesps);
-EXPORT_SYMBOL(esps_running);
-
-irqreturn_t esp_intr(int irq, void *dev_id);
-
-/* Debugging routines */
-static struct esp_cmdstrings {
-       unchar cmdchar;
-       char *text;
-} esp_cmd_strings[] = {
-       /* Miscellaneous */
-       { ESP_CMD_NULL, "ESP_NOP", },
-       { ESP_CMD_FLUSH, "FIFO_FLUSH", },
-       { ESP_CMD_RC, "RSTESP", },
-       { ESP_CMD_RS, "RSTSCSI", },
-       /* Disconnected State Group */
-       { ESP_CMD_RSEL, "RESLCTSEQ", },
-       { ESP_CMD_SEL, "SLCTNATN", },
-       { ESP_CMD_SELA, "SLCTATN", },
-       { ESP_CMD_SELAS, "SLCTATNSTOP", },
-       { ESP_CMD_ESEL, "ENSLCTRESEL", },
-       { ESP_CMD_DSEL, "DISSELRESEL", },
-       { ESP_CMD_SA3, "SLCTATN3", },
-       { ESP_CMD_RSEL3, "RESLCTSEQ", },
-       /* Target State Group */
-       { ESP_CMD_SMSG, "SNDMSG", },
-       { ESP_CMD_SSTAT, "SNDSTATUS", },
-       { ESP_CMD_SDATA, "SNDDATA", },
-       { ESP_CMD_DSEQ, "DISCSEQ", },
-       { ESP_CMD_TSEQ, "TERMSEQ", },
-       { ESP_CMD_TCCSEQ, "TRGTCMDCOMPSEQ", },
-       { ESP_CMD_DCNCT, "DISC", },
-       { ESP_CMD_RMSG, "RCVMSG", },
-       { ESP_CMD_RCMD, "RCVCMD", },
-       { ESP_CMD_RDATA, "RCVDATA", },
-       { ESP_CMD_RCSEQ, "RCVCMDSEQ", },
-       /* Initiator State Group */
-       { ESP_CMD_TI, "TRANSINFO", },
-       { ESP_CMD_ICCSEQ, "INICMDSEQCOMP", },
-       { ESP_CMD_MOK, "MSGACCEPTED", },
-       { ESP_CMD_TPAD, "TPAD", },
-       { ESP_CMD_SATN, "SATN", },
-       { ESP_CMD_RATN, "RATN", },
-};
-#define NUM_ESP_COMMANDS  ((sizeof(esp_cmd_strings)) / (sizeof(struct esp_cmdstrings)))
-
-/* Print textual representation of an ESP command */
-static inline void esp_print_cmd(unchar espcmd)
-{
-       unchar dma_bit = espcmd & ESP_CMD_DMA;
-       int i;
-
-       espcmd &= ~dma_bit;
-       for(i=0; i<NUM_ESP_COMMANDS; i++)
-               if(esp_cmd_strings[i].cmdchar == espcmd)
-                       break;
-       if(i==NUM_ESP_COMMANDS)
-               printk("ESP_Unknown");
-       else
-               printk("%s%s", esp_cmd_strings[i].text,
-                      ((dma_bit) ? "+DMA" : ""));
-}
-
-/* Print the status register's value */
-static inline void esp_print_statreg(unchar statreg)
-{
-       unchar phase;
-
-       printk("STATUS<");
-       phase = statreg & ESP_STAT_PMASK;
-       printk("%s,", (phase == ESP_DOP ? "DATA-OUT" :
-                      (phase == ESP_DIP ? "DATA-IN" :
-                       (phase == ESP_CMDP ? "COMMAND" :
-                        (phase == ESP_STATP ? "STATUS" :
-                         (phase == ESP_MOP ? "MSG-OUT" :
-                          (phase == ESP_MIP ? "MSG_IN" :
-                           "unknown")))))));
-       if(statreg & ESP_STAT_TDONE)
-               printk("TRANS_DONE,");
-       if(statreg & ESP_STAT_TCNT)
-               printk("TCOUNT_ZERO,");
-       if(statreg & ESP_STAT_PERR)
-               printk("P_ERROR,");
-       if(statreg & ESP_STAT_SPAM)
-               printk("SPAM,");
-       if(statreg & ESP_STAT_INTR)
-               printk("IRQ,");
-       printk(">");
-}
-
-/* Print the interrupt register's value */
-static inline void esp_print_ireg(unchar intreg)
-{
-       printk("INTREG< ");
-       if(intreg & ESP_INTR_S)
-               printk("SLCT_NATN ");
-       if(intreg & ESP_INTR_SATN)
-               printk("SLCT_ATN ");
-       if(intreg & ESP_INTR_RSEL)
-               printk("RSLCT ");
-       if(intreg & ESP_INTR_FDONE)
-               printk("FDONE ");
-       if(intreg & ESP_INTR_BSERV)
-               printk("BSERV ");
-       if(intreg & ESP_INTR_DC)
-               printk("DISCNCT ");
-       if(intreg & ESP_INTR_IC)
-               printk("ILL_CMD ");
-       if(intreg & ESP_INTR_SR)
-               printk("SCSI_BUS_RESET ");
-       printk(">");
-}
-
-/* Print the sequence step registers contents */
-static inline void esp_print_seqreg(unchar stepreg)
-{
-       stepreg &= ESP_STEP_VBITS;
-       printk("STEP<%s>",
-              (stepreg == ESP_STEP_ASEL ? "SLCT_ARB_CMPLT" :
-               (stepreg == ESP_STEP_SID ? "1BYTE_MSG_SENT" :
-                (stepreg == ESP_STEP_NCMD ? "NOT_IN_CMD_PHASE" :
-                 (stepreg == ESP_STEP_PPC ? "CMD_BYTES_LOST" :
-                  (stepreg == ESP_STEP_FINI4 ? "CMD_SENT_OK" :
-                   "UNKNOWN"))))));
-}
-
-static char *phase_string(int phase)
-{
-       switch(phase) {
-       case not_issued:
-               return "UNISSUED";
-       case in_slct_norm:
-               return "SLCTNORM";
-       case in_slct_stop:
-               return "SLCTSTOP";
-       case in_slct_msg:
-               return "SLCTMSG";
-       case in_slct_tag:
-               return "SLCTTAG";
-       case in_slct_sneg:
-               return "SLCTSNEG";
-       case in_datain:
-               return "DATAIN";
-       case in_dataout:
-               return "DATAOUT";
-       case in_data_done:
-               return "DATADONE";
-       case in_msgin:
-               return "MSGIN";
-       case in_msgincont:
-               return "MSGINCONT";
-       case in_msgindone:
-               return "MSGINDONE";
-       case in_msgout:
-               return "MSGOUT";
-       case in_msgoutdone:
-               return "MSGOUTDONE";
-       case in_cmdbegin:
-               return "CMDBEGIN";
-       case in_cmdend:
-               return "CMDEND";
-       case in_status:
-               return "STATUS";
-       case in_freeing:
-               return "FREEING";
-       case in_the_dark:
-               return "CLUELESS";
-       case in_abortone:
-               return "ABORTONE";
-       case in_abortall:
-               return "ABORTALL";
-       case in_resetdev:
-               return "RESETDEV";
-       case in_resetbus:
-               return "RESETBUS";
-       case in_tgterror:
-               return "TGTERROR";
-       default:
-               return "UNKNOWN";
-       };
-}
-
-#ifdef DEBUG_STATE_MACHINE
-static inline void esp_advance_phase(Scsi_Cmnd *s, int newphase)
-{
-       ESPLOG(("<%s>", phase_string(newphase)));
-       s->SCp.sent_command = s->SCp.phase;
-       s->SCp.phase = newphase;
-}
-#else
-#define esp_advance_phase(__s, __newphase) \
-       (__s)->SCp.sent_command = (__s)->SCp.phase; \
-       (__s)->SCp.phase = (__newphase);
-#endif
-
-#ifdef DEBUG_ESP_CMDS
-static inline void esp_cmd(struct NCR_ESP *esp, struct ESP_regs *eregs,
-                          unchar cmd)
-{
-       esp->espcmdlog[esp->espcmdent] = cmd;
-       esp->espcmdent = (esp->espcmdent + 1) & 31;
-       esp_write(eregs->esp_cmnd, cmd);
-}
-#else
-#define esp_cmd(__esp, __eregs, __cmd) esp_write((__eregs)->esp_cmnd, (__cmd))
-#endif
-
-/* How we use the various Linux SCSI data structures for operation.
- *
- * struct scsi_cmnd:
- *
- *   We keep track of the syncronous capabilities of a target
- *   in the device member, using sync_min_period and
- *   sync_max_offset.  These are the values we directly write
- *   into the ESP registers while running a command.  If offset
- *   is zero the ESP will use asynchronous transfers.
- *   If the borken flag is set we assume we shouldn't even bother
- *   trying to negotiate for synchronous transfer as this target
- *   is really stupid.  If we notice the target is dropping the
- *   bus, and we have been allowing it to disconnect, we clear
- *   the disconnect flag.
- */
-
-/* Manipulation of the ESP command queues.  Thanks to the aha152x driver
- * and its author, Juergen E. Fischer, for the methods used here.
- * Note that these are per-ESP queues, not global queues like
- * the aha152x driver uses.
- */
-static inline void append_SC(Scsi_Cmnd **SC, Scsi_Cmnd *new_SC)
-{
-       Scsi_Cmnd *end;
-
-       new_SC->host_scribble = (unsigned char *) NULL;
-       if(!*SC)
-               *SC = new_SC;
-       else {
-               for(end=*SC;end->host_scribble;end=(Scsi_Cmnd *)end->host_scribble)
-                       ;
-               end->host_scribble = (unsigned char *) new_SC;
-       }
-}
-
-static inline void prepend_SC(Scsi_Cmnd **SC, Scsi_Cmnd *new_SC)
-{
-       new_SC->host_scribble = (unsigned char *) *SC;
-       *SC = new_SC;
-}
-
-static inline Scsi_Cmnd *remove_first_SC(Scsi_Cmnd **SC)
-{
-       Scsi_Cmnd *ptr;
-
-       ptr = *SC;
-       if(ptr)
-               *SC = (Scsi_Cmnd *) (*SC)->host_scribble;
-       return ptr;
-}
-
-static inline Scsi_Cmnd *remove_SC(Scsi_Cmnd **SC, int target, int lun)
-{
-       Scsi_Cmnd *ptr, *prev;
-
-       for(ptr = *SC, prev = NULL;
-           ptr && ((ptr->device->id != target) || (ptr->device->lun != lun));
-           prev = ptr, ptr = (Scsi_Cmnd *) ptr->host_scribble)
-               ;
-       if(ptr) {
-               if(prev)
-                       prev->host_scribble=ptr->host_scribble;
-               else
-                       *SC=(Scsi_Cmnd *)ptr->host_scribble;
-       }
-       return ptr;
-}
-
-/* Resetting various pieces of the ESP scsi driver chipset */
-
-/* Reset the ESP chip, _not_ the SCSI bus. */
-static void esp_reset_esp(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       int family_code, version, i;
-       volatile int trash;
-
-       /* Now reset the ESP chip */
-       esp_cmd(esp, eregs, ESP_CMD_RC);
-       esp_cmd(esp, eregs, ESP_CMD_NULL | ESP_CMD_DMA);
-       if(esp->erev == fast)
-               esp_write(eregs->esp_cfg2, ESP_CONFIG2_FENAB);
-       esp_cmd(esp, eregs, ESP_CMD_NULL | ESP_CMD_DMA);
-
-       /* This is the only point at which it is reliable to read
-        * the ID-code for a fast ESP chip variant.
-        */
-       esp->max_period = ((35 * esp->ccycle) / 1000);
-       if(esp->erev == fast) {
-               char *erev2string[] = {
-                       "Emulex FAS236",
-                       "Emulex FPESP100A",
-                       "fast",
-                       "QLogic FAS366",
-                       "Emulex FAS216",
-                       "Symbios Logic 53CF9x-2",
-                       "unknown!"
-               };
-                       
-               version = esp_read(eregs->esp_uid);
-               family_code = (version & 0xf8) >> 3;
-               if(family_code == 0x02) {
-                       if ((version & 7) == 2)
-                               esp->erev = fas216;     
-                        else
-                               esp->erev = fas236;
-               } else if(family_code == 0x0a)
-                       esp->erev = fas366; /* Version is usually '5'. */
-               else if(family_code == 0x00) {
-                       if ((version & 7) == 2)
-                               esp->erev = fas100a; /* NCR53C9X */
-                       else
-                               esp->erev = espunknown;
-               } else if(family_code == 0x14) {
-                       if ((version & 7) == 2)
-                               esp->erev = fsc;
-                       else
-                               esp->erev = espunknown;
-               } else if(family_code == 0x00) {
-                       if ((version & 7) == 2)
-                               esp->erev = fas100a; /* NCR53C9X */
-                       else
-                               esp->erev = espunknown;
-               } else
-                       esp->erev = espunknown;
-               ESPLOG(("esp%d: FAST chip is %s (family=%d, version=%d)\n",
-                       esp->esp_id, erev2string[esp->erev - fas236],
-                       family_code, (version & 7)));
-
-               esp->min_period = ((4 * esp->ccycle) / 1000);
-       } else {
-               esp->min_period = ((5 * esp->ccycle) / 1000);
-       }
-
-       /* Reload the configuration registers */
-       esp_write(eregs->esp_cfact, esp->cfact);
-       esp->prev_stp = 0;
-       esp_write(eregs->esp_stp, 0);
-       esp->prev_soff = 0;
-       esp_write(eregs->esp_soff, 0);
-       esp_write(eregs->esp_timeo, esp->neg_defp);
-       esp->max_period = (esp->max_period + 3)>>2;
-       esp->min_period = (esp->min_period + 3)>>2;
-
-       esp_write(eregs->esp_cfg1, esp->config1);
-       switch(esp->erev) {
-       case esp100:
-               /* nothing to do */
-               break;
-       case esp100a:
-               esp_write(eregs->esp_cfg2, esp->config2);
-               break;
-       case esp236:
-               /* Slow 236 */
-               esp_write(eregs->esp_cfg2, esp->config2);
-               esp->prev_cfg3 = esp->config3[0];
-               esp_write(eregs->esp_cfg3, esp->prev_cfg3);
-               break;
-       case fas366:
-               panic("esp: FAS366 support not present, please notify "
-                     "jongk@cs.utwente.nl");
-               break;
-       case fas216:
-       case fas236:
-       case fsc:
-               /* Fast ESP variants */
-               esp_write(eregs->esp_cfg2, esp->config2);
-               for(i=0; i<8; i++)
-                       esp->config3[i] |= ESP_CONFIG3_FCLK;
-               esp->prev_cfg3 = esp->config3[0];
-               esp_write(eregs->esp_cfg3, esp->prev_cfg3);
-               if(esp->diff)
-                       esp->radelay = 0;
-               else
-                       esp->radelay = 16;
-               /* Different timeout constant for these chips */
-               esp->neg_defp =
-                       FSC_NEG_DEFP(esp->cfreq,
-                                    (esp->cfact == ESP_CCF_F0 ?
-                                     ESP_CCF_F7 + 1 : esp->cfact));
-               esp_write(eregs->esp_timeo, esp->neg_defp);
-               /* Enable Active Negotiation if possible */
-               if((esp->erev == fsc) && !esp->diff)
-                       esp_write(eregs->esp_cfg4, ESP_CONFIG4_EAN);
-               break;
-       case fas100a:
-               /* Fast 100a */
-               esp_write(eregs->esp_cfg2, esp->config2);
-               for(i=0; i<8; i++)
-                       esp->config3[i] |= ESP_CONFIG3_FCLOCK;
-               esp->prev_cfg3 = esp->config3[0];
-               esp_write(eregs->esp_cfg3, esp->prev_cfg3);
-               esp->radelay = 32;
-               break;
-       default:
-               panic("esp: what could it be... I wonder...");
-               break;
-       };
-
-       /* Eat any bitrot in the chip */
-       trash = esp_read(eregs->esp_intrpt);
-       udelay(100);
-}
-
-/* This places the ESP into a known state at boot time. */
-void esp_bootup_reset(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       volatile unchar trash;
-
-       /* Reset the DMA */
-       if(esp->dma_reset)
-               esp->dma_reset(esp);
-
-       /* Reset the ESP */
-       esp_reset_esp(esp, eregs);
-
-       /* Reset the SCSI bus, but tell ESP not to generate an irq */
-       esp_write(eregs->esp_cfg1, (esp_read(eregs->esp_cfg1) | ESP_CONFIG1_SRRDISAB));
-       esp_cmd(esp, eregs, ESP_CMD_RS);
-       udelay(400);
-       esp_write(eregs->esp_cfg1, esp->config1);
-
-       /* Eat any bitrot in the chip and we are done... */
-       trash = esp_read(eregs->esp_intrpt);
-}
-EXPORT_SYMBOL(esp_bootup_reset);
-
-/* Allocate structure and insert basic data such as SCSI chip frequency
- * data and a pointer to the device
- */
-struct NCR_ESP* esp_allocate(struct scsi_host_template *tpnt, void *esp_dev,
-                            int hotplug)
-{
-       struct NCR_ESP *esp, *elink;
-       struct Scsi_Host *esp_host;
-
-       if (hotplug)
-               esp_host = scsi_host_alloc(tpnt, sizeof(struct NCR_ESP));
-       else
-               esp_host = scsi_register(tpnt, sizeof(struct NCR_ESP));
-       if(!esp_host)
-               panic("Cannot register ESP SCSI host");
-       esp = (struct NCR_ESP *) esp_host->hostdata;
-       if(!esp)
-               panic("No esp in hostdata");
-       esp->ehost = esp_host;
-       esp->edev = esp_dev;
-       esp->esp_id = nesps++;
-
-       /* Set bitshift value (only used on Amiga with multiple ESPs) */
-       esp->shift = 2;
-
-       /* Put into the chain of esp chips detected */
-       if(espchain) {
-               elink = espchain;
-               while(elink->next) elink = elink->next;
-               elink->next = esp;
-       } else {
-               espchain = esp;
-       }
-       esp->next = NULL;
-
-       return esp;
-}
-
-void esp_deallocate(struct NCR_ESP *esp)
-{
-       struct NCR_ESP *elink;
-
-       if(espchain == esp) {
-               espchain = NULL;
-       } else {
-               for(elink = espchain; elink && (elink->next != esp); elink = elink->next);
-               if(elink) 
-                       elink->next = esp->next;
-       }
-       nesps--;
-}
-
-/* Complete initialization of ESP structure and device
- * Caller must have initialized appropriate parts of the ESP structure
- * between the call to esp_allocate and this function.
- */
-void esp_initialize(struct NCR_ESP *esp)
-{
-       struct ESP_regs *eregs = esp->eregs;
-       unsigned int fmhz;
-       unchar ccf;
-       int i;
-       
-       /* Check out the clock properties of the chip. */
-
-       /* This is getting messy but it has to be done
-        * correctly or else you get weird behavior all
-        * over the place.  We are trying to basically
-        * figure out three pieces of information.
-        *
-        * a) Clock Conversion Factor
-        *
-        *    This is a representation of the input
-        *    crystal clock frequency going into the
-        *    ESP on this machine.  Any operation whose
-        *    timing is longer than 400ns depends on this
-        *    value being correct.  For example, you'll
-        *    get blips for arbitration/selection during
-        *    high load or with multiple targets if this
-        *    is not set correctly.
-        *
-        * b) Selection Time-Out
-        *
-        *    The ESP isn't very bright and will arbitrate
-        *    for the bus and try to select a target
-        *    forever if you let it.  This value tells
-        *    the ESP when it has taken too long to
-        *    negotiate and that it should interrupt
-        *    the CPU so we can see what happened.
-        *    The value is computed as follows (from
-        *    NCR/Symbios chip docs).
-        *
-        *          (Time Out Period) *  (Input Clock)
-        *    STO = ----------------------------------
-        *          (8192) * (Clock Conversion Factor)
-        *
-        *    You usually want the time out period to be
-        *    around 250ms, I think we'll set it a little
-        *    bit higher to account for fully loaded SCSI
-        *    bus's and slow devices that don't respond so
-        *    quickly to selection attempts. (yeah, I know
-        *    this is out of spec. but there is a lot of
-        *    buggy pieces of firmware out there so bite me)
-        *
-        * c) Imperical constants for synchronous offset
-        *    and transfer period register values
-        *
-        *    This entails the smallest and largest sync
-        *    period we could ever handle on this ESP.
-        */
-       
-       fmhz = esp->cfreq;
-
-       if(fmhz <= (5000000))
-               ccf = 0;
-       else
-               ccf = (((5000000 - 1) + (fmhz))/(5000000));
-       if(!ccf || ccf > 8) {
-               /* If we can't find anything reasonable,
-                * just assume 20MHZ.  This is the clock
-                * frequency of the older sun4c's where I've
-                * been unable to find the clock-frequency
-                * PROM property.  All other machines provide
-                * useful values it seems.
-                */
-               ccf = ESP_CCF_F4;
-               fmhz = (20000000);
-       }
-       if(ccf==(ESP_CCF_F7+1))
-               esp->cfact = ESP_CCF_F0;
-       else if(ccf == ESP_CCF_NEVER)
-               esp->cfact = ESP_CCF_F2;
-       else
-               esp->cfact = ccf;
-       esp->cfreq = fmhz;
-       esp->ccycle = ESP_MHZ_TO_CYCLE(fmhz);
-       esp->ctick = ESP_TICK(ccf, esp->ccycle);
-       esp->neg_defp = ESP_NEG_DEFP(fmhz, ccf);
-       esp->sync_defp = SYNC_DEFP_SLOW;
-
-       printk("SCSI ID %d Clk %dMHz CCF=%d TOut %d ",
-              esp->scsi_id, (esp->cfreq / 1000000),
-              ccf, (int) esp->neg_defp);
-
-       /* Fill in ehost data */
-       esp->ehost->base = (unsigned long)eregs;
-       esp->ehost->this_id = esp->scsi_id;
-       esp->ehost->irq = esp->irq;
-
-       /* SCSI id mask */
-       esp->scsi_id_mask = (1 << esp->scsi_id);
-
-       /* Probe the revision of this esp */
-       esp->config1 = (ESP_CONFIG1_PENABLE | (esp->scsi_id & 7));
-       esp->config2 = (ESP_CONFIG2_SCSI2ENAB | ESP_CONFIG2_REGPARITY);
-       esp_write(eregs->esp_cfg2, esp->config2);
-       if((esp_read(eregs->esp_cfg2) & ~(ESP_CONFIG2_MAGIC)) !=
-          (ESP_CONFIG2_SCSI2ENAB | ESP_CONFIG2_REGPARITY)) {
-               printk("NCR53C90(esp100)\n");
-               esp->erev = esp100;
-       } else {
-               esp->config2 = 0;
-               esp_write(eregs->esp_cfg2, 0);
-               esp_write(eregs->esp_cfg3, 5);
-               if(esp_read(eregs->esp_cfg3) != 5) {
-                       printk("NCR53C90A(esp100a)\n");
-                       esp->erev = esp100a;
-               } else {
-                       int target;
-
-                       for(target=0; target<8; target++)
-                               esp->config3[target] = 0;
-                       esp->prev_cfg3 = 0;
-                       esp_write(eregs->esp_cfg3, 0);
-                       if(ccf > ESP_CCF_F5) {
-                               printk("NCR53C9XF(espfast)\n");
-                               esp->erev = fast;
-                               esp->sync_defp = SYNC_DEFP_FAST;
-                       } else {
-                               printk("NCR53C9x(esp236)\n");
-                               esp->erev = esp236;
-                       }
-               }
-       }                               
-
-       /* Initialize the command queues */
-       esp->current_SC = NULL;
-       esp->disconnected_SC = NULL;
-       esp->issue_SC = NULL;
-
-       /* Clear the state machines. */
-       esp->targets_present = 0;
-       esp->resetting_bus = 0;
-       esp->snip = 0;
-
-       init_waitqueue_head(&esp->reset_queue);
-
-       esp->fas_premature_intr_workaround = 0;
-       for(i = 0; i < 32; i++)
-               esp->espcmdlog[i] = 0;
-       esp->espcmdent = 0;
-       for(i = 0; i < 16; i++) {
-               esp->cur_msgout[i] = 0;
-               esp->cur_msgin[i] = 0;
-       }
-       esp->prevmsgout = esp->prevmsgin = 0;
-       esp->msgout_len = esp->msgin_len = 0;
-
-       /* Clear the one behind caches to hold unmatchable values. */
-       esp->prev_soff = esp->prev_stp = esp->prev_cfg3 = 0xff;
-
-       /* Reset the thing before we try anything... */
-       esp_bootup_reset(esp, eregs);
-
-       esps_in_use++;
-}
-
-/* The info function will return whatever useful
- * information the developer sees fit.  If not provided, then
- * the name field will be used instead.
- */
-const char *esp_info(struct Scsi_Host *host)
-{
-       struct NCR_ESP *esp;
-
-       esp = (struct NCR_ESP *) host->hostdata;
-       switch(esp->erev) {
-       case esp100:
-               return "ESP100 (NCR53C90)";
-       case esp100a:
-               return "ESP100A (NCR53C90A)";
-       case esp236:
-               return "ESP236 (NCR53C9x)";
-       case fas216:
-               return "Emulex FAS216";
-       case fas236:
-               return "Emulex FAS236";
-       case fas366:
-               return "QLogic FAS366";
-       case fas100a:
-               return "FPESP100A";
-       case fsc:
-               return "Symbios Logic 53CF9x-2";
-       default:
-               panic("Bogon ESP revision");
-       };
-}
-EXPORT_SYMBOL(esp_info);
-
-/* From Wolfgang Stanglmeier's NCR scsi driver. */
-struct info_str
-{
-       char *buffer;
-       int length;
-       int offset;
-       int pos;
-};
-
-static void copy_mem_info(struct info_str *info, char *data, int len)
-{
-       if (info->pos + len > info->length)
-               len = info->length - info->pos;
-
-       if (info->pos + len < info->offset) {
-               info->pos += len;
-               return;
-       }
-       if (info->pos < info->offset) {
-               data += (info->offset - info->pos);
-               len  -= (info->offset - info->pos);
-       }
-
-       if (len > 0) {
-               memcpy(info->buffer + info->pos, data, len);
-               info->pos += len;
-       }
-}
-
-static int copy_info(struct info_str *info, char *fmt, ...)
-{
-       va_list args;
-       char buf[81];
-       int len;
-
-       va_start(args, fmt);
-       len = vsprintf(buf, fmt, args);
-       va_end(args);
-
-       copy_mem_info(info, buf, len);
-       return len;
-}
-
-static int esp_host_info(struct NCR_ESP *esp, char *ptr, off_t offset, int len)
-{
-       struct scsi_device *sdev;
-       struct info_str info;
-       int i;
-
-       info.buffer     = ptr;
-       info.length     = len;
-       info.offset     = offset;
-       info.pos        = 0;
-
-       copy_info(&info, "ESP Host Adapter:\n");
-       copy_info(&info, "\tESP Model\t\t");
-       switch(esp->erev) {
-       case esp100:
-               copy_info(&info, "ESP100 (NCR53C90)\n");
-               break;
-       case esp100a:
-               copy_info(&info, "ESP100A (NCR53C90A)\n");
-               break;
-       case esp236:
-               copy_info(&info, "ESP236 (NCR53C9x)\n");
-               break;
-       case fas216:
-               copy_info(&info, "Emulex FAS216\n");
-               break;
-       case fas236:
-               copy_info(&info, "Emulex FAS236\n");
-               break;
-       case fas100a:
-               copy_info(&info, "FPESP100A\n");
-               break;
-       case fast:
-               copy_info(&info, "Generic FAST\n");
-               break;
-       case fas366:
-               copy_info(&info, "QLogic FAS366\n");
-               break;
-       case fsc:
-               copy_info(&info, "Symbios Logic 53C9x-2\n");
-               break;
-       case espunknown:
-       default:
-               copy_info(&info, "Unknown!\n");
-               break;
-       };
-       copy_info(&info, "\tLive Targets\t\t[ ");
-       for(i = 0; i < 15; i++) {
-               if(esp->targets_present & (1 << i))
-                       copy_info(&info, "%d ", i);
-       }
-       copy_info(&info, "]\n\n");
-       
-       /* Now describe the state of each existing target. */
-       copy_info(&info, "Target #\tconfig3\t\tSync Capabilities\tDisconnect\n");
-
-       shost_for_each_device(sdev, esp->ehost) {
-               struct esp_device *esp_dev = sdev->hostdata;
-               uint id = sdev->id;
-
-               if (!(esp->targets_present & (1 << id)))
-                       continue;
-
-               copy_info(&info, "%d\t\t", id);
-               copy_info(&info, "%08lx\t", esp->config3[id]);
-               copy_info(&info, "[%02lx,%02lx]\t\t\t",
-                       esp_dev->sync_max_offset,
-                       esp_dev->sync_min_period);
-               copy_info(&info, "%s\n", esp_dev->disconnect ? "yes" : "no");
-       }
-
-       return info.pos > info.offset? info.pos - info.offset : 0;
-}
-
-/* ESP proc filesystem code. */
-int esp_proc_info(struct Scsi_Host *shost, char *buffer, char **start, off_t offset, int length,
-                 int inout)
-{
-       struct NCR_ESP *esp = (struct NCR_ESP *)shost->hostdata;
-
-       if(inout)
-               return -EINVAL; /* not yet */
-       if(start)
-               *start = buffer;
-       return esp_host_info(esp, buffer, offset, length);
-}
-EXPORT_SYMBOL(esp_proc_info);
-
-static void esp_get_dmabufs(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-       if(sp->use_sg == 0) {
-               sp->SCp.this_residual = sp->request_bufflen;
-               sp->SCp.buffer = (struct scatterlist *) sp->request_buffer;
-               sp->SCp.buffers_residual = 0;
-               if (esp->dma_mmu_get_scsi_one)
-                       esp->dma_mmu_get_scsi_one(esp, sp);
-               else
-                       sp->SCp.ptr =
-                               (char *) virt_to_phys(sp->request_buffer);
-       } else {
-               sp->SCp.buffer = (struct scatterlist *) sp->request_buffer;
-               sp->SCp.buffers_residual = sp->use_sg - 1;
-               sp->SCp.this_residual = sp->SCp.buffer->length;
-               if (esp->dma_mmu_get_scsi_sgl)
-                       esp->dma_mmu_get_scsi_sgl(esp, sp);
-               else
-                       sp->SCp.ptr =
-                               (char *) virt_to_phys(sg_virt(sp->SCp.buffer));
-       }
-}
-
-static void esp_release_dmabufs(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-       if(sp->use_sg == 0) {
-               if (esp->dma_mmu_release_scsi_one)
-                       esp->dma_mmu_release_scsi_one(esp, sp);
-       } else {
-               if (esp->dma_mmu_release_scsi_sgl)
-                       esp->dma_mmu_release_scsi_sgl(esp, sp);
-       }
-}
-
-static void esp_restore_pointers(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-       struct esp_pointers *ep = &esp->data_pointers[scmd_id(sp)];
-
-       sp->SCp.ptr = ep->saved_ptr;
-       sp->SCp.buffer = ep->saved_buffer;
-       sp->SCp.this_residual = ep->saved_this_residual;
-       sp->SCp.buffers_residual = ep->saved_buffers_residual;
-}
-
-static void esp_save_pointers(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-       struct esp_pointers *ep = &esp->data_pointers[scmd_id(sp)];
-
-       ep->saved_ptr = sp->SCp.ptr;
-       ep->saved_buffer = sp->SCp.buffer;
-       ep->saved_this_residual = sp->SCp.this_residual;
-       ep->saved_buffers_residual = sp->SCp.buffers_residual;
-}
-
-/* Some rules:
- *
- *   1) Never ever panic while something is live on the bus.
- *      If there is to be any chance of syncing the disks this
- *      rule is to be obeyed.
- *
- *   2) Any target that causes a foul condition will no longer
- *      have synchronous transfers done to it, no questions
- *      asked.
- *
- *   3) Keep register accesses to a minimum.  Think about some
- *      day when we have Xbus machines this is running on and
- *      the ESP chip is on the other end of the machine on a
- *      different board from the cpu where this is running.
- */
-
-/* Fire off a command.  We assume the bus is free and that the only
- * case where we could see an interrupt is where we have disconnected
- * commands active and they are trying to reselect us.
- */
-static inline void esp_check_cmd(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-       switch(sp->cmd_len) {
-       case 6:
-       case 10:
-       case 12:
-               esp->esp_slowcmd = 0;
-               break;
-
-       default:
-               esp->esp_slowcmd = 1;
-               esp->esp_scmdleft = sp->cmd_len;
-               esp->esp_scmdp = &sp->cmnd[0];
-               break;
-       };
-}
-
-static inline void build_sync_nego_msg(struct NCR_ESP *esp, int period, int offset)
-{
-       esp->cur_msgout[0] = EXTENDED_MESSAGE;
-       esp->cur_msgout[1] = 3;
-       esp->cur_msgout[2] = EXTENDED_SDTR;
-       esp->cur_msgout[3] = period;
-       esp->cur_msgout[4] = offset;
-       esp->msgout_len = 5;
-}
-
-static void esp_exec_cmd(struct NCR_ESP *esp)
-{
-       struct ESP_regs *eregs = esp->eregs;
-       struct esp_device *esp_dev;
-       Scsi_Cmnd *SCptr;
-       struct scsi_device *SDptr;
-       volatile unchar *cmdp = esp->esp_command;
-       unsigned char the_esp_command;
-       int lun, target;
-       int i;
-
-       /* Hold off if we have disconnected commands and
-        * an IRQ is showing...
-        */
-       if(esp->disconnected_SC && esp->dma_irq_p(esp))
-               return;
-
-       /* Grab first member of the issue queue. */
-       SCptr = esp->current_SC = remove_first_SC(&esp->issue_SC);
-
-       /* Safe to panic here because current_SC is null. */
-       if(!SCptr)
-               panic("esp: esp_exec_cmd and issue queue is NULL");
-
-       SDptr = SCptr->device;
-       esp_dev = SDptr->hostdata;
-       lun = SCptr->device->lun;
-       target = SCptr->device->id;
-
-       esp->snip = 0;
-       esp->msgout_len = 0;
-
-       /* Send it out whole, or piece by piece?   The ESP
-        * only knows how to automatically send out 6, 10,
-        * and 12 byte commands.  I used to think that the
-        * Linux SCSI code would never throw anything other
-        * than that to us, but then again there is the
-        * SCSI generic driver which can send us anything.
-        */
-       esp_check_cmd(esp, SCptr);
-
-       /* If arbitration/selection is successful, the ESP will leave
-        * ATN asserted, causing the target to go into message out
-        * phase.  The ESP will feed the target the identify and then
-        * the target can only legally go to one of command,
-        * datain/out, status, or message in phase, or stay in message
-        * out phase (should we be trying to send a sync negotiation
-        * message after the identify).  It is not allowed to drop
-        * BSY, but some buggy targets do and we check for this
-        * condition in the selection complete code.  Most of the time
-        * we'll make the command bytes available to the ESP and it
-        * will not interrupt us until it finishes command phase, we
-        * cannot do this for command sizes the ESP does not
-        * understand and in this case we'll get interrupted right
-        * when the target goes into command phase.
-        *
-        * It is absolutely _illegal_ in the presence of SCSI-2 devices
-        * to use the ESP select w/o ATN command.  When SCSI-2 devices are
-        * present on the bus we _must_ always go straight to message out
-        * phase with an identify message for the target.  Being that
-        * selection attempts in SCSI-1 w/o ATN was an option, doing SCSI-2
-        * selections should not confuse SCSI-1 we hope.
-        */
-
-       if(esp_dev->sync) {
-               /* this targets sync is known */
-#ifdef CONFIG_SCSI_MAC_ESP
-do_sync_known:
-#endif
-               if(esp_dev->disconnect)
-                       *cmdp++ = IDENTIFY(1, lun);
-               else
-                       *cmdp++ = IDENTIFY(0, lun);
-
-               if(esp->esp_slowcmd) {
-                       the_esp_command = (ESP_CMD_SELAS | ESP_CMD_DMA);
-                       esp_advance_phase(SCptr, in_slct_stop);
-               } else {
-                       the_esp_command = (ESP_CMD_SELA | ESP_CMD_DMA);
-                       esp_advance_phase(SCptr, in_slct_norm);
-               }
-       } else if(!(esp->targets_present & (1<<target)) || !(esp_dev->disconnect)) {
-               /* After the bootup SCSI code sends both the
-                * TEST_UNIT_READY and INQUIRY commands we want
-                * to at least attempt allowing the device to
-                * disconnect.
-                */
-               ESPMISC(("esp: Selecting device for first time. target=%d "
-                        "lun=%d\n", target, SCptr->device->lun));
-               if(!SDptr->borken && !esp_dev->disconnect)
-                       esp_dev->disconnect = 1;
-
-               *cmdp++ = IDENTIFY(0, lun);
-               esp->prevmsgout = NOP;
-               esp_advance_phase(SCptr, in_slct_norm);
-               the_esp_command = (ESP_CMD_SELA | ESP_CMD_DMA);
-
-               /* Take no chances... */
-               esp_dev->sync_max_offset = 0;
-               esp_dev->sync_min_period = 0;
-       } else {
-               int toshiba_cdrom_hwbug_wkaround = 0;
-
-#ifdef CONFIG_SCSI_MAC_ESP
-               /* Never allow synchronous transfers (disconnect OK) on
-                * Macintosh. Well, maybe later when we figured out how to 
-                * do DMA on the machines that support it ...
-                */
-               esp_dev->disconnect = 1;
-               esp_dev->sync_max_offset = 0;
-               esp_dev->sync_min_period = 0;
-               esp_dev->sync = 1;
-               esp->snip = 0;
-               goto do_sync_known;
-#endif
-               /* We've talked to this guy before,
-                * but never negotiated.  Let's try
-                * sync negotiation.
-                */
-               if(!SDptr->borken) {
-                       if((SDptr->type == TYPE_ROM) &&
-                          (!strncmp(SDptr->vendor, "TOSHIBA", 7))) {
-                               /* Nice try sucker... */
-                               ESPMISC(("esp%d: Disabling sync for buggy "
-                                        "Toshiba CDROM.\n", esp->esp_id));
-                               toshiba_cdrom_hwbug_wkaround = 1;
-                               build_sync_nego_msg(esp, 0, 0);
-                       } else {
-                               build_sync_nego_msg(esp, esp->sync_defp, 15);
-                       }
-               } else {
-                       build_sync_nego_msg(esp, 0, 0);
-               }
-               esp_dev->sync = 1;
-               esp->snip = 1;
-
-               /* A fix for broken SCSI1 targets, when they disconnect
-                * they lock up the bus and confuse ESP.  So disallow
-                * disconnects for SCSI1 targets for now until we
-                * find a better fix.
-                *
-                * Addendum: This is funny, I figured out what was going
-                *           on.  The blotzed SCSI1 target would disconnect,
-                *           one of the other SCSI2 targets or both would be
-                *           disconnected as well.  The SCSI1 target would
-                *           stay disconnected long enough that we start
-                *           up a command on one of the SCSI2 targets.  As
-                *           the ESP is arbitrating for the bus the SCSI1
-                *           target begins to arbitrate as well to reselect
-                *           the ESP.  The SCSI1 target refuses to drop it's
-                *           ID bit on the data bus even though the ESP is
-                *           at ID 7 and is the obvious winner for any
-                *           arbitration.  The ESP is a poor sport and refuses
-                *           to lose arbitration, it will continue indefinitely
-                *           trying to arbitrate for the bus and can only be
-                *           stopped via a chip reset or SCSI bus reset.
-                *           Therefore _no_ disconnects for SCSI1 targets
-                *           thank you very much. ;-)
-                */
-               if(((SDptr->scsi_level < 3) && (SDptr->type != TYPE_TAPE)) ||
-                  toshiba_cdrom_hwbug_wkaround || SDptr->borken) {
-                       ESPMISC((KERN_INFO "esp%d: Disabling DISCONNECT for target %d "
-                                "lun %d\n", esp->esp_id, SCptr->device->id, SCptr->device->lun));
-                       esp_dev->disconnect = 0;
-                       *cmdp++ = IDENTIFY(0, lun);
-               } else {
-                       *cmdp++ = IDENTIFY(1, lun);
-               }
-
-               /* ESP fifo is only so big...
-                * Make this look like a slow command.
-                */
-               esp->esp_slowcmd = 1;
-               esp->esp_scmdleft = SCptr->cmd_len;
-               esp->esp_scmdp = &SCptr->cmnd[0];
-
-               the_esp_command = (ESP_CMD_SELAS | ESP_CMD_DMA);
-               esp_advance_phase(SCptr, in_slct_msg);
-       }
-
-       if(!esp->esp_slowcmd)
-               for(i = 0; i < SCptr->cmd_len; i++)
-                       *cmdp++ = SCptr->cmnd[i];
-
-       esp_write(eregs->esp_busid, (target & 7));
-       if (esp->prev_soff != esp_dev->sync_max_offset ||
-           esp->prev_stp  != esp_dev->sync_min_period ||
-           (esp->erev > esp100a &&
-            esp->prev_cfg3 != esp->config3[target])) {
-               esp->prev_soff = esp_dev->sync_max_offset;
-               esp_write(eregs->esp_soff, esp->prev_soff);
-               esp->prev_stp = esp_dev->sync_min_period;
-               esp_write(eregs->esp_stp, esp->prev_stp); 
-               if(esp->erev > esp100a) {
-                       esp->prev_cfg3 = esp->config3[target];
-                       esp_write(eregs->esp_cfg3, esp->prev_cfg3);
-               }
-       }
-       i = (cmdp - esp->esp_command);
-
-       /* Set up the DMA and ESP counters */
-       if(esp->do_pio_cmds){
-               int j = 0;
-
-               /* 
-                * XXX MSch:
-                *
-                * It seems this is required, at least to clean up
-                * after failed commands when using PIO mode ...
-                */
-               esp_cmd(esp, eregs, ESP_CMD_FLUSH);
-
-               for(;j<i;j++)
-                       esp_write(eregs->esp_fdata, esp->esp_command[j]);
-               the_esp_command &= ~ESP_CMD_DMA;
-
-               /* Tell ESP to "go". */
-               esp_cmd(esp, eregs, the_esp_command);
-       } else {
-               /* Set up the ESP counters */
-               esp_write(eregs->esp_tclow, i);
-               esp_write(eregs->esp_tcmed, 0);
-               esp->dma_init_write(esp, esp->esp_command_dvma, i);
-
-               /* Tell ESP to "go". */
-               esp_cmd(esp, eregs, the_esp_command);
-       }
-}
-
-/* Queue a SCSI command delivered from the mid-level Linux SCSI code. */
-int esp_queue(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
-{
-       struct NCR_ESP *esp;
-
-       /* Set up func ptr and initial driver cmd-phase. */
-       SCpnt->scsi_done = done;
-       SCpnt->SCp.phase = not_issued;
-
-       esp = (struct NCR_ESP *) SCpnt->device->host->hostdata;
-
-       if(esp->dma_led_on)
-               esp->dma_led_on(esp);
-
-       /* We use the scratch area. */
-       ESPQUEUE(("esp_queue: target=%d lun=%d ", SCpnt->device->id, SCpnt->lun));
-       ESPDISC(("N<%02x,%02x>", SCpnt->device->id, SCpnt->lun));
-
-       esp_get_dmabufs(esp, SCpnt);
-       esp_save_pointers(esp, SCpnt); /* FIXME for tag queueing */
-
-       SCpnt->SCp.Status           = CHECK_CONDITION;
-       SCpnt->SCp.Message          = 0xff;
-       SCpnt->SCp.sent_command     = 0;
-
-       /* Place into our queue. */
-       if(SCpnt->cmnd[0] == REQUEST_SENSE) {
-               ESPQUEUE(("RQSENSE\n"));
-               prepend_SC(&esp->issue_SC, SCpnt);
-       } else {
-               ESPQUEUE(("\n"));
-               append_SC(&esp->issue_SC, SCpnt);
-       }
-
-       /* Run it now if we can. */
-       if(!esp->current_SC && !esp->resetting_bus)
-               esp_exec_cmd(esp);
-
-       return 0;
-}
-
-/* Dump driver state. */
-static void esp_dump_cmd(Scsi_Cmnd *SCptr)
-{
-       ESPLOG(("[tgt<%02x> lun<%02x> "
-               "pphase<%s> cphase<%s>]",
-               SCptr->device->id, SCptr->device->lun,
-               phase_string(SCptr->SCp.sent_command),
-               phase_string(SCptr->SCp.phase)));
-}
-
-static void esp_dump_state(struct NCR_ESP *esp, 
-                          struct ESP_regs *eregs)
-{
-       Scsi_Cmnd *SCptr = esp->current_SC;
-#ifdef DEBUG_ESP_CMDS
-       int i;
-#endif
-
-       ESPLOG(("esp%d: dumping state\n", esp->esp_id));
-       
-       /* Print DMA status */
-       esp->dma_dump_state(esp);
-
-       ESPLOG(("esp%d: SW [sreg<%02x> sstep<%02x> ireg<%02x>]\n",
-               esp->esp_id, esp->sreg, esp->seqreg, esp->ireg));
-       ESPLOG(("esp%d: HW reread [sreg<%02x> sstep<%02x> ireg<%02x>]\n",
-               esp->esp_id, esp_read(eregs->esp_status), esp_read(eregs->esp_sstep),
-               esp_read(eregs->esp_intrpt)));
-#ifdef DEBUG_ESP_CMDS
-       printk("esp%d: last ESP cmds [", esp->esp_id);
-       i = (esp->espcmdent - 1) & 31;
-       printk("<");
-       esp_print_cmd(esp->espcmdlog[i]);
-       printk(">");
-       i = (i - 1) & 31;
-       printk("<");
-       esp_print_cmd(esp->espcmdlog[i]);
-       printk(">");
-       i = (i - 1) & 31;
-       printk("<");
-       esp_print_cmd(esp->espcmdlog[i]);
-       printk(">");
-       i = (i - 1) & 31;
-       printk("<");
-       esp_print_cmd(esp->espcmdlog[i]);
-       printk(">");
-       printk("]\n");
-#endif /* (DEBUG_ESP_CMDS) */
-
-       if(SCptr) {
-               ESPLOG(("esp%d: current command ", esp->esp_id));
-               esp_dump_cmd(SCptr);
-       }
-       ESPLOG(("\n"));
-       SCptr = esp->disconnected_SC;
-       ESPLOG(("esp%d: disconnected ", esp->esp_id));
-       while(SCptr) {
-               esp_dump_cmd(SCptr);
-               SCptr = (Scsi_Cmnd *) SCptr->host_scribble;
-       }
-       ESPLOG(("\n"));
-}
-
-/* Abort a command.  The host_lock is acquired by caller. */
-int esp_abort(Scsi_Cmnd *SCptr)
-{
-       struct NCR_ESP *esp = (struct NCR_ESP *) SCptr->device->host->hostdata;
-       struct ESP_regs *eregs = esp->eregs;
-       int don;
-
-       ESPLOG(("esp%d: Aborting command\n", esp->esp_id));
-       esp_dump_state(esp, eregs);
-
-       /* Wheee, if this is the current command on the bus, the
-        * best we can do is assert ATN and wait for msgout phase.
-        * This should even fix a hung SCSI bus when we lose state
-        * in the driver and timeout because the eventual phase change
-        * will cause the ESP to (eventually) give an interrupt.
-        */
-       if(esp->current_SC == SCptr) {
-               esp->cur_msgout[0] = ABORT;
-               esp->msgout_len = 1;
-               esp->msgout_ctr = 0;
-               esp_cmd(esp, eregs, ESP_CMD_SATN);
-               return SUCCESS;
-       }
-
-       /* If it is still in the issue queue then we can safely
-        * call the completion routine and report abort success.
-        */
-       don = esp->dma_ports_p(esp);
-       if(don) {
-               esp->dma_ints_off(esp);
-               synchronize_irq(esp->irq);
-       }
-       if(esp->issue_SC) {
-               Scsi_Cmnd **prev, *this;
-               for(prev = (&esp->issue_SC), this = esp->issue_SC;
-                   this;
-                   prev = (Scsi_Cmnd **) &(this->host_scribble),
-                   this = (Scsi_Cmnd *) this->host_scribble) {
-                       if(this == SCptr) {
-                               *prev = (Scsi_Cmnd *) this->host_scribble;
-                               this->host_scribble = NULL;
-                               esp_release_dmabufs(esp, this);
-                               this->result = DID_ABORT << 16;
-                               this->scsi_done(this);
-                               if(don)
-                                       esp->dma_ints_on(esp);
-                               return SUCCESS;
-                       }
-               }
-       }
-
-       /* Yuck, the command to abort is disconnected, it is not
-        * worth trying to abort it now if something else is live
-        * on the bus at this time.  So, we let the SCSI code wait
-        * a little bit and try again later.
-        */
-       if(esp->current_SC) {
-               if(don)
-                       esp->dma_ints_on(esp);
-               return FAILED;
-       }
-
-       /* It's disconnected, we have to reconnect to re-establish
-        * the nexus and tell the device to abort.  However, we really
-        * cannot 'reconnect' per se.  Don't try to be fancy, just
-        * indicate failure, which causes our caller to reset the whole
-        * bus.
-        */
-
-       if(don)
-               esp->dma_ints_on(esp);
-       return FAILED;
-}
-
-/* We've sent ESP_CMD_RS to the ESP, the interrupt had just
- * arrived indicating the end of the SCSI bus reset.  Our job
- * is to clean out the command queues and begin re-execution
- * of SCSI commands once more.
- */
-static int esp_finish_reset(struct NCR_ESP *esp,
-                           struct ESP_regs *eregs)
-{
-       Scsi_Cmnd *sp = esp->current_SC;
-
-       /* Clean up currently executing command, if any. */
-       if (sp != NULL) {
-               esp_release_dmabufs(esp, sp);
-               sp->result = (DID_RESET << 16);
-               sp->scsi_done(sp);
-               esp->current_SC = NULL;
-       }
-
-       /* Clean up disconnected queue, they have been invalidated
-        * by the bus reset.
-        */
-       if (esp->disconnected_SC) {
-               while((sp = remove_first_SC(&esp->disconnected_SC)) != NULL) {
-                       esp_release_dmabufs(esp, sp);
-                       sp->result = (DID_RESET << 16);
-                       sp->scsi_done(sp);
-               }
-       }
-
-       /* SCSI bus reset is complete. */
-       esp->resetting_bus = 0;
-       wake_up(&esp->reset_queue);
-
-       /* Ok, now it is safe to get commands going once more. */
-       if(esp->issue_SC)
-               esp_exec_cmd(esp);
-
-       return do_intr_end;
-}
-
-static int esp_do_resetbus(struct NCR_ESP *esp,
-                          struct ESP_regs *eregs)
-{
-       ESPLOG(("esp%d: Resetting scsi bus\n", esp->esp_id));
-       esp->resetting_bus = 1;
-       esp_cmd(esp, eregs, ESP_CMD_RS);
-
-       return do_intr_end;
-}
-
-/* Reset ESP chip, reset hanging bus, then kill active and
- * disconnected commands for targets without soft reset.
- *
- * The host_lock is acquired by caller.
- */
-int esp_reset(Scsi_Cmnd *SCptr)
-{
-       struct NCR_ESP *esp = (struct NCR_ESP *) SCptr->device->host->hostdata;
-
-       spin_lock_irq(esp->ehost->host_lock);
-       (void) esp_do_resetbus(esp, esp->eregs);
-       spin_unlock_irq(esp->ehost->host_lock);
-
-       wait_event(esp->reset_queue, (esp->resetting_bus == 0));
-
-       return SUCCESS;
-}
-
-/* Internal ESP done function. */
-static void esp_done(struct NCR_ESP *esp, int error)
-{
-       Scsi_Cmnd *done_SC;
-
-       if(esp->current_SC) {
-               done_SC = esp->current_SC;
-               esp->current_SC = NULL;
-               esp_release_dmabufs(esp, done_SC);
-               done_SC->result = error;
-               done_SC->scsi_done(done_SC);
-
-               /* Bus is free, issue any commands in the queue. */
-               if(esp->issue_SC && !esp->current_SC)
-                       esp_exec_cmd(esp);
-       } else {
-               /* Panic is safe as current_SC is null so we may still
-                * be able to accept more commands to sync disk buffers.
-                */
-               ESPLOG(("panicing\n"));
-               panic("esp: done() called with NULL esp->current_SC");
-       }
-}
-
-/* Wheee, ESP interrupt engine. */  
-
-/* Forward declarations. */
-static int esp_do_phase_determine(struct NCR_ESP *esp, 
-                                 struct ESP_regs *eregs);
-static int esp_do_data_finale(struct NCR_ESP *esp, struct ESP_regs *eregs);
-static int esp_select_complete(struct NCR_ESP *esp, struct ESP_regs *eregs);
-static int esp_do_status(struct NCR_ESP *esp, struct ESP_regs *eregs);
-static int esp_do_msgin(struct NCR_ESP *esp, struct ESP_regs *eregs);
-static int esp_do_msgindone(struct NCR_ESP *esp, struct ESP_regs *eregs);
-static int esp_do_msgout(struct NCR_ESP *esp, struct ESP_regs *eregs);
-static int esp_do_cmdbegin(struct NCR_ESP *esp, struct ESP_regs *eregs);
-
-#define sreg_datainp(__sreg)  (((__sreg) & ESP_STAT_PMASK) == ESP_DIP)
-#define sreg_dataoutp(__sreg) (((__sreg) & ESP_STAT_PMASK) == ESP_DOP)
-
-/* We try to avoid some interrupts by jumping ahead and see if the ESP
- * has gotten far enough yet.  Hence the following.
- */
-static inline int skipahead1(struct NCR_ESP *esp, struct ESP_regs *eregs,
-                            Scsi_Cmnd *scp, int prev_phase, int new_phase)
-{
-       if(scp->SCp.sent_command != prev_phase)
-               return 0;
-
-       if(esp->dma_irq_p(esp)) {
-               /* Yes, we are able to save an interrupt. */
-               esp->sreg = (esp_read(eregs->esp_status) & ~(ESP_STAT_INTR));
-               esp->ireg = esp_read(eregs->esp_intrpt);
-               if(!(esp->ireg & ESP_INTR_SR))
-                       return 0;
-               else
-                       return do_reset_complete;
-       }
-       /* Ho hum, target is taking forever... */
-       scp->SCp.sent_command = new_phase; /* so we don't recurse... */
-       return do_intr_end;
-}
-
-static inline int skipahead2(struct NCR_ESP *esp,
-                            struct ESP_regs *eregs,
-                            Scsi_Cmnd *scp, int prev_phase1, int prev_phase2,
-                            int new_phase)
-{
-       if(scp->SCp.sent_command != prev_phase1 &&
-          scp->SCp.sent_command != prev_phase2)
-               return 0;
-       if(esp->dma_irq_p(esp)) {
-               /* Yes, we are able to save an interrupt. */
-               esp->sreg = (esp_read(eregs->esp_status) & ~(ESP_STAT_INTR));
-               esp->ireg = esp_read(eregs->esp_intrpt);
-               if(!(esp->ireg & ESP_INTR_SR))
-                       return 0;
-               else
-                       return do_reset_complete;
-       }
-       /* Ho hum, target is taking forever... */
-       scp->SCp.sent_command = new_phase; /* so we don't recurse... */
-       return do_intr_end;
-}
-
-/* Misc. esp helper macros. */
-#define esp_setcount(__eregs, __cnt) \
-       esp_write((__eregs)->esp_tclow, ((__cnt) & 0xff)); \
-       esp_write((__eregs)->esp_tcmed, (((__cnt) >> 8) & 0xff))
-
-#define esp_getcount(__eregs) \
-       ((esp_read((__eregs)->esp_tclow)&0xff) | \
-        ((esp_read((__eregs)->esp_tcmed)&0xff) << 8))
-
-#define fcount(__esp, __eregs) \
-       (esp_read((__eregs)->esp_fflags) & ESP_FF_FBYTES)
-
-#define fnzero(__esp, __eregs) \
-       (esp_read((__eregs)->esp_fflags) & ESP_FF_ONOTZERO)
-
-/* XXX speculative nops unnecessary when continuing amidst a data phase
- * XXX even on esp100!!!  another case of flooding the bus with I/O reg
- * XXX writes...
- */
-#define esp_maybe_nop(__esp, __eregs) \
-       if((__esp)->erev == esp100) \
-               esp_cmd((__esp), (__eregs), ESP_CMD_NULL)
-
-#define sreg_to_dataphase(__sreg) \
-       ((((__sreg) & ESP_STAT_PMASK) == ESP_DOP) ? in_dataout : in_datain)
-
-/* The ESP100 when in synchronous data phase, can mistake a long final
- * REQ pulse from the target as an extra byte, it places whatever is on
- * the data lines into the fifo.  For now, we will assume when this
- * happens that the target is a bit quirky and we don't want to
- * be talking synchronously to it anyways.  Regardless, we need to
- * tell the ESP to eat the extraneous byte so that we can proceed
- * to the next phase.
- */
-static inline int esp100_sync_hwbug(struct NCR_ESP *esp, struct ESP_regs *eregs,
-                                   Scsi_Cmnd *sp, int fifocnt)
-{
-       /* Do not touch this piece of code. */
-       if((!(esp->erev == esp100)) ||
-          (!(sreg_datainp((esp->sreg = esp_read(eregs->esp_status))) && !fifocnt) &&
-           !(sreg_dataoutp(esp->sreg) && !fnzero(esp, eregs)))) {
-               if(sp->SCp.phase == in_dataout)
-                       esp_cmd(esp, eregs, ESP_CMD_FLUSH);
-               return 0;
-       } else {
-               /* Async mode for this guy. */
-               build_sync_nego_msg(esp, 0, 0);
-
-               /* Ack the bogus byte, but set ATN first. */
-               esp_cmd(esp, eregs, ESP_CMD_SATN);
-               esp_cmd(esp, eregs, ESP_CMD_MOK);
-               return 1;
-       }
-}
-
-/* This closes the window during a selection with a reselect pending, because
- * we use DMA for the selection process the FIFO should hold the correct
- * contents if we get reselected during this process.  So we just need to
- * ack the possible illegal cmd interrupt pending on the esp100.
- */
-static inline int esp100_reconnect_hwbug(struct NCR_ESP *esp,
-                                        struct ESP_regs *eregs)
-{
-       volatile unchar junk;
-
-       if(esp->erev != esp100)
-               return 0;
-       junk = esp_read(eregs->esp_intrpt);
-
-       if(junk & ESP_INTR_SR)
-               return 1;
-       return 0;
-}
-
-/* This verifies the BUSID bits during a reselection so that we know which
- * target is talking to us.
- */
-static inline int reconnect_target(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       int it, me = esp->scsi_id_mask, targ = 0;
-
-       if(2 != fcount(esp, eregs))
-               return -1;
-       it = esp_read(eregs->esp_fdata);
-       if(!(it & me))
-               return -1;
-       it &= ~me;
-       if(it & (it - 1))
-               return -1;
-       while(!(it & 1))
-               targ++, it >>= 1;
-       return targ;
-}
-
-/* This verifies the identify from the target so that we know which lun is
- * being reconnected.
- */
-static inline int reconnect_lun(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       int lun;
-
-       if((esp->sreg & ESP_STAT_PMASK) != ESP_MIP)
-               return -1;
-       lun = esp_read(eregs->esp_fdata);
-
-       /* Yes, you read this correctly.  We report lun of zero
-        * if we see parity error.  ESP reports parity error for
-        * the lun byte, and this is the only way to hope to recover
-        * because the target is connected.
-        */
-       if(esp->sreg & ESP_STAT_PERR)
-               return 0;
-
-       /* Check for illegal bits being set in the lun. */
-       if((lun & 0x40) || !(lun & 0x80))
-               return -1;
-
-       return lun & 7;
-}
-
-/* This puts the driver in a state where it can revitalize a command that
- * is being continued due to reselection.
- */
-static inline void esp_connect(struct NCR_ESP *esp, struct ESP_regs *eregs,
-                              Scsi_Cmnd *sp)
-{
-       struct scsi_device *dp = sp->device;
-       struct esp_device *esp_dev = dp->hostdata;
-
-       if(esp->prev_soff  != esp_dev->sync_max_offset ||
-          esp->prev_stp   != esp_dev->sync_min_period ||
-          (esp->erev > esp100a &&
-           esp->prev_cfg3 != esp->config3[scmd_id(sp)])) {
-               esp->prev_soff = esp_dev->sync_max_offset;
-               esp_write(eregs->esp_soff, esp->prev_soff);
-               esp->prev_stp = esp_dev->sync_min_period;
-               esp_write(eregs->esp_stp, esp->prev_stp);
-               if(esp->erev > esp100a) {
-                       esp->prev_cfg3 = esp->config3[scmd_id(sp)];
-                       esp_write(eregs->esp_cfg3, esp->prev_cfg3);
-               } 
-       }
-       esp->current_SC = sp;
-}
-
-/* This will place the current working command back into the issue queue
- * if we are to receive a reselection amidst a selection attempt.
- */
-static inline void esp_reconnect(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-       if(!esp->disconnected_SC)
-               ESPLOG(("esp%d: Weird, being reselected but disconnected "
-                       "command queue is empty.\n", esp->esp_id));
-       esp->snip = 0;
-       esp->current_SC = NULL;
-       sp->SCp.phase = not_issued;
-       append_SC(&esp->issue_SC, sp);
-}
-
-/* Begin message in phase. */
-static int esp_do_msgin(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       esp_cmd(esp, eregs, ESP_CMD_FLUSH);
-       esp_maybe_nop(esp, eregs);
-       esp_cmd(esp, eregs, ESP_CMD_TI);
-       esp->msgin_len = 1;
-       esp->msgin_ctr = 0;
-       esp_advance_phase(esp->current_SC, in_msgindone);
-       return do_work_bus;
-}
-
-static inline void advance_sg(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-       ++sp->SCp.buffer;
-       --sp->SCp.buffers_residual;
-       sp->SCp.this_residual = sp->SCp.buffer->length;
-       if (esp->dma_advance_sg)
-               esp->dma_advance_sg (sp);
-       else
-               sp->SCp.ptr = (char *) virt_to_phys(sg_virt(sp->SCp.buffer));
-
-}
-
-/* Please note that the way I've coded these routines is that I _always_
- * check for a disconnect during any and all information transfer
- * phases.  The SCSI standard states that the target _can_ cause a BUS
- * FREE condition by dropping all MSG/CD/IO/BSY signals.  Also note
- * that during information transfer phases the target controls every
- * change in phase, the only thing the initiator can do is "ask" for
- * a message out phase by driving ATN true.  The target can, and sometimes
- * will, completely ignore this request so we cannot assume anything when
- * we try to force a message out phase to abort/reset a target.  Most of
- * the time the target will eventually be nice and go to message out, so
- * we may have to hold on to our state about what we want to tell the target
- * for some period of time.
- */
-
-/* I think I have things working here correctly.  Even partial transfers
- * within a buffer or sub-buffer should not upset us at all no matter
- * how bad the target and/or ESP fucks things up.
- */
-static int esp_do_data(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       Scsi_Cmnd *SCptr = esp->current_SC;
-       int thisphase, hmuch;
-
-       ESPDATA(("esp_do_data: "));
-       esp_maybe_nop(esp, eregs);
-       thisphase = sreg_to_dataphase(esp->sreg);
-       esp_advance_phase(SCptr, thisphase);
-       ESPDATA(("newphase<%s> ", (thisphase == in_datain) ? "DATAIN" : "DATAOUT"));
-       hmuch = esp->dma_can_transfer(esp, SCptr);
-
-       /*
-        * XXX MSch: cater for PIO transfer here; PIO used if hmuch == 0
-        */
-       if (hmuch) {    /* DMA */
-               /*
-                * DMA
-                */
-               ESPDATA(("hmuch<%d> ", hmuch));
-               esp->current_transfer_size = hmuch;
-               esp_setcount(eregs, (esp->fas_premature_intr_workaround ?
-                                    (hmuch + 0x40) : hmuch));
-               esp->dma_setup(esp, (__u32)((unsigned long)SCptr->SCp.ptr), 
-                              hmuch, (thisphase == in_datain));
-               ESPDATA(("DMA|TI --> do_intr_end\n"));
-               esp_cmd(esp, eregs, ESP_CMD_DMA | ESP_CMD_TI);
-               return do_intr_end;
-               /*
-                * end DMA
-                */
-       } else {
-               /*
-                * PIO
-                */
-               int oldphase, i = 0; /* or where we left off last time ?? esp->current_data ?? */
-               int fifocnt = 0;
-               unsigned char *p = phys_to_virt((unsigned long)SCptr->SCp.ptr);
-
-               oldphase = esp_read(eregs->esp_status) & ESP_STAT_PMASK;
-
-               /*
-                * polled transfer; ugly, can we make this happen in a DRQ 
-                * interrupt handler ??
-                * requires keeping track of state information in host or 
-                * command struct!
-                * Problem: I've never seen a DRQ happen on Mac, not even
-                * with ESP_CMD_DMA ...
-                */
-
-               /* figure out how much needs to be transferred */
-               hmuch = SCptr->SCp.this_residual;
-               ESPDATA(("hmuch<%d> pio ", hmuch));
-               esp->current_transfer_size = hmuch;
-
-               /* tell the ESP ... */
-               esp_setcount(eregs, hmuch);
-
-               /* loop */
-               while (hmuch) {
-                       int j, fifo_stuck = 0, newphase;
-                       unsigned long timeout;
-#if 0
-                       unsigned long flags;
-#endif
-#if 0
-                       if ( i % 10 )
-                               ESPDATA(("\r"));
-                       else
-                               ESPDATA(( /*"\n"*/ "\r"));
-#endif
-#if 0
-                       local_irq_save(flags);
-#endif
-                       if(thisphase == in_datain) {
-                               /* 'go' ... */ 
-                               esp_cmd(esp, eregs, ESP_CMD_TI);
-
-                               /* wait for data */
-                               timeout = 1000000;
-                               while (!((esp->sreg=esp_read(eregs->esp_status)) & ESP_STAT_INTR) && --timeout)
-                                       udelay(2);
-                               if (timeout == 0)
-                                       printk("DRQ datain timeout! \n");
-
-                               newphase = esp->sreg & ESP_STAT_PMASK;
-
-                               /* see how much we got ... */
-                               fifocnt = (esp_read(eregs->esp_fflags) & ESP_FF_FBYTES);
-
-                               if (!fifocnt)
-                                       fifo_stuck++;
-                               else
-                                       fifo_stuck = 0;
-
-                               ESPDATA(("\rgot %d st %x ph %x", fifocnt, esp->sreg, newphase));
-
-                               /* read fifo */
-                               for(j=0;j<fifocnt;j++)
-                                       p[i++] = esp_read(eregs->esp_fdata);
-
-                               ESPDATA(("(%d) ", i));
-
-                               /* how many to go ?? */
-                               hmuch -= fifocnt;
-
-                               /* break if status phase !! */
-                               if(newphase == ESP_STATP) {
-                                       /* clear int. */
-                                       esp->ireg = esp_read(eregs->esp_intrpt);
-                                       break;
-                               }
-                       } else {
-#define MAX_FIFO 8
-                               /* how much will fit ? */
-                               int this_count = MAX_FIFO - fifocnt;
-                               if (this_count > hmuch)
-                                       this_count = hmuch;
-
-                               /* fill fifo */
-                               for(j=0;j<this_count;j++)
-                                       esp_write(eregs->esp_fdata, p[i++]);
-
-                               /* how many left if this goes out ?? */
-                               hmuch -= this_count;
-
-                               /* 'go' ... */ 
-                               esp_cmd(esp, eregs, ESP_CMD_TI);
-
-                               /* wait for 'got it' */
-                               timeout = 1000000;
-                               while (!((esp->sreg=esp_read(eregs->esp_status)) & ESP_STAT_INTR) && --timeout)
-                                       udelay(2);
-                               if (timeout == 0)
-                                       printk("DRQ dataout timeout!  \n");
-
-                               newphase = esp->sreg & ESP_STAT_PMASK;
-
-                               /* need to check how much was sent ?? */
-                               fifocnt = (esp_read(eregs->esp_fflags) & ESP_FF_FBYTES);
-
-                               ESPDATA(("\rsent %d st %x ph %x", this_count - fifocnt, esp->sreg, newphase));
-
-                               ESPDATA(("(%d) ", i));
-
-                               /* break if status phase !! */
-                               if(newphase == ESP_STATP) {
-                                       /* clear int. */
-                                       esp->ireg = esp_read(eregs->esp_intrpt);
-                                       break;
-                               }
-
-                       }
-
-                       /* clear int. */
-                       esp->ireg = esp_read(eregs->esp_intrpt);
-
-                       ESPDATA(("ir %x ... ", esp->ireg));
-
-                       if (hmuch == 0)
-                               ESPDATA(("done! \n"));
-
-#if 0
-                       local_irq_restore(flags);
-#endif
-
-                       /* check new bus phase */
-                       if (newphase != oldphase && i < esp->current_transfer_size) {
-                               /* something happened; disconnect ?? */
-                               ESPDATA(("phase change, dropped out with %d done ... ", i));
-                               break;
-                       }
-
-                       /* check int. status */
-                       if (esp->ireg & ESP_INTR_DC) {
-                               /* disconnect */
-                               ESPDATA(("disconnect; %d transferred ... ", i));
-                               break;
-                       } else if (esp->ireg & ESP_INTR_FDONE) {
-                               /* function done */
-                               ESPDATA(("function done; %d transferred ... ", i));
-                               break;
-                       }
-
-                       /* XXX fixme: bail out on stall */
-                       if (fifo_stuck > 10) {
-                               /* we're stuck */
-                               ESPDATA(("fifo stall; %d transferred ... ", i));
-                               break;
-                       }
-               }
-
-               ESPDATA(("\n"));
-               /* check successful completion ?? */
-
-               if (thisphase == in_dataout)
-                       hmuch += fifocnt; /* stuck?? adjust data pointer ...*/
-
-               /* tell do_data_finale how much was transferred */
-               esp->current_transfer_size -= hmuch;
-
-               /* still not completely sure on this one ... */         
-               return /*do_intr_end*/ do_work_bus /*do_phase_determine*/ ;
-
-               /*
-                * end PIO
-                */
-       }
-       return do_intr_end;
-}
-
-/* See how successful the data transfer was. */
-static int esp_do_data_finale(struct NCR_ESP *esp,
-                             struct ESP_regs *eregs)
-{
-       Scsi_Cmnd *SCptr = esp->current_SC;
-       struct esp_device *esp_dev = SCptr->device->hostdata;
-       int bogus_data = 0, bytes_sent = 0, fifocnt, ecount = 0;
-
-       if(esp->dma_led_off)
-               esp->dma_led_off(esp);
-
-       ESPDATA(("esp_do_data_finale: "));
-
-       if(SCptr->SCp.phase == in_datain) {
-               if(esp->sreg & ESP_STAT_PERR) {
-                       /* Yuck, parity error.  The ESP asserts ATN
-                        * so that we can go to message out phase
-                        * immediately and inform the target that
-                        * something bad happened.
-                        */
-                       ESPLOG(("esp%d: data bad parity detected.\n",
-                               esp->esp_id));
-                       esp->cur_msgout[0] = INITIATOR_ERROR;
-                       esp->msgout_len = 1;
-               }
-               if(esp->dma_drain)
-                       esp->dma_drain(esp);
-       }
-       if(esp->dma_invalidate)
-               esp->dma_invalidate(esp);
-
-       /* This could happen for the above parity error case. */
-       if(!(esp->ireg == ESP_INTR_BSERV)) {
-               /* Please go to msgout phase, please please please... */
-               ESPLOG(("esp%d: !BSERV after data, probably to msgout\n",
-                       esp->esp_id));
-               return esp_do_phase_determine(esp, eregs);
-       }       
-
-       /* Check for partial transfers and other horrible events. */
-       fifocnt = (esp_read(eregs->esp_fflags) & ESP_FF_FBYTES);
-       ecount = esp_getcount(eregs);
-       if(esp->fas_premature_intr_workaround)
-               ecount -= 0x40;
-       bytes_sent = esp->current_transfer_size;
-
-       ESPDATA(("trans_sz=%d, ", bytes_sent));
-       if(!(esp->sreg & ESP_STAT_TCNT))
-               bytes_sent -= ecount;
-       if(SCptr->SCp.phase == in_dataout)
-               bytes_sent -= fifocnt;
-
-       ESPDATA(("bytes_sent=%d (ecount=%d, fifocnt=%d), ", bytes_sent,
-                ecount, fifocnt));
-
-       /* If we were in synchronous mode, check for peculiarities. */
-       if(esp_dev->sync_max_offset)
-               bogus_data = esp100_sync_hwbug(esp, eregs, SCptr, fifocnt);
-       else
-               esp_cmd(esp, eregs, ESP_CMD_FLUSH);
-
-       /* Until we are sure of what has happened, we are certainly
-        * in the dark.
-        */
-       esp_advance_phase(SCptr, in_the_dark);
-
-       /* Check for premature interrupt condition. Can happen on FAS2x6
-        * chips. QLogic recommends a workaround by overprogramming the
-        * transfer counters, but this makes doing scatter-gather impossible.
-        * Until there is a way to disable scatter-gather for a single target,
-        * and not only for the entire host adapter as it is now, the workaround
-        * is way to expensive performance wise.
-        * Instead, it turns out that when this happens the target has disconnected
-        * already but it doesn't show in the interrupt register. Compensate for
-        * that here to try and avoid a SCSI bus reset.
-        */
-       if(!esp->fas_premature_intr_workaround && (fifocnt == 1) &&
-          sreg_dataoutp(esp->sreg)) {
-               ESPLOG(("esp%d: Premature interrupt, enabling workaround\n",
-                       esp->esp_id));
-#if 0
-               /* Disable scatter-gather operations, they are not possible
-                * when using this workaround.
-                */
-               esp->ehost->sg_tablesize = 0;
-               esp->ehost->use_clustering = ENABLE_CLUSTERING;
-               esp->fas_premature_intr_workaround = 1;
-               bytes_sent = 0;
-               if(SCptr->use_sg) {
-                       ESPLOG(("esp%d: Aborting scatter-gather operation\n",
-                               esp->esp_id));
-                       esp->cur_msgout[0] = ABORT;
-                       esp->msgout_len = 1;
-                       esp->msgout_ctr = 0;
-                       esp_cmd(esp, eregs, ESP_CMD_SATN);
-                       esp_setcount(eregs, 0xffff);
-                       esp_cmd(esp, eregs, ESP_CMD_NULL);
-                       esp_cmd(esp, eregs, ESP_CMD_TPAD | ESP_CMD_DMA);
-                       return do_intr_end;
-               }
-#else
-               /* Just set the disconnected bit. That's what appears to
-                * happen anyway. The state machine will pick it up when
-                * we return.
-                */
-               esp->ireg |= ESP_INTR_DC;
-#endif
-        }
-
-       if(bytes_sent < 0) {
-               /* I've seen this happen due to lost state in this
-                * driver.  No idea why it happened, but allowing
-                * this value to be negative caused things to
-                * lock up.  This allows greater chance of recovery.
-                * In fact every time I've seen this, it has been
-                * a driver bug without question.
-                */
-               ESPLOG(("esp%d: yieee, bytes_sent < 0!\n", esp->esp_id));
-               ESPLOG(("esp%d: csz=%d fifocount=%d ecount=%d\n",
-                       esp->esp_id,
-                       esp->current_transfer_size, fifocnt, ecount));
-               ESPLOG(("esp%d: use_sg=%d ptr=%p this_residual=%d\n",
-                       esp->esp_id,
-                       SCptr->use_sg, SCptr->SCp.ptr, SCptr->SCp.this_residual));
-               ESPLOG(("esp%d: Forcing async for target %d\n", esp->esp_id, 
-                       SCptr->device->id));
-               SCptr->device->borken = 1;
-               esp_dev->sync = 0;
-               bytes_sent = 0;
-       }
-
-       /* Update the state of our transfer. */
-       SCptr->SCp.ptr += bytes_sent;
-       SCptr->SCp.this_residual -= bytes_sent;
-       if(SCptr->SCp.this_residual < 0) {
-               /* shit */
-               ESPLOG(("esp%d: Data transfer overrun.\n", esp->esp_id));
-               SCptr->SCp.this_residual = 0;
-       }
-
-       /* Maybe continue. */
-       if(!bogus_data) {
-               ESPDATA(("!bogus_data, "));
-               /* NO MATTER WHAT, we advance the scatterlist,
-                * if the target should decide to disconnect
-                * in between scatter chunks (which is common)
-                * we could die horribly!  I used to have the sg
-                * advance occur only if we are going back into
-                * (or are staying in) a data phase, you can
-                * imagine the hell I went through trying to
-                * figure this out.
-                */
-               if(!SCptr->SCp.this_residual && SCptr->SCp.buffers_residual)
-                       advance_sg(esp, SCptr);
-#ifdef DEBUG_ESP_DATA
-               if(sreg_datainp(esp->sreg) || sreg_dataoutp(esp->sreg)) {
-                       ESPDATA(("to more data\n"));
-               } else {
-                       ESPDATA(("to new phase\n"));
-               }
-#endif
-               return esp_do_phase_determine(esp, eregs);
-       }
-       /* Bogus data, just wait for next interrupt. */
-       ESPLOG(("esp%d: bogus_data during end of data phase\n",
-               esp->esp_id));
-       return do_intr_end;
-}
-
-/* We received a non-good status return at the end of
- * running a SCSI command.  This is used to decide if
- * we should clear our synchronous transfer state for
- * such a device when that happens.
- *
- * The idea is that when spinning up a disk or rewinding
- * a tape, we don't want to go into a loop re-negotiating
- * synchronous capabilities over and over.
- */
-static int esp_should_clear_sync(Scsi_Cmnd *sp)
-{
-       unchar cmd = sp->cmnd[0];
-
-       /* These cases are for spinning up a disk and
-        * waiting for that spinup to complete.
-        */
-       if(cmd == START_STOP)
-               return 0;
-
-       if(cmd == TEST_UNIT_READY)
-               return 0;
-
-       /* One more special case for SCSI tape drives,
-        * this is what is used to probe the device for
-        * completion of a rewind or tape load operation.
-        */
-       if(sp->device->type == TYPE_TAPE && cmd == MODE_SENSE)
-               return 0;
-
-       return 1;
-}
-
-/* Either a command is completing or a target is dropping off the bus
- * to continue the command in the background so we can do other work.
- */
-static int esp_do_freebus(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       Scsi_Cmnd *SCptr = esp->current_SC;
-       int rval;
-
-       rval = skipahead2(esp, eregs, SCptr, in_status, in_msgindone, in_freeing);
-       if(rval)
-               return rval;
-
-       if(esp->ireg != ESP_INTR_DC) {
-               ESPLOG(("esp%d: Target will not disconnect\n", esp->esp_id));
-               return do_reset_bus; /* target will not drop BSY... */
-       }
-       esp->msgout_len = 0;
-       esp->prevmsgout = NOP;
-       if(esp->prevmsgin == COMMAND_COMPLETE) {
-               struct esp_device *esp_dev = SCptr->device->hostdata;
-               /* Normal end of nexus. */
-               if(esp->disconnected_SC)
-                       esp_cmd(esp, eregs, ESP_CMD_ESEL);
-
-               if(SCptr->SCp.Status != GOOD &&
-                  SCptr->SCp.Status != CONDITION_GOOD &&
-                  ((1<<scmd_id(SCptr)) & esp->targets_present) &&
-                  esp_dev->sync && esp_dev->sync_max_offset) {
-                       /* SCSI standard says that the synchronous capabilities
-                        * should be renegotiated at this point.  Most likely
-                        * we are about to request sense from this target
-                        * in which case we want to avoid using sync
-                        * transfers until we are sure of the current target
-                        * state.
-                        */
-                       ESPMISC(("esp: Status <%d> for target %d lun %d\n",
-                                SCptr->SCp.Status, SCptr->device->id, SCptr->device->lun));
-
-                       /* But don't do this when spinning up a disk at
-                        * boot time while we poll for completion as it
-                        * fills up the console with messages.  Also, tapes
-                        * can report not ready many times right after
-                        * loading up a tape.
-                        */
-                       if(esp_should_clear_sync(SCptr) != 0)
-                               esp_dev->sync = 0;
-               }
-               ESPDISC(("F<%02x,%02x>", SCptr->device->id, SCptr->device->lun));
-               esp_done(esp, ((SCptr->SCp.Status & 0xff) |
-                              ((SCptr->SCp.Message & 0xff)<<8) |
-                              (DID_OK << 16)));
-       } else if(esp->prevmsgin == DISCONNECT) {
-               /* Normal disconnect. */
-               esp_cmd(esp, eregs, ESP_CMD_ESEL);
-               ESPDISC(("D<%02x,%02x>", SCptr->device->id, SCptr->device->lun));
-               append_SC(&esp->disconnected_SC, SCptr);
-               esp->current_SC = NULL;
-               if(esp->issue_SC)
-                       esp_exec_cmd(esp);
-       } else {
-               /* Driver bug, we do not expect a disconnect here
-                * and should not have advanced the state engine
-                * to in_freeing.
-                */
-               ESPLOG(("esp%d: last msg not disc and not cmd cmplt.\n",
-                       esp->esp_id));
-               return do_reset_bus;
-       }
-       return do_intr_end;
-}
-
-/* When a reselect occurs, and we cannot find the command to
- * reconnect to in our queues, we do this.
- */
-static int esp_bad_reconnect(struct NCR_ESP *esp)
-{
-       Scsi_Cmnd *sp;
-
-       ESPLOG(("esp%d: Eieeee, reconnecting unknown command!\n",
-               esp->esp_id));
-       ESPLOG(("QUEUE DUMP\n"));
-       sp = esp->issue_SC;
-       ESPLOG(("esp%d: issue_SC[", esp->esp_id));
-       while(sp) {
-               ESPLOG(("<%02x,%02x>", sp->device->id, sp->device->lun));
-               sp = (Scsi_Cmnd *) sp->host_scribble;
-       }
-       ESPLOG(("]\n"));
-       sp = esp->current_SC;
-       ESPLOG(("esp%d: current_SC[", esp->esp_id));
-       while(sp) {
-               ESPLOG(("<%02x,%02x>", sp->device->id, sp->device->lun));
-               sp = (Scsi_Cmnd *) sp->host_scribble;
-       }
-       ESPLOG(("]\n"));
-       sp = esp->disconnected_SC;
-       ESPLOG(("esp%d: disconnected_SC[", esp->esp_id));
-       while(sp) {
-               ESPLOG(("<%02x,%02x>", sp->device->id, sp->device->lun));
-               sp = (Scsi_Cmnd *) sp->host_scribble;
-       }
-       ESPLOG(("]\n"));
-       return do_reset_bus;
-}
-
-/* Do the needy when a target tries to reconnect to us. */
-static int esp_do_reconnect(struct NCR_ESP *esp, 
-                           struct ESP_regs *eregs)
-{
-       int lun, target;
-       Scsi_Cmnd *SCptr;
-
-       /* Check for all bogus conditions first. */
-       target = reconnect_target(esp, eregs);
-       if(target < 0) {
-               ESPDISC(("bad bus bits\n"));
-               return do_reset_bus;
-       }
-       lun = reconnect_lun(esp, eregs);
-       if(lun < 0) {
-               ESPDISC(("target=%2x, bad identify msg\n", target));
-               return do_reset_bus;
-       }
-
-       /* Things look ok... */
-       ESPDISC(("R<%02x,%02x>", target, lun));
-
-       esp_cmd(esp, eregs, ESP_CMD_FLUSH);
-       if(esp100_reconnect_hwbug(esp, eregs))
-               return do_reset_bus;
-       esp_cmd(esp, eregs, ESP_CMD_NULL);
-
-       SCptr = remove_SC(&esp->disconnected_SC, (unchar) target, (unchar) lun);
-       if(!SCptr)
-               return esp_bad_reconnect(esp);
-
-       esp_connect(esp, eregs, SCptr);
-       esp_cmd(esp, eregs, ESP_CMD_MOK);
-
-       /* Reconnect implies a restore pointers operation. */
-       esp_restore_pointers(esp, SCptr);
-
-       esp->snip = 0;
-       esp_advance_phase(SCptr, in_the_dark);
-       return do_intr_end;
-}
-
-/* End of NEXUS (hopefully), pick up status + message byte then leave if
- * all goes well.
- */
-static int esp_do_status(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       Scsi_Cmnd *SCptr = esp->current_SC;
-       int intr, rval;
-
-       rval = skipahead1(esp, eregs, SCptr, in_the_dark, in_status);
-       if(rval)
-               return rval;
-
-       intr = esp->ireg;
-       ESPSTAT(("esp_do_status: "));
-       if(intr != ESP_INTR_DC) {
-               int message_out = 0; /* for parity problems */
-
-               /* Ack the message. */
-               ESPSTAT(("ack msg, "));
-               esp_cmd(esp, eregs, ESP_CMD_MOK);
-
-               if(esp->dma_poll)
-                       esp->dma_poll(esp, (unsigned char *) esp->esp_command);
-
-               ESPSTAT(("got something, "));
-               /* ESP chimes in with one of
-                *
-                * 1) function done interrupt:
-                *      both status and message in bytes
-                *      are available
-                *
-                * 2) bus service interrupt:
-                *      only status byte was acquired
-                *
-                * 3) Anything else:
-                *      can't happen, but we test for it
-                *      anyways
-                *
-                * ALSO: If bad parity was detected on either
-                *       the status _or_ the message byte then
-                *       the ESP has asserted ATN on the bus
-                *       and we must therefore wait for the
-                *       next phase change.
-                */
-               if(intr & ESP_INTR_FDONE) {
-                       /* We got it all, hallejulia. */
-                       ESPSTAT(("got both, "));
-                       SCptr->SCp.Status = esp->esp_command[0];
-                       SCptr->SCp.Message = esp->esp_command[1];
-                       esp->prevmsgin = SCptr->SCp.Message;
-                       esp->cur_msgin[0] = SCptr->SCp.Message;
-                       if(esp->sreg & ESP_STAT_PERR) {
-                               /* There was bad parity for the
-                                * message byte, the status byte
-                                * was ok.
-                                */
-                               message_out = MSG_PARITY_ERROR;
-                       }
-               } else if(intr == ESP_INTR_BSERV) {
-                       /* Only got status byte. */
-                       ESPLOG(("esp%d: got status only, ", esp->esp_id));
-                       if(!(esp->sreg & ESP_STAT_PERR)) {
-                               SCptr->SCp.Status = esp->esp_command[0];
-                               SCptr->SCp.Message = 0xff;
-                       } else {
-                               /* The status byte had bad parity.
-                                * we leave the scsi_pointer Status
-                                * field alone as we set it to a default
-                                * of CHECK_CONDITION in esp_queue.
-                                */
-                               message_out = INITIATOR_ERROR;
-                       }
-               } else {
-                       /* This shouldn't happen ever. */
-                       ESPSTAT(("got bolixed\n"));
-                       esp_advance_phase(SCptr, in_the_dark);
-                       return esp_do_phase_determine(esp, eregs);
-               }
-
-               if(!message_out) {
-                       ESPSTAT(("status=%2x msg=%2x, ", SCptr->SCp.Status,
-                               SCptr->SCp.Message));
-                       if(SCptr->SCp.Message == COMMAND_COMPLETE) {
-                               ESPSTAT(("and was COMMAND_COMPLETE\n"));
-                               esp_advance_phase(SCptr, in_freeing);
-                               return esp_do_freebus(esp, eregs);
-                       } else {
-                               ESPLOG(("esp%d: and _not_ COMMAND_COMPLETE\n",
-                                       esp->esp_id));
-                               esp->msgin_len = esp->msgin_ctr = 1;
-                               esp_advance_phase(SCptr, in_msgindone);
-                               return esp_do_msgindone(esp, eregs);
-                       }
-               } else {
-                       /* With luck we'll be able to let the target
-                        * know that bad parity happened, it will know
-                        * which byte caused the problems and send it
-                        * again.  For the case where the status byte
-                        * receives bad parity, I do not believe most
-                        * targets recover very well.  We'll see.
-                        */
-                       ESPLOG(("esp%d: bad parity somewhere mout=%2x\n",
-                               esp->esp_id, message_out));
-                       esp->cur_msgout[0] = message_out;
-                       esp->msgout_len = esp->msgout_ctr = 1;
-                       esp_advance_phase(SCptr, in_the_dark);
-                       return esp_do_phase_determine(esp, eregs);
-               }
-       } else {
-               /* If we disconnect now, all hell breaks loose. */
-               ESPLOG(("esp%d: whoops, disconnect\n", esp->esp_id));
-               esp_advance_phase(SCptr, in_the_dark);
-               return esp_do_phase_determine(esp, eregs);
-       }
-}
-
-static int esp_enter_status(struct NCR_ESP *esp,
-                           struct ESP_regs *eregs)
-{
-       unchar thecmd = ESP_CMD_ICCSEQ;
-
-       esp_cmd(esp, eregs, ESP_CMD_FLUSH);
-
-       if(esp->do_pio_cmds) {
-               esp_advance_phase(esp->current_SC, in_status);
-               esp_cmd(esp, eregs, thecmd);
-               while(!(esp_read(esp->eregs->esp_status) & ESP_STAT_INTR));
-               esp->esp_command[0] = esp_read(eregs->esp_fdata);
-                while(!(esp_read(esp->eregs->esp_status) & ESP_STAT_INTR));
-                esp->esp_command[1] = esp_read(eregs->esp_fdata);
-       } else {
-               esp->esp_command[0] = esp->esp_command[1] = 0xff;
-               esp_write(eregs->esp_tclow, 2);
-               esp_write(eregs->esp_tcmed, 0);
-               esp->dma_init_read(esp, esp->esp_command_dvma, 2);
-               thecmd |= ESP_CMD_DMA;
-               esp_cmd(esp, eregs, thecmd);
-               esp_advance_phase(esp->current_SC, in_status);
-       }
-
-       return esp_do_status(esp, eregs);
-}
-
-static int esp_disconnect_amidst_phases(struct NCR_ESP *esp,
-                                       struct ESP_regs *eregs)
-{
-       Scsi_Cmnd *sp = esp->current_SC;
-       struct esp_device *esp_dev = sp->device->hostdata;
-
-       /* This means real problems if we see this
-        * here.  Unless we were actually trying
-        * to force the device to abort/reset.
-        */
-       ESPLOG(("esp%d: Disconnect amidst phases, ", esp->esp_id));
-       ESPLOG(("pphase<%s> cphase<%s>, ",
-               phase_string(sp->SCp.phase),
-               phase_string(sp->SCp.sent_command)));
-
-       if(esp->disconnected_SC)
-               esp_cmd(esp, eregs, ESP_CMD_ESEL);
-
-       switch(esp->cur_msgout[0]) {
-       default:
-               /* We didn't expect this to happen at all. */
-               ESPLOG(("device is bolixed\n"));
-               esp_advance_phase(sp, in_tgterror);
-               esp_done(esp, (DID_ERROR << 16));
-               break;
-
-       case BUS_DEVICE_RESET:
-               ESPLOG(("device reset successful\n"));
-               esp_dev->sync_max_offset = 0;
-               esp_dev->sync_min_period = 0;
-               esp_dev->sync = 0;
-               esp_advance_phase(sp, in_resetdev);
-               esp_done(esp, (DID_RESET << 16));
-               break;
-
-       case ABORT:
-               ESPLOG(("device abort successful\n"));
-               esp_advance_phase(sp, in_abortone);
-               esp_done(esp, (DID_ABORT << 16));
-               break;
-
-       };
-       return do_intr_end;
-}
-
-static int esp_enter_msgout(struct NCR_ESP *esp,
-                           struct ESP_regs *eregs)
-{
-       esp_advance_phase(esp->current_SC, in_msgout);
-       return esp_do_msgout(esp, eregs);
-}
-
-static int esp_enter_msgin(struct NCR_ESP *esp,
-                          struct ESP_regs *eregs)
-{
-       esp_advance_phase(esp->current_SC, in_msgin);
-       return esp_do_msgin(esp, eregs);
-}
-
-static int esp_enter_cmd(struct NCR_ESP *esp,
-                        struct ESP_regs *eregs)
-{
-       esp_advance_phase(esp->current_SC, in_cmdbegin);
-       return esp_do_cmdbegin(esp, eregs);
-}
-
-static int esp_enter_badphase(struct NCR_ESP *esp,
-                             struct ESP_regs *eregs)
-{
-       ESPLOG(("esp%d: Bizarre bus phase %2x.\n", esp->esp_id,
-               esp->sreg & ESP_STAT_PMASK));
-       return do_reset_bus;
-}
-
-typedef int (*espfunc_t)(struct NCR_ESP *,
-                        struct ESP_regs *);
-
-static espfunc_t phase_vector[] = {
-       esp_do_data,            /* ESP_DOP */
-       esp_do_data,            /* ESP_DIP */
-       esp_enter_cmd,          /* ESP_CMDP */
-       esp_enter_status,       /* ESP_STATP */
-       esp_enter_badphase,     /* ESP_STAT_PMSG */
-       esp_enter_badphase,     /* ESP_STAT_PMSG | ESP_STAT_PIO */
-       esp_enter_msgout,       /* ESP_MOP */
-       esp_enter_msgin,        /* ESP_MIP */
-};
-
-/* The target has control of the bus and we have to see where it has
- * taken us.
- */
-static int esp_do_phase_determine(struct NCR_ESP *esp,
-                                 struct ESP_regs *eregs)
-{
-       if ((esp->ireg & ESP_INTR_DC) != 0)
-               return esp_disconnect_amidst_phases(esp, eregs);
-       return phase_vector[esp->sreg & ESP_STAT_PMASK](esp, eregs);
-}
-
-/* First interrupt after exec'ing a cmd comes here. */
-static int esp_select_complete(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       Scsi_Cmnd *SCptr = esp->current_SC;
-       struct esp_device *esp_dev = SCptr->device->hostdata;
-       int cmd_bytes_sent, fcnt;
-
-       fcnt = (esp_read(eregs->esp_fflags) & ESP_FF_FBYTES);
-       cmd_bytes_sent = esp->dma_bytes_sent(esp, fcnt);
-       if(esp->dma_invalidate)
-               esp->dma_invalidate(esp);
-
-       /* Let's check to see if a reselect happened
-        * while we we're trying to select.  This must
-        * be checked first.
-        */
-       if(esp->ireg == (ESP_INTR_RSEL | ESP_INTR_FDONE)) {
-               esp_reconnect(esp, SCptr);
-               return esp_do_reconnect(esp, eregs);
-       }
-
-       /* Looks like things worked, we should see a bus service &
-        * a function complete interrupt at this point.  Note we
-        * are doing a direct comparison because we don't want to
-        * be fooled into thinking selection was successful if
-        * ESP_INTR_DC is set, see below.
-        */
-       if(esp->ireg == (ESP_INTR_FDONE | ESP_INTR_BSERV)) {
-               /* target speaks... */
-               esp->targets_present |= (1<<scmd_id(SCptr));
-
-               /* What if the target ignores the sdtr? */
-               if(esp->snip)
-                       esp_dev->sync = 1;
-
-               /* See how far, if at all, we got in getting
-                * the information out to the target.
-                */
-               switch(esp->seqreg) {
-               default:
-
-               case ESP_STEP_ASEL:
-                       /* Arbitration won, target selected, but
-                        * we are in some phase which is not command
-                        * phase nor is it message out phase.
-                        *
-                        * XXX We've confused the target, obviously.
-                        * XXX So clear it's state, but we also end
-                        * XXX up clearing everyone elses.  That isn't
-                        * XXX so nice.  I'd like to just reset this
-                        * XXX target, but if I cannot even get it's
-                        * XXX attention and finish selection to talk
-                        * XXX to it, there is not much more I can do.
-                        * XXX If we have a loaded bus we're going to
-                        * XXX spend the next second or so renegotiating
-                        * XXX for synchronous transfers.
-                        */
-                       ESPLOG(("esp%d: STEP_ASEL for tgt %d\n",
-                               esp->esp_id, SCptr->device->id));
-
-               case ESP_STEP_SID:
-                       /* Arbitration won, target selected, went
-                        * to message out phase, sent one message
-                        * byte, then we stopped.  ATN is asserted
-                        * on the SCSI bus and the target is still
-                        * there hanging on.  This is a legal
-                        * sequence step if we gave the ESP a select
-                        * and stop command.
-                        *
-                        * XXX See above, I could set the borken flag
-                        * XXX in the device struct and retry the
-                        * XXX command.  But would that help for
-                        * XXX tagged capable targets?
-                        */
-
-               case ESP_STEP_NCMD:
-                       /* Arbitration won, target selected, maybe
-                        * sent the one message byte in message out
-                        * phase, but we did not go to command phase
-                        * in the end.  Actually, we could have sent
-                        * only some of the message bytes if we tried
-                        * to send out the entire identify and tag
-                        * message using ESP_CMD_SA3.
-                        */
-                       cmd_bytes_sent = 0;
-                       break;
-
-               case ESP_STEP_PPC:
-                       /* No, not the powerPC pinhead.  Arbitration
-                        * won, all message bytes sent if we went to
-                        * message out phase, went to command phase
-                        * but only part of the command was sent.
-                        *
-                        * XXX I've seen this, but usually in conjunction
-                        * XXX with a gross error which appears to have
-                        * XXX occurred between the time I told the
-                        * XXX ESP to arbitrate and when I got the
-                        * XXX interrupt.  Could I have misloaded the
-                        * XXX command bytes into the fifo?  Actually,
-                        * XXX I most likely missed a phase, and therefore
-                        * XXX went into never never land and didn't even
-                        * XXX know it.  That was the old driver though.
-                        * XXX What is even more peculiar is that the ESP
-                        * XXX showed the proper function complete and
-                        * XXX bus service bits in the interrupt register.
-                        */
-
-               case ESP_STEP_FINI4:
-               case ESP_STEP_FINI5:
-               case ESP_STEP_FINI6:
-               case ESP_STEP_FINI7:
-                       /* Account for the identify message */
-                       if(SCptr->SCp.phase == in_slct_norm)
-                               cmd_bytes_sent -= 1;
-               };
-               esp_cmd(esp, eregs, ESP_CMD_NULL);
-
-               /* Be careful, we could really get fucked during synchronous
-                * data transfers if we try to flush the fifo now.
-                */
-               if(!fcnt && /* Fifo is empty and... */
-                  /* either we are not doing synchronous transfers or... */
-                  (!esp_dev->sync_max_offset ||
-                   /* We are not going into data in phase. */
-                   ((esp->sreg & ESP_STAT_PMASK) != ESP_DIP)))
-                       esp_cmd(esp, eregs, ESP_CMD_FLUSH); /* flush is safe */
-
-               /* See how far we got if this is not a slow command. */
-               if(!esp->esp_slowcmd) {
-                       if(cmd_bytes_sent < 0)
-                               cmd_bytes_sent = 0;
-                       if(cmd_bytes_sent != SCptr->cmd_len) {
-                               /* Crapola, mark it as a slowcmd
-                                * so that we have some chance of
-                                * keeping the command alive with
-                                * good luck.
-                                *
-                                * XXX Actually, if we didn't send it all
-                                * XXX this means either we didn't set things
-                                * XXX up properly (driver bug) or the target
-                                * XXX or the ESP detected parity on one of
-                                * XXX the command bytes.  This makes much
-                                * XXX more sense, and therefore this code
-                                * XXX should be changed to send out a
-                                * XXX parity error message or if the status
-                                * XXX register shows no parity error then
-                                * XXX just expect the target to bring the
-                                * XXX bus into message in phase so that it
-                                * XXX can send us the parity error message.
-                                * XXX SCSI sucks...
-                                */
-                               esp->esp_slowcmd = 1;
-                               esp->esp_scmdp = &(SCptr->cmnd[cmd_bytes_sent]);
-                               esp->esp_scmdleft = (SCptr->cmd_len - cmd_bytes_sent);
-                       }
-               }
-
-               /* Now figure out where we went. */
-               esp_advance_phase(SCptr, in_the_dark);
-               return esp_do_phase_determine(esp, eregs);
-       }
-
-       /* Did the target even make it? */
-       if(esp->ireg == ESP_INTR_DC) {
-               /* wheee... nobody there or they didn't like
-                * what we told it to do, clean up.
-                */
-
-               /* If anyone is off the bus, but working on
-                * a command in the background for us, tell
-                * the ESP to listen for them.
-                */
-               if(esp->disconnected_SC)
-                       esp_cmd(esp, eregs, ESP_CMD_ESEL);
-
-               if(((1<<SCptr->device->id) & esp->targets_present) &&
-                  esp->seqreg && esp->cur_msgout[0] == EXTENDED_MESSAGE &&
-                  (SCptr->SCp.phase == in_slct_msg ||
-                   SCptr->SCp.phase == in_slct_stop)) {
-                       /* shit */
-                       esp->snip = 0;
-                       ESPLOG(("esp%d: Failed synchronous negotiation for target %d "
-                               "lun %d\n", esp->esp_id, SCptr->device->id, SCptr->device->lun));
-                       esp_dev->sync_max_offset = 0;
-                       esp_dev->sync_min_period = 0;
-                       esp_dev->sync = 1; /* so we don't negotiate again */
-
-                       /* Run the command again, this time though we
-                        * won't try to negotiate for synchronous transfers.
-                        *
-                        * XXX I'd like to do something like send an
-                        * XXX INITIATOR_ERROR or ABORT message to the
-                        * XXX target to tell it, "Sorry I confused you,
-                        * XXX please come back and I will be nicer next
-                        * XXX time".  But that requires having the target
-                        * XXX on the bus, and it has dropped BSY on us.
-                        */
-                       esp->current_SC = NULL;
-                       esp_advance_phase(SCptr, not_issued);
-                       prepend_SC(&esp->issue_SC, SCptr);
-                       esp_exec_cmd(esp);
-                       return do_intr_end;
-               }
-
-               /* Ok, this is normal, this is what we see during boot
-                * or whenever when we are scanning the bus for targets.
-                * But first make sure that is really what is happening.
-                */
-               if(((1<<SCptr->device->id) & esp->targets_present)) {
-                       ESPLOG(("esp%d: Warning, live target %d not responding to "
-                               "selection.\n", esp->esp_id, SCptr->device->id));
-
-                       /* This _CAN_ happen.  The SCSI standard states that
-                        * the target is to _not_ respond to selection if
-                        * _it_ detects bad parity on the bus for any reason.
-                        * Therefore, we assume that if we've talked successfully
-                        * to this target before, bad parity is the problem.
-                        */
-                       esp_done(esp, (DID_PARITY << 16));
-               } else {
-                       /* Else, there really isn't anyone there. */
-                       ESPMISC(("esp: selection failure, maybe nobody there?\n"));
-                       ESPMISC(("esp: target %d lun %d\n",
-                                SCptr->device->id, SCptr->device->lun));
-                       esp_done(esp, (DID_BAD_TARGET << 16));
-               }
-               return do_intr_end;
-       }
-
-
-       ESPLOG(("esp%d: Selection failure.\n", esp->esp_id));
-       printk("esp%d: Currently -- ", esp->esp_id);
-       esp_print_ireg(esp->ireg);
-       printk(" ");
-       esp_print_statreg(esp->sreg);
-       printk(" ");
-       esp_print_seqreg(esp->seqreg);
-       printk("\n");
-       printk("esp%d: New -- ", esp->esp_id);
-       esp->sreg = esp_read(eregs->esp_status);
-       esp->seqreg = esp_read(eregs->esp_sstep);
-       esp->ireg = esp_read(eregs->esp_intrpt);
-       esp_print_ireg(esp->ireg);
-       printk(" ");
-       esp_print_statreg(esp->sreg);
-       printk(" ");
-       esp_print_seqreg(esp->seqreg);
-       printk("\n");
-       ESPLOG(("esp%d: resetting bus\n", esp->esp_id));
-       return do_reset_bus; /* ugh... */
-}
-
-/* Continue reading bytes for msgin phase. */
-static int esp_do_msgincont(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       if(esp->ireg & ESP_INTR_BSERV) {
-               /* in the right phase too? */
-               if((esp->sreg & ESP_STAT_PMASK) == ESP_MIP) {
-                       /* phew... */
-                       esp_cmd(esp, eregs, ESP_CMD_TI);
-                       esp_advance_phase(esp->current_SC, in_msgindone);
-                       return do_intr_end;
-               }
-
-               /* We changed phase but ESP shows bus service,
-                * in this case it is most likely that we, the
-                * hacker who has been up for 20hrs straight
-                * staring at the screen, drowned in coffee
-                * smelling like retched cigarette ashes
-                * have miscoded something..... so, try to
-                * recover as best we can.
-                */
-               ESPLOG(("esp%d: message in mis-carriage.\n", esp->esp_id));
-       }
-       esp_advance_phase(esp->current_SC, in_the_dark);
-       return do_phase_determine;
-}
-
-static int check_singlebyte_msg(struct NCR_ESP *esp,
-                               struct ESP_regs *eregs)
-{
-       esp->prevmsgin = esp->cur_msgin[0];
-       if(esp->cur_msgin[0] & 0x80) {
-               /* wheee... */
-               ESPLOG(("esp%d: target sends identify amidst phases\n",
-                       esp->esp_id));
-               esp_advance_phase(esp->current_SC, in_the_dark);
-               return 0;
-       } else if(((esp->cur_msgin[0] & 0xf0) == 0x20) ||
-                 (esp->cur_msgin[0] == EXTENDED_MESSAGE)) {
-               esp->msgin_len = 2;
-               esp_advance_phase(esp->current_SC, in_msgincont);
-               return 0;
-       }
-       esp_advance_phase(esp->current_SC, in_the_dark);
-       switch(esp->cur_msgin[0]) {
-       default:
-               /* We don't want to hear about it. */
-               ESPLOG(("esp%d: msg %02x which we don't know about\n", esp->esp_id,
-                       esp->cur_msgin[0]));
-               return MESSAGE_REJECT;
-
-       case NOP:
-               ESPLOG(("esp%d: target %d sends a nop\n", esp->esp_id,
-                       esp->current_SC->device->id));
-               return 0;
-
-       case RESTORE_POINTERS:
-               /* In this case we might also have to backup the
-                * "slow command" pointer.  It is rare to get such
-                * a save/restore pointer sequence so early in the
-                * bus transition sequences, but cover it.
-                */
-               if(esp->esp_slowcmd) {
-                       esp->esp_scmdleft = esp->current_SC->cmd_len;
-                       esp->esp_scmdp = &esp->current_SC->cmnd[0];
-               }
-               esp_restore_pointers(esp, esp->current_SC);
-               return 0;
-
-       case SAVE_POINTERS:
-               esp_save_pointers(esp, esp->current_SC);
-               return 0;
-
-       case COMMAND_COMPLETE:
-       case DISCONNECT:
-               /* Freeing the bus, let it go. */
-               esp->current_SC->SCp.phase = in_freeing;
-               return 0;
-
-       case MESSAGE_REJECT:
-               ESPMISC(("msg reject, "));
-               if(esp->prevmsgout == EXTENDED_MESSAGE) {
-                       struct esp_device *esp_dev = esp->current_SC->device->hostdata;
-
-                       /* Doesn't look like this target can
-                        * do synchronous or WIDE transfers.
-                        */
-                       ESPSDTR(("got reject, was trying nego, clearing sync/WIDE\n"));
-                       esp_dev->sync = 1;
-                       esp_dev->wide = 1;
-                       esp_dev->sync_min_period = 0;
-                       esp_dev->sync_max_offset = 0;
-                       return 0;
-               } else {
-                       ESPMISC(("not sync nego, sending ABORT\n"));
-                       return ABORT;
-               }
-       };
-}
-
-/* Target negotiates for synchronous transfers before we do, this
- * is legal although very strange.  What is even funnier is that
- * the SCSI2 standard specifically recommends against targets doing
- * this because so many initiators cannot cope with this occurring.
- */
-static int target_with_ants_in_pants(struct NCR_ESP *esp,
-                                    Scsi_Cmnd *SCptr,
-                                    struct esp_device *esp_dev)
-{
-       if(esp_dev->sync || SCptr->device->borken) {
-               /* sorry, no can do */
-               ESPSDTR(("forcing to async, "));
-               build_sync_nego_msg(esp, 0, 0);
-               esp_dev->sync = 1;
-               esp->snip = 1;
-               ESPLOG(("esp%d: hoping for msgout\n", esp->esp_id));
-               esp_advance_phase(SCptr, in_the_dark);
-               return EXTENDED_MESSAGE;
-       }
-
-       /* Ok, we'll check them out... */
-       return 0;
-}
-
-static void sync_report(struct NCR_ESP *esp)
-{
-       int msg3, msg4;
-       char *type;
-
-       msg3 = esp->cur_msgin[3];
-       msg4 = esp->cur_msgin[4];
-       if(msg4) {
-               int hz = 1000000000 / (msg3 * 4);
-               int integer = hz / 1000000;
-               int fraction = (hz - (integer * 1000000)) / 10000;
-               if((msg3 * 4) < 200) {
-                       type = "FAST";
-               } else {
-                       type = "synchronous";
-               }
-
-               /* Do not transform this back into one big printk
-                * again, it triggers a bug in our sparc64-gcc272
-                * sibling call optimization.  -DaveM
-                */
-               ESPLOG((KERN_INFO "esp%d: target %d ",
-                       esp->esp_id, esp->current_SC->device->id));
-               ESPLOG(("[period %dns offset %d %d.%02dMHz ",
-                       (int) msg3 * 4, (int) msg4,
-                       integer, fraction));
-               ESPLOG(("%s SCSI%s]\n", type,
-                       (((msg3 * 4) < 200) ? "-II" : "")));
-       } else {
-               ESPLOG((KERN_INFO "esp%d: target %d asynchronous\n",
-                       esp->esp_id, esp->current_SC->device->id));
-       }
-}
-
-static int check_multibyte_msg(struct NCR_ESP *esp,
-                              struct ESP_regs *eregs)
-{
-       Scsi_Cmnd *SCptr = esp->current_SC;
-       struct esp_device *esp_dev = SCptr->device->hostdata;
-       unchar regval = 0;
-       int message_out = 0;
-
-       ESPSDTR(("chk multibyte msg: "));
-       if(esp->cur_msgin[2] == EXTENDED_SDTR) {
-               int period = esp->cur_msgin[3];
-               int offset = esp->cur_msgin[4];
-
-               ESPSDTR(("is sync nego response, "));
-               if(!esp->snip) {
-                       int rval;
-
-                       /* Target negotiates first! */
-                       ESPSDTR(("target jumps the gun, "));
-                       message_out = EXTENDED_MESSAGE; /* we must respond */
-                       rval = target_with_ants_in_pants(esp, SCptr, esp_dev);
-                       if(rval)
-                               return rval;
-               }
-
-               ESPSDTR(("examining sdtr, "));
-
-               /* Offset cannot be larger than ESP fifo size. */
-               if(offset > 15) {
-                       ESPSDTR(("offset too big %2x, ", offset));
-                       offset = 15;
-                       ESPSDTR(("sending back new offset\n"));
-                       build_sync_nego_msg(esp, period, offset);
-                       return EXTENDED_MESSAGE;
-               }
-
-               if(offset && period > esp->max_period) {
-                       /* Yeee, async for this slow device. */
-                       ESPSDTR(("period too long %2x, ", period));
-                       build_sync_nego_msg(esp, 0, 0);
-                       ESPSDTR(("hoping for msgout\n"));
-                       esp_advance_phase(esp->current_SC, in_the_dark);
-                       return EXTENDED_MESSAGE;
-               } else if (offset && period < esp->min_period) {
-                       ESPSDTR(("period too short %2x, ", period));
-                       period = esp->min_period;
-                       if(esp->erev > esp236)
-                               regval = 4;
-                       else
-                               regval = 5;
-               } else if(offset) {
-                       int tmp;
-
-                       ESPSDTR(("period is ok, "));
-                       tmp = esp->ccycle / 1000;
-                       regval = (((period << 2) + tmp - 1) / tmp);
-                       if(regval && (esp->erev > esp236)) {
-                               if(period >= 50)
-                                       regval--;
-                       }
-               }
-
-               if(offset) {
-                       unchar bit;
-
-                       esp_dev->sync_min_period = (regval & 0x1f);
-                       esp_dev->sync_max_offset = (offset | esp->radelay);
-                       if(esp->erev > esp236) {
-                               if(esp->erev == fas100a)
-                                       bit = ESP_CONFIG3_FAST;
-                               else
-                                       bit = ESP_CONFIG3_FSCSI;
-                               if(period < 50)
-                                       esp->config3[SCptr->device->id] |= bit;
-                               else
-                                       esp->config3[SCptr->device->id] &= ~bit;
-                               esp->prev_cfg3 = esp->config3[SCptr->device->id];
-                               esp_write(eregs->esp_cfg3, esp->prev_cfg3);
-                       }
-                       esp->prev_soff = esp_dev->sync_min_period;
-                       esp_write(eregs->esp_soff, esp->prev_soff);
-                       esp->prev_stp = esp_dev->sync_max_offset;
-                       esp_write(eregs->esp_stp, esp->prev_stp);
-
-                       ESPSDTR(("soff=%2x stp=%2x cfg3=%2x\n",
-                               esp_dev->sync_max_offset,
-                               esp_dev->sync_min_period,
-                               esp->config3[scmd_id(SCptr)]));
-
-                       esp->snip = 0;
-               } else if(esp_dev->sync_max_offset) {
-                       unchar bit;
-
-                       /* back to async mode */
-                       ESPSDTR(("unaccaptable sync nego, forcing async\n"));
-                       esp_dev->sync_max_offset = 0;
-                       esp_dev->sync_min_period = 0;
-                       esp->prev_soff = 0;
-                       esp_write(eregs->esp_soff, 0);
-                       esp->prev_stp = 0;
-                       esp_write(eregs->esp_stp, 0);
-                       if(esp->erev > esp236) {
-                               if(esp->erev == fas100a)
-                                       bit = ESP_CONFIG3_FAST;
-                               else
-                                       bit = ESP_CONFIG3_FSCSI;
-                               esp->config3[SCptr->device->id] &= ~bit;
-                               esp->prev_cfg3 = esp->config3[SCptr->device->id];
-                               esp_write(eregs->esp_cfg3, esp->prev_cfg3);
-                       }
-               }
-
-               sync_report(esp);
-
-               ESPSDTR(("chk multibyte msg: sync is known, "));
-               esp_dev->sync = 1;
-
-               if(message_out) {
-                       ESPLOG(("esp%d: sending sdtr back, hoping for msgout\n",
-                               esp->esp_id));
-                       build_sync_nego_msg(esp, period, offset);
-                       esp_advance_phase(SCptr, in_the_dark);
-                       return EXTENDED_MESSAGE;
-               }
-
-               ESPSDTR(("returning zero\n"));
-               esp_advance_phase(SCptr, in_the_dark); /* ...or else! */
-               return 0;
-       } else if(esp->cur_msgin[2] == EXTENDED_WDTR) {
-               ESPLOG(("esp%d: AIEEE wide msg received\n", esp->esp_id));
-               message_out = MESSAGE_REJECT;
-       } else if(esp->cur_msgin[2] == EXTENDED_MODIFY_DATA_POINTER) {
-               ESPLOG(("esp%d: rejecting modify data ptr msg\n", esp->esp_id));
-               message_out = MESSAGE_REJECT;
-       }
-       esp_advance_phase(SCptr, in_the_dark);
-       return message_out;
-}
-
-static int esp_do_msgindone(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       Scsi_Cmnd *SCptr = esp->current_SC;
-       int message_out = 0, it = 0, rval;
-
-       rval = skipahead1(esp, eregs, SCptr, in_msgin, in_msgindone);
-       if(rval)
-               return rval;
-       if(SCptr->SCp.sent_command != in_status) {
-               if(!(esp->ireg & ESP_INTR_DC)) {
-                       if(esp->msgin_len && (esp->sreg & ESP_STAT_PERR)) {
-                               message_out = MSG_PARITY_ERROR;
-                               esp_cmd(esp, eregs, ESP_CMD_FLUSH);
-                       } else if((it = (esp_read(eregs->esp_fflags) & ESP_FF_FBYTES))!=1) {
-                               /* We certainly dropped the ball somewhere. */
-                               message_out = INITIATOR_ERROR;
-                               esp_cmd(esp, eregs, ESP_CMD_FLUSH);
-                       } else if(!esp->msgin_len) {
-                               it = esp_read(eregs->esp_fdata);
-                               esp_advance_phase(SCptr, in_msgincont);
-                       } else {
-                               /* it is ok and we want it */
-                               it = esp->cur_msgin[esp->msgin_ctr] =
-                                       esp_read(eregs->esp_fdata);
-                               esp->msgin_ctr++;
-                       }
-               } else {
-                       esp_advance_phase(SCptr, in_the_dark);
-                       return do_work_bus;
-               }
-       } else {
-               it = esp->cur_msgin[0];
-       }
-       if(!message_out && esp->msgin_len) {
-               if(esp->msgin_ctr < esp->msgin_len) {
-                       esp_advance_phase(SCptr, in_msgincont);
-               } else if(esp->msgin_len == 1) {
-                       message_out = check_singlebyte_msg(esp, eregs);
-               } else if(esp->msgin_len == 2) {
-                       if(esp->cur_msgin[0] == EXTENDED_MESSAGE) {
-                               if((it+2) >= 15) {
-                                       message_out = MESSAGE_REJECT;
-                               } else {
-                                       esp->msgin_len = (it + 2);
-                                       esp_advance_phase(SCptr, in_msgincont);
-                               }
-                       } else {
-                               message_out = MESSAGE_REJECT; /* foo on you */
-                       }
-               } else {
-                       message_out = check_multibyte_msg(esp, eregs);
-               }
-       }
-       if(message_out < 0) {
-               return -message_out;
-       } else if(message_out) {
-               if(((message_out != 1) &&
-                   ((message_out < 0x20) || (message_out & 0x80))))
-                       esp->msgout_len = 1;
-               esp->cur_msgout[0] = message_out;
-               esp_cmd(esp, eregs, ESP_CMD_SATN);
-               esp_advance_phase(SCptr, in_the_dark);
-               esp->msgin_len = 0;
-       }
-       esp->sreg = esp_read(eregs->esp_status);
-       esp->sreg &= ~(ESP_STAT_INTR);
-       if((esp->sreg & (ESP_STAT_PMSG|ESP_STAT_PCD)) == (ESP_STAT_PMSG|ESP_STAT_PCD))
-               esp_cmd(esp, eregs, ESP_CMD_MOK);
-       if((SCptr->SCp.sent_command == in_msgindone) &&
-           (SCptr->SCp.phase == in_freeing))
-               return esp_do_freebus(esp, eregs);
-       return do_intr_end;
-}
-
-static int esp_do_cmdbegin(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       unsigned char tmp;
-       Scsi_Cmnd *SCptr = esp->current_SC;
-
-       esp_advance_phase(SCptr, in_cmdend);
-       esp_cmd(esp, eregs, ESP_CMD_FLUSH);
-       tmp = *esp->esp_scmdp++;
-       esp->esp_scmdleft--;
-       esp_write(eregs->esp_fdata, tmp);
-       esp_cmd(esp, eregs, ESP_CMD_TI);
-       return do_intr_end;
-}
-
-static int esp_do_cmddone(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       esp_cmd(esp, eregs, ESP_CMD_NULL);
-       if(esp->ireg & ESP_INTR_BSERV) {
-               esp_advance_phase(esp->current_SC, in_the_dark);
-               return esp_do_phase_determine(esp, eregs);
-       }
-       ESPLOG(("esp%d: in do_cmddone() but didn't get BSERV interrupt.\n",
-               esp->esp_id));
-       return do_reset_bus;
-}
-
-static int esp_do_msgout(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       esp_cmd(esp, eregs, ESP_CMD_FLUSH);
-       switch(esp->msgout_len) {
-       case 1:
-               esp_write(eregs->esp_fdata, esp->cur_msgout[0]);
-               esp_cmd(esp, eregs, ESP_CMD_TI);
-               break;
-
-       case 2:
-               if(esp->do_pio_cmds){
-                       esp_write(eregs->esp_fdata, esp->cur_msgout[0]);
-                       esp_write(eregs->esp_fdata, esp->cur_msgout[1]);
-                       esp_cmd(esp, eregs, ESP_CMD_TI);
-               } else {
-                       esp->esp_command[0] = esp->cur_msgout[0];
-                       esp->esp_command[1] = esp->cur_msgout[1];
-                       esp->dma_setup(esp, esp->esp_command_dvma, 2, 0);
-                       esp_setcount(eregs, 2);
-                       esp_cmd(esp, eregs, ESP_CMD_DMA | ESP_CMD_TI);
-               }
-               break;
-
-       case 4:
-               esp->snip = 1;
-               if(esp->do_pio_cmds){
-                       esp_write(eregs->esp_fdata, esp->cur_msgout[0]);
-                       esp_write(eregs->esp_fdata, esp->cur_msgout[1]);
-                       esp_write(eregs->esp_fdata, esp->cur_msgout[2]);
-                       esp_write(eregs->esp_fdata, esp->cur_msgout[3]);
-                       esp_cmd(esp, eregs, ESP_CMD_TI);
-               } else {
-                       esp->esp_command[0] = esp->cur_msgout[0];
-                       esp->esp_command[1] = esp->cur_msgout[1];
-                       esp->esp_command[2] = esp->cur_msgout[2];
-                       esp->esp_command[3] = esp->cur_msgout[3];
-                       esp->dma_setup(esp, esp->esp_command_dvma, 4, 0);
-                       esp_setcount(eregs, 4);
-                       esp_cmd(esp, eregs, ESP_CMD_DMA | ESP_CMD_TI);
-               }
-               break;
-
-       case 5:
-               esp->snip = 1;
-               if(esp->do_pio_cmds){
-                       esp_write(eregs->esp_fdata, esp->cur_msgout[0]);
-                       esp_write(eregs->esp_fdata, esp->cur_msgout[1]);
-                       esp_write(eregs->esp_fdata, esp->cur_msgout[2]);
-                       esp_write(eregs->esp_fdata, esp->cur_msgout[3]);
-                       esp_write(eregs->esp_fdata, esp->cur_msgout[4]);
-                       esp_cmd(esp, eregs, ESP_CMD_TI);
-               } else {
-                       esp->esp_command[0] = esp->cur_msgout[0];
-                       esp->esp_command[1] = esp->cur_msgout[1];
-                       esp->esp_command[2] = esp->cur_msgout[2];
-                       esp->esp_command[3] = esp->cur_msgout[3];
-                       esp->esp_command[4] = esp->cur_msgout[4];
-                       esp->dma_setup(esp, esp->esp_command_dvma, 5, 0);
-                       esp_setcount(eregs, 5);
-                       esp_cmd(esp, eregs, ESP_CMD_DMA | ESP_CMD_TI);
-               }
-               break;
-
-       default:
-               /* whoops */
-               ESPMISC(("bogus msgout sending NOP\n"));
-               esp->cur_msgout[0] = NOP;
-               esp_write(eregs->esp_fdata, esp->cur_msgout[0]);
-               esp->msgout_len = 1;
-               esp_cmd(esp, eregs, ESP_CMD_TI);
-               break;
-       }
-       esp_advance_phase(esp->current_SC, in_msgoutdone);
-       return do_intr_end;
-}
-
-static int esp_do_msgoutdone(struct NCR_ESP *esp, 
-                            struct ESP_regs *eregs)
-{
-       if((esp->msgout_len > 1) && esp->dma_barrier)
-               esp->dma_barrier(esp);
-
-       if(!(esp->ireg & ESP_INTR_DC)) {
-               esp_cmd(esp, eregs, ESP_CMD_NULL);
-               switch(esp->sreg & ESP_STAT_PMASK) {
-               case ESP_MOP:
-                       /* whoops, parity error */
-                       ESPLOG(("esp%d: still in msgout, parity error assumed\n",
-                               esp->esp_id));
-                       if(esp->msgout_len > 1)
-                               esp_cmd(esp, eregs, ESP_CMD_SATN);
-                       esp_advance_phase(esp->current_SC, in_msgout);
-                       return do_work_bus;
-
-               case ESP_DIP:
-                       break;
-
-               default:
-                       if(!fcount(esp, eregs) &&
-                          !(((struct esp_device *)esp->current_SC->device->hostdata)->sync_max_offset))
-                               esp_cmd(esp, eregs, ESP_CMD_FLUSH);
-                       break;
-
-               };
-       }
-
-       /* If we sent out a synchronous negotiation message, update
-        * our state.
-        */
-       if(esp->cur_msgout[2] == EXTENDED_MESSAGE &&
-          esp->cur_msgout[4] == EXTENDED_SDTR) {
-               esp->snip = 1; /* anal retentiveness... */
-       }
-
-       esp->prevmsgout = esp->cur_msgout[0];
-       esp->msgout_len = 0;
-       esp_advance_phase(esp->current_SC, in_the_dark);
-       return esp_do_phase_determine(esp, eregs);
-}
-
-static int esp_bus_unexpected(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       ESPLOG(("esp%d: command in weird state %2x\n",
-               esp->esp_id, esp->current_SC->SCp.phase));
-       return do_reset_bus;
-}
-
-static espfunc_t bus_vector[] = {
-       esp_do_data_finale,
-       esp_do_data_finale,
-       esp_bus_unexpected,
-       esp_do_msgin,
-       esp_do_msgincont,
-       esp_do_msgindone,
-       esp_do_msgout,
-       esp_do_msgoutdone,
-       esp_do_cmdbegin,
-       esp_do_cmddone,
-       esp_do_status,
-       esp_do_freebus,
-       esp_do_phase_determine,
-       esp_bus_unexpected,
-       esp_bus_unexpected,
-       esp_bus_unexpected,
-};
-
-/* This is the second tier in our dual-level SCSI state machine. */
-static int esp_work_bus(struct NCR_ESP *esp, struct ESP_regs *eregs)
-{
-       Scsi_Cmnd *SCptr = esp->current_SC;
-       unsigned int phase;
-
-       ESPBUS(("esp_work_bus: "));
-       if(!SCptr) {
-               ESPBUS(("reconnect\n"));
-               return esp_do_reconnect(esp, eregs);
-       }
-       phase = SCptr->SCp.phase;
-       if ((phase & 0xf0) == in_phases_mask)
-               return bus_vector[(phase & 0x0f)](esp, eregs);
-       else if((phase & 0xf0) == in_slct_mask)
-               return esp_select_complete(esp, eregs);
-       else
-               return esp_bus_unexpected(esp, eregs);
-}
-
-static espfunc_t isvc_vector[] = {
-       NULL,
-       esp_do_phase_determine,
-       esp_do_resetbus,
-       esp_finish_reset,
-       esp_work_bus
-};
-
-/* Main interrupt handler for an esp adapter. */
-void esp_handle(struct NCR_ESP *esp)
-{
-       struct ESP_regs *eregs;
-       Scsi_Cmnd *SCptr;
-       int what_next = do_intr_end;
-       eregs = esp->eregs;
-       SCptr = esp->current_SC;
-
-       if(esp->dma_irq_entry)
-               esp->dma_irq_entry(esp);
-
-       /* Check for errors. */
-       esp->sreg = esp_read(eregs->esp_status);
-       esp->sreg &= (~ESP_STAT_INTR);
-       esp->seqreg = (esp_read(eregs->esp_sstep) & ESP_STEP_VBITS);
-       esp->ireg = esp_read(eregs->esp_intrpt);   /* Unlatch intr and stat regs */
-       ESPIRQ(("handle_irq: [sreg<%02x> sstep<%02x> ireg<%02x>]\n",
-               esp->sreg, esp->seqreg, esp->ireg));
-       if(esp->sreg & (ESP_STAT_SPAM)) {
-               /* Gross error, could be due to one of:
-                *
-                * - top of fifo overwritten, could be because
-                *   we tried to do a synchronous transfer with
-                *   an offset greater than ESP fifo size
-                *
-                * - top of command register overwritten
-                *
-                * - DMA setup to go in one direction, SCSI
-                *   bus points in the other, whoops
-                *
-                * - weird phase change during asynchronous
-                *   data phase while we are initiator
-                */
-               ESPLOG(("esp%d: Gross error sreg=%2x\n", esp->esp_id, esp->sreg));
-
-               /* If a command is live on the bus we cannot safely
-                * reset the bus, so we'll just let the pieces fall
-                * where they may.  Here we are hoping that the
-                * target will be able to cleanly go away soon
-                * so we can safely reset things.
-                */
-               if(!SCptr) {
-                       ESPLOG(("esp%d: No current cmd during gross error, "
-                               "resetting bus\n", esp->esp_id));
-                       what_next = do_reset_bus;
-                       goto state_machine;
-               }
-       }
-
-       /* No current cmd is only valid at this point when there are
-        * commands off the bus or we are trying a reset.
-        */
-       if(!SCptr && !esp->disconnected_SC && !(esp->ireg & ESP_INTR_SR)) {
-               /* Panic is safe, since current_SC is null. */
-               ESPLOG(("esp%d: no command in esp_handle()\n", esp->esp_id));
-               panic("esp_handle: current_SC == penguin within interrupt!");
-       }
-
-       if(esp->ireg & (ESP_INTR_IC)) {
-               /* Illegal command fed to ESP.  Outside of obvious
-                * software bugs that could cause this, there is
-                * a condition with ESP100 where we can confuse the
-                * ESP into an erroneous illegal command interrupt
-                * because it does not scrape the FIFO properly
-                * for reselection.  See esp100_reconnect_hwbug()
-                * to see how we try very hard to avoid this.
-                */
-               ESPLOG(("esp%d: invalid command\n", esp->esp_id));
-
-               esp_dump_state(esp, eregs);
-
-               if(SCptr) {
-                       /* Devices with very buggy firmware can drop BSY
-                        * during a scatter list interrupt when using sync
-                        * mode transfers.  We continue the transfer as
-                        * expected, the target drops the bus, the ESP
-                        * gets confused, and we get a illegal command
-                        * interrupt because the bus is in the disconnected
-                        * state now and ESP_CMD_TI is only allowed when
-                        * a nexus is alive on the bus.
-                        */
-                       ESPLOG(("esp%d: Forcing async and disabling disconnect for "
-                               "target %d\n", esp->esp_id, SCptr->device->id));
-                       SCptr->device->borken = 1; /* foo on you */
-               }
-
-               what_next = do_reset_bus;
-       } else if(!(esp->ireg & ~(ESP_INTR_FDONE | ESP_INTR_BSERV | ESP_INTR_DC))) {
-               int phase;
-
-               if(SCptr) {
-                       phase = SCptr->SCp.phase;
-                       if(phase & in_phases_mask) {
-                               what_next = esp_work_bus(esp, eregs);
-                       } else if(phase & in_slct_mask) {
-                               what_next = esp_select_complete(esp, eregs);
-                       } else {
-                               ESPLOG(("esp%d: interrupt for no good reason...\n",
-                                       esp->esp_id));
-                               what_next = do_intr_end;
-                       }
-               } else {
-                       ESPLOG(("esp%d: BSERV or FDONE or DC while SCptr==NULL\n",
-                               esp->esp_id));
-                       what_next = do_reset_bus;
-               }
-       } else if(esp->ireg & ESP_INTR_SR) {
-               ESPLOG(("esp%d: SCSI bus reset interrupt\n", esp->esp_id));
-               what_next = do_reset_complete;
-       } else if(esp->ireg & (ESP_INTR_S | ESP_INTR_SATN)) {
-               ESPLOG(("esp%d: AIEEE we have been selected by another initiator!\n",
-                       esp->esp_id));
-               what_next = do_reset_bus;
-       } else if(esp->ireg & ESP_INTR_RSEL) {
-               if(!SCptr) {
-                       /* This is ok. */
-                       what_next = esp_do_reconnect(esp, eregs);
-               } else if(SCptr->SCp.phase & in_slct_mask) {
-                       /* Only selection code knows how to clean
-                        * up properly.
-                        */
-                       ESPDISC(("Reselected during selection attempt\n"));
-                       what_next = esp_select_complete(esp, eregs);
-               } else {
-                       ESPLOG(("esp%d: Reselected while bus is busy\n",
-                               esp->esp_id));
-                       what_next = do_reset_bus;
-               }
-       }
-
-       /* This is tier-one in our dual level SCSI state machine. */
-state_machine:
-       while(what_next != do_intr_end) {
-               if (what_next >= do_phase_determine &&
-                   what_next < do_intr_end)
-                       what_next = isvc_vector[what_next](esp, eregs);
-               else {
-                       /* state is completely lost ;-( */
-                       ESPLOG(("esp%d: interrupt engine loses state, resetting bus\n",
-                               esp->esp_id));
-                       what_next = do_reset_bus;
-               }
-       }
-       if(esp->dma_irq_exit)
-               esp->dma_irq_exit(esp);
-}
-EXPORT_SYMBOL(esp_handle);
-
-#ifndef CONFIG_SMP
-irqreturn_t esp_intr(int irq, void *dev_id)
-{
-       struct NCR_ESP *esp;
-       unsigned long flags;
-       int again;
-       struct Scsi_Host *dev = dev_id;
-
-       /* Handle all ESP interrupts showing at this IRQ level. */
-       spin_lock_irqsave(dev->host_lock, flags);
-repeat:
-       again = 0;
-       for_each_esp(esp) {
-#ifndef __mips__           
-               if(((esp)->irq & 0xff) == irq) {
-#endif             
-                       if(esp->dma_irq_p(esp)) {
-                               again = 1;
-
-                               esp->dma_ints_off(esp);
-
-                               ESPIRQ(("I%d(", esp->esp_id));
-                               esp_handle(esp);
-                               ESPIRQ((")"));
-
-                               esp->dma_ints_on(esp);
-                       }
-#ifndef __mips__                   
-               }
-#endif     
-       }
-       if(again)
-               goto repeat;
-       spin_unlock_irqrestore(dev->host_lock, flags);
-       return IRQ_HANDLED;
-}
-#else
-/* For SMP we only service one ESP on the list list at our IRQ level! */
-irqreturn_t esp_intr(int irq, void *dev_id)
-{
-       struct NCR_ESP *esp;
-       unsigned long flags;
-       struct Scsi_Host *dev = dev_id;
-       
-       /* Handle all ESP interrupts showing at this IRQ level. */
-       spin_lock_irqsave(dev->host_lock, flags);
-       for_each_esp(esp) {
-               if(((esp)->irq & 0xf) == irq) {
-                       if(esp->dma_irq_p(esp)) {
-                               esp->dma_ints_off(esp);
-
-                               ESPIRQ(("I[%d:%d](",
-                                       smp_processor_id(), esp->esp_id));
-                               esp_handle(esp);
-                               ESPIRQ((")"));
-
-                               esp->dma_ints_on(esp);
-                               goto out;
-                       }
-               }
-       }
-out:
-       spin_unlock_irqrestore(dev->host_lock, flags);
-       return IRQ_HANDLED;
-}
-#endif
-
-int esp_slave_alloc(struct scsi_device *SDptr)
-{
-       struct esp_device *esp_dev =
-               kzalloc(sizeof(struct esp_device), GFP_ATOMIC);
-
-       if (!esp_dev)
-               return -ENOMEM;
-       SDptr->hostdata = esp_dev;
-       return 0;
-}
-
-void esp_slave_destroy(struct scsi_device *SDptr)
-{
-       struct NCR_ESP *esp = (struct NCR_ESP *) SDptr->host->hostdata;
-
-       esp->targets_present &= ~(1 << sdev_id(SDptr));
-       kfree(SDptr->hostdata);
-       SDptr->hostdata = NULL;
-}
-
-#ifdef MODULE
-int init_module(void) { return 0; }
-void cleanup_module(void) {}
-void esp_release(void)
-{
-       esps_in_use--;
-       esps_running = esps_in_use;
-}
-EXPORT_SYMBOL(esp_release);
-#endif
-
-EXPORT_SYMBOL(esp_abort);
-EXPORT_SYMBOL(esp_allocate);
-EXPORT_SYMBOL(esp_deallocate);
-EXPORT_SYMBOL(esp_initialize);
-EXPORT_SYMBOL(esp_intr);
-EXPORT_SYMBOL(esp_queue);
-EXPORT_SYMBOL(esp_reset);
-EXPORT_SYMBOL(esp_slave_alloc);
-EXPORT_SYMBOL(esp_slave_destroy);
-EXPORT_SYMBOL(esps_in_use);
-
-MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/NCR53C9x.h b/drivers/scsi/NCR53C9x.h
deleted file mode 100644 (file)
index 00a0ba0..0000000
+++ /dev/null
@@ -1,668 +0,0 @@
-/* NCR53C9x.c:  Defines and structures for the NCR53C9x generic driver.
- *
- * Originally esp.h:  Defines and structures for the Sparc ESP 
- *                   (Enhanced SCSI Processor) driver under Linux.
- *
- * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
- *
- * Generalization by Jesper Skov (jskov@cygnus.co.uk)
- *
- * More generalization (for i386 stuff) by Tymm Twillman (tymm@computer.org)
- */
-
-#ifndef NCR53C9X_H
-#define NCR53C9X_H
-
-#include <linux/interrupt.h>
-
-/* djweis for mac driver */
-#if defined(CONFIG_MAC)
-#define PAD_SIZE 15
-#else
-#define PAD_SIZE 3
-#endif
-
-/* Handle multiple hostadapters on Amiga
- * generally PAD_SIZE = 3
- * but there is one exception: Oktagon (PAD_SIZE = 1) */
-#if defined(CONFIG_OKTAGON_SCSI) || defined(CONFIG_OKTAGON_SCSI_MODULE)
-#undef PAD_SIZE
-#if defined(CONFIG_BLZ1230_SCSI) || defined(CONFIG_BLZ1230_SCSI_MODULE) || \
-    defined(CONFIG_BLZ2060_SCSI) || defined(CONFIG_BLZ2060_SCSI_MODULE) || \
-    defined(CONFIG_CYBERSTORM_SCSI) || defined(CONFIG_CYBERSTORM_SCSI_MODULE) || \
-    defined(CONFIG_CYBERSTORMII_SCSI) || defined(CONFIG_CYBERSTORMII_SCSI_MODULE) || \
-    defined(CONFIG_FASTLANE_SCSI) || defined(CONFIG_FASTLANE_SCSI_MODULE)
-#define MULTIPLE_PAD_SIZES
-#else
-#define PAD_SIZE 1
-#endif
-#endif
-
-/* Macros for debugging messages */
-
-#define DEBUG_ESP
-/* #define DEBUG_ESP_DATA */
-/* #define DEBUG_ESP_QUEUE */
-/* #define DEBUG_ESP_DISCONNECT */
-/* #define DEBUG_ESP_STATUS */
-/* #define DEBUG_ESP_PHASES */
-/* #define DEBUG_ESP_WORKBUS */
-/* #define DEBUG_STATE_MACHINE */
-/* #define DEBUG_ESP_CMDS */
-/* #define DEBUG_ESP_IRQS */
-/* #define DEBUG_SDTR */
-/* #define DEBUG_ESP_SG */
-
-/* Use the following to sprinkle debugging messages in a way which
- * suits you if combinations of the above become too verbose when
- * trying to track down a specific problem.
- */
-/* #define DEBUG_ESP_MISC */
-
-#if defined(DEBUG_ESP)
-#define ESPLOG(foo)  printk foo
-#else
-#define ESPLOG(foo)
-#endif /* (DEBUG_ESP) */
-
-#if defined(DEBUG_ESP_DATA)
-#define ESPDATA(foo)  printk foo
-#else
-#define ESPDATA(foo)
-#endif
-
-#if defined(DEBUG_ESP_QUEUE)
-#define ESPQUEUE(foo)  printk foo
-#else
-#define ESPQUEUE(foo)
-#endif
-
-#if defined(DEBUG_ESP_DISCONNECT)
-#define ESPDISC(foo)  printk foo
-#else
-#define ESPDISC(foo)
-#endif
-
-#if defined(DEBUG_ESP_STATUS)
-#define ESPSTAT(foo)  printk foo
-#else
-#define ESPSTAT(foo)
-#endif
-
-#if defined(DEBUG_ESP_PHASES)
-#define ESPPHASE(foo)  printk foo
-#else
-#define ESPPHASE(foo)
-#endif
-
-#if defined(DEBUG_ESP_WORKBUS)
-#define ESPBUS(foo)  printk foo
-#else
-#define ESPBUS(foo)
-#endif
-
-#if defined(DEBUG_ESP_IRQS)
-#define ESPIRQ(foo)  printk foo
-#else
-#define ESPIRQ(foo)
-#endif
-
-#if defined(DEBUG_SDTR)
-#define ESPSDTR(foo)  printk foo
-#else
-#define ESPSDTR(foo)
-#endif
-
-#if defined(DEBUG_ESP_MISC)
-#define ESPMISC(foo)  printk foo
-#else
-#define ESPMISC(foo)
-#endif
-
-/*
- * padding for register structure
- */
-#ifdef CONFIG_JAZZ_ESP
-#define EREGS_PAD(n)
-#else
-#ifndef MULTIPLE_PAD_SIZES
-#define EREGS_PAD(n)    unchar n[PAD_SIZE];
-#endif
-#endif
-
-/* The ESP SCSI controllers have their register sets in three
- * "classes":
- *
- * 1) Registers which are both read and write.
- * 2) Registers which are read only.
- * 3) Registers which are write only.
- *
- * Yet, they all live within the same IO space.
- */
-
-#if !defined(__i386__) && !defined(__x86_64__)
-
-#ifndef MULTIPLE_PAD_SIZES
-
-#ifdef CONFIG_CPU_HAS_WB
-#include <asm/wbflush.h>
-#define esp_write(__reg, __val) do{(__reg) = (__val); wbflush();} while(0)
-#else
-#define esp_write(__reg, __val) ((__reg) = (__val))
-#endif
-#define esp_read(__reg) (__reg)
-
-struct ESP_regs {
-                                /* Access    Description              Offset */
-    volatile unchar esp_tclow;  /* rw  Low bits of the transfer count 0x00   */
-                                EREGS_PAD(tlpad1);
-    volatile unchar esp_tcmed;  /* rw  Mid bits of the transfer count 0x04   */
-                                EREGS_PAD(fdpad);
-    volatile unchar esp_fdata;  /* rw  FIFO data bits                 0x08   */
-                                EREGS_PAD(cbpad);
-    volatile unchar esp_cmnd;   /* rw  SCSI command bits              0x0c   */
-                                EREGS_PAD(stpad);
-    volatile unchar esp_status; /* ro  ESP status register            0x10   */
-#define esp_busid   esp_status  /* wo  Bus ID for select/reselect     0x10   */
-                                EREGS_PAD(irqpd);
-    volatile unchar esp_intrpt; /* ro  Kind of interrupt              0x14   */
-#define esp_timeo   esp_intrpt  /* wo  Timeout value for select/resel 0x14   */
-                                EREGS_PAD(sspad);
-    volatile unchar esp_sstep;  /* ro  Sequence step register         0x18   */
-#define esp_stp     esp_sstep   /* wo  Transfer period per sync       0x18   */
-                                EREGS_PAD(ffpad);
-    volatile unchar esp_fflags; /* ro  Bits of current FIFO info      0x1c   */
-#define esp_soff    esp_fflags  /* wo  Sync offset                    0x1c   */
-                                EREGS_PAD(cf1pd);
-    volatile unchar esp_cfg1;   /* rw  First configuration register   0x20   */
-                                EREGS_PAD(cfpad);
-    volatile unchar esp_cfact;  /* wo  Clock conversion factor        0x24   */
-                                EREGS_PAD(ctpad);
-    volatile unchar esp_ctest;  /* wo  Chip test register             0x28   */
-                                EREGS_PAD(cf2pd);
-    volatile unchar esp_cfg2;   /* rw  Second configuration register  0x2c   */
-                                EREGS_PAD(cf3pd);
-
-    /* The following is only found on the 53C9X series SCSI chips */
-    volatile unchar esp_cfg3;   /* rw  Third configuration register   0x30  */
-                                EREGS_PAD(cf4pd);
-    volatile unchar esp_cfg4;   /* rw  Fourth configuration register  0x34  */
-                                EREGS_PAD(thpd);
-    /* The following is found on all chips except the NCR53C90 (ESP100) */
-    volatile unchar esp_tchi;   /* rw  High bits of transfer count    0x38  */
-#define esp_uid     esp_tchi    /* ro  Unique ID code                 0x38  */
-                                EREGS_PAD(fgpad);    
-    volatile unchar esp_fgrnd;  /* rw  Data base for fifo             0x3c  */
-};
-
-#else /* MULTIPLE_PAD_SIZES */
-
-#define esp_write(__reg, __val) (*(__reg) = (__val))
-#define esp_read(__reg) (*(__reg))
-
-struct ESP_regs {
-    unsigned char io_addr[64]; /* dummy */
-                                                 /* Access    Description              Offset */
-#define esp_tclow   io_addr                      /* rw  Low bits of the transfer count 0x00   */
-#define esp_tcmed   io_addr + (1<<(esp->shift))  /* rw  Mid bits of the transfer count 0x04   */
-#define esp_fdata   io_addr + (2<<(esp->shift))  /* rw  FIFO data bits                 0x08   */
-#define esp_cmnd    io_addr + (3<<(esp->shift))  /* rw  SCSI command bits              0x0c   */
-#define esp_status  io_addr + (4<<(esp->shift))  /* ro  ESP status register            0x10   */
-#define esp_busid   esp_status                   /* wo  Bus ID for select/reselect     0x10   */
-#define esp_intrpt  io_addr + (5<<(esp->shift))  /* ro  Kind of interrupt              0x14   */
-#define esp_timeo   esp_intrpt                   /* wo  Timeout value for select/resel 0x14   */
-#define esp_sstep   io_addr + (6<<(esp->shift))  /* ro  Sequence step register         0x18   */
-#define esp_stp     esp_sstep                    /* wo  Transfer period per sync       0x18   */
-#define esp_fflags  io_addr + (7<<(esp->shift))  /* ro  Bits of current FIFO info      0x1c   */
-#define esp_soff    esp_fflags                   /* wo  Sync offset                    0x1c   */
-#define esp_cfg1    io_addr + (8<<(esp->shift))  /* rw  First configuration register   0x20   */
-#define esp_cfact   io_addr + (9<<(esp->shift))  /* wo  Clock conversion factor        0x24   */
-#define esp_ctest   io_addr + (10<<(esp->shift)) /* wo  Chip test register             0x28   */
-#define esp_cfg2    io_addr + (11<<(esp->shift)) /* rw  Second configuration register  0x2c   */
-
-    /* The following is only found on the 53C9X series SCSI chips */
-#define esp_cfg3    io_addr + (12<<(esp->shift)) /* rw  Third configuration register   0x30  */
-#define esp_cfg4    io_addr + (13<<(esp->shift)) /* rw  Fourth configuration register  0x34  */
-
-    /* The following is found on all chips except the NCR53C90 (ESP100) */
-#define esp_tchi    io_addr + (14<<(esp->shift)) /* rw  High bits of transfer count    0x38  */
-#define esp_uid     esp_tchi                     /* ro  Unique ID code                 0x38  */
-#define esp_fgrnd   io_addr + (15<<(esp->shift)) /* rw  Data base for fifo             0x3c  */
-};
-
-#endif
-
-#else /* !defined(__i386__) && !defined(__x86_64__) */
-
-#define esp_write(__reg, __val) outb((__val), (__reg))
-#define esp_read(__reg) inb((__reg))
-
-struct ESP_regs {
-    unsigned int io_addr;
-                                 /* Access    Description              Offset */
-#define esp_tclow   io_addr      /* rw  Low bits of the transfer count 0x00   */
-#define esp_tcmed   io_addr + 1  /* rw  Mid bits of the transfer count 0x04   */
-#define esp_fdata   io_addr + 2  /* rw  FIFO data bits                 0x08   */
-#define esp_cmnd    io_addr + 3  /* rw  SCSI command bits              0x0c   */
-#define esp_status  io_addr + 4  /* ro  ESP status register            0x10   */
-#define esp_busid   esp_status   /* wo  Bus ID for select/reselect     0x10   */
-#define esp_intrpt  io_addr + 5  /* ro  Kind of interrupt              0x14   */
-#define esp_timeo   esp_intrpt   /* wo  Timeout value for select/resel 0x14   */
-#define esp_sstep   io_addr + 6  /* ro  Sequence step register         0x18   */
-#define esp_stp     esp_sstep    /* wo  Transfer period per sync       0x18   */
-#define esp_fflags  io_addr + 7  /* ro  Bits of current FIFO info      0x1c   */
-#define esp_soff    esp_fflags   /* wo  Sync offset                    0x1c   */
-#define esp_cfg1    io_addr + 8  /* rw  First configuration register   0x20   */
-#define esp_cfact   io_addr + 9  /* wo  Clock conversion factor        0x24   */
-#define esp_ctest   io_addr + 10 /* wo  Chip test register             0x28   */
-#define esp_cfg2    io_addr + 11 /* rw  Second configuration register  0x2c   */
-
-    /* The following is only found on the 53C9X series SCSI chips */
-#define esp_cfg3    io_addr + 12 /* rw  Third configuration register   0x30  */
-#define esp_cfg4    io_addr + 13 /* rw  Fourth configuration register  0x34  */
-
-    /* The following is found on all chips except the NCR53C90 (ESP100) */
-#define esp_tchi    io_addr + 14 /* rw  High bits of transfer count    0x38  */
-#define esp_uid     esp_tchi     /* ro  Unique ID code                 0x38  */
-#define esp_fgrnd   io_addr + 15 /* rw  Data base for fifo             0x3c  */
-};
-
-#endif /* !defined(__i386__) && !defined(__x86_64__) */
-
-/* Various revisions of the ESP board. */
-enum esp_rev {
-  esp100     = 0x00,  /* NCR53C90 - very broken */
-  esp100a    = 0x01,  /* NCR53C90A */
-  esp236     = 0x02,
-  fas236     = 0x03,
-  fas100a    = 0x04,
-  fast       = 0x05,
-  fas366     = 0x06,
-  fas216     = 0x07,
-  fsc        = 0x08,  /* SYM53C94-2 */
-  espunknown = 0x09
-};
-
-/* We allocate one of these for each scsi device and attach it to
- * SDptr->hostdata for use in the driver
- */
-struct esp_device {
-  unsigned char sync_min_period;
-  unsigned char sync_max_offset;
-  unsigned sync:1;
-  unsigned wide:1;
-  unsigned disconnect:1;
-};
-
-/* We get one of these for each ESP probed. */
-struct NCR_ESP {
-  struct NCR_ESP *next;                   /* Next ESP on probed or NULL */
-  struct ESP_regs *eregs;                /* All esp registers */
-  int dma;                                /* Who I do transfers with. */
-  void *dregs;                           /* And his registers. */
-  struct Scsi_Host *ehost;                /* Backpointer to SCSI Host */
-
-  void *edev;                            /* Pointer to controller base/SBus */
-  int esp_id;                             /* Unique per-ESP ID number */
-
-  /* ESP Configuration Registers */
-  unsigned char config1;                  /* Copy of the 1st config register */
-  unsigned char config2;                  /* Copy of the 2nd config register */
-  unsigned char config3[16];              /* Copy of the 3rd config register */
-
-  /* The current command we are sending to the ESP chip.  This esp_command
-   * ptr needs to be mapped in DVMA area so we can send commands and read
-   * from the ESP fifo without burning precious CPU cycles.  Programmed I/O
-   * sucks when we have the DVMA to do it for us.  The ESP is stupid and will
-   * only send out 6, 10, and 12 byte SCSI commands, others we need to send
-   * one byte at a time.  esp_slowcmd being set says that we are doing one
-   * of the command types ESP doesn't understand, esp_scmdp keeps track of
-   * which byte we are sending, esp_scmdleft says how many bytes to go.
-   */
-  volatile unchar *esp_command;           /* Location of command (CPU view)  */
-  __u32            esp_command_dvma;      /* Location of command (DVMA view) */
-  unsigned char esp_clen;                 /* Length of this command */
-  unsigned char esp_slowcmd;
-  unsigned char *esp_scmdp;
-  unsigned char esp_scmdleft;
-
-  /* The following are used to determine the cause of an IRQ. Upon every
-   * IRQ entry we synchronize these with the hardware registers.
-   */
-  unchar ireg;                            /* Copy of ESP interrupt register */
-  unchar sreg;                            /* Same for ESP status register */
-  unchar seqreg;                          /* The ESP sequence register */
-
-  /* The following is set when a premature interrupt condition is detected
-   * in some FAS revisions.
-   */
-  unchar fas_premature_intr_workaround;
-
-  /* To save register writes to the ESP, which can be expensive, we
-   * keep track of the previous value that various registers had for
-   * the last target we connected to.  If they are the same for the
-   * current target, we skip the register writes as they are not needed.
-   */
-  unchar prev_soff, prev_stp, prev_cfg3;
-
-  /* For each target we keep track of save/restore data
-   * pointer information.  This needs to be updated majorly
-   * when we add support for tagged queueing.  -DaveM
-   */
-  struct esp_pointers {
-         char *saved_ptr;
-         struct scatterlist *saved_buffer;
-         int saved_this_residual;
-         int saved_buffers_residual;
-  } data_pointers[16] /*XXX [MAX_TAGS_PER_TARGET]*/;
-
-  /* Clock periods, frequencies, synchronization, etc. */
-  unsigned int cfreq;                    /* Clock frequency in HZ */
-  unsigned int cfact;                    /* Clock conversion factor */
-  unsigned int ccycle;                   /* One ESP clock cycle */
-  unsigned int ctick;                    /* One ESP clock time */
-  unsigned int radelay;                  /* FAST chip req/ack delay */
-  unsigned int neg_defp;                 /* Default negotiation period */
-  unsigned int sync_defp;                /* Default sync transfer period */
-  unsigned int max_period;               /* longest our period can be */
-  unsigned int min_period;               /* shortest period we can withstand */
-  /* For slow to medium speed input clock rates we shoot for 5mb/s,
-   * but for high input clock rates we try to do 10mb/s although I
-   * don't think a transfer can even run that fast with an ESP even
-   * with DMA2 scatter gather pipelining.
-   */
-#define SYNC_DEFP_SLOW            0x32   /* 5mb/s  */
-#define SYNC_DEFP_FAST            0x19   /* 10mb/s */
-
-  unsigned int snip;                      /* Sync. negotiation in progress */
-  unsigned int wnip;                      /* WIDE negotiation in progress */
-  unsigned int targets_present;           /* targets spoken to before */
-
-  int current_transfer_size;              /* Set at beginning of data dma */
-
-  unchar espcmdlog[32];                   /* Log of current esp cmds sent. */
-  unchar espcmdent;                       /* Current entry in esp cmd log. */
-
-  /* Misc. info about this ESP */
-  enum esp_rev erev;                      /* ESP revision */
-  int irq;                                /* IRQ for this ESP */
-  int scsi_id;                            /* Who am I as initiator? */
-  int scsi_id_mask;                       /* Bitmask of 'me'. */
-  int diff;                               /* Differential SCSI bus? */
-  int slot;                               /* Slot the adapter occupies */
-
-  /* Our command queues, only one cmd lives in the current_SC queue. */
-  Scsi_Cmnd *issue_SC;           /* Commands to be issued */
-  Scsi_Cmnd *current_SC;         /* Who is currently working the bus */
-  Scsi_Cmnd *disconnected_SC;    /* Commands disconnected from the bus */
-
-  /* Message goo */
-  unchar cur_msgout[16];
-  unchar cur_msgin[16];
-  unchar prevmsgout, prevmsgin;
-  unchar msgout_len, msgin_len;
-  unchar msgout_ctr, msgin_ctr;
-
-  /* States that we cannot keep in the per cmd structure because they
-   * cannot be assosciated with any specific command.
-   */
-  unchar resetting_bus;
-  wait_queue_head_t reset_queue;
-
-  unchar do_pio_cmds;          /* Do command transfer with pio */
-
-  /* How much bits do we have to shift the registers */
-  unsigned char shift;
-
-  /* Functions handling DMA
-   */ 
-  /* Required functions */
-  int  (*dma_bytes_sent)(struct NCR_ESP *, int);
-  int  (*dma_can_transfer)(struct NCR_ESP *, Scsi_Cmnd *);
-  void (*dma_dump_state)(struct NCR_ESP *);
-  void (*dma_init_read)(struct NCR_ESP *, __u32, int);
-  void (*dma_init_write)(struct NCR_ESP *, __u32, int);
-  void (*dma_ints_off)(struct NCR_ESP *);
-  void (*dma_ints_on)(struct NCR_ESP *);
-  int  (*dma_irq_p)(struct NCR_ESP *);
-  int  (*dma_ports_p)(struct NCR_ESP *);
-  void (*dma_setup)(struct NCR_ESP *, __u32, int, int);
-
-  /* Optional functions (i.e. may be initialized to 0) */
-  void (*dma_barrier)(struct NCR_ESP *);
-  void (*dma_drain)(struct NCR_ESP *);
-  void (*dma_invalidate)(struct NCR_ESP *);
-  void (*dma_irq_entry)(struct NCR_ESP *);
-  void (*dma_irq_exit)(struct NCR_ESP *);
-  void (*dma_led_off)(struct NCR_ESP *);
-  void (*dma_led_on)(struct NCR_ESP *);
-  void (*dma_poll)(struct NCR_ESP *, unsigned char *);
-  void (*dma_reset)(struct NCR_ESP *);
-    
-  /* Optional virtual DMA functions */
-  void (*dma_mmu_get_scsi_one)(struct NCR_ESP *, Scsi_Cmnd *);
-  void (*dma_mmu_get_scsi_sgl)(struct NCR_ESP *, Scsi_Cmnd *);
-  void (*dma_mmu_release_scsi_one)(struct NCR_ESP *, Scsi_Cmnd *);
-  void (*dma_mmu_release_scsi_sgl)(struct NCR_ESP *, Scsi_Cmnd *);
-  void (*dma_advance_sg)(Scsi_Cmnd *);
-};
-
-/* Bitfield meanings for the above registers. */
-
-/* ESP config reg 1, read-write, found on all ESP chips */
-#define ESP_CONFIG1_ID        0x07             /* My BUS ID bits */
-#define ESP_CONFIG1_CHTEST    0x08             /* Enable ESP chip tests */
-#define ESP_CONFIG1_PENABLE   0x10             /* Enable parity checks */
-#define ESP_CONFIG1_PARTEST   0x20             /* Parity test mode enabled? */
-#define ESP_CONFIG1_SRRDISAB  0x40             /* Disable SCSI reset reports */
-#define ESP_CONFIG1_SLCABLE   0x80             /* Enable slow cable mode */
-
-/* ESP config reg 2, read-write, found only on esp100a+esp200+esp236+fsc chips */
-#define ESP_CONFIG2_DMAPARITY 0x01             /* enable DMA Parity (200,236,fsc) */
-#define ESP_CONFIG2_REGPARITY 0x02             /* enable reg Parity (200,236,fsc) */
-#define ESP_CONFIG2_BADPARITY 0x04             /* Bad parity target abort  */
-#define ESP_CONFIG2_SCSI2ENAB 0x08             /* Enable SCSI-2 features (tmode only) */
-#define ESP_CONFIG2_HI        0x10             /* High Impedance DREQ ???  */
-#define ESP_CONFIG2_HMEFENAB  0x10             /* HME features enable */
-#define ESP_CONFIG2_BCM       0x20             /* Enable byte-ctrl (236,fsc)   */
-#define ESP_CONFIG2_FENAB     0x40             /* Enable features (fas100,esp216,fsc)      */
-#define ESP_CONFIG2_SPL       0x40             /* Enable status-phase latch (esp236)   */
-#define ESP_CONFIG2_RFB       0x80             /* Reserve FIFO byte (fsc) */
-#define ESP_CONFIG2_MAGIC     0xe0             /* Invalid bits... */
-
-/* ESP config register 3 read-write, found only esp236+fas236+fas100a+fsc chips */
-#define ESP_CONFIG3_FCLOCK    0x01             /* FAST SCSI clock rate (esp100a/fas366) */
-#define ESP_CONFIG3_TEM       0x01             /* Enable thresh-8 mode (esp/fas236/fsc)  */
-#define ESP_CONFIG3_FAST      0x02             /* Enable FAST SCSI     (esp100a) */
-#define ESP_CONFIG3_ADMA      0x02             /* Enable alternate-dma (esp/fas236/fsc)  */
-#define ESP_CONFIG3_TENB      0x04             /* group2 SCSI2 support (esp100a) */
-#define ESP_CONFIG3_SRB       0x04             /* Save residual byte   (esp/fas236/fsc)  */
-#define ESP_CONFIG3_TMS       0x08             /* Three-byte msg's ok  (esp100a) */
-#define ESP_CONFIG3_FCLK      0x08             /* Fast SCSI clock rate (esp/fas236/fsc)  */
-#define ESP_CONFIG3_IDMSG     0x10             /* ID message checking  (esp100a) */
-#define ESP_CONFIG3_FSCSI     0x10             /* Enable FAST SCSI     (esp/fas236/fsc)  */
-#define ESP_CONFIG3_GTM       0x20             /* group2 SCSI2 support (esp/fas236/fsc)  */
-#define ESP_CONFIG3_TBMS      0x40             /* Three-byte msg's ok  (esp/fas236/fsc)  */
-#define ESP_CONFIG3_IMS       0x80             /* ID msg chk'ng        (esp/fas236/fsc)  */
-
-/* ESP config register 4 read-write, found only on fsc chips */
-#define ESP_CONFIG4_BBTE      0x01             /* Back-to-Back transfer enable */
-#define ESP_CONFIG4_TEST      0x02             /* Transfer counter test mode */
-#define ESP_CONFIG4_EAN       0x04             /* Enable Active Negotiation */
-
-/* ESP command register read-write */
-/* Group 1 commands:  These may be sent at any point in time to the ESP
- *                    chip.  None of them can generate interrupts 'cept
- *                    the "SCSI bus reset" command if you have not disabled
- *                    SCSI reset interrupts in the config1 ESP register.
- */
-#define ESP_CMD_NULL          0x00             /* Null command, ie. a nop */
-#define ESP_CMD_FLUSH         0x01             /* FIFO Flush */
-#define ESP_CMD_RC            0x02             /* Chip reset */
-#define ESP_CMD_RS            0x03             /* SCSI bus reset */
-
-/* Group 2 commands:  ESP must be an initiator and connected to a target
- *                    for these commands to work.
- */
-#define ESP_CMD_TI            0x10             /* Transfer Information */
-#define ESP_CMD_ICCSEQ        0x11             /* Initiator cmd complete sequence */
-#define ESP_CMD_MOK           0x12             /* Message okie-dokie */
-#define ESP_CMD_TPAD          0x18             /* Transfer Pad */
-#define ESP_CMD_SATN          0x1a             /* Set ATN */
-#define ESP_CMD_RATN          0x1b             /* De-assert ATN */
-
-/* Group 3 commands:  ESP must be in the MSGOUT or MSGIN state and be connected
- *                    to a target as the initiator for these commands to work.
- */
-#define ESP_CMD_SMSG          0x20             /* Send message */
-#define ESP_CMD_SSTAT         0x21             /* Send status */
-#define ESP_CMD_SDATA         0x22             /* Send data */
-#define ESP_CMD_DSEQ          0x23             /* Discontinue Sequence */
-#define ESP_CMD_TSEQ          0x24             /* Terminate Sequence */
-#define ESP_CMD_TCCSEQ        0x25             /* Target cmd cmplt sequence */
-#define ESP_CMD_DCNCT         0x27             /* Disconnect */
-#define ESP_CMD_RMSG          0x28             /* Receive Message */
-#define ESP_CMD_RCMD          0x29             /* Receive Command */
-#define ESP_CMD_RDATA         0x2a             /* Receive Data */
-#define ESP_CMD_RCSEQ         0x2b             /* Receive cmd sequence */
-
-/* Group 4 commands:  The ESP must be in the disconnected state and must
- *                    not be connected to any targets as initiator for
- *                    these commands to work.
- */
-#define ESP_CMD_RSEL          0x40             /* Reselect */
-#define ESP_CMD_SEL           0x41             /* Select w/o ATN */
-#define ESP_CMD_SELA          0x42             /* Select w/ATN */
-#define ESP_CMD_SELAS         0x43             /* Select w/ATN & STOP */
-#define ESP_CMD_ESEL          0x44             /* Enable selection */
-#define ESP_CMD_DSEL          0x45             /* Disable selections */
-#define ESP_CMD_SA3           0x46             /* Select w/ATN3 */
-#define ESP_CMD_RSEL3         0x47             /* Reselect3 */
-
-/* This bit enables the ESP's DMA */
-#define ESP_CMD_DMA           0x80             /* Do DMA? */
-
-/* ESP status register read-only */
-#define ESP_STAT_PIO          0x01             /* IO phase bit */
-#define ESP_STAT_PCD          0x02             /* CD phase bit */
-#define ESP_STAT_PMSG         0x04             /* MSG phase bit */
-#define ESP_STAT_PMASK        0x07             /* Mask of phase bits */
-#define ESP_STAT_TDONE        0x08             /* Transfer Completed */
-#define ESP_STAT_TCNT         0x10             /* Transfer Counter Is Zero */
-#define ESP_STAT_PERR         0x20             /* Parity error */
-#define ESP_STAT_SPAM         0x40             /* Real bad error */
-/* This indicates the 'interrupt pending' condition, it is a reserved
- * bit on old revs of the ESP (ESP100, ESP100A, FAS100A).
- */
-#define ESP_STAT_INTR         0x80             /* Interrupt */
-
-/* The status register can be masked with ESP_STAT_PMASK and compared
- * with the following values to determine the current phase the ESP
- * (at least thinks it) is in.  For our purposes we also add our own
- * software 'done' bit for our phase management engine.
- */
-#define ESP_DOP   (0)                                       /* Data Out  */
-#define ESP_DIP   (ESP_STAT_PIO)                            /* Data In   */
-#define ESP_CMDP  (ESP_STAT_PCD)                            /* Command   */
-#define ESP_STATP (ESP_STAT_PCD|ESP_STAT_PIO)               /* Status    */
-#define ESP_MOP   (ESP_STAT_PMSG|ESP_STAT_PCD)              /* Message Out */
-#define ESP_MIP   (ESP_STAT_PMSG|ESP_STAT_PCD|ESP_STAT_PIO) /* Message In */
-
-/* ESP interrupt register read-only */
-#define ESP_INTR_S            0x01             /* Select w/o ATN */
-#define ESP_INTR_SATN         0x02             /* Select w/ATN */
-#define ESP_INTR_RSEL         0x04             /* Reselected */
-#define ESP_INTR_FDONE        0x08             /* Function done */
-#define ESP_INTR_BSERV        0x10             /* Bus service */
-#define ESP_INTR_DC           0x20             /* Disconnect */
-#define ESP_INTR_IC           0x40             /* Illegal command given */
-#define ESP_INTR_SR           0x80             /* SCSI bus reset detected */
-
-/* Interrupt status macros */
-#define ESP_SRESET_IRQ(esp)  ((esp)->intreg & (ESP_INTR_SR))
-#define ESP_ILLCMD_IRQ(esp)  ((esp)->intreg & (ESP_INTR_IC))
-#define ESP_SELECT_WITH_ATN_IRQ(esp)     ((esp)->intreg & (ESP_INTR_SATN))
-#define ESP_SELECT_WITHOUT_ATN_IRQ(esp)  ((esp)->intreg & (ESP_INTR_S))
-#define ESP_SELECTION_IRQ(esp)  ((ESP_SELECT_WITH_ATN_IRQ(esp)) ||         \
-                                (ESP_SELECT_WITHOUT_ATN_IRQ(esp)))
-#define ESP_RESELECTION_IRQ(esp)         ((esp)->intreg & (ESP_INTR_RSEL))
-
-/* ESP sequence step register read-only */
-#define ESP_STEP_VBITS        0x07             /* Valid bits */
-#define ESP_STEP_ASEL         0x00             /* Selection&Arbitrate cmplt */
-#define ESP_STEP_SID          0x01             /* One msg byte sent */
-#define ESP_STEP_NCMD         0x02             /* Was not in command phase */
-#define ESP_STEP_PPC          0x03             /* Early phase chg caused cmnd
-                                                * bytes to be lost
-                                                */
-#define ESP_STEP_FINI4        0x04             /* Command was sent ok */
-
-/* Ho hum, some ESP's set the step register to this as well... */
-#define ESP_STEP_FINI5        0x05
-#define ESP_STEP_FINI6        0x06
-#define ESP_STEP_FINI7        0x07
-#define ESP_STEP_SOM          0x08             /* Synchronous Offset Max */
-
-/* ESP chip-test register read-write */
-#define ESP_TEST_TARG         0x01             /* Target test mode */
-#define ESP_TEST_INI          0x02             /* Initiator test mode */
-#define ESP_TEST_TS           0x04             /* Tristate test mode */
-
-/* ESP unique ID register read-only, found on fas236+fas100a+fsc only */
-#define ESP_UID_F100A         0x00             /* FAS100A  */
-#define ESP_UID_F236          0x02             /* FAS236   */
-#define ESP_UID_FSC           0xa2             /* NCR53CF9x-2  */
-#define ESP_UID_REV           0x07             /* ESP revision */
-#define ESP_UID_FAM           0xf8             /* ESP family   */
-
-/* ESP fifo flags register read-only */
-/* Note that the following implies a 16 byte FIFO on the ESP. */
-#define ESP_FF_FBYTES         0x1f             /* Num bytes in FIFO */
-#define ESP_FF_ONOTZERO       0x20             /* offset ctr not zero (esp100,fsc) */
-#define ESP_FF_SSTEP          0xe0             /* Sequence step */
-
-/* ESP clock conversion factor register write-only */
-#define ESP_CCF_F0            0x00             /* 35.01MHz - 40MHz */
-#define ESP_CCF_NEVER         0x01             /* Set it to this and die */
-#define ESP_CCF_F2            0x02             /* 10MHz */
-#define ESP_CCF_F3            0x03             /* 10.01MHz - 15MHz */
-#define ESP_CCF_F4            0x04             /* 15.01MHz - 20MHz */
-#define ESP_CCF_F5            0x05             /* 20.01MHz - 25MHz */
-#define ESP_CCF_F6            0x06             /* 25.01MHz - 30MHz */
-#define ESP_CCF_F7            0x07             /* 30.01MHz - 35MHz */
-
-#define ESP_BUS_TIMEOUT        275             /* In milli-seconds */
-#define ESP_TIMEO_CONST       8192
-#define FSC_TIMEO_CONST       7668
-#define ESP_NEG_DEFP(mhz, cfact) \
-        ((ESP_BUS_TIMEOUT * ((mhz) / 1000)) / (8192 * (cfact)))
-#define FSC_NEG_DEFP(mhz, cfact) \
-        ((ESP_BUS_TIMEOUT * ((mhz) / 1000)) / (7668 * (cfact)))
-#define ESP_MHZ_TO_CYCLE(mhertz)  ((1000000000) / ((mhertz) / 1000))
-#define ESP_TICK(ccf, cycle)  ((7682 * (ccf) * (cycle) / 1000))
-
-
-/* UGLY, UGLY, UGLY! */
-extern int nesps, esps_in_use, esps_running;
-
-/* For our interrupt engine. */
-#define for_each_esp(esp) \
-        for((esp) = espchain; (esp); (esp) = (esp)->next)
-
-
-/* External functions */
-extern void esp_bootup_reset(struct NCR_ESP *esp, struct ESP_regs *eregs);
-extern struct NCR_ESP *esp_allocate(struct scsi_host_template *, void *, int);
-extern void esp_deallocate(struct NCR_ESP *);
-extern void esp_release(void);
-extern void esp_initialize(struct NCR_ESP *);
-extern irqreturn_t esp_intr(int, void *);
-extern const char *esp_info(struct Scsi_Host *);
-extern int esp_queue(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
-extern int esp_abort(Scsi_Cmnd *);
-extern int esp_reset(Scsi_Cmnd *);
-extern int esp_proc_info(struct Scsi_Host *shost, char *buffer, char **start, off_t offset, int length,
-                        int inout);
-extern int esp_slave_alloc(struct scsi_device *);
-extern void esp_slave_destroy(struct scsi_device *);
-#endif /* !(NCR53C9X_H) */
index d7235f42cf5faa730792415727e4998dbbd1cbc2..bfd0e64964accc6e8317c50338725d4fc8db6ad5 100644 (file)
@@ -859,44 +859,31 @@ static int setinqserial(struct aac_dev *dev, void *data, int cid)
                        le32_to_cpu(dev->adapter_info.serial[0]), cid);
 }
 
-static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
-                     u8 a_sense_code, u8 incorrect_length,
-                     u8 bit_pointer, u16 field_pointer,
-                     u32 residue)
+static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
+       u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
 {
-       sense_buf[0] = 0xF0;    /* Sense data valid, err code 70h (current error) */
+       u8 *sense_buf = (u8 *)sense_data;
+       /* Sense data valid, err code 70h */
+       sense_buf[0] = 0x70; /* No info field */
        sense_buf[1] = 0;       /* Segment number, always zero */
 
-       if (incorrect_length) {
-               sense_buf[2] = sense_key | 0x20;/* Set ILI bit | sense key */
-               sense_buf[3] = BYTE3(residue);
-               sense_buf[4] = BYTE2(residue);
-               sense_buf[5] = BYTE1(residue);
-               sense_buf[6] = BYTE0(residue);
-       } else
-               sense_buf[2] = sense_key;       /* Sense key */
-
-       if (sense_key == ILLEGAL_REQUEST)
-               sense_buf[7] = 10;      /* Additional sense length */
-       else
-               sense_buf[7] = 6;       /* Additional sense length */
+       sense_buf[2] = sense_key;       /* Sense key */
 
        sense_buf[12] = sense_code;     /* Additional sense code */
        sense_buf[13] = a_sense_code;   /* Additional sense code qualifier */
+
        if (sense_key == ILLEGAL_REQUEST) {
-               sense_buf[15] = 0;
+               sense_buf[7] = 10;      /* Additional sense length */
 
-               if (sense_code == SENCODE_INVALID_PARAM_FIELD)
-                       sense_buf[15] = 0x80;/* Std sense key specific field */
+               sense_buf[15] = bit_pointer;
                /* Illegal parameter is in the parameter block */
-
                if (sense_code == SENCODE_INVALID_CDB_FIELD)
-                       sense_buf[15] = 0xc0;/* Std sense key specific field */
+                       sense_buf[15] |= 0xc0;/* Std sense key specific field */
                /* Illegal parameter is in the CDB block */
-               sense_buf[15] |= bit_pointer;
                sense_buf[16] = field_pointer >> 8;     /* MSB */
                sense_buf[17] = field_pointer;          /* LSB */
-       }
+       } else
+               sense_buf[7] = 6;       /* Additional sense length */
 }
 
 static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
@@ -906,11 +893,9 @@ static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
                dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
                cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
                        SAM_STAT_CHECK_CONDITION;
-               set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
-                           HARDWARE_ERROR,
-                           SENCODE_INTERNAL_TARGET_FAILURE,
-                           ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
-                           0, 0);
+               set_sense(&dev->fsa_dev[cid].sense_data,
+                 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
+                 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
                memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
                       min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
                             SCSI_SENSE_BUFFERSIZE));
@@ -1520,11 +1505,9 @@ static void io_callback(void *context, struct fib * fibptr)
                  le32_to_cpu(readreply->status));
 #endif
                scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
-               set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
-                                   HARDWARE_ERROR,
-                                   SENCODE_INTERNAL_TARGET_FAILURE,
-                                   ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
-                                   0, 0);
+               set_sense(&dev->fsa_dev[cid].sense_data,
+                 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
+                 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
                memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
                       min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
                             SCSI_SENSE_BUFFERSIZE));
@@ -1733,11 +1716,9 @@ static void synchronize_callback(void *context, struct fib *fibptr)
                     le32_to_cpu(synchronizereply->status));
                cmd->result = DID_OK << 16 |
                        COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
-               set_sense((u8 *)&dev->fsa_dev[cid].sense_data,
-                                   HARDWARE_ERROR,
-                                   SENCODE_INTERNAL_TARGET_FAILURE,
-                                   ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
-                                   0, 0);
+               set_sense(&dev->fsa_dev[cid].sense_data,
+                 HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
+                 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
                memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
                       min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
                             SCSI_SENSE_BUFFERSIZE));
@@ -1945,10 +1926,9 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
        {
                dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
                scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
-               set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
-                           ILLEGAL_REQUEST,
-                           SENCODE_INVALID_COMMAND,
-                           ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
+               set_sense(&dev->fsa_dev[cid].sense_data,
+                 ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
+                 ASENCODE_INVALID_COMMAND, 0, 0);
                memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
                       min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
                             SCSI_SENSE_BUFFERSIZE));
@@ -1995,10 +1975,9 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
                                scsicmd->result = DID_OK << 16 |
                                  COMMAND_COMPLETE << 8 |
                                  SAM_STAT_CHECK_CONDITION;
-                               set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
-                                 ILLEGAL_REQUEST,
-                                 SENCODE_INVALID_CDB_FIELD,
-                                 ASENCODE_NO_SENSE, 0, 7, 2, 0);
+                               set_sense(&dev->fsa_dev[cid].sense_data,
+                                 ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
+                                 ASENCODE_NO_SENSE, 7, 2);
                                memcpy(scsicmd->sense_buffer,
                                  &dev->fsa_dev[cid].sense_data,
                                  min_t(size_t,
@@ -2254,9 +2233,9 @@ int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
                         */
                        dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n", scsicmd->cmnd[0]));
                        scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
-                       set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
-                               ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
-                               ASENCODE_INVALID_COMMAND, 0, 0, 0, 0);
+                       set_sense(&dev->fsa_dev[cid].sense_data,
+                         ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
+                         ASENCODE_INVALID_COMMAND, 0, 0);
                        memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
                                min_t(size_t,
                                      sizeof(dev->fsa_dev[cid].sense_data),
index f8afa358b6b67fba3ba9aa36293ecfdbfd9be01d..abef05146d7580e17d3929dcc8cc600d69c420c6 100644 (file)
@@ -243,6 +243,7 @@ static int next_getadapter_fib(struct aac_dev * dev, void __user *arg)
         *      Search the list of AdapterFibContext addresses on the adapter
         *      to be sure this is a valid address
         */
+       spin_lock_irqsave(&dev->fib_lock, flags);
        entry = dev->fib_list.next;
        fibctx = NULL;
 
@@ -251,24 +252,25 @@ static int next_getadapter_fib(struct aac_dev * dev, void __user *arg)
                /*
                 *      Extract the AdapterFibContext from the Input parameters.
                 */
-               if (fibctx->unique == f.fibctx) {   /* We found a winner */
+               if (fibctx->unique == f.fibctx) { /* We found a winner */
                        break;
                }
                entry = entry->next;
                fibctx = NULL;
        }
        if (!fibctx) {
+               spin_unlock_irqrestore(&dev->fib_lock, flags);
                dprintk ((KERN_INFO "Fib Context not found\n"));
                return -EINVAL;
        }
 
        if((fibctx->type != FSAFS_NTC_GET_ADAPTER_FIB_CONTEXT) ||
                 (fibctx->size != sizeof(struct aac_fib_context))) {
+               spin_unlock_irqrestore(&dev->fib_lock, flags);
                dprintk ((KERN_INFO "Fib Context corrupt?\n"));
                return -EINVAL;
        }
        status = 0;
-       spin_lock_irqsave(&dev->fib_lock, flags);
        /*
         *      If there are no fibs to send back, then either wait or return
         *      -EAGAIN
@@ -414,8 +416,8 @@ static int close_getadapter_fib(struct aac_dev * dev, void __user *arg)
  *     @arg: ioctl arguments
  *
  *     This routine returns the driver version.
- *      Under Linux, there have been no version incompatibilities, so this is
- *      simple!
+ *     Under Linux, there have been no version incompatibilities, so this is
+ *     simple!
  */
 
 static int check_revision(struct aac_dev *dev, void __user *arg)
@@ -463,7 +465,7 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
        u32 data_dir;
        void __user *sg_user[32];
        void *sg_list[32];
-       u32   sg_indx = 0;
+       u32 sg_indx = 0;
        u32 byte_count = 0;
        u32 actual_fibsize64, actual_fibsize = 0;
        int i;
@@ -517,11 +519,11 @@ static int aac_send_raw_srb(struct aac_dev* dev, void __user * arg)
        // Fix up srb for endian and force some values
 
        srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);       // Force this
-       srbcmd->channel  = cpu_to_le32(user_srbcmd->channel);
+       srbcmd->channel  = cpu_to_le32(user_srbcmd->channel);
        srbcmd->id       = cpu_to_le32(user_srbcmd->id);
-       srbcmd->lun      = cpu_to_le32(user_srbcmd->lun);
-       srbcmd->timeout  = cpu_to_le32(user_srbcmd->timeout);
-       srbcmd->flags    = cpu_to_le32(flags);
+       srbcmd->lun      = cpu_to_le32(user_srbcmd->lun);
+       srbcmd->timeout  = cpu_to_le32(user_srbcmd->timeout);
+       srbcmd->flags    = cpu_to_le32(flags);
        srbcmd->retry_limit = 0; // Obsolete parameter
        srbcmd->cdb_size = cpu_to_le32(user_srbcmd->cdb_size);
        memcpy(srbcmd->cdb, user_srbcmd->cdb, sizeof(srbcmd->cdb));
@@ -786,9 +788,9 @@ static int aac_get_pci_info(struct aac_dev* dev, void __user *arg)
        pci_info.bus = dev->pdev->bus->number;
        pci_info.slot = PCI_SLOT(dev->pdev->devfn);
 
-       if (copy_to_user(arg, &pci_info, sizeof(struct aac_pci_info))) {
-              dprintk((KERN_DEBUG "aacraid: Could not copy pci info\n"));
-              return -EFAULT;
+       if (copy_to_user(arg, &pci_info, sizeof(struct aac_pci_info))) {
+               dprintk((KERN_DEBUG "aacraid: Could not copy pci info\n"));
+               return -EFAULT;
        }
        return 0;
 }
index fb0886140dd788efa31f220558247e16439fab98..e80d2a0c46aff85eb839018d5e4d8f12e326372b 100644 (file)
@@ -1130,31 +1130,29 @@ static int __devinit aac_probe_one(struct pci_dev *pdev,
        if (error < 0)
                goto out_deinit;
 
-       if (!(aac->adapter_info.options & AAC_OPT_NEW_COMM)) {
-               error = pci_set_dma_max_seg_size(pdev, 65536);
-               if (error)
-                       goto out_deinit;
-       }
-
        /*
         * Lets override negotiations and drop the maximum SG limit to 34
         */
        if ((aac_drivers[index].quirks & AAC_QUIRK_34SG) &&
-                       (aac->scsi_host_ptr->sg_tablesize > 34)) {
-               aac->scsi_host_ptr->sg_tablesize = 34;
-               aac->scsi_host_ptr->max_sectors
-                 = (aac->scsi_host_ptr->sg_tablesize * 8) + 112;
+                       (shost->sg_tablesize > 34)) {
+               shost->sg_tablesize = 34;
+               shost->max_sectors = (shost->sg_tablesize * 8) + 112;
        }
 
        if ((aac_drivers[index].quirks & AAC_QUIRK_17SG) &&
-                       (aac->scsi_host_ptr->sg_tablesize > 17)) {
-               aac->scsi_host_ptr->sg_tablesize = 17;
-               aac->scsi_host_ptr->max_sectors
-                 = (aac->scsi_host_ptr->sg_tablesize * 8) + 112;
+                       (shost->sg_tablesize > 17)) {
+               shost->sg_tablesize = 17;
+               shost->max_sectors = (shost->sg_tablesize * 8) + 112;
        }
 
+       error = pci_set_dma_max_seg_size(pdev,
+               (aac->adapter_info.options & AAC_OPT_NEW_COMM) ?
+                       (shost->max_sectors << 9) : 65536);
+       if (error)
+               goto out_deinit;
+
        /*
-        * Firware printf works only with older firmware.
+        * Firmware printf works only with older firmware.
         */
        if (aac_drivers[index].quirks & AAC_QUIRK_34SG)
                aac->printf_enabled = 1;
index 374ed025dc5a1da2636061e4e9b12f97f0691905..ccef891d642fd7ffd90bdb923078e80f3828cc09 100644 (file)
@@ -12261,7 +12261,7 @@ static ushort __devinit AdvReadEEPWord(AdvPortAddr iop_base, int eep_word_addr)
 /*
  * Write the EEPROM from 'cfg_buf'.
  */
-void __devinit
+static void __devinit
 AdvSet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
 {
        ushort *wbuf;
@@ -12328,7 +12328,7 @@ AdvSet3550EEPConfig(AdvPortAddr iop_base, ADVEEP_3550_CONFIG *cfg_buf)
 /*
  * Write the EEPROM from 'cfg_buf'.
  */
-void __devinit
+static void __devinit
 AdvSet38C0800EEPConfig(AdvPortAddr iop_base, ADVEEP_38C0800_CONFIG *cfg_buf)
 {
        ushort *wbuf;
@@ -12395,7 +12395,7 @@ AdvSet38C0800EEPConfig(AdvPortAddr iop_base, ADVEEP_38C0800_CONFIG *cfg_buf)
 /*
  * Write the EEPROM from 'cfg_buf'.
  */
-void __devinit
+static void __devinit
 AdvSet38C1600EEPConfig(AdvPortAddr iop_base, ADVEEP_38C1600_CONFIG *cfg_buf)
 {
        ushort *wbuf;
index a67e29f83ae5003cdcb8e65e75951d7fee3093b6..57786502e3ec18df7f47815b549a2e0152791110 100644 (file)
@@ -48,7 +48,7 @@ struct class_device_attribute;
 /*The limit of outstanding scsi command that firmware can handle*/
 #define ARCMSR_MAX_OUTSTANDING_CMD                                             256
 #define ARCMSR_MAX_FREECCB_NUM                                                 320
-#define ARCMSR_DRIVER_VERSION               "Driver Version 1.20.00.15 2007/08/30"
+#define ARCMSR_DRIVER_VERSION               "Driver Version 1.20.00.15 2007/12/24"
 #define ARCMSR_SCSI_INITIATOR_ID                                               255
 #define ARCMSR_MAX_XFER_SECTORS                                                        512
 #define ARCMSR_MAX_XFER_SECTORS_B                                              4096
@@ -248,6 +248,7 @@ struct FIRMWARE_INFO
 #define ARCMSR_MESSAGE_START_BGRB                    0x00060008
 #define ARCMSR_MESSAGE_START_DRIVER_MODE             0x000E0008
 #define ARCMSR_MESSAGE_SET_POST_WINDOW               0x000F0008
+#define ARCMSR_MESSAGE_ACTIVE_EOI_MODE             0x00100008
 /* ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK */
 #define ARCMSR_MESSAGE_FIRMWARE_OK                   0x80000000
 /* ioctl transfer */
@@ -256,6 +257,7 @@ struct FIRMWARE_INFO
 #define ARCMSR_DRV2IOP_DATA_READ_OK                   0x00000002
 #define ARCMSR_DRV2IOP_CDB_POSTED                     0x00000004
 #define ARCMSR_DRV2IOP_MESSAGE_CMD_POSTED             0x00000008
+#define ARCMSR_DRV2IOP_END_OF_INTERRUPT                0x00000010
 
 /* data tunnel buffer between user space program and its firmware */
 /* user space data to iop 128bytes */
index f4a202e8df267329e44b15cbe48ad546911de118..4f9ff32cfed09592c91bf4e92b1103803c90718c 100644 (file)
@@ -315,9 +315,6 @@ static int arcmsr_alloc_ccb_pool(struct AdapterControlBlock *acb)
                                (0x20 - ((unsigned long)dma_coherent_handle & 0x1F));
                }
 
-               reg = (struct MessageUnit_B *)(dma_coherent +
-               ARCMSR_MAX_FREECCB_NUM * sizeof(struct CommandControlBlock));
-
                dma_addr = dma_coherent_handle;
                ccb_tmp = (struct CommandControlBlock *)dma_coherent;
                for (i = 0; i < ARCMSR_MAX_FREECCB_NUM; i++) {
@@ -371,8 +368,8 @@ static int arcmsr_alloc_ccb_pool(struct AdapterControlBlock *acb)
 
 out:
        dma_free_coherent(&acb->pdev->dev,
-               ARCMSR_MAX_FREECCB_NUM * sizeof(struct CommandControlBlock) + 0x20,
-               acb->dma_coherent, acb->dma_coherent_handle);
+               (ARCMSR_MAX_FREECCB_NUM * sizeof(struct CommandControlBlock) + 0x20 +
+               sizeof(struct MessageUnit_B)), acb->dma_coherent, acb->dma_coherent_handle);
        return -ENOMEM;
 }
 
@@ -509,6 +506,7 @@ static uint8_t arcmsr_hbb_wait_msgint_ready(struct AdapterControlBlock *acb)
                                & ARCMSR_IOP2DRV_MESSAGE_CMD_DONE) {
                                writel(ARCMSR_MESSAGE_INT_CLEAR_PATTERN
                                        , reg->iop2drv_doorbell_reg);
+                               writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT, reg->drv2iop_doorbell_reg);
                                return 0x00;
                        }
                        msleep(10);
@@ -748,6 +746,7 @@ static void arcmsr_drain_donequeue(struct AdapterControlBlock *acb, uint32_t fla
                                , ccb->startdone
                                , atomic_read(&acb->ccboutstandingcount));
                }
+       else
        arcmsr_report_ccb_state(acb, ccb, flag_ccb);
 }
 
@@ -886,7 +885,7 @@ static void arcmsr_enable_outbound_ints(struct AdapterControlBlock *acb, \
        }
 }
 
-static void arcmsr_build_ccb(struct AdapterControlBlock *acb,
+static int arcmsr_build_ccb(struct AdapterControlBlock *acb,
        struct CommandControlBlock *ccb, struct scsi_cmnd *pcmd)
 {
        struct ARCMSR_CDB *arcmsr_cdb = (struct ARCMSR_CDB *)&ccb->arcmsr_cdb;
@@ -906,6 +905,8 @@ static void arcmsr_build_ccb(struct AdapterControlBlock *acb,
        memcpy(arcmsr_cdb->Cdb, pcmd->cmnd, pcmd->cmd_len);
 
        nseg = scsi_dma_map(pcmd);
+       if (nseg > ARCMSR_MAX_SG_ENTRIES)
+               return FAILED;
        BUG_ON(nseg < 0);
 
        if (nseg) {
@@ -946,6 +947,7 @@ static void arcmsr_build_ccb(struct AdapterControlBlock *acb,
                arcmsr_cdb->Flags |= ARCMSR_CDB_FLAG_WRITE;
                ccb->ccb_flags |= CCB_FLAG_WRITE;
        }
+       return SUCCESS;
 }
 
 static void arcmsr_post_ccb(struct AdapterControlBlock *acb, struct CommandControlBlock *ccb)
@@ -1036,18 +1038,22 @@ static void arcmsr_free_ccb_pool(struct AdapterControlBlock *acb)
        switch (acb->adapter_type) {
        case ACB_ADAPTER_TYPE_A: {
                iounmap(acb->pmuA);
+               dma_free_coherent(&acb->pdev->dev,
+               ARCMSR_MAX_FREECCB_NUM * sizeof (struct CommandControlBlock) + 0x20,
+               acb->dma_coherent,
+               acb->dma_coherent_handle);
                break;
        }
        case ACB_ADAPTER_TYPE_B: {
                struct MessageUnit_B *reg = acb->pmuB;
                iounmap(reg->drv2iop_doorbell_reg - ARCMSR_DRV2IOP_DOORBELL);
                iounmap(reg->ioctl_wbuffer_reg - ARCMSR_IOCTL_WBUFFER);
+               dma_free_coherent(&acb->pdev->dev,
+               (ARCMSR_MAX_FREECCB_NUM * sizeof(struct CommandControlBlock) + 0x20 +
+               sizeof(struct MessageUnit_B)), acb->dma_coherent, acb->dma_coherent_handle);
        }
        }
-       dma_free_coherent(&acb->pdev->dev,
-               ARCMSR_MAX_FREECCB_NUM * sizeof (struct CommandControlBlock) + 0x20,
-               acb->dma_coherent,
-               acb->dma_coherent_handle);
+
 }
 
 void arcmsr_iop_message_read(struct AdapterControlBlock *acb)
@@ -1273,7 +1279,9 @@ static int arcmsr_handle_hbb_isr(struct AdapterControlBlock *acb)
                return 1;
 
        writel(~outbound_doorbell, reg->iop2drv_doorbell_reg);
-
+       /*in case the last action of doorbell interrupt clearance is cached, this action can push HW to write down the clear bit*/
+       readl(reg->iop2drv_doorbell_reg);
+       writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT, reg->drv2iop_doorbell_reg);
        if (outbound_doorbell & ARCMSR_IOP2DRV_DATA_WRITE_OK)   {
                arcmsr_iop2drv_data_wrote_handle(acb);
        }
@@ -1380,12 +1388,13 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, \
 
        case ARCMSR_MESSAGE_READ_RQBUFFER: {
                unsigned long *ver_addr;
-               dma_addr_t buf_handle;
                uint8_t *pQbuffer, *ptmpQbuffer;
                int32_t allxfer_len = 0;
+               void *tmp;
 
-               ver_addr = pci_alloc_consistent(acb->pdev, 1032, &buf_handle);
-               if (!ver_addr) {
+               tmp = kmalloc(1032, GFP_KERNEL|GFP_DMA);
+               ver_addr = (unsigned long *)tmp;
+               if (!tmp) {
                        retvalue = ARCMSR_MESSAGE_FAIL;
                        goto message_out;
                }
@@ -1421,18 +1430,19 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, \
                memcpy(pcmdmessagefld->messagedatabuffer, (uint8_t *)ver_addr, allxfer_len);
                pcmdmessagefld->cmdmessage.Length = allxfer_len;
                pcmdmessagefld->cmdmessage.ReturnCode = ARCMSR_MESSAGE_RETURNCODE_OK;
-               pci_free_consistent(acb->pdev, 1032, ver_addr, buf_handle);
+               kfree(tmp);
                }
                break;
 
        case ARCMSR_MESSAGE_WRITE_WQBUFFER: {
                unsigned long *ver_addr;
-               dma_addr_t buf_handle;
                int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex;
                uint8_t *pQbuffer, *ptmpuserbuffer;
+               void *tmp;
 
-               ver_addr = pci_alloc_consistent(acb->pdev, 1032, &buf_handle);
-               if (!ver_addr) {
+               tmp = kmalloc(1032, GFP_KERNEL|GFP_DMA);
+               ver_addr = (unsigned long *)tmp;
+               if (!tmp) {
                        retvalue = ARCMSR_MESSAGE_FAIL;
                        goto message_out;
                }
@@ -1482,7 +1492,7 @@ static int arcmsr_iop_message_xfer(struct AdapterControlBlock *acb, \
                                retvalue = ARCMSR_MESSAGE_FAIL;
                        }
                        }
-                       pci_free_consistent(acb->pdev, 1032, ver_addr, buf_handle);
+                       kfree(tmp);
                }
                break;
 
@@ -1682,8 +1692,11 @@ static int arcmsr_queue_command(struct scsi_cmnd *cmd,
        ccb = arcmsr_get_freeccb(acb);
        if (!ccb)
                return SCSI_MLQUEUE_HOST_BUSY;
-
-       arcmsr_build_ccb(acb, ccb, cmd);
+       if ( arcmsr_build_ccb( acb, ccb, cmd ) == FAILED ) {
+               cmd->result = (DID_ERROR << 16) | (RESERVATION_CONFLICT << 1);
+               cmd->scsi_done(cmd);
+               return 0;
+       }
        arcmsr_post_ccb(acb, ccb);
        return 0;
 }
@@ -1844,7 +1857,7 @@ static void arcmsr_polling_hba_ccbdone(struct AdapterControlBlock *acb,
        }
 }
 
-static void arcmsr_polling_hbb_ccbdone(struct AdapterControlBlock *acb, \
+static void arcmsr_polling_hbb_ccbdone(struct AdapterControlBlock *acb,
                                        struct CommandControlBlock *poll_ccb)
 {
                struct MessageUnit_B *reg = acb->pmuB;
@@ -1878,7 +1891,7 @@ static void arcmsr_polling_hbb_ccbdone(struct AdapterControlBlock *acb, \
       (acb->vir2phy_offset + (flag_ccb << 5));/*frame must be 32 bytes aligned*/
                        poll_ccb_done = (ccb == poll_ccb) ? 1:0;
                        if ((ccb->acb != acb) || (ccb->startdone != ARCMSR_CCB_START)) {
-                               if (ccb->startdone == ARCMSR_CCB_ABORTED) {
+                               if ((ccb->startdone == ARCMSR_CCB_ABORTED) || (ccb == poll_ccb)) {
                                        printk(KERN_NOTICE "arcmsr%d: \
                scsi id = %d lun = %d ccb = '0x%p' poll command abort successfully \n"
                                                ,acb->host->host_no
@@ -1901,7 +1914,7 @@ static void arcmsr_polling_hbb_ccbdone(struct AdapterControlBlock *acb, \
                }       /*drain reply FIFO*/
 }
 
-static void arcmsr_polling_ccbdone(struct AdapterControlBlock *acb, \
+static void arcmsr_polling_ccbdone(struct AdapterControlBlock *acb,
                                        struct CommandControlBlock *poll_ccb)
 {
        switch (acb->adapter_type) {
@@ -2026,6 +2039,7 @@ static void arcmsr_wait_firmware_ready(struct AdapterControlBlock *acb)
                do {
                        firmware_state = readl(reg->iop2drv_doorbell_reg);
                } while ((firmware_state & ARCMSR_MESSAGE_FIRMWARE_OK) == 0);
+               writel(ARCMSR_DRV2IOP_END_OF_INTERRUPT, reg->drv2iop_doorbell_reg);
                }
                break;
        }
@@ -2090,19 +2104,39 @@ static void arcmsr_clear_doorbell_queue_buffer(struct AdapterControlBlock *acb)
        }
 }
 
+static void arcmsr_enable_eoi_mode(struct AdapterControlBlock *acb)
+{
+       switch (acb->adapter_type) {
+       case ACB_ADAPTER_TYPE_A:
+               return;
+       case ACB_ADAPTER_TYPE_B:
+               {
+                       struct MessageUnit_B *reg = acb->pmuB;
+                       writel(ARCMSR_MESSAGE_ACTIVE_EOI_MODE, reg->drv2iop_doorbell_reg);
+                       if(arcmsr_hbb_wait_msgint_ready(acb)) {
+                               printk(KERN_NOTICE "ARCMSR IOP enables EOI_MODE TIMEOUT");
+                               return;
+                       }
+               }
+               break;
+       }
+       return;
+}
+
 static void arcmsr_iop_init(struct AdapterControlBlock *acb)
 {
        uint32_t intmask_org;
 
-       arcmsr_wait_firmware_ready(acb);
-       arcmsr_iop_confirm(acb);
        /* disable all outbound interrupt */
        intmask_org = arcmsr_disable_outbound_ints(acb);
+       arcmsr_wait_firmware_ready(acb);
+       arcmsr_iop_confirm(acb);
        arcmsr_get_firmware_spec(acb);
        /*start background rebuild*/
        arcmsr_start_adapter_bgrb(acb);
        /* empty doorbell Qbuffer if door bell ringed */
        arcmsr_clear_doorbell_queue_buffer(acb);
+       arcmsr_enable_eoi_mode(acb);
        /* enable outbound Post Queue,outbound doorbell Interrupt */
        arcmsr_enable_outbound_ints(acb, intmask_org);
        acb->acb_flags |= ACB_F_IOP_INITED;
@@ -2275,6 +2309,7 @@ static pci_ers_result_t arcmsr_pci_slot_reset(struct pci_dev *pdev)
        arcmsr_start_adapter_bgrb(acb);
        /* empty doorbell Qbuffer if door bell ringed */
        arcmsr_clear_doorbell_queue_buffer(acb);
+       arcmsr_enable_eoi_mode(acb);
        /* enable outbound Post Queue,outbound doorbell Interrupt */
        arcmsr_enable_outbound_ints(acb, intmask_org);
        acb->acb_flags |= ACB_F_IOP_INITED;
index eceacf6d49eacb6da78c9c9e180f3e05ef641345..3bedf2466bd1fdcca6b9e07391535843d2f63701 100644 (file)
@@ -1790,7 +1790,7 @@ int acornscsi_starttransfer(AS_Host *host)
        return 0;
     }
 
-    residual = host->SCpnt->request_bufflen - host->scsi.SCp.scsi_xferred;
+    residual = scsi_bufflen(host->SCpnt) - host->scsi.SCp.scsi_xferred;
 
     sbic_arm_write(host->scsi.io_port, SBIC_SYNCHTRANSFER, host->device[host->SCpnt->device->id].sync_xfer);
     sbic_arm_writenext(host->scsi.io_port, residual >> 16);
@@ -2270,7 +2270,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
        case 0x4b:                      /* -> PHASE_STATUSIN                            */
        case 0x8b:                      /* -> PHASE_STATUSIN                            */
            /* DATA IN -> STATUS */
-           host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen -
+           host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
                                          acornscsi_sbic_xfcount(host);
            acornscsi_dma_stop(host);
            acornscsi_readstatusbyte(host);
@@ -2281,7 +2281,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
        case 0x4e:                      /* -> PHASE_MSGOUT                              */
        case 0x8e:                      /* -> PHASE_MSGOUT                              */
            /* DATA IN -> MESSAGE OUT */
-           host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen -
+           host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
                                          acornscsi_sbic_xfcount(host);
            acornscsi_dma_stop(host);
            acornscsi_sendmessage(host);
@@ -2291,7 +2291,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
        case 0x4f:                      /* message in                                   */
        case 0x8f:                      /* message in                                   */
            /* DATA IN -> MESSAGE IN */
-           host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen -
+           host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
                                          acornscsi_sbic_xfcount(host);
            acornscsi_dma_stop(host);
            acornscsi_message(host);    /* -> PHASE_MSGIN, PHASE_DISCONNECT             */
@@ -2319,7 +2319,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
        case 0x4b:                      /* -> PHASE_STATUSIN                            */
        case 0x8b:                      /* -> PHASE_STATUSIN                            */
            /* DATA OUT -> STATUS */
-           host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen -
+           host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
                                          acornscsi_sbic_xfcount(host);
            acornscsi_dma_stop(host);
            acornscsi_dma_adjust(host);
@@ -2331,7 +2331,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
        case 0x4e:                      /* -> PHASE_MSGOUT                              */
        case 0x8e:                      /* -> PHASE_MSGOUT                              */
            /* DATA OUT -> MESSAGE OUT */
-           host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen -
+           host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
                                          acornscsi_sbic_xfcount(host);
            acornscsi_dma_stop(host);
            acornscsi_dma_adjust(host);
@@ -2342,7 +2342,7 @@ intr_ret_t acornscsi_sbicintr(AS_Host *host, int in_irq)
        case 0x4f:                      /* message in                                   */
        case 0x8f:                      /* message in                                   */
            /* DATA OUT -> MESSAGE IN */
-           host->scsi.SCp.scsi_xferred = host->SCpnt->request_bufflen -
+           host->scsi.SCp.scsi_xferred = scsi_bufflen(host->SCpnt) -
                                          acornscsi_sbic_xfcount(host);
            acornscsi_dma_stop(host);
            acornscsi_dma_adjust(host);
index bb6550e31926d4a2752a1f7984d3d2978950fd42..138a521ba1a81c238c2ff817630c107a38a5771c 100644 (file)
  * The scatter-gather list handling.  This contains all
  * the yucky stuff that needs to be fixed properly.
  */
+
+/*
+ * copy_SCp_to_sg() Assumes contiguous allocation at @sg of at-most @max
+ * entries of uninitialized memory. SCp is from scsi-ml and has a valid
+ * (possibly chained) sg-list
+ */
 static inline int copy_SCp_to_sg(struct scatterlist *sg, struct scsi_pointer *SCp, int max)
 {
        int bufs = SCp->buffers_residual;
 
+       /* FIXME: It should be easy for drivers to loop on copy_SCp_to_sg().
+        * and to remove this BUG_ON. Use min() in-its-place
+        */
        BUG_ON(bufs + 1 > max);
 
        sg_set_buf(sg, SCp->ptr, SCp->this_residual);
 
-       if (bufs)
-               memcpy(sg + 1, SCp->buffer + 1,
-                      sizeof(struct scatterlist) * bufs);
+       if (bufs) {
+               struct scatterlist *src_sg;
+               unsigned i;
+
+               for_each_sg(sg_next(SCp->buffer), src_sg, bufs, i)
+                       *(++sg) = *src_sg;
+               sg_mark_end(sg);
+       }
+
        return bufs + 1;
 }
 
@@ -36,7 +51,7 @@ static inline int next_SCp(struct scsi_pointer *SCp)
 {
        int ret = SCp->buffers_residual;
        if (ret) {
-               SCp->buffer++;
+               SCp->buffer = sg_next(SCp->buffer);
                SCp->buffers_residual--;
                SCp->ptr = sg_virt(SCp->buffer);
                SCp->this_residual = SCp->buffer->length;
@@ -68,46 +83,46 @@ static inline void init_SCp(struct scsi_cmnd *SCpnt)
 {
        memset(&SCpnt->SCp, 0, sizeof(struct scsi_pointer));
 
-       if (SCpnt->use_sg) {
+       if (scsi_bufflen(SCpnt)) {
                unsigned long len = 0;
-               int buf;
 
-               SCpnt->SCp.buffer = (struct scatterlist *) SCpnt->request_buffer;
-               SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1;
+               SCpnt->SCp.buffer = scsi_sglist(SCpnt);
+               SCpnt->SCp.buffers_residual = scsi_sg_count(SCpnt) - 1;
                SCpnt->SCp.ptr = sg_virt(SCpnt->SCp.buffer);
                SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
-               SCpnt->SCp.phase = SCpnt->request_bufflen;
+               SCpnt->SCp.phase = scsi_bufflen(SCpnt);
 
 #ifdef BELT_AND_BRACES
-               /*
-                * Calculate correct buffer length.  Some commands
-                * come in with the wrong request_bufflen.
-                */
-               for (buf = 0; buf <= SCpnt->SCp.buffers_residual; buf++)
-                       len += SCpnt->SCp.buffer[buf].length;
-
-               if (SCpnt->request_bufflen != len)
-                       printk(KERN_WARNING "scsi%d.%c: bad request buffer "
-                              "length %d, should be %ld\n", SCpnt->device->host->host_no,
-                              '0' + SCpnt->device->id, SCpnt->request_bufflen, len);
-               SCpnt->request_bufflen = len;
+               {       /*
+                        * Calculate correct buffer length.  Some commands
+                        * come in with the wrong scsi_bufflen.
+                        */
+                       struct scatterlist *sg;
+                       unsigned i, sg_count = scsi_sg_count(SCpnt);
+
+                       scsi_for_each_sg(SCpnt, sg, sg_count, i)
+                               len += sg->length;
+
+                       if (scsi_bufflen(SCpnt) != len) {
+                               printk(KERN_WARNING
+                                      "scsi%d.%c: bad request buffer "
+                                      "length %d, should be %ld\n",
+                                       SCpnt->device->host->host_no,
+                                       '0' + SCpnt->device->id,
+                                       scsi_bufflen(SCpnt), len);
+                               /*
+                                * FIXME: Totaly naive fixup. We should abort
+                                * with error
+                                */
+                               SCpnt->SCp.phase =
+                                       min_t(unsigned long, len,
+                                             scsi_bufflen(SCpnt));
+                       }
+               }
 #endif
        } else {
-               SCpnt->SCp.ptr = (unsigned char *)SCpnt->request_buffer;
-               SCpnt->SCp.this_residual = SCpnt->request_bufflen;
-               SCpnt->SCp.phase = SCpnt->request_bufflen;
-       }
-
-       /*
-        * If the upper SCSI layers pass a buffer, but zero length,
-        * we aren't interested in the buffer pointer.
-        */
-       if (SCpnt->SCp.this_residual == 0 && SCpnt->SCp.ptr) {
-#if 0 //def BELT_AND_BRACES
-               printk(KERN_WARNING "scsi%d.%c: zero length buffer passed for "
-                      "command ", SCpnt->host->host_no, '0' + SCpnt->target);
-               __scsi_print_command(SCpnt->cmnd);
-#endif
                SCpnt->SCp.ptr = NULL;
+               SCpnt->SCp.this_residual = 0;
+               SCpnt->SCp.phase = 0;
        }
 }
diff --git a/drivers/scsi/blz1230.c b/drivers/scsi/blz1230.c
deleted file mode 100644 (file)
index 23f7c24..0000000
+++ /dev/null
@@ -1,353 +0,0 @@
-/* blz1230.c: Driver for Blizzard 1230 SCSI IV Controller.
- *
- * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
- *
- * This driver is based on the CyberStorm driver, hence the occasional
- * reference to CyberStorm.
- */
-
-/* TODO:
- *
- * 1) Figure out how to make a cleaner merge with the sparc driver with regard
- *    to the caches and the Sparc MMU mapping.
- * 2) Make as few routines required outside the generic driver. A lot of the
- *    routines in this file used to be inline!
- */
-
-#include <linux/module.h>
-
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/types.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <linux/blkdev.h>
-#include <linux/proc_fs.h>
-#include <linux/stat.h>
-#include <linux/interrupt.h>
-
-#include "scsi.h"
-#include <scsi/scsi_host.h>
-#include "NCR53C9x.h"
-
-#include <linux/zorro.h>
-#include <asm/irq.h>
-#include <asm/amigaints.h>
-#include <asm/amigahw.h>
-
-#include <asm/pgtable.h>
-
-#define MKIV 1
-
-/* The controller registers can be found in the Z2 config area at these
- * offsets:
- */
-#define BLZ1230_ESP_ADDR 0x8000
-#define BLZ1230_DMA_ADDR 0x10000
-#define BLZ1230II_ESP_ADDR 0x10000
-#define BLZ1230II_DMA_ADDR 0x10021
-
-
-/* The Blizzard 1230 DMA interface
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- * Only two things can be programmed in the Blizzard DMA:
- *  1) The data direction is controlled by the status of bit 31 (1 = write)
- *  2) The source/dest address (word aligned, shifted one right) in bits 30-0
- *
- * Program DMA by first latching the highest byte of the address/direction
- * (i.e. bits 31-24 of the long word constructed as described in steps 1+2
- * above). Then write each byte of the address/direction (starting with the
- * top byte, working down) to the DMA address register.
- *
- * Figure out interrupt status by reading the ESP status byte.
- */
-struct blz1230_dma_registers {
-       volatile unsigned char dma_addr;        /* DMA address      [0x0000] */
-       unsigned char dmapad2[0x7fff];
-       volatile unsigned char dma_latch;       /* DMA latch        [0x8000] */
-};
-
-struct blz1230II_dma_registers {
-       volatile unsigned char dma_addr;        /* DMA address      [0x0000] */
-       unsigned char dmapad2[0xf];
-       volatile unsigned char dma_latch;       /* DMA latch        [0x0010] */
-};
-
-#define BLZ1230_DMA_WRITE 0x80000000
-
-static int  dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
-static int  dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
-static void dma_dump_state(struct NCR_ESP *esp);
-static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
-static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length);
-static void dma_ints_off(struct NCR_ESP *esp);
-static void dma_ints_on(struct NCR_ESP *esp);
-static int  dma_irq_p(struct NCR_ESP *esp);
-static int  dma_ports_p(struct NCR_ESP *esp);
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
-
-static volatile unsigned char cmd_buffer[16];
-                               /* This is where all commands are put
-                                * before they are transferred to the ESP chip
-                                * via PIO.
-                                */
-
-/***************************************************************** Detection */
-int __init blz1230_esp_detect(struct scsi_host_template *tpnt)
-{
-       struct NCR_ESP *esp;
-       struct zorro_dev *z = NULL;
-       unsigned long address;
-       struct ESP_regs *eregs;
-       unsigned long board;
-
-#if MKIV
-#define REAL_BLZ1230_ID                ZORRO_PROD_PHASE5_BLIZZARD_1230_IV_1260
-#define REAL_BLZ1230_ESP_ADDR  BLZ1230_ESP_ADDR
-#define REAL_BLZ1230_DMA_ADDR  BLZ1230_DMA_ADDR
-#else
-#define REAL_BLZ1230_ID                ZORRO_PROD_PHASE5_BLIZZARD_1230_II_FASTLANE_Z3_CYBERSCSI_CYBERSTORM060
-#define REAL_BLZ1230_ESP_ADDR  BLZ1230II_ESP_ADDR
-#define REAL_BLZ1230_DMA_ADDR  BLZ1230II_DMA_ADDR
-#endif
-
-       if ((z = zorro_find_device(REAL_BLZ1230_ID, z))) {
-           board = z->resource.start;
-           if (request_mem_region(board+REAL_BLZ1230_ESP_ADDR,
-                                  sizeof(struct ESP_regs), "NCR53C9x")) {
-               /* Do some magic to figure out if the blizzard is
-                * equipped with a SCSI controller
-                */
-               address = ZTWO_VADDR(board);
-               eregs = (struct ESP_regs *)(address + REAL_BLZ1230_ESP_ADDR);
-               esp = esp_allocate(tpnt, (void *)board + REAL_BLZ1230_ESP_ADDR,
-                                  0);
-
-               esp_write(eregs->esp_cfg1, (ESP_CONFIG1_PENABLE | 7));
-               udelay(5);
-               if(esp_read(eregs->esp_cfg1) != (ESP_CONFIG1_PENABLE | 7))
-                       goto err_out;
-
-               /* Do command transfer with programmed I/O */
-               esp->do_pio_cmds = 1;
-
-               /* Required functions */
-               esp->dma_bytes_sent = &dma_bytes_sent;
-               esp->dma_can_transfer = &dma_can_transfer;
-               esp->dma_dump_state = &dma_dump_state;
-               esp->dma_init_read = &dma_init_read;
-               esp->dma_init_write = &dma_init_write;
-               esp->dma_ints_off = &dma_ints_off;
-               esp->dma_ints_on = &dma_ints_on;
-               esp->dma_irq_p = &dma_irq_p;
-               esp->dma_ports_p = &dma_ports_p;
-               esp->dma_setup = &dma_setup;
-
-               /* Optional functions */
-               esp->dma_barrier = 0;
-               esp->dma_drain = 0;
-               esp->dma_invalidate = 0;
-               esp->dma_irq_entry = 0;
-               esp->dma_irq_exit = 0;
-               esp->dma_led_on = 0;
-               esp->dma_led_off = 0;
-               esp->dma_poll = 0;
-               esp->dma_reset = 0;
-
-               /* SCSI chip speed */
-               esp->cfreq = 40000000;
-
-               /* The DMA registers on the Blizzard are mapped
-                * relative to the device (i.e. in the same Zorro
-                * I/O block).
-                */
-               esp->dregs = (void *)(address + REAL_BLZ1230_DMA_ADDR);
-       
-               /* ESP register base */
-               esp->eregs = eregs;
-
-               /* Set the command buffer */
-               esp->esp_command = cmd_buffer;
-               esp->esp_command_dvma = virt_to_bus((void *)cmd_buffer);
-
-               esp->irq = IRQ_AMIGA_PORTS;
-               esp->slot = board+REAL_BLZ1230_ESP_ADDR;
-               if (request_irq(IRQ_AMIGA_PORTS, esp_intr, IRQF_SHARED,
-                                "Blizzard 1230 SCSI IV", esp->ehost))
-                       goto err_out;
-
-               /* Figure out our scsi ID on the bus */
-               esp->scsi_id = 7;
-               
-               /* We don't have a differential SCSI-bus. */
-               esp->diff = 0;
-
-               esp_initialize(esp);
-
-               printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
-               esps_running = esps_in_use;
-               return esps_in_use;
-           }
-       }
-       return 0;
- err_out:
-       scsi_unregister(esp->ehost);
-       esp_deallocate(esp);
-       release_mem_region(board+REAL_BLZ1230_ESP_ADDR,
-                          sizeof(struct ESP_regs));
-       return 0;
-}
-
-/************************************************************* DMA Functions */
-static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
-{
-       /* Since the Blizzard DMA is fully dedicated to the ESP chip,
-        * the number of bytes sent (to the ESP chip) equals the number
-        * of bytes in the FIFO - there is no buffering in the DMA controller.
-        * XXXX Do I read this right? It is from host to ESP, right?
-        */
-       return fifo_count;
-}
-
-static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-       /* I don't think there's any limit on the Blizzard DMA. So we use what
-        * the ESP chip can handle (24 bit).
-        */
-       unsigned long sz = sp->SCp.this_residual;
-       if(sz > 0x1000000)
-               sz = 0x1000000;
-       return sz;
-}
-
-static void dma_dump_state(struct NCR_ESP *esp)
-{
-       ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
-               amiga_custom.intreqr, amiga_custom.intenar));
-}
-
-void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
-{
-#if MKIV
-       struct blz1230_dma_registers *dregs = 
-               (struct blz1230_dma_registers *) (esp->dregs);
-#else
-       struct blz1230II_dma_registers *dregs = 
-               (struct blz1230II_dma_registers *) (esp->dregs);
-#endif
-
-       cache_clear(addr, length);
-
-       addr >>= 1;
-       addr &= ~(BLZ1230_DMA_WRITE);
-
-       /* First set latch */
-       dregs->dma_latch = (addr >> 24) & 0xff;
-
-       /* Then pump the address to the DMA address register */
-#if MKIV
-       dregs->dma_addr = (addr >> 24) & 0xff;
-#endif
-       dregs->dma_addr = (addr >> 16) & 0xff;
-       dregs->dma_addr = (addr >>  8) & 0xff;
-       dregs->dma_addr = (addr      ) & 0xff;
-}
-
-void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
-{
-#if MKIV
-       struct blz1230_dma_registers *dregs = 
-               (struct blz1230_dma_registers *) (esp->dregs);
-#else
-       struct blz1230II_dma_registers *dregs = 
-               (struct blz1230II_dma_registers *) (esp->dregs);
-#endif
-
-       cache_push(addr, length);
-
-       addr >>= 1;
-       addr |= BLZ1230_DMA_WRITE;
-
-       /* First set latch */
-       dregs->dma_latch = (addr >> 24) & 0xff;
-
-       /* Then pump the address to the DMA address register */
-#if MKIV
-       dregs->dma_addr = (addr >> 24) & 0xff;
-#endif
-       dregs->dma_addr = (addr >> 16) & 0xff;
-       dregs->dma_addr = (addr >>  8) & 0xff;
-       dregs->dma_addr = (addr      ) & 0xff;
-}
-
-static void dma_ints_off(struct NCR_ESP *esp)
-{
-       disable_irq(esp->irq);
-}
-
-static void dma_ints_on(struct NCR_ESP *esp)
-{
-       enable_irq(esp->irq);
-}
-
-static int dma_irq_p(struct NCR_ESP *esp)
-{
-       return (esp_read(esp->eregs->esp_status) & ESP_STAT_INTR);
-}
-
-static int dma_ports_p(struct NCR_ESP *esp)
-{
-       return ((amiga_custom.intenar) & IF_PORTS);
-}
-
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
-{
-       /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
-        * so when (write) is true, it actually means READ!
-        */
-       if(write){
-               dma_init_read(esp, addr, count);
-       } else {
-               dma_init_write(esp, addr, count);
-       }
-}
-
-#define HOSTS_C
-
-int blz1230_esp_release(struct Scsi_Host *instance)
-{
-#ifdef MODULE
-       unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
-       esp_deallocate((struct NCR_ESP *)instance->hostdata);
-       esp_release();
-       release_mem_region(address, sizeof(struct ESP_regs));
-       free_irq(IRQ_AMIGA_PORTS, esp_intr);
-#endif
-       return 1;
-}
-
-
-static struct scsi_host_template driver_template = {
-       .proc_name              = "esp-blz1230",
-       .proc_info              = esp_proc_info,
-       .name                   = "Blizzard1230 SCSI IV",
-       .detect                 = blz1230_esp_detect,
-       .slave_alloc            = esp_slave_alloc,
-       .slave_destroy          = esp_slave_destroy,
-       .release                = blz1230_esp_release,
-       .queuecommand           = esp_queue,
-       .eh_abort_handler       = esp_abort,
-       .eh_bus_reset_handler   = esp_reset,
-       .can_queue              = 7,
-       .this_id                = 7,
-       .sg_tablesize           = SG_ALL,
-       .cmd_per_lun            = 1,
-       .use_clustering         = ENABLE_CLUSTERING
-};
-
-
-#include "scsi_module.c"
-
-MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/blz2060.c b/drivers/scsi/blz2060.c
deleted file mode 100644 (file)
index b6203ec..0000000
+++ /dev/null
@@ -1,306 +0,0 @@
-/* blz2060.c: Driver for Blizzard 2060 SCSI Controller.
- *
- * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
- *
- * This driver is based on the CyberStorm driver, hence the occasional
- * reference to CyberStorm.
- */
-
-/* TODO:
- *
- * 1) Figure out how to make a cleaner merge with the sparc driver with regard
- *    to the caches and the Sparc MMU mapping.
- * 2) Make as few routines required outside the generic driver. A lot of the
- *    routines in this file used to be inline!
- */
-
-#include <linux/module.h>
-
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/types.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <linux/blkdev.h>
-#include <linux/proc_fs.h>
-#include <linux/stat.h>
-#include <linux/interrupt.h>
-
-#include "scsi.h"
-#include <scsi/scsi_host.h>
-#include "NCR53C9x.h"
-
-#include <linux/zorro.h>
-#include <asm/irq.h>
-#include <asm/amigaints.h>
-#include <asm/amigahw.h>
-
-#include <asm/pgtable.h>
-
-/* The controller registers can be found in the Z2 config area at these
- * offsets:
- */
-#define BLZ2060_ESP_ADDR 0x1ff00
-#define BLZ2060_DMA_ADDR 0x1ffe0
-
-
-/* The Blizzard 2060 DMA interface
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- * Only two things can be programmed in the Blizzard DMA:
- *  1) The data direction is controlled by the status of bit 31 (1 = write)
- *  2) The source/dest address (word aligned, shifted one right) in bits 30-0
- *
- * Figure out interrupt status by reading the ESP status byte.
- */
-struct blz2060_dma_registers {
-       volatile unsigned char dma_led_ctrl;    /* DMA led control   [0x000] */
-       unsigned char dmapad1[0x0f];
-       volatile unsigned char dma_addr0;       /* DMA address (MSB) [0x010] */
-       unsigned char dmapad2[0x03];
-       volatile unsigned char dma_addr1;       /* DMA address       [0x014] */
-       unsigned char dmapad3[0x03];
-       volatile unsigned char dma_addr2;       /* DMA address       [0x018] */
-       unsigned char dmapad4[0x03];
-       volatile unsigned char dma_addr3;       /* DMA address (LSB) [0x01c] */
-};
-
-#define BLZ2060_DMA_WRITE 0x80000000
-
-/* DMA control bits */
-#define BLZ2060_DMA_LED    0x02                /* HD led control 1 = off */
-
-static int  dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
-static int  dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
-static void dma_dump_state(struct NCR_ESP *esp);
-static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
-static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length);
-static void dma_ints_off(struct NCR_ESP *esp);
-static void dma_ints_on(struct NCR_ESP *esp);
-static int  dma_irq_p(struct NCR_ESP *esp);
-static void dma_led_off(struct NCR_ESP *esp);
-static void dma_led_on(struct NCR_ESP *esp);
-static int  dma_ports_p(struct NCR_ESP *esp);
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
-
-static volatile unsigned char cmd_buffer[16];
-                               /* This is where all commands are put
-                                * before they are transferred to the ESP chip
-                                * via PIO.
-                                */
-
-/***************************************************************** Detection */
-int __init blz2060_esp_detect(struct scsi_host_template *tpnt)
-{
-       struct NCR_ESP *esp;
-       struct zorro_dev *z = NULL;
-       unsigned long address;
-
-       if ((z = zorro_find_device(ZORRO_PROD_PHASE5_BLIZZARD_2060, z))) {
-           unsigned long board = z->resource.start;
-           if (request_mem_region(board+BLZ2060_ESP_ADDR,
-                                  sizeof(struct ESP_regs), "NCR53C9x")) {
-               esp = esp_allocate(tpnt, (void *)board + BLZ2060_ESP_ADDR, 0);
-
-               /* Do command transfer with programmed I/O */
-               esp->do_pio_cmds = 1;
-
-               /* Required functions */
-               esp->dma_bytes_sent = &dma_bytes_sent;
-               esp->dma_can_transfer = &dma_can_transfer;
-               esp->dma_dump_state = &dma_dump_state;
-               esp->dma_init_read = &dma_init_read;
-               esp->dma_init_write = &dma_init_write;
-               esp->dma_ints_off = &dma_ints_off;
-               esp->dma_ints_on = &dma_ints_on;
-               esp->dma_irq_p = &dma_irq_p;
-               esp->dma_ports_p = &dma_ports_p;
-               esp->dma_setup = &dma_setup;
-
-               /* Optional functions */
-               esp->dma_barrier = 0;
-               esp->dma_drain = 0;
-               esp->dma_invalidate = 0;
-               esp->dma_irq_entry = 0;
-               esp->dma_irq_exit = 0;
-               esp->dma_led_on = &dma_led_on;
-               esp->dma_led_off = &dma_led_off;
-               esp->dma_poll = 0;
-               esp->dma_reset = 0;
-
-               /* SCSI chip speed */
-               esp->cfreq = 40000000;
-
-               /* The DMA registers on the Blizzard are mapped
-                * relative to the device (i.e. in the same Zorro
-                * I/O block).
-                */
-               address = (unsigned long)ZTWO_VADDR(board);
-               esp->dregs = (void *)(address + BLZ2060_DMA_ADDR);
-
-               /* ESP register base */
-               esp->eregs = (struct ESP_regs *)(address + BLZ2060_ESP_ADDR);
-               
-               /* Set the command buffer */
-               esp->esp_command = cmd_buffer;
-               esp->esp_command_dvma = virt_to_bus((void *)cmd_buffer);
-
-               esp->irq = IRQ_AMIGA_PORTS;
-               request_irq(IRQ_AMIGA_PORTS, esp_intr, IRQF_SHARED,
-                           "Blizzard 2060 SCSI", esp->ehost);
-
-               /* Figure out our scsi ID on the bus */
-               esp->scsi_id = 7;
-               
-               /* We don't have a differential SCSI-bus. */
-               esp->diff = 0;
-
-               esp_initialize(esp);
-
-               printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
-               esps_running = esps_in_use;
-               return esps_in_use;
-           }
-       }
-       return 0;
-}
-
-/************************************************************* DMA Functions */
-static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
-{
-       /* Since the Blizzard DMA is fully dedicated to the ESP chip,
-        * the number of bytes sent (to the ESP chip) equals the number
-        * of bytes in the FIFO - there is no buffering in the DMA controller.
-        * XXXX Do I read this right? It is from host to ESP, right?
-        */
-       return fifo_count;
-}
-
-static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-       /* I don't think there's any limit on the Blizzard DMA. So we use what
-        * the ESP chip can handle (24 bit).
-        */
-       unsigned long sz = sp->SCp.this_residual;
-       if(sz > 0x1000000)
-               sz = 0x1000000;
-       return sz;
-}
-
-static void dma_dump_state(struct NCR_ESP *esp)
-{
-       ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
-               amiga_custom.intreqr, amiga_custom.intenar));
-}
-
-static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
-{
-       struct blz2060_dma_registers *dregs = 
-               (struct blz2060_dma_registers *) (esp->dregs);
-
-       cache_clear(addr, length);
-
-       addr >>= 1;
-       addr &= ~(BLZ2060_DMA_WRITE);
-       dregs->dma_addr3 = (addr      ) & 0xff;
-       dregs->dma_addr2 = (addr >>  8) & 0xff;
-       dregs->dma_addr1 = (addr >> 16) & 0xff;
-       dregs->dma_addr0 = (addr >> 24) & 0xff;
-}
-
-static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
-{
-       struct blz2060_dma_registers *dregs = 
-               (struct blz2060_dma_registers *) (esp->dregs);
-
-       cache_push(addr, length);
-
-       addr >>= 1;
-       addr |= BLZ2060_DMA_WRITE;
-       dregs->dma_addr3 = (addr      ) & 0xff;
-       dregs->dma_addr2 = (addr >>  8) & 0xff;
-       dregs->dma_addr1 = (addr >> 16) & 0xff;
-       dregs->dma_addr0 = (addr >> 24) & 0xff;
-}
-
-static void dma_ints_off(struct NCR_ESP *esp)
-{
-       disable_irq(esp->irq);
-}
-
-static void dma_ints_on(struct NCR_ESP *esp)
-{
-       enable_irq(esp->irq);
-}
-
-static int dma_irq_p(struct NCR_ESP *esp)
-{
-       return (esp_read(esp->eregs->esp_status) & ESP_STAT_INTR);
-}
-
-static void dma_led_off(struct NCR_ESP *esp)
-{
-       ((struct blz2060_dma_registers *) (esp->dregs))->dma_led_ctrl =
-               BLZ2060_DMA_LED;
-}
-
-static void dma_led_on(struct NCR_ESP *esp)
-{
-       ((struct blz2060_dma_registers *) (esp->dregs))->dma_led_ctrl = 0;
-}
-
-static int dma_ports_p(struct NCR_ESP *esp)
-{
-       return ((amiga_custom.intenar) & IF_PORTS);
-}
-
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
-{
-       /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
-        * so when (write) is true, it actually means READ!
-        */
-       if(write){
-               dma_init_read(esp, addr, count);
-       } else {
-               dma_init_write(esp, addr, count);
-       }
-}
-
-#define HOSTS_C
-
-int blz2060_esp_release(struct Scsi_Host *instance)
-{
-#ifdef MODULE
-       unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
-
-       esp_deallocate((struct NCR_ESP *)instance->hostdata);
-       esp_release();
-       release_mem_region(address, sizeof(struct ESP_regs));
-       free_irq(IRQ_AMIGA_PORTS, esp_intr);
-#endif
-       return 1;
-}
-
-
-static struct scsi_host_template driver_template = {
-       .proc_name              = "esp-blz2060",
-       .proc_info              = esp_proc_info,
-       .name                   = "Blizzard2060 SCSI",
-       .detect                 = blz2060_esp_detect,
-       .slave_alloc            = esp_slave_alloc,
-       .slave_destroy          = esp_slave_destroy,
-       .release                = blz2060_esp_release,
-       .queuecommand           = esp_queue,
-       .eh_abort_handler       = esp_abort,
-       .eh_bus_reset_handler   = esp_reset,
-       .can_queue              = 7,
-       .this_id                = 7,
-       .sg_tablesize           = SG_ALL,
-       .cmd_per_lun            = 1,
-       .use_clustering         = ENABLE_CLUSTERING
-};
-
-
-#include "scsi_module.c"
-
-MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/cyberstorm.c b/drivers/scsi/cyberstorm.c
deleted file mode 100644 (file)
index c6b98a4..0000000
+++ /dev/null
@@ -1,377 +0,0 @@
-/* cyberstorm.c: Driver for CyberStorm SCSI Controller.
- *
- * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
- *
- * The CyberStorm SCSI driver is based on David S. Miller's ESP driver
- * for the Sparc computers. 
- * 
- * This work was made possible by Phase5 who willingly (and most generously)
- * supported me with hardware and all the information I needed.
- */
-
-/* TODO:
- *
- * 1) Figure out how to make a cleaner merge with the sparc driver with regard
- *    to the caches and the Sparc MMU mapping.
- * 2) Make as few routines required outside the generic driver. A lot of the
- *    routines in this file used to be inline!
- */
-
-#include <linux/module.h>
-
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/types.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <linux/blkdev.h>
-#include <linux/proc_fs.h>
-#include <linux/stat.h>
-#include <linux/interrupt.h>
-
-#include "scsi.h"
-#include <scsi/scsi_host.h>
-#include "NCR53C9x.h"
-
-#include <linux/zorro.h>
-#include <asm/irq.h>
-#include <asm/amigaints.h>
-#include <asm/amigahw.h>
-
-#include <asm/pgtable.h>
-
-/* The controller registers can be found in the Z2 config area at these
- * offsets:
- */
-#define CYBER_ESP_ADDR 0xf400
-#define CYBER_DMA_ADDR 0xf800
-
-
-/* The CyberStorm DMA interface */
-struct cyber_dma_registers {
-       volatile unsigned char dma_addr0;       /* DMA address (MSB) [0x000] */
-       unsigned char dmapad1[1];
-       volatile unsigned char dma_addr1;       /* DMA address       [0x002] */
-       unsigned char dmapad2[1];
-       volatile unsigned char dma_addr2;       /* DMA address       [0x004] */
-       unsigned char dmapad3[1];
-       volatile unsigned char dma_addr3;       /* DMA address (LSB) [0x006] */
-       unsigned char dmapad4[0x3fb];
-       volatile unsigned char cond_reg;        /* DMA cond    (ro)  [0x402] */
-#define ctrl_reg  cond_reg                     /* DMA control (wo)  [0x402] */
-};
-
-/* DMA control bits */
-#define CYBER_DMA_LED    0x80  /* HD led control 1 = on */
-#define CYBER_DMA_WRITE  0x40  /* DMA direction. 1 = write */
-#define CYBER_DMA_Z3     0x20  /* 16 (Z2) or 32 (CHIP/Z3) bit DMA transfer */
-
-/* DMA status bits */
-#define CYBER_DMA_HNDL_INTR 0x80       /* DMA IRQ pending? */
-
-/* The bits below appears to be Phase5 Debug bits only; they were not
- * described by Phase5 so using them may seem a bit stupid...
- */
-#define CYBER_HOST_ID 0x02     /* If set, host ID should be 7, otherwise
-                                * it should be 6.
-                                */
-#define CYBER_SLOW_CABLE 0x08  /* If *not* set, assume SLOW_CABLE */
-
-static int  dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
-static int  dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
-static void dma_dump_state(struct NCR_ESP *esp);
-static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
-static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length);
-static void dma_ints_off(struct NCR_ESP *esp);
-static void dma_ints_on(struct NCR_ESP *esp);
-static int  dma_irq_p(struct NCR_ESP *esp);
-static void dma_led_off(struct NCR_ESP *esp);
-static void dma_led_on(struct NCR_ESP *esp);
-static int  dma_ports_p(struct NCR_ESP *esp);
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
-
-static unsigned char ctrl_data = 0;    /* Keep backup of the stuff written
-                                * to ctrl_reg. Always write a copy
-                                * to this register when writing to
-                                * the hardware register!
-                                */
-
-static volatile unsigned char cmd_buffer[16];
-                               /* This is where all commands are put
-                                * before they are transferred to the ESP chip
-                                * via PIO.
-                                */
-
-/***************************************************************** Detection */
-int __init cyber_esp_detect(struct scsi_host_template *tpnt)
-{
-       struct NCR_ESP *esp;
-       struct zorro_dev *z = NULL;
-       unsigned long address;
-
-       while ((z = zorro_find_device(ZORRO_WILDCARD, z))) {
-           unsigned long board = z->resource.start;
-           if ((z->id == ZORRO_PROD_PHASE5_BLIZZARD_1220_CYBERSTORM ||
-                z->id == ZORRO_PROD_PHASE5_BLIZZARD_1230_II_FASTLANE_Z3_CYBERSCSI_CYBERSTORM060) &&
-               request_mem_region(board+CYBER_ESP_ADDR,
-                                  sizeof(struct ESP_regs), "NCR53C9x")) {
-               /* Figure out if this is a CyberStorm or really a 
-                * Fastlane/Blizzard Mk II by looking at the board size.
-                * CyberStorm maps 64kB
-                * (ZORRO_PROD_PHASE5_BLIZZARD_1220_CYBERSTORM does anyway)
-                */
-               if(z->resource.end-board != 0xffff) {
-                       release_mem_region(board+CYBER_ESP_ADDR,
-                                          sizeof(struct ESP_regs));
-                       return 0;
-               }
-               esp = esp_allocate(tpnt, (void *)board + CYBER_ESP_ADDR, 0);
-
-               /* Do command transfer with programmed I/O */
-               esp->do_pio_cmds = 1;
-
-               /* Required functions */
-               esp->dma_bytes_sent = &dma_bytes_sent;
-               esp->dma_can_transfer = &dma_can_transfer;
-               esp->dma_dump_state = &dma_dump_state;
-               esp->dma_init_read = &dma_init_read;
-               esp->dma_init_write = &dma_init_write;
-               esp->dma_ints_off = &dma_ints_off;
-               esp->dma_ints_on = &dma_ints_on;
-               esp->dma_irq_p = &dma_irq_p;
-               esp->dma_ports_p = &dma_ports_p;
-               esp->dma_setup = &dma_setup;
-
-               /* Optional functions */
-               esp->dma_barrier = 0;
-               esp->dma_drain = 0;
-               esp->dma_invalidate = 0;
-               esp->dma_irq_entry = 0;
-               esp->dma_irq_exit = 0;
-               esp->dma_led_on = &dma_led_on;
-               esp->dma_led_off = &dma_led_off;
-               esp->dma_poll = 0;
-               esp->dma_reset = 0;
-
-               /* SCSI chip speed */
-               esp->cfreq = 40000000;
-
-               /* The DMA registers on the CyberStorm are mapped
-                * relative to the device (i.e. in the same Zorro
-                * I/O block).
-                */
-               address = (unsigned long)ZTWO_VADDR(board);
-               esp->dregs = (void *)(address + CYBER_DMA_ADDR);
-
-               /* ESP register base */
-               esp->eregs = (struct ESP_regs *)(address + CYBER_ESP_ADDR);
-               
-               /* Set the command buffer */
-               esp->esp_command = cmd_buffer;
-               esp->esp_command_dvma = virt_to_bus((void *)cmd_buffer);
-
-               esp->irq = IRQ_AMIGA_PORTS;
-               request_irq(IRQ_AMIGA_PORTS, esp_intr, IRQF_SHARED,
-                           "CyberStorm SCSI", esp->ehost);
-               /* Figure out our scsi ID on the bus */
-               /* The DMA cond flag contains a hardcoded jumper bit
-                * which can be used to select host number 6 or 7.
-                * However, even though it may change, we use a hardcoded
-                * value of 7.
-                */
-               esp->scsi_id = 7;
-               
-               /* We don't have a differential SCSI-bus. */
-               esp->diff = 0;
-
-               esp_initialize(esp);
-
-               printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
-               esps_running = esps_in_use;
-               return esps_in_use;
-           }
-       }
-       return 0;
-}
-
-/************************************************************* DMA Functions */
-static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
-{
-       /* Since the CyberStorm DMA is fully dedicated to the ESP chip,
-        * the number of bytes sent (to the ESP chip) equals the number
-        * of bytes in the FIFO - there is no buffering in the DMA controller.
-        * XXXX Do I read this right? It is from host to ESP, right?
-        */
-       return fifo_count;
-}
-
-static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-       /* I don't think there's any limit on the CyberDMA. So we use what
-        * the ESP chip can handle (24 bit).
-        */
-       unsigned long sz = sp->SCp.this_residual;
-       if(sz > 0x1000000)
-               sz = 0x1000000;
-       return sz;
-}
-
-static void dma_dump_state(struct NCR_ESP *esp)
-{
-       ESPLOG(("esp%d: dma -- cond_reg<%02x>\n",
-               esp->esp_id, ((struct cyber_dma_registers *)
-                             (esp->dregs))->cond_reg));
-       ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
-               amiga_custom.intreqr, amiga_custom.intenar));
-}
-
-static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
-{
-       struct cyber_dma_registers *dregs = 
-               (struct cyber_dma_registers *) esp->dregs;
-
-       cache_clear(addr, length);
-
-       addr &= ~(1);
-       dregs->dma_addr0 = (addr >> 24) & 0xff;
-       dregs->dma_addr1 = (addr >> 16) & 0xff;
-       dregs->dma_addr2 = (addr >>  8) & 0xff;
-       dregs->dma_addr3 = (addr      ) & 0xff;
-       ctrl_data &= ~(CYBER_DMA_WRITE);
-
-       /* Check if physical address is outside Z2 space and of
-        * block length/block aligned in memory. If this is the
-        * case, enable 32 bit transfer. In all other cases, fall back
-        * to 16 bit transfer.
-        * Obviously 32 bit transfer should be enabled if the DMA address
-        * and length are 32 bit aligned. However, this leads to some
-        * strange behavior. Even 64 bit aligned addr/length fails.
-        * Until I've found a reason for this, 32 bit transfer is only
-        * used for full-block transfers (1kB).
-        *                                                      -jskov
-        */
-#if 0
-       if((addr & 0x3fc) || length & 0x3ff || ((addr > 0x200000) &&
-                                               (addr < 0xff0000)))
-               ctrl_data &= ~(CYBER_DMA_Z3);   /* Z2, do 16 bit DMA */
-       else
-               ctrl_data |= CYBER_DMA_Z3; /* CHIP/Z3, do 32 bit DMA */
-#else
-       ctrl_data &= ~(CYBER_DMA_Z3);   /* Z2, do 16 bit DMA */
-#endif
-       dregs->ctrl_reg = ctrl_data;
-}
-
-static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
-{
-       struct cyber_dma_registers *dregs = 
-               (struct cyber_dma_registers *) esp->dregs;
-
-       cache_push(addr, length);
-
-       addr |= 1;
-       dregs->dma_addr0 = (addr >> 24) & 0xff;
-       dregs->dma_addr1 = (addr >> 16) & 0xff;
-       dregs->dma_addr2 = (addr >>  8) & 0xff;
-       dregs->dma_addr3 = (addr      ) & 0xff;
-       ctrl_data |= CYBER_DMA_WRITE;
-
-       /* See comment above */
-#if 0
-       if((addr & 0x3fc) || length & 0x3ff || ((addr > 0x200000) &&
-                                               (addr < 0xff0000)))
-               ctrl_data &= ~(CYBER_DMA_Z3);   /* Z2, do 16 bit DMA */
-       else
-               ctrl_data |= CYBER_DMA_Z3; /* CHIP/Z3, do 32 bit DMA */
-#else
-       ctrl_data &= ~(CYBER_DMA_Z3);   /* Z2, do 16 bit DMA */
-#endif
-       dregs->ctrl_reg = ctrl_data;
-}
-
-static void dma_ints_off(struct NCR_ESP *esp)
-{
-       disable_irq(esp->irq);
-}
-
-static void dma_ints_on(struct NCR_ESP *esp)
-{
-       enable_irq(esp->irq);
-}
-
-static int dma_irq_p(struct NCR_ESP *esp)
-{
-       /* It's important to check the DMA IRQ bit in the correct way! */
-       return ((esp_read(esp->eregs->esp_status) & ESP_STAT_INTR) &&
-               ((((struct cyber_dma_registers *)(esp->dregs))->cond_reg) &
-                CYBER_DMA_HNDL_INTR));
-}
-
-static void dma_led_off(struct NCR_ESP *esp)
-{
-       ctrl_data &= ~CYBER_DMA_LED;
-       ((struct cyber_dma_registers *)(esp->dregs))->ctrl_reg = ctrl_data;
-}
-
-static void dma_led_on(struct NCR_ESP *esp)
-{
-       ctrl_data |= CYBER_DMA_LED;
-       ((struct cyber_dma_registers *)(esp->dregs))->ctrl_reg = ctrl_data;
-}
-
-static int dma_ports_p(struct NCR_ESP *esp)
-{
-       return ((amiga_custom.intenar) & IF_PORTS);
-}
-
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
-{
-       /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
-        * so when (write) is true, it actually means READ!
-        */
-       if(write){
-               dma_init_read(esp, addr, count);
-       } else {
-               dma_init_write(esp, addr, count);
-       }
-}
-
-#define HOSTS_C
-
-int cyber_esp_release(struct Scsi_Host *instance)
-{
-#ifdef MODULE
-       unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
-
-       esp_deallocate((struct NCR_ESP *)instance->hostdata);
-       esp_release();
-       release_mem_region(address, sizeof(struct ESP_regs));
-       free_irq(IRQ_AMIGA_PORTS, esp_intr);
-#endif
-       return 1;
-}
-
-
-static struct scsi_host_template driver_template = {
-       .proc_name              = "esp-cyberstorm",
-       .proc_info              = esp_proc_info,
-       .name                   = "CyberStorm SCSI",
-       .detect                 = cyber_esp_detect,
-       .slave_alloc            = esp_slave_alloc,
-       .slave_destroy          = esp_slave_destroy,
-       .release                = cyber_esp_release,
-       .queuecommand           = esp_queue,
-       .eh_abort_handler       = esp_abort,
-       .eh_bus_reset_handler   = esp_reset,
-       .can_queue              = 7,
-       .this_id                = 7,
-       .sg_tablesize           = SG_ALL,
-       .cmd_per_lun            = 1,
-       .use_clustering         = ENABLE_CLUSTERING
-};
-
-
-#include "scsi_module.c"
-
-MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/cyberstormII.c b/drivers/scsi/cyberstormII.c
deleted file mode 100644 (file)
index e336e85..0000000
+++ /dev/null
@@ -1,314 +0,0 @@
-/* cyberstormII.c: Driver for CyberStorm SCSI Mk II
- *
- * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
- *
- * This driver is based on cyberstorm.c
- */
-
-/* TODO:
- *
- * 1) Figure out how to make a cleaner merge with the sparc driver with regard
- *    to the caches and the Sparc MMU mapping.
- * 2) Make as few routines required outside the generic driver. A lot of the
- *    routines in this file used to be inline!
- */
-
-#include <linux/module.h>
-
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/types.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <linux/blkdev.h>
-#include <linux/proc_fs.h>
-#include <linux/stat.h>
-#include <linux/interrupt.h>
-
-#include "scsi.h"
-#include <scsi/scsi_host.h>
-#include "NCR53C9x.h"
-
-#include <linux/zorro.h>
-#include <asm/irq.h>
-#include <asm/amigaints.h>
-#include <asm/amigahw.h>
-
-#include <asm/pgtable.h>
-
-/* The controller registers can be found in the Z2 config area at these
- * offsets:
- */
-#define CYBERII_ESP_ADDR 0x1ff03
-#define CYBERII_DMA_ADDR 0x1ff43
-
-
-/* The CyberStorm II DMA interface */
-struct cyberII_dma_registers {
-       volatile unsigned char cond_reg;        /* DMA cond    (ro)  [0x000] */
-#define ctrl_reg  cond_reg                     /* DMA control (wo)  [0x000] */
-       unsigned char dmapad4[0x3f];
-       volatile unsigned char dma_addr0;       /* DMA address (MSB) [0x040] */
-       unsigned char dmapad1[3];
-       volatile unsigned char dma_addr1;       /* DMA address       [0x044] */
-       unsigned char dmapad2[3];
-       volatile unsigned char dma_addr2;       /* DMA address       [0x048] */
-       unsigned char dmapad3[3];
-       volatile unsigned char dma_addr3;       /* DMA address (LSB) [0x04c] */
-};
-
-/* DMA control bits */
-#define CYBERII_DMA_LED    0x02        /* HD led control 1 = on */
-
-static int  dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
-static int  dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
-static void dma_dump_state(struct NCR_ESP *esp);
-static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
-static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length);
-static void dma_ints_off(struct NCR_ESP *esp);
-static void dma_ints_on(struct NCR_ESP *esp);
-static int  dma_irq_p(struct NCR_ESP *esp);
-static void dma_led_off(struct NCR_ESP *esp);
-static void dma_led_on(struct NCR_ESP *esp);
-static int  dma_ports_p(struct NCR_ESP *esp);
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
-
-static volatile unsigned char cmd_buffer[16];
-                               /* This is where all commands are put
-                                * before they are transferred to the ESP chip
-                                * via PIO.
-                                */
-
-/***************************************************************** Detection */
-int __init cyberII_esp_detect(struct scsi_host_template *tpnt)
-{
-       struct NCR_ESP *esp;
-       struct zorro_dev *z = NULL;
-       unsigned long address;
-       struct ESP_regs *eregs;
-
-       if ((z = zorro_find_device(ZORRO_PROD_PHASE5_CYBERSTORM_MK_II, z))) {
-           unsigned long board = z->resource.start;
-           if (request_mem_region(board+CYBERII_ESP_ADDR,
-                                  sizeof(struct ESP_regs), "NCR53C9x")) {
-               /* Do some magic to figure out if the CyberStorm Mk II
-                * is equipped with a SCSI controller
-                */
-               address = (unsigned long)ZTWO_VADDR(board);
-               eregs = (struct ESP_regs *)(address + CYBERII_ESP_ADDR);
-
-               esp = esp_allocate(tpnt, (void *)board + CYBERII_ESP_ADDR, 0);
-
-               esp_write(eregs->esp_cfg1, (ESP_CONFIG1_PENABLE | 7));
-               udelay(5);
-               if(esp_read(eregs->esp_cfg1) != (ESP_CONFIG1_PENABLE | 7)) {
-                       esp_deallocate(esp);
-                       scsi_unregister(esp->ehost);
-                       release_mem_region(board+CYBERII_ESP_ADDR,
-                                          sizeof(struct ESP_regs));
-                       return 0; /* Bail out if address did not hold data */
-               }
-
-               /* Do command transfer with programmed I/O */
-               esp->do_pio_cmds = 1;
-
-               /* Required functions */
-               esp->dma_bytes_sent = &dma_bytes_sent;
-               esp->dma_can_transfer = &dma_can_transfer;
-               esp->dma_dump_state = &dma_dump_state;
-               esp->dma_init_read = &dma_init_read;
-               esp->dma_init_write = &dma_init_write;
-               esp->dma_ints_off = &dma_ints_off;
-               esp->dma_ints_on = &dma_ints_on;
-               esp->dma_irq_p = &dma_irq_p;
-               esp->dma_ports_p = &dma_ports_p;
-               esp->dma_setup = &dma_setup;
-
-               /* Optional functions */
-               esp->dma_barrier = 0;
-               esp->dma_drain = 0;
-               esp->dma_invalidate = 0;
-               esp->dma_irq_entry = 0;
-               esp->dma_irq_exit = 0;
-               esp->dma_led_on = &dma_led_on;
-               esp->dma_led_off = &dma_led_off;
-               esp->dma_poll = 0;
-               esp->dma_reset = 0;
-
-               /* SCSI chip speed */
-               esp->cfreq = 40000000;
-
-               /* The DMA registers on the CyberStorm are mapped
-                * relative to the device (i.e. in the same Zorro
-                * I/O block).
-                */
-               esp->dregs = (void *)(address + CYBERII_DMA_ADDR);
-
-               /* ESP register base */
-               esp->eregs = eregs;
-               
-               /* Set the command buffer */
-               esp->esp_command = cmd_buffer;
-               esp->esp_command_dvma = virt_to_bus((void *)cmd_buffer);
-
-               esp->irq = IRQ_AMIGA_PORTS;
-               request_irq(IRQ_AMIGA_PORTS, esp_intr, IRQF_SHARED,
-                           "CyberStorm SCSI Mk II", esp->ehost);
-
-               /* Figure out our scsi ID on the bus */
-               esp->scsi_id = 7;
-               
-               /* We don't have a differential SCSI-bus. */
-               esp->diff = 0;
-
-               esp_initialize(esp);
-
-               printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
-               esps_running = esps_in_use;
-               return esps_in_use;
-           }
-       }
-       return 0;
-}
-
-/************************************************************* DMA Functions */
-static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
-{
-       /* Since the CyberStorm DMA is fully dedicated to the ESP chip,
-        * the number of bytes sent (to the ESP chip) equals the number
-        * of bytes in the FIFO - there is no buffering in the DMA controller.
-        * XXXX Do I read this right? It is from host to ESP, right?
-        */
-       return fifo_count;
-}
-
-static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-       /* I don't think there's any limit on the CyberDMA. So we use what
-        * the ESP chip can handle (24 bit).
-        */
-       unsigned long sz = sp->SCp.this_residual;
-       if(sz > 0x1000000)
-               sz = 0x1000000;
-       return sz;
-}
-
-static void dma_dump_state(struct NCR_ESP *esp)
-{
-       ESPLOG(("esp%d: dma -- cond_reg<%02x>\n",
-               esp->esp_id, ((struct cyberII_dma_registers *)
-                             (esp->dregs))->cond_reg));
-       ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
-               amiga_custom.intreqr, amiga_custom.intenar));
-}
-
-static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
-{
-       struct cyberII_dma_registers *dregs = 
-               (struct cyberII_dma_registers *) esp->dregs;
-
-       cache_clear(addr, length);
-
-       addr &= ~(1);
-       dregs->dma_addr0 = (addr >> 24) & 0xff;
-       dregs->dma_addr1 = (addr >> 16) & 0xff;
-       dregs->dma_addr2 = (addr >>  8) & 0xff;
-       dregs->dma_addr3 = (addr      ) & 0xff;
-}
-
-static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
-{
-       struct cyberII_dma_registers *dregs = 
-               (struct cyberII_dma_registers *) esp->dregs;
-
-       cache_push(addr, length);
-
-       addr |= 1;
-       dregs->dma_addr0 = (addr >> 24) & 0xff;
-       dregs->dma_addr1 = (addr >> 16) & 0xff;
-       dregs->dma_addr2 = (addr >>  8) & 0xff;
-       dregs->dma_addr3 = (addr      ) & 0xff;
-}
-
-static void dma_ints_off(struct NCR_ESP *esp)
-{
-       disable_irq(esp->irq);
-}
-
-static void dma_ints_on(struct NCR_ESP *esp)
-{
-       enable_irq(esp->irq);
-}
-
-static int dma_irq_p(struct NCR_ESP *esp)
-{
-       /* It's important to check the DMA IRQ bit in the correct way! */
-       return (esp_read(esp->eregs->esp_status) & ESP_STAT_INTR);
-}
-
-static void dma_led_off(struct NCR_ESP *esp)
-{
-       ((struct cyberII_dma_registers *)(esp->dregs))->ctrl_reg &= ~CYBERII_DMA_LED;
-}
-
-static void dma_led_on(struct NCR_ESP *esp)
-{
-       ((struct cyberII_dma_registers *)(esp->dregs))->ctrl_reg |= CYBERII_DMA_LED;
-}
-
-static int dma_ports_p(struct NCR_ESP *esp)
-{
-       return ((amiga_custom.intenar) & IF_PORTS);
-}
-
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
-{
-       /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
-        * so when (write) is true, it actually means READ!
-        */
-       if(write){
-               dma_init_read(esp, addr, count);
-       } else {
-               dma_init_write(esp, addr, count);
-       }
-}
-
-#define HOSTS_C
-
-int cyberII_esp_release(struct Scsi_Host *instance)
-{
-#ifdef MODULE
-       unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
-
-       esp_deallocate((struct NCR_ESP *)instance->hostdata); 
-       esp_release();
-       release_mem_region(address, sizeof(struct ESP_regs));
-       free_irq(IRQ_AMIGA_PORTS, esp_intr);
-#endif
-       return 1;
-}
-
-
-static struct scsi_host_template driver_template = {
-       .proc_name              = "esp-cyberstormII",
-       .proc_info              = esp_proc_info,
-       .name                   = "CyberStorm Mk II SCSI",
-       .detect                 = cyberII_esp_detect,
-       .slave_alloc            = esp_slave_alloc,
-       .slave_destroy          = esp_slave_destroy,
-       .release                = cyberII_esp_release,
-       .queuecommand           = esp_queue,
-       .eh_abort_handler       = esp_abort,
-       .eh_bus_reset_handler   = esp_reset,
-       .can_queue              = 7,
-       .this_id                = 7,
-       .sg_tablesize           = SG_ALL,
-       .cmd_per_lun            = 1,
-       .use_clustering         = ENABLE_CLUSTERING
-};
-
-
-#include "scsi_module.c"
-
-MODULE_LICENSE("GPL");
index 22ef3716e7864168977b4e7967358bf0b6496b1a..e351db6c00779873a6f94bb7002118501c8b847c 100644 (file)
@@ -4267,7 +4267,7 @@ static int __devinit adapter_sg_tables_alloc(struct AdapterCtlBlk *acb)
        const unsigned srbs_per_page = PAGE_SIZE/SEGMENTX_LEN;
        int srb_idx = 0;
        unsigned i = 0;
-       struct SGentry *ptr;
+       struct SGentry *uninitialized_var(ptr);
 
        for (i = 0; i < DC395x_MAX_SRB_CNT; i++)
                acb->srb_array[i].segment_x = NULL;
diff --git a/drivers/scsi/dec_esp.c b/drivers/scsi/dec_esp.c
deleted file mode 100644 (file)
index d42ad66..0000000
+++ /dev/null
@@ -1,687 +0,0 @@
-/*
- * dec_esp.c: Driver for SCSI chips on IOASIC based TURBOchannel DECstations
- *            and TURBOchannel PMAZ-A cards
- *
- * TURBOchannel changes by Harald Koerfgen
- * PMAZ-A support by David Airlie
- *
- * based on jazz_esp.c:
- * Copyright (C) 1997 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
- *
- * jazz_esp is based on David S. Miller's ESP driver and cyber_esp
- *
- * 20000819 - Small PMAZ-AA fixes by Florian Lohoff <flo@rfc822.org>
- *            Be warned the PMAZ-AA works currently as a single card.
- *            Dont try to put multiple cards in one machine - They are
- *            both detected but it may crash under high load garbling your
- *            data.
- * 20001005    - Initialization fixes for 2.4.0-test9
- *                       Florian Lohoff <flo@rfc822.org>
- *
- *     Copyright (C) 2002, 2003, 2005, 2006  Maciej W. Rozycki
- */
-
-#include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/types.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <linux/blkdev.h>
-#include <linux/proc_fs.h>
-#include <linux/spinlock.h>
-#include <linux/stat.h>
-#include <linux/tc.h>
-
-#include <asm/dma.h>
-#include <asm/irq.h>
-#include <asm/pgtable.h>
-#include <asm/system.h>
-
-#include <asm/dec/interrupts.h>
-#include <asm/dec/ioasic.h>
-#include <asm/dec/ioasic_addrs.h>
-#include <asm/dec/ioasic_ints.h>
-#include <asm/dec/machtype.h>
-#include <asm/dec/system.h>
-
-#define DEC_SCSI_SREG 0
-#define DEC_SCSI_DMAREG 0x40000
-#define DEC_SCSI_SRAM 0x80000
-#define DEC_SCSI_DIAG 0xC0000
-
-#include "scsi.h"
-#include <scsi/scsi_host.h>
-#include "NCR53C9x.h"
-
-static int  dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
-static void dma_drain(struct NCR_ESP *esp);
-static int  dma_can_transfer(struct NCR_ESP *esp, struct scsi_cmnd *sp);
-static void dma_dump_state(struct NCR_ESP *esp);
-static void dma_init_read(struct NCR_ESP *esp, u32 vaddress, int length);
-static void dma_init_write(struct NCR_ESP *esp, u32 vaddress, int length);
-static void dma_ints_off(struct NCR_ESP *esp);
-static void dma_ints_on(struct NCR_ESP *esp);
-static int  dma_irq_p(struct NCR_ESP *esp);
-static int  dma_ports_p(struct NCR_ESP *esp);
-static void dma_setup(struct NCR_ESP *esp, u32 addr, int count, int write);
-static void dma_mmu_get_scsi_one(struct NCR_ESP *esp, struct scsi_cmnd * sp);
-static void dma_mmu_get_scsi_sgl(struct NCR_ESP *esp, struct scsi_cmnd * sp);
-static void dma_advance_sg(struct scsi_cmnd * sp);
-
-static void pmaz_dma_drain(struct NCR_ESP *esp);
-static void pmaz_dma_init_read(struct NCR_ESP *esp, u32 vaddress, int length);
-static void pmaz_dma_init_write(struct NCR_ESP *esp, u32 vaddress, int length);
-static void pmaz_dma_ints_off(struct NCR_ESP *esp);
-static void pmaz_dma_ints_on(struct NCR_ESP *esp);
-static void pmaz_dma_setup(struct NCR_ESP *esp, u32 addr, int count, int write);
-static void pmaz_dma_mmu_get_scsi_one(struct NCR_ESP *esp, struct scsi_cmnd * sp);
-
-#define TC_ESP_RAM_SIZE 0x20000
-#define ESP_TGT_DMA_SIZE ((TC_ESP_RAM_SIZE/7) & ~(sizeof(int)-1))
-#define ESP_NCMD 7
-
-#define TC_ESP_DMAR_MASK  0x1ffff
-#define TC_ESP_DMAR_WRITE 0x80000000
-#define TC_ESP_DMA_ADDR(x) ((unsigned)(x) & TC_ESP_DMAR_MASK)
-
-u32 esp_virt_buffer;
-int scsi_current_length;
-
-volatile unsigned char cmd_buffer[16];
-volatile unsigned char pmaz_cmd_buffer[16];
-                               /* This is where all commands are put
-                                * before they are trasfered to the ESP chip
-                                * via PIO.
-                                */
-
-static irqreturn_t scsi_dma_merr_int(int, void *);
-static irqreturn_t scsi_dma_err_int(int, void *);
-static irqreturn_t scsi_dma_int(int, void *);
-
-static struct scsi_host_template dec_esp_template = {
-       .module                 = THIS_MODULE,
-       .name                   = "NCR53C94",
-       .info                   = esp_info,
-       .queuecommand           = esp_queue,
-       .eh_abort_handler       = esp_abort,
-       .eh_bus_reset_handler   = esp_reset,
-       .slave_alloc            = esp_slave_alloc,
-       .slave_destroy          = esp_slave_destroy,
-       .proc_info              = esp_proc_info,
-       .proc_name              = "dec_esp",
-       .can_queue              = 7,
-       .sg_tablesize           = SG_ALL,
-       .cmd_per_lun            = 1,
-       .use_clustering         = DISABLE_CLUSTERING,
-};
-
-static struct NCR_ESP *dec_esp_platform;
-
-/***************************************************************** Detection */
-static int dec_esp_platform_probe(void)
-{
-       struct NCR_ESP *esp;
-       int err = 0;
-
-       if (IOASIC) {
-               esp = esp_allocate(&dec_esp_template, NULL, 1);
-
-               /* Do command transfer with programmed I/O */
-               esp->do_pio_cmds = 1;
-
-               /* Required functions */
-               esp->dma_bytes_sent = &dma_bytes_sent;
-               esp->dma_can_transfer = &dma_can_transfer;
-               esp->dma_dump_state = &dma_dump_state;
-               esp->dma_init_read = &dma_init_read;
-               esp->dma_init_write = &dma_init_write;
-               esp->dma_ints_off = &dma_ints_off;
-               esp->dma_ints_on = &dma_ints_on;
-               esp->dma_irq_p = &dma_irq_p;
-               esp->dma_ports_p = &dma_ports_p;
-               esp->dma_setup = &dma_setup;
-
-               /* Optional functions */
-               esp->dma_barrier = 0;
-               esp->dma_drain = &dma_drain;
-               esp->dma_invalidate = 0;
-               esp->dma_irq_entry = 0;
-               esp->dma_irq_exit = 0;
-               esp->dma_poll = 0;
-               esp->dma_reset = 0;
-               esp->dma_led_off = 0;
-               esp->dma_led_on = 0;
-
-               /* virtual DMA functions */
-               esp->dma_mmu_get_scsi_one = &dma_mmu_get_scsi_one;
-               esp->dma_mmu_get_scsi_sgl = &dma_mmu_get_scsi_sgl;
-               esp->dma_mmu_release_scsi_one = 0;
-               esp->dma_mmu_release_scsi_sgl = 0;
-               esp->dma_advance_sg = &dma_advance_sg;
-
-
-               /* SCSI chip speed */
-               esp->cfreq = 25000000;
-
-               esp->dregs = 0;
-
-               /* ESP register base */
-               esp->eregs = (void *)CKSEG1ADDR(dec_kn_slot_base +
-                                               IOASIC_SCSI);
-
-               /* Set the command buffer */
-               esp->esp_command = (volatile unsigned char *) cmd_buffer;
-
-               /* get virtual dma address for command buffer */
-               esp->esp_command_dvma = virt_to_phys(cmd_buffer);
-
-               esp->irq = dec_interrupt[DEC_IRQ_ASC];
-
-               esp->scsi_id = 7;
-
-               /* Check for differential SCSI-bus */
-               esp->diff = 0;
-
-               err = request_irq(esp->irq, esp_intr, IRQF_DISABLED,
-                                 "ncr53c94", esp->ehost);
-               if (err)
-                       goto err_alloc;
-               err = request_irq(dec_interrupt[DEC_IRQ_ASC_MERR],
-                                 scsi_dma_merr_int, IRQF_DISABLED,
-                                 "ncr53c94 error", esp->ehost);
-               if (err)
-                       goto err_irq;
-               err = request_irq(dec_interrupt[DEC_IRQ_ASC_ERR],
-                                 scsi_dma_err_int, IRQF_DISABLED,
-                                 "ncr53c94 overrun", esp->ehost);
-               if (err)
-                       goto err_irq_merr;
-               err = request_irq(dec_interrupt[DEC_IRQ_ASC_DMA], scsi_dma_int,
-                                 IRQF_DISABLED, "ncr53c94 dma", esp->ehost);
-               if (err)
-                       goto err_irq_err;
-
-               esp_initialize(esp);
-
-               err = scsi_add_host(esp->ehost, NULL);
-               if (err) {
-                       printk(KERN_ERR "ESP: Unable to register adapter\n");
-                       goto err_irq_dma;
-               }
-
-               scsi_scan_host(esp->ehost);
-
-               dec_esp_platform = esp;
-       }
-
-       return 0;
-
-err_irq_dma:
-       free_irq(dec_interrupt[DEC_IRQ_ASC_DMA], esp->ehost);
-err_irq_err:
-       free_irq(dec_interrupt[DEC_IRQ_ASC_ERR], esp->ehost);
-err_irq_merr:
-       free_irq(dec_interrupt[DEC_IRQ_ASC_MERR], esp->ehost);
-err_irq:
-       free_irq(esp->irq, esp->ehost);
-err_alloc:
-       esp_deallocate(esp);
-       scsi_host_put(esp->ehost);
-       return err;
-}
-
-static int __init dec_esp_probe(struct device *dev)
-{
-       struct NCR_ESP *esp;
-       resource_size_t start, len;
-       int err;
-
-       esp = esp_allocate(&dec_esp_template,  NULL, 1);
-
-       dev_set_drvdata(dev, esp);
-
-       start = to_tc_dev(dev)->resource.start;
-       len = to_tc_dev(dev)->resource.end - start + 1;
-
-       if (!request_mem_region(start, len, dev->bus_id)) {
-               printk(KERN_ERR "%s: Unable to reserve MMIO resource\n",
-                      dev->bus_id);
-               err = -EBUSY;
-               goto err_alloc;
-       }
-
-       /* Store base addr into esp struct.  */
-       esp->slot = start;
-
-       esp->dregs = 0;
-       esp->eregs = (void *)CKSEG1ADDR(start + DEC_SCSI_SREG);
-       esp->do_pio_cmds = 1;
-
-       /* Set the command buffer.  */
-       esp->esp_command = (volatile unsigned char *)pmaz_cmd_buffer;
-
-       /* Get virtual dma address for command buffer.  */
-       esp->esp_command_dvma = virt_to_phys(pmaz_cmd_buffer);
-
-       esp->cfreq = tc_get_speed(to_tc_dev(dev)->bus);
-
-       esp->irq = to_tc_dev(dev)->interrupt;
-
-       /* Required functions.  */
-       esp->dma_bytes_sent = &dma_bytes_sent;
-       esp->dma_can_transfer = &dma_can_transfer;
-       esp->dma_dump_state = &dma_dump_state;
-       esp->dma_init_read = &pmaz_dma_init_read;
-       esp->dma_init_write = &pmaz_dma_init_write;
-       esp->dma_ints_off = &pmaz_dma_ints_off;
-       esp->dma_ints_on = &pmaz_dma_ints_on;
-       esp->dma_irq_p = &dma_irq_p;
-       esp->dma_ports_p = &dma_ports_p;
-       esp->dma_setup = &pmaz_dma_setup;
-
-       /* Optional functions.  */
-       esp->dma_barrier = 0;
-       esp->dma_drain = &pmaz_dma_drain;
-       esp->dma_invalidate = 0;
-       esp->dma_irq_entry = 0;
-       esp->dma_irq_exit = 0;
-       esp->dma_poll = 0;
-       esp->dma_reset = 0;
-       esp->dma_led_off = 0;
-       esp->dma_led_on = 0;
-
-       esp->dma_mmu_get_scsi_one = pmaz_dma_mmu_get_scsi_one;
-       esp->dma_mmu_get_scsi_sgl = 0;
-       esp->dma_mmu_release_scsi_one = 0;
-       esp->dma_mmu_release_scsi_sgl = 0;
-       esp->dma_advance_sg = 0;
-
-       err = request_irq(esp->irq, esp_intr, IRQF_DISABLED, "PMAZ_AA",
-                         esp->ehost);
-       if (err) {
-               printk(KERN_ERR "%s: Unable to get IRQ %d\n",
-                      dev->bus_id, esp->irq);
-               goto err_resource;
-       }
-
-       esp->scsi_id = 7;
-       esp->diff = 0;
-       esp_initialize(esp);
-
-       err = scsi_add_host(esp->ehost, dev);
-       if (err) {
-               printk(KERN_ERR "%s: Unable to register adapter\n",
-                      dev->bus_id);
-               goto err_irq;
-       }
-
-       scsi_scan_host(esp->ehost);
-
-       return 0;
-
-err_irq:
-       free_irq(esp->irq, esp->ehost);
-
-err_resource:
-       release_mem_region(start, len);
-
-err_alloc:
-       esp_deallocate(esp);
-       scsi_host_put(esp->ehost);
-       return err;
-}
-
-static void __exit dec_esp_platform_remove(void)
-{
-       struct NCR_ESP *esp = dec_esp_platform;
-
-       free_irq(esp->irq, esp->ehost);
-       esp_deallocate(esp);
-       scsi_host_put(esp->ehost);
-       dec_esp_platform = NULL;
-}
-
-static void __exit dec_esp_remove(struct device *dev)
-{
-       struct NCR_ESP *esp = dev_get_drvdata(dev);
-
-       free_irq(esp->irq, esp->ehost);
-       esp_deallocate(esp);
-       scsi_host_put(esp->ehost);
-}
-
-
-/************************************************************* DMA Functions */
-static irqreturn_t scsi_dma_merr_int(int irq, void *dev_id)
-{
-       printk("Got unexpected SCSI DMA Interrupt! < ");
-       printk("SCSI_DMA_MEMRDERR ");
-       printk(">\n");
-
-       return IRQ_HANDLED;
-}
-
-static irqreturn_t scsi_dma_err_int(int irq, void *dev_id)
-{
-       /* empty */
-
-       return IRQ_HANDLED;
-}
-
-static irqreturn_t scsi_dma_int(int irq, void *dev_id)
-{
-       u32 scsi_next_ptr;
-
-       scsi_next_ptr = ioasic_read(IO_REG_SCSI_DMA_P);
-
-       /* next page */
-       scsi_next_ptr = (((scsi_next_ptr >> 3) + PAGE_SIZE) & PAGE_MASK) << 3;
-       ioasic_write(IO_REG_SCSI_DMA_BP, scsi_next_ptr);
-       fast_iob();
-
-       return IRQ_HANDLED;
-}
-
-static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
-{
-       return fifo_count;
-}
-
-static void dma_drain(struct NCR_ESP *esp)
-{
-       u32 nw, data0, data1, scsi_data_ptr;
-       u16 *p;
-
-       nw = ioasic_read(IO_REG_SCSI_SCR);
-
-       /*
-        * Is there something in the dma buffers left?
-        */
-       if (nw) {
-               scsi_data_ptr = ioasic_read(IO_REG_SCSI_DMA_P) >> 3;
-               p = phys_to_virt(scsi_data_ptr);
-               switch (nw) {
-               case 1:
-                       data0 = ioasic_read(IO_REG_SCSI_SDR0);
-                       p[0] = data0 & 0xffff;
-                       break;
-               case 2:
-                       data0 = ioasic_read(IO_REG_SCSI_SDR0);
-                       p[0] = data0 & 0xffff;
-                       p[1] = (data0 >> 16) & 0xffff;
-                       break;
-               case 3:
-                       data0 = ioasic_read(IO_REG_SCSI_SDR0);
-                       data1 = ioasic_read(IO_REG_SCSI_SDR1);
-                       p[0] = data0 & 0xffff;
-                       p[1] = (data0 >> 16) & 0xffff;
-                       p[2] = data1 & 0xffff;
-                       break;
-               default:
-                       printk("Strange: %d words in dma buffer left\n", nw);
-                       break;
-               }
-       }
-}
-
-static int dma_can_transfer(struct NCR_ESP *esp, struct scsi_cmnd * sp)
-{
-       return sp->SCp.this_residual;
-}
-
-static void dma_dump_state(struct NCR_ESP *esp)
-{
-}
-
-static void dma_init_read(struct NCR_ESP *esp, u32 vaddress, int length)
-{
-       u32 scsi_next_ptr, ioasic_ssr;
-       unsigned long flags;
-
-       if (vaddress & 3)
-               panic("dec_esp.c: unable to handle partial word transfers, yet...");
-
-       dma_cache_wback_inv((unsigned long) phys_to_virt(vaddress), length);
-
-       spin_lock_irqsave(&ioasic_ssr_lock, flags);
-
-       fast_mb();
-       ioasic_ssr = ioasic_read(IO_REG_SSR);
-
-       ioasic_ssr &= ~IO_SSR_SCSI_DMA_EN;
-       ioasic_write(IO_REG_SSR, ioasic_ssr);
-
-       fast_wmb();
-       ioasic_write(IO_REG_SCSI_SCR, 0);
-       ioasic_write(IO_REG_SCSI_DMA_P, vaddress << 3);
-
-       /* prepare for next page */
-       scsi_next_ptr = ((vaddress + PAGE_SIZE) & PAGE_MASK) << 3;
-       ioasic_write(IO_REG_SCSI_DMA_BP, scsi_next_ptr);
-
-       ioasic_ssr |= (IO_SSR_SCSI_DMA_DIR | IO_SSR_SCSI_DMA_EN);
-       fast_wmb();
-       ioasic_write(IO_REG_SSR, ioasic_ssr);
-
-       fast_iob();
-       spin_unlock_irqrestore(&ioasic_ssr_lock, flags);
-}
-
-static void dma_init_write(struct NCR_ESP *esp, u32 vaddress, int length)
-{
-       u32 scsi_next_ptr, ioasic_ssr;
-       unsigned long flags;
-
-       if (vaddress & 3)
-               panic("dec_esp.c: unable to handle partial word transfers, yet...");
-
-       dma_cache_wback_inv((unsigned long) phys_to_virt(vaddress), length);
-
-       spin_lock_irqsave(&ioasic_ssr_lock, flags);
-
-       fast_mb();
-       ioasic_ssr = ioasic_read(IO_REG_SSR);
-
-       ioasic_ssr &= ~(IO_SSR_SCSI_DMA_DIR | IO_SSR_SCSI_DMA_EN);
-       ioasic_write(IO_REG_SSR, ioasic_ssr);
-
-       fast_wmb();
-       ioasic_write(IO_REG_SCSI_SCR, 0);
-       ioasic_write(IO_REG_SCSI_DMA_P, vaddress << 3);
-
-       /* prepare for next page */
-       scsi_next_ptr = ((vaddress + PAGE_SIZE) & PAGE_MASK) << 3;
-       ioasic_write(IO_REG_SCSI_DMA_BP, scsi_next_ptr);
-
-       ioasic_ssr |= IO_SSR_SCSI_DMA_EN;
-       fast_wmb();
-       ioasic_write(IO_REG_SSR, ioasic_ssr);
-
-       fast_iob();
-       spin_unlock_irqrestore(&ioasic_ssr_lock, flags);
-}
-
-static void dma_ints_off(struct NCR_ESP *esp)
-{
-       disable_irq(dec_interrupt[DEC_IRQ_ASC_DMA]);
-}
-
-static void dma_ints_on(struct NCR_ESP *esp)
-{
-       enable_irq(dec_interrupt[DEC_IRQ_ASC_DMA]);
-}
-
-static int dma_irq_p(struct NCR_ESP *esp)
-{
-       return (esp->eregs->esp_status & ESP_STAT_INTR);
-}
-
-static int dma_ports_p(struct NCR_ESP *esp)
-{
-       /*
-        * FIXME: what's this good for?
-        */
-       return 1;
-}
-
-static void dma_setup(struct NCR_ESP *esp, u32 addr, int count, int write)
-{
-       /*
-        * DMA_ST_WRITE means "move data from device to memory"
-        * so when (write) is true, it actually means READ!
-        */
-       if (write)
-               dma_init_read(esp, addr, count);
-       else
-               dma_init_write(esp, addr, count);
-}
-
-static void dma_mmu_get_scsi_one(struct NCR_ESP *esp, struct scsi_cmnd * sp)
-{
-       sp->SCp.ptr = (char *)virt_to_phys(sp->request_buffer);
-}
-
-static void dma_mmu_get_scsi_sgl(struct NCR_ESP *esp, struct scsi_cmnd * sp)
-{
-       int sz = sp->SCp.buffers_residual;
-       struct scatterlist *sg = sp->SCp.buffer;
-
-       while (sz >= 0) {
-               sg[sz].dma_address = page_to_phys(sg[sz].page) + sg[sz].offset;
-               sz--;
-       }
-       sp->SCp.ptr = (char *)(sp->SCp.buffer->dma_address);
-}
-
-static void dma_advance_sg(struct scsi_cmnd * sp)
-{
-       sp->SCp.ptr = (char *)(sp->SCp.buffer->dma_address);
-}
-
-static void pmaz_dma_drain(struct NCR_ESP *esp)
-{
-       memcpy(phys_to_virt(esp_virt_buffer),
-              (void *)CKSEG1ADDR(esp->slot + DEC_SCSI_SRAM +
-                                 ESP_TGT_DMA_SIZE),
-              scsi_current_length);
-}
-
-static void pmaz_dma_init_read(struct NCR_ESP *esp, u32 vaddress, int length)
-{
-       volatile u32 *dmareg =
-               (volatile u32 *)CKSEG1ADDR(esp->slot + DEC_SCSI_DMAREG);
-
-       if (length > ESP_TGT_DMA_SIZE)
-               length = ESP_TGT_DMA_SIZE;
-
-       *dmareg = TC_ESP_DMA_ADDR(ESP_TGT_DMA_SIZE);
-
-       iob();
-
-       esp_virt_buffer = vaddress;
-       scsi_current_length = length;
-}
-
-static void pmaz_dma_init_write(struct NCR_ESP *esp, u32 vaddress, int length)
-{
-       volatile u32 *dmareg =
-               (volatile u32 *)CKSEG1ADDR(esp->slot + DEC_SCSI_DMAREG);
-
-       memcpy((void *)CKSEG1ADDR(esp->slot + DEC_SCSI_SRAM +
-                                 ESP_TGT_DMA_SIZE),
-              phys_to_virt(vaddress), length);
-
-       wmb();
-       *dmareg = TC_ESP_DMAR_WRITE | TC_ESP_DMA_ADDR(ESP_TGT_DMA_SIZE);
-
-       iob();
-}
-
-static void pmaz_dma_ints_off(struct NCR_ESP *esp)
-{
-}
-
-static void pmaz_dma_ints_on(struct NCR_ESP *esp)
-{
-}
-
-static void pmaz_dma_setup(struct NCR_ESP *esp, u32 addr, int count, int write)
-{
-       /*
-        * DMA_ST_WRITE means "move data from device to memory"
-        * so when (write) is true, it actually means READ!
-        */
-       if (write)
-               pmaz_dma_init_read(esp, addr, count);
-       else
-               pmaz_dma_init_write(esp, addr, count);
-}
-
-static void pmaz_dma_mmu_get_scsi_one(struct NCR_ESP *esp, struct scsi_cmnd * sp)
-{
-       sp->SCp.ptr = (char *)virt_to_phys(sp->request_buffer);
-}
-
-
-#ifdef CONFIG_TC
-static int __init dec_esp_tc_probe(struct device *dev);
-static int __exit dec_esp_tc_remove(struct device *dev);
-
-static const struct tc_device_id dec_esp_tc_table[] = {
-        { "DEC     ", "PMAZ-AA " },
-        { }
-};
-MODULE_DEVICE_TABLE(tc, dec_esp_tc_table);
-
-static struct tc_driver dec_esp_tc_driver = {
-        .id_table       = dec_esp_tc_table,
-        .driver         = {
-                .name   = "dec_esp",
-                .bus    = &tc_bus_type,
-                .probe  = dec_esp_tc_probe,
-                .remove = __exit_p(dec_esp_tc_remove),
-        },
-};
-
-static int __init dec_esp_tc_probe(struct device *dev)
-{
-       int status = dec_esp_probe(dev);
-       if (!status)
-               get_device(dev);
-       return status;
-}
-
-static int __exit dec_esp_tc_remove(struct device *dev)
-{
-       put_device(dev);
-       dec_esp_remove(dev);
-       return 0;
-}
-#endif
-
-static int __init dec_esp_init(void)
-{
-       int status;
-
-       status = tc_register_driver(&dec_esp_tc_driver);
-       if (!status)
-               dec_esp_platform_probe();
-
-       if (nesps) {
-               pr_info("ESP: Total of %d ESP hosts found, "
-                       "%d actually in use.\n", nesps, esps_in_use);
-               esps_running = esps_in_use;
-       }
-
-       return status;
-}
-
-static void __exit dec_esp_exit(void)
-{
-       dec_esp_platform_remove();
-       tc_unregister_driver(&dec_esp_tc_driver);
-}
-
-
-module_init(dec_esp_init);
-module_exit(dec_esp_exit);
diff --git a/drivers/scsi/fastlane.c b/drivers/scsi/fastlane.c
deleted file mode 100644 (file)
index 4266a21..0000000
+++ /dev/null
@@ -1,421 +0,0 @@
-/* fastlane.c: Driver for Phase5's Fastlane SCSI Controller.
- *
- * Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
- *
- * This driver is based on the CyberStorm driver, hence the occasional
- * reference to CyberStorm.
- *
- * Betatesting & crucial adjustments by
- *        Patrik Rak (prak3264@ss1000.ms.mff.cuni.cz)
- *
- */
-
-/* TODO:
- *
- * o According to the doc from laire, it is required to reset the DMA when
- *   the transfer is done. ATM we reset DMA just before every new 
- *   dma_init_(read|write).
- *
- * 1) Figure out how to make a cleaner merge with the sparc driver with regard
- *    to the caches and the Sparc MMU mapping.
- * 2) Make as few routines required outside the generic driver. A lot of the
- *    routines in this file used to be inline!
- */
-
-#include <linux/module.h>
-
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/types.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <linux/blkdev.h>
-#include <linux/proc_fs.h>
-#include <linux/stat.h>
-#include <linux/interrupt.h>
-
-#include "scsi.h"
-#include <scsi/scsi_host.h>
-#include "NCR53C9x.h"
-
-#include <linux/zorro.h>
-#include <asm/irq.h>
-
-#include <asm/amigaints.h>
-#include <asm/amigahw.h>
-
-#include <asm/pgtable.h>
-
-/* Such day has just come... */
-#if 0
-/* Let this defined unless you really need to enable DMA IRQ one day */
-#define NODMAIRQ
-#endif
-
-/* The controller registers can be found in the Z2 config area at these
- * offsets:
- */
-#define FASTLANE_ESP_ADDR 0x1000001
-#define FASTLANE_DMA_ADDR 0x1000041
-
-
-/* The Fastlane DMA interface */
-struct fastlane_dma_registers {
-       volatile unsigned char cond_reg;        /* DMA status  (ro) [0x0000] */
-#define ctrl_reg  cond_reg                     /* DMA control (wo) [0x0000] */
-       unsigned char dmapad1[0x3f];
-       volatile unsigned char clear_strobe;    /* DMA clear   (wo) [0x0040] */
-};
-
-
-/* DMA status bits */
-#define FASTLANE_DMA_MINT  0x80
-#define FASTLANE_DMA_IACT  0x40
-#define FASTLANE_DMA_CREQ  0x20
-
-/* DMA control bits */
-#define FASTLANE_DMA_FCODE 0xa0
-#define FASTLANE_DMA_MASK  0xf3
-#define FASTLANE_DMA_LED   0x10        /* HD led control 1 = on */
-#define FASTLANE_DMA_WRITE 0x08 /* 1 = write */
-#define FASTLANE_DMA_ENABLE 0x04 /* Enable DMA */
-#define FASTLANE_DMA_EDI   0x02        /* Enable DMA IRQ ? */
-#define FASTLANE_DMA_ESI   0x01        /* Enable SCSI IRQ */
-
-static int  dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
-static int  dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
-static void dma_dump_state(struct NCR_ESP *esp);
-static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length);
-static void dma_init_write(struct NCR_ESP *esp, __u32 vaddr, int length);
-static void dma_ints_off(struct NCR_ESP *esp);
-static void dma_ints_on(struct NCR_ESP *esp);
-static int  dma_irq_p(struct NCR_ESP *esp);
-static void dma_irq_exit(struct NCR_ESP *esp);
-static void dma_led_off(struct NCR_ESP *esp);
-static void dma_led_on(struct NCR_ESP *esp);
-static int  dma_ports_p(struct NCR_ESP *esp);
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
-
-static unsigned char ctrl_data = 0;    /* Keep backup of the stuff written
-                                * to ctrl_reg. Always write a copy
-                                * to this register when writing to
-                                * the hardware register!
-                                */
-
-static volatile unsigned char cmd_buffer[16];
-                               /* This is where all commands are put
-                                * before they are transferred to the ESP chip
-                                * via PIO.
-                                */
-
-static inline void dma_clear(struct NCR_ESP *esp)
-{
-       struct fastlane_dma_registers *dregs =
-               (struct fastlane_dma_registers *) (esp->dregs);
-       unsigned long *t;
-
-       ctrl_data = (ctrl_data & FASTLANE_DMA_MASK);
-       dregs->ctrl_reg = ctrl_data;
-
-       t = (unsigned long *)(esp->edev);
-
-       dregs->clear_strobe = 0;
-       *t = 0 ;
-}
-
-/***************************************************************** Detection */
-int __init fastlane_esp_detect(struct scsi_host_template *tpnt)
-{
-       struct NCR_ESP *esp;
-       struct zorro_dev *z = NULL;
-       unsigned long address;
-
-       if ((z = zorro_find_device(ZORRO_PROD_PHASE5_BLIZZARD_1230_II_FASTLANE_Z3_CYBERSCSI_CYBERSTORM060, z))) {
-           unsigned long board = z->resource.start;
-           if (request_mem_region(board+FASTLANE_ESP_ADDR,
-                                  sizeof(struct ESP_regs), "NCR53C9x")) {
-               /* Check if this is really a fastlane controller. The problem
-                * is that also the cyberstorm and blizzard controllers use
-                * this ID value. Fortunately only Fastlane maps in Z3 space
-                */
-               if (board < 0x1000000) {
-                       goto err_release;
-               }
-               esp = esp_allocate(tpnt, (void *)board + FASTLANE_ESP_ADDR, 0);
-
-               /* Do command transfer with programmed I/O */
-               esp->do_pio_cmds = 1;
-
-               /* Required functions */
-               esp->dma_bytes_sent = &dma_bytes_sent;
-               esp->dma_can_transfer = &dma_can_transfer;
-               esp->dma_dump_state = &dma_dump_state;
-               esp->dma_init_read = &dma_init_read;
-               esp->dma_init_write = &dma_init_write;
-               esp->dma_ints_off = &dma_ints_off;
-               esp->dma_ints_on = &dma_ints_on;
-               esp->dma_irq_p = &dma_irq_p;
-               esp->dma_ports_p = &dma_ports_p;
-               esp->dma_setup = &dma_setup;
-
-               /* Optional functions */
-               esp->dma_barrier = 0;
-               esp->dma_drain = 0;
-               esp->dma_invalidate = 0;
-               esp->dma_irq_entry = 0;
-               esp->dma_irq_exit = &dma_irq_exit;
-               esp->dma_led_on = &dma_led_on;
-               esp->dma_led_off = &dma_led_off;
-               esp->dma_poll = 0;
-               esp->dma_reset = 0;
-
-               /* Initialize the portBits (enable IRQs) */
-               ctrl_data = (FASTLANE_DMA_FCODE |
-#ifndef NODMAIRQ
-                            FASTLANE_DMA_EDI |
-#endif
-                            FASTLANE_DMA_ESI);
-                       
-
-               /* SCSI chip clock */
-               esp->cfreq = 40000000;
-
-
-               /* Map the physical address space into virtual kernel space */
-               address = (unsigned long)
-                       z_ioremap(board, z->resource.end-board+1);
-
-               if(!address){
-                       printk("Could not remap Fastlane controller memory!");
-                       goto err_unregister;
-               }
-
-
-               /* The DMA registers on the Fastlane are mapped
-                * relative to the device (i.e. in the same Zorro
-                * I/O block).
-                */
-               esp->dregs = (void *)(address + FASTLANE_DMA_ADDR);
-
-               /* ESP register base */
-               esp->eregs = (struct ESP_regs *)(address + FASTLANE_ESP_ADDR);
-
-               /* Board base */
-               esp->edev = (void *) address;
-               
-               /* Set the command buffer */
-               esp->esp_command = cmd_buffer;
-               esp->esp_command_dvma = virt_to_bus((void *)cmd_buffer);
-
-               esp->irq = IRQ_AMIGA_PORTS;
-               esp->slot = board+FASTLANE_ESP_ADDR;
-               if (request_irq(IRQ_AMIGA_PORTS, esp_intr, IRQF_SHARED,
-                               "Fastlane SCSI", esp->ehost)) {
-                       printk(KERN_WARNING "Fastlane: Could not get IRQ%d, aborting.\n", IRQ_AMIGA_PORTS);
-                       goto err_unmap;
-               }                       
-
-               /* Controller ID */
-               esp->scsi_id = 7;
-               
-               /* We don't have a differential SCSI-bus. */
-               esp->diff = 0;
-
-               dma_clear(esp);
-               esp_initialize(esp);
-
-               printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps, esps_in_use);
-               esps_running = esps_in_use;
-               return esps_in_use;
-           }
-       }
-       return 0;
-
- err_unmap:
-       z_iounmap((void *)address);
- err_unregister:
-       scsi_unregister (esp->ehost);
- err_release:
-       release_mem_region(z->resource.start+FASTLANE_ESP_ADDR,
-                          sizeof(struct ESP_regs));
-       return 0;
-}
-
-
-/************************************************************* DMA Functions */
-static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
-{
-       /* Since the Fastlane DMA is fully dedicated to the ESP chip,
-        * the number of bytes sent (to the ESP chip) equals the number
-        * of bytes in the FIFO - there is no buffering in the DMA controller.
-        * XXXX Do I read this right? It is from host to ESP, right?
-        */
-       return fifo_count;
-}
-
-static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-       unsigned long sz = sp->SCp.this_residual;
-       if(sz > 0xfffc)
-               sz = 0xfffc;
-       return sz;
-}
-
-static void dma_dump_state(struct NCR_ESP *esp)
-{
-       ESPLOG(("esp%d: dma -- cond_reg<%02x>\n",
-               esp->esp_id, ((struct fastlane_dma_registers *)
-                             (esp->dregs))->cond_reg));
-       ESPLOG(("intreq:<%04x>, intena:<%04x>\n",
-               amiga_custom.intreqr, amiga_custom.intenar));
-}
-
-static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
-{
-       struct fastlane_dma_registers *dregs = 
-               (struct fastlane_dma_registers *) (esp->dregs);
-       unsigned long *t;
-       
-       cache_clear(addr, length);
-
-       dma_clear(esp);
-
-       t = (unsigned long *)((addr & 0x00ffffff) + esp->edev);
-
-       dregs->clear_strobe = 0;
-       *t = addr;
-
-       ctrl_data = (ctrl_data & FASTLANE_DMA_MASK) | FASTLANE_DMA_ENABLE;
-       dregs->ctrl_reg = ctrl_data;
-}
-
-static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
-{
-       struct fastlane_dma_registers *dregs = 
-               (struct fastlane_dma_registers *) (esp->dregs);
-       unsigned long *t;
-
-       cache_push(addr, length);
-
-       dma_clear(esp);
-
-       t = (unsigned long *)((addr & 0x00ffffff) + (esp->edev));
-
-       dregs->clear_strobe = 0;
-       *t = addr;
-
-       ctrl_data = ((ctrl_data & FASTLANE_DMA_MASK) | 
-                    FASTLANE_DMA_ENABLE |
-                    FASTLANE_DMA_WRITE);
-       dregs->ctrl_reg = ctrl_data;
-}
-
-
-static void dma_ints_off(struct NCR_ESP *esp)
-{
-       disable_irq(esp->irq);
-}
-
-static void dma_ints_on(struct NCR_ESP *esp)
-{
-       enable_irq(esp->irq);
-}
-
-static void dma_irq_exit(struct NCR_ESP *esp)
-{
-       struct fastlane_dma_registers *dregs = 
-               (struct fastlane_dma_registers *) (esp->dregs);
-
-       dregs->ctrl_reg = ctrl_data & ~(FASTLANE_DMA_EDI|FASTLANE_DMA_ESI);
-#ifdef __mc68000__
-       nop();
-#endif
-       dregs->ctrl_reg = ctrl_data;
-}
-
-static int dma_irq_p(struct NCR_ESP *esp)
-{
-       struct fastlane_dma_registers *dregs = 
-               (struct fastlane_dma_registers *) (esp->dregs);
-       unsigned char dma_status;
-
-       dma_status = dregs->cond_reg;
-
-       if(dma_status & FASTLANE_DMA_IACT)
-               return 0;       /* not our IRQ */
-
-       /* Return non-zero if ESP requested IRQ */
-       return (
-#ifndef NODMAIRQ
-          (dma_status & FASTLANE_DMA_CREQ) &&
-#endif
-          (!(dma_status & FASTLANE_DMA_MINT)) &&
-          (esp_read(((struct ESP_regs *) (esp->eregs))->esp_status) & ESP_STAT_INTR));
-}
-
-static void dma_led_off(struct NCR_ESP *esp)
-{
-       ctrl_data &= ~FASTLANE_DMA_LED;
-       ((struct fastlane_dma_registers *)(esp->dregs))->ctrl_reg = ctrl_data;
-}
-
-static void dma_led_on(struct NCR_ESP *esp)
-{
-       ctrl_data |= FASTLANE_DMA_LED;
-       ((struct fastlane_dma_registers *)(esp->dregs))->ctrl_reg = ctrl_data;
-}
-
-static int dma_ports_p(struct NCR_ESP *esp)
-{
-       return ((amiga_custom.intenar) & IF_PORTS);
-}
-
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
-{
-       /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
-        * so when (write) is true, it actually means READ!
-        */
-       if(write){
-               dma_init_read(esp, addr, count);
-       } else {
-               dma_init_write(esp, addr, count);
-       }
-}
-
-#define HOSTS_C
-
-int fastlane_esp_release(struct Scsi_Host *instance)
-{
-#ifdef MODULE
-       unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
-       esp_deallocate((struct NCR_ESP *)instance->hostdata);
-       esp_release();
-       release_mem_region(address, sizeof(struct ESP_regs));
-       free_irq(IRQ_AMIGA_PORTS, esp_intr);
-#endif
-       return 1;
-}
-
-
-static struct scsi_host_template driver_template = {
-       .proc_name              = "esp-fastlane",
-       .proc_info              = esp_proc_info,
-       .name                   = "Fastlane SCSI",
-       .detect                 = fastlane_esp_detect,
-       .slave_alloc            = esp_slave_alloc,
-       .slave_destroy          = esp_slave_destroy,
-       .release                = fastlane_esp_release,
-       .queuecommand           = esp_queue,
-       .eh_abort_handler       = esp_abort,
-       .eh_bus_reset_handler   = esp_reset,
-       .can_queue              = 7,
-       .this_id                = 7,
-       .sg_tablesize           = SG_ALL,
-       .cmd_per_lun            = 1,
-       .use_clustering         = ENABLE_CLUSTERING
-};
-
-#include "scsi_module.c"
-
-MODULE_LICENSE("GPL");
index b6f99dfbb038b91d02ef59d473a1052d4ab7b82b..8a178674cb18cd02928d0cd08a1ecf2be2503508 100644 (file)
@@ -629,8 +629,9 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
        int rc;
 
        if (tcp_conn->in.datalen) {
-               printk(KERN_ERR "iscsi_tcp: invalid R2t with datalen %d\n",
-                      tcp_conn->in.datalen);
+               iscsi_conn_printk(KERN_ERR, conn,
+                                 "invalid R2t with datalen %d\n",
+                                 tcp_conn->in.datalen);
                return ISCSI_ERR_DATALEN;
        }
 
@@ -644,8 +645,9 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
        iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr);
 
        if (!ctask->sc || session->state != ISCSI_STATE_LOGGED_IN) {
-               printk(KERN_INFO "iscsi_tcp: dropping R2T itt %d in "
-                      "recovery...\n", ctask->itt);
+               iscsi_conn_printk(KERN_INFO, conn,
+                                 "dropping R2T itt %d in recovery.\n",
+                                 ctask->itt);
                return 0;
        }
 
@@ -655,7 +657,8 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
        r2t->exp_statsn = rhdr->statsn;
        r2t->data_length = be32_to_cpu(rhdr->data_length);
        if (r2t->data_length == 0) {
-               printk(KERN_ERR "iscsi_tcp: invalid R2T with zero data len\n");
+               iscsi_conn_printk(KERN_ERR, conn,
+                                 "invalid R2T with zero data len\n");
                __kfifo_put(tcp_ctask->r2tpool.queue, (void*)&r2t,
                            sizeof(void*));
                return ISCSI_ERR_DATALEN;
@@ -668,9 +671,10 @@ iscsi_r2t_rsp(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask)
 
        r2t->data_offset = be32_to_cpu(rhdr->data_offset);
        if (r2t->data_offset + r2t->data_length > scsi_bufflen(ctask->sc)) {
-               printk(KERN_ERR "iscsi_tcp: invalid R2T with data len %u at "
-                      "offset %u and total length %d\n", r2t->data_length,
-                      r2t->data_offset, scsi_bufflen(ctask->sc));
+               iscsi_conn_printk(KERN_ERR, conn,
+                                 "invalid R2T with data len %u at offset %u "
+                                 "and total length %d\n", r2t->data_length,
+                                 r2t->data_offset, scsi_bufflen(ctask->sc));
                __kfifo_put(tcp_ctask->r2tpool.queue, (void*)&r2t,
                            sizeof(void*));
                return ISCSI_ERR_DATALEN;
@@ -736,8 +740,9 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
        /* verify PDU length */
        tcp_conn->in.datalen = ntoh24(hdr->dlength);
        if (tcp_conn->in.datalen > conn->max_recv_dlength) {
-               printk(KERN_ERR "iscsi_tcp: datalen %d > %d\n",
-                      tcp_conn->in.datalen, conn->max_recv_dlength);
+               iscsi_conn_printk(KERN_ERR, conn,
+                                 "iscsi_tcp: datalen %d > %d\n",
+                                 tcp_conn->in.datalen, conn->max_recv_dlength);
                return ISCSI_ERR_DATALEN;
        }
 
@@ -819,10 +824,12 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct iscsi_hdr *hdr)
                 * For now we fail until we find a vendor that needs it
                 */
                if (ISCSI_DEF_MAX_RECV_SEG_LEN < tcp_conn->in.datalen) {
-                       printk(KERN_ERR "iscsi_tcp: received buffer of len %u "
-                             "but conn buffer is only %u (opcode %0x)\n",
-                             tcp_conn->in.datalen,
-                             ISCSI_DEF_MAX_RECV_SEG_LEN, opcode);
+                       iscsi_conn_printk(KERN_ERR, conn,
+                                         "iscsi_tcp: received buffer of "
+                                         "len %u but conn buffer is only %u "
+                                         "(opcode %0x)\n",
+                                         tcp_conn->in.datalen,
+                                         ISCSI_DEF_MAX_RECV_SEG_LEN, opcode);
                        rc = ISCSI_ERR_PROTO;
                        break;
                }
@@ -1496,30 +1503,25 @@ iscsi_tcp_conn_create(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
        tcp_conn->tx_hash.tfm = crypto_alloc_hash("crc32c", 0,
                                                  CRYPTO_ALG_ASYNC);
        tcp_conn->tx_hash.flags = 0;
-       if (IS_ERR(tcp_conn->tx_hash.tfm)) {
-               printk(KERN_ERR "Could not create connection due to crc32c "
-                      "loading error %ld. Make sure the crc32c module is "
-                      "built as a module or into the kernel\n",
-                       PTR_ERR(tcp_conn->tx_hash.tfm));
+       if (IS_ERR(tcp_conn->tx_hash.tfm))
                goto free_tcp_conn;
-       }
 
        tcp_conn->rx_hash.tfm = crypto_alloc_hash("crc32c", 0,
                                                  CRYPTO_ALG_ASYNC);
        tcp_conn->rx_hash.flags = 0;
-       if (IS_ERR(tcp_conn->rx_hash.tfm)) {
-               printk(KERN_ERR "Could not create connection due to crc32c "
-                      "loading error %ld. Make sure the crc32c module is "
-                      "built as a module or into the kernel\n",
-                       PTR_ERR(tcp_conn->rx_hash.tfm));
+       if (IS_ERR(tcp_conn->rx_hash.tfm))
                goto free_tx_tfm;
-       }
 
        return cls_conn;
 
 free_tx_tfm:
        crypto_free_hash(tcp_conn->tx_hash.tfm);
 free_tcp_conn:
+       iscsi_conn_printk(KERN_ERR, conn,
+                         "Could not create connection due to crc32c "
+                         "loading error. Make sure the crc32c "
+                         "module is built as a module or into the "
+                         "kernel\n");
        kfree(tcp_conn);
 tcp_conn_alloc_fail:
        iscsi_conn_teardown(cls_conn);
@@ -1627,7 +1629,8 @@ iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session,
        /* lookup for existing socket */
        sock = sockfd_lookup((int)transport_eph, &err);
        if (!sock) {
-               printk(KERN_ERR "iscsi_tcp: sockfd_lookup failed %d\n", err);
+               iscsi_conn_printk(KERN_ERR, conn,
+                                 "sockfd_lookup failed %d\n", err);
                return -EEXIST;
        }
        /*
index 553168ae44f1864c01a6f5cdc8508cc985fc7029..59f8445eab0daa7a5b138c278897da53aa4ca351 100644 (file)
@@ -160,7 +160,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_cmd_task *ctask)
        hdr->opcode = ISCSI_OP_SCSI_CMD;
        hdr->flags = ISCSI_ATTR_SIMPLE;
        int_to_scsilun(sc->device->lun, (struct scsi_lun *)hdr->lun);
-       hdr->itt = build_itt(ctask->itt, conn->id, session->age);
+       hdr->itt = build_itt(ctask->itt, session->age);
        hdr->data_length = cpu_to_be32(scsi_bufflen(sc));
        hdr->cmdsn = cpu_to_be32(session->cmdsn);
        session->cmdsn++;
@@ -416,8 +416,9 @@ static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
 
                if (datalen < 2) {
 invalid_datalen:
-                       printk(KERN_ERR "iscsi: Got CHECK_CONDITION but "
-                              "invalid data buffer size of %d\n", datalen);
+                       iscsi_conn_printk(KERN_ERR,  conn,
+                                        "Got CHECK_CONDITION but invalid data "
+                                        "buffer size of %d\n", datalen);
                        sc->result = DID_BAD_TARGET << 16;
                        goto out;
                }
@@ -494,7 +495,7 @@ static void iscsi_send_nopout(struct iscsi_conn *conn, struct iscsi_nopin *rhdr)
 
        mtask = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)&hdr, NULL, 0);
        if (!mtask) {
-               printk(KERN_ERR "Could not send nopout\n");
+               iscsi_conn_printk(KERN_ERR, conn, "Could not send nopout\n");
                return;
        }
 
@@ -522,9 +523,10 @@ static int iscsi_handle_reject(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
                if (ntoh24(reject->dlength) >= sizeof(struct iscsi_hdr)) {
                        memcpy(&rejected_pdu, data, sizeof(struct iscsi_hdr));
                        itt = get_itt(rejected_pdu.itt);
-                       printk(KERN_ERR "itt 0x%x had pdu (op 0x%x) rejected "
-                               "due to DataDigest error.\n", itt,
-                               rejected_pdu.opcode);
+                       iscsi_conn_printk(KERN_ERR, conn,
+                                         "itt 0x%x had pdu (op 0x%x) rejected "
+                                         "due to DataDigest error.\n", itt,
+                                         rejected_pdu.opcode);
                }
        }
        return 0;
@@ -541,8 +543,8 @@ static int iscsi_handle_reject(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
  * queuecommand or send generic. session lock must be held and verify
  * itt must have been called.
  */
-int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
-                        char *data, int datalen)
+static int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
+                               char *data, int datalen)
 {
        struct iscsi_session *session = conn->session;
        int opcode = hdr->opcode & ISCSI_OPCODE_MASK, rc = 0;
@@ -672,7 +674,6 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
 
        return rc;
 }
-EXPORT_SYMBOL_GPL(__iscsi_complete_pdu);
 
 int iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
                       char *data, int datalen)
@@ -697,18 +698,13 @@ int iscsi_verify_itt(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
        if (hdr->itt != RESERVED_ITT) {
                if (((__force u32)hdr->itt & ISCSI_AGE_MASK) !=
                    (session->age << ISCSI_AGE_SHIFT)) {
-                       printk(KERN_ERR "iscsi: received itt %x expected "
-                               "session age (%x)\n", (__force u32)hdr->itt,
-                               session->age & ISCSI_AGE_MASK);
+                       iscsi_conn_printk(KERN_ERR, conn,
+                                         "received itt %x expected session "
+                                         "age (%x)\n", (__force u32)hdr->itt,
+                                         session->age & ISCSI_AGE_MASK);
                        return ISCSI_ERR_BAD_ITT;
                }
 
-               if (((__force u32)hdr->itt & ISCSI_CID_MASK) !=
-                   (conn->id << ISCSI_CID_SHIFT)) {
-                       printk(KERN_ERR "iscsi: received itt %x, expected "
-                               "CID (%x)\n", (__force u32)hdr->itt, conn->id);
-                       return ISCSI_ERR_BAD_ITT;
-               }
                itt = get_itt(hdr->itt);
        } else
                itt = ~0U;
@@ -717,16 +713,17 @@ int iscsi_verify_itt(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
                ctask = session->cmds[itt];
 
                if (!ctask->sc) {
-                       printk(KERN_INFO "iscsi: dropping ctask with "
-                              "itt 0x%x\n", ctask->itt);
+                       iscsi_conn_printk(KERN_INFO, conn, "dropping ctask "
+                                         "with itt 0x%x\n", ctask->itt);
                        /* force drop */
                        return ISCSI_ERR_NO_SCSI_CMD;
                }
 
                if (ctask->sc->SCp.phase != session->age) {
-                       printk(KERN_ERR "iscsi: ctask's session age %d, "
-                               "expected %d\n", ctask->sc->SCp.phase,
-                               session->age);
+                       iscsi_conn_printk(KERN_ERR, conn,
+                                         "iscsi: ctask's session age %d, "
+                                         "expected %d\n", ctask->sc->SCp.phase,
+                                         session->age);
                        return ISCSI_ERR_SESSION_FAILED;
                }
        }
@@ -771,7 +768,7 @@ static void iscsi_prep_mtask(struct iscsi_conn *conn,
         */
        nop->cmdsn = cpu_to_be32(session->cmdsn);
        if (hdr->itt != RESERVED_ITT) {
-               hdr->itt = build_itt(mtask->itt, conn->id, session->age);
+               hdr->itt = build_itt(mtask->itt, session->age);
                /*
                 * TODO: We always use immediate, so we never hit this.
                 * If we start to send tmfs or nops as non-immediate then
@@ -997,6 +994,7 @@ enum {
        FAILURE_SESSION_IN_RECOVERY,
        FAILURE_SESSION_RECOVERY_TIMEOUT,
        FAILURE_SESSION_LOGGING_OUT,
+       FAILURE_SESSION_NOT_READY,
 };
 
 int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
@@ -1017,6 +1015,12 @@ int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
        session = iscsi_hostdata(host->hostdata);
        spin_lock(&session->lock);
 
+       reason = iscsi_session_chkready(session_to_cls(session));
+       if (reason) {
+               sc->result = reason;
+               goto fault;
+       }
+
        /*
         * ISCSI_STATE_FAILED is a temp. state. The recovery
         * code will decide what is best to do with command queued
@@ -1033,18 +1037,23 @@ int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
                switch (session->state) {
                case ISCSI_STATE_IN_RECOVERY:
                        reason = FAILURE_SESSION_IN_RECOVERY;
-                       goto reject;
+                       sc->result = DID_IMM_RETRY << 16;
+                       break;
                case ISCSI_STATE_LOGGING_OUT:
                        reason = FAILURE_SESSION_LOGGING_OUT;
-                       goto reject;
+                       sc->result = DID_IMM_RETRY << 16;
+                       break;
                case ISCSI_STATE_RECOVERY_FAILED:
                        reason = FAILURE_SESSION_RECOVERY_TIMEOUT;
+                       sc->result = DID_NO_CONNECT << 16;
                        break;
                case ISCSI_STATE_TERMINATE:
                        reason = FAILURE_SESSION_TERMINATE;
+                       sc->result = DID_NO_CONNECT << 16;
                        break;
                default:
                        reason = FAILURE_SESSION_FREED;
+                       sc->result = DID_NO_CONNECT << 16;
                }
                goto fault;
        }
@@ -1052,6 +1061,7 @@ int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
        conn = session->leadconn;
        if (!conn) {
                reason = FAILURE_SESSION_FREED;
+               sc->result = DID_NO_CONNECT << 16;
                goto fault;
        }
 
@@ -1091,9 +1101,7 @@ reject:
 
 fault:
        spin_unlock(&session->lock);
-       printk(KERN_ERR "iscsi: cmd 0x%x is not queued (%d)\n",
-              sc->cmnd[0], reason);
-       sc->result = (DID_NO_CONNECT << 16);
+       debug_scsi("iscsi: cmd 0x%x is not queued (%d)\n", sc->cmnd[0], reason);
        scsi_set_resid(sc, scsi_bufflen(sc));
        sc->scsi_done(sc);
        spin_lock(host->host_lock);
@@ -1160,7 +1168,8 @@ failed:
        mutex_lock(&session->eh_mutex);
        spin_lock_bh(&session->lock);
        if (session->state == ISCSI_STATE_LOGGED_IN)
-               printk(KERN_INFO "iscsi: host reset succeeded\n");
+               iscsi_session_printk(KERN_INFO, session,
+                                    "host reset succeeded\n");
        else
                goto failed;
        spin_unlock_bh(&session->lock);
@@ -1239,7 +1248,8 @@ static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn,
  * Fail commands. session lock held and recv side suspended and xmit
  * thread flushed
  */
-static void fail_all_commands(struct iscsi_conn *conn, unsigned lun)
+static void fail_all_commands(struct iscsi_conn *conn, unsigned lun,
+                             int error)
 {
        struct iscsi_cmd_task *ctask, *tmp;
 
@@ -1251,7 +1261,7 @@ static void fail_all_commands(struct iscsi_conn *conn, unsigned lun)
                if (lun == ctask->sc->device->lun || lun == -1) {
                        debug_scsi("failing pending sc %p itt 0x%x\n",
                                   ctask->sc, ctask->itt);
-                       fail_command(conn, ctask, DID_BUS_BUSY << 16);
+                       fail_command(conn, ctask, error << 16);
                }
        }
 
@@ -1259,7 +1269,7 @@ static void fail_all_commands(struct iscsi_conn *conn, unsigned lun)
                if (lun == ctask->sc->device->lun || lun == -1) {
                        debug_scsi("failing requeued sc %p itt 0x%x\n",
                                   ctask->sc, ctask->itt);
-                       fail_command(conn, ctask, DID_BUS_BUSY << 16);
+                       fail_command(conn, ctask, error << 16);
                }
        }
 
@@ -1357,10 +1367,10 @@ static void iscsi_check_transport_timeouts(unsigned long data)
        last_recv = conn->last_recv;
        if (time_before_eq(last_recv + timeout + (conn->ping_timeout * HZ),
                           jiffies)) {
-               printk(KERN_ERR "ping timeout of %d secs expired, "
-                      "last rx %lu, last ping %lu, now %lu\n",
-                      conn->ping_timeout, last_recv,
-                      conn->last_ping, jiffies);
+               iscsi_conn_printk(KERN_ERR, conn, "ping timeout of %d secs "
+                                 "expired, last rx %lu, last ping %lu, "
+                                 "now %lu\n", conn->ping_timeout, last_recv,
+                                 conn->last_ping, jiffies);
                spin_unlock(&session->lock);
                iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
                return;
@@ -1373,14 +1383,11 @@ static void iscsi_check_transport_timeouts(unsigned long data)
                        iscsi_send_nopout(conn, NULL);
                }
                next_timeout = last_recv + timeout + (conn->ping_timeout * HZ);
-       } else {
+       } else
                next_timeout = last_recv + timeout;
-       }
 
-       if (next_timeout) {
-               debug_scsi("Setting next tmo %lu\n", next_timeout);
-               mod_timer(&conn->transport_timer, next_timeout);
-       }
+       debug_scsi("Setting next tmo %lu\n", next_timeout);
+       mod_timer(&conn->transport_timer, next_timeout);
 done:
        spin_unlock(&session->lock);
 }
@@ -1573,7 +1580,7 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc)
        /* need to grab the recv lock then session lock */
        write_lock_bh(conn->recv_lock);
        spin_lock(&session->lock);
-       fail_all_commands(conn, sc->device->lun);
+       fail_all_commands(conn, sc->device->lun, DID_ERROR);
        conn->tmf_state = TMF_INITIAL;
        spin_unlock(&session->lock);
        write_unlock_bh(conn->recv_lock);
@@ -1944,9 +1951,10 @@ void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn)
                }
                spin_unlock_irqrestore(session->host->host_lock, flags);
                msleep_interruptible(500);
-               printk(KERN_INFO "iscsi: scsi conn_destroy(): host_busy %d "
-                      "host_failed %d\n", session->host->host_busy,
-                      session->host->host_failed);
+               iscsi_conn_printk(KERN_INFO, conn, "iscsi conn_destroy(): "
+                                 "host_busy %d host_failed %d\n",
+                                 session->host->host_busy,
+                                 session->host->host_failed);
                /*
                 * force eh_abort() to unblock
                 */
@@ -1975,27 +1983,28 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
        struct iscsi_session *session = conn->session;
 
        if (!session) {
-               printk(KERN_ERR "iscsi: can't start unbound connection\n");
+               iscsi_conn_printk(KERN_ERR, conn,
+                                 "can't start unbound connection\n");
                return -EPERM;
        }
 
        if ((session->imm_data_en || !session->initial_r2t_en) &&
             session->first_burst > session->max_burst) {
-               printk("iscsi: invalid burst lengths: "
-                      "first_burst %d max_burst %d\n",
-                      session->first_burst, session->max_burst);
+               iscsi_conn_printk(KERN_INFO, conn, "invalid burst lengths: "
+                                 "first_burst %d max_burst %d\n",
+                                 session->first_burst, session->max_burst);
                return -EINVAL;
        }
 
        if (conn->ping_timeout && !conn->recv_timeout) {
-               printk(KERN_ERR "iscsi: invalid recv timeout of zero "
-                     "Using 5 seconds\n.");
+               iscsi_conn_printk(KERN_ERR, conn, "invalid recv timeout of "
+                                 "zero. Using 5 seconds\n.");
                conn->recv_timeout = 5;
        }
 
        if (conn->recv_timeout && !conn->ping_timeout) {
-               printk(KERN_ERR "iscsi: invalid ping timeout of zero "
-                     "Using 5 seconds.\n");
+               iscsi_conn_printk(KERN_ERR, conn, "invalid ping timeout of "
+                                 "zero. Using 5 seconds.\n");
                conn->ping_timeout = 5;
        }
 
@@ -2019,11 +2028,9 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
                conn->stop_stage = 0;
                conn->tmf_state = TMF_INITIAL;
                session->age++;
-               spin_unlock_bh(&session->lock);
-
-               iscsi_unblock_session(session_to_cls(session));
-               wake_up(&conn->ehwait);
-               return 0;
+               if (session->age == 16)
+                       session->age = 0;
+               break;
        case STOP_CONN_TERM:
                conn->stop_stage = 0;
                break;
@@ -2032,6 +2039,8 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
        }
        spin_unlock_bh(&session->lock);
 
+       iscsi_unblock_session(session_to_cls(session));
+       wake_up(&conn->ehwait);
        return 0;
 }
 EXPORT_SYMBOL_GPL(iscsi_conn_start);
@@ -2123,7 +2132,8 @@ static void iscsi_start_session_recovery(struct iscsi_session *session,
         * flush queues.
         */
        spin_lock_bh(&session->lock);
-       fail_all_commands(conn, -1);
+       fail_all_commands(conn, -1,
+                       STOP_CONN_RECOVER ? DID_BUS_BUSY : DID_ERROR);
        flush_control_queues(session, conn);
        spin_unlock_bh(&session->lock);
        mutex_unlock(&session->eh_mutex);
@@ -2140,7 +2150,8 @@ void iscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
                iscsi_start_session_recovery(session, conn, flag);
                break;
        default:
-               printk(KERN_ERR "iscsi: invalid stop flag %d\n", flag);
+               iscsi_conn_printk(KERN_ERR, conn,
+                                 "invalid stop flag %d\n", flag);
        }
 }
 EXPORT_SYMBOL_GPL(iscsi_conn_stop);
diff --git a/drivers/scsi/mac_esp.c b/drivers/scsi/mac_esp.c
deleted file mode 100644 (file)
index bcb4902..0000000
+++ /dev/null
@@ -1,751 +0,0 @@
-/*
- * 68k mac 53c9[46] scsi driver
- *
- * copyright (c) 1998, David Weis weisd3458@uni.edu
- *
- * debugging on Quadra 800 and 660AV Michael Schmitz, Dave Kilzer 7/98
- *
- * based loosely on cyber_esp.c
- */
-
-/* these are unused for now */
-#define myreadl(addr) (*(volatile unsigned int *) (addr))
-#define mywritel(b, addr) ((*(volatile unsigned int *) (addr)) = (b))
-
-
-#include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/types.h>
-#include <linux/ctype.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <linux/blkdev.h>
-#include <linux/proc_fs.h>
-#include <linux/stat.h>
-#include <linux/init.h>
-#include <linux/interrupt.h>
-
-#include "scsi.h"
-#include <scsi/scsi_host.h>
-#include "NCR53C9x.h"
-
-#include <asm/io.h>
-
-#include <asm/setup.h>
-#include <asm/irq.h>
-#include <asm/macints.h>
-#include <asm/machw.h>
-#include <asm/mac_via.h>
-
-#include <asm/pgtable.h>
-
-#include <asm/macintosh.h>
-
-/* #define DEBUG_MAC_ESP */
-
-extern void esp_handle(struct NCR_ESP *esp);
-extern void mac_esp_intr(int irq, void *dev_id);
-
-static int  dma_bytes_sent(struct NCR_ESP * esp, int fifo_count);
-static int  dma_can_transfer(struct NCR_ESP * esp, Scsi_Cmnd *sp);
-static void dma_dump_state(struct NCR_ESP * esp);
-static void dma_init_read(struct NCR_ESP * esp, char * vaddress, int length);
-static void dma_init_write(struct NCR_ESP * esp, char * vaddress, int length);
-static void dma_ints_off(struct NCR_ESP * esp);
-static void dma_ints_on(struct NCR_ESP * esp);
-static int  dma_irq_p(struct NCR_ESP * esp);
-static int  dma_irq_p_quick(struct NCR_ESP * esp);
-static void dma_led_off(struct NCR_ESP * esp);
-static void dma_led_on(struct NCR_ESP *esp);
-static int  dma_ports_p(struct NCR_ESP *esp);
-static void dma_setup(struct NCR_ESP * esp, __u32 addr, int count, int write);
-static void dma_setup_quick(struct NCR_ESP * esp, __u32 addr, int count, int write);
-
-static int esp_dafb_dma_irq_p(struct NCR_ESP * espdev);
-static int esp_iosb_dma_irq_p(struct NCR_ESP * espdev);
-
-static volatile unsigned char cmd_buffer[16];
-                               /* This is where all commands are put
-                                * before they are transferred to the ESP chip
-                                * via PIO.
-                                */
-
-static int esp_initialized = 0;
-
-static int setup_num_esps = -1;
-static int setup_disconnect = -1;
-static int setup_nosync = -1;
-static int setup_can_queue = -1;
-static int setup_cmd_per_lun = -1;
-static int setup_sg_tablesize = -1;
-#ifdef SUPPORT_TAGS
-static int setup_use_tagged_queuing = -1;
-#endif
-static int setup_hostid = -1;
-
-/*
- * Experimental ESP inthandler; check macints.c to make sure dev_id is 
- * set up properly!
- */
-
-void mac_esp_intr(int irq, void *dev_id)
-{
-       struct NCR_ESP *esp = (struct NCR_ESP *) dev_id;
-       int irq_p = 0;
-
-       /* Handle the one ESP interrupt showing at this IRQ level. */
-       if(((esp)->irq & 0xff) == irq) {
-       /*
-        * Debug ..
-        */
-               irq_p = esp->dma_irq_p(esp);
-               printk("mac_esp: irq_p %x current %p disconnected %p\n",
-                       irq_p, esp->current_SC, esp->disconnected_SC);
-                       
-               /*
-                * Mac: if we're here, it's an ESP interrupt for sure!
-                */
-               if((esp->current_SC || esp->disconnected_SC)) {
-                       esp->dma_ints_off(esp);
-
-                       ESPIRQ(("I%d(", esp->esp_id));
-                       esp_handle(esp);
-                       ESPIRQ((")"));
-
-                       esp->dma_ints_on(esp);
-               }
-       }
-}
-
-/*
- * Debug hooks; use for playing with the interrupt flag testing and interrupt
- * acknowledge on the various machines
- */
-
-void scsi_esp_polled(int irq, void *dev_id)
-{
-       if (esp_initialized == 0)
-               return;
-
-       mac_esp_intr(irq, dev_id);
-}
-
-void fake_intr(int irq, void *dev_id)
-{
-#ifdef DEBUG_MAC_ESP
-       printk("mac_esp: got irq\n");
-#endif
-
-       mac_esp_intr(irq, dev_id);
-}
-
-irqreturn_t fake_drq(int irq, void *dev_id)
-{
-       printk("mac_esp: got drq\n");
-       return IRQ_HANDLED;
-}
-
-#define DRIVER_SETUP
-
-/*
- * Function : mac_esp_setup(char *str)
- *
- * Purpose : booter command line initialization of the overrides array,
- *
- * Inputs : str - parameters, separated by commas.
- *
- * Currently unused in the new driver; need to add settable parameters to the 
- * detect function.
- *
- */
-
-static int __init mac_esp_setup(char *str) {
-#ifdef DRIVER_SETUP
-       /* Format of mac53c9x parameter is:
-        *   mac53c9x=<num_esps>,<disconnect>,<nosync>,<can_queue>,<cmd_per_lun>,<sg_tablesize>,<hostid>,<use_tags>
-        * Negative values mean don't change.
-        */
-       
-       char *this_opt;
-       long opt;
-
-       this_opt = strsep (&str, ",");
-       if(this_opt) {
-               opt = simple_strtol( this_opt, NULL, 0 );
-
-               if (opt >= 0 && opt <= 2)
-                       setup_num_esps = opt;
-               else if (opt > 2)
-                       printk( "mac_esp_setup: invalid number of hosts %ld !\n", opt );
-
-               this_opt = strsep (&str, ",");
-       }
-       if(this_opt) {
-               opt = simple_strtol( this_opt, NULL, 0 );
-       
-               if (opt > 0)
-                       setup_disconnect = opt;
-
-               this_opt = strsep (&str, ",");
-       }
-       if(this_opt) {
-               opt = simple_strtol( this_opt, NULL, 0 );
-
-               if (opt >= 0)
-                       setup_nosync = opt;
-
-               this_opt = strsep (&str, ",");
-       }
-       if(this_opt) {
-               opt = simple_strtol( this_opt, NULL, 0 );
-
-               if (opt > 0)
-                       setup_can_queue = opt;
-
-               this_opt = strsep (&str, ",");
-       }
-       if(this_opt) {
-               opt = simple_strtol( this_opt, NULL, 0 );
-
-               if (opt > 0)
-                       setup_cmd_per_lun = opt;
-
-               this_opt = strsep (&str, ",");
-       }
-       if(this_opt) {
-               opt = simple_strtol( this_opt, NULL, 0 );
-
-               if (opt >= 0) {
-                       setup_sg_tablesize = opt;
-                       /* Must be <= SG_ALL (255) */
-                       if (setup_sg_tablesize > SG_ALL)
-                               setup_sg_tablesize = SG_ALL;
-               }
-
-               this_opt = strsep (&str, ",");
-       }
-       if(this_opt) {
-               opt = simple_strtol( this_opt, NULL, 0 );
-
-               /* Must be between 0 and 7 */
-               if (opt >= 0 && opt <= 7)
-                       setup_hostid = opt;
-               else if (opt > 7)
-                       printk( "mac_esp_setup: invalid host ID %ld !\n", opt);
-
-               this_opt = strsep (&str, ",");
-       }
-#ifdef SUPPORT_TAGS
-       if(this_opt) {
-               opt = simple_strtol( this_opt, NULL, 0 );
-               if (opt >= 0)
-                       setup_use_tagged_queuing = !!opt;
-       }
-#endif
-#endif
-       return 1; 
-}
-
-__setup("mac53c9x=", mac_esp_setup);
-
-
-/*
- * ESP address 'detection'
- */
-
-unsigned long get_base(int chip_num)
-{
-       /*
-        * using the chip_num and mac model, figure out where the
-        * chips are mapped
-        */
-
-       unsigned long io_base = 0x50f00000;
-       unsigned int second_offset = 0x402;
-       unsigned long scsi_loc = 0;
-
-       switch (macintosh_config->scsi_type) {
-
-       /* 950, 900, 700 */
-       case MAC_SCSI_QUADRA2:
-               scsi_loc =  io_base + 0xf000 + ((chip_num == 0) ? 0 : second_offset);
-               break;
-
-       /* av's */
-       case MAC_SCSI_QUADRA3:
-               scsi_loc = io_base + 0x18000 + ((chip_num == 0) ? 0 : second_offset);
-               break;
-
-       /* most quadra/centris models are like this */  
-       case MAC_SCSI_QUADRA:
-               scsi_loc = io_base + 0x10000;
-               break;
-
-       default:
-               printk("mac_esp: get_base: hit default!\n");
-               scsi_loc = io_base + 0x10000;
-               break;
-
-       } /* switch */
-
-       printk("mac_esp: io base at 0x%lx\n", scsi_loc);
-
-       return scsi_loc;
-}
-
-/*
- * Model dependent ESP setup
- */
-
-int mac_esp_detect(struct scsi_host_template * tpnt)
-{
-       int quick = 0;
-       int chipnum, chipspresent = 0;
-#if 0
-       unsigned long timeout;
-#endif
-
-       if (esp_initialized > 0)
-               return -ENODEV;
-
-       /* what do we have in this machine... */
-       if (MACHW_PRESENT(MAC_SCSI_96)) {
-               chipspresent ++;
-       }
-
-       if (MACHW_PRESENT(MAC_SCSI_96_2)) {
-               chipspresent ++;
-       }
-
-       /* number of ESPs present ? */
-       if (setup_num_esps >= 0) {
-         if (chipspresent >= setup_num_esps)
-           chipspresent = setup_num_esps;
-         else
-           printk("mac_esp_detect: num_hosts detected %d setup %d \n",
-                  chipspresent, setup_num_esps);
-       }
-
-       /* TODO: add disconnect / nosync flags */
-
-       /* setup variables */
-       tpnt->can_queue =
-         (setup_can_queue > 0) ? setup_can_queue : 7;
-       tpnt->cmd_per_lun =
-         (setup_cmd_per_lun > 0) ? setup_cmd_per_lun : 1;
-       tpnt->sg_tablesize = 
-         (setup_sg_tablesize >= 0) ? setup_sg_tablesize : SG_ALL;
-
-       if (setup_hostid >= 0)
-         tpnt->this_id = setup_hostid;
-       else {
-         /* use 7 as default */
-         tpnt->this_id = 7;
-       }
-
-#ifdef SUPPORT_TAGS
-       if (setup_use_tagged_queuing < 0)
-               setup_use_tagged_queuing = DEFAULT_USE_TAGGED_QUEUING;
-#endif
-
-       for (chipnum = 0; chipnum < chipspresent; chipnum ++) {
-               struct NCR_ESP * esp;
-
-               esp = esp_allocate(tpnt, NULL, 0);
-               esp->eregs = (struct ESP_regs *) get_base(chipnum);
-
-               esp->dma_irq_p = &esp_dafb_dma_irq_p;
-               if (chipnum == 0) {
-
-                       if (macintosh_config->scsi_type == MAC_SCSI_QUADRA) {
-                               /* most machines except those below :-) */
-                               quick = 1;
-                               esp->dma_irq_p = &esp_iosb_dma_irq_p;
-                       } else if (macintosh_config->scsi_type == MAC_SCSI_QUADRA3) {
-                               /* mostly av's */
-                               quick = 0;
-                       } else {
-                               /* q950, 900, 700 */
-                               quick = 1;
-                               out_be32(0xf9800024, 0x1d1);
-                               esp->dregs = (void *) 0xf9800024;
-                       }
-
-               } else { /* chipnum */
-
-                       quick = 1;
-                       out_be32(0xf9800028, 0x1d1);
-                       esp->dregs = (void *) 0xf9800028;
-
-               } /* chipnum == 0 */
-
-               /* use pio for command bytes; pio for message/data: TBI */
-               esp->do_pio_cmds = 1;
-
-               /* Set the command buffer */
-               esp->esp_command = (volatile unsigned char*) cmd_buffer;
-               esp->esp_command_dvma = (__u32) cmd_buffer;
-
-               /* various functions */
-               esp->dma_bytes_sent = &dma_bytes_sent;
-               esp->dma_can_transfer = &dma_can_transfer;
-               esp->dma_dump_state = &dma_dump_state;
-               esp->dma_init_read = NULL;
-               esp->dma_init_write = NULL;
-               esp->dma_ints_off = &dma_ints_off;
-               esp->dma_ints_on = &dma_ints_on;
-
-               esp->dma_ports_p = &dma_ports_p;
-
-
-               /* Optional functions */
-               esp->dma_barrier = NULL;
-               esp->dma_drain = NULL;
-               esp->dma_invalidate = NULL;
-               esp->dma_irq_entry = NULL;
-               esp->dma_irq_exit = NULL;
-               esp->dma_led_on = NULL;
-               esp->dma_led_off = NULL;
-               esp->dma_poll = NULL;
-               esp->dma_reset = NULL;
-
-               /* SCSI chip speed */
-               /* below esp->cfreq = 40000000; */
-
-
-               if (quick) {
-                       /* 'quick' means there's handshake glue logic like in the 5380 case */
-                       esp->dma_setup = &dma_setup_quick;
-               } else {
-                       esp->dma_setup = &dma_setup;
-               }
-
-               if (chipnum == 0) {
-
-                       esp->irq = IRQ_MAC_SCSI;
-
-                       request_irq(IRQ_MAC_SCSI, esp_intr, 0, "Mac ESP SCSI", esp->ehost);
-#if 0  /* conflicts with IOP ADB */
-                       request_irq(IRQ_MAC_SCSIDRQ, fake_drq, 0, "Mac ESP DRQ", esp->ehost);
-#endif
-
-                       if (macintosh_config->scsi_type == MAC_SCSI_QUADRA) {
-                               esp->cfreq = 16500000;
-                       } else {
-                               esp->cfreq = 25000000;
-                       }
-
-
-               } else { /* chipnum == 1 */
-
-                       esp->irq = IRQ_MAC_SCSIDRQ;
-#if 0  /* conflicts with IOP ADB */
-                       request_irq(IRQ_MAC_SCSIDRQ, esp_intr, 0, "Mac ESP SCSI 2", esp->ehost);
-#endif
-
-                       esp->cfreq = 25000000;
-
-               }
-
-               if (quick) {
-                       printk("esp: using quick version\n");
-               }
-
-               printk("esp: addr at 0x%p\n", esp->eregs);
-
-               esp->scsi_id = 7;
-               esp->diff = 0;
-
-               esp_initialize(esp);
-
-       } /* for chipnum */
-
-       if (chipspresent)
-               printk("\nmac_esp: %d esp controllers found\n", chipspresent);
-
-       esp_initialized = chipspresent;
-
-       return chipspresent;
-}
-
-static int mac_esp_release(struct Scsi_Host *shost)
-{
-       if (shost->irq)
-               free_irq(shost->irq, NULL);
-       if (shost->io_port && shost->n_io_port)
-               release_region(shost->io_port, shost->n_io_port);
-       scsi_unregister(shost);
-       return 0;
-}
-
-/*
- * I've been wondering what this is supposed to do, for some time. Talking 
- * to Allen Briggs: These machines have an extra register someplace where the
- * DRQ pin of the ESP can be monitored. That isn't useful for determining 
- * anything else (such as reselect interrupt or other magic) though. 
- * Maybe make the semantics should be changed like 
- * if (esp->current_SC)
- *     ... check DRQ flag ...
- * else 
- *     ... disconnected, check pending VIA interrupt ...
- *
- * There's a problem with using the dabf flag or mac_irq_pending() here: both
- * seem to return 1 even though no interrupt is currently pending, resulting
- * in esp_exec_cmd() holding off the next command, and possibly infinite loops
- * in esp_intr(). 
- * Short term fix: just use esp_status & ESP_STAT_INTR here, as long as we
- * use simple PIO. The DRQ status will be important when implementing pseudo
- * DMA mode (set up ESP transfer count, return, do a batch of bytes in PIO or 
- * 'hardware handshake' mode upon DRQ).
- * If you plan on changing this (i.e. to save the esp_status register access in 
- * favor of a VIA register access or a shadow register for the IFR), make sure
- * to try a debug version of this first to monitor what registers would be a good
- * indicator of the ESP interrupt.
- */
-
-static int esp_dafb_dma_irq_p(struct NCR_ESP * esp)
-{
-       unsigned int ret;
-       int sreg = esp_read(esp->eregs->esp_status);
-
-#ifdef DEBUG_MAC_ESP
-       printk("mac_esp: esp_dafb_dma_irq_p dafb %d irq %d\n", 
-               readl(esp->dregs), mac_irq_pending(IRQ_MAC_SCSI));
-#endif
-
-       sreg &= ESP_STAT_INTR;
-
-       /*
-        * maybe working; this is essentially what's used for iosb_dma_irq_p
-        */
-       if (sreg)
-               return 1;
-       else
-               return 0;
-
-       /*
-        * didn't work ...
-        */
-#if 0
-       if (esp->current_SC)
-               ret = readl(esp->dregs) & 0x200;
-       else if (esp->disconnected_SC)
-               ret = 1; /* sreg ?? */
-       else
-               ret = mac_irq_pending(IRQ_MAC_SCSI);
-
-       return(ret);
-#endif
-
-}
-
-/*
- * See above: testing mac_irq_pending always returned 8 (SCSI IRQ) regardless 
- * of the actual ESP status.
- */
-
-static int esp_iosb_dma_irq_p(struct NCR_ESP * esp)
-{
-       int ret  = mac_irq_pending(IRQ_MAC_SCSI) || mac_irq_pending(IRQ_MAC_SCSIDRQ);
-       int sreg = esp_read(esp->eregs->esp_status);
-
-#ifdef DEBUG_MAC_ESP
-       printk("mac_esp: dma_irq_p drq %d irq %d sreg %x curr %p disc %p\n", 
-               mac_irq_pending(IRQ_MAC_SCSIDRQ), mac_irq_pending(IRQ_MAC_SCSI), 
-               sreg, esp->current_SC, esp->disconnected_SC);
-#endif
-
-       sreg &= ESP_STAT_INTR;
-
-       if (sreg)
-               return (sreg);
-       else
-               return 0;
-}
-
-/*
- * This seems to be OK for PIO at least ... usually 0 after PIO.
- */
-
-static int dma_bytes_sent(struct NCR_ESP * esp, int fifo_count)
-{
-
-#ifdef DEBUG_MAC_ESP
-       printk("mac_esp: dma bytes sent = %x\n", fifo_count);
-#endif
-
-       return fifo_count;
-}
-
-/*
- * dma_can_transfer is used to switch between DMA and PIO, if DMA (pseudo)
- * is ever implemented. Returning 0 here will use PIO.
- */
-
-static int dma_can_transfer(struct NCR_ESP * esp, Scsi_Cmnd * sp)
-{
-       unsigned long sz = sp->SCp.this_residual;
-#if 0  /* no DMA yet; make conditional */
-       if (sz > 0x10000000) {
-               sz = 0x10000000;
-       }
-       printk("mac_esp: dma can transfer = 0lx%x\n", sz);
-#else
-
-#ifdef DEBUG_MAC_ESP
-       printk("mac_esp: pio to transfer = %ld\n", sz);
-#endif
-
-       sz = 0;
-#endif
-       return sz;
-}
-
-/*
- * Not yet ...
- */
-
-static void dma_dump_state(struct NCR_ESP * esp)
-{
-#ifdef DEBUG_MAC_ESP
-       printk("mac_esp: dma_dump_state: called\n");
-#endif
-#if 0
-       ESPLOG(("esp%d: dma -- cond_reg<%02x>\n",
-               esp->esp_id, ((struct mac_dma_registers *)
-               (esp->dregs))->cond_reg));
-#endif
-}
-
-/*
- * DMA setup: should be used to set up the ESP transfer count for pseudo
- * DMA transfers; need a DRQ transfer function to do the actual transfer
- */
-
-static void dma_init_read(struct NCR_ESP * esp, char * vaddress, int length)
-{
-       printk("mac_esp: dma_init_read\n");
-}
-
-
-static void dma_init_write(struct NCR_ESP * esp, char * vaddress, int length)
-{
-       printk("mac_esp: dma_init_write\n");
-}
-
-
-static void dma_ints_off(struct NCR_ESP * esp)
-{
-       disable_irq(esp->irq);
-}
-
-
-static void dma_ints_on(struct NCR_ESP * esp)
-{
-       enable_irq(esp->irq);
-}
-
-/*
- * generic dma_irq_p(), unused
- */
-
-static int dma_irq_p(struct NCR_ESP * esp)
-{
-       int i = esp_read(esp->eregs->esp_status);
-
-#ifdef DEBUG_MAC_ESP
-       printk("mac_esp: dma_irq_p status %d\n", i);
-#endif
-
-       return (i & ESP_STAT_INTR);
-}
-
-static int dma_irq_p_quick(struct NCR_ESP * esp)
-{
-       /*
-        * Copied from iosb_dma_irq_p()
-        */
-       int ret  = mac_irq_pending(IRQ_MAC_SCSI) || mac_irq_pending(IRQ_MAC_SCSIDRQ);
-       int sreg = esp_read(esp->eregs->esp_status);
-
-#ifdef DEBUG_MAC_ESP
-       printk("mac_esp: dma_irq_p drq %d irq %d sreg %x curr %p disc %p\n", 
-               mac_irq_pending(IRQ_MAC_SCSIDRQ), mac_irq_pending(IRQ_MAC_SCSI), 
-               sreg, esp->current_SC, esp->disconnected_SC);
-#endif
-
-       sreg &= ESP_STAT_INTR;
-
-       if (sreg)
-               return (sreg);
-       else
-               return 0;
-
-}
-
-static void dma_led_off(struct NCR_ESP * esp)
-{
-#ifdef DEBUG_MAC_ESP
-       printk("mac_esp: dma_led_off: called\n");
-#endif
-}
-
-
-static void dma_led_on(struct NCR_ESP * esp)
-{
-#ifdef DEBUG_MAC_ESP
-       printk("mac_esp: dma_led_on: called\n");
-#endif
-}
-
-
-static int dma_ports_p(struct NCR_ESP * esp)
-{
-       return 0;
-}
-
-
-static void dma_setup(struct NCR_ESP * esp, __u32 addr, int count, int write)
-{
-
-#ifdef DEBUG_MAC_ESP
-       printk("mac_esp: dma_setup\n");
-#endif
-
-       if (write) {
-               dma_init_read(esp, (char *) addr, count);
-       } else {
-               dma_init_write(esp, (char *) addr, count);
-       }
-}
-
-
-static void dma_setup_quick(struct NCR_ESP * esp, __u32 addr, int count, int write)
-{
-#ifdef DEBUG_MAC_ESP
-       printk("mac_esp: dma_setup_quick\n");
-#endif
-}
-
-static struct scsi_host_template driver_template = {
-       .proc_name              = "mac_esp",
-       .name                   = "Mac 53C9x SCSI",
-       .detect                 = mac_esp_detect,
-       .slave_alloc            = esp_slave_alloc,
-       .slave_destroy          = esp_slave_destroy,
-       .release                = mac_esp_release,
-       .info                   = esp_info,
-       .queuecommand           = esp_queue,
-       .eh_abort_handler       = esp_abort,
-       .eh_bus_reset_handler   = esp_reset,
-       .can_queue              = 7,
-       .this_id                = 7,
-       .sg_tablesize           = SG_ALL,
-       .cmd_per_lun            = 1,
-       .use_clustering         = DISABLE_CLUSTERING
-};
-
-
-#include "scsi_module.c"
-
-MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/mca_53c9x.c b/drivers/scsi/mca_53c9x.c
deleted file mode 100644 (file)
index d693d0f..0000000
+++ /dev/null
@@ -1,520 +0,0 @@
-/* mca_53c9x.c: Driver for the SCSI adapter found on NCR 35xx
- *  (and maybe some other) Microchannel machines
- *
- * Code taken mostly from Cyberstorm SCSI drivers
- *   Copyright (C) 1996 Jesper Skov (jskov@cygnus.co.uk)
- *
- * Hacked to work with the NCR MCA stuff by Tymm Twillman (tymm@computer.org)
- *
- * The CyberStorm SCSI driver (and this driver) is based on David S. Miller's
- *   ESP driver  * for the Sparc computers. 
- * 
- * Special thanks to Ken Stewart at Symbios (LSI) for helping with info on
- *  the 86C01.  I was on the brink of going ga-ga...
- *
- * Also thanks to Jesper Skov for helping me with info on how the Amiga
- *  does things...
- */
-
-/*
- * This is currently only set up to use one 53c9x card at a time; it could be 
- *  changed fairly easily to detect/use more than one, but I'm not too sure how
- *  many cards that use the 53c9x on MCA systems there are (if, in fact, there
- *  are cards that use them, other than the one built into some NCR systems)...
- *  If anyone requests this, I'll throw it in, otherwise it's not worth the
- *  effort.
- */
-
-/*
- * Info on the 86C01 MCA interface chip at the bottom, if you care enough to
- *  look.
- */
-
-#include <linux/delay.h>
-#include <linux/interrupt.h>
-#include <linux/kernel.h>
-#include <linux/mca.h>
-#include <linux/types.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <linux/blkdev.h>
-#include <linux/proc_fs.h>
-#include <linux/stat.h>
-#include <linux/mca-legacy.h>
-
-#include "scsi.h"
-#include <scsi/scsi_host.h>
-#include "NCR53C9x.h"
-
-#include <asm/dma.h>
-#include <asm/irq.h>
-#include <asm/mca_dma.h>
-#include <asm/pgtable.h>
-
-/*
- * From ibmmca.c (IBM scsi controller card driver) -- used for turning PS2 disk
- *  activity LED on and off
- */
-
-#define PS2_SYS_CTR    0x92
-
-/* Ports the ncr's 53c94 can be put at; indexed by pos register value */
-
-#define MCA_53C9X_IO_PORTS {                             \
-                         0x0000, 0x0240, 0x0340, 0x0400, \
-                        0x0420, 0x3240, 0x8240, 0xA240, \
-                       }
-                       
-/*
- * Supposedly there were some cards put together with the 'c9x and 86c01.  If
- *   they have different ID's from the ones on the 3500 series machines, 
- *   you can add them here and hopefully things will work out.
- */
-                       
-#define MCA_53C9X_IDS {          \
-                         0x7F4C, \
-                        0x0000, \
-                        }
-
-static int  dma_bytes_sent(struct NCR_ESP *, int);
-static int  dma_can_transfer(struct NCR_ESP *, Scsi_Cmnd *);
-static void dma_dump_state(struct NCR_ESP *);
-static void dma_init_read(struct NCR_ESP *, __u32, int);
-static void dma_init_write(struct NCR_ESP *, __u32, int);
-static void dma_ints_off(struct NCR_ESP *);
-static void dma_ints_on(struct NCR_ESP *);
-static int  dma_irq_p(struct NCR_ESP *);
-static int  dma_ports_p(struct NCR_ESP *);
-static void dma_setup(struct NCR_ESP *, __u32, int, int);
-static void dma_led_on(struct NCR_ESP *);
-static void dma_led_off(struct NCR_ESP *);
-
-/* This is where all commands are put before they are trasfered to the 
- *  53c9x via PIO.
- */
-
-static volatile unsigned char cmd_buffer[16];
-
-/*
- * We keep the structure that is used to access the registers on the 53c9x
- *  here.
- */
-
-static struct ESP_regs eregs;
-
-/***************************************************************** Detection */
-static int mca_esp_detect(struct scsi_host_template *tpnt)
-{
-       struct NCR_ESP *esp;
-       static int io_port_by_pos[] = MCA_53C9X_IO_PORTS;
-       int mca_53c9x_ids[] = MCA_53C9X_IDS;
-       int *id_to_check = mca_53c9x_ids;
-       int slot;
-       int pos[3];
-       unsigned int tmp_io_addr;
-       unsigned char tmp_byte;
-
-
-       if (!MCA_bus)
-               return 0;
-
-       while (*id_to_check) { 
-               if ((slot = mca_find_adapter(*id_to_check, 0)) !=
-                 MCA_NOTFOUND) 
-               {
-                       esp = esp_allocate(tpnt, NULL, 0);
-
-                       pos[0] = mca_read_stored_pos(slot, 2);
-                       pos[1] = mca_read_stored_pos(slot, 3);
-                       pos[2] = mca_read_stored_pos(slot, 4);
-
-                       esp->eregs = &eregs;
-
-                       /*
-                        * IO port base is given in the first (non-ID) pos
-                        *  register, like so:
-                        *
-                        *  Bits 3  2  1       IO base
-                        * ----------------------------
-                        *       0  0  0       <disabled>
-                        *       0  0  1       0x0240
-                        *       0  1  0       0x0340
-                        *       0  1  1       0x0400
-                        *       1  0  0       0x0420
-                        *       1  0  1       0x3240
-                        *       1  1  0       0x8240
-                        *       1  1  1       0xA240
-                        */
-
-                       tmp_io_addr =
-                         io_port_by_pos[(pos[0] & 0x0E) >> 1];
-
-                       esp->eregs->io_addr = tmp_io_addr + 0x10;
-
-                       if (esp->eregs->io_addr == 0x0000) { 
-                               printk("Adapter is disabled.\n");
-                               break;
-                       }
-
-                       /*
-                        * IRQ is specified in bits 4 and 5:
-                        *
-                        *  Bits  4  5        IRQ
-                        * -----------------------
-                        *        0  0         3
-                        *        0  1         5
-                        *        1  0         7
-                        *        1  1         9
-                        */
-
-                       esp->irq = ((pos[0] & 0x30) >> 3) + 3;
-
-                       /*
-                        * DMA channel is in the low 3 bits of the second
-                        *  POS register
-                        */
-
-                       esp->dma = pos[1] & 7;
-                       esp->slot = slot;
-
-                       if (request_irq(esp->irq, esp_intr, 0,
-                        "NCR 53c9x SCSI", esp->ehost))
-                       {
-                               printk("Unable to request IRQ %d.\n", esp->irq);
-                               esp_deallocate(esp);
-                               scsi_unregister(esp->ehost);
-                               return 0;
-                       }
-
-                       if (request_dma(esp->dma, "NCR 53c9x SCSI")) {
-                               printk("Unable to request DMA channel %d.\n",
-                                esp->dma);
-                               free_irq(esp->irq, esp_intr);
-                               esp_deallocate(esp);
-                               scsi_unregister(esp->ehost);
-                               return 0;
-                       }
-
-                       request_region(tmp_io_addr, 32, "NCR 53c9x SCSI");
-
-                       /*
-                        * 86C01 handles DMA, IO mode, from address
-                        *  (base + 0x0a)
-                        */
-
-                       mca_disable_dma(esp->dma);
-                       mca_set_dma_io(esp->dma, tmp_io_addr + 0x0a);
-                       mca_enable_dma(esp->dma);
-                       /* Tell the 86C01 to give us interrupts */
-
-                       tmp_byte = inb(tmp_io_addr + 0x02) | 0x40;
-                       outb(tmp_byte, tmp_io_addr + 0x02); 
-
-                       /*
-                        * Scsi ID -- general purpose register, hi
-                        *  2 bits; add 4 to this number to get the
-                        *  ID
-                        */
-
-                       esp->scsi_id = ((pos[2] & 0xC0) >> 6) + 4;
-
-                       /* Do command transfer with programmed I/O */
-
-                       esp->do_pio_cmds = 1;
-
-                       /* Required functions */
-
-                       esp->dma_bytes_sent = &dma_bytes_sent;
-                       esp->dma_can_transfer = &dma_can_transfer;
-                       esp->dma_dump_state = &dma_dump_state;
-                       esp->dma_init_read = &dma_init_read;
-                       esp->dma_init_write = &dma_init_write;
-                       esp->dma_ints_off = &dma_ints_off;
-                       esp->dma_ints_on = &dma_ints_on;
-                       esp->dma_irq_p = &dma_irq_p;
-                       esp->dma_ports_p = &dma_ports_p;
-                       esp->dma_setup = &dma_setup;
-
-                       /* Optional functions */
-
-                       esp->dma_barrier = NULL;
-                       esp->dma_drain = NULL;
-                       esp->dma_invalidate = NULL;
-                       esp->dma_irq_entry = NULL;
-                       esp->dma_irq_exit = NULL;
-                       esp->dma_led_on = dma_led_on;
-                       esp->dma_led_off = dma_led_off;
-                       esp->dma_poll = NULL;
-                       esp->dma_reset = NULL;
-
-                       /* Set the command buffer */
-
-                       esp->esp_command = (volatile unsigned char*)
-                         cmd_buffer;
-                       esp->esp_command_dvma = isa_virt_to_bus(cmd_buffer);
-
-                       /* SCSI chip speed */
-
-                       esp->cfreq = 25000000;
-
-                       /* Differential SCSI? I think not. */
-
-                       esp->diff = 0;
-
-                       esp_initialize(esp);
-
-                       printk(" Adapter found in slot %2d: io port 0x%x "
-                         "irq %d dma channel %d\n", slot + 1, tmp_io_addr,
-                          esp->irq, esp->dma);
-
-                       mca_set_adapter_name(slot, "NCR 53C9X SCSI Adapter");
-                       mca_mark_as_used(slot);
-
-                       break;
-               }
-    
-               id_to_check++;
-       }
-
-       return esps_in_use;
-}
-
-
-/******************************************************************* Release */
-
-static int mca_esp_release(struct Scsi_Host *host)
-{
-       struct NCR_ESP *esp = (struct NCR_ESP *)host->hostdata;
-       unsigned char tmp_byte;
-
-       esp_deallocate(esp);
-       /*
-        * Tell the 86C01 to stop sending interrupts
-        */
-
-       tmp_byte = inb(esp->eregs->io_addr - 0x0E);
-       tmp_byte &= ~0x40;
-       outb(tmp_byte, esp->eregs->io_addr - 0x0E);
-
-       free_irq(esp->irq, esp_intr);
-       free_dma(esp->dma);
-
-       mca_mark_as_unused(esp->slot);
-
-       return 0;
-}
-
-/************************************************************* DMA Functions */
-static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
-{
-       /* Ask the 53c9x.  It knows. */
-
-       return fifo_count;
-}
-
-static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-       /* 
-        * The MCA dma channels can only do up to 128K bytes at a time.
-         *  (16 bit mode)
-        */
-
-       unsigned long sz = sp->SCp.this_residual;
-       if(sz > 0x20000)
-               sz = 0x20000;
-       return sz;
-}
-
-static void dma_dump_state(struct NCR_ESP *esp)
-{
-       /*
-        * Doesn't quite match up to the other drivers, but we do what we
-        *  can.
-        */
-
-       ESPLOG(("esp%d: dma channel <%d>\n", esp->esp_id, esp->dma));
-       ESPLOG(("bytes left to dma: %d\n", mca_get_dma_residue(esp->dma)));
-}
-
-static void dma_init_read(struct NCR_ESP *esp, __u32 addr, int length)
-{
-       unsigned long flags;
-
-
-       save_flags(flags);
-       cli();
-
-       mca_disable_dma(esp->dma);
-       mca_set_dma_mode(esp->dma, MCA_DMA_MODE_XFER | MCA_DMA_MODE_16 |
-         MCA_DMA_MODE_IO);
-       mca_set_dma_addr(esp->dma, addr);
-       mca_set_dma_count(esp->dma, length / 2); /* !!! */
-       mca_enable_dma(esp->dma);
-
-       restore_flags(flags);
-}
-
-static void dma_init_write(struct NCR_ESP *esp, __u32 addr, int length)
-{
-       unsigned long flags;
-
-
-       save_flags(flags);
-       cli();
-
-       mca_disable_dma(esp->dma);
-       mca_set_dma_mode(esp->dma, MCA_DMA_MODE_XFER | MCA_DMA_MODE_WRITE |
-         MCA_DMA_MODE_16 | MCA_DMA_MODE_IO);
-       mca_set_dma_addr(esp->dma, addr);
-       mca_set_dma_count(esp->dma, length / 2); /* !!! */
-       mca_enable_dma(esp->dma);
-
-       restore_flags(flags);
-}
-
-static void dma_ints_off(struct NCR_ESP *esp)
-{
-       /*
-        * Tell the 'C01 to shut up.  All interrupts are routed through it.
-        */
-
-       outb(inb(esp->eregs->io_addr - 0x0E) & ~0x40,
-        esp->eregs->io_addr - 0x0E);
-}
-
-static void dma_ints_on(struct NCR_ESP *esp)
-{
-       /*
-        * Ok.  You can speak again.
-        */
-
-       outb(inb(esp->eregs->io_addr - 0x0E) | 0x40,
-        esp->eregs->io_addr - 0x0E);
-}
-
-static int dma_irq_p(struct NCR_ESP *esp)
-{
-       /*
-        * DaveM says that this should return a "yes" if there is an interrupt
-        *  or a DMA error occurred.  I copied the Amiga driver's semantics,
-        *  though, because it seems to work and we can't really tell if
-        *  a DMA error happened.  This gives the "yes" if the scsi chip
-        *  is sending an interrupt and no DMA activity is taking place
-        */
-
-       return (!(inb(esp->eregs->io_addr - 0x04) & 1) &&
-        !(inb(esp->eregs->io_addr - 0x04) & 2) ); 
-}
-
-static int dma_ports_p(struct NCR_ESP *esp)
-{
-       /*
-        * Check to see if interrupts are enabled on the 'C01 (in case abort
-        *  is entered multiple times, so we only do the abort once)
-        */
-
-       return (inb(esp->eregs->io_addr - 0x0E) & 0x40) ? 1:0;
-}
-
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
-{
-       if(write){
-               dma_init_write(esp, addr, count);
-       } else {
-               dma_init_read(esp, addr, count);
-       }
-}
-
-/*
- * These will not play nicely with other disk controllers that try to use the
- *  disk active LED... but what can you do?  Don't answer that.
- *
- * Stolen shamelessly from ibmmca.c -- IBM Microchannel SCSI adapter driver
- *
- */
-
-static void dma_led_on(struct NCR_ESP *esp)
-{
-       outb(inb(PS2_SYS_CTR) | 0xc0, PS2_SYS_CTR);
-}
-
-static void dma_led_off(struct NCR_ESP *esp)
-{
-       outb(inb(PS2_SYS_CTR) & 0x3f, PS2_SYS_CTR);
-}
-
-static struct scsi_host_template driver_template = {
-       .proc_name              = "mca_53c9x",
-       .name                   = "NCR 53c9x SCSI",
-       .detect                 = mca_esp_detect,
-       .slave_alloc            = esp_slave_alloc,
-       .slave_destroy          = esp_slave_destroy,
-       .release                = mca_esp_release,
-       .queuecommand           = esp_queue,
-       .eh_abort_handler       = esp_abort,
-       .eh_bus_reset_handler   = esp_reset,
-       .can_queue              = 7,
-       .sg_tablesize           = SG_ALL,
-       .cmd_per_lun            = 1,
-       .unchecked_isa_dma      = 1,
-       .use_clustering         = DISABLE_CLUSTERING
-};
-
-
-#include "scsi_module.c"
-
-/*
- * OK, here's the goods I promised.  The NCR 86C01 is an MCA interface chip 
- *  that handles enabling/diabling IRQ, dma interfacing, IO port selection
- *  and other fun stuff.  It takes up 16 addresses, and the chip it is
- *  connnected to gets the following 16.  Registers are as follows:
- *
- * Offsets 0-1 : Card ID
- *
- * Offset    2 : Mode enable register --
- *                Bit    7 : Data Word width (1 = 16, 0 = 8)
- *               Bit    6 : IRQ enable (1 = enabled)
- *                Bits 5,4 : IRQ select
- *                              0  0 : IRQ 3
- *                             0  1 : IRQ 5
- *                             1  0 : IRQ 7
- *                             1  1 : IRQ 9
- *                Bits 3-1 : Base Address
- *                           0  0  0 : <disabled>
- *                          0  0  1 : 0x0240
- *                          0  1  0 : 0x0340
- *                                  0  1  1 : 0x0400
- *                          1  0  0 : 0x0420
- *                          1  0  1 : 0x3240
- *                          1  1  0 : 0x8240
- *                          1  1  1 : 0xA240
- *               Bit    0 : Card enable (1 = enabled)
- *
- * Offset    3 : DMA control register --
- *                Bit    7 : DMA enable (1 = enabled)
- *                Bits 6,5 : Preemt Count Select (transfers to complete after
- *                            'C01 has been preempted on MCA bus)
- *                              0  0 : 0
- *                              0  1 : 1
- *                              1  0 : 3
- *                              1  1 : 7
- *  (all these wacky numbers; I'm sure there's a reason somewhere)
- *                Bit    4 : Fairness enable (1 = fair bus priority)
- *                Bits 3-0 : Arbitration level (0-15 consecutive)
- * 
- * Offset    4 : General purpose register
- *                Bits 7-3 : User definable (here, 7,6 are SCSI ID)
- *                Bits 2-0 : reserved
- *
- * Offset   10 : DMA decode register (used for IO based DMA; also can do
- *                PIO through this port)
- *
- * Offset   12 : Status
- *                Bits 7-2 : reserved
- *                Bit    1 : DMA pending (1 = pending)
- *                Bit    0 : IRQ pending (0 = pending)
- *
- * Exciting, huh?  
- *
- */                
diff --git a/drivers/scsi/oktagon_esp.c b/drivers/scsi/oktagon_esp.c
deleted file mode 100644 (file)
index 8e5eadb..0000000
+++ /dev/null
@@ -1,606 +0,0 @@
-/*
- * Oktagon_esp.c -- Driver for bsc Oktagon
- *
- * Written by Carsten Pluntke 1998
- *
- * Based on cyber_esp.c
- */
-
-
-#if defined(CONFIG_AMIGA) || defined(CONFIG_APUS)
-#define USE_BOTTOM_HALF
-#endif
-
-#include <linux/module.h>
-
-#include <linux/kernel.h>
-#include <linux/delay.h>
-#include <linux/types.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <linux/blkdev.h>
-#include <linux/proc_fs.h>
-#include <linux/stat.h>
-#include <linux/reboot.h>
-#include <asm/system.h>
-#include <asm/ptrace.h>
-#include <asm/pgtable.h>
-
-
-#include "scsi.h"
-#include <scsi/scsi_host.h>
-#include "NCR53C9x.h"
-
-#include <linux/zorro.h>
-#include <asm/irq.h>
-#include <asm/amigaints.h>
-#include <asm/amigahw.h>
-
-#ifdef USE_BOTTOM_HALF
-#include <linux/workqueue.h>
-#include <linux/interrupt.h>
-#endif
-
-/* The controller registers can be found in the Z2 config area at these
- * offsets:
- */
-#define OKTAGON_ESP_ADDR 0x03000
-#define OKTAGON_DMA_ADDR 0x01000
-
-
-static int  dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
-static int  dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
-static void dma_dump_state(struct NCR_ESP *esp);
-static void dma_init_read(struct NCR_ESP *esp, __u32 vaddress, int length);
-static void dma_init_write(struct NCR_ESP *esp, __u32 vaddress, int length);
-static void dma_ints_off(struct NCR_ESP *esp);
-static void dma_ints_on(struct NCR_ESP *esp);
-static int  dma_irq_p(struct NCR_ESP *esp);
-static void dma_led_off(struct NCR_ESP *esp);
-static void dma_led_on(struct NCR_ESP *esp);
-static int  dma_ports_p(struct NCR_ESP *esp);
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
-
-static void dma_irq_exit(struct NCR_ESP *esp);
-static void dma_invalidate(struct NCR_ESP *esp);
-
-static void dma_mmu_get_scsi_one(struct NCR_ESP *,Scsi_Cmnd *);
-static void dma_mmu_get_scsi_sgl(struct NCR_ESP *,Scsi_Cmnd *);
-static void dma_mmu_release_scsi_one(struct NCR_ESP *,Scsi_Cmnd *);
-static void dma_mmu_release_scsi_sgl(struct NCR_ESP *,Scsi_Cmnd *);
-static void dma_advance_sg(Scsi_Cmnd *);
-static int  oktagon_notify_reboot(struct notifier_block *this, unsigned long code, void *x);
-
-#ifdef USE_BOTTOM_HALF
-static void dma_commit(struct work_struct *unused);
-
-long oktag_to_io(long *paddr, long *addr, long len);
-long oktag_from_io(long *addr, long *paddr, long len);
-
-static DECLARE_WORK(tq_fake_dma, dma_commit);
-
-#define DMA_MAXTRANSFER 0x8000
-
-#else
-
-/*
- * No bottom half. Use transfer directly from IRQ. Find a narrow path
- * between too much IRQ overhead and clogging the IRQ for too long.
- */
-
-#define DMA_MAXTRANSFER 0x1000
-
-#endif
-
-static struct notifier_block oktagon_notifier = { 
-       oktagon_notify_reboot,
-       NULL,
-       0
-};
-
-static long *paddress;
-static long *address;
-static long len;
-static long dma_on;
-static int direction;
-static struct NCR_ESP *current_esp;
-
-
-static volatile unsigned char cmd_buffer[16];
-                               /* This is where all commands are put
-                                * before they are trasfered to the ESP chip
-                                * via PIO.
-                                */
-
-/***************************************************************** Detection */
-int oktagon_esp_detect(struct scsi_host_template *tpnt)
-{
-       struct NCR_ESP *esp;
-       struct zorro_dev *z = NULL;
-       unsigned long address;
-       struct ESP_regs *eregs;
-
-       while ((z = zorro_find_device(ZORRO_PROD_BSC_OKTAGON_2008, z))) {
-           unsigned long board = z->resource.start;
-           if (request_mem_region(board+OKTAGON_ESP_ADDR,
-                                  sizeof(struct ESP_regs), "NCR53C9x")) {
-               /*
-                * It is a SCSI controller.
-                * Hardwire Host adapter to SCSI ID 7
-                */
-               
-               address = (unsigned long)ZTWO_VADDR(board);
-               eregs = (struct ESP_regs *)(address + OKTAGON_ESP_ADDR);
-
-               /* This line was 5 lines lower */
-               esp = esp_allocate(tpnt, (void *)board + OKTAGON_ESP_ADDR, 0);
-
-               /* we have to shift the registers only one bit for oktagon */
-               esp->shift = 1;
-
-               esp_write(eregs->esp_cfg1, (ESP_CONFIG1_PENABLE | 7));
-               udelay(5);
-               if (esp_read(eregs->esp_cfg1) != (ESP_CONFIG1_PENABLE | 7))
-                       return 0; /* Bail out if address did not hold data */
-
-               /* Do command transfer with programmed I/O */
-               esp->do_pio_cmds = 1;
-
-               /* Required functions */
-               esp->dma_bytes_sent = &dma_bytes_sent;
-               esp->dma_can_transfer = &dma_can_transfer;
-               esp->dma_dump_state = &dma_dump_state;
-               esp->dma_init_read = &dma_init_read;
-               esp->dma_init_write = &dma_init_write;
-               esp->dma_ints_off = &dma_ints_off;
-               esp->dma_ints_on = &dma_ints_on;
-               esp->dma_irq_p = &dma_irq_p;
-               esp->dma_ports_p = &dma_ports_p;
-               esp->dma_setup = &dma_setup;
-
-               /* Optional functions */
-               esp->dma_barrier = 0;
-               esp->dma_drain = 0;
-               esp->dma_invalidate = &dma_invalidate;
-               esp->dma_irq_entry = 0;
-               esp->dma_irq_exit = &dma_irq_exit;
-               esp->dma_led_on = &dma_led_on;
-               esp->dma_led_off = &dma_led_off;
-               esp->dma_poll = 0;
-               esp->dma_reset = 0;
-
-               esp->dma_mmu_get_scsi_one = &dma_mmu_get_scsi_one;
-               esp->dma_mmu_get_scsi_sgl = &dma_mmu_get_scsi_sgl;
-               esp->dma_mmu_release_scsi_one = &dma_mmu_release_scsi_one;
-               esp->dma_mmu_release_scsi_sgl = &dma_mmu_release_scsi_sgl;
-               esp->dma_advance_sg = &dma_advance_sg;
-
-               /* SCSI chip speed */
-               /* Looking at the quartz of the SCSI board... */
-               esp->cfreq = 25000000;
-
-               /* The DMA registers on the CyberStorm are mapped
-                * relative to the device (i.e. in the same Zorro
-                * I/O block).
-                */
-               esp->dregs = (void *)(address + OKTAGON_DMA_ADDR);
-
-               paddress = (long *) esp->dregs;
-
-               /* ESP register base */
-               esp->eregs = eregs;
-               
-               /* Set the command buffer */
-               esp->esp_command = (volatile unsigned char*) cmd_buffer;
-
-               /* Yes, the virtual address. See below. */
-               esp->esp_command_dvma = (__u32) cmd_buffer;
-
-               esp->irq = IRQ_AMIGA_PORTS;
-               request_irq(IRQ_AMIGA_PORTS, esp_intr, IRQF_SHARED,
-                           "BSC Oktagon SCSI", esp->ehost);
-
-               /* Figure out our scsi ID on the bus */
-               esp->scsi_id = 7;
-               
-               /* We don't have a differential SCSI-bus. */
-               esp->diff = 0;
-
-               esp_initialize(esp);
-
-               printk("ESP_Oktagon Driver 1.1"
-#ifdef USE_BOTTOM_HALF
-                      " [BOTTOM_HALF]"
-#else
-                      " [IRQ]"
-#endif
-                      " registered.\n");
-               printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps,esps_in_use);
-               esps_running = esps_in_use;
-               current_esp = esp;
-               register_reboot_notifier(&oktagon_notifier);
-               return esps_in_use;
-           }
-       }
-       return 0;
-}
-
-
-/*
- * On certain configurations the SCSI equipment gets confused on reboot,
- * so we have to reset it then.
- */
-
-static int
-oktagon_notify_reboot(struct notifier_block *this, unsigned long code, void *x)
-{
-  struct NCR_ESP *esp;
-  
-  if((code == SYS_DOWN || code == SYS_HALT) && (esp = current_esp))
-   {
-    esp_bootup_reset(esp,esp->eregs);
-    udelay(500); /* Settle time. Maybe unnecessary. */
-   }
-  return NOTIFY_DONE;
-}
-    
-
-       
-#ifdef USE_BOTTOM_HALF
-
-
-/*
- * The bsc Oktagon controller has no real DMA, so we have to do the 'DMA
- * transfer' in the interrupt (Yikes!) or use a bottom half to not to clutter
- * IRQ's for longer-than-good.
- *
- * FIXME
- * BIG PROBLEM: 'len' is usually the buffer length, not the expected length
- * of the data. So DMA may finish prematurely, further reads lead to
- * 'machine check' on APUS systems (don't know about m68k systems, AmigaOS
- * deliberately ignores the bus faults) and a normal copy-loop can't
- * be exited prematurely just at the right moment by the dma_invalidate IRQ.
- * So do it the hard way, write an own copier in assembler and
- * catch the exception.
- *                                     -- Carsten
- */
-static void dma_commit(struct work_struct *unused)
-{
-    long wait,len2,pos;
-    struct NCR_ESP *esp;
-
-    ESPDATA(("Transfer: %ld bytes, Address 0x%08lX, Direction: %d\n",
-         len,(long) address,direction));
-    dma_ints_off(current_esp);
-
-    pos = 0;
-    wait = 1;
-    if(direction) /* write? (memory to device) */
-     {
-      while(len > 0)
-       {
-        len2 = oktag_to_io(paddress, address+pos, len);
-       if(!len2)
-        {
-         if(wait > 1000)
-          {
-           printk("Expedited DMA exit (writing) %ld\n",len);
-           break;
-          }
-         mdelay(wait);
-         wait *= 2;
-        }
-       pos += len2;
-       len -= len2*sizeof(long);
-       }
-     } else {
-      while(len > 0)
-       {
-        len2 = oktag_from_io(address+pos, paddress, len);
-       if(!len2)
-        {
-         if(wait > 1000)
-          {
-           printk("Expedited DMA exit (reading) %ld\n",len);
-           break;
-          }
-         mdelay(wait);
-         wait *= 2;
-        }
-       pos += len2;
-       len -= len2*sizeof(long);
-       }
-     }
-
-    /* to make esp->shift work */
-    esp=current_esp;
-
-#if 0
-    len2 = (esp_read(current_esp->eregs->esp_tclow) & 0xff) |
-           ((esp_read(current_esp->eregs->esp_tcmed) & 0xff) << 8);
-
-    /*
-     * Uh uh. If you see this, len and transfer count registers were out of
-     * sync. That means really serious trouble.
-     */
-
-    if(len2)
-      printk("Eeeek!! Transfer count still %ld!\n",len2);
-#endif
-
-    /*
-     * Normally we just need to exit and wait for the interrupt to come.
-     * But at least one device (my Microtek ScanMaker 630) regularly mis-
-     * calculates the bytes it should send which is really ugly because
-     * it locks up the SCSI bus if not accounted for.
-     */
-
-    if(!(esp_read(current_esp->eregs->esp_status) & ESP_STAT_INTR))
-     {
-      long len = 100;
-      long trash[10];
-
-      /*
-       * Interrupt bit was not set. Either the device is just plain lazy
-       * so we give it a 10 ms chance or...
-       */
-      while(len-- && (!(esp_read(current_esp->eregs->esp_status) & ESP_STAT_INTR)))
-        udelay(100);
-
-
-      if(!(esp_read(current_esp->eregs->esp_status) & ESP_STAT_INTR))
-       {
-        /*
-        * So we think that the transfer count is out of sync. Since we
-        * have all we want we are happy and can ditch the trash.
-        */
-        
-        len = DMA_MAXTRANSFER;
-
-        while(len-- && (!(esp_read(current_esp->eregs->esp_status) & ESP_STAT_INTR)))
-          oktag_from_io(trash,paddress,2);
-
-        if(!(esp_read(current_esp->eregs->esp_status) & ESP_STAT_INTR))
-         {
-          /*
-           * Things really have gone wrong. If we leave the system in that
-           * state, the SCSI bus is locked forever. I hope that this will
-           * turn the system in a more or less running state.
-           */
-          printk("Device is bolixed, trying bus reset...\n");
-         esp_bootup_reset(current_esp,current_esp->eregs);
-         }
-       }
-     }
-
-    ESPDATA(("Transfer_finale: do_data_finale should come\n"));
-
-    len = 0;
-    dma_on = 0;
-    dma_ints_on(current_esp);
-}
-
-#endif
-
-/************************************************************* DMA Functions */
-static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
-{
-       /* Since the CyberStorm DMA is fully dedicated to the ESP chip,
-        * the number of bytes sent (to the ESP chip) equals the number
-        * of bytes in the FIFO - there is no buffering in the DMA controller.
-        * XXXX Do I read this right? It is from host to ESP, right?
-        */
-       return fifo_count;
-}
-
-static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-       unsigned long sz = sp->SCp.this_residual;
-       if(sz > DMA_MAXTRANSFER)
-               sz = DMA_MAXTRANSFER;
-       return sz;
-}
-
-static void dma_dump_state(struct NCR_ESP *esp)
-{
-}
-
-/*
- * What the f$@& is this?
- *
- * Some SCSI devices (like my Microtek ScanMaker 630 scanner) want to transfer
- * more data than requested. How much? Dunno. So ditch the bogus data into
- * the sink, hoping the device will advance to the next phase sooner or later.
- *
- *                         -- Carsten
- */
-
-static long oktag_eva_buffer[16]; /* The data sink */
-
-static void oktag_check_dma(void)
-{
-  struct NCR_ESP *esp;
-
-  esp=current_esp;
-  if(!len)
-   {
-    address = oktag_eva_buffer;
-    len = 2;
-    /* esp_do_data sets them to zero like len */
-    esp_write(current_esp->eregs->esp_tclow,2);
-    esp_write(current_esp->eregs->esp_tcmed,0);
-   }
-}
-
-static void dma_init_read(struct NCR_ESP *esp, __u32 vaddress, int length)
-{
-       /* Zorro is noncached, everything else done using processor. */
-       /* cache_clear(addr, length); */
-       
-       if(dma_on)
-         panic("dma_init_read while dma process is initialized/running!\n");
-       direction = 0;
-       address = (long *) vaddress;
-       current_esp = esp;
-       len = length;
-       oktag_check_dma();
-        dma_on = 1;
-}
-
-static void dma_init_write(struct NCR_ESP *esp, __u32 vaddress, int length)
-{
-       /* cache_push(addr, length); */
-
-       if(dma_on)
-         panic("dma_init_write while dma process is initialized/running!\n");
-       direction = 1;
-       address = (long *) vaddress;
-       current_esp = esp;
-       len = length;
-       oktag_check_dma();
-       dma_on = 1;
-}
-
-static void dma_ints_off(struct NCR_ESP *esp)
-{
-       disable_irq(esp->irq);
-}
-
-static void dma_ints_on(struct NCR_ESP *esp)
-{
-       enable_irq(esp->irq);
-}
-
-static int dma_irq_p(struct NCR_ESP *esp)
-{
-       /* It's important to check the DMA IRQ bit in the correct way! */
-       return (esp_read(esp->eregs->esp_status) & ESP_STAT_INTR);
-}
-
-static void dma_led_off(struct NCR_ESP *esp)
-{
-}
-
-static void dma_led_on(struct NCR_ESP *esp)
-{
-}
-
-static int dma_ports_p(struct NCR_ESP *esp)
-{
-       return ((amiga_custom.intenar) & IF_PORTS);
-}
-
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
-{
-       /* On the Sparc, DMA_ST_WRITE means "move data from device to memory"
-        * so when (write) is true, it actually means READ!
-        */
-       if(write){
-               dma_init_read(esp, addr, count);
-       } else {
-               dma_init_write(esp, addr, count);
-       }
-}
-
-/*
- * IRQ entry when DMA transfer is ready to be started
- */
-
-static void dma_irq_exit(struct NCR_ESP *esp)
-{
-#ifdef USE_BOTTOM_HALF
-       if(dma_on)
-        {
-         schedule_work(&tq_fake_dma);
-        }
-#else
-       while(len && !dma_irq_p(esp))
-        {
-         if(direction)
-           *paddress = *address++;
-          else
-           *address++ = *paddress;
-         len -= (sizeof(long));
-        }
-       len = 0;
-        dma_on = 0;
-#endif
-}
-
-/*
- * IRQ entry when DMA has just finished
- */
-
-static void dma_invalidate(struct NCR_ESP *esp)
-{
-}
-
-/*
- * Since the processor does the data transfer we have to use the custom
- * mmu interface to pass the virtual address, not the physical.
- */
-
-void dma_mmu_get_scsi_one(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-        sp->SCp.ptr =
-                sp->request_buffer;
-}
-
-void dma_mmu_get_scsi_sgl(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-        sp->SCp.ptr = sg_virt(sp->SCp.buffer);
-}
-
-void dma_mmu_release_scsi_one(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-}
-
-void dma_mmu_release_scsi_sgl(struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-}
-
-void dma_advance_sg(Scsi_Cmnd *sp)
-{
-       sp->SCp.ptr = sg_virt(sp->SCp.buffer);
-}
-
-
-#define HOSTS_C
-
-int oktagon_esp_release(struct Scsi_Host *instance)
-{
-#ifdef MODULE
-       unsigned long address = (unsigned long)((struct NCR_ESP *)instance->hostdata)->edev;
-       esp_release();
-       release_mem_region(address, sizeof(struct ESP_regs));
-       free_irq(IRQ_AMIGA_PORTS, esp_intr);
-       unregister_reboot_notifier(&oktagon_notifier);
-#endif
-       return 1;
-}
-
-
-static struct scsi_host_template driver_template = {
-       .proc_name              = "esp-oktagon",
-       .proc_info              = &esp_proc_info,
-       .name                   = "BSC Oktagon SCSI",
-       .detect                 = oktagon_esp_detect,
-       .slave_alloc            = esp_slave_alloc,
-       .slave_destroy          = esp_slave_destroy,
-       .release                = oktagon_esp_release,
-       .queuecommand           = esp_queue,
-       .eh_abort_handler       = esp_abort,
-       .eh_bus_reset_handler   = esp_reset,
-       .can_queue              = 7,
-       .this_id                = 7,
-       .sg_tablesize           = SG_ALL,
-       .cmd_per_lun            = 1,
-       .use_clustering         = ENABLE_CLUSTERING
-};
-
-
-#include "scsi_module.c"
-
-MODULE_LICENSE("GPL");
diff --git a/drivers/scsi/oktagon_io.S b/drivers/scsi/oktagon_io.S
deleted file mode 100644 (file)
index 8a7340b..0000000
+++ /dev/null
@@ -1,194 +0,0 @@
-/* -*- mode: asm -*-
- * Due to problems while transferring data I've put these routines as assembly
- * code.
- * Since I'm no PPC assembler guru, the code is just the assembler version of
-
-int oktag_to_io(long *paddr,long *addr,long len)
-{
-  long *addr2 = addr;
-  for(len=(len+sizeof(long)-1)/sizeof(long);len--;)
-    *paddr = *addr2++;
-  return addr2 - addr;
-}
-
-int oktag_from_io(long *addr,long *paddr,long len)
-{
-  long *addr2 = addr;
-  for(len=(len+sizeof(long)-1)/sizeof(long);len--;)
-    *addr2++ = *paddr;
-  return addr2 - addr;
-}
-
- * assembled using gcc -O2 -S, with two exception catch points where data
- * is moved to/from the IO register.
- */
-
-
-#ifdef CONFIG_APUS
-
-       .file   "oktagon_io.c"
-
-gcc2_compiled.:
-/*
-       .section ".text"
-*/
-       .align 2
-       .globl oktag_to_io
-       .type    oktag_to_io,@function
-oktag_to_io:
-       addi 5,5,3
-       srwi 5,5,2
-       cmpwi 1,5,0
-       mr 9,3
-       mr 3,4
-       addi 5,5,-1
-       bc 12,6,.L3
-.L5:
-       cmpwi 1,5,0
-       lwz 0,0(3)
-       addi 3,3,4
-       addi 5,5,-1
-exp1:  stw 0,0(9)
-       bc 4,6,.L5
-.L3:
-ret1:  subf 3,4,3
-       srawi 3,3,2
-       blr
-.Lfe1:
-       .size    oktag_to_io,.Lfe1-oktag_to_io
-       .align 2
-       .globl oktag_from_io
-       .type    oktag_from_io,@function
-oktag_from_io:
-       addi 5,5,3
-       srwi 5,5,2
-       cmpwi 1,5,0
-       mr 9,3
-       addi 5,5,-1
-       bc 12,6,.L9
-.L11:
-       cmpwi 1,5,0
-exp2:  lwz 0,0(4)
-       addi 5,5,-1
-       stw 0,0(3)
-       addi 3,3,4
-       bc 4,6,.L11
-.L9:
-ret2:  subf 3,9,3
-       srawi 3,3,2
-       blr
-.Lfe2:
-       .size    oktag_from_io,.Lfe2-oktag_from_io
-       .ident  "GCC: (GNU) egcs-2.90.29 980515 (egcs-1.0.3 release)"
-
-/*
- * Exception table.
- * Second longword shows where to jump when an exception at the addr the first
- * longword is pointing to is caught.
- */
-
-.section __ex_table,"a"
-       .align  2
-oktagon_except:
-       .long   exp1,ret1
-       .long   exp2,ret2
-
-#else
-
-/*
-The code which follows is for 680x0 based assembler and is meant for
-Linux/m68k. It was created by cross compiling the code using the
-instructions given above. I then added the four labels used in the
-exception handler table at the bottom of this file.
-- Kevin <kcozens@interlog.com>
-*/
-
-#ifdef CONFIG_AMIGA
-
-       .file   "oktagon_io.c"
-       .version        "01.01"
-gcc2_compiled.:
-.text
-       .align  2
-.globl oktag_to_io
-       .type    oktag_to_io,@function
-oktag_to_io:
-       link.w %a6,#0
-       move.l %d2,-(%sp)
-       move.l 8(%a6),%a1
-       move.l 12(%a6),%d1
-       move.l %d1,%a0
-       move.l 16(%a6),%d0
-       addq.l #3,%d0
-       lsr.l #2,%d0
-       subq.l #1,%d0
-       moveq.l #-1,%d2
-       cmp.l %d0,%d2
-       jbeq .L3
-.L5:
-exp1:
-       move.l (%a0)+,(%a1)
-       dbra %d0,.L5
-       clr.w %d0
-       subq.l #1,%d0
-       jbcc .L5
-.L3:
-ret1:
-       move.l %a0,%d0
-       sub.l %d1,%d0
-       asr.l #2,%d0
-       move.l -4(%a6),%d2
-       unlk %a6
-       rts
-
-.Lfe1:
-       .size    oktag_to_io,.Lfe1-oktag_to_io
-       .align  2
-.globl oktag_from_io
-       .type    oktag_from_io,@function
-oktag_from_io:
-       link.w %a6,#0
-       move.l %d2,-(%sp)
-       move.l 8(%a6),%d1
-       move.l 12(%a6),%a1
-       move.l %d1,%a0
-       move.l 16(%a6),%d0
-       addq.l #3,%d0
-       lsr.l #2,%d0
-       subq.l #1,%d0
-       moveq.l #-1,%d2
-       cmp.l %d0,%d2
-       jbeq .L9
-.L11:
-exp2:
-       move.l (%a1),(%a0)+
-       dbra %d0,.L11
-       clr.w %d0
-       subq.l #1,%d0
-       jbcc .L11
-.L9:
-ret2:
-       move.l %a0,%d0
-       sub.l %d1,%d0
-       asr.l #2,%d0
-       move.l -4(%a6),%d2
-       unlk %a6
-       rts
-.Lfe2:
-       .size    oktag_from_io,.Lfe2-oktag_from_io
-       .ident  "GCC: (GNU) 2.7.2.1"
-
-/*
- * Exception table.
- * Second longword shows where to jump when an exception at the addr the first
- * longword is pointing to is caught.
- */
-
-.section __ex_table,"a"
-       .align  2
-oktagon_except:
-       .long   exp1,ret1
-       .long   exp2,ret2
-
-#endif
-#endif
index 17b4a7c4618cd0e3a9667d8f2fb60da8c59e17bd..0cd614a0fa73d98eb354aee000c1c4f1909de050 100644 (file)
@@ -35,7 +35,7 @@
 
 #define BOUNCE_SIZE                    (64*1024)
 
-#define PS3ROM_MAX_SECTORS             (BOUNCE_SIZE / CD_FRAMESIZE)
+#define PS3ROM_MAX_SECTORS             (BOUNCE_SIZE >> 9)
 
 
 struct ps3rom_private {
index adf97320574bacd7b53f63a0be445805e379d8be..4894dc886b6286fb446da3dbaa173269c0dd7a22 100644 (file)
@@ -428,6 +428,19 @@ qla2x00_sysfs_read_sfp(struct kobject *kobj,
        if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
                return 0;
 
+       if (ha->sfp_data)
+               goto do_read;
+
+       ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
+           &ha->sfp_data_dma);
+       if (!ha->sfp_data) {
+               qla_printk(KERN_WARNING, ha,
+                   "Unable to allocate memory for SFP read-data.\n");
+               return 0;
+       }
+
+do_read:
+       memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
        addr = 0xa0;
        for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
            iter++, offset += SFP_BLOCK_SIZE) {
@@ -835,7 +848,7 @@ qla2x00_get_host_port_id(struct Scsi_Host *shost)
 static void
 qla2x00_get_host_speed(struct Scsi_Host *shost)
 {
-       scsi_qla_host_t *ha = shost_priv(shost);
+       scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
        uint32_t speed = 0;
 
        switch (ha->link_data_rate) {
@@ -848,6 +861,9 @@ qla2x00_get_host_speed(struct Scsi_Host *shost)
        case PORT_SPEED_4GB:
                speed = 4;
                break;
+       case PORT_SPEED_8GB:
+               speed = 8;
+               break;
        }
        fc_host_speed(shost) = speed;
 }
@@ -855,7 +871,7 @@ qla2x00_get_host_speed(struct Scsi_Host *shost)
 static void
 qla2x00_get_host_port_type(struct Scsi_Host *shost)
 {
-       scsi_qla_host_t *ha = shost_priv(shost);
+       scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
        uint32_t port_type = FC_PORTTYPE_UNKNOWN;
 
        switch (ha->current_topology) {
@@ -965,7 +981,7 @@ qla2x00_issue_lip(struct Scsi_Host *shost)
 static struct fc_host_statistics *
 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
 {
-       scsi_qla_host_t *ha = shost_priv(shost);
+       scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
        int rval;
        struct link_statistics *stats;
        dma_addr_t stats_dma;
@@ -1049,7 +1065,7 @@ qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
 static void
 qla2x00_get_host_port_state(struct Scsi_Host *shost)
 {
-       scsi_qla_host_t *ha = shost_priv(shost);
+       scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
 
        if (!ha->flags.online)
                fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
index b72c7f170854a9b8f93e9a0ceb7929684e770633..3750319f4968749d99a821fd1294610723c078e3 100644 (file)
@@ -2041,8 +2041,6 @@ typedef struct vport_params {
 #define VP_RET_CODE_NO_MEM             5
 #define VP_RET_CODE_NOT_FOUND          6
 
-#define to_qla_parent(x) (((x)->parent) ? (x)->parent : (x))
-
 /*
  * ISP operations
  */
index ba35fc26ce6b8d0bf04f564d6de92137e35efa59..193f688ec3d788770a1596ddd97ad610f812f00b 100644 (file)
@@ -66,6 +66,7 @@ extern int ql2xqfullrampup;
 extern int num_hosts;
 
 extern int qla2x00_loop_reset(scsi_qla_host_t *);
+extern void qla2x00_abort_all_cmds(scsi_qla_host_t *, int);
 
 /*
  * Global Functions in qla_mid.c source file.
index d0633ca894be7cfd06f622b78de4f2b2792486e4..d5c7853e7ebab34e0b621d98dbb6f36de823ca06 100644 (file)
@@ -925,6 +925,16 @@ qla2x00_setup_chip(scsi_qla_host_t *ha)
 {
        int rval;
        uint32_t srisc_address = 0;
+       struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
+       unsigned long flags;
+
+       if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
+               /* Disable SRAM, Instruction RAM and GP RAM parity.  */
+               spin_lock_irqsave(&ha->hardware_lock, flags);
+               WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
+               RD_REG_WORD(&reg->hccr);
+               spin_unlock_irqrestore(&ha->hardware_lock, flags);
+       }
 
        /* Load firmware sequences */
        rval = ha->isp_ops->load_risc(ha, &srisc_address);
@@ -968,6 +978,19 @@ qla2x00_setup_chip(scsi_qla_host_t *ha)
                }
        }
 
+       if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
+               /* Enable proper parity. */
+               spin_lock_irqsave(&ha->hardware_lock, flags);
+               if (IS_QLA2300(ha))
+                       /* SRAM parity */
+                       WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
+               else
+                       /* SRAM, Instruction RAM and GP RAM parity */
+                       WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
+               RD_REG_WORD(&reg->hccr);
+               spin_unlock_irqrestore(&ha->hardware_lock, flags);
+       }
+
        if (rval) {
                DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
                    ha->host_no));
@@ -3213,9 +3236,6 @@ int
 qla2x00_abort_isp(scsi_qla_host_t *ha)
 {
        int rval;
-       unsigned long flags = 0;
-       uint16_t       cnt;
-       srb_t          *sp;
        uint8_t        status = 0;
 
        if (ha->flags.online) {
@@ -3236,19 +3256,8 @@ qla2x00_abort_isp(scsi_qla_host_t *ha)
                                    LOOP_DOWN_TIME);
                }
 
-               spin_lock_irqsave(&ha->hardware_lock, flags);
                /* Requeue all commands in outstanding command list. */
-               for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
-                       sp = ha->outstanding_cmds[cnt];
-                       if (sp) {
-                               ha->outstanding_cmds[cnt] = NULL;
-                               sp->flags = 0;
-                               sp->cmd->result = DID_RESET << 16;
-                               sp->cmd->host_scribble = (unsigned char *)NULL;
-                               qla2x00_sp_compl(ha, sp);
-                       }
-               }
-               spin_unlock_irqrestore(&ha->hardware_lock, flags);
+               qla2x00_abort_all_cmds(ha, DID_RESET << 16);
 
                ha->isp_ops->get_flash_version(ha, ha->request_ring);
 
@@ -3273,6 +3282,7 @@ qla2x00_abort_isp(scsi_qla_host_t *ha)
                        clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
 
                        if (ha->eft) {
+                               memset(ha->eft, 0, EFT_SIZE);
                                rval = qla2x00_enable_eft_trace(ha,
                                    ha->eft_dma, EFT_NUM_BUFFERS);
                                if (rval) {
@@ -3357,60 +3367,15 @@ static int
 qla2x00_restart_isp(scsi_qla_host_t *ha)
 {
        uint8_t         status = 0;
-       struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
-       unsigned long   flags = 0;
        uint32_t wait_time;
 
        /* If firmware needs to be loaded */
        if (qla2x00_isp_firmware(ha)) {
                ha->flags.online = 0;
-               if (!(status = ha->isp_ops->chip_diag(ha))) {
-                       if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
-                               status = qla2x00_setup_chip(ha);
-                               goto done;
-                       }
-
-                       spin_lock_irqsave(&ha->hardware_lock, flags);
-
-                       if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha) &&
-                           !IS_QLA25XX(ha)) {
-                               /*
-                                * Disable SRAM, Instruction RAM and GP RAM
-                                * parity.
-                                */
-                               WRT_REG_WORD(&reg->hccr,
-                                   (HCCR_ENABLE_PARITY + 0x0));
-                               RD_REG_WORD(&reg->hccr);
-                       }
-
-                       spin_unlock_irqrestore(&ha->hardware_lock, flags);
-
+               if (!(status = ha->isp_ops->chip_diag(ha)))
                        status = qla2x00_setup_chip(ha);
-
-                       spin_lock_irqsave(&ha->hardware_lock, flags);
-
-                       if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha) &&
-                           !IS_QLA25XX(ha)) {
-                               /* Enable proper parity */
-                               if (IS_QLA2300(ha))
-                                       /* SRAM parity */
-                                       WRT_REG_WORD(&reg->hccr,
-                                           (HCCR_ENABLE_PARITY + 0x1));
-                               else
-                                       /*
-                                        * SRAM, Instruction RAM and GP RAM
-                                        * parity.
-                                        */
-                                       WRT_REG_WORD(&reg->hccr,
-                                           (HCCR_ENABLE_PARITY + 0x7));
-                               RD_REG_WORD(&reg->hccr);
-                       }
-
-                       spin_unlock_irqrestore(&ha->hardware_lock, flags);
-               }
        }
 
- done:
        if (!status && !(status = qla2x00_init_rings(ha))) {
                clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
                if (!(status = qla2x00_fw_ready(ha))) {
index 8e3b04464cff26903b69a87a164ec34f58176ac2..5d1a3f7c408f3193a1d0cf4b78d3e6356354b892 100644 (file)
@@ -119,6 +119,13 @@ static __inline__ void qla2x00_check_fabric_devices(scsi_qla_host_t *ha)
        qla2x00_get_firmware_state(ha, &fw_state);
 }
 
+static __inline__ scsi_qla_host_t * to_qla_parent(scsi_qla_host_t *);
+static __inline__ scsi_qla_host_t *
+to_qla_parent(scsi_qla_host_t *ha)
+{
+       return ha->parent ? ha->parent : ha;
+}
+
 /**
  * qla2x00_issue_marker() - Issue a Marker IOCB if necessary.
  * @ha: HA context
index 642a0c3f09c6a6a11fb9d99d884b1334d64aa651..14e6f22944b71886be2ba17094a406e2f49b2f7c 100644 (file)
@@ -1815,6 +1815,8 @@ int
 qla2x00_request_irqs(scsi_qla_host_t *ha)
 {
        int ret;
+       device_reg_t __iomem *reg = ha->iobase;
+       unsigned long flags;
 
        /* If possible, enable MSI-X. */
        if (!IS_QLA2432(ha) && !IS_QLA2532(ha))
@@ -1846,7 +1848,7 @@ qla2x00_request_irqs(scsi_qla_host_t *ha)
                DEBUG2(qla_printk(KERN_INFO, ha,
                    "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
                    ha->fw_attributes));
-               return ret;
+               goto clear_risc_ints;
        }
        qla_printk(KERN_WARNING, ha,
            "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
@@ -1864,15 +1866,30 @@ skip_msi:
 
        ret = request_irq(ha->pdev->irq, ha->isp_ops->intr_handler,
            IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
-       if (!ret) {
-               ha->flags.inta_enabled = 1;
-               ha->host->irq = ha->pdev->irq;
-       } else {
+       if (ret) {
                qla_printk(KERN_WARNING, ha,
                    "Failed to reserve interrupt %d already in use.\n",
                    ha->pdev->irq);
+               goto fail;
+       }
+       ha->flags.inta_enabled = 1;
+       ha->host->irq = ha->pdev->irq;
+clear_risc_ints:
+
+       ha->isp_ops->disable_intrs(ha);
+       spin_lock_irqsave(&ha->hardware_lock, flags);
+       if (IS_FWI2_CAPABLE(ha)) {
+               WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
+               WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
+       } else {
+               WRT_REG_WORD(&reg->isp.semaphore, 0);
+               WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
+               WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
        }
+       spin_unlock_irqrestore(&ha->hardware_lock, flags);
+       ha->isp_ops->enable_intrs(ha);
 
+fail:
        return ret;
 }
 
index 0c10c0b0fb732602e5f0548be2e7be23a3ad1615..99d29fff836d631bc37686b6c45bee7972dcb4e4 100644 (file)
@@ -980,7 +980,7 @@ qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
        DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
            ha->host_no));
 
-       if (ha->fw_attributes & BIT_2)
+       if (ha->flags.npiv_supported)
                mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
        else
                mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
index 8f69caf8327254dc12d55bff8487d3dfadbf318b..3c1b43356adb7624c513f6186b2d6f915a7d80d9 100644 (file)
@@ -204,10 +204,8 @@ static int qla2x00_do_dpc(void *data);
 
 static void qla2x00_rst_aen(scsi_qla_host_t *);
 
-static uint8_t qla2x00_mem_alloc(scsi_qla_host_t *);
+static int qla2x00_mem_alloc(scsi_qla_host_t *);
 static void qla2x00_mem_free(scsi_qla_host_t *ha);
-static int qla2x00_allocate_sp_pool( scsi_qla_host_t *ha);
-static void qla2x00_free_sp_pool(scsi_qla_host_t *ha);
 static void qla2x00_sp_free_dma(scsi_qla_host_t *, srb_t *);
 
 /* -------------------------------------------------------------------------- */
@@ -1117,6 +1115,27 @@ qla2x00_device_reset(scsi_qla_host_t *ha, fc_port_t *reset_fcport)
        return ha->isp_ops->abort_target(reset_fcport);
 }
 
+void
+qla2x00_abort_all_cmds(scsi_qla_host_t *ha, int res)
+{
+       int cnt;
+       unsigned long flags;
+       srb_t *sp;
+
+       spin_lock_irqsave(&ha->hardware_lock, flags);
+       for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
+               sp = ha->outstanding_cmds[cnt];
+               if (sp) {
+                       ha->outstanding_cmds[cnt] = NULL;
+                       sp->flags = 0;
+                       sp->cmd->result = res;
+                       sp->cmd->host_scribble = (unsigned char *)NULL;
+                       qla2x00_sp_compl(ha, sp);
+               }
+       }
+       spin_unlock_irqrestore(&ha->hardware_lock, flags);
+}
+
 static int
 qla2xxx_slave_alloc(struct scsi_device *sdev)
 {
@@ -1557,10 +1576,8 @@ static int __devinit
 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
 {
        int     ret = -ENODEV;
-       device_reg_t __iomem *reg;
        struct Scsi_Host *host;
        scsi_qla_host_t *ha;
-       unsigned long   flags = 0;
        char pci_info[30];
        char fw_str[30];
        struct scsi_host_template *sht;
@@ -1608,6 +1625,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
        ha->parent = NULL;
        ha->bars = bars;
        ha->mem_only = mem_only;
+       spin_lock_init(&ha->hardware_lock);
 
        /* Set ISP-type information. */
        qla2x00_set_isp_flags(ha);
@@ -1621,8 +1639,6 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
            "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
            ha->iobase);
 
-       spin_lock_init(&ha->hardware_lock);
-
        ha->prev_topology = 0;
        ha->init_cb_size = sizeof(init_cb_t);
        ha->mgmt_svr_loop_id = MANAGEMENT_SERVER + ha->vp_idx;
@@ -1751,34 +1767,6 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
        DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
            ha->host_no, ha));
 
-       ha->isp_ops->disable_intrs(ha);
-
-       spin_lock_irqsave(&ha->hardware_lock, flags);
-       reg = ha->iobase;
-       if (IS_FWI2_CAPABLE(ha)) {
-               WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_HOST_INT);
-               WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_CLR_RISC_INT);
-       } else {
-               WRT_REG_WORD(&reg->isp.semaphore, 0);
-               WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_RISC_INT);
-               WRT_REG_WORD(&reg->isp.hccr, HCCR_CLR_HOST_INT);
-
-               /* Enable proper parity */
-               if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) {
-                       if (IS_QLA2300(ha))
-                               /* SRAM parity */
-                               WRT_REG_WORD(&reg->isp.hccr,
-                                   (HCCR_ENABLE_PARITY + 0x1));
-                       else
-                               /* SRAM, Instruction RAM and GP RAM parity */
-                               WRT_REG_WORD(&reg->isp.hccr,
-                                   (HCCR_ENABLE_PARITY + 0x7));
-               }
-       }
-       spin_unlock_irqrestore(&ha->hardware_lock, flags);
-
-       ha->isp_ops->enable_intrs(ha);
-
        pci_set_drvdata(pdev, ha);
 
        ha->flags.init_done = 1;
@@ -1848,10 +1836,14 @@ qla2x00_remove_one(struct pci_dev *pdev)
 static void
 qla2x00_free_device(scsi_qla_host_t *ha)
 {
+       qla2x00_abort_all_cmds(ha, DID_NO_CONNECT << 16);
+
        /* Disable timer */
        if (ha->timer_active)
                qla2x00_stop_timer(ha);
 
+       ha->flags.online = 0;
+
        /* Kill the kernel thread for this host */
        if (ha->dpc_thread) {
                struct task_struct *t = ha->dpc_thread;
@@ -1870,8 +1862,6 @@ qla2x00_free_device(scsi_qla_host_t *ha)
        if (ha->eft)
                qla2x00_disable_eft_trace(ha);
 
-       ha->flags.online = 0;
-
        /* Stop currently executing firmware. */
        qla2x00_try_to_stop_firmware(ha);
 
@@ -2010,196 +2000,109 @@ qla2x00_mark_all_devices_lost(scsi_qla_host_t *ha, int defer)
 *
 * Returns:
 *      0  = success.
-*      1  = failure.
+*      !0  = failure.
 */
-static uint8_t
+static int
 qla2x00_mem_alloc(scsi_qla_host_t *ha)
 {
        char    name[16];
-       uint8_t   status = 1;
-       int     retry= 10;
-
-       do {
-               /*
-                * This will loop only once if everything goes well, else some
-                * number of retries will be performed to get around a kernel
-                * bug where available mem is not allocated until after a
-                * little delay and a retry.
-                */
-               ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
-                   (ha->request_q_length + 1) * sizeof(request_t),
-                   &ha->request_dma, GFP_KERNEL);
-               if (ha->request_ring == NULL) {
-                       qla_printk(KERN_WARNING, ha,
-                           "Memory Allocation failed - request_ring\n");
-
-                       qla2x00_mem_free(ha);
-                       msleep(100);
-
-                       continue;
-               }
-
-               ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
-                   (ha->response_q_length + 1) * sizeof(response_t),
-                   &ha->response_dma, GFP_KERNEL);
-               if (ha->response_ring == NULL) {
-                       qla_printk(KERN_WARNING, ha,
-                           "Memory Allocation failed - response_ring\n");
-
-                       qla2x00_mem_free(ha);
-                       msleep(100);
-
-                       continue;
-               }
-
-               ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
-                   &ha->gid_list_dma, GFP_KERNEL);
-               if (ha->gid_list == NULL) {
-                       qla_printk(KERN_WARNING, ha,
-                           "Memory Allocation failed - gid_list\n");
-
-                       qla2x00_mem_free(ha);
-                       msleep(100);
-
-                       continue;
-               }
-
-               /* get consistent memory allocated for init control block */
-               ha->init_cb = dma_alloc_coherent(&ha->pdev->dev,
-                   ha->init_cb_size, &ha->init_cb_dma, GFP_KERNEL);
-               if (ha->init_cb == NULL) {
-                       qla_printk(KERN_WARNING, ha,
-                           "Memory Allocation failed - init_cb\n");
-
-                       qla2x00_mem_free(ha);
-                       msleep(100);
-
-                       continue;
-               }
-               memset(ha->init_cb, 0, ha->init_cb_size);
-
-               snprintf(name, sizeof(name), "%s_%ld", QLA2XXX_DRIVER_NAME,
-                   ha->host_no);
-               ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
-                   DMA_POOL_SIZE, 8, 0);
-               if (ha->s_dma_pool == NULL) {
-                       qla_printk(KERN_WARNING, ha,
-                           "Memory Allocation failed - s_dma_pool\n");
-
-                       qla2x00_mem_free(ha);
-                       msleep(100);
-
-                       continue;
-               }
-
-               if (qla2x00_allocate_sp_pool(ha)) {
-                       qla_printk(KERN_WARNING, ha,
-                           "Memory Allocation failed - "
-                           "qla2x00_allocate_sp_pool()\n");
-
-                       qla2x00_mem_free(ha);
-                       msleep(100);
-
-                       continue;
-               }
-
-               /* Allocate memory for SNS commands */
-               if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
-                       /* Get consistent memory allocated for SNS commands */
-                       ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
-                           sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma,
-                           GFP_KERNEL);
-                       if (ha->sns_cmd == NULL) {
-                               /* error */
-                               qla_printk(KERN_WARNING, ha,
-                                   "Memory Allocation failed - sns_cmd\n");
-
-                               qla2x00_mem_free(ha);
-                               msleep(100);
-
-                               continue;
-                       }
-                       memset(ha->sns_cmd, 0, sizeof(struct sns_cmd_pkt));
-               } else {
-                       /* Get consistent memory allocated for MS IOCB */
-                       ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
-                           &ha->ms_iocb_dma);
-                       if (ha->ms_iocb == NULL) {
-                               /* error */
-                               qla_printk(KERN_WARNING, ha,
-                                   "Memory Allocation failed - ms_iocb\n");
-
-                               qla2x00_mem_free(ha);
-                               msleep(100);
-
-                               continue;
-                       }
-                       memset(ha->ms_iocb, 0, sizeof(ms_iocb_entry_t));
-
-                       /*
-                        * Get consistent memory allocated for CT SNS
-                        * commands
-                        */
-                       ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
-                           sizeof(struct ct_sns_pkt), &ha->ct_sns_dma,
-                           GFP_KERNEL);
-                       if (ha->ct_sns == NULL) {
-                               /* error */
-                               qla_printk(KERN_WARNING, ha,
-                                   "Memory Allocation failed - ct_sns\n");
 
-                               qla2x00_mem_free(ha);
-                               msleep(100);
+       ha->request_ring = dma_alloc_coherent(&ha->pdev->dev,
+           (ha->request_q_length + 1) * sizeof(request_t), &ha->request_dma,
+           GFP_KERNEL);
+       if (!ha->request_ring)
+               goto fail;
+
+       ha->response_ring = dma_alloc_coherent(&ha->pdev->dev,
+           (ha->response_q_length + 1) * sizeof(response_t),
+           &ha->response_dma, GFP_KERNEL);
+       if (!ha->response_ring)
+               goto fail_free_request_ring;
+
+       ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
+           &ha->gid_list_dma, GFP_KERNEL);
+       if (!ha->gid_list)
+               goto fail_free_response_ring;
+
+       ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
+           &ha->init_cb_dma, GFP_KERNEL);
+       if (!ha->init_cb)
+               goto fail_free_gid_list;
+
+       snprintf(name, sizeof(name), "%s_%ld", QLA2XXX_DRIVER_NAME,
+           ha->host_no);
+       ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
+           DMA_POOL_SIZE, 8, 0);
+       if (!ha->s_dma_pool)
+               goto fail_free_init_cb;
 
-                               continue;
-                       }
-                       memset(ha->ct_sns, 0, sizeof(struct ct_sns_pkt));
-
-                       if (IS_FWI2_CAPABLE(ha)) {
-                               /*
-                                * Get consistent memory allocated for SFP
-                                * block.
-                                */
-                               ha->sfp_data = dma_pool_alloc(ha->s_dma_pool,
-                                   GFP_KERNEL, &ha->sfp_data_dma);
-                               if (ha->sfp_data == NULL) {
-                                       qla_printk(KERN_WARNING, ha,
-                                           "Memory Allocation failed - "
-                                           "sfp_data\n");
-
-                                       qla2x00_mem_free(ha);
-                                       msleep(100);
-
-                                       continue;
-                               }
-                               memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
-                       }
-               }
-
-               /* Get memory for cached NVRAM */
-               ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
-               if (ha->nvram == NULL) {
-                       /* error */
-                       qla_printk(KERN_WARNING, ha,
-                           "Memory Allocation failed - nvram cache\n");
-
-                       qla2x00_mem_free(ha);
-                       msleep(100);
-
-                       continue;
-               }
-
-               /* Done all allocations without any error. */
-               status = 0;
-
-       } while (retry-- && status != 0);
+       ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
+       if (!ha->srb_mempool)
+               goto fail_free_s_dma_pool;
+
+       /* Get memory for cached NVRAM */
+       ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
+       if (!ha->nvram)
+               goto fail_free_srb_mempool;
+
+       /* Allocate memory for SNS commands */
+       if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
+               /* Get consistent memory allocated for SNS commands */
+               ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
+                   sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
+               if (!ha->sns_cmd)
+                       goto fail_free_nvram;
+       } else {
+               /* Get consistent memory allocated for MS IOCB */
+               ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
+                   &ha->ms_iocb_dma);
+               if (!ha->ms_iocb)
+                       goto fail_free_nvram;
 
-       if (status) {
-               printk(KERN_WARNING
-                       "%s(): **** FAILED ****\n", __func__);
+               /* Get consistent memory allocated for CT SNS commands */
+               ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
+                   sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
+               if (!ha->ct_sns)
+                       goto fail_free_ms_iocb;
        }
 
-       return(status);
+       return 0;
+
+fail_free_ms_iocb:
+       dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
+       ha->ms_iocb = NULL;
+       ha->ms_iocb_dma = 0;
+fail_free_nvram:
+       kfree(ha->nvram);
+       ha->nvram = NULL;
+fail_free_srb_mempool:
+       mempool_destroy(ha->srb_mempool);
+       ha->srb_mempool = NULL;
+fail_free_s_dma_pool:
+       dma_pool_destroy(ha->s_dma_pool);
+       ha->s_dma_pool = NULL;
+fail_free_init_cb:
+       dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
+           ha->init_cb_dma);
+       ha->init_cb = NULL;
+       ha->init_cb_dma = 0;
+fail_free_gid_list:
+       dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
+           ha->gid_list_dma);
+       ha->gid_list = NULL;
+       ha->gid_list_dma = 0;
+fail_free_response_ring:
+       dma_free_coherent(&ha->pdev->dev, (ha->response_q_length + 1) *
+           sizeof(response_t), ha->response_ring, ha->response_dma);
+       ha->response_ring = NULL;
+       ha->response_dma = 0;
+fail_free_request_ring:
+       dma_free_coherent(&ha->pdev->dev, (ha->request_q_length + 1) *
+           sizeof(request_t), ha->request_ring, ha->request_dma);
+       ha->request_ring = NULL;
+       ha->request_dma = 0;
+fail:
+       return -ENOMEM;
 }
 
 /*
@@ -2215,14 +2118,8 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
        struct list_head        *fcpl, *fcptemp;
        fc_port_t       *fcport;
 
-       if (ha == NULL) {
-               /* error */
-               DEBUG2(printk("%s(): ERROR invalid ha pointer.\n", __func__));
-               return;
-       }
-
-       /* free sp pool */
-       qla2x00_free_sp_pool(ha);
+       if (ha->srb_mempool)
+               mempool_destroy(ha->srb_mempool);
 
        if (ha->fce)
                dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
@@ -2270,6 +2167,7 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
                    (ha->request_q_length + 1) * sizeof(request_t),
                    ha->request_ring, ha->request_dma);
 
+       ha->srb_mempool = NULL;
        ha->eft = NULL;
        ha->eft_dma = 0;
        ha->sns_cmd = NULL;
@@ -2308,44 +2206,6 @@ qla2x00_mem_free(scsi_qla_host_t *ha)
        kfree(ha->nvram);
 }
 
-/*
- * qla2x00_allocate_sp_pool
- *      This routine is called during initialization to allocate
- *      memory for local srb_t.
- *
- * Input:
- *      ha   = adapter block pointer.
- *
- * Context:
- *      Kernel context.
- */
-static int
-qla2x00_allocate_sp_pool(scsi_qla_host_t *ha)
-{
-       int      rval;
-
-       rval = QLA_SUCCESS;
-       ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
-       if (ha->srb_mempool == NULL) {
-               qla_printk(KERN_INFO, ha, "Unable to allocate SRB mempool.\n");
-               rval = QLA_FUNCTION_FAILED;
-       }
-       return (rval);
-}
-
-/*
- *  This routine frees all adapter allocated memory.
- *
- */
-static void
-qla2x00_free_sp_pool( scsi_qla_host_t *ha)
-{
-       if (ha->srb_mempool) {
-               mempool_destroy(ha->srb_mempool);
-               ha->srb_mempool = NULL;
-       }
-}
-
 /**************************************************************************
 * qla2x00_do_dpc
 *   This kernel thread is a task that is schedule by the interrupt handler
@@ -2367,6 +2227,9 @@ qla2x00_do_dpc(void *data)
        fc_port_t       *fcport;
        uint8_t         status;
        uint16_t        next_loopid;
+       struct scsi_qla_host *vha;
+       int             i;
+
 
        ha = (scsi_qla_host_t *)data;
 
@@ -2409,6 +2272,18 @@ qla2x00_do_dpc(void *data)
                                }
                                clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
                        }
+
+                       for_each_mapped_vp_idx(ha, i) {
+                               list_for_each_entry(vha, &ha->vp_list,
+                                   vp_list) {
+                                       if (i == vha->vp_idx) {
+                                               set_bit(ISP_ABORT_NEEDED,
+                                                   &vha->dpc_flags);
+                                               break;
+                                       }
+                               }
+                       }
+
                        DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
                            ha->host_no));
                }
@@ -3029,3 +2904,4 @@ MODULE_FIRMWARE(FW_FILE_ISP22XX);
 MODULE_FIRMWARE(FW_FILE_ISP2300);
 MODULE_FIRMWARE(FW_FILE_ISP2322);
 MODULE_FIRMWARE(FW_FILE_ISP24XX);
+MODULE_FIRMWARE(FW_FILE_ISP25XX);
index b68fb73613ed1a69ba6cb4774e0ea202bc27ab45..26822c8807eecb6e1adc0d5eed29f4de93735aaa 100644 (file)
@@ -893,6 +893,8 @@ qla2x00_flip_colors(scsi_qla_host_t *ha, uint16_t *pflags)
        }
 }
 
+#define PIO_REG(h, r) ((h)->pio_address + offsetof(struct device_reg_2xxx, r))
+
 void
 qla2x00_beacon_blink(struct scsi_qla_host *ha)
 {
@@ -902,15 +904,12 @@ qla2x00_beacon_blink(struct scsi_qla_host *ha)
        unsigned long flags;
        struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
 
-       if (ha->pio_address)
-               reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
-
        spin_lock_irqsave(&ha->hardware_lock, flags);
 
        /* Save the Original GPIOE. */
        if (ha->pio_address) {
-               gpio_enable = RD_REG_WORD_PIO(&reg->gpioe);
-               gpio_data = RD_REG_WORD_PIO(&reg->gpiod);
+               gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
+               gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
        } else {
                gpio_enable = RD_REG_WORD(&reg->gpioe);
                gpio_data = RD_REG_WORD(&reg->gpiod);
@@ -920,7 +919,7 @@ qla2x00_beacon_blink(struct scsi_qla_host *ha)
        gpio_enable |= GPIO_LED_MASK;
 
        if (ha->pio_address) {
-               WRT_REG_WORD_PIO(&reg->gpioe, gpio_enable);
+               WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
        } else {
                WRT_REG_WORD(&reg->gpioe, gpio_enable);
                RD_REG_WORD(&reg->gpioe);
@@ -936,7 +935,7 @@ qla2x00_beacon_blink(struct scsi_qla_host *ha)
 
        /* Set the modified gpio_data values */
        if (ha->pio_address) {
-               WRT_REG_WORD_PIO(&reg->gpiod, gpio_data);
+               WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
        } else {
                WRT_REG_WORD(&reg->gpiod, gpio_data);
                RD_REG_WORD(&reg->gpiod);
@@ -962,14 +961,11 @@ qla2x00_beacon_on(struct scsi_qla_host *ha)
                return QLA_FUNCTION_FAILED;
        }
 
-       if (ha->pio_address)
-               reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
-
        /* Turn off LEDs. */
        spin_lock_irqsave(&ha->hardware_lock, flags);
        if (ha->pio_address) {
-               gpio_enable = RD_REG_WORD_PIO(&reg->gpioe);
-               gpio_data = RD_REG_WORD_PIO(&reg->gpiod);
+               gpio_enable = RD_REG_WORD_PIO(PIO_REG(ha, gpioe));
+               gpio_data = RD_REG_WORD_PIO(PIO_REG(ha, gpiod));
        } else {
                gpio_enable = RD_REG_WORD(&reg->gpioe);
                gpio_data = RD_REG_WORD(&reg->gpiod);
@@ -978,7 +974,7 @@ qla2x00_beacon_on(struct scsi_qla_host *ha)
 
        /* Set the modified gpio_enable values. */
        if (ha->pio_address) {
-               WRT_REG_WORD_PIO(&reg->gpioe, gpio_enable);
+               WRT_REG_WORD_PIO(PIO_REG(ha, gpioe), gpio_enable);
        } else {
                WRT_REG_WORD(&reg->gpioe, gpio_enable);
                RD_REG_WORD(&reg->gpioe);
@@ -987,7 +983,7 @@ qla2x00_beacon_on(struct scsi_qla_host *ha)
        /* Clear out previously set LED colour. */
        gpio_data &= ~GPIO_LED_MASK;
        if (ha->pio_address) {
-               WRT_REG_WORD_PIO(&reg->gpiod, gpio_data);
+               WRT_REG_WORD_PIO(PIO_REG(ha, gpiod), gpio_data);
        } else {
                WRT_REG_WORD(&reg->gpiod, gpio_data);
                RD_REG_WORD(&reg->gpiod);
@@ -1244,13 +1240,12 @@ qla2x00_read_flash_byte(scsi_qla_host_t *ha, uint32_t addr)
        if (ha->pio_address) {
                uint16_t data2;
 
-               reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
-               WRT_REG_WORD_PIO(&reg->flash_address, (uint16_t)addr);
+               WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
                do {
-                       data = RD_REG_WORD_PIO(&reg->flash_data);
+                       data = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
                        barrier();
                        cpu_relax();
-                       data2 = RD_REG_WORD_PIO(&reg->flash_data);
+                       data2 = RD_REG_WORD_PIO(PIO_REG(ha, flash_data));
                } while (data != data2);
        } else {
                WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
@@ -1304,9 +1299,8 @@ qla2x00_write_flash_byte(scsi_qla_host_t *ha, uint32_t addr, uint8_t data)
 
        /* Always perform IO mapped accesses to the FLASH registers. */
        if (ha->pio_address) {
-               reg = (struct device_reg_2xxx __iomem *)ha->pio_address;
-               WRT_REG_WORD_PIO(&reg->flash_address, (uint16_t)addr);
-               WRT_REG_WORD_PIO(&reg->flash_data, (uint16_t)data);
+               WRT_REG_WORD_PIO(PIO_REG(ha, flash_address), (uint16_t)addr);
+               WRT_REG_WORD_PIO(PIO_REG(ha, flash_data), (uint16_t)data);
        } else {
                WRT_REG_WORD(&reg->flash_address, (uint16_t)addr);
                RD_REG_WORD(&reg->ctrl_status);         /* PCI Posting. */
index 2c2f6b4697c7196127207638133ca0870bae4a7f..c5742cc15abbbc56b1134619d09714e400d1a33d 100644 (file)
@@ -7,7 +7,7 @@
 /*
  * Driver version
  */
-#define QLA2XXX_VERSION      "8.02.00-k7"
+#define QLA2XXX_VERSION      "8.02.00-k8"
 
 #define QLA_DRIVER_MAJOR_VER   8
 #define QLA_DRIVER_MINOR_VER   2
index 49925f92555e8a3b485316d5963bc0dd8ef6d49f..10b3b9a620f357f0bcf91a39546a9b594451f149 100644 (file)
@@ -1306,6 +1306,7 @@ int qla4xxx_process_ddb_changed(struct scsi_qla_host *ha,
                atomic_set(&ddb_entry->relogin_timer, 0);
                clear_bit(DF_RELOGIN, &ddb_entry->flags);
                clear_bit(DF_NO_RELOGIN, &ddb_entry->flags);
+               iscsi_unblock_session(ddb_entry->sess);
                iscsi_session_event(ddb_entry->sess,
                                    ISCSI_KEVENT_CREATE_SESSION);
                /*
index 2e2b9fedffcc7c763b1f1d8f70df0faa38e27f61..c3c59d7630371781b25a7bf46fed47d02f37edb6 100644 (file)
@@ -63,8 +63,6 @@ static int qla4xxx_sess_get_param(struct iscsi_cls_session *sess,
                                  enum iscsi_param param, char *buf);
 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
                                  enum iscsi_host_param param, char *buf);
-static void qla4xxx_conn_stop(struct iscsi_cls_conn *conn, int flag);
-static int qla4xxx_conn_start(struct iscsi_cls_conn *conn);
 static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session);
 
 /*
@@ -91,6 +89,8 @@ static struct scsi_host_template qla4xxx_driver_template = {
        .slave_alloc            = qla4xxx_slave_alloc,
        .slave_destroy          = qla4xxx_slave_destroy,
 
+       .scan_finished          = iscsi_scan_finished,
+
        .this_id                = -1,
        .cmd_per_lun            = 3,
        .use_clustering         = ENABLE_CLUSTERING,
@@ -116,8 +116,6 @@ static struct iscsi_transport qla4xxx_iscsi_transport = {
        .get_conn_param         = qla4xxx_conn_get_param,
        .get_session_param      = qla4xxx_sess_get_param,
        .get_host_param         = qla4xxx_host_get_param,
-       .start_conn             = qla4xxx_conn_start,
-       .stop_conn              = qla4xxx_conn_stop,
        .session_recovery_timedout = qla4xxx_recovery_timedout,
 };
 
@@ -128,48 +126,19 @@ static void qla4xxx_recovery_timedout(struct iscsi_cls_session *session)
        struct ddb_entry *ddb_entry = session->dd_data;
        struct scsi_qla_host *ha = ddb_entry->ha;
 
-       DEBUG2(printk("scsi%ld: %s: index [%d] port down retry count of (%d) "
-                     "secs exhausted, marking device DEAD.\n", ha->host_no,
-                     __func__, ddb_entry->fw_ddb_index,
-                     ha->port_down_retry_count));
-
-       atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
-
-       DEBUG2(printk("scsi%ld: %s: scheduling dpc routine - dpc flags = "
-                     "0x%lx\n", ha->host_no, __func__, ha->dpc_flags));
-       queue_work(ha->dpc_thread, &ha->dpc_work);
-}
-
-static int qla4xxx_conn_start(struct iscsi_cls_conn *conn)
-{
-       struct iscsi_cls_session *session;
-       struct ddb_entry *ddb_entry;
-
-       session = iscsi_dev_to_session(conn->dev.parent);
-       ddb_entry = session->dd_data;
-
-       DEBUG2(printk("scsi%ld: %s: index [%d] starting conn\n",
-                     ddb_entry->ha->host_no, __func__,
-                     ddb_entry->fw_ddb_index));
-       iscsi_unblock_session(session);
-       return 0;
-}
-
-static void qla4xxx_conn_stop(struct iscsi_cls_conn *conn, int flag)
-{
-       struct iscsi_cls_session *session;
-       struct ddb_entry *ddb_entry;
+       if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
+               atomic_set(&ddb_entry->state, DDB_STATE_DEAD);
 
-       session = iscsi_dev_to_session(conn->dev.parent);
-       ddb_entry = session->dd_data;
+               DEBUG2(printk("scsi%ld: %s: index [%d] port down retry count "
+                             "of (%d) secs exhausted, marking device DEAD.\n",
+                             ha->host_no, __func__, ddb_entry->fw_ddb_index,
+                             ha->port_down_retry_count));
 
-       DEBUG2(printk("scsi%ld: %s: index [%d] stopping conn\n",
-                     ddb_entry->ha->host_no, __func__,
-                     ddb_entry->fw_ddb_index));
-       if (flag == STOP_CONN_RECOVER)
-               iscsi_block_session(session);
-       else
-               printk(KERN_ERR "iscsi: invalid stop flag %d\n", flag);
+               DEBUG2(printk("scsi%ld: %s: scheduling dpc routine - dpc "
+                             "flags = 0x%lx\n",
+                             ha->host_no, __func__, ha->dpc_flags));
+               queue_work(ha->dpc_thread, &ha->dpc_work);
+       }
 }
 
 static int qla4xxx_host_get_param(struct Scsi_Host *shost,
@@ -308,6 +277,9 @@ int qla4xxx_add_sess(struct ddb_entry *ddb_entry)
                DEBUG2(printk(KERN_ERR "Could not add connection.\n"));
                return -ENOMEM;
        }
+
+       /* finally ready to go */
+       iscsi_unblock_session(ddb_entry->sess);
        return 0;
 }
 
@@ -364,6 +336,7 @@ void qla4xxx_mark_device_missing(struct scsi_qla_host *ha,
        DEBUG3(printk("scsi%d:%d:%d: index [%d] marked MISSING\n",
                      ha->host_no, ddb_entry->bus, ddb_entry->target,
                      ddb_entry->fw_ddb_index));
+       iscsi_block_session(ddb_entry->sess);
        iscsi_conn_error(ddb_entry->conn, ISCSI_ERR_CONN_FAILED);
 }
 
@@ -430,9 +403,21 @@ static int qla4xxx_queuecommand(struct scsi_cmnd *cmd,
 {
        struct scsi_qla_host *ha = to_qla_host(cmd->device->host);
        struct ddb_entry *ddb_entry = cmd->device->hostdata;
+       struct iscsi_cls_session *sess = ddb_entry->sess;
        struct srb *srb;
        int rval;
 
+       if (!sess) {
+               cmd->result = DID_IMM_RETRY << 16;
+               goto qc_fail_command;
+       }
+
+       rval = iscsi_session_chkready(sess);
+       if (rval) {
+               cmd->result = rval;
+               goto qc_fail_command;
+       }
+
        if (atomic_read(&ddb_entry->state) != DDB_STATE_ONLINE) {
                if (atomic_read(&ddb_entry->state) == DDB_STATE_DEAD) {
                        cmd->result = DID_NO_CONNECT << 16;
@@ -1323,7 +1308,7 @@ static int __devinit qla4xxx_probe_adapter(struct pci_dev *pdev,
               qla4xxx_version_str, ha->pdev->device, pci_name(ha->pdev),
               ha->host_no, ha->firmware_version[0], ha->firmware_version[1],
               ha->patch_number, ha->build_number);
-
+       scsi_scan_host(host);
        return 0;
 
 remove_host:
index b35d19472caa080a7a8614a8e211216b001e8f62..fecba05b4e7783da1c22402080c7ab0c6338504b 100644 (file)
@@ -969,9 +969,10 @@ void starget_for_each_device(struct scsi_target *starget, void *data,
 EXPORT_SYMBOL(starget_for_each_device);
 
 /**
- * __starget_for_each_device  -  helper to walk all devices of a target
- *                              (UNLOCKED)
+ * __starget_for_each_device - helper to walk all devices of a target (UNLOCKED)
  * @starget:   target whose devices we want to iterate over.
+ * @data:      parameter for callback @fn()
+ * @fn:                callback function that is invoked for each device
  *
  * This traverses over each device of @starget.  It does _not_
  * take a reference on the scsi_device, so the whole loop must be
index f243fc30c908dce70387e776aa945cde84e5bc4a..135c1d0547015e3ce54edcf634f24d3f7247cefb 100644 (file)
@@ -301,7 +301,6 @@ static int scsi_req_map_sg(struct request *rq, struct scatterlist *sgl,
                page = sg_page(sg);
                off = sg->offset;
                len = sg->length;
-               data_len += len;
 
                while (len > 0 && data_len > 0) {
                        /*
index 0d7b4e79415c6b141256e7f91328c12d2a86c56d..fac7534f3ec4a88237c7e7b6ca25d48ebb7034d6 100644 (file)
 #include <scsi/scsi_transport_iscsi.h>
 #include <scsi/iscsi_if.h>
 
-#define ISCSI_SESSION_ATTRS 18
-#define ISCSI_CONN_ATTRS 11
+#define ISCSI_SESSION_ATTRS 19
+#define ISCSI_CONN_ATTRS 13
 #define ISCSI_HOST_ATTRS 4
-#define ISCSI_TRANSPORT_VERSION "2.0-867"
+#define ISCSI_TRANSPORT_VERSION "2.0-868"
 
 struct iscsi_internal {
        int daemon_pid;
@@ -127,12 +127,13 @@ static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
        memset(ihost, 0, sizeof(*ihost));
        INIT_LIST_HEAD(&ihost->sessions);
        mutex_init(&ihost->mutex);
+       atomic_set(&ihost->nr_scans, 0);
 
-       snprintf(ihost->unbind_workq_name, KOBJ_NAME_LEN, "iscsi_unbind_%d",
+       snprintf(ihost->scan_workq_name, KOBJ_NAME_LEN, "iscsi_scan_%d",
                shost->host_no);
-       ihost->unbind_workq = create_singlethread_workqueue(
-                                               ihost->unbind_workq_name);
-       if (!ihost->unbind_workq)
+       ihost->scan_workq = create_singlethread_workqueue(
+                                               ihost->scan_workq_name);
+       if (!ihost->scan_workq)
                return -ENOMEM;
        return 0;
 }
@@ -143,7 +144,7 @@ static int iscsi_remove_host(struct transport_container *tc, struct device *dev,
        struct Scsi_Host *shost = dev_to_shost(dev);
        struct iscsi_host *ihost = shost->shost_data;
 
-       destroy_workqueue(ihost->unbind_workq);
+       destroy_workqueue(ihost->scan_workq);
        return 0;
 }
 
@@ -221,6 +222,54 @@ static struct iscsi_cls_conn *iscsi_conn_lookup(uint32_t sid, uint32_t cid)
  * The following functions can be used by LLDs that allocate
  * their own scsi_hosts or by software iscsi LLDs
  */
+static struct {
+       int value;
+       char *name;
+} iscsi_session_state_names[] = {
+       { ISCSI_SESSION_LOGGED_IN,      "LOGGED_IN" },
+       { ISCSI_SESSION_FAILED,         "FAILED" },
+       { ISCSI_SESSION_FREE,           "FREE" },
+};
+
+const char *iscsi_session_state_name(int state)
+{
+       int i;
+       char *name = NULL;
+
+       for (i = 0; i < ARRAY_SIZE(iscsi_session_state_names); i++) {
+               if (iscsi_session_state_names[i].value == state) {
+                       name = iscsi_session_state_names[i].name;
+                       break;
+               }
+       }
+       return name;
+}
+
+int iscsi_session_chkready(struct iscsi_cls_session *session)
+{
+       unsigned long flags;
+       int err;
+
+       spin_lock_irqsave(&session->lock, flags);
+       switch (session->state) {
+       case ISCSI_SESSION_LOGGED_IN:
+               err = 0;
+               break;
+       case ISCSI_SESSION_FAILED:
+               err = DID_IMM_RETRY << 16;
+               break;
+       case ISCSI_SESSION_FREE:
+               err = DID_NO_CONNECT << 16;
+               break;
+       default:
+               err = DID_NO_CONNECT << 16;
+               break;
+       }
+       spin_unlock_irqrestore(&session->lock, flags);
+       return err;
+}
+EXPORT_SYMBOL_GPL(iscsi_session_chkready);
+
 static void iscsi_session_release(struct device *dev)
 {
        struct iscsi_cls_session *session = iscsi_dev_to_session(dev);
@@ -236,6 +285,25 @@ static int iscsi_is_session_dev(const struct device *dev)
        return dev->release == iscsi_session_release;
 }
 
+/**
+ * iscsi_scan_finished - helper to report when running scans are done
+ * @shost: scsi host
+ * @time: scan run time
+ *
+ * This function can be used by drives like qla4xxx to report to the scsi
+ * layer when the scans it kicked off at module load time are done.
+ */
+int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time)
+{
+       struct iscsi_host *ihost = shost->shost_data;
+       /*
+        * qla4xxx will have kicked off some session unblocks before calling
+        * scsi_scan_host, so just wait for them to complete.
+        */
+       return !atomic_read(&ihost->nr_scans);
+}
+EXPORT_SYMBOL_GPL(iscsi_scan_finished);
+
 static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
                           uint id, uint lun)
 {
@@ -254,14 +322,50 @@ static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
        return 0;
 }
 
+static void iscsi_scan_session(struct work_struct *work)
+{
+       struct iscsi_cls_session *session =
+                       container_of(work, struct iscsi_cls_session, scan_work);
+       struct Scsi_Host *shost = iscsi_session_to_shost(session);
+       struct iscsi_host *ihost = shost->shost_data;
+       unsigned long flags;
+
+       spin_lock_irqsave(&session->lock, flags);
+       if (session->state != ISCSI_SESSION_LOGGED_IN) {
+               spin_unlock_irqrestore(&session->lock, flags);
+               goto done;
+       }
+       spin_unlock_irqrestore(&session->lock, flags);
+
+       scsi_scan_target(&session->dev, 0, session->target_id,
+                        SCAN_WILD_CARD, 1);
+done:
+       atomic_dec(&ihost->nr_scans);
+}
+
 static void session_recovery_timedout(struct work_struct *work)
 {
        struct iscsi_cls_session *session =
                container_of(work, struct iscsi_cls_session,
                             recovery_work.work);
+       unsigned long flags;
+
+       iscsi_cls_session_printk(KERN_INFO, session,
+                                "session recovery timed out after %d secs\n",
+                                session->recovery_tmo);
 
-       dev_printk(KERN_INFO, &session->dev, "iscsi: session recovery timed "
-                 "out after %d secs\n", session->recovery_tmo);
+       spin_lock_irqsave(&session->lock, flags);
+       switch (session->state) {
+       case ISCSI_SESSION_FAILED:
+               session->state = ISCSI_SESSION_FREE;
+               break;
+       case ISCSI_SESSION_LOGGED_IN:
+       case ISCSI_SESSION_FREE:
+               /* we raced with the unblock's flush */
+               spin_unlock_irqrestore(&session->lock, flags);
+               return;
+       }
+       spin_unlock_irqrestore(&session->lock, flags);
 
        if (session->transport->session_recovery_timedout)
                session->transport->session_recovery_timedout(session);
@@ -269,16 +373,44 @@ static void session_recovery_timedout(struct work_struct *work)
        scsi_target_unblock(&session->dev);
 }
 
-void iscsi_unblock_session(struct iscsi_cls_session *session)
+void __iscsi_unblock_session(struct iscsi_cls_session *session)
 {
        if (!cancel_delayed_work(&session->recovery_work))
                flush_workqueue(iscsi_eh_timer_workq);
        scsi_target_unblock(&session->dev);
 }
+
+void iscsi_unblock_session(struct iscsi_cls_session *session)
+{
+       struct Scsi_Host *shost = iscsi_session_to_shost(session);
+       struct iscsi_host *ihost = shost->shost_data;
+       unsigned long flags;
+
+       spin_lock_irqsave(&session->lock, flags);
+       session->state = ISCSI_SESSION_LOGGED_IN;
+       spin_unlock_irqrestore(&session->lock, flags);
+
+       __iscsi_unblock_session(session);
+       /*
+        * Only do kernel scanning if the driver is properly hooked into
+        * the async scanning code (drivers like iscsi_tcp do login and
+        * scanning from userspace).
+        */
+       if (shost->hostt->scan_finished) {
+               if (queue_work(ihost->scan_workq, &session->scan_work))
+                       atomic_inc(&ihost->nr_scans);
+       }
+}
 EXPORT_SYMBOL_GPL(iscsi_unblock_session);
 
 void iscsi_block_session(struct iscsi_cls_session *session)
 {
+       unsigned long flags;
+
+       spin_lock_irqsave(&session->lock, flags);
+       session->state = ISCSI_SESSION_FAILED;
+       spin_unlock_irqrestore(&session->lock, flags);
+
        scsi_target_block(&session->dev);
        queue_delayed_work(iscsi_eh_timer_workq, &session->recovery_work,
                           session->recovery_tmo * HZ);
@@ -311,7 +443,7 @@ static int iscsi_unbind_session(struct iscsi_cls_session *session)
        struct Scsi_Host *shost = iscsi_session_to_shost(session);
        struct iscsi_host *ihost = shost->shost_data;
 
-       return queue_work(ihost->unbind_workq, &session->unbind_work);
+       return queue_work(ihost->scan_workq, &session->unbind_work);
 }
 
 struct iscsi_cls_session *
@@ -327,10 +459,13 @@ iscsi_alloc_session(struct Scsi_Host *shost,
 
        session->transport = transport;
        session->recovery_tmo = 120;
+       session->state = ISCSI_SESSION_FREE;
        INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout);
        INIT_LIST_HEAD(&session->host_list);
        INIT_LIST_HEAD(&session->sess_list);
        INIT_WORK(&session->unbind_work, __iscsi_unbind_session);
+       INIT_WORK(&session->scan_work, iscsi_scan_session);
+       spin_lock_init(&session->lock);
 
        /* this is released in the dev's release function */
        scsi_host_get(shost);
@@ -358,8 +493,8 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
                 session->sid);
        err = device_add(&session->dev);
        if (err) {
-               dev_printk(KERN_ERR, &session->dev, "iscsi: could not "
-                          "register session's dev\n");
+               iscsi_cls_session_printk(KERN_ERR, session,
+                                        "could not register session's dev\n");
                goto release_host;
        }
        transport_register_device(&session->dev);
@@ -444,22 +579,28 @@ void iscsi_remove_session(struct iscsi_cls_session *session)
         * If we are blocked let commands flow again. The lld or iscsi
         * layer should set up the queuecommand to fail commands.
         */
-       iscsi_unblock_session(session);
-       iscsi_unbind_session(session);
+       spin_lock_irqsave(&session->lock, flags);
+       session->state = ISCSI_SESSION_FREE;
+       spin_unlock_irqrestore(&session->lock, flags);
+       __iscsi_unblock_session(session);
+       __iscsi_unbind_session(&session->unbind_work);
+
+       /* flush running scans */
+       flush_workqueue(ihost->scan_workq);
        /*
         * If the session dropped while removing devices then we need to make
         * sure it is not blocked
         */
        if (!cancel_delayed_work(&session->recovery_work))
                flush_workqueue(iscsi_eh_timer_workq);
-       flush_workqueue(ihost->unbind_workq);
 
        /* hw iscsi may not have removed all connections from session */
        err = device_for_each_child(&session->dev, NULL,
                                    iscsi_iter_destroy_conn_fn);
        if (err)
-               dev_printk(KERN_ERR, &session->dev, "iscsi: Could not delete "
-                          "all connections for session. Error %d.\n", err);
+               iscsi_cls_session_printk(KERN_ERR, session,
+                                        "Could not delete all connections "
+                                        "for session. Error %d.\n", err);
 
        transport_unregister_device(&session->dev);
        device_del(&session->dev);
@@ -531,8 +672,8 @@ iscsi_create_conn(struct iscsi_cls_session *session, uint32_t cid)
        conn->dev.release = iscsi_conn_release;
        err = device_register(&conn->dev);
        if (err) {
-               dev_printk(KERN_ERR, &conn->dev, "iscsi: could not register "
-                          "connection's dev\n");
+               iscsi_cls_session_printk(KERN_ERR, session, "could not "
+                                        "register connection's dev\n");
                goto release_parent_ref;
        }
        transport_register_device(&conn->dev);
@@ -639,8 +780,8 @@ int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
        skb = alloc_skb(len, GFP_ATOMIC);
        if (!skb) {
                iscsi_conn_error(conn, ISCSI_ERR_CONN_FAILED);
-               dev_printk(KERN_ERR, &conn->dev, "iscsi: can not deliver "
-                          "control PDU: OOM\n");
+               iscsi_cls_conn_printk(KERN_ERR, conn, "can not deliver "
+                                     "control PDU: OOM\n");
                return -ENOMEM;
        }
 
@@ -661,20 +802,27 @@ EXPORT_SYMBOL_GPL(iscsi_recv_pdu);
 
 void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error)
 {
+       struct iscsi_cls_session *session = iscsi_conn_to_session(conn);
        struct nlmsghdr *nlh;
        struct sk_buff  *skb;
        struct iscsi_uevent *ev;
        struct iscsi_internal *priv;
        int len = NLMSG_SPACE(sizeof(*ev));
+       unsigned long flags;
 
        priv = iscsi_if_transport_lookup(conn->transport);
        if (!priv)
                return;
 
+       spin_lock_irqsave(&session->lock, flags);
+       if (session->state == ISCSI_SESSION_LOGGED_IN)
+               session->state = ISCSI_SESSION_FAILED;
+       spin_unlock_irqrestore(&session->lock, flags);
+
        skb = alloc_skb(len, GFP_ATOMIC);
        if (!skb) {
-               dev_printk(KERN_ERR, &conn->dev, "iscsi: gracefully ignored "
-                         "conn error (%d)\n", error);
+               iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
+                                     "conn error (%d)\n", error);
                return;
        }
 
@@ -688,8 +836,8 @@ void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error)
 
        iscsi_broadcast_skb(skb, GFP_ATOMIC);
 
-       dev_printk(KERN_INFO, &conn->dev, "iscsi: detected conn error (%d)\n",
-                  error);
+       iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn error (%d)\n",
+                             error);
 }
 EXPORT_SYMBOL_GPL(iscsi_conn_error);
 
@@ -744,8 +892,8 @@ iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
 
                skbstat = alloc_skb(len, GFP_ATOMIC);
                if (!skbstat) {
-                       dev_printk(KERN_ERR, &conn->dev, "iscsi: can not "
-                                  "deliver stats: OOM\n");
+                       iscsi_cls_conn_printk(KERN_ERR, conn, "can not "
+                                             "deliver stats: OOM\n");
                        return -ENOMEM;
                }
 
@@ -801,8 +949,9 @@ int iscsi_session_event(struct iscsi_cls_session *session,
 
        skb = alloc_skb(len, GFP_KERNEL);
        if (!skb) {
-               dev_printk(KERN_ERR, &session->dev, "Cannot notify userspace "
-                         "of session event %u\n", event);
+               iscsi_cls_session_printk(KERN_ERR, session,
+                                        "Cannot notify userspace of session "
+                                        "event %u\n", event);
                return -ENOMEM;
        }
 
@@ -825,8 +974,8 @@ int iscsi_session_event(struct iscsi_cls_session *session,
                ev->r.unbind_session.sid = session->sid;
                break;
        default:
-               dev_printk(KERN_ERR, &session->dev, "Invalid event %u.\n",
-                          event);
+               iscsi_cls_session_printk(KERN_ERR, session, "Invalid event "
+                                        "%u.\n", event);
                kfree_skb(skb);
                return -EINVAL;
        }
@@ -837,8 +986,10 @@ int iscsi_session_event(struct iscsi_cls_session *session,
         */
        rc = iscsi_broadcast_skb(skb, GFP_KERNEL);
        if (rc < 0)
-               dev_printk(KERN_ERR, &session->dev, "Cannot notify userspace "
-                         "of session event %u. Check iscsi daemon\n", event);
+               iscsi_cls_session_printk(KERN_ERR, session,
+                                        "Cannot notify userspace of session "
+                                        "event %u. Check iscsi daemon\n",
+                                        event);
        return rc;
 }
 EXPORT_SYMBOL_GPL(iscsi_session_event);
@@ -871,16 +1022,15 @@ iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
 
        session = iscsi_session_lookup(ev->u.c_conn.sid);
        if (!session) {
-               printk(KERN_ERR "iscsi: invalid session %d\n",
+               printk(KERN_ERR "iscsi: invalid session %d.\n",
                       ev->u.c_conn.sid);
                return -EINVAL;
        }
 
        conn = transport->create_conn(session, ev->u.c_conn.cid);
        if (!conn) {
-               printk(KERN_ERR "iscsi: couldn't create a new "
-                          "connection for session %d\n",
-                          session->sid);
+               iscsi_cls_session_printk(KERN_ERR, session,
+                                        "couldn't create a new connection.");
                return -ENOMEM;
        }
 
@@ -1246,6 +1396,15 @@ iscsi_session_attr(fast_abort, ISCSI_PARAM_FAST_ABORT, 0);
 iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0);
 iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0);
 
+static ssize_t
+show_priv_session_state(struct class_device *cdev, char *buf)
+{
+       struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev);
+       return sprintf(buf, "%s\n", iscsi_session_state_name(session->state));
+}
+static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state,
+                       NULL);
+
 #define iscsi_priv_session_attr_show(field, format)                    \
 static ssize_t                                                         \
 show_priv_session_##field(struct class_device *cdev, char *buf)                \
@@ -1472,6 +1631,7 @@ iscsi_register_transport(struct iscsi_transport *tt)
        SETUP_SESSION_RD_ATTR(abort_tmo, ISCSI_ABORT_TMO);
        SETUP_SESSION_RD_ATTR(lu_reset_tmo,ISCSI_LU_RESET_TMO);
        SETUP_PRIV_SESSION_RD_ATTR(recovery_tmo);
+       SETUP_PRIV_SESSION_RD_ATTR(state);
 
        BUG_ON(count > ISCSI_SESSION_ATTRS);
        priv->session_attrs[count] = NULL;
index 51a5557f42dda472fd67bb0b7352ddb7ff1d3c7a..37df8bbe7f462b3c74228abef8f9ed71a6e6e731 100644 (file)
@@ -929,6 +929,7 @@ static int sd_done(struct scsi_cmnd *SCpnt)
        unsigned int xfer_size = scsi_bufflen(SCpnt);
        unsigned int good_bytes = result ? 0 : xfer_size;
        u64 start_lba = SCpnt->request->sector;
+       u64 end_lba = SCpnt->request->sector + (xfer_size / 512);
        u64 bad_lba;
        struct scsi_sense_hdr sshdr;
        int sense_valid = 0;
@@ -967,26 +968,23 @@ static int sd_done(struct scsi_cmnd *SCpnt)
                        goto out;
                if (xfer_size <= SCpnt->device->sector_size)
                        goto out;
-               switch (SCpnt->device->sector_size) {
-               case 256:
+               if (SCpnt->device->sector_size < 512) {
+                       /* only legitimate sector_size here is 256 */
                        start_lba <<= 1;
-                       break;
-               case 512:
-                       break;
-               case 1024:
-                       start_lba >>= 1;
-                       break;
-               case 2048:
-                       start_lba >>= 2;
-                       break;
-               case 4096:
-                       start_lba >>= 3;
-                       break;
-               default:
-                       /* Print something here with limiting frequency. */
-                       goto out;
-                       break;
+                       end_lba <<= 1;
+               } else {
+                       /* be careful ... don't want any overflows */
+                       u64 factor = SCpnt->device->sector_size / 512;
+                       do_div(start_lba, factor);
+                       do_div(end_lba, factor);
                }
+
+               if (bad_lba < start_lba  || bad_lba >= end_lba)
+                       /* the bad lba was reported incorrectly, we have
+                        * no idea where the error is
+                        */
+                       goto out;
+
                /* This computation should always be done in terms of
                 * the resolution of the device's medium.
                 */
diff --git a/drivers/scsi/ses.c b/drivers/scsi/ses.c
new file mode 100644 (file)
index 0000000..2a6e4f4
--- /dev/null
@@ -0,0 +1,689 @@
+/*
+ * SCSI Enclosure Services
+ *
+ * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com>
+ *
+**-----------------------------------------------------------------------------
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  version 2 as published by the Free Software Foundation.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+**
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+**-----------------------------------------------------------------------------
+*/
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/enclosure.h>
+
+#include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_dbg.h>
+#include <scsi/scsi_device.h>
+#include <scsi/scsi_driver.h>
+#include <scsi/scsi_host.h>
+
+struct ses_device {
+       char *page1;
+       char *page2;
+       char *page10;
+       short page1_len;
+       short page2_len;
+       short page10_len;
+};
+
+struct ses_component {
+       u64 addr;
+       unsigned char *desc;
+};
+
+static int ses_probe(struct device *dev)
+{
+       struct scsi_device *sdev = to_scsi_device(dev);
+       int err = -ENODEV;
+
+       if (sdev->type != TYPE_ENCLOSURE)
+               goto out;
+
+       err = 0;
+       sdev_printk(KERN_NOTICE, sdev, "Attached Enclosure device\n");
+
+ out:
+       return err;
+}
+
+#define SES_TIMEOUT 30
+#define SES_RETRIES 3
+
+static int ses_recv_diag(struct scsi_device *sdev, int page_code,
+                        void *buf, int bufflen)
+{
+       char cmd[] = {
+               RECEIVE_DIAGNOSTIC,
+               1,              /* Set PCV bit */
+               page_code,
+               bufflen >> 8,
+               bufflen & 0xff,
+               0
+       };
+
+       return scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buf, bufflen,
+                               NULL, SES_TIMEOUT, SES_RETRIES);
+}
+
+static int ses_send_diag(struct scsi_device *sdev, int page_code,
+                        void *buf, int bufflen)
+{
+       u32 result;
+
+       char cmd[] = {
+               SEND_DIAGNOSTIC,
+               0x10,           /* Set PF bit */
+               0,
+               bufflen >> 8,
+               bufflen & 0xff,
+               0
+       };
+
+       result = scsi_execute_req(sdev, cmd, DMA_TO_DEVICE, buf, bufflen,
+                                 NULL, SES_TIMEOUT, SES_RETRIES);
+       if (result)
+               sdev_printk(KERN_ERR, sdev, "SEND DIAGNOSTIC result: %8x\n",
+                           result);
+       return result;
+}
+
+static int ses_set_page2_descriptor(struct enclosure_device *edev,
+                                     struct enclosure_component *ecomp,
+                                     char *desc)
+{
+       int i, j, count = 0, descriptor = ecomp->number;
+       struct scsi_device *sdev = to_scsi_device(edev->cdev.dev);
+       struct ses_device *ses_dev = edev->scratch;
+       char *type_ptr = ses_dev->page1 + 12 + ses_dev->page1[11];
+       char *desc_ptr = ses_dev->page2 + 8;
+
+       /* Clear everything */
+       memset(desc_ptr, 0, ses_dev->page2_len - 8);
+       for (i = 0; i < ses_dev->page1[10]; i++, type_ptr += 4) {
+               for (j = 0; j < type_ptr[1]; j++) {
+                       desc_ptr += 4;
+                       if (type_ptr[0] != ENCLOSURE_COMPONENT_DEVICE &&
+                           type_ptr[0] != ENCLOSURE_COMPONENT_ARRAY_DEVICE)
+                               continue;
+                       if (count++ == descriptor) {
+                               memcpy(desc_ptr, desc, 4);
+                               /* set select */
+                               desc_ptr[0] |= 0x80;
+                               /* clear reserved, just in case */
+                               desc_ptr[0] &= 0xf0;
+                       }
+               }
+       }
+
+       return ses_send_diag(sdev, 2, ses_dev->page2, ses_dev->page2_len);
+}
+
+static char *ses_get_page2_descriptor(struct enclosure_device *edev,
+                                     struct enclosure_component *ecomp)
+{
+       int i, j, count = 0, descriptor = ecomp->number;
+       struct scsi_device *sdev = to_scsi_device(edev->cdev.dev);
+       struct ses_device *ses_dev = edev->scratch;
+       char *type_ptr = ses_dev->page1 + 12 + ses_dev->page1[11];
+       char *desc_ptr = ses_dev->page2 + 8;
+
+       ses_recv_diag(sdev, 2, ses_dev->page2, ses_dev->page2_len);
+
+       for (i = 0; i < ses_dev->page1[10]; i++, type_ptr += 4) {
+               for (j = 0; j < type_ptr[1]; j++) {
+                       desc_ptr += 4;
+                       if (type_ptr[0] != ENCLOSURE_COMPONENT_DEVICE &&
+                           type_ptr[0] != ENCLOSURE_COMPONENT_ARRAY_DEVICE)
+                               continue;
+                       if (count++ == descriptor)
+                               return desc_ptr;
+               }
+       }
+       return NULL;
+}
+
+static void ses_get_fault(struct enclosure_device *edev,
+                         struct enclosure_component *ecomp)
+{
+       char *desc;
+
+       desc = ses_get_page2_descriptor(edev, ecomp);
+       ecomp->fault = (desc[3] & 0x60) >> 4;
+}
+
+static int ses_set_fault(struct enclosure_device *edev,
+                         struct enclosure_component *ecomp,
+                        enum enclosure_component_setting val)
+{
+       char desc[4] = {0 };
+
+       switch (val) {
+       case ENCLOSURE_SETTING_DISABLED:
+               /* zero is disabled */
+               break;
+       case ENCLOSURE_SETTING_ENABLED:
+               desc[2] = 0x02;
+               break;
+       default:
+               /* SES doesn't do the SGPIO blink settings */
+               return -EINVAL;
+       }
+
+       return ses_set_page2_descriptor(edev, ecomp, desc);
+}
+
+static void ses_get_status(struct enclosure_device *edev,
+                          struct enclosure_component *ecomp)
+{
+       char *desc;
+
+       desc = ses_get_page2_descriptor(edev, ecomp);
+       ecomp->status = (desc[0] & 0x0f);
+}
+
+static void ses_get_locate(struct enclosure_device *edev,
+                          struct enclosure_component *ecomp)
+{
+       char *desc;
+
+       desc = ses_get_page2_descriptor(edev, ecomp);
+       ecomp->locate = (desc[2] & 0x02) ? 1 : 0;
+}
+
+static int ses_set_locate(struct enclosure_device *edev,
+                         struct enclosure_component *ecomp,
+                         enum enclosure_component_setting val)
+{
+       char desc[4] = {0 };
+
+       switch (val) {
+       case ENCLOSURE_SETTING_DISABLED:
+               /* zero is disabled */
+               break;
+       case ENCLOSURE_SETTING_ENABLED:
+               desc[2] = 0x02;
+               break;
+       default:
+               /* SES doesn't do the SGPIO blink settings */
+               return -EINVAL;
+       }
+       return ses_set_page2_descriptor(edev, ecomp, desc);
+}
+
+static int ses_set_active(struct enclosure_device *edev,
+                         struct enclosure_component *ecomp,
+                         enum enclosure_component_setting val)
+{
+       char desc[4] = {0 };
+
+       switch (val) {
+       case ENCLOSURE_SETTING_DISABLED:
+               /* zero is disabled */
+               ecomp->active = 0;
+               break;
+       case ENCLOSURE_SETTING_ENABLED:
+               desc[2] = 0x80;
+               ecomp->active = 1;
+               break;
+       default:
+               /* SES doesn't do the SGPIO blink settings */
+               return -EINVAL;
+       }
+       return ses_set_page2_descriptor(edev, ecomp, desc);
+}
+
+static struct enclosure_component_callbacks ses_enclosure_callbacks = {
+       .get_fault              = ses_get_fault,
+       .set_fault              = ses_set_fault,
+       .get_status             = ses_get_status,
+       .get_locate             = ses_get_locate,
+       .set_locate             = ses_set_locate,
+       .set_active             = ses_set_active,
+};
+
+struct ses_host_edev {
+       struct Scsi_Host *shost;
+       struct enclosure_device *edev;
+};
+
+int ses_match_host(struct enclosure_device *edev, void *data)
+{
+       struct ses_host_edev *sed = data;
+       struct scsi_device *sdev;
+
+       if (!scsi_is_sdev_device(edev->cdev.dev))
+               return 0;
+
+       sdev = to_scsi_device(edev->cdev.dev);
+
+       if (sdev->host != sed->shost)
+               return 0;
+
+       sed->edev = edev;
+       return 1;
+}
+
+static void ses_process_descriptor(struct enclosure_component *ecomp,
+                                  unsigned char *desc)
+{
+       int eip = desc[0] & 0x10;
+       int invalid = desc[0] & 0x80;
+       enum scsi_protocol proto = desc[0] & 0x0f;
+       u64 addr = 0;
+       struct ses_component *scomp = ecomp->scratch;
+       unsigned char *d;
+
+       scomp->desc = desc;
+
+       if (invalid)
+               return;
+
+       switch (proto) {
+       case SCSI_PROTOCOL_SAS:
+               if (eip)
+                       d = desc + 8;
+               else
+                       d = desc + 4;
+               /* only take the phy0 addr */
+               addr = (u64)d[12] << 56 |
+                       (u64)d[13] << 48 |
+                       (u64)d[14] << 40 |
+                       (u64)d[15] << 32 |
+                       (u64)d[16] << 24 |
+                       (u64)d[17] << 16 |
+                       (u64)d[18] << 8 |
+                       (u64)d[19];
+               break;
+       default:
+               /* FIXME: Need to add more protocols than just SAS */
+               break;
+       }
+       scomp->addr = addr;
+}
+
+struct efd {
+       u64 addr;
+       struct device *dev;
+};
+
+static int ses_enclosure_find_by_addr(struct enclosure_device *edev,
+                                     void *data)
+{
+       struct efd *efd = data;
+       int i;
+       struct ses_component *scomp;
+
+       if (!edev->component[0].scratch)
+               return 0;
+
+       for (i = 0; i < edev->components; i++) {
+               scomp = edev->component[i].scratch;
+               if (scomp->addr != efd->addr)
+                       continue;
+
+               enclosure_add_device(edev, i, efd->dev);
+               return 1;
+       }
+       return 0;
+}
+
+#define VPD_INQUIRY_SIZE 512
+
+static void ses_match_to_enclosure(struct enclosure_device *edev,
+                                  struct scsi_device *sdev)
+{
+       unsigned char *buf = kmalloc(VPD_INQUIRY_SIZE, GFP_KERNEL);
+       unsigned char *desc;
+       int len;
+       struct efd efd = {
+               .addr = 0,
+       };
+       unsigned char cmd[] = {
+               INQUIRY,
+               1,
+               0x83,
+               VPD_INQUIRY_SIZE >> 8,
+               VPD_INQUIRY_SIZE & 0xff,
+               0
+       };
+
+       if (!buf)
+               return;
+
+       if (scsi_execute_req(sdev, cmd, DMA_FROM_DEVICE, buf,
+                            VPD_INQUIRY_SIZE, NULL, SES_TIMEOUT, SES_RETRIES))
+               goto free;
+
+       len = (buf[2] << 8) + buf[3];
+       desc = buf + 4;
+       while (desc < buf + len) {
+               enum scsi_protocol proto = desc[0] >> 4;
+               u8 code_set = desc[0] & 0x0f;
+               u8 piv = desc[1] & 0x80;
+               u8 assoc = (desc[1] & 0x30) >> 4;
+               u8 type = desc[1] & 0x0f;
+               u8 len = desc[3];
+
+               if (piv && code_set == 1 && assoc == 1 && code_set == 1
+                   && proto == SCSI_PROTOCOL_SAS && type == 3 && len == 8)
+                       efd.addr = (u64)desc[4] << 56 |
+                               (u64)desc[5] << 48 |
+                               (u64)desc[6] << 40 |
+                               (u64)desc[7] << 32 |
+                               (u64)desc[8] << 24 |
+                               (u64)desc[9] << 16 |
+                               (u64)desc[10] << 8 |
+                               (u64)desc[11];
+
+               desc += len + 4;
+       }
+       if (!efd.addr)
+               goto free;
+
+       efd.dev = &sdev->sdev_gendev;
+
+       enclosure_for_each_device(ses_enclosure_find_by_addr, &efd);
+ free:
+       kfree(buf);
+}
+
+#define INIT_ALLOC_SIZE 32
+
+static int ses_intf_add(struct class_device *cdev,
+                       struct class_interface *intf)
+{
+       struct scsi_device *sdev = to_scsi_device(cdev->dev);
+       struct scsi_device *tmp_sdev;
+       unsigned char *buf = NULL, *hdr_buf, *type_ptr, *desc_ptr,
+               *addl_desc_ptr;
+       struct ses_device *ses_dev;
+       u32 result;
+       int i, j, types, len, components = 0;
+       int err = -ENOMEM;
+       struct enclosure_device *edev;
+       struct ses_component *scomp;
+
+       if (!scsi_device_enclosure(sdev)) {
+               /* not an enclosure, but might be in one */
+               edev =  enclosure_find(&sdev->host->shost_gendev);
+               if (edev) {
+                       ses_match_to_enclosure(edev, sdev);
+                       class_device_put(&edev->cdev);
+               }
+               return -ENODEV;
+       }
+
+       /* TYPE_ENCLOSURE prints a message in probe */
+       if (sdev->type != TYPE_ENCLOSURE)
+               sdev_printk(KERN_NOTICE, sdev, "Embedded Enclosure Device\n");
+
+       ses_dev = kzalloc(sizeof(*ses_dev), GFP_KERNEL);
+       hdr_buf = kzalloc(INIT_ALLOC_SIZE, GFP_KERNEL);
+       if (!hdr_buf || !ses_dev)
+               goto err_init_free;
+
+       result = ses_recv_diag(sdev, 1, hdr_buf, INIT_ALLOC_SIZE);
+       if (result)
+               goto recv_failed;
+
+       if (hdr_buf[1] != 0) {
+               /* FIXME: need subenclosure support; I've just never
+                * seen a device with subenclosures and it makes the
+                * traversal routines more complex */
+               sdev_printk(KERN_ERR, sdev,
+                       "FIXME driver has no support for subenclosures (%d)\n",
+                       buf[1]);
+               goto err_free;
+       }
+
+       len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
+       buf = kzalloc(len, GFP_KERNEL);
+       if (!buf)
+               goto err_free;
+
+       ses_dev->page1 = buf;
+       ses_dev->page1_len = len;
+
+       result = ses_recv_diag(sdev, 1, buf, len);
+       if (result)
+               goto recv_failed;
+
+       types = buf[10];
+       len = buf[11];
+
+       type_ptr = buf + 12 + len;
+
+       for (i = 0; i < types; i++, type_ptr += 4) {
+               if (type_ptr[0] == ENCLOSURE_COMPONENT_DEVICE ||
+                   type_ptr[0] == ENCLOSURE_COMPONENT_ARRAY_DEVICE)
+                       components += type_ptr[1];
+       }
+
+       result = ses_recv_diag(sdev, 2, hdr_buf, INIT_ALLOC_SIZE);
+       if (result)
+               goto recv_failed;
+
+       len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
+       buf = kzalloc(len, GFP_KERNEL);
+       if (!buf)
+               goto err_free;
+
+       /* make sure getting page 2 actually works */
+       result = ses_recv_diag(sdev, 2, buf, len);
+       if (result)
+               goto recv_failed;
+       ses_dev->page2 = buf;
+       ses_dev->page2_len = len;
+
+       /* The additional information page --- allows us
+        * to match up the devices */
+       result = ses_recv_diag(sdev, 10, hdr_buf, INIT_ALLOC_SIZE);
+       if (result)
+               goto no_page10;
+
+       len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
+       buf = kzalloc(len, GFP_KERNEL);
+       if (!buf)
+               goto err_free;
+
+       result = ses_recv_diag(sdev, 10, buf, len);
+       if (result)
+               goto recv_failed;
+       ses_dev->page10 = buf;
+       ses_dev->page10_len = len;
+
+ no_page10:
+       scomp = kmalloc(sizeof(struct ses_component) * components, GFP_KERNEL);
+       if (!scomp)
+               goto  err_free;
+
+       edev = enclosure_register(cdev->dev, sdev->sdev_gendev.bus_id,
+                                 components, &ses_enclosure_callbacks);
+       if (IS_ERR(edev)) {
+               err = PTR_ERR(edev);
+               goto err_free;
+       }
+
+       edev->scratch = ses_dev;
+       for (i = 0; i < components; i++)
+               edev->component[i].scratch = scomp++;
+
+       /* Page 7 for the descriptors is optional */
+       buf = NULL;
+       result = ses_recv_diag(sdev, 7, hdr_buf, INIT_ALLOC_SIZE);
+       if (result)
+               goto simple_populate;
+
+       len = (hdr_buf[2] << 8) + hdr_buf[3] + 4;
+       /* add 1 for trailing '\0' we'll use */
+       buf = kzalloc(len + 1, GFP_KERNEL);
+       result = ses_recv_diag(sdev, 7, buf, len);
+       if (result) {
+ simple_populate:
+               kfree(buf);
+               buf = NULL;
+               desc_ptr = NULL;
+               addl_desc_ptr = NULL;
+       } else {
+               desc_ptr = buf + 8;
+               len = (desc_ptr[2] << 8) + desc_ptr[3];
+               /* skip past overall descriptor */
+               desc_ptr += len + 4;
+               addl_desc_ptr = ses_dev->page10 + 8;
+       }
+       type_ptr = ses_dev->page1 + 12 + ses_dev->page1[11];
+       components = 0;
+       for (i = 0; i < types; i++, type_ptr += 4) {
+               for (j = 0; j < type_ptr[1]; j++) {
+                       char *name = NULL;
+                       struct enclosure_component *ecomp;
+
+                       if (desc_ptr) {
+                               len = (desc_ptr[2] << 8) + desc_ptr[3];
+                               desc_ptr += 4;
+                               /* Add trailing zero - pushes into
+                                * reserved space */
+                               desc_ptr[len] = '\0';
+                               name = desc_ptr;
+                       }
+                       if (type_ptr[0] != ENCLOSURE_COMPONENT_DEVICE &&
+                           type_ptr[0] != ENCLOSURE_COMPONENT_ARRAY_DEVICE)
+                               continue;
+                       ecomp = enclosure_component_register(edev,
+                                                            components++,
+                                                            type_ptr[0],
+                                                            name);
+                       if (desc_ptr) {
+                               desc_ptr += len;
+                               if (!IS_ERR(ecomp))
+                                       ses_process_descriptor(ecomp,
+                                                              addl_desc_ptr);
+
+                               if (addl_desc_ptr)
+                                       addl_desc_ptr += addl_desc_ptr[1] + 2;
+                       }
+               }
+       }
+       kfree(buf);
+       kfree(hdr_buf);
+
+       /* see if there are any devices matching before
+        * we found the enclosure */
+       shost_for_each_device(tmp_sdev, sdev->host) {
+               if (tmp_sdev->lun != 0 || scsi_device_enclosure(tmp_sdev))
+                       continue;
+               ses_match_to_enclosure(edev, tmp_sdev);
+       }
+
+       return 0;
+
+ recv_failed:
+       sdev_printk(KERN_ERR, sdev, "Failed to get diagnostic page 0x%x\n",
+                   result);
+       err = -ENODEV;
+ err_free:
+       kfree(buf);
+       kfree(ses_dev->page10);
+       kfree(ses_dev->page2);
+       kfree(ses_dev->page1);
+ err_init_free:
+       kfree(ses_dev);
+       kfree(hdr_buf);
+       sdev_printk(KERN_ERR, sdev, "Failed to bind enclosure %d\n", err);
+       return err;
+}
+
+static int ses_remove(struct device *dev)
+{
+       return 0;
+}
+
+static void ses_intf_remove(struct class_device *cdev,
+                           struct class_interface *intf)
+{
+       struct scsi_device *sdev = to_scsi_device(cdev->dev);
+       struct enclosure_device *edev;
+       struct ses_device *ses_dev;
+
+       if (!scsi_device_enclosure(sdev))
+               return;
+
+       edev = enclosure_find(cdev->dev);
+       if (!edev)
+               return;
+
+       ses_dev = edev->scratch;
+       edev->scratch = NULL;
+
+       kfree(ses_dev->page1);
+       kfree(ses_dev->page2);
+       kfree(ses_dev);
+
+       kfree(edev->component[0].scratch);
+
+       class_device_put(&edev->cdev);
+       enclosure_unregister(edev);
+}
+
+static struct class_interface ses_interface = {
+       .add    = ses_intf_add,
+       .remove = ses_intf_remove,
+};
+
+static struct scsi_driver ses_template = {
+       .owner                  = THIS_MODULE,
+       .gendrv = {
+               .name           = "ses",
+               .probe          = ses_probe,
+               .remove         = ses_remove,
+       },
+};
+
+static int __init ses_init(void)
+{
+       int err;
+
+       err = scsi_register_interface(&ses_interface);
+       if (err)
+               return err;
+
+       err = scsi_register_driver(&ses_template.gendrv);
+       if (err)
+               goto out_unreg;
+
+       return 0;
+
+ out_unreg:
+       scsi_unregister_interface(&ses_interface);
+       return err;
+}
+
+static void __exit ses_exit(void)
+{
+       scsi_unregister_driver(&ses_template.gendrv);
+       scsi_unregister_interface(&ses_interface);
+}
+
+module_init(ses_init);
+module_exit(ses_exit);
+
+MODULE_ALIAS_SCSI_DEVICE(TYPE_ENCLOSURE);
+
+MODULE_AUTHOR("James Bottomley");
+MODULE_DESCRIPTION("SCSI Enclosure Services (ses) driver");
+MODULE_LICENSE("GPL v2");
index aba28f335b88ffd677764a4aeaade2d91e95137a..e5156aa6dd203d850209dc78a16b8d7b548360ab 100644 (file)
@@ -1160,23 +1160,22 @@ sg_fasync(int fd, struct file *filp, int mode)
        return (retval < 0) ? retval : 0;
 }
 
-static struct page *
-sg_vma_nopage(struct vm_area_struct *vma, unsigned long addr, int *type)
+static int
+sg_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 {
        Sg_fd *sfp;
-       struct page *page = NOPAGE_SIGBUS;
        unsigned long offset, len, sa;
        Sg_scatter_hold *rsv_schp;
        struct scatterlist *sg;
        int k;
 
        if ((NULL == vma) || (!(sfp = (Sg_fd *) vma->vm_private_data)))
-               return page;
+               return VM_FAULT_SIGBUS;
        rsv_schp = &sfp->reserve;
-       offset = addr - vma->vm_start;
+       offset = vmf->pgoff << PAGE_SHIFT;
        if (offset >= rsv_schp->bufflen)
-               return page;
-       SCSI_LOG_TIMEOUT(3, printk("sg_vma_nopage: offset=%lu, scatg=%d\n",
+               return VM_FAULT_SIGBUS;
+       SCSI_LOG_TIMEOUT(3, printk("sg_vma_fault: offset=%lu, scatg=%d\n",
                                   offset, rsv_schp->k_use_sg));
        sg = rsv_schp->buffer;
        sa = vma->vm_start;
@@ -1185,21 +1184,21 @@ sg_vma_nopage(struct vm_area_struct *vma, unsigned long addr, int *type)
                len = vma->vm_end - sa;
                len = (len < sg->length) ? len : sg->length;
                if (offset < len) {
+                       struct page *page;
                        page = virt_to_page(page_address(sg_page(sg)) + offset);
                        get_page(page); /* increment page count */
-                       break;
+                       vmf->page = page;
+                       return 0; /* success */
                }
                sa += len;
                offset -= len;
        }
 
-       if (type)
-               *type = VM_FAULT_MINOR;
-       return page;
+       return VM_FAULT_SIGBUS;
 }
 
 static struct vm_operations_struct sg_mmap_vm_ops = {
-       .nopage = sg_vma_nopage,
+       .fault = sg_vma_fault,
 };
 
 static int
index 50ba492502035afe85d0bd62899b02c132022c63..208565bdbe8e946c5f7c0676d72c2b04174d59fa 100644 (file)
@@ -163,6 +163,29 @@ static void scsi_cd_put(struct scsi_cd *cd)
        mutex_unlock(&sr_ref_mutex);
 }
 
+/* identical to scsi_test_unit_ready except that it doesn't
+ * eat the NOT_READY returns for removable media */
+int sr_test_unit_ready(struct scsi_device *sdev, struct scsi_sense_hdr *sshdr)
+{
+       int retries = MAX_RETRIES;
+       int the_result;
+       u8 cmd[] = {TEST_UNIT_READY, 0, 0, 0, 0, 0 };
+
+       /* issue TEST_UNIT_READY until the initial startup UNIT_ATTENTION
+        * conditions are gone, or a timeout happens
+        */
+       do {
+               the_result = scsi_execute_req(sdev, cmd, DMA_NONE, NULL,
+                                             0, sshdr, SR_TIMEOUT,
+                                             retries--);
+
+       } while (retries > 0 &&
+                (!scsi_status_is_good(the_result) ||
+                 (scsi_sense_valid(sshdr) &&
+                  sshdr->sense_key == UNIT_ATTENTION)));
+       return the_result;
+}
+
 /*
  * This function checks to see if the media has been changed in the
  * CDROM drive.  It is possible that we have already sensed a change,
@@ -185,8 +208,7 @@ static int sr_media_change(struct cdrom_device_info *cdi, int slot)
        }
 
        sshdr =  kzalloc(sizeof(*sshdr), GFP_KERNEL);
-       retval = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES,
-                                     sshdr);
+       retval = sr_test_unit_ready(cd->device, sshdr);
        if (retval || (scsi_sense_valid(sshdr) &&
                       /* 0x3a is medium not present */
                       sshdr->asc == 0x3a)) {
@@ -733,10 +755,8 @@ static void get_capabilities(struct scsi_cd *cd)
 {
        unsigned char *buffer;
        struct scsi_mode_data data;
-       unsigned char cmd[MAX_COMMAND_SIZE];
        struct scsi_sense_hdr sshdr;
-       unsigned int the_result;
-       int retries, rc, n;
+       int rc, n;
 
        static const char *loadmech[] =
        {
@@ -758,23 +778,8 @@ static void get_capabilities(struct scsi_cd *cd)
                return;
        }
 
-       /* issue TEST_UNIT_READY until the initial startup UNIT_ATTENTION
-        * conditions are gone, or a timeout happens
-        */
-       retries = 0;
-       do {
-               memset((void *)cmd, 0, MAX_COMMAND_SIZE);
-               cmd[0] = TEST_UNIT_READY;
-
-               the_result = scsi_execute_req (cd->device, cmd, DMA_NONE, NULL,
-                                              0, &sshdr, SR_TIMEOUT,
-                                              MAX_RETRIES);
-
-               retries++;
-       } while (retries < 5 && 
-                (!scsi_status_is_good(the_result) ||
-                 (scsi_sense_valid(&sshdr) &&
-                  sshdr.sense_key == UNIT_ATTENTION)));
+       /* eat unit attentions */
+       sr_test_unit_ready(cd->device, &sshdr);
 
        /* ask for mode page 0x2a */
        rc = scsi_mode_sense(cd->device, 0, 0x2a, buffer, 128,
index 81fbc0b78a5235cd5fe770e914c2eed60baa58cc..1e144dfdbd4b915ca0b00803631de6a2c3fd7766 100644 (file)
@@ -61,6 +61,7 @@ int sr_select_speed(struct cdrom_device_info *cdi, int speed);
 int sr_audio_ioctl(struct cdrom_device_info *, unsigned int, void *);
 
 int sr_is_xa(Scsi_CD *);
+int sr_test_unit_ready(struct scsi_device *sdev, struct scsi_sense_hdr *sshdr);
 
 /* sr_vendor.c */
 void sr_vendor_init(Scsi_CD *);
index d5cebff1d646dde9492072aa8d9f7a0846b48b79..ae87d08df58832c9d6ce60a091cbb8ace3203d7b 100644 (file)
@@ -306,8 +306,7 @@ int sr_drive_status(struct cdrom_device_info *cdi, int slot)
                /* we have no changer support */
                return -EINVAL;
        }
-       if (0 == scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES,
-                                     &sshdr))
+       if (0 == sr_test_unit_ready(cd->device, &sshdr))
                return CDS_DISC_OK;
 
        if (!cdrom_get_media_event(cdi, &med)) {
index 1bc41907a03817c206db14357ccf11976a2843a6..06152c7fa689bfd21e6dbd7df465ea060a0dcd85 100644 (file)
-/* sun3x_esp.c:  EnhancedScsiProcessor Sun3x SCSI driver code.
+/* sun3x_esp.c: ESP front-end for Sun3x systems.
  *
- * (C) 1999 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
- *
- * Based on David S. Miller's esp driver
+ * Copyright (C) 2007,2008 Thomas Bogendoerfer (tsbogend@alpha.franken.de)
  */
 
 #include <linux/kernel.h>
 #include <linux/types.h>
-#include <linux/string.h>
-#include <linux/slab.h>
-#include <linux/blkdev.h>
-#include <linux/proc_fs.h>
-#include <linux/stat.h>
 #include <linux/delay.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
 #include <linux/interrupt.h>
 
-#include "scsi.h"
-#include <scsi/scsi_host.h>
-#include "NCR53C9x.h"
-
 #include <asm/sun3x.h>
+#include <asm/io.h>
+#include <asm/dma.h>
 #include <asm/dvma.h>
-#include <asm/irq.h>
-
-static void dma_barrier(struct NCR_ESP *esp);
-static int  dma_bytes_sent(struct NCR_ESP *esp, int fifo_count);
-static int  dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp);
-static void dma_drain(struct NCR_ESP *esp);
-static void dma_invalidate(struct NCR_ESP *esp);
-static void dma_dump_state(struct NCR_ESP *esp);
-static void dma_init_read(struct NCR_ESP *esp, __u32 vaddress, int length);
-static void dma_init_write(struct NCR_ESP *esp, __u32 vaddress, int length);
-static void dma_ints_off(struct NCR_ESP *esp);
-static void dma_ints_on(struct NCR_ESP *esp);
-static int  dma_irq_p(struct NCR_ESP *esp);
-static void dma_poll(struct NCR_ESP *esp, unsigned char *vaddr);
-static int  dma_ports_p(struct NCR_ESP *esp);
-static void dma_reset(struct NCR_ESP *esp);
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write);
-static void dma_mmu_get_scsi_one (struct NCR_ESP *esp, Scsi_Cmnd *sp);
-static void dma_mmu_get_scsi_sgl (struct NCR_ESP *esp, Scsi_Cmnd *sp);
-static void dma_mmu_release_scsi_one (struct NCR_ESP *esp, Scsi_Cmnd *sp);
-static void dma_mmu_release_scsi_sgl (struct NCR_ESP *esp, Scsi_Cmnd *sp);
-static void dma_advance_sg (Scsi_Cmnd *sp);
-
-/* Detecting ESP chips on the machine.  This is the simple and easy
- * version.
- */
-int sun3x_esp_detect(struct scsi_host_template *tpnt)
-{
-       struct NCR_ESP *esp;
-       struct ConfigDev *esp_dev;
-
-       esp_dev = 0;
-       esp = esp_allocate(tpnt, esp_dev, 0);
-
-       /* Do command transfer with DMA */
-       esp->do_pio_cmds = 0;
-
-       /* Required functions */
-       esp->dma_bytes_sent = &dma_bytes_sent;
-       esp->dma_can_transfer = &dma_can_transfer;
-       esp->dma_dump_state = &dma_dump_state;
-       esp->dma_init_read = &dma_init_read;
-       esp->dma_init_write = &dma_init_write;
-       esp->dma_ints_off = &dma_ints_off;
-       esp->dma_ints_on = &dma_ints_on;
-       esp->dma_irq_p = &dma_irq_p;
-       esp->dma_ports_p = &dma_ports_p;
-       esp->dma_setup = &dma_setup;
-
-       /* Optional functions */
-       esp->dma_barrier = &dma_barrier;
-       esp->dma_invalidate = &dma_invalidate;
-       esp->dma_drain = &dma_drain;
-       esp->dma_irq_entry = 0;
-       esp->dma_irq_exit = 0;
-       esp->dma_led_on = 0;
-       esp->dma_led_off = 0;
-       esp->dma_poll = &dma_poll;
-       esp->dma_reset = &dma_reset;
-
-        /* virtual DMA functions */
-        esp->dma_mmu_get_scsi_one = &dma_mmu_get_scsi_one;
-        esp->dma_mmu_get_scsi_sgl = &dma_mmu_get_scsi_sgl;
-        esp->dma_mmu_release_scsi_one = &dma_mmu_release_scsi_one;
-        esp->dma_mmu_release_scsi_sgl = &dma_mmu_release_scsi_sgl;
-        esp->dma_advance_sg = &dma_advance_sg;
-           
-       /* SCSI chip speed */
-       esp->cfreq = 20000000;
-       esp->eregs = (struct ESP_regs *)(SUN3X_ESP_BASE);
-       esp->dregs = (void *)SUN3X_ESP_DMA;
 
-       esp->esp_command = (volatile unsigned char *)dvma_malloc(DVMA_PAGE_SIZE);
-       esp->esp_command_dvma = dvma_vtob((unsigned long)esp->esp_command);
-
-       esp->irq = 2;
-       if (request_irq(esp->irq, esp_intr, IRQF_DISABLED,
-                       "SUN3X SCSI", esp->ehost)) {
-               esp_deallocate(esp);
-               return 0;
-       }
+/* DMA controller reg offsets */
+#define DMA_CSR                0x00UL  /* rw  DMA control/status register    0x00   */
+#define DMA_ADDR        0x04UL /* rw  DMA transfer address register  0x04   */
+#define DMA_COUNT       0x08UL /* rw  DMA transfer count register    0x08   */
+#define DMA_TEST        0x0cUL /* rw  DMA test/debug register        0x0c   */
 
-       esp->scsi_id = 7;
-       esp->diff = 0;
+#include <scsi/scsi_host.h>
 
-       esp_initialize(esp);
+#include "esp_scsi.h"
 
-       /* for reasons beyond my knowledge (and which should likely be fixed)
-          sync mode doesn't work on a 3/80 at 5mhz.  but it does at 4. */
-       esp->sync_defp = 0x3f;
+#define DRV_MODULE_NAME                "sun3x_esp"
+#define PFX DRV_MODULE_NAME    ": "
+#define DRV_VERSION            "1.000"
+#define DRV_MODULE_RELDATE     "Nov 1, 2007"
 
-       printk("ESP: Total of %d ESP hosts found, %d actually in use.\n", nesps,
-              esps_in_use);
-       esps_running = esps_in_use;
-       return esps_in_use;
+/*
+ * m68k always assumes readl/writel operate on little endian
+ * mmio space; this is wrong at least for Sun3x, so we
+ * need to workaround this until a proper way is found
+ */
+#if 0
+#define dma_read32(REG) \
+       readl(esp->dma_regs + (REG))
+#define dma_write32(VAL, REG) \
+       writel((VAL), esp->dma_regs + (REG))
+#else
+#define dma_read32(REG) \
+       *(volatile u32 *)(esp->dma_regs + (REG))
+#define dma_write32(VAL, REG) \
+       do { *(volatile u32 *)(esp->dma_regs + (REG)) = (VAL); } while (0)
+#endif
+
+static void sun3x_esp_write8(struct esp *esp, u8 val, unsigned long reg)
+{
+       writeb(val, esp->regs + (reg * 4UL));
 }
 
-static void dma_do_drain(struct NCR_ESP *esp)
+static u8 sun3x_esp_read8(struct esp *esp, unsigned long reg)
 {
-       struct sparc_dma_registers *dregs =
-               (struct sparc_dma_registers *) esp->dregs;
-       
-       int count = 500000;
-       while((dregs->cond_reg & DMA_PEND_READ) && (--count > 0)) 
-               udelay(1);
-       if(!count) {
-               printk("%s:%d timeout CSR %08lx\n", __FILE__, __LINE__, dregs->cond_reg);
-       }
-       dregs->cond_reg |= DMA_FIFO_STDRAIN;
-       
-       count = 500000;
-       while((dregs->cond_reg & DMA_FIFO_ISDRAIN) && (--count > 0)) 
-               udelay(1);
-       if(!count) {
-               printk("%s:%d timeout CSR %08lx\n", __FILE__, __LINE__, dregs->cond_reg);
-       }
+       return readb(esp->regs + (reg * 4UL));
 }
-static void dma_barrier(struct NCR_ESP *esp)
+
+static dma_addr_t sun3x_esp_map_single(struct esp *esp, void *buf,
+                                     size_t sz, int dir)
 {
-       struct sparc_dma_registers *dregs =
-               (struct sparc_dma_registers *) esp->dregs;
-       int count = 500000;
-  
-       while((dregs->cond_reg & DMA_PEND_READ) && (--count > 0))
-               udelay(1);
-       if(!count) {
-               printk("%s:%d timeout CSR %08lx\n", __FILE__, __LINE__, dregs->cond_reg);
-       }
-       dregs->cond_reg &= ~(DMA_ENABLE);
+       return dma_map_single(esp->dev, buf, sz, dir);
 }
 
-/* This uses various DMA csr fields and the fifo flags count value to
- * determine how many bytes were successfully sent/received by the ESP.
- */
-static int dma_bytes_sent(struct NCR_ESP *esp, int fifo_count)
+static int sun3x_esp_map_sg(struct esp *esp, struct scatterlist *sg,
+                                 int num_sg, int dir)
 {
-       struct sparc_dma_registers *dregs = 
-               (struct sparc_dma_registers *) esp->dregs;
-
-       int rval = dregs->st_addr - esp->esp_command_dvma;
-
-       return rval - fifo_count;
+       return dma_map_sg(esp->dev, sg, num_sg, dir);
 }
 
-static int dma_can_transfer(struct NCR_ESP *esp, Scsi_Cmnd *sp)
+static void sun3x_esp_unmap_single(struct esp *esp, dma_addr_t addr,
+                                 size_t sz, int dir)
 {
-       return sp->SCp.this_residual;
+       dma_unmap_single(esp->dev, addr, sz, dir);
 }
 
-static void dma_drain(struct NCR_ESP *esp)
+static void sun3x_esp_unmap_sg(struct esp *esp, struct scatterlist *sg,
+                             int num_sg, int dir)
 {
-       struct sparc_dma_registers *dregs =
-               (struct sparc_dma_registers *) esp->dregs;
-       int count = 500000;
-
-       if(dregs->cond_reg & DMA_FIFO_ISDRAIN) {
-               dregs->cond_reg |= DMA_FIFO_STDRAIN;
-               while((dregs->cond_reg & DMA_FIFO_ISDRAIN) && (--count > 0))
-                       udelay(1);
-               if(!count) {
-                       printk("%s:%d timeout CSR %08lx\n", __FILE__, __LINE__, dregs->cond_reg);
-               }
-
-       }
+       dma_unmap_sg(esp->dev, sg, num_sg, dir);
 }
 
-static void dma_invalidate(struct NCR_ESP *esp)
+static int sun3x_esp_irq_pending(struct esp *esp)
 {
-       struct sparc_dma_registers *dregs =
-               (struct sparc_dma_registers *) esp->dregs;
-
-       __u32 tmp;
-       int count = 500000;
-
-       while(((tmp = dregs->cond_reg) & DMA_PEND_READ) && (--count > 0)) 
-               udelay(1);
+       if (dma_read32(DMA_CSR) & (DMA_HNDL_INTR | DMA_HNDL_ERROR))
+               return 1;
+       return 0;
+}
 
-       if(!count) {
-               printk("%s:%d timeout CSR %08lx\n", __FILE__, __LINE__, dregs->cond_reg);
-       }
+static void sun3x_esp_reset_dma(struct esp *esp)
+{
+       u32 val;
 
-       dregs->cond_reg = tmp | DMA_FIFO_INV;
-       dregs->cond_reg &= ~DMA_FIFO_INV;
+       val = dma_read32(DMA_CSR);
+       dma_write32(val | DMA_RST_SCSI, DMA_CSR);
+       dma_write32(val & ~DMA_RST_SCSI, DMA_CSR);
 
+       /* Enable interrupts.  */
+       val = dma_read32(DMA_CSR);
+       dma_write32(val | DMA_INT_ENAB, DMA_CSR);
 }
 
-static void dma_dump_state(struct NCR_ESP *esp)
+static void sun3x_esp_dma_drain(struct esp *esp)
 {
-       struct sparc_dma_registers *dregs =
-               (struct sparc_dma_registers *) esp->dregs;
+       u32 csr;
+       int lim;
 
-       ESPLOG(("esp%d: dma -- cond_reg<%08lx> addr<%08lx>\n",
-               esp->esp_id, dregs->cond_reg, dregs->st_addr));
-}
+       csr = dma_read32(DMA_CSR);
+       if (!(csr & DMA_FIFO_ISDRAIN))
+               return;
 
-static void dma_init_read(struct NCR_ESP *esp, __u32 vaddress, int length)
-{
-       struct sparc_dma_registers *dregs = 
-               (struct sparc_dma_registers *) esp->dregs;
+       dma_write32(csr | DMA_FIFO_STDRAIN, DMA_CSR);
 
-       dregs->st_addr = vaddress;
-       dregs->cond_reg |= (DMA_ST_WRITE | DMA_ENABLE);
+       lim = 1000;
+       while (dma_read32(DMA_CSR) & DMA_FIFO_ISDRAIN) {
+               if (--lim == 0) {
+                       printk(KERN_ALERT PFX "esp%d: DMA will not drain!\n",
+                              esp->host->unique_id);
+                       break;
+               }
+               udelay(1);
+       }
 }
 
-static void dma_init_write(struct NCR_ESP *esp, __u32 vaddress, int length)
+static void sun3x_esp_dma_invalidate(struct esp *esp)
 {
-       struct sparc_dma_registers *dregs = 
-               (struct sparc_dma_registers *) esp->dregs;
-
-       /* Set up the DMA counters */
+       u32 val;
+       int lim;
+
+       lim = 1000;
+       while ((val = dma_read32(DMA_CSR)) & DMA_PEND_READ) {
+               if (--lim == 0) {
+                       printk(KERN_ALERT PFX "esp%d: DMA will not "
+                              "invalidate!\n", esp->host->unique_id);
+                       break;
+               }
+               udelay(1);
+       }
 
-       dregs->st_addr = vaddress;
-       dregs->cond_reg = ((dregs->cond_reg & ~(DMA_ST_WRITE)) | DMA_ENABLE);
+       val &= ~(DMA_ENABLE | DMA_ST_WRITE | DMA_BCNT_ENAB);
+       val |= DMA_FIFO_INV;
+       dma_write32(val, DMA_CSR);
+       val &= ~DMA_FIFO_INV;
+       dma_write32(val, DMA_CSR);
 }
 
-static void dma_ints_off(struct NCR_ESP *esp)
+static void sun3x_esp_send_dma_cmd(struct esp *esp, u32 addr, u32 esp_count,
+                                 u32 dma_count, int write, u8 cmd)
 {
-       DMA_INTSOFF((struct sparc_dma_registers *) esp->dregs);
+       u32 csr;
+
+       BUG_ON(!(cmd & ESP_CMD_DMA));
+
+       sun3x_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
+       sun3x_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
+       csr = dma_read32(DMA_CSR);
+       csr |= DMA_ENABLE;
+       if (write)
+               csr |= DMA_ST_WRITE;
+       else
+               csr &= ~DMA_ST_WRITE;
+       dma_write32(csr, DMA_CSR);
+       dma_write32(addr, DMA_ADDR);
+
+       scsi_esp_cmd(esp, cmd);
 }
 
-static void dma_ints_on(struct NCR_ESP *esp)
+static int sun3x_esp_dma_error(struct esp *esp)
 {
-       DMA_INTSON((struct sparc_dma_registers *) esp->dregs);
-}
+       u32 csr = dma_read32(DMA_CSR);
 
-static int dma_irq_p(struct NCR_ESP *esp)
-{
-       return DMA_IRQ_P((struct sparc_dma_registers *) esp->dregs);
+       if (csr & DMA_HNDL_ERROR)
+               return 1;
+
+       return 0;
 }
 
-static void dma_poll(struct NCR_ESP *esp, unsigned char *vaddr)
+static const struct esp_driver_ops sun3x_esp_ops = {
+       .esp_write8     =       sun3x_esp_write8,
+       .esp_read8      =       sun3x_esp_read8,
+       .map_single     =       sun3x_esp_map_single,
+       .map_sg         =       sun3x_esp_map_sg,
+       .unmap_single   =       sun3x_esp_unmap_single,
+       .unmap_sg       =       sun3x_esp_unmap_sg,
+       .irq_pending    =       sun3x_esp_irq_pending,
+       .reset_dma      =       sun3x_esp_reset_dma,
+       .dma_drain      =       sun3x_esp_dma_drain,
+       .dma_invalidate =       sun3x_esp_dma_invalidate,
+       .send_dma_cmd   =       sun3x_esp_send_dma_cmd,
+       .dma_error      =       sun3x_esp_dma_error,
+};
+
+static int __devinit esp_sun3x_probe(struct platform_device *dev)
 {
-       int count = 50;
-       dma_do_drain(esp);
+       struct scsi_host_template *tpnt = &scsi_esp_template;
+       struct Scsi_Host *host;
+       struct esp *esp;
+       struct resource *res;
+       int err = -ENOMEM;
 
-       /* Wait till the first bits settle. */
-       while((*(volatile unsigned char *)vaddr == 0xff) && (--count > 0))
-               udelay(1);
+       host = scsi_host_alloc(tpnt, sizeof(struct esp));
+       if (!host)
+               goto fail;
 
-       if(!count) {
-//             printk("%s:%d timeout expire (data %02x)\n", __FILE__, __LINE__,
-//                    esp_read(esp->eregs->esp_fdata));
-               //mach_halt();
-               vaddr[0] = esp_read(esp->eregs->esp_fdata);
-               vaddr[1] = esp_read(esp->eregs->esp_fdata);
-       }
+       host->max_id = 8;
+       esp = shost_priv(host);
 
-}      
+       esp->host = host;
+       esp->dev = dev;
+       esp->ops = &sun3x_esp_ops;
 
-static int dma_ports_p(struct NCR_ESP *esp)
-{
-       return (((struct sparc_dma_registers *) esp->dregs)->cond_reg 
-                       & DMA_INT_ENAB);
-}
+       res = platform_get_resource(dev, IORESOURCE_MEM, 0);
+       if (!res && !res->start)
+               goto fail_unlink;
 
-/* Resetting various pieces of the ESP scsi driver chipset/buses. */
-static void dma_reset(struct NCR_ESP *esp)
-{
-       struct sparc_dma_registers *dregs =
-               (struct sparc_dma_registers *)esp->dregs;
+       esp->regs = ioremap_nocache(res->start, 0x20);
+       if (!esp->regs)
+               goto fail_unmap_regs;
 
-       /* Punt the DVMA into a known state. */
-       dregs->cond_reg |= DMA_RST_SCSI;
-       dregs->cond_reg &= ~(DMA_RST_SCSI);
-       DMA_INTSON(dregs);
-}
+       res = platform_get_resource(dev, IORESOURCE_MEM, 1);
+       if (!res && !res->start)
+               goto fail_unmap_regs;
 
-static void dma_setup(struct NCR_ESP *esp, __u32 addr, int count, int write)
-{
-       struct sparc_dma_registers *dregs = 
-               (struct sparc_dma_registers *) esp->dregs;
-       unsigned long nreg = dregs->cond_reg;
+       esp->dma_regs = ioremap_nocache(res->start, 0x10);
 
-//     printk("dma_setup %c addr %08x cnt %08x\n",
-//            write ? 'W' : 'R', addr, count);
+       esp->command_block = dma_alloc_coherent(esp->dev, 16,
+                                               &esp->command_block_dma,
+                                               GFP_KERNEL);
+       if (!esp->command_block)
+               goto fail_unmap_regs_dma;
 
-       dma_do_drain(esp);
+       host->irq = platform_get_irq(dev, 0);
+       err = request_irq(host->irq, scsi_esp_intr, IRQF_SHARED,
+                         "SUN3X ESP", esp);
+       if (err < 0)
+               goto fail_unmap_command_block;
 
-       if(write)
-               nreg |= DMA_ST_WRITE;
-       else {
-               nreg &= ~(DMA_ST_WRITE);
-       }
-               
-       nreg |= DMA_ENABLE;
-       dregs->cond_reg = nreg;
-       dregs->st_addr = addr;
-}
+       esp->scsi_id = 7;
+       esp->host->this_id = esp->scsi_id;
+       esp->scsi_id_mask = (1 << esp->scsi_id);
+       esp->cfreq = 20000000;
 
-static void dma_mmu_get_scsi_one (struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-    sp->SCp.have_data_in = dvma_map((unsigned long)sp->SCp.buffer,
-                                      sp->SCp.this_residual);
-    sp->SCp.ptr = (char *)((unsigned long)sp->SCp.have_data_in);
+       dev_set_drvdata(&dev->dev, esp);
+
+       err = scsi_esp_register(esp, &dev->dev);
+       if (err)
+               goto fail_free_irq;
+
+       return 0;
+
+fail_free_irq:
+       free_irq(host->irq, esp);
+fail_unmap_command_block:
+       dma_free_coherent(esp->dev, 16,
+                         esp->command_block,
+                         esp->command_block_dma);
+fail_unmap_regs_dma:
+       iounmap(esp->dma_regs);
+fail_unmap_regs:
+       iounmap(esp->regs);
+fail_unlink:
+       scsi_host_put(host);
+fail:
+       return err;
 }
 
-static void dma_mmu_get_scsi_sgl (struct NCR_ESP *esp, Scsi_Cmnd *sp)
+static int __devexit esp_sun3x_remove(struct platform_device *dev)
 {
-    int sz = sp->SCp.buffers_residual;
-    struct scatterlist *sg = sp->SCp.buffer;
-
-    while (sz >= 0) {
-           sg[sz].dma_address = dvma_map((unsigned long)sg_virt(&sg[sz]),
-                                         sg[sz].length);
-           sz--;
-    }
-    sp->SCp.ptr=(char *)((unsigned long)sp->SCp.buffer->dma_address);
-}
+       struct esp *esp = dev_get_drvdata(&dev->dev);
+       unsigned int irq = esp->host->irq;
+       u32 val;
 
-static void dma_mmu_release_scsi_one (struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-    dvma_unmap((char *)sp->SCp.have_data_in);
-}
+       scsi_esp_unregister(esp);
 
-static void dma_mmu_release_scsi_sgl (struct NCR_ESP *esp, Scsi_Cmnd *sp)
-{
-    int sz = sp->use_sg - 1;
-    struct scatterlist *sg = (struct scatterlist *)sp->request_buffer;
-                        
-    while(sz >= 0) {
-        dvma_unmap((char *)sg[sz].dma_address);
-        sz--;
-    }
-}
+       /* Disable interrupts.  */
+       val = dma_read32(DMA_CSR);
+       dma_write32(val & ~DMA_INT_ENAB, DMA_CSR);
 
-static void dma_advance_sg (Scsi_Cmnd *sp)
-{
-    sp->SCp.ptr = (char *)((unsigned long)sp->SCp.buffer->dma_address);
-}
+       free_irq(irq, esp);
+       dma_free_coherent(esp->dev, 16,
+                         esp->command_block,
+                         esp->command_block_dma);
 
-static int sun3x_esp_release(struct Scsi_Host *instance)
-{
-       /* this code does not support being compiled as a module */      
-       return 1;
+       scsi_host_put(esp->host);
 
+       return 0;
 }
 
-static struct scsi_host_template driver_template = {
-       .proc_name              = "sun3x_esp",
-       .proc_info              = &esp_proc_info,
-       .name                   = "Sun ESP 100/100a/200",
-       .detect                 = sun3x_esp_detect,
-       .release                = sun3x_esp_release,
-       .slave_alloc            = esp_slave_alloc,
-       .slave_destroy          = esp_slave_destroy,
-       .info                   = esp_info,
-       .queuecommand           = esp_queue,
-       .eh_abort_handler       = esp_abort,
-       .eh_bus_reset_handler   = esp_reset,
-       .can_queue              = 7,
-       .this_id                = 7,
-       .sg_tablesize           = SG_ALL,
-       .cmd_per_lun            = 1,
-       .use_clustering         = DISABLE_CLUSTERING,
+static struct platform_driver esp_sun3x_driver = {
+       .probe          = esp_sun3x_probe,
+       .remove         = __devexit_p(esp_sun3x_remove),
+       .driver = {
+               .name   = "sun3x_esp",
+       },
 };
 
+static int __init sun3x_esp_init(void)
+{
+       return platform_driver_register(&esp_sun3x_driver);
+}
 
-#include "scsi_module.c"
+static void __exit sun3x_esp_exit(void)
+{
+       platform_driver_unregister(&esp_sun3x_driver);
+}
 
+MODULE_DESCRIPTION("Sun3x ESP SCSI driver");
+MODULE_AUTHOR("Thomas Bogendoerfer (tsbogend@alpha.franken.de)");
 MODULE_LICENSE("GPL");
+MODULE_VERSION(DRV_VERSION);
+
+module_init(sun3x_esp_init);
+module_exit(sun3x_esp_exit);
index 254bdaeb35ff69d970fffd76533e944fd60577b2..35142b5341b5358d045b216dabaf3d2fea618dc7 100644 (file)
@@ -3842,7 +3842,7 @@ int sym_compute_residual(struct sym_hcb *np, struct sym_ccb *cp)
        if (cp->startp == cp->phys.head.lastp ||
            sym_evaluate_dp(np, cp, scr_to_cpu(cp->phys.head.lastp),
                            &dp_ofs) < 0) {
-               return cp->data_len;
+               return cp->data_len - cp->odd_byte_adjustment;
        }
 
        /*
index 662c00451be443556e32f1bbd930a4c6dcd811bc..58d7eee4fe81133779d066b9a02f119273b027d8 100644 (file)
@@ -1216,7 +1216,7 @@ static void scsi_to_dev_dir(unsigned int i, unsigned int j) {
       cpp->xdir = DTD_IN;
       return;
       }
-   else if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {
+   else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
       cpp->xdir = DTD_OUT;
       return;
       }
index b8a4bd94f51d5501cbf813d38f75147a9e180ab9..77f7a7f0646e00ce1bbfb0b2fb439c283df06887 100644 (file)
@@ -305,7 +305,7 @@ static inline int map_8250_out_reg(struct uart_8250_port *up, int offset)
        return au_io_out_map[offset];
 }
 
-#elif defined (CONFIG_SERIAL_8250_RM9K)
+#elif defined(CONFIG_SERIAL_8250_RM9K)
 
 static const u8
        regmap_in[8] = {
@@ -475,7 +475,7 @@ static inline void _serial_dl_write(struct uart_8250_port *up, int value)
        serial_outp(up, UART_DLM, value >> 8 & 0xff);
 }
 
-#if defined (CONFIG_SERIAL_8250_AU1X00)
+#if defined(CONFIG_SERIAL_8250_AU1X00)
 /* Au1x00 haven't got a standard divisor latch */
 static int serial_dl_read(struct uart_8250_port *up)
 {
@@ -492,7 +492,7 @@ static void serial_dl_write(struct uart_8250_port *up, int value)
        else
                _serial_dl_write(up, value);
 }
-#elif defined (CONFIG_SERIAL_8250_RM9K)
+#elif defined(CONFIG_SERIAL_8250_RM9K)
 static int serial_dl_read(struct uart_8250_port *up)
 {
        return  (up->port.iotype == UPIO_RM9000) ?
@@ -1185,8 +1185,8 @@ static void autoconfig_irq(struct uart_8250_port *up)
 
        irqs = probe_irq_on();
        serial_outp(up, UART_MCR, 0);
-       udelay (10);
-       if (up->port.flags & UPF_FOURPORT)  {
+       udelay(10);
+       if (up->port.flags & UPF_FOURPORT) {
                serial_outp(up, UART_MCR,
                            UART_MCR_DTR | UART_MCR_RTS);
        } else {
@@ -1199,7 +1199,7 @@ static void autoconfig_irq(struct uart_8250_port *up)
        (void)serial_inp(up, UART_IIR);
        (void)serial_inp(up, UART_MSR);
        serial_outp(up, UART_TX, 0xFF);
-       udelay (20);
+       udelay(20);
        irq = probe_irq_off(irqs);
 
        serial_outp(up, UART_MCR, save_mcr);
@@ -1343,7 +1343,7 @@ receive_chars(struct uart_8250_port *up, unsigned int *status)
 
                uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag);
 
-       ignore_char:
+ignore_char:
                lsr = serial_inp(up, UART_LSR);
        } while ((lsr & UART_LSR_DR) && (max_count-- > 0));
        spin_unlock(&up->port.lock);
@@ -1633,7 +1633,8 @@ static void serial8250_backup_timeout(unsigned long data)
                serial_out(up, UART_IER, ier);
 
        /* Standard timer interval plus 0.2s to keep the port running */
-       mod_timer(&up->timer, jiffies + poll_timeout(up->port.timeout) + HZ/5);
+       mod_timer(&up->timer,
+               jiffies + poll_timeout(up->port.timeout) + HZ / 5);
 }
 
 static unsigned int serial8250_tx_empty(struct uart_port *port)
@@ -1844,7 +1845,7 @@ static int serial8250_startup(struct uart_port *port)
                        up->timer.function = serial8250_backup_timeout;
                        up->timer.data = (unsigned long)up;
                        mod_timer(&up->timer, jiffies +
-                                 poll_timeout(up->port.timeout) + HZ/5);
+                               poll_timeout(up->port.timeout) + HZ / 5);
                }
        }
 
@@ -2173,6 +2174,7 @@ serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
        }
        serial8250_set_mctrl(&up->port, up->port.mctrl);
        spin_unlock_irqrestore(&up->port.lock, flags);
+       tty_termios_encode_baud_rate(termios, baud, baud);
 }
 
 static void
index 1f16de719962829e181f4860040a83a6094dcfa7..38776e8b064b07f57f8815709efd70defeb9d4ca 100644 (file)
@@ -82,7 +82,8 @@ static void __init serial_putc(struct uart_port *port, int c)
        serial_out(port, UART_TX, c);
 }
 
-static void __init early_serial8250_write(struct console *console, const char *s, unsigned int count)
+static void __init early_serial8250_write(struct console *console,
+                                       const char *s, unsigned int count)
 {
        struct uart_port *port = &early_device.port;
        unsigned int ier;
@@ -132,7 +133,8 @@ static void __init init_port(struct early_serial8250_device *device)
        serial_out(port, UART_LCR, c & ~UART_LCR_DLAB);
 }
 
-static int __init parse_options(struct early_serial8250_device *device, char *options)
+static int __init parse_options(struct early_serial8250_device *device,
+                                                               char *options)
 {
        struct uart_port *port = &device->port;
        int mmio, length;
@@ -145,8 +147,10 @@ static int __init parse_options(struct early_serial8250_device *device, char *op
                port->iotype = UPIO_MEM;
                port->mapbase = simple_strtoul(options + 5, &options, 0);
 #ifdef CONFIG_FIX_EARLYCON_MEM
-               set_fixmap_nocache(FIX_EARLYCON_MEM_BASE, port->mapbase & PAGE_MASK);
-               port->membase = (void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE);
+               set_fixmap_nocache(FIX_EARLYCON_MEM_BASE,
+                                       port->mapbase & PAGE_MASK);
+               port->membase =
+                       (void __iomem *)__fix_to_virt(FIX_EARLYCON_MEM_BASE);
                port->membase += port->mapbase & ~PAGE_MASK;
 #else
                port->membase = ioremap(port->mapbase, 64);
@@ -165,7 +169,8 @@ static int __init parse_options(struct early_serial8250_device *device, char *op
        } else
                return -EINVAL;
 
-       if ((options = strchr(options, ','))) {
+       options = strchr(options, ',');
+       if (options) {
                options++;
                device->baud = simple_strtoul(options, NULL, 0);
                length = min(strcspn(options, " "), sizeof(device->options));
@@ -179,7 +184,7 @@ static int __init parse_options(struct early_serial8250_device *device, char *op
        printk(KERN_INFO "Early serial console at %s 0x%llx (options '%s')\n",
                mmio ? "MMIO" : "I/O port",
                mmio ? (unsigned long long) port->mapbase
-                    : (unsigned long long) port->iobase,
+                    : (unsigned long long) port->iobase,
                device->options);
        return 0;
 }
@@ -199,7 +204,8 @@ static int __init early_serial8250_setup(char *options)
        if (device->port.membase || device->port.iobase)
                return 0;
 
-       if ((err = parse_options(device, options)) < 0)
+       err = parse_options(device, options);
+       if (err < 0)
                return err;
 
        init_port(device);
@@ -219,7 +225,8 @@ int __init setup_early_serial8250_console(char *cmdline)
        }
 
        options = strchr(cmdline, ',') + 1;
-       if ((err = early_serial8250_setup(options)) < 0)
+       err = early_serial8250_setup(options);
+       if (err < 0)
                return err;
 
        register_console(&early_serial8250_console);
index c5d0addfda4f9404d97ffb9f39c46b9f5e79a7c8..4eb7437a404a5fa5e4c4d8087d040a55891a2eb8 100644 (file)
@@ -25,8 +25,7 @@
 
 #include "8250.h"
 
-static int __init 
-serial_init_chip(struct parisc_device *dev)
+static int __init serial_init_chip(struct parisc_device *dev)
 {
        struct uart_port port;
        unsigned long address;
@@ -38,18 +37,17 @@ serial_init_chip(struct parisc_device *dev)
                 * what we have here is a missing parent device, so tell
                 * the user what they're missing.
                 */
-               if (parisc_parent(dev)->id.hw_type != HPHW_IOA) {
-                       printk(KERN_INFO "Serial: device 0x%lx not configured.\n"
+               if (parisc_parent(dev)->id.hw_type != HPHW_IOA)
+                       printk(KERN_INFO
+                               "Serial: device 0x%lx not configured.\n"
                                "Enable support for Wax, Lasi, Asp or Dino.\n",
                                dev->hpa.start);
-               }
                return -ENODEV;
        }
 
        address = dev->hpa.start;
-       if (dev->id.sversion != 0x8d) {
+       if (dev->id.sversion != 0x8d)
                address += 0x800;
-       }
 
        memset(&port, 0, sizeof(port));
        port.iotype     = UPIO_MEM;
@@ -63,11 +61,12 @@ serial_init_chip(struct parisc_device *dev)
 
        err = serial8250_register_port(&port);
        if (err < 0) {
-               printk(KERN_WARNING "serial8250_register_port returned error %d\n", err);
+               printk(KERN_WARNING
+                       "serial8250_register_port returned error %d\n", err);
                iounmap(port.membase);
                return err;
        }
-        
+
        return 0;
 }
 
index 2cf0953fe0ecb6f29e8180305afc68af95a89e27..0e1410f2c03394362f25a07b6ce27981dff38ab2 100644 (file)
@@ -36,7 +36,7 @@ static struct hp300_port *hp300_ports;
 #ifdef CONFIG_HPDCA
 
 static int __devinit hpdca_init_one(struct dio_dev *d,
-                                const struct dio_device_id *ent);
+                                       const struct dio_device_id *ent);
 static void __devexit hpdca_remove_one(struct dio_dev *d);
 
 static struct dio_device_id hpdca_dio_tbl[] = {
@@ -85,7 +85,7 @@ extern int hp300_uart_scode;
 
 #ifdef CONFIG_SERIAL_8250_CONSOLE
 /*
- * Parse the bootinfo to find descriptions for headless console and 
+ * Parse the bootinfo to find descriptions for headless console and
  * debug serial ports and register them with the 8250 driver.
  * This function should be called before serial_console_init() is called
  * to make sure the serial console will be available for use. IA-64 kernel
@@ -126,13 +126,11 @@ int __init hp300_setup_serial_console(void)
                printk(KERN_WARNING "Serial console is APCI but support is disabled (CONFIG_HPAPCI)!\n");
                return 0;
 #endif
-       }
-       else {
+       } else {
 #ifdef CONFIG_HPDCA
                unsigned long pa = dio_scodetophysaddr(scode);
-               if (!pa) {
+               if (!pa)
                        return 0;
-               }
 
                printk(KERN_INFO "Serial console is HP DCA at select code %d\n", scode);
 
@@ -145,26 +143,23 @@ int __init hp300_setup_serial_console(void)
                /* Enable board-interrupts */
                out_8(pa + DIO_VIRADDRBASE + DCA_IC, DCA_IC_IE);
 
-               if (DIO_ID(pa + DIO_VIRADDRBASE) & 0x80) {
+               if (DIO_ID(pa + DIO_VIRADDRBASE) & 0x80)
                        add_preferred_console("ttyS", port.line, "9600n8");
-               }
 #else
                printk(KERN_WARNING "Serial console is DCA but support is disabled (CONFIG_HPDCA)!\n");
                return 0;
 #endif
        }
 
-       if (early_serial_setup(&port) < 0) {
+       if (early_serial_setup(&port) < 0)
                printk(KERN_WARNING "hp300_setup_serial_console(): early_serial_setup() failed.\n");
-       }
-
        return 0;
 }
 #endif /* CONFIG_SERIAL_8250_CONSOLE */
 
 #ifdef CONFIG_HPDCA
 static int __devinit hpdca_init_one(struct dio_dev *d,
-                                const struct dio_device_id *ent)
+                               const struct dio_device_id *ent)
 {
        struct uart_port port;
        int line;
@@ -210,7 +205,7 @@ static int __devinit hpdca_init_one(struct dio_dev *d,
 
 static int __init hp300_8250_init(void)
 {
-       static int called = 0;
+       static int called;
 #ifdef CONFIG_HPAPCI
        int line;
        unsigned long base;
@@ -239,13 +234,12 @@ static int __init hp300_8250_init(void)
         * Port 1 is either the console or the DCA.
         */
        for (i = 1; i < 4; i++) {
-               /* Port 1 is the console on a 425e, on other machines it's mapped to
-                * DCA.
+               /* Port 1 is the console on a 425e, on other machines it's
+                * mapped to DCA.
                 */
 #ifdef CONFIG_SERIAL_8250_CONSOLE
-               if (i == 1) {
+               if (i == 1)
                        continue;
-               }
 #endif
 
                /* Create new serial device */
@@ -259,7 +253,8 @@ static int __init hp300_8250_init(void)
 
                /* Memory mapped I/O */
                uport.iotype = UPIO_MEM;
-               uport.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF;
+               uport.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ \
+                             | UPF_BOOT_AUTOCONF;
                /* XXX - no interrupt support yet */
                uport.irq = 0;
                uport.uartclk = HPAPCI_BAUD_BASE * 16;
@@ -270,8 +265,8 @@ static int __init hp300_8250_init(void)
                line = serial8250_register_port(&uport);
 
                if (line < 0) {
-                       printk(KERN_NOTICE "8250_hp300: register_serial() APCI %d"
-                              " irq %d failed\n", i, uport.irq);
+                       printk(KERN_NOTICE "8250_hp300: register_serial() APCI"
+                              " %d irq %d failed\n", i, uport.irq);
                        kfree(port);
                        continue;
                }
index daf569cd3c8fcb19150069a548b06c83b58c3cf3..7609150e7d5eeec1da05fed57c97fac82d60ce9f 100644 (file)
        }
 
 static struct plat_serial8250_port hub6_data[] = {
-       HUB6(0,0),
-       HUB6(0,1),
-       HUB6(0,2),
-       HUB6(0,3),
-       HUB6(0,4),
-       HUB6(0,5),
-       HUB6(1,0),
-       HUB6(1,1),
-       HUB6(1,2),
-       HUB6(1,3),
-       HUB6(1,4),
-       HUB6(1,5),
+       HUB6(0, 0),
+       HUB6(0, 1),
+       HUB6(0, 2),
+       HUB6(0, 3),
+       HUB6(0, 4),
+       HUB6(0, 5),
+       HUB6(1, 0),
+       HUB6(1, 1),
+       HUB6(1, 2),
+       HUB6(1, 3),
+       HUB6(1, 4),
+       HUB6(1, 5),
        { },
 };
 
index 0a4ac2b6eb5a2a8d5c0a25da3a1a0bdf40c4f317..a8bec498cad6f8dddd323dd7a3df9b8e7b1a65ac 100644 (file)
@@ -140,7 +140,7 @@ afavlab_setup(struct serial_private *priv, struct pciserial_board *board,
              struct uart_port *port, int idx)
 {
        unsigned int bar, offset = board->first_offset;
-       
+
        bar = FL_GET_BASE(board->flags);
        if (idx < 4)
                bar += idx;
@@ -227,8 +227,8 @@ static int pci_inteli960ni_init(struct pci_dev *dev)
                return -ENODEV;
 
        /* is firmware started? */
-       pci_read_config_dword(dev, 0x44, (void*) &oldval); 
-       if (oldval == 0x00001000L) { /* RESET value */ 
+       pci_read_config_dword(dev, 0x44, (void *)&oldval);
+       if (oldval == 0x00001000L) { /* RESET value */
                printk(KERN_DEBUG "Local i960 firmware missing");
                return -ENODEV;
        }
@@ -253,11 +253,11 @@ static int pci_plx9050_init(struct pci_dev *dev)
 
        irq_config = 0x41;
        if (dev->vendor == PCI_VENDOR_ID_PANACOM ||
-           dev->subsystem_vendor == PCI_SUBVENDOR_ID_EXSYS) {
+           dev->subsystem_vendor == PCI_SUBVENDOR_ID_EXSYS)
                irq_config = 0x43;
-       }
+
        if ((dev->vendor == PCI_VENDOR_ID_PLX) &&
-           (dev->device == PCI_DEVICE_ID_PLX_ROMULUS)) {
+           (dev->device == PCI_DEVICE_ID_PLX_ROMULUS))
                /*
                 * As the megawolf cards have the int pins active
                 * high, and have 2 UART chips, both ints must be
@@ -267,8 +267,6 @@ static int pci_plx9050_init(struct pci_dev *dev)
                 * deep FIFOs
                 */
                irq_config = 0x5b;
-       }
-
        /*
         * enable/disable interrupts
         */
@@ -343,14 +341,14 @@ static int sbs_init(struct pci_dev *dev)
 {
        u8 __iomem *p;
 
-       p = ioremap(pci_resource_start(dev, 0),pci_resource_len(dev,0));
+       p = ioremap(pci_resource_start(dev, 0), pci_resource_len(dev, 0));
 
        if (p == NULL)
                return -ENOMEM;
        /* Set bit-4 Control Register (UART RESET) in to reset the uarts */
-       writeb(0x10,p + OCT_REG_CR_OFF);
+       writeb(0x10, p + OCT_REG_CR_OFF);
        udelay(50);
-       writeb(0x0,p + OCT_REG_CR_OFF);
+       writeb(0x0, p + OCT_REG_CR_OFF);
 
        /* Set bit-2 (INTENABLE) of Control Register */
        writeb(0x4, p + OCT_REG_CR_OFF);
@@ -367,10 +365,10 @@ static void __devexit sbs_exit(struct pci_dev *dev)
 {
        u8 __iomem *p;
 
-       p = ioremap(pci_resource_start(dev, 0),pci_resource_len(dev,0));
-       if (p != NULL) {
+       p = ioremap(pci_resource_start(dev, 0), pci_resource_len(dev, 0));
+       /* FIXME: What if resource_len < OCT_REG_CR_OFF */
+       if (p != NULL)
                writeb(0, p + OCT_REG_CR_OFF);
-       }
        iounmap(p);
 }
 
@@ -386,7 +384,7 @@ static void __devexit sbs_exit(struct pci_dev *dev)
  * with other OSes (like M$ DOS).
  *
  *  SIIG support added by Andrey Panin <pazke@donpac.ru>, 10/1999
- * 
+ *
  * There is two family of SIIG serial cards with different PCI
  * interface chip and different configuration methods:
  *     - 10x cards have control registers in IO and/or memory space;
@@ -489,21 +487,21 @@ static const unsigned short timedia_single_port[] = {
 
 static const unsigned short timedia_dual_port[] = {
        0x0002, 0x4036, 0x4037, 0x4038, 0x4078, 0x4079, 0x4085,
-       0x4088, 0x4089, 0x5037, 0x5078, 0x5079, 0x5085, 0x6079, 
-       0x7079, 0x8079, 0x8137, 0x8138, 0x8237, 0x8238, 0x9079, 
+       0x4088, 0x4089, 0x5037, 0x5078, 0x5079, 0x5085, 0x6079,
+       0x7079, 0x8079, 0x8137, 0x8138, 0x8237, 0x8238, 0x9079,
        0x9137, 0x9138, 0x9237, 0x9238, 0xA079, 0xB079, 0xC079,
        0xD079, 0
 };
 
 static const unsigned short timedia_quad_port[] = {
-       0x4055, 0x4056, 0x4095, 0x4096, 0x5056, 0x8156, 0x8157, 
-       0x8256, 0x8257, 0x9056, 0x9156, 0x9157, 0x9158, 0x9159, 
+       0x4055, 0x4056, 0x4095, 0x4096, 0x5056, 0x8156, 0x8157,
+       0x8256, 0x8257, 0x9056, 0x9156, 0x9157, 0x9158, 0x9159,
        0x9256, 0x9257, 0xA056, 0xA157, 0xA158, 0xA159, 0xB056,
        0xB157, 0
 };
 
 static const unsigned short timedia_eight_port[] = {
-       0x4065, 0x4066, 0x5065, 0x5066, 0x8166, 0x9066, 0x9166, 
+       0x4065, 0x4066, 0x5065, 0x5066, 0x8166, 0x9066, 0x9166,
        0x9167, 0x9168, 0xA066, 0xA167, 0xA168, 0
 };
 
@@ -656,7 +654,8 @@ static int pci_ite887x_init(struct pci_dev *dev)
                                ITE_887x_POSIO_ENABLE | ITE_887x_POSIO_SPEED |
                                ITE_887x_POSIO_IOSIZE_32 | inta_addr[i]);
                        /* write INTCBAR - ioport */
-                       pci_write_config_dword(dev, ITE_887x_INTCBAR, inta_addr[i]);
+                       pci_write_config_dword(dev, ITE_887x_INTCBAR,
+                                                               inta_addr[i]);
                        ret = inb(inta_addr[i]);
                        if (ret != 0xff) {
                                /* ioport connected */
@@ -755,7 +754,7 @@ pci_default_setup(struct serial_private *priv, struct pciserial_board *board,
 
        if (board->flags & FL_REGION_SZ_CAP && idx >= maxnr)
                return 1;
-                       
+
        return setup_port(priv, port, bar, offset, board->reg_shift);
 }
 
@@ -843,7 +842,7 @@ static struct pci_serial_quirk pci_serial_quirks[] = {
                .init           = pci_plx9050_init,
                .setup          = pci_default_setup,
                .exit           = __devexit_p(pci_plx9050_exit),
-       },              
+       },
        {
                .vendor         = PCI_VENDOR_ID_PANACOM,
                .device         = PCI_DEVICE_ID_PANACOM_DUALMODEM,
@@ -1032,7 +1031,7 @@ static struct pci_serial_quirk *find_quirk(struct pci_dev *dev)
                    quirk_id_matches(quirk->device, dev->device) &&
                    quirk_id_matches(quirk->subvendor, dev->subsystem_vendor) &&
                    quirk_id_matches(quirk->subdevice, dev->subsystem_device))
-                       break;
+                       break;
        return quirk;
 }
 
@@ -1711,7 +1710,7 @@ static struct pciserial_board pci_boards[] __devinitdata = {
 };
 
 static const struct pci_device_id softmodem_blacklist[] = {
-       { PCI_VDEVICE ( AL, 0x5457 ), }, /* ALi Corporation M5457 AC'97 Modem */
+       { PCI_VDEVICE(AL, 0x5457), }, /* ALi Corporation M5457 AC'97 Modem */
 };
 
 /*
@@ -1724,13 +1723,13 @@ serial_pci_guess_board(struct pci_dev *dev, struct pciserial_board *board)
 {
        const struct pci_device_id *blacklist;
        int num_iomem, num_port, first_port = -1, i;
-       
+
        /*
         * If it is not a communications device or the programming
         * interface is greater than 6, give up.
         *
         * (Should we try to make guesses for multiport serial devices
-        * later?) 
+        * later?)
         */
        if ((((dev->class >> 8) != PCI_CLASS_COMMUNICATION_SERIAL) &&
             ((dev->class >> 8) != PCI_CLASS_COMMUNICATION_MODEM)) ||
@@ -1863,25 +1862,23 @@ pciserial_init_ports(struct pci_dev *dev, struct pciserial_board *board)
                        break;
 
 #ifdef SERIAL_DEBUG_PCI
-               printk("Setup PCI port: port %x, irq %d, type %d\n",
+               printk(KERN_DEBUG "Setup PCI port: port %x, irq %d, type %d\n",
                       serial_port.iobase, serial_port.irq, serial_port.iotype);
 #endif
-               
+
                priv->line[i] = serial8250_register_port(&serial_port);
                if (priv->line[i] < 0) {
                        printk(KERN_WARNING "Couldn't register serial port %s: %d\n", pci_name(dev), priv->line[i]);
                        break;
                }
        }
-
        priv->nr = i;
-
        return priv;
 
- err_deinit:
+err_deinit:
        if (quirk->exit)
                quirk->exit(dev);
- err_out:
+err_out:
        return priv;
 }
 EXPORT_SYMBOL_GPL(pciserial_init_ports);
@@ -2171,22 +2168,22 @@ static struct pci_device_id serial_pci_tbl[] = {
                pbn_b0_8_1843200_200 },
 
        {       PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_U530,
-               PCI_ANY_ID, PCI_ANY_ID, 0, 0, 
+               PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_b2_bt_1_115200 },
        {       PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM2,
-               PCI_ANY_ID, PCI_ANY_ID, 0, 0, 
+               PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_b2_bt_2_115200 },
        {       PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM422,
-               PCI_ANY_ID, PCI_ANY_ID, 0, 0, 
+               PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_b2_bt_4_115200 },
        {       PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM232,
-               PCI_ANY_ID, PCI_ANY_ID, 0, 0, 
+               PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_b2_bt_2_115200 },
        {       PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_COMM4,
-               PCI_ANY_ID, PCI_ANY_ID, 0, 0, 
+               PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_b2_bt_4_115200 },
        {       PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_COMM8,
-               PCI_ANY_ID, PCI_ANY_ID, 0, 0, 
+               PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_b2_8_115200 },
        {       PCI_VENDOR_ID_SEALEVEL, PCI_DEVICE_ID_SEALEVEL_UCOMM8,
                PCI_ANY_ID, PCI_ANY_ID, 0, 0,
@@ -2201,11 +2198,11 @@ static struct pci_device_id serial_pci_tbl[] = {
        /*
         * VScom SPCOM800, from sl@s.pl
         */
-       {       PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_SPCOM800, 
-               PCI_ANY_ID, PCI_ANY_ID, 0, 0, 
+       {       PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_SPCOM800,
+               PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_b2_8_921600 },
        {       PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_1077,
-               PCI_ANY_ID, PCI_ANY_ID, 0, 0, 
+               PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_b2_4_921600 },
        {       PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
                PCI_SUBVENDOR_ID_KEYSPAN,
@@ -2223,27 +2220,27 @@ static struct pci_device_id serial_pci_tbl[] = {
                pbn_b2_4_115200 },
        {       PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
                PCI_SUBVENDOR_ID_CHASE_PCIFAST,
-               PCI_SUBDEVICE_ID_CHASE_PCIFAST4, 0, 0, 
+               PCI_SUBDEVICE_ID_CHASE_PCIFAST4, 0, 0,
                pbn_b2_4_460800 },
        {       PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
                PCI_SUBVENDOR_ID_CHASE_PCIFAST,
-               PCI_SUBDEVICE_ID_CHASE_PCIFAST8, 0, 0, 
+               PCI_SUBDEVICE_ID_CHASE_PCIFAST8, 0, 0,
                pbn_b2_8_460800 },
        {       PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
                PCI_SUBVENDOR_ID_CHASE_PCIFAST,
-               PCI_SUBDEVICE_ID_CHASE_PCIFAST16, 0, 0, 
+               PCI_SUBDEVICE_ID_CHASE_PCIFAST16, 0, 0,
                pbn_b2_16_460800 },
        {       PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
                PCI_SUBVENDOR_ID_CHASE_PCIFAST,
-               PCI_SUBDEVICE_ID_CHASE_PCIFAST16FMC, 0, 0, 
+               PCI_SUBDEVICE_ID_CHASE_PCIFAST16FMC, 0, 0,
                pbn_b2_16_460800 },
        {       PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
                PCI_SUBVENDOR_ID_CHASE_PCIRAS,
-               PCI_SUBDEVICE_ID_CHASE_PCIRAS4, 0, 0, 
+               PCI_SUBDEVICE_ID_CHASE_PCIRAS4, 0, 0,
                pbn_b2_4_460800 },
        {       PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
                PCI_SUBVENDOR_ID_CHASE_PCIRAS,
-               PCI_SUBDEVICE_ID_CHASE_PCIRAS8, 0, 0, 
+               PCI_SUBDEVICE_ID_CHASE_PCIRAS8, 0, 0,
                pbn_b2_8_460800 },
        {       PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
                PCI_SUBVENDOR_ID_EXSYS,
@@ -2269,10 +2266,12 @@ static struct pci_device_id serial_pci_tbl[] = {
                PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_b1_8_115200 },
        {       PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_OXSEMI_16PCI954,
-               PCI_VENDOR_ID_SPECIALIX, PCI_SUBDEVICE_ID_SPECIALIX_SPEED4, 0, 0,
+               PCI_VENDOR_ID_SPECIALIX, PCI_SUBDEVICE_ID_SPECIALIX_SPEED4,
+               0, 0,
                pbn_b0_4_921600 },
        {       PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954,
-               PCI_SUBVENDOR_ID_SIIG, PCI_SUBDEVICE_ID_SIIG_QUARTET_SERIAL, 0, 0,
+               PCI_SUBVENDOR_ID_SIIG, PCI_SUBDEVICE_ID_SIIG_QUARTET_SERIAL,
+               0, 0,
                pbn_b0_4_1152000 },
 
                /*
@@ -2312,7 +2311,7 @@ static struct pci_device_id serial_pci_tbl[] = {
         * Digitan DS560-558, from jimd@esoft.com
         */
        {       PCI_VENDOR_ID_ATT, PCI_DEVICE_ID_ATT_VENUS_MODEM,
-               PCI_ANY_ID, PCI_ANY_ID, 0, 0, 
+               PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_b1_1_115200 },
 
        /*
@@ -2320,16 +2319,16 @@ static struct pci_device_id serial_pci_tbl[] = {
         *  The 400L and 800L have a custom setup quirk.
         */
        {       PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_100,
-               PCI_ANY_ID, PCI_ANY_ID, 0, 0, 
+               PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_b0_1_921600 },
        {       PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_200,
-               PCI_ANY_ID, PCI_ANY_ID, 0, 0, 
+               PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_b0_2_921600 },
        {       PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_400,
-               PCI_ANY_ID, PCI_ANY_ID, 0, 0, 
+               PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_b0_4_921600 },
        {       PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_800B,
-               PCI_ANY_ID, PCI_ANY_ID, 0, 0, 
+               PCI_ANY_ID, PCI_ANY_ID, 0, 0,
                pbn_b0_4_921600 },
        {       PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_100L,
                PCI_ANY_ID, PCI_ANY_ID, 0, 0,
index 84a054d7e9865aec10da1601a7e3f4deba7635c7..b82595cf13e86ff759c92109fb096f706e68e7e5 100644 (file)
@@ -380,6 +380,21 @@ config SERIAL_ATMEL_CONSOLE
          console is the device which receives all kernel messages and
          warnings and which allows logins in single user mode).
 
+config SERIAL_ATMEL_PDC
+       bool "Support DMA transfers on AT91 / AT32 serial port"
+       depends on SERIAL_ATMEL
+       default y
+       help
+         Say Y here if you wish to use the PDC to do DMA transfers to
+         and from the Atmel AT91 / AT32 serial port. In order to
+         actually use DMA transfers, make sure that the use_dma_tx
+         and use_dma_rx members in the atmel_uart_data struct is set
+         appropriately for each port.
+
+         Note that break and error handling currently doesn't work
+         properly when DMA is enabled. Make sure that ports where
+         this matters don't use DMA.
+
 config SERIAL_ATMEL_TTYAT
        bool "Install as device ttyATn instead of ttySn"
        depends on SERIAL_ATMEL=y
index 60f52904aad0fc4bfe7142d348c35a434dac1731..fad245b064d666a00017aabcc8f6ccb9b4f08a91 100644 (file)
@@ -7,6 +7,8 @@
  *  Based on drivers/char/serial_sa1100.c, by Deep Blue Solutions Ltd.
  *  Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
  *
+ *  DMA support added by Chip Coldwell.
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
@@ -33,6 +35,7 @@
 #include <linux/sysrq.h>
 #include <linux/tty_flip.h>
 #include <linux/platform_device.h>
+#include <linux/dma-mapping.h>
 #include <linux/atmel_pdc.h>
 #include <linux/atmel_serial.h>
 
 #include <asm/arch/gpio.h>
 #endif
 
+#define PDC_BUFFER_SIZE                512
+/* Revisit: We should calculate this based on the actual port settings */
+#define PDC_RX_TIMEOUT         (3 * 10)                /* 3 bytes */
+
 #if defined(CONFIG_SERIAL_ATMEL_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
 #define SUPPORT_SYSRQ
 #endif
@@ -73,6 +80,7 @@
 
 #define ATMEL_ISR_PASS_LIMIT   256
 
+/* UART registers. CR is write-only, hence no GET macro */
 #define UART_PUT_CR(port,v)    __raw_writel(v, (port)->membase + ATMEL_US_CR)
 #define UART_GET_MR(port)      __raw_readl((port)->membase + ATMEL_US_MR)
 #define UART_PUT_MR(port,v)    __raw_writel(v, (port)->membase + ATMEL_US_MR)
@@ -86,8 +94,6 @@
 #define UART_PUT_BRGR(port,v)  __raw_writel(v, (port)->membase + ATMEL_US_BRGR)
 #define UART_PUT_RTOR(port,v)  __raw_writel(v, (port)->membase + ATMEL_US_RTOR)
 
-// #define UART_GET_CR(port)   __raw_readl((port)->membase + ATMEL_US_CR)              // is write-only
-
  /* PDC registers */
 #define UART_PUT_PTCR(port,v)  __raw_writel(v, (port)->membase + ATMEL_PDC_PTCR)
 #define UART_GET_PTSR(port)    __raw_readl((port)->membase + ATMEL_PDC_PTSR)
 
 #define UART_PUT_TPR(port,v)   __raw_writel(v, (port)->membase + ATMEL_PDC_TPR)
 #define UART_PUT_TCR(port,v)   __raw_writel(v, (port)->membase + ATMEL_PDC_TCR)
-//#define UART_PUT_TNPR(port,v)        __raw_writel(v, (port)->membase + ATMEL_PDC_TNPR)
-//#define UART_PUT_TNCR(port,v)        __raw_writel(v, (port)->membase + ATMEL_PDC_TNCR)
 
 static int (*atmel_open_hook)(struct uart_port *);
 static void (*atmel_close_hook)(struct uart_port *);
 
+struct atmel_dma_buffer {
+       unsigned char   *buf;
+       dma_addr_t      dma_addr;
+       unsigned int    dma_size;
+       unsigned int    ofs;
+};
+
+struct atmel_uart_char {
+       u16             status;
+       u16             ch;
+};
+
+#define ATMEL_SERIAL_RINGSIZE 1024
+
 /*
  * We wrap our port structure around the generic uart_port.
  */
@@ -114,6 +132,19 @@ struct atmel_uart_port {
        struct clk              *clk;           /* uart clock */
        unsigned short          suspended;      /* is port suspended? */
        int                     break_active;   /* break being received */
+
+       short                   use_dma_rx;     /* enable PDC receiver */
+       short                   pdc_rx_idx;     /* current PDC RX buffer */
+       struct atmel_dma_buffer pdc_rx[2];      /* PDC receier */
+
+       short                   use_dma_tx;     /* enable PDC transmitter */
+       struct atmel_dma_buffer pdc_tx;         /* PDC transmitter */
+
+       struct tasklet_struct   tasklet;
+       unsigned int            irq_status;
+       unsigned int            irq_status_prev;
+
+       struct circ_buf         rx_ring;
 };
 
 static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
@@ -122,6 +153,38 @@ static struct atmel_uart_port atmel_ports[ATMEL_MAX_UART];
 static struct console atmel_console;
 #endif
 
+static inline struct atmel_uart_port *
+to_atmel_uart_port(struct uart_port *uart)
+{
+       return container_of(uart, struct atmel_uart_port, uart);
+}
+
+#ifdef CONFIG_SERIAL_ATMEL_PDC
+static bool atmel_use_dma_rx(struct uart_port *port)
+{
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+
+       return atmel_port->use_dma_rx;
+}
+
+static bool atmel_use_dma_tx(struct uart_port *port)
+{
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+
+       return atmel_port->use_dma_tx;
+}
+#else
+static bool atmel_use_dma_rx(struct uart_port *port)
+{
+       return false;
+}
+
+static bool atmel_use_dma_tx(struct uart_port *port)
+{
+       return false;
+}
+#endif
+
 /*
  * Return TIOCSER_TEMT when transmitter FIFO and Shift register is empty.
  */
@@ -141,8 +204,8 @@ static void atmel_set_mctrl(struct uart_port *port, u_int mctrl)
 #ifdef CONFIG_ARCH_AT91RM9200
        if (cpu_is_at91rm9200()) {
                /*
-                * AT91RM9200 Errata #39: RTS0 is not internally connected to PA21.
-                *  We need to drive the pin manually.
+                * AT91RM9200 Errata #39: RTS0 is not internally connected
+                * to PA21. We need to drive the pin manually.
                 */
                if (port->mapbase == AT91RM9200_BASE_US0) {
                        if (mctrl & TIOCM_RTS)
@@ -203,7 +266,12 @@ static u_int atmel_get_mctrl(struct uart_port *port)
  */
 static void atmel_stop_tx(struct uart_port *port)
 {
-       UART_PUT_IDR(port, ATMEL_US_TXRDY);
+       if (atmel_use_dma_tx(port)) {
+               /* disable PDC transmit */
+               UART_PUT_PTCR(port, ATMEL_PDC_TXTDIS);
+               UART_PUT_IDR(port, ATMEL_US_ENDTX | ATMEL_US_TXBUFE);
+       } else
+               UART_PUT_IDR(port, ATMEL_US_TXRDY);
 }
 
 /*
@@ -211,7 +279,17 @@ static void atmel_stop_tx(struct uart_port *port)
  */
 static void atmel_start_tx(struct uart_port *port)
 {
-       UART_PUT_IER(port, ATMEL_US_TXRDY);
+       if (atmel_use_dma_tx(port)) {
+               if (UART_GET_PTSR(port) & ATMEL_PDC_TXTEN)
+                       /* The transmitter is already running.  Yes, we
+                          really need this.*/
+                       return;
+
+               UART_PUT_IER(port, ATMEL_US_ENDTX | ATMEL_US_TXBUFE);
+               /* re-enable PDC transmit */
+               UART_PUT_PTCR(port, ATMEL_PDC_TXTEN);
+       } else
+               UART_PUT_IER(port, ATMEL_US_TXRDY);
 }
 
 /*
@@ -219,7 +297,12 @@ static void atmel_start_tx(struct uart_port *port)
  */
 static void atmel_stop_rx(struct uart_port *port)
 {
-       UART_PUT_IDR(port, ATMEL_US_RXRDY);
+       if (atmel_use_dma_rx(port)) {
+               /* disable PDC receive */
+               UART_PUT_PTCR(port, ATMEL_PDC_RXTDIS);
+               UART_PUT_IDR(port, ATMEL_US_ENDRX | ATMEL_US_TIMEOUT);
+       } else
+               UART_PUT_IDR(port, ATMEL_US_RXRDY);
 }
 
 /*
@@ -227,7 +310,8 @@ static void atmel_stop_rx(struct uart_port *port)
  */
 static void atmel_enable_ms(struct uart_port *port)
 {
-       UART_PUT_IER(port, ATMEL_US_RIIC | ATMEL_US_DSRIC | ATMEL_US_DCDIC | ATMEL_US_CTSIC);
+       UART_PUT_IER(port, ATMEL_US_RIIC | ATMEL_US_DSRIC
+                       | ATMEL_US_DCDIC | ATMEL_US_CTSIC);
 }
 
 /*
@@ -241,23 +325,64 @@ static void atmel_break_ctl(struct uart_port *port, int break_state)
                UART_PUT_CR(port, ATMEL_US_STPBRK);     /* stop break */
 }
 
+/*
+ * Stores the incoming character in the ring buffer
+ */
+static void
+atmel_buffer_rx_char(struct uart_port *port, unsigned int status,
+                    unsigned int ch)
+{
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+       struct circ_buf *ring = &atmel_port->rx_ring;
+       struct atmel_uart_char *c;
+
+       if (!CIRC_SPACE(ring->head, ring->tail, ATMEL_SERIAL_RINGSIZE))
+               /* Buffer overflow, ignore char */
+               return;
+
+       c = &((struct atmel_uart_char *)ring->buf)[ring->head];
+       c->status       = status;
+       c->ch           = ch;
+
+       /* Make sure the character is stored before we update head. */
+       smp_wmb();
+
+       ring->head = (ring->head + 1) & (ATMEL_SERIAL_RINGSIZE - 1);
+}
+
+/*
+ * Deal with parity, framing and overrun errors.
+ */
+static void atmel_pdc_rxerr(struct uart_port *port, unsigned int status)
+{
+       /* clear error */
+       UART_PUT_CR(port, ATMEL_US_RSTSTA);
+
+       if (status & ATMEL_US_RXBRK) {
+               /* ignore side-effect */
+               status &= ~(ATMEL_US_PARE | ATMEL_US_FRAME);
+               port->icount.brk++;
+       }
+       if (status & ATMEL_US_PARE)
+               port->icount.parity++;
+       if (status & ATMEL_US_FRAME)
+               port->icount.frame++;
+       if (status & ATMEL_US_OVRE)
+               port->icount.overrun++;
+}
+
 /*
  * Characters received (called from interrupt handler)
  */
 static void atmel_rx_chars(struct uart_port *port)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *) port;
-       struct tty_struct *tty = port->info->tty;
-       unsigned int status, ch, flg;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+       unsigned int status, ch;
 
        status = UART_GET_CSR(port);
        while (status & ATMEL_US_RXRDY) {
                ch = UART_GET_CHAR(port);
 
-               port->icount.rx++;
-
-               flg = TTY_NORMAL;
-
                /*
                 * note that the error handling code is
                 * out of the main execution path
@@ -265,15 +390,14 @@ static void atmel_rx_chars(struct uart_port *port)
                if (unlikely(status & (ATMEL_US_PARE | ATMEL_US_FRAME
                                       | ATMEL_US_OVRE | ATMEL_US_RXBRK)
                             || atmel_port->break_active)) {
-                       UART_PUT_CR(port, ATMEL_US_RSTSTA);     /* clear error */
+
+                       /* clear error */
+                       UART_PUT_CR(port, ATMEL_US_RSTSTA);
+
                        if (status & ATMEL_US_RXBRK
                            && !atmel_port->break_active) {
-                               status &= ~(ATMEL_US_PARE | ATMEL_US_FRAME);    /* ignore side-effect */
-                               port->icount.brk++;
                                atmel_port->break_active = 1;
                                UART_PUT_IER(port, ATMEL_US_RXBRK);
-                               if (uart_handle_break(port))
-                                       goto ignore_char;
                        } else {
                                /*
                                 * This is either the end-of-break
@@ -286,52 +410,30 @@ static void atmel_rx_chars(struct uart_port *port)
                                status &= ~ATMEL_US_RXBRK;
                                atmel_port->break_active = 0;
                        }
-                       if (status & ATMEL_US_PARE)
-                               port->icount.parity++;
-                       if (status & ATMEL_US_FRAME)
-                               port->icount.frame++;
-                       if (status & ATMEL_US_OVRE)
-                               port->icount.overrun++;
-
-                       status &= port->read_status_mask;
-
-                       if (status & ATMEL_US_RXBRK)
-                               flg = TTY_BREAK;
-                       else if (status & ATMEL_US_PARE)
-                               flg = TTY_PARITY;
-                       else if (status & ATMEL_US_FRAME)
-                               flg = TTY_FRAME;
                }
 
-               if (uart_handle_sysrq_char(port, ch))
-                       goto ignore_char;
-
-               uart_insert_char(port, status, ATMEL_US_OVRE, ch, flg);
-
-       ignore_char:
+               atmel_buffer_rx_char(port, status, ch);
                status = UART_GET_CSR(port);
        }
 
-       tty_flip_buffer_push(tty);
+       tasklet_schedule(&atmel_port->tasklet);
 }
 
 /*
- * Transmit characters (called from interrupt handler)
+ * Transmit characters (called from tasklet with TXRDY interrupt
+ * disabled)
  */
 static void atmel_tx_chars(struct uart_port *port)
 {
        struct circ_buf *xmit = &port->info->xmit;
 
-       if (port->x_char) {
+       if (port->x_char && UART_GET_CSR(port) & ATMEL_US_TXRDY) {
                UART_PUT_CHAR(port, port->x_char);
                port->icount.tx++;
                port->x_char = 0;
-               return;
        }
-       if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
-               atmel_stop_tx(port);
+       if (uart_circ_empty(xmit) || uart_tx_stopped(port))
                return;
-       }
 
        while (UART_GET_CSR(port) & ATMEL_US_TXRDY) {
                UART_PUT_CHAR(port, xmit->buf[xmit->tail]);
@@ -344,8 +446,88 @@ static void atmel_tx_chars(struct uart_port *port)
        if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
                uart_write_wakeup(port);
 
-       if (uart_circ_empty(xmit))
-               atmel_stop_tx(port);
+       if (!uart_circ_empty(xmit))
+               UART_PUT_IER(port, ATMEL_US_TXRDY);
+}
+
+/*
+ * receive interrupt handler.
+ */
+static void
+atmel_handle_receive(struct uart_port *port, unsigned int pending)
+{
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+
+       if (atmel_use_dma_rx(port)) {
+               /*
+                * PDC receive. Just schedule the tasklet and let it
+                * figure out the details.
+                *
+                * TODO: We're not handling error flags correctly at
+                * the moment.
+                */
+               if (pending & (ATMEL_US_ENDRX | ATMEL_US_TIMEOUT)) {
+                       UART_PUT_IDR(port, (ATMEL_US_ENDRX
+                                               | ATMEL_US_TIMEOUT));
+                       tasklet_schedule(&atmel_port->tasklet);
+               }
+
+               if (pending & (ATMEL_US_RXBRK | ATMEL_US_OVRE |
+                               ATMEL_US_FRAME | ATMEL_US_PARE))
+                       atmel_pdc_rxerr(port, pending);
+       }
+
+       /* Interrupt receive */
+       if (pending & ATMEL_US_RXRDY)
+               atmel_rx_chars(port);
+       else if (pending & ATMEL_US_RXBRK) {
+               /*
+                * End of break detected. If it came along with a
+                * character, atmel_rx_chars will handle it.
+                */
+               UART_PUT_CR(port, ATMEL_US_RSTSTA);
+               UART_PUT_IDR(port, ATMEL_US_RXBRK);
+               atmel_port->break_active = 0;
+       }
+}
+
+/*
+ * transmit interrupt handler. (Transmit is IRQF_NODELAY safe)
+ */
+static void
+atmel_handle_transmit(struct uart_port *port, unsigned int pending)
+{
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+
+       if (atmel_use_dma_tx(port)) {
+               /* PDC transmit */
+               if (pending & (ATMEL_US_ENDTX | ATMEL_US_TXBUFE)) {
+                       UART_PUT_IDR(port, ATMEL_US_ENDTX | ATMEL_US_TXBUFE);
+                       tasklet_schedule(&atmel_port->tasklet);
+               }
+       } else {
+               /* Interrupt transmit */
+               if (pending & ATMEL_US_TXRDY) {
+                       UART_PUT_IDR(port, ATMEL_US_TXRDY);
+                       tasklet_schedule(&atmel_port->tasklet);
+               }
+       }
+}
+
+/*
+ * status flags interrupt handler.
+ */
+static void
+atmel_handle_status(struct uart_port *port, unsigned int pending,
+                   unsigned int status)
+{
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+
+       if (pending & (ATMEL_US_RIIC | ATMEL_US_DSRIC | ATMEL_US_DCDIC
+                               | ATMEL_US_CTSIC)) {
+               atmel_port->irq_status = status;
+               tasklet_schedule(&atmel_port->tasklet);
+       }
 }
 
 /*
@@ -354,47 +536,255 @@ static void atmel_tx_chars(struct uart_port *port)
 static irqreturn_t atmel_interrupt(int irq, void *dev_id)
 {
        struct uart_port *port = dev_id;
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *) port;
        unsigned int status, pending, pass_counter = 0;
 
-       status = UART_GET_CSR(port);
-       pending = status & UART_GET_IMR(port);
-       while (pending) {
-               /* Interrupt receive */
-               if (pending & ATMEL_US_RXRDY)
-                       atmel_rx_chars(port);
-               else if (pending & ATMEL_US_RXBRK) {
+       do {
+               status = UART_GET_CSR(port);
+               pending = status & UART_GET_IMR(port);
+               if (!pending)
+                       break;
+
+               atmel_handle_receive(port, pending);
+               atmel_handle_status(port, pending, status);
+               atmel_handle_transmit(port, pending);
+       } while (pass_counter++ < ATMEL_ISR_PASS_LIMIT);
+
+       return IRQ_HANDLED;
+}
+
+/*
+ * Called from tasklet with ENDTX and TXBUFE interrupts disabled.
+ */
+static void atmel_tx_dma(struct uart_port *port)
+{
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+       struct circ_buf *xmit = &port->info->xmit;
+       struct atmel_dma_buffer *pdc = &atmel_port->pdc_tx;
+       int count;
+
+       xmit->tail += pdc->ofs;
+       xmit->tail &= UART_XMIT_SIZE - 1;
+
+       port->icount.tx += pdc->ofs;
+       pdc->ofs = 0;
+
+       if (!uart_circ_empty(xmit)) {
+               /* more to transmit - setup next transfer */
+
+               /* disable PDC transmit */
+               UART_PUT_PTCR(port, ATMEL_PDC_TXTDIS);
+               dma_sync_single_for_device(port->dev,
+                                          pdc->dma_addr,
+                                          pdc->dma_size,
+                                          DMA_TO_DEVICE);
+
+               count = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE);
+               pdc->ofs = count;
+
+               UART_PUT_TPR(port, pdc->dma_addr + xmit->tail);
+               UART_PUT_TCR(port, count);
+               /* re-enable PDC transmit and interrupts */
+               UART_PUT_PTCR(port, ATMEL_PDC_TXTEN);
+               UART_PUT_IER(port, ATMEL_US_ENDTX | ATMEL_US_TXBUFE);
+       } else {
+               /* nothing left to transmit - disable the transmitter */
+
+               /* disable PDC transmit */
+               UART_PUT_PTCR(port, ATMEL_PDC_TXTDIS);
+       }
+
+       if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
+               uart_write_wakeup(port);
+}
+
+static void atmel_rx_from_ring(struct uart_port *port)
+{
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+       struct circ_buf *ring = &atmel_port->rx_ring;
+       unsigned int flg;
+       unsigned int status;
+
+       while (ring->head != ring->tail) {
+               struct atmel_uart_char c;
+
+               /* Make sure c is loaded after head. */
+               smp_rmb();
+
+               c = ((struct atmel_uart_char *)ring->buf)[ring->tail];
+
+               ring->tail = (ring->tail + 1) & (ATMEL_SERIAL_RINGSIZE - 1);
+
+               port->icount.rx++;
+               status = c.status;
+               flg = TTY_NORMAL;
+
+               /*
+                * note that the error handling code is
+                * out of the main execution path
+                */
+               if (unlikely(status & (ATMEL_US_PARE | ATMEL_US_FRAME
+                                      | ATMEL_US_OVRE | ATMEL_US_RXBRK))) {
+                       if (status & ATMEL_US_RXBRK) {
+                               /* ignore side-effect */
+                               status &= ~(ATMEL_US_PARE | ATMEL_US_FRAME);
+
+                               port->icount.brk++;
+                               if (uart_handle_break(port))
+                                       continue;
+                       }
+                       if (status & ATMEL_US_PARE)
+                               port->icount.parity++;
+                       if (status & ATMEL_US_FRAME)
+                               port->icount.frame++;
+                       if (status & ATMEL_US_OVRE)
+                               port->icount.overrun++;
+
+                       status &= port->read_status_mask;
+
+                       if (status & ATMEL_US_RXBRK)
+                               flg = TTY_BREAK;
+                       else if (status & ATMEL_US_PARE)
+                               flg = TTY_PARITY;
+                       else if (status & ATMEL_US_FRAME)
+                               flg = TTY_FRAME;
+               }
+
+
+               if (uart_handle_sysrq_char(port, c.ch))
+                       continue;
+
+               uart_insert_char(port, status, ATMEL_US_OVRE, c.ch, flg);
+       }
+
+       /*
+        * Drop the lock here since it might end up calling
+        * uart_start(), which takes the lock.
+        */
+       spin_unlock(&port->lock);
+       tty_flip_buffer_push(port->info->tty);
+       spin_lock(&port->lock);
+}
+
+static void atmel_rx_from_dma(struct uart_port *port)
+{
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+       struct tty_struct *tty = port->info->tty;
+       struct atmel_dma_buffer *pdc;
+       int rx_idx = atmel_port->pdc_rx_idx;
+       unsigned int head;
+       unsigned int tail;
+       unsigned int count;
+
+       do {
+               /* Reset the UART timeout early so that we don't miss one */
+               UART_PUT_CR(port, ATMEL_US_STTTO);
+
+               pdc = &atmel_port->pdc_rx[rx_idx];
+               head = UART_GET_RPR(port) - pdc->dma_addr;
+               tail = pdc->ofs;
+
+               /* If the PDC has switched buffers, RPR won't contain
+                * any address within the current buffer. Since head
+                * is unsigned, we just need a one-way comparison to
+                * find out.
+                *
+                * In this case, we just need to consume the entire
+                * buffer and resubmit it for DMA. This will clear the
+                * ENDRX bit as well, so that we can safely re-enable
+                * all interrupts below.
+                */
+               head = min(head, pdc->dma_size);
+
+               if (likely(head != tail)) {
+                       dma_sync_single_for_cpu(port->dev, pdc->dma_addr,
+                                       pdc->dma_size, DMA_FROM_DEVICE);
+
                        /*
-                        * End of break detected. If it came along
-                        * with a character, atmel_rx_chars will
-                        * handle it.
+                        * head will only wrap around when we recycle
+                        * the DMA buffer, and when that happens, we
+                        * explicitly set tail to 0. So head will
+                        * always be greater than tail.
                         */
-                       UART_PUT_CR(port, ATMEL_US_RSTSTA);
-                       UART_PUT_IDR(port, ATMEL_US_RXBRK);
-                       atmel_port->break_active = 0;
+                       count = head - tail;
+
+                       tty_insert_flip_string(tty, pdc->buf + pdc->ofs, count);
+
+                       dma_sync_single_for_device(port->dev, pdc->dma_addr,
+                                       pdc->dma_size, DMA_FROM_DEVICE);
+
+                       port->icount.rx += count;
+                       pdc->ofs = head;
                }
 
-               // TODO: All reads to CSR will clear these interrupts!
-               if (pending & ATMEL_US_RIIC) port->icount.rng++;
-               if (pending & ATMEL_US_DSRIC) port->icount.dsr++;
-               if (pending & ATMEL_US_DCDIC)
+               /*
+                * If the current buffer is full, we need to check if
+                * the next one contains any additional data.
+                */
+               if (head >= pdc->dma_size) {
+                       pdc->ofs = 0;
+                       UART_PUT_RNPR(port, pdc->dma_addr);
+                       UART_PUT_RNCR(port, pdc->dma_size);
+
+                       rx_idx = !rx_idx;
+                       atmel_port->pdc_rx_idx = rx_idx;
+               }
+       } while (head >= pdc->dma_size);
+
+       /*
+        * Drop the lock here since it might end up calling
+        * uart_start(), which takes the lock.
+        */
+       spin_unlock(&port->lock);
+       tty_flip_buffer_push(tty);
+       spin_lock(&port->lock);
+
+       UART_PUT_IER(port, ATMEL_US_ENDRX | ATMEL_US_TIMEOUT);
+}
+
+/*
+ * tasklet handling tty stuff outside the interrupt handler.
+ */
+static void atmel_tasklet_func(unsigned long data)
+{
+       struct uart_port *port = (struct uart_port *)data;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+       unsigned int status;
+       unsigned int status_change;
+
+       /* The interrupt handler does not take the lock */
+       spin_lock(&port->lock);
+
+       if (atmel_use_dma_tx(port))
+               atmel_tx_dma(port);
+       else
+               atmel_tx_chars(port);
+
+       status = atmel_port->irq_status;
+       status_change = status ^ atmel_port->irq_status_prev;
+
+       if (status_change & (ATMEL_US_RI | ATMEL_US_DSR
+                               | ATMEL_US_DCD | ATMEL_US_CTS)) {
+               /* TODO: All reads to CSR will clear these interrupts! */
+               if (status_change & ATMEL_US_RI)
+                       port->icount.rng++;
+               if (status_change & ATMEL_US_DSR)
+                       port->icount.dsr++;
+               if (status_change & ATMEL_US_DCD)
                        uart_handle_dcd_change(port, !(status & ATMEL_US_DCD));
-               if (pending & ATMEL_US_CTSIC)
+               if (status_change & ATMEL_US_CTS)
                        uart_handle_cts_change(port, !(status & ATMEL_US_CTS));
-               if (pending & (ATMEL_US_RIIC | ATMEL_US_DSRIC | ATMEL_US_DCDIC | ATMEL_US_CTSIC))
-                       wake_up_interruptible(&port->info->delta_msr_wait);
 
-               /* Interrupt transmit */
-               if (pending & ATMEL_US_TXRDY)
-                       atmel_tx_chars(port);
+               wake_up_interruptible(&port->info->delta_msr_wait);
 
-               if (pass_counter++ > ATMEL_ISR_PASS_LIMIT)
-                       break;
-
-               status = UART_GET_CSR(port);
-               pending = status & UART_GET_IMR(port);
+               atmel_port->irq_status_prev = status;
        }
-       return IRQ_HANDLED;
+
+       if (atmel_use_dma_rx(port))
+               atmel_rx_from_dma(port);
+       else
+               atmel_rx_from_ring(port);
+
+       spin_unlock(&port->lock);
 }
 
 /*
@@ -402,6 +792,8 @@ static irqreturn_t atmel_interrupt(int irq, void *dev_id)
  */
 static int atmel_startup(struct uart_port *port)
 {
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+       struct tty_struct *tty = port->info->tty;
        int retval;
 
        /*
@@ -414,12 +806,63 @@ static int atmel_startup(struct uart_port *port)
        /*
         * Allocate the IRQ
         */
-       retval = request_irq(port->irq, atmel_interrupt, IRQF_SHARED, "atmel_serial", port);
+       retval = request_irq(port->irq, atmel_interrupt, IRQF_SHARED,
+                       tty ? tty->name : "atmel_serial", port);
        if (retval) {
                printk("atmel_serial: atmel_startup - Can't get irq\n");
                return retval;
        }
 
+       /*
+        * Initialize DMA (if necessary)
+        */
+       if (atmel_use_dma_rx(port)) {
+               int i;
+
+               for (i = 0; i < 2; i++) {
+                       struct atmel_dma_buffer *pdc = &atmel_port->pdc_rx[i];
+
+                       pdc->buf = kmalloc(PDC_BUFFER_SIZE, GFP_KERNEL);
+                       if (pdc->buf == NULL) {
+                               if (i != 0) {
+                                       dma_unmap_single(port->dev,
+                                               atmel_port->pdc_rx[0].dma_addr,
+                                               PDC_BUFFER_SIZE,
+                                               DMA_FROM_DEVICE);
+                                       kfree(atmel_port->pdc_rx[0].buf);
+                               }
+                               free_irq(port->irq, port);
+                               return -ENOMEM;
+                       }
+                       pdc->dma_addr = dma_map_single(port->dev,
+                                                      pdc->buf,
+                                                      PDC_BUFFER_SIZE,
+                                                      DMA_FROM_DEVICE);
+                       pdc->dma_size = PDC_BUFFER_SIZE;
+                       pdc->ofs = 0;
+               }
+
+               atmel_port->pdc_rx_idx = 0;
+
+               UART_PUT_RPR(port, atmel_port->pdc_rx[0].dma_addr);
+               UART_PUT_RCR(port, PDC_BUFFER_SIZE);
+
+               UART_PUT_RNPR(port, atmel_port->pdc_rx[1].dma_addr);
+               UART_PUT_RNCR(port, PDC_BUFFER_SIZE);
+       }
+       if (atmel_use_dma_tx(port)) {
+               struct atmel_dma_buffer *pdc = &atmel_port->pdc_tx;
+               struct circ_buf *xmit = &port->info->xmit;
+
+               pdc->buf = xmit->buf;
+               pdc->dma_addr = dma_map_single(port->dev,
+                                              pdc->buf,
+                                              UART_XMIT_SIZE,
+                                              DMA_TO_DEVICE);
+               pdc->dma_size = UART_XMIT_SIZE;
+               pdc->ofs = 0;
+       }
+
        /*
         * If there is a specific "open" function (to register
         * control line interrupts)
@@ -436,9 +879,21 @@ static int atmel_startup(struct uart_port *port)
         * Finally, enable the serial port
         */
        UART_PUT_CR(port, ATMEL_US_RSTSTA | ATMEL_US_RSTRX);
-       UART_PUT_CR(port, ATMEL_US_TXEN | ATMEL_US_RXEN);               /* enable xmit & rcvr */
+       /* enable xmit & rcvr */
+       UART_PUT_CR(port, ATMEL_US_TXEN | ATMEL_US_RXEN);
 
-       UART_PUT_IER(port, ATMEL_US_RXRDY);             /* enable receive only */
+       if (atmel_use_dma_rx(port)) {
+               /* set UART timeout */
+               UART_PUT_RTOR(port, PDC_RX_TIMEOUT);
+               UART_PUT_CR(port, ATMEL_US_STTTO);
+
+               UART_PUT_IER(port, ATMEL_US_ENDRX | ATMEL_US_TIMEOUT);
+               /* enable PDC controller */
+               UART_PUT_PTCR(port, ATMEL_PDC_RXTEN);
+       } else {
+               /* enable receive only */
+               UART_PUT_IER(port, ATMEL_US_RXRDY);
+       }
 
        return 0;
 }
@@ -448,6 +903,38 @@ static int atmel_startup(struct uart_port *port)
  */
 static void atmel_shutdown(struct uart_port *port)
 {
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
+       /*
+        * Ensure everything is stopped.
+        */
+       atmel_stop_rx(port);
+       atmel_stop_tx(port);
+
+       /*
+        * Shut-down the DMA.
+        */
+       if (atmel_use_dma_rx(port)) {
+               int i;
+
+               for (i = 0; i < 2; i++) {
+                       struct atmel_dma_buffer *pdc = &atmel_port->pdc_rx[i];
+
+                       dma_unmap_single(port->dev,
+                                        pdc->dma_addr,
+                                        pdc->dma_size,
+                                        DMA_FROM_DEVICE);
+                       kfree(pdc->buf);
+               }
+       }
+       if (atmel_use_dma_tx(port)) {
+               struct atmel_dma_buffer *pdc = &atmel_port->pdc_tx;
+
+               dma_unmap_single(port->dev,
+                                pdc->dma_addr,
+                                pdc->dma_size,
+                                DMA_TO_DEVICE);
+       }
+
        /*
         * Disable all interrupts, port and break condition.
         */
@@ -470,45 +957,48 @@ static void atmel_shutdown(struct uart_port *port)
 /*
  * Power / Clock management.
  */
-static void atmel_serial_pm(struct uart_port *port, unsigned int state, unsigned int oldstate)
+static void atmel_serial_pm(struct uart_port *port, unsigned int state,
+                           unsigned int oldstate)
 {
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *) port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
        switch (state) {
-               case 0:
-                       /*
-                        * Enable the peripheral clock for this serial port.
-                        * This is called on uart_open() or a resume event.
-                        */
-                       clk_enable(atmel_port->clk);
-                       break;
-               case 3:
-                       /*
-                        * Disable the peripheral clock for this serial port.
-                        * This is called on uart_close() or a suspend event.
-                        */
-                       clk_disable(atmel_port->clk);
-                       break;
-               default:
-                       printk(KERN_ERR "atmel_serial: unknown pm %d\n", state);
+       case 0:
+               /*
+                * Enable the peripheral clock for this serial port.
+                * This is called on uart_open() or a resume event.
+                */
+               clk_enable(atmel_port->clk);
+               break;
+       case 3:
+               /*
+                * Disable the peripheral clock for this serial port.
+                * This is called on uart_close() or a suspend event.
+                */
+               clk_disable(atmel_port->clk);
+               break;
+       default:
+               printk(KERN_ERR "atmel_serial: unknown pm %d\n", state);
        }
 }
 
 /*
  * Change the port parameters
  */
-static void atmel_set_termios(struct uart_port *port, struct ktermios * termios, struct ktermios * old)
+static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
+                             struct ktermios *old)
 {
        unsigned long flags;
        unsigned int mode, imr, quot, baud;
 
        /* Get current mode register */
-       mode = UART_GET_MR(port) & ~(ATMEL_US_USCLKS | ATMEL_US_CHRL | ATMEL_US_NBSTOP | ATMEL_US_PAR);
+       mode = UART_GET_MR(port) & ~(ATMEL_US_USCLKS | ATMEL_US_CHRL
+                                       | ATMEL_US_NBSTOP | ATMEL_US_PAR);
 
-       baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
+       baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
        quot = uart_get_divisor(port, baud);
 
-       if (quot > 65535) {             /* BRGR is 16-bit, so switch to slower clock */
+       if (quot > 65535) {     /* BRGR is 16-bit, so switch to slower clock */
                quot /= 8;
                mode |= ATMEL_US_USCLKS_MCK_DIV8;
        }
@@ -535,18 +1025,17 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios * termios,
 
        /* parity */
        if (termios->c_cflag & PARENB) {
-               if (termios->c_cflag & CMSPAR) {                        /* Mark or Space parity */
+               /* Mark or Space parity */
+               if (termios->c_cflag & CMSPAR) {
                        if (termios->c_cflag & PARODD)
                                mode |= ATMEL_US_PAR_MARK;
                        else
                                mode |= ATMEL_US_PAR_SPACE;
-               }
-               else if (termios->c_cflag & PARODD)
+               } else if (termios->c_cflag & PARODD)
                        mode |= ATMEL_US_PAR_ODD;
                else
                        mode |= ATMEL_US_PAR_EVEN;
-       }
-       else
+       } else
                mode |= ATMEL_US_PAR_NONE;
 
        spin_lock_irqsave(&port->lock, flags);
@@ -557,6 +1046,10 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios * termios,
        if (termios->c_iflag & (BRKINT | PARMRK))
                port->read_status_mask |= ATMEL_US_RXBRK;
 
+       if (atmel_use_dma_rx(port))
+               /* need to enable error interrupts */
+               UART_PUT_IER(port, port->read_status_mask);
+
        /*
         * Characters to ignore
         */
@@ -572,16 +1065,16 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios * termios,
                if (termios->c_iflag & IGNPAR)
                        port->ignore_status_mask |= ATMEL_US_OVRE;
        }
-
-       // TODO: Ignore all characters if CREAD is set.
+       /* TODO: Ignore all characters if CREAD is set.*/
 
        /* update the per-port timeout */
        uart_update_timeout(port, termios->c_cflag, baud);
 
-       /* disable interrupts and drain transmitter */
-       imr = UART_GET_IMR(port);       /* get interrupt mask */
-       UART_PUT_IDR(port, -1);         /* disable all interrupts */
-       while (!(UART_GET_CSR(port) & ATMEL_US_TXEMPTY)) { barrier(); }
+       /* save/disable interrupts and drain transmitter */
+       imr = UART_GET_IMR(port);
+       UART_PUT_IDR(port, -1);
+       while (!(UART_GET_CSR(port) & ATMEL_US_TXEMPTY))
+               cpu_relax();
 
        /* disable receiver and transmitter */
        UART_PUT_CR(port, ATMEL_US_TXDIS | ATMEL_US_RXDIS);
@@ -707,7 +1200,8 @@ static struct uart_ops atmel_pops = {
 /*
  * Configure the port from the platform device resource info.
  */
-static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port, struct platform_device *pdev)
+static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port,
+                                     struct platform_device *pdev)
 {
        struct uart_port *port = &atmel_port->uart;
        struct atmel_uart_data *data = pdev->dev.platform_data;
@@ -722,6 +1216,11 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port, struct
        port->mapbase   = pdev->resource[0].start;
        port->irq       = pdev->resource[1].start;
 
+       tasklet_init(&atmel_port->tasklet, atmel_tasklet_func,
+                       (unsigned long)port);
+
+       memset(&atmel_port->rx_ring, 0, sizeof(atmel_port->rx_ring));
+
        if (data->regs)
                /* Already mapped by setup code */
                port->membase = data->regs;
@@ -730,11 +1229,17 @@ static void __devinit atmel_init_port(struct atmel_uart_port *atmel_port, struct
                port->membase   = NULL;
        }
 
-       if (!atmel_port->clk) {         /* for console, the clock could already be configured */
+       /* for console, the clock could already be configured */
+       if (!atmel_port->clk) {
                atmel_port->clk = clk_get(&pdev->dev, "usart");
                clk_enable(atmel_port->clk);
                port->uartclk = clk_get_rate(atmel_port->clk);
        }
+
+       atmel_port->use_dma_rx = data->use_dma_rx;
+       atmel_port->use_dma_tx = data->use_dma_tx;
+       if (atmel_use_dma_tx(port))
+               port->fifosize = PDC_BUFFER_SIZE;
 }
 
 /*
@@ -754,12 +1259,11 @@ void __init atmel_register_uart_fns(struct atmel_port_fns *fns)
        atmel_pops.set_wake     = fns->set_wake;
 }
 
-
 #ifdef CONFIG_SERIAL_ATMEL_CONSOLE
 static void atmel_console_putchar(struct uart_port *port, int ch)
 {
        while (!(UART_GET_CSR(port) & ATMEL_US_TXRDY))
-               barrier();
+               cpu_relax();
        UART_PUT_CHAR(port, ch);
 }
 
@@ -772,38 +1276,40 @@ static void atmel_console_write(struct console *co, const char *s, u_int count)
        unsigned int status, imr;
 
        /*
-        *      First, save IMR and then disable interrupts
+        * First, save IMR and then disable interrupts
         */
-       imr = UART_GET_IMR(port);       /* get interrupt mask */
+       imr = UART_GET_IMR(port);
        UART_PUT_IDR(port, ATMEL_US_RXRDY | ATMEL_US_TXRDY);
 
        uart_console_write(port, s, count, atmel_console_putchar);
 
        /*
-        *      Finally, wait for transmitter to become empty
-        *      and restore IMR
+        * Finally, wait for transmitter to become empty
+        * and restore IMR
         */
        do {
                status = UART_GET_CSR(port);
        } while (!(status & ATMEL_US_TXRDY));
-       UART_PUT_IER(port, imr);        /* set interrupts back the way they were */
+       /* set interrupts back the way they were */
+       UART_PUT_IER(port, imr);
 }
 
 /*
- * If the port was already initialised (eg, by a boot loader), try to determine
- * the current setup.
+ * If the port was already initialised (eg, by a boot loader),
+ * try to determine the current setup.
  */
-static void __init atmel_console_get_options(struct uart_port *port, int *baud, int *parity, int *bits)
+static void __init atmel_console_get_options(struct uart_port *port, int *baud,
+                                            int *parity, int *bits)
 {
        unsigned int mr, quot;
 
-// TODO: CR is a write-only register
-//     unsigned int cr;
-//
-//     cr = UART_GET_CR(port) & (ATMEL_US_RXEN | ATMEL_US_TXEN);
-//     if (cr == (ATMEL_US_RXEN | ATMEL_US_TXEN)) {
-//             /* ok, the port was enabled */
-//     }
+       /*
+        * If the baud rate generator isn't running, the port wasn't
+        * initialized by the boot loader.
+        */
+       quot = UART_GET_BRGR(port);
+       if (!quot)
+               return;
 
        mr = UART_GET_MR(port) & ATMEL_US_CHRL;
        if (mr == ATMEL_US_CHRL_8)
@@ -823,7 +1329,6 @@ static void __init atmel_console_get_options(struct uart_port *port, int *baud,
         * lower than one of those, as it would make us fall through
         * to a much lower baud rate than we really want.
         */
-       quot = UART_GET_BRGR(port);
        *baud = port->uartclk / (16 * (quot - 1));
 }
 
@@ -835,10 +1340,12 @@ static int __init atmel_console_setup(struct console *co, char *options)
        int parity = 'n';
        int flow = 'n';
 
-       if (port->membase == 0)         /* Port not initialized yet - delay setup */
+       if (port->membase == NULL) {
+               /* Port not initialized yet - delay setup */
                return -ENODEV;
+       }
 
-       UART_PUT_IDR(port, -1);                         /* disable interrupts */
+       UART_PUT_IDR(port, -1);
        UART_PUT_CR(port, ATMEL_US_RSTSTA | ATMEL_US_RSTRX);
        UART_PUT_CR(port, ATMEL_US_TXEN | ATMEL_US_RXEN);
 
@@ -870,13 +1377,16 @@ static struct console atmel_console = {
 static int __init atmel_console_init(void)
 {
        if (atmel_default_console_device) {
-               add_preferred_console(ATMEL_DEVICENAME, atmel_default_console_device->id, NULL);
-               atmel_init_port(&(atmel_ports[atmel_default_console_device->id]), atmel_default_console_device);
+               add_preferred_console(ATMEL_DEVICENAME,
+                                     atmel_default_console_device->id, NULL);
+               atmel_init_port(&atmel_ports[atmel_default_console_device->id],
+                               atmel_default_console_device);
                register_console(&atmel_console);
        }
 
        return 0;
 }
+
 console_initcall(atmel_console_init);
 
 /*
@@ -884,34 +1394,48 @@ console_initcall(atmel_console_init);
  */
 static int __init atmel_late_console_init(void)
 {
-       if (atmel_default_console_device && !(atmel_console.flags & CON_ENABLED))
+       if (atmel_default_console_device
+           && !(atmel_console.flags & CON_ENABLED))
                register_console(&atmel_console);
 
        return 0;
 }
+
 core_initcall(atmel_late_console_init);
 
+static inline bool atmel_is_console_port(struct uart_port *port)
+{
+       return port->cons && port->cons->index == port->line;
+}
+
 #else
 #define ATMEL_CONSOLE_DEVICE   NULL
+
+static inline bool atmel_is_console_port(struct uart_port *port)
+{
+       return false;
+}
 #endif
 
 static struct uart_driver atmel_uart = {
-       .owner                  = THIS_MODULE,
-       .driver_name            = "atmel_serial",
-       .dev_name               = ATMEL_DEVICENAME,
-       .major                  = SERIAL_ATMEL_MAJOR,
-       .minor                  = MINOR_START,
-       .nr                     = ATMEL_MAX_UART,
-       .cons                   = ATMEL_CONSOLE_DEVICE,
+       .owner          = THIS_MODULE,
+       .driver_name    = "atmel_serial",
+       .dev_name       = ATMEL_DEVICENAME,
+       .major          = SERIAL_ATMEL_MAJOR,
+       .minor          = MINOR_START,
+       .nr             = ATMEL_MAX_UART,
+       .cons           = ATMEL_CONSOLE_DEVICE,
 };
 
 #ifdef CONFIG_PM
-static int atmel_serial_suspend(struct platform_device *pdev, pm_message_t state)
+static int atmel_serial_suspend(struct platform_device *pdev,
+                               pm_message_t state)
 {
        struct uart_port *port = platform_get_drvdata(pdev);
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *) port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
-       if (device_may_wakeup(&pdev->dev) && !at91_suspend_entering_slow_clock())
+       if (device_may_wakeup(&pdev->dev)
+           && !at91_suspend_entering_slow_clock())
                enable_irq_wake(port->irq);
        else {
                uart_suspend_port(&atmel_uart, port);
@@ -924,13 +1448,12 @@ static int atmel_serial_suspend(struct platform_device *pdev, pm_message_t state
 static int atmel_serial_resume(struct platform_device *pdev)
 {
        struct uart_port *port = platform_get_drvdata(pdev);
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *) port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
 
        if (atmel_port->suspended) {
                uart_resume_port(&atmel_uart, port);
                atmel_port->suspended = 0;
-       }
-       else
+       } else
                disable_irq_wake(port->irq);
 
        return 0;
@@ -943,15 +1466,40 @@ static int atmel_serial_resume(struct platform_device *pdev)
 static int __devinit atmel_serial_probe(struct platform_device *pdev)
 {
        struct atmel_uart_port *port;
+       void *data;
        int ret;
 
+       BUILD_BUG_ON(!is_power_of_2(ATMEL_SERIAL_RINGSIZE));
+
        port = &atmel_ports[pdev->id];
        atmel_init_port(port, pdev);
 
+       if (!atmel_use_dma_rx(&port->uart)) {
+               ret = -ENOMEM;
+               data = kmalloc(sizeof(struct atmel_uart_char)
+                               * ATMEL_SERIAL_RINGSIZE, GFP_KERNEL);
+               if (!data)
+                       goto err_alloc_ring;
+               port->rx_ring.buf = data;
+       }
+
        ret = uart_add_one_port(&atmel_uart, &port->uart);
-       if (!ret) {
-               device_init_wakeup(&pdev->dev, 1);
-               platform_set_drvdata(pdev, port);
+       if (ret)
+               goto err_add_port;
+
+       device_init_wakeup(&pdev->dev, 1);
+       platform_set_drvdata(pdev, port);
+
+       return 0;
+
+err_add_port:
+       kfree(port->rx_ring.buf);
+       port->rx_ring.buf = NULL;
+err_alloc_ring:
+       if (!atmel_is_console_port(&port->uart)) {
+               clk_disable(port->clk);
+               clk_put(port->clk);
+               port->clk = NULL;
        }
 
        return ret;
@@ -960,19 +1508,21 @@ static int __devinit atmel_serial_probe(struct platform_device *pdev)
 static int __devexit atmel_serial_remove(struct platform_device *pdev)
 {
        struct uart_port *port = platform_get_drvdata(pdev);
-       struct atmel_uart_port *atmel_port = (struct atmel_uart_port *) port;
+       struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
        int ret = 0;
 
-       clk_disable(atmel_port->clk);
-       clk_put(atmel_port->clk);
-
        device_init_wakeup(&pdev->dev, 0);
        platform_set_drvdata(pdev, NULL);
 
-       if (port) {
-               ret = uart_remove_one_port(&atmel_uart, port);
-               kfree(port);
-       }
+       ret = uart_remove_one_port(&atmel_uart, port);
+
+       tasklet_kill(&atmel_port->tasklet);
+       kfree(atmel_port->rx_ring.buf);
+
+       /* "port" is allocated statically, so we shouldn't free it */
+
+       clk_disable(atmel_port->clk);
+       clk_put(atmel_port->clk);
 
        return ret;
 }
index 276da148c57e015a6a148ec60a028d3d2e840ba6..0f5a17987ccacaf84283a1754134adfd7f3c2f7a 100644 (file)
@@ -58,7 +58,8 @@ static struct lock_class_key port_lock_key;
 #define uart_console(port)     (0)
 #endif
 
-static void uart_change_speed(struct uart_state *state, struct ktermios *old_termios);
+static void uart_change_speed(struct uart_state *state,
+                                       struct ktermios *old_termios);
 static void uart_wait_until_sent(struct tty_struct *tty, int timeout);
 static void uart_change_pm(struct uart_state *state, int pm_state);
 
@@ -129,8 +130,8 @@ uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear)
        spin_unlock_irqrestore(&port->lock, flags);
 }
 
-#define uart_set_mctrl(port,set)       uart_update_mctrl(port,set,0)
-#define uart_clear_mctrl(port,clear)   uart_update_mctrl(port,0,clear)
+#define uart_set_mctrl(port, set)      uart_update_mctrl(port, set, 0)
+#define uart_clear_mctrl(port, clear)  uart_update_mctrl(port, 0, clear)
 
 /*
  * Startup the port.  This will be called once per open.  All calls
@@ -290,7 +291,7 @@ uart_update_timeout(struct uart_port *port, unsigned int cflag,
                break;
        default:
                bits = 10;
-               break; // CS8
+               break; /* CS8 */
        }
 
        if (cflag & CSTOPB)
@@ -622,7 +623,7 @@ static int uart_get_info(struct uart_state *state,
        tmp.close_delay     = state->close_delay / 10;
        tmp.closing_wait    = state->closing_wait == USF_CLOSING_WAIT_NONE ?
                                ASYNC_CLOSING_WAIT_NONE :
-                               state->closing_wait / 10;
+                               state->closing_wait / 10;
        tmp.custom_divisor  = port->custom_divisor;
        tmp.hub6            = port->hub6;
        tmp.io_type         = port->iotype;
@@ -788,7 +789,8 @@ static int uart_set_info(struct uart_state *state,
                         * We failed anyway.
                         */
                        retval = -EBUSY;
-                       goto exit;  // Added to return the correct error -Ram Gupta
+                       /* Added to return the correct error -Ram Gupta */
+                       goto exit;
                }
        }
 
@@ -858,7 +860,7 @@ static int uart_get_lsr_info(struct uart_state *state,
            ((uart_circ_chars_pending(&state->info->xmit) > 0) &&
             !state->info->tty->stopped && !state->info->tty->hw_stopped))
                result &= ~TIOCSER_TEMT;
-       
+
        return put_user(result, value);
 }
 
@@ -996,8 +998,8 @@ uart_wait_modem_status(struct uart_state *state, unsigned long arg)
                    ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
                    ((arg & TIOCM_CD)  && (cnow.dcd != cprev.dcd)) ||
                    ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
-                       ret = 0;
-                       break;
+                       ret = 0;
+                       break;
                }
 
                schedule();
@@ -1137,7 +1139,8 @@ uart_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd,
        return ret;
 }
 
-static void uart_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
+static void uart_set_termios(struct tty_struct *tty,
+                                               struct ktermios *old_termios)
 {
        struct uart_state *state = tty->driver_data;
        unsigned long flags;
@@ -1213,7 +1216,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
 {
        struct uart_state *state = tty->driver_data;
        struct uart_port *port;
-       
+
        BUG_ON(!kernel_locked());
 
        if (!state || !state->port)
@@ -1278,8 +1281,8 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
        uart_shutdown(state);
        uart_flush_buffer(tty);
 
-       tty_ldisc_flush(tty);   
-       
+       tty_ldisc_flush(tty);
+
        tty->closing = 0;
        state->info->tty = NULL;
 
@@ -1341,7 +1344,7 @@ static void uart_wait_until_sent(struct tty_struct *tty, int timeout)
        expire = jiffies + timeout;
 
        pr_debug("uart_wait_until_sent(%d), jiffies=%lu, expire=%lu...\n",
-               port->line, jiffies, expire);
+               port->line, jiffies, expire);
 
        /*
         * Check whether the transmitter is empty every 'char_time'.
@@ -1460,10 +1463,9 @@ uart_block_til_ready(struct file *filp, struct uart_state *state)
                 * have set TTY_IO_ERROR for a non-existant port.
                 */
                if ((filp->f_flags & O_NONBLOCK) ||
-                   (info->tty->termios->c_cflag & CLOCAL) ||
-                   (info->tty->flags & (1 << TTY_IO_ERROR))) {
+                   (info->tty->termios->c_cflag & CLOCAL) ||
+                   (info->tty->flags & (1 << TTY_IO_ERROR)))
                        break;
-               }
 
                /*
                 * Set DTR to allow modem to know we're waiting.  Do
@@ -1551,8 +1553,8 @@ static struct uart_state *uart_get(struct uart_driver *drv, int line)
 }
 
 /*
- * In 2.4.5, calls to uart_open are serialised by the BKL in
- *   linux/fs/devices.c:chrdev_open()
+ * calls to uart_open are serialised by the BKL in
+ *   fs/char_dev.c:chrdev_open()
  * Note that if this fails, then uart_close() _will_ be called.
  *
  * In time, we want to scrap the "opening nonpresent ports"
@@ -1674,7 +1676,7 @@ static int uart_line_info(char *buf, struct uart_driver *drv, int i)
                        port->line, uart_type(port),
                        mmio ? "mmio:0x" : "port:",
                        mmio ? (unsigned long long)port->mapbase
-                            : (unsigned long long) port->iobase,
+                            : (unsigned long long) port->iobase,
                        port->irq);
 
        if (port->type == PORT_UNKNOWN) {
@@ -1682,8 +1684,7 @@ static int uart_line_info(char *buf, struct uart_driver *drv, int i)
                return ret + 1;
        }
 
-       if(capable(CAP_SYS_ADMIN))
-       {
+       if (capable(CAP_SYS_ADMIN)) {
                mutex_lock(&state->mutex);
                pm_state = state->pm_state;
                if (pm_state)
@@ -1709,12 +1710,12 @@ static int uart_line_info(char *buf, struct uart_driver *drv, int i)
                if (port->icount.overrun)
                        ret += sprintf(buf + ret, " oe:%d",
                                port->icount.overrun);
-       
-#define INFOBIT(bit,str) \
+
+#define INFOBIT(bit, str) \
        if (port->mctrl & (bit)) \
                strncat(stat_buf, (str), sizeof(stat_buf) - \
                        strlen(stat_buf) - 2)
-#define STATBIT(bit,str) \
+#define STATBIT(bit, str) \
        if (status & (bit)) \
                strncat(stat_buf, (str), sizeof(stat_buf) - \
                       strlen(stat_buf) - 2)
@@ -1730,7 +1731,7 @@ static int uart_line_info(char *buf, struct uart_driver *drv, int i)
                if (stat_buf[0])
                        stat_buf[0] = ' ';
                strcat(stat_buf, "\n");
-       
+
                ret += sprintf(buf + ret, stat_buf);
        } else {
                strcat(buf, "\n");
@@ -1992,11 +1993,11 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *port)
                /*
                 * Wait for the transmitter to empty.
                 */
-               for (tries = 3; !ops->tx_empty(port) && tries; tries--) {
+               for (tries = 3; !ops->tx_empty(port) && tries; tries--)
                        msleep(10);
-               }
                if (!tries)
-                       printk(KERN_ERR "%s%s%s%d: Unable to drain transmitter\n",
+                       printk(KERN_ERR "%s%s%s%d: Unable to drain "
+                                       "transmitter\n",
                               port->dev ? port->dev->bus_id : "",
                               port->dev ? ": " : "",
                               drv->dev_name, port->line);
index 9b3f612000009fc9239d9f549b4a0eab8cd13498..69f19f22487566e2e12110236c550265da7b7ff5 100644 (file)
@@ -9,7 +9,7 @@ menuconfig THERMAL
          Generic Thermal Sysfs driver offers a generic mechanism for
          thermal management. Usually it's made up of one or more thermal
          zone and cooling device.
-         each thermal zone contains its own temperature, trip points,
+         Each thermal zone contains its own temperature, trip points,
          cooling devices.
          All platforms with ACPI thermal support can use this driver.
-         If you want this support, you should say Y here
+         If you want this support, you should say Y here.
index 3273e348fd14584d1173001b12688eb2ce3c1e14..e782b3e7fcdb01c8b525e845e565538143bd2012 100644 (file)
@@ -267,7 +267,7 @@ thermal_cooling_device_cur_state_store(struct device *dev,
 }
 
 static struct device_attribute dev_attr_cdev_type =
-               __ATTR(type, 0444, thermal_cooling_device_type_show, NULL);
+__ATTR(type, 0444, thermal_cooling_device_type_show, NULL);
 static DEVICE_ATTR(max_state, 0444,
                   thermal_cooling_device_max_state_show, NULL);
 static DEVICE_ATTR(cur_state, 0644,
@@ -276,7 +276,7 @@ static DEVICE_ATTR(cur_state, 0644,
 
 static ssize_t
 thermal_cooling_device_trip_point_show(struct device *dev,
-                                   struct device_attribute *attr, char *buf)
+                                      struct device_attribute *attr, char *buf)
 {
        struct thermal_cooling_device_instance *instance;
 
@@ -293,11 +293,12 @@ thermal_cooling_device_trip_point_show(struct device *dev,
 
 /**
  * thermal_zone_bind_cooling_device - bind a cooling device to a thermal zone
- * this function is usually called in the thermal zone device .bind callback.
  * @tz:                thermal zone device
  * @trip:      indicates which trip point the cooling devices is
  *             associated with in this thermal zone.
  * @cdev:      thermal cooling device
+ *
+ * This function is usually called in the thermal zone device .bind callback.
  */
 int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
                                     int trip,
@@ -307,8 +308,7 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
        struct thermal_cooling_device_instance *pos;
        int result;
 
-       if (trip >= tz->trips ||
-           (trip < 0 && trip != THERMAL_TRIPS_NONE))
+       if (trip >= tz->trips || (trip < 0 && trip != THERMAL_TRIPS_NONE))
                return -EINVAL;
 
        if (!tz || !cdev)
@@ -361,15 +361,17 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
        kfree(dev);
        return result;
 }
+
 EXPORT_SYMBOL(thermal_zone_bind_cooling_device);
 
 /**
  * thermal_zone_unbind_cooling_device - unbind a cooling device from a thermal zone
- * this function is usually called in the thermal zone device .unbind callback.
  * @tz:                thermal zone device
  * @trip:      indicates which trip point the cooling devices is
  *             associated with in this thermal zone.
  * @cdev:      thermal cooling device
+ *
+ * This function is usually called in the thermal zone device .unbind callback.
  */
 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
                                       int trip,
@@ -379,8 +381,7 @@ int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
 
        mutex_lock(&tz->lock);
        list_for_each_entry_safe(pos, next, &tz->cooling_devices, node) {
-               if (pos->tz == tz && pos->trip == trip
-                   && pos->cdev == cdev) {
+               if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
                        list_del(&pos->node);
                        mutex_unlock(&tz->lock);
                        goto unbind;
@@ -397,6 +398,7 @@ int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
        kfree(pos);
        return 0;
 }
+
 EXPORT_SYMBOL(thermal_zone_unbind_cooling_device);
 
 static void thermal_release(struct device *dev)
@@ -425,7 +427,10 @@ static struct class thermal_class = {
  * @ops:               standard thermal cooling devices callbacks.
  */
 struct thermal_cooling_device *thermal_cooling_device_register(char *type,
-                      void *devdata, struct thermal_cooling_device_ops *ops)
+                                                              void *devdata,
+                                                              struct
+                                                              thermal_cooling_device_ops
+                                                              *ops)
 {
        struct thermal_cooling_device *cdev;
        struct thermal_zone_device *pos;
@@ -435,7 +440,7 @@ struct thermal_cooling_device *thermal_cooling_device_register(char *type,
                return NULL;
 
        if (!ops || !ops->get_max_state || !ops->get_cur_state ||
-               !ops->set_cur_state)
+           !ops->set_cur_state)
                return NULL;
 
        cdev = kzalloc(sizeof(struct thermal_cooling_device), GFP_KERNEL);
@@ -462,8 +467,7 @@ struct thermal_cooling_device *thermal_cooling_device_register(char *type,
 
        /* sys I/F */
        if (type) {
-               result = device_create_file(&cdev->device,
-                                           &dev_attr_cdev_type);
+               result = device_create_file(&cdev->device, &dev_attr_cdev_type);
                if (result)
                        goto unregister;
        }
@@ -496,11 +500,11 @@ struct thermal_cooling_device *thermal_cooling_device_register(char *type,
        device_unregister(&cdev->device);
        return NULL;
 }
+
 EXPORT_SYMBOL(thermal_cooling_device_register);
 
 /**
  * thermal_cooling_device_unregister - removes the registered thermal cooling device
- *
  * @cdev:      the thermal cooling device to remove.
  *
  * thermal_cooling_device_unregister() must be called when the device is no
@@ -533,8 +537,7 @@ void thermal_cooling_device_unregister(struct
        }
        mutex_unlock(&thermal_list_lock);
        if (cdev->type[0])
-               device_remove_file(&cdev->device,
-                                  &dev_attr_cdev_type);
+               device_remove_file(&cdev->device, &dev_attr_cdev_type);
        device_remove_file(&cdev->device, &dev_attr_max_state);
        device_remove_file(&cdev->device, &dev_attr_cur_state);
 
@@ -542,6 +545,7 @@ void thermal_cooling_device_unregister(struct
        device_unregister(&cdev->device);
        return;
 }
+
 EXPORT_SYMBOL(thermal_cooling_device_unregister);
 
 /**
@@ -555,8 +559,10 @@ EXPORT_SYMBOL(thermal_cooling_device_unregister);
  * longer needed.
  */
 struct thermal_zone_device *thermal_zone_device_register(char *type,
-                                       int trips, void *devdata,
-                                       struct thermal_zone_device_ops *ops)
+                                                        int trips,
+                                                        void *devdata, struct
+                                                        thermal_zone_device_ops
+                                                        *ops)
 {
        struct thermal_zone_device *tz;
        struct thermal_cooling_device *pos;
@@ -625,9 +631,9 @@ struct thermal_zone_device *thermal_zone_device_register(char *type,
        list_add_tail(&tz->node, &thermal_tz_list);
        if (ops->bind)
                list_for_each_entry(pos, &thermal_cdev_list, node) {
-                       result = ops->bind(tz, pos);
-                       if (result)
-                               break;
+               result = ops->bind(tz, pos);
+               if (result)
+                       break;
                }
        mutex_unlock(&thermal_list_lock);
 
@@ -639,11 +645,11 @@ struct thermal_zone_device *thermal_zone_device_register(char *type,
        device_unregister(&tz->device);
        return NULL;
 }
+
 EXPORT_SYMBOL(thermal_zone_device_register);
 
 /**
  * thermal_device_unregister - removes the registered thermal zone device
- *
  * @tz: the thermal zone device to remove
  */
 void thermal_zone_device_unregister(struct thermal_zone_device *tz)
@@ -685,6 +691,7 @@ void thermal_zone_device_unregister(struct thermal_zone_device *tz)
        device_unregister(&tz->device);
        return;
 }
+
 EXPORT_SYMBOL(thermal_zone_device_unregister);
 
 static int __init thermal_init(void)
index 33469cf5aec35af86933b39d3781a409ffc9f97c..e01862300169772d714a6ab24a4db9938825fd9d 100644 (file)
@@ -1418,8 +1418,8 @@ show_function (struct device *_dev, struct device_attribute *attr, char *buf)
 }
 static DEVICE_ATTR (function, S_IRUGO, show_function, NULL);
 
-static ssize_t
-show_registers (struct device *_dev, struct device_attribute *attr, char *buf)
+static ssize_t net2280_show_registers(struct device *_dev,
+                               struct device_attribute *attr, char *buf)
 {
        struct net2280          *dev;
        char                    *next;
@@ -1571,7 +1571,7 @@ show_registers (struct device *_dev, struct device_attribute *attr, char *buf)
 
        return PAGE_SIZE - size;
 }
-static DEVICE_ATTR (registers, S_IRUGO, show_registers, NULL);
+static DEVICE_ATTR(registers, S_IRUGO, net2280_show_registers, NULL);
 
 static ssize_t
 show_queues (struct device *_dev, struct device_attribute *attr, char *buf)
index 2b53d1f5628107b65d559e97cf5fc8007f41a6df..06f87b04f207750074a5253cbf991df7405a9071 100644 (file)
@@ -6,7 +6,7 @@ menu "Console display driver support"
 
 config VGA_CONSOLE
        bool "VGA text console" if EMBEDDED || !X86
-       depends on !ARCH_ACORN && !ARCH_EBSA110 && !4xx && !8xx && !SPARC && !M68K && !PARISC && !FRV && !ARCH_VERSATILE && !SUPERH && !BLACKFIN && !AVR32
+       depends on !ARCH_ACORN && !ARCH_EBSA110 && !4xx && !8xx && !SPARC && !M68K && !PARISC && !FRV && !ARCH_VERSATILE && !SUPERH && !BLACKFIN && !AVR32 && !MN10300
        default y
        help
          Saying Y here will allow you to use Linux in text mode through a
index 3bf6ace1720c6230a1b44f884685c8f383541cdd..d7312825592bd33e84cff35805a5430aebfb4220 100644 (file)
@@ -1778,12 +1778,9 @@ config SUNRPC_GSS
        tristate
 
 config SUNRPC_XPRT_RDMA
-       tristate "RDMA transport for sunrpc (EXPERIMENTAL)"
+       tristate
        depends on SUNRPC && INFINIBAND && EXPERIMENTAL
-       default m
-       help
-         Adds a client RPC transport for supporting kernel NFS over RDMA
-         mounts, including Infiniband and iWARP. Experimental.
+       default SUNRPC && INFINIBAND
 
 config SUNRPC_BIND34
        bool "Support for rpcbind versions 3 & 4 (EXPERIMENTAL)"
index 7c3d5f923da1c4f0d4d2f06392e3151649625cd3..b5c3b6114add3860febc8b1c20fc9287be5e4f52 100644 (file)
@@ -61,7 +61,8 @@ config BINFMT_SHARED_FLAT
 
 config BINFMT_AOUT
        tristate "Kernel support for a.out and ECOFF binaries"
-       depends on X86_32 || ALPHA || ARM || M68K || SPARC32
+       depends on ARCH_SUPPORTS_AOUT && \
+               (X86_32 || ALPHA || ARM || M68K || SPARC32)
        ---help---
          A.out (Assembler.OUTput) is a set of formats for libraries and
          executables used in the earliest versions of UNIX.  Linux used
index b36695ae5c2e9ff97b06ae999f0f1baaf01dd333..9e421eeb672bed6ae53f85ff9a4eaf7cdcf92c92 100644 (file)
@@ -20,6 +20,8 @@
 #include <linux/vfs.h>
 #include <linux/parser.h>
 #include <linux/bitops.h>
+#include <linux/mount.h>
+#include <linux/seq_file.h>
 
 #include <asm/uaccess.h>
 #include <asm/system.h>
@@ -30,6 +32,9 @@
 #include "dir_f.h"
 #include "dir_fplus.h"
 
+#define ADFS_DEFAULT_OWNER_MASK S_IRWXU
+#define ADFS_DEFAULT_OTHER_MASK (S_IRWXG | S_IRWXO)
+
 void __adfs_error(struct super_block *sb, const char *function, const char *fmt, ...)
 {
        char error_buf[128];
@@ -134,6 +139,22 @@ static void adfs_put_super(struct super_block *sb)
        sb->s_fs_info = NULL;
 }
 
+static int adfs_show_options(struct seq_file *seq, struct vfsmount *mnt)
+{
+       struct adfs_sb_info *asb = ADFS_SB(mnt->mnt_sb);
+
+       if (asb->s_uid != 0)
+               seq_printf(seq, ",uid=%u", asb->s_uid);
+       if (asb->s_gid != 0)
+               seq_printf(seq, ",gid=%u", asb->s_gid);
+       if (asb->s_owner_mask != ADFS_DEFAULT_OWNER_MASK)
+               seq_printf(seq, ",ownmask=%o", asb->s_owner_mask);
+       if (asb->s_other_mask != ADFS_DEFAULT_OTHER_MASK)
+               seq_printf(seq, ",othmask=%o", asb->s_other_mask);
+
+       return 0;
+}
+
 enum {Opt_uid, Opt_gid, Opt_ownmask, Opt_othmask, Opt_err};
 
 static match_table_t tokens = {
@@ -259,6 +280,7 @@ static const struct super_operations adfs_sops = {
        .put_super      = adfs_put_super,
        .statfs         = adfs_statfs,
        .remount_fs     = adfs_remount,
+       .show_options   = adfs_show_options,
 };
 
 static struct adfs_discmap *adfs_read_map(struct super_block *sb, struct adfs_discrecord *dr)
@@ -344,8 +366,8 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent)
        /* set default options */
        asb->s_uid = 0;
        asb->s_gid = 0;
-       asb->s_owner_mask = S_IRWXU;
-       asb->s_other_mask = S_IRWXG | S_IRWXO;
+       asb->s_owner_mask = ADFS_DEFAULT_OWNER_MASK;
+       asb->s_other_mask = ADFS_DEFAULT_OTHER_MASK;
 
        if (parse_options(sb, data))
                goto error;
index 3c45d49c0d26046780c79e9d15da0a1e39550f68..d2dc047cb4796b4a879606e60349ec4eb55a79ae 100644 (file)
@@ -122,6 +122,7 @@ static const struct super_operations affs_sops = {
        .write_super    = affs_write_super,
        .statfs         = affs_statfs,
        .remount_fs     = affs_remount,
+       .show_options   = generic_show_options,
 };
 
 enum {
@@ -272,6 +273,8 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent)
        u8                       sig[4];
        int                      ret = -EINVAL;
 
+       save_mount_options(sb, data);
+
        pr_debug("AFFS: read_super(%s)\n",data ? (const char *)data : "no options");
 
        sb->s_magic             = AFFS_SUPER_MAGIC;
@@ -487,14 +490,21 @@ affs_remount(struct super_block *sb, int *flags, char *data)
        int                      root_block;
        unsigned long            mount_flags;
        int                      res = 0;
+       char                    *new_opts = kstrdup(data, GFP_KERNEL);
 
        pr_debug("AFFS: remount(flags=0x%x,opts=\"%s\")\n",*flags,data);
 
        *flags |= MS_NODIRATIME;
 
-       if (!parse_options(data,&uid,&gid,&mode,&reserved,&root_block,
-           &blocksize,&sbi->s_prefix,sbi->s_volume,&mount_flags))
+       if (!parse_options(data, &uid, &gid, &mode, &reserved, &root_block,
+                          &blocksize, &sbi->s_prefix, sbi->s_volume,
+                          &mount_flags)) {
+               kfree(new_opts);
                return -EINVAL;
+       }
+       kfree(sb->s_options);
+       sb->s_options = new_opts;
+
        sbi->s_flags = mount_flags;
        sbi->s_mode  = mode;
        sbi->s_uid   = uid;
index 9446a1fd108a35452579df735f4877f6ad992a6f..3bcbeceba1bb6a778b08328ea459023927a2ccc8 100644 (file)
@@ -287,7 +287,7 @@ static int afs_check_permit(struct afs_vnode *vnode, struct key *key,
 int afs_permission(struct inode *inode, int mask, struct nameidata *nd)
 {
        struct afs_vnode *vnode = AFS_FS_I(inode);
-       afs_access_t access;
+       afs_access_t uninitialized_var(access);
        struct key *key;
        int ret;
 
index 4b2558c42213c5e79328fe71ef0b2380f07b8405..36bbce45f44b40248352b433b460a116c7dccfa6 100644 (file)
@@ -52,6 +52,7 @@ static const struct super_operations afs_super_ops = {
        .clear_inode    = afs_clear_inode,
        .umount_begin   = afs_umount_begin,
        .put_super      = afs_put_super,
+       .show_options   = generic_show_options,
 };
 
 static struct kmem_cache *afs_inode_cachep;
@@ -357,6 +358,7 @@ static int afs_get_sb(struct file_system_type *fs_type,
        struct super_block *sb;
        struct afs_volume *vol;
        struct key *key;
+       char *new_opts = kstrdup(options, GFP_KERNEL);
        int ret;
 
        _enter(",,%s,%p", dev_name, options);
@@ -408,9 +410,11 @@ static int afs_get_sb(struct file_system_type *fs_type,
                        deactivate_super(sb);
                        goto error;
                }
+               sb->s_options = new_opts;
                sb->s_flags |= MS_ACTIVE;
        } else {
                _debug("reuse");
+               kfree(new_opts);
                ASSERTCMP(sb->s_flags, &, MS_ACTIVE);
        }
 
@@ -424,6 +428,7 @@ error:
        afs_put_volume(params.volume);
        afs_put_cell(params.cell);
        key_put(params.key);
+       kfree(new_opts);
        _leave(" = %d", ret);
        return ret;
 }
index 8a37dbbf3437cb78021c22c608dc8beb4cbe2788..b74c567383bc3689412a6195cb5fd4e2520cb724 100644 (file)
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -317,7 +317,7 @@ out:
 /* wait_on_sync_kiocb:
  *     Waits on the given sync kiocb to complete.
  */
-ssize_t fastcall wait_on_sync_kiocb(struct kiocb *iocb)
+ssize_t wait_on_sync_kiocb(struct kiocb *iocb)
 {
        while (iocb->ki_users) {
                set_current_state(TASK_UNINTERRUPTIBLE);
@@ -336,7 +336,7 @@ ssize_t fastcall wait_on_sync_kiocb(struct kiocb *iocb)
  * go away, they will call put_ioctx and release any pinned memory
  * associated with the request (held via struct page * references).
  */
-void fastcall exit_aio(struct mm_struct *mm)
+void exit_aio(struct mm_struct *mm)
 {
        struct kioctx *ctx = mm->ioctx_list;
        mm->ioctx_list = NULL;
@@ -365,7 +365,7 @@ void fastcall exit_aio(struct mm_struct *mm)
  *     Called when the last user of an aio context has gone away,
  *     and the struct needs to be freed.
  */
-void fastcall __put_ioctx(struct kioctx *ctx)
+void __put_ioctx(struct kioctx *ctx)
 {
        unsigned nr_events = ctx->max_reqs;
 
@@ -397,8 +397,7 @@ void fastcall __put_ioctx(struct kioctx *ctx)
  * This prevents races between the aio code path referencing the
  * req (after submitting it) and aio_complete() freeing the req.
  */
-static struct kiocb *__aio_get_req(struct kioctx *ctx);
-static struct kiocb fastcall *__aio_get_req(struct kioctx *ctx)
+static struct kiocb *__aio_get_req(struct kioctx *ctx)
 {
        struct kiocb *req = NULL;
        struct aio_ring *ring;
@@ -533,7 +532,7 @@ static int __aio_put_req(struct kioctx *ctx, struct kiocb *req)
  *     Returns true if this put was the last user of the kiocb,
  *     false if the request is still in use.
  */
-int fastcall aio_put_req(struct kiocb *req)
+int aio_put_req(struct kiocb *req)
 {
        struct kioctx *ctx = req->ki_ctx;
        int ret;
@@ -893,7 +892,7 @@ static void try_queue_kicked_iocb(struct kiocb *iocb)
  *      The retry is usually executed by aio workqueue
  *      threads (See aio_kick_handler).
  */
-void fastcall kick_iocb(struct kiocb *iocb)
+void kick_iocb(struct kiocb *iocb)
 {
        /* sync iocbs are easy: they can only ever be executing from a 
         * single context. */
@@ -912,7 +911,7 @@ EXPORT_SYMBOL(kick_iocb);
  *     Returns true if this is the last user of the request.  The 
  *     only other user of the request can be the cancellation code.
  */
-int fastcall aio_complete(struct kiocb *iocb, long res, long res2)
+int aio_complete(struct kiocb *iocb, long res, long res2)
 {
        struct kioctx   *ctx = iocb->ki_ctx;
        struct aio_ring_info    *info;
@@ -1330,6 +1329,10 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb)
                opcode = IOCB_CMD_PWRITEV;
        }
 
+       /* This matches the pread()/pwrite() logic */
+       if (iocb->ki_pos < 0)
+               return -EINVAL;
+
        do {
                ret = rw_op(iocb, &iocb->ki_iovec[iocb->ki_cur_seg],
                            iocb->ki_nr_segs - iocb->ki_cur_seg,
@@ -1348,6 +1351,13 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb)
        if ((ret == 0) || (iocb->ki_left == 0))
                ret = iocb->ki_nbytes - iocb->ki_left;
 
+       /* If we managed to write some out we return that, rather than
+        * the eventual error. */
+       if (opcode == IOCB_CMD_PWRITEV
+           && ret < 0 && ret != -EIOCBQUEUED && ret != -EIOCBRETRY
+           && iocb->ki_nbytes - iocb->ki_left)
+               ret = iocb->ki_nbytes - iocb->ki_left;
+
        return ret;
 }
 
@@ -1523,7 +1533,7 @@ static int aio_wake_function(wait_queue_t *wait, unsigned mode,
        return 1;
 }
 
-int fastcall io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
+int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
                         struct iocb *iocb)
 {
        struct kiocb *req;
index 708bdb89fea14782c625e14c04e63902003b442b..dda510d31f840dbba96834619a668f723bc99e16 100644 (file)
@@ -54,6 +54,7 @@ out_kill_sb:
 
 static const struct super_operations autofs_sops = {
        .statfs         = simple_statfs,
+       .show_options   = generic_show_options,
 };
 
 enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto};
@@ -140,6 +141,8 @@ int autofs_fill_super(struct super_block *s, void *data, int silent)
        int minproto, maxproto;
        pid_t pgid;
 
+       save_mount_options(s, data);
+
        sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
        if (!sbi)
                goto fail_unlock;
index 7f05d6ccdb130c8171a80af52c7266ebb14bc2f6..2fdcf5e1d236a7d309283c009ed67ecda6796bcb 100644 (file)
@@ -176,11 +176,16 @@ out_kill_sb:
 static int autofs4_show_options(struct seq_file *m, struct vfsmount *mnt)
 {
        struct autofs_sb_info *sbi = autofs4_sbi(mnt->mnt_sb);
+       struct inode *root_inode = mnt->mnt_sb->s_root->d_inode;
 
        if (!sbi)
                return 0;
 
        seq_printf(m, ",fd=%d", sbi->pipefd);
+       if (root_inode->i_uid != 0)
+               seq_printf(m, ",uid=%u", root_inode->i_uid);
+       if (root_inode->i_gid != 0)
+               seq_printf(m, ",gid=%u", root_inode->i_gid);
        seq_printf(m, ",pgrp=%d", sbi->oz_pgrp);
        seq_printf(m, ",timeout=%lu", sbi->exp_timeout/HZ);
        seq_printf(m, ",minproto=%d", sbi->min_proto);
index 403fe661c14474a49636394a4e74505e1ec7e142..82123ff3e1dd744db3d766769fafd53d2e133a32 100644 (file)
@@ -57,6 +57,7 @@ static const struct super_operations befs_sops = {
        .put_super      = befs_put_super,       /* uninit super */
        .statfs         = befs_statfs,  /* statfs */
        .remount_fs     = befs_remount,
+       .show_options   = generic_show_options,
 };
 
 /* slab cache for befs_inode_info objects */
@@ -759,10 +760,11 @@ befs_fill_super(struct super_block *sb, void *data, int silent)
        befs_super_block *disk_sb;
        struct inode *root;
        long ret = -EINVAL;
-
        const unsigned long sb_block = 0;
        const off_t x86_sb_off = 512;
 
+       save_mount_options(sb, data);
+
        sb->s_fs_info = kmalloc(sizeof (*befs_sb), GFP_KERNEL);
        if (sb->s_fs_info == NULL) {
                printk(KERN_ERR
index 7f65e71bf8595b6f5c5047dc86d26236b933c63c..a1bb2244cac772dd31dd8caff79b99fcead5ac3d 100644 (file)
@@ -28,6 +28,7 @@
 #include <asm/system.h>
 #include <asm/uaccess.h>
 #include <asm/cacheflush.h>
+#include <asm/a.out-core.h>
 
 static int load_aout_binary(struct linux_binprm *, struct pt_regs * regs);
 static int load_aout_library(struct file*);
@@ -118,7 +119,7 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file, u
        dump.u_ar0 = offsetof(struct user, regs);
 #endif
        dump.signal = signr;
-       dump_thread(regs, &dump);
+       aout_dump_thread(regs, &dump);
 
 /* If the size of the dump file exceeds the rlimit, then see what would happen
    if we wrote the stack, but not the data area.  */
index 111771d38e6e2d457aa939ba35dafaee5dd28db3..41a958a7585e750cd800b2d229d5b3b2a04f0898 100644 (file)
@@ -134,8 +134,7 @@ static int padzero(unsigned long elf_bss)
 
 static int
 create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
-               int interp_aout, unsigned long load_addr,
-               unsigned long interp_load_addr)
+               unsigned long load_addr, unsigned long interp_load_addr)
 {
        unsigned long p = bprm->p;
        int argc = bprm->argc;
@@ -223,12 +222,7 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
 
        sp = STACK_ADD(p, ei_index);
 
-       items = (argc + 1) + (envc + 1);
-       if (interp_aout) {
-               items += 3; /* a.out interpreters require argv & envp too */
-       } else {
-               items += 1; /* ELF interpreters only put argc on the stack */
-       }
+       items = (argc + 1) + (envc + 1) + 1;
        bprm->p = STACK_ROUND(sp, items);
 
        /* Point sp at the lowest address on the stack */
@@ -251,16 +245,8 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
        /* Now, let's put argc (and argv, envp if appropriate) on the stack */
        if (__put_user(argc, sp++))
                return -EFAULT;
-       if (interp_aout) {
-               argv = sp + 2;
-               envp = argv + argc + 1;
-               if (__put_user((elf_addr_t)(unsigned long)argv, sp++) ||
-                   __put_user((elf_addr_t)(unsigned long)envp, sp++))
-                       return -EFAULT;
-       } else {
-               argv = sp;
-               envp = argv + argc + 1;
-       }
+       argv = sp;
+       envp = argv + argc + 1;
 
        /* Populate argv and envp */
        p = current->mm->arg_end = current->mm->arg_start;
@@ -513,59 +499,12 @@ out:
        return error;
 }
 
-static unsigned long load_aout_interp(struct exec *interp_ex,
-               struct file *interpreter)
-{
-       unsigned long text_data, elf_entry = ~0UL;
-       char __user * addr;
-       loff_t offset;
-
-       current->mm->end_code = interp_ex->a_text;
-       text_data = interp_ex->a_text + interp_ex->a_data;
-       current->mm->end_data = text_data;
-       current->mm->brk = interp_ex->a_bss + text_data;
-
-       switch (N_MAGIC(*interp_ex)) {
-       case OMAGIC:
-               offset = 32;
-               addr = (char __user *)0;
-               break;
-       case ZMAGIC:
-       case QMAGIC:
-               offset = N_TXTOFF(*interp_ex);
-               addr = (char __user *)N_TXTADDR(*interp_ex);
-               break;
-       default:
-               goto out;
-       }
-
-       down_write(&current->mm->mmap_sem);     
-       do_brk(0, text_data);
-       up_write(&current->mm->mmap_sem);
-       if (!interpreter->f_op || !interpreter->f_op->read)
-               goto out;
-       if (interpreter->f_op->read(interpreter, addr, text_data, &offset) < 0)
-               goto out;
-       flush_icache_range((unsigned long)addr,
-                          (unsigned long)addr + text_data);
-
-       down_write(&current->mm->mmap_sem);     
-       do_brk(ELF_PAGESTART(text_data + ELF_MIN_ALIGN - 1),
-               interp_ex->a_bss);
-       up_write(&current->mm->mmap_sem);
-       elf_entry = interp_ex->a_entry;
-
-out:
-       return elf_entry;
-}
-
 /*
  * These are the functions used to load ELF style executables and shared
  * libraries.  There is no binary dependent code anywhere else.
  */
 
 #define INTERPRETER_NONE 0
-#define INTERPRETER_AOUT 1
 #define INTERPRETER_ELF 2
 
 #ifndef STACK_RND_MASK
@@ -594,7 +533,6 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
        unsigned long load_addr = 0, load_bias = 0;
        int load_addr_set = 0;
        char * elf_interpreter = NULL;
-       unsigned int interpreter_type = INTERPRETER_NONE;
        unsigned long error;
        struct elf_phdr *elf_ppnt, *elf_phdata;
        unsigned long elf_bss, elf_brk;
@@ -605,7 +543,6 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
        unsigned long interp_load_addr = 0;
        unsigned long start_code, end_code, start_data, end_data;
        unsigned long reloc_func_desc = 0;
-       char passed_fileno[6];
        struct files_struct *files;
        int executable_stack = EXSTACK_DEFAULT;
        unsigned long def_flags = 0;
@@ -774,59 +711,18 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
 
        /* Some simple consistency checks for the interpreter */
        if (elf_interpreter) {
-               static int warn;
-               interpreter_type = INTERPRETER_ELF | INTERPRETER_AOUT;
-
-               /* Now figure out which format our binary is */
-               if ((N_MAGIC(loc->interp_ex) != OMAGIC) &&
-                   (N_MAGIC(loc->interp_ex) != ZMAGIC) &&
-                   (N_MAGIC(loc->interp_ex) != QMAGIC))
-                       interpreter_type = INTERPRETER_ELF;
-
-               if (memcmp(loc->interp_elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
-                       interpreter_type &= ~INTERPRETER_ELF;
-
-               if (interpreter_type == INTERPRETER_AOUT && warn < 10) {
-                       printk(KERN_WARNING "a.out ELF interpreter %s is "
-                               "deprecated and will not be supported "
-                               "after Linux 2.6.25\n", elf_interpreter);
-                       warn++;
-               }
-
                retval = -ELIBBAD;
-               if (!interpreter_type)
+               /* Not an ELF interpreter */
+               if (memcmp(loc->interp_elf_ex.e_ident, ELFMAG, SELFMAG) != 0)
                        goto out_free_dentry;
-
-               /* Make sure only one type was selected */
-               if ((interpreter_type & INTERPRETER_ELF) &&
-                    interpreter_type != INTERPRETER_ELF) {
-                       // FIXME - ratelimit this before re-enabling
-                       // printk(KERN_WARNING "ELF: Ambiguous type, using ELF\n");
-                       interpreter_type = INTERPRETER_ELF;
-               }
                /* Verify the interpreter has a valid arch */
-               if ((interpreter_type == INTERPRETER_ELF) &&
-                   !elf_check_arch(&loc->interp_elf_ex))
+               if (!elf_check_arch(&loc->interp_elf_ex))
                        goto out_free_dentry;
        } else {
                /* Executables without an interpreter also need a personality  */
                SET_PERSONALITY(loc->elf_ex, 0);
        }
 
-       /* OK, we are done with that, now set up the arg stuff,
-          and then start this sucker up */
-       if ((!bprm->sh_bang) && (interpreter_type == INTERPRETER_AOUT)) {
-               char *passed_p = passed_fileno;
-               sprintf(passed_fileno, "%d", elf_exec_fileno);
-
-               if (elf_interpreter) {
-                       retval = copy_strings_kernel(1, &passed_p, bprm);
-                       if (retval)
-                               goto out_free_dentry; 
-                       bprm->argc++;
-               }
-       }
-
        /* Flush all traces of the currently running executable */
        retval = flush_old_exec(bprm);
        if (retval)
@@ -1004,24 +900,19 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
        }
 
        if (elf_interpreter) {
-               if (interpreter_type == INTERPRETER_AOUT) {
-                       elf_entry = load_aout_interp(&loc->interp_ex,
-                                                    interpreter);
-               } else {
-                       unsigned long uninitialized_var(interp_map_addr);
-
-                       elf_entry = load_elf_interp(&loc->interp_elf_ex,
-                                                   interpreter,
-                                                   &interp_map_addr,
-                                                   load_bias);
-                       if (!IS_ERR((void *)elf_entry)) {
-                               /*
-                                * load_elf_interp() returns relocation
-                                * adjustment
-                                */
-                               interp_load_addr = elf_entry;
-                               elf_entry += loc->interp_elf_ex.e_entry;
-                       }
+               unsigned long uninitialized_var(interp_map_addr);
+
+               elf_entry = load_elf_interp(&loc->interp_elf_ex,
+                                           interpreter,
+                                           &interp_map_addr,
+                                           load_bias);
+               if (!IS_ERR((void *)elf_entry)) {
+                       /*
+                        * load_elf_interp() returns relocation
+                        * adjustment
+                        */
+                       interp_load_addr = elf_entry;
+                       elf_entry += loc->interp_elf_ex.e_entry;
                }
                if (BAD_ADDR(elf_entry)) {
                        force_sig(SIGSEGV, current);
@@ -1045,8 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
 
        kfree(elf_phdata);
 
-       if (interpreter_type != INTERPRETER_AOUT)
-               sys_close(elf_exec_fileno);
+       sys_close(elf_exec_fileno);
 
        set_binfmt(&elf_format);
 
@@ -1061,15 +951,12 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
        compute_creds(bprm);
        current->flags &= ~PF_FORKNOEXEC;
        retval = create_elf_tables(bprm, &loc->elf_ex,
-                         (interpreter_type == INTERPRETER_AOUT),
                          load_addr, interp_load_addr);
        if (retval < 0) {
                send_sig(SIGKILL, current, 0);
                goto out;
        }
        /* N.B. passed_fileno might not be initialized? */
-       if (interpreter_type == INTERPRETER_AOUT)
-               current->mm->arg_start += strlen(passed_fileno) + 1;
        current->mm->end_code = end_code;
        current->mm->start_code = start_code;
        current->mm->start_data = start_data;
index 33764fd6db66122ff36b52fba3ebf95f26d4a5d7..d8a02f1e08ccbc16ba10c0be505d97237f5d21c0 100644 (file)
@@ -20,7 +20,6 @@
 #include <linux/sched.h>
 #include <linux/mm.h>
 #include <linux/mman.h>
-#include <linux/a.out.h>
 #include <linux/errno.h>
 #include <linux/signal.h>
 #include <linux/string.h>
index 9208c41209f9a1b21c93ee74f7981346740fa844..14c63527c762d8cdc8fc443dec512bd4f34e194f 100644 (file)
@@ -29,7 +29,6 @@
 #include <linux/personality.h>
 #include <linux/init.h>
 
-#include <asm/a.out.h>
 #include <asm/uaccess.h>
 #include <asm/pgtable.h>
 
index 826baf4f04bc738fdfea27f6652bc3c0bfe9969d..3ebccf4aa7e3280318b4ae8fbd2b28514d929749 100644 (file)
@@ -67,14 +67,14 @@ static int sync_buffer(void *word)
        return 0;
 }
 
-void fastcall __lock_buffer(struct buffer_head *bh)
+void __lock_buffer(struct buffer_head *bh)
 {
        wait_on_bit_lock(&bh->b_state, BH_Lock, sync_buffer,
                                                        TASK_UNINTERRUPTIBLE);
 }
 EXPORT_SYMBOL(__lock_buffer);
 
-void fastcall unlock_buffer(struct buffer_head *bh)
+void unlock_buffer(struct buffer_head *bh)
 {
        smp_mb__before_clear_bit();
        clear_buffer_locked(bh);
@@ -678,7 +678,7 @@ void mark_buffer_dirty_inode(struct buffer_head *bh, struct inode *inode)
        } else {
                BUG_ON(mapping->assoc_mapping != buffer_mapping);
        }
-       if (list_empty(&bh->b_assoc_buffers)) {
+       if (!bh->b_assoc_map) {
                spin_lock(&buffer_mapping->private_lock);
                list_move_tail(&bh->b_assoc_buffers,
                                &mapping->private_list);
@@ -794,6 +794,7 @@ static int fsync_buffers_list(spinlock_t *lock, struct list_head *list)
 {
        struct buffer_head *bh;
        struct list_head tmp;
+       struct address_space *mapping;
        int err = 0, err2;
 
        INIT_LIST_HEAD(&tmp);
@@ -801,9 +802,14 @@ static int fsync_buffers_list(spinlock_t *lock, struct list_head *list)
        spin_lock(lock);
        while (!list_empty(list)) {
                bh = BH_ENTRY(list->next);
+               mapping = bh->b_assoc_map;
                __remove_assoc_queue(bh);
+               /* Avoid race with mark_buffer_dirty_inode() which does
+                * a lockless check and we rely on seeing the dirty bit */
+               smp_mb();
                if (buffer_dirty(bh) || buffer_locked(bh)) {
                        list_add(&bh->b_assoc_buffers, &tmp);
+                       bh->b_assoc_map = mapping;
                        if (buffer_dirty(bh)) {
                                get_bh(bh);
                                spin_unlock(lock);
@@ -822,8 +828,17 @@ static int fsync_buffers_list(spinlock_t *lock, struct list_head *list)
 
        while (!list_empty(&tmp)) {
                bh = BH_ENTRY(tmp.prev);
-               list_del_init(&bh->b_assoc_buffers);
                get_bh(bh);
+               mapping = bh->b_assoc_map;
+               __remove_assoc_queue(bh);
+               /* Avoid race with mark_buffer_dirty_inode() which does
+                * a lockless check and we rely on seeing the dirty bit */
+               smp_mb();
+               if (buffer_dirty(bh)) {
+                       list_add(&bh->b_assoc_buffers,
+                                &bh->b_assoc_map->private_list);
+                       bh->b_assoc_map = mapping;
+               }
                spin_unlock(lock);
                wait_on_buffer(bh);
                if (!buffer_uptodate(bh))
@@ -1164,7 +1179,7 @@ __getblk_slow(struct block_device *bdev, sector_t block, int size)
  * mark_buffer_dirty() is atomic.  It takes bh->b_page->mapping->private_lock,
  * mapping->tree_lock and the global inode_lock.
  */
-void fastcall mark_buffer_dirty(struct buffer_head *bh)
+void mark_buffer_dirty(struct buffer_head *bh)
 {
        WARN_ON_ONCE(!buffer_uptodate(bh));
        if (!buffer_dirty(bh) && !test_set_buffer_dirty(bh))
@@ -1195,7 +1210,7 @@ void __brelse(struct buffer_head * buf)
 void __bforget(struct buffer_head *bh)
 {
        clear_buffer_dirty(bh);
-       if (!list_empty(&bh->b_assoc_buffers)) {
+       if (bh->b_assoc_map) {
                struct address_space *buffer_mapping = bh->b_page->mapping;
 
                spin_lock(&buffer_mapping->private_lock);
@@ -1436,6 +1451,7 @@ void invalidate_bh_lrus(void)
 {
        on_each_cpu(invalidate_bh_lru, NULL, 1, 1);
 }
+EXPORT_SYMBOL_GPL(invalidate_bh_lrus);
 
 void set_bh_page(struct buffer_head *bh,
                struct page *page, unsigned long offset)
@@ -3021,7 +3037,7 @@ drop_buffers(struct page *page, struct buffer_head **buffers_to_free)
        do {
                struct buffer_head *next = bh->b_this_page;
 
-               if (!list_empty(&bh->b_assoc_buffers))
+               if (bh->b_assoc_map)
                        __remove_assoc_queue(bh);
                bh = next;
        } while (bh != head);
index 2c7a8b5b45989b25d40f8cb6a283d7ffb8940c5a..038674aa88a72c09a88388ee7cf1b54839675052 100644 (file)
@@ -357,7 +357,7 @@ void cdev_put(struct cdev *p)
 /*
  * Called every time a character special file is opened
  */
-int chrdev_open(struct inode * inode, struct file * filp)
+static int chrdev_open(struct inode *inode, struct file *filp)
 {
        struct cdev *p;
        struct cdev *new = NULL;
index 614bd75b5a4a38f476045953b4c897c7966a7e5e..ee32c0eac7c1078576d1a17bfa03b11c45c4146c 100644 (file)
@@ -78,7 +78,6 @@
 #include <linux/mii.h>
 #include <linux/if_bonding.h>
 #include <linux/watchdog.h>
-#include <linux/dm-ioctl.h>
 
 #include <linux/soundcard.h>
 #include <linux/lp.h>
@@ -1993,39 +1992,6 @@ COMPATIBLE_IOCTL(STOP_ARRAY_RO)
 COMPATIBLE_IOCTL(RESTART_ARRAY_RW)
 COMPATIBLE_IOCTL(GET_BITMAP_FILE)
 ULONG_IOCTL(SET_BITMAP_FILE)
-/* DM */
-COMPATIBLE_IOCTL(DM_VERSION_32)
-COMPATIBLE_IOCTL(DM_REMOVE_ALL_32)
-COMPATIBLE_IOCTL(DM_LIST_DEVICES_32)
-COMPATIBLE_IOCTL(DM_DEV_CREATE_32)
-COMPATIBLE_IOCTL(DM_DEV_REMOVE_32)
-COMPATIBLE_IOCTL(DM_DEV_RENAME_32)
-COMPATIBLE_IOCTL(DM_DEV_SUSPEND_32)
-COMPATIBLE_IOCTL(DM_DEV_STATUS_32)
-COMPATIBLE_IOCTL(DM_DEV_WAIT_32)
-COMPATIBLE_IOCTL(DM_TABLE_LOAD_32)
-COMPATIBLE_IOCTL(DM_TABLE_CLEAR_32)
-COMPATIBLE_IOCTL(DM_TABLE_DEPS_32)
-COMPATIBLE_IOCTL(DM_TABLE_STATUS_32)
-COMPATIBLE_IOCTL(DM_LIST_VERSIONS_32)
-COMPATIBLE_IOCTL(DM_TARGET_MSG_32)
-COMPATIBLE_IOCTL(DM_DEV_SET_GEOMETRY_32)
-COMPATIBLE_IOCTL(DM_VERSION)
-COMPATIBLE_IOCTL(DM_REMOVE_ALL)
-COMPATIBLE_IOCTL(DM_LIST_DEVICES)
-COMPATIBLE_IOCTL(DM_DEV_CREATE)
-COMPATIBLE_IOCTL(DM_DEV_REMOVE)
-COMPATIBLE_IOCTL(DM_DEV_RENAME)
-COMPATIBLE_IOCTL(DM_DEV_SUSPEND)
-COMPATIBLE_IOCTL(DM_DEV_STATUS)
-COMPATIBLE_IOCTL(DM_DEV_WAIT)
-COMPATIBLE_IOCTL(DM_TABLE_LOAD)
-COMPATIBLE_IOCTL(DM_TABLE_CLEAR)
-COMPATIBLE_IOCTL(DM_TABLE_DEPS)
-COMPATIBLE_IOCTL(DM_TABLE_STATUS)
-COMPATIBLE_IOCTL(DM_LIST_VERSIONS)
-COMPATIBLE_IOCTL(DM_TARGET_MSG)
-COMPATIBLE_IOCTL(DM_DEV_SET_GEOMETRY)
 /* Big K */
 COMPATIBLE_IOCTL(PIO_FONT)
 COMPATIBLE_IOCTL(GIO_FONT)
index fa6b7f7ff914269a8a8bbc4fe0bc90d01701f567..fddffe4851f550cd78315189d6466bc0a24ad126 100644 (file)
@@ -56,13 +56,15 @@ const struct inode_operations debugfs_link_operations = {
        .follow_link    = debugfs_follow_link,
 };
 
-static void debugfs_u8_set(void *data, u64 val)
+static int debugfs_u8_set(void *data, u64 val)
 {
        *(u8 *)data = val;
+       return 0;
 }
-static u64 debugfs_u8_get(void *data)
+static int debugfs_u8_get(void *data, u64 *val)
 {
-       return *(u8 *)data;
+       *val = *(u8 *)data;
+       return 0;
 }
 DEFINE_SIMPLE_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%llu\n");
 
@@ -97,13 +99,15 @@ struct dentry *debugfs_create_u8(const char *name, mode_t mode,
 }
 EXPORT_SYMBOL_GPL(debugfs_create_u8);
 
-static void debugfs_u16_set(void *data, u64 val)
+static int debugfs_u16_set(void *data, u64 val)
 {
        *(u16 *)data = val;
+       return 0;
 }
-static u64 debugfs_u16_get(void *data)
+static int debugfs_u16_get(void *data, u64 *val)
 {
-       return *(u16 *)data;
+       *val = *(u16 *)data;
+       return 0;
 }
 DEFINE_SIMPLE_ATTRIBUTE(fops_u16, debugfs_u16_get, debugfs_u16_set, "%llu\n");
 
@@ -138,13 +142,15 @@ struct dentry *debugfs_create_u16(const char *name, mode_t mode,
 }
 EXPORT_SYMBOL_GPL(debugfs_create_u16);
 
-static void debugfs_u32_set(void *data, u64 val)
+static int debugfs_u32_set(void *data, u64 val)
 {
        *(u32 *)data = val;
+       return 0;
 }
-static u64 debugfs_u32_get(void *data)
+static int debugfs_u32_get(void *data, u64 *val)
 {
-       return *(u32 *)data;
+       *val = *(u32 *)data;
+       return 0;
 }
 DEFINE_SIMPLE_ATTRIBUTE(fops_u32, debugfs_u32_get, debugfs_u32_set, "%llu\n");
 
@@ -179,14 +185,16 @@ struct dentry *debugfs_create_u32(const char *name, mode_t mode,
 }
 EXPORT_SYMBOL_GPL(debugfs_create_u32);
 
-static void debugfs_u64_set(void *data, u64 val)
+static int debugfs_u64_set(void *data, u64 val)
 {
        *(u64 *)data = val;
+       return 0;
 }
 
-static u64 debugfs_u64_get(void *data)
+static int debugfs_u64_get(void *data, u64 *val)
 {
-       return *(u64 *)data;
+       *val = *(u64 *)data;
+       return 0;
 }
 DEFINE_SIMPLE_ATTRIBUTE(fops_u64, debugfs_u64_get, debugfs_u64_set, "%llu\n");
 
index 06ef9a255c76f7c8657176bc850b5f4c81909f75..f120e1207874715b052788ea9105458da9348145 100644 (file)
 #include <linux/devpts_fs.h>
 #include <linux/parser.h>
 #include <linux/fsnotify.h>
+#include <linux/seq_file.h>
 
 #define DEVPTS_SUPER_MAGIC 0x1cd1
 
+#define DEVPTS_DEFAULT_MODE 0600
+
 static struct vfsmount *devpts_mnt;
 static struct dentry *devpts_root;
 
@@ -32,7 +35,7 @@ static struct {
        uid_t   uid;
        gid_t   gid;
        umode_t mode;
-} config = {.mode = 0600};
+} config = {.mode = DEVPTS_DEFAULT_MODE};
 
 enum {
        Opt_uid, Opt_gid, Opt_mode,
@@ -54,7 +57,7 @@ static int devpts_remount(struct super_block *sb, int *flags, char *data)
        config.setgid  = 0;
        config.uid     = 0;
        config.gid     = 0;
-       config.mode    = 0600;
+       config.mode    = DEVPTS_DEFAULT_MODE;
 
        while ((p = strsep(&data, ",")) != NULL) {
                substring_t args[MAX_OPT_ARGS];
@@ -81,7 +84,7 @@ static int devpts_remount(struct super_block *sb, int *flags, char *data)
                case Opt_mode:
                        if (match_octal(&args[0], &option))
                                return -EINVAL;
-                       config.mode = option & ~S_IFMT;
+                       config.mode = option & S_IALLUGO;
                        break;
                default:
                        printk(KERN_ERR "devpts: called with bogus options\n");
@@ -92,9 +95,21 @@ static int devpts_remount(struct super_block *sb, int *flags, char *data)
        return 0;
 }
 
+static int devpts_show_options(struct seq_file *seq, struct vfsmount *vfs)
+{
+       if (config.setuid)
+               seq_printf(seq, ",uid=%u", config.uid);
+       if (config.setgid)
+               seq_printf(seq, ",gid=%u", config.gid);
+       seq_printf(seq, ",mode=%03o", config.mode);
+
+       return 0;
+}
+
 static const struct super_operations devpts_sops = {
        .statfs         = simple_statfs,
        .remount_fs     = devpts_remount,
+       .show_options   = devpts_show_options,
 };
 
 static int
index be923e4bc38972954325aee09363cb38bff60884..9ff6069094d81353239e38c56f37a5da72bf1f69 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -119,7 +119,7 @@ asmlinkage long sys_uselib(const char __user * library)
        if (error)
                goto exit;
 
-       file = nameidata_to_filp(&nd, O_RDONLY);
+       file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE);
        error = PTR_ERR(file);
        if (IS_ERR(file))
                goto out;
@@ -658,7 +658,8 @@ struct file *open_exec(const char *name)
                        int err = vfs_permission(&nd, MAY_EXEC);
                        file = ERR_PTR(err);
                        if (!err) {
-                               file = nameidata_to_filp(&nd, O_RDONLY);
+                               file = nameidata_to_filp(&nd,
+                                                       O_RDONLY|O_LARGEFILE);
                                if (!IS_ERR(file)) {
                                        err = deny_write_access(file);
                                        if (err) {
@@ -782,26 +783,8 @@ static int de_thread(struct task_struct *tsk)
        zap_other_threads(tsk);
        read_unlock(&tasklist_lock);
 
-       /*
-        * Account for the thread group leader hanging around:
-        */
-       count = 1;
-       if (!thread_group_leader(tsk)) {
-               count = 2;
-               /*
-                * The SIGALRM timer survives the exec, but needs to point
-                * at us as the new group leader now.  We have a race with
-                * a timer firing now getting the old leader, so we need to
-                * synchronize with any firing (by calling del_timer_sync)
-                * before we can safely let the old group leader die.
-                */
-               sig->tsk = tsk;
-               spin_unlock_irq(lock);
-               if (hrtimer_cancel(&sig->real_timer))
-                       hrtimer_restart(&sig->real_timer);
-               spin_lock_irq(lock);
-       }
-
+       /* Account for the thread group leader hanging around: */
+       count = thread_group_leader(tsk) ? 1 : 2;
        sig->notify_count = count;
        while (atomic_read(&sig->count) > count) {
                __set_current_state(TASK_UNINTERRUPTIBLE);
@@ -1184,7 +1167,7 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
 {
        int try,retval;
        struct linux_binfmt *fmt;
-#ifdef __alpha__
+#if defined(__alpha__) && defined(CONFIG_ARCH_SUPPORTS_AOUT)
        /* handle /sbin/loader.. */
        {
            struct exec * eh = (struct exec *) bprm->buf;
index f1e5705e75f1f300fb7551c92f4d8983b27b23c9..47d88da2d33b5fab73349fa26776f7773d98d194 100644 (file)
@@ -126,7 +126,6 @@ extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
 /* inode.c */
 extern struct inode *ext2_iget (struct super_block *, unsigned long);
 extern int ext2_write_inode (struct inode *, int);
-extern void ext2_put_inode (struct inode *);
 extern void ext2_delete_inode (struct inode *);
 extern int ext2_sync_inode (struct inode *);
 extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int);
index 22f1010bf79f9f40cb9557d100694f2af9397f74..088b011bb97e2882892a766a94b9bcac2894d984 100644 (file)
@@ -285,6 +285,9 @@ static int ext2_show_options(struct seq_file *seq, struct vfsmount *vfs)
                seq_puts(seq, ",xip");
 #endif
 
+       if (!test_opt(sb, RESERVATION))
+               seq_puts(seq, ",noreservation");
+
        return 0;
 }
 
index a75713031105159ab82472301be86abef9ccc0af..da0cb2c0e4376717292fd2afc1d4ff147b9fc6b8 100644 (file)
@@ -630,9 +630,7 @@ do_more:
        jbd_unlock_bh_state(bitmap_bh);
 
        spin_lock(sb_bgl_lock(sbi, block_group));
-       desc->bg_free_blocks_count =
-               cpu_to_le16(le16_to_cpu(desc->bg_free_blocks_count) +
-                       group_freed);
+       le16_add_cpu(&desc->bg_free_blocks_count, group_freed);
        spin_unlock(sb_bgl_lock(sbi, block_group));
        percpu_counter_add(&sbi->s_freeblocks_counter, count);
 
@@ -1696,8 +1694,7 @@ allocated:
                        ret_block, goal_hits, goal_attempts);
 
        spin_lock(sb_bgl_lock(sbi, group_no));
-       gdp->bg_free_blocks_count =
-                       cpu_to_le16(le16_to_cpu(gdp->bg_free_blocks_count)-num);
+       le16_add_cpu(&gdp->bg_free_blocks_count, -num);
        spin_unlock(sb_bgl_lock(sbi, group_no));
        percpu_counter_sub(&sbi->s_freeblocks_counter, num);
 
index 58ae2f943f12c64d863312214bebd6fe2e908a52..4f4020c54683acbc2969e01e531b8e117ef6a005 100644 (file)
@@ -164,11 +164,9 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
 
                if (gdp) {
                        spin_lock(sb_bgl_lock(sbi, block_group));
-                       gdp->bg_free_inodes_count = cpu_to_le16(
-                               le16_to_cpu(gdp->bg_free_inodes_count) + 1);
+                       le16_add_cpu(&gdp->bg_free_inodes_count, 1);
                        if (is_directory)
-                               gdp->bg_used_dirs_count = cpu_to_le16(
-                                 le16_to_cpu(gdp->bg_used_dirs_count) - 1);
+                               le16_add_cpu(&gdp->bg_used_dirs_count, -1);
                        spin_unlock(sb_bgl_lock(sbi, block_group));
                        percpu_counter_inc(&sbi->s_freeinodes_counter);
                        if (is_directory)
@@ -527,11 +525,9 @@ got:
        err = ext3_journal_get_write_access(handle, bh2);
        if (err) goto fail;
        spin_lock(sb_bgl_lock(sbi, group));
-       gdp->bg_free_inodes_count =
-               cpu_to_le16(le16_to_cpu(gdp->bg_free_inodes_count) - 1);
+       le16_add_cpu(&gdp->bg_free_inodes_count, -1);
        if (S_ISDIR(mode)) {
-               gdp->bg_used_dirs_count =
-                       cpu_to_le16(le16_to_cpu(gdp->bg_used_dirs_count) + 1);
+               le16_add_cpu(&gdp->bg_used_dirs_count, 1);
        }
        spin_unlock(sb_bgl_lock(sbi, group));
        BUFFER_TRACE(bh2, "call ext3_journal_dirty_metadata");
index ebc05af7343aecb669304b4914359534834ac108..9397d779c43de16283369293df8bbdcd65c4a796 100644 (file)
@@ -518,8 +518,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
        EXT3_SB(sb)->s_gdb_count++;
        kfree(o_group_desc);
 
-       es->s_reserved_gdt_blocks =
-               cpu_to_le16(le16_to_cpu(es->s_reserved_gdt_blocks) - 1);
+       le16_add_cpu(&es->s_reserved_gdt_blocks, -1);
        ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh);
 
        return 0;
@@ -890,10 +889,8 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
         * blocks/inodes before the group is live won't actually let us
         * allocate the new space yet.
         */
-       es->s_blocks_count = cpu_to_le32(le32_to_cpu(es->s_blocks_count) +
-               input->blocks_count);
-       es->s_inodes_count = cpu_to_le32(le32_to_cpu(es->s_inodes_count) +
-               EXT3_INODES_PER_GROUP(sb));
+       le32_add_cpu(&es->s_blocks_count, input->blocks_count);
+       le32_add_cpu(&es->s_inodes_count, EXT3_INODES_PER_GROUP(sb));
 
        /*
         * We need to protect s_groups_count against other CPUs seeing
@@ -926,8 +923,7 @@ int ext3_group_add(struct super_block *sb, struct ext3_new_group_data *input)
 
        /* Update the reserved block counts only once the new group is
         * active. */
-       es->s_r_blocks_count = cpu_to_le32(le32_to_cpu(es->s_r_blocks_count) +
-               input->reserved_blocks);
+       le32_add_cpu(&es->s_r_blocks_count, input->reserved_blocks);
 
        /* Update the free space counts */
        percpu_counter_add(&sbi->s_freeblocks_counter,
index cf2a2c3660ec793b4e20d090bd16e6192d824644..8e02cbfb1123afeba4d8b687874ff2e0ab37a6c3 100644 (file)
@@ -1222,7 +1222,7 @@ static int ext3_setup_super(struct super_block *sb, struct ext3_super_block *es,
 #endif
        if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
                es->s_max_mnt_count = cpu_to_le16(EXT3_DFL_MAX_MNT_COUNT);
-       es->s_mnt_count=cpu_to_le16(le16_to_cpu(es->s_mnt_count) + 1);
+       le16_add_cpu(&es->s_mnt_count, 1);
        es->s_mtime = cpu_to_le32(get_seconds());
        ext3_update_dynamic_rev(sb);
        EXT3_SET_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER);
index 408373819e34eddb7dec372b9d518189d54b4242..fb89c299becece36d14c319a33d0ab8301ae2007 100644 (file)
@@ -492,8 +492,7 @@ ext3_xattr_release_block(handle_t *handle, struct inode *inode,
                get_bh(bh);
                ext3_forget(handle, 1, inode, bh, bh->b_blocknr);
        } else {
-               BHDR(bh)->h_refcount = cpu_to_le32(
-                               le32_to_cpu(BHDR(bh)->h_refcount) - 1);
+               le32_add_cpu(&BHDR(bh)->h_refcount, -1);
                error = ext3_journal_dirty_metadata(handle, bh);
                if (IS_SYNC(inode))
                        handle->h_sync = 1;
@@ -780,8 +779,7 @@ inserted:
                                if (error)
                                        goto cleanup_dquot;
                                lock_buffer(new_bh);
-                               BHDR(new_bh)->h_refcount = cpu_to_le32(1 +
-                                       le32_to_cpu(BHDR(new_bh)->h_refcount));
+                               le32_add_cpu(&BHDR(new_bh)->h_refcount, 1);
                                ea_bdebug(new_bh, "reusing; refcount now=%d",
                                        le32_to_cpu(BHDR(new_bh)->h_refcount));
                                unlock_buffer(new_bh);
index 085269e07fb3a86f9849b54d5403f68de5bed844..53f3cf62b7c18c945bdcc3caaddf9466a91ca391 100644 (file)
@@ -837,6 +837,8 @@ static int fat_show_options(struct seq_file *m, struct vfsmount *mnt)
                if (!opts->numtail)
                        seq_puts(m, ",nonumtail");
        }
+       if (sbi->options.flush)
+               seq_puts(m, ",flush");
 
        return 0;
 }
index 8685263ccc4a7aa51d6666136c285687393bfabb..e632da761fc11cd19b8637bcad23b1f5562d7382 100644 (file)
@@ -24,7 +24,7 @@
 #include <asm/siginfo.h>
 #include <asm/uaccess.h>
 
-void fastcall set_close_on_exec(unsigned int fd, int flag)
+void set_close_on_exec(unsigned int fd, int flag)
 {
        struct files_struct *files = current->files;
        struct fdtable *fdt;
@@ -309,7 +309,7 @@ pid_t f_getown(struct file *filp)
 {
        pid_t pid;
        read_lock(&filp->f_owner.lock);
-       pid = pid_nr_ns(filp->f_owner.pid, current->nsproxy->pid_ns);
+       pid = pid_vnr(filp->f_owner.pid);
        if (filp->f_owner.pid_type == PIDTYPE_PGID)
                pid = -pid;
        read_unlock(&filp->f_owner.lock);
index 664e3f2309b89811b028603da0f17a6e266ee9fd..6d27befe2d48ff5fbb13a45c5cd86618777bbbd9 100644 (file)
@@ -197,7 +197,7 @@ int init_file(struct file *file, struct vfsmount *mnt, struct dentry *dentry,
 }
 EXPORT_SYMBOL(init_file);
 
-void fastcall fput(struct file *file)
+void fput(struct file *file)
 {
        if (atomic_dec_and_test(&file->f_count))
                __fput(file);
@@ -208,7 +208,7 @@ EXPORT_SYMBOL(fput);
 /* __fput is called from task context when aio completion releases the last
  * last use of a struct file *.  Do not use otherwise.
  */
-void fastcall __fput(struct file *file)
+void __fput(struct file *file)
 {
        struct dentry *dentry = file->f_path.dentry;
        struct vfsmount *mnt = file->f_path.mnt;
@@ -241,7 +241,7 @@ void fastcall __fput(struct file *file)
        mntput(mnt);
 }
 
-struct file fastcall *fget(unsigned int fd)
+struct file *fget(unsigned int fd)
 {
        struct file *file;
        struct files_struct *files = current->files;
@@ -269,7 +269,7 @@ EXPORT_SYMBOL(fget);
  * and a flag is returned to be passed to the corresponding fput_light().
  * There must not be a cloning between an fget_light/fput_light pair.
  */
-struct file fastcall *fget_light(unsigned int fd, int *fput_needed)
+struct file *fget_light(unsigned int fd, int *fput_needed)
 {
        struct file *file;
        struct files_struct *files = current->files;
index db80ce9eb1d07896fb3ddd5f545ed8876dc8b2fa..c0076077d33874d0d63322d7c698ccbb04e4ed78 100644 (file)
@@ -655,7 +655,7 @@ int write_inode_now(struct inode *inode, int sync)
        int ret;
        struct writeback_control wbc = {
                .nr_to_write = LONG_MAX,
-               .sync_mode = WB_SYNC_ALL,
+               .sync_mode = sync ? WB_SYNC_ALL : WB_SYNC_NONE,
                .range_start = 0,
                .range_end = LLONG_MAX,
        };
index 574707409bbfafc92d91006fd74d065085170d43..033f7bdd47e80e2f659be152bd51e0441e607c3d 100644 (file)
@@ -29,6 +29,8 @@ DEFINE_MUTEX(fuse_mutex);
 
 #define FUSE_SUPER_MAGIC 0x65735546
 
+#define FUSE_DEFAULT_BLKSIZE 512
+
 struct fuse_mount_data {
        int fd;
        unsigned rootmode;
@@ -355,7 +357,7 @@ static int parse_fuse_opt(char *opt, struct fuse_mount_data *d, int is_bdev)
        char *p;
        memset(d, 0, sizeof(struct fuse_mount_data));
        d->max_read = ~0;
-       d->blksize = 512;
+       d->blksize = FUSE_DEFAULT_BLKSIZE;
 
        while ((p = strsep(&opt, ",")) != NULL) {
                int token;
@@ -440,6 +442,9 @@ static int fuse_show_options(struct seq_file *m, struct vfsmount *mnt)
                seq_puts(m, ",allow_other");
        if (fc->max_read != ~0)
                seq_printf(m, ",max_read=%u", fc->max_read);
+       if (mnt->mnt_sb->s_bdev &&
+           mnt->mnt_sb->s_blocksize != FUSE_DEFAULT_BLKSIZE)
+               seq_printf(m, ",blksize=%lu", mnt->mnt_sb->s_blocksize);
        return 0;
 }
 
index 9e10f9444b648fde00d0cfe8086c8189d5a9eba7..628ccf6fa402500aa15d7d53969b0f62b6ea5188 100644 (file)
@@ -325,7 +325,7 @@ int hfsplus_hash_dentry(struct dentry *dentry, struct qstr *str)
        struct super_block *sb = dentry->d_sb;
        const char *astr;
        const u16 *dstr;
-       int casefold, decompose, size, dsize, len;
+       int casefold, decompose, size, len;
        unsigned long hash;
        wchar_t c;
        u16 c2;
@@ -336,6 +336,7 @@ int hfsplus_hash_dentry(struct dentry *dentry, struct qstr *str)
        astr = str->name;
        len = str->len;
        while (len > 0) {
+               int uninitialized_var(dsize);
                size = asc2unichar(sb, astr, len, &c);
                astr += size;
                len -= size;
index 2b9b35733aacd00be2673995887521263ae66a39..d0549cb4fb23640a79d0221262b14742b5c1a468 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/mm.h>
 #include <linux/pagemap.h>
 #include <linux/statfs.h>
+#include <linux/seq_file.h>
 #include "hostfs.h"
 #include "init.h"
 #include "kern.h"
@@ -322,12 +323,25 @@ static void hostfs_destroy_inode(struct inode *inode)
        kfree(HOSTFS_I(inode));
 }
 
+static int hostfs_show_options(struct seq_file *seq, struct vfsmount *vfs)
+{
+       struct inode *root = vfs->mnt_sb->s_root->d_inode;
+       const char *root_path = HOSTFS_I(root)->host_filename;
+       size_t offset = strlen(root_ino) + 1;
+
+       if (strlen(root_path) > offset)
+               seq_printf(seq, ",%s", root_path + offset);
+
+       return 0;
+}
+
 static const struct super_operations hostfs_sbops = {
        .alloc_inode    = hostfs_alloc_inode,
        .drop_inode     = generic_delete_inode,
        .delete_inode   = hostfs_delete_inode,
        .destroy_inode  = hostfs_destroy_inode,
        .statfs         = hostfs_statfs,
+       .show_options   = hostfs_show_options,
 };
 
 int hostfs_readdir(struct file *file, void *ent, filldir_t filldir)
index 00971d999964848884187593fb744ef16888620a..f63a699ec659c076263a221c72414f1cdc111a5b 100644 (file)
@@ -386,6 +386,7 @@ static int hpfs_remount_fs(struct super_block *s, int *flags, char *data)
        int lowercase, conv, eas, chk, errs, chkdsk, timeshift;
        int o;
        struct hpfs_sb_info *sbi = hpfs_sb(s);
+       char *new_opts = kstrdup(data, GFP_KERNEL);
        
        *flags |= MS_NOATIME;
        
@@ -398,15 +399,15 @@ static int hpfs_remount_fs(struct super_block *s, int *flags, char *data)
        if (!(o = parse_opts(data, &uid, &gid, &umask, &lowercase, &conv,
            &eas, &chk, &errs, &chkdsk, &timeshift))) {
                printk("HPFS: bad mount options.\n");
-               return 1;
+               goto out_err;
        }
        if (o == 2) {
                hpfs_help();
-               return 1;
+               goto out_err;
        }
        if (timeshift != sbi->sb_timeshift) {
                printk("HPFS: timeshift can't be changed using remount.\n");
-               return 1;
+               goto out_err;
        }
 
        unmark_dirty(s);
@@ -419,7 +420,14 @@ static int hpfs_remount_fs(struct super_block *s, int *flags, char *data)
 
        if (!(*flags & MS_RDONLY)) mark_dirty(s);
 
+       kfree(s->s_options);
+       s->s_options = new_opts;
+
        return 0;
+
+out_err:
+       kfree(new_opts);
+       return -EINVAL;
 }
 
 /* Super operations */
@@ -432,6 +440,7 @@ static const struct super_operations hpfs_sops =
        .put_super      = hpfs_put_super,
        .statfs         = hpfs_statfs,
        .remount_fs     = hpfs_remount_fs,
+       .show_options   = generic_show_options,
 };
 
 static int hpfs_fill_super(struct super_block *s, void *options, int silent)
@@ -454,6 +463,8 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)
 
        int o;
 
+       save_mount_options(s, options);
+
        sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
        if (!sbi)
                return -ENOMEM;
index 3b3cc28cdefcaf5929be2a3d13be24bf4791fd6c..eee9487ae47fb78a12ffd92a4adaa6e185fbe085 100644 (file)
@@ -734,6 +734,7 @@ static const struct super_operations hugetlbfs_ops = {
        .delete_inode   = hugetlbfs_delete_inode,
        .drop_inode     = hugetlbfs_drop_inode,
        .put_super      = hugetlbfs_put_super,
+       .show_options   = generic_show_options,
 };
 
 static int
@@ -817,6 +818,8 @@ hugetlbfs_fill_super(struct super_block *sb, void *data, int silent)
        struct hugetlbfs_config config;
        struct hugetlbfs_sb_info *sbinfo;
 
+       save_mount_options(sb, data);
+
        config.nr_blocks = -1; /* No limit on size by default */
        config.nr_inodes = -1; /* No limit on number of inodes by default */
        config.uid = current->fsuid;
index a336c9709f3cc477ed15236642b743f0a3ca493e..3ab09a65c456499d0b51604ab84f364c42f4eed5 100644 (file)
@@ -283,7 +283,7 @@ static void inotify_dev_queue_event(struct inotify_watch *w, u32 wd, u32 mask,
        /* we can safely put the watch as we don't reference it while
         * generating the event
         */
-       if (mask & IN_IGNORED || mask & IN_ONESHOT)
+       if (mask & IN_IGNORED || w->mask & IN_ONESHOT)
                put_inotify_watch(w); /* final put */
 
        /* coalescing: drop this event if it is a dupe of the previous */
index 875d37fb6c70f7da561833e5af1a34d048fd4d9a..044a254d526b86e38ca0ca925540468ce06e19f1 100644 (file)
@@ -110,6 +110,7 @@ static const struct super_operations isofs_sops = {
        .put_super      = isofs_put_super,
        .statfs         = isofs_statfs,
        .remount_fs     = isofs_remount,
+       .show_options   = generic_show_options,
 };
 
 
@@ -144,7 +145,8 @@ struct iso9660_options{
        char nocompress;
        unsigned char check;
        unsigned int blocksize;
-       mode_t mode;
+       mode_t fmode;
+       mode_t dmode;
        gid_t gid;
        uid_t uid;
        char *iocharset;
@@ -305,7 +307,7 @@ enum {
        Opt_block, Opt_check_r, Opt_check_s, Opt_cruft, Opt_gid, Opt_ignore,
        Opt_iocharset, Opt_map_a, Opt_map_n, Opt_map_o, Opt_mode, Opt_nojoliet,
        Opt_norock, Opt_sb, Opt_session, Opt_uid, Opt_unhide, Opt_utf8, Opt_err,
-       Opt_nocompress, Opt_hide, Opt_showassoc,
+       Opt_nocompress, Opt_hide, Opt_showassoc, Opt_dmode,
 };
 
 static match_table_t tokens = {
@@ -332,6 +334,7 @@ static match_table_t tokens = {
        {Opt_uid, "uid=%u"},
        {Opt_gid, "gid=%u"},
        {Opt_mode, "mode=%u"},
+       {Opt_dmode, "dmode=%u"},
        {Opt_block, "block=%u"},
        {Opt_ignore, "conv=binary"},
        {Opt_ignore, "conv=b"},
@@ -359,7 +362,7 @@ static int parse_options(char *options, struct iso9660_options *popt)
        popt->check = 'u';              /* unset */
        popt->nocompress = 0;
        popt->blocksize = 1024;
-       popt->mode = S_IRUGO | S_IXUGO; /*
+       popt->fmode = popt->dmode = S_IRUGO | S_IXUGO; /*
                                         * r-x for all.  The disc could
                                         * be shared with DOS machines so
                                         * virtually anything could be
@@ -451,7 +454,12 @@ static int parse_options(char *options, struct iso9660_options *popt)
                case Opt_mode:
                        if (match_int(&args[0], &option))
                                return 0;
-                       popt->mode = option;
+                       popt->fmode = option;
+                       break;
+               case Opt_dmode:
+                       if (match_int(&args[0], &option))
+                               return 0;
+                       popt->dmode = option;
                        break;
                case Opt_block:
                        if (match_int(&args[0], &option))
@@ -554,6 +562,8 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
        int table, error = -EINVAL;
        unsigned int vol_desc_start;
 
+       save_mount_options(s, data);
+
        sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
        if (!sbi)
                return -ENOMEM;
@@ -801,7 +811,8 @@ root_found:
         * on the disk as suid, so we merely allow them to set the default
         * permissions.
         */
-       sbi->s_mode = opt.mode & 0777;
+       sbi->s_fmode = opt.fmode & 0777;
+       sbi->s_dmode = opt.dmode & 0777;
 
        /*
         * Read the root inode, which _may_ result in changing
@@ -1248,7 +1259,7 @@ static int isofs_read_inode(struct inode *inode)
        ei->i_file_format = isofs_file_normal;
 
        if (de->flags[-high_sierra] & 2) {
-               inode->i_mode = S_IRUGO | S_IXUGO | S_IFDIR;
+               inode->i_mode = sbi->s_dmode | S_IFDIR;
                inode->i_nlink = 1;     /*
                                         * Set to 1.  We know there are 2, but
                                         * the find utility tries to optimize
@@ -1258,9 +1269,8 @@ static int isofs_read_inode(struct inode *inode)
                                         */
        } else {
                /* Everybody gets to read the file. */
-               inode->i_mode = sbi->s_mode;
+               inode->i_mode = sbi->s_fmode | S_IFREG;
                inode->i_nlink = 1;
-               inode->i_mode |= S_IFREG;
        }
        inode->i_uid = sbi->s_uid;
        inode->i_gid = sbi->s_gid;
index f3213f9f89afcfaa79f98fc9bb2a61f2165fca0f..d1bdf8adb3510a98ffe2c49518ba6bdd272eaa2d 100644 (file)
@@ -51,7 +51,8 @@ struct isofs_sb_info {
        unsigned char s_hide;
        unsigned char s_showassoc;
 
-       mode_t s_mode;
+       mode_t s_fmode;
+       mode_t s_dmode;
        gid_t s_gid;
        uid_t s_uid;
        struct nls_table *s_nls_iocharset; /* Native language support table */
index 31853eb65b4cb0f2bf4f365e21a0456e7362d1b1..8e08efcaede26c06d01271b5dbebeafd55a0183d 100644 (file)
@@ -131,6 +131,8 @@ static int journal_write_commit_record(journal_t *journal,
                barrier_done = 1;
        }
        ret = sync_dirty_buffer(bh);
+       if (barrier_done)
+               clear_buffer_ordered(bh);
        /* is it possible for another commit to fail at roughly
         * the same time as this one?  If so, we don't want to
         * trust the barrier flag in the super, but instead want
@@ -148,7 +150,6 @@ static int journal_write_commit_record(journal_t *journal,
                spin_unlock(&journal->j_state_lock);
 
                /* And try again, without the barrier */
-               clear_buffer_ordered(bh);
                set_buffer_uptodate(bh);
                set_buffer_dirty(bh);
                ret = sync_dirty_buffer(bh);
index 5523bde963879d6060c9a9d19396e8a8615b40a2..b004dfadd8917d4cbf91d9994a9b4893ea6b3922 100644 (file)
@@ -583,8 +583,8 @@ int simple_transaction_release(struct inode *inode, struct file *file)
 /* Simple attribute files */
 
 struct simple_attr {
-       u64 (*get)(void *);
-       void (*set)(void *, u64);
+       int (*get)(void *, u64 *);
+       int (*set)(void *, u64);
        char get_buf[24];       /* enough to store a u64 and "\n\0" */
        char set_buf[24];
        void *data;
@@ -595,7 +595,7 @@ struct simple_attr {
 /* simple_attr_open is called by an actual attribute open file operation
  * to set the attribute specific access operations. */
 int simple_attr_open(struct inode *inode, struct file *file,
-                    u64 (*get)(void *), void (*set)(void *, u64),
+                    int (*get)(void *, u64 *), int (*set)(void *, u64),
                     const char *fmt)
 {
        struct simple_attr *attr;
@@ -615,7 +615,7 @@ int simple_attr_open(struct inode *inode, struct file *file,
        return nonseekable_open(inode, file);
 }
 
-int simple_attr_close(struct inode *inode, struct file *file)
+int simple_attr_release(struct inode *inode, struct file *file)
 {
        kfree(file->private_data);
        return 0;
@@ -634,15 +634,24 @@ ssize_t simple_attr_read(struct file *file, char __user *buf,
        if (!attr->get)
                return -EACCES;
 
-       mutex_lock(&attr->mutex);
-       if (*ppos) /* continued read */
+       ret = mutex_lock_interruptible(&attr->mutex);
+       if (ret)
+               return ret;
+
+       if (*ppos) {            /* continued read */
                size = strlen(attr->get_buf);
-       else      /* first read */
+       } else {                /* first read */
+               u64 val;
+               ret = attr->get(attr->data, &val);
+               if (ret)
+                       goto out;
+
                size = scnprintf(attr->get_buf, sizeof(attr->get_buf),
-                                attr->fmt,
-                                (unsigned long long)attr->get(attr->data));
+                                attr->fmt, (unsigned long long)val);
+       }
 
        ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size);
+out:
        mutex_unlock(&attr->mutex);
        return ret;
 }
@@ -657,11 +666,13 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf,
        ssize_t ret;
 
        attr = file->private_data;
-
        if (!attr->set)
                return -EACCES;
 
-       mutex_lock(&attr->mutex);
+       ret = mutex_lock_interruptible(&attr->mutex);
+       if (ret)
+               return ret;
+
        ret = -EFAULT;
        size = min(sizeof(attr->set_buf) - 1, len);
        if (copy_from_user(attr->set_buf, buf, size))
@@ -793,6 +804,6 @@ EXPORT_SYMBOL(simple_transaction_get);
 EXPORT_SYMBOL(simple_transaction_read);
 EXPORT_SYMBOL(simple_transaction_release);
 EXPORT_SYMBOL_GPL(simple_attr_open);
-EXPORT_SYMBOL_GPL(simple_attr_close);
+EXPORT_SYMBOL_GPL(simple_attr_release);
 EXPORT_SYMBOL_GPL(simple_attr_read);
 EXPORT_SYMBOL_GPL(simple_attr_write);
index 49354b9c7dc1234779a7c21114e0c976d12e7e1d..f36f0e61558dabfdeb7be02ed245e8bca13c663b 100644 (file)
@@ -658,8 +658,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
        if (cfl) {
                __locks_copy_lock(fl, cfl);
                if (cfl->fl_nspid)
-                       fl->fl_pid = pid_nr_ns(cfl->fl_nspid,
-                                               task_active_pid_ns(current));
+                       fl->fl_pid = pid_vnr(cfl->fl_nspid);
        } else
                fl->fl_type = F_UNLCK;
        unlock_kernel();
@@ -2084,7 +2083,7 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
        unsigned int fl_pid;
 
        if (fl->fl_nspid)
-               fl_pid = pid_nr_ns(fl->fl_nspid, task_active_pid_ns(current));
+               fl_pid = pid_vnr(fl->fl_nspid);
        else
                fl_pid = fl->fl_pid;
 
index 241cff423653692ec067afa71ccf9c8ca4e86b05..52703986323a98ae43b93a92c91d439660a7fc6f 100644 (file)
  * any extra contention...
  */
 
-static int fastcall link_path_walk(const char *name, struct nameidata *nd);
+static int link_path_walk(const char *name, struct nameidata *nd);
 
 /* In order to reduce some races, while at the same time doing additional
  * checking and hopefully speeding things up, we copy filenames to the
@@ -823,7 +823,7 @@ fail:
  * Returns 0 and nd will have valid dentry and mnt on success.
  * Returns error and drops reference to input namei data on failure.
  */
-static fastcall int __link_path_walk(const char * name, struct nameidata *nd)
+static int __link_path_walk(const char *name, struct nameidata *nd)
 {
        struct path next;
        struct inode *inode;
@@ -1015,7 +1015,7 @@ return_err:
  * Retry the whole path once, forcing real lookup requests
  * instead of relying on the dcache.
  */
-static int fastcall link_path_walk(const char *name, struct nameidata *nd)
+static int link_path_walk(const char *name, struct nameidata *nd)
 {
        struct nameidata save = *nd;
        int result;
@@ -1039,7 +1039,7 @@ static int fastcall link_path_walk(const char *name, struct nameidata *nd)
        return result;
 }
 
-static int fastcall path_walk(const char * name, struct nameidata *nd)
+static int path_walk(const char *name, struct nameidata *nd)
 {
        current->total_link_count = 0;
        return link_path_walk(name, nd);
@@ -1116,7 +1116,7 @@ set_it:
 }
 
 /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
-static int fastcall do_path_lookup(int dfd, const char *name,
+static int do_path_lookup(int dfd, const char *name,
                                unsigned int flags, struct nameidata *nd)
 {
        int retval = 0;
@@ -1183,7 +1183,7 @@ fput_fail:
        goto out_fail;
 }
 
-int fastcall path_lookup(const char *name, unsigned int flags,
+int path_lookup(const char *name, unsigned int flags,
                        struct nameidata *nd)
 {
        return do_path_lookup(AT_FDCWD, name, flags, nd);
@@ -1409,7 +1409,7 @@ struct dentry *lookup_one_noperm(const char *name, struct dentry *base)
        return __lookup_hash(&this, base, NULL);
 }
 
-int fastcall __user_walk_fd(int dfd, const char __user *name, unsigned flags,
+int __user_walk_fd(int dfd, const char __user *name, unsigned flags,
                            struct nameidata *nd)
 {
        char *tmp = getname(name);
@@ -1422,7 +1422,7 @@ int fastcall __user_walk_fd(int dfd, const char __user *name, unsigned flags,
        return err;
 }
 
-int fastcall __user_walk(const char __user *name, unsigned flags, struct nameidata *nd)
+int __user_walk(const char __user *name, unsigned flags, struct nameidata *nd)
 {
        return __user_walk_fd(AT_FDCWD, name, flags, nd);
 }
index e9c10cd01e1325cff95869cbb0f23aa8d14c10ce..63ced21c12dc2a2f212786c3b5e2d25b48437bf6 100644 (file)
@@ -320,6 +320,50 @@ void mnt_unpin(struct vfsmount *mnt)
 
 EXPORT_SYMBOL(mnt_unpin);
 
+static inline void mangle(struct seq_file *m, const char *s)
+{
+       seq_escape(m, s, " \t\n\\");
+}
+
+/*
+ * Simple .show_options callback for filesystems which don't want to
+ * implement more complex mount option showing.
+ *
+ * See also save_mount_options().
+ */
+int generic_show_options(struct seq_file *m, struct vfsmount *mnt)
+{
+       const char *options = mnt->mnt_sb->s_options;
+
+       if (options != NULL && options[0]) {
+               seq_putc(m, ',');
+               mangle(m, options);
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL(generic_show_options);
+
+/*
+ * If filesystem uses generic_show_options(), this function should be
+ * called from the fill_super() callback.
+ *
+ * The .remount_fs callback usually needs to be handled in a special
+ * way, to make sure, that previous options are not overwritten if the
+ * remount fails.
+ *
+ * Also note, that if the filesystem's .remount_fs function doesn't
+ * reset all options to their default value, but changes only newly
+ * given options, then the displayed options will not reflect reality
+ * any more.
+ */
+void save_mount_options(struct super_block *sb, char *options)
+{
+       kfree(sb->s_options);
+       sb->s_options = kstrdup(options, GFP_KERNEL);
+}
+EXPORT_SYMBOL(save_mount_options);
+
 /* iterator */
 static void *m_start(struct seq_file *m, loff_t *pos)
 {
@@ -341,11 +385,6 @@ static void m_stop(struct seq_file *m, void *v)
        up_read(&namespace_sem);
 }
 
-static inline void mangle(struct seq_file *m, const char *s)
-{
-       seq_escape(m, s, " \t\n\\");
-}
-
 static int show_vfsmnt(struct seq_file *m, void *v)
 {
        struct vfsmount *mnt = list_entry(v, struct vfsmount, mnt_list);
@@ -897,8 +936,9 @@ out_unlock:
 
 /*
  * recursively change the type of the mountpoint.
+ * noinline this do_mount helper to save do_mount stack space.
  */
-static int do_change_type(struct nameidata *nd, int flag)
+static noinline int do_change_type(struct nameidata *nd, int flag)
 {
        struct vfsmount *m, *mnt = nd->mnt;
        int recurse = flag & MS_REC;
@@ -921,8 +961,10 @@ static int do_change_type(struct nameidata *nd, int flag)
 
 /*
  * do loopback mount.
+ * noinline this do_mount helper to save do_mount stack space.
  */
-static int do_loopback(struct nameidata *nd, char *old_name, int recurse)
+static noinline int do_loopback(struct nameidata *nd, char *old_name,
+                               int recurse)
 {
        struct nameidata old_nd;
        struct vfsmount *mnt = NULL;
@@ -971,8 +1013,9 @@ out:
  * change filesystem flags. dir should be a physical root of filesystem.
  * If you've mounted a non-root directory somewhere and want to do remount
  * on it - tough luck.
+ * noinline this do_mount helper to save do_mount stack space.
  */
-static int do_remount(struct nameidata *nd, int flags, int mnt_flags,
+static noinline int do_remount(struct nameidata *nd, int flags, int mnt_flags,
                      void *data)
 {
        int err;
@@ -1007,7 +1050,10 @@ static inline int tree_contains_unbindable(struct vfsmount *mnt)
        return 0;
 }
 
-static int do_move_mount(struct nameidata *nd, char *old_name)
+/*
+ * noinline this do_mount helper to save do_mount stack space.
+ */
+static noinline int do_move_mount(struct nameidata *nd, char *old_name)
 {
        struct nameidata old_nd, parent_nd;
        struct vfsmount *p;
@@ -1082,8 +1128,9 @@ out:
 /*
  * create a new mount for userspace and request it to be added into the
  * namespace's tree
+ * noinline this do_mount helper to save do_mount stack space.
  */
-static int do_new_mount(struct nameidata *nd, char *type, int flags,
+static noinline int do_new_mount(struct nameidata *nd, char *type, int flags,
                        int mnt_flags, char *name, void *data)
 {
        struct vfsmount *mnt;
index eff1f18d034f1b2510aa6ef54c71427bda284ba1..fbbb9f7afa1ab2f8a4a020c904f8b2c11304f431 100644 (file)
@@ -28,6 +28,8 @@
 #include <linux/init.h>
 #include <linux/smp_lock.h>
 #include <linux/vfs.h>
+#include <linux/mount.h>
+#include <linux/seq_file.h>
 
 #include <linux/ncp_fs.h>
 
 #include "ncplib_kernel.h"
 #include "getopt.h"
 
+#define NCP_DEFAULT_FILE_MODE 0600
+#define NCP_DEFAULT_DIR_MODE 0700
+#define NCP_DEFAULT_TIME_OUT 10
+#define NCP_DEFAULT_RETRY_COUNT 20
+
 static void ncp_delete_inode(struct inode *);
 static void ncp_put_super(struct super_block *);
 static int  ncp_statfs(struct dentry *, struct kstatfs *);
+static int  ncp_show_options(struct seq_file *, struct vfsmount *);
 
 static struct kmem_cache * ncp_inode_cachep;
 
@@ -96,6 +104,7 @@ static const struct super_operations ncp_sops =
        .put_super      = ncp_put_super,
        .statfs         = ncp_statfs,
        .remount_fs     = ncp_remount,
+       .show_options   = ncp_show_options,
 };
 
 extern struct dentry_operations ncp_root_dentry_operations;
@@ -304,6 +313,37 @@ static void ncp_stop_tasks(struct ncp_server *server) {
        flush_scheduled_work();
 }
 
+static int  ncp_show_options(struct seq_file *seq, struct vfsmount *mnt)
+{
+       struct ncp_server *server = NCP_SBP(mnt->mnt_sb);
+       unsigned int tmp;
+
+       if (server->m.uid != 0)
+               seq_printf(seq, ",uid=%u", server->m.uid);
+       if (server->m.gid != 0)
+               seq_printf(seq, ",gid=%u", server->m.gid);
+       if (server->m.mounted_uid != 0)
+               seq_printf(seq, ",owner=%u", server->m.mounted_uid);
+       tmp = server->m.file_mode & S_IALLUGO;
+       if (tmp != NCP_DEFAULT_FILE_MODE)
+               seq_printf(seq, ",mode=0%o", tmp);
+       tmp = server->m.dir_mode & S_IALLUGO;
+       if (tmp != NCP_DEFAULT_DIR_MODE)
+               seq_printf(seq, ",dirmode=0%o", tmp);
+       if (server->m.time_out != NCP_DEFAULT_TIME_OUT * HZ / 100) {
+               tmp = server->m.time_out * 100 / HZ;
+               seq_printf(seq, ",timeout=%u", tmp);
+       }
+       if (server->m.retry_count != NCP_DEFAULT_RETRY_COUNT)
+               seq_printf(seq, ",retry=%u", server->m.retry_count);
+       if (server->m.flags != 0)
+               seq_printf(seq, ",flags=%lu", server->m.flags);
+       if (server->m.wdog_pid != NULL)
+               seq_printf(seq, ",wdogpid=%u", pid_vnr(server->m.wdog_pid));
+
+       return 0;
+}
+
 static const struct ncp_option ncp_opts[] = {
        { "uid",        OPT_INT,        'u' },
        { "gid",        OPT_INT,        'g' },
@@ -331,12 +371,12 @@ static int ncp_parse_options(struct ncp_mount_data_kernel *data, char *options)
        data->mounted_uid = 0;
        data->wdog_pid = NULL;
        data->ncp_fd = ~0;
-       data->time_out = 10;
-       data->retry_count = 20;
+       data->time_out = NCP_DEFAULT_TIME_OUT;
+       data->retry_count = NCP_DEFAULT_RETRY_COUNT;
        data->uid = 0;
        data->gid = 0;
-       data->file_mode = 0600;
-       data->dir_mode = 0700;
+       data->file_mode = NCP_DEFAULT_FILE_MODE;
+       data->dir_mode = NCP_DEFAULT_DIR_MODE;
        data->info_fd = -1;
        data->mounted_vol[0] = 0;
        
@@ -982,6 +1022,7 @@ static struct file_system_type ncp_fs_type = {
        .name           = "ncpfs",
        .get_sb         = ncp_get_sb,
        .kill_sb        = kill_anon_super,
+       .fs_flags       = FS_BINARY_MOUNTDATA,
 };
 
 static int __init init_ncp_fs(void)
index b144b1957dd99f7e011e7f635454f4d9215e4757..f55c437124a2287e1ae80834af5059c0f3388d38 100644 (file)
@@ -696,6 +696,17 @@ int nfs_flush_incompatible(struct file *file, struct page *page)
        return status;
 }
 
+/*
+ * If the page cache is marked as unsafe or invalid, then we can't rely on
+ * the PageUptodate() flag. In this case, we will need to turn off
+ * write optimisations that depend on the page contents being correct.
+ */
+static int nfs_write_pageuptodate(struct page *page, struct inode *inode)
+{
+       return PageUptodate(page) &&
+               !(NFS_I(inode)->cache_validity & (NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA));
+}
+
 /*
  * Update and possibly write a cached page of an NFS file.
  *
@@ -717,10 +728,13 @@ int nfs_updatepage(struct file *file, struct page *page,
                (long long)(page_offset(page) +offset));
 
        /* If we're not using byte range locks, and we know the page
-        * is entirely in cache, it may be more efficient to avoid
-        * fragmenting write requests.
+        * is up to date, it may be more efficient to extend the write
+        * to cover the entire page in order to avoid fragmentation
+        * inefficiencies.
         */
-       if (PageUptodate(page) && inode->i_flock == NULL && !(file->f_mode & O_SYNC)) {
+       if (nfs_write_pageuptodate(page, inode) &&
+                       inode->i_flock == NULL &&
+                       !(file->f_mode & O_SYNC)) {
                count = max(count + offset, nfs_page_length(page));
                offset = 0;
        }
diff --git a/fs/ocfs2/cluster/endian.h b/fs/ocfs2/cluster/endian.h
deleted file mode 100644 (file)
index 2df9082..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/* -*- mode: c; c-basic-offset: 8; -*-
- * vim: noexpandtab sw=8 ts=8 sts=0:
- *
- * Copyright (C) 2005 Oracle.  All rights reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA.
- */
-
-#ifndef OCFS2_CLUSTER_ENDIAN_H
-#define OCFS2_CLUSTER_ENDIAN_H
-
-static inline void be32_add_cpu(__be32 *var, u32 val)
-{
-       *var = cpu_to_be32(be32_to_cpu(*var) + val);
-}
-
-#endif /* OCFS2_CLUSTER_ENDIAN_H */
index af2070da308b87904c468988ba94cae0ee7cf8ae..709fba25bf7e1b4ed4b1f89b12f6fb632450a5b8 100644 (file)
@@ -24,7 +24,6 @@
 #include <linux/sysctl.h>
 #include <linux/configfs.h>
 
-#include "endian.h"
 #include "tcp.h"
 #include "nodemanager.h"
 #include "heartbeat.h"
index 2fd8bded38f31391c5aa80c2ec36c01874bf4572..644bee55d8ba4ccfb5ff29a489e2494274580c2f 100644 (file)
@@ -43,7 +43,6 @@
 #include "cluster/heartbeat.h"
 #include "cluster/nodemanager.h"
 #include "cluster/tcp.h"
-#include "cluster/endian.h"
 
 #include "dlmapi.h"
 #include "dlmcommon.h"
diff --git a/fs/ocfs2/endian.h b/fs/ocfs2/endian.h
deleted file mode 100644 (file)
index 1942e09..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/* -*- mode: c; c-basic-offset: 8; -*-
- * vim: noexpandtab sw=8 ts=8 sts=0:
- *
- * Copyright (C) 2005 Oracle.  All rights reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA.
- */
-
-#ifndef OCFS2_ENDIAN_H
-#define OCFS2_ENDIAN_H
-
-static inline void le16_add_cpu(__le16 *var, u16 val)
-{
-       *var = cpu_to_le16(le16_to_cpu(*var) + val);
-}
-
-static inline void le32_add_cpu(__le32 *var, u32 val)
-{
-       *var = cpu_to_le32(le32_to_cpu(*var) + val);
-}
-
-static inline void le64_add_cpu(__le64 *var, u64 val)
-{
-       *var = cpu_to_le64(le64_to_cpu(*var) + val);
-}
-
-static inline void be32_add_cpu(__be32 *var, u32 val)
-{
-       *var = cpu_to_be32(be32_to_cpu(*var) + val);
-}
-
-#endif /* OCFS2_ENDIAN_H */
index e8b7292e01527f72798d2a31a0fe27ef1a8d099d..6546cef212e3d1a14ca1797127d789c4cfc53eec 100644 (file)
@@ -43,7 +43,6 @@
 #include "dlm/dlmapi.h"
 
 #include "ocfs2_fs.h"
-#include "endian.h"
 #include "ocfs2_lockid.h"
 
 /* Most user visible OCFS2 inodes will have very few pieces of
index 4932b4d1da05f72037b22ec04378edcf83fbc14f..43fcd6031969509cb6d64d7d705cb1990a920e2e 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -991,7 +991,7 @@ static void __put_unused_fd(struct files_struct *files, unsigned int fd)
                files->next_fd = fd;
 }
 
-void fastcall put_unused_fd(unsigned int fd)
+void put_unused_fd(unsigned int fd)
 {
        struct files_struct *files = current->files;
        spin_lock(&files->file_lock);
@@ -1014,7 +1014,7 @@ EXPORT_SYMBOL(put_unused_fd);
  * will follow.
  */
 
-void fastcall fd_install(unsigned int fd, struct file * file)
+void fd_install(unsigned int fd, struct file *file)
 {
        struct files_struct *files = current->files;
        struct fdtable *fdt;
@@ -1061,7 +1061,6 @@ asmlinkage long sys_open(const char __user *filename, int flags, int mode)
        prevent_tail_call(ret);
        return ret;
 }
-EXPORT_UNUSED_SYMBOL_GPL(sys_open); /* To be deleted for 2.6.25 */
 
 asmlinkage long sys_openat(int dfd, const char __user *filename, int flags,
                           int mode)
index e66ec48e95d8f44223ba960e5fe82a9c7acd962d..a07e9a5420649d57c7da5b5b7b27f877d24b9c91 100644 (file)
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -576,9 +576,7 @@ bad_pipe_w(struct file *filp, const char __user *buf, size_t count,
        return -EBADF;
 }
 
-static int
-pipe_ioctl(struct inode *pino, struct file *filp,
-          unsigned int cmd, unsigned long arg)
+static long pipe_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
        struct inode *inode = filp->f_path.dentry->d_inode;
        struct pipe_inode_info *pipe;
@@ -785,7 +783,7 @@ const struct file_operations read_fifo_fops = {
        .aio_read       = pipe_read,
        .write          = bad_pipe_w,
        .poll           = pipe_poll,
-       .ioctl          = pipe_ioctl,
+       .unlocked_ioctl = pipe_ioctl,
        .open           = pipe_read_open,
        .release        = pipe_read_release,
        .fasync         = pipe_read_fasync,
@@ -797,7 +795,7 @@ const struct file_operations write_fifo_fops = {
        .write          = do_sync_write,
        .aio_write      = pipe_write,
        .poll           = pipe_poll,
-       .ioctl          = pipe_ioctl,
+       .unlocked_ioctl = pipe_ioctl,
        .open           = pipe_write_open,
        .release        = pipe_write_release,
        .fasync         = pipe_write_fasync,
@@ -810,7 +808,7 @@ const struct file_operations rdwr_fifo_fops = {
        .write          = do_sync_write,
        .aio_write      = pipe_write,
        .poll           = pipe_poll,
-       .ioctl          = pipe_ioctl,
+       .unlocked_ioctl = pipe_ioctl,
        .open           = pipe_rdwr_open,
        .release        = pipe_rdwr_release,
        .fasync         = pipe_rdwr_fasync,
@@ -822,7 +820,7 @@ static const struct file_operations read_pipe_fops = {
        .aio_read       = pipe_read,
        .write          = bad_pipe_w,
        .poll           = pipe_poll,
-       .ioctl          = pipe_ioctl,
+       .unlocked_ioctl = pipe_ioctl,
        .open           = pipe_read_open,
        .release        = pipe_read_release,
        .fasync         = pipe_read_fasync,
@@ -834,7 +832,7 @@ static const struct file_operations write_pipe_fops = {
        .write          = do_sync_write,
        .aio_write      = pipe_write,
        .poll           = pipe_poll,
-       .ioctl          = pipe_ioctl,
+       .unlocked_ioctl = pipe_ioctl,
        .open           = pipe_write_open,
        .release        = pipe_write_release,
        .fasync         = pipe_write_fasync,
@@ -847,7 +845,7 @@ static const struct file_operations rdwr_pipe_fops = {
        .write          = do_sync_write,
        .aio_write      = pipe_write,
        .poll           = pipe_poll,
-       .ioctl          = pipe_ioctl,
+       .unlocked_ioctl = pipe_ioctl,
        .open           = pipe_rdwr_open,
        .release        = pipe_rdwr_release,
        .fasync         = pipe_rdwr_fasync,
index 6ba2746e451706fc59beee9319cb896187958f05..07d6c4853fe858da49c51d8c199a8a3ff635602a 100644 (file)
@@ -77,6 +77,7 @@
 #include <linux/cpuset.h>
 #include <linux/rcupdate.h>
 #include <linux/delayacct.h>
+#include <linux/seq_file.h>
 #include <linux/pid_namespace.h>
 
 #include <asm/pgtable.h>
 do { memcpy(buffer, string, strlen(string)); \
      buffer += strlen(string); } while (0)
 
-static inline char *task_name(struct task_struct *p, char *buf)
+static inline void task_name(struct seq_file *m, struct task_struct *p)
 {
        int i;
+       char *buf, *end;
        char *name;
        char tcomm[sizeof(p->comm)];
 
        get_task_comm(tcomm, p);
 
-       ADDBUF(buf, "Name:\t");
+       seq_printf(m, "Name:\t");
+       end = m->buf + m->size;
+       buf = m->buf + m->count;
        name = tcomm;
        i = sizeof(tcomm);
-       do {
+       while (i && (buf < end)) {
                unsigned char c = *name;
                name++;
                i--;
@@ -107,20 +111,21 @@ static inline char *task_name(struct task_struct *p, char *buf)
                if (!c)
                        break;
                if (c == '\\') {
-                       buf[1] = c;
-                       buf += 2;
+                       buf++;
+                       if (buf < end)
+                               *buf++ = c;
                        continue;
                }
                if (c == '\n') {
-                       buf[0] = '\\';
-                       buf[1] = 'n';
-                       buf += 2;
+                       *buf++ = '\\';
+                       if (buf < end)
+                               *buf++ = 'n';
                        continue;
                }
                buf++;
-       } while (i);
-       *buf = '\n';
-       return buf+1;
+       }
+       m->count = buf - m->buf;
+       seq_printf(m, "\n");
 }
 
 /*
@@ -151,21 +156,20 @@ static inline const char *get_task_state(struct task_struct *tsk)
        return *p;
 }
 
-static inline char *task_state(struct task_struct *p, char *buffer)
+static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
+                               struct pid *pid, struct task_struct *p)
 {
        struct group_info *group_info;
        int g;
        struct fdtable *fdt = NULL;
-       struct pid_namespace *ns;
        pid_t ppid, tpid;
 
-       ns = current->nsproxy->pid_ns;
        rcu_read_lock();
        ppid = pid_alive(p) ?
                task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
        tpid = pid_alive(p) && p->ptrace ?
                task_pid_nr_ns(rcu_dereference(p->parent), ns) : 0;
-       buffer += sprintf(buffer,
+       seq_printf(m,
                "State:\t%s\n"
                "Tgid:\t%d\n"
                "Pid:\t%d\n"
@@ -175,7 +179,7 @@ static inline char *task_state(struct task_struct *p, char *buffer)
                "Gid:\t%d\t%d\t%d\t%d\n",
                get_task_state(p),
                task_tgid_nr_ns(p, ns),
-               task_pid_nr_ns(p, ns),
+               pid_nr_ns(pid, ns),
                ppid, tpid,
                p->uid, p->euid, p->suid, p->fsuid,
                p->gid, p->egid, p->sgid, p->fsgid);
@@ -183,7 +187,7 @@ static inline char *task_state(struct task_struct *p, char *buffer)
        task_lock(p);
        if (p->files)
                fdt = files_fdtable(p->files);
-       buffer += sprintf(buffer,
+       seq_printf(m,
                "FDSize:\t%d\n"
                "Groups:\t",
                fdt ? fdt->max_fds : 0);
@@ -194,20 +198,18 @@ static inline char *task_state(struct task_struct *p, char *buffer)
        task_unlock(p);
 
        for (g = 0; g < min(group_info->ngroups, NGROUPS_SMALL); g++)
-               buffer += sprintf(buffer, "%d ", GROUP_AT(group_info, g));
+               seq_printf(m, "%d ", GROUP_AT(group_info, g));
        put_group_info(group_info);
 
-       buffer += sprintf(buffer, "\n");
-       return buffer;
+       seq_printf(m, "\n");
 }
 
-static char *render_sigset_t(const char *header, sigset_t *set, char *buffer)
+static void render_sigset_t(struct seq_file *m, const char *header,
+                               sigset_t *set)
 {
-       int i, len;
+       int i;
 
-       len = strlen(header);
-       memcpy(buffer, header, len);
-       buffer += len;
+       seq_printf(m, "%s", header);
 
        i = _NSIG;
        do {
@@ -218,12 +220,10 @@ static char *render_sigset_t(const char *header, sigset_t *set, char *buffer)
                if (sigismember(set, i+2)) x |= 2;
                if (sigismember(set, i+3)) x |= 4;
                if (sigismember(set, i+4)) x |= 8;
-               *buffer++ = (x < 10 ? '0' : 'a' - 10) + x;
+               seq_printf(m, "%x", x);
        } while (i >= 4);
 
-       *buffer++ = '\n';
-       *buffer = 0;
-       return buffer;
+       seq_printf(m, "\n");
 }
 
 static void collect_sigign_sigcatch(struct task_struct *p, sigset_t *ign,
@@ -241,7 +241,7 @@ static void collect_sigign_sigcatch(struct task_struct *p, sigset_t *ign,
        }
 }
 
-static inline char *task_sig(struct task_struct *p, char *buffer)
+static inline void task_sig(struct seq_file *m, struct task_struct *p)
 {
        unsigned long flags;
        sigset_t pending, shpending, blocked, ignored, caught;
@@ -268,67 +268,66 @@ static inline char *task_sig(struct task_struct *p, char *buffer)
        }
        rcu_read_unlock();
 
-       buffer += sprintf(buffer, "Threads:\t%d\n", num_threads);
-       buffer += sprintf(buffer, "SigQ:\t%lu/%lu\n", qsize, qlim);
+       seq_printf(m, "Threads:\t%d\n", num_threads);
+       seq_printf(m, "SigQ:\t%lu/%lu\n", qsize, qlim);
 
        /* render them all */
-       buffer = render_sigset_t("SigPnd:\t", &pending, buffer);
-       buffer = render_sigset_t("ShdPnd:\t", &shpending, buffer);
-       buffer = render_sigset_t("SigBlk:\t", &blocked, buffer);
-       buffer = render_sigset_t("SigIgn:\t", &ignored, buffer);
-       buffer = render_sigset_t("SigCgt:\t", &caught, buffer);
-
-       return buffer;
+       render_sigset_t(m, "SigPnd:\t", &pending);
+       render_sigset_t(m, "ShdPnd:\t", &shpending);
+       render_sigset_t(m, "SigBlk:\t", &blocked);
+       render_sigset_t(m, "SigIgn:\t", &ignored);
+       render_sigset_t(m, "SigCgt:\t", &caught);
 }
 
-static char *render_cap_t(const char *header, kernel_cap_t *a, char *buffer)
+static void render_cap_t(struct seq_file *m, const char *header,
+                       kernel_cap_t *a)
 {
        unsigned __capi;
 
-       buffer += sprintf(buffer, "%s", header);
+       seq_printf(m, "%s", header);
        CAP_FOR_EACH_U32(__capi) {
-               buffer += sprintf(buffer, "%08x",
-                                 a->cap[(_LINUX_CAPABILITY_U32S-1) - __capi]);
+               seq_printf(m, "%08x",
+                          a->cap[(_LINUX_CAPABILITY_U32S-1) - __capi]);
        }
-       return buffer + sprintf(buffer, "\n");
+       seq_printf(m, "\n");
 }
 
-static inline char *task_cap(struct task_struct *p, char *buffer)
+static inline void task_cap(struct seq_file *m, struct task_struct *p)
 {
-       buffer = render_cap_t("CapInh:\t", &p->cap_inheritable, buffer);
-       buffer = render_cap_t("CapPrm:\t", &p->cap_permitted, buffer);
-       return render_cap_t("CapEff:\t", &p->cap_effective, buffer);
+       render_cap_t(m, "CapInh:\t", &p->cap_inheritable);
+       render_cap_t(m, "CapPrm:\t", &p->cap_permitted);
+       render_cap_t(m, "CapEff:\t", &p->cap_effective);
 }
 
-static inline char *task_context_switch_counts(struct task_struct *p,
-                                               char *buffer)
+static inline void task_context_switch_counts(struct seq_file *m,
+                                               struct task_struct *p)
 {
-       return buffer + sprintf(buffer, "voluntary_ctxt_switches:\t%lu\n"
-                           "nonvoluntary_ctxt_switches:\t%lu\n",
-                           p->nvcsw,
-                           p->nivcsw);
+       seq_printf(m,   "voluntary_ctxt_switches:\t%lu\n"
+                       "nonvoluntary_ctxt_switches:\t%lu\n",
+                       p->nvcsw,
+                       p->nivcsw);
 }
 
-int proc_pid_status(struct task_struct *task, char *buffer)
+int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
+                       struct pid *pid, struct task_struct *task)
 {
-       char *orig = buffer;
        struct mm_struct *mm = get_task_mm(task);
 
-       buffer = task_name(task, buffer);
-       buffer = task_state(task, buffer);
+       task_name(m, task);
+       task_state(m, ns, pid, task);
 
        if (mm) {
-               buffer = task_mem(mm, buffer);
+               task_mem(m, mm);
                mmput(mm);
        }
-       buffer = task_sig(task, buffer);
-       buffer = task_cap(task, buffer);
-       buffer = cpuset_task_status_allowed(task, buffer);
+       task_sig(m, task);
+       task_cap(m, task);
+       cpuset_task_status_allowed(m, task);
 #if defined(CONFIG_S390)
-       buffer = task_show_regs(task, buffer);
+       task_show_regs(m, task);
 #endif
-       buffer = task_context_switch_counts(task, buffer);
-       return buffer - orig;
+       task_context_switch_counts(m, task);
+       return 0;
 }
 
 /*
@@ -390,14 +389,14 @@ static cputime_t task_gtime(struct task_struct *p)
        return p->gtime;
 }
 
-static int do_task_stat(struct task_struct *task, char *buffer, int whole)
+static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
+                       struct pid *pid, struct task_struct *task, int whole)
 {
        unsigned long vsize, eip, esp, wchan = ~0UL;
        long priority, nice;
        int tty_pgrp = -1, tty_nr = 0;
        sigset_t sigign, sigcatch;
        char state;
-       int res;
        pid_t ppid = 0, pgid = -1, sid = -1;
        int num_threads = 0;
        struct mm_struct *mm;
@@ -409,9 +408,6 @@ static int do_task_stat(struct task_struct *task, char *buffer, int whole)
        unsigned long rsslim = 0;
        char tcomm[sizeof(task->comm)];
        unsigned long flags;
-       struct pid_namespace *ns;
-
-       ns = current->nsproxy->pid_ns;
 
        state = *get_task_state(task);
        vsize = eip = esp = 0;
@@ -498,10 +494,10 @@ static int do_task_stat(struct task_struct *task, char *buffer, int whole)
        /* convert nsec -> ticks */
        start_time = nsec_to_clock_t(start_time);
 
-       res = sprintf(buffer, "%d (%s) %c %d %d %d %d %d %u %lu \
+       seq_printf(m, "%d (%s) %c %d %d %d %d %d %u %lu \
 %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
 %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
-               task_pid_nr_ns(task, ns),
+               pid_nr_ns(pid, ns),
                tcomm,
                state,
                ppid,
@@ -550,20 +546,23 @@ static int do_task_stat(struct task_struct *task, char *buffer, int whole)
                cputime_to_clock_t(cgtime));
        if (mm)
                mmput(mm);
-       return res;
+       return 0;
 }
 
-int proc_tid_stat(struct task_struct *task, char *buffer)
+int proc_tid_stat(struct seq_file *m, struct pid_namespace *ns,
+                       struct pid *pid, struct task_struct *task)
 {
-       return do_task_stat(task, buffer, 0);
+       return do_task_stat(m, ns, pid, task, 0);
 }
 
-int proc_tgid_stat(struct task_struct *task, char *buffer)
+int proc_tgid_stat(struct seq_file *m, struct pid_namespace *ns,
+                       struct pid *pid, struct task_struct *task)
 {
-       return do_task_stat(task, buffer, 1);
+       return do_task_stat(m, ns, pid, task, 1);
 }
 
-int proc_pid_statm(struct task_struct *task, char *buffer)
+int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
+                       struct pid *pid, struct task_struct *task)
 {
        int size = 0, resident = 0, shared = 0, text = 0, lib = 0, data = 0;
        struct mm_struct *mm = get_task_mm(task);
@@ -572,7 +571,8 @@ int proc_pid_statm(struct task_struct *task, char *buffer)
                size = task_statm(mm, &shared, &text, &data, &resident);
                mmput(mm);
        }
+       seq_printf(m, "%d %d %d %d %d %d %d\n",
+                       size, resident, shared, text, lib, data, 0);
 
-       return sprintf(buffer, "%d %d %d %d %d %d %d\n",
-                      size, resident, shared, text, lib, data, 0);
+       return 0;
 }
index c59852b38787382a9399de7c69ae787ce22d9bf4..a0c4ba6c6e578f83c6ee70dd4dbf73a78bd5f002 100644 (file)
@@ -121,6 +121,10 @@ struct pid_entry {
        NOD(NAME, (S_IFREG|(MODE)),                     \
                NULL, &proc_info_file_operations,       \
                { .proc_read = &proc_##OTYPE } )
+#define ONE(NAME, MODE, OTYPE)                         \
+       NOD(NAME, (S_IFREG|(MODE)),                     \
+               NULL, &proc_single_file_operations,     \
+               { .proc_show = &proc_##OTYPE } )
 
 int maps_protect;
 EXPORT_SYMBOL(maps_protect);
@@ -502,7 +506,7 @@ static const struct inode_operations proc_def_inode_operations = {
        .setattr        = proc_setattr,
 };
 
-extern struct seq_operations mounts_op;
+extern const struct seq_operations mounts_op;
 struct proc_mounts {
        struct seq_file m;
        int event;
@@ -581,7 +585,7 @@ static const struct file_operations proc_mounts_operations = {
        .poll           = mounts_poll,
 };
 
-extern struct seq_operations mountstats_op;
+extern const struct seq_operations mountstats_op;
 static int mountstats_open(struct inode *inode, struct file *file)
 {
        int ret = seq_open(file, &mountstats_op);
@@ -658,6 +662,45 @@ static const struct file_operations proc_info_file_operations = {
        .read           = proc_info_read,
 };
 
+static int proc_single_show(struct seq_file *m, void *v)
+{
+       struct inode *inode = m->private;
+       struct pid_namespace *ns;
+       struct pid *pid;
+       struct task_struct *task;
+       int ret;
+
+       ns = inode->i_sb->s_fs_info;
+       pid = proc_pid(inode);
+       task = get_pid_task(pid, PIDTYPE_PID);
+       if (!task)
+               return -ESRCH;
+
+       ret = PROC_I(inode)->op.proc_show(m, ns, pid, task);
+
+       put_task_struct(task);
+       return ret;
+}
+
+static int proc_single_open(struct inode *inode, struct file *filp)
+{
+       int ret;
+       ret = single_open(filp, proc_single_show, NULL);
+       if (!ret) {
+               struct seq_file *m = filp->private_data;
+
+               m->private = inode;
+       }
+       return ret;
+}
+
+static const struct file_operations proc_single_file_operations = {
+       .open           = proc_single_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
 static int mem_open(struct inode* inode, struct file* file)
 {
        file->private_data = (void*)((long)current->self_exec_id);
@@ -2058,15 +2101,23 @@ static const struct file_operations proc_coredump_filter_operations = {
 static int proc_self_readlink(struct dentry *dentry, char __user *buffer,
                              int buflen)
 {
+       struct pid_namespace *ns = dentry->d_sb->s_fs_info;
+       pid_t pid = task_pid_nr_ns(current, ns);
        char tmp[PROC_NUMBUF];
-       sprintf(tmp, "%d", task_tgid_vnr(current));
+       if (!pid)
+               return -ENOENT;
+       sprintf(tmp, "%d", pid);
        return vfs_readlink(dentry,buffer,buflen,tmp);
 }
 
 static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
 {
+       struct pid_namespace *ns = dentry->d_sb->s_fs_info;
+       pid_t pid = task_pid_nr_ns(current, ns);
        char tmp[PROC_NUMBUF];
-       sprintf(tmp, "%d", task_tgid_vnr(current));
+       if (!pid)
+               return ERR_PTR(-ENOENT);
+       sprintf(tmp, "%d", pid);
        return ERR_PTR(vfs_follow_link(nd,tmp));
 }
 
@@ -2231,14 +2282,14 @@ static const struct pid_entry tgid_base_stuff[] = {
        DIR("fdinfo",     S_IRUSR|S_IXUSR, fdinfo),
        REG("environ",    S_IRUSR, environ),
        INF("auxv",       S_IRUSR, pid_auxv),
-       INF("status",     S_IRUGO, pid_status),
+       ONE("status",     S_IRUGO, pid_status),
        INF("limits",     S_IRUSR, pid_limits),
 #ifdef CONFIG_SCHED_DEBUG
        REG("sched",      S_IRUGO|S_IWUSR, pid_sched),
 #endif
        INF("cmdline",    S_IRUGO, pid_cmdline),
-       INF("stat",       S_IRUGO, tgid_stat),
-       INF("statm",      S_IRUGO, pid_statm),
+       ONE("stat",       S_IRUGO, tgid_stat),
+       ONE("statm",      S_IRUGO, pid_statm),
        REG("maps",       S_IRUGO, maps),
 #ifdef CONFIG_NUMA
        REG("numa_maps",  S_IRUGO, numa_maps),
@@ -2562,14 +2613,14 @@ static const struct pid_entry tid_base_stuff[] = {
        DIR("fdinfo",    S_IRUSR|S_IXUSR, fdinfo),
        REG("environ",   S_IRUSR, environ),
        INF("auxv",      S_IRUSR, pid_auxv),
-       INF("status",    S_IRUGO, pid_status),
+       ONE("status",    S_IRUGO, pid_status),
        INF("limits",    S_IRUSR, pid_limits),
 #ifdef CONFIG_SCHED_DEBUG
        REG("sched",     S_IRUGO|S_IWUSR, pid_sched),
 #endif
        INF("cmdline",   S_IRUGO, pid_cmdline),
-       INF("stat",      S_IRUGO, tid_stat),
-       INF("statm",     S_IRUGO, pid_statm),
+       ONE("stat",      S_IRUGO, tid_stat),
+       ONE("statm",     S_IRUGO, pid_statm),
        REG("maps",      S_IRUGO, maps),
 #ifdef CONFIG_NUMA
        REG("numa_maps", S_IRUGO, numa_maps),
index 6a2fe5187b6265db0c896aa9e68ec6fb7507a3a4..68971e66cd41ca438f7dff0e6047322fca2b5d5f 100644 (file)
 
 #include "internal.h"
 
-static ssize_t proc_file_read(struct file *file, char __user *buf,
-                             size_t nbytes, loff_t *ppos);
-static ssize_t proc_file_write(struct file *file, const char __user *buffer,
-                              size_t count, loff_t *ppos);
-static loff_t proc_file_lseek(struct file *, loff_t, int);
-
 DEFINE_SPINLOCK(proc_subdir_lock);
 
 static int proc_match(int len, const char *name, struct proc_dir_entry *de)
@@ -40,12 +34,6 @@ static int proc_match(int len, const char *name, struct proc_dir_entry *de)
        return !memcmp(name, de->name, len);
 }
 
-static const struct file_operations proc_file_operations = {
-       .llseek         = proc_file_lseek,
-       .read           = proc_file_read,
-       .write          = proc_file_write,
-};
-
 /* buffer size is one page but our output routines use some slack for overruns */
 #define PROC_BLOCK_SIZE        (PAGE_SIZE - 1024)
 
@@ -233,6 +221,12 @@ proc_file_lseek(struct file *file, loff_t offset, int orig)
        return retval;
 }
 
+static const struct file_operations proc_file_operations = {
+       .llseek         = proc_file_lseek,
+       .read           = proc_file_read,
+       .write          = proc_file_write,
+};
+
 static int proc_notify_change(struct dentry *dentry, struct iattr *iattr)
 {
        struct inode *inode = dentry->d_inode;
@@ -406,12 +400,12 @@ struct dentry *proc_lookup(struct inode * dir, struct dentry *dentry, struct nam
                                spin_unlock(&proc_subdir_lock);
                                error = -EINVAL;
                                inode = proc_get_inode(dir->i_sb, ino, de);
-                               spin_lock(&proc_subdir_lock);
-                               break;
+                               goto out_unlock;
                        }
                }
        }
        spin_unlock(&proc_subdir_lock);
+out_unlock:
        unlock_kernel();
 
        if (inode) {
@@ -527,6 +521,7 @@ static const struct inode_operations proc_dir_inode_operations = {
 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
 {
        unsigned int i;
+       struct proc_dir_entry *tmp;
        
        i = get_inode_number();
        if (i == 0)
@@ -550,6 +545,15 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
        }
 
        spin_lock(&proc_subdir_lock);
+
+       for (tmp = dir->subdir; tmp; tmp = tmp->next)
+               if (strcmp(tmp->name, dp->name) == 0) {
+                       printk(KERN_WARNING "proc_dir_entry '%s' already "
+                                       "registered\n", dp->name);
+                       dump_stack();
+                       break;
+               }
+
        dp->next = dir->subdir;
        dp->parent = dir;
        dir->subdir = dp;
@@ -558,7 +562,7 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
        return 0;
 }
 
-static struct proc_dir_entry *proc_create(struct proc_dir_entry **parent,
+static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent,
                                          const char *name,
                                          mode_t mode,
                                          nlink_t nlink)
@@ -601,7 +605,7 @@ struct proc_dir_entry *proc_symlink(const char *name,
 {
        struct proc_dir_entry *ent;
 
-       ent = proc_create(&parent,name,
+       ent = __proc_create(&parent, name,
                          (S_IFLNK | S_IRUGO | S_IWUGO | S_IXUGO),1);
 
        if (ent) {
@@ -626,7 +630,7 @@ struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
 {
        struct proc_dir_entry *ent;
 
-       ent = proc_create(&parent, name, S_IFDIR | mode, 2);
+       ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
        if (ent) {
                if (proc_register(parent, ent) < 0) {
                        kfree(ent);
@@ -660,7 +664,7 @@ struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
                nlink = 1;
        }
 
-       ent = proc_create(&parent,name,mode,nlink);
+       ent = __proc_create(&parent, name, mode, nlink);
        if (ent) {
                if (proc_register(parent, ent) < 0) {
                        kfree(ent);
@@ -670,6 +674,38 @@ struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
        return ent;
 }
 
+struct proc_dir_entry *proc_create(const char *name, mode_t mode,
+                                  struct proc_dir_entry *parent,
+                                  const struct file_operations *proc_fops)
+{
+       struct proc_dir_entry *pde;
+       nlink_t nlink;
+
+       if (S_ISDIR(mode)) {
+               if ((mode & S_IALLUGO) == 0)
+                       mode |= S_IRUGO | S_IXUGO;
+               nlink = 2;
+       } else {
+               if ((mode & S_IFMT) == 0)
+                       mode |= S_IFREG;
+               if ((mode & S_IALLUGO) == 0)
+                       mode |= S_IRUGO;
+               nlink = 1;
+       }
+
+       pde = __proc_create(&parent, name, mode, nlink);
+       if (!pde)
+               goto out;
+       pde->proc_fops = proc_fops;
+       if (proc_register(parent, pde) < 0)
+               goto out_free;
+       return pde;
+out_free:
+       kfree(pde);
+out:
+       return NULL;
+}
+
 void free_proc_entry(struct proc_dir_entry *de)
 {
        unsigned int ino = de->low_ino;
@@ -679,7 +715,7 @@ void free_proc_entry(struct proc_dir_entry *de)
 
        release_inode_number(ino);
 
-       if (S_ISLNK(de->mode) && de->data)
+       if (S_ISLNK(de->mode))
                kfree(de->data);
        kfree(de);
 }
index 6ecf6396f0722e302c9108cd972624ff2cee290d..82b3a1b5a70b8c887a2e4b7cf698843097b84c0e 100644 (file)
@@ -467,4 +467,3 @@ out_no_root:
        de_put(&proc_root);
        return -ENOMEM;
 }
-MODULE_LICENSE("GPL");
index 7d57e80699241fade80e341cd47ca057444a6f69..ea496ffeabe7da2ac85f962a0186376c18c6f0c2 100644 (file)
@@ -46,12 +46,17 @@ extern int nommu_vma_show(struct seq_file *, struct vm_area_struct *);
 
 extern int maps_protect;
 
-extern void create_seq_entry(char *name, mode_t mode, const struct file_operations *f);
+extern void create_seq_entry(char *name, mode_t mode,
+                               const struct file_operations *f);
 extern int proc_exe_link(struct inode *, struct dentry **, struct vfsmount **);
-extern int proc_tid_stat(struct task_struct *,  char *);
-extern int proc_tgid_stat(struct task_struct *, char *);
-extern int proc_pid_status(struct task_struct *, char *);
-extern int proc_pid_statm(struct task_struct *, char *);
+extern int proc_tid_stat(struct seq_file *m, struct pid_namespace *ns,
+                               struct pid *pid, struct task_struct *task);
+extern int proc_tgid_stat(struct seq_file *m, struct pid_namespace *ns,
+                               struct pid *pid, struct task_struct *task);
+extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
+                               struct pid *pid, struct task_struct *task);
+extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
+                               struct pid *pid, struct task_struct *task);
 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
 
 extern const struct file_operations proc_maps_operations;
index 7dd26e18cbfd6f4941f9744d47381ada5c4bfcfe..e78c81fcf547981f3aa99c7ebeca831af15e98f5 100644 (file)
@@ -12,7 +12,6 @@
 #include <linux/mm.h>
 #include <linux/proc_fs.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/capability.h>
 #include <linux/elf.h>
 #include <linux/elfcore.h>
index 22f789de390941797102693a7a80c635a7f381ce..5d9147b9d7380c35a4610de862f12ca4503a2c8a 100644 (file)
@@ -116,7 +116,7 @@ static void *nommu_vma_list_next(struct seq_file *m, void *v, loff_t *pos)
        return rb_next((struct rb_node *) v);
 }
 
-static struct seq_operations proc_nommu_vma_list_seqop = {
+static const struct seq_operations proc_nommu_vma_list_seqop = {
        .start  = nommu_vma_list_start,
        .next   = nommu_vma_list_next,
        .stop   = nommu_vma_list_stop,
index 2686592dbcb2b01b29108da7587361afce9fa6c3..468805d40e2bdb44daeb43bfccf4a1b5919c7add 100644 (file)
@@ -222,7 +222,7 @@ static int meminfo_read_proc(char *page, char **start, off_t off,
 #undef K
 }
 
-extern struct seq_operations fragmentation_op;
+extern const struct seq_operations fragmentation_op;
 static int fragmentation_open(struct inode *inode, struct file *file)
 {
        (void)inode;
@@ -236,7 +236,7 @@ static const struct file_operations fragmentation_file_operations = {
        .release        = seq_release,
 };
 
-extern struct seq_operations pagetypeinfo_op;
+extern const struct seq_operations pagetypeinfo_op;
 static int pagetypeinfo_open(struct inode *inode, struct file *file)
 {
        return seq_open(file, &pagetypeinfo_op);
@@ -249,7 +249,7 @@ static const struct file_operations pagetypeinfo_file_ops = {
        .release        = seq_release,
 };
 
-extern struct seq_operations zoneinfo_op;
+extern const struct seq_operations zoneinfo_op;
 static int zoneinfo_open(struct inode *inode, struct file *file)
 {
        return seq_open(file, &zoneinfo_op);
@@ -274,7 +274,7 @@ static int version_read_proc(char *page, char **start, off_t off,
        return proc_calc_metrics(page, start, off, count, eof, len);
 }
 
-extern struct seq_operations cpuinfo_op;
+extern const struct seq_operations cpuinfo_op;
 static int cpuinfo_open(struct inode *inode, struct file *file)
 {
        return seq_open(file, &cpuinfo_op);
@@ -327,7 +327,7 @@ static void devinfo_stop(struct seq_file *f, void *v)
        /* Nothing to do */
 }
 
-static struct seq_operations devinfo_ops = {
+static const struct seq_operations devinfo_ops = {
        .start = devinfo_start,
        .next  = devinfo_next,
        .stop  = devinfo_stop,
@@ -346,7 +346,7 @@ static const struct file_operations proc_devinfo_operations = {
        .release        = seq_release,
 };
 
-extern struct seq_operations vmstat_op;
+extern const struct seq_operations vmstat_op;
 static int vmstat_open(struct inode *inode, struct file *file)
 {
        return seq_open(file, &vmstat_op);
@@ -377,7 +377,7 @@ static int stram_read_proc(char *page, char **start, off_t off,
 #endif
 
 #ifdef CONFIG_BLOCK
-extern struct seq_operations partitions_op;
+extern const struct seq_operations partitions_op;
 static int partitions_open(struct inode *inode, struct file *file)
 {
        return seq_open(file, &partitions_op);
@@ -389,7 +389,7 @@ static const struct file_operations proc_partitions_operations = {
        .release        = seq_release,
 };
 
-extern struct seq_operations diskstats_op;
+extern const struct seq_operations diskstats_op;
 static int diskstats_open(struct inode *inode, struct file *file)
 {
        return seq_open(file, &diskstats_op);
@@ -403,7 +403,7 @@ static const struct file_operations proc_diskstats_operations = {
 #endif
 
 #ifdef CONFIG_MODULES
-extern struct seq_operations modules_op;
+extern const struct seq_operations modules_op;
 static int modules_open(struct inode *inode, struct file *file)
 {
        return seq_open(file, &modules_op);
@@ -430,7 +430,7 @@ static const struct file_operations proc_slabinfo_operations = {
 };
 
 #ifdef CONFIG_DEBUG_SLAB_LEAK
-extern struct seq_operations slabstats_op;
+extern const struct seq_operations slabstats_op;
 static int slabstats_open(struct inode *inode, struct file *file)
 {
        unsigned long *n = kzalloc(PAGE_SIZE, GFP_KERNEL);
@@ -604,7 +604,7 @@ static void int_seq_stop(struct seq_file *f, void *v)
 }
 
 
-static struct seq_operations int_seq_ops = {
+static const struct seq_operations int_seq_ops = {
        .start = int_seq_start,
        .next  = int_seq_next,
        .stop  = int_seq_stop,
index 4823c9677facf0790ccf0971f516d253ef43f093..14e9b5aaf863bce23d6ccb03aa582cb9b6a4c566 100644 (file)
@@ -67,12 +67,7 @@ EXPORT_SYMBOL_GPL(seq_release_net);
 struct proc_dir_entry *proc_net_fops_create(struct net *net,
        const char *name, mode_t mode, const struct file_operations *fops)
 {
-       struct proc_dir_entry *res;
-
-       res = create_proc_entry(name, mode, net->proc_net);
-       if (res)
-               res->proc_fops = fops;
-       return res;
+       return proc_create(name, mode, net->proc_net, fops);
 }
 EXPORT_SYMBOL_GPL(proc_net_fops_create);
 
index 4e57fcf85982f648ec29f7c0962a1cebae990388..b9cb23c08f631fbafb632cfa0bd1e180712c7443 100644 (file)
@@ -9,7 +9,7 @@
 
 static struct dentry_operations proc_sys_dentry_operations;
 static const struct file_operations proc_sys_file_operations;
-static struct inode_operations proc_sys_inode_operations;
+static const struct inode_operations proc_sys_inode_operations;
 
 static void proc_sys_refresh_inode(struct inode *inode, struct ctl_table *table)
 {
@@ -446,7 +446,7 @@ static const struct file_operations proc_sys_file_operations = {
        .readdir        = proc_sys_readdir,
 };
 
-static struct inode_operations proc_sys_inode_operations = {
+static const struct inode_operations proc_sys_inode_operations = {
        .lookup         = proc_sys_lookup,
        .permission     = proc_sys_permission,
        .setattr        = proc_sys_setattr,
index 22846225acfaa933b992ed4e787199960b601757..49816e00b51a25899f860215166b97acd8584044 100644 (file)
@@ -15,9 +15,6 @@
 #include <linux/seq_file.h>
 #include <linux/bitops.h>
 
-static int tty_ldiscs_read_proc(char *page, char **start, off_t off,
-                               int count, int *eof, void *data);
-
 /*
  * The /proc/tty directory inodes...
  */
@@ -120,7 +117,7 @@ static void t_stop(struct seq_file *m, void *v)
        mutex_unlock(&tty_mutex);
 }
 
-static struct seq_operations tty_drivers_op = {
+static const struct seq_operations tty_drivers_op = {
        .start  = t_start,
        .next   = t_next,
        .stop   = t_stop,
index 81f99e691f99014eeaefb8cefa0c582719074a39..ef0fb57fc9ef794e6a5b849c27efe26fadb9f4f8 100644 (file)
@@ -232,6 +232,7 @@ void pid_ns_release_proc(struct pid_namespace *ns)
 EXPORT_SYMBOL(proc_symlink);
 EXPORT_SYMBOL(proc_mkdir);
 EXPORT_SYMBOL(create_proc_entry);
+EXPORT_SYMBOL(proc_create);
 EXPORT_SYMBOL(remove_proc_entry);
 EXPORT_SYMBOL(proc_root);
 EXPORT_SYMBOL(proc_root_fs);
index 38338ed98cc6df167febbe2fc962f55a700bfb19..ae4d3f2c8cb2dc1b629e3d7e356fb269421fd47d 100644 (file)
@@ -9,13 +9,14 @@
 #include <linux/mempolicy.h>
 #include <linux/swap.h>
 #include <linux/swapops.h>
+#include <linux/seq_file.h>
 
 #include <asm/elf.h>
 #include <asm/uaccess.h>
 #include <asm/tlbflush.h>
 #include "internal.h"
 
-char *task_mem(struct mm_struct *mm, char *buffer)
+void task_mem(struct seq_file *m, struct mm_struct *mm)
 {
        unsigned long data, text, lib;
        unsigned long hiwater_vm, total_vm, hiwater_rss, total_rss;
@@ -37,7 +38,7 @@ char *task_mem(struct mm_struct *mm, char *buffer)
        data = mm->total_vm - mm->shared_vm - mm->stack_vm;
        text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10;
        lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text;
-       buffer += sprintf(buffer,
+       seq_printf(m,
                "VmPeak:\t%8lu kB\n"
                "VmSize:\t%8lu kB\n"
                "VmLck:\t%8lu kB\n"
@@ -56,7 +57,6 @@ char *task_mem(struct mm_struct *mm, char *buffer)
                data << (PAGE_SHIFT-10),
                mm->stack_vm << (PAGE_SHIFT-10), text, lib,
                (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
-       return buffer;
 }
 
 unsigned long task_vsize(struct mm_struct *mm)
@@ -216,7 +216,7 @@ static void m_stop(struct seq_file *m, void *v)
 }
 
 static int do_maps_open(struct inode *inode, struct file *file,
-                       struct seq_operations *ops)
+                       const struct seq_operations *ops)
 {
        struct proc_maps_private *priv;
        int ret = -ENOMEM;
@@ -299,7 +299,7 @@ static int show_map(struct seq_file *m, void *v)
        return 0;
 }
 
-static struct seq_operations proc_pid_maps_op = {
+static const struct seq_operations proc_pid_maps_op = {
        .start  = m_start,
        .next   = m_next,
        .stop   = m_stop,
@@ -434,7 +434,7 @@ static int show_smap(struct seq_file *m, void *v)
        return ret;
 }
 
-static struct seq_operations proc_pid_smaps_op = {
+static const struct seq_operations proc_pid_smaps_op = {
        .start  = m_start,
        .next   = m_next,
        .stop   = m_stop,
@@ -734,7 +734,7 @@ static int show_numa_map_checked(struct seq_file *m, void *v)
        return show_numa_map(m, v);
 }
 
-static struct seq_operations proc_pid_numa_maps_op = {
+static const struct seq_operations proc_pid_numa_maps_op = {
         .start  = m_start,
         .next   = m_next,
         .stop   = m_stop,
index 1932c2ca345729580c60f5a0a2b8187779b9c450..abfc6f5e56caa696138ad8c91c22a3d35c32b231 100644 (file)
@@ -12,7 +12,7 @@
  * each process that owns it. Non-shared memory is counted
  * accurately.
  */
-char *task_mem(struct mm_struct *mm, char *buffer)
+void task_mem(struct seq_file *m, struct mm_struct *mm)
 {
        struct vm_list_struct *vml;
        unsigned long bytes = 0, sbytes = 0, slack = 0;
@@ -58,14 +58,13 @@ char *task_mem(struct mm_struct *mm, char *buffer)
 
        bytes += kobjsize(current); /* includes kernel stack */
 
-       buffer += sprintf(buffer,
+       seq_printf(m,
                "Mem:\t%8lu bytes\n"
                "Slack:\t%8lu bytes\n"
                "Shared:\t%8lu bytes\n",
                bytes, slack, sbytes);
 
        up_read(&mm->mmap_sem);
-       return buffer;
 }
 
 unsigned long task_vsize(struct mm_struct *mm)
@@ -199,7 +198,7 @@ static void *m_next(struct seq_file *m, void *_vml, loff_t *pos)
        return vml ? vml->next : NULL;
 }
 
-static struct seq_operations proc_pid_maps_ops = {
+static const struct seq_operations proc_pid_maps_ops = {
        .start  = m_start,
        .next   = m_next,
        .stop   = m_stop,
index 523e1098ae88f4d85fe87f9df388249e46af9adf..9ac0f5e064e09e99f58b428e933b2903a893a5b9 100644 (file)
@@ -10,7 +10,6 @@
 #include <linux/mm.h>
 #include <linux/proc_fs.h>
 #include <linux/user.h>
-#include <linux/a.out.h>
 #include <linux/elf.h>
 #include <linux/elfcore.h>
 #include <linux/highmem.h>
index 1c177f29e1b72be0aa63f38496ed81727d01f653..49a98718ecdf77ce2dae03b74530a0c90d13195f 100644 (file)
@@ -366,7 +366,6 @@ asmlinkage ssize_t sys_read(unsigned int fd, char __user * buf, size_t count)
 
        return ret;
 }
-EXPORT_UNUSED_SYMBOL_GPL(sys_read); /* to be deleted for 2.6.25 */
 
 asmlinkage ssize_t sys_write(unsigned int fd, const char __user * buf, size_t count)
 {
index 001144621672793c2cb3fd58e3604a990c093312..8f86c52b30d821884c3f576932e3e0d2e96981ba 100644 (file)
@@ -444,7 +444,7 @@ static int r_show(struct seq_file *m, void *v)
        return show(m, v);
 }
 
-static struct seq_operations r_ops = {
+static const struct seq_operations r_ops = {
        .start = r_start,
        .next = r_next,
        .stop = r_stop,
index 5cd85fe5df5d9671516a03d3c9927b96ea0e7c63..6033f0c3bd0bcfb22d84882555eaf36dee95dfde 100644 (file)
@@ -617,6 +617,7 @@ static const struct super_operations reiserfs_sops = {
        .unlockfs = reiserfs_unlockfs,
        .statfs = reiserfs_statfs,
        .remount_fs = reiserfs_remount,
+       .show_options = generic_show_options,
 #ifdef CONFIG_QUOTA
        .quota_read = reiserfs_quota_read,
        .quota_write = reiserfs_quota_write,
@@ -1138,6 +1139,7 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
        unsigned long safe_mask = 0;
        unsigned int commit_max_age = (unsigned int)-1;
        struct reiserfs_journal *journal = SB_JOURNAL(s);
+       char *new_opts = kstrdup(arg, GFP_KERNEL);
        int err;
 #ifdef CONFIG_QUOTA
        int i;
@@ -1153,7 +1155,8 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
                        REISERFS_SB(s)->s_qf_names[i] = NULL;
                }
 #endif
-               return -EINVAL;
+               err = -EINVAL;
+               goto out_err;
        }
 
        handle_attrs(s);
@@ -1191,9 +1194,9 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
        }
 
        if (blocks) {
-               int rc = reiserfs_resize(s, blocks);
-               if (rc != 0)
-                       return rc;
+               err = reiserfs_resize(s, blocks);
+               if (err != 0)
+                       goto out_err;
        }
 
        if (*mount_flags & MS_RDONLY) {
@@ -1201,16 +1204,16 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
                /* remount read-only */
                if (s->s_flags & MS_RDONLY)
                        /* it is read-only already */
-                       return 0;
+                       goto out_ok;
                /* try to remount file system with read-only permissions */
                if (sb_umount_state(rs) == REISERFS_VALID_FS
                    || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
-                       return 0;
+                       goto out_ok;
                }
 
                err = journal_begin(&th, s, 10);
                if (err)
-                       return err;
+                       goto out_err;
 
                /* Mounting a rw partition read-only. */
                reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
@@ -1220,11 +1223,13 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
                /* remount read-write */
                if (!(s->s_flags & MS_RDONLY)) {
                        reiserfs_xattr_init(s, *mount_flags);
-                       return 0;       /* We are read-write already */
+                       goto out_ok;    /* We are read-write already */
                }
 
-               if (reiserfs_is_journal_aborted(journal))
-                       return journal->j_errno;
+               if (reiserfs_is_journal_aborted(journal)) {
+                       err = journal->j_errno;
+                       goto out_err;
+               }
 
                handle_data_mode(s, mount_options);
                handle_barrier_mode(s, mount_options);
@@ -1232,7 +1237,7 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
                s->s_flags &= ~MS_RDONLY;       /* now it is safe to call journal_begin */
                err = journal_begin(&th, s, 10);
                if (err)
-                       return err;
+                       goto out_err;
 
                /* Mount a partition which is read-only, read-write */
                reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
@@ -1247,7 +1252,7 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
        SB_JOURNAL(s)->j_must_wait = 1;
        err = journal_end(&th, s, 10);
        if (err)
-               return err;
+               goto out_err;
        s->s_dirt = 0;
 
        if (!(*mount_flags & MS_RDONLY)) {
@@ -1255,7 +1260,14 @@ static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
                reiserfs_xattr_init(s, *mount_flags);
        }
 
+out_ok:
+       kfree(s->s_options);
+       s->s_options = new_opts;
        return 0;
+
+out_err:
+       kfree(new_opts);
+       return err;
 }
 
 static int read_super_block(struct super_block *s, int offset)
@@ -1559,6 +1571,8 @@ static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
        struct reiserfs_sb_info *sbi;
        int errval = -EINVAL;
 
+       save_mount_options(s, data);
+
        sbi = kzalloc(sizeof(struct reiserfs_sb_info), GFP_KERNEL);
        if (!sbi) {
                errval = -ENOMEM;
index 4ee49e86edde5a2272781b6e49e0371b721ceb33..14e2262c0a046641ece8086c7f7329a8a114ebda 100644 (file)
@@ -1179,6 +1179,9 @@ static int copy_from_user_mmap_sem(void *dst, const void __user *src, size_t n)
 {
        int partial;
 
+       if (!access_ok(VERIFY_READ, src, n))
+               return -EFAULT;
+
        pagefault_disable();
        partial = __copy_from_user_inatomic(dst, src, n);
        pagefault_enable();
@@ -1387,6 +1390,11 @@ static long vmsplice_to_user(struct file *file, const struct iovec __user *iov,
                        break;
                }
 
+               if (unlikely(!access_ok(VERIFY_WRITE, base, len))) {
+                       error = -EFAULT;
+                       break;
+               }
+
                sd.len = 0;
                sd.total_len = len;
                sd.flags = flags;
index ceaf2e3d594cdd89afabab0253cf1ab59badceba..88811f60c8de517829ce7828c1971bfb4f90d8a1 100644 (file)
@@ -105,6 +105,7 @@ static inline void destroy_super(struct super_block *s)
 {
        security_sb_free(s);
        kfree(s->s_subtype);
+       kfree(s->s_options);
        kfree(s);
 }
 
@@ -603,6 +604,7 @@ int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
                        mark_files_ro(sb);
                else if (!fs_may_remount_ro(sb))
                        return -EBUSY;
+               DQUOT_OFF(sb);
        }
 
        if (sb->s_op->remount_fs) {
index ab26176f6b91129e924351c067aad96b909223ec..d721a1af19721fc0202ba9985b1278a04871b039 100644 (file)
 #include "udf_i.h"
 #include "udf_sb.h"
 
-#define udf_clear_bit(nr,addr) ext2_clear_bit(nr,addr)
-#define udf_set_bit(nr,addr) ext2_set_bit(nr,addr)
+#define udf_clear_bit(nr, addr) ext2_clear_bit(nr, addr)
+#define udf_set_bit(nr, addr) ext2_set_bit(nr, addr)
 #define udf_test_bit(nr, addr) ext2_test_bit(nr, addr)
 #define udf_find_first_one_bit(addr, size) find_first_one_bit(addr, size)
-#define udf_find_next_one_bit(addr, size, offset) find_next_one_bit(addr, size, offset)
+#define udf_find_next_one_bit(addr, size, offset) \
+               find_next_one_bit(addr, size, offset)
 
 #define leBPL_to_cpup(x) leNUM_to_cpup(BITS_PER_LONG, x)
-#define leNUM_to_cpup(x,y) xleNUM_to_cpup(x,y)
-#define xleNUM_to_cpup(x,y) (le ## x ## _to_cpup(y))
+#define leNUM_to_cpup(x, y) xleNUM_to_cpup(x, y)
+#define xleNUM_to_cpup(x, y) (le ## x ## _to_cpup(y))
 #define uintBPL_t uint(BITS_PER_LONG)
 #define uint(x) xuint(x)
 #define xuint(x) __le ## x
@@ -62,7 +63,8 @@ static inline int find_next_one_bit(void *addr, int size, int offset)
                result += BITS_PER_LONG;
        }
        while (size & ~(BITS_PER_LONG - 1)) {
-               if ((tmp = leBPL_to_cpup(p++)))
+               tmp = leBPL_to_cpup(p++);
+               if (tmp)
                        goto found_middle;
                result += BITS_PER_LONG;
                size -= BITS_PER_LONG;
@@ -88,12 +90,12 @@ static int read_block_bitmap(struct super_block *sb,
        kernel_lb_addr loc;
 
        loc.logicalBlockNum = bitmap->s_extPosition;
-       loc.partitionReferenceNum = UDF_SB_PARTITION(sb);
+       loc.partitionReferenceNum = UDF_SB(sb)->s_partition;
 
        bh = udf_tread(sb, udf_get_lb_pblock(sb, loc, block));
-       if (!bh) {
+       if (!bh)
                retval = -EIO;
-       }
+
        bitmap->s_block_bitmap[bitmap_nr] = bh;
        return retval;
 }
@@ -138,6 +140,20 @@ static inline int load_block_bitmap(struct super_block *sb,
        return slot;
 }
 
+static bool udf_add_free_space(struct udf_sb_info *sbi,
+                               u16 partition, u32 cnt)
+{
+       struct logicalVolIntegrityDesc *lvid;
+
+       if (sbi->s_lvid_bh)
+               return false;
+
+       lvid = (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data;
+       lvid->freeSpaceTable[partition] = cpu_to_le32(le32_to_cpu(
+                                       lvid->freeSpaceTable[partition]) + cnt);
+       return true;
+}
+
 static void udf_bitmap_free_blocks(struct super_block *sb,
                                   struct inode *inode,
                                   struct udf_bitmap *bitmap,
@@ -155,57 +171,58 @@ static void udf_bitmap_free_blocks(struct super_block *sb,
 
        mutex_lock(&sbi->s_alloc_mutex);
        if (bloc.logicalBlockNum < 0 ||
-           (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) {
+           (bloc.logicalBlockNum + count) >
+               sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
                udf_debug("%d < %d || %d + %d > %d\n",
                          bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
-                         UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum));
+                         sbi->s_partmaps[bloc.partitionReferenceNum].
+                                                       s_partition_len);
                goto error_return;
        }
 
-       block = bloc.logicalBlockNum + offset + (sizeof(struct spaceBitmapDesc) << 3);
+       block = bloc.logicalBlockNum + offset +
+               (sizeof(struct spaceBitmapDesc) << 3);
 
-do_more:
-       overflow = 0;
-       block_group = block >> (sb->s_blocksize_bits + 3);
-       bit = block % (sb->s_blocksize << 3);
+       do {
+               overflow = 0;
+               block_group = block >> (sb->s_blocksize_bits + 3);
+               bit = block % (sb->s_blocksize << 3);
 
-       /*
-        * Check to see if we are freeing blocks across a group boundary.
-        */
-       if (bit + count > (sb->s_blocksize << 3)) {
-               overflow = bit + count - (sb->s_blocksize << 3);
-               count -= overflow;
-       }
-       bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
-       if (bitmap_nr < 0)
-               goto error_return;
+               /*
+               * Check to see if we are freeing blocks across a group boundary.
+               */
+               if (bit + count > (sb->s_blocksize << 3)) {
+                       overflow = bit + count - (sb->s_blocksize << 3);
+                       count -= overflow;
+               }
+               bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
+               if (bitmap_nr < 0)
+                       goto error_return;
 
-       bh = bitmap->s_block_bitmap[bitmap_nr];
-       for (i = 0; i < count; i++) {
-               if (udf_set_bit(bit + i, bh->b_data)) {
-                       udf_debug("bit %ld already set\n", bit + i);
-                       udf_debug("byte=%2x\n", ((char *)bh->b_data)[(bit + i) >> 3]);
-               } else {
-                       if (inode)
-                               DQUOT_FREE_BLOCK(inode, 1);
-                       if (UDF_SB_LVIDBH(sb)) {
-                               UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] =
-                                       cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]) + 1);
+               bh = bitmap->s_block_bitmap[bitmap_nr];
+               for (i = 0; i < count; i++) {
+                       if (udf_set_bit(bit + i, bh->b_data)) {
+                               udf_debug("bit %ld already set\n", bit + i);
+                               udf_debug("byte=%2x\n",
+                                       ((char *)bh->b_data)[(bit + i) >> 3]);
+                       } else {
+                               if (inode)
+                                       DQUOT_FREE_BLOCK(inode, 1);
+                               udf_add_free_space(sbi, sbi->s_partition, 1);
                        }
                }
-       }
-       mark_buffer_dirty(bh);
-       if (overflow) {
-               block += count;
-               count = overflow;
-               goto do_more;
-       }
+               mark_buffer_dirty(bh);
+               if (overflow) {
+                       block += count;
+                       count = overflow;
+               }
+       } while (overflow);
+
 error_return:
        sb->s_dirt = 1;
-       if (UDF_SB_LVIDBH(sb))
-               mark_buffer_dirty(UDF_SB_LVIDBH(sb));
+       if (sbi->s_lvid_bh)
+               mark_buffer_dirty(sbi->s_lvid_bh);
        mutex_unlock(&sbi->s_alloc_mutex);
-       return;
 }
 
 static int udf_bitmap_prealloc_blocks(struct super_block *sb,
@@ -219,53 +236,50 @@ static int udf_bitmap_prealloc_blocks(struct super_block *sb,
        int bit, block, block_group, group_start;
        int nr_groups, bitmap_nr;
        struct buffer_head *bh;
+       __u32 part_len;
 
        mutex_lock(&sbi->s_alloc_mutex);
-       if (first_block < 0 || first_block >= UDF_SB_PARTLEN(sb, partition))
+       part_len = sbi->s_partmaps[partition].s_partition_len;
+       if (first_block < 0 || first_block >= part_len)
                goto out;
 
-       if (first_block + block_count > UDF_SB_PARTLEN(sb, partition))
-               block_count = UDF_SB_PARTLEN(sb, partition) - first_block;
+       if (first_block + block_count > part_len)
+               block_count = part_len - first_block;
 
-repeat:
-       nr_groups = (UDF_SB_PARTLEN(sb, partition) +
-                    (sizeof(struct spaceBitmapDesc) << 3) +
-                    (sb->s_blocksize * 8) - 1) / (sb->s_blocksize * 8);
-       block = first_block + (sizeof(struct spaceBitmapDesc) << 3);
-       block_group = block >> (sb->s_blocksize_bits + 3);
-       group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
+       do {
+               nr_groups = udf_compute_nr_groups(sb, partition);
+               block = first_block + (sizeof(struct spaceBitmapDesc) << 3);
+               block_group = block >> (sb->s_blocksize_bits + 3);
+               group_start = block_group ? 0 : sizeof(struct spaceBitmapDesc);
 
-       bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
-       if (bitmap_nr < 0)
-               goto out;
-       bh = bitmap->s_block_bitmap[bitmap_nr];
+               bitmap_nr = load_block_bitmap(sb, bitmap, block_group);
+               if (bitmap_nr < 0)
+                       goto out;
+               bh = bitmap->s_block_bitmap[bitmap_nr];
 
-       bit = block % (sb->s_blocksize << 3);
+               bit = block % (sb->s_blocksize << 3);
 
-       while (bit < (sb->s_blocksize << 3) && block_count > 0) {
-               if (!udf_test_bit(bit, bh->b_data)) {
-                       goto out;
-               } else if (DQUOT_PREALLOC_BLOCK(inode, 1)) {
-                       goto out;
-               } else if (!udf_clear_bit(bit, bh->b_data)) {
-                       udf_debug("bit already cleared for block %d\n", bit);
-                       DQUOT_FREE_BLOCK(inode, 1);
-                       goto out;
+               while (bit < (sb->s_blocksize << 3) && block_count > 0) {
+                       if (!udf_test_bit(bit, bh->b_data))
+                               goto out;
+                       else if (DQUOT_PREALLOC_BLOCK(inode, 1))
+                               goto out;
+                       else if (!udf_clear_bit(bit, bh->b_data)) {
+                               udf_debug("bit already cleared for block %d\n", bit);
+                               DQUOT_FREE_BLOCK(inode, 1);
+                               goto out;
+                       }
+                       block_count--;
+                       alloc_count++;
+                       bit++;
+                       block++;
                }
-               block_count--;
-               alloc_count++;
-               bit++;
-               block++;
-       }
-       mark_buffer_dirty(bh);
-       if (block_count > 0)
-               goto repeat;
+               mark_buffer_dirty(bh);
+       } while (block_count > 0);
+
 out:
-       if (UDF_SB_LVIDBH(sb)) {
-               UDF_SB_LVID(sb)->freeSpaceTable[partition] =
-                       cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - alloc_count);
-               mark_buffer_dirty(UDF_SB_LVIDBH(sb));
-       }
+       if (udf_add_free_space(sbi, partition, -alloc_count))
+               mark_buffer_dirty(sbi->s_lvid_bh);
        sb->s_dirt = 1;
        mutex_unlock(&sbi->s_alloc_mutex);
        return alloc_count;
@@ -287,7 +301,7 @@ static int udf_bitmap_new_block(struct super_block *sb,
        mutex_lock(&sbi->s_alloc_mutex);
 
 repeat:
-       if (goal < 0 || goal >= UDF_SB_PARTLEN(sb, partition))
+       if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len)
                goal = 0;
 
        nr_groups = bitmap->s_nr_groups;
@@ -312,14 +326,16 @@ repeat:
                if (bit < end_goal)
                        goto got_block;
 
-               ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF, sb->s_blocksize - ((bit + 7) >> 3));
+               ptr = memscan((char *)bh->b_data + (bit >> 3), 0xFF,
+                             sb->s_blocksize - ((bit + 7) >> 3));
                newbit = (ptr - ((char *)bh->b_data)) << 3;
                if (newbit < sb->s_blocksize << 3) {
                        bit = newbit;
                        goto search_back;
                }
 
-               newbit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, bit);
+               newbit = udf_find_next_one_bit(bh->b_data,
+                                              sb->s_blocksize << 3, bit);
                if (newbit < sb->s_blocksize << 3) {
                        bit = newbit;
                        goto got_block;
@@ -358,15 +374,20 @@ repeat:
        if (bit < sb->s_blocksize << 3)
                goto search_back;
        else
-               bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, group_start << 3);
+               bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3,
+                                           group_start << 3);
        if (bit >= sb->s_blocksize << 3) {
                mutex_unlock(&sbi->s_alloc_mutex);
                return 0;
        }
 
 search_back:
-       for (i = 0; i < 7 && bit > (group_start << 3) && udf_test_bit(bit - 1, bh->b_data); i++, bit--)
-               ; /* empty loop */
+       i = 0;
+       while (i < 7 && bit > (group_start << 3) &&
+              udf_test_bit(bit - 1, bh->b_data)) {
+               ++i;
+               --bit;
+       }
 
 got_block:
 
@@ -389,11 +410,8 @@ got_block:
 
        mark_buffer_dirty(bh);
 
-       if (UDF_SB_LVIDBH(sb)) {
-               UDF_SB_LVID(sb)->freeSpaceTable[partition] =
-                       cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - 1);
-               mark_buffer_dirty(UDF_SB_LVIDBH(sb));
-       }
+       if (udf_add_free_space(sbi, partition, -1))
+               mark_buffer_dirty(sbi->s_lvid_bh);
        sb->s_dirt = 1;
        mutex_unlock(&sbi->s_alloc_mutex);
        *err = 0;
@@ -418,56 +436,70 @@ static void udf_table_free_blocks(struct super_block *sb,
        struct extent_position oepos, epos;
        int8_t etype;
        int i;
+       struct udf_inode_info *iinfo;
 
        mutex_lock(&sbi->s_alloc_mutex);
        if (bloc.logicalBlockNum < 0 ||
-           (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) {
+           (bloc.logicalBlockNum + count) >
+               sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
                udf_debug("%d < %d || %d + %d > %d\n",
                          bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
-                         UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum));
+                         sbi->s_partmaps[bloc.partitionReferenceNum].
+                                                       s_partition_len);
                goto error_return;
        }
 
-       /* We do this up front - There are some error conditions that could occure,
-          but.. oh well */
+       iinfo = UDF_I(table);
+       /* We do this up front - There are some error conditions that
+          could occure, but.. oh well */
        if (inode)
                DQUOT_FREE_BLOCK(inode, count);
-       if (UDF_SB_LVIDBH(sb)) {
-               UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)] =
-                       cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]) + count);
-               mark_buffer_dirty(UDF_SB_LVIDBH(sb));
-       }
+       if (udf_add_free_space(sbi, sbi->s_partition, count))
+               mark_buffer_dirty(sbi->s_lvid_bh);
 
        start = bloc.logicalBlockNum + offset;
        end = bloc.logicalBlockNum + offset + count - 1;
 
        epos.offset = oepos.offset = sizeof(struct unallocSpaceEntry);
        elen = 0;
-       epos.block = oepos.block = UDF_I_LOCATION(table);
+       epos.block = oepos.block = iinfo->i_location;
        epos.bh = oepos.bh = NULL;
 
        while (count &&
               (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) {
-               if (((eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) == start)) {
-                       if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) {
-                               count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
-                               start += ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
-                               elen = (etype << 30) | (0x40000000 - sb->s_blocksize);
+               if (((eloc.logicalBlockNum +
+                       (elen >> sb->s_blocksize_bits)) == start)) {
+                       if ((0x3FFFFFFF - elen) <
+                                       (count << sb->s_blocksize_bits)) {
+                               uint32_t tmp = ((0x3FFFFFFF - elen) >>
+                                                       sb->s_blocksize_bits);
+                               count -= tmp;
+                               start += tmp;
+                               elen = (etype << 30) |
+                                       (0x40000000 - sb->s_blocksize);
                        } else {
-                               elen = (etype << 30) | (elen + (count << sb->s_blocksize_bits));
+                               elen = (etype << 30) |
+                                       (elen +
+                                       (count << sb->s_blocksize_bits));
                                start += count;
                                count = 0;
                        }
                        udf_write_aext(table, &oepos, eloc, elen, 1);
                } else if (eloc.logicalBlockNum == (end + 1)) {
-                       if ((0x3FFFFFFF - elen) < (count << sb->s_blocksize_bits)) {
-                               count -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
-                               end -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
-                               eloc.logicalBlockNum -= ((0x3FFFFFFF - elen) >> sb->s_blocksize_bits);
-                               elen = (etype << 30) | (0x40000000 - sb->s_blocksize);
+                       if ((0x3FFFFFFF - elen) <
+                                       (count << sb->s_blocksize_bits)) {
+                               uint32_t tmp = ((0x3FFFFFFF - elen) >>
+                                               sb->s_blocksize_bits);
+                               count -= tmp;
+                               end -= tmp;
+                               eloc.logicalBlockNum -= tmp;
+                               elen = (etype << 30) |
+                                       (0x40000000 - sb->s_blocksize);
                        } else {
                                eloc.logicalBlockNum = start;
-                               elen = (etype << 30) | (elen + (count << sb->s_blocksize_bits));
+                               elen = (etype << 30) |
+                                       (elen +
+                                       (count << sb->s_blocksize_bits));
                                end -= count;
                                count = 0;
                        }
@@ -488,9 +520,9 @@ static void udf_table_free_blocks(struct super_block *sb,
 
        if (count) {
                /*
-                * NOTE: we CANNOT use udf_add_aext here, as it can try to allocate
-                * a new block, and since we hold the super block lock already
-                * very bad things would happen :)
+                * NOTE: we CANNOT use udf_add_aext here, as it can try to
+                * allocate a new block, and since we hold the super block
+                * lock already very bad things would happen :)
                 *
                 * We copy the behavior of udf_add_aext, but instead of
                 * trying to allocate a new block close to the existing one,
@@ -509,11 +541,11 @@ static void udf_table_free_blocks(struct super_block *sb,
                elen = EXT_RECORDED_ALLOCATED |
                        (count << sb->s_blocksize_bits);
 
-               if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT) {
+               if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                        adsize = sizeof(short_ad);
-               } else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG) {
+               else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                        adsize = sizeof(long_ad);
-               else {
+               else {
                        brelse(oepos.bh);
                        brelse(epos.bh);
                        goto error_return;
@@ -531,56 +563,70 @@ static void udf_table_free_blocks(struct super_block *sb,
                        eloc.logicalBlockNum++;
                        elen -= sb->s_blocksize;
 
-                       if (!(epos.bh = udf_tread(sb, udf_get_lb_pblock(sb, epos.block, 0)))) {
+                       epos.bh = udf_tread(sb,
+                                       udf_get_lb_pblock(sb, epos.block, 0));
+                       if (!epos.bh) {
                                brelse(oepos.bh);
                                goto error_return;
                        }
                        aed = (struct allocExtDesc *)(epos.bh->b_data);
-                       aed->previousAllocExtLocation = cpu_to_le32(oepos.block.logicalBlockNum);
+                       aed->previousAllocExtLocation =
+                               cpu_to_le32(oepos.block.logicalBlockNum);
                        if (epos.offset + adsize > sb->s_blocksize) {
                                loffset = epos.offset;
                                aed->lengthAllocDescs = cpu_to_le32(adsize);
-                               sptr = UDF_I_DATA(table) + epos.offset - adsize;
-                               dptr = epos.bh->b_data + sizeof(struct allocExtDesc);
+                               sptr = iinfo->i_ext.i_data + epos.offset
+                                                               - adsize;
+                               dptr = epos.bh->b_data +
+                                       sizeof(struct allocExtDesc);
                                memcpy(dptr, sptr, adsize);
-                               epos.offset = sizeof(struct allocExtDesc) + adsize;
+                               epos.offset = sizeof(struct allocExtDesc) +
+                                               adsize;
                        } else {
                                loffset = epos.offset + adsize;
                                aed->lengthAllocDescs = cpu_to_le32(0);
                                if (oepos.bh) {
                                        sptr = oepos.bh->b_data + epos.offset;
-                                       aed = (struct allocExtDesc *)oepos.bh->b_data;
+                                       aed = (struct allocExtDesc *)
+                                               oepos.bh->b_data;
                                        aed->lengthAllocDescs =
-                                               cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
+                                               cpu_to_le32(le32_to_cpu(
+                                                       aed->lengthAllocDescs) +
+                                                               adsize);
                                } else {
-                                       sptr = UDF_I_DATA(table) + epos.offset;
-                                       UDF_I_LENALLOC(table) += adsize;
+                                       sptr = iinfo->i_ext.i_data +
+                                                               epos.offset;
+                                       iinfo->i_lenAlloc += adsize;
                                        mark_inode_dirty(table);
                                }
                                epos.offset = sizeof(struct allocExtDesc);
                        }
-                       if (UDF_SB_UDFREV(sb) >= 0x0200)
-                               udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 3, 1,
-                                           epos.block.logicalBlockNum, sizeof(tag));
+                       if (sbi->s_udfrev >= 0x0200)
+                               udf_new_tag(epos.bh->b_data, TAG_IDENT_AED,
+                                           3, 1, epos.block.logicalBlockNum,
+                                           sizeof(tag));
                        else
-                               udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 2, 1,
-                                           epos.block.logicalBlockNum, sizeof(tag));
-
-                       switch (UDF_I_ALLOCTYPE(table)) {
-                               case ICBTAG_FLAG_AD_SHORT:
-                                       sad = (short_ad *)sptr;
-                                       sad->extLength = cpu_to_le32(
-                                               EXT_NEXT_EXTENT_ALLOCDECS |
-                                               sb->s_blocksize);
-                                       sad->extPosition = cpu_to_le32(epos.block.logicalBlockNum);
-                                       break;
-                               case ICBTAG_FLAG_AD_LONG:
-                                       lad = (long_ad *)sptr;
-                                       lad->extLength = cpu_to_le32(
-                                               EXT_NEXT_EXTENT_ALLOCDECS |
-                                               sb->s_blocksize);
-                                       lad->extLocation = cpu_to_lelb(epos.block);
-                                       break;
+                               udf_new_tag(epos.bh->b_data, TAG_IDENT_AED,
+                                           2, 1, epos.block.logicalBlockNum,
+                                           sizeof(tag));
+
+                       switch (iinfo->i_alloc_type) {
+                       case ICBTAG_FLAG_AD_SHORT:
+                               sad = (short_ad *)sptr;
+                               sad->extLength = cpu_to_le32(
+                                       EXT_NEXT_EXTENT_ALLOCDECS |
+                                       sb->s_blocksize);
+                               sad->extPosition =
+                                       cpu_to_le32(epos.block.logicalBlockNum);
+                               break;
+                       case ICBTAG_FLAG_AD_LONG:
+                               lad = (long_ad *)sptr;
+                               lad->extLength = cpu_to_le32(
+                                       EXT_NEXT_EXTENT_ALLOCDECS |
+                                       sb->s_blocksize);
+                               lad->extLocation =
+                                       cpu_to_lelb(epos.block);
+                               break;
                        }
                        if (oepos.bh) {
                                udf_update_tag(oepos.bh->b_data, loffset);
@@ -590,16 +636,18 @@ static void udf_table_free_blocks(struct super_block *sb,
                        }
                }
 
-               if (elen) { /* It's possible that stealing the block emptied the extent */
+               /* It's possible that stealing the block emptied the extent */
+               if (elen) {
                        udf_write_aext(table, &epos, eloc, elen, 1);
 
                        if (!epos.bh) {
-                               UDF_I_LENALLOC(table) += adsize;
+                               iinfo->i_lenAlloc += adsize;
                                mark_inode_dirty(table);
                        } else {
                                aed = (struct allocExtDesc *)epos.bh->b_data;
                                aed->lengthAllocDescs =
-                                       cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
+                                       cpu_to_le32(le32_to_cpu(
+                                           aed->lengthAllocDescs) + adsize);
                                udf_update_tag(epos.bh->b_data, epos.offset);
                                mark_buffer_dirty(epos.bh);
                        }
@@ -626,20 +674,23 @@ static int udf_table_prealloc_blocks(struct super_block *sb,
        kernel_lb_addr eloc;
        struct extent_position epos;
        int8_t etype = -1;
+       struct udf_inode_info *iinfo;
 
-       if (first_block < 0 || first_block >= UDF_SB_PARTLEN(sb, partition))
+       if (first_block < 0 ||
+               first_block >= sbi->s_partmaps[partition].s_partition_len)
                return 0;
 
-       if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT)
+       iinfo = UDF_I(table);
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                adsize = sizeof(short_ad);
-       else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG)
+       else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                adsize = sizeof(long_ad);
        else
                return 0;
 
        mutex_lock(&sbi->s_alloc_mutex);
        epos.offset = sizeof(struct unallocSpaceEntry);
-       epos.block = UDF_I_LOCATION(table);
+       epos.block = iinfo->i_location;
        epos.bh = NULL;
        eloc.logicalBlockNum = 0xFFFFFFFF;
 
@@ -654,26 +705,26 @@ static int udf_table_prealloc_blocks(struct super_block *sb,
                epos.offset -= adsize;
 
                alloc_count = (elen >> sb->s_blocksize_bits);
-               if (inode && DQUOT_PREALLOC_BLOCK(inode, alloc_count > block_count ? block_count : alloc_count)) {
+               if (inode && DQUOT_PREALLOC_BLOCK(inode,
+                       alloc_count > block_count ? block_count : alloc_count))
                        alloc_count = 0;
-               else if (alloc_count > block_count) {
+               else if (alloc_count > block_count) {
                        alloc_count = block_count;
                        eloc.logicalBlockNum += alloc_count;
                        elen -= (alloc_count << sb->s_blocksize_bits);
-                       udf_write_aext(table, &epos, eloc, (etype << 30) | elen, 1);
-               } else {
-                       udf_delete_aext(table, epos, eloc, (etype << 30) | elen);
-               }
+                       udf_write_aext(table, &epos, eloc,
+                                       (etype << 30) | elen, 1);
+               } else
+                       udf_delete_aext(table, epos, eloc,
+                                       (etype << 30) | elen);
        } else {
                alloc_count = 0;
        }
 
        brelse(epos.bh);
 
-       if (alloc_count && UDF_SB_LVIDBH(sb)) {
-               UDF_SB_LVID(sb)->freeSpaceTable[partition] =
-                       cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - alloc_count);
-               mark_buffer_dirty(UDF_SB_LVIDBH(sb));
+       if (alloc_count && udf_add_free_space(sbi, partition, -alloc_count)) {
+               mark_buffer_dirty(sbi->s_lvid_bh);
                sb->s_dirt = 1;
        }
        mutex_unlock(&sbi->s_alloc_mutex);
@@ -692,33 +743,35 @@ static int udf_table_new_block(struct super_block *sb,
        kernel_lb_addr eloc, uninitialized_var(goal_eloc);
        struct extent_position epos, goal_epos;
        int8_t etype;
+       struct udf_inode_info *iinfo = UDF_I(table);
 
        *err = -ENOSPC;
 
-       if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_SHORT)
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                adsize = sizeof(short_ad);
-       else if (UDF_I_ALLOCTYPE(table) == ICBTAG_FLAG_AD_LONG)
+       else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                adsize = sizeof(long_ad);
        else
                return newblock;
 
        mutex_lock(&sbi->s_alloc_mutex);
-       if (goal < 0 || goal >= UDF_SB_PARTLEN(sb, partition))
+       if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len)
                goal = 0;
 
-       /* We search for the closest matching block to goal. If we find a exact hit,
-          we stop. Otherwise we keep going till we run out of extents.
-          We store the buffer_head, bloc, and extoffset of the current closest
-          match and use that when we are done.
+       /* We search for the closest matching block to goal. If we find
+          a exact hit, we stop. Otherwise we keep going till we run out
+          of extents. We store the buffer_head, bloc, and extoffset
+          of the current closest match and use that when we are done.
         */
        epos.offset = sizeof(struct unallocSpaceEntry);
-       epos.block = UDF_I_LOCATION(table);
+       epos.block = iinfo->i_location;
        epos.bh = goal_epos.bh = NULL;
 
        while (spread &&
               (etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) {
                if (goal >= eloc.logicalBlockNum) {
-                       if (goal < eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits))
+                       if (goal < eloc.logicalBlockNum +
+                                       (elen >> sb->s_blocksize_bits))
                                nspread = 0;
                        else
                                nspread = goal - eloc.logicalBlockNum -
@@ -771,11 +824,8 @@ static int udf_table_new_block(struct super_block *sb,
                udf_delete_aext(table, goal_epos, goal_eloc, goal_elen);
        brelse(goal_epos.bh);
 
-       if (UDF_SB_LVIDBH(sb)) {
-               UDF_SB_LVID(sb)->freeSpaceTable[partition] =
-                       cpu_to_le32(le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[partition]) - 1);
-               mark_buffer_dirty(UDF_SB_LVIDBH(sb));
-       }
+       if (udf_add_free_space(sbi, partition, -1))
+               mark_buffer_dirty(sbi->s_lvid_bh);
 
        sb->s_dirt = 1;
        mutex_unlock(&sbi->s_alloc_mutex);
@@ -789,22 +839,23 @@ inline void udf_free_blocks(struct super_block *sb,
                            uint32_t count)
 {
        uint16_t partition = bloc.partitionReferenceNum;
+       struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
 
-       if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) {
+       if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) {
                return udf_bitmap_free_blocks(sb, inode,
-                                             UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap,
+                                             map->s_uspace.s_bitmap,
                                              bloc, offset, count);
-       } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) {
+       } else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) {
                return udf_table_free_blocks(sb, inode,
-                                            UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table,
+                                            map->s_uspace.s_table,
                                             bloc, offset, count);
-       } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) {
+       } else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) {
                return udf_bitmap_free_blocks(sb, inode,
-                                             UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap,
+                                             map->s_fspace.s_bitmap,
                                              bloc, offset, count);
-       } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) {
+       } else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) {
                return udf_table_free_blocks(sb, inode,
-                                            UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table,
+                                            map->s_fspace.s_table,
                                             bloc, offset, count);
        } else {
                return;
@@ -816,51 +867,55 @@ inline int udf_prealloc_blocks(struct super_block *sb,
                               uint16_t partition, uint32_t first_block,
                               uint32_t block_count)
 {
-       if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) {
+       struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
+
+       if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
                return udf_bitmap_prealloc_blocks(sb, inode,
-                                                 UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap,
-                                                 partition, first_block, block_count);
-       } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) {
+                                                 map->s_uspace.s_bitmap,
+                                                 partition, first_block,
+                                                 block_count);
+       else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
                return udf_table_prealloc_blocks(sb, inode,
-                                                UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table,
-                                                partition, first_block, block_count);
-       } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) {
+                                                map->s_uspace.s_table,
+                                                partition, first_block,
+                                                block_count);
+       else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
                return udf_bitmap_prealloc_blocks(sb, inode,
-                                                 UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap,
-                                                 partition, first_block, block_count);
-       } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) {
+                                                 map->s_fspace.s_bitmap,
+                                                 partition, first_block,
+                                                 block_count);
+       else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
                return udf_table_prealloc_blocks(sb, inode,
-                                                UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table,
-                                                partition, first_block, block_count);
-       } else {
+                                                map->s_fspace.s_table,
+                                                partition, first_block,
+                                                block_count);
+       else
                return 0;
-       }
 }
 
 inline int udf_new_block(struct super_block *sb,
                         struct inode *inode,
                         uint16_t partition, uint32_t goal, int *err)
 {
-       int ret;
+       struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
 
-       if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) {
-               ret = udf_bitmap_new_block(sb, inode,
-                                          UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap,
+       if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
+               return udf_bitmap_new_block(sb, inode,
+                                          map->s_uspace.s_bitmap,
                                           partition, goal, err);
-               return ret;
-       } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) {
+       else if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
                return udf_table_new_block(sb, inode,
-                                          UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_table,
+                                          map->s_uspace.s_table,
                                           partition, goal, err);
-       } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_BITMAP) {
+       else if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
                return udf_bitmap_new_block(sb, inode,
-                                           UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_bitmap,
+                                           map->s_fspace.s_bitmap,
                                            partition, goal, err);
-       } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_FREED_TABLE) {
+       else if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
                return udf_table_new_block(sb, inode,
-                                          UDF_SB_PARTMAPS(sb)[partition].s_fspace.s_table,
+                                          map->s_fspace.s_table,
                                           partition, goal, err);
-       else {
+       else {
                *err = -EIO;
                return 0;
        }
index 85aaee5fab261ec42621e594e7710e80abc7b789..b1661296e786291c35b5c1f47e96da0c2a73ee13 100644 (file)
@@ -79,7 +79,7 @@ static uint16_t crc_table[256] = {
  *     July 21, 1997 - Andrew E. Mileski
  *     Adapted from OSTA-UDF(tm) 1.50 standard.
  */
-uint16_t udf_crc(uint8_t * data, uint32_t size, uint16_t crc)
+uint16_t udf_crc(uint8_t *data, uint32_t size, uint16_t crc)
 {
        while (size--)
                crc = crc_table[(crc >> 8 ^ *(data++)) & 0xffU] ^ (crc << 8);
index 9e3b9f97ddbc31bdc7715b51da85fb70ccb3b459..4b44e23caa1225a769f89b21dd4ad999034cf974 100644 (file)
 #include "udf_i.h"
 #include "udf_sb.h"
 
-/* Prototypes for file operations */
-static int udf_readdir(struct file *, void *, filldir_t);
-static int do_udf_readdir(struct inode *, struct file *, filldir_t, void *);
-
-/* readdir and lookup functions */
-
-const struct file_operations udf_dir_operations = {
-       .read                   = generic_read_dir,
-       .readdir                = udf_readdir,
-       .ioctl                  = udf_ioctl,
-       .fsync                  = udf_fsync_file,
-};
-
-/*
- * udf_readdir
- *
- * PURPOSE
- *     Read a directory entry.
- *
- * DESCRIPTION
- *     Optional - sys_getdents() will return -ENOTDIR if this routine is not
- *     available.
- *
- *     Refer to sys_getdents() in fs/readdir.c
- *     sys_getdents() -> .
- *
- * PRE-CONDITIONS
- *     filp                    Pointer to directory file.
- *     buf                     Pointer to directory entry buffer.
- *     filldir                 Pointer to filldir function.
- *
- * POST-CONDITIONS
- *     <return>                >=0 on success.
- *
- * HISTORY
- *     July 1, 1997 - Andrew E. Mileski
- *     Written, tested, and released.
- */
-
-int udf_readdir(struct file *filp, void *dirent, filldir_t filldir)
-{
-       struct inode *dir = filp->f_path.dentry->d_inode;
-       int result;
-
-       lock_kernel();
-
-       if (filp->f_pos == 0) {
-               if (filldir(dirent, ".", 1, filp->f_pos, dir->i_ino, DT_DIR) < 0) {
-                       unlock_kernel();
-                       return 0;
-               }
-               filp->f_pos++;
-       }
-
-       result = do_udf_readdir(dir, filp, filldir, dirent);
-       unlock_kernel();
-       return result;
-}
-
-static int
-do_udf_readdir(struct inode *dir, struct file *filp, filldir_t filldir,
-              void *dirent)
+static int do_udf_readdir(struct inode *dir, struct file *filp,
+                         filldir_t filldir, void *dirent)
 {
        struct udf_fileident_bh fibh;
        struct fileIdentDesc *fi = NULL;
@@ -117,6 +57,7 @@ do_udf_readdir(struct inode *dir, struct file *filp, filldir_t filldir,
        int i, num;
        unsigned int dt_type;
        struct extent_position epos = { NULL, 0, {0, 0} };
+       struct udf_inode_info *iinfo;
 
        if (nf_pos >= size)
                return 0;
@@ -125,15 +66,17 @@ do_udf_readdir(struct inode *dir, struct file *filp, filldir_t filldir,
                nf_pos = (udf_ext0_offset(dir) >> 2);
 
        fibh.soffset = fibh.eoffset = (nf_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
-       if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
+       iinfo = UDF_I(dir);
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
                fibh.sbh = fibh.ebh = NULL;
        } else if (inode_bmap(dir, nf_pos >> (dir->i_sb->s_blocksize_bits - 2),
                              &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) {
                block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
                if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
-                       if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
+                       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                                epos.offset -= sizeof(short_ad);
-                       else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
+                       else if (iinfo->i_alloc_type ==
+                                       ICBTAG_FLAG_AD_LONG)
                                epos.offset -= sizeof(long_ad);
                } else {
                        offset = 0;
@@ -244,3 +187,57 @@ do_udf_readdir(struct inode *dir, struct file *filp, filldir_t filldir,
 
        return 0;
 }
+
+/*
+ * udf_readdir
+ *
+ * PURPOSE
+ *     Read a directory entry.
+ *
+ * DESCRIPTION
+ *     Optional - sys_getdents() will return -ENOTDIR if this routine is not
+ *     available.
+ *
+ *     Refer to sys_getdents() in fs/readdir.c
+ *     sys_getdents() -> .
+ *
+ * PRE-CONDITIONS
+ *     filp                    Pointer to directory file.
+ *     buf                     Pointer to directory entry buffer.
+ *     filldir                 Pointer to filldir function.
+ *
+ * POST-CONDITIONS
+ *     <return>                >=0 on success.
+ *
+ * HISTORY
+ *     July 1, 1997 - Andrew E. Mileski
+ *     Written, tested, and released.
+ */
+
+static int udf_readdir(struct file *filp, void *dirent, filldir_t filldir)
+{
+       struct inode *dir = filp->f_path.dentry->d_inode;
+       int result;
+
+       lock_kernel();
+
+       if (filp->f_pos == 0) {
+               if (filldir(dirent, ".", 1, filp->f_pos, dir->i_ino, DT_DIR) < 0) {
+                       unlock_kernel();
+                       return 0;
+               }
+               filp->f_pos++;
+       }
+
+       result = do_udf_readdir(dir, filp, filldir, dirent);
+       unlock_kernel();
+       return result;
+}
+
+/* readdir and lookup functions */
+const struct file_operations udf_dir_operations = {
+       .read                   = generic_read_dir,
+       .readdir                = udf_readdir,
+       .ioctl                  = udf_ioctl,
+       .fsync                  = udf_fsync_file,
+};
index ff8c08fd7bf533ff53d6e659f284edb9c23e5a1d..2820f8fcf4cc2e932b72f70cf25a7c69586546d9 100644 (file)
@@ -19,7 +19,7 @@
 #include <linux/buffer_head.h>
 
 #if 0
-static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
+static uint8_t *udf_filead_read(struct inode *dir, uint8_t *tmpad,
                                uint8_t ad_size, kernel_lb_addr fe_loc,
                                int *pos, int *offset, struct buffer_head **bh,
                                int *error)
@@ -45,7 +45,8 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
                block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
                if (!block)
                        return NULL;
-               if (!(*bh = udf_tread(dir->i_sb, block)))
+               *bh = udf_tread(dir->i_sb, block);
+               if (!*bh)
                        return NULL;
        } else if (*offset > dir->i_sb->s_blocksize) {
                ad = tmpad;
@@ -57,10 +58,12 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
                block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
                if (!block)
                        return NULL;
-               if (!((*bh) = udf_tread(dir->i_sb, block)))
+               (*bh) = udf_tread(dir->i_sb, block);
+               if (!*bh)
                        return NULL;
 
-               memcpy((uint8_t *)ad + remainder, (*bh)->b_data, ad_size - remainder);
+               memcpy((uint8_t *)ad + remainder, (*bh)->b_data,
+                       ad_size - remainder);
                *offset = ad_size - remainder;
        }
 
@@ -68,29 +71,31 @@ static uint8_t *udf_filead_read(struct inode *dir, uint8_t * tmpad,
 }
 #endif
 
-struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
+struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t *nf_pos,
                                         struct udf_fileident_bh *fibh,
                                         struct fileIdentDesc *cfi,
                                         struct extent_position *epos,
-                                        kernel_lb_addr * eloc, uint32_t * elen,
-                                        sector_t * offset)
+                                        kernel_lb_addr *eloc, uint32_t *elen,
+                                        sector_t *offset)
 {
        struct fileIdentDesc *fi;
        int i, num, block;
        struct buffer_head *tmp, *bha[16];
+       struct udf_inode_info *iinfo = UDF_I(dir);
 
        fibh->soffset = fibh->eoffset;
 
-       if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
-               fi = udf_get_fileident(UDF_I_DATA(dir) -
-                                      (UDF_I_EFE(dir) ?
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
+               fi = udf_get_fileident(iinfo->i_ext.i_data -
+                                      (iinfo->i_efe ?
                                        sizeof(struct extendedFileEntry) :
                                        sizeof(struct fileEntry)),
-                                      dir->i_sb->s_blocksize, &(fibh->eoffset));
+                                      dir->i_sb->s_blocksize,
+                                      &(fibh->eoffset));
                if (!fi)
                        return NULL;
 
-               *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2);
+               *nf_pos += fibh->eoffset - fibh->soffset;
 
                memcpy((uint8_t *)cfi, (uint8_t *)fi,
                       sizeof(struct fileIdentDesc));
@@ -100,6 +105,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
 
        if (fibh->eoffset == dir->i_sb->s_blocksize) {
                int lextoffset = epos->offset;
+               unsigned char blocksize_bits = dir->i_sb->s_blocksize_bits;
 
                if (udf_next_aext(dir, epos, eloc, elen, 1) !=
                    (EXT_RECORDED_ALLOCATED >> 30))
@@ -109,24 +115,27 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
 
                (*offset)++;
 
-               if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
+               if ((*offset << blocksize_bits) >= *elen)
                        *offset = 0;
                else
                        epos->offset = lextoffset;
 
                brelse(fibh->sbh);
-               if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block)))
+               fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
+               if (!fibh->sbh)
                        return NULL;
                fibh->soffset = fibh->eoffset = 0;
 
-               if (!(*offset & ((16 >> (dir->i_sb->s_blocksize_bits - 9)) - 1))) {
-                       i = 16 >> (dir->i_sb->s_blocksize_bits - 9);
-                       if (i + *offset > (*elen >> dir->i_sb->s_blocksize_bits))
-                               i = (*elen >> dir->i_sb->s_blocksize_bits)-*offset;
+               if (!(*offset & ((16 >> (blocksize_bits - 9)) - 1))) {
+                       i = 16 >> (blocksize_bits - 9);
+                       if (i + *offset > (*elen >> blocksize_bits))
+                               i = (*elen >> blocksize_bits)-*offset;
                        for (num = 0; i > 0; i--) {
-                               block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset + i);
+                               block = udf_get_lb_pblock(dir->i_sb, *eloc,
+                                                         *offset + i);
                                tmp = udf_tgetblk(dir->i_sb, block);
-                               if (tmp && !buffer_uptodate(tmp) && !buffer_locked(tmp))
+                               if (tmp && !buffer_uptodate(tmp) &&
+                                               !buffer_locked(tmp))
                                        bha[num++] = tmp;
                                else
                                        brelse(tmp);
@@ -148,7 +157,7 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
        if (!fi)
                return NULL;
 
-       *nf_pos += ((fibh->eoffset - fibh->soffset) >> 2);
+       *nf_pos += fibh->eoffset - fibh->soffset;
 
        if (fibh->eoffset <= dir->i_sb->s_blocksize) {
                memcpy((uint8_t *)cfi, (uint8_t *)fi,
@@ -172,20 +181,23 @@ struct fileIdentDesc *udf_fileident_read(struct inode *dir, loff_t * nf_pos,
                fibh->soffset -= dir->i_sb->s_blocksize;
                fibh->eoffset -= dir->i_sb->s_blocksize;
 
-               if (!(fibh->ebh = udf_tread(dir->i_sb, block)))
+               fibh->ebh = udf_tread(dir->i_sb, block);
+               if (!fibh->ebh)
                        return NULL;
 
                if (sizeof(struct fileIdentDesc) > -fibh->soffset) {
                        int fi_len;
 
                        memcpy((uint8_t *)cfi, (uint8_t *)fi, -fibh->soffset);
-                       memcpy((uint8_t *)cfi - fibh->soffset, fibh->ebh->b_data,
+                       memcpy((uint8_t *)cfi - fibh->soffset,
+                              fibh->ebh->b_data,
                               sizeof(struct fileIdentDesc) + fibh->soffset);
 
-                       fi_len = (sizeof(struct fileIdentDesc) + cfi->lengthFileIdent +
+                       fi_len = (sizeof(struct fileIdentDesc) +
+                                 cfi->lengthFileIdent +
                                  le16_to_cpu(cfi->lengthOfImpUse) + 3) & ~3;
 
-                       *nf_pos += ((fi_len - (fibh->eoffset - fibh->soffset)) >> 2);
+                       *nf_pos += fi_len - (fibh->eoffset - fibh->soffset);
                        fibh->eoffset = fibh->soffset + fi_len;
                } else {
                        memcpy((uint8_t *)cfi, (uint8_t *)fi,
@@ -210,11 +222,10 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset)
 
        ptr = buffer;
 
-       if ((*offset > 0) && (*offset < bufsize)) {
+       if ((*offset > 0) && (*offset < bufsize))
                ptr += *offset;
-       }
        fi = (struct fileIdentDesc *)ptr;
-       if (le16_to_cpu(fi->descTag.tagIdent) != TAG_IDENT_FID) {
+       if (fi->descTag.tagIdent != cpu_to_le16(TAG_IDENT_FID)) {
                udf_debug("0x%x != TAG_IDENT_FID\n",
                          le16_to_cpu(fi->descTag.tagIdent));
                udf_debug("offset: %u sizeof: %lu bufsize: %u\n",
@@ -222,12 +233,11 @@ struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize, int *offset)
                          bufsize);
                return NULL;
        }
-       if ((*offset + sizeof(struct fileIdentDesc)) > bufsize) {
+       if ((*offset + sizeof(struct fileIdentDesc)) > bufsize)
                lengthThisIdent = sizeof(struct fileIdentDesc);
-       } else {
+       else
                lengthThisIdent = sizeof(struct fileIdentDesc) +
                        fi->lengthFileIdent + le16_to_cpu(fi->lengthOfImpUse);
-       }
 
        /* we need to figure padding, too! */
        padlen = lengthThisIdent % UDF_NAME_PAD;
@@ -252,17 +262,17 @@ static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset)
 
        fe = (struct fileEntry *)buffer;
 
-       if (le16_to_cpu(fe->descTag.tagIdent) != TAG_IDENT_FE) {
+       if (fe->descTag.tagIdent != cpu_to_le16(TAG_IDENT_FE)) {
                udf_debug("0x%x != TAG_IDENT_FE\n",
                          le16_to_cpu(fe->descTag.tagIdent));
                return NULL;
        }
 
-       ptr = (uint8_t *)(fe->extendedAttr) + le32_to_cpu(fe->lengthExtendedAttr);
+       ptr = (uint8_t *)(fe->extendedAttr) +
+               le32_to_cpu(fe->lengthExtendedAttr);
 
-       if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs))) {
+       if ((*offset > 0) && (*offset < le32_to_cpu(fe->lengthAllocDescs)))
                ptr += *offset;
-       }
 
        ext = (extent_ad *)ptr;
 
@@ -271,7 +281,7 @@ static extent_ad *udf_get_fileextent(void *buffer, int bufsize, int *offset)
 }
 #endif
 
-short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset,
+short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, uint32_t *offset,
                              int inc)
 {
        short_ad *sa;
@@ -281,17 +291,20 @@ short_ad *udf_get_fileshortad(uint8_t *ptr, int maxoffset, int *offset,
                return NULL;
        }
 
-       if ((*offset < 0) || ((*offset + sizeof(short_ad)) > maxoffset))
-               return NULL;
-       else if ((sa = (short_ad *)ptr)->extLength == 0)
+       if ((*offset + sizeof(short_ad)) > maxoffset)
                return NULL;
+       else {
+               sa = (short_ad *)ptr;
+               if (sa->extLength == 0)
+                       return NULL;
+       }
 
        if (inc)
                *offset += sizeof(short_ad);
        return sa;
 }
 
-long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, int *offset, int inc)
+long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, uint32_t *offset, int inc)
 {
        long_ad *la;
 
@@ -300,10 +313,13 @@ long_ad *udf_get_filelongad(uint8_t *ptr, int maxoffset, int *offset, int inc)
                return NULL;
        }
 
-       if ((*offset < 0) || ((*offset + sizeof(long_ad)) > maxoffset))
-               return NULL;
-       else if ((la = (long_ad *)ptr)->extLength == 0)
+       if ((*offset + sizeof(long_ad)) > maxoffset)
                return NULL;
+       else {
+               la = (long_ad *)ptr;
+               if (la->extLength == 0)
+                       return NULL;
+       }
 
        if (inc)
                *offset += sizeof(long_ad);
index 7c7a1b39d56c9071cd28370f92b1945e659aa702..97c71ae7c68922f3cbe2f2ea48f0fb8a623fbc1d 100644 (file)
@@ -45,12 +45,13 @@ static int udf_adinicb_readpage(struct file *file, struct page *page)
 {
        struct inode *inode = page->mapping->host;
        char *kaddr;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
        BUG_ON(!PageLocked(page));
 
        kaddr = kmap(page);
        memset(kaddr, 0, PAGE_CACHE_SIZE);
-       memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), inode->i_size);
+       memcpy(kaddr, iinfo->i_ext.i_data + iinfo->i_lenEAttr, inode->i_size);
        flush_dcache_page(page);
        SetPageUptodate(page);
        kunmap(page);
@@ -59,15 +60,17 @@ static int udf_adinicb_readpage(struct file *file, struct page *page)
        return 0;
 }
 
-static int udf_adinicb_writepage(struct page *page, struct writeback_control *wbc)
+static int udf_adinicb_writepage(struct page *page,
+                                struct writeback_control *wbc)
 {
        struct inode *inode = page->mapping->host;
        char *kaddr;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
        BUG_ON(!PageLocked(page));
 
        kaddr = kmap(page);
-       memcpy(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), kaddr, inode->i_size);
+       memcpy(iinfo->i_ext.i_data + iinfo->i_lenEAttr, kaddr, inode->i_size);
        mark_inode_dirty(inode);
        SetPageUptodate(page);
        kunmap(page);
@@ -84,9 +87,10 @@ static int udf_adinicb_write_end(struct file *file,
        struct inode *inode = mapping->host;
        unsigned offset = pos & (PAGE_CACHE_SIZE - 1);
        char *kaddr;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
        kaddr = kmap_atomic(page, KM_USER0);
-       memcpy(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset,
+       memcpy(iinfo->i_ext.i_data + iinfo->i_lenEAttr + offset,
                kaddr + offset, copied);
        kunmap_atomic(kaddr, KM_USER0);
 
@@ -109,25 +113,27 @@ static ssize_t udf_file_aio_write(struct kiocb *iocb, const struct iovec *iov,
        struct inode *inode = file->f_path.dentry->d_inode;
        int err, pos;
        size_t count = iocb->ki_left;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
                if (file->f_flags & O_APPEND)
                        pos = inode->i_size;
                else
                        pos = ppos;
 
-               if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) +
+               if (inode->i_sb->s_blocksize <
+                               (udf_file_entry_alloc_offset(inode) +
                                                pos + count)) {
                        udf_expand_file_adinicb(inode, pos + count, &err);
-                       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
+                       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
                                udf_debug("udf_expand_adinicb: err=%d\n", err);
                                return err;
                        }
                } else {
                        if (pos + count > inode->i_size)
-                               UDF_I_LENALLOC(inode) = pos + count;
+                               iinfo->i_lenAlloc = pos + count;
                        else
-                               UDF_I_LENALLOC(inode) = inode->i_size;
+                               iinfo->i_lenAlloc = inode->i_size;
                }
        }
 
@@ -191,23 +197,28 @@ int udf_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
 
        switch (cmd) {
        case UDF_GETVOLIDENT:
-               return copy_to_user((char __user *)arg,
-                                   UDF_SB_VOLIDENT(inode->i_sb), 32) ? -EFAULT : 0;
+               if (copy_to_user((char __user *)arg,
+                                UDF_SB(inode->i_sb)->s_volume_ident, 32))
+                       return -EFAULT;
+               else
+                       return 0;
        case UDF_RELOCATE_BLOCKS:
                if (!capable(CAP_SYS_ADMIN))
                        return -EACCES;
                if (get_user(old_block, (long __user *)arg))
                        return -EFAULT;
-               if ((result = udf_relocate_blocks(inode->i_sb,
-                                                 old_block, &new_block)) == 0)
+               result = udf_relocate_blocks(inode->i_sb,
+                                               old_block, &new_block);
+               if (result == 0)
                        result = put_user(new_block, (long __user *)arg);
                return result;
        case UDF_GETEASIZE:
-               result = put_user(UDF_I_LENEATTR(inode), (int __user *)arg);
+               result = put_user(UDF_I(inode)->i_lenEAttr, (int __user *)arg);
                break;
        case UDF_GETEABLOCK:
-               result = copy_to_user((char __user *)arg, UDF_I_DATA(inode),
-                                     UDF_I_LENEATTR(inode)) ? -EFAULT : 0;
+               result = copy_to_user((char __user *)arg,
+                                     UDF_I(inode)->i_ext.i_data,
+                                     UDF_I(inode)->i_lenEAttr) ? -EFAULT : 0;
                break;
        }
 
index 636d8f613929a01dd854ae8773e87abdb325ba1b..84360315aca2083001727f1defc0d453b4c07779 100644 (file)
@@ -43,19 +43,21 @@ void udf_free_inode(struct inode *inode)
        clear_inode(inode);
 
        mutex_lock(&sbi->s_alloc_mutex);
-       if (sbi->s_lvidbh) {
+       if (sbi->s_lvid_bh) {
+               struct logicalVolIntegrityDescImpUse *lvidiu =
+                                                       udf_sb_lvidiu(sbi);
                if (S_ISDIR(inode->i_mode))
-                       UDF_SB_LVIDIU(sb)->numDirs =
-                               cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs) - 1);
+                       lvidiu->numDirs =
+                               cpu_to_le32(le32_to_cpu(lvidiu->numDirs) - 1);
                else
-                       UDF_SB_LVIDIU(sb)->numFiles =
-                               cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) - 1);
+                       lvidiu->numFiles =
+                               cpu_to_le32(le32_to_cpu(lvidiu->numFiles) - 1);
 
-               mark_buffer_dirty(sbi->s_lvidbh);
+               mark_buffer_dirty(sbi->s_lvid_bh);
        }
        mutex_unlock(&sbi->s_alloc_mutex);
 
-       udf_free_blocks(sb, NULL, UDF_I_LOCATION(inode), 0, 1);
+       udf_free_blocks(sb, NULL, UDF_I(inode)->i_location, 0, 1);
 }
 
 struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
@@ -64,7 +66,9 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
        struct udf_sb_info *sbi = UDF_SB(sb);
        struct inode *inode;
        int block;
-       uint32_t start = UDF_I_LOCATION(dir).logicalBlockNum;
+       uint32_t start = UDF_I(dir)->i_location.logicalBlockNum;
+       struct udf_inode_info *iinfo;
+       struct udf_inode_info *dinfo = UDF_I(dir);
 
        inode = new_inode(sb);
 
@@ -74,13 +78,15 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
        }
        *err = -ENOSPC;
 
-       UDF_I_UNIQUE(inode) = 0;
-       UDF_I_LENEXTENTS(inode) = 0;
-       UDF_I_NEXT_ALLOC_BLOCK(inode) = 0;
-       UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
-       UDF_I_STRAT4096(inode) = 0;
+       iinfo = UDF_I(inode);
+       iinfo->i_unique = 0;
+       iinfo->i_lenExtents = 0;
+       iinfo->i_next_alloc_block = 0;
+       iinfo->i_next_alloc_goal = 0;
+       iinfo->i_strat4096 = 0;
 
-       block = udf_new_block(dir->i_sb, NULL, UDF_I_LOCATION(dir).partitionReferenceNum,
+       block = udf_new_block(dir->i_sb, NULL,
+                             dinfo->i_location.partitionReferenceNum,
                              start, err);
        if (*err) {
                iput(inode);
@@ -88,21 +94,27 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
        }
 
        mutex_lock(&sbi->s_alloc_mutex);
-       if (UDF_SB_LVIDBH(sb)) {
+       if (sbi->s_lvid_bh) {
+               struct logicalVolIntegrityDesc *lvid =
+                       (struct logicalVolIntegrityDesc *)
+                       sbi->s_lvid_bh->b_data;
+               struct logicalVolIntegrityDescImpUse *lvidiu =
+                                                       udf_sb_lvidiu(sbi);
                struct logicalVolHeaderDesc *lvhd;
                uint64_t uniqueID;
-               lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(sb)->logicalVolContentsUse);
+               lvhd = (struct logicalVolHeaderDesc *)
+                               (lvid->logicalVolContentsUse);
                if (S_ISDIR(mode))
-                       UDF_SB_LVIDIU(sb)->numDirs =
-                               cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs) + 1);
+                       lvidiu->numDirs =
+                               cpu_to_le32(le32_to_cpu(lvidiu->numDirs) + 1);
                else
-                       UDF_SB_LVIDIU(sb)->numFiles =
-                               cpu_to_le32(le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) + 1);
-               UDF_I_UNIQUE(inode) = uniqueID = le64_to_cpu(lvhd->uniqueID);
+                       lvidiu->numFiles =
+                               cpu_to_le32(le32_to_cpu(lvidiu->numFiles) + 1);
+               iinfo->i_unique = uniqueID = le64_to_cpu(lvhd->uniqueID);
                if (!(++uniqueID & 0x00000000FFFFFFFFUL))
                        uniqueID += 16;
                lvhd->uniqueID = cpu_to_le64(uniqueID);
-               mark_buffer_dirty(UDF_SB_LVIDBH(sb));
+               mark_buffer_dirty(sbi->s_lvid_bh);
        }
        inode->i_mode = mode;
        inode->i_uid = current->fsuid;
@@ -114,35 +126,41 @@ struct inode *udf_new_inode(struct inode *dir, int mode, int *err)
                inode->i_gid = current->fsgid;
        }
 
-       UDF_I_LOCATION(inode).logicalBlockNum = block;
-       UDF_I_LOCATION(inode).partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum;
-       inode->i_ino = udf_get_lb_pblock(sb, UDF_I_LOCATION(inode), 0);
+       iinfo->i_location.logicalBlockNum = block;
+       iinfo->i_location.partitionReferenceNum =
+                               dinfo->i_location.partitionReferenceNum;
+       inode->i_ino = udf_get_lb_pblock(sb, iinfo->i_location, 0);
        inode->i_blocks = 0;
-       UDF_I_LENEATTR(inode) = 0;
-       UDF_I_LENALLOC(inode) = 0;
-       UDF_I_USE(inode) = 0;
+       iinfo->i_lenEAttr = 0;
+       iinfo->i_lenAlloc = 0;
+       iinfo->i_use = 0;
        if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_EXTENDED_FE)) {
-               UDF_I_EFE(inode) = 1;
-               UDF_UPDATE_UDFREV(inode->i_sb, UDF_VERS_USE_EXTENDED_FE);
-               UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry), GFP_KERNEL);
+               iinfo->i_efe = 1;
+               if (UDF_VERS_USE_EXTENDED_FE > sbi->s_udfrev)
+                       sbi->s_udfrev = UDF_VERS_USE_EXTENDED_FE;
+               iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize -
+                                           sizeof(struct extendedFileEntry),
+                                           GFP_KERNEL);
        } else {
-               UDF_I_EFE(inode) = 0;
-               UDF_I_DATA(inode) = kzalloc(inode->i_sb->s_blocksize - sizeof(struct fileEntry), GFP_KERNEL);
+               iinfo->i_efe = 0;
+               iinfo->i_ext.i_data = kzalloc(inode->i_sb->s_blocksize -
+                                           sizeof(struct fileEntry),
+                                           GFP_KERNEL);
        }
-       if (!UDF_I_DATA(inode)) {
+       if (!iinfo->i_ext.i_data) {
                iput(inode);
                *err = -ENOMEM;
                mutex_unlock(&sbi->s_alloc_mutex);
                return NULL;
        }
        if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_AD_IN_ICB))
-               UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
+               iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
        else if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
-               UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
+               iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
        else
-               UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG;
+               iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG;
        inode->i_mtime = inode->i_atime = inode->i_ctime =
-               UDF_I_CRTIME(inode) = current_fs_time(inode->i_sb);
+               iinfo->i_crtime = current_fs_time(inode->i_sb);
        insert_inode_hash(inode);
        mark_inode_dirty(inode);
        mutex_unlock(&sbi->s_alloc_mutex);
index 6ff8151984cfb45d4d80e06db9aadfb0ca9d6361..24cfa55d0fdc4a2ecd4964f4c759a8babd428e72 100644 (file)
@@ -19,7 +19,8 @@
  *  10/04/98 dgb  Added rudimentary directory functions
  *  10/07/98      Fully working udf_block_map! It works!
  *  11/25/98      bmap altered to better support extents
- *  12/06/98 blf  partition support in udf_iget, udf_block_map and udf_read_inode
+ *  12/06/98 blf  partition support in udf_iget, udf_block_map
+ *                and udf_read_inode
  *  12/12/98      rewrote udf_block_map to handle next extents and descs across
  *                block boundaries (which is not actually allowed)
  *  12/20/98      added support for strategy 4096
@@ -51,7 +52,7 @@ static int udf_update_inode(struct inode *, int);
 static void udf_fill_inode(struct inode *, struct buffer_head *);
 static int udf_alloc_i_data(struct inode *inode, size_t size);
 static struct buffer_head *inode_getblk(struct inode *, sector_t, int *,
-                                       long *, int *);
+                                       sector_t *, int *);
 static int8_t udf_insert_aext(struct inode *, struct extent_position,
                              kernel_lb_addr, uint32_t);
 static void udf_split_extents(struct inode *, int *, int, int,
@@ -111,16 +112,18 @@ no_delete:
  */
 void udf_clear_inode(struct inode *inode)
 {
+       struct udf_inode_info *iinfo;
        if (!(inode->i_sb->s_flags & MS_RDONLY)) {
                lock_kernel();
                /* Discard preallocation for directories, symlinks, etc. */
                udf_discard_prealloc(inode);
                udf_truncate_tail_extent(inode);
                unlock_kernel();
-               write_inode_now(inode, 1);
+               write_inode_now(inode, 0);
        }
-       kfree(UDF_I_DATA(inode));
-       UDF_I_DATA(inode) = NULL;
+       iinfo = UDF_I(inode);
+       kfree(iinfo->i_ext.i_data);
+       iinfo->i_ext.i_data = NULL;
 }
 
 static int udf_writepage(struct page *page, struct writeback_control *wbc)
@@ -160,6 +163,7 @@ void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err)
 {
        struct page *page;
        char *kaddr;
+       struct udf_inode_info *iinfo = UDF_I(inode);
        struct writeback_control udf_wbc = {
                .sync_mode = WB_SYNC_NONE,
                .nr_to_write = 1,
@@ -168,11 +172,11 @@ void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err)
        /* from now on we have normal address_space methods */
        inode->i_data.a_ops = &udf_aops;
 
-       if (!UDF_I_LENALLOC(inode)) {
+       if (!iinfo->i_lenAlloc) {
                if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
-                       UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
+                       iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
                else
-                       UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG;
+                       iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG;
                mark_inode_dirty(inode);
                return;
        }
@@ -182,21 +186,21 @@ void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err)
 
        if (!PageUptodate(page)) {
                kaddr = kmap(page);
-               memset(kaddr + UDF_I_LENALLOC(inode), 0x00,
-                      PAGE_CACHE_SIZE - UDF_I_LENALLOC(inode));
-               memcpy(kaddr, UDF_I_DATA(inode) + UDF_I_LENEATTR(inode),
-                      UDF_I_LENALLOC(inode));
+               memset(kaddr + iinfo->i_lenAlloc, 0x00,
+                      PAGE_CACHE_SIZE - iinfo->i_lenAlloc);
+               memcpy(kaddr, iinfo->i_ext.i_data + iinfo->i_lenEAttr,
+                       iinfo->i_lenAlloc);
                flush_dcache_page(page);
                SetPageUptodate(page);
                kunmap(page);
        }
-       memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0x00,
-              UDF_I_LENALLOC(inode));
-       UDF_I_LENALLOC(inode) = 0;
+       memset(iinfo->i_ext.i_data + iinfo->i_lenEAttr, 0x00,
+              iinfo->i_lenAlloc);
+       iinfo->i_lenAlloc = 0;
        if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
-               UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_SHORT;
+               iinfo->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
        else
-               UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_LONG;
+               iinfo->i_alloc_type = ICBTAG_FLAG_AD_LONG;
 
        inode->i_data.a_ops->writepage(page, &udf_wbc);
        page_cache_release(page);
@@ -215,9 +219,10 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
        struct extent_position epos;
 
        struct udf_fileident_bh sfibh, dfibh;
-       loff_t f_pos = udf_ext0_offset(inode) >> 2;
-       int size = (udf_ext0_offset(inode) + inode->i_size) >> 2;
+       loff_t f_pos = udf_ext0_offset(inode);
+       int size = udf_ext0_offset(inode) + inode->i_size;
        struct fileIdentDesc cfi, *sfi, *dfi;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
        if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
                alloctype = ICBTAG_FLAG_AD_SHORT;
@@ -225,19 +230,20 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
                alloctype = ICBTAG_FLAG_AD_LONG;
 
        if (!inode->i_size) {
-               UDF_I_ALLOCTYPE(inode) = alloctype;
+               iinfo->i_alloc_type = alloctype;
                mark_inode_dirty(inode);
                return NULL;
        }
 
        /* alloc block, and copy data to it */
        *block = udf_new_block(inode->i_sb, inode,
-                              UDF_I_LOCATION(inode).partitionReferenceNum,
-                              UDF_I_LOCATION(inode).logicalBlockNum, err);
+                              iinfo->i_location.partitionReferenceNum,
+                              iinfo->i_location.logicalBlockNum, err);
        if (!(*block))
                return NULL;
        newblock = udf_get_pblock(inode->i_sb, *block,
-                                 UDF_I_LOCATION(inode).partitionReferenceNum, 0);
+                                 iinfo->i_location.partitionReferenceNum,
+                               0);
        if (!newblock)
                return NULL;
        dbh = udf_tgetblk(inode->i_sb, newblock);
@@ -249,39 +255,44 @@ struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
        unlock_buffer(dbh);
        mark_buffer_dirty_inode(dbh, inode);
 
-       sfibh.soffset = sfibh.eoffset = (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2;
+       sfibh.soffset = sfibh.eoffset =
+                       f_pos & (inode->i_sb->s_blocksize - 1);
        sfibh.sbh = sfibh.ebh = NULL;
        dfibh.soffset = dfibh.eoffset = 0;
        dfibh.sbh = dfibh.ebh = dbh;
-       while ((f_pos < size)) {
-               UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
-               sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL, NULL, NULL, NULL);
+       while (f_pos < size) {
+               iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
+               sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL,
+                                        NULL, NULL, NULL);
                if (!sfi) {
                        brelse(dbh);
                        return NULL;
                }
-               UDF_I_ALLOCTYPE(inode) = alloctype;
+               iinfo->i_alloc_type = alloctype;
                sfi->descTag.tagLocation = cpu_to_le32(*block);
                dfibh.soffset = dfibh.eoffset;
                dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
                dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
                if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
-                                sfi->fileIdent + le16_to_cpu(sfi->lengthOfImpUse))) {
-                       UDF_I_ALLOCTYPE(inode) = ICBTAG_FLAG_AD_IN_ICB;
+                                sfi->fileIdent +
+                                       le16_to_cpu(sfi->lengthOfImpUse))) {
+                       iinfo->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
                        brelse(dbh);
                        return NULL;
                }
        }
        mark_buffer_dirty_inode(dbh, inode);
 
-       memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), 0, UDF_I_LENALLOC(inode));
-       UDF_I_LENALLOC(inode) = 0;
+       memset(iinfo->i_ext.i_data + iinfo->i_lenEAttr, 0,
+               iinfo->i_lenAlloc);
+       iinfo->i_lenAlloc = 0;
        eloc.logicalBlockNum = *block;
-       eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;
-       elen = inode->i_size;
-       UDF_I_LENEXTENTS(inode) = elen;
+       eloc.partitionReferenceNum =
+                               iinfo->i_location.partitionReferenceNum;
+       elen = inode->i_sb->s_blocksize;
+       iinfo->i_lenExtents = elen;
        epos.bh = NULL;
-       epos.block = UDF_I_LOCATION(inode);
+       epos.block = iinfo->i_location;
        epos.offset = udf_file_entry_alloc_offset(inode);
        udf_add_aext(inode, &epos, eloc, elen, 0);
        /* UniqueID stuff */
@@ -296,7 +307,8 @@ static int udf_get_block(struct inode *inode, sector_t block,
 {
        int err, new;
        struct buffer_head *bh;
-       unsigned long phys;
+       sector_t phys = 0;
+       struct udf_inode_info *iinfo;
 
        if (!create) {
                phys = udf_block_map(inode, block);
@@ -314,9 +326,10 @@ static int udf_get_block(struct inode *inode, sector_t block,
        if (block < 0)
                goto abort_negative;
 
-       if (block == UDF_I_NEXT_ALLOC_BLOCK(inode) + 1) {
-               UDF_I_NEXT_ALLOC_BLOCK(inode)++;
-               UDF_I_NEXT_ALLOC_GOAL(inode)++;
+       iinfo = UDF_I(inode);
+       if (block == iinfo->i_next_alloc_block + 1) {
+               iinfo->i_next_alloc_block++;
+               iinfo->i_next_alloc_goal++;
        }
 
        err = 0;
@@ -366,32 +379,35 @@ static struct buffer_head *udf_getblk(struct inode *inode, long block,
 
 /* Extend the file by 'blocks' blocks, return the number of extents added */
 int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
-                   kernel_long_ad * last_ext, sector_t blocks)
+                   kernel_long_ad *last_ext, sector_t blocks)
 {
        sector_t add;
        int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
        struct super_block *sb = inode->i_sb;
        kernel_lb_addr prealloc_loc = {};
        int prealloc_len = 0;
+       struct udf_inode_info *iinfo;
 
        /* The previous extent is fake and we should not extend by anything
         * - there's nothing to do... */
        if (!blocks && fake)
                return 0;
 
+       iinfo = UDF_I(inode);
        /* Round the last extent up to a multiple of block size */
        if (last_ext->extLength & (sb->s_blocksize - 1)) {
                last_ext->extLength =
                        (last_ext->extLength & UDF_EXTENT_FLAG_MASK) |
                        (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) +
                          sb->s_blocksize - 1) & ~(sb->s_blocksize - 1));
-               UDF_I_LENEXTENTS(inode) =
-                       (UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) &
+               iinfo->i_lenExtents =
+                       (iinfo->i_lenExtents + sb->s_blocksize - 1) &
                        ~(sb->s_blocksize - 1);
        }
 
        /* Last extent are just preallocated blocks? */
-       if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_ALLOCATED) {
+       if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
+                                               EXT_NOT_RECORDED_ALLOCATED) {
                /* Save the extent so that we can reattach it to the end */
                prealloc_loc = last_ext->extLocation;
                prealloc_len = last_ext->extLength;
@@ -399,13 +415,15 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
                last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
                        (last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
                last_ext->extLocation.logicalBlockNum = 0;
-                       last_ext->extLocation.partitionReferenceNum = 0;
+               last_ext->extLocation.partitionReferenceNum = 0;
        }
 
        /* Can we merge with the previous extent? */
-       if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_NOT_ALLOCATED) {
-               add = ((1 << 30) - sb->s_blocksize - (last_ext->extLength &
-                                                     UDF_EXTENT_LENGTH_MASK)) >> sb->s_blocksize_bits;
+       if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
+                                       EXT_NOT_RECORDED_NOT_ALLOCATED) {
+               add = ((1 << 30) - sb->s_blocksize -
+                       (last_ext->extLength & UDF_EXTENT_LENGTH_MASK)) >>
+                       sb->s_blocksize_bits;
                if (add > blocks)
                        add = blocks;
                blocks -= add;
@@ -416,9 +434,9 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
                udf_add_aext(inode, last_pos, last_ext->extLocation,
                             last_ext->extLength, 1);
                count++;
-       } else {
-               udf_write_aext(inode, last_pos, last_ext->extLocation, last_ext->extLength, 1);
-       }
+       } else
+               udf_write_aext(inode, last_pos, last_ext->extLocation,
+                               last_ext->extLength, 1);
 
        /* Managed to do everything necessary? */
        if (!blocks)
@@ -426,9 +444,10 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
 
        /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */
        last_ext->extLocation.logicalBlockNum = 0;
-               last_ext->extLocation.partitionReferenceNum = 0;
+       last_ext->extLocation.partitionReferenceNum = 0;
        add = (1 << (30-sb->s_blocksize_bits)) - 1;
-       last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits);
+       last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
+                               (add << sb->s_blocksize_bits);
 
        /* Create enough extents to cover the whole hole */
        while (blocks > add) {
@@ -450,7 +469,8 @@ int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
 out:
        /* Do we have some preallocated blocks saved? */
        if (prealloc_len) {
-               if (udf_add_aext(inode, last_pos, prealloc_loc, prealloc_len, 1) == -1)
+               if (udf_add_aext(inode, last_pos, prealloc_loc,
+                                prealloc_len, 1) == -1)
                        return -1;
                last_ext->extLocation = prealloc_loc;
                last_ext->extLength = prealloc_len;
@@ -458,9 +478,9 @@ out:
        }
 
        /* last_pos should point to the last written extent... */
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                last_pos->offset -= sizeof(short_ad);
-       else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
+       else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                last_pos->offset -= sizeof(long_ad);
        else
                return -1;
@@ -469,7 +489,7 @@ out:
 }
 
 static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
-                                       int *err, long *phys, int *new)
+                                       int *err, sector_t *phys, int *new)
 {
        static sector_t last_block;
        struct buffer_head *result = NULL;
@@ -483,11 +503,12 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
        uint32_t newblocknum, newblock;
        sector_t offset = 0;
        int8_t etype;
-       int goal = 0, pgoal = UDF_I_LOCATION(inode).logicalBlockNum;
+       struct udf_inode_info *iinfo = UDF_I(inode);
+       int goal = 0, pgoal = iinfo->i_location.logicalBlockNum;
        int lastblock = 0;
 
        prev_epos.offset = udf_file_entry_alloc_offset(inode);
-       prev_epos.block = UDF_I_LOCATION(inode);
+       prev_epos.block = iinfo->i_location;
        prev_epos.bh = NULL;
        cur_epos = next_epos = prev_epos;
        b_off = (loff_t)block << inode->i_sb->s_blocksize_bits;
@@ -515,7 +536,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
                prev_epos.offset = cur_epos.offset;
                cur_epos.offset = next_epos.offset;
 
-               if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1)) == -1)
+               etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1);
+               if (etype == -1)
                        break;
 
                c = !c;
@@ -569,9 +591,11 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
                        startnum = 1;
                } else {
                        /* Create a fake extent when there's not one */
-                       memset(&laarr[0].extLocation, 0x00, sizeof(kernel_lb_addr));
+                       memset(&laarr[0].extLocation, 0x00,
+                               sizeof(kernel_lb_addr));
                        laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
-                       /* Will udf_extend_file() create real extent from a fake one? */
+                       /* Will udf_extend_file() create real extent from
+                          a fake one? */
                        startnum = (offset > 0);
                }
                /* Create extents for the hole between EOF and offset */
@@ -589,14 +613,16 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
                offset = 0;
                count += ret;
                /* We are not covered by a preallocated extent? */
-               if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) != EXT_NOT_RECORDED_ALLOCATED) {
+               if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) !=
+                                               EXT_NOT_RECORDED_ALLOCATED) {
                        /* Is there any real extent? - otherwise we overwrite
                         * the fake one... */
                        if (count)
                                c = !c;
                        laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
                                inode->i_sb->s_blocksize;
-                       memset(&laarr[c].extLocation, 0x00, sizeof(kernel_lb_addr));
+                       memset(&laarr[c].extLocation, 0x00,
+                               sizeof(kernel_lb_addr));
                        count++;
                        endnum++;
                }
@@ -605,7 +631,8 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
        } else {
                endnum = startnum = ((count > 2) ? 2 : count);
 
-               /* if the current extent is in position 0, swap it with the previous */
+               /* if the current extent is in position 0,
+                  swap it with the previous */
                if (!c && count != 1) {
                        laarr[2] = laarr[0];
                        laarr[0] = laarr[1];
@@ -613,44 +640,47 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
                        c = 1;
                }
 
-               /* if the current block is located in an extent, read the next extent */
-               if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1) {
+               /* if the current block is located in an extent,
+                  read the next extent */
+               etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0);
+               if (etype != -1) {
                        laarr[c + 1].extLength = (etype << 30) | elen;
                        laarr[c + 1].extLocation = eloc;
                        count++;
                        startnum++;
                        endnum++;
-               } else {
+               } else
                        lastblock = 1;
-               }
        }
 
        /* if the current extent is not recorded but allocated, get the
         * block in the extent corresponding to the requested block */
-       if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
+       if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
                newblocknum = laarr[c].extLocation.logicalBlockNum + offset;
-       else { /* otherwise, allocate a new block */
-               if (UDF_I_NEXT_ALLOC_BLOCK(inode) == block)
-                       goal = UDF_I_NEXT_ALLOC_GOAL(inode);
+       else { /* otherwise, allocate a new block */
+               if (iinfo->i_next_alloc_block == block)
+                       goal = iinfo->i_next_alloc_goal;
 
                if (!goal) {
-                       if (!(goal = pgoal))
-                               goal = UDF_I_LOCATION(inode).logicalBlockNum + 1;
+                       if (!(goal = pgoal)) /* XXX: what was intended here? */
+                               goal = iinfo->i_location.logicalBlockNum + 1;
                }
 
-               if (!(newblocknum = udf_new_block(inode->i_sb, inode,
-                                                 UDF_I_LOCATION(inode).partitionReferenceNum,
-                                                 goal, err))) {
+               newblocknum = udf_new_block(inode->i_sb, inode,
+                               iinfo->i_location.partitionReferenceNum,
+                               goal, err);
+               if (!newblocknum) {
                        brelse(prev_epos.bh);
                        *err = -ENOSPC;
                        return NULL;
                }
-               UDF_I_LENEXTENTS(inode) += inode->i_sb->s_blocksize;
+               iinfo->i_lenExtents += inode->i_sb->s_blocksize;
        }
 
-       /* if the extent the requsted block is located in contains multiple blocks,
-        * split the extent into at most three extents. blocks prior to requested
-        * block, requested block, and blocks after requested block */
+       /* if the extent the requsted block is located in contains multiple
+        * blocks, split the extent into at most three extents. blocks prior
+        * to requested block, requested block, and blocks after requested
+        * block */
        udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
 
 #ifdef UDF_PREALLOCATE
@@ -668,15 +698,15 @@ static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
 
        brelse(prev_epos.bh);
 
-       if (!(newblock = udf_get_pblock(inode->i_sb, newblocknum,
-                                       UDF_I_LOCATION(inode).partitionReferenceNum, 0))) {
+       newblock = udf_get_pblock(inode->i_sb, newblocknum,
+                               iinfo->i_location.partitionReferenceNum, 0);
+       if (!newblock)
                return NULL;
-       }
        *phys = newblock;
        *err = 0;
        *new = 1;
-       UDF_I_NEXT_ALLOC_BLOCK(inode) = block;
-       UDF_I_NEXT_ALLOC_GOAL(inode) = newblocknum;
+       iinfo->i_next_alloc_block = block;
+       iinfo->i_next_alloc_goal = newblocknum;
        inode->i_ctime = current_fs_time(inode->i_sb);
 
        if (IS_SYNC(inode))
@@ -692,16 +722,20 @@ static void udf_split_extents(struct inode *inode, int *c, int offset,
                              kernel_long_ad laarr[EXTENT_MERGE_SIZE],
                              int *endnum)
 {
+       unsigned long blocksize = inode->i_sb->s_blocksize;
+       unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
+
        if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) ||
-           (laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
+           (laarr[*c].extLength >> 30) ==
+                               (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
                int curr = *c;
                int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) +
-                           inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
+                           blocksize - 1) >> blocksize_bits;
                int8_t etype = (laarr[curr].extLength >> 30);
 
-               if (blen == 1) {
+               if (blen == 1)
                        ;
-               else if (!offset || blen == offset + 1) {
+               else if (!offset || blen == offset + 1) {
                        laarr[curr + 2] = laarr[curr + 1];
                        laarr[curr + 1] = laarr[curr];
                } else {
@@ -711,15 +745,18 @@ static void udf_split_extents(struct inode *inode, int *c, int offset,
 
                if (offset) {
                        if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
-                               udf_free_blocks(inode->i_sb, inode, laarr[curr].extLocation, 0, offset);
-                               laarr[curr].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
-                                       (offset << inode->i_sb->s_blocksize_bits);
+                               udf_free_blocks(inode->i_sb, inode,
+                                               laarr[curr].extLocation,
+                                               0, offset);
+                               laarr[curr].extLength =
+                                       EXT_NOT_RECORDED_NOT_ALLOCATED |
+                                       (offset << blocksize_bits);
                                laarr[curr].extLocation.logicalBlockNum = 0;
-                               laarr[curr].extLocation.partitionReferenceNum = 0;
-                       } else {
+                               laarr[curr].extLocation.
+                                               partitionReferenceNum = 0;
+                       } else
                                laarr[curr].extLength = (etype << 30) |
-                                       (offset << inode->i_sb->s_blocksize_bits);
-                       }
+                                       (offset << blocksize_bits);
                        curr++;
                        (*c)++;
                        (*endnum)++;
@@ -728,16 +765,17 @@ static void udf_split_extents(struct inode *inode, int *c, int offset,
                laarr[curr].extLocation.logicalBlockNum = newblocknum;
                if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
                        laarr[curr].extLocation.partitionReferenceNum =
-                               UDF_I_LOCATION(inode).partitionReferenceNum;
+                               UDF_I(inode)->i_location.partitionReferenceNum;
                laarr[curr].extLength = EXT_RECORDED_ALLOCATED |
-                       inode->i_sb->s_blocksize;
+                       blocksize;
                curr++;
 
                if (blen != offset + 1) {
                        if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
-                               laarr[curr].extLocation.logicalBlockNum += (offset + 1);
+                               laarr[curr].extLocation.logicalBlockNum +=
+                                                               offset + 1;
                        laarr[curr].extLength = (etype << 30) |
-                               ((blen - (offset + 1)) << inode->i_sb->s_blocksize_bits);
+                               ((blen - (offset + 1)) << blocksize_bits);
                        curr++;
                        (*endnum)++;
                }
@@ -756,69 +794,86 @@ static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
                else
                        start = c;
        } else {
-               if ((laarr[c + 1].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
+               if ((laarr[c + 1].extLength >> 30) ==
+                                       (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
                        start = c + 1;
-                       length = currlength = (((laarr[c + 1].extLength & UDF_EXTENT_LENGTH_MASK) +
-                                               inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
-               } else {
+                       length = currlength =
+                               (((laarr[c + 1].extLength &
+                                       UDF_EXTENT_LENGTH_MASK) +
+                               inode->i_sb->s_blocksize - 1) >>
+                               inode->i_sb->s_blocksize_bits);
+               } else
                        start = c;
-               }
        }
 
        for (i = start + 1; i <= *endnum; i++) {
                if (i == *endnum) {
                        if (lastblock)
                                length += UDF_DEFAULT_PREALLOC_BLOCKS;
-               } else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
-                       length += (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
-                                   inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
-               } else {
+               } else if ((laarr[i].extLength >> 30) ==
+                               (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
+                       length += (((laarr[i].extLength &
+                                               UDF_EXTENT_LENGTH_MASK) +
+                                   inode->i_sb->s_blocksize - 1) >>
+                                   inode->i_sb->s_blocksize_bits);
+               } else
                        break;
-               }
        }
 
        if (length) {
                int next = laarr[start].extLocation.logicalBlockNum +
                        (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) +
-                         inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
+                         inode->i_sb->s_blocksize - 1) >>
+                         inode->i_sb->s_blocksize_bits);
                int numalloc = udf_prealloc_blocks(inode->i_sb, inode,
-                                                  laarr[start].extLocation.partitionReferenceNum,
-                                                  next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ? length :
-                                                         UDF_DEFAULT_PREALLOC_BLOCKS) - currlength);
+                               laarr[start].extLocation.partitionReferenceNum,
+                               next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ?
+                               length : UDF_DEFAULT_PREALLOC_BLOCKS) -
+                               currlength);
                if (numalloc)   {
-                       if (start == (c + 1)) {
+                       if (start == (c + 1))
                                laarr[start].extLength +=
-                                       (numalloc << inode->i_sb->s_blocksize_bits);
-                       } else {
+                                       (numalloc <<
+                                        inode->i_sb->s_blocksize_bits);
+                       else {
                                memmove(&laarr[c + 2], &laarr[c + 1],
                                        sizeof(long_ad) * (*endnum - (c + 1)));
                                (*endnum)++;
                                laarr[c + 1].extLocation.logicalBlockNum = next;
                                laarr[c + 1].extLocation.partitionReferenceNum =
-                                       laarr[c].extLocation.partitionReferenceNum;
-                               laarr[c + 1].extLength = EXT_NOT_RECORDED_ALLOCATED |
-                                       (numalloc << inode->i_sb->s_blocksize_bits);
+                                       laarr[c].extLocation.
+                                                       partitionReferenceNum;
+                               laarr[c + 1].extLength =
+                                       EXT_NOT_RECORDED_ALLOCATED |
+                                       (numalloc <<
+                                        inode->i_sb->s_blocksize_bits);
                                start = c + 1;
                        }
 
                        for (i = start + 1; numalloc && i < *endnum; i++) {
-                               int elen = ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
-                                           inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits;
+                               int elen = ((laarr[i].extLength &
+                                               UDF_EXTENT_LENGTH_MASK) +
+                                           inode->i_sb->s_blocksize - 1) >>
+                                           inode->i_sb->s_blocksize_bits;
 
                                if (elen > numalloc) {
                                        laarr[i].extLength -=
-                                               (numalloc << inode->i_sb->s_blocksize_bits);
+                                               (numalloc <<
+                                                inode->i_sb->s_blocksize_bits);
                                        numalloc = 0;
                                } else {
                                        numalloc -= elen;
                                        if (*endnum > (i + 1))
-                                               memmove(&laarr[i], &laarr[i + 1],
-                                                       sizeof(long_ad) * (*endnum - (i + 1)));
+                                               memmove(&laarr[i],
+                                                       &laarr[i + 1],
+                                                       sizeof(long_ad) *
+                                                       (*endnum - (i + 1)));
                                        i--;
                                        (*endnum)--;
                                }
                        }
-                       UDF_I_LENEXTENTS(inode) += numalloc << inode->i_sb->s_blocksize_bits;
+                       UDF_I(inode)->i_lenExtents +=
+                               numalloc << inode->i_sb->s_blocksize_bits;
                }
        }
 }
@@ -828,70 +883,97 @@ static void udf_merge_extents(struct inode *inode,
                              int *endnum)
 {
        int i;
+       unsigned long blocksize = inode->i_sb->s_blocksize;
+       unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
 
        for (i = 0; i < (*endnum - 1); i++) {
-               if ((laarr[i].extLength >> 30) == (laarr[i + 1].extLength >> 30)) {
-                       if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) ||
-                           ((laarr[i + 1].extLocation.logicalBlockNum - laarr[i].extLocation.logicalBlockNum) ==
-                            (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
-                              inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits))) {
-                               if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
-                                    (laarr[i + 1].extLength & UDF_EXTENT_LENGTH_MASK) +
-                                    inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
-                                       laarr[i + 1].extLength = (laarr[i + 1].extLength -
-                                                                 (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
-                                                                 UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize - 1);
-                                       laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) +
-                                               (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize;
-                                       laarr[i + 1].extLocation.logicalBlockNum =
-                                               laarr[i].extLocation.logicalBlockNum +
-                                               ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) >>
-                                                inode->i_sb->s_blocksize_bits);
-                               } else {
-                                       laarr[i].extLength = laarr[i + 1].extLength +
-                                               (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
-                                                 inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize - 1));
-                                       if (*endnum > (i + 2))
-                                               memmove(&laarr[i + 1], &laarr[i + 2],
-                                                       sizeof(long_ad) * (*endnum - (i + 2)));
-                                       i--;
-                                       (*endnum)--;
-                               }
+               kernel_long_ad *li /*l[i]*/ = &laarr[i];
+               kernel_long_ad *lip1 /*l[i plus 1]*/ = &laarr[i + 1];
+
+               if (((li->extLength >> 30) == (lip1->extLength >> 30)) &&
+                       (((li->extLength >> 30) ==
+                               (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) ||
+                       ((lip1->extLocation.logicalBlockNum -
+                         li->extLocation.logicalBlockNum) ==
+                       (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
+                       blocksize - 1) >> blocksize_bits)))) {
+
+                       if (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
+                               (lip1->extLength & UDF_EXTENT_LENGTH_MASK) +
+                               blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
+                               lip1->extLength = (lip1->extLength -
+                                                 (li->extLength &
+                                                  UDF_EXTENT_LENGTH_MASK) +
+                                                  UDF_EXTENT_LENGTH_MASK) &
+                                                       ~(blocksize - 1);
+                               li->extLength = (li->extLength &
+                                                UDF_EXTENT_FLAG_MASK) +
+                                               (UDF_EXTENT_LENGTH_MASK + 1) -
+                                               blocksize;
+                               lip1->extLocation.logicalBlockNum =
+                                       li->extLocation.logicalBlockNum +
+                                       ((li->extLength &
+                                               UDF_EXTENT_LENGTH_MASK) >>
+                                               blocksize_bits);
+                       } else {
+                               li->extLength = lip1->extLength +
+                                       (((li->extLength &
+                                               UDF_EXTENT_LENGTH_MASK) +
+                                        blocksize - 1) & ~(blocksize - 1));
+                               if (*endnum > (i + 2))
+                                       memmove(&laarr[i + 1], &laarr[i + 2],
+                                               sizeof(long_ad) *
+                                               (*endnum - (i + 2)));
+                               i--;
+                               (*endnum)--;
                        }
-               } else if (((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) &&
-                          ((laarr[i + 1].extLength >> 30) == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) {
-                       udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0,
-                                       ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
-                                        inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
-                       laarr[i].extLocation.logicalBlockNum = 0;
-                       laarr[i].extLocation.partitionReferenceNum = 0;
-
-                       if (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
-                            (laarr[i + 1].extLength & UDF_EXTENT_LENGTH_MASK) +
-                            inode->i_sb->s_blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
-                               laarr[i + 1].extLength = (laarr[i + 1].extLength -
-                                                         (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
-                                                         UDF_EXTENT_LENGTH_MASK) & ~(inode->i_sb->s_blocksize - 1);
-                               laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_FLAG_MASK) +
-                                       (UDF_EXTENT_LENGTH_MASK + 1) - inode->i_sb->s_blocksize;
+               } else if (((li->extLength >> 30) ==
+                               (EXT_NOT_RECORDED_ALLOCATED >> 30)) &&
+                          ((lip1->extLength >> 30) ==
+                               (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) {
+                       udf_free_blocks(inode->i_sb, inode, li->extLocation, 0,
+                                       ((li->extLength &
+                                         UDF_EXTENT_LENGTH_MASK) +
+                                        blocksize - 1) >> blocksize_bits);
+                       li->extLocation.logicalBlockNum = 0;
+                       li->extLocation.partitionReferenceNum = 0;
+
+                       if (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
+                            (lip1->extLength & UDF_EXTENT_LENGTH_MASK) +
+                            blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
+                               lip1->extLength = (lip1->extLength -
+                                                  (li->extLength &
+                                                  UDF_EXTENT_LENGTH_MASK) +
+                                                  UDF_EXTENT_LENGTH_MASK) &
+                                                  ~(blocksize - 1);
+                               li->extLength = (li->extLength &
+                                                UDF_EXTENT_FLAG_MASK) +
+                                               (UDF_EXTENT_LENGTH_MASK + 1) -
+                                               blocksize;
                        } else {
-                               laarr[i].extLength = laarr[i + 1].extLength +
-                                       (((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
-                                         inode->i_sb->s_blocksize - 1) & ~(inode->i_sb->s_blocksize - 1));
+                               li->extLength = lip1->extLength +
+                                       (((li->extLength &
+                                               UDF_EXTENT_LENGTH_MASK) +
+                                         blocksize - 1) & ~(blocksize - 1));
                                if (*endnum > (i + 2))
                                        memmove(&laarr[i + 1], &laarr[i + 2],
-                                               sizeof(long_ad) * (*endnum - (i + 2)));
+                                               sizeof(long_ad) *
+                                               (*endnum - (i + 2)));
                                i--;
                                (*endnum)--;
                        }
-               } else if ((laarr[i].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
-                       udf_free_blocks(inode->i_sb, inode, laarr[i].extLocation, 0,
-                                       ((laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) +
-                                        inode->i_sb->s_blocksize - 1) >> inode->i_sb->s_blocksize_bits);
-                       laarr[i].extLocation.logicalBlockNum = 0;
-                       laarr[i].extLocation.partitionReferenceNum = 0;
-                       laarr[i].extLength = (laarr[i].extLength & UDF_EXTENT_LENGTH_MASK) |
-                               EXT_NOT_RECORDED_NOT_ALLOCATED;
+               } else if ((li->extLength >> 30) ==
+                                       (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
+                       udf_free_blocks(inode->i_sb, inode,
+                                       li->extLocation, 0,
+                                       ((li->extLength &
+                                               UDF_EXTENT_LENGTH_MASK) +
+                                        blocksize - 1) >> blocksize_bits);
+                       li->extLocation.logicalBlockNum = 0;
+                       li->extLocation.partitionReferenceNum = 0;
+                       li->extLength = (li->extLength &
+                                               UDF_EXTENT_LENGTH_MASK) |
+                                               EXT_NOT_RECORDED_NOT_ALLOCATED;
                }
        }
 }
@@ -953,6 +1035,7 @@ void udf_truncate(struct inode *inode)
 {
        int offset;
        int err;
+       struct udf_inode_info *iinfo;
 
        if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
              S_ISLNK(inode->i_mode)))
@@ -961,25 +1044,28 @@ void udf_truncate(struct inode *inode)
                return;
 
        lock_kernel();
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
-               if (inode->i_sb->s_blocksize < (udf_file_entry_alloc_offset(inode) +
-                                               inode->i_size)) {
+       iinfo = UDF_I(inode);
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
+               if (inode->i_sb->s_blocksize <
+                               (udf_file_entry_alloc_offset(inode) +
+                                inode->i_size)) {
                        udf_expand_file_adinicb(inode, inode->i_size, &err);
-                       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
-                               inode->i_size = UDF_I_LENALLOC(inode);
+                       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
+                               inode->i_size = iinfo->i_lenAlloc;
                                unlock_kernel();
                                return;
-                       } else {
+                       } else
                                udf_truncate_extents(inode);
-                       }
                } else {
                        offset = inode->i_size & (inode->i_sb->s_blocksize - 1);
-                       memset(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode) + offset, 0x00,
-                              inode->i_sb->s_blocksize - offset - udf_file_entry_alloc_offset(inode));
-                       UDF_I_LENALLOC(inode) = inode->i_size;
+                       memset(iinfo->i_ext.i_data + iinfo->i_lenEAttr + offset,
+                               0x00, inode->i_sb->s_blocksize -
+                               offset - udf_file_entry_alloc_offset(inode));
+                       iinfo->i_lenAlloc = inode->i_size;
                }
        } else {
-               block_truncate_page(inode->i_mapping, inode->i_size, udf_get_block);
+               block_truncate_page(inode->i_mapping, inode->i_size,
+                                   udf_get_block);
                udf_truncate_extents(inode);
        }
 
@@ -996,6 +1082,7 @@ static void __udf_read_inode(struct inode *inode)
        struct buffer_head *bh = NULL;
        struct fileEntry *fe;
        uint16_t ident;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
        /*
         * Set defaults, but the inode is still incomplete!
@@ -1009,7 +1096,7 @@ static void __udf_read_inode(struct inode *inode)
         *      i_nlink = 1
         *      i_op = NULL;
         */
-       bh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 0, &ident);
+       bh = udf_read_ptagged(inode->i_sb, iinfo->i_location, 0, &ident);
        if (!bh) {
                printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
                       inode->i_ino);
@@ -1019,8 +1106,8 @@ static void __udf_read_inode(struct inode *inode)
 
        if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE &&
            ident != TAG_IDENT_USE) {
-               printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed ident=%d\n",
-                      inode->i_ino, ident);
+               printk(KERN_ERR "udf: udf_read_inode(ino %ld) "
+                               "failed ident=%d\n", inode->i_ino, ident);
                brelse(bh);
                make_bad_inode(inode);
                return;
@@ -1028,11 +1115,12 @@ static void __udf_read_inode(struct inode *inode)
 
        fe = (struct fileEntry *)bh->b_data;
 
-       if (le16_to_cpu(fe->icbTag.strategyType) == 4096) {
+       if (fe->icbTag.strategyType == cpu_to_le16(4096)) {
                struct buffer_head *ibh = NULL, *nbh = NULL;
                struct indirectEntry *ie;
 
-               ibh = udf_read_ptagged(inode->i_sb, UDF_I_LOCATION(inode), 1, &ident);
+               ibh = udf_read_ptagged(inode->i_sb, iinfo->i_location, 1,
+                                       &ident);
                if (ident == TAG_IDENT_IE) {
                        if (ibh) {
                                kernel_lb_addr loc;
@@ -1041,10 +1129,12 @@ static void __udf_read_inode(struct inode *inode)
                                loc = lelb_to_cpu(ie->indirectICB.extLocation);
 
                                if (ie->indirectICB.extLength &&
-                                   (nbh = udf_read_ptagged(inode->i_sb, loc, 0, &ident))) {
+                                   (nbh = udf_read_ptagged(inode->i_sb, loc, 0,
+                                                           &ident))) {
                                        if (ident == TAG_IDENT_FE ||
                                            ident == TAG_IDENT_EFE) {
-                                               memcpy(&UDF_I_LOCATION(inode), &loc,
+                                               memcpy(&iinfo->i_location,
+                                                      &loc,
                                                       sizeof(kernel_lb_addr));
                                                brelse(bh);
                                                brelse(ibh);
@@ -1062,7 +1152,7 @@ static void __udf_read_inode(struct inode *inode)
                } else {
                        brelse(ibh);
                }
-       } else if (le16_to_cpu(fe->icbTag.strategyType) != 4) {
+       } else if (fe->icbTag.strategyType != cpu_to_le16(4)) {
                printk(KERN_ERR "udf: unsupported strategy type: %d\n",
                       le16_to_cpu(fe->icbTag.strategyType));
                brelse(bh);
@@ -1081,51 +1171,63 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
        time_t convtime;
        long convtime_usec;
        int offset;
+       struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
        fe = (struct fileEntry *)bh->b_data;
        efe = (struct extendedFileEntry *)bh->b_data;
 
-       if (le16_to_cpu(fe->icbTag.strategyType) == 4)
-               UDF_I_STRAT4096(inode) = 0;
-       else /* if (le16_to_cpu(fe->icbTag.strategyType) == 4096) */
-               UDF_I_STRAT4096(inode) = 1;
-
-       UDF_I_ALLOCTYPE(inode) = le16_to_cpu(fe->icbTag.flags) & ICBTAG_FLAG_AD_MASK;
-       UDF_I_UNIQUE(inode) = 0;
-       UDF_I_LENEATTR(inode) = 0;
-       UDF_I_LENEXTENTS(inode) = 0;
-       UDF_I_LENALLOC(inode) = 0;
-       UDF_I_NEXT_ALLOC_BLOCK(inode) = 0;
-       UDF_I_NEXT_ALLOC_GOAL(inode) = 0;
-       if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_EFE) {
-               UDF_I_EFE(inode) = 1;
-               UDF_I_USE(inode) = 0;
-               if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry))) {
+       if (fe->icbTag.strategyType == cpu_to_le16(4))
+               iinfo->i_strat4096 = 0;
+       else /* if (fe->icbTag.strategyType == cpu_to_le16(4096)) */
+               iinfo->i_strat4096 = 1;
+
+       iinfo->i_alloc_type = le16_to_cpu(fe->icbTag.flags) &
+                                                       ICBTAG_FLAG_AD_MASK;
+       iinfo->i_unique = 0;
+       iinfo->i_lenEAttr = 0;
+       iinfo->i_lenExtents = 0;
+       iinfo->i_lenAlloc = 0;
+       iinfo->i_next_alloc_block = 0;
+       iinfo->i_next_alloc_goal = 0;
+       if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_EFE)) {
+               iinfo->i_efe = 1;
+               iinfo->i_use = 0;
+               if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
+                                       sizeof(struct extendedFileEntry))) {
                        make_bad_inode(inode);
                        return;
                }
-               memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct extendedFileEntry),
-                      inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry));
-       } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_FE) {
-               UDF_I_EFE(inode) = 0;
-               UDF_I_USE(inode) = 0;
-               if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct fileEntry))) {
+               memcpy(iinfo->i_ext.i_data,
+                      bh->b_data + sizeof(struct extendedFileEntry),
+                      inode->i_sb->s_blocksize -
+                                       sizeof(struct extendedFileEntry));
+       } else if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_FE)) {
+               iinfo->i_efe = 0;
+               iinfo->i_use = 0;
+               if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
+                                               sizeof(struct fileEntry))) {
                        make_bad_inode(inode);
                        return;
                }
-               memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct fileEntry),
+               memcpy(iinfo->i_ext.i_data,
+                      bh->b_data + sizeof(struct fileEntry),
                       inode->i_sb->s_blocksize - sizeof(struct fileEntry));
-       } else if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
-               UDF_I_EFE(inode) = 0;
-               UDF_I_USE(inode) = 1;
-               UDF_I_LENALLOC(inode) =
-                   le32_to_cpu(((struct unallocSpaceEntry *)bh->b_data)->lengthAllocDescs);
-               if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry))) {
+       } else if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_USE)) {
+               iinfo->i_efe = 0;
+               iinfo->i_use = 1;
+               iinfo->i_lenAlloc = le32_to_cpu(
+                               ((struct unallocSpaceEntry *)bh->b_data)->
+                                lengthAllocDescs);
+               if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
+                                       sizeof(struct unallocSpaceEntry))) {
                        make_bad_inode(inode);
                        return;
                }
-               memcpy(UDF_I_DATA(inode), bh->b_data + sizeof(struct unallocSpaceEntry),
-                      inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry));
+               memcpy(iinfo->i_ext.i_data,
+                      bh->b_data + sizeof(struct unallocSpaceEntry),
+                      inode->i_sb->s_blocksize -
+                                       sizeof(struct unallocSpaceEntry));
                return;
        }
 
@@ -1146,12 +1248,12 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
                inode->i_nlink = 1;
 
        inode->i_size = le64_to_cpu(fe->informationLength);
-       UDF_I_LENEXTENTS(inode) = inode->i_size;
+       iinfo->i_lenExtents = inode->i_size;
 
        inode->i_mode = udf_convert_permissions(fe);
        inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask;
 
-       if (UDF_I_EFE(inode) == 0) {
+       if (iinfo->i_efe == 0) {
                inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
                        (inode->i_sb->s_blocksize_bits - 9);
 
@@ -1160,7 +1262,7 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
                        inode->i_atime.tv_sec = convtime;
                        inode->i_atime.tv_nsec = convtime_usec * 1000;
                } else {
-                       inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
+                       inode->i_atime = sbi->s_record_time;
                }
 
                if (udf_stamp_to_time(&convtime, &convtime_usec,
@@ -1168,7 +1270,7 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
                        inode->i_mtime.tv_sec = convtime;
                        inode->i_mtime.tv_nsec = convtime_usec * 1000;
                } else {
-                       inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
+                       inode->i_mtime = sbi->s_record_time;
                }
 
                if (udf_stamp_to_time(&convtime, &convtime_usec,
@@ -1176,13 +1278,13 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
                        inode->i_ctime.tv_sec = convtime;
                        inode->i_ctime.tv_nsec = convtime_usec * 1000;
                } else {
-                       inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
+                       inode->i_ctime = sbi->s_record_time;
                }
 
-               UDF_I_UNIQUE(inode) = le64_to_cpu(fe->uniqueID);
-               UDF_I_LENEATTR(inode) = le32_to_cpu(fe->lengthExtendedAttr);
-               UDF_I_LENALLOC(inode) = le32_to_cpu(fe->lengthAllocDescs);
-               offset = sizeof(struct fileEntry) + UDF_I_LENEATTR(inode);
+               iinfo->i_unique = le64_to_cpu(fe->uniqueID);
+               iinfo->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr);
+               iinfo->i_lenAlloc = le32_to_cpu(fe->lengthAllocDescs);
+               offset = sizeof(struct fileEntry) + iinfo->i_lenEAttr;
        } else {
                inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
                    (inode->i_sb->s_blocksize_bits - 9);
@@ -1192,7 +1294,7 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
                        inode->i_atime.tv_sec = convtime;
                        inode->i_atime.tv_nsec = convtime_usec * 1000;
                } else {
-                       inode->i_atime = UDF_SB_RECORDTIME(inode->i_sb);
+                       inode->i_atime = sbi->s_record_time;
                }
 
                if (udf_stamp_to_time(&convtime, &convtime_usec,
@@ -1200,15 +1302,15 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
                        inode->i_mtime.tv_sec = convtime;
                        inode->i_mtime.tv_nsec = convtime_usec * 1000;
                } else {
-                       inode->i_mtime = UDF_SB_RECORDTIME(inode->i_sb);
+                       inode->i_mtime = sbi->s_record_time;
                }
 
                if (udf_stamp_to_time(&convtime, &convtime_usec,
                                      lets_to_cpu(efe->createTime))) {
-                       UDF_I_CRTIME(inode).tv_sec = convtime;
-                       UDF_I_CRTIME(inode).tv_nsec = convtime_usec * 1000;
+                       iinfo->i_crtime.tv_sec = convtime;
+                       iinfo->i_crtime.tv_nsec = convtime_usec * 1000;
                } else {
-                       UDF_I_CRTIME(inode) = UDF_SB_RECORDTIME(inode->i_sb);
+                       iinfo->i_crtime = sbi->s_record_time;
                }
 
                if (udf_stamp_to_time(&convtime, &convtime_usec,
@@ -1216,13 +1318,14 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
                        inode->i_ctime.tv_sec = convtime;
                        inode->i_ctime.tv_nsec = convtime_usec * 1000;
                } else {
-                       inode->i_ctime = UDF_SB_RECORDTIME(inode->i_sb);
+                       inode->i_ctime = sbi->s_record_time;
                }
 
-               UDF_I_UNIQUE(inode) = le64_to_cpu(efe->uniqueID);
-               UDF_I_LENEATTR(inode) = le32_to_cpu(efe->lengthExtendedAttr);
-               UDF_I_LENALLOC(inode) = le32_to_cpu(efe->lengthAllocDescs);
-               offset = sizeof(struct extendedFileEntry) + UDF_I_LENEATTR(inode);
+               iinfo->i_unique = le64_to_cpu(efe->uniqueID);
+               iinfo->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr);
+               iinfo->i_lenAlloc = le32_to_cpu(efe->lengthAllocDescs);
+               offset = sizeof(struct extendedFileEntry) +
+                                                       iinfo->i_lenEAttr;
        }
 
        switch (fe->icbTag.fileType) {
@@ -1235,7 +1338,7 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
        case ICBTAG_FILE_TYPE_REALTIME:
        case ICBTAG_FILE_TYPE_REGULAR:
        case ICBTAG_FILE_TYPE_UNDEF:
-               if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
+               if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
                        inode->i_data.a_ops = &udf_adinicb_aops;
                else
                        inode->i_data.a_ops = &udf_aops;
@@ -1261,31 +1364,33 @@ static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
                inode->i_mode = S_IFLNK | S_IRWXUGO;
                break;
        default:
-               printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown file type=%d\n",
-                      inode->i_ino, fe->icbTag.fileType);
+               printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown "
+                               "file type=%d\n", inode->i_ino,
+                               fe->icbTag.fileType);
                make_bad_inode(inode);
                return;
        }
        if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
-               struct deviceSpec *dsea = (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
+               struct deviceSpec *dsea =
+                       (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
                if (dsea) {
                        init_special_inode(inode, inode->i_mode,
-                                          MKDEV(le32_to_cpu(dsea->majorDeviceIdent),
-                                                le32_to_cpu(dsea->minorDeviceIdent)));
+                               MKDEV(le32_to_cpu(dsea->majorDeviceIdent),
+                                     le32_to_cpu(dsea->minorDeviceIdent)));
                        /* Developer ID ??? */
-               } else {
+               } else
                        make_bad_inode(inode);
-               }
        }
 }
 
 static int udf_alloc_i_data(struct inode *inode, size_t size)
 {
-       UDF_I_DATA(inode) = kmalloc(size, GFP_KERNEL);
+       struct udf_inode_info *iinfo = UDF_I(inode);
+       iinfo->i_ext.i_data = kmalloc(size, GFP_KERNEL);
 
-       if (!UDF_I_DATA(inode)) {
-               printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) no free memory\n",
-                      inode->i_ino);
+       if (!iinfo->i_ext.i_data) {
+               printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) "
+                               "no free memory\n", inode->i_ino);
                return -ENOMEM;
        }
 
@@ -1301,12 +1406,12 @@ static mode_t udf_convert_permissions(struct fileEntry *fe)
        permissions = le32_to_cpu(fe->permissions);
        flags = le16_to_cpu(fe->icbTag.flags);
 
-       mode =  (( permissions      ) & S_IRWXO) |
-               (( permissions >> 2 ) & S_IRWXG) |
-               (( permissions >> 4 ) & S_IRWXU) |
-               (( flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) |
-               (( flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) |
-               (( flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0);
+       mode =  ((permissions) & S_IRWXO) |
+               ((permissions >> 2) & S_IRWXG) |
+               ((permissions >> 4) & S_IRWXU) |
+               ((flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) |
+               ((flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) |
+               ((flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0);
 
        return mode;
 }
@@ -1350,11 +1455,15 @@ static int udf_update_inode(struct inode *inode, int do_sync)
        uint32_t udfperms;
        uint16_t icbflags;
        uint16_t crclen;
-       int i;
        kernel_timestamp cpu_time;
        int err = 0;
+       struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
+       unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
-       bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, UDF_I_LOCATION(inode), 0));
+       bh = udf_tread(inode->i_sb,
+                       udf_get_lb_pblock(inode->i_sb,
+                                         iinfo->i_location, 0));
        if (!bh) {
                udf_debug("bread failure\n");
                return -EIO;
@@ -1365,23 +1474,24 @@ static int udf_update_inode(struct inode *inode, int do_sync)
        fe = (struct fileEntry *)bh->b_data;
        efe = (struct extendedFileEntry *)bh->b_data;
 
-       if (le16_to_cpu(fe->descTag.tagIdent) == TAG_IDENT_USE) {
+       if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_USE)) {
                struct unallocSpaceEntry *use =
                        (struct unallocSpaceEntry *)bh->b_data;
 
-               use->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
-               memcpy(bh->b_data + sizeof(struct unallocSpaceEntry), UDF_I_DATA(inode),
-                      inode->i_sb->s_blocksize - sizeof(struct unallocSpaceEntry));
-               crclen = sizeof(struct unallocSpaceEntry) + UDF_I_LENALLOC(inode) - sizeof(tag);
-               use->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
+               use->lengthAllocDescs = cpu_to_le32(iinfo->i_lenAlloc);
+               memcpy(bh->b_data + sizeof(struct unallocSpaceEntry),
+                      iinfo->i_ext.i_data, inode->i_sb->s_blocksize -
+                                       sizeof(struct unallocSpaceEntry));
+               crclen = sizeof(struct unallocSpaceEntry) +
+                               iinfo->i_lenAlloc - sizeof(tag);
+               use->descTag.tagLocation = cpu_to_le32(
+                                               iinfo->i_location.
+                                                       logicalBlockNum);
                use->descTag.descCRCLength = cpu_to_le16(crclen);
-               use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use + sizeof(tag), crclen, 0));
-
-               use->descTag.tagChecksum = 0;
-               for (i = 0; i < 16; i++) {
-                       if (i != 4)
-                               use->descTag.tagChecksum += ((uint8_t *)&(use->descTag))[i];
-               }
+               use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use +
+                                                          sizeof(tag), crclen,
+                                                          0));
+               use->descTag.tagChecksum = udf_tag_checksum(&use->descTag);
 
                mark_buffer_dirty(bh);
                brelse(bh);
@@ -1398,14 +1508,14 @@ static int udf_update_inode(struct inode *inode, int do_sync)
        else
                fe->gid = cpu_to_le32(inode->i_gid);
 
-       udfperms =      ((inode->i_mode & S_IRWXO)     ) |
-                       ((inode->i_mode & S_IRWXG) << 2) |
-                       ((inode->i_mode & S_IRWXU) << 4);
+       udfperms = ((inode->i_mode & S_IRWXO)) |
+                  ((inode->i_mode & S_IRWXG) << 2) |
+                  ((inode->i_mode & S_IRWXU) << 4);
 
-       udfperms |=     (le32_to_cpu(fe->permissions) &
-                       (FE_PERM_O_DELETE | FE_PERM_O_CHATTR |
-                        FE_PERM_G_DELETE | FE_PERM_G_CHATTR |
-                        FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
+       udfperms |= (le32_to_cpu(fe->permissions) &
+                   (FE_PERM_O_DELETE | FE_PERM_O_CHATTR |
+                    FE_PERM_G_DELETE | FE_PERM_G_CHATTR |
+                    FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
        fe->permissions = cpu_to_le32(udfperms);
 
        if (S_ISDIR(inode->i_mode))
@@ -1426,8 +1536,9 @@ static int udf_update_inode(struct inode *inode, int do_sync)
                                                     sizeof(regid), 12, 0x3);
                        dsea->attrType = cpu_to_le32(12);
                        dsea->attrSubtype = 1;
-                       dsea->attrLength = cpu_to_le32(sizeof(struct deviceSpec) +
-                                                      sizeof(regid));
+                       dsea->attrLength = cpu_to_le32(
+                                               sizeof(struct deviceSpec) +
+                                               sizeof(regid));
                        dsea->impUseLength = cpu_to_le32(sizeof(regid));
                }
                eid = (regid *)dsea->impUse;
@@ -1439,12 +1550,13 @@ static int udf_update_inode(struct inode *inode, int do_sync)
                dsea->minorDeviceIdent = cpu_to_le32(iminor(inode));
        }
 
-       if (UDF_I_EFE(inode) == 0) {
-               memcpy(bh->b_data + sizeof(struct fileEntry), UDF_I_DATA(inode),
+       if (iinfo->i_efe == 0) {
+               memcpy(bh->b_data + sizeof(struct fileEntry),
+                      iinfo->i_ext.i_data,
                       inode->i_sb->s_blocksize - sizeof(struct fileEntry));
                fe->logicalBlocksRecorded = cpu_to_le64(
-                       (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >>
-                       (inode->i_sb->s_blocksize_bits - 9));
+                       (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
+                       (blocksize_bits - 9));
 
                if (udf_time_to_stamp(&cpu_time, inode->i_atime))
                        fe->accessTime = cpu_to_lets(cpu_time);
@@ -1456,40 +1568,41 @@ static int udf_update_inode(struct inode *inode, int do_sync)
                strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
                fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
                fe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
-               fe->uniqueID = cpu_to_le64(UDF_I_UNIQUE(inode));
-               fe->lengthExtendedAttr = cpu_to_le32(UDF_I_LENEATTR(inode));
-               fe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
+               fe->uniqueID = cpu_to_le64(iinfo->i_unique);
+               fe->lengthExtendedAttr = cpu_to_le32(iinfo->i_lenEAttr);
+               fe->lengthAllocDescs = cpu_to_le32(iinfo->i_lenAlloc);
                fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE);
                crclen = sizeof(struct fileEntry);
        } else {
-               memcpy(bh->b_data + sizeof(struct extendedFileEntry), UDF_I_DATA(inode),
-                      inode->i_sb->s_blocksize - sizeof(struct extendedFileEntry));
+               memcpy(bh->b_data + sizeof(struct extendedFileEntry),
+                      iinfo->i_ext.i_data,
+                      inode->i_sb->s_blocksize -
+                                       sizeof(struct extendedFileEntry));
                efe->objectSize = cpu_to_le64(inode->i_size);
                efe->logicalBlocksRecorded = cpu_to_le64(
-                       (inode->i_blocks + (1 << (inode->i_sb->s_blocksize_bits - 9)) - 1) >>
-                       (inode->i_sb->s_blocksize_bits - 9));
+                       (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
+                       (blocksize_bits - 9));
 
-               if (UDF_I_CRTIME(inode).tv_sec > inode->i_atime.tv_sec ||
-                   (UDF_I_CRTIME(inode).tv_sec == inode->i_atime.tv_sec &&
-                    UDF_I_CRTIME(inode).tv_nsec > inode->i_atime.tv_nsec)) {
-                       UDF_I_CRTIME(inode) = inode->i_atime;
-               }
-               if (UDF_I_CRTIME(inode).tv_sec > inode->i_mtime.tv_sec ||
-                   (UDF_I_CRTIME(inode).tv_sec == inode->i_mtime.tv_sec &&
-                    UDF_I_CRTIME(inode).tv_nsec > inode->i_mtime.tv_nsec)) {
-                       UDF_I_CRTIME(inode) = inode->i_mtime;
-               }
-               if (UDF_I_CRTIME(inode).tv_sec > inode->i_ctime.tv_sec ||
-                   (UDF_I_CRTIME(inode).tv_sec == inode->i_ctime.tv_sec &&
-                    UDF_I_CRTIME(inode).tv_nsec > inode->i_ctime.tv_nsec)) {
-                       UDF_I_CRTIME(inode) = inode->i_ctime;
-               }
+               if (iinfo->i_crtime.tv_sec > inode->i_atime.tv_sec ||
+                   (iinfo->i_crtime.tv_sec == inode->i_atime.tv_sec &&
+                    iinfo->i_crtime.tv_nsec > inode->i_atime.tv_nsec))
+                       iinfo->i_crtime = inode->i_atime;
+
+               if (iinfo->i_crtime.tv_sec > inode->i_mtime.tv_sec ||
+                   (iinfo->i_crtime.tv_sec == inode->i_mtime.tv_sec &&
+                    iinfo->i_crtime.tv_nsec > inode->i_mtime.tv_nsec))
+                       iinfo->i_crtime = inode->i_mtime;
+
+               if (iinfo->i_crtime.tv_sec > inode->i_ctime.tv_sec ||
+                   (iinfo->i_crtime.tv_sec == inode->i_ctime.tv_sec &&
+                    iinfo->i_crtime.tv_nsec > inode->i_ctime.tv_nsec))
+                       iinfo->i_crtime = inode->i_ctime;
 
                if (udf_time_to_stamp(&cpu_time, inode->i_atime))
                        efe->accessTime = cpu_to_lets(cpu_time);
                if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
                        efe->modificationTime = cpu_to_lets(cpu_time);
-               if (udf_time_to_stamp(&cpu_time, UDF_I_CRTIME(inode)))
+               if (udf_time_to_stamp(&cpu_time, iinfo->i_crtime))
                        efe->createTime = cpu_to_lets(cpu_time);
                if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
                        efe->attrTime = cpu_to_lets(cpu_time);
@@ -1498,13 +1611,13 @@ static int udf_update_inode(struct inode *inode, int do_sync)
                strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
                efe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
                efe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
-               efe->uniqueID = cpu_to_le64(UDF_I_UNIQUE(inode));
-               efe->lengthExtendedAttr = cpu_to_le32(UDF_I_LENEATTR(inode));
-               efe->lengthAllocDescs = cpu_to_le32(UDF_I_LENALLOC(inode));
+               efe->uniqueID = cpu_to_le64(iinfo->i_unique);
+               efe->lengthExtendedAttr = cpu_to_le32(iinfo->i_lenEAttr);
+               efe->lengthAllocDescs = cpu_to_le32(iinfo->i_lenAlloc);
                efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE);
                crclen = sizeof(struct extendedFileEntry);
        }
-       if (UDF_I_STRAT4096(inode)) {
+       if (iinfo->i_strat4096) {
                fe->icbTag.strategyType = cpu_to_le16(4096);
                fe->icbTag.strategyParameter = cpu_to_le16(1);
                fe->icbTag.numEntries = cpu_to_le16(2);
@@ -1528,7 +1641,7 @@ static int udf_update_inode(struct inode *inode, int do_sync)
        else if (S_ISSOCK(inode->i_mode))
                fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET;
 
-       icbflags =      UDF_I_ALLOCTYPE(inode) |
+       icbflags =      iinfo->i_alloc_type |
                        ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) |
                        ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) |
                        ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) |
@@ -1537,29 +1650,28 @@ static int udf_update_inode(struct inode *inode, int do_sync)
                                ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY));
 
        fe->icbTag.flags = cpu_to_le16(icbflags);
-       if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200)
+       if (sbi->s_udfrev >= 0x0200)
                fe->descTag.descVersion = cpu_to_le16(3);
        else
                fe->descTag.descVersion = cpu_to_le16(2);
-       fe->descTag.tagSerialNum = cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb));
-       fe->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
-       crclen += UDF_I_LENEATTR(inode) + UDF_I_LENALLOC(inode) - sizeof(tag);
+       fe->descTag.tagSerialNum = cpu_to_le16(sbi->s_serial_number);
+       fe->descTag.tagLocation = cpu_to_le32(
+                                       iinfo->i_location.logicalBlockNum);
+       crclen += iinfo->i_lenEAttr + iinfo->i_lenAlloc -
+                                                               sizeof(tag);
        fe->descTag.descCRCLength = cpu_to_le16(crclen);
-       fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag), crclen, 0));
-
-       fe->descTag.tagChecksum = 0;
-       for (i = 0; i < 16; i++) {
-               if (i != 4)
-                       fe->descTag.tagChecksum += ((uint8_t *)&(fe->descTag))[i];
-       }
+       fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag),
+                                                 crclen, 0));
+       fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag);
 
        /* write the data blocks */
        mark_buffer_dirty(bh);
        if (do_sync) {
                sync_dirty_buffer(bh);
                if (buffer_req(bh) && !buffer_uptodate(bh)) {
-                       printk("IO error syncing udf inode [%s:%08lx]\n",
-                              inode->i_sb->s_id, inode->i_ino);
+                       printk(KERN_WARNING "IO error syncing udf inode "
+                               "[%s:%08lx]\n", inode->i_sb->s_id,
+                               inode->i_ino);
                        err = -EIO;
                }
        }
@@ -1577,7 +1689,7 @@ struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
                return NULL;
 
        if (inode->i_state & I_NEW) {
-               memcpy(&UDF_I_LOCATION(inode), &ino, sizeof(kernel_lb_addr));
+               memcpy(&UDF_I(inode)->i_location, &ino, sizeof(kernel_lb_addr));
                __udf_read_inode(inode);
                unlock_new_inode(inode);
        }
@@ -1585,7 +1697,8 @@ struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
        if (is_bad_inode(inode))
                goto out_iput;
 
-       if (ino.logicalBlockNum >= UDF_SB_PARTLEN(sb, ino.partitionReferenceNum)) {
+       if (ino.logicalBlockNum >= UDF_SB(sb)->
+                       s_partmaps[ino.partitionReferenceNum].s_partition_len) {
                udf_debug("block=%d, partition=%d out of range\n",
                          ino.logicalBlockNum, ino.partitionReferenceNum);
                make_bad_inode(inode);
@@ -1599,7 +1712,7 @@ struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
        return NULL;
 }
 
-int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
+int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
                    kernel_lb_addr eloc, uint32_t elen, int inc)
 {
        int adsize;
@@ -1608,15 +1721,18 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
        struct allocExtDesc *aed;
        int8_t etype;
        uint8_t *ptr;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
        if (!epos->bh)
-               ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
+               ptr = iinfo->i_ext.i_data + epos->offset -
+                       udf_file_entry_alloc_offset(inode) +
+                       iinfo->i_lenEAttr;
        else
                ptr = epos->bh->b_data + epos->offset;
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                adsize = sizeof(short_ad);
-       else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
+       else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                adsize = sizeof(long_ad);
        else
                return -1;
@@ -1627,15 +1743,16 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
                int err, loffset;
                kernel_lb_addr obloc = epos->block;
 
-               if (!(epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL,
-                                                                 obloc.partitionReferenceNum,
-                                                                 obloc.logicalBlockNum, &err))) {
+               epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL,
+                                               obloc.partitionReferenceNum,
+                                               obloc.logicalBlockNum, &err);
+               if (!epos->block.logicalBlockNum)
                        return -1;
-               }
-               if (!(nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb,
-                                                                      epos->block, 0)))) {
+               nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb,
+                                                                epos->block,
+                                                                0));
+               if (!nbh)
                        return -1;
-               }
                lock_buffer(nbh);
                memset(nbh->b_data, 0x00, inode->i_sb->s_blocksize);
                set_buffer_uptodate(nbh);
@@ -1644,7 +1761,8 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
 
                aed = (struct allocExtDesc *)(nbh->b_data);
                if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
-                       aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum);
+                       aed->previousAllocExtLocation =
+                                       cpu_to_le32(obloc.logicalBlockNum);
                if (epos->offset + adsize > inode->i_sb->s_blocksize) {
                        loffset = epos->offset;
                        aed->lengthAllocDescs = cpu_to_le32(adsize);
@@ -1661,24 +1779,26 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
                        if (epos->bh) {
                                aed = (struct allocExtDesc *)epos->bh->b_data;
                                aed->lengthAllocDescs =
-                                       cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
+                                       cpu_to_le32(le32_to_cpu(
+                                       aed->lengthAllocDescs) + adsize);
                        } else {
-                               UDF_I_LENALLOC(inode) += adsize;
+                               iinfo->i_lenAlloc += adsize;
                                mark_inode_dirty(inode);
                        }
                }
-               if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200)
+               if (UDF_SB(inode->i_sb)->s_udfrev >= 0x0200)
                        udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
                                    epos->block.logicalBlockNum, sizeof(tag));
                else
                        udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
                                    epos->block.logicalBlockNum, sizeof(tag));
-               switch (UDF_I_ALLOCTYPE(inode)) {
+               switch (iinfo->i_alloc_type) {
                case ICBTAG_FLAG_AD_SHORT:
                        sad = (short_ad *)sptr;
                        sad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
                                                     inode->i_sb->s_blocksize);
-                       sad->extPosition = cpu_to_le32(epos->block.logicalBlockNum);
+                       sad->extPosition =
+                               cpu_to_le32(epos->block.logicalBlockNum);
                        break;
                case ICBTAG_FLAG_AD_LONG:
                        lad = (long_ad *)sptr;
@@ -1690,10 +1810,11 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
                }
                if (epos->bh) {
                        if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
-                           UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
+                           UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
                                udf_update_tag(epos->bh->b_data, loffset);
                        else
-                               udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc));
+                               udf_update_tag(epos->bh->b_data,
+                                               sizeof(struct allocExtDesc));
                        mark_buffer_dirty_inode(epos->bh, inode);
                        brelse(epos->bh);
                } else {
@@ -1705,36 +1826,43 @@ int8_t udf_add_aext(struct inode * inode, struct extent_position * epos,
        etype = udf_write_aext(inode, epos, eloc, elen, inc);
 
        if (!epos->bh) {
-               UDF_I_LENALLOC(inode) += adsize;
+               iinfo->i_lenAlloc += adsize;
                mark_inode_dirty(inode);
        } else {
                aed = (struct allocExtDesc *)epos->bh->b_data;
                aed->lengthAllocDescs =
-                       cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize);
-               if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) || UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
-                       udf_update_tag(epos->bh->b_data, epos->offset + (inc ? 0 : adsize));
+                       cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) +
+                                   adsize);
+               if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
+                               UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
+                       udf_update_tag(epos->bh->b_data,
+                                       epos->offset + (inc ? 0 : adsize));
                else
-                       udf_update_tag(epos->bh->b_data, sizeof(struct allocExtDesc));
+                       udf_update_tag(epos->bh->b_data,
+                                       sizeof(struct allocExtDesc));
                mark_buffer_dirty_inode(epos->bh, inode);
        }
 
        return etype;
 }
 
-int8_t udf_write_aext(struct inode * inode, struct extent_position * epos,
+int8_t udf_write_aext(struct inode *inode, struct extent_position *epos,
                      kernel_lb_addr eloc, uint32_t elen, int inc)
 {
        int adsize;
        uint8_t *ptr;
        short_ad *sad;
        long_ad *lad;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
        if (!epos->bh)
-               ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
+               ptr = iinfo->i_ext.i_data + epos->offset -
+                       udf_file_entry_alloc_offset(inode) +
+                       iinfo->i_lenEAttr;
        else
                ptr = epos->bh->b_data + epos->offset;
 
-       switch (UDF_I_ALLOCTYPE(inode)) {
+       switch (iinfo->i_alloc_type) {
        case ICBTAG_FLAG_AD_SHORT:
                sad = (short_ad *)ptr;
                sad->extLength = cpu_to_le32(elen);
@@ -1754,10 +1882,12 @@ int8_t udf_write_aext(struct inode * inode, struct extent_position * epos,
 
        if (epos->bh) {
                if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
-                   UDF_SB_UDFREV(inode->i_sb) >= 0x0201) {
-                       struct allocExtDesc *aed = (struct allocExtDesc *)epos->bh->b_data;
+                   UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) {
+                       struct allocExtDesc *aed =
+                               (struct allocExtDesc *)epos->bh->b_data;
                        udf_update_tag(epos->bh->b_data,
-                                      le32_to_cpu(aed->lengthAllocDescs) + sizeof(struct allocExtDesc));
+                                      le32_to_cpu(aed->lengthAllocDescs) +
+                                      sizeof(struct allocExtDesc));
                }
                mark_buffer_dirty_inode(epos->bh, inode);
        } else {
@@ -1770,19 +1900,21 @@ int8_t udf_write_aext(struct inode * inode, struct extent_position * epos,
        return (elen >> 30);
 }
 
-int8_t udf_next_aext(struct inode * inode, struct extent_position * epos,
-                    kernel_lb_addr * eloc, uint32_t * elen, int inc)
+int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
+                    kernel_lb_addr *eloc, uint32_t *elen, int inc)
 {
        int8_t etype;
 
        while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) ==
               (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
+               int block;
                epos->block = *eloc;
                epos->offset = sizeof(struct allocExtDesc);
                brelse(epos->bh);
-               if (!(epos->bh = udf_tread(inode->i_sb, udf_get_lb_pblock(inode->i_sb, epos->block, 0)))) {
-                       udf_debug("reading block %d failed!\n",
-                                 udf_get_lb_pblock(inode->i_sb, epos->block, 0));
+               block = udf_get_lb_pblock(inode->i_sb, epos->block, 0);
+               epos->bh = udf_tread(inode->i_sb, block);
+               if (!epos->bh) {
+                       udf_debug("reading block %d failed!\n", block);
                        return -1;
                }
        }
@@ -1790,47 +1922,55 @@ int8_t udf_next_aext(struct inode * inode, struct extent_position * epos,
        return etype;
 }
 
-int8_t udf_current_aext(struct inode * inode, struct extent_position * epos,
-                       kernel_lb_addr * eloc, uint32_t * elen, int inc)
+int8_t udf_current_aext(struct inode *inode, struct extent_position *epos,
+                       kernel_lb_addr *eloc, uint32_t *elen, int inc)
 {
        int alen;
        int8_t etype;
        uint8_t *ptr;
        short_ad *sad;
        long_ad *lad;
-
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
        if (!epos->bh) {
                if (!epos->offset)
                        epos->offset = udf_file_entry_alloc_offset(inode);
-               ptr = UDF_I_DATA(inode) + epos->offset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode);
-               alen = udf_file_entry_alloc_offset(inode) + UDF_I_LENALLOC(inode);
+               ptr = iinfo->i_ext.i_data + epos->offset -
+                       udf_file_entry_alloc_offset(inode) +
+                       iinfo->i_lenEAttr;
+               alen = udf_file_entry_alloc_offset(inode) +
+                                                       iinfo->i_lenAlloc;
        } else {
                if (!epos->offset)
                        epos->offset = sizeof(struct allocExtDesc);
                ptr = epos->bh->b_data + epos->offset;
                alen = sizeof(struct allocExtDesc) +
-                       le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->lengthAllocDescs);
+                       le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->
+                                                       lengthAllocDescs);
        }
 
-       switch (UDF_I_ALLOCTYPE(inode)) {
+       switch (iinfo->i_alloc_type) {
        case ICBTAG_FLAG_AD_SHORT:
-               if (!(sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc)))
+               sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc);
+               if (!sad)
                        return -1;
                etype = le32_to_cpu(sad->extLength) >> 30;
                eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
-               eloc->partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;
+               eloc->partitionReferenceNum =
+                               iinfo->i_location.partitionReferenceNum;
                *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK;
                break;
        case ICBTAG_FLAG_AD_LONG:
-               if (!(lad = udf_get_filelongad(ptr, alen, &epos->offset, inc)))
+               lad = udf_get_filelongad(ptr, alen, &epos->offset, inc);
+               if (!lad)
                        return -1;
                etype = le32_to_cpu(lad->extLength) >> 30;
                *eloc = lelb_to_cpu(lad->extLocation);
                *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK;
                break;
        default:
-               udf_debug("alloc_type = %d unsupported\n", UDF_I_ALLOCTYPE(inode));
+               udf_debug("alloc_type = %d unsupported\n",
+                               iinfo->i_alloc_type);
                return -1;
        }
 
@@ -1858,22 +1998,24 @@ static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos,
        return (nelen >> 30);
 }
 
-int8_t udf_delete_aext(struct inode * inode, struct extent_position epos,
+int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
                       kernel_lb_addr eloc, uint32_t elen)
 {
        struct extent_position oepos;
        int adsize;
        int8_t etype;
        struct allocExtDesc *aed;
+       struct udf_inode_info *iinfo;
 
        if (epos.bh) {
                get_bh(epos.bh);
                get_bh(epos.bh);
        }
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
+       iinfo = UDF_I(inode);
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                adsize = sizeof(short_ad);
-       else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
+       else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                adsize = sizeof(long_ad);
        else
                adsize = 0;
@@ -1900,33 +2042,39 @@ int8_t udf_delete_aext(struct inode * inode, struct extent_position epos,
                udf_write_aext(inode, &oepos, eloc, elen, 1);
                udf_write_aext(inode, &oepos, eloc, elen, 1);
                if (!oepos.bh) {
-                       UDF_I_LENALLOC(inode) -= (adsize * 2);
+                       iinfo->i_lenAlloc -= (adsize * 2);
                        mark_inode_dirty(inode);
                } else {
                        aed = (struct allocExtDesc *)oepos.bh->b_data;
                        aed->lengthAllocDescs =
-                               cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - (2 * adsize));
+                               cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
+                                           (2 * adsize));
                        if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
-                           UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
-                               udf_update_tag(oepos.bh->b_data, oepos.offset - (2 * adsize));
+                           UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
+                               udf_update_tag(oepos.bh->b_data,
+                                               oepos.offset - (2 * adsize));
                        else
-                               udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc));
+                               udf_update_tag(oepos.bh->b_data,
+                                               sizeof(struct allocExtDesc));
                        mark_buffer_dirty_inode(oepos.bh, inode);
                }
        } else {
                udf_write_aext(inode, &oepos, eloc, elen, 1);
                if (!oepos.bh) {
-                       UDF_I_LENALLOC(inode) -= adsize;
+                       iinfo->i_lenAlloc -= adsize;
                        mark_inode_dirty(inode);
                } else {
                        aed = (struct allocExtDesc *)oepos.bh->b_data;
                        aed->lengthAllocDescs =
-                               cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) - adsize);
+                               cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
+                                           adsize);
                        if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
-                           UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
-                               udf_update_tag(oepos.bh->b_data, epos.offset - adsize);
+                           UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
+                               udf_update_tag(oepos.bh->b_data,
+                                               epos.offset - adsize);
                        else
-                               udf_update_tag(oepos.bh->b_data, sizeof(struct allocExtDesc));
+                               udf_update_tag(oepos.bh->b_data,
+                                               sizeof(struct allocExtDesc));
                        mark_buffer_dirty_inode(oepos.bh, inode);
                }
        }
@@ -1937,34 +2085,38 @@ int8_t udf_delete_aext(struct inode * inode, struct extent_position epos,
        return (elen >> 30);
 }
 
-int8_t inode_bmap(struct inode * inode, sector_t block,
-                 struct extent_position * pos, kernel_lb_addr * eloc,
-                 uint32_t * elen, sector_t * offset)
+int8_t inode_bmap(struct inode *inode, sector_t block,
+                 struct extent_position *pos, kernel_lb_addr *eloc,
+                 uint32_t *elen, sector_t *offset)
 {
+       unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
        loff_t lbcount = 0, bcount =
-           (loff_t) block << inode->i_sb->s_blocksize_bits;
+           (loff_t) block << blocksize_bits;
        int8_t etype;
+       struct udf_inode_info *iinfo;
 
        if (block < 0) {
                printk(KERN_ERR "udf: inode_bmap: block < 0\n");
                return -1;
        }
 
+       iinfo = UDF_I(inode);
        pos->offset = 0;
-       pos->block = UDF_I_LOCATION(inode);
+       pos->block = iinfo->i_location;
        pos->bh = NULL;
        *elen = 0;
 
        do {
-               if ((etype = udf_next_aext(inode, pos, eloc, elen, 1)) == -1) {
-                       *offset = (bcount - lbcount) >> inode->i_sb->s_blocksize_bits;
-                       UDF_I_LENEXTENTS(inode) = lbcount;
+               etype = udf_next_aext(inode, pos, eloc, elen, 1);
+               if (etype == -1) {
+                       *offset = (bcount - lbcount) >> blocksize_bits;
+                       iinfo->i_lenExtents = lbcount;
                        return -1;
                }
                lbcount += *elen;
        } while (lbcount <= bcount);
 
-       *offset = (bcount + *elen - lbcount) >> inode->i_sb->s_blocksize_bits;
+       *offset = (bcount + *elen - lbcount) >> blocksize_bits;
 
        return etype;
 }
@@ -1979,7 +2131,8 @@ long udf_block_map(struct inode *inode, sector_t block)
 
        lock_kernel();
 
-       if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30))
+       if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) ==
+                                               (EXT_RECORDED_ALLOCATED >> 30))
                ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
        else
                ret = 0;
index 15297deb5051022fbc31c877aa2b6f7d525bd348..a1d6da0caf7132121e7b5d69ea880aeeb97d1875 100644 (file)
@@ -51,18 +51,18 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
        uint8_t *ea = NULL, *ad = NULL;
        int offset;
        uint16_t crclen;
-       int i;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
-       ea = UDF_I_DATA(inode);
-       if (UDF_I_LENEATTR(inode)) {
-               ad = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode);
+       ea = iinfo->i_ext.i_data;
+       if (iinfo->i_lenEAttr) {
+               ad = iinfo->i_ext.i_data + iinfo->i_lenEAttr;
        } else {
                ad = ea;
                size += sizeof(struct extendedAttrHeaderDesc);
        }
 
        offset = inode->i_sb->s_blocksize - udf_file_entry_alloc_offset(inode) -
-               UDF_I_LENALLOC(inode);
+               iinfo->i_lenAlloc;
 
        /* TODO - Check for FreeEASpace */
 
@@ -70,69 +70,80 @@ struct genericFormat *udf_add_extendedattr(struct inode *inode, uint32_t size,
                struct extendedAttrHeaderDesc *eahd;
                eahd = (struct extendedAttrHeaderDesc *)ea;
 
-               if (UDF_I_LENALLOC(inode)) {
-                       memmove(&ad[size], ad, UDF_I_LENALLOC(inode));
-               }
+               if (iinfo->i_lenAlloc)
+                       memmove(&ad[size], ad, iinfo->i_lenAlloc);
 
-               if (UDF_I_LENEATTR(inode)) {
+               if (iinfo->i_lenEAttr) {
                        /* check checksum/crc */
-                       if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD ||
-                           le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) {
+                       if (eahd->descTag.tagIdent !=
+                                       cpu_to_le16(TAG_IDENT_EAHD) ||
+                           le32_to_cpu(eahd->descTag.tagLocation) !=
+                                       iinfo->i_location.logicalBlockNum)
                                return NULL;
-                       }
                } else {
+                       struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
+
                        size -= sizeof(struct extendedAttrHeaderDesc);
-                       UDF_I_LENEATTR(inode) += sizeof(struct extendedAttrHeaderDesc);
+                       iinfo->i_lenEAttr +=
+                               sizeof(struct extendedAttrHeaderDesc);
                        eahd->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EAHD);
-                       if (UDF_SB_UDFREV(inode->i_sb) >= 0x0200)
+                       if (sbi->s_udfrev >= 0x0200)
                                eahd->descTag.descVersion = cpu_to_le16(3);
                        else
                                eahd->descTag.descVersion = cpu_to_le16(2);
-                       eahd->descTag.tagSerialNum = cpu_to_le16(UDF_SB_SERIALNUM(inode->i_sb));
-                       eahd->descTag.tagLocation = cpu_to_le32(UDF_I_LOCATION(inode).logicalBlockNum);
+                       eahd->descTag.tagSerialNum =
+                                       cpu_to_le16(sbi->s_serial_number);
+                       eahd->descTag.tagLocation = cpu_to_le32(
+                                       iinfo->i_location.logicalBlockNum);
                        eahd->impAttrLocation = cpu_to_le32(0xFFFFFFFF);
                        eahd->appAttrLocation = cpu_to_le32(0xFFFFFFFF);
                }
 
-               offset = UDF_I_LENEATTR(inode);
+               offset = iinfo->i_lenEAttr;
                if (type < 2048) {
-                       if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) {
-                               uint32_t aal = le32_to_cpu(eahd->appAttrLocation);
+                       if (le32_to_cpu(eahd->appAttrLocation) <
+                                       iinfo->i_lenEAttr) {
+                               uint32_t aal =
+                                       le32_to_cpu(eahd->appAttrLocation);
                                memmove(&ea[offset - aal + size],
                                        &ea[aal], offset - aal);
                                offset -= aal;
-                               eahd->appAttrLocation = cpu_to_le32(aal + size);
+                               eahd->appAttrLocation =
+                                               cpu_to_le32(aal + size);
                        }
-                       if (le32_to_cpu(eahd->impAttrLocation) < UDF_I_LENEATTR(inode)) {
-                               uint32_t ial = le32_to_cpu(eahd->impAttrLocation);
+                       if (le32_to_cpu(eahd->impAttrLocation) <
+                                       iinfo->i_lenEAttr) {
+                               uint32_t ial =
+                                       le32_to_cpu(eahd->impAttrLocation);
                                memmove(&ea[offset - ial + size],
                                        &ea[ial], offset - ial);
                                offset -= ial;
-                               eahd->impAttrLocation = cpu_to_le32(ial + size);
+                               eahd->impAttrLocation =
+                                               cpu_to_le32(ial + size);
                        }
                } else if (type < 65536) {
-                       if (le32_to_cpu(eahd->appAttrLocation) < UDF_I_LENEATTR(inode)) {
-                               uint32_t aal = le32_to_cpu(eahd->appAttrLocation);
+                       if (le32_to_cpu(eahd->appAttrLocation) <
+                                       iinfo->i_lenEAttr) {
+                               uint32_t aal =
+                                       le32_to_cpu(eahd->appAttrLocation);
                                memmove(&ea[offset - aal + size],
                                        &ea[aal], offset - aal);
                                offset -= aal;
-                               eahd->appAttrLocation = cpu_to_le32(aal + size);
+                               eahd->appAttrLocation =
+                                               cpu_to_le32(aal + size);
                        }
                }
                /* rewrite CRC + checksum of eahd */
                crclen = sizeof(struct extendedAttrHeaderDesc) - sizeof(tag);
                eahd->descTag.descCRCLength = cpu_to_le16(crclen);
                eahd->descTag.descCRC = cpu_to_le16(udf_crc((char *)eahd +
-                                                           sizeof(tag), crclen, 0));
-               eahd->descTag.tagChecksum = 0;
-               for (i = 0; i < 16; i++)
-                       if (i != 4)
-                               eahd->descTag.tagChecksum += ((uint8_t *)&(eahd->descTag))[i];
-               UDF_I_LENEATTR(inode) += size;
+                                               sizeof(tag), crclen, 0));
+               eahd->descTag.tagChecksum = udf_tag_checksum(&eahd->descTag);
+               iinfo->i_lenEAttr += size;
                return (struct genericFormat *)&ea[offset];
        }
-       if (loc & 0x02) {
-       }
+       if (loc & 0x02)
+               ;
 
        return NULL;
 }
@@ -143,18 +154,20 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
        struct genericFormat *gaf;
        uint8_t *ea = NULL;
        uint32_t offset;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
-       ea = UDF_I_DATA(inode);
+       ea = iinfo->i_ext.i_data;
 
-       if (UDF_I_LENEATTR(inode)) {
+       if (iinfo->i_lenEAttr) {
                struct extendedAttrHeaderDesc *eahd;
                eahd = (struct extendedAttrHeaderDesc *)ea;
 
                /* check checksum/crc */
-               if (le16_to_cpu(eahd->descTag.tagIdent) != TAG_IDENT_EAHD ||
-                   le32_to_cpu(eahd->descTag.tagLocation) != UDF_I_LOCATION(inode).logicalBlockNum) {
+               if (eahd->descTag.tagIdent !=
+                               cpu_to_le16(TAG_IDENT_EAHD) ||
+                   le32_to_cpu(eahd->descTag.tagLocation) !=
+                               iinfo->i_location.logicalBlockNum)
                        return NULL;
-               }
 
                if (type < 2048)
                        offset = sizeof(struct extendedAttrHeaderDesc);
@@ -163,9 +176,10 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
                else
                        offset = le32_to_cpu(eahd->appAttrLocation);
 
-               while (offset < UDF_I_LENEATTR(inode)) {
+               while (offset < iinfo->i_lenEAttr) {
                        gaf = (struct genericFormat *)&ea[offset];
-                       if (le32_to_cpu(gaf->attrType) == type && gaf->attrSubtype == subtype)
+                       if (le32_to_cpu(gaf->attrType) == type &&
+                                       gaf->attrSubtype == subtype)
                                return gaf;
                        else
                                offset += le32_to_cpu(gaf->attrLength);
@@ -186,21 +200,20 @@ struct genericFormat *udf_get_extendedattr(struct inode *inode, uint32_t type,
  *     Written, tested, and released.
  */
 struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
-                                   uint32_t location, uint16_t * ident)
+                                   uint32_t location, uint16_t *ident)
 {
        tag *tag_p;
        struct buffer_head *bh = NULL;
-       register uint8_t checksum;
-       register int i;
+       struct udf_sb_info *sbi = UDF_SB(sb);
 
        /* Read the block */
        if (block == 0xFFFFFFFF)
                return NULL;
 
-       bh = udf_tread(sb, block + UDF_SB_SESSION(sb));
+       bh = udf_tread(sb, block + sbi->s_session);
        if (!bh) {
                udf_debug("block=%d, location=%d: read failed\n",
-                         block + UDF_SB_SESSION(sb), location);
+                         block + sbi->s_session, location);
                return NULL;
        }
 
@@ -210,24 +223,20 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
 
        if (location != le32_to_cpu(tag_p->tagLocation)) {
                udf_debug("location mismatch block %u, tag %u != %u\n",
-                         block + UDF_SB_SESSION(sb), le32_to_cpu(tag_p->tagLocation), location);
+                         block + sbi->s_session,
+                         le32_to_cpu(tag_p->tagLocation), location);
                goto error_out;
        }
 
        /* Verify the tag checksum */
-       checksum = 0U;
-       for (i = 0; i < 4; i++)
-               checksum += (uint8_t)(bh->b_data[i]);
-       for (i = 5; i < 16; i++)
-               checksum += (uint8_t)(bh->b_data[i]);
-       if (checksum != tag_p->tagChecksum) {
+       if (udf_tag_checksum(tag_p) != tag_p->tagChecksum) {
                printk(KERN_ERR "udf: tag checksum failed block %d\n", block);
                goto error_out;
        }
 
        /* Verify the tag version */
-       if (le16_to_cpu(tag_p->descVersion) != 0x0002U &&
-           le16_to_cpu(tag_p->descVersion) != 0x0003U) {
+       if (tag_p->descVersion != cpu_to_le16(0x0002U) &&
+           tag_p->descVersion != cpu_to_le16(0x0003U)) {
                udf_debug("tag version 0x%04x != 0x0002 || 0x0003 block %d\n",
                          le16_to_cpu(tag_p->descVersion), block);
                goto error_out;
@@ -236,11 +245,11 @@ struct buffer_head *udf_read_tagged(struct super_block *sb, uint32_t block,
        /* Verify the descriptor CRC */
        if (le16_to_cpu(tag_p->descCRCLength) + sizeof(tag) > sb->s_blocksize ||
            le16_to_cpu(tag_p->descCRC) == udf_crc(bh->b_data + sizeof(tag),
-                                                  le16_to_cpu(tag_p->descCRCLength), 0)) {
+                                       le16_to_cpu(tag_p->descCRCLength), 0))
                return bh;
-       }
+
        udf_debug("Crc failure block %d: crc = %d, crclen = %d\n",
-                 block + UDF_SB_SESSION(sb), le16_to_cpu(tag_p->descCRC),
+                 block + sbi->s_session, le16_to_cpu(tag_p->descCRC),
                  le16_to_cpu(tag_p->descCRCLength));
 
 error_out:
@@ -249,7 +258,7 @@ error_out:
 }
 
 struct buffer_head *udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc,
-                                    uint32_t offset, uint16_t * ident)
+                                    uint32_t offset, uint16_t *ident)
 {
        return udf_read_tagged(sb, udf_get_lb_pblock(sb, loc, offset),
                               loc.logicalBlockNum + offset, ident);
@@ -258,17 +267,11 @@ struct buffer_head *udf_read_ptagged(struct super_block *sb, kernel_lb_addr loc,
 void udf_update_tag(char *data, int length)
 {
        tag *tptr = (tag *)data;
-       int i;
-
        length -= sizeof(tag);
 
-       tptr->tagChecksum = 0;
        tptr->descCRCLength = cpu_to_le16(length);
        tptr->descCRC = cpu_to_le16(udf_crc(data + sizeof(tag), length, 0));
-
-       for (i = 0; i < 16; i++)
-               if (i != 4)
-                       tptr->tagChecksum += (uint8_t)(data[i]);
+       tptr->tagChecksum = udf_tag_checksum(tptr);
 }
 
 void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
@@ -281,3 +284,14 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
        tptr->tagLocation = cpu_to_le32(loc);
        udf_update_tag(data, length);
 }
+
+u8 udf_tag_checksum(const tag *t)
+{
+       u8 *data = (u8 *)t;
+       u8 checksum = 0;
+       int i;
+       for (i = 0; i < sizeof(tag); ++i)
+               if (i != 4) /* position of checksum */
+                       checksum += data[i];
+       return checksum;
+}
index bec96a6b3343c8586fa30823673fb8f8db32cbe7..112a5fb0b27ba201285e71593ccda10323277516 100644 (file)
@@ -43,12 +43,10 @@ static inline int udf_match(int len1, const char *name1, int len2,
 
 int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
                 struct fileIdentDesc *sfi, struct udf_fileident_bh *fibh,
-                uint8_t * impuse, uint8_t * fileident)
+                uint8_t *impuse, uint8_t *fileident)
 {
        uint16_t crclen = fibh->eoffset - fibh->soffset - sizeof(tag);
        uint16_t crc;
-       uint8_t checksum = 0;
-       int i;
        int offset;
        uint16_t liu = le16_to_cpu(cfi->lengthOfImpUse);
        uint8_t lfi = cfi->lengthFileIdent;
@@ -56,7 +54,7 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
                sizeof(struct fileIdentDesc);
        int adinicb = 0;
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
+       if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
                adinicb = 1;
 
        offset = fibh->soffset + sizeof(struct fileIdentDesc);
@@ -68,7 +66,8 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
                        memcpy(fibh->ebh->b_data + offset, impuse, liu);
                } else {
                        memcpy((uint8_t *)sfi->impUse, impuse, -offset);
-                       memcpy(fibh->ebh->b_data, impuse - offset, liu + offset);
+                       memcpy(fibh->ebh->b_data, impuse - offset,
+                               liu + offset);
                }
        }
 
@@ -80,8 +79,10 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
                } else if (offset >= 0) {
                        memcpy(fibh->ebh->b_data + offset, fileident, lfi);
                } else {
-                       memcpy((uint8_t *)sfi->fileIdent + liu, fileident, -offset);
-                       memcpy(fibh->ebh->b_data, fileident - offset, lfi + offset);
+                       memcpy((uint8_t *)sfi->fileIdent + liu, fileident,
+                               -offset);
+                       memcpy(fibh->ebh->b_data, fileident - offset,
+                               lfi + offset);
                }
        }
 
@@ -101,27 +102,29 @@ int udf_write_fi(struct inode *inode, struct fileIdentDesc *cfi,
 
        if (fibh->sbh == fibh->ebh) {
                crc = udf_crc((uint8_t *)sfi->impUse,
-                             crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc);
+                             crclen + sizeof(tag) -
+                             sizeof(struct fileIdentDesc), crc);
        } else if (sizeof(struct fileIdentDesc) >= -fibh->soffset) {
-               crc = udf_crc(fibh->ebh->b_data + sizeof(struct fileIdentDesc) + fibh->soffset,
-                             crclen + sizeof(tag) - sizeof(struct fileIdentDesc), crc);
+               crc = udf_crc(fibh->ebh->b_data +
+                                       sizeof(struct fileIdentDesc) +
+                                       fibh->soffset,
+                             crclen + sizeof(tag) -
+                                       sizeof(struct fileIdentDesc),
+                             crc);
        } else {
                crc = udf_crc((uint8_t *)sfi->impUse,
-                             -fibh->soffset - sizeof(struct fileIdentDesc), crc);
+                             -fibh->soffset - sizeof(struct fileIdentDesc),
+                             crc);
                crc = udf_crc(fibh->ebh->b_data, fibh->eoffset, crc);
        }
 
        cfi->descTag.descCRC = cpu_to_le16(crc);
        cfi->descTag.descCRCLength = cpu_to_le16(crclen);
+       cfi->descTag.tagChecksum = udf_tag_checksum(&cfi->descTag);
 
-       for (i = 0; i < 16; i++) {
-               if (i != 4)
-                       checksum += ((uint8_t *)&cfi->descTag)[i];
-       }
-
-       cfi->descTag.tagChecksum = checksum;
        if (adinicb || (sizeof(struct fileIdentDesc) <= -fibh->soffset)) {
-               memcpy((uint8_t *)sfi, (uint8_t *)cfi, sizeof(struct fileIdentDesc));
+               memcpy((uint8_t *)sfi, (uint8_t *)cfi,
+                       sizeof(struct fileIdentDesc));
        } else {
                memcpy((uint8_t *)sfi, (uint8_t *)cfi, -fibh->soffset);
                memcpy(fibh->ebh->b_data, (uint8_t *)cfi - fibh->soffset,
@@ -155,26 +158,28 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
        uint32_t elen;
        sector_t offset;
        struct extent_position epos = {};
+       struct udf_inode_info *dinfo = UDF_I(dir);
 
-       size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
-       f_pos = (udf_ext0_offset(dir) >> 2);
+       size = udf_ext0_offset(dir) + dir->i_size;
+       f_pos = udf_ext0_offset(dir);
 
-       fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
-       if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
+       fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
+       if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
                fibh->sbh = fibh->ebh = NULL;
-       } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
-                             &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) {
+       else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits,
+                             &epos, &eloc, &elen, &offset) ==
+                                       (EXT_RECORDED_ALLOCATED >> 30)) {
                block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
                if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
-                       if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
+                       if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                                epos.offset -= sizeof(short_ad);
-                       else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
+                       else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                                epos.offset -= sizeof(long_ad);
-               } else {
+               } else
                        offset = 0;
-               }
 
-               if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) {
+               fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
+               if (!fibh->sbh) {
                        brelse(epos.bh);
                        return NULL;
                }
@@ -183,7 +188,7 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
                return NULL;
        }
 
-       while ((f_pos < size)) {
+       while (f_pos < size) {
                fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc,
                                        &elen, &offset);
                if (!fi) {
@@ -202,14 +207,18 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
                } else {
                        int poffset;    /* Unpaded ending offset */
 
-                       poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi;
+                       poffset = fibh->soffset + sizeof(struct fileIdentDesc) +
+                                       liu + lfi;
 
-                       if (poffset >= lfi) {
-                               nameptr = (uint8_t *)(fibh->ebh->b_data + poffset - lfi);
-                       } else {
+                       if (poffset >= lfi)
+                               nameptr = (uint8_t *)(fibh->ebh->b_data +
+                                                     poffset - lfi);
+                       else {
                                nameptr = fname;
-                               memcpy(nameptr, fi->fileIdent + liu, lfi - poffset);
-                               memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset);
+                               memcpy(nameptr, fi->fileIdent + liu,
+                                       lfi - poffset);
+                               memcpy(nameptr + lfi - poffset,
+                                       fibh->ebh->b_data, poffset);
                        }
                }
 
@@ -226,11 +235,11 @@ static struct fileIdentDesc *udf_find_entry(struct inode *dir,
                if (!lfi)
                        continue;
 
-               if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi))) {
-                       if (udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) {
-                               brelse(epos.bh);
-                               return fi;
-                       }
+               flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
+               if (flen && udf_match(flen, fname, dentry->d_name.len,
+                                     dentry->d_name.name)) {
+                       brelse(epos.bh);
+                       return fi;
                }
        }
 
@@ -291,16 +300,16 @@ static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry,
        if (!strncmp(dentry->d_name.name, ".B=", 3)) {
                kernel_lb_addr lb = {
                        .logicalBlockNum = 0,
-                       .partitionReferenceNum = simple_strtoul(dentry->d_name.name + 3,
-                                                               NULL, 0),
+                       .partitionReferenceNum =
+                               simple_strtoul(dentry->d_name.name + 3,
+                                               NULL, 0),
                };
                inode = udf_iget(dir->i_sb, lb);
                if (!inode) {
                        unlock_kernel();
                        return ERR_PTR(-EACCES);
                }
-       }
-       else
+       } else
 #endif /* UDF_RECOVERY */
 
        if (udf_find_entry(dir, dentry, &fibh, &cfi)) {
@@ -325,14 +334,14 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
                                           struct udf_fileident_bh *fibh,
                                           struct fileIdentDesc *cfi, int *err)
 {
-       struct super_block *sb;
+       struct super_block *sb = dir->i_sb;
        struct fileIdentDesc *fi = NULL;
        char name[UDF_NAME_LEN], fname[UDF_NAME_LEN];
        int namelen;
        loff_t f_pos;
        int flen;
        char *nameptr;
-       loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
+       loff_t size = udf_ext0_offset(dir) + dir->i_size;
        int nfidlen;
        uint8_t lfi;
        uint16_t liu;
@@ -341,16 +350,16 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
        uint32_t elen;
        sector_t offset;
        struct extent_position epos = {};
-
-       sb = dir->i_sb;
+       struct udf_inode_info *dinfo;
 
        if (dentry) {
                if (!dentry->d_name.len) {
                        *err = -EINVAL;
                        return NULL;
                }
-               if (!(namelen = udf_put_filename(sb, dentry->d_name.name, name,
-                                                dentry->d_name.len))) {
+               namelen = udf_put_filename(sb, dentry->d_name.name, name,
+                                                dentry->d_name.len);
+               if (!namelen) {
                        *err = -ENAMETOOLONG;
                        return NULL;
                }
@@ -360,39 +369,40 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
 
        nfidlen = (sizeof(struct fileIdentDesc) + namelen + 3) & ~3;
 
-       f_pos = (udf_ext0_offset(dir) >> 2);
+       f_pos = udf_ext0_offset(dir);
 
-       fibh->soffset = fibh->eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
-       if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
+       fibh->soffset = fibh->eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
+       dinfo = UDF_I(dir);
+       if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
                fibh->sbh = fibh->ebh = NULL;
-       } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
-                             &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) {
+       else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits,
+                             &epos, &eloc, &elen, &offset) ==
+                                       (EXT_RECORDED_ALLOCATED >> 30)) {
                block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
                if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
-                       if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
+                       if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                                epos.offset -= sizeof(short_ad);
-                       else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
+                       else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                                epos.offset -= sizeof(long_ad);
-               } else {
+               } else
                        offset = 0;
-               }
 
-               if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block))) {
+               fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block);
+               if (!fibh->sbh) {
                        brelse(epos.bh);
                        *err = -EIO;
                        return NULL;
                }
 
-               block = UDF_I_LOCATION(dir).logicalBlockNum;
-
+               block = dinfo->i_location.logicalBlockNum;
        } else {
-               block = udf_get_lb_pblock(dir->i_sb, UDF_I_LOCATION(dir), 0);
+               block = udf_get_lb_pblock(dir->i_sb, dinfo->i_location, 0);
                fibh->sbh = fibh->ebh = NULL;
                fibh->soffset = fibh->eoffset = sb->s_blocksize;
                goto add;
        }
 
-       while ((f_pos < size)) {
+       while (f_pos < size) {
                fi = udf_fileident_read(dir, &f_pos, fibh, cfi, &epos, &eloc,
                                        &elen, &offset);
 
@@ -408,33 +418,39 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
                liu = le16_to_cpu(cfi->lengthOfImpUse);
                lfi = cfi->lengthFileIdent;
 
-               if (fibh->sbh == fibh->ebh) {
+               if (fibh->sbh == fibh->ebh)
                        nameptr = fi->fileIdent + liu;
-               else {
+               else {
                        int poffset;    /* Unpaded ending offset */
 
-                       poffset = fibh->soffset + sizeof(struct fileIdentDesc) + liu + lfi;
+                       poffset = fibh->soffset + sizeof(struct fileIdentDesc) +
+                                       liu + lfi;
 
-                       if (poffset >= lfi) {
-                               nameptr = (char *)(fibh->ebh->b_data + poffset - lfi);
-                       } else {
+                       if (poffset >= lfi)
+                               nameptr = (char *)(fibh->ebh->b_data +
+                                                  poffset - lfi);
+                       else {
                                nameptr = fname;
-                               memcpy(nameptr, fi->fileIdent + liu, lfi - poffset);
-                               memcpy(nameptr + lfi - poffset, fibh->ebh->b_data, poffset);
+                               memcpy(nameptr, fi->fileIdent + liu,
+                                       lfi - poffset);
+                               memcpy(nameptr + lfi - poffset,
+                                       fibh->ebh->b_data, poffset);
                        }
                }
 
                if ((cfi->fileCharacteristics & FID_FILE_CHAR_DELETED) != 0) {
-                       if (((sizeof(struct fileIdentDesc) + liu + lfi + 3) & ~3) == nfidlen) {
+                       if (((sizeof(struct fileIdentDesc) +
+                                       liu + lfi + 3) & ~3) == nfidlen) {
                                brelse(epos.bh);
                                cfi->descTag.tagSerialNum = cpu_to_le16(1);
                                cfi->fileVersionNum = cpu_to_le16(1);
                                cfi->fileCharacteristics = 0;
                                cfi->lengthFileIdent = namelen;
                                cfi->lengthOfImpUse = cpu_to_le16(0);
-                               if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) {
+                               if (!udf_write_fi(dir, cfi, fi, fibh, NULL,
+                                                 name))
                                        return fi;
-                               else {
+                               else {
                                        *err = -EIO;
                                        return NULL;
                                }
@@ -444,8 +460,9 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
                if (!lfi || !dentry)
                        continue;
 
-               if ((flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi)) &&
-                   udf_match(flen, fname, dentry->d_name.len, dentry->d_name.name)) {
+               flen = udf_get_filename(dir->i_sb, nameptr, fname, lfi);
+               if (flen && udf_match(flen, fname, dentry->d_name.len,
+                                     dentry->d_name.name)) {
                        if (fibh->sbh != fibh->ebh)
                                brelse(fibh->ebh);
                        brelse(fibh->sbh);
@@ -456,29 +473,34 @@ static struct fileIdentDesc *udf_add_entry(struct inode *dir,
        }
 
 add:
+       if (dinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
+               elen = (elen + sb->s_blocksize - 1) & ~(sb->s_blocksize - 1);
+               if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
+                       epos.offset -= sizeof(short_ad);
+               else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
+                       epos.offset -= sizeof(long_ad);
+               udf_write_aext(dir, &epos, eloc, elen, 1);
+       }
        f_pos += nfidlen;
 
-       if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB &&
+       if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB &&
            sb->s_blocksize - fibh->eoffset < nfidlen) {
                brelse(epos.bh);
                epos.bh = NULL;
                fibh->soffset -= udf_ext0_offset(dir);
                fibh->eoffset -= udf_ext0_offset(dir);
-               f_pos -= (udf_ext0_offset(dir) >> 2);
+               f_pos -= udf_ext0_offset(dir);
                if (fibh->sbh != fibh->ebh)
                        brelse(fibh->ebh);
                brelse(fibh->sbh);
-               if (!(fibh->sbh = fibh->ebh = udf_expand_dir_adinicb(dir, &block, err)))
+               fibh->sbh = fibh->ebh =
+                               udf_expand_dir_adinicb(dir, &block, err);
+               if (!fibh->sbh)
                        return NULL;
-               epos.block = UDF_I_LOCATION(dir);
-               eloc.logicalBlockNum = block;
-               eloc.partitionReferenceNum = UDF_I_LOCATION(dir).partitionReferenceNum;
-               elen = dir->i_sb->s_blocksize;
+               epos.block = dinfo->i_location;
                epos.offset = udf_file_entry_alloc_offset(dir);
-               if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
-                       epos.offset += sizeof(short_ad);
-               else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
-                       epos.offset += sizeof(long_ad);
+               /* Load extent udf_expand_dir_adinicb() has created */
+               udf_current_aext(dir, &epos, &eloc, &elen, 1);
        }
 
        if (sb->s_blocksize - fibh->eoffset >= nfidlen) {
@@ -489,15 +511,19 @@ add:
                        fibh->sbh = fibh->ebh;
                }
 
-               if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
-                       block = UDF_I_LOCATION(dir).logicalBlockNum;
-                       fi = (struct fileIdentDesc *)(UDF_I_DATA(dir) + fibh->soffset -
-                                                     udf_ext0_offset(dir) +
-                                                     UDF_I_LENEATTR(dir));
+               if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
+                       block = dinfo->i_location.logicalBlockNum;
+                       fi = (struct fileIdentDesc *)
+                                       (dinfo->i_ext.i_data +
+                                        fibh->soffset -
+                                        udf_ext0_offset(dir) +
+                                        dinfo->i_lenEAttr);
                } else {
-                       block = eloc.logicalBlockNum + ((elen - 1) >>
-                                                       dir->i_sb->s_blocksize_bits);
-                       fi = (struct fileIdentDesc *)(fibh->sbh->b_data + fibh->soffset);
+                       block = eloc.logicalBlockNum +
+                                       ((elen - 1) >>
+                                               dir->i_sb->s_blocksize_bits);
+                       fi = (struct fileIdentDesc *)
+                               (fibh->sbh->b_data + fibh->soffset);
                }
        } else {
                fibh->soffset = fibh->eoffset - sb->s_blocksize;
@@ -509,7 +535,8 @@ add:
 
                block = eloc.logicalBlockNum + ((elen - 1) >>
                                                dir->i_sb->s_blocksize_bits);
-               fibh->ebh = udf_bread(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2), 1, err);
+               fibh->ebh = udf_bread(dir,
+                               f_pos >> dir->i_sb->s_blocksize_bits, 1, err);
                if (!fibh->ebh) {
                        brelse(epos.bh);
                        brelse(fibh->sbh);
@@ -521,32 +548,34 @@ add:
                            (EXT_RECORDED_ALLOCATED >> 30)) {
                                block = eloc.logicalBlockNum + ((elen - 1) >>
                                        dir->i_sb->s_blocksize_bits);
-                       } else {
+                       } else
                                block++;
-                       }
 
                        brelse(fibh->sbh);
                        fibh->sbh = fibh->ebh;
                        fi = (struct fileIdentDesc *)(fibh->sbh->b_data);
                } else {
                        fi = (struct fileIdentDesc *)
-                               (fibh->sbh->b_data + sb->s_blocksize + fibh->soffset);
+                               (fibh->sbh->b_data + sb->s_blocksize +
+                                       fibh->soffset);
                }
        }
 
        memset(cfi, 0, sizeof(struct fileIdentDesc));
-       if (UDF_SB_UDFREV(sb) >= 0x0200)
-               udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block, sizeof(tag));
+       if (UDF_SB(sb)->s_udfrev >= 0x0200)
+               udf_new_tag((char *)cfi, TAG_IDENT_FID, 3, 1, block,
+                           sizeof(tag));
        else
-               udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block, sizeof(tag));
+               udf_new_tag((char *)cfi, TAG_IDENT_FID, 2, 1, block,
+                           sizeof(tag));
        cfi->fileVersionNum = cpu_to_le16(1);
        cfi->lengthFileIdent = namelen;
        cfi->lengthOfImpUse = cpu_to_le16(0);
        if (!udf_write_fi(dir, cfi, fi, fibh, NULL, name)) {
                brelse(epos.bh);
                dir->i_size += nfidlen;
-               if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
-                       UDF_I_LENALLOC(dir) += nfidlen;
+               if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
+                       dinfo->i_lenAlloc += nfidlen;
                mark_inode_dirty(dir);
                return fi;
        } else {
@@ -578,6 +607,7 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
        struct inode *inode;
        struct fileIdentDesc cfi, *fi;
        int err;
+       struct udf_inode_info *iinfo;
 
        lock_kernel();
        inode = udf_new_inode(dir, mode, &err);
@@ -586,7 +616,8 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
                return err;
        }
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
+       iinfo = UDF_I(inode);
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
                inode->i_data.a_ops = &udf_adinicb_aops;
        else
                inode->i_data.a_ops = &udf_aops;
@@ -595,7 +626,8 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
        inode->i_mode = mode;
        mark_inode_dirty(inode);
 
-       if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) {
+       fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
+       if (!fi) {
                inode->i_nlink--;
                mark_inode_dirty(inode);
                iput(inode);
@@ -603,13 +635,12 @@ static int udf_create(struct inode *dir, struct dentry *dentry, int mode,
                return err;
        }
        cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
-       cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));
+       cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
        *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
-               cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL);
+               cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL);
        udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
-       if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
+       if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
                mark_inode_dirty(dir);
-       }
        if (fibh.sbh != fibh.ebh)
                brelse(fibh.ebh);
        brelse(fibh.sbh);
@@ -626,6 +657,7 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode,
        struct udf_fileident_bh fibh;
        struct fileIdentDesc cfi, *fi;
        int err;
+       struct udf_inode_info *iinfo;
 
        if (!old_valid_dev(rdev))
                return -EINVAL;
@@ -636,9 +668,11 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode,
        if (!inode)
                goto out;
 
+       iinfo = UDF_I(inode);
        inode->i_uid = current->fsuid;
        init_special_inode(inode, mode, rdev);
-       if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) {
+       fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
+       if (!fi) {
                inode->i_nlink--;
                mark_inode_dirty(inode);
                iput(inode);
@@ -646,13 +680,12 @@ static int udf_mknod(struct inode *dir, struct dentry *dentry, int mode,
                return err;
        }
        cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
-       cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));
+       cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
        *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
-               cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL);
+               cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL);
        udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
-       if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
+       if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
                mark_inode_dirty(dir);
-       }
        mark_inode_dirty(inode);
 
        if (fibh.sbh != fibh.ebh)
@@ -672,6 +705,8 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        struct udf_fileident_bh fibh;
        struct fileIdentDesc cfi, *fi;
        int err;
+       struct udf_inode_info *dinfo = UDF_I(dir);
+       struct udf_inode_info *iinfo;
 
        lock_kernel();
        err = -EMLINK;
@@ -683,9 +718,11 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        if (!inode)
                goto out;
 
+       iinfo = UDF_I(inode);
        inode->i_op = &udf_dir_inode_operations;
        inode->i_fop = &udf_dir_operations;
-       if (!(fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err))) {
+       fi = udf_add_entry(inode, NULL, &fibh, &cfi, &err);
+       if (!fi) {
                inode->i_nlink--;
                mark_inode_dirty(inode);
                iput(inode);
@@ -693,10 +730,11 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        }
        inode->i_nlink = 2;
        cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
-       cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(dir));
+       cfi.icb.extLocation = cpu_to_lelb(dinfo->i_location);
        *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
-               cpu_to_le32(UDF_I_UNIQUE(dir) & 0x00000000FFFFFFFFUL);
-       cfi.fileCharacteristics = FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT;
+               cpu_to_le32(dinfo->i_unique & 0x00000000FFFFFFFFUL);
+       cfi.fileCharacteristics =
+                       FID_FILE_CHAR_DIRECTORY | FID_FILE_CHAR_PARENT;
        udf_write_fi(inode, &cfi, fi, &fibh, NULL, NULL);
        brelse(fibh.sbh);
        inode->i_mode = S_IFDIR | mode;
@@ -704,16 +742,17 @@ static int udf_mkdir(struct inode *dir, struct dentry *dentry, int mode)
                inode->i_mode |= S_ISGID;
        mark_inode_dirty(inode);
 
-       if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) {
+       fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
+       if (!fi) {
                inode->i_nlink = 0;
                mark_inode_dirty(inode);
                iput(inode);
                goto out;
        }
        cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
-       cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));
+       cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
        *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
-               cpu_to_le32(UDF_I_UNIQUE(inode) & 0x00000000FFFFFFFFUL);
+               cpu_to_le32(iinfo->i_unique & 0x00000000FFFFFFFFUL);
        cfi.fileCharacteristics |= FID_FILE_CHAR_DIRECTORY;
        udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
        inc_nlink(dir);
@@ -734,32 +773,33 @@ static int empty_dir(struct inode *dir)
        struct fileIdentDesc *fi, cfi;
        struct udf_fileident_bh fibh;
        loff_t f_pos;
-       loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
+       loff_t size = udf_ext0_offset(dir) + dir->i_size;
        int block;
        kernel_lb_addr eloc;
        uint32_t elen;
        sector_t offset;
        struct extent_position epos = {};
+       struct udf_inode_info *dinfo = UDF_I(dir);
 
-       f_pos = (udf_ext0_offset(dir) >> 2);
+       f_pos = udf_ext0_offset(dir);
+       fibh.soffset = fibh.eoffset = f_pos & (dir->i_sb->s_blocksize - 1);
 
-       fibh.soffset = fibh.eoffset = (f_pos & ((dir->i_sb->s_blocksize - 1) >> 2)) << 2;
-
-       if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
+       if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
                fibh.sbh = fibh.ebh = NULL;
-       } else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
-                             &epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30)) {
+       else if (inode_bmap(dir, f_pos >> dir->i_sb->s_blocksize_bits,
+                             &epos, &eloc, &elen, &offset) ==
+                                       (EXT_RECORDED_ALLOCATED >> 30)) {
                block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
                if ((++offset << dir->i_sb->s_blocksize_bits) < elen) {
-                       if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
+                       if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                                epos.offset -= sizeof(short_ad);
-                       else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
+                       else if (dinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                                epos.offset -= sizeof(long_ad);
-               } else {
+               } else
                        offset = 0;
-               }
 
-               if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block))) {
+               fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block);
+               if (!fibh.sbh) {
                        brelse(epos.bh);
                        return 0;
                }
@@ -768,7 +808,7 @@ static int empty_dir(struct inode *dir)
                return 0;
        }
 
-       while ((f_pos < size)) {
+       while (f_pos < size) {
                fi = udf_fileident_read(dir, &f_pos, &fibh, &cfi, &epos, &eloc,
                                        &elen, &offset);
                if (!fi) {
@@ -828,7 +868,8 @@ static int udf_rmdir(struct inode *dir, struct dentry *dentry)
        clear_nlink(inode);
        inode->i_size = 0;
        inode_dec_link_count(dir);
-       inode->i_ctime = dir->i_ctime = dir->i_mtime = current_fs_time(dir->i_sb);
+       inode->i_ctime = dir->i_ctime = dir->i_mtime =
+                                               current_fs_time(dir->i_sb);
        mark_inode_dirty(dir);
 
 end_rmdir:
@@ -901,36 +942,42 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
        int block;
        char name[UDF_NAME_LEN];
        int namelen;
+       struct buffer_head *bh;
+       struct udf_inode_info *iinfo;
 
        lock_kernel();
-       if (!(inode = udf_new_inode(dir, S_IFLNK, &err)))
+       inode = udf_new_inode(dir, S_IFLNK, &err);
+       if (!inode)
                goto out;
 
+       iinfo = UDF_I(inode);
        inode->i_mode = S_IFLNK | S_IRWXUGO;
        inode->i_data.a_ops = &udf_symlink_aops;
        inode->i_op = &page_symlink_inode_operations;
 
-       if (UDF_I_ALLOCTYPE(inode) != ICBTAG_FLAG_AD_IN_ICB) {
+       if (iinfo->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
                kernel_lb_addr eloc;
                uint32_t elen;
 
                block = udf_new_block(inode->i_sb, inode,
-                                     UDF_I_LOCATION(inode).partitionReferenceNum,
-                                     UDF_I_LOCATION(inode).logicalBlockNum, &err);
+                               iinfo->i_location.partitionReferenceNum,
+                               iinfo->i_location.logicalBlockNum, &err);
                if (!block)
                        goto out_no_entry;
-               epos.block = UDF_I_LOCATION(inode);
+               epos.block = iinfo->i_location;
                epos.offset = udf_file_entry_alloc_offset(inode);
                epos.bh = NULL;
                eloc.logicalBlockNum = block;
-               eloc.partitionReferenceNum = UDF_I_LOCATION(inode).partitionReferenceNum;
+               eloc.partitionReferenceNum =
+                               iinfo->i_location.partitionReferenceNum;
                elen = inode->i_sb->s_blocksize;
-               UDF_I_LENEXTENTS(inode) = elen;
+               iinfo->i_lenExtents = elen;
                udf_add_aext(inode, &epos, eloc, elen, 0);
                brelse(epos.bh);
 
                block = udf_get_pblock(inode->i_sb, block,
-                                      UDF_I_LOCATION(inode).partitionReferenceNum, 0);
+                               iinfo->i_location.partitionReferenceNum,
+                               0);
                epos.bh = udf_tread(inode->i_sb, block);
                lock_buffer(epos.bh);
                memset(epos.bh->b_data, 0x00, inode->i_sb->s_blocksize);
@@ -938,9 +985,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
                unlock_buffer(epos.bh);
                mark_buffer_dirty_inode(epos.bh, inode);
                ea = epos.bh->b_data + udf_ext0_offset(inode);
-       } else {
-               ea = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode);
-       }
+       } else
+               ea = iinfo->i_ext.i_data + iinfo->i_lenEAttr;
 
        eoffset = inode->i_sb->s_blocksize - udf_ext0_offset(inode);
        pc = (struct pathComponent *)ea;
@@ -977,7 +1023,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
                if (compstart[0] == '.') {
                        if ((symname - compstart) == 1)
                                pc->componentType = 4;
-                       else if ((symname - compstart) == 2 && compstart[1] == '.')
+                       else if ((symname - compstart) == 2 &&
+                                       compstart[1] == '.')
                                pc->componentType = 3;
                }
 
@@ -987,7 +1034,8 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
                        if (!namelen)
                                goto out_no_entry;
 
-                       if (elen + sizeof(struct pathComponent) + namelen > eoffset)
+                       if (elen + sizeof(struct pathComponent) + namelen >
+                                       eoffset)
                                goto out_no_entry;
                        else
                                pc->lengthComponentIdent = namelen;
@@ -1006,30 +1054,34 @@ static int udf_symlink(struct inode *dir, struct dentry *dentry,
 
        brelse(epos.bh);
        inode->i_size = elen;
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB)
-               UDF_I_LENALLOC(inode) = inode->i_size;
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
+               iinfo->i_lenAlloc = inode->i_size;
        mark_inode_dirty(inode);
 
-       if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err)))
+       fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
+       if (!fi)
                goto out_no_entry;
        cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
-       cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));
-       if (UDF_SB_LVIDBH(inode->i_sb)) {
+       cfi.icb.extLocation = cpu_to_lelb(iinfo->i_location);
+       bh = UDF_SB(inode->i_sb)->s_lvid_bh;
+       if (bh) {
+               struct logicalVolIntegrityDesc *lvid =
+                               (struct logicalVolIntegrityDesc *)bh->b_data;
                struct logicalVolHeaderDesc *lvhd;
                uint64_t uniqueID;
-               lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse);
+               lvhd = (struct logicalVolHeaderDesc *)
+                               lvid->logicalVolContentsUse;
                uniqueID = le64_to_cpu(lvhd->uniqueID);
                *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
                        cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL);
                if (!(++uniqueID & 0x00000000FFFFFFFFUL))
                        uniqueID += 16;
                lvhd->uniqueID = cpu_to_le64(uniqueID);
-               mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb));
+               mark_buffer_dirty(bh);
        }
        udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
-       if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
+       if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
                mark_inode_dirty(dir);
-       }
        if (fibh.sbh != fibh.ebh)
                brelse(fibh.ebh);
        brelse(fibh.sbh);
@@ -1053,6 +1105,7 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir,
        struct udf_fileident_bh fibh;
        struct fileIdentDesc cfi, *fi;
        int err;
+       struct buffer_head *bh;
 
        lock_kernel();
        if (inode->i_nlink >= (256 << sizeof(inode->i_nlink)) - 1) {
@@ -1060,28 +1113,32 @@ static int udf_link(struct dentry *old_dentry, struct inode *dir,
                return -EMLINK;
        }
 
-       if (!(fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err))) {
+       fi = udf_add_entry(dir, dentry, &fibh, &cfi, &err);
+       if (!fi) {
                unlock_kernel();
                return err;
        }
        cfi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize);
-       cfi.icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(inode));
-       if (UDF_SB_LVIDBH(inode->i_sb)) {
+       cfi.icb.extLocation = cpu_to_lelb(UDF_I(inode)->i_location);
+       bh = UDF_SB(inode->i_sb)->s_lvid_bh;
+       if (bh) {
+               struct logicalVolIntegrityDesc *lvid =
+                               (struct logicalVolIntegrityDesc *)bh->b_data;
                struct logicalVolHeaderDesc *lvhd;
                uint64_t uniqueID;
-               lvhd = (struct logicalVolHeaderDesc *)(UDF_SB_LVID(inode->i_sb)->logicalVolContentsUse);
+               lvhd = (struct logicalVolHeaderDesc *)
+                               (lvid->logicalVolContentsUse);
                uniqueID = le64_to_cpu(lvhd->uniqueID);
                *(__le32 *)((struct allocDescImpUse *)cfi.icb.impUse)->impUse =
                        cpu_to_le32(uniqueID & 0x00000000FFFFFFFFUL);
                if (!(++uniqueID & 0x00000000FFFFFFFFUL))
                        uniqueID += 16;
                lvhd->uniqueID = cpu_to_le64(uniqueID);
-               mark_buffer_dirty(UDF_SB_LVIDBH(inode->i_sb));
+               mark_buffer_dirty(bh);
        }
        udf_write_fi(dir, &cfi, fi, &fibh, NULL, NULL);
-       if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB) {
+       if (UDF_I(dir)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
                mark_inode_dirty(dir);
-       }
 
        if (fibh.sbh != fibh.ebh)
                brelse(fibh.ebh);
@@ -1105,13 +1162,16 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
        struct inode *old_inode = old_dentry->d_inode;
        struct inode *new_inode = new_dentry->d_inode;
        struct udf_fileident_bh ofibh, nfibh;
-       struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL, ocfi, ncfi;
+       struct fileIdentDesc *ofi = NULL, *nfi = NULL, *dir_fi = NULL;
+       struct fileIdentDesc ocfi, ncfi;
        struct buffer_head *dir_bh = NULL;
        int retval = -ENOENT;
        kernel_lb_addr tloc;
+       struct udf_inode_info *old_iinfo = UDF_I(old_inode);
 
        lock_kernel();
-       if ((ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi))) {
+       ofi = udf_find_entry(old_dir, old_dentry, &ofibh, &ocfi);
+       if (ofi) {
                if (ofibh.sbh != ofibh.ebh)
                        brelse(ofibh.ebh);
                brelse(ofibh.sbh);
@@ -1131,7 +1191,7 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
                }
        }
        if (S_ISDIR(old_inode->i_mode)) {
-               uint32_t offset = udf_ext0_offset(old_inode);
+               int offset = udf_ext0_offset(old_inode);
 
                if (new_inode) {
                        retval = -ENOTEMPTY;
@@ -1139,30 +1199,36 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
                                goto end_rename;
                }
                retval = -EIO;
-               if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) {
-                       dir_fi = udf_get_fileident(UDF_I_DATA(old_inode) -
-                                                  (UDF_I_EFE(old_inode) ?
-                                                   sizeof(struct extendedFileEntry) :
-                                                   sizeof(struct fileEntry)),
-                                                  old_inode->i_sb->s_blocksize, &offset);
+               if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
+                       dir_fi = udf_get_fileident(
+                                       old_iinfo->i_ext.i_data -
+                                         (old_iinfo->i_efe ?
+                                          sizeof(struct extendedFileEntry) :
+                                          sizeof(struct fileEntry)),
+                                       old_inode->i_sb->s_blocksize, &offset);
                } else {
                        dir_bh = udf_bread(old_inode, 0, 0, &retval);
                        if (!dir_bh)
                                goto end_rename;
-                       dir_fi = udf_get_fileident(dir_bh->b_data, old_inode->i_sb->s_blocksize, &offset);
+                       dir_fi = udf_get_fileident(dir_bh->b_data,
+                                       old_inode->i_sb->s_blocksize, &offset);
                }
                if (!dir_fi)
                        goto end_rename;
                tloc = lelb_to_cpu(dir_fi->icb.extLocation);
-               if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) != old_dir->i_ino)
+               if (udf_get_lb_pblock(old_inode->i_sb, tloc, 0) !=
+                               old_dir->i_ino)
                        goto end_rename;
 
                retval = -EMLINK;
-               if (!new_inode && new_dir->i_nlink >= (256 << sizeof(new_dir->i_nlink)) - 1)
+               if (!new_inode &&
+                       new_dir->i_nlink >=
+                               (256 << sizeof(new_dir->i_nlink)) - 1)
                        goto end_rename;
        }
        if (!nfi) {
-               nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi, &retval);
+               nfi = udf_add_entry(new_dir, new_dentry, &nfibh, &ncfi,
+                                   &retval);
                if (!nfi)
                        goto end_rename;
        }
@@ -1194,18 +1260,19 @@ static int udf_rename(struct inode *old_dir, struct dentry *old_dentry,
        mark_inode_dirty(old_dir);
 
        if (dir_fi) {
-               dir_fi->icb.extLocation = cpu_to_lelb(UDF_I_LOCATION(new_dir));
-               udf_update_tag((char *)dir_fi, (sizeof(struct fileIdentDesc) +
-                                               le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3);
-               if (UDF_I_ALLOCTYPE(old_inode) == ICBTAG_FLAG_AD_IN_ICB) {
+               dir_fi->icb.extLocation = cpu_to_lelb(UDF_I(new_dir)->i_location);
+               udf_update_tag((char *)dir_fi,
+                               (sizeof(struct fileIdentDesc) +
+                               le16_to_cpu(dir_fi->lengthOfImpUse) + 3) & ~3);
+               if (old_iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
                        mark_inode_dirty(old_inode);
-               } else {
+               else
                        mark_buffer_dirty_inode(dir_bh, old_inode);
-               }
+
                inode_dec_link_count(old_dir);
-               if (new_inode) {
+               if (new_inode)
                        inode_dec_link_count(new_inode);
-               else {
+               else {
                        inc_nlink(new_dir);
                        mark_inode_dirty(new_dir);
                }
index aaab24c8c498d33ee3e9bb8774cf4fca47cee0bb..fc533345ab89198a12fb472765f7c9073a356970 100644 (file)
 inline uint32_t udf_get_pblock(struct super_block *sb, uint32_t block,
                               uint16_t partition, uint32_t offset)
 {
-       if (partition >= UDF_SB_NUMPARTS(sb)) {
-               udf_debug("block=%d, partition=%d, offset=%d: invalid partition\n",
-                         block, partition, offset);
+       struct udf_sb_info *sbi = UDF_SB(sb);
+       struct udf_part_map *map;
+       if (partition >= sbi->s_partitions) {
+               udf_debug("block=%d, partition=%d, offset=%d: "
+                         "invalid partition\n", block, partition, offset);
                return 0xFFFFFFFF;
        }
-       if (UDF_SB_PARTFUNC(sb, partition))
-               return UDF_SB_PARTFUNC(sb, partition)(sb, block, partition, offset);
+       map = &sbi->s_partmaps[partition];
+       if (map->s_partition_func)
+               return map->s_partition_func(sb, block, partition, offset);
        else
-               return UDF_SB_PARTROOT(sb, partition) + block + offset;
+               return map->s_partition_root + block + offset;
 }
 
 uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
@@ -49,12 +52,18 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
        uint32_t newblock;
        uint32_t index;
        uint32_t loc;
+       struct udf_sb_info *sbi = UDF_SB(sb);
+       struct udf_part_map *map;
+       struct udf_virtual_data *vdata;
+       struct udf_inode_info *iinfo;
 
-       index = (sb->s_blocksize - UDF_SB_TYPEVIRT(sb,partition).s_start_offset) / sizeof(uint32_t);
+       map = &sbi->s_partmaps[partition];
+       vdata = &map->s_type_specific.s_virtual;
+       index = (sb->s_blocksize - vdata->s_start_offset) / sizeof(uint32_t);
 
-       if (block > UDF_SB_TYPEVIRT(sb,partition).s_num_entries) {
-               udf_debug("Trying to access block beyond end of VAT (%d max %d)\n",
-                         block, UDF_SB_TYPEVIRT(sb,partition).s_num_entries);
+       if (block > vdata->s_num_entries) {
+               udf_debug("Trying to access block beyond end of VAT "
+                         "(%d max %d)\n", block, vdata->s_num_entries);
                return 0xFFFFFFFF;
        }
 
@@ -64,12 +73,13 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
                index = block % (sb->s_blocksize / sizeof(uint32_t));
        } else {
                newblock = 0;
-               index = UDF_SB_TYPEVIRT(sb,partition).s_start_offset / sizeof(uint32_t) + block;
+               index = vdata->s_start_offset / sizeof(uint32_t) + block;
        }
 
-       loc = udf_block_map(UDF_SB_VAT(sb), newblock);
+       loc = udf_block_map(sbi->s_vat_inode, newblock);
 
-       if (!(bh = sb_bread(sb, loc))) {
+       bh = sb_bread(sb, loc);
+       if (!bh) {
                udf_debug("get_pblock(UDF_VIRTUAL_MAP:%p,%d,%d) VAT: %d[%d]\n",
                          sb, block, partition, loc, index);
                return 0xFFFFFFFF;
@@ -79,50 +89,61 @@ uint32_t udf_get_pblock_virt15(struct super_block *sb, uint32_t block,
 
        brelse(bh);
 
-       if (UDF_I_LOCATION(UDF_SB_VAT(sb)).partitionReferenceNum == partition) {
+       iinfo = UDF_I(sbi->s_vat_inode);
+       if (iinfo->i_location.partitionReferenceNum == partition) {
                udf_debug("recursive call to udf_get_pblock!\n");
                return 0xFFFFFFFF;
        }
 
        return udf_get_pblock(sb, loc,
-                             UDF_I_LOCATION(UDF_SB_VAT(sb)).partitionReferenceNum,
+                             iinfo->i_location.partitionReferenceNum,
                              offset);
 }
 
-inline uint32_t udf_get_pblock_virt20(struct super_block * sb, uint32_t block,
+inline uint32_t udf_get_pblock_virt20(struct super_block *sb, uint32_t block,
                                      uint16_t partition, uint32_t offset)
 {
        return udf_get_pblock_virt15(sb, block, partition, offset);
 }
 
-uint32_t udf_get_pblock_spar15(struct super_block * sb, uint32_t block,
+uint32_t udf_get_pblock_spar15(struct super_block *sb, uint32_t block,
                               uint16_t partition, uint32_t offset)
 {
        int i;
        struct sparingTable *st = NULL;
-       uint32_t packet = (block + offset) & ~(UDF_SB_TYPESPAR(sb,partition).s_packet_len - 1);
+       struct udf_sb_info *sbi = UDF_SB(sb);
+       struct udf_part_map *map;
+       uint32_t packet;
+       struct udf_sparing_data *sdata;
+
+       map = &sbi->s_partmaps[partition];
+       sdata = &map->s_type_specific.s_sparing;
+       packet = (block + offset) & ~(sdata->s_packet_len - 1);
 
        for (i = 0; i < 4; i++) {
-               if (UDF_SB_TYPESPAR(sb,partition).s_spar_map[i] != NULL) {
-                       st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,partition).s_spar_map[i]->b_data;
+               if (sdata->s_spar_map[i] != NULL) {
+                       st = (struct sparingTable *)
+                                       sdata->s_spar_map[i]->b_data;
                        break;
                }
        }
 
        if (st) {
                for (i = 0; i < le16_to_cpu(st->reallocationTableLen); i++) {
-                       if (le32_to_cpu(st->mapEntry[i].origLocation) >= 0xFFFFFFF0) {
+                       struct sparingEntry *entry = &st->mapEntry[i];
+                       u32 origLoc = le32_to_cpu(entry->origLocation);
+                       if (origLoc >= 0xFFFFFFF0)
                                break;
-                       } else if (le32_to_cpu(st->mapEntry[i].origLocation) == packet) {
-                               return le32_to_cpu(st->mapEntry[i].mappedLocation) +
-                                       ((block + offset) & (UDF_SB_TYPESPAR(sb,partition).s_packet_len - 1));
-                       } else if (le32_to_cpu(st->mapEntry[i].origLocation) > packet) {
+                       else if (origLoc == packet)
+                               return le32_to_cpu(entry->mappedLocation) +
+                                       ((block + offset) &
+                                               (sdata->s_packet_len - 1));
+                       else if (origLoc > packet)
                                break;
-                       }
                }
        }
 
-       return UDF_SB_PARTROOT(sb,partition) + block + offset;
+       return map->s_partition_root + block + offset;
 }
 
 int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
@@ -132,69 +153,109 @@ int udf_relocate_blocks(struct super_block *sb, long old_block, long *new_block)
        struct sparingEntry mapEntry;
        uint32_t packet;
        int i, j, k, l;
+       struct udf_sb_info *sbi = UDF_SB(sb);
+       u16 reallocationTableLen;
+       struct buffer_head *bh;
 
-       for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
-               if (old_block > UDF_SB_PARTROOT(sb,i) &&
-                   old_block < UDF_SB_PARTROOT(sb,i) + UDF_SB_PARTLEN(sb,i)) {
-                       sdata = &UDF_SB_TYPESPAR(sb,i);
-                       packet = (old_block - UDF_SB_PARTROOT(sb,i)) & ~(sdata->s_packet_len - 1);
+       for (i = 0; i < sbi->s_partitions; i++) {
+               struct udf_part_map *map = &sbi->s_partmaps[i];
+               if (old_block > map->s_partition_root &&
+                   old_block < map->s_partition_root + map->s_partition_len) {
+                       sdata = &map->s_type_specific.s_sparing;
+                       packet = (old_block - map->s_partition_root) &
+                                               ~(sdata->s_packet_len - 1);
 
-                       for (j = 0; j < 4; j++) {
-                               if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL) {
-                                       st = (struct sparingTable *)sdata->s_spar_map[j]->b_data;
+                       for (j = 0; j < 4; j++)
+                               if (sdata->s_spar_map[j] != NULL) {
+                                       st = (struct sparingTable *)
+                                               sdata->s_spar_map[j]->b_data;
                                        break;
                                }
-                       }
 
                        if (!st)
                                return 1;
 
-                       for (k = 0; k < le16_to_cpu(st->reallocationTableLen); k++) {
-                               if (le32_to_cpu(st->mapEntry[k].origLocation) == 0xFFFFFFFF) {
+                       reallocationTableLen =
+                                       le16_to_cpu(st->reallocationTableLen);
+                       for (k = 0; k < reallocationTableLen; k++) {
+                               struct sparingEntry *entry = &st->mapEntry[k];
+                               u32 origLoc = le32_to_cpu(entry->origLocation);
+
+                               if (origLoc == 0xFFFFFFFF) {
                                        for (; j < 4; j++) {
-                                               if (sdata->s_spar_map[j]) {
-                                                       st = (struct sparingTable *)sdata->s_spar_map[j]->b_data;
-                                                       st->mapEntry[k].origLocation = cpu_to_le32(packet);
-                                                       udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry));
-                                                       mark_buffer_dirty(sdata->s_spar_map[j]);
-                                               }
+                                               int len;
+                                               bh = sdata->s_spar_map[j];
+                                               if (!bh)
+                                                       continue;
+
+                                               st = (struct sparingTable *)
+                                                               bh->b_data;
+                                               entry->origLocation =
+                                                       cpu_to_le32(packet);
+                                               len =
+                                                 sizeof(struct sparingTable) +
+                                                 reallocationTableLen *
+                                                 sizeof(struct sparingEntry);
+                                               udf_update_tag((char *)st, len);
+                                               mark_buffer_dirty(bh);
                                        }
-                                       *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) +
-                                               ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1));
+                                       *new_block = le32_to_cpu(
+                                                       entry->mappedLocation) +
+                                                    ((old_block -
+                                                       map->s_partition_root) &
+                                                    (sdata->s_packet_len - 1));
                                        return 0;
-                               } else if (le32_to_cpu(st->mapEntry[k].origLocation) == packet) {
-                                       *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) +
-                                               ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1));
+                               } else if (origLoc == packet) {
+                                       *new_block = le32_to_cpu(
+                                                       entry->mappedLocation) +
+                                                    ((old_block -
+                                                       map->s_partition_root) &
+                                                    (sdata->s_packet_len - 1));
                                        return 0;
-                               } else if (le32_to_cpu(st->mapEntry[k].origLocation) > packet) {
+                               } else if (origLoc > packet)
                                        break;
-                               }
                        }
 
-                       for (l = k; l < le16_to_cpu(st->reallocationTableLen); l++) {
-                               if (le32_to_cpu(st->mapEntry[l].origLocation) == 0xFFFFFFFF) {
-                                       for (; j < 4; j++) {
-                                               if (sdata->s_spar_map[j]) {
-                                                       st = (struct sparingTable *)sdata->s_spar_map[j]->b_data;
-                                                       mapEntry = st->mapEntry[l];
-                                                       mapEntry.origLocation = cpu_to_le32(packet);
-                                                       memmove(&st->mapEntry[k + 1], &st->mapEntry[k], (l - k) * sizeof(struct sparingEntry));
-                                                       st->mapEntry[k] = mapEntry;
-                                                       udf_update_tag((char *)st, sizeof(struct sparingTable) + le16_to_cpu(st->reallocationTableLen) * sizeof(struct sparingEntry));
-                                                       mark_buffer_dirty(sdata->s_spar_map[j]);
-                                               }
-                                       }
-                                       *new_block = le32_to_cpu(st->mapEntry[k].mappedLocation) +
-                                               ((old_block - UDF_SB_PARTROOT(sb,i)) & (sdata->s_packet_len - 1));
-                                       return 0;
+                       for (l = k; l < reallocationTableLen; l++) {
+                               struct sparingEntry *entry = &st->mapEntry[l];
+                               u32 origLoc = le32_to_cpu(entry->origLocation);
+
+                               if (origLoc != 0xFFFFFFFF)
+                                       continue;
+
+                               for (; j < 4; j++) {
+                                       bh = sdata->s_spar_map[j];
+                                       if (!bh)
+                                               continue;
+
+                                       st = (struct sparingTable *)bh->b_data;
+                                       mapEntry = st->mapEntry[l];
+                                       mapEntry.origLocation =
+                                                       cpu_to_le32(packet);
+                                       memmove(&st->mapEntry[k + 1],
+                                               &st->mapEntry[k],
+                                               (l - k) *
+                                               sizeof(struct sparingEntry));
+                                       st->mapEntry[k] = mapEntry;
+                                       udf_update_tag((char *)st,
+                                               sizeof(struct sparingTable) +
+                                               reallocationTableLen *
+                                               sizeof(struct sparingEntry));
+                                       mark_buffer_dirty(bh);
                                }
+                               *new_block =
+                                       le32_to_cpu(
+                                             st->mapEntry[k].mappedLocation) +
+                                       ((old_block - map->s_partition_root) &
+                                        (sdata->s_packet_len - 1));
+                               return 0;
                        }
 
                        return 1;
                } /* if old_block */
        }
 
-       if (i == UDF_SB_NUMPARTS(sb)) {
+       if (i == sbi->s_partitions) {
                /* outside of partitions */
                /* for now, fail =) */
                return 1;
index 4360c7a05743727a3f7b94753057a5a831eb2b0b..f3ac4abfc9467a093ac54ebdef4283e9eaec166c 100644 (file)
@@ -33,8 +33,8 @@
  *  10/17/98      added freespace count for "df"
  *  11/11/98 gr   added novrs option
  *  11/26/98 dgb  added fileset,anchor mount options
- *  12/06/98 blf  really hosed things royally. vat/sparing support. sequenced vol descs
- *                rewrote option handling based on isofs
+ *  12/06/98 blf  really hosed things royally. vat/sparing support. sequenced
+ *                vol descs. rewrote option handling based on isofs
  *  12/20/98      find the free space bitmap (if it exists)
  */
 
@@ -52,6 +52,9 @@
 #include <linux/buffer_head.h>
 #include <linux/vfs.h>
 #include <linux/vmalloc.h>
+#include <linux/errno.h>
+#include <linux/mount.h>
+#include <linux/seq_file.h>
 #include <asm/byteorder.h>
 
 #include <linux/udf_fs.h>
@@ -70,6 +73,8 @@
 #define VDS_POS_TERMINATING_DESC       6
 #define VDS_POS_LENGTH                 7
 
+#define UDF_DEFAULT_BLOCKSIZE 2048
+
 static char error_buf[1024];
 
 /* These are the "meat" - everything else is stuffing */
@@ -94,6 +99,17 @@ static void udf_open_lvid(struct super_block *);
 static void udf_close_lvid(struct super_block *);
 static unsigned int udf_count_free(struct super_block *);
 static int udf_statfs(struct dentry *, struct kstatfs *);
+static int udf_show_options(struct seq_file *, struct vfsmount *);
+
+struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi)
+{
+       struct logicalVolIntegrityDesc *lvid =
+               (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data;
+       __u32 number_of_partitions = le32_to_cpu(lvid->numOfPartitions);
+       __u32 offset = number_of_partitions * 2 *
+                               sizeof(uint32_t)/sizeof(uint8_t);
+       return (struct logicalVolIntegrityDescImpUse *)&(lvid->impUse[offset]);
+}
 
 /* UDF filesystem type */
 static int udf_get_sb(struct file_system_type *fs_type,
@@ -116,7 +132,7 @@ static struct kmem_cache *udf_inode_cachep;
 static struct inode *udf_alloc_inode(struct super_block *sb)
 {
        struct udf_inode_info *ei;
-       ei = (struct udf_inode_info *)kmem_cache_alloc(udf_inode_cachep, GFP_KERNEL);
+       ei = kmem_cache_alloc(udf_inode_cachep, GFP_KERNEL);
        if (!ei)
                return NULL;
 
@@ -170,6 +186,7 @@ static const struct super_operations udf_sb_ops = {
        .write_super    = udf_write_super,
        .statfs         = udf_statfs,
        .remount_fs     = udf_remount_fs,
+       .show_options   = udf_show_options,
 };
 
 struct udf_options {
@@ -218,6 +235,79 @@ static void __exit exit_udf_fs(void)
 module_init(init_udf_fs)
 module_exit(exit_udf_fs)
 
+static int udf_sb_alloc_partition_maps(struct super_block *sb, u32 count)
+{
+       struct udf_sb_info *sbi = UDF_SB(sb);
+
+       sbi->s_partmaps = kcalloc(count, sizeof(struct udf_part_map),
+                                 GFP_KERNEL);
+       if (!sbi->s_partmaps) {
+               udf_error(sb, __FUNCTION__,
+                         "Unable to allocate space for %d partition maps",
+                         count);
+               sbi->s_partitions = 0;
+               return -ENOMEM;
+       }
+
+       sbi->s_partitions = count;
+       return 0;
+}
+
+static int udf_show_options(struct seq_file *seq, struct vfsmount *mnt)
+{
+       struct super_block *sb = mnt->mnt_sb;
+       struct udf_sb_info *sbi = UDF_SB(sb);
+
+       if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT))
+               seq_puts(seq, ",nostrict");
+       if (sb->s_blocksize != UDF_DEFAULT_BLOCKSIZE)
+               seq_printf(seq, ",bs=%lu", sb->s_blocksize);
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE))
+               seq_puts(seq, ",unhide");
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE))
+               seq_puts(seq, ",undelete");
+       if (!UDF_QUERY_FLAG(sb, UDF_FLAG_USE_AD_IN_ICB))
+               seq_puts(seq, ",noadinicb");
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_USE_SHORT_AD))
+               seq_puts(seq, ",shortad");
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_FORGET))
+               seq_puts(seq, ",uid=forget");
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_IGNORE))
+               seq_puts(seq, ",uid=ignore");
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_FORGET))
+               seq_puts(seq, ",gid=forget");
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_IGNORE))
+               seq_puts(seq, ",gid=ignore");
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET))
+               seq_printf(seq, ",uid=%u", sbi->s_uid);
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET))
+               seq_printf(seq, ",gid=%u", sbi->s_gid);
+       if (sbi->s_umask != 0)
+               seq_printf(seq, ",umask=%o", sbi->s_umask);
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_SESSION_SET))
+               seq_printf(seq, ",session=%u", sbi->s_session);
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_LASTBLOCK_SET))
+               seq_printf(seq, ",lastblock=%u", sbi->s_last_block);
+       /*
+        * s_anchor[2] could be zeroed out in case there is no anchor
+        * in the specified block, but then the "anchor=N" option
+        * originally given by the user wasn't effective, so it's OK
+        * if we don't show it.
+        */
+       if (sbi->s_anchor[2] != 0)
+               seq_printf(seq, ",anchor=%u", sbi->s_anchor[2]);
+       /*
+        * volume, partition, fileset and rootdir seem to be ignored
+        * currently
+        */
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8))
+               seq_puts(seq, ",utf8");
+       if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP) && sbi->s_nls_map)
+               seq_printf(seq, ",iocharset=%s", sbi->s_nls_map->charset);
+
+       return 0;
+}
+
 /*
  * udf_parse_options
  *
@@ -310,13 +400,14 @@ static match_table_t tokens = {
        {Opt_err,       NULL}
 };
 
-static int udf_parse_options(char *options, struct udf_options *uopt)
+static int udf_parse_options(char *options, struct udf_options *uopt,
+                            bool remount)
 {
        char *p;
        int option;
 
        uopt->novrs = 0;
-       uopt->blocksize = 2048;
+       uopt->blocksize = UDF_DEFAULT_BLOCKSIZE;
        uopt->partition = 0xFFFF;
        uopt->session = 0xFFFFFFFF;
        uopt->lastblock = 0;
@@ -386,11 +477,15 @@ static int udf_parse_options(char *options, struct udf_options *uopt)
                        if (match_int(args, &option))
                                return 0;
                        uopt->session = option;
+                       if (!remount)
+                               uopt->flags |= (1 << UDF_FLAG_SESSION_SET);
                        break;
                case Opt_lastblock:
                        if (match_int(args, &option))
                                return 0;
                        uopt->lastblock = option;
+                       if (!remount)
+                               uopt->flags |= (1 << UDF_FLAG_LASTBLOCK_SET);
                        break;
                case Opt_anchor:
                        if (match_int(args, &option))
@@ -447,7 +542,7 @@ static int udf_parse_options(char *options, struct udf_options *uopt)
        return 1;
 }
 
-void udf_write_super(struct super_block *sb)
+static void udf_write_super(struct super_block *sb)
 {
        lock_kernel();
 
@@ -461,22 +556,23 @@ void udf_write_super(struct super_block *sb)
 static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
 {
        struct udf_options uopt;
+       struct udf_sb_info *sbi = UDF_SB(sb);
 
-       uopt.flags = UDF_SB(sb)->s_flags;
-       uopt.uid   = UDF_SB(sb)->s_uid;
-       uopt.gid   = UDF_SB(sb)->s_gid;
-       uopt.umask = UDF_SB(sb)->s_umask;
+       uopt.flags = sbi->s_flags;
+       uopt.uid   = sbi->s_uid;
+       uopt.gid   = sbi->s_gid;
+       uopt.umask = sbi->s_umask;
 
-       if (!udf_parse_options(options, &uopt))
+       if (!udf_parse_options(options, &uopt, true))
                return -EINVAL;
 
-       UDF_SB(sb)->s_flags = uopt.flags;
-       UDF_SB(sb)->s_uid   = uopt.uid;
-       UDF_SB(sb)->s_gid   = uopt.gid;
-       UDF_SB(sb)->s_umask = uopt.umask;
+       sbi->s_flags = uopt.flags;
+       sbi->s_uid   = uopt.uid;
+       sbi->s_gid   = uopt.gid;
+       sbi->s_umask = uopt.umask;
 
-       if (UDF_SB_LVIDBH(sb)) {
-               int write_rev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
+       if (sbi->s_lvid_bh) {
+               int write_rev = le16_to_cpu(udf_sb_lvidiu(sbi)->minUDFWriteRev);
                if (write_rev > UDF_MAX_WRITE_VERSION)
                        *flags |= MS_RDONLY;
        }
@@ -538,17 +634,19 @@ static int udf_vrs(struct super_block *sb, int silent)
        int iso9660 = 0;
        int nsr02 = 0;
        int nsr03 = 0;
+       struct udf_sb_info *sbi;
 
        /* Block size must be a multiple of 512 */
        if (sb->s_blocksize & 511)
                return 0;
+       sbi = UDF_SB(sb);
 
        if (sb->s_blocksize < sizeof(struct volStructDesc))
                sectorsize = sizeof(struct volStructDesc);
        else
                sectorsize = sb->s_blocksize;
 
-       sector += (UDF_SB_SESSION(sb) << sb->s_blocksize_bits);
+       sector += (sbi->s_session << sb->s_blocksize_bits);
 
        udf_debug("Starting at sector %u (%ld byte sectors)\n",
                  (sector >> sb->s_blocksize_bits), sb->s_blocksize);
@@ -561,47 +659,52 @@ static int udf_vrs(struct super_block *sb, int silent)
 
                /* Look for ISO  descriptors */
                vsd = (struct volStructDesc *)(bh->b_data +
-                                              (sector & (sb->s_blocksize - 1)));
+                                             (sector & (sb->s_blocksize - 1)));
 
                if (vsd->stdIdent[0] == 0) {
                        brelse(bh);
                        break;
-               } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN)) {
+               } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001,
+                                   VSD_STD_ID_LEN)) {
                        iso9660 = sector;
                        switch (vsd->structType) {
                        case 0:
                                udf_debug("ISO9660 Boot Record found\n");
                                break;
                        case 1:
-                               udf_debug
-                                   ("ISO9660 Primary Volume Descriptor found\n");
+                               udf_debug("ISO9660 Primary Volume Descriptor "
+                                         "found\n");
                                break;
                        case 2:
-                               udf_debug
-                                   ("ISO9660 Supplementary Volume Descriptor found\n");
+                               udf_debug("ISO9660 Supplementary Volume "
+                                         "Descriptor found\n");
                                break;
                        case 3:
-                               udf_debug
-                                   ("ISO9660 Volume Partition Descriptor found\n");
+                               udf_debug("ISO9660 Volume Partition Descriptor "
+                                         "found\n");
                                break;
                        case 255:
-                               udf_debug
-                                   ("ISO9660 Volume Descriptor Set Terminator found\n");
+                               udf_debug("ISO9660 Volume Descriptor Set "
+                                         "Terminator found\n");
                                break;
                        default:
                                udf_debug("ISO9660 VRS (%u) found\n",
                                          vsd->structType);
                                break;
                        }
-               } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN)) {
-               } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01, VSD_STD_ID_LEN)) {
+               } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01,
+                                   VSD_STD_ID_LEN))
+                       ; /* nothing */
+               else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01,
+                                   VSD_STD_ID_LEN)) {
                        brelse(bh);
                        break;
-               } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN)) {
+               } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02,
+                                   VSD_STD_ID_LEN))
                        nsr02 = sector;
-               } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN)) {
+               else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03,
+                                   VSD_STD_ID_LEN))
                        nsr03 = sector;
-               }
                brelse(bh);
        }
 
@@ -609,7 +712,7 @@ static int udf_vrs(struct super_block *sb, int silent)
                return nsr03;
        else if (nsr02)
                return nsr02;
-       else if (sector - (UDF_SB_SESSION(sb) << sb->s_blocksize_bits) == 32768)
+       else if (sector - (sbi->s_session << sb->s_blocksize_bits) == 32768)
                return -1;
        else
                return 0;
@@ -634,11 +737,15 @@ static int udf_vrs(struct super_block *sb, int silent)
  */
 static void udf_find_anchor(struct super_block *sb)
 {
-       int lastblock = UDF_SB_LASTBLOCK(sb);
+       int lastblock;
        struct buffer_head *bh = NULL;
        uint16_t ident;
        uint32_t location;
        int i;
+       struct udf_sb_info *sbi;
+
+       sbi = UDF_SB(sb);
+       lastblock = sbi->s_last_block;
 
        if (lastblock) {
                int varlastblock = udf_variable_to_fixed(lastblock);
@@ -658,57 +765,83 @@ static void udf_find_anchor(struct super_block *sb)
                 *  however, if the disc isn't closed, it could be 512 */
 
                for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) {
-                       if (last[i] < 0 || !(bh = sb_bread(sb, last[i]))) {
-                               ident = location = 0;
-                       } else {
-                               ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
-                               location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
-                               brelse(bh);
+                       ident = location = 0;
+                       if (last[i] >= 0) {
+                               bh = sb_bread(sb, last[i]);
+                               if (bh) {
+                                       tag *t = (tag *)bh->b_data;
+                                       ident = le16_to_cpu(t->tagIdent);
+                                       location = le32_to_cpu(t->tagLocation);
+                                       brelse(bh);
+                               }
                        }
 
                        if (ident == TAG_IDENT_AVDP) {
-                               if (location == last[i] - UDF_SB_SESSION(sb)) {
-                                       lastblock = UDF_SB_ANCHOR(sb)[0] = last[i] - UDF_SB_SESSION(sb);
-                                       UDF_SB_ANCHOR(sb)[1] = last[i] - 256 - UDF_SB_SESSION(sb);
-                               } else if (location == udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb)) {
+                               if (location == last[i] - sbi->s_session) {
+                                       lastblock = last[i] - sbi->s_session;
+                                       sbi->s_anchor[0] = lastblock;
+                                       sbi->s_anchor[1] = lastblock - 256;
+                               } else if (location ==
+                                               udf_variable_to_fixed(last[i]) -
+                                                       sbi->s_session) {
                                        UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
-                                       lastblock = UDF_SB_ANCHOR(sb)[0] = udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb);
-                                       UDF_SB_ANCHOR(sb)[1] = lastblock - 256 - UDF_SB_SESSION(sb);
+                                       lastblock =
+                                               udf_variable_to_fixed(last[i]) -
+                                                       sbi->s_session;
+                                       sbi->s_anchor[0] = lastblock;
+                                       sbi->s_anchor[1] = lastblock - 256 -
+                                                               sbi->s_session;
                                } else {
-                                       udf_debug("Anchor found at block %d, location mismatch %d.\n",
+                                       udf_debug("Anchor found at block %d, "
+                                                 "location mismatch %d.\n",
                                                  last[i], location);
                                }
-                       } else if (ident == TAG_IDENT_FE || ident == TAG_IDENT_EFE) {
+                       } else if (ident == TAG_IDENT_FE ||
+                                       ident == TAG_IDENT_EFE) {
                                lastblock = last[i];
-                               UDF_SB_ANCHOR(sb)[3] = 512;
+                               sbi->s_anchor[3] = 512;
                        } else {
-                               if (last[i] < 256 || !(bh = sb_bread(sb, last[i] - 256))) {
-                                       ident = location = 0;
-                               } else {
-                                       ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
-                                       location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
-                                       brelse(bh);
+                               ident = location = 0;
+                               if (last[i] >= 256) {
+                                       bh = sb_bread(sb, last[i] - 256);
+                                       if (bh) {
+                                               tag *t = (tag *)bh->b_data;
+                                               ident = le16_to_cpu(
+                                                               t->tagIdent);
+                                               location = le32_to_cpu(
+                                                               t->tagLocation);
+                                               brelse(bh);
+                                       }
                                }
 
                                if (ident == TAG_IDENT_AVDP &&
-                                   location == last[i] - 256 - UDF_SB_SESSION(sb)) {
+                                   location == last[i] - 256 -
+                                               sbi->s_session) {
                                        lastblock = last[i];
-                                       UDF_SB_ANCHOR(sb)[1] = last[i] - 256;
+                                       sbi->s_anchor[1] = last[i] - 256;
                                } else {
-                                       if (last[i] < 312 + UDF_SB_SESSION(sb) ||
-                                           !(bh = sb_bread(sb, last[i] - 312 - UDF_SB_SESSION(sb)))) {
-                                               ident = location = 0;
-                                       } else {
-                                               ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
-                                               location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
-                                               brelse(bh);
+                                       ident = location = 0;
+                                       if (last[i] >= 312 + sbi->s_session) {
+                                               bh = sb_bread(sb,
+                                                               last[i] - 312 -
+                                                               sbi->s_session);
+                                               if (bh) {
+                                                       tag *t = (tag *)
+                                                                bh->b_data;
+                                                       ident = le16_to_cpu(
+                                                               t->tagIdent);
+                                                       location = le32_to_cpu(
+                                                               t->tagLocation);
+                                                       brelse(bh);
+                                               }
                                        }
 
                                        if (ident == TAG_IDENT_AVDP &&
                                            location == udf_variable_to_fixed(last[i]) - 256) {
-                                               UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
+                                               UDF_SET_FLAG(sb,
+                                                            UDF_FLAG_VARCONV);
                                                lastblock = udf_variable_to_fixed(last[i]);
-                                               UDF_SB_ANCHOR(sb)[1] = lastblock - 256;
+                                               sbi->s_anchor[1] = lastblock - 256;
                                        }
                                }
                        }
@@ -716,10 +849,12 @@ static void udf_find_anchor(struct super_block *sb)
        }
 
        if (!lastblock) {
-               /* We havn't found the lastblock. check 312 */
-               if ((bh = sb_bread(sb, 312 + UDF_SB_SESSION(sb)))) {
-                       ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
-                       location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
+               /* We haven't found the lastblock. check 312 */
+               bh = sb_bread(sb, 312 + sbi->s_session);
+               if (bh) {
+                       tag *t = (tag *)bh->b_data;
+                       ident = le16_to_cpu(t->tagIdent);
+                       location = le32_to_cpu(t->tagLocation);
                        brelse(bh);
 
                        if (ident == TAG_IDENT_AVDP && location == 256)
@@ -727,29 +862,33 @@ static void udf_find_anchor(struct super_block *sb)
                }
        }
 
-       for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
-               if (UDF_SB_ANCHOR(sb)[i]) {
-                       if (!(bh = udf_read_tagged(sb, UDF_SB_ANCHOR(sb)[i],
-                                                  UDF_SB_ANCHOR(sb)[i], &ident))) {
-                               UDF_SB_ANCHOR(sb)[i] = 0;
-                       } else {
+       for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
+               if (sbi->s_anchor[i]) {
+                       bh = udf_read_tagged(sb, sbi->s_anchor[i],
+                                            sbi->s_anchor[i], &ident);
+                       if (!bh)
+                               sbi->s_anchor[i] = 0;
+                       else {
                                brelse(bh);
                                if ((ident != TAG_IDENT_AVDP) &&
-                                   (i || (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE))) {
-                                       UDF_SB_ANCHOR(sb)[i] = 0;
-                               }
+                                   (i || (ident != TAG_IDENT_FE &&
+                                          ident != TAG_IDENT_EFE)))
+                                       sbi->s_anchor[i] = 0;
                        }
                }
        }
 
-       UDF_SB_LASTBLOCK(sb) = lastblock;
+       sbi->s_last_block = lastblock;
 }
 
-static int udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, kernel_lb_addr *root)
+static int udf_find_fileset(struct super_block *sb,
+                           kernel_lb_addr *fileset,
+                           kernel_lb_addr *root)
 {
        struct buffer_head *bh = NULL;
        long lastblock;
        uint16_t ident;
+       struct udf_sb_info *sbi;
 
        if (fileset->logicalBlockNum != 0xFFFFFFFF ||
            fileset->partitionReferenceNum != 0xFFFF) {
@@ -764,22 +903,27 @@ static int udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, ker
 
        }
 
-       if (!bh) { /* Search backwards through the partitions */
+       sbi = UDF_SB(sb);
+       if (!bh) {
+               /* Search backwards through the partitions */
                kernel_lb_addr newfileset;
 
 /* --> cvg: FIXME - is it reasonable? */
                return 1;
 
-               for (newfileset.partitionReferenceNum = UDF_SB_NUMPARTS(sb) - 1;
+               for (newfileset.partitionReferenceNum = sbi->s_partitions - 1;
                     (newfileset.partitionReferenceNum != 0xFFFF &&
                      fileset->logicalBlockNum == 0xFFFFFFFF &&
                      fileset->partitionReferenceNum == 0xFFFF);
                     newfileset.partitionReferenceNum--) {
-                       lastblock = UDF_SB_PARTLEN(sb, newfileset.partitionReferenceNum);
+                       lastblock = sbi->s_partmaps
+                                       [newfileset.partitionReferenceNum]
+                                               .s_partition_len;
                        newfileset.logicalBlockNum = 0;
 
                        do {
-                               bh = udf_read_ptagged(sb, newfileset, 0, &ident);
+                               bh = udf_read_ptagged(sb, newfileset, 0,
+                                                     &ident);
                                if (!bh) {
                                        newfileset.logicalBlockNum++;
                                        continue;
@@ -789,11 +933,12 @@ static int udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, ker
                                case TAG_IDENT_SBD:
                                {
                                        struct spaceBitmapDesc *sp;
-                                       sp = (struct spaceBitmapDesc *)bh->b_data;
+                                       sp = (struct spaceBitmapDesc *)
+                                                               bh->b_data;
                                        newfileset.logicalBlockNum += 1 +
                                                ((le32_to_cpu(sp->numOfBytes) +
-                                                 sizeof(struct spaceBitmapDesc) - 1)
-                                                >> sb->s_blocksize_bits);
+                                                 sizeof(struct spaceBitmapDesc)
+                                                 - 1) >> sb->s_blocksize_bits);
                                        brelse(bh);
                                        break;
                                }
@@ -818,7 +963,7 @@ static int udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, ker
                          fileset->logicalBlockNum,
                          fileset->partitionReferenceNum);
 
-               UDF_SB_PARTITION(sb) = fileset->partitionReferenceNum;
+               sbi->s_partition = fileset->partitionReferenceNum;
                udf_load_fileset(sb, bh, root);
                brelse(bh);
                return 0;
@@ -840,26 +985,26 @@ static void udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
                              lets_to_cpu(pvoldesc->recordingDateAndTime))) {
                kernel_timestamp ts;
                ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
-               udf_debug("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n",
+               udf_debug("recording time %ld/%ld, %04u/%02u/%02u"
+                         " %02u:%02u (%x)\n",
                          recording, recording_usec,
                          ts.year, ts.month, ts.day, ts.hour,
                          ts.minute, ts.typeAndTimezone);
-               UDF_SB_RECORDTIME(sb).tv_sec = recording;
-               UDF_SB_RECORDTIME(sb).tv_nsec = recording_usec * 1000;
+               UDF_SB(sb)->s_record_time.tv_sec = recording;
+               UDF_SB(sb)->s_record_time.tv_nsec = recording_usec * 1000;
        }
 
-       if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32)) {
+       if (!udf_build_ustr(&instr, pvoldesc->volIdent, 32))
                if (udf_CS0toUTF8(&outstr, &instr)) {
-                       strncpy(UDF_SB_VOLIDENT(sb), outstr.u_name,
+                       strncpy(UDF_SB(sb)->s_volume_ident, outstr.u_name,
                                outstr.u_len > 31 ? 31 : outstr.u_len);
-                       udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb));
+                       udf_debug("volIdent[] = '%s'\n",
+                                       UDF_SB(sb)->s_volume_ident);
                }
-       }
 
-       if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128)) {
+       if (!udf_build_ustr(&instr, pvoldesc->volSetIdent, 128))
                if (udf_CS0toUTF8(&outstr, &instr))
                        udf_debug("volSetIdent[] = '%s'\n", outstr.u_name);
-       }
 }
 
 static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
@@ -871,65 +1016,124 @@ static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
 
        *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
 
-       UDF_SB_SERIALNUM(sb) = le16_to_cpu(fset->descTag.tagSerialNum);
+       UDF_SB(sb)->s_serial_number = le16_to_cpu(fset->descTag.tagSerialNum);
 
        udf_debug("Rootdir at block=%d, partition=%d\n",
                  root->logicalBlockNum, root->partitionReferenceNum);
 }
 
+int udf_compute_nr_groups(struct super_block *sb, u32 partition)
+{
+       struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
+       return (map->s_partition_len +
+               (sizeof(struct spaceBitmapDesc) << 3) +
+               (sb->s_blocksize * 8) - 1) /
+               (sb->s_blocksize * 8);
+}
+
+static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
+{
+       struct udf_bitmap *bitmap;
+       int nr_groups;
+       int size;
+
+       nr_groups = udf_compute_nr_groups(sb, index);
+       size = sizeof(struct udf_bitmap) +
+               (sizeof(struct buffer_head *) * nr_groups);
+
+       if (size <= PAGE_SIZE)
+               bitmap = kmalloc(size, GFP_KERNEL);
+       else
+               bitmap = vmalloc(size); /* TODO: get rid of vmalloc */
+
+       if (bitmap == NULL) {
+               udf_error(sb, __FUNCTION__,
+                         "Unable to allocate space for bitmap "
+                         "and %d buffer_head pointers", nr_groups);
+               return NULL;
+       }
+
+       memset(bitmap, 0x00, size);
+       bitmap->s_block_bitmap = (struct buffer_head **)(bitmap + 1);
+       bitmap->s_nr_groups = nr_groups;
+       return bitmap;
+}
+
 static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
 {
        struct partitionDesc *p;
        int i;
+       struct udf_part_map *map;
+       struct udf_sb_info *sbi;
 
        p = (struct partitionDesc *)bh->b_data;
+       sbi = UDF_SB(sb);
 
-       for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
+       for (i = 0; i < sbi->s_partitions; i++) {
+               map = &sbi->s_partmaps[i];
                udf_debug("Searching map: (%d == %d)\n",
-                         UDF_SB_PARTMAPS(sb)[i].s_partition_num, le16_to_cpu(p->partitionNumber));
-               if (UDF_SB_PARTMAPS(sb)[i].s_partition_num == le16_to_cpu(p->partitionNumber)) {
-                       UDF_SB_PARTLEN(sb,i) = le32_to_cpu(p->partitionLength); /* blocks */
-                       UDF_SB_PARTROOT(sb,i) = le32_to_cpu(p->partitionStartingLocation);
-                       if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_READ_ONLY)
-                               UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_READ_ONLY;
-                       if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_WRITE_ONCE)
-                               UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_WRITE_ONCE;
-                       if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_REWRITABLE)
-                               UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_REWRITABLE;
-                       if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_OVERWRITABLE)
-                               UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_OVERWRITABLE;
-
-                       if (!strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) ||
-                           !strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03)) {
+                         map->s_partition_num,
+                         le16_to_cpu(p->partitionNumber));
+               if (map->s_partition_num ==
+                               le16_to_cpu(p->partitionNumber)) {
+                       map->s_partition_len =
+                               le32_to_cpu(p->partitionLength); /* blocks */
+                       map->s_partition_root =
+                               le32_to_cpu(p->partitionStartingLocation);
+                       if (p->accessType ==
+                                       cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
+                               map->s_partition_flags |=
+                                               UDF_PART_FLAG_READ_ONLY;
+                       if (p->accessType ==
+                                       cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
+                               map->s_partition_flags |=
+                                               UDF_PART_FLAG_WRITE_ONCE;
+                       if (p->accessType ==
+                                       cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
+                               map->s_partition_flags |=
+                                               UDF_PART_FLAG_REWRITABLE;
+                       if (p->accessType ==
+                                   cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
+                               map->s_partition_flags |=
+                                               UDF_PART_FLAG_OVERWRITABLE;
+
+                       if (!strcmp(p->partitionContents.ident,
+                                   PD_PARTITION_CONTENTS_NSR02) ||
+                           !strcmp(p->partitionContents.ident,
+                                   PD_PARTITION_CONTENTS_NSR03)) {
                                struct partitionHeaderDesc *phd;
 
-                               phd = (struct partitionHeaderDesc *)(p->partitionContentsUse);
+                               phd = (struct partitionHeaderDesc *)
+                                               (p->partitionContentsUse);
                                if (phd->unallocSpaceTable.extLength) {
                                        kernel_lb_addr loc = {
                                                .logicalBlockNum = le32_to_cpu(phd->unallocSpaceTable.extPosition),
                                                .partitionReferenceNum = i,
                                        };
 
-                                       UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table =
+                                       map->s_uspace.s_table =
                                                udf_iget(sb, loc);
-                                       if (!UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table) {
+                                       if (!map->s_uspace.s_table) {
                                                udf_debug("cannot load unallocSpaceTable (part %d)\n", i);
                                                return 1;
                                        }
-                                       UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_TABLE;
+                                       map->s_partition_flags |=
+                                               UDF_PART_FLAG_UNALLOC_TABLE;
                                        udf_debug("unallocSpaceTable (part %d) @ %ld\n",
-                                                 i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table->i_ino);
+                                                 i, map->s_uspace.s_table->i_ino);
                                }
                                if (phd->unallocSpaceBitmap.extLength) {
-                                       UDF_SB_ALLOC_BITMAP(sb, i, s_uspace);
-                                       if (UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap != NULL) {
-                                               UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extLength =
+                                       struct udf_bitmap *bitmap =
+                                               udf_sb_alloc_bitmap(sb, i);
+                                       map->s_uspace.s_bitmap = bitmap;
+                                       if (bitmap != NULL) {
+                                               bitmap->s_extLength =
                                                        le32_to_cpu(phd->unallocSpaceBitmap.extLength);
-                                               UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition =
+                                               bitmap->s_extPosition =
                                                        le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
-                                               UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_BITMAP;
+                                               map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
                                                udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
-                                                         i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition);
+                                                         i, bitmap->s_extPosition);
                                        }
                                }
                                if (phd->partitionIntegrityTable.extLength)
@@ -940,40 +1144,45 @@ static int udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
                                                .partitionReferenceNum = i,
                                        };
 
-                                       UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table =
+                                       map->s_fspace.s_table =
                                                udf_iget(sb, loc);
-                                       if (!UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table) {
+                                       if (!map->s_fspace.s_table) {
                                                udf_debug("cannot load freedSpaceTable (part %d)\n", i);
                                                return 1;
                                        }
-                                       UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_TABLE;
+                                       map->s_partition_flags |=
+                                               UDF_PART_FLAG_FREED_TABLE;
                                        udf_debug("freedSpaceTable (part %d) @ %ld\n",
-                                                 i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table->i_ino);
+                                                 i, map->s_fspace.s_table->i_ino);
                                }
                                if (phd->freedSpaceBitmap.extLength) {
-                                       UDF_SB_ALLOC_BITMAP(sb, i, s_fspace);
-                                       if (UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap != NULL) {
-                                               UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extLength =
+                                       struct udf_bitmap *bitmap =
+                                               udf_sb_alloc_bitmap(sb, i);
+                                       map->s_fspace.s_bitmap = bitmap;
+                                       if (bitmap != NULL) {
+                                               bitmap->s_extLength =
                                                        le32_to_cpu(phd->freedSpaceBitmap.extLength);
-                                               UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition =
+                                               bitmap->s_extPosition =
                                                        le32_to_cpu(phd->freedSpaceBitmap.extPosition);
-                                               UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_BITMAP;
+                                               map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
                                                udf_debug("freedSpaceBitmap (part %d) @ %d\n",
-                                                         i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition);
+                                                         i, bitmap->s_extPosition);
                                        }
                                }
                        }
                        break;
                }
        }
-       if (i == UDF_SB_NUMPARTS(sb)) {
+       if (i == sbi->s_partitions)
                udf_debug("Partition (%d) not found in partition map\n",
                          le16_to_cpu(p->partitionNumber));
-       } else {
-               udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n",
-                         le16_to_cpu(p->partitionNumber), i, UDF_SB_PARTTYPE(sb,i),
-                         UDF_SB_PARTROOT(sb,i), UDF_SB_PARTLEN(sb,i));
-       }
+       else
+               udf_debug("Partition (%d:%d type %x) starts at physical %d, "
+                         "block length %d\n",
+                         le16_to_cpu(p->partitionNumber), i,
+                         map->s_partition_type,
+                         map->s_partition_root,
+                         map->s_partition_len);
        return 0;
 }
 
@@ -983,70 +1192,105 @@ static int udf_load_logicalvol(struct super_block *sb, struct buffer_head *bh,
        struct logicalVolDesc *lvd;
        int i, j, offset;
        uint8_t type;
+       struct udf_sb_info *sbi = UDF_SB(sb);
+       struct genericPartitionMap *gpm;
 
        lvd = (struct logicalVolDesc *)bh->b_data;
 
-       UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps));
+       i = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps));
+       if (i != 0)
+               return i;
 
        for (i = 0, offset = 0;
-            i < UDF_SB_NUMPARTS(sb) && offset < le32_to_cpu(lvd->mapTableLength);
-            i++, offset += ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapLength) {
-               type = ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapType;
+            i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength);
+            i++, offset += gpm->partitionMapLength) {
+               struct udf_part_map *map = &sbi->s_partmaps[i];
+               gpm = (struct genericPartitionMap *)
+                               &(lvd->partitionMaps[offset]);
+               type = gpm->partitionMapType;
                if (type == 1) {
-                       struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)&(lvd->partitionMaps[offset]);
-                       UDF_SB_PARTTYPE(sb,i) = UDF_TYPE1_MAP15;
-                       UDF_SB_PARTVSN(sb,i) = le16_to_cpu(gpm1->volSeqNum);
-                       UDF_SB_PARTNUM(sb,i) = le16_to_cpu(gpm1->partitionNum);
-                       UDF_SB_PARTFUNC(sb,i) = NULL;
+                       struct genericPartitionMap1 *gpm1 =
+                               (struct genericPartitionMap1 *)gpm;
+                       map->s_partition_type = UDF_TYPE1_MAP15;
+                       map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum);
+                       map->s_partition_num = le16_to_cpu(gpm1->partitionNum);
+                       map->s_partition_func = NULL;
                } else if (type == 2) {
-                       struct udfPartitionMap2 *upm2 = (struct udfPartitionMap2 *)&(lvd->partitionMaps[offset]);
-                       if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, strlen(UDF_ID_VIRTUAL))) {
-                               if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0150) {
-                                       UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP15;
-                                       UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt15;
-                               } else if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0200) {
-                                       UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP20;
-                                       UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt20;
+                       struct udfPartitionMap2 *upm2 =
+                                               (struct udfPartitionMap2 *)gpm;
+                       if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL,
+                                               strlen(UDF_ID_VIRTUAL))) {
+                               u16 suf =
+                                       le16_to_cpu(((__le16 *)upm2->partIdent.
+                                                       identSuffix)[0]);
+                               if (suf == 0x0150) {
+                                       map->s_partition_type =
+                                                       UDF_VIRTUAL_MAP15;
+                                       map->s_partition_func =
+                                                       udf_get_pblock_virt15;
+                               } else if (suf == 0x0200) {
+                                       map->s_partition_type =
+                                                       UDF_VIRTUAL_MAP20;
+                                       map->s_partition_func =
+                                                       udf_get_pblock_virt20;
                                }
-                       } else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE))) {
+                       } else if (!strncmp(upm2->partIdent.ident,
+                                               UDF_ID_SPARABLE,
+                                               strlen(UDF_ID_SPARABLE))) {
                                uint32_t loc;
                                uint16_t ident;
                                struct sparingTable *st;
-                               struct sparablePartitionMap *spm = (struct sparablePartitionMap *)&(lvd->partitionMaps[offset]);
+                               struct sparablePartitionMap *spm =
+                                       (struct sparablePartitionMap *)gpm;
 
-                               UDF_SB_PARTTYPE(sb,i) = UDF_SPARABLE_MAP15;
-                               UDF_SB_TYPESPAR(sb,i).s_packet_len = le16_to_cpu(spm->packetLength);
+                               map->s_partition_type = UDF_SPARABLE_MAP15;
+                               map->s_type_specific.s_sparing.s_packet_len =
+                                               le16_to_cpu(spm->packetLength);
                                for (j = 0; j < spm->numSparingTables; j++) {
-                                       loc = le32_to_cpu(spm->locSparingTable[j]);
-                                       UDF_SB_TYPESPAR(sb,i).s_spar_map[j] =
-                                               udf_read_tagged(sb, loc, loc, &ident);
-                                       if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL) {
-                                               st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,i).s_spar_map[j]->b_data;
-                                               if (ident != 0 ||
-                                                   strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING))) {
-                                                       brelse(UDF_SB_TYPESPAR(sb,i).s_spar_map[j]);
-                                                       UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = NULL;
+                                       struct buffer_head *bh2;
+
+                                       loc = le32_to_cpu(
+                                               spm->locSparingTable[j]);
+                                       bh2 = udf_read_tagged(sb, loc, loc,
+                                                            &ident);
+                                       map->s_type_specific.s_sparing.
+                                                       s_spar_map[j] = bh2;
+
+                                       if (bh2 != NULL) {
+                                               st = (struct sparingTable *)
+                                                               bh2->b_data;
+                                               if (ident != 0 || strncmp(
+                                                       st->sparingIdent.ident,
+                                                       UDF_ID_SPARING,
+                                                       strlen(UDF_ID_SPARING))) {
+                                                       brelse(bh2);
+                                                       map->s_type_specific.
+                                                               s_sparing.
+                                                               s_spar_map[j] =
+                                                                       NULL;
                                                }
                                        }
                                }
-                               UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_spar15;
+                               map->s_partition_func = udf_get_pblock_spar15;
                        } else {
-                               udf_debug("Unknown ident: %s\n", upm2->partIdent.ident);
+                               udf_debug("Unknown ident: %s\n",
+                                         upm2->partIdent.ident);
                                continue;
                        }
-                       UDF_SB_PARTVSN(sb,i) = le16_to_cpu(upm2->volSeqNum);
-                       UDF_SB_PARTNUM(sb,i) = le16_to_cpu(upm2->partitionNum);
+                       map->s_volumeseqnum = le16_to_cpu(upm2->volSeqNum);
+                       map->s_partition_num = le16_to_cpu(upm2->partitionNum);
                }
                udf_debug("Partition (%d:%d) type %d on volume %d\n",
-                         i, UDF_SB_PARTNUM(sb,i), type, UDF_SB_PARTVSN(sb,i));
+                         i, map->s_partition_num, type,
+                         map->s_volumeseqnum);
        }
 
        if (fileset) {
                long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]);
 
                *fileset = lelb_to_cpu(la->extLocation);
-               udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
-                         fileset->logicalBlockNum,
+               udf_debug("FileSet found in LogicalVolDesc at block=%d, "
+                         "partition=%d\n", fileset->logicalBlockNum,
                          fileset->partitionReferenceNum);
        }
        if (lvd->integritySeqExt.extLength)
@@ -1063,22 +1307,26 @@ static void udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
 {
        struct buffer_head *bh = NULL;
        uint16_t ident;
+       struct udf_sb_info *sbi = UDF_SB(sb);
+       struct logicalVolIntegrityDesc *lvid;
 
        while (loc.extLength > 0 &&
               (bh = udf_read_tagged(sb, loc.extLocation,
                                     loc.extLocation, &ident)) &&
               ident == TAG_IDENT_LVID) {
-               UDF_SB_LVIDBH(sb) = bh;
+               sbi->s_lvid_bh = bh;
+               lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
 
-               if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength)
-                       udf_load_logicalvolint(sb, leea_to_cpu(UDF_SB_LVID(sb)->nextIntegrityExt));
+               if (lvid->nextIntegrityExt.extLength)
+                       udf_load_logicalvolint(sb,
+                               leea_to_cpu(lvid->nextIntegrityExt));
 
-               if (UDF_SB_LVIDBH(sb) != bh)
+               if (sbi->s_lvid_bh != bh)
                        brelse(bh);
                loc.extLength -= sb->s_blocksize;
                loc.extLocation++;
        }
-       if (UDF_SB_LVIDBH(sb) != bh)
+       if (sbi->s_lvid_bh != bh)
                brelse(bh);
 }
 
@@ -1097,11 +1345,12 @@ static void udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
  *     July 1, 1997 - Andrew E. Mileski
  *     Written, tested, and released.
  */
-static int udf_process_sequence(struct super_block *sb, long block, long lastblock,
-                                kernel_lb_addr *fileset)
+static int udf_process_sequence(struct super_block *sb, long block,
+                               long lastblock, kernel_lb_addr *fileset)
 {
        struct buffer_head *bh = NULL;
        struct udf_vds_record vds[VDS_POS_LENGTH];
+       struct udf_vds_record *curr;
        struct generic_desc *gd;
        struct volDescPtr *vdp;
        int done = 0;
@@ -1124,43 +1373,51 @@ static int udf_process_sequence(struct super_block *sb, long block, long lastblo
                vdsn = le32_to_cpu(gd->volDescSeqNum);
                switch (ident) {
                case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
-                       if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum) {
-                               vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn;
-                               vds[VDS_POS_PRIMARY_VOL_DESC].block = block;
+                       curr = &vds[VDS_POS_PRIMARY_VOL_DESC];
+                       if (vdsn >= curr->volDescSeqNum) {
+                               curr->volDescSeqNum = vdsn;
+                               curr->block = block;
                        }
                        break;
                case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
-                       if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum) {
-                               vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn;
-                               vds[VDS_POS_VOL_DESC_PTR].block = block;
+                       curr = &vds[VDS_POS_VOL_DESC_PTR];
+                       if (vdsn >= curr->volDescSeqNum) {
+                               curr->volDescSeqNum = vdsn;
+                               curr->block = block;
 
                                vdp = (struct volDescPtr *)bh->b_data;
-                               next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation);
-                               next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength);
+                               next_s = le32_to_cpu(
+                                       vdp->nextVolDescSeqExt.extLocation);
+                               next_e = le32_to_cpu(
+                                       vdp->nextVolDescSeqExt.extLength);
                                next_e = next_e >> sb->s_blocksize_bits;
                                next_e += next_s;
                        }
                        break;
                case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
-                       if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum) {
-                               vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn;
-                               vds[VDS_POS_IMP_USE_VOL_DESC].block = block;
+                       curr = &vds[VDS_POS_IMP_USE_VOL_DESC];
+                       if (vdsn >= curr->volDescSeqNum) {
+                               curr->volDescSeqNum = vdsn;
+                               curr->block = block;
                        }
                        break;
                case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
-                       if (!vds[VDS_POS_PARTITION_DESC].block)
-                               vds[VDS_POS_PARTITION_DESC].block = block;
+                       curr = &vds[VDS_POS_PARTITION_DESC];
+                       if (!curr->block)
+                               curr->block = block;
                        break;
                case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
-                       if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum) {
-                               vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn;
-                               vds[VDS_POS_LOGICAL_VOL_DESC].block = block;
+                       curr = &vds[VDS_POS_LOGICAL_VOL_DESC];
+                       if (vdsn >= curr->volDescSeqNum) {
+                               curr->volDescSeqNum = vdsn;
+                               curr->block = block;
                        }
                        break;
                case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
-                       if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum) {
-                               vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn;
-                               vds[VDS_POS_UNALLOC_SPACE_DESC].block = block;
+                       curr = &vds[VDS_POS_UNALLOC_SPACE_DESC];
+                       if (vdsn >= curr->volDescSeqNum) {
+                               curr->volDescSeqNum = vdsn;
+                               curr->block = block;
                        }
                        break;
                case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
@@ -1169,32 +1426,38 @@ static int udf_process_sequence(struct super_block *sb, long block, long lastblo
                                block = next_s;
                                lastblock = next_e;
                                next_s = next_e = 0;
-                       } else {
+                       } else
                                done = 1;
-                       }
                        break;
                }
                brelse(bh);
        }
        for (i = 0; i < VDS_POS_LENGTH; i++) {
                if (vds[i].block) {
-                       bh = udf_read_tagged(sb, vds[i].block, vds[i].block, &ident);
+                       bh = udf_read_tagged(sb, vds[i].block, vds[i].block,
+                                            &ident);
 
                        if (i == VDS_POS_PRIMARY_VOL_DESC) {
                                udf_load_pvoldesc(sb, bh);
                        } else if (i == VDS_POS_LOGICAL_VOL_DESC) {
-                               udf_load_logicalvol(sb, bh, fileset);
+                               if (udf_load_logicalvol(sb, bh, fileset)) {
+                                       brelse(bh);
+                                       return 1;
+                               }
                        } else if (i == VDS_POS_PARTITION_DESC) {
                                struct buffer_head *bh2 = NULL;
                                if (udf_load_partdesc(sb, bh)) {
                                        brelse(bh);
                                        return 1;
                                }
-                               for (j = vds[i].block + 1; j <  vds[VDS_POS_TERMINATING_DESC].block; j++) {
+                               for (j = vds[i].block + 1;
+                                    j <  vds[VDS_POS_TERMINATING_DESC].block;
+                                    j++) {
                                        bh2 = udf_read_tagged(sb, j, j, &ident);
                                        gd = (struct generic_desc *)bh2->b_data;
                                        if (ident == TAG_IDENT_PD)
-                                               if (udf_load_partdesc(sb, bh2)) {
+                                               if (udf_load_partdesc(sb,
+                                                                     bh2)) {
                                                        brelse(bh);
                                                        brelse(bh2);
                                                        return 1;
@@ -1222,14 +1485,17 @@ static int udf_check_valid(struct super_block *sb, int novrs, int silent)
        }
        /* Check that it is NSR02 compliant */
        /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
-       else if ((block = udf_vrs(sb, silent)) == -1) {
-               udf_debug("Failed to read byte 32768. Assuming open disc. "
-                         "Skipping validity check\n");
-               if (!UDF_SB_LASTBLOCK(sb))
-                       UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
-               return 0;
-       } else {
-               return !block;
+       else {
+               block = udf_vrs(sb, silent);
+               if (block == -1) {
+                       struct udf_sb_info *sbi = UDF_SB(sb);
+                       udf_debug("Failed to read byte 32768. Assuming open "
+                                 "disc. Skipping validity check\n");
+                       if (!sbi->s_last_block)
+                               sbi->s_last_block = udf_get_last_block(sb);
+                       return 0;
+               } else
+                       return !block;
        }
 }
 
@@ -1240,100 +1506,121 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
        struct buffer_head *bh;
        long main_s, main_e, reserve_s, reserve_e;
        int i, j;
+       struct udf_sb_info *sbi;
 
        if (!sb)
                return 1;
+       sbi = UDF_SB(sb);
 
-       for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
-               if (UDF_SB_ANCHOR(sb)[i] &&
-                   (bh = udf_read_tagged(sb, UDF_SB_ANCHOR(sb)[i],
-                                         UDF_SB_ANCHOR(sb)[i], &ident))) {
-                       anchor = (struct anchorVolDescPtr *)bh->b_data;
+       for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
+               if (!sbi->s_anchor[i])
+                       continue;
+               bh = udf_read_tagged(sb, sbi->s_anchor[i], sbi->s_anchor[i],
+                                    &ident);
+               if (!bh)
+                       continue;
 
-                       /* Locate the main sequence */
-                       main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
-                       main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength );
-                       main_e = main_e >> sb->s_blocksize_bits;
-                       main_e += main_s;
+               anchor = (struct anchorVolDescPtr *)bh->b_data;
 
-                       /* Locate the reserve sequence */
-                       reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation);
-                       reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
-                       reserve_e = reserve_e >> sb->s_blocksize_bits;
-                       reserve_e += reserve_s;
+               /* Locate the main sequence */
+               main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
+               main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength);
+               main_e = main_e >> sb->s_blocksize_bits;
+               main_e += main_s;
 
-                       brelse(bh);
+               /* Locate the reserve sequence */
+               reserve_s = le32_to_cpu(
+                               anchor->reserveVolDescSeqExt.extLocation);
+               reserve_e = le32_to_cpu(
+                               anchor->reserveVolDescSeqExt.extLength);
+               reserve_e = reserve_e >> sb->s_blocksize_bits;
+               reserve_e += reserve_s;
 
-                       /* Process the main & reserve sequences */
-                       /* responsible for finding the PartitionDesc(s) */
-                       if (!(udf_process_sequence(sb, main_s, main_e, fileset) &&
-                             udf_process_sequence(sb, reserve_s, reserve_e, fileset))) {
-                               break;
-                       }
-               }
+               brelse(bh);
+
+               /* Process the main & reserve sequences */
+               /* responsible for finding the PartitionDesc(s) */
+               if (!(udf_process_sequence(sb, main_s, main_e,
+                                          fileset) &&
+                     udf_process_sequence(sb, reserve_s, reserve_e,
+                                          fileset)))
+                       break;
        }
 
-       if (i == ARRAY_SIZE(UDF_SB_ANCHOR(sb))) {
+       if (i == ARRAY_SIZE(sbi->s_anchor)) {
                udf_debug("No Anchor block found\n");
                return 1;
-       } else
-               udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]);
+       }
+       udf_debug("Using anchor in block %d\n", sbi->s_anchor[i]);
 
-       for (i = 0; i < UDF_SB_NUMPARTS(sb); i++) {
+       for (i = 0; i < sbi->s_partitions; i++) {
                kernel_lb_addr uninitialized_var(ino);
-               switch (UDF_SB_PARTTYPE(sb, i)) {
+               struct udf_part_map *map = &sbi->s_partmaps[i];
+               switch (map->s_partition_type) {
                case UDF_VIRTUAL_MAP15:
                case UDF_VIRTUAL_MAP20:
-                       if (!UDF_SB_LASTBLOCK(sb)) {
-                               UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
+                       if (!sbi->s_last_block) {
+                               sbi->s_last_block = udf_get_last_block(sb);
                                udf_find_anchor(sb);
                        }
 
-                       if (!UDF_SB_LASTBLOCK(sb)) {
+                       if (!sbi->s_last_block) {
                                udf_debug("Unable to determine Lastblock (For "
                                          "Virtual Partition)\n");
                                return 1;
                        }
 
-                       for (j = 0; j < UDF_SB_NUMPARTS(sb); j++) {
+                       for (j = 0; j < sbi->s_partitions; j++) {
+                               struct udf_part_map *map2 = &sbi->s_partmaps[j];
                                if (j != i &&
-                                   UDF_SB_PARTVSN(sb, i) == UDF_SB_PARTVSN(sb, j) &&
-                                   UDF_SB_PARTNUM(sb, i) == UDF_SB_PARTNUM(sb, j)) {
+                                   map->s_volumeseqnum ==
+                                               map2->s_volumeseqnum &&
+                                   map->s_partition_num ==
+                                               map2->s_partition_num) {
                                        ino.partitionReferenceNum = j;
-                                       ino.logicalBlockNum = UDF_SB_LASTBLOCK(sb) - UDF_SB_PARTROOT(sb, j);
+                                       ino.logicalBlockNum =
+                                               sbi->s_last_block -
+                                                       map2->s_partition_root;
                                        break;
                                }
                        }
 
-                       if (j == UDF_SB_NUMPARTS(sb))
+                       if (j == sbi->s_partitions)
                                return 1;
 
-                       if (!(UDF_SB_VAT(sb) = udf_iget(sb, ino)))
+                       sbi->s_vat_inode = udf_iget(sb, ino);
+                       if (!sbi->s_vat_inode)
                                return 1;
 
-                       if (UDF_SB_PARTTYPE(sb, i) == UDF_VIRTUAL_MAP15) {
-                               UDF_SB_TYPEVIRT(sb, i).s_start_offset =
-                                       udf_ext0_offset(UDF_SB_VAT(sb));
-                               UDF_SB_TYPEVIRT(sb, i).s_num_entries =
-                                       (UDF_SB_VAT(sb)->i_size - 36) >> 2;
-                       } else if (UDF_SB_PARTTYPE(sb, i) == UDF_VIRTUAL_MAP20) {
-                               struct buffer_head *bh = NULL;
+                       if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
+                               map->s_type_specific.s_virtual.s_start_offset =
+                                       udf_ext0_offset(sbi->s_vat_inode);
+                               map->s_type_specific.s_virtual.s_num_entries =
+                                       (sbi->s_vat_inode->i_size - 36) >> 2;
+                       } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
                                uint32_t pos;
+                               struct virtualAllocationTable20 *vat20;
 
-                               pos = udf_block_map(UDF_SB_VAT(sb), 0);
+                               pos = udf_block_map(sbi->s_vat_inode, 0);
                                bh = sb_bread(sb, pos);
                                if (!bh)
                                        return 1;
-                               UDF_SB_TYPEVIRT(sb, i).s_start_offset =
-                                       le16_to_cpu(((struct virtualAllocationTable20 *)bh->b_data +
-                                                    udf_ext0_offset(UDF_SB_VAT(sb)))->lengthHeader) +
-                                       udf_ext0_offset(UDF_SB_VAT(sb));
-                               UDF_SB_TYPEVIRT(sb, i).s_num_entries = (UDF_SB_VAT(sb)->i_size -
-                                                                       UDF_SB_TYPEVIRT(sb, i).s_start_offset) >> 2;
+                               vat20 = (struct virtualAllocationTable20 *)
+                                       bh->b_data +
+                                       udf_ext0_offset(sbi->s_vat_inode);
+                               map->s_type_specific.s_virtual.s_start_offset =
+                                       le16_to_cpu(vat20->lengthHeader) +
+                                       udf_ext0_offset(sbi->s_vat_inode);
+                               map->s_type_specific.s_virtual.s_num_entries =
+                                       (sbi->s_vat_inode->i_size -
+                                        map->s_type_specific.s_virtual.
+                                                       s_start_offset) >> 2;
                                brelse(bh);
                        }
-                       UDF_SB_PARTROOT(sb, i) = udf_get_pblock(sb, 0, i, 0);
-                       UDF_SB_PARTLEN(sb, i) = UDF_SB_PARTLEN(sb, ino.partitionReferenceNum);
+                       map->s_partition_root = udf_get_pblock(sb, 0, i, 0);
+                       map->s_partition_len =
+                               sbi->s_partmaps[ino.partitionReferenceNum].
+                                                               s_partition_len;
                }
        }
        return 0;
@@ -1341,62 +1628,86 @@ static int udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
 
 static void udf_open_lvid(struct super_block *sb)
 {
-       if (UDF_SB_LVIDBH(sb)) {
-               int i;
+       struct udf_sb_info *sbi = UDF_SB(sb);
+       struct buffer_head *bh = sbi->s_lvid_bh;
+       if (bh) {
                kernel_timestamp cpu_time;
+               struct logicalVolIntegrityDesc *lvid =
+                               (struct logicalVolIntegrityDesc *)bh->b_data;
+               struct logicalVolIntegrityDescImpUse *lvidiu =
+                                                       udf_sb_lvidiu(sbi);
 
-               UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
-               UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
+               lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
+               lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
                if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
-                       UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time);
-               UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_OPEN;
-
-               UDF_SB_LVID(sb)->descTag.descCRC = cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
-                                                                      le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0));
+                       lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
+               lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
 
-               UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
-               for (i = 0; i < 16; i++)
-                       if (i != 4)
-                               UDF_SB_LVID(sb)->descTag.tagChecksum +=
-                                       ((uint8_t *) &(UDF_SB_LVID(sb)->descTag))[i];
+               lvid->descTag.descCRC = cpu_to_le16(
+                       udf_crc((char *)lvid + sizeof(tag),
+                               le16_to_cpu(lvid->descTag.descCRCLength),
+                               0));
 
-               mark_buffer_dirty(UDF_SB_LVIDBH(sb));
+               lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
+               mark_buffer_dirty(bh);
        }
 }
 
 static void udf_close_lvid(struct super_block *sb)
 {
        kernel_timestamp cpu_time;
-       int i;
+       struct udf_sb_info *sbi = UDF_SB(sb);
+       struct buffer_head *bh = sbi->s_lvid_bh;
+       struct logicalVolIntegrityDesc *lvid;
+
+       if (!bh)
+               return;
+
+       lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
 
-       if (UDF_SB_LVIDBH(sb) &&
-           UDF_SB_LVID(sb)->integrityType == LVID_INTEGRITY_TYPE_OPEN) {
-               UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
-               UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
+       if (lvid->integrityType == LVID_INTEGRITY_TYPE_OPEN) {
+               struct logicalVolIntegrityDescImpUse *lvidiu =
+                                                       udf_sb_lvidiu(sbi);
+               lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
+               lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
                if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
-                       UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time);
-               if (UDF_MAX_WRITE_VERSION > le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev))
-                       UDF_SB_LVIDIU(sb)->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
-               if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev))
-                       UDF_SB_LVIDIU(sb)->minUDFReadRev = cpu_to_le16(UDF_SB_UDFREV(sb));
-               if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev))
-                       UDF_SB_LVIDIU(sb)->minUDFWriteRev = cpu_to_le16(UDF_SB_UDFREV(sb));
-               UDF_SB_LVID(sb)->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
-
-               UDF_SB_LVID(sb)->descTag.descCRC =
-                       cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
-                                           le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0));
-
-               UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
-               for (i = 0; i < 16; i++)
-                       if (i != 4)
-                               UDF_SB_LVID(sb)->descTag.tagChecksum +=
-                                       ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i];
-
-               mark_buffer_dirty(UDF_SB_LVIDBH(sb));
+                       lvid->recordingDateAndTime = cpu_to_lets(cpu_time);
+               if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
+                       lvidiu->maxUDFWriteRev =
+                                       cpu_to_le16(UDF_MAX_WRITE_VERSION);
+               if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
+                       lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
+               if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
+                       lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
+               lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
+
+               lvid->descTag.descCRC = cpu_to_le16(
+                       udf_crc((char *)lvid + sizeof(tag),
+                               le16_to_cpu(lvid->descTag.descCRCLength),
+                               0));
+
+               lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
+               mark_buffer_dirty(bh);
        }
 }
 
+static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
+{
+       int i;
+       int nr_groups = bitmap->s_nr_groups;
+       int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) *
+                                               nr_groups);
+
+       for (i = 0; i < nr_groups; i++)
+               if (bitmap->s_block_bitmap[i])
+                       brelse(bitmap->s_block_bitmap[i]);
+
+       if (size <= PAGE_SIZE)
+               kfree(bitmap);
+       else
+               vfree(bitmap);
+}
+
 /*
  * udf_read_super
  *
@@ -1426,16 +1737,15 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
        uopt.gid = -1;
        uopt.umask = 0;
 
-       sbi = kmalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
+       sbi = kzalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
        if (!sbi)
                return -ENOMEM;
 
        sb->s_fs_info = sbi;
-       memset(UDF_SB(sb), 0x00, sizeof(struct udf_sb_info));
 
        mutex_init(&sbi->s_alloc_mutex);
 
-       if (!udf_parse_options((char *)options, &uopt))
+       if (!udf_parse_options((char *)options, &uopt, false))
                goto error_out;
 
        if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
@@ -1459,30 +1769,31 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
        fileset.logicalBlockNum = 0xFFFFFFFF;
        fileset.partitionReferenceNum = 0xFFFF;
 
-       UDF_SB(sb)->s_flags = uopt.flags;
-       UDF_SB(sb)->s_uid = uopt.uid;
-       UDF_SB(sb)->s_gid = uopt.gid;
-       UDF_SB(sb)->s_umask = uopt.umask;
-       UDF_SB(sb)->s_nls_map = uopt.nls_map;
+       sbi->s_flags = uopt.flags;
+       sbi->s_uid = uopt.uid;
+       sbi->s_gid = uopt.gid;
+       sbi->s_umask = uopt.umask;
+       sbi->s_nls_map = uopt.nls_map;
 
        /* Set the block size for all transfers */
        if (!udf_set_blocksize(sb, uopt.blocksize))
                goto error_out;
 
        if (uopt.session == 0xFFFFFFFF)
-               UDF_SB_SESSION(sb) = udf_get_last_session(sb);
+               sbi->s_session = udf_get_last_session(sb);
        else
-               UDF_SB_SESSION(sb) = uopt.session;
+               sbi->s_session = uopt.session;
 
-       udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb));
+       udf_debug("Multi-session=%d\n", sbi->s_session);
 
-       UDF_SB_LASTBLOCK(sb) = uopt.lastblock;
-       UDF_SB_ANCHOR(sb)[0] = UDF_SB_ANCHOR(sb)[1] = 0;
-       UDF_SB_ANCHOR(sb)[2] = uopt.anchor;
-       UDF_SB_ANCHOR(sb)[3] = 256;
+       sbi->s_last_block = uopt.lastblock;
+       sbi->s_anchor[0] = sbi->s_anchor[1] = 0;
+       sbi->s_anchor[2] = uopt.anchor;
+       sbi->s_anchor[3] = 256;
 
-       if (udf_check_valid(sb, uopt.novrs, silent)) { /* read volume recognition sequences */
-               printk("UDF-fs: No VRS found\n");
+       if (udf_check_valid(sb, uopt.novrs, silent)) {
+               /* read volume recognition sequences */
+               printk(KERN_WARNING "UDF-fs: No VRS found\n");
                goto error_out;
        }
 
@@ -1496,27 +1807,30 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
        sb->s_time_gran = 1000;
 
        if (udf_load_partition(sb, &fileset)) {
-               printk("UDF-fs: No partition found (1)\n");
+               printk(KERN_WARNING "UDF-fs: No partition found (1)\n");
                goto error_out;
        }
 
-       udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb));
+       udf_debug("Lastblock=%d\n", sbi->s_last_block);
 
-       if (UDF_SB_LVIDBH(sb)) {
-               uint16_t minUDFReadRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev);
-               uint16_t minUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
-               /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */
+       if (sbi->s_lvid_bh) {
+               struct logicalVolIntegrityDescImpUse *lvidiu =
+                                                       udf_sb_lvidiu(sbi);
+               uint16_t minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev);
+               uint16_t minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev);
+               /* uint16_t maxUDFWriteRev =
+                               le16_to_cpu(lvidiu->maxUDFWriteRev); */
 
                if (minUDFReadRev > UDF_MAX_READ_VERSION) {
-                       printk("UDF-fs: minUDFReadRev=%x (max is %x)\n",
-                              le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev),
+                       printk(KERN_ERR "UDF-fs: minUDFReadRev=%x "
+                                       "(max is %x)\n",
+                              le16_to_cpu(lvidiu->minUDFReadRev),
                               UDF_MAX_READ_VERSION);
                        goto error_out;
-               } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION) {
+               } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
                        sb->s_flags |= MS_RDONLY;
-               }
 
-               UDF_SB_UDFREV(sb) = minUDFWriteRev;
+               sbi->s_udfrev = minUDFWriteRev;
 
                if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
                        UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
@@ -1524,29 +1838,30 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
                        UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
        }
 
-       if (!UDF_SB_NUMPARTS(sb)) {
-               printk("UDF-fs: No partition found (2)\n");
+       if (!sbi->s_partitions) {
+               printk(KERN_WARNING "UDF-fs: No partition found (2)\n");
                goto error_out;
        }
 
-       if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_READ_ONLY) {
-               printk("UDF-fs: Partition marked readonly; forcing readonly mount\n");
+       if (sbi->s_partmaps[sbi->s_partition].s_partition_flags &
+                       UDF_PART_FLAG_READ_ONLY) {
+               printk(KERN_NOTICE "UDF-fs: Partition marked readonly; "
+                                  "forcing readonly mount\n");
                sb->s_flags |= MS_RDONLY;
        }
 
        if (udf_find_fileset(sb, &fileset, &rootdir)) {
-               printk("UDF-fs: No fileset found\n");
+               printk(KERN_WARNING "UDF-fs: No fileset found\n");
                goto error_out;
        }
 
        if (!silent) {
                kernel_timestamp ts;
-               udf_time_to_stamp(&ts, UDF_SB_RECORDTIME(sb));
-               udf_info("UDF %s (%s) Mounting volume '%s', "
+               udf_time_to_stamp(&ts, sbi->s_record_time);
+               udf_info("UDF: Mounting volume '%s', "
                         "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
-                        UDFFS_VERSION, UDFFS_DATE,
-                        UDF_SB_VOLIDENT(sb), ts.year, ts.month, ts.day, ts.hour, ts.minute,
-                        ts.typeAndTimezone);
+                        sbi->s_volume_ident, ts.year, ts.month, ts.day,
+                        ts.hour, ts.minute, ts.typeAndTimezone);
        }
        if (!(sb->s_flags & MS_RDONLY))
                udf_open_lvid(sb);
@@ -1556,7 +1871,8 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
        /* perhaps it's not extensible enough, but for now ... */
        inode = udf_iget(sb, rootdir);
        if (!inode) {
-               printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n",
+               printk(KERN_ERR "UDF-fs: Error in udf_iget, block=%d, "
+                               "partition=%d\n",
                       rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
                goto error_out;
        }
@@ -1564,7 +1880,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
        /* Allocate a dentry for the root inode */
        sb->s_root = d_alloc_root(inode);
        if (!sb->s_root) {
-               printk("UDF-fs: Couldn't allocate root dentry\n");
+               printk(KERN_ERR "UDF-fs: Couldn't allocate root dentry\n");
                iput(inode);
                goto error_out;
        }
@@ -1572,30 +1888,32 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
        return 0;
 
 error_out:
-       if (UDF_SB_VAT(sb))
-               iput(UDF_SB_VAT(sb));
-       if (UDF_SB_NUMPARTS(sb)) {
-               if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
-                       iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
-               if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
-                       iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
-               if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
-                       UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_uspace);
-               if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
-                       UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_fspace);
-               if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15) {
+       if (sbi->s_vat_inode)
+               iput(sbi->s_vat_inode);
+       if (sbi->s_partitions) {
+               struct udf_part_map *map = &sbi->s_partmaps[sbi->s_partition];
+               if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
+                       iput(map->s_uspace.s_table);
+               if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
+                       iput(map->s_fspace.s_table);
+               if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
+                       udf_sb_free_bitmap(map->s_uspace.s_bitmap);
+               if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
+                       udf_sb_free_bitmap(map->s_fspace.s_bitmap);
+               if (map->s_partition_type == UDF_SPARABLE_MAP15)
                        for (i = 0; i < 4; i++)
-                               brelse(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]);
-               }
+                               brelse(map->s_type_specific.s_sparing.
+                                               s_spar_map[i]);
        }
 #ifdef CONFIG_UDF_NLS
        if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
-               unload_nls(UDF_SB(sb)->s_nls_map);
+               unload_nls(sbi->s_nls_map);
 #endif
        if (!(sb->s_flags & MS_RDONLY))
                udf_close_lvid(sb);
-       brelse(UDF_SB_LVIDBH(sb));
-       UDF_SB_FREE(sb);
+       brelse(sbi->s_lvid_bh);
+
+       kfree(sbi->s_partmaps);
        kfree(sbi);
        sb->s_fs_info = NULL;
 
@@ -1614,7 +1932,7 @@ void udf_error(struct super_block *sb, const char *function,
        va_start(args, fmt);
        vsnprintf(error_buf, sizeof(error_buf), fmt, args);
        va_end(args);
-       printk (KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
+       printk(KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
                sb->s_id, function, error_buf);
 }
 
@@ -1646,31 +1964,34 @@ void udf_warning(struct super_block *sb, const char *function,
 static void udf_put_super(struct super_block *sb)
 {
        int i;
+       struct udf_sb_info *sbi;
 
-       if (UDF_SB_VAT(sb))
-               iput(UDF_SB_VAT(sb));
-       if (UDF_SB_NUMPARTS(sb)) {
-               if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
-                       iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
-               if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
-                       iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
-               if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
-                       UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_uspace);
-               if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
-                       UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb), s_fspace);
-               if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15) {
+       sbi = UDF_SB(sb);
+       if (sbi->s_vat_inode)
+               iput(sbi->s_vat_inode);
+       if (sbi->s_partitions) {
+               struct udf_part_map *map = &sbi->s_partmaps[sbi->s_partition];
+               if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
+                       iput(map->s_uspace.s_table);
+               if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
+                       iput(map->s_fspace.s_table);
+               if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
+                       udf_sb_free_bitmap(map->s_uspace.s_bitmap);
+               if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
+                       udf_sb_free_bitmap(map->s_fspace.s_bitmap);
+               if (map->s_partition_type == UDF_SPARABLE_MAP15)
                        for (i = 0; i < 4; i++)
-                               brelse(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]);
-               }
+                               brelse(map->s_type_specific.s_sparing.
+                                               s_spar_map[i]);
        }
 #ifdef CONFIG_UDF_NLS
        if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
-               unload_nls(UDF_SB(sb)->s_nls_map);
+               unload_nls(sbi->s_nls_map);
 #endif
        if (!(sb->s_flags & MS_RDONLY))
                udf_close_lvid(sb);
-       brelse(UDF_SB_LVIDBH(sb));
-       UDF_SB_FREE(sb);
+       brelse(sbi->s_lvid_bh);
+       kfree(sbi->s_partmaps);
        kfree(sb->s_fs_info);
        sb->s_fs_info = NULL;
 }
@@ -1691,15 +2012,22 @@ static void udf_put_super(struct super_block *sb)
 static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
        struct super_block *sb = dentry->d_sb;
+       struct udf_sb_info *sbi = UDF_SB(sb);
+       struct logicalVolIntegrityDescImpUse *lvidiu;
+
+       if (sbi->s_lvid_bh != NULL)
+               lvidiu = udf_sb_lvidiu(sbi);
+       else
+               lvidiu = NULL;
 
        buf->f_type = UDF_SUPER_MAGIC;
        buf->f_bsize = sb->s_blocksize;
-       buf->f_blocks = UDF_SB_PARTLEN(sb, UDF_SB_PARTITION(sb));
+       buf->f_blocks = sbi->s_partmaps[sbi->s_partition].s_partition_len;
        buf->f_bfree = udf_count_free(sb);
        buf->f_bavail = buf->f_bfree;
-       buf->f_files = (UDF_SB_LVIDBH(sb) ?
-                       (le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) +
-                        le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)) : 0) + buf->f_bfree;
+       buf->f_files = (lvidiu != NULL ? (le32_to_cpu(lvidiu->numFiles) +
+                                         le32_to_cpu(lvidiu->numDirs)) : 0)
+                       + buf->f_bfree;
        buf->f_ffree = buf->f_bfree;
        /* __kernel_fsid_t f_fsid */
        buf->f_namelen = UDF_NAME_LEN - 2;
@@ -1711,7 +2039,8 @@ static unsigned char udf_bitmap_lookup[16] = {
        0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
 };
 
-static unsigned int udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
+static unsigned int udf_count_free_bitmap(struct super_block *sb,
+                                         struct udf_bitmap *bitmap)
 {
        struct buffer_head *bh = NULL;
        unsigned int accum = 0;
@@ -1727,7 +2056,7 @@ static unsigned int udf_count_free_bitmap(struct super_block *sb, struct udf_bit
        lock_kernel();
 
        loc.logicalBlockNum = bitmap->s_extPosition;
-       loc.partitionReferenceNum = UDF_SB_PARTITION(sb);
+       loc.partitionReferenceNum = UDF_SB(sb)->s_partition;
        bh = udf_read_ptagged(sb, loc, 0, &ident);
 
        if (!bh) {
@@ -1772,7 +2101,8 @@ out:
        return accum;
 }
 
-static unsigned int udf_count_free_table(struct super_block *sb, struct inode *table)
+static unsigned int udf_count_free_table(struct super_block *sb,
+                                        struct inode *table)
 {
        unsigned int accum = 0;
        uint32_t elen;
@@ -1782,13 +2112,13 @@ static unsigned int udf_count_free_table(struct super_block *sb, struct inode *t
 
        lock_kernel();
 
-       epos.block = UDF_I_LOCATION(table);
+       epos.block = UDF_I(table)->i_location;
        epos.offset = sizeof(struct unallocSpaceEntry);
        epos.bh = NULL;
 
-       while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) {
+       while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
                accum += (elen >> table->i_sb->s_blocksize_bits);
-       }
+
        brelse(epos.bh);
 
        unlock_kernel();
@@ -1799,10 +2129,17 @@ static unsigned int udf_count_free_table(struct super_block *sb, struct inode *t
 static unsigned int udf_count_free(struct super_block *sb)
 {
        unsigned int accum = 0;
-
-       if (UDF_SB_LVIDBH(sb)) {
-               if (le32_to_cpu(UDF_SB_LVID(sb)->numOfPartitions) > UDF_SB_PARTITION(sb)) {
-                       accum = le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]);
+       struct udf_sb_info *sbi;
+       struct udf_part_map *map;
+
+       sbi = UDF_SB(sb);
+       if (sbi->s_lvid_bh) {
+               struct logicalVolIntegrityDesc *lvid =
+                       (struct logicalVolIntegrityDesc *)
+                       sbi->s_lvid_bh->b_data;
+               if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) {
+                       accum = le32_to_cpu(
+                                       lvid->freeSpaceTable[sbi->s_partition]);
                        if (accum == 0xFFFFFFFF)
                                accum = 0;
                }
@@ -1811,24 +2148,25 @@ static unsigned int udf_count_free(struct super_block *sb)
        if (accum)
                return accum;
 
-       if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP) {
+       map = &sbi->s_partmaps[sbi->s_partition];
+       if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) {
                accum += udf_count_free_bitmap(sb,
-                                              UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_bitmap);
+                                              map->s_uspace.s_bitmap);
        }
-       if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP) {
+       if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) {
                accum += udf_count_free_bitmap(sb,
-                                              UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_bitmap);
+                                              map->s_fspace.s_bitmap);
        }
        if (accum)
                return accum;
 
-       if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE) {
+       if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) {
                accum += udf_count_free_table(sb,
-                                             UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
+                                             map->s_uspace.s_table);
        }
-       if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE) {
+       if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) {
                accum += udf_count_free_table(sb,
-                                             UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
+                                             map->s_fspace.s_table);
        }
 
        return accum;
index e6f933dd6a7b9929440a781903ea11a4192698f8..6ec99221e50c6c02dd90df64e8b0a39d9bc771b8 100644 (file)
@@ -33,7 +33,8 @@
 #include <linux/buffer_head.h>
 #include "udf_i.h"
 
-static void udf_pc_to_char(struct super_block *sb, char *from, int fromlen, char *to)
+static void udf_pc_to_char(struct super_block *sb, char *from, int fromlen,
+                          char *to)
 {
        struct pathComponent *pc;
        int elen = 0;
@@ -78,10 +79,12 @@ static int udf_symlink_filler(struct file *file, struct page *page)
        char *symlink;
        int err = -EIO;
        char *p = kmap(page);
+       struct udf_inode_info *iinfo;
 
        lock_kernel();
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB) {
-               symlink = UDF_I_DATA(inode) + UDF_I_LENEATTR(inode);
+       iinfo = UDF_I(inode);
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
+               symlink = iinfo->i_ext.i_data + iinfo->i_lenEAttr;
        } else {
                bh = sb_bread(inode->i_sb, udf_block_map(inode, 0));
 
index 7fc3912885a565bddbdadd8a9ade8057bd82b3ac..fe61be17cdab93315f5f66b32d5add96b20b1d23 100644 (file)
@@ -74,17 +74,18 @@ void udf_truncate_tail_extent(struct inode *inode)
        uint64_t lbcount = 0;
        int8_t etype = -1, netype;
        int adsize;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB ||
-           inode->i_size == UDF_I_LENEXTENTS(inode))
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB ||
+           inode->i_size == iinfo->i_lenExtents)
                return;
        /* Are we going to delete the file anyway? */
        if (inode->i_nlink == 0)
                return;
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                adsize = sizeof(short_ad);
-       else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
+       else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                adsize = sizeof(long_ad);
        else
                BUG();
@@ -117,7 +118,7 @@ void udf_truncate_tail_extent(struct inode *inode)
        }
        /* This inode entry is in-memory only and thus we don't have to mark
         * the inode dirty */
-       UDF_I_LENEXTENTS(inode) = inode->i_size;
+       iinfo->i_lenExtents = inode->i_size;
        brelse(epos.bh);
 }
 
@@ -129,19 +130,20 @@ void udf_discard_prealloc(struct inode *inode)
        uint64_t lbcount = 0;
        int8_t etype = -1, netype;
        int adsize;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB ||
-           inode->i_size == UDF_I_LENEXTENTS(inode))
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB ||
+           inode->i_size == iinfo->i_lenExtents)
                return;
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                adsize = sizeof(short_ad);
-       else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
+       else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                adsize = sizeof(long_ad);
        else
                adsize = 0;
 
-       epos.block = UDF_I_LOCATION(inode);
+       epos.block = iinfo->i_location;
 
        /* Find the last extent in the file */
        while ((netype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
@@ -153,8 +155,9 @@ void udf_discard_prealloc(struct inode *inode)
                lbcount -= elen;
                extent_trunc(inode, &epos, eloc, etype, elen, 0);
                if (!epos.bh) {
-                       UDF_I_LENALLOC(inode) =
-                               epos.offset - udf_file_entry_alloc_offset(inode);
+                       iinfo->i_lenAlloc =
+                               epos.offset -
+                               udf_file_entry_alloc_offset(inode);
                        mark_inode_dirty(inode);
                } else {
                        struct allocExtDesc *aed =
@@ -163,7 +166,7 @@ void udf_discard_prealloc(struct inode *inode)
                                cpu_to_le32(epos.offset -
                                            sizeof(struct allocExtDesc));
                        if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
-                           UDF_SB_UDFREV(inode->i_sb) >= 0x0201)
+                           UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
                                udf_update_tag(epos.bh->b_data, epos.offset);
                        else
                                udf_update_tag(epos.bh->b_data,
@@ -173,7 +176,7 @@ void udf_discard_prealloc(struct inode *inode)
        }
        /* This inode entry is in-memory only and thus we don't have to mark
         * the inode dirty */
-       UDF_I_LENEXTENTS(inode) = lbcount;
+       iinfo->i_lenExtents = lbcount;
        brelse(epos.bh);
 }
 
@@ -184,13 +187,15 @@ void udf_truncate_extents(struct inode *inode)
        uint32_t elen, nelen = 0, indirect_ext_len = 0, lenalloc;
        int8_t etype;
        struct super_block *sb = inode->i_sb;
+       struct udf_sb_info *sbi = UDF_SB(sb);
        sector_t first_block = inode->i_size >> sb->s_blocksize_bits, offset;
        loff_t byte_offset;
        int adsize;
+       struct udf_inode_info *iinfo = UDF_I(inode);
 
-       if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
+       if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
                adsize = sizeof(short_ad);
-       else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
+       else if (iinfo->i_alloc_type == ICBTAG_FLAG_AD_LONG)
                adsize = sizeof(long_ad);
        else
                BUG();
@@ -212,7 +217,8 @@ void udf_truncate_extents(struct inode *inode)
                else
                        lenalloc -= sizeof(struct allocExtDesc);
 
-               while ((etype = udf_current_aext(inode, &epos, &eloc, &elen, 0)) != -1) {
+               while ((etype = udf_current_aext(inode, &epos, &eloc,
+                                                &elen, 0)) != -1) {
                        if (etype == (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
                                udf_write_aext(inode, &epos, neloc, nelen, 0);
                                if (indirect_ext_len) {
@@ -224,35 +230,43 @@ void udf_truncate_extents(struct inode *inode)
                                                        0, indirect_ext_len);
                                } else {
                                        if (!epos.bh) {
-                                               UDF_I_LENALLOC(inode) = lenalloc;
+                                               iinfo->i_lenAlloc =
+                                                               lenalloc;
                                                mark_inode_dirty(inode);
                                        } else {
                                                struct allocExtDesc *aed =
-                                                       (struct allocExtDesc *)(epos.bh->b_data);
+                                                       (struct allocExtDesc *)
+                                                       (epos.bh->b_data);
+                                               int len =
+                                                   sizeof(struct allocExtDesc);
+
                                                aed->lengthAllocDescs =
                                                    cpu_to_le32(lenalloc);
-                                               if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) ||
-                                                   UDF_SB_UDFREV(sb) >= 0x0201)
-                                                       udf_update_tag(epos.bh->b_data,
-                                                                      lenalloc +
-                                                                      sizeof(struct allocExtDesc));
-                                               else
-                                                       udf_update_tag(epos.bh->b_data,
-                                                                      sizeof(struct allocExtDesc));
-                                               mark_buffer_dirty_inode(epos.bh, inode);
+                                               if (!UDF_QUERY_FLAG(sb,
+                                                       UDF_FLAG_STRICT) ||
+                                                   sbi->s_udfrev >= 0x0201)
+                                                       len += lenalloc;
+
+                                               udf_update_tag(epos.bh->b_data,
+                                                               len);
+                                               mark_buffer_dirty_inode(
+                                                               epos.bh, inode);
                                        }
                                }
                                brelse(epos.bh);
                                epos.offset = sizeof(struct allocExtDesc);
                                epos.block = eloc;
-                               epos.bh = udf_tread(sb, udf_get_lb_pblock(sb, eloc, 0));
+                               epos.bh = udf_tread(sb,
+                                               udf_get_lb_pblock(sb, eloc, 0));
                                if (elen)
-                                       indirect_ext_len = (elen + sb->s_blocksize -1) >>
+                                       indirect_ext_len =
+                                               (elen + sb->s_blocksize - 1) >>
                                                sb->s_blocksize_bits;
                                else
                                        indirect_ext_len = 1;
                        } else {
-                               extent_trunc(inode, &epos, eloc, etype, elen, 0);
+                               extent_trunc(inode, &epos, eloc, etype,
+                                            elen, 0);
                                epos.offset += adsize;
                        }
                }
@@ -264,19 +278,20 @@ void udf_truncate_extents(struct inode *inode)
                                        indirect_ext_len);
                } else {
                        if (!epos.bh) {
-                               UDF_I_LENALLOC(inode) = lenalloc;
+                               iinfo->i_lenAlloc = lenalloc;
                                mark_inode_dirty(inode);
                        } else {
                                struct allocExtDesc *aed =
                                    (struct allocExtDesc *)(epos.bh->b_data);
                                aed->lengthAllocDescs = cpu_to_le32(lenalloc);
                                if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT) ||
-                                   UDF_SB_UDFREV(sb) >= 0x0201)
+                                   sbi->s_udfrev >= 0x0201)
                                        udf_update_tag(epos.bh->b_data,
-                                                      lenalloc + sizeof(struct allocExtDesc));
+                                               lenalloc +
+                                               sizeof(struct allocExtDesc));
                                else
                                        udf_update_tag(epos.bh->b_data,
-                                                      sizeof(struct allocExtDesc));
+                                               sizeof(struct allocExtDesc));
                                mark_buffer_dirty_inode(epos.bh, inode);
                        }
                }
@@ -290,13 +305,16 @@ void udf_truncate_extents(struct inode *inode)
                         *  extending the file by 'offset' blocks.
                         */
                        if ((!epos.bh &&
-                            epos.offset == udf_file_entry_alloc_offset(inode)) ||
-                           (epos.bh && epos.offset == sizeof(struct allocExtDesc))) {
+                            epos.offset ==
+                                       udf_file_entry_alloc_offset(inode)) ||
+                           (epos.bh && epos.offset ==
+                                               sizeof(struct allocExtDesc))) {
                                /* File has no extents at all or has empty last
                                 * indirect extent! Create a fake extent... */
                                extent.extLocation.logicalBlockNum = 0;
                                extent.extLocation.partitionReferenceNum = 0;
-                               extent.extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
+                               extent.extLength =
+                                       EXT_NOT_RECORDED_NOT_ALLOCATED;
                        } else {
                                epos.offset -= adsize;
                                etype = udf_next_aext(inode, &epos,
@@ -305,10 +323,12 @@ void udf_truncate_extents(struct inode *inode)
                                extent.extLength |= etype << 30;
                        }
                        udf_extend_file(inode, &epos, &extent,
-                                       offset + ((inode->i_size & (sb->s_blocksize - 1)) != 0));
+                                       offset +
+                                       ((inode->i_size &
+                                               (sb->s_blocksize - 1)) != 0));
                }
        }
-       UDF_I_LENEXTENTS(inode) = inode->i_size;
+       iinfo->i_lenExtents = inode->i_size;
 
        brelse(epos.bh);
 }
index d7dbe6f3ba0ca8b0b5944c338501ec1b280bcace..ccc52f16bf7d573291a94aedab5ef6d33cfc8bee 100644 (file)
@@ -7,20 +7,4 @@ static inline struct udf_inode_info *UDF_I(struct inode *inode)
        return list_entry(inode, struct udf_inode_info, vfs_inode);
 }
 
-#define UDF_I_LOCATION(X)      ( UDF_I(X)->i_location )
-#define UDF_I_LENEATTR(X)      ( UDF_I(X)->i_lenEAttr )
-#define UDF_I_LENALLOC(X)      ( UDF_I(X)->i_lenAlloc )
-#define UDF_I_LENEXTENTS(X)    ( UDF_I(X)->i_lenExtents )
-#define UDF_I_UNIQUE(X)                ( UDF_I(X)->i_unique )
-#define UDF_I_ALLOCTYPE(X)     ( UDF_I(X)->i_alloc_type )
-#define UDF_I_EFE(X)           ( UDF_I(X)->i_efe )
-#define UDF_I_USE(X)           ( UDF_I(X)->i_use )
-#define UDF_I_STRAT4096(X)     ( UDF_I(X)->i_strat4096 )
-#define UDF_I_NEXT_ALLOC_BLOCK(X)      ( UDF_I(X)->i_next_alloc_block )
-#define UDF_I_NEXT_ALLOC_GOAL(X)       ( UDF_I(X)->i_next_alloc_goal )
-#define UDF_I_CRTIME(X)                ( UDF_I(X)->i_crtime )
-#define UDF_I_SAD(X)           ( UDF_I(X)->i_ext.i_sad )
-#define UDF_I_LAD(X)           ( UDF_I(X)->i_ext.i_lad )
-#define UDF_I_DATA(X)          ( UDF_I(X)->i_ext.i_data )
-
 #endif /* !defined(_LINUX_UDF_I_H) */
index 3c2982017c6da50d14437391e1f985d036ffcae8..737d1c604eea0330848b1223dc4e696f4fee0cb7 100644 (file)
@@ -26,6 +26,8 @@
 #define UDF_FLAG_GID_IGNORE     14
 #define UDF_FLAG_UID_SET       15
 #define UDF_FLAG_GID_SET       16
+#define UDF_FLAG_SESSION_SET   17
+#define UDF_FLAG_LASTBLOCK_SET 18
 
 #define UDF_PART_FLAG_UNALLOC_BITMAP   0x0001
 #define UDF_PART_FLAG_UNALLOC_TABLE    0x0002
@@ -41,96 +43,12 @@ static inline struct udf_sb_info *UDF_SB(struct super_block *sb)
        return sb->s_fs_info;
 }
 
-#define UDF_SB_FREE(X)\
-{\
-       if (UDF_SB(X)) {\
-               kfree(UDF_SB_PARTMAPS(X));\
-               UDF_SB_PARTMAPS(X) = NULL;\
-       }\
-}
-
-#define UDF_SB_ALLOC_PARTMAPS(X,Y)\
-{\
-       UDF_SB_PARTMAPS(X) = kmalloc(sizeof(struct udf_part_map) * Y, GFP_KERNEL);\
-       if (UDF_SB_PARTMAPS(X) != NULL) {\
-               UDF_SB_NUMPARTS(X) = Y;\
-               memset(UDF_SB_PARTMAPS(X), 0x00, sizeof(struct udf_part_map) * Y);\
-       } else {\
-               UDF_SB_NUMPARTS(X) = 0;\
-               udf_error(X, __FUNCTION__, "Unable to allocate space for %d partition maps", Y);\
-       }\
-}
-
-#define UDF_SB_ALLOC_BITMAP(X,Y,Z)\
-{\
-       int nr_groups = ((UDF_SB_PARTLEN((X),(Y)) + (sizeof(struct spaceBitmapDesc) << 3) +\
-               ((X)->s_blocksize * 8) - 1) / ((X)->s_blocksize * 8));\
-       int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) * nr_groups);\
-       if (size <= PAGE_SIZE)\
-               UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap = kmalloc(size, GFP_KERNEL);\
-       else\
-               UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap = vmalloc(size);\
-       if (UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap != NULL) {\
-               memset(UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap, 0x00, size);\
-               UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_block_bitmap =\
-                       (struct buffer_head **)(UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap + 1);\
-               UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_nr_groups = nr_groups;\
-       } else {\
-               udf_error(X, __FUNCTION__, "Unable to allocate space for bitmap and %d buffer_head pointers", nr_groups);\
-       }\
-}
+struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi);
 
-#define UDF_SB_FREE_BITMAP(X,Y,Z)\
-{\
-       int i;\
-       int nr_groups = UDF_SB_BITMAP_NR_GROUPS(X,Y,Z);\
-       int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) * nr_groups);\
-       for (i = 0; i < nr_groups; i++) {\
-               if (UDF_SB_BITMAP(X,Y,Z,i))\
-                       brelse(UDF_SB_BITMAP(X,Y,Z,i));\
-       }\
-       if (size <= PAGE_SIZE)\
-               kfree(UDF_SB_PARTMAPS(X)[Y].Z.s_bitmap);\
-       else\
-               vfree(UDF_SB_PARTMAPS(X)[Y].Z.s_bitmap);\
-}
+int udf_compute_nr_groups(struct super_block *sb, u32 partition);
 
 #define UDF_QUERY_FLAG(X,Y)                    ( UDF_SB(X)->s_flags & ( 1 << (Y) ) )
 #define UDF_SET_FLAG(X,Y)                      ( UDF_SB(X)->s_flags |= ( 1 << (Y) ) )
 #define UDF_CLEAR_FLAG(X,Y)                    ( UDF_SB(X)->s_flags &= ~( 1 << (Y) ) )
 
-#define UDF_UPDATE_UDFREV(X,Y)                 ( ((Y) > UDF_SB_UDFREV(X)) ? UDF_SB_UDFREV(X) = (Y) : UDF_SB_UDFREV(X) )
-
-#define UDF_SB_PARTMAPS(X)                     ( UDF_SB(X)->s_partmaps )
-#define UDF_SB_PARTTYPE(X,Y)                   ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_type )
-#define UDF_SB_PARTROOT(X,Y)                   ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_root )
-#define UDF_SB_PARTLEN(X,Y)                    ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_len )
-#define UDF_SB_PARTVSN(X,Y)                    ( UDF_SB_PARTMAPS(X)[(Y)].s_volumeseqnum )
-#define UDF_SB_PARTNUM(X,Y)                    ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_num )
-#define UDF_SB_TYPESPAR(X,Y)                   ( UDF_SB_PARTMAPS(X)[(Y)].s_type_specific.s_sparing )
-#define UDF_SB_TYPEVIRT(X,Y)                   ( UDF_SB_PARTMAPS(X)[(Y)].s_type_specific.s_virtual )
-#define UDF_SB_PARTFUNC(X,Y)                   ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_func )
-#define UDF_SB_PARTFLAGS(X,Y)                  ( UDF_SB_PARTMAPS(X)[(Y)].s_partition_flags )
-#define UDF_SB_BITMAP(X,Y,Z,I)                 ( UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_block_bitmap[I] )
-#define UDF_SB_BITMAP_NR_GROUPS(X,Y,Z)         ( UDF_SB_PARTMAPS(X)[(Y)].Z.s_bitmap->s_nr_groups )
-
-#define UDF_SB_VOLIDENT(X)                     ( UDF_SB(X)->s_volident )
-#define UDF_SB_NUMPARTS(X)                     ( UDF_SB(X)->s_partitions )
-#define UDF_SB_PARTITION(X)                    ( UDF_SB(X)->s_partition )
-#define UDF_SB_SESSION(X)                      ( UDF_SB(X)->s_session )
-#define UDF_SB_ANCHOR(X)                       ( UDF_SB(X)->s_anchor )
-#define UDF_SB_LASTBLOCK(X)                    ( UDF_SB(X)->s_lastblock )
-#define UDF_SB_LVIDBH(X)                       ( UDF_SB(X)->s_lvidbh )
-#define UDF_SB_LVID(X)                         ( (struct logicalVolIntegrityDesc *)UDF_SB_LVIDBH(X)->b_data )
-#define UDF_SB_LVIDIU(X)                       ( (struct logicalVolIntegrityDescImpUse *)&(UDF_SB_LVID(X)->impUse[le32_to_cpu(UDF_SB_LVID(X)->numOfPartitions) * 2 * sizeof(uint32_t)/sizeof(uint8_t)]) )
-
-#define UDF_SB_UMASK(X)                                ( UDF_SB(X)->s_umask )
-#define UDF_SB_GID(X)                          ( UDF_SB(X)->s_gid )
-#define UDF_SB_UID(X)                          ( UDF_SB(X)->s_uid )
-#define UDF_SB_RECORDTIME(X)                   ( UDF_SB(X)->s_recordtime )
-#define UDF_SB_SERIALNUM(X)                    ( UDF_SB(X)->s_serialnum )
-#define UDF_SB_UDFREV(X)                       ( UDF_SB(X)->s_udfrev )
-#define UDF_SB_FLAGS(X)                                ( UDF_SB(X)->s_flags )
-#define UDF_SB_VAT(X)                          ( UDF_SB(X)->s_vat )
-
 #endif /* __LINUX_UDF_SB_H */
index c8016cc9e7e669cae81d09544f174eea22a32a78..681dc2b66cdbb9583e7c8f2d958f227f96928380 100644 (file)
 #define UDF_PATH_LEN           1023
 
 #define udf_file_entry_alloc_offset(inode)\
-       (UDF_I_USE(inode) ?\
+       (UDF_I(inode)->i_use ?\
                sizeof(struct unallocSpaceEntry) :\
-               ((UDF_I_EFE(inode) ?\
+               ((UDF_I(inode)->i_efe ?\
                        sizeof(struct extendedFileEntry) :\
-                       sizeof(struct fileEntry)) + UDF_I_LENEATTR(inode)))
+                       sizeof(struct fileEntry)) + UDF_I(inode)->i_lenEAttr))
 
 #define udf_ext0_offset(inode)\
-       (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_IN_ICB ?\
+       (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB ?\
                udf_file_entry_alloc_offset(inode) : 0)
 
 #define udf_get_lb_pblock(sb,loc,offset) udf_get_pblock((sb), (loc).logicalBlockNum, (loc).partitionReferenceNum, (offset))
 
+/* computes tag checksum */
+u8 udf_tag_checksum(const tag *t);
+
 struct dentry;
 struct inode;
 struct task_struct;
@@ -185,8 +188,8 @@ extern struct fileIdentDesc *udf_fileident_read(struct inode *, loff_t *,
                                                sector_t *);
 extern struct fileIdentDesc *udf_get_fileident(void *buffer, int bufsize,
                                               int *offset);
-extern long_ad *udf_get_filelongad(uint8_t *, int, int *, int);
-extern short_ad *udf_get_fileshortad(uint8_t *, int, int *, int);
+extern long_ad *udf_get_filelongad(uint8_t *, int, uint32_t *, int);
+extern short_ad *udf_get_fileshortad(uint8_t *, int, uint32_t *, int);
 
 /* crc.c */
 extern uint16_t udf_crc(uint8_t *, uint32_t, uint16_t);
index adcb87c2da7edbd79be82f07d4641f41d9a7646b..ce595732ba6f37e0fd697ddc3ca4cfe9ab5f9423 100644 (file)
    Boston, MA 02111-1307, USA.  */
 
 /*
- * dgb 10/02/98: ripped this from glibc source to help convert timestamps to unix time
- *     10/04/98: added new table-based lookup after seeing how ugly the gnu code is
+ * dgb 10/02/98: ripped this from glibc source to help convert timestamps
+ *               to unix time
+ *     10/04/98: added new table-based lookup after seeing how ugly
+ *               the gnu code is
  * blf 09/27/99: ripped out all the old code and inserted new table from
  *              John Brockmeyer (without leap second corrections)
  *              rewrote udf_stamp_to_time and fixed timezone accounting in
@@ -55,27 +57,27 @@ static const unsigned short int __mon_yday[2][13] = {
 
 #define MAX_YEAR_SECONDS       69
 #define SPD                    0x15180 /*3600*24 */
-#define SPY(y,l,s)             (SPD * (365*y+l)+s)
-
-static time_t year_seconds[MAX_YEAR_SECONDS]= {
-/*1970*/ SPY( 0, 0,0), SPY( 1, 0,0), SPY( 2, 0,0), SPY( 3, 1,0),
-/*1974*/ SPY( 4, 1,0), SPY( 5, 1,0), SPY( 6, 1,0), SPY( 7, 2,0),
-/*1978*/ SPY( 8, 2,0), SPY( 9, 2,0), SPY(10, 2,0), SPY(11, 3,0),
-/*1982*/ SPY(12, 3,0), SPY(13, 3,0), SPY(14, 3,0), SPY(15, 4,0),
-/*1986*/ SPY(16, 4,0), SPY(17, 4,0), SPY(18, 4,0), SPY(19, 5,0),
-/*1990*/ SPY(20, 5,0), SPY(21, 5,0), SPY(22, 5,0), SPY(23, 6,0),
-/*1994*/ SPY(24, 6,0), SPY(25, 6,0), SPY(26, 6,0), SPY(27, 7,0),
-/*1998*/ SPY(28, 7,0), SPY(29, 7,0), SPY(30, 7,0), SPY(31, 8,0),
-/*2002*/ SPY(32, 8,0), SPY(33, 8,0), SPY(34, 8,0), SPY(35, 9,0),
-/*2006*/ SPY(36, 9,0), SPY(37, 9,0), SPY(38, 9,0), SPY(39,10,0),
-/*2010*/ SPY(40,10,0), SPY(41,10,0), SPY(42,10,0), SPY(43,11,0),
-/*2014*/ SPY(44,11,0), SPY(45,11,0), SPY(46,11,0), SPY(47,12,0),
-/*2018*/ SPY(48,12,0), SPY(49,12,0), SPY(50,12,0), SPY(51,13,0),
-/*2022*/ SPY(52,13,0), SPY(53,13,0), SPY(54,13,0), SPY(55,14,0),
-/*2026*/ SPY(56,14,0), SPY(57,14,0), SPY(58,14,0), SPY(59,15,0),
-/*2030*/ SPY(60,15,0), SPY(61,15,0), SPY(62,15,0), SPY(63,16,0),
-/*2034*/ SPY(64,16,0), SPY(65,16,0), SPY(66,16,0), SPY(67,17,0),
-/*2038*/ SPY(68,17,0)
+#define SPY(y, l, s)           (SPD * (365 * y + l) + s)
+
+static time_t year_seconds[MAX_YEAR_SECONDS] = {
+/*1970*/ SPY(0,   0, 0), SPY(1,   0, 0), SPY(2,   0, 0), SPY(3,   1, 0),
+/*1974*/ SPY(4,   1, 0), SPY(5,   1, 0), SPY(6,   1, 0), SPY(7,   2, 0),
+/*1978*/ SPY(8,   2, 0), SPY(9,   2, 0), SPY(10,  2, 0), SPY(11,  3, 0),
+/*1982*/ SPY(12,  3, 0), SPY(13,  3, 0), SPY(14,  3, 0), SPY(15,  4, 0),
+/*1986*/ SPY(16,  4, 0), SPY(17,  4, 0), SPY(18,  4, 0), SPY(19,  5, 0),
+/*1990*/ SPY(20,  5, 0), SPY(21,  5, 0), SPY(22,  5, 0), SPY(23,  6, 0),
+/*1994*/ SPY(24,  6, 0), SPY(25,  6, 0), SPY(26,  6, 0), SPY(27,  7, 0),
+/*1998*/ SPY(28,  7, 0), SPY(29,  7, 0), SPY(30,  7, 0), SPY(31,  8, 0),
+/*2002*/ SPY(32,  8, 0), SPY(33,  8, 0), SPY(34,  8, 0), SPY(35,  9, 0),
+/*2006*/ SPY(36,  9, 0), SPY(37,  9, 0), SPY(38,  9, 0), SPY(39, 10, 0),
+/*2010*/ SPY(40, 10, 0), SPY(41, 10, 0), SPY(42, 10, 0), SPY(43, 11, 0),
+/*2014*/ SPY(44, 11, 0), SPY(45, 11, 0), SPY(46, 11, 0), SPY(47, 12, 0),
+/*2018*/ SPY(48, 12, 0), SPY(49, 12, 0), SPY(50, 12, 0), SPY(51, 13, 0),
+/*2022*/ SPY(52, 13, 0), SPY(53, 13, 0), SPY(54, 13, 0), SPY(55, 14, 0),
+/*2026*/ SPY(56, 14, 0), SPY(57, 14, 0), SPY(58, 14, 0), SPY(59, 15, 0),
+/*2030*/ SPY(60, 15, 0), SPY(61, 15, 0), SPY(62, 15, 0), SPY(63, 16, 0),
+/*2034*/ SPY(64, 16, 0), SPY(65, 16, 0), SPY(66, 16, 0), SPY(67, 17, 0),
+/*2038*/ SPY(68, 17, 0)
 };
 
 extern struct timezone sys_tz;
@@ -115,7 +117,7 @@ time_t *udf_stamp_to_time(time_t *dest, long *dest_usec, kernel_timestamp src)
        return dest;
 }
 
-kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts)
+kernel_timestamp *udf_time_to_stamp(kernel_timestamp *dest, struct timespec ts)
 {
        long int days, rem, y;
        const unsigned short int *ip;
@@ -137,7 +139,7 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts)
        dest->second = rem % 60;
        y = 1970;
 
-#define DIV(a,b) ((a) / (b) - ((a) % (b) < 0))
+#define DIV(a, b) ((a) / (b) - ((a) % (b) < 0))
 #define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400))
 
        while (days < 0 || days >= (__isleap(y) ? 366 : 365)) {
@@ -145,8 +147,8 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts)
 
                /* Adjust DAYS and Y to match the guessed year.  */
                days -= ((yg - y) * 365
-                        + LEAPS_THRU_END_OF (yg - 1)
-                        - LEAPS_THRU_END_OF (y - 1));
+                        + LEAPS_THRU_END_OF(yg - 1)
+                        - LEAPS_THRU_END_OF(y - 1));
                y = yg;
        }
        dest->year = y;
@@ -158,7 +160,8 @@ kernel_timestamp *udf_time_to_stamp(kernel_timestamp * dest, struct timespec ts)
        dest->day = days + 1;
 
        dest->centiseconds = ts.tv_nsec / 10000000;
-       dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000) / 100;
+       dest->hundredsOfMicroseconds = (ts.tv_nsec / 1000 -
+                                       dest->centiseconds * 10000) / 100;
        dest->microseconds = (ts.tv_nsec / 1000 - dest->centiseconds * 10000 -
                              dest->hundredsOfMicroseconds * 100);
        return dest;
index 9e6099c26c27a7434de44af03b05f79cc97bd0ca..e533b11703bf60a1e8e5d2a0d94b909585940a1d 100644 (file)
@@ -136,12 +136,18 @@ int udf_CS0toUTF8(struct ustr *utf_o, struct ustr *ocu_i)
                if (c < 0x80U) {
                        utf_o->u_name[utf_o->u_len++] = (uint8_t)c;
                } else if (c < 0x800U) {
-                       utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xc0 | (c >> 6));
-                       utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f));
+                       utf_o->u_name[utf_o->u_len++] =
+                                               (uint8_t)(0xc0 | (c >> 6));
+                       utf_o->u_name[utf_o->u_len++] =
+                                               (uint8_t)(0x80 | (c & 0x3f));
                } else {
-                       utf_o->u_name[utf_o->u_len++] = (uint8_t)(0xe0 | (c >> 12));
-                       utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | ((c >> 6) & 0x3f));
-                       utf_o->u_name[utf_o->u_len++] = (uint8_t)(0x80 | (c & 0x3f));
+                       utf_o->u_name[utf_o->u_len++] =
+                                               (uint8_t)(0xe0 | (c >> 12));
+                       utf_o->u_name[utf_o->u_len++] =
+                                               (uint8_t)(0x80 |
+                                                         ((c >> 6) & 0x3f));
+                       utf_o->u_name[utf_o->u_len++] =
+                                               (uint8_t)(0x80 | (c & 0x3f));
                }
        }
        utf_o->u_cmpID = 8;
@@ -232,9 +238,8 @@ try_again:
                        goto error_out;
                }
 
-               if (max_val == 0xffffU) {
+               if (max_val == 0xffffU)
                        ocu[++u_len] = (uint8_t)(utf_char >> 8);
-               }
                ocu[++u_len] = (uint8_t)(utf_char & 0xffU);
        }
 
@@ -330,29 +335,29 @@ int udf_get_filename(struct super_block *sb, uint8_t *sname, uint8_t *dname,
        struct ustr filename, unifilename;
        int len;
 
-       if (udf_build_ustr_exact(&unifilename, sname, flen)) {
+       if (udf_build_ustr_exact(&unifilename, sname, flen))
                return 0;
-       }
 
        if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
                if (!udf_CS0toUTF8(&filename, &unifilename)) {
-                       udf_debug("Failed in udf_get_filename: sname = %s\n", sname);
+                       udf_debug("Failed in udf_get_filename: sname = %s\n",
+                                 sname);
                        return 0;
                }
        } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
-               if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, &filename, &unifilename)) {
-                       udf_debug("Failed in udf_get_filename: sname = %s\n", sname);
+               if (!udf_CS0toNLS(UDF_SB(sb)->s_nls_map, &filename,
+                                 &unifilename)) {
+                       udf_debug("Failed in udf_get_filename: sname = %s\n",
+                                 sname);
                        return 0;
                }
-       } else {
+       } else
                return 0;
-       }
 
        len = udf_translate_to_linux(dname, filename.u_name, filename.u_len,
                                     unifilename.u_name, unifilename.u_len);
-       if (len) {
+       if (len)
                return len;
-       }
 
        return 0;
 }
@@ -363,23 +368,20 @@ int udf_put_filename(struct super_block *sb, const uint8_t *sname,
        struct ustr unifilename;
        int namelen;
 
-       if (!(udf_char_to_ustr(&unifilename, sname, flen))) {
+       if (!udf_char_to_ustr(&unifilename, sname, flen))
                return 0;
-       }
 
        if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8)) {
                namelen = udf_UTF8toCS0(dname, &unifilename, UDF_NAME_LEN);
-               if (!namelen) {
+               if (!namelen)
                        return 0;
-               }
        } else if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP)) {
-               namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname, &unifilename, UDF_NAME_LEN);
-               if (!namelen) {
+               namelen = udf_NLStoCS0(UDF_SB(sb)->s_nls_map, dname,
+                                       &unifilename, UDF_NAME_LEN);
+               if (!namelen)
                        return 0;
-               }
-       } else {
+       } else
                return 0;
-       }
 
        return namelen;
 }
@@ -389,8 +391,9 @@ int udf_put_filename(struct super_block *sb, const uint8_t *sname,
 #define CRC_MARK               '#'
 #define EXT_SIZE               5
 
-static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen,
-                                 uint8_t *fidName, int fidNameLen)
+static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName,
+                                 int udfLen, uint8_t *fidName,
+                                 int fidNameLen)
 {
        int index, newIndex = 0, needsCRC = 0;
        int extIndex = 0, newExtIndex = 0, hasExt = 0;
@@ -409,13 +412,16 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen
                        if (curr == '/' || curr == 0) {
                                needsCRC = 1;
                                curr = ILLEGAL_CHAR_MARK;
-                               while (index + 1 < udfLen && (udfName[index + 1] == '/' ||
-                                                             udfName[index + 1] == 0))
+                               while (index + 1 < udfLen &&
+                                               (udfName[index + 1] == '/' ||
+                                                udfName[index + 1] == 0))
                                        index++;
-                       } if (curr == EXT_MARK && (udfLen - index - 1) <= EXT_SIZE) {
-                               if (udfLen == index + 1) {
+                       }
+                       if (curr == EXT_MARK &&
+                                       (udfLen - index - 1) <= EXT_SIZE) {
+                               if (udfLen == index + 1)
                                        hasExt = 0;
-                               else {
+                               else {
                                        hasExt = 1;
                                        extIndex = index;
                                        newExtIndex = newIndex;
@@ -433,16 +439,18 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen
 
                if (hasExt) {
                        int maxFilenameLen;
-                       for(index = 0; index < EXT_SIZE && extIndex + index + 1 < udfLen; index++) {
+                       for (index = 0;
+                            index < EXT_SIZE && extIndex + index + 1 < udfLen;
+                            index++) {
                                curr = udfName[extIndex + index + 1];
 
                                if (curr == '/' || curr == 0) {
                                        needsCRC = 1;
                                        curr = ILLEGAL_CHAR_MARK;
-                                       while(extIndex + index + 2 < udfLen &&
-                                             (index + 1 < EXT_SIZE
-                                              && (udfName[extIndex + index + 2] == '/' ||
-                                                  udfName[extIndex + index + 2] == 0)))
+                                       while (extIndex + index + 2 < udfLen &&
+                                             (index + 1 < EXT_SIZE &&
+                                               (udfName[extIndex + index + 2] == '/' ||
+                                                udfName[extIndex + index + 2] == 0)))
                                                index++;
                                }
                                ext[localExtIndex++] = curr;
@@ -452,9 +460,8 @@ static int udf_translate_to_linux(uint8_t *newName, uint8_t *udfName, int udfLen
                                newIndex = maxFilenameLen;
                        else
                                newIndex = newExtIndex;
-               } else if (newIndex > 250) {
+               } else if (newIndex > 250)
                        newIndex = 250;
-               }
                newName[newIndex++] = CRC_MARK;
                valueCRC = udf_crc(fidName, fidNameLen, 0);
                newName[newIndex++] = hexChar[(valueCRC & 0xf000) >> 12];
index f63a09ce8683b8fbb43eb088e4b7466ce40caec0..1fca381f0ce2b225be84297ef1d0a4045695e4ee 100644 (file)
@@ -9,7 +9,6 @@
  */
 
 #include <linux/fs.h>
-#include <linux/ufs_fs.h>
 #include <linux/stat.h>
 #include <linux/time.h>
 #include <linux/string.h>
@@ -19,6 +18,7 @@
 #include <linux/bitops.h>
 #include <asm/byteorder.h>
 
+#include "ufs_fs.h"
 #include "ufs.h"
 #include "swab.h"
 #include "util.h"
index 2a815665644f30b0d3efb4d632004cada1ddc57f..b4676322ddb65830d69b74a014c78668eb24a90f 100644 (file)
@@ -9,7 +9,6 @@
  */
 
 #include <linux/fs.h>
-#include <linux/ufs_fs.h>
 #include <linux/time.h>
 #include <linux/stat.h>
 #include <linux/string.h>
@@ -17,6 +16,7 @@
 
 #include <asm/byteorder.h>
 
+#include "ufs_fs.h"
 #include "ufs.h"
 #include "swab.h"
 #include "util.h"
index aaf2878305ceb6b0108ebb5a0ea832504cd43e54..ef563fc8d72c3b62418d5ae13548ae156548d94a 100644 (file)
@@ -18,9 +18,9 @@
 
 #include <linux/time.h>
 #include <linux/fs.h>
-#include <linux/ufs_fs.h>
 #include <linux/swap.h>
 
+#include "ufs_fs.h"
 #include "ufs.h"
 #include "swab.h"
 #include "util.h"
index a46c97bf023fb25462606b228ed5372a67d79fd4..625ef17c6f83122139dda3b675b3a41486df40f3 100644 (file)
@@ -24,9 +24,9 @@
  */
 
 #include <linux/fs.h>
-#include <linux/ufs_fs.h>
 #include <linux/buffer_head.h> /* for sync_mapping_buffers() */
 
+#include "ufs_fs.h"
 #include "ufs.h"
 
 
index 7e260bc0d94f66719f40a71bebdfea19fb09c859..ac181f6806a3f253e1fe70afe67f1a88da34018d 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 #include <linux/fs.h>
-#include <linux/ufs_fs.h>
 #include <linux/time.h>
 #include <linux/stat.h>
 #include <linux/string.h>
@@ -34,6 +33,7 @@
 #include <linux/bitops.h>
 #include <asm/byteorder.h>
 
+#include "ufs_fs.h"
 #include "ufs.h"
 #include "swab.h"
 #include "util.h"
index 489f26bc26d9b4084b56b563761859186e1f9fd6..5446b888fc8e34448078b22096983b04262b71dc 100644 (file)
@@ -30,7 +30,6 @@
 
 #include <linux/errno.h>
 #include <linux/fs.h>
-#include <linux/ufs_fs.h>
 #include <linux/time.h>
 #include <linux/stat.h>
 #include <linux/string.h>
@@ -38,6 +37,7 @@
 #include <linux/smp_lock.h>
 #include <linux/buffer_head.h>
 
+#include "ufs_fs.h"
 #include "ufs.h"
 #include "swab.h"
 #include "util.h"
index 747a4de6c69526d14eaff5b48a08031d21d10d5d..e3a9b1fac75a2c4f6d04c94f6c22bb39d530d523 100644 (file)
@@ -29,8 +29,9 @@
 
 #include <linux/time.h>
 #include <linux/fs.h>
-#include <linux/ufs_fs.h>
 #include <linux/smp_lock.h>
+
+#include "ufs_fs.h"
 #include "ufs.h"
 #include "util.h"
 
index 73deff475e6362326ab6e6785f89a93ad5b3f158..85b22b5977fa3d5c1d3eda3874742baf07a7d480 100644 (file)
@@ -76,7 +76,6 @@
 
 #include <linux/errno.h>
 #include <linux/fs.h>
-#include <linux/ufs_fs.h>
 #include <linux/slab.h>
 #include <linux/time.h>
 #include <linux/stat.h>
@@ -91,6 +90,7 @@
 #include <linux/mount.h>
 #include <linux/seq_file.h>
 
+#include "ufs_fs.h"
 #include "ufs.h"
 #include "swab.h"
 #include "util.h"
@@ -131,6 +131,8 @@ static void ufs_print_super_stuff(struct super_block *sb,
                printk(KERN_INFO"  cs_nffree(Num of free frags): %llu\n",
                       (unsigned long long)
                       fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree));
+               printk(KERN_INFO"  fs_maxsymlinklen: %u\n",
+                      fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen));
        } else {
                printk(" sblkno:      %u\n", fs32_to_cpu(sb, usb1->fs_sblkno));
                printk(" cblkno:      %u\n", fs32_to_cpu(sb, usb1->fs_cblkno));
@@ -1061,8 +1063,8 @@ magic_found:
        uspi->s_bpf = uspi->s_fsize << 3;
        uspi->s_bpfshift = uspi->s_fshift + 3;
        uspi->s_bpfmask = uspi->s_bpf - 1;
-       if ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) ==
-           UFS_MOUNT_UFSTYPE_44BSD)
+       if ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_44BSD ||
+           (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_UFS2)
                uspi->s_maxsymlinklen =
                    fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen);
 
index 43ac10e75a4aae8234a20cf301b55aaa7ad661e2..c0156eda44bcff1e53e17689167da63b046ca926 100644 (file)
@@ -27,7 +27,8 @@
 
 #include <linux/fs.h>
 #include <linux/namei.h>
-#include <linux/ufs_fs.h>
+
+#include "ufs_fs.h"
 #include "ufs.h"
 
 
index 311ded34c2b2b1027dc17e3f8b7d4f9682ba7412..41dd431ce228e409d9efdbbf63865feea608625c 100644 (file)
@@ -36,7 +36,6 @@
 
 #include <linux/errno.h>
 #include <linux/fs.h>
-#include <linux/ufs_fs.h>
 #include <linux/fcntl.h>
 #include <linux/time.h>
 #include <linux/stat.h>
@@ -46,6 +45,7 @@
 #include <linux/blkdev.h>
 #include <linux/sched.h>
 
+#include "ufs_fs.h"
 #include "ufs.h"
 #include "swab.h"
 #include "util.h"
similarity index 99%
rename from include/linux/ufs_fs.h
rename to fs/ufs/ufs_fs.h
index 10b854d3561fd982a42d976eddbdad8aa6a538fa..54bde1895a80820d9ad32540a50b4c81e36f0d19 100644 (file)
 #include <linux/stat.h>
 #include <linux/fs.h>
 
-#ifndef __KERNEL__
-typedef __u64 __fs64;
-typedef __u32 __fs32;
-typedef __u16 __fs16;
-#else
 #include <asm/div64.h>
 typedef __u64 __bitwise __fs64;
 typedef __u32 __bitwise __fs32;
 typedef __u16 __bitwise __fs16;
-#endif
 
 #define UFS_BBLOCK 0
 #define UFS_BBSIZE 8192
@@ -197,7 +191,7 @@ typedef __u16 __bitwise __fs16;
  */
 #define UFS_MINFREE         5
 #define UFS_DEFAULTOPT      UFS_OPTTIME
-            
+
 /*
  * Turn file system block numbers into disk block addresses.
  * This maps file system blocks to device size blocks.
@@ -714,7 +708,7 @@ struct ufs_cg_private_info {
        __u32   c_clustersumoff;/* (u_int32) counts of avail clusters */
        __u32   c_clusteroff;   /* (u_int8) free cluster map */
        __u32   c_nclusterblks; /* number of clusters this cg */
-};     
+};
 
 
 struct ufs_sb_private_info {
index 410084dae3891be9c0c4d3de4c42dc6ccf50218e..85a7fc9e4a4e345161a1c8a8a26e0eebcb834aae 100644 (file)
@@ -8,9 +8,9 @@
  
 #include <linux/string.h>
 #include <linux/slab.h>
-#include <linux/ufs_fs.h>
 #include <linux/buffer_head.h>
 
+#include "ufs_fs.h"
 #include "ufs.h"
 #include "swab.h"
 #include "util.h"
index d1491aa7a0e29da822b9924d45a626945c17fffe..97316451fc6d5975070ff689e5ff076852d98cd0 100644 (file)
@@ -70,7 +70,6 @@ xfs-y                         += xfs_alloc.o \
                                   xfs_iget.o \
                                   xfs_inode.o \
                                   xfs_inode_item.o \
-                                  xfs_iocore.o \
                                   xfs_iomap.o \
                                   xfs_itable.o \
                                   xfs_dfrag.o \
diff --git a/fs/xfs/linux-2.6/spin.h b/fs/xfs/linux-2.6/spin.h
deleted file mode 100644 (file)
index 50a6191..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-#ifndef __XFS_SUPPORT_SPIN_H__
-#define __XFS_SUPPORT_SPIN_H__
-
-#include <linux/sched.h>       /* preempt needs this */
-#include <linux/spinlock.h>
-
-/*
- * Map lock_t from IRIX to Linux spinlocks.
- *
- * We do not make use of lock_t from interrupt context, so we do not
- * have to worry about disabling interrupts at all (unlike IRIX).
- */
-
-typedef spinlock_t lock_t;
-
-#define SPLDECL(s)                     unsigned long s
-#ifndef DEFINE_SPINLOCK
-#define DEFINE_SPINLOCK(s)             spinlock_t s = SPIN_LOCK_UNLOCKED
-#endif
-
-#define spinlock_init(lock, name)      spin_lock_init(lock)
-#define        spinlock_destroy(lock)
-#define mutex_spinlock(lock)           ({ spin_lock(lock); 0; })
-#define mutex_spinunlock(lock, s)      do { spin_unlock(lock); (void)s; } while (0)
-#define nested_spinlock(lock)          spin_lock(lock)
-#define nested_spinunlock(lock)                spin_unlock(lock)
-
-#endif /* __XFS_SUPPORT_SPIN_H__ */
index 2e34b104107cd8d7f76ba1a6901fa6900e5209a3..e0519529c26cca838a9c65cfb370eb593fef16a6 100644 (file)
@@ -107,6 +107,18 @@ xfs_page_trace(
 #define xfs_page_trace(tag, inode, page, pgoff)
 #endif
 
+STATIC struct block_device *
+xfs_find_bdev_for_inode(
+       struct xfs_inode        *ip)
+{
+       struct xfs_mount        *mp = ip->i_mount;
+
+       if (XFS_IS_REALTIME_INODE(ip))
+               return mp->m_rtdev_targp->bt_bdev;
+       else
+               return mp->m_ddev_targp->bt_bdev;
+}
+
 /*
  * Schedule IO completion handling on a xfsdatad if this was
  * the final hold on this ioend. If we are asked to wait,
@@ -151,7 +163,7 @@ xfs_destroy_ioend(
 /*
  * Update on-disk file size now that data has been written to disk.
  * The current in-memory file size is i_size.  If a write is beyond
- * eof io_new_size will be the intended file size until i_size is
+ * eof i_new_size will be the intended file size until i_size is
  * updated.  If this write does not extend all the way to the valid
  * file size then restrict this update to the end of the write.
  */
@@ -173,7 +185,7 @@ xfs_setfilesize(
 
        xfs_ilock(ip, XFS_ILOCK_EXCL);
 
-       isize = MAX(ip->i_size, ip->i_iocore.io_new_size);
+       isize = MAX(ip->i_size, ip->i_new_size);
        isize = MIN(isize, bsize);
 
        if (ip->i_d.di_size < isize) {
@@ -226,12 +238,13 @@ xfs_end_bio_unwritten(
 {
        xfs_ioend_t             *ioend =
                container_of(work, xfs_ioend_t, io_work);
+       struct xfs_inode        *ip = XFS_I(ioend->io_inode);
        xfs_off_t               offset = ioend->io_offset;
        size_t                  size = ioend->io_size;
 
        if (likely(!ioend->io_error)) {
-               xfs_bmap(XFS_I(ioend->io_inode), offset, size,
-                               BMAPI_UNWRITTEN, NULL, NULL);
+               if (!XFS_FORCED_SHUTDOWN(ip->i_mount))
+                       xfs_iomap_write_unwritten(ip, offset, size);
                xfs_setfilesize(ioend);
        }
        xfs_destroy_ioend(ioend);
@@ -304,7 +317,7 @@ xfs_map_blocks(
        xfs_inode_t             *ip = XFS_I(inode);
        int                     error, nmaps = 1;
 
-       error = xfs_bmap(ip, offset, count,
+       error = xfs_iomap(ip, offset, count,
                                flags, mapp, &nmaps);
        if (!error && (flags & (BMAPI_WRITE|BMAPI_ALLOCATE)))
                xfs_iflags_set(ip, XFS_IMODIFIED);
@@ -1323,7 +1336,7 @@ __xfs_get_blocks(
        offset = (xfs_off_t)iblock << inode->i_blkbits;
        ASSERT(bh_result->b_size >= (1 << inode->i_blkbits));
        size = bh_result->b_size;
-       error = xfs_bmap(XFS_I(inode), offset, size,
+       error = xfs_iomap(XFS_I(inode), offset, size,
                             create ? flags : BMAPI_READ, &iomap, &niomap);
        if (error)
                return -error;
@@ -1471,28 +1484,21 @@ xfs_vm_direct_IO(
 {
        struct file     *file = iocb->ki_filp;
        struct inode    *inode = file->f_mapping->host;
-       xfs_iomap_t     iomap;
-       int             maps = 1;
-       int             error;
+       struct block_device *bdev;
        ssize_t         ret;
 
-       error = xfs_bmap(XFS_I(inode), offset, 0,
-                               BMAPI_DEVICE, &iomap, &maps);
-       if (error)
-               return -error;
+       bdev = xfs_find_bdev_for_inode(XFS_I(inode));
 
        if (rw == WRITE) {
                iocb->private = xfs_alloc_ioend(inode, IOMAP_UNWRITTEN);
                ret = blockdev_direct_IO_own_locking(rw, iocb, inode,
-                       iomap.iomap_target->bt_bdev,
-                       iov, offset, nr_segs,
+                       bdev, iov, offset, nr_segs,
                        xfs_get_blocks_direct,
                        xfs_end_io_direct);
        } else {
                iocb->private = xfs_alloc_ioend(inode, IOMAP_READ);
                ret = blockdev_direct_IO_no_locking(rw, iocb, inode,
-                       iomap.iomap_target->bt_bdev,
-                       iov, offset, nr_segs,
+                       bdev, iov, offset, nr_segs,
                        xfs_get_blocks_direct,
                        xfs_end_io_direct);
        }
@@ -1525,8 +1531,7 @@ xfs_vm_bmap(
        struct inode            *inode = (struct inode *)mapping->host;
        struct xfs_inode        *ip = XFS_I(inode);
 
-       vn_trace_entry(XFS_I(inode), __FUNCTION__,
-                       (inst_t *)__return_address);
+       xfs_itrace_entry(XFS_I(inode));
        xfs_rwlock(ip, VRWLOCK_READ);
        xfs_flush_pages(ip, (xfs_off_t)0, -1, 0, FI_REMAPF);
        xfs_rwunlock(ip, VRWLOCK_READ);
index 0382c19d6523708792675b9215aebd4867801aa3..e347bfd47c9126f30680820519c31b4f06d91294 100644 (file)
@@ -387,8 +387,6 @@ _xfs_buf_lookup_pages(
                if (unlikely(page == NULL)) {
                        if (flags & XBF_READ_AHEAD) {
                                bp->b_page_count = i;
-                               for (i = 0; i < bp->b_page_count; i++)
-                                       unlock_page(bp->b_pages[i]);
                                return -ENOMEM;
                        }
 
@@ -418,24 +416,17 @@ _xfs_buf_lookup_pages(
                ASSERT(!PagePrivate(page));
                if (!PageUptodate(page)) {
                        page_count--;
-                       if (blocksize >= PAGE_CACHE_SIZE) {
-                               if (flags & XBF_READ)
-                                       bp->b_locked = 1;
-                       } else if (!PagePrivate(page)) {
+                       if (blocksize < PAGE_CACHE_SIZE && !PagePrivate(page)) {
                                if (test_page_region(page, offset, nbytes))
                                        page_count++;
                        }
                }
 
+               unlock_page(page);
                bp->b_pages[i] = page;
                offset = 0;
        }
 
-       if (!bp->b_locked) {
-               for (i = 0; i < bp->b_page_count; i++)
-                       unlock_page(bp->b_pages[i]);
-       }
-
        if (page_count == bp->b_page_count)
                bp->b_flags |= XBF_DONE;
 
@@ -751,7 +742,6 @@ xfs_buf_associate_memory(
                bp->b_pages[i] = mem_to_page((void *)pageaddr);
                pageaddr += PAGE_CACHE_SIZE;
        }
-       bp->b_locked = 0;
 
        bp->b_count_desired = len;
        bp->b_buffer_length = buflen;
@@ -1098,25 +1088,13 @@ xfs_buf_iostart(
        return status;
 }
 
-STATIC_INLINE int
-_xfs_buf_iolocked(
-       xfs_buf_t               *bp)
-{
-       ASSERT(bp->b_flags & (XBF_READ | XBF_WRITE));
-       if (bp->b_flags & XBF_READ)
-               return bp->b_locked;
-       return 0;
-}
-
 STATIC_INLINE void
 _xfs_buf_ioend(
        xfs_buf_t               *bp,
        int                     schedule)
 {
-       if (atomic_dec_and_test(&bp->b_io_remaining) == 1) {
-               bp->b_locked = 0;
+       if (atomic_dec_and_test(&bp->b_io_remaining) == 1)
                xfs_buf_ioend(bp, schedule);
-       }
 }
 
 STATIC void
@@ -1147,10 +1125,6 @@ xfs_buf_bio_end_io(
 
                if (--bvec >= bio->bi_io_vec)
                        prefetchw(&bvec->bv_page->flags);
-
-               if (_xfs_buf_iolocked(bp)) {
-                       unlock_page(page);
-               }
        } while (bvec >= bio->bi_io_vec);
 
        _xfs_buf_ioend(bp, 1);
@@ -1161,13 +1135,12 @@ STATIC void
 _xfs_buf_ioapply(
        xfs_buf_t               *bp)
 {
-       int                     i, rw, map_i, total_nr_pages, nr_pages;
+       int                     rw, map_i, total_nr_pages, nr_pages;
        struct bio              *bio;
        int                     offset = bp->b_offset;
        int                     size = bp->b_count_desired;
        sector_t                sector = bp->b_bn;
        unsigned int            blocksize = bp->b_target->bt_bsize;
-       int                     locking = _xfs_buf_iolocked(bp);
 
        total_nr_pages = bp->b_page_count;
        map_i = 0;
@@ -1190,7 +1163,7 @@ _xfs_buf_ioapply(
         * filesystem block size is not smaller than the page size.
         */
        if ((bp->b_buffer_length < PAGE_CACHE_SIZE) &&
-           (bp->b_flags & XBF_READ) && locking &&
+           (bp->b_flags & XBF_READ) &&
            (blocksize >= PAGE_CACHE_SIZE)) {
                bio = bio_alloc(GFP_NOIO, 1);
 
@@ -1207,24 +1180,6 @@ _xfs_buf_ioapply(
                goto submit_io;
        }
 
-       /* Lock down the pages which we need to for the request */
-       if (locking && (bp->b_flags & XBF_WRITE) && (bp->b_locked == 0)) {
-               for (i = 0; size; i++) {
-                       int             nbytes = PAGE_CACHE_SIZE - offset;
-                       struct page     *page = bp->b_pages[i];
-
-                       if (nbytes > size)
-                               nbytes = size;
-
-                       lock_page(page);
-
-                       size -= nbytes;
-                       offset = 0;
-               }
-               offset = bp->b_offset;
-               size = bp->b_count_desired;
-       }
-
 next_chunk:
        atomic_inc(&bp->b_io_remaining);
        nr_pages = BIO_MAX_SECTORS >> (PAGE_SHIFT - BBSHIFT);
@@ -1571,7 +1526,7 @@ xfs_alloc_delwrite_queue(
 
        INIT_LIST_HEAD(&btp->bt_list);
        INIT_LIST_HEAD(&btp->bt_delwrite_queue);
-       spinlock_init(&btp->bt_delwrite_lock, "delwri_lock");
+       spin_lock_init(&btp->bt_delwrite_lock);
        btp->bt_flags = 0;
        btp->bt_task = kthread_run(xfsbufd, btp, "xfsbufd");
        if (IS_ERR(btp->bt_task)) {
index b5908a34b15d80916ac7ce307a76f02e319bcf73..a3d207de48b8b206e510a9b4009a6eb5cedad5f7 100644 (file)
@@ -143,7 +143,6 @@ typedef struct xfs_buf {
        void                    *b_fspriv2;
        void                    *b_fspriv3;
        unsigned short          b_error;        /* error code on I/O */
-       unsigned short          b_locked;       /* page array is locked */
        unsigned int            b_page_count;   /* size of page array */
        unsigned int            b_offset;       /* page offset in first page */
        struct page             **b_pages;      /* array of page pointers */
index 15bd4948832ce7b1f789074b4ec77f53d0a9e25a..ca4f66c4de16aaa743f5dcb7cc0e44ae02715ef1 100644 (file)
@@ -118,20 +118,29 @@ xfs_nfs_get_inode(
        u64                     ino,
        u32                     generation)
  {
-       xfs_fid_t               xfid;
-       bhv_vnode_t             *vp;
+       xfs_mount_t             *mp = XFS_M(sb);
+       xfs_inode_t             *ip;
        int                     error;
 
-       xfid.fid_len = sizeof(xfs_fid_t) - sizeof(xfid.fid_len);
-       xfid.fid_pad = 0;
-       xfid.fid_ino = ino;
-       xfid.fid_gen = generation;
+       /*
+        * NFS can sometimes send requests for ino 0.  Fail them gracefully.
+        */
+       if (ino == 0)
+               return ERR_PTR(-ESTALE);
 
-       error = xfs_vget(XFS_M(sb), &vp, &xfid);
+       error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
        if (error)
                return ERR_PTR(-error);
+       if (!ip)
+               return ERR_PTR(-EIO);
+
+       if (!ip->i_d.di_mode || ip->i_d.di_gen != generation) {
+               xfs_iput_new(ip, XFS_ILOCK_SHARED);
+               return ERR_PTR(-ENOENT);
+       }
 
-       return vp ? vn_to_inode(vp) : NULL;
+       xfs_iunlock(ip, XFS_ILOCK_SHARED);
+       return ip->i_vnode;
 }
 
 STATIC struct dentry *
index 21a1c2b1c5fcf716b779fb973ef31fa5acb6114c..edab1ffbb163ef8bc53335645aee1faa334e364d 100644 (file)
@@ -350,8 +350,8 @@ xfs_file_readdir(
 
                size = buf.used;
                de = (struct hack_dirent *)buf.dirent;
-               curr_offset = de->offset /* & 0x7fffffff */;
                while (size > 0) {
+                       curr_offset = de->offset /* & 0x7fffffff */;
                        if (filldir(dirent, de->name, de->namlen,
                                        curr_offset & 0x7fffffff,
                                        de->ino, de->d_type)) {
@@ -362,7 +362,6 @@ xfs_file_readdir(
                                       sizeof(u64));
                        size -= reclen;
                        de = (struct hack_dirent *)((char *)de + reclen);
-                       curr_offset = de->offset /* & 0x7fffffff */;
                }
        }
 
index 9febf9dc999d902558c527fbc0a01c77c0f46602..ef90e64641e6a662b0478d74fc0918246c9a2e95 100644 (file)
@@ -47,5 +47,6 @@ xfs_param_t xfs_params = {
 /*
  * Global system credential structure.
  */
-cred_t sys_cred_val, *sys_cred = &sys_cred_val;
+static cred_t sys_cred_val;
+cred_t *sys_cred = &sys_cred_val;
 
index 98a56568bb24a942640729e47bd5d0e6a6d2234f..4c82a050a3a8be848ec8177edce521618a38398c 100644 (file)
@@ -75,7 +75,6 @@ xfs_find_handle(
        xfs_handle_t            handle;
        xfs_fsop_handlereq_t    hreq;
        struct inode            *inode;
-       bhv_vnode_t             *vp;
 
        if (copy_from_user(&hreq, arg, sizeof(hreq)))
                return -XFS_ERROR(EFAULT);
@@ -134,21 +133,16 @@ xfs_find_handle(
                return -XFS_ERROR(EBADF);
        }
 
-       /* we need the vnode */
-       vp = vn_from_inode(inode);
-
        /* now we can grab the fsid */
        memcpy(&handle.ha_fsid, XFS_I(inode)->i_mount->m_fixedfsid,
                        sizeof(xfs_fsid_t));
        hsize = sizeof(xfs_fsid_t);
 
        if (cmd != XFS_IOC_PATH_TO_FSHANDLE) {
-               xfs_inode_t     *ip;
+               xfs_inode_t     *ip = XFS_I(inode);
                int             lock_mode;
 
                /* need to get access to the xfs_inode to read the generation */
-               ip = xfs_vtoi(vp);
-               ASSERT(ip);
                lock_mode = xfs_ilock_map_shared(ip);
 
                /* fill in fid section of handle from inode */
@@ -176,21 +170,19 @@ xfs_find_handle(
 
 
 /*
- * Convert userspace handle data into vnode (and inode).
- * We [ab]use the fact that all the fsop_handlereq ioctl calls
- * have a data structure argument whose first component is always
- * a xfs_fsop_handlereq_t, so we can cast to and from this type.
- * This allows us to optimise the copy_from_user calls and gives
- * a handy, shared routine.
+ * Convert userspace handle data into inode.
+ *
+ * We use the fact that all the fsop_handlereq ioctl calls have a data
+ * structure argument whose first component is always a xfs_fsop_handlereq_t,
+ * so we can pass that sub structure into this handy, shared routine.
  *
- * If no error, caller must always VN_RELE the returned vp.
+ * If no error, caller must always iput the returned inode.
  */
 STATIC int
 xfs_vget_fsop_handlereq(
        xfs_mount_t             *mp,
        struct inode            *parinode,      /* parent inode pointer    */
        xfs_fsop_handlereq_t    *hreq,
-       bhv_vnode_t             **vp,
        struct inode            **inode)
 {
        void                    __user *hanp;
@@ -199,8 +191,6 @@ xfs_vget_fsop_handlereq(
        xfs_handle_t            *handlep;
        xfs_handle_t            handle;
        xfs_inode_t             *ip;
-       struct inode            *inodep;
-       bhv_vnode_t             *vpp;
        xfs_ino_t               ino;
        __u32                   igen;
        int                     error;
@@ -241,7 +231,7 @@ xfs_vget_fsop_handlereq(
        }
 
        /*
-        * Get the XFS inode, building a vnode to go with it.
+        * Get the XFS inode, building a Linux inode to go with it.
         */
        error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
        if (error)
@@ -253,12 +243,9 @@ xfs_vget_fsop_handlereq(
                return XFS_ERROR(ENOENT);
        }
 
-       vpp = XFS_ITOV(ip);
-       inodep = vn_to_inode(vpp);
        xfs_iunlock(ip, XFS_ILOCK_SHARED);
 
-       *vp = vpp;
-       *inode = inodep;
+       *inode = XFS_ITOV(ip);
        return 0;
 }
 
@@ -275,7 +262,6 @@ xfs_open_by_handle(
        struct file             *filp;
        struct inode            *inode;
        struct dentry           *dentry;
-       bhv_vnode_t             *vp;
        xfs_fsop_handlereq_t    hreq;
 
        if (!capable(CAP_SYS_ADMIN))
@@ -283,7 +269,7 @@ xfs_open_by_handle(
        if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
                return -XFS_ERROR(EFAULT);
 
-       error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
+       error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &inode);
        if (error)
                return -error;
 
@@ -385,7 +371,6 @@ xfs_readlink_by_handle(
 {
        struct inode            *inode;
        xfs_fsop_handlereq_t    hreq;
-       bhv_vnode_t             *vp;
        __u32                   olen;
        void                    *link;
        int                     error;
@@ -395,7 +380,7 @@ xfs_readlink_by_handle(
        if (copy_from_user(&hreq, arg, sizeof(xfs_fsop_handlereq_t)))
                return -XFS_ERROR(EFAULT);
 
-       error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &vp, &inode);
+       error = xfs_vget_fsop_handlereq(mp, parinode, &hreq, &inode);
        if (error)
                return -error;
 
@@ -438,34 +423,32 @@ xfs_fssetdm_by_handle(
        struct fsdmidata        fsd;
        xfs_fsop_setdm_handlereq_t dmhreq;
        struct inode            *inode;
-       bhv_vnode_t             *vp;
 
        if (!capable(CAP_MKNOD))
                return -XFS_ERROR(EPERM);
        if (copy_from_user(&dmhreq, arg, sizeof(xfs_fsop_setdm_handlereq_t)))
                return -XFS_ERROR(EFAULT);
 
-       error = xfs_vget_fsop_handlereq(mp, parinode, &dmhreq.hreq, &vp, &inode);
+       error = xfs_vget_fsop_handlereq(mp, parinode, &dmhreq.hreq, &inode);
        if (error)
                return -error;
 
        if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) {
-               VN_RELE(vp);
-               return -XFS_ERROR(EPERM);
+               error = -XFS_ERROR(EPERM);
+               goto out;
        }
 
        if (copy_from_user(&fsd, dmhreq.data, sizeof(fsd))) {
-               VN_RELE(vp);
-               return -XFS_ERROR(EFAULT);
+               error = -XFS_ERROR(EFAULT);
+               goto out;
        }
 
-       error = xfs_set_dmattrs(xfs_vtoi(vp),
-                       fsd.fsd_dmevmask, fsd.fsd_dmstate);
+       error = -xfs_set_dmattrs(XFS_I(inode), fsd.fsd_dmevmask,
+                                fsd.fsd_dmstate);
 
-       VN_RELE(vp);
-       if (error)
-               return -error;
-       return 0;
+ out:
+       iput(inode);
+       return error;
 }
 
 STATIC int
@@ -478,7 +461,6 @@ xfs_attrlist_by_handle(
        attrlist_cursor_kern_t  *cursor;
        xfs_fsop_attrlist_handlereq_t al_hreq;
        struct inode            *inode;
-       bhv_vnode_t             *vp;
        char                    *kbuf;
 
        if (!capable(CAP_SYS_ADMIN))
@@ -488,8 +470,7 @@ xfs_attrlist_by_handle(
        if (al_hreq.buflen > XATTR_LIST_MAX)
                return -XFS_ERROR(EINVAL);
 
-       error = xfs_vget_fsop_handlereq(mp, parinode, &al_hreq.hreq,
-                       &vp, &inode);
+       error = xfs_vget_fsop_handlereq(mp, parinode, &al_hreq.hreq, &inode);
        if (error)
                goto out;
 
@@ -509,7 +490,7 @@ xfs_attrlist_by_handle(
  out_kfree:
        kfree(kbuf);
  out_vn_rele:
-       VN_RELE(vp);
+       iput(inode);
  out:
        return -error;
 }
@@ -531,7 +512,7 @@ xfs_attrmulti_attr_get(
        if (!kbuf)
                return ENOMEM;
 
-       error = xfs_attr_get(XFS_I(inode), name, kbuf, len, flags, NULL);
+       error = xfs_attr_get(XFS_I(inode), name, kbuf, (int *)len, flags, NULL);
        if (error)
                goto out_kfree;
 
@@ -598,7 +579,6 @@ xfs_attrmulti_by_handle(
        xfs_attr_multiop_t      *ops;
        xfs_fsop_attrmulti_handlereq_t am_hreq;
        struct inode            *inode;
-       bhv_vnode_t             *vp;
        unsigned int            i, size;
        char                    *attr_name;
 
@@ -607,7 +587,7 @@ xfs_attrmulti_by_handle(
        if (copy_from_user(&am_hreq, arg, sizeof(xfs_fsop_attrmulti_handlereq_t)))
                return -XFS_ERROR(EFAULT);
 
-       error = xfs_vget_fsop_handlereq(mp, parinode, &am_hreq.hreq, &vp, &inode);
+       error = xfs_vget_fsop_handlereq(mp, parinode, &am_hreq.hreq, &inode);
        if (error)
                goto out;
 
@@ -666,7 +646,7 @@ xfs_attrmulti_by_handle(
  out_kfree_ops:
        kfree(ops);
  out_vn_rele:
-       VN_RELE(vp);
+       iput(inode);
  out:
        return -error;
 }
@@ -702,7 +682,6 @@ xfs_ioc_fsgeometry(
 
 STATIC int
 xfs_ioc_xattr(
-       bhv_vnode_t             *vp,
        xfs_inode_t             *ip,
        struct file             *filp,
        unsigned int            cmd,
@@ -735,12 +714,10 @@ xfs_ioctl(
        void                    __user *arg)
 {
        struct inode            *inode = filp->f_path.dentry->d_inode;
-       bhv_vnode_t             *vp = vn_from_inode(inode);
        xfs_mount_t             *mp = ip->i_mount;
        int                     error;
 
-       vn_trace_entry(XFS_I(inode), "xfs_ioctl", (inst_t *)__return_address);
-
+       xfs_itrace_entry(XFS_I(inode));
        switch (cmd) {
 
        case XFS_IOC_ALLOCSP:
@@ -764,7 +741,7 @@ xfs_ioctl(
        case XFS_IOC_DIOINFO: {
                struct dioattr  da;
                xfs_buftarg_t   *target =
-                       (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
+                       XFS_IS_REALTIME_INODE(ip) ?
                        mp->m_rtdev_targp : mp->m_ddev_targp;
 
                da.d_mem = da.d_miniosz = 1 << target->bt_sshift;
@@ -796,7 +773,7 @@ xfs_ioctl(
        case XFS_IOC_GETXFLAGS:
        case XFS_IOC_SETXFLAGS:
        case XFS_IOC_FSSETXATTR:
-               return xfs_ioc_xattr(vp, ip, filp, cmd, arg);
+               return xfs_ioc_xattr(ip, filp, cmd, arg);
 
        case XFS_IOC_FSSETDM: {
                struct fsdmidata        dmi;
@@ -1203,7 +1180,6 @@ xfs_ioc_fsgetxattr(
 
 STATIC int
 xfs_ioc_xattr(
-       bhv_vnode_t             *vp,
        xfs_inode_t             *ip,
        struct file             *filp,
        unsigned int            cmd,
@@ -1237,7 +1213,7 @@ xfs_ioc_xattr(
 
                error = xfs_setattr(ip, vattr, attr_flags, NULL);
                if (likely(!error))
-                       __vn_revalidate(vp, vattr);     /* update flags */
+                       vn_revalidate(XFS_ITOV(ip));    /* update flags */
                error = -error;
                break;
        }
@@ -1272,7 +1248,7 @@ xfs_ioc_xattr(
 
                error = xfs_setattr(ip, vattr, attr_flags, NULL);
                if (likely(!error))
-                       __vn_revalidate(vp, vattr);     /* update flags */
+                       vn_revalidate(XFS_ITOV(ip));    /* update flags */
                error = -error;
                break;
        }
index bf2a956b63c28490f4eae13cd8d58a09df17ce81..a4b254eb43b2ec74151ada8ffb1e9fc2dd41cfab 100644 (file)
@@ -44,6 +44,7 @@
 #include "xfs_error.h"
 #include "xfs_dfrag.h"
 #include "xfs_vnodeops.h"
+#include "xfs_ioctl32.h"
 
 #define  _NATIVE_IOC(cmd, type) \
          _IOC(_IOC_DIR(cmd), _IOC_TYPE(cmd), _IOC_NR(cmd), sizeof(type))
@@ -379,9 +380,6 @@ xfs_compat_ioctl(
        switch (cmd) {
        case XFS_IOC_DIOINFO:
        case XFS_IOC_FSGEOMETRY:
-       case XFS_IOC_GETVERSION:
-       case XFS_IOC_GETXFLAGS:
-       case XFS_IOC_SETXFLAGS:
        case XFS_IOC_FSGETXATTR:
        case XFS_IOC_FSSETXATTR:
        case XFS_IOC_FSGETXATTRA:
@@ -407,6 +405,11 @@ xfs_compat_ioctl(
        case XFS_IOC_ERROR_CLEARALL:
                break;
 
+       case XFS_IOC32_GETXFLAGS:
+       case XFS_IOC32_SETXFLAGS:
+       case XFS_IOC32_GETVERSION:
+               cmd = _NATIVE_IOC(cmd, long);
+               break;
 #ifdef BROKEN_X86_ALIGNMENT
        /* xfs_flock_t has wrong u32 vs u64 alignment */
        case XFS_IOC_ALLOCSP_32:
index 5e8bb7f71b5ae214ab7802b77cae09a6c44901bf..cc4abd3daa49b62aa8a6a822015e33c69e099ea9 100644 (file)
@@ -52,6 +52,7 @@
 #include <linux/xattr.h>
 #include <linux/namei.h>
 #include <linux/security.h>
+#include <linux/falloc.h>
 
 /*
  * Bring the atime in the XFS inode uptodate.
@@ -70,6 +71,22 @@ xfs_synchronize_atime(
        }
 }
 
+/*
+ * If the linux inode exists, mark it dirty.
+ * Used when commiting a dirty inode into a transaction so that
+ * the inode will get written back by the linux code
+ */
+void
+xfs_mark_inode_dirty_sync(
+       xfs_inode_t     *ip)
+{
+       bhv_vnode_t     *vp;
+
+       vp = XFS_ITOV_NULL(ip);
+       if (vp)
+               mark_inode_dirty_sync(vn_to_inode(vp));
+}
+
 /*
  * Change the requested timestamp in the given inode.
  * We don't lock across timestamp updates, and we don't log them but
@@ -184,10 +201,6 @@ xfs_validate_fields(
        struct xfs_inode        *ip = XFS_I(inode);
        loff_t size;
 
-       inode->i_nlink = ip->i_d.di_nlink;
-       inode->i_blocks =
-               XFS_FSB_TO_BB(ip->i_mount, ip->i_d.di_nblocks +
-                                          ip->i_delayed_blks);
        /* we're under i_sem so i_size can't change under us */
        size = XFS_ISIZE(ip);
        if (i_size_read(inode) != size)
@@ -541,13 +554,32 @@ xfs_vn_put_link(
 }
 
 #ifdef CONFIG_XFS_POSIX_ACL
+STATIC int
+xfs_check_acl(
+       struct inode            *inode,
+       int                     mask)
+{
+       struct xfs_inode        *ip = XFS_I(inode);
+       int                     error;
+
+       xfs_itrace_entry(ip);
+
+       if (XFS_IFORK_Q(ip)) {
+               error = xfs_acl_iaccess(ip, mask, NULL);
+               if (error != -1)
+                       return -error;
+       }
+
+       return -EAGAIN;
+}
+
 STATIC int
 xfs_vn_permission(
-       struct inode    *inode,
-       int             mode,
-       struct nameidata *nd)
+       struct inode            *inode,
+       int                     mask,
+       struct nameidata        *nd)
 {
-       return -xfs_access(XFS_I(inode), mode << 6, NULL);
+       return generic_permission(inode, mask, xfs_check_acl);
 }
 #else
 #define xfs_vn_permission NULL
@@ -555,33 +587,61 @@ xfs_vn_permission(
 
 STATIC int
 xfs_vn_getattr(
-       struct vfsmount *mnt,
-       struct dentry   *dentry,
-       struct kstat    *stat)
+       struct vfsmount         *mnt,
+       struct dentry           *dentry,
+       struct kstat            *stat)
 {
-       struct inode    *inode = dentry->d_inode;
-       bhv_vattr_t     vattr = { .va_mask = XFS_AT_STAT };
-       int             error;
-
-       error = xfs_getattr(XFS_I(inode), &vattr, ATTR_LAZY);
-       if (likely(!error)) {
-               stat->size = i_size_read(inode);
-               stat->dev = inode->i_sb->s_dev;
-               stat->rdev = (vattr.va_rdev == 0) ? 0 :
-                               MKDEV(sysv_major(vattr.va_rdev) & 0x1ff,
-                                     sysv_minor(vattr.va_rdev));
-               stat->mode = vattr.va_mode;
-               stat->nlink = vattr.va_nlink;
-               stat->uid = vattr.va_uid;
-               stat->gid = vattr.va_gid;
-               stat->ino = vattr.va_nodeid;
-               stat->atime = vattr.va_atime;
-               stat->mtime = vattr.va_mtime;
-               stat->ctime = vattr.va_ctime;
-               stat->blocks = vattr.va_nblocks;
-               stat->blksize = vattr.va_blocksize;
+       struct inode            *inode = dentry->d_inode;
+       struct xfs_inode        *ip = XFS_I(inode);
+       struct xfs_mount        *mp = ip->i_mount;
+
+       xfs_itrace_entry(ip);
+
+       if (XFS_FORCED_SHUTDOWN(mp))
+               return XFS_ERROR(EIO);
+
+       stat->size = XFS_ISIZE(ip);
+       stat->dev = inode->i_sb->s_dev;
+       stat->mode = ip->i_d.di_mode;
+       stat->nlink = ip->i_d.di_nlink;
+       stat->uid = ip->i_d.di_uid;
+       stat->gid = ip->i_d.di_gid;
+       stat->ino = ip->i_ino;
+#if XFS_BIG_INUMS
+       stat->ino += mp->m_inoadd;
+#endif
+       stat->atime = inode->i_atime;
+       stat->mtime.tv_sec = ip->i_d.di_mtime.t_sec;
+       stat->mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
+       stat->ctime.tv_sec = ip->i_d.di_ctime.t_sec;
+       stat->ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
+       stat->blocks =
+               XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
+
+
+       switch (inode->i_mode & S_IFMT) {
+       case S_IFBLK:
+       case S_IFCHR:
+               stat->blksize = BLKDEV_IOSIZE;
+               stat->rdev = MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
+                                  sysv_minor(ip->i_df.if_u2.if_rdev));
+               break;
+       default:
+               if (XFS_IS_REALTIME_INODE(ip)) {
+                       /*
+                        * If the file blocks are being allocated from a
+                        * realtime volume, then return the inode's realtime
+                        * extent size or the realtime volume's extent size.
+                        */
+                       stat->blksize =
+                               xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
+               } else
+                       stat->blksize = xfs_preferred_iosize(mp);
+               stat->rdev = 0;
+               break;
        }
-       return -error;
+
+       return 0;
 }
 
 STATIC int
@@ -636,7 +696,7 @@ xfs_vn_setattr(
 
        error = xfs_setattr(XFS_I(inode), &vattr, flags, NULL);
        if (likely(!error))
-               __vn_revalidate(vn_from_inode(inode), &vattr);
+               vn_revalidate(vn_from_inode(inode));
        return -error;
 }
 
@@ -750,6 +810,47 @@ xfs_vn_removexattr(
        return namesp->attr_remove(vp, attr, xflags);
 }
 
+STATIC long
+xfs_vn_fallocate(
+       struct inode    *inode,
+       int             mode,
+       loff_t          offset,
+       loff_t          len)
+{
+       long            error;
+       loff_t          new_size = 0;
+       xfs_flock64_t   bf;
+       xfs_inode_t     *ip = XFS_I(inode);
+
+       /* preallocation on directories not yet supported */
+       error = -ENODEV;
+       if (S_ISDIR(inode->i_mode))
+               goto out_error;
+
+       bf.l_whence = 0;
+       bf.l_start = offset;
+       bf.l_len = len;
+
+       xfs_ilock(ip, XFS_IOLOCK_EXCL);
+       error = xfs_change_file_space(ip, XFS_IOC_RESVSP, &bf,
+                                               0, NULL, ATTR_NOLOCK);
+       if (!error && !(mode & FALLOC_FL_KEEP_SIZE) &&
+           offset + len > i_size_read(inode))
+               new_size = offset + len;
+
+       /* Change file size if needed */
+       if (new_size) {
+               bhv_vattr_t     va;
+
+               va.va_mask = XFS_AT_SIZE;
+               va.va_size = new_size;
+               error = xfs_setattr(ip, &va, ATTR_NOLOCK, NULL);
+       }
+
+       xfs_iunlock(ip, XFS_IOLOCK_EXCL);
+out_error:
+       return error;
+}
 
 const struct inode_operations xfs_inode_operations = {
        .permission             = xfs_vn_permission,
@@ -760,6 +861,7 @@ const struct inode_operations xfs_inode_operations = {
        .getxattr               = xfs_vn_getxattr,
        .listxattr              = xfs_vn_listxattr,
        .removexattr            = xfs_vn_removexattr,
+       .fallocate              = xfs_vn_fallocate,
 };
 
 const struct inode_operations xfs_dir_inode_operations = {
index dc3752de22da198a9a39c603f1e26eab23053588..3ca39c4e5d2a7cdcf8dc02c0e668e1ef71646c28 100644 (file)
@@ -43,7 +43,6 @@
 
 #include <kmem.h>
 #include <mrlock.h>
-#include <spin.h>
 #include <sv.h>
 #include <mutex.h>
 #include <sema.h>
@@ -75,6 +74,7 @@
 #include <linux/notifier.h>
 #include <linux/delay.h>
 #include <linux/log2.h>
+#include <linux/spinlock.h>
 
 #include <asm/page.h>
 #include <asm/div64.h>
 #define current_restore_flags_nested(sp, f)    \
                (current->flags = ((current->flags & ~(f)) | (*(sp) & (f))))
 
-#define NBPP           PAGE_SIZE
-#define NDPP           (1 << (PAGE_SHIFT - 9))
+#define spinlock_destroy(lock)
 
 #define NBBY           8               /* number of bits per byte */
-#define        NBPC            PAGE_SIZE       /* Number of bytes per click */
-#define        BPCSHIFT        PAGE_SHIFT      /* LOG2(NBPC) if exact */
 
 /*
  * Size of block device i/o is parameterized here.
  * Currently the system supports page-sized i/o.
  */
-#define        BLKDEV_IOSHIFT          BPCSHIFT
+#define        BLKDEV_IOSHIFT          PAGE_CACHE_SHIFT
 #define        BLKDEV_IOSIZE           (1<<BLKDEV_IOSHIFT)
 /* number of BB's per block device block */
 #define        BLKDEV_BB               BTOBB(BLKDEV_IOSIZE)
 
-/* bytes to clicks */
-#define        btoc(x)         (((__psunsigned_t)(x)+(NBPC-1))>>BPCSHIFT)
-#define        btoct(x)        ((__psunsigned_t)(x)>>BPCSHIFT)
-#define        btoc64(x)       (((__uint64_t)(x)+(NBPC-1))>>BPCSHIFT)
-#define        btoct64(x)      ((__uint64_t)(x)>>BPCSHIFT)
-
-/* off_t bytes to clicks */
-#define offtoc(x)       (((__uint64_t)(x)+(NBPC-1))>>BPCSHIFT)
-#define offtoct(x)      ((xfs_off_t)(x)>>BPCSHIFT)
-
-/* clicks to off_t bytes */
-#define        ctooff(x)       ((xfs_off_t)(x)<<BPCSHIFT)
-
-/* clicks to bytes */
-#define        ctob(x)         ((__psunsigned_t)(x)<<BPCSHIFT)
-#define btoct(x)        ((__psunsigned_t)(x)>>BPCSHIFT)
-#define        ctob64(x)       ((__uint64_t)(x)<<BPCSHIFT)
-
-/* bytes to clicks */
-#define btoc(x)         (((__psunsigned_t)(x)+(NBPC-1))>>BPCSHIFT)
-
 #define ENOATTR                ENODATA         /* Attribute not found */
 #define EWRONGFS       EINVAL          /* Mount with wrong filesystem type */
 #define EFSCORRUPTED   EUCLEAN         /* Filesystem is corrupted */
 #define xfs_stack_trace()      dump_stack()
 #define xfs_itruncate_data(ip, off)    \
        (-vmtruncate(vn_to_inode(XFS_ITOV(ip)), (off)))
-#define xfs_statvfs_fsid(statp, mp)    \
-       ({ u64 id = huge_encode_dev((mp)->m_ddev_targp->bt_dev); \
-          __kernel_fsid_t *fsid = &(statp)->f_fsid;    \
-       (fsid->val[0] = (u32)id, fsid->val[1] = (u32)(id >> 32)); })
 
 
 /* Move the kernel do_div definition off to one side */
index 6f614f35f65015140d2078a92484328d275e94c1..1663533884902bb749a371271e7e4943f507a3f7 100644 (file)
 void
 xfs_rw_enter_trace(
        int                     tag,
-       xfs_iocore_t            *io,
+       xfs_inode_t             *ip,
        void                    *data,
        size_t                  segs,
        loff_t                  offset,
        int                     ioflags)
 {
-       xfs_inode_t     *ip = XFS_IO_INODE(io);
-
        if (ip->i_rwtrace == NULL)
                return;
        ktrace_enter(ip->i_rwtrace,
@@ -78,8 +76,8 @@ xfs_rw_enter_trace(
                (void *)((unsigned long)((offset >> 32) & 0xffffffff)),
                (void *)((unsigned long)(offset & 0xffffffff)),
                (void *)((unsigned long)ioflags),
-               (void *)((unsigned long)((io->io_new_size >> 32) & 0xffffffff)),
-               (void *)((unsigned long)(io->io_new_size & 0xffffffff)),
+               (void *)((unsigned long)((ip->i_new_size >> 32) & 0xffffffff)),
+               (void *)((unsigned long)(ip->i_new_size & 0xffffffff)),
                (void *)((unsigned long)current_pid()),
                (void *)NULL,
                (void *)NULL,
@@ -89,13 +87,12 @@ xfs_rw_enter_trace(
 
 void
 xfs_inval_cached_trace(
-       xfs_iocore_t    *io,
+       xfs_inode_t     *ip,
        xfs_off_t       offset,
        xfs_off_t       len,
        xfs_off_t       first,
        xfs_off_t       last)
 {
-       xfs_inode_t     *ip = XFS_IO_INODE(io);
 
        if (ip->i_rwtrace == NULL)
                return;
@@ -131,7 +128,7 @@ xfs_inval_cached_trace(
  */
 STATIC int
 xfs_iozero(
-       struct inode            *ip,    /* inode                        */
+       struct xfs_inode        *ip,    /* inode                        */
        loff_t                  pos,    /* offset in file               */
        size_t                  count)  /* size of data to zero         */
 {
@@ -139,7 +136,7 @@ xfs_iozero(
        struct address_space    *mapping;
        int                     status;
 
-       mapping = ip->i_mapping;
+       mapping = ip->i_vnode->i_mapping;
        do {
                unsigned offset, bytes;
                void *fsdata;
@@ -205,7 +202,7 @@ xfs_read(
 
        if (unlikely(ioflags & IO_ISDIRECT)) {
                xfs_buftarg_t   *target =
-                       (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
+                       XFS_IS_REALTIME_INODE(ip) ?
                                mp->m_rtdev_targp : mp->m_ddev_targp;
                if ((*offset & target->bt_smask) ||
                    (size & target->bt_smask)) {
@@ -246,9 +243,8 @@ xfs_read(
 
        if (unlikely(ioflags & IO_ISDIRECT)) {
                if (VN_CACHED(vp))
-                       ret = xfs_flushinval_pages(ip,
-                                       ctooff(offtoct(*offset)),
-                                       -1, FI_REMAPF_LOCKED);
+                       ret = xfs_flushinval_pages(ip, (*offset & PAGE_CACHE_MASK),
+                                                   -1, FI_REMAPF_LOCKED);
                mutex_unlock(&inode->i_mutex);
                if (ret) {
                        xfs_iunlock(ip, XFS_IOLOCK_SHARED);
@@ -256,7 +252,7 @@ xfs_read(
                }
        }
 
-       xfs_rw_enter_trace(XFS_READ_ENTER, &ip->i_iocore,
+       xfs_rw_enter_trace(XFS_READ_ENTER, ip,
                                (void *)iovp, segs, *offset, ioflags);
 
        iocb->ki_pos = *offset;
@@ -301,7 +297,7 @@ xfs_splice_read(
                        return -error;
                }
        }
-       xfs_rw_enter_trace(XFS_SPLICE_READ_ENTER, &ip->i_iocore,
+       xfs_rw_enter_trace(XFS_SPLICE_READ_ENTER, ip,
                           pipe, count, *ppos, ioflags);
        ret = generic_file_splice_read(infilp, ppos, pipe, count, flags);
        if (ret > 0)
@@ -323,7 +319,6 @@ xfs_splice_write(
 {
        bhv_vnode_t             *vp = XFS_ITOV(ip);
        xfs_mount_t             *mp = ip->i_mount;
-       xfs_iocore_t            *io = &ip->i_iocore;
        ssize_t                 ret;
        struct inode            *inode = outfilp->f_mapping->host;
        xfs_fsize_t             isize, new_size;
@@ -350,10 +345,10 @@ xfs_splice_write(
 
        xfs_ilock(ip, XFS_ILOCK_EXCL);
        if (new_size > ip->i_size)
-               io->io_new_size = new_size;
+               ip->i_new_size = new_size;
        xfs_iunlock(ip, XFS_ILOCK_EXCL);
 
-       xfs_rw_enter_trace(XFS_SPLICE_WRITE_ENTER, &ip->i_iocore,
+       xfs_rw_enter_trace(XFS_SPLICE_WRITE_ENTER, ip,
                           pipe, count, *ppos, ioflags);
        ret = generic_file_splice_write(pipe, outfilp, ppos, count, flags);
        if (ret > 0)
@@ -370,9 +365,9 @@ xfs_splice_write(
                xfs_iunlock(ip, XFS_ILOCK_EXCL);
        }
 
-       if (io->io_new_size) {
+       if (ip->i_new_size) {
                xfs_ilock(ip, XFS_ILOCK_EXCL);
-               io->io_new_size = 0;
+               ip->i_new_size = 0;
                if (ip->i_d.di_size > ip->i_size)
                        ip->i_d.di_size = ip->i_size;
                xfs_iunlock(ip, XFS_ILOCK_EXCL);
@@ -389,20 +384,19 @@ xfs_splice_write(
  */
 STATIC int                             /* error (positive) */
 xfs_zero_last_block(
-       struct inode    *ip,
-       xfs_iocore_t    *io,
+       xfs_inode_t     *ip,
        xfs_fsize_t     offset,
        xfs_fsize_t     isize)
 {
        xfs_fileoff_t   last_fsb;
-       xfs_mount_t     *mp = io->io_mount;
+       xfs_mount_t     *mp = ip->i_mount;
        int             nimaps;
        int             zero_offset;
        int             zero_len;
        int             error = 0;
        xfs_bmbt_irec_t imap;
 
-       ASSERT(ismrlocked(io->io_lock, MR_UPDATE) != 0);
+       ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE) != 0);
 
        zero_offset = XFS_B_FSB_OFFSET(mp, isize);
        if (zero_offset == 0) {
@@ -415,7 +409,7 @@ xfs_zero_last_block(
 
        last_fsb = XFS_B_TO_FSBT(mp, isize);
        nimaps = 1;
-       error = XFS_BMAPI(mp, NULL, io, last_fsb, 1, 0, NULL, 0, &imap,
+       error = xfs_bmapi(NULL, ip, last_fsb, 1, 0, NULL, 0, &imap,
                          &nimaps, NULL, NULL);
        if (error) {
                return error;
@@ -433,14 +427,14 @@ xfs_zero_last_block(
         * out sync.  We need to drop the ilock while we do this so we
         * don't deadlock when the buffer cache calls back to us.
         */
-       XFS_IUNLOCK(mp, io, XFS_ILOCK_EXCL| XFS_EXTSIZE_RD);
+       xfs_iunlock(ip, XFS_ILOCK_EXCL| XFS_EXTSIZE_RD);
 
        zero_len = mp->m_sb.sb_blocksize - zero_offset;
        if (isize + zero_len > offset)
                zero_len = offset - isize;
        error = xfs_iozero(ip, isize, zero_len);
 
-       XFS_ILOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
+       xfs_ilock(ip, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
        ASSERT(error >= 0);
        return error;
 }
@@ -458,35 +452,33 @@ xfs_zero_last_block(
 
 int                                    /* error (positive) */
 xfs_zero_eof(
-       bhv_vnode_t     *vp,
-       xfs_iocore_t    *io,
+       xfs_inode_t     *ip,
        xfs_off_t       offset,         /* starting I/O offset */
        xfs_fsize_t     isize)          /* current inode size */
 {
-       struct inode    *ip = vn_to_inode(vp);
+       xfs_mount_t     *mp = ip->i_mount;
        xfs_fileoff_t   start_zero_fsb;
        xfs_fileoff_t   end_zero_fsb;
        xfs_fileoff_t   zero_count_fsb;
        xfs_fileoff_t   last_fsb;
        xfs_fileoff_t   zero_off;
        xfs_fsize_t     zero_len;
-       xfs_mount_t     *mp = io->io_mount;
        int             nimaps;
        int             error = 0;
        xfs_bmbt_irec_t imap;
 
-       ASSERT(ismrlocked(io->io_lock, MR_UPDATE));
-       ASSERT(ismrlocked(io->io_iolock, MR_UPDATE));
+       ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE));
+       ASSERT(ismrlocked(&ip->i_iolock, MR_UPDATE));
        ASSERT(offset > isize);
 
        /*
         * First handle zeroing the block on which isize resides.
         * We only zero a part of that block so it is handled specially.
         */
-       error = xfs_zero_last_block(ip, io, offset, isize);
+       error = xfs_zero_last_block(ip, offset, isize);
        if (error) {
-               ASSERT(ismrlocked(io->io_lock, MR_UPDATE));
-               ASSERT(ismrlocked(io->io_iolock, MR_UPDATE));
+               ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE));
+               ASSERT(ismrlocked(&ip->i_iolock, MR_UPDATE));
                return error;
        }
 
@@ -514,11 +506,11 @@ xfs_zero_eof(
        while (start_zero_fsb <= end_zero_fsb) {
                nimaps = 1;
                zero_count_fsb = end_zero_fsb - start_zero_fsb + 1;
-               error = XFS_BMAPI(mp, NULL, io, start_zero_fsb, zero_count_fsb,
+               error = xfs_bmapi(NULL, ip, start_zero_fsb, zero_count_fsb,
                                  0, NULL, 0, &imap, &nimaps, NULL, NULL);
                if (error) {
-                       ASSERT(ismrlocked(io->io_lock, MR_UPDATE));
-                       ASSERT(ismrlocked(io->io_iolock, MR_UPDATE));
+                       ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE));
+                       ASSERT(ismrlocked(&ip->i_iolock, MR_UPDATE));
                        return error;
                }
                ASSERT(nimaps > 0);
@@ -542,7 +534,7 @@ xfs_zero_eof(
                 * Drop the inode lock while we're doing the I/O.
                 * We'll still have the iolock to protect us.
                 */
-               XFS_IUNLOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
+               xfs_iunlock(ip, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
 
                zero_off = XFS_FSB_TO_B(mp, start_zero_fsb);
                zero_len = XFS_FSB_TO_B(mp, imap.br_blockcount);
@@ -558,14 +550,13 @@ xfs_zero_eof(
                start_zero_fsb = imap.br_startoff + imap.br_blockcount;
                ASSERT(start_zero_fsb <= (end_zero_fsb + 1));
 
-               XFS_ILOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
+               xfs_ilock(ip, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
        }
 
        return 0;
 
 out_lock:
-
-       XFS_ILOCK(mp, io, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
+       xfs_ilock(ip, XFS_ILOCK_EXCL|XFS_EXTSIZE_RD);
        ASSERT(error >= 0);
        return error;
 }
@@ -587,7 +578,6 @@ xfs_write(
        xfs_mount_t             *mp;
        ssize_t                 ret = 0, error = 0;
        xfs_fsize_t             isize, new_size;
-       xfs_iocore_t            *io;
        int                     iolock;
        int                     eventsent = 0;
        bhv_vrwlock_t           locktype;
@@ -607,8 +597,7 @@ xfs_write(
        if (count == 0)
                return 0;
 
-       io = &xip->i_iocore;
-       mp = io->io_mount;
+       mp = xip->i_mount;
 
        xfs_wait_for_freeze(mp, SB_FREEZE_WRITE);
 
@@ -667,7 +656,7 @@ start:
 
        if (ioflags & IO_ISDIRECT) {
                xfs_buftarg_t   *target =
-                       (xip->i_d.di_flags & XFS_DIFLAG_REALTIME) ?
+                       XFS_IS_REALTIME_INODE(xip) ?
                                mp->m_rtdev_targp : mp->m_ddev_targp;
 
                if ((pos & target->bt_smask) || (count & target->bt_smask)) {
@@ -688,7 +677,7 @@ start:
 
        new_size = pos + count;
        if (new_size > xip->i_size)
-               io->io_new_size = new_size;
+               xip->i_new_size = new_size;
 
        if (likely(!(ioflags & IO_INVIS))) {
                file_update_time(file);
@@ -706,7 +695,7 @@ start:
         */
 
        if (pos > xip->i_size) {
-               error = xfs_zero_eof(vp, io, pos, xip->i_size);
+               error = xfs_zero_eof(xip, pos, xip->i_size);
                if (error) {
                        xfs_iunlock(xip, XFS_ILOCK_EXCL);
                        goto out_unlock_internal;
@@ -740,10 +729,10 @@ retry:
        if ((ioflags & IO_ISDIRECT)) {
                if (VN_CACHED(vp)) {
                        WARN_ON(need_i_mutex == 0);
-                       xfs_inval_cached_trace(io, pos, -1,
-                                       ctooff(offtoct(pos)), -1);
+                       xfs_inval_cached_trace(xip, pos, -1,
+                                       (pos & PAGE_CACHE_MASK), -1);
                        error = xfs_flushinval_pages(xip,
-                                       ctooff(offtoct(pos)),
+                                       (pos & PAGE_CACHE_MASK),
                                        -1, FI_REMAPF_LOCKED);
                        if (error)
                                goto out_unlock_internal;
@@ -751,7 +740,7 @@ retry:
 
                if (need_i_mutex) {
                        /* demote the lock now the cached pages are gone */
-                       XFS_ILOCK_DEMOTE(mp, io, XFS_IOLOCK_EXCL);
+                       xfs_ilock_demote(xip, XFS_IOLOCK_EXCL);
                        mutex_unlock(&inode->i_mutex);
 
                        iolock = XFS_IOLOCK_SHARED;
@@ -759,7 +748,7 @@ retry:
                        need_i_mutex = 0;
                }
 
-               xfs_rw_enter_trace(XFS_DIOWR_ENTER, io, (void *)iovp, segs,
+               xfs_rw_enter_trace(XFS_DIOWR_ENTER, xip, (void *)iovp, segs,
                                *offset, ioflags);
                ret = generic_file_direct_write(iocb, iovp,
                                &segs, pos, offset, count, ocount);
@@ -779,7 +768,7 @@ retry:
                        goto relock;
                }
        } else {
-               xfs_rw_enter_trace(XFS_WRITE_ENTER, io, (void *)iovp, segs,
+               xfs_rw_enter_trace(XFS_WRITE_ENTER, xip, (void *)iovp, segs,
                                *offset, ioflags);
                ret = generic_file_buffered_write(iocb, iovp, segs,
                                pos, offset, count, ret);
@@ -843,9 +832,9 @@ retry:
        }
 
  out_unlock_internal:
-       if (io->io_new_size) {
+       if (xip->i_new_size) {
                xfs_ilock(xip, XFS_ILOCK_EXCL);
-               io->io_new_size = 0;
+               xip->i_new_size = 0;
                /*
                 * If this was a direct or synchronous I/O that failed (such
                 * as ENOSPC) then part of the I/O may have been written to
@@ -894,25 +883,6 @@ xfs_bdstrat_cb(struct xfs_buf *bp)
        }
 }
 
-
-int
-xfs_bmap(
-       xfs_inode_t     *ip,
-       xfs_off_t       offset,
-       ssize_t         count,
-       int             flags,
-       xfs_iomap_t     *iomapp,
-       int             *niomaps)
-{
-       xfs_iocore_t    *io = &ip->i_iocore;
-
-       ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFREG);
-       ASSERT(((ip->i_d.di_flags & XFS_DIFLAG_REALTIME) != 0) ==
-              ((ip->i_iocore.io_flags & XFS_IOCORE_RT) != 0));
-
-       return xfs_iomap(io, offset, count, flags, iomapp, niomaps);
-}
-
 /*
  * Wrapper around bdstrat so that we can stop data
  * from going to disk in case we are shutting down the filesystem.
index 4b7747a828d9a090a764097ff6accb4800cb1f53..e200253139cfd1be0840bd6360fff47083fd3483 100644 (file)
@@ -19,7 +19,6 @@
 #define __XFS_LRW_H__
 
 struct xfs_mount;
-struct xfs_iocore;
 struct xfs_inode;
 struct xfs_bmbt_irec;
 struct xfs_buf;
@@ -60,20 +59,19 @@ struct xfs_iomap;
 #define        XFS_IOMAP_UNWRITTEN     27
 #define XFS_SPLICE_READ_ENTER  28
 #define XFS_SPLICE_WRITE_ENTER 29
-extern void xfs_rw_enter_trace(int, struct xfs_iocore *,
-                               void *, size_t, loff_t, int);
-extern void xfs_inval_cached_trace(struct xfs_iocore *,
-                               xfs_off_t, xfs_off_t, xfs_off_t, xfs_off_t);
+extern void xfs_rw_enter_trace(int, struct xfs_inode *,
+               void *, size_t, loff_t, int);
+extern void xfs_inval_cached_trace(struct xfs_inode *,
+               xfs_off_t, xfs_off_t, xfs_off_t, xfs_off_t);
 #else
-#define xfs_rw_enter_trace(tag, io, data, size, offset, ioflags)
-#define xfs_inval_cached_trace(io, offset, len, first, last)
+#define xfs_rw_enter_trace(tag, ip, data, size, offset, ioflags)
+#define xfs_inval_cached_trace(ip, offset, len, first, last)
 #endif
 
 extern int xfsbdstrat(struct xfs_mount *, struct xfs_buf *);
 extern int xfs_bdstrat_cb(struct xfs_buf *);
 extern int xfs_dev_is_read_only(struct xfs_mount *, char *);
 
-extern int xfs_zero_eof(struct inode *, struct xfs_iocore *, xfs_off_t,
-                               xfs_fsize_t);
+extern int xfs_zero_eof(struct xfs_inode *, xfs_off_t, xfs_fsize_t);
 
 #endif /* __XFS_LRW_H__ */
index 8cb63c60c04880e4395c3eace8c033de19d32038..21dfc9da235e623ef77a330076edb6269f375f48 100644 (file)
@@ -41,6 +41,7 @@
 #include "xfs_rtalloc.h"
 #include "xfs_error.h"
 #include "xfs_itable.h"
+#include "xfs_fsops.h"
 #include "xfs_rw.h"
 #include "xfs_acl.h"
 #include "xfs_attr.h"
@@ -49,6 +50,8 @@
 #include "xfs_vnodeops.h"
 #include "xfs_vfsops.h"
 #include "xfs_version.h"
+#include "xfs_log_priv.h"
+#include "xfs_trans_priv.h"
 
 #include <linux/namei.h>
 #include <linux/init.h>
@@ -87,6 +90,435 @@ xfs_args_allocate(
        return args;
 }
 
+#define MNTOPT_LOGBUFS "logbufs"       /* number of XFS log buffers */
+#define MNTOPT_LOGBSIZE        "logbsize"      /* size of XFS log buffers */
+#define MNTOPT_LOGDEV  "logdev"        /* log device */
+#define MNTOPT_RTDEV   "rtdev"         /* realtime I/O device */
+#define MNTOPT_BIOSIZE "biosize"       /* log2 of preferred buffered io size */
+#define MNTOPT_WSYNC   "wsync"         /* safe-mode nfs compatible mount */
+#define MNTOPT_INO64   "ino64"         /* force inodes into 64-bit range */
+#define MNTOPT_NOALIGN "noalign"       /* turn off stripe alignment */
+#define MNTOPT_SWALLOC "swalloc"       /* turn on stripe width allocation */
+#define MNTOPT_SUNIT   "sunit"         /* data volume stripe unit */
+#define MNTOPT_SWIDTH  "swidth"        /* data volume stripe width */
+#define MNTOPT_NOUUID  "nouuid"        /* ignore filesystem UUID */
+#define MNTOPT_MTPT    "mtpt"          /* filesystem mount point */
+#define MNTOPT_GRPID   "grpid"         /* group-ID from parent directory */
+#define MNTOPT_NOGRPID "nogrpid"       /* group-ID from current process */
+#define MNTOPT_BSDGROUPS    "bsdgroups"    /* group-ID from parent directory */
+#define MNTOPT_SYSVGROUPS   "sysvgroups"   /* group-ID from current process */
+#define MNTOPT_ALLOCSIZE    "allocsize"    /* preferred allocation size */
+#define MNTOPT_NORECOVERY   "norecovery"   /* don't run XFS recovery */
+#define MNTOPT_BARRIER "barrier"       /* use writer barriers for log write and
+                                        * unwritten extent conversion */
+#define MNTOPT_NOBARRIER "nobarrier"   /* .. disable */
+#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
+#define MNTOPT_64BITINODE   "inode64"  /* inodes can be allocated anywhere */
+#define MNTOPT_IKEEP   "ikeep"         /* do not free empty inode clusters */
+#define MNTOPT_NOIKEEP "noikeep"       /* free empty inode clusters */
+#define MNTOPT_LARGEIO    "largeio"    /* report large I/O sizes in stat() */
+#define MNTOPT_NOLARGEIO   "nolargeio" /* do not report large I/O sizes
+                                        * in stat(). */
+#define MNTOPT_ATTR2   "attr2"         /* do use attr2 attribute format */
+#define MNTOPT_NOATTR2 "noattr2"       /* do not use attr2 attribute format */
+#define MNTOPT_FILESTREAM  "filestreams" /* use filestreams allocator */
+#define MNTOPT_QUOTA   "quota"         /* disk quotas (user) */
+#define MNTOPT_NOQUOTA "noquota"       /* no quotas */
+#define MNTOPT_USRQUOTA        "usrquota"      /* user quota enabled */
+#define MNTOPT_GRPQUOTA        "grpquota"      /* group quota enabled */
+#define MNTOPT_PRJQUOTA        "prjquota"      /* project quota enabled */
+#define MNTOPT_UQUOTA  "uquota"        /* user quota (IRIX variant) */
+#define MNTOPT_GQUOTA  "gquota"        /* group quota (IRIX variant) */
+#define MNTOPT_PQUOTA  "pquota"        /* project quota (IRIX variant) */
+#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
+#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
+#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
+#define MNTOPT_QUOTANOENF  "qnoenforce"        /* same as uqnoenforce */
+#define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
+#define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
+#define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
+
+STATIC unsigned long
+suffix_strtoul(char *s, char **endp, unsigned int base)
+{
+       int     last, shift_left_factor = 0;
+       char    *value = s;
+
+       last = strlen(value) - 1;
+       if (value[last] == 'K' || value[last] == 'k') {
+               shift_left_factor = 10;
+               value[last] = '\0';
+       }
+       if (value[last] == 'M' || value[last] == 'm') {
+               shift_left_factor = 20;
+               value[last] = '\0';
+       }
+       if (value[last] == 'G' || value[last] == 'g') {
+               shift_left_factor = 30;
+               value[last] = '\0';
+       }
+
+       return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
+}
+
+STATIC int
+xfs_parseargs(
+       struct xfs_mount        *mp,
+       char                    *options,
+       struct xfs_mount_args   *args,
+       int                     update)
+{
+       char                    *this_char, *value, *eov;
+       int                     dsunit, dswidth, vol_dsunit, vol_dswidth;
+       int                     iosize;
+       int                     ikeep = 0;
+
+       args->flags |= XFSMNT_BARRIER;
+       args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
+
+       if (!options)
+               goto done;
+
+       iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
+
+       while ((this_char = strsep(&options, ",")) != NULL) {
+               if (!*this_char)
+                       continue;
+               if ((value = strchr(this_char, '=')) != NULL)
+                       *value++ = 0;
+
+               if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
+                       if (!value || !*value) {
+                               cmn_err(CE_WARN,
+                                       "XFS: %s option requires an argument",
+                                       this_char);
+                               return EINVAL;
+                       }
+                       args->logbufs = simple_strtoul(value, &eov, 10);
+               } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
+                       if (!value || !*value) {
+                               cmn_err(CE_WARN,
+                                       "XFS: %s option requires an argument",
+                                       this_char);
+                               return EINVAL;
+                       }
+                       args->logbufsize = suffix_strtoul(value, &eov, 10);
+               } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
+                       if (!value || !*value) {
+                               cmn_err(CE_WARN,
+                                       "XFS: %s option requires an argument",
+                                       this_char);
+                               return EINVAL;
+                       }
+                       strncpy(args->logname, value, MAXNAMELEN);
+               } else if (!strcmp(this_char, MNTOPT_MTPT)) {
+                       if (!value || !*value) {
+                               cmn_err(CE_WARN,
+                                       "XFS: %s option requires an argument",
+                                       this_char);
+                               return EINVAL;
+                       }
+                       strncpy(args->mtpt, value, MAXNAMELEN);
+               } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
+                       if (!value || !*value) {
+                               cmn_err(CE_WARN,
+                                       "XFS: %s option requires an argument",
+                                       this_char);
+                               return EINVAL;
+                       }
+                       strncpy(args->rtname, value, MAXNAMELEN);
+               } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
+                       if (!value || !*value) {
+                               cmn_err(CE_WARN,
+                                       "XFS: %s option requires an argument",
+                                       this_char);
+                               return EINVAL;
+                       }
+                       iosize = simple_strtoul(value, &eov, 10);
+                       args->flags |= XFSMNT_IOSIZE;
+                       args->iosizelog = (uint8_t) iosize;
+               } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
+                       if (!value || !*value) {
+                               cmn_err(CE_WARN,
+                                       "XFS: %s option requires an argument",
+                                       this_char);
+                               return EINVAL;
+                       }
+                       iosize = suffix_strtoul(value, &eov, 10);
+                       args->flags |= XFSMNT_IOSIZE;
+                       args->iosizelog = ffs(iosize) - 1;
+               } else if (!strcmp(this_char, MNTOPT_GRPID) ||
+                          !strcmp(this_char, MNTOPT_BSDGROUPS)) {
+                       mp->m_flags |= XFS_MOUNT_GRPID;
+               } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
+                          !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
+                       mp->m_flags &= ~XFS_MOUNT_GRPID;
+               } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
+                       args->flags |= XFSMNT_WSYNC;
+               } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
+                       args->flags |= XFSMNT_OSYNCISOSYNC;
+               } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
+                       args->flags |= XFSMNT_NORECOVERY;
+               } else if (!strcmp(this_char, MNTOPT_INO64)) {
+                       args->flags |= XFSMNT_INO64;
+#if !XFS_BIG_INUMS
+                       cmn_err(CE_WARN,
+                               "XFS: %s option not allowed on this system",
+                               this_char);
+                       return EINVAL;
+#endif
+               } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
+                       args->flags |= XFSMNT_NOALIGN;
+               } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
+                       args->flags |= XFSMNT_SWALLOC;
+               } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
+                       if (!value || !*value) {
+                               cmn_err(CE_WARN,
+                                       "XFS: %s option requires an argument",
+                                       this_char);
+                               return EINVAL;
+                       }
+                       dsunit = simple_strtoul(value, &eov, 10);
+               } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
+                       if (!value || !*value) {
+                               cmn_err(CE_WARN,
+                                       "XFS: %s option requires an argument",
+                                       this_char);
+                               return EINVAL;
+                       }
+                       dswidth = simple_strtoul(value, &eov, 10);
+               } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
+                       args->flags &= ~XFSMNT_32BITINODES;
+#if !XFS_BIG_INUMS
+                       cmn_err(CE_WARN,
+                               "XFS: %s option not allowed on this system",
+                               this_char);
+                       return EINVAL;
+#endif
+               } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
+                       args->flags |= XFSMNT_NOUUID;
+               } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
+                       args->flags |= XFSMNT_BARRIER;
+               } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
+                       args->flags &= ~XFSMNT_BARRIER;
+               } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
+                       ikeep = 1;
+                       args->flags &= ~XFSMNT_IDELETE;
+               } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
+                       args->flags |= XFSMNT_IDELETE;
+               } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
+                       args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
+               } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
+                       args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
+               } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
+                       args->flags |= XFSMNT_ATTR2;
+               } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
+                       args->flags &= ~XFSMNT_ATTR2;
+               } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
+                       args->flags2 |= XFSMNT2_FILESTREAMS;
+               } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
+                       args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
+                       args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
+               } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
+                          !strcmp(this_char, MNTOPT_UQUOTA) ||
+                          !strcmp(this_char, MNTOPT_USRQUOTA)) {
+                       args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
+               } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
+                          !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
+                       args->flags |= XFSMNT_UQUOTA;
+                       args->flags &= ~XFSMNT_UQUOTAENF;
+               } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
+                          !strcmp(this_char, MNTOPT_PRJQUOTA)) {
+                       args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
+               } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
+                       args->flags |= XFSMNT_PQUOTA;
+                       args->flags &= ~XFSMNT_PQUOTAENF;
+               } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
+                          !strcmp(this_char, MNTOPT_GRPQUOTA)) {
+                       args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
+               } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
+                       args->flags |= XFSMNT_GQUOTA;
+                       args->flags &= ~XFSMNT_GQUOTAENF;
+               } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
+                       args->flags |= XFSMNT_DMAPI;
+               } else if (!strcmp(this_char, MNTOPT_XDSM)) {
+                       args->flags |= XFSMNT_DMAPI;
+               } else if (!strcmp(this_char, MNTOPT_DMI)) {
+                       args->flags |= XFSMNT_DMAPI;
+               } else if (!strcmp(this_char, "ihashsize")) {
+                       cmn_err(CE_WARN,
+       "XFS: ihashsize no longer used, option is deprecated.");
+               } else if (!strcmp(this_char, "osyncisdsync")) {
+                       /* no-op, this is now the default */
+                       cmn_err(CE_WARN,
+       "XFS: osyncisdsync is now the default, option is deprecated.");
+               } else if (!strcmp(this_char, "irixsgid")) {
+                       cmn_err(CE_WARN,
+       "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
+               } else {
+                       cmn_err(CE_WARN,
+                               "XFS: unknown mount option [%s].", this_char);
+                       return EINVAL;
+               }
+       }
+
+       if (args->flags & XFSMNT_NORECOVERY) {
+               if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
+                       cmn_err(CE_WARN,
+                               "XFS: no-recovery mounts must be read-only.");
+                       return EINVAL;
+               }
+       }
+
+       if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
+               cmn_err(CE_WARN,
+       "XFS: sunit and swidth options incompatible with the noalign option");
+               return EINVAL;
+       }
+
+       if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
+               cmn_err(CE_WARN,
+                       "XFS: cannot mount with both project and group quota");
+               return EINVAL;
+       }
+
+       if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
+               printk("XFS: %s option needs the mount point option as well\n",
+                       MNTOPT_DMAPI);
+               return EINVAL;
+       }
+
+       if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
+               cmn_err(CE_WARN,
+                       "XFS: sunit and swidth must be specified together");
+               return EINVAL;
+       }
+
+       if (dsunit && (dswidth % dsunit != 0)) {
+               cmn_err(CE_WARN,
+       "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
+                       dswidth, dsunit);
+               return EINVAL;
+       }
+
+       /*
+        * Applications using DMI filesystems often expect the
+        * inode generation number to be monotonically increasing.
+        * If we delete inode chunks we break this assumption, so
+        * keep unused inode chunks on disk for DMI filesystems
+        * until we come up with a better solution.
+        * Note that if "ikeep" or "noikeep" mount options are
+        * supplied, then they are honored.
+        */
+       if (!(args->flags & XFSMNT_DMAPI) && !ikeep)
+               args->flags |= XFSMNT_IDELETE;
+
+       if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
+               if (dsunit) {
+                       args->sunit = dsunit;
+                       args->flags |= XFSMNT_RETERR;
+               } else {
+                       args->sunit = vol_dsunit;
+               }
+               dswidth ? (args->swidth = dswidth) :
+                         (args->swidth = vol_dswidth);
+       } else {
+               args->sunit = args->swidth = 0;
+       }
+
+done:
+       if (args->flags & XFSMNT_32BITINODES)
+               mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
+       if (args->flags2)
+               args->flags |= XFSMNT_FLAGS2;
+       return 0;
+}
+
+struct proc_xfs_info {
+       int     flag;
+       char    *str;
+};
+
+STATIC int
+xfs_showargs(
+       struct xfs_mount        *mp,
+       struct seq_file         *m)
+{
+       static struct proc_xfs_info xfs_info_set[] = {
+               /* the few simple ones we can get from the mount struct */
+               { XFS_MOUNT_WSYNC,              "," MNTOPT_WSYNC },
+               { XFS_MOUNT_INO64,              "," MNTOPT_INO64 },
+               { XFS_MOUNT_NOALIGN,            "," MNTOPT_NOALIGN },
+               { XFS_MOUNT_SWALLOC,            "," MNTOPT_SWALLOC },
+               { XFS_MOUNT_NOUUID,             "," MNTOPT_NOUUID },
+               { XFS_MOUNT_NORECOVERY,         "," MNTOPT_NORECOVERY },
+               { XFS_MOUNT_OSYNCISOSYNC,       "," MNTOPT_OSYNCISOSYNC },
+               { XFS_MOUNT_ATTR2,              "," MNTOPT_ATTR2 },
+               { XFS_MOUNT_FILESTREAMS,        "," MNTOPT_FILESTREAM },
+               { XFS_MOUNT_DMAPI,              "," MNTOPT_DMAPI },
+               { XFS_MOUNT_GRPID,              "," MNTOPT_GRPID },
+               { 0, NULL }
+       };
+       static struct proc_xfs_info xfs_info_unset[] = {
+               /* the few simple ones we can get from the mount struct */
+               { XFS_MOUNT_IDELETE,            "," MNTOPT_IKEEP },
+               { XFS_MOUNT_COMPAT_IOSIZE,      "," MNTOPT_LARGEIO },
+               { XFS_MOUNT_BARRIER,            "," MNTOPT_NOBARRIER },
+               { XFS_MOUNT_SMALL_INUMS,        "," MNTOPT_64BITINODE },
+               { 0, NULL }
+       };
+       struct proc_xfs_info    *xfs_infop;
+
+       for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
+               if (mp->m_flags & xfs_infop->flag)
+                       seq_puts(m, xfs_infop->str);
+       }
+       for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
+               if (!(mp->m_flags & xfs_infop->flag))
+                       seq_puts(m, xfs_infop->str);
+       }
+
+       if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
+               seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
+                               (int)(1 << mp->m_writeio_log) >> 10);
+
+       if (mp->m_logbufs > 0)
+               seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
+       if (mp->m_logbsize > 0)
+               seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
+
+       if (mp->m_logname)
+               seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
+       if (mp->m_rtname)
+               seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
+
+       if (mp->m_dalign > 0)
+               seq_printf(m, "," MNTOPT_SUNIT "=%d",
+                               (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
+       if (mp->m_swidth > 0)
+               seq_printf(m, "," MNTOPT_SWIDTH "=%d",
+                               (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
+
+       if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
+               seq_puts(m, "," MNTOPT_USRQUOTA);
+       else if (mp->m_qflags & XFS_UQUOTA_ACCT)
+               seq_puts(m, "," MNTOPT_UQUOTANOENF);
+
+       if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
+               seq_puts(m, "," MNTOPT_PRJQUOTA);
+       else if (mp->m_qflags & XFS_PQUOTA_ACCT)
+               seq_puts(m, "," MNTOPT_PQUOTANOENF);
+
+       if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
+               seq_puts(m, "," MNTOPT_GRPQUOTA);
+       else if (mp->m_qflags & XFS_GQUOTA_ACCT)
+               seq_puts(m, "," MNTOPT_GQUOTANOENF);
+
+       if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
+               seq_puts(m, "," MNTOPT_NOQUOTA);
+
+       return 0;
+}
 __uint64_t
 xfs_max_file_offset(
        unsigned int            blockshift)
@@ -137,7 +569,7 @@ xfs_set_inodeops(
                break;
        case S_IFLNK:
                inode->i_op = &xfs_symlink_inode_operations;
-               if (inode->i_blocks)
+               if (!(XFS_I(inode)->i_df.if_flags & XFS_IFINLINE))
                        inode->i_mapping->a_ops = &xfs_address_space_operations;
                break;
        default:
@@ -174,8 +606,6 @@ xfs_revalidate_inode(
 
        inode->i_generation = ip->i_d.di_gen;
        i_size_write(inode, ip->i_d.di_size);
-       inode->i_blocks =
-               XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
        inode->i_atime.tv_sec   = ip->i_d.di_atime.t_sec;
        inode->i_atime.tv_nsec  = ip->i_d.di_atime.t_nsec;
        inode->i_mtime.tv_sec   = ip->i_d.di_mtime.t_sec;
@@ -334,6 +764,64 @@ xfs_blkdev_issue_flush(
        blkdev_issue_flush(buftarg->bt_bdev, NULL);
 }
 
+/*
+ * XFS AIL push thread support
+ */
+void
+xfsaild_wakeup(
+       xfs_mount_t             *mp,
+       xfs_lsn_t               threshold_lsn)
+{
+       mp->m_ail.xa_target = threshold_lsn;
+       wake_up_process(mp->m_ail.xa_task);
+}
+
+int
+xfsaild(
+       void    *data)
+{
+       xfs_mount_t     *mp = (xfs_mount_t *)data;
+       xfs_lsn_t       last_pushed_lsn = 0;
+       long            tout = 0;
+
+       while (!kthread_should_stop()) {
+               if (tout)
+                       schedule_timeout_interruptible(msecs_to_jiffies(tout));
+               tout = 1000;
+
+               /* swsusp */
+               try_to_freeze();
+
+               ASSERT(mp->m_log);
+               if (XFS_FORCED_SHUTDOWN(mp))
+                       continue;
+
+               tout = xfsaild_push(mp, &last_pushed_lsn);
+       }
+
+       return 0;
+}      /* xfsaild */
+
+int
+xfsaild_start(
+       xfs_mount_t     *mp)
+{
+       mp->m_ail.xa_target = 0;
+       mp->m_ail.xa_task = kthread_run(xfsaild, mp, "xfsaild");
+       if (IS_ERR(mp->m_ail.xa_task))
+               return -PTR_ERR(mp->m_ail.xa_task);
+       return 0;
+}
+
+void
+xfsaild_stop(
+       xfs_mount_t     *mp)
+{
+       kthread_stop(mp->m_ail.xa_task);
+}
+
+
+
 STATIC struct inode *
 xfs_fs_alloc_inode(
        struct super_block      *sb)
@@ -361,7 +849,7 @@ xfs_fs_inode_init_once(
        inode_init_once(vn_to_inode((bhv_vnode_t *)vnode));
 }
 
-STATIC int
+STATIC int __init
 xfs_init_zones(void)
 {
        xfs_vnode_zone = kmem_zone_init_flags(sizeof(bhv_vnode_t), "xfs_vnode",
@@ -410,8 +898,7 @@ xfs_fs_write_inode(
 {
        int                     error = 0, flags = FLUSH_INODE;
 
-       vn_trace_entry(XFS_I(inode), __FUNCTION__,
-                       (inst_t *)__return_address);
+       xfs_itrace_entry(XFS_I(inode));
        if (sync) {
                filemap_fdatawait(inode->i_mapping);
                flags |= FLUSH_SYNC;
@@ -438,8 +925,7 @@ xfs_fs_clear_inode(
         * find an inode with di_mode == 0 but without IGET_CREATE set.
         */
        if (ip) {
-               vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
-
+               xfs_itrace_entry(ip);
                XFS_STATS_INC(vn_rele);
                XFS_STATS_INC(vn_remove);
                XFS_STATS_INC(vn_reclaim);
@@ -683,8 +1169,44 @@ xfs_fs_statfs(
        struct dentry           *dentry,
        struct kstatfs          *statp)
 {
-       return -xfs_statvfs(XFS_M(dentry->d_sb), statp,
-                               vn_from_inode(dentry->d_inode));
+       struct xfs_mount        *mp = XFS_M(dentry->d_sb);
+       xfs_sb_t                *sbp = &mp->m_sb;
+       __uint64_t              fakeinos, id;
+       xfs_extlen_t            lsize;
+
+       statp->f_type = XFS_SB_MAGIC;
+       statp->f_namelen = MAXNAMELEN - 1;
+
+       id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
+       statp->f_fsid.val[0] = (u32)id;
+       statp->f_fsid.val[1] = (u32)(id >> 32);
+
+       xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
+
+       spin_lock(&mp->m_sb_lock);
+       statp->f_bsize = sbp->sb_blocksize;
+       lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
+       statp->f_blocks = sbp->sb_dblocks - lsize;
+       statp->f_bfree = statp->f_bavail =
+                               sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
+       fakeinos = statp->f_bfree << sbp->sb_inopblog;
+#if XFS_BIG_INUMS
+       fakeinos += mp->m_inoadd;
+#endif
+       statp->f_files =
+           MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
+       if (mp->m_maxicount)
+#if XFS_BIG_INUMS
+               if (!mp->m_inoadd)
+#endif
+                       statp->f_files = min_t(typeof(statp->f_files),
+                                               statp->f_files,
+                                               mp->m_maxicount);
+       statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
+       spin_unlock(&mp->m_sb_lock);
+
+       XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
+       return 0;
 }
 
 STATIC int
@@ -704,11 +1226,19 @@ xfs_fs_remount(
        return -error;
 }
 
+/*
+ * Second stage of a freeze. The data is already frozen so we only
+ * need to take care of themetadata. Once that's done write a dummy
+ * record to dirty the log in case of a crash while frozen.
+ */
 STATIC void
 xfs_fs_lockfs(
        struct super_block      *sb)
 {
-       xfs_freeze(XFS_M(sb));
+       struct xfs_mount        *mp = XFS_M(sb);
+
+       xfs_attr_quiesce(mp);
+       xfs_fs_log_dummy(mp);
 }
 
 STATIC int
@@ -779,7 +1309,6 @@ xfs_fs_fill_super(
        struct inode            *rootvp;
        struct xfs_mount        *mp = NULL;
        struct xfs_mount_args   *args = xfs_args_allocate(sb, silent);
-       struct kstatfs          statvfs;
        int                     error;
 
        mp = xfs_mount_init();
@@ -807,21 +1336,19 @@ xfs_fs_fill_super(
        if (error)
                goto fail_vfsop;
 
-       error = xfs_statvfs(mp, &statvfs, NULL);
-       if (error)
-               goto fail_unmount;
-
        sb->s_dirt = 1;
-       sb->s_magic = statvfs.f_type;
-       sb->s_blocksize = statvfs.f_bsize;
-       sb->s_blocksize_bits = ffs(statvfs.f_bsize) - 1;
+       sb->s_magic = XFS_SB_MAGIC;
+       sb->s_blocksize = mp->m_sb.sb_blocksize;
+       sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
        sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
        sb->s_time_gran = 1;
        set_posix_acl_flag(sb);
 
-       error = xfs_root(mp, &rootvp);
-       if (error)
+       rootvp = igrab(mp->m_rootip->i_vnode);
+       if (!rootvp) {
+               error = ENOENT;
                goto fail_unmount;
+       }
 
        sb->s_root = d_alloc_root(vn_to_inode(rootvp));
        if (!sb->s_root) {
@@ -841,8 +1368,7 @@ xfs_fs_fill_super(
                goto fail_vnrele;
        }
 
-       vn_trace_exit(XFS_I(sb->s_root->d_inode), __FUNCTION__,
-                       (inst_t *)__return_address);
+       xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
 
        kmem_free(args, sizeof(*args));
        return 0;
index 814169fd7e1e2088fbc956cada3f432ed3da31bb..bc7afe00733801c869840881051f966ea9b553bf 100644 (file)
@@ -40,7 +40,7 @@
 #define vptosync(v)             (&vsync[((unsigned long)v) % NVSYNC])
 static wait_queue_head_t vsync[NVSYNC];
 
-void
+void __init
 vn_init(void)
 {
        int i;
@@ -82,84 +82,55 @@ vn_ioerror(
                xfs_do_force_shutdown(ip->i_mount, SHUTDOWN_DEVICE_REQ, f, l);
 }
 
-bhv_vnode_t *
-vn_initialize(
-       struct inode    *inode)
-{
-       bhv_vnode_t     *vp = vn_from_inode(inode);
-
-       XFS_STATS_INC(vn_active);
-       XFS_STATS_INC(vn_alloc);
-
-       ASSERT(VN_CACHED(vp) == 0);
-
-       return vp;
-}
-
 /*
- * Revalidate the Linux inode from the vattr.
+ * Revalidate the Linux inode from the XFS inode.
  * Note: i_size _not_ updated; we must hold the inode
  * semaphore when doing that - callers responsibility.
  */
-void
-vn_revalidate_core(
-       bhv_vnode_t     *vp,
-       bhv_vattr_t     *vap)
+int
+vn_revalidate(
+       bhv_vnode_t             *vp)
 {
-       struct inode    *inode = vn_to_inode(vp);
-
-       inode->i_mode       = vap->va_mode;
-       inode->i_nlink      = vap->va_nlink;
-       inode->i_uid        = vap->va_uid;
-       inode->i_gid        = vap->va_gid;
-       inode->i_blocks     = vap->va_nblocks;
-       inode->i_mtime      = vap->va_mtime;
-       inode->i_ctime      = vap->va_ctime;
-       if (vap->va_xflags & XFS_XFLAG_IMMUTABLE)
+       struct inode            *inode = vn_to_inode(vp);
+       struct xfs_inode        *ip = XFS_I(inode);
+       struct xfs_mount        *mp = ip->i_mount;
+       unsigned long           xflags;
+
+       xfs_itrace_entry(ip);
+
+       if (XFS_FORCED_SHUTDOWN(mp))
+               return -EIO;
+
+       xfs_ilock(ip, XFS_ILOCK_SHARED);
+       inode->i_mode       = ip->i_d.di_mode;
+       inode->i_uid        = ip->i_d.di_uid;
+       inode->i_gid        = ip->i_d.di_gid;
+       inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
+       inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
+       inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
+       inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
+
+       xflags = xfs_ip2xflags(ip);
+       if (xflags & XFS_XFLAG_IMMUTABLE)
                inode->i_flags |= S_IMMUTABLE;
        else
                inode->i_flags &= ~S_IMMUTABLE;
-       if (vap->va_xflags & XFS_XFLAG_APPEND)
+       if (xflags & XFS_XFLAG_APPEND)
                inode->i_flags |= S_APPEND;
        else
                inode->i_flags &= ~S_APPEND;
-       if (vap->va_xflags & XFS_XFLAG_SYNC)
+       if (xflags & XFS_XFLAG_SYNC)
                inode->i_flags |= S_SYNC;
        else
                inode->i_flags &= ~S_SYNC;
-       if (vap->va_xflags & XFS_XFLAG_NOATIME)
+       if (xflags & XFS_XFLAG_NOATIME)
                inode->i_flags |= S_NOATIME;
        else
                inode->i_flags &= ~S_NOATIME;
-}
-
-/*
- * Revalidate the Linux inode from the vnode.
- */
-int
-__vn_revalidate(
-       bhv_vnode_t     *vp,
-       bhv_vattr_t     *vattr)
-{
-       int             error;
-
-       vn_trace_entry(xfs_vtoi(vp), __FUNCTION__, (inst_t *)__return_address);
-       vattr->va_mask = XFS_AT_STAT | XFS_AT_XFLAGS;
-       error = xfs_getattr(xfs_vtoi(vp), vattr, 0);
-       if (likely(!error)) {
-               vn_revalidate_core(vp, vattr);
-               xfs_iflags_clear(xfs_vtoi(vp), XFS_IMODIFIED);
-       }
-       return -error;
-}
-
-int
-vn_revalidate(
-       bhv_vnode_t     *vp)
-{
-       bhv_vattr_t     vattr;
+       xfs_iunlock(ip, XFS_ILOCK_SHARED);
 
-       return __vn_revalidate(vp, &vattr);
+       xfs_iflags_clear(ip, XFS_IMODIFIED);
+       return 0;
 }
 
 /*
@@ -179,7 +150,7 @@ vn_hold(
        return vp;
 }
 
-#ifdef XFS_VNODE_TRACE
+#ifdef XFS_INODE_TRACE
 
 /*
  * Reference count of Linux inode if present, -1 if the xfs_inode
@@ -211,32 +182,32 @@ static inline int xfs_icount(struct xfs_inode *ip)
  * Vnode tracing code.
  */
 void
-vn_trace_entry(xfs_inode_t *ip, const char *func, inst_t *ra)
+_xfs_itrace_entry(xfs_inode_t *ip, const char *func, inst_t *ra)
 {
-       KTRACE_ENTER(ip, VNODE_KTRACE_ENTRY, func, 0, ra);
+       KTRACE_ENTER(ip, INODE_KTRACE_ENTRY, func, 0, ra);
 }
 
 void
-vn_trace_exit(xfs_inode_t *ip, const char *func, inst_t *ra)
+_xfs_itrace_exit(xfs_inode_t *ip, const char *func, inst_t *ra)
 {
-       KTRACE_ENTER(ip, VNODE_KTRACE_EXIT, func, 0, ra);
+       KTRACE_ENTER(ip, INODE_KTRACE_EXIT, func, 0, ra);
 }
 
 void
-vn_trace_hold(xfs_inode_t *ip, char *file, int line, inst_t *ra)
+xfs_itrace_hold(xfs_inode_t *ip, char *file, int line, inst_t *ra)
 {
-       KTRACE_ENTER(ip, VNODE_KTRACE_HOLD, file, line, ra);
+       KTRACE_ENTER(ip, INODE_KTRACE_HOLD, file, line, ra);
 }
 
 void
-vn_trace_ref(xfs_inode_t *ip, char *file, int line, inst_t *ra)
+_xfs_itrace_ref(xfs_inode_t *ip, char *file, int line, inst_t *ra)
 {
-       KTRACE_ENTER(ip, VNODE_KTRACE_REF, file, line, ra);
+       KTRACE_ENTER(ip, INODE_KTRACE_REF, file, line, ra);
 }
 
 void
-vn_trace_rele(xfs_inode_t *ip, char *file, int line, inst_t *ra)
+xfs_itrace_rele(xfs_inode_t *ip, char *file, int line, inst_t *ra)
 {
-       KTRACE_ENTER(ip, VNODE_KTRACE_RELE, file, line, ra);
+       KTRACE_ENTER(ip, INODE_KTRACE_RELE, file, line, ra);
 }
-#endif /* XFS_VNODE_TRACE */
+#endif /* XFS_INODE_TRACE */
index 55fb469485892d8d667dd866d46f5a61d875add0..b5ea418693b1b4f1d76ef2b2dd8e6bf149733150 100644 (file)
@@ -187,10 +187,7 @@ typedef struct bhv_vattr {
        (VN_ISREG(vp) && ((mode) & (VSGID|(VEXEC>>3))) == VSGID)
 
 extern void    vn_init(void);
-extern bhv_vnode_t     *vn_initialize(struct inode *);
 extern int     vn_revalidate(bhv_vnode_t *);
-extern int     __vn_revalidate(bhv_vnode_t *, bhv_vattr_t *);
-extern void    vn_revalidate_core(bhv_vnode_t *, bhv_vattr_t *);
 
 /*
  * Yeah, these don't take vnode anymore at all, all this should be
@@ -210,12 +207,12 @@ static inline int vn_count(bhv_vnode_t *vp)
  */
 extern bhv_vnode_t     *vn_hold(bhv_vnode_t *);
 
-#if defined(XFS_VNODE_TRACE)
+#if defined(XFS_INODE_TRACE)
 #define VN_HOLD(vp)            \
        ((void)vn_hold(vp),     \
-         vn_trace_hold(xfs_vtoi(vp), __FILE__, __LINE__, (inst_t *)__return_address))
+         xfs_itrace_hold(xfs_vtoi(vp), __FILE__, __LINE__, (inst_t *)__return_address))
 #define VN_RELE(vp)            \
-         (vn_trace_rele(xfs_vtoi(vp), __FILE__, __LINE__, (inst_t *)__return_address), \
+         (xfs_itrace_rele(xfs_vtoi(vp), __FILE__, __LINE__, (inst_t *)__return_address), \
           iput(vn_to_inode(vp)))
 #else
 #define VN_HOLD(vp)            ((void)vn_hold(vp))
@@ -238,11 +235,6 @@ static inline bhv_vnode_t *vn_grab(bhv_vnode_t *vp)
 /*
  * Dealing with bad inodes
  */
-static inline void vn_mark_bad(bhv_vnode_t *vp)
-{
-       make_bad_inode(vn_to_inode(vp));
-}
-
 static inline int VN_BAD(bhv_vnode_t *vp)
 {
        return is_bad_inode(vn_to_inode(vp));
@@ -296,26 +288,36 @@ static inline void vn_atime_to_time_t(bhv_vnode_t *vp, time_t *tt)
 /*
  * Tracking vnode activity.
  */
-#if defined(XFS_VNODE_TRACE)
-
-#define        VNODE_TRACE_SIZE        16              /* number of trace entries */
-#define        VNODE_KTRACE_ENTRY      1
-#define        VNODE_KTRACE_EXIT       2
-#define        VNODE_KTRACE_HOLD       3
-#define        VNODE_KTRACE_REF        4
-#define        VNODE_KTRACE_RELE       5
-
-extern void vn_trace_entry(struct xfs_inode *, const char *, inst_t *);
-extern void vn_trace_exit(struct xfs_inode *, const char *, inst_t *);
-extern void vn_trace_hold(struct xfs_inode *, char *, int, inst_t *);
-extern void vn_trace_ref(struct xfs_inode *, char *, int, inst_t *);
-extern void vn_trace_rele(struct xfs_inode *, char *, int, inst_t *);
+#if defined(XFS_INODE_TRACE)
+
+#define        INODE_TRACE_SIZE        16              /* number of trace entries */
+#define        INODE_KTRACE_ENTRY      1
+#define        INODE_KTRACE_EXIT       2
+#define        INODE_KTRACE_HOLD       3
+#define        INODE_KTRACE_REF        4
+#define        INODE_KTRACE_RELE       5
+
+extern void _xfs_itrace_entry(struct xfs_inode *, const char *, inst_t *);
+extern void _xfs_itrace_exit(struct xfs_inode *, const char *, inst_t *);
+extern void xfs_itrace_hold(struct xfs_inode *, char *, int, inst_t *);
+extern void _xfs_itrace_ref(struct xfs_inode *, char *, int, inst_t *);
+extern void xfs_itrace_rele(struct xfs_inode *, char *, int, inst_t *);
+#define xfs_itrace_entry(ip)   \
+       _xfs_itrace_entry(ip, __FUNCTION__, (inst_t *)__return_address)
+#define xfs_itrace_exit(ip)    \
+       _xfs_itrace_exit(ip, __FUNCTION__, (inst_t *)__return_address)
+#define xfs_itrace_exit_tag(ip, tag)   \
+       _xfs_itrace_exit(ip, tag, (inst_t *)__return_address)
+#define xfs_itrace_ref(ip)     \
+       _xfs_itrace_ref(ip, __FILE__, __LINE__, (inst_t *)__return_address)
+
 #else
-#define        vn_trace_entry(a,b,c)
-#define        vn_trace_exit(a,b,c)
-#define        vn_trace_hold(a,b,c,d)
-#define        vn_trace_ref(a,b,c,d)
-#define        vn_trace_rele(a,b,c,d)
+#define        xfs_itrace_entry(a)
+#define        xfs_itrace_exit(a)
+#define        xfs_itrace_exit_tag(a, b)
+#define        xfs_itrace_hold(a, b, c, d)
+#define        xfs_itrace_ref(a)
+#define        xfs_itrace_rele(a, b, c, d)
 #endif
 
 #endif /* __XFS_VNODE_H__ */
index cfdd35ee9f7a1e192aa797abe8659c870e789967..665babcca6a6891724199df74ac09af68065503b 100644 (file)
@@ -1209,7 +1209,6 @@ xfs_qm_dqflush(
        xfs_buf_t               *bp;
        xfs_disk_dquot_t        *ddqp;
        int                     error;
-       SPLDECL(s);
 
        ASSERT(XFS_DQ_IS_LOCKED(dqp));
        ASSERT(XFS_DQ_IS_FLUSH_LOCKED(dqp));
@@ -1270,9 +1269,9 @@ xfs_qm_dqflush(
        mp = dqp->q_mount;
 
        /* lsn is 64 bits */
-       AIL_LOCK(mp, s);
+       spin_lock(&mp->m_ail_lock);
        dqp->q_logitem.qli_flush_lsn = dqp->q_logitem.qli_item.li_lsn;
-       AIL_UNLOCK(mp, s);
+       spin_unlock(&mp->m_ail_lock);
 
        /*
         * Attach an iodone routine so that we can remove this dquot from the
@@ -1318,7 +1317,6 @@ xfs_qm_dqflush_done(
        xfs_dq_logitem_t        *qip)
 {
        xfs_dquot_t             *dqp;
-       SPLDECL(s);
 
        dqp = qip->qli_dquot;
 
@@ -1333,15 +1331,15 @@ xfs_qm_dqflush_done(
        if ((qip->qli_item.li_flags & XFS_LI_IN_AIL) &&
            qip->qli_item.li_lsn == qip->qli_flush_lsn) {
 
-               AIL_LOCK(dqp->q_mount, s);
+               spin_lock(&dqp->q_mount->m_ail_lock);
                /*
                 * xfs_trans_delete_ail() drops the AIL lock.
                 */
                if (qip->qli_item.li_lsn == qip->qli_flush_lsn)
                        xfs_trans_delete_ail(dqp->q_mount,
-                                            (xfs_log_item_t*)qip, s);
+                                            (xfs_log_item_t*)qip);
                else
-                       AIL_UNLOCK(dqp->q_mount, s);
+                       spin_unlock(&dqp->q_mount->m_ail_lock);
        }
 
        /*
index 78d3ab95c5fda9224c9927e3cb6816aac907d7b8..5c371a92e3e24c010cbed274fb8b3f37169a466e 100644 (file)
@@ -123,11 +123,6 @@ XFS_DQ_IS_LOCKED(xfs_dquot_t *dqp)
                                   vsema(&((dqp)->q_flock)); \
                                   (dqp)->dq_flags &= ~(XFS_DQ_FLOCKED); }
 
-#define XFS_DQ_PINLOCK(dqp)       mutex_spinlock( \
-                                    &(XFS_DQ_TO_QINF(dqp)->qi_pinlock))
-#define XFS_DQ_PINUNLOCK(dqp, s)   mutex_spinunlock( \
-                                    &(XFS_DQ_TO_QINF(dqp)->qi_pinlock), s)
-
 #define XFS_DQ_IS_FLUSH_LOCKED(dqp) (issemalocked(&((dqp)->q_flock)))
 #define XFS_DQ_IS_ON_FREELIST(dqp)  ((dqp)->dq_flnext != (dqp))
 #define XFS_DQ_IS_DIRTY(dqp)   ((dqp)->dq_flags & XFS_DQ_DIRTY)
index ddb61fe22a5c7ed9914879bdad603d34390c0f64..1800e8d1f646f09448f8686267f5a1574645683d 100644 (file)
@@ -94,14 +94,13 @@ STATIC void
 xfs_qm_dquot_logitem_pin(
        xfs_dq_logitem_t *logitem)
 {
-       unsigned long   s;
        xfs_dquot_t *dqp;
 
        dqp = logitem->qli_dquot;
        ASSERT(XFS_DQ_IS_LOCKED(dqp));
-       s = XFS_DQ_PINLOCK(dqp);
+       spin_lock(&(XFS_DQ_TO_QINF(dqp)->qi_pinlock));
        dqp->q_pincount++;
-       XFS_DQ_PINUNLOCK(dqp, s);
+       spin_unlock(&(XFS_DQ_TO_QINF(dqp)->qi_pinlock));
 }
 
 /*
@@ -115,17 +114,16 @@ xfs_qm_dquot_logitem_unpin(
        xfs_dq_logitem_t *logitem,
        int               stale)
 {
-       unsigned long   s;
        xfs_dquot_t *dqp;
 
        dqp = logitem->qli_dquot;
        ASSERT(dqp->q_pincount > 0);
-       s = XFS_DQ_PINLOCK(dqp);
+       spin_lock(&(XFS_DQ_TO_QINF(dqp)->qi_pinlock));
        dqp->q_pincount--;
        if (dqp->q_pincount == 0) {
                sv_broadcast(&dqp->q_pinwait);
        }
-       XFS_DQ_PINUNLOCK(dqp, s);
+       spin_unlock(&(XFS_DQ_TO_QINF(dqp)->qi_pinlock));
 }
 
 /* ARGSUSED */
@@ -189,8 +187,6 @@ void
 xfs_qm_dqunpin_wait(
        xfs_dquot_t     *dqp)
 {
-       SPLDECL(s);
-
        ASSERT(XFS_DQ_IS_LOCKED(dqp));
        if (dqp->q_pincount == 0) {
                return;
@@ -200,9 +196,9 @@ xfs_qm_dqunpin_wait(
         * Give the log a push so we don't wait here too long.
         */
        xfs_log_force(dqp->q_mount, (xfs_lsn_t)0, XFS_LOG_FORCE);
-       s = XFS_DQ_PINLOCK(dqp);
+       spin_lock(&(XFS_DQ_TO_QINF(dqp)->qi_pinlock));
        if (dqp->q_pincount == 0) {
-               XFS_DQ_PINUNLOCK(dqp, s);
+               spin_unlock(&(XFS_DQ_TO_QINF(dqp)->qi_pinlock));
                return;
        }
        sv_wait(&(dqp->q_pinwait), PINOD,
@@ -216,8 +212,8 @@ xfs_qm_dqunpin_wait(
  * If so, we want to push it out to help us take this item off the AIL as soon
  * as possible.
  *
- * We must not be holding the AIL_LOCK at this point. Calling incore() to
- * search the buffer cache can be a time consuming thing, and AIL_LOCK is a
+ * We must not be holding the AIL lock at this point. Calling incore() to
+ * search the buffer cache can be a time consuming thing, and AIL lock is a
  * spinlock.
  */
 STATIC void
@@ -322,7 +318,7 @@ xfs_qm_dquot_logitem_trylock(
                 * want to do that now since we might sleep in the device
                 * strategy routine.  We also don't want to grab the buffer lock
                 * here because we'd like not to call into the buffer cache
-                * while holding the AIL_LOCK.
+                * while holding the AIL lock.
                 * Make sure to only return PUSHBUF if we set pushbuf_flag
                 * ourselves.  If someone else is doing it then we don't
                 * want to go to the push routine and duplicate their efforts.
@@ -562,15 +558,14 @@ xfs_qm_qoffend_logitem_committed(
        xfs_lsn_t lsn)
 {
        xfs_qoff_logitem_t      *qfs;
-       SPLDECL(s);
 
        qfs = qfe->qql_start_lip;
-       AIL_LOCK(qfs->qql_item.li_mountp,s);
+       spin_lock(&qfs->qql_item.li_mountp->m_ail_lock);
        /*
         * Delete the qoff-start logitem from the AIL.
         * xfs_trans_delete_ail() drops the AIL lock.
         */
-       xfs_trans_delete_ail(qfs->qql_item.li_mountp, (xfs_log_item_t *)qfs, s);
+       xfs_trans_delete_ail(qfs->qql_item.li_mountp, (xfs_log_item_t *)qfs);
        kmem_free(qfs, sizeof(xfs_qoff_logitem_t));
        kmem_free(qfe, sizeof(xfs_qoff_logitem_t));
        return (xfs_lsn_t)-1;
index d488645f833d709f59fdb940bb6112e72d664655..35582fe9d648d9652fbaaf03f2cde3fa45440efd 100644 (file)
@@ -310,7 +310,6 @@ xfs_qm_mount_quotas(
        xfs_mount_t     *mp,
        int             mfsi_flags)
 {
-       unsigned long   s;
        int             error = 0;
        uint            sbf;
 
@@ -367,13 +366,13 @@ xfs_qm_mount_quotas(
 
  write_changes:
        /*
-        * We actually don't have to acquire the SB_LOCK at all.
+        * We actually don't have to acquire the m_sb_lock at all.
         * This can only be called from mount, and that's single threaded. XXX
         */
-       s = XFS_SB_LOCK(mp);
+       spin_lock(&mp->m_sb_lock);
        sbf = mp->m_sb.sb_qflags;
        mp->m_sb.sb_qflags = mp->m_qflags & XFS_MOUNT_QUOTA_ALL;
-       XFS_SB_UNLOCK(mp, s);
+       spin_unlock(&mp->m_sb_lock);
 
        if (sbf != (mp->m_qflags & XFS_MOUNT_QUOTA_ALL)) {
                if (xfs_qm_write_sb_changes(mp, XFS_SB_QFLAGS)) {
@@ -1139,7 +1138,7 @@ xfs_qm_init_quotainfo(
                return error;
        }
 
-       spinlock_init(&qinf->qi_pinlock, "xfs_qinf_pin");
+       spin_lock_init(&qinf->qi_pinlock);
        xfs_qm_list_init(&qinf->qi_dqlist, "mpdqlist", 0);
        qinf->qi_dqreclaims = 0;
 
@@ -1370,7 +1369,6 @@ xfs_qm_qino_alloc(
 {
        xfs_trans_t     *tp;
        int             error;
-       unsigned long   s;
        int             committed;
 
        tp = xfs_trans_alloc(mp, XFS_TRANS_QM_QINOCREATE);
@@ -1402,7 +1400,7 @@ xfs_qm_qino_alloc(
         * sbfields arg may contain fields other than *QUOTINO;
         * VERSIONNUM for example.
         */
-       s = XFS_SB_LOCK(mp);
+       spin_lock(&mp->m_sb_lock);
        if (flags & XFS_QMOPT_SBVERSION) {
 #if defined(DEBUG) && defined(XFS_LOUD_RECOVERY)
                unsigned oldv = mp->m_sb.sb_versionnum;
@@ -1429,7 +1427,7 @@ xfs_qm_qino_alloc(
                mp->m_sb.sb_uquotino = (*ip)->i_ino;
        else
                mp->m_sb.sb_gquotino = (*ip)->i_ino;
-       XFS_SB_UNLOCK(mp, s);
+       spin_unlock(&mp->m_sb_lock);
        xfs_mod_sb(tp, sbfields);
 
        if ((error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES))) {
index 23ccaa5fceaf8fce92ba713ff0b263dd86ba6132..baf537c1c177bc4f67caf909d0a1cfbc4e491662 100644 (file)
@@ -52,8 +52,8 @@ extern kmem_zone_t    *qm_dqtrxzone;
 /*
  * Dquot hashtable constants/threshold values.
  */
-#define XFS_QM_HASHSIZE_LOW            (NBPP / sizeof(xfs_dqhash_t))
-#define XFS_QM_HASHSIZE_HIGH           ((NBPP * 4) / sizeof(xfs_dqhash_t))
+#define XFS_QM_HASHSIZE_LOW            (PAGE_SIZE / sizeof(xfs_dqhash_t))
+#define XFS_QM_HASHSIZE_HIGH           ((PAGE_SIZE * 4) / sizeof(xfs_dqhash_t))
 
 /*
  * This defines the unit of allocation of dquots.
@@ -106,7 +106,7 @@ typedef struct xfs_qm {
 typedef struct xfs_quotainfo {
        xfs_inode_t     *qi_uquotaip;    /* user quota inode */
        xfs_inode_t     *qi_gquotaip;    /* group quota inode */
-       lock_t           qi_pinlock;     /* dquot pinning mutex */
+       spinlock_t       qi_pinlock;     /* dquot pinning lock */
        xfs_dqlist_t     qi_dqlist;      /* all dquots in filesys */
        int              qi_dqreclaims;  /* a change here indicates
                                            a removal in the dqlist */
index ad5579d4eac479e1c26266a06fb9ad081211bdba..2cc5886cfe85e232374f67bf84620b564d9bbc42 100644 (file)
@@ -200,7 +200,6 @@ xfs_qm_scall_quotaoff(
        boolean_t               force)
 {
        uint                    dqtype;
-       unsigned long   s;
        int                     error;
        uint                    inactivate_flags;
        xfs_qoff_logitem_t      *qoffstart;
@@ -237,9 +236,9 @@ xfs_qm_scall_quotaoff(
        if ((flags & XFS_ALL_QUOTA_ACCT) == 0) {
                mp->m_qflags &= ~(flags);
 
-               s = XFS_SB_LOCK(mp);
+               spin_lock(&mp->m_sb_lock);
                mp->m_sb.sb_qflags = mp->m_qflags;
-               XFS_SB_UNLOCK(mp, s);
+               spin_unlock(&mp->m_sb_lock);
                mutex_unlock(&(XFS_QI_QOFFLOCK(mp)));
 
                /* XXX what to do if error ? Revert back to old vals incore ? */
@@ -415,7 +414,6 @@ xfs_qm_scall_quotaon(
        uint            flags)
 {
        int             error;
-       unsigned long   s;
        uint            qf;
        uint            accflags;
        __int64_t       sbflags;
@@ -468,10 +466,10 @@ xfs_qm_scall_quotaon(
         * Change sb_qflags on disk but not incore mp->qflags
         * if this is the root filesystem.
         */
-       s = XFS_SB_LOCK(mp);
+       spin_lock(&mp->m_sb_lock);
        qf = mp->m_sb.sb_qflags;
        mp->m_sb.sb_qflags = qf | flags;
-       XFS_SB_UNLOCK(mp, s);
+       spin_unlock(&mp->m_sb_lock);
 
        /*
         * There's nothing to change if it's the same.
@@ -815,7 +813,6 @@ xfs_qm_log_quotaoff(
 {
        xfs_trans_t            *tp;
        int                     error;
-       unsigned long   s;
        xfs_qoff_logitem_t     *qoffi=NULL;
        uint                    oldsbqflag=0;
 
@@ -832,10 +829,10 @@ xfs_qm_log_quotaoff(
        qoffi = xfs_trans_get_qoff_item(tp, NULL, flags & XFS_ALL_QUOTA_ACCT);
        xfs_trans_log_quotaoff_item(tp, qoffi);
 
-       s = XFS_SB_LOCK(mp);
+       spin_lock(&mp->m_sb_lock);
        oldsbqflag = mp->m_sb.sb_qflags;
        mp->m_sb.sb_qflags = (mp->m_qflags & ~(flags)) & XFS_MOUNT_QUOTA_ALL;
-       XFS_SB_UNLOCK(mp, s);
+       spin_unlock(&mp->m_sb_lock);
 
        xfs_mod_sb(tp, XFS_SB_QFLAGS);
 
@@ -854,9 +851,9 @@ error0:
                 * No one else is modifying sb_qflags, so this is OK.
                 * We still hold the quotaofflock.
                 */
-               s = XFS_SB_LOCK(mp);
+               spin_lock(&mp->m_sb_lock);
                mp->m_sb.sb_qflags = oldsbqflag;
-               XFS_SB_UNLOCK(mp, s);
+               spin_unlock(&mp->m_sb_lock);
        }
        *qoffstartp = qoffi;
        return (error);
index f45a49ffd3a34907f6b1ca2aceaea7dce40e2133..c27abef7b84f9498821dfb9704e21b15bb86e781 100644 (file)
@@ -17,7 +17,6 @@
  */
 #include <xfs.h>
 #include "debug.h"
-#include "spin.h"
 
 static char            message[1024];  /* keep it off the stack */
 static DEFINE_SPINLOCK(xfs_err_lock);
@@ -81,3 +80,9 @@ assfail(char *expr, char *file, int line)
        printk("Assertion failed: %s, file: %s, line: %d\n", expr, file, line);
        BUG();
 }
+
+void
+xfs_hex_dump(void *p, int length)
+{
+       print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_OFFSET, 16, 1, p, length, 1);
+}
index 5cf2e86caa7198653b37f086bf02335d2599fad6..129067cfcb86eba3f9fb54d18a27a3c47bf7ba22 100644 (file)
@@ -21,7 +21,7 @@ static kmem_zone_t *ktrace_hdr_zone;
 static kmem_zone_t *ktrace_ent_zone;
 static int          ktrace_zentries;
 
-void
+void __init
 ktrace_init(int zentries)
 {
        ktrace_zentries = zentries;
@@ -36,7 +36,7 @@ ktrace_init(int zentries)
        ASSERT(ktrace_ent_zone);
 }
 
-void
+void __exit
 ktrace_uninit(void)
 {
        kmem_zone_destroy(ktrace_hdr_zone);
@@ -90,8 +90,6 @@ ktrace_alloc(int nentries, unsigned int __nocast sleep)
                return NULL;
        }
 
-       spinlock_init(&(ktp->kt_lock), "kt_lock");
-
        ktp->kt_entries  = ktep;
        ktp->kt_nentries = nentries;
        ktp->kt_index    = 0;
@@ -114,8 +112,6 @@ ktrace_free(ktrace_t *ktp)
        if (ktp == (ktrace_t *)NULL)
                return;
 
-       spinlock_destroy(&ktp->kt_lock);
-
        /*
         * Special treatment for the Vnode trace buffer.
         */
index 0d73216287c06b3cd1b08b3600869277d19e8f43..56e72b40a859a42471fc685ad84bb164bed78f56 100644 (file)
@@ -18,8 +18,6 @@
 #ifndef __XFS_SUPPORT_KTRACE_H__
 #define __XFS_SUPPORT_KTRACE_H__
 
-#include <spin.h>
-
 /*
  * Trace buffer entry structure.
  */
@@ -31,7 +29,6 @@ typedef struct ktrace_entry {
  * Trace buffer header structure.
  */
 typedef struct ktrace {
-       lock_t          kt_lock;        /* mutex to guard counters */
        int             kt_nentries;    /* number of entries in trace buf */
        int             kt_index;       /* current index in entries */
        int             kt_rollover;
index e157015c70ffcad4ed7ee0e989e4714fb55db526..493a6ecf8590c5e697bcf7fe116875ae14ce90e3 100644 (file)
@@ -133,7 +133,7 @@ uuid_table_remove(uuid_t *uuid)
        mutex_unlock(&uuid_monitor);
 }
 
-void
+void __init
 uuid_init(void)
 {
        mutex_init(&uuid_monitor);
index b5a7d92c68438a7d7e6b1d5e38b33a833bb0dd7b..540e4c98982512a365eeccc4bd7f5d16b1d9db63 100644 (file)
@@ -37,7 +37,7 @@
 #define XFS_LOG_TRACE 1
 #define XFS_RW_TRACE 1
 #define XFS_BUF_TRACE 1
-#define XFS_VNODE_TRACE 1
+#define XFS_INODE_TRACE 1
 #define XFS_FILESTREAMS_TRACE 1
 #endif
 
index 5bfb66f33cafce0b4e81b8ec22c3985a10f53e2b..7272fe39a92de3c1007999e14ffb310a933654f0 100644 (file)
@@ -391,32 +391,6 @@ xfs_acl_allow_set(
        return error;
 }
 
-/*
- * The access control process to determine the access permission:
- *     if uid == file owner id, use the file owner bits.
- *     if gid == file owner group id, use the file group bits.
- *     scan ACL for a matching user or group, and use matched entry
- *     permission. Use total permissions of all matching group entries,
- *     until all acl entries are exhausted. The final permission produced
- *     by matching acl entry or entries needs to be & with group permission.
- *     if not owner, owning group, or matching entry in ACL, use file
- *     other bits.  
- */
-STATIC int
-xfs_acl_capability_check(
-       mode_t          mode,
-       cred_t          *cr)
-{
-       if ((mode & ACL_READ) && !capable_cred(cr, CAP_DAC_READ_SEARCH))
-               return EACCES;
-       if ((mode & ACL_WRITE) && !capable_cred(cr, CAP_DAC_OVERRIDE))
-               return EACCES;
-       if ((mode & ACL_EXECUTE) && !capable_cred(cr, CAP_DAC_OVERRIDE))
-               return EACCES;
-
-       return 0;
-}
-
 /*
  * Note: cr is only used here for the capability check if the ACL test fails.
  *       It is not used to find out the credentials uid or groups etc, as was
@@ -438,7 +412,6 @@ xfs_acl_access(
 
        matched.ae_tag = 0;     /* Invalid type */
        matched.ae_perm = 0;
-       md >>= 6;       /* Normalize the bits for comparison */
 
        for (i = 0; i < fap->acl_cnt; i++) {
                /*
@@ -520,7 +493,8 @@ xfs_acl_access(
                break;
        }
 
-       return xfs_acl_capability_check(md, cr);
+       /* EACCES tells generic_permission to check for capability overrides */
+       return EACCES;
 }
 
 /*
index 34b7d3391299a02b3e76d8203b876a28b067cf54..332a772461c47ad6a25fc42a812bd055d6579d3c 100644 (file)
@@ -75,7 +75,6 @@ extern int xfs_acl_vremove(bhv_vnode_t *, int);
 #define _ACL_GET_DEFAULT(pv,pd)        (xfs_acl_vtoacl(pv,NULL,pd) == 0)
 #define _ACL_ACCESS_EXISTS     xfs_acl_vhasacl_access
 #define _ACL_DEFAULT_EXISTS    xfs_acl_vhasacl_default
-#define _ACL_XFS_IACCESS(i,m,c) (XFS_IFORK_Q(i) ? xfs_acl_iaccess(i,m,c) : -1)
 
 #define _ACL_ALLOC(a)          ((a) = kmem_zone_alloc(xfs_acl_zone, KM_SLEEP))
 #define _ACL_FREE(a)           ((a)? kmem_zone_free(xfs_acl_zone, (a)):(void)0)
@@ -95,7 +94,6 @@ extern int xfs_acl_vremove(bhv_vnode_t *, int);
 #define _ACL_GET_DEFAULT(pv,pd)        (0)
 #define _ACL_ACCESS_EXISTS     (NULL)
 #define _ACL_DEFAULT_EXISTS    (NULL)
-#define _ACL_XFS_IACCESS(i,m,c) (-1)
 #endif
 
 #endif /* __XFS_ACL_H__ */
index 9381b0360c4b3e2da63a460dc2bcd6db30657fb5..61b292a9fb414f2486ce92a1175b8a11b2cc6e7d 100644 (file)
@@ -193,7 +193,7 @@ typedef struct xfs_perag
        xfs_agino_t     pagi_count;     /* number of allocated inodes */
        int             pagb_count;     /* pagb slots in use */
 #ifdef __KERNEL__
-       lock_t          pagb_lock;      /* lock for pagb_list */
+       spinlock_t      pagb_lock;      /* lock for pagb_list */
 #endif
        xfs_perag_busy_t *pagb_list;    /* unstable blocks */
        atomic_t        pagf_fstrms;    /* # of filestreams active in this AG */
index 012a649a19c35c2fc68e0b953557b92f42df83b7..ea6aa60ace06b243c18a508afe718b07dbe58e58 100644 (file)
@@ -2206,7 +2206,7 @@ xfs_alloc_read_agf(
                        be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNOi]);
                pag->pagf_levels[XFS_BTNUM_CNTi] =
                        be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNTi]);
-               spinlock_init(&pag->pagb_lock, "xfspagb");
+               spin_lock_init(&pag->pagb_lock);
                pag->pagb_list = kmem_zalloc(XFS_PAGB_NUM_SLOTS *
                                        sizeof(xfs_perag_busy_t), KM_SLEEP);
                pag->pagf_init = 1;
@@ -2500,10 +2500,9 @@ xfs_alloc_mark_busy(xfs_trans_t *tp,
        xfs_mount_t             *mp;
        xfs_perag_busy_t        *bsy;
        int                     n;
-       SPLDECL(s);
 
        mp = tp->t_mountp;
-       s = mutex_spinlock(&mp->m_perag[agno].pagb_lock);
+       spin_lock(&mp->m_perag[agno].pagb_lock);
 
        /* search pagb_list for an open slot */
        for (bsy = mp->m_perag[agno].pagb_list, n = 0;
@@ -2533,7 +2532,7 @@ xfs_alloc_mark_busy(xfs_trans_t *tp,
                xfs_trans_set_sync(tp);
        }
 
-       mutex_spinunlock(&mp->m_perag[agno].pagb_lock, s);
+       spin_unlock(&mp->m_perag[agno].pagb_lock);
 }
 
 void
@@ -2543,11 +2542,10 @@ xfs_alloc_clear_busy(xfs_trans_t *tp,
 {
        xfs_mount_t             *mp;
        xfs_perag_busy_t        *list;
-       SPLDECL(s);
 
        mp = tp->t_mountp;
 
-       s = mutex_spinlock(&mp->m_perag[agno].pagb_lock);
+       spin_lock(&mp->m_perag[agno].pagb_lock);
        list = mp->m_perag[agno].pagb_list;
 
        ASSERT(idx < XFS_PAGB_NUM_SLOTS);
@@ -2559,7 +2557,7 @@ xfs_alloc_clear_busy(xfs_trans_t *tp,
                TRACE_UNBUSY("xfs_alloc_clear_busy", "missing", agno, idx, tp);
        }
 
-       mutex_spinunlock(&mp->m_perag[agno].pagb_lock, s);
+       spin_unlock(&mp->m_perag[agno].pagb_lock);
 }
 
 
@@ -2578,11 +2576,10 @@ xfs_alloc_search_busy(xfs_trans_t *tp,
        xfs_agblock_t           uend, bend;
        xfs_lsn_t               lsn;
        int                     cnt;
-       SPLDECL(s);
 
        mp = tp->t_mountp;
 
-       s = mutex_spinlock(&mp->m_perag[agno].pagb_lock);
+       spin_lock(&mp->m_perag[agno].pagb_lock);
        cnt = mp->m_perag[agno].pagb_count;
 
        uend = bno + len - 1;
@@ -2615,12 +2612,12 @@ xfs_alloc_search_busy(xfs_trans_t *tp,
        if (cnt) {
                TRACE_BUSYSEARCH("xfs_alloc_search_busy", "found", agno, bno, len, n, tp);
                lsn = bsy->busy_tp->t_commit_lsn;
-               mutex_spinunlock(&mp->m_perag[agno].pagb_lock, s);
+               spin_unlock(&mp->m_perag[agno].pagb_lock);
                xfs_log_force(mp, lsn, XFS_LOG_FORCE|XFS_LOG_SYNC);
        } else {
                TRACE_BUSYSEARCH("xfs_alloc_search_busy", "not-found", agno, bno, len, n, tp);
                n = -1;
-               mutex_spinunlock(&mp->m_perag[agno].pagb_lock, s);
+               spin_unlock(&mp->m_perag[agno].pagb_lock);
        }
 
        return n;
index 93fa64dd1be6ab49287bc5a1e8a4659767fa20f0..e58f321fdae9b1822038c58605785d277a3e6fb2 100644 (file)
@@ -929,7 +929,7 @@ xfs_attr_shortform_addname(xfs_da_args_t *args)
  * This leaf block cannot have a "remote" value, we only call this routine
  * if bmap_one_block() says there is only one block (ie: no remote blks).
  */
-int
+STATIC int
 xfs_attr_leaf_addname(xfs_da_args_t *args)
 {
        xfs_inode_t *dp;
index 81f45dae1c57f668c09786b405b2b805862bb556..eb3815ebb7aaee17fe7716fd7aae9133adc4cfce 100644 (file)
@@ -226,17 +226,15 @@ xfs_attr_shortform_bytesfit(xfs_inode_t *dp, int bytes)
 STATIC void
 xfs_sbversion_add_attr2(xfs_mount_t *mp, xfs_trans_t *tp)
 {
-       unsigned long s;
-
        if ((mp->m_flags & XFS_MOUNT_ATTR2) &&
            !(XFS_SB_VERSION_HASATTR2(&mp->m_sb))) {
-               s = XFS_SB_LOCK(mp);
+               spin_lock(&mp->m_sb_lock);
                if (!XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
                        XFS_SB_VERSION_ADDATTR2(&mp->m_sb);
-                       XFS_SB_UNLOCK(mp, s);
+                       spin_unlock(&mp->m_sb_lock);
                        xfs_mod_sb(tp, XFS_SB_VERSIONNUM | XFS_SB_FEATURES2);
                } else
-                       XFS_SB_UNLOCK(mp, s);
+                       spin_unlock(&mp->m_sb_lock);
        }
 }
 
index fab0b6d5a41be3916ac8893a2f82f142cd4443f4..48228848f5ae3e2e6f52900b6d0ea7215274a36d 100644 (file)
  * XFS bit manipulation routines, used in non-realtime code.
  */
 
-#ifndef HAVE_ARCH_HIGHBIT
-/*
- * Index of high bit number in byte, -1 for none set, 0..7 otherwise.
- */
-static const char xfs_highbit[256] = {
-       -1, 0, 1, 1, 2, 2, 2, 2,                        /* 00 .. 07 */
-       3, 3, 3, 3, 3, 3, 3, 3,                 /* 08 .. 0f */
-       4, 4, 4, 4, 4, 4, 4, 4,                 /* 10 .. 17 */
-       4, 4, 4, 4, 4, 4, 4, 4,                 /* 18 .. 1f */
-       5, 5, 5, 5, 5, 5, 5, 5,                 /* 20 .. 27 */
-       5, 5, 5, 5, 5, 5, 5, 5,                 /* 28 .. 2f */
-       5, 5, 5, 5, 5, 5, 5, 5,                 /* 30 .. 37 */
-       5, 5, 5, 5, 5, 5, 5, 5,                 /* 38 .. 3f */
-       6, 6, 6, 6, 6, 6, 6, 6,                 /* 40 .. 47 */
-       6, 6, 6, 6, 6, 6, 6, 6,                 /* 48 .. 4f */
-       6, 6, 6, 6, 6, 6, 6, 6,                 /* 50 .. 57 */
-       6, 6, 6, 6, 6, 6, 6, 6,                 /* 58 .. 5f */
-       6, 6, 6, 6, 6, 6, 6, 6,                 /* 60 .. 67 */
-       6, 6, 6, 6, 6, 6, 6, 6,                 /* 68 .. 6f */
-       6, 6, 6, 6, 6, 6, 6, 6,                 /* 70 .. 77 */
-       6, 6, 6, 6, 6, 6, 6, 6,                 /* 78 .. 7f */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* 80 .. 87 */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* 88 .. 8f */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* 90 .. 97 */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* 98 .. 9f */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* a0 .. a7 */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* a8 .. af */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* b0 .. b7 */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* b8 .. bf */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* c0 .. c7 */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* c8 .. cf */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* d0 .. d7 */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* d8 .. df */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* e0 .. e7 */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* e8 .. ef */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* f0 .. f7 */
-       7, 7, 7, 7, 7, 7, 7, 7,                 /* f8 .. ff */
-};
-#endif
-
-/*
- * xfs_highbit32: get high bit set out of 32-bit argument, -1 if none set.
- */
-inline int
-xfs_highbit32(
-       __uint32_t      v)
-{
-#ifdef HAVE_ARCH_HIGHBIT
-       return highbit32(v);
-#else
-       int             i;
-
-       if (v & 0xffff0000)
-               if (v & 0xff000000)
-                       i = 24;
-               else
-                       i = 16;
-       else if (v & 0x0000ffff)
-               if (v & 0x0000ff00)
-                       i = 8;
-               else
-                       i = 0;
-       else
-               return -1;
-       return i + xfs_highbit[(v >> i) & 0xff];
-#endif
-}
-
-/*
- * xfs_lowbit64: get low bit set out of 64-bit argument, -1 if none set.
- */
-int
-xfs_lowbit64(
-       __uint64_t      v)
-{
-       __uint32_t      w = (__uint32_t)v;
-       int             n = 0;
-
-       if (w) {        /* lower bits */
-               n = ffs(w);
-       } else {        /* upper bits */
-               w = (__uint32_t)(v >> 32);
-               if (w && (n = ffs(w)))
-                       n += 32;
-       }
-       return n - 1;
-}
-
-/*
- * xfs_highbit64: get high bit set out of 64-bit argument, -1 if none set.
- */
-int
-xfs_highbit64(
-       __uint64_t      v)
-{
-       __uint32_t      h = (__uint32_t)(v >> 32);
-
-       if (h)
-               return xfs_highbit32(h) + 32;
-       return xfs_highbit32((__uint32_t)v);
-}
-
-
 /*
  * Return whether bitmap is empty.
  * Size is number of words in the bitmap, which is padded to word boundary
index 082641a9782c073e832fab360d88d98020f87310..325a007dec91de7942df66db18afc0be2199a61c 100644 (file)
@@ -47,13 +47,30 @@ static inline __uint64_t xfs_mask64lo(int n)
 }
 
 /* Get high bit set out of 32-bit argument, -1 if none set */
-extern int xfs_highbit32(__uint32_t v);
-
-/* Get low bit set out of 64-bit argument, -1 if none set */
-extern int xfs_lowbit64(__uint64_t v);
+static inline int xfs_highbit32(__uint32_t v)
+{
+       return fls(v) - 1;
+}
 
 /* Get high bit set out of 64-bit argument, -1 if none set */
-extern int xfs_highbit64(__uint64_t);
+static inline int xfs_highbit64(__uint64_t v)
+{
+       return fls64(v) - 1;
+}
+
+/* Get low bit set out of 32-bit argument, -1 if none set */
+static inline int xfs_lowbit32(__uint32_t v)
+{
+       __uint32_t t = v;
+       return (t) ? find_first_bit((unsigned long *)&t, 32) : -1;
+}
+
+/* Get low bit set out of 64-bit argument, -1 if none set */
+static inline int xfs_lowbit64(__uint64_t v)
+{
+       __uint64_t t = v;
+       return (t) ? find_first_bit((unsigned long *)&t, 64) : -1;
+}
 
 /* Return whether bitmap is empty (1 == empty) */
 extern int xfs_bitmap_empty(uint *map, uint size);
index 2e9b34b7344b4e81f268db68428e45e9363ef787..1c0a5a585a82775880b981d13fb500793e784617 100644 (file)
@@ -2830,11 +2830,11 @@ xfs_bmap_btalloc(
                args.prod = align;
                if ((args.mod = (xfs_extlen_t)do_mod(ap->off, args.prod)))
                        args.mod = (xfs_extlen_t)(args.prod - args.mod);
-       } else if (mp->m_sb.sb_blocksize >= NBPP) {
+       } else if (mp->m_sb.sb_blocksize >= PAGE_CACHE_SIZE) {
                args.prod = 1;
                args.mod = 0;
        } else {
-               args.prod = NBPP >> mp->m_sb.sb_blocklog;
+               args.prod = PAGE_CACHE_SIZE >> mp->m_sb.sb_blocklog;
                if ((args.mod = (xfs_extlen_t)(do_mod(ap->off, args.prod))))
                        args.mod = (xfs_extlen_t)(args.prod - args.mod);
        }
@@ -2969,7 +2969,7 @@ STATIC int
 xfs_bmap_alloc(
        xfs_bmalloca_t  *ap)            /* bmap alloc argument struct */
 {
-       if ((ap->ip->i_d.di_flags & XFS_DIFLAG_REALTIME) && ap->userdata)
+       if (XFS_IS_REALTIME_INODE(ap->ip) && ap->userdata)
                return xfs_bmap_rtalloc(ap);
        return xfs_bmap_btalloc(ap);
 }
@@ -3096,8 +3096,7 @@ xfs_bmap_del_extent(
                /*
                 * Realtime allocation.  Free it and record di_nblocks update.
                 */
-               if (whichfork == XFS_DATA_FORK &&
-                   (ip->i_d.di_flags & XFS_DIFLAG_REALTIME)) {
+               if (whichfork == XFS_DATA_FORK && XFS_IS_REALTIME_INODE(ip)) {
                        xfs_fsblock_t   bno;
                        xfs_filblks_t   len;
 
@@ -3956,7 +3955,6 @@ xfs_bmap_add_attrfork(
        xfs_bmap_free_t         flist;          /* freed extent records */
        xfs_mount_t             *mp;            /* mount structure */
        xfs_trans_t             *tp;            /* transaction pointer */
-       unsigned long           s;              /* spinlock spl value */
        int                     blks;           /* space reservation */
        int                     version = 1;    /* superblock attr version */
        int                     committed;      /* xaction was committed */
@@ -4053,7 +4051,7 @@ xfs_bmap_add_attrfork(
           (!XFS_SB_VERSION_HASATTR2(&mp->m_sb) && version == 2)) {
                __int64_t sbfields = 0;
 
-               s = XFS_SB_LOCK(mp);
+               spin_lock(&mp->m_sb_lock);
                if (!XFS_SB_VERSION_HASATTR(&mp->m_sb)) {
                        XFS_SB_VERSION_ADDATTR(&mp->m_sb);
                        sbfields |= XFS_SB_VERSIONNUM;
@@ -4063,10 +4061,10 @@ xfs_bmap_add_attrfork(
                        sbfields |= (XFS_SB_VERSIONNUM | XFS_SB_FEATURES2);
                }
                if (sbfields) {
-                       XFS_SB_UNLOCK(mp, s);
+                       spin_unlock(&mp->m_sb_lock);
                        xfs_mod_sb(tp, sbfields);
                } else
-                       XFS_SB_UNLOCK(mp, s);
+                       spin_unlock(&mp->m_sb_lock);
        }
        if ((error = xfs_bmap_finish(&tp, &flist, &committed)))
                goto error2;
@@ -6394,7 +6392,7 @@ xfs_bmap_count_blocks(
  * Recursively walks each level of a btree
  * to count total fsblocks is use.
  */
-int                                     /* error */
+STATIC int                                     /* error */
 xfs_bmap_count_tree(
        xfs_mount_t     *mp,            /* file system mount point */
        xfs_trans_t     *tp,            /* transaction pointer */
@@ -6470,7 +6468,7 @@ xfs_bmap_count_tree(
 /*
  * Count leaf blocks given a range of extent records.
  */
-int
+STATIC int
 xfs_bmap_count_leaves(
        xfs_ifork_t             *ifp,
        xfs_extnum_t            idx,
@@ -6490,7 +6488,7 @@ xfs_bmap_count_leaves(
  * Count leaf blocks given a range of extent records originally
  * in btree format.
  */
-int
+STATIC int
 xfs_bmap_disk_count_leaves(
        xfs_extnum_t            idx,
        xfs_bmbt_block_t        *block,
index 68267d75ff19ef4264c5d316c0084149c53b54a6..87224b7d7984d9affdc9323f71d3c4066ed3f0a3 100644 (file)
@@ -25,6 +25,8 @@ struct xfs_inode;
 struct xfs_mount;
 struct xfs_trans;
 
+extern kmem_zone_t     *xfs_bmap_free_item_zone;
+
 /*
  * DELTA: describe a change to the in-core extent list.
  *
index 32b49ec00fb521510b888cab245d06653acfed17..c4181d85605cb646e94c55afd5d4bb49d43f1dd3 100644 (file)
@@ -2062,8 +2062,7 @@ xfs_bmbt_insert(
                                pcur->bc_private.b.allocated;
                        pcur->bc_private.b.allocated = 0;
                        ASSERT((cur->bc_private.b.firstblock != NULLFSBLOCK) ||
-                              (cur->bc_private.b.ip->i_d.di_flags &
-                               XFS_DIFLAG_REALTIME));
+                              XFS_IS_REALTIME_INODE(cur->bc_private.b.ip));
                        cur->bc_private.b.firstblock =
                                pcur->bc_private.b.firstblock;
                        ASSERT(cur->bc_private.b.flist ==
index 6e40a0a198ffd19a1da3750e6d1cd6746e8414ef..7440b78f9cec3b6d5c722e804b3fbc5acca756c8 100644 (file)
@@ -24,6 +24,8 @@ struct xfs_inode;
 struct xfs_mount;
 struct xfs_trans;
 
+extern kmem_zone_t     *xfs_btree_cur_zone;
+
 /*
  * This nonsense is to make -wlint happy.
  */
index c8f2c2886fe4a018516708bc071eae85f42a1b57..63debd147eb554f69a07fcd78241a2b882c3f311 100644 (file)
@@ -378,7 +378,6 @@ xfs_buf_item_unpin(
        xfs_mount_t     *mp;
        xfs_buf_t       *bp;
        int             freed;
-       SPLDECL(s);
 
        bp = bip->bli_buf;
        ASSERT(bp != NULL);
@@ -409,8 +408,8 @@ xfs_buf_item_unpin(
                        XFS_BUF_SET_FSPRIVATE(bp, NULL);
                        XFS_BUF_CLR_IODONE_FUNC(bp);
                } else {
-                       AIL_LOCK(mp,s);
-                       xfs_trans_delete_ail(mp, (xfs_log_item_t *)bip, s);
+                       spin_lock(&mp->m_ail_lock);
+                       xfs_trans_delete_ail(mp, (xfs_log_item_t *)bip);
                        xfs_buf_item_relse(bp);
                        ASSERT(XFS_BUF_FSPRIVATE(bp, void *) == NULL);
                }
@@ -1113,7 +1112,6 @@ xfs_buf_iodone(
        xfs_buf_log_item_t      *bip)
 {
        struct xfs_mount        *mp;
-       SPLDECL(s);
 
        ASSERT(bip->bli_buf == bp);
 
@@ -1128,11 +1126,11 @@ xfs_buf_iodone(
         *
         * Either way, AIL is useless if we're forcing a shutdown.
         */
-       AIL_LOCK(mp,s);
+       spin_lock(&mp->m_ail_lock);
        /*
         * xfs_trans_delete_ail() drops the AIL lock.
         */
-       xfs_trans_delete_ail(mp, (xfs_log_item_t *)bip, s);
+       xfs_trans_delete_ail(mp, (xfs_log_item_t *)bip);
 
 #ifdef XFS_TRANS_DEBUG
        kmem_free(bip->bli_orig, XFS_BUF_COUNT(bp));
index d7e13614306635bfae1f31bfbd1728e0ff3c1e36..5a41c348bb1ce7f6b2d7e55a7d096ae17ebc4ba8 100644 (file)
@@ -18,6 +18,8 @@
 #ifndef        __XFS_BUF_ITEM_H__
 #define        __XFS_BUF_ITEM_H__
 
+extern kmem_zone_t     *xfs_buf_item_zone;
+
 /*
  * This is the structure used to lay out a buf log item in the
  * log.  The data map describes which 128 byte chunks of the buffer
index 26d09e2e1a7f98e3f9cf35fae58fd931e4c5098f..1b446849fb3d60fe38c2df9a35197fcb9d3021e6 100644 (file)
@@ -2218,7 +2218,7 @@ xfs_da_state_free(xfs_da_state_t *state)
 
 #ifdef XFS_DABUF_DEBUG
 xfs_dabuf_t    *xfs_dabuf_global_list;
-lock_t         xfs_dabuf_global_lock;
+spinlock_t     xfs_dabuf_global_lock;
 #endif
 
 /*
@@ -2264,10 +2264,9 @@ xfs_da_buf_make(int nbuf, xfs_buf_t **bps, inst_t *ra)
        }
 #ifdef XFS_DABUF_DEBUG
        {
-               SPLDECL(s);
                xfs_dabuf_t     *p;
 
-               s = mutex_spinlock(&xfs_dabuf_global_lock);
+               spin_lock(&xfs_dabuf_global_lock);
                for (p = xfs_dabuf_global_list; p; p = p->next) {
                        ASSERT(p->blkno != dabuf->blkno ||
                               p->target != dabuf->target);
@@ -2277,7 +2276,7 @@ xfs_da_buf_make(int nbuf, xfs_buf_t **bps, inst_t *ra)
                        xfs_dabuf_global_list->prev = dabuf;
                dabuf->next = xfs_dabuf_global_list;
                xfs_dabuf_global_list = dabuf;
-               mutex_spinunlock(&xfs_dabuf_global_lock, s);
+               spin_unlock(&xfs_dabuf_global_lock);
        }
 #endif
        return dabuf;
@@ -2319,16 +2318,14 @@ xfs_da_buf_done(xfs_dabuf_t *dabuf)
                kmem_free(dabuf->data, BBTOB(dabuf->bbcount));
 #ifdef XFS_DABUF_DEBUG
        {
-               SPLDECL(s);
-
-               s = mutex_spinlock(&xfs_dabuf_global_lock);
+               spin_lock(&xfs_dabuf_global_lock);
                if (dabuf->prev)
                        dabuf->prev->next = dabuf->next;
                else
                        xfs_dabuf_global_list = dabuf->next;
                if (dabuf->next)
                        dabuf->next->prev = dabuf->prev;
-               mutex_spinunlock(&xfs_dabuf_global_lock, s);
+               spin_unlock(&xfs_dabuf_global_lock);
        }
        memset(dabuf, 0, XFS_DA_BUF_SIZE(dabuf->nbuf));
 #endif
index 44dabf02f2a3ca99c844101fa213a000949fed0f..7facf86f74f92c6904fcfc5da89435ecc5f8a3db 100644 (file)
@@ -260,6 +260,7 @@ void xfs_da_binval(struct xfs_trans *tp, xfs_dabuf_t *dabuf);
 xfs_daddr_t xfs_da_blkno(xfs_dabuf_t *dabuf);
 
 extern struct kmem_zone *xfs_da_state_zone;
+extern struct kmem_zone *xfs_dabuf_zone;
 #endif /* __KERNEL__ */
 
 #endif /* __XFS_DA_BTREE_H__ */
index 584f1ae85cd9b9537dcf6d052aaf796f81ac0a5b..3f53fad356a30a199e11ad761d47cb6b53aa6252 100644 (file)
@@ -52,76 +52,72 @@ xfs_swapext(
        xfs_swapext_t   __user *sxu)
 {
        xfs_swapext_t   *sxp;
-       xfs_inode_t     *ip=NULL, *tip=NULL;
-       xfs_mount_t     *mp;
-       struct file     *fp = NULL, *tfp = NULL;
-       bhv_vnode_t     *vp, *tvp;
+       xfs_inode_t     *ip, *tip;
+       struct file     *file, *target_file;
        int             error = 0;
 
        sxp = kmem_alloc(sizeof(xfs_swapext_t), KM_MAYFAIL);
        if (!sxp) {
                error = XFS_ERROR(ENOMEM);
-               goto error0;
+               goto out;
        }
 
        if (copy_from_user(sxp, sxu, sizeof(xfs_swapext_t))) {
                error = XFS_ERROR(EFAULT);
-               goto error0;
+               goto out_free_sxp;
        }
 
        /* Pull information for the target fd */
-       if (((fp = fget((int)sxp->sx_fdtarget)) == NULL) ||
-           ((vp = vn_from_inode(fp->f_path.dentry->d_inode)) == NULL))  {
+       file = fget((int)sxp->sx_fdtarget);
+       if (!file) {
                error = XFS_ERROR(EINVAL);
-               goto error0;
+               goto out_free_sxp;
        }
 
-       ip = xfs_vtoi(vp);
-       if (ip == NULL) {
+       if (!(file->f_mode & FMODE_WRITE) || (file->f_flags & O_APPEND)) {
                error = XFS_ERROR(EBADF);
-               goto error0;
+               goto out_put_file;
        }
 
-       if (((tfp = fget((int)sxp->sx_fdtmp)) == NULL) ||
-           ((tvp = vn_from_inode(tfp->f_path.dentry->d_inode)) == NULL)) {
+       target_file = fget((int)sxp->sx_fdtmp);
+       if (!target_file) {
                error = XFS_ERROR(EINVAL);
-               goto error0;
+               goto out_put_file;
        }
 
-       tip = xfs_vtoi(tvp);
-       if (tip == NULL) {
+       if (!(target_file->f_mode & FMODE_WRITE) ||
+           (target_file->f_flags & O_APPEND)) {
                error = XFS_ERROR(EBADF);
-               goto error0;
+               goto out_put_target_file;
        }
 
+       ip = XFS_I(file->f_path.dentry->d_inode);
+       tip = XFS_I(target_file->f_path.dentry->d_inode);
+
        if (ip->i_mount != tip->i_mount) {
-               error =  XFS_ERROR(EINVAL);
-               goto error0;
+               error = XFS_ERROR(EINVAL);
+               goto out_put_target_file;
        }
 
        if (ip->i_ino == tip->i_ino) {
-               error =  XFS_ERROR(EINVAL);
-               goto error0;
+               error = XFS_ERROR(EINVAL);
+               goto out_put_target_file;
        }
 
-       mp = ip->i_mount;
-
-       if (XFS_FORCED_SHUTDOWN(mp)) {
-               error =  XFS_ERROR(EIO);
-               goto error0;
+       if (XFS_FORCED_SHUTDOWN(ip->i_mount)) {
+               error = XFS_ERROR(EIO);
+               goto out_put_target_file;
        }
 
-       error = XFS_SWAP_EXTENTS(mp, &ip->i_iocore, &tip->i_iocore, sxp);
-
- error0:
-       if (fp != NULL)
-               fput(fp);
-       if (tfp != NULL)
-               fput(tfp);
-
-       if (sxp != NULL)
-               kmem_free(sxp, sizeof(xfs_swapext_t));
+       error = xfs_swap_extents(ip, tip, sxp);
 
+ out_put_target_file:
+       fput(target_file);
+ out_put_file:
+       fput(file);
+ out_free_sxp:
+       kmem_free(sxp, sizeof(xfs_swapext_t));
+ out:
        return error;
 }
 
@@ -169,15 +165,6 @@ xfs_swap_extents(
        xfs_lock_inodes(ips, 2, 0, lock_flags);
        locked = 1;
 
-       /* Check permissions */
-       error = xfs_iaccess(ip, S_IWUSR, NULL);
-       if (error)
-               goto error0;
-
-       error = xfs_iaccess(tip, S_IWUSR, NULL);
-       if (error)
-               goto error0;
-
        /* Verify that both files have the same format */
        if ((ip->i_d.di_mode & S_IFMT) != (tip->i_d.di_mode & S_IFMT)) {
                error = XFS_ERROR(EINVAL);
@@ -185,8 +172,7 @@ xfs_swap_extents(
        }
 
        /* Verify both files are either real-time or non-realtime */
-       if ((ip->i_d.di_flags & XFS_DIFLAG_REALTIME) !=
-           (tip->i_d.di_flags & XFS_DIFLAG_REALTIME)) {
+       if (XFS_IS_REALTIME_INODE(ip) != XFS_IS_REALTIME_INODE(tip)) {
                error = XFS_ERROR(EINVAL);
                goto error0;
        }
@@ -199,7 +185,7 @@ xfs_swap_extents(
        }
 
        if (VN_CACHED(tvp) != 0) {
-               xfs_inval_cached_trace(&tip->i_iocore, 0, -1, 0, -1);
+               xfs_inval_cached_trace(tip, 0, -1, 0, -1);
                error = xfs_flushinval_pages(tip, 0, -1,
                                FI_REMAPF_LOCKED);
                if (error)
index dedd713574e130b8b2a3e449a8cffb5b529ca12a..c9065eaf2a4d2a9eceea58fe0563f4377cfe0ad1 100644 (file)
@@ -171,69 +171,35 @@ typedef enum xfs_dinode_fmt
 /*
  * Inode data & attribute fork sizes, per inode.
  */
-#define XFS_CFORK_Q(dcp)                    ((dcp)->di_forkoff != 0)
-#define        XFS_CFORK_Q_DISK(dcp)               ((dcp)->di_forkoff != 0)
-
-#define XFS_CFORK_BOFF(dcp)                 ((int)((dcp)->di_forkoff << 3))
-#define        XFS_CFORK_BOFF_DISK(dcp)            ((int)((dcp)->di_forkoff << 3))
-
-#define        XFS_CFORK_DSIZE_DISK(dcp,mp) \
-       (XFS_CFORK_Q_DISK(dcp) ? XFS_CFORK_BOFF_DISK(dcp) : XFS_LITINO(mp))
-#define XFS_CFORK_DSIZE(dcp,mp) \
-       (XFS_CFORK_Q(dcp) ? XFS_CFORK_BOFF(dcp) : XFS_LITINO(mp))
-
-#define        XFS_CFORK_ASIZE_DISK(dcp,mp) \
-       (XFS_CFORK_Q_DISK(dcp) ? XFS_LITINO(mp) - XFS_CFORK_BOFF_DISK(dcp) : 0)
-#define XFS_CFORK_ASIZE(dcp,mp) \
-       (XFS_CFORK_Q(dcp) ? XFS_LITINO(mp) - XFS_CFORK_BOFF(dcp) : 0)
-
-#define        XFS_CFORK_SIZE_DISK(dcp,mp,w) \
-       ((w) == XFS_DATA_FORK ? \
-               XFS_CFORK_DSIZE_DISK(dcp, mp) : \
-               XFS_CFORK_ASIZE_DISK(dcp, mp))
-#define XFS_CFORK_SIZE(dcp,mp,w) \
-       ((w) == XFS_DATA_FORK ? \
-               XFS_CFORK_DSIZE(dcp, mp) : XFS_CFORK_ASIZE(dcp, mp))
+#define XFS_DFORK_Q(dip)               ((dip)->di_core.di_forkoff != 0)
+#define XFS_DFORK_BOFF(dip)            ((int)((dip)->di_core.di_forkoff << 3))
 
 #define XFS_DFORK_DSIZE(dip,mp) \
-       XFS_CFORK_DSIZE_DISK(&(dip)->di_core, mp)
-#define XFS_DFORK_DSIZE_HOST(dip,mp) \
-       XFS_CFORK_DSIZE(&(dip)->di_core, mp)
+       (XFS_DFORK_Q(dip) ? \
+               XFS_DFORK_BOFF(dip) : \
+               XFS_LITINO(mp))
 #define XFS_DFORK_ASIZE(dip,mp) \
-       XFS_CFORK_ASIZE_DISK(&(dip)->di_core, mp)
-#define XFS_DFORK_ASIZE_HOST(dip,mp) \
-       XFS_CFORK_ASIZE(&(dip)->di_core, mp)
-#define        XFS_DFORK_SIZE(dip,mp,w) \
-       XFS_CFORK_SIZE_DISK(&(dip)->di_core, mp, w)
-#define        XFS_DFORK_SIZE_HOST(dip,mp,w) \
-       XFS_CFORK_SIZE(&(dip)->di_core, mp, w)
+       (XFS_DFORK_Q(dip) ? \
+               XFS_LITINO(mp) - XFS_DFORK_BOFF(dip) : \
+               0)
+#define XFS_DFORK_SIZE(dip,mp,w) \
+       ((w) == XFS_DATA_FORK ? \
+               XFS_DFORK_DSIZE(dip, mp) : \
+               XFS_DFORK_ASIZE(dip, mp))
 
-#define        XFS_DFORK_Q(dip)                    XFS_CFORK_Q_DISK(&(dip)->di_core)
-#define        XFS_DFORK_BOFF(dip)                 XFS_CFORK_BOFF_DISK(&(dip)->di_core)
-#define        XFS_DFORK_DPTR(dip)                 ((dip)->di_u.di_c)
-#define        XFS_DFORK_APTR(dip)     \
+#define XFS_DFORK_DPTR(dip)                ((dip)->di_u.di_c)
+#define XFS_DFORK_APTR(dip)    \
        ((dip)->di_u.di_c + XFS_DFORK_BOFF(dip))
-#define        XFS_DFORK_PTR(dip,w)    \
+#define XFS_DFORK_PTR(dip,w)   \
        ((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip))
-#define        XFS_CFORK_FORMAT(dcp,w) \
-       ((w) == XFS_DATA_FORK ? (dcp)->di_format : (dcp)->di_aformat)
-#define        XFS_CFORK_FMT_SET(dcp,w,n) \
+#define XFS_DFORK_FORMAT(dip,w) \
        ((w) == XFS_DATA_FORK ? \
-               ((dcp)->di_format = (n)) : ((dcp)->di_aformat = (n)))
-#define        XFS_DFORK_FORMAT(dip,w) XFS_CFORK_FORMAT(&(dip)->di_core, w)
-
-#define        XFS_CFORK_NEXTENTS_DISK(dcp,w) \
+               (dip)->di_core.di_format : \
+               (dip)->di_core.di_aformat)
+#define XFS_DFORK_NEXTENTS(dip,w) \
        ((w) == XFS_DATA_FORK ? \
-               be32_to_cpu((dcp)->di_nextents) : \
-               be16_to_cpu((dcp)->di_anextents))
-#define XFS_CFORK_NEXTENTS(dcp,w) \
-       ((w) == XFS_DATA_FORK ? (dcp)->di_nextents : (dcp)->di_anextents)
-#define        XFS_DFORK_NEXTENTS(dip,w) XFS_CFORK_NEXTENTS_DISK(&(dip)->di_core, w)
-#define        XFS_DFORK_NEXTENTS_HOST(dip,w) XFS_CFORK_NEXTENTS(&(dip)->di_core, w)
-
-#define        XFS_CFORK_NEXT_SET(dcp,w,n) \
-       ((w) == XFS_DATA_FORK ? \
-               ((dcp)->di_nextents = (n)) : ((dcp)->di_anextents = (n)))
+               be32_to_cpu((dip)->di_core.di_nextents) : \
+               be16_to_cpu((dip)->di_core.di_anextents))
 
 #define        XFS_BUF_TO_DINODE(bp)   ((xfs_dinode_t *)XFS_BUF_PTR(bp))
 
@@ -273,6 +239,12 @@ typedef enum xfs_dinode_fmt
 #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
 #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
 
+#ifdef CONFIG_XFS_RT
+#define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
+#else
+#define XFS_IS_REALTIME_INODE(ip) (0)
+#endif
+
 #define XFS_DIFLAG_ANY \
        (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
         XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
index b0f1ee8fcb90abb776a8dbd53f3664d4df189fe3..be7c4251fa619e03a161cf3d66c60dd2e0518151 100644 (file)
@@ -42,6 +42,7 @@
 #include "xfs_dir2_node.h"
 #include "xfs_dir2_trace.h"
 #include "xfs_error.h"
+#include "xfs_vnodeops.h"
 
 
 void
@@ -301,7 +302,7 @@ xfs_readdir(
        int             rval;           /* return value */
        int             v;              /* type-checking value */
 
-       vn_trace_entry(dp, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(dp);
 
        if (XFS_FORCED_SHUTDOWN(dp->i_mount))
                return XFS_ERROR(EIO);
index a4634d94e561ab9624b272662b2a4a2841640309..05e5365d3c3170bd034c16e1cd79761e5dcf7bcf 100644 (file)
@@ -230,37 +230,6 @@ xfs_error_report(
        }
 }
 
-STATIC void
-xfs_hex_dump(void *p, int length)
-{
-       __uint8_t *uip = (__uint8_t*)p;
-       int     i;
-       char    sbuf[128], *s;
-
-       s = sbuf;
-       *s = '\0';
-       for (i=0; i<length; i++, uip++) {
-               if ((i % 16) == 0) {
-                       if (*s != '\0')
-                               cmn_err(CE_ALERT, "%s\n", sbuf);
-                       s = sbuf;
-                       sprintf(s, "0x%x: ", i);
-                       while( *s != '\0')
-                               s++;
-               }
-               sprintf(s, "%02x ", *uip);
-
-               /*
-                * the kernel sprintf is a void; user sprintf returns
-                * the sprintf'ed string's length.  Find the new end-
-                * of-string
-                */
-               while( *s != '\0')
-                       s++;
-       }
-       cmn_err(CE_ALERT, "%s\n", sbuf);
-}
-
 void
 xfs_corruption_error(
        char            *tag,
index 10e9d9619ae5779ddb3a89437bad9b4abbc56af3..6490d2a9f8e1268d6bea93782eecc89f66f34b48 100644 (file)
@@ -174,6 +174,8 @@ extern void xfs_cmn_err(int panic_tag, int level, struct xfs_mount *mp,
 /* PRINTFLIKE3 */
 extern void xfs_fs_cmn_err(int level, struct xfs_mount *mp, char *fmt, ...);
 
+extern void xfs_hex_dump(void *p, int length);
+
 #define xfs_fs_repair_cmn_err(level, mp, fmt, args...) \
        xfs_fs_cmn_err(level, mp, fmt "  Unmount and run xfs_repair.", ## args)
 
index f938a51be81b64fb358d12d9284c5479459150ae..132bd07b9bb8abb5663e97e2190f3ee075260d61 100644 (file)
@@ -110,19 +110,18 @@ STATIC void
 xfs_efi_item_unpin(xfs_efi_log_item_t *efip, int stale)
 {
        xfs_mount_t     *mp;
-       SPLDECL(s);
 
        mp = efip->efi_item.li_mountp;
-       AIL_LOCK(mp, s);
+       spin_lock(&mp->m_ail_lock);
        if (efip->efi_flags & XFS_EFI_CANCELED) {
                /*
                 * xfs_trans_delete_ail() drops the AIL lock.
                 */
-               xfs_trans_delete_ail(mp, (xfs_log_item_t *)efip, s);
+               xfs_trans_delete_ail(mp, (xfs_log_item_t *)efip);
                xfs_efi_item_free(efip);
        } else {
                efip->efi_flags |= XFS_EFI_COMMITTED;
-               AIL_UNLOCK(mp, s);
+               spin_unlock(&mp->m_ail_lock);
        }
 }
 
@@ -138,10 +137,9 @@ xfs_efi_item_unpin_remove(xfs_efi_log_item_t *efip, xfs_trans_t *tp)
 {
        xfs_mount_t     *mp;
        xfs_log_item_desc_t     *lidp;
-       SPLDECL(s);
 
        mp = efip->efi_item.li_mountp;
-       AIL_LOCK(mp, s);
+       spin_lock(&mp->m_ail_lock);
        if (efip->efi_flags & XFS_EFI_CANCELED) {
                /*
                 * free the xaction descriptor pointing to this item
@@ -152,11 +150,11 @@ xfs_efi_item_unpin_remove(xfs_efi_log_item_t *efip, xfs_trans_t *tp)
                 * pull the item off the AIL.
                 * xfs_trans_delete_ail() drops the AIL lock.
                 */
-               xfs_trans_delete_ail(mp, (xfs_log_item_t *)efip, s);
+               xfs_trans_delete_ail(mp, (xfs_log_item_t *)efip);
                xfs_efi_item_free(efip);
        } else {
                efip->efi_flags |= XFS_EFI_COMMITTED;
-               AIL_UNLOCK(mp, s);
+               spin_unlock(&mp->m_ail_lock);
        }
 }
 
@@ -350,13 +348,12 @@ xfs_efi_release(xfs_efi_log_item_t        *efip,
 {
        xfs_mount_t     *mp;
        int             extents_left;
-       SPLDECL(s);
 
        mp = efip->efi_item.li_mountp;
        ASSERT(efip->efi_next_extent > 0);
        ASSERT(efip->efi_flags & XFS_EFI_COMMITTED);
 
-       AIL_LOCK(mp, s);
+       spin_lock(&mp->m_ail_lock);
        ASSERT(efip->efi_next_extent >= nextents);
        efip->efi_next_extent -= nextents;
        extents_left = efip->efi_next_extent;
@@ -364,10 +361,10 @@ xfs_efi_release(xfs_efi_log_item_t        *efip,
                /*
                 * xfs_trans_delete_ail() drops the AIL lock.
                 */
-               xfs_trans_delete_ail(mp, (xfs_log_item_t *)efip, s);
+               xfs_trans_delete_ail(mp, (xfs_log_item_t *)efip);
                xfs_efi_item_free(efip);
        } else {
-               AIL_UNLOCK(mp, s);
+               spin_unlock(&mp->m_ail_lock);
        }
 }
 
index 36d8f6aa11afeed014b3223c1a00334a502c9e38..eb03eab5ca52bd5f924e986a516ef800c5bb8e3a 100644 (file)
@@ -348,7 +348,7 @@ _xfs_filestream_update_ag(
 }
 
 /* xfs_fstrm_free_func(): callback for freeing cached stream items. */
-void
+STATIC void
 xfs_fstrm_free_func(
        unsigned long   ino,
        void            *data)
index aab9662765170b556bdf82cd623c2642dce8aa45..3bed6433d0501f09ab8589961aeabd1e810bb200 100644 (file)
@@ -419,9 +419,13 @@ typedef struct xfs_handle {
 /*
  * ioctl commands that are used by Linux filesystems
  */
-#define XFS_IOC_GETXFLAGS      _IOR('f', 1, long)
-#define XFS_IOC_SETXFLAGS      _IOW('f', 2, long)
-#define XFS_IOC_GETVERSION     _IOR('v', 1, long)
+#define XFS_IOC_GETXFLAGS      FS_IOC_GETFLAGS
+#define XFS_IOC_SETXFLAGS      FS_IOC_SETFLAGS
+#define XFS_IOC_GETVERSION     FS_IOC_GETVERSION
+/* 32-bit compat counterparts */
+#define XFS_IOC32_GETXFLAGS    FS_IOC32_GETFLAGS
+#define XFS_IOC32_SETXFLAGS    FS_IOC32_SETFLAGS
+#define XFS_IOC32_GETVERSION   FS_IOC32_GETVERSION
 
 /*
  * ioctl commands that replace IRIX fcntl()'s
index c92d5b821029b4a002681c5a112862c84f1e7e0c..b8de7f3cc17efa6bd37dac31a40b539e322f4189 100644 (file)
@@ -462,15 +462,13 @@ xfs_fs_counts(
        xfs_mount_t             *mp,
        xfs_fsop_counts_t       *cnt)
 {
-       unsigned long   s;
-
        xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
-       s = XFS_SB_LOCK(mp);
+       spin_lock(&mp->m_sb_lock);
        cnt->freedata = mp->m_sb.sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
        cnt->freertx = mp->m_sb.sb_frextents;
        cnt->freeino = mp->m_sb.sb_ifree;
        cnt->allocino = mp->m_sb.sb_icount;
-       XFS_SB_UNLOCK(mp, s);
+       spin_unlock(&mp->m_sb_lock);
        return 0;
 }
 
@@ -497,7 +495,6 @@ xfs_reserve_blocks(
 {
        __int64_t               lcounter, delta, fdblks_delta;
        __uint64_t              request;
-       unsigned long           s;
 
        /* If inval is null, report current values and return */
        if (inval == (__uint64_t *)NULL) {
@@ -515,7 +512,7 @@ xfs_reserve_blocks(
         * problem. we needto work out if we are freeing or allocation
         * blocks first, then we can do the modification as necessary.
         *
-        * We do this under the XFS_SB_LOCK so that if we are near
+        * We do this under the m_sb_lock so that if we are near
         * ENOSPC, we will hold out any changes while we work out
         * what to do. This means that the amount of free space can
         * change while we do this, so we need to retry if we end up
@@ -526,7 +523,7 @@ xfs_reserve_blocks(
         * enabled, disabled or even compiled in....
         */
 retry:
-       s = XFS_SB_LOCK(mp);
+       spin_lock(&mp->m_sb_lock);
        xfs_icsb_sync_counters_flags(mp, XFS_ICSB_SB_LOCKED);
 
        /*
@@ -569,7 +566,7 @@ out:
                outval->resblks = mp->m_resblks;
                outval->resblks_avail = mp->m_resblks_avail;
        }
-       XFS_SB_UNLOCK(mp, s);
+       spin_unlock(&mp->m_sb_lock);
 
        if (fdblks_delta) {
                /*
index bf8e9aff272e3765e3ebbdfe39d0962ae68e594e..8efc4a5b8b9289f30d8d11c069021b6a606e592d 100644 (file)
@@ -81,8 +81,6 @@ typedef       struct xfs_btree_sblock xfs_inobt_block_t;
 #define        XFS_INOBT_MASK(i)               ((xfs_inofree_t)1 << (i))
 #define        XFS_INOBT_IS_FREE(rp,i)         \
                (((rp)->ir_free & XFS_INOBT_MASK(i)) != 0)
-#define        XFS_INOBT_IS_FREE_DISK(rp,i)    \
-               ((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0)
 #define        XFS_INOBT_SET_FREE(rp,i)        ((rp)->ir_free |= XFS_INOBT_MASK(i))
 #define        XFS_INOBT_CLR_FREE(rp,i)        ((rp)->ir_free &= ~XFS_INOBT_MASK(i))
 
index fb69ef180b275f9d0300dc5faa23483e7936f5e7..f01b07687faf93103ff7964f266607b3a6a3ce17 100644 (file)
@@ -65,7 +65,7 @@
  */
 STATIC int
 xfs_iget_core(
-       bhv_vnode_t     *vp,
+       struct inode    *inode,
        xfs_mount_t     *mp,
        xfs_trans_t     *tp,
        xfs_ino_t       ino,
@@ -74,9 +74,9 @@ xfs_iget_core(
        xfs_inode_t     **ipp,
        xfs_daddr_t     bno)
 {
+       struct inode    *old_inode;
        xfs_inode_t     *ip;
        xfs_inode_t     *iq;
-       bhv_vnode_t     *inode_vp;
        int             error;
        xfs_icluster_t  *icl, *new_icl = NULL;
        unsigned long   first_index, mask;
@@ -111,8 +111,8 @@ again:
                        goto again;
                }
 
-               inode_vp = XFS_ITOV_NULL(ip);
-               if (inode_vp == NULL) {
+               old_inode = ip->i_vnode;
+               if (old_inode == NULL) {
                        /*
                         * If IRECLAIM is set this inode is
                         * on its way out of the system,
@@ -140,28 +140,9 @@ again:
                                return ENOENT;
                        }
 
-                       /*
-                        * There may be transactions sitting in the
-                        * incore log buffers or being flushed to disk
-                        * at this time.  We can't clear the
-                        * XFS_IRECLAIMABLE flag until these
-                        * transactions have hit the disk, otherwise we
-                        * will void the guarantee the flag provides
-                        * xfs_iunpin()
-                        */
-                       if (xfs_ipincount(ip)) {
-                               read_unlock(&pag->pag_ici_lock);
-                               xfs_log_force(mp, 0,
-                                       XFS_LOG_FORCE|XFS_LOG_SYNC);
-                               XFS_STATS_INC(xs_ig_frecycle);
-                               goto again;
-                       }
-
-                       vn_trace_exit(ip, "xfs_iget.alloc",
-                               (inst_t *)__return_address);
+                       xfs_itrace_exit_tag(ip, "xfs_iget.alloc");
 
                        XFS_STATS_INC(xs_ig_found);
-
                        xfs_iflags_clear(ip, XFS_IRECLAIMABLE);
                        read_unlock(&pag->pag_ici_lock);
 
@@ -171,13 +152,11 @@ again:
 
                        goto finish_inode;
 
-               } else if (vp != inode_vp) {
-                       struct inode *inode = vn_to_inode(inode_vp);
-
+               } else if (inode != old_inode) {
                        /* The inode is being torn down, pause and
                         * try again.
                         */
-                       if (inode->i_state & (I_FREEING | I_CLEAR)) {
+                       if (old_inode->i_state & (I_FREEING | I_CLEAR)) {
                                read_unlock(&pag->pag_ici_lock);
                                delay(1);
                                XFS_STATS_INC(xs_ig_frecycle);
@@ -190,7 +169,7 @@ again:
 */
                        cmn_err(CE_PANIC,
                "xfs_iget_core: ambiguous vns: vp/0x%p, invp/0x%p",
-                                       inode_vp, vp);
+                                       old_inode, inode);
                }
 
                /*
@@ -200,20 +179,16 @@ again:
                XFS_STATS_INC(xs_ig_found);
 
 finish_inode:
-               if (ip->i_d.di_mode == 0) {
-                       if (!(flags & XFS_IGET_CREATE)) {
-                               xfs_put_perag(mp, pag);
-                               return ENOENT;
-                       }
-                       xfs_iocore_inode_reinit(ip);
+               if (ip->i_d.di_mode == 0 && !(flags & XFS_IGET_CREATE)) {
+                       xfs_put_perag(mp, pag);
+                       return ENOENT;
                }
 
                if (lock_flags != 0)
                        xfs_ilock(ip, lock_flags);
 
                xfs_iflags_clear(ip, XFS_ISTALE);
-               vn_trace_exit(ip, "xfs_iget.found",
-                                       (inst_t *)__return_address);
+               xfs_itrace_exit_tag(ip, "xfs_iget.found");
                goto return_ip;
        }
 
@@ -234,10 +209,16 @@ finish_inode:
                return error;
        }
 
-       vn_trace_exit(ip, "xfs_iget.alloc", (inst_t *)__return_address);
+       xfs_itrace_exit_tag(ip, "xfs_iget.alloc");
+
+
+       mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
+                    "xfsino", ip->i_ino);
+       mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
+       init_waitqueue_head(&ip->i_ipin_wait);
+       atomic_set(&ip->i_pincount, 0);
+       initnsema(&ip->i_flock, 1, "xfsfino");
 
-       xfs_inode_lock_init(ip, vp);
-       xfs_iocore_inode_init(ip);
        if (lock_flags)
                xfs_ilock(ip, lock_flags);
 
@@ -333,9 +314,6 @@ finish_inode:
        ASSERT(ip->i_df.if_ext_max ==
               XFS_IFORK_DSIZE(ip) / sizeof(xfs_bmbt_rec_t));
 
-       ASSERT(((ip->i_d.di_flags & XFS_DIFLAG_REALTIME) != 0) ==
-              ((ip->i_iocore.io_flags & XFS_IOCORE_RT) != 0));
-
        xfs_iflags_set(ip, XFS_IMODIFIED);
        *ipp = ip;
 
@@ -343,7 +321,7 @@ finish_inode:
         * If we have a real type for an on-disk inode, we can set ops(&unlock)
         * now.  If it's a new inode being created, xfs_ialloc will handle it.
         */
-       xfs_initialize_vnode(mp, vp, ip);
+       xfs_initialize_vnode(mp, inode, ip);
        return 0;
 }
 
@@ -363,69 +341,58 @@ xfs_iget(
        xfs_daddr_t     bno)
 {
        struct inode    *inode;
-       bhv_vnode_t     *vp = NULL;
+       xfs_inode_t     *ip;
        int             error;
 
        XFS_STATS_INC(xs_ig_attempts);
 
 retry:
        inode = iget_locked(mp->m_super, ino);
-       if (inode) {
-               xfs_inode_t     *ip;
-
-               vp = vn_from_inode(inode);
-               if (inode->i_state & I_NEW) {
-                       vn_initialize(inode);
-                       error = xfs_iget_core(vp, mp, tp, ino, flags,
-                                       lock_flags, ipp, bno);
-                       if (error) {
-                               vn_mark_bad(vp);
-                               if (inode->i_state & I_NEW)
-                                       unlock_new_inode(inode);
-                               iput(inode);
-                       }
-               } else {
-                       /*
-                        * If the inode is not fully constructed due to
-                        * filehandle mismatches wait for the inode to go
-                        * away and try again.
-                        *
-                        * iget_locked will call __wait_on_freeing_inode
-                        * to wait for the inode to go away.
-                        */
-                       if (is_bad_inode(inode) ||
-                           ((ip = xfs_vtoi(vp)) == NULL)) {
-                               iput(inode);
-                               delay(1);
-                               goto retry;
-                       }
-
-                       if (lock_flags != 0)
-                               xfs_ilock(ip, lock_flags);
-                       XFS_STATS_INC(xs_ig_found);
-                       *ipp = ip;
-                       error = 0;
+       if (!inode)
+               /* If we got no inode we are out of memory */
+               return ENOMEM;
+
+       if (inode->i_state & I_NEW) {
+               XFS_STATS_INC(vn_active);
+               XFS_STATS_INC(vn_alloc);
+
+               error = xfs_iget_core(inode, mp, tp, ino, flags,
+                               lock_flags, ipp, bno);
+               if (error) {
+                       make_bad_inode(inode);
+                       if (inode->i_state & I_NEW)
+                               unlock_new_inode(inode);
+                       iput(inode);
                }
-       } else
-               error = ENOMEM; /* If we got no inode we are out of memory */
+               return error;
+       }
 
-       return error;
-}
+       /*
+        * If the inode is not fully constructed due to
+        * filehandle mismatches wait for the inode to go
+        * away and try again.
+        *
+        * iget_locked will call __wait_on_freeing_inode
+        * to wait for the inode to go away.
+        */
+       if (is_bad_inode(inode)) {
+               iput(inode);
+               delay(1);
+               goto retry;
+       }
 
-/*
- * Do the setup for the various locks within the incore inode.
- */
-void
-xfs_inode_lock_init(
-       xfs_inode_t     *ip,
-       bhv_vnode_t     *vp)
-{
-       mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
-                    "xfsino", ip->i_ino);
-       mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
-       init_waitqueue_head(&ip->i_ipin_wait);
-       atomic_set(&ip->i_pincount, 0);
-       initnsema(&ip->i_flock, 1, "xfsfino");
+       ip = XFS_I(inode);
+       if (!ip) {
+               iput(inode);
+               delay(1);
+               goto retry;
+       }
+
+       if (lock_flags != 0)
+               xfs_ilock(ip, lock_flags);
+       XFS_STATS_INC(xs_ig_found);
+       *ipp = ip;
+       return 0;
 }
 
 /*
@@ -465,11 +432,9 @@ void
 xfs_iput(xfs_inode_t   *ip,
         uint           lock_flags)
 {
-       bhv_vnode_t     *vp = XFS_ITOV(ip);
-
-       vn_trace_entry(ip, "xfs_iput", (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
        xfs_iunlock(ip, lock_flags);
-       VN_RELE(vp);
+       IRELE(ip);
 }
 
 /*
@@ -479,20 +444,19 @@ void
 xfs_iput_new(xfs_inode_t       *ip,
             uint               lock_flags)
 {
-       bhv_vnode_t     *vp = XFS_ITOV(ip);
-       struct inode    *inode = vn_to_inode(vp);
+       struct inode    *inode = ip->i_vnode;
 
-       vn_trace_entry(ip, "xfs_iput_new", (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        if ((ip->i_d.di_mode == 0)) {
                ASSERT(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
-               vn_mark_bad(vp);
+               make_bad_inode(inode);
        }
        if (inode->i_state & I_NEW)
                unlock_new_inode(inode);
        if (lock_flags)
                xfs_iunlock(ip, lock_flags);
-       VN_RELE(vp);
+       IRELE(ip);
 }
 
 
@@ -505,8 +469,6 @@ xfs_iput_new(xfs_inode_t    *ip,
 void
 xfs_ireclaim(xfs_inode_t *ip)
 {
-       bhv_vnode_t     *vp;
-
        /*
         * Remove from old hash list and mount list.
         */
@@ -535,9 +497,8 @@ xfs_ireclaim(xfs_inode_t *ip)
        /*
         * Pull our behavior descriptor from the vnode chain.
         */
-       vp = XFS_ITOV_NULL(ip);
-       if (vp) {
-               vn_to_inode(vp)->i_private = NULL;
+       if (ip->i_vnode) {
+               ip->i_vnode->i_private = NULL;
                ip->i_vnode = NULL;
        }
 
index 344948082819d94b82c72c5967d14e83e140cc36..a550546a70832dc727dd117ef1c4bbc3f0ef5e90 100644 (file)
@@ -15,6 +15,8 @@
  * along with this program; if not, write the Free Software Foundation,
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
+#include <linux/log2.h>
+
 #include "xfs.h"
 #include "xfs_fs.h"
 #include "xfs_types.h"
@@ -826,15 +828,17 @@ xfs_ip2xflags(
        xfs_icdinode_t          *dic = &ip->i_d;
 
        return _xfs_dic2xflags(dic->di_flags) |
-                               (XFS_CFORK_Q(dic) ? XFS_XFLAG_HASATTR : 0);
+                               (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
 }
 
 uint
 xfs_dic2xflags(
-       xfs_dinode_core_t       *dic)
+       xfs_dinode_t            *dip)
 {
+       xfs_dinode_core_t       *dic = &dip->di_core;
+
        return _xfs_dic2xflags(be16_to_cpu(dic->di_flags)) |
-                               (XFS_CFORK_Q_DISK(dic) ? XFS_XFLAG_HASATTR : 0);
+                               (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
 }
 
 /*
@@ -884,8 +888,8 @@ xfs_iread(
         * Initialize inode's trace buffers.
         * Do this before xfs_iformat in case it adds entries.
         */
-#ifdef XFS_VNODE_TRACE
-       ip->i_trace = ktrace_alloc(VNODE_TRACE_SIZE, KM_SLEEP);
+#ifdef XFS_INODE_TRACE
+       ip->i_trace = ktrace_alloc(INODE_TRACE_SIZE, KM_SLEEP);
 #endif
 #ifdef XFS_BMAP_TRACE
        ip->i_xtrace = ktrace_alloc(XFS_BMAP_KTRACE_SIZE, KM_SLEEP);
@@ -1220,10 +1224,8 @@ xfs_ialloc(
                                        ip->i_d.di_extsize = pip->i_d.di_extsize;
                                }
                        } else if ((mode & S_IFMT) == S_IFREG) {
-                               if (pip->i_d.di_flags & XFS_DIFLAG_RTINHERIT) {
+                               if (pip->i_d.di_flags & XFS_DIFLAG_RTINHERIT)
                                        di_flags |= XFS_DIFLAG_REALTIME;
-                                       ip->i_iocore.io_flags |= XFS_IOCORE_RT;
-                               }
                                if (pip->i_d.di_flags & XFS_DIFLAG_EXTSZINHERIT) {
                                        di_flags |= XFS_DIFLAG_EXTSIZE;
                                        ip->i_d.di_extsize = pip->i_d.di_extsize;
@@ -1298,7 +1300,10 @@ xfs_isize_check(
        if ((ip->i_d.di_mode & S_IFMT) != S_IFREG)
                return;
 
-       if (ip->i_d.di_flags & (XFS_DIFLAG_REALTIME | XFS_DIFLAG_EXTSIZE))
+       if (XFS_IS_REALTIME_INODE(ip))
+               return;
+
+       if (ip->i_d.di_flags & XFS_DIFLAG_EXTSIZE)
                return;
 
        nimaps = 2;
@@ -1711,7 +1716,7 @@ xfs_itruncate_finish(
                 * runs.
                 */
                XFS_BMAP_INIT(&free_list, &first_block);
-               error = XFS_BUNMAPI(mp, ntp, &ip->i_iocore,
+               error = xfs_bunmapi(ntp, ip,
                                    first_unmap_block, unmap_len,
                                    XFS_BMAPI_AFLAG(fork) |
                                      (sync ? 0 : XFS_BMAPI_ASYNC),
@@ -1844,8 +1849,6 @@ xfs_igrow_start(
        xfs_fsize_t     new_size,
        cred_t          *credp)
 {
-       int             error;
-
        ASSERT(ismrlocked(&(ip->i_lock), MR_UPDATE) != 0);
        ASSERT(ismrlocked(&(ip->i_iolock), MR_UPDATE) != 0);
        ASSERT(new_size > ip->i_size);
@@ -1855,9 +1858,7 @@ xfs_igrow_start(
         * xfs_write_file() beyond the end of the file
         * and any blocks between the old and new file sizes.
         */
-       error = xfs_zero_eof(XFS_ITOV(ip), &ip->i_iocore, new_size,
-                            ip->i_size);
-       return error;
+       return xfs_zero_eof(ip, new_size, ip->i_size);
 }
 
 /*
@@ -1959,24 +1960,6 @@ xfs_iunlink(
        ASSERT(agi->agi_unlinked[bucket_index]);
        ASSERT(be32_to_cpu(agi->agi_unlinked[bucket_index]) != agino);
 
-       error = xfs_itobp(mp, tp, ip, &dip, &ibp, 0, 0);
-       if (error)
-               return error;
-
-       /*
-        * Clear the on-disk di_nlink. This is to prevent xfs_bulkstat
-        * from picking up this inode when it is reclaimed (its incore state
-        * initialzed but not flushed to disk yet). The in-core di_nlink is
-        * already cleared in xfs_droplink() and a corresponding transaction
-        * logged. The hack here just synchronizes the in-core to on-disk
-        * di_nlink value in advance before the actual inode sync to disk.
-        * This is OK because the inode is already unlinked and would never
-        * change its di_nlink again for this inode generation.
-        * This is a temporary hack that would require a proper fix
-        * in the future.
-        */
-       dip->di_core.di_nlink = 0;
-
        if (be32_to_cpu(agi->agi_unlinked[bucket_index]) != NULLAGINO) {
                /*
                 * There is already another inode in the bucket we need
@@ -1984,6 +1967,10 @@ xfs_iunlink(
                 * Here we put the head pointer into our next pointer,
                 * and then we fall through to point the head at us.
                 */
+               error = xfs_itobp(mp, tp, ip, &dip, &ibp, 0, 0);
+               if (error)
+                       return error;
+
                ASSERT(be32_to_cpu(dip->di_next_unlinked) == NULLAGINO);
                /* both on-disk, don't endian flip twice */
                dip->di_next_unlinked = agi->agi_unlinked[bucket_index];
@@ -2209,7 +2196,6 @@ xfs_ifree_cluster(
        xfs_inode_log_item_t    *iip;
        xfs_log_item_t          *lip;
        xfs_perag_t             *pag = xfs_get_perag(mp, inum);
-       SPLDECL(s);
 
        if (mp->m_sb.sb_blocksize >= XFS_INODE_CLUSTER_SIZE(mp)) {
                blks_per_cluster = 1;
@@ -2311,9 +2297,9 @@ xfs_ifree_cluster(
                                iip = (xfs_inode_log_item_t *)lip;
                                ASSERT(iip->ili_logged == 1);
                                lip->li_cb = (void(*)(xfs_buf_t*,xfs_log_item_t*)) xfs_istale_done;
-                               AIL_LOCK(mp,s);
+                               spin_lock(&mp->m_ail_lock);
                                iip->ili_flush_lsn = iip->ili_item.li_lsn;
-                               AIL_UNLOCK(mp, s);
+                               spin_unlock(&mp->m_ail_lock);
                                xfs_iflags_set(iip->ili_inode, XFS_ISTALE);
                                pre_flushed++;
                        }
@@ -2334,9 +2320,9 @@ xfs_ifree_cluster(
                        iip->ili_last_fields = iip->ili_format.ilf_fields;
                        iip->ili_format.ilf_fields = 0;
                        iip->ili_logged = 1;
-                       AIL_LOCK(mp,s);
+                       spin_lock(&mp->m_ail_lock);
                        iip->ili_flush_lsn = iip->ili_item.li_lsn;
-                       AIL_UNLOCK(mp, s);
+                       spin_unlock(&mp->m_ail_lock);
 
                        xfs_buf_attach_iodone(bp,
                                (void(*)(xfs_buf_t*,xfs_log_item_t*))
@@ -2374,6 +2360,8 @@ xfs_ifree(
        int                     error;
        int                     delete;
        xfs_ino_t               first_ino;
+       xfs_dinode_t            *dip;
+       xfs_buf_t               *ibp;
 
        ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE));
        ASSERT(ip->i_transp == tp);
@@ -2409,8 +2397,27 @@ xfs_ifree(
         * by reincarnations of this inode.
         */
        ip->i_d.di_gen++;
+
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
 
+       error = xfs_itobp(ip->i_mount, tp, ip, &dip, &ibp, 0, 0);
+       if (error)
+               return error;
+
+        /*
+       * Clear the on-disk di_mode. This is to prevent xfs_bulkstat
+       * from picking up this inode when it is reclaimed (its incore state
+       * initialzed but not flushed to disk yet). The in-core di_mode is
+       * already cleared  and a corresponding transaction logged.
+       * The hack here just synchronizes the in-core to on-disk
+       * di_mode value in advance before the actual inode sync to disk.
+       * This is OK because the inode is already unlinked and would never
+       * change its di_mode again for this inode generation.
+       * This is a temporary hack that would require a proper fix
+       * in the future.
+       */
+       dip->di_core.di_mode = 0;
+
        if (delete) {
                xfs_ifree_cluster(ip, tp, first_ino);
        }
@@ -2735,7 +2742,6 @@ void
 xfs_idestroy(
        xfs_inode_t     *ip)
 {
-
        switch (ip->i_d.di_mode & S_IFMT) {
        case S_IFREG:
        case S_IFDIR:
@@ -2749,7 +2755,7 @@ xfs_idestroy(
        mrfree(&ip->i_iolock);
        freesema(&ip->i_flock);
 
-#ifdef XFS_VNODE_TRACE
+#ifdef XFS_INODE_TRACE
        ktrace_free(ip->i_trace);
 #endif
 #ifdef XFS_BMAP_TRACE
@@ -2775,16 +2781,15 @@ xfs_idestroy(
                 */
                xfs_mount_t     *mp = ip->i_mount;
                xfs_log_item_t  *lip = &ip->i_itemp->ili_item;
-               int             s;
 
                ASSERT(((lip->li_flags & XFS_LI_IN_AIL) == 0) ||
                                       XFS_FORCED_SHUTDOWN(ip->i_mount));
                if (lip->li_flags & XFS_LI_IN_AIL) {
-                       AIL_LOCK(mp, s);
+                       spin_lock(&mp->m_ail_lock);
                        if (lip->li_flags & XFS_LI_IN_AIL)
-                               xfs_trans_delete_ail(mp, lip, s);
+                               xfs_trans_delete_ail(mp, lip);
                        else
-                               AIL_UNLOCK(mp, s);
+                               spin_unlock(&mp->m_ail_lock);
                }
                xfs_inode_item_destroy(ip);
        }
@@ -2816,40 +2821,8 @@ xfs_iunpin(
 {
        ASSERT(atomic_read(&ip->i_pincount) > 0);
 
-       if (atomic_dec_and_lock(&ip->i_pincount, &ip->i_flags_lock)) {
-
-               /*
-                * If the inode is currently being reclaimed, the link between
-                * the bhv_vnode and the xfs_inode will be broken after the
-                * XFS_IRECLAIM* flag is set. Hence, if these flags are not
-                * set, then we can move forward and mark the linux inode dirty
-                * knowing that it is still valid as it won't freed until after
-                * the bhv_vnode<->xfs_inode link is broken in xfs_reclaim. The
-                * i_flags_lock is used to synchronise the setting of the
-                * XFS_IRECLAIM* flags and the breaking of the link, and so we
-                * can execute atomically w.r.t to reclaim by holding this lock
-                * here.
-                *
-                * However, we still need to issue the unpin wakeup call as the
-                * inode reclaim may be blocked waiting for the inode to become
-                * unpinned.
-                */
-
-               if (!__xfs_iflags_test(ip, XFS_IRECLAIM|XFS_IRECLAIMABLE)) {
-                       bhv_vnode_t     *vp = XFS_ITOV_NULL(ip);
-                       struct inode *inode = NULL;
-
-                       BUG_ON(vp == NULL);
-                       inode = vn_to_inode(vp);
-                       BUG_ON(inode->i_state & I_CLEAR);
-
-                       /* make sync come back and flush this inode */
-                       if (!(inode->i_state & (I_NEW|I_FREEING)))
-                               mark_inode_dirty_sync(inode);
-               }
-               spin_unlock(&ip->i_flags_lock);
+       if (atomic_dec_and_test(&ip->i_pincount))
                wake_up(&ip->i_ipin_wait);
-       }
 }
 
 /*
@@ -3338,7 +3311,6 @@ xfs_iflush_int(
 #ifdef XFS_TRANS_DEBUG
        int                     first;
 #endif
-       SPLDECL(s);
 
        ASSERT(ismrlocked(&ip->i_lock, MR_UPDATE|MR_ACCESS));
        ASSERT(issemalocked(&(ip->i_flock)));
@@ -3533,9 +3505,9 @@ xfs_iflush_int(
                iip->ili_logged = 1;
 
                ASSERT(sizeof(xfs_lsn_t) == 8); /* don't lock if it shrinks */
-               AIL_LOCK(mp,s);
+               spin_lock(&mp->m_ail_lock);
                iip->ili_flush_lsn = iip->ili_item.li_lsn;
-               AIL_UNLOCK(mp, s);
+               spin_unlock(&mp->m_ail_lock);
 
                /*
                 * Attach the function xfs_iflush_done to the inode's
@@ -3611,95 +3583,6 @@ xfs_iflush_all(
        XFS_MOUNT_IUNLOCK(mp);
 }
 
-/*
- * xfs_iaccess: check accessibility of inode for mode.
- */
-int
-xfs_iaccess(
-       xfs_inode_t     *ip,
-       mode_t          mode,
-       cred_t          *cr)
-{
-       int             error;
-       mode_t          orgmode = mode;
-       struct inode    *inode = vn_to_inode(XFS_ITOV(ip));
-
-       if (mode & S_IWUSR) {
-               umode_t         imode = inode->i_mode;
-
-               if (IS_RDONLY(inode) &&
-                   (S_ISREG(imode) || S_ISDIR(imode) || S_ISLNK(imode)))
-                       return XFS_ERROR(EROFS);
-
-               if (IS_IMMUTABLE(inode))
-                       return XFS_ERROR(EACCES);
-       }
-
-       /*
-        * If there's an Access Control List it's used instead of
-        * the mode bits.
-        */
-       if ((error = _ACL_XFS_IACCESS(ip, mode, cr)) != -1)
-               return error ? XFS_ERROR(error) : 0;
-
-       if (current_fsuid(cr) != ip->i_d.di_uid) {
-               mode >>= 3;
-               if (!in_group_p((gid_t)ip->i_d.di_gid))
-                       mode >>= 3;
-       }
-
-       /*
-        * If the DACs are ok we don't need any capability check.
-        */
-       if ((ip->i_d.di_mode & mode) == mode)
-               return 0;
-       /*
-        * Read/write DACs are always overridable.
-        * Executable DACs are overridable if at least one exec bit is set.
-        */
-       if (!(orgmode & S_IXUSR) ||
-           (inode->i_mode & S_IXUGO) || S_ISDIR(inode->i_mode))
-               if (capable_cred(cr, CAP_DAC_OVERRIDE))
-                       return 0;
-
-       if ((orgmode == S_IRUSR) ||
-           (S_ISDIR(inode->i_mode) && (!(orgmode & S_IWUSR)))) {
-               if (capable_cred(cr, CAP_DAC_READ_SEARCH))
-                       return 0;
-#ifdef NOISE
-               cmn_err(CE_NOTE, "Ick: mode=%o, orgmode=%o", mode, orgmode);
-#endif /* NOISE */
-               return XFS_ERROR(EACCES);
-       }
-       return XFS_ERROR(EACCES);
-}
-
-/*
- * xfs_iroundup: round up argument to next power of two
- */
-uint
-xfs_iroundup(
-       uint    v)
-{
-       int i;
-       uint m;
-
-       if ((v & (v - 1)) == 0)
-               return v;
-       ASSERT((v & 0x80000000) == 0);
-       if ((v & (v + 1)) == 0)
-               return v + 1;
-       for (i = 0, m = 1; i < 31; i++, m <<= 1) {
-               if (v & m)
-                       continue;
-               v |= m;
-               if ((v & (v + 1)) == 0)
-                       return v + 1;
-       }
-       ASSERT(0);
-       return( 0 );
-}
-
 #ifdef XFS_ILOCK_TRACE
 ktrace_t       *xfs_ilock_trace_buf;
 
@@ -4206,7 +4089,7 @@ xfs_iext_realloc_direct(
                        return;
                }
                if (!is_power_of_2(new_size)){
-                       rnew_size = xfs_iroundup(new_size);
+                       rnew_size = roundup_pow_of_two(new_size);
                }
                if (rnew_size != ifp->if_real_bytes) {
                        ifp->if_u1.if_extents =
@@ -4229,7 +4112,7 @@ xfs_iext_realloc_direct(
        else {
                new_size += ifp->if_bytes;
                if (!is_power_of_2(new_size)) {
-                       rnew_size = xfs_iroundup(new_size);
+                       rnew_size = roundup_pow_of_two(new_size);
                }
                xfs_iext_inline_to_direct(ifp, rnew_size);
        }
index e5aff929cc65effe4bbc0d5f25527c2a597e6b52..bfcd72cbaeea9f4e95b1892979d93768f8476d8a 100644 (file)
@@ -132,45 +132,6 @@ typedef struct dm_attrs_s {
        __uint16_t      da_pad;         /* DMIG extra padding */
 } dm_attrs_t;
 
-typedef struct xfs_iocore {
-       void                    *io_obj;        /* pointer to container
-                                                * inode or dcxvn structure */
-       struct xfs_mount        *io_mount;      /* fs mount struct ptr */
-#ifdef DEBUG
-       mrlock_t                *io_lock;       /* inode IO lock */
-       mrlock_t                *io_iolock;     /* inode IO lock */
-#endif
-
-       /* I/O state */
-       xfs_fsize_t             io_new_size;    /* sz when write completes */
-
-       /* Miscellaneous state. */
-       unsigned int            io_flags;       /* IO related flags */
-
-       /* DMAPI state */
-       dm_attrs_t              io_dmattrs;
-
-} xfs_iocore_t;
-
-#define        io_dmevmask     io_dmattrs.da_dmevmask
-#define        io_dmstate      io_dmattrs.da_dmstate
-
-#define XFS_IO_INODE(io)       ((xfs_inode_t *) ((io)->io_obj))
-#define XFS_IO_DCXVN(io)       ((dcxvn_t *) ((io)->io_obj))
-
-/*
- * Flags in the flags field
- */
-
-#define XFS_IOCORE_RT          0x1
-
-/*
- * xfs_iocore prototypes
- */
-
-extern void xfs_iocore_inode_init(struct xfs_inode *);
-extern void xfs_iocore_inode_reinit(struct xfs_inode *);
-
 /*
  * This is the xfs inode cluster structure.  This structure is used by
  * xfs_iflush to find inodes that share a cluster and can be flushed to disk at
@@ -181,7 +142,7 @@ typedef struct xfs_icluster {
        xfs_daddr_t             icl_blkno;      /* starting block number of
                                                 * the cluster */
        struct xfs_buf          *icl_buf;       /* the inode buffer */
-       lock_t                  icl_lock;       /* inode list lock */
+       spinlock_t              icl_lock;       /* inode list lock */
 } xfs_icluster_t;
 
 /*
@@ -283,9 +244,6 @@ typedef struct xfs_inode {
        struct xfs_inode        **i_refcache;   /* ptr to entry in ref cache */
        struct xfs_inode        *i_release;     /* inode to unref */
 #endif
-       /* I/O state */
-       xfs_iocore_t            i_iocore;       /* I/O core */
-
        /* Miscellaneous state. */
        unsigned short          i_flags;        /* see defined flags below */
        unsigned char           i_update_core;  /* timestamps/size is dirty */
@@ -298,9 +256,10 @@ typedef struct xfs_inode {
        struct hlist_node       i_cnode;        /* cluster link node */
 
        xfs_fsize_t             i_size;         /* in-memory size */
+       xfs_fsize_t             i_new_size;     /* size when write completes */
        atomic_t                i_iocount;      /* outstanding I/O count */
        /* Trace buffers per inode. */
-#ifdef XFS_VNODE_TRACE
+#ifdef XFS_INODE_TRACE
        struct ktrace           *i_trace;       /* general inode trace */
 #endif
 #ifdef XFS_BMAP_TRACE
@@ -382,17 +341,42 @@ xfs_iflags_test_and_clear(xfs_inode_t *ip, unsigned short flags)
 /*
  * Fork handling.
  */
-#define        XFS_IFORK_PTR(ip,w)             \
-       ((w) == XFS_DATA_FORK ? &(ip)->i_df : (ip)->i_afp)
-#define        XFS_IFORK_Q(ip)                 XFS_CFORK_Q(&(ip)->i_d)
-#define        XFS_IFORK_DSIZE(ip)             XFS_CFORK_DSIZE(&ip->i_d, ip->i_mount)
-#define        XFS_IFORK_ASIZE(ip)             XFS_CFORK_ASIZE(&ip->i_d, ip->i_mount)
-#define        XFS_IFORK_SIZE(ip,w)            XFS_CFORK_SIZE(&ip->i_d, ip->i_mount, w)
-#define        XFS_IFORK_FORMAT(ip,w)          XFS_CFORK_FORMAT(&ip->i_d, w)
-#define        XFS_IFORK_FMT_SET(ip,w,n)       XFS_CFORK_FMT_SET(&ip->i_d, w, n)
-#define        XFS_IFORK_NEXTENTS(ip,w)        XFS_CFORK_NEXTENTS(&ip->i_d, w)
-#define        XFS_IFORK_NEXT_SET(ip,w,n)      XFS_CFORK_NEXT_SET(&ip->i_d, w, n)
 
+#define XFS_IFORK_Q(ip)                        ((ip)->i_d.di_forkoff != 0)
+#define XFS_IFORK_BOFF(ip)             ((int)((ip)->i_d.di_forkoff << 3))
+
+#define XFS_IFORK_PTR(ip,w)            \
+       ((w) == XFS_DATA_FORK ? \
+               &(ip)->i_df : \
+               (ip)->i_afp)
+#define XFS_IFORK_DSIZE(ip) \
+       (XFS_IFORK_Q(ip) ? \
+               XFS_IFORK_BOFF(ip) : \
+               XFS_LITINO((ip)->i_mount))
+#define XFS_IFORK_ASIZE(ip) \
+       (XFS_IFORK_Q(ip) ? \
+               XFS_LITINO((ip)->i_mount) - XFS_IFORK_BOFF(ip) : \
+               0)
+#define XFS_IFORK_SIZE(ip,w) \
+       ((w) == XFS_DATA_FORK ? \
+               XFS_IFORK_DSIZE(ip) : \
+               XFS_IFORK_ASIZE(ip))
+#define XFS_IFORK_FORMAT(ip,w) \
+       ((w) == XFS_DATA_FORK ? \
+               (ip)->i_d.di_format : \
+               (ip)->i_d.di_aformat)
+#define XFS_IFORK_FMT_SET(ip,w,n) \
+       ((w) == XFS_DATA_FORK ? \
+               ((ip)->i_d.di_format = (n)) : \
+               ((ip)->i_d.di_aformat = (n)))
+#define XFS_IFORK_NEXTENTS(ip,w) \
+       ((w) == XFS_DATA_FORK ? \
+               (ip)->i_d.di_nextents : \
+               (ip)->i_d.di_anextents)
+#define XFS_IFORK_NEXT_SET(ip,w,n) \
+       ((w) == XFS_DATA_FORK ? \
+               ((ip)->i_d.di_nextents = (n)) : \
+               ((ip)->i_d.di_anextents = (n)))
 
 #ifdef __KERNEL__
 
@@ -509,7 +493,6 @@ void                xfs_ihash_init(struct xfs_mount *);
 void           xfs_ihash_free(struct xfs_mount *);
 xfs_inode_t    *xfs_inode_incore(struct xfs_mount *, xfs_ino_t,
                                  struct xfs_trans *);
-void            xfs_inode_lock_init(xfs_inode_t *, bhv_vnode_t *);
 int            xfs_iget(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
                         uint, uint, xfs_inode_t **, xfs_daddr_t);
 void           xfs_iput(xfs_inode_t *, uint);
@@ -545,7 +528,7 @@ void                xfs_dinode_to_disk(struct xfs_dinode_core *,
                                   struct xfs_icdinode *);
 
 uint           xfs_ip2xflags(struct xfs_inode *);
-uint           xfs_dic2xflags(struct xfs_dinode_core *);
+uint           xfs_dic2xflags(struct xfs_dinode *);
 int            xfs_ifree(struct xfs_trans *, xfs_inode_t *,
                           struct xfs_bmap_free *);
 int            xfs_itruncate_start(xfs_inode_t *, uint, xfs_fsize_t);
@@ -567,13 +550,12 @@ void              xfs_iunpin(xfs_inode_t *);
 int            xfs_iextents_copy(xfs_inode_t *, xfs_bmbt_rec_t *, int);
 int            xfs_iflush(xfs_inode_t *, uint);
 void           xfs_iflush_all(struct xfs_mount *);
-int            xfs_iaccess(xfs_inode_t *, mode_t, cred_t *);
-uint           xfs_iroundup(uint);
 void           xfs_ichgtime(xfs_inode_t *, int);
 xfs_fsize_t    xfs_file_last_byte(xfs_inode_t *);
 void           xfs_lock_inodes(xfs_inode_t **, int, int, uint);
 
 void           xfs_synchronize_atime(xfs_inode_t *);
+void           xfs_mark_inode_dirty_sync(xfs_inode_t *);
 
 xfs_bmbt_rec_host_t *xfs_iext_get_ext(xfs_ifork_t *, xfs_extnum_t);
 void           xfs_iext_insert(xfs_ifork_t *, xfs_extnum_t, xfs_extnum_t,
index 565d470a6b4a074e1b17bd422eebd53005e2c146..034ca7202295dc143d4e4563968c610fd8041242 100644 (file)
@@ -274,6 +274,11 @@ xfs_inode_item_format(
         */
        xfs_synchronize_atime(ip);
 
+       /*
+        * make sure the linux inode is dirty
+        */
+       xfs_mark_inode_dirty_sync(ip);
+
        vecp->i_addr = (xfs_caddr_t)&ip->i_d;
        vecp->i_len  = sizeof(xfs_dinode_core_t);
        XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_ICORE);
@@ -615,7 +620,7 @@ xfs_inode_item_trylock(
                        return XFS_ITEM_PUSHBUF;
                } else {
                        /*
-                        * We hold the AIL_LOCK, so we must specify the
+                        * We hold the AIL lock, so we must specify the
                         * NONOTIFY flag so that we won't double trip.
                         */
                        xfs_iunlock(ip, XFS_ILOCK_SHARED|XFS_IUNLOCK_NONOTIFY);
@@ -749,7 +754,7 @@ xfs_inode_item_committed(
  * marked delayed write. If that's the case, we'll initiate a bawrite on that
  * buffer to expedite the process.
  *
- * We aren't holding the AIL_LOCK (or the flush lock) when this gets called,
+ * We aren't holding the AIL lock (or the flush lock) when this gets called,
  * so it is inherently race-y.
  */
 STATIC void
@@ -792,7 +797,7 @@ xfs_inode_item_pushbuf(
                if (XFS_BUF_ISDELAYWRITE(bp)) {
                        /*
                         * We were racing with iflush because we don't hold
-                        * the AIL_LOCK or the flush lock. However, at this point,
+                        * the AIL lock or the flush lock. However, at this point,
                         * we have the buffer, and we know that it's dirty.
                         * So, it's possible that iflush raced with us, and
                         * this item is already taken off the AIL.
@@ -968,7 +973,6 @@ xfs_iflush_done(
        xfs_inode_log_item_t    *iip)
 {
        xfs_inode_t     *ip;
-       SPLDECL(s);
 
        ip = iip->ili_inode;
 
@@ -983,15 +987,15 @@ xfs_iflush_done(
         */
        if (iip->ili_logged &&
            (iip->ili_item.li_lsn == iip->ili_flush_lsn)) {
-               AIL_LOCK(ip->i_mount, s);
+               spin_lock(&ip->i_mount->m_ail_lock);
                if (iip->ili_item.li_lsn == iip->ili_flush_lsn) {
                        /*
                         * xfs_trans_delete_ail() drops the AIL lock.
                         */
                        xfs_trans_delete_ail(ip->i_mount,
-                                            (xfs_log_item_t*)iip, s);
+                                            (xfs_log_item_t*)iip);
                } else {
-                       AIL_UNLOCK(ip->i_mount, s);
+                       spin_unlock(&ip->i_mount->m_ail_lock);
                }
        }
 
@@ -1025,21 +1029,19 @@ xfs_iflush_abort(
 {
        xfs_inode_log_item_t    *iip;
        xfs_mount_t             *mp;
-       SPLDECL(s);
 
        iip = ip->i_itemp;
        mp = ip->i_mount;
        if (iip) {
                if (iip->ili_item.li_flags & XFS_LI_IN_AIL) {
-                       AIL_LOCK(mp, s);
+                       spin_lock(&mp->m_ail_lock);
                        if (iip->ili_item.li_flags & XFS_LI_IN_AIL) {
                                /*
                                 * xfs_trans_delete_ail() drops the AIL lock.
                                 */
-                               xfs_trans_delete_ail(mp, (xfs_log_item_t *)iip,
-                                       s);
+                               xfs_trans_delete_ail(mp, (xfs_log_item_t *)iip);
                        } else
-                               AIL_UNLOCK(mp, s);
+                               spin_unlock(&mp->m_ail_lock);
                }
                iip->ili_logged = 0;
                /*
diff --git a/fs/xfs/xfs_iocore.c b/fs/xfs/xfs_iocore.c
deleted file mode 100644 (file)
index b27b5d5..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-#include "xfs.h"
-#include "xfs_fs.h"
-#include "xfs_types.h"
-#include "xfs_bit.h"
-#include "xfs_log.h"
-#include "xfs_inum.h"
-#include "xfs_trans.h"
-#include "xfs_sb.h"
-#include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dfrag.h"
-#include "xfs_dmapi.h"
-#include "xfs_mount.h"
-#include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
-#include "xfs_dinode.h"
-#include "xfs_inode.h"
-#include "xfs_inode_item.h"
-#include "xfs_itable.h"
-#include "xfs_btree.h"
-#include "xfs_alloc.h"
-#include "xfs_ialloc.h"
-#include "xfs_bmap.h"
-#include "xfs_error.h"
-#include "xfs_rw.h"
-#include "xfs_quota.h"
-#include "xfs_trans_space.h"
-#include "xfs_iomap.h"
-
-
-STATIC xfs_fsize_t
-xfs_size_fn(
-       xfs_inode_t             *ip)
-{
-       return XFS_ISIZE(ip);
-}
-
-STATIC int
-xfs_ioinit(
-       struct xfs_mount        *mp,
-       struct xfs_mount_args   *mntargs,
-       int                     flags)
-{
-       return xfs_mountfs(mp, flags);
-}
-
-xfs_ioops_t    xfs_iocore_xfs = {
-       .xfs_ioinit             = (xfs_ioinit_t) xfs_ioinit,
-       .xfs_bmapi_func         = (xfs_bmapi_t) xfs_bmapi,
-       .xfs_bunmapi_func       = (xfs_bunmapi_t) xfs_bunmapi,
-       .xfs_bmap_eof_func      = (xfs_bmap_eof_t) xfs_bmap_eof,
-       .xfs_iomap_write_direct =
-                       (xfs_iomap_write_direct_t) xfs_iomap_write_direct,
-       .xfs_iomap_write_delay =
-                       (xfs_iomap_write_delay_t) xfs_iomap_write_delay,
-       .xfs_iomap_write_allocate =
-                       (xfs_iomap_write_allocate_t) xfs_iomap_write_allocate,
-       .xfs_iomap_write_unwritten =
-                       (xfs_iomap_write_unwritten_t) xfs_iomap_write_unwritten,
-       .xfs_ilock              = (xfs_lock_t) xfs_ilock,
-       .xfs_lck_map_shared     = (xfs_lck_map_shared_t) xfs_ilock_map_shared,
-       .xfs_ilock_demote       = (xfs_lock_demote_t) xfs_ilock_demote,
-       .xfs_ilock_nowait       = (xfs_lock_nowait_t) xfs_ilock_nowait,
-       .xfs_unlock             = (xfs_unlk_t) xfs_iunlock,
-       .xfs_size_func          = (xfs_size_t) xfs_size_fn,
-       .xfs_iodone             = (xfs_iodone_t) fs_noerr,
-       .xfs_swap_extents_func  = (xfs_swap_extents_t) xfs_swap_extents,
-};
-
-void
-xfs_iocore_inode_reinit(
-       xfs_inode_t     *ip)
-{
-       xfs_iocore_t    *io = &ip->i_iocore;
-
-       io->io_flags = 0;
-       if (ip->i_d.di_flags & XFS_DIFLAG_REALTIME)
-               io->io_flags |= XFS_IOCORE_RT;
-       io->io_dmevmask = ip->i_d.di_dmevmask;
-       io->io_dmstate = ip->i_d.di_dmstate;
-}
-
-void
-xfs_iocore_inode_init(
-       xfs_inode_t     *ip)
-{
-       xfs_iocore_t    *io = &ip->i_iocore;
-       xfs_mount_t     *mp = ip->i_mount;
-
-       io->io_mount = mp;
-#ifdef DEBUG
-       io->io_lock = &ip->i_lock;
-       io->io_iolock = &ip->i_iolock;
-#endif
-
-       io->io_obj = (void *)ip;
-
-       xfs_iocore_inode_reinit(ip);
-}
index 72786e356d56ebba6e1f6455cf9f471fd52745fa..fde37f87d52faa9a87674b0d95a9f813a2330820 100644 (file)
 void
 xfs_iomap_enter_trace(
        int             tag,
-       xfs_iocore_t    *io,
+       xfs_inode_t     *ip,
        xfs_off_t       offset,
        ssize_t         count)
 {
-       xfs_inode_t     *ip = XFS_IO_INODE(io);
-
        if (!ip->i_rwtrace)
                return;
 
@@ -70,8 +68,8 @@ xfs_iomap_enter_trace(
                (void *)((unsigned long)((offset >> 32) & 0xffffffff)),
                (void *)((unsigned long)(offset & 0xffffffff)),
                (void *)((unsigned long)count),
-               (void *)((unsigned long)((io->io_new_size >> 32) & 0xffffffff)),
-               (void *)((unsigned long)(io->io_new_size & 0xffffffff)),
+               (void *)((unsigned long)((ip->i_new_size >> 32) & 0xffffffff)),
+               (void *)((unsigned long)(ip->i_new_size & 0xffffffff)),
                (void *)((unsigned long)current_pid()),
                (void *)NULL,
                (void *)NULL,
@@ -84,15 +82,13 @@ xfs_iomap_enter_trace(
 void
 xfs_iomap_map_trace(
        int             tag,
-       xfs_iocore_t    *io,
+       xfs_inode_t     *ip,
        xfs_off_t       offset,
        ssize_t         count,
        xfs_iomap_t     *iomapp,
        xfs_bmbt_irec_t *imapp,
        int             flags)
 {
-       xfs_inode_t     *ip = XFS_IO_INODE(io);
-
        if (!ip->i_rwtrace)
                return;
 
@@ -126,7 +122,7 @@ xfs_iomap_map_trace(
 
 STATIC int
 xfs_imap_to_bmap(
-       xfs_iocore_t    *io,
+       xfs_inode_t     *ip,
        xfs_off_t       offset,
        xfs_bmbt_irec_t *imap,
        xfs_iomap_t     *iomapp,
@@ -134,11 +130,10 @@ xfs_imap_to_bmap(
        int             iomaps,                 /* Number of iomap entries */
        int             flags)
 {
-       xfs_mount_t     *mp;
+       xfs_mount_t     *mp = ip->i_mount;
        int             pbm;
        xfs_fsblock_t   start_block;
 
-       mp = io->io_mount;
 
        for (pbm = 0; imaps && pbm < iomaps; imaps--, iomapp++, imap++, pbm++) {
                iomapp->iomap_offset = XFS_FSB_TO_B(mp, imap->br_startoff);
@@ -146,7 +141,7 @@ xfs_imap_to_bmap(
                iomapp->iomap_bsize = XFS_FSB_TO_B(mp, imap->br_blockcount);
                iomapp->iomap_flags = flags;
 
-               if (io->io_flags & XFS_IOCORE_RT) {
+               if (XFS_IS_REALTIME_INODE(ip)) {
                        iomapp->iomap_flags |= IOMAP_REALTIME;
                        iomapp->iomap_target = mp->m_rtdev_targp;
                } else {
@@ -160,7 +155,7 @@ xfs_imap_to_bmap(
                        iomapp->iomap_bn = IOMAP_DADDR_NULL;
                        iomapp->iomap_flags |= IOMAP_DELAY;
                } else {
-                       iomapp->iomap_bn = XFS_FSB_TO_DB_IO(io, start_block);
+                       iomapp->iomap_bn = XFS_FSB_TO_DB(ip, start_block);
                        if (ISUNWRITTEN(imap))
                                iomapp->iomap_flags |= IOMAP_UNWRITTEN;
                }
@@ -172,14 +167,14 @@ xfs_imap_to_bmap(
 
 int
 xfs_iomap(
-       xfs_iocore_t    *io,
+       xfs_inode_t     *ip,
        xfs_off_t       offset,
        ssize_t         count,
        int             flags,
        xfs_iomap_t     *iomapp,
        int             *niomaps)
 {
-       xfs_mount_t     *mp = io->io_mount;
+       xfs_mount_t     *mp = ip->i_mount;
        xfs_fileoff_t   offset_fsb, end_fsb;
        int             error = 0;
        int             lockmode = 0;
@@ -188,45 +183,37 @@ xfs_iomap(
        int             bmapi_flags = 0;
        int             iomap_flags = 0;
 
+       ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFREG);
+
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
 
-       switch (flags &
-               (BMAPI_READ | BMAPI_WRITE | BMAPI_ALLOCATE |
-                BMAPI_UNWRITTEN | BMAPI_DEVICE)) {
+       switch (flags & (BMAPI_READ | BMAPI_WRITE | BMAPI_ALLOCATE)) {
        case BMAPI_READ:
-               xfs_iomap_enter_trace(XFS_IOMAP_READ_ENTER, io, offset, count);
-               lockmode = XFS_LCK_MAP_SHARED(mp, io);
+               xfs_iomap_enter_trace(XFS_IOMAP_READ_ENTER, ip, offset, count);
+               lockmode = xfs_ilock_map_shared(ip);
                bmapi_flags = XFS_BMAPI_ENTIRE;
                break;
        case BMAPI_WRITE:
-               xfs_iomap_enter_trace(XFS_IOMAP_WRITE_ENTER, io, offset, count);
+               xfs_iomap_enter_trace(XFS_IOMAP_WRITE_ENTER, ip, offset, count);
                lockmode = XFS_ILOCK_EXCL|XFS_EXTSIZE_WR;
                if (flags & BMAPI_IGNSTATE)
                        bmapi_flags |= XFS_BMAPI_IGSTATE|XFS_BMAPI_ENTIRE;
-               XFS_ILOCK(mp, io, lockmode);
+               xfs_ilock(ip, lockmode);
                break;
        case BMAPI_ALLOCATE:
-               xfs_iomap_enter_trace(XFS_IOMAP_ALLOC_ENTER, io, offset, count);
+               xfs_iomap_enter_trace(XFS_IOMAP_ALLOC_ENTER, ip, offset, count);
                lockmode = XFS_ILOCK_SHARED|XFS_EXTSIZE_RD;
                bmapi_flags = XFS_BMAPI_ENTIRE;
+
                /* Attempt non-blocking lock */
                if (flags & BMAPI_TRYLOCK) {
-                       if (!XFS_ILOCK_NOWAIT(mp, io, lockmode))
+                       if (!xfs_ilock_nowait(ip, lockmode))
                                return XFS_ERROR(EAGAIN);
                } else {
-                       XFS_ILOCK(mp, io, lockmode);
+                       xfs_ilock(ip, lockmode);
                }
                break;
-       case BMAPI_UNWRITTEN:
-               goto phase2;
-       case BMAPI_DEVICE:
-               lockmode = XFS_LCK_MAP_SHARED(mp, io);
-               iomapp->iomap_target = io->io_flags & XFS_IOCORE_RT ?
-                       mp->m_rtdev_targp : mp->m_ddev_targp;
-               error = 0;
-               *niomaps = 1;
-               goto out;
        default:
                BUG();
        }
@@ -237,7 +224,7 @@ xfs_iomap(
        end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count);
        offset_fsb = XFS_B_TO_FSBT(mp, offset);
 
-       error = XFS_BMAPI(mp, NULL, io, offset_fsb,
+       error = xfs_bmapi(NULL, ip, offset_fsb,
                        (xfs_filblks_t)(end_fsb - offset_fsb),
                        bmapi_flags,  NULL, 0, &imap,
                        &nimaps, NULL, NULL);
@@ -245,54 +232,48 @@ xfs_iomap(
        if (error)
                goto out;
 
-phase2:
-       switch (flags & (BMAPI_WRITE|BMAPI_ALLOCATE|BMAPI_UNWRITTEN)) {
+       switch (flags & (BMAPI_WRITE|BMAPI_ALLOCATE)) {
        case BMAPI_WRITE:
                /* If we found an extent, return it */
                if (nimaps &&
                    (imap.br_startblock != HOLESTARTBLOCK) &&
                    (imap.br_startblock != DELAYSTARTBLOCK)) {
-                       xfs_iomap_map_trace(XFS_IOMAP_WRITE_MAP, io,
+                       xfs_iomap_map_trace(XFS_IOMAP_WRITE_MAP, ip,
                                        offset, count, iomapp, &imap, flags);
                        break;
                }
 
                if (flags & (BMAPI_DIRECT|BMAPI_MMAP)) {
-                       error = XFS_IOMAP_WRITE_DIRECT(mp, io, offset,
-                                       count, flags, &imap, &nimaps, nimaps);
+                       error = xfs_iomap_write_direct(ip, offset, count, flags,
+                                                      &imap, &nimaps, nimaps);
                } else {
-                       error = XFS_IOMAP_WRITE_DELAY(mp, io, offset, count,
-                                       flags, &imap, &nimaps);
+                       error = xfs_iomap_write_delay(ip, offset, count, flags,
+                                                     &imap, &nimaps);
                }
                if (!error) {
-                       xfs_iomap_map_trace(XFS_IOMAP_ALLOC_MAP, io,
+                       xfs_iomap_map_trace(XFS_IOMAP_ALLOC_MAP, ip,
                                        offset, count, iomapp, &imap, flags);
                }
                iomap_flags = IOMAP_NEW;
                break;
        case BMAPI_ALLOCATE:
                /* If we found an extent, return it */
-               XFS_IUNLOCK(mp, io, lockmode);
+               xfs_iunlock(ip, lockmode);
                lockmode = 0;
 
                if (nimaps && !ISNULLSTARTBLOCK(imap.br_startblock)) {
-                       xfs_iomap_map_trace(XFS_IOMAP_WRITE_MAP, io,
+                       xfs_iomap_map_trace(XFS_IOMAP_WRITE_MAP, ip,
                                        offset, count, iomapp, &imap, flags);
                        break;
                }
 
-               error = XFS_IOMAP_WRITE_ALLOCATE(mp, io, offset, count,
+               error = xfs_iomap_write_allocate(ip, offset, count,
                                                 &imap, &nimaps);
                break;
-       case BMAPI_UNWRITTEN:
-               lockmode = 0;
-               error = XFS_IOMAP_WRITE_UNWRITTEN(mp, io, offset, count);
-               nimaps = 0;
-               break;
        }
 
        if (nimaps) {
-               *niomaps = xfs_imap_to_bmap(io, offset, &imap,
+               *niomaps = xfs_imap_to_bmap(ip, offset, &imap,
                                            iomapp, nimaps, *niomaps, iomap_flags);
        } else if (niomaps) {
                *niomaps = 0;
@@ -300,14 +281,15 @@ phase2:
 
 out:
        if (lockmode)
-               XFS_IUNLOCK(mp, io, lockmode);
+               xfs_iunlock(ip, lockmode);
        return XFS_ERROR(error);
 }
 
+
 STATIC int
 xfs_iomap_eof_align_last_fsb(
        xfs_mount_t     *mp,
-       xfs_iocore_t    *io,
+       xfs_inode_t     *ip,
        xfs_fsize_t     isize,
        xfs_extlen_t    extsize,
        xfs_fileoff_t   *last_fsb)
@@ -316,7 +298,7 @@ xfs_iomap_eof_align_last_fsb(
        xfs_extlen_t    align;
        int             eof, error;
 
-       if (io->io_flags & XFS_IOCORE_RT)
+       if (XFS_IS_REALTIME_INODE(ip))
                ;
        /*
         * If mounted with the "-o swalloc" option, roundup the allocation
@@ -347,7 +329,7 @@ xfs_iomap_eof_align_last_fsb(
        }
 
        if (new_last_fsb) {
-               error = XFS_BMAP_EOF(mp, io, new_last_fsb, XFS_DATA_FORK, &eof);
+               error = xfs_bmap_eof(ip, new_last_fsb, XFS_DATA_FORK, &eof);
                if (error)
                        return error;
                if (eof)
@@ -416,7 +398,6 @@ xfs_iomap_write_direct(
        int             found)
 {
        xfs_mount_t     *mp = ip->i_mount;
-       xfs_iocore_t    *io = &ip->i_iocore;
        xfs_fileoff_t   offset_fsb;
        xfs_fileoff_t   last_fsb;
        xfs_filblks_t   count_fsb, resaligned;
@@ -446,13 +427,13 @@ xfs_iomap_write_direct(
        extsz = xfs_get_extsz_hint(ip);
 
        isize = ip->i_size;
-       if (io->io_new_size > isize)
-               isize = io->io_new_size;
+       if (ip->i_new_size > isize)
+               isize = ip->i_new_size;
 
        offset_fsb = XFS_B_TO_FSBT(mp, offset);
        last_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count)));
        if ((offset + count) > isize) {
-               error = xfs_iomap_eof_align_last_fsb(mp, io, isize, extsz,
+               error = xfs_iomap_eof_align_last_fsb(mp, ip, isize, extsz,
                                                        &last_fsb);
                if (error)
                        goto error_out;
@@ -519,7 +500,7 @@ xfs_iomap_write_direct(
         */
        XFS_BMAP_INIT(&free_list, &firstfsb);
        nimaps = 1;
-       error = XFS_BMAPI(mp, tp, io, offset_fsb, count_fsb, bmapi_flag,
+       error = xfs_bmapi(tp, ip, offset_fsb, count_fsb, bmapi_flag,
                &firstfsb, 0, &imap, &nimaps, &free_list, NULL);
        if (error)
                goto error0;
@@ -542,7 +523,8 @@ xfs_iomap_write_direct(
                goto error_out;
        }
 
-       if (unlikely(!imap.br_startblock && !(io->io_flags & XFS_IOCORE_RT))) {
+       if (unlikely(!imap.br_startblock &&
+                    !(XFS_IS_REALTIME_INODE(ip)))) {
                error = xfs_cmn_err_fsblock_zero(ip, &imap);
                goto error_out;
        }
@@ -577,7 +559,7 @@ error_out:
 STATIC int
 xfs_iomap_eof_want_preallocate(
        xfs_mount_t     *mp,
-       xfs_iocore_t    *io,
+       xfs_inode_t     *ip,
        xfs_fsize_t     isize,
        xfs_off_t       offset,
        size_t          count,
@@ -604,7 +586,7 @@ xfs_iomap_eof_want_preallocate(
        while (count_fsb > 0) {
                imaps = nimaps;
                firstblock = NULLFSBLOCK;
-               error = XFS_BMAPI(mp, NULL, io, start_fsb, count_fsb, 0,
+               error = xfs_bmapi(NULL, ip, start_fsb, count_fsb, 0,
                                  &firstblock, 0, imap, &imaps, NULL, NULL);
                if (error)
                        return error;
@@ -630,7 +612,6 @@ xfs_iomap_write_delay(
        int             *nmaps)
 {
        xfs_mount_t     *mp = ip->i_mount;
-       xfs_iocore_t    *io = &ip->i_iocore;
        xfs_fileoff_t   offset_fsb;
        xfs_fileoff_t   last_fsb;
        xfs_off_t       aligned_offset;
@@ -658,10 +639,10 @@ xfs_iomap_write_delay(
 
 retry:
        isize = ip->i_size;
-       if (io->io_new_size > isize)
-               isize = io->io_new_size;
+       if (ip->i_new_size > isize)
+               isize = ip->i_new_size;
 
-       error = xfs_iomap_eof_want_preallocate(mp, io, isize, offset, count,
+       error = xfs_iomap_eof_want_preallocate(mp, ip, isize, offset, count,
                                ioflag, imap, XFS_WRITE_IMAPS, &prealloc);
        if (error)
                return error;
@@ -675,7 +656,7 @@ retry:
        }
 
        if (prealloc || extsz) {
-               error = xfs_iomap_eof_align_last_fsb(mp, io, isize, extsz,
+               error = xfs_iomap_eof_align_last_fsb(mp, ip, isize, extsz,
                                                        &last_fsb);
                if (error)
                        return error;
@@ -683,7 +664,7 @@ retry:
 
        nimaps = XFS_WRITE_IMAPS;
        firstblock = NULLFSBLOCK;
-       error = XFS_BMAPI(mp, NULL, io, offset_fsb,
+       error = xfs_bmapi(NULL, ip, offset_fsb,
                          (xfs_filblks_t)(last_fsb - offset_fsb),
                          XFS_BMAPI_DELAY | XFS_BMAPI_WRITE |
                          XFS_BMAPI_ENTIRE, &firstblock, 1, imap,
@@ -697,7 +678,7 @@ retry:
         */
        if (nimaps == 0) {
                xfs_iomap_enter_trace(XFS_IOMAP_WRITE_NOSPACE,
-                                       io, offset, count);
+                                       ip, offset, count);
                if (xfs_flush_space(ip, &fsynced, &ioflag))
                        return XFS_ERROR(ENOSPC);
 
@@ -705,7 +686,8 @@ retry:
                goto retry;
        }
 
-       if (unlikely(!imap[0].br_startblock && !(io->io_flags & XFS_IOCORE_RT)))
+       if (unlikely(!imap[0].br_startblock &&
+                    !(XFS_IS_REALTIME_INODE(ip))))
                return xfs_cmn_err_fsblock_zero(ip, &imap[0]);
 
        *ret_imap = imap[0];
@@ -720,6 +702,9 @@ retry:
  * the originating callers request.
  *
  * Called without a lock on the inode.
+ *
+ * We no longer bother to look at the incoming map - all we have to
+ * guarantee is that whatever we allocate fills the required range.
  */
 int
 xfs_iomap_write_allocate(
@@ -730,15 +715,14 @@ xfs_iomap_write_allocate(
        int             *retmap)
 {
        xfs_mount_t     *mp = ip->i_mount;
-       xfs_iocore_t    *io = &ip->i_iocore;
        xfs_fileoff_t   offset_fsb, last_block;
        xfs_fileoff_t   end_fsb, map_start_fsb;
        xfs_fsblock_t   first_block;
        xfs_bmap_free_t free_list;
        xfs_filblks_t   count_fsb;
-       xfs_bmbt_irec_t imap[XFS_STRAT_WRITE_IMAPS];
+       xfs_bmbt_irec_t imap;
        xfs_trans_t     *tp;
-       int             i, nimaps, committed;
+       int             nimaps, committed;
        int             error = 0;
        int             nres;
 
@@ -785,13 +769,38 @@ xfs_iomap_write_allocate(
 
                        XFS_BMAP_INIT(&free_list, &first_block);
 
-                       nimaps = XFS_STRAT_WRITE_IMAPS;
                        /*
-                        * Ensure we don't go beyond eof - it is possible
-                        * the extents changed since we did the read call,
-                        * we dropped the ilock in the interim.
+                        * it is possible that the extents have changed since
+                        * we did the read call as we dropped the ilock for a
+                        * while. We have to be careful about truncates or hole
+                        * punchs here - we are not allowed to allocate
+                        * non-delalloc blocks here.
+                        *
+                        * The only protection against truncation is the pages
+                        * for the range we are being asked to convert are
+                        * locked and hence a truncate will block on them
+                        * first.
+                        *
+                        * As a result, if we go beyond the range we really
+                        * need and hit an delalloc extent boundary followed by
+                        * a hole while we have excess blocks in the map, we
+                        * will fill the hole incorrectly and overrun the
+                        * transaction reservation.
+                        *
+                        * Using a single map prevents this as we are forced to
+                        * check each map we look for overlap with the desired
+                        * range and abort as soon as we find it. Also, given
+                        * that we only return a single map, having one beyond
+                        * what we can return is probably a bit silly.
+                        *
+                        * We also need to check that we don't go beyond EOF;
+                        * this is a truncate optimisation as a truncate sets
+                        * the new file size before block on the pages we
+                        * currently have locked under writeback. Because they
+                        * are about to be tossed, we don't need to write them
+                        * back....
                         */
-
+                       nimaps = 1;
                        end_fsb = XFS_B_TO_FSB(mp, ip->i_size);
                        xfs_bmap_last_offset(NULL, ip, &last_block,
                                XFS_DATA_FORK);
@@ -805,9 +814,9 @@ xfs_iomap_write_allocate(
                        }
 
                        /* Go get the actual blocks */
-                       error = XFS_BMAPI(mp, tp, io, map_start_fsb, count_fsb,
+                       error = xfs_bmapi(tp, ip, map_start_fsb, count_fsb,
                                        XFS_BMAPI_WRITE, &first_block, 1,
-                                       imap, &nimaps, &free_list, NULL);
+                                       &imap, &nimaps, &free_list, NULL);
                        if (error)
                                goto trans_cancel;
 
@@ -826,27 +835,24 @@ xfs_iomap_write_allocate(
                 * See if we were able to allocate an extent that
                 * covers at least part of the callers request
                 */
-               for (i = 0; i < nimaps; i++) {
-                       if (unlikely(!imap[i].br_startblock &&
-                                    !(io->io_flags & XFS_IOCORE_RT)))
-                               return xfs_cmn_err_fsblock_zero(ip, &imap[i]);
-                       if ((offset_fsb >= imap[i].br_startoff) &&
-                           (offset_fsb < (imap[i].br_startoff +
-                                          imap[i].br_blockcount))) {
-                               *map = imap[i];
-                               *retmap = 1;
-                               XFS_STATS_INC(xs_xstrat_quick);
-                               return 0;
-                       }
-                       count_fsb -= imap[i].br_blockcount;
+               if (unlikely(!imap.br_startblock &&
+                            XFS_IS_REALTIME_INODE(ip)))
+                       return xfs_cmn_err_fsblock_zero(ip, &imap);
+               if ((offset_fsb >= imap.br_startoff) &&
+                   (offset_fsb < (imap.br_startoff +
+                                  imap.br_blockcount))) {
+                       *map = imap;
+                       *retmap = 1;
+                       XFS_STATS_INC(xs_xstrat_quick);
+                       return 0;
                }
 
-               /* So far we have not mapped the requested part of the
+               /*
+                * So far we have not mapped the requested part of the
                 * file, just surrounding data, try again.
                 */
-               nimaps--;
-               map_start_fsb = imap[nimaps].br_startoff +
-                               imap[nimaps].br_blockcount;
+               count_fsb -= imap.br_blockcount;
+               map_start_fsb = imap.br_startoff + imap.br_blockcount;
        }
 
 trans_cancel:
@@ -864,7 +870,6 @@ xfs_iomap_write_unwritten(
        size_t          count)
 {
        xfs_mount_t     *mp = ip->i_mount;
-       xfs_iocore_t    *io = &ip->i_iocore;
        xfs_fileoff_t   offset_fsb;
        xfs_filblks_t   count_fsb;
        xfs_filblks_t   numblks_fsb;
@@ -877,8 +882,7 @@ xfs_iomap_write_unwritten(
        int             committed;
        int             error;
 
-       xfs_iomap_enter_trace(XFS_IOMAP_UNWRITTEN,
-                               &ip->i_iocore, offset, count);
+       xfs_iomap_enter_trace(XFS_IOMAP_UNWRITTEN, ip, offset, count);
 
        offset_fsb = XFS_B_TO_FSBT(mp, offset);
        count_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count);
@@ -912,7 +916,7 @@ xfs_iomap_write_unwritten(
                 */
                XFS_BMAP_INIT(&free_list, &firstfsb);
                nimaps = 1;
-               error = XFS_BMAPI(mp, tp, io, offset_fsb, count_fsb,
+               error = xfs_bmapi(tp, ip, offset_fsb, count_fsb,
                                  XFS_BMAPI_WRITE|XFS_BMAPI_CONVERT, &firstfsb,
                                  1, &imap, &nimaps, &free_list, NULL);
                if (error)
@@ -928,7 +932,7 @@ xfs_iomap_write_unwritten(
                        return XFS_ERROR(error);
 
                if (unlikely(!imap.br_startblock &&
-                            !(io->io_flags & XFS_IOCORE_RT)))
+                            !(XFS_IS_REALTIME_INODE(ip))))
                        return xfs_cmn_err_fsblock_zero(ip, &imap);
 
                if ((numblks_fsb = imap.br_blockcount) == 0) {
index f5c09887fe93647c6db79db7fa18531688c8c347..ee1a0c134cc274479a8da663bca33f1e9745d38f 100644 (file)
@@ -36,14 +36,12 @@ typedef enum {
        BMAPI_READ = (1 << 0),          /* read extents */
        BMAPI_WRITE = (1 << 1),         /* create extents */
        BMAPI_ALLOCATE = (1 << 2),      /* delayed allocate to real extents */
-       BMAPI_UNWRITTEN  = (1 << 3),    /* unwritten extents to real extents */
        /* modifiers */
        BMAPI_IGNSTATE = (1 << 4),      /* ignore unwritten state on read */
        BMAPI_DIRECT = (1 << 5),        /* direct instead of buffered write */
        BMAPI_MMAP = (1 << 6),          /* allocate for mmap write */
        BMAPI_SYNC = (1 << 7),          /* sync write to flush delalloc space */
        BMAPI_TRYLOCK = (1 << 8),       /* non-blocking request */
-       BMAPI_DEVICE = (1 << 9),        /* we only want to know the device */
 } bmapi_flags_t;
 
 
@@ -73,11 +71,10 @@ typedef struct xfs_iomap {
        iomap_flags_t           iomap_flags;
 } xfs_iomap_t;
 
-struct xfs_iocore;
 struct xfs_inode;
 struct xfs_bmbt_irec;
 
-extern int xfs_iomap(struct xfs_iocore *, xfs_off_t, ssize_t, int,
+extern int xfs_iomap(struct xfs_inode *, xfs_off_t, ssize_t, int,
                     struct xfs_iomap *, int *);
 extern int xfs_iomap_write_direct(struct xfs_inode *, xfs_off_t, size_t,
                                  int, struct xfs_bmbt_irec *, int *, int);
index 9fc4c288652980e4d81c2da25fc5470f13d8b664..658aab6b1bbfc193a9276d33bd002f4a1586dce7 100644 (file)
@@ -170,7 +170,7 @@ xfs_bulkstat_one_dinode(
        buf->bs_mtime.tv_nsec = be32_to_cpu(dic->di_mtime.t_nsec);
        buf->bs_ctime.tv_sec = be32_to_cpu(dic->di_ctime.t_sec);
        buf->bs_ctime.tv_nsec = be32_to_cpu(dic->di_ctime.t_nsec);
-       buf->bs_xflags = xfs_dic2xflags(dic);
+       buf->bs_xflags = xfs_dic2xflags(dip);
        buf->bs_extsize = be32_to_cpu(dic->di_extsize) << mp->m_sb.sb_blocklog;
        buf->bs_extents = be32_to_cpu(dic->di_nextents);
        buf->bs_gen = be32_to_cpu(dic->di_gen);
@@ -291,7 +291,7 @@ xfs_bulkstat_use_dinode(
        dip = (xfs_dinode_t *)
                        xfs_buf_offset(bp, clustidx << mp->m_sb.sb_inodelog);
        /*
-        * Check the buffer containing the on-disk inode for di_nlink == 0.
+        * Check the buffer containing the on-disk inode for di_mode == 0.
         * This is to prevent xfs_bulkstat from picking up just reclaimed
         * inodes that have their in-core state initialized but not flushed
         * to disk yet. This is a temporary hack that would require a proper
@@ -299,7 +299,7 @@ xfs_bulkstat_use_dinode(
         */
        if (be16_to_cpu(dip->di_core.di_magic) != XFS_DINODE_MAGIC ||
            !XFS_DINODE_GOOD_VERSION(dip->di_core.di_version) ||
-           !dip->di_core.di_nlink)
+           !dip->di_core.di_mode)
                return 0;
        if (flags & BULKSTAT_FG_QUICK) {
                *dipp = dip;
@@ -307,7 +307,7 @@ xfs_bulkstat_use_dinode(
        }
        /* BULKSTAT_FG_INLINE: if attr fork is local, or not there, use it */
        aformat = dip->di_core.di_aformat;
-       if ((XFS_CFORK_Q(&dip->di_core) == 0) ||
+       if ((XFS_DFORK_Q(dip) == 0) ||
            (aformat == XFS_DINODE_FMT_LOCAL) ||
            (aformat == XFS_DINODE_FMT_EXTENTS && !dip->di_core.di_anextents)) {
                *dipp = dip;
@@ -399,7 +399,7 @@ xfs_bulkstat(
                (XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_inodelog);
        nimask = ~(nicluster - 1);
        nbcluster = nicluster >> mp->m_sb.sb_inopblog;
-       irbuf = kmem_zalloc_greedy(&irbsize, NBPC, NBPC * 4,
+       irbuf = kmem_zalloc_greedy(&irbsize, PAGE_SIZE, PAGE_SIZE * 4,
                                   KM_SLEEP | KM_MAYFAIL | KM_LARGE);
        nirbuf = irbsize / sizeof(*irbuf);
 
@@ -830,7 +830,7 @@ xfs_inumbers(
        agino = XFS_INO_TO_AGINO(mp, ino);
        left = *count;
        *count = 0;
-       bcount = MIN(left, (int)(NBPP / sizeof(*buffer)));
+       bcount = MIN(left, (int)(PAGE_SIZE / sizeof(*buffer)));
        buffer = kmem_alloc(bcount * sizeof(*buffer), KM_SLEEP);
        error = bufidx = 0;
        cur = NULL;
index 77c12715a7d06f00be9f67932930b22aed6eb6cc..b3ac3805d3c4434ac13257846d326ca3c6c100af 100644 (file)
@@ -399,10 +399,10 @@ xfs_log_notify(xfs_mount_t          *mp,          /* mount of partition */
 {
        xlog_t *log = mp->m_log;
        xlog_in_core_t    *iclog = (xlog_in_core_t *)iclog_hndl;
-       int     abortflg, spl;
+       int     abortflg;
 
        cb->cb_next = NULL;
-       spl = LOG_LOCK(log);
+       spin_lock(&log->l_icloglock);
        abortflg = (iclog->ic_state & XLOG_STATE_IOERROR);
        if (!abortflg) {
                ASSERT_ALWAYS((iclog->ic_state == XLOG_STATE_ACTIVE) ||
@@ -411,7 +411,7 @@ xfs_log_notify(xfs_mount_t    *mp,          /* mount of partition */
                *(iclog->ic_callback_tail) = cb;
                iclog->ic_callback_tail = &(cb->cb_next);
        }
-       LOG_UNLOCK(log, spl);
+       spin_unlock(&log->l_icloglock);
        return abortflg;
 }      /* xfs_log_notify */
 
@@ -498,11 +498,14 @@ xfs_log_reserve(xfs_mount_t        *mp,
  * Return error or zero.
  */
 int
-xfs_log_mount(xfs_mount_t      *mp,
-             xfs_buftarg_t     *log_target,
-             xfs_daddr_t       blk_offset,
-             int               num_bblks)
+xfs_log_mount(
+       xfs_mount_t     *mp,
+       xfs_buftarg_t   *log_target,
+       xfs_daddr_t     blk_offset,
+       int             num_bblks)
 {
+       int             error;
+
        if (!(mp->m_flags & XFS_MOUNT_NORECOVERY))
                cmn_err(CE_NOTE, "XFS mounting filesystem %s", mp->m_fsname);
        else {
@@ -514,12 +517,22 @@ xfs_log_mount(xfs_mount_t *mp,
 
        mp->m_log = xlog_alloc_log(mp, log_target, blk_offset, num_bblks);
 
+       /*
+        * Initialize the AIL now we have a log.
+        */
+       spin_lock_init(&mp->m_ail_lock);
+       error = xfs_trans_ail_init(mp);
+       if (error) {
+               cmn_err(CE_WARN, "XFS: AIL initialisation failed: error %d", error);
+               goto error;
+       }
+
        /*
         * skip log recovery on a norecovery mount.  pretend it all
         * just worked.
         */
        if (!(mp->m_flags & XFS_MOUNT_NORECOVERY)) {
-               int             error, readonly = (mp->m_flags & XFS_MOUNT_RDONLY);
+               int     readonly = (mp->m_flags & XFS_MOUNT_RDONLY);
 
                if (readonly)
                        mp->m_flags &= ~XFS_MOUNT_RDONLY;
@@ -530,8 +543,7 @@ xfs_log_mount(xfs_mount_t   *mp,
                        mp->m_flags |= XFS_MOUNT_RDONLY;
                if (error) {
                        cmn_err(CE_WARN, "XFS: log mount/recovery failed: error %d", error);
-                       xlog_dealloc_log(mp->m_log);
-                       return error;
+                       goto error;
                }
        }
 
@@ -540,6 +552,9 @@ xfs_log_mount(xfs_mount_t   *mp,
 
        /* End mounting message in xfs_log_mount_finish */
        return 0;
+error:
+       xfs_log_unmount_dealloc(mp);
+       return error;
 }      /* xfs_log_mount */
 
 /*
@@ -606,7 +621,6 @@ xfs_log_unmount_write(xfs_mount_t *mp)
        xfs_log_ticket_t tic = NULL;
        xfs_lsn_t        lsn;
        int              error;
-       SPLDECL(s);
 
        /* the data section must be 32 bit size aligned */
        struct {
@@ -659,24 +673,24 @@ xfs_log_unmount_write(xfs_mount_t *mp)
                }
 
 
-               s = LOG_LOCK(log);
+               spin_lock(&log->l_icloglock);
                iclog = log->l_iclog;
                iclog->ic_refcnt++;
-               LOG_UNLOCK(log, s);
+               spin_unlock(&log->l_icloglock);
                xlog_state_want_sync(log, iclog);
                (void) xlog_state_release_iclog(log, iclog);
 
-               s = LOG_LOCK(log);
+               spin_lock(&log->l_icloglock);
                if (!(iclog->ic_state == XLOG_STATE_ACTIVE ||
                      iclog->ic_state == XLOG_STATE_DIRTY)) {
                        if (!XLOG_FORCED_SHUTDOWN(log)) {
                                sv_wait(&iclog->ic_forcesema, PMEM,
                                        &log->l_icloglock, s);
                        } else {
-                               LOG_UNLOCK(log, s);
+                               spin_unlock(&log->l_icloglock);
                        }
                } else {
-                       LOG_UNLOCK(log, s);
+                       spin_unlock(&log->l_icloglock);
                }
                if (tic) {
                        xlog_trace_loggrant(log, tic, "unmount rec");
@@ -697,15 +711,15 @@ xfs_log_unmount_write(xfs_mount_t *mp)
                 * a file system that went into forced_shutdown as
                 * the result of an unmount..
                 */
-               s = LOG_LOCK(log);
+               spin_lock(&log->l_icloglock);
                iclog = log->l_iclog;
                iclog->ic_refcnt++;
-               LOG_UNLOCK(log, s);
+               spin_unlock(&log->l_icloglock);
 
                xlog_state_want_sync(log, iclog);
                (void) xlog_state_release_iclog(log, iclog);
 
-               s = LOG_LOCK(log);
+               spin_lock(&log->l_icloglock);
 
                if ( ! (   iclog->ic_state == XLOG_STATE_ACTIVE
                        || iclog->ic_state == XLOG_STATE_DIRTY
@@ -714,7 +728,7 @@ xfs_log_unmount_write(xfs_mount_t *mp)
                                sv_wait(&iclog->ic_forcesema, PMEM,
                                        &log->l_icloglock, s);
                } else {
-                       LOG_UNLOCK(log, s);
+                       spin_unlock(&log->l_icloglock);
                }
        }
 
@@ -723,10 +737,14 @@ xfs_log_unmount_write(xfs_mount_t *mp)
 
 /*
  * Deallocate log structures for unmount/relocation.
+ *
+ * We need to stop the aild from running before we destroy
+ * and deallocate the log as the aild references the log.
  */
 void
 xfs_log_unmount_dealloc(xfs_mount_t *mp)
 {
+       xfs_trans_ail_destroy(mp);
        xlog_dealloc_log(mp->m_log);
 }
 
@@ -762,20 +780,18 @@ xfs_log_move_tail(xfs_mount_t     *mp,
        xlog_ticket_t   *tic;
        xlog_t          *log = mp->m_log;
        int             need_bytes, free_bytes, cycle, bytes;
-       SPLDECL(s);
 
        if (XLOG_FORCED_SHUTDOWN(log))
                return;
-       ASSERT(!XFS_FORCED_SHUTDOWN(mp));
 
        if (tail_lsn == 0) {
                /* needed since sync_lsn is 64 bits */
-               s = LOG_LOCK(log);
+               spin_lock(&log->l_icloglock);
                tail_lsn = log->l_last_sync_lsn;
-               LOG_UNLOCK(log, s);
+               spin_unlock(&log->l_icloglock);
        }
 
-       s = GRANT_LOCK(log);
+       spin_lock(&log->l_grant_lock);
 
        /* Also an invalid lsn.  1 implies that we aren't passing in a valid
         * tail_lsn.
@@ -824,7 +840,7 @@ xfs_log_move_tail(xfs_mount_t       *mp,
                        tic = tic->t_next;
                } while (tic != log->l_reserve_headq);
        }
-       GRANT_UNLOCK(log, s);
+       spin_unlock(&log->l_grant_lock);
 }      /* xfs_log_move_tail */
 
 /*
@@ -836,14 +852,13 @@ xfs_log_move_tail(xfs_mount_t     *mp,
 int
 xfs_log_need_covered(xfs_mount_t *mp)
 {
-       SPLDECL(s);
        int             needed = 0, gen;
        xlog_t          *log = mp->m_log;
 
        if (!xfs_fs_writable(mp))
                return 0;
 
-       s = LOG_LOCK(log);
+       spin_lock(&log->l_icloglock);
        if (((log->l_covered_state == XLOG_STATE_COVER_NEED) ||
                (log->l_covered_state == XLOG_STATE_COVER_NEED2))
                        && !xfs_trans_first_ail(mp, &gen)
@@ -856,7 +871,7 @@ xfs_log_need_covered(xfs_mount_t *mp)
                }
                needed = 1;
        }
-       LOG_UNLOCK(log, s);
+       spin_unlock(&log->l_icloglock);
        return needed;
 }
 
@@ -881,17 +896,16 @@ xfs_lsn_t
 xlog_assign_tail_lsn(xfs_mount_t *mp)
 {
        xfs_lsn_t tail_lsn;
-       SPLDECL(s);
        xlog_t    *log = mp->m_log;
 
        tail_lsn = xfs_trans_tail_ail(mp);
-       s = GRANT_LOCK(log);
+       spin_lock(&log->l_grant_lock);
        if (tail_lsn != 0) {
                log->l_tail_lsn = tail_lsn;
        } else {
                tail_lsn = log->l_tail_lsn = log->l_last_sync_lsn;
        }
-       GRANT_UNLOCK(log, s);
+       spin_unlock(&log->l_grant_lock);
 
        return tail_lsn;
 }      /* xlog_assign_tail_lsn */
@@ -911,7 +925,7 @@ xlog_assign_tail_lsn(xfs_mount_t *mp)
  * the tail.  The details of this case are described below, but the end
  * result is that we return the size of the log as the amount of space left.
  */
-int
+STATIC int
 xlog_space_left(xlog_t *log, int cycle, int bytes)
 {
        int free_bytes;
@@ -1165,7 +1179,7 @@ xlog_alloc_log(xfs_mount_t        *mp,
        log->l_flags       |= XLOG_ACTIVE_RECOVERY;
 
        log->l_prev_block  = -1;
-       ASSIGN_ANY_LSN_HOST(log->l_tail_lsn, 1, 0);
+       log->l_tail_lsn    = xlog_assign_lsn(1, 0);
        /* log->l_tail_lsn = 0x100000000LL; cycle = 1; current block = 0 */
        log->l_last_sync_lsn = log->l_tail_lsn;
        log->l_curr_cycle  = 1;     /* 0 is bad since this is initial value */
@@ -1193,8 +1207,8 @@ xlog_alloc_log(xfs_mount_t        *mp,
        ASSERT(XFS_BUF_VALUSEMA(bp) <= 0);
        log->l_xbuf = bp;
 
-       spinlock_init(&log->l_icloglock, "iclog");
-       spinlock_init(&log->l_grant_lock, "grhead_iclog");
+       spin_lock_init(&log->l_icloglock);
+       spin_lock_init(&log->l_grant_lock);
        initnsema(&log->l_flushsema, 0, "ic-flush");
        xlog_state_ticket_alloc(log);  /* wait until after icloglock inited */
 
@@ -1231,12 +1245,12 @@ xlog_alloc_log(xfs_mount_t      *mp,
 
                head = &iclog->ic_header;
                memset(head, 0, sizeof(xlog_rec_header_t));
-               INT_SET(head->h_magicno, ARCH_CONVERT, XLOG_HEADER_MAGIC_NUM);
-               INT_SET(head->h_version, ARCH_CONVERT,
+               head->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
+               head->h_version = cpu_to_be32(
                        XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) ? 2 : 1);
-               INT_SET(head->h_size, ARCH_CONVERT, log->l_iclog_size);
+               head->h_size = cpu_to_be32(log->l_iclog_size);
                /* new fields */
-               INT_SET(head->h_fmt, ARCH_CONVERT, XLOG_FMT);
+               head->h_fmt = cpu_to_be32(XLOG_FMT);
                memcpy(&head->h_fs_uuid, &mp->m_sb.sb_uuid, sizeof(uuid_t));
 
 
@@ -1293,7 +1307,7 @@ xlog_commit_record(xfs_mount_t  *mp,
  * pushes on an lsn which is further along in the log once we reach the high
  * water mark.  In this manner, we would be creating a low water mark.
  */
-void
+STATIC void
 xlog_grant_push_ail(xfs_mount_t        *mp,
                    int         need_bytes)
 {
@@ -1305,11 +1319,10 @@ xlog_grant_push_ail(xfs_mount_t *mp,
     int                threshold_block;        /* block in lsn we'd like to be at */
     int                threshold_cycle;        /* lsn cycle we'd like to be at */
     int                free_threshold;
-    SPLDECL(s);
 
     ASSERT(BTOBB(need_bytes) < log->l_logBBsize);
 
-    s = GRANT_LOCK(log);
+    spin_lock(&log->l_grant_lock);
     free_bytes = xlog_space_left(log,
                                 log->l_grant_reserve_cycle,
                                 log->l_grant_reserve_bytes);
@@ -1331,8 +1344,7 @@ xlog_grant_push_ail(xfs_mount_t   *mp,
            threshold_block -= log->l_logBBsize;
            threshold_cycle += 1;
        }
-       ASSIGN_ANY_LSN_HOST(threshold_lsn, threshold_cycle,
-                      threshold_block);
+       threshold_lsn = xlog_assign_lsn(threshold_cycle, threshold_block);
 
        /* Don't pass in an lsn greater than the lsn of the last
         * log record known to be on disk.
@@ -1340,7 +1352,7 @@ xlog_grant_push_ail(xfs_mount_t   *mp,
        if (XFS_LSN_CMP(threshold_lsn, log->l_last_sync_lsn) > 0)
            threshold_lsn = log->l_last_sync_lsn;
     }
-    GRANT_UNLOCK(log, s);
+    spin_unlock(&log->l_grant_lock);
 
     /*
      * Get the transaction layer to kick the dirty buffers out to
@@ -1378,19 +1390,18 @@ xlog_grant_push_ail(xfs_mount_t *mp,
  * is added immediately before calling bwrite().
  */
 
-int
+STATIC int
 xlog_sync(xlog_t               *log,
          xlog_in_core_t        *iclog)
 {
        xfs_caddr_t     dptr;           /* pointer to byte sized element */
        xfs_buf_t       *bp;
-       int             i, ops;
+       int             i;
        uint            count;          /* byte count of bwrite */
        uint            count_init;     /* initial count before roundup */
        int             roundoff;       /* roundoff to BB or stripe */
        int             split = 0;      /* split write into two regions */
        int             error;
-       SPLDECL(s);
        int             v2 = XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb);
 
        XFS_STATS_INC(xs_log_writes);
@@ -1415,30 +1426,26 @@ xlog_sync(xlog_t                *log,
                 roundoff < BBTOB(1)));
 
        /* move grant heads by roundoff in sync */
-       s = GRANT_LOCK(log);
+       spin_lock(&log->l_grant_lock);
        xlog_grant_add_space(log, roundoff);
-       GRANT_UNLOCK(log, s);
+       spin_unlock(&log->l_grant_lock);
 
        /* put cycle number in every block */
        xlog_pack_data(log, iclog, roundoff); 
 
        /* real byte length */
        if (v2) {
-               INT_SET(iclog->ic_header.h_len, 
-                       ARCH_CONVERT,
-                       iclog->ic_offset + roundoff);
+               iclog->ic_header.h_len =
+                       cpu_to_be32(iclog->ic_offset + roundoff);
        } else {
-               INT_SET(iclog->ic_header.h_len, ARCH_CONVERT, iclog->ic_offset);
+               iclog->ic_header.h_len =
+                       cpu_to_be32(iclog->ic_offset);
        }
 
-       /* put ops count in correct order */
-       ops = iclog->ic_header.h_num_logops;
-       INT_SET(iclog->ic_header.h_num_logops, ARCH_CONVERT, ops);
-
        bp = iclog->ic_bp;
        ASSERT(XFS_BUF_FSPRIVATE2(bp, unsigned long) == (unsigned long)1);
        XFS_BUF_SET_FSPRIVATE2(bp, (unsigned long)2);
-       XFS_BUF_SET_ADDR(bp, BLOCK_LSN(INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT)));
+       XFS_BUF_SET_ADDR(bp, BLOCK_LSN(be64_to_cpu(iclog->ic_header.h_lsn)));
 
        XFS_STATS_ADD(xs_log_blocks, BTOBB(count));
 
@@ -1501,10 +1508,10 @@ xlog_sync(xlog_t                *log,
                 * a new cycle.  Watch out for the header magic number
                 * case, though.
                 */
-               for (i=0; i<split; i += BBSIZE) {
-                       INT_MOD(*(uint *)dptr, ARCH_CONVERT, +1);
-                       if (INT_GET(*(uint *)dptr, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM)
-                               INT_MOD(*(uint *)dptr, ARCH_CONVERT, +1);
+               for (i = 0; i < split; i += BBSIZE) {
+                       be32_add((__be32 *)dptr, 1);
+                       if (be32_to_cpu(*(__be32 *)dptr) == XLOG_HEADER_MAGIC_NUM)
+                               be32_add((__be32 *)dptr, 1);
                        dptr += BBSIZE;
                }
 
@@ -1527,14 +1534,13 @@ xlog_sync(xlog_t                *log,
 /*
  * Deallocate a log structure
  */
-void
+STATIC void
 xlog_dealloc_log(xlog_t *log)
 {
        xlog_in_core_t  *iclog, *next_iclog;
        xlog_ticket_t   *tic, *next_tic;
        int             i;
 
-
        iclog = log->l_iclog;
        for (i=0; i<log->l_iclog_bufs; i++) {
                sv_destroy(&iclog->ic_forcesema);
@@ -1565,7 +1571,7 @@ xlog_dealloc_log(xlog_t *log)
                tic = log->l_unmount_free;
                while (tic) {
                        next_tic = tic->t_next;
-                       kmem_free(tic, NBPP);
+                       kmem_free(tic, PAGE_SIZE);
                        tic = next_tic;
                }
        }
@@ -1592,14 +1598,12 @@ xlog_state_finish_copy(xlog_t           *log,
                       int              record_cnt,
                       int              copy_bytes)
 {
-       SPLDECL(s);
+       spin_lock(&log->l_icloglock);
 
-       s = LOG_LOCK(log);
-
-       iclog->ic_header.h_num_logops += record_cnt;
+       be32_add(&iclog->ic_header.h_num_logops, record_cnt);
        iclog->ic_offset += copy_bytes;
 
-       LOG_UNLOCK(log, s);
+       spin_unlock(&log->l_icloglock);
 }      /* xlog_state_finish_copy */
 
 
@@ -1752,7 +1756,7 @@ xlog_print_tic_res(xfs_mount_t *mp, xlog_ticket_t *ticket)
  *     we don't update ic_offset until the end when we know exactly how many
  *     bytes have been written out.
  */
-int
+STATIC int
 xlog_write(xfs_mount_t *       mp,
           xfs_log_iovec_t      reg[],
           int                  nentries,
@@ -1823,7 +1827,7 @@ xlog_write(xfs_mount_t *  mp,
 
        /* start_lsn is the first lsn written to. That's all we need. */
        if (! *start_lsn)
-           *start_lsn = INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT);
+           *start_lsn = be64_to_cpu(iclog->ic_header.h_lsn);
 
        /* This loop writes out as many regions as can fit in the amount
         * of space which was allocated by xlog_state_get_iclog_space().
@@ -1839,7 +1843,7 @@ xlog_write(xfs_mount_t *  mp,
             */
            if (ticket->t_flags & XLOG_TIC_INITED) {
                logop_head              = (xlog_op_header_t *)ptr;
-               INT_SET(logop_head->oh_tid, ARCH_CONVERT, ticket->t_tid);
+               logop_head->oh_tid      = cpu_to_be32(ticket->t_tid);
                logop_head->oh_clientid = ticket->t_clientid;
                logop_head->oh_len      = 0;
                logop_head->oh_flags    = XLOG_START_TRANS;
@@ -1853,7 +1857,7 @@ xlog_write(xfs_mount_t *  mp,
 
            /* Copy log operation header directly into data section */
            logop_head                  = (xlog_op_header_t *)ptr;
-           INT_SET(logop_head->oh_tid, ARCH_CONVERT, ticket->t_tid);
+           logop_head->oh_tid          = cpu_to_be32(ticket->t_tid);
            logop_head->oh_clientid     = ticket->t_clientid;
            logop_head->oh_res2         = 0;
 
@@ -1888,13 +1892,14 @@ xlog_write(xfs_mount_t *        mp,
 
            copy_off = partial_copy_len;
            if (need_copy <= iclog->ic_size - log_offset) { /*complete write */
-               INT_SET(logop_head->oh_len, ARCH_CONVERT, copy_len = need_copy);
+               copy_len = need_copy;
+               logop_head->oh_len = cpu_to_be32(copy_len);
                if (partial_copy)
                    logop_head->oh_flags|= (XLOG_END_TRANS|XLOG_WAS_CONT_TRANS);
                partial_copy_len = partial_copy = 0;
            } else {                                        /* partial write */
                copy_len = iclog->ic_size - log_offset;
-               INT_SET(logop_head->oh_len, ARCH_CONVERT, copy_len);
+               logop_head->oh_len = cpu_to_be32(copy_len);
                logop_head->oh_flags |= XLOG_CONTINUE_TRANS;
                if (partial_copy)
                        logop_head->oh_flags |= XLOG_WAS_CONT_TRANS;
@@ -1992,7 +1997,8 @@ xlog_state_clean_log(xlog_t *log)
                         * We don't need to cover the dummy.
                         */
                        if (!changed &&
-                          (INT_GET(iclog->ic_header.h_num_logops, ARCH_CONVERT) == XLOG_COVER_OPS)) {
+                          (be32_to_cpu(iclog->ic_header.h_num_logops) ==
+                                       XLOG_COVER_OPS)) {
                                changed = 1;
                        } else {
                                /*
@@ -2060,7 +2066,7 @@ xlog_get_lowest_lsn(
        lowest_lsn = 0;
        do {
            if (!(lsn_log->ic_state & (XLOG_STATE_ACTIVE|XLOG_STATE_DIRTY))) {
-               lsn = INT_GET(lsn_log->ic_header.h_lsn, ARCH_CONVERT);
+               lsn = be64_to_cpu(lsn_log->ic_header.h_lsn);
                if ((lsn && !lowest_lsn) ||
                    (XFS_LSN_CMP(lsn, lowest_lsn) < 0)) {
                        lowest_lsn = lsn;
@@ -2089,9 +2095,8 @@ xlog_state_do_callback(
        int                funcdidcallbacks; /* flag: function did callbacks */
        int                repeats;     /* for issuing console warnings if
                                         * looping too many times */
-       SPLDECL(s);
 
-       s = LOG_LOCK(log);
+       spin_lock(&log->l_icloglock);
        first_iclog = iclog = log->l_iclog;
        ioerrors = 0;
        funcdidcallbacks = 0;
@@ -2136,7 +2141,7 @@ xlog_state_do_callback(
                                 * to DO_CALLBACK, we will not process it when
                                 * we retry since a previous iclog is in the
                                 * CALLBACK and the state cannot change since
-                                * we are holding the LOG_LOCK.
+                                * we are holding the l_icloglock.
                                 */
                                if (!(iclog->ic_state &
                                        (XLOG_STATE_DONE_SYNC |
@@ -2162,11 +2167,9 @@ xlog_state_do_callback(
                                 */
 
                                lowest_lsn = xlog_get_lowest_lsn(log);
-                               if (lowest_lsn && (
-                                       XFS_LSN_CMP(
-                                               lowest_lsn,
-                                               INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT)
-                                       )<0)) {
+                               if (lowest_lsn &&
+                                   XFS_LSN_CMP(lowest_lsn,
+                                               be64_to_cpu(iclog->ic_header.h_lsn)) < 0) {
                                        iclog = iclog->ic_next;
                                        continue; /* Leave this iclog for
                                                   * another thread */
@@ -2174,19 +2177,18 @@ xlog_state_do_callback(
 
                                iclog->ic_state = XLOG_STATE_CALLBACK;
 
-                               LOG_UNLOCK(log, s);
+                               spin_unlock(&log->l_icloglock);
 
                                /* l_last_sync_lsn field protected by
-                                * GRANT_LOCK. Don't worry about iclog's lsn.
+                                * l_grant_lock. Don't worry about iclog's lsn.
                                 * No one else can be here except us.
                                 */
-                               s = GRANT_LOCK(log);
-                               ASSERT(XFS_LSN_CMP(
-                                               log->l_last_sync_lsn,
-                                               INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT)
-                                       )<=0);
-                               log->l_last_sync_lsn = INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT);
-                               GRANT_UNLOCK(log, s);
+                               spin_lock(&log->l_grant_lock);
+                               ASSERT(XFS_LSN_CMP(log->l_last_sync_lsn,
+                                      be64_to_cpu(iclog->ic_header.h_lsn)) <= 0);
+                               log->l_last_sync_lsn =
+                                       be64_to_cpu(iclog->ic_header.h_lsn);
+                               spin_unlock(&log->l_grant_lock);
 
                                /*
                                 * Keep processing entries in the callback list
@@ -2195,7 +2197,7 @@ xlog_state_do_callback(
                                 * empty and change the state to DIRTY so that
                                 * we don't miss any more callbacks being added.
                                 */
-                               s = LOG_LOCK(log);
+                               spin_lock(&log->l_icloglock);
                        } else {
                                ioerrors++;
                        }
@@ -2204,14 +2206,14 @@ xlog_state_do_callback(
                        while (cb) {
                                iclog->ic_callback_tail = &(iclog->ic_callback);
                                iclog->ic_callback = NULL;
-                               LOG_UNLOCK(log, s);
+                               spin_unlock(&log->l_icloglock);
 
                                /* perform callbacks in the order given */
                                for (; cb; cb = cb_next) {
                                        cb_next = cb->cb_next;
                                        cb->cb_func(cb->cb_arg, aborted);
                                }
-                               s = LOG_LOCK(log);
+                               spin_lock(&log->l_icloglock);
                                cb = iclog->ic_callback;
                        }
 
@@ -2258,7 +2260,7 @@ xlog_state_do_callback(
                         *
                         * SYNCING - i/o completion will go through logs
                         * DONE_SYNC - interrupt thread should be waiting for
-                        *              LOG_LOCK
+                        *              l_icloglock
                         * IOERROR - give up hope all ye who enter here
                         */
                        if (iclog->ic_state == XLOG_STATE_WANT_SYNC ||
@@ -2276,7 +2278,7 @@ xlog_state_do_callback(
                flushcnt = log->l_flushcnt;
                log->l_flushcnt = 0;
        }
-       LOG_UNLOCK(log, s);
+       spin_unlock(&log->l_icloglock);
        while (flushcnt--)
                vsema(&log->l_flushsema);
 }      /* xlog_state_do_callback */
@@ -2296,15 +2298,14 @@ xlog_state_do_callback(
  * global state machine log lock.  Assume that the calls to cvsema won't
  * take a long time.  At least we know it won't sleep.
  */
-void
+STATIC void
 xlog_state_done_syncing(
        xlog_in_core_t  *iclog,
        int             aborted)
 {
        xlog_t             *log = iclog->ic_log;
-       SPLDECL(s);
 
-       s = LOG_LOCK(log);
+       spin_lock(&log->l_icloglock);
 
        ASSERT(iclog->ic_state == XLOG_STATE_SYNCING ||
               iclog->ic_state == XLOG_STATE_IOERROR);
@@ -2320,7 +2321,7 @@ xlog_state_done_syncing(
         */
        if (iclog->ic_state != XLOG_STATE_IOERROR) {
                if (--iclog->ic_bwritecnt == 1) {
-                       LOG_UNLOCK(log, s);
+                       spin_unlock(&log->l_icloglock);
                        return;
                }
                iclog->ic_state = XLOG_STATE_DONE_SYNC;
@@ -2332,7 +2333,7 @@ xlog_state_done_syncing(
         * I/O, the others get to wait for the result.
         */
        sv_broadcast(&iclog->ic_writesema);
-       LOG_UNLOCK(log, s);
+       spin_unlock(&log->l_icloglock);
        xlog_state_do_callback(log, aborted, iclog);    /* also cleans log */
 }      /* xlog_state_done_syncing */
 
@@ -2357,7 +2358,7 @@ xlog_state_done_syncing(
  *             needs to be incremented, depending on the amount of data which
  *             is copied.
  */
-int
+STATIC int
 xlog_state_get_iclog_space(xlog_t        *log,
                           int            len,
                           xlog_in_core_t **iclogp,
@@ -2365,23 +2366,22 @@ xlog_state_get_iclog_space(xlog_t         *log,
                           int            *continued_write,
                           int            *logoffsetp)
 {
-       SPLDECL(s);
        int               log_offset;
        xlog_rec_header_t *head;
        xlog_in_core_t    *iclog;
        int               error;
 
 restart:
-       s = LOG_LOCK(log);
+       spin_lock(&log->l_icloglock);
        if (XLOG_FORCED_SHUTDOWN(log)) {
-               LOG_UNLOCK(log, s);
+               spin_unlock(&log->l_icloglock);
                return XFS_ERROR(EIO);
        }
 
        iclog = log->l_iclog;
        if (! (iclog->ic_state == XLOG_STATE_ACTIVE)) {
                log->l_flushcnt++;
-               LOG_UNLOCK(log, s);
+               spin_unlock(&log->l_icloglock);
                xlog_trace_iclog(iclog, XLOG_TRACE_SLEEP_FLUSH);
                XFS_STATS_INC(xs_log_noiclogs);
                /* Ensure that log writes happen */
@@ -2404,8 +2404,9 @@ restart:
                xlog_tic_add_region(ticket,
                                    log->l_iclog_hsize,
                                    XLOG_REG_TYPE_LRHEADER);
-               INT_SET(head->h_cycle, ARCH_CONVERT, log->l_curr_cycle);
-               ASSIGN_LSN(head->h_lsn, log);
+               head->h_cycle = cpu_to_be32(log->l_curr_cycle);
+               head->h_lsn = cpu_to_be64(
+                       xlog_assign_lsn(log->l_curr_cycle, log->l_curr_block));
                ASSERT(log->l_curr_block >= 0);
        }
 
@@ -2423,12 +2424,12 @@ restart:
 
                /* If I'm the only one writing to this iclog, sync it to disk */
                if (iclog->ic_refcnt == 1) {
-                       LOG_UNLOCK(log, s);
+                       spin_unlock(&log->l_icloglock);
                        if ((error = xlog_state_release_iclog(log, iclog)))
                                return error;
                } else {
                        iclog->ic_refcnt--;
-                       LOG_UNLOCK(log, s);
+                       spin_unlock(&log->l_icloglock);
                }
                goto restart;
        }
@@ -2449,7 +2450,7 @@ restart:
        *iclogp = iclog;
 
        ASSERT(iclog->ic_offset <= iclog->ic_size);
-       LOG_UNLOCK(log, s);
+       spin_unlock(&log->l_icloglock);
 
        *logoffsetp = log_offset;
        return 0;
@@ -2467,7 +2468,6 @@ xlog_grant_log_space(xlog_t          *log,
 {
        int              free_bytes;
        int              need_bytes;
-       SPLDECL(s);
 #ifdef DEBUG
        xfs_lsn_t        tail_lsn;
 #endif
@@ -2479,7 +2479,7 @@ xlog_grant_log_space(xlog_t          *log,
 #endif
 
        /* Is there space or do we need to sleep? */
-       s = GRANT_LOCK(log);
+       spin_lock(&log->l_grant_lock);
        xlog_trace_loggrant(log, tic, "xlog_grant_log_space: enter");
 
        /* something is already sleeping; insert new transaction at end */
@@ -2502,7 +2502,7 @@ xlog_grant_log_space(xlog_t          *log,
                 */
                xlog_trace_loggrant(log, tic,
                                    "xlog_grant_log_space: wake 1");
-               s = GRANT_LOCK(log);
+               spin_lock(&log->l_grant_lock);
        }
        if (tic->t_flags & XFS_LOG_PERM_RESERV)
                need_bytes = tic->t_unit_res*tic->t_ocnt;
@@ -2524,14 +2524,14 @@ redo:
                sv_wait(&tic->t_sema, PINOD|PLTWAIT, &log->l_grant_lock, s);
 
                if (XLOG_FORCED_SHUTDOWN(log)) {
-                       s = GRANT_LOCK(log);
+                       spin_lock(&log->l_grant_lock);
                        goto error_return;
                }
 
                xlog_trace_loggrant(log, tic,
                                    "xlog_grant_log_space: wake 2");
                xlog_grant_push_ail(log->l_mp, need_bytes);
-               s = GRANT_LOCK(log);
+               spin_lock(&log->l_grant_lock);
                goto redo;
        } else if (tic->t_flags & XLOG_TIC_IN_Q)
                xlog_del_ticketq(&log->l_reserve_headq, tic);
@@ -2553,7 +2553,7 @@ redo:
 #endif
        xlog_trace_loggrant(log, tic, "xlog_grant_log_space: exit");
        xlog_verify_grant_head(log, 1);
-       GRANT_UNLOCK(log, s);
+       spin_unlock(&log->l_grant_lock);
        return 0;
 
  error_return:
@@ -2567,7 +2567,7 @@ redo:
         */
        tic->t_curr_res = 0;
        tic->t_cnt = 0; /* ungrant will give back unit_res * t_cnt. */
-       GRANT_UNLOCK(log, s);
+       spin_unlock(&log->l_grant_lock);
        return XFS_ERROR(EIO);
 }      /* xlog_grant_log_space */
 
@@ -2581,7 +2581,6 @@ STATIC int
 xlog_regrant_write_log_space(xlog_t       *log,
                             xlog_ticket_t *tic)
 {
-       SPLDECL(s);
        int             free_bytes, need_bytes;
        xlog_ticket_t   *ntic;
 #ifdef DEBUG
@@ -2599,7 +2598,7 @@ xlog_regrant_write_log_space(xlog_t          *log,
                panic("regrant Recovery problem");
 #endif
 
-       s = GRANT_LOCK(log);
+       spin_lock(&log->l_grant_lock);
        xlog_trace_loggrant(log, tic, "xlog_regrant_write_log_space: enter");
 
        if (XLOG_FORCED_SHUTDOWN(log))
@@ -2638,14 +2637,14 @@ xlog_regrant_write_log_space(xlog_t        *log,
                        /* If we're shutting down, this tic is already
                         * off the queue */
                        if (XLOG_FORCED_SHUTDOWN(log)) {
-                               s = GRANT_LOCK(log);
+                               spin_lock(&log->l_grant_lock);
                                goto error_return;
                        }
 
                        xlog_trace_loggrant(log, tic,
                                    "xlog_regrant_write_log_space: wake 1");
                        xlog_grant_push_ail(log->l_mp, tic->t_unit_res);
-                       s = GRANT_LOCK(log);
+                       spin_lock(&log->l_grant_lock);
                }
        }
 
@@ -2665,14 +2664,14 @@ redo:
 
                /* If we're shutting down, this tic is already off the queue */
                if (XLOG_FORCED_SHUTDOWN(log)) {
-                       s = GRANT_LOCK(log);
+                       spin_lock(&log->l_grant_lock);
                        goto error_return;
                }
 
                xlog_trace_loggrant(log, tic,
                                    "xlog_regrant_write_log_space: wake 2");
                xlog_grant_push_ail(log->l_mp, need_bytes);
-               s = GRANT_LOCK(log);
+               spin_lock(&log->l_grant_lock);
                goto redo;
        } else if (tic->t_flags & XLOG_TIC_IN_Q)
                xlog_del_ticketq(&log->l_write_headq, tic);
@@ -2689,7 +2688,7 @@ redo:
 
        xlog_trace_loggrant(log, tic, "xlog_regrant_write_log_space: exit");
        xlog_verify_grant_head(log, 1);
-       GRANT_UNLOCK(log, s);
+       spin_unlock(&log->l_grant_lock);
        return 0;
 
 
@@ -2704,7 +2703,7 @@ redo:
         */
        tic->t_curr_res = 0;
        tic->t_cnt = 0; /* ungrant will give back unit_res * t_cnt. */
-       GRANT_UNLOCK(log, s);
+       spin_unlock(&log->l_grant_lock);
        return XFS_ERROR(EIO);
 }      /* xlog_regrant_write_log_space */
 
@@ -2720,14 +2719,12 @@ STATIC void
 xlog_regrant_reserve_log_space(xlog_t       *log,
                               xlog_ticket_t *ticket)
 {
-       SPLDECL(s);
-
        xlog_trace_loggrant(log, ticket,
                            "xlog_regrant_reserve_log_space: enter");
        if (ticket->t_cnt > 0)
                ticket->t_cnt--;
 
-       s = GRANT_LOCK(log);
+       spin_lock(&log->l_grant_lock);
        xlog_grant_sub_space(log, ticket->t_curr_res);
        ticket->t_curr_res = ticket->t_unit_res;
        xlog_tic_reset_res(ticket);
@@ -2737,7 +2734,7 @@ xlog_regrant_reserve_log_space(xlog_t          *log,
 
        /* just return if we still have some of the pre-reserved space */
        if (ticket->t_cnt > 0) {
-               GRANT_UNLOCK(log, s);
+               spin_unlock(&log->l_grant_lock);
                return;
        }
 
@@ -2745,7 +2742,7 @@ xlog_regrant_reserve_log_space(xlog_t          *log,
        xlog_trace_loggrant(log, ticket,
                            "xlog_regrant_reserve_log_space: exit");
        xlog_verify_grant_head(log, 0);
-       GRANT_UNLOCK(log, s);
+       spin_unlock(&log->l_grant_lock);
        ticket->t_curr_res = ticket->t_unit_res;
        xlog_tic_reset_res(ticket);
 }      /* xlog_regrant_reserve_log_space */
@@ -2769,12 +2766,10 @@ STATIC void
 xlog_ungrant_log_space(xlog_t       *log,
                       xlog_ticket_t *ticket)
 {
-       SPLDECL(s);
-
        if (ticket->t_cnt > 0)
                ticket->t_cnt--;
 
-       s = GRANT_LOCK(log);
+       spin_lock(&log->l_grant_lock);
        xlog_trace_loggrant(log, ticket, "xlog_ungrant_log_space: enter");
 
        xlog_grant_sub_space(log, ticket->t_curr_res);
@@ -2791,7 +2786,7 @@ xlog_ungrant_log_space(xlog_t          *log,
 
        xlog_trace_loggrant(log, ticket, "xlog_ungrant_log_space: exit");
        xlog_verify_grant_head(log, 1);
-       GRANT_UNLOCK(log, s);
+       spin_unlock(&log->l_grant_lock);
        xfs_log_move_tail(log->l_mp, 1);
 }      /* xlog_ungrant_log_space */
 
@@ -2799,15 +2794,13 @@ xlog_ungrant_log_space(xlog_t        *log,
 /*
  * Atomically put back used ticket.
  */
-void
+STATIC void
 xlog_state_put_ticket(xlog_t       *log,
                      xlog_ticket_t *tic)
 {
-       unsigned long s;
-
-       s = LOG_LOCK(log);
+       spin_lock(&log->l_icloglock);
        xlog_ticket_put(log, tic);
-       LOG_UNLOCK(log, s);
+       spin_unlock(&log->l_icloglock);
 }      /* xlog_state_put_ticket */
 
 /*
@@ -2819,19 +2812,18 @@ xlog_state_put_ticket(xlog_t        *log,
  *
  *
  */
-int
+STATIC int
 xlog_state_release_iclog(xlog_t                *log,
                         xlog_in_core_t *iclog)
 {
-       SPLDECL(s);
        int             sync = 0;       /* do we sync? */
 
        xlog_assign_tail_lsn(log->l_mp);
 
-       s = LOG_LOCK(log);
+       spin_lock(&log->l_icloglock);
 
        if (iclog->ic_state & XLOG_STATE_IOERROR) {
-               LOG_UNLOCK(log, s);
+               spin_unlock(&log->l_icloglock);
                return XFS_ERROR(EIO);
        }
 
@@ -2843,12 +2835,12 @@ xlog_state_release_iclog(xlog_t         *log,
            iclog->ic_state == XLOG_STATE_WANT_SYNC) {
                sync++;
                iclog->ic_state = XLOG_STATE_SYNCING;
-               INT_SET(iclog->ic_header.h_tail_lsn, ARCH_CONVERT, log->l_tail_lsn);
+               iclog->ic_header.h_tail_lsn = cpu_to_be64(log->l_tail_lsn);
                xlog_verify_tail_lsn(log, iclog, log->l_tail_lsn);
                /* cycle incremented when incrementing curr_block */
        }
 
-       LOG_UNLOCK(log, s);
+       spin_unlock(&log->l_icloglock);
 
        /*
         * We let the log lock go, so it's possible that we hit a log I/O
@@ -2881,7 +2873,7 @@ xlog_state_switch_iclogs(xlog_t           *log,
        if (!eventual_size)
                eventual_size = iclog->ic_offset;
        iclog->ic_state = XLOG_STATE_WANT_SYNC;
-       INT_SET(iclog->ic_header.h_prev_block, ARCH_CONVERT, log->l_prev_block);
+       iclog->ic_header.h_prev_block = cpu_to_be32(log->l_prev_block);
        log->l_prev_block = log->l_curr_block;
        log->l_prev_cycle = log->l_curr_cycle;
 
@@ -2939,13 +2931,12 @@ xlog_state_sync_all(xlog_t *log, uint flags, int *log_flushed)
 {
        xlog_in_core_t  *iclog;
        xfs_lsn_t       lsn;
-       SPLDECL(s);
 
-       s = LOG_LOCK(log);
+       spin_lock(&log->l_icloglock);
 
        iclog = log->l_iclog;
        if (iclog->ic_state & XLOG_STATE_IOERROR) {
-               LOG_UNLOCK(log, s);
+               spin_unlock(&log->l_icloglock);
                return XFS_ERROR(EIO);
        }
 
@@ -2978,15 +2969,15 @@ xlog_state_sync_all(xlog_t *log, uint flags, int *log_flushed)
                                 * the previous sync.
                                 */
                                iclog->ic_refcnt++;
-                               lsn = INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT);
+                               lsn = be64_to_cpu(iclog->ic_header.h_lsn);
                                xlog_state_switch_iclogs(log, iclog, 0);
-                               LOG_UNLOCK(log, s);
+                               spin_unlock(&log->l_icloglock);
 
                                if (xlog_state_release_iclog(log, iclog))
                                        return XFS_ERROR(EIO);
                                *log_flushed = 1;
-                               s = LOG_LOCK(log);
-                               if (INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT) == lsn &&
+                               spin_lock(&log->l_icloglock);
+                               if (be64_to_cpu(iclog->ic_header.h_lsn) == lsn &&
                                    iclog->ic_state != XLOG_STATE_DIRTY)
                                        goto maybe_sleep;
                                else
@@ -3011,12 +3002,12 @@ maybe_sleep:
        if (flags & XFS_LOG_SYNC) {
                /*
                 * We must check if we're shutting down here, before
-                * we wait, while we're holding the LOG_LOCK.
+                * we wait, while we're holding the l_icloglock.
                 * Then we check again after waking up, in case our
                 * sleep was disturbed by a bad news.
                 */
                if (iclog->ic_state & XLOG_STATE_IOERROR) {
-                       LOG_UNLOCK(log, s);
+                       spin_unlock(&log->l_icloglock);
                        return XFS_ERROR(EIO);
                }
                XFS_STATS_INC(xs_log_force_sleep);
@@ -3033,7 +3024,7 @@ maybe_sleep:
        } else {
 
 no_sleep:
-               LOG_UNLOCK(log, s);
+               spin_unlock(&log->l_icloglock);
        }
        return 0;
 }      /* xlog_state_sync_all */
@@ -3051,7 +3042,7 @@ no_sleep:
  * If filesystem activity goes to zero, the iclog will get flushed only by
  * bdflush().
  */
-int
+STATIC int
 xlog_state_sync(xlog_t   *log,
                xfs_lsn_t lsn,
                uint      flags,
@@ -3059,26 +3050,24 @@ xlog_state_sync(xlog_t    *log,
 {
     xlog_in_core_t     *iclog;
     int                        already_slept = 0;
-    SPLDECL(s);
-
 
 try_again:
-    s = LOG_LOCK(log);
+    spin_lock(&log->l_icloglock);
     iclog = log->l_iclog;
 
     if (iclog->ic_state & XLOG_STATE_IOERROR) {
-           LOG_UNLOCK(log, s);
+           spin_unlock(&log->l_icloglock);
            return XFS_ERROR(EIO);
     }
 
     do {
-       if (INT_GET(iclog->ic_header.h_lsn, ARCH_CONVERT) != lsn) {
-           iclog = iclog->ic_next;
-           continue;
+       if (be64_to_cpu(iclog->ic_header.h_lsn) != lsn) {
+               iclog = iclog->ic_next;
+               continue;
        }
 
        if (iclog->ic_state == XLOG_STATE_DIRTY) {
-               LOG_UNLOCK(log, s);
+               spin_unlock(&log->l_icloglock);
                return 0;
        }
 
@@ -3113,11 +3102,11 @@ try_again:
                } else {
                        iclog->ic_refcnt++;
                        xlog_state_switch_iclogs(log, iclog, 0);
-                       LOG_UNLOCK(log, s);
+                       spin_unlock(&log->l_icloglock);
                        if (xlog_state_release_iclog(log, iclog))
                                return XFS_ERROR(EIO);
                        *log_flushed = 1;
-                       s = LOG_LOCK(log);
+                       spin_lock(&log->l_icloglock);
                }
        }
 
@@ -3129,7 +3118,7 @@ try_again:
                 * gotten a log write error.
                 */
                if (iclog->ic_state & XLOG_STATE_IOERROR) {
-                       LOG_UNLOCK(log, s);
+                       spin_unlock(&log->l_icloglock);
                        return XFS_ERROR(EIO);
                }
                XFS_STATS_INC(xs_log_force_sleep);
@@ -3143,13 +3132,13 @@ try_again:
                        return XFS_ERROR(EIO);
                *log_flushed = 1;
        } else {                /* just return */
-               LOG_UNLOCK(log, s);
+               spin_unlock(&log->l_icloglock);
        }
        return 0;
 
     } while (iclog != log->l_iclog);
 
-    LOG_UNLOCK(log, s);
+    spin_unlock(&log->l_icloglock);
     return 0;
 }      /* xlog_state_sync */
 
@@ -3158,12 +3147,10 @@ try_again:
  * Called when we want to mark the current iclog as being ready to sync to
  * disk.
  */
-void
+STATIC void
 xlog_state_want_sync(xlog_t *log, xlog_in_core_t *iclog)
 {
-       SPLDECL(s);
-
-       s = LOG_LOCK(log);
+       spin_lock(&log->l_icloglock);
 
        if (iclog->ic_state == XLOG_STATE_ACTIVE) {
                xlog_state_switch_iclogs(log, iclog, 0);
@@ -3172,7 +3159,7 @@ xlog_state_want_sync(xlog_t *log, xlog_in_core_t *iclog)
                        (XLOG_STATE_WANT_SYNC|XLOG_STATE_IOERROR));
        }
 
-       LOG_UNLOCK(log, s);
+       spin_unlock(&log->l_icloglock);
 }      /* xlog_state_want_sync */
 
 
@@ -3193,16 +3180,15 @@ xlog_state_ticket_alloc(xlog_t *log)
        xlog_ticket_t   *t_list;
        xlog_ticket_t   *next;
        xfs_caddr_t     buf;
-       uint            i = (NBPP / sizeof(xlog_ticket_t)) - 2;
-       SPLDECL(s);
+       uint            i = (PAGE_SIZE / sizeof(xlog_ticket_t)) - 2;
 
        /*
         * The kmem_zalloc may sleep, so we shouldn't be holding the
         * global lock.  XXXmiken: may want to use zone allocator.
         */
-       buf = (xfs_caddr_t) kmem_zalloc(NBPP, KM_SLEEP);
+       buf = (xfs_caddr_t) kmem_zalloc(PAGE_SIZE, KM_SLEEP);
 
-       s = LOG_LOCK(log);
+       spin_lock(&log->l_icloglock);
 
        /* Attach 1st ticket to Q, so we can keep track of allocated memory */
        t_list = (xlog_ticket_t *)buf;
@@ -3231,7 +3217,7 @@ xlog_state_ticket_alloc(xlog_t *log)
        }
        t_list->t_next = NULL;
        log->l_tail = t_list;
-       LOG_UNLOCK(log, s);
+       spin_unlock(&log->l_icloglock);
 }      /* xlog_state_ticket_alloc */
 
 
@@ -3273,7 +3259,7 @@ xlog_ticket_put(xlog_t            *log,
 /*
  * Grab ticket off freelist or allocation some more
  */
-xlog_ticket_t *
+STATIC xlog_ticket_t *
 xlog_ticket_get(xlog_t         *log,
                int             unit_bytes,
                int             cnt,
@@ -3282,15 +3268,14 @@ xlog_ticket_get(xlog_t          *log,
 {
        xlog_ticket_t   *tic;
        uint            num_headers;
-       SPLDECL(s);
 
  alloc:
        if (log->l_freelist == NULL)
                xlog_state_ticket_alloc(log);           /* potentially sleep */
 
-       s = LOG_LOCK(log);
+       spin_lock(&log->l_icloglock);
        if (log->l_freelist == NULL) {
-               LOG_UNLOCK(log, s);
+               spin_unlock(&log->l_icloglock);
                goto alloc;
        }
        tic             = log->l_freelist;
@@ -3298,7 +3283,7 @@ xlog_ticket_get(xlog_t            *log,
        if (log->l_freelist == NULL)
                log->l_tail = NULL;
        log->l_ticket_cnt--;
-       LOG_UNLOCK(log, s);
+       spin_unlock(&log->l_icloglock);
 
        /*
         * Permanent reservations have up to 'cnt'-1 active log operations
@@ -3473,10 +3458,9 @@ xlog_verify_iclog(xlog_t  *log,
        __uint8_t               clientid;
        int                     len, i, j, k, op_len;
        int                     idx;
-       SPLDECL(s);
 
        /* check validity of iclog pointers */
-       s = LOG_LOCK(log);
+       spin_lock(&log->l_icloglock);
        icptr = log->l_iclog;
        for (i=0; i < log->l_iclog_bufs; i++) {
                if (icptr == NULL)
@@ -3485,21 +3469,21 @@ xlog_verify_iclog(xlog_t         *log,
        }
        if (icptr != log->l_iclog)
                xlog_panic("xlog_verify_iclog: corrupt iclog ring");
-       LOG_UNLOCK(log, s);
+       spin_unlock(&log->l_icloglock);
 
        /* check log magic numbers */
-       ptr = (xfs_caddr_t) &(iclog->ic_header);
-       if (INT_GET(*(uint *)ptr, ARCH_CONVERT) != XLOG_HEADER_MAGIC_NUM)
+       if (be32_to_cpu(iclog->ic_header.h_magicno) != XLOG_HEADER_MAGIC_NUM)
                xlog_panic("xlog_verify_iclog: invalid magic num");
 
-       for (ptr += BBSIZE; ptr < ((xfs_caddr_t)&(iclog->ic_header))+count;
+       ptr = (xfs_caddr_t) &iclog->ic_header;
+       for (ptr += BBSIZE; ptr < ((xfs_caddr_t)&iclog->ic_header) + count;
             ptr += BBSIZE) {
-               if (INT_GET(*(uint *)ptr, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM)
+               if (be32_to_cpu(*(__be32 *)ptr) == XLOG_HEADER_MAGIC_NUM)
                        xlog_panic("xlog_verify_iclog: unexpected magic num");
        }
 
        /* check fields */
-       len = INT_GET(iclog->ic_header.h_num_logops, ARCH_CONVERT);
+       len = be32_to_cpu(iclog->ic_header.h_num_logops);
        ptr = iclog->ic_datap;
        base_ptr = ptr;
        ophead = (xlog_op_header_t *)ptr;
@@ -3517,9 +3501,11 @@ xlog_verify_iclog(xlog_t  *log,
                        if (idx >= (XLOG_HEADER_CYCLE_SIZE / BBSIZE)) {
                                j = idx / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
                                k = idx % (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
-                               clientid = GET_CLIENT_ID(xhdr[j].hic_xheader.xh_cycle_data[k], ARCH_CONVERT);
+                               clientid = xlog_get_client_id(
+                                       xhdr[j].hic_xheader.xh_cycle_data[k]);
                        } else {
-                               clientid = GET_CLIENT_ID(iclog->ic_header.h_cycle_data[idx], ARCH_CONVERT);
+                               clientid = xlog_get_client_id(
+                                       iclog->ic_header.h_cycle_data[idx]);
                        }
                }
                if (clientid != XFS_TRANSACTION && clientid != XFS_LOG)
@@ -3531,16 +3517,16 @@ xlog_verify_iclog(xlog_t         *log,
                field_offset = (__psint_t)
                               ((xfs_caddr_t)&(ophead->oh_len) - base_ptr);
                if (syncing == B_FALSE || (field_offset & 0x1ff)) {
-                       op_len = INT_GET(ophead->oh_len, ARCH_CONVERT);
+                       op_len = be32_to_cpu(ophead->oh_len);
                } else {
                        idx = BTOBBT((__psint_t)&ophead->oh_len -
                                    (__psint_t)iclog->ic_datap);
                        if (idx >= (XLOG_HEADER_CYCLE_SIZE / BBSIZE)) {
                                j = idx / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
                                k = idx % (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
-                               op_len = INT_GET(xhdr[j].hic_xheader.xh_cycle_data[k], ARCH_CONVERT);
+                               op_len = be32_to_cpu(xhdr[j].hic_xheader.xh_cycle_data[k]);
                        } else {
-                               op_len = INT_GET(iclog->ic_header.h_cycle_data[idx], ARCH_CONVERT);
+                               op_len = be32_to_cpu(iclog->ic_header.h_cycle_data[idx]);
                        }
                }
                ptr += sizeof(xlog_op_header_t) + op_len;
@@ -3549,7 +3535,7 @@ xlog_verify_iclog(xlog_t   *log,
 #endif
 
 /*
- * Mark all iclogs IOERROR. LOG_LOCK is held by the caller.
+ * Mark all iclogs IOERROR. l_icloglock is held by the caller.
  */
 STATIC int
 xlog_state_ioerror(
@@ -3597,8 +3583,6 @@ xfs_log_force_umount(
        xlog_t          *log;
        int             retval;
        int             dummy;
-       SPLDECL(s);
-       SPLDECL(s2);
 
        log = mp->m_log;
 
@@ -3627,8 +3611,8 @@ xfs_log_force_umount(
         * before we mark the filesystem SHUTDOWN and wake
         * everybody up to tell the bad news.
         */
-       s = GRANT_LOCK(log);
-       s2 = LOG_LOCK(log);
+       spin_lock(&log->l_grant_lock);
+       spin_lock(&log->l_icloglock);
        mp->m_flags |= XFS_MOUNT_FS_SHUTDOWN;
        XFS_BUF_DONE(mp->m_sb_bp);
        /*
@@ -3644,7 +3628,7 @@ xfs_log_force_umount(
         */
        if (logerror)
                retval = xlog_state_ioerror(log);
-       LOG_UNLOCK(log, s2);
+       spin_unlock(&log->l_icloglock);
 
        /*
         * We don't want anybody waiting for log reservations
@@ -3667,7 +3651,7 @@ xfs_log_force_umount(
                        tic = tic->t_next;
                } while (tic != log->l_write_headq);
        }
-       GRANT_UNLOCK(log, s);
+       spin_unlock(&log->l_grant_lock);
 
        if (! (log->l_iclog->ic_state & XLOG_STATE_IOERROR)) {
                ASSERT(!logerror);
@@ -3676,9 +3660,9 @@ xfs_log_force_umount(
                 * log down completely.
                 */
                xlog_state_sync_all(log, XFS_LOG_FORCE|XFS_LOG_SYNC, &dummy);
-               s2 = LOG_LOCK(log);
+               spin_lock(&log->l_icloglock);
                retval = xlog_state_ioerror(log);
-               LOG_UNLOCK(log, s2);
+               spin_unlock(&log->l_icloglock);
        }
        /*
         * Wake up everybody waiting on xfs_log_force.
@@ -3691,13 +3675,13 @@ xfs_log_force_umount(
        {
                xlog_in_core_t  *iclog;
 
-               s = LOG_LOCK(log);
+               spin_lock(&log->l_icloglock);
                iclog = log->l_iclog;
                do {
                        ASSERT(iclog->ic_callback == 0);
                        iclog = iclog->ic_next;
                } while (iclog != log->l_iclog);
-               LOG_UNLOCK(log, s);
+               spin_unlock(&log->l_icloglock);
        }
 #endif
        /* return non-zero if log IOERROR transition had already happened */
index ebbe93f4f97bc7925a458996e2f8c11943223f9a..4cdac048df5e2265c3516ca402fcc547034a3206 100644 (file)
@@ -22,8 +22,9 @@
 
 #define CYCLE_LSN(lsn) ((uint)((lsn)>>32))
 #define BLOCK_LSN(lsn) ((uint)(lsn))
+
 /* this is used in a spot where we might otherwise double-endian-flip */
-#define CYCLE_LSN_DISK(lsn) (((uint *)&(lsn))[0])
+#define CYCLE_LSN_DISK(lsn) (((__be32 *)&(lsn))[0])
 
 #ifdef __KERNEL__
 /*
index 752f964b369965c0ec34746ff7fb566317138df0..e008233ee2492dd4b7c96f76ccaafc372b32201e 100644 (file)
@@ -55,32 +55,21 @@ struct xfs_mount;
        BTOBB(XLOG_MAX_ICLOGS << (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) ? \
         XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
 
-/*
- *  set lsns
- */
 
-#define ASSIGN_ANY_LSN_HOST(lsn,cycle,block)  \
-    { \
-       (lsn) = ((xfs_lsn_t)(cycle)<<32)|(block); \
-    }
-#define ASSIGN_ANY_LSN_DISK(lsn,cycle,block)  \
-    { \
-       INT_SET(((uint *)&(lsn))[0], ARCH_CONVERT, (cycle)); \
-       INT_SET(((uint *)&(lsn))[1], ARCH_CONVERT, (block)); \
-    }
-#define ASSIGN_LSN(lsn,log) \
-    ASSIGN_ANY_LSN_DISK(lsn,(log)->l_curr_cycle,(log)->l_curr_block);
-
-#define XLOG_SET(f,b)          (((f) & (b)) == (b))
-
-#define GET_CYCLE(ptr, arch) \
-    (INT_GET(*(uint *)(ptr), arch) == XLOG_HEADER_MAGIC_NUM ? \
-        INT_GET(*((uint *)(ptr)+1), arch) : \
-        INT_GET(*(uint *)(ptr), arch) \
-    )
+static inline xfs_lsn_t xlog_assign_lsn(uint cycle, uint block)
+{
+       return ((xfs_lsn_t)cycle << 32) | block;
+}
 
-#define BLK_AVG(blk1, blk2)    ((blk1+blk2) >> 1)
+static inline uint xlog_get_cycle(char *ptr)
+{
+       if (be32_to_cpu(*(__be32 *)ptr) == XLOG_HEADER_MAGIC_NUM)
+               return be32_to_cpu(*((__be32 *)ptr + 1));
+       else
+               return be32_to_cpu(*(__be32 *)ptr);
+}
 
+#define BLK_AVG(blk1, blk2)    ((blk1+blk2) >> 1)
 
 #ifdef __KERNEL__
 
@@ -96,19 +85,10 @@ struct xfs_mount;
  *
  * this has endian issues, of course.
  */
-
-#ifndef XFS_NATIVE_HOST
-#define GET_CLIENT_ID(i,arch) \
-    ((i) & 0xff)
-#else
-#define GET_CLIENT_ID(i,arch) \
-    ((i) >> 24)
-#endif
-
-#define GRANT_LOCK(log)                mutex_spinlock(&(log)->l_grant_lock)
-#define GRANT_UNLOCK(log, s)   mutex_spinunlock(&(log)->l_grant_lock, s)
-#define LOG_LOCK(log)          mutex_spinlock(&(log)->l_icloglock)
-#define LOG_UNLOCK(log, s)     mutex_spinunlock(&(log)->l_icloglock, s)
+static inline uint xlog_get_client_id(__be32 i)
+{
+       return be32_to_cpu(i) >> 24;
+}
 
 #define xlog_panic(args...)    cmn_err(CE_PANIC, ## args)
 #define xlog_exit(args...)     cmn_err(CE_PANIC, ## args)
@@ -285,11 +265,11 @@ typedef struct xlog_ticket {
 
 
 typedef struct xlog_op_header {
-       xlog_tid_t oh_tid;      /* transaction id of operation  :  4 b */
-       int        oh_len;      /* bytes in data region         :  4 b */
-       __uint8_t  oh_clientid; /* who sent me this             :  1 b */
-       __uint8_t  oh_flags;    /*                              :  1 b */
-       ushort     oh_res2;     /* 32 bit align                 :  2 b */
+       __be32     oh_tid;      /* transaction id of operation  :  4 b */
+       __be32     oh_len;      /* bytes in data region         :  4 b */
+       __u8       oh_clientid; /* who sent me this             :  1 b */
+       __u8       oh_flags;    /*                              :  1 b */
+       __u16      oh_res2;     /* 32 bit align                 :  2 b */
 } xlog_op_header_t;
 
 
@@ -307,25 +287,25 @@ typedef struct xlog_op_header {
 #endif
 
 typedef struct xlog_rec_header {
-       uint      h_magicno;    /* log record (LR) identifier           :  4 */
-       uint      h_cycle;      /* write cycle of log                   :  4 */
-       int       h_version;    /* LR version                           :  4 */
-       int       h_len;        /* len in bytes; should be 64-bit aligned: 4 */
-       xfs_lsn_t h_lsn;        /* lsn of this LR                       :  8 */
-       xfs_lsn_t h_tail_lsn;   /* lsn of 1st LR w/ buffers not committed: 8 */
-       uint      h_chksum;     /* may not be used; non-zero if used    :  4 */
-       int       h_prev_block; /* block number to previous LR          :  4 */
-       int       h_num_logops; /* number of log operations in this LR  :  4 */
-       uint      h_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE];
+       __be32    h_magicno;    /* log record (LR) identifier           :  4 */
+       __be32    h_cycle;      /* write cycle of log                   :  4 */
+       __be32    h_version;    /* LR version                           :  4 */
+       __be32    h_len;        /* len in bytes; should be 64-bit aligned: 4 */
+       __be64    h_lsn;        /* lsn of this LR                       :  8 */
+       __be64    h_tail_lsn;   /* lsn of 1st LR w/ buffers not committed: 8 */
+       __be32    h_chksum;     /* may not be used; non-zero if used    :  4 */
+       __be32    h_prev_block; /* block number to previous LR          :  4 */
+       __be32    h_num_logops; /* number of log operations in this LR  :  4 */
+       __be32    h_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE];
        /* new fields */
-       int       h_fmt;        /* format of log record                 :  4 */
-       uuid_t    h_fs_uuid;    /* uuid of FS                           : 16 */
-       int       h_size;       /* iclog size                           :  4 */
+       __be32    h_fmt;        /* format of log record                 :  4 */
+       uuid_t    h_fs_uuid;    /* uuid of FS                           : 16 */
+       __be32    h_size;       /* iclog size                           :  4 */
 } xlog_rec_header_t;
 
 typedef struct xlog_rec_ext_header {
-       uint      xh_cycle;     /* write cycle of log                   : 4 */
-       uint      xh_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE]; /*    : 256 */
+       __be32    xh_cycle;     /* write cycle of log                   : 4 */
+       __be32    xh_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE]; /*    : 256 */
 } xlog_rec_ext_header_t;
 
 #ifdef __KERNEL__
@@ -415,7 +395,7 @@ typedef struct log {
        xlog_ticket_t           *l_unmount_free;/* kmem_free these addresses */
        xlog_ticket_t           *l_tail;        /* free list of tickets */
        xlog_in_core_t          *l_iclog;       /* head log queue       */
-       lock_t                  l_icloglock;    /* grab to change iclog state */
+       spinlock_t              l_icloglock;    /* grab to change iclog state */
        xfs_lsn_t               l_tail_lsn;     /* lsn of 1st LR with unflushed
                                                 * buffers */
        xfs_lsn_t               l_last_sync_lsn;/* lsn of last LR on disk */
@@ -439,7 +419,7 @@ typedef struct log {
        char                    *l_iclog_bak[XLOG_MAX_ICLOGS];
 
        /* The following block of fields are changed while holding grant_lock */
-       lock_t                  l_grant_lock;
+       spinlock_t              l_grant_lock;
        xlog_ticket_t           *l_reserve_headq;
        xlog_ticket_t           *l_write_headq;
        int                     l_grant_reserve_cycle;
index 851eca8a7150e7746728941a4a2c1ca7898e8054..b82d5d4d2462898e4d1d383ddd6456262104516e 100644 (file)
@@ -198,7 +198,7 @@ xlog_header_check_dump(
        cmn_err(CE_DEBUG, "    log : uuid = ");
        for (b = 0; b < 16; b++)
                cmn_err(CE_DEBUG, "%02x",((uchar_t *)&head->h_fs_uuid)[b]);
-       cmn_err(CE_DEBUG, ", fmt = %d\n", INT_GET(head->h_fmt, ARCH_CONVERT));
+       cmn_err(CE_DEBUG, ", fmt = %d\n", be32_to_cpu(head->h_fmt));
 }
 #else
 #define xlog_header_check_dump(mp, head)
@@ -212,14 +212,14 @@ xlog_header_check_recover(
        xfs_mount_t             *mp,
        xlog_rec_header_t       *head)
 {
-       ASSERT(INT_GET(head->h_magicno, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM);
+       ASSERT(be32_to_cpu(head->h_magicno) == XLOG_HEADER_MAGIC_NUM);
 
        /*
         * IRIX doesn't write the h_fmt field and leaves it zeroed
         * (XLOG_FMT_UNKNOWN). This stops us from trying to recover
         * a dirty log created in IRIX.
         */
-       if (unlikely(INT_GET(head->h_fmt, ARCH_CONVERT) != XLOG_FMT)) {
+       if (unlikely(be32_to_cpu(head->h_fmt) != XLOG_FMT)) {
                xlog_warn(
        "XFS: dirty log written in incompatible format - can't recover");
                xlog_header_check_dump(mp, head);
@@ -245,7 +245,7 @@ xlog_header_check_mount(
        xfs_mount_t             *mp,
        xlog_rec_header_t       *head)
 {
-       ASSERT(INT_GET(head->h_magicno, ARCH_CONVERT) == XLOG_HEADER_MAGIC_NUM);
+       ASSERT(be32_to_cpu(head->h_magicno) == XLOG_HEADER_MAGIC_NUM);
 
        if (uuid_is_nil(&head->h_fs_uuid)) {
                /*
@@ -293,7 +293,7 @@ xlog_recover_iodone(
  * Note that the algorithm can not be perfect because the disk will not
  * necessarily be perfect.
  */
-int
+STATIC int
 xlog_find_cycle_start(
        xlog_t          *log,
        xfs_buf_t       *bp,
@@ -311,7 +311,7 @@ xlog_find_cycle_start(
                if ((error = xlog_bread(log, mid_blk, 1, bp)))
                        return error;
                offset = xlog_align(log, mid_blk, 1, bp);
-               mid_cycle = GET_CYCLE(offset, ARCH_CONVERT);
+               mid_cycle = xlog_get_cycle(offset);
                if (mid_cycle == cycle) {
                        *last_blk = mid_blk;
                        /* last_half_cycle == mid_cycle */
@@ -371,7 +371,7 @@ xlog_find_verify_cycle(
 
                buf = xlog_align(log, i, bcount, bp);
                for (j = 0; j < bcount; j++) {
-                       cycle = GET_CYCLE(buf, ARCH_CONVERT);
+                       cycle = xlog_get_cycle(buf);
                        if (cycle == stop_on_cycle_no) {
                                *new_blk = i+j;
                                goto out;
@@ -447,8 +447,7 @@ xlog_find_verify_log_record(
 
                head = (xlog_rec_header_t *)offset;
 
-               if (XLOG_HEADER_MAGIC_NUM ==
-                   INT_GET(head->h_magicno, ARCH_CONVERT))
+               if (XLOG_HEADER_MAGIC_NUM == be32_to_cpu(head->h_magicno))
                        break;
 
                if (!smallmem)
@@ -480,7 +479,7 @@ xlog_find_verify_log_record(
         * record do we update last_blk.
         */
        if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) {
-               uint    h_size = INT_GET(head->h_size, ARCH_CONVERT);
+               uint    h_size = be32_to_cpu(head->h_size);
 
                xhdrs = h_size / XLOG_HEADER_CYCLE_SIZE;
                if (h_size % XLOG_HEADER_CYCLE_SIZE)
@@ -489,8 +488,8 @@ xlog_find_verify_log_record(
                xhdrs = 1;
        }
 
-       if (*last_blk - i + extra_bblks
-                       != BTOBB(INT_GET(head->h_len, ARCH_CONVERT)) + xhdrs)
+       if (*last_blk - i + extra_bblks !=
+           BTOBB(be32_to_cpu(head->h_len)) + xhdrs)
                *last_blk = i;
 
 out:
@@ -550,13 +549,13 @@ xlog_find_head(
        if ((error = xlog_bread(log, 0, 1, bp)))
                goto bp_err;
        offset = xlog_align(log, 0, 1, bp);
-       first_half_cycle = GET_CYCLE(offset, ARCH_CONVERT);
+       first_half_cycle = xlog_get_cycle(offset);
 
        last_blk = head_blk = log_bbnum - 1;    /* get cycle # of last block */
        if ((error = xlog_bread(log, last_blk, 1, bp)))
                goto bp_err;
        offset = xlog_align(log, last_blk, 1, bp);
-       last_half_cycle = GET_CYCLE(offset, ARCH_CONVERT);
+       last_half_cycle = xlog_get_cycle(offset);
        ASSERT(last_half_cycle != 0);
 
        /*
@@ -808,7 +807,7 @@ xlog_find_tail(
                if ((error = xlog_bread(log, 0, 1, bp)))
                        goto bread_err;
                offset = xlog_align(log, 0, 1, bp);
-               if (GET_CYCLE(offset, ARCH_CONVERT) == 0) {
+               if (xlog_get_cycle(offset) == 0) {
                        *tail_blk = 0;
                        /* leave all other log inited values alone */
                        goto exit;
@@ -823,8 +822,7 @@ xlog_find_tail(
                if ((error = xlog_bread(log, i, 1, bp)))
                        goto bread_err;
                offset = xlog_align(log, i, 1, bp);
-               if (XLOG_HEADER_MAGIC_NUM ==
-                   INT_GET(*(uint *)offset, ARCH_CONVERT)) {
+               if (XLOG_HEADER_MAGIC_NUM == be32_to_cpu(*(__be32 *)offset)) {
                        found = 1;
                        break;
                }
@@ -841,7 +839,7 @@ xlog_find_tail(
                                goto bread_err;
                        offset = xlog_align(log, i, 1, bp);
                        if (XLOG_HEADER_MAGIC_NUM ==
-                           INT_GET(*(uint*)offset, ARCH_CONVERT)) {
+                           be32_to_cpu(*(__be32 *)offset)) {
                                found = 2;
                                break;
                        }
@@ -855,7 +853,7 @@ xlog_find_tail(
 
        /* find blk_no of tail of log */
        rhead = (xlog_rec_header_t *)offset;
-       *tail_blk = BLOCK_LSN(INT_GET(rhead->h_tail_lsn, ARCH_CONVERT));
+       *tail_blk = BLOCK_LSN(be64_to_cpu(rhead->h_tail_lsn));
 
        /*
         * Reset log values according to the state of the log when we
@@ -869,11 +867,11 @@ xlog_find_tail(
         */
        log->l_prev_block = i;
        log->l_curr_block = (int)*head_blk;
-       log->l_curr_cycle = INT_GET(rhead->h_cycle, ARCH_CONVERT);
+       log->l_curr_cycle = be32_to_cpu(rhead->h_cycle);
        if (found == 2)
                log->l_curr_cycle++;
-       log->l_tail_lsn = INT_GET(rhead->h_tail_lsn, ARCH_CONVERT);
-       log->l_last_sync_lsn = INT_GET(rhead->h_lsn, ARCH_CONVERT);
+       log->l_tail_lsn = be64_to_cpu(rhead->h_tail_lsn);
+       log->l_last_sync_lsn = be64_to_cpu(rhead->h_lsn);
        log->l_grant_reserve_cycle = log->l_curr_cycle;
        log->l_grant_reserve_bytes = BBTOB(log->l_curr_block);
        log->l_grant_write_cycle = log->l_curr_cycle;
@@ -891,8 +889,8 @@ xlog_find_tail(
         * unmount record rather than the block after it.
         */
        if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) {
-               int     h_size = INT_GET(rhead->h_size, ARCH_CONVERT);
-               int     h_version = INT_GET(rhead->h_version, ARCH_CONVERT);
+               int     h_size = be32_to_cpu(rhead->h_size);
+               int     h_version = be32_to_cpu(rhead->h_version);
 
                if ((h_version & XLOG_VERSION_2) &&
                    (h_size > XLOG_HEADER_CYCLE_SIZE)) {
@@ -906,10 +904,10 @@ xlog_find_tail(
                hblks = 1;
        }
        after_umount_blk = (i + hblks + (int)
-               BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT))) % log->l_logBBsize;
+               BTOBB(be32_to_cpu(rhead->h_len))) % log->l_logBBsize;
        tail_lsn = log->l_tail_lsn;
        if (*head_blk == after_umount_blk &&
-           INT_GET(rhead->h_num_logops, ARCH_CONVERT) == 1) {
+           be32_to_cpu(rhead->h_num_logops) == 1) {
                umount_data_blk = (i + hblks) % log->l_logBBsize;
                if ((error = xlog_bread(log, umount_data_blk, 1, bp))) {
                        goto bread_err;
@@ -922,10 +920,12 @@ xlog_find_tail(
                         * log records will point recovery to after the
                         * current unmount record.
                         */
-                       ASSIGN_ANY_LSN_HOST(log->l_tail_lsn, log->l_curr_cycle,
-                                       after_umount_blk);
-                       ASSIGN_ANY_LSN_HOST(log->l_last_sync_lsn, log->l_curr_cycle,
-                                       after_umount_blk);
+                       log->l_tail_lsn =
+                               xlog_assign_lsn(log->l_curr_cycle,
+                                               after_umount_blk);
+                       log->l_last_sync_lsn =
+                               xlog_assign_lsn(log->l_curr_cycle,
+                                               after_umount_blk);
                        *tail_blk = after_umount_blk;
 
                        /*
@@ -986,7 +986,7 @@ exit:
  *     -1 => use *blk_no as the first block of the log
  *     >0 => error has occurred
  */
-int
+STATIC int
 xlog_find_zeroed(
        xlog_t          *log,
        xfs_daddr_t     *blk_no)
@@ -1007,7 +1007,7 @@ xlog_find_zeroed(
        if ((error = xlog_bread(log, 0, 1, bp)))
                goto bp_err;
        offset = xlog_align(log, 0, 1, bp);
-       first_cycle = GET_CYCLE(offset, ARCH_CONVERT);
+       first_cycle = xlog_get_cycle(offset);
        if (first_cycle == 0) {         /* completely zeroed log */
                *blk_no = 0;
                xlog_put_bp(bp);
@@ -1018,7 +1018,7 @@ xlog_find_zeroed(
        if ((error = xlog_bread(log, log_bbnum-1, 1, bp)))
                goto bp_err;
        offset = xlog_align(log, log_bbnum-1, 1, bp);
-       last_cycle = GET_CYCLE(offset, ARCH_CONVERT);
+       last_cycle = xlog_get_cycle(offset);
        if (last_cycle != 0) {          /* log completely written to */
                xlog_put_bp(bp);
                return 0;
@@ -1098,13 +1098,13 @@ xlog_add_record(
        xlog_rec_header_t       *recp = (xlog_rec_header_t *)buf;
 
        memset(buf, 0, BBSIZE);
-       INT_SET(recp->h_magicno, ARCH_CONVERT, XLOG_HEADER_MAGIC_NUM);
-       INT_SET(recp->h_cycle, ARCH_CONVERT, cycle);
-       INT_SET(recp->h_version, ARCH_CONVERT,
+       recp->h_magicno = cpu_to_be32(XLOG_HEADER_MAGIC_NUM);
+       recp->h_cycle = cpu_to_be32(cycle);
+       recp->h_version = cpu_to_be32(
                        XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb) ? 2 : 1);
-       ASSIGN_ANY_LSN_DISK(recp->h_lsn, cycle, block);
-       ASSIGN_ANY_LSN_DISK(recp->h_tail_lsn, tail_cycle, tail_block);
-       INT_SET(recp->h_fmt, ARCH_CONVERT, XLOG_FMT);
+       recp->h_lsn = cpu_to_be64(xlog_assign_lsn(cycle, block));
+       recp->h_tail_lsn = cpu_to_be64(xlog_assign_lsn(tail_cycle, tail_block));
+       recp->h_fmt = cpu_to_be32(XLOG_FMT);
        memcpy(&recp->h_fs_uuid, &log->l_mp->m_sb.sb_uuid, sizeof(uuid_t));
 }
 
@@ -2211,7 +2211,7 @@ xlog_recover_do_buffer_trans(
         * overlap with future reads of those inodes.
         */
        if (XFS_DINODE_MAGIC ==
-           INT_GET(*((__uint16_t *)(xfs_buf_offset(bp, 0))), ARCH_CONVERT) &&
+           be16_to_cpu(*((__be16 *)xfs_buf_offset(bp, 0))) &&
            (XFS_BUF_COUNT(bp) != MAX(log->l_mp->m_sb.sb_blocksize,
                        (__uint32_t)XFS_INODE_CLUSTER_SIZE(log->l_mp)))) {
                XFS_BUF_STALE(bp);
@@ -2581,8 +2581,7 @@ xlog_recover_do_dquot_trans(
        /*
         * This type of quotas was turned off, so ignore this record.
         */
-       type = INT_GET(recddq->d_flags, ARCH_CONVERT) &
-                       (XFS_DQ_USER | XFS_DQ_PROJ | XFS_DQ_GROUP);
+       type = recddq->d_flags & (XFS_DQ_USER | XFS_DQ_PROJ | XFS_DQ_GROUP);
        ASSERT(type);
        if (log->l_quotaoffs_flag & type)
                return (0);
@@ -2660,7 +2659,6 @@ xlog_recover_do_efi_trans(
        xfs_mount_t             *mp;
        xfs_efi_log_item_t      *efip;
        xfs_efi_log_format_t    *efi_formatp;
-       SPLDECL(s);
 
        if (pass == XLOG_RECOVER_PASS1) {
                return 0;
@@ -2678,11 +2676,11 @@ xlog_recover_do_efi_trans(
        efip->efi_next_extent = efi_formatp->efi_nextents;
        efip->efi_flags |= XFS_EFI_COMMITTED;
 
-       AIL_LOCK(mp,s);
+       spin_lock(&mp->m_ail_lock);
        /*
         * xfs_trans_update_ail() drops the AIL lock.
         */
-       xfs_trans_update_ail(mp, (xfs_log_item_t *)efip, lsn, s);
+       xfs_trans_update_ail(mp, (xfs_log_item_t *)efip, lsn);
        return 0;
 }
 
@@ -2707,7 +2705,6 @@ xlog_recover_do_efd_trans(
        xfs_log_item_t          *lip;
        int                     gen;
        __uint64_t              efi_id;
-       SPLDECL(s);
 
        if (pass == XLOG_RECOVER_PASS1) {
                return;
@@ -2725,7 +2722,7 @@ xlog_recover_do_efd_trans(
         * in the AIL.
         */
        mp = log->l_mp;
-       AIL_LOCK(mp,s);
+       spin_lock(&mp->m_ail_lock);
        lip = xfs_trans_first_ail(mp, &gen);
        while (lip != NULL) {
                if (lip->li_type == XFS_LI_EFI) {
@@ -2735,22 +2732,14 @@ xlog_recover_do_efd_trans(
                                 * xfs_trans_delete_ail() drops the
                                 * AIL lock.
                                 */
-                               xfs_trans_delete_ail(mp, lip, s);
-                               break;
+                               xfs_trans_delete_ail(mp, lip);
+                               xfs_efi_item_free(efip);
+                               return;
                        }
                }
                lip = xfs_trans_next_ail(mp, lip, &gen, NULL);
        }
-
-       /*
-        * If we found it, then free it up.  If it wasn't there, it
-        * must have been overwritten in the log.  Oh well.
-        */
-       if (lip != NULL) {
-               xfs_efi_item_free(efip);
-       } else {
-               AIL_UNLOCK(mp, s);
-       }
+       spin_unlock(&mp->m_ail_lock);
 }
 
 /*
@@ -2897,8 +2886,8 @@ xlog_recover_process_data(
        unsigned long           hash;
        uint                    flags;
 
-       lp = dp + INT_GET(rhead->h_len, ARCH_CONVERT);
-       num_logops = INT_GET(rhead->h_num_logops, ARCH_CONVERT);
+       lp = dp + be32_to_cpu(rhead->h_len);
+       num_logops = be32_to_cpu(rhead->h_num_logops);
 
        /* check the log format matches our own - else we can't recover */
        if (xlog_header_check_recover(log->l_mp, rhead))
@@ -2915,15 +2904,20 @@ xlog_recover_process_data(
                        ASSERT(0);
                        return (XFS_ERROR(EIO));
                }
-               tid = INT_GET(ohead->oh_tid, ARCH_CONVERT);
+               tid = be32_to_cpu(ohead->oh_tid);
                hash = XLOG_RHASH(tid);
                trans = xlog_recover_find_tid(rhash[hash], tid);
                if (trans == NULL) {               /* not found; add new tid */
                        if (ohead->oh_flags & XLOG_START_TRANS)
                                xlog_recover_new_tid(&rhash[hash], tid,
-                                       INT_GET(rhead->h_lsn, ARCH_CONVERT));
+                                       be64_to_cpu(rhead->h_lsn));
                } else {
-                       ASSERT(dp+INT_GET(ohead->oh_len, ARCH_CONVERT) <= lp);
+                       if (dp + be32_to_cpu(ohead->oh_len) > lp) {
+                               xlog_warn(
+                       "XFS: xlog_recover_process_data: bad length");
+                               WARN_ON(1);
+                               return (XFS_ERROR(EIO));
+                       }
                        flags = ohead->oh_flags & ~XLOG_END_TRANS;
                        if (flags & XLOG_WAS_CONT_TRANS)
                                flags &= ~XLOG_CONTINUE_TRANS;
@@ -2937,8 +2931,7 @@ xlog_recover_process_data(
                                break;
                        case XLOG_WAS_CONT_TRANS:
                                error = xlog_recover_add_to_cont_trans(trans,
-                                               dp, INT_GET(ohead->oh_len,
-                                                       ARCH_CONVERT));
+                                               dp, be32_to_cpu(ohead->oh_len));
                                break;
                        case XLOG_START_TRANS:
                                xlog_warn(
@@ -2949,8 +2942,7 @@ xlog_recover_process_data(
                        case 0:
                        case XLOG_CONTINUE_TRANS:
                                error = xlog_recover_add_to_trans(trans,
-                                               dp, INT_GET(ohead->oh_len,
-                                                       ARCH_CONVERT));
+                                               dp, be32_to_cpu(ohead->oh_len));
                                break;
                        default:
                                xlog_warn(
@@ -2962,7 +2954,7 @@ xlog_recover_process_data(
                        if (error)
                                return error;
                }
-               dp += INT_GET(ohead->oh_len, ARCH_CONVERT);
+               dp += be32_to_cpu(ohead->oh_len);
                num_logops--;
        }
        return 0;
@@ -3075,10 +3067,9 @@ xlog_recover_process_efis(
        xfs_efi_log_item_t      *efip;
        int                     gen;
        xfs_mount_t             *mp;
-       SPLDECL(s);
 
        mp = log->l_mp;
-       AIL_LOCK(mp,s);
+       spin_lock(&mp->m_ail_lock);
 
        lip = xfs_trans_first_ail(mp, &gen);
        while (lip != NULL) {
@@ -3099,12 +3090,12 @@ xlog_recover_process_efis(
                        continue;
                }
 
-               AIL_UNLOCK(mp, s);
+               spin_unlock(&mp->m_ail_lock);
                xlog_recover_process_efi(mp, efip);
-               AIL_LOCK(mp,s);
+               spin_lock(&mp->m_ail_lock);
                lip = xfs_trans_next_ail(mp, lip, &gen, NULL);
        }
-       AIL_UNLOCK(mp, s);
+       spin_unlock(&mp->m_ail_lock);
 }
 
 /*
@@ -3315,16 +3306,16 @@ xlog_pack_data_checksum(
        int             size)
 {
        int             i;
-       uint            *up;
+       __be32          *up;
        uint            chksum = 0;
 
-       up = (uint *)iclog->ic_datap;
+       up = (__be32 *)iclog->ic_datap;
        /* divide length by 4 to get # words */
        for (i = 0; i < (size >> 2); i++) {
-               chksum ^= INT_GET(*up, ARCH_CONVERT);
+               chksum ^= be32_to_cpu(*up);
                up++;
        }
-       INT_SET(iclog->ic_header.h_chksum, ARCH_CONVERT, chksum);
+       iclog->ic_header.h_chksum = cpu_to_be32(chksum);
 }
 #else
 #define xlog_pack_data_checksum(log, iclog, size)
@@ -3341,7 +3332,7 @@ xlog_pack_data(
 {
        int                     i, j, k;
        int                     size = iclog->ic_offset + roundoff;
-       uint                    cycle_lsn;
+       __be32                  cycle_lsn;
        xfs_caddr_t             dp;
        xlog_in_core_2_t        *xhdr;
 
@@ -3352,8 +3343,8 @@ xlog_pack_data(
        dp = iclog->ic_datap;
        for (i = 0; i < BTOBB(size) &&
                i < (XLOG_HEADER_CYCLE_SIZE / BBSIZE); i++) {
-               iclog->ic_header.h_cycle_data[i] = *(uint *)dp;
-               *(uint *)dp = cycle_lsn;
+               iclog->ic_header.h_cycle_data[i] = *(__be32 *)dp;
+               *(__be32 *)dp = cycle_lsn;
                dp += BBSIZE;
        }
 
@@ -3362,8 +3353,8 @@ xlog_pack_data(
                for ( ; i < BTOBB(size); i++) {
                        j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
                        k = i % (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
-                       xhdr[j].hic_xheader.xh_cycle_data[k] = *(uint *)dp;
-                       *(uint *)dp = cycle_lsn;
+                       xhdr[j].hic_xheader.xh_cycle_data[k] = *(__be32 *)dp;
+                       *(__be32 *)dp = cycle_lsn;
                        dp += BBSIZE;
                }
 
@@ -3380,21 +3371,21 @@ xlog_unpack_data_checksum(
        xfs_caddr_t             dp,
        xlog_t                  *log)
 {
-       uint                    *up = (uint *)dp;
+       __be32                  *up = (__be32 *)dp;
        uint                    chksum = 0;
        int                     i;
 
        /* divide length by 4 to get # words */
-       for (i=0; i < INT_GET(rhead->h_len, ARCH_CONVERT) >> 2; i++) {
-               chksum ^= INT_GET(*up, ARCH_CONVERT);
+       for (i=0; i < be32_to_cpu(rhead->h_len) >> 2; i++) {
+               chksum ^= be32_to_cpu(*up);
                up++;
        }
-       if (chksum != INT_GET(rhead->h_chksum, ARCH_CONVERT)) {
+       if (chksum != be32_to_cpu(rhead->h_chksum)) {
            if (rhead->h_chksum ||
                ((log->l_flags & XLOG_CHKSUM_MISMATCH) == 0)) {
                    cmn_err(CE_DEBUG,
                        "XFS: LogR chksum mismatch: was (0x%x) is (0x%x)\n",
-                           INT_GET(rhead->h_chksum, ARCH_CONVERT), chksum);
+                           be32_to_cpu(rhead->h_chksum), chksum);
                    cmn_err(CE_DEBUG,
 "XFS: Disregard message if filesystem was created with non-DEBUG kernel");
                    if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) {
@@ -3418,18 +3409,18 @@ xlog_unpack_data(
        int                     i, j, k;
        xlog_in_core_2_t        *xhdr;
 
-       for (i = 0; i < BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT)) &&
+       for (i = 0; i < BTOBB(be32_to_cpu(rhead->h_len)) &&
                  i < (XLOG_HEADER_CYCLE_SIZE / BBSIZE); i++) {
-               *(uint *)dp = *(uint *)&rhead->h_cycle_data[i];
+               *(__be32 *)dp = *(__be32 *)&rhead->h_cycle_data[i];
                dp += BBSIZE;
        }
 
        if (XFS_SB_VERSION_HASLOGV2(&log->l_mp->m_sb)) {
                xhdr = (xlog_in_core_2_t *)rhead;
-               for ( ; i < BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT)); i++) {
+               for ( ; i < BTOBB(be32_to_cpu(rhead->h_len)); i++) {
                        j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
                        k = i % (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
-                       *(uint *)dp = xhdr[j].hic_xheader.xh_cycle_data[k];
+                       *(__be32 *)dp = xhdr[j].hic_xheader.xh_cycle_data[k];
                        dp += BBSIZE;
                }
        }
@@ -3445,24 +3436,21 @@ xlog_valid_rec_header(
 {
        int                     hlen;
 
-       if (unlikely(
-           (INT_GET(rhead->h_magicno, ARCH_CONVERT) !=
-                       XLOG_HEADER_MAGIC_NUM))) {
+       if (unlikely(be32_to_cpu(rhead->h_magicno) != XLOG_HEADER_MAGIC_NUM)) {
                XFS_ERROR_REPORT("xlog_valid_rec_header(1)",
                                XFS_ERRLEVEL_LOW, log->l_mp);
                return XFS_ERROR(EFSCORRUPTED);
        }
        if (unlikely(
            (!rhead->h_version ||
-           (INT_GET(rhead->h_version, ARCH_CONVERT) &
-                       (~XLOG_VERSION_OKBITS)) != 0))) {
+           (be32_to_cpu(rhead->h_version) & (~XLOG_VERSION_OKBITS))))) {
                xlog_warn("XFS: %s: unrecognised log version (%d).",
-                       __FUNCTION__, INT_GET(rhead->h_version, ARCH_CONVERT));
+                       __FUNCTION__, be32_to_cpu(rhead->h_version));
                return XFS_ERROR(EIO);
        }
 
        /* LR body must have data or it wouldn't have been written */
-       hlen = INT_GET(rhead->h_len, ARCH_CONVERT);
+       hlen = be32_to_cpu(rhead->h_len);
        if (unlikely( hlen <= 0 || hlen > INT_MAX )) {
                XFS_ERROR_REPORT("xlog_valid_rec_header(2)",
                                XFS_ERRLEVEL_LOW, log->l_mp);
@@ -3522,9 +3510,8 @@ xlog_do_recovery_pass(
                error = xlog_valid_rec_header(log, rhead, tail_blk);
                if (error)
                        goto bread_err1;
-               h_size = INT_GET(rhead->h_size, ARCH_CONVERT);
-               if ((INT_GET(rhead->h_version, ARCH_CONVERT)
-                               & XLOG_VERSION_2) &&
+               h_size = be32_to_cpu(rhead->h_size);
+               if ((be32_to_cpu(rhead->h_version) & XLOG_VERSION_2) &&
                    (h_size > XLOG_HEADER_CYCLE_SIZE)) {
                        hblks = h_size / XLOG_HEADER_CYCLE_SIZE;
                        if (h_size % XLOG_HEADER_CYCLE_SIZE)
@@ -3561,7 +3548,7 @@ xlog_do_recovery_pass(
                                goto bread_err2;
 
                        /* blocks in data section */
-                       bblks = (int)BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT));
+                       bblks = (int)BTOBB(be32_to_cpu(rhead->h_len));
                        error = xlog_bread(log, blk_no + hblks, bblks, dbp);
                        if (error)
                                goto bread_err2;
@@ -3636,7 +3623,7 @@ xlog_do_recovery_pass(
                        if (error)
                                goto bread_err2;
 
-                       bblks = (int)BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT));
+                       bblks = (int)BTOBB(be32_to_cpu(rhead->h_len));
                        blk_no += hblks;
 
                        /* Read in data for log record */
@@ -3707,7 +3694,7 @@ xlog_do_recovery_pass(
                        error = xlog_valid_rec_header(log, rhead, blk_no);
                        if (error)
                                goto bread_err2;
-                       bblks = (int)BTOBB(INT_GET(rhead->h_len, ARCH_CONVERT));
+                       bblks = (int)BTOBB(be32_to_cpu(rhead->h_len));
                        if ((error = xlog_bread(log, blk_no+hblks, bblks, dbp)))
                                goto bread_err2;
                        offset = xlog_align(log, blk_no+hblks, bblks, dbp);
index ebdb76da527c81d6c021e0ffe995ef1395393c9e..6409b376299594f4a90fd0e8b67b0f34656364da 100644 (file)
@@ -136,15 +136,9 @@ xfs_mount_init(void)
                mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
        }
 
-       AIL_LOCKINIT(&mp->m_ail_lock, "xfs_ail");
-       spinlock_init(&mp->m_sb_lock, "xfs_sb");
+       spin_lock_init(&mp->m_sb_lock);
        mutex_init(&mp->m_ilock);
        mutex_init(&mp->m_growlock);
-       /*
-        * Initialize the AIL.
-        */
-       xfs_trans_ail_init(mp);
-
        atomic_set(&mp->m_active_trans, 0);
 
        return mp;
@@ -171,7 +165,7 @@ xfs_mount_free(
                          sizeof(xfs_perag_t) * mp->m_sb.sb_agcount);
        }
 
-       AIL_LOCK_DESTROY(&mp->m_ail_lock);
+       spinlock_destroy(&mp->m_ail_lock);
        spinlock_destroy(&mp->m_sb_lock);
        mutex_destroy(&mp->m_ilock);
        mutex_destroy(&mp->m_growlock);
@@ -616,7 +610,7 @@ xfs_mount_common(xfs_mount_t *mp, xfs_sb_t *sbp)
        int     i;
 
        mp->m_agfrotor = mp->m_agirotor = 0;
-       spinlock_init(&mp->m_agirotor_lock, "m_agirotor_lock");
+       spin_lock_init(&mp->m_agirotor_lock);
        mp->m_maxagi = mp->m_sb.sb_agcount;
        mp->m_blkbit_log = sbp->sb_blocklog + XFS_NBBYLOG;
        mp->m_blkbb_log = sbp->sb_blocklog - BBSHIFT;
@@ -696,7 +690,6 @@ xfs_initialize_perag_data(xfs_mount_t *mp, xfs_agnumber_t agcount)
        uint64_t        bfreelst = 0;
        uint64_t        btree = 0;
        int             error;
-       int             s;
 
        for (index = 0; index < agcount; index++) {
                /*
@@ -721,11 +714,11 @@ xfs_initialize_perag_data(xfs_mount_t *mp, xfs_agnumber_t agcount)
        /*
         * Overwrite incore superblock counters with just-read data
         */
-       s = XFS_SB_LOCK(mp);
+       spin_lock(&mp->m_sb_lock);
        sbp->sb_ifree = ifree;
        sbp->sb_icount = ialloc;
        sbp->sb_fdblocks = bfree + bfreelst + btree;
-       XFS_SB_UNLOCK(mp, s);
+       spin_unlock(&mp->m_sb_lock);
 
        /* Fixup the per-cpu counters as well. */
        xfs_icsb_reinit_counters(mp);
@@ -734,49 +727,13 @@ xfs_initialize_perag_data(xfs_mount_t *mp, xfs_agnumber_t agcount)
 }
 
 /*
- * xfs_mountfs
- *
- * This function does the following on an initial mount of a file system:
- *     - reads the superblock from disk and init the mount struct
- *     - if we're a 32-bit kernel, do a size check on the superblock
- *             so we don't mount terabyte filesystems
- *     - init mount struct realtime fields
- *     - allocate inode hash table for fs
- *     - init directory manager
- *     - perform recovery and init the log manager
+ * Update alignment values based on mount options and sb values
  */
-int
-xfs_mountfs(
-       xfs_mount_t     *mp,
-       int             mfsi_flags)
+STATIC int
+xfs_update_alignment(xfs_mount_t *mp, int mfsi_flags, __uint64_t *update_flags)
 {
-       xfs_buf_t       *bp;
        xfs_sb_t        *sbp = &(mp->m_sb);
-       xfs_inode_t     *rip;
-       bhv_vnode_t     *rvp = NULL;
-       int             readio_log, writeio_log;
-       xfs_daddr_t     d;
-       __uint64_t      resblks;
-       __int64_t       update_flags;
-       uint            quotamount, quotaflags;
-       int             agno;
-       int             uuid_mounted = 0;
-       int             error = 0;
 
-       if (mp->m_sb_bp == NULL) {
-               if ((error = xfs_readsb(mp, mfsi_flags))) {
-                       return error;
-               }
-       }
-       xfs_mount_common(mp, sbp);
-
-       /*
-        * Check if sb_agblocks is aligned at stripe boundary
-        * If sb_agblocks is NOT aligned turn off m_dalign since
-        * allocator alignment is within an ag, therefore ag has
-        * to be aligned at stripe boundary.
-        */
-       update_flags = 0LL;
        if (mp->m_dalign && !(mfsi_flags & XFS_MFSI_SECOND)) {
                /*
                 * If stripe unit and stripe width are not multiples
@@ -787,8 +744,7 @@ xfs_mountfs(
                        if (mp->m_flags & XFS_MOUNT_RETERR) {
                                cmn_err(CE_WARN,
                                        "XFS: alignment check 1 failed");
-                               error = XFS_ERROR(EINVAL);
-                               goto error1;
+                               return XFS_ERROR(EINVAL);
                        }
                        mp->m_dalign = mp->m_swidth = 0;
                } else {
@@ -798,8 +754,7 @@ xfs_mountfs(
                        mp->m_dalign = XFS_BB_TO_FSBT(mp, mp->m_dalign);
                        if (mp->m_dalign && (sbp->sb_agblocks % mp->m_dalign)) {
                                if (mp->m_flags & XFS_MOUNT_RETERR) {
-                                       error = XFS_ERROR(EINVAL);
-                                       goto error1;
+                                       return XFS_ERROR(EINVAL);
                                }
                                xfs_fs_cmn_err(CE_WARN, mp,
 "stripe alignment turned off: sunit(%d)/swidth(%d) incompatible with agsize(%d)",
@@ -816,8 +771,7 @@ xfs_mountfs(
 "stripe alignment turned off: sunit(%d) less than bsize(%d)",
                                                mp->m_dalign,
                                                mp->m_blockmask +1);
-                                       error = XFS_ERROR(EINVAL);
-                                       goto error1;
+                                       return XFS_ERROR(EINVAL);
                                }
                                mp->m_swidth = 0;
                        }
@@ -830,11 +784,11 @@ xfs_mountfs(
                if (XFS_SB_VERSION_HASDALIGN(sbp)) {
                        if (sbp->sb_unit != mp->m_dalign) {
                                sbp->sb_unit = mp->m_dalign;
-                               update_flags |= XFS_SB_UNIT;
+                               *update_flags |= XFS_SB_UNIT;
                        }
                        if (sbp->sb_width != mp->m_swidth) {
                                sbp->sb_width = mp->m_swidth;
-                               update_flags |= XFS_SB_WIDTH;
+                               *update_flags |= XFS_SB_WIDTH;
                        }
                }
        } else if ((mp->m_flags & XFS_MOUNT_NOALIGN) != XFS_MOUNT_NOALIGN &&
@@ -843,49 +797,45 @@ xfs_mountfs(
                        mp->m_swidth = sbp->sb_width;
        }
 
-       xfs_alloc_compute_maxlevels(mp);
-       xfs_bmap_compute_maxlevels(mp, XFS_DATA_FORK);
-       xfs_bmap_compute_maxlevels(mp, XFS_ATTR_FORK);
-       xfs_ialloc_compute_maxlevels(mp);
+       return 0;
+}
 
-       if (sbp->sb_imax_pct) {
-               __uint64_t      icount;
+/*
+ * Set the maximum inode count for this filesystem
+ */
+STATIC void
+xfs_set_maxicount(xfs_mount_t *mp)
+{
+       xfs_sb_t        *sbp = &(mp->m_sb);
+       __uint64_t      icount;
 
-               /* Make sure the maximum inode count is a multiple of the
-                * units we allocate inodes in.
+       if (sbp->sb_imax_pct) {
+               /*
+                * Make sure the maximum inode count is a multiple
+                * of the units we allocate inodes in.
                 */
-
                icount = sbp->sb_dblocks * sbp->sb_imax_pct;
                do_div(icount, 100);
                do_div(icount, mp->m_ialloc_blks);
                mp->m_maxicount = (icount * mp->m_ialloc_blks)  <<
                                   sbp->sb_inopblog;
-       } else
+       } else {
                mp->m_maxicount = 0;
-
-       mp->m_maxioffset = xfs_max_file_offset(sbp->sb_blocklog);
-
-       /*
-        * XFS uses the uuid from the superblock as the unique
-        * identifier for fsid.  We can not use the uuid from the volume
-        * since a single partition filesystem is identical to a single
-        * partition volume/filesystem.
-        */
-       if ((mfsi_flags & XFS_MFSI_SECOND) == 0 &&
-           (mp->m_flags & XFS_MOUNT_NOUUID) == 0) {
-               if (xfs_uuid_mount(mp)) {
-                       error = XFS_ERROR(EINVAL);
-                       goto error1;
-               }
-               uuid_mounted=1;
        }
+}
+
+/*
+ * Set the default minimum read and write sizes unless
+ * already specified in a mount option.
+ * We use smaller I/O sizes when the file system
+ * is being used for NFS service (wsync mount option).
+ */
+STATIC void
+xfs_set_rw_sizes(xfs_mount_t *mp)
+{
+       xfs_sb_t        *sbp = &(mp->m_sb);
+       int             readio_log, writeio_log;
 
-       /*
-        * Set the default minimum read and write sizes unless
-        * already specified in a mount option.
-        * We use smaller I/O sizes when the file system
-        * is being used for NFS service (wsync mount option).
-        */
        if (!(mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)) {
                if (mp->m_flags & XFS_MOUNT_WSYNC) {
                        readio_log = XFS_WSYNC_READIO_LOG;
@@ -911,17 +861,14 @@ xfs_mountfs(
                mp->m_writeio_log = writeio_log;
        }
        mp->m_writeio_blocks = 1 << (mp->m_writeio_log - sbp->sb_blocklog);
+}
 
-       /*
-        * Set the inode cluster size.
-        * This may still be overridden by the file system
-        * block size if it is larger than the chosen cluster size.
-        */
-       mp->m_inode_cluster_size = XFS_INODE_BIG_CLUSTER_SIZE;
-
-       /*
-        * Set whether we're using inode alignment.
-        */
+/*
+ * Set whether we're using inode alignment.
+ */
+STATIC void
+xfs_set_inoalignment(xfs_mount_t *mp)
+{
        if (XFS_SB_VERSION_HASALIGN(&mp->m_sb) &&
            mp->m_sb.sb_inoalignmt >=
            XFS_B_TO_FSBT(mp, mp->m_inode_cluster_size))
@@ -937,14 +884,22 @@ xfs_mountfs(
                mp->m_sinoalign = mp->m_dalign;
        else
                mp->m_sinoalign = 0;
-       /*
-        * Check that the data (and log if separate) are an ok size.
-        */
+}
+
+/*
+ * Check that the data (and log if separate) are an ok size.
+ */
+STATIC int
+xfs_check_sizes(xfs_mount_t *mp, int mfsi_flags)
+{
+       xfs_buf_t       *bp;
+       xfs_daddr_t     d;
+       int             error;
+
        d = (xfs_daddr_t)XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks);
        if (XFS_BB_TO_FSB(mp, d) != mp->m_sb.sb_dblocks) {
                cmn_err(CE_WARN, "XFS: size check 1 failed");
-               error = XFS_ERROR(E2BIG);
-               goto error1;
+               return XFS_ERROR(E2BIG);
        }
        error = xfs_read_buf(mp, mp->m_ddev_targp,
                             d - XFS_FSS_TO_BB(mp, 1),
@@ -953,10 +908,9 @@ xfs_mountfs(
                xfs_buf_relse(bp);
        } else {
                cmn_err(CE_WARN, "XFS: size check 2 failed");
-               if (error == ENOSPC) {
+               if (error == ENOSPC)
                        error = XFS_ERROR(E2BIG);
-               }
-               goto error1;
+               return error;
        }
 
        if (((mfsi_flags & XFS_MFSI_CLIENT) == 0) &&
@@ -964,8 +918,7 @@ xfs_mountfs(
                d = (xfs_daddr_t)XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks);
                if (XFS_BB_TO_FSB(mp, d) != mp->m_sb.sb_logblocks) {
                        cmn_err(CE_WARN, "XFS: size check 3 failed");
-                       error = XFS_ERROR(E2BIG);
-                       goto error1;
+                       return XFS_ERROR(E2BIG);
                }
                error = xfs_read_buf(mp, mp->m_logdev_targp,
                                     d - XFS_FSB_TO_BB(mp, 1),
@@ -974,17 +927,111 @@ xfs_mountfs(
                        xfs_buf_relse(bp);
                } else {
                        cmn_err(CE_WARN, "XFS: size check 3 failed");
-                       if (error == ENOSPC) {
+                       if (error == ENOSPC)
                                error = XFS_ERROR(E2BIG);
-                       }
+                       return error;
+               }
+       }
+       return 0;
+}
+
+/*
+ * xfs_mountfs
+ *
+ * This function does the following on an initial mount of a file system:
+ *     - reads the superblock from disk and init the mount struct
+ *     - if we're a 32-bit kernel, do a size check on the superblock
+ *             so we don't mount terabyte filesystems
+ *     - init mount struct realtime fields
+ *     - allocate inode hash table for fs
+ *     - init directory manager
+ *     - perform recovery and init the log manager
+ */
+int
+xfs_mountfs(
+       xfs_mount_t     *mp,
+       int             mfsi_flags)
+{
+       xfs_sb_t        *sbp = &(mp->m_sb);
+       xfs_inode_t     *rip;
+       bhv_vnode_t     *rvp = NULL;
+       __uint64_t      resblks;
+       __int64_t       update_flags = 0LL;
+       uint            quotamount, quotaflags;
+       int             agno;
+       int             uuid_mounted = 0;
+       int             error = 0;
+
+       if (mp->m_sb_bp == NULL) {
+               error = xfs_readsb(mp, mfsi_flags);
+               if (error)
+                       return error;
+       }
+       xfs_mount_common(mp, sbp);
+
+       /*
+        * Check if sb_agblocks is aligned at stripe boundary
+        * If sb_agblocks is NOT aligned turn off m_dalign since
+        * allocator alignment is within an ag, therefore ag has
+        * to be aligned at stripe boundary.
+        */
+       error = xfs_update_alignment(mp, mfsi_flags, &update_flags);
+       if (error)
+               goto error1;
+
+       xfs_alloc_compute_maxlevels(mp);
+       xfs_bmap_compute_maxlevels(mp, XFS_DATA_FORK);
+       xfs_bmap_compute_maxlevels(mp, XFS_ATTR_FORK);
+       xfs_ialloc_compute_maxlevels(mp);
+
+       xfs_set_maxicount(mp);
+
+       mp->m_maxioffset = xfs_max_file_offset(sbp->sb_blocklog);
+
+       /*
+        * XFS uses the uuid from the superblock as the unique
+        * identifier for fsid.  We can not use the uuid from the volume
+        * since a single partition filesystem is identical to a single
+        * partition volume/filesystem.
+        */
+       if ((mfsi_flags & XFS_MFSI_SECOND) == 0 &&
+           (mp->m_flags & XFS_MOUNT_NOUUID) == 0) {
+               if (xfs_uuid_mount(mp)) {
+                       error = XFS_ERROR(EINVAL);
                        goto error1;
                }
+               uuid_mounted=1;
        }
 
+       /*
+        * Set the minimum read and write sizes
+        */
+       xfs_set_rw_sizes(mp);
+
+       /*
+        * Set the inode cluster size.
+        * This may still be overridden by the file system
+        * block size if it is larger than the chosen cluster size.
+        */
+       mp->m_inode_cluster_size = XFS_INODE_BIG_CLUSTER_SIZE;
+
+       /*
+        * Set inode alignment fields
+        */
+       xfs_set_inoalignment(mp);
+
+       /*
+        * Check that the data (and log if separate) are an ok size.
+        */
+       error = xfs_check_sizes(mp, mfsi_flags);
+       if (error)
+               goto error1;
+
        /*
         * Initialize realtime fields in the mount structure
         */
-       if ((error = xfs_rtmount_init(mp))) {
+       error = xfs_rtmount_init(mp);
+       if (error) {
                cmn_err(CE_WARN, "XFS: RT mount failed");
                goto error1;
        }
@@ -1102,7 +1149,8 @@ xfs_mountfs(
        /*
         * Initialize realtime inode pointers in the mount structure
         */
-       if ((error = xfs_rtmount_inodes(mp))) {
+       error = xfs_rtmount_inodes(mp);
+       if (error) {
                /*
                 * Free up the root inode.
                 */
@@ -1120,7 +1168,8 @@ xfs_mountfs(
        /*
         * Initialise the XFS quota management subsystem for this mount
         */
-       if ((error = XFS_QM_INIT(mp, &quotamount, &quotaflags)))
+       error = XFS_QM_INIT(mp, &quotamount, &quotaflags);
+       if (error)
                goto error4;
 
        /*
@@ -1137,7 +1186,8 @@ xfs_mountfs(
        /*
         * Complete the quota initialisation, post-log-replay component.
         */
-       if ((error = XFS_QM_MOUNT(mp, quotamount, quotaflags, mfsi_flags)))
+       error = XFS_QM_MOUNT(mp, quotamount, quotaflags, mfsi_flags);
+       if (error)
                goto error4;
 
        /*
@@ -1255,7 +1305,6 @@ xfs_unmountfs(xfs_mount_t *mp, struct cred *cr)
 #if defined(DEBUG) || defined(INDUCE_IO_ERROR)
        xfs_errortag_clearall(mp, 0);
 #endif
-       XFS_IODONE(mp);
        xfs_mount_free(mp);
        return 0;
 }
@@ -1441,7 +1490,7 @@ xfs_mod_sb(xfs_trans_t *tp, __int64_t fields)
  * Fields are not allowed to dip below zero, so if the delta would
  * do this do not apply it and return EINVAL.
  *
- * The SB_LOCK must be held when this routine is called.
+ * The m_sb_lock must be held when this routine is called.
  */
 int
 xfs_mod_incore_sb_unlocked(
@@ -1606,7 +1655,7 @@ xfs_mod_incore_sb_unlocked(
 /*
  * xfs_mod_incore_sb() is used to change a field in the in-core
  * superblock structure by the specified delta.  This modification
- * is protected by the SB_LOCK.  Just use the xfs_mod_incore_sb_unlocked()
+ * is protected by the m_sb_lock.  Just use the xfs_mod_incore_sb_unlocked()
  * routine to do the work.
  */
 int
@@ -1616,7 +1665,6 @@ xfs_mod_incore_sb(
        int64_t         delta,
        int             rsvd)
 {
-       unsigned long   s;
        int     status;
 
        /* check for per-cpu counters */
@@ -1633,9 +1681,9 @@ xfs_mod_incore_sb(
                /* FALLTHROUGH */
 #endif
        default:
-               s = XFS_SB_LOCK(mp);
+               spin_lock(&mp->m_sb_lock);
                status = xfs_mod_incore_sb_unlocked(mp, field, delta, rsvd);
-               XFS_SB_UNLOCK(mp, s);
+               spin_unlock(&mp->m_sb_lock);
                break;
        }
 
@@ -1656,7 +1704,6 @@ xfs_mod_incore_sb(
 int
 xfs_mod_incore_sb_batch(xfs_mount_t *mp, xfs_mod_sb_t *msb, uint nmsb, int rsvd)
 {
-       unsigned long   s;
        int             status=0;
        xfs_mod_sb_t    *msbp;
 
@@ -1664,10 +1711,10 @@ xfs_mod_incore_sb_batch(xfs_mount_t *mp, xfs_mod_sb_t *msb, uint nmsb, int rsvd)
         * Loop through the array of mod structures and apply each
         * individually.  If any fail, then back out all those
         * which have already been applied.  Do all of this within
-        * the scope of the SB_LOCK so that all of the changes will
+        * the scope of the m_sb_lock so that all of the changes will
         * be atomic.
         */
-       s = XFS_SB_LOCK(mp);
+       spin_lock(&mp->m_sb_lock);
        msbp = &msb[0];
        for (msbp = &msbp[0]; msbp < (msb + nmsb); msbp++) {
                /*
@@ -1681,11 +1728,11 @@ xfs_mod_incore_sb_batch(xfs_mount_t *mp, xfs_mod_sb_t *msb, uint nmsb, int rsvd)
                case XFS_SBS_IFREE:
                case XFS_SBS_FDBLOCKS:
                        if (!(mp->m_flags & XFS_MOUNT_NO_PERCPU_SB)) {
-                               XFS_SB_UNLOCK(mp, s);
+                               spin_unlock(&mp->m_sb_lock);
                                status = xfs_icsb_modify_counters(mp,
                                                        msbp->msb_field,
                                                        msbp->msb_delta, rsvd);
-                               s = XFS_SB_LOCK(mp);
+                               spin_lock(&mp->m_sb_lock);
                                break;
                        }
                        /* FALLTHROUGH */
@@ -1719,12 +1766,12 @@ xfs_mod_incore_sb_batch(xfs_mount_t *mp, xfs_mod_sb_t *msb, uint nmsb, int rsvd)
                        case XFS_SBS_IFREE:
                        case XFS_SBS_FDBLOCKS:
                                if (!(mp->m_flags & XFS_MOUNT_NO_PERCPU_SB)) {
-                                       XFS_SB_UNLOCK(mp, s);
+                                       spin_unlock(&mp->m_sb_lock);
                                        status = xfs_icsb_modify_counters(mp,
                                                        msbp->msb_field,
                                                        -(msbp->msb_delta),
                                                        rsvd);
-                                       s = XFS_SB_LOCK(mp);
+                                       spin_lock(&mp->m_sb_lock);
                                        break;
                                }
                                /* FALLTHROUGH */
@@ -1740,7 +1787,7 @@ xfs_mod_incore_sb_batch(xfs_mount_t *mp, xfs_mod_sb_t *msb, uint nmsb, int rsvd)
                        msbp--;
                }
        }
-       XFS_SB_UNLOCK(mp, s);
+       spin_unlock(&mp->m_sb_lock);
        return status;
 }
 
@@ -1888,12 +1935,12 @@ xfs_mount_log_sbunit(
  *
  * Locking rules:
  *
- *     1. XFS_SB_LOCK() before picking up per-cpu locks
+ *     1. m_sb_lock before picking up per-cpu locks
  *     2. per-cpu locks always picked up via for_each_online_cpu() order
- *     3. accurate counter sync requires XFS_SB_LOCK + per cpu locks
+ *     3. accurate counter sync requires m_sb_lock + per cpu locks
  *     4. modifying per-cpu counters requires holding per-cpu lock
- *     5. modifying global counters requires holding XFS_SB_LOCK
- *     6. enabling or disabling a counter requires holding the XFS_SB_LOCK
+ *     5. modifying global counters requires holding m_sb_lock
+ *     6. enabling or disabling a counter requires holding the m_sb_lock 
  *        and _none_ of the per-cpu locks.
  *
  * Disabled counters are only ever re-enabled by a balance operation
@@ -1920,7 +1967,6 @@ xfs_icsb_cpu_notify(
 {
        xfs_icsb_cnts_t *cntp;
        xfs_mount_t     *mp;
-       int             s;
 
        mp = (xfs_mount_t *)container_of(nfb, xfs_mount_t, m_icsb_notifier);
        cntp = (xfs_icsb_cnts_t *)
@@ -1946,7 +1992,7 @@ xfs_icsb_cpu_notify(
                 * count into the total on the global superblock and
                 * re-enable the counters. */
                xfs_icsb_lock(mp);
-               s = XFS_SB_LOCK(mp);
+               spin_lock(&mp->m_sb_lock);
                xfs_icsb_disable_counter(mp, XFS_SBS_ICOUNT);
                xfs_icsb_disable_counter(mp, XFS_SBS_IFREE);
                xfs_icsb_disable_counter(mp, XFS_SBS_FDBLOCKS);
@@ -1963,7 +2009,7 @@ xfs_icsb_cpu_notify(
                                         XFS_ICSB_SB_LOCKED, 0);
                xfs_icsb_balance_counter(mp, XFS_SBS_FDBLOCKS,
                                         XFS_ICSB_SB_LOCKED, 0);
-               XFS_SB_UNLOCK(mp, s);
+               spin_unlock(&mp->m_sb_lock);
                xfs_icsb_unlock(mp);
                break;
        }
@@ -2194,11 +2240,10 @@ xfs_icsb_sync_counters_flags(
        int             flags)
 {
        xfs_icsb_cnts_t cnt;
-       int             s;
 
        /* Pass 1: lock all counters */
        if ((flags & XFS_ICSB_SB_LOCKED) == 0)
-               s = XFS_SB_LOCK(mp);
+               spin_lock(&mp->m_sb_lock);
 
        xfs_icsb_count(mp, &cnt, flags);
 
@@ -2211,7 +2256,7 @@ xfs_icsb_sync_counters_flags(
                mp->m_sb.sb_fdblocks = cnt.icsb_fdblocks;
 
        if ((flags & XFS_ICSB_SB_LOCKED) == 0)
-               XFS_SB_UNLOCK(mp, s);
+               spin_unlock(&mp->m_sb_lock);
 }
 
 /*
@@ -2252,11 +2297,10 @@ xfs_icsb_balance_counter(
 {
        uint64_t        count, resid;
        int             weight = num_online_cpus();
-       int             s;
        uint64_t        min = (uint64_t)min_per_cpu;
 
        if (!(flags & XFS_ICSB_SB_LOCKED))
-               s = XFS_SB_LOCK(mp);
+               spin_lock(&mp->m_sb_lock);
 
        /* disable counter and sync counter */
        xfs_icsb_disable_counter(mp, field);
@@ -2290,10 +2334,10 @@ xfs_icsb_balance_counter(
        xfs_icsb_enable_counter(mp, field, count, resid);
 out:
        if (!(flags & XFS_ICSB_SB_LOCKED))
-               XFS_SB_UNLOCK(mp, s);
+               spin_unlock(&mp->m_sb_lock);
 }
 
-int
+STATIC int
 xfs_icsb_modify_counters(
        xfs_mount_t     *mp,
        xfs_sb_field_t  field,
@@ -2302,7 +2346,7 @@ xfs_icsb_modify_counters(
 {
        xfs_icsb_cnts_t *icsbp;
        long long       lcounter;       /* long counter for 64 bit fields */
-       int             cpu, ret = 0, s;
+       int             cpu, ret = 0;
 
        might_sleep();
 again:
@@ -2380,15 +2424,15 @@ slow_path:
         * running atomically here, we know a rebalance cannot
         * be in progress. Hence we can go straight to operating
         * on the global superblock. We do not call xfs_mod_incore_sb()
-        * here even though we need to get the SB_LOCK. Doing so
+        * here even though we need to get the m_sb_lock. Doing so
         * will cause us to re-enter this function and deadlock.
-        * Hence we get the SB_LOCK ourselves and then call
+        * Hence we get the m_sb_lock ourselves and then call
         * xfs_mod_incore_sb_unlocked() as the unlocked path operates
         * directly on the global counters.
         */
-       s = XFS_SB_LOCK(mp);
+       spin_lock(&mp->m_sb_lock);
        ret = xfs_mod_incore_sb_unlocked(mp, field, delta, rsvd);
-       XFS_SB_UNLOCK(mp, s);
+       spin_unlock(&mp->m_sb_lock);
 
        /*
         * Now that we've modified the global superblock, we
index c618f7cb5f0e274f1ffbffe873995906247c96ea..f7c620ec6e695eb338b4da9a21692bf5d0c59608 100644 (file)
@@ -56,20 +56,12 @@ struct cred;
 struct log;
 struct xfs_mount_args;
 struct xfs_inode;
-struct xfs_iocore;
 struct xfs_bmbt_irec;
 struct xfs_bmap_free;
 struct xfs_extdelta;
 struct xfs_swapext;
 struct xfs_mru_cache;
 
-#define        AIL_LOCK_T              lock_t
-#define        AIL_LOCKINIT(x,y)       spinlock_init(x,y)
-#define        AIL_LOCK_DESTROY(x)     spinlock_destroy(x)
-#define        AIL_LOCK(mp,s)          s=mutex_spinlock(&(mp)->m_ail_lock)
-#define        AIL_UNLOCK(mp,s)        mutex_spinunlock(&(mp)->m_ail_lock, s)
-
-
 /*
  * Prototypes and functions for the Data Migration subsystem.
  */
@@ -196,105 +188,6 @@ typedef struct xfs_qmops {
 #define XFS_QM_QUOTACTL(mp, cmd, id, addr) \
        (*(mp)->m_qm_ops->xfs_quotactl)(mp, cmd, id, addr)
 
-
-/*
- * Prototypes and functions for I/O core modularization.
- */
-
-typedef int            (*xfs_ioinit_t)(struct xfs_mount *,
-                               struct xfs_mount_args *, int);
-typedef int            (*xfs_bmapi_t)(struct xfs_trans *, void *,
-                               xfs_fileoff_t, xfs_filblks_t, int,
-                               xfs_fsblock_t *, xfs_extlen_t,
-                               struct xfs_bmbt_irec *, int *,
-                               struct xfs_bmap_free *, struct xfs_extdelta *);
-typedef int            (*xfs_bunmapi_t)(struct xfs_trans *,
-                               void *, xfs_fileoff_t,
-                               xfs_filblks_t, int, xfs_extnum_t,
-                               xfs_fsblock_t *, struct xfs_bmap_free *,
-                               struct xfs_extdelta *, int *);
-typedef int            (*xfs_bmap_eof_t)(void *, xfs_fileoff_t, int, int *);
-typedef int            (*xfs_iomap_write_direct_t)(
-                               void *, xfs_off_t, size_t, int,
-                               struct xfs_bmbt_irec *, int *, int);
-typedef int            (*xfs_iomap_write_delay_t)(
-                               void *, xfs_off_t, size_t, int,
-                               struct xfs_bmbt_irec *, int *);
-typedef int            (*xfs_iomap_write_allocate_t)(
-                               void *, xfs_off_t, size_t,
-                               struct xfs_bmbt_irec *, int *);
-typedef int            (*xfs_iomap_write_unwritten_t)(
-                               void *, xfs_off_t, size_t);
-typedef uint           (*xfs_lck_map_shared_t)(void *);
-typedef void           (*xfs_lock_t)(void *, uint);
-typedef void           (*xfs_lock_demote_t)(void *, uint);
-typedef int            (*xfs_lock_nowait_t)(void *, uint);
-typedef void           (*xfs_unlk_t)(void *, unsigned int);
-typedef xfs_fsize_t    (*xfs_size_t)(void *);
-typedef xfs_fsize_t    (*xfs_iodone_t)(struct xfs_mount *);
-typedef int            (*xfs_swap_extents_t)(void *, void *,
-                               struct xfs_swapext*);
-
-typedef struct xfs_ioops {
-       xfs_ioinit_t                    xfs_ioinit;
-       xfs_bmapi_t                     xfs_bmapi_func;
-       xfs_bunmapi_t                   xfs_bunmapi_func;
-       xfs_bmap_eof_t                  xfs_bmap_eof_func;
-       xfs_iomap_write_direct_t        xfs_iomap_write_direct;
-       xfs_iomap_write_delay_t         xfs_iomap_write_delay;
-       xfs_iomap_write_allocate_t      xfs_iomap_write_allocate;
-       xfs_iomap_write_unwritten_t     xfs_iomap_write_unwritten;
-       xfs_lock_t                      xfs_ilock;
-       xfs_lck_map_shared_t            xfs_lck_map_shared;
-       xfs_lock_demote_t               xfs_ilock_demote;
-       xfs_lock_nowait_t               xfs_ilock_nowait;
-       xfs_unlk_t                      xfs_unlock;
-       xfs_size_t                      xfs_size_func;
-       xfs_iodone_t                    xfs_iodone;
-       xfs_swap_extents_t              xfs_swap_extents_func;
-} xfs_ioops_t;
-
-#define XFS_IOINIT(mp, args, flags) \
-       (*(mp)->m_io_ops.xfs_ioinit)(mp, args, flags)
-#define XFS_BMAPI(mp, trans,io,bno,len,f,first,tot,mval,nmap,flist,delta) \
-       (*(mp)->m_io_ops.xfs_bmapi_func) \
-               (trans,(io)->io_obj,bno,len,f,first,tot,mval,nmap,flist,delta)
-#define XFS_BUNMAPI(mp, trans,io,bno,len,f,nexts,first,flist,delta,done) \
-       (*(mp)->m_io_ops.xfs_bunmapi_func) \
-               (trans,(io)->io_obj,bno,len,f,nexts,first,flist,delta,done)
-#define XFS_BMAP_EOF(mp, io, endoff, whichfork, eof) \
-       (*(mp)->m_io_ops.xfs_bmap_eof_func) \
-               ((io)->io_obj, endoff, whichfork, eof)
-#define XFS_IOMAP_WRITE_DIRECT(mp, io, offset, count, flags, mval, nmap, found)\
-       (*(mp)->m_io_ops.xfs_iomap_write_direct) \
-               ((io)->io_obj, offset, count, flags, mval, nmap, found)
-#define XFS_IOMAP_WRITE_DELAY(mp, io, offset, count, flags, mval, nmap) \
-       (*(mp)->m_io_ops.xfs_iomap_write_delay) \
-               ((io)->io_obj, offset, count, flags, mval, nmap)
-#define XFS_IOMAP_WRITE_ALLOCATE(mp, io, offset, count, mval, nmap) \
-       (*(mp)->m_io_ops.xfs_iomap_write_allocate) \
-               ((io)->io_obj, offset, count, mval, nmap)
-#define XFS_IOMAP_WRITE_UNWRITTEN(mp, io, offset, count) \
-       (*(mp)->m_io_ops.xfs_iomap_write_unwritten) \
-               ((io)->io_obj, offset, count)
-#define XFS_LCK_MAP_SHARED(mp, io) \
-       (*(mp)->m_io_ops.xfs_lck_map_shared)((io)->io_obj)
-#define XFS_ILOCK(mp, io, mode) \
-       (*(mp)->m_io_ops.xfs_ilock)((io)->io_obj, mode)
-#define XFS_ILOCK_NOWAIT(mp, io, mode) \
-       (*(mp)->m_io_ops.xfs_ilock_nowait)((io)->io_obj, mode)
-#define XFS_IUNLOCK(mp, io, mode) \
-       (*(mp)->m_io_ops.xfs_unlock)((io)->io_obj, mode)
-#define XFS_ILOCK_DEMOTE(mp, io, mode) \
-       (*(mp)->m_io_ops.xfs_ilock_demote)((io)->io_obj, mode)
-#define XFS_SIZE(mp, io) \
-       (*(mp)->m_io_ops.xfs_size_func)((io)->io_obj)
-#define XFS_IODONE(mp) \
-       (*(mp)->m_io_ops.xfs_iodone)(mp)
-#define XFS_SWAP_EXTENTS(mp, io, tio, sxp) \
-       (*(mp)->m_io_ops.xfs_swap_extents_func) \
-               ((io)->io_obj, (tio)->io_obj, sxp)
-
 #ifdef HAVE_PERCPU_SB
 
 /*
@@ -326,14 +219,20 @@ extern void       xfs_icsb_sync_counters_flags(struct xfs_mount *, int);
 #define xfs_icsb_sync_counters_flags(mp, flags)        do { } while (0)
 #endif
 
+typedef struct xfs_ail {
+       xfs_ail_entry_t         xa_ail;
+       uint                    xa_gen;
+       struct task_struct      *xa_task;
+       xfs_lsn_t               xa_target;
+} xfs_ail_t;
+
 typedef struct xfs_mount {
        struct super_block      *m_super;
        xfs_tid_t               m_tid;          /* next unused tid for fs */
-       AIL_LOCK_T              m_ail_lock;     /* fs AIL mutex */
-       xfs_ail_entry_t         m_ail;          /* fs active log item list */
-       uint                    m_ail_gen;      /* fs AIL generation count */
+       spinlock_t              m_ail_lock;     /* fs AIL mutex */
+       xfs_ail_t               m_ail;          /* fs active log item list */
        xfs_sb_t                m_sb;           /* copy of fs superblock */
-       lock_t                  m_sb_lock;      /* sb counter mutex */
+       spinlock_t              m_sb_lock;      /* sb counter lock */
        struct xfs_buf          *m_sb_bp;       /* buffer for superblock */
        char                    *m_fsname;      /* filesystem name */
        int                     m_fsname_len;   /* strlen of fs name */
@@ -342,7 +241,7 @@ typedef struct xfs_mount {
        int                     m_bsize;        /* fs logical block size */
        xfs_agnumber_t          m_agfrotor;     /* last ag where space found */
        xfs_agnumber_t          m_agirotor;     /* last ag dir inode alloced */
-       lock_t                  m_agirotor_lock;/* .. and lock protecting it */
+       spinlock_t              m_agirotor_lock;/* .. and lock protecting it */
        xfs_agnumber_t          m_maxagi;       /* highest inode alloc group */
        struct xfs_inode        *m_inodes;      /* active inode list */
        struct list_head        m_del_inodes;   /* inodes to reclaim */
@@ -423,7 +322,6 @@ typedef struct xfs_mount {
                                                 * hash table */
        struct xfs_dmops        *m_dm_ops;      /* vector of DMI ops */
        struct xfs_qmops        *m_qm_ops;      /* vector of XQM ops */
-       struct xfs_ioops        m_io_ops;       /* vector of I/O ops */
        atomic_t                m_active_trans; /* number trans frozen */
 #ifdef HAVE_PERCPU_SB
        xfs_icsb_cnts_t         *m_sb_cnts;     /* per-cpu superblock counters */
@@ -610,8 +508,6 @@ typedef struct xfs_mod_sb {
 
 #define        XFS_MOUNT_ILOCK(mp)     mutex_lock(&((mp)->m_ilock))
 #define        XFS_MOUNT_IUNLOCK(mp)   mutex_unlock(&((mp)->m_ilock))
-#define        XFS_SB_LOCK(mp)         mutex_spinlock(&(mp)->m_sb_lock)
-#define        XFS_SB_UNLOCK(mp,s)     mutex_spinunlock(&(mp)->m_sb_lock,(s))
 
 extern xfs_mount_t *xfs_mount_init(void);
 extern void    xfs_mod_sb(xfs_trans_t *, __int64_t);
@@ -646,7 +542,6 @@ extern int  xfs_qmops_get(struct xfs_mount *, struct xfs_mount_args *);
 extern void    xfs_qmops_put(struct xfs_mount *);
 
 extern struct xfs_dmops xfs_dmcore_xfs;
-extern struct xfs_ioops xfs_iocore_xfs;
 
 extern int     xfs_init(void);
 extern void    xfs_cleanup(void);
index e0b358c1c533cc66220d47140dbd5df4b0341a96..a0b2c0a2589a97166f23982999aa3a15b95a9687 100644 (file)
@@ -225,10 +225,14 @@ _xfs_mru_cache_list_insert(
  * list need to be deleted.  For each element this involves removing it from the
  * data store, removing it from the reap list, calling the client's free
  * function and deleting the element from the element zone.
+ *
+ * We get called holding the mru->lock, which we drop and then reacquire.
+ * Sparse need special help with this to tell it we know what we are doing.
  */
 STATIC void
 _xfs_mru_cache_clear_reap_list(
-       xfs_mru_cache_t         *mru)
+       xfs_mru_cache_t         *mru) __releases(mru->lock) __acquires(mru->lock)
+
 {
        xfs_mru_cache_elem_t    *elem, *next;
        struct list_head        tmp;
@@ -245,7 +249,7 @@ _xfs_mru_cache_clear_reap_list(
                 */
                list_move(&elem->list_node, &tmp);
        }
-       mutex_spinunlock(&mru->lock, 0);
+       spin_unlock(&mru->lock);
 
        list_for_each_entry_safe(elem, next, &tmp, list_node) {
 
@@ -259,7 +263,7 @@ _xfs_mru_cache_clear_reap_list(
                kmem_zone_free(xfs_mru_elem_zone, elem);
        }
 
-       mutex_spinlock(&mru->lock);
+       spin_lock(&mru->lock);
 }
 
 /*
@@ -280,7 +284,7 @@ _xfs_mru_cache_reap(
        if (!mru || !mru->lists)
                return;
 
-       mutex_spinlock(&mru->lock);
+       spin_lock(&mru->lock);
        next = _xfs_mru_cache_migrate(mru, jiffies);
        _xfs_mru_cache_clear_reap_list(mru);
 
@@ -294,7 +298,7 @@ _xfs_mru_cache_reap(
                queue_delayed_work(xfs_mru_reap_wq, &mru->work, next);
        }
 
-       mutex_spinunlock(&mru->lock, 0);
+       spin_unlock(&mru->lock);
 }
 
 int
@@ -368,7 +372,7 @@ xfs_mru_cache_create(
         */
        INIT_RADIX_TREE(&mru->store, GFP_ATOMIC);
        INIT_LIST_HEAD(&mru->reap_list);
-       spinlock_init(&mru->lock, "xfs_mru_cache");
+       spin_lock_init(&mru->lock);
        INIT_DELAYED_WORK(&mru->work, _xfs_mru_cache_reap);
 
        mru->grp_time  = grp_time;
@@ -398,17 +402,17 @@ xfs_mru_cache_flush(
        if (!mru || !mru->lists)
                return;
 
-       mutex_spinlock(&mru->lock);
+       spin_lock(&mru->lock);
        if (mru->queued) {
-               mutex_spinunlock(&mru->lock, 0);
+               spin_unlock(&mru->lock);
                cancel_rearming_delayed_workqueue(xfs_mru_reap_wq, &mru->work);
-               mutex_spinlock(&mru->lock);
+               spin_lock(&mru->lock);
        }
 
        _xfs_mru_cache_migrate(mru, jiffies + mru->grp_count * mru->grp_time);
        _xfs_mru_cache_clear_reap_list(mru);
 
-       mutex_spinunlock(&mru->lock, 0);
+       spin_unlock(&mru->lock);
 }
 
 void
@@ -454,13 +458,13 @@ xfs_mru_cache_insert(
        elem->key = key;
        elem->value = value;
 
-       mutex_spinlock(&mru->lock);
+       spin_lock(&mru->lock);
 
        radix_tree_insert(&mru->store, key, elem);
        radix_tree_preload_end();
        _xfs_mru_cache_list_insert(mru, elem);
 
-       mutex_spinunlock(&mru->lock, 0);
+       spin_unlock(&mru->lock);
 
        return 0;
 }
@@ -483,14 +487,14 @@ xfs_mru_cache_remove(
        if (!mru || !mru->lists)
                return NULL;
 
-       mutex_spinlock(&mru->lock);
+       spin_lock(&mru->lock);
        elem = radix_tree_delete(&mru->store, key);
        if (elem) {
                value = elem->value;
                list_del(&elem->list_node);
        }
 
-       mutex_spinunlock(&mru->lock, 0);
+       spin_unlock(&mru->lock);
 
        if (elem)
                kmem_zone_free(xfs_mru_elem_zone, elem);
@@ -528,6 +532,10 @@ xfs_mru_cache_delete(
  *
  * If the element isn't found, this function returns NULL and the spinlock is
  * released.  xfs_mru_cache_done() should NOT be called when this occurs.
+ *
+ * Because sparse isn't smart enough to know about conditional lock return
+ * status, we need to help it get it right by annotating the path that does
+ * not release the lock.
  */
 void *
 xfs_mru_cache_lookup(
@@ -540,14 +548,14 @@ xfs_mru_cache_lookup(
        if (!mru || !mru->lists)
                return NULL;
 
-       mutex_spinlock(&mru->lock);
+       spin_lock(&mru->lock);
        elem = radix_tree_lookup(&mru->store, key);
        if (elem) {
                list_del(&elem->list_node);
                _xfs_mru_cache_list_insert(mru, elem);
-       }
-       else
-               mutex_spinunlock(&mru->lock, 0);
+               __release(mru_lock); /* help sparse not be stupid */
+       else
+               spin_unlock(&mru->lock);
 
        return elem ? elem->value : NULL;
 }
@@ -571,10 +579,12 @@ xfs_mru_cache_peek(
        if (!mru || !mru->lists)
                return NULL;
 
-       mutex_spinlock(&mru->lock);
+       spin_lock(&mru->lock);
        elem = radix_tree_lookup(&mru->store, key);
        if (!elem)
-               mutex_spinunlock(&mru->lock, 0);
+               spin_unlock(&mru->lock);
+       else
+               __release(mru_lock); /* help sparse not be stupid */
 
        return elem ? elem->value : NULL;
 }
@@ -586,7 +596,7 @@ xfs_mru_cache_peek(
  */
 void
 xfs_mru_cache_done(
-       xfs_mru_cache_t *mru)
+       xfs_mru_cache_t *mru) __releases(mru->lock)
 {
-       mutex_spinunlock(&mru->lock, 0);
+       spin_unlock(&mru->lock);
 }
index 2ec1d8a27352e6a8595af8cbaecbfc9390e16cdd..a294e58db8dda71c5230c39f39117863c7344d72 100644 (file)
@@ -49,18 +49,17 @@ xfs_mount_reset_sbqflags(xfs_mount_t *mp)
 {
        int                     error;
        xfs_trans_t             *tp;
-       unsigned long           s;
 
        mp->m_qflags = 0;
        /*
         * It is OK to look at sb_qflags here in mount path,
-        * without SB_LOCK.
+        * without m_sb_lock.
         */
        if (mp->m_sb.sb_qflags == 0)
                return 0;
-       s = XFS_SB_LOCK(mp);
+       spin_lock(&mp->m_sb_lock);
        mp->m_sb.sb_qflags = 0;
-       XFS_SB_UNLOCK(mp, s);
+       spin_unlock(&mp->m_sb_lock);
 
        /*
         * if the fs is readonly, let the incore superblock run
index 44ea0ba36476fcd5e21f664cd27b8393ad795dfc..7eb157a59f9eef5521babb49a5d8e082dc9f68d2 100644 (file)
@@ -39,6 +39,7 @@
 #include "xfs_refcache.h"
 #include "xfs_utils.h"
 #include "xfs_trans_space.h"
+#include "xfs_vnodeops.h"
 
 
 /*
@@ -118,7 +119,7 @@ xfs_lock_for_rename(
        inum1 = ip1->i_ino;
 
        ASSERT(ip1);
-       ITRACE(ip1);
+       xfs_itrace_ref(ip1);
 
        /*
         * Unlock dp1 and lock dp2 if they are different.
@@ -141,7 +142,7 @@ xfs_lock_for_rename(
                IRELE (ip1);
                return error;
        } else {
-               ITRACE(ip2);
+               xfs_itrace_ref(ip2);
        }
 
        /*
@@ -247,8 +248,8 @@ xfs_rename(
        int             src_namelen = VNAMELEN(src_vname);
        int             target_namelen = VNAMELEN(target_vname);
 
-       vn_trace_entry(src_dp, "xfs_rename", (inst_t *)__return_address);
-       vn_trace_entry(xfs_vtoi(target_dir_vp), "xfs_rename", (inst_t *)__return_address);
+       xfs_itrace_entry(src_dp);
+       xfs_itrace_entry(xfs_vtoi(target_dir_vp));
 
        /*
         * Find the XFS behavior descriptor for the target directory
index 47082c01872d0621f0c8499862e16c6ef33d2aee..ca83ddf72af4569ab8cfa1b3cdfcbbf16c80ffb6 100644 (file)
@@ -72,18 +72,6 @@ STATIC int xfs_rtmodify_summary(xfs_mount_t *, xfs_trans_t *, int,
  * Internal functions.
  */
 
-/*
- * xfs_lowbit32: get low bit set out of 32-bit argument, -1 if none set.
- */
-STATIC int
-xfs_lowbit32(
-       __uint32_t      v)
-{
-       if (v)
-               return ffs(v) - 1;
-       return -1;
-}
-
 /*
  * Allocate space to the bitmap or summary file, and zero it, for growfs.
  */
@@ -444,6 +432,7 @@ xfs_rtallocate_extent_near(
        }
        bbno = XFS_BITTOBLOCK(mp, bno);
        i = 0;
+       ASSERT(minlen != 0);
        log2len = xfs_highbit32(minlen);
        /*
         * Loop over all bitmap blocks (bbno + i is current block).
@@ -612,6 +601,8 @@ xfs_rtallocate_extent_size(
        xfs_suminfo_t   sum;            /* summary information for extents */
 
        ASSERT(minlen % prod == 0 && maxlen % prod == 0);
+       ASSERT(maxlen != 0);
+
        /*
         * Loop over all the levels starting with maxlen.
         * At each level, look at all the bitmap blocks, to see if there
@@ -669,6 +660,9 @@ xfs_rtallocate_extent_size(
                *rtblock = NULLRTBLOCK;
                return 0;
        }
+       ASSERT(minlen != 0);
+       ASSERT(maxlen != 0);
+
        /*
         * Loop over sizes, from maxlen down to minlen.
         * This time, when we do the allocations, allow smaller ones
@@ -1954,6 +1948,7 @@ xfs_growfs_rt(
                                  nsbp->sb_blocksize * nsbp->sb_rextsize);
                nsbp->sb_rextents = nsbp->sb_rblocks;
                do_div(nsbp->sb_rextents, nsbp->sb_rextsize);
+               ASSERT(nsbp->sb_rextents != 0);
                nsbp->sb_rextslog = xfs_highbit32(nsbp->sb_rextents);
                nrsumlevels = nmp->m_rsumlevels = nsbp->sb_rextslog + 1;
                nrsumsize =
index 799c1f87126318bf54e0fcf9b4f59c088a9ee2fd..8d8dcd215716262d5a9bdb2a46e6c7b359604769 100644 (file)
@@ -21,8 +21,6 @@
 struct xfs_mount;
 struct xfs_trans;
 
-#define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
-
 /* Min and max rt extent sizes, specified in bytes */
 #define        XFS_MAX_RTEXTSIZE       (1024 * 1024 * 1024)    /* 1GB */
 #define        XFS_DFL_RTEXTSIZE       (64 * 1024)             /* 64KB */
index 49875e1d129f2fe2395f996e249ba075ca915c4f..f87db5344ce61145857566ec0a54c116e37b7482 100644 (file)
@@ -32,18 +32,10 @@ struct xfs_mount;
 static inline xfs_daddr_t
 xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb)
 {
-       return (((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME) ? \
+       return (XFS_IS_REALTIME_INODE(ip) ? \
                 (xfs_daddr_t)XFS_FSB_TO_BB((ip)->i_mount, (fsb)) : \
                 XFS_FSB_TO_DADDR((ip)->i_mount, (fsb)));
 }
-#define XFS_FSB_TO_DB_IO(io,fsb) xfs_fsb_to_db_io(io,fsb)
-static inline xfs_daddr_t
-xfs_fsb_to_db_io(struct xfs_iocore *io, xfs_fsblock_t fsb)
-{
-       return (((io)->io_flags & XFS_IOCORE_RT) ? \
-                XFS_FSB_TO_BB((io)->io_mount, (fsb)) : \
-                XFS_FSB_TO_DADDR((io)->io_mount, (fsb)));
-}
 
 /*
  * Flags for xfs_free_eofblocks
@@ -61,7 +53,7 @@ xfs_get_extsz_hint(
 {
        xfs_extlen_t    extsz;
 
-       if (unlikely(ip->i_d.di_flags & XFS_DIFLAG_REALTIME)) {
+       if (unlikely(XFS_IS_REALTIME_INODE(ip))) {
                extsz = (ip->i_d.di_flags & XFS_DIFLAG_EXTSIZE)
                                ? ip->i_d.di_extsize
                                : ip->i_mount->m_sb.sb_rextsize;
index 8878322ee793ccc524bc6fe07c9969658de6ba21..71e4c8dcc69b46996e65f7829e8c2325d58dfecd 100644 (file)
@@ -1322,7 +1322,6 @@ xfs_trans_chunk_committed(
        xfs_lsn_t               item_lsn;
        struct xfs_mount        *mp;
        int                     i;
-       SPLDECL(s);
 
        lidp = licp->lic_descs;
        for (i = 0; i < licp->lic_unused; i++, lidp++) {
@@ -1363,7 +1362,7 @@ xfs_trans_chunk_committed(
                 * the test below.
                 */
                mp = lip->li_mountp;
-               AIL_LOCK(mp,s);
+               spin_lock(&mp->m_ail_lock);
                if (XFS_LSN_CMP(item_lsn, lip->li_lsn) > 0) {
                        /*
                         * This will set the item's lsn to item_lsn
@@ -1372,9 +1371,9 @@ xfs_trans_chunk_committed(
                         *
                         * xfs_trans_update_ail() drops the AIL lock.
                         */
-                       xfs_trans_update_ail(mp, lip, item_lsn, s);
+                       xfs_trans_update_ail(mp, lip, item_lsn);
                } else {
-                       AIL_UNLOCK(mp, s);
+                       spin_unlock(&mp->m_ail_lock);
                }
 
                /*
index 0e26e729023eaf919720a9a7b48b6cb4aaf7240e..7f40628d85c70edc880bd4c5fc629460e77054b1 100644 (file)
@@ -992,8 +992,9 @@ int         _xfs_trans_commit(xfs_trans_t *,
                                  int *);
 #define xfs_trans_commit(tp, flags)    _xfs_trans_commit(tp, flags, NULL)
 void           xfs_trans_cancel(xfs_trans_t *, int);
-void           xfs_trans_ail_init(struct xfs_mount *);
-xfs_lsn_t      xfs_trans_push_ail(struct xfs_mount *, xfs_lsn_t);
+int            xfs_trans_ail_init(struct xfs_mount *);
+void           xfs_trans_ail_destroy(struct xfs_mount *);
+void           xfs_trans_push_ail(struct xfs_mount *, xfs_lsn_t);
 xfs_lsn_t      xfs_trans_tail_ail(struct xfs_mount *);
 void           xfs_trans_unlocked_item(struct xfs_mount *,
                                        xfs_log_item_t *);
@@ -1001,6 +1002,8 @@ xfs_log_busy_slot_t *xfs_trans_add_busy(xfs_trans_t *tp,
                                        xfs_agnumber_t ag,
                                        xfs_extlen_t idx);
 
+extern kmem_zone_t     *xfs_trans_zone;
+
 #endif /* __KERNEL__ */
 
 #endif /* __XFS_TRANS_H__ */
index 5b2ff59f19cf9b04dfa38e8fe533d7acba5068c9..4d6330eddc8d32e60ddfc8228290d904665b7cf6 100644 (file)
@@ -34,9 +34,9 @@ STATIC xfs_log_item_t * xfs_ail_min(xfs_ail_entry_t *);
 STATIC xfs_log_item_t * xfs_ail_next(xfs_ail_entry_t *, xfs_log_item_t *);
 
 #ifdef DEBUG
-STATIC void xfs_ail_check(xfs_ail_entry_t *);
+STATIC void xfs_ail_check(xfs_ail_entry_t *, xfs_log_item_t *);
 #else
-#define        xfs_ail_check(a)
+#define        xfs_ail_check(a,l)
 #endif /* DEBUG */
 
 
@@ -55,16 +55,15 @@ xfs_trans_tail_ail(
 {
        xfs_lsn_t       lsn;
        xfs_log_item_t  *lip;
-       SPLDECL(s);
 
-       AIL_LOCK(mp,s);
-       lip = xfs_ail_min(&(mp->m_ail));
+       spin_lock(&mp->m_ail_lock);
+       lip = xfs_ail_min(&(mp->m_ail.xa_ail));
        if (lip == NULL) {
                lsn = (xfs_lsn_t)0;
        } else {
                lsn = lip->li_lsn;
        }
-       AIL_UNLOCK(mp, s);
+       spin_unlock(&mp->m_ail_lock);
 
        return lsn;
 }
@@ -72,120 +71,185 @@ xfs_trans_tail_ail(
 /*
  * xfs_trans_push_ail
  *
- * This routine is called to move the tail of the AIL
- * forward.  It does this by trying to flush items in the AIL
- * whose lsns are below the given threshold_lsn.
+ * This routine is called to move the tail of the AIL forward.  It does this by
+ * trying to flush items in the AIL whose lsns are below the given
+ * threshold_lsn.
  *
- * The routine returns the lsn of the tail of the log.
+ * the push is run asynchronously in a separate thread, so we return the tail
+ * of the log right now instead of the tail after the push. This means we will
+ * either continue right away, or we will sleep waiting on the async thread to
+ * do it's work.
+ *
+ * We do this unlocked - we only need to know whether there is anything in the
+ * AIL at the time we are called. We don't need to access the contents of
+ * any of the objects, so the lock is not needed.
  */
-xfs_lsn_t
+void
 xfs_trans_push_ail(
        xfs_mount_t             *mp,
        xfs_lsn_t               threshold_lsn)
 {
-       xfs_lsn_t               lsn;
        xfs_log_item_t          *lip;
-       int                     gen;
-       int                     restarts;
-       int                     lock_result;
-       int                     flush_log;
-       SPLDECL(s);
 
-#define        XFS_TRANS_PUSH_AIL_RESTARTS     1000
+       lip = xfs_ail_min(&mp->m_ail.xa_ail);
+       if (lip && !XFS_FORCED_SHUTDOWN(mp)) {
+               if (XFS_LSN_CMP(threshold_lsn, mp->m_ail.xa_target) > 0)
+                       xfsaild_wakeup(mp, threshold_lsn);
+       }
+}
+
+/*
+ * Return the item in the AIL with the current lsn.
+ * Return the current tree generation number for use
+ * in calls to xfs_trans_next_ail().
+ */
+STATIC xfs_log_item_t *
+xfs_trans_first_push_ail(
+       xfs_mount_t     *mp,
+       int             *gen,
+       xfs_lsn_t       lsn)
+{
+       xfs_log_item_t  *lip;
+
+       lip = xfs_ail_min(&(mp->m_ail.xa_ail));
+       *gen = (int)mp->m_ail.xa_gen;
+       if (lsn == 0)
+               return lip;
+
+       while (lip && (XFS_LSN_CMP(lip->li_lsn, lsn) < 0))
+               lip = lip->li_ail.ail_forw;
 
-       AIL_LOCK(mp,s);
-       lip = xfs_trans_first_ail(mp, &gen);
-       if (lip == NULL || XFS_FORCED_SHUTDOWN(mp)) {
+       return lip;
+}
+
+/*
+ * Function that does the work of pushing on the AIL
+ */
+long
+xfsaild_push(
+       xfs_mount_t     *mp,
+       xfs_lsn_t       *last_lsn)
+{
+       long            tout = 1000; /* milliseconds */
+       xfs_lsn_t       last_pushed_lsn = *last_lsn;
+       xfs_lsn_t       target =  mp->m_ail.xa_target;
+       xfs_lsn_t       lsn;
+       xfs_log_item_t  *lip;
+       int             gen;
+       int             restarts;
+       int             flush_log, count, stuck;
+
+#define        XFS_TRANS_PUSH_AIL_RESTARTS     10
+
+       spin_lock(&mp->m_ail_lock);
+       lip = xfs_trans_first_push_ail(mp, &gen, *last_lsn);
+       if (!lip || XFS_FORCED_SHUTDOWN(mp)) {
                /*
-                * Just return if the AIL is empty.
+                * AIL is empty or our push has reached the end.
                 */
-               AIL_UNLOCK(mp, s);
-               return (xfs_lsn_t)0;
+               spin_unlock(&mp->m_ail_lock);
+               last_pushed_lsn = 0;
+               goto out;
        }
 
        XFS_STATS_INC(xs_push_ail);
 
        /*
         * While the item we are looking at is below the given threshold
-        * try to flush it out.  Make sure to limit the number of times
-        * we allow xfs_trans_next_ail() to restart scanning from the
-        * beginning of the list.  We'd like not to stop until we've at least
+        * try to flush it out. We'd like not to stop until we've at least
         * tried to push on everything in the AIL with an LSN less than
-        * the given threshold. However, we may give up before that if
-        * we realize that we've been holding the AIL_LOCK for 'too long',
-        * blocking interrupts. Currently, too long is < 500us roughly.
+        * the given threshold.
+        *
+        * However, we will stop after a certain number of pushes and wait
+        * for a reduced timeout to fire before pushing further. This
+        * prevents use from spinning when we can't do anything or there is
+        * lots of contention on the AIL lists.
         */
-       flush_log = 0;
-       restarts = 0;
-       while (((restarts < XFS_TRANS_PUSH_AIL_RESTARTS) &&
-               (XFS_LSN_CMP(lip->li_lsn, threshold_lsn) < 0))) {
+       tout = 10;
+       lsn = lip->li_lsn;
+       flush_log = stuck = count = restarts = 0;
+       while ((XFS_LSN_CMP(lip->li_lsn, target) < 0)) {
+               int     lock_result;
                /*
-                * If we can lock the item without sleeping, unlock
-                * the AIL lock and flush the item.  Then re-grab the
-                * AIL lock so we can look for the next item on the
-                * AIL.  Since we unlock the AIL while we flush the
-                * item, the next routine may start over again at the
-                * the beginning of the list if anything has changed.
-                * That is what the generation count is for.
+                * If we can lock the item without sleeping, unlock the AIL
+                * lock and flush the item.  Then re-grab the AIL lock so we
+                * can look for the next item on the AIL. List changes are
+                * handled by the AIL lookup functions internally
                 *
-                * If we can't lock the item, either its holder will flush
-                * it or it is already being flushed or it is being relogged.
-                * In any of these case it is being taken care of and we
-                * can just skip to the next item in the list.
+                * If we can't lock the item, either its holder will flush it
+                * or it is already being flushed or it is being relogged.  In
+                * any of these case it is being taken care of and we can just
+                * skip to the next item in the list.
                 */
                lock_result = IOP_TRYLOCK(lip);
+               spin_unlock(&mp->m_ail_lock);
                switch (lock_result) {
-                     case XFS_ITEM_SUCCESS:
-                       AIL_UNLOCK(mp, s);
+               case XFS_ITEM_SUCCESS:
                        XFS_STATS_INC(xs_push_ail_success);
                        IOP_PUSH(lip);
-                       AIL_LOCK(mp,s);
+                       last_pushed_lsn = lsn;
                        break;
 
-                     case XFS_ITEM_PUSHBUF:
-                       AIL_UNLOCK(mp, s);
+               case XFS_ITEM_PUSHBUF:
                        XFS_STATS_INC(xs_push_ail_pushbuf);
-#ifdef XFSRACEDEBUG
-                       delay_for_intr();
-                       delay(300);
-#endif
-                       ASSERT(lip->li_ops->iop_pushbuf);
-                       ASSERT(lip);
                        IOP_PUSHBUF(lip);
-                       AIL_LOCK(mp,s);
+                       last_pushed_lsn = lsn;
                        break;
 
-                     case XFS_ITEM_PINNED:
+               case XFS_ITEM_PINNED:
                        XFS_STATS_INC(xs_push_ail_pinned);
+                       stuck++;
                        flush_log = 1;
                        break;
 
-                     case XFS_ITEM_LOCKED:
+               case XFS_ITEM_LOCKED:
                        XFS_STATS_INC(xs_push_ail_locked);
+                       last_pushed_lsn = lsn;
+                       stuck++;
                        break;
 
-                     case XFS_ITEM_FLUSHING:
+               case XFS_ITEM_FLUSHING:
                        XFS_STATS_INC(xs_push_ail_flushing);
+                       last_pushed_lsn = lsn;
+                       stuck++;
                        break;
 
-                     default:
+               default:
                        ASSERT(0);
                        break;
                }
 
-               lip = xfs_trans_next_ail(mp, lip, &gen, &restarts);
-               if (lip == NULL) {
+               spin_lock(&mp->m_ail_lock);
+               /* should we bother continuing? */
+               if (XFS_FORCED_SHUTDOWN(mp))
+                       break;
+               ASSERT(mp->m_log);
+
+               count++;
+
+               /*
+                * Are there too many items we can't do anything with?
+                * If we we are skipping too many items because we can't flush
+                * them or they are already being flushed, we back off and
+                * given them time to complete whatever operation is being
+                * done. i.e. remove pressure from the AIL while we can't make
+                * progress so traversals don't slow down further inserts and
+                * removals to/from the AIL.
+                *
+                * The value of 100 is an arbitrary magic number based on
+                * observation.
+                */
+               if (stuck > 100)
                        break;
-               }
-               if (XFS_FORCED_SHUTDOWN(mp)) {
-                       /*
-                        * Just return if we shut down during the last try.
-                        */
-                       AIL_UNLOCK(mp, s);
-                       return (xfs_lsn_t)0;
-               }
 
+               lip = xfs_trans_next_ail(mp, lip, &gen, &restarts);
+               if (lip == NULL)
+                       break;
+               if (restarts > XFS_TRANS_PUSH_AIL_RESTARTS)
+                       break;
+               lsn = lip->li_lsn;
        }
+       spin_unlock(&mp->m_ail_lock);
 
        if (flush_log) {
                /*
@@ -193,22 +257,35 @@ xfs_trans_push_ail(
                 * push out the log so it will become unpinned and
                 * move forward in the AIL.
                 */
-               AIL_UNLOCK(mp, s);
                XFS_STATS_INC(xs_push_ail_flush);
                xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
-               AIL_LOCK(mp, s);
        }
 
-       lip = xfs_ail_min(&(mp->m_ail));
-       if (lip == NULL) {
-               lsn = (xfs_lsn_t)0;
-       } else {
-               lsn = lip->li_lsn;
+       /*
+        * We reached the target so wait a bit longer for I/O to complete and
+        * remove pushed items from the AIL before we start the next scan from
+        * the start of the AIL.
+        */
+       if ((XFS_LSN_CMP(lsn, target) >= 0)) {
+               tout += 20;
+               last_pushed_lsn = 0;
+       } else if ((restarts > XFS_TRANS_PUSH_AIL_RESTARTS) ||
+                  (count && ((stuck * 100) / count > 90))) {
+               /*
+                * Either there is a lot of contention on the AIL or we
+                * are stuck due to operations in progress. "Stuck" in this
+                * case is defined as >90% of the items we tried to push
+                * were stuck.
+                *
+                * Backoff a bit more to allow some I/O to complete before
+                * continuing from where we were.
+                */
+               tout += 10;
        }
-
-       AIL_UNLOCK(mp, s);
-       return lsn;
-}      /* xfs_trans_push_ail */
+out:
+       *last_lsn = last_pushed_lsn;
+       return tout;
+}      /* xfsaild_push */
 
 
 /*
@@ -249,7 +326,7 @@ xfs_trans_unlocked_item(
         * the call to xfs_log_move_tail() doesn't do anything if there's
         * not enough free space to wake people up so we're safe calling it.
         */
-       min_lip = xfs_ail_min(&mp->m_ail);
+       min_lip = xfs_ail_min(&mp->m_ail.xa_ail);
 
        if (min_lip == lip)
                xfs_log_move_tail(mp, 1);
@@ -269,21 +346,19 @@ xfs_trans_unlocked_item(
  * has changed.
  *
  * This function must be called with the AIL lock held.  The lock
- * is dropped before returning, so the caller must pass in the
- * cookie returned by AIL_LOCK.
+ * is dropped before returning.
  */
 void
 xfs_trans_update_ail(
        xfs_mount_t     *mp,
        xfs_log_item_t  *lip,
-       xfs_lsn_t       lsn,
-       unsigned long   s) __releases(mp->m_ail_lock)
+       xfs_lsn_t       lsn) __releases(mp->m_ail_lock)
 {
        xfs_ail_entry_t         *ailp;
        xfs_log_item_t          *dlip=NULL;
        xfs_log_item_t          *mlip;  /* ptr to minimum lip */
 
-       ailp = &(mp->m_ail);
+       ailp = &(mp->m_ail.xa_ail);
        mlip = xfs_ail_min(ailp);
 
        if (lip->li_flags & XFS_LI_IN_AIL) {
@@ -296,14 +371,14 @@ xfs_trans_update_ail(
        lip->li_lsn = lsn;
 
        xfs_ail_insert(ailp, lip);
-       mp->m_ail_gen++;
+       mp->m_ail.xa_gen++;
 
        if (mlip == dlip) {
-               mlip = xfs_ail_min(&(mp->m_ail));
-               AIL_UNLOCK(mp, s);
+               mlip = xfs_ail_min(&(mp->m_ail.xa_ail));
+               spin_unlock(&mp->m_ail_lock);
                xfs_log_move_tail(mp, mlip->li_lsn);
        } else {
-               AIL_UNLOCK(mp, s);
+               spin_unlock(&mp->m_ail_lock);
        }
 
 
@@ -322,21 +397,19 @@ xfs_trans_update_ail(
  * has changed.
  *
  * This function must be called with the AIL lock held.  The lock
- * is dropped before returning, so the caller must pass in the
- * cookie returned by AIL_LOCK.
+ * is dropped before returning.
  */
 void
 xfs_trans_delete_ail(
        xfs_mount_t     *mp,
-       xfs_log_item_t  *lip,
-       unsigned long   s) __releases(mp->m_ail_lock)
+       xfs_log_item_t  *lip) __releases(mp->m_ail_lock)
 {
        xfs_ail_entry_t         *ailp;
        xfs_log_item_t          *dlip;
        xfs_log_item_t          *mlip;
 
        if (lip->li_flags & XFS_LI_IN_AIL) {
-               ailp = &(mp->m_ail);
+               ailp = &(mp->m_ail.xa_ail);
                mlip = xfs_ail_min(ailp);
                dlip = xfs_ail_delete(ailp, lip);
                ASSERT(dlip == lip);
@@ -344,14 +417,14 @@ xfs_trans_delete_ail(
 
                lip->li_flags &= ~XFS_LI_IN_AIL;
                lip->li_lsn = 0;
-               mp->m_ail_gen++;
+               mp->m_ail.xa_gen++;
 
                if (mlip == dlip) {
-                       mlip = xfs_ail_min(&(mp->m_ail));
-                       AIL_UNLOCK(mp, s);
+                       mlip = xfs_ail_min(&(mp->m_ail.xa_ail));
+                       spin_unlock(&mp->m_ail_lock);
                        xfs_log_move_tail(mp, (mlip ? mlip->li_lsn : 0));
                } else {
-                       AIL_UNLOCK(mp, s);
+                       spin_unlock(&mp->m_ail_lock);
                }
        }
        else {
@@ -360,12 +433,12 @@ xfs_trans_delete_ail(
                 * serious trouble if we get to this stage.
                 */
                if (XFS_FORCED_SHUTDOWN(mp))
-                       AIL_UNLOCK(mp, s);
+                       spin_unlock(&mp->m_ail_lock);
                else {
                        xfs_cmn_err(XFS_PTAG_AILDELETE, CE_ALERT, mp,
                "%s: attempting to delete a log item that is not in the AIL",
                                        __FUNCTION__);
-                       AIL_UNLOCK(mp, s);
+                       spin_unlock(&mp->m_ail_lock);
                        xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
                }
        }
@@ -385,10 +458,10 @@ xfs_trans_first_ail(
 {
        xfs_log_item_t  *lip;
 
-       lip = xfs_ail_min(&(mp->m_ail));
-       *gen = (int)mp->m_ail_gen;
+       lip = xfs_ail_min(&(mp->m_ail.xa_ail));
+       *gen = (int)mp->m_ail.xa_gen;
 
-       return (lip);
+       return lip;
 }
 
 /*
@@ -408,11 +481,11 @@ xfs_trans_next_ail(
        xfs_log_item_t  *nlip;
 
        ASSERT(mp && lip && gen);
-       if (mp->m_ail_gen == *gen) {
-               nlip = xfs_ail_next(&(mp->m_ail), lip);
+       if (mp->m_ail.xa_gen == *gen) {
+               nlip = xfs_ail_next(&(mp->m_ail.xa_ail), lip);
        } else {
-               nlip = xfs_ail_min(&(mp->m_ail));
-               *gen = (int)mp->m_ail_gen;
+               nlip = xfs_ail_min(&(mp->m_ail).xa_ail);
+               *gen = (int)mp->m_ail.xa_gen;
                if (restarts != NULL) {
                        XFS_STATS_INC(xs_push_ail_restarts);
                        (*restarts)++;
@@ -437,12 +510,20 @@ xfs_trans_next_ail(
 /*
  * Initialize the doubly linked list to point only to itself.
  */
-void
+int
 xfs_trans_ail_init(
        xfs_mount_t     *mp)
 {
-       mp->m_ail.ail_forw = (xfs_log_item_t*)&(mp->m_ail);
-       mp->m_ail.ail_back = (xfs_log_item_t*)&(mp->m_ail);
+       mp->m_ail.xa_ail.ail_forw = (xfs_log_item_t*)&mp->m_ail.xa_ail;
+       mp->m_ail.xa_ail.ail_back = (xfs_log_item_t*)&mp->m_ail.xa_ail;
+       return xfsaild_start(mp);
+}
+
+void
+xfs_trans_ail_destroy(
+       xfs_mount_t     *mp)
+{
+       xfsaild_stop(mp);
 }
 
 /*
@@ -482,7 +563,7 @@ xfs_ail_insert(
        next_lip->li_ail.ail_forw = lip;
        lip->li_ail.ail_forw->li_ail.ail_back = lip;
 
-       xfs_ail_check(base);
+       xfs_ail_check(base, lip);
        return;
 }
 
@@ -496,12 +577,12 @@ xfs_ail_delete(
        xfs_log_item_t  *lip)
 /* ARGSUSED */
 {
+       xfs_ail_check(base, lip);
        lip->li_ail.ail_forw->li_ail.ail_back = lip->li_ail.ail_back;
        lip->li_ail.ail_back->li_ail.ail_forw = lip->li_ail.ail_forw;
        lip->li_ail.ail_forw = NULL;
        lip->li_ail.ail_back = NULL;
 
-       xfs_ail_check(base);
        return lip;
 }
 
@@ -545,13 +626,13 @@ xfs_ail_next(
  */
 STATIC void
 xfs_ail_check(
-       xfs_ail_entry_t *base)
+       xfs_ail_entry_t *base,
+       xfs_log_item_t  *lip)
 {
-       xfs_log_item_t  *lip;
        xfs_log_item_t  *prev_lip;
 
-       lip = base->ail_forw;
-       if (lip == (xfs_log_item_t*)base) {
+       prev_lip = base->ail_forw;
+       if (prev_lip == (xfs_log_item_t*)base) {
                /*
                 * Make sure the pointers are correct when the list
                 * is empty.
@@ -560,10 +641,28 @@ xfs_ail_check(
                return;
        }
 
+       /*
+        * Check the next and previous entries are valid.
+        */
+       ASSERT((lip->li_flags & XFS_LI_IN_AIL) != 0);
+       prev_lip = lip->li_ail.ail_back;
+       if (prev_lip != (xfs_log_item_t*)base) {
+               ASSERT(prev_lip->li_ail.ail_forw == lip);
+               ASSERT(XFS_LSN_CMP(prev_lip->li_lsn, lip->li_lsn) <= 0);
+       }
+       prev_lip = lip->li_ail.ail_forw;
+       if (prev_lip != (xfs_log_item_t*)base) {
+               ASSERT(prev_lip->li_ail.ail_back == lip);
+               ASSERT(XFS_LSN_CMP(prev_lip->li_lsn, lip->li_lsn) >= 0);
+       }
+
+
+#ifdef XFS_TRANS_DEBUG
        /*
         * Walk the list checking forward and backward pointers,
         * lsn ordering, and that every entry has the XFS_LI_IN_AIL
-        * flag set.
+        * flag set. This is really expensive, so only do it when
+        * specifically debugging the transaction subsystem.
         */
        prev_lip = (xfs_log_item_t*)base;
        while (lip != (xfs_log_item_t*)base) {
@@ -578,5 +677,6 @@ xfs_ail_check(
        }
        ASSERT(lip == (xfs_log_item_t*)base);
        ASSERT(base->ail_back == prev_lip);
+#endif /* XFS_TRANS_DEBUG */
 }
 #endif /* DEBUG */
index 2912aac07c7bff8d7133a54297c78d6707a6669c..66a09f0d894b0c42b2eafb5a667bf1e0c57b4b97 100644 (file)
@@ -21,6 +21,7 @@
 #include "xfs_log.h"
 #include "xfs_inum.h"
 #include "xfs_trans.h"
+#include "xfs_trans_priv.h"
 
 STATIC int     xfs_trans_unlock_chunk(xfs_log_item_chunk_t *,
                                        int, int, xfs_lsn_t);
index 447ac4308c917cd445a5a0acea364a7b567d5405..3c748c456ed4f9a58c03babd86d9afd401ca8efe 100644 (file)
@@ -47,15 +47,22 @@ xfs_log_busy_slot_t         *xfs_trans_add_busy(xfs_trans_t *tp,
  * From xfs_trans_ail.c
  */
 void                   xfs_trans_update_ail(struct xfs_mount *mp,
-                                    struct xfs_log_item *lip, xfs_lsn_t lsn,
-                                    unsigned long s)
+                                    struct xfs_log_item *lip, xfs_lsn_t lsn)
                                     __releases(mp->m_ail_lock);
 void                   xfs_trans_delete_ail(struct xfs_mount *mp,
-                                    struct xfs_log_item *lip, unsigned long s)
+                                    struct xfs_log_item *lip)
                                     __releases(mp->m_ail_lock);
 struct xfs_log_item    *xfs_trans_first_ail(struct xfs_mount *, int *);
 struct xfs_log_item    *xfs_trans_next_ail(struct xfs_mount *,
                                     struct xfs_log_item *, int *, int *);
 
 
+/*
+ * AIL push thread support
+ */
+long   xfsaild_push(struct xfs_mount *, xfs_lsn_t *);
+void   xfsaild_wakeup(struct xfs_mount *, xfs_lsn_t);
+int    xfsaild_start(struct xfs_mount *);
+void   xfsaild_stop(struct xfs_mount *);
+
 #endif /* __XFS_TRANS_PRIV_H__ */
index 673b405eaa31cfc82d38bff06052a7847e20a4c7..45d740df53b73d2166fe92490e68ea004ec83a7e 100644 (file)
@@ -73,7 +73,7 @@ xfs_dir_lookup_int(
 {
        int             error;
 
-       vn_trace_entry(dp, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(dp);
 
        error = xfs_dir_lookup(NULL, dp, VNAME(dentry), VNAMELEN(dentry), inum);
        if (!error) {
@@ -302,6 +302,7 @@ xfs_droplink(
 
        ASSERT (ip->i_d.di_nlink > 0);
        ip->i_d.di_nlink--;
+       drop_nlink(ip->i_vnode);
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
 
        error = 0;
@@ -330,7 +331,6 @@ xfs_bump_ino_vers2(
        xfs_inode_t     *ip)
 {
        xfs_mount_t     *mp;
-       unsigned long           s;
 
        ASSERT(ismrlocked (&ip->i_lock, MR_UPDATE));
        ASSERT(ip->i_d.di_version == XFS_DINODE_VERSION_1);
@@ -340,13 +340,13 @@ xfs_bump_ino_vers2(
        memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
        mp = tp->t_mountp;
        if (!XFS_SB_VERSION_HASNLINK(&mp->m_sb)) {
-               s = XFS_SB_LOCK(mp);
+               spin_lock(&mp->m_sb_lock);
                if (!XFS_SB_VERSION_HASNLINK(&mp->m_sb)) {
                        XFS_SB_VERSION_ADDNLINK(&mp->m_sb);
-                       XFS_SB_UNLOCK(mp, s);
+                       spin_unlock(&mp->m_sb_lock);
                        xfs_mod_sb(tp, XFS_SB_VERSIONNUM);
                } else {
-                       XFS_SB_UNLOCK(mp, s);
+                       spin_unlock(&mp->m_sb_lock);
                }
        }
        /* Caller must log the inode */
@@ -366,6 +366,7 @@ xfs_bumplink(
 
        ASSERT(ip->i_d.di_nlink > 0);
        ip->i_d.di_nlink++;
+       inc_nlink(ip->i_vnode);
        if ((ip->i_d.di_version == XFS_DINODE_VERSION_1) &&
            (ip->i_d.di_nlink > XFS_MAXLINK_1)) {
                /*
index a00b26d8840e75f8e802c3c37da496ab4b342cd5..f857fcccb723ca75373be0e2524d201e74074060 100644 (file)
@@ -20,8 +20,6 @@
 
 #define IRELE(ip)      VN_RELE(XFS_ITOV(ip))
 #define IHOLD(ip)      VN_HOLD(XFS_ITOV(ip))
-#define        ITRACE(ip)      vn_trace_ref(ip, __FILE__, __LINE__, \
-                               (inst_t *)__return_address)
 
 extern int xfs_get_dir_entry (bhv_vname_t *, xfs_inode_t **);
 extern int xfs_dir_lookup_int (xfs_inode_t *, uint, bhv_vname_t *, xfs_ino_t *,
index a1544597bcd318c7f35a80551321c1f103b55f13..413587f0215578760d0109dc3825ceb296ce0fab 100644 (file)
 #include "xfs_vfsops.h"
 
 
-int
+int __init
 xfs_init(void)
 {
-       extern kmem_zone_t      *xfs_bmap_free_item_zone;
-       extern kmem_zone_t      *xfs_btree_cur_zone;
-       extern kmem_zone_t      *xfs_trans_zone;
-       extern kmem_zone_t      *xfs_buf_item_zone;
-       extern kmem_zone_t      *xfs_dabuf_zone;
 #ifdef XFS_DABUF_DEBUG
-       extern lock_t           xfs_dabuf_global_lock;
-       spinlock_init(&xfs_dabuf_global_lock, "xfsda");
+       extern spinlock_t        xfs_dabuf_global_lock;
+       spin_lock_init(&xfs_dabuf_global_lock);
 #endif
 
        /*
@@ -152,18 +147,12 @@ xfs_init(void)
        return 0;
 }
 
-void
+void __exit
 xfs_cleanup(void)
 {
-       extern kmem_zone_t      *xfs_bmap_free_item_zone;
-       extern kmem_zone_t      *xfs_btree_cur_zone;
        extern kmem_zone_t      *xfs_inode_zone;
-       extern kmem_zone_t      *xfs_trans_zone;
-       extern kmem_zone_t      *xfs_da_state_zone;
-       extern kmem_zone_t      *xfs_dabuf_zone;
        extern kmem_zone_t      *xfs_efd_zone;
        extern kmem_zone_t      *xfs_efi_zone;
-       extern kmem_zone_t      *xfs_buf_item_zone;
        extern kmem_zone_t      *xfs_icluster_zone;
 
        xfs_cleanup_procfs();
@@ -449,8 +438,6 @@ xfs_mount(
        if (error)
                return error;
 
-       mp->m_io_ops = xfs_iocore_xfs;
-
        if (args->flags & XFSMNT_QUIET)
                flags |= XFS_MFSI_QUIET;
 
@@ -544,7 +531,7 @@ xfs_mount(
        if ((error = xfs_filestream_mount(mp)))
                goto error2;
 
-       error = XFS_IOINIT(mp, args, flags);
+       error = xfs_mountfs(mp, flags);
        if (error)
                goto error2;
 
@@ -694,7 +681,7 @@ xfs_quiesce_fs(
  * care of the metadata. New transactions are already blocked, so we need to
  * wait for any remaining transactions to drain out before proceding.
  */
-STATIC void
+void
 xfs_attr_quiesce(
        xfs_mount_t     *mp)
 {
@@ -820,80 +807,6 @@ fscorrupt_out2:
        return XFS_ERROR(EFSCORRUPTED);
 }
 
-/*
- * xfs_root extracts the root vnode from a vfs.
- *
- * vfsp -- the vfs struct for the desired file system
- * vpp  -- address of the caller's vnode pointer which should be
- *         set to the desired fs root vnode
- */
-int
-xfs_root(
-       xfs_mount_t     *mp,
-       bhv_vnode_t     **vpp)
-{
-       bhv_vnode_t     *vp;
-
-       vp = XFS_ITOV(mp->m_rootip);
-       VN_HOLD(vp);
-       *vpp = vp;
-       return 0;
-}
-
-/*
- * xfs_statvfs
- *
- * Fill in the statvfs structure for the given file system.  We use
- * the superblock lock in the mount structure to ensure a consistent
- * snapshot of the counters returned.
- */
-int
-xfs_statvfs(
-       xfs_mount_t     *mp,
-       bhv_statvfs_t   *statp,
-       bhv_vnode_t     *vp)
-{
-       __uint64_t      fakeinos;
-       xfs_extlen_t    lsize;
-       xfs_sb_t        *sbp;
-       unsigned long   s;
-
-       sbp = &(mp->m_sb);
-
-       statp->f_type = XFS_SB_MAGIC;
-
-       xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
-       s = XFS_SB_LOCK(mp);
-       statp->f_bsize = sbp->sb_blocksize;
-       lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
-       statp->f_blocks = sbp->sb_dblocks - lsize;
-       statp->f_bfree = statp->f_bavail =
-                               sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
-       fakeinos = statp->f_bfree << sbp->sb_inopblog;
-#if XFS_BIG_INUMS
-       fakeinos += mp->m_inoadd;
-#endif
-       statp->f_files =
-           MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
-       if (mp->m_maxicount)
-#if XFS_BIG_INUMS
-               if (!mp->m_inoadd)
-#endif
-                       statp->f_files = min_t(typeof(statp->f_files),
-                                               statp->f_files,
-                                               mp->m_maxicount);
-       statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
-       XFS_SB_UNLOCK(mp, s);
-
-       xfs_statvfs_fsid(statp, mp);
-       statp->f_namelen = MAXNAMELEN - 1;
-
-       if (vp)
-               XFS_QM_DQSTATVFS(xfs_vtoi(vp), statp);
-       return 0;
-}
-
-
 /*
  * xfs_sync flushes any pending I/O to file system vfsp.
  *
@@ -981,8 +894,6 @@ xfs_sync_inodes(
        int             *bypassed)
 {
        xfs_inode_t     *ip = NULL;
-       xfs_inode_t     *ip_next;
-       xfs_buf_t       *bp;
        bhv_vnode_t     *vp = NULL;
        int             error;
        int             last_error;
@@ -992,7 +903,6 @@ xfs_sync_inodes(
        boolean_t       mount_locked;
        boolean_t       vnode_refed;
        int             preempt;
-       xfs_dinode_t    *dip;
        xfs_iptr_t      *ipointer;
 #ifdef DEBUG
        boolean_t       ipointer_in = B_FALSE;
@@ -1045,6 +955,8 @@ xfs_sync_inodes(
 
 #define XFS_PREEMPT_MASK       0x7f
 
+       ASSERT(!(flags & SYNC_BDFLUSH));
+
        if (bypassed)
                *bypassed = 0;
        if (mp->m_flags & XFS_MOUNT_RDONLY)
@@ -1057,7 +969,7 @@ xfs_sync_inodes(
        ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
 
        fflag = XFS_B_ASYNC;            /* default is don't wait */
-       if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
+       if (flags & SYNC_DELWRI)
                fflag = XFS_B_DELWRI;
        if (flags & SYNC_WAIT)
                fflag = 0;              /* synchronous overrides all */
@@ -1146,24 +1058,6 @@ xfs_sync_inodes(
                        return 0;
                }
 
-               /*
-                * If this is just vfs_sync() or pflushd() calling
-                * then we can skip inodes for which it looks like
-                * there is nothing to do.  Since we don't have the
-                * inode locked this is racy, but these are periodic
-                * calls so it doesn't matter.  For the others we want
-                * to know for sure, so we at least try to lock them.
-                */
-               if (flags & SYNC_BDFLUSH) {
-                       if (((ip->i_itemp == NULL) ||
-                            !(ip->i_itemp->ili_format.ilf_fields &
-                              XFS_ILOG_ALL)) &&
-                           (ip->i_update_core == 0)) {
-                               ip = ip->i_mnext;
-                               continue;
-                       }
-               }
-
                /*
                 * Try to lock without sleeping.  We're out of order with
                 * the inode list lock here, so if we fail we need to drop
@@ -1181,7 +1075,7 @@ xfs_sync_inodes(
                 * it.
                 */
                if (xfs_ilock_nowait(ip, lock_flags) == 0) {
-                       if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
+                       if (vp == NULL) {
                                ip = ip->i_mnext;
                                continue;
                        }
@@ -1242,160 +1136,27 @@ xfs_sync_inodes(
                        xfs_ilock(ip, XFS_ILOCK_SHARED);
                }
 
-               if (flags & SYNC_BDFLUSH) {
-                       if ((flags & SYNC_ATTR) &&
-                           ((ip->i_update_core) ||
-                            ((ip->i_itemp != NULL) &&
-                             (ip->i_itemp->ili_format.ilf_fields != 0)))) {
-
-                               /* Insert marker and drop lock if not already
-                                * done.
-                                */
-                               if (mount_locked) {
-                                       IPOINTER_INSERT(ip, mp);
-                               }
-
-                               /*
-                                * We don't want the periodic flushing of the
-                                * inodes by vfs_sync() to interfere with
-                                * I/O to the file, especially read I/O
-                                * where it is only the access time stamp
-                                * that is being flushed out.  To prevent
-                                * long periods where we have both inode
-                                * locks held shared here while reading the
-                                * inode's buffer in from disk, we drop the
-                                * inode lock while reading in the inode
-                                * buffer.  We have to release the buffer
-                                * and reacquire the inode lock so that they
-                                * are acquired in the proper order (inode
-                                * locks first).  The buffer will go at the
-                                * end of the lru chain, though, so we can
-                                * expect it to still be there when we go
-                                * for it again in xfs_iflush().
-                                */
-                               if ((xfs_ipincount(ip) == 0) &&
-                                   xfs_iflock_nowait(ip)) {
-
-                                       xfs_ifunlock(ip);
-                                       xfs_iunlock(ip, XFS_ILOCK_SHARED);
-
-                                       error = xfs_itobp(mp, NULL, ip,
-                                                         &dip, &bp, 0, 0);
-                                       if (!error) {
-                                               xfs_buf_relse(bp);
-                                       } else {
-                                               /* Bailing out, remove the
-                                                * marker and free it.
-                                                */
-                                               XFS_MOUNT_ILOCK(mp);
-                                               IPOINTER_REMOVE(ip, mp);
-                                               XFS_MOUNT_IUNLOCK(mp);
-
-                                               ASSERT(!(lock_flags &
-                                                       XFS_IOLOCK_SHARED));
-
-                                               kmem_free(ipointer,
-                                                       sizeof(xfs_iptr_t));
-                                               return (0);
-                                       }
-
-                                       /*
-                                        * Since we dropped the inode lock,
-                                        * the inode may have been reclaimed.
-                                        * Therefore, we reacquire the mount
-                                        * lock and check to see if we were the
-                                        * inode reclaimed. If this happened
-                                        * then the ipointer marker will no
-                                        * longer point back at us. In this
-                                        * case, move ip along to the inode
-                                        * after the marker, remove the marker
-                                        * and continue.
-                                        */
-                                       XFS_MOUNT_ILOCK(mp);
-                                       mount_locked = B_TRUE;
-
-                                       if (ip != ipointer->ip_mprev) {
-                                               IPOINTER_REMOVE(ip, mp);
-
-                                               ASSERT(!vnode_refed);
-                                               ASSERT(!(lock_flags &
-                                                       XFS_IOLOCK_SHARED));
-                                               continue;
-                                       }
-
-                                       ASSERT(ip->i_mount == mp);
-
-                                       if (xfs_ilock_nowait(ip,
-                                                   XFS_ILOCK_SHARED) == 0) {
-                                               ASSERT(ip->i_mount == mp);
-                                               /*
-                                                * We failed to reacquire
-                                                * the inode lock without
-                                                * sleeping, so just skip
-                                                * the inode for now.  We
-                                                * clear the ILOCK bit from
-                                                * the lock_flags so that we
-                                                * won't try to drop a lock
-                                                * we don't hold below.
-                                                */
-                                               lock_flags &= ~XFS_ILOCK_SHARED;
-                                               IPOINTER_REMOVE(ip_next, mp);
-                                       } else if ((xfs_ipincount(ip) == 0) &&
-                                                  xfs_iflock_nowait(ip)) {
-                                               ASSERT(ip->i_mount == mp);
-                                               /*
-                                                * Since this is vfs_sync()
-                                                * calling we only flush the
-                                                * inode out if we can lock
-                                                * it without sleeping and
-                                                * it is not pinned.  Drop
-                                                * the mount lock here so
-                                                * that we don't hold it for
-                                                * too long. We already have
-                                                * a marker in the list here.
-                                                */
-                                               XFS_MOUNT_IUNLOCK(mp);
-                                               mount_locked = B_FALSE;
-                                               error = xfs_iflush(ip,
-                                                          XFS_IFLUSH_DELWRI);
-                                       } else {
-                                               ASSERT(ip->i_mount == mp);
-                                               IPOINTER_REMOVE(ip_next, mp);
-                                       }
-                               }
-
-                       }
+               if ((flags & SYNC_ATTR) &&
+                   (ip->i_update_core ||
+                    (ip->i_itemp && ip->i_itemp->ili_format.ilf_fields))) {
+                       if (mount_locked)
+                               IPOINTER_INSERT(ip, mp);
 
-               } else {
-                       if ((flags & SYNC_ATTR) &&
-                           ((ip->i_update_core) ||
-                            ((ip->i_itemp != NULL) &&
-                             (ip->i_itemp->ili_format.ilf_fields != 0)))) {
-                               if (mount_locked) {
-                                       IPOINTER_INSERT(ip, mp);
-                               }
+                       if (flags & SYNC_WAIT) {
+                               xfs_iflock(ip);
+                               error = xfs_iflush(ip, XFS_IFLUSH_SYNC);
 
-                               if (flags & SYNC_WAIT) {
-                                       xfs_iflock(ip);
-                                       error = xfs_iflush(ip,
-                                                          XFS_IFLUSH_SYNC);
-                               } else {
-                                       /*
-                                        * If we can't acquire the flush
-                                        * lock, then the inode is already
-                                        * being flushed so don't bother
-                                        * waiting.  If we can lock it then
-                                        * do a delwri flush so we can
-                                        * combine multiple inode flushes
-                                        * in each disk write.
-                                        */
-                                       if (xfs_iflock_nowait(ip)) {
-                                               error = xfs_iflush(ip,
-                                                          XFS_IFLUSH_DELWRI);
-                                       }
-                                       else if (bypassed)
-                                               (*bypassed)++;
-                               }
+                       /*
+                        * If we can't acquire the flush lock, then the inode
+                        * is already being flushed so don't bother waiting.
+                        *
+                        * If we can lock it then do a delwri flush so we can
+                        * combine multiple inode flushes in each disk write.
+                        */
+                       } else if (xfs_iflock_nowait(ip)) {
+                               error = xfs_iflush(ip, XFS_IFLUSH_DELWRI);
+                       } else if (bypassed) {
+                               (*bypassed)++;
                        }
                }
 
@@ -1627,499 +1388,3 @@ xfs_syncsub(
 
        return XFS_ERROR(last_error);
 }
-
-/*
- * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
- */
-int
-xfs_vget(
-       xfs_mount_t     *mp,
-       bhv_vnode_t     **vpp,
-       xfs_fid_t       *xfid)
-{
-       xfs_inode_t     *ip;
-       int             error;
-       xfs_ino_t       ino;
-       unsigned int    igen;
-
-       /*
-        * Invalid.  Since handles can be created in user space and passed in
-        * via gethandle(), this is not cause for a panic.
-        */
-       if (xfid->fid_len != sizeof(*xfid) - sizeof(xfid->fid_len))
-               return XFS_ERROR(EINVAL);
-
-       ino  = xfid->fid_ino;
-       igen = xfid->fid_gen;
-
-       /*
-        * NFS can sometimes send requests for ino 0.  Fail them gracefully.
-        */
-       if (ino == 0)
-               return XFS_ERROR(ESTALE);
-
-       error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
-       if (error) {
-               *vpp = NULL;
-               return error;
-       }
-
-       if (ip == NULL) {
-               *vpp = NULL;
-               return XFS_ERROR(EIO);
-       }
-
-       if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
-               xfs_iput_new(ip, XFS_ILOCK_SHARED);
-               *vpp = NULL;
-               return XFS_ERROR(ENOENT);
-       }
-
-       *vpp = XFS_ITOV(ip);
-       xfs_iunlock(ip, XFS_ILOCK_SHARED);
-       return 0;
-}
-
-
-#define MNTOPT_LOGBUFS "logbufs"       /* number of XFS log buffers */
-#define MNTOPT_LOGBSIZE        "logbsize"      /* size of XFS log buffers */
-#define MNTOPT_LOGDEV  "logdev"        /* log device */
-#define MNTOPT_RTDEV   "rtdev"         /* realtime I/O device */
-#define MNTOPT_BIOSIZE "biosize"       /* log2 of preferred buffered io size */
-#define MNTOPT_WSYNC   "wsync"         /* safe-mode nfs compatible mount */
-#define MNTOPT_INO64   "ino64"         /* force inodes into 64-bit range */
-#define MNTOPT_NOALIGN "noalign"       /* turn off stripe alignment */
-#define MNTOPT_SWALLOC "swalloc"       /* turn on stripe width allocation */
-#define MNTOPT_SUNIT   "sunit"         /* data volume stripe unit */
-#define MNTOPT_SWIDTH  "swidth"        /* data volume stripe width */
-#define MNTOPT_NOUUID  "nouuid"        /* ignore filesystem UUID */
-#define MNTOPT_MTPT    "mtpt"          /* filesystem mount point */
-#define MNTOPT_GRPID   "grpid"         /* group-ID from parent directory */
-#define MNTOPT_NOGRPID "nogrpid"       /* group-ID from current process */
-#define MNTOPT_BSDGROUPS    "bsdgroups"    /* group-ID from parent directory */
-#define MNTOPT_SYSVGROUPS   "sysvgroups"   /* group-ID from current process */
-#define MNTOPT_ALLOCSIZE    "allocsize"    /* preferred allocation size */
-#define MNTOPT_NORECOVERY   "norecovery"   /* don't run XFS recovery */
-#define MNTOPT_BARRIER "barrier"       /* use writer barriers for log write and
-                                        * unwritten extent conversion */
-#define MNTOPT_NOBARRIER "nobarrier"   /* .. disable */
-#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
-#define MNTOPT_64BITINODE   "inode64"  /* inodes can be allocated anywhere */
-#define MNTOPT_IKEEP   "ikeep"         /* do not free empty inode clusters */
-#define MNTOPT_NOIKEEP "noikeep"       /* free empty inode clusters */
-#define MNTOPT_LARGEIO    "largeio"    /* report large I/O sizes in stat() */
-#define MNTOPT_NOLARGEIO   "nolargeio" /* do not report large I/O sizes
-                                        * in stat(). */
-#define MNTOPT_ATTR2   "attr2"         /* do use attr2 attribute format */
-#define MNTOPT_NOATTR2 "noattr2"       /* do not use attr2 attribute format */
-#define MNTOPT_FILESTREAM  "filestreams" /* use filestreams allocator */
-#define MNTOPT_QUOTA   "quota"         /* disk quotas (user) */
-#define MNTOPT_NOQUOTA "noquota"       /* no quotas */
-#define MNTOPT_USRQUOTA        "usrquota"      /* user quota enabled */
-#define MNTOPT_GRPQUOTA        "grpquota"      /* group quota enabled */
-#define MNTOPT_PRJQUOTA        "prjquota"      /* project quota enabled */
-#define MNTOPT_UQUOTA  "uquota"        /* user quota (IRIX variant) */
-#define MNTOPT_GQUOTA  "gquota"        /* group quota (IRIX variant) */
-#define MNTOPT_PQUOTA  "pquota"        /* project quota (IRIX variant) */
-#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
-#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
-#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
-#define MNTOPT_QUOTANOENF  "qnoenforce"        /* same as uqnoenforce */
-#define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
-#define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
-#define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
-
-STATIC unsigned long
-suffix_strtoul(char *s, char **endp, unsigned int base)
-{
-       int     last, shift_left_factor = 0;
-       char    *value = s;
-
-       last = strlen(value) - 1;
-       if (value[last] == 'K' || value[last] == 'k') {
-               shift_left_factor = 10;
-               value[last] = '\0';
-       }
-       if (value[last] == 'M' || value[last] == 'm') {
-               shift_left_factor = 20;
-               value[last] = '\0';
-       }
-       if (value[last] == 'G' || value[last] == 'g') {
-               shift_left_factor = 30;
-               value[last] = '\0';
-       }
-
-       return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
-}
-
-int
-xfs_parseargs(
-       struct xfs_mount        *mp,
-       char                    *options,
-       struct xfs_mount_args   *args,
-       int                     update)
-{
-       char                    *this_char, *value, *eov;
-       int                     dsunit, dswidth, vol_dsunit, vol_dswidth;
-       int                     iosize;
-       int                     ikeep = 0;
-
-       args->flags |= XFSMNT_BARRIER;
-       args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
-
-       if (!options)
-               goto done;
-
-       iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
-
-       while ((this_char = strsep(&options, ",")) != NULL) {
-               if (!*this_char)
-                       continue;
-               if ((value = strchr(this_char, '=')) != NULL)
-                       *value++ = 0;
-
-               if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
-                       if (!value || !*value) {
-                               cmn_err(CE_WARN,
-                                       "XFS: %s option requires an argument",
-                                       this_char);
-                               return EINVAL;
-                       }
-                       args->logbufs = simple_strtoul(value, &eov, 10);
-               } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
-                       if (!value || !*value) {
-                               cmn_err(CE_WARN,
-                                       "XFS: %s option requires an argument",
-                                       this_char);
-                               return EINVAL;
-                       }
-                       args->logbufsize = suffix_strtoul(value, &eov, 10);
-               } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
-                       if (!value || !*value) {
-                               cmn_err(CE_WARN,
-                                       "XFS: %s option requires an argument",
-                                       this_char);
-                               return EINVAL;
-                       }
-                       strncpy(args->logname, value, MAXNAMELEN);
-               } else if (!strcmp(this_char, MNTOPT_MTPT)) {
-                       if (!value || !*value) {
-                               cmn_err(CE_WARN,
-                                       "XFS: %s option requires an argument",
-                                       this_char);
-                               return EINVAL;
-                       }
-                       strncpy(args->mtpt, value, MAXNAMELEN);
-               } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
-                       if (!value || !*value) {
-                               cmn_err(CE_WARN,
-                                       "XFS: %s option requires an argument",
-                                       this_char);
-                               return EINVAL;
-                       }
-                       strncpy(args->rtname, value, MAXNAMELEN);
-               } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
-                       if (!value || !*value) {
-                               cmn_err(CE_WARN,
-                                       "XFS: %s option requires an argument",
-                                       this_char);
-                               return EINVAL;
-                       }
-                       iosize = simple_strtoul(value, &eov, 10);
-                       args->flags |= XFSMNT_IOSIZE;
-                       args->iosizelog = (uint8_t) iosize;
-               } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
-                       if (!value || !*value) {
-                               cmn_err(CE_WARN,
-                                       "XFS: %s option requires an argument",
-                                       this_char);
-                               return EINVAL;
-                       }
-                       iosize = suffix_strtoul(value, &eov, 10);
-                       args->flags |= XFSMNT_IOSIZE;
-                       args->iosizelog = ffs(iosize) - 1;
-               } else if (!strcmp(this_char, MNTOPT_GRPID) ||
-                          !strcmp(this_char, MNTOPT_BSDGROUPS)) {
-                       mp->m_flags |= XFS_MOUNT_GRPID;
-               } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
-                          !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
-                       mp->m_flags &= ~XFS_MOUNT_GRPID;
-               } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
-                       args->flags |= XFSMNT_WSYNC;
-               } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
-                       args->flags |= XFSMNT_OSYNCISOSYNC;
-               } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
-                       args->flags |= XFSMNT_NORECOVERY;
-               } else if (!strcmp(this_char, MNTOPT_INO64)) {
-                       args->flags |= XFSMNT_INO64;
-#if !XFS_BIG_INUMS
-                       cmn_err(CE_WARN,
-                               "XFS: %s option not allowed on this system",
-                               this_char);
-                       return EINVAL;
-#endif
-               } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
-                       args->flags |= XFSMNT_NOALIGN;
-               } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
-                       args->flags |= XFSMNT_SWALLOC;
-               } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
-                       if (!value || !*value) {
-                               cmn_err(CE_WARN,
-                                       "XFS: %s option requires an argument",
-                                       this_char);
-                               return EINVAL;
-                       }
-                       dsunit = simple_strtoul(value, &eov, 10);
-               } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
-                       if (!value || !*value) {
-                               cmn_err(CE_WARN,
-                                       "XFS: %s option requires an argument",
-                                       this_char);
-                               return EINVAL;
-                       }
-                       dswidth = simple_strtoul(value, &eov, 10);
-               } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
-                       args->flags &= ~XFSMNT_32BITINODES;
-#if !XFS_BIG_INUMS
-                       cmn_err(CE_WARN,
-                               "XFS: %s option not allowed on this system",
-                               this_char);
-                       return EINVAL;
-#endif
-               } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
-                       args->flags |= XFSMNT_NOUUID;
-               } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
-                       args->flags |= XFSMNT_BARRIER;
-               } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
-                       args->flags &= ~XFSMNT_BARRIER;
-               } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
-                       ikeep = 1;
-                       args->flags &= ~XFSMNT_IDELETE;
-               } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
-                       args->flags |= XFSMNT_IDELETE;
-               } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
-                       args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
-               } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
-                       args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
-               } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
-                       args->flags |= XFSMNT_ATTR2;
-               } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
-                       args->flags &= ~XFSMNT_ATTR2;
-               } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
-                       args->flags2 |= XFSMNT2_FILESTREAMS;
-               } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
-                       args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
-                       args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
-               } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
-                          !strcmp(this_char, MNTOPT_UQUOTA) ||
-                          !strcmp(this_char, MNTOPT_USRQUOTA)) {
-                       args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
-               } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
-                          !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
-                       args->flags |= XFSMNT_UQUOTA;
-                       args->flags &= ~XFSMNT_UQUOTAENF;
-               } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
-                          !strcmp(this_char, MNTOPT_PRJQUOTA)) {
-                       args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
-               } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
-                       args->flags |= XFSMNT_PQUOTA;
-                       args->flags &= ~XFSMNT_PQUOTAENF;
-               } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
-                          !strcmp(this_char, MNTOPT_GRPQUOTA)) {
-                       args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
-               } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
-                       args->flags |= XFSMNT_GQUOTA;
-                       args->flags &= ~XFSMNT_GQUOTAENF;
-               } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
-                       args->flags |= XFSMNT_DMAPI;
-               } else if (!strcmp(this_char, MNTOPT_XDSM)) {
-                       args->flags |= XFSMNT_DMAPI;
-               } else if (!strcmp(this_char, MNTOPT_DMI)) {
-                       args->flags |= XFSMNT_DMAPI;
-               } else if (!strcmp(this_char, "ihashsize")) {
-                       cmn_err(CE_WARN,
-       "XFS: ihashsize no longer used, option is deprecated.");
-               } else if (!strcmp(this_char, "osyncisdsync")) {
-                       /* no-op, this is now the default */
-                       cmn_err(CE_WARN,
-       "XFS: osyncisdsync is now the default, option is deprecated.");
-               } else if (!strcmp(this_char, "irixsgid")) {
-                       cmn_err(CE_WARN,
-       "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
-               } else {
-                       cmn_err(CE_WARN,
-                               "XFS: unknown mount option [%s].", this_char);
-                       return EINVAL;
-               }
-       }
-
-       if (args->flags & XFSMNT_NORECOVERY) {
-               if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
-                       cmn_err(CE_WARN,
-                               "XFS: no-recovery mounts must be read-only.");
-                       return EINVAL;
-               }
-       }
-
-       if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
-               cmn_err(CE_WARN,
-       "XFS: sunit and swidth options incompatible with the noalign option");
-               return EINVAL;
-       }
-
-       if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
-               cmn_err(CE_WARN,
-                       "XFS: cannot mount with both project and group quota");
-               return EINVAL;
-       }
-
-       if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
-               printk("XFS: %s option needs the mount point option as well\n",
-                       MNTOPT_DMAPI);
-               return EINVAL;
-       }
-
-       if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
-               cmn_err(CE_WARN,
-                       "XFS: sunit and swidth must be specified together");
-               return EINVAL;
-       }
-
-       if (dsunit && (dswidth % dsunit != 0)) {
-               cmn_err(CE_WARN,
-       "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
-                       dswidth, dsunit);
-               return EINVAL;
-       }
-
-       /*
-        * Applications using DMI filesystems often expect the
-        * inode generation number to be monotonically increasing.
-        * If we delete inode chunks we break this assumption, so
-        * keep unused inode chunks on disk for DMI filesystems
-        * until we come up with a better solution.
-        * Note that if "ikeep" or "noikeep" mount options are
-        * supplied, then they are honored.
-        */
-       if (!(args->flags & XFSMNT_DMAPI) && !ikeep)
-               args->flags |= XFSMNT_IDELETE;
-
-       if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
-               if (dsunit) {
-                       args->sunit = dsunit;
-                       args->flags |= XFSMNT_RETERR;
-               } else {
-                       args->sunit = vol_dsunit;
-               }
-               dswidth ? (args->swidth = dswidth) :
-                         (args->swidth = vol_dswidth);
-       } else {
-               args->sunit = args->swidth = 0;
-       }
-
-done:
-       if (args->flags & XFSMNT_32BITINODES)
-               mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
-       if (args->flags2)
-               args->flags |= XFSMNT_FLAGS2;
-       return 0;
-}
-
-int
-xfs_showargs(
-       struct xfs_mount        *mp,
-       struct seq_file         *m)
-{
-       static struct proc_xfs_info {
-               int     flag;
-               char    *str;
-       } xfs_info[] = {
-               /* the few simple ones we can get from the mount struct */
-               { XFS_MOUNT_WSYNC,              "," MNTOPT_WSYNC },
-               { XFS_MOUNT_INO64,              "," MNTOPT_INO64 },
-               { XFS_MOUNT_NOALIGN,            "," MNTOPT_NOALIGN },
-               { XFS_MOUNT_SWALLOC,            "," MNTOPT_SWALLOC },
-               { XFS_MOUNT_NOUUID,             "," MNTOPT_NOUUID },
-               { XFS_MOUNT_NORECOVERY,         "," MNTOPT_NORECOVERY },
-               { XFS_MOUNT_OSYNCISOSYNC,       "," MNTOPT_OSYNCISOSYNC },
-               { 0, NULL }
-       };
-       struct proc_xfs_info    *xfs_infop;
-
-       for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
-               if (mp->m_flags & xfs_infop->flag)
-                       seq_puts(m, xfs_infop->str);
-       }
-
-       if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
-               seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
-                               (int)(1 << mp->m_writeio_log) >> 10);
-
-       if (mp->m_logbufs > 0)
-               seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
-       if (mp->m_logbsize > 0)
-               seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
-
-       if (mp->m_logname)
-               seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
-       if (mp->m_rtname)
-               seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
-
-       if (mp->m_dalign > 0)
-               seq_printf(m, "," MNTOPT_SUNIT "=%d",
-                               (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
-       if (mp->m_swidth > 0)
-               seq_printf(m, "," MNTOPT_SWIDTH "=%d",
-                               (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
-
-       if (!(mp->m_flags & XFS_MOUNT_IDELETE))
-               seq_printf(m, "," MNTOPT_IKEEP);
-       if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
-               seq_printf(m, "," MNTOPT_LARGEIO);
-
-       if (!(mp->m_flags & XFS_MOUNT_SMALL_INUMS))
-               seq_printf(m, "," MNTOPT_64BITINODE);
-       if (mp->m_flags & XFS_MOUNT_GRPID)
-               seq_printf(m, "," MNTOPT_GRPID);
-
-       if (mp->m_qflags & XFS_UQUOTA_ACCT) {
-               if (mp->m_qflags & XFS_UQUOTA_ENFD)
-                       seq_puts(m, "," MNTOPT_USRQUOTA);
-               else
-                       seq_puts(m, "," MNTOPT_UQUOTANOENF);
-       }
-
-       if (mp->m_qflags & XFS_PQUOTA_ACCT) {
-               if (mp->m_qflags & XFS_OQUOTA_ENFD)
-                       seq_puts(m, "," MNTOPT_PRJQUOTA);
-               else
-                       seq_puts(m, "," MNTOPT_PQUOTANOENF);
-       }
-
-       if (mp->m_qflags & XFS_GQUOTA_ACCT) {
-               if (mp->m_qflags & XFS_OQUOTA_ENFD)
-                       seq_puts(m, "," MNTOPT_GRPQUOTA);
-               else
-                       seq_puts(m, "," MNTOPT_GQUOTANOENF);
-       }
-
-       if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
-               seq_puts(m, "," MNTOPT_NOQUOTA);
-
-       if (mp->m_flags & XFS_MOUNT_DMAPI)
-               seq_puts(m, "," MNTOPT_DMAPI);
-       return 0;
-}
-
-/*
- * Second stage of a freeze. The data is already frozen so we only
- * need to take care of themetadata. Once that's done write a dummy
- * record to dirty the log in case of a crash while frozen.
- */
-void
-xfs_freeze(
-       xfs_mount_t     *mp)
-{
-       xfs_attr_quiesce(mp);
-       xfs_fs_log_dummy(mp);
-}
index a592fe02a3393367150447d4dae6af4ce36870dc..1688817c55ed358adeb13a31a04acf05486040a5 100644 (file)
@@ -13,16 +13,9 @@ int xfs_mount(struct xfs_mount *mp, struct xfs_mount_args *args,
 int xfs_unmount(struct xfs_mount *mp, int flags, struct cred *credp);
 int xfs_mntupdate(struct xfs_mount *mp, int *flags,
                struct xfs_mount_args *args);
-int xfs_root(struct xfs_mount *mp, bhv_vnode_t **vpp);
-int xfs_statvfs(struct xfs_mount *mp, struct kstatfs *statp,
-               bhv_vnode_t *vp);
 int xfs_sync(struct xfs_mount *mp, int flags);
-int xfs_vget(struct xfs_mount *mp, bhv_vnode_t **vpp, struct xfs_fid *xfid);
-int xfs_parseargs(struct xfs_mount *mp, char *options,
-               struct xfs_mount_args *args, int update);
-int xfs_showargs(struct xfs_mount *mp, struct seq_file *m);
-void xfs_freeze(struct xfs_mount *mp);
 void xfs_do_force_shutdown(struct xfs_mount *mp, int flags, char *fname,
                int lnnum);
+void xfs_attr_quiesce(struct xfs_mount *mp);
 
 #endif /* _XFS_VFSOPS_H */
index efd5aff9eaf6aa1d149fa6431ca6355e944c5b1a..51305242ff8cb8b8793e4d19412adfdc309aa555 100644 (file)
@@ -88,7 +88,7 @@ xfs_getattr(
        bhv_vnode_t     *vp = XFS_ITOV(ip);
        xfs_mount_t     *mp = ip->i_mount;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
@@ -136,7 +136,7 @@ xfs_getattr(
        default:
                vap->va_rdev = 0;
 
-               if (!(ip->i_d.di_flags & XFS_DIFLAG_REALTIME)) {
+               if (!(XFS_IS_REALTIME_INODE(ip))) {
                        vap->va_blocksize = xfs_preferred_iosize(mp);
                } else {
 
@@ -228,7 +228,7 @@ xfs_setattr(
        int                     file_owner;
        int                     need_iolock = 1;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        if (mp->m_flags & XFS_MOUNT_RDONLY)
                return XFS_ERROR(EROFS);
@@ -508,7 +508,7 @@ xfs_setattr(
                 */
                if ((ip->i_d.di_nextents || ip->i_delayed_blks) &&
                    (mask & XFS_AT_XFLAGS) &&
-                   (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) !=
+                   (XFS_IS_REALTIME_INODE(ip)) !=
                    (vap->va_xflags & XFS_XFLAG_REALTIME)) {
                        code = XFS_ERROR(EINVAL);       /* EFBIG? */
                        goto error_return;
@@ -520,7 +520,7 @@ xfs_setattr(
                if ((mask & XFS_AT_EXTSIZE) && vap->va_extsize != 0) {
                        xfs_extlen_t    size;
 
-                       if ((ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ||
+                       if (XFS_IS_REALTIME_INODE(ip) ||
                            ((mask & XFS_AT_XFLAGS) &&
                            (vap->va_xflags & XFS_XFLAG_REALTIME))) {
                                size = mp->m_sb.sb_rextsize <<
@@ -804,12 +804,8 @@ xfs_setattr(
                                if (vap->va_xflags & XFS_XFLAG_EXTSZINHERIT)
                                        di_flags |= XFS_DIFLAG_EXTSZINHERIT;
                        } else if ((ip->i_d.di_mode & S_IFMT) == S_IFREG) {
-                               if (vap->va_xflags & XFS_XFLAG_REALTIME) {
+                               if (vap->va_xflags & XFS_XFLAG_REALTIME)
                                        di_flags |= XFS_DIFLAG_REALTIME;
-                                       ip->i_iocore.io_flags |= XFS_IOCORE_RT;
-                               } else {
-                                       ip->i_iocore.io_flags &= ~XFS_IOCORE_RT;
-                               }
                                if (vap->va_xflags & XFS_XFLAG_EXTSIZE)
                                        di_flags |= XFS_DIFLAG_EXTSIZE;
                        }
@@ -902,28 +898,6 @@ xfs_setattr(
        return code;
 }
 
-
-/*
- * xfs_access
- * Null conversion from vnode mode bits to inode mode bits, as in efs.
- */
-int
-xfs_access(
-       xfs_inode_t     *ip,
-       int             mode,
-       cred_t          *credp)
-{
-       int             error;
-
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
-
-       xfs_ilock(ip, XFS_ILOCK_SHARED);
-       error = xfs_iaccess(ip, mode, credp);
-       xfs_iunlock(ip, XFS_ILOCK_SHARED);
-       return error;
-}
-
-
 /*
  * The maximum pathlen is 1024 bytes. Since the minimum file system
  * blocksize is 512 bytes, we can get a max of 2 extents back from
@@ -987,7 +961,7 @@ xfs_readlink(
        int             pathlen;
        int             error = 0;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
@@ -1033,7 +1007,7 @@ xfs_fsync(
        int             error;
        int             log_flushed = 0, changed = 1;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        ASSERT(start >= 0 && stop >= -1);
 
@@ -1149,7 +1123,7 @@ xfs_fsync(
                 * If this inode is on the RT dev we need to flush that
                 * cache as well.
                 */
-               if (ip->i_d.di_flags & XFS_DIFLAG_REALTIME)
+               if (XFS_IS_REALTIME_INODE(ip))
                        xfs_blkdev_issue_flush(ip->i_mount->m_rtdev_targp);
        }
 
@@ -1188,7 +1162,7 @@ xfs_free_eofblocks(
 
        nimaps = 1;
        xfs_ilock(ip, XFS_ILOCK_SHARED);
-       error = XFS_BMAPI(mp, NULL, &ip->i_iocore, end_fsb, map_len, 0,
+       error = xfs_bmapi(NULL, ip, end_fsb, map_len, 0,
                          NULL, 0, &imap, &nimaps, NULL, NULL);
        xfs_iunlock(ip, XFS_ILOCK_SHARED);
 
@@ -1562,9 +1536,6 @@ xfs_release(
                        error = xfs_free_eofblocks(mp, ip, XFS_FREE_EOF_LOCK);
                        if (error)
                                return error;
-                       /* Update linux inode block count after free above */
-                       vn_to_inode(vp)->i_blocks = XFS_FSB_TO_BB(mp,
-                               ip->i_d.di_nblocks + ip->i_delayed_blks);
                }
        }
 
@@ -1592,7 +1563,7 @@ xfs_inactive(
        int             error;
        int             truncate;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        /*
         * If the inode is already free, then there can be nothing
@@ -1638,9 +1609,6 @@ xfs_inactive(
                        error = xfs_free_eofblocks(mp, ip, XFS_FREE_EOF_LOCK);
                        if (error)
                                return VN_INACTIVE_CACHE;
-                       /* Update linux inode block count after free above */
-                       vn_to_inode(vp)->i_blocks = XFS_FSB_TO_BB(mp,
-                               ip->i_d.di_nblocks + ip->i_delayed_blks);
                }
                goto out;
        }
@@ -1805,7 +1773,7 @@ xfs_lookup(
        int                     error;
        uint                    lock_mode;
 
-       vn_trace_entry(dp, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(dp);
 
        if (XFS_FORCED_SHUTDOWN(dp->i_mount))
                return XFS_ERROR(EIO);
@@ -1814,7 +1782,7 @@ xfs_lookup(
        error = xfs_dir_lookup_int(dp, lock_mode, dentry, &e_inum, &ip);
        if (!error) {
                *vpp = XFS_ITOV(ip);
-               ITRACE(ip);
+               xfs_itrace_ref(ip);
        }
        xfs_iunlock_map_shared(dp, lock_mode);
        return error;
@@ -1848,7 +1816,7 @@ xfs_create(
        int                     namelen;
 
        ASSERT(!*vpp);
-       vn_trace_entry(dp, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(dp);
 
        namelen = VNAMELEN(dentry);
 
@@ -1930,7 +1898,7 @@ xfs_create(
                        goto error_return;
                goto abort_return;
        }
-       ITRACE(ip);
+       xfs_itrace_ref(ip);
 
        /*
         * At this point, we've gotten a newly allocated inode.
@@ -2098,7 +2066,7 @@ again:
 
        e_inum = ip->i_ino;
 
-       ITRACE(ip);
+       xfs_itrace_ref(ip);
 
        /*
         * We want to lock in increasing inum. Since we've already
@@ -2321,7 +2289,7 @@ xfs_remove(
        uint                    resblks;
        int                     namelen;
 
-       vn_trace_entry(dp, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(dp);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
@@ -2364,9 +2332,8 @@ xfs_remove(
 
        dm_di_mode = ip->i_d.di_mode;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
-
-       ITRACE(ip);
+       xfs_itrace_entry(ip);
+       xfs_itrace_ref(ip);
 
        error = XFS_QM_DQATTACH(mp, dp, 0);
        if (!error && dp != ip)
@@ -2498,8 +2465,7 @@ xfs_remove(
        if (link_zero && xfs_inode_is_filestream(ip))
                xfs_filestream_deassociate(ip);
 
-       vn_trace_exit(ip, __FUNCTION__, (inst_t *)__return_address);
-
+       xfs_itrace_exit(ip);
        IRELE(ip);
 
 /*     Fall through to std_return with error = 0 */
@@ -2562,8 +2528,8 @@ xfs_link(
        char                    *target_name = VNAME(dentry);
        int                     target_namelen;
 
-       vn_trace_entry(tdp, __FUNCTION__, (inst_t *)__return_address);
-       vn_trace_entry(xfs_vtoi(src_vp), __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(tdp);
+       xfs_itrace_entry(xfs_vtoi(src_vp));
 
        target_namelen = VNAMELEN(dentry);
        ASSERT(!VN_ISDIR(src_vp));
@@ -2744,7 +2710,7 @@ xfs_mkdir(
 
        /* Return through std_return after this point. */
 
-       vn_trace_entry(dp, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(dp);
 
        mp = dp->i_mount;
        udqp = gdqp = NULL;
@@ -2810,7 +2776,7 @@ xfs_mkdir(
                        goto error_return;
                goto abort_return;
        }
-       ITRACE(cdp);
+       xfs_itrace_ref(cdp);
 
        /*
         * Now we add the directory inode to the transaction.
@@ -2936,7 +2902,7 @@ xfs_rmdir(
        int                     last_cdp_link;
        uint                    resblks;
 
-       vn_trace_entry(dp, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(dp);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
@@ -3041,7 +3007,7 @@ xfs_rmdir(
                VN_HOLD(dir_vp);
        }
 
-       ITRACE(cdp);
+       xfs_itrace_ref(cdp);
        xfs_trans_ijoin(tp, cdp, XFS_ILOCK_EXCL);
 
        ASSERT(cdp->i_d.di_nlink >= 2);
@@ -3189,8 +3155,7 @@ xfs_symlink(
        ip = NULL;
        tp = NULL;
 
-       vn_trace_entry(dp, __FUNCTION__, (inst_t *)__return_address);
-
+       xfs_itrace_entry(dp);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
@@ -3317,7 +3282,7 @@ xfs_symlink(
                        goto error_return;
                goto error1;
        }
-       ITRACE(ip);
+       xfs_itrace_ref(ip);
 
        /*
         * An error after we've joined dp to the transaction will result in the
@@ -3465,27 +3430,6 @@ std_return:
        goto std_return;
 }
 
-
-int
-xfs_fid2(
-       xfs_inode_t     *ip,
-       xfs_fid_t       *xfid)
-{
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
-
-       xfid->fid_len = sizeof(xfs_fid_t) - sizeof(xfid->fid_len);
-       xfid->fid_pad = 0;
-       /*
-        * use memcpy because the inode is a long long and there's no
-        * assurance that xfid->fid_ino is properly aligned.
-        */
-       memcpy(&xfid->fid_ino, &ip->i_ino, sizeof(xfid->fid_ino));
-       xfid->fid_gen = ip->i_d.di_gen;
-
-       return 0;
-}
-
-
 int
 xfs_rwlock(
        xfs_inode_t     *ip,
@@ -3558,11 +3502,11 @@ xfs_inode_flush(
                if (iip && iip->ili_last_lsn) {
                        xlog_t          *log = mp->m_log;
                        xfs_lsn_t       sync_lsn;
-                       int             s, log_flags = XFS_LOG_FORCE;
+                       int             log_flags = XFS_LOG_FORCE;
 
-                       s = GRANT_LOCK(log);
+                       spin_lock(&log->l_grant_lock);
                        sync_lsn = log->l_last_sync_lsn;
-                       GRANT_UNLOCK(log, s);
+                       spin_unlock(&log->l_grant_lock);
 
                        if ((XFS_LSN_CMP(iip->ili_last_lsn, sync_lsn) > 0)) {
                                if (flags & FLUSH_SYNC)
@@ -3637,8 +3581,8 @@ xfs_set_dmattrs(
        xfs_ilock(ip, XFS_ILOCK_EXCL);
        xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
 
-       ip->i_iocore.io_dmevmask = ip->i_d.di_dmevmask = evmask;
-       ip->i_iocore.io_dmstate  = ip->i_d.di_dmstate  = state;
+       ip->i_d.di_dmevmask = evmask;
+       ip->i_d.di_dmstate  = state;
 
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
        IHOLD(ip);
@@ -3653,7 +3597,7 @@ xfs_reclaim(
 {
        bhv_vnode_t     *vp = XFS_ITOV(ip);
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        ASSERT(!VN_MAPPED(vp));
 
@@ -3871,7 +3815,7 @@ xfs_alloc_file_space(
        int                     committed;
        int                     error;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
@@ -3976,7 +3920,7 @@ retry:
                 * Issue the xfs_bmapi() call to allocate the blocks
                 */
                XFS_BMAP_INIT(&free_list, &firstfsb);
-               error = XFS_BMAPI(mp, tp, &ip->i_iocore, startoffset_fsb,
+               error = xfs_bmapi(tp, ip, startoffset_fsb,
                                  allocatesize_fsb, bmapi_flag,
                                  &firstfsb, 0, imapp, &nimaps,
                                  &free_list, NULL);
@@ -4052,13 +3996,13 @@ xfs_zero_remaining_bytes(
        int                     error = 0;
 
        bp = xfs_buf_get_noaddr(mp->m_sb.sb_blocksize,
-                               ip->i_d.di_flags & XFS_DIFLAG_REALTIME ?
+                               XFS_IS_REALTIME_INODE(ip) ?
                                mp->m_rtdev_targp : mp->m_ddev_targp);
 
        for (offset = startoff; offset <= endoff; offset = lastoffset + 1) {
                offset_fsb = XFS_B_TO_FSBT(mp, offset);
                nimap = 1;
-               error = XFS_BMAPI(mp, NULL, &ip->i_iocore, offset_fsb, 1, 0,
+               error = xfs_bmapi(NULL, ip, offset_fsb, 1, 0,
                        NULL, 0, &imap, &nimap, NULL, NULL);
                if (error || nimap < 1)
                        break;
@@ -4141,7 +4085,7 @@ xfs_free_file_space(
        vp = XFS_ITOV(ip);
        mp = ip->i_mount;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        if ((error = XFS_QM_DQATTACH(mp, ip, 0)))
                return error;
@@ -4149,7 +4093,7 @@ xfs_free_file_space(
        error = 0;
        if (len <= 0)   /* if nothing being freed */
                return error;
-       rt = (ip->i_d.di_flags & XFS_DIFLAG_REALTIME);
+       rt = XFS_IS_REALTIME_INODE(ip);
        startoffset_fsb = XFS_B_TO_FSB(mp, offset);
        end_dmi_offset = offset + len;
        endoffset_fsb = XFS_B_TO_FSBT(mp, end_dmi_offset);
@@ -4172,15 +4116,12 @@ xfs_free_file_space(
                vn_iowait(ip);  /* wait for the completion of any pending DIOs */
        }
 
-       rounding = max_t(uint, 1 << mp->m_sb.sb_blocklog, NBPP);
+       rounding = max_t(uint, 1 << mp->m_sb.sb_blocklog, PAGE_CACHE_SIZE);
        ioffset = offset & ~(rounding - 1);
 
        if (VN_CACHED(vp) != 0) {
-               xfs_inval_cached_trace(&ip->i_iocore, ioffset, -1,
-                               ctooff(offtoct(ioffset)), -1);
-               error = xfs_flushinval_pages(ip,
-                               ctooff(offtoct(ioffset)),
-                               -1, FI_REMAPF_LOCKED);
+               xfs_inval_cached_trace(ip, ioffset, -1, ioffset, -1);
+               error = xfs_flushinval_pages(ip, ioffset, -1, FI_REMAPF_LOCKED);
                if (error)
                        goto out_unlock_iolock;
        }
@@ -4193,7 +4134,7 @@ xfs_free_file_space(
         */
        if (rt && !XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb)) {
                nimap = 1;
-               error = XFS_BMAPI(mp, NULL, &ip->i_iocore, startoffset_fsb,
+               error = xfs_bmapi(NULL, ip, startoffset_fsb,
                        1, 0, NULL, 0, &imap, &nimap, NULL, NULL);
                if (error)
                        goto out_unlock_iolock;
@@ -4208,7 +4149,7 @@ xfs_free_file_space(
                                startoffset_fsb += mp->m_sb.sb_rextsize - mod;
                }
                nimap = 1;
-               error = XFS_BMAPI(mp, NULL, &ip->i_iocore, endoffset_fsb - 1,
+               error = xfs_bmapi(NULL, ip, endoffset_fsb - 1,
                        1, 0, NULL, 0, &imap, &nimap, NULL, NULL);
                if (error)
                        goto out_unlock_iolock;
@@ -4284,7 +4225,7 @@ xfs_free_file_space(
                 * issue the bunmapi() call to free the blocks
                 */
                XFS_BMAP_INIT(&free_list, &firstfsb);
-               error = XFS_BUNMAPI(mp, tp, &ip->i_iocore, startoffset_fsb,
+               error = xfs_bunmapi(tp, ip, startoffset_fsb,
                                  endoffset_fsb - startoffset_fsb,
                                  0, 2, &firstfsb, &free_list, NULL, &done);
                if (error) {
@@ -4347,23 +4288,11 @@ xfs_change_file_space(
        xfs_trans_t     *tp;
        bhv_vattr_t     va;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
-       /*
-        * must be a regular file and have write permission
-        */
        if (!S_ISREG(ip->i_d.di_mode))
                return XFS_ERROR(EINVAL);
 
-       xfs_ilock(ip, XFS_ILOCK_SHARED);
-
-       if ((error = xfs_iaccess(ip, S_IWUSR, credp))) {
-               xfs_iunlock(ip, XFS_ILOCK_SHARED);
-               return error;
-       }
-
-       xfs_iunlock(ip, XFS_ILOCK_SHARED);
-
        switch (bf->l_whence) {
        case 0: /*SEEK_SET*/
                break;
index b7e461c40cfbace8e0289ab1d131a67f8b813a86..4e3970f0e5e37f96138189aef88a305f27ee06bd 100644 (file)
@@ -18,7 +18,6 @@ int xfs_open(struct xfs_inode *ip);
 int xfs_getattr(struct xfs_inode *ip, struct bhv_vattr *vap, int flags);
 int xfs_setattr(struct xfs_inode *ip, struct bhv_vattr *vap, int flags,
                struct cred *credp);
-int xfs_access(struct xfs_inode *ip, int mode, struct cred *credp);
 int xfs_readlink(struct xfs_inode *ip, char *link);
 int xfs_fsync(struct xfs_inode *ip, int flag, xfs_off_t start,
                xfs_off_t stop);
@@ -39,7 +38,6 @@ int xfs_readdir(struct xfs_inode      *dp, void *dirent, size_t bufsize,
 int xfs_symlink(struct xfs_inode *dp, bhv_vname_t *dentry,
                char *target_path, mode_t mode, bhv_vnode_t **vpp,
                struct cred *credp);
-int xfs_fid2(struct xfs_inode *ip, struct xfs_fid *xfid);
 int xfs_rwlock(struct xfs_inode *ip, bhv_vrwlock_t locktype);
 void xfs_rwunlock(struct xfs_inode *ip, bhv_vrwlock_t locktype);
 int xfs_inode_flush(struct xfs_inode *ip, int flags);
diff --git a/include/asm-alpha/a.out-core.h b/include/asm-alpha/a.out-core.h
new file mode 100644 (file)
index 0000000..9e33e92
--- /dev/null
@@ -0,0 +1,80 @@
+/* a.out coredump register dumper
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_A_OUT_CORE_H
+#define _ASM_A_OUT_CORE_H
+
+#ifdef __KERNEL__
+
+#include <linux/user.h>
+
+/*
+ * Fill in the user structure for an ECOFF core dump.
+ */
+static inline void aout_dump_thread(struct pt_regs *pt, struct user *dump)
+{
+       /* switch stack follows right below pt_regs: */
+       struct switch_stack * sw = ((struct switch_stack *) pt) - 1;
+
+       dump->magic = CMAGIC;
+       dump->start_code  = current->mm->start_code;
+       dump->start_data  = current->mm->start_data;
+       dump->start_stack = rdusp() & ~(PAGE_SIZE - 1);
+       dump->u_tsize = ((current->mm->end_code - dump->start_code)
+                        >> PAGE_SHIFT);
+       dump->u_dsize = ((current->mm->brk + PAGE_SIZE-1 - dump->start_data)
+                        >> PAGE_SHIFT);
+       dump->u_ssize = (current->mm->start_stack - dump->start_stack
+                        + PAGE_SIZE-1) >> PAGE_SHIFT;
+
+       /*
+        * We store the registers in an order/format that is
+        * compatible with DEC Unix/OSF/1 as this makes life easier
+        * for gdb.
+        */
+       dump->regs[EF_V0]  = pt->r0;
+       dump->regs[EF_T0]  = pt->r1;
+       dump->regs[EF_T1]  = pt->r2;
+       dump->regs[EF_T2]  = pt->r3;
+       dump->regs[EF_T3]  = pt->r4;
+       dump->regs[EF_T4]  = pt->r5;
+       dump->regs[EF_T5]  = pt->r6;
+       dump->regs[EF_T6]  = pt->r7;
+       dump->regs[EF_T7]  = pt->r8;
+       dump->regs[EF_S0]  = sw->r9;
+       dump->regs[EF_S1]  = sw->r10;
+       dump->regs[EF_S2]  = sw->r11;
+       dump->regs[EF_S3]  = sw->r12;
+       dump->regs[EF_S4]  = sw->r13;
+       dump->regs[EF_S5]  = sw->r14;
+       dump->regs[EF_S6]  = sw->r15;
+       dump->regs[EF_A3]  = pt->r19;
+       dump->regs[EF_A4]  = pt->r20;
+       dump->regs[EF_A5]  = pt->r21;
+       dump->regs[EF_T8]  = pt->r22;
+       dump->regs[EF_T9]  = pt->r23;
+       dump->regs[EF_T10] = pt->r24;
+       dump->regs[EF_T11] = pt->r25;
+       dump->regs[EF_RA]  = pt->r26;
+       dump->regs[EF_T12] = pt->r27;
+       dump->regs[EF_AT]  = pt->r28;
+       dump->regs[EF_SP]  = rdusp();
+       dump->regs[EF_PS]  = pt->ps;
+       dump->regs[EF_PC]  = pt->pc;
+       dump->regs[EF_GP]  = pt->gp;
+       dump->regs[EF_A0]  = pt->r16;
+       dump->regs[EF_A1]  = pt->r17;
+       dump->regs[EF_A2]  = pt->r18;
+       memcpy((char *)dump->regs + EF_SIZE, sw->fp, 32 * 8);
+}
+
+#endif /* __KERNEL__ */
+#endif /* _ASM_A_OUT_CORE_H */
index e43cf61649a9e07195e1ccf815b12bedf0d4376a..02ce8473870a96c326b91fe8a8f321b0c734dc0f 100644 (file)
@@ -98,11 +98,5 @@ struct exec
        set_personality (((BFPM->sh_bang || EX.ah.entry < 0x100000000L \
                           ? ADDR_LIMIT_32BIT : 0) | PER_OSF4))
 
-#define STACK_TOP \
-  (current->personality & ADDR_LIMIT_32BIT ? 0x80000000 : 0x00120000000UL)
-
-#define STACK_TOP_MAX  0x00120000000UL
-
-#endif
-
+#endif /* __KERNEL__ */
 #endif /* __A_OUT_GNU_H__ */
index 05f09f997d829429f0ece5af420105299997afd0..22ff9762d17b63b8379abea371cb816d37dcaae2 100644 (file)
@@ -62,6 +62,8 @@ typedef unsigned long pgprot_t;
 
 #endif /* STRICT_MM_TYPECHECKS */
 
+typedef struct page *pgtable_t;
+
 #ifdef USE_48_BIT_KSEG
 #define PAGE_OFFSET            0xffff800000000000UL
 #else
index 214e7996346f25e890c9221c35fac975f4e7ee78..0982f1d39499fbe337b440cc995913e2fbbb792d 100644 (file)
@@ -5,15 +5,7 @@
    hardware ignores reprogramming.  We also need userland buy-in to the 
    change in HZ, since this is visible in the wait4 resources etc.  */
 
-
-#ifndef HZ
-# ifndef CONFIG_ALPHA_RAWHIDE
-#  define HZ   1024
-# else
-#  define HZ   1200
-# endif
-#endif
-
+#define HZ             CONFIG_HZ
 #define USER_HZ                HZ
 
 #define EXEC_PAGESIZE  8192
index fdbedacc7375158990236e13b546a7fa1c92a8a6..fd090155dccd14367fcde13c425f5d224de7eb21 100644 (file)
  */
 
 static inline void
-pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte)
+pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t pte)
 {
        pmd_set(pmd, (pte_t *)(page_to_pa(pte) + PAGE_OFFSET));
 }
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 static inline void
 pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
@@ -57,18 +58,23 @@ pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        free_page((unsigned long)pte);
 }
 
-static inline struct page *
-pte_alloc_one(struct mm_struct *mm, unsigned long addr)
+static inline pgtable_t
+pte_alloc_one(struct mm_struct *mm, unsigned long address)
 {
-       pte_t *pte = pte_alloc_one_kernel(mm, addr);
-       if (pte)
-               return virt_to_page(pte);
-       return NULL;
+       pte_t *pte = pte_alloc_one_kernel(mm, address);
+       struct page *page;
+
+       if (!pte)
+               return NULL;
+       page = virt_to_page(pte);
+       pgtable_page_ctor(page);
+       return page;
 }
 
 static inline void
-pte_free(struct mm_struct *mm, struct page *page)
+pte_free(struct mm_struct *mm, pgtable_t page)
 {
+       pgtable_page_dtor(page);
        __free_page(page);
 }
 
index 425b7b6d28cbba8e99ec8c1bbd9af578b77752df..94afe5859301f272eb6dedf7343f6e877f8fd77c 100644 (file)
  */
 #define TASK_SIZE (0x40000000000UL)
 
+#define STACK_TOP \
+  (current->personality & ADDR_LIMIT_32BIT ? 0x80000000 : 0x00120000000UL)
+
+#define STACK_TOP_MAX  0x00120000000UL
+
 /* This decides where the kernel will search for a free chunk of vm
  * space during mmap's.
  */
diff --git a/include/asm-arm/a.out-core.h b/include/asm-arm/a.out-core.h
new file mode 100644 (file)
index 0000000..93d04ac
--- /dev/null
@@ -0,0 +1,49 @@
+/* a.out coredump register dumper
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_A_OUT_CORE_H
+#define _ASM_A_OUT_CORE_H
+
+#ifdef __KERNEL__
+
+#include <linux/user.h>
+#include <linux/elfcore.h>
+
+/*
+ * fill in the user structure for an a.out core dump
+ */
+static inline void aout_dump_thread(struct pt_regs *regs, struct user *dump)
+{
+       struct task_struct *tsk = current;
+
+       dump->magic = CMAGIC;
+       dump->start_code = tsk->mm->start_code;
+       dump->start_stack = regs->ARM_sp & ~(PAGE_SIZE - 1);
+
+       dump->u_tsize = (tsk->mm->end_code - tsk->mm->start_code) >> PAGE_SHIFT;
+       dump->u_dsize = (tsk->mm->brk - tsk->mm->start_data + PAGE_SIZE - 1) >> PAGE_SHIFT;
+       dump->u_ssize = 0;
+
+       dump->u_debugreg[0] = tsk->thread.debug.bp[0].address;
+       dump->u_debugreg[1] = tsk->thread.debug.bp[1].address;
+       dump->u_debugreg[2] = tsk->thread.debug.bp[0].insn.arm;
+       dump->u_debugreg[3] = tsk->thread.debug.bp[1].insn.arm;
+       dump->u_debugreg[4] = tsk->thread.debug.nsaved;
+
+       if (dump->start_stack < 0x04000000)
+               dump->u_ssize = (0x04000000 - dump->start_stack) >> PAGE_SHIFT;
+
+       dump->regs = *regs;
+       dump->u_fpvalid = dump_fpu (regs, &dump->u_fp);
+}
+
+#endif /* __KERNEL__ */
+#endif /* _ASM_A_OUT_CORE_H */
index d7165e86df25012d4e56ed99666dc2c7cbbad95f..79489fdcc8b812c4ba81e88dd4bd3692622efac5 100644 (file)
@@ -27,12 +27,6 @@ struct exec
 
 #define M_ARM 103
 
-#ifdef __KERNEL__
-#define STACK_TOP      ((current->personality == PER_LINUX_32BIT) ? \
-                        TASK_SIZE : TASK_SIZE_26)
-#define STACK_TOP_MAX  TASK_SIZE
-#endif
-
 #ifndef LIBRARY_START_TEXT
 #define LIBRARY_START_TEXT     (0x00c00000)
 #endif
index cb29d84e690ddd9a25109731389c34954f49a39c..020bd98710a13ce2e82ff5e0741fa89308172985 100644 (file)
@@ -24,7 +24,7 @@
  * reattempted until it succeeds.
  */
 static inline void
-__mutex_fastpath_lock(atomic_t *count, fastcall void (*fail_fn)(atomic_t *))
+__mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
 {
        int __ex_flag, __res;
 
@@ -44,7 +44,7 @@ __mutex_fastpath_lock(atomic_t *count, fastcall void (*fail_fn)(atomic_t *))
 }
 
 static inline int
-__mutex_fastpath_lock_retval(atomic_t *count, fastcall int (*fail_fn)(atomic_t *))
+__mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
 {
        int __ex_flag, __res;
 
@@ -70,7 +70,7 @@ __mutex_fastpath_lock_retval(atomic_t *count, fastcall int (*fail_fn)(atomic_t *
  * better generated assembly.
  */
 static inline void
-__mutex_fastpath_unlock(atomic_t *count, fastcall void (*fail_fn)(atomic_t *))
+__mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *))
 {
        int __ex_flag, __res, __orig;
 
index 31ff12f4ffb7b5fdb757767a159c4f855c544630..c86f68ee65118b6c7cdd2fec34ee7509abbaae46 100644 (file)
@@ -171,6 +171,8 @@ typedef unsigned long pgprot_t;
 
 #endif /* STRICT_MM_TYPECHECKS */
 
+typedef struct page *pgtable_t;
+
 #endif /* CONFIG_MMU */
 
 #include <asm/memory.h>
index fb6c6e3222bddc19131fc59408e12ffbfb824a22..163b0305dd76b3e83176f294eb204d3a389bd3ad 100644 (file)
@@ -66,7 +66,7 @@ pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr)
        return pte;
 }
 
-static inline struct page *
+static inline pgtable_t
 pte_alloc_one(struct mm_struct *mm, unsigned long addr)
 {
        struct page *pte;
@@ -75,6 +75,7 @@ pte_alloc_one(struct mm_struct *mm, unsigned long addr)
        if (pte) {
                void *page = page_address(pte);
                clean_dcache_area(page, sizeof(pte_t) * PTRS_PER_PTE);
+               pgtable_page_ctor(pte);
        }
 
        return pte;
@@ -91,8 +92,9 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        }
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *pte)
+static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 {
+       pgtable_page_dtor(pte);
        __free_page(pte);
 }
 
@@ -123,10 +125,11 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
 }
 
 static inline void
-pmd_populate(struct mm_struct *mm, pmd_t *pmdp, struct page *ptep)
+pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
 {
        __pmd_populate(pmdp, page_to_pfn(ptep) << PAGE_SHIFT | _PAGE_USER_TABLE);
 }
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 #endif /* CONFIG_MMU */
 
index e142a2a016ca06d391adf5564ba2141c06ad02ac..c37379dadcb294f92a88d1c145029f935eed7c78 100644 (file)
@@ -51,14 +51,10 @@ typedef long long           __kernel_loff_t;
 #endif
 
 typedef struct {
-#if defined(__KERNEL__) || defined(__USE_ALL)
        int     val[2];
-#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
-       int     __val[2];
-#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
 } __kernel_fsid_t;
 
-#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
+#if defined(__KERNEL__)
 
 #undef __FD_SET
 #define __FD_SET(fd, fdsetp) \
index 1bbf16182d62ab4bfabd3c13e065d8280c38ccd9..bd8029e8dc67fd19cc6ed02f5f62f0debb074dd1 100644 (file)
 #include <asm/ptrace.h>
 #include <asm/types.h>
 
+#ifdef __KERNEL__
+#define STACK_TOP      ((current->personality == PER_LINUX_32BIT) ? \
+                        TASK_SIZE : TASK_SIZE_26)
+#define STACK_TOP_MAX  TASK_SIZE
+#endif
+
 union debug_insn {
        u32     arm;
        u16     thumb;
index 9f398ab28ed08c983934c7c08c0f598a52615700..e46375a34a72f0dbda360b82ac68d9d038d88425 100644 (file)
@@ -17,11 +17,4 @@ struct exec
 #define N_DRSIZE(a)    ((a).a_drsize)
 #define N_SYMSIZE(a)   ((a).a_syms)
 
-#ifdef __KERNEL__
-
-#define STACK_TOP      TASK_SIZE
-#define STACK_TOP_MAX  STACK_TOP
-
-#endif
-
 #endif /* __ASM_AVR32_A_OUT_H */
index d6993a6b6473b8071c42ef9c5485f7f5dbb6d95d..7597b0bd2f01d6527f5f8db835c0c10a2521b6b0 100644 (file)
@@ -51,6 +51,9 @@ struct platform_device *
 at32_add_device_ide(unsigned int id, unsigned int extint,
                    struct ide_platform_data *data);
 
+/* mask says which PWM channels to mux */
+struct platform_device *at32_add_device_pwm(u32 mask);
+
 /* depending on what's hooked up, not all SSC pins will be used */
 #define        ATMEL_SSC_TK            0x01
 #define        ATMEL_SSC_TF            0x02
index ee23499cec34df071b4c6a75ae189ed08797f7df..5582968feee853220432ac4b503c038c4beb7d0f 100644 (file)
@@ -34,6 +34,7 @@ extern void copy_page(void *to, void *from);
 typedef struct { unsigned long pte; } pte_t;
 typedef struct { unsigned long pgd; } pgd_t;
 typedef struct { unsigned long pgprot; } pgprot_t;
+typedef struct page *pgtable_t;
 
 #define pte_val(x)             ((x).pte)
 #define pgd_val(x)             ((x).pgd)
index b77e364b4c444a164c9741d2d6ab94df1dfc2e35..51fc1f6e4b17afb9d73b7065ad6bea459549d205 100644 (file)
        set_pmd(pmd, __pmd(_PAGE_TABLE + __pa(pte)))
 
 static __inline__ void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
-                                   struct page *pte)
+                                   pgtable_t pte)
 {
        set_pmd(pmd, __pmd(_PAGE_TABLE + page_to_phys(pte)));
 }
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 /*
  * Allocate and free page tables
@@ -51,7 +52,9 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm,
        struct page *pte;
 
        pte = alloc_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
-
+       if (!pte)
+               return NULL;
+       pgtable_page_ctor(pte);
        return pte;
 }
 
@@ -60,12 +63,17 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        free_page((unsigned long)pte);
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *pte)
+static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 {
+       pgtable_page_dtor(pte);
        __free_page(pte);
 }
 
-#define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
+#define __pte_free_tlb(tlb,pte)                                \
+do {                                                   \
+       pgtable_page_dtor(pte);                         \
+       tlb_remove_page((tlb), pte);                    \
+} while (0)
 
 #define check_pgt_cache() do { } while(0)
 
index 9e255b9996393aa503290b865534198ec32e93ad..fe0c0c014389934df839a35b03b075f6e02cd631 100644 (file)
@@ -46,11 +46,7 @@ typedef long long       __kernel_loff_t;
 #endif
 
 typedef struct {
-#if defined(__KERNEL__) || defined(__USE_ALL)
     int     val[2];
-#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
-    int     __val[2];
-#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
 } __kernel_fsid_t;
 
 #if defined(__KERNEL__)
index 4212551c1cd9962d81268ed0e40e23e4ebefd0aa..49a88f5a9d2feda1c7b033cfd19c71453c6dd6bf 100644 (file)
 
 #define TASK_SIZE      0x80000000
 
+#ifdef __KERNEL__
+#define STACK_TOP      TASK_SIZE
+#define STACK_TOP_MAX  STACK_TOP
+#endif
+
 #ifndef __ASSEMBLY__
 
 static inline void *current_text_addr(void)
index d37a6849bf74968d2e7d4b18c59fd6003e776150..6c3d652ebd33e02786bfe411cfa28f74b4e59c3f 100644 (file)
@@ -16,10 +16,4 @@ struct exec {
 #define N_DRSIZE(a)    ((a).a_drsize)
 #define N_SYMSIZE(a)   ((a).a_syms)
 
-#ifdef __KERNEL__
-
-#define STACK_TOP      TASK_SIZE
-
-#endif
-
 #endif                         /* __BFIN_A_OUT_H__ */
index c3fa50fa50b845f6c3d9b5d48c8ee17de80526b9..23aa1f8c1bd17ad9ffe7f8bd19e8f1435776fe72 100644 (file)
@@ -39,14 +39,10 @@ typedef long long __kernel_loff_t;
 #endif
 
 typedef struct {
-#if defined(__KERNEL__) || defined(__USE_ALL)
        int val[2];
-#else                          /* !defined(__KERNEL__) && !defined(__USE_ALL) */
-       int __val[2];
-#endif                         /* !defined(__KERNEL__) && !defined(__USE_ALL) */
 } __kernel_fsid_t;
 
-#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
+#if defined(__KERNEL__)
 
 #undef __FD_SET
 #define        __FD_SET(d, set)        ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
@@ -60,6 +56,6 @@ typedef struct {
 #undef __FD_ZERO
 #define __FD_ZERO(fdsetp) (memset (fdsetp, 0, sizeof(*(fd_set *)fdsetp)))
 
-#endif                         /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+#endif                         /* defined(__KERNEL__) */
 
 #endif
index c571e958558cde4876c663a7a084ffa74883f489..1033e5c7601190089dfbd6cf7a19b95d32e796d2 100644 (file)
@@ -30,6 +30,10 @@ static inline void wrusp(unsigned long usp)
 extern unsigned long memory_end;
 #define TASK_SIZE      (memory_end)
 
+#ifdef __KERNEL__
+#define STACK_TOP      TASK_SIZE
+#endif
+
 #define TASK_UNMAPPED_BASE     0
 
 struct thread_struct {
index 919b34a084f8fe3967d1f0b54603a9cb232eab04..c82e9f9b75f68d8206b48dc4f6036f8726941e01 100644 (file)
@@ -6,11 +6,6 @@
  * wants to know about a.out even if there is no interpreter available...
  */
 
-/* grabbed from the intel stuff  */   
-#define STACK_TOP TASK_SIZE
-#define STACK_TOP_MAX  STACK_TOP
-
-
 struct exec
 {
   unsigned long a_info;                /* Use macros N_MAGIC, etc for access */
@@ -28,5 +23,4 @@ struct exec
 #define N_DRSIZE(a)    ((a).a_drsize)
 #define N_SYMSIZE(a)   ((a).a_syms)
 
-
 #endif
index 3b0156c4631107dc91dc13dd86468f2dff2c91ca..c45bb1ef397cb3466c2d836f8fc1679ba69d4a9d 100644 (file)
@@ -26,6 +26,7 @@
 typedef struct { unsigned long pte; } pte_t;
 typedef struct { unsigned long pgd; } pgd_t;
 typedef struct { unsigned long pgprot; } pgprot_t;
+typedef struct page *pgtable_t;
 #endif
 
 #define pte_val(x)     ((x).pte)
index b249726398320ffcc9b12d56fc227dc3be6929e5..0e47994e40be536de84bcb6ed85a37770fb6015a 100644 (file)
@@ -3,7 +3,7 @@
 
 /* Currently we assume that HZ=100 is good for CRIS. */
 #ifdef __KERNEL__
-# define HZ            100             /* Internal kernel timer frequency */
+# define HZ            CONFIG_HZ       /* Internal kernel timer frequency */
 # define USER_HZ       100             /* .. some user interfaces are in "ticks" */
 # define CLOCKS_PER_SEC        (USER_HZ)       /* like times() */
 #endif
index 8ddd66f8177346aeba8c6dd42bf1d313e2355b0a..a1ba761d0573637ffb79ff4f9d6624d644dad9ce 100644 (file)
@@ -6,6 +6,7 @@
 
 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, pte)
 #define pmd_populate(mm, pmd, pte) pmd_set(pmd, page_address(pte))
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 /*
  * Allocate and free page tables.
@@ -27,10 +28,11 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long ad
        return pte;
 }
 
-static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
+static inline pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
 {
        struct page *pte;
        pte = alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0);
+       pgtable_page_ctor(pte);
        return pte;
 }
 
@@ -39,13 +41,17 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        free_page((unsigned long)pte);
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *pte)
+static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 {
+       pgtable_page_dtor(pte);
        __free_page(pte);
 }
 
-
-#define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
+#define __pte_free_tlb(tlb,pte)                                \
+do {                                                   \
+       pgtable_page_dtor(pte);                         \
+       tlb_remove_page((tlb), pte);                    \
+} while (0)
 
 #define check_pgt_cache()          do { } while (0)
 
index 3a5e4c43eae730c6acce90361cb83a9d7adc266d..ce3fb25a460b81ef5e32592bd2c004afe4f9cbc9 100644 (file)
@@ -44,11 +44,7 @@ typedef long long    __kernel_loff_t;
 #endif
 
 typedef struct {
-#if defined(__KERNEL__) || defined(__USE_ALL)
        int     val[2];
-#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
-       int     __val[2];
-#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
 } __kernel_fsid_t;
 
 #ifdef __KERNEL__
index 568da1deceb908d9f89f341b810954b3958d1487..cdc0c1dce6be32891de3092bdea19aca17972d75 100644 (file)
@@ -17,6 +17,9 @@
 
 struct task_struct;
 
+#define STACK_TOP      TASK_SIZE
+#define STACK_TOP_MAX  STACK_TOP
+
 /* This decides where the kernel will search for a free chunk of vm
  * space during mmap's.
  */
diff --git a/include/asm-frv/a.out.h b/include/asm-frv/a.out.h
deleted file mode 100644 (file)
index dd3b7e5..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-/*
- * FRV doesn't do AOUT format. This header file should be removed as
- * soon as fs/exec.c and fs/proc/kcore.c and the archs that require
- * them to include linux/a.out.h are fixed.
- */
index cacc045700de98eb36f156738cb12b2c24f0ad36..c2c1e89e747d248d78c0a7535fe2b4f11740edb7 100644 (file)
@@ -25,6 +25,7 @@ typedef struct { unsigned long        ste[64];} pmd_t;
 typedef struct { pmd_t         pue[1]; } pud_t;
 typedef struct { pud_t         pge[1]; } pgd_t;
 typedef struct { unsigned long pgprot; } pgprot_t;
+typedef struct page *pgtable_t;
 
 #define pte_val(x)     ((x).pte)
 #define pmd_val(x)     ((x).ste[0])
index 365653b1726c18892a3a1ea5efb760b50f64ddaa..6859dd503ed366910cfe0fa85e7c0acf53e7f525 100644 (file)
@@ -2,7 +2,7 @@
 #define _ASM_PARAM_H
 
 #ifdef __KERNEL__
-#define HZ             1000            /* Internal kernel timer frequency */
+#define HZ             CONFIG_HZ       /* Internal kernel timer frequency */
 #define USER_HZ                100             /* .. some user interfaces are in "ticks" */
 #define CLOCKS_PER_SEC (USER_HZ)       /* like times() */
 #endif
index e89620ef08cab876e315ec845d6c96d0d6e1cc97..971e6addb0095a4175d86b68715937e918d2f474 100644 (file)
@@ -25,6 +25,7 @@
 do {                                                                           \
        __set_pmd((PMD), page_to_pfn(PAGE) << PAGE_SHIFT | _PAGE_TABLE);        \
 } while(0)
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 /*
  * Allocate and free page tables.
@@ -35,19 +36,24 @@ extern void pgd_free(struct mm_struct *mm, pgd_t *);
 
 extern pte_t *pte_alloc_one_kernel(struct mm_struct *, unsigned long);
 
-extern struct page *pte_alloc_one(struct mm_struct *, unsigned long);
+extern pgtable_t pte_alloc_one(struct mm_struct *, unsigned long);
 
 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        free_page((unsigned long)pte);
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *pte)
+static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 {
+       pgtable_page_dtor(pte);
        __free_page(pte);
 }
 
-#define __pte_free_tlb(tlb,pte)                tlb_remove_page((tlb),(pte))
+#define __pte_free_tlb(tlb,pte)                                \
+do {                                                   \
+       pgtable_page_dtor(pte);                         \
+       tlb_remove_page((tlb),(pte));                   \
+} while (0)
 
 /*
  * allocating and freeing a pmd is trivial: the 1-entry pmd is
index 73c2ba8d76b4877a2a0d2dc70abf4e7be37e2c80..a9f1f5be0632e86bdecdda60d3dccffdb6510e7a 100644 (file)
@@ -39,14 +39,10 @@ typedef long long   __kernel_loff_t;
 #endif
 
 typedef struct {
-#if defined(__KERNEL__) || defined(__USE_ALL)
        int     val[2];
-#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
-       int     __val[2];
-#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
 } __kernel_fsid_t;
 
-#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
+#if defined(__KERNEL__)
 
 #undef __FD_SET
 #define        __FD_SET(d, set)        ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
@@ -60,7 +56,7 @@ typedef struct {
 #undef __FD_ZERO
 #define __FD_ZERO(fdsetp) (memset (fdsetp, 0, sizeof(*(fd_set *)fdsetp)))
 
-#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+#endif /* defined(__KERNEL__) */
 
 #endif
 
index 57ba6063595914a8021b38d923b23763da80ab5f..fd9dcfd91c396188a1fe6148e85914c8d857a75d 100644 (file)
@@ -1,4 +1,6 @@
+ifeq ($(wildcard include/asm-$(SRCARCH)/a.out.h),include/asm-$(SRCARCH)/a.out.h)
 unifdef-y += a.out.h
+endif
 unifdef-y += auxvec.h
 unifdef-y += byteorder.h
 unifdef-y += errno.h
index cde592fca441824f23869d55617e36b58438c979..67dc84cd1343dd6d1674b64f2be832481f0ed072 100644 (file)
  * in the low address range. Architectures for which this is not
  * true can't use this generic implementation.
  */
-extern unsigned int fastcall ioread8(void __iomem *);
-extern unsigned int fastcall ioread16(void __iomem *);
-extern unsigned int fastcall ioread16be(void __iomem *);
-extern unsigned int fastcall ioread32(void __iomem *);
-extern unsigned int fastcall ioread32be(void __iomem *);
+extern unsigned int ioread8(void __iomem *);
+extern unsigned int ioread16(void __iomem *);
+extern unsigned int ioread16be(void __iomem *);
+extern unsigned int ioread32(void __iomem *);
+extern unsigned int ioread32be(void __iomem *);
 
-extern void fastcall iowrite8(u8, void __iomem *);
-extern void fastcall iowrite16(u16, void __iomem *);
-extern void fastcall iowrite16be(u16, void __iomem *);
-extern void fastcall iowrite32(u32, void __iomem *);
-extern void fastcall iowrite32be(u32, void __iomem *);
+extern void iowrite8(u8, void __iomem *);
+extern void iowrite16(u16, void __iomem *);
+extern void iowrite16be(u16, void __iomem *);
+extern void iowrite32(u32, void __iomem *);
+extern void iowrite32be(u32, void __iomem *);
 
 /*
  * "string" versions of the above. Note that they
@@ -48,13 +48,13 @@ extern void fastcall iowrite32be(u32, void __iomem *);
  * memory across multiple ports, use "memcpy_toio()"
  * and friends.
  */
-extern void fastcall ioread8_rep(void __iomem *port, void *buf, unsigned long count);
-extern void fastcall ioread16_rep(void __iomem *port, void *buf, unsigned long count);
-extern void fastcall ioread32_rep(void __iomem *port, void *buf, unsigned long count);
+extern void ioread8_rep(void __iomem *port, void *buf, unsigned long count);
+extern void ioread16_rep(void __iomem *port, void *buf, unsigned long count);
+extern void ioread32_rep(void __iomem *port, void *buf, unsigned long count);
 
-extern void fastcall iowrite8_rep(void __iomem *port, const void *buf, unsigned long count);
-extern void fastcall iowrite16_rep(void __iomem *port, const void *buf, unsigned long count);
-extern void fastcall iowrite32_rep(void __iomem *port, const void *buf, unsigned long count);
+extern void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count);
+extern void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count);
+extern void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count);
 
 /* Create a virtual mapping cookie for an IO port range */
 extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
index 0134151656af2f8d5b0def7315f8108c6644cadf..ed108be6743fcaaca05c2f312f66bdca825abd9e 100644 (file)
@@ -18,7 +18,7 @@
  * 1 even when the "1" assertion wasn't true.
  */
 static inline void
-__mutex_fastpath_lock(atomic_t *count, fastcall void (*fail_fn)(atomic_t *))
+__mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
 {
        if (unlikely(atomic_dec_return(count) < 0))
                fail_fn(count);
@@ -37,7 +37,7 @@ __mutex_fastpath_lock(atomic_t *count, fastcall void (*fail_fn)(atomic_t *))
  * or anything the slow path function returns.
  */
 static inline int
-__mutex_fastpath_lock_retval(atomic_t *count, fastcall int (*fail_fn)(atomic_t *))
+__mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
 {
        if (unlikely(atomic_dec_return(count) < 0))
                return fail_fn(count);
@@ -61,7 +61,7 @@ __mutex_fastpath_lock_retval(atomic_t *count, fastcall int (*fail_fn)(atomic_t *
  * to return 0 otherwise.
  */
 static inline void
-__mutex_fastpath_unlock(atomic_t *count, fastcall void (*fail_fn)(atomic_t *))
+__mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *))
 {
        smp_mb();
        if (unlikely(atomic_inc_return(count) <= 0))
index 6a7e8c141b536d66a6bc0149ad33c339ad040925..7b9cd2cbfebe527cffbea01df889465b039c91be 100644 (file)
@@ -23,7 +23,7 @@
  * even when the "1" assertion wasn't true.
  */
 static inline void
-__mutex_fastpath_lock(atomic_t *count, fastcall void (*fail_fn)(atomic_t *))
+__mutex_fastpath_lock(atomic_t *count, void (*fail_fn)(atomic_t *))
 {
        if (unlikely(atomic_xchg(count, 0) != 1))
                fail_fn(count);
@@ -42,7 +42,7 @@ __mutex_fastpath_lock(atomic_t *count, fastcall void (*fail_fn)(atomic_t *))
  * or anything the slow path function returns
  */
 static inline int
-__mutex_fastpath_lock_retval(atomic_t *count, fastcall int (*fail_fn)(atomic_t *))
+__mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *))
 {
        if (unlikely(atomic_xchg(count, 0) != 1))
                return fail_fn(count);
@@ -65,7 +65,7 @@ __mutex_fastpath_lock_retval(atomic_t *count, fastcall int (*fail_fn)(atomic_t *
  * to return 0 otherwise.
  */
 static inline void
-__mutex_fastpath_unlock(atomic_t *count, fastcall void (*fail_fn)(atomic_t *))
+__mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *))
 {
        smp_mb();
        if (unlikely(atomic_xchg(count, 1) != 0))
index 33dca30a3c452199537913bcc6e3e1447dfcef5c..7d39ecc92d9430380ccd00d4be4021932b1db8c3 100644 (file)
@@ -61,8 +61,14 @@ static inline int kernel_termios_to_user_termio(struct termio __user *termio,
        return 0;
 }
 
+#ifndef user_termios_to_kernel_termios
 #define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios))
+#endif
+
+#ifndef kernel_termios_to_user_termios
 #define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios))
+#endif
+
 #define user_termios_to_kernel_termios_1(k, u) copy_from_user(k, u, sizeof(struct termios))
 #define kernel_termios_to_user_termios_1(u, k) copy_to_user(u, k, sizeof(struct termios))
 
index aa5d22778235992f08155cf2229d6e12188b15ce..ded780f0a49235d741a9fda178f65fad1f5921c3 100644 (file)
@@ -17,11 +17,4 @@ struct exec
 #define N_DRSIZE(a)    ((a).a_drsize)
 #define N_SYMSIZE(a)   ((a).a_syms)
 
-#ifdef __KERNEL__
-
-#define STACK_TOP      TASK_SIZE
-#define STACK_TOP_MAX  STACK_TOP
-
-#endif
-
 #endif /* __H8300_A_OUT_H__ */
index c25806ed1fb368d2581b00f853bb4d55ade94b9d..04f64f1003792b77c4a6be5a8da51f3f7b2e9b93 100644 (file)
@@ -3,7 +3,7 @@
 
 
 #ifndef HZ
-#define HZ 100
+#define HZ CONFIG_HZ
 #endif
 
 #ifdef __KERNEL__
index 7de94b1fd0e53321a8fe6dcf9f99990319afdbf5..5c553927fc538ae149426cb38f327a213d031141 100644 (file)
@@ -38,14 +38,10 @@ typedef long long   __kernel_loff_t;
 #endif
 
 typedef struct {
-#if defined(__KERNEL__) || defined(__USE_ALL)
        int     val[2];
-#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
-       int     __val[2];
-#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
 } __kernel_fsid_t;
 
-#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
+#if defined(__KERNEL__)
 
 #undef __FD_SET
 #define        __FD_SET(d, set)        ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
@@ -59,6 +55,6 @@ typedef struct {
 #undef __FD_ZERO
 #define __FD_ZERO(fdsetp) (memset (fdsetp, 0, sizeof(*(fd_set *)fdsetp)))
 
-#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+#endif /* defined(__KERNEL__) */
 
 #endif
index 49fc886a623278249302edf3c169c883526e8313..69e8a34eb6d589a4fd2f2e8bc950910a8549290f 100644 (file)
@@ -39,6 +39,11 @@ static inline void wrusp(unsigned long usp) {
  */
 #define TASK_SIZE      (0xFFFFFFFFUL)
 
+#ifdef __KERNEL__
+#define STACK_TOP      TASK_SIZE
+#define STACK_TOP_MAX  STACK_TOP
+#endif
+
 /*
  * This decides where the kernel will search for a free chunk of vm
  * space during mmap's. We won't be using it
index 7293ac1df3ab96446d67624e919288712fa174f3..193dcfb67596b41bd65461d3ff9f4a8a1e8fcd86 100644 (file)
@@ -29,7 +29,4 @@ struct exec {
 #define N_SYMSIZE(x)   0
 #define N_TXTOFF(x)    0
 
-#ifdef __KERNEL__
-#include <asm/ustack.h>
-#endif
 #endif /* _ASM_IA64_A_OUT_H */
index 8a8aa3fd7cd4493dfa6060418bed502cf1bd5227..4999a6c63775b87f4432378c6774e74f2ae2bfb0 100644 (file)
@@ -185,6 +185,7 @@ get_order (unsigned long size)
 #endif
   typedef struct { unsigned long pgd; } pgd_t;
   typedef struct { unsigned long pgprot; } pgprot_t;
+  typedef struct page *pgtable_t;
 
 # define pte_val(x)    ((x).pte)
 # define pmd_val(x)    ((x).pmd)
@@ -206,6 +207,7 @@ get_order (unsigned long size)
     typedef unsigned long pmd_t;
     typedef unsigned long pgd_t;
     typedef unsigned long pgprot_t;
+    typedef struct page *pgtable_t;
 # endif
 
 # define pte_val(x)    (x)
index 556d988123ac1cd5ba351396caf39479401450b0..b9ac1a6fc21694a55e2771e471ab8cc90ab997cf 100644 (file)
@@ -70,10 +70,11 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
 #define __pmd_free_tlb(tlb, pmd)       pmd_free((tlb)->mm, pmd)
 
 static inline void
-pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, struct page *pte)
+pmd_populate(struct mm_struct *mm, pmd_t * pmd_entry, pgtable_t pte)
 {
        pmd_val(*pmd_entry) = page_to_phys(pte);
 }
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 static inline void
 pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmd_entry, pte_t * pte)
@@ -81,11 +82,17 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t * pmd_entry, pte_t * pte)
        pmd_val(*pmd_entry) = __pa(pte);
 }
 
-static inline struct page *pte_alloc_one(struct mm_struct *mm,
-                                        unsigned long addr)
+static inline pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long addr)
 {
-       void *pg = quicklist_alloc(0, GFP_KERNEL, NULL);
-       return pg ? virt_to_page(pg) : NULL;
+       struct page *page;
+       void *pg;
+
+       pg = quicklist_alloc(0, GFP_KERNEL, NULL);
+       if (!pg)
+               return NULL;
+       page = virt_to_page(pg);
+       pgtable_page_ctor(page);
+       return page;
 }
 
 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
@@ -94,8 +101,9 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
        return quicklist_alloc(0, GFP_KERNEL, NULL);
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *pte)
+static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 {
+       pgtable_page_dtor(pte);
        quicklist_free_page(0, NULL, pte);
 }
 
index 6a1b5d42f328c44231f8d0630f41f4b2a12d279f..ab150f5c1666e6c543b1a508cd309b7804f490d0 100644 (file)
@@ -17,11 +17,4 @@ struct exec
 #define N_DRSIZE(a)    ((a).a_drsize)
 #define N_SYMSIZE(a)   ((a).a_syms)
 
-#ifdef __KERNEL__
-
-#define STACK_TOP      TASK_SIZE
-#define STACK_TOP_MAX  STACK_TOP
-
-#endif
-
 #endif /* _ASM_M32R_A_OUT_H */
index 05d43bbbf940b022b140edb86256526ea338c620..8a677f3fca683d658dc41c6306ff6828f9df6390 100644 (file)
@@ -28,6 +28,7 @@ typedef struct { unsigned long pgd; } pgd_t;
 #define PTE_MASK       PAGE_MASK
 
 typedef struct { unsigned long pgprot; } pgprot_t;
+typedef struct page *pgtable_t;
 
 #define pmd_val(x)     ((x).pmd)
 #define pgd_val(x)     ((x).pgd)
index 3e14026e39cdaf2a479d1a09dabaf9c2d6b514b8..94c770196048335767a40f9fd8fd649d11f1effb 100644 (file)
@@ -2,7 +2,7 @@
 #define _ASM_M32R_PARAM_H
 
 #ifdef __KERNEL__
-# define HZ            100             /* Internal kernel timer frequency */
+# define HZ            CONFIG_HZ       /* Internal kernel timer frequency */
 # define USER_HZ       100             /* .. some user interfaces are in "ticks" */
 # define CLOCKS_PER_SEC        (USER_HZ)       /* like times() */
 #endif
index e5921adfad1b6ae2490fb89aa61689f9eaf20b5e..f11a2b909cdbf8ab3bc1a11195b0160173c2a58b 100644 (file)
@@ -9,10 +9,11 @@
        set_pmd(pmd, __pmd(_PAGE_TABLE + __pa(pte)))
 
 static __inline__ void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
-       struct page *pte)
+       pgtable_t pte)
 {
        set_pmd(pmd, __pmd(_PAGE_TABLE + page_to_phys(pte)));
 }
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 /*
  * Allocate and free page tables.
@@ -37,12 +38,12 @@ static __inline__ pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
        return pte;
 }
 
-static __inline__ struct page *pte_alloc_one(struct mm_struct *mm,
+static __inline__ pgtable_t pte_alloc_one(struct mm_struct *mm,
        unsigned long address)
 {
        struct page *pte = alloc_page(GFP_KERNEL|__GFP_ZERO);
 
-
+       pgtable_page_ctor(pte);
        return pte;
 }
 
@@ -51,8 +52,9 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        free_page((unsigned long)pte);
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *pte)
+static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 {
+       pgtable_page_dtor(pte);
        __free_page(pte);
 }
 
index 1caac65d208f244b327f9ea612562e5ebccc6c4b..b309c58586377421e6def20f4dc5c240c69c55af 100644 (file)
@@ -39,14 +39,10 @@ typedef long long   __kernel_loff_t;
 #endif
 
 typedef struct {
-#if defined(__KERNEL__) || defined(__USE_ALL)
        int     val[2];
-#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
-       int     __val[2];
-#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
 } __kernel_fsid_t;
 
-#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
+#if defined(__KERNEL__)
 
 #undef __FD_SET
 static __inline__ void __FD_SET(unsigned long __fd, __kernel_fd_set *__fdsetp)
@@ -117,6 +113,6 @@ static __inline__ void __FD_ZERO(__kernel_fd_set *__p)
        }
 }
 
-#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+#endif /* defined(__KERNEL__) */
 
 #endif  /* _ASM_M32R_POSIX_TYPES_H */
index 32755bf136de83891063e6f672be1dc1e66be259..1a997fc148a2f8d3afbb426db84564413b296973 100644 (file)
@@ -60,6 +60,11 @@ extern struct cpuinfo_m32r cpu_data[];
 #define TASK_SIZE  (0x00400000UL)
 #endif
 
+#ifdef __KERNEL__
+#define STACK_TOP      TASK_SIZE
+#define STACK_TOP_MAX  STACK_TOP
+#endif
+
 /* This decides where the kernel will search for a free chunk of vm
  * space during mmap's.
  */
diff --git a/include/asm-m68k/a.out-core.h b/include/asm-m68k/a.out-core.h
new file mode 100644 (file)
index 0000000..f6bfc1d
--- /dev/null
@@ -0,0 +1,67 @@
+/* a.out coredump register dumper
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_A_OUT_CORE_H
+#define _ASM_A_OUT_CORE_H
+
+#ifdef __KERNEL__
+
+#include <linux/user.h>
+#include <linux/elfcore.h>
+
+/*
+ * fill in the user structure for an a.out core dump
+ */
+static inline void aout_dump_thread(struct pt_regs *regs, struct user *dump)
+{
+       struct switch_stack *sw;
+
+/* changed the size calculations - should hopefully work better. lbt */
+       dump->magic = CMAGIC;
+       dump->start_code = 0;
+       dump->start_stack = rdusp() & ~(PAGE_SIZE - 1);
+       dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
+       dump->u_dsize = ((unsigned long) (current->mm->brk +
+                                         (PAGE_SIZE-1))) >> PAGE_SHIFT;
+       dump->u_dsize -= dump->u_tsize;
+       dump->u_ssize = 0;
+
+       if (dump->start_stack < TASK_SIZE)
+               dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
+
+       dump->u_ar0 = offsetof(struct user, regs);
+       sw = ((struct switch_stack *)regs) - 1;
+       dump->regs.d1 = regs->d1;
+       dump->regs.d2 = regs->d2;
+       dump->regs.d3 = regs->d3;
+       dump->regs.d4 = regs->d4;
+       dump->regs.d5 = regs->d5;
+       dump->regs.d6 = sw->d6;
+       dump->regs.d7 = sw->d7;
+       dump->regs.a0 = regs->a0;
+       dump->regs.a1 = regs->a1;
+       dump->regs.a2 = regs->a2;
+       dump->regs.a3 = sw->a3;
+       dump->regs.a4 = sw->a4;
+       dump->regs.a5 = sw->a5;
+       dump->regs.a6 = sw->a6;
+       dump->regs.d0 = regs->d0;
+       dump->regs.orig_d0 = regs->orig_d0;
+       dump->regs.stkadj = regs->stkadj;
+       dump->regs.sr = regs->sr;
+       dump->regs.pc = regs->pc;
+       dump->regs.fmtvec = (regs->format << 12) | regs->vector;
+       /* dump floating point stuff */
+       dump->u_fpvalid = dump_fpu (regs, &dump->m68kfp);
+}
+
+#endif /* __KERNEL__ */
+#endif /* _ASM_A_OUT_CORE_H */
index 6fc86a221a94702a8367e5952a7ab59805f14977..3885fe43432a79089d22527d1617927aa6ecc5e8 100644 (file)
@@ -17,11 +17,4 @@ struct exec
 #define N_DRSIZE(a)    ((a).a_drsize)
 #define N_SYMSIZE(a)   ((a).a_syms)
 
-#ifdef __KERNEL__
-
-#define STACK_TOP      TASK_SIZE
-#define STACK_TOP_MAX  STACK_TOP
-
-#endif
-
 #endif /* __M68K_A_OUT_H__ */
index 500ec9b8b1892aebb41ec8833fa982abf5acaf9f..d08bf6261df88889f0e39091f8356580920208bb 100644 (file)
@@ -7,7 +7,6 @@
 extern pmd_t *get_pointer_table(void);
 extern int free_pointer_table(pmd_t *);
 
-
 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long address)
 {
        pte_t *pte;
@@ -28,7 +27,7 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        free_page((unsigned long) pte);
 }
 
-static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
+static inline pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
 {
        struct page *page = alloc_pages(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO, 0);
        pte_t *pte;
@@ -43,19 +42,21 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long add
                nocache_page(pte);
        }
        kunmap(pte);
-
+       pgtable_page_ctor(page);
        return page;
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *page)
+static inline void pte_free(struct mm_struct *mm, pgtable_t page)
 {
+       pgtable_page_dtor(page);
        cache_page(kmap(page));
        kunmap(page);
        __free_page(page);
 }
 
-static inline void __pte_free_tlb(struct mmu_gather *tlb, struct page *page)
+static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t page)
 {
+       pgtable_page_dtor(page);
        cache_page(kmap(page));
        kunmap(page);
        __free_page(page);
@@ -94,10 +95,11 @@ static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *
        pmd_set(pmd, pte);
 }
 
-static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *page)
+static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t page)
 {
        pmd_set(pmd, page_address(page));
 }
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
 {
index 3f29e2a03a43bd203d34c633ed2c5a5749b35b4e..880c2cbff8a681cc8619ef50f5b26cd5fd202433 100644 (file)
@@ -91,6 +91,7 @@ typedef struct { unsigned long pte; } pte_t;
 typedef struct { unsigned long pmd[16]; } pmd_t;
 typedef struct { unsigned long pgd; } pgd_t;
 typedef struct { unsigned long pgprot; } pgprot_t;
+typedef struct page *pgtable_t;
 
 #define pte_val(x)     ((x).pte)
 #define pmd_val(x)     ((&x)->pmd[0])
index 60f409d81658193e36e1f077d1e643a1e390b191..536a27888358d59a15e6f4342513a3fb04ebb3be 100644 (file)
@@ -2,7 +2,7 @@
 #define _M68K_PARAM_H
 
 #ifdef __KERNEL__
-# define HZ            100             /* Internal kernel timer frequency */
+# define HZ            CONFIG_HZ       /* Internal kernel timer frequency */
 # define USER_HZ       100             /* .. some user interfaces are in "ticks" */
 # define CLOCKS_PER_SEC        (USER_HZ)       /* like times() */
 #endif
index fa166ee30286fdca3cb2488a8b8586527fe0d455..63cdcc142d9357bc93c7210945d9080616176944 100644 (file)
@@ -39,14 +39,10 @@ typedef long long   __kernel_loff_t;
 #endif
 
 typedef struct {
-#if defined(__KERNEL__) || defined(__USE_ALL)
        int     val[2];
-#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
-       int     __val[2];
-#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
 } __kernel_fsid_t;
 
-#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
+#if defined(__KERNEL__)
 
 #undef __FD_SET
 #define        __FD_SET(d, set)        ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d))
@@ -60,6 +56,6 @@ typedef struct {
 #undef __FD_ZERO
 #define __FD_ZERO(fdsetp) (memset (fdsetp, 0, sizeof(*(fd_set *)fdsetp)))
 
-#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+#endif /* defined(__KERNEL__) */
 
 #endif
index 4453ec379c5dabd2e723f8b8105ca6066e2b6f14..1f61ef53f0e0b068f2962f0a22d0f1dd4899f964 100644 (file)
@@ -41,6 +41,11 @@ static inline void wrusp(unsigned long usp)
 #define TASK_SIZE      (0x0E000000UL)
 #endif
 
+#ifdef __KERNEL__
+#define STACK_TOP      TASK_SIZE
+#define STACK_TOP_MAX  STACK_TOP
+#endif
+
 /* This decides where the kernel will search for a free chunk of vm
  * space during mmap's.
  */
index a5a91e72714b0b9e715bba4ee0a008a777187057..d4c83f14381652402d35f4b3cb5fb5967f97a6de 100644 (file)
@@ -26,12 +26,17 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
         free_page((unsigned long) pte);
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *page)
+static inline void pte_free(struct mm_struct *mm, pgtable_t page)
 {
+       pgtable_page_dtor(page);
         __free_page(page);
 }
 
-#define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
+#define __pte_free_tlb(tlb,pte)                                \
+do {                                                   \
+       pgtable_page_dtor(pte);                         \
+       tlb_remove_page((tlb), pte);                    \
+} while (0)
 
 static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
                                          unsigned long address)
@@ -45,8 +50,8 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
        return (pte_t *) (page);
 }
 
-static inline struct page *pte_alloc_one(struct mm_struct *mm,
-                                        unsigned long address)
+static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
+                                       unsigned long address)
 {
         struct page *page = alloc_pages(GFP_KERNEL|__GFP_REPEAT, 0);
 
@@ -54,6 +59,7 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm,
                return NULL;
 
        clear_highpage(page);
+       pgtable_page_ctor(page);
        return page;
 
 }
@@ -63,10 +69,11 @@ static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *
        pmd_val(*pmd) = __pa((unsigned long)pte);
 }
 
-static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *page)
+static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t page)
 {
        pmd_val(*pmd) = __pa((unsigned long)page_address(page));
 }
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 /*
  * allocating and freeing a pmd is trivial: the 1-entry pmd is
index 4c9904d6512ed6e278184fa56375d072239f0f07..96c45101832491ecbb7e0cabdb5b49d49f5fa5d2 100644 (file)
@@ -1,13 +1,7 @@
 #ifndef _M68KNOMMU_PARAM_H
 #define _M68KNOMMU_PARAM_H
 
-
-#if defined(CONFIG_CLEOPATRA)
-#define        HZ 1000
-#endif
-#ifndef HZ
-#define        HZ 100
-#endif
+#define HZ CONFIG_HZ
 
 #ifdef __KERNEL__
 #define        USER_HZ         HZ
index bf55a5b34bef7458c3a69a7b7a05398dec7e8986..cad8371422abd8e083e8446482c6137b08e42ec8 100644 (file)
@@ -32,17 +32,4 @@ struct exec
 #define N_DRSIZE(a)    ((a).a_drsize)
 #define N_SYMSIZE(a)   ((a).a_syms)
 
-#ifdef __KERNEL__
-
-#ifdef CONFIG_32BIT
-#define STACK_TOP      TASK_SIZE
-#endif
-#ifdef CONFIG_64BIT
-#define STACK_TOP      \
-      (test_thread_flag(TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE)
-#endif
-#define STACK_TOP_MAX  TASK_SIZE
-
-#endif
-
 #endif /* _ASM_A_OUT_H */
index 635aa44d2290dfcb85b056015341ff0580d232b3..8735aa0b89630987f9d7341efa88e13a4bf9eb7a 100644 (file)
@@ -90,6 +90,7 @@ typedef struct { unsigned long pte; } pte_t;
 #define pte_val(x)     ((x).pte)
 #define __pte(x)       ((pte_t) { (x) } )
 #endif
+typedef struct page *pgtable_t;
 
 /*
  * For 3-level pagetables we defines these ourselves, for 2-level the
index c4efeced8396da58d0bad7b56fc4f2da50d2f753..1275831dda29b65ae90d2046f781a747cb4a3df0 100644 (file)
@@ -20,10 +20,11 @@ static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
 }
 
 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
-       struct page *pte)
+       pgtable_t pte)
 {
        set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
 }
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 /*
  * Initialize a new pmd table with invalid pointers.
@@ -79,9 +80,10 @@ static inline struct page *pte_alloc_one(struct mm_struct *mm,
        struct page *pte;
 
        pte = alloc_pages(GFP_KERNEL | __GFP_REPEAT, PTE_ORDER);
-       if (pte)
+       if (pte) {
                clear_highpage(pte);
-
+               pgtable_page_ctor(pte);
+       }
        return pte;
 }
 
@@ -90,12 +92,17 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        free_pages((unsigned long)pte, PTE_ORDER);
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *pte)
+static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 {
+       pgtable_page_dtor(pte);
        __free_pages(pte, PTE_ORDER);
 }
 
-#define __pte_free_tlb(tlb, pte)       tlb_remove_page((tlb), (pte))
+#define __pte_free_tlb(tlb,pte)                                \
+do {                                                   \
+       pgtable_page_dtor(pte);                         \
+       tlb_remove_page((tlb), pte);                    \
+} while (0)
 
 #ifdef CONFIG_32BIT
 
index c2e8a0070daf71ce2e626759ba8f76ebc0044916..c200102c858614d7f11ce7afd95c4ccaea6eeb03 100644 (file)
@@ -69,7 +69,7 @@ typedef struct {
 #endif
 } __kernel_fsid_t;
 
-#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
+#if defined(__KERNEL__)
 
 #undef __FD_SET
 static __inline__ void __FD_SET(unsigned long __fd, __kernel_fd_set *__fdsetp)
@@ -139,6 +139,6 @@ static __inline__ void __FD_ZERO(__kernel_fd_set *__p)
        }
 }
 
-#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+#endif /* defined(__KERNEL__) */
 
 #endif /* _ASM_POSIX_TYPES_H */
index 36f42de594094b73f5b60ffc2dc0f09ebdf20b1c..58cbac5a64e4472dd45e17c3cef7426b86dbf243 100644 (file)
@@ -39,6 +39,7 @@ extern unsigned int vced_count, vcei_count;
  * so don't change it unless you know what you are doing.
  */
 #define TASK_SIZE      0x7fff8000UL
+#define STACK_TOP      TASK_SIZE
 
 /*
  * This decides where the kernel will search for a free chunk of vm
@@ -57,6 +58,8 @@ extern unsigned int vced_count, vcei_count;
  */
 #define TASK_SIZE32    0x7fff8000UL
 #define TASK_SIZE      0x10000000000UL
+#define STACK_TOP      \
+      (test_thread_flag(TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE)
 
 /*
  * This decides where the kernel will search for a free chunk of vm
@@ -69,6 +72,10 @@ extern unsigned int vced_count, vcei_count;
        (test_tsk_thread_flag(tsk, TIF_32BIT_ADDR) ? TASK_SIZE32 : TASK_SIZE)
 #endif
 
+#ifdef __KERNEL__
+#define STACK_TOP_MAX  TASK_SIZE
+#endif
+
 #define NUM_FPU_REGS   32
 
 typedef __u64 fpureg_t;
diff --git a/include/asm-mn10300/.gitignore b/include/asm-mn10300/.gitignore
new file mode 100644 (file)
index 0000000..0f87ba7
--- /dev/null
@@ -0,0 +1,2 @@
+proc
+unit
diff --git a/include/asm-mn10300/Kbuild b/include/asm-mn10300/Kbuild
new file mode 100644 (file)
index 0000000..79384c5
--- /dev/null
@@ -0,0 +1,5 @@
+include include/asm-generic/Kbuild.asm
+
+unifdef-y += termios.h
+unifdef-y += ptrace.h
+unifdef-y += page.h
diff --git a/include/asm-mn10300/atomic.h b/include/asm-mn10300/atomic.h
new file mode 100644 (file)
index 0000000..27c9690
--- /dev/null
@@ -0,0 +1,166 @@
+/* MN10300 Atomic counter operations
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_ATOMIC_H
+#define _ASM_ATOMIC_H
+
+#ifdef CONFIG_SMP
+#error not SMP safe
+#endif
+
+/*
+ * Atomic operations that C can't guarantee us.  Useful for
+ * resource counting etc..
+ */
+
+/*
+ * Make sure gcc doesn't try to be clever and move things around
+ * on us. We need to use _exactly_ the address the user gave us,
+ * not some alias that contains the same information.
+ */
+typedef struct {
+       int     counter;
+} atomic_t;
+
+#define ATOMIC_INIT(i) { (i) }
+
+#ifdef __KERNEL__
+
+/**
+ * atomic_read - read atomic variable
+ * @v: pointer of type atomic_t
+ *
+ * Atomically reads the value of @v.  Note that the guaranteed
+ * useful range of an atomic_t is only 24 bits.
+ */
+#define atomic_read(v) ((v)->counter)
+
+/**
+ * atomic_set - set atomic variable
+ * @v: pointer of type atomic_t
+ * @i: required value
+ *
+ * Atomically sets the value of @v to @i.  Note that the guaranteed
+ * useful range of an atomic_t is only 24 bits.
+ */
+#define atomic_set(v, i) (((v)->counter) = (i))
+
+#include <asm/system.h>
+
+/**
+ * atomic_add_return - add integer to atomic variable
+ * @i: integer value to add
+ * @v: pointer of type atomic_t
+ *
+ * Atomically adds @i to @v and returns the result
+ * Note that the guaranteed useful range of an atomic_t is only 24 bits.
+ */
+static inline int atomic_add_return(int i, atomic_t *v)
+{
+       unsigned long flags;
+       int temp;
+
+       local_irq_save(flags);
+       temp = v->counter;
+       temp += i;
+       v->counter = temp;
+       local_irq_restore(flags);
+
+       return temp;
+}
+
+/**
+ * atomic_sub_return - subtract integer from atomic variable
+ * @i: integer value to subtract
+ * @v: pointer of type atomic_t
+ *
+ * Atomically subtracts @i from @v and returns the result
+ * Note that the guaranteed useful range of an atomic_t is only 24 bits.
+ */
+static inline int atomic_sub_return(int i, atomic_t *v)
+{
+       unsigned long flags;
+       int temp;
+
+       local_irq_save(flags);
+       temp = v->counter;
+       temp -= i;
+       v->counter = temp;
+       local_irq_restore(flags);
+
+       return temp;
+}
+
+static inline int atomic_add_negative(int i, atomic_t *v)
+{
+       return atomic_add_return(i, v) < 0;
+}
+
+static inline void atomic_add(int i, atomic_t *v)
+{
+       atomic_add_return(i, v);
+}
+
+static inline void atomic_sub(int i, atomic_t *v)
+{
+       atomic_sub_return(i, v);
+}
+
+static inline void atomic_inc(atomic_t *v)
+{
+       atomic_add_return(1, v);
+}
+
+static inline void atomic_dec(atomic_t *v)
+{
+       atomic_sub_return(1, v);
+}
+
+#define atomic_dec_return(v)           atomic_sub_return(1, (v))
+#define atomic_inc_return(v)           atomic_add_return(1, (v))
+
+#define atomic_sub_and_test(i, v)      (atomic_sub_return((i), (v)) == 0)
+#define atomic_dec_and_test(v)         (atomic_sub_return(1, (v)) == 0)
+#define atomic_inc_and_test(v)         (atomic_add_return(1, (v)) == 0)
+
+#define atomic_add_unless(v, a, u)                             \
+({                                                             \
+       int c, old;                                             \
+       c = atomic_read(v);                                     \
+       while (c != (u) && (old = atomic_cmpxchg((v), c, c + (a))) != c) \
+               c = old;                                        \
+       c != (u);                                               \
+})
+
+#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
+
+static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
+{
+       unsigned long flags;
+
+       mask = ~mask;
+       local_irq_save(flags);
+       *addr &= mask;
+       local_irq_restore(flags);
+}
+
+#define atomic_xchg(ptr, v)            (xchg(&(ptr)->counter, (v)))
+#define atomic_cmpxchg(v, old, new)    (cmpxchg(&((v)->counter), (old), (new)))
+
+/* Atomic operations are already serializing on MN10300??? */
+#define smp_mb__before_atomic_dec()    barrier()
+#define smp_mb__after_atomic_dec()     barrier()
+#define smp_mb__before_atomic_inc()    barrier()
+#define smp_mb__after_atomic_inc()     barrier()
+
+#include <asm-generic/atomic.h>
+
+#endif /* __KERNEL__ */
+#endif /* _ASM_ATOMIC_H */
diff --git a/include/asm-mn10300/auxvec.h b/include/asm-mn10300/auxvec.h
new file mode 100644 (file)
index 0000000..4fdb60b
--- /dev/null
@@ -0,0 +1,4 @@
+#ifndef _ASM_AUXVEC_H
+#define _ASM_AUXVEC_H
+
+#endif
diff --git a/include/asm-mn10300/bitops.h b/include/asm-mn10300/bitops.h
new file mode 100644 (file)
index 0000000..cc6d40c
--- /dev/null
@@ -0,0 +1,229 @@
+/* MN10300 bit operations
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ *
+ * These have to be done with inline assembly: that way the bit-setting
+ * is guaranteed to be atomic. All bit operations return 0 if the bit
+ * was cleared before the operation and != 0 if it was not.
+ *
+ * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
+ */
+#ifndef __ASM_BITOPS_H
+#define __ASM_BITOPS_H
+
+#include <asm/cpu-regs.h>
+
+#define smp_mb__before_clear_bit()     barrier()
+#define smp_mb__after_clear_bit()      barrier()
+
+/*
+ * set bit
+ */
+#define __set_bit(nr, addr)                                    \
+({                                                             \
+       volatile unsigned char *_a = (unsigned char *)(addr);   \
+       const unsigned shift = (nr) & 7;                        \
+       _a += (nr) >> 3;                                        \
+                                                               \
+       asm volatile("bset %2,(%1) # set_bit reg"               \
+                    : "=m"(*_a)                                \
+                    : "a"(_a), "d"(1 << shift),  "m"(*_a)      \
+                    : "memory", "cc");                         \
+})
+
+#define set_bit(nr, addr) __set_bit((nr), (addr))
+
+/*
+ * clear bit
+ */
+#define ___clear_bit(nr, addr)                                 \
+({                                                             \
+       volatile unsigned char *_a = (unsigned char *)(addr);   \
+       const unsigned shift = (nr) & 7;                        \
+       _a += (nr) >> 3;                                        \
+                                                               \
+       asm volatile("bclr %2,(%1) # clear_bit reg"             \
+                    : "=m"(*_a)                                \
+                    : "a"(_a), "d"(1 << shift), "m"(*_a)       \
+                    : "memory", "cc");                         \
+})
+
+#define clear_bit(nr, addr) ___clear_bit((nr), (addr))
+
+
+static inline void __clear_bit(int nr, volatile void *addr)
+{
+       unsigned int *a = (unsigned int *) addr;
+       int mask;
+
+       a += nr >> 5;
+       mask = 1 << (nr & 0x1f);
+       *a &= ~mask;
+}
+
+/*
+ * test bit
+ */
+static inline int test_bit(int nr, const volatile void *addr)
+{
+       return 1UL & (((const unsigned int *) addr)[nr >> 5] >> (nr & 31));
+}
+
+/*
+ * change bit
+ */
+static inline void __change_bit(int nr, volatile void *addr)
+{
+       int     mask;
+       unsigned int *a = (unsigned int *) addr;
+
+       a += nr >> 5;
+       mask = 1 << (nr & 0x1f);
+       *a ^= mask;
+}
+
+extern void change_bit(int nr, volatile void *addr);
+
+/*
+ * test and set bit
+ */
+#define __test_and_set_bit(nr,addr)                            \
+({                                                             \
+       volatile unsigned char *_a = (unsigned char *)(addr);   \
+       const unsigned shift = (nr) & 7;                        \
+       unsigned epsw;                                          \
+       _a += (nr) >> 3;                                        \
+                                                               \
+       asm volatile("bset %3,(%2) # test_set_bit reg\n"        \
+                    "mov epsw,%1"                              \
+                    : "=m"(*_a), "=d"(epsw)                    \
+                    : "a"(_a), "d"(1 << shift), "m"(*_a)       \
+                    : "memory", "cc");                         \
+                                                               \
+       !(epsw & EPSW_FLAG_Z);                                  \
+})
+
+#define test_and_set_bit(nr, addr) __test_and_set_bit((nr), (addr))
+
+/*
+ * test and clear bit
+ */
+#define __test_and_clear_bit(nr, addr)                         \
+({                                                             \
+        volatile unsigned char *_a = (unsigned char *)(addr);  \
+       const unsigned shift = (nr) & 7;                        \
+       unsigned epsw;                                          \
+       _a += (nr) >> 3;                                        \
+                                                               \
+       asm volatile("bclr %3,(%2) # test_clear_bit reg\n"      \
+                    "mov epsw,%1"                              \
+                    : "=m"(*_a), "=d"(epsw)                    \
+                    : "a"(_a), "d"(1 << shift), "m"(*_a)       \
+                    : "memory", "cc");                         \
+                                                               \
+       !(epsw & EPSW_FLAG_Z);                                  \
+})
+
+#define test_and_clear_bit(nr, addr) __test_and_clear_bit((nr), (addr))
+
+/*
+ * test and change bit
+ */
+static inline int __test_and_change_bit(int nr, volatile void *addr)
+{
+       int     mask, retval;
+       unsigned int *a = (unsigned int *)addr;
+
+       a += nr >> 5;
+       mask = 1 << (nr & 0x1f);
+       retval = (mask & *a) != 0;
+       *a ^= mask;
+
+       return retval;
+}
+
+extern int test_and_change_bit(int nr, volatile void *addr);
+
+#include <asm-generic/bitops/lock.h>
+
+#ifdef __KERNEL__
+
+/**
+ * __ffs - find first bit set
+ * @x: the word to search
+ *
+ * - return 31..0 to indicate bit 31..0 most least significant bit set
+ * - if no bits are set in x, the result is undefined
+ */
+static inline __attribute__((const))
+unsigned long __ffs(unsigned long x)
+{
+       int bit;
+       asm("bsch %2,%0" : "=r"(bit) : "0"(0), "r"(x & -x));
+       return bit;
+}
+
+/*
+ * special slimline version of fls() for calculating ilog2_u32()
+ * - note: no protection against n == 0
+ */
+static inline __attribute__((const))
+int __ilog2_u32(u32 n)
+{
+       int bit;
+       asm("bsch %2,%0" : "=r"(bit) : "0"(0), "r"(n));
+       return bit;
+}
+
+/**
+ * fls - find last bit set
+ * @x: the word to search
+ *
+ * This is defined the same way as ffs:
+ * - return 32..1 to indicate bit 31..0 most significant bit set
+ * - return 0 to indicate no bits set
+ */
+static inline __attribute__((const))
+int fls(int x)
+{
+       return (x != 0) ? __ilog2_u32(x) + 1 : 0;
+}
+
+/**
+ * ffs - find first bit set
+ * @x: the word to search
+ *
+ * - return 32..1 to indicate bit 31..0 most least significant bit set
+ * - return 0 to indicate no bits set
+ */
+static inline __attribute__((const))
+int ffs(int x)
+{
+       /* Note: (x & -x) gives us a mask that is the least significant
+        * (rightmost) 1-bit of the value in x.
+        */
+       return fls(x & -x);
+}
+
+#include <asm-generic/bitops/ffz.h>
+#include <asm-generic/bitops/fls64.h>
+#include <asm-generic/bitops/find.h>
+#include <asm-generic/bitops/sched.h>
+#include <asm-generic/bitops/hweight.h>
+
+#define ext2_set_bit_atomic(lock, nr, addr) \
+       test_and_set_bit((nr) ^ 0x18, (addr))
+#define ext2_clear_bit_atomic(lock, nr, addr) \
+       test_and_clear_bit((nr) ^ 0x18, (addr))
+
+#include <asm-generic/bitops/ext2-non-atomic.h>
+#include <asm-generic/bitops/minix-le.h>
+
+#endif /* __KERNEL__ */
+#endif /* __ASM_BITOPS_H */
diff --git a/include/asm-mn10300/bug.h b/include/asm-mn10300/bug.h
new file mode 100644 (file)
index 0000000..4fcf338
--- /dev/null
@@ -0,0 +1,35 @@
+/* MN10300 Kernel bug reporting
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_BUG_H
+#define _ASM_BUG_H
+
+/*
+ * Tell the user there is some problem.
+ */
+#define _debug_bug_trap()                                      \
+do {                                                           \
+       asm volatile(                                           \
+               "       syscall 15                      \n"     \
+               "0:                                     \n"     \
+               "       .section __bug_table,\"a\"      \n"     \
+               "       .long 0b,%0,%1                  \n"     \
+               "       .previous                       \n"     \
+               :                                               \
+               : "i"(__FILE__), "i"(__LINE__)                  \
+               );                                              \
+} while (0)
+
+#define BUG() _debug_bug_trap()
+
+#define HAVE_ARCH_BUG
+#include <asm-generic/bug.h>
+
+#endif /* _ASM_BUG_H */
diff --git a/include/asm-mn10300/bugs.h b/include/asm-mn10300/bugs.h
new file mode 100644 (file)
index 0000000..31c8bc5
--- /dev/null
@@ -0,0 +1,20 @@
+/* MN10300 Checks for architecture-dependent bugs
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_BUGS_H
+#define _ASM_BUGS_H
+
+#include <asm/processor.h>
+
+static inline void __init check_bugs(void)
+{
+}
+
+#endif /* _ASM_BUGS_H */
diff --git a/include/asm-mn10300/busctl-regs.h b/include/asm-mn10300/busctl-regs.h
new file mode 100644 (file)
index 0000000..1632aef
--- /dev/null
@@ -0,0 +1,151 @@
+/* AM33v2 on-board bus controller registers
+ *
+ * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_BUSCTL_REGS_H
+#define _ASM_BUSCTL_REGS_H
+
+#include <asm/cpu-regs.h>
+
+#ifdef __KERNEL__
+
+/* bus controller registers */
+#define BCCR                   __SYSREG(0xc0002000, u32)       /* bus controller control reg */
+#define BCCR_B0AD              0x00000003      /* block 0 (80000000-83ffffff) bus allocation */
+#define BCCR_B1AD              0x0000000c      /* block 1 (84000000-87ffffff) bus allocation */
+#define BCCR_B2AD              0x00000030      /* block 2 (88000000-8bffffff) bus allocation */
+#define BCCR_B3AD              0x000000c0      /* block 3 (8c000000-8fffffff) bus allocation */
+#define BCCR_B4AD              0x00000300      /* block 4 (90000000-93ffffff) bus allocation */
+#define BCCR_B5AD              0x00000c00      /* block 5 (94000000-97ffffff) bus allocation */
+#define BCCR_B6AD              0x00003000      /* block 6 (98000000-9bffffff) bus allocation */
+#define BCCR_B7AD              0x0000c000      /* block 7 (9c000000-9fffffff) bus allocation */
+#define BCCR_BxAD_EXBUS                0x0             /* - direct to system bus controller */
+#define BCCR_BxAD_OPEXBUS      0x1             /* - direct to memory bus controller */
+#define BCCR_BxAD_OCMBUS       0x2             /* - direct to on chip memory */
+#define BCCR_API               0x00070000      /* bus arbitration priority */
+#define BCCR_API_DMACICD       0x00000000      /* - DMA > CI > CD */
+#define BCCR_API_DMACDCI       0x00010000      /* - DMA > CD > CI */
+#define BCCR_API_CICDDMA       0x00020000      /* - CI > CD > DMA */
+#define BCCR_API_CDCIDMA       0x00030000      /* - CD > CI > DMA */
+#define BCCR_API_ROUNDROBIN    0x00040000      /* - round robin */
+#define BCCR_BEPRI_DMACICD     0x00c00000      /* bus error address priority */
+#define BCCR_BEPRI_DMACDCI     0x00000000      /* - DMA > CI > CD */
+#define BCCR_BEPRI_CICDDMA     0x00400000      /* - DMA > CD > CI */
+#define BCCR_BEPRI_CDCIDMA     0x00800000      /* - CI > CD > DMA */
+#define BCCR_BEPRI             0x00c00000      /* - CD > CI > DMA */
+#define BCCR_TMON              0x03000000      /* timeout value settings */
+#define BCCR_TMON_16IOCLK      0x00000000      /* - 16 IOCLK cycles */
+#define BCCR_TMON_256IOCLK     0x01000000      /* - 256 IOCLK cycles */
+#define BCCR_TMON_4096IOCLK    0x02000000      /* - 4096 IOCLK cycles */
+#define BCCR_TMON_65536IOCLK   0x03000000      /* - 65536 IOCLK cycles */
+#define BCCR_TMOE              0x10000000      /* timeout detection enable */
+
+#define BCBERR                 __SYSREG(0xc0002010, u32)       /* bus error source reg */
+#define BCBERR_BESB            0x0000001f      /* erroneous access destination space */
+#define BCBERR_BESB_MON                0x00000001      /* - monitor space */
+#define BCBERR_BESB_IO         0x00000002      /* - IO bus */
+#define BCBERR_BESB_EX         0x00000004      /* - EX bus */
+#define BCBERR_BESB_OPEX       0x00000008      /* - OpEX bus */
+#define BCBERR_BESB_OCM                0x00000010      /* - on chip memory */
+#define BCBERR_BERW            0x00000100      /* type of access */
+#define BCBERR_BERW_WRITE      0x00000000      /* - write */
+#define BCBERR_BERW_READ       0x00000100      /* - read */
+#define BCBERR_BESD            0x00000200      /* error detector */
+#define BCBERR_BESD_BCU                0x00000000      /* - BCU detected error */
+#define BCBERR_BESD_SLAVE_BUS  0x00000200      /* - slave bus detected error */
+#define BCBERR_BEBST           0x00000400      /* type of access */
+#define BCBERR_BEBST_SINGLE    0x00000000      /* - single */
+#define BCBERR_BEBST_BURST     0x00000400      /* - burst */
+#define BCBERR_BEME            0x00000800      /* multiple bus error flag */
+#define BCBERR_BEMR            0x00007000      /* master bus that caused the error */
+#define BCBERR_BEMR_NOERROR    0x00000000      /* - no error */
+#define BCBERR_BEMR_CI         0x00001000      /* - CPU instruction fetch bus caused error */
+#define BCBERR_BEMR_CD         0x00002000      /* - CPU data bus caused error */
+#define BCBERR_BEMR_DMA                0x00004000      /* - DMA bus caused error */
+
+#define BCBEAR                 __SYSREGC(0xc0002020, u32)      /* bus error address reg */
+
+/* system bus controller registers */
+#define SBBASE(X)              __SYSREG(0xd8c00100 + (X) * 0x10, u32)  /* SBC base addr regs */
+#define SBBASE_BE              0x00000001      /* bank enable */
+#define SBBASE_BAM             0x0000fffe      /* bank address mask [31:17] */
+#define SBBASE_BBA             0xfffe0000      /* bank base address [31:17] */
+
+#define SBCNTRL0(X)            __SYSREG(0xd8c00200 + (X) * 0x10, u32)  /* SBC bank ctrl0 regs */
+#define SBCNTRL0_WEH           0x00000f00      /* write enable hold */
+#define SBCNTRL0_REH           0x0000f000      /* read enable hold */
+#define SBCNTRL0_RWH           0x000f0000      /* SRW signal hold */
+#define SBCNTRL0_CSH           0x00f00000      /* chip select hold */
+#define SBCNTRL0_DAH           0x0f000000      /* data hold */
+#define SBCNTRL0_ADH           0xf0000000      /* address hold */
+
+#define SBCNTRL1(X)            __SYSREG(0xd8c00204 + (X) * 0x10, u32)  /* SBC bank ctrl1 regs */
+#define SBCNTRL1_WED           0x00000f00      /* write enable delay */
+#define SBCNTRL1_RED           0x0000f000      /* read enable delay */
+#define SBCNTRL1_RWD           0x000f0000      /* SRW signal delay */
+#define SBCNTRL1_ASW           0x00f00000      /* address strobe width */
+#define SBCNTRL1_CSD           0x0f000000      /* chip select delay */
+#define SBCNTRL1_ASD           0xf0000000      /* address strobe delay */
+
+#define SBCNTRL2(X)            __SYSREG(0xd8c00208 + (X) * 0x10, u32)  /* SBC bank ctrl2 regs */
+#define SBCNTRL2_WC            0x000000ff      /* wait count */
+#define SBCNTRL2_BWC           0x00000f00      /* burst wait count */
+#define SBCNTRL2_WM            0x01000000      /* wait mode setting */
+#define SBCNTRL2_WM_FIXEDWAIT  0x00000000      /* - fixed wait access */
+#define SBCNTRL2_WM_HANDSHAKE  0x01000000      /* - handshake access */
+#define SBCNTRL2_BM            0x02000000      /* bus synchronisation mode */
+#define SBCNTRL2_BM_SYNC       0x00000000      /* - synchronous mode */
+#define SBCNTRL2_BM_ASYNC      0x02000000      /* - asynchronous mode */
+#define SBCNTRL2_BW            0x04000000      /* bus width */
+#define SBCNTRL2_BW_32         0x00000000      /* - 32 bits */
+#define SBCNTRL2_BW_16         0x04000000      /* - 16 bits */
+#define SBCNTRL2_RWINV         0x08000000      /* R/W signal invert polarity */
+#define SBCNTRL2_RWINV_NORM    0x00000000      /* - normal (read high) */
+#define SBCNTRL2_RWINV_INV     0x08000000      /* - inverted (read low) */
+#define SBCNTRL2_BT            0x70000000      /* bus type setting */
+#define SBCNTRL2_BT_SRAM       0x00000000      /* - SRAM interface */
+#define SBCNTRL2_BT_ADMUX      0x00000000      /* - addr/data multiplexed interface */
+#define SBCNTRL2_BT_BROM       0x00000000      /* - burst ROM interface */
+#define SBCNTRL2_BTSE          0x80000000      /* burst enable */
+
+/* memory bus controller */
+#define SDBASE(X)              __SYSREG(0xda000008 + (X) * 0x4, u32)   /* MBC base addr regs */
+#define SDBASE_CE              0x00000001      /* chip enable */
+#define SDBASE_CBAM            0x0000fff0      /* chip base address mask [31:20] */
+#define SDBASE_CBAM_SHIFT      16
+#define SDBASE_CBA             0xfff00000      /* chip base address [31:20] */
+
+#define SDRAMBUS               __SYSREG(0xda000000, u32)       /* bus mode control reg */
+#define SDRAMBUS_REFEN         0x00000004      /* refresh enable */
+#define SDRAMBUS_TRC           0x00000018      /* refresh command delay time */
+#define SDRAMBUS_BSTPT         0x00000020      /* burst stop command enable */
+#define SDRAMBUS_PONSEQ                0x00000040      /* power on sequence */
+#define SDRAMBUS_SELFREQ       0x00000080      /* self-refresh mode request */
+#define SDRAMBUS_SELFON                0x00000100      /* self-refresh mode on */
+#define SDRAMBUS_SIZE          0x00030000      /* SDRAM size */
+#define SDRAMBUS_SIZE_64Mbit   0x00010000      /* 64Mbit SDRAM (x16) */
+#define SDRAMBUS_SIZE_128Mbit  0x00020000      /* 128Mbit SDRAM (x16) */
+#define SDRAMBUS_SIZE_256Mbit  0x00030000      /* 256Mbit SDRAM (x16) */
+#define SDRAMBUS_TRASWAIT      0x000c0000      /* row address precharge command cycle number */
+#define SDRAMBUS_REFNUM                0x00300000      /* refresh command number */
+#define SDRAMBUS_BSTWAIT       0x00c00000      /* burst stop command cycle */
+#define SDRAMBUS_SETWAIT       0x03000000      /* mode register setting command cycle */
+#define SDRAMBUS_PREWAIT       0x0c000000      /* precharge command cycle */
+#define SDRAMBUS_RASLATE       0x30000000      /* RAS latency */
+#define SDRAMBUS_CASLATE       0xc0000000      /* CAS latency */
+
+#define SDREFCNT               __SYSREG(0xda000004, u32)       /* refresh period reg */
+#define SDREFCNT_PERI          0x00000fff      /* refresh period */
+
+#define SDSHDW                 __SYSREG(0xda000010, u32)       /* test reg */
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_BUSCTL_REGS_H */
diff --git a/include/asm-mn10300/byteorder.h b/include/asm-mn10300/byteorder.h
new file mode 100644 (file)
index 0000000..3c993cc
--- /dev/null
@@ -0,0 +1,46 @@
+/* MN10300 Byte-order primitive construction
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_BYTEORDER_H
+#define _ASM_BYTEORDER_H
+
+#include <asm/types.h>
+
+#ifdef __GNUC__
+
+static inline __attribute__((const))
+__u32 ___arch__swab32(__u32 x)
+{
+       __u32 ret;
+       asm("swap %1,%0" : "=r" (ret) : "r" (x));
+       return ret;
+}
+
+static inline __attribute__((const))
+__u16 ___arch__swab16(__u16 x)
+{
+       __u16 ret;
+       asm("swaph %1,%0" : "=r" (ret) : "r" (x));
+       return ret;
+}
+
+#define __arch__swab32(x) ___arch__swab32(x)
+#define __arch__swab16(x) ___arch__swab16(x)
+
+#if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
+#  define __BYTEORDER_HAS_U64__
+#  define __SWAB_64_THRU_32__
+#endif
+
+#endif /* __GNUC__ */
+
+#include <linux/byteorder/little_endian.h>
+
+#endif /* _ASM_BYTEORDER_H */
diff --git a/include/asm-mn10300/cache.h b/include/asm-mn10300/cache.h
new file mode 100644 (file)
index 0000000..9e01122
--- /dev/null
@@ -0,0 +1,54 @@
+/* MN10300 cache management registers
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_CACHE_H
+#define _ASM_CACHE_H
+
+#include <asm/cpu-regs.h>
+#include <asm/proc/cache.h>
+
+#ifndef __ASSEMBLY__
+#define L1_CACHE_DISPARITY     (L1_CACHE_NENTRIES * L1_CACHE_BYTES)
+#else
+#define L1_CACHE_DISPARITY     L1_CACHE_NENTRIES * L1_CACHE_BYTES
+#endif
+
+/* data cache purge registers
+ * - read from the register to unconditionally purge that cache line
+ * - write address & 0xffffff00 to conditionally purge that cache line
+ *   - clear LSB to request invalidation as well
+ */
+#define DCACHE_PURGE(WAY, ENTRY) \
+       __SYSREG(0xc8400000 + (WAY) * L1_CACHE_WAYDISP + \
+                (ENTRY) * L1_CACHE_BYTES, u32)
+
+#define DCACHE_PURGE_WAY0(ENTRY) \
+       __SYSREG(0xc8400000 + 0 * L1_CACHE_WAYDISP + (ENTRY) * L1_CACHE_BYTES, u32)
+#define DCACHE_PURGE_WAY1(ENTRY) \
+       __SYSREG(0xc8400000 + 1 * L1_CACHE_WAYDISP + (ENTRY) * L1_CACHE_BYTES, u32)
+#define DCACHE_PURGE_WAY2(ENTRY) \
+       __SYSREG(0xc8400000 + 2 * L1_CACHE_WAYDISP + (ENTRY) * L1_CACHE_BYTES, u32)
+#define DCACHE_PURGE_WAY3(ENTRY) \
+       __SYSREG(0xc8400000 + 3 * L1_CACHE_WAYDISP + (ENTRY) * L1_CACHE_BYTES, u32)
+
+/* instruction cache access registers */
+#define ICACHE_DATA(WAY, ENTRY, OFF) \
+       __SYSREG(0xc8000000 + (WAY) * L1_CACHE_WAYDISP + (ENTRY) * 0x10 + (OFF) * 4, u32)
+#define ICACHE_TAG(WAY, ENTRY)  \
+       __SYSREG(0xc8100000 + (WAY) * L1_CACHE_WAYDISP + (ENTRY) * 0x10, u32)
+
+/* instruction cache access registers */
+#define DCACHE_DATA(WAY, ENTRY, OFF) \
+       __SYSREG(0xc8200000 + (WAY) * L1_CACHE_WAYDISP + (ENTRY) * 0x10 + (OFF) * 4, u32)
+#define DCACHE_TAG(WAY, ENTRY)  \
+       __SYSREG(0xc8300000 + (WAY) * L1_CACHE_WAYDISP + (ENTRY) * 0x10, u32)
+
+#endif /* _ASM_CACHE_H */
diff --git a/include/asm-mn10300/cacheflush.h b/include/asm-mn10300/cacheflush.h
new file mode 100644 (file)
index 0000000..2db746a
--- /dev/null
@@ -0,0 +1,116 @@
+/* MN10300 Cache flushing
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_CACHEFLUSH_H
+#define _ASM_CACHEFLUSH_H
+
+#ifndef __ASSEMBLY__
+
+/* Keep includes the same across arches.  */
+#include <linux/mm.h>
+
+/*
+ * virtually-indexed cache managment (our cache is physically indexed)
+ */
+#define flush_cache_all()                      do {} while (0)
+#define flush_cache_mm(mm)                     do {} while (0)
+#define flush_cache_dup_mm(mm)                 do {} while (0)
+#define flush_cache_range(mm, start, end)      do {} while (0)
+#define flush_cache_page(vma, vmaddr, pfn)     do {} while (0)
+#define flush_cache_vmap(start, end)           do {} while (0)
+#define flush_cache_vunmap(start, end)         do {} while (0)
+#define flush_dcache_page(page)                        do {} while (0)
+#define flush_dcache_mmap_lock(mapping)                do {} while (0)
+#define flush_dcache_mmap_unlock(mapping)      do {} while (0)
+
+/*
+ * physically-indexed cache managment
+ */
+#ifndef CONFIG_MN10300_CACHE_DISABLED
+
+extern void flush_icache_range(unsigned long start, unsigned long end);
+extern void flush_icache_page(struct vm_area_struct *vma, struct page *pg);
+
+#else
+
+#define flush_icache_range(start, end)         do {} while (0)
+#define flush_icache_page(vma, pg)             do {} while (0)
+
+#endif
+
+#define flush_icache_user_range(vma, pg, adr, len) \
+       flush_icache_range(adr, adr + len)
+
+#define copy_to_user_page(vma, page, vaddr, dst, src, len) \
+       do {                                    \
+               memcpy(dst, src, len);          \
+               flush_icache_page(vma, page);   \
+       } while (0)
+
+#define copy_from_user_page(vma, page, vaddr, dst, src, len) \
+       memcpy(dst, src, len)
+
+/*
+ * primitive routines
+ */
+#ifndef CONFIG_MN10300_CACHE_DISABLED
+extern void mn10300_icache_inv(void);
+extern void mn10300_dcache_inv(void);
+extern void mn10300_dcache_inv_page(unsigned start);
+extern void mn10300_dcache_inv_range(unsigned start, unsigned end);
+extern void mn10300_dcache_inv_range2(unsigned start, unsigned size);
+#ifdef CONFIG_MN10300_CACHE_WBACK
+extern void mn10300_dcache_flush(void);
+extern void mn10300_dcache_flush_page(unsigned start);
+extern void mn10300_dcache_flush_range(unsigned start, unsigned end);
+extern void mn10300_dcache_flush_range2(unsigned start, unsigned size);
+extern void mn10300_dcache_flush_inv(void);
+extern void mn10300_dcache_flush_inv_page(unsigned start);
+extern void mn10300_dcache_flush_inv_range(unsigned start, unsigned end);
+extern void mn10300_dcache_flush_inv_range2(unsigned start, unsigned size);
+#else
+#define mn10300_dcache_flush()                         do {} while (0)
+#define mn10300_dcache_flush_page(start)               do {} while (0)
+#define mn10300_dcache_flush_range(start, end)         do {} while (0)
+#define mn10300_dcache_flush_range2(start, size)       do {} while (0)
+#define mn10300_dcache_flush_inv()                     mn10300_dcache_inv()
+#define mn10300_dcache_flush_inv_page(start) \
+       mn10300_dcache_inv_page((start))
+#define mn10300_dcache_flush_inv_range(start, end) \
+       mn10300_dcache_inv_range((start), (end))
+#define mn10300_dcache_flush_inv_range2(start, size) \
+       mn10300_dcache_inv_range2((start), (size))
+#endif /* CONFIG_MN10300_CACHE_WBACK */
+#else
+#define mn10300_icache_inv()                           do {} while (0)
+#define mn10300_dcache_inv()                           do {} while (0)
+#define mn10300_dcache_inv_page(start)                 do {} while (0)
+#define mn10300_dcache_inv_range(start, end)           do {} while (0)
+#define mn10300_dcache_inv_range2(start, size)         do {} while (0)
+#define mn10300_dcache_flush()                         do {} while (0)
+#define mn10300_dcache_flush_inv_page(start)           do {} while (0)
+#define mn10300_dcache_flush_inv()                     do {} while (0)
+#define mn10300_dcache_flush_inv_range(start, end)     do {} while (0)
+#define mn10300_dcache_flush_inv_range2(start, size)   do {} while (0)
+#define mn10300_dcache_flush_page(start)               do {} while (0)
+#define mn10300_dcache_flush_range(start, end)         do {} while (0)
+#define mn10300_dcache_flush_range2(start, size)       do {} while (0)
+#endif /* CONFIG_MN10300_CACHE_DISABLED */
+
+/*
+ * internal debugging function
+ */
+#ifdef CONFIG_DEBUG_PAGEALLOC
+extern void kernel_map_pages(struct page *page, int numpages, int enable);
+#endif
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _ASM_CACHEFLUSH_H */
diff --git a/include/asm-mn10300/checksum.h b/include/asm-mn10300/checksum.h
new file mode 100644 (file)
index 0000000..9fb2a8d
--- /dev/null
@@ -0,0 +1,86 @@
+/* MN10300 Optimised checksumming code
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_CHECKSUM_H
+#define _ASM_CHECKSUM_H
+
+extern __wsum csum_partial(const void *buff, int len, __wsum sum);
+extern __wsum csum_partial_copy_nocheck(const void *src, void *dst,
+                                       int len, __wsum sum);
+extern __wsum csum_partial_copy_from_user(const void *src, void *dst,
+                                         int len, __wsum sum,
+                                         int *err_ptr);
+extern __sum16 ip_fast_csum(const void *iph, unsigned int ihl);
+extern __wsum csum_partial(const void *buff, int len, __wsum sum);
+extern __sum16 ip_compute_csum(const void *buff, int len);
+
+#define csum_partial_copy_fromuser csum_partial_copy
+extern __wsum csum_partial_copy(const void *src, void *dst, int len,
+                               __wsum sum);
+
+static inline __sum16 csum_fold(__wsum sum)
+{
+       asm(
+               "       add     %1,%0           \n"
+               "       addc    0xffff,%0       \n"
+               : "=r" (sum)
+               : "r" (sum << 16), "0" (sum & 0xffff0000)
+               : "cc"
+           );
+       return (~sum) >> 16;
+}
+
+static inline __wsum csum_tcpudp_nofold(unsigned long saddr,
+                                       unsigned long daddr,
+                                       unsigned short len,
+                                       unsigned short proto,
+                                       __wsum sum)
+{
+       __wsum tmp;
+
+       tmp = (__wsum) ntohs(len) << 16;
+       tmp += (__wsum) proto << 8;
+
+       asm(
+               "       add     %1,%0           \n"
+               "       addc    %2,%0           \n"
+               "       addc    %3,%0           \n"
+               "       addc    0,%0            \n"
+               : "=r" (sum)
+               : "r" (daddr), "r"(saddr), "r"(tmp), "0"(sum)
+               : "cc"
+           );
+       return sum;
+}
+
+/*
+ * computes the checksum of the TCP/UDP pseudo-header
+ * returns a 16-bit checksum, already complemented
+ */
+static inline __sum16 csum_tcpudp_magic(unsigned long saddr,
+                                       unsigned long daddr,
+                                       unsigned short len,
+                                       unsigned short proto,
+                                       __wsum sum)
+{
+       return csum_fold(csum_tcpudp_nofold(saddr, daddr, len, proto, sum));
+}
+
+#undef _HAVE_ARCH_IPV6_CSUM
+
+/*
+ *     Copy and checksum to user
+ */
+#define HAVE_CSUM_COPY_USER
+extern __wsum csum_and_copy_to_user(const void *src, void *dst, int len,
+                                   __wsum sum, int *err_ptr);
+
+
+#endif /* _ASM_CHECKSUM_H */
diff --git a/include/asm-mn10300/cpu-regs.h b/include/asm-mn10300/cpu-regs.h
new file mode 100644 (file)
index 0000000..757e9b5
--- /dev/null
@@ -0,0 +1,290 @@
+/* MN10300 Core system registers
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_CPU_REGS_H
+#define _ASM_CPU_REGS_H
+
+#ifndef __ASSEMBLY__
+#include <linux/types.h>
+#endif
+
+#ifdef CONFIG_MN10300_CPU_AM33V2
+/* we tell the compiler to pretend to be AM33 so that it doesn't try and use
+ * the FP regs, but tell the assembler that we're actually allowed AM33v2
+ * instructions */
+#ifndef __ASSEMBLY__
+asm(" .am33_2\n");
+#else
+.am33_2
+#endif
+#endif
+
+#ifdef __KERNEL__
+
+#ifndef __ASSEMBLY__
+#define __SYSREG(ADDR, TYPE) (*(volatile TYPE *)(ADDR))
+#define __SYSREGC(ADDR, TYPE) (*(const volatile TYPE *)(ADDR))
+#else
+#define __SYSREG(ADDR, TYPE) ADDR
+#define __SYSREGC(ADDR, TYPE) ADDR
+#endif
+
+/* CPU registers */
+#define EPSW_FLAG_Z            0x00000001      /* zero flag */
+#define EPSW_FLAG_N            0x00000002      /* negative flag */
+#define EPSW_FLAG_C            0x00000004      /* carry flag */
+#define EPSW_FLAG_V            0x00000008      /* overflow flag */
+#define EPSW_IM                        0x00000700      /* interrupt mode */
+#define EPSW_IM_0              0x00000000      /* interrupt mode 0 */
+#define EPSW_IM_1              0x00000100      /* interrupt mode 1 */
+#define EPSW_IM_2              0x00000200      /* interrupt mode 2 */
+#define EPSW_IM_3              0x00000300      /* interrupt mode 3 */
+#define EPSW_IM_4              0x00000400      /* interrupt mode 4 */
+#define EPSW_IM_5              0x00000500      /* interrupt mode 5 */
+#define EPSW_IM_6              0x00000600      /* interrupt mode 6 */
+#define EPSW_IM_7              0x00000700      /* interrupt mode 7 */
+#define EPSW_IE                        0x00000800      /* interrupt enable */
+#define EPSW_S                 0x00003000      /* software auxilliary bits */
+#define EPSW_T                 0x00008000      /* trace enable */
+#define EPSW_nSL               0x00010000      /* not supervisor level */
+#define EPSW_NMID              0x00020000      /* nonmaskable interrupt disable */
+#define EPSW_nAR               0x00040000      /* register bank control */
+#define EPSW_ML                        0x00080000      /* monitor level */
+#define EPSW_FE                        0x00100000      /* FPU enable */
+
+/* FPU registers */
+#define FPCR_EF_I              0x00000001      /* inexact result FPU exception flag */
+#define FPCR_EF_U              0x00000002      /* underflow FPU exception flag */
+#define FPCR_EF_O              0x00000004      /* overflow FPU exception flag */
+#define FPCR_EF_Z              0x00000008      /* zero divide FPU exception flag */
+#define FPCR_EF_V              0x00000010      /* invalid operand FPU exception flag */
+#define FPCR_EE_I              0x00000020      /* inexact result FPU exception enable */
+#define FPCR_EE_U              0x00000040      /* underflow FPU exception enable */
+#define FPCR_EE_O              0x00000080      /* overflow FPU exception enable */
+#define FPCR_EE_Z              0x00000100      /* zero divide FPU exception enable */
+#define FPCR_EE_V              0x00000200      /* invalid operand FPU exception enable */
+#define FPCR_EC_I              0x00000400      /* inexact result FPU exception cause */
+#define FPCR_EC_U              0x00000800      /* underflow FPU exception cause */
+#define FPCR_EC_O              0x00001000      /* overflow FPU exception cause */
+#define FPCR_EC_Z              0x00002000      /* zero divide FPU exception cause */
+#define FPCR_EC_V              0x00004000      /* invalid operand FPU exception cause */
+#define FPCR_RM                        0x00030000      /* rounding mode */
+#define FPCR_RM_NEAREST                0x00000000      /* - round to nearest value */
+#define FPCR_FCC_U             0x00040000      /* FPU unordered condition code */
+#define FPCR_FCC_E             0x00080000      /* FPU equal condition code */
+#define FPCR_FCC_G             0x00100000      /* FPU greater than condition code */
+#define FPCR_FCC_L             0x00200000      /* FPU less than condition code */
+#define FPCR_INIT              0x00000000      /* no exceptions, rounding to nearest */
+
+/* CPU control registers */
+#define CPUP                   __SYSREG(0xc0000020, u16)       /* CPU pipeline register */
+#define CPUP_DWBD              0x0020          /* write buffer disable flag */
+#define CPUP_IPFD              0x0040          /* instruction prefetch disable flag */
+#define CPUP_EXM               0x0080          /* exception operation mode */
+#define CPUP_EXM_AM33V1                0x0000          /* - AM33 v1 exception mode */
+#define CPUP_EXM_AM33V2                0x0080          /* - AM33 v2 exception mode */
+
+#define CPUM                   __SYSREG(0xc0000040, u16)       /* CPU mode register */
+#define CPUM_SLEEP             0x0004          /* set to enter sleep state */
+#define CPUM_HALT              0x0008          /* set to enter halt state */
+#define CPUM_STOP              0x0010          /* set to enter stop state */
+
+#define CPUREV                 __SYSREGC(0xc0000050, u32)      /* CPU revision register */
+#define CPUREV_TYPE            0x0000000f      /* CPU type */
+#define CPUREV_TYPE_S          0
+#define CPUREV_TYPE_AM33V1     0x00000000      /* - AM33 V1 core, AM33/1.00 arch */
+#define CPUREV_TYPE_AM33V2     0x00000001      /* - AM33 V2 core, AM33/2.00 arch */
+#define CPUREV_TYPE_AM34V1     0x00000002      /* - AM34 V1 core, AM33/2.00 arch */
+#define CPUREV_REVISION                0x000000f0      /* CPU revision */
+#define CPUREV_REVISION_S      4
+#define CPUREV_ICWAY           0x00000f00      /* number of instruction cache ways */
+#define CPUREV_ICWAY_S         8
+#define CPUREV_ICSIZE          0x0000f000      /* instruction cache way size */
+#define CPUREV_ICSIZE_S                12
+#define CPUREV_DCWAY           0x000f0000      /* number of data cache ways */
+#define CPUREV_DCWAY_S         16
+#define CPUREV_DCSIZE          0x00f00000      /* data cache way size */
+#define CPUREV_DCSIZE_S                20
+#define CPUREV_FPUTYPE         0x0f000000      /* FPU core type */
+#define CPUREV_FPUTYPE_NONE    0x00000000      /* - no FPU core implemented */
+#define CPUREV_OCDCTG          0xf0000000      /* on-chip debug function category */
+
+#define DCR                    __SYSREG(0xc0000030, u16)       /* Debug control register */
+
+/* interrupt/exception control registers */
+#define IVAR0                  __SYSREG(0xc0000000, u16)       /* interrupt vector 0 */
+#define IVAR1                  __SYSREG(0xc0000004, u16)       /* interrupt vector 1 */
+#define IVAR2                  __SYSREG(0xc0000008, u16)       /* interrupt vector 2 */
+#define IVAR3                  __SYSREG(0xc000000c, u16)       /* interrupt vector 3 */
+#define IVAR4                  __SYSREG(0xc0000010, u16)       /* interrupt vector 4 */
+#define IVAR5                  __SYSREG(0xc0000014, u16)       /* interrupt vector 5 */
+#define IVAR6                  __SYSREG(0xc0000018, u16)       /* interrupt vector 6 */
+
+#define TBR                    __SYSREG(0xc0000024, u32)       /* Trap table base */
+#define TBR_TB                 0xff000000      /* table base address bits 31-24 */
+#define TBR_INT_CODE           0x00ffffff      /* interrupt code */
+
+#define DEAR                   __SYSREG(0xc0000038, u32)       /* Data access exception address */
+
+#define sISR                   __SYSREG(0xc0000044, u32)       /* Supervisor interrupt status */
+#define        sISR_IRQICE             0x00000001      /* ICE interrupt */
+#define        sISR_ISTEP              0x00000002      /* single step interrupt */
+#define        sISR_MISSA              0x00000004      /* memory access address misalignment fault */
+#define        sISR_UNIMP              0x00000008      /* unimplemented instruction execution fault */
+#define        sISR_PIEXE              0x00000010      /* program interrupt */
+#define        sISR_MEMERR             0x00000020      /* illegal memory access fault */
+#define        sISR_IBREAK             0x00000040      /* instraction break interrupt */
+#define        sISR_DBSRL              0x00000080      /* debug serial interrupt */
+#define        sISR_PERIDB             0x00000100      /* peripheral debug interrupt */
+#define        sISR_EXUNIMP            0x00000200      /* unimplemented ex-instruction execution fault */
+#define        sISR_OBREAK             0x00000400      /* operand break interrupt */
+#define        sISR_PRIV               0x00000800      /* privileged instruction execution fault */
+#define        sISR_BUSERR             0x00001000      /* bus error fault */
+#define        sISR_DBLFT              0x00002000      /* double fault */
+#define        sISR_DBG                0x00008000      /* debug reserved interrupt */
+#define sISR_ITMISS            0x00010000      /* instruction TLB miss */
+#define sISR_DTMISS            0x00020000      /* data TLB miss */
+#define sISR_ITEX              0x00040000      /* instruction TLB access exception */
+#define sISR_DTEX              0x00080000      /* data TLB access exception */
+#define sISR_ILGIA             0x00100000      /* illegal instruction access exception */
+#define sISR_ILGDA             0x00200000      /* illegal data access exception */
+#define sISR_IOIA              0x00400000      /* internal I/O space instruction access excep */
+#define sISR_PRIVA             0x00800000      /* privileged space instruction access excep */
+#define sISR_PRIDA             0x01000000      /* privileged space data access excep */
+#define sISR_DISA              0x02000000      /* data space instruction access excep */
+#define sISR_SYSC              0x04000000      /* system call instruction excep */
+#define sISR_FPUD              0x08000000      /* FPU disabled excep */
+#define sISR_FPUUI             0x10000000      /* FPU unimplemented instruction excep */
+#define sISR_FPUOP             0x20000000      /* FPU operation excep */
+#define sISR_NE                        0x80000000      /* multiple synchronous exceptions excep */
+
+/* cache control registers */
+#define CHCTR                  __SYSREG(0xc0000070, u16)       /* cache control */
+#define CHCTR_ICEN             0x0001          /* instruction cache enable */
+#define CHCTR_DCEN             0x0002          /* data cache enable */
+#define CHCTR_ICBUSY           0x0004          /* instruction cache busy */
+#define CHCTR_DCBUSY           0x0008          /* data cache busy */
+#define CHCTR_ICINV            0x0010          /* instruction cache invalidate */
+#define CHCTR_DCINV            0x0020          /* data cache invalidate */
+#define CHCTR_DCWTMD           0x0040          /* data cache writing mode */
+#define CHCTR_DCWTMD_WRBACK    0x0000          /* - write back mode */
+#define CHCTR_DCWTMD_WRTHROUGH 0x0040          /* - write through mode */
+#define CHCTR_DCALMD           0x0080          /* data cache allocation mode */
+#define CHCTR_ICWMD            0x0f00          /* instruction cache way mode */
+#define CHCTR_DCWMD            0xf000          /* data cache way mode */
+
+/* MMU control registers */
+#define MMUCTR                 __SYSREG(0xc0000090, u32)       /* MMU control register */
+#define MMUCTR_IRP             0x0000003f      /* instruction TLB replace pointer */
+#define MMUCTR_ITE             0x00000040      /* instruction TLB enable */
+#define MMUCTR_IIV             0x00000080      /* instruction TLB invalidate */
+#define MMUCTR_ITL             0x00000700      /* instruction TLB lock pointer */
+#define MMUCTR_ITL_NOLOCK      0x00000000      /* - no lock */
+#define MMUCTR_ITL_LOCK0       0x00000100      /* - entry 0 locked */
+#define MMUCTR_ITL_LOCK0_1     0x00000200      /* - entry 0-1 locked */
+#define MMUCTR_ITL_LOCK0_3     0x00000300      /* - entry 0-3 locked */
+#define MMUCTR_ITL_LOCK0_7     0x00000400      /* - entry 0-7 locked */
+#define MMUCTR_ITL_LOCK0_15    0x00000500      /* - entry 0-15 locked */
+#define MMUCTR_CE              0x00008000      /* cacheable bit enable */
+#define MMUCTR_DRP             0x003f0000      /* data TLB replace pointer */
+#define MMUCTR_DTE             0x00400000      /* data TLB enable */
+#define MMUCTR_DIV             0x00800000      /* data TLB invalidate */
+#define MMUCTR_DTL             0x07000000      /* data TLB lock pointer */
+#define MMUCTR_DTL_NOLOCK      0x00000000      /* - no lock */
+#define MMUCTR_DTL_LOCK0       0x01000000      /* - entry 0 locked */
+#define MMUCTR_DTL_LOCK0_1     0x02000000      /* - entry 0-1 locked */
+#define MMUCTR_DTL_LOCK0_3     0x03000000      /* - entry 0-3 locked */
+#define MMUCTR_DTL_LOCK0_7     0x04000000      /* - entry 0-7 locked */
+#define MMUCTR_DTL_LOCK0_15    0x05000000      /* - entry 0-15 locked */
+
+#define PIDR                   __SYSREG(0xc0000094, u16)       /* PID register */
+#define PIDR_PID               0x00ff          /* process identifier */
+
+#define PTBR                   __SYSREG(0xc0000098, unsigned long) /* Page table base register */
+
+#define IPTEL                  __SYSREG(0xc00000a0, u32)       /* instruction TLB entry */
+#define DPTEL                  __SYSREG(0xc00000b0, u32)       /* data TLB entry */
+#define xPTEL_V                        0x00000001      /* TLB entry valid */
+#define xPTEL_UNUSED1          0x00000002      /* unused bit */
+#define xPTEL_UNUSED2          0x00000004      /* unused bit */
+#define xPTEL_C                        0x00000008      /* cached if set */
+#define xPTEL_PV               0x00000010      /* page valid */
+#define xPTEL_D                        0x00000020      /* dirty */
+#define xPTEL_PR               0x000001c0      /* page protection */
+#define xPTEL_PR_ROK           0x00000000      /* - R/O kernel */
+#define xPTEL_PR_RWK           0x00000100      /* - R/W kernel */
+#define xPTEL_PR_ROK_ROU       0x00000080      /* - R/O kernel and R/O user */
+#define xPTEL_PR_RWK_ROU       0x00000180      /* - R/W kernel and R/O user */
+#define xPTEL_PR_RWK_RWU       0x000001c0      /* - R/W kernel and R/W user */
+#define xPTEL_G                        0x00000200      /* global (use PID if 0) */
+#define xPTEL_PS               0x00000c00      /* page size */
+#define xPTEL_PS_4Kb           0x00000000      /* - 4Kb page */
+#define xPTEL_PS_128Kb         0x00000400      /* - 128Kb page */
+#define xPTEL_PS_1Kb           0x00000800      /* - 1Kb page */
+#define xPTEL_PS_4Mb           0x00000c00      /* - 4Mb page */
+#define xPTEL_PPN              0xfffff006      /* physical page number */
+
+#define xPTEL_V_BIT            0       /* bit numbers corresponding to above masks */
+#define xPTEL_UNUSED1_BIT      1
+#define xPTEL_UNUSED2_BIT      2
+#define xPTEL_C_BIT            3
+#define xPTEL_PV_BIT           4
+#define xPTEL_D_BIT            5
+#define xPTEL_G_BIT            9
+
+#define IPTEU                  __SYSREG(0xc00000a4, u32)       /* instruction TLB virtual addr */
+#define DPTEU                  __SYSREG(0xc00000b4, u32)       /* data TLB virtual addr */
+#define xPTEU_VPN              0xfffffc00      /* virtual page number */
+#define xPTEU_PID              0x000000ff      /* process identifier to which applicable */
+
+#define IPTEL2                 __SYSREG(0xc00000a8, u32)       /* instruction TLB entry */
+#define DPTEL2                 __SYSREG(0xc00000b8, u32)       /* data TLB entry */
+#define xPTEL2_V               0x00000001      /* TLB entry valid */
+#define xPTEL2_C               0x00000002      /* cacheable */
+#define xPTEL2_PV              0x00000004      /* page valid */
+#define xPTEL2_D               0x00000008      /* dirty */
+#define xPTEL2_PR              0x00000070      /* page protection */
+#define xPTEL2_PR_ROK          0x00000000      /* - R/O kernel */
+#define xPTEL2_PR_RWK          0x00000040      /* - R/W kernel */
+#define xPTEL2_PR_ROK_ROU      0x00000020      /* - R/O kernel and R/O user */
+#define xPTEL2_PR_RWK_ROU      0x00000060      /* - R/W kernel and R/O user */
+#define xPTEL2_PR_RWK_RWU      0x00000070      /* - R/W kernel and R/W user */
+#define xPTEL2_G               0x00000080      /* global (use PID if 0) */
+#define xPTEL2_PS              0x00000300      /* page size */
+#define xPTEL2_PS_4Kb          0x00000000      /* - 4Kb page */
+#define xPTEL2_PS_128Kb                0x00000100      /* - 128Kb page */
+#define xPTEL2_PS_1Kb          0x00000200      /* - 1Kb page */
+#define xPTEL2_PS_4Mb          0x00000300      /* - 4Mb page */
+#define xPTEL2_PPN             0xfffffc00      /* physical page number */
+
+#define MMUFCR                 __SYSREGC(0xc000009c, u32)      /* MMU exception cause */
+#define MMUFCR_IFC             __SYSREGC(0xc000009c, u16)      /* MMU instruction excep cause */
+#define MMUFCR_DFC             __SYSREGC(0xc000009e, u16)      /* MMU data exception cause */
+#define MMUFCR_xFC_TLBMISS     0x0001          /* TLB miss flag */
+#define MMUFCR_xFC_INITWR      0x0002          /* initial write excep flag */
+#define MMUFCR_xFC_PGINVAL     0x0004          /* page invalid excep flag */
+#define MMUFCR_xFC_PROTVIOL    0x0008          /* protection violation excep flag */
+#define MMUFCR_xFC_ACCESS      0x0010          /* access level flag */
+#define MMUFCR_xFC_ACCESS_USR  0x0000          /* - user mode */
+#define MMUFCR_xFC_ACCESS_SR   0x0010          /* - supervisor mode */
+#define MMUFCR_xFC_TYPE                0x0020          /* access type flag */
+#define MMUFCR_xFC_TYPE_READ   0x0000          /* - read */
+#define MMUFCR_xFC_TYPE_WRITE  0x0020          /* - write */
+#define MMUFCR_xFC_PR          0x01c0          /* page protection flag */
+#define MMUFCR_xFC_PR_ROK      0x0000          /* - R/O kernel */
+#define MMUFCR_xFC_PR_RWK      0x0100          /* - R/W kernel */
+#define MMUFCR_xFC_PR_ROK_ROU  0x0080          /* - R/O kernel and R/O user */
+#define MMUFCR_xFC_PR_RWK_ROU  0x0180          /* - R/W kernel and R/O user */
+#define MMUFCR_xFC_PR_RWK_RWU  0x01c0          /* - R/W kernel and R/W user */
+#define MMUFCR_xFC_ILLADDR     0x0200          /* illegal address excep flag */
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_CPU_REGS_H */
diff --git a/include/asm-mn10300/cputime.h b/include/asm-mn10300/cputime.h
new file mode 100644 (file)
index 0000000..6d68ad7
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/cputime.h>
diff --git a/include/asm-mn10300/current.h b/include/asm-mn10300/current.h
new file mode 100644 (file)
index 0000000..ca6027d
--- /dev/null
@@ -0,0 +1,37 @@
+/* MN10300 Current task structure accessor
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_CURRENT_H
+#define _ASM_CURRENT_H
+
+#include <linux/thread_info.h>
+
+/*
+ * dedicate E2 to keeping the current task pointer
+ */
+#ifdef CONFIG_MN10300_CURRENT_IN_E2
+
+register struct task_struct *const current asm("e2") __attribute__((used));
+
+#define get_current() current
+
+extern struct task_struct *__current;
+
+#else
+static inline __attribute__((const))
+struct task_struct *get_current(void)
+{
+       return current_thread_info()->task;
+}
+
+#define current get_current()
+#endif
+
+#endif /* _ASM_CURRENT_H */
diff --git a/include/asm-mn10300/delay.h b/include/asm-mn10300/delay.h
new file mode 100644 (file)
index 0000000..34517b3
--- /dev/null
@@ -0,0 +1,19 @@
+/* MN10300 Uninterruptible delay routines
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_DELAY_H
+#define _ASM_DELAY_H
+
+extern void __udelay(unsigned long usecs);
+extern void __delay(unsigned long loops);
+
+#define udelay(n) __udelay(n)
+
+#endif /* _ASM_DELAY_H */
diff --git a/include/asm-mn10300/device.h b/include/asm-mn10300/device.h
new file mode 100644 (file)
index 0000000..f0a4c25
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/device.h>
diff --git a/include/asm-mn10300/div64.h b/include/asm-mn10300/div64.h
new file mode 100644 (file)
index 0000000..bf9c515
--- /dev/null
@@ -0,0 +1,103 @@
+/* MN10300 64-bit division
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_DIV64
+#define _ASM_DIV64
+
+#include <linux/types.h>
+
+extern void ____unhandled_size_in_do_div___(void);
+
+/*
+ * divide n by base, leaving the result in n and returning the remainder
+ * - we can do this quite efficiently on the MN10300 by cascading the divides
+ *   through the MDR register
+ */
+#define do_div(n, base)                                                        \
+({                                                                     \
+       unsigned __rem = 0;                                             \
+       if (sizeof(n) <= 4) {                                           \
+               asm("mov        %1,mdr  \n"                             \
+                   "divu       %2,%0   \n"                             \
+                   "mov        mdr,%1  \n"                             \
+                   : "+r"(n), "=d"(__rem)                              \
+                   : "r"(base), "1"(__rem)                             \
+                   : "cc"                                              \
+                   );                                                  \
+       } else if (sizeof(n) <= 8) {                                    \
+               union {                                                 \
+                       unsigned long long l;                           \
+                       u32 w[2];                                       \
+               } __quot;                                               \
+               __quot.l = n;                                           \
+               asm("mov        %0,mdr  \n"     /* MDR = 0 */           \
+                   "divu       %3,%1   \n"                             \
+                   /* __quot.MSL = __div.MSL / base, */                \
+                   /* MDR = MDR:__div.MSL % base */                    \
+                   "divu       %3,%2   \n"                             \
+                   /* __quot.LSL = MDR:__div.LSL / base, */            \
+                   /* MDR = MDR:__div.LSL % base */                    \
+                   "mov        mdr,%0  \n"                             \
+                   : "=d"(__rem), "=r"(__quot.w[1]), "=r"(__quot.w[0]) \
+                   : "r"(base), "0"(__rem), "1"(__quot.w[1]),          \
+                     "2"(__quot.w[0])                                  \
+                   : "cc"                                              \
+                   );                                                  \
+               n = __quot.l;                                           \
+       } else {                                                        \
+               ____unhandled_size_in_do_div___();                      \
+       }                                                               \
+       __rem;                                                          \
+})
+
+/*
+ * do an unsigned 32-bit multiply and divide with intermediate 64-bit product
+ * so as not to lose accuracy
+ * - we use the MDR register to hold the MSW of the product
+ */
+static inline __attribute__((const))
+unsigned __muldiv64u(unsigned val, unsigned mult, unsigned div)
+{
+       unsigned result;
+
+       asm("mulu       %2,%0   \n"     /* MDR:val = val*mult */
+           "divu       %3,%0   \n"     /* val = MDR:val/div;
+                                        * MDR = MDR:val%div */
+           : "=r"(result)
+           : "0"(val), "ir"(mult), "r"(div)
+           );
+
+       return result;
+}
+
+/*
+ * do a signed 32-bit multiply and divide with intermediate 64-bit product so
+ * as not to lose accuracy
+ * - we use the MDR register to hold the MSW of the product
+ */
+static inline __attribute__((const))
+signed __muldiv64s(signed val, signed mult, signed div)
+{
+       signed result;
+
+       asm("mul        %2,%0   \n"     /* MDR:val = val*mult */
+           "div        %3,%0   \n"     /* val = MDR:val/div;
+                                        * MDR = MDR:val%div */
+           : "=r"(result)
+           : "0"(val), "ir"(mult), "r"(div)
+           );
+
+       return result;
+}
+
+extern __attribute__((const))
+uint64_t div64_64(uint64_t dividend, uint64_t divisor);
+
+#endif /* _ASM_DIV64 */
diff --git a/include/asm-mn10300/dma-mapping.h b/include/asm-mn10300/dma-mapping.h
new file mode 100644 (file)
index 0000000..7c882fc
--- /dev/null
@@ -0,0 +1,234 @@
+/* DMA mapping routines for the MN10300 arch
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_DMA_MAPPING_H
+#define _ASM_DMA_MAPPING_H
+
+#include <linux/mm.h>
+#include <linux/scatterlist.h>
+
+#include <asm/cache.h>
+#include <asm/io.h>
+
+extern void *dma_alloc_coherent(struct device *dev, size_t size,
+                               dma_addr_t *dma_handle, int flag);
+
+extern void dma_free_coherent(struct device *dev, size_t size,
+                             void *vaddr, dma_addr_t dma_handle);
+
+#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent((d), (s), (h), (f))
+#define dma_free_noncoherent(d, s, v, h)  dma_free_coherent((d), (s), (v), (h))
+
+/*
+ * Map a single buffer of the indicated size for DMA in streaming mode.  The
+ * 32-bit bus address to use is returned.
+ *
+ * Once the device is given the dma address, the device owns this memory until
+ * either pci_unmap_single or pci_dma_sync_single is performed.
+ */
+static inline
+dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
+                         enum dma_data_direction direction)
+{
+       BUG_ON(direction == DMA_NONE);
+       mn10300_dcache_flush_inv();
+       return virt_to_bus(ptr);
+}
+
+/*
+ * Unmap a single streaming mode DMA translation.  The dma_addr and size must
+ * match what was provided for in a previous pci_map_single call.  All other
+ * usages are undefined.
+ *
+ * After this call, reads by the cpu to the buffer are guarenteed to see
+ * whatever the device wrote there.
+ */
+static inline
+void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
+                     enum dma_data_direction direction)
+{
+       BUG_ON(direction == DMA_NONE);
+}
+
+/*
+ * Map a set of buffers described by scatterlist in streaming mode for DMA.
+ * This is the scather-gather version of the above pci_map_single interface.
+ * Here the scatter gather list elements are each tagged with the appropriate
+ * dma address and length.  They are obtained via sg_dma_{address,length}(SG).
+ *
+ * NOTE: An implementation may be able to use a smaller number of DMA
+ *       address/length pairs than there are SG table elements.  (for example
+ *       via virtual mapping capabilities) The routine returns the number of
+ *       addr/length pairs actually used, at most nents.
+ *
+ * Device ownership issues as mentioned above for pci_map_single are the same
+ * here.
+ */
+static inline
+int dma_map_sg(struct device *dev, struct scatterlist *sglist, int nents,
+              enum dma_data_direction direction)
+{
+       struct scatterlist *sg;
+       int i;
+
+       BUG_ON(!valid_dma_direction(direction));
+       WARN_ON(nents == 0 || sglist[0].length == 0);
+
+       for_each_sg(sglist, sg, nents, i) {
+               BUG_ON(!sg_page(sg));
+
+               sg->dma_address = sg_phys(sg);
+       }
+
+       mn10300_dcache_flush_inv();
+       return nents;
+}
+
+/*
+ * Unmap a set of streaming mode DMA translations.
+ * Again, cpu read rules concerning calls here are the same as for
+ * pci_unmap_single() above.
+ */
+static inline
+void dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
+                 enum dma_data_direction direction)
+{
+       BUG_ON(!valid_dma_direction(direction));
+}
+
+/*
+ * pci_{map,unmap}_single_page maps a kernel page to a dma_addr_t. identical
+ * to pci_map_single, but takes a struct page instead of a virtual address
+ */
+static inline
+dma_addr_t dma_map_page(struct device *dev, struct page *page,
+                       unsigned long offset, size_t size,
+                       enum dma_data_direction direction)
+{
+       BUG_ON(direction == DMA_NONE);
+       return page_to_bus(page) + offset;
+}
+
+static inline
+void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
+                   enum dma_data_direction direction)
+{
+       BUG_ON(direction == DMA_NONE);
+}
+
+/*
+ * Make physical memory consistent for a single streaming mode DMA translation
+ * after a transfer.
+ *
+ * If you perform a pci_map_single() but wish to interrogate the buffer using
+ * the cpu, yet do not wish to teardown the PCI dma mapping, you must call this
+ * function before doing so.  At the next point you give the PCI dma address
+ * back to the card, the device again owns the buffer.
+ */
+static inline
+void dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
+                            size_t size, enum dma_data_direction direction)
+{
+}
+
+static inline
+void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
+                               size_t size, enum dma_data_direction direction)
+{
+       mn10300_dcache_flush_inv();
+}
+
+static inline
+void dma_sync_single_range_for_cpu(struct device *dev, dma_addr_t dma_handle,
+                                  unsigned long offset, size_t size,
+                                  enum dma_data_direction direction)
+{
+}
+
+static inline void
+dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
+                                unsigned long offset, size_t size,
+                                enum dma_data_direction direction)
+{
+       mn10300_dcache_flush_inv();
+}
+
+
+/*
+ * Make physical memory consistent for a set of streaming mode DMA translations
+ * after a transfer.
+ *
+ * The same as pci_dma_sync_single but for a scatter-gather list, same rules
+ * and usage.
+ */
+static inline
+void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
+                        int nelems, enum dma_data_direction direction)
+{
+}
+
+static inline
+void dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
+                           int nelems, enum dma_data_direction direction)
+{
+       mn10300_dcache_flush_inv();
+}
+
+static inline
+int dma_mapping_error(dma_addr_t dma_addr)
+{
+       return 0;
+}
+
+/*
+ * Return whether the given PCI device DMA address mask can be supported
+ * properly.  For example, if your device can only drive the low 24-bits during
+ * PCI bus mastering, then you would pass 0x00ffffff as the mask to this
+ * function.
+ */
+static inline
+int dma_supported(struct device *dev, u64 mask)
+{
+       /*
+        * we fall back to GFP_DMA when the mask isn't all 1s, so we can't
+        * guarantee allocations that must be within a tighter range than
+        * GFP_DMA
+        */
+       if (mask < 0x00ffffff)
+               return 0;
+       return 1;
+}
+
+static inline
+int dma_set_mask(struct device *dev, u64 mask)
+{
+       if (!dev->dma_mask || !dma_supported(dev, mask))
+               return -EIO;
+
+       *dev->dma_mask = mask;
+       return 0;
+}
+
+static inline
+int dma_get_cache_alignment(void)
+{
+       return 1 << L1_CACHE_SHIFT;
+}
+
+#define dma_is_consistent(d)   (1)
+
+static inline
+void dma_cache_sync(void *vaddr, size_t size,
+                   enum dma_data_direction direction)
+{
+       mn10300_dcache_flush_inv();
+}
+
+#endif
diff --git a/include/asm-mn10300/dma.h b/include/asm-mn10300/dma.h
new file mode 100644 (file)
index 0000000..098df2e
--- /dev/null
@@ -0,0 +1,118 @@
+/* MN10300 ISA DMA handlers and definitions
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_DMA_H
+#define _ASM_DMA_H
+
+#include <asm/system.h>
+#include <linux/spinlock.h>
+#include <asm/io.h>
+#include <linux/delay.h>
+
+#undef MAX_DMA_CHANNELS                /* switch off linux/kernel/dma.c */
+#define MAX_DMA_ADDRESS                0xbfffffff
+
+extern spinlock_t dma_spin_lock;
+
+static inline unsigned long claim_dma_lock(void)
+{
+       unsigned long flags;
+       spin_lock_irqsave(&dma_spin_lock, flags);
+       return flags;
+}
+
+static inline void release_dma_lock(unsigned long flags)
+{
+       spin_unlock_irqrestore(&dma_spin_lock, flags);
+}
+
+/* enable/disable a specific DMA channel */
+static inline void enable_dma(unsigned int dmanr)
+{
+}
+
+static inline void disable_dma(unsigned int dmanr)
+{
+}
+
+/* Clear the 'DMA Pointer Flip Flop'.
+ * Write 0 for LSB/MSB, 1 for MSB/LSB access.
+ * Use this once to initialize the FF to a known state.
+ * After that, keep track of it. :-)
+ * --- In order to do that, the DMA routines below should ---
+ * --- only be used while holding the DMA lock ! ---
+ */
+static inline void clear_dma_ff(unsigned int dmanr)
+{
+}
+
+/* set mode (above) for a specific DMA channel */
+static inline void set_dma_mode(unsigned int dmanr, char mode)
+{
+}
+
+/* Set only the page register bits of the transfer address.
+ * This is used for successive transfers when we know the contents of
+ * the lower 16 bits of the DMA current address register, but a 64k boundary
+ * may have been crossed.
+ */
+static inline void set_dma_page(unsigned int dmanr, char pagenr)
+{
+}
+
+
+/* Set transfer address & page bits for specific DMA channel.
+ * Assumes dma flipflop is clear.
+ */
+static inline void set_dma_addr(unsigned int dmanr, unsigned int a)
+{
+}
+
+
+/* Set transfer size (max 64k for DMA1..3, 128k for DMA5..7) for
+ * a specific DMA channel.
+ * You must ensure the parameters are valid.
+ * NOTE: from a manual: "the number of transfers is one more
+ * than the initial word count"! This is taken into account.
+ * Assumes dma flip-flop is clear.
+ * NOTE 2: "count" represents _bytes_ and must be even for channels 5-7.
+ */
+static inline void set_dma_count(unsigned int dmanr, unsigned int count)
+{
+}
+
+
+/* Get DMA residue count. After a DMA transfer, this
+ * should return zero. Reading this while a DMA transfer is
+ * still in progress will return unpredictable results.
+ * If called before the channel has been used, it may return 1.
+ * Otherwise, it returns the number of _bytes_ left to transfer.
+ *
+ * Assumes DMA flip-flop is clear.
+ */
+static inline int get_dma_residue(unsigned int dmanr)
+{
+       return 0;
+}
+
+
+/* These are in kernel/dma.c: */
+extern int request_dma(unsigned int dmanr, const char *device_id);
+extern void free_dma(unsigned int dmanr);
+
+/* From PCI */
+
+#ifdef CONFIG_PCI
+extern int isa_dma_bridge_buggy;
+#else
+#define isa_dma_bridge_buggy   (0)
+#endif
+
+#endif /* _ASM_DMA_H */
diff --git a/include/asm-mn10300/dmactl-regs.h b/include/asm-mn10300/dmactl-regs.h
new file mode 100644 (file)
index 0000000..58a199d
--- /dev/null
@@ -0,0 +1,101 @@
+/* MN10300 on-board DMA controller registers
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_DMACTL_REGS_H
+#define _ASM_DMACTL_REGS_H
+
+#include <asm/cpu-regs.h>
+
+#ifdef __KERNEL__
+
+/* DMA registers */
+#define        DMxCTR(N)               __SYSREG(0xd2000000 + ((N) * 0x100), u32)       /* control reg */
+#define        DMxCTR_BG               0x0000001f      /* transfer request source */
+#define        DMxCTR_BG_SOFT          0x00000000      /* - software source */
+#define        DMxCTR_BG_SC0TX         0x00000002      /* - serial port 0 transmission */
+#define        DMxCTR_BG_SC0RX         0x00000003      /* - serial port 0 reception */
+#define        DMxCTR_BG_SC1TX         0x00000004      /* - serial port 1 transmission */
+#define        DMxCTR_BG_SC1RX         0x00000005      /* - serial port 1 reception */
+#define        DMxCTR_BG_SC2TX         0x00000006      /* - serial port 2 transmission */
+#define        DMxCTR_BG_SC2RX         0x00000007      /* - serial port 2 reception */
+#define        DMxCTR_BG_TM0UFLOW      0x00000008      /* - timer 0 underflow */
+#define        DMxCTR_BG_TM1UFLOW      0x00000009      /* - timer 1 underflow */
+#define        DMxCTR_BG_TM2UFLOW      0x0000000a      /* - timer 2 underflow */
+#define        DMxCTR_BG_TM3UFLOW      0x0000000b      /* - timer 3 underflow */
+#define        DMxCTR_BG_TM6ACMPCAP    0x0000000c      /* - timer 6A compare/capture */
+#define        DMxCTR_BG_AFE           0x0000000d      /* - analogue front-end interrupt source */
+#define        DMxCTR_BG_ADC           0x0000000e      /* - A/D conversion end interrupt source */
+#define        DMxCTR_BG_IRDA          0x0000000f      /* - IrDA interrupt source */
+#define        DMxCTR_BG_RTC           0x00000010      /* - RTC interrupt source */
+#define        DMxCTR_BG_XIRQ0         0x00000011      /* - XIRQ0 pin interrupt source */
+#define        DMxCTR_BG_XIRQ1         0x00000012      /* - XIRQ1 pin interrupt source */
+#define        DMxCTR_BG_XDMR0         0x00000013      /* - external request 0 source (XDMR0 pin) */
+#define        DMxCTR_BG_XDMR1         0x00000014      /* - external request 1 source (XDMR1 pin) */
+#define        DMxCTR_SAM              0x000000e0      /* DMA transfer src addr mode */
+#define        DMxCTR_SAM_INCR         0x00000000      /* - increment */
+#define        DMxCTR_SAM_DECR         0x00000020      /* - decrement */
+#define        DMxCTR_SAM_FIXED        0x00000040      /* - fixed */
+#define        DMxCTR_DAM              0x00000000      /* DMA transfer dest addr mode */
+#define        DMxCTR_DAM_INCR         0x00000000      /* - increment */
+#define        DMxCTR_DAM_DECR         0x00000100      /* - decrement */
+#define        DMxCTR_DAM_FIXED        0x00000200      /* - fixed */
+#define        DMxCTR_TM               0x00001800      /* DMA transfer mode */
+#define        DMxCTR_TM_BATCH         0x00000000      /* - batch transfer */
+#define        DMxCTR_TM_INTERM        0x00001000      /* - intermittent transfer */
+#define        DMxCTR_UT               0x00006000      /* DMA transfer unit */
+#define        DMxCTR_UT_1             0x00000000      /* - 1 byte */
+#define        DMxCTR_UT_2             0x00002000      /* - 2 byte */
+#define        DMxCTR_UT_4             0x00004000      /* - 4 byte */
+#define        DMxCTR_UT_16            0x00006000      /* - 16 byte */
+#define        DMxCTR_TEN              0x00010000      /* DMA channel transfer enable */
+#define        DMxCTR_RQM              0x00060000      /* external request input source mode */
+#define        DMxCTR_RQM_FALLEDGE     0x00000000      /* - falling edge */
+#define        DMxCTR_RQM_RISEEDGE     0x00020000      /* - rising edge */
+#define        DMxCTR_RQM_LOLEVEL      0x00040000      /* - low level */
+#define        DMxCTR_RQM_HILEVEL      0x00060000      /* - high level */
+#define        DMxCTR_RQF              0x01000000      /* DMA transfer request flag */
+#define        DMxCTR_XEND             0x80000000      /* DMA transfer end flag */
+
+#define        DMxSRC(N)               __SYSREG(0xd2000004 + ((N) * 0x100), u32)       /* control reg */
+
+#define        DMxDST(N)               __SYSREG(0xd2000008 + ((N) * 0x100), u32)       /* src addr reg */
+
+#define        DMxSIZ(N)               __SYSREG(0xd200000c + ((N) * 0x100), u32)       /* dest addr reg */
+#define DMxSIZ_CT              0x000fffff      /* number of bytes to transfer */
+
+#define        DMxCYC(N)               __SYSREG(0xd2000010 + ((N) * 0x100), u32)       /* intermittent
+                                                                                * size reg */
+#define DMxCYC_CYC             0x000000ff      /* number of interrmittent transfers -1 */
+
+#define DM0IRQ                 16              /* DMA channel 0 complete IRQ */
+#define DM1IRQ                 17              /* DMA channel 1 complete IRQ */
+#define DM2IRQ                 18              /* DMA channel 2 complete IRQ */
+#define DM3IRQ                 19              /* DMA channel 3 complete IRQ */
+
+#define        DM0ICR                  GxICR(DM0IRQ)   /* DMA channel 0 complete intr ctrl reg */
+#define        DM1ICR                  GxICR(DM0IR1)   /* DMA channel 1 complete intr ctrl reg */
+#define        DM2ICR                  GxICR(DM0IR2)   /* DMA channel 2 complete intr ctrl reg */
+#define        DM3ICR                  GxICR(DM0IR3)   /* DMA channel 3 complete intr ctrl reg */
+
+#ifndef __ASSEMBLY__
+
+struct mn10300_dmactl_regs {
+       u32             ctr;
+       const void      *src;
+       void            *dst;
+       u32             siz;
+       u32             cyc;
+} __attribute__((aligned(0x100)));
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_DMACTL_REGS_H */
diff --git a/include/asm-mn10300/elf.h b/include/asm-mn10300/elf.h
new file mode 100644 (file)
index 0000000..256a704
--- /dev/null
@@ -0,0 +1,147 @@
+/* MN10300 ELF constant and register definitions
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_ELF_H
+#define _ASM_ELF_H
+
+#include <linux/utsname.h>
+#include <asm/ptrace.h>
+#include <asm/user.h>
+
+/*
+ * AM33 relocations
+ */
+#define R_MN10300_NONE         0       /* No reloc.  */
+#define R_MN10300_32           1       /* Direct 32 bit.  */
+#define R_MN10300_16           2       /* Direct 16 bit.  */
+#define R_MN10300_8            3       /* Direct 8 bit.  */
+#define R_MN10300_PCREL32      4       /* PC-relative 32-bit.  */
+#define R_MN10300_PCREL16      5       /* PC-relative 16-bit signed.  */
+#define R_MN10300_PCREL8       6       /* PC-relative 8-bit signed.  */
+#define R_MN10300_24           9       /* Direct 24 bit.  */
+#define R_MN10300_RELATIVE     23      /* Adjust by program base.  */
+
+/*
+ * ELF register definitions..
+ */
+typedef unsigned long elf_greg_t;
+
+#define ELF_NGREG (sizeof (struct pt_regs) / sizeof(elf_greg_t))
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+#define ELF_NFPREG 32
+typedef float elf_fpreg_t;
+
+typedef struct {
+       elf_fpreg_t     fpregs[ELF_NFPREG];
+       u_int32_t       fpcr;
+} elf_fpregset_t;
+
+extern int dump_fpu(struct pt_regs *, elf_fpregset_t *);
+
+/*
+ * This is used to ensure we don't load something for the wrong architecture
+ */
+#define elf_check_arch(x) \
+       (((x)->e_machine == EM_CYGNUS_MN10300) ||       \
+        ((x)->e_machine == EM_MN10300))
+
+/*
+ * These are used to set parameters in the core dumps.
+ */
+#define ELF_CLASS      ELFCLASS32
+#define ELF_DATA       ELFDATA2LSB
+#define ELF_ARCH       EM_MN10300
+
+/*
+ * ELF process initialiser
+ */
+#define ELF_PLAT_INIT(_r, load_addr)                                   \
+do {                                                                   \
+       struct pt_regs *_ur = current->thread.uregs;                    \
+       _ur->a3   = 0;  _ur->a2   = 0;  _ur->d3   = 0;  _ur->d2   = 0;  \
+       _ur->mcvf = 0;  _ur->mcrl = 0;  _ur->mcrh = 0;  _ur->mdrq = 0;  \
+       _ur->e1   = 0;  _ur->e0   = 0;  _ur->e7   = 0;  _ur->e6   = 0;  \
+       _ur->e5   = 0;  _ur->e4   = 0;  _ur->e3   = 0;  _ur->e2   = 0;  \
+       _ur->lar  = 0;  _ur->lir  = 0;  _ur->mdr  = 0;                  \
+       _ur->a1   = 0;  _ur->a0   = 0;  _ur->d1   = 0;  _ur->d0   = 0;  \
+} while (0)
+
+#define USE_ELF_CORE_DUMP
+#define ELF_EXEC_PAGESIZE      4096
+
+/*
+ * This is the location that an ET_DYN program is loaded if exec'ed.  Typical
+ * use of this is to invoke "./ld.so someprog" to test out a new version of
+ * the loader.  We need to make sure that it is out of the way of the program
+ * that it will "exec", and that there is sufficient room for the brk.
+ * - must clear the VMALLOC area
+ */
+#define ELF_ET_DYN_BASE         0x04000000
+
+/*
+ * regs is struct pt_regs, pr_reg is elf_gregset_t (which is
+ * now struct user_regs, they are different)
+ * - ELF_CORE_COPY_REGS has been guessed, and may be wrong
+ */
+#define ELF_CORE_COPY_REGS(pr_reg, regs)       \
+do {                                           \
+       pr_reg[0]       = regs->a3;             \
+       pr_reg[1]       = regs->a2;             \
+       pr_reg[2]       = regs->d3;             \
+       pr_reg[3]       = regs->d2;             \
+       pr_reg[4]       = regs->mcvf;           \
+       pr_reg[5]       = regs->mcrl;           \
+       pr_reg[6]       = regs->mcrh;           \
+       pr_reg[7]       = regs->mdrq;           \
+       pr_reg[8]       = regs->e1;             \
+       pr_reg[9]       = regs->e0;             \
+       pr_reg[10]      = regs->e7;             \
+       pr_reg[11]      = regs->e6;             \
+       pr_reg[12]      = regs->e5;             \
+       pr_reg[13]      = regs->e4;             \
+       pr_reg[14]      = regs->e3;             \
+       pr_reg[15]      = regs->e2;             \
+       pr_reg[16]      = regs->sp;             \
+       pr_reg[17]      = regs->lar;            \
+       pr_reg[18]      = regs->lir;            \
+       pr_reg[19]      = regs->mdr;            \
+       pr_reg[20]      = regs->a1;             \
+       pr_reg[21]      = regs->a0;             \
+       pr_reg[22]      = regs->d1;             \
+       pr_reg[23]      = regs->d0;             \
+       pr_reg[24]      = regs->orig_d0;        \
+       pr_reg[25]      = regs->epsw;           \
+       pr_reg[26]      = regs->pc;             \
+} while (0);
+
+/*
+ * This yields a mask that user programs can use to figure out what
+ * instruction set this CPU supports.  This could be done in user space,
+ * but it's not easy, and we've already done it here.
+ */
+#define ELF_HWCAP      (0)
+
+/*
+ * This yields a string that ld.so will use to load implementation
+ * specific libraries for optimization.  This is more specific in
+ * intent than poking at uname or /proc/cpuinfo.
+ *
+ * For the moment, we have only optimizations for the Intel generations,
+ * but that could change...
+ */
+#define ELF_PLATFORM  (NULL)
+
+#ifdef __KERNEL__
+#define SET_PERSONALITY(ex, ibcs2) set_personality(PER_LINUX)
+#endif
+
+#endif /* _ASM_ELF_H */
diff --git a/include/asm-mn10300/emergency-restart.h b/include/asm-mn10300/emergency-restart.h
new file mode 100644 (file)
index 0000000..3711bd9
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/emergency-restart.h>
diff --git a/include/asm-mn10300/errno.h b/include/asm-mn10300/errno.h
new file mode 100644 (file)
index 0000000..4c82b50
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/errno.h>
diff --git a/include/asm-mn10300/exceptions.h b/include/asm-mn10300/exceptions.h
new file mode 100644 (file)
index 0000000..fa16466
--- /dev/null
@@ -0,0 +1,121 @@
+/* MN10300 Microcontroller core exceptions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_EXCEPTIONS_H
+#define _ASM_EXCEPTIONS_H
+
+#include <linux/linkage.h>
+
+/*
+ * define the breakpoint instruction opcode to use
+ * - note that the JTAG unit steals 0xFF, so we want to avoid that if we can
+ *   (can use 0xF7)
+ */
+#define GDBSTUB_BKPT           0xFF
+
+#ifndef __ASSEMBLY__
+
+/*
+ * enumeration of exception codes (as extracted from TBR MSW)
+ */
+enum exception_code {
+       EXCEP_RESET             = 0x000000,     /* reset */
+
+       /* MMU exceptions */
+       EXCEP_ITLBMISS          = 0x000100,     /* instruction TLB miss */
+       EXCEP_DTLBMISS          = 0x000108,     /* data TLB miss */
+       EXCEP_IAERROR           = 0x000110,     /* instruction address */
+       EXCEP_DAERROR           = 0x000118,     /* data address */
+
+       /* system exceptions */
+       EXCEP_TRAP              = 0x000128,     /* program interrupt (PI instruction) */
+       EXCEP_ISTEP             = 0x000130,     /* single step */
+       EXCEP_IBREAK            = 0x000150,     /* instruction breakpoint */
+       EXCEP_OBREAK            = 0x000158,     /* operand breakpoint */
+       EXCEP_PRIVINS           = 0x000160,     /* privileged instruction execution */
+       EXCEP_UNIMPINS          = 0x000168,     /* unimplemented instruction execution */
+       EXCEP_UNIMPEXINS        = 0x000170,     /* unimplemented extended instruction execution */
+       EXCEP_MEMERR            = 0x000178,     /* illegal memory access */
+       EXCEP_MISALIGN          = 0x000180,     /* misalignment */
+       EXCEP_BUSERROR          = 0x000188,     /* bus error */
+       EXCEP_ILLINSACC         = 0x000190,     /* illegal instruction access */
+       EXCEP_ILLDATACC         = 0x000198,     /* illegal data access */
+       EXCEP_IOINSACC          = 0x0001a0,     /* I/O space instruction access */
+       EXCEP_PRIVINSACC        = 0x0001a8,     /* privileged space instruction access */
+       EXCEP_PRIVDATACC        = 0x0001b0,     /* privileged space data access */
+       EXCEP_DATINSACC         = 0x0001b8,     /* data space instruction access */
+       EXCEP_DOUBLE_FAULT      = 0x000200,     /* double fault */
+
+       /* FPU exceptions */
+       EXCEP_FPU_DISABLED      = 0x0001c0,     /* FPU disabled */
+       EXCEP_FPU_UNIMPINS      = 0x0001c8,     /* FPU unimplemented operation */
+       EXCEP_FPU_OPERATION     = 0x0001d0,     /* FPU operation */
+
+       /* interrupts */
+       EXCEP_WDT               = 0x000240,     /* watchdog timer overflow */
+       EXCEP_NMI               = 0x000248,     /* non-maskable interrupt */
+       EXCEP_IRQ_LEVEL0        = 0x000280,     /* level 0 maskable interrupt */
+       EXCEP_IRQ_LEVEL1        = 0x000288,     /* level 1 maskable interrupt */
+       EXCEP_IRQ_LEVEL2        = 0x000290,     /* level 2 maskable interrupt */
+       EXCEP_IRQ_LEVEL3        = 0x000298,     /* level 3 maskable interrupt */
+       EXCEP_IRQ_LEVEL4        = 0x0002a0,     /* level 4 maskable interrupt */
+       EXCEP_IRQ_LEVEL5        = 0x0002a8,     /* level 5 maskable interrupt */
+       EXCEP_IRQ_LEVEL6        = 0x0002b0,     /* level 6 maskable interrupt */
+
+       /* system calls */
+       EXCEP_SYSCALL0          = 0x000300,     /* system call 0 */
+       EXCEP_SYSCALL1          = 0x000308,     /* system call 1 */
+       EXCEP_SYSCALL2          = 0x000310,     /* system call 2 */
+       EXCEP_SYSCALL3          = 0x000318,     /* system call 3 */
+       EXCEP_SYSCALL4          = 0x000320,     /* system call 4 */
+       EXCEP_SYSCALL5          = 0x000328,     /* system call 5 */
+       EXCEP_SYSCALL6          = 0x000330,     /* system call 6 */
+       EXCEP_SYSCALL7          = 0x000338,     /* system call 7 */
+       EXCEP_SYSCALL8          = 0x000340,     /* system call 8 */
+       EXCEP_SYSCALL9          = 0x000348,     /* system call 9 */
+       EXCEP_SYSCALL10         = 0x000350,     /* system call 10 */
+       EXCEP_SYSCALL11         = 0x000358,     /* system call 11 */
+       EXCEP_SYSCALL12         = 0x000360,     /* system call 12 */
+       EXCEP_SYSCALL13         = 0x000368,     /* system call 13 */
+       EXCEP_SYSCALL14         = 0x000370,     /* system call 14 */
+       EXCEP_SYSCALL15         = 0x000378,     /* system call 15 */
+};
+
+extern void __set_intr_stub(enum exception_code code, void *handler);
+extern void set_intr_stub(enum exception_code code, void *handler);
+extern void set_jtag_stub(enum exception_code code, void *handler);
+
+struct pt_regs;
+
+extern asmlinkage void __common_exception(void);
+extern asmlinkage void itlb_miss(void);
+extern asmlinkage void dtlb_miss(void);
+extern asmlinkage void itlb_aerror(void);
+extern asmlinkage void dtlb_aerror(void);
+extern asmlinkage void raw_bus_error(void);
+extern asmlinkage void double_fault(void);
+extern asmlinkage int  system_call(struct pt_regs *);
+extern asmlinkage void fpu_exception(struct pt_regs *, enum exception_code);
+extern asmlinkage void nmi(struct pt_regs *, enum exception_code);
+extern asmlinkage void uninitialised_exception(struct pt_regs *,
+                                              enum exception_code);
+extern asmlinkage void irq_handler(void);
+extern asmlinkage void profile_handler(void);
+extern asmlinkage void nmi_handler(void);
+extern asmlinkage void misalignment(struct pt_regs *, enum exception_code);
+
+extern void die(const char *, struct pt_regs *, enum exception_code)
+       ATTRIB_NORET;
+
+extern int die_if_no_fixup(const char *, struct pt_regs *, enum exception_code);
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _ASM_EXCEPTIONS_H */
diff --git a/include/asm-mn10300/fb.h b/include/asm-mn10300/fb.h
new file mode 100644 (file)
index 0000000..697b24a
--- /dev/null
@@ -0,0 +1,23 @@
+/* MN10300 Frame buffer stuff
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_FB_H
+#define _ASM_FB_H
+
+#include <linux/fb.h>
+
+#define fb_pgprotect(...) do {} while (0)
+
+static inline int fb_is_primary_device(struct fb_info *info)
+{
+       return 0;
+}
+
+#endif /* _ASM_FB_H */
diff --git a/include/asm-mn10300/fcntl.h b/include/asm-mn10300/fcntl.h
new file mode 100644 (file)
index 0000000..46ab12d
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/fcntl.h>
diff --git a/include/asm-mn10300/fpu.h b/include/asm-mn10300/fpu.h
new file mode 100644 (file)
index 0000000..64a2b83
--- /dev/null
@@ -0,0 +1,85 @@
+/* MN10300 FPU definitions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ * Derived from include/asm-i386/i387.h: Copyright (C) 1994 Linus Torvalds
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_FPU_H
+#define _ASM_FPU_H
+
+#include <asm/processor.h>
+#include <asm/sigcontext.h>
+#include <asm/user.h>
+
+#ifdef __KERNEL__
+
+/* the task that owns the FPU state */
+extern struct task_struct *fpu_state_owner;
+
+#define set_using_fpu(tsk)                             \
+do {                                                   \
+       (tsk)->thread.fpu_flags |= THREAD_USING_FPU;    \
+} while (0)
+
+#define clear_using_fpu(tsk)                           \
+do {                                                   \
+       (tsk)->thread.fpu_flags &= ~THREAD_USING_FPU;   \
+} while (0)
+
+#define is_using_fpu(tsk) ((tsk)->thread.fpu_flags & THREAD_USING_FPU)
+
+#define unlazy_fpu(tsk)                                        \
+do {                                                   \
+       preempt_disable();                              \
+       if (fpu_state_owner == (tsk))                   \
+               fpu_save(&tsk->thread.fpu_state);       \
+       preempt_enable();                               \
+} while (0)
+
+#define exit_fpu()                             \
+do {                                           \
+       struct task_struct *__tsk = current;    \
+       preempt_disable();                      \
+       if (fpu_state_owner == __tsk)           \
+               fpu_state_owner = NULL;         \
+       preempt_enable();                       \
+} while (0)
+
+#define flush_fpu()                                    \
+do {                                                   \
+       struct task_struct *__tsk = current;            \
+       preempt_disable();                              \
+       if (fpu_state_owner == __tsk) {                 \
+               fpu_state_owner = NULL;                 \
+               __tsk->thread.uregs->epsw &= ~EPSW_FE;  \
+       }                                               \
+       preempt_enable();                               \
+       clear_using_fpu(__tsk);                         \
+} while (0)
+
+extern asmlinkage void fpu_init_state(void);
+extern asmlinkage void fpu_kill_state(struct task_struct *);
+extern asmlinkage void fpu_disabled(struct pt_regs *, enum exception_code);
+extern asmlinkage void fpu_exception(struct pt_regs *, enum exception_code);
+
+#ifdef CONFIG_FPU
+extern asmlinkage void fpu_save(struct fpu_state_struct *);
+extern asmlinkage void fpu_restore(struct fpu_state_struct *);
+#else
+#define fpu_save(a)
+#define fpu_restore(a)
+#endif /* CONFIG_FPU  */
+
+/*
+ * signal frame handlers
+ */
+extern int fpu_setup_sigcontext(struct fpucontext *buf);
+extern int fpu_restore_sigcontext(struct fpucontext *buf);
+
+#endif /* __KERNEL__ */
+#endif /* _ASM_FPU_H */
diff --git a/include/asm-mn10300/frame.inc b/include/asm-mn10300/frame.inc
new file mode 100644 (file)
index 0000000..5b1949b
--- /dev/null
@@ -0,0 +1,91 @@
+/* MN10300 Microcontroller core system register definitions -*- asm -*-
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_FRAME_INC
+#define _ASM_FRAME_INC
+
+#ifndef __ASSEMBLY__
+#error not for use in C files
+#endif
+
+#ifndef __ASM_OFFSETS_H__
+#include <asm/asm-offsets.h>
+#endif
+
+#define pi break
+
+#define fp a3
+
+###############################################################################
+#
+# build a stack frame from the registers
+# - the caller has subtracted 4 from SP before coming here
+#
+###############################################################################
+.macro SAVE_ALL
+       add     -4,sp                           # next exception frame ptr save area
+       movm    [other],(sp)
+       mov     usp,a1
+       mov     a1,(sp)                         # USP in MOVM[other] dummy slot
+       movm    [d2,d3,a2,a3,exreg0,exreg1,exother],(sp)
+       mov     sp,fp                           # FRAME pointer in A3
+       add     -12,sp                          # allow for calls to be made
+       mov     (__frame),a1
+       mov     a1,(REG_NEXT,fp)
+       mov     fp,(__frame)
+
+       and     ~EPSW_FE,epsw                   # disable the FPU inside the kernel
+
+       # we may be holding current in E2
+#ifdef CONFIG_MN10300_CURRENT_IN_E2
+       mov     (__current),e2
+#endif
+.endm
+
+###############################################################################
+#
+# restore the registers from a stack frame
+#
+###############################################################################
+.macro RESTORE_ALL
+       # peel back the stack to the calling frame
+       # - this permits execve() to discard extra frames due to kernel syscalls
+       mov     (__frame),fp
+       mov     fp,sp
+       mov     (REG_NEXT,fp),d0                # userspace has regs->next == 0
+       mov     d0,(__frame)
+
+#ifndef CONFIG_MN10300_USING_JTAG
+       mov     (REG_EPSW,fp),d0
+       btst    EPSW_T,d0
+       beq     99f
+
+       or      EPSW_NMID,epsw
+       movhu   (DCR),d1
+       or      0x0001, d1
+       movhu   d1,(DCR)
+
+99:
+#endif
+       movm    (sp),[d2,d3,a2,a3,exreg0,exreg1,exother]
+
+       # must restore usp even if returning to kernel space,
+       # when CONFIG_PREEMPT is enabled.
+       mov     (sp),a1                         # USP in MOVM[other] dummy slot
+       mov     a1,usp
+
+       movm    (sp),[other]
+       add     8,sp
+       rti
+
+.endm
+
+
+#endif /* _ASM_FRAME_INC */
diff --git a/include/asm-mn10300/futex.h b/include/asm-mn10300/futex.h
new file mode 100644 (file)
index 0000000..0b74582
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/futex.h>
diff --git a/include/asm-mn10300/gdb-stub.h b/include/asm-mn10300/gdb-stub.h
new file mode 100644 (file)
index 0000000..e5a6368
--- /dev/null
@@ -0,0 +1,183 @@
+/* MN10300 Kernel GDB stub definitions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ * - Derived from asm-mips/gdb-stub.h (c) 1995 Andreas Busse
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_GDB_STUB_H
+#define _ASM_GDB_STUB_H
+
+#include <asm/exceptions.h>
+
+/*
+ * register ID numbers in GDB remote protocol
+ */
+
+#define GDB_REGID_PC           9
+#define GDB_REGID_FP           7
+#define GDB_REGID_SP           8
+
+/*
+ * virtual stack layout for the GDB exception handler
+ */
+#define NUMREGS                        64
+
+#define GDB_FR_D0              (0 * 4)
+#define GDB_FR_D1              (1 * 4)
+#define GDB_FR_D2              (2 * 4)
+#define GDB_FR_D3              (3 * 4)
+#define GDB_FR_A0              (4 * 4)
+#define GDB_FR_A1              (5 * 4)
+#define GDB_FR_A2              (6 * 4)
+#define GDB_FR_A3              (7 * 4)
+
+#define GDB_FR_SP              (8 * 4)
+#define GDB_FR_PC              (9 * 4)
+#define GDB_FR_MDR             (10 * 4)
+#define GDB_FR_EPSW            (11 * 4)
+#define GDB_FR_LIR             (12 * 4)
+#define GDB_FR_LAR             (13 * 4)
+#define GDB_FR_MDRQ            (14 * 4)
+
+#define GDB_FR_E0              (15 * 4)
+#define GDB_FR_E1              (16 * 4)
+#define GDB_FR_E2              (17 * 4)
+#define GDB_FR_E3              (18 * 4)
+#define GDB_FR_E4              (19 * 4)
+#define GDB_FR_E5              (20 * 4)
+#define GDB_FR_E6              (21 * 4)
+#define GDB_FR_E7              (22 * 4)
+
+#define GDB_FR_SSP             (23 * 4)
+#define GDB_FR_MSP             (24 * 4)
+#define GDB_FR_USP             (25 * 4)
+#define GDB_FR_MCRH            (26 * 4)
+#define GDB_FR_MCRL            (27 * 4)
+#define GDB_FR_MCVF            (28 * 4)
+
+#define GDB_FR_FPCR            (29 * 4)
+#define GDB_FR_DUMMY0          (30 * 4)
+#define GDB_FR_DUMMY1          (31 * 4)
+
+#define GDB_FR_FS0             (32 * 4)
+
+#define GDB_FR_SIZE            (NUMREGS * 4)
+
+#ifndef __ASSEMBLY__
+
+/*
+ * This is the same as above, but for the high-level
+ * part of the GDB stub.
+ */
+
+struct gdb_regs {
+       /* saved main processor registers */
+       u32     d0, d1, d2, d3, a0, a1, a2, a3;
+       u32     sp, pc, mdr, epsw, lir, lar, mdrq;
+       u32     e0, e1, e2, e3, e4, e5, e6, e7;
+       u32     ssp, msp, usp, mcrh, mcrl, mcvf;
+
+       /* saved floating point registers */
+       u32     fpcr, _dummy0, _dummy1;
+       u32     fs0,  fs1,  fs2,  fs3,  fs4,  fs5,  fs6,  fs7;
+       u32     fs8,  fs9,  fs10, fs11, fs12, fs13, fs14, fs15;
+       u32     fs16, fs17, fs18, fs19, fs20, fs21, fs22, fs23;
+       u32     fs24, fs25, fs26, fs27, fs28, fs29, fs30, fs31;
+};
+
+/*
+ * Prototypes
+ */
+extern void show_registers_only(struct pt_regs *regs);
+
+extern asmlinkage void gdbstub_init(void);
+extern asmlinkage void gdbstub_exit(int status);
+extern asmlinkage void gdbstub_io_init(void);
+extern asmlinkage void gdbstub_io_set_baud(unsigned baud);
+extern asmlinkage int  gdbstub_io_rx_char(unsigned char *_ch, int nonblock);
+extern asmlinkage void gdbstub_io_tx_char(unsigned char ch);
+extern asmlinkage void gdbstub_io_tx_flush(void);
+
+extern asmlinkage void gdbstub_io_rx_handler(void);
+extern asmlinkage void gdbstub_rx_irq(struct pt_regs *, enum exception_code);
+extern asmlinkage int  gdbstub_intercept(struct pt_regs *, enum exception_code);
+extern asmlinkage void gdbstub_exception(struct pt_regs *, enum exception_code);
+extern asmlinkage void __gdbstub_bug_trap(void);
+extern asmlinkage void __gdbstub_pause(void);
+extern asmlinkage void start_kernel(void);
+
+#ifndef CONFIG_MN10300_CACHE_DISABLED
+extern asmlinkage void gdbstub_purge_cache(void);
+#else
+#define gdbstub_purge_cache()  do {} while (0)
+#endif
+
+/* Used to prevent crashes in memory access */
+extern asmlinkage int  gdbstub_read_byte(const u8 *, u8 *);
+extern asmlinkage int  gdbstub_read_word(const u8 *, u8 *);
+extern asmlinkage int  gdbstub_read_dword(const u8 *, u8 *);
+extern asmlinkage int  gdbstub_write_byte(u32, u8 *);
+extern asmlinkage int  gdbstub_write_word(u32, u8 *);
+extern asmlinkage int  gdbstub_write_dword(u32, u8 *);
+
+extern asmlinkage void gdbstub_read_byte_guard(void);
+extern asmlinkage void gdbstub_read_byte_cont(void);
+extern asmlinkage void gdbstub_read_word_guard(void);
+extern asmlinkage void gdbstub_read_word_cont(void);
+extern asmlinkage void gdbstub_read_dword_guard(void);
+extern asmlinkage void gdbstub_read_dword_cont(void);
+extern asmlinkage void gdbstub_write_byte_guard(void);
+extern asmlinkage void gdbstub_write_byte_cont(void);
+extern asmlinkage void gdbstub_write_word_guard(void);
+extern asmlinkage void gdbstub_write_word_cont(void);
+extern asmlinkage void gdbstub_write_dword_guard(void);
+extern asmlinkage void gdbstub_write_dword_cont(void);
+
+extern u8      gdbstub_rx_buffer[PAGE_SIZE];
+extern u32     gdbstub_rx_inp;
+extern u32     gdbstub_rx_outp;
+extern u8      gdbstub_rx_overflow;
+extern u8      gdbstub_busy;
+extern u8      gdbstub_rx_unget;
+
+#ifdef CONFIG_GDBSTUB_DEBUGGING
+extern void gdbstub_printk(const char *fmt, ...)
+       __attribute__((format(printf, 1, 2)));
+#else
+static inline __attribute__((format(printf, 1, 2)))
+void gdbstub_printk(const char *fmt, ...)
+{
+}
+#endif
+
+#ifdef CONFIG_GDBSTUB_DEBUG_ENTRY
+#define gdbstub_entry(FMT, ...) gdbstub_printk(FMT, ##__VA_ARGS__)
+#else
+#define gdbstub_entry(FMT, ...) ({ 0; })
+#endif
+
+#ifdef CONFIG_GDBSTUB_DEBUG_PROTOCOL
+#define gdbstub_proto(FMT, ...) gdbstub_printk(FMT, ##__VA_ARGS__)
+#else
+#define gdbstub_proto(FMT, ...) ({ 0; })
+#endif
+
+#ifdef CONFIG_GDBSTUB_DEBUG_IO
+#define gdbstub_io(FMT, ...) gdbstub_printk(FMT, ##__VA_ARGS__)
+#else
+#define gdbstub_io(FMT, ...) ({ 0; })
+#endif
+
+#ifdef CONFIG_GDBSTUB_DEBUG_BREAKPOINT
+#define gdbstub_bkpt(FMT, ...) gdbstub_printk(FMT, ##__VA_ARGS__)
+#else
+#define gdbstub_bkpt(FMT, ...) ({ 0; })
+#endif
+
+#endif /* !__ASSEMBLY__ */
+#endif /* _ASM_GDB_STUB_H */
diff --git a/include/asm-mn10300/hardirq.h b/include/asm-mn10300/hardirq.h
new file mode 100644 (file)
index 0000000..54d9501
--- /dev/null
@@ -0,0 +1,48 @@
+/* MN10300 Hardware IRQ statistics and management
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Modified by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_HARDIRQ_H
+#define _ASM_HARDIRQ_H
+
+#include <linux/threads.h>
+#include <linux/irq.h>
+#include <asm/exceptions.h>
+
+/* assembly code in softirq.h is sensitive to the offsets of these fields */
+typedef struct {
+       unsigned int    __softirq_pending;
+       unsigned long   idle_timestamp;
+       unsigned int    __nmi_count;    /* arch dependent */
+       unsigned int    __irq_count;    /* arch dependent */
+} ____cacheline_aligned irq_cpustat_t;
+
+#include <linux/irq_cpustat.h> /* Standard mappings for irq_cpustat_t above */
+
+extern void ack_bad_irq(int irq);
+
+/*
+ * manipulate stubs in the MN10300 CPU Trap/Interrupt Vector table
+ * - these should jump to __common_exception in entry.S unless there's a good
+ *   reason to do otherwise (see trap_preinit() in traps.c)
+ */
+typedef void (*intr_stub_fnx)(struct pt_regs *regs,
+                             enum exception_code intcode);
+
+/*
+ * manipulate pointers in the Exception table (see entry.S)
+ * - these are indexed by decoding the lower 24 bits of the TBR register
+ * - note that the MN103E010 doesn't always trap through the correct vector,
+ *   but does always set the TBR correctly
+ */
+extern asmlinkage void set_excp_vector(enum exception_code code,
+                                      intr_stub_fnx handler);
+
+#endif /* _ASM_HARDIRQ_H */
diff --git a/include/asm-mn10300/highmem.h b/include/asm-mn10300/highmem.h
new file mode 100644 (file)
index 0000000..383c0c4
--- /dev/null
@@ -0,0 +1,114 @@
+/* MN10300 Virtual kernel memory mappings for high memory
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ * - Derived from include/asm-i386/highmem.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_HIGHMEM_H
+#define _ASM_HIGHMEM_H
+
+#ifdef __KERNEL__
+
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <asm/kmap_types.h>
+#include <asm/pgtable.h>
+
+/* undef for production */
+#undef HIGHMEM_DEBUG
+
+/* declarations for highmem.c */
+extern unsigned long highstart_pfn, highend_pfn;
+
+extern pte_t *kmap_pte;
+extern pgprot_t kmap_prot;
+extern pte_t *pkmap_page_table;
+
+extern void __init kmap_init(void);
+
+/*
+ * Right now we initialize only a single pte table. It can be extended
+ * easily, subsequent pte tables have to be allocated in one physical
+ * chunk of RAM.
+ */
+#define PKMAP_BASE     0xfe000000UL
+#define LAST_PKMAP     1024
+#define LAST_PKMAP_MASK (LAST_PKMAP - 1)
+#define PKMAP_NR(virt)  ((virt - PKMAP_BASE) >> PAGE_SHIFT)
+#define PKMAP_ADDR(nr)  (PKMAP_BASE + ((nr) << PAGE_SHIFT))
+
+extern unsigned long __fastcall kmap_high(struct page *page);
+extern void __fastcall kunmap_high(struct page *page);
+
+static inline unsigned long kmap(struct page *page)
+{
+       if (in_interrupt())
+               BUG();
+       if (page < highmem_start_page)
+               return page_address(page);
+       return kmap_high(page);
+}
+
+static inline void kunmap(struct page *page)
+{
+       if (in_interrupt())
+               BUG();
+       if (page < highmem_start_page)
+               return;
+       kunmap_high(page);
+}
+
+/*
+ * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
+ * gives a more generic (and caching) interface. But kmap_atomic can
+ * be used in IRQ contexts, so in some (very limited) cases we need
+ * it.
+ */
+static inline unsigned long kmap_atomic(struct page *page, enum km_type type)
+{
+       enum fixed_addresses idx;
+       unsigned long vaddr;
+
+       if (page < highmem_start_page)
+               return page_address(page);
+
+       idx = type + KM_TYPE_NR * smp_processor_id();
+       vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
+#if HIGHMEM_DEBUG
+       if (!pte_none(*(kmap_pte - idx)))
+               BUG();
+#endif
+       set_pte(kmap_pte - idx, mk_pte(page, kmap_prot));
+       __flush_tlb_one(vaddr);
+
+       return vaddr;
+}
+
+static inline void kunmap_atomic(unsigned long vaddr, enum km_type type)
+{
+#if HIGHMEM_DEBUG
+       enum fixed_addresses idx = type + KM_TYPE_NR * smp_processor_id();
+
+       if (vaddr < FIXADDR_START) /* FIXME */
+               return;
+
+       if (vaddr != __fix_to_virt(FIX_KMAP_BEGIN + idx))
+               BUG();
+
+       /*
+        * force other mappings to Oops if they'll try to access
+        * this pte without first remap it
+        */
+       pte_clear(kmap_pte - idx);
+       __flush_tlb_one(vaddr);
+#endif
+}
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_HIGHMEM_H */
diff --git a/include/asm-mn10300/hw_irq.h b/include/asm-mn10300/hw_irq.h
new file mode 100644 (file)
index 0000000..7061990
--- /dev/null
@@ -0,0 +1,14 @@
+/* MN10300 Hardware interrupt definitions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_HW_IRQ_H
+#define _ASM_HW_IRQ_H
+
+#endif /* _ASM_HW_IRQ_H */
diff --git a/include/asm-mn10300/ide.h b/include/asm-mn10300/ide.h
new file mode 100644 (file)
index 0000000..dc23512
--- /dev/null
@@ -0,0 +1,43 @@
+/* MN10300 Arch-specific IDE code
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ * - Derived from include/asm-i386/ide.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_IDE_H
+#define _ASM_IDE_H
+
+#ifdef __KERNEL__
+
+#include <asm/intctl-regs.h>
+
+#undef SUPPORT_SLOW_DATA_PORTS
+#define SUPPORT_SLOW_DATA_PORTS 0
+
+#undef SUPPORT_VLB_SYNC
+#define SUPPORT_VLB_SYNC 0
+
+#ifndef MAX_HWIFS
+#define MAX_HWIFS 8
+#endif
+
+/*
+ * some bits needed for parts of the IDE subsystem to compile
+ */
+#define __ide_mm_insw(port, addr, n) \
+       insw((unsigned long) (port), (addr), (n))
+#define __ide_mm_insl(port, addr, n) \
+       insl((unsigned long) (port), (addr), (n))
+#define __ide_mm_outsw(port, addr, n) \
+       outsw((unsigned long) (port), (addr), (n))
+#define __ide_mm_outsl(port, addr, n) \
+       outsl((unsigned long) (port), (addr), (n))
+
+#endif /* __KERNEL__ */
+#endif /* _ASM_IDE_H */
diff --git a/include/asm-mn10300/intctl-regs.h b/include/asm-mn10300/intctl-regs.h
new file mode 100644 (file)
index 0000000..ba544c7
--- /dev/null
@@ -0,0 +1,73 @@
+/* MN10300 On-board interrupt controller registers
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_INTCTL_REGS_H
+#define _ASM_INTCTL_REGS_H
+
+#include <asm/cpu-regs.h>
+
+#ifdef __KERNEL__
+
+/* interrupt controller registers */
+#define GxICR(X)               __SYSREG(0xd4000000 + (X) * 4, u16)     /* group irq ctrl regs */
+
+#define IAGR                   __SYSREG(0xd4000100, u16)       /* intr acceptance group reg */
+#define IAGR_GN                        0x00fc          /* group number register
+                                                * (documentation _has_ to be wrong)
+                                                */
+
+#define EXTMD                  __SYSREG(0xd4000200, u16)       /* external pin intr spec reg */
+#define GET_XIRQ_TRIGGER(X) ((EXTMD >> ((X) * 2)) & 3)
+
+#define SET_XIRQ_TRIGGER(X,Y)                  \
+do {                                           \
+       u16 x = EXTMD;                          \
+       x &= ~(3 << ((X) * 2));                 \
+       x |= ((Y) & 3) << ((X) * 2);            \
+       EXTMD = x;                              \
+} while (0)
+
+#define XIRQ_TRIGGER_LOWLEVEL  0
+#define XIRQ_TRIGGER_HILEVEL   1
+#define XIRQ_TRIGGER_NEGEDGE   2
+#define XIRQ_TRIGGER_POSEDGE   3
+
+/* non-maskable interrupt control */
+#define NMIIRQ                 0
+#define NMICR                  GxICR(NMIIRQ)   /* NMI control register */
+#define NMICR_NMIF             0x0001          /* NMI pin interrupt flag */
+#define NMICR_WDIF             0x0002          /* watchdog timer overflow flag */
+#define NMICR_ABUSERR          0x0008          /* async bus error flag */
+
+/* maskable interrupt control */
+#define GxICR_DETECT           0x0001          /* interrupt detect flag */
+#define GxICR_REQUEST          0x0010          /* interrupt request flag */
+#define GxICR_ENABLE           0x0100          /* interrupt enable flag */
+#define GxICR_LEVEL            0x7000          /* interrupt priority level */
+#define GxICR_LEVEL_0          0x0000          /* - level 0 */
+#define GxICR_LEVEL_1          0x1000          /* - level 1 */
+#define GxICR_LEVEL_2          0x2000          /* - level 2 */
+#define GxICR_LEVEL_3          0x3000          /* - level 3 */
+#define GxICR_LEVEL_4          0x4000          /* - level 4 */
+#define GxICR_LEVEL_5          0x5000          /* - level 5 */
+#define GxICR_LEVEL_6          0x6000          /* - level 6 */
+#define GxICR_LEVEL_SHIFT      12
+
+#ifndef __ASSEMBLY__
+extern void set_intr_level(int irq, u16 level);
+extern void set_intr_postackable(int irq);
+#endif
+
+/* external interrupts */
+#define XIRQxICR(X)            GxICR((X))      /* external interrupt control regs */
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_INTCTL_REGS_H */
diff --git a/include/asm-mn10300/io.h b/include/asm-mn10300/io.h
new file mode 100644 (file)
index 0000000..b8b6dc8
--- /dev/null
@@ -0,0 +1,299 @@
+/* MN10300 I/O port emulation and memory-mapped I/O
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_IO_H
+#define _ASM_IO_H
+
+#include <asm/page.h> /* I/O is all done through memory accesses */
+#include <asm/cpu-regs.h>
+#include <asm/cacheflush.h>
+
+#define mmiowb() do {} while (0)
+
+/*****************************************************************************/
+/*
+ * readX/writeX() are used to access memory mapped devices. On some
+ * architectures the memory mapped IO stuff needs to be accessed
+ * differently. On the x86 architecture, we just read/write the
+ * memory location directly.
+ */
+static inline u8 readb(const volatile void __iomem *addr)
+{
+       return *(const volatile u8 *) addr;
+}
+
+static inline u16 readw(const volatile void __iomem *addr)
+{
+       return *(const volatile u16 *) addr;
+}
+
+static inline u32 readl(const volatile void __iomem *addr)
+{
+       return *(const volatile u32 *) addr;
+}
+
+#define __raw_readb readb
+#define __raw_readw readw
+#define __raw_readl readl
+
+#define readb_relaxed readb
+#define readw_relaxed readw
+#define readl_relaxed readl
+
+static inline void writeb(u8 b, volatile void __iomem *addr)
+{
+       *(volatile u8 *) addr = b;
+}
+
+static inline void writew(u16 b, volatile void __iomem *addr)
+{
+       *(volatile u16 *) addr = b;
+}
+
+static inline void writel(u32 b, volatile void __iomem *addr)
+{
+       *(volatile u32 *) addr = b;
+}
+
+#define __raw_writeb writeb
+#define __raw_writew writew
+#define __raw_writel writel
+
+/*****************************************************************************/
+/*
+ * traditional input/output functions
+ */
+static inline u8 inb_local(unsigned long addr)
+{
+       return readb((volatile void __iomem *) addr);
+}
+
+static inline void outb_local(u8 b, unsigned long addr)
+{
+       return writeb(b, (volatile void __iomem *) addr);
+}
+
+static inline u8 inb(unsigned long addr)
+{
+       return readb((volatile void __iomem *) addr);
+}
+
+static inline u16 inw(unsigned long addr)
+{
+       return readw((volatile void __iomem *) addr);
+}
+
+static inline u32 inl(unsigned long addr)
+{
+       return readl((volatile void __iomem *) addr);
+}
+
+static inline void outb(u8 b, unsigned long addr)
+{
+       return writeb(b, (volatile void __iomem *) addr);
+}
+
+static inline void outw(u16 b, unsigned long addr)
+{
+       return writew(b, (volatile void __iomem *) addr);
+}
+
+static inline void outl(u32 b, unsigned long addr)
+{
+       return writel(b, (volatile void __iomem *) addr);
+}
+
+#define inb_p(addr)    inb(addr)
+#define inw_p(addr)    inw(addr)
+#define inl_p(addr)    inl(addr)
+#define outb_p(x, addr)        outb((x), (addr))
+#define outw_p(x, addr)        outw((x), (addr))
+#define outl_p(x, addr)        outl((x), (addr))
+
+static inline void insb(unsigned long addr, void *buffer, int count)
+{
+       if (count) {
+               u8 *buf = buffer;
+               do {
+                       u8 x = inb(addr);
+                       *buf++ = x;
+               } while (--count);
+       }
+}
+
+static inline void insw(unsigned long addr, void *buffer, int count)
+{
+       if (count) {
+               u16 *buf = buffer;
+               do {
+                       u16 x = inw(addr);
+                       *buf++ = x;
+               } while (--count);
+       }
+}
+
+static inline void insl(unsigned long addr, void *buffer, int count)
+{
+       if (count) {
+               u32 *buf = buffer;
+               do {
+                       u32 x = inl(addr);
+                       *buf++ = x;
+               } while (--count);
+       }
+}
+
+static inline void outsb(unsigned long addr, const void *buffer, int count)
+{
+       if (count) {
+               const u8 *buf = buffer;
+               do {
+                       outb(*buf++, addr);
+               } while (--count);
+       }
+}
+
+static inline void outsw(unsigned long addr, const void *buffer, int count)
+{
+       if (count) {
+               const u16 *buf = buffer;
+               do {
+                       outw(*buf++, addr);
+               } while (--count);
+       }
+}
+
+extern void __outsl(unsigned long addr, const void *buffer, int count);
+static inline void outsl(unsigned long addr, const void *buffer, int count)
+{
+       if ((unsigned long) buffer & 0x3)
+               return __outsl(addr, buffer, count);
+
+       if (count) {
+               const u32 *buf = buffer;
+               do {
+                       outl(*buf++, addr);
+               } while (--count);
+       }
+}
+
+#define ioread8(addr)          readb(addr)
+#define ioread16(addr)         readw(addr)
+#define ioread32(addr)         readl(addr)
+
+#define iowrite8(v, addr)      writeb((v), (addr))
+#define iowrite16(v, addr)     writew((v), (addr))
+#define iowrite32(v, addr)     writel((v), (addr))
+
+#define ioread8_rep(p, dst, count) \
+       insb((unsigned long) (p), (dst), (count))
+#define ioread16_rep(p, dst, count) \
+       insw((unsigned long) (p), (dst), (count))
+#define ioread32_rep(p, dst, count) \
+       insl((unsigned long) (p), (dst), (count))
+
+#define iowrite8_rep(p, src, count) \
+       outsb((unsigned long) (p), (src), (count))
+#define iowrite16_rep(p, src, count) \
+       outsw((unsigned long) (p), (src), (count))
+#define iowrite32_rep(p, src, count) \
+       outsl((unsigned long) (p), (src), (count))
+
+
+#define IO_SPACE_LIMIT 0xffffffff
+
+#ifdef __KERNEL__
+
+#include <linux/vmalloc.h>
+#define __io_virt(x) ((void *) (x))
+
+/* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
+struct pci_dev;
+extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
+static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
+{
+}
+
+/*
+ * Change virtual addresses to physical addresses and vv.
+ * These are pretty trivial
+ */
+static inline unsigned long virt_to_phys(volatile void *address)
+{
+       return __pa(address);
+}
+
+static inline void *phys_to_virt(unsigned long address)
+{
+       return __va(address);
+}
+
+/*
+ * Change "struct page" to physical address.
+ */
+static inline void *__ioremap(unsigned long offset, unsigned long size,
+                             unsigned long flags)
+{
+       return (void *) offset;
+}
+
+static inline void *ioremap(unsigned long offset, unsigned long size)
+{
+       return (void *) offset;
+}
+
+/*
+ * This one maps high address device memory and turns off caching for that
+ * area.  it's useful if some control registers are in such an area and write
+ * combining or read caching is not desirable:
+ */
+static inline void *ioremap_nocache(unsigned long offset, unsigned long size)
+{
+       return (void *) (offset | 0x20000000);
+}
+
+static inline void iounmap(void *addr)
+{
+}
+
+static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
+{
+       return (void __iomem *) port;
+}
+
+static inline void ioport_unmap(void __iomem *p)
+{
+}
+
+#define xlate_dev_kmem_ptr(p)  ((void *) (p))
+#define xlate_dev_mem_ptr(p)   ((void *) (p))
+
+/*
+ * PCI bus iomem addresses must be in the region 0x80000000-0x9fffffff
+ */
+static inline unsigned long virt_to_bus(volatile void *address)
+{
+       return ((unsigned long) address) & ~0x20000000;
+}
+
+static inline void *bus_to_virt(unsigned long address)
+{
+       return (void *) address;
+}
+
+#define page_to_bus page_to_phys
+
+#define memset_io(a, b, c)     memset(__io_virt(a), (b), (c))
+#define memcpy_fromio(a, b, c) memcpy((a), __io_virt(b), (c))
+#define memcpy_toio(a, b, c)   memcpy(__io_virt(a), (b), (c))
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_IO_H */
diff --git a/include/asm-mn10300/ioctl.h b/include/asm-mn10300/ioctl.h
new file mode 100644 (file)
index 0000000..b279fe0
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/ioctl.h>
diff --git a/include/asm-mn10300/ioctls.h b/include/asm-mn10300/ioctls.h
new file mode 100644 (file)
index 0000000..dcbfb45
--- /dev/null
@@ -0,0 +1,88 @@
+#ifndef _ASM_IOCTLS_H
+#define _ASM_IOCTLS_H
+
+#include <asm/ioctl.h>
+
+/* 0x54 is just a magic number to make these relatively unique ('T') */
+
+#define TCGETS         0x5401
+#define TCSETS         0x5402
+#define TCSETSW                0x5403
+#define TCSETSF                0x5404
+#define TCGETA         0x5405
+#define TCSETA         0x5406
+#define TCSETAW                0x5407
+#define TCSETAF                0x5408
+#define TCSBRK         0x5409
+#define TCXONC         0x540A
+#define TCFLSH         0x540B
+#define TIOCEXCL       0x540C
+#define TIOCNXCL       0x540D
+#define TIOCSCTTY      0x540E
+#define TIOCGPGRP      0x540F
+#define TIOCSPGRP      0x5410
+#define TIOCOUTQ       0x5411
+#define TIOCSTI                0x5412
+#define TIOCGWINSZ     0x5413
+#define TIOCSWINSZ     0x5414
+#define TIOCMGET       0x5415
+#define TIOCMBIS       0x5416
+#define TIOCMBIC       0x5417
+#define TIOCMSET       0x5418
+#define TIOCGSOFTCAR   0x5419
+#define TIOCSSOFTCAR   0x541A
+#define FIONREAD       0x541B
+#define TIOCINQ                FIONREAD
+#define TIOCLINUX      0x541C
+#define TIOCCONS       0x541D
+#define TIOCGSERIAL    0x541E
+#define TIOCSSERIAL    0x541F
+#define TIOCPKT                0x5420
+#define FIONBIO                0x5421
+#define TIOCNOTTY      0x5422
+#define TIOCSETD       0x5423
+#define TIOCGETD       0x5424
+#define TCSBRKP                0x5425  /* Needed for POSIX tcsendbreak() */
+/* #define TIOCTTYGSTRUCT 0x5426 - Former debugging-only ioctl */
+#define TIOCSBRK       0x5427  /* BSD compatibility */
+#define TIOCCBRK       0x5428  /* BSD compatibility */
+#define TIOCGSID       0x5429  /* Return the session ID of FD */
+#define TCGETS2                _IOR('T', 0x2A, struct termios2)
+#define TCSETS2                _IOW('T', 0x2B, struct termios2)
+#define TCSETSW2       _IOW('T', 0x2C, struct termios2)
+#define TCSETSF2       _IOW('T', 0x2D, struct termios2)
+#define TIOCGPTN       _IOR('T', 0x30, unsigned int) /* Get Pty Number
+                                                      * (of pty-mux device) */
+#define TIOCSPTLCK     _IOW('T', 0x31, int)  /* Lock/unlock Pty */
+
+#define FIONCLEX       0x5450
+#define FIOCLEX                0x5451
+#define FIOASYNC       0x5452
+#define TIOCSERCONFIG  0x5453
+#define TIOCSERGWILD   0x5454
+#define TIOCSERSWILD   0x5455
+#define TIOCGLCKTRMIOS 0x5456
+#define TIOCSLCKTRMIOS 0x5457
+#define TIOCSERGSTRUCT 0x5458 /* For debugging only */
+#define TIOCSERGETLSR   0x5459 /* Get line status register */
+#define TIOCSERGETMULTI 0x545A /* Get multiport config  */
+#define TIOCSERSETMULTI 0x545B /* Set multiport config */
+
+#define TIOCMIWAIT     0x545C  /* wait for a change on serial input line(s) */
+#define TIOCGICOUNT    0x545D  /* read serial port inline interrupt counts */
+#define TIOCGHAYESESP   0x545E  /* Get Hayes ESP configuration */
+#define TIOCSHAYESESP   0x545F  /* Set Hayes ESP configuration */
+#define FIOQSIZE       0x5460
+
+/* Used for packet mode */
+#define TIOCPKT_DATA            0
+#define TIOCPKT_FLUSHREAD       1
+#define TIOCPKT_FLUSHWRITE      2
+#define TIOCPKT_STOP            4
+#define TIOCPKT_START           8
+#define TIOCPKT_NOSTOP         16
+#define TIOCPKT_DOSTOP         32
+
+#define TIOCSER_TEMT    0x01   /* Transmitter physically empty */
+
+#endif /* _ASM_IOCTLS_H */
diff --git a/include/asm-mn10300/ipc.h b/include/asm-mn10300/ipc.h
new file mode 100644 (file)
index 0000000..a46e3d9
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/ipc.h>
diff --git a/include/asm-mn10300/ipcbuf.h b/include/asm-mn10300/ipcbuf.h
new file mode 100644 (file)
index 0000000..efbbef8
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef _ASM_IPCBUF_H_
+#define _ASM_IPCBUF_H
+
+/*
+ * The ipc64_perm structure for MN10300 architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 32-bit mode_t and seq
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct ipc64_perm
+{
+       __kernel_key_t          key;
+       __kernel_uid32_t        uid;
+       __kernel_gid32_t        gid;
+       __kernel_uid32_t        cuid;
+       __kernel_gid32_t        cgid;
+       __kernel_mode_t         mode;
+       unsigned short          __pad1;
+       unsigned short          seq;
+       unsigned short          __pad2;
+       unsigned long           __unused1;
+       unsigned long           __unused2;
+};
+
+#endif /* _ASM_IPCBUF_H */
diff --git a/include/asm-mn10300/irq.h b/include/asm-mn10300/irq.h
new file mode 100644 (file)
index 0000000..53b3801
--- /dev/null
@@ -0,0 +1,32 @@
+/* MN10300 Hardware interrupt definitions
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Modified by David Howells (dhowells@redhat.com)
+ * - Derived from include/asm-i386/irq.h:
+ *   - (C) 1992, 1993 Linus Torvalds, (C) 1997 Ingo Molnar
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_IRQ_H
+#define _ASM_IRQ_H
+
+#include <asm/intctl-regs.h>
+#include <asm/reset-regs.h>
+#include <asm/proc/irq.h>
+
+/* this number is used when no interrupt has been assigned */
+#define NO_IRQ         INT_MAX
+
+/* hardware irq numbers */
+#define NR_IRQS                GxICR_NUM_IRQS
+
+/* external hardware irq numbers */
+#define NR_XIRQS       GxICR_NUM_XIRQS
+
+#define irq_canonicalize(IRQ) (IRQ)
+
+#endif /* _ASM_IRQ_H */
diff --git a/include/asm-mn10300/irq_regs.h b/include/asm-mn10300/irq_regs.h
new file mode 100644 (file)
index 0000000..a848cd2
--- /dev/null
@@ -0,0 +1,24 @@
+/* MN10300 IRQ registers pointer definition
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_IRQ_REGS_H
+#define _ASM_IRQ_REGS_H
+
+/*
+ * Per-cpu current frame pointer - the location of the last exception frame on
+ * the stack
+ */
+#define ARCH_HAS_OWN_IRQ_REGS
+
+#ifndef __ASSEMBLY__
+#define get_irq_regs() (__frame)
+#endif
+
+#endif /* _ASM_IRQ_REGS_H */
diff --git a/include/asm-mn10300/kdebug.h b/include/asm-mn10300/kdebug.h
new file mode 100644 (file)
index 0000000..0f47e11
--- /dev/null
@@ -0,0 +1,22 @@
+/* MN10300 In-kernel death knells
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_KDEBUG_H
+#define _ASM_KDEBUG_H
+
+/* Grossly misnamed. */
+enum die_val {
+       DIE_OOPS = 1,
+       DIE_BREAKPOINT,
+       DIE_GPF,
+};
+
+#endif /* _ASM_KDEBUG_H */
diff --git a/include/asm-mn10300/kmap_types.h b/include/asm-mn10300/kmap_types.h
new file mode 100644 (file)
index 0000000..3398f9f
--- /dev/null
@@ -0,0 +1,31 @@
+/* MN10300 kmap_atomic() slot IDs
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_KMAP_TYPES_H
+#define _ASM_KMAP_TYPES_H
+
+enum km_type {
+       KM_BOUNCE_READ,
+       KM_SKB_SUNRPC_DATA,
+       KM_SKB_DATA_SOFTIRQ,
+       KM_USER0,
+       KM_USER1,
+       KM_BIO_SRC_IRQ,
+       KM_BIO_DST_IRQ,
+       KM_PTE0,
+       KM_PTE1,
+       KM_IRQ0,
+       KM_IRQ1,
+       KM_SOFTIRQ0,
+       KM_SOFTIRQ1,
+       KM_TYPE_NR
+};
+
+#endif /* _ASM_KMAP_TYPES_H */
diff --git a/include/asm-mn10300/kprobes.h b/include/asm-mn10300/kprobes.h
new file mode 100644 (file)
index 0000000..c800b59
--- /dev/null
@@ -0,0 +1,50 @@
+/* MN10300 Kernel Probes support
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by Mark Salter (msalter@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public Licence as published by
+ * the Free Software Foundation; either version 2 of the Licence, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public Licence for more details.
+ *
+ * You should have received a copy of the GNU General Public Licence
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+#ifndef _ASM_KPROBES_H
+#define _ASM_KPROBES_H
+
+#include <linux/types.h>
+#include <linux/ptrace.h>
+
+struct kprobe;
+
+typedef unsigned char kprobe_opcode_t;
+#define BREAKPOINT_INSTRUCTION 0xff
+#define MAX_INSN_SIZE 8
+#define MAX_STACK_SIZE 128
+
+/* Architecture specific copy of original instruction */
+struct arch_specific_insn {
+       /*  copy of original instruction
+        */
+       kprobe_opcode_t insn[MAX_INSN_SIZE];
+};
+
+extern const int kretprobe_blacklist_size;
+
+extern int kprobe_exceptions_notify(struct notifier_block *self,
+                                   unsigned long val, void *data);
+
+#define flush_insn_slot(p)  do {} while (0)
+
+extern void arch_remove_kprobe(struct kprobe *p);
+
+#endif /* _ASM_KPROBES_H */
diff --git a/include/asm-mn10300/linkage.h b/include/asm-mn10300/linkage.h
new file mode 100644 (file)
index 0000000..29a32e4
--- /dev/null
@@ -0,0 +1,22 @@
+/* MN10300 Linkage and calling-convention overrides
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_LINKAGE_H
+#define _ASM_LINKAGE_H
+
+/* don't override anything */
+#define asmlinkage
+#define FASTCALL(x) x
+#define fastcall
+
+#define __ALIGN                .align 4,0xcb
+#define __ALIGN_STR    ".align 4,0xcb"
+
+#endif
diff --git a/include/asm-mn10300/local.h b/include/asm-mn10300/local.h
new file mode 100644 (file)
index 0000000..c11c530
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/local.h>
diff --git a/include/asm-mn10300/mc146818rtc.h b/include/asm-mn10300/mc146818rtc.h
new file mode 100644 (file)
index 0000000..df6bc6e
--- /dev/null
@@ -0,0 +1 @@
+#include <asm/rtc-regs.h>
diff --git a/include/asm-mn10300/mman.h b/include/asm-mn10300/mman.h
new file mode 100644 (file)
index 0000000..b7986b6
--- /dev/null
@@ -0,0 +1,28 @@
+/* MN10300 Constants for mmap and co.
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * - Derived from asm-x86/mman.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_MMAN_H
+#define _ASM_MMAN_H
+
+#include <asm-generic/mman.h>
+
+#define MAP_GROWSDOWN  0x0100          /* stack-like segment */
+#define MAP_DENYWRITE  0x0800          /* ETXTBSY */
+#define MAP_EXECUTABLE 0x1000          /* mark it as an executable */
+#define MAP_LOCKED     0x2000          /* pages are locked */
+#define MAP_NORESERVE  0x4000          /* don't check for reservations */
+#define MAP_POPULATE   0x8000          /* populate (prefault) pagetables */
+#define MAP_NONBLOCK   0x10000         /* do not block on IO */
+
+#define MCL_CURRENT    1               /* lock all current mappings */
+#define MCL_FUTURE     2               /* lock all future mappings */
+
+#endif /* _ASM_MMAN_H */
diff --git a/include/asm-mn10300/mmu.h b/include/asm-mn10300/mmu.h
new file mode 100644 (file)
index 0000000..2d2d097
--- /dev/null
@@ -0,0 +1,19 @@
+/* MN10300 Memory management context
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ * - Derived from include/asm-frv/mmu.h
+ */
+
+#ifndef _ASM_MMU_H
+#define _ASM_MMU_H
+
+/*
+ * MMU context
+ */
+typedef struct {
+       unsigned long   tlbpid[NR_CPUS];        /* TLB PID for this process on
+                                                * each CPU */
+} mm_context_t;
+
+#endif /* _ASM_MMU_H */
diff --git a/include/asm-mn10300/mmu_context.h b/include/asm-mn10300/mmu_context.h
new file mode 100644 (file)
index 0000000..a9e2e34
--- /dev/null
@@ -0,0 +1,138 @@
+/* MN10300 MMU context management
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Modified by David Howells (dhowells@redhat.com)
+ * - Derived from include/asm-m32r/mmu_context.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ *
+ *
+ * This implements an algorithm to provide TLB PID mappings to provide
+ * selective access to the TLB for processes, thus reducing the number of TLB
+ * flushes required.
+ *
+ * Note, however, that the M32R algorithm is technically broken as it does not
+ * handle version wrap-around, and could, theoretically, have a problem with a
+ * very long lived program that sleeps long enough for the version number to
+ * wrap all the way around so that its TLB mappings appear valid once again.
+ */
+#ifndef _ASM_MMU_CONTEXT_H
+#define _ASM_MMU_CONTEXT_H
+
+#include <asm/atomic.h>
+#include <asm/pgalloc.h>
+#include <asm/tlbflush.h>
+#include <asm-generic/mm_hooks.h>
+
+#define MMU_CONTEXT_TLBPID_MASK                0x000000ffUL
+#define MMU_CONTEXT_VERSION_MASK       0xffffff00UL
+#define MMU_CONTEXT_FIRST_VERSION      0x00000100UL
+#define MMU_NO_CONTEXT                 0x00000000UL
+
+extern unsigned long mmu_context_cache[NR_CPUS];
+#define mm_context(mm) (mm->context.tlbpid[smp_processor_id()])
+
+#define enter_lazy_tlb(mm, tsk)        do {} while (0)
+
+#ifdef CONFIG_SMP
+#define cpu_ran_vm(cpu, task) \
+       cpu_set((cpu), (task)->cpu_vm_mask)
+#define cpu_maybe_ran_vm(cpu, task) \
+       cpu_test_and_set((cpu), (task)->cpu_vm_mask)
+#else
+#define cpu_ran_vm(cpu, task)          do {} while (0)
+#define cpu_maybe_ran_vm(cpu, task)    true
+#endif /* CONFIG_SMP */
+
+/*
+ * allocate an MMU context
+ */
+static inline unsigned long allocate_mmu_context(struct mm_struct *mm)
+{
+       unsigned long *pmc = &mmu_context_cache[smp_processor_id()];
+       unsigned long mc = ++(*pmc);
+
+       if (!(mc & MMU_CONTEXT_TLBPID_MASK)) {
+               /* we exhausted the TLB PIDs of this version on this CPU, so we
+                * flush this CPU's TLB in its entirety and start new cycle */
+               flush_tlb_all();
+
+               /* fix the TLB version if needed (we avoid version #0 so as to
+                * distingush MMU_NO_CONTEXT) */
+               if (!mc)
+                       *pmc = mc = MMU_CONTEXT_FIRST_VERSION;
+       }
+       mm_context(mm) = mc;
+       return mc;
+}
+
+/*
+ * get an MMU context if one is needed
+ */
+static inline unsigned long get_mmu_context(struct mm_struct *mm)
+{
+       unsigned long mc = MMU_NO_CONTEXT, cache;
+
+       if (mm) {
+               cache = mmu_context_cache[smp_processor_id()];
+               mc = mm_context(mm);
+
+               /* if we have an old version of the context, replace it */
+               if ((mc ^ cache) & MMU_CONTEXT_VERSION_MASK)
+                       mc = allocate_mmu_context(mm);
+       }
+       return mc;
+}
+
+/*
+ * initialise the context related info for a new mm_struct instance
+ */
+static inline int init_new_context(struct task_struct *tsk,
+                                  struct mm_struct *mm)
+{
+       int num_cpus = NR_CPUS, i;
+
+       for (i = 0; i < num_cpus; i++)
+               mm->context.tlbpid[i] = MMU_NO_CONTEXT;
+       return 0;
+}
+
+/*
+ * destroy context related info for an mm_struct that is about to be put to
+ * rest
+ */
+#define destroy_context(mm)    do { } while (0)
+
+/*
+ * after we have set current->mm to a new value, this activates the context for
+ * the new mm so we see the new mappings.
+ */
+static inline void activate_context(struct mm_struct *mm, int cpu)
+{
+       PIDR = get_mmu_context(mm) & MMU_CONTEXT_TLBPID_MASK;
+}
+
+/*
+ * change between virtual memory sets
+ */
+static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
+                            struct task_struct *tsk)
+{
+       int cpu = smp_processor_id();
+
+       if (prev != next) {
+               cpu_ran_vm(cpu, next);
+               activate_context(next, cpu);
+               PTBR = (unsigned long) next->pgd;
+       } else if (!cpu_maybe_ran_vm(cpu, next)) {
+               activate_context(next, cpu);
+       }
+}
+
+#define deactivate_mm(tsk, mm) do {} while (0)
+#define activate_mm(prev, next)        switch_mm((prev), (next), NULL)
+
+#endif /* _ASM_MMU_CONTEXT_H */
diff --git a/include/asm-mn10300/module.h b/include/asm-mn10300/module.h
new file mode 100644 (file)
index 0000000..5d7057d
--- /dev/null
@@ -0,0 +1,27 @@
+/* MN10300 Arch-specific module definitions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by Mark Salter (msalter@redhat.com)
+ * Derived from include/asm-i386/module.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_MODULE_H
+#define _ASM_MODULE_H
+
+struct mod_arch_specific {
+};
+
+#define Elf_Shdr       Elf32_Shdr
+#define Elf_Sym                Elf32_Sym
+#define Elf_Ehdr       Elf32_Ehdr
+
+/*
+ * Include the MN10300 architecture version.
+ */
+#define MODULE_ARCH_VERMAGIC __stringify(PROCESSOR_MODEL_NAME) " "
+
+#endif /* _ASM_MODULE_H */
diff --git a/include/asm-mn10300/msgbuf.h b/include/asm-mn10300/msgbuf.h
new file mode 100644 (file)
index 0000000..8b60245
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef _ASM_MSGBUF_H
+#define _ASM_MSGBUF_H
+
+/*
+ * The msqid64_ds structure for MN10300 architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 64-bit time_t to solve y2038 problem
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct msqid64_ds {
+       struct ipc64_perm       msg_perm;
+       __kernel_time_t         msg_stime;      /* last msgsnd time */
+       unsigned long           __unused1;
+       __kernel_time_t         msg_rtime;      /* last msgrcv time */
+       unsigned long           __unused2;
+       __kernel_time_t         msg_ctime;      /* last change time */
+       unsigned long           __unused3;
+       unsigned long           msg_cbytes;     /* current number of bytes on queue */
+       unsigned long           msg_qnum;       /* number of messages in queue */
+       unsigned long           msg_qbytes;     /* max number of bytes on queue */
+       __kernel_pid_t          msg_lspid;      /* pid of last msgsnd */
+       __kernel_pid_t          msg_lrpid;      /* last receive pid */
+       unsigned long           __unused4;
+       unsigned long           __unused5;
+};
+
+#endif /* _ASM_MSGBUF_H */
diff --git a/include/asm-mn10300/mutex.h b/include/asm-mn10300/mutex.h
new file mode 100644 (file)
index 0000000..84f5490
--- /dev/null
@@ -0,0 +1,16 @@
+/* MN10300 Mutex fastpath
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ *
+ *
+ * TODO: implement optimized primitives instead, or leave the generic
+ * implementation in place, or pick the atomic_xchg() based generic
+ * implementation. (see asm-generic/mutex-xchg.h for details)
+ */
+#include <asm-generic/mutex-null.h>
diff --git a/include/asm-mn10300/namei.h b/include/asm-mn10300/namei.h
new file mode 100644 (file)
index 0000000..bd9ce94
--- /dev/null
@@ -0,0 +1,22 @@
+/* Emulation stuff
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_NAMEI_H
+#define _ASM_NAMEI_H
+
+/* This dummy routine maybe changed to something useful
+ * for /usr/gnemul/ emulation stuff.
+ * Look at asm-sparc/namei.h for details.
+ */
+
+#define __emul_prefix() NULL
+
+#endif /* _ASM_NAMEI_H */
diff --git a/include/asm-mn10300/nmi.h b/include/asm-mn10300/nmi.h
new file mode 100644 (file)
index 0000000..f3671cb
--- /dev/null
@@ -0,0 +1,14 @@
+/* MN10300 NMI handling
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_NMI_H
+#define _ASM_NMI_H
+
+#endif /* _ASM_NMI_H */
diff --git a/include/asm-mn10300/page.h b/include/asm-mn10300/page.h
new file mode 100644 (file)
index 0000000..124971b
--- /dev/null
@@ -0,0 +1,131 @@
+/* MN10300 Page table definitions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_PAGE_H
+#define _ASM_PAGE_H
+
+/* PAGE_SHIFT determines the page size */
+#define PAGE_SHIFT     12
+
+#ifndef __ASSEMBLY__
+#define PAGE_SIZE      (1UL << PAGE_SHIFT)
+#define PAGE_MASK      (~(PAGE_SIZE - 1))
+#else
+#define PAGE_SIZE      +(1 << PAGE_SHIFT)      /* unary plus marks an
+                                                * immediate val not an addr */
+#define PAGE_MASK      +(~(PAGE_SIZE - 1))
+#endif
+
+#ifdef __KERNEL__
+#ifndef __ASSEMBLY__
+
+#define clear_page(page)       memset((void *)(page), 0, PAGE_SIZE)
+#define copy_page(to, from)    memcpy((void *)(to), (void *)(from), PAGE_SIZE)
+
+#define clear_user_page(addr, vaddr, page)     clear_page(addr)
+#define copy_user_page(vto, vfrom, vaddr, to)  copy_page(vto, vfrom)
+
+/*
+ * These are used to make use of C type-checking..
+ */
+typedef struct { unsigned long pte; } pte_t;
+typedef struct { unsigned long pgd; } pgd_t;
+typedef struct { unsigned long pgprot; } pgprot_t;
+typedef struct page *pgtable_t;
+
+#define PTE_MASK       PAGE_MASK
+#define HPAGE_SHIFT    22
+
+#ifdef CONFIG_HUGETLB_PAGE
+#define HPAGE_SIZE             ((1UL) << HPAGE_SHIFT)
+#define HPAGE_MASK             (~(HPAGE_SIZE - 1))
+#define HUGETLB_PAGE_ORDER     (HPAGE_SHIFT - PAGE_SHIFT)
+#endif
+
+#define pte_val(x)     ((x).pte)
+#define pgd_val(x)     ((x).pgd)
+#define pgprot_val(x)  ((x).pgprot)
+
+#define __pte(x)       ((pte_t) { (x) })
+#define __pgd(x)       ((pgd_t) { (x) })
+#define __pgprot(x)    ((pgprot_t) { (x) })
+
+#include <asm-generic/pgtable-nopmd.h>
+
+#endif /* !__ASSEMBLY__ */
+
+/* to align the pointer to the (next) page boundary */
+#define PAGE_ALIGN(addr)       (((addr) + PAGE_SIZE - 1) & PAGE_MASK)
+
+/*
+ * This handles the memory map.. We could make this a config
+ * option, but too many people screw it up, and too few need
+ * it.
+ *
+ * A __PAGE_OFFSET of 0xC0000000 means that the kernel has
+ * a virtual address space of one gigabyte, which limits the
+ * amount of physical memory you can use to about 950MB.
+ */
+
+#ifndef __ASSEMBLY__
+
+/* Pure 2^n version of get_order */
+static inline int get_order(unsigned long size) __attribute__((const));
+static inline int get_order(unsigned long size)
+{
+       int order;
+
+       size = (size - 1) >> (PAGE_SHIFT - 1);
+       order = -1;
+       do {
+               size >>= 1;
+               order++;
+       } while (size);
+       return order;
+}
+
+#endif /* __ASSEMBLY__ */
+
+#include <asm/page_offset.h>
+
+#define __PAGE_OFFSET          (PAGE_OFFSET_RAW)
+#define PAGE_OFFSET            ((unsigned long) __PAGE_OFFSET)
+
+/*
+ * main RAM and kernel working space are coincident at 0x90000000, but to make
+ * life more interesting, there's also an uncached virtual shadow at 0xb0000000
+ * - these mappings are fixed in the MMU
+ */
+#define __pfn_disp             (CONFIG_KERNEL_RAM_BASE_ADDRESS >> PAGE_SHIFT)
+
+#define __pa(x)                        ((unsigned long)(x))
+#define __va(x)                        ((void *)(unsigned long)(x))
+#define pfn_to_kaddr(pfn)      __va((pfn) << PAGE_SHIFT)
+#define pfn_to_page(pfn)       (mem_map + ((pfn) - __pfn_disp))
+#define page_to_pfn(page)      ((unsigned long)((page) - mem_map) + __pfn_disp)
+
+#define pfn_valid(pfn)                                 \
+({                                                     \
+       unsigned long __pfn = (pfn) - __pfn_disp;       \
+       __pfn < max_mapnr;                              \
+})
+
+#define virt_to_page(kaddr)    pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
+#define virt_addr_valid(kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT)
+#define page_to_phys(page)     (page_to_pfn(page) << PAGE_SHIFT)
+
+#define VM_DATA_DEFAULT_FLAGS \
+       (VM_READ | VM_WRITE | \
+       ((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
+                VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_PAGE_H */
diff --git a/include/asm-mn10300/page_offset.h b/include/asm-mn10300/page_offset.h
new file mode 100644 (file)
index 0000000..8eb5b16
--- /dev/null
@@ -0,0 +1,11 @@
+/* MN10300 Kernel base address
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ */
+#ifndef _ASM_PAGE_OFFSET_H
+#define _ASM_PAGE_OFFSET_H
+
+#define PAGE_OFFSET_RAW CONFIG_KERNEL_RAM_BASE_ADDRESS
+
+#endif
diff --git a/include/asm-mn10300/param.h b/include/asm-mn10300/param.h
new file mode 100644 (file)
index 0000000..54b883e
--- /dev/null
@@ -0,0 +1,34 @@
+/* MN10300 Kernel parameters
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_PARAM_H
+#define _ASM_PARAM_H
+
+#ifdef __KERNEL__
+#define HZ             1000            /* Internal kernel timer frequency */
+#define USER_HZ                100             /* .. some user interfaces are in
+                                        * "ticks" */
+#define CLOCKS_PER_SEC (USER_HZ)       /* like times() */
+#endif
+
+#ifndef HZ
+#define HZ             100
+#endif
+
+#define EXEC_PAGESIZE  4096
+
+#ifndef NOGROUP
+#define NOGROUP                (-1)
+#endif
+
+#define MAXHOSTNAMELEN 64      /* max length of hostname */
+#define COMMAND_LINE_SIZE 256
+
+#endif /* _ASM_PARAM_H */
diff --git a/include/asm-mn10300/pci.h b/include/asm-mn10300/pci.h
new file mode 100644 (file)
index 0000000..205192c
--- /dev/null
@@ -0,0 +1,133 @@
+/* MN10300 PCI definitions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_PCI_H
+#define _ASM_PCI_H
+
+#ifdef __KERNEL__
+#include <linux/mm.h>          /* for struct page */
+
+#if 0
+#define __pcbdebug(FMT, ADDR, ...) \
+       printk(KERN_DEBUG "PCIBRIDGE[%08x]: "FMT"\n", \
+              (u32)(ADDR), ##__VA_ARGS__)
+
+#define __pcidebug(FMT, BUS, DEVFN, WHERE,...)         \
+do {                                                   \
+       printk(KERN_DEBUG "PCI[%02x:%02x.%x + %02x]: "FMT"\n",  \
+              (BUS)->number,                                   \
+              PCI_SLOT(DEVFN),                                 \
+              PCI_FUNC(DEVFN),                                 \
+              (u32)(WHERE), ##__VA_ARGS__);                    \
+} while (0)
+
+#else
+#define __pcbdebug(FMT, ADDR, ...)             do {} while (0)
+#define __pcidebug(FMT, BUS, DEVFN, WHERE, ...)        do {} while (0)
+#endif
+
+/* Can be used to override the logic in pci_scan_bus for skipping
+ * already-configured bus numbers - to be used for buggy BIOSes or
+ * architectures with incomplete PCI setup by the loader */
+
+#ifdef CONFIG_PCI
+#define pcibios_assign_all_busses()    1
+extern void unit_pci_init(void);
+#else
+#define pcibios_assign_all_busses()    0
+#endif
+
+extern unsigned long pci_mem_start;
+#define PCIBIOS_MIN_IO         0xBE000004
+#define PCIBIOS_MIN_MEM                0xB8000000
+
+void pcibios_set_master(struct pci_dev *dev);
+void pcibios_penalize_isa_irq(int irq);
+
+/* Dynamic DMA mapping stuff.
+ * i386 has everything mapped statically.
+ */
+
+#include <linux/types.h>
+#include <linux/slab.h>
+#include <asm/scatterlist.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <asm/io.h>
+
+struct pci_dev;
+
+/* The PCI address space does equal the physical memory
+ * address space.  The networking and block device layers use
+ * this boolean for bounce buffer decisions.
+ */
+#define PCI_DMA_BUS_IS_PHYS    (1)
+
+
+/* This is always fine. */
+#define pci_dac_dma_supported(pci_dev, mask)   (0)
+
+/*
+ * These macros should be used after a pci_map_sg call has been done
+ * to get bus addresses of each of the SG entries and their lengths.
+ * You should only work with the number of sg entries pci_map_sg
+ * returns.
+ */
+#define sg_dma_address(sg)     ((sg)->dma_address)
+#define sg_dma_len(sg)         ((sg)->length)
+
+/* Return the index of the PCI controller for device. */
+static inline int pci_controller_num(struct pci_dev *dev)
+{
+       return 0;
+}
+
+#define HAVE_PCI_MMAP
+extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
+                              enum pci_mmap_state mmap_state,
+                              int write_combine);
+
+#endif /* __KERNEL__ */
+
+/* implement the pci_ DMA API in terms of the generic device dma_ one */
+#include <asm-generic/pci-dma-compat.h>
+
+/**
+ * pcibios_resource_to_bus - convert resource to PCI bus address
+ * @dev: device which owns this resource
+ * @region: converted bus-centric region (start,end)
+ * @res: resource to convert
+ *
+ * Convert a resource to a PCI device bus address or bus window.
+ */
+extern void pcibios_resource_to_bus(struct pci_dev *dev,
+                                   struct pci_bus_region *region,
+                                   struct resource *res);
+
+extern void pcibios_bus_to_resource(struct pci_dev *dev,
+                                   struct resource *res,
+                                   struct pci_bus_region *region);
+
+static inline struct resource *
+pcibios_select_root(struct pci_dev *pdev, struct resource *res)
+{
+       struct resource *root = NULL;
+
+       if (res->flags & IORESOURCE_IO)
+               root = &ioport_resource;
+       if (res->flags & IORESOURCE_MEM)
+               root = &iomem_resource;
+
+       return root;
+}
+
+#define pcibios_scan_all_fns(a, b)     0
+
+#endif /* _ASM_PCI_H */
diff --git a/include/asm-mn10300/percpu.h b/include/asm-mn10300/percpu.h
new file mode 100644 (file)
index 0000000..06a959d
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/percpu.h>
diff --git a/include/asm-mn10300/pgalloc.h b/include/asm-mn10300/pgalloc.h
new file mode 100644 (file)
index 0000000..ec057e1
--- /dev/null
@@ -0,0 +1,56 @@
+/* MN10300 Page and page table/directory allocation
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_PGALLOC_H
+#define _ASM_PGALLOC_H
+
+#include <asm/processor.h>
+#include <asm/page.h>
+#include <linux/threads.h>
+#include <linux/mm.h>          /* for struct page */
+
+struct mm_struct;
+struct page;
+
+/* attach a page table to a PMD entry */
+#define pmd_populate_kernel(mm, pmd, pte) \
+       set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE))
+
+static inline
+void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte)
+{
+       set_pmd(pmd, __pmd((page_to_pfn(pte) << PAGE_SHIFT) | _PAGE_TABLE));
+}
+#define pmd_pgtable(pmd) pmd_page(pmd)
+
+/*
+ * Allocate and free page tables.
+ */
+
+extern pgd_t *pgd_alloc(struct mm_struct *);
+extern void pgd_free(struct mm_struct *, pgd_t *);
+
+extern pte_t *pte_alloc_one_kernel(struct mm_struct *, unsigned long);
+extern struct page *pte_alloc_one(struct mm_struct *, unsigned long);
+
+static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
+{
+       free_page((unsigned long) pte);
+}
+
+static inline void pte_free(struct mm_struct *mm, struct page *pte)
+{
+       __free_page(pte);
+}
+
+
+#define __pte_free_tlb(tlb, pte) tlb_remove_page((tlb), (pte))
+
+#endif /* _ASM_PGALLOC_H */
diff --git a/include/asm-mn10300/pgtable.h b/include/asm-mn10300/pgtable.h
new file mode 100644 (file)
index 0000000..375c494
--- /dev/null
@@ -0,0 +1,489 @@
+/* MN10300 Page table manipulators and constants
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ *
+ *
+ * The Linux memory management assumes a three-level page table setup. On
+ * the i386, we use that, but "fold" the mid level into the top-level page
+ * table, so that we physically have the same two-level page table as the
+ * i386 mmu expects.
+ *
+ * This file contains the functions and defines necessary to modify and use
+ * the i386 page table tree for the purposes of the MN10300 TLB handler
+ * functions.
+ */
+#ifndef _ASM_PGTABLE_H
+#define _ASM_PGTABLE_H
+
+#include <asm/cpu-regs.h>
+
+#ifndef __ASSEMBLY__
+#include <asm/processor.h>
+#include <asm/cache.h>
+#include <linux/threads.h>
+
+#include <asm/bitops.h>
+
+#include <linux/slab.h>
+#include <linux/list.h>
+#include <linux/spinlock.h>
+
+/*
+ * ZERO_PAGE is a global shared page that is always zero: used
+ * for zero-mapped memory areas etc..
+ */
+#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
+extern unsigned long empty_zero_page[1024];
+extern spinlock_t pgd_lock;
+extern struct page *pgd_list;
+
+extern void pmd_ctor(void *, struct kmem_cache *, unsigned long);
+extern void pgtable_cache_init(void);
+extern void paging_init(void);
+
+#endif /* !__ASSEMBLY__ */
+
+/*
+ * The Linux mn10300 paging architecture only implements both the traditional
+ * 2-level page tables
+ */
+#define PGDIR_SHIFT    22
+#define PTRS_PER_PGD   1024
+#define PTRS_PER_PUD   1       /* we don't really have any PUD physically */
+#define PTRS_PER_PMD   1       /* we don't really have any PMD physically */
+#define PTRS_PER_PTE   1024
+
+#define PGD_SIZE       PAGE_SIZE
+#define PMD_SIZE       (1UL << PMD_SHIFT)
+#define PGDIR_SIZE     (1UL << PGDIR_SHIFT)
+#define PGDIR_MASK     (~(PGDIR_SIZE - 1))
+
+#define USER_PTRS_PER_PGD      (TASK_SIZE / PGDIR_SIZE)
+#define FIRST_USER_ADDRESS     0
+
+#define USER_PGD_PTRS          (PAGE_OFFSET >> PGDIR_SHIFT)
+#define KERNEL_PGD_PTRS                (PTRS_PER_PGD - USER_PGD_PTRS)
+
+#define TWOLEVEL_PGDIR_SHIFT   22
+#define BOOT_USER_PGD_PTRS     (__PAGE_OFFSET >> TWOLEVEL_PGDIR_SHIFT)
+#define BOOT_KERNEL_PGD_PTRS   (1024 - BOOT_USER_PGD_PTRS)
+
+#ifndef __ASSEMBLY__
+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
+#endif
+
+/*
+ * Unfortunately, due to the way the MMU works on the MN10300, the vmalloc VM
+ * area has to be in the lower half of the virtual address range (the upper
+ * half is not translated through the TLB).
+ *
+ * So in this case, the vmalloc area goes at the bottom of the address map
+ * (leaving a hole at the very bottom to catch addressing errors), and
+ * userspace starts immediately above.
+ *
+ * The vmalloc() routines also leaves a hole of 4kB between each vmalloced
+ * area to catch addressing errors.
+ */
+#define VMALLOC_OFFSET (8 * 1024 * 1024)
+#define VMALLOC_START  (0x70000000)
+#define VMALLOC_END    (0x7C000000)
+
+#ifndef __ASSEMBLY__
+extern pte_t kernel_vmalloc_ptes[(VMALLOC_END - VMALLOC_START) / PAGE_SIZE];
+#endif
+
+/* IPTEL/DPTEL bit assignments */
+#define _PAGE_BIT_VALID                xPTEL_V_BIT
+#define _PAGE_BIT_ACCESSED     xPTEL_UNUSED1_BIT       /* mustn't be loaded into IPTEL/DPTEL */
+#define _PAGE_BIT_NX           xPTEL_UNUSED2_BIT       /* mustn't be loaded into IPTEL/DPTEL */
+#define _PAGE_BIT_CACHE                xPTEL_C_BIT
+#define _PAGE_BIT_PRESENT      xPTEL_PV_BIT
+#define _PAGE_BIT_DIRTY                xPTEL_D_BIT
+#define _PAGE_BIT_GLOBAL       xPTEL_G_BIT
+
+#define _PAGE_VALID            xPTEL_V
+#define _PAGE_ACCESSED         xPTEL_UNUSED1
+#define _PAGE_NX               xPTEL_UNUSED2           /* no-execute bit */
+#define _PAGE_CACHE            xPTEL_C
+#define _PAGE_PRESENT          xPTEL_PV
+#define _PAGE_DIRTY            xPTEL_D
+#define _PAGE_PROT             xPTEL_PR
+#define _PAGE_PROT_RKNU                xPTEL_PR_ROK
+#define _PAGE_PROT_WKNU                xPTEL_PR_RWK
+#define _PAGE_PROT_RKRU                xPTEL_PR_ROK_ROU
+#define _PAGE_PROT_WKRU                xPTEL_PR_RWK_ROU
+#define _PAGE_PROT_WKWU                xPTEL_PR_RWK_RWU
+#define _PAGE_GLOBAL           xPTEL_G
+#define _PAGE_PSE              xPTEL_PS_4Mb            /* 4MB page */
+
+#define _PAGE_FILE             xPTEL_UNUSED1_BIT       /* set:pagecache unset:swap */
+
+#define __PAGE_PROT_UWAUX      0x040
+#define __PAGE_PROT_USER       0x080
+#define __PAGE_PROT_WRITE      0x100
+
+#define _PAGE_PRESENTV         (_PAGE_PRESENT|_PAGE_VALID)
+#define _PAGE_PROTNONE         0x000   /* If not present */
+
+#ifndef __ASSEMBLY__
+
+#define VMALLOC_VMADDR(x) ((unsigned long)(x))
+
+#define _PAGE_TABLE    (_PAGE_PRESENTV | _PAGE_PROT_WKNU | _PAGE_ACCESSED | _PAGE_DIRTY)
+#define _PAGE_CHG_MASK (PTE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
+
+#define __PAGE_NONE    (_PAGE_PRESENTV | _PAGE_PROT_RKNU | _PAGE_ACCESSED | _PAGE_CACHE)
+#define __PAGE_SHARED  (_PAGE_PRESENTV | _PAGE_PROT_WKWU | _PAGE_ACCESSED | _PAGE_CACHE)
+#define __PAGE_COPY    (_PAGE_PRESENTV | _PAGE_PROT_RKRU | _PAGE_ACCESSED | _PAGE_CACHE)
+#define __PAGE_READONLY        (_PAGE_PRESENTV | _PAGE_PROT_RKRU | _PAGE_ACCESSED | _PAGE_CACHE)
+
+#define PAGE_NONE              __pgprot(__PAGE_NONE     | _PAGE_NX)
+#define PAGE_SHARED_NOEXEC     __pgprot(__PAGE_SHARED   | _PAGE_NX)
+#define PAGE_COPY_NOEXEC       __pgprot(__PAGE_COPY     | _PAGE_NX)
+#define PAGE_READONLY_NOEXEC   __pgprot(__PAGE_READONLY | _PAGE_NX)
+#define PAGE_SHARED_EXEC       __pgprot(__PAGE_SHARED)
+#define PAGE_COPY_EXEC         __pgprot(__PAGE_COPY)
+#define PAGE_READONLY_EXEC     __pgprot(__PAGE_READONLY)
+#define PAGE_COPY              PAGE_COPY_NOEXEC
+#define PAGE_READONLY          PAGE_READONLY_NOEXEC
+#define PAGE_SHARED            PAGE_SHARED_EXEC
+
+#define __PAGE_KERNEL_BASE (_PAGE_PRESENTV | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
+
+#define __PAGE_KERNEL          (__PAGE_KERNEL_BASE | _PAGE_PROT_WKNU | _PAGE_CACHE | _PAGE_NX)
+#define __PAGE_KERNEL_NOCACHE  (__PAGE_KERNEL_BASE | _PAGE_PROT_WKNU | _PAGE_NX)
+#define __PAGE_KERNEL_EXEC     (__PAGE_KERNEL & ~_PAGE_NX)
+#define __PAGE_KERNEL_RO       (__PAGE_KERNEL_BASE | _PAGE_PROT_RKNU | _PAGE_CACHE | _PAGE_NX)
+#define __PAGE_KERNEL_LARGE    (__PAGE_KERNEL | _PAGE_PSE)
+#define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
+
+#define PAGE_KERNEL            __pgprot(__PAGE_KERNEL)
+#define PAGE_KERNEL_RO         __pgprot(__PAGE_KERNEL_RO)
+#define PAGE_KERNEL_EXEC       __pgprot(__PAGE_KERNEL_EXEC)
+#define PAGE_KERNEL_NOCACHE    __pgprot(__PAGE_KERNEL_NOCACHE)
+#define PAGE_KERNEL_LARGE      __pgprot(__PAGE_KERNEL_LARGE)
+#define PAGE_KERNEL_LARGE_EXEC __pgprot(__PAGE_KERNEL_LARGE_EXEC)
+
+/*
+ * Whilst the MN10300 can do page protection for execute (given separate data
+ * and insn TLBs), we are not supporting it at the moment. Write permission,
+ * however, always implies read permission (but not execute permission).
+ */
+#define __P000 PAGE_NONE
+#define __P001 PAGE_READONLY_NOEXEC
+#define __P010 PAGE_COPY_NOEXEC
+#define __P011 PAGE_COPY_NOEXEC
+#define __P100 PAGE_READONLY_EXEC
+#define __P101 PAGE_READONLY_EXEC
+#define __P110 PAGE_COPY_EXEC
+#define __P111 PAGE_COPY_EXEC
+
+#define __S000 PAGE_NONE
+#define __S001 PAGE_READONLY_NOEXEC
+#define __S010 PAGE_SHARED_NOEXEC
+#define __S011 PAGE_SHARED_NOEXEC
+#define __S100 PAGE_READONLY_EXEC
+#define __S101 PAGE_READONLY_EXEC
+#define __S110 PAGE_SHARED_EXEC
+#define __S111 PAGE_SHARED_EXEC
+
+/*
+ * Define this to warn about kernel memory accesses that are
+ * done without a 'verify_area(VERIFY_WRITE,..)'
+ */
+#undef TEST_VERIFY_AREA
+
+#define pte_present(x) (pte_val(x) & _PAGE_VALID)
+#define pte_clear(mm, addr, xp)                                \
+do {                                                   \
+       set_pte_at((mm), (addr), (xp), __pte(0));       \
+} while (0)
+
+#define pmd_none(x)    (!pmd_val(x))
+#define pmd_present(x) (!pmd_none(x))
+#define pmd_clear(xp)  do { set_pmd(xp, __pmd(0)); } while (0)
+#define        pmd_bad(x)      0
+
+
+#define pages_to_mb(x) ((x) >> (20 - PAGE_SHIFT))
+
+#ifndef __ASSEMBLY__
+
+/*
+ * The following only work if pte_present() is true.
+ * Undefined behaviour if not..
+ */
+static inline int pte_user(pte_t pte)  { return pte_val(pte) & __PAGE_PROT_USER; }
+static inline int pte_read(pte_t pte)  { return pte_val(pte) & __PAGE_PROT_USER; }
+static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
+static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
+static inline int pte_write(pte_t pte) { return pte_val(pte) & __PAGE_PROT_WRITE; }
+
+/*
+ * The following only works if pte_present() is not true.
+ */
+static inline int pte_file(pte_t pte)  { return pte_val(pte) & _PAGE_FILE; }
+
+static inline pte_t pte_rdprotect(pte_t pte)
+{
+       pte_val(pte) &= ~(__PAGE_PROT_USER|__PAGE_PROT_UWAUX); return pte;
+}
+static inline pte_t pte_exprotect(pte_t pte)
+{
+       pte_val(pte) |= _PAGE_NX; return pte;
+}
+
+static inline pte_t pte_wrprotect(pte_t pte)
+{
+       pte_val(pte) &= ~(__PAGE_PROT_WRITE|__PAGE_PROT_UWAUX); return pte;
+}
+
+static inline pte_t pte_mkclean(pte_t pte)     { pte_val(pte) &= ~_PAGE_DIRTY; return pte; }
+static inline pte_t pte_mkold(pte_t pte)       { pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
+static inline pte_t pte_mkdirty(pte_t pte)     { pte_val(pte) |= _PAGE_DIRTY; return pte; }
+static inline pte_t pte_mkyoung(pte_t pte)     { pte_val(pte) |= _PAGE_ACCESSED; return pte; }
+static inline pte_t pte_mkexec(pte_t pte)      { pte_val(pte) &= ~_PAGE_NX; return pte; }
+
+static inline pte_t pte_mkread(pte_t pte)
+{
+       pte_val(pte) |= __PAGE_PROT_USER;
+       if (pte_write(pte))
+               pte_val(pte) |= __PAGE_PROT_UWAUX;
+       return pte;
+}
+static inline pte_t pte_mkwrite(pte_t pte)
+{
+       pte_val(pte) |= __PAGE_PROT_WRITE;
+       if (pte_val(pte) & __PAGE_PROT_USER)
+               pte_val(pte) |= __PAGE_PROT_UWAUX;
+       return pte;
+}
+
+#define pte_ERROR(e) \
+       printk(KERN_ERR "%s:%d: bad pte %08lx.\n", \
+              __FILE__, __LINE__, pte_val(e))
+#define pgd_ERROR(e) \
+       printk(KERN_ERR "%s:%d: bad pgd %08lx.\n", \
+              __FILE__, __LINE__, pgd_val(e))
+
+/*
+ * The "pgd_xxx()" functions here are trivial for a folded two-level
+ * setup: the pgd is never bad, and a pmd always exists (as it's folded
+ * into the pgd entry)
+ */
+#define pgd_clear(xp)                          do { } while (0)
+
+/*
+ * Certain architectures need to do special things when PTEs
+ * within a page table are directly modified.  Thus, the following
+ * hook is made available.
+ */
+#define set_pte(pteptr, pteval)                        (*(pteptr) = pteval)
+#define set_pte_at(mm, addr, ptep, pteval)     set_pte((ptep), (pteval))
+#define set_pte_atomic(pteptr, pteval)         set_pte((pteptr), (pteval))
+
+/*
+ * (pmds are folded into pgds so this doesn't get actually called,
+ * but the define is needed for a generic inline function.)
+ */
+#define set_pmd(pmdptr, pmdval) (*(pmdptr) = pmdval)
+
+#define ptep_get_and_clear(mm, addr, ptep) \
+       __pte(xchg(&(ptep)->pte, 0))
+#define pte_same(a, b)         (pte_val(a) == pte_val(b))
+#define pte_page(x)            pfn_to_page(pte_pfn(x))
+#define pte_none(x)            (!pte_val(x))
+#define pte_pfn(x)             ((unsigned long) (pte_val(x) >> PAGE_SHIFT))
+#define __pfn_addr(pfn)                ((pfn) << PAGE_SHIFT)
+#define pfn_pte(pfn, prot)     __pte(__pfn_addr(pfn) | pgprot_val(prot))
+#define pfn_pmd(pfn, prot)     __pmd(__pfn_addr(pfn) | pgprot_val(prot))
+
+/*
+ * All present user pages are user-executable:
+ */
+static inline int pte_exec(pte_t pte)
+{
+       return pte_user(pte);
+}
+
+/*
+ * All present pages are kernel-executable:
+ */
+static inline int pte_exec_kernel(pte_t pte)
+{
+       return 1;
+}
+
+/*
+ * Bits 0 and 1 are taken, split up the 29 bits of offset
+ * into this range:
+ */
+#define PTE_FILE_MAX_BITS      29
+
+#define pte_to_pgoff(pte)      (pte_val(pte) >> 2)
+#define pgoff_to_pte(off)      __pte((off) << 2 | _PAGE_FILE)
+
+/* Encode and de-code a swap entry */
+#define __swp_type(x)                  (((x).val >> 2) & 0x3f)
+#define __swp_offset(x)                        ((x).val >> 8)
+#define __swp_entry(type, offset) \
+       ((swp_entry_t) { ((type) << 2) | ((offset) << 8) })
+#define __pte_to_swp_entry(pte)                ((swp_entry_t) { pte_val(pte) })
+#define __swp_entry_to_pte(x)          __pte((x).val)
+
+static inline
+int ptep_test_and_clear_dirty(struct vm_area_struct *vma, unsigned long addr,
+                             pte_t *ptep)
+{
+       if (!pte_dirty(*ptep))
+               return 0;
+       return test_and_clear_bit(_PAGE_BIT_DIRTY, &ptep->pte);
+}
+
+static inline
+int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr,
+                             pte_t *ptep)
+{
+       if (!pte_young(*ptep))
+               return 0;
+       return test_and_clear_bit(_PAGE_BIT_ACCESSED, &ptep->pte);
+}
+
+static inline
+void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
+{
+       pte_val(*ptep) &= ~(__PAGE_PROT_WRITE|__PAGE_PROT_UWAUX);
+}
+
+static inline void ptep_mkdirty(pte_t *ptep)
+{
+       set_bit(_PAGE_BIT_DIRTY, &ptep->pte);
+}
+
+/*
+ * Macro to mark a page protection value as "uncacheable".  On processors which
+ * do not support it, this is a no-op.
+ */
+#define pgprot_noncached(prot) __pgprot(pgprot_val(prot) | _PAGE_CACHE)
+
+
+/*
+ * Conversion functions: convert a page and protection to a page entry,
+ * and a page entry and page directory to the page they refer to.
+ */
+
+#define mk_pte(page, pgprot)   pfn_pte(page_to_pfn(page), (pgprot))
+#define mk_pte_huge(entry) \
+       ((entry).pte |= _PAGE_PRESENT | _PAGE_PSE | _PAGE_VALID)
+
+static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
+{
+       pte_val(pte) &= _PAGE_CHG_MASK;
+       pte_val(pte) |= pgprot_val(newprot);
+       return pte;
+}
+
+#define page_pte(page) page_pte_prot((page), __pgprot(0))
+
+#define pmd_page_kernel(pmd) \
+       ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK))
+
+#define pmd_page(pmd)  pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT)
+
+#define pmd_large(pmd) \
+       ((pmd_val(pmd) & (_PAGE_PSE | _PAGE_PRESENT)) == \
+        (_PAGE_PSE | _PAGE_PRESENT))
+
+/*
+ * the pgd page can be thought of an array like this: pgd_t[PTRS_PER_PGD]
+ *
+ * this macro returns the index of the entry in the pgd page which would
+ * control the given virtual address
+ */
+#define pgd_index(address) (((address) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
+
+/*
+ * pgd_offset() returns a (pgd_t *)
+ * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
+ */
+#define pgd_offset(mm, address)        ((mm)->pgd + pgd_index(address))
+
+/*
+ * a shortcut which implies the use of the kernel's pgd, instead
+ * of a process's
+ */
+#define pgd_offset_k(address)  pgd_offset(&init_mm, address)
+
+/*
+ * the pmd page can be thought of an array like this: pmd_t[PTRS_PER_PMD]
+ *
+ * this macro returns the index of the entry in the pmd page which would
+ * control the given virtual address
+ */
+#define pmd_index(address) \
+       (((address) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
+
+/*
+ * the pte page can be thought of an array like this: pte_t[PTRS_PER_PTE]
+ *
+ * this macro returns the index of the entry in the pte page which would
+ * control the given virtual address
+ */
+#define pte_index(address) \
+       (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
+
+#define pte_offset_kernel(dir, address) \
+       ((pte_t *) pmd_page_kernel(*(dir)) +  pte_index(address))
+
+/*
+ * Make a given kernel text page executable/non-executable.
+ * Returns the previous executability setting of that page (which
+ * is used to restore the previous state). Used by the SMP bootup code.
+ * NOTE: this is an __init function for security reasons.
+ */
+static inline int set_kernel_exec(unsigned long vaddr, int enable)
+{
+       return 0;
+}
+
+#define pte_offset_map(dir, address) \
+       ((pte_t *) page_address(pmd_page(*(dir))) + pte_index(address))
+#define pte_offset_map_nested(dir, address) pte_offset_map(dir, address)
+#define pte_unmap(pte)         do {} while (0)
+#define pte_unmap_nested(pte)  do {} while (0)
+
+/*
+ * The MN10300 has external MMU info in the form of a TLB: this is adapted from
+ * the kernel page tables containing the necessary information by tlb-mn10300.S
+ */
+extern void update_mmu_cache(struct vm_area_struct *vma,
+                            unsigned long address, pte_t pte);
+
+#endif /* !__ASSEMBLY__ */
+
+#define kern_addr_valid(addr)  (1)
+
+#define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
+       remap_pfn_range((vma), (vaddr), (pfn), (size), (prot))
+
+#define MK_IOSPACE_PFN(space, pfn)     (pfn)
+#define GET_IOSPACE(pfn)               0
+#define GET_PFN(pfn)                   (pfn)
+
+#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
+#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_DIRTY
+#define __HAVE_ARCH_PTEP_GET_AND_CLEAR
+#define __HAVE_ARCH_PTEP_SET_WRPROTECT
+#define __HAVE_ARCH_PTEP_MKDIRTY
+#define __HAVE_ARCH_PTE_SAME
+#include <asm-generic/pgtable.h>
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* _ASM_PGTABLE_H */
diff --git a/include/asm-mn10300/pio-regs.h b/include/asm-mn10300/pio-regs.h
new file mode 100644 (file)
index 0000000..96bc818
--- /dev/null
@@ -0,0 +1,233 @@
+/* MN10300 On-board I/O port module registers
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_PIO_REGS_H
+#define _ASM_PIO_REGS_H
+
+#include <asm/cpu-regs.h>
+#include <asm/intctl-regs.h>
+
+#ifdef __KERNEL__
+
+/* I/O port 0 */
+#define        P0MD                    __SYSREG(0xdb000000, u16)       /* mode reg */
+#define P0MD_0                 0x0003  /* mask */
+#define P0MD_0_IN              0x0000  /* input mode */
+#define P0MD_0_OUT             0x0001  /* output mode */
+#define P0MD_0_TM0IO           0x0002  /* timer 0 I/O mode */
+#define P0MD_0_EYECLK          0x0003  /* test signal output (clock) */
+#define P0MD_1                 0x000c
+#define P0MD_1_IN              0x0000
+#define P0MD_1_OUT             0x0004
+#define P0MD_1_TM1IO           0x0008  /* timer 1 I/O mode */
+#define P0MD_1_EYED            0x000c  /* test signal output (data) */
+#define P0MD_2                 0x0030
+#define P0MD_2_IN              0x0000
+#define P0MD_2_OUT             0x0010
+#define P0MD_2_TM2IO           0x0020  /* timer 2 I/O mode */
+#define P0MD_3                 0x00c0
+#define P0MD_3_IN              0x0000
+#define P0MD_3_OUT             0x0040
+#define P0MD_3_TM3IO           0x0080  /* timer 3 I/O mode */
+#define P0MD_4                 0x0300
+#define P0MD_4_IN              0x0000
+#define P0MD_4_OUT             0x0100
+#define P0MD_4_TM4IO           0x0200  /* timer 4 I/O mode */
+#define P0MD_4_XCTS            0x0300  /* XCTS input for serial port 2 */
+#define P0MD_5                 0x0c00
+#define P0MD_5_IN              0x0000
+#define P0MD_5_OUT             0x0400
+#define P0MD_5_TM5IO           0x0800  /* timer 5 I/O mode */
+#define P0MD_6                 0x3000
+#define P0MD_6_IN              0x0000
+#define P0MD_6_OUT             0x1000
+#define P0MD_6_TM6IOA          0x2000  /* timer 6 I/O mode A */
+#define P0MD_7                 0xc000
+#define P0MD_7_IN              0x0000
+#define P0MD_7_OUT             0x4000
+#define P0MD_7_TM6IOB          0x8000  /* timer 6 I/O mode B */
+
+#define        P0IN                    __SYSREG(0xdb000004, u8)        /* in reg */
+#define        P0OUT                   __SYSREG(0xdb000008, u8)        /* out reg */
+
+#define        P0TMIO                  __SYSREG(0xdb00000c, u8)        /* TM pin I/O control reg */
+#define P0TMIO_TM0_IN          0x00
+#define P0TMIO_TM0_OUT         0x01
+#define P0TMIO_TM1_IN          0x00
+#define P0TMIO_TM1_OUT         0x02
+#define P0TMIO_TM2_IN          0x00
+#define P0TMIO_TM2_OUT         0x04
+#define P0TMIO_TM3_IN          0x00
+#define P0TMIO_TM3_OUT         0x08
+#define P0TMIO_TM4_IN          0x00
+#define P0TMIO_TM4_OUT         0x10
+#define P0TMIO_TM5_IN          0x00
+#define P0TMIO_TM5_OUT         0x20
+#define P0TMIO_TM6A_IN         0x00
+#define P0TMIO_TM6A_OUT                0x40
+#define P0TMIO_TM6B_IN         0x00
+#define P0TMIO_TM6B_OUT                0x80
+
+/* I/O port 1 */
+#define        P1MD                    __SYSREG(0xdb000100, u16)       /* mode reg */
+#define P1MD_0                 0x0003  /* mask */
+#define P1MD_0_IN              0x0000  /* input mode */
+#define P1MD_0_OUT             0x0001  /* output mode */
+#define P1MD_0_TM7IO           0x0002  /* timer 7 I/O mode */
+#define P1MD_0_ADTRG           0x0003  /* A/D converter trigger mode */
+#define P1MD_1                 0x000c
+#define P1MD_1_IN              0x0000
+#define P1MD_1_OUT             0x0004
+#define P1MD_1_TM8IO           0x0008  /* timer 8 I/O mode */
+#define P1MD_1_XDMR0           0x000c  /* DMA request input 0 mode */
+#define P1MD_2                 0x0030
+#define P1MD_2_IN              0x0000
+#define P1MD_2_OUT             0x0010
+#define P1MD_2_TM9IO           0x0020  /* timer 9 I/O mode */
+#define P1MD_2_XDMR1           0x0030  /* DMA request input 1 mode */
+#define P1MD_3                 0x00c0
+#define P1MD_3_IN              0x0000
+#define P1MD_3_OUT             0x0040
+#define P1MD_3_TM10IO          0x0080  /* timer 10 I/O mode */
+#define P1MD_3_FRQS0           0x00c0  /* CPU clock multiplier setting input 0 mode */
+#define P1MD_4                 0x0300
+#define P1MD_4_IN              0x0000
+#define P1MD_4_OUT             0x0100
+#define P1MD_4_TM11IO          0x0200  /* timer 11 I/O mode */
+#define P1MD_4_FRQS1           0x0300  /* CPU clock multiplier setting input 1 mode */
+
+#define        P1IN                    __SYSREG(0xdb000104, u8)        /* in reg */
+#define        P1OUT                   __SYSREG(0xdb000108, u8)        /* out reg */
+#define        P1TMIO                  __SYSREG(0xdb00010c, u8)        /* TM pin I/O control reg */
+#define P1TMIO_TM11_IN         0x00
+#define P1TMIO_TM11_OUT                0x01
+#define P1TMIO_TM10_IN         0x00
+#define P1TMIO_TM10_OUT                0x02
+#define P1TMIO_TM9_IN          0x00
+#define P1TMIO_TM9_OUT         0x04
+#define P1TMIO_TM8_IN          0x00
+#define P1TMIO_TM8_OUT         0x08
+#define P1TMIO_TM7_IN          0x00
+#define P1TMIO_TM7_OUT         0x10
+
+/* I/O port 2 */
+#define        P2MD                    __SYSREG(0xdb000200, u16)       /* mode reg */
+#define P2MD_0                 0x0003  /* mask */
+#define P2MD_0_IN              0x0000  /* input mode */
+#define P2MD_0_OUT             0x0001  /* output mode */
+#define P2MD_0_BOOTBW          0x0003  /* boot bus width selector mode */
+#define P2MD_1                 0x000c
+#define P2MD_1_IN              0x0000
+#define P2MD_1_OUT             0x0004
+#define P2MD_1_BOOTSEL         0x000c  /* boot device selector mode */
+#define P2MD_2                 0x0030
+#define P2MD_2_IN              0x0000
+#define P2MD_2_OUT             0x0010
+#define P2MD_3                 0x00c0
+#define P2MD_3_IN              0x0000
+#define P2MD_3_OUT             0x0040
+#define P2MD_3_CKIO            0x00c0  /* mode */
+#define P2MD_4                 0x0300
+#define P2MD_4_IN              0x0000
+#define P2MD_4_OUT             0x0100
+#define P2MD_4_CMOD            0x0300  /* mode */
+
+#define        P2IN                    __SYSREG(0xdb000204, u8)        /* in reg */
+#define        P2OUT                   __SYSREG(0xdb000208, u8)        /* out reg */
+#define        P2TMIO                  __SYSREG(0xdb00020c, u8)        /* TM pin I/O control reg */
+
+/* I/O port 3 */
+#define        P3MD                    __SYSREG(0xdb000300, u16)       /* mode reg */
+#define P3MD_0                 0x0003  /* mask */
+#define P3MD_0_IN              0x0000  /* input mode */
+#define P3MD_0_OUT             0x0001  /* output mode */
+#define P3MD_0_AFRXD           0x0002  /* AFR interface mode */
+#define P3MD_1                 0x000c
+#define P3MD_1_IN              0x0000
+#define P3MD_1_OUT             0x0004
+#define P3MD_1_AFTXD           0x0008  /* AFR interface mode */
+#define P3MD_2                 0x0030
+#define P3MD_2_IN              0x0000
+#define P3MD_2_OUT             0x0010
+#define P3MD_2_AFSCLK          0x0020  /* AFR interface mode */
+#define P3MD_3                 0x00c0
+#define P3MD_3_IN              0x0000
+#define P3MD_3_OUT             0x0040
+#define P3MD_3_AFFS            0x0080  /* AFR interface mode */
+#define P3MD_4                 0x0300
+#define P3MD_4_IN              0x0000
+#define P3MD_4_OUT             0x0100
+#define P3MD_4_AFEHC           0x0200  /* AFR interface mode */
+
+#define        P3IN                    __SYSREG(0xdb000304, u8)        /* in reg */
+#define        P3OUT                   __SYSREG(0xdb000308, u8)        /* out reg */
+
+/* I/O port 4 */
+#define        P4MD                    __SYSREG(0xdb000400, u16)       /* mode reg */
+#define P4MD_0                 0x0003  /* mask */
+#define P4MD_0_IN              0x0000  /* input mode */
+#define P4MD_0_OUT             0x0001  /* output mode */
+#define P4MD_0_SCL0            0x0002  /* I2C/serial mode */
+#define P4MD_1                 0x000c
+#define P4MD_1_IN              0x0000
+#define P4MD_1_OUT             0x0004
+#define P4MD_1_SDA0            0x0008
+#define P4MD_2                 0x0030
+#define P4MD_2_IN              0x0000
+#define P4MD_2_OUT             0x0010
+#define P4MD_2_SCL1            0x0020
+#define P4MD_3                 0x00c0
+#define P4MD_3_IN              0x0000
+#define P4MD_3_OUT             0x0040
+#define P4MD_3_SDA1            0x0080
+#define P4MD_4                 0x0300
+#define P4MD_4_IN              0x0000
+#define P4MD_4_OUT             0x0100
+#define P4MD_4_SBO0            0x0200
+#define P4MD_5                 0x0c00
+#define P4MD_5_IN              0x0000
+#define P4MD_5_OUT             0x0400
+#define P4MD_5_SBO1            0x0800
+#define P4MD_6                 0x3000
+#define P4MD_6_IN              0x0000
+#define P4MD_6_OUT             0x1000
+#define P4MD_6_SBT0            0x2000
+#define P4MD_7                 0xc000
+#define P4MD_7_IN              0x0000
+#define P4MD_7_OUT             0x4000
+#define P4MD_7_SBT1            0x8000
+
+#define        P4IN                    __SYSREG(0xdb000404, u8)        /* in reg */
+#define        P4OUT                   __SYSREG(0xdb000408, u8)        /* out reg */
+
+/* I/O port 5 */
+#define        P5MD                    __SYSREG(0xdb000500, u16)       /* mode reg */
+#define P5MD_0                 0x0003  /* mask */
+#define P5MD_0_IN              0x0000  /* input mode */
+#define P5MD_0_OUT             0x0001  /* output mode */
+#define P5MD_0_IRTXD           0x0002  /* IrDA mode */
+#define P5MD_0_SOUT            0x0004  /* serial mode */
+#define P5MD_1                 0x000c
+#define P5MD_1_IN              0x0000
+#define P5MD_1_OUT             0x0004
+#define P5MD_1_IRRXDS          0x0008  /* IrDA mode */
+#define P5MD_1_SIN             0x000c  /* serial mode */
+#define P5MD_2                 0x0030
+#define P5MD_2_IN              0x0000
+#define P5MD_2_OUT             0x0010
+#define P5MD_2_IRRXDF          0x0020  /* IrDA mode */
+
+#define        P5IN                    __SYSREG(0xdb000504, u8)        /* in reg */
+#define        P5OUT                   __SYSREG(0xdb000508, u8)        /* out reg */
+
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_PIO_REGS_H */
diff --git a/include/asm-mn10300/poll.h b/include/asm-mn10300/poll.h
new file mode 100644 (file)
index 0000000..c98509d
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/poll.h>
diff --git a/include/asm-mn10300/posix_types.h b/include/asm-mn10300/posix_types.h
new file mode 100644 (file)
index 0000000..077567c
--- /dev/null
@@ -0,0 +1,132 @@
+/* MN10300 POSIX types
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_POSIX_TYPES_H
+#define _ASM_POSIX_TYPES_H
+
+/*
+ * This file is generally used by user-level software, so you need to
+ * be a little careful about namespace pollution etc.  Also, we cannot
+ * assume GCC is being used.
+ */
+
+typedef unsigned long  __kernel_ino_t;
+typedef unsigned short __kernel_mode_t;
+typedef unsigned short __kernel_nlink_t;
+typedef long           __kernel_off_t;
+typedef int            __kernel_pid_t;
+typedef unsigned short __kernel_ipc_pid_t;
+typedef unsigned short __kernel_uid_t;
+typedef unsigned short __kernel_gid_t;
+typedef unsigned long  __kernel_size_t;
+typedef long           __kernel_ssize_t;
+typedef int            __kernel_ptrdiff_t;
+typedef long           __kernel_time_t;
+typedef long           __kernel_suseconds_t;
+typedef long           __kernel_clock_t;
+typedef int            __kernel_timer_t;
+typedef int            __kernel_clockid_t;
+typedef int            __kernel_daddr_t;
+typedef char *         __kernel_caddr_t;
+typedef unsigned short __kernel_uid16_t;
+typedef unsigned short __kernel_gid16_t;
+typedef unsigned int   __kernel_uid32_t;
+typedef unsigned int   __kernel_gid32_t;
+
+typedef unsigned short __kernel_old_uid_t;
+typedef unsigned short __kernel_old_gid_t;
+typedef unsigned short __kernel_old_dev_t;
+
+#ifdef __GNUC__
+typedef long long      __kernel_loff_t;
+#endif
+
+typedef struct {
+#if defined(__KERNEL__) || defined(__USE_ALL)
+       int     val[2];
+#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
+       int     __val[2];
+#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
+} __kernel_fsid_t;
+
+#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
+
+#undef __FD_SET
+static inline void __FD_SET(unsigned long __fd, __kernel_fd_set *__fdsetp)
+{
+       unsigned long __tmp = __fd / __NFDBITS;
+       unsigned long __rem = __fd % __NFDBITS;
+       __fdsetp->fds_bits[__tmp] |= (1UL<<__rem);
+}
+
+#undef __FD_CLR
+static inline void __FD_CLR(unsigned long __fd, __kernel_fd_set *__fdsetp)
+{
+       unsigned long __tmp = __fd / __NFDBITS;
+       unsigned long __rem = __fd % __NFDBITS;
+       __fdsetp->fds_bits[__tmp] &= ~(1UL<<__rem);
+}
+
+
+#undef __FD_ISSET
+static inline int __FD_ISSET(unsigned long __fd, const __kernel_fd_set *__p)
+{
+       unsigned long __tmp = __fd / __NFDBITS;
+       unsigned long __rem = __fd % __NFDBITS;
+       return (__p->fds_bits[__tmp] & (1UL<<__rem)) != 0;
+}
+
+/*
+ * This will unroll the loop for the normal constant case (8 ints,
+ * for a 256-bit fd_set)
+ */
+#undef __FD_ZERO
+static inline void __FD_ZERO(__kernel_fd_set *__p)
+{
+       unsigned long *__tmp = __p->fds_bits;
+       int __i;
+
+       if (__builtin_constant_p(__FDSET_LONGS)) {
+               switch (__FDSET_LONGS) {
+               case 16:
+                       __tmp[ 0] = 0; __tmp[ 1] = 0;
+                       __tmp[ 2] = 0; __tmp[ 3] = 0;
+                       __tmp[ 4] = 0; __tmp[ 5] = 0;
+                       __tmp[ 6] = 0; __tmp[ 7] = 0;
+                       __tmp[ 8] = 0; __tmp[ 9] = 0;
+                       __tmp[10] = 0; __tmp[11] = 0;
+                       __tmp[12] = 0; __tmp[13] = 0;
+                       __tmp[14] = 0; __tmp[15] = 0;
+                       return;
+
+               case 8:
+                       __tmp[ 0] = 0; __tmp[ 1] = 0;
+                       __tmp[ 2] = 0; __tmp[ 3] = 0;
+                       __tmp[ 4] = 0; __tmp[ 5] = 0;
+                       __tmp[ 6] = 0; __tmp[ 7] = 0;
+                       return;
+
+               case 4:
+                       __tmp[ 0] = 0; __tmp[ 1] = 0;
+                       __tmp[ 2] = 0; __tmp[ 3] = 0;
+                       return;
+               }
+       }
+       __i = __FDSET_LONGS;
+       while (__i) {
+               __i--;
+               *__tmp = 0;
+               __tmp++;
+       }
+}
+
+#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+
+#endif /* _ASM_POSIX_TYPES_H */
diff --git a/include/asm-mn10300/proc-mn103e010/cache.h b/include/asm-mn10300/proc-mn103e010/cache.h
new file mode 100644 (file)
index 0000000..bdc1f9a
--- /dev/null
@@ -0,0 +1,33 @@
+/* MN103E010 Cache specification
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_PROC_CACHE_H
+#define _ASM_PROC_CACHE_H
+
+/* L1 cache */
+
+#define L1_CACHE_NWAYS         4       /* number of ways in caches */
+#define L1_CACHE_NENTRIES      256     /* number of entries in each way */
+#define L1_CACHE_BYTES         16      /* bytes per entry */
+#define L1_CACHE_SHIFT         4       /* shift for bytes per entry */
+#define L1_CACHE_WAYDISP       0x1000  /* displacement of one way from the next */
+
+#define L1_CACHE_TAG_VALID     0x00000001      /* cache tag valid bit */
+#define L1_CACHE_TAG_DIRTY     0x00000008      /* data cache tag dirty bit */
+#define L1_CACHE_TAG_ENTRY     0x00000ff0      /* cache tag entry address mask */
+#define L1_CACHE_TAG_ADDRESS   0xfffff000      /* cache tag line address mask */
+
+/*
+ * specification of the interval between interrupt checking intervals whilst
+ * managing the cache with the interrupts disabled
+ */
+#define MN10300_DCACHE_INV_RANGE_INTR_LOG2_INTERVAL    4
+
+#endif /* _ASM_PROC_CACHE_H */
diff --git a/include/asm-mn10300/proc-mn103e010/clock.h b/include/asm-mn10300/proc-mn103e010/clock.h
new file mode 100644 (file)
index 0000000..caf9983
--- /dev/null
@@ -0,0 +1,18 @@
+/* MN103E010-specific clocks
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_PROC_CLOCK_H
+#define _ASM_PROC_CLOCK_H
+
+#include <asm/unit/clock.h>
+
+#define MN10300_WDCLK          MN10300_IOCLK
+
+#endif /* _ASM_PROC_CLOCK_H */
diff --git a/include/asm-mn10300/proc-mn103e010/irq.h b/include/asm-mn10300/proc-mn103e010/irq.h
new file mode 100644 (file)
index 0000000..aa6ee8f
--- /dev/null
@@ -0,0 +1,34 @@
+/* MN103E010 On-board interrupt controller numbers
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_PROC_IRQ_H
+#define _ASM_PROC_IRQ_H
+
+#ifdef __KERNEL__
+
+#define GxICR_NUM_IRQS         42
+
+#define GxICR_NUM_XIRQS                8
+
+#define XIRQ0          34
+#define XIRQ1          35
+#define XIRQ2          36
+#define XIRQ3          37
+#define XIRQ4          38
+#define XIRQ5          39
+#define XIRQ6          40
+#define XIRQ7          41
+
+#define XIRQ2IRQ(num)  (XIRQ0 + num)
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_PROC_IRQ_H */
diff --git a/include/asm-mn10300/proc-mn103e010/proc.h b/include/asm-mn10300/proc-mn103e010/proc.h
new file mode 100644 (file)
index 0000000..22a2b93
--- /dev/null
@@ -0,0 +1,18 @@
+/* MN103E010 Processor description
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_PROC_PROC_H
+#define _ASM_PROC_PROC_H
+
+#define PROCESSOR_VENDOR_NAME  "Matsushita"
+#define PROCESSOR_MODEL_NAME   "mn103e010"
+
+#endif /* _ASM_PROC_PROC_H */
diff --git a/include/asm-mn10300/processor.h b/include/asm-mn10300/processor.h
new file mode 100644 (file)
index 0000000..f1b081f
--- /dev/null
@@ -0,0 +1,186 @@
+/* MN10300 Processor specifics
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_PROCESSOR_H
+#define _ASM_PROCESSOR_H
+
+#include <asm/page.h>
+#include <asm/ptrace.h>
+#include <asm/cpu-regs.h>
+#include <linux/threads.h>
+
+/* Forward declaration, a strange C thing */
+struct task_struct;
+struct mm_struct;
+
+/*
+ * Default implementation of macro that returns current
+ * instruction pointer ("program counter").
+ */
+#define current_text_addr()                    \
+({                                             \
+       void *__pc;                             \
+       asm("mov pc,%0" : "=a"(__pc));          \
+       __pc;                                   \
+})
+
+extern void show_registers(struct pt_regs *regs);
+
+/*
+ *  CPU type and hardware bug flags. Kept separately for each CPU.
+ *  Members of this structure are referenced in head.S, so think twice
+ *  before touching them. [mj]
+ */
+
+struct mn10300_cpuinfo {
+       int             type;
+       unsigned long   loops_per_sec;
+       char            hard_math;
+       unsigned long   *pgd_quick;
+       unsigned long   *pte_quick;
+       unsigned long   pgtable_cache_sz;
+};
+
+extern struct mn10300_cpuinfo boot_cpu_data;
+
+#define cpu_data &boot_cpu_data
+#define current_cpu_data boot_cpu_data
+
+extern void identify_cpu(struct mn10300_cpuinfo *);
+extern void print_cpu_info(struct mn10300_cpuinfo *);
+extern void dodgy_tsc(void);
+#define cpu_relax() do {} while (0)
+
+/*
+ * User space process size: 1.75GB (default).
+ */
+#define TASK_SIZE              0x70000000
+
+/*
+ * Where to put the userspace stack by default
+ */
+#define STACK_TOP              0x70000000
+#define STACK_TOP_MAX          STACK_TOP
+
+/* This decides where the kernel will search for a free chunk of vm
+ * space during mmap's.
+ */
+#define TASK_UNMAPPED_BASE     0x30000000
+
+typedef struct {
+       unsigned long   seg;
+} mm_segment_t;
+
+struct fpu_state_struct {
+       unsigned long   fs[32];         /* fpu registers */
+       unsigned long   fpcr;           /* fpu control register */
+};
+
+struct thread_struct {
+       struct pt_regs          *uregs;         /* userspace register frame */
+       unsigned long           pc;             /* kernel PC */
+       unsigned long           sp;             /* kernel SP */
+       unsigned long           a3;             /* kernel FP */
+       unsigned long           wchan;
+       unsigned long           usp;
+       struct pt_regs          *__frame;
+       unsigned long           fpu_flags;
+#define THREAD_USING_FPU       0x00000001      /* T if this task is using the FPU */
+       struct fpu_state_struct fpu_state;
+};
+
+#define INIT_THREAD                            \
+{                                              \
+       .uregs          = init_uregs,           \
+       .pc             = 0,                    \
+       .sp             = 0,                    \
+       .a3             = 0,                    \
+       .wchan          = 0,                    \
+       .__frame        = NULL,                 \
+}
+
+#define INIT_MMAP \
+{ &init_mm, 0, 0, NULL, PAGE_SHARED, VM_READ | VM_WRITE | VM_EXEC, 1, \
+  NULL, NULL }
+
+/*
+ * do necessary setup to start up a newly executed thread
+ * - need to discard the frame stacked by the kernel thread invoking the execve
+ *   syscall (see RESTORE_ALL macro)
+ */
+#define start_thread(regs, new_pc, new_sp) do {                \
+       set_fs(USER_DS);                                \
+       __frame = current->thread.uregs;                \
+       __frame->epsw = EPSW_nSL | EPSW_IE | EPSW_IM;   \
+       __frame->pc = new_pc;                           \
+       __frame->sp = new_sp;                           \
+} while (0)
+
+/* Free all resources held by a thread. */
+extern void release_thread(struct task_struct *);
+
+/* Prepare to copy thread state - unlazy all lazy status */
+extern void prepare_to_copy(struct task_struct *tsk);
+
+/*
+ * create a kernel thread without removing it from tasklists
+ */
+extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
+
+/*
+ * Return saved PC of a blocked thread.
+ */
+extern unsigned long thread_saved_pc(struct task_struct *tsk);
+
+unsigned long get_wchan(struct task_struct *p);
+
+#define task_pt_regs(task)                                             \
+({                                                                     \
+       struct pt_regs *__regs__;                                       \
+       __regs__ = (struct pt_regs *) (KSTK_TOP(task_stack_page(task)) - 8); \
+       __regs__ - 1;                                                   \
+})
+
+#define KSTK_EIP(task) (task_pt_regs(task)->pc)
+#define KSTK_ESP(task) (task_pt_regs(task)->sp)
+
+#define KSTK_TOP(info)                         \
+({                                             \
+       (unsigned long)(info) + THREAD_SIZE;    \
+})
+
+#define ARCH_HAS_PREFETCH
+#define ARCH_HAS_PREFETCHW
+
+static inline void prefetch(const void *x)
+{
+#ifndef CONFIG_MN10300_CACHE_DISABLED
+#ifdef CONFIG_MN10300_PROC_MN103E010
+       asm volatile ("nop; nop; dcpf (%0)" : : "r"(x));
+#else
+       asm volatile ("dcpf (%0)" : : "r"(x));
+#endif
+#endif
+}
+
+static inline void prefetchw(const void *x)
+{
+#ifndef CONFIG_MN10300_CACHE_DISABLED
+#ifdef CONFIG_MN10300_PROC_MN103E010
+       asm volatile ("nop; nop; dcpf (%0)" : : "r"(x));
+#else
+       asm volatile ("dcpf (%0)" : : "r"(x));
+#endif
+#endif
+}
+
+#endif /* _ASM_PROCESSOR_H */
diff --git a/include/asm-mn10300/ptrace.h b/include/asm-mn10300/ptrace.h
new file mode 100644 (file)
index 0000000..b368468
--- /dev/null
@@ -0,0 +1,99 @@
+/* MN10300 Exception frame layout and ptrace constants
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_PTRACE_H
+#define _ASM_PTRACE_H
+
+#define PT_A3          0
+#define PT_A2          1
+#define PT_D3          2
+#define        PT_D2           3
+#define PT_MCVF                4
+#define        PT_MCRL         5
+#define PT_MCRH                6
+#define        PT_MDRQ         7
+#define        PT_E1           8
+#define        PT_E0           9
+#define        PT_E7           10
+#define        PT_E6           11
+#define        PT_E5           12
+#define        PT_E4           13
+#define        PT_E3           14
+#define        PT_E2           15
+#define        PT_SP           16
+#define        PT_LAR          17
+#define        PT_LIR          18
+#define        PT_MDR          19
+#define        PT_A1           20
+#define        PT_A0           21
+#define        PT_D1           22
+#define        PT_D0           23
+#define PT_ORIG_D0     24
+#define        PT_EPSW         25
+#define        PT_PC           26
+#define NR_PTREGS      27
+
+#ifndef __ASSEMBLY__
+/*
+ * This defines the way registers are stored in the event of an exception
+ * - the strange order is due to the MOVM instruction
+ */
+struct pt_regs {
+       unsigned long           a3;             /* syscall arg 3 */
+       unsigned long           a2;             /* syscall arg 4 */
+       unsigned long           d3;             /* syscall arg 5 */
+       unsigned long           d2;             /* syscall arg 6 */
+       unsigned long           mcvf;
+       unsigned long           mcrl;
+       unsigned long           mcrh;
+       unsigned long           mdrq;
+       unsigned long           e1;
+       unsigned long           e0;
+       unsigned long           e7;
+       unsigned long           e6;
+       unsigned long           e5;
+       unsigned long           e4;
+       unsigned long           e3;
+       unsigned long           e2;
+       unsigned long           sp;
+       unsigned long           lar;
+       unsigned long           lir;
+       unsigned long           mdr;
+       unsigned long           a1;
+       unsigned long           a0;             /* syscall arg 1 */
+       unsigned long           d1;             /* syscall arg 2 */
+       unsigned long           d0;             /* syscall ret */
+       struct pt_regs          *next;          /* next frame pointer */
+       unsigned long           orig_d0;        /* syscall number */
+       unsigned long           epsw;
+       unsigned long           pc;
+};
+#endif
+
+extern struct pt_regs *__frame; /* current frame pointer */
+
+/* Arbitrarily choose the same ptrace numbers as used by the Sparc code. */
+#define PTRACE_GETREGS            12
+#define PTRACE_SETREGS            13
+#define PTRACE_GETFPREGS          14
+#define PTRACE_SETFPREGS          15
+
+/* options set using PTRACE_SETOPTIONS */
+#define PTRACE_O_TRACESYSGOOD     0x00000001
+
+#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
+#define user_mode(regs)                        (((regs)->epsw & EPSW_nSL) == EPSW_nSL)
+#define instruction_pointer(regs)      ((regs)->pc)
+extern void show_regs(struct pt_regs *);
+#endif
+
+#define profile_pc(regs) ((regs)->pc)
+
+#endif /* _ASM_PTRACE_H */
diff --git a/include/asm-mn10300/reset-regs.h b/include/asm-mn10300/reset-regs.h
new file mode 100644 (file)
index 0000000..174523d
--- /dev/null
@@ -0,0 +1,64 @@
+/* MN10300 Reset controller and watchdog timer definitions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_RESET_REGS_H
+#define _ASM_RESET_REGS_H
+
+#include <asm/cpu-regs.h>
+#include <asm/exceptions.h>
+
+#ifdef __KERNEL__
+
+#ifdef CONFIG_MN10300_WD_TIMER
+#define ARCH_HAS_NMI_WATCHDOG          /* See include/linux/nmi.h */
+#endif
+
+/*
+ * watchdog timer registers
+ */
+#define WDBC                   __SYSREGC(0xc0001000, u8) /* watchdog binary counter reg */
+
+#define WDCTR                  __SYSREG(0xc0001002, u8)  /* watchdog timer control reg */
+#define WDCTR_WDCK             0x07    /* clock source selection */
+#define WDCTR_WDCK_256th       0x00    /* - OSCI/256 */
+#define WDCTR_WDCK_1024th      0x01    /* - OSCI/1024 */
+#define WDCTR_WDCK_2048th      0x02    /* - OSCI/2048 */
+#define WDCTR_WDCK_16384th     0x03    /* - OSCI/16384 */
+#define WDCTR_WDCK_65536th     0x04    /* - OSCI/65536 */
+#define WDCTR_WDRST            0x40    /* binary counter reset */
+#define WDCTR_WDCNE            0x80    /* watchdog timer enable */
+
+#define RSTCTR                 __SYSREG(0xc0001004, u8) /* reset control reg */
+#define RSTCTR_CHIPRST         0x01    /* chip reset */
+#define RSTCTR_DBFRST          0x02    /* double fault reset flag */
+#define RSTCTR_WDTRST          0x04    /* watchdog timer reset flag */
+#define RSTCTR_WDREN           0x08    /* watchdog timer reset enable */
+
+#ifndef __ASSEMBLY__
+
+static inline void mn10300_proc_hard_reset(void)
+{
+       RSTCTR &= ~RSTCTR_CHIPRST;
+       RSTCTR |= RSTCTR_CHIPRST;
+}
+
+extern unsigned int watchdog_alert_counter;
+
+extern void watchdog_go(void);
+extern asmlinkage void watchdog_handler(void);
+extern asmlinkage
+void watchdog_interrupt(struct pt_regs *, enum exception_code);
+
+#endif
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_RESET_REGS_H */
diff --git a/include/asm-mn10300/resource.h b/include/asm-mn10300/resource.h
new file mode 100644 (file)
index 0000000..04bc4db
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/resource.h>
diff --git a/include/asm-mn10300/rtc-regs.h b/include/asm-mn10300/rtc-regs.h
new file mode 100644 (file)
index 0000000..c42deef
--- /dev/null
@@ -0,0 +1,86 @@
+/* MN10300 on-chip Real-Time Clock registers
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_RTC_REGS_H
+#define _ASM_RTC_REGS_H
+
+#include <asm/intctl-regs.h>
+
+#ifdef __KERNEL__
+
+#define RTSCR                  __SYSREG(0xd8600000, u8) /* RTC seconds count reg */
+#define RTSAR                  __SYSREG(0xd8600001, u8) /* RTC seconds alarm reg */
+#define RTMCR                  __SYSREG(0xd8600002, u8) /* RTC minutes count reg */
+#define RTMAR                  __SYSREG(0xd8600003, u8) /* RTC minutes alarm reg */
+#define RTHCR                  __SYSREG(0xd8600004, u8) /* RTC hours count reg */
+#define RTHAR                  __SYSREG(0xd8600005, u8) /* RTC hours alarm reg */
+#define RTDWCR                 __SYSREG(0xd8600006, u8) /* RTC day of the week count reg */
+#define RTDMCR                 __SYSREG(0xd8600007, u8) /* RTC days count reg */
+#define RTMTCR                 __SYSREG(0xd8600008, u8) /* RTC months count reg */
+#define RTYCR                  __SYSREG(0xd8600009, u8) /* RTC years count reg */
+
+#define RTCRA                  __SYSREG(0xd860000a, u8)/* RTC control reg A */
+#define RTCRA_RS               0x0f    /* periodic timer interrupt cycle setting */
+#define RTCRA_RS_NONE          0x00    /* - off */
+#define RTCRA_RS_3_90625ms     0x01    /* - 3.90625ms  (1/256s) */
+#define RTCRA_RS_7_8125ms      0x02    /* - 7.8125ms   (1/128s) */
+#define RTCRA_RS_122_070us     0x03    /* - 122.070us  (1/8192s) */
+#define RTCRA_RS_244_141us     0x04    /* - 244.141us  (1/4096s) */
+#define RTCRA_RS_488_281us     0x05    /* - 488.281us  (1/2048s) */
+#define RTCRA_RS_976_5625us    0x06    /* - 976.5625us (1/1024s) */
+#define RTCRA_RS_1_953125ms    0x07    /* - 1.953125ms (1/512s) */
+#define RTCRA_RS_3_90624ms     0x08    /* - 3.90624ms  (1/256s) */
+#define RTCRA_RS_7_8125ms_b    0x09    /* - 7.8125ms   (1/128s) */
+#define RTCRA_RS_15_625ms      0x0a    /* - 15.625ms   (1/64s) */
+#define RTCRA_RS_31_25ms       0x0b    /* - 31.25ms    (1/32s) */
+#define RTCRA_RS_62_5ms                0x0c    /* - 62.5ms     (1/16s) */
+#define RTCRA_RS_125ms         0x0d    /* - 125ms      (1/8s) */
+#define RTCRA_RS_250ms         0x0e    /* - 250ms      (1/4s) */
+#define RTCRA_RS_500ms         0x0f    /* - 500ms      (1/2s) */
+#define RTCRA_DVR              0x40    /* divider reset */
+#define RTCRA_UIP              0x80    /* clock update flag */
+
+#define RTCRB                  __SYSREG(0xd860000b, u8) /* RTC control reg B */
+#define RTCRB_DSE              0x01    /* daylight savings time enable */
+#define RTCRB_TM               0x02    /* time format */
+#define RTCRB_TM_12HR          0x00    /* - 12 hour format */
+#define RTCRB_TM_24HR          0x02    /* - 24 hour format */
+#define RTCRB_DM               0x04    /* numeric value format */
+#define RTCRB_DM_BCD           0x00    /* - BCD */
+#define RTCRB_DM_BINARY                0x04    /* - binary */
+#define RTCRB_UIE              0x10    /* update interrupt disable */
+#define RTCRB_AIE              0x20    /* alarm interrupt disable */
+#define RTCRB_PIE              0x40    /* periodic interrupt disable */
+#define RTCRB_SET              0x80    /* clock update enable */
+
+#define RTSRC                  __SYSREG(0xd860000c, u8) /* RTC status reg C */
+#define RTSRC_UF               0x10    /* update end interrupt flag */
+#define RTSRC_AF               0x20    /* alarm interrupt flag */
+#define RTSRC_PF               0x40    /* periodic interrupt flag */
+#define RTSRC_IRQF             0x80    /* interrupt flag */
+
+#define RTIRQ                  32
+#define RTICR                  GxICR(RTIRQ)
+
+/*
+ * MC146818 RTC compatibility defs for the MN10300 on-chip RTC
+ */
+#define RTC_PORT(x)            0xd8600000
+#define RTC_ALWAYS_BCD         1       /* RTC operates in binary mode */
+
+#define CMOS_READ(addr)                __SYSREG(0xd8600000 + (addr), u8)
+#define CMOS_WRITE(val, addr)  \
+       do { __SYSREG(0xd8600000 + (addr), u8) = val; } while (0)
+
+#define RTC_IRQ                        RTIRQ
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_RTC_REGS_H */
diff --git a/include/asm-mn10300/rtc.h b/include/asm-mn10300/rtc.h
new file mode 100644 (file)
index 0000000..c295194
--- /dev/null
@@ -0,0 +1,41 @@
+/* MN10300 Real time clock definitions
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_RTC_H
+#define _ASM_RTC_H
+
+#ifdef CONFIG_MN10300_RTC
+
+#include <linux/init.h>
+
+extern void check_rtc_time(void);
+extern void __init calibrate_clock(void);
+extern unsigned long __init get_initial_rtc_time(void);
+
+#else /* !CONFIG_MN10300_RTC */
+
+static inline void check_rtc_time(void)
+{
+}
+
+static inline void calibrate_clock(void)
+{
+}
+
+static inline unsigned long get_initial_rtc_time(void)
+{
+       return 0;
+}
+
+#endif /* !CONFIG_MN10300_RTC */
+
+#include <asm-generic/rtc.h>
+
+#endif /* _ASM_RTC_H */
diff --git a/include/asm-mn10300/scatterlist.h b/include/asm-mn10300/scatterlist.h
new file mode 100644 (file)
index 0000000..e29d91d
--- /dev/null
@@ -0,0 +1,46 @@
+/* MN10300 Scatterlist definitions
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_SCATTERLIST_H
+#define _ASM_SCATTERLIST_H
+
+#include <asm/types.h>
+
+/*
+ * Drivers must set either ->address or (preferred) page and ->offset
+ * to indicate where data must be transferred to/from.
+ *
+ * Using page is recommended since it handles highmem data as well as
+ * low mem. ->address is restricted to data which has a virtual mapping, and
+ * it will go away in the future. Updating to page can be automated very
+ * easily -- something like
+ *
+ * sg->address = some_ptr;
+ *
+ * can be rewritten as
+ *
+ * sg_set_page(virt_to_page(some_ptr));
+ * sg->offset = (unsigned long) some_ptr & ~PAGE_MASK;
+ *
+ * and that's it. There's no excuse for not highmem enabling YOUR driver. /jens
+ */
+struct scatterlist {
+#ifdef CONFIG_DEBUG_SG
+       unsigned long   sg_magic;
+#endif
+       unsigned long   page_link;
+       unsigned int    offset;         /* for highmem, page offset */
+       dma_addr_t      dma_address;
+       unsigned int    length;
+};
+
+#define ISA_DMA_THRESHOLD (0x00ffffff)
+
+#endif /* _ASM_SCATTERLIST_H */
diff --git a/include/asm-mn10300/sections.h b/include/asm-mn10300/sections.h
new file mode 100644 (file)
index 0000000..2b8c516
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/sections.h>
diff --git a/include/asm-mn10300/semaphore.h b/include/asm-mn10300/semaphore.h
new file mode 100644 (file)
index 0000000..5a9e1ad
--- /dev/null
@@ -0,0 +1,169 @@
+/* MN10300 Semaphores
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_SEMAPHORE_H
+#define _ASM_SEMAPHORE_H
+
+#ifndef __ASSEMBLY__
+
+#include <linux/linkage.h>
+#include <linux/wait.h>
+#include <linux/spinlock.h>
+#include <linux/rwsem.h>
+
+#define SEMAPHORE_DEBUG                0
+
+/*
+ * the semaphore definition
+ * - if count is >0 then there are tokens available on the semaphore for down
+ *   to collect
+ * - if count is <=0 then there are no spare tokens, and anyone that wants one
+ *   must wait
+ * - if wait_list is not empty, then there are processes waiting for the
+ *   semaphore
+ */
+struct semaphore {
+       atomic_t                count;          /* it's not really atomic, it's
+                                                * just that certain modules
+                                                * expect to be able to access
+                                                * it directly */
+       spinlock_t              wait_lock;
+       struct list_head        wait_list;
+#if SEMAPHORE_DEBUG
+       unsigned                __magic;
+#endif
+};
+
+#if SEMAPHORE_DEBUG
+# define __SEM_DEBUG_INIT(name) , (long)&(name).__magic
+#else
+# define __SEM_DEBUG_INIT(name)
+#endif
+
+
+#define __SEMAPHORE_INITIALIZER(name, init_count)                      \
+{                                                                      \
+       .count          = ATOMIC_INIT(init_count),                      \
+       .wait_lock      = __SPIN_LOCK_UNLOCKED((name).wait_lock),       \
+       .wait_list      = LIST_HEAD_INIT((name).wait_list)              \
+       __SEM_DEBUG_INIT(name)                                          \
+}
+
+#define __DECLARE_SEMAPHORE_GENERIC(name,count) \
+       struct semaphore name = __SEMAPHORE_INITIALIZER(name, count)
+
+#define DECLARE_MUTEX(name) __DECLARE_SEMAPHORE_GENERIC(name, 1)
+#define DECLARE_MUTEX_LOCKED(name) __DECLARE_SEMAPHORE_GENERIC(name, 0)
+
+static inline void sema_init(struct semaphore *sem, int val)
+{
+       *sem = (struct semaphore) __SEMAPHORE_INITIALIZER(*sem, val);
+}
+
+static inline void init_MUTEX(struct semaphore *sem)
+{
+       sema_init(sem, 1);
+}
+
+static inline void init_MUTEX_LOCKED(struct semaphore *sem)
+{
+       sema_init(sem, 0);
+}
+
+extern void __down(struct semaphore *sem, unsigned long flags);
+extern int  __down_interruptible(struct semaphore *sem, unsigned long flags);
+extern void __up(struct semaphore *sem);
+
+static inline void down(struct semaphore *sem)
+{
+       unsigned long flags;
+       int count;
+
+#if SEMAPHORE_DEBUG
+       CHECK_MAGIC(sem->__magic);
+#endif
+
+       spin_lock_irqsave(&sem->wait_lock, flags);
+       count = atomic_read(&sem->count);
+       if (likely(count > 0)) {
+               atomic_set(&sem->count, count - 1);
+               spin_unlock_irqrestore(&sem->wait_lock, flags);
+       } else {
+               __down(sem, flags);
+       }
+}
+
+static inline int down_interruptible(struct semaphore *sem)
+{
+       unsigned long flags;
+       int count, ret = 0;
+
+#if SEMAPHORE_DEBUG
+       CHECK_MAGIC(sem->__magic);
+#endif
+
+       spin_lock_irqsave(&sem->wait_lock, flags);
+       count = atomic_read(&sem->count);
+       if (likely(count > 0)) {
+               atomic_set(&sem->count, count - 1);
+               spin_unlock_irqrestore(&sem->wait_lock, flags);
+       } else {
+               ret = __down_interruptible(sem, flags);
+       }
+       return ret;
+}
+
+/*
+ * non-blockingly attempt to down() a semaphore.
+ * - returns zero if we acquired it
+ */
+static inline int down_trylock(struct semaphore *sem)
+{
+       unsigned long flags;
+       int count, success = 0;
+
+#if SEMAPHORE_DEBUG
+       CHECK_MAGIC(sem->__magic);
+#endif
+
+       spin_lock_irqsave(&sem->wait_lock, flags);
+       count = atomic_read(&sem->count);
+       if (likely(count > 0)) {
+               atomic_set(&sem->count, count - 1);
+               success = 1;
+       }
+       spin_unlock_irqrestore(&sem->wait_lock, flags);
+       return !success;
+}
+
+static inline void up(struct semaphore *sem)
+{
+       unsigned long flags;
+
+#if SEMAPHORE_DEBUG
+       CHECK_MAGIC(sem->__magic);
+#endif
+
+       spin_lock_irqsave(&sem->wait_lock, flags);
+       if (!list_empty(&sem->wait_list))
+               __up(sem);
+       else
+               atomic_set(&sem->count, atomic_read(&sem->count) + 1);
+       spin_unlock_irqrestore(&sem->wait_lock, flags);
+}
+
+static inline int sem_getcount(struct semaphore *sem)
+{
+       return atomic_read(&sem->count);
+}
+
+#endif /* __ASSEMBLY__ */
+
+#endif
diff --git a/include/asm-mn10300/sembuf.h b/include/asm-mn10300/sembuf.h
new file mode 100644 (file)
index 0000000..301f3f9
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef _ASM_SEMBUF_H
+#define _ASM_SEMBUF_H
+
+/*
+ * The semid64_ds structure for MN10300 architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 64-bit time_t to solve y2038 problem
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct semid64_ds {
+       struct ipc64_perm sem_perm;             /* permissions .. see ipc.h */
+       __kernel_time_t sem_otime;              /* last semop time */
+       unsigned long   __unused1;
+       __kernel_time_t sem_ctime;              /* last change time */
+       unsigned long   __unused2;
+       unsigned long   sem_nsems;              /* no. of semaphores in array */
+       unsigned long   __unused3;
+       unsigned long   __unused4;
+};
+
+#endif /* _ASM_SEMBUF_H */
diff --git a/include/asm-mn10300/serial-regs.h b/include/asm-mn10300/serial-regs.h
new file mode 100644 (file)
index 0000000..6498469
--- /dev/null
@@ -0,0 +1,160 @@
+/* MN10300 on-board serial port module registers
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_SERIAL_REGS_H
+#define _ASM_SERIAL_REGS_H
+
+#include <asm/cpu-regs.h>
+#include <asm/intctl-regs.h>
+
+#ifdef __KERNEL__
+
+/* serial port 0 */
+#define        SC0CTR                  __SYSREG(0xd4002000, u16)       /* control reg */
+#define        SC01CTR_CK              0x0007  /* clock source select */
+#define        SC0CTR_CK_TM8UFLOW_8    0x0000  /* - 1/8 timer 8 underflow (serial port 0 only) */
+#define        SC1CTR_CK_TM9UFLOW_8    0x0000  /* - 1/8 timer 9 underflow (serial port 1 only) */
+#define        SC01CTR_CK_IOCLK_8      0x0001  /* - 1/8 IOCLK */
+#define        SC01CTR_CK_IOCLK_32     0x0002  /* - 1/32 IOCLK */
+#define        SC0CTR_CK_TM2UFLOW_2    0x0003  /* - 1/2 timer 2 underflow (serial port 0 only) */
+#define        SC1CTR_CK_TM3UFLOW_2    0x0003  /* - 1/2 timer 3 underflow (serial port 1 only) */
+#define        SC0CTR_CK_TM0UFLOW_8    0x0004  /* - 1/8 timer 1 underflow (serial port 0 only) */
+#define        SC1CTR_CK_TM1UFLOW_8    0x0004  /* - 1/8 timer 2 underflow (serial port 1 only) */
+#define        SC0CTR_CK_TM2UFLOW_8    0x0005  /* - 1/8 timer 2 underflow (serial port 0 only) */
+#define        SC1CTR_CK_TM3UFLOW_8    0x0005  /* - 1/8 timer 3 underflow (serial port 1 only) */
+#define        SC01CTR_CK_EXTERN_8     0x0006  /* - 1/8 external closk */
+#define        SC01CTR_CK_EXTERN       0x0007  /* - external closk */
+#define        SC01CTR_STB             0x0008  /* stop bit select */
+#define        SC01CTR_STB_1BIT        0x0000  /* - 1 stop bit */
+#define        SC01CTR_STB_2BIT        0x0008  /* - 2 stop bits */
+#define        SC01CTR_PB              0x0070  /* parity bit select */
+#define        SC01CTR_PB_NONE         0x0000  /* - no parity */
+#define        SC01CTR_PB_FIXED0       0x0040  /* - fixed at 0 */
+#define        SC01CTR_PB_FIXED1       0x0050  /* - fixed at 1 */
+#define        SC01CTR_PB_EVEN         0x0060  /* - even parity */
+#define        SC01CTR_PB_ODD          0x0070  /* - odd parity */
+#define        SC01CTR_CLN             0x0080  /* character length */
+#define        SC01CTR_CLN_7BIT        0x0000  /* - 7 bit chars */
+#define        SC01CTR_CLN_8BIT        0x0080  /* - 8 bit chars */
+#define        SC01CTR_TOE             0x0100  /* T input output enable */
+#define        SC01CTR_OD              0x0200  /* bit order select */
+#define        SC01CTR_OD_LSBFIRST     0x0000  /* - LSB first */
+#define        SC01CTR_OD_MSBFIRST     0x0200  /* - MSB first */
+#define        SC01CTR_MD              0x0c00  /* mode select */
+#define SC01CTR_MD_STST_SYNC   0x0000  /* - start-stop synchronous */
+#define SC01CTR_MD_CLOCK_SYNC1 0x0400  /* - clock synchronous 1 */
+#define SC01CTR_MD_I2C         0x0800  /* - I2C mode */
+#define SC01CTR_MD_CLOCK_SYNC2 0x0c00  /* - clock synchronous 2 */
+#define        SC01CTR_IIC             0x1000  /* I2C mode select */
+#define        SC01CTR_BKE             0x2000  /* break transmit enable */
+#define        SC01CTR_RXE             0x4000  /* receive enable */
+#define        SC01CTR_TXE             0x8000  /* transmit enable */
+
+#define        SC0ICR                  __SYSREG(0xd4002004, u8)        /* interrupt control reg */
+#define SC01ICR_DMD            0x80    /* output data mode */
+#define SC01ICR_TD             0x20    /* transmit DMA trigger cause */
+#define SC01ICR_TI             0x10    /* transmit interrupt cause */
+#define SC01ICR_RES            0x04    /* receive error select */
+#define SC01ICR_RI             0x01    /* receive interrupt cause */
+
+#define        SC0TXB                  __SYSREG(0xd4002008, u8)        /* transmit buffer reg */
+#define        SC0RXB                  __SYSREG(0xd4002009, u8)        /* receive buffer reg */
+
+#define        SC0STR                  __SYSREG(0xd400200c, u16)       /* status reg */
+#define SC01STR_OEF            0x0001  /* overrun error found */
+#define SC01STR_PEF            0x0002  /* parity error found */
+#define SC01STR_FEF            0x0004  /* framing error found */
+#define SC01STR_RBF            0x0010  /* receive buffer status */
+#define SC01STR_TBF            0x0020  /* transmit buffer status */
+#define SC01STR_RXF            0x0040  /* receive status */
+#define SC01STR_TXF            0x0080  /* transmit status */
+#define SC01STR_STF            0x0100  /* I2C start sequence found */
+#define SC01STR_SPF            0x0200  /* I2C stop sequence found */
+
+#define SC0RXIRQ               20      /* timer 0 Receive IRQ */
+#define SC0TXIRQ               21      /* timer 0 Transmit IRQ */
+
+#define        SC0RXICR                GxICR(SC0RXIRQ) /* serial 0 receive intr ctrl reg */
+#define        SC0TXICR                GxICR(SC0TXIRQ) /* serial 0 transmit intr ctrl reg */
+
+/* serial port 1 */
+#define        SC1CTR                  __SYSREG(0xd4002010, u16)       /* serial port 1 control */
+#define        SC1ICR                  __SYSREG(0xd4002014, u8)        /* interrupt control reg */
+#define        SC1TXB                  __SYSREG(0xd4002018, u8)        /* transmit buffer reg */
+#define        SC1RXB                  __SYSREG(0xd4002019, u8)        /* receive buffer reg */
+#define        SC1STR                  __SYSREG(0xd400201c, u16)       /* status reg */
+
+#define SC1RXIRQ               22      /* timer 1 Receive IRQ */
+#define SC1TXIRQ               23      /* timer 1 Transmit IRQ */
+
+#define        SC1RXICR                GxICR(SC1RXIRQ) /* serial 1 receive intr ctrl reg */
+#define        SC1TXICR                GxICR(SC1TXIRQ) /* serial 1 transmit intr ctrl reg */
+
+/* serial port 2 */
+#define        SC2CTR                  __SYSREG(0xd4002020, u16)       /* control reg */
+#define        SC2CTR_CK               0x0003  /* clock source select */
+#define        SC2CTR_CK_TM10UFLOW     0x0000  /* - timer 10 underflow */
+#define        SC2CTR_CK_TM2UFLOW      0x0001  /* - timer 2 underflow */
+#define        SC2CTR_CK_EXTERN        0x0002  /* - external closk */
+#define        SC2CTR_CK_TM3UFLOW      0x0003  /* - timer 3 underflow */
+#define        SC2CTR_STB              0x0008  /* stop bit select */
+#define        SC2CTR_STB_1BIT         0x0000  /* - 1 stop bit */
+#define        SC2CTR_STB_2BIT         0x0008  /* - 2 stop bits */
+#define        SC2CTR_PB               0x0070  /* parity bit select */
+#define        SC2CTR_PB_NONE          0x0000  /* - no parity */
+#define        SC2CTR_PB_FIXED0        0x0040  /* - fixed at 0 */
+#define        SC2CTR_PB_FIXED1        0x0050  /* - fixed at 1 */
+#define        SC2CTR_PB_EVEN          0x0060  /* - even parity */
+#define        SC2CTR_PB_ODD           0x0070  /* - odd parity */
+#define        SC2CTR_CLN              0x0080  /* character length */
+#define        SC2CTR_CLN_7BIT         0x0000  /* - 7 bit chars */
+#define        SC2CTR_CLN_8BIT         0x0080  /* - 8 bit chars */
+#define        SC2CTR_TWE              0x0100  /* transmit wait enable (enable XCTS control) */
+#define        SC2CTR_OD               0x0200  /* bit order select */
+#define        SC2CTR_OD_LSBFIRST      0x0000  /* - LSB first */
+#define        SC2CTR_OD_MSBFIRST      0x0200  /* - MSB first */
+#define        SC2CTR_TWS              0x1000  /* transmit wait select */
+#define        SC2CTR_TWS_XCTS_HIGH    0x0000  /* - interrupt TX when XCTS high */
+#define        SC2CTR_TWS_XCTS_LOW     0x1000  /* - interrupt TX when XCTS low */
+#define        SC2CTR_BKE              0x2000  /* break transmit enable */
+#define        SC2CTR_RXE              0x4000  /* receive enable */
+#define        SC2CTR_TXE              0x8000  /* transmit enable */
+
+#define        SC2ICR                  __SYSREG(0xd4002024, u8)        /* interrupt control reg */
+#define SC2ICR_TD              0x20    /* transmit DMA trigger cause */
+#define SC2ICR_TI              0x10    /* transmit interrupt cause */
+#define SC2ICR_RES             0x04    /* receive error select */
+#define SC2ICR_RI              0x01    /* receive interrupt cause */
+
+#define        SC2TXB                  __SYSREG(0xd4002018, u8)        /* transmit buffer reg */
+#define        SC2RXB                  __SYSREG(0xd4002019, u8)        /* receive buffer reg */
+#define        SC2STR                  __SYSREG(0xd400201c, u8)        /* status reg */
+#define SC2STR_OEF             0x0001  /* overrun error found */
+#define SC2STR_PEF             0x0002  /* parity error found */
+#define SC2STR_FEF             0x0004  /* framing error found */
+#define SC2STR_CTS             0x0008  /* XCTS input pin status (0 means high) */
+#define SC2STR_RBF             0x0010  /* receive buffer status */
+#define SC2STR_TBF             0x0020  /* transmit buffer status */
+#define SC2STR_RXF             0x0040  /* receive status */
+#define SC2STR_TXF             0x0080  /* transmit status */
+
+#define        SC2TIM                  __SYSREG(0xd400202d, u8)        /* status reg */
+
+#define SC2RXIRQ               24      /* serial 2 Receive IRQ */
+#define SC2TXIRQ               25      /* serial 2 Transmit IRQ */
+
+#define        SC2RXICR                GxICR(SC2RXIRQ) /* serial 2 receive intr ctrl reg */
+#define        SC2TXICR                GxICR(SC2TXIRQ) /* serial 2 transmit intr ctrl reg */
+
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_SERIAL_REGS_H */
diff --git a/include/asm-mn10300/serial.h b/include/asm-mn10300/serial.h
new file mode 100644 (file)
index 0000000..99785a9
--- /dev/null
@@ -0,0 +1,36 @@
+/* Standard UART definitions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+/*
+ * The ASB2305 has an 18.432 MHz clock the UART
+ */
+#define BASE_BAUD      (18432000 / 16)
+
+/* Standard COM flags (except for COM4, because of the 8514 problem) */
+#ifdef CONFIG_SERIAL_DETECT_IRQ
+#define STD_COM_FLAGS  (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ)
+#define STD_COM4_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_AUTO_IRQ)
+#else
+#define STD_COM_FLAGS  (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
+#define STD_COM4_FLAGS ASYNC_BOOT_AUTOCONF
+#endif
+
+#ifdef CONFIG_SERIAL_MANY_PORTS
+#define FOURPORT_FLAGS ASYNC_FOURPORT
+#define ACCENT_FLAGS   0
+#define BOCA_FLAGS     0
+#define HUB6_FLAGS     0
+#define RS_TABLE_SIZE  64
+#else
+#define RS_TABLE_SIZE
+#endif
+
+#include <asm/unit/serial.h>
diff --git a/include/asm-mn10300/setup.h b/include/asm-mn10300/setup.h
new file mode 100644 (file)
index 0000000..08356c8
--- /dev/null
@@ -0,0 +1,17 @@
+/* MN10300 Setup declarations
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_SETUP_H
+#define _ASM_SETUP_H
+
+extern void __init unit_setup(void);
+extern void __init unit_init_IRQ(void);
+
+#endif /* _ASM_SETUP_H */
diff --git a/include/asm-mn10300/shmbuf.h b/include/asm-mn10300/shmbuf.h
new file mode 100644 (file)
index 0000000..8f300cc
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef _ASM_SHMBUF_H
+#define _ASM_SHMBUF_H
+
+/*
+ * The shmid64_ds structure for MN10300 architecture.
+ * Note extra padding because this structure is passed back and forth
+ * between kernel and user space.
+ *
+ * Pad space is left for:
+ * - 64-bit time_t to solve y2038 problem
+ * - 2 miscellaneous 32-bit values
+ */
+
+struct shmid64_ds {
+       struct ipc64_perm       shm_perm;       /* operation perms */
+       size_t                  shm_segsz;      /* size of segment (bytes) */
+       __kernel_time_t         shm_atime;      /* last attach time */
+       unsigned long           __unused1;
+       __kernel_time_t         shm_dtime;      /* last detach time */
+       unsigned long           __unused2;
+       __kernel_time_t         shm_ctime;      /* last change time */
+       unsigned long           __unused3;
+       __kernel_pid_t          shm_cpid;       /* pid of creator */
+       __kernel_pid_t          shm_lpid;       /* pid of last operator */
+       unsigned long           shm_nattch;     /* no. of current attaches */
+       unsigned long           __unused4;
+       unsigned long           __unused5;
+};
+
+struct shminfo64 {
+       unsigned long   shmmax;
+       unsigned long   shmmin;
+       unsigned long   shmmni;
+       unsigned long   shmseg;
+       unsigned long   shmall;
+       unsigned long   __unused1;
+       unsigned long   __unused2;
+       unsigned long   __unused3;
+       unsigned long   __unused4;
+};
+
+#endif /* _ASM_SHMBUF_H */
diff --git a/include/asm-mn10300/shmparam.h b/include/asm-mn10300/shmparam.h
new file mode 100644 (file)
index 0000000..ab666ed
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef _ASM_SHMPARAM_H
+#define _ASM_SHMPARAM_H
+
+#define        SHMLBA PAGE_SIZE                 /* attach addr a multiple of this */
+
+#endif /* _ASM_SHMPARAM_H */
diff --git a/include/asm-mn10300/sigcontext.h b/include/asm-mn10300/sigcontext.h
new file mode 100644 (file)
index 0000000..4de3aff
--- /dev/null
@@ -0,0 +1,52 @@
+/* MN10300 Userspace signal context
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_SIGCONTEXT_H
+#define _ASM_SIGCONTEXT_H
+
+struct fpucontext {
+       /* Regular FPU environment */
+       unsigned long   fs[32];         /* fpu registers */
+       unsigned long   fpcr;           /* fpu control register */
+};
+
+struct sigcontext {
+       unsigned long   d0;
+       unsigned long   d1;
+       unsigned long   d2;
+       unsigned long   d3;
+       unsigned long   a0;
+       unsigned long   a1;
+       unsigned long   a2;
+       unsigned long   a3;
+       unsigned long   e0;
+       unsigned long   e1;
+       unsigned long   e2;
+       unsigned long   e3;
+       unsigned long   e4;
+       unsigned long   e5;
+       unsigned long   e6;
+       unsigned long   e7;
+       unsigned long   lar;
+       unsigned long   lir;
+       unsigned long   mdr;
+       unsigned long   mcvf;
+       unsigned long   mcrl;
+       unsigned long   mcrh;
+       unsigned long   mdrq;
+       unsigned long   sp;
+       unsigned long   epsw;
+       unsigned long   pc;
+       struct fpucontext *fpucontext;
+       unsigned long   oldmask;
+};
+
+
+#endif /* _ASM_SIGCONTEXT_H */
diff --git a/include/asm-mn10300/siginfo.h b/include/asm-mn10300/siginfo.h
new file mode 100644 (file)
index 0000000..0815d29
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/siginfo.h>
diff --git a/include/asm-mn10300/signal.h b/include/asm-mn10300/signal.h
new file mode 100644 (file)
index 0000000..e98817c
--- /dev/null
@@ -0,0 +1,171 @@
+/* MN10300 Signal definitions
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_SIGNAL_H
+#define _ASM_SIGNAL_H
+
+#include <linux/types.h>
+
+/* Avoid too many header ordering problems.  */
+struct siginfo;
+
+#ifdef __KERNEL__
+/* Most things should be clean enough to redefine this at will, if care
+   is taken to make libc match.  */
+
+#define _NSIG          64
+#define _NSIG_BPW      32
+#define _NSIG_WORDS    (_NSIG / _NSIG_BPW)
+
+typedef unsigned long old_sigset_t;            /* at least 32 bits */
+
+typedef struct {
+       unsigned long   sig[_NSIG_WORDS];
+} sigset_t;
+
+#else
+/* Here we must cater to libcs that poke about in kernel headers.  */
+
+#define NSIG           32
+typedef unsigned long sigset_t;
+
+#endif /* __KERNEL__ */
+
+#define SIGHUP          1
+#define SIGINT          2
+#define SIGQUIT                 3
+#define SIGILL          4
+#define SIGTRAP                 5
+#define SIGABRT                 6
+#define SIGIOT          6
+#define SIGBUS          7
+#define SIGFPE          8
+#define SIGKILL                 9
+#define SIGUSR1                10
+#define SIGSEGV                11
+#define SIGUSR2                12
+#define SIGPIPE                13
+#define SIGALRM                14
+#define SIGTERM                15
+#define SIGSTKFLT      16
+#define SIGCHLD                17
+#define SIGCONT                18
+#define SIGSTOP                19
+#define SIGTSTP                20
+#define SIGTTIN                21
+#define SIGTTOU                22
+#define SIGURG         23
+#define SIGXCPU                24
+#define SIGXFSZ                25
+#define SIGVTALRM      26
+#define SIGPROF                27
+#define SIGWINCH       28
+#define SIGIO          29
+#define SIGPOLL                SIGIO
+/*
+#define SIGLOST                29
+*/
+#define SIGPWR         30
+#define SIGSYS         31
+#define        SIGUNUSED       31
+
+/* These should not be considered constants from userland.  */
+#define SIGRTMIN       32
+#define SIGRTMAX       (_NSIG-1)
+
+/*
+ * SA_FLAGS values:
+ *
+ * SA_ONSTACK indicates that a registered stack_t will be used.
+ * SA_RESTART flag to get restarting signals (which were the default long ago)
+ * SA_NOCLDSTOP flag to turn off SIGCHLD when children stop.
+ * SA_RESETHAND clears the handler when the signal is delivered.
+ * SA_NOCLDWAIT flag on SIGCHLD to inhibit zombies.
+ * SA_NODEFER prevents the current signal from being masked in the handler.
+ *
+ * SA_ONESHOT and SA_NOMASK are the historical Linux names for the Single
+ * Unix names RESETHAND and NODEFER respectively.
+ */
+#define SA_NOCLDSTOP   0x00000001U
+#define SA_NOCLDWAIT   0x00000002U
+#define SA_SIGINFO     0x00000004U
+#define SA_ONSTACK     0x08000000U
+#define SA_RESTART     0x10000000U
+#define SA_NODEFER     0x40000000U
+#define SA_RESETHAND   0x80000000U
+
+#define SA_NOMASK      SA_NODEFER
+#define SA_ONESHOT     SA_RESETHAND
+
+#define SA_RESTORER    0x04000000
+
+/*
+ * sigaltstack controls
+ */
+#define SS_ONSTACK     1
+#define SS_DISABLE     2
+
+#define MINSIGSTKSZ    2048
+#define SIGSTKSZ       8192
+
+#include <asm-generic/signal.h>
+
+#ifdef __KERNEL__
+struct old_sigaction {
+       __sighandler_t sa_handler;
+       old_sigset_t sa_mask;
+       unsigned long sa_flags;
+       __sigrestore_t sa_restorer;
+};
+
+struct sigaction {
+       __sighandler_t sa_handler;
+       unsigned long sa_flags;
+       __sigrestore_t sa_restorer;
+       sigset_t sa_mask;               /* mask last for extensibility */
+};
+
+struct k_sigaction {
+       struct sigaction sa;
+};
+#else
+/* Here we must cater to libcs that poke about in kernel headers.  */
+
+struct sigaction {
+       union {
+         __sighandler_t _sa_handler;
+         void (*_sa_sigaction)(int, struct siginfo *, void *);
+       } _u;
+       sigset_t sa_mask;
+       unsigned long sa_flags;
+       void (*sa_restorer)(void);
+};
+
+#define sa_handler     _u._sa_handler
+#define sa_sigaction   _u._sa_sigaction
+
+#endif /* __KERNEL__ */
+
+typedef struct sigaltstack {
+       void __user     *ss_sp;
+       int             ss_flags;
+       size_t          ss_size;
+} stack_t;
+
+#ifdef __KERNEL__
+#include <asm/sigcontext.h>
+
+
+struct pt_regs;
+#define ptrace_signal_deliver(regs, cookie) do { } while (0)
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_SIGNAL_H */
diff --git a/include/asm-mn10300/smp.h b/include/asm-mn10300/smp.h
new file mode 100644 (file)
index 0000000..4eb8c61
--- /dev/null
@@ -0,0 +1,18 @@
+/* MN10300 SMP support
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_SMP_H
+#define _ASM_SMP_H
+
+#ifdef CONFIG_SMP
+#error SMP not yet supported for MN10300
+#endif
+
+#endif
diff --git a/include/asm-mn10300/socket.h b/include/asm-mn10300/socket.h
new file mode 100644 (file)
index 0000000..99ca648
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef _ASM_SOCKET_H
+#define _ASM_SOCKET_H
+
+#include <asm/sockios.h>
+
+/* For setsockopt(2) */
+#define SOL_SOCKET     1
+
+#define SO_DEBUG       1
+#define SO_REUSEADDR   2
+#define SO_TYPE                3
+#define SO_ERROR       4
+#define SO_DONTROUTE   5
+#define SO_BROADCAST   6
+#define SO_SNDBUF      7
+#define SO_RCVBUF      8
+#define SO_SNDBUFFORCE 32
+#define SO_RCVBUFFORCE 33
+#define SO_KEEPALIVE   9
+#define SO_OOBINLINE   10
+#define SO_NO_CHECK    11
+#define SO_PRIORITY    12
+#define SO_LINGER      13
+#define SO_BSDCOMPAT   14
+/* To add :#define SO_REUSEPORT 15 */
+#define SO_PASSCRED    16
+#define SO_PEERCRED    17
+#define SO_RCVLOWAT    18
+#define SO_SNDLOWAT    19
+#define SO_RCVTIMEO    20
+#define SO_SNDTIMEO    21
+
+/* Security levels - as per NRL IPv6 - don't actually do anything */
+#define SO_SECURITY_AUTHENTICATION             22
+#define SO_SECURITY_ENCRYPTION_TRANSPORT       23
+#define SO_SECURITY_ENCRYPTION_NETWORK         24
+
+#define SO_BINDTODEVICE        25
+
+/* Socket filtering */
+#define SO_ATTACH_FILTER        26
+#define SO_DETACH_FILTER        27
+
+#define SO_PEERNAME            28
+#define SO_TIMESTAMP           29
+#define SCM_TIMESTAMP          SO_TIMESTAMP
+
+#define SO_ACCEPTCONN          30
+
+#define SO_PEERSEC             31
+#define SO_PASSSEC             34
+#define SO_TIMESTAMPNS         35
+#define SCM_TIMESTAMPNS                SO_TIMESTAMPNS
+
+#endif /* _ASM_SOCKET_H */
diff --git a/include/asm-mn10300/sockios.h b/include/asm-mn10300/sockios.h
new file mode 100644 (file)
index 0000000..b03043a
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef _ASM_SOCKIOS_H
+#define _ASM_SOCKIOS_H
+
+/* Socket-level I/O control calls. */
+#define FIOSETOWN      0x8901
+#define SIOCSPGRP      0x8902
+#define FIOGETOWN      0x8903
+#define SIOCGPGRP      0x8904
+#define SIOCATMARK     0x8905
+#define SIOCGSTAMP     0x8906          /* Get stamp */
+#define SIOCGSTAMPNS   0x8907          /* Get stamp (timespec) */
+
+#endif /* _ASM_SOCKIOS_H */
diff --git a/include/asm-mn10300/spinlock.h b/include/asm-mn10300/spinlock.h
new file mode 100644 (file)
index 0000000..4bf9c8b
--- /dev/null
@@ -0,0 +1,16 @@
+/* MN10300 spinlock support
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_SPINLOCK_H
+#define _ASM_SPINLOCK_H
+
+#error SMP spinlocks not implemented for MN10300
+
+#endif /* _ASM_SPINLOCK_H */
diff --git a/include/asm-mn10300/stat.h b/include/asm-mn10300/stat.h
new file mode 100644 (file)
index 0000000..63ff837
--- /dev/null
@@ -0,0 +1,78 @@
+#ifndef _ASM_STAT_H
+#define _ASM_STAT_H
+
+struct __old_kernel_stat {
+       unsigned short st_dev;
+       unsigned short st_ino;
+       unsigned short st_mode;
+       unsigned short st_nlink;
+       unsigned short st_uid;
+       unsigned short st_gid;
+       unsigned short st_rdev;
+       unsigned long  st_size;
+       unsigned long  st_atime;
+       unsigned long  st_mtime;
+       unsigned long  st_ctime;
+};
+
+struct stat {
+       unsigned long  st_dev;
+       unsigned long  st_ino;
+       unsigned short st_mode;
+       unsigned short st_nlink;
+       unsigned short st_uid;
+       unsigned short st_gid;
+       unsigned long  st_rdev;
+       unsigned long  st_size;
+       unsigned long  st_blksize;
+       unsigned long  st_blocks;
+       unsigned long  st_atime;
+       unsigned long  st_atime_nsec;
+       unsigned long  st_mtime;
+       unsigned long  st_mtime_nsec;
+       unsigned long  st_ctime;
+       unsigned long  st_ctime_nsec;
+       unsigned long  __unused4;
+       unsigned long  __unused5;
+};
+
+/* This matches struct stat64 in glibc2.1, hence the absolutely
+ * insane amounts of padding around dev_t's.
+ */
+struct stat64 {
+       unsigned long long      st_dev;
+       unsigned char   __pad0[4];
+
+#define STAT64_HAS_BROKEN_ST_INO       1
+       unsigned long   __st_ino;
+
+       unsigned int    st_mode;
+       unsigned int    st_nlink;
+
+       unsigned long   st_uid;
+       unsigned long   st_gid;
+
+       unsigned long long      st_rdev;
+       unsigned char   __pad3[4];
+
+       long long       st_size;
+       unsigned long   st_blksize;
+
+       unsigned long   st_blocks;      /* Number 512-byte blocks allocated. */
+       unsigned long   __pad4;         /* future possible st_blocks high bits */
+
+       unsigned long   st_atime;
+       unsigned long   st_atime_nsec;
+
+       unsigned long   st_mtime;
+       unsigned int    st_mtime_nsec;
+
+       unsigned long   st_ctime;
+       unsigned long   st_ctime_nsec;
+
+       unsigned long long      st_ino;
+};
+
+#define STAT_HAVE_NSEC 1
+
+#endif /* _ASM_STAT_H */
diff --git a/include/asm-mn10300/statfs.h b/include/asm-mn10300/statfs.h
new file mode 100644 (file)
index 0000000..0b91fe1
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/statfs.h>
diff --git a/include/asm-mn10300/string.h b/include/asm-mn10300/string.h
new file mode 100644 (file)
index 0000000..47dbd43
--- /dev/null
@@ -0,0 +1,32 @@
+/* MN10300 Optimised string functions
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Modified by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_STRING_H
+#define _ASM_STRING_H
+
+#define __HAVE_ARCH_MEMSET
+#define __HAVE_ARCH_MEMCPY
+#define __HAVE_ARCH_MEMMOVE
+
+extern void *memset(void *dest, int ch, size_t count);
+extern void *memcpy(void *dest, const void *src, size_t count);
+extern void *memmove(void *dest, const void *src, size_t count);
+
+
+extern void __struct_cpy_bug(void);
+#define struct_cpy(x, y)                       \
+({                                              \
+       if (sizeof(*(x)) != sizeof(*(y)))       \
+               __struct_cpy_bug;               \
+       memcpy(x, y, sizeof(*(x)));             \
+})
+
+#endif /* _ASM_STRING_H */
diff --git a/include/asm-mn10300/system.h b/include/asm-mn10300/system.h
new file mode 100644 (file)
index 0000000..8214fb7
--- /dev/null
@@ -0,0 +1,237 @@
+/* MN10300 System definitions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_SYSTEM_H
+#define _ASM_SYSTEM_H
+
+#include <asm/cpu-regs.h>
+
+#ifdef __KERNEL__
+#ifndef __ASSEMBLY__
+
+#include <linux/kernel.h>
+
+struct task_struct;
+struct thread_struct;
+
+extern asmlinkage
+struct task_struct *__switch_to(struct thread_struct *prev,
+                               struct thread_struct *next,
+                               struct task_struct *prev_task);
+
+/* context switching is now performed out-of-line in switch_to.S */
+#define switch_to(prev, next, last)                                    \
+do {                                                                   \
+       current->thread.wchan = (u_long) __builtin_return_address(0);   \
+       (last) = __switch_to(&(prev)->thread, &(next)->thread, (prev)); \
+       mb();                                                           \
+       current->thread.wchan = 0;                                      \
+} while (0)
+
+#define arch_align_stack(x) (x)
+
+#define nop() asm volatile ("nop")
+
+#endif /* !__ASSEMBLY__ */
+
+/*
+ * Force strict CPU ordering.
+ * And yes, this is required on UP too when we're talking
+ * to devices.
+ *
+ * For now, "wmb()" doesn't actually do anything, as all
+ * Intel CPU's follow what Intel calls a *Processor Order*,
+ * in which all writes are seen in the program order even
+ * outside the CPU.
+ *
+ * I expect future Intel CPU's to have a weaker ordering,
+ * but I'd also expect them to finally get their act together
+ * and add some real memory barriers if so.
+ *
+ * Some non intel clones support out of order store. wmb() ceases to be a
+ * nop for these.
+ */
+
+#define mb()   asm volatile ("": : :"memory")
+#define rmb()  mb()
+#define wmb()  asm volatile ("": : :"memory")
+
+#ifdef CONFIG_SMP
+#define smp_mb()       mb()
+#define smp_rmb()      rmb()
+#define smp_wmb()      wmb()
+#else
+#define smp_mb()       barrier()
+#define smp_rmb()      barrier()
+#define smp_wmb()      barrier()
+#endif
+
+#define set_mb(var, value)  do { var = value;  mb(); } while (0)
+#define set_wmb(var, value) do { var = value; wmb(); } while (0)
+
+#define read_barrier_depends()         do {} while (0)
+#define smp_read_barrier_depends()     do {} while (0)
+
+/*****************************************************************************/
+/*
+ * interrupt control
+ * - "disabled": run in IM1/2
+ *   - level 0 - GDB stub
+ *   - level 1 - virtual serial DMA (if present)
+ *   - level 5 - normal interrupt priority
+ *   - level 6 - timer interrupt
+ * - "enabled":  run in IM7
+ */
+#ifdef CONFIG_MN10300_TTYSM
+#define MN10300_CLI_LEVEL      EPSW_IM_2
+#else
+#define MN10300_CLI_LEVEL      EPSW_IM_1
+#endif
+
+#define local_save_flags(x)                    \
+do {                                           \
+       typecheck(unsigned long, x);            \
+       asm volatile(                           \
+               "       mov epsw,%0     \n"     \
+               : "=d"(x)                       \
+               );                              \
+} while (0)
+
+#define local_irq_disable()                                            \
+do {                                                                   \
+       asm volatile(                                                   \
+               "       and %0,epsw     \n"                             \
+               "       or %1,epsw      \n"                             \
+               "       nop             \n"                             \
+               "       nop             \n"                             \
+               "       nop             \n"                             \
+               :                                                       \
+               : "i"(~EPSW_IM), "i"(EPSW_IE | MN10300_CLI_LEVEL)       \
+               );                                                      \
+} while (0)
+
+#define local_irq_save(x)                      \
+do {                                           \
+       local_save_flags(x);                    \
+       local_irq_disable();                    \
+} while (0)
+
+/*
+ * we make sure local_irq_enable() doesn't cause priority inversion
+ */
+#ifndef __ASSEMBLY__
+
+extern unsigned long __mn10300_irq_enabled_epsw;
+
+#endif
+
+#define local_irq_enable()                                             \
+do {                                                                   \
+       unsigned long tmp;                                              \
+                                                                       \
+       asm volatile(                                                   \
+               "       mov     epsw,%0         \n"                     \
+               "       and     %1,%0           \n"                     \
+               "       or      %2,%0           \n"                     \
+               "       mov     %0,epsw         \n"                     \
+               : "=&d"(tmp)                                            \
+               : "i"(~EPSW_IM), "r"(__mn10300_irq_enabled_epsw)        \
+               );                                                      \
+} while (0)
+
+#define local_irq_restore(x)                   \
+do {                                           \
+       typecheck(unsigned long, x);            \
+       asm volatile(                           \
+               "       mov %0,epsw     \n"     \
+               "       nop             \n"     \
+               "       nop             \n"     \
+               "       nop             \n"     \
+               :                               \
+               : "d"(x)                        \
+               : "memory", "cc"                \
+               );                              \
+} while (0)
+
+#define irqs_disabled()                                \
+({                                             \
+       unsigned long flags;                    \
+       local_save_flags(flags);                \
+       (flags & EPSW_IM) <= MN10300_CLI_LEVEL; \
+})
+
+/* hook to save power by halting the CPU
+ * - called from the idle loop
+ * - must reenable interrupts (which takes three instruction cycles to complete)
+ */
+#define safe_halt()                                                    \
+do {                                                                   \
+       asm volatile("  or      %0,epsw \n"                             \
+                    "  nop             \n"                             \
+                    "  nop             \n"                             \
+                    "  bset    %2,(%1) \n"                             \
+                    :                                                  \
+                    : "i"(EPSW_IE|EPSW_IM), "n"(&CPUM), "i"(CPUM_SLEEP)\
+                    : "cc"                                             \
+                    );                                                 \
+} while (0)
+
+#define STI    or EPSW_IE|EPSW_IM,epsw
+#define CLI    and ~EPSW_IM,epsw; or EPSW_IE|MN10300_CLI_LEVEL,epsw; nop; nop; nop
+
+/*****************************************************************************/
+/*
+ * MN10300 doesn't actually have an exchange instruction
+ */
+#ifndef __ASSEMBLY__
+
+struct __xchg_dummy { unsigned long a[100]; };
+#define __xg(x) ((struct __xchg_dummy *)(x))
+
+static inline
+unsigned long __xchg(volatile unsigned long *m, unsigned long val)
+{
+       unsigned long retval;
+       unsigned long flags;
+
+       local_irq_save(flags);
+       retval = *m;
+       *m = val;
+       local_irq_restore(flags);
+       return retval;
+}
+
+#define xchg(ptr, v)                                           \
+       ((__typeof__(*(ptr))) __xchg((unsigned long *)(ptr),    \
+                                    (unsigned long)(v)))
+
+static inline unsigned long __cmpxchg(volatile unsigned long *m,
+                                     unsigned long old, unsigned long new)
+{
+       unsigned long retval;
+       unsigned long flags;
+
+       local_irq_save(flags);
+       retval = *m;
+       if (retval == old)
+               *m = new;
+       local_irq_restore(flags);
+       return retval;
+}
+
+#define cmpxchg(ptr, o, n)                                     \
+       ((__typeof__(*(ptr))) __cmpxchg((unsigned long *)(ptr), \
+                                       (unsigned long)(o),     \
+                                       (unsigned long)(n)))
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* __KERNEL__ */
+#endif /* _ASM_SYSTEM_H */
diff --git a/include/asm-mn10300/termbits.h b/include/asm-mn10300/termbits.h
new file mode 100644 (file)
index 0000000..eb2b0dc
--- /dev/null
@@ -0,0 +1,200 @@
+#ifndef _ASM_TERMBITS_H
+#define _ASM_TERMBITS_H
+
+#include <linux/posix_types.h>
+
+typedef unsigned char  cc_t;
+typedef unsigned int   speed_t;
+typedef unsigned int   tcflag_t;
+
+#define NCCS 19
+struct termios {
+       tcflag_t c_iflag;               /* input mode flags */
+       tcflag_t c_oflag;               /* output mode flags */
+       tcflag_t c_cflag;               /* control mode flags */
+       tcflag_t c_lflag;               /* local mode flags */
+       cc_t c_line;                    /* line discipline */
+       cc_t c_cc[NCCS];                /* control characters */
+};
+
+struct termios2 {
+       tcflag_t c_iflag;               /* input mode flags */
+       tcflag_t c_oflag;               /* output mode flags */
+       tcflag_t c_cflag;               /* control mode flags */
+       tcflag_t c_lflag;               /* local mode flags */
+       cc_t c_line;                    /* line discipline */
+       cc_t c_cc[NCCS];                /* control characters */
+       speed_t c_ispeed;               /* input speed */
+       speed_t c_ospeed;               /* output speed */
+};
+
+struct ktermios {
+       tcflag_t c_iflag;               /* input mode flags */
+       tcflag_t c_oflag;               /* output mode flags */
+       tcflag_t c_cflag;               /* control mode flags */
+       tcflag_t c_lflag;               /* local mode flags */
+       cc_t c_line;                    /* line discipline */
+       cc_t c_cc[NCCS];                /* control characters */
+       speed_t c_ispeed;               /* input speed */
+       speed_t c_ospeed;               /* output speed */
+};
+
+/* c_cc characters */
+#define VINTR 0
+#define VQUIT 1
+#define VERASE 2
+#define VKILL 3
+#define VEOF 4
+#define VTIME 5
+#define VMIN 6
+#define VSWTC 7
+#define VSTART 8
+#define VSTOP 9
+#define VSUSP 10
+#define VEOL 11
+#define VREPRINT 12
+#define VDISCARD 13
+#define VWERASE 14
+#define VLNEXT 15
+#define VEOL2 16
+
+
+/* c_iflag bits */
+#define IGNBRK 0000001
+#define BRKINT 0000002
+#define IGNPAR 0000004
+#define PARMRK 0000010
+#define INPCK  0000020
+#define ISTRIP 0000040
+#define INLCR  0000100
+#define IGNCR  0000200
+#define ICRNL  0000400
+#define IUCLC  0001000
+#define IXON   0002000
+#define IXANY  0004000
+#define IXOFF  0010000
+#define IMAXBEL        0020000
+#define IUTF8  0040000
+
+/* c_oflag bits */
+#define OPOST  0000001
+#define OLCUC  0000002
+#define ONLCR  0000004
+#define OCRNL  0000010
+#define ONOCR  0000020
+#define ONLRET 0000040
+#define OFILL  0000100
+#define OFDEL  0000200
+#define NLDLY  0000400
+#define   NL0  0000000
+#define   NL1  0000400
+#define CRDLY  0003000
+#define   CR0  0000000
+#define   CR1  0001000
+#define   CR2  0002000
+#define   CR3  0003000
+#define TABDLY 0014000
+#define   TAB0 0000000
+#define   TAB1 0004000
+#define   TAB2 0010000
+#define   TAB3 0014000
+#define   XTABS        0014000
+#define BSDLY  0020000
+#define   BS0  0000000
+#define   BS1  0020000
+#define VTDLY  0040000
+#define   VT0  0000000
+#define   VT1  0040000
+#define FFDLY  0100000
+#define   FF0  0000000
+#define   FF1  0100000
+
+/* c_cflag bit meaning */
+#define CBAUD  0010017
+#define  B0    0000000         /* hang up */
+#define  B50   0000001
+#define  B75   0000002
+#define  B110  0000003
+#define  B134  0000004
+#define  B150  0000005
+#define  B200  0000006
+#define  B300  0000007
+#define  B600  0000010
+#define  B1200 0000011
+#define  B1800 0000012
+#define  B2400 0000013
+#define  B4800 0000014
+#define  B9600 0000015
+#define  B19200        0000016
+#define  B38400        0000017
+#define EXTA B19200
+#define EXTB B38400
+#define CSIZE  0000060
+#define   CS5  0000000
+#define   CS6  0000020
+#define   CS7  0000040
+#define   CS8  0000060
+#define CSTOPB 0000100
+#define CREAD  0000200
+#define PARENB 0000400
+#define PARODD 0001000
+#define HUPCL  0002000
+#define CLOCAL 0004000
+#define CBAUDEX 0010000
+#define   BOTHER  0010000
+#define    B57600 0010001
+#define   B115200 0010002
+#define   B230400 0010003
+#define   B460800 0010004
+#define   B500000 0010005
+#define   B576000 0010006
+#define   B921600 0010007
+#define  B1000000 0010010
+#define  B1152000 0010011
+#define  B1500000 0010012
+#define  B2000000 0010013
+#define  B2500000 0010014
+#define  B3000000 0010015
+#define  B3500000 0010016
+#define  B4000000 0010017
+#define CIBAUD   002003600000  /* input baud rate (not used) */
+#define CTVB     004000000000          /* VisioBraille Terminal flow control */
+#define CMSPAR   010000000000          /* mark or space (stick) parity */
+#define CRTSCTS          020000000000          /* flow control */
+
+#define IBSHIFT          16            /* Shift from CBAUD to CIBAUD */
+
+/* c_lflag bits */
+#define ISIG   0000001
+#define ICANON 0000002
+#define XCASE  0000004
+#define ECHO   0000010
+#define ECHOE  0000020
+#define ECHOK  0000040
+#define ECHONL 0000100
+#define NOFLSH 0000200
+#define TOSTOP 0000400
+#define ECHOCTL        0001000
+#define ECHOPRT        0002000
+#define ECHOKE 0004000
+#define FLUSHO 0010000
+#define PENDIN 0040000
+#define IEXTEN 0100000
+
+/* tcflow() and TCXONC use these */
+#define        TCOOFF          0
+#define        TCOON           1
+#define        TCIOFF          2
+#define        TCION           3
+
+/* tcflush() and TCFLSH use these */
+#define        TCIFLUSH        0
+#define        TCOFLUSH        1
+#define        TCIOFLUSH       2
+
+/* tcsetattr uses these */
+#define        TCSANOW         0
+#define        TCSADRAIN       1
+#define        TCSAFLUSH       2
+
+#endif /* _ASM_TERMBITS_H */
diff --git a/include/asm-mn10300/termios.h b/include/asm-mn10300/termios.h
new file mode 100644 (file)
index 0000000..dd7cf61
--- /dev/null
@@ -0,0 +1,92 @@
+#ifndef _ASM_TERMIOS_H
+#define _ASM_TERMIOS_H
+
+#include <asm/termbits.h>
+#include <asm/ioctls.h>
+
+struct winsize {
+       unsigned short ws_row;
+       unsigned short ws_col;
+       unsigned short ws_xpixel;
+       unsigned short ws_ypixel;
+};
+
+#define NCC 8
+struct termio {
+       unsigned short c_iflag;         /* input mode flags */
+       unsigned short c_oflag;         /* output mode flags */
+       unsigned short c_cflag;         /* control mode flags */
+       unsigned short c_lflag;         /* local mode flags */
+       unsigned char c_line;           /* line discipline */
+       unsigned char c_cc[NCC];        /* control characters */
+};
+
+#ifdef __KERNEL__
+/*     intr=^C         quit=^|         erase=del       kill=^U
+       eof=^D          vtime=\0        vmin=\1         sxtc=\0
+       start=^Q        stop=^S         susp=^Z         eol=\0
+       reprint=^R      discard=^U      werase=^W       lnext=^V
+       eol2=\0
+*/
+#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
+#endif
+
+/* modem lines */
+#define TIOCM_LE       0x001
+#define TIOCM_DTR      0x002
+#define TIOCM_RTS      0x004
+#define TIOCM_ST       0x008
+#define TIOCM_SR       0x010
+#define TIOCM_CTS      0x020
+#define TIOCM_CAR      0x040
+#define TIOCM_RNG      0x080
+#define TIOCM_DSR      0x100
+#define TIOCM_CD       TIOCM_CAR
+#define TIOCM_RI       TIOCM_RNG
+#define TIOCM_OUT1     0x2000
+#define TIOCM_OUT2     0x4000
+#define TIOCM_LOOP     0x8000
+
+#define TIOCM_MODEM_BITS       TIOCM_OUT2      /* IRDA support */
+
+/*
+ * Translate a "termio" structure into a "termios". Ugh.
+ */
+#define SET_LOW_TERMIOS_BITS(termios, termio, x) { \
+       unsigned short __tmp; \
+       get_user(__tmp, &(termio)->x); \
+       *(unsigned short *) &(termios)->x = __tmp; \
+}
+
+#define user_termio_to_kernel_termios(termios, termio) \
+({ \
+       SET_LOW_TERMIOS_BITS(termios, termio, c_iflag); \
+       SET_LOW_TERMIOS_BITS(termios, termio, c_oflag); \
+       SET_LOW_TERMIOS_BITS(termios, termio, c_cflag); \
+       SET_LOW_TERMIOS_BITS(termios, termio, c_lflag); \
+       copy_from_user((termios)->c_cc, (termio)->c_cc, NCC); \
+})
+
+/*
+ * Translate a "termios" structure into a "termio". Ugh.
+ */
+#define kernel_termios_to_user_termio(termio, termios) \
+({ \
+       put_user((termios)->c_iflag, &(termio)->c_iflag); \
+       put_user((termios)->c_oflag, &(termio)->c_oflag); \
+       put_user((termios)->c_cflag, &(termio)->c_cflag); \
+       put_user((termios)->c_lflag, &(termio)->c_lflag); \
+       put_user((termios)->c_line,  &(termio)->c_line); \
+       copy_to_user((termio)->c_cc, (termios)->c_cc, NCC); \
+})
+
+#define user_termios_to_kernel_termios(k, u) \
+       copy_from_user(k, u, sizeof(struct termios2))
+#define kernel_termios_to_user_termios(u, k) \
+       copy_to_user(u, k, sizeof(struct termios2))
+#define user_termios_to_kernel_termios_1(k, u) \
+       copy_from_user(k, u, sizeof(struct termios))
+#define kernel_termios_to_user_termios_1(u, k) \
+       copy_to_user(u, k, sizeof(struct termios))
+
+#endif /* _ASM_TERMIOS_H */
diff --git a/include/asm-mn10300/thread_info.h b/include/asm-mn10300/thread_info.h
new file mode 100644 (file)
index 0000000..e397e71
--- /dev/null
@@ -0,0 +1,168 @@
+/* MN10300 Low-level thread information
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_THREAD_INFO_H
+#define _ASM_THREAD_INFO_H
+
+#ifdef __KERNEL__
+
+#include <asm/page.h>
+
+#ifndef __ASSEMBLY__
+#include <asm/processor.h>
+#endif
+
+#define PREEMPT_ACTIVE         0x10000000
+
+#ifdef CONFIG_4KSTACKS
+#define THREAD_SIZE            (4096)
+#else
+#define THREAD_SIZE            (8192)
+#endif
+
+#define STACK_WARN             (THREAD_SIZE / 8)
+
+/*
+ * low level task data that entry.S needs immediate access to
+ * - this struct should fit entirely inside of one cache line
+ * - this struct shares the supervisor stack pages
+ * - if the contents of this structure are changed, the assembly constants
+ *   must also be changed
+ */
+#ifndef __ASSEMBLY__
+
+struct thread_info {
+       struct task_struct      *task;          /* main task structure */
+       struct exec_domain      *exec_domain;   /* execution domain */
+       unsigned long           flags;          /* low level flags */
+       __u32                   cpu;            /* current CPU */
+       __s32                   preempt_count;  /* 0 => preemptable, <0 => BUG */
+
+       mm_segment_t            addr_limit;     /* thread address space:
+                                                  0-0xBFFFFFFF for user-thead
+                                                  0-0xFFFFFFFF for kernel-thread
+                                               */
+       struct restart_block    restart_block;
+
+       __u8                    supervisor_stack[0];
+};
+
+#else /* !__ASSEMBLY__ */
+
+#ifndef __ASM_OFFSETS_H__
+#include <asm/asm-offsets.h>
+#endif
+
+#endif
+
+/*
+ * macros/functions for gaining access to the thread information structure
+ *
+ * preempt_count needs to be 1 initially, until the scheduler is functional.
+ */
+#ifndef __ASSEMBLY__
+
+#define INIT_THREAD_INFO(tsk)                  \
+{                                              \
+       .task           = &tsk,                 \
+       .exec_domain    = &default_exec_domain, \
+       .flags          = 0,                    \
+       .cpu            = 0,                    \
+       .preempt_count  = 1,                    \
+       .addr_limit     = KERNEL_DS,            \
+       .restart_block = {                      \
+               .fn = do_no_restart_syscall,    \
+       },                                      \
+}
+
+#define init_thread_info       (init_thread_union.thread_info)
+#define init_stack             (init_thread_union.stack)
+#define init_uregs                                                     \
+       ((struct pt_regs *)                                             \
+        ((unsigned long) init_stack + THREAD_SIZE - sizeof(struct pt_regs)))
+
+extern struct thread_info *__current_ti;
+
+/* how to get the thread information struct from C */
+static inline __attribute__((const))
+struct thread_info *current_thread_info(void)
+{
+       struct thread_info *ti;
+       asm("mov sp,%0\n"
+           "and %1,%0\n"
+           : "=d" (ti)
+           : "i" (~(THREAD_SIZE - 1))
+           : "cc");
+       return ti;
+}
+
+/* how to get the current stack pointer from C */
+static inline unsigned long current_stack_pointer(void)
+{
+       unsigned long sp;
+       asm("mov sp,%0; ":"=r" (sp));
+       return sp;
+}
+
+/* thread information allocation */
+#ifdef CONFIG_DEBUG_STACK_USAGE
+#define alloc_thread_info(tsk) kzalloc(THREAD_SIZE, GFP_KERNEL)
+#else
+#define alloc_thread_info(tsk) kmalloc(THREAD_SIZE, GFP_KERNEL)
+#endif
+
+#define free_thread_info(ti)   kfree((ti))
+#define get_thread_info(ti)    get_task_struct((ti)->task)
+#define put_thread_info(ti)    put_task_struct((ti)->task)
+
+#else /* !__ASSEMBLY__ */
+
+#ifndef __VMLINUX_LDS__
+/* how to get the thread information struct from ASM */
+.macro GET_THREAD_INFO reg
+       mov     sp,\reg
+       and     -THREAD_SIZE,\reg
+.endm
+#endif
+#endif
+
+/*
+ * thread information flags
+ * - these are process state flags that various assembly files may need to
+ *   access
+ * - pending work-to-be-done flags are in LSW
+ * - other flags in MSW
+ */
+#define TIF_SYSCALL_TRACE      0       /* syscall trace active */
+#define TIF_NOTIFY_RESUME      1       /* resumption notification requested */
+#define TIF_SIGPENDING         2       /* signal pending */
+#define TIF_NEED_RESCHED       3       /* rescheduling necessary */
+#define TIF_SINGLESTEP         4       /* restore singlestep on return to user mode */
+#define TIF_RESTORE_SIGMASK    5       /* restore signal mask in do_signal() */
+#define TIF_POLLING_NRFLAG     16      /* true if poll_idle() is polling TIF_NEED_RESCHED */
+#define TIF_MEMDIE             17      /* OOM killer killed process */
+#define TIF_FREEZE             18      /* freezing for suspend */
+
+#define _TIF_SYSCALL_TRACE     +(1 << TIF_SYSCALL_TRACE)
+#define _TIF_NOTIFY_RESUME     +(1 << TIF_NOTIFY_RESUME)
+#define _TIF_SIGPENDING                +(1 << TIF_SIGPENDING)
+#define _TIF_NEED_RESCHED      +(1 << TIF_NEED_RESCHED)
+#define _TIF_SINGLESTEP                +(1 << TIF_SINGLESTEP)
+#define _TIF_RESTORE_SIGMASK   +(1 << TIF_RESTORE_SIGMASK)
+#define _TIF_POLLING_NRFLAG    +(1 << TIF_POLLING_NRFLAG)
+#define _TIF_FREEZE            +(1 << TIF_FREEZE)
+
+#define _TIF_WORK_MASK         0x0000FFFE      /* work to do on interrupt/exception return */
+#define _TIF_ALLWORK_MASK      0x0000FFFF      /* work to do on any return to u-space */
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_THREAD_INFO_H */
diff --git a/include/asm-mn10300/timer-regs.h b/include/asm-mn10300/timer-regs.h
new file mode 100644 (file)
index 0000000..1d883b7
--- /dev/null
@@ -0,0 +1,293 @@
+/* AM33v2 on-board timer module registers
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_TIMER_REGS_H
+#define _ASM_TIMER_REGS_H
+
+#include <asm/cpu-regs.h>
+#include <asm/intctl-regs.h>
+
+#ifdef __KERNEL__
+
+/* timer prescalar control */
+#define        TMPSCNT                 __SYSREG(0xd4003071, u8) /* timer prescaler control */
+#define        TMPSCNT_ENABLE          0x80    /* timer prescaler enable */
+#define        TMPSCNT_DISABLE         0x00    /* timer prescaler disable */
+
+/* 8 bit timers */
+#define        TM0MD                   __SYSREG(0xd4003000, u8) /* timer 0 mode register */
+#define        TM0MD_SRC               0x07    /* timer source */
+#define        TM0MD_SRC_IOCLK         0x00    /* - IOCLK */
+#define        TM0MD_SRC_IOCLK_8       0x01    /* - 1/8 IOCLK */
+#define        TM0MD_SRC_IOCLK_32      0x02    /* - 1/32 IOCLK */
+#define        TM0MD_SRC_TM2IO         0x03    /* - TM2IO pin input */
+#define        TM0MD_SRC_TM1UFLOW      0x05    /* - timer 1 underflow */
+#define        TM0MD_SRC_TM2UFLOW      0x06    /* - timer 2 underflow */
+#define        TM0MD_SRC_TM0IO         0x07    /* - TM0IO pin input */
+#define        TM0MD_INIT_COUNTER      0x40    /* initialize TMnBC = TMnBR */
+#define        TM0MD_COUNT_ENABLE      0x80    /* timer count enable */
+
+#define        TM1MD                   __SYSREG(0xd4003001, u8) /* timer 1 mode register */
+#define        TM1MD_SRC               0x07    /* timer source */
+#define        TM1MD_SRC_IOCLK         0x00    /* - IOCLK */
+#define        TM1MD_SRC_IOCLK_8       0x01    /* - 1/8 IOCLK */
+#define        TM1MD_SRC_IOCLK_32      0x02    /* - 1/32 IOCLK */
+#define        TM1MD_SRC_TM0CASCADE    0x03    /* - cascade with timer 0 */
+#define        TM1MD_SRC_TM0UFLOW      0x04    /* - timer 0 underflow */
+#define        TM1MD_SRC_TM2UFLOW      0x06    /* - timer 2 underflow */
+#define        TM1MD_SRC_TM1IO         0x07    /* - TM1IO pin input */
+#define        TM1MD_INIT_COUNTER      0x40    /* initialize TMnBC = TMnBR */
+#define        TM1MD_COUNT_ENABLE      0x80    /* timer count enable */
+
+#define        TM2MD                   __SYSREG(0xd4003002, u8) /* timer 2 mode register */
+#define        TM2MD_SRC               0x07    /* timer source */
+#define        TM2MD_SRC_IOCLK         0x00    /* - IOCLK */
+#define        TM2MD_SRC_IOCLK_8       0x01    /* - 1/8 IOCLK */
+#define        TM2MD_SRC_IOCLK_32      0x02    /* - 1/32 IOCLK */
+#define        TM2MD_SRC_TM1CASCADE    0x03    /* - cascade with timer 1 */
+#define        TM2MD_SRC_TM0UFLOW      0x04    /* - timer 0 underflow */
+#define        TM2MD_SRC_TM1UFLOW      0x05    /* - timer 1 underflow */
+#define        TM2MD_SRC_TM2IO         0x07    /* - TM2IO pin input */
+#define        TM2MD_INIT_COUNTER      0x40    /* initialize TMnBC = TMnBR */
+#define        TM2MD_COUNT_ENABLE      0x80    /* timer count enable */
+
+#define        TM3MD                   __SYSREG(0xd4003003, u8) /* timer 3 mode register */
+#define        TM3MD_SRC               0x07    /* timer source */
+#define        TM3MD_SRC_IOCLK         0x00    /* - IOCLK */
+#define        TM3MD_SRC_IOCLK_8       0x01    /* - 1/8 IOCLK */
+#define        TM3MD_SRC_IOCLK_32      0x02    /* - 1/32 IOCLK */
+#define        TM3MD_SRC_TM1CASCADE    0x03    /* - cascade with timer 2 */
+#define        TM3MD_SRC_TM0UFLOW      0x04    /* - timer 0 underflow */
+#define        TM3MD_SRC_TM1UFLOW      0x05    /* - timer 1 underflow */
+#define        TM3MD_SRC_TM2UFLOW      0x06    /* - timer 2 underflow */
+#define        TM3MD_SRC_TM3IO         0x07    /* - TM3IO pin input */
+#define        TM3MD_INIT_COUNTER      0x40    /* initialize TMnBC = TMnBR */
+#define        TM3MD_COUNT_ENABLE      0x80    /* timer count enable */
+
+#define        TM01MD                  __SYSREG(0xd4003000, u16)  /* timer 0:1 mode register */
+
+#define        TM0BR                   __SYSREG(0xd4003010, u8)   /* timer 0 base register */
+#define        TM1BR                   __SYSREG(0xd4003011, u8)   /* timer 1 base register */
+#define        TM2BR                   __SYSREG(0xd4003012, u8)   /* timer 2 base register */
+#define        TM3BR                   __SYSREG(0xd4003013, u8)   /* timer 3 base register */
+#define        TM01BR                  __SYSREG(0xd4003010, u16)  /* timer 0:1 base register */
+
+#define        TM0BC                   __SYSREGC(0xd4003020, u8)  /* timer 0 binary counter */
+#define        TM1BC                   __SYSREGC(0xd4003021, u8)  /* timer 1 binary counter */
+#define        TM2BC                   __SYSREGC(0xd4003022, u8)  /* timer 2 binary counter */
+#define        TM3BC                   __SYSREGC(0xd4003023, u8)  /* timer 3 binary counter */
+#define        TM01BC                  __SYSREGC(0xd4003020, u16) /* timer 0:1 binary counter */
+
+#define TM0IRQ                 2       /* timer 0 IRQ */
+#define TM1IRQ                 3       /* timer 1 IRQ */
+#define TM2IRQ                 4       /* timer 2 IRQ */
+#define TM3IRQ                 5       /* timer 3 IRQ */
+
+#define        TM0ICR                  GxICR(TM0IRQ)   /* timer 0 uflow intr ctrl reg */
+#define        TM1ICR                  GxICR(TM1IRQ)   /* timer 1 uflow intr ctrl reg */
+#define        TM2ICR                  GxICR(TM2IRQ)   /* timer 2 uflow intr ctrl reg */
+#define        TM3ICR                  GxICR(TM3IRQ)   /* timer 3 uflow intr ctrl reg */
+
+/* 16-bit timers 4,5 & 7-11 */
+#define        TM4MD                   __SYSREG(0xd4003080, u8)   /* timer 4 mode register */
+#define        TM4MD_SRC               0x07    /* timer source */
+#define        TM4MD_SRC_IOCLK         0x00    /* - IOCLK */
+#define        TM4MD_SRC_IOCLK_8       0x01    /* - 1/8 IOCLK */
+#define        TM4MD_SRC_IOCLK_32      0x02    /* - 1/32 IOCLK */
+#define        TM4MD_SRC_TM0UFLOW      0x04    /* - timer 0 underflow */
+#define        TM4MD_SRC_TM1UFLOW      0x05    /* - timer 1 underflow */
+#define        TM4MD_SRC_TM2UFLOW      0x06    /* - timer 2 underflow */
+#define        TM4MD_SRC_TM4IO         0x07    /* - TM4IO pin input */
+#define        TM4MD_INIT_COUNTER      0x40    /* initialize TMnBC = TMnBR */
+#define        TM4MD_COUNT_ENABLE      0x80    /* timer count enable */
+
+#define        TM5MD                   __SYSREG(0xd4003082, u8)   /* timer 5 mode register */
+#define        TM5MD_SRC               0x07    /* timer source */
+#define        TM5MD_SRC_IOCLK         0x00    /* - IOCLK */
+#define        TM5MD_SRC_IOCLK_8       0x01    /* - 1/8 IOCLK */
+#define        TM5MD_SRC_IOCLK_32      0x02    /* - 1/32 IOCLK */
+#define        TM5MD_SRC_TM4CASCADE    0x03    /* - cascade with timer 4 */
+#define        TM5MD_SRC_TM0UFLOW      0x04    /* - timer 0 underflow */
+#define        TM5MD_SRC_TM1UFLOW      0x05    /* - timer 1 underflow */
+#define        TM5MD_SRC_TM2UFLOW      0x06    /* - timer 2 underflow */
+#define        TM5MD_SRC_TM5IO         0x07    /* - TM5IO pin input */
+#define        TM5MD_INIT_COUNTER      0x40    /* initialize TMnBC = TMnBR */
+#define        TM5MD_COUNT_ENABLE      0x80    /* timer count enable */
+
+#define        TM7MD                   __SYSREG(0xd4003086, u8)   /* timer 7 mode register */
+#define        TM7MD_SRC               0x07    /* timer source */
+#define        TM7MD_SRC_IOCLK         0x00    /* - IOCLK */
+#define        TM7MD_SRC_IOCLK_8       0x01    /* - 1/8 IOCLK */
+#define        TM7MD_SRC_IOCLK_32      0x02    /* - 1/32 IOCLK */
+#define        TM7MD_SRC_TM0UFLOW      0x04    /* - timer 0 underflow */
+#define        TM7MD_SRC_TM1UFLOW      0x05    /* - timer 1 underflow */
+#define        TM7MD_SRC_TM2UFLOW      0x06    /* - timer 2 underflow */
+#define        TM7MD_SRC_TM7IO         0x07    /* - TM7IO pin input */
+#define        TM7MD_INIT_COUNTER      0x40    /* initialize TMnBC = TMnBR */
+#define        TM7MD_COUNT_ENABLE      0x80    /* timer count enable */
+
+#define        TM8MD                   __SYSREG(0xd4003088, u8)   /* timer 8 mode register */
+#define        TM8MD_SRC               0x07    /* timer source */
+#define        TM8MD_SRC_IOCLK         0x00    /* - IOCLK */
+#define        TM8MD_SRC_IOCLK_8       0x01    /* - 1/8 IOCLK */
+#define        TM8MD_SRC_IOCLK_32      0x02    /* - 1/32 IOCLK */
+#define        TM8MD_SRC_TM7CASCADE    0x03    /* - cascade with timer 7 */
+#define        TM8MD_SRC_TM0UFLOW      0x04    /* - timer 0 underflow */
+#define        TM8MD_SRC_TM1UFLOW      0x05    /* - timer 1 underflow */
+#define        TM8MD_SRC_TM2UFLOW      0x06    /* - timer 2 underflow */
+#define        TM8MD_SRC_TM8IO         0x07    /* - TM8IO pin input */
+#define        TM8MD_INIT_COUNTER      0x40    /* initialize TMnBC = TMnBR */
+#define        TM8MD_COUNT_ENABLE      0x80    /* timer count enable */
+
+#define        TM9MD                   __SYSREG(0xd400308a, u8)   /* timer 9 mode register */
+#define        TM9MD_SRC               0x07    /* timer source */
+#define        TM9MD_SRC_IOCLK         0x00    /* - IOCLK */
+#define        TM9MD_SRC_IOCLK_8       0x01    /* - 1/8 IOCLK */
+#define        TM9MD_SRC_IOCLK_32      0x02    /* - 1/32 IOCLK */
+#define        TM9MD_SRC_TM8CASCADE    0x03    /* - cascade with timer 8 */
+#define        TM9MD_SRC_TM0UFLOW      0x04    /* - timer 0 underflow */
+#define        TM9MD_SRC_TM1UFLOW      0x05    /* - timer 1 underflow */
+#define        TM9MD_SRC_TM2UFLOW      0x06    /* - timer 2 underflow */
+#define        TM9MD_SRC_TM9IO         0x07    /* - TM9IO pin input */
+#define        TM9MD_INIT_COUNTER      0x40    /* initialize TMnBC = TMnBR */
+#define        TM9MD_COUNT_ENABLE      0x80    /* timer count enable */
+
+#define        TM10MD                  __SYSREG(0xd400308c, u8)   /* timer 10 mode register */
+#define        TM10MD_SRC              0x07    /* timer source */
+#define        TM10MD_SRC_IOCLK        0x00    /* - IOCLK */
+#define        TM10MD_SRC_IOCLK_8      0x01    /* - 1/8 IOCLK */
+#define        TM10MD_SRC_IOCLK_32     0x02    /* - 1/32 IOCLK */
+#define        TM10MD_SRC_TM9CASCADE   0x03    /* - cascade with timer 9 */
+#define        TM10MD_SRC_TM0UFLOW     0x04    /* - timer 0 underflow */
+#define        TM10MD_SRC_TM1UFLOW     0x05    /* - timer 1 underflow */
+#define        TM10MD_SRC_TM2UFLOW     0x06    /* - timer 2 underflow */
+#define        TM10MD_SRC_TM10IO       0x07    /* - TM10IO pin input */
+#define        TM10MD_INIT_COUNTER     0x40    /* initialize TMnBC = TMnBR */
+#define        TM10MD_COUNT_ENABLE     0x80    /* timer count enable */
+
+#define        TM11MD                  __SYSREG(0xd400308e, u8)   /* timer 11 mode register */
+#define        TM11MD_SRC              0x07    /* timer source */
+#define        TM11MD_SRC_IOCLK        0x00    /* - IOCLK */
+#define        TM11MD_SRC_IOCLK_8      0x01    /* - 1/8 IOCLK */
+#define        TM11MD_SRC_IOCLK_32     0x02    /* - 1/32 IOCLK */
+#define        TM11MD_SRC_TM7CASCADE   0x03    /* - cascade with timer 7 */
+#define        TM11MD_SRC_TM0UFLOW     0x04    /* - timer 0 underflow */
+#define        TM11MD_SRC_TM1UFLOW     0x05    /* - timer 1 underflow */
+#define        TM11MD_SRC_TM2UFLOW     0x06    /* - timer 2 underflow */
+#define        TM11MD_SRC_TM11IO       0x07    /* - TM11IO pin input */
+#define        TM11MD_INIT_COUNTER     0x40    /* initialize TMnBC = TMnBR */
+#define        TM11MD_COUNT_ENABLE     0x80    /* timer count enable */
+
+#define        TM4BR                   __SYSREG(0xd4003090, u16)  /* timer 4 base register */
+#define        TM5BR                   __SYSREG(0xd4003092, u16)  /* timer 5 base register */
+#define        TM7BR                   __SYSREG(0xd4003096, u16)  /* timer 7 base register */
+#define        TM8BR                   __SYSREG(0xd4003098, u16)  /* timer 8 base register */
+#define        TM9BR                   __SYSREG(0xd400309a, u16)  /* timer 9 base register */
+#define        TM10BR                  __SYSREG(0xd400309c, u16)  /* timer 10 base register */
+#define        TM11BR                  __SYSREG(0xd400309e, u16)  /* timer 11 base register */
+#define        TM45BR                  __SYSREG(0xd4003090, u32)  /* timer 4:5 base register */
+
+#define        TM4BC                   __SYSREG(0xd40030a0, u16)  /* timer 4 binary counter */
+#define        TM5BC                   __SYSREG(0xd40030a2, u16)  /* timer 5 binary counter */
+#define        TM45BC                  __SYSREG(0xd40030a0, u32)  /* timer 4:5 binary counter */
+
+#define        TM7BC                   __SYSREG(0xd40030a6, u16)  /* timer 7 binary counter */
+#define        TM8BC                   __SYSREG(0xd40030a8, u16)  /* timer 8 binary counter */
+#define        TM9BC                   __SYSREG(0xd40030aa, u16)  /* timer 9 binary counter */
+#define        TM10BC                  __SYSREG(0xd40030ac, u16)  /* timer 10 binary counter */
+#define        TM11BC                  __SYSREG(0xd40030ae, u16)  /* timer 11 binary counter */
+
+#define TM4IRQ                 6       /* timer 4 IRQ */
+#define TM5IRQ                 7       /* timer 5 IRQ */
+#define TM7IRQ                 11      /* timer 7 IRQ */
+#define TM8IRQ                 12      /* timer 8 IRQ */
+#define TM9IRQ                 13      /* timer 9 IRQ */
+#define TM10IRQ                        14      /* timer 10 IRQ */
+#define TM11IRQ                        15      /* timer 11 IRQ */
+
+#define        TM4ICR                  GxICR(TM4IRQ)   /* timer 4 uflow intr ctrl reg */
+#define        TM5ICR                  GxICR(TM5IRQ)   /* timer 5 uflow intr ctrl reg */
+#define        TM7ICR                  GxICR(TM7IRQ)   /* timer 7 uflow intr ctrl reg */
+#define        TM8ICR                  GxICR(TM8IRQ)   /* timer 8 uflow intr ctrl reg */
+#define        TM9ICR                  GxICR(TM9IRQ)   /* timer 9 uflow intr ctrl reg */
+#define        TM10ICR                 GxICR(TM10IRQ)  /* timer 10 uflow intr ctrl reg */
+#define        TM11ICR                 GxICR(TM11IRQ)  /* timer 11 uflow intr ctrl reg */
+
+/* 16-bit timer 6 */
+#define        TM6MD                   __SYSREG(0xd4003084, u16)  /* timer6 mode register */
+#define        TM6MD_SRC               0x0007  /* timer source */
+#define        TM6MD_SRC_IOCLK         0x0000  /* - IOCLK */
+#define        TM6MD_SRC_IOCLK_8       0x0001  /* - 1/8 IOCLK */
+#define        TM6MD_SRC_IOCLK_32      0x0002  /* - 1/32 IOCLK */
+#define        TM6MD_SRC_TM0UFLOW      0x0004  /* - timer 0 underflow */
+#define        TM6MD_SRC_TM1UFLOW      0x0005  /* - timer 1 underflow */
+#define        TM6MD_SRC_TM6IOB_BOTH   0x0006  /* - TM6IOB pin input (both edges) */
+#define        TM6MD_SRC_TM6IOB_SINGLE 0x0007  /* - TM6IOB pin input (single edge) */
+#define        TM6MD_CLR_ENABLE        0x0010  /* clear count enable */
+#define        TM6MD_ONESHOT_ENABLE    0x0040  /* oneshot count */
+#define        TM6MD_TRIG_ENABLE       0x0080  /* TM6IOB pin trigger enable */
+#define TM6MD_PWM              0x3800  /* PWM output mode */
+#define TM6MD_PWM_DIS          0x0000  /* - disabled */
+#define        TM6MD_PWM_10BIT         0x1000  /* - 10 bits mode */
+#define        TM6MD_PWM_11BIT         0x1800  /* - 11 bits mode */
+#define        TM6MD_PWM_12BIT         0x3000  /* - 12 bits mode */
+#define        TM6MD_PWM_14BIT         0x3800  /* - 14 bits mode */
+#define        TM6MD_INIT_COUNTER      0x4000  /* initialize TMnBC to zero */
+#define        TM6MD_COUNT_ENABLE      0x8000  /* timer count enable */
+
+#define        TM6MDA                  __SYSREG(0xd40030b4, u8)   /* timer6 cmp/cap A mode reg */
+#define TM6MDA_OUT             0x07    /* output select */
+#define        TM6MDA_OUT_SETA_RESETB  0x00    /* - set at match A, reset at match B */
+#define        TM6MDA_OUT_SETA_RESETOV 0x01    /* - set at match A, reset at overflow */
+#define        TM6MDA_OUT_SETA         0x02    /* - set at match A */
+#define        TM6MDA_OUT_RESETA       0x03    /* - reset at match A */
+#define        TM6MDA_OUT_TOGGLE       0x04    /* - toggle on match A */
+#define TM6MDA_MODE            0xc0    /* compare A register mode */
+#define        TM6MDA_MODE_CMP_SINGLE  0x00    /* - compare, single buffer mode */
+#define        TM6MDA_MODE_CMP_DOUBLE  0x40    /* - compare, double buffer mode */
+#define        TM6MDA_MODE_CAP_S_EDGE  0x80    /* - capture, single edge mode */
+#define        TM6MDA_MODE_CAP_D_EDGE  0xc0    /* - capture, double edge mode */
+#define TM6MDA_EDGE            0x20    /* compare A edge select */
+#define        TM6MDA_EDGE_FALLING     0x00    /* capture on falling edge */
+#define        TM6MDA_EDGE_RISING      0x20    /* capture on rising edge */
+#define        TM6MDA_CAPTURE_ENABLE   0x10    /* capture enable */
+
+#define        TM6MDB                  __SYSREG(0xd40030b5, u8)   /* timer6 cmp/cap B mode reg */
+#define TM6MDB_OUT             0x07    /* output select */
+#define        TM6MDB_OUT_SETB_RESETA  0x00    /* - set at match B, reset at match A */
+#define        TM6MDB_OUT_SETB_RESETOV 0x01    /* - set at match B */
+#define        TM6MDB_OUT_RESETB       0x03    /* - reset at match B */
+#define        TM6MDB_OUT_TOGGLE       0x04    /* - toggle on match B */
+#define TM6MDB_MODE            0xc0    /* compare B register mode */
+#define        TM6MDB_MODE_CMP_SINGLE  0x00    /* - compare, single buffer mode */
+#define        TM6MDB_MODE_CMP_DOUBLE  0x40    /* - compare, double buffer mode */
+#define        TM6MDB_MODE_CAP_S_EDGE  0x80    /* - capture, single edge mode */
+#define        TM6MDB_MODE_CAP_D_EDGE  0xc0    /* - capture, double edge mode */
+#define TM6MDB_EDGE            0x20    /* compare B edge select */
+#define        TM6MDB_EDGE_FALLING     0x00    /* capture on falling edge */
+#define        TM6MDB_EDGE_RISING      0x20    /* capture on rising edge */
+#define        TM6MDB_CAPTURE_ENABLE   0x10    /* capture enable */
+
+#define        TM6CA                   __SYSREG(0xd40030c4, u16)   /* timer6 cmp/capture reg A */
+#define        TM6CB                   __SYSREG(0xd40030d4, u16)   /* timer6 cmp/capture reg B */
+#define        TM6BC                   __SYSREG(0xd40030a4, u16)   /* timer6 binary counter */
+
+#define TM6IRQ                 6       /* timer 6 IRQ */
+#define TM6AIRQ                        9       /* timer 6A IRQ */
+#define TM6BIRQ                        10      /* timer 6B IRQ */
+
+#define        TM6ICR                  GxICR(TM6IRQ)   /* timer 6 uflow intr ctrl reg */
+#define        TM6AICR                 GxICR(TM6AIRQ)  /* timer 6A intr control reg */
+#define        TM6BICR                 GxICR(TM6BIRQ)  /* timer 6B intr control reg */
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_TIMER_REGS_H */
diff --git a/include/asm-mn10300/timex.h b/include/asm-mn10300/timex.h
new file mode 100644 (file)
index 0000000..3944277
--- /dev/null
@@ -0,0 +1,33 @@
+/* MN10300 Architecture time management specifications
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_TIMEX_H
+#define _ASM_TIMEX_H
+
+#include <asm/hardirq.h>
+#include <asm/unit/timex.h>
+
+#define TICK_SIZE (tick_nsec / 1000)
+
+#define CLOCK_TICK_RATE 1193180 /* Underlying HZ - this should probably be set
+                                * to something appropriate, but what? */
+
+extern cycles_t cacheflush_time;
+
+#ifdef __KERNEL__
+
+static inline cycles_t get_cycles(void)
+{
+       return read_timestamp_counter();
+}
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_TIMEX_H */
diff --git a/include/asm-mn10300/tlb.h b/include/asm-mn10300/tlb.h
new file mode 100644 (file)
index 0000000..65d232b
--- /dev/null
@@ -0,0 +1,34 @@
+/* MN10300 TLB definitions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_TLB_H
+#define _ASM_TLB_H
+
+#include <asm/tlbflush.h>
+
+extern void check_pgt_cache(void);
+
+/*
+ * we don't need any special per-pte or per-vma handling...
+ */
+#define tlb_start_vma(tlb, vma)                                do { } while (0)
+#define tlb_end_vma(tlb, vma)                          do { } while (0)
+#define __tlb_remove_tlb_entry(tlb, ptep, address)     do { } while (0)
+
+/*
+ * .. because we flush the whole mm when it fills up
+ */
+#define tlb_flush(tlb) flush_tlb_mm((tlb)->mm)
+
+/* for now, just use the generic stuff */
+#include <asm-generic/tlb.h>
+
+#endif /* _ASM_TLB_H */
diff --git a/include/asm-mn10300/tlbflush.h b/include/asm-mn10300/tlbflush.h
new file mode 100644 (file)
index 0000000..e023986
--- /dev/null
@@ -0,0 +1,80 @@
+/* MN10300 TLB flushing functions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_TLBFLUSH_H
+#define _ASM_TLBFLUSH_H
+
+#include <asm/processor.h>
+
+#define __flush_tlb()                                          \
+do {                                                           \
+       int w;                                                  \
+       __asm__ __volatile__                                    \
+               ("      mov %1,%0               \n"             \
+                "      or %2,%0                \n"             \
+                "      mov %0,%1               \n"             \
+                : "=d"(w)                                      \
+                : "m"(MMUCTR), "i"(MMUCTR_IIV|MMUCTR_DIV)      \
+                : "memory"                                     \
+                );                                             \
+} while (0)
+
+#define __flush_tlb_all() __flush_tlb()
+#define __flush_tlb_one(addr) __flush_tlb()
+
+
+/*
+ * TLB flushing:
+ *
+ *  - flush_tlb() flushes the current mm struct TLBs
+ *  - flush_tlb_all() flushes all processes TLBs
+ *  - flush_tlb_mm(mm) flushes the specified mm context TLB's
+ *  - flush_tlb_page(vma, vmaddr) flushes one page
+ *  - flush_tlb_range(mm, start, end) flushes a range of pages
+ *  - flush_tlb_pgtables(mm, start, end) flushes a range of page tables
+ */
+#define flush_tlb_all()                                \
+do {                                           \
+       preempt_disable();                      \
+       __flush_tlb_all();                      \
+       preempt_enable();                       \
+} while (0)
+
+#define flush_tlb_mm(mm)                       \
+do {                                           \
+       preempt_disable();                      \
+       __flush_tlb_all();                      \
+       preempt_enable();                       \
+} while (0)
+
+#define flush_tlb_range(vma, start, end)                       \
+do {                                                           \
+       unsigned long __s __attribute__((unused)) = (start);    \
+       unsigned long __e __attribute__((unused)) = (end);      \
+       preempt_disable();                                      \
+       __flush_tlb_all();                                      \
+       preempt_enable();                                       \
+} while (0)
+
+
+#define __flush_tlb_global()                   flush_tlb_all()
+#define flush_tlb()                            flush_tlb_all()
+#define flush_tlb_kernel_range(start, end)                     \
+do {                                                           \
+       unsigned long __s __attribute__((unused)) = (start);    \
+       unsigned long __e __attribute__((unused)) = (end);      \
+       flush_tlb_all();                                        \
+} while (0)
+
+extern void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr);
+
+#define flush_tlb_pgtables(mm, start, end)     do {} while (0)
+
+#endif /* _ASM_TLBFLUSH_H */
diff --git a/include/asm-mn10300/topology.h b/include/asm-mn10300/topology.h
new file mode 100644 (file)
index 0000000..5428f33
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/topology.h>
diff --git a/include/asm-mn10300/types.h b/include/asm-mn10300/types.h
new file mode 100644 (file)
index 0000000..d40ea76
--- /dev/null
@@ -0,0 +1,67 @@
+/* MN10300 Basic type definitions
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_TYPES_H
+#define _ASM_TYPES_H
+
+#ifndef __ASSEMBLY__
+
+typedef unsigned short umode_t;
+
+/*
+ * __xx is ok: it doesn't pollute the POSIX namespace. Use these in the
+ * header files exported to user space
+ */
+
+typedef __signed__ char __s8;
+typedef unsigned char __u8;
+
+typedef __signed__ short __s16;
+typedef unsigned short __u16;
+
+typedef __signed__ int __s32;
+typedef unsigned int __u32;
+
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+typedef __signed__ long long __s64;
+typedef unsigned long long __u64;
+#endif
+
+#endif /* __ASSEMBLY__ */
+
+/*
+ * These aren't exported outside the kernel to avoid name space clashes
+ */
+#ifdef __KERNEL__
+
+#define BITS_PER_LONG 32
+
+#ifndef __ASSEMBLY__
+
+typedef signed char s8;
+typedef unsigned char u8;
+
+typedef signed short s16;
+typedef unsigned short u16;
+
+typedef signed int s32;
+typedef unsigned int u32;
+
+typedef signed long long s64;
+typedef unsigned long long u64;
+
+/* Dma addresses are 32-bits wide.  */
+typedef u32 dma_addr_t;
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* __KERNEL__ */
+
+#endif /* _ASM_TYPES_H */
diff --git a/include/asm-mn10300/uaccess.h b/include/asm-mn10300/uaccess.h
new file mode 100644 (file)
index 0000000..46b9b64
--- /dev/null
@@ -0,0 +1,490 @@
+/* MN10300 userspace access functions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_UACCESS_H
+#define _ASM_UACCESS_H
+
+/*
+ * User space memory access functions
+ */
+#include <linux/sched.h>
+#include <asm/page.h>
+#include <asm/pgtable.h>
+#include <asm/errno.h>
+
+#define VERIFY_READ 0
+#define VERIFY_WRITE 1
+
+/*
+ * The fs value determines whether argument validity checking should be
+ * performed or not.  If get_fs() == USER_DS, checking is performed, with
+ * get_fs() == KERNEL_DS, checking is bypassed.
+ *
+ * For historical reasons, these macros are grossly misnamed.
+ */
+
+#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
+
+#define KERNEL_XDS     MAKE_MM_SEG(0xBFFFFFFF)
+#define KERNEL_DS      MAKE_MM_SEG(0x9FFFFFFF)
+#define USER_DS                MAKE_MM_SEG(TASK_SIZE)
+
+#define get_ds()       (KERNEL_DS)
+#define get_fs()       (current_thread_info()->addr_limit)
+#define set_fs(x)      (current_thread_info()->addr_limit = (x))
+#define __kernel_ds_p() (current_thread_info()->addr_limit.seg == 0x9FFFFFFF)
+
+#define segment_eq(a, b) ((a).seg == (b).seg)
+
+#define __addr_ok(addr) \
+       ((unsigned long)(addr) < (current_thread_info()->addr_limit.seg))
+
+/*
+ * check that a range of addresses falls within the current address limit
+ */
+static inline int ___range_ok(unsigned long addr, unsigned int size)
+{
+       int flag = 1, tmp;
+
+       asm("   add     %3,%1   \n"     /* set C-flag if addr + size > 4Gb */
+           "   bcs     0f      \n"
+           "   cmp     %4,%1   \n"     /* jump if addr+size>limit (error) */
+           "   bhi     0f      \n"
+           "   clr     %0      \n"     /* mark okay */
+           "0:                 \n"
+           : "=r"(flag), "=&r"(tmp)
+           : "1"(addr), "ir"(size),
+             "r"(current_thread_info()->addr_limit.seg), "0"(flag)
+           : "cc"
+           );
+
+       return flag;
+}
+
+#define __range_ok(addr, size) ___range_ok((unsigned long)(addr), (u32)(size))
+
+#define access_ok(type, addr, size) (__range_ok((addr), (size)) == 0)
+#define __access_ok(addr, size)     (__range_ok((addr), (size)) == 0)
+
+static inline int verify_area(int type, const void *addr, unsigned long size)
+{
+       return access_ok(type, addr, size) ? 0 : -EFAULT;
+}
+
+
+/*
+ * The exception table consists of pairs of addresses: the first is the
+ * address of an instruction that is allowed to fault, and the second is
+ * the address at which the program should continue.  No registers are
+ * modified, so it is entirely up to the continuation code to figure out
+ * what to do.
+ *
+ * All the routines below use bits of fixup code that are out of line
+ * with the main instruction path.  This means when everything is well,
+ * we don't even have to jump over them.  Further, they do not intrude
+ * on our cache or tlb entries.
+ */
+
+struct exception_table_entry
+{
+       unsigned long insn, fixup;
+};
+
+/* Returns 0 if exception not found and fixup otherwise.  */
+extern int fixup_exception(struct pt_regs *regs);
+
+#define put_user(x, ptr) __put_user_check((x), (ptr), sizeof(*(ptr)))
+#define get_user(x, ptr) __get_user_check((x), (ptr), sizeof(*(ptr)))
+
+/*
+ * The "__xxx" versions do not do address space checking, useful when
+ * doing multiple accesses to the same area (the user has to do the
+ * checks by hand with "access_ok()")
+ */
+#define __put_user(x, ptr) __put_user_nocheck((x), (ptr), sizeof(*(ptr)))
+#define __get_user(x, ptr) __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
+
+/*
+ * The "xxx_ret" versions return constant specified in third argument, if
+ * something bad happens. These macros can be optimized for the
+ * case of just returning from the function xxx_ret is used.
+ */
+
+#define put_user_ret(x, ptr, ret) \
+       ({ if (put_user((x), (ptr)))    return (ret); })
+#define get_user_ret(x, ptr, ret) \
+       ({ if (get_user((x), (ptr)))    return (ret); })
+#define __put_user_ret(x, ptr, ret) \
+       ({ if (__put_user((x), (ptr)))  return (ret); })
+#define __get_user_ret(x, ptr, ret) \
+       ({ if (__get_user((x), (ptr)))  return (ret); })
+
+struct __large_struct { unsigned long buf[100]; };
+#define __m(x) (*(struct __large_struct *)(x))
+
+#define __get_user_nocheck(x, ptr, size)       \
+({                                             \
+       __typeof(*(ptr)) __gu_val;              \
+       unsigned long __gu_addr;                \
+       int __gu_err;                           \
+       __gu_addr = (unsigned long) (ptr);      \
+       switch (size) {                         \
+       case 1:  __get_user_asm("bu"); break;   \
+       case 2:  __get_user_asm("hu"); break;   \
+       case 4:  __get_user_asm(""  ); break;   \
+       default: __get_user_unknown(); break;   \
+       }                                       \
+       x = (__typeof__(*(ptr))) __gu_val;      \
+       __gu_err;                               \
+})
+
+#define __get_user_check(x, ptr, size)                 \
+({                                                     \
+       __typeof__(*(ptr)) __gu_val;                    \
+       unsigned long __gu_addr;                        \
+       int __gu_err;                                   \
+       __gu_addr = (unsigned long) (ptr);              \
+       if (likely(__access_ok(__gu_addr,size))) {      \
+               switch (size) {                         \
+               case 1:  __get_user_asm("bu"); break;   \
+               case 2:  __get_user_asm("hu"); break;   \
+               case 4:  __get_user_asm(""  ); break;   \
+               default: __get_user_unknown(); break;   \
+               }                                       \
+       }                                               \
+       else {                                          \
+               __gu_err = -EFAULT;                     \
+               __gu_val = 0;                           \
+       }                                               \
+       x = (__typeof__(*(ptr))) __gu_val;              \
+       __gu_err;                                       \
+})
+
+#define __get_user_asm(INSN)                                   \
+({                                                             \
+       asm volatile(                                   \
+               "1:\n"                                          \
+               "       mov"INSN"       %2,%1\n"                \
+               "       mov             0,%0\n"                 \
+               "2:\n"                                          \
+               "       .section        .fixup,\"ax\"\n"        \
+               "3:\n\t"                                        \
+               "       mov             %3,%0\n"                \
+               "       jmp             2b\n"                   \
+               "       .previous\n"                            \
+               "       .section        __ex_table,\"a\"\n"     \
+               "       .balign         4\n"                    \
+               "       .long           1b, 3b\n"               \
+               "       .previous"                              \
+               : "=&r" (__gu_err), "=&r" (__gu_val)            \
+               : "m" (__m(__gu_addr)), "i" (-EFAULT));         \
+})
+
+extern int __get_user_unknown(void);
+
+#define __put_user_nocheck(x, ptr, size)                       \
+({                                                             \
+       union {                                                 \
+               __typeof__(*(ptr)) val;                         \
+               u32 bits[2];                                    \
+       } __pu_val;                                             \
+       unsigned long __pu_addr;                                \
+       int __pu_err;                                           \
+       __pu_val.val = (x);                                     \
+       __pu_addr = (unsigned long) (ptr);                      \
+       switch (size) {                                         \
+       case 1:  __put_user_asm("bu"); break;                   \
+       case 2:  __put_user_asm("hu"); break;                   \
+       case 4:  __put_user_asm(""  ); break;                   \
+       case 8:  __put_user_asm8();    break;                   \
+       default: __pu_err = __put_user_unknown(); break;        \
+       }                                                       \
+       __pu_err;                                               \
+})
+
+#define __put_user_check(x, ptr, size)                                 \
+({                                                                     \
+       union {                                                         \
+               __typeof__(*(ptr)) val;                                 \
+               u32 bits[2];                                            \
+       } __pu_val;                                                     \
+       unsigned long __pu_addr;                                        \
+       int __pu_err;                                                   \
+       __pu_val.val = (x);                                             \
+       __pu_addr = (unsigned long) (ptr);                              \
+       if (likely(__access_ok(__pu_addr, size))) {                     \
+               switch (size) {                                         \
+               case 1:  __put_user_asm("bu"); break;                   \
+               case 2:  __put_user_asm("hu"); break;                   \
+               case 4:  __put_user_asm(""  ); break;                   \
+               case 8:  __put_user_asm8();    break;                   \
+               default: __pu_err = __put_user_unknown(); break;        \
+               }                                                       \
+       }                                                               \
+       else {                                                          \
+               __pu_err = -EFAULT;                                     \
+       }                                                               \
+       __pu_err;                                                       \
+})
+
+#define __put_user_asm(INSN)                                   \
+({                                                             \
+       asm volatile(                                           \
+               "1:\n"                                          \
+               "       mov"INSN"       %1,%2\n"                \
+               "       mov             0,%0\n"                 \
+               "2:\n"                                          \
+               "       .section        .fixup,\"ax\"\n"        \
+               "3:\n"                                          \
+               "       mov             %3,%0\n"                \
+               "       jmp             2b\n"                   \
+               "       .previous\n"                            \
+               "       .section        __ex_table,\"a\"\n"     \
+               "       .balign         4\n"                    \
+               "       .long           1b, 3b\n"               \
+               "       .previous"                              \
+               : "=&r" (__pu_err)                              \
+               : "r" (__pu_val.val), "m" (__m(__pu_addr)),     \
+                 "i" (-EFAULT)                                 \
+               );                                              \
+})
+
+#define __put_user_asm8()                                              \
+({                                                                     \
+       asm volatile(                                                   \
+               "1:     mov             %1,%3           \n"             \
+               "2:     mov             %2,%4           \n"             \
+               "       mov             0,%0            \n"             \
+               "3:                                     \n"             \
+               "       .section        .fixup,\"ax\"   \n"             \
+               "4:                                     \n"             \
+               "       mov             %5,%0           \n"             \
+               "       jmp             2b              \n"             \
+               "       .previous                       \n"             \
+               "       .section        __ex_table,\"a\"\n"             \
+               "       .balign         4               \n"             \
+               "       .long           1b, 4b          \n"             \
+               "       .long           2b, 4b          \n"             \
+               "       .previous                       \n"             \
+               : "=&r" (__pu_err)                                      \
+               : "r" (__pu_val.bits[0]), "r" (__pu_val.bits[1]),       \
+                 "m" (__m(__pu_addr)), "m" (__m(__pu_addr+4)),         \
+                 "i" (-EFAULT)                                         \
+               );                                                      \
+})
+
+extern int __put_user_unknown(void);
+
+
+/*
+ * Copy To/From Userspace
+ */
+/* Generic arbitrary sized copy.  */
+#define __copy_user(to, from, size)                                    \
+do {                                                                   \
+       if (size) {                                                     \
+               void *__to = to;                                        \
+               const void *__from = from;                              \
+               int w;                                                  \
+               asm volatile(                                           \
+                       "0:     movbu   (%0),%3;\n"                     \
+                       "1:     movbu   %3,(%1);\n"                     \
+                       "       inc     %0;\n"                          \
+                       "       inc     %1;\n"                          \
+                       "       add     -1,%2;\n"                       \
+                       "       bne     0b;\n"                          \
+                       "2:\n"                                          \
+                       "       .section .fixup,\"ax\"\n"               \
+                       "3:     jmp     2b\n"                           \
+                       "       .previous\n"                            \
+                       "       .section __ex_table,\"a\"\n"            \
+                       "       .balign 4\n"                            \
+                       "       .long   0b,3b\n"                        \
+                       "       .long   1b,3b\n"                        \
+                       "       .previous\n"                            \
+                       : "=a"(__from), "=a"(__to), "=r"(size), "=&r"(w)\
+                       : "0"(__from), "1"(__to), "2"(size)             \
+                       : "memory");                                    \
+       }                                                               \
+} while (0)
+
+#define __copy_user_zeroing(to, from, size)                            \
+do {                                                                   \
+       if (size) {                                                     \
+               void *__to = to;                                        \
+               const void *__from = from;                              \
+               int w;                                                  \
+               asm volatile(                                           \
+                       "0:     movbu   (%0),%3;\n"                     \
+                       "1:     movbu   %3,(%1);\n"                     \
+                       "       inc     %0;\n"                          \
+                       "       inc     %1;\n"                          \
+                       "       add     -1,%2;\n"                       \
+                       "       bne     0b;\n"                          \
+                       "2:\n"                                          \
+                       "       .section .fixup,\"ax\"\n"               \
+                       "3:\n"                                          \
+                       "       mov     %2,%0\n"                        \
+                       "       clr     %3\n"                           \
+                       "4:     movbu   %3,(%1);\n"                     \
+                       "       inc     %1;\n"                          \
+                       "       add     -1,%2;\n"                       \
+                       "       bne     4b;\n"                          \
+                       "       mov     %0,%2\n"                        \
+                       "       jmp     2b\n"                           \
+                       "       .previous\n"                            \
+                       "       .section __ex_table,\"a\"\n"            \
+                       "       .balign 4\n"                            \
+                       "       .long   0b,3b\n"                        \
+                       "       .long   1b,3b\n"                        \
+                       "       .previous\n"                            \
+                       : "=a"(__from), "=a"(__to), "=r"(size), "=&r"(w)\
+                       : "0"(__from), "1"(__to), "2"(size)             \
+                       : "memory");                                    \
+       }                                                               \
+} while (0)
+
+/* We let the __ versions of copy_from/to_user inline, because they're often
+ * used in fast paths and have only a small space overhead.
+ */
+static inline
+unsigned long __generic_copy_from_user_nocheck(void *to, const void *from,
+                                              unsigned long n)
+{
+       __copy_user_zeroing(to, from, n);
+       return n;
+}
+
+static inline
+unsigned long __generic_copy_to_user_nocheck(void *to, const void *from,
+                                            unsigned long n)
+{
+       __copy_user(to, from, n);
+       return n;
+}
+
+
+#if 0
+#error don't use - these macros don't increment to & from pointers
+/* Optimize just a little bit when we know the size of the move. */
+#define __constant_copy_user(to, from, size)   \
+do {                                           \
+       asm volatile(                           \
+               "       mov %0,a0;\n"           \
+               "0:     movbu (%1),d3;\n"       \
+               "1:     movbu d3,(%2);\n"       \
+               "       add -1,a0;\n"           \
+               "       bne 0b;\n"              \
+               "2:;"                           \
+               ".section .fixup,\"ax\"\n"      \
+               "3:     jmp 2b\n"               \
+               ".previous\n"                   \
+               ".section __ex_table,\"a\"\n"   \
+               "       .balign 4\n"            \
+               "       .long 0b,3b\n"          \
+               "       .long 1b,3b\n"          \
+               ".previous"                     \
+               :                               \
+               : "d"(size), "d"(to), "d"(from) \
+               : "d3", "a0");                  \
+} while (0)
+
+/* Optimize just a little bit when we know the size of the move. */
+#define __constant_copy_user_zeroing(to, from, size)   \
+do {                                                   \
+       asm volatile(                                   \
+               "       mov %0,a0;\n"                   \
+               "0:     movbu (%1),d3;\n"               \
+               "1:     movbu d3,(%2);\n"               \
+               "       add -1,a0;\n"                   \
+               "       bne 0b;\n"                      \
+               "2:;"                                   \
+               ".section .fixup,\"ax\"\n"              \
+               "3:     jmp 2b\n"                       \
+               ".previous\n"                           \
+               ".section __ex_table,\"a\"\n"           \
+               "       .balign 4\n"                    \
+               "       .long 0b,3b\n"                  \
+               "       .long 1b,3b\n"                  \
+               ".previous"                             \
+               :                                       \
+               : "d"(size), "d"(to), "d"(from)         \
+               : "d3", "a0");                          \
+} while (0)
+
+static inline
+unsigned long __constant_copy_to_user(void *to, const void *from,
+                                     unsigned long n)
+{
+       if (access_ok(VERIFY_WRITE, to, n))
+               __constant_copy_user(to, from, n);
+       return n;
+}
+
+static inline
+unsigned long __constant_copy_from_user(void *to, const void *from,
+                                       unsigned long n)
+{
+       if (access_ok(VERIFY_READ, from, n))
+               __constant_copy_user_zeroing(to, from, n);
+       return n;
+}
+
+static inline
+unsigned long __constant_copy_to_user_nocheck(void *to, const void *from,
+                                             unsigned long n)
+{
+       __constant_copy_user(to, from, n);
+       return n;
+}
+
+static inline
+unsigned long __constant_copy_from_user_nocheck(void *to, const void *from,
+                                               unsigned long n)
+{
+       __constant_copy_user_zeroing(to, from, n);
+       return n;
+}
+#endif
+
+extern unsigned long __generic_copy_to_user(void __user *, const void *,
+                                           unsigned long);
+extern unsigned long __generic_copy_from_user(void *, const void __user *,
+                                             unsigned long);
+
+#define __copy_to_user_inatomic(to, from, n) \
+       __generic_copy_to_user_nocheck((to), (from), (n))
+#define __copy_from_user_inatomic(to, from, n) \
+       __generic_copy_from_user_nocheck((to), (from), (n))
+
+#define __copy_to_user(to, from, n)                    \
+({                                                     \
+       might_sleep();                                  \
+       __copy_to_user_inatomic((to), (from), (n));     \
+})
+
+#define __copy_from_user(to, from, n)                  \
+({                                                     \
+       might_sleep();                                  \
+       __copy_from_user_inatomic((to), (from), (n));   \
+})
+
+
+#define copy_to_user(to, from, n)   __generic_copy_to_user((to), (from), (n))
+#define copy_from_user(to, from, n) __generic_copy_from_user((to), (from), (n))
+
+extern long strncpy_from_user(char *dst, const char __user *src, long count);
+extern long __strncpy_from_user(char *dst, const char __user *src, long count);
+extern long strnlen_user(const char __user *str, long n);
+#define strlen_user(str) strnlen_user(str, ~0UL >> 1)
+extern unsigned long clear_user(void __user *mem, unsigned long len);
+extern unsigned long __clear_user(void __user *mem, unsigned long len);
+
+#endif /* _ASM_UACCESS_H */
diff --git a/include/asm-mn10300/ucontext.h b/include/asm-mn10300/ucontext.h
new file mode 100644 (file)
index 0000000..fcab5c1
--- /dev/null
@@ -0,0 +1,22 @@
+/* MN10300 User context
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_UCONTEXT_H
+#define _ASM_UCONTEXT_H
+
+struct ucontext {
+       unsigned long     uc_flags;
+       struct ucontext  *uc_link;
+       stack_t           uc_stack;
+       struct sigcontext uc_mcontext;
+       sigset_t          uc_sigmask;   /* mask last for extensibility */
+};
+
+#endif /* _ASM_UCONTEXT_H */
diff --git a/include/asm-mn10300/unaligned.h b/include/asm-mn10300/unaligned.h
new file mode 100644 (file)
index 0000000..cad3afb
--- /dev/null
@@ -0,0 +1,136 @@
+/* MN10300 Unaligned memory access handling
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_UNALIGNED_H
+#define _ASM_UNALIGNED_H
+
+#include <asm/types.h>
+
+#if 0
+extern int __bug_unaligned_x(void *ptr);
+
+/*
+ * What is the most efficient way of loading/storing an unaligned value?
+ *
+ * That is the subject of this file.  Efficiency here is defined as
+ * minimum code size with minimum register usage for the common cases.
+ * It is currently not believed that long longs are common, so we
+ * trade efficiency for the chars, shorts and longs against the long
+ * longs.
+ *
+ * Current stats with gcc 2.7.2.2 for these functions:
+ *
+ *     ptrsize get:    code    regs    put:    code    regs
+ *     1               1       1               1       2
+ *     2               3       2               3       2
+ *     4               7       3               7       3
+ *     8               20      6               16      6
+ *
+ * gcc 2.95.1 seems to code differently:
+ *
+ *     ptrsize get:    code    regs    put:    code    regs
+ *     1               1       1               1       2
+ *     2               3       2               3       2
+ *     4               7       4               7       4
+ *     8               19      8               15      6
+ *
+ * which may or may not be more efficient (depending upon whether
+ * you can afford the extra registers).  Hopefully the gcc 2.95
+ * is inteligent enough to decide if it is better to use the
+ * extra register, but evidence so far seems to suggest otherwise.
+ *
+ * Unfortunately, gcc is not able to optimise the high word
+ * out of long long >> 32, or the low word from long long << 32
+ */
+
+#define __get_unaligned_2(__p)                                 \
+       (__p[0] | __p[1] << 8)
+
+#define __get_unaligned_4(__p)                                 \
+       (__p[0] | __p[1] << 8 | __p[2] << 16 | __p[3] << 24)
+
+#define get_unaligned(ptr)                                     \
+({                                                             \
+       unsigned int __v1, __v2;                                \
+       __typeof__(*(ptr)) __v;                                 \
+       __u8 *__p = (__u8 *)(ptr);                              \
+                                                               \
+       switch (sizeof(*(ptr))) {                               \
+       case 1: __v = *(ptr);                   break;          \
+       case 2: __v = __get_unaligned_2(__p);   break;          \
+       case 4: __v = __get_unaligned_4(__p);   break;          \
+       case 8:                                                 \
+               __v2 = __get_unaligned_4((__p+4));              \
+               __v1 = __get_unaligned_4(__p);                  \
+               __v = ((unsigned long long)__v2 << 32 | __v1);  \
+               break;                                          \
+       default: __v = __bug_unaligned_x(__p);  break;          \
+       }                                                       \
+       __v;                                                    \
+})
+
+
+static inline void __put_unaligned_2(__u32 __v, register __u8 *__p)
+{
+       *__p++ = __v;
+       *__p++ = __v >> 8;
+}
+
+static inline void __put_unaligned_4(__u32 __v, register __u8 *__p)
+{
+       __put_unaligned_2(__v >> 16, __p + 2);
+       __put_unaligned_2(__v, __p);
+}
+
+static inline void __put_unaligned_8(const unsigned long long __v, __u8 *__p)
+{
+       /*
+        * tradeoff: 8 bytes of stack for all unaligned puts (2
+        * instructions), or an extra register in the long long
+        * case - go for the extra register.
+        */
+       __put_unaligned_4(__v >> 32, __p + 4);
+       __put_unaligned_4(__v, __p);
+}
+
+/*
+ * Try to store an unaligned value as efficiently as possible.
+ */
+#define put_unaligned(val, ptr)                                                \
+       ({                                                              \
+               switch (sizeof(*(ptr))) {                               \
+               case 1:                                                 \
+                       *(ptr) = (val);                                 \
+                       break;                                          \
+               case 2:                                                 \
+                       __put_unaligned_2((val), (__u8 *)(ptr));        \
+                       break;                                          \
+               case 4:                                                 \
+                       __put_unaligned_4((val), (__u8 *)(ptr));        \
+                       break;                                          \
+               case 8:                                                 \
+                       __put_unaligned_8((val), (__u8 *)(ptr));        \
+                       break;                                          \
+               default:                                                \
+                       __bug_unaligned_x(ptr);                         \
+                       break;                                          \
+               }                                                       \
+               (void) 0;                                               \
+       })
+
+
+#else
+
+#define get_unaligned(ptr) (*(ptr))
+#define put_unaligned(val, ptr) ({ *(ptr) = (val); (void) 0; })
+
+#endif
+
+#endif
diff --git a/include/asm-mn10300/unistd.h b/include/asm-mn10300/unistd.h
new file mode 100644 (file)
index 0000000..3721aa9
--- /dev/null
@@ -0,0 +1,384 @@
+/* MN10300 System call number list
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_UNISTD_H
+#define _ASM_UNISTD_H
+
+#define __NR_restart_syscall      0
+#define __NR_exit                1
+#define __NR_fork                2
+#define __NR_read                3
+#define __NR_write               4
+#define __NR_open                5
+#define __NR_close               6
+#define __NR_waitpid             7
+#define __NR_creat               8
+#define __NR_link                9
+#define __NR_unlink             10
+#define __NR_execve             11
+#define __NR_chdir              12
+#define __NR_time               13
+#define __NR_mknod              14
+#define __NR_chmod              15
+#define __NR_lchown             16
+#define __NR_break              17
+#define __NR_oldstat            18
+#define __NR_lseek              19
+#define __NR_getpid             20
+#define __NR_mount              21
+#define __NR_umount             22
+#define __NR_setuid             23
+#define __NR_getuid             24
+#define __NR_stime              25
+#define __NR_ptrace             26
+#define __NR_alarm              27
+#define __NR_oldfstat           28
+#define __NR_pause              29
+#define __NR_utime              30
+#define __NR_stty               31
+#define __NR_gtty               32
+#define __NR_access             33
+#define __NR_nice               34
+#define __NR_ftime              35
+#define __NR_sync               36
+#define __NR_kill               37
+#define __NR_rename             38
+#define __NR_mkdir              39
+#define __NR_rmdir              40
+#define __NR_dup                41
+#define __NR_pipe               42
+#define __NR_times              43
+#define __NR_prof               44
+#define __NR_brk                45
+#define __NR_setgid             46
+#define __NR_getgid             47
+#define __NR_signal             48
+#define __NR_geteuid            49
+#define __NR_getegid            50
+#define __NR_acct               51
+#define __NR_umount2            52
+#define __NR_lock               53
+#define __NR_ioctl              54
+#define __NR_fcntl              55
+#define __NR_mpx                56
+#define __NR_setpgid            57
+#define __NR_ulimit             58
+#define __NR_oldolduname        59
+#define __NR_umask              60
+#define __NR_chroot             61
+#define __NR_ustat              62
+#define __NR_dup2               63
+#define __NR_getppid            64
+#define __NR_getpgrp            65
+#define __NR_setsid             66
+#define __NR_sigaction          67
+#define __NR_sgetmask           68
+#define __NR_ssetmask           69
+#define __NR_setreuid           70
+#define __NR_setregid           71
+#define __NR_sigsuspend                 72
+#define __NR_sigpending                 73
+#define __NR_sethostname        74
+#define __NR_setrlimit          75
+#define __NR_getrlimit          76     /* Back compatible 2Gig limited rlimit */
+#define __NR_getrusage          77
+#define __NR_gettimeofday       78
+#define __NR_settimeofday       79
+#define __NR_getgroups          80
+#define __NR_setgroups          81
+#define __NR_select             82
+#define __NR_symlink            83
+#define __NR_oldlstat           84
+#define __NR_readlink           85
+#define __NR_uselib             86
+#define __NR_swapon             87
+#define __NR_reboot             88
+#define __NR_readdir            89
+#define __NR_mmap               90
+#define __NR_munmap             91
+#define __NR_truncate           92
+#define __NR_ftruncate          93
+#define __NR_fchmod             94
+#define __NR_fchown             95
+#define __NR_getpriority        96
+#define __NR_setpriority        97
+#define __NR_profil             98
+#define __NR_statfs             99
+#define __NR_fstatfs           100
+#define __NR_ioperm            101
+#define __NR_socketcall                102
+#define __NR_syslog            103
+#define __NR_setitimer         104
+#define __NR_getitimer         105
+#define __NR_stat              106
+#define __NR_lstat             107
+#define __NR_fstat             108
+#define __NR_olduname          109
+#define __NR_iopl              110
+#define __NR_vhangup           111
+#define __NR_idle              112
+#define __NR_vm86old           113
+#define __NR_wait4             114
+#define __NR_swapoff           115
+#define __NR_sysinfo           116
+#define __NR_ipc               117
+#define __NR_fsync             118
+#define __NR_sigreturn         119
+#define __NR_clone             120
+#define __NR_setdomainname     121
+#define __NR_uname             122
+#define __NR_modify_ldt                123
+#define __NR_adjtimex          124
+#define __NR_mprotect          125
+#define __NR_sigprocmask       126
+#define __NR_create_module     127
+#define __NR_init_module       128
+#define __NR_delete_module     129
+#define __NR_get_kernel_syms   130
+#define __NR_quotactl          131
+#define __NR_getpgid           132
+#define __NR_fchdir            133
+#define __NR_bdflush           134
+#define __NR_sysfs             135
+#define __NR_personality       136
+#define __NR_afs_syscall       137 /* Syscall for Andrew File System */
+#define __NR_setfsuid          138
+#define __NR_setfsgid          139
+#define __NR__llseek           140
+#define __NR_getdents          141
+#define __NR__newselect                142
+#define __NR_flock             143
+#define __NR_msync             144
+#define __NR_readv             145
+#define __NR_writev            146
+#define __NR_getsid            147
+#define __NR_fdatasync         148
+#define __NR__sysctl           149
+#define __NR_mlock             150
+#define __NR_munlock           151
+#define __NR_mlockall          152
+#define __NR_munlockall                153
+#define __NR_sched_setparam            154
+#define __NR_sched_getparam            155
+#define __NR_sched_setscheduler                156
+#define __NR_sched_getscheduler                157
+#define __NR_sched_yield               158
+#define __NR_sched_get_priority_max    159
+#define __NR_sched_get_priority_min    160
+#define __NR_sched_rr_get_interval     161
+#define __NR_nanosleep         162
+#define __NR_mremap            163
+#define __NR_setresuid         164
+#define __NR_getresuid         165
+#define __NR_vm86              166
+#define __NR_query_module      167
+#define __NR_poll              168
+#define __NR_nfsservctl                169
+#define __NR_setresgid         170
+#define __NR_getresgid         171
+#define __NR_prctl              172
+#define __NR_rt_sigreturn      173
+#define __NR_rt_sigaction      174
+#define __NR_rt_sigprocmask    175
+#define __NR_rt_sigpending     176
+#define __NR_rt_sigtimedwait   177
+#define __NR_rt_sigqueueinfo   178
+#define __NR_rt_sigsuspend     179
+#define __NR_pread64           180
+#define __NR_pwrite64          181
+#define __NR_chown             182
+#define __NR_getcwd            183
+#define __NR_capget            184
+#define __NR_capset            185
+#define __NR_sigaltstack       186
+#define __NR_sendfile          187
+#define __NR_getpmsg           188     /* some people actually want streams */
+#define __NR_putpmsg           189     /* some people actually want streams */
+#define __NR_vfork             190
+#define __NR_ugetrlimit                191     /* SuS compliant getrlimit */
+#define __NR_mmap2             192
+#define __NR_truncate64                193
+#define __NR_ftruncate64       194
+#define __NR_stat64            195
+#define __NR_lstat64           196
+#define __NR_fstat64           197
+#define __NR_lchown32          198
+#define __NR_getuid32          199
+#define __NR_getgid32          200
+#define __NR_geteuid32         201
+#define __NR_getegid32         202
+#define __NR_setreuid32                203
+#define __NR_setregid32                204
+#define __NR_getgroups32       205
+#define __NR_setgroups32       206
+#define __NR_fchown32          207
+#define __NR_setresuid32       208
+#define __NR_getresuid32       209
+#define __NR_setresgid32       210
+#define __NR_getresgid32       211
+#define __NR_chown32           212
+#define __NR_setuid32          213
+#define __NR_setgid32          214
+#define __NR_setfsuid32                215
+#define __NR_setfsgid32                216
+#define __NR_pivot_root                217
+#define __NR_mincore           218
+#define __NR_madvise           219
+#define __NR_madvise1          219     /* delete when C lib stub is removed */
+#define __NR_getdents64                220
+#define __NR_fcntl64           221
+/* 223 is unused */
+#define __NR_gettid            224
+#define __NR_readahead         225
+#define __NR_setxattr          226
+#define __NR_lsetxattr         227
+#define __NR_fsetxattr         228
+#define __NR_getxattr          229
+#define __NR_lgetxattr         230
+#define __NR_fgetxattr         231
+#define __NR_listxattr         232
+#define __NR_llistxattr                233
+#define __NR_flistxattr                234
+#define __NR_removexattr       235
+#define __NR_lremovexattr      236
+#define __NR_fremovexattr      237
+#define __NR_tkill             238
+#define __NR_sendfile64                239
+#define __NR_futex             240
+#define __NR_sched_setaffinity 241
+#define __NR_sched_getaffinity 242
+#define __NR_set_thread_area   243
+#define __NR_get_thread_area   244
+#define __NR_io_setup          245
+#define __NR_io_destroy                246
+#define __NR_io_getevents      247
+#define __NR_io_submit         248
+#define __NR_io_cancel         249
+#define __NR_fadvise64         250
+
+#define __NR_exit_group                252
+#define __NR_lookup_dcookie    253
+#define __NR_epoll_create      254
+#define __NR_epoll_ctl         255
+#define __NR_epoll_wait                256
+#define __NR_remap_file_pages  257
+#define __NR_set_tid_address   258
+#define __NR_timer_create      259
+#define __NR_timer_settime     (__NR_timer_create+1)
+#define __NR_timer_gettime     (__NR_timer_create+2)
+#define __NR_timer_getoverrun  (__NR_timer_create+3)
+#define __NR_timer_delete      (__NR_timer_create+4)
+#define __NR_clock_settime     (__NR_timer_create+5)
+#define __NR_clock_gettime     (__NR_timer_create+6)
+#define __NR_clock_getres      (__NR_timer_create+7)
+#define __NR_clock_nanosleep   (__NR_timer_create+8)
+#define __NR_statfs64          268
+#define __NR_fstatfs64         269
+#define __NR_tgkill            270
+#define __NR_utimes            271
+#define __NR_fadvise64_64      272
+#define __NR_vserver           273
+#define __NR_mbind             274
+#define __NR_get_mempolicy     275
+#define __NR_set_mempolicy     276
+#define __NR_mq_open           277
+#define __NR_mq_unlink         (__NR_mq_open+1)
+#define __NR_mq_timedsend      (__NR_mq_open+2)
+#define __NR_mq_timedreceive   (__NR_mq_open+3)
+#define __NR_mq_notify         (__NR_mq_open+4)
+#define __NR_mq_getsetattr     (__NR_mq_open+5)
+#define __NR_kexec_load                283
+#define __NR_waitid            284
+#define __NR_add_key           286
+#define __NR_request_key       287
+#define __NR_keyctl            288
+#define __NR_cacheflush                289
+#define __NR_ioprio_set                290
+#define __NR_ioprio_get                291
+#define __NR_inotify_init      292
+#define __NR_inotify_add_watch 293
+#define __NR_inotify_rm_watch  294
+#define __NR_migrate_pages     295
+#define __NR_openat            296
+#define __NR_mkdirat           297
+#define __NR_mknodat           298
+#define __NR_fchownat          299
+#define __NR_futimesat         300
+#define __NR_fstatat64         301
+#define __NR_unlinkat          302
+#define __NR_renameat          303
+#define __NR_linkat            304
+#define __NR_symlinkat         305
+#define __NR_readlinkat                306
+#define __NR_fchmodat          307
+#define __NR_faccessat         308
+#define __NR_pselect6          309
+#define __NR_ppoll             310
+#define __NR_unshare           311
+#define __NR_set_robust_list   312
+#define __NR_get_robust_list   313
+#define __NR_splice            314
+#define __NR_sync_file_range   315
+#define __NR_tee               316
+#define __NR_vmsplice          317
+#define __NR_move_pages                318
+#define __NR_getcpu            319
+#define __NR_epoll_pwait       320
+#define __NR_utimensat         321
+#define __NR_signalfd          322
+#define __NR_timerfd_create    323
+#define __NR_eventfd           324
+#define __NR_fallocate         325
+#define __NR_timerfd_settime   326
+#define __NR_timerfd_gettime   327
+
+#ifdef __KERNEL__
+
+#define NR_syscalls 326
+
+/*
+ * specify the deprecated syscalls we want to support on this arch
+ */
+#define __ARCH_WANT_IPC_PARSE_VERSION
+#define __ARCH_WANT_OLD_READDIR
+#define __ARCH_WANT_OLD_STAT
+#define __ARCH_WANT_STAT64
+#define __ARCH_WANT_SYS_ALARM
+#define __ARCH_WANT_SYS_GETHOSTNAME
+#define __ARCH_WANT_SYS_PAUSE
+#define __ARCH_WANT_SYS_SGETMASK
+#define __ARCH_WANT_SYS_SIGNAL
+#define __ARCH_WANT_SYS_TIME
+#define __ARCH_WANT_SYS_UTIME
+#define __ARCH_WANT_SYS_WAITPID
+#define __ARCH_WANT_SYS_SOCKETCALL
+#define __ARCH_WANT_SYS_FADVISE64
+#define __ARCH_WANT_SYS_GETPGRP
+#define __ARCH_WANT_SYS_LLSEEK
+#define __ARCH_WANT_SYS_NICE
+#define __ARCH_WANT_SYS_OLD_GETRLIMIT
+#define __ARCH_WANT_SYS_OLDUMOUNT
+#define __ARCH_WANT_SYS_SIGPENDING
+#define __ARCH_WANT_SYS_SIGPROCMASK
+#define __ARCH_WANT_SYS_RT_SIGACTION
+#define __ARCH_WANT_SYS_RT_SIGSUSPEND
+
+/*
+ * "Conditional" syscalls
+ *
+ * What we want is __attribute__((weak,alias("sys_ni_syscall"))),
+ * but it doesn't work on all toolchains, so we just do it by hand
+ */
+#ifndef cond_syscall
+#define cond_syscall(x) asm(".weak\t" #x "\n\t.set\t" #x ",sys_ni_syscall");
+#endif
+
+#endif /* __KERNEL__ */
+#endif /* _ASM_UNISTD_H */
diff --git a/include/asm-mn10300/unit-asb2303/clock.h b/include/asm-mn10300/unit-asb2303/clock.h
new file mode 100644 (file)
index 0000000..8b450e9
--- /dev/null
@@ -0,0 +1,45 @@
+/* ASB2303-specific clocks
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_UNIT_CLOCK_H
+#define _ASM_UNIT_CLOCK_H
+
+#ifndef __ASSEMBLY__
+
+#ifdef CONFIG_MN10300_RTC
+
+extern unsigned long mn10300_ioclk;    /* IOCLK (crystal speed) in HZ */
+extern unsigned long mn10300_iobclk;
+extern unsigned long mn10300_tsc_per_HZ;
+
+#define MN10300_IOCLK          ((unsigned long)mn10300_ioclk)
+/* If this processors has a another clock, uncomment the below. */
+/* #define MN10300_IOBCLK      ((unsigned long)mn10300_iobclk) */
+
+#else /* !CONFIG_MN10300_RTC */
+
+#define MN10300_IOCLK          33333333UL
+/* #define MN10300_IOBCLK      66666666UL */
+
+#endif /* !CONFIG_MN10300_RTC */
+
+#define MN10300_JCCLK          MN10300_IOCLK
+#define MN10300_TSCCLK         MN10300_IOCLK
+
+#ifdef CONFIG_MN10300_RTC
+#define MN10300_TSC_PER_HZ     ((unsigned long)mn10300_tsc_per_HZ)
+#else /* !CONFIG_MN10300_RTC */
+#define MN10300_TSC_PER_HZ     (MN10300_TSCCLK/HZ)
+#endif /* !CONFIG_MN10300_RTC */
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* _ASM_UNIT_CLOCK_H */
diff --git a/include/asm-mn10300/unit-asb2303/leds.h b/include/asm-mn10300/unit-asb2303/leds.h
new file mode 100644 (file)
index 0000000..3a7543e
--- /dev/null
@@ -0,0 +1,43 @@
+/* ASB2303-specific LEDs
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_UNIT_LEDS_H
+#define _ASM_UNIT_LEDS_H
+
+#include <asm/pio-regs.h>
+#include <asm/cpu-regs.h>
+#include <asm/exceptions.h>
+
+#define ASB2303_GPIO0DEF       __SYSREG(0xDB000000, u32)
+#define ASB2303_7SEGLEDS       __SYSREG(0xDB000008, u32)
+
+/*
+ * use the 7-segment LEDs to indicate states
+ */
+
+/* flip the 7-segment LEDs between "G" and "-" */
+#define mn10300_set_gdbleds(ONOFF)                     \
+do {                                                   \
+       ASB2303_7SEGLEDS = (ONOFF) ? 0x85 : 0x7f;       \
+} while (0)
+
+/* indicate double-fault by displaying "d" on the LEDs */
+#define mn10300_set_dbfleds                    \
+       mov     0x43,d0                 ;       \
+       movbu   d0,(ASB2303_7SEGLEDS)
+
+#ifndef __ASSEMBLY__
+extern void peripheral_leds_display_exception(enum exception_code code);
+extern void peripheral_leds_led_chase(void);
+extern void debug_to_serial(const char *p, int n);
+#endif /* __ASSEMBLY__ */
+
+#endif /* _ASM_UNIT_LEDS_H */
diff --git a/include/asm-mn10300/unit-asb2303/serial.h b/include/asm-mn10300/unit-asb2303/serial.h
new file mode 100644 (file)
index 0000000..0d55cf5
--- /dev/null
@@ -0,0 +1,136 @@
+/* ASB2303-specific 8250 serial ports
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_UNIT_SERIAL_H
+#define _ASM_UNIT_SERIAL_H
+
+#include <asm/cpu-regs.h>
+#include <asm/proc/irq.h>
+#include <linux/serial_reg.h>
+
+#define SERIAL_PORT0_BASE_ADDRESS      0xA6FB0000
+#define SERIAL_PORT1_BASE_ADDRESS      0xA6FC0000
+
+#define SERIAL_IRQ     XIRQ0   /* Dual serial (PC16552)        (Hi) */
+
+/*
+ * dispose of the /dev/ttyS0 and /dev/ttyS1 serial ports
+ */
+#ifndef CONFIG_GDBSTUB_ON_TTYSx
+
+#define SERIAL_PORT_DFNS                                               \
+       {                                                               \
+       .baud_base              = BASE_BAUD,                            \
+       .irq                    = SERIAL_IRQ,                           \
+       .flags                  = STD_COM_FLAGS,                        \
+       .iomem_base             = (u8 *) SERIAL_PORT0_BASE_ADDRESS,     \
+       .iomem_reg_shift        = 2,                                    \
+       .io_type                = SERIAL_IO_MEM,                        \
+       },                                                              \
+       {                                                               \
+       .baud_base              = BASE_BAUD,                            \
+       .irq                    = SERIAL_IRQ,                           \
+       .flags                  = STD_COM_FLAGS,                        \
+       .iomem_base             = (u8 *) SERIAL_PORT1_BASE_ADDRESS,     \
+       .iomem_reg_shift        = 2,                                    \
+       .io_type                = SERIAL_IO_MEM,                        \
+       },
+
+#ifndef __ASSEMBLY__
+
+static inline void __debug_to_serial(const char *p, int n)
+{
+}
+
+#endif /* !__ASSEMBLY__ */
+
+#else /* CONFIG_GDBSTUB_ON_TTYSx */
+
+#define SERIAL_PORT_DFNS /* both stolen by gdb-stub because they share an IRQ */
+
+#if defined(CONFIG_GDBSTUB_ON_TTYS0)
+#define GDBPORT_SERIAL_RX      __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_RX  * 4, u8)
+#define GDBPORT_SERIAL_TX      __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_TX  * 4, u8)
+#define GDBPORT_SERIAL_DLL     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_DLL * 4, u8)
+#define GDBPORT_SERIAL_DLM     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_DLM * 4, u8)
+#define GDBPORT_SERIAL_IER     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_IER * 4, u8)
+#define GDBPORT_SERIAL_IIR     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_IIR * 4, u8)
+#define GDBPORT_SERIAL_FCR     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_FCR * 4, u8)
+#define GDBPORT_SERIAL_LCR     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_LCR * 4, u8)
+#define GDBPORT_SERIAL_MCR     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MCR * 4, u8)
+#define GDBPORT_SERIAL_LSR     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_LSR * 4, u8)
+#define GDBPORT_SERIAL_MSR     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MSR * 4, u8)
+#define GDBPORT_SERIAL_SCR     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_SCR * 4, u8)
+#define GDBPORT_SERIAL_IRQ     SERIAL_IRQ
+
+#elif defined(CONFIG_GDBSTUB_ON_TTYS1)
+#define GDBPORT_SERIAL_RX      __SYSREG(SERIAL_PORT1_BASE_ADDRESS + UART_RX  * 4, u8)
+#define GDBPORT_SERIAL_TX      __SYSREG(SERIAL_PORT1_BASE_ADDRESS + UART_TX  * 4, u8)
+#define GDBPORT_SERIAL_DLL     __SYSREG(SERIAL_PORT1_BASE_ADDRESS + UART_DLL * 4, u8)
+#define GDBPORT_SERIAL_DLM     __SYSREG(SERIAL_PORT1_BASE_ADDRESS + UART_DLM * 4, u8)
+#define GDBPORT_SERIAL_IER     __SYSREG(SERIAL_PORT1_BASE_ADDRESS + UART_IER * 4, u8)
+#define GDBPORT_SERIAL_IIR     __SYSREG(SERIAL_PORT1_BASE_ADDRESS + UART_IIR * 4, u8)
+#define GDBPORT_SERIAL_FCR     __SYSREG(SERIAL_PORT1_BASE_ADDRESS + UART_FCR * 4, u8)
+#define GDBPORT_SERIAL_LCR     __SYSREG(SERIAL_PORT1_BASE_ADDRESS + UART_LCR * 4, u8)
+#define GDBPORT_SERIAL_MCR     __SYSREG(SERIAL_PORT1_BASE_ADDRESS + UART_MCR * 4, u8)
+#define GDBPORT_SERIAL_LSR     __SYSREG(SERIAL_PORT1_BASE_ADDRESS + UART_LSR * 4, u8)
+#define GDBPORT_SERIAL_MSR     __SYSREG(SERIAL_PORT1_BASE_ADDRESS + UART_MSR * 4, u8)
+#define GDBPORT_SERIAL_SCR     __SYSREG(SERIAL_PORT1_BASE_ADDRESS + UART_SCR * 4, u8)
+#define GDBPORT_SERIAL_IRQ     SERIAL_IRQ
+#endif
+
+#ifndef __ASSEMBLY__
+
+#define LSR_WAIT_FOR(STATE)                                    \
+do {                                                           \
+       while (!(GDBPORT_SERIAL_LSR & UART_LSR_##STATE)) {}     \
+} while (0)
+#define FLOWCTL_WAIT_FOR(LINE)                                 \
+do {                                                           \
+       while (!(GDBPORT_SERIAL_MSR & UART_MSR_##LINE)) {}      \
+} while (0)
+#define FLOWCTL_CLEAR(LINE)                    \
+do {                                           \
+       GDBPORT_SERIAL_MCR &= ~UART_MCR_##LINE; \
+} while (0)
+#define FLOWCTL_SET(LINE)                      \
+do {                                           \
+       GDBPORT_SERIAL_MCR |= UART_MCR_##LINE;  \
+} while (0)
+#define FLOWCTL_QUERY(LINE)    ({ GDBPORT_SERIAL_MSR & UART_MSR_##LINE; })
+
+static inline void __debug_to_serial(const char *p, int n)
+{
+       char ch;
+
+       FLOWCTL_SET(DTR);
+
+       for (; n > 0; n--) {
+               LSR_WAIT_FOR(THRE);
+               FLOWCTL_WAIT_FOR(CTS);
+
+               ch = *p++;
+               if (ch == 0x0a) {
+                       GDBPORT_SERIAL_TX = 0x0d;
+                       LSR_WAIT_FOR(THRE);
+                       FLOWCTL_WAIT_FOR(CTS);
+               }
+               GDBPORT_SERIAL_TX = ch;
+       }
+
+       FLOWCTL_CLEAR(DTR);
+}
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* CONFIG_GDBSTUB_ON_TTYSx */
+
+#endif /* _ASM_UNIT_SERIAL_H */
diff --git a/include/asm-mn10300/unit-asb2303/smc91111.h b/include/asm-mn10300/unit-asb2303/smc91111.h
new file mode 100644 (file)
index 0000000..dd456e9
--- /dev/null
@@ -0,0 +1,50 @@
+/* Support for the SMC91C111 NIC on an ASB2303
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_UNIT_SMC91111_H
+#define _ASM_UNIT_SMC91111_H
+
+#include <asm/intctl-regs.h>
+
+#define SMC91111_BASE          0xAA000300UL
+#define SMC91111_BASE_END      0xAA000400UL
+#define SMC91111_IRQ           XIRQ3
+
+#define SMC_CAN_USE_8BIT       0
+#define SMC_CAN_USE_16BIT      1
+#define SMC_CAN_USE_32BIT      0
+#define SMC_NOWAIT             1
+#define SMC_IRQ_FLAGS          (0)
+
+#if SMC_CAN_USE_8BIT
+#define SMC_inb(a, r)          inb((unsigned long) ((a) + (r)))
+#define SMC_outb(v, a, r)      outb(v, (unsigned long) ((a) + (r)))
+#endif
+
+#if SMC_CAN_USE_16BIT
+#define SMC_inw(a, r)          inw((unsigned long) ((a) + (r)))
+#define SMC_outw(v, a, r)      outw(v, (unsigned long) ((a) + (r)))
+#define SMC_insw(a, r, p, l)   insw((unsigned long) ((a) + (r)), (p), (l))
+#define SMC_outsw(a, r, p, l)  outsw((unsigned long) ((a) + (r)), (p), (l))
+#endif
+
+#if SMC_CAN_USE_32BIT
+#define SMC_inl(a, r)          inl((unsigned long) ((a) + (r)))
+#define SMC_outl(v, a, r)      outl(v, (unsigned long) ((a) + (r)))
+#define SMC_insl(a, r, p, l)   insl((unsigned long) ((a) + (r)), (p), (l))
+#define SMC_outsl(a, r, p, l)  outsl((unsigned long) ((a) + (r)), (p), (l))
+#endif
+
+#define RPC_LSA_DEFAULT                RPC_LED_100_10
+#define RPC_LSB_DEFAULT                RPC_LED_TX_RX
+
+#define set_irq_type(irq, type)
+
+#endif /*  _ASM_UNIT_SMC91111_H */
diff --git a/include/asm-mn10300/unit-asb2303/timex.h b/include/asm-mn10300/unit-asb2303/timex.h
new file mode 100644 (file)
index 0000000..7e54b0c
--- /dev/null
@@ -0,0 +1,135 @@
+/* ASB2303-specific timer specifcations
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_UNIT_TIMEX_H
+#define _ASM_UNIT_TIMEX_H
+
+#ifndef __ASSEMBLY__
+#include <linux/irq.h>
+#endif /* __ASSEMBLY__ */
+
+#include <asm/timer-regs.h>
+#include <asm/unit/clock.h>
+
+/*
+ * jiffies counter specifications
+ */
+
+#define        TMJCBR_MAX              0xffff
+#define        TMJCBC                  TM01BC
+
+#define        TMJCMD                  TM01MD
+#define        TMJCBR                  TM01BR
+#define        TMJCIRQ                 TM1IRQ
+#define        TMJCICR                 TM1ICR
+#define        TMJCICR_LEVEL           GxICR_LEVEL_5
+
+#ifndef __ASSEMBLY__
+
+static inline void startup_jiffies_counter(void)
+{
+       unsigned rate;
+       u16 md, t16;
+
+       /* use as little prescaling as possible to avoid losing accuracy */
+       md = TM0MD_SRC_IOCLK;
+       rate = MN10300_JCCLK / HZ;
+
+       if (rate > TMJCBR_MAX) {
+               md = TM0MD_SRC_IOCLK_8;
+               rate = MN10300_JCCLK / 8 / HZ;
+
+               if (rate > TMJCBR_MAX) {
+                       md = TM0MD_SRC_IOCLK_32;
+                       rate = MN10300_JCCLK / 32 / HZ;
+
+                       if (rate > TMJCBR_MAX)
+                               BUG();
+               }
+       }
+
+       TMJCBR = rate - 1;
+       t16 = TMJCBR;
+
+       TMJCMD =
+               md |
+               TM1MD_SRC_TM0CASCADE << 8 |
+               TM0MD_INIT_COUNTER |
+               TM1MD_INIT_COUNTER << 8;
+
+       TMJCMD =
+               md |
+               TM1MD_SRC_TM0CASCADE << 8 |
+               TM0MD_COUNT_ENABLE |
+               TM1MD_COUNT_ENABLE << 8;
+
+       t16 = TMJCMD;
+
+       TMJCICR |= GxICR_ENABLE | GxICR_DETECT | GxICR_REQUEST;
+       t16 = TMJCICR;
+}
+
+static inline void shutdown_jiffies_counter(void)
+{
+}
+
+#endif /* !__ASSEMBLY__ */
+
+
+/*
+ * timestamp counter specifications
+ */
+
+#define        TMTSCBR_MAX             0xffffffff
+#define        TMTSCBC                 TM45BC
+
+#ifndef __ASSEMBLY__
+
+static inline void startup_timestamp_counter(void)
+{
+       /* set up timer 4 & 5 cascaded as a 32-bit counter to count real time
+        * - count down from 4Gig-1 to 0 and wrap at IOCLK rate
+        */
+       TM45BR = TMTSCBR_MAX;
+
+       TM4MD = TM4MD_SRC_IOCLK;
+       TM4MD |= TM4MD_INIT_COUNTER;
+       TM4MD &= ~TM4MD_INIT_COUNTER;
+       TM4ICR = 0;
+
+       TM5MD = TM5MD_SRC_TM4CASCADE;
+       TM5MD |= TM5MD_INIT_COUNTER;
+       TM5MD &= ~TM5MD_INIT_COUNTER;
+       TM5ICR = 0;
+
+       TM5MD |= TM5MD_COUNT_ENABLE;
+       TM4MD |= TM4MD_COUNT_ENABLE;
+}
+
+static inline void shutdown_timestamp_counter(void)
+{
+       TM4MD = 0;
+       TM5MD = 0;
+}
+
+/*
+ * we use a cascaded pair of 16-bit down-counting timers to count I/O
+ * clock cycles for the purposes of time keeping
+ */
+typedef unsigned long cycles_t;
+
+static inline cycles_t read_timestamp_counter(void)
+{
+       return (cycles_t)TMTSCBC;
+}
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* _ASM_UNIT_TIMEX_H */
diff --git a/include/asm-mn10300/unit-asb2305/clock.h b/include/asm-mn10300/unit-asb2305/clock.h
new file mode 100644 (file)
index 0000000..7d51484
--- /dev/null
@@ -0,0 +1,45 @@
+/* ASB2305-specific clocks
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_UNIT_CLOCK_H
+#define _ASM_UNIT_CLOCK_H
+
+#ifndef __ASSEMBLY__
+
+#ifdef CONFIG_MN10300_RTC
+
+extern unsigned long mn10300_ioclk;    /* IOCLK (crystal speed) in HZ */
+extern unsigned long mn10300_iobclk;
+extern unsigned long mn10300_tsc_per_HZ;
+
+#define MN10300_IOCLK          ((unsigned long)mn10300_ioclk)
+/* If this processors has a another clock, uncomment the below. */
+/* #define MN10300_IOBCLK      ((unsigned long)mn10300_iobclk) */
+
+#else /* !CONFIG_MN10300_RTC */
+
+#define MN10300_IOCLK          33333333UL
+/* #define MN10300_IOBCLK      66666666UL */
+
+#endif /* !CONFIG_MN10300_RTC */
+
+#define MN10300_JCCLK          MN10300_IOCLK
+#define MN10300_TSCCLK         MN10300_IOCLK
+
+#ifdef CONFIG_MN10300_RTC
+#define MN10300_TSC_PER_HZ     ((unsigned long)mn10300_tsc_per_HZ)
+#else /* !CONFIG_MN10300_RTC */
+#define MN10300_TSC_PER_HZ     (MN10300_TSCCLK/HZ)
+#endif /* !CONFIG_MN10300_RTC */
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* _ASM_UNIT_CLOCK_H */
diff --git a/include/asm-mn10300/unit-asb2305/leds.h b/include/asm-mn10300/unit-asb2305/leds.h
new file mode 100644 (file)
index 0000000..bc471f6
--- /dev/null
@@ -0,0 +1,51 @@
+/* ASB2305-specific LEDs
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_UNIT_LEDS_H
+#define _ASM_UNIT_LEDS_H
+
+#include <asm/pio-regs.h>
+#include <asm/cpu-regs.h>
+#include <asm/exceptions.h>
+
+#define ASB2305_7SEGLEDS       __SYSREG(0xA6F90000, u32)
+
+/* perform a hard reset by driving PIO06 low */
+#define mn10300_unit_hard_reset()              \
+do {                                           \
+       P0OUT &= 0xbf;                          \
+       P0MD = (P0MD & P0MD_6) | P0MD_6_OUT;    \
+} while (0)
+
+/*
+ * use the 7-segment LEDs to indicate states
+ */
+/* indicate double-fault by displaying "db-f" on the LEDs */
+#define mn10300_set_dbfleds                    \
+       mov     0x43077f1d,d0           ;       \
+       mov     d0,(ASB2305_7SEGLEDS)
+
+/* flip the 7-segment LEDs between "Gdb-" and "----" */
+#define mn10300_set_gdbleds(ONOFF)                             \
+do {                                                           \
+       ASB2305_7SEGLEDS = (ONOFF) ? 0x8543077f : 0x7f7f7f7f;   \
+} while (0)
+
+#ifndef __ASSEMBLY__
+extern void peripheral_leds_display_exception(enum exception_code);
+extern void peripheral_leds_led_chase(void);
+extern void peripheral_leds7x4_display_dec(unsigned int, unsigned int);
+extern void peripheral_leds7x4_display_hex(unsigned int, unsigned int);
+extern void peripheral_leds7x4_display_minssecs(unsigned int, unsigned int);
+extern void peripheral_leds7x4_display_rtc(void);
+#endif /* __ASSEMBLY__ */
+
+#endif /* _ASM_UNIT_LEDS_H */
diff --git a/include/asm-mn10300/unit-asb2305/serial.h b/include/asm-mn10300/unit-asb2305/serial.h
new file mode 100644 (file)
index 0000000..73d31d6
--- /dev/null
@@ -0,0 +1,120 @@
+/* ASB2305-specific 8250 serial ports
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_UNIT_SERIAL_H
+#define _ASM_UNIT_SERIAL_H
+
+#include <asm/cpu/cpu-regs.h>
+#include <asm/proc/irq.h>
+#include <linux/serial_reg.h>
+
+#define SERIAL_PORT0_BASE_ADDRESS      0xA6FB0000
+#define ASB2305_DEBUG_MCR      __SYSREG(0xA6FB0000 + UART_MCR * 2, u8)
+
+#define SERIAL_IRQ     XIRQ0   /* Dual serial (PC16552)        (Hi) */
+
+/*
+ * dispose of the /dev/ttyS0 serial port
+ */
+#ifndef CONFIG_GDBSTUB_ON_TTYSx
+
+#define SERIAL_PORT_DFNS                                               \
+       {                                                               \
+       .baud_base              = BASE_BAUD,                            \
+       .irq                    = SERIAL_IRQ,                           \
+       .flags                  = STD_COM_FLAGS,                        \
+       .iomem_base             = (u8 *) SERIAL_PORT0_BASE_ADDRESS,     \
+       .iomem_reg_shift        = 2,                                    \
+       .io_type                = SERIAL_IO_MEM,                        \
+       },
+
+#ifndef __ASSEMBLY__
+
+static inline void __debug_to_serial(const char *p, int n)
+{
+}
+
+#endif /* !__ASSEMBLY__ */
+
+#else /* CONFIG_GDBSTUB_ON_TTYSx */
+
+#define SERIAL_PORT_DFNS /* stolen by gdb-stub */
+
+#if defined(CONFIG_GDBSTUB_ON_TTYS0)
+#define GDBPORT_SERIAL_RX      __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_RX  * 4, u8)
+#define GDBPORT_SERIAL_TX      __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_TX  * 4, u8)
+#define GDBPORT_SERIAL_DLL     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_DLL * 4, u8)
+#define GDBPORT_SERIAL_DLM     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_DLM * 4, u8)
+#define GDBPORT_SERIAL_IER     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_IER * 4, u8)
+#define GDBPORT_SERIAL_IIR     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_IIR * 4, u8)
+#define GDBPORT_SERIAL_FCR     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_FCR * 4, u8)
+#define GDBPORT_SERIAL_LCR     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_LCR * 4, u8)
+#define GDBPORT_SERIAL_MCR     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MCR * 4, u8)
+#define GDBPORT_SERIAL_LSR     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_LSR * 4, u8)
+#define GDBPORT_SERIAL_MSR     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MSR * 4, u8)
+#define GDBPORT_SERIAL_SCR     __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_SCR * 4, u8)
+#define GDBPORT_SERIAL_IRQ     SERIAL_IRQ
+
+#elif defined(CONFIG_GDBSTUB_ON_TTYS1)
+#error The ASB2305 doesnt have a /dev/ttyS1
+#endif
+
+#ifndef __ASSEMBLY__
+
+#define TTYS0_TX       __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_TX  * 4, u8)
+#define TTYS0_MCR      __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MCR * 4, u8)
+#define TTYS0_LSR      __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_LSR * 4, u8)
+#define TTYS0_MSR      __SYSREG(SERIAL_PORT0_BASE_ADDRESS + UART_MSR * 4, u8)
+
+#define LSR_WAIT_FOR(STATE)                            \
+do {                                                   \
+       while (!(TTYS0_LSR & UART_LSR_##STATE)) {}      \
+} while (0)
+#define FLOWCTL_WAIT_FOR(LINE)                         \
+do {                                                   \
+       while (!(TTYS0_MSR & UART_MSR_##LINE)) {}       \
+} while (0)
+#define FLOWCTL_CLEAR(LINE)                    \
+do {                                           \
+       TTYS0_MCR &= ~UART_MCR_##LINE;          \
+} while (0)
+#define FLOWCTL_SET(LINE)                      \
+do {                                           \
+       TTYS0_MCR |= UART_MCR_##LINE;           \
+} while (0)
+#define FLOWCTL_QUERY(LINE)    ({ TTYS0_MSR & UART_MSR_##LINE; })
+
+static inline void __debug_to_serial(const char *p, int n)
+{
+       char ch;
+
+       FLOWCTL_SET(DTR);
+
+       for (; n > 0; n--) {
+               LSR_WAIT_FOR(THRE);
+               FLOWCTL_WAIT_FOR(CTS);
+
+               ch = *p++;
+               if (ch == 0x0a) {
+                       TTYS0_TX = 0x0d;
+                       LSR_WAIT_FOR(THRE);
+                       FLOWCTL_WAIT_FOR(CTS);
+               }
+               TTYS0_TX = ch;
+       }
+
+       FLOWCTL_CLEAR(DTR);
+}
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* CONFIG_GDBSTUB_ON_TTYSx */
+
+#endif /* _ASM_UNIT_SERIAL_H */
diff --git a/include/asm-mn10300/unit-asb2305/timex.h b/include/asm-mn10300/unit-asb2305/timex.h
new file mode 100644 (file)
index 0000000..10e1bfe
--- /dev/null
@@ -0,0 +1,135 @@
+/* ASB2305 timer specifcations
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_UNIT_TIMEX_H
+#define _ASM_UNIT_TIMEX_H
+
+#ifndef __ASSEMBLY__
+#include <linux/irq.h>
+#endif /* __ASSEMBLY__ */
+
+#include <asm/cpu/timer-regs.h>
+#include <asm/unit/clock.h>
+
+/*
+ * jiffies counter specifications
+ */
+
+#define        TMJCBR_MAX              0xffff
+#define        TMJCBC                  TM01BC
+
+#define        TMJCMD                  TM01MD
+#define        TMJCBR                  TM01BR
+#define        TMJCIRQ                 TM1IRQ
+#define        TMJCICR                 TM1ICR
+#define        TMJCICR_LEVEL           GxICR_LEVEL_5
+
+#ifndef __ASSEMBLY__
+
+static inline void startup_jiffies_counter(void)
+{
+       unsigned rate;
+       u16 md, t16;
+
+       /* use as little prescaling as possible to avoid losing accuracy */
+       md = TM0MD_SRC_IOCLK;
+       rate = MN10300_JCCLK / HZ;
+
+       if (rate > TMJCBR_MAX) {
+               md = TM0MD_SRC_IOCLK_8;
+               rate = MN10300_JCCLK / 8 / HZ;
+
+               if (rate > TMJCBR_MAX) {
+                       md = TM0MD_SRC_IOCLK_32;
+                       rate = MN10300_JCCLK / 32 / HZ;
+
+                       if (rate > TMJCBR_MAX)
+                               BUG();
+               }
+       }
+
+       TMJCBR = rate - 1;
+       t16 = TMJCBR;
+
+       TMJCMD =
+               md |
+               TM1MD_SRC_TM0CASCADE << 8 |
+               TM0MD_INIT_COUNTER |
+               TM1MD_INIT_COUNTER << 8;
+
+       TMJCMD =
+               md |
+               TM1MD_SRC_TM0CASCADE << 8 |
+               TM0MD_COUNT_ENABLE |
+               TM1MD_COUNT_ENABLE << 8;
+
+       t16 = TMJCMD;
+
+       TMJCICR |= GxICR_ENABLE | GxICR_DETECT | GxICR_REQUEST;
+       t16 = TMJCICR;
+}
+
+static inline void shutdown_jiffies_counter(void)
+{
+}
+
+#endif /* !__ASSEMBLY__ */
+
+
+/*
+ * timestamp counter specifications
+ */
+
+#define        TMTSCBR_MAX             0xffffffff
+#define        TMTSCBC                 TM45BC
+
+#ifndef __ASSEMBLY__
+
+static inline void startup_timestamp_counter(void)
+{
+       /* set up timer 4 & 5 cascaded as a 32-bit counter to count real time
+        * - count down from 4Gig-1 to 0 and wrap at IOCLK rate
+        */
+       TM45BR = TMTSCBR_MAX;
+
+       TM4MD = TM4MD_SRC_IOCLK;
+       TM4MD |= TM4MD_INIT_COUNTER;
+       TM4MD &= ~TM4MD_INIT_COUNTER;
+       TM4ICR = 0;
+
+       TM5MD = TM5MD_SRC_TM4CASCADE;
+       TM5MD |= TM5MD_INIT_COUNTER;
+       TM5MD &= ~TM5MD_INIT_COUNTER;
+       TM5ICR = 0;
+
+       TM5MD |= TM5MD_COUNT_ENABLE;
+       TM4MD |= TM4MD_COUNT_ENABLE;
+}
+
+static inline void shutdown_timestamp_counter(void)
+{
+       TM4MD = 0;
+       TM5MD = 0;
+}
+
+/*
+ * we use a cascaded pair of 16-bit down-counting timers to count I/O
+ * clock cycles for the purposes of time keeping
+ */
+typedef unsigned long cycles_t;
+
+static inline cycles_t read_timestamp_counter(void)
+{
+       return (cycles_t) TMTSCBC;
+}
+
+#endif /* !__ASSEMBLY__ */
+
+#endif /* _ASM_UNIT_TIMEX_H */
diff --git a/include/asm-mn10300/user.h b/include/asm-mn10300/user.h
new file mode 100644 (file)
index 0000000..e119390
--- /dev/null
@@ -0,0 +1,53 @@
+/* MN10300 User process data
+ *
+ * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+#ifndef _ASM_USER_H
+#define _ASM_USER_H
+
+#include <asm/page.h>
+#include <linux/ptrace.h>
+
+#ifndef __ASSEMBLY__
+/*
+ * When the kernel dumps core, it starts by dumping the user struct - this will
+ * be used by gdb to figure out where the data and stack segments are within
+ * the file, and what virtual addresses to use.
+ */
+struct user {
+       /* We start with the registers, to mimic the way that "memory" is
+        * returned from the ptrace(3,...) function.
+        */
+       struct pt_regs regs;            /* Where the registers are actually stored */
+
+       /* The rest of this junk is to help gdb figure out what goes where */
+       unsigned long int u_tsize;      /* Text segment size (pages). */
+       unsigned long int u_dsize;      /* Data segment size (pages). */
+       unsigned long int u_ssize;      /* Stack segment size (pages). */
+       unsigned long start_code;       /* Starting virtual address of text. */
+       unsigned long start_stack;      /* Starting virtual address of stack area.
+                                          This is actually the bottom of the stack,
+                                          the top of the stack is always found in the
+                                          esp register.  */
+       long int signal;                /* Signal that caused the core dump. */
+       int reserved;                   /* No longer used */
+       struct user_pt_regs *u_ar0;     /* Used by gdb to help find the values for */
+
+       /* the registers */
+       unsigned long magic;            /* To uniquely identify a core file */
+       char u_comm[32];                /* User command that was responsible */
+};
+#endif
+
+#define NBPG PAGE_SIZE
+#define UPAGES 1
+#define HOST_TEXT_START_ADDR   +(u.start_code)
+#define HOST_STACK_END_ADDR    +(u.start_stack + u.u_ssize * NBPG)
+
+#endif /* _ASM_USER_H */
diff --git a/include/asm-mn10300/vga.h b/include/asm-mn10300/vga.h
new file mode 100644 (file)
index 0000000..0163e50
--- /dev/null
@@ -0,0 +1,17 @@
+/* MN10300 VGA register definitions
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_VGA_H
+#define _ASM_VGA_H
+
+
+
+#endif /* _ASM_VGA_H */
diff --git a/include/asm-mn10300/xor.h b/include/asm-mn10300/xor.h
new file mode 100644 (file)
index 0000000..c82eb12
--- /dev/null
@@ -0,0 +1 @@
+#include <asm-generic/xor.h>
index 23e2c90943e58ade6c9deacd26a818bb70518973..eb04e34c5bb1ed3a448c4148eb9c37d852925225 100644 (file)
@@ -17,14 +17,4 @@ struct exec
 #define N_DRSIZE(a)    ((a).a_drsize)
 #define N_SYMSIZE(a)   ((a).a_syms)
 
-#ifdef __KERNEL__
-
-/* XXX: STACK_TOP actually should be STACK_BOTTOM for parisc.
- * prumpf */
-
-#define STACK_TOP      TASK_SIZE
-#define STACK_TOP_MAX  DEFAULT_TASK_SIZE
-
-#endif
-
 #endif /* __A_OUT_GNU_H__ */
index b08d9151c71e4495b1ed9b8884199b92f7c007da..27d50b85954109d123a8e9118a8799a4eadc5221 100644 (file)
@@ -91,6 +91,7 @@ typedef unsigned long pgprot_t;
 
 #endif /* STRICT_MM_TYPECHECKS */
 
+typedef struct page *pgtable_t;
 
 typedef struct __physmem_range {
        unsigned long start_pfn;
index aab66f1bea14d67c3381d39ba6bd0d15550467b7..3996dfc30a3f3366aebd714d63b35fb8455fcbac 100644 (file)
@@ -115,11 +115,14 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
 
 #define pmd_populate(mm, pmd, pte_page) \
        pmd_populate_kernel(mm, pmd, page_address(pte_page))
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
-static inline struct page *
+static inline pgtable_t
 pte_alloc_one(struct mm_struct *mm, unsigned long address)
 {
        struct page *page = alloc_page(GFP_KERNEL|__GFP_REPEAT|__GFP_ZERO);
+       if (page)
+               pgtable_page_ctor(page);
        return page;
 }
 
@@ -135,7 +138,11 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        free_page((unsigned long)pte);
 }
 
-#define pte_free(mm, page) pte_free_kernel(page_address(page))
+static inline void pte_free_kernel(struct mm_struct *mm, struct page *pte)
+{
+       pgtable_page_dtor(pte);
+       pte_free_kernel(page_address((pte));
+}
 
 #define check_pgt_cache()      do { } while (0)
 
index b634e3c47fdce61d08f2fdaef2abf5f2c3f464c1..bb725a6630bb97373db7e212fc18b55d7dfa67b1 100644 (file)
@@ -47,18 +47,14 @@ typedef unsigned long long  __kernel_ino64_t;
 typedef unsigned int           __kernel_old_dev_t;
 
 typedef struct {
-#if defined(__KERNEL__) || defined(__USE_ALL)
        int     val[2];
-#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
-       int     __val[2];
-#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
 } __kernel_fsid_t;
 
 /* compatibility stuff */
 typedef __kernel_uid_t __kernel_old_uid_t;
 typedef __kernel_gid_t __kernel_old_gid_t;
 
-#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
+#if defined(__KERNEL__)
 
 #undef __FD_SET
 static __inline__ void __FD_SET(unsigned long __fd, __kernel_fd_set *__fdsetp)
@@ -128,6 +124,6 @@ static __inline__ void __FD_ZERO(__kernel_fd_set *__p)
        }
 }
 
-#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+#endif /* defined(__KERNEL__) */
 
 #endif
index 3bb06e898fdef5f0ad27d66a7144ed2e945c6d06..3c9d34844c83e0f6f4939ed01d54887ce16b7b5d 100644 (file)
 #define DEFAULT_MAP_BASE       DEFAULT_MAP_BASE32
 #endif
 
+#ifdef __KERNEL__
+
+/* XXX: STACK_TOP actually should be STACK_BOTTOM for parisc.
+ * prumpf */
+
+#define STACK_TOP      TASK_SIZE
+#define STACK_TOP_MAX  DEFAULT_TASK_SIZE
+
+#endif
+
 #ifndef __ASSEMBLY__
 
 /*
index 5c5ea83f934956c4f9e2166e95e170194602d29d..89cead6b176e3a33a8b1464c061ce8937c875e3d 100644 (file)
@@ -17,23 +17,4 @@ struct exec
 #define N_DRSIZE(a)    ((a).a_drsize)
 #define N_SYMSIZE(a)   ((a).a_syms)
 
-#ifdef __KERNEL__
-#ifdef __powerpc64__
-
-#define STACK_TOP_USER64 TASK_SIZE_USER64
-#define STACK_TOP_USER32 TASK_SIZE_USER32
-
-#define STACK_TOP (test_thread_flag(TIF_32BIT) ? \
-                  STACK_TOP_USER32 : STACK_TOP_USER64)
-
-#define STACK_TOP_MAX STACK_TOP_USER64
-
-#else /* __powerpc64__ */
-
-#define STACK_TOP TASK_SIZE
-#define STACK_TOP_MAX  STACK_TOP
-
-#endif /* __powerpc64__ */
-#endif /* __KERNEL__ */
-
 #endif /* _ASM_POWERPC_A_OUT_H */
index 61e3725bbd37e18eae791ed2b3cf36e3d045b2eb..df47bbb6ea1348e6c6ad95898baa911e819823b7 100644 (file)
@@ -190,6 +190,8 @@ extern int page_is_ram(unsigned long pfn);
 
 struct vm_area_struct;
 
+typedef struct page *pgtable_t;
+
 #include <asm-generic/memory_model.h>
 #endif /* __ASSEMBLY__ */
 
index c162a4c37b39ce5df12573c209dfd3a1edbdd59b..58c07147b3ea445c17851c8cb5ab8489a6432805 100644 (file)
@@ -22,17 +22,19 @@ extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
                (pmd_val(*(pmd)) = __pa(pte) | _PMD_PRESENT)
 #define pmd_populate(mm, pmd, pte)     \
                (pmd_val(*(pmd)) = (page_to_pfn(pte) << PAGE_SHIFT) | _PMD_PRESENT)
+#define pmd_pgtable(pmd) pmd_page(pmd)
 #else
 #define pmd_populate_kernel(mm, pmd, pte)      \
                (pmd_val(*(pmd)) = (unsigned long)pte | _PMD_PRESENT)
 #define pmd_populate(mm, pmd, pte)     \
                (pmd_val(*(pmd)) = (unsigned long)lowmem_page_address(pte) | _PMD_PRESENT)
+#define pmd_pgtable(pmd) pmd_page(pmd)
 #endif
 
 extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr);
-extern struct page *pte_alloc_one(struct mm_struct *mm, unsigned long addr);
+extern pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long addr);
 extern void pte_free_kernel(struct mm_struct *mm, pte_t *pte);
-extern void pte_free(struct mm_struct *mm, struct page *pte);
+extern void pte_free(struct mm_struct *mm, pgtable_t pte);
 
 #define __pte_free_tlb(tlb, pte)       pte_free((tlb)->mm, (pte))
 
index 5afae8593931e5cf4966688307488adfc856a38b..68980990f62a764f3896cfe95830d412f98cf824 100644 (file)
@@ -58,6 +58,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
 #define pmd_populate(mm, pmd, pte_page) \
        pmd_populate_kernel(mm, pmd, page_address(pte_page))
 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 
 #else /* CONFIG_PPC_64K_PAGES */
@@ -72,6 +73,7 @@ static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
 
 #define pmd_populate(mm, pmd, pte_page) \
        pmd_populate_kernel(mm, pmd, page_address(pte_page))
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 #endif /* CONFIG_PPC_64K_PAGES */
 
@@ -92,11 +94,18 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
         return (pte_t *)__get_free_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
 }
 
-static inline struct page *pte_alloc_one(struct mm_struct *mm,
-                                        unsigned long address)
+static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
+                                       unsigned long address)
 {
-       pte_t *pte = pte_alloc_one_kernel(mm, address);
-       return pte ? virt_to_page(pte) : NULL;
+       struct page *page;
+       pte_t *pte;
+
+       pte = pte_alloc_one_kernel(mm, address);
+       if (!pte)
+               return NULL;
+       page = virt_to_page(pte);
+       pgtable_page_ctor(page);
+       return page;
 }
 
 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
@@ -104,8 +113,9 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        free_page((unsigned long)pte);
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *ptepage)
+static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
 {
+       pgtable_page_dtor(ptepage);
        __free_page(ptepage);
 }
 
@@ -136,9 +146,12 @@ static inline void pgtable_free(pgtable_free_t pgf)
 
 extern void pgtable_free_tlb(struct mmu_gather *tlb, pgtable_free_t pgf);
 
-#define __pte_free_tlb(tlb, ptepage)   \
+#define __pte_free_tlb(tlb,ptepage)    \
+do { \
+       pgtable_page_dtor(ptepage); \
        pgtable_free_tlb(tlb, pgtable_free_cache(page_address(ptepage), \
-               PTE_NONCACHE_NUM, PTE_TABLE_SIZE-1))
+               PTE_NONCACHE_NUM, PTE_TABLE_SIZE-1)); \
+} while (0)
 #define __pmd_free_tlb(tlb, pmd)       \
        pgtable_free_tlb(tlb, pgtable_free_cache(pmd, \
                PMD_CACHE_NUM, PMD_TABLE_SIZE-1))
index 2f2288f520bed3422e7f06a99d096ab27d16a9be..c4e396b540df54289c0d5b2433ec3e93608a39d2 100644 (file)
@@ -64,8 +64,7 @@ typedef struct {
 
 #else /* __GNUC__ */
 
-#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) \
-    || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 0)
+#if defined(__KERNEL__)
 /* With GNU C, use inline functions instead so args are evaluated only once: */
 
 #undef __FD_SET
@@ -124,6 +123,6 @@ static __inline__ void __FD_ZERO(__kernel_fd_set *p)
        }
 }
 
-#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+#endif /* defined(__KERNEL__) */
 #endif /* __GNUC__ */
 #endif /* _ASM_POWERPC_POSIX_TYPES_H */
index 1f4765d6546fe0313b6bbc150ff38b509d6811ba..fd98ca998b4fa87cec01af7418af98c207a273eb 100644 (file)
@@ -113,6 +113,25 @@ extern struct task_struct *last_task_used_spe;
                TASK_UNMAPPED_BASE_USER32 : TASK_UNMAPPED_BASE_USER64 )
 #endif
 
+#ifdef __KERNEL__
+#ifdef __powerpc64__
+
+#define STACK_TOP_USER64 TASK_SIZE_USER64
+#define STACK_TOP_USER32 TASK_SIZE_USER32
+
+#define STACK_TOP (test_thread_flag(TIF_32BIT) ? \
+                  STACK_TOP_USER32 : STACK_TOP_USER64)
+
+#define STACK_TOP_MAX STACK_TOP_USER64
+
+#else /* __powerpc64__ */
+
+#define STACK_TOP TASK_SIZE
+#define STACK_TOP_MAX  STACK_TOP
+
+#endif /* __powerpc64__ */
+#endif /* __KERNEL__ */
+
 typedef struct {
        unsigned long seg;
 } mm_segment_t;
index 7c39a95829c7263932cf445fe94200c050991df4..fd4d1d74cfb1da92f1714e30755ef228ba3fb275 100644 (file)
@@ -23,17 +23,19 @@ extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
                (pmd_val(*(pmd)) = __pa(pte) | _PMD_PRESENT)
 #define pmd_populate(mm, pmd, pte)     \
                (pmd_val(*(pmd)) = (page_to_pfn(pte) << PAGE_SHIFT) | _PMD_PRESENT)
+#define pmd_pgtable(pmd) pmd_page(pmd)
 #else
 #define pmd_populate_kernel(mm, pmd, pte)      \
                (pmd_val(*(pmd)) = (unsigned long)pte | _PMD_PRESENT)
 #define pmd_populate(mm, pmd, pte)     \
                (pmd_val(*(pmd)) = (unsigned long)lowmem_page_address(pte) | _PMD_PRESENT)
+#define pmd_pgtable(pmd) pmd_page(pmd)
 #endif
 
 extern pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long addr);
-extern struct page *pte_alloc_one(struct mm_struct *mm, unsigned long addr);
+extern pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long addr);
 extern void pte_free_kernel(struct mm_struct *mm, pte_t *pte);
-extern void pte_free(struct mm_struct *mm, struct page *pte);
+extern void pte_free(struct mm_struct *mm, pgtable_t pte);
 
 #define __pte_free_tlb(tlb, pte)       pte_free((tlb)->mm, (pte))
 
index 46158dcaf5178107a22701eb96a39c523b3b1b57..8d6bd9c2952e400902c2b353ada7acb9f3d1e08f 100644 (file)
@@ -29,11 +29,4 @@ struct exec
 #define N_DRSIZE(a)    ((a).a_drsize)
 #define N_SYMSIZE(a)   ((a).a_syms)
 
-#ifdef __KERNEL__
-
-#define STACK_TOP      TASK_SIZE
-#define STACK_TOP_MAX  DEFAULT_TASK_SIZE
-
-#endif
-
 #endif /* __A_OUT_GNU_H__ */
index 07e19b2dd73fd0181c50cb32c3c59a1b0c969d3d..40e481b1b4613777e19a555a2814597ac7a6f7b8 100644 (file)
 #define TIOCSBRK       0x5427  /* BSD compatibility */
 #define TIOCCBRK       0x5428  /* BSD compatibility */
 #define TIOCGSID       0x5429  /* Return the session ID of FD */
+#define TCGETS2                _IOR('T',0x2A, struct termios2)
+#define TCSETS2                _IOW('T',0x2B, struct termios2)
+#define TCSETSW2       _IOW('T',0x2C, struct termios2)
+#define TCSETSF2       _IOW('T',0x2D, struct termios2)
 #define TIOCGPTN       _IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */
 #define TIOCSPTLCK     _IOW('T',0x31, int)  /* Lock/unlock Pty */
 
index a55f9d979dfb0a29aa87d8b61c2d1680529bc31c..7f29a981f48c78580bc80060bc72c798e7599ce7 100644 (file)
@@ -109,6 +109,8 @@ typedef struct { unsigned long pgd; } pgd_t;
 
 #endif /* __s390x__ */
 
+typedef struct page *pgtable_t;
+
 #define __pte(x)        ((pte_t) { (x) } )
 #define __pmd(x)        ((pmd_t) { (x) } )
 #define __pgd(x)        ((pgd_t) { (x) } )
index 6f6619ba898062c6af642c83dd574eda02c0e6c6..900d44807e107bf2d8ce042b433cad88bf50f7e3 100644 (file)
@@ -132,7 +132,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, pte_t *pte)
 }
 
 static inline void
-pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *page)
+pmd_populate(struct mm_struct *mm, pmd_t *pmd, pgtable_t page)
 {
        pte_t *pte = (pte_t *)page_to_phys(page);
        pmd_t *shadow_pmd = get_shadow_table(pmd);
@@ -142,6 +142,7 @@ pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *page)
        if (shadow_pmd && shadow_pte)
                pmd_populate_kernel(mm, shadow_pmd, shadow_pte);
 }
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 /*
  * page table entry allocation/free routines.
index 4f744609cd11b35aed60e95e33125553809b1692..e8785634cbdbf99540d8fca6a843a016904178e8 100644 (file)
@@ -78,6 +78,13 @@ extern int get_cpu_capability(unsigned int *);
 
 #endif /* __s390x__ */
 
+#ifdef __KERNEL__
+
+#define STACK_TOP              TASK_SIZE
+#define STACK_TOP_MAX          DEFAULT_TASK_SIZE
+
+#endif
+
 #define HAVE_ARCH_PICK_MMAP_LAYOUT
 
 typedef struct {
@@ -161,6 +168,7 @@ struct stack_frame {
 /* Forward declaration, a strange C thing */
 struct task_struct;
 struct mm_struct;
+struct seq_file;
 
 /* Free all resources held by a thread. */
 extern void release_thread(struct task_struct *);
@@ -177,7 +185,7 @@ extern unsigned long thread_saved_pc(struct task_struct *t);
 /*
  * Print register of task into buffer. Used in fs/proc/array.c.
  */
-extern char *task_show_regs(struct task_struct *task, char *buffer);
+extern void task_show_regs(struct seq_file *m, struct task_struct *task);
 
 extern void show_registers(struct pt_regs *regs);
 extern void show_code(struct pt_regs *regs);
index 811b9a9cdc085ad577476696879755c636a55792..58731853d529bc6a893d4b41114cb1b6f208e003 100644 (file)
@@ -148,6 +148,7 @@ struct ktermios {
 #define HUPCL  0002000
 #define CLOCAL 0004000
 #define CBAUDEX 0010000
+#define  BOTHER  0010000
 #define  B57600  0010001
 #define  B115200 0010002
 #define  B230400 0010003
@@ -163,10 +164,12 @@ struct ktermios {
 #define  B3000000 0010015
 #define  B3500000 0010016
 #define  B4000000 0010017
-#define CIBAUD   002003600000  /* input baud rate (not used) */
+#define CIBAUD   002003600000  /* input baud rate */
 #define CMSPAR   010000000000          /* mark or space (stick) parity */
 #define CRTSCTS          020000000000          /* flow control */
 
+#define IBSHIFT          16            /* Shift from CBAUD to CIBAUD */
+
 /* c_lflag bits */
 #define ISIG   0000001
 #define ICANON 0000002
index a3480e25eb4b3ff2af0f388227d924c8326ba1d6..67f66278f533f8706d5467560530a164c63121cf 100644 (file)
@@ -57,6 +57,9 @@ struct termio {
 */
 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
 
+#define user_termios_to_kernel_termios(k, u) copy_from_user(k, u, sizeof(struct termios2))
+#define kernel_termios_to_user_termios(u, k) copy_to_user(u, k, sizeof(struct termios2))
+
 #include <asm-generic/termios.h>
 
 #endif /* __KERNEL__ */
index 985de2b88279c99a563d85635af1ccec07fc0a6c..3c8177fa9e06e9b0b7800f14ce112917b9843dcc 100644 (file)
@@ -95,7 +95,7 @@ static inline void tlb_remove_page(struct mmu_gather *tlb, struct page *page)
  * pte_free_tlb frees a pte table and clears the CRSTE for the
  * page table from the tlb.
  */
-static inline void pte_free_tlb(struct mmu_gather *tlb, struct page *page)
+static inline void pte_free_tlb(struct mmu_gather *tlb, pgtable_t page)
 {
        if (!tlb->fullmm) {
                tlb->array[tlb->nr_ptes++] = page;
index 685d0f6125fab272d81ccc8220afc008777e89ff..1f93130e179cb8bf7f6c10e164e3b3d2ec5f441f 100644 (file)
@@ -17,11 +17,4 @@ struct exec
 #define N_DRSIZE(a)    ((a).a_drsize)
 #define N_SYMSIZE(a)   ((a).a_syms)
 
-#ifdef __KERNEL__
-
-#define STACK_TOP      TASK_SIZE
-#define STACK_TOP_MAX  STACK_TOP
-
-#endif
-
 #endif /* __ASM_SH_A_OUT_H */
index e0fe02950f522b067d75bd8cf4f2d5ecbfeaf41c..134562dc8c4547224739ef99c819c91c39d4659c 100644 (file)
@@ -100,6 +100,8 @@ typedef struct { unsigned long pgd; } pgd_t;
 #define __pgd(x) ((pgd_t) { (x) } )
 #define __pgprot(x)    ((pgprot_t) { (x) } )
 
+typedef struct page *pgtable_t;
+
 #endif /* !__ASSEMBLY__ */
 
 /*
index 59ca16d77a1d79b20775362e8d76d7d9cc2d3594..84dd2db7104c74f4f57eb4f1c7d0bfc1f4159869 100644 (file)
@@ -14,10 +14,11 @@ static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
 }
 
 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
-                               struct page *pte)
+                               pgtable_t pte)
 {
        set_pmd(pmd, __pmd((unsigned long)page_address(pte)));
 }
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 static inline void pgd_ctor(void *x)
 {
@@ -47,11 +48,18 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
        return quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
 }
 
-static inline struct page *pte_alloc_one(struct mm_struct *mm,
-                                        unsigned long address)
+static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
+                                       unsigned long address)
 {
-       void *pg = quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
-       return pg ? virt_to_page(pg) : NULL;
+       struct page *page;
+       void *pg;
+
+       pg = quicklist_alloc(QUICK_PT, GFP_KERNEL | __GFP_REPEAT, NULL);
+       if (!pg)
+               return NULL;
+       page = virt_to_page(pg);
+       pgtable_page_ctor(page);
+       return page;
 }
 
 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
@@ -59,12 +67,17 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        quicklist_free(QUICK_PT, NULL, pte);
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *pte)
+static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 {
+       pgtable_page_dtor(pte);
        quicklist_free_page(QUICK_PT, NULL, pte);
 }
 
-#define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
+#define __pte_free_tlb(tlb,pte)                                \
+do {                                                   \
+       pgtable_page_dtor(pte);                         \
+       tlb_remove_page((tlb), (pte));                  \
+} while (0)
 
 /*
  * allocating and freeing a pmd is trivial: the 1-entry pmd is
index a7edaa1a870cbe52dab58864e569a479cfcbd0e1..df2d5b039ef41ad5bfdf5bd0e99436461a49bb28 100644 (file)
@@ -50,6 +50,9 @@ extern struct sh_cpuinfo cpu_data[];
  */
 #define TASK_SIZE      0x7c000000UL
 
+#define STACK_TOP      TASK_SIZE
+#define STACK_TOP_MAX  STACK_TOP
+
 /* This decides where the kernel will search for a free chunk of vm
  * space during mmap's.
  */
index 99c22b14a85b1b20abea399446247119cd82997a..eda4bef448e9f867f70c23a31b9eaa2d5be2a8e4 100644 (file)
@@ -83,6 +83,9 @@ extern struct sh_cpuinfo cpu_data[];
  */
 #define TASK_SIZE      0x7ffff000UL
 
+#define STACK_TOP      TASK_SIZE
+#define STACK_TOP_MAX  STACK_TOP
+
 /* This decides where the kernel will search for a free chunk of vm
  * space during mmap's.
  */
diff --git a/include/asm-sparc/a.out-core.h b/include/asm-sparc/a.out-core.h
new file mode 100644 (file)
index 0000000..e8fd338
--- /dev/null
@@ -0,0 +1,52 @@
+/* a.out coredump register dumper
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_A_OUT_CORE_H
+#define _ASM_A_OUT_CORE_H
+
+#ifdef __KERNEL__
+
+#include <linux/user.h>
+
+/*
+ * fill in the user structure for an a.out core dump
+ */
+static inline void aout_dump_thread(struct pt_regs *regs, struct user *dump)
+{
+       unsigned long first_stack_page;
+
+       dump->magic = SUNOS_CORE_MAGIC;
+       dump->len = sizeof(struct user);
+       dump->regs.psr = regs->psr;
+       dump->regs.pc = regs->pc;
+       dump->regs.npc = regs->npc;
+       dump->regs.y = regs->y;
+       /* fuck me plenty */
+       memcpy(&dump->regs.regs[0], &regs->u_regs[1], (sizeof(unsigned long) * 15));
+       dump->uexec = current->thread.core_exec;
+       dump->u_tsize = (((unsigned long) current->mm->end_code) -
+               ((unsigned long) current->mm->start_code)) & ~(PAGE_SIZE - 1);
+       dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1)));
+       dump->u_dsize -= dump->u_tsize;
+       dump->u_dsize &= ~(PAGE_SIZE - 1);
+       first_stack_page = (regs->u_regs[UREG_FP] & ~(PAGE_SIZE - 1));
+       dump->u_ssize = (TASK_SIZE - first_stack_page) & ~(PAGE_SIZE - 1);
+       memcpy(&dump->fpu.fpstatus.fregs.regs[0], &current->thread.float_regs[0], (sizeof(unsigned long) * 32));
+       dump->fpu.fpstatus.fsr = current->thread.fsr;
+       dump->fpu.fpstatus.flags = dump->fpu.fpstatus.extra = 0;
+       dump->fpu.fpstatus.fpq_count = current->thread.fpqdepth;
+       memcpy(&dump->fpu.fpstatus.fpq[0], &current->thread.fpqueue[0],
+              ((sizeof(unsigned long) * 2) * 16));
+       dump->sigcode = 0;
+}
+
+#endif /* __KERNEL__ */
+#endif /* _ASM_A_OUT_CORE_H */
index 917e04250696d065ef46bd5c3ae7c15be8b0123d..744cfe6c0de8ffca0c3d61b06d7735df8488c89f 100644 (file)
@@ -87,13 +87,4 @@ struct relocation_info /* used when header.a_machtype == M_SPARC */
 
 #define N_RELOCATION_INFO_DECLARED 1
 
-#ifdef __KERNEL__
-
-#include <asm/page.h>
-
-#define STACK_TOP      (PAGE_OFFSET - PAGE_SIZE)
-#define STACK_TOP_MAX  STACK_TOP
-
-#endif /* __KERNEL__ */
-
 #endif /* __SPARC_A_OUT_H__ */
index cbc48c0c4e15324fdafe23640036a5127315eea1..39ccf2da297c757e6b9e47f60d3dddec04bb4da4 100644 (file)
@@ -123,6 +123,8 @@ typedef unsigned long iopgprot_t;
 
 #endif
 
+typedef struct page *pgtable_t;
+
 extern unsigned long sparc_unmapped_base;
 
 BTFIXUPDEF_SETHI(sparc_unmapped_base)
index beaf02d364f231374f0f6c602f68839754b2cec2..86ba59af9d2c7d44d775a64d3c548d53622228a2 100644 (file)
@@ -3,7 +3,7 @@
 #define _ASMSPARC_PARAM_H
 
 #ifdef __KERNEL__
-# define HZ            100     /* Internal kernel timer frequency */
+# define HZ            CONFIG_HZ       /* Internal kernel timer frequency */
 # define USER_HZ       100     /* .. some user interfaces are in "ticks" */
 # define CLOCKS_PER_SEC (USER_HZ)
 #endif
index b5fbdd36447fbf2b69f384957b76962731553645..6292cd00e5affdd8f913ddbfc1dbf290795384ac 100644 (file)
@@ -50,10 +50,11 @@ BTFIXUPDEF_CALL(void, free_pmd_fast, pmd_t *)
 
 BTFIXUPDEF_CALL(void, pmd_populate, pmd_t *, struct page *)
 #define pmd_populate(MM, PMD, PTE)        BTFIXUP_CALL(pmd_populate)(PMD, PTE)
+#define pmd_pgtable(pmd) pmd_page(pmd)
 BTFIXUPDEF_CALL(void, pmd_set, pmd_t *, pte_t *)
 #define pmd_populate_kernel(MM, PMD, PTE) BTFIXUP_CALL(pmd_set)(PMD, PTE)
 
-BTFIXUPDEF_CALL(struct page *, pte_alloc_one, struct mm_struct *, unsigned long)
+BTFIXUPDEF_CALL(pgtable_t , pte_alloc_one, struct mm_struct *, unsigned long)
 #define pte_alloc_one(mm, address)     BTFIXUP_CALL(pte_alloc_one)(mm, address)
 BTFIXUPDEF_CALL(pte_t *, pte_alloc_one_kernel, struct mm_struct *, unsigned long)
 #define pte_alloc_one_kernel(mm, addr) BTFIXUP_CALL(pte_alloc_one_kernel)(mm, addr)
@@ -61,7 +62,7 @@ BTFIXUPDEF_CALL(pte_t *, pte_alloc_one_kernel, struct mm_struct *, unsigned long
 BTFIXUPDEF_CALL(void, free_pte_fast, pte_t *)
 #define pte_free_kernel(mm, pte)       BTFIXUP_CALL(free_pte_fast)(pte)
 
-BTFIXUPDEF_CALL(void, pte_free, struct page *)
+BTFIXUPDEF_CALL(void, pte_free, pgtable_t )
 #define pte_free(mm, pte)      BTFIXUP_CALL(pte_free)(pte)
 #define __pte_free_tlb(tlb, pte)       pte_free((tlb)->mm, pte)
 
index 62c8fa7b36d4e8556c56900f0cfadf46f5221abc..dcc07eb5e181b8394143ab9396a4a3576967753a 100644 (file)
@@ -39,14 +39,10 @@ typedef long long   __kernel_loff_t;
 #endif
 
 typedef struct {
-#if defined(__KERNEL__) || defined(__USE_ALL)
        int     val[2];
-#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
-       int     __val[2];
-#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
 } __kernel_fsid_t;
 
-#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
+#if defined(__KERNEL__)
 
 #undef __FD_SET
 static inline void __FD_SET(unsigned long fd, __kernel_fd_set *fdsetp)
@@ -117,6 +113,6 @@ static inline void __FD_ZERO(__kernel_fd_set *p)
        }
 }
 
-#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+#endif /* defined(__KERNEL__) */
 
 #endif /* !(__ARCH_SPARC_POSIX_TYPES_H) */
index 6fbb3f0af8d891a6b7e1fdc8b80c58970a0a5a4e..40b1e41fdea7037e8d361c372674dd8cb55e39de 100644 (file)
  * we can make our access_ok test faster
  */
 #define TASK_SIZE      PAGE_OFFSET
+#ifdef __KERNEL__
+#define STACK_TOP      (PAGE_OFFSET - PAGE_SIZE)
+#define STACK_TOP_MAX  STACK_TOP
+#endif /* __KERNEL__ */
 
 struct task_struct;
 
index 3cf132e1aa2548c19c62cc885d063129b7ed05d2..366b11696ee3cddd18690964a9b791cf5ff3608a 100644 (file)
@@ -13,7 +13,6 @@
 #include <linux/string.h>
 #include <linux/errno.h>
 #include <asm/vac-ops.h>
-#include <asm/a.out.h>
 #endif
 
 #ifndef __ASSEMBLY__
diff --git a/include/asm-sparc64/a.out-core.h b/include/asm-sparc64/a.out-core.h
new file mode 100644 (file)
index 0000000..3499b3c
--- /dev/null
@@ -0,0 +1,31 @@
+/* a.out coredump register dumper
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_A_OUT_CORE_H
+#define _ASM_A_OUT_CORE_H
+
+#ifdef __KERNEL__
+
+#include <linux/user.h>
+
+/*
+ * fill in the user structure for an a.out core dump
+ */
+static inline void aout_dump_thread(struct pt_regs *regs, struct user *dump)
+{
+       /* Only should be used for SunOS and ancient a.out
+        * SparcLinux binaries...  Not worth implementing.
+        */
+       memset(dump, 0, sizeof(struct user));
+}
+
+#endif /* __KERNEL__ */
+#endif /* _ASM_A_OUT_CORE_H */
index 902e07f89a42a7ab125ee032775e1842a239efb6..53c95bdfc66eb5e005442e0db26bc3c34d7524a5 100644 (file)
@@ -93,18 +93,6 @@ struct relocation_info /* used when header.a_machtype == M_SPARC */
 
 #define N_RELOCATION_INFO_DECLARED 1
 
-#ifdef __KERNEL__
-
-#define STACK_TOP32    ((1UL << 32UL) - PAGE_SIZE)
-#define STACK_TOP64    (0x0000080000000000UL - (1UL << 32UL))
-
-#define STACK_TOP (test_thread_flag(TIF_32BIT) ? \
-                  STACK_TOP32 : STACK_TOP64)
-
-#define STACK_TOP_MAX STACK_TOP64
-
-#endif
-
 #endif /* !(__ASSEMBLY__) */
 
 #endif /* !(__SPARC64_A_OUT_H__) */
index cdf950e017eeebad8cb7e553953ac8808ec188ec..e93a482aa24a0b874c50a2d109bf55f6b9c28fdc 100644 (file)
@@ -104,6 +104,8 @@ typedef unsigned long pgprot_t;
 
 #endif /* (STRICT_MM_TYPECHECKS) */
 
+typedef struct page *pgtable_t;
+
 #define TASK_UNMAPPED_BASE     (test_thread_flag(TIF_32BIT) ? \
                                 (_AC(0x0000000070000000,UL)) : \
                                 (_AC(0xfffff80000000000,UL) + (1UL << 32UL)))
index b48f73c2274ef7ee682204deffa9bcd09dad962f..3ee2d406373b9fc03a671d2c28b49adbb91dd634 100644 (file)
@@ -43,11 +43,18 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
        return quicklist_alloc(0, GFP_KERNEL, NULL);
 }
 
-static inline struct page *pte_alloc_one(struct mm_struct *mm,
-                                        unsigned long address)
+static inline pgtable_t pte_alloc_one(struct mm_struct *mm,
+                                       unsigned long address)
 {
-       void *pg = quicklist_alloc(0, GFP_KERNEL, NULL);
-       return pg ? virt_to_page(pg) : NULL;
+       struct page *page;
+       void *pg;
+
+       pg = quicklist_alloc(0, GFP_KERNEL, NULL);
+       if (!pg)
+               return NULL;
+       page = virt_to_page(pg);
+       pgtable_page_ctor(page);
+       return page;
 }
                
 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
@@ -55,8 +62,9 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        quicklist_free(0, NULL, pte);
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *ptepage)
+static inline void pte_free(struct mm_struct *mm, pgtable_t ptepage)
 {
+       pgtable_page_dtor(ptepage);
        quicklist_free_page(0, NULL, ptepage);
 }
 
@@ -64,6 +72,7 @@ static inline void pte_free(struct mm_struct *mm, struct page *ptepage)
 #define pmd_populate_kernel(MM, PMD, PTE)      pmd_set(PMD, PTE)
 #define pmd_populate(MM,PMD,PTE_PAGE)          \
        pmd_populate_kernel(MM,PMD,page_address(PTE_PAGE))
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 static inline void check_pgt_cache(void)
 {
index 3426a65ecd3527bce9522dd23396c91bc8414ae0..4eaaa0196636ebd91c5a8255cd38d611fc8a4502 100644 (file)
@@ -43,14 +43,10 @@ typedef long long              __kernel_loff_t;
 #endif
 
 typedef struct {
-#if defined(__KERNEL__) || defined(__USE_ALL)
        int     val[2];
-#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
-       int     __val[2];
-#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
 } __kernel_fsid_t;
 
-#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
+#if defined(__KERNEL__)
 
 #undef __FD_SET
 static inline void __FD_SET(unsigned long fd, __kernel_fd_set *fdsetp)
@@ -121,6 +117,6 @@ static inline void __FD_ZERO(__kernel_fd_set *p)
        }
 }
 
-#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+#endif /* defined(__KERNEL__) */
 
 #endif /* !(__ARCH_SPARC64_POSIX_TYPES_H) */
index 66dd2fa0e319ef9025b849951887d2ee0775b04d..8da484c19822cc1d08d59d4fc635e06329ef2675 100644 (file)
@@ -14,7 +14,6 @@
 #define current_text_addr() ({ void *pc; __asm__("rd %%pc, %0" : "=r" (pc)); pc; })
 
 #include <asm/asi.h>
-#include <asm/a.out.h>
 #include <asm/pstate.h>
 #include <asm/ptrace.h>
 #include <asm/page.h>
 #else
 #define VPTE_SIZE      (1 << (VA_BITS - PAGE_SHIFT + 3))
 #endif
+
 #define TASK_SIZE      ((unsigned long)-VPTE_SIZE)
+#ifdef __KERNEL__
+
+#define STACK_TOP32    ((1UL << 32UL) - PAGE_SIZE)
+#define STACK_TOP64    (0x0000080000000000UL - (1UL << 32UL))
+
+#define STACK_TOP      (test_thread_flag(TIF_32BIT) ? \
+                        STACK_TOP32 : STACK_TOP64)
+
+#define STACK_TOP_MAX  STACK_TOP64
+
+#endif
 
 #ifndef __ASSEMBLY__
 
index 93720e7b0289250267dbc461b1defb9d4160e6e5..d8547b87e730e7db3c77efd372db27f04a06066d 100644 (file)
@@ -10,7 +10,6 @@
 #include <linux/compiler.h>
 #include <linux/sched.h>
 #include <linux/string.h>
-#include <asm/a.out.h>
 #include <asm/asi.h>
 #include <asm/system.h>
 #include <asm/spitfire.h>
index fce4e857dfc30632b82d79f4fce9b4e338a953c2..02b138943837347e45112cf6f4f35f40ab216387 100644 (file)
@@ -8,7 +8,7 @@
 #ifndef _SPARC64_USER_H
 #define _SPARC64_USER_H
 
-#include <asm/a.out.h>
+#include <linux/a.out.h>
 struct sunos_regs {
        unsigned int psr, pc, npc, y;
        unsigned int regs[15];
diff --git a/include/asm-um/a.out-core.h b/include/asm-um/a.out-core.h
new file mode 100644 (file)
index 0000000..995643b
--- /dev/null
@@ -0,0 +1,27 @@
+/* a.out coredump register dumper
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef __UM_A_OUT_CORE_H
+#define __UM_A_OUT_CORE_H
+
+#ifdef __KERNEL__
+
+#include <linux/user.h>
+
+/*
+ * fill in the user structure for an a.out core dump
+ */
+static inline void aout_dump_thread(struct pt_regs *regs, struct user *u)
+{
+}
+
+#endif /* __KERNEL__ */
+#endif /* __UM_A_OUT_CORE_H */
index f42ff14577fac4875228242f26128ae6659e92f0..754181ee86831433bcfcc4e2ba4ad78c516c6229 100644 (file)
@@ -8,15 +8,4 @@
 
 #include "asm/arch/a.out.h"
 
-#undef STACK_TOP
-#undef STACK_TOP_MAX
-
-extern unsigned long stacksizelim;
-
-#define STACK_ROOM (stacksizelim)
-
-#define STACK_TOP (TASK_SIZE - 2 * PAGE_SIZE)
-
-#define STACK_TOP_MAX STACK_TOP
-
 #endif
index 89a87c18b927f75d6b1ee486b83996deba4f754b..9d2be52b865526586c93a79f1a14d4d7515b820c 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __UM_FIXMAP_H
 #define __UM_FIXMAP_H
 
+#include <asm/processor.h>
 #include <asm/system.h>
 #include <asm/kmap_types.h>
 #include <asm/archparam.h>
@@ -57,7 +58,7 @@ extern void __set_fixmap (enum fixed_addresses idx,
  * at the top of mem..
  */
 
-#define FIXADDR_TOP    (CONFIG_TOP_ADDR - 2 * PAGE_SIZE)
+#define FIXADDR_TOP    (TASK_SIZE - 2 * PAGE_SIZE)
 #define FIXADDR_SIZE   (__end_of_fixed_addresses << PAGE_SHIFT)
 #define FIXADDR_START  (FIXADDR_TOP - FIXADDR_SIZE)
 
index fe2374d705d15af36114379cfa5e4192a1125aca..381f96b1c8259153fca3433c9eca220031fa1e63 100644 (file)
@@ -79,6 +79,8 @@ typedef unsigned long phys_t;
 
 typedef struct { unsigned long pgprot; } pgprot_t;
 
+typedef struct page *pgtable_t;
+
 #define pgd_val(x)     ((x).pgd)
 #define pgprot_val(x)  ((x).pgprot)
 
index 4f3e62b02861f0a743a3ffe45f280e127b0c7f01..9062a6e72241f60235b0c6f4c2bd41dd9c00ab6d 100644 (file)
@@ -18,6 +18,7 @@
        set_pmd(pmd, __pmd(_PAGE_TABLE +                        \
                ((unsigned long long)page_to_pfn(pte) <<        \
                        (unsigned long long) PAGE_SHIFT)))
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 /*
  * Allocate and free page tables.
@@ -26,19 +27,24 @@ extern pgd_t *pgd_alloc(struct mm_struct *);
 extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
 
 extern pte_t *pte_alloc_one_kernel(struct mm_struct *, unsigned long);
-extern struct page *pte_alloc_one(struct mm_struct *, unsigned long);
+extern pgtable_t pte_alloc_one(struct mm_struct *, unsigned long);
 
 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        free_page((unsigned long) pte);
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *pte)
+static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 {
+       pgtable_page_dtor(pte);
        __free_page(pte);
 }
 
-#define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
+#define __pte_free_tlb(tlb,pte)                                \
+do {                                                   \
+       pgtable_page_dtor(pte);                         \
+       tlb_remove_page((tlb),(pte));                   \
+} while (0)
 
 #ifdef CONFIG_3_LEVEL_PGTABLES
 
index b7d9a16a74511d74194515042f703ecf940e5f24..bed668824b5f94529c8d28e7209078d181f87d4b 100644 (file)
@@ -11,7 +11,6 @@ struct pt_regs;
 struct task_struct;
 
 #include "asm/ptrace.h"
-#include "asm/pgtable.h"
 #include "registers.h"
 #include "sysdep/archsetjmp.h"
 
@@ -92,7 +91,18 @@ static inline void mm_copy_segments(struct mm_struct *from_mm,
 /*
  * User space process size: 3GB (default).
  */
-#define TASK_SIZE (CONFIG_TOP_ADDR & PGDIR_MASK)
+extern unsigned long task_size;
+
+#define TASK_SIZE (task_size)
+
+#undef STACK_TOP
+#undef STACK_TOP_MAX
+
+extern unsigned long stacksizelim;
+
+#define STACK_ROOM     (stacksizelim)
+#define STACK_TOP      (TASK_SIZE - 2 * PAGE_SIZE)
+#define STACK_TOP_MAX  STACK_TOP
 
 /* This decides where the kernel will search for a free chunk of vm
  * space during mmap's.
index d946bf2d334a5fd08b18c0513d1cdb4571c653ac..e50933175e9105206e207afcdc61ec46d0d49463 100644 (file)
@@ -26,7 +26,7 @@ static inline void rep_nop(void)
 #define cpu_relax()   rep_nop()
 
 #define INIT_ARCH_THREAD { .debugregs                  = { [ 0 ... 7 ] = 0 }, \
-                           .debugregs_seq      = 0,                           \
+                          .debugregs_seq       = 0, \
                           .fs                  = 0, \
                           .faultinfo           = { 0, 0, 0 } }
 
@@ -37,6 +37,7 @@ static inline void arch_flush_thread(struct arch_thread *thread)
 static inline void arch_copy_thread(struct arch_thread *from,
                                     struct arch_thread *to)
 {
+       to->fs = from->fs;
 }
 
 #include "asm/arch/user.h"
index 3be77d5ecfce38c9d9efec628c529582083ef92f..cd5eaee103b0f8069bf3de282cbb4ac9d34ba5ef 100644 (file)
@@ -134,10 +134,4 @@ extern void anna_uart_pre_configure (unsigned chan,
 #define V850E_TIMER_D_TMCD_CS_MIN      1 /* min 2^1 divider */
 
 
-/* For <asm/param.h> */
-#ifndef HZ
-#define HZ     100
-#endif
-
-
 #endif /* __V850_ANNA_H__ */
index 659bc910ffd72f060012131b8c6fc05775e3299c..5a5ca9073d0931027a470091ecec0ac81ceddb4d 100644 (file)
@@ -149,10 +149,4 @@ extern void as85ep1_uart_pre_configure (unsigned chan,
 #define V850E_TIMER_D_TMCD_CS_MIN      2 /* min 2^2 divider */
 
 
-/* For <asm/param.h> */
-#ifndef HZ
-#define HZ     100
-#endif
-
-
 #endif /* __V850_AS85EP1_H__ */
index d32f04504b135073de1410fc14e8ea103184d6a5..23aae666c718ce62ae1f18129d6eec12021a3f5b 100644 (file)
@@ -79,10 +79,4 @@ extern char _r0_ram;
 #endif
 
 
-/* For <asm/param.h> */
-#ifndef HZ
-#define HZ                     122 /* actually, 8.192ms ticks =~ 122.07 */
-#endif
-
-
 #endif /* __V850_FPGA85E2C_H__ */
index 3c65bd573782d34e060d52299bfcc5a4cd7b37bb..281832690290536007c861a8362634cb673b7f43 100644 (file)
@@ -23,8 +23,7 @@
 #define MAXHOSTNAMELEN 64      /* max length of hostname */
 
 #ifdef __KERNEL__
-#include <asm/machdep.h>       /* For HZ */
-
+# define HZ            CONFIG_HZ
 # define USER_HZ       100
 # define CLOCKS_PER_SEC        USER_HZ
 #endif
index ccb7297a0edcab0e8fd7a8d849f62da02a3db982..7f403b765390d179e8e939835e9e5052d67677d0 100644 (file)
@@ -44,15 +44,11 @@ typedef __kernel_uid_t __kernel_old_uid_t;
 typedef unsigned int   __kernel_old_dev_t;
 
 typedef struct {
-#if defined(__KERNEL__) || defined(__USE_ALL)
        int     val[2];
-#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
-       int     __val[2];
-#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
 } __kernel_fsid_t;
 
 
-#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
+#if defined(__KERNEL__)
 
 /* We used to include <asm/bitops.h> here, which seems the right thing, but
    it caused nasty include-file definition order problems.  Removing the
@@ -71,6 +67,6 @@ typedef struct {
 #define __FD_ZERO(fd_set) \
   memset (fd_set, 0, sizeof (*(fd_set *)fd_set))
 
-#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+#endif /* defined(__KERNEL__) */
 
 #endif /* __V850_POSIX_TYPES_H__ */
index e85d261b79bf0ee140ab1f5f349b6b25e100d25d..db9879f00aa7b9adacca1a8b72a7f21126bdbb59 100644 (file)
 #endif /* CONFIG_RTE_MB_A_PCI */
 
 
-/* For <asm/param.h> */
-#ifndef HZ
-#define HZ     100
-#endif
-
-
 #ifndef __ASSEMBLY__
 extern void rte_cb_early_init (void);
 extern void rte_cb_init_irqs (void);
index 10236abbe9be7aca7fdfb04c4f28a1b1d3ee0aad..026932d476cd9036aa57208e780076687f6ba99b 100644 (file)
 #define R0_RAM_ADDR            0xFFFFF000
 
 
-/* For <asm/param.h> */
-#ifndef HZ
-#define HZ                     24      /* Minimum supported frequency.  */
-#endif
-
 /* For <asm/irq.h> */
 #define NUM_CPU_IRQS           6
 
index 17dd4fa318e65d4eb17ecbfb0f824b525f139eeb..8b4d6974066c2d624f3deb58ff32c17e5950682b 100644 (file)
 #define R0_RAM_ADDR            0xFFFFE000
 
 
-/* For <asm/param.h> */
-#ifndef HZ
-#define HZ                     24      /* Minimum supported frequency.  */
-#endif
-
-
 #endif /* __V850_SIM85E2_H__ */
diff --git a/include/asm-x86/a.out-core.h b/include/asm-x86/a.out-core.h
new file mode 100644 (file)
index 0000000..d2b6e11
--- /dev/null
@@ -0,0 +1,71 @@
+/* a.out coredump register dumper
+ *
+ * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public Licence
+ * as published by the Free Software Foundation; either version
+ * 2 of the Licence, or (at your option) any later version.
+ */
+
+#ifndef _ASM_A_OUT_CORE_H
+#define _ASM_A_OUT_CORE_H
+
+#ifdef __KERNEL__
+#ifdef CONFIG_X86_32
+
+#include <linux/user.h>
+#include <linux/elfcore.h>
+
+/*
+ * fill in the user structure for an a.out core dump
+ */
+static inline void aout_dump_thread(struct pt_regs *regs, struct user *dump)
+{
+       u16 gs;
+
+/* changed the size calculations - should hopefully work better. lbt */
+       dump->magic = CMAGIC;
+       dump->start_code = 0;
+       dump->start_stack = regs->sp & ~(PAGE_SIZE - 1);
+       dump->u_tsize = ((unsigned long) current->mm->end_code) >> PAGE_SHIFT;
+       dump->u_dsize = ((unsigned long) (current->mm->brk + (PAGE_SIZE-1))) >> PAGE_SHIFT;
+       dump->u_dsize -= dump->u_tsize;
+       dump->u_ssize = 0;
+       dump->u_debugreg[0] = current->thread.debugreg0;
+       dump->u_debugreg[1] = current->thread.debugreg1;
+       dump->u_debugreg[2] = current->thread.debugreg2;
+       dump->u_debugreg[3] = current->thread.debugreg3;
+       dump->u_debugreg[4] = 0;
+       dump->u_debugreg[5] = 0;
+       dump->u_debugreg[6] = current->thread.debugreg6;
+       dump->u_debugreg[7] = current->thread.debugreg7;
+
+       if (dump->start_stack < TASK_SIZE)
+               dump->u_ssize = ((unsigned long) (TASK_SIZE - dump->start_stack)) >> PAGE_SHIFT;
+
+       dump->regs.bx = regs->bx;
+       dump->regs.cx = regs->cx;
+       dump->regs.dx = regs->dx;
+       dump->regs.si = regs->si;
+       dump->regs.di = regs->di;
+       dump->regs.bp = regs->bp;
+       dump->regs.ax = regs->ax;
+       dump->regs.ds = (u16)regs->ds;
+       dump->regs.es = (u16)regs->es;
+       dump->regs.fs = (u16)regs->fs;
+       savesegment(gs,gs);
+       dump->regs.orig_ax = regs->orig_ax;
+       dump->regs.ip = regs->ip;
+       dump->regs.cs = (u16)regs->cs;
+       dump->regs.flags = regs->flags;
+       dump->regs.sp = regs->sp;
+       dump->regs.ss = (u16)regs->ss;
+
+       dump->u_fpvalid = dump_fpu (regs, &dump->i387);
+}
+
+#endif /* CONFIG_X86_32 */
+#endif /* __KERNEL__ */
+#endif /* _ASM_A_OUT_CORE_H */
index a62443e38eb81bb4fd7f68802d042e1aac66a8b8..4684f97a5bbd1b1edce881a88e75393b580a2cd1 100644 (file)
@@ -17,14 +17,4 @@ struct exec
 #define N_DRSIZE(a)    ((a).a_drsize)
 #define N_SYMSIZE(a)   ((a).a_syms)
 
-#ifdef __KERNEL__
-# include <linux/thread_info.h>
-# define STACK_TOP     TASK_SIZE
-# ifdef CONFIG_X86_32
-#  define STACK_TOP_MAX        STACK_TOP
-# else
-#  define STACK_TOP_MAX        TASK_SIZE64
-# endif
-#endif
-
 #endif /* _ASM_X86_A_OUT_H */
index a6fd10f230d2e628660e252bda6623bc3840f67f..ba715d9798b093aeee1a50aecf5373caf8930835 100644 (file)
@@ -50,6 +50,8 @@ typedef unsigned long phys_addr_t;
 typedef union { pteval_t pte, pte_low; } pte_t;
 typedef pte_t boot_pte_t;
 
+typedef struct page *pgtable_t;
+
 #endif /* __ASSEMBLY__ */
 #endif /* CONFIG_X86_PAE */
 
index dcf0c0746075ba07f4527f2018bb846f8ebf8424..f7393bc516eff1c1d25ad799f0441f734a151280 100644 (file)
@@ -71,6 +71,8 @@ typedef unsigned long pgdval_t;
 typedef unsigned long  pgprotval_t;
 typedef unsigned long  phys_addr_t;
 
+typedef struct page *pgtable_t;
+
 typedef struct { pteval_t pte; } pte_t;
 
 #define vmemmap ((struct page *)VMEMMAP_START)
index bab12718a913fa446f25c8c9e6e2b2d380e3761a..6bea6e5b5ee55044dd06bea1b55677bf9cba20bf 100644 (file)
@@ -31,6 +31,7 @@ static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *p
        paravirt_alloc_pt(mm, pfn);
        set_pmd(pmd, __pmd(((pteval_t)pfn << PAGE_SHIFT) | _PAGE_TABLE));
 }
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 /*
  * Allocate and free page tables.
@@ -39,15 +40,16 @@ extern pgd_t *pgd_alloc(struct mm_struct *);
 extern void pgd_free(struct mm_struct *mm, pgd_t *pgd);
 
 extern pte_t *pte_alloc_one_kernel(struct mm_struct *, unsigned long);
-extern struct page *pte_alloc_one(struct mm_struct *, unsigned long);
+extern pgtable_t pte_alloc_one(struct mm_struct *, unsigned long);
 
 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
 {
        free_page((unsigned long)pte);
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *pte)
+static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 {
+       pgtable_page_dtor(pte);
        __free_page(pte);
 }
 
index 4f6220db22b110bbf1606d75316a36e1b458fa1a..8d6722320dccd7818383abe4445eef5b9bc85f0c 100644 (file)
@@ -12,6 +12,8 @@
 #define pgd_populate(mm, pgd, pud) \
                set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)))
 
+#define pmd_pgtable(pmd) pmd_page(pmd)
+
 static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd, struct page *pte)
 {
        set_pmd(pmd, __pmd(_PAGE_TABLE | (page_to_pfn(pte) << PAGE_SHIFT)));
@@ -91,12 +93,17 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm, unsigned long ad
        return (pte_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
 }
 
-static inline struct page *pte_alloc_one(struct mm_struct *mm, unsigned long address)
+static inline pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
 {
-       void *p = (void *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
+       struct page *page;
+       void *p;
+
+       p = (void *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
        if (!p)
                return NULL;
-       return virt_to_page(p);
+       page = virt_to_page(p);
+       pgtable_page_ctor(page);
+       return page;
 }
 
 /* Should really implement gc for free page table pages. This could be
@@ -108,12 +115,17 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        free_page((unsigned long)pte); 
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *pte)
+static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 {
+       pgtable_page_dtor(pte);
        __free_page(pte);
 } 
 
-#define __pte_free_tlb(tlb,pte) tlb_remove_page((tlb),(pte))
+#define __pte_free_tlb(tlb,pte)                                \
+do {                                                   \
+       pgtable_page_dtor((pte));                               \
+       tlb_remove_page((tlb), (pte));                  \
+} while (0)
 
 #define __pmd_free_tlb(tlb,x)   tlb_remove_page((tlb),virt_to_page(x))
 #define __pud_free_tlb(tlb,x)   tlb_remove_page((tlb),virt_to_page(x))
index 133e31e7dfdeb452cd311ea73fff5c3b2603df07..015e539cdef5536f639a08bfe281cfa207075562 100644 (file)
@@ -39,14 +39,10 @@ typedef long long   __kernel_loff_t;
 #endif
 
 typedef struct {
-#if defined(__KERNEL__) || defined(__USE_ALL)
        int     val[2];
-#else /* !defined(__KERNEL__) && !defined(__USE_ALL) */
-       int     __val[2];
-#endif /* !defined(__KERNEL__) && !defined(__USE_ALL) */
 } __kernel_fsid_t;
 
-#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2)
+#if defined(__KERNEL__)
 
 #undef __FD_SET
 #define __FD_SET(fd,fdsetp) \
@@ -77,6 +73,6 @@ do { \
                        "2" ((__kernel_fd_set *) (fdsetp)) : "memory"); \
 } while (0)
 
-#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+#endif /* defined(__KERNEL__) */
 
 #endif
index ab4d0c2a3f8f286b792e2b2b724c6186849fb5e3..149920dcd341520c21964883302a95668111e6a0 100644 (file)
@@ -719,6 +719,8 @@ static inline void prefetchw(const void *x)
  * User space process size: 3GB (default).
  */
 #define TASK_SIZE      (PAGE_OFFSET)
+#define STACK_TOP      TASK_SIZE
+#define STACK_TOP_MAX  STACK_TOP
 
 #define INIT_THREAD  {                                                 \
        .sp0 = sizeof(init_stack) + (long)&init_stack,                  \
@@ -802,6 +804,9 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
 #define TASK_SIZE_OF(child)    ((test_tsk_thread_flag(child, TIF_IA32)) ? \
                                  IA32_PAGE_OFFSET : TASK_SIZE64)
 
+#define STACK_TOP              TASK_SIZE
+#define STACK_TOP_MAX          TASK_SIZE64
+
 #define INIT_THREAD  { \
        .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
 }
index 05a2f67c676853ecf8e09d33b257eedbd4ef47e0..fdf13702924ae6f2d23e1ba3af4f4c492cdd701b 100644 (file)
 #ifndef _XTENSA_A_OUT_H
 #define _XTENSA_A_OUT_H
 
-/* Note: the kernel needs the a.out definitions, even if only ELF is used. */
-
-#define STACK_TOP      TASK_SIZE
-#define STACK_TOP_MAX  STACK_TOP
-
 struct exec
 {
   unsigned long a_info;
index 1adedbf41d019acd775bd1c8b3b61f664d649979..80a6ae0dd25957e548d53b4c3e125f32df042ba9 100644 (file)
@@ -98,6 +98,7 @@
 typedef struct { unsigned long pte; } pte_t;           /* page table entry */
 typedef struct { unsigned long pgd; } pgd_t;           /* PGD table entry */
 typedef struct { unsigned long pgprot; } pgprot_t;
+typedef struct page *pgtable_t;
 
 #define pte_val(x)     ((x).pte)
 #define pgd_val(x)     ((x).pgd)
index ce3a336cad07c188ebe7dc10805c2d6c060212a8..82ad34d92d359746de497c9a680306a7a661f45f 100644 (file)
@@ -12,7 +12,7 @@
 #define _XTENSA_PARAM_H
 
 #ifdef __KERNEL__
-# define HZ            100             /* internal timer frequency */
+# define HZ            CONFIG_HZ       /* internal timer frequency */
 # define USER_HZ       100             /* for user interfaces in "ticks" */
 # define CLOCKS_PER_SEC (USER_HZ)      /* frequnzy at which times() counts */
 #endif
index 1d51ba5463f9f2f215015c598b5ef51bb7ff06f2..8d1544eb461ebfa13b3cd352786ba2af6fcf077e 100644 (file)
@@ -24,6 +24,7 @@
        (pmd_val(*(pmdp)) = ((unsigned long)ptep))
 #define pmd_populate(mm, pmdp, page)                                        \
        (pmd_val(*(pmdp)) = ((unsigned long)page_to_virt(page)))
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 static inline pgd_t*
 pgd_alloc(struct mm_struct *mm)
@@ -46,10 +47,14 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
        return kmem_cache_alloc(pgtable_cache, GFP_KERNEL|__GFP_REPEAT);
 }
 
-static inline struct page *pte_alloc_one(struct mm_struct *mm, 
-                                        unsigned long addr)
+static inline pte_token_t pte_alloc_one(struct mm_struct *mm,
+                                       unsigned long addr)
 {
-       return virt_to_page(pte_alloc_one_kernel(mm, addr));
+       struct page *page;
+
+       page = virt_to_page(pte_alloc_one_kernel(mm, addr));
+       pgtable_page_ctor(page);
+       return page;
 }
 
 static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
@@ -57,10 +62,12 @@ static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
        kmem_cache_free(pgtable_cache, pte);
 }
 
-static inline void pte_free(struct mm_struct *mm, struct page *page)
+static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
 {
-       kmem_cache_free(pgtable_cache, page_address(page));
+       pgtable_page_dtor(pte);
+       kmem_cache_free(pgtable_cache, page_address(pte));
 }
+#define pmd_pgtable(pmd) pmd_page(pmd)
 
 #endif /* __KERNEL__ */
 #endif /* _XTENSA_PGALLOC_H */
index 4ad77dda6d5f229422c93ac3562397f2539a8967..43f9dd1126a41be1bac284085906debf1ab34b3b 100644 (file)
@@ -64,8 +64,7 @@ typedef struct {
 
 #else /* __GNUC__ */
 
-#if defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) \
-    || (__GLIBC__ == 2 && __GLIBC_MINOR__ == 0)
+#if defined(__KERNEL__)
 /* With GNU C, use inline functions instead so args are evaluated only once: */
 
 #undef __FD_SET
@@ -118,6 +117,6 @@ static __inline__ void __FD_ZERO(__kernel_fd_set *p)
        }
 }
 
-#endif /* defined(__KERNEL__) || !defined(__GLIBC__) || (__GLIBC__ < 2) */
+#endif /* defined(__KERNEL__) */
 #endif /* __GNUC__ */
 #endif /* _XTENSA_POSIX_TYPES_H */
index 35145bcd96ebb034847768a5ff783e1c9d457432..96408f4366244a0010888c4e021bf5c09364eb4d 100644 (file)
@@ -34,6 +34,8 @@
  */
 
 #define TASK_SIZE      __XTENSA_UL_CONST(0x40000000)
+#define STACK_TOP      TASK_SIZE
+#define STACK_TOP_MAX  STACK_TOP
 
 /*
  * General exception cause assigned to debug exceptions. Debug exceptions go
index 2ebf068ba504f1afa9112716d141d95cac859baf..5cae9b5960eaa8dcde73feed6ea848a4958e56c0 100644 (file)
@@ -338,7 +338,6 @@ unifdef-y += tty.h
 unifdef-y += types.h
 unifdef-y += udf_fs_i.h
 unifdef-y += udp.h
-unifdef-y += ufs_fs.h
 unifdef-y += uinput.h
 unifdef-y += uio.h
 unifdef-y += unistd.h
index 82cd918f2ab708ca4545cf863e30f2db187777de..208f4e8ed304d30d90b7c3c94cd61c03b95421eb 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __A_OUT_GNU_H__
 #define __A_OUT_GNU_H__
 
+#ifdef CONFIG_ARCH_SUPPORTS_AOUT
+
 #define __GNU_EXEC_MACROS__
 
 #ifndef __STRUCT_EXEC_OVERRIDE__
@@ -9,6 +11,8 @@
 
 #endif /* __STRUCT_EXEC_OVERRIDE__ */
 
+#ifndef __ASSEMBLY__
+
 /* these go in the N_MACHTYPE field */
 enum machine_type {
 #if defined (M_OLDSUN2)
@@ -272,5 +276,11 @@ struct relocation_info
 };
 #endif /* no N_RELOCATION_INFO_DECLARED.  */
 
-
+#endif /*__ASSEMBLY__ */
+#else /* CONFIG_ARCH_SUPPORTS_AOUT */
+#ifndef __ASSEMBLY__
+struct exec {
+};
+#endif
+#endif /* CONFIG_ARCH_SUPPORTS_AOUT */
 #endif /* __A_OUT_GNU_H__ */
diff --git a/include/linux/atmel_pwm.h b/include/linux/atmel_pwm.h
new file mode 100644 (file)
index 0000000..ea04abb
--- /dev/null
@@ -0,0 +1,70 @@
+#ifndef __LINUX_ATMEL_PWM_H
+#define __LINUX_ATMEL_PWM_H
+
+/**
+ * struct pwm_channel - driver handle to a PWM channel
+ * @regs: base of this channel's registers
+ * @index: number of this channel (0..31)
+ * @mck: base clock rate, which can be prescaled and maybe subdivided
+ *
+ * Drivers initialize a pwm_channel structure using pwm_channel_alloc().
+ * Then they configure its clock rate (derived from MCK), alignment,
+ * polarity, and duty cycle by writing directly to the channel registers,
+ * before enabling the channel by calling pwm_channel_enable().
+ *
+ * After emitting a PWM signal for the desired length of time, drivers
+ * may then pwm_channel_disable() or pwm_channel_free().  Both of these
+ * disable the channel, but when it's freed the IRQ is deconfigured and
+ * the channel must later be re-allocated and reconfigured.
+ *
+ * Note that if the period or duty cycle need to be changed while the
+ * PWM channel is operating, drivers must use the PWM_CUPD double buffer
+ * mechanism, either polling until they change or getting implicitly
+ * notified through a once-per-period interrupt handler.
+ */
+struct pwm_channel {
+       void __iomem    *regs;
+       unsigned        index;
+       unsigned long   mck;
+};
+
+extern int pwm_channel_alloc(int index, struct pwm_channel *ch);
+extern int pwm_channel_free(struct pwm_channel *ch);
+
+extern int pwm_clk_alloc(unsigned prescale, unsigned div);
+extern void pwm_clk_free(unsigned clk);
+
+extern int __pwm_channel_onoff(struct pwm_channel *ch, int enabled);
+
+#define pwm_channel_enable(ch) __pwm_channel_onoff((ch), 1)
+#define pwm_channel_disable(ch)        __pwm_channel_onoff((ch), 0)
+
+/* periodic interrupts, mostly for CUPD changes to period or cycle */
+extern int pwm_channel_handler(struct pwm_channel *ch,
+               void (*handler)(struct pwm_channel *ch));
+
+/* per-channel registers (banked at pwm_channel->regs) */
+#define PWM_CMR                0x00            /* mode register */
+#define                PWM_CPR_CPD     (1 << 10)       /* set: CUPD modifies period */
+#define                PWM_CPR_CPOL    (1 << 9)        /* set: idle high */
+#define                PWM_CPR_CALG    (1 << 8)        /* set: center align */
+#define                PWM_CPR_CPRE    (0xf << 0)      /* mask: rate is mck/(2^pre) */
+#define                PWM_CPR_CLKA    (0xb << 0)      /* rate CLKA */
+#define                PWM_CPR_CLKB    (0xc << 0)      /* rate CLKB */
+#define PWM_CDTY       0x04            /* duty cycle (max of CPRD) */
+#define PWM_CPRD       0x08            /* period (count up from zero) */
+#define PWM_CCNT       0x0c            /* counter (20 bits?) */
+#define PWM_CUPD       0x10            /* update CPRD (or CDTY) next period */
+
+static inline void
+pwm_channel_writel(struct pwm_channel *pwmc, unsigned offset, u32 val)
+{
+       __raw_writel(val, pwmc->regs + offset);
+}
+
+static inline u32 pwm_channel_readl(struct pwm_channel *pwmc, unsigned offset)
+{
+       return __raw_readl(pwmc->regs + offset);
+}
+
+#endif /* __LINUX_ATMEL_PWM_H */
index 3dc715b025002d90935cac7e204e16a197060b63..d3771551fdd9046108596ccc185c431062cb8c01 100644 (file)
 #define htons(x) ___htons(x)
 #define ntohs(x) ___ntohs(x)
 
+static inline void le16_add_cpu(__le16 *var, u16 val)
+{
+       *var = cpu_to_le16(le16_to_cpu(*var) + val);
+}
+
+static inline void le32_add_cpu(__le32 *var, u32 val)
+{
+       *var = cpu_to_le32(le32_to_cpu(*var) + val);
+}
+
+static inline void le64_add_cpu(__le64 *var, u64 val)
+{
+       *var = cpu_to_le64(le64_to_cpu(*var) + val);
+}
+
+static inline void be16_add_cpu(__be16 *var, u16 val)
+{
+       *var = cpu_to_be16(be16_to_cpu(*var) + val);
+}
+
+static inline void be32_add_cpu(__be32 *var, u32 val)
+{
+       *var = cpu_to_be32(be32_to_cpu(*var) + val);
+}
+
+static inline void be64_add_cpu(__be64 *var, u64 val)
+{
+       *var = cpu_to_be64(be64_to_cpu(*var) + val);
+}
+
 #endif /* KERNEL */
 
 #endif /* _LINUX_BYTEORDER_GENERIC_H */
index ecae585ec3da97fce87fa5703e64d51519522d59..f8c9a2752f067b505a59b95d07a93a61a7845cd3 100644 (file)
@@ -57,7 +57,9 @@ extern int cpuset_memory_pressure_enabled;
 extern void __cpuset_memory_pressure_bump(void);
 
 extern const struct file_operations proc_cpuset_operations;
-extern char *cpuset_task_status_allowed(struct task_struct *task, char *buffer);
+struct seq_file;
+extern void cpuset_task_status_allowed(struct seq_file *m,
+                                       struct task_struct *task);
 
 extern void cpuset_lock(void);
 extern void cpuset_unlock(void);
@@ -126,10 +128,9 @@ static inline int cpuset_mems_allowed_intersects(const struct task_struct *tsk1,
 
 static inline void cpuset_memory_pressure_bump(void) {}
 
-static inline char *cpuset_task_status_allowed(struct task_struct *task,
-                                                       char *buffer)
+static inline void cpuset_task_status_allowed(struct seq_file *m,
+                                               struct task_struct *task)
 {
-       return buffer;
 }
 
 static inline void cpuset_lock(void) {}
index e765e191663dde89ecc150639d2d4eee1096ae88..cb784579956bb35a3f11abde8178ce6ba2da1e44 100644 (file)
@@ -110,15 +110,15 @@ struct target_type {
 };
 
 struct io_restrictions {
-       unsigned int            max_sectors;
-       unsigned short          max_phys_segments;
-       unsigned short          max_hw_segments;
-       unsigned short          hardsect_size;
-       unsigned int            max_segment_size;
-       unsigned int            max_hw_sectors;
-       unsigned long           seg_boundary_mask;
-       unsigned long           bounce_pfn;
-       unsigned char           no_cluster; /* inverted so that 0 is default */
+       unsigned long bounce_pfn;
+       unsigned long seg_boundary_mask;
+       unsigned max_hw_sectors;
+       unsigned max_sectors;
+       unsigned max_segment_size;
+       unsigned short hardsect_size;
+       unsigned short max_hw_segments;
+       unsigned short max_phys_segments;
+       unsigned char no_cluster; /* inverted so that 0 is default */
 };
 
 struct dm_target {
index 523281c5b7f55fa964534b4d38061b6c7b172d8a..b03c41bbfa140a8b1f83bbea29684e5eebed1e35 100644 (file)
@@ -232,36 +232,6 @@ enum {
        DM_DEV_SET_GEOMETRY_CMD
 };
 
-/*
- * The dm_ioctl struct passed into the ioctl is just the header
- * on a larger chunk of memory.  On x86-64 and other
- * architectures the dm-ioctl struct will be padded to an 8 byte
- * boundary so the size will be different, which would change the
- * ioctl code - yes I really messed up.  This hack forces these
- * architectures to have the correct ioctl code.
- */
-#ifdef CONFIG_COMPAT
-typedef char ioctl_struct[308];
-#define DM_VERSION_32       _IOWR(DM_IOCTL, DM_VERSION_CMD, ioctl_struct)
-#define DM_REMOVE_ALL_32    _IOWR(DM_IOCTL, DM_REMOVE_ALL_CMD, ioctl_struct)
-#define DM_LIST_DEVICES_32  _IOWR(DM_IOCTL, DM_LIST_DEVICES_CMD, ioctl_struct)
-
-#define DM_DEV_CREATE_32    _IOWR(DM_IOCTL, DM_DEV_CREATE_CMD, ioctl_struct)
-#define DM_DEV_REMOVE_32    _IOWR(DM_IOCTL, DM_DEV_REMOVE_CMD, ioctl_struct)
-#define DM_DEV_RENAME_32    _IOWR(DM_IOCTL, DM_DEV_RENAME_CMD, ioctl_struct)
-#define DM_DEV_SUSPEND_32   _IOWR(DM_IOCTL, DM_DEV_SUSPEND_CMD, ioctl_struct)
-#define DM_DEV_STATUS_32    _IOWR(DM_IOCTL, DM_DEV_STATUS_CMD, ioctl_struct)
-#define DM_DEV_WAIT_32      _IOWR(DM_IOCTL, DM_DEV_WAIT_CMD, ioctl_struct)
-
-#define DM_TABLE_LOAD_32    _IOWR(DM_IOCTL, DM_TABLE_LOAD_CMD, ioctl_struct)
-#define DM_TABLE_CLEAR_32   _IOWR(DM_IOCTL, DM_TABLE_CLEAR_CMD, ioctl_struct)
-#define DM_TABLE_DEPS_32    _IOWR(DM_IOCTL, DM_TABLE_DEPS_CMD, ioctl_struct)
-#define DM_TABLE_STATUS_32  _IOWR(DM_IOCTL, DM_TABLE_STATUS_CMD, ioctl_struct)
-#define DM_LIST_VERSIONS_32 _IOWR(DM_IOCTL, DM_LIST_VERSIONS_CMD, ioctl_struct)
-#define DM_TARGET_MSG_32    _IOWR(DM_IOCTL, DM_TARGET_MSG_CMD, ioctl_struct)
-#define DM_DEV_SET_GEOMETRY_32 _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, ioctl_struct)
-#endif
-
 #define DM_IOCTL 0xfd
 
 #define DM_VERSION       _IOWR(DM_IOCTL, DM_VERSION_CMD, struct dm_ioctl)
@@ -286,9 +256,9 @@ typedef char ioctl_struct[308];
 #define DM_DEV_SET_GEOMETRY    _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
 
 #define DM_VERSION_MAJOR       4
-#define DM_VERSION_MINOR       12
+#define DM_VERSION_MINOR       13
 #define DM_VERSION_PATCHLEVEL  0
-#define DM_VERSION_EXTRA       "-ioctl (2007-10-02)"
+#define DM_VERSION_EXTRA       "-ioctl (2007-10-18)"
 
 /* Status bits */
 #define DM_READONLY_FLAG       (1 << 0) /* In/Out */
index ffb6439cb5e610ca164a0e52ee1d3a3667a16677..56c73b8475519cc7ee5db5886c92aa6d8f5f2d15 100644 (file)
@@ -28,7 +28,7 @@
 #ifdef CONFIG_DMAR
 struct intel_iommu;
 
-extern char *dmar_get_fault_reason(u8 fault_reason);
+extern const char *dmar_get_fault_reason(u8 fault_reason);
 
 /* Can't use the common MSI interrupt functions
  * since DMAR is not a pci device
index b1251b2af568b6d2c7c3063b7d4f57a071c79c1e..325acdf5c4625c468f2f6108706ecb971efd856e 100644 (file)
@@ -35,8 +35,11 @@ enum dmi_device_type {
        DMI_DEV_TYPE_ETHERNET,
        DMI_DEV_TYPE_TOKENRING,
        DMI_DEV_TYPE_SOUND,
+       DMI_DEV_TYPE_PATA,
+       DMI_DEV_TYPE_SATA,
+       DMI_DEV_TYPE_SAS,
        DMI_DEV_TYPE_IPMI = -1,
-       DMI_DEV_TYPE_OEM_STRING = -2
+       DMI_DEV_TYPE_OEM_STRING = -2,
 };
 
 struct dmi_header {
@@ -79,6 +82,7 @@ extern void dmi_scan_machine(void);
 extern int dmi_get_year(int field);
 extern int dmi_name_in_vendors(const char *str);
 extern int dmi_available;
+extern int dmi_walk(void (*decode)(const struct dmi_header *));
 
 #else
 
@@ -89,6 +93,8 @@ static inline const struct dmi_device * dmi_find_device(int type, const char *na
 static inline int dmi_get_year(int year) { return 0; }
 static inline int dmi_name_in_vendors(const char *s) { return 0; }
 #define dmi_available 0
+static inline int dmi_walk(void (*decode)(const struct dmi_header *))
+       { return -1; }
 
 #endif
 
index 5834e843a946af4bf2a1e9597c73ec050b904baa..18bea78fe47b3e5ce97f98bac45fd6e1e6acd785 100644 (file)
@@ -31,6 +31,7 @@
 #define EM_V850                87      /* NEC v850 */
 #define EM_M32R                88      /* Renesas M32R */
 #define EM_H8_300      46      /* Renesas H8/300,300H,H8S */
+#define EM_MN10300     89      /* Panasonic/MEI MN10300, AM33 */
 #define EM_BLACKFIN     106     /* ADI Blackfin Processor */
 #define EM_FRV         0x5441  /* Fujitsu FR-V */
 #define EM_AVR32       0x18ad  /* Atmel AVR32 */
@@ -47,6 +48,8 @@
 #define EM_CYGNUS_M32R 0x9041
 /* This is the old interim value for S/390 architecture */
 #define EM_S390_OLD    0xA390
+/* Also Panasonic/MEI MN10300, AM33 */
+#define EM_CYGNUS_MN10300 0xbeef
 
 
 #endif /* _LINUX_ELF_EM_H */
diff --git a/include/linux/enclosure.h b/include/linux/enclosure.h
new file mode 100644 (file)
index 0000000..a5978f1
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Enclosure Services
+ *
+ * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com>
+ *
+**-----------------------------------------------------------------------------
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  version 2 as published by the Free Software Foundation.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+**
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+**-----------------------------------------------------------------------------
+*/
+#ifndef _LINUX_ENCLOSURE_H_
+#define _LINUX_ENCLOSURE_H_
+
+#include <linux/device.h>
+#include <linux/list.h>
+
+/* A few generic types ... taken from ses-2 */
+enum enclosure_component_type {
+       ENCLOSURE_COMPONENT_DEVICE = 0x01,
+       ENCLOSURE_COMPONENT_ARRAY_DEVICE = 0x17,
+};
+
+/* ses-2 common element status */
+enum enclosure_status {
+       ENCLOSURE_STATUS_UNSUPPORTED = 0,
+       ENCLOSURE_STATUS_OK,
+       ENCLOSURE_STATUS_CRITICAL,
+       ENCLOSURE_STATUS_NON_CRITICAL,
+       ENCLOSURE_STATUS_UNRECOVERABLE,
+       ENCLOSURE_STATUS_NOT_INSTALLED,
+       ENCLOSURE_STATUS_UNKNOWN,
+       ENCLOSURE_STATUS_UNAVAILABLE,
+};
+
+/* SFF-8485 activity light settings */
+enum enclosure_component_setting {
+       ENCLOSURE_SETTING_DISABLED = 0,
+       ENCLOSURE_SETTING_ENABLED = 1,
+       ENCLOSURE_SETTING_BLINK_A_ON_OFF = 2,
+       ENCLOSURE_SETTING_BLINK_A_OFF_ON = 3,
+       ENCLOSURE_SETTING_BLINK_B_ON_OFF = 6,
+       ENCLOSURE_SETTING_BLINK_B_OFF_ON = 7,
+};
+
+struct enclosure_device;
+struct enclosure_component;
+struct enclosure_component_callbacks {
+       void (*get_status)(struct enclosure_device *,
+                            struct enclosure_component *);
+       int (*set_status)(struct enclosure_device *,
+                         struct enclosure_component *,
+                         enum enclosure_status);
+       void (*get_fault)(struct enclosure_device *,
+                         struct enclosure_component *);
+       int (*set_fault)(struct enclosure_device *,
+                        struct enclosure_component *,
+                        enum enclosure_component_setting);
+       void (*get_active)(struct enclosure_device *,
+                          struct enclosure_component *);
+       int (*set_active)(struct enclosure_device *,
+                         struct enclosure_component *,
+                         enum enclosure_component_setting);
+       void (*get_locate)(struct enclosure_device *,
+                          struct enclosure_component *);
+       int (*set_locate)(struct enclosure_device *,
+                         struct enclosure_component *,
+                         enum enclosure_component_setting);
+};
+
+
+struct enclosure_component {
+       void *scratch;
+       struct class_device cdev;
+       enum enclosure_component_type type;
+       int number;
+       int fault;
+       int active;
+       int locate;
+       enum enclosure_status status;
+};
+
+struct enclosure_device {
+       void *scratch;
+       struct list_head node;
+       struct class_device cdev;
+       struct enclosure_component_callbacks *cb;
+       int components;
+       struct enclosure_component component[0];
+};
+
+static inline struct enclosure_device *
+to_enclosure_device(struct class_device *dev)
+{
+       return container_of(dev, struct enclosure_device, cdev);
+}
+
+static inline struct enclosure_component *
+to_enclosure_component(struct class_device *dev)
+{
+       return container_of(dev, struct enclosure_component, cdev);
+}
+
+struct enclosure_device *
+enclosure_register(struct device *, const char *, int,
+                  struct enclosure_component_callbacks *);
+void enclosure_unregister(struct enclosure_device *);
+struct enclosure_component *
+enclosure_component_register(struct enclosure_device *, unsigned int,
+                                enum enclosure_component_type, const char *);
+int enclosure_add_device(struct enclosure_device *enclosure, int component,
+                        struct device *dev);
+int enclosure_remove_device(struct enclosure_device *enclosure, int component);
+struct enclosure_device *enclosure_find(struct device *dev);
+int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
+                             void *data);
+
+#endif /* _LINUX_ENCLOSURE_H_ */
index 36b7abefacbe4b743ba128afcdcfee7b5c05a885..18cfbf76ec5be8f1f20ddb2fad22f7cd6101596c 100644 (file)
@@ -1038,6 +1038,12 @@ struct super_block {
         * in /proc/mounts will be "type.subtype"
         */
        char *s_subtype;
+
+       /*
+        * Saved mount options for lazy filesystems using
+        * generic_show_options()
+        */
+       char *s_options;
 };
 
 extern struct timespec current_fs_time(struct super_block *sb);
@@ -1618,7 +1624,6 @@ extern int register_chrdev(unsigned int, const char *,
                           const struct file_operations *);
 extern void unregister_chrdev(unsigned int, const char *);
 extern void unregister_chrdev_region(dev_t, unsigned);
-extern int chrdev_open(struct inode *, struct file *);
 extern void chrdev_show(struct seq_file *,off_t);
 
 /* fs/block_dev.c */
@@ -1807,9 +1812,6 @@ extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *,
                unsigned long, loff_t, loff_t *, size_t, ssize_t);
 extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos);
 extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos);
-extern void do_generic_mapping_read(struct address_space *mapping,
-                                   struct file_ra_state *, struct file *,
-                                   loff_t *, read_descriptor_t *, read_actor_t);
 extern int generic_segment_checks(const struct iovec *iov,
                unsigned long *nr_segs, size_t *count, int access_flags);
 
@@ -1847,18 +1849,6 @@ static inline int xip_truncate_page(struct address_space *mapping, loff_t from)
 }
 #endif
 
-static inline void do_generic_file_read(struct file * filp, loff_t *ppos,
-                                       read_descriptor_t * desc,
-                                       read_actor_t actor)
-{
-       do_generic_mapping_read(filp->f_mapping,
-                               &filp->f_ra,
-                               filp,
-                               ppos,
-                               desc,
-                               actor);
-}
-
 #ifdef CONFIG_BLOCK
 ssize_t __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
        struct block_device *bdev, const struct iovec *iov, loff_t offset,
@@ -1985,6 +1975,9 @@ extern int __must_check inode_setattr(struct inode *, struct iattr *);
 
 extern void file_update_time(struct file *file);
 
+extern int generic_show_options(struct seq_file *m, struct vfsmount *mnt);
+extern void save_mount_options(struct super_block *sb, char *options);
+
 static inline ino_t parent_ino(struct dentry *dentry)
 {
        ino_t res;
@@ -2056,7 +2049,7 @@ static int __fops ## _open(struct inode *inode, struct file *file)        \
 static struct file_operations __fops = {                               \
        .owner   = THIS_MODULE,                                         \
        .open    = __fops ## _open,                                     \
-       .release = simple_attr_close,                                   \
+       .release = simple_attr_release,                                 \
        .read    = simple_attr_read,                                    \
        .write   = simple_attr_write,                                   \
 };
@@ -2068,9 +2061,9 @@ __simple_attr_check_format(const char *fmt, ...)
 }
 
 int simple_attr_open(struct inode *inode, struct file *file,
-                    u64 (*get)(void *), void (*set)(void *, u64),
+                    int (*get)(void *, u64 *), int (*set)(void *, u64),
                     const char *fmt);
-int simple_attr_close(struct inode *inode, struct file *file);
+int simple_attr_release(struct inode *inode, struct file *file);
 ssize_t simple_attr_read(struct file *file, char __user *buf,
                         size_t len, loff_t *ppos);
 ssize_t simple_attr_write(struct file *file, const char __user *buf,
index 8371b664b41f44314dbc5a6a2fae4e2d0953414c..600fc3bcf63ec2509f3e758a448083914d2c5b01 100644 (file)
@@ -78,7 +78,7 @@ enum hrtimer_cb_mode {
  * as otherwise the timer could be removed before the softirq code finishes the
  * the handling of the timer.
  *
- * The HRTIMER_STATE_ENQUEUE bit is always or'ed to the current state to
+ * The HRTIMER_STATE_ENQUEUED bit is always or'ed to the current state to
  * preserve the HRTIMER_STATE_CALLBACK bit in the above scenario.
  *
  * All state transitions are protected by cpu_base->lock.
@@ -225,11 +225,14 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
  * idea of the (in)accuracy of timers. Timer values are rounded up to
  * this resolution values.
  */
-# define KTIME_HIGH_RES                (ktime_t) { .tv64 = 1 }
+# define HIGH_RES_NSEC         1
+# define KTIME_HIGH_RES                (ktime_t) { .tv64 = HIGH_RES_NSEC }
+# define MONOTONIC_RES_NSEC    HIGH_RES_NSEC
 # define KTIME_MONOTONIC_RES   KTIME_HIGH_RES
 
 #else
 
+# define MONOTONIC_RES_NSEC    LOW_RES_NSEC
 # define KTIME_MONOTONIC_RES   KTIME_LOW_RES
 
 /*
index 30d606afcafe98c9f22cce117082cc3cb2af83ed..7ca198b379afb59b1cc1d6a653926a03b35123cd 100644 (file)
@@ -17,6 +17,7 @@ static inline int is_vm_hugetlb_page(struct vm_area_struct *vma)
 }
 
 int hugetlb_sysctl_handler(struct ctl_table *, int, struct file *, void __user *, size_t *, loff_t *);
+int hugetlb_overcommit_handler(struct ctl_table *, int, struct file *, void __user *, size_t *, loff_t *);
 int hugetlb_treat_movable_handler(struct ctl_table *, int, struct file *, void __user *, size_t *, loff_t *);
 int copy_hugetlb_page_range(struct mm_struct *, struct mm_struct *, struct vm_area_struct *);
 int follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *, struct page **, struct vm_area_struct **, unsigned long *, int *, int, int);
index f922b060158ba22ec0ce37838509e0939bb65910..b979112f74e0d3aca3242d5ca8f8fda9c96067ac 100644 (file)
 
 #define I2C_DRIVERID_I2CDEV    900
 
-/* IDs --   Use DRIVERIDs 1000-1999 for sensors.
-   These were originally in sensors.h in the lm_sensors package */
-#define I2C_DRIVERID_LM78 1002
-#define I2C_DRIVERID_LM75 1003
-#define I2C_DRIVERID_GL518 1004
-#define I2C_DRIVERID_EEPROM 1005
-#define I2C_DRIVERID_W83781D 1006
-#define I2C_DRIVERID_LM80 1007
-#define I2C_DRIVERID_ADM1021 1008
-#define I2C_DRIVERID_ADM9240 1009
-#define I2C_DRIVERID_LTC1710 1010
-#define I2C_DRIVERID_BT869 1013
-#define I2C_DRIVERID_MAXILIFE 1014
-#define I2C_DRIVERID_MATORB 1015
-#define I2C_DRIVERID_GL520 1016
-#define I2C_DRIVERID_THMC50 1017
-#define I2C_DRIVERID_ADM1025 1020
-#define I2C_DRIVERID_LM87 1021
-#define I2C_DRIVERID_PCF8574 1022
-#define I2C_DRIVERID_MTP008 1023
-#define I2C_DRIVERID_DS1621 1024
-#define I2C_DRIVERID_ADM1024 1025
-#define I2C_DRIVERID_CH700X 1027 /* single driver for CH7003-7009 digital pc to tv encoders */
-#define I2C_DRIVERID_FSCPOS 1028
-#define I2C_DRIVERID_FSCSCY 1029
-#define I2C_DRIVERID_PCF8591 1030
-#define I2C_DRIVERID_LM92 1033
-#define I2C_DRIVERID_SMARTBATT 1035
-#define I2C_DRIVERID_BMCSENSORS 1036
-#define I2C_DRIVERID_FS451 1037
-#define I2C_DRIVERID_LM85 1039
-#define I2C_DRIVERID_LM83 1040
-#define I2C_DRIVERID_LM90 1042
-#define I2C_DRIVERID_ASB100 1043
-#define I2C_DRIVERID_FSCHER 1046
-#define I2C_DRIVERID_W83L785TS 1047
 #define I2C_DRIVERID_OV7670 1048       /* Omnivision 7670 camera */
 
 /*
index 408696ea51892f0deaf7a866f7e5ec99619c5770..b8826107b5180e78b163e3b92f605bf7dcd22faf 100644 (file)
@@ -100,58 +100,6 @@ struct kern_ipc_perm
        void            *security;
 };
 
-struct ipc_ids;
-struct ipc_namespace {
-       struct kref     kref;
-       struct ipc_ids  *ids[3];
-
-       int             sem_ctls[4];
-       int             used_sems;
-
-       int             msg_ctlmax;
-       int             msg_ctlmnb;
-       int             msg_ctlmni;
-       atomic_t        msg_bytes;
-       atomic_t        msg_hdrs;
-
-       size_t          shm_ctlmax;
-       size_t          shm_ctlall;
-       int             shm_ctlmni;
-       int             shm_tot;
-};
-
-extern struct ipc_namespace init_ipc_ns;
-
-#ifdef CONFIG_SYSVIPC
-#define INIT_IPC_NS(ns)                .ns             = &init_ipc_ns,
-extern void free_ipc_ns(struct kref *kref);
-extern struct ipc_namespace *copy_ipcs(unsigned long flags,
-                                               struct ipc_namespace *ns);
-#else
-#define INIT_IPC_NS(ns)
-static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
-                                               struct ipc_namespace *ns)
-{
-       return ns;
-}
-#endif
-
-static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
-{
-#ifdef CONFIG_SYSVIPC
-       if (ns)
-               kref_get(&ns->kref);
-#endif
-       return ns;
-}
-
-static inline void put_ipc_ns(struct ipc_namespace *ns)
-{
-#ifdef CONFIG_SYSVIPC
-       kref_put(&ns->kref, free_ipc_ns);
-#endif
-}
-
 #endif /* __KERNEL__ */
 
 #endif /* _LINUX_IPC_H */
diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
new file mode 100644 (file)
index 0000000..e4451d1
--- /dev/null
@@ -0,0 +1,81 @@
+#ifndef __IPC_NAMESPACE_H__
+#define __IPC_NAMESPACE_H__
+
+#include <linux/err.h>
+#include <linux/idr.h>
+#include <linux/rwsem.h>
+
+struct ipc_ids {
+       int in_use;
+       unsigned short seq;
+       unsigned short seq_max;
+       struct rw_semaphore rw_mutex;
+       struct idr ipcs_idr;
+};
+
+struct ipc_namespace {
+       struct kref     kref;
+       struct ipc_ids  ids[3];
+
+       int             sem_ctls[4];
+       int             used_sems;
+
+       int             msg_ctlmax;
+       int             msg_ctlmnb;
+       int             msg_ctlmni;
+       atomic_t        msg_bytes;
+       atomic_t        msg_hdrs;
+
+       size_t          shm_ctlmax;
+       size_t          shm_ctlall;
+       int             shm_ctlmni;
+       int             shm_tot;
+};
+
+extern struct ipc_namespace init_ipc_ns;
+
+#ifdef CONFIG_SYSVIPC
+#define INIT_IPC_NS(ns)                .ns             = &init_ipc_ns,
+#else
+#define INIT_IPC_NS(ns)
+#endif
+
+#if defined(CONFIG_SYSVIPC) && defined(CONFIG_IPC_NS)
+extern void free_ipc_ns(struct kref *kref);
+extern struct ipc_namespace *copy_ipcs(unsigned long flags,
+                                      struct ipc_namespace *ns);
+extern void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
+                     void (*free)(struct ipc_namespace *,
+                                  struct kern_ipc_perm *));
+
+static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
+{
+       if (ns)
+               kref_get(&ns->kref);
+       return ns;
+}
+
+static inline void put_ipc_ns(struct ipc_namespace *ns)
+{
+       kref_put(&ns->kref, free_ipc_ns);
+}
+#else
+static inline struct ipc_namespace *copy_ipcs(unsigned long flags,
+               struct ipc_namespace *ns)
+{
+       if (flags & CLONE_NEWIPC)
+               return ERR_PTR(-EINVAL);
+
+       return ns;
+}
+
+static inline struct ipc_namespace *get_ipc_ns(struct ipc_namespace *ns)
+{
+       return ns;
+}
+
+static inline void put_ipc_ns(struct ipc_namespace *ns)
+{
+}
+#endif
+#endif
index 4669be08061799641263078c61297293f3643eb7..bfd9efb5cb49874b88e117711f505b4d012e8804 100644 (file)
@@ -25,7 +25,7 @@
 #include <asm/irq_regs.h>
 
 struct irq_desc;
-typedef        void fastcall (*irq_flow_handler_t)(unsigned int irq,
+typedef        void (*irq_flow_handler_t)(unsigned int irq,
                                            struct irq_desc *desc);
 
 
@@ -276,19 +276,19 @@ extern int handle_IRQ_event(unsigned int irq, struct irqaction *action);
  * Built-in IRQ handlers for various IRQ types,
  * callable via desc->chip->handle_irq()
  */
-extern void fastcall handle_level_irq(unsigned int irq, struct irq_desc *desc);
-extern void fastcall handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc);
-extern void fastcall handle_edge_irq(unsigned int irq, struct irq_desc *desc);
-extern void fastcall handle_simple_irq(unsigned int irq, struct irq_desc *desc);
-extern void fastcall handle_percpu_irq(unsigned int irq, struct irq_desc *desc);
-extern void fastcall handle_bad_irq(unsigned int irq, struct irq_desc *desc);
+extern void handle_level_irq(unsigned int irq, struct irq_desc *desc);
+extern void handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc);
+extern void handle_edge_irq(unsigned int irq, struct irq_desc *desc);
+extern void handle_simple_irq(unsigned int irq, struct irq_desc *desc);
+extern void handle_percpu_irq(unsigned int irq, struct irq_desc *desc);
+extern void handle_bad_irq(unsigned int irq, struct irq_desc *desc);
 
 /*
  * Monolithic do_IRQ implementation.
  * (is an explicit fastcall, because i386 4KSTACKS calls it from assembly)
  */
 #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
-extern fastcall unsigned int __do_IRQ(unsigned int irq);
+extern unsigned int __do_IRQ(unsigned int irq);
 #endif
 
 /*
@@ -367,6 +367,9 @@ set_irq_chained_handler(unsigned int irq,
        __set_irq_handler(irq, handle, 1, NULL);
 }
 
+extern void set_irq_noprobe(unsigned int irq);
+extern void set_irq_probe(unsigned int irq);
+
 /* Handle dynamic irq creation and destruction */
 extern int create_irq(void);
 extern void destroy_irq(unsigned int irq);
index 7ba9e47bf061588b03556a4aaa767a087cc45c16..e0b5b684d83f2969816f051acb2e1158da2fe06d 100644 (file)
@@ -42,7 +42,7 @@
 /* LATCH is used in the interval timer and ftape setup. */
 #define LATCH  ((CLOCK_TICK_RATE + HZ/2) / HZ) /* For divider */
 
-/* Suppose we want to devide two numbers NOM and DEN: NOM/DEN, the we can
+/* Suppose we want to devide two numbers NOM and DEN: NOM/DEN, then we can
  * improve accuracy by shifting LSH bits, hence calculating:
  *     (NOM << LSH) / DEN
  * This however means trouble for large NOM, because (NOM << LSH) may no
@@ -160,7 +160,7 @@ extern unsigned long preset_lpj;
  * We want to do realistic conversions of time so we need to use the same
  * values the update wall clock code uses as the jiffies size.  This value
  * is: TICK_NSEC (which is defined in timex.h).  This
- * is a constant and is in nanoseconds.  We will used scaled math
+ * is a constant and is in nanoseconds.  We will use scaled math
  * with a set of scales defined here as SEC_JIFFIE_SC,  USEC_JIFFIE_SC and
  * NSEC_JIFFIE_SC.  Note that these defines contain nothing but
  * constants and so are computed at compile time.  SHIFT_HZ (computed in
@@ -204,7 +204,7 @@ extern unsigned long preset_lpj;
  * operator if the result is a long long AND at least one of the
  * operands is cast to long long (usually just prior to the "*" so as
  * not to confuse it into thinking it really has a 64-bit operand,
- * which, buy the way, it can do, but it take more code and at least 2
+ * which, buy the way, it can do, but it takes more code and at least 2
  * mpys).
 
  * We also need to be aware that one second in nanoseconds is only a
index 9e01f376840a8c154327badfdd3a94f1f3643713..2df44e77327002938f08d345f34e5e773cc37363 100644 (file)
@@ -133,7 +133,7 @@ NORET_TYPE void panic(const char * fmt, ...)
 extern void oops_enter(void);
 extern void oops_exit(void);
 extern int oops_may_print(void);
-fastcall NORET_TYPE void do_exit(long error_code)
+NORET_TYPE void do_exit(long error_code)
        ATTRIB_NORET;
 NORET_TYPE void complete_and_exit(struct completion *, long)
        ATTRIB_NORET;
@@ -141,6 +141,10 @@ extern unsigned long simple_strtoul(const char *,char **,unsigned int);
 extern long simple_strtol(const char *,char **,unsigned int);
 extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
 extern long long simple_strtoll(const char *,char **,unsigned int);
+extern int strict_strtoul(const char *, unsigned int, unsigned long *);
+extern int strict_strtol(const char *, unsigned int, long *);
+extern int strict_strtoull(const char *, unsigned int, unsigned long long *);
+extern int strict_strtoll(const char *, unsigned int, long long *);
 extern int sprintf(char * buf, const char * fmt, ...)
        __attribute__ ((format (printf, 2, 3)));
 extern int vsprintf(char *buf, const char *, va_list)
@@ -172,8 +176,6 @@ extern int kernel_text_address(unsigned long addr);
 struct pid;
 extern struct pid *session_of_pgrp(struct pid *pgrp);
 
-extern void dump_thread(struct pt_regs *regs, struct user *dump);
-
 #ifdef CONFIG_PRINTK
 asmlinkage int vprintk(const char *fmt, va_list args)
        __attribute__ ((format (printf, 1, 0)));
@@ -182,6 +184,13 @@ asmlinkage int printk(const char * fmt, ...)
 extern int log_buf_get_len(void);
 extern int log_buf_read(int idx);
 extern int log_buf_copy(char *dest, int idx, int len);
+
+extern int printk_ratelimit_jiffies;
+extern int printk_ratelimit_burst;
+extern int printk_ratelimit(void);
+extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
+extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
+                                  unsigned int interval_msec);
 #else
 static inline int vprintk(const char *s, va_list args)
        __attribute__ ((format (printf, 1, 0)));
@@ -192,6 +201,12 @@ static inline int __cold printk(const char *s, ...) { return 0; }
 static inline int log_buf_get_len(void) { return 0; }
 static inline int log_buf_read(int idx) { return 0; }
 static inline int log_buf_copy(char *dest, int idx, int len) { return 0; }
+static inline int printk_ratelimit(void) { return 0; }
+static inline int __printk_ratelimit(int ratelimit_jiffies, \
+                                    int ratelimit_burst) { return 0; }
+static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies, \
+                                         unsigned int interval_msec)   \
+               { return false; }
 #endif
 
 extern void __attribute__((format(printf, 1, 2)))
@@ -199,11 +214,6 @@ extern void __attribute__((format(printf, 1, 2)))
 
 unsigned long int_sqrt(unsigned long);
 
-extern int printk_ratelimit(void);
-extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
-extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
-                               unsigned int interval_msec);
-
 static inline void console_silent(void)
 {
        console_loglevel = 0;
@@ -224,6 +234,7 @@ extern int panic_on_unrecovered_nmi;
 extern int tainted;
 extern const char *print_tainted(void);
 extern void add_taint(unsigned);
+extern int root_mountflags;
 
 /* Values used for system_state */
 extern enum system_states {
index a6ddec141f96c83752ddb060079d0efa4e517aa4..36c542b70c6d88152b001ca22d9b61d3af897fce 100644 (file)
@@ -316,7 +316,8 @@ static inline ktime_t ktime_sub_us(const ktime_t kt, const u64 usec)
  * idea of the (in)accuracy of timers. Timer values are rounded up to
  * this resolution values.
  */
-#define KTIME_LOW_RES          (ktime_t){ .tv64 = TICK_NSEC }
+#define LOW_RES_NSEC           TICK_NSEC
+#define KTIME_LOW_RES          (ktime_t){ .tv64 = LOW_RES_NSEC }
 
 /* Get the monotonic time in timespec format: */
 extern void ktime_get_ts(struct timespec *ts);
index 89d7c691b93a6a660ee5468ac333a805b049a6f7..e8abb3814209f556a06750af5ba3941ed0796eda 100644 (file)
@@ -894,6 +894,18 @@ static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long a
 #define pte_lockptr(mm, pmd)   ({(void)(pmd); &(mm)->page_table_lock;})
 #endif /* NR_CPUS < CONFIG_SPLIT_PTLOCK_CPUS */
 
+static inline void pgtable_page_ctor(struct page *page)
+{
+       pte_lock_init(page);
+       inc_zone_page_state(page, NR_PAGETABLE);
+}
+
+static inline void pgtable_page_dtor(struct page *page)
+{
+       pte_lock_deinit(page);
+       dec_zone_page_state(page, NR_PAGETABLE);
+}
+
 #define pte_offset_map_lock(mm, pmd, address, ptlp)    \
 ({                                                     \
        spinlock_t *__ptl = pte_lockptr(mm, pmd);       \
@@ -1136,7 +1148,7 @@ struct page *follow_page(struct vm_area_struct *, unsigned long address,
 #define FOLL_GET       0x04    /* do get_page on page */
 #define FOLL_ANON      0x08    /* give ZERO_PAGE if no pgtable */
 
-typedef int (*pte_fn_t)(pte_t *pte, struct page *pmd_page, unsigned long addr,
+typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr,
                        void *data);
 extern int apply_to_page_range(struct mm_struct *mm, unsigned long address,
                               unsigned long size, pte_fn_t fn, void *data);
index 34023c65d4669bc4c4894d392e9d915db3710034..bfee0bd1d43545742504225e0ab0754a315e7aa9 100644 (file)
@@ -64,7 +64,10 @@ struct page {
 #if NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS
            spinlock_t ptl;
 #endif
-           struct kmem_cache *slab;    /* SLUB: Pointer to slab */
+           struct {
+                  struct kmem_cache *slab;     /* SLUB: Pointer to slab */
+                  void *end;                   /* SLUB: end marker */
+           };
            struct page *first_page;    /* Compound tail pages */
        };
        union {
index ac481e2094fd01b79e12279a0b631092b7b6f8e4..ac28e8761e8436b1af7cb0b1f7d92ec37ffe6f1f 100644 (file)
@@ -449,7 +449,7 @@ static inline void __module_get(struct module *module)
 /* For kallsyms to ask for address resolution.  namebuf should be at
  * least KSYM_NAME_LEN long: a pointer to namebuf is returned if
  * found, otherwise NULL. */
-char *module_address_lookup(unsigned long addr,
+const char *module_address_lookup(unsigned long addr,
                            unsigned long *symbolsize,
                            unsigned long *offset,
                            char **modname,
@@ -519,7 +519,7 @@ static inline void module_put(struct module *module)
 #define module_name(mod) "kernel"
 
 /* For kallsyms to ask for address resolution.  NULL means not found. */
-static inline char *module_address_lookup(unsigned long addr,
+static inline const char *module_address_lookup(unsigned long addr,
                                          unsigned long *symbolsize,
                                          unsigned long *offset,
                                          char **modname,
index 05c590352dd7f59259c555d1e6e85c20396f0f43..bc6da10ceee002ef14850e8025839e67d0d87c48 100644 (file)
@@ -112,7 +112,7 @@ extern void __mutex_init(struct mutex *lock, const char *name,
  *
  * Returns 1 if the mutex is locked, 0 if unlocked.
  */
-static inline int fastcall mutex_is_locked(struct mutex *lock)
+static inline int mutex_is_locked(struct mutex *lock)
 {
        return atomic_read(&lock->count) != 1;
 }
@@ -132,9 +132,9 @@ extern int __must_check mutex_lock_killable_nested(struct mutex *lock,
 #define mutex_lock_interruptible(lock) mutex_lock_interruptible_nested(lock, 0)
 #define mutex_lock_killable(lock) mutex_lock_killable_nested(lock, 0)
 #else
-extern void fastcall mutex_lock(struct mutex *lock);
-extern int __must_check fastcall mutex_lock_interruptible(struct mutex *lock);
-extern int __must_check fastcall mutex_lock_killable(struct mutex *lock);
+extern void mutex_lock(struct mutex *lock);
+extern int __must_check mutex_lock_interruptible(struct mutex *lock);
+extern int __must_check mutex_lock_killable(struct mutex *lock);
 
 # define mutex_lock_nested(lock, subclass) mutex_lock(lock)
 # define mutex_lock_interruptible_nested(lock, subclass) mutex_lock_interruptible(lock)
@@ -145,7 +145,7 @@ extern int __must_check fastcall mutex_lock_killable(struct mutex *lock);
  * NOTE: mutex_trylock() follows the spin_trylock() convention,
  *       not the down_trylock() convention!
  */
-extern int fastcall mutex_trylock(struct mutex *lock);
-extern void fastcall mutex_unlock(struct mutex *lock);
+extern int mutex_trylock(struct mutex *lock);
+extern void mutex_unlock(struct mutex *lock);
 
 #endif
index cc2b47240a8f2b53cb68ea9af0593bcbdd1e8897..986572081e19053b84061d7ecfc20702fbce2b59 100644 (file)
@@ -35,7 +35,6 @@ enum {
 };
 
 #define nbd_cmd(req) ((req)->cmd[0])
-#define MAX_NBD 128
 
 /* userspace doesn't need the nbd_device structure */
 #ifdef __KERNEL__
index 6db69ff5d83eb9f2b6bf137556246ea48cdba03a..700725ddcaae3edf050fb6093e516d5abd7c67c3 100644 (file)
@@ -298,6 +298,7 @@ struct sadb_x_sec_ctx {
 #define SADB_X_EALG_BLOWFISHCBC                7
 #define SADB_EALG_NULL                 11
 #define SADB_X_EALG_AESCBC             12
+#define SADB_X_EALG_AESCTR             13
 #define SADB_X_EALG_AES_CCM_ICV8       14
 #define SADB_X_EALG_AES_CCM_ICV12      15
 #define SADB_X_EALG_AES_CCM_ICV16      16
index e29a900a84992f308ced20ed5ce4e9a4f2685f09..f84d532b5d23e543bf21481b1c4521ccc8c5f660 100644 (file)
@@ -118,18 +118,17 @@ extern struct pid *find_pid(int nr);
  */
 extern struct pid *find_get_pid(int nr);
 extern struct pid *find_ge_pid(int nr, struct pid_namespace *);
+int next_pidmap(struct pid_namespace *pid_ns, int last);
 
 extern struct pid *alloc_pid(struct pid_namespace *ns);
 extern void FASTCALL(free_pid(struct pid *pid));
-extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
 
 /*
  * the helpers to get the pid's id seen from different namespaces
  *
  * pid_nr()    : global id, i.e. the id seen from the init namespace;
- * pid_vnr()   : virtual id, i.e. the id seen from the namespace this pid
- *               belongs to. this only makes sence when called in the
- *               context of the task that belongs to the same namespace;
+ * pid_vnr()   : virtual id, i.e. the id seen from the pid namespace of
+ *               current.
  * pid_nr_ns() : id seen from the ns specified.
  *
  * see also task_xid_nr() etc in include/linux/sched.h
@@ -144,14 +143,7 @@ static inline pid_t pid_nr(struct pid *pid)
 }
 
 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
-
-static inline pid_t pid_vnr(struct pid *pid)
-{
-       pid_t nr = 0;
-       if (pid)
-               nr = pid->numbers[pid->level].nr;
-       return nr;
-}
+pid_t pid_vnr(struct pid *pid);
 
 #define do_each_pid_task(pid, type, task)                              \
        do {                                                            \
@@ -160,7 +152,13 @@ static inline pid_t pid_vnr(struct pid *pid)
                        hlist_for_each_entry_rcu((task), pos___,        \
                                &pid->tasks[type], pids[type].node) {
 
+                       /*
+                        * Both old and new leaders may be attached to
+                        * the same pid in the middle of de_thread().
+                        */
 #define while_each_pid_task(pid, type, task)                           \
+                               if (type == PIDTYPE_PID)                \
+                                       break;                          \
                        }                                               \
        } while (0)
 
index 1689e28483e49d2c2f043a55531280e783fb48d5..fcd61fa2c833e415ab823e03532bd4880b16be79 100644 (file)
@@ -39,6 +39,7 @@ static inline struct pid_namespace *get_pid_ns(struct pid_namespace *ns)
 
 extern struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *ns);
 extern void free_pid_ns(struct kref *kref);
+extern void zap_pid_ns_processes(struct pid_namespace *pid_ns);
 
 static inline void put_pid_ns(struct pid_namespace *ns)
 {
@@ -66,6 +67,11 @@ static inline void put_pid_ns(struct pid_namespace *ns)
 {
 }
 
+
+static inline void zap_pid_ns_processes(struct pid_namespace *ns)
+{
+       BUG();
+}
 #endif /* CONFIG_PID_NS */
 
 static inline struct pid_namespace *task_active_pid_ns(struct task_struct *tsk)
index 484988ed301e3fc03741950dc67949148bdb16d8..23f0c54175cdde74280bf89782a4c0743a0ef58e 100644 (file)
@@ -11,8 +11,8 @@
 #include <linux/list.h>
 
 #ifdef CONFIG_DEBUG_PREEMPT
-  extern void fastcall add_preempt_count(int val);
-  extern void fastcall sub_preempt_count(int val);
+  extern void add_preempt_count(int val);
+  extern void sub_preempt_count(int val);
 #else
 # define add_preempt_count(val)        do { preempt_count() += (val); } while (0)
 # define sub_preempt_count(val)        do { preempt_count() -= (val); } while (0)
index e43551516831c53d2fd2ba021de863a54b02e709..d6a4f69bdc92464b8416327ecead0fd30e39eaa5 100644 (file)
@@ -118,13 +118,17 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
 int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir);
 unsigned long task_vsize(struct mm_struct *);
 int task_statm(struct mm_struct *, int *, int *, int *, int *);
-char *task_mem(struct mm_struct *, char *);
+void task_mem(struct seq_file *, struct mm_struct *);
+void clear_refs_smap(struct mm_struct *mm);
 
 struct proc_dir_entry *de_get(struct proc_dir_entry *de);
 void de_put(struct proc_dir_entry *de);
 
 extern struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
                                                struct proc_dir_entry *parent);
+struct proc_dir_entry *proc_create(const char *name, mode_t mode,
+                               struct proc_dir_entry *parent,
+                               const struct file_operations *proc_fops);
 extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
 
 extern struct vfsmount *proc_mnt;
@@ -219,7 +223,12 @@ static inline void proc_flush_task(struct task_struct *task)
 
 static inline struct proc_dir_entry *create_proc_entry(const char *name,
        mode_t mode, struct proc_dir_entry *parent) { return NULL; }
-
+static inline struct proc_dir_entry *proc_create(const char *name,
+       mode_t mode, struct proc_dir_entry *parent,
+       const struct file_operations *proc_fops)
+{
+       return NULL;
+}
 #define remove_proc_entry(name, parent) do {} while (0)
 
 static inline struct proc_dir_entry *proc_symlink(const char *name,
@@ -262,6 +271,9 @@ extern void kclist_add(struct kcore_list *, void *, size_t);
 union proc_op {
        int (*proc_get_link)(struct inode *, struct dentry **, struct vfsmount **);
        int (*proc_read)(struct task_struct *task, char *page);
+       int (*proc_show)(struct seq_file *m,
+               struct pid_namespace *ns, struct pid *pid,
+               struct task_struct *task);
 };
 
 struct proc_inode {
index 6ab80714a9169c67ae116b5e4b0ae9aaceb4620e..ebe0c17039cf0f8dec6d6207da29052463a610d3 100644 (file)
@@ -67,7 +67,6 @@
 #define PT_TRACE_EXEC  0x00000080
 #define PT_TRACE_VFORK_DONE    0x00000100
 #define PT_TRACE_EXIT  0x00000200
-#define PT_ATTACHED    0x00000400      /* parent != real_parent */
 
 #define PT_TRACE_MASK  0x000003f4
 
index ece8eb3e4151411be2df54326405d03f880ab38d..60c2a033b19e0fa7333b29d591a5f00d497a838a 100644 (file)
@@ -46,8 +46,8 @@
 #define rcu_bh_qsctr_inc(cpu)
 #define call_rcu_bh(head, rcu) call_rcu(head, rcu)
 
-extern void __rcu_read_lock(void);
-extern void __rcu_read_unlock(void);
+extern void __rcu_read_lock(void)      __acquires(RCU);
+extern void __rcu_read_unlock(void)    __releases(RCU);
 extern int rcu_pending(int cpu);
 extern int rcu_needs_cpu(int cpu);
 
index 422eab4958a6996b3f9a57a6ee6fa44217fcddc9..8e7eff2cd0ab44d78d0ddc021ad3275459f34f9d 100644 (file)
@@ -287,7 +287,7 @@ static inline struct reiserfs_sb_info *REISERFS_SB(const struct super_block *sb)
 
 /* Don't trust REISERFS_SB(sb)->s_bmap_nr, it's a u16
  * which overflows on large file systems. */
-static inline u32 reiserfs_bmap_count(struct super_block *sb)
+static inline __u32 reiserfs_bmap_count(struct super_block *sb)
 {
        return (SB_BLOCK_COUNT(sb) - 1) / (sb->s_blocksize * 8) + 1;
 }
index 8a4812c1c038db0f1e5654531784ac5c801a25d2..00e14411732627f2cd46bcbcb947335cc0b94b61 100644 (file)
@@ -460,7 +460,7 @@ struct signal_struct {
 
        /* ITIMER_REAL timer for the process */
        struct hrtimer real_timer;
-       struct task_struct *tsk;
+       struct pid *leader_pid;
        ktime_t it_real_incr;
 
        /* ITIMER_PROF and ITIMER_VIRTUAL timers for the process */
@@ -1332,9 +1332,8 @@ struct pid_namespace;
  * from various namespaces
  *
  * task_xid_nr()     : global id, i.e. the id seen from the init namespace;
- * task_xid_vnr()    : virtual id, i.e. the id seen from the namespace the task
- *                     belongs to. this only makes sence when called in the
- *                     context of the task that belongs to the same namespace;
+ * task_xid_vnr()    : virtual id, i.e. the id seen from the pid namespace of
+ *                     current.
  * task_xid_nr_ns()  : id seen from the ns specified;
  *
  * set_task_vxid()   : assigns a virtual id to a task;
@@ -1632,7 +1631,7 @@ extern struct task_struct *find_task_by_vpid(pid_t nr);
 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
                struct pid_namespace *ns);
 
-extern void __set_special_pids(pid_t session, pid_t pgrp);
+extern void __set_special_pids(struct pid *pid);
 
 /* per-UID process charging. */
 extern struct user_struct * alloc_uid(struct user_namespace *, uid_t);
@@ -1687,11 +1686,9 @@ extern void block_all_signals(int (*notifier)(void *priv), void *priv,
 extern void unblock_all_signals(void);
 extern void release_task(struct task_struct * p);
 extern int send_sig_info(int, struct siginfo *, struct task_struct *);
-extern int send_group_sig_info(int, struct siginfo *, struct task_struct *);
 extern int force_sigsegv(int, struct task_struct *);
 extern int force_sig_info(int, struct siginfo *, struct task_struct *);
 extern int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
-extern int kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp);
 extern int kill_pid_info(int sig, struct siginfo *info, struct pid *pid);
 extern int kill_pid_info_as_uid(int, struct siginfo *, struct pid *, uid_t, uid_t, u32);
 extern int kill_pgrp(struct pid *pid, int sig, int priv);
index 9963f81fea9a080e63b4093023ff7ad98f23a5ac..1a0b6cf83ff1b7954af90c1d0df0dda6a7de621b 100644 (file)
 #define PORT_MCF       78
 
 
+/* MN10300 on-chip UART numbers */
+#define PORT_MN10300           80
+#define PORT_MN10300_CTS       81
+
 #ifdef __KERNEL__
 
 #include <linux/compiler.h>
index f3c51899117f5e83abb3a44c5b94ff11574df382..8d5fb36ea04741488c7233c6f9171075117f9a65 100644 (file)
@@ -30,9 +30,12 @@ struct shmem_sb_info {
        unsigned long free_blocks;  /* How many are left for allocation */
        unsigned long max_inodes;   /* How many inodes are allowed */
        unsigned long free_inodes;  /* How many are left for allocation */
+       spinlock_t stat_lock;       /* Serialize shmem_sb_info changes */
+       uid_t uid;                  /* Mount uid for root directory */
+       gid_t gid;                  /* Mount gid for root directory */
+       mode_t mode;                /* Mount mode for root directory */
        int policy;                 /* Default NUMA memory alloc policy */
        nodemask_t policy_nodes;    /* nodemask for preferred and bind */
-       spinlock_t    stat_lock;
 };
 
 static inline struct shmem_inode_info *SHMEM_I(struct inode *inode)
index 7e095147656cfac8320faab052f5574e79cd6f13..42d2e0a948f4866533c7211c031362c8246b542a 100644 (file)
@@ -241,6 +241,7 @@ extern int show_unhandled_signals;
 
 struct pt_regs;
 extern int get_signal_to_deliver(siginfo_t *info, struct k_sigaction *return_ka, struct pt_regs *regs, void *cookie);
+extern void exit_signals(struct task_struct *tsk);
 
 extern struct kmem_cache *sighand_cachep;
 
index ddb1a706b144036dd1805eac5baa66784adbbc29..5e6d3d634d5b4a28ae4d3a22aee8a83eda8fac43 100644 (file)
 #include <linux/workqueue.h>
 #include <linux/kobject.h>
 
+enum stat_item {
+       ALLOC_FASTPATH,         /* Allocation from cpu slab */
+       ALLOC_SLOWPATH,         /* Allocation by getting a new cpu slab */
+       FREE_FASTPATH,          /* Free to cpu slub */
+       FREE_SLOWPATH,          /* Freeing not to cpu slab */
+       FREE_FROZEN,            /* Freeing to frozen slab */
+       FREE_ADD_PARTIAL,       /* Freeing moves slab to partial list */
+       FREE_REMOVE_PARTIAL,    /* Freeing removes last object */
+       ALLOC_FROM_PARTIAL,     /* Cpu slab acquired from partial list */
+       ALLOC_SLAB,             /* Cpu slab acquired from page allocator */
+       ALLOC_REFILL,           /* Refill cpu slab from slab freelist */
+       FREE_SLAB,              /* Slab freed to the page allocator */
+       CPUSLAB_FLUSH,          /* Abandoning of the cpu slab */
+       DEACTIVATE_FULL,        /* Cpu slab was full when deactivated */
+       DEACTIVATE_EMPTY,       /* Cpu slab was empty when deactivated */
+       DEACTIVATE_TO_HEAD,     /* Cpu slab was moved to the head of partials */
+       DEACTIVATE_TO_TAIL,     /* Cpu slab was moved to the tail of partials */
+       DEACTIVATE_REMOTE_FREES,/* Slab contained remotely freed objects */
+       NR_SLUB_STAT_ITEMS };
+
 struct kmem_cache_cpu {
        void **freelist;        /* Pointer to first free per cpu object */
        struct page *page;      /* The slab from which we are allocating */
        int node;               /* The node of the page (or -1 for debug) */
        unsigned int offset;    /* Freepointer offset (in word units) */
        unsigned int objsize;   /* Size of an object (from kmem_cache) */
+#ifdef CONFIG_SLUB_STATS
+       unsigned stat[NR_SLUB_STAT_ITEMS];
+#endif
 };
 
 struct kmem_cache_node {
index 124449733c55a64595198aa8dc8eaf6a682189ca..576a5f77d3bd8d6583bec34b6c2d95dbe3bf362b 100644 (file)
@@ -71,7 +71,7 @@
 #define LOCK_SECTION_END                        \
         ".previous\n\t"
 
-#define __lockfunc fastcall __attribute__((section(".spinlock.text")))
+#define __lockfunc __attribute__((section(".spinlock.text")))
 
 /*
  * Pull the raw_spinlock_t and raw_rwlock_t definitions:
index ceaab9fff15507e592e87fc6cc4b8a5b4bca3e99..2091a19f1655aab8e5130256f83af4103efa9e3f 100644 (file)
@@ -120,7 +120,7 @@ extern void getboottime(struct timespec *ts);
 extern void monotonic_to_bootbased(struct timespec *ts);
 
 extern struct timespec timespec_trunc(struct timespec t, unsigned gran);
-extern int timekeeping_is_continuous(void);
+extern int timekeeping_valid_for_hres(void);
 extern void update_wall_time(void);
 extern void update_xtime_cache(u64 nsec);
 
index de0e71359ede60eadb302df0988300c97c790e3e..979fefdeb86210c15e318cc7eb8986f813181c75 100644 (file)
@@ -35,8 +35,8 @@ extern struct tvec_base boot_tvec_bases;
        struct timer_list _name =                               \
                TIMER_INITIALIZER(_function, _expires, _data)
 
-void fastcall init_timer(struct timer_list * timer);
-void fastcall init_timer_deferrable(struct timer_list *timer);
+void init_timer(struct timer_list *timer);
+void init_timer_deferrable(struct timer_list *timer);
 
 static inline void setup_timer(struct timer_list * timer,
                                void (*function)(unsigned long),
@@ -124,8 +124,6 @@ static inline void timer_stats_timer_clear_start_info(struct timer_list *timer)
 }
 #endif
 
-extern void delayed_work_timer_fn(unsigned long __data);
-
 /**
  * add_timer - start a timer
  * @timer: the timer to be added
index b94c0e4efe2487a027dbc70ae9ed36336f392345..9dc2346627b4b5c6c825dc09143041a66d22c092 100644 (file)
@@ -53,7 +53,7 @@ typedef __kernel_uid_t                uid_t;
 typedef __kernel_gid_t         gid_t;
 #endif /* __KERNEL__ */
 
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+#if defined(__GNUC__)
 typedef __kernel_loff_t                loff_t;
 #endif
 
@@ -119,7 +119,7 @@ typedef             __u8            uint8_t;
 typedef                __u16           uint16_t;
 typedef                __u32           uint32_t;
 
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+#if defined(__GNUC__)
 typedef                __u64           uint64_t;
 typedef                __u64           u_int64_t;
 typedef                __s64           int64_t;
@@ -181,7 +181,7 @@ typedef __u16 __bitwise __le16;
 typedef __u16 __bitwise __be16;
 typedef __u32 __bitwise __le32;
 typedef __u32 __bitwise __be32;
-#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+#if defined(__GNUC__)
 typedef __u64 __bitwise __le64;
 typedef __u64 __bitwise __be64;
 #endif
index 36c684e1b11040476fb685d8067a3831a00b4e2d..aa88654eb76b4050c92db6364a7338739fe936b8 100644 (file)
 #define UDF_PREALLOCATE
 #define UDF_DEFAULT_PREALLOC_BLOCKS    8
 
-#define UDFFS_DATE                     "2004/29/09"
-#define UDFFS_VERSION                  "0.9.8.1"
-
 #undef UDFFS_DEBUG
 
 #ifdef UDFFS_DEBUG
 #define udf_debug(f, a...) \
-       { \
+       do { \
                printk (KERN_DEBUG "UDF-fs DEBUG %s:%d:%s: ", \
                        __FILE__, __LINE__, __FUNCTION__); \
                printk (f, ##a); \
-       }
+       } while (0)
 #else
 #define udf_debug(f, a...) /**/
 #endif
index 80ae9ef940dccaac300f187c5292d52d42d92bad..9bc47352b6b445e74a73d69f3a4172aecf5158a7 100644 (file)
@@ -75,7 +75,7 @@ struct udf_part_map
 struct udf_sb_info
 {
        struct udf_part_map     *s_partmaps;
-       __u8                    s_volident[32];
+       __u8                    s_volume_ident[32];
 
        /* Overall info */
        __u16                   s_partitions;
@@ -84,9 +84,9 @@ struct udf_sb_info
        /* Sector headers */
        __s32                   s_session;
        __u32                   s_anchor[4];
-       __u32                   s_lastblock;
+       __u32                   s_last_block;
 
-       struct buffer_head      *s_lvidbh;
+       struct buffer_head      *s_lvid_bh;
 
        /* Default permissions */
        mode_t                  s_umask;
@@ -94,10 +94,10 @@ struct udf_sb_info
        uid_t                   s_uid;
 
        /* Root Info */
-       struct timespec         s_recordtime;
+       struct timespec         s_record_time;
 
        /* Fileset Info */
-       __u16                   s_serialnum;
+       __u16                   s_serial_number;
 
        /* highest UDF revision we have recorded to this media */
        __u16                   s_udfrev;
@@ -109,7 +109,7 @@ struct udf_sb_info
        struct nls_table        *s_nls_map;
 
        /* VAT inode */
-       struct inode            *s_vat;
+       struct inode            *s_vat_inode;
 
        struct mutex            s_alloc_mutex;
 };
index 923db99175f2144a8df2ad0c8e3e2e5aaff6ebcc..11232676bfff59af017b4b3343c67dc430004c4b 100644 (file)
@@ -35,6 +35,7 @@ struct new_utsname {
 #include <linux/sched.h>
 #include <linux/kref.h>
 #include <linux/nsproxy.h>
+#include <linux/err.h>
 #include <asm/atomic.h>
 
 struct uts_namespace {
@@ -43,6 +44,7 @@ struct uts_namespace {
 };
 extern struct uts_namespace init_uts_ns;
 
+#ifdef CONFIG_UTS_NS
 static inline void get_uts_ns(struct uts_namespace *ns)
 {
        kref_get(&ns->kref);
@@ -56,6 +58,25 @@ static inline void put_uts_ns(struct uts_namespace *ns)
 {
        kref_put(&ns->kref, free_uts_ns);
 }
+#else
+static inline void get_uts_ns(struct uts_namespace *ns)
+{
+}
+
+static inline void put_uts_ns(struct uts_namespace *ns)
+{
+}
+
+static inline struct uts_namespace *copy_utsname(unsigned long flags,
+                                       struct uts_namespace *ns)
+{
+       if (flags & CLONE_NEWUTS)
+               return ERR_PTR(-EINVAL);
+
+       return ns;
+}
+#endif
+
 static inline struct new_utsname *utsname(void)
 {
        return &current->nsproxy->uts_ns->name;
index d8d85b13364dd23e3c6772a506465e71812c7685..953d6040ff50349a61130a06cae45b916a5f09fc 100644 (file)
@@ -150,19 +150,6 @@ struct rt6_statistics {
  *
  */
 
-#define RTPRI_FIREWALL 8               /* Firewall control information */
-#define RTPRI_FLOW     16              /* Flow based forwarding rules  */
-#define RTPRI_KERN_CTL 32              /* Kernel control routes        */
-
-#define RTPRI_USER_MIN 256             /* Mimimum user priority        */
-#define RTPRI_USER_MAX 1024            /* Maximum user priority        */
-
-#define RTPRI_KERN_DFLT        4096            /* Kernel default routes        */
-
-#define        MAX_FLOW_BACKTRACE      32
-
-
-typedef void                   (*f_pnode)(struct fib6_node *fn, void *);
 
 struct fib6_table {
        struct hlist_node       tb6_hlist;
index faac0eee1ef3d934482209406d7e4ac406760379..f99e4f0f568f902c8cd67f3dbc49517dcc26200e 100644 (file)
@@ -1,11 +1,9 @@
 #ifndef _NET_IP6_ROUTE_H
 #define _NET_IP6_ROUTE_H
 
-#define IP6_RT_PRIO_FW         16
 #define IP6_RT_PRIO_USER       1024
 #define IP6_RT_PRIO_ADDRCONF   256
 #define IP6_RT_PRIO_KERN       512
-#define IP6_RT_FLOW_MASK       0x00ff
 
 struct route_info {
        __u8                    type;
index 73b5711faf32f4e47b81044ec0c54b0978c669ca..49aac6323fbeaf7c4dacbb16c8194d91246977bf 100644 (file)
@@ -67,7 +67,7 @@ struct nf_ct_ext_type
        void (*destroy)(struct nf_conn *ct);
        /* Called when realloacted (can be NULL).
           Contents has already been moved. */
-       void (*move)(struct nf_conn *ct, void *old);
+       void (*move)(void *new, void *old);
 
        enum nf_ct_ext_id id;
 
index fb42eb7a86a55dc41fa0556059551012e9b46aca..2e159a812f83e5271e9553897d37b7b878360917 100644 (file)
@@ -130,11 +130,6 @@ static inline u32 msg_type(struct tipc_msg *m)
        return msg_bits(m, 1, 29, 0x7);
 }
 
-static inline u32 msg_direct(struct tipc_msg *m)
-{
-       return (msg_type(m) == TIPC_DIRECT_MSG);
-}
-
 static inline u32 msg_named(struct tipc_msg *m)
 {
        return (msg_type(m) == TIPC_NAMED_MSG);
@@ -207,17 +202,6 @@ static inline u32 msg_nameupper(struct tipc_msg *m)
        return msg_word(m, 10);
 }
 
-static inline char *msg_options(struct tipc_msg *m, u32 *len)
-{
-       u32 pos = msg_bits(m, 1, 16, 0x7);
-
-       if (!pos)
-               return 0;
-       pos = (pos * 4) + 28;
-       *len = msg_hdr_sz(m) - pos;
-       return (char *)&m->hdr[pos/4];
-}
-
 #endif
 
 #endif
index 318a909e7ae15afe3f26d01a4a96be8863192f98..5ffec8ad6964c7ac9cebe0edfdb0517bff106064 100644 (file)
@@ -45,8 +45,8 @@
 /* initiator tags; opaque for target */
 typedef uint32_t __bitwise__ itt_t;
 /* below makes sense only for initiator that created this tag */
-#define build_itt(itt, id, age) ((__force itt_t)\
-       ((itt) | ((id) << ISCSI_CID_SHIFT) | ((age) << ISCSI_AGE_SHIFT)))
+#define build_itt(itt, age) ((__force itt_t)\
+       ((itt) | ((age) << ISCSI_AGE_SHIFT)))
 #define get_itt(itt) ((__force uint32_t)(itt_t)(itt) & ISCSI_ITT_MASK)
 #define RESERVED_ITT ((__force itt_t)0xffffffff)
 
index 889f51fabab9edae977c660de18e563a9f5c0982..7b90b63fb5c7cabf920d26590b8de56663dd46e6 100644 (file)
@@ -70,8 +70,6 @@ enum {
 #define ISCSI_SUSPEND_BIT              1
 
 #define ISCSI_ITT_MASK                 (0xfff)
-#define ISCSI_CID_SHIFT                        12
-#define ISCSI_CID_MASK                 (0xffff << ISCSI_CID_SHIFT)
 #define ISCSI_AGE_SHIFT                        28
 #define ISCSI_AGE_MASK                 (0xf << ISCSI_AGE_SHIFT)
 
@@ -135,6 +133,14 @@ static inline void* iscsi_next_hdr(struct iscsi_cmd_task *ctask)
        return (void*)ctask->hdr + ctask->hdr_len;
 }
 
+/* Connection's states */
+enum {
+       ISCSI_CONN_INITIAL_STAGE,
+       ISCSI_CONN_STARTED,
+       ISCSI_CONN_STOPPED,
+       ISCSI_CONN_CLEANUP_WAIT,
+};
+
 struct iscsi_conn {
        struct iscsi_cls_conn   *cls_conn;      /* ptr to class connection */
        void                    *dd_data;       /* iscsi_transport data */
@@ -227,6 +233,17 @@ struct iscsi_pool {
        int                     max;            /* Max number of elements */
 };
 
+/* Session's states */
+enum {
+       ISCSI_STATE_FREE = 1,
+       ISCSI_STATE_LOGGED_IN,
+       ISCSI_STATE_FAILED,
+       ISCSI_STATE_TERMINATE,
+       ISCSI_STATE_IN_RECOVERY,
+       ISCSI_STATE_RECOVERY_FAILED,
+       ISCSI_STATE_LOGGING_OUT,
+};
+
 struct iscsi_session {
        /*
         * Syncs up the scsi eh thread with the iscsi eh thread when sending
@@ -325,6 +342,10 @@ extern int iscsi_session_get_param(struct iscsi_cls_session *cls_session,
 #define session_to_cls(_sess) \
        hostdata_session(_sess->host->hostdata)
 
+#define iscsi_session_printk(prefix, _sess, fmt, a...) \
+       iscsi_cls_session_printk(prefix,                \
+               (struct iscsi_cls_session *)session_to_cls(_sess), fmt, ##a)
+
 /*
  * connection management
  */
@@ -339,6 +360,9 @@ extern void iscsi_conn_failure(struct iscsi_conn *conn, enum iscsi_err err);
 extern int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
                                enum iscsi_param param, char *buf);
 
+#define iscsi_conn_printk(prefix, _c, fmt, a...) \
+       iscsi_cls_conn_printk(prefix, _c->cls_conn, fmt, ##a)
+
 /*
  * pdu and task processing
  */
@@ -349,8 +373,6 @@ extern int iscsi_conn_send_pdu(struct iscsi_cls_conn *, struct iscsi_hdr *,
                                char *, uint32_t);
 extern int iscsi_complete_pdu(struct iscsi_conn *, struct iscsi_hdr *,
                              char *, int);
-extern int __iscsi_complete_pdu(struct iscsi_conn *, struct iscsi_hdr *,
-                               char *, int);
 extern int iscsi_verify_itt(struct iscsi_conn *, struct iscsi_hdr *,
                            uint32_t *);
 extern void iscsi_requeue_ctask(struct iscsi_cmd_task *ctask);
index 82251575a9b45e1a4e24475dc71503deef0223a8..1f74bcd603fedaee2d513758add2ebe4d827fea6 100644 (file)
@@ -235,6 +235,20 @@ static inline int scsi_status_is_good(int status)
 #define TYPE_RBC           0x0e
 #define TYPE_NO_LUN         0x7f
 
+/* SCSI protocols; these are taken from SPC-3 section 7.5 */
+enum scsi_protocol {
+       SCSI_PROTOCOL_FCP = 0,  /* Fibre Channel */
+       SCSI_PROTOCOL_SPI = 1,  /* parallel SCSI */
+       SCSI_PROTOCOL_SSA = 2,  /* Serial Storage Architecture - Obsolete */
+       SCSI_PROTOCOL_SBP = 3,  /* firewire */
+       SCSI_PROTOCOL_SRP = 4,  /* Infiniband RDMA */
+       SCSI_PROTOCOL_ISCSI = 5,
+       SCSI_PROTOCOL_SAS = 6,
+       SCSI_PROTOCOL_ADT = 7,  /* Media Changers */
+       SCSI_PROTOCOL_ATA = 8,
+       SCSI_PROTOCOL_UNSPEC = 0xf, /* No specific protocol */
+};
+
 /* Returns a human-readable name for the device */
 extern const char * scsi_device_type(unsigned type);
 
index 5c58d594126a93bcb697e4c61b9a61c31aaa30b3..d1299e999723457192565457c00604e294eea5d8 100644 (file)
@@ -280,39 +280,45 @@ struct scsi_host_template {
         * If the host wants to be called before the scan starts, but
         * after the midlayer has set up ready for the scan, it can fill
         * in this function.
+        *
+        * Status: OPTIONAL
         */
        void (* scan_start)(struct Scsi_Host *);
 
        /*
-        * fill in this function to allow the queue depth of this host
-        * to be changeable (on a per device basis).  returns either
+        * Fill in this function to allow the queue depth of this host
+        * to be changeable (on a per device basis).  Returns either
         * the current queue depth setting (may be different from what
         * was passed in) or an error.  An error should only be
         * returned if the requested depth is legal but the driver was
         * unable to set it.  If the requested depth is illegal, the
         * driver should set and return the closest legal queue depth.
         *
+        * Status: OPTIONAL
         */
        int (* change_queue_depth)(struct scsi_device *, int);
 
        /*
-        * fill in this function to allow the changing of tag types
+        * Fill in this function to allow the changing of tag types
         * (this also allows the enabling/disabling of tag command
         * queueing).  An error should only be returned if something
         * went wrong in the driver while trying to set the tag type.
         * If the driver doesn't support the requested tag type, then
         * it should set the closest type it does support without
         * returning an error.  Returns the actual tag type set.
+        *
+        * Status: OPTIONAL
         */
        int (* change_queue_type)(struct scsi_device *, int);
 
        /*
-        * This function determines the bios parameters for a given
+        * This function determines the BIOS parameters for a given
         * harddisk.  These tend to be numbers that are made up by
         * the host adapter.  Parameters:
         * size, device, list (heads, sectors, cylinders)
         *
-        * Status: OPTIONAL */
+        * Status: OPTIONAL
+        */
        int (* bios_param)(struct scsi_device *, struct block_device *,
                        sector_t, int []);
 
@@ -351,7 +357,7 @@ struct scsi_host_template {
 
        /*
         * This determines if we will use a non-interrupt driven
-        * or an interrupt driven scheme,  It is set to the maximum number
+        * or an interrupt driven scheme.  It is set to the maximum number
         * of simultaneous commands a given host adapter will accept.
         */
        int can_queue;
@@ -372,12 +378,12 @@ struct scsi_host_template {
        unsigned short sg_tablesize;
 
        /*
-        * If the host adapter has limitations beside segment count
+        * Set this if the host adapter has limitations beside segment count.
         */
        unsigned short max_sectors;
 
        /*
-        * dma scatter gather segment boundary limit. a segment crossing this
+        * DMA scatter gather segment boundary limit. A segment crossing this
         * boundary will be split in two.
         */
        unsigned long dma_boundary;
@@ -386,7 +392,7 @@ struct scsi_host_template {
         * This specifies "machine infinity" for host templates which don't
         * limit the transfer size.  Note this limit represents an absolute
         * maximum, and may be over the transfer limits allowed for
-        * individual devices (e.g. 256 for SCSI-1)
+        * individual devices (e.g. 256 for SCSI-1).
         */
 #define SCSI_DEFAULT_MAX_SECTORS       1024
 
@@ -413,12 +419,12 @@ struct scsi_host_template {
        unsigned supported_mode:2;
 
        /*
-        * true if this host adapter uses unchecked DMA onto an ISA bus.
+        * True if this host adapter uses unchecked DMA onto an ISA bus.
         */
        unsigned unchecked_isa_dma:1;
 
        /*
-        * true if this host adapter can make good use of clustering.
+        * True if this host adapter can make good use of clustering.
         * I originally thought that if the tablesize was large that it
         * was a waste of CPU cycles to prepare a cluster list, but
         * it works out that the Buslogic is faster if you use a smaller
@@ -428,7 +434,7 @@ struct scsi_host_template {
        unsigned use_clustering:1;
 
        /*
-        * True for emulated SCSI host adapters (e.g. ATAPI)
+        * True for emulated SCSI host adapters (e.g. ATAPI).
         */
        unsigned emulated:1;
 
@@ -438,12 +444,12 @@ struct scsi_host_template {
        unsigned skip_settle_delay:1;
 
        /*
-        * ordered write support
+        * True if we are using ordered write support.
         */
        unsigned ordered_tag:1;
 
        /*
-        * Countdown for host blocking with no commands outstanding
+        * Countdown for host blocking with no commands outstanding.
         */
        unsigned int max_host_blocked;
 
@@ -522,8 +528,8 @@ struct Scsi_Host {
        struct scsi_transport_template *transportt;
 
        /*
-        * area to keep a shared tag map (if needed, will be
-        * NULL if not)
+        * Area to keep a shared tag map (if needed, will be
+        * NULL if not).
         */
        struct blk_queue_tag    *bqt;
 
@@ -596,16 +602,16 @@ struct Scsi_Host {
        /*
         * Host uses correct SCSI ordering not PC ordering. The bit is
         * set for the minority of drivers whose authors actually read
-        * the spec ;)
+        * the spec ;).
         */
        unsigned reverse_ordering:1;
 
        /*
-        * ordered write support
+        * Ordered write support
         */
        unsigned ordered_tag:1;
 
-       /* task mgmt function in progress */
+       /* Task mgmt function in progress */
        unsigned tmf_in_progress:1;
 
        /* Asynchronous scan in progress */
index 404f11d331d6e767711a86e860013e63f88b8611..dbc96ef4cc72020b827e6e04e4dfe0d125091e38 100644 (file)
@@ -149,13 +149,6 @@ extern void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error);
 extern int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
                          char *data, uint32_t data_size);
 
-
-/* Connection's states */
-#define ISCSI_CONN_INITIAL_STAGE       0
-#define ISCSI_CONN_STARTED             1
-#define ISCSI_CONN_STOPPED             2
-#define ISCSI_CONN_CLEANUP_WAIT                3
-
 struct iscsi_cls_conn {
        struct list_head conn_list;     /* item in connlist */
        void *dd_data;                  /* LLD private data */
@@ -169,27 +162,31 @@ struct iscsi_cls_conn {
 #define iscsi_dev_to_conn(_dev) \
        container_of(_dev, struct iscsi_cls_conn, dev)
 
-/* Session's states */
-#define ISCSI_STATE_FREE               1
-#define ISCSI_STATE_LOGGED_IN          2
-#define ISCSI_STATE_FAILED             3
-#define ISCSI_STATE_TERMINATE          4
-#define ISCSI_STATE_IN_RECOVERY                5
-#define ISCSI_STATE_RECOVERY_FAILED    6
-#define ISCSI_STATE_LOGGING_OUT                7
+#define iscsi_conn_to_session(_conn) \
+       iscsi_dev_to_session(_conn->dev.parent)
+
+/* iscsi class session state */
+enum {
+       ISCSI_SESSION_LOGGED_IN,
+       ISCSI_SESSION_FAILED,
+       ISCSI_SESSION_FREE,
+};
 
 struct iscsi_cls_session {
        struct list_head sess_list;             /* item in session_list */
        struct list_head host_list;
        struct iscsi_transport *transport;
+       spinlock_t lock;
+       struct work_struct scan_work;
+       struct work_struct unbind_work;
 
        /* recovery fields */
        int recovery_tmo;
        struct delayed_work recovery_work;
-       struct work_struct unbind_work;
 
        int target_id;
 
+       int state;
        int sid;                                /* session id */
        void *dd_data;                          /* LLD private data */
        struct device dev;      /* sysfs transport/container device */
@@ -206,14 +203,22 @@ struct iscsi_cls_session {
 
 struct iscsi_host {
        struct list_head sessions;
+       atomic_t nr_scans;
        struct mutex mutex;
-       struct workqueue_struct *unbind_workq;
-       char unbind_workq_name[KOBJ_NAME_LEN];
+       struct workqueue_struct *scan_workq;
+       char scan_workq_name[KOBJ_NAME_LEN];
 };
 
 /*
  * session and connection functions that can be used by HW iSCSI LLDs
  */
+#define iscsi_cls_session_printk(prefix, _cls_session, fmt, a...) \
+       dev_printk(prefix, &(_cls_session)->dev, fmt, ##a)
+
+#define iscsi_cls_conn_printk(prefix, _cls_conn, fmt, a...) \
+       dev_printk(prefix, &(_cls_conn)->dev, fmt, ##a)
+
+extern int iscsi_session_chkready(struct iscsi_cls_session *session);
 extern struct iscsi_cls_session *iscsi_alloc_session(struct Scsi_Host *shost,
                                        struct iscsi_transport *transport);
 extern int iscsi_add_session(struct iscsi_cls_session *session,
@@ -231,6 +236,6 @@ extern struct iscsi_cls_conn *iscsi_create_conn(struct iscsi_cls_session *sess,
 extern int iscsi_destroy_conn(struct iscsi_cls_conn *conn);
 extern void iscsi_unblock_session(struct iscsi_cls_session *session);
 extern void iscsi_block_session(struct iscsi_cls_session *session);
-
+extern int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time);
 
 #endif
index 95ac2657b0f452d71590746a493d6b8960068006..455170e1c1e355d9e73348ac0467e24b10d67ed5 100644 (file)
@@ -214,27 +214,6 @@ config TASK_IO_ACCOUNTING
 
          Say N if unsure.
 
-config USER_NS
-       bool "User Namespaces (EXPERIMENTAL)"
-       default n
-       depends on EXPERIMENTAL
-       help
-         Support user namespaces.  This allows containers, i.e.
-         vservers, to use user namespaces to provide different
-         user info for different servers.  If unsure, say N.
-
-config PID_NS
-       bool "PID Namespaces (EXPERIMENTAL)"
-       default n
-       depends on EXPERIMENTAL
-       help
-         Suport process id namespaces.  This allows having multiple
-         process with the same pid as long as they are in different
-         pid namespaces.  This is a building block of containers.
-
-         Unless you want to work with an experimental feature
-         say N here.
-
 config AUDIT
        bool "Auditing support"
        depends on NET
@@ -420,6 +399,49 @@ config RELAY
 
          If unsure, say N.
 
+config NAMESPACES
+       bool "Namespaces support" if EMBEDDED
+       default !EMBEDDED
+       help
+         Provides the way to make tasks work with different objects using
+         the same id. For example same IPC id may refer to different objects
+         or same user id or pid may refer to different tasks when used in
+         different namespaces.
+
+config UTS_NS
+       bool "UTS namespace"
+       depends on NAMESPACES
+       help
+         In this namespace tasks see different info provided with the
+         uname() system call
+
+config IPC_NS
+       bool "IPC namespace"
+       depends on NAMESPACES && SYSVIPC
+       help
+         In this namespace tasks work with IPC ids which correspond to
+         different IPC objects in different namespaces
+
+config USER_NS
+       bool "User namespace (EXPERIMENTAL)"
+       depends on NAMESPACES && EXPERIMENTAL
+       help
+         This allows containers, i.e. vservers, to use user namespaces
+         to provide different user info for different servers.
+         If unsure, say N.
+
+config PID_NS
+       bool "PID Namespaces (EXPERIMENTAL)"
+       default n
+       depends on NAMESPACES && EXPERIMENTAL
+       help
+         Suport process id namespaces.  This allows having multiple
+         process with the same pid as long as they are in different
+         pid namespaces.  This is a building block of containers.
+
+         Unless you want to work with an experimental feature
+         say N here.
+
 config BLK_DEV_INITRD
        bool "Initial RAM filesystem and RAM disk (initramfs/initrd) support"
        depends on BROKEN || !FRV
index 2a78932f6c075abd36b331db09191b785d3156bc..c59859b85db0d999f3e6cf1e8af1aead1fef39d6 100644 (file)
@@ -238,22 +238,18 @@ EXPORT_SYMBOL(loops_per_jiffy);
 
 static int __init debug_kernel(char *str)
 {
-       if (*str)
-               return 0;
        console_loglevel = 10;
-       return 1;
+       return 0;
 }
 
 static int __init quiet_kernel(char *str)
 {
-       if (*str)
-               return 0;
        console_loglevel = 4;
-       return 1;
+       return 0;
 }
 
-__setup("debug", debug_kernel);
-__setup("quiet", quiet_kernel);
+early_param("debug", debug_kernel);
+early_param("quiet", quiet_kernel);
 
 static int __init loglevel(char *str)
 {
@@ -261,7 +257,7 @@ static int __init loglevel(char *str)
        return 1;
 }
 
-__setup("loglevel=", loglevel);
+early_param("loglevel", loglevel);
 
 /*
  * Unknown boot options get handed to init, unless they look like
@@ -833,7 +829,6 @@ static int __init kernel_init(void * unused)
         */
        init_pid_ns.child_reaper = current;
 
-       __set_special_pids(1, 1);
        cad_pid = task_pid(current);
 
        smp_prepare_cpus(setup_max_cpus);
index b93bba6652f1e7abc068d96ea3490e9491939684..5fc5e33ea047c9f46b18948d06e0133733dba8dc 100644 (file)
@@ -7,4 +7,5 @@ obj-$(CONFIG_SYSVIPC) += util.o msgutil.o msg.o sem.o shm.o
 obj-$(CONFIG_SYSVIPC_SYSCTL) += ipc_sysctl.o
 obj_mq-$(CONFIG_COMPAT) += compat_mq.o
 obj-$(CONFIG_POSIX_MQUEUE) += mqueue.o msgutil.o $(obj_mq-y)
+obj-$(CONFIG_IPC_NS) += namespace.o
 
index 79e24e878c1eae6d2dc1247f72dec8de71ce2108..7f4235bed51bd92323cc6807ca68171c283633e2 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/nsproxy.h>
 #include <linux/sysctl.h>
 #include <linux/uaccess.h>
+#include <linux/ipc_namespace.h>
 
 static void *get_ipc(ctl_table *table)
 {
index 6ca7b97114f3c599d1fbb5c7beea0f7003bd4217..60f7a27f7a9e4ddeacb1eb95e1d867860b964f3c 100644 (file)
@@ -332,8 +332,7 @@ static ssize_t mqueue_read_file(struct file *filp, char __user *u_data,
                        (info->notify_owner &&
                         info->notify.sigev_notify == SIGEV_SIGNAL) ?
                                info->notify.sigev_signo : 0,
-                       pid_nr_ns(info->notify_owner,
-                               current->nsproxy->pid_ns));
+                       pid_vnr(info->notify_owner));
        spin_unlock(&info->lock);
        buffer[sizeof(buffer)-1] = '\0';
        slen = strlen(buffer)+1;
@@ -510,7 +509,7 @@ static void __do_notify(struct mqueue_inode_info *info)
                        sig_i.si_errno = 0;
                        sig_i.si_code = SI_MESGQ;
                        sig_i.si_value = info->notify.sigev_value;
-                       sig_i.si_pid = task_pid_vnr(current);
+                       sig_i.si_pid = task_tgid_vnr(current);
                        sig_i.si_uid = current->uid;
 
                        kill_pid_info(info->notify.sigev_signo,
index ec0c724054b95ce733eee1510d044df7d95bea20..46585a05473eceb84f23c456e0f7dc96ab0bfbf6 100644 (file)
--- a/ipc/msg.c
+++ b/ipc/msg.c
@@ -36,6 +36,7 @@
 #include <linux/seq_file.h>
 #include <linux/rwsem.h>
 #include <linux/nsproxy.h>
+#include <linux/ipc_namespace.h>
 
 #include <asm/current.h>
 #include <asm/uaccess.h>
@@ -66,72 +67,37 @@ struct msg_sender {
 #define SEARCH_NOTEQUAL                3
 #define SEARCH_LESSEQUAL       4
 
-static struct ipc_ids init_msg_ids;
-
-#define msg_ids(ns)    (*((ns)->ids[IPC_MSG_IDS]))
+#define msg_ids(ns)    ((ns)->ids[IPC_MSG_IDS])
 
 #define msg_unlock(msq)                ipc_unlock(&(msq)->q_perm)
 #define msg_buildid(id, seq)   ipc_buildid(id, seq)
 
-static void freeque(struct ipc_namespace *, struct msg_queue *);
+static void freeque(struct ipc_namespace *, struct kern_ipc_perm *);
 static int newque(struct ipc_namespace *, struct ipc_params *);
 #ifdef CONFIG_PROC_FS
 static int sysvipc_msg_proc_show(struct seq_file *s, void *it);
 #endif
 
-static void __msg_init_ns(struct ipc_namespace *ns, struct ipc_ids *ids)
+void msg_init_ns(struct ipc_namespace *ns)
 {
-       ns->ids[IPC_MSG_IDS] = ids;
        ns->msg_ctlmax = MSGMAX;
        ns->msg_ctlmnb = MSGMNB;
        ns->msg_ctlmni = MSGMNI;
        atomic_set(&ns->msg_bytes, 0);
        atomic_set(&ns->msg_hdrs, 0);
-       ipc_init_ids(ids);
-}
-
-int msg_init_ns(struct ipc_namespace *ns)
-{
-       struct ipc_ids *ids;
-
-       ids = kmalloc(sizeof(struct ipc_ids), GFP_KERNEL);
-       if (ids == NULL)
-               return -ENOMEM;
-
-       __msg_init_ns(ns, ids);
-       return 0;
+       ipc_init_ids(&ns->ids[IPC_MSG_IDS]);
 }
 
+#ifdef CONFIG_IPC_NS
 void msg_exit_ns(struct ipc_namespace *ns)
 {
-       struct msg_queue *msq;
-       struct kern_ipc_perm *perm;
-       int next_id;
-       int total, in_use;
-
-       down_write(&msg_ids(ns).rw_mutex);
-
-       in_use = msg_ids(ns).in_use;
-
-       for (total = 0, next_id = 0; total < in_use; next_id++) {
-               perm = idr_find(&msg_ids(ns).ipcs_idr, next_id);
-               if (perm == NULL)
-                       continue;
-               ipc_lock_by_ptr(perm);
-               msq = container_of(perm, struct msg_queue, q_perm);
-               freeque(ns, msq);
-               total++;
-       }
-
-       up_write(&msg_ids(ns).rw_mutex);
-
-       kfree(ns->ids[IPC_MSG_IDS]);
-       ns->ids[IPC_MSG_IDS] = NULL;
+       free_ipcs(ns, &msg_ids(ns), freeque);
 }
+#endif
 
 void __init msg_init(void)
 {
-       __msg_init_ns(&init_ipc_ns, &init_msg_ids);
+       msg_init_ns(&init_ipc_ns);
        ipc_init_proc_interface("sysvipc/msg",
                                "       key      msqid perms      cbytes       qnum lspid lrpid   uid   gid  cuid  cgid      stime      rtime      ctime\n",
                                IPC_MSG_IDS, sysvipc_msg_proc_show);
@@ -289,9 +255,10 @@ static void expunge_all(struct msg_queue *msq, int res)
  * msg_ids.rw_mutex (writer) and the spinlock for this message queue are held
  * before freeque() is called. msg_ids.rw_mutex remains locked on exit.
  */
-static void freeque(struct ipc_namespace *ns, struct msg_queue *msq)
+static void freeque(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
 {
        struct list_head *tmp;
+       struct msg_queue *msq = container_of(ipcp, struct msg_queue, q_perm);
 
        expunge_all(msq, -EIDRM);
        ss_wakeup(&msq->q_senders, 1);
@@ -597,7 +564,7 @@ asmlinkage long sys_msgctl(int msqid, int cmd, struct msqid_ds __user *buf)
                break;
        }
        case IPC_RMID:
-               freeque(ns, msq);
+               freeque(ns, &msq->q_perm);
                break;
        }
        err = 0;
diff --git a/ipc/namespace.c b/ipc/namespace.c
new file mode 100644 (file)
index 0000000..1b96765
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * linux/ipc/namespace.c
+ * Copyright (C) 2006 Pavel Emelyanov <xemul@openvz.org> OpenVZ, SWsoft Inc.
+ */
+
+#include <linux/ipc.h>
+#include <linux/msg.h>
+#include <linux/ipc_namespace.h>
+#include <linux/rcupdate.h>
+#include <linux/nsproxy.h>
+#include <linux/slab.h>
+
+#include "util.h"
+
+static struct ipc_namespace *clone_ipc_ns(struct ipc_namespace *old_ns)
+{
+       struct ipc_namespace *ns;
+
+       ns = kmalloc(sizeof(struct ipc_namespace), GFP_KERNEL);
+       if (ns == NULL)
+               return ERR_PTR(-ENOMEM);
+
+       sem_init_ns(ns);
+       msg_init_ns(ns);
+       shm_init_ns(ns);
+
+       kref_init(&ns->kref);
+       return ns;
+}
+
+struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns)
+{
+       struct ipc_namespace *new_ns;
+
+       BUG_ON(!ns);
+       get_ipc_ns(ns);
+
+       if (!(flags & CLONE_NEWIPC))
+               return ns;
+
+       new_ns = clone_ipc_ns(ns);
+
+       put_ipc_ns(ns);
+       return new_ns;
+}
+
+/*
+ * free_ipcs - free all ipcs of one type
+ * @ns:   the namespace to remove the ipcs from
+ * @ids:  the table of ipcs to free
+ * @free: the function called to free each individual ipc
+ *
+ * Called for each kind of ipc when an ipc_namespace exits.
+ */
+void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids,
+              void (*free)(struct ipc_namespace *, struct kern_ipc_perm *))
+{
+       struct kern_ipc_perm *perm;
+       int next_id;
+       int total, in_use;
+
+       down_write(&ids->rw_mutex);
+
+       in_use = ids->in_use;
+
+       for (total = 0, next_id = 0; total < in_use; next_id++) {
+               perm = idr_find(&ids->ipcs_idr, next_id);
+               if (perm == NULL)
+                       continue;
+               ipc_lock_by_ptr(perm);
+               free(ns, perm);
+               total++;
+       }
+       up_write(&ids->rw_mutex);
+}
+
+void free_ipc_ns(struct kref *kref)
+{
+       struct ipc_namespace *ns;
+
+       ns = container_of(kref, struct ipc_namespace, kref);
+       sem_exit_ns(ns);
+       msg_exit_ns(ns);
+       shm_exit_ns(ns);
+       kfree(ns);
+}
index d65e285b7e309de03d68cbef348929d0b23f961f..0b45a4d383c6ae662845f5e26c6bc19f25c10a22 100644 (file)
--- a/ipc/sem.c
+++ b/ipc/sem.c
 #include <linux/seq_file.h>
 #include <linux/rwsem.h>
 #include <linux/nsproxy.h>
+#include <linux/ipc_namespace.h>
 
 #include <asm/uaccess.h>
 #include "util.h"
 
-#define sem_ids(ns)    (*((ns)->ids[IPC_SEM_IDS]))
+#define sem_ids(ns)    ((ns)->ids[IPC_SEM_IDS])
 
 #define sem_unlock(sma)                ipc_unlock(&(sma)->sem_perm)
 #define sem_checkid(sma, semid)        ipc_checkid(&sma->sem_perm, semid)
 #define sem_buildid(id, seq)   ipc_buildid(id, seq)
 
-static struct ipc_ids init_sem_ids;
-
 static int newary(struct ipc_namespace *, struct ipc_params *);
-static void freeary(struct ipc_namespace *, struct sem_array *);
+static void freeary(struct ipc_namespace *, struct kern_ipc_perm *);
 #ifdef CONFIG_PROC_FS
 static int sysvipc_sem_proc_show(struct seq_file *s, void *it);
 #endif
@@ -117,58 +116,26 @@ static int sysvipc_sem_proc_show(struct seq_file *s, void *it);
 #define sc_semopm      sem_ctls[2]
 #define sc_semmni      sem_ctls[3]
 
-static void __sem_init_ns(struct ipc_namespace *ns, struct ipc_ids *ids)
+void sem_init_ns(struct ipc_namespace *ns)
 {
-       ns->ids[IPC_SEM_IDS] = ids;
        ns->sc_semmsl = SEMMSL;
        ns->sc_semmns = SEMMNS;
        ns->sc_semopm = SEMOPM;
        ns->sc_semmni = SEMMNI;
        ns->used_sems = 0;
-       ipc_init_ids(ids);
-}
-
-int sem_init_ns(struct ipc_namespace *ns)
-{
-       struct ipc_ids *ids;
-
-       ids = kmalloc(sizeof(struct ipc_ids), GFP_KERNEL);
-       if (ids == NULL)
-               return -ENOMEM;
-
-       __sem_init_ns(ns, ids);
-       return 0;
+       ipc_init_ids(&ns->ids[IPC_SEM_IDS]);
 }
 
+#ifdef CONFIG_IPC_NS
 void sem_exit_ns(struct ipc_namespace *ns)
 {
-       struct sem_array *sma;
-       struct kern_ipc_perm *perm;
-       int next_id;
-       int total, in_use;
-
-       down_write(&sem_ids(ns).rw_mutex);
-
-       in_use = sem_ids(ns).in_use;
-
-       for (total = 0, next_id = 0; total < in_use; next_id++) {
-               perm = idr_find(&sem_ids(ns).ipcs_idr, next_id);
-               if (perm == NULL)
-                       continue;
-               ipc_lock_by_ptr(perm);
-               sma = container_of(perm, struct sem_array, sem_perm);
-               freeary(ns, sma);
-               total++;
-       }
-       up_write(&sem_ids(ns).rw_mutex);
-
-       kfree(ns->ids[IPC_SEM_IDS]);
-       ns->ids[IPC_SEM_IDS] = NULL;
+       free_ipcs(ns, &sem_ids(ns), freeary);
 }
+#endif
 
 void __init sem_init (void)
 {
-       __sem_init_ns(&init_ipc_ns, &init_sem_ids);
+       sem_init_ns(&init_ipc_ns);
        ipc_init_proc_interface("sysvipc/sem",
                                "       key      semid perms      nsems   uid   gid  cuid  cgid      otime      ctime\n",
                                IPC_SEM_IDS, sysvipc_sem_proc_show);
@@ -557,10 +524,11 @@ static int count_semzcnt (struct sem_array * sma, ushort semnum)
  * as a writer and the spinlock for this semaphore set hold. sem_ids.rw_mutex
  * remains locked on exit.
  */
-static void freeary(struct ipc_namespace *ns, struct sem_array *sma)
+static void freeary(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
 {
        struct sem_undo *un;
        struct sem_queue *q;
+       struct sem_array *sma = container_of(ipcp, struct sem_array, sem_perm);
 
        /* Invalidate the existing undo structures for this semaphore set.
         * (They will be freed without any further action in exit_sem()
@@ -614,8 +582,8 @@ static unsigned long copy_semid_to_user(void __user *buf, struct semid64_ds *in,
        }
 }
 
-static int semctl_nolock(struct ipc_namespace *ns, int semid, int semnum,
-               int cmd, int version, union semun arg)
+static int semctl_nolock(struct ipc_namespace *ns, int semid,
+                        int cmd, int version, union semun arg)
 {
        int err = -EINVAL;
        struct sem_array *sma;
@@ -654,14 +622,23 @@ static int semctl_nolock(struct ipc_namespace *ns, int semid, int semnum,
                        return -EFAULT;
                return (max_id < 0) ? 0: max_id;
        }
+       case IPC_STAT:
        case SEM_STAT:
        {
                struct semid64_ds tbuf;
                int id;
 
-               sma = sem_lock(ns, semid);
-               if (IS_ERR(sma))
-                       return PTR_ERR(sma);
+               if (cmd == SEM_STAT) {
+                       sma = sem_lock(ns, semid);
+                       if (IS_ERR(sma))
+                               return PTR_ERR(sma);
+                       id = sma->sem_perm.id;
+               } else {
+                       sma = sem_lock_check(ns, semid);
+                       if (IS_ERR(sma))
+                               return PTR_ERR(sma);
+                       id = 0;
+               }
 
                err = -EACCES;
                if (ipcperms (&sma->sem_perm, S_IRUGO))
@@ -671,8 +648,6 @@ static int semctl_nolock(struct ipc_namespace *ns, int semid, int semnum,
                if (err)
                        goto out_unlock;
 
-               id = sma->sem_perm.id;
-
                memset(&tbuf, 0, sizeof(tbuf));
 
                kernel_to_ipc64_perm(&sma->sem_perm, &tbuf.sem_perm);
@@ -807,19 +782,6 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
                err = 0;
                goto out_unlock;
        }
-       case IPC_STAT:
-       {
-               struct semid64_ds tbuf;
-               memset(&tbuf,0,sizeof(tbuf));
-               kernel_to_ipc64_perm(&sma->sem_perm, &tbuf.sem_perm);
-               tbuf.sem_otime  = sma->sem_otime;
-               tbuf.sem_ctime  = sma->sem_ctime;
-               tbuf.sem_nsems  = sma->sem_nsems;
-               sem_unlock(sma);
-               if (copy_semid_to_user (arg.buf, &tbuf, version))
-                       return -EFAULT;
-               return 0;
-       }
        /* GETVAL, GETPID, GETNCTN, GETZCNT, SETVAL: fall-through */
        }
        err = -EINVAL;
@@ -947,7 +909,7 @@ static int semctl_down(struct ipc_namespace *ns, int semid, int semnum,
 
        switch(cmd){
        case IPC_RMID:
-               freeary(ns, sma);
+               freeary(ns, ipcp);
                err = 0;
                break;
        case IPC_SET:
@@ -986,15 +948,15 @@ asmlinkage long sys_semctl (int semid, int semnum, int cmd, union semun arg)
        switch(cmd) {
        case IPC_INFO:
        case SEM_INFO:
+       case IPC_STAT:
        case SEM_STAT:
-               err = semctl_nolock(ns,semid,semnum,cmd,version,arg);
+               err = semctl_nolock(ns, semid, cmd, version, arg);
                return err;
        case GETALL:
        case GETVAL:
        case GETPID:
        case GETNCNT:
        case GETZCNT:
-       case IPC_STAT:
        case SETVAL:
        case SETALL:
                err = semctl_main(ns,semid,semnum,cmd,version,arg);
index 65c3a294aba5cf265823f3d6f369b7b206643d22..c47e87278a92d87acf6bdfefbb16ab73186c24b2 100644 (file)
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -38,6 +38,7 @@
 #include <linux/rwsem.h>
 #include <linux/nsproxy.h>
 #include <linux/mount.h>
+#include <linux/ipc_namespace.h>
 
 #include <asm/uaccess.h>
 
@@ -55,9 +56,7 @@ struct shm_file_data {
 static const struct file_operations shm_file_operations;
 static struct vm_operations_struct shm_vm_ops;
 
-static struct ipc_ids init_shm_ids;
-
-#define shm_ids(ns)    (*((ns)->ids[IPC_SHM_IDS]))
+#define shm_ids(ns)    ((ns)->ids[IPC_SHM_IDS])
 
 #define shm_unlock(shp)                        \
        ipc_unlock(&(shp)->shm_perm)
@@ -71,22 +70,24 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
 #endif
 
-static void __shm_init_ns(struct ipc_namespace *ns, struct ipc_ids *ids)
+void shm_init_ns(struct ipc_namespace *ns)
 {
-       ns->ids[IPC_SHM_IDS] = ids;
        ns->shm_ctlmax = SHMMAX;
        ns->shm_ctlall = SHMALL;
        ns->shm_ctlmni = SHMMNI;
        ns->shm_tot = 0;
-       ipc_init_ids(ids);
+       ipc_init_ids(&ns->ids[IPC_SHM_IDS]);
 }
 
 /*
  * Called with shm_ids.rw_mutex (writer) and the shp structure locked.
  * Only shm_ids.rw_mutex remains locked on exit.
  */
-static void do_shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *shp)
+static void do_shm_rmid(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp)
 {
+       struct shmid_kernel *shp;
+       shp = container_of(ipcp, struct shmid_kernel, shm_perm);
+
        if (shp->shm_nattch){
                shp->shm_perm.mode |= SHM_DEST;
                /* Do not find it any more */
@@ -96,47 +97,16 @@ static void do_shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *shp)
                shm_destroy(ns, shp);
 }
 
-int shm_init_ns(struct ipc_namespace *ns)
-{
-       struct ipc_ids *ids;
-
-       ids = kmalloc(sizeof(struct ipc_ids), GFP_KERNEL);
-       if (ids == NULL)
-               return -ENOMEM;
-
-       __shm_init_ns(ns, ids);
-       return 0;
-}
-
+#ifdef CONFIG_IPC_NS
 void shm_exit_ns(struct ipc_namespace *ns)
 {
-       struct shmid_kernel *shp;
-       struct kern_ipc_perm *perm;
-       int next_id;
-       int total, in_use;
-
-       down_write(&shm_ids(ns).rw_mutex);
-
-       in_use = shm_ids(ns).in_use;
-
-       for (total = 0, next_id = 0; total < in_use; next_id++) {
-               perm = idr_find(&shm_ids(ns).ipcs_idr, next_id);
-               if (perm == NULL)
-                       continue;
-               ipc_lock_by_ptr(perm);
-               shp = container_of(perm, struct shmid_kernel, shm_perm);
-               do_shm_rmid(ns, shp);
-               total++;
-       }
-       up_write(&shm_ids(ns).rw_mutex);
-
-       kfree(ns->ids[IPC_SHM_IDS]);
-       ns->ids[IPC_SHM_IDS] = NULL;
+       free_ipcs(ns, &shm_ids(ns), do_shm_rmid);
 }
+#endif
 
 void __init shm_init (void)
 {
-       __shm_init_ns(&init_ipc_ns, &init_shm_ids);
+       shm_init_ns(&init_ipc_ns);
        ipc_init_proc_interface("sysvipc/shm",
                                "       key      shmid perms       size  cpid  lpid nattch   uid   gid  cuid  cgid      atime      dtime      ctime\n",
                                IPC_SHM_IDS, sysvipc_shm_proc_show);
@@ -847,7 +817,7 @@ asmlinkage long sys_shmctl (int shmid, int cmd, struct shmid_ds __user *buf)
                if (err)
                        goto out_unlock_up;
 
-               do_shm_rmid(ns, shp);
+               do_shm_rmid(ns, &shp->shm_perm);
                up_write(&shm_ids(ns).rw_mutex);
                goto out;
        }
index 76c1f3461e22603496652242299af80d0e17d860..fd1b50da9db8858793a11c0e6c503fb523280786 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/audit.h>
 #include <linux/nsproxy.h>
 #include <linux/rwsem.h>
+#include <linux/ipc_namespace.h>
 
 #include <asm/unistd.h>
 
@@ -51,66 +52,6 @@ struct ipc_namespace init_ipc_ns = {
        },
 };
 
-static struct ipc_namespace *clone_ipc_ns(struct ipc_namespace *old_ns)
-{
-       int err;
-       struct ipc_namespace *ns;
-
-       err = -ENOMEM;
-       ns = kmalloc(sizeof(struct ipc_namespace), GFP_KERNEL);
-       if (ns == NULL)
-               goto err_mem;
-
-       err = sem_init_ns(ns);
-       if (err)
-               goto err_sem;
-       err = msg_init_ns(ns);
-       if (err)
-               goto err_msg;
-       err = shm_init_ns(ns);
-       if (err)
-               goto err_shm;
-
-       kref_init(&ns->kref);
-       return ns;
-
-err_shm:
-       msg_exit_ns(ns);
-err_msg:
-       sem_exit_ns(ns);
-err_sem:
-       kfree(ns);
-err_mem:
-       return ERR_PTR(err);
-}
-
-struct ipc_namespace *copy_ipcs(unsigned long flags, struct ipc_namespace *ns)
-{
-       struct ipc_namespace *new_ns;
-
-       BUG_ON(!ns);
-       get_ipc_ns(ns);
-
-       if (!(flags & CLONE_NEWIPC))
-               return ns;
-
-       new_ns = clone_ipc_ns(ns);
-
-       put_ipc_ns(ns);
-       return new_ns;
-}
-
-void free_ipc_ns(struct kref *kref)
-{
-       struct ipc_namespace *ns;
-
-       ns = container_of(kref, struct ipc_namespace, kref);
-       sem_exit_ns(ns);
-       msg_exit_ns(ns);
-       shm_exit_ns(ns);
-       kfree(ns);
-}
-
 /**
  *     ipc_init        -       initialise IPC subsystem
  *
@@ -307,7 +248,7 @@ int ipc_addid(struct ipc_ids* ids, struct kern_ipc_perm* new, int size)
  *     This routine is called by sys_msgget, sys_semget() and sys_shmget()
  *     when the key is IPC_PRIVATE.
  */
-int ipcget_new(struct ipc_namespace *ns, struct ipc_ids *ids,
+static int ipcget_new(struct ipc_namespace *ns, struct ipc_ids *ids,
                struct ipc_ops *ops, struct ipc_params *params)
 {
        int err;
@@ -371,7 +312,7 @@ static int ipc_check_perms(struct kern_ipc_perm *ipcp, struct ipc_ops *ops,
  *
  *     On success, the ipc id is returned.
  */
-int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids,
+static int ipcget_public(struct ipc_namespace *ns, struct ipc_ids *ids,
                struct ipc_ops *ops, struct ipc_params *params)
 {
        struct kern_ipc_perm *ipcp;
@@ -769,6 +710,57 @@ struct kern_ipc_perm *ipc_lock_down(struct ipc_ids *ids, int id)
        return out;
 }
 
+struct kern_ipc_perm *ipc_lock_check_down(struct ipc_ids *ids, int id)
+{
+       struct kern_ipc_perm *out;
+
+       out = ipc_lock_down(ids, id);
+       if (IS_ERR(out))
+               return out;
+
+       if (ipc_checkid(out, id)) {
+               ipc_unlock(out);
+               return ERR_PTR(-EIDRM);
+       }
+
+       return out;
+}
+
+struct kern_ipc_perm *ipc_lock_check(struct ipc_ids *ids, int id)
+{
+       struct kern_ipc_perm *out;
+
+       out = ipc_lock(ids, id);
+       if (IS_ERR(out))
+               return out;
+
+       if (ipc_checkid(out, id)) {
+               ipc_unlock(out);
+               return ERR_PTR(-EIDRM);
+       }
+
+       return out;
+}
+
+/**
+ * ipcget - Common sys_*get() code
+ * @ns : namsepace
+ * @ids : IPC identifier set
+ * @ops : operations to be called on ipc object creation, permission checks
+ *        and further checks
+ * @params : the parameters needed by the previous operations.
+ *
+ * Common routine called by sys_msgget(), sys_semget() and sys_shmget().
+ */
+int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids,
+                       struct ipc_ops *ops, struct ipc_params *params)
+{
+       if (params->key == IPC_PRIVATE)
+               return ipcget_new(ns, ids, ops, params);
+       else
+               return ipcget_public(ns, ids, ops, params);
+}
+
 #ifdef __ARCH_WANT_IPC_PARSE_VERSION
 
 
@@ -841,7 +833,7 @@ static void *sysvipc_proc_next(struct seq_file *s, void *it, loff_t *pos)
        if (ipc && ipc != SEQ_START_TOKEN)
                ipc_unlock(ipc);
 
-       return sysvipc_find_ipc(iter->ns->ids[iface->ids], *pos, pos);
+       return sysvipc_find_ipc(&iter->ns->ids[iface->ids], *pos, pos);
 }
 
 /*
@@ -854,7 +846,7 @@ static void *sysvipc_proc_start(struct seq_file *s, loff_t *pos)
        struct ipc_proc_iface *iface = iter->iface;
        struct ipc_ids *ids;
 
-       ids = iter->ns->ids[iface->ids];
+       ids = &iter->ns->ids[iface->ids];
 
        /*
         * Take the lock - this will be released by the corresponding
@@ -885,7 +877,7 @@ static void sysvipc_proc_stop(struct seq_file *s, void *it)
        if (ipc && ipc != SEQ_START_TOKEN)
                ipc_unlock(ipc);
 
-       ids = iter->ns->ids[iface->ids];
+       ids = &iter->ns->ids[iface->ids];
        /* Release the lock we took in start() */
        up_read(&ids->rw_mutex);
 }
index 9ffea40457cedb17eca4cc9df13ed1b3a5f1a3f7..f37d160c98fe7c5c42b44d9611979a4a79d793fc 100644 (file)
@@ -10,7 +10,6 @@
 #ifndef _IPC_UTIL_H
 #define _IPC_UTIL_H
 
-#include <linux/idr.h>
 #include <linux/err.h>
 
 #define USHRT_MAX 0xffff
@@ -20,22 +19,16 @@ void sem_init (void);
 void msg_init (void);
 void shm_init (void);
 
-int sem_init_ns(struct ipc_namespace *ns);
-int msg_init_ns(struct ipc_namespace *ns);
-int shm_init_ns(struct ipc_namespace *ns);
+struct ipc_namespace;
+
+void sem_init_ns(struct ipc_namespace *ns);
+void msg_init_ns(struct ipc_namespace *ns);
+void shm_init_ns(struct ipc_namespace *ns);
 
 void sem_exit_ns(struct ipc_namespace *ns);
 void msg_exit_ns(struct ipc_namespace *ns);
 void shm_exit_ns(struct ipc_namespace *ns);
 
-struct ipc_ids {
-       int in_use;
-       unsigned short seq;
-       unsigned short seq_max;
-       struct rw_semaphore rw_mutex;
-       struct idr ipcs_idr;
-};
-
 /*
  * Structure that holds the parameters needed by the ipc operations
  * (see after)
@@ -66,6 +59,7 @@ struct ipc_ops {
 };
 
 struct seq_file;
+struct ipc_ids;
 
 void ipc_init_ids(struct ipc_ids *);
 #ifdef CONFIG_PROC_FS
@@ -129,10 +123,6 @@ int ipc_parse_version (int *cmd);
 extern void free_msg(struct msg_msg *msg);
 extern struct msg_msg *load_msg(const void __user *src, int len);
 extern int store_msg(void __user *dest, struct msg_msg *msg, int len);
-extern int ipcget_new(struct ipc_namespace *, struct ipc_ids *,
-                       struct ipc_ops *, struct ipc_params *);
-extern int ipcget_public(struct ipc_namespace *, struct ipc_ids *,
-                       struct ipc_ops *, struct ipc_params *);
 
 static inline int ipc_buildid(int id, int seq)
 {
@@ -161,57 +151,9 @@ static inline void ipc_unlock(struct kern_ipc_perm *perm)
        rcu_read_unlock();
 }
 
-static inline struct kern_ipc_perm *ipc_lock_check_down(struct ipc_ids *ids,
-                                               int id)
-{
-       struct kern_ipc_perm *out;
-
-       out = ipc_lock_down(ids, id);
-       if (IS_ERR(out))
-               return out;
-
-       if (ipc_checkid(out, id)) {
-               ipc_unlock(out);
-               return ERR_PTR(-EIDRM);
-       }
-
-       return out;
-}
-
-static inline struct kern_ipc_perm *ipc_lock_check(struct ipc_ids *ids,
-                                               int id)
-{
-       struct kern_ipc_perm *out;
-
-       out = ipc_lock(ids, id);
-       if (IS_ERR(out))
-               return out;
-
-       if (ipc_checkid(out, id)) {
-               ipc_unlock(out);
-               return ERR_PTR(-EIDRM);
-       }
-
-       return out;
-}
-
-/**
- * ipcget - Common sys_*get() code
- * @ns : namsepace
- * @ids : IPC identifier set
- * @ops : operations to be called on ipc object creation, permission checks
- *        and further checks
- * @params : the parameters needed by the previous operations.
- *
- * Common routine called by sys_msgget(), sys_semget() and sys_shmget().
- */
-static inline int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids,
-                       struct ipc_ops *ops, struct ipc_params *params)
-{
-       if (params->key == IPC_PRIVATE)
-               return ipcget_new(ns, ids, ops, params);
-       else
-               return ipcget_public(ns, ids, ops, params);
-}
+struct kern_ipc_perm *ipc_lock_check_down(struct ipc_ids *ids, int id);
+struct kern_ipc_perm *ipc_lock_check(struct ipc_ids *ids, int id);
+int ipcget(struct ipc_namespace *ns, struct ipc_ids *ids,
+                       struct ipc_ops *ops, struct ipc_params *params);
 
 #endif
index 685697c0a1818bbddeac651cabb4ba14f7fddb54..6c584c55a6e9e8f164fa949b8a5c5ed8054ed9f8 100644 (file)
@@ -4,12 +4,12 @@
 
 obj-y     = sched.o fork.o exec_domain.o panic.o printk.o profile.o \
            exit.o itimer.o time.o softirq.o resource.o \
-           sysctl.o capability.o ptrace.o timer.o user.o user_namespace.o \
+           sysctl.o capability.o ptrace.o timer.o user.o \
            signal.o sys.o kmod.o workqueue.o pid.o \
            rcupdate.o extable.o params.o posix-timers.o \
            kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \
            hrtimer.o rwsem.o nsproxy.o srcu.o \
-           utsname.o notifier.o ksysfs.o pm_qos_params.o
+           notifier.o ksysfs.o pm_qos_params.o
 
 obj-$(CONFIG_SYSCTL) += sysctl_check.o
 obj-$(CONFIG_STACKTRACE) += stacktrace.o
@@ -42,6 +42,9 @@ obj-$(CONFIG_CGROUPS) += cgroup.o
 obj-$(CONFIG_CGROUP_DEBUG) += cgroup_debug.o
 obj-$(CONFIG_CPUSETS) += cpuset.o
 obj-$(CONFIG_CGROUP_NS) += ns_cgroup.o
+obj-$(CONFIG_UTS_NS) += utsname.o
+obj-$(CONFIG_USER_NS) += user_namespace.o
+obj-$(CONFIG_PID_NS) += pid_namespace.o
 obj-$(CONFIG_IKCONFIG) += configs.o
 obj-$(CONFIG_RESOURCE_COUNTERS) += res_counter.o
 obj-$(CONFIG_STOP_MACHINE) += stop_machine.o
@@ -88,3 +91,11 @@ quiet_cmd_ikconfiggz = IKCFG   $@
 targets += config_data.h
 $(obj)/config_data.h: $(obj)/config_data.gz FORCE
        $(call if_changed,ikconfiggz)
+
+$(obj)/time.o: $(obj)/timeconst.h
+
+quiet_cmd_timeconst  = TIMEC   $@
+      cmd_timeconst  = $(PERL) $< $(CONFIG_HZ) > $@
+targets += timeconst.h
+$(obj)/timeconst.h: $(src)/timeconst.pl FORCE
+       $(call if_changed,timeconst)
index e0d3a4f56ecbddb4a4c87c714bc49991fefa2cc2..2eff3f63abed6c91c2bbcb1c8d0eccbb97d54c7d 100644 (file)
@@ -389,7 +389,7 @@ int disable_nonboot_cpus(void)
        return error;
 }
 
-void enable_nonboot_cpus(void)
+void __ref enable_nonboot_cpus(void)
 {
        int cpu, error;
 
index 67b2bfe27814e248fcc481f0f6e2ccd65fb5ba55..3e296ed81d4da76aefa913e7deed8f76f2032087 100644 (file)
@@ -2255,13 +2255,14 @@ const struct file_operations proc_cpuset_operations = {
 #endif /* CONFIG_PROC_PID_CPUSET */
 
 /* Display task cpus_allowed, mems_allowed in /proc/<pid>/status file. */
-char *cpuset_task_status_allowed(struct task_struct *task, char *buffer)
-{
-       buffer += sprintf(buffer, "Cpus_allowed:\t");
-       buffer += cpumask_scnprintf(buffer, PAGE_SIZE, task->cpus_allowed);
-       buffer += sprintf(buffer, "\n");
-       buffer += sprintf(buffer, "Mems_allowed:\t");
-       buffer += nodemask_scnprintf(buffer, PAGE_SIZE, task->mems_allowed);
-       buffer += sprintf(buffer, "\n");
-       return buffer;
+void cpuset_task_status_allowed(struct seq_file *m, struct task_struct *task)
+{
+       seq_printf(m, "Cpus_allowed:\t");
+       m->count += cpumask_scnprintf(m->buf + m->count, m->size - m->count,
+                                       task->cpus_allowed);
+       seq_printf(m, "\n");
+       seq_printf(m, "Mems_allowed:\t");
+       m->count += nodemask_scnprintf(m->buf + m->count, m->size - m->count,
+                                       task->mems_allowed);
+       seq_printf(m, "\n");
 }
index eb9934a82fc1a900f29eb751e520603b82f2492f..3b893e78ce61a09c486f1351249f3d94701e89f5 100644 (file)
@@ -293,26 +293,27 @@ static void reparent_to_kthreadd(void)
        switch_uid(INIT_USER);
 }
 
-void __set_special_pids(pid_t session, pid_t pgrp)
+void __set_special_pids(struct pid *pid)
 {
        struct task_struct *curr = current->group_leader;
+       pid_t nr = pid_nr(pid);
 
-       if (task_session_nr(curr) != session) {
+       if (task_session(curr) != pid) {
                detach_pid(curr, PIDTYPE_SID);
-               set_task_session(curr, session);
-               attach_pid(curr, PIDTYPE_SID, find_pid(session));
+               attach_pid(curr, PIDTYPE_SID, pid);
+               set_task_session(curr, nr);
        }
-       if (task_pgrp_nr(curr) != pgrp) {
+       if (task_pgrp(curr) != pid) {
                detach_pid(curr, PIDTYPE_PGID);
-               set_task_pgrp(curr, pgrp);
-               attach_pid(curr, PIDTYPE_PGID, find_pid(pgrp));
+               attach_pid(curr, PIDTYPE_PGID, pid);
+               set_task_pgrp(curr, nr);
        }
 }
 
-static void set_special_pids(pid_t session, pid_t pgrp)
+static void set_special_pids(struct pid *pid)
 {
        write_lock_irq(&tasklist_lock);
-       __set_special_pids(session, pgrp);
+       __set_special_pids(pid);
        write_unlock_irq(&tasklist_lock);
 }
 
@@ -383,7 +384,11 @@ void daemonize(const char *name, ...)
         */
        current->flags |= PF_NOFREEZE;
 
-       set_special_pids(1, 1);
+       if (current->nsproxy != &init_nsproxy) {
+               get_nsproxy(&init_nsproxy);
+               switch_task_namespaces(current, &init_nsproxy);
+       }
+       set_special_pids(&init_struct_pid);
        proc_clear_tty(current);
 
        /* Block and flush all signals */
@@ -398,11 +403,6 @@ void daemonize(const char *name, ...)
        current->fs = fs;
        atomic_inc(&fs->count);
 
-       if (current->nsproxy != init_task.nsproxy) {
-               get_nsproxy(init_task.nsproxy);
-               switch_task_namespaces(current, init_task.nsproxy);
-       }
-
        exit_files(current);
        current->files = init_task.files;
        atomic_inc(&current->files->count);
@@ -458,7 +458,7 @@ struct files_struct *get_files_struct(struct task_struct *task)
        return files;
 }
 
-void fastcall put_files_struct(struct files_struct *files)
+void put_files_struct(struct files_struct *files)
 {
        struct fdtable *fdt;
 
@@ -745,24 +745,6 @@ static void exit_notify(struct task_struct *tsk)
        struct task_struct *t;
        struct pid *pgrp;
 
-       if (signal_pending(tsk) && !(tsk->signal->flags & SIGNAL_GROUP_EXIT)
-           && !thread_group_empty(tsk)) {
-               /*
-                * This occurs when there was a race between our exit
-                * syscall and a group signal choosing us as the one to
-                * wake up.  It could be that we are the only thread
-                * alerted to check for pending signals, but another thread
-                * should be woken now to take the signal since we will not.
-                * Now we'll wake all the threads in the group just to make
-                * sure someone gets all the pending signals.
-                */
-               spin_lock_irq(&tsk->sighand->siglock);
-               for (t = next_thread(tsk); t != tsk; t = next_thread(t))
-                       if (!signal_pending(t) && !(t->flags & PF_EXITING))
-                               recalc_sigpending_and_wake(t);
-               spin_unlock_irq(&tsk->sighand->siglock);
-       }
-
        /*
         * This does two things:
         *
@@ -905,7 +887,7 @@ static inline void exit_child_reaper(struct task_struct *tsk)
        zap_pid_ns_processes(tsk->nsproxy->pid_ns);
 }
 
-fastcall NORET_TYPE void do_exit(long code)
+NORET_TYPE void do_exit(long code)
 {
        struct task_struct *tsk = current;
        int group_dead;
@@ -947,7 +929,7 @@ fastcall NORET_TYPE void do_exit(long code)
                schedule();
        }
 
-       tsk->flags |= PF_EXITING;
+       exit_signals(tsk);  /* sets PF_EXITING */
        /*
         * tsk->flags are checked in the futex code to protect against
         * an exiting task cleaning up the robust pi futexes.
@@ -1108,20 +1090,23 @@ asmlinkage void sys_exit_group(int error_code)
        do_group_exit((error_code & 0xff) << 8);
 }
 
-static int eligible_child(pid_t pid, int options, struct task_struct *p)
+static struct pid *task_pid_type(struct task_struct *task, enum pid_type type)
+{
+       struct pid *pid = NULL;
+       if (type == PIDTYPE_PID)
+               pid = task->pids[type].pid;
+       else if (type < PIDTYPE_MAX)
+               pid = task->group_leader->pids[type].pid;
+       return pid;
+}
+
+static int eligible_child(enum pid_type type, struct pid *pid, int options,
+                         struct task_struct *p)
 {
        int err;
-       struct pid_namespace *ns;
 
-       ns = current->nsproxy->pid_ns;
-       if (pid > 0) {
-               if (task_pid_nr_ns(p, ns) != pid)
-                       return 0;
-       } else if (!pid) {
-               if (task_pgrp_nr_ns(p, ns) != task_pgrp_vnr(current))
-                       return 0;
-       } else if (pid != -1) {
-               if (task_pgrp_nr_ns(p, ns) != -pid)
+       if (type < PIDTYPE_MAX) {
+               if (task_pid_type(p, type) != pid)
                        return 0;
        }
 
@@ -1140,18 +1125,16 @@ static int eligible_child(pid_t pid, int options, struct task_struct *p)
        if (((p->exit_signal != SIGCHLD) ^ ((options & __WCLONE) != 0))
            && !(options & __WALL))
                return 0;
-       /*
-        * Do not consider thread group leaders that are
-        * in a non-empty thread group:
-        */
-       if (delay_group_leader(p))
-               return 2;
 
        err = security_task_wait(p);
-       if (err)
-               return err;
+       if (likely(!err))
+               return 1;
 
-       return 1;
+       if (type != PIDTYPE_PID)
+               return 0;
+       /* This child was explicitly requested, abort */
+       read_unlock(&tasklist_lock);
+       return err;
 }
 
 static int wait_noreap_copyout(struct task_struct *p, pid_t pid, uid_t uid,
@@ -1191,20 +1174,13 @@ static int wait_task_zombie(struct task_struct *p, int noreap,
 {
        unsigned long state;
        int retval, status, traced;
-       struct pid_namespace *ns;
-
-       ns = current->nsproxy->pid_ns;
+       pid_t pid = task_pid_vnr(p);
 
        if (unlikely(noreap)) {
-               pid_t pid = task_pid_nr_ns(p, ns);
                uid_t uid = p->uid;
                int exit_code = p->exit_code;
                int why, status;
 
-               if (unlikely(p->exit_state != EXIT_ZOMBIE))
-                       return 0;
-               if (unlikely(p->exit_signal == -1 && p->ptrace == 0))
-                       return 0;
                get_task_struct(p);
                read_unlock(&tasklist_lock);
                if ((exit_code & 0x7f) == 0) {
@@ -1315,11 +1291,11 @@ static int wait_task_zombie(struct task_struct *p, int noreap,
                        retval = put_user(status, &infop->si_status);
        }
        if (!retval && infop)
-               retval = put_user(task_pid_nr_ns(p, ns), &infop->si_pid);
+               retval = put_user(pid, &infop->si_pid);
        if (!retval && infop)
                retval = put_user(p->uid, &infop->si_uid);
        if (!retval)
-               retval = task_pid_nr_ns(p, ns);
+               retval = pid;
 
        if (traced) {
                write_lock_irq(&tasklist_lock);
@@ -1351,21 +1327,38 @@ static int wait_task_zombie(struct task_struct *p, int noreap,
  * the lock and this task is uninteresting.  If we return nonzero, we have
  * released the lock and the system call should return.
  */
-static int wait_task_stopped(struct task_struct *p, int delayed_group_leader,
+static int wait_task_stopped(struct task_struct *p,
                             int noreap, struct siginfo __user *infop,
                             int __user *stat_addr, struct rusage __user *ru)
 {
-       int retval, exit_code;
+       int retval, exit_code, why;
+       uid_t uid = 0; /* unneeded, required by compiler */
        pid_t pid;
 
-       if (!p->exit_code)
-               return 0;
-       if (delayed_group_leader && !(p->ptrace & PT_PTRACED) &&
-           p->signal->group_stop_count > 0)
+       exit_code = 0;
+       spin_lock_irq(&p->sighand->siglock);
+
+       if (unlikely(!task_is_stopped_or_traced(p)))
+               goto unlock_sig;
+
+       if (!(p->ptrace & PT_PTRACED) && p->signal->group_stop_count > 0)
                /*
                 * A group stop is in progress and this is the group leader.
                 * We won't report until all threads have stopped.
                 */
+               goto unlock_sig;
+
+       exit_code = p->exit_code;
+       if (!exit_code)
+               goto unlock_sig;
+
+       if (!noreap)
+               p->exit_code = 0;
+
+       uid = p->uid;
+unlock_sig:
+       spin_unlock_irq(&p->sighand->siglock);
+       if (!exit_code)
                return 0;
 
        /*
@@ -1375,65 +1368,15 @@ static int wait_task_stopped(struct task_struct *p, int delayed_group_leader,
         * keep holding onto the tasklist_lock while we call getrusage and
         * possibly take page faults for user memory.
         */
-       pid = task_pid_nr_ns(p, current->nsproxy->pid_ns);
        get_task_struct(p);
+       pid = task_pid_vnr(p);
+       why = (p->ptrace & PT_PTRACED) ? CLD_TRAPPED : CLD_STOPPED;
        read_unlock(&tasklist_lock);
 
-       if (unlikely(noreap)) {
-               uid_t uid = p->uid;
-               int why = (p->ptrace & PT_PTRACED) ? CLD_TRAPPED : CLD_STOPPED;
-
-               exit_code = p->exit_code;
-               if (unlikely(!exit_code) || unlikely(p->exit_state))
-                       goto bail_ref;
+       if (unlikely(noreap))
                return wait_noreap_copyout(p, pid, uid,
                                           why, exit_code,
                                           infop, ru);
-       }
-
-       write_lock_irq(&tasklist_lock);
-
-       /*
-        * This uses xchg to be atomic with the thread resuming and setting
-        * it.  It must also be done with the write lock held to prevent a
-        * race with the EXIT_ZOMBIE case.
-        */
-       exit_code = xchg(&p->exit_code, 0);
-       if (unlikely(p->exit_state)) {
-               /*
-                * The task resumed and then died.  Let the next iteration
-                * catch it in EXIT_ZOMBIE.  Note that exit_code might
-                * already be zero here if it resumed and did _exit(0).
-                * The task itself is dead and won't touch exit_code again;
-                * other processors in this function are locked out.
-                */
-               p->exit_code = exit_code;
-               exit_code = 0;
-       }
-       if (unlikely(exit_code == 0)) {
-               /*
-                * Another thread in this function got to it first, or it
-                * resumed, or it resumed and then died.
-                */
-               write_unlock_irq(&tasklist_lock);
-bail_ref:
-               put_task_struct(p);
-               /*
-                * We are returning to the wait loop without having successfully
-                * removed the process and having released the lock. We cannot
-                * continue, since the "p" task pointer is potentially stale.
-                *
-                * Return -EAGAIN, and do_wait() will restart the loop from the
-                * beginning. Do _not_ re-acquire the lock.
-                */
-               return -EAGAIN;
-       }
-
-       /* move to end of parent's list to avoid starvation */
-       remove_parent(p);
-       add_parent(p);
-
-       write_unlock_irq(&tasklist_lock);
 
        retval = ru ? getrusage(p, RUSAGE_BOTH, ru) : 0;
        if (!retval && stat_addr)
@@ -1443,15 +1386,13 @@ bail_ref:
        if (!retval && infop)
                retval = put_user(0, &infop->si_errno);
        if (!retval && infop)
-               retval = put_user((short)((p->ptrace & PT_PTRACED)
-                                         ? CLD_TRAPPED : CLD_STOPPED),
-                                 &infop->si_code);
+               retval = put_user(why, &infop->si_code);
        if (!retval && infop)
                retval = put_user(exit_code, &infop->si_status);
        if (!retval && infop)
                retval = put_user(pid, &infop->si_pid);
        if (!retval && infop)
-               retval = put_user(p->uid, &infop->si_uid);
+               retval = put_user(uid, &infop->si_uid);
        if (!retval)
                retval = pid;
        put_task_struct(p);
@@ -1473,7 +1414,6 @@ static int wait_task_continued(struct task_struct *p, int noreap,
        int retval;
        pid_t pid;
        uid_t uid;
-       struct pid_namespace *ns;
 
        if (!(p->signal->flags & SIGNAL_STOP_CONTINUED))
                return 0;
@@ -1488,8 +1428,7 @@ static int wait_task_continued(struct task_struct *p, int noreap,
                p->signal->flags &= ~SIGNAL_STOP_CONTINUED;
        spin_unlock_irq(&p->sighand->siglock);
 
-       ns = current->nsproxy->pid_ns;
-       pid = task_pid_nr_ns(p, ns);
+       pid = task_pid_vnr(p);
        uid = p->uid;
        get_task_struct(p);
        read_unlock(&tasklist_lock);
@@ -1500,7 +1439,7 @@ static int wait_task_continued(struct task_struct *p, int noreap,
                if (!retval && stat_addr)
                        retval = put_user(0xffff, stat_addr);
                if (!retval)
-                       retval = task_pid_nr_ns(p, ns);
+                       retval = pid;
        } else {
                retval = wait_noreap_copyout(p, pid, uid,
                                             CLD_CONTINUED, SIGCONT,
@@ -1511,101 +1450,63 @@ static int wait_task_continued(struct task_struct *p, int noreap,
        return retval;
 }
 
-
-static inline int my_ptrace_child(struct task_struct *p)
-{
-       if (!(p->ptrace & PT_PTRACED))
-               return 0;
-       if (!(p->ptrace & PT_ATTACHED))
-               return 1;
-       /*
-        * This child was PTRACE_ATTACH'd.  We should be seeing it only if
-        * we are the attacher.  If we are the real parent, this is a race
-        * inside ptrace_attach.  It is waiting for the tasklist_lock,
-        * which we have to switch the parent links, but has already set
-        * the flags in p->ptrace.
-        */
-       return (p->parent != p->real_parent);
-}
-
-static long do_wait(pid_t pid, int options, struct siginfo __user *infop,
-                   int __user *stat_addr, struct rusage __user *ru)
+static long do_wait(enum pid_type type, struct pid *pid, int options,
+                   struct siginfo __user *infop, int __user *stat_addr,
+                   struct rusage __user *ru)
 {
        DECLARE_WAITQUEUE(wait, current);
        struct task_struct *tsk;
        int flag, retval;
-       int allowed, denied;
 
        add_wait_queue(&current->signal->wait_chldexit,&wait);
 repeat:
+       /* If there is nothing that can match our critier just get out */
+       retval = -ECHILD;
+       if ((type < PIDTYPE_MAX) && (!pid || hlist_empty(&pid->tasks[type])))
+               goto end;
+
        /*
         * We will set this flag if we see any child that might later
         * match our criteria, even if we are not able to reap it yet.
         */
-       flag = 0;
-       allowed = denied = 0;
+       flag = retval = 0;
        current->state = TASK_INTERRUPTIBLE;
        read_lock(&tasklist_lock);
        tsk = current;
        do {
                struct task_struct *p;
-               int ret;
 
                list_for_each_entry(p, &tsk->children, sibling) {
-                       ret = eligible_child(pid, options, p);
+                       int ret = eligible_child(type, pid, options, p);
                        if (!ret)
                                continue;
 
                        if (unlikely(ret < 0)) {
-                               denied = ret;
-                               continue;
-                       }
-                       allowed = 1;
-
-                       if (task_is_stopped_or_traced(p)) {
+                               retval = ret;
+                       } else if (task_is_stopped_or_traced(p)) {
                                /*
                                 * It's stopped now, so it might later
                                 * continue, exit, or stop again.
-                                *
-                                * When we hit the race with PTRACE_ATTACH, we
-                                * will not report this child.  But the race
-                                * means it has not yet been moved to our
-                                * ptrace_children list, so we need to set the
-                                * flag here to avoid a spurious ECHILD when
-                                * the race happens with the only child.
                                 */
                                flag = 1;
+                               if (!(p->ptrace & PT_PTRACED) &&
+                                   !(options & WUNTRACED))
+                                       continue;
 
-                               if (!my_ptrace_child(p)) {
-                                       if (task_is_traced(p))
-                                               continue;
-                                       if (!(options & WUNTRACED))
-                                               continue;
-                               }
-
-                               retval = wait_task_stopped(p, ret == 2,
+                               retval = wait_task_stopped(p,
                                                (options & WNOWAIT), infop,
                                                stat_addr, ru);
-                               if (retval == -EAGAIN)
-                                       goto repeat;
-                               if (retval != 0) /* He released the lock.  */
-                                       goto end;
-                       } else if (p->exit_state == EXIT_ZOMBIE) {
+                       } else if (p->exit_state == EXIT_ZOMBIE &&
+                                       !delay_group_leader(p)) {
                                /*
-                                * Eligible but we cannot release it yet:
+                                * We don't reap group leaders with subthreads.
                                 */
-                               if (ret == 2)
-                                       goto check_continued;
                                if (!likely(options & WEXITED))
                                        continue;
                                retval = wait_task_zombie(p,
                                                (options & WNOWAIT), infop,
                                                stat_addr, ru);
-                               /* He released the lock.  */
-                               if (retval != 0)
-                                       goto end;
                        } else if (p->exit_state != EXIT_DEAD) {
-check_continued:
                                /*
                                 * It's running now, so it might later
                                 * exit, stop, or stop and then continue.
@@ -1616,17 +1517,20 @@ check_continued:
                                retval = wait_task_continued(p,
                                                (options & WNOWAIT), infop,
                                                stat_addr, ru);
-                               if (retval != 0) /* He released the lock.  */
-                                       goto end;
                        }
+                       if (retval != 0) /* tasklist_lock released */
+                               goto end;
                }
                if (!flag) {
                        list_for_each_entry(p, &tsk->ptrace_children,
-                                           ptrace_list) {
-                               if (!eligible_child(pid, options, p))
+                                                               ptrace_list) {
+                               flag = eligible_child(type, pid, options, p);
+                               if (!flag)
                                        continue;
-                               flag = 1;
-                               break;
+                               if (likely(flag > 0))
+                                       break;
+                               retval = flag;
+                               goto end;
                        }
                }
                if (options & __WNOTHREAD)
@@ -1634,10 +1538,9 @@ check_continued:
                tsk = next_thread(tsk);
                BUG_ON(tsk->signal != current->signal);
        } while (tsk != current);
-
        read_unlock(&tasklist_lock);
+
        if (flag) {
-               retval = 0;
                if (options & WNOHANG)
                        goto end;
                retval = -ERESTARTSYS;
@@ -1647,14 +1550,12 @@ check_continued:
                goto repeat;
        }
        retval = -ECHILD;
-       if (unlikely(denied) && !allowed)
-               retval = denied;
 end:
        current->state = TASK_RUNNING;
        remove_wait_queue(&current->signal->wait_chldexit,&wait);
        if (infop) {
                if (retval > 0)
-               retval = 0;
+                       retval = 0;
                else {
                        /*
                         * For a WNOHANG return, clear out all the fields
@@ -1678,10 +1579,12 @@ end:
        return retval;
 }
 
-asmlinkage long sys_waitid(int which, pid_t pid,
+asmlinkage long sys_waitid(int which, pid_t upid,
                           struct siginfo __user *infop, int options,
                           struct rusage __user *ru)
 {
+       struct pid *pid = NULL;
+       enum pid_type type;
        long ret;
 
        if (options & ~(WNOHANG|WNOWAIT|WEXITED|WSTOPPED|WCONTINUED))
@@ -1691,37 +1594,58 @@ asmlinkage long sys_waitid(int which, pid_t pid,
 
        switch (which) {
        case P_ALL:
-               pid = -1;
+               type = PIDTYPE_MAX;
                break;
        case P_PID:
-               if (pid <= 0)
+               type = PIDTYPE_PID;
+               if (upid <= 0)
                        return -EINVAL;
                break;
        case P_PGID:
-               if (pid <= 0)
+               type = PIDTYPE_PGID;
+               if (upid <= 0)
                        return -EINVAL;
-               pid = -pid;
                break;
        default:
                return -EINVAL;
        }
 
-       ret = do_wait(pid, options, infop, NULL, ru);
+       if (type < PIDTYPE_MAX)
+               pid = find_get_pid(upid);
+       ret = do_wait(type, pid, options, infop, NULL, ru);
+       put_pid(pid);
 
        /* avoid REGPARM breakage on x86: */
        prevent_tail_call(ret);
        return ret;
 }
 
-asmlinkage long sys_wait4(pid_t pid, int __user *stat_addr,
+asmlinkage long sys_wait4(pid_t upid, int __user *stat_addr,
                          int options, struct rusage __user *ru)
 {
+       struct pid *pid = NULL;
+       enum pid_type type;
        long ret;
 
        if (options & ~(WNOHANG|WUNTRACED|WCONTINUED|
                        __WNOTHREAD|__WCLONE|__WALL))
                return -EINVAL;
-       ret = do_wait(pid, options | WEXITED, NULL, stat_addr, ru);
+
+       if (upid == -1)
+               type = PIDTYPE_MAX;
+       else if (upid < 0) {
+               type = PIDTYPE_PGID;
+               pid = find_get_pid(-upid);
+       } else if (upid == 0) {
+               type = PIDTYPE_PGID;
+               pid = get_pid(task_pgrp(current));
+       } else /* upid > 0 */ {
+               type = PIDTYPE_PID;
+               pid = find_get_pid(upid);
+       }
+
+       ret = do_wait(type, pid, options | WEXITED, NULL, stat_addr, ru);
+       put_pid(pid);
 
        /* avoid REGPARM breakage on x86: */
        prevent_tail_call(ret);
index b2ef8e4fad70da87632b315f3be76f829371c99b..4363a4eb84e329db0c34617152cb6a452ed8cab4 100644 (file)
@@ -390,7 +390,7 @@ struct mm_struct * mm_alloc(void)
  * is dropped: either by a lazy thread or by
  * mmput. Free the page directory and the mm.
  */
-void fastcall __mmdrop(struct mm_struct *mm)
+void __mmdrop(struct mm_struct *mm)
 {
        BUG_ON(mm == &init_mm);
        mm_free_pgd(mm);
@@ -909,7 +909,6 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk)
        hrtimer_init(&sig->real_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
        sig->it_real_incr.tv64 = 0;
        sig->real_timer.function = it_real_fn;
-       sig->tsk = tsk;
 
        sig->it_virt_expires = cputime_zero;
        sig->it_virt_incr = cputime_zero;
@@ -1338,6 +1337,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
                        if (clone_flags & CLONE_NEWPID)
                                p->nsproxy->pid_ns->child_reaper = p;
 
+                       p->signal->leader_pid = pid;
                        p->signal->tty = current->signal->tty;
                        set_task_pgrp(p, task_pgrp_nr(current));
                        set_task_session(p, task_session_nr(current));
@@ -1488,13 +1488,7 @@ long do_fork(unsigned long clone_flags,
        if (!IS_ERR(p)) {
                struct completion vfork;
 
-               /*
-                * this is enough to call pid_nr_ns here, but this if
-                * improves optimisation of regular fork()
-                */
-               nr = (clone_flags & CLONE_NEWPID) ?
-                       task_pid_nr_ns(p, current->nsproxy->pid_ns) :
-                               task_pid_vnr(p);
+               nr = task_pid_vnr(p);
 
                if (clone_flags & CLONE_PARENT_SETTID)
                        put_user(nr, parent_tidptr);
index 44019ce30a14213991a73c61c852073d4d6c8112..cc54c627635653e7210706c691cedaef2652e0dc 100644 (file)
@@ -286,7 +286,7 @@ static inline void mask_ack_irq(struct irq_desc *desc, int irq)
  *     Note: The caller is expected to handle the ack, clear, mask and
  *     unmask issues if necessary.
  */
-void fastcall
+void
 handle_simple_irq(unsigned int irq, struct irq_desc *desc)
 {
        struct irqaction *action;
@@ -327,7 +327,7 @@ out_unlock:
  *     it after the associated handler has acknowledged the device, so the
  *     interrupt line is back to inactive.
  */
-void fastcall
+void
 handle_level_irq(unsigned int irq, struct irq_desc *desc)
 {
        unsigned int cpu = smp_processor_id();
@@ -375,7 +375,7 @@ out_unlock:
  *     for modern forms of interrupt handlers, which handle the flow
  *     details in hardware, transparently.
  */
-void fastcall
+void
 handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
 {
        unsigned int cpu = smp_processor_id();
@@ -434,7 +434,7 @@ out:
  *     the handler was running. If all pending interrupts are handled, the
  *     loop is left.
  */
-void fastcall
+void
 handle_edge_irq(unsigned int irq, struct irq_desc *desc)
 {
        const unsigned int cpu = smp_processor_id();
@@ -505,7 +505,7 @@ out_unlock:
  *
  *     Per CPU interrupts on SMP machines without locking requirements
  */
-void fastcall
+void
 handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
 {
        irqreturn_t action_ret;
@@ -589,3 +589,39 @@ set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
        set_irq_chip(irq, chip);
        __set_irq_handler(irq, handle, 0, name);
 }
+
+void __init set_irq_noprobe(unsigned int irq)
+{
+       struct irq_desc *desc;
+       unsigned long flags;
+
+       if (irq >= NR_IRQS) {
+               printk(KERN_ERR "Trying to mark IRQ%d non-probeable\n", irq);
+
+               return;
+       }
+
+       desc = irq_desc + irq;
+
+       spin_lock_irqsave(&desc->lock, flags);
+       desc->status |= IRQ_NOPROBE;
+       spin_unlock_irqrestore(&desc->lock, flags);
+}
+
+void __init set_irq_probe(unsigned int irq)
+{
+       struct irq_desc *desc;
+       unsigned long flags;
+
+       if (irq >= NR_IRQS) {
+               printk(KERN_ERR "Trying to mark IRQ%d probeable\n", irq);
+
+               return;
+       }
+
+       desc = irq_desc + irq;
+
+       spin_lock_irqsave(&desc->lock, flags);
+       desc->status &= ~IRQ_NOPROBE;
+       spin_unlock_irqrestore(&desc->lock, flags);
+}
index dc335ad27525f0019d475124322779d6c6ed5f09..5fa6198e91394a935bcb8f51d70cdef9222c261f 100644 (file)
@@ -25,7 +25,7 @@
  *
  * Handles spurious and unhandled IRQ's. It also prints a debugmessage.
  */
-void fastcall
+void
 handle_bad_irq(unsigned int irq, struct irq_desc *desc)
 {
        print_irq_desc(irq, desc);
@@ -163,7 +163,7 @@ irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
  * This is the original x86 implementation which is used for every
  * interrupt type.
  */
-fastcall unsigned int __do_IRQ(unsigned int irq)
+unsigned int __do_IRQ(unsigned int irq)
 {
        struct irq_desc *desc = irq_desc + irq;
        struct irqaction *action;
index 2fab344dbf56c737b39feb3951e822e5911a775b..ab982747d9bd8121c19b3327b96c7760adb7577e 100644 (file)
@@ -132,7 +132,7 @@ enum hrtimer_restart it_real_fn(struct hrtimer *timer)
        struct signal_struct *sig =
                container_of(timer, struct signal_struct, real_timer);
 
-       send_group_sig_info(SIGALRM, SEND_SIG_PRIV, sig->tsk);
+       kill_pid_info(SIGALRM, SEND_SIG_PRIV, sig->leader_pid);
 
        return HRTIMER_NORESTART;
 }
index bd60278ee7035945d1db4dfaed0f26b3c4a457e8..4202da97a1da8c289479880155807d4c1aa5766e 100644 (file)
@@ -46,6 +46,7 @@
 #include <asm/semaphore.h>
 #include <asm/cacheflush.h>
 #include <linux/license.h>
+#include <asm/sections.h>
 
 #if 0
 #define DEBUGP printk
@@ -290,7 +291,7 @@ static unsigned long __find_symbol(const char *name,
                }
        }
        DEBUGP("Failed to find symbol %s\n", name);
-       return 0;
+       return -ENOENT;
 }
 
 /* Search for module by name: must hold module_mutex. */
@@ -343,9 +344,6 @@ static inline unsigned int block_size(int val)
        return val;
 }
 
-/* Created by linker magic */
-extern char __per_cpu_start[], __per_cpu_end[];
-
 static void *percpu_modalloc(unsigned long size, unsigned long align,
                             const char *name)
 {
@@ -783,7 +781,7 @@ void __symbol_put(const char *symbol)
        const unsigned long *crc;
 
        preempt_disable();
-       if (!__find_symbol(symbol, &owner, &crc, 1))
+       if (IS_ERR_VALUE(__find_symbol(symbol, &owner, &crc, 1)))
                BUG();
        module_put(owner);
        preempt_enable();
@@ -929,7 +927,8 @@ static inline int check_modstruct_version(Elf_Shdr *sechdrs,
        const unsigned long *crc;
        struct module *owner;
 
-       if (!__find_symbol("struct_module", &owner, &crc, 1))
+       if (IS_ERR_VALUE(__find_symbol("struct_module",
+                                               &owner, &crc, 1)))
                BUG();
        return check_version(sechdrs, versindex, "struct_module", mod,
                             crc);
@@ -978,12 +977,12 @@ static unsigned long resolve_symbol(Elf_Shdr *sechdrs,
 
        ret = __find_symbol(name, &owner, &crc,
                        !(mod->taints & TAINT_PROPRIETARY_MODULE));
-       if (ret) {
+       if (!IS_ERR_VALUE(ret)) {
                /* use_module can fail due to OOM,
                   or module initialization or unloading */
                if (!check_version(sechdrs, versindex, name, mod, crc) ||
                    !use_module(mod, owner))
-                       ret = 0;
+                       ret = -EINVAL;
        }
        return ret;
 }
@@ -1371,7 +1370,9 @@ void *__symbol_get(const char *symbol)
 
        preempt_disable();
        value = __find_symbol(symbol, &owner, &crc, 1);
-       if (value && strong_try_module_get(owner) != 0)
+       if (IS_ERR_VALUE(value))
+               value = 0;
+       else if (strong_try_module_get(owner))
                value = 0;
        preempt_enable();
 
@@ -1391,14 +1392,16 @@ static int verify_export_symbols(struct module *mod)
        const unsigned long *crc;
 
        for (i = 0; i < mod->num_syms; i++)
-               if (__find_symbol(mod->syms[i].name, &owner, &crc, 1)) {
+               if (!IS_ERR_VALUE(__find_symbol(mod->syms[i].name,
+                                                       &owner, &crc, 1))) {
                        name = mod->syms[i].name;
                        ret = -ENOEXEC;
                        goto dup;
                }
 
        for (i = 0; i < mod->num_gpl_syms; i++)
-               if (__find_symbol(mod->gpl_syms[i].name, &owner, &crc, 1)) {
+               if (!IS_ERR_VALUE(__find_symbol(mod->gpl_syms[i].name,
+                                                       &owner, &crc, 1))) {
                        name = mod->gpl_syms[i].name;
                        ret = -ENOEXEC;
                        goto dup;
@@ -1448,7 +1451,7 @@ static int simplify_symbols(Elf_Shdr *sechdrs,
                                           strtab + sym[i].st_name, mod);
 
                        /* Ok if resolved.  */
-                       if (sym[i].st_value != 0)
+                       if (!IS_ERR_VALUE(sym[i].st_value))
                                break;
                        /* Ok if weak.  */
                        if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK)
@@ -2250,7 +2253,7 @@ static const char *get_ksymbol(struct module *mod,
 
 /* For kallsyms to ask for address resolution.  NULL means not found.  Careful
  * not to lock to avoid deadlock on oopses, simply disable preemption. */
-char *module_address_lookup(unsigned long addr,
+const char *module_address_lookup(unsigned long addr,
                            unsigned long *size,
                            unsigned long *offset,
                            char **modname,
@@ -2275,7 +2278,7 @@ char *module_address_lookup(unsigned long addr,
                ret = namebuf;
        }
        preempt_enable();
-       return (char *)ret;
+       return ret;
 }
 
 int lookup_module_symbol_name(unsigned long addr, char *symname)
index d17436cdea1b39a7cb0efc96801bf0655dcb8fb5..3aaa06c561deba97838d6fab2cb66229e2a3e686 100644 (file)
@@ -107,7 +107,7 @@ void debug_mutex_init(struct mutex *lock, const char *name,
  * use of the mutex is forbidden. The mutex must not be locked when
  * this function is called.
  */
-void fastcall mutex_destroy(struct mutex *lock)
+void mutex_destroy(struct mutex *lock)
 {
        DEBUG_LOCKS_WARN_ON(mutex_is_locked(lock));
        lock->magic = NULL;
index d9ec9b6662501e0c5815f61812ad1f42e8b79d1c..d046a345d365793e84076e2517ec02cdd11bc40d 100644 (file)
@@ -58,7 +58,7 @@ EXPORT_SYMBOL(__mutex_init);
  * We also put the fastpath first in the kernel image, to make sure the
  * branch is predicted by the CPU as default-untaken.
  */
-static void fastcall noinline __sched
+static void noinline __sched
 __mutex_lock_slowpath(atomic_t *lock_count);
 
 /***
@@ -82,7 +82,7 @@ __mutex_lock_slowpath(atomic_t *lock_count);
  *
  * This function is similar to (but not equivalent to) down().
  */
-void inline fastcall __sched mutex_lock(struct mutex *lock)
+void inline __sched mutex_lock(struct mutex *lock)
 {
        might_sleep();
        /*
@@ -95,8 +95,7 @@ void inline fastcall __sched mutex_lock(struct mutex *lock)
 EXPORT_SYMBOL(mutex_lock);
 #endif
 
-static void fastcall noinline __sched
-__mutex_unlock_slowpath(atomic_t *lock_count);
+static noinline void __sched __mutex_unlock_slowpath(atomic_t *lock_count);
 
 /***
  * mutex_unlock - release the mutex
@@ -109,7 +108,7 @@ __mutex_unlock_slowpath(atomic_t *lock_count);
  *
  * This function is similar to (but not equivalent to) up().
  */
-void fastcall __sched mutex_unlock(struct mutex *lock)
+void __sched mutex_unlock(struct mutex *lock)
 {
        /*
         * The unlocking fastpath is the 0->1 transition from 'locked'
@@ -234,7 +233,7 @@ EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested);
 /*
  * Release the lock, slowpath:
  */
-static fastcall inline void
+static inline void
 __mutex_unlock_common_slowpath(atomic_t *lock_count, int nested)
 {
        struct mutex *lock = container_of(lock_count, struct mutex, count);
@@ -271,7 +270,7 @@ __mutex_unlock_common_slowpath(atomic_t *lock_count, int nested)
 /*
  * Release the lock, slowpath:
  */
-static fastcall noinline void
+static noinline void
 __mutex_unlock_slowpath(atomic_t *lock_count)
 {
        __mutex_unlock_common_slowpath(lock_count, 1);
@@ -282,10 +281,10 @@ __mutex_unlock_slowpath(atomic_t *lock_count)
  * Here come the less common (and hence less performance-critical) APIs:
  * mutex_lock_interruptible() and mutex_trylock().
  */
-static int fastcall noinline __sched
+static noinline int __sched
 __mutex_lock_killable_slowpath(atomic_t *lock_count);
 
-static noinline int fastcall __sched
+static noinline int __sched
 __mutex_lock_interruptible_slowpath(atomic_t *lock_count);
 
 /***
@@ -299,7 +298,7 @@ __mutex_lock_interruptible_slowpath(atomic_t *lock_count);
  *
  * This function is similar to (but not equivalent to) down_interruptible().
  */
-int fastcall __sched mutex_lock_interruptible(struct mutex *lock)
+int __sched mutex_lock_interruptible(struct mutex *lock)
 {
        might_sleep();
        return __mutex_fastpath_lock_retval
@@ -308,7 +307,7 @@ int fastcall __sched mutex_lock_interruptible(struct mutex *lock)
 
 EXPORT_SYMBOL(mutex_lock_interruptible);
 
-int fastcall __sched mutex_lock_killable(struct mutex *lock)
+int __sched mutex_lock_killable(struct mutex *lock)
 {
        might_sleep();
        return __mutex_fastpath_lock_retval
@@ -316,7 +315,7 @@ int fastcall __sched mutex_lock_killable(struct mutex *lock)
 }
 EXPORT_SYMBOL(mutex_lock_killable);
 
-static void fastcall noinline __sched
+static noinline void __sched
 __mutex_lock_slowpath(atomic_t *lock_count)
 {
        struct mutex *lock = container_of(lock_count, struct mutex, count);
@@ -324,7 +323,7 @@ __mutex_lock_slowpath(atomic_t *lock_count)
        __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0, _RET_IP_);
 }
 
-static int fastcall noinline __sched
+static noinline int __sched
 __mutex_lock_killable_slowpath(atomic_t *lock_count)
 {
        struct mutex *lock = container_of(lock_count, struct mutex, count);
@@ -332,7 +331,7 @@ __mutex_lock_killable_slowpath(atomic_t *lock_count)
        return __mutex_lock_common(lock, TASK_KILLABLE, 0, _RET_IP_);
 }
 
-static noinline int fastcall __sched
+static noinline int __sched
 __mutex_lock_interruptible_slowpath(atomic_t *lock_count)
 {
        struct mutex *lock = container_of(lock_count, struct mutex, count);
@@ -381,7 +380,7 @@ static inline int __mutex_trylock_slowpath(atomic_t *lock_count)
  * This function must not be used in interrupt context. The
  * mutex must be released by the same task that acquired it.
  */
-int fastcall __sched mutex_trylock(struct mutex *lock)
+int __sched mutex_trylock(struct mutex *lock)
 {
        return __mutex_fastpath_trylock(&lock->count,
                                        __mutex_trylock_slowpath);
index 79f871bc0ef40026e111df575622cbc6b11031c3..f5d332cf8c631704b1ee440c35317644e4f6eff9 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/utsname.h>
 #include <linux/pid_namespace.h>
 #include <net/net_namespace.h>
+#include <linux/ipc_namespace.h>
 
 static struct kmem_cache *nsproxy_cachep;
 
index e28c70628bb7d1cd723c84b26cbfeb1a6104c2a4..afc46a23eb6d15ebfb328f242979d75998d6d4c4 100644 (file)
@@ -180,12 +180,12 @@ int parse_args(const char *name,
 #define STANDARD_PARAM_DEF(name, type, format, tmptype, strtolfn)              \
        int param_set_##name(const char *val, struct kernel_param *kp)  \
        {                                                               \
-               char *endp;                                             \
                tmptype l;                                              \
+               int ret;                                                \
                                                                        \
                if (!val) return -EINVAL;                               \
-               l = strtolfn(val, &endp, 0);                            \
-               if (endp == val || ((type)l != l))                      \
+               ret = strtolfn(val, 0, &l);                             \
+               if (ret == -EINVAL || ((type)l != l))                   \
                        return -EINVAL;                                 \
                *((type *)kp->arg) = l;                                 \
                return 0;                                               \
@@ -195,13 +195,13 @@ int parse_args(const char *name,
                return sprintf(buffer, format, *((type *)kp->arg));     \
        }
 
-STANDARD_PARAM_DEF(byte, unsigned char, "%c", unsigned long, simple_strtoul);
-STANDARD_PARAM_DEF(short, short, "%hi", long, simple_strtol);
-STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", unsigned long, simple_strtoul);
-STANDARD_PARAM_DEF(int, int, "%i", long, simple_strtol);
-STANDARD_PARAM_DEF(uint, unsigned int, "%u", unsigned long, simple_strtoul);
-STANDARD_PARAM_DEF(long, long, "%li", long, simple_strtol);
-STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, simple_strtoul);
+STANDARD_PARAM_DEF(byte, unsigned char, "%c", unsigned long, strict_strtoul);
+STANDARD_PARAM_DEF(short, short, "%hi", long, strict_strtol);
+STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", unsigned long, strict_strtoul);
+STANDARD_PARAM_DEF(int, int, "%i", long, strict_strtol);
+STANDARD_PARAM_DEF(uint, unsigned int, "%u", unsigned long, strict_strtoul);
+STANDARD_PARAM_DEF(long, long, "%li", long, strict_strtol);
+STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, strict_strtoul);
 
 int param_set_charp(const char *val, struct kernel_param *kp)
 {
index 3b30bccdfcdc92def5dcb4313d4606bc58d6cb46..477691576b338b38caa173c386b3a70ce7351a72 100644 (file)
@@ -41,7 +41,6 @@
 static struct hlist_head *pid_hash;
 static int pidhash_shift;
 struct pid init_struct_pid = INIT_STRUCT_PID;
-static struct kmem_cache *pid_ns_cachep;
 
 int pid_max = PID_MAX_DEFAULT;
 
@@ -112,7 +111,7 @@ EXPORT_SYMBOL(is_container_init);
 
 static  __cacheline_aligned_in_smp DEFINE_SPINLOCK(pidmap_lock);
 
-static fastcall void free_pidmap(struct pid_namespace *pid_ns, int pid)
+static void free_pidmap(struct pid_namespace *pid_ns, int pid)
 {
        struct pidmap *map = pid_ns->pidmap + pid / BITS_PER_PAGE;
        int offset = pid & BITS_PER_PAGE_MASK;
@@ -181,7 +180,7 @@ static int alloc_pidmap(struct pid_namespace *pid_ns)
        return -1;
 }
 
-static int next_pidmap(struct pid_namespace *pid_ns, int last)
+int next_pidmap(struct pid_namespace *pid_ns, int last)
 {
        int offset;
        struct pidmap *map, *end;
@@ -199,7 +198,7 @@ static int next_pidmap(struct pid_namespace *pid_ns, int last)
        return -1;
 }
 
-fastcall void put_pid(struct pid *pid)
+void put_pid(struct pid *pid)
 {
        struct pid_namespace *ns;
 
@@ -221,7 +220,7 @@ static void delayed_put_pid(struct rcu_head *rhp)
        put_pid(pid);
 }
 
-fastcall void free_pid(struct pid *pid)
+void free_pid(struct pid *pid)
 {
        /* We can be called with write_lock_irq(&tasklist_lock) held */
        int i;
@@ -287,7 +286,7 @@ out_free:
        goto out;
 }
 
-struct pid * fastcall find_pid_ns(int nr, struct pid_namespace *ns)
+struct pid *find_pid_ns(int nr, struct pid_namespace *ns)
 {
        struct hlist_node *elem;
        struct upid *pnr;
@@ -317,7 +316,7 @@ EXPORT_SYMBOL_GPL(find_pid);
 /*
  * attach_pid() must be called with the tasklist_lock write-held.
  */
-int fastcall attach_pid(struct task_struct *task, enum pid_type type,
+int attach_pid(struct task_struct *task, enum pid_type type,
                struct pid *pid)
 {
        struct pid_link *link;
@@ -329,7 +328,7 @@ int fastcall attach_pid(struct task_struct *task, enum pid_type type,
        return 0;
 }
 
-void fastcall detach_pid(struct task_struct *task, enum pid_type type)
+void detach_pid(struct task_struct *task, enum pid_type type)
 {
        struct pid_link *link;
        struct pid *pid;
@@ -349,7 +348,7 @@ void fastcall detach_pid(struct task_struct *task, enum pid_type type)
 }
 
 /* transfer_pid is an optimization of attach_pid(new), detach_pid(old) */
-void fastcall transfer_pid(struct task_struct *old, struct task_struct *new,
+void transfer_pid(struct task_struct *old, struct task_struct *new,
                           enum pid_type type)
 {
        new->pids[type].pid = old->pids[type].pid;
@@ -357,7 +356,7 @@ void fastcall transfer_pid(struct task_struct *old, struct task_struct *new,
        old->pids[type].pid = NULL;
 }
 
-struct task_struct * fastcall pid_task(struct pid *pid, enum pid_type type)
+struct task_struct *pid_task(struct pid *pid, enum pid_type type)
 {
        struct task_struct *result = NULL;
        if (pid) {
@@ -409,7 +408,7 @@ struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
        return pid;
 }
 
-struct task_struct *fastcall get_pid_task(struct pid *pid, enum pid_type type)
+struct task_struct *get_pid_task(struct pid *pid, enum pid_type type)
 {
        struct task_struct *result;
        rcu_read_lock();
@@ -444,6 +443,12 @@ pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
        return nr;
 }
 
+pid_t pid_vnr(struct pid *pid)
+{
+       return pid_nr_ns(pid, current->nsproxy->pid_ns);
+}
+EXPORT_SYMBOL_GPL(pid_vnr);
+
 pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
 {
        return pid_nr_ns(task_pid(tsk), ns);
@@ -488,180 +493,6 @@ struct pid *find_ge_pid(int nr, struct pid_namespace *ns)
 }
 EXPORT_SYMBOL_GPL(find_get_pid);
 
-struct pid_cache {
-       int nr_ids;
-       char name[16];
-       struct kmem_cache *cachep;
-       struct list_head list;
-};
-
-static LIST_HEAD(pid_caches_lh);
-static DEFINE_MUTEX(pid_caches_mutex);
-
-/*
- * creates the kmem cache to allocate pids from.
- * @nr_ids: the number of numerical ids this pid will have to carry
- */
-
-static struct kmem_cache *create_pid_cachep(int nr_ids)
-{
-       struct pid_cache *pcache;
-       struct kmem_cache *cachep;
-
-       mutex_lock(&pid_caches_mutex);
-       list_for_each_entry (pcache, &pid_caches_lh, list)
-               if (pcache->nr_ids == nr_ids)
-                       goto out;
-
-       pcache = kmalloc(sizeof(struct pid_cache), GFP_KERNEL);
-       if (pcache == NULL)
-               goto err_alloc;
-
-       snprintf(pcache->name, sizeof(pcache->name), "pid_%d", nr_ids);
-       cachep = kmem_cache_create(pcache->name,
-                       sizeof(struct pid) + (nr_ids - 1) * sizeof(struct upid),
-                       0, SLAB_HWCACHE_ALIGN, NULL);
-       if (cachep == NULL)
-               goto err_cachep;
-
-       pcache->nr_ids = nr_ids;
-       pcache->cachep = cachep;
-       list_add(&pcache->list, &pid_caches_lh);
-out:
-       mutex_unlock(&pid_caches_mutex);
-       return pcache->cachep;
-
-err_cachep:
-       kfree(pcache);
-err_alloc:
-       mutex_unlock(&pid_caches_mutex);
-       return NULL;
-}
-
-#ifdef CONFIG_PID_NS
-static struct pid_namespace *create_pid_namespace(int level)
-{
-       struct pid_namespace *ns;
-       int i;
-
-       ns = kmem_cache_alloc(pid_ns_cachep, GFP_KERNEL);
-       if (ns == NULL)
-               goto out;
-
-       ns->pidmap[0].page = kzalloc(PAGE_SIZE, GFP_KERNEL);
-       if (!ns->pidmap[0].page)
-               goto out_free;
-
-       ns->pid_cachep = create_pid_cachep(level + 1);
-       if (ns->pid_cachep == NULL)
-               goto out_free_map;
-
-       kref_init(&ns->kref);
-       ns->last_pid = 0;
-       ns->child_reaper = NULL;
-       ns->level = level;
-
-       set_bit(0, ns->pidmap[0].page);
-       atomic_set(&ns->pidmap[0].nr_free, BITS_PER_PAGE - 1);
-
-       for (i = 1; i < PIDMAP_ENTRIES; i++) {
-               ns->pidmap[i].page = 0;
-               atomic_set(&ns->pidmap[i].nr_free, BITS_PER_PAGE);
-       }
-
-       return ns;
-
-out_free_map:
-       kfree(ns->pidmap[0].page);
-out_free:
-       kmem_cache_free(pid_ns_cachep, ns);
-out:
-       return ERR_PTR(-ENOMEM);
-}
-
-static void destroy_pid_namespace(struct pid_namespace *ns)
-{
-       int i;
-
-       for (i = 0; i < PIDMAP_ENTRIES; i++)
-               kfree(ns->pidmap[i].page);
-       kmem_cache_free(pid_ns_cachep, ns);
-}
-
-struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *old_ns)
-{
-       struct pid_namespace *new_ns;
-
-       BUG_ON(!old_ns);
-       new_ns = get_pid_ns(old_ns);
-       if (!(flags & CLONE_NEWPID))
-               goto out;
-
-       new_ns = ERR_PTR(-EINVAL);
-       if (flags & CLONE_THREAD)
-               goto out_put;
-
-       new_ns = create_pid_namespace(old_ns->level + 1);
-       if (!IS_ERR(new_ns))
-               new_ns->parent = get_pid_ns(old_ns);
-
-out_put:
-       put_pid_ns(old_ns);
-out:
-       return new_ns;
-}
-
-void free_pid_ns(struct kref *kref)
-{
-       struct pid_namespace *ns, *parent;
-
-       ns = container_of(kref, struct pid_namespace, kref);
-
-       parent = ns->parent;
-       destroy_pid_namespace(ns);
-
-       if (parent != NULL)
-               put_pid_ns(parent);
-}
-#endif /* CONFIG_PID_NS */
-
-void zap_pid_ns_processes(struct pid_namespace *pid_ns)
-{
-       int nr;
-       int rc;
-
-       /*
-        * The last thread in the cgroup-init thread group is terminating.
-        * Find remaining pid_ts in the namespace, signal and wait for them
-        * to exit.
-        *
-        * Note:  This signals each threads in the namespace - even those that
-        *        belong to the same thread group, To avoid this, we would have
-        *        to walk the entire tasklist looking a processes in this
-        *        namespace, but that could be unnecessarily expensive if the
-        *        pid namespace has just a few processes. Or we need to
-        *        maintain a tasklist for each pid namespace.
-        *
-        */
-       read_lock(&tasklist_lock);
-       nr = next_pidmap(pid_ns, 1);
-       while (nr > 0) {
-               kill_proc_info(SIGKILL, SEND_SIG_PRIV, nr);
-               nr = next_pidmap(pid_ns, nr);
-       }
-       read_unlock(&tasklist_lock);
-
-       do {
-               clear_thread_flag(TIF_SIGPENDING);
-               rc = sys_wait4(-1, NULL, __WALL, NULL);
-       } while (rc != -ECHILD);
-
-
-       /* Child reaper for the pid namespace is going away */
-       pid_ns->child_reaper = NULL;
-       return;
-}
-
 /*
  * The pid hash table is scaled according to the amount of memory in the
  * machine.  From a minimum of 16 slots up to 4096 slots at one gigabyte or
@@ -694,9 +525,6 @@ void __init pidmap_init(void)
        set_bit(0, init_pid_ns.pidmap[0].page);
        atomic_dec(&init_pid_ns.pidmap[0].nr_free);
 
-       init_pid_ns.pid_cachep = create_pid_cachep(1);
-       if (init_pid_ns.pid_cachep == NULL)
-               panic("Can't create pid_1 cachep\n");
-
-       pid_ns_cachep = KMEM_CACHE(pid_namespace, SLAB_PANIC);
+       init_pid_ns.pid_cachep = KMEM_CACHE(pid,
+                       SLAB_HWCACHE_ALIGN | SLAB_PANIC);
 }
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
new file mode 100644 (file)
index 0000000..6d792b6
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ * Pid namespaces
+ *
+ * Authors:
+ *    (C) 2007 Pavel Emelyanov <xemul@openvz.org>, OpenVZ, SWsoft Inc.
+ *    (C) 2007 Sukadev Bhattiprolu <sukadev@us.ibm.com>, IBM
+ *     Many thanks to Oleg Nesterov for comments and help
+ *
+ */
+
+#include <linux/pid.h>
+#include <linux/pid_namespace.h>
+#include <linux/syscalls.h>
+#include <linux/err.h>
+
+#define BITS_PER_PAGE          (PAGE_SIZE*8)
+
+struct pid_cache {
+       int nr_ids;
+       char name[16];
+       struct kmem_cache *cachep;
+       struct list_head list;
+};
+
+static LIST_HEAD(pid_caches_lh);
+static DEFINE_MUTEX(pid_caches_mutex);
+static struct kmem_cache *pid_ns_cachep;
+
+/*
+ * creates the kmem cache to allocate pids from.
+ * @nr_ids: the number of numerical ids this pid will have to carry
+ */
+
+static struct kmem_cache *create_pid_cachep(int nr_ids)
+{
+       struct pid_cache *pcache;
+       struct kmem_cache *cachep;
+
+       mutex_lock(&pid_caches_mutex);
+       list_for_each_entry(pcache, &pid_caches_lh, list)
+               if (pcache->nr_ids == nr_ids)
+                       goto out;
+
+       pcache = kmalloc(sizeof(struct pid_cache), GFP_KERNEL);
+       if (pcache == NULL)
+               goto err_alloc;
+
+       snprintf(pcache->name, sizeof(pcache->name), "pid_%d", nr_ids);
+       cachep = kmem_cache_create(pcache->name,
+                       sizeof(struct pid) + (nr_ids - 1) * sizeof(struct upid),
+                       0, SLAB_HWCACHE_ALIGN, NULL);
+       if (cachep == NULL)
+               goto err_cachep;
+
+       pcache->nr_ids = nr_ids;
+       pcache->cachep = cachep;
+       list_add(&pcache->list, &pid_caches_lh);
+out:
+       mutex_unlock(&pid_caches_mutex);
+       return pcache->cachep;
+
+err_cachep:
+       kfree(pcache);
+err_alloc:
+       mutex_unlock(&pid_caches_mutex);
+       return NULL;
+}
+
+static struct pid_namespace *create_pid_namespace(int level)
+{
+       struct pid_namespace *ns;
+       int i;
+
+       ns = kmem_cache_alloc(pid_ns_cachep, GFP_KERNEL);
+       if (ns == NULL)
+               goto out;
+
+       ns->pidmap[0].page = kzalloc(PAGE_SIZE, GFP_KERNEL);
+       if (!ns->pidmap[0].page)
+               goto out_free;
+
+       ns->pid_cachep = create_pid_cachep(level + 1);
+       if (ns->pid_cachep == NULL)
+               goto out_free_map;
+
+       kref_init(&ns->kref);
+       ns->last_pid = 0;
+       ns->child_reaper = NULL;
+       ns->level = level;
+
+       set_bit(0, ns->pidmap[0].page);
+       atomic_set(&ns->pidmap[0].nr_free, BITS_PER_PAGE - 1);
+
+       for (i = 1; i < PIDMAP_ENTRIES; i++) {
+               ns->pidmap[i].page = 0;
+               atomic_set(&ns->pidmap[i].nr_free, BITS_PER_PAGE);
+       }
+
+       return ns;
+
+out_free_map:
+       kfree(ns->pidmap[0].page);
+out_free:
+       kmem_cache_free(pid_ns_cachep, ns);
+out:
+       return ERR_PTR(-ENOMEM);
+}
+
+static void destroy_pid_namespace(struct pid_namespace *ns)
+{
+       int i;
+
+       for (i = 0; i < PIDMAP_ENTRIES; i++)
+               kfree(ns->pidmap[i].page);
+       kmem_cache_free(pid_ns_cachep, ns);
+}
+
+struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *old_ns)
+{
+       struct pid_namespace *new_ns;
+
+       BUG_ON(!old_ns);
+       new_ns = get_pid_ns(old_ns);
+       if (!(flags & CLONE_NEWPID))
+               goto out;
+
+       new_ns = ERR_PTR(-EINVAL);
+       if (flags & CLONE_THREAD)
+               goto out_put;
+
+       new_ns = create_pid_namespace(old_ns->level + 1);
+       if (!IS_ERR(new_ns))
+               new_ns->parent = get_pid_ns(old_ns);
+
+out_put:
+       put_pid_ns(old_ns);
+out:
+       return new_ns;
+}
+
+void free_pid_ns(struct kref *kref)
+{
+       struct pid_namespace *ns, *parent;
+
+       ns = container_of(kref, struct pid_namespace, kref);
+
+       parent = ns->parent;
+       destroy_pid_namespace(ns);
+
+       if (parent != NULL)
+               put_pid_ns(parent);
+}
+
+void zap_pid_ns_processes(struct pid_namespace *pid_ns)
+{
+       int nr;
+       int rc;
+
+       /*
+        * The last thread in the cgroup-init thread group is terminating.
+        * Find remaining pid_ts in the namespace, signal and wait for them
+        * to exit.
+        *
+        * Note:  This signals each threads in the namespace - even those that
+        *        belong to the same thread group, To avoid this, we would have
+        *        to walk the entire tasklist looking a processes in this
+        *        namespace, but that could be unnecessarily expensive if the
+        *        pid namespace has just a few processes. Or we need to
+        *        maintain a tasklist for each pid namespace.
+        *
+        */
+       read_lock(&tasklist_lock);
+       nr = next_pidmap(pid_ns, 1);
+       while (nr > 0) {
+               kill_proc_info(SIGKILL, SEND_SIG_PRIV, nr);
+               nr = next_pidmap(pid_ns, nr);
+       }
+       read_unlock(&tasklist_lock);
+
+       do {
+               clear_thread_flag(TIF_SIGPENDING);
+               rc = sys_wait4(-1, NULL, __WALL, NULL);
+       } while (rc != -ECHILD);
+
+
+       /* Child reaper for the pid namespace is going away */
+       pid_ns->child_reaper = NULL;
+       return;
+}
+
+static __init int pid_namespaces_init(void)
+{
+       pid_ns_cachep = KMEM_CACHE(pid_namespace, SLAB_PANIC);
+       return 0;
+}
+
+__initcall(pid_namespaces_init);
index 0b7c82ac467eb1db24e0614fe7cc1d2704d27a48..2eae91f954ca2ed98b05e2c145b38c2cb857fbb5 100644 (file)
@@ -20,7 +20,7 @@ static int check_clock(const clockid_t which_clock)
                return 0;
 
        read_lock(&tasklist_lock);
-       p = find_task_by_pid(pid);
+       p = find_task_by_vpid(pid);
        if (!p || !(CPUCLOCK_PERTHREAD(which_clock) ?
                   same_thread_group(p, current) : thread_group_leader(p))) {
                error = -EINVAL;
@@ -305,7 +305,7 @@ int posix_cpu_clock_get(const clockid_t which_clock, struct timespec *tp)
                 */
                struct task_struct *p;
                rcu_read_lock();
-               p = find_task_by_pid(pid);
+               p = find_task_by_vpid(pid);
                if (p) {
                        if (CPUCLOCK_PERTHREAD(which_clock)) {
                                if (same_thread_group(p, current)) {
@@ -354,7 +354,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
                if (pid == 0) {
                        p = current;
                } else {
-                       p = find_task_by_pid(pid);
+                       p = find_task_by_vpid(pid);
                        if (p && !same_thread_group(p, current))
                                p = NULL;
                }
@@ -362,7 +362,7 @@ int posix_cpu_timer_create(struct k_itimer *new_timer)
                if (pid == 0) {
                        p = current->group_leader;
                } else {
-                       p = find_task_by_pid(pid);
+                       p = find_task_by_vpid(pid);
                        if (p && !thread_group_leader(p))
                                p = NULL;
                }
index 122d5c787fe2fc7300deeb153fec9a1d3835cd34..ce268966007d6f71904cd8229939f6fb9a2324c5 100644 (file)
@@ -404,7 +404,7 @@ static struct task_struct * good_sigevent(sigevent_t * event)
        struct task_struct *rtn = current->group_leader;
 
        if ((event->sigev_notify & SIGEV_THREAD_ID ) &&
-               (!(rtn = find_task_by_pid(event->sigev_notify_thread_id)) ||
+               (!(rtn = find_task_by_vpid(event->sigev_notify_thread_id)) ||
                 !same_thread_group(rtn, current) ||
                 (event->sigev_notify & ~SIGEV_THREAD_ID) != SIGEV_SIGNAL))
                return NULL;
index 4a090621f3793fe705352565a41a022441e617b6..bee36100f110ab75617ad4dce16beac9e1434f76 100644 (file)
@@ -32,7 +32,6 @@
 #include <linux/security.h>
 #include <linux/bootmem.h>
 #include <linux/syscalls.h>
-#include <linux/jiffies.h>
 
 #include <asm/uaccess.h>
 
@@ -567,19 +566,6 @@ static int printk_time = 0;
 #endif
 module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
 
-static int __init printk_time_setup(char *str)
-{
-       if (*str)
-               return 0;
-       printk_time = 1;
-       printk(KERN_NOTICE "The 'time' option is deprecated and "
-               "is scheduled for removal in early 2008\n");
-       printk(KERN_NOTICE "Use 'printk.time=<value>' instead\n");
-       return 1;
-}
-
-__setup("time", printk_time_setup);
-
 /* Check if we have any console registered that can be called early in boot. */
 static int have_callable_console(void)
 {
@@ -1265,6 +1251,7 @@ void tty_write_message(struct tty_struct *tty, char *msg)
        return;
 }
 
+#if defined CONFIG_PRINTK
 /*
  * printk rate limiting, lifted from the networking subsystem.
  *
@@ -1334,3 +1321,4 @@ bool printk_timed_ratelimit(unsigned long *caller_jiffies,
        return false;
 }
 EXPORT_SYMBOL(printk_timed_ratelimit);
+#endif
index e64c2da11c0f89018c31aca62dd69688d22d59eb..3b7a1b055122a698c0f97a05eae8cbe6a229bb6f 100644 (file)
@@ -20,7 +20,6 @@
 #include <linux/mm.h>
 #include <linux/cpumask.h>
 #include <linux/cpu.h>
-#include <linux/profile.h>
 #include <linux/highmem.h>
 #include <linux/mutex.h>
 #include <asm/sections.h>
index 628b03ab88a579c52f9c802440e768c4752ab957..fdb34e86f923f188113e7945e63c572c805c65a2 100644 (file)
@@ -99,10 +99,12 @@ int ptrace_check_attach(struct task_struct *child, int kill)
         * be changed by us so it's not changing right after this.
         */
        read_lock(&tasklist_lock);
-       if ((child->ptrace & PT_PTRACED) && child->parent == current &&
-           (!(child->ptrace & PT_ATTACHED) || child->real_parent != current)
-           && child->signal != NULL) {
+       if ((child->ptrace & PT_PTRACED) && child->parent == current) {
                ret = 0;
+               /*
+                * child->sighand can't be NULL, release_task()
+                * does ptrace_unlink() before __exit_signal().
+                */
                spin_lock_irq(&child->sighand->siglock);
                if (task_is_stopped(child))
                        child->state = TASK_TRACED;
@@ -200,8 +202,7 @@ repeat:
                goto bad;
 
        /* Go */
-       task->ptrace |= PT_PTRACED | ((task->real_parent != current)
-                                     ? PT_ATTACHED : 0);
+       task->ptrace |= PT_PTRACED;
        if (capable(CAP_SYS_PTRACE))
                task->ptrace |= PT_PTRACE_CAP;
 
index 56d73cb8826d86ff75ce0dea818ce658be11cf49..5fcb4fe645e245a4a6c043aedbf1c212dbefadf0 100644 (file)
@@ -130,7 +130,7 @@ void debug_rt_mutex_deadlock(int detect, struct rt_mutex_waiter *act_waiter,
 
        task = rt_mutex_owner(act_waiter->lock);
        if (task && task != current) {
-               act_waiter->deadlock_task_pid = task->pid;
+               act_waiter->deadlock_task_pid = get_pid(task_pid(task));
                act_waiter->deadlock_lock = lock;
        }
 }
@@ -142,9 +142,12 @@ void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter)
        if (!waiter->deadlock_lock || !rt_trace_on)
                return;
 
-       task = find_task_by_pid(waiter->deadlock_task_pid);
-       if (!task)
+       rcu_read_lock();
+       task = pid_task(waiter->deadlock_task_pid, PIDTYPE_PID);
+       if (!task) {
+               rcu_read_unlock();
                return;
+       }
 
        TRACE_OFF_NOLOCK();
 
@@ -173,6 +176,7 @@ void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter)
                current->comm, task_pid_nr(current));
        dump_stack();
        debug_show_all_locks();
+       rcu_read_unlock();
 
        printk("[ turning off deadlock detection."
               "Please report this trace. ]\n\n");
@@ -203,10 +207,12 @@ void debug_rt_mutex_init_waiter(struct rt_mutex_waiter *waiter)
        memset(waiter, 0x11, sizeof(*waiter));
        plist_node_init(&waiter->list_entry, MAX_PRIO);
        plist_node_init(&waiter->pi_list_entry, MAX_PRIO);
+       waiter->deadlock_task_pid = NULL;
 }
 
 void debug_rt_mutex_free_waiter(struct rt_mutex_waiter *waiter)
 {
+       put_pid(waiter->deadlock_task_pid);
        TRACE_WARN_ON(!plist_node_empty(&waiter->list_entry));
        TRACE_WARN_ON(!plist_node_empty(&waiter->pi_list_entry));
        TRACE_WARN_ON(waiter->task);
index 2d3b83593ca3232a0414fc8f808e8435376a9d4c..e124bf5800ea140ceeb936c7cba6429fea0e49b5 100644 (file)
@@ -51,7 +51,7 @@ struct rt_mutex_waiter {
        struct rt_mutex         *lock;
 #ifdef CONFIG_DEBUG_RT_MUTEXES
        unsigned long           ip;
-       pid_t                   deadlock_task_pid;
+       struct pid              *deadlock_task_pid;
        struct rt_mutex         *deadlock_lock;
 #endif
 };
index 9474b23c28bf41f5989df3b94c5e810b0f1e971a..3eedd5260907fe5be7b6c058b95629757585b695 100644 (file)
@@ -1893,13 +1893,13 @@ out:
        return success;
 }
 
-int fastcall wake_up_process(struct task_struct *p)
+int wake_up_process(struct task_struct *p)
 {
        return try_to_wake_up(p, TASK_ALL, 0);
 }
 EXPORT_SYMBOL(wake_up_process);
 
-int fastcall wake_up_state(struct task_struct *p, unsigned int state)
+int wake_up_state(struct task_struct *p, unsigned int state)
 {
        return try_to_wake_up(p, state, 0);
 }
@@ -1986,7 +1986,7 @@ void sched_fork(struct task_struct *p, int clone_flags)
  * that must be done for every newly created context, then puts the task
  * on the runqueue and wakes it.
  */
-void fastcall wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
+void wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
 {
        unsigned long flags;
        struct rq *rq;
@@ -3753,7 +3753,7 @@ void scheduler_tick(void)
 
 #if defined(CONFIG_PREEMPT) && defined(CONFIG_DEBUG_PREEMPT)
 
-void fastcall add_preempt_count(int val)
+void add_preempt_count(int val)
 {
        /*
         * Underflow?
@@ -3769,7 +3769,7 @@ void fastcall add_preempt_count(int val)
 }
 EXPORT_SYMBOL(add_preempt_count);
 
-void fastcall sub_preempt_count(int val)
+void sub_preempt_count(int val)
 {
        /*
         * Underflow?
@@ -4067,7 +4067,7 @@ static void __wake_up_common(wait_queue_head_t *q, unsigned int mode,
  * @nr_exclusive: how many wake-one or wake-many threads to wake up
  * @key: is directly passed to the wakeup function
  */
-void fastcall __wake_up(wait_queue_head_t *q, unsigned int mode,
+void __wake_up(wait_queue_head_t *q, unsigned int mode,
                        int nr_exclusive, void *key)
 {
        unsigned long flags;
@@ -4081,7 +4081,7 @@ EXPORT_SYMBOL(__wake_up);
 /*
  * Same as __wake_up but called with the spinlock in wait_queue_head_t held.
  */
-void fastcall __wake_up_locked(wait_queue_head_t *q, unsigned int mode)
+void __wake_up_locked(wait_queue_head_t *q, unsigned int mode)
 {
        __wake_up_common(q, mode, 1, 0, NULL);
 }
@@ -4099,7 +4099,7 @@ void fastcall __wake_up_locked(wait_queue_head_t *q, unsigned int mode)
  *
  * On UP it can prevent extra preemption.
  */
-void fastcall
+void
 __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr_exclusive)
 {
        unsigned long flags;
index 5d30ff5618475273c60e6aeb59e7cf092603b9a4..2c1f08defac29c7fc64475e1612b35c1c8056e1b 100644 (file)
@@ -1018,7 +1018,7 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
 }
 
 /*
- * kill_pgrp_info() sends a signal to a process group: this is what the tty
+ * __kill_pgrp_info() sends a signal to a process group: this is what the tty
  * control characters do (^C, ^Z etc)
  */
 
@@ -1037,30 +1037,28 @@ int __kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp)
        return success ? 0 : retval;
 }
 
-int kill_pgrp_info(int sig, struct siginfo *info, struct pid *pgrp)
-{
-       int retval;
-
-       read_lock(&tasklist_lock);
-       retval = __kill_pgrp_info(sig, info, pgrp);
-       read_unlock(&tasklist_lock);
-
-       return retval;
-}
-
 int kill_pid_info(int sig, struct siginfo *info, struct pid *pid)
 {
-       int error;
+       int error = -ESRCH;
        struct task_struct *p;
 
        rcu_read_lock();
        if (unlikely(sig_needs_tasklist(sig)))
                read_lock(&tasklist_lock);
 
+retry:
        p = pid_task(pid, PIDTYPE_PID);
-       error = -ESRCH;
-       if (p)
+       if (p) {
                error = group_send_sig_info(sig, info, p);
+               if (unlikely(error == -ESRCH))
+                       /*
+                        * The task was unhashed in between, try again.
+                        * If it is dead, pid_task() will return NULL,
+                        * if we race with de_thread() it will find the
+                        * new leader.
+                        */
+                       goto retry;
+       }
 
        if (unlikely(sig_needs_tasklist(sig)))
                read_unlock(&tasklist_lock);
@@ -1125,14 +1123,22 @@ EXPORT_SYMBOL_GPL(kill_pid_info_as_uid);
 static int kill_something_info(int sig, struct siginfo *info, int pid)
 {
        int ret;
-       rcu_read_lock();
-       if (!pid) {
-               ret = kill_pgrp_info(sig, info, task_pgrp(current));
-       } else if (pid == -1) {
+
+       if (pid > 0) {
+               rcu_read_lock();
+               ret = kill_pid_info(sig, info, find_vpid(pid));
+               rcu_read_unlock();
+               return ret;
+       }
+
+       read_lock(&tasklist_lock);
+       if (pid != -1) {
+               ret = __kill_pgrp_info(sig, info,
+                               pid ? find_vpid(-pid) : task_pgrp(current));
+       } else {
                int retval = 0, count = 0;
                struct task_struct * p;
 
-               read_lock(&tasklist_lock);
                for_each_process(p) {
                        if (p->pid > 1 && !same_thread_group(p, current)) {
                                int err = group_send_sig_info(sig, info, p);
@@ -1141,14 +1147,10 @@ static int kill_something_info(int sig, struct siginfo *info, int pid)
                                        retval = err;
                        }
                }
-               read_unlock(&tasklist_lock);
                ret = count ? retval : -ESRCH;
-       } else if (pid < 0) {
-               ret = kill_pgrp_info(sig, info, find_vpid(-pid));
-       } else {
-               ret = kill_pid_info(sig, info, find_vpid(pid));
        }
-       rcu_read_unlock();
+       read_unlock(&tasklist_lock);
+
        return ret;
 }
 
@@ -1196,20 +1198,6 @@ send_sig(int sig, struct task_struct *p, int priv)
        return send_sig_info(sig, __si_special(priv), p);
 }
 
-/*
- * This is the entry point for "process-wide" signals.
- * They will go to an appropriate thread in the thread group.
- */
-int
-send_group_sig_info(int sig, struct siginfo *info, struct task_struct *p)
-{
-       int ret;
-       read_lock(&tasklist_lock);
-       ret = group_send_sig_info(sig, info, p);
-       read_unlock(&tasklist_lock);
-       return ret;
-}
-
 void
 force_sig(int sig, struct task_struct *p)
 {
@@ -1237,7 +1225,13 @@ force_sigsegv(int sig, struct task_struct *p)
 
 int kill_pgrp(struct pid *pid, int sig, int priv)
 {
-       return kill_pgrp_info(sig, __si_special(priv), pid);
+       int ret;
+
+       read_lock(&tasklist_lock);
+       ret = __kill_pgrp_info(sig, __si_special(priv), pid);
+       read_unlock(&tasklist_lock);
+
+       return ret;
 }
 EXPORT_SYMBOL(kill_pgrp);
 
@@ -1556,11 +1550,6 @@ static inline int may_ptrace_stop(void)
 {
        if (!likely(current->ptrace & PT_PTRACED))
                return 0;
-
-       if (unlikely(current->parent == current->real_parent &&
-                   (current->ptrace & PT_ATTACHED)))
-               return 0;
-
        /*
         * Are we in the middle of do_coredump?
         * If so and our tracer is also part of the coredump stopping
@@ -1596,10 +1585,10 @@ static int sigkill_pending(struct task_struct *tsk)
  * That makes it a way to test a stopped process for
  * being ptrace-stopped vs being job-control-stopped.
  *
- * If we actually decide not to stop at all because the tracer is gone,
- * we leave nostop_code in current->exit_code.
+ * If we actually decide not to stop at all because the tracer
+ * is gone, we keep current->exit_code unless clear_code.
  */
-static void ptrace_stop(int exit_code, int nostop_code, siginfo_t *info)
+static void ptrace_stop(int exit_code, int clear_code, siginfo_t *info)
 {
        int killed = 0;
 
@@ -1643,11 +1632,12 @@ static void ptrace_stop(int exit_code, int nostop_code, siginfo_t *info)
        } else {
                /*
                 * By the time we got the lock, our tracer went away.
-                * Don't stop here.
+                * Don't drop the lock yet, another tracer may come.
                 */
+               __set_current_state(TASK_RUNNING);
+               if (clear_code)
+                       current->exit_code = 0;
                read_unlock(&tasklist_lock);
-               set_current_state(TASK_RUNNING);
-               current->exit_code = nostop_code;
        }
 
        /*
@@ -1680,7 +1670,7 @@ void ptrace_notify(int exit_code)
 
        /* Let the debugger run.  */
        spin_lock_irq(&current->sighand->siglock);
-       ptrace_stop(exit_code, 0, &info);
+       ptrace_stop(exit_code, 1, &info);
        spin_unlock_irq(&current->sighand->siglock);
 }
 
@@ -1743,7 +1733,7 @@ static int do_signal_stop(int signr)
                         * stop is always done with the siglock held,
                         * so this check has no races.
                         */
-                       if (!t->exit_state &&
+                       if (!(t->flags & PF_EXITING) &&
                            !task_is_stopped_or_traced(t)) {
                                stop_count++;
                                signal_wake_up(t, 0);
@@ -1787,7 +1777,7 @@ relock:
                        ptrace_signal_deliver(regs, cookie);
 
                        /* Let the debugger run.  */
-                       ptrace_stop(signr, signr, info);
+                       ptrace_stop(signr, 0, info);
 
                        /* We're back.  Did the debugger cancel the sig?  */
                        signr = current->exit_code;
@@ -1904,6 +1894,48 @@ relock:
        return signr;
 }
 
+void exit_signals(struct task_struct *tsk)
+{
+       int group_stop = 0;
+       struct task_struct *t;
+
+       if (thread_group_empty(tsk) || signal_group_exit(tsk->signal)) {
+               tsk->flags |= PF_EXITING;
+               return;
+       }
+
+       spin_lock_irq(&tsk->sighand->siglock);
+       /*
+        * From now this task is not visible for group-wide signals,
+        * see wants_signal(), do_signal_stop().
+        */
+       tsk->flags |= PF_EXITING;
+       if (!signal_pending(tsk))
+               goto out;
+
+       /* It could be that __group_complete_signal() choose us to
+        * notify about group-wide signal. Another thread should be
+        * woken now to take the signal since we will not.
+        */
+       for (t = tsk; (t = next_thread(t)) != tsk; )
+               if (!signal_pending(t) && !(t->flags & PF_EXITING))
+                       recalc_sigpending_and_wake(t);
+
+       if (unlikely(tsk->signal->group_stop_count) &&
+                       !--tsk->signal->group_stop_count) {
+               tsk->signal->flags = SIGNAL_STOP_STOPPED;
+               group_stop = 1;
+       }
+out:
+       spin_unlock_irq(&tsk->sighand->siglock);
+
+       if (unlikely(group_stop)) {
+               read_lock(&tasklist_lock);
+               do_notify_parent_cldstop(tsk, CLD_STOPPED);
+               read_unlock(&tasklist_lock);
+       }
+}
+
 EXPORT_SYMBOL(recalc_sigpending);
 EXPORT_SYMBOL_GPL(dequeue_signal);
 EXPORT_SYMBOL(flush_signals);
index d7837d45419eabbbead3886b104a697b5bcaf29c..5b3aea5f471e06a2bac64ad232dce64e60650ea4 100644 (file)
@@ -320,7 +320,7 @@ void irq_exit(void)
 /*
  * This function must run with irqs disabled!
  */
-inline fastcall void raise_softirq_irqoff(unsigned int nr)
+inline void raise_softirq_irqoff(unsigned int nr)
 {
        __raise_softirq_irqoff(nr);
 
@@ -337,7 +337,7 @@ inline fastcall void raise_softirq_irqoff(unsigned int nr)
                wakeup_softirqd();
 }
 
-void fastcall raise_softirq(unsigned int nr)
+void raise_softirq(unsigned int nr)
 {
        unsigned long flags;
 
@@ -363,7 +363,7 @@ struct tasklet_head
 static DEFINE_PER_CPU(struct tasklet_head, tasklet_vec) = { NULL };
 static DEFINE_PER_CPU(struct tasklet_head, tasklet_hi_vec) = { NULL };
 
-void fastcall __tasklet_schedule(struct tasklet_struct *t)
+void __tasklet_schedule(struct tasklet_struct *t)
 {
        unsigned long flags;
 
@@ -376,7 +376,7 @@ void fastcall __tasklet_schedule(struct tasklet_struct *t)
 
 EXPORT_SYMBOL(__tasklet_schedule);
 
-void fastcall __tasklet_hi_schedule(struct tasklet_struct *t)
+void __tasklet_hi_schedule(struct tasklet_struct *t)
 {
        unsigned long flags;
 
index e3c08d4324deed268673c23ff8efd01817874d68..a626116af5db96b58f47434eb47c6af23da6535e 100644 (file)
@@ -916,8 +916,8 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
 {
        struct task_struct *p;
        struct task_struct *group_leader = current->group_leader;
-       int err = -EINVAL;
-       struct pid_namespace *ns;
+       struct pid *pgrp;
+       int err;
 
        if (!pid)
                pid = task_pid_vnr(group_leader);
@@ -929,12 +929,10 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
        /* From this point forward we keep holding onto the tasklist lock
         * so that our parent does not change from under us. -DaveM
         */
-       ns = current->nsproxy->pid_ns;
-
        write_lock_irq(&tasklist_lock);
 
        err = -ESRCH;
-       p = find_task_by_pid_ns(pid, ns);
+       p = find_task_by_vpid(pid);
        if (!p)
                goto out;
 
@@ -942,7 +940,7 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
        if (!thread_group_leader(p))
                goto out;
 
-       if (p->real_parent->tgid == group_leader->tgid) {
+       if (same_thread_group(p->real_parent, group_leader)) {
                err = -EPERM;
                if (task_session(p) != task_session(group_leader))
                        goto out;
@@ -959,10 +957,12 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
        if (p->signal->leader)
                goto out;
 
+       pgrp = task_pid(p);
        if (pgid != pid) {
                struct task_struct *g;
 
-               g = find_task_by_pid_type_ns(PIDTYPE_PGID, pgid, ns);
+               pgrp = find_vpid(pgid);
+               g = pid_task(pgrp, PIDTYPE_PGID);
                if (!g || task_session(g) != task_session(group_leader))
                        goto out;
        }
@@ -971,13 +971,10 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
        if (err)
                goto out;
 
-       if (task_pgrp_nr_ns(p, ns) != pgid) {
-               struct pid *pid;
-
+       if (task_pgrp(p) != pgrp) {
                detach_pid(p, PIDTYPE_PGID);
-               pid = find_vpid(pgid);
-               attach_pid(p, PIDTYPE_PGID, pid);
-               set_task_pgrp(p, pid_nr(pid));
+               attach_pid(p, PIDTYPE_PGID, pgrp);
+               set_task_pgrp(p, pid_nr(pgrp));
        }
 
        err = 0;
@@ -994,17 +991,14 @@ asmlinkage long sys_getpgid(pid_t pid)
        else {
                int retval;
                struct task_struct *p;
-               struct pid_namespace *ns;
-
-               ns = current->nsproxy->pid_ns;
 
                read_lock(&tasklist_lock);
-               p = find_task_by_pid_ns(pid, ns);
+               p = find_task_by_vpid(pid);
                retval = -ESRCH;
                if (p) {
                        retval = security_task_getpgid(p);
                        if (!retval)
-                               retval = task_pgrp_nr_ns(p, ns);
+                               retval = task_pgrp_vnr(p);
                }
                read_unlock(&tasklist_lock);
                return retval;
@@ -1028,19 +1022,16 @@ asmlinkage long sys_getsid(pid_t pid)
        else {
                int retval;
                struct task_struct *p;
-               struct pid_namespace *ns;
-
-               ns = current->nsproxy->pid_ns;
 
-               read_lock(&tasklist_lock);
-               p = find_task_by_pid_ns(pid, ns);
+               rcu_read_lock();
+               p = find_task_by_vpid(pid);
                retval = -ESRCH;
                if (p) {
                        retval = security_task_getsid(p);
                        if (!retval)
-                               retval = task_session_nr_ns(p, ns);
+                               retval = task_session_vnr(p);
                }
-               read_unlock(&tasklist_lock);
+               rcu_read_unlock();
                return retval;
        }
 }
@@ -1048,35 +1039,29 @@ asmlinkage long sys_getsid(pid_t pid)
 asmlinkage long sys_setsid(void)
 {
        struct task_struct *group_leader = current->group_leader;
-       pid_t session;
+       struct pid *sid = task_pid(group_leader);
+       pid_t session = pid_vnr(sid);
        int err = -EPERM;
 
        write_lock_irq(&tasklist_lock);
-
        /* Fail if I am already a session leader */
        if (group_leader->signal->leader)
                goto out;
 
-       session = group_leader->pid;
        /* Fail if a process group id already exists that equals the
         * proposed session id.
-        *
-        * Don't check if session id == 1 because kernel threads use this
-        * session id and so the check will always fail and make it so
-        * init cannot successfully call setsid.
         */
-       if (session > 1 && find_task_by_pid_type_ns(PIDTYPE_PGID,
-                               session, &init_pid_ns))
+       if (pid_task(sid, PIDTYPE_PGID))
                goto out;
 
        group_leader->signal->leader = 1;
-       __set_special_pids(session, session);
+       __set_special_pids(sid);
 
        spin_lock(&group_leader->sighand->siglock);
        group_leader->signal->tty = NULL;
        spin_unlock(&group_leader->sighand->siglock);
 
-       err = task_pgrp_vnr(group_leader);
+       err = session;
 out:
        write_unlock_irq(&tasklist_lock);
        return err;
index 8c98d8147d883ac977d08ff8189b7fd4c1042136..d41ef6b4cf727dc5cd8b48d3f761df9016c8eb20 100644 (file)
@@ -37,7 +37,6 @@
 #include <linux/highuid.h>
 #include <linux/writeback.h>
 #include <linux/hugetlb.h>
-#include <linux/security.h>
 #include <linux/initrd.h>
 #include <linux/times.h>
 #include <linux/limits.h>
@@ -74,8 +73,6 @@ extern int suid_dumpable;
 extern char core_pattern[];
 extern int pid_max;
 extern int min_free_kbytes;
-extern int printk_ratelimit_jiffies;
-extern int printk_ratelimit_burst;
 extern int pid_max_min, pid_max_max;
 extern int sysctl_drop_caches;
 extern int percpu_pagelist_fraction;
@@ -491,14 +488,6 @@ static struct ctl_table kern_table[] = {
                .mode           = 0644,
                .proc_handler   = &proc_dointvec,
        },
-       {
-               .ctl_name       = KERN_PRINTK,
-               .procname       = "printk",
-               .data           = &console_loglevel,
-               .maxlen         = 4*sizeof(int),
-               .mode           = 0644,
-               .proc_handler   = &proc_dointvec,
-       },
 #ifdef CONFIG_KMOD
        {
                .ctl_name       = KERN_MODPROBE,
@@ -645,6 +634,15 @@ static struct ctl_table kern_table[] = {
                .mode           = 0644,
                .proc_handler   = &proc_dointvec,
        },
+#if defined CONFIG_PRINTK
+       {
+               .ctl_name       = KERN_PRINTK,
+               .procname       = "printk",
+               .data           = &console_loglevel,
+               .maxlen         = 4*sizeof(int),
+               .mode           = 0644,
+               .proc_handler   = &proc_dointvec,
+       },
        {
                .ctl_name       = KERN_PRINTK_RATELIMIT,
                .procname       = "printk_ratelimit",
@@ -662,6 +660,7 @@ static struct ctl_table kern_table[] = {
                .mode           = 0644,
                .proc_handler   = &proc_dointvec,
        },
+#endif
        {
                .ctl_name       = KERN_NGROUPS_MAX,
                .procname       = "ngroups_max",
@@ -982,7 +981,7 @@ static struct ctl_table vm_table[] = {
                .data           = &nr_overcommit_huge_pages,
                .maxlen         = sizeof(nr_overcommit_huge_pages),
                .mode           = 0644,
-               .proc_handler   = &proc_doulongvec_minmax,
+               .proc_handler   = &hugetlb_overcommit_handler,
        },
 #endif
        {
@@ -2488,7 +2487,7 @@ static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp
        pid_t tmp;
        int r;
 
-       tmp = pid_nr_ns(cad_pid, current->nsproxy->pid_ns);
+       tmp = pid_vnr(cad_pid);
 
        r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
                               lenp, ppos, NULL, NULL);
index 006365b69eafdfcebbaa47ba1370a87d58813e94..c09350d564f2c4d3baa5b1510ed0d42aeabdc6ba 100644 (file)
@@ -8,10 +8,10 @@
 struct trans_ctl_table {
        int                     ctl_name;
        const char              *procname;
-       struct trans_ctl_table  *child;
+       const struct trans_ctl_table *child;
 };
 
-static struct trans_ctl_table trans_random_table[] = {
+static const struct trans_ctl_table trans_random_table[] = {
        { RANDOM_POOLSIZE,      "poolsize" },
        { RANDOM_ENTROPY_COUNT, "entropy_avail" },
        { RANDOM_READ_THRESH,   "read_wakeup_threshold" },
@@ -21,13 +21,13 @@ static struct trans_ctl_table trans_random_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_pty_table[] = {
+static const struct trans_ctl_table trans_pty_table[] = {
        { PTY_MAX,              "max" },
        { PTY_NR,               "nr" },
        {}
 };
 
-static struct trans_ctl_table trans_kern_table[] = {
+static const struct trans_ctl_table trans_kern_table[] = {
        { KERN_OSTYPE,                  "ostype" },
        { KERN_OSRELEASE,               "osrelease" },
        /* KERN_OSREV not used */
@@ -107,7 +107,7 @@ static struct trans_ctl_table trans_kern_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_vm_table[] = {
+static const struct trans_ctl_table trans_vm_table[] = {
        { VM_OVERCOMMIT_MEMORY,         "overcommit_memory" },
        { VM_PAGE_CLUSTER,              "page-cluster" },
        { VM_DIRTY_BACKGROUND,          "dirty_background_ratio" },
@@ -139,7 +139,7 @@ static struct trans_ctl_table trans_vm_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_core_table[] = {
+static const struct trans_ctl_table trans_net_core_table[] = {
        { NET_CORE_WMEM_MAX,            "wmem_max" },
        { NET_CORE_RMEM_MAX,            "rmem_max" },
        { NET_CORE_WMEM_DEFAULT,        "wmem_default" },
@@ -165,14 +165,14 @@ static struct trans_ctl_table trans_net_core_table[] = {
        {},
 };
 
-static struct trans_ctl_table trans_net_unix_table[] = {
+static const struct trans_ctl_table trans_net_unix_table[] = {
        /* NET_UNIX_DESTROY_DELAY unused */
        /* NET_UNIX_DELETE_DELAY unused */
        { NET_UNIX_MAX_DGRAM_QLEN,      "max_dgram_qlen" },
        {}
 };
 
-static struct trans_ctl_table trans_net_ipv4_route_table[] = {
+static const struct trans_ctl_table trans_net_ipv4_route_table[] = {
        { NET_IPV4_ROUTE_FLUSH,                 "flush" },
        { NET_IPV4_ROUTE_MIN_DELAY,             "min_delay" },
        { NET_IPV4_ROUTE_MAX_DELAY,             "max_delay" },
@@ -195,7 +195,7 @@ static struct trans_ctl_table trans_net_ipv4_route_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_ipv4_conf_vars_table[] = {
+static const struct trans_ctl_table trans_net_ipv4_conf_vars_table[] = {
        { NET_IPV4_CONF_FORWARDING,             "forwarding" },
        { NET_IPV4_CONF_MC_FORWARDING,          "mc_forwarding" },
 
@@ -222,14 +222,14 @@ static struct trans_ctl_table trans_net_ipv4_conf_vars_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_ipv4_conf_table[] = {
+static const struct trans_ctl_table trans_net_ipv4_conf_table[] = {
        { NET_PROTO_CONF_ALL,           "all",          trans_net_ipv4_conf_vars_table },
        { NET_PROTO_CONF_DEFAULT,       "default",      trans_net_ipv4_conf_vars_table },
        { 0, NULL, trans_net_ipv4_conf_vars_table },
        {}
 };
 
-static struct trans_ctl_table trans_net_neigh_vars_table[] = {
+static const struct trans_ctl_table trans_net_neigh_vars_table[] = {
        { NET_NEIGH_MCAST_SOLICIT,      "mcast_solicit" },
        { NET_NEIGH_UCAST_SOLICIT,      "ucast_solicit" },
        { NET_NEIGH_APP_SOLICIT,        "app_solicit" },
@@ -251,13 +251,13 @@ static struct trans_ctl_table trans_net_neigh_vars_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_neigh_table[] = {
+static const struct trans_ctl_table trans_net_neigh_table[] = {
        { NET_PROTO_CONF_DEFAULT, "default", trans_net_neigh_vars_table },
        { 0, NULL, trans_net_neigh_vars_table },
        {}
 };
 
-static struct trans_ctl_table trans_net_ipv4_netfilter_table[] = {
+static const struct trans_ctl_table trans_net_ipv4_netfilter_table[] = {
        { NET_IPV4_NF_CONNTRACK_MAX,                            "ip_conntrack_max" },
 
        { NET_IPV4_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,           "ip_conntrack_tcp_timeout_syn_sent" },
@@ -294,7 +294,7 @@ static struct trans_ctl_table trans_net_ipv4_netfilter_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_ipv4_table[] = {
+static const struct trans_ctl_table trans_net_ipv4_table[] = {
        { NET_IPV4_FORWARD,                     "ip_forward" },
        { NET_IPV4_DYNADDR,                     "ip_dynaddr" },
 
@@ -393,13 +393,13 @@ static struct trans_ctl_table trans_net_ipv4_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_ipx_table[] = {
+static const struct trans_ctl_table trans_net_ipx_table[] = {
        { NET_IPX_PPROP_BROADCASTING,   "ipx_pprop_broadcasting" },
        /* NET_IPX_FORWARDING unused */
        {}
 };
 
-static struct trans_ctl_table trans_net_atalk_table[] = {
+static const struct trans_ctl_table trans_net_atalk_table[] = {
        { NET_ATALK_AARP_EXPIRY_TIME,           "aarp-expiry-time" },
        { NET_ATALK_AARP_TICK_TIME,             "aarp-tick-time" },
        { NET_ATALK_AARP_RETRANSMIT_LIMIT,      "aarp-retransmit-limit" },
@@ -407,7 +407,7 @@ static struct trans_ctl_table trans_net_atalk_table[] = {
        {},
 };
 
-static struct trans_ctl_table trans_net_netrom_table[] = {
+static const struct trans_ctl_table trans_net_netrom_table[] = {
        { NET_NETROM_DEFAULT_PATH_QUALITY,              "default_path_quality" },
        { NET_NETROM_OBSOLESCENCE_COUNT_INITIALISER,    "obsolescence_count_initialiser" },
        { NET_NETROM_NETWORK_TTL_INITIALISER,           "network_ttl_initialiser" },
@@ -423,7 +423,7 @@ static struct trans_ctl_table trans_net_netrom_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_ax25_param_table[] = {
+static const struct trans_ctl_table trans_net_ax25_param_table[] = {
        { NET_AX25_IP_DEFAULT_MODE,     "ip_default_mode" },
        { NET_AX25_DEFAULT_MODE,        "ax25_default_mode" },
        { NET_AX25_BACKOFF_TYPE,        "backoff_type" },
@@ -441,12 +441,12 @@ static struct trans_ctl_table trans_net_ax25_param_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_ax25_table[] = {
+static const struct trans_ctl_table trans_net_ax25_table[] = {
        { 0, NULL, trans_net_ax25_param_table },
        {}
 };
 
-static struct trans_ctl_table trans_net_bridge_table[] = {
+static const struct trans_ctl_table trans_net_bridge_table[] = {
        { NET_BRIDGE_NF_CALL_ARPTABLES,         "bridge-nf-call-arptables" },
        { NET_BRIDGE_NF_CALL_IPTABLES,          "bridge-nf-call-iptables" },
        { NET_BRIDGE_NF_CALL_IP6TABLES,         "bridge-nf-call-ip6tables" },
@@ -455,7 +455,7 @@ static struct trans_ctl_table trans_net_bridge_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_rose_table[] = {
+static const struct trans_ctl_table trans_net_rose_table[] = {
        { NET_ROSE_RESTART_REQUEST_TIMEOUT,     "restart_request_timeout" },
        { NET_ROSE_CALL_REQUEST_TIMEOUT,        "call_request_timeout" },
        { NET_ROSE_RESET_REQUEST_TIMEOUT,       "reset_request_timeout" },
@@ -469,7 +469,7 @@ static struct trans_ctl_table trans_net_rose_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_ipv6_conf_var_table[] = {
+static const struct trans_ctl_table trans_net_ipv6_conf_var_table[] = {
        { NET_IPV6_FORWARDING,                  "forwarding" },
        { NET_IPV6_HOP_LIMIT,                   "hop_limit" },
        { NET_IPV6_MTU,                         "mtu" },
@@ -497,14 +497,14 @@ static struct trans_ctl_table trans_net_ipv6_conf_var_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_ipv6_conf_table[] = {
+static const struct trans_ctl_table trans_net_ipv6_conf_table[] = {
        { NET_PROTO_CONF_ALL,           "all",  trans_net_ipv6_conf_var_table },
        { NET_PROTO_CONF_DEFAULT,       "default", trans_net_ipv6_conf_var_table },
        { 0, NULL, trans_net_ipv6_conf_var_table },
        {}
 };
 
-static struct trans_ctl_table trans_net_ipv6_route_table[] = {
+static const struct trans_ctl_table trans_net_ipv6_route_table[] = {
        { NET_IPV6_ROUTE_FLUSH,                 "flush" },
        { NET_IPV6_ROUTE_GC_THRESH,             "gc_thresh" },
        { NET_IPV6_ROUTE_MAX_SIZE,              "max_size" },
@@ -518,12 +518,12 @@ static struct trans_ctl_table trans_net_ipv6_route_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_ipv6_icmp_table[] = {
+static const struct trans_ctl_table trans_net_ipv6_icmp_table[] = {
        { NET_IPV6_ICMP_RATELIMIT,      "ratelimit" },
        {}
 };
 
-static struct trans_ctl_table trans_net_ipv6_table[] = {
+static const struct trans_ctl_table trans_net_ipv6_table[] = {
        { NET_IPV6_CONF,                "conf",         trans_net_ipv6_conf_table },
        { NET_IPV6_NEIGH,               "neigh",        trans_net_neigh_table },
        { NET_IPV6_ROUTE,               "route",        trans_net_ipv6_route_table },
@@ -538,7 +538,7 @@ static struct trans_ctl_table trans_net_ipv6_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_x25_table[] = {
+static const struct trans_ctl_table trans_net_x25_table[] = {
        { NET_X25_RESTART_REQUEST_TIMEOUT,      "restart_request_timeout" },
        { NET_X25_CALL_REQUEST_TIMEOUT,         "call_request_timeout" },
        { NET_X25_RESET_REQUEST_TIMEOUT,        "reset_request_timeout" },
@@ -548,13 +548,13 @@ static struct trans_ctl_table trans_net_x25_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_tr_table[] = {
+static const struct trans_ctl_table trans_net_tr_table[] = {
        { NET_TR_RIF_TIMEOUT,   "rif_timeout" },
        {}
 };
 
 
-static struct trans_ctl_table trans_net_decnet_conf_vars[] = {
+static const struct trans_ctl_table trans_net_decnet_conf_vars[] = {
        { NET_DECNET_CONF_DEV_FORWARDING,       "forwarding" },
        { NET_DECNET_CONF_DEV_PRIORITY,         "priority" },
        { NET_DECNET_CONF_DEV_T2,               "t2" },
@@ -562,12 +562,12 @@ static struct trans_ctl_table trans_net_decnet_conf_vars[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_decnet_conf[] = {
+static const struct trans_ctl_table trans_net_decnet_conf[] = {
        { 0, NULL, trans_net_decnet_conf_vars },
        {}
 };
 
-static struct trans_ctl_table trans_net_decnet_table[] = {
+static const struct trans_ctl_table trans_net_decnet_table[] = {
        { NET_DECNET_CONF,              "conf", trans_net_decnet_conf },
        { NET_DECNET_NODE_ADDRESS,      "node_address" },
        { NET_DECNET_NODE_NAME,         "node_name" },
@@ -585,7 +585,7 @@ static struct trans_ctl_table trans_net_decnet_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_sctp_table[] = {
+static const struct trans_ctl_table trans_net_sctp_table[] = {
        { NET_SCTP_RTO_INITIAL,         "rto_initial" },
        { NET_SCTP_RTO_MIN,             "rto_min" },
        { NET_SCTP_RTO_MAX,             "rto_max" },
@@ -606,7 +606,7 @@ static struct trans_ctl_table trans_net_sctp_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_llc_llc2_timeout_table[] = {
+static const struct trans_ctl_table trans_net_llc_llc2_timeout_table[] = {
        { NET_LLC2_ACK_TIMEOUT,         "ack" },
        { NET_LLC2_P_TIMEOUT,           "p" },
        { NET_LLC2_REJ_TIMEOUT,         "rej" },
@@ -614,23 +614,23 @@ static struct trans_ctl_table trans_net_llc_llc2_timeout_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_llc_station_table[] = {
+static const struct trans_ctl_table trans_net_llc_station_table[] = {
        { NET_LLC_STATION_ACK_TIMEOUT,  "ack_timeout" },
        {}
 };
 
-static struct trans_ctl_table trans_net_llc_llc2_table[] = {
+static const struct trans_ctl_table trans_net_llc_llc2_table[] = {
        { NET_LLC2,             "timeout",      trans_net_llc_llc2_timeout_table },
        {}
 };
 
-static struct trans_ctl_table trans_net_llc_table[] = {
+static const struct trans_ctl_table trans_net_llc_table[] = {
        { NET_LLC2,             "llc2",         trans_net_llc_llc2_table },
        { NET_LLC_STATION,      "station",      trans_net_llc_station_table },
        {}
 };
 
-static struct trans_ctl_table trans_net_netfilter_table[] = {
+static const struct trans_ctl_table trans_net_netfilter_table[] = {
        { NET_NF_CONNTRACK_MAX,                         "nf_conntrack_max" },
        { NET_NF_CONNTRACK_TCP_TIMEOUT_SYN_SENT,        "nf_conntrack_tcp_timeout_syn_sent" },
        { NET_NF_CONNTRACK_TCP_TIMEOUT_SYN_RECV,        "nf_conntrack_tcp_timeout_syn_recv" },
@@ -667,12 +667,12 @@ static struct trans_ctl_table trans_net_netfilter_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_dccp_table[] = {
+static const struct trans_ctl_table trans_net_dccp_table[] = {
        { NET_DCCP_DEFAULT,     "default" },
        {}
 };
 
-static struct trans_ctl_table trans_net_irda_table[] = {
+static const struct trans_ctl_table trans_net_irda_table[] = {
        { NET_IRDA_DISCOVERY,           "discovery" },
        { NET_IRDA_DEVNAME,             "devname" },
        { NET_IRDA_DEBUG,               "debug" },
@@ -690,7 +690,7 @@ static struct trans_ctl_table trans_net_irda_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_net_table[] = {
+static const struct trans_ctl_table trans_net_table[] = {
        { NET_CORE,             "core",         trans_net_core_table },
        /* NET_ETHER not used */
        /* NET_802 not used */
@@ -716,7 +716,7 @@ static struct trans_ctl_table trans_net_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_fs_quota_table[] = {
+static const struct trans_ctl_table trans_fs_quota_table[] = {
        { FS_DQ_LOOKUPS,        "lookups" },
        { FS_DQ_DROPS,          "drops" },
        { FS_DQ_READS,          "reads" },
@@ -729,7 +729,7 @@ static struct trans_ctl_table trans_fs_quota_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_fs_xfs_table[] = {
+static const struct trans_ctl_table trans_fs_xfs_table[] = {
        { XFS_RESTRICT_CHOWN,   "restrict_chown" },
        { XFS_SGID_INHERIT,     "irix_sgid_inherit" },
        { XFS_SYMLINK_MODE,     "irix_symlink_mode" },
@@ -750,24 +750,24 @@ static struct trans_ctl_table trans_fs_xfs_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_fs_ocfs2_nm_table[] = {
+static const struct trans_ctl_table trans_fs_ocfs2_nm_table[] = {
        { 1, "hb_ctl_path" },
        {}
 };
 
-static struct trans_ctl_table trans_fs_ocfs2_table[] = {
+static const struct trans_ctl_table trans_fs_ocfs2_table[] = {
        { 1,    "nm",   trans_fs_ocfs2_nm_table },
        {}
 };
 
-static struct trans_ctl_table trans_inotify_table[] = {
+static const struct trans_ctl_table trans_inotify_table[] = {
        { INOTIFY_MAX_USER_INSTANCES,   "max_user_instances" },
        { INOTIFY_MAX_USER_WATCHES,     "max_user_watches" },
        { INOTIFY_MAX_QUEUED_EVENTS,    "max_queued_events" },
        {}
 };
 
-static struct trans_ctl_table trans_fs_table[] = {
+static const struct trans_ctl_table trans_fs_table[] = {
        { FS_NRINODE,           "inode-nr" },
        { FS_STATINODE,         "inode-state" },
        /* FS_MAXINODE unused */
@@ -793,11 +793,11 @@ static struct trans_ctl_table trans_fs_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_debug_table[] = {
+static const struct trans_ctl_table trans_debug_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_cdrom_table[] = {
+static const struct trans_ctl_table trans_cdrom_table[] = {
        { DEV_CDROM_INFO,               "info" },
        { DEV_CDROM_AUTOCLOSE,          "autoclose" },
        { DEV_CDROM_AUTOEJECT,          "autoeject" },
@@ -807,12 +807,12 @@ static struct trans_ctl_table trans_cdrom_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_ipmi_table[] = {
+static const struct trans_ctl_table trans_ipmi_table[] = {
        { DEV_IPMI_POWEROFF_POWERCYCLE, "poweroff_powercycle" },
        {}
 };
 
-static struct trans_ctl_table trans_mac_hid_files[] = {
+static const struct trans_ctl_table trans_mac_hid_files[] = {
        /* DEV_MAC_HID_KEYBOARD_SENDS_LINUX_KEYCODES unused */
        /* DEV_MAC_HID_KEYBOARD_LOCK_KEYCODES unused */
        { DEV_MAC_HID_MOUSE_BUTTON_EMULATION,   "mouse_button_emulation" },
@@ -822,35 +822,35 @@ static struct trans_ctl_table trans_mac_hid_files[] = {
        {}
 };
 
-static struct trans_ctl_table trans_raid_table[] = {
+static const struct trans_ctl_table trans_raid_table[] = {
        { DEV_RAID_SPEED_LIMIT_MIN,     "speed_limit_min" },
        { DEV_RAID_SPEED_LIMIT_MAX,     "speed_limit_max" },
        {}
 };
 
-static struct trans_ctl_table trans_scsi_table[] = {
+static const struct trans_ctl_table trans_scsi_table[] = {
        { DEV_SCSI_LOGGING_LEVEL, "logging_level" },
        {}
 };
 
-static struct trans_ctl_table trans_parport_default_table[] = {
+static const struct trans_ctl_table trans_parport_default_table[] = {
        { DEV_PARPORT_DEFAULT_TIMESLICE,        "timeslice" },
        { DEV_PARPORT_DEFAULT_SPINTIME,         "spintime" },
        {}
 };
 
-static struct trans_ctl_table trans_parport_device_table[] = {
+static const struct trans_ctl_table trans_parport_device_table[] = {
        { DEV_PARPORT_DEVICE_TIMESLICE,         "timeslice" },
        {}
 };
 
-static struct trans_ctl_table trans_parport_devices_table[] = {
+static const struct trans_ctl_table trans_parport_devices_table[] = {
        { DEV_PARPORT_DEVICES_ACTIVE,           "active" },
        { 0, NULL, trans_parport_device_table },
        {}
 };
 
-static struct trans_ctl_table trans_parport_parport_table[] = {
+static const struct trans_ctl_table trans_parport_parport_table[] = {
        { DEV_PARPORT_SPINTIME,         "spintime" },
        { DEV_PARPORT_BASE_ADDR,        "base-addr" },
        { DEV_PARPORT_IRQ,              "irq" },
@@ -864,13 +864,13 @@ static struct trans_ctl_table trans_parport_parport_table[] = {
        { DEV_PARPORT_AUTOPROBE + 4,    "autoprobe3" },
        {}
 };
-static struct trans_ctl_table trans_parport_table[] = {
+static const struct trans_ctl_table trans_parport_table[] = {
        { DEV_PARPORT_DEFAULT,  "default",      trans_parport_default_table },
        { 0, NULL, trans_parport_parport_table },
        {}
 };
 
-static struct trans_ctl_table trans_dev_table[] = {
+static const struct trans_ctl_table trans_dev_table[] = {
        { DEV_CDROM,    "cdrom",        trans_cdrom_table },
        /* DEV_HWMON unused */
        { DEV_PARPORT,  "parport",      trans_parport_table },
@@ -881,19 +881,19 @@ static struct trans_ctl_table trans_dev_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_bus_isa_table[] = {
+static const struct trans_ctl_table trans_bus_isa_table[] = {
        { BUS_ISA_MEM_BASE,     "membase" },
        { BUS_ISA_PORT_BASE,    "portbase" },
        { BUS_ISA_PORT_SHIFT,   "portshift" },
        {}
 };
 
-static struct trans_ctl_table trans_bus_table[] = {
+static const struct trans_ctl_table trans_bus_table[] = {
        { CTL_BUS_ISA,  "isa",  trans_bus_isa_table },
        {}
 };
 
-static struct trans_ctl_table trans_arlan_conf_table0[] = {
+static const struct trans_ctl_table trans_arlan_conf_table0[] = {
        { 1,    "spreadingCode" },
        { 2,    "channelNumber" },
        { 3,    "scramblingDisable" },
@@ -964,7 +964,7 @@ static struct trans_ctl_table trans_arlan_conf_table0[] = {
        {}
 };
 
-static struct trans_ctl_table trans_arlan_conf_table1[] = {
+static const struct trans_ctl_table trans_arlan_conf_table1[] = {
        { 1,    "spreadingCode" },
        { 2,    "channelNumber" },
        { 3,    "scramblingDisable" },
@@ -1035,7 +1035,7 @@ static struct trans_ctl_table trans_arlan_conf_table1[] = {
        {}
 };
 
-static struct trans_ctl_table trans_arlan_conf_table2[] = {
+static const struct trans_ctl_table trans_arlan_conf_table2[] = {
        { 1,    "spreadingCode" },
        { 2,    "channelNumber" },
        { 3,    "scramblingDisable" },
@@ -1106,7 +1106,7 @@ static struct trans_ctl_table trans_arlan_conf_table2[] = {
        {}
 };
 
-static struct trans_ctl_table trans_arlan_conf_table3[] = {
+static const struct trans_ctl_table trans_arlan_conf_table3[] = {
        { 1,    "spreadingCode" },
        { 2,    "channelNumber" },
        { 3,    "scramblingDisable" },
@@ -1177,7 +1177,7 @@ static struct trans_ctl_table trans_arlan_conf_table3[] = {
        {}
 };
 
-static struct trans_ctl_table trans_arlan_table[] = {
+static const struct trans_ctl_table trans_arlan_table[] = {
        { 1,            "arlan0",       trans_arlan_conf_table0 },
        { 2,            "arlan1",       trans_arlan_conf_table1 },
        { 3,            "arlan2",       trans_arlan_conf_table2 },
@@ -1185,13 +1185,13 @@ static struct trans_ctl_table trans_arlan_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_s390dbf_table[] = {
+static const struct trans_ctl_table trans_s390dbf_table[] = {
        { 5678 /* CTL_S390DBF_STOPPABLE */,     "debug_stoppable" },
        { 5679 /* CTL_S390DBF_ACTIVE */,        "debug_active" },
        {}
 };
 
-static struct trans_ctl_table trans_sunrpc_table[] = {
+static const struct trans_ctl_table trans_sunrpc_table[] = {
        { CTL_RPCDEBUG,         "rpc_debug" },
        { CTL_NFSDEBUG,         "nfs_debug" },
        { CTL_NFSDDEBUG,        "nfsd_debug" },
@@ -1203,7 +1203,7 @@ static struct trans_ctl_table trans_sunrpc_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_pm_table[] = {
+static const struct trans_ctl_table trans_pm_table[] = {
        { 1 /* CTL_PM_SUSPEND */,       "suspend" },
        { 2 /* CTL_PM_CMODE */,         "cmode" },
        { 3 /* CTL_PM_P0 */,            "p0" },
@@ -1211,13 +1211,13 @@ static struct trans_ctl_table trans_pm_table[] = {
        {}
 };
 
-static struct trans_ctl_table trans_frv_table[] = {
+static const struct trans_ctl_table trans_frv_table[] = {
        { 1,    "cache-mode" },
        { 2,    "pin-cxnr" },
        {}
 };
 
-static struct trans_ctl_table trans_root_table[] = {
+static const struct trans_ctl_table trans_root_table[] = {
        { CTL_KERN,     "kernel",       trans_kern_table },
        { CTL_VM,       "vm",           trans_vm_table },
        { CTL_NET,      "net",          trans_net_table },
@@ -1261,15 +1261,14 @@ static struct ctl_table *sysctl_parent(struct ctl_table *table, int n)
        return table;
 }
 
-static struct trans_ctl_table *sysctl_binary_lookup(struct ctl_table *table)
+static const struct trans_ctl_table *sysctl_binary_lookup(struct ctl_table *table)
 {
        struct ctl_table *test;
-       struct trans_ctl_table *ref;
-       int depth, cur_depth;
+       const struct trans_ctl_table *ref;
+       int cur_depth;
 
-       depth = sysctl_depth(table);
+       cur_depth = sysctl_depth(table);
 
-       cur_depth = depth;
        ref = trans_root_table;
 repeat:
        test = sysctl_parent(table, cur_depth);
@@ -1437,7 +1436,7 @@ static void sysctl_check_leaf(struct nsproxy *namespaces,
 
 static void sysctl_check_bin_path(struct ctl_table *table, const char **fail)
 {
-       struct trans_ctl_table *ref;
+       const struct trans_ctl_table *ref;
 
        ref = sysctl_binary_lookup(table);
        if (table->ctl_name && !ref)
index 33af3e55570dfc5d8fe74aba067d2e26591c1a91..a5ec013b6c807be91292179023406e995f765fb2 100644 (file)
@@ -39,6 +39,8 @@
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
 
+#include "timeconst.h"
+
 /*
  * The timezone where the local system is located.  Used as a default by some
  * programs who obtain this value by using gettimeofday.
@@ -93,7 +95,8 @@ asmlinkage long sys_stime(time_t __user *tptr)
 
 #endif /* __ARCH_WANT_SYS_TIME */
 
-asmlinkage long sys_gettimeofday(struct timeval __user *tv, struct timezone __user *tz)
+asmlinkage long sys_gettimeofday(struct timeval __user *tv,
+                                struct timezone __user *tz)
 {
        if (likely(tv != NULL)) {
                struct timeval ktv;
@@ -118,7 +121,7 @@ asmlinkage long sys_gettimeofday(struct timeval __user *tv, struct timezone __us
  * hard to make the program warp the clock precisely n hours)  or
  * compile in the timezone information into the kernel.  Bad, bad....
  *
- *                                             - TYT, 1992-01-01
+ *                                             - TYT, 1992-01-01
  *
  * The best thing to do is to keep the CMOS clock in universal time (UTC)
  * as real UNIX machines always do it. This avoids all headaches about
@@ -240,7 +243,11 @@ unsigned int inline jiffies_to_msecs(const unsigned long j)
 #elif HZ > MSEC_PER_SEC && !(HZ % MSEC_PER_SEC)
        return (j + (HZ / MSEC_PER_SEC) - 1)/(HZ / MSEC_PER_SEC);
 #else
-       return (j * MSEC_PER_SEC) / HZ;
+# if BITS_PER_LONG == 32
+       return ((u64)HZ_TO_MSEC_MUL32 * j) >> HZ_TO_MSEC_SHR32;
+# else
+       return (j * HZ_TO_MSEC_NUM) / HZ_TO_MSEC_DEN;
+# endif
 #endif
 }
 EXPORT_SYMBOL(jiffies_to_msecs);
@@ -252,7 +259,11 @@ unsigned int inline jiffies_to_usecs(const unsigned long j)
 #elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
        return (j + (HZ / USEC_PER_SEC) - 1)/(HZ / USEC_PER_SEC);
 #else
-       return (j * USEC_PER_SEC) / HZ;
+# if BITS_PER_LONG == 32
+       return ((u64)HZ_TO_USEC_MUL32 * j) >> HZ_TO_USEC_SHR32;
+# else
+       return (j * HZ_TO_USEC_NUM) / HZ_TO_USEC_DEN;
+# endif
 #endif
 }
 EXPORT_SYMBOL(jiffies_to_usecs);
@@ -267,7 +278,7 @@ EXPORT_SYMBOL(jiffies_to_usecs);
  *
  * This function should be only used for timestamps returned by
  * current_kernel_time() or CURRENT_TIME, not with do_gettimeofday() because
- * it doesn't handle the better resolution of the later.
+ * it doesn't handle the better resolution of the latter.
  */
 struct timespec timespec_trunc(struct timespec t, unsigned gran)
 {
@@ -315,7 +326,7 @@ EXPORT_SYMBOL_GPL(getnstimeofday);
  * This algorithm was first published by Gauss (I think).
  *
  * WARNING: this function will overflow on 2106-02-07 06:28:16 on
- * machines were long is 32-bit! (However, as time_t is signed, we
+ * machines where long is 32-bit! (However, as time_t is signed, we
  * will already get problems at other places on 2038-01-19 03:14:08)
  */
 unsigned long
@@ -352,7 +363,7 @@ EXPORT_SYMBOL(mktime);
  * normalize to the timespec storage format
  *
  * Note: The tv_nsec part is always in the range of
- *     0 <= tv_nsec < NSEC_PER_SEC
+ *     0 <= tv_nsec < NSEC_PER_SEC
  * For negative values only the tv_sec field is negative !
  */
 void set_normalized_timespec(struct timespec *ts, time_t sec, long nsec)
@@ -453,12 +464,13 @@ unsigned long msecs_to_jiffies(const unsigned int m)
        /*
         * Generic case - multiply, round and divide. But first
         * check that if we are doing a net multiplication, that
-        * we wouldnt overflow:
+        * we wouldn't overflow:
         */
        if (HZ > MSEC_PER_SEC && m > jiffies_to_msecs(MAX_JIFFY_OFFSET))
                return MAX_JIFFY_OFFSET;
 
-       return (m * HZ + MSEC_PER_SEC - 1) / MSEC_PER_SEC;
+       return ((u64)MSEC_TO_HZ_MUL32 * m + MSEC_TO_HZ_ADJ32)
+               >> MSEC_TO_HZ_SHR32;
 #endif
 }
 EXPORT_SYMBOL(msecs_to_jiffies);
@@ -472,7 +484,8 @@ unsigned long usecs_to_jiffies(const unsigned int u)
 #elif HZ > USEC_PER_SEC && !(HZ % USEC_PER_SEC)
        return u * (HZ / USEC_PER_SEC);
 #else
-       return (u * HZ + USEC_PER_SEC - 1) / USEC_PER_SEC;
+       return ((u64)USEC_TO_HZ_MUL32 * u + USEC_TO_HZ_ADJ32)
+               >> USEC_TO_HZ_SHR32;
 #endif
 }
 EXPORT_SYMBOL(usecs_to_jiffies);
index 3e59fce6dd432e5b2f85c660c4ebaf40f70fd921..3d1e3e1a19716e94cdad4116b1ca73242ac45f1e 100644 (file)
@@ -133,7 +133,7 @@ static void clockevents_do_notify(unsigned long reason, void *dev)
 }
 
 /*
- * Called after a notify add to make devices availble which were
+ * Called after a notify add to make devices available which were
  * released from the notifier call.
  */
 static void clockevents_notify_released(void)
@@ -218,6 +218,8 @@ void clockevents_exchange_device(struct clock_event_device *old,
  */
 void clockevents_notify(unsigned long reason, void *arg)
 {
+       struct list_head *node, *tmp;
+
        spin_lock(&clockevents_lock);
        clockevents_do_notify(reason, arg);
 
@@ -227,13 +229,8 @@ void clockevents_notify(unsigned long reason, void *arg)
                 * Unregister the clock event devices which were
                 * released from the users in the notify chain.
                 */
-               while (!list_empty(&clockevents_released)) {
-                       struct clock_event_device *dev;
-
-                       dev = list_entry(clockevents_released.next,
-                                        struct clock_event_device, list);
-                       list_del(&dev->list);
-               }
+               list_for_each_safe(node, tmp, &clockevents_released)
+                       list_del(node);
                break;
        default:
                break;
index 81afb3927eccca2a8f684eb41508740779ed102a..548c436a776bd35b40b7e9143f24a2743246650b 100644 (file)
@@ -91,7 +91,6 @@ static void clocksource_ratewd(struct clocksource *cs, int64_t delta)
               cs->name, delta);
        cs->flags &= ~(CLOCK_SOURCE_VALID_FOR_HRES | CLOCK_SOURCE_WATCHDOG);
        clocksource_change_rating(cs, 0);
-       cs->flags &= ~CLOCK_SOURCE_WATCHDOG;
        list_del(&cs->wd_list);
 }
 
index 88267f0a84713082dfb8ca719a76337b69990f04..fa9bb73dbdb41c4678ca0ad1da01ebcaf5e46cc1 100644 (file)
@@ -681,7 +681,7 @@ int tick_check_oneshot_change(int allow_nohz)
        if (ts->nohz_mode != NOHZ_MODE_INACTIVE)
                return 0;
 
-       if (!timekeeping_is_continuous() || !tick_is_oneshot_available())
+       if (!timekeeping_valid_for_hres() || !tick_is_oneshot_available())
                return 0;
 
        if (!allow_nohz)
index cd5dbc4579c9bd3058063450b08e732c31e14ddf..1af9fb050fe28b1e77ae9f43c3005e16972b2d65 100644 (file)
@@ -201,9 +201,9 @@ static inline s64 __get_nsec_offset(void) { return 0; }
 #endif
 
 /**
- * timekeeping_is_continuous - check to see if timekeeping is free running
+ * timekeeping_valid_for_hres - Check if timekeeping is suitable for hres
  */
-int timekeeping_is_continuous(void)
+int timekeeping_valid_for_hres(void)
 {
        unsigned long seq;
        int ret;
@@ -364,7 +364,7 @@ static __always_inline int clocksource_bigadjust(s64 error, s64 *interval,
         * with losing too many ticks, otherwise we would overadjust and
         * produce an even larger error.  The smaller the adjustment the
         * faster we try to adjust for it, as lost ticks can do less harm
-        * here.  This is tuned so that an error of about 1 msec is adusted
+        * here.  This is tuned so that an error of about 1 msec is adjusted
         * within about 1 sec (or 2^20 nsec in 2^SHIFT_HZ ticks).
         */
        error2 = clock->error >> (TICK_LENGTH_SHIFT + 22 - 2 * SHIFT_HZ);
diff --git a/kernel/timeconst.pl b/kernel/timeconst.pl
new file mode 100644 (file)
index 0000000..62b1287
--- /dev/null
@@ -0,0 +1,402 @@
+#!/usr/bin/perl
+# -----------------------------------------------------------------------
+#
+#   Copyright 2007 rPath, Inc. - All Rights Reserved
+#
+#   This file is part of the Linux kernel, and is made available under
+#   the terms of the GNU General Public License version 2 or (at your
+#   option) any later version; incorporated herein by reference.
+#
+# -----------------------------------------------------------------------
+#
+
+#
+# Usage: timeconst.pl HZ > timeconst.h
+#
+
+# Precomputed values for systems without Math::BigInt
+# Generated by:
+# timeconst.pl --can 24 32 48 64 100 122 128 200 250 256 300 512 1000 1024 1200
+%canned_values = (
+       24 => [
+               '0xa6aaaaab','0x2aaaaaa',26,
+               '0xa6aaaaaaaaaaaaab','0x2aaaaaaaaaaaaaa',58,
+               125,3,
+               '0xc49ba5e4','0x1fbe76c8b4',37,
+               '0xc49ba5e353f7ceda','0x1fbe76c8b439581062',69,
+               3,125,
+               '0xa2c2aaab','0xaaaa',16,
+               '0xa2c2aaaaaaaaaaab','0xaaaaaaaaaaaa',48,
+               125000,3,
+               '0xc9539b89','0x7fffbce4217d',47,
+               '0xc9539b8887229e91','0x7fffbce4217d2849cb25',79,
+               3,125000,
+       ], 32 => [
+               '0xfa000000','0x6000000',27,
+               '0xfa00000000000000','0x600000000000000',59,
+               125,4,
+               '0x83126e98','0xfdf3b645a',36,
+               '0x83126e978d4fdf3c','0xfdf3b645a1cac0831',68,
+               4,125,
+               '0xf4240000','0x0',17,
+               '0xf424000000000000','0x0',49,
+               31250,1,
+               '0x8637bd06','0x3fff79c842fa',46,
+               '0x8637bd05af6c69b6','0x3fff79c842fa5093964a',78,
+               1,31250,
+       ], 48 => [
+               '0xa6aaaaab','0x6aaaaaa',27,
+               '0xa6aaaaaaaaaaaaab','0x6aaaaaaaaaaaaaa',59,
+               125,6,
+               '0xc49ba5e4','0xfdf3b645a',36,
+               '0xc49ba5e353f7ceda','0xfdf3b645a1cac0831',68,
+               6,125,
+               '0xa2c2aaab','0x15555',17,
+               '0xa2c2aaaaaaaaaaab','0x1555555555555',49,
+               62500,3,
+               '0xc9539b89','0x3fffbce4217d',46,
+               '0xc9539b8887229e91','0x3fffbce4217d2849cb25',78,
+               3,62500,
+       ], 64 => [
+               '0xfa000000','0xe000000',28,
+               '0xfa00000000000000','0xe00000000000000',60,
+               125,8,
+               '0x83126e98','0x7ef9db22d',35,
+               '0x83126e978d4fdf3c','0x7ef9db22d0e560418',67,
+               8,125,
+               '0xf4240000','0x0',18,
+               '0xf424000000000000','0x0',50,
+               15625,1,
+               '0x8637bd06','0x1fff79c842fa',45,
+               '0x8637bd05af6c69b6','0x1fff79c842fa5093964a',77,
+               1,15625,
+       ], 100 => [
+               '0xa0000000','0x0',28,
+               '0xa000000000000000','0x0',60,
+               10,1,
+               '0xcccccccd','0x733333333',35,
+               '0xcccccccccccccccd','0x73333333333333333',67,
+               1,10,
+               '0x9c400000','0x0',18,
+               '0x9c40000000000000','0x0',50,
+               10000,1,
+               '0xd1b71759','0x1fff2e48e8a7',45,
+               '0xd1b71758e219652c','0x1fff2e48e8a71de69ad4',77,
+               1,10000,
+       ], 122 => [
+               '0x8325c53f','0xfbcda3a',28,
+               '0x8325c53ef368eb05','0xfbcda3ac10c9714',60,
+               500,61,
+               '0xf9db22d1','0x7fbe76c8b',35,
+               '0xf9db22d0e560418a','0x7fbe76c8b43958106',67,
+               61,500,
+               '0x8012e2a0','0x3ef36',18,
+               '0x8012e29f79b47583','0x3ef368eb04325',50,
+               500000,61,
+               '0xffda4053','0x1ffffbce4217',45,
+               '0xffda4052d666a983','0x1ffffbce4217d2849cb2',77,
+               61,500000,
+       ], 128 => [
+               '0xfa000000','0x1e000000',29,
+               '0xfa00000000000000','0x1e00000000000000',61,
+               125,16,
+               '0x83126e98','0x3f7ced916',34,
+               '0x83126e978d4fdf3c','0x3f7ced916872b020c',66,
+               16,125,
+               '0xf4240000','0x40000',19,
+               '0xf424000000000000','0x4000000000000',51,
+               15625,2,
+               '0x8637bd06','0xfffbce4217d',44,
+               '0x8637bd05af6c69b6','0xfffbce4217d2849cb25',76,
+               2,15625,
+       ], 200 => [
+               '0xa0000000','0x0',29,
+               '0xa000000000000000','0x0',61,
+               5,1,
+               '0xcccccccd','0x333333333',34,
+               '0xcccccccccccccccd','0x33333333333333333',66,
+               1,5,
+               '0x9c400000','0x0',19,
+               '0x9c40000000000000','0x0',51,
+               5000,1,
+               '0xd1b71759','0xfff2e48e8a7',44,
+               '0xd1b71758e219652c','0xfff2e48e8a71de69ad4',76,
+               1,5000,
+       ], 250 => [
+               '0x80000000','0x0',29,
+               '0x8000000000000000','0x0',61,
+               4,1,
+               '0x80000000','0x180000000',33,
+               '0x8000000000000000','0x18000000000000000',65,
+               1,4,
+               '0xfa000000','0x0',20,
+               '0xfa00000000000000','0x0',52,
+               4000,1,
+               '0x83126e98','0x7ff7ced9168',43,
+               '0x83126e978d4fdf3c','0x7ff7ced916872b020c4',75,
+               1,4000,
+       ], 256 => [
+               '0xfa000000','0x3e000000',30,
+               '0xfa00000000000000','0x3e00000000000000',62,
+               125,32,
+               '0x83126e98','0x1fbe76c8b',33,
+               '0x83126e978d4fdf3c','0x1fbe76c8b43958106',65,
+               32,125,
+               '0xf4240000','0xc0000',20,
+               '0xf424000000000000','0xc000000000000',52,
+               15625,4,
+               '0x8637bd06','0x7ffde7210be',43,
+               '0x8637bd05af6c69b6','0x7ffde7210be9424e592',75,
+               4,15625,
+       ], 300 => [
+               '0xd5555556','0x2aaaaaaa',30,
+               '0xd555555555555556','0x2aaaaaaaaaaaaaaa',62,
+               10,3,
+               '0x9999999a','0x1cccccccc',33,
+               '0x999999999999999a','0x1cccccccccccccccc',65,
+               3,10,
+               '0xd0555556','0xaaaaa',20,
+               '0xd055555555555556','0xaaaaaaaaaaaaa',52,
+               10000,3,
+               '0x9d495183','0x7ffcb923a29',43,
+               '0x9d495182a9930be1','0x7ffcb923a29c779a6b5',75,
+               3,10000,
+       ], 512 => [
+               '0xfa000000','0x7e000000',31,
+               '0xfa00000000000000','0x7e00000000000000',63,
+               125,64,
+               '0x83126e98','0xfdf3b645',32,
+               '0x83126e978d4fdf3c','0xfdf3b645a1cac083',64,
+               64,125,
+               '0xf4240000','0x1c0000',21,
+               '0xf424000000000000','0x1c000000000000',53,
+               15625,8,
+               '0x8637bd06','0x3ffef39085f',42,
+               '0x8637bd05af6c69b6','0x3ffef39085f4a1272c9',74,
+               8,15625,
+       ], 1000 => [
+               '0x80000000','0x0',31,
+               '0x8000000000000000','0x0',63,
+               1,1,
+               '0x80000000','0x0',31,
+               '0x8000000000000000','0x0',63,
+               1,1,
+               '0xfa000000','0x0',22,
+               '0xfa00000000000000','0x0',54,
+               1000,1,
+               '0x83126e98','0x1ff7ced9168',41,
+               '0x83126e978d4fdf3c','0x1ff7ced916872b020c4',73,
+               1,1000,
+       ], 1024 => [
+               '0xfa000000','0xfe000000',32,
+               '0xfa00000000000000','0xfe00000000000000',64,
+               125,128,
+               '0x83126e98','0x7ef9db22',31,
+               '0x83126e978d4fdf3c','0x7ef9db22d0e56041',63,
+               128,125,
+               '0xf4240000','0x3c0000',22,
+               '0xf424000000000000','0x3c000000000000',54,
+               15625,16,
+               '0x8637bd06','0x1fff79c842f',41,
+               '0x8637bd05af6c69b6','0x1fff79c842fa5093964',73,
+               16,15625,
+       ], 1200 => [
+               '0xd5555556','0xd5555555',32,
+               '0xd555555555555556','0xd555555555555555',64,
+               5,6,
+               '0x9999999a','0x66666666',31,
+               '0x999999999999999a','0x6666666666666666',63,
+               6,5,
+               '0xd0555556','0x2aaaaa',22,
+               '0xd055555555555556','0x2aaaaaaaaaaaaa',54,
+               2500,3,
+               '0x9d495183','0x1ffcb923a29',41,
+               '0x9d495182a9930be1','0x1ffcb923a29c779a6b5',73,
+               3,2500,
+       ]
+);
+
+$has_bigint = eval 'use Math::BigInt qw(bgcd); 1;';
+
+sub bint($)
+{
+       my($x) = @_;
+       return Math::BigInt->new($x);
+}
+
+#
+# Constants for division by reciprocal multiplication.
+# (bits, numerator, denominator)
+#
+sub fmul($$$)
+{
+       my ($b,$n,$d) = @_;
+
+       $n = bint($n);
+       $d = bint($d);
+
+       return scalar (($n << $b)+$d-bint(1))/$d;
+}
+
+sub fadj($$$)
+{
+       my($b,$n,$d) = @_;
+
+       $n = bint($n);
+       $d = bint($d);
+
+       $d = $d/bgcd($n, $d);
+       return scalar (($d-bint(1)) << $b)/$d;
+}
+
+sub fmuls($$$) {
+       my($b,$n,$d) = @_;
+       my($s,$m);
+       my($thres) = bint(1) << ($b-1);
+
+       $n = bint($n);
+       $d = bint($d);
+
+       for ($s = 0; 1; $s++) {
+               $m = fmul($s,$n,$d);
+               return $s if ($m >= $thres);
+       }
+       return 0;
+}
+
+# Provides mul, adj, and shr factors for a specific
+# (bit, time, hz) combination
+sub muladj($$$) {
+       my($b, $t, $hz) = @_;
+       my $s = fmuls($b, $t, $hz);
+       my $m = fmul($s, $t, $hz);
+       my $a = fadj($s, $t, $hz);
+       return ($m->as_hex(), $a->as_hex(), $s);
+}
+
+# Provides numerator, denominator values
+sub numden($$) {
+       my($n, $d) = @_;
+       my $g = bgcd($n, $d);
+       return ($n/$g, $d/$g);
+}
+
+# All values for a specific (time, hz) combo
+sub conversions($$) {
+       my ($t, $hz) = @_;
+       my @val = ();
+
+       # HZ_TO_xx
+       push(@val, muladj(32, $t, $hz));
+       push(@val, muladj(64, $t, $hz));
+       push(@val, numden($t, $hz));
+
+       # xx_TO_HZ
+       push(@val, muladj(32, $hz, $t));
+       push(@val, muladj(64, $hz, $t));
+       push(@val, numden($hz, $t));
+
+       return @val;
+}
+
+sub compute_values($) {
+       my($hz) = @_;
+       my @val = ();
+       my $s, $m, $a, $g;
+
+       if (!$has_bigint) {
+               die "$0: HZ == $hz not canned and ".
+                   "Math::BigInt not available\n";
+       }
+
+       # MSEC conversions
+       push(@val, conversions(1000, $hz));
+
+       # USEC conversions
+       push(@val, conversions(1000000, $hz));
+
+       return @val;
+}
+
+sub output($@)
+{
+       my($hz, @val) = @_;
+       my $pfx, $bit, $suf, $s, $m, $a;
+
+       print "/* Automatically generated by kernel/timeconst.pl */\n";
+       print "/* Conversion constants for HZ == $hz */\n";
+       print "\n";
+       print "#ifndef KERNEL_TIMECONST_H\n";
+       print "#define KERNEL_TIMECONST_H\n";
+       print "\n";
+
+       print "#include <linux/param.h>\n";
+
+       print "\n";
+       print "#if HZ != $hz\n";
+       print "#error \"kernel/timeconst.h has the wrong HZ value!\"\n";
+       print "#endif\n";
+       print "\n";
+
+       foreach $pfx ('HZ_TO_MSEC','MSEC_TO_HZ',
+                     'USEC_TO_HZ','HZ_TO_USEC') {
+               foreach $bit (32, 64) {
+                       foreach $suf ('MUL', 'ADJ', 'SHR') {
+                               printf "#define %-23s %s\n",
+                                       "${pfx}_$suf$bit", shift(@val);
+                       }
+               }
+               foreach $suf ('NUM', 'DEN') {
+                       printf "#define %-23s %s\n",
+                               "${pfx}_$suf", shift(@val);
+               }
+       }
+
+       print "\n";
+       print "#endif /* KERNEL_TIMECONST_H */\n";
+}
+
+($hz) = @ARGV;
+
+# Use this to generate the %canned_values structure
+if ($hz eq '--can') {
+       shift(@ARGV);
+       @hzlist = sort {$a <=> $b} (@ARGV);
+
+       print "# Precomputed values for systems without Math::BigInt\n";
+       print "# Generated by:\n";
+       print "# timeconst.pl --can ", join(' ', @hzlist), "\n";
+       print "\%canned_values = (\n";
+       my $pf = "\t";
+       foreach $hz (@hzlist) {
+               my @values = compute_values($hz);
+               print "$pf$hz => [\n";
+               while (scalar(@values)) {
+                       my $bit;
+                       foreach $bit (32, 64) {
+                               my $m = shift(@values);
+                               my $a = shift(@values);
+                               my $s = shift(@values);
+                               print "\t\t\'",$m,"\',\'",$a,"\',",$s,",\n";
+                       }
+                       my $n = shift(@values);
+                       my $d = shift(@values);
+                       print "\t\t",$n,',',$d,",\n";
+               }
+               print "\t]";
+               $pf = ', ';
+       }
+       print "\n);\n";
+} else {
+       $hz += 0;                       # Force to number
+       if ($hz < 1) {
+               die "Usage: $0 HZ\n";
+       }
+
+       @val = @{$canned_values{$hz}};
+       if (!defined(@val)) {
+               @val = compute_values($hz);
+       }
+       output($hz, @val);
+}
+exit 0;
index 70b29b59343f6e5a0a0e2cd8cf636748ed16925d..99b00a25f88b3efc4c0558c78ece429d3d3300c3 100644 (file)
@@ -327,7 +327,7 @@ static void timer_stats_account_timer(struct timer_list *timer) {}
  * init_timer() must be done to a timer prior calling *any* of the
  * other timer functions.
  */
-void fastcall init_timer(struct timer_list *timer)
+void init_timer(struct timer_list *timer)
 {
        timer->entry.next = NULL;
        timer->base = __raw_get_cpu_var(tvec_bases);
@@ -339,7 +339,7 @@ void fastcall init_timer(struct timer_list *timer)
 }
 EXPORT_SYMBOL(init_timer);
 
-void fastcall init_timer_deferrable(struct timer_list *timer)
+void init_timer_deferrable(struct timer_list *timer)
 {
        init_timer(timer);
        timer_set_deferrable(timer);
@@ -979,7 +979,7 @@ asmlinkage long sys_getppid(void)
        int pid;
 
        rcu_read_lock();
-       pid = task_tgid_nr_ns(current->real_parent, current->nsproxy->pid_ns);
+       pid = task_tgid_vnr(current->real_parent);
        rcu_read_unlock();
 
        return pid;
@@ -1042,7 +1042,7 @@ static void process_timeout(unsigned long __data)
  *
  * In all cases the return value is guaranteed to be non-negative.
  */
-fastcall signed long __sched schedule_timeout(signed long timeout)
+signed long __sched schedule_timeout(signed long timeout)
 {
        struct timer_list timer;
        unsigned long expire;
index bc1c48d35cb32726623b37b47a09d4325aaf4074..7d7900c5a1fd29262028470af3e45deb71682db9 100644 (file)
 #include <linux/module.h>
 #include <linux/user_namespace.h>
 
+struct user_namespace init_user_ns = {
+       .kref = {
+               .refcount       = ATOMIC_INIT(2),
+       },
+       .root_user = &root_user,
+};
+EXPORT_SYMBOL_GPL(init_user_ns);
+
 /*
  * UID task count cache, to get fast user lookup in "alloc_uid"
  * when changing user ID's (ie setuid() and friends).
@@ -427,6 +435,7 @@ void switch_uid(struct user_struct *new_user)
        suid_keys(current);
 }
 
+#ifdef CONFIG_USER_NS
 void release_uids(struct user_namespace *ns)
 {
        int i;
@@ -451,6 +460,7 @@ void release_uids(struct user_namespace *ns)
 
        free_uid(ns->root_user);
 }
+#endif
 
 static int __init uid_cache_init(void)
 {
index 7af90fc4f0fd3d870c1f5dbb3b0771fc16bbc5a4..4c9006275df7fef80ae61944d39cdeea78246bb0 100644 (file)
 #include <linux/nsproxy.h>
 #include <linux/user_namespace.h>
 
-struct user_namespace init_user_ns = {
-       .kref = {
-               .refcount       = ATOMIC_INIT(2),
-       },
-       .root_user = &root_user,
-};
-
-EXPORT_SYMBOL_GPL(init_user_ns);
-
-#ifdef CONFIG_USER_NS
-
 /*
  * Clone a new ns copying an original user ns, setting refcount to 1
  * @old_ns: namespace to clone
@@ -84,5 +73,3 @@ void free_user_ns(struct kref *kref)
        release_uids(ns);
        kfree(ns);
 }
-
-#endif /* CONFIG_USER_NS */
index f9876888a569d286fc9e9e08250f9b9b075a58fd..c275c56cf2d313e509a2aac411d3bcebf4278ca1 100644 (file)
@@ -18,7 +18,7 @@ void init_waitqueue_head(wait_queue_head_t *q)
 
 EXPORT_SYMBOL(init_waitqueue_head);
 
-void fastcall add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait)
+void add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait)
 {
        unsigned long flags;
 
@@ -29,7 +29,7 @@ void fastcall add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait)
 }
 EXPORT_SYMBOL(add_wait_queue);
 
-void fastcall add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait)
+void add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait)
 {
        unsigned long flags;
 
@@ -40,7 +40,7 @@ void fastcall add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait)
 }
 EXPORT_SYMBOL(add_wait_queue_exclusive);
 
-void fastcall remove_wait_queue(wait_queue_head_t *q, wait_queue_t *wait)
+void remove_wait_queue(wait_queue_head_t *q, wait_queue_t *wait)
 {
        unsigned long flags;
 
@@ -63,7 +63,7 @@ EXPORT_SYMBOL(remove_wait_queue);
  * stops them from bleeding out - it would still allow subsequent
  * loads to move into the critical region).
  */
-void fastcall
+void
 prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state)
 {
        unsigned long flags;
@@ -82,7 +82,7 @@ prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state)
 }
 EXPORT_SYMBOL(prepare_to_wait);
 
-void fastcall
+void
 prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state)
 {
        unsigned long flags;
@@ -101,7 +101,7 @@ prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state)
 }
 EXPORT_SYMBOL(prepare_to_wait_exclusive);
 
-void fastcall finish_wait(wait_queue_head_t *q, wait_queue_t *wait)
+void finish_wait(wait_queue_head_t *q, wait_queue_t *wait)
 {
        unsigned long flags;
 
@@ -157,7 +157,7 @@ EXPORT_SYMBOL(wake_bit_function);
  * waiting, the actions of __wait_on_bit() and __wait_on_bit_lock() are
  * permitted return codes. Nonzero return codes halt waiting and return.
  */
-int __sched fastcall
+int __sched
 __wait_on_bit(wait_queue_head_t *wq, struct wait_bit_queue *q,
                        int (*action)(void *), unsigned mode)
 {
@@ -173,7 +173,7 @@ __wait_on_bit(wait_queue_head_t *wq, struct wait_bit_queue *q,
 }
 EXPORT_SYMBOL(__wait_on_bit);
 
-int __sched fastcall out_of_line_wait_on_bit(void *word, int bit,
+int __sched out_of_line_wait_on_bit(void *word, int bit,
                                        int (*action)(void *), unsigned mode)
 {
        wait_queue_head_t *wq = bit_waitqueue(word, bit);
@@ -183,7 +183,7 @@ int __sched fastcall out_of_line_wait_on_bit(void *word, int bit,
 }
 EXPORT_SYMBOL(out_of_line_wait_on_bit);
 
-int __sched fastcall
+int __sched
 __wait_on_bit_lock(wait_queue_head_t *wq, struct wait_bit_queue *q,
                        int (*action)(void *), unsigned mode)
 {
@@ -201,7 +201,7 @@ __wait_on_bit_lock(wait_queue_head_t *wq, struct wait_bit_queue *q,
 }
 EXPORT_SYMBOL(__wait_on_bit_lock);
 
-int __sched fastcall out_of_line_wait_on_bit_lock(void *word, int bit,
+int __sched out_of_line_wait_on_bit_lock(void *word, int bit,
                                        int (*action)(void *), unsigned mode)
 {
        wait_queue_head_t *wq = bit_waitqueue(word, bit);
@@ -211,7 +211,7 @@ int __sched fastcall out_of_line_wait_on_bit_lock(void *word, int bit,
 }
 EXPORT_SYMBOL(out_of_line_wait_on_bit_lock);
 
-void fastcall __wake_up_bit(wait_queue_head_t *wq, void *word, int bit)
+void __wake_up_bit(wait_queue_head_t *wq, void *word, int bit)
 {
        struct wait_bit_key key = __WAIT_BIT_KEY_INITIALIZER(word, bit);
        if (waitqueue_active(wq))
@@ -236,13 +236,13 @@ EXPORT_SYMBOL(__wake_up_bit);
  * may need to use a less regular barrier, such fs/inode.c's smp_mb(),
  * because spin_unlock() does not guarantee a memory barrier.
  */
-void fastcall wake_up_bit(void *word, int bit)
+void wake_up_bit(void *word, int bit)
 {
        __wake_up_bit(bit_waitqueue(word, bit), word, bit);
 }
 EXPORT_SYMBOL(wake_up_bit);
 
-fastcall wait_queue_head_t *bit_waitqueue(void *word, int bit)
+wait_queue_head_t *bit_waitqueue(void *word, int bit)
 {
        const int shift = BITS_PER_LONG == 32 ? 5 : 6;
        const struct zone *zone = page_zone(virt_to_page(word));
index 52db48e7f6e79b5dc78da41903dc162c5e97d755..ff06611655af71e82f915b3790b81aaa0193e61a 100644 (file)
@@ -161,7 +161,7 @@ static void __queue_work(struct cpu_workqueue_struct *cwq,
  * We queue the work to the CPU it was submitted, but there is no
  * guarantee that it will be processed by that CPU.
  */
-int fastcall queue_work(struct workqueue_struct *wq, struct work_struct *work)
+int queue_work(struct workqueue_struct *wq, struct work_struct *work)
 {
        int ret = 0;
 
@@ -175,7 +175,7 @@ int fastcall queue_work(struct workqueue_struct *wq, struct work_struct *work)
 }
 EXPORT_SYMBOL_GPL(queue_work);
 
-void delayed_work_timer_fn(unsigned long __data)
+static void delayed_work_timer_fn(unsigned long __data)
 {
        struct delayed_work *dwork = (struct delayed_work *)__data;
        struct cpu_workqueue_struct *cwq = get_wq_data(&dwork->work);
@@ -192,7 +192,7 @@ void delayed_work_timer_fn(unsigned long __data)
  *
  * Returns 0 if @work was already on a queue, non-zero otherwise.
  */
-int fastcall queue_delayed_work(struct workqueue_struct *wq,
+int queue_delayed_work(struct workqueue_struct *wq,
                        struct delayed_work *dwork, unsigned long delay)
 {
        timer_stats_timer_set_start_info(&dwork->timer);
@@ -388,7 +388,7 @@ static int flush_cpu_workqueue(struct cpu_workqueue_struct *cwq)
  * This function used to run the workqueues itself.  Now we just wait for the
  * helper threads to do it.
  */
-void fastcall flush_workqueue(struct workqueue_struct *wq)
+void flush_workqueue(struct workqueue_struct *wq)
 {
        const cpumask_t *cpu_map = wq_cpu_map(wq);
        int cpu;
@@ -546,7 +546,7 @@ static struct workqueue_struct *keventd_wq __read_mostly;
  *
  * This puts a job in the kernel-global workqueue.
  */
-int fastcall schedule_work(struct work_struct *work)
+int schedule_work(struct work_struct *work)
 {
        return queue_work(keventd_wq, work);
 }
@@ -560,7 +560,7 @@ EXPORT_SYMBOL(schedule_work);
  * After waiting for a given time this puts a job in the kernel-global
  * workqueue.
  */
-int fastcall schedule_delayed_work(struct delayed_work *dwork,
+int schedule_delayed_work(struct delayed_work *dwork,
                                        unsigned long delay)
 {
        timer_stats_timer_set_start_info(&dwork->timer);
index 0d385be682db021dccc6482f385d8bb6f30fa75e..ce0bb2600c25e9621b7b895b9457439e3f7ae5e1 100644 (file)
@@ -205,6 +205,19 @@ config SLUB_DEBUG_ON
          off in a kernel built with CONFIG_SLUB_DEBUG_ON by specifying
          "slub_debug=-".
 
+config SLUB_STATS
+       default n
+       bool "Enable SLUB performance statistics"
+       depends on SLUB
+       help
+         SLUB statistics are useful to debug SLUBs allocation behavior in
+         order find ways to optimize the allocator. This should never be
+         enabled for production use since keeping statistics slows down
+         the allocator by a few percentage points. The slabinfo command
+         supports the determination of the most active slabs to figure
+         out which slabs are relevant to a particular load.
+         Try running: slabinfo -DA
+
 config DEBUG_PREEMPT
        bool "Debug preemptible kernel"
        depends on DEBUG_KERNEL && PREEMPT && (TRACE_IRQFLAGS_SUPPORT || PPC64)
@@ -391,7 +404,8 @@ config DEBUG_HIGHMEM
 config DEBUG_BUGVERBOSE
        bool "Verbose BUG() reporting (adds 70K)" if DEBUG_KERNEL && EMBEDDED
        depends on BUG
-       depends on ARM || AVR32 || M32R || M68K || SPARC32 || SPARC64 || FRV || SUPERH || GENERIC_BUG || BLACKFIN
+       depends on ARM || AVR32 || M32R || M68K || SPARC32 || SPARC64 || \
+                  FRV || SUPERH || GENERIC_BUG || BLACKFIN || MN10300
        default !EMBEDDED
        help
          Say Y here to make BUG() panics output the file name and line number
@@ -441,7 +455,9 @@ config DEBUG_SG
 
 config FRAME_POINTER
        bool "Compile the kernel with frame pointers"
-       depends on DEBUG_KERNEL && (X86 || CRIS || M68K || M68KNOMMU || FRV || UML || S390 || AVR32 || SUPERH || BLACKFIN)
+       depends on DEBUG_KERNEL && \
+               (X86 || CRIS || M68K || M68KNOMMU || FRV || UML || S390 || \
+                AVR32 || SUPERH || BLACKFIN || MN10300)
        default y if DEBUG_INFO && UML
        help
          If you say Y here the resulting kernel image will be slightly larger
index 23985a278bbb08d919ab9bc92dd7869d3aba8f0a..a50a311554cc30e5e1b5d992988397a33f560ac6 100644 (file)
@@ -134,23 +134,26 @@ bool should_fail(struct fault_attr *attr, ssize_t size)
 
 #ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
 
-static void debugfs_ul_set(void *data, u64 val)
+static int debugfs_ul_set(void *data, u64 val)
 {
        *(unsigned long *)data = val;
+       return 0;
 }
 
 #ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER
-static void debugfs_ul_set_MAX_STACK_TRACE_DEPTH(void *data, u64 val)
+static int debugfs_ul_set_MAX_STACK_TRACE_DEPTH(void *data, u64 val)
 {
        *(unsigned long *)data =
                val < MAX_STACK_TRACE_DEPTH ?
                val : MAX_STACK_TRACE_DEPTH;
+       return 0;
 }
 #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
 
-static u64 debugfs_ul_get(void *data)
+static int debugfs_ul_get(void *data, u64 *val)
 {
-       return *(unsigned long *)data;
+       *val = *(unsigned long *)data;
+       return 0;
 }
 
 DEFINE_SIMPLE_ATTRIBUTE(fops_ul, debugfs_ul_get, debugfs_ul_set, "%llu\n");
@@ -174,14 +177,16 @@ static struct dentry *debugfs_create_ul_MAX_STACK_TRACE_DEPTH(
 }
 #endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
 
-static void debugfs_atomic_t_set(void *data, u64 val)
+static int debugfs_atomic_t_set(void *data, u64 val)
 {
        atomic_set((atomic_t *)data, val);
+       return 0;
 }
 
-static u64 debugfs_atomic_t_get(void *data)
+static int debugfs_atomic_t_get(void *data, u64 *val)
 {
-       return atomic_read((atomic_t *)data);
+       *val = atomic_read((atomic_t *)data);
+       return 0;
 }
 
 DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get,
index 72c42687ba1095e1357e81a0aa259275dd5cc618..db004a9ff509bb6314793edcb76f48e785240e47 100644 (file)
@@ -69,27 +69,27 @@ static void bad_io_access(unsigned long port, const char *access)
 #define mmio_read32be(addr) be32_to_cpu(__raw_readl(addr))
 #endif
 
-unsigned int fastcall ioread8(void __iomem *addr)
+unsigned int ioread8(void __iomem *addr)
 {
        IO_COND(addr, return inb(port), return readb(addr));
        return 0xff;
 }
-unsigned int fastcall ioread16(void __iomem *addr)
+unsigned int ioread16(void __iomem *addr)
 {
        IO_COND(addr, return inw(port), return readw(addr));
        return 0xffff;
 }
-unsigned int fastcall ioread16be(void __iomem *addr)
+unsigned int ioread16be(void __iomem *addr)
 {
        IO_COND(addr, return pio_read16be(port), return mmio_read16be(addr));
        return 0xffff;
 }
-unsigned int fastcall ioread32(void __iomem *addr)
+unsigned int ioread32(void __iomem *addr)
 {
        IO_COND(addr, return inl(port), return readl(addr));
        return 0xffffffff;
 }
-unsigned int fastcall ioread32be(void __iomem *addr)
+unsigned int ioread32be(void __iomem *addr)
 {
        IO_COND(addr, return pio_read32be(port), return mmio_read32be(addr));
        return 0xffffffff;
@@ -110,23 +110,23 @@ EXPORT_SYMBOL(ioread32be);
 #define mmio_write32be(val,port) __raw_writel(be32_to_cpu(val),port)
 #endif
 
-void fastcall iowrite8(u8 val, void __iomem *addr)
+void iowrite8(u8 val, void __iomem *addr)
 {
        IO_COND(addr, outb(val,port), writeb(val, addr));
 }
-void fastcall iowrite16(u16 val, void __iomem *addr)
+void iowrite16(u16 val, void __iomem *addr)
 {
        IO_COND(addr, outw(val,port), writew(val, addr));
 }
-void fastcall iowrite16be(u16 val, void __iomem *addr)
+void iowrite16be(u16 val, void __iomem *addr)
 {
        IO_COND(addr, pio_write16be(val,port), mmio_write16be(val, addr));
 }
-void fastcall iowrite32(u32 val, void __iomem *addr)
+void iowrite32(u32 val, void __iomem *addr)
 {
        IO_COND(addr, outl(val,port), writel(val, addr));
 }
-void fastcall iowrite32be(u32 val, void __iomem *addr)
+void iowrite32be(u32 val, void __iomem *addr)
 {
        IO_COND(addr, pio_write32be(val,port), mmio_write32be(val, addr));
 }
@@ -193,15 +193,15 @@ static inline void mmio_outsl(void __iomem *addr, const u32 *src, int count)
 }
 #endif
 
-void fastcall ioread8_rep(void __iomem *addr, void *dst, unsigned long count)
+void ioread8_rep(void __iomem *addr, void *dst, unsigned long count)
 {
        IO_COND(addr, insb(port,dst,count), mmio_insb(addr, dst, count));
 }
-void fastcall ioread16_rep(void __iomem *addr, void *dst, unsigned long count)
+void ioread16_rep(void __iomem *addr, void *dst, unsigned long count)
 {
        IO_COND(addr, insw(port,dst,count), mmio_insw(addr, dst, count));
 }
-void fastcall ioread32_rep(void __iomem *addr, void *dst, unsigned long count)
+void ioread32_rep(void __iomem *addr, void *dst, unsigned long count)
 {
        IO_COND(addr, insl(port,dst,count), mmio_insl(addr, dst, count));
 }
@@ -209,15 +209,15 @@ EXPORT_SYMBOL(ioread8_rep);
 EXPORT_SYMBOL(ioread16_rep);
 EXPORT_SYMBOL(ioread32_rep);
 
-void fastcall iowrite8_rep(void __iomem *addr, const void *src, unsigned long count)
+void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count)
 {
        IO_COND(addr, outsb(port, src, count), mmio_outsb(addr, src, count));
 }
-void fastcall iowrite16_rep(void __iomem *addr, const void *src, unsigned long count)
+void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count)
 {
        IO_COND(addr, outsw(port, src, count), mmio_outsw(addr, src, count));
 }
-void fastcall iowrite32_rep(void __iomem *addr, const void *src, unsigned long count)
+void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count)
 {
        IO_COND(addr, outsl(port, src,count), mmio_outsl(addr, src, count));
 }
index c4cfd6c0342ff1e4fbc04b9fff3b93f0d00118bd..9df3ca56db11455f39c436a6fa79f423b7e35b67 100644 (file)
@@ -125,7 +125,7 @@ __rwsem_wake_one_writer(struct rw_semaphore *sem)
 /*
  * get a read lock on the semaphore
  */
-void fastcall __sched __down_read(struct rw_semaphore *sem)
+void __sched __down_read(struct rw_semaphore *sem)
 {
        struct rwsem_waiter waiter;
        struct task_struct *tsk;
@@ -168,7 +168,7 @@ void fastcall __sched __down_read(struct rw_semaphore *sem)
 /*
  * trylock for reading -- returns 1 if successful, 0 if contention
  */
-int fastcall __down_read_trylock(struct rw_semaphore *sem)
+int __down_read_trylock(struct rw_semaphore *sem)
 {
        unsigned long flags;
        int ret = 0;
@@ -191,7 +191,7 @@ int fastcall __down_read_trylock(struct rw_semaphore *sem)
  * get a write lock on the semaphore
  * - we increment the waiting count anyway to indicate an exclusive lock
  */
-void fastcall __sched __down_write_nested(struct rw_semaphore *sem, int subclass)
+void __sched __down_write_nested(struct rw_semaphore *sem, int subclass)
 {
        struct rwsem_waiter waiter;
        struct task_struct *tsk;
@@ -231,7 +231,7 @@ void fastcall __sched __down_write_nested(struct rw_semaphore *sem, int subclass
        ;
 }
 
-void fastcall __sched __down_write(struct rw_semaphore *sem)
+void __sched __down_write(struct rw_semaphore *sem)
 {
        __down_write_nested(sem, 0);
 }
@@ -239,7 +239,7 @@ void fastcall __sched __down_write(struct rw_semaphore *sem)
 /*
  * trylock for writing -- returns 1 if successful, 0 if contention
  */
-int fastcall __down_write_trylock(struct rw_semaphore *sem)
+int __down_write_trylock(struct rw_semaphore *sem)
 {
        unsigned long flags;
        int ret = 0;
@@ -260,7 +260,7 @@ int fastcall __down_write_trylock(struct rw_semaphore *sem)
 /*
  * release a read lock on the semaphore
  */
-void fastcall __up_read(struct rw_semaphore *sem)
+void __up_read(struct rw_semaphore *sem)
 {
        unsigned long flags;
 
@@ -275,7 +275,7 @@ void fastcall __up_read(struct rw_semaphore *sem)
 /*
  * release a write lock on the semaphore
  */
-void fastcall __up_write(struct rw_semaphore *sem)
+void __up_write(struct rw_semaphore *sem)
 {
        unsigned long flags;
 
@@ -292,7 +292,7 @@ void fastcall __up_write(struct rw_semaphore *sem)
  * downgrade a write lock into a read lock
  * - just wake up any readers at the front of the queue
  */
-void fastcall __downgrade_write(struct rw_semaphore *sem)
+void __downgrade_write(struct rw_semaphore *sem)
 {
        unsigned long flags;
 
index 128180523860388004c5679394b2d64946d37c62..0198782cdacb645b47bd127b8b41fe6d1c179e24 100644 (file)
  *    we cannot lose wakeup events.
  */
 
-fastcall void __up(struct semaphore *sem)
+void __up(struct semaphore *sem)
 {
        wake_up(&sem->wait);
 }
 
-fastcall void __sched __down(struct semaphore * sem)
+void __sched __down(struct semaphore *sem)
 {
        struct task_struct *tsk = current;
        DECLARE_WAITQUEUE(wait, tsk);
@@ -90,7 +90,7 @@ fastcall void __sched __down(struct semaphore * sem)
        tsk->state = TASK_RUNNING;
 }
 
-fastcall int __sched __down_interruptible(struct semaphore * sem)
+int __sched __down_interruptible(struct semaphore *sem)
 {
        int retval = 0;
        struct task_struct *tsk = current;
@@ -153,7 +153,7 @@ fastcall int __sched __down_interruptible(struct semaphore * sem)
  * single "cmpxchg" without failure cases,
  * but then it wouldn't work on a 386.
  */
-fastcall int __down_trylock(struct semaphore * sem)
+int __down_trylock(struct semaphore *sem)
 {
        int sleepers;
        unsigned long flags;
index 7b481cea54ae1a9492d2c59ae3aa795b392ad28b..419993f58c6b6d61c7f881b90508ade03312085e 100644 (file)
@@ -126,6 +126,129 @@ long long simple_strtoll(const char *cp,char **endp,unsigned int base)
        return simple_strtoull(cp,endp,base);
 }
 
+
+/**
+ * strict_strtoul - convert a string to an unsigned long strictly
+ * @cp: The string to be converted
+ * @base: The number base to use
+ * @res: The converted result value
+ *
+ * strict_strtoul converts a string to an unsigned long only if the
+ * string is really an unsigned long string, any string containing
+ * any invalid char at the tail will be rejected and -EINVAL is returned,
+ * only a newline char at the tail is acceptible because people generally
+ * change a module parameter in the following way:
+ *
+ *     echo 1024 > /sys/module/e1000/parameters/copybreak
+ *
+ * echo will append a newline to the tail.
+ *
+ * It returns 0 if conversion is successful and *res is set to the converted
+ * value, otherwise it returns -EINVAL and *res is set to 0.
+ *
+ * simple_strtoul just ignores the successive invalid characters and
+ * return the converted value of prefix part of the string.
+ */
+int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
+
+/**
+ * strict_strtol - convert a string to a long strictly
+ * @cp: The string to be converted
+ * @base: The number base to use
+ * @res: The converted result value
+ *
+ * strict_strtol is similiar to strict_strtoul, but it allows the first
+ * character of a string is '-'.
+ *
+ * It returns 0 if conversion is successful and *res is set to the converted
+ * value, otherwise it returns -EINVAL and *res is set to 0.
+ */
+int strict_strtol(const char *cp, unsigned int base, long *res);
+
+/**
+ * strict_strtoull - convert a string to an unsigned long long strictly
+ * @cp: The string to be converted
+ * @base: The number base to use
+ * @res: The converted result value
+ *
+ * strict_strtoull converts a string to an unsigned long long only if the
+ * string is really an unsigned long long string, any string containing
+ * any invalid char at the tail will be rejected and -EINVAL is returned,
+ * only a newline char at the tail is acceptible because people generally
+ * change a module parameter in the following way:
+ *
+ *     echo 1024 > /sys/module/e1000/parameters/copybreak
+ *
+ * echo will append a newline to the tail of the string.
+ *
+ * It returns 0 if conversion is successful and *res is set to the converted
+ * value, otherwise it returns -EINVAL and *res is set to 0.
+ *
+ * simple_strtoull just ignores the successive invalid characters and
+ * return the converted value of prefix part of the string.
+ */
+int strict_strtoull(const char *cp, unsigned int base, unsigned long long *res);
+
+/**
+ * strict_strtoll - convert a string to a long long strictly
+ * @cp: The string to be converted
+ * @base: The number base to use
+ * @res: The converted result value
+ *
+ * strict_strtoll is similiar to strict_strtoull, but it allows the first
+ * character of a string is '-'.
+ *
+ * It returns 0 if conversion is successful and *res is set to the converted
+ * value, otherwise it returns -EINVAL and *res is set to 0.
+ */
+int strict_strtoll(const char *cp, unsigned int base, long long *res);
+
+#define define_strict_strtoux(type, valtype)                           \
+int strict_strtou##type(const char *cp, unsigned int base, valtype *res)\
+{                                                                      \
+       char *tail;                                                     \
+       valtype val;                                                    \
+       size_t len;                                                     \
+                                                                       \
+       *res = 0;                                                       \
+       len = strlen(cp);                                               \
+       if (len == 0)                                                   \
+               return -EINVAL;                                         \
+                                                                       \
+       val = simple_strtoul(cp, &tail, base);                          \
+       if ((*tail == '\0') ||                                          \
+               ((len == (size_t)(tail - cp) + 1) && (*tail == '\n'))) {\
+               *res = val;                                             \
+               return 0;                                               \
+       }                                                               \
+                                                                       \
+       return -EINVAL;                                                 \
+}                                                                      \
+
+#define define_strict_strtox(type, valtype)                            \
+int strict_strto##type(const char *cp, unsigned int base, valtype *res)        \
+{                                                                      \
+       int ret;                                                        \
+       if (*cp == '-') {                                               \
+               ret = strict_strtou##type(cp+1, base, res);             \
+               if (ret != 0)                                           \
+                       *res = -(*res);                                 \
+       } else                                                          \
+               ret = strict_strtou##type(cp, base, res);               \
+                                                                       \
+       return ret;                                                     \
+}                                                                      \
+
+define_strict_strtoux(l, unsigned long)
+define_strict_strtox(l, long)
+define_strict_strtoux(ll, unsigned long long)
+define_strict_strtox(ll, long long)
+
+EXPORT_SYMBOL(strict_strtoul);
+EXPORT_SYMBOL(strict_strtol);
+EXPORT_SYMBOL(strict_strtoll);
+EXPORT_SYMBOL(strict_strtoull);
+
 static int skip_atoi(const char **s)
 {
        int i=0;
index 5357fcc4643b5a653c82d849690ababaeaec9a0e..b7b1be6dbd83840ce287b515e0f1fab422acba7a 100644 (file)
@@ -875,9 +875,7 @@ static void shrink_readahead_size_eio(struct file *filp,
 }
 
 /**
- * do_generic_mapping_read - generic file read routine
- * @mapping:   address_space to be read
- * @ra:                file's readahead state
+ * do_generic_file_read - generic file read routine
  * @filp:      the file to read
  * @ppos:      current file position
  * @desc:      read_descriptor
@@ -888,18 +886,13 @@ static void shrink_readahead_size_eio(struct file *filp,
  *
  * This is really ugly. But the goto's actually try to clarify some
  * of the logic when it comes to error handling etc.
- *
- * Note the struct file* is only passed for the use of readpage.
- * It may be NULL.
  */
-void do_generic_mapping_read(struct address_space *mapping,
-                            struct file_ra_state *ra,
-                            struct file *filp,
-                            loff_t *ppos,
-                            read_descriptor_t *desc,
-                            read_actor_t actor)
+static void do_generic_file_read(struct file *filp, loff_t *ppos,
+               read_descriptor_t *desc, read_actor_t actor)
 {
+       struct address_space *mapping = filp->f_mapping;
        struct inode *inode = mapping->host;
+       struct file_ra_state *ra = &filp->f_ra;
        pgoff_t index;
        pgoff_t last_index;
        pgoff_t prev_index;
@@ -1091,7 +1084,6 @@ out:
        if (filp)
                file_accessed(filp);
 }
-EXPORT_SYMBOL(do_generic_mapping_read);
 
 int file_read_actor(read_descriptor_t *desc, struct page *page,
                        unsigned long offset, unsigned long size)
@@ -1332,7 +1324,7 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
        struct file_ra_state *ra = &file->f_ra;
        struct inode *inode = mapping->host;
        struct page *page;
-       unsigned long size;
+       pgoff_t size;
        int did_readaround = 0;
        int ret = 0;
 
index 0420a0292b0306425306b8db141b55b59f1010be..5e598c42afd726be44f9d862a086d52ed8adbd2a 100644 (file)
@@ -56,7 +56,8 @@ do_xip_mapping_read(struct address_space *mapping,
                    read_actor_t actor)
 {
        struct inode *inode = mapping->host;
-       unsigned long index, end_index, offset;
+       pgoff_t index, end_index;
+       unsigned long offset;
        loff_t isize;
 
        BUG_ON(!mapping->a_ops->get_xip_page);
index 1a5642074e342532f4a844ed0d2fdc86bd9b5de9..d9a380312467d7d13f70064c50b6c718e38f55a6 100644 (file)
@@ -605,6 +605,16 @@ int hugetlb_treat_movable_handler(struct ctl_table *table, int write,
        return 0;
 }
 
+int hugetlb_overcommit_handler(struct ctl_table *table, int write,
+                       struct file *file, void __user *buffer,
+                       size_t *length, loff_t *ppos)
+{
+       spin_lock(&hugetlb_lock);
+       proc_doulongvec_minmax(table, write, file, buffer, length, ppos);
+       spin_unlock(&hugetlb_lock);
+       return 0;
+}
+
 #endif /* CONFIG_SYSCTL */
 
 int hugetlb_report_meminfo(char *buf)
index 153a54b2013ca9927edf1dda4e047a82a952c05e..e5628a5fd678ff2b8faa02521e49cec4d769970e 100644 (file)
@@ -134,11 +134,9 @@ void pmd_clear_bad(pmd_t *pmd)
  */
 static void free_pte_range(struct mmu_gather *tlb, pmd_t *pmd)
 {
-       struct page *page = pmd_page(*pmd);
+       pgtable_t token = pmd_pgtable(*pmd);
        pmd_clear(pmd);
-       pte_lock_deinit(page);
-       pte_free_tlb(tlb, page);
-       dec_zone_page_state(page, NR_PAGETABLE);
+       pte_free_tlb(tlb, token);
        tlb->mm->nr_ptes--;
 }
 
@@ -309,21 +307,19 @@ void free_pgtables(struct mmu_gather **tlb, struct vm_area_struct *vma,
 
 int __pte_alloc(struct mm_struct *mm, pmd_t *pmd, unsigned long address)
 {
-       struct page *new = pte_alloc_one(mm, address);
+       pgtable_t new = pte_alloc_one(mm, address);
        if (!new)
                return -ENOMEM;
 
-       pte_lock_init(new);
        spin_lock(&mm->page_table_lock);
-       if (pmd_present(*pmd)) {        /* Another has populated it */
-               pte_lock_deinit(new);
-               pte_free(mm, new);
-       } else {
+       if (!pmd_present(*pmd)) {       /* Has another populated it ? */
                mm->nr_ptes++;
-               inc_zone_page_state(new, NR_PAGETABLE);
                pmd_populate(mm, pmd, new);
+               new = NULL;
        }
        spin_unlock(&mm->page_table_lock);
+       if (new)
+               pte_free(mm, new);
        return 0;
 }
 
@@ -334,11 +330,13 @@ int __pte_alloc_kernel(pmd_t *pmd, unsigned long address)
                return -ENOMEM;
 
        spin_lock(&init_mm.page_table_lock);
-       if (pmd_present(*pmd))          /* Another has populated it */
-               pte_free_kernel(&init_mm, new);
-       else
+       if (!pmd_present(*pmd)) {       /* Has another populated it ? */
                pmd_populate_kernel(&init_mm, pmd, new);
+               new = NULL;
+       }
        spin_unlock(&init_mm.page_table_lock);
+       if (new)
+               pte_free_kernel(&init_mm, new);
        return 0;
 }
 
@@ -1390,7 +1388,7 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd,
 {
        pte_t *pte;
        int err;
-       struct page *pmd_page;
+       pgtable_t token;
        spinlock_t *uninitialized_var(ptl);
 
        pte = (mm == &init_mm) ?
@@ -1401,10 +1399,10 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd,
 
        BUG_ON(pmd_huge(*pmd));
 
-       pmd_page = pmd_page(*pmd);
+       token = pmd_pgtable(*pmd);
 
        do {
-               err = fn(pte, pmd_page, addr, data);
+               err = fn(pte, token, addr, data);
                if (err)
                        break;
        } while (pte++, addr += PAGE_SIZE, addr != end);
index 26a54a17dc9f5dfc0191da8f0dd774476ab8eee0..75b979313346387d399dac1c6e36758d60f466dd 100644 (file)
@@ -1451,7 +1451,7 @@ try_next_zone:
 /*
  * This is the 'heart' of the zoned buddy allocator.
  */
-struct page * fastcall
+struct page *
 __alloc_pages(gfp_t gfp_mask, unsigned int order,
                struct zonelist *zonelist)
 {
index 85bed948fafc8aecb22daf1f68023b91080a30f4..90b576cbc06e40fb0f43d06f37f5ef24deee9f13 100644 (file)
@@ -49,6 +49,7 @@
 #include <linux/ctype.h>
 #include <linux/migrate.h>
 #include <linux/highmem.h>
+#include <linux/seq_file.h>
 
 #include <asm/uaccess.h>
 #include <asm/div64.h>
@@ -84,6 +85,18 @@ enum sgp_type {
        SGP_WRITE,      /* may exceed i_size, may allocate page */
 };
 
+#ifdef CONFIG_TMPFS
+static unsigned long shmem_default_max_blocks(void)
+{
+       return totalram_pages / 2;
+}
+
+static unsigned long shmem_default_max_inodes(void)
+{
+       return min(totalram_pages - totalhigh_pages, totalram_pages / 2);
+}
+#endif
+
 static int shmem_getpage(struct inode *inode, unsigned long idx,
                         struct page **pagep, enum sgp_type sgp, int *type);
 
@@ -1068,7 +1081,8 @@ redirty:
 }
 
 #ifdef CONFIG_NUMA
-static inline int shmem_parse_mpol(char *value, int *policy, nodemask_t *policy_nodes)
+#ifdef CONFIG_TMPFS
+static int shmem_parse_mpol(char *value, int *policy, nodemask_t *policy_nodes)
 {
        char *nodelist = strchr(value, ':');
        int err = 1;
@@ -1117,6 +1131,42 @@ out:
        return err;
 }
 
+static void shmem_show_mpol(struct seq_file *seq, int policy,
+                           const nodemask_t policy_nodes)
+{
+       char *policy_string;
+
+       switch (policy) {
+       case MPOL_PREFERRED:
+               policy_string = "prefer";
+               break;
+       case MPOL_BIND:
+               policy_string = "bind";
+               break;
+       case MPOL_INTERLEAVE:
+               policy_string = "interleave";
+               break;
+       default:
+               /* MPOL_DEFAULT */
+               return;
+       }
+
+       seq_printf(seq, ",mpol=%s", policy_string);
+
+       if (policy != MPOL_INTERLEAVE ||
+           !nodes_equal(policy_nodes, node_states[N_HIGH_MEMORY])) {
+               char buffer[64];
+               int len;
+
+               len = nodelist_scnprintf(buffer, sizeof(buffer), policy_nodes);
+               if (len < sizeof(buffer))
+                       seq_printf(seq, ":%s", buffer);
+               else
+                       seq_printf(seq, ":?");
+       }
+}
+#endif /* CONFIG_TMPFS */
+
 static struct page *shmem_swapin(swp_entry_t entry, gfp_t gfp,
                        struct shmem_inode_info *info, unsigned long idx)
 {
@@ -1148,13 +1198,20 @@ static struct page *shmem_alloc_page(gfp_t gfp,
        mpol_free(pvma.vm_policy);
        return page;
 }
-#else
+#else /* !CONFIG_NUMA */
+#ifdef CONFIG_TMPFS
 static inline int shmem_parse_mpol(char *value, int *policy,
                                                nodemask_t *policy_nodes)
 {
        return 1;
 }
 
+static inline void shmem_show_mpol(struct seq_file *seq, int policy,
+                           const nodemask_t policy_nodes)
+{
+}
+#endif /* CONFIG_TMPFS */
+
 static inline struct page *shmem_swapin(swp_entry_t entry, gfp_t gfp,
                        struct shmem_inode_info *info, unsigned long idx)
 {
@@ -1166,7 +1223,7 @@ static inline struct page *shmem_alloc_page(gfp_t gfp,
 {
        return alloc_page(gfp);
 }
-#endif
+#endif /* CONFIG_NUMA */
 
 /*
  * shmem_getpage - either get the page from swap or allocate a new one
@@ -2077,9 +2134,8 @@ static const struct export_operations shmem_export_ops = {
        .fh_to_dentry   = shmem_fh_to_dentry,
 };
 
-static int shmem_parse_options(char *options, int *mode, uid_t *uid,
-       gid_t *gid, unsigned long *blocks, unsigned long *inodes,
-       int *policy, nodemask_t *policy_nodes)
+static int shmem_parse_options(char *options, struct shmem_sb_info *sbinfo,
+                              bool remount)
 {
        char *this_char, *value, *rest;
 
@@ -2122,35 +2178,37 @@ static int shmem_parse_options(char *options, int *mode, uid_t *uid,
                        }
                        if (*rest)
                                goto bad_val;
-                       *blocks = DIV_ROUND_UP(size, PAGE_CACHE_SIZE);
+                       sbinfo->max_blocks =
+                               DIV_ROUND_UP(size, PAGE_CACHE_SIZE);
                } else if (!strcmp(this_char,"nr_blocks")) {
-                       *blocks = memparse(value,&rest);
+                       sbinfo->max_blocks = memparse(value, &rest);
                        if (*rest)
                                goto bad_val;
                } else if (!strcmp(this_char,"nr_inodes")) {
-                       *inodes = memparse(value,&rest);
+                       sbinfo->max_inodes = memparse(value, &rest);
                        if (*rest)
                                goto bad_val;
                } else if (!strcmp(this_char,"mode")) {
-                       if (!mode)
+                       if (remount)
                                continue;
-                       *mode = simple_strtoul(value,&rest,8);
+                       sbinfo->mode = simple_strtoul(value, &rest, 8) & 07777;
                        if (*rest)
                                goto bad_val;
                } else if (!strcmp(this_char,"uid")) {
-                       if (!uid)
+                       if (remount)
                                continue;
-                       *uid = simple_strtoul(value,&rest,0);
+                       sbinfo->uid = simple_strtoul(value, &rest, 0);
                        if (*rest)
                                goto bad_val;
                } else if (!strcmp(this_char,"gid")) {
-                       if (!gid)
+                       if (remount)
                                continue;
-                       *gid = simple_strtoul(value,&rest,0);
+                       sbinfo->gid = simple_strtoul(value, &rest, 0);
                        if (*rest)
                                goto bad_val;
                } else if (!strcmp(this_char,"mpol")) {
-                       if (shmem_parse_mpol(value,policy,policy_nodes))
+                       if (shmem_parse_mpol(value, &sbinfo->policy,
+                                            &sbinfo->policy_nodes))
                                goto bad_val;
                } else {
                        printk(KERN_ERR "tmpfs: Bad mount option %s\n",
@@ -2170,24 +2228,20 @@ bad_val:
 static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
 {
        struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
-       unsigned long max_blocks = sbinfo->max_blocks;
-       unsigned long max_inodes = sbinfo->max_inodes;
-       int policy = sbinfo->policy;
-       nodemask_t policy_nodes = sbinfo->policy_nodes;
+       struct shmem_sb_info config = *sbinfo;
        unsigned long blocks;
        unsigned long inodes;
        int error = -EINVAL;
 
-       if (shmem_parse_options(data, NULL, NULL, NULL, &max_blocks,
-                               &max_inodes, &policy, &policy_nodes))
+       if (shmem_parse_options(data, &config, true))
                return error;
 
        spin_lock(&sbinfo->stat_lock);
        blocks = sbinfo->max_blocks - sbinfo->free_blocks;
        inodes = sbinfo->max_inodes - sbinfo->free_inodes;
-       if (max_blocks < blocks)
+       if (config.max_blocks < blocks)
                goto out;
-       if (max_inodes < inodes)
+       if (config.max_inodes < inodes)
                goto out;
        /*
         * Those tests also disallow limited->unlimited while any are in
@@ -2195,23 +2249,42 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
         * but we must separately disallow unlimited->limited, because
         * in that case we have no record of how much is already in use.
         */
-       if (max_blocks && !sbinfo->max_blocks)
+       if (config.max_blocks && !sbinfo->max_blocks)
                goto out;
-       if (max_inodes && !sbinfo->max_inodes)
+       if (config.max_inodes && !sbinfo->max_inodes)
                goto out;
 
        error = 0;
-       sbinfo->max_blocks  = max_blocks;
-       sbinfo->free_blocks = max_blocks - blocks;
-       sbinfo->max_inodes  = max_inodes;
-       sbinfo->free_inodes = max_inodes - inodes;
-       sbinfo->policy policy;
-       sbinfo->policy_nodes = policy_nodes;
+       sbinfo->max_blocks  = config.max_blocks;
+       sbinfo->free_blocks = config.max_blocks - blocks;
+       sbinfo->max_inodes  = config.max_inodes;
+       sbinfo->free_inodes = config.max_inodes - inodes;
+       sbinfo->policy      = config.policy;
+       sbinfo->policy_nodes = config.policy_nodes;
 out:
        spin_unlock(&sbinfo->stat_lock);
        return error;
 }
-#endif
+
+static int shmem_show_options(struct seq_file *seq, struct vfsmount *vfs)
+{
+       struct shmem_sb_info *sbinfo = SHMEM_SB(vfs->mnt_sb);
+
+       if (sbinfo->max_blocks != shmem_default_max_blocks())
+               seq_printf(seq, ",size=%luk",
+                       sbinfo->max_blocks << (PAGE_CACHE_SHIFT - 10));
+       if (sbinfo->max_inodes != shmem_default_max_inodes())
+               seq_printf(seq, ",nr_inodes=%lu", sbinfo->max_inodes);
+       if (sbinfo->mode != (S_IRWXUGO | S_ISVTX))
+               seq_printf(seq, ",mode=%03o", sbinfo->mode);
+       if (sbinfo->uid != 0)
+               seq_printf(seq, ",uid=%u", sbinfo->uid);
+       if (sbinfo->gid != 0)
+               seq_printf(seq, ",gid=%u", sbinfo->gid);
+       shmem_show_mpol(seq, sbinfo->policy, sbinfo->policy_nodes);
+       return 0;
+}
+#endif /* CONFIG_TMPFS */
 
 static void shmem_put_super(struct super_block *sb)
 {
@@ -2224,15 +2297,23 @@ static int shmem_fill_super(struct super_block *sb,
 {
        struct inode *inode;
        struct dentry *root;
-       int mode   = S_IRWXUGO | S_ISVTX;
-       uid_t uid = current->fsuid;
-       gid_t gid = current->fsgid;
-       int err = -ENOMEM;
        struct shmem_sb_info *sbinfo;
-       unsigned long blocks = 0;
-       unsigned long inodes = 0;
-       int policy = MPOL_DEFAULT;
-       nodemask_t policy_nodes = node_states[N_HIGH_MEMORY];
+       int err = -ENOMEM;
+
+       /* Round up to L1_CACHE_BYTES to resist false sharing */
+       sbinfo = kmalloc(max((int)sizeof(struct shmem_sb_info),
+                               L1_CACHE_BYTES), GFP_KERNEL);
+       if (!sbinfo)
+               return -ENOMEM;
+
+       sbinfo->max_blocks = 0;
+       sbinfo->max_inodes = 0;
+       sbinfo->mode = S_IRWXUGO | S_ISVTX;
+       sbinfo->uid = current->fsuid;
+       sbinfo->gid = current->fsgid;
+       sbinfo->policy = MPOL_DEFAULT;
+       sbinfo->policy_nodes = node_states[N_HIGH_MEMORY];
+       sb->s_fs_info = sbinfo;
 
 #ifdef CONFIG_TMPFS
        /*
@@ -2241,34 +2322,22 @@ static int shmem_fill_super(struct super_block *sb,
         * but the internal instance is left unlimited.
         */
        if (!(sb->s_flags & MS_NOUSER)) {
-               blocks = totalram_pages / 2;
-               inodes = totalram_pages - totalhigh_pages;
-               if (inodes > blocks)
-                       inodes = blocks;
-               if (shmem_parse_options(data, &mode, &uid, &gid, &blocks,
-                                       &inodes, &policy, &policy_nodes))
-                       return -EINVAL;
+               sbinfo->max_blocks = shmem_default_max_blocks();
+               sbinfo->max_inodes = shmem_default_max_inodes();
+               if (shmem_parse_options(data, sbinfo, false)) {
+                       err = -EINVAL;
+                       goto failed;
+               }
        }
        sb->s_export_op = &shmem_export_ops;
 #else
        sb->s_flags |= MS_NOUSER;
 #endif
 
-       /* Round up to L1_CACHE_BYTES to resist false sharing */
-       sbinfo = kmalloc(max((int)sizeof(struct shmem_sb_info),
-                               L1_CACHE_BYTES), GFP_KERNEL);
-       if (!sbinfo)
-               return -ENOMEM;
-
        spin_lock_init(&sbinfo->stat_lock);
-       sbinfo->max_blocks = blocks;
-       sbinfo->free_blocks = blocks;
-       sbinfo->max_inodes = inodes;
-       sbinfo->free_inodes = inodes;
-       sbinfo->policy = policy;
-       sbinfo->policy_nodes = policy_nodes;
+       sbinfo->free_blocks = sbinfo->max_blocks;
+       sbinfo->free_inodes = sbinfo->max_inodes;
 
-       sb->s_fs_info = sbinfo;
        sb->s_maxbytes = SHMEM_MAX_BYTES;
        sb->s_blocksize = PAGE_CACHE_SIZE;
        sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
@@ -2280,11 +2349,11 @@ static int shmem_fill_super(struct super_block *sb,
        sb->s_flags |= MS_POSIXACL;
 #endif
 
-       inode = shmem_get_inode(sb, S_IFDIR | mode, 0);
+       inode = shmem_get_inode(sb, S_IFDIR | sbinfo->mode, 0);
        if (!inode)
                goto failed;
-       inode->i_uid = uid;
-       inode->i_gid = gid;
+       inode->i_uid = sbinfo->uid;
+       inode->i_gid = sbinfo->gid;
        root = d_alloc_root(inode);
        if (!root)
                goto failed_iput;
@@ -2420,6 +2489,7 @@ static const struct super_operations shmem_ops = {
 #ifdef CONFIG_TMPFS
        .statfs         = shmem_statfs,
        .remount_fs     = shmem_remount_fs,
+       .show_options   = shmem_show_options,
 #endif
        .delete_inode   = shmem_delete_inode,
        .drop_inode     = generic_delete_inode,
index 3f056677fa8fea56ef3a678cc8e9d8a8d27b2371..e2989ae243b53571bb8ee5695771adbd90185f3d 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -149,6 +149,13 @@ static inline void ClearSlabDebug(struct page *page)
 /* Enable to test recovery from slab corruption on boot */
 #undef SLUB_RESILIENCY_TEST
 
+/*
+ * Currently fastpath is not supported if preemption is enabled.
+ */
+#if defined(CONFIG_FAST_CMPXCHG_LOCAL) && !defined(CONFIG_PREEMPT)
+#define SLUB_FASTPATH
+#endif
+
 #if PAGE_SHIFT <= 12
 
 /*
@@ -243,6 +250,7 @@ enum track_item { TRACK_ALLOC, TRACK_FREE };
 static int sysfs_slab_add(struct kmem_cache *);
 static int sysfs_slab_alias(struct kmem_cache *, const char *);
 static void sysfs_slab_remove(struct kmem_cache *);
+
 #else
 static inline int sysfs_slab_add(struct kmem_cache *s) { return 0; }
 static inline int sysfs_slab_alias(struct kmem_cache *s, const char *p)
@@ -251,8 +259,16 @@ static inline void sysfs_slab_remove(struct kmem_cache *s)
 {
        kfree(s);
 }
+
 #endif
 
+static inline void stat(struct kmem_cache_cpu *c, enum stat_item si)
+{
+#ifdef CONFIG_SLUB_STATS
+       c->stat[si]++;
+#endif
+}
+
 /********************************************************************
  *                     Core slab cache functions
  *******************************************************************/
@@ -280,15 +296,32 @@ static inline struct kmem_cache_cpu *get_cpu_slab(struct kmem_cache *s, int cpu)
 #endif
 }
 
+/*
+ * The end pointer in a slab is special. It points to the first object in the
+ * slab but has bit 0 set to mark it.
+ *
+ * Note that SLUB relies on page_mapping returning NULL for pages with bit 0
+ * in the mapping set.
+ */
+static inline int is_end(void *addr)
+{
+       return (unsigned long)addr & PAGE_MAPPING_ANON;
+}
+
+void *slab_address(struct page *page)
+{
+       return page->end - PAGE_MAPPING_ANON;
+}
+
 static inline int check_valid_pointer(struct kmem_cache *s,
                                struct page *page, const void *object)
 {
        void *base;
 
-       if (!object)
+       if (object == page->end)
                return 1;
 
-       base = page_address(page);
+       base = slab_address(page);
        if (object < base || object >= base + s->objects * s->size ||
                (object - base) % s->size) {
                return 0;
@@ -321,7 +354,8 @@ static inline void set_freepointer(struct kmem_cache *s, void *object, void *fp)
 
 /* Scan freelist */
 #define for_each_free_object(__p, __s, __free) \
-       for (__p = (__free); __p; __p = get_freepointer((__s), __p))
+       for (__p = (__free); (__p) != page->end; __p = get_freepointer((__s),\
+               __p))
 
 /* Determine object index from a given position */
 static inline int slab_index(void *p, struct kmem_cache *s, void *addr)
@@ -473,7 +507,7 @@ static void slab_fix(struct kmem_cache *s, char *fmt, ...)
 static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p)
 {
        unsigned int off;       /* Offset of last byte */
-       u8 *addr = page_address(page);
+       u8 *addr = slab_address(page);
 
        print_tracking(s, p);
 
@@ -651,7 +685,7 @@ static int slab_pad_check(struct kmem_cache *s, struct page *page)
        if (!(s->flags & SLAB_POISON))
                return 1;
 
-       start = page_address(page);
+       start = slab_address(page);
        end = start + (PAGE_SIZE << s->order);
        length = s->objects * s->size;
        remainder = end - (start + length);
@@ -685,9 +719,10 @@ static int check_object(struct kmem_cache *s, struct page *page,
                        endobject, red, s->inuse - s->objsize))
                        return 0;
        } else {
-               if ((s->flags & SLAB_POISON) && s->objsize < s->inuse)
-                       check_bytes_and_report(s, page, p, "Alignment padding", endobject,
-                               POISON_INUSE, s->inuse - s->objsize);
+               if ((s->flags & SLAB_POISON) && s->objsize < s->inuse) {
+                       check_bytes_and_report(s, page, p, "Alignment padding",
+                               endobject, POISON_INUSE, s->inuse - s->objsize);
+               }
        }
 
        if (s->flags & SLAB_POISON) {
@@ -718,7 +753,7 @@ static int check_object(struct kmem_cache *s, struct page *page,
                 * of the free objects in this slab. May cause
                 * another error because the object count is now wrong.
                 */
-               set_freepointer(s, p, NULL);
+               set_freepointer(s, p, page->end);
                return 0;
        }
        return 1;
@@ -752,18 +787,18 @@ static int on_freelist(struct kmem_cache *s, struct page *page, void *search)
        void *fp = page->freelist;
        void *object = NULL;
 
-       while (fp && nr <= s->objects) {
+       while (fp != page->end && nr <= s->objects) {
                if (fp == search)
                        return 1;
                if (!check_valid_pointer(s, page, fp)) {
                        if (object) {
                                object_err(s, page, object,
                                        "Freechain corrupt");
-                               set_freepointer(s, object, NULL);
+                               set_freepointer(s, object, page->end);
                                break;
                        } else {
                                slab_err(s, page, "Freepointer corrupt");
-                               page->freelist = NULL;
+                               page->freelist = page->end;
                                page->inuse = s->objects;
                                slab_fix(s, "Freelist cleared");
                                return 0;
@@ -869,7 +904,7 @@ bad:
                 */
                slab_fix(s, "Marking all objects used");
                page->inuse = s->objects;
-               page->freelist = NULL;
+               page->freelist = page->end;
        }
        return 0;
 }
@@ -894,11 +929,10 @@ static int free_debug_processing(struct kmem_cache *s, struct page *page,
                return 0;
 
        if (unlikely(s != page->slab)) {
-               if (!PageSlab(page))
+               if (!PageSlab(page)) {
                        slab_err(s, page, "Attempt to free object(0x%p) "
                                "outside of slab", object);
-               else
-               if (!page->slab) {
+               } else if (!page->slab) {
                        printk(KERN_ERR
                                "SLUB <none>: no slab for object 0x%p.\n",
                                                object);
@@ -910,7 +944,7 @@ static int free_debug_processing(struct kmem_cache *s, struct page *page,
        }
 
        /* Special debug activities for freeing objects */
-       if (!SlabFrozen(page) && !page->freelist)
+       if (!SlabFrozen(page) && page->freelist == page->end)
                remove_full(s, page);
        if (s->flags & SLAB_STORE_USER)
                set_track(s, object, TRACK_FREE, addr);
@@ -1007,7 +1041,7 @@ static unsigned long kmem_cache_flags(unsigned long objsize,
                 */
                if (slub_debug && (!slub_debug_slabs ||
                    strncmp(slub_debug_slabs, name,
-                       strlen(slub_debug_slabs)) == 0))
+                       strlen(slub_debug_slabs)) == 0))
                                flags |= slub_debug;
        }
 
@@ -1102,6 +1136,7 @@ static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
                SetSlabDebug(page);
 
        start = page_address(page);
+       page->end = start + 1;
 
        if (unlikely(s->flags & SLAB_POISON))
                memset(start, POISON_INUSE, PAGE_SIZE << s->order);
@@ -1113,7 +1148,7 @@ static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
                last = p;
        }
        setup_object(s, page, last);
-       set_freepointer(s, last, NULL);
+       set_freepointer(s, last, page->end);
 
        page->freelist = start;
        page->inuse = 0;
@@ -1129,7 +1164,7 @@ static void __free_slab(struct kmem_cache *s, struct page *page)
                void *p;
 
                slab_pad_check(s, page);
-               for_each_object(p, s, page_address(page))
+               for_each_object(p, s, slab_address(page))
                        check_object(s, page, p, 0);
                ClearSlabDebug(page);
        }
@@ -1139,6 +1174,7 @@ static void __free_slab(struct kmem_cache *s, struct page *page)
                NR_SLAB_RECLAIMABLE : NR_SLAB_UNRECLAIMABLE,
                -pages);
 
+       page->mapping = NULL;
        __free_pages(page, s->order);
 }
 
@@ -1183,7 +1219,7 @@ static __always_inline void slab_lock(struct page *page)
 
 static __always_inline void slab_unlock(struct page *page)
 {
-       bit_spin_unlock(PG_locked, &page->flags);
+       __bit_spin_unlock(PG_locked, &page->flags);
 }
 
 static __always_inline int slab_trylock(struct page *page)
@@ -1294,8 +1330,8 @@ static struct page *get_any_partial(struct kmem_cache *s, gfp_t flags)
                        get_cycles() % 1024 > s->remote_node_defrag_ratio)
                return NULL;
 
-       zonelist = &NODE_DATA(slab_node(current->mempolicy))
-                                       ->node_zonelists[gfp_zone(flags)];
+       zonelist = &NODE_DATA(
+               slab_node(current->mempolicy))->node_zonelists[gfp_zone(flags)];
        for (z = zonelist->zones; *z; z++) {
                struct kmem_cache_node *n;
 
@@ -1337,17 +1373,22 @@ static struct page *get_partial(struct kmem_cache *s, gfp_t flags, int node)
 static void unfreeze_slab(struct kmem_cache *s, struct page *page, int tail)
 {
        struct kmem_cache_node *n = get_node(s, page_to_nid(page));
+       struct kmem_cache_cpu *c = get_cpu_slab(s, smp_processor_id());
 
        ClearSlabFrozen(page);
        if (page->inuse) {
 
-               if (page->freelist)
+               if (page->freelist != page->end) {
                        add_partial(n, page, tail);
-               else if (SlabDebug(page) && (s->flags & SLAB_STORE_USER))
-                       add_full(n, page);
+                       stat(c, tail ? DEACTIVATE_TO_TAIL : DEACTIVATE_TO_HEAD);
+               } else {
+                       stat(c, DEACTIVATE_FULL);
+                       if (SlabDebug(page) && (s->flags & SLAB_STORE_USER))
+                               add_full(n, page);
+               }
                slab_unlock(page);
-
        } else {
+               stat(c, DEACTIVATE_EMPTY);
                if (n->nr_partial < MIN_PARTIAL) {
                        /*
                         * Adding an empty slab to the partial slabs in order
@@ -1361,6 +1402,7 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page, int tail)
                        slab_unlock(page);
                } else {
                        slab_unlock(page);
+                       stat(get_cpu_slab(s, raw_smp_processor_id()), FREE_SLAB);
                        discard_slab(s, page);
                }
        }
@@ -1373,12 +1415,19 @@ static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
 {
        struct page *page = c->page;
        int tail = 1;
+
+       if (c->freelist)
+               stat(c, DEACTIVATE_REMOTE_FREES);
        /*
         * Merge cpu freelist into freelist. Typically we get here
         * because both freelists are empty. So this is unlikely
         * to occur.
+        *
+        * We need to use _is_end here because deactivate slab may
+        * be called for a debug slab. Then c->freelist may contain
+        * a dummy pointer.
         */
-       while (unlikely(c->freelist)) {
+       while (unlikely(!is_end(c->freelist))) {
                void **object;
 
                tail = 0;       /* Hot objects. Put the slab first */
@@ -1398,6 +1447,7 @@ static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
 
 static inline void flush_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
 {
+       stat(c, CPUSLAB_FLUSH);
        slab_lock(c->page);
        deactivate_slab(s, c);
 }
@@ -1469,16 +1519,21 @@ static void *__slab_alloc(struct kmem_cache *s,
 {
        void **object;
        struct page *new;
+#ifdef SLUB_FASTPATH
+       unsigned long flags;
 
+       local_irq_save(flags);
+#endif
        if (!c->page)
                goto new_slab;
 
        slab_lock(c->page);
        if (unlikely(!node_match(c, node)))
                goto another_slab;
+       stat(c, ALLOC_REFILL);
 load_freelist:
        object = c->page->freelist;
-       if (unlikely(!object))
+       if (unlikely(object == c->page->end))
                goto another_slab;
        if (unlikely(SlabDebug(c->page)))
                goto debug;
@@ -1486,9 +1541,15 @@ load_freelist:
        object = c->page->freelist;
        c->freelist = object[c->offset];
        c->page->inuse = s->objects;
-       c->page->freelist = NULL;
+       c->page->freelist = c->page->end;
        c->node = page_to_nid(c->page);
+unlock_out:
        slab_unlock(c->page);
+       stat(c, ALLOC_SLOWPATH);
+out:
+#ifdef SLUB_FASTPATH
+       local_irq_restore(flags);
+#endif
        return object;
 
 another_slab:
@@ -1498,6 +1559,7 @@ new_slab:
        new = get_partial(s, gfpflags, node);
        if (new) {
                c->page = new;
+               stat(c, ALLOC_FROM_PARTIAL);
                goto load_freelist;
        }
 
@@ -1511,6 +1573,7 @@ new_slab:
 
        if (new) {
                c = get_cpu_slab(s, smp_processor_id());
+               stat(c, ALLOC_SLAB);
                if (c->page)
                        flush_slab(s, c);
                slab_lock(new);
@@ -1518,7 +1581,8 @@ new_slab:
                c->page = new;
                goto load_freelist;
        }
-       return NULL;
+       object = NULL;
+       goto out;
 debug:
        object = c->page->freelist;
        if (!alloc_debug_processing(s, c->page, object, addr))
@@ -1527,8 +1591,7 @@ debug:
        c->page->inuse++;
        c->page->freelist = object[c->offset];
        c->node = -1;
-       slab_unlock(c->page);
-       return object;
+       goto unlock_out;
 }
 
 /*
@@ -1545,20 +1608,50 @@ static __always_inline void *slab_alloc(struct kmem_cache *s,
                gfp_t gfpflags, int node, void *addr)
 {
        void **object;
-       unsigned long flags;
        struct kmem_cache_cpu *c;
 
+/*
+ * The SLUB_FASTPATH path is provisional and is currently disabled if the
+ * kernel is compiled with preemption or if the arch does not support
+ * fast cmpxchg operations. There are a couple of coming changes that will
+ * simplify matters and allow preemption. Ultimately we may end up making
+ * SLUB_FASTPATH the default.
+ *
+ * 1. The introduction of the per cpu allocator will avoid array lookups
+ *    through get_cpu_slab(). A special register can be used instead.
+ *
+ * 2. The introduction of per cpu atomic operations (cpu_ops) means that
+ *    we can realize the logic here entirely with per cpu atomics. The
+ *    per cpu atomic ops will take care of the preemption issues.
+ */
+
+#ifdef SLUB_FASTPATH
+       c = get_cpu_slab(s, raw_smp_processor_id());
+       do {
+               object = c->freelist;
+               if (unlikely(is_end(object) || !node_match(c, node))) {
+                       object = __slab_alloc(s, gfpflags, node, addr, c);
+                       break;
+               }
+               stat(c, ALLOC_FASTPATH);
+       } while (cmpxchg_local(&c->freelist, object, object[c->offset])
+                                                               != object);
+#else
+       unsigned long flags;
+
        local_irq_save(flags);
        c = get_cpu_slab(s, smp_processor_id());
-       if (unlikely(!c->freelist || !node_match(c, node)))
+       if (unlikely(is_end(c->freelist) || !node_match(c, node)))
 
                object = __slab_alloc(s, gfpflags, node, addr, c);
 
        else {
                object = c->freelist;
                c->freelist = object[c->offset];
+               stat(c, ALLOC_FASTPATH);
        }
        local_irq_restore(flags);
+#endif
 
        if (unlikely((gfpflags & __GFP_ZERO) && object))
                memset(object, 0, c->objsize);
@@ -1593,7 +1686,15 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
 {
        void *prior;
        void **object = (void *)x;
+       struct kmem_cache_cpu *c;
+
+#ifdef SLUB_FASTPATH
+       unsigned long flags;
 
+       local_irq_save(flags);
+#endif
+       c = get_cpu_slab(s, raw_smp_processor_id());
+       stat(c, FREE_SLOWPATH);
        slab_lock(page);
 
        if (unlikely(SlabDebug(page)))
@@ -1603,8 +1704,10 @@ checks_ok:
        page->freelist = object;
        page->inuse--;
 
-       if (unlikely(SlabFrozen(page)))
+       if (unlikely(SlabFrozen(page))) {
+               stat(c, FREE_FROZEN);
                goto out_unlock;
+       }
 
        if (unlikely(!page->inuse))
                goto slab_empty;
@@ -1614,21 +1717,31 @@ checks_ok:
         * was not on the partial list before
         * then add it.
         */
-       if (unlikely(!prior))
+       if (unlikely(prior == page->end)) {
                add_partial(get_node(s, page_to_nid(page)), page, 1);
+               stat(c, FREE_ADD_PARTIAL);
+       }
 
 out_unlock:
        slab_unlock(page);
+#ifdef SLUB_FASTPATH
+       local_irq_restore(flags);
+#endif
        return;
 
 slab_empty:
-       if (prior)
+       if (prior != page->end) {
                /*
                 * Slab still on the partial list.
                 */
                remove_partial(s, page);
-
+               stat(c, FREE_REMOVE_PARTIAL);
+       }
        slab_unlock(page);
+       stat(c, FREE_SLAB);
+#ifdef SLUB_FASTPATH
+       local_irq_restore(flags);
+#endif
        discard_slab(s, page);
        return;
 
@@ -1653,19 +1766,49 @@ static __always_inline void slab_free(struct kmem_cache *s,
                        struct page *page, void *x, void *addr)
 {
        void **object = (void *)x;
-       unsigned long flags;
        struct kmem_cache_cpu *c;
 
+#ifdef SLUB_FASTPATH
+       void **freelist;
+
+       c = get_cpu_slab(s, raw_smp_processor_id());
+       debug_check_no_locks_freed(object, s->objsize);
+       do {
+               freelist = c->freelist;
+               barrier();
+               /*
+                * If the compiler would reorder the retrieval of c->page to
+                * come before c->freelist then an interrupt could
+                * change the cpu slab before we retrieve c->freelist. We
+                * could be matching on a page no longer active and put the
+                * object onto the freelist of the wrong slab.
+                *
+                * On the other hand: If we already have the freelist pointer
+                * then any change of cpu_slab will cause the cmpxchg to fail
+                * since the freelist pointers are unique per slab.
+                */
+               if (unlikely(page != c->page || c->node < 0)) {
+                       __slab_free(s, page, x, addr, c->offset);
+                       break;
+               }
+               object[c->offset] = freelist;
+               stat(c, FREE_FASTPATH);
+       } while (cmpxchg_local(&c->freelist, freelist, object) != freelist);
+#else
+       unsigned long flags;
+
        local_irq_save(flags);
        debug_check_no_locks_freed(object, s->objsize);
        c = get_cpu_slab(s, smp_processor_id());
        if (likely(page == c->page && c->node >= 0)) {
                object[c->offset] = c->freelist;
                c->freelist = object;
+               stat(c, FREE_FASTPATH);
        } else
                __slab_free(s, page, x, addr, c->offset);
 
        local_irq_restore(flags);
+#endif
 }
 
 void kmem_cache_free(struct kmem_cache *s, void *x)
@@ -1842,7 +1985,7 @@ static void init_kmem_cache_cpu(struct kmem_cache *s,
                        struct kmem_cache_cpu *c)
 {
        c->page = NULL;
-       c->freelist = NULL;
+       c->freelist = (void *)PAGE_MAPPING_ANON;
        c->node = 0;
        c->offset = s->offset / sizeof(void *);
        c->objsize = s->objsize;
@@ -2446,7 +2589,8 @@ static noinline struct kmem_cache *dma_kmalloc_cache(int index, gfp_t flags)
                goto unlock_out;
 
        realsize = kmalloc_caches[index].objsize;
-       text = kasprintf(flags & ~SLUB_DMA, "kmalloc_dma-%d", (unsigned int)realsize),
+       text = kasprintf(flags & ~SLUB_DMA, "kmalloc_dma-%d",
+                        (unsigned int)realsize);
        s = kmalloc(kmem_size, flags & ~SLUB_DMA);
 
        if (!s || !text || !kmem_cache_open(s, flags, text,
@@ -2601,6 +2745,7 @@ EXPORT_SYMBOL(ksize);
 void kfree(const void *x)
 {
        struct page *page;
+       void *object = (void *)x;
 
        if (unlikely(ZERO_OR_NULL_PTR(x)))
                return;
@@ -2610,7 +2755,7 @@ void kfree(const void *x)
                put_page(page);
                return;
        }
-       slab_free(page->slab, page, (void *)x, __builtin_return_address(0));
+       slab_free(page->slab, page, object, __builtin_return_address(0));
 }
 EXPORT_SYMBOL(kfree);
 
@@ -2896,7 +3041,8 @@ void __init kmem_cache_init(void)
 #endif
 
 
-       printk(KERN_INFO "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
+       printk(KERN_INFO
+               "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
                " CPUs=%d, Nodes=%d\n",
                caches, cache_line_size(),
                slub_min_order, slub_max_order, slub_min_objects,
@@ -3063,7 +3209,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
 }
 
 static struct notifier_block __cpuinitdata slab_notifier = {
-       &slab_cpuup_callback, NULL, 0
+       .notifier_call = slab_cpuup_callback
 };
 
 #endif
@@ -3104,7 +3250,7 @@ static int validate_slab(struct kmem_cache *s, struct page *page,
                                                unsigned long *map)
 {
        void *p;
-       void *addr = page_address(page);
+       void *addr = slab_address(page);
 
        if (!check_slab(s, page) ||
                        !on_freelist(s, page, NULL))
@@ -3221,8 +3367,9 @@ static void resiliency_test(void)
        p = kzalloc(32, GFP_KERNEL);
        p[32 + sizeof(void *)] = 0x34;
        printk(KERN_ERR "\n2. kmalloc-32: Clobber next pointer/next slab"
-                       " 0x34 -> -0x%p\n", p);
-       printk(KERN_ERR "If allocated object is overwritten then not detectable\n\n");
+                       " 0x34 -> -0x%p\n", p);
+       printk(KERN_ERR
+               "If allocated object is overwritten then not detectable\n\n");
 
        validate_slab_cache(kmalloc_caches + 5);
        p = kzalloc(64, GFP_KERNEL);
@@ -3230,7 +3377,8 @@ static void resiliency_test(void)
        *p = 0x56;
        printk(KERN_ERR "\n3. kmalloc-64: corrupting random byte 0x56->0x%p\n",
                                                                        p);
-       printk(KERN_ERR "If allocated object is overwritten then not detectable\n\n");
+       printk(KERN_ERR
+               "If allocated object is overwritten then not detectable\n\n");
        validate_slab_cache(kmalloc_caches + 6);
 
        printk(KERN_ERR "\nB. Corruption after free\n");
@@ -3243,7 +3391,8 @@ static void resiliency_test(void)
        p = kzalloc(256, GFP_KERNEL);
        kfree(p);
        p[50] = 0x9a;
-       printk(KERN_ERR "\n2. kmalloc-256: Clobber 50th byte 0x9a->0x%p\n\n", p);
+       printk(KERN_ERR "\n2. kmalloc-256: Clobber 50th byte 0x9a->0x%p\n\n",
+                       p);
        validate_slab_cache(kmalloc_caches + 8);
 
        p = kzalloc(512, GFP_KERNEL);
@@ -3384,7 +3533,7 @@ static int add_location(struct loc_track *t, struct kmem_cache *s,
 static void process_slab(struct loc_track *t, struct kmem_cache *s,
                struct page *page, enum track_item alloc)
 {
-       void *addr = page_address(page);
+       void *addr = slab_address(page);
        DECLARE_BITMAP(map, s->objects);
        void *p;
 
@@ -3872,6 +4021,62 @@ static ssize_t remote_node_defrag_ratio_store(struct kmem_cache *s,
 SLAB_ATTR(remote_node_defrag_ratio);
 #endif
 
+#ifdef CONFIG_SLUB_STATS
+
+static int show_stat(struct kmem_cache *s, char *buf, enum stat_item si)
+{
+       unsigned long sum  = 0;
+       int cpu;
+       int len;
+       int *data = kmalloc(nr_cpu_ids * sizeof(int), GFP_KERNEL);
+
+       if (!data)
+               return -ENOMEM;
+
+       for_each_online_cpu(cpu) {
+               unsigned x = get_cpu_slab(s, cpu)->stat[si];
+
+               data[cpu] = x;
+               sum += x;
+       }
+
+       len = sprintf(buf, "%lu", sum);
+
+       for_each_online_cpu(cpu) {
+               if (data[cpu] && len < PAGE_SIZE - 20)
+                       len += sprintf(buf + len, " c%d=%u", cpu, data[cpu]);
+       }
+       kfree(data);
+       return len + sprintf(buf + len, "\n");
+}
+
+#define STAT_ATTR(si, text)                                    \
+static ssize_t text##_show(struct kmem_cache *s, char *buf)    \
+{                                                              \
+       return show_stat(s, buf, si);                           \
+}                                                              \
+SLAB_ATTR_RO(text);                                            \
+
+STAT_ATTR(ALLOC_FASTPATH, alloc_fastpath);
+STAT_ATTR(ALLOC_SLOWPATH, alloc_slowpath);
+STAT_ATTR(FREE_FASTPATH, free_fastpath);
+STAT_ATTR(FREE_SLOWPATH, free_slowpath);
+STAT_ATTR(FREE_FROZEN, free_frozen);
+STAT_ATTR(FREE_ADD_PARTIAL, free_add_partial);
+STAT_ATTR(FREE_REMOVE_PARTIAL, free_remove_partial);
+STAT_ATTR(ALLOC_FROM_PARTIAL, alloc_from_partial);
+STAT_ATTR(ALLOC_SLAB, alloc_slab);
+STAT_ATTR(ALLOC_REFILL, alloc_refill);
+STAT_ATTR(FREE_SLAB, free_slab);
+STAT_ATTR(CPUSLAB_FLUSH, cpuslab_flush);
+STAT_ATTR(DEACTIVATE_FULL, deactivate_full);
+STAT_ATTR(DEACTIVATE_EMPTY, deactivate_empty);
+STAT_ATTR(DEACTIVATE_TO_HEAD, deactivate_to_head);
+STAT_ATTR(DEACTIVATE_TO_TAIL, deactivate_to_tail);
+STAT_ATTR(DEACTIVATE_REMOTE_FREES, deactivate_remote_frees);
+
+#endif
+
 static struct attribute *slab_attrs[] = {
        &slab_size_attr.attr,
        &object_size_attr.attr,
@@ -3901,6 +4106,25 @@ static struct attribute *slab_attrs[] = {
 #endif
 #ifdef CONFIG_NUMA
        &remote_node_defrag_ratio_attr.attr,
+#endif
+#ifdef CONFIG_SLUB_STATS
+       &alloc_fastpath_attr.attr,
+       &alloc_slowpath_attr.attr,
+       &free_fastpath_attr.attr,
+       &free_slowpath_attr.attr,
+       &free_frozen_attr.attr,
+       &free_add_partial_attr.attr,
+       &free_remove_partial_attr.attr,
+       &alloc_from_partial_attr.attr,
+       &alloc_slab_attr.attr,
+       &alloc_refill_attr.attr,
+       &free_slab_attr.attr,
+       &cpuslab_flush_attr.attr,
+       &deactivate_full_attr.attr,
+       &deactivate_empty_attr.attr,
+       &deactivate_to_head_attr.attr,
+       &deactivate_to_tail_attr.attr,
+       &deactivate_remote_frees_attr.attr,
 #endif
        NULL
 };
index 0536dde139d1e1f6f28fc93ccd05a9fc337e2c7e..950c0be9ca8154d7b119019e50be5dc6838faa5b 100644 (file)
@@ -820,7 +820,7 @@ void  __attribute__((weak)) vmalloc_sync_all(void)
 }
 
 
-static int f(pte_t *pte, struct page *pmd_page, unsigned long addr, void *data)
+static int f(pte_t *pte, pgtable_t table, unsigned long addr, void *data)
 {
        /* apply_to_page_range() does all the hard work. */
        return 0;
index b6a5d454f2ffa9219c4037c68e50d6b49eef6f2f..6627c6ae5db682a77ff92a8bb0cf577c69c32fac 100644 (file)
@@ -30,7 +30,7 @@ menu "Networking options"
 config NET_NS
        bool "Network namespace support"
        default n
-       depends on EXPERIMENTAL && !SYSFS
+       depends on EXPERIMENTAL && !SYSFS && NAMESPACES
        help
          Allow user space to create what appear to be multiple instances
          of the network stack.
index 5158e886630f3c2ba732a4c7df8f5d34abd8607c..36b9f22ed83a4aa668478a2a0b3502fcb2a7b3ba 100644 (file)
@@ -118,7 +118,6 @@ static int can_create(struct net *net, struct socket *sock, int protocol)
 {
        struct sock *sk;
        struct can_proto *cp;
-       char module_name[sizeof("can-proto-000")];
        int err = 0;
 
        sock->state = SS_UNCONNECTED;
@@ -129,26 +128,21 @@ static int can_create(struct net *net, struct socket *sock, int protocol)
        if (net != &init_net)
                return -EAFNOSUPPORT;
 
+#ifdef CONFIG_KMOD
        /* try to load protocol module, when CONFIG_KMOD is defined */
        if (!proto_tab[protocol]) {
-               sprintf(module_name, "can-proto-%d", protocol);
-               err = request_module(module_name);
+               err = request_module("can-proto-%d", protocol);
 
                /*
                 * In case of error we only print a message but don't
                 * return the error code immediately.  Below we will
                 * return -EPROTONOSUPPORT
                 */
-               if (err == -ENOSYS) {
-                       if (printk_ratelimit())
-                               printk(KERN_INFO "can: request_module(%s)"
-                                      " not implemented.\n", module_name);
-               } else if (err) {
-                       if (printk_ratelimit())
-                               printk(KERN_ERR "can: request_module(%s)"
-                                      " failed.\n", module_name);
-               }
+               if (err && printk_ratelimit())
+                       printk(KERN_ERR "can: request_module "
+                              "(can-proto-%d) failed.\n", protocol);
        }
+#endif
 
        spin_lock(&proto_tab_lock);
        cp = proto_tab[protocol];
@@ -662,26 +656,26 @@ int can_proto_register(struct can_proto *cp)
                return -EINVAL;
        }
 
+       err = proto_register(cp->prot, 0);
+       if (err < 0)
+               return err;
+
        spin_lock(&proto_tab_lock);
        if (proto_tab[proto]) {
                printk(KERN_ERR "can: protocol %d already registered\n",
                       proto);
                err = -EBUSY;
-               goto errout;
+       } else {
+               proto_tab[proto] = cp;
+
+               /* use generic ioctl function if not defined by module */
+               if (!cp->ops->ioctl)
+                       cp->ops->ioctl = can_ioctl;
        }
+       spin_unlock(&proto_tab_lock);
 
-       err = proto_register(cp->prot, 0);
        if (err < 0)
-               goto errout;
-
-       proto_tab[proto] = cp;
-
-       /* use generic ioctl function if the module doesn't bring its own */
-       if (!cp->ops->ioctl)
-               cp->ops->ioctl = can_ioctl;
-
- errout:
-       spin_unlock(&proto_tab_lock);
+               proto_unregister(cp->prot);
 
        return err;
 }
@@ -700,9 +694,10 @@ void can_proto_unregister(struct can_proto *cp)
                printk(KERN_ERR "BUG: can: protocol %d is not registered\n",
                       proto);
        }
-       proto_unregister(cp->prot);
        proto_tab[proto] = NULL;
        spin_unlock(&proto_tab_lock);
+
+       proto_unregister(cp->prot);
 }
 EXPORT_SYMBOL(can_proto_unregister);
 
index aeefd1419d009da25a1171ff4f1c7d05e12bd981..94cd7f27c44470109263bd653301e9944b403496 100644 (file)
@@ -98,7 +98,6 @@ static void raw_rcv(struct sk_buff *skb, void *data)
        struct sock *sk = (struct sock *)data;
        struct raw_sock *ro = raw_sk(sk);
        struct sockaddr_can *addr;
-       int error;
 
        if (!ro->recv_own_msgs) {
                /* check the received tx sock reference */
@@ -121,14 +120,12 @@ static void raw_rcv(struct sk_buff *skb, void *data)
        addr->can_family  = AF_CAN;
        addr->can_ifindex = skb->dev->ifindex;
 
-       error = sock_queue_rcv_skb(sk, skb);
-       if (error < 0)
+       if (sock_queue_rcv_skb(sk, skb) < 0)
                kfree_skb(skb);
 }
 
 static int raw_enable_filters(struct net_device *dev, struct sock *sk,
-                             struct can_filter *filter,
-                             int count)
+                             struct can_filter *filter, int count)
 {
        int err = 0;
        int i;
@@ -163,8 +160,7 @@ static int raw_enable_errfilter(struct net_device *dev, struct sock *sk,
 }
 
 static void raw_disable_filters(struct net_device *dev, struct sock *sk,
-                             struct can_filter *filter,
-                             int count)
+                             struct can_filter *filter, int count)
 {
        int i;
 
@@ -353,7 +349,6 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len)
                /* filters set by default/setsockopt */
                err = raw_enable_allfilters(dev, sk);
                dev_put(dev);
-
        } else {
                ifindex = 0;
 
@@ -466,7 +461,6 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
                        if (err) {
                                if (count > 1)
                                        kfree(filter);
-
                                goto out_fil;
                        }
 
@@ -673,25 +667,25 @@ static int raw_recvmsg(struct kiocb *iocb, struct socket *sock,
 {
        struct sock *sk = sock->sk;
        struct sk_buff *skb;
-       int error = 0;
+       int err = 0;
        int noblock;
 
        noblock =  flags & MSG_DONTWAIT;
        flags   &= ~MSG_DONTWAIT;
 
-       skb = skb_recv_datagram(sk, flags, noblock, &error);
+       skb = skb_recv_datagram(sk, flags, noblock, &err);
        if (!skb)
-               return error;
+               return err;
 
        if (size < skb->len)
                msg->msg_flags |= MSG_TRUNC;
        else
                size = skb->len;
 
-       error = memcpy_toiovec(msg->msg_iov, skb->data, size);
-       if (error < 0) {
+       err = memcpy_toiovec(msg->msg_iov, skb->data, size);
+       if (err < 0) {
                skb_free_datagram(sk, skb);
-               return error;
+               return err;
        }
 
        sock_recv_timestamp(msg, sk, skb);
index 46b38e06e0d75601bde3fbef5dbf3048008bc263..a77531c139b7d85dbb6f11297d7cea363acd7074 100644 (file)
@@ -30,8 +30,8 @@ struct flow_cache_entry {
        struct flow_cache_entry *next;
        u16                     family;
        u8                      dir;
-       struct flowi            key;
        u32                     genid;
+       struct flowi            key;
        void                    *object;
        atomic_t                *object_ref;
 };
@@ -52,7 +52,7 @@ struct flow_percpu_info {
        int hash_rnd_recalc;
        u32 hash_rnd;
        int count;
-} ____cacheline_aligned;
+};
 static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
 
 #define flow_hash_rnd_recalc(cpu) \
@@ -346,7 +346,7 @@ static int __init flow_cache_init(void)
 
        flow_cachep = kmem_cache_create("flow_cache",
                                        sizeof(struct flow_cache_entry),
-                                       0, SLAB_HWCACHE_ALIGN|SLAB_PANIC,
+                                       0, SLAB_PANIC,
                                        NULL);
        flow_hash_shift = 10;
        flow_lwm = 2 * flow_hash_size;
index 31be29b8b5a3cb597b7ea991ef0c074293692b5b..9dc0abb50eaf05ba0db41ed0566a0c4a9516f1c8 100644 (file)
@@ -94,7 +94,7 @@ struct dn_rt_hash_bucket
 {
        struct dn_route *chain;
        spinlock_t lock;
-} __attribute__((__aligned__(8)));
+};
 
 extern struct neigh_table dn_neigh_table;
 
index dd07362d2b8f42e5303419d509a0a1136e51cd42..0d5fa3a54d04053f8068ce685c157ffa554c8539 100644 (file)
@@ -600,10 +600,10 @@ static void nf_nat_cleanup_conntrack(struct nf_conn *ct)
        spin_unlock_bh(&nf_nat_lock);
 }
 
-static void nf_nat_move_storage(struct nf_conn *conntrack, void *old)
+static void nf_nat_move_storage(void *new, void *old)
 {
-       struct nf_conn_nat *new_nat = nf_ct_ext_find(conntrack, NF_CT_EXT_NAT);
-       struct nf_conn_nat *old_nat = (struct nf_conn_nat *)old;
+       struct nf_conn_nat *new_nat = new;
+       struct nf_conn_nat *old_nat = old;
        struct nf_conn *ct = old_nat->ct;
 
        if (!ct || !(ct->status & IPS_NAT_DONE_MASK))
index 8842ecb9be484e279a603053912c0f850b4eb11b..525787b52b72f03f87e77c0f785623083fca8b2b 100644 (file)
@@ -2041,7 +2041,7 @@ int ip_route_input(struct sk_buff *skb, __be32 daddr, __be32 saddr,
        int iif = dev->ifindex;
        struct net *net;
 
-       net = skb->dev->nd_net;
+       net = dev->nd_net;
        tos &= IPTOS_RT_MASK;
        hash = rt_hash(daddr, saddr, iif);
 
index 2255e3c082ed68d6c493f481b87b136a9b53a943..fee22caf1bad54b37edb00e3554a53615a8cb82b 100644 (file)
@@ -482,6 +482,10 @@ static int iucv_sock_connect(struct socket *sock, struct sockaddr *addr,
        /* Create path. */
        iucv->path = iucv_path_alloc(IUCV_QUEUELEN_DEFAULT,
                                     IPRMDATA, GFP_KERNEL);
+       if (!iucv->path) {
+               err = -ENOMEM;
+               goto done;
+       }
        err = iucv_path_connect(iucv->path, &af_iucv_handler,
                                sa->siucv_user_id, NULL, user_data, sk);
        if (err) {
@@ -1094,6 +1098,8 @@ static void iucv_callback_rx(struct iucv_path *path, struct iucv_message *msg)
 
 save_message:
        save_msg = kzalloc(sizeof(struct sock_msg_q), GFP_ATOMIC | GFP_DMA);
+       if (!save_msg)
+               return;
        save_msg->path = path;
        save_msg->msg = *msg;
 
@@ -1106,24 +1112,31 @@ static void iucv_callback_txdone(struct iucv_path *path,
                                 struct iucv_message *msg)
 {
        struct sock *sk = path->private;
-       struct sk_buff *this;
+       struct sk_buff *this = NULL;
        struct sk_buff_head *list = &iucv_sk(sk)->send_skb_q;
        struct sk_buff *list_skb = list->next;
        unsigned long flags;
 
-       if (list_skb) {
+       if (!skb_queue_empty(list)) {
                spin_lock_irqsave(&list->lock, flags);
 
-               do {
-                       this = list_skb;
+               while (list_skb != (struct sk_buff *)list) {
+                       if (!memcmp(&msg->tag, list_skb->cb, 4)) {
+                               this = list_skb;
+                               break;
+                       }
                        list_skb = list_skb->next;
-               } while (memcmp(&msg->tag, this->cb, 4) && list_skb);
+               }
+               if (this)
+                       __skb_unlink(this, list);
 
                spin_unlock_irqrestore(&list->lock, flags);
 
-               skb_unlink(this, &iucv_sk(sk)->send_skb_q);
-               kfree_skb(this);
+               if (this)
+                       kfree_skb(this);
        }
+       if (!this)
+               printk(KERN_ERR "AF_IUCV msg tag %u not found\n", msg->tag);
 
        if (sk->sk_state == IUCV_CLOSING) {
                if (skb_queue_empty(&iucv_sk(sk)->send_skb_q)) {
index f13fe8821cbd7bf7817c6eacb85709aaca134492..2753b0c448f374f3f27c26f991e97d94c43459ad 100644 (file)
@@ -693,9 +693,9 @@ int iucv_register(struct iucv_handler *handler, int smp)
                iucv_setmask_up();
        INIT_LIST_HEAD(&handler->paths);
 
-       spin_lock_irq(&iucv_table_lock);
+       spin_lock_bh(&iucv_table_lock);
        list_add_tail(&handler->list, &iucv_handler_list);
-       spin_unlock_irq(&iucv_table_lock);
+       spin_unlock_bh(&iucv_table_lock);
        rc = 0;
 out_mutex:
        mutex_unlock(&iucv_register_mutex);
index cf6ba6659a8080938b3aaaa44c6ef46d0a47ad72..8b9be1e978cda3dc00c01050d69e495ac8c610ad 100644 (file)
@@ -109,7 +109,8 @@ void *__nf_ct_ext_add(struct nf_conn *ct, enum nf_ct_ext_id id, gfp_t gfp)
                        rcu_read_lock();
                        t = rcu_dereference(nf_ct_ext_types[i]);
                        if (t && t->move)
-                               t->move(ct, ct->ext + ct->ext->offset[i]);
+                               t->move((void *)new + new->offset[i],
+                                       (void *)ct->ext + ct->ext->offset[i]);
                        rcu_read_unlock();
                }
                kfree(ct->ext);
index 3e0cccae563648b735f125cde27125367e6d0f4e..202d7fa09483841ac91143f1d1c53dab9d6a6d50 100644 (file)
@@ -125,7 +125,7 @@ enum tcp_bit_set {
  * CLOSE_WAIT: ACK seen (after FIN)
  * LAST_ACK:   FIN seen (after FIN)
  * TIME_WAIT:  last ACK seen
- * CLOSE:      closed connection
+ * CLOSE:      closed connection (RST)
  *
  * LISTEN state is not used.
  *
@@ -824,7 +824,21 @@ static int tcp_packet(struct nf_conn *ct,
        case TCP_CONNTRACK_SYN_SENT:
                if (old_state < TCP_CONNTRACK_TIME_WAIT)
                        break;
-               if ((ct->proto.tcp.seen[!dir].flags & IP_CT_TCP_FLAG_CLOSE_INIT)
+               /* RFC 1122: "When a connection is closed actively,
+                * it MUST linger in TIME-WAIT state for a time 2xMSL
+                * (Maximum Segment Lifetime). However, it MAY accept
+                * a new SYN from the remote TCP to reopen the connection
+                * directly from TIME-WAIT state, if..."
+                * We ignore the conditions because we are in the
+                * TIME-WAIT state anyway.
+                *
+                * Handle aborted connections: we and the server
+                * think there is an existing connection but the client
+                * aborts it and starts a new one.
+                */
+               if (((ct->proto.tcp.seen[dir].flags
+                     | ct->proto.tcp.seen[!dir].flags)
+                    & IP_CT_TCP_FLAG_CLOSE_INIT)
                    || (ct->proto.tcp.last_dir == dir
                        && ct->proto.tcp.last_index == TCP_RST_SET)) {
                        /* Attempt to reopen a closed/aborted connection.
@@ -837,16 +851,23 @@ static int tcp_packet(struct nf_conn *ct,
                /* Fall through */
        case TCP_CONNTRACK_IGNORE:
                /* Ignored packets:
+                *
+                * Our connection entry may be out of sync, so ignore
+                * packets which may signal the real connection between
+                * the client and the server.
                 *
                 * a) SYN in ORIGINAL
                 * b) SYN/ACK in REPLY
                 * c) ACK in reply direction after initial SYN in original.
+                *
+                * If the ignored packet is invalid, the receiver will send
+                * a RST we'll catch below.
                 */
                if (index == TCP_SYNACK_SET
                    && ct->proto.tcp.last_index == TCP_SYN_SET
                    && ct->proto.tcp.last_dir != dir
                    && ntohl(th->ack_seq) == ct->proto.tcp.last_end) {
-                       /* This SYN/ACK acknowledges a SYN that we earlier
+                       /* b) This SYN/ACK acknowledges a SYN that we earlier
                         * ignored as invalid. This means that the client and
                         * the server are both in sync, while the firewall is
                         * not. We kill this session and block the SYN/ACK so
@@ -870,7 +891,7 @@ static int tcp_packet(struct nf_conn *ct,
                write_unlock_bh(&tcp_lock);
                if (LOG_INVALID(IPPROTO_TCP))
                        nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
-                                 "nf_ct_tcp: invalid packed ignored ");
+                                 "nf_ct_tcp: invalid packet ignored ");
                return NF_ACCEPT;
        case TCP_CONNTRACK_MAX:
                /* Invalid packet */
@@ -924,8 +945,7 @@ static int tcp_packet(struct nf_conn *ct,
 
        ct->proto.tcp.state = new_state;
        if (old_state != new_state
-           && (new_state == TCP_CONNTRACK_FIN_WAIT
-               || new_state == TCP_CONNTRACK_CLOSE))
+           && new_state == TCP_CONNTRACK_CLOSE)
                ct->proto.tcp.seen[dir].flags |= IP_CT_TCP_FLAG_CLOSE_INIT;
        timeout = ct->proto.tcp.retrans >= nf_ct_tcp_max_retrans
                  && tcp_timeouts[new_state] > nf_ct_tcp_timeout_max_retrans
index 01035fc0e140637146c16b0413db56baf6aa3180..4f984dc60319645648a66403bcb2dd2f014efd23 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/ip.h>
 #include <linux/ipv6.h>
 #include <linux/netfilter/x_tables.h>
+#include <linux/netfilter/xt_iprange.h>
 #include <linux/netfilter_ipv4/ipt_iprange.h>
 
 static bool
@@ -148,7 +149,7 @@ static struct xt_match iprange_mt_reg[] __read_mostly = {
        {
                .name      = "iprange",
                .revision  = 1,
-               .family    = AF_INET6,
+               .family    = AF_INET,
                .match     = iprange_mt4,
                .matchsize = sizeof(struct xt_iprange_mtinfo),
                .me        = THIS_MODULE,
index 2a7e648fbcf44edd7ce7944fee7627f3590d434a..d417ec8e3ca3b1893150f98ced8b46bb3558a878 100644 (file)
@@ -735,11 +735,13 @@ static int em_meta_match(struct sk_buff *skb, struct tcf_ematch *m,
 
 static inline void meta_delete(struct meta_match *meta)
 {
-       struct meta_type_ops *ops = meta_type_ops(&meta->lvalue);
+       if (meta) {
+               struct meta_type_ops *ops = meta_type_ops(&meta->lvalue);
 
-       if (ops && ops->destroy) {
-               ops->destroy(&meta->lvalue);
-               ops->destroy(&meta->rvalue);
+               if (ops && ops->destroy) {
+                       ops->destroy(&meta->lvalue);
+                       ops->destroy(&meta->rvalue);
+               }
        }
 
        kfree(meta);
index e4bd5335e48d9eb64bdd9d5b1bf899ce7a8ec8d9..3ba67e6ce03e284ed27b87f4b6916f465dbf084b 100644 (file)
@@ -57,11 +57,6 @@ static inline int in_own_cluster(u32 addr)
        return !((addr ^ tipc_own_addr) >> 12);
 }
 
-static inline int in_own_zone(u32 addr)
-{
-       return !((addr ^ tipc_own_addr) >> 24);
-}
-
 static inline int is_slave(u32 addr)
 {
        return addr & 0x800;
index f910ed29d05570172223da5070a0aefa1e772df5..a2416fa6b90688752ea67dddefa9642244281565 100644 (file)
@@ -73,19 +73,6 @@ struct node;
 extern char tipc_bclink_name[];
 
 
-/**
- * nmap_get - determine if node exists in a node map
- */
-
-static inline int tipc_nmap_get(struct node_map *nm_ptr, u32 node)
-{
-       int n = tipc_node(node);
-       int w = n / WSIZE;
-       int b = n % WSIZE;
-
-       return nm_ptr->map[w] & (1 << b);
-}
-
 /**
  * nmap_add - add a node to a node map
  */
index ce2659836374c8341d597bfc43d8dcbacf2b3dcf..e9ef6df26562c224256006f4a71733347ca354f7 100644 (file)
@@ -663,11 +663,6 @@ static inline void msg_set_remote_node(struct tipc_msg *m, u32 a)
        msg_set_word(m, msg_hdr_sz(m)/4, a);
 }
 
-static inline int msg_dataoctet(struct tipc_msg *m, u32 pos)
-{
-       return(msg_data(m)[pos + 4] != 0);
-}
-
 static inline void msg_set_dataoctet(struct tipc_msg *m, u32 pos)
 {
        msg_data(m)[pos + 4] = 1;
index 24ddfd2ca38bf037e6b1710e78dedcd24aa0e1df..22909036b9bc35195a84408b4f9e23440464f189 100644 (file)
@@ -71,9 +71,9 @@ struct tipc_sock {
 static u32 dispatch(struct tipc_port *tport, struct sk_buff *buf);
 static void wakeupdispatch(struct tipc_port *tport);
 
-static struct proto_ops packet_ops;
-static struct proto_ops stream_ops;
-static struct proto_ops msg_ops;
+static const struct proto_ops packet_ops;
+static const struct proto_ops stream_ops;
+static const struct proto_ops msg_ops;
 
 static struct proto tipc_proto;
 
@@ -1615,7 +1615,7 @@ static int getsockopt(struct socket *sock,
  * Protocol switches for the various types of TIPC sockets
  */
 
-static struct proto_ops msg_ops = {
+static const struct proto_ops msg_ops = {
        .owner          = THIS_MODULE,
        .family         = AF_TIPC,
        .release        = release,
@@ -1636,7 +1636,7 @@ static struct proto_ops msg_ops = {
        .sendpage       = sock_no_sendpage
 };
 
-static struct proto_ops packet_ops = {
+static const struct proto_ops packet_ops = {
        .owner          = THIS_MODULE,
        .family         = AF_TIPC,
        .release        = release,
@@ -1657,7 +1657,7 @@ static struct proto_ops packet_ops = {
        .sendpage       = sock_no_sendpage
 };
 
-static struct proto_ops stream_ops = {
+static const struct proto_ops stream_ops = {
        .owner          = THIS_MODULE,
        .family         = AF_TIPC,
        .release        = release,
@@ -1678,7 +1678,7 @@ static struct proto_ops stream_ops = {
        .sendpage       = sock_no_sendpage
 };
 
-static struct net_proto_family tipc_family_ops = {
+static const struct net_proto_family tipc_family_ops = {
        .owner          = THIS_MODULE,
        .family         = AF_TIPC,
        .create         = tipc_create
index 6cc15250de69949606638cd6fab4afb6a0cadee5..8aa6440d689f75bde521070c5d3f81ce5c81199b 100644 (file)
@@ -399,6 +399,23 @@ static struct xfrm_algo_desc ealg_list[] = {
                .sadb_alg_maxbits = 256
        }
 },
+{
+       .name = "rfc3686(ctr(aes))",
+
+       .uinfo = {
+               .encr = {
+                       .blockbits = 128,
+                       .defkeybits = 160, /* 128-bit key + 32-bit nonce */
+               }
+       },
+
+       .desc = {
+               .sadb_alg_id = SADB_X_EALG_AESCTR,
+               .sadb_alg_ivlen = 8,
+               .sadb_alg_minbits = 128,
+               .sadb_alg_maxbits = 256
+       }
+},
 };
 
 static struct xfrm_algo_desc calg_list[] = {
index 579f50fa838c507fa120c46fb0546ba544ba90ea..2086a856400a9c7258958b96fe0f3d53d3d70ff8 100755 (executable)
@@ -9,7 +9,7 @@ use strict;
 my $P = $0;
 $P =~ s@.*/@@g;
 
-my $V = '0.12';
+my $V = '0.14';
 
 use Getopt::Long qw(:config no_auto_abbrev);
 
@@ -24,13 +24,14 @@ my $file = 0;
 my $check = 0;
 my $summary = 1;
 my $mailback = 0;
+my $summary_file = 0;
 my $root;
+my %debug;
 GetOptions(
        'q|quiet+'      => \$quiet,
        'tree!'         => \$tree,
        'signoff!'      => \$chk_signoff,
        'patch!'        => \$chk_patch,
-       'test-type!'    => \$tst_type,
        'emacs!'        => \$emacs,
        'terse!'        => \$terse,
        'file!'         => \$file,
@@ -39,6 +40,10 @@ GetOptions(
        'root=s'        => \$root,
        'summary!'      => \$summary,
        'mailback!'     => \$mailback,
+       'summary-file!' => \$summary_file,
+
+       'debug=s'       => \%debug,
+       'test-type!'    => \$tst_type,
 ) or exit;
 
 my $exit = 0;
@@ -46,16 +51,24 @@ my $exit = 0;
 if ($#ARGV < 0) {
        print "usage: $P [options] patchfile\n";
        print "version: $V\n";
-       print "options: -q           => quiet\n";
-       print "         --no-tree    => run without a kernel tree\n";
-       print "         --terse      => one line per report\n";
-       print "         --emacs      => emacs compile window format\n";
-       print "         --file       => check a source file\n";
-       print "         --strict     => enable more subjective tests\n";
-       print "         --root       => path to the kernel tree root\n";
+       print "options: -q               => quiet\n";
+       print "         --no-tree        => run without a kernel tree\n";
+       print "         --terse          => one line per report\n";
+       print "         --emacs          => emacs compile window format\n";
+       print "         --file           => check a source file\n";
+       print "         --strict         => enable more subjective tests\n";
+       print "         --root           => path to the kernel tree root\n";
+       print "         --no-summary     => suppress the per-file summary\n";
+       print "         --summary-file   => include the filename in summary\n";
        exit(1);
 }
 
+my $dbg_values = 0;
+my $dbg_possible = 0;
+for my $key (keys %debug) {
+       eval "\${dbg_$key} = '$debug{$key}';"
+}
+
 if ($terse) {
        $emacs = 1;
        $quiet++;
@@ -110,7 +123,7 @@ our $Assignment     = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)};
 our $Operators = qr{
                        <=|>=|==|!=|
                        =>|->|<<|>>|<|>|!|~|
-                       &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/
+                       &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%
                  }x;
 
 our $NonptrType;
@@ -152,7 +165,7 @@ sub build_types {
        $Type   = qr{
                        \b$NonptrType\b
                        (?:\s*\*+\s*const|\s*\*+|(?:\s*\[\s*\])+)?
-                       (?:\s+$Sparse|\s+$Attribute)*
+                       (?:\s+$Inline|\s+$Sparse|\s+$Attribute)*
                  }x;
        $Declare        = qr{(?:$Storage\s+)?$Type};
 }
@@ -181,6 +194,8 @@ if ($tree && -f "$root/$removal") {
 }
 
 my @rawlines = ();
+my @lines = ();
+my $vname;
 for my $filename (@ARGV) {
        if ($file) {
                open(FILE, "diff -u /dev/null $filename|") ||
@@ -189,15 +204,21 @@ for my $filename (@ARGV) {
                open(FILE, "<$filename") ||
                        die "$P: $filename: open failed - $!\n";
        }
+       if ($filename eq '-') {
+               $vname = 'Your patch';
+       } else {
+               $vname = $filename;
+       }
        while (<FILE>) {
                chomp;
                push(@rawlines, $_);
        }
        close(FILE);
-       if (!process($filename, @rawlines)) {
+       if (!process($filename)) {
                $exit = 1;
        }
        @rawlines = ();
+       @lines = ();
 }
 
 exit($exit);
@@ -274,20 +295,30 @@ sub sanitise_line {
        my $l = '';
 
        my $quote = '';
+       my $qlen = 0;
 
        foreach my $c (split(//, $line)) {
+               # The second backslash of a pair is not a "quote".
+               if ($l eq "\\" && $c eq "\\") {
+                       $c = 'X';
+               }
                if ($l ne "\\" && ($c eq "'" || $c eq '"')) {
                        if ($quote eq '') {
                                $quote = $c;
                                $res .= $c;
                                $l = $c;
+                               $qlen = 0;
                                next;
                        } elsif ($quote eq $c) {
                                $quote = '';
                        }
                }
+               if ($quote eq "'" && $qlen > 1) {
+                       $quote = '';
+               }
                if ($quote && $c ne "\t") {
                        $res .= "X";
+                       $qlen++;
                } else {
                        $res .= $c;
                }
@@ -295,6 +326,28 @@ sub sanitise_line {
                $l = $c;
        }
 
+       # Clear out the comments.
+       while ($res =~ m@(/\*.*?\*/)@g) {
+               substr($res, $-[1], $+[1] - $-[1]) = $; x ($+[1] - $-[1]);
+       }
+       if ($res =~ m@(/\*.*)@) {
+               substr($res, $-[1], $+[1] - $-[1]) = $; x ($+[1] - $-[1]);
+       }
+       if ($res =~ m@^.(.*\*/)@) {
+               substr($res, $-[1], $+[1] - $-[1]) = $; x ($+[1] - $-[1]);
+       }
+
+       # The pathname on a #include may be surrounded by '<' and '>'.
+       if ($res =~ /^.#\s*include\s+\<(.*)\>/) {
+               my $clean = 'X' x length($1);
+               $res =~ s@\<.*\>@<$clean>@;
+
+       # The whole of a #error is a string.
+       } elsif ($res =~ /^.#\s*(?:error|warning)\s+(.*)\b/) {
+               my $clean = 'X' x length($1);
+               $res =~ s@(#\s*(?:error|warning)\s+).*@$1$clean@;
+       }
+
        return $res;
 }
 
@@ -305,30 +358,36 @@ sub ctx_statement_block {
        my $soff = $off;
        my $coff = $off - 1;
 
+       my $loff = 0;
+
        my $type = '';
        my $level = 0;
        my $c;
        my $len = 0;
+
+       my $remainder;
        while (1) {
                #warn "CSB: blk<$blk>\n";
                # If we are about to drop off the end, pull in more
                # context.
                if ($off >= $len) {
                        for (; $remain > 0; $line++) {
-                               next if ($rawlines[$line] =~ /^-/);
+                               next if ($lines[$line] =~ /^-/);
                                $remain--;
-                               $blk .= sanitise_line($rawlines[$line]) . "\n";
+                               $loff = $len;
+                               $blk .= $lines[$line] . "\n";
                                $len = length($blk);
                                $line++;
                                last;
                        }
                        # Bail if there is no further context.
                        #warn "CSB: blk<$blk> off<$off> len<$len>\n";
-                       if ($off == $len) {
+                       if ($off >= $len) {
                                last;
                        }
                }
                $c = substr($blk, $off, 1);
+               $remainder = substr($blk, $off);
 
                #warn "CSB: c<$c> type<$type> level<$level>\n";
                # Statement ends at the ';' or a close '}' at the
@@ -337,6 +396,12 @@ sub ctx_statement_block {
                        last;
                }
 
+               # An else is really a conditional as long as its not else if
+               if ($level == 0 && $remainder =~ /(\s+else)(?:\s|{)/ &&
+                                       $remainder !~ /\s+else\s+if\b/) {
+                       $coff = $off + length($1);
+               }
+
                if (($type eq '' || $type eq '(') && $c eq '(') {
                        $level++;
                        $type = '(';
@@ -363,6 +428,10 @@ sub ctx_statement_block {
                }
                $off++;
        }
+       if ($off == $len) {
+               $line++;
+               $remain--;
+       }
 
        my $statement = substr($blk, $soff, $off - $soff + 1);
        my $condition = substr($blk, $soff, $coff - $soff + 1);
@@ -370,7 +439,30 @@ sub ctx_statement_block {
        #warn "STATEMENT<$statement>\n";
        #warn "CONDITION<$condition>\n";
 
-       return ($statement, $condition);
+       #print "off<$off> loff<$loff>\n";
+
+       return ($statement, $condition,
+                       $line, $remain + 1, $off - $loff + 1, $level);
+}
+
+sub ctx_statement_full {
+       my ($linenr, $remain, $off) = @_;
+       my ($statement, $condition, $level);
+
+       my (@chunks);
+
+       ($statement, $condition, $linenr, $remain, $off, $level) =
+                               ctx_statement_block($linenr, $remain, $off);
+       #print "F: c<$condition> s<$statement>\n";
+       for (;;) {
+               push(@chunks, [ $condition, $statement ]);
+               last if (!($remain > 0 && $condition =~ /^.\s*(?:if|else|do)/));
+               ($statement, $condition, $linenr, $remain, $off, $level) =
+                               ctx_statement_block($linenr, $remain, $off);
+               #print "C: c<$condition> s<$statement>\n";
+       }
+
+       return ($level, $linenr, @chunks);
 }
 
 sub ctx_block_get {
@@ -500,103 +592,110 @@ sub cat_vet {
        return $res;
 }
 
+my $av_preprocessor = 0;
+my $av_paren = 0;
+my @av_paren_type;
+
+sub annotate_reset {
+       $av_preprocessor = 0;
+       $av_paren = 0;
+       @av_paren_type = ();
+}
+
 sub annotate_values {
        my ($stream, $type) = @_;
 
        my $res;
        my $cur = $stream;
 
-       my $debug = 0;
-
-       print "$stream\n" if ($debug);
-
-       ##my $type = 'N';
-       my $pos = 0;
-       my $preprocessor = 0;
-       my $paren = 0;
-       my @paren_type;
+       print "$stream\n" if ($dbg_values > 1);
 
        while (length($cur)) {
-               print " <$type> " if ($debug);
+               print " <$type> " if ($dbg_values > 1);
                if ($cur =~ /^(\s+)/o) {
-                       print "WS($1)\n" if ($debug);
-                       if ($1 =~ /\n/ && $preprocessor) {
-                               $preprocessor = 0;
+                       print "WS($1)\n" if ($dbg_values > 1);
+                       if ($1 =~ /\n/ && $av_preprocessor) {
+                               $av_preprocessor = 0;
                                $type = 'N';
                        }
 
                } elsif ($cur =~ /^($Type)/) {
-                       print "DECLARE($1)\n" if ($debug);
+                       print "DECLARE($1)\n" if ($dbg_values > 1);
                        $type = 'T';
 
                } elsif ($cur =~ /^(#\s*define\s*$Ident)(\(?)/o) {
-                       print "DEFINE($1)\n" if ($debug);
-                       $preprocessor = 1;
-                       $paren_type[$paren] = 'N';
+                       print "DEFINE($1)\n" if ($dbg_values > 1);
+                       $av_preprocessor = 1;
+                       $av_paren_type[$av_paren] = 'N';
 
-               } elsif ($cur =~ /^(#\s*(?:ifdef|ifndef|if|else|endif))/o) {
-                       print "PRE($1)\n" if ($debug);
-                       $preprocessor = 1;
+               } elsif ($cur =~ /^(#\s*(?:ifdef|ifndef|if|else|elif|endif))/o) {
+                       print "PRE($1)\n" if ($dbg_values > 1);
+                       $av_preprocessor = 1;
                        $type = 'N';
 
                } elsif ($cur =~ /^(\\\n)/o) {
-                       print "PRECONT($1)\n" if ($debug);
+                       print "PRECONT($1)\n" if ($dbg_values > 1);
 
                } elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
-                       print "SIZEOF($1)\n" if ($debug);
+                       print "SIZEOF($1)\n" if ($dbg_values > 1);
                        if (defined $2) {
-                               $paren_type[$paren] = 'V';
+                               $av_paren_type[$av_paren] = 'V';
                        }
                        $type = 'N';
 
-               } elsif ($cur =~ /^(if|while|typeof|for)\b/o) {
-                       print "COND($1)\n" if ($debug);
-                       $paren_type[$paren] = 'N';
+               } elsif ($cur =~ /^(if|while|typeof|__typeof__|for)\b/o) {
+                       print "COND($1)\n" if ($dbg_values > 1);
+                       $av_paren_type[$av_paren] = 'N';
                        $type = 'N';
 
                } elsif ($cur =~/^(return|case|else)/o) {
-                       print "KEYWORD($1)\n" if ($debug);
+                       print "KEYWORD($1)\n" if ($dbg_values > 1);
                        $type = 'N';
 
                } elsif ($cur =~ /^(\()/o) {
-                       print "PAREN('$1')\n" if ($debug);
-                       $paren++;
+                       print "PAREN('$1')\n" if ($dbg_values > 1);
+                       $av_paren++;
                        $type = 'N';
 
                } elsif ($cur =~ /^(\))/o) {
-                       $paren-- if ($paren > 0);
-                       if (defined $paren_type[$paren]) {
-                               $type = $paren_type[$paren];
-                               undef $paren_type[$paren];
-                               print "PAREN('$1') -> $type\n" if ($debug);
+                       $av_paren-- if ($av_paren > 0);
+                       if (defined $av_paren_type[$av_paren]) {
+                               $type = $av_paren_type[$av_paren];
+                               undef $av_paren_type[$av_paren];
+                               print "PAREN('$1') -> $type\n"
+                                                       if ($dbg_values > 1);
                        } else {
-                               print "PAREN('$1')\n" if ($debug);
+                               print "PAREN('$1')\n" if ($dbg_values > 1);
                        }
 
                } elsif ($cur =~ /^($Ident)\(/o) {
-                       print "FUNC($1)\n" if ($debug);
-                       $paren_type[$paren] = 'V';
+                       print "FUNC($1)\n" if ($dbg_values > 1);
+                       $av_paren_type[$av_paren] = 'V';
 
                } elsif ($cur =~ /^($Ident|$Constant)/o) {
-                       print "IDENT($1)\n" if ($debug);
+                       print "IDENT($1)\n" if ($dbg_values > 1);
                        $type = 'V';
 
                } elsif ($cur =~ /^($Assignment)/o) {
-                       print "ASSIGN($1)\n" if ($debug);
+                       print "ASSIGN($1)\n" if ($dbg_values > 1);
                        $type = 'N';
 
+               } elsif ($cur =~/^(;)/) {
+                       print "END($1)\n" if ($dbg_values > 1);
+                       $type = 'E';
+
                } elsif ($cur =~ /^(;|{|}|\?|:|\[)/o) {
-                       print "END($1)\n" if ($debug);
+                       print "CLOSE($1)\n" if ($dbg_values > 1);
                        $type = 'N';
 
                } elsif ($cur =~ /^($Operators)/o) {
-                       print "OP($1)\n" if ($debug);
+                       print "OP($1)\n" if ($dbg_values > 1);
                        if ($1 ne '++' && $1 ne '--') {
                                $type = 'N';
                        }
 
                } elsif ($cur =~ /(^.)/o) {
-                       print "C($1)\n" if ($debug);
+                       print "C($1)\n" if ($dbg_values > 1);
                }
                if (defined $1) {
                        $cur = substr($cur, length($1));
@@ -608,7 +707,7 @@ sub annotate_values {
 }
 
 sub possible {
-       my ($possible) = @_;
+       my ($possible, $line) = @_;
 
        #print "CHECK<$possible>\n";
        if ($possible !~ /^(?:$Storage|$Type|DEFINE_\S+)$/ &&
@@ -616,7 +715,7 @@ sub possible {
            $possible ne 'struct' && $possible ne 'enum' &&
            $possible ne 'case' && $possible ne 'else' &&
            $possible ne 'typedef') {
-               #print "POSSIBLE<$possible>\n";
+               warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible);
                push(@typeList, $possible);
                build_types();
        }
@@ -624,16 +723,15 @@ sub possible {
 
 my $prefix = '';
 
-my @report = ();
 sub report {
        my $line = $prefix . $_[0];
 
        $line = (split('\n', $line))[0] . "\n" if ($terse);
 
-       push(@report, $line);
+       push(our @report, $line);
 }
 sub report_dump {
-       @report;
+       our @report;
 }
 sub ERROR {
        report("ERROR: $_[0]\n");
@@ -655,11 +753,12 @@ sub CHK {
 
 sub process {
        my $filename = shift;
-       my @lines = @_;
 
        my $linenr=0;
        my $prevline="";
+       my $prevrawline="";
        my $stashline="";
+       my $stashrawline="";
 
        my $length;
        my $indent;
@@ -670,6 +769,7 @@ sub process {
        my $signoff = 0;
        my $is_patch = 0;
 
+       our @report = ();
        our $cnt_lines = 0;
        our $cnt_error = 0;
        our $cnt_warn = 0;
@@ -681,14 +781,29 @@ sub process {
        my $realcnt = 0;
        my $here = '';
        my $in_comment = 0;
+       my $comment_edge = 0;
        my $first_line = 0;
 
-       my $prev_values = 'N';
+       my $prev_values = 'E';
+
+       # suppression flags
+       my $suppress_ifbraces = 0;
 
+       # Pre-scan the patch sanitizing the lines.
        # Pre-scan the patch looking for any __setup documentation.
+       #
        my @setup_docs = ();
        my $setup_docs = 0;
-       foreach my $line (@lines) {
+       my $line;
+       foreach my $rawline (@rawlines) {
+               # Standardise the strings and chars within the input to
+               # simplify matching.
+               $line = sanitise_line($rawline);
+               push(@lines, $line);
+
+               ##print "==>$rawline\n";
+               ##print "-->$line\n";
+
                if ($line=~/^\+\+\+\s+(\S+)/) {
                        $setup_docs = 0;
                        if ($1 =~ m@Documentation/kernel-parameters.txt$@) {
@@ -707,8 +822,7 @@ sub process {
        foreach my $line (@lines) {
                $linenr++;
 
-               my $rawline = $line;
-
+               my $rawline = $rawlines[$linenr - 1];
 
 #extract the filename as it passes
                if ($line=~/^\+\+\+\s+(\S+)/) {
@@ -728,7 +842,10 @@ sub process {
                        } else {
                                $realcnt=1+1;
                        }
-                       $prev_values = 'N';
+                       annotate_reset();
+                       $prev_values = 'E';
+
+                       $suppress_ifbraces = $linenr - 1;
                        next;
                }
 
@@ -746,7 +863,7 @@ sub process {
                        if ($linenr == $first_line) {
                                my $edge;
                                for (my $ln = $first_line; $ln < ($linenr + $realcnt); $ln++) {
-                                       ($edge) = ($lines[$ln - 1] =~ m@(/\*|\*/)@);
+                                       ($edge) = ($rawlines[$ln - 1] =~ m@(/\*|\*/)@);
                                        last if (defined $edge);
                                }
                                if (defined $edge && $edge eq '*/') {
@@ -757,25 +874,30 @@ sub process {
                        # Guestimate if this is a continuing comment.  If this
                        # is the start of a diff block and this line starts
                        # ' *' then it is very likely a comment.
-                       if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
+                       if ($linenr == $first_line and $rawline =~ m@^.\s* \*(?:\s|$)@) {
                                $in_comment = 1;
                        }
 
                        # Find the last comment edge on _this_ line.
-                       while (($line =~ m@(/\*|\*/)@g)) {
+                       $comment_edge = 0;
+                       while (($rawline =~ m@(/\*|\*/)@g)) {
                                if ($1 eq '/*') {
                                        $in_comment = 1;
                                } else {
                                        $in_comment = 0;
                                }
+                               $comment_edge = 1;
                        }
 
                        # Measure the line length and indent.
-                       ($length, $indent) = line_stats($line);
+                       ($length, $indent) = line_stats($rawline);
 
                        # Track the previous line.
                        ($prevline, $stashline) = ($stashline, $line);
                        ($previndent, $stashindent) = ($stashindent, $indent);
+                       ($prevrawline, $stashrawline) = ($stashrawline, $rawline);
+
+                       #warn "ic<$in_comment> ce<$comment_edge> line<$line>\n";
 
                } elsif ($realcnt == 1) {
                        $realcnt--;
@@ -786,9 +908,9 @@ sub process {
                $here = "#$realline: " if ($file);
                $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
 
-               my $hereline = "$here\n$line\n";
-               my $herecurr = "$here\n$line\n";
-               my $hereprev = "$here\n$prevline\n$line\n";
+               my $hereline = "$here\n$rawline\n";
+               my $herecurr = "$here\n$rawline\n";
+               my $hereprev = "$here\n$prevrawline\n$rawline\n";
 
                $prefix = "$filename:$realline: " if ($emacs && $file);
                $prefix = "$filename:$linenr: " if ($emacs && !$file);
@@ -816,7 +938,7 @@ sub process {
 
 # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
                if (($realfile =~ /^$/ || $line =~ /^\+/) &&
-                    !($line =~ m/^(
+                    !($rawline =~ m/^(
                                [\x09\x0A\x0D\x20-\x7E]              # ASCII
                                | [\xC2-\xDF][\x80-\xBF]             # non-overlong 2-byte
                                |  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
@@ -826,7 +948,7 @@ sub process {
                                | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
                                |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
                                )*$/x )) {
-                       ERROR("Invalid UTF-8\n" . $herecurr);
+                       ERROR("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $herecurr);
                }
 
 #ignore lines being removed
@@ -837,15 +959,15 @@ sub process {
 
 #trailing whitespace
                if ($line =~ /^\+.*\015/) {
-                       my $herevet = "$here\n" . cat_vet($line) . "\n";
+                       my $herevet = "$here\n" . cat_vet($rawline) . "\n";
                        ERROR("DOS line endings\n" . $herevet);
 
-               } elsif ($line =~ /^\+.*\S\s+$/ || $line =~ /^\+\s+$/) {
-                       my $herevet = "$here\n" . cat_vet($line) . "\n";
+               } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
+                       my $herevet = "$here\n" . cat_vet($rawline) . "\n";
                        ERROR("trailing whitespace\n" . $herevet);
                }
 #80 column limit
-               if ($line =~ /^\+/ && !($prevline=~/\/\*\*/) && $length > 80) {
+               if ($line =~ /^\+/ && !($prevrawline=~/\/\*\*/) && $length > 80) {
                        WARN("line over 80 characters\n" . $herecurr);
                }
 
@@ -859,46 +981,48 @@ sub process {
 
 # at the beginning of a line any tabs must come first and anything
 # more than 8 must use tabs.
-               if ($line=~/^\+\s* \t\s*\S/ or $line=~/^\+\s*        \s*/) {
-                       my $herevet = "$here\n" . cat_vet($line) . "\n";
+               if ($rawline =~ /^\+\s* \t\s*\S/ ||
+                   $rawline =~ /^\+\s*        \s*/) {
+                       my $herevet = "$here\n" . cat_vet($rawline) . "\n";
                        ERROR("use tabs not spaces\n" . $herevet);
                }
 
-# Remove comments from the line before processing.
-               my $comment_edge = ($line =~ s@/\*.*\*/@@g) +
-                                  ($line =~ s@/\*.*@@) +
-                                  ($line =~ s@^(.).*\*/@$1@);
+# check for RCS/CVS revision markers
+               if ($rawline =~ /\$(Revision|Log|Id)(?:\$|)/) {
+                       WARN("CVS style keyword markers, these will _not_ be updated\n". $herecurr);
+               }
 
 # The rest of our checks refer specifically to C style
 # only apply those _outside_ comments.  Only skip
 # lines in the middle of comments.
                next if (!$comment_edge && $in_comment);
 
-# Standardise the strings and chars within the input to simplify matching.
-               $line = sanitise_line($line);
-
 # Check for potential 'bare' types
-               if ($realcnt &&
-                   $line !~ /$Ident:\s*$/ &&
-                   ($line =~ /^.\s*$Ident\s*\(\*+\s*$Ident\)\s*\(/ ||
-                    $line !~ /^.\s*$Ident\s*\(/)) {
+               if ($realcnt) {
+                       # Ignore goto labels.
+                       if ($line =~ /$Ident:\*$/) {
+
+                       # Ignore functions being called
+                       } elsif ($line =~ /^.\s*$Ident\s*\(/) {
+
                        # definitions in global scope can only start with types
-                       if ($line =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b/) {
-                               possible($1);
+                       } elsif ($line =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b/) {
+                               possible($1, $line);
 
                        # declarations always start with types
-                       } elsif ($prev_values eq 'N' && $line =~ /^.\s*(?:$Storage\s+)?($Ident)\b\s*\**\s*$Ident\s*(?:;|=)/) {
+                       } elsif ($prev_values eq 'E' && $line =~ /^.\s*(?:$Storage\s+)?(?:const\s+)?($Ident)\b(:?\s+$Sparse)?\s*\**\s*$Ident\s*(?:;|=|,)/) {
                                possible($1);
+                       }
 
                        # any (foo ... *) is a pointer cast, and foo is a type
-                       } elsif ($line =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/) {
-                               possible($1);
+                       while ($line =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/g) {
+                               possible($1, $line);
                        }
 
                        # Check for any sort of function declaration.
                        # int foo(something bar, other baz);
                        # void (*store_gdt)(x86_descr_ptr *);
-                       if ($prev_values eq 'N' && $line =~ /^(.(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/) {
+                       if ($prev_values eq 'E' && $line =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/) {
                                my ($name_len) = length($1);
                                my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, $name_len);
                                my $ctx = join("\n", @ctx);
@@ -909,7 +1033,7 @@ sub process {
                                for my $arg (split(/\s*,\s*/, $ctx)) {
                                        if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/ || $arg =~ /^($Ident)$/) {
 
-                                               possible($1);
+                                               possible($1, $line);
                                        }
                                }
                        }
@@ -974,8 +1098,11 @@ sub process {
                my $opline = $line; $opline =~ s/^./ /;
                my $curr_values = annotate_values($opline . "\n", $prev_values);
                $curr_values = $prev_values . $curr_values;
-               #warn "--> $opline\n";
-               #warn "--> $curr_values ($prev_values)\n";
+               if ($dbg_values) {
+                       my $outline = $opline; $outline =~ s/\t/ /g;
+                       warn "--> .$outline\n";
+                       warn "--> $curr_values\n";
+               }
                $prev_values = substr($curr_values, -1);
 
 #ignore lines not being added
@@ -1004,9 +1131,6 @@ sub process {
                                ERROR("malformed #include filename\n" .
                                        $herecurr);
                        }
-                       # Sanitise this special form of string.
-                       $path = 'X' x length($path);
-                       $line =~ s{\<.*\>}{<$path>};
                }
 
 # no C99 // comments
@@ -1074,7 +1198,7 @@ sub process {
 #              }
 
                if ($line =~ /\bLINUX_VERSION_CODE\b/) {
-                       WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged" . $herecurr);
+                       WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
                }
 
 # printk should use KERN_* levels.  Note that follow on printk's on the
@@ -1102,7 +1226,7 @@ sub process {
 
 # function brace can't be on same line, except for #defines of do while,
 # or if closed on same line
-               if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).* {/) and
+               if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).*\s{/) and
                    !($line=~/\#define.*do\s{/) and !($line=~/}/)) {
                        ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr);
                }
@@ -1115,8 +1239,22 @@ sub process {
 
 # check for spaces between functions and their parentheses.
                while ($line =~ /($Ident)\s+\(/g) {
-                       if ($1 !~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright|case)$/ &&
-                           $line !~ /$Type\s+\(/ && $line !~ /^.\#\s*define\b/) {
+                       my $name = $1;
+                       my $ctx = substr($line, 0, $-[1]);
+
+                       # Ignore those directives where spaces _are_ permitted.
+                       if ($name =~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright|case|__asm__)$/) {
+
+                       # cpp #define statements have non-optional spaces, ie
+                       # if there is a space between the name and the open
+                       # parenthesis it is simply not a parameter group.
+                       } elsif ($ctx =~ /^.\#\s*define\s*$/) {
+
+                       # If this whole things ends with a type its most
+                       # likely a typedef for a function.
+                       } elsif ("$ctx$name" =~ /$Type$/) {
+
+                       } else {
                                WARN("no space between function name and open parenthesis '('\n" . $herecurr);
                        }
                }
@@ -1126,9 +1264,9 @@ sub process {
                                <<=|>>=|<=|>=|==|!=|
                                \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
                                =>|->|<<|>>|<|>|=|!|~|
-                               &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/
+                               &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%
                        }x;
-                       my @elements = split(/($ops|;)/, $opline);
+                       my @elements = split(/($;+|$ops|;)/, $opline);
                        my $off = 0;
 
                        my $blank = copy_spacing($opline);
@@ -1188,8 +1326,15 @@ sub process {
                                #       print "UNARY: <$op_left$op_type $is_unary $a:$op:$c> <$ca:$op:$cc> <$unary_ctx>\n";
                                #}
 
+                               # Ignore operators passed as parameters.
+                               if ($op_type ne 'V' &&
+                                   $ca =~ /\s$/ && $cc =~ /^\s*,/) {
+
+                               # Ignore comments
+                               } elsif ($op =~ /^$;+$/) {
+
                                # ; should have either the end of line or a space or \ after it
-                               if ($op eq ';') {
+                               } elsif ($op eq ';') {
                                        if ($ctx !~ /.x[WEB]/ && $cc !~ /^\\/ &&
                                            $cc !~ /^;/) {
                                                ERROR("need space after that '$op' $at\n" . $hereptr);
@@ -1231,7 +1376,7 @@ sub process {
                                        if ($ctx !~ /[WOB]x[^W]/ && $ctx !~ /[^W]x[WOBE]/) {
                                                ERROR("need space one side of that '$op' $at\n" . $hereptr);
                                        }
-                                       if ($ctx =~ /Wx./ && $cc =~ /^;/) {
+                                       if ($ctx =~ /WxB/ || ($ctx =~ /Wx./ && $cc =~ /^;/)) {
                                                ERROR("no space before that '$op' $at\n" . $hereptr);
                                        }
 
@@ -1239,7 +1384,8 @@ sub process {
                                } elsif ($op eq '<<' or $op eq '>>' or
                                         $op eq '&' or $op eq '^' or $op eq '|' or
                                         $op eq '+' or $op eq '-' or
-                                        $op eq '*' or $op eq '/')
+                                        $op eq '*' or $op eq '/' or
+                                        $op eq '%')
                                {
                                        if ($ctx !~ /VxV|WxW|VxE|WxE|VxO/) {
                                                ERROR("need consistent spacing around '$op' $at\n" .
@@ -1303,7 +1449,7 @@ sub process {
                    $line !~ /for\s*\(\s+;/) {
                        ERROR("no space after that open parenthesis '('\n" . $herecurr);
                }
-               if ($line =~ /\s\)/ && $line !~ /^.\s*\)/ &&
+               if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
                    $line !~ /for\s*\(.*;\s+\)/) {
                        ERROR("no space before that close parenthesis ')'\n" . $herecurr);
                }
@@ -1324,23 +1470,41 @@ sub process {
                        my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
 
                        if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/) {
-                               ERROR("do not use assignment in if condition ($c)\n" . $herecurr);
+                               ERROR("do not use assignment in if condition\n" . $herecurr);
                        }
 
                        # Find out what is on the end of the line after the
                        # conditional.
                        substr($s, 0, length($c)) = '';
                        $s =~ s/\n.*//g;
-
-                       if (length($c) && $s !~ /^\s*({|;|\/\*.*\*\/)?\s*\\*\s*$/) {
+                       $s =~ s/$;//g;  # Remove any comments
+                       if (length($c) && $s !~ /^\s*({|;|)\s*\\*\s*$/) {
                                ERROR("trailing statements should be on next line\n" . $herecurr);
                        }
                }
 
+# Check for bitwise tests written as boolean
+               if ($line =~ /
+                       (?:
+                               (?:\[|\(|\&\&|\|\|)
+                               \s*0[xX][0-9]+\s*
+                               (?:\&\&|\|\|)
+                       |
+                               (?:\&\&|\|\|)
+                               \s*0[xX][0-9]+\s*
+                               (?:\&\&|\|\||\)|\])
+                       )/x)
+               {
+                       WARN("boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
+               }
+
 # if and else should not have general statements after it
-               if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/ &&
-                   $1 !~ /^\s*(?:\sif|{|\\|$)/) {
-                       ERROR("trailing statements should be on next line\n" . $herecurr);
+               if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
+                       my $s = $1;
+                       $s =~ s/$;//g;  # Remove any comments
+                       if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
+                               ERROR("trailing statements should be on next line\n" . $herecurr);
+                       }
                }
 
                # Check for }<nl>else {, these must be at the same
@@ -1350,6 +1514,20 @@ sub process {
                        ERROR("else should follow close brace '}'\n" . $hereprev);
                }
 
+               if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and
+                                               $previndent == $indent) {
+                       my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
+
+                       # Find out what is on the end of the line after the
+                       # conditional.
+                       substr($s, 0, length($c)) = '';
+                       $s =~ s/\n.*//g;
+
+                       if ($s =~ /^\s*;/) {
+                               ERROR("while should follow close brace '}'\n" . $hereprev);
+                       }
+               }
+
 #studly caps, commented out until figure out how to distinguish between use of existing and adding new
 #              if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) {
 #                  print "No studly caps, use _\n";
@@ -1419,7 +1597,48 @@ sub process {
                }
 
 # check for redundant bracing round if etc
-               if ($line =~ /\b(if|while|for|else)\b/) {
+               if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
+                       my ($level, $endln, @chunks) =
+                               ctx_statement_full($linenr, $realcnt, 0);
+                       #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
+                       if ($#chunks > 1 && $level == 0) {
+                               my $allowed = 0;
+                               my $seen = 0;
+                               for my $chunk (@chunks) {
+                                       my ($cond, $block) = @{$chunk};
+
+                                       substr($block, 0, length($cond)) = '';
+
+                                       $seen++ if ($block =~ /^\s*{/);
+
+                                       $block =~ s/(^|\n)./$1/g;
+                                       $block =~ s/^\s*{//;
+                                       $block =~ s/}\s*$//;
+                                       $block =~ s/^\s*//;
+                                       $block =~ s/\s*$//;
+
+                                       my @lines = ($block =~ /\n/g);
+                                       my @statements = ($block =~ /;/g);
+
+                                       #print "cond<$cond> block<$block> lines<" . scalar(@lines) . "> statements<" . scalar(@statements) . "> seen<$seen> allowed<$allowed>\n";
+                                       if (scalar(@lines) != 0) {
+                                               $allowed = 1;
+                                       }
+                                       if ($block =~/\b(?:if|for|while)\b/) {
+                                               $allowed = 1;
+                                       }
+                                       if (scalar(@statements) > 1) {
+                                               $allowed = 1;
+                                       }
+                               }
+                               if ($seen && !$allowed) {
+                                       WARN("braces {} are not necessary for any arm of this statement\n" . $herecurr);
+                                       $suppress_ifbraces = $endln;
+                               }
+                       }
+               }
+               if ($linenr > $suppress_ifbraces &&
+                                       $line =~ /\b(if|while|for|else)\b/) {
                        # Locate the end of the opening statement.
                        my @control = ctx_statement($linenr, $realcnt, 0);
                        my $nr = $linenr + (scalar(@control) - 1);
@@ -1442,13 +1661,16 @@ sub process {
                                my $after = $1;
 
                                #print "block<" . join(' ', @block) . "><" . scalar(@block) . ">\n";
-                               #print "stmt<$stmt>\n\n";
+                               #print "before<$before> stmt<$stmt> after<$after>\n\n";
 
                                # Count the newlines, if there is only one
                                # then the block should not have {}'s.
                                my @lines = ($stmt =~ /\n/g);
+                               my @statements = ($stmt =~ /;/g);
                                #print "lines<" . scalar(@lines) . ">\n";
+                               #print "statements<" . scalar(@statements) . ">\n";
                                if ($lvl == 0 && scalar(@lines) == 0 &&
+                                   scalar(@statements) < 2 &&
                                    $stmt !~ /{/ && $stmt !~ /\bif\b/ &&
                                    $before !~ /}/ && $after !~ /{/) {
                                        my $herectx = "$here\n" . join("\n", @control, @block[1 .. $#block]) . "\n";
@@ -1557,6 +1779,17 @@ sub process {
                if ($line =~ /\*\s*\)\s*k[czm]alloc\b/) {
                        WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
                }
+
+# check for gcc specific __FUNCTION__
+               if ($line =~ /__FUNCTION__/) {
+                       WARN("__func__ should be used instead of gcc specific __FUNCTION__\n"  . $herecurr);
+               }
+       }
+
+       # If we have no input at all, then there is nothing to report on
+       # so just keep quiet.
+       if ($#rawlines == -1) {
+               exit(0);
        }
 
        # In mailback mode only produce a report in the negative, for
@@ -1579,7 +1812,8 @@ sub process {
        }
 
        print report_dump();
-       if ($summary) {
+       if ($summary && !($clean == 1 && $quiet == 1)) {
+               print "$filename " if ($summary_file);
                print "total: $cnt_error errors, $cnt_warn warnings, " .
                        (($check)? "$cnt_chk checks, " : "") .
                        "$cnt_lines lines checked\n";
@@ -1587,12 +1821,22 @@ sub process {
        }
 
        if ($clean == 1 && $quiet == 0) {
-               print "Your patch has no obvious style problems and is ready for submission.\n"
+               print "$vname has no obvious style problems and is ready for submission.\n"
        }
        if ($clean == 0 && $quiet == 0) {
-               print "Your patch has style problems, please review.  If any of these errors\n";
+               print "$vname has style problems, please review.  If any of these errors\n";
                print "are false positives report them to the maintainer, see\n";
                print "CHECKPATCH in MAINTAINERS.\n";
        }
+       print <<EOL if ($file == 1 && $quiet == 0);
+
+WARNING: Using --file mode. Please do not send patches to linux-kernel
+that change whole existing files if you did not significantly change most
+of the the file for other reasons anyways or just wrote the file newly
+from scratch. Pure code style patches have a significant cost in a
+quickly changing code base like Linux because they cause rejects
+with other changes.
+EOL
+
        return $clean;
 }
index a8057f25955319d089badd9515553b62497f82a1..044453a4ee5b71fa0f09eb964278375c0f464e6d 100644 (file)
@@ -1580,7 +1580,7 @@ static int cs4297a_ioctl_mixdev(struct inode *inode, struct file *file,
 // ******************************************************************************************
 //   Mixer file operations struct.
 // ******************************************************************************************
-static /*const */ struct file_operations cs4297a_mixer_fops = {
+static const struct file_operations cs4297a_mixer_fops = {
        .owner          = THIS_MODULE,
        .llseek         = no_llseek,
        .ioctl          = cs4297a_ioctl_mixdev,
@@ -2491,7 +2491,7 @@ static int cs4297a_open(struct inode *inode, struct file *file)
 // ******************************************************************************************
 //   Wave (audio) file operations struct.
 // ******************************************************************************************
-static /*const */ struct file_operations cs4297a_audio_fops = {
+static const struct file_operations cs4297a_audio_fops = {
        .owner          = THIS_MODULE,
        .llseek         = no_llseek,
        .read           = cs4297a_read,
index 6959ee1bd17f46cf41965fb295361c410370fd13..d6af9065d1c0287b7e40452b21c9b63153194b43 100644 (file)
@@ -2878,7 +2878,7 @@ trident_release(struct inode *inode, struct file *file)
        return 0;
 }
 
-static /*const */ struct file_operations trident_audio_fops = {
+static const struct file_operations trident_audio_fops = {
        .owner = THIS_MODULE,
        .llseek = no_llseek,
        .read = trident_read,
@@ -4104,7 +4104,7 @@ trident_ioctl_mixdev(struct inode *inode, struct file *file, unsigned int cmd,
        return codec->mixer_ioctl(codec, cmd, arg);
 }
 
-static /*const */ struct file_operations trident_mixer_fops = {
+static const struct file_operations trident_mixer_fops = {
        .owner = THIS_MODULE,
        .llseek = no_llseek,
        .ioctl = trident_ioctl_mixdev,
index 3c4fe26096fcd3917db20d8a9ecfa6188496f420..32fbf800696901866b760cef48b880a151c58399 100644 (file)
@@ -1186,38 +1186,38 @@ static struct notifier_block kvm_cpu_notifier = {
        .priority = 20, /* must be > scheduler priority */
 };
 
-static u64 vm_stat_get(void *_offset)
+static int vm_stat_get(void *_offset, u64 *val)
 {
        unsigned offset = (long)_offset;
-       u64 total = 0;
        struct kvm *kvm;
 
+       *val = 0;
        spin_lock(&kvm_lock);
        list_for_each_entry(kvm, &vm_list, vm_list)
-               total += *(u32 *)((void *)kvm + offset);
+               *val += *(u32 *)((void *)kvm + offset);
        spin_unlock(&kvm_lock);
-       return total;
+       return 0;
 }
 
 DEFINE_SIMPLE_ATTRIBUTE(vm_stat_fops, vm_stat_get, NULL, "%llu\n");
 
-static u64 vcpu_stat_get(void *_offset)
+static int vcpu_stat_get(void *_offset, u64 *val)
 {
        unsigned offset = (long)_offset;
-       u64 total = 0;
        struct kvm *kvm;
        struct kvm_vcpu *vcpu;
        int i;
 
+       *val = 0;
        spin_lock(&kvm_lock);
        list_for_each_entry(kvm, &vm_list, vm_list)
                for (i = 0; i < KVM_MAX_VCPUS; ++i) {
                        vcpu = kvm->vcpus[i];
                        if (vcpu)
-                               total += *(u32 *)((void *)vcpu + offset);
+                               *val += *(u32 *)((void *)vcpu + offset);
                }
        spin_unlock(&kvm_lock);
-       return total;
+       return 0;
 }
 
 DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_fops, vcpu_stat_get, NULL, "%llu\n");