aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/testing/sysfs-block59
-rw-r--r--Documentation/ABI/testing/sysfs-bus-pci-devices-cciss33
-rw-r--r--Documentation/Smack.txt20
-rw-r--r--Documentation/block/biodoc.txt2
-rw-r--r--Documentation/filesystems/gfs2-glocks.txt2
-rw-r--r--Documentation/filesystems/gfs2.txt19
-rw-r--r--Documentation/kernel-parameters.txt6
-rw-r--r--Documentation/sysctl/kernel.txt11
-rw-r--r--MAINTAINERS16
-rw-r--r--arch/arm/plat-mxc/include/mach/imx-uart.h5
-rw-r--r--arch/arm/plat-omap/mailbox.c63
-rw-r--r--arch/frv/Kconfig1
-rw-r--r--arch/frv/include/asm/bitops.h29
-rw-r--r--arch/frv/include/asm/elf.h1
-rw-r--r--arch/frv/include/asm/pci.h7
-rw-r--r--arch/frv/include/asm/ptrace.h11
-rw-r--r--arch/frv/include/asm/syscall.h123
-rw-r--r--arch/frv/include/asm/thread_info.h10
-rw-r--r--arch/frv/kernel/entry.S13
-rw-r--r--arch/frv/kernel/ptrace.c755
-rw-r--r--arch/frv/kernel/signal.c10
-rw-r--r--arch/frv/kernel/uaccess.c6
-rw-r--r--arch/frv/mb93090-mb00/pci-dma-nommu.c6
-rw-r--r--arch/frv/mb93090-mb00/pci-dma.c6
-rw-r--r--arch/ia64/include/asm/kvm_host.h6
-rw-r--r--arch/ia64/include/asm/pgtable.h2
-rw-r--r--arch/ia64/kernel/irq_ia64.c3
-rw-r--r--arch/ia64/kvm/Kconfig2
-rw-r--r--arch/ia64/kvm/kvm-ia64.c263
-rw-r--r--arch/ia64/kvm/kvm_fw.c28
-rw-r--r--arch/ia64/kvm/lapic.h6
-rw-r--r--arch/ia64/kvm/optvfault.S30
-rw-r--r--arch/ia64/kvm/process.c5
-rw-r--r--arch/ia64/kvm/vcpu.c20
-rw-r--r--arch/ia64/kvm/vmm.c12
-rw-r--r--arch/ia64/kvm/vmm_ivt.S18
-rw-r--r--arch/ia64/kvm/vtlb.c3
-rw-r--r--arch/mn10300/Kconfig1
-rw-r--r--arch/mn10300/include/asm/elf.h3
-rw-r--r--arch/mn10300/include/asm/processor.h8
-rw-r--r--arch/mn10300/include/asm/ptrace.h8
-rw-r--r--arch/mn10300/kernel/entry.S13
-rw-r--r--arch/mn10300/kernel/ptrace.c454
-rw-r--r--arch/mn10300/kernel/signal.c9
-rw-r--r--arch/mn10300/mm/tlb-mn10300.S18
-rw-r--r--arch/powerpc/kvm/powerpc.c6
-rw-r--r--arch/powerpc/sysdev/axonram.c2
-rw-r--r--arch/s390/include/asm/kvm_host.h5
-rw-r--r--arch/s390/kvm/intercept.c28
-rw-r--r--arch/s390/kvm/interrupt.c59
-rw-r--r--arch/s390/kvm/kvm-s390.c63
-rw-r--r--arch/s390/kvm/kvm-s390.h4
-rw-r--r--arch/s390/kvm/priv.c4
-rw-r--r--arch/s390/kvm/sigp.c16
-rw-r--r--arch/sh/Kconfig126
-rw-r--r--arch/sh/Kconfig.cpu8
-rw-r--r--arch/sh/Kconfig.debug23
-rw-r--r--arch/sh/Makefile73
-rw-r--r--arch/sh/boards/Kconfig15
-rw-r--r--arch/sh/boards/board-ap325rxa.c12
-rw-r--r--arch/sh/boards/board-sh7785lcr.c44
-rw-r--r--arch/sh/boards/mach-cayman/Makefile2
-rw-r--r--arch/sh/boards/mach-cayman/irq.c17
-rw-r--r--arch/sh/boards/mach-cayman/panic.c49
-rw-r--r--arch/sh/boards/mach-cayman/setup.c2
-rw-r--r--arch/sh/boards/mach-dreamcast/setup.c6
-rw-r--r--arch/sh/boards/mach-migor/setup.c19
-rw-r--r--arch/sh/boards/mach-r2d/setup.c50
-rw-r--r--arch/sh/boards/mach-se/7724/Makefile10
-rw-r--r--arch/sh/boards/mach-se/7724/irq.c139
-rw-r--r--arch/sh/boards/mach-se/7724/setup.c448
-rw-r--r--arch/sh/boards/mach-se/7751/Makefile2
-rw-r--r--arch/sh/boards/mach-se/7751/io.c16
-rw-r--r--arch/sh/boards/mach-se/7751/pci.c147
-rw-r--r--arch/sh/boards/mach-se/7780/irq.c27
-rw-r--r--arch/sh/boards/mach-se/Makefile1
-rw-r--r--arch/sh/boards/mach-sh03/rtc.c10
-rw-r--r--arch/sh/boards/mach-snapgear/io.c16
-rw-r--r--arch/sh/boards/mach-systemh/io.c16
-rw-r--r--arch/sh/boards/mach-titan/io.c20
-rw-r--r--arch/sh/boot/Makefile6
-rw-r--r--arch/sh/boot/compressed/Makefile50
-rw-r--r--arch/sh/boot/compressed/Makefile_3246
-rw-r--r--arch/sh/boot/compressed/Makefile_6443
-rw-r--r--arch/sh/boot/compressed/head_64.S5
-rw-r--r--arch/sh/boot/compressed/vmlinux_64.lds64
-rw-r--r--arch/sh/cchips/Kconfig5
-rw-r--r--arch/sh/cchips/hd6446x/hd64461.c2
-rw-r--r--arch/sh/configs/ap325rxa_defconfig37
-rw-r--r--arch/sh/configs/cayman_defconfig71
-rw-r--r--arch/sh/configs/dreamcast_defconfig39
-rw-r--r--arch/sh/configs/edosk7705_defconfig29
-rw-r--r--arch/sh/configs/edosk7760_defconfig32
-rw-r--r--arch/sh/configs/espt_defconfig39
-rw-r--r--arch/sh/configs/hp6xx_defconfig35
-rw-r--r--arch/sh/configs/landisk_defconfig48
-rw-r--r--arch/sh/configs/lboxre2_defconfig44
-rw-r--r--arch/sh/configs/magicpanelr2_defconfig30
-rw-r--r--arch/sh/configs/microdev_defconfig36
-rw-r--r--arch/sh/configs/migor_defconfig36
-rw-r--r--arch/sh/configs/polaris_defconfig30
-rw-r--r--arch/sh/configs/r7780mp_defconfig38
-rw-r--r--arch/sh/configs/r7785rp_defconfig38
-rw-r--r--arch/sh/configs/rsk7201_defconfig37
-rw-r--r--arch/sh/configs/rsk7203_defconfig40
-rw-r--r--arch/sh/configs/rts7751r2d1_defconfig43
-rw-r--r--arch/sh/configs/rts7751r2dplus_defconfig130
-rw-r--r--arch/sh/configs/sdk7780_defconfig38
-rw-r--r--arch/sh/configs/se7206_defconfig35
-rw-r--r--arch/sh/configs/se7343_defconfig42
-rw-r--r--arch/sh/configs/se7619_defconfig35
-rw-r--r--arch/sh/configs/se7705_defconfig34
-rw-r--r--arch/sh/configs/se7712_defconfig30
-rw-r--r--arch/sh/configs/se7721_defconfig33
-rw-r--r--arch/sh/configs/se7722_defconfig38
-rw-r--r--arch/sh/configs/se7724_defconfig1552
-rw-r--r--arch/sh/configs/se7750_defconfig34
-rw-r--r--arch/sh/configs/se7751_defconfig34
-rw-r--r--arch/sh/configs/se7780_defconfig38
-rw-r--r--arch/sh/configs/sh03_defconfig43
-rw-r--r--arch/sh/configs/sh7710voipgw_defconfig35
-rw-r--r--arch/sh/configs/sh7724_generic_defconfig707
-rw-r--r--arch/sh/configs/sh7763rdp_defconfig35
-rw-r--r--arch/sh/configs/sh7770_generic_defconfig700
-rw-r--r--arch/sh/configs/sh7785lcr_32bit_defconfig37
-rw-r--r--arch/sh/configs/sh7785lcr_defconfig6
-rw-r--r--arch/sh/configs/shmin_defconfig31
-rw-r--r--arch/sh/configs/shx3_defconfig32
-rw-r--r--arch/sh/configs/snapgear_defconfig40
-rw-r--r--arch/sh/configs/systemh_defconfig39
-rw-r--r--arch/sh/configs/titan_defconfig40
-rw-r--r--arch/sh/configs/ul2_defconfig37
-rw-r--r--arch/sh/configs/urquell_defconfig39
-rw-r--r--arch/sh/drivers/dma/Kconfig3
-rw-r--r--arch/sh/drivers/pci/Kconfig18
-rw-r--r--arch/sh/drivers/pci/Makefile28
-rw-r--r--arch/sh/drivers/pci/fixups-cayman.c (renamed from arch/sh/drivers/pci/ops-cayman.c)12
-rw-r--r--arch/sh/drivers/pci/fixups-dreamcast.c9
-rw-r--r--arch/sh/drivers/pci/fixups-landisk.c (renamed from arch/sh/drivers/pci/ops-landisk.c)33
-rw-r--r--arch/sh/drivers/pci/fixups-lboxre2.c41
-rw-r--r--arch/sh/drivers/pci/fixups-r7780rp.c41
-rw-r--r--arch/sh/drivers/pci/fixups-rts7751r2d.c48
-rw-r--r--arch/sh/drivers/pci/fixups-sdk7780.c63
-rw-r--r--arch/sh/drivers/pci/fixups-se7751.c111
-rw-r--r--arch/sh/drivers/pci/fixups-se7780.c60
-rw-r--r--arch/sh/drivers/pci/fixups-sh7785lcr.c46
-rw-r--r--arch/sh/drivers/pci/fixups-snapgear.c38
-rw-r--r--arch/sh/drivers/pci/fixups-titan.c (renamed from arch/sh/drivers/pci/ops-titan.c)39
-rw-r--r--arch/sh/drivers/pci/ops-dreamcast.c107
-rw-r--r--arch/sh/drivers/pci/ops-lboxre2.c63
-rw-r--r--arch/sh/drivers/pci/ops-r7780rp.c68
-rw-r--r--arch/sh/drivers/pci/ops-rts7751r2d.c74
-rw-r--r--arch/sh/drivers/pci/ops-sdk7780.c73
-rw-r--r--arch/sh/drivers/pci/ops-se7780.c96
-rw-r--r--arch/sh/drivers/pci/ops-sh03.c45
-rw-r--r--arch/sh/drivers/pci/ops-sh4.c79
-rw-r--r--arch/sh/drivers/pci/ops-sh5.c25
-rw-r--r--arch/sh/drivers/pci/ops-sh7785lcr.c66
-rw-r--r--arch/sh/drivers/pci/ops-snapgear.c94
-rw-r--r--arch/sh/drivers/pci/pci-auto.c545
-rw-r--r--arch/sh/drivers/pci/pci-dreamcast.c102
-rw-r--r--arch/sh/drivers/pci/pci-sh4.h19
-rw-r--r--arch/sh/drivers/pci/pci-sh5.c55
-rw-r--r--arch/sh/drivers/pci/pci-sh5.h3
-rw-r--r--arch/sh/drivers/pci/pci-sh7751.c215
-rw-r--r--arch/sh/drivers/pci/pci-sh7751.h12
-rw-r--r--arch/sh/drivers/pci/pci-sh7780.c224
-rw-r--r--arch/sh/drivers/pci/pci-sh7780.h16
-rw-r--r--arch/sh/drivers/pci/pci.c279
-rw-r--r--arch/sh/include/asm/atomic-llsc.h27
-rw-r--r--arch/sh/include/asm/atomic.h4
-rw-r--r--arch/sh/include/asm/cacheflush.h2
-rw-r--r--arch/sh/include/asm/clock.h113
-rw-r--r--arch/sh/include/asm/cmpxchg-llsc.h2
-rw-r--r--arch/sh/include/asm/device.h2
-rw-r--r--arch/sh/include/asm/hd64461.h148
-rw-r--r--arch/sh/include/asm/io.h22
-rw-r--r--arch/sh/include/asm/irq.h3
-rw-r--r--arch/sh/include/asm/kprobes.h2
-rw-r--r--arch/sh/include/asm/machvec.h3
-rw-r--r--arch/sh/include/asm/pci.h118
-rw-r--r--arch/sh/include/asm/pgtable.h4
-rw-r--r--arch/sh/include/asm/processor.h23
-rw-r--r--arch/sh/include/asm/ptrace.h5
-rw-r--r--arch/sh/include/asm/rtc.h11
-rw-r--r--arch/sh/include/asm/spinlock.h2
-rw-r--r--arch/sh/include/asm/swab.h12
-rw-r--r--arch/sh/include/asm/system_32.h2
-rw-r--r--arch/sh/include/asm/timer.h44
-rw-r--r--arch/sh/include/asm/types.h4
-rw-r--r--arch/sh/include/asm/ubc.h11
-rw-r--r--arch/sh/include/asm/unaligned-sh4a.h10
-rw-r--r--arch/sh/include/asm/unistd_32.h3
-rw-r--r--arch/sh/include/asm/unistd_64.h3
-rw-r--r--arch/sh/include/cpu-sh2a/cpu/ubc.h29
-rw-r--r--arch/sh/include/cpu-sh3/cpu/timer.h67
-rw-r--r--arch/sh/include/cpu-sh4/cpu/cache.h2
-rw-r--r--arch/sh/include/cpu-sh4/cpu/freq.h18
-rw-r--r--arch/sh/include/cpu-sh4/cpu/sh7722.h14
-rw-r--r--arch/sh/include/cpu-sh4/cpu/sh7723.h14
-rw-r--r--arch/sh/include/cpu-sh4/cpu/sh7724.h269
-rw-r--r--arch/sh/include/cpu-sh4/cpu/sh7785.h25
-rw-r--r--arch/sh/include/cpu-sh4/cpu/timer.h60
-rw-r--r--arch/sh/include/cpu-sh5/cpu/irq.h1
-rw-r--r--arch/sh/include/mach-common/mach/sh7785lcr.h10
-rw-r--r--arch/sh/include/mach-dreamcast/mach/pci.h2
-rw-r--r--arch/sh/include/mach-se/mach/se7724.h67
-rw-r--r--arch/sh/kernel/Makefile_326
-rw-r--r--arch/sh/kernel/Makefile_649
-rw-r--r--arch/sh/kernel/cpu/Makefile1
-rw-r--r--arch/sh/kernel/cpu/clock-cpg.c256
-rw-r--r--arch/sh/kernel/cpu/clock.c606
-rw-r--r--arch/sh/kernel/cpu/init.c7
-rw-r--r--arch/sh/kernel/cpu/irq/imask.c68
-rw-r--r--arch/sh/kernel/cpu/irq/intc-sh5.c36
-rw-r--r--arch/sh/kernel/cpu/irq/ipr.c9
-rw-r--r--arch/sh/kernel/cpu/sh2/clock-sh7619.c16
-rw-r--r--arch/sh/kernel/cpu/sh2/setup-sh7619.c84
-rw-r--r--arch/sh/kernel/cpu/sh2a/clock-sh7201.c14
-rw-r--r--arch/sh/kernel/cpu/sh2a/clock-sh7203.c15
-rw-r--r--arch/sh/kernel/cpu/sh2a/clock-sh7206.c12
-rw-r--r--arch/sh/kernel/cpu/sh2a/setup-mxg.c111
-rw-r--r--arch/sh/kernel/cpu/sh2a/setup-sh7201.c115
-rw-r--r--arch/sh/kernel/cpu/sh2a/setup-sh7203.c154
-rw-r--r--arch/sh/kernel/cpu/sh2a/setup-sh7206.c187
-rw-r--r--arch/sh/kernel/cpu/sh3/clock-sh3.c12
-rw-r--r--arch/sh/kernel/cpu/sh3/clock-sh7705.c12
-rw-r--r--arch/sh/kernel/cpu/sh3/clock-sh7706.c12
-rw-r--r--arch/sh/kernel/cpu/sh3/clock-sh7709.c12
-rw-r--r--arch/sh/kernel/cpu/sh3/clock-sh7710.c12
-rw-r--r--arch/sh/kernel/cpu/sh3/clock-sh7712.c8
-rw-r--r--arch/sh/kernel/cpu/sh3/setup-sh7705.c108
-rw-r--r--arch/sh/kernel/cpu/sh3/setup-sh770x.c108
-rw-r--r--arch/sh/kernel/cpu/sh3/setup-sh7710.c108
-rw-r--r--arch/sh/kernel/cpu/sh3/setup-sh7720.c270
-rw-r--r--arch/sh/kernel/cpu/sh4/clock-sh4-202.c43
-rw-r--r--arch/sh/kernel/cpu/sh4/clock-sh4.c12
-rw-r--r--arch/sh/kernel/cpu/sh4/probe.c130
-rw-r--r--arch/sh/kernel/cpu/sh4/setup-sh4-202.c164
-rw-r--r--arch/sh/kernel/cpu/sh4/setup-sh7750.c187
-rw-r--r--arch/sh/kernel/cpu/sh4/setup-sh7760.c140
-rw-r--r--arch/sh/kernel/cpu/sh4a/Makefile9
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7343.c211
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7366.c211
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7722.c923
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7723.c222
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7724.c242
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7763.c46
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7770.c12
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7780.c43
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7785.c208
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7786.c47
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-shx3.c41
-rw-r--r--arch/sh/kernel/cpu/sh4a/pinmux-sh7724.c2230
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7343.c122
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7366.c119
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7722.c123
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7723.c231
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7724.c786
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7763.c204
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7770.c546
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7780.c204
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7785.c210
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7786.c393
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-shx3.c209
-rw-r--r--arch/sh/kernel/cpu/sh5/Makefile3
-rw-r--r--arch/sh/kernel/cpu/sh5/clock-sh5.c14
-rw-r--r--arch/sh/kernel/cpu/sh5/entry.S65
-rw-r--r--arch/sh/kernel/cpu/sh5/setup-sh5.c195
-rw-r--r--arch/sh/kernel/io.c1
-rw-r--r--arch/sh/kernel/io_trapped.c2
-rw-r--r--arch/sh/kernel/irq.c77
-rw-r--r--arch/sh/kernel/kgdb.c4
-rw-r--r--arch/sh/kernel/localtimer.c (renamed from arch/sh/kernel/timers/timer-broadcast.c)0
-rw-r--r--arch/sh/kernel/machvec.c1
-rw-r--r--arch/sh/kernel/module.c2
-rw-r--r--arch/sh/kernel/process_32.c4
-rw-r--r--arch/sh/kernel/ptrace_32.c8
-rw-r--r--arch/sh/kernel/setup.c26
-rw-r--r--arch/sh/kernel/sh_ksyms_32.c9
-rw-r--r--arch/sh/kernel/sh_ksyms_64.c2
-rw-r--r--arch/sh/kernel/syscalls_32.S3
-rw-r--r--arch/sh/kernel/syscalls_64.S1
-rw-r--r--arch/sh/kernel/time.c125
-rw-r--r--arch/sh/kernel/time_32.c240
-rw-r--r--arch/sh/kernel/time_64.c363
-rw-r--r--arch/sh/kernel/timers/Makefile11
-rw-r--r--arch/sh/kernel/timers/timer-cmt.c188
-rw-r--r--arch/sh/kernel/timers/timer-mtu2.c202
-rw-r--r--arch/sh/kernel/timers/timer-tmu.c297
-rw-r--r--arch/sh/kernel/timers/timer.c55
-rw-r--r--arch/sh/kernel/traps.c6
-rw-r--r--arch/sh/kernel/traps_32.c15
-rw-r--r--arch/sh/kernel/traps_64.c35
-rw-r--r--arch/sh/kernel/vmlinux.lds.S179
-rw-r--r--arch/sh/kernel/vmlinux_32.lds.S154
-rw-r--r--arch/sh/kernel/vmlinux_64.lds.S163
-rw-r--r--arch/sh/lib64/.gitignore1
-rw-r--r--arch/sh/lib64/dbg.c182
-rw-r--r--arch/sh/lib64/panic.c43
-rw-r--r--arch/sh/lib64/sdivsi3.S6
-rw-r--r--arch/sh/lib64/udelay.c2
-rw-r--r--arch/sh/mm/Kconfig31
-rw-r--r--arch/sh/mm/cache-sh5.c8
-rw-r--r--arch/sh/mm/init.c3
-rw-r--r--arch/sh/mm/ioremap_32.c14
-rw-r--r--arch/sh/mm/ioremap_64.c266
-rw-r--r--arch/sh/mm/mmap.c136
-rw-r--r--arch/sh/oprofile/common.c1
-rw-r--r--arch/sh/tools/mach-types1
-rw-r--r--arch/um/drivers/ubd_kern.c36
-rw-r--r--arch/x86/include/asm/cpufeature.h2
-rw-r--r--arch/x86/include/asm/kvm.h1
-rw-r--r--arch/x86/include/asm/kvm_host.h45
-rw-r--r--arch/x86/include/asm/kvm_x86_emulate.h6
-rw-r--r--arch/x86/include/asm/msr.h23
-rw-r--r--arch/x86/include/asm/svm.h1
-rw-r--r--arch/x86/include/asm/termios.h1
-rw-r--r--arch/x86/include/asm/vmx.h1
-rw-r--r--arch/x86/kernel/cpu/mcheck/mce_64.c1
-rw-r--r--arch/x86/kernel/kvm.c4
-rw-r--r--arch/x86/kernel/smp.c3
-rw-r--r--arch/x86/kvm/Kconfig6
-rw-r--r--arch/x86/kvm/Makefile2
-rw-r--r--arch/x86/kvm/i8254.c109
-rw-r--r--arch/x86/kvm/i8254.h12
-rw-r--r--arch/x86/kvm/irq.c7
-rw-r--r--arch/x86/kvm/kvm_timer.h18
-rw-r--r--arch/x86/kvm/lapic.c251
-rw-r--r--arch/x86/kvm/lapic.h12
-rw-r--r--arch/x86/kvm/mmu.c194
-rw-r--r--arch/x86/kvm/mmu.h5
-rw-r--r--arch/x86/kvm/paging_tmpl.h16
-rw-r--r--arch/x86/kvm/svm.c415
-rw-r--r--arch/x86/kvm/timer.c46
-rw-r--r--arch/x86/kvm/vmx.c721
-rw-r--r--arch/x86/kvm/x86.c409
-rw-r--r--arch/x86/kvm/x86.h14
-rw-r--r--arch/x86/kvm/x86_emulate.c141
-rw-r--r--arch/x86/lib/Makefile2
-rw-r--r--arch/x86/lib/msr-on-cpu.c97
-rw-r--r--arch/x86/lib/msr.c183
-rw-r--r--block/Kconfig11
-rw-r--r--block/as-iosched.c24
-rw-r--r--block/blk-barrier.c27
-rw-r--r--block/blk-core.c858
-rw-r--r--block/blk-exec.c1
-rw-r--r--block/blk-integrity.c2
-rw-r--r--block/blk-ioc.c12
-rw-r--r--block/blk-map.c25
-rw-r--r--block/blk-merge.c71
-rw-r--r--block/blk-settings.c269
-rw-r--r--block/blk-sysfs.c62
-rw-r--r--block/blk-tag.c17
-rw-r--r--block/blk-timeout.c22
-rw-r--r--block/blk.h51
-rw-r--r--block/bsg.c8
-rw-r--r--block/cfq-iosched.c38
-rw-r--r--block/compat_ioctl.c4
-rw-r--r--block/deadline-iosched.c2
-rw-r--r--block/elevator.c185
-rw-r--r--block/genhd.c11
-rw-r--r--block/ioctl.c12
-rw-r--r--block/scsi_ioctl.c13
-rw-r--r--drivers/ata/ahci.c87
-rw-r--r--drivers/ata/ata_piix.c11
-rw-r--r--drivers/ata/libata-core.c11
-rw-r--r--drivers/ata/libata-scsi.c2
-rw-r--r--drivers/ata/libata-sff.c20
-rw-r--r--drivers/ata/sata_nv.c131
-rw-r--r--drivers/ata/sata_sil.c2
-rw-r--r--drivers/ata/sata_sx4.c11
-rw-r--r--drivers/block/DAC960.c10
-rw-r--r--drivers/block/Kconfig2
-rw-r--r--drivers/block/amiflop.c54
-rw-r--r--drivers/block/ataflop.c66
-rw-r--r--drivers/block/brd.c7
-rw-r--r--drivers/block/cciss.c927
-rw-r--r--drivers/block/cciss.h34
-rw-r--r--drivers/block/cciss_cmd.h2
-rw-r--r--drivers/block/cciss_scsi.c109
-rw-r--r--drivers/block/cpqarray.c20
-rw-r--r--drivers/block/floppy.c85
-rw-r--r--drivers/block/hd.c106
-rw-r--r--drivers/block/loop.c37
-rw-r--r--drivers/block/mg_disk.c537
-rw-r--r--drivers/block/nbd.c23
-rw-r--r--drivers/block/paride/pcd.c29
-rw-r--r--drivers/block/paride/pd.c22
-rw-r--r--drivers/block/paride/pf.c47
-rw-r--r--drivers/block/pktcdvd.c8
-rw-r--r--drivers/block/ps3disk.c24
-rw-r--r--drivers/block/sunvdc.c14
-rw-r--r--drivers/block/swim.c48
-rw-r--r--drivers/block/swim3.c107
-rw-r--r--drivers/block/sx8.c17
-rw-r--r--drivers/block/ub.c54
-rw-r--r--drivers/block/viodasd.c12
-rw-r--r--drivers/block/virtio_blk.c110
-rw-r--r--drivers/block/xd.c41
-rw-r--r--drivers/block/xen-blkfront.c34
-rw-r--r--drivers/block/xsysace.c46
-rw-r--r--drivers/block/z2ram.c19
-rw-r--r--drivers/bluetooth/hci_ldisc.c5
-rw-r--r--drivers/cdrom/cdrom.c4
-rw-r--r--drivers/cdrom/gdrom.c36
-rw-r--r--drivers/cdrom/viocd.c33
-rw-r--r--drivers/char/Kconfig13
-rw-r--r--drivers/char/Makefile1
-rw-r--r--drivers/char/bfin_jtag_comm.c365
-rw-r--r--drivers/char/cyclades.c290
-rw-r--r--drivers/char/epca.c17
-rw-r--r--drivers/char/ip2/i2lib.c4
-rw-r--r--drivers/char/ip2/ip2main.c4
-rw-r--r--drivers/char/isicom.c19
-rw-r--r--drivers/char/istallion.c8
-rw-r--r--drivers/char/moxa.c5
-rw-r--r--drivers/char/mxser.c12
-rw-r--r--drivers/char/n_hdlc.c4
-rw-r--r--drivers/char/n_tty.c29
-rw-r--r--drivers/char/pcmcia/synclink_cs.c11
-rw-r--r--drivers/char/pty.c11
-rw-r--r--drivers/char/raw.c2
-rw-r--r--drivers/char/rocket.c19
-rw-r--r--drivers/char/selection.c2
-rw-r--r--drivers/char/stallion.c6
-rw-r--r--drivers/char/synclink.c9
-rw-r--r--drivers/char/synclink_gt.c86
-rw-r--r--drivers/char/synclinkmp.c9
-rw-r--r--drivers/char/tty_audit.c10
-rw-r--r--drivers/char/tty_io.c122
-rw-r--r--drivers/char/tty_ioctl.c88
-rw-r--r--drivers/char/tty_ldisc.c549
-rw-r--r--drivers/char/tty_port.c47
-rw-r--r--drivers/clocksource/Makefile2
-rw-r--r--drivers/clocksource/sh_cmt.c116
-rw-r--r--drivers/clocksource/sh_mtu2.c357
-rw-r--r--drivers/clocksource/sh_tmu.c461
-rw-r--r--drivers/edac/Kconfig26
-rw-r--r--drivers/edac/Makefile7
-rw-r--r--drivers/edac/amd64_edac.c3354
-rw-r--r--drivers/edac/amd64_edac.h644
-rw-r--r--drivers/edac/amd64_edac_dbg.c255
-rw-r--r--drivers/edac/amd64_edac_err_types.c161
-rw-r--r--drivers/edac/amd64_edac_inj.c185
-rw-r--r--drivers/edac/edac_core.h9
-rw-r--r--drivers/firmware/dmi_scan.c1
-rw-r--r--drivers/i2c/busses/i2c-sh7760.c2
-rw-r--r--drivers/ide/alim15x3.c10
-rw-r--r--drivers/ide/ide-atapi.c183
-rw-r--r--drivers/ide/ide-cd.c152
-rw-r--r--drivers/ide/ide-cd.h4
-rw-r--r--drivers/ide/ide-disk.c11
-rw-r--r--drivers/ide/ide-dma.c22
-rw-r--r--drivers/ide/ide-floppy.c32
-rw-r--r--drivers/ide/ide-io.c57
-rw-r--r--drivers/ide/ide-ioctls.c1
-rw-r--r--drivers/ide/ide-lib.c2
-rw-r--r--drivers/ide/ide-park.c7
-rw-r--r--drivers/ide/ide-pm.c38
-rw-r--r--drivers/ide/ide-tape.c736
-rw-r--r--drivers/ide/ide-taskfile.c20
-rw-r--r--drivers/ide/pdc202xx_old.c2
-rw-r--r--drivers/ide/tc86c001.c2
-rw-r--r--drivers/ide/tx4939ide.c2
-rw-r--r--drivers/md/bitmap.c4
-rw-r--r--drivers/md/dm-exception-store.c2
-rw-r--r--drivers/md/dm-log.c3
-rw-r--r--drivers/md/dm-snap-persistent.c2
-rw-r--r--drivers/md/dm-table.c38
-rw-r--r--drivers/md/linear.c2
-rw-r--r--drivers/md/md.c2
-rw-r--r--drivers/md/multipath.c4
-rw-r--r--drivers/md/raid0.c2
-rw-r--r--drivers/md/raid1.c4
-rw-r--r--drivers/md/raid10.c8
-rw-r--r--drivers/md/raid5.c4
-rw-r--r--drivers/memstick/core/mspro_block.c19
-rw-r--r--drivers/message/fusion/mptsas.c22
-rw-r--r--drivers/message/i2o/i2o_block.c43
-rw-r--r--drivers/mmc/card/block.c12
-rw-r--r--drivers/mmc/card/queue.c11
-rw-r--r--drivers/mtd/mtd_blkdevs.c43
-rw-r--r--drivers/parport/parport_pc.c1802
-rw-r--r--drivers/rtc/Kconfig2
-rw-r--r--drivers/s390/block/dasd.c37
-rw-r--r--drivers/s390/block/dasd_diag.c5
-rw-r--r--drivers/s390/block/dasd_eckd.c6
-rw-r--r--drivers/s390/block/dasd_fba.c7
-rw-r--r--drivers/s390/block/dcssblk.c2
-rw-r--r--drivers/s390/block/xpram.c2
-rw-r--r--drivers/s390/char/tape_34xx.c2
-rw-r--r--drivers/s390/char/tape_3590.c2
-rw-r--r--drivers/s390/char/tape_block.c26
-rw-r--r--drivers/sbus/char/jsflash.c26
-rw-r--r--drivers/scsi/eata.c24
-rw-r--r--drivers/scsi/libsas/sas_expander.c16
-rw-r--r--drivers/scsi/libsas/sas_host_smp.c49
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c22
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_transport.c23
-rw-r--r--drivers/scsi/osd/osd_initiator.c72
-rw-r--r--drivers/scsi/scsi_lib.c87
-rw-r--r--drivers/scsi/scsi_tgt_lib.c2
-rw-r--r--drivers/scsi/scsi_transport_sas.c4
-rw-r--r--drivers/scsi/sd.c26
-rw-r--r--drivers/scsi/sd_dif.c2
-rw-r--r--drivers/scsi/sg.c17
-rw-r--r--drivers/scsi/sr.c17
-rw-r--r--drivers/scsi/st.c6
-rw-r--r--drivers/scsi/u14-34f.c22
-rw-r--r--drivers/serial/8250.c7
-rw-r--r--drivers/serial/8250_pci.c3
-rw-r--r--drivers/serial/Kconfig8
-rw-r--r--drivers/serial/Makefile1
-rw-r--r--drivers/serial/bfin_5xx.c77
-rw-r--r--drivers/serial/bfin_sport_uart.c58
-rw-r--r--drivers/serial/icom.c20
-rw-r--r--drivers/serial/imx.c294
-rw-r--r--drivers/serial/jsm/jsm.h1
-rw-r--r--drivers/serial/jsm/jsm_tty.c14
-rw-r--r--drivers/serial/sh-sci.c388
-rw-r--r--drivers/serial/sh-sci.h42
-rw-r--r--drivers/serial/timbuart.c526
-rw-r--r--drivers/serial/timbuart.h58
-rw-r--r--drivers/sh/intc.c11
-rw-r--r--drivers/usb/class/cdc-acm.c442
-rw-r--r--drivers/usb/class/cdc-acm.h5
-rw-r--r--drivers/usb/serial/belkin_sa.c6
-rw-r--r--drivers/usb/serial/ch341.c46
-rw-r--r--drivers/usb/serial/console.c6
-rw-r--r--drivers/usb/serial/cp210x.c253
-rw-r--r--drivers/usb/serial/cyberjack.c6
-rw-r--r--drivers/usb/serial/cypress_m8.c81
-rw-r--r--drivers/usb/serial/digi_acceleport.c75
-rw-r--r--drivers/usb/serial/empeg.c6
-rw-r--r--drivers/usb/serial/ftdi_sio.c149
-rw-r--r--drivers/usb/serial/garmin_gps.c3
-rw-r--r--drivers/usb/serial/generic.c3
-rw-r--r--drivers/usb/serial/io_edgeport.c10
-rw-r--r--drivers/usb/serial/io_ti.c3
-rw-r--r--drivers/usb/serial/ipaq.c6
-rw-r--r--drivers/usb/serial/ipw.c18
-rw-r--r--drivers/usb/serial/ir-usb.c6
-rw-r--r--drivers/usb/serial/iuu_phoenix.c102
-rw-r--r--drivers/usb/serial/keyspan.c13
-rw-r--r--drivers/usb/serial/keyspan.h8
-rw-r--r--drivers/usb/serial/keyspan_pda.c48
-rw-r--r--drivers/usb/serial/kl5kusb105.c6
-rw-r--r--drivers/usb/serial/kobil_sct.c9
-rw-r--r--drivers/usb/serial/mct_u232.c37
-rw-r--r--drivers/usb/serial/mos7720.c3
-rw-r--r--drivers/usb/serial/mos7840.c48
-rw-r--r--drivers/usb/serial/navman.c3
-rw-r--r--drivers/usb/serial/omninet.c6
-rw-r--r--drivers/usb/serial/opticon.c3
-rw-r--r--drivers/usb/serial/option.c68
-rw-r--r--drivers/usb/serial/oti6858.c57
-rw-r--r--drivers/usb/serial/pl2303.c79
-rw-r--r--drivers/usb/serial/sierra.c351
-rw-r--r--drivers/usb/serial/spcp8x5.c85
-rw-r--r--drivers/usb/serial/symbolserial.c3
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c6
-rw-r--r--drivers/usb/serial/usb-serial.c144
-rw-r--r--drivers/usb/serial/visor.c6
-rw-r--r--drivers/usb/serial/whiteheat.c33
-rw-r--r--drivers/usb/storage/scsiglue.c4
-rw-r--r--drivers/video/hitfb.c4
-rw-r--r--fs/bio.c26
-rw-r--r--fs/block_dev.c6
-rw-r--r--fs/buffer.c8
-rw-r--r--fs/cifs/CHANGES11
-rw-r--r--fs/cifs/README16
-rw-r--r--fs/cifs/cifs_spnego.c6
-rw-r--r--fs/cifs/cifsacl.c178
-rw-r--r--fs/cifs/cifsfs.c2
-rw-r--r--fs/cifs/cifsfs.h4
-rw-r--r--fs/cifs/cifsproto.h10
-rw-r--r--fs/cifs/cifssmb.c7
-rw-r--r--fs/cifs/connect.c34
-rw-r--r--fs/cifs/file.c2
-rw-r--r--fs/cifs/inode.c19
-rw-r--r--fs/cifs/netmisc.c24
-rw-r--r--fs/cifs/readdir.c44
-rw-r--r--fs/coda/file.c9
-rw-r--r--fs/compat.c6
-rw-r--r--fs/devpts/inode.c4
-rw-r--r--fs/direct-io.c2
-rw-r--r--fs/exec.c10
-rw-r--r--fs/exofs/osd.c4
-rw-r--r--fs/ext2/super.c1
-rw-r--r--fs/ext3/super.c5
-rw-r--r--fs/ext4/Makefile4
-rw-r--r--fs/ext4/balloc.c28
-rw-r--r--fs/ext4/block_validity.c244
-rw-r--r--fs/ext4/dir.c3
-rw-r--r--fs/ext4/ext4.h354
-rw-r--r--fs/ext4/ext4_i.h140
-rw-r--r--fs/ext4/ext4_sb.h161
-rw-r--r--fs/ext4/extents.c85
-rw-r--r--fs/ext4/group.h29
-rw-r--r--fs/ext4/ialloc.c73
-rw-r--r--fs/ext4/inode.c593
-rw-r--r--fs/ext4/mballoc.c166
-rw-r--r--fs/ext4/mballoc.h1
-rw-r--r--fs/ext4/namei.c27
-rw-r--r--fs/ext4/namei.h8
-rw-r--r--fs/ext4/resize.c36
-rw-r--r--fs/ext4/super.c833
-rw-r--r--fs/gfs2/Kconfig1
-rw-r--r--fs/gfs2/Makefile4
-rw-r--r--fs/gfs2/aops.c (renamed from fs/gfs2/ops_address.c)21
-rw-r--r--fs/gfs2/bmap.c12
-rw-r--r--fs/gfs2/dentry.c (renamed from fs/gfs2/ops_dentry.c)0
-rw-r--r--fs/gfs2/dir.c11
-rw-r--r--fs/gfs2/eattr.c14
-rw-r--r--fs/gfs2/export.c (renamed from fs/gfs2/ops_export.c)0
-rw-r--r--fs/gfs2/file.c (renamed from fs/gfs2/ops_file.c)36
-rw-r--r--fs/gfs2/glock.c21
-rw-r--r--fs/gfs2/glops.c20
-rw-r--r--fs/gfs2/incore.h27
-rw-r--r--fs/gfs2/inode.c150
-rw-r--r--fs/gfs2/inode.h52
-rw-r--r--fs/gfs2/log.c6
-rw-r--r--fs/gfs2/lops.c14
-rw-r--r--fs/gfs2/main.c8
-rw-r--r--fs/gfs2/meta_io.c105
-rw-r--r--fs/gfs2/mount.c185
-rw-r--r--fs/gfs2/ops_address.h23
-rw-r--r--fs/gfs2/ops_fstype.c72
-rw-r--r--fs/gfs2/ops_inode.c146
-rw-r--r--fs/gfs2/ops_super.c723
-rw-r--r--fs/gfs2/quota.c1
-rw-r--r--fs/gfs2/recovery.c102
-rw-r--r--fs/gfs2/recovery.h2
-rw-r--r--fs/gfs2/rgrp.c143
-rw-r--r--fs/gfs2/rgrp.h47
-rw-r--r--fs/gfs2/super.c903
-rw-r--r--fs/gfs2/sys.c245
-rw-r--r--fs/gfs2/trans.c9
-rw-r--r--fs/hugetlbfs/inode.c2
-rw-r--r--fs/ioctl.c14
-rw-r--r--fs/jbd2/journal.c8
-rw-r--r--fs/mpage.c6
-rw-r--r--fs/namei.c6
-rw-r--r--fs/nfsd/vfs.c14
-rw-r--r--fs/nilfs2/the_nilfs.c2
-rw-r--r--fs/ntfs/super.c6
-rw-r--r--fs/ocfs2/cluster/heartbeat.c2
-rw-r--r--fs/ocfs2/super.c2
-rw-r--r--fs/partitions/check.c10
-rw-r--r--fs/partitions/ibm.c2
-rw-r--r--fs/partitions/msdos.c4
-rw-r--r--fs/pipe.c14
-rw-r--r--fs/proc/base.c6
-rw-r--r--fs/read_write.c7
-rw-r--r--fs/splice.c338
-rw-r--r--fs/udf/super.c2
-rw-r--r--fs/xfs/linux-2.6/xfs_buf.c2
-rw-r--r--include/linux/bio.h10
-rw-r--r--include/linux/blkdev.h245
-rw-r--r--include/linux/clocksource.h10
-rw-r--r--include/linux/cyclades.h37
-rw-r--r--include/linux/device-mapper.h2
-rw-r--r--include/linux/elevator.h4
-rw-r--r--include/linux/fs.h2
-rw-r--r--include/linux/genhd.h1
-rw-r--r--include/linux/ide.h27
-rw-r--r--include/linux/ima.h11
-rw-r--r--include/linux/init_task.h4
-rw-r--r--include/linux/iocontext.h6
-rw-r--r--include/linux/kvm.h46
-rw-r--r--include/linux/kvm_host.h21
-rw-r--r--include/linux/kvm_types.h27
-rw-r--r--include/linux/loop.h3
-rw-r--r--include/linux/lsm_audit.h111
-rw-r--r--include/linux/magic.h1
-rw-r--r--include/linux/mg_disk.h206
-rw-r--r--include/linux/mm.h2
-rw-r--r--include/linux/pci_ids.h2
-rw-r--r--include/linux/pipe_fs_i.h1
-rw-r--r--include/linux/rational.h19
-rw-r--r--include/linux/sched.h5
-rw-r--r--include/linux/security.h2
-rw-r--r--include/linux/serial.h116
-rw-r--r--include/linux/serial_core.h6
-rw-r--r--include/linux/serial_sci.h3
-rw-r--r--include/linux/sh_cmt.h13
-rw-r--r--include/linux/sh_timer.h13
-rw-r--r--include/linux/splice.h3
-rw-r--r--include/linux/time.h15
-rw-r--r--include/linux/tty.h18
-rw-r--r--include/linux/tty_driver.h6
-rw-r--r--include/linux/usb/serial.h10
-rw-r--r--include/linux/virtio_blk.h12
-rw-r--r--include/scsi/scsi_cmnd.h2
-rw-r--r--include/trace/events/block.h29
-rw-r--r--ipc/shm.c3
-rw-r--r--kernel/cred.c4
-rw-r--r--kernel/exit.c1
-rw-r--r--kernel/module.c7
-rw-r--r--kernel/ptrace.c9
-rw-r--r--kernel/signal.c11
-rw-r--r--kernel/slow-work.c4
-rw-r--r--kernel/sysctl.c14
-rw-r--r--kernel/time/clocksource.c3
-rw-r--r--kernel/time/timekeeping.c7
-rw-r--r--kernel/trace/blktrace.c21
-rw-r--r--lib/Kconfig3
-rw-r--r--lib/Makefile1
-rw-r--r--lib/rational.c62
-rw-r--r--mm/Kconfig19
-rw-r--r--mm/bounce.c4
-rw-r--r--mm/mmap.c3
-rw-r--r--mm/nommu.c3
-rw-r--r--mm/shmem.c2
-rw-r--r--security/Kconfig22
-rw-r--r--security/Makefile3
-rw-r--r--security/commoncap.c32
-rw-r--r--security/inode.c2
-rw-r--r--security/integrity/ima/ima_audit.c32
-rw-r--r--security/integrity/ima/ima_crypto.c4
-rw-r--r--security/integrity/ima/ima_fs.c8
-rw-r--r--security/integrity/ima/ima_iint.c2
-rw-r--r--security/integrity/ima/ima_init.c4
-rw-r--r--security/integrity/ima/ima_main.c86
-rw-r--r--security/integrity/ima/ima_policy.c48
-rw-r--r--security/lsm_audit.c386
-rw-r--r--security/root_plug.c12
-rw-r--r--security/security.c3
-rw-r--r--security/selinux/avc.c2
-rw-r--r--security/selinux/hooks.c24
-rw-r--r--security/selinux/include/security.h7
-rw-r--r--security/selinux/nlmsgtab.c2
-rw-r--r--security/selinux/selinuxfs.c8
-rw-r--r--security/selinux/ss/services.c30
-rw-r--r--security/smack/smack.h108
-rw-r--r--security/smack/smack_access.c143
-rw-r--r--security/smack/smack_lsm.c405
-rw-r--r--security/smack/smackfs.c68
-rw-r--r--security/tomoyo/common.c119
-rw-r--r--security/tomoyo/common.h134
-rw-r--r--security/tomoyo/domain.c240
-rw-r--r--security/tomoyo/file.c156
-rw-r--r--security/tomoyo/realpath.c23
-rw-r--r--security/tomoyo/tomoyo.c4
-rw-r--r--security/tomoyo/tomoyo.h13
-rw-r--r--sound/oss/Kconfig2
-rw-r--r--sound/oss/sh_dac_audio.c85
-rw-r--r--virt/kvm/ioapic.c153
-rw-r--r--virt/kvm/ioapic.h27
-rw-r--r--virt/kvm/iommu.c27
-rw-r--r--virt/kvm/irq_comm.c111
-rw-r--r--virt/kvm/kvm_main.c678
753 files changed, 40178 insertions, 19663 deletions
diff --git a/Documentation/ABI/testing/sysfs-block b/Documentation/ABI/testing/sysfs-block
index 44f52a4f5903..cbbd3e069945 100644
--- a/Documentation/ABI/testing/sysfs-block
+++ b/Documentation/ABI/testing/sysfs-block
@@ -60,3 +60,62 @@ Description:
60 Indicates whether the block layer should automatically 60 Indicates whether the block layer should automatically
61 generate checksums for write requests bound for 61 generate checksums for write requests bound for
62 devices that support receiving integrity metadata. 62 devices that support receiving integrity metadata.
63
64What: /sys/block/<disk>/alignment_offset
65Date: April 2009
66Contact: Martin K. Petersen <martin.petersen@oracle.com>
67Description:
68 Storage devices may report a physical block size that is
69 bigger than the logical block size (for instance a drive
70 with 4KB physical sectors exposing 512-byte logical
71 blocks to the operating system). This parameter
72 indicates how many bytes the beginning of the device is
73 offset from the disk's natural alignment.
74
75What: /sys/block/<disk>/<partition>/alignment_offset
76Date: April 2009
77Contact: Martin K. Petersen <martin.petersen@oracle.com>
78Description:
79 Storage devices may report a physical block size that is
80 bigger than the logical block size (for instance a drive
81 with 4KB physical sectors exposing 512-byte logical
82 blocks to the operating system). This parameter
83 indicates how many bytes the beginning of the partition
84 is offset from the disk's natural alignment.
85
86What: /sys/block/<disk>/queue/logical_block_size
87Date: May 2009
88Contact: Martin K. Petersen <martin.petersen@oracle.com>
89Description:
90 This is the smallest unit the storage device can
91 address. It is typically 512 bytes.
92
93What: /sys/block/<disk>/queue/physical_block_size
94Date: May 2009
95Contact: Martin K. Petersen <martin.petersen@oracle.com>
96Description:
97 This is the smallest unit the storage device can write
98 without resorting to read-modify-write operation. It is
99 usually the same as the logical block size but may be
100 bigger. One example is SATA drives with 4KB sectors
101 that expose a 512-byte logical block size to the
102 operating system.
103
104What: /sys/block/<disk>/queue/minimum_io_size
105Date: April 2009
106Contact: Martin K. Petersen <martin.petersen@oracle.com>
107Description:
108 Storage devices may report a preferred minimum I/O size,
109 which is the smallest request the device can perform
110 without incurring a read-modify-write penalty. For disk
111 drives this is often the physical block size. For RAID
112 arrays it is often the stripe chunk size.
113
114What: /sys/block/<disk>/queue/optimal_io_size
115Date: April 2009
116Contact: Martin K. Petersen <martin.petersen@oracle.com>
117Description:
118 Storage devices may report an optimal I/O size, which is
119 the device's preferred unit of receiving I/O. This is
120 rarely reported for disk drives. For RAID devices it is
121 usually the stripe width or the internal block size.
diff --git a/Documentation/ABI/testing/sysfs-bus-pci-devices-cciss b/Documentation/ABI/testing/sysfs-bus-pci-devices-cciss
new file mode 100644
index 000000000000..0a92a7c93a62
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-bus-pci-devices-cciss
@@ -0,0 +1,33 @@
1Where: /sys/bus/pci/devices/<dev>/ccissX/cXdY/model
2Date: March 2009
3Kernel Version: 2.6.30
4Contact: iss_storagedev@hp.com
5Description: Displays the SCSI INQUIRY page 0 model for logical drive
6 Y of controller X.
7
8Where: /sys/bus/pci/devices/<dev>/ccissX/cXdY/rev
9Date: March 2009
10Kernel Version: 2.6.30
11Contact: iss_storagedev@hp.com
12Description: Displays the SCSI INQUIRY page 0 revision for logical
13 drive Y of controller X.
14
15Where: /sys/bus/pci/devices/<dev>/ccissX/cXdY/unique_id
16Date: March 2009
17Kernel Version: 2.6.30
18Contact: iss_storagedev@hp.com
19Description: Displays the SCSI INQUIRY page 83 serial number for logical
20 drive Y of controller X.
21
22Where: /sys/bus/pci/devices/<dev>/ccissX/cXdY/vendor
23Date: March 2009
24Kernel Version: 2.6.30
25Contact: iss_storagedev@hp.com
26Description: Displays the SCSI INQUIRY page 0 vendor for logical drive
27 Y of controller X.
28
29Where: /sys/bus/pci/devices/<dev>/ccissX/cXdY/block:cciss!cXdY
30Date: March 2009
31Kernel Version: 2.6.30
32Contact: iss_storagedev@hp.com
33Description: A symbolic link to /sys/block/cciss!cXdY
diff --git a/Documentation/Smack.txt b/Documentation/Smack.txt
index 629c92e99783..34614b4c708e 100644
--- a/Documentation/Smack.txt
+++ b/Documentation/Smack.txt
@@ -184,8 +184,9 @@ length. Single character labels using special characters, that being anything
184other than a letter or digit, are reserved for use by the Smack development 184other than a letter or digit, are reserved for use by the Smack development
185team. Smack labels are unstructured, case sensitive, and the only operation 185team. Smack labels are unstructured, case sensitive, and the only operation
186ever performed on them is comparison for equality. Smack labels cannot 186ever performed on them is comparison for equality. Smack labels cannot
187contain unprintable characters or the "/" (slash) character. Smack labels 187contain unprintable characters, the "/" (slash), the "\" (backslash), the "'"
188cannot begin with a '-', which is reserved for special options. 188(quote) and '"' (double-quote) characters.
189Smack labels cannot begin with a '-', which is reserved for special options.
189 190
190There are some predefined labels: 191There are some predefined labels:
191 192
@@ -523,3 +524,18 @@ Smack supports some mount options:
523 524
524These mount options apply to all file system types. 525These mount options apply to all file system types.
525 526
527Smack auditing
528
529If you want Smack auditing of security events, you need to set CONFIG_AUDIT
530in your kernel configuration.
531By default, all denied events will be audited. You can change this behavior by
532writing a single character to the /smack/logging file :
5330 : no logging
5341 : log denied (default)
5352 : log accepted
5363 : log denied & accepted
537
538Events are logged as 'key=value' pairs, for each event you at least will get
539the subjet, the object, the rights requested, the action, the kernel function
540that triggered the event, plus other pairs depending on the type of event
541audited.
diff --git a/Documentation/block/biodoc.txt b/Documentation/block/biodoc.txt
index 6fab97ea7e6b..8d2158a1c6aa 100644
--- a/Documentation/block/biodoc.txt
+++ b/Documentation/block/biodoc.txt
@@ -186,7 +186,7 @@ a virtual address mapping (unlike the earlier scheme of virtual address
186do not have a corresponding kernel virtual address space mapping) and 186do not have a corresponding kernel virtual address space mapping) and
187low-memory pages. 187low-memory pages.
188 188
189Note: Please refer to Documentation/PCI/PCI-DMA-mapping.txt for a discussion 189Note: Please refer to Documentation/DMA-mapping.txt for a discussion
190on PCI high mem DMA aspects and mapping of scatter gather lists, and support 190on PCI high mem DMA aspects and mapping of scatter gather lists, and support
191for 64 bit PCI. 191for 64 bit PCI.
192 192
diff --git a/Documentation/filesystems/gfs2-glocks.txt b/Documentation/filesystems/gfs2-glocks.txt
index 4dae9a3840bf..0494f78d87e4 100644
--- a/Documentation/filesystems/gfs2-glocks.txt
+++ b/Documentation/filesystems/gfs2-glocks.txt
@@ -60,7 +60,7 @@ go_lock | Called for the first local holder of a lock
60go_unlock | Called on the final local unlock of a lock 60go_unlock | Called on the final local unlock of a lock
61go_dump | Called to print content of object for debugfs file, or on 61go_dump | Called to print content of object for debugfs file, or on
62 | error to dump glock to the log. 62 | error to dump glock to the log.
63go_type; | The type of the glock, LM_TYPE_..... 63go_type | The type of the glock, LM_TYPE_.....
64go_min_hold_time | The minimum hold time 64go_min_hold_time | The minimum hold time
65 65
66The minimum hold time for each lock is the time after a remote lock 66The minimum hold time for each lock is the time after a remote lock
diff --git a/Documentation/filesystems/gfs2.txt b/Documentation/filesystems/gfs2.txt
index 593004b6bbab..5e3ab8f3beff 100644
--- a/Documentation/filesystems/gfs2.txt
+++ b/Documentation/filesystems/gfs2.txt
@@ -11,18 +11,15 @@ their I/O so file system consistency is maintained. One of the nifty
11features of GFS is perfect consistency -- changes made to the file system 11features of GFS is perfect consistency -- changes made to the file system
12on one machine show up immediately on all other machines in the cluster. 12on one machine show up immediately on all other machines in the cluster.
13 13
14GFS uses interchangable inter-node locking mechanisms. Different lock 14GFS uses interchangable inter-node locking mechanisms, the currently
15modules can plug into GFS and each file system selects the appropriate 15supported mechanisms are:
16lock module at mount time. Lock modules include:
17 16
18 lock_nolock -- allows gfs to be used as a local file system 17 lock_nolock -- allows gfs to be used as a local file system
19 18
20 lock_dlm -- uses a distributed lock manager (dlm) for inter-node locking 19 lock_dlm -- uses a distributed lock manager (dlm) for inter-node locking
21 The dlm is found at linux/fs/dlm/ 20 The dlm is found at linux/fs/dlm/
22 21
23In addition to interfacing with an external locking manager, a gfs lock 22Lock_dlm depends on user space cluster management systems found
24module is responsible for interacting with external cluster management
25systems. Lock_dlm depends on user space cluster management systems found
26at the URL above. 23at the URL above.
27 24
28To use gfs as a local file system, no external clustering systems are 25To use gfs as a local file system, no external clustering systems are
@@ -31,13 +28,19 @@ needed, simply:
31 $ mkfs -t gfs2 -p lock_nolock -j 1 /dev/block_device 28 $ mkfs -t gfs2 -p lock_nolock -j 1 /dev/block_device
32 $ mount -t gfs2 /dev/block_device /dir 29 $ mount -t gfs2 /dev/block_device /dir
33 30
34GFS2 is not on-disk compatible with previous versions of GFS. 31If you are using Fedora, you need to install the gfs2-utils package
32and, for lock_dlm, you will also need to install the cman package
33and write a cluster.conf as per the documentation.
34
35GFS2 is not on-disk compatible with previous versions of GFS, but it
36is pretty close.
35 37
36The following man pages can be found at the URL above: 38The following man pages can be found at the URL above:
37 gfs2_fsck to repair a filesystem 39 fsck.gfs2 to repair a filesystem
38 gfs2_grow to expand a filesystem online 40 gfs2_grow to expand a filesystem online
39 gfs2_jadd to add journals to a filesystem online 41 gfs2_jadd to add journals to a filesystem online
40 gfs2_tool to manipulate, examine and tune a filesystem 42 gfs2_tool to manipulate, examine and tune a filesystem
41 gfs2_quota to examine and change quota values in a filesystem 43 gfs2_quota to examine and change quota values in a filesystem
44 gfs2_convert to convert a gfs filesystem to gfs2 in-place
42 mount.gfs2 to help mount(8) mount a filesystem 45 mount.gfs2 to help mount(8) mount a filesystem
43 mkfs.gfs2 to make a filesystem 46 mkfs.gfs2 to make a filesystem
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 4a3c2209a124..72d3bf08d79b 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -928,6 +928,12 @@ and is between 256 and 4096 characters. It is defined in the file
928 Formt: { "sha1" | "md5" } 928 Formt: { "sha1" | "md5" }
929 default: "sha1" 929 default: "sha1"
930 930
931 ima_tcb [IMA]
932 Load a policy which meets the needs of the Trusted
933 Computing Base. This means IMA will measure all
934 programs exec'd, files mmap'd for exec, and all files
935 opened for read by uid=0.
936
931 in2000= [HW,SCSI] 937 in2000= [HW,SCSI]
932 See header of drivers/scsi/in2000.c. 938 See header of drivers/scsi/in2000.c.
933 939
diff --git a/Documentation/sysctl/kernel.txt b/Documentation/sysctl/kernel.txt
index f11ca7979fa6..322a00bb99d9 100644
--- a/Documentation/sysctl/kernel.txt
+++ b/Documentation/sysctl/kernel.txt
@@ -32,6 +32,7 @@ show up in /proc/sys/kernel:
32- kstack_depth_to_print [ X86 only ] 32- kstack_depth_to_print [ X86 only ]
33- l2cr [ PPC only ] 33- l2cr [ PPC only ]
34- modprobe ==> Documentation/debugging-modules.txt 34- modprobe ==> Documentation/debugging-modules.txt
35- modules_disabled
35- msgmax 36- msgmax
36- msgmnb 37- msgmnb
37- msgmni 38- msgmni
@@ -184,6 +185,16 @@ kernel stack.
184 185
185============================================================== 186==============================================================
186 187
188modules_disabled:
189
190A toggle value indicating if modules are allowed to be loaded
191in an otherwise modular kernel. This toggle defaults to off
192(0), but can be set true (1). Once true, modules can be
193neither loaded nor unloaded, and the toggle cannot be set back
194to false.
195
196==============================================================
197
187osrelease, ostype & version: 198osrelease, ostype & version:
188 199
189# cat osrelease 200# cat osrelease
diff --git a/MAINTAINERS b/MAINTAINERS
index cf4abddfc8a4..ccdb57524e3c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -71,7 +71,7 @@ P: Person
71M: Mail patches to 71M: Mail patches to
72L: Mailing list that is relevant to this area 72L: Mailing list that is relevant to this area
73W: Web-page with status/info 73W: Web-page with status/info
74T: SCM tree type and location. Type is one of: git, hg, quilt. 74T: SCM tree type and location. Type is one of: git, hg, quilt, stgit.
75S: Status, one of the following: 75S: Status, one of the following:
76 76
77 Supported: Someone is actually paid to look after this. 77 Supported: Someone is actually paid to look after this.
@@ -159,7 +159,8 @@ F: drivers/net/r8169.c
1598250/16?50 (AND CLONE UARTS) SERIAL DRIVER 1598250/16?50 (AND CLONE UARTS) SERIAL DRIVER
160L: linux-serial@vger.kernel.org 160L: linux-serial@vger.kernel.org
161W: http://serial.sourceforge.net 161W: http://serial.sourceforge.net
162S: Orphan 162M: alan@lxorguk.ukuu.org.uk
163S: Odd Fixes
163F: drivers/serial/8250* 164F: drivers/serial/8250*
164F: include/linux/serial_8250.h 165F: include/linux/serial_8250.h
165 166
@@ -1978,6 +1979,16 @@ F: Documentation/edac.txt
1978F: drivers/edac/edac_* 1979F: drivers/edac/edac_*
1979F: include/linux/edac.h 1980F: include/linux/edac.h
1980 1981
1982EDAC-AMD64
1983P: Doug Thompson
1984M: dougthompson@xmission.com
1985P: Borislav Petkov
1986M: borislav.petkov@amd.com
1987L: bluesmoke-devel@lists.sourceforge.net (moderated for non-subscribers)
1988W: bluesmoke.sourceforge.net
1989S: Supported
1990F: drivers/edac/amd64_edac*
1991
1981EDAC-E752X 1992EDAC-E752X
1982P: Mark Gross 1993P: Mark Gross
1983M: mark.gross@intel.com 1994M: mark.gross@intel.com
@@ -5629,6 +5640,7 @@ P: Alan Cox
5629M: alan@lxorguk.ukuu.org.uk 5640M: alan@lxorguk.ukuu.org.uk
5630L: linux-kernel@vger.kernel.org 5641L: linux-kernel@vger.kernel.org
5631S: Maintained 5642S: Maintained
5643T: stgit http://zeniv.linux.org.uk/~alan/ttydev/
5632 5644
5633TULIP NETWORK DRIVERS 5645TULIP NETWORK DRIVERS
5634P: Grant Grundler 5646P: Grant Grundler
diff --git a/arch/arm/plat-mxc/include/mach/imx-uart.h b/arch/arm/plat-mxc/include/mach/imx-uart.h
index 599217b2e13f..f9bd17dd8dd7 100644
--- a/arch/arm/plat-mxc/include/mach/imx-uart.h
+++ b/arch/arm/plat-mxc/include/mach/imx-uart.h
@@ -20,11 +20,16 @@
20#define ASMARM_ARCH_UART_H 20#define ASMARM_ARCH_UART_H
21 21
22#define IMXUART_HAVE_RTSCTS (1<<0) 22#define IMXUART_HAVE_RTSCTS (1<<0)
23#define IMXUART_IRDA (1<<1)
23 24
24struct imxuart_platform_data { 25struct imxuart_platform_data {
25 int (*init)(struct platform_device *pdev); 26 int (*init)(struct platform_device *pdev);
26 int (*exit)(struct platform_device *pdev); 27 int (*exit)(struct platform_device *pdev);
27 unsigned int flags; 28 unsigned int flags;
29 void (*irda_enable)(int enable);
30 unsigned int irda_inv_rx:1;
31 unsigned int irda_inv_tx:1;
32 unsigned short transceiver_delay;
28}; 33};
29 34
30#endif 35#endif
diff --git a/arch/arm/plat-omap/mailbox.c b/arch/arm/plat-omap/mailbox.c
index 0abfbaa59871..40424edae939 100644
--- a/arch/arm/plat-omap/mailbox.c
+++ b/arch/arm/plat-omap/mailbox.c
@@ -147,24 +147,40 @@ static int __mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg, void *arg)
147 return ret; 147 return ret;
148} 148}
149 149
150struct omap_msg_tx_data {
151 mbox_msg_t msg;
152 void *arg;
153};
154
155static void omap_msg_tx_end_io(struct request *rq, int error)
156{
157 kfree(rq->special);
158 __blk_put_request(rq->q, rq);
159}
160
150int omap_mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg, void* arg) 161int omap_mbox_msg_send(struct omap_mbox *mbox, mbox_msg_t msg, void* arg)
151{ 162{
163 struct omap_msg_tx_data *tx_data;
152 struct request *rq; 164 struct request *rq;
153 struct request_queue *q = mbox->txq->queue; 165 struct request_queue *q = mbox->txq->queue;
154 int ret = 0; 166
167 tx_data = kmalloc(sizeof(*tx_data), GFP_ATOMIC);
168 if (unlikely(!tx_data))
169 return -ENOMEM;
155 170
156 rq = blk_get_request(q, WRITE, GFP_ATOMIC); 171 rq = blk_get_request(q, WRITE, GFP_ATOMIC);
157 if (unlikely(!rq)) { 172 if (unlikely(!rq)) {
158 ret = -ENOMEM; 173 kfree(tx_data);
159 goto fail; 174 return -ENOMEM;
160 } 175 }
161 176
162 rq->data = (void *)msg; 177 tx_data->msg = msg;
163 blk_insert_request(q, rq, 0, arg); 178 tx_data->arg = arg;
179 rq->end_io = omap_msg_tx_end_io;
180 blk_insert_request(q, rq, 0, tx_data);
164 181
165 schedule_work(&mbox->txq->work); 182 schedule_work(&mbox->txq->work);
166 fail: 183 return 0;
167 return ret;
168} 184}
169EXPORT_SYMBOL(omap_mbox_msg_send); 185EXPORT_SYMBOL(omap_mbox_msg_send);
170 186
@@ -178,22 +194,28 @@ static void mbox_tx_work(struct work_struct *work)
178 struct request_queue *q = mbox->txq->queue; 194 struct request_queue *q = mbox->txq->queue;
179 195
180 while (1) { 196 while (1) {
197 struct omap_msg_tx_data *tx_data;
198
181 spin_lock(q->queue_lock); 199 spin_lock(q->queue_lock);
182 rq = elv_next_request(q); 200 rq = blk_fetch_request(q);
183 spin_unlock(q->queue_lock); 201 spin_unlock(q->queue_lock);
184 202
185 if (!rq) 203 if (!rq)
186 break; 204 break;
187 205
188 ret = __mbox_msg_send(mbox, (mbox_msg_t) rq->data, rq->special); 206 tx_data = rq->special;
207
208 ret = __mbox_msg_send(mbox, tx_data->msg, tx_data->arg);
189 if (ret) { 209 if (ret) {
190 enable_mbox_irq(mbox, IRQ_TX); 210 enable_mbox_irq(mbox, IRQ_TX);
211 spin_lock(q->queue_lock);
212 blk_requeue_request(q, rq);
213 spin_unlock(q->queue_lock);
191 return; 214 return;
192 } 215 }
193 216
194 spin_lock(q->queue_lock); 217 spin_lock(q->queue_lock);
195 if (__blk_end_request(rq, 0, 0)) 218 __blk_end_request_all(rq, 0);
196 BUG();
197 spin_unlock(q->queue_lock); 219 spin_unlock(q->queue_lock);
198 } 220 }
199} 221}
@@ -218,16 +240,13 @@ static void mbox_rx_work(struct work_struct *work)
218 240
219 while (1) { 241 while (1) {
220 spin_lock_irqsave(q->queue_lock, flags); 242 spin_lock_irqsave(q->queue_lock, flags);
221 rq = elv_next_request(q); 243 rq = blk_fetch_request(q);
222 spin_unlock_irqrestore(q->queue_lock, flags); 244 spin_unlock_irqrestore(q->queue_lock, flags);
223 if (!rq) 245 if (!rq)
224 break; 246 break;
225 247
226 msg = (mbox_msg_t) rq->data; 248 msg = (mbox_msg_t)rq->special;
227 249 blk_end_request_all(rq, 0);
228 if (blk_end_request(rq, 0, 0))
229 BUG();
230
231 mbox->rxq->callback((void *)msg); 250 mbox->rxq->callback((void *)msg);
232 } 251 }
233} 252}
@@ -264,7 +283,6 @@ static void __mbox_rx_interrupt(struct omap_mbox *mbox)
264 goto nomem; 283 goto nomem;
265 284
266 msg = mbox_fifo_read(mbox); 285 msg = mbox_fifo_read(mbox);
267 rq->data = (void *)msg;
268 286
269 if (unlikely(mbox_seq_test(mbox, msg))) { 287 if (unlikely(mbox_seq_test(mbox, msg))) {
270 pr_info("mbox: Illegal seq bit!(%08x)\n", msg); 288 pr_info("mbox: Illegal seq bit!(%08x)\n", msg);
@@ -272,7 +290,7 @@ static void __mbox_rx_interrupt(struct omap_mbox *mbox)
272 mbox->err_notify(); 290 mbox->err_notify();
273 } 291 }
274 292
275 blk_insert_request(q, rq, 0, NULL); 293 blk_insert_request(q, rq, 0, (void *)msg);
276 if (mbox->ops->type == OMAP_MBOX_TYPE1) 294 if (mbox->ops->type == OMAP_MBOX_TYPE1)
277 break; 295 break;
278 } 296 }
@@ -329,16 +347,15 @@ omap_mbox_read(struct device *dev, struct device_attribute *attr, char *buf)
329 347
330 while (1) { 348 while (1) {
331 spin_lock_irqsave(q->queue_lock, flags); 349 spin_lock_irqsave(q->queue_lock, flags);
332 rq = elv_next_request(q); 350 rq = blk_fetch_request(q);
333 spin_unlock_irqrestore(q->queue_lock, flags); 351 spin_unlock_irqrestore(q->queue_lock, flags);
334 352
335 if (!rq) 353 if (!rq)
336 break; 354 break;
337 355
338 *p = (mbox_msg_t) rq->data; 356 *p = (mbox_msg_t)rq->special;
339 357
340 if (blk_end_request(rq, 0, 0)) 358 blk_end_request_all(rq, 0);
341 BUG();
342 359
343 if (unlikely(mbox_seq_test(mbox, *p))) { 360 if (unlikely(mbox_seq_test(mbox, *p))) {
344 pr_info("mbox: Illegal seq bit!(%08x) ignored\n", *p); 361 pr_info("mbox: Illegal seq bit!(%08x) ignored\n", *p);
diff --git a/arch/frv/Kconfig b/arch/frv/Kconfig
index 9d1552a9ee2c..8a5bd7a9c6f5 100644
--- a/arch/frv/Kconfig
+++ b/arch/frv/Kconfig
@@ -6,6 +6,7 @@ config FRV
6 bool 6 bool
7 default y 7 default y
8 select HAVE_IDE 8 select HAVE_IDE
9 select HAVE_ARCH_TRACEHOOK
9 10
10config ZONE_DMA 11config ZONE_DMA
11 bool 12 bool
diff --git a/arch/frv/include/asm/bitops.h b/arch/frv/include/asm/bitops.h
index 287f6f697ce2..50ae91b29674 100644
--- a/arch/frv/include/asm/bitops.h
+++ b/arch/frv/include/asm/bitops.h
@@ -112,7 +112,7 @@ extern unsigned long atomic_test_and_XOR_mask(unsigned long mask, volatile unsig
112#define atomic_clear_mask(mask, v) atomic_test_and_ANDNOT_mask((mask), (v)) 112#define atomic_clear_mask(mask, v) atomic_test_and_ANDNOT_mask((mask), (v))
113#define atomic_set_mask(mask, v) atomic_test_and_OR_mask((mask), (v)) 113#define atomic_set_mask(mask, v) atomic_test_and_OR_mask((mask), (v))
114 114
115static inline int test_and_clear_bit(int nr, volatile void *addr) 115static inline int test_and_clear_bit(unsigned long nr, volatile void *addr)
116{ 116{
117 volatile unsigned long *ptr = addr; 117 volatile unsigned long *ptr = addr;
118 unsigned long mask = 1UL << (nr & 31); 118 unsigned long mask = 1UL << (nr & 31);
@@ -120,7 +120,7 @@ static inline int test_and_clear_bit(int nr, volatile void *addr)
120 return (atomic_test_and_ANDNOT_mask(mask, ptr) & mask) != 0; 120 return (atomic_test_and_ANDNOT_mask(mask, ptr) & mask) != 0;
121} 121}
122 122
123static inline int test_and_set_bit(int nr, volatile void *addr) 123static inline int test_and_set_bit(unsigned long nr, volatile void *addr)
124{ 124{
125 volatile unsigned long *ptr = addr; 125 volatile unsigned long *ptr = addr;
126 unsigned long mask = 1UL << (nr & 31); 126 unsigned long mask = 1UL << (nr & 31);
@@ -128,7 +128,7 @@ static inline int test_and_set_bit(int nr, volatile void *addr)
128 return (atomic_test_and_OR_mask(mask, ptr) & mask) != 0; 128 return (atomic_test_and_OR_mask(mask, ptr) & mask) != 0;
129} 129}
130 130
131static inline int test_and_change_bit(int nr, volatile void *addr) 131static inline int test_and_change_bit(unsigned long nr, volatile void *addr)
132{ 132{
133 volatile unsigned long *ptr = addr; 133 volatile unsigned long *ptr = addr;
134 unsigned long mask = 1UL << (nr & 31); 134 unsigned long mask = 1UL << (nr & 31);
@@ -136,22 +136,22 @@ static inline int test_and_change_bit(int nr, volatile void *addr)
136 return (atomic_test_and_XOR_mask(mask, ptr) & mask) != 0; 136 return (atomic_test_and_XOR_mask(mask, ptr) & mask) != 0;
137} 137}
138 138
139static inline void clear_bit(int nr, volatile void *addr) 139static inline void clear_bit(unsigned long nr, volatile void *addr)
140{ 140{
141 test_and_clear_bit(nr, addr); 141 test_and_clear_bit(nr, addr);
142} 142}
143 143
144static inline void set_bit(int nr, volatile void *addr) 144static inline void set_bit(unsigned long nr, volatile void *addr)
145{ 145{
146 test_and_set_bit(nr, addr); 146 test_and_set_bit(nr, addr);
147} 147}
148 148
149static inline void change_bit(int nr, volatile void * addr) 149static inline void change_bit(unsigned long nr, volatile void *addr)
150{ 150{
151 test_and_change_bit(nr, addr); 151 test_and_change_bit(nr, addr);
152} 152}
153 153
154static inline void __clear_bit(int nr, volatile void * addr) 154static inline void __clear_bit(unsigned long nr, volatile void *addr)
155{ 155{
156 volatile unsigned long *a = addr; 156 volatile unsigned long *a = addr;
157 int mask; 157 int mask;
@@ -161,7 +161,7 @@ static inline void __clear_bit(int nr, volatile void * addr)
161 *a &= ~mask; 161 *a &= ~mask;
162} 162}
163 163
164static inline void __set_bit(int nr, volatile void * addr) 164static inline void __set_bit(unsigned long nr, volatile void *addr)
165{ 165{
166 volatile unsigned long *a = addr; 166 volatile unsigned long *a = addr;
167 int mask; 167 int mask;
@@ -171,7 +171,7 @@ static inline void __set_bit(int nr, volatile void * addr)
171 *a |= mask; 171 *a |= mask;
172} 172}
173 173
174static inline void __change_bit(int nr, volatile void *addr) 174static inline void __change_bit(unsigned long nr, volatile void *addr)
175{ 175{
176 volatile unsigned long *a = addr; 176 volatile unsigned long *a = addr;
177 int mask; 177 int mask;
@@ -181,7 +181,7 @@ static inline void __change_bit(int nr, volatile void *addr)
181 *a ^= mask; 181 *a ^= mask;
182} 182}
183 183
184static inline int __test_and_clear_bit(int nr, volatile void * addr) 184static inline int __test_and_clear_bit(unsigned long nr, volatile void *addr)
185{ 185{
186 volatile unsigned long *a = addr; 186 volatile unsigned long *a = addr;
187 int mask, retval; 187 int mask, retval;
@@ -193,7 +193,7 @@ static inline int __test_and_clear_bit(int nr, volatile void * addr)
193 return retval; 193 return retval;
194} 194}
195 195
196static inline int __test_and_set_bit(int nr, volatile void * addr) 196static inline int __test_and_set_bit(unsigned long nr, volatile void *addr)
197{ 197{
198 volatile unsigned long *a = addr; 198 volatile unsigned long *a = addr;
199 int mask, retval; 199 int mask, retval;
@@ -205,7 +205,7 @@ static inline int __test_and_set_bit(int nr, volatile void * addr)
205 return retval; 205 return retval;
206} 206}
207 207
208static inline int __test_and_change_bit(int nr, volatile void * addr) 208static inline int __test_and_change_bit(unsigned long nr, volatile void *addr)
209{ 209{
210 volatile unsigned long *a = addr; 210 volatile unsigned long *a = addr;
211 int mask, retval; 211 int mask, retval;
@@ -220,12 +220,13 @@ static inline int __test_and_change_bit(int nr, volatile void * addr)
220/* 220/*
221 * This routine doesn't need to be atomic. 221 * This routine doesn't need to be atomic.
222 */ 222 */
223static inline int __constant_test_bit(int nr, const volatile void * addr) 223static inline int
224__constant_test_bit(unsigned long nr, const volatile void *addr)
224{ 225{
225 return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0; 226 return ((1UL << (nr & 31)) & (((const volatile unsigned int *) addr)[nr >> 5])) != 0;
226} 227}
227 228
228static inline int __test_bit(int nr, const volatile void * addr) 229static inline int __test_bit(unsigned long nr, const volatile void *addr)
229{ 230{
230 int * a = (int *) addr; 231 int * a = (int *) addr;
231 int mask; 232 int mask;
diff --git a/arch/frv/include/asm/elf.h b/arch/frv/include/asm/elf.h
index 7279ec07d62e..7bbf6e47f8c8 100644
--- a/arch/frv/include/asm/elf.h
+++ b/arch/frv/include/asm/elf.h
@@ -116,6 +116,7 @@ do { \
116} while(0) 116} while(0)
117 117
118#define USE_ELF_CORE_DUMP 118#define USE_ELF_CORE_DUMP
119#define CORE_DUMP_USE_REGSET
119#define ELF_FDPIC_CORE_EFLAGS EF_FRV_FDPIC 120#define ELF_FDPIC_CORE_EFLAGS EF_FRV_FDPIC
120#define ELF_EXEC_PAGESIZE 16384 121#define ELF_EXEC_PAGESIZE 16384
121 122
diff --git a/arch/frv/include/asm/pci.h b/arch/frv/include/asm/pci.h
index 585d9b49949a..cc685e60b0f9 100644
--- a/arch/frv/include/asm/pci.h
+++ b/arch/frv/include/asm/pci.h
@@ -87,8 +87,7 @@ static inline void pci_dma_sync_single(struct pci_dev *hwdev,
87 dma_addr_t dma_handle, 87 dma_addr_t dma_handle,
88 size_t size, int direction) 88 size_t size, int direction)
89{ 89{
90 if (direction == PCI_DMA_NONE) 90 BUG_ON(direction == PCI_DMA_NONE);
91 BUG();
92 91
93 frv_cache_wback_inv((unsigned long)bus_to_virt(dma_handle), 92 frv_cache_wback_inv((unsigned long)bus_to_virt(dma_handle),
94 (unsigned long)bus_to_virt(dma_handle) + size); 93 (unsigned long)bus_to_virt(dma_handle) + size);
@@ -105,9 +104,7 @@ static inline void pci_dma_sync_sg(struct pci_dev *hwdev,
105 int nelems, int direction) 104 int nelems, int direction)
106{ 105{
107 int i; 106 int i;
108 107 BUG_ON(direction == PCI_DMA_NONE);
109 if (direction == PCI_DMA_NONE)
110 BUG();
111 108
112 for (i = 0; i < nelems; i++) 109 for (i = 0; i < nelems; i++)
113 frv_cache_wback_inv(sg_dma_address(&sg[i]), 110 frv_cache_wback_inv(sg_dma_address(&sg[i]),
diff --git a/arch/frv/include/asm/ptrace.h b/arch/frv/include/asm/ptrace.h
index cf6934012b64..a54b535c9e49 100644
--- a/arch/frv/include/asm/ptrace.h
+++ b/arch/frv/include/asm/ptrace.h
@@ -65,6 +65,8 @@
65#ifdef __KERNEL__ 65#ifdef __KERNEL__
66#ifndef __ASSEMBLY__ 66#ifndef __ASSEMBLY__
67 67
68struct task_struct;
69
68/* 70/*
69 * we dedicate GR28 to keeping a pointer to the current exception frame 71 * we dedicate GR28 to keeping a pointer to the current exception frame
70 * - gr28 is destroyed on entry to the kernel from userspace 72 * - gr28 is destroyed on entry to the kernel from userspace
@@ -73,11 +75,18 @@ register struct pt_regs *__frame asm("gr28");
73 75
74#define user_mode(regs) (!((regs)->psr & PSR_S)) 76#define user_mode(regs) (!((regs)->psr & PSR_S))
75#define instruction_pointer(regs) ((regs)->pc) 77#define instruction_pointer(regs) ((regs)->pc)
78#define user_stack_pointer(regs) ((regs)->sp)
76 79
77extern unsigned long user_stack(const struct pt_regs *); 80extern unsigned long user_stack(const struct pt_regs *);
78extern void show_regs(struct pt_regs *); 81extern void show_regs(struct pt_regs *);
79#define profile_pc(regs) ((regs)->pc) 82#define profile_pc(regs) ((regs)->pc)
80#endif 83
84#define task_pt_regs(task) ((task)->thread.frame0)
85
86#define arch_has_single_step() (1)
87extern void user_enable_single_step(struct task_struct *);
88extern void user_disable_single_step(struct task_struct *);
81 89
82#endif /* !__ASSEMBLY__ */ 90#endif /* !__ASSEMBLY__ */
91#endif /* __KERNEL__ */
83#endif /* _ASM_PTRACE_H */ 92#endif /* _ASM_PTRACE_H */
diff --git a/arch/frv/include/asm/syscall.h b/arch/frv/include/asm/syscall.h
new file mode 100644
index 000000000000..70689eb29b98
--- /dev/null
+++ b/arch/frv/include/asm/syscall.h
@@ -0,0 +1,123 @@
1/* syscall parameter access functions
2 *
3 * Copyright (C) 2009 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
10 */
11
12#ifndef _ASM_SYSCALL_H
13#define _ASM_SYSCALL_H
14
15#include <linux/err.h>
16#include <asm/ptrace.h>
17
18/*
19 * Get the system call number or -1
20 */
21static inline long syscall_get_nr(struct task_struct *task,
22 struct pt_regs *regs)
23{
24 return regs->syscallno;
25}
26
27/*
28 * Restore the clobbered GR8 register
29 * (1st syscall arg was overwritten with syscall return or error)
30 */
31static inline void syscall_rollback(struct task_struct *task,
32 struct pt_regs *regs)
33{
34 regs->gr8 = regs->orig_gr8;
35}
36
37/*
38 * See if the syscall return value is an error, returning it if it is and 0 if
39 * not
40 */
41static inline long syscall_get_error(struct task_struct *task,
42 struct pt_regs *regs)
43{
44 return IS_ERR_VALUE(regs->gr8) ? regs->gr8 : 0;
45}
46
47/*
48 * Get the syscall return value
49 */
50static inline long syscall_get_return_value(struct task_struct *task,
51 struct pt_regs *regs)
52{
53 return regs->gr8;
54}
55
56/*
57 * Set the syscall return value
58 */
59static inline void syscall_set_return_value(struct task_struct *task,
60 struct pt_regs *regs,
61 int error, long val)
62{
63 if (error)
64 regs->gr8 = -error;
65 else
66 regs->gr8 = val;
67}
68
69/*
70 * Retrieve the system call arguments
71 */
72static inline void syscall_get_arguments(struct task_struct *task,
73 struct pt_regs *regs,
74 unsigned int i, unsigned int n,
75 unsigned long *args)
76{
77 /*
78 * Do this simply for now. If we need to start supporting
79 * fetching arguments from arbitrary indices, this will need some
80 * extra logic. Presently there are no in-tree users that depend
81 * on this behaviour.
82 */
83 BUG_ON(i);
84
85 /* Argument pattern is: GR8, GR9, GR10, GR11, GR12, GR13 */
86 switch (n) {
87 case 6: args[5] = regs->gr13;
88 case 5: args[4] = regs->gr12;
89 case 4: args[3] = regs->gr11;
90 case 3: args[2] = regs->gr10;
91 case 2: args[1] = regs->gr9;
92 case 1: args[0] = regs->gr8;
93 break;
94 default:
95 BUG();
96 }
97}
98
99/*
100 * Alter the system call arguments
101 */
102static inline void syscall_set_arguments(struct task_struct *task,
103 struct pt_regs *regs,
104 unsigned int i, unsigned int n,
105 const unsigned long *args)
106{
107 /* Same note as above applies */
108 BUG_ON(i);
109
110 switch (n) {
111 case 6: regs->gr13 = args[5];
112 case 5: regs->gr12 = args[4];
113 case 4: regs->gr11 = args[3];
114 case 3: regs->gr10 = args[2];
115 case 2: regs->gr9 = args[1];
116 case 1: regs->gr8 = args[0];
117 break;
118 default:
119 BUG();
120 }
121}
122
123#endif /* _ASM_SYSCALL_H */
diff --git a/arch/frv/include/asm/thread_info.h b/arch/frv/include/asm/thread_info.h
index bb53ab753ffb..e8a5ed7be021 100644
--- a/arch/frv/include/asm/thread_info.h
+++ b/arch/frv/include/asm/thread_info.h
@@ -109,20 +109,20 @@ register struct thread_info *__current_thread_info asm("gr15");
109 * - other flags in MSW 109 * - other flags in MSW
110 */ 110 */
111#define TIF_SYSCALL_TRACE 0 /* syscall trace active */ 111#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
112#define TIF_SIGPENDING 1 /* signal pending */ 112#define TIF_NOTIFY_RESUME 1 /* callback before returning to user */
113#define TIF_NEED_RESCHED 2 /* rescheduling necessary */ 113#define TIF_SIGPENDING 2 /* signal pending */
114#define TIF_SINGLESTEP 3 /* restore singlestep on return to user mode */ 114#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
115#define TIF_IRET 4 /* return with iret */ 115#define TIF_SINGLESTEP 4 /* restore singlestep on return to user mode */
116#define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */ 116#define TIF_RESTORE_SIGMASK 5 /* restore signal mask in do_signal() */
117#define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */ 117#define TIF_POLLING_NRFLAG 16 /* true if poll_idle() is polling TIF_NEED_RESCHED */
118#define TIF_MEMDIE 17 /* OOM killer killed process */ 118#define TIF_MEMDIE 17 /* OOM killer killed process */
119#define TIF_FREEZE 18 /* freezing for suspend */ 119#define TIF_FREEZE 18 /* freezing for suspend */
120 120
121#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) 121#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
122#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
122#define _TIF_SIGPENDING (1 << TIF_SIGPENDING) 123#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
123#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED) 124#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
124#define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP) 125#define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP)
125#define _TIF_IRET (1 << TIF_IRET)
126#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK) 126#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
127#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG) 127#define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
128#define _TIF_FREEZE (1 << TIF_FREEZE) 128#define _TIF_FREEZE (1 << TIF_FREEZE)
diff --git a/arch/frv/kernel/entry.S b/arch/frv/kernel/entry.S
index 1da523b3298e..356e0e327a89 100644
--- a/arch/frv/kernel/entry.S
+++ b/arch/frv/kernel/entry.S
@@ -886,7 +886,6 @@ system_call:
886 bnc icc0,#0,__syscall_badsys 886 bnc icc0,#0,__syscall_badsys
887 887
888 ldi @(gr15,#TI_FLAGS),gr4 888 ldi @(gr15,#TI_FLAGS),gr4
889 ori gr4,#_TIF_SYSCALL_TRACE,gr4
890 andicc gr4,#_TIF_SYSCALL_TRACE,gr0,icc0 889 andicc gr4,#_TIF_SYSCALL_TRACE,gr0,icc0
891 bne icc0,#0,__syscall_trace_entry 890 bne icc0,#0,__syscall_trace_entry
892 891
@@ -1150,11 +1149,10 @@ __entry_work_notifysig:
1150 # perform syscall entry tracing 1149 # perform syscall entry tracing
1151__syscall_trace_entry: 1150__syscall_trace_entry:
1152 LEDS 0x6320 1151 LEDS 0x6320
1153 setlos.p #0,gr8 1152 call syscall_trace_entry
1154 call do_syscall_trace
1155 1153
1156 ldi @(gr28,#REG_SYSCALLNO),gr7 1154 lddi.p @(gr28,#REG_GR(8)) ,gr8
1157 lddi @(gr28,#REG_GR(8)) ,gr8 1155 ori gr8,#0,gr7 ; syscall_trace_entry() returned new syscallno
1158 lddi @(gr28,#REG_GR(10)),gr10 1156 lddi @(gr28,#REG_GR(10)),gr10
1159 lddi.p @(gr28,#REG_GR(12)),gr12 1157 lddi.p @(gr28,#REG_GR(12)),gr12
1160 1158
@@ -1169,11 +1167,10 @@ __syscall_exit_work:
1169 beq icc0,#1,__entry_work_pending 1167 beq icc0,#1,__entry_work_pending
1170 1168
1171 movsg psr,gr23 1169 movsg psr,gr23
1172 andi gr23,#~PSR_PIL,gr23 ; could let do_syscall_trace() call schedule() 1170 andi gr23,#~PSR_PIL,gr23 ; could let syscall_trace_exit() call schedule()
1173 movgs gr23,psr 1171 movgs gr23,psr
1174 1172
1175 setlos.p #1,gr8 1173 call syscall_trace_exit
1176 call do_syscall_trace
1177 bra __entry_resume_userspace 1174 bra __entry_resume_userspace
1178 1175
1179__syscall_badsys: 1176__syscall_badsys:
diff --git a/arch/frv/kernel/ptrace.c b/arch/frv/kernel/ptrace.c
index 5e7d401d21e7..60eeed3694c0 100644
--- a/arch/frv/kernel/ptrace.c
+++ b/arch/frv/kernel/ptrace.c
@@ -19,6 +19,9 @@
19#include <linux/user.h> 19#include <linux/user.h>
20#include <linux/security.h> 20#include <linux/security.h>
21#include <linux/signal.h> 21#include <linux/signal.h>
22#include <linux/regset.h>
23#include <linux/elf.h>
24#include <linux/tracehook.h>
22 25
23#include <asm/uaccess.h> 26#include <asm/uaccess.h>
24#include <asm/page.h> 27#include <asm/page.h>
@@ -33,6 +36,169 @@
33 */ 36 */
34 37
35/* 38/*
39 * retrieve the contents of FRV userspace general registers
40 */
41static int genregs_get(struct task_struct *target,
42 const struct user_regset *regset,
43 unsigned int pos, unsigned int count,
44 void *kbuf, void __user *ubuf)
45{
46 const struct user_int_regs *iregs = &target->thread.user->i;
47 int ret;
48
49 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
50 iregs, 0, sizeof(*iregs));
51 if (ret < 0)
52 return ret;
53
54 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
55 sizeof(*iregs), -1);
56}
57
58/*
59 * update the contents of the FRV userspace general registers
60 */
61static int genregs_set(struct task_struct *target,
62 const struct user_regset *regset,
63 unsigned int pos, unsigned int count,
64 const void *kbuf, const void __user *ubuf)
65{
66 struct user_int_regs *iregs = &target->thread.user->i;
67 unsigned int offs_gr0, offs_gr1;
68 int ret;
69
70 /* not allowed to set PSR or __status */
71 if (pos < offsetof(struct user_int_regs, psr) + sizeof(long) &&
72 pos + count > offsetof(struct user_int_regs, psr))
73 return -EIO;
74
75 if (pos < offsetof(struct user_int_regs, __status) + sizeof(long) &&
76 pos + count > offsetof(struct user_int_regs, __status))
77 return -EIO;
78
79 /* set the control regs */
80 offs_gr0 = offsetof(struct user_int_regs, gr[0]);
81 offs_gr1 = offsetof(struct user_int_regs, gr[1]);
82 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
83 iregs, 0, offs_gr0);
84 if (ret < 0)
85 return ret;
86
87 /* skip GR0/TBR */
88 ret = user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
89 offs_gr0, offs_gr1);
90 if (ret < 0)
91 return ret;
92
93 /* set the general regs */
94 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
95 &iregs->gr[1], offs_gr1, sizeof(*iregs));
96 if (ret < 0)
97 return ret;
98
99 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
100 sizeof(*iregs), -1);
101}
102
103/*
104 * retrieve the contents of FRV userspace FP/Media registers
105 */
106static int fpmregs_get(struct task_struct *target,
107 const struct user_regset *regset,
108 unsigned int pos, unsigned int count,
109 void *kbuf, void __user *ubuf)
110{
111 const struct user_fpmedia_regs *fpregs = &target->thread.user->f;
112 int ret;
113
114 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
115 fpregs, 0, sizeof(*fpregs));
116 if (ret < 0)
117 return ret;
118
119 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
120 sizeof(*fpregs), -1);
121}
122
123/*
124 * update the contents of the FRV userspace FP/Media registers
125 */
126static int fpmregs_set(struct task_struct *target,
127 const struct user_regset *regset,
128 unsigned int pos, unsigned int count,
129 const void *kbuf, const void __user *ubuf)
130{
131 struct user_fpmedia_regs *fpregs = &target->thread.user->f;
132 int ret;
133
134 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
135 fpregs, 0, sizeof(*fpregs));
136 if (ret < 0)
137 return ret;
138
139 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
140 sizeof(*fpregs), -1);
141}
142
143/*
144 * determine if the FP/Media registers have actually been used
145 */
146static int fpmregs_active(struct task_struct *target,
147 const struct user_regset *regset)
148{
149 return tsk_used_math(target) ? regset->n : 0;
150}
151
152/*
153 * Define the register sets available on the FRV under Linux
154 */
155enum frv_regset {
156 REGSET_GENERAL,
157 REGSET_FPMEDIA,
158};
159
160static const struct user_regset frv_regsets[] = {
161 /*
162 * General register format is:
163 * PSR, ISR, CCR, CCCR, LR, LCR, PC, (STATUS), SYSCALLNO, ORIG_G8
164 * GNER0-1, IACC0, TBR, GR1-63
165 */
166 [REGSET_GENERAL] = {
167 .core_note_type = NT_PRSTATUS,
168 .n = ELF_NGREG,
169 .size = sizeof(long),
170 .align = sizeof(long),
171 .get = genregs_get,
172 .set = genregs_set,
173 },
174 /*
175 * FPU/Media register format is:
176 * FR0-63, FNER0-1, MSR0-1, ACC0-7, ACCG0-8, FSR
177 */
178 [REGSET_FPMEDIA] = {
179 .core_note_type = NT_PRFPREG,
180 .n = sizeof(struct user_fpmedia_regs) / sizeof(long),
181 .size = sizeof(long),
182 .align = sizeof(long),
183 .get = fpmregs_get,
184 .set = fpmregs_set,
185 .active = fpmregs_active,
186 },
187};
188
189static const struct user_regset_view user_frv_native_view = {
190 .name = "frv",
191 .e_machine = EM_FRV,
192 .regsets = frv_regsets,
193 .n = ARRAY_SIZE(frv_regsets),
194};
195
196const struct user_regset_view *task_user_regset_view(struct task_struct *task)
197{
198 return &user_frv_native_view;
199}
200
201/*
36 * Get contents of register REGNO in task TASK. 202 * Get contents of register REGNO in task TASK.
37 */ 203 */
38static inline long get_reg(struct task_struct *task, int regno) 204static inline long get_reg(struct task_struct *task, int regno)
@@ -69,40 +235,23 @@ static inline int put_reg(struct task_struct *task, int regno,
69} 235}
70 236
71/* 237/*
72 * check that an address falls within the bounds of the target process's memory
73 * mappings
74 */
75static inline int is_user_addr_valid(struct task_struct *child,
76 unsigned long start, unsigned long len)
77{
78#ifdef CONFIG_MMU
79 if (start >= PAGE_OFFSET || len > PAGE_OFFSET - start)
80 return -EIO;
81 return 0;
82#else
83 struct vm_area_struct *vma;
84
85 vma = find_vma(child->mm, start);
86 if (vma && start >= vma->vm_start && start + len <= vma->vm_end)
87 return 0;
88
89 return -EIO;
90#endif
91}
92
93/*
94 * Called by kernel/ptrace.c when detaching.. 238 * Called by kernel/ptrace.c when detaching..
95 * 239 *
96 * Control h/w single stepping 240 * Control h/w single stepping
97 */ 241 */
98void ptrace_disable(struct task_struct *child) 242void user_enable_single_step(struct task_struct *child)
243{
244 child->thread.frame0->__status |= REG__STATUS_STEP;
245}
246
247void user_disable_single_step(struct task_struct *child)
99{ 248{
100 child->thread.frame0->__status &= ~REG__STATUS_STEP; 249 child->thread.frame0->__status &= ~REG__STATUS_STEP;
101} 250}
102 251
103void ptrace_enable(struct task_struct *child) 252void ptrace_disable(struct task_struct *child)
104{ 253{
105 child->thread.frame0->__status |= REG__STATUS_STEP; 254 user_disable_single_step(child);
106} 255}
107 256
108long arch_ptrace(struct task_struct *child, long request, long addr, long data) 257long arch_ptrace(struct task_struct *child, long request, long addr, long data)
@@ -111,15 +260,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
111 int ret; 260 int ret;
112 261
113 switch (request) { 262 switch (request) {
114 /* when I and D space are separate, these will need to be fixed. */
115 case PTRACE_PEEKTEXT: /* read word at location addr. */
116 case PTRACE_PEEKDATA:
117 ret = -EIO;
118 if (is_user_addr_valid(child, addr, sizeof(tmp)) < 0)
119 break;
120 ret = generic_ptrace_peekdata(child, addr, data);
121 break;
122
123 /* read the word at location addr in the USER area. */ 263 /* read the word at location addr in the USER area. */
124 case PTRACE_PEEKUSR: { 264 case PTRACE_PEEKUSR: {
125 tmp = 0; 265 tmp = 0;
@@ -163,15 +303,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
163 break; 303 break;
164 } 304 }
165 305
166 /* when I and D space are separate, this will have to be fixed. */
167 case PTRACE_POKETEXT: /* write the word at location addr. */
168 case PTRACE_POKEDATA:
169 ret = -EIO;
170 if (is_user_addr_valid(child, addr, sizeof(tmp)) < 0)
171 break;
172 ret = generic_ptrace_pokedata(child, addr, data);
173 break;
174
175 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */ 306 case PTRACE_POKEUSR: /* write the word at location addr in the USER area */
176 ret = -EIO; 307 ret = -EIO;
177 if ((addr & 3) || addr < 0) 308 if ((addr & 3) || addr < 0)
@@ -179,7 +310,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
179 310
180 ret = 0; 311 ret = 0;
181 switch (addr >> 2) { 312 switch (addr >> 2) {
182 case 0 ... PT__END-1: 313 case 0 ... PT__END - 1:
183 ret = put_reg(child, addr >> 2, data); 314 ret = put_reg(child, addr >> 2, data);
184 break; 315 break;
185 316
@@ -189,95 +320,29 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
189 } 320 }
190 break; 321 break;
191 322
192 case PTRACE_SYSCALL: /* continue and stop at next (return from) syscall */ 323 case PTRACE_GETREGS: /* Get all integer regs from the child. */
193 case PTRACE_CONT: /* restart after signal. */ 324 return copy_regset_to_user(child, &user_frv_native_view,
194 ret = -EIO; 325 REGSET_GENERAL,
195 if (!valid_signal(data)) 326 0, sizeof(child->thread.user->i),
196 break; 327 (void __user *)data);
197 if (request == PTRACE_SYSCALL) 328
198 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE); 329 case PTRACE_SETREGS: /* Set all integer regs in the child. */
199 else 330 return copy_regset_from_user(child, &user_frv_native_view,
200 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); 331 REGSET_GENERAL,
201 child->exit_code = data; 332 0, sizeof(child->thread.user->i),
202 ptrace_disable(child); 333 (const void __user *)data);
203 wake_up_process(child); 334
204 ret = 0; 335 case PTRACE_GETFPREGS: /* Get the child FP/Media state. */
205 break; 336 return copy_regset_to_user(child, &user_frv_native_view,
206 337 REGSET_FPMEDIA,
207 /* make the child exit. Best I can do is send it a sigkill. 338 0, sizeof(child->thread.user->f),
208 * perhaps it should be put in the status that it wants to 339 (void __user *)data);
209 * exit. 340
210 */ 341 case PTRACE_SETFPREGS: /* Set the child FP/Media state. */
211 case PTRACE_KILL: 342 return copy_regset_from_user(child, &user_frv_native_view,
212 ret = 0; 343 REGSET_FPMEDIA,
213 if (child->exit_state == EXIT_ZOMBIE) /* already dead */ 344 0, sizeof(child->thread.user->f),
214 break; 345 (const void __user *)data);
215 child->exit_code = SIGKILL;
216 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
217 ptrace_disable(child);
218 wake_up_process(child);
219 break;
220
221 case PTRACE_SINGLESTEP: /* set the trap flag. */
222 ret = -EIO;
223 if (!valid_signal(data))
224 break;
225 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
226 ptrace_enable(child);
227 child->exit_code = data;
228 wake_up_process(child);
229 ret = 0;
230 break;
231
232 case PTRACE_DETACH: /* detach a process that was attached. */
233 ret = ptrace_detach(child, data);
234 break;
235
236 case PTRACE_GETREGS: { /* Get all integer regs from the child. */
237 int i;
238 for (i = 0; i < PT__GPEND; i++) {
239 tmp = get_reg(child, i);
240 if (put_user(tmp, (unsigned long *) data)) {
241 ret = -EFAULT;
242 break;
243 }
244 data += sizeof(long);
245 }
246 ret = 0;
247 break;
248 }
249
250 case PTRACE_SETREGS: { /* Set all integer regs in the child. */
251 int i;
252 for (i = 0; i < PT__GPEND; i++) {
253 if (get_user(tmp, (unsigned long *) data)) {
254 ret = -EFAULT;
255 break;
256 }
257 put_reg(child, i, tmp);
258 data += sizeof(long);
259 }
260 ret = 0;
261 break;
262 }
263
264 case PTRACE_GETFPREGS: { /* Get the child FP/Media state. */
265 ret = 0;
266 if (copy_to_user((void *) data,
267 &child->thread.user->f,
268 sizeof(child->thread.user->f)))
269 ret = -EFAULT;
270 break;
271 }
272
273 case PTRACE_SETFPREGS: { /* Set the child FP/Media state. */
274 ret = 0;
275 if (copy_from_user(&child->thread.user->f,
276 (void *) data,
277 sizeof(child->thread.user->f)))
278 ret = -EFAULT;
279 break;
280 }
281 346
282 case PTRACE_GETFDPIC: 347 case PTRACE_GETFDPIC:
283 tmp = 0; 348 tmp = 0;
@@ -300,414 +365,36 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
300 break; 365 break;
301 366
302 default: 367 default:
303 ret = -EIO; 368 ret = ptrace_request(child, request, addr, data);
304 break; 369 break;
305 } 370 }
306 return ret; 371 return ret;
307} 372}
308 373
309int __nongprelbss kstrace; 374/*
310 375 * handle tracing of system call entry
311static const struct { 376 * - return the revised system call number or ULONG_MAX to cause ENOSYS
312 const char *name; 377 */
313 unsigned argmask; 378asmlinkage unsigned long syscall_trace_entry(void)
314} __syscall_name_table[NR_syscalls] = {
315 [0] = { "restart_syscall" },
316 [1] = { "exit", 0x000001 },
317 [2] = { "fork", 0xffffff },
318 [3] = { "read", 0x000141 },
319 [4] = { "write", 0x000141 },
320 [5] = { "open", 0x000235 },
321 [6] = { "close", 0x000001 },
322 [7] = { "waitpid", 0x000141 },
323 [8] = { "creat", 0x000025 },
324 [9] = { "link", 0x000055 },
325 [10] = { "unlink", 0x000005 },
326 [11] = { "execve", 0x000445 },
327 [12] = { "chdir", 0x000005 },
328 [13] = { "time", 0x000004 },
329 [14] = { "mknod", 0x000325 },
330 [15] = { "chmod", 0x000025 },
331 [16] = { "lchown", 0x000025 },
332 [17] = { "break" },
333 [18] = { "oldstat", 0x000045 },
334 [19] = { "lseek", 0x000131 },
335 [20] = { "getpid", 0xffffff },
336 [21] = { "mount", 0x043555 },
337 [22] = { "umount", 0x000005 },
338 [23] = { "setuid", 0x000001 },
339 [24] = { "getuid", 0xffffff },
340 [25] = { "stime", 0x000004 },
341 [26] = { "ptrace", 0x004413 },
342 [27] = { "alarm", 0x000001 },
343 [28] = { "oldfstat", 0x000041 },
344 [29] = { "pause", 0xffffff },
345 [30] = { "utime", 0x000045 },
346 [31] = { "stty" },
347 [32] = { "gtty" },
348 [33] = { "access", 0x000025 },
349 [34] = { "nice", 0x000001 },
350 [35] = { "ftime" },
351 [36] = { "sync", 0xffffff },
352 [37] = { "kill", 0x000011 },
353 [38] = { "rename", 0x000055 },
354 [39] = { "mkdir", 0x000025 },
355 [40] = { "rmdir", 0x000005 },
356 [41] = { "dup", 0x000001 },
357 [42] = { "pipe", 0x000004 },
358 [43] = { "times", 0x000004 },
359 [44] = { "prof" },
360 [45] = { "brk", 0x000004 },
361 [46] = { "setgid", 0x000001 },
362 [47] = { "getgid", 0xffffff },
363 [48] = { "signal", 0x000041 },
364 [49] = { "geteuid", 0xffffff },
365 [50] = { "getegid", 0xffffff },
366 [51] = { "acct", 0x000005 },
367 [52] = { "umount2", 0x000035 },
368 [53] = { "lock" },
369 [54] = { "ioctl", 0x000331 },
370 [55] = { "fcntl", 0x000331 },
371 [56] = { "mpx" },
372 [57] = { "setpgid", 0x000011 },
373 [58] = { "ulimit" },
374 [60] = { "umask", 0x000002 },
375 [61] = { "chroot", 0x000005 },
376 [62] = { "ustat", 0x000043 },
377 [63] = { "dup2", 0x000011 },
378 [64] = { "getppid", 0xffffff },
379 [65] = { "getpgrp", 0xffffff },
380 [66] = { "setsid", 0xffffff },
381 [67] = { "sigaction" },
382 [68] = { "sgetmask" },
383 [69] = { "ssetmask" },
384 [70] = { "setreuid" },
385 [71] = { "setregid" },
386 [72] = { "sigsuspend" },
387 [73] = { "sigpending" },
388 [74] = { "sethostname" },
389 [75] = { "setrlimit" },
390 [76] = { "getrlimit" },
391 [77] = { "getrusage" },
392 [78] = { "gettimeofday" },
393 [79] = { "settimeofday" },
394 [80] = { "getgroups" },
395 [81] = { "setgroups" },
396 [82] = { "select" },
397 [83] = { "symlink" },
398 [84] = { "oldlstat" },
399 [85] = { "readlink" },
400 [86] = { "uselib" },
401 [87] = { "swapon" },
402 [88] = { "reboot" },
403 [89] = { "readdir" },
404 [91] = { "munmap", 0x000034 },
405 [92] = { "truncate" },
406 [93] = { "ftruncate" },
407 [94] = { "fchmod" },
408 [95] = { "fchown" },
409 [96] = { "getpriority" },
410 [97] = { "setpriority" },
411 [99] = { "statfs" },
412 [100] = { "fstatfs" },
413 [102] = { "socketcall" },
414 [103] = { "syslog" },
415 [104] = { "setitimer" },
416 [105] = { "getitimer" },
417 [106] = { "stat" },
418 [107] = { "lstat" },
419 [108] = { "fstat" },
420 [111] = { "vhangup" },
421 [114] = { "wait4" },
422 [115] = { "swapoff" },
423 [116] = { "sysinfo" },
424 [117] = { "ipc" },
425 [118] = { "fsync" },
426 [119] = { "sigreturn" },
427 [120] = { "clone" },
428 [121] = { "setdomainname" },
429 [122] = { "uname" },
430 [123] = { "modify_ldt" },
431 [123] = { "cacheflush" },
432 [124] = { "adjtimex" },
433 [125] = { "mprotect" },
434 [126] = { "sigprocmask" },
435 [127] = { "create_module" },
436 [128] = { "init_module" },
437 [129] = { "delete_module" },
438 [130] = { "get_kernel_syms" },
439 [131] = { "quotactl" },
440 [132] = { "getpgid" },
441 [133] = { "fchdir" },
442 [134] = { "bdflush" },
443 [135] = { "sysfs" },
444 [136] = { "personality" },
445 [137] = { "afs_syscall" },
446 [138] = { "setfsuid" },
447 [139] = { "setfsgid" },
448 [140] = { "_llseek", 0x014331 },
449 [141] = { "getdents" },
450 [142] = { "_newselect", 0x000141 },
451 [143] = { "flock" },
452 [144] = { "msync" },
453 [145] = { "readv" },
454 [146] = { "writev" },
455 [147] = { "getsid", 0x000001 },
456 [148] = { "fdatasync", 0x000001 },
457 [149] = { "_sysctl", 0x000004 },
458 [150] = { "mlock" },
459 [151] = { "munlock" },
460 [152] = { "mlockall" },
461 [153] = { "munlockall" },
462 [154] = { "sched_setparam" },
463 [155] = { "sched_getparam" },
464 [156] = { "sched_setscheduler" },
465 [157] = { "sched_getscheduler" },
466 [158] = { "sched_yield" },
467 [159] = { "sched_get_priority_max" },
468 [160] = { "sched_get_priority_min" },
469 [161] = { "sched_rr_get_interval" },
470 [162] = { "nanosleep", 0x000044 },
471 [163] = { "mremap" },
472 [164] = { "setresuid" },
473 [165] = { "getresuid" },
474 [166] = { "vm86" },
475 [167] = { "query_module" },
476 [168] = { "poll" },
477 [169] = { "nfsservctl" },
478 [170] = { "setresgid" },
479 [171] = { "getresgid" },
480 [172] = { "prctl", 0x333331 },
481 [173] = { "rt_sigreturn", 0xffffff },
482 [174] = { "rt_sigaction", 0x001441 },
483 [175] = { "rt_sigprocmask", 0x001441 },
484 [176] = { "rt_sigpending", 0x000014 },
485 [177] = { "rt_sigtimedwait", 0x001444 },
486 [178] = { "rt_sigqueueinfo", 0x000411 },
487 [179] = { "rt_sigsuspend", 0x000014 },
488 [180] = { "pread", 0x003341 },
489 [181] = { "pwrite", 0x003341 },
490 [182] = { "chown", 0x000115 },
491 [183] = { "getcwd" },
492 [184] = { "capget" },
493 [185] = { "capset" },
494 [186] = { "sigaltstack" },
495 [187] = { "sendfile" },
496 [188] = { "getpmsg" },
497 [189] = { "putpmsg" },
498 [190] = { "vfork", 0xffffff },
499 [191] = { "ugetrlimit" },
500 [192] = { "mmap2", 0x313314 },
501 [193] = { "truncate64" },
502 [194] = { "ftruncate64" },
503 [195] = { "stat64", 0x000045 },
504 [196] = { "lstat64", 0x000045 },
505 [197] = { "fstat64", 0x000041 },
506 [198] = { "lchown32" },
507 [199] = { "getuid32", 0xffffff },
508 [200] = { "getgid32", 0xffffff },
509 [201] = { "geteuid32", 0xffffff },
510 [202] = { "getegid32", 0xffffff },
511 [203] = { "setreuid32" },
512 [204] = { "setregid32" },
513 [205] = { "getgroups32" },
514 [206] = { "setgroups32" },
515 [207] = { "fchown32" },
516 [208] = { "setresuid32" },
517 [209] = { "getresuid32" },
518 [210] = { "setresgid32" },
519 [211] = { "getresgid32" },
520 [212] = { "chown32" },
521 [213] = { "setuid32" },
522 [214] = { "setgid32" },
523 [215] = { "setfsuid32" },
524 [216] = { "setfsgid32" },
525 [217] = { "pivot_root" },
526 [218] = { "mincore" },
527 [219] = { "madvise" },
528 [220] = { "getdents64" },
529 [221] = { "fcntl64" },
530 [223] = { "security" },
531 [224] = { "gettid" },
532 [225] = { "readahead" },
533 [226] = { "setxattr" },
534 [227] = { "lsetxattr" },
535 [228] = { "fsetxattr" },
536 [229] = { "getxattr" },
537 [230] = { "lgetxattr" },
538 [231] = { "fgetxattr" },
539 [232] = { "listxattr" },
540 [233] = { "llistxattr" },
541 [234] = { "flistxattr" },
542 [235] = { "removexattr" },
543 [236] = { "lremovexattr" },
544 [237] = { "fremovexattr" },
545 [238] = { "tkill" },
546 [239] = { "sendfile64" },
547 [240] = { "futex" },
548 [241] = { "sched_setaffinity" },
549 [242] = { "sched_getaffinity" },
550 [243] = { "set_thread_area" },
551 [244] = { "get_thread_area" },
552 [245] = { "io_setup" },
553 [246] = { "io_destroy" },
554 [247] = { "io_getevents" },
555 [248] = { "io_submit" },
556 [249] = { "io_cancel" },
557 [250] = { "fadvise64" },
558 [252] = { "exit_group", 0x000001 },
559 [253] = { "lookup_dcookie" },
560 [254] = { "epoll_create" },
561 [255] = { "epoll_ctl" },
562 [256] = { "epoll_wait" },
563 [257] = { "remap_file_pages" },
564 [258] = { "set_tid_address" },
565 [259] = { "timer_create" },
566 [260] = { "timer_settime" },
567 [261] = { "timer_gettime" },
568 [262] = { "timer_getoverrun" },
569 [263] = { "timer_delete" },
570 [264] = { "clock_settime" },
571 [265] = { "clock_gettime" },
572 [266] = { "clock_getres" },
573 [267] = { "clock_nanosleep" },
574 [268] = { "statfs64" },
575 [269] = { "fstatfs64" },
576 [270] = { "tgkill" },
577 [271] = { "utimes" },
578 [272] = { "fadvise64_64" },
579 [273] = { "vserver" },
580 [274] = { "mbind" },
581 [275] = { "get_mempolicy" },
582 [276] = { "set_mempolicy" },
583 [277] = { "mq_open" },
584 [278] = { "mq_unlink" },
585 [279] = { "mq_timedsend" },
586 [280] = { "mq_timedreceive" },
587 [281] = { "mq_notify" },
588 [282] = { "mq_getsetattr" },
589 [283] = { "sys_kexec_load" },
590};
591
592asmlinkage void do_syscall_trace(int leaving)
593{ 379{
594#if 0 380 __frame->__status |= REG__STATUS_SYSC_ENTRY;
595 unsigned long *argp; 381 if (tracehook_report_syscall_entry(__frame)) {
596 const char *name; 382 /* tracing decided this syscall should not happen, so
597 unsigned argmask; 383 * We'll return a bogus call number to get an ENOSYS
598 char buffer[16]; 384 * error, but leave the original number in
599 385 * __frame->syscallno
600 if (!kstrace) 386 */
601 return; 387 return ULONG_MAX;
602
603 if (!current->mm)
604 return;
605
606 if (__frame->gr7 == __NR_close)
607 return;
608
609#if 0
610 if (__frame->gr7 != __NR_mmap2 &&
611 __frame->gr7 != __NR_vfork &&
612 __frame->gr7 != __NR_execve &&
613 __frame->gr7 != __NR_exit)
614 return;
615#endif
616
617 argmask = 0;
618 name = NULL;
619 if (__frame->gr7 < NR_syscalls) {
620 name = __syscall_name_table[__frame->gr7].name;
621 argmask = __syscall_name_table[__frame->gr7].argmask;
622 }
623 if (!name) {
624 sprintf(buffer, "sys_%lx", __frame->gr7);
625 name = buffer;
626 }
627
628 if (!leaving) {
629 if (!argmask) {
630 printk(KERN_CRIT "[%d] %s(%lx,%lx,%lx,%lx,%lx,%lx)\n",
631 current->pid,
632 name,
633 __frame->gr8,
634 __frame->gr9,
635 __frame->gr10,
636 __frame->gr11,
637 __frame->gr12,
638 __frame->gr13);
639 }
640 else if (argmask == 0xffffff) {
641 printk(KERN_CRIT "[%d] %s()\n",
642 current->pid,
643 name);
644 }
645 else {
646 printk(KERN_CRIT "[%d] %s(",
647 current->pid,
648 name);
649
650 argp = &__frame->gr8;
651
652 do {
653 switch (argmask & 0xf) {
654 case 1:
655 printk("%ld", (long) *argp);
656 break;
657 case 2:
658 printk("%lo", *argp);
659 break;
660 case 3:
661 printk("%lx", *argp);
662 break;
663 case 4:
664 printk("%p", (void *) *argp);
665 break;
666 case 5:
667 printk("\"%s\"", (char *) *argp);
668 break;
669 }
670
671 argp++;
672 argmask >>= 4;
673 if (argmask)
674 printk(",");
675
676 } while (argmask);
677
678 printk(")\n");
679 }
680 }
681 else {
682 if ((int)__frame->gr8 > -4096 && (int)__frame->gr8 < 4096)
683 printk(KERN_CRIT "[%d] %s() = %ld\n", current->pid, name, __frame->gr8);
684 else
685 printk(KERN_CRIT "[%d] %s() = %lx\n", current->pid, name, __frame->gr8);
686 } 388 }
687 return;
688#endif
689
690 if (!test_thread_flag(TIF_SYSCALL_TRACE))
691 return;
692
693 if (!(current->ptrace & PT_PTRACED))
694 return;
695 389
696 /* we need to indicate entry or exit to strace */ 390 return __frame->syscallno;
697 if (leaving) 391}
698 __frame->__status |= REG__STATUS_SYSC_EXIT;
699 else
700 __frame->__status |= REG__STATUS_SYSC_ENTRY;
701
702 ptrace_notify(SIGTRAP);
703 392
704 /* 393/*
705 * this isn't the same as continuing with a signal, but it will do 394 * handle tracing of system call exit
706 * for normal use. strace only continues with a signal if the 395 */
707 * stopping signal is not SIGTRAP. -brl 396asmlinkage void syscall_trace_exit(void)
708 */ 397{
709 if (current->exit_code) { 398 __frame->__status |= REG__STATUS_SYSC_EXIT;
710 send_sig(current->exit_code, current, 1); 399 tracehook_report_syscall_exit(__frame, 0);
711 current->exit_code = 0;
712 }
713} 400}
diff --git a/arch/frv/kernel/signal.c b/arch/frv/kernel/signal.c
index 3bdb368292a8..4a7a62c6e783 100644
--- a/arch/frv/kernel/signal.c
+++ b/arch/frv/kernel/signal.c
@@ -21,6 +21,7 @@
21#include <linux/unistd.h> 21#include <linux/unistd.h>
22#include <linux/personality.h> 22#include <linux/personality.h>
23#include <linux/freezer.h> 23#include <linux/freezer.h>
24#include <linux/tracehook.h>
24#include <asm/ucontext.h> 25#include <asm/ucontext.h>
25#include <asm/uaccess.h> 26#include <asm/uaccess.h>
26#include <asm/cacheflush.h> 27#include <asm/cacheflush.h>
@@ -516,6 +517,9 @@ static void do_signal(void)
516 * clear the TIF_RESTORE_SIGMASK flag */ 517 * clear the TIF_RESTORE_SIGMASK flag */
517 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 518 if (test_thread_flag(TIF_RESTORE_SIGMASK))
518 clear_thread_flag(TIF_RESTORE_SIGMASK); 519 clear_thread_flag(TIF_RESTORE_SIGMASK);
520
521 tracehook_signal_handler(signr, &info, &ka, __frame,
522 test_thread_flag(TIF_SINGLESTEP));
519 } 523 }
520 524
521 return; 525 return;
@@ -564,4 +568,10 @@ asmlinkage void do_notify_resume(__u32 thread_info_flags)
564 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 568 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
565 do_signal(); 569 do_signal();
566 570
571 /* deal with notification on about to resume userspace execution */
572 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
573 clear_thread_flag(TIF_NOTIFY_RESUME);
574 tracehook_notify_resume(__frame);
575 }
576
567} /* end do_notify_resume() */ 577} /* end do_notify_resume() */
diff --git a/arch/frv/kernel/uaccess.c b/arch/frv/kernel/uaccess.c
index 9fb771a20df3..374f88d6cc00 100644
--- a/arch/frv/kernel/uaccess.c
+++ b/arch/frv/kernel/uaccess.c
@@ -23,8 +23,7 @@ long strncpy_from_user(char *dst, const char __user *src, long count)
23 char *p, ch; 23 char *p, ch;
24 long err = -EFAULT; 24 long err = -EFAULT;
25 25
26 if (count < 0) 26 BUG_ON(count < 0);
27 BUG();
28 27
29 p = dst; 28 p = dst;
30 29
@@ -76,8 +75,7 @@ long strnlen_user(const char __user *src, long count)
76 long err = 0; 75 long err = 0;
77 char ch; 76 char ch;
78 77
79 if (count < 0) 78 BUG_ON(count < 0);
80 BUG();
81 79
82#ifndef CONFIG_MMU 80#ifndef CONFIG_MMU
83 if ((unsigned long) src < memory_start) 81 if ((unsigned long) src < memory_start)
diff --git a/arch/frv/mb93090-mb00/pci-dma-nommu.c b/arch/frv/mb93090-mb00/pci-dma-nommu.c
index 52ff9aec799d..4e1ba0b15443 100644
--- a/arch/frv/mb93090-mb00/pci-dma-nommu.c
+++ b/arch/frv/mb93090-mb00/pci-dma-nommu.c
@@ -116,8 +116,7 @@ EXPORT_SYMBOL(dma_free_coherent);
116dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size, 116dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
117 enum dma_data_direction direction) 117 enum dma_data_direction direction)
118{ 118{
119 if (direction == DMA_NONE) 119 BUG_ON(direction == DMA_NONE);
120 BUG();
121 120
122 frv_cache_wback_inv((unsigned long) ptr, (unsigned long) ptr + size); 121 frv_cache_wback_inv((unsigned long) ptr, (unsigned long) ptr + size);
123 122
@@ -151,8 +150,7 @@ int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
151 frv_cache_wback_inv(sg_dma_address(&sg[i]), 150 frv_cache_wback_inv(sg_dma_address(&sg[i]),
152 sg_dma_address(&sg[i]) + sg_dma_len(&sg[i])); 151 sg_dma_address(&sg[i]) + sg_dma_len(&sg[i]));
153 152
154 if (direction == DMA_NONE) 153 BUG_ON(direction == DMA_NONE);
155 BUG();
156 154
157 return nents; 155 return nents;
158} 156}
diff --git a/arch/frv/mb93090-mb00/pci-dma.c b/arch/frv/mb93090-mb00/pci-dma.c
index 3ddedebc4eb3..45954f0813dc 100644
--- a/arch/frv/mb93090-mb00/pci-dma.c
+++ b/arch/frv/mb93090-mb00/pci-dma.c
@@ -48,8 +48,7 @@ EXPORT_SYMBOL(dma_free_coherent);
48dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size, 48dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
49 enum dma_data_direction direction) 49 enum dma_data_direction direction)
50{ 50{
51 if (direction == DMA_NONE) 51 BUG_ON(direction == DMA_NONE);
52 BUG();
53 52
54 frv_cache_wback_inv((unsigned long) ptr, (unsigned long) ptr + size); 53 frv_cache_wback_inv((unsigned long) ptr, (unsigned long) ptr + size);
55 54
@@ -81,8 +80,7 @@ int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
81 void *vaddr; 80 void *vaddr;
82 int i; 81 int i;
83 82
84 if (direction == DMA_NONE) 83 BUG_ON(direction == DMA_NONE);
85 BUG();
86 84
87 dampr2 = __get_DAMPR(2); 85 dampr2 = __get_DAMPR(2);
88 86
diff --git a/arch/ia64/include/asm/kvm_host.h b/arch/ia64/include/asm/kvm_host.h
index 4542651e6acb..5f43697aed30 100644
--- a/arch/ia64/include/asm/kvm_host.h
+++ b/arch/ia64/include/asm/kvm_host.h
@@ -371,6 +371,7 @@ struct kvm_vcpu_arch {
371 int last_run_cpu; 371 int last_run_cpu;
372 int vmm_tr_slot; 372 int vmm_tr_slot;
373 int vm_tr_slot; 373 int vm_tr_slot;
374 int sn_rtc_tr_slot;
374 375
375#define KVM_MP_STATE_RUNNABLE 0 376#define KVM_MP_STATE_RUNNABLE 0
376#define KVM_MP_STATE_UNINITIALIZED 1 377#define KVM_MP_STATE_UNINITIALIZED 1
@@ -465,6 +466,7 @@ struct kvm_arch {
465 unsigned long vmm_init_rr; 466 unsigned long vmm_init_rr;
466 467
467 int online_vcpus; 468 int online_vcpus;
469 int is_sn2;
468 470
469 struct kvm_ioapic *vioapic; 471 struct kvm_ioapic *vioapic;
470 struct kvm_vm_stat stat; 472 struct kvm_vm_stat stat;
@@ -472,6 +474,7 @@ struct kvm_arch {
472 474
473 struct list_head assigned_dev_head; 475 struct list_head assigned_dev_head;
474 struct iommu_domain *iommu_domain; 476 struct iommu_domain *iommu_domain;
477 int iommu_flags;
475 struct hlist_head irq_ack_notifier_list; 478 struct hlist_head irq_ack_notifier_list;
476 479
477 unsigned long irq_sources_bitmap; 480 unsigned long irq_sources_bitmap;
@@ -578,6 +581,8 @@ struct kvm_vmm_info{
578 kvm_vmm_entry *vmm_entry; 581 kvm_vmm_entry *vmm_entry;
579 kvm_tramp_entry *tramp_entry; 582 kvm_tramp_entry *tramp_entry;
580 unsigned long vmm_ivt; 583 unsigned long vmm_ivt;
584 unsigned long patch_mov_ar;
585 unsigned long patch_mov_ar_sn2;
581}; 586};
582 587
583int kvm_highest_pending_irq(struct kvm_vcpu *vcpu); 588int kvm_highest_pending_irq(struct kvm_vcpu *vcpu);
@@ -585,7 +590,6 @@ int kvm_emulate_halt(struct kvm_vcpu *vcpu);
585int kvm_pal_emul(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run); 590int kvm_pal_emul(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
586void kvm_sal_emul(struct kvm_vcpu *vcpu); 591void kvm_sal_emul(struct kvm_vcpu *vcpu);
587 592
588static inline void kvm_inject_nmi(struct kvm_vcpu *vcpu) {}
589#endif /* __ASSEMBLY__*/ 593#endif /* __ASSEMBLY__*/
590 594
591#endif 595#endif
diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
index 7a9bff47564f..0a9cc73d35c7 100644
--- a/arch/ia64/include/asm/pgtable.h
+++ b/arch/ia64/include/asm/pgtable.h
@@ -146,6 +146,8 @@
146#define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX) 146#define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
147#define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX) 147#define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
148#define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX) 148#define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
149#define PAGE_KERNEL_UC __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX | \
150 _PAGE_MA_UC)
149 151
150# ifndef __ASSEMBLY__ 152# ifndef __ASSEMBLY__
151 153
diff --git a/arch/ia64/kernel/irq_ia64.c b/arch/ia64/kernel/irq_ia64.c
index acc4d19ae62a..b448197728be 100644
--- a/arch/ia64/kernel/irq_ia64.c
+++ b/arch/ia64/kernel/irq_ia64.c
@@ -610,6 +610,9 @@ static struct irqaction ipi_irqaction = {
610 .name = "IPI" 610 .name = "IPI"
611}; 611};
612 612
613/*
614 * KVM uses this interrupt to force a cpu out of guest mode
615 */
613static struct irqaction resched_irqaction = { 616static struct irqaction resched_irqaction = {
614 .handler = dummy_handler, 617 .handler = dummy_handler,
615 .flags = IRQF_DISABLED, 618 .flags = IRQF_DISABLED,
diff --git a/arch/ia64/kvm/Kconfig b/arch/ia64/kvm/Kconfig
index 0a2d6b86075a..64d520937874 100644
--- a/arch/ia64/kvm/Kconfig
+++ b/arch/ia64/kvm/Kconfig
@@ -23,7 +23,7 @@ if VIRTUALIZATION
23 23
24config KVM 24config KVM
25 tristate "Kernel-based Virtual Machine (KVM) support" 25 tristate "Kernel-based Virtual Machine (KVM) support"
26 depends on HAVE_KVM && EXPERIMENTAL 26 depends on HAVE_KVM && MODULES && EXPERIMENTAL
27 # for device assignment: 27 # for device assignment:
28 depends on PCI 28 depends on PCI
29 select PREEMPT_NOTIFIERS 29 select PREEMPT_NOTIFIERS
diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c
index d20a5db4c4dd..80c57b0a21c4 100644
--- a/arch/ia64/kvm/kvm-ia64.c
+++ b/arch/ia64/kvm/kvm-ia64.c
@@ -41,6 +41,9 @@
41#include <asm/div64.h> 41#include <asm/div64.h>
42#include <asm/tlb.h> 42#include <asm/tlb.h>
43#include <asm/elf.h> 43#include <asm/elf.h>
44#include <asm/sn/addrs.h>
45#include <asm/sn/clksupport.h>
46#include <asm/sn/shub_mmr.h>
44 47
45#include "misc.h" 48#include "misc.h"
46#include "vti.h" 49#include "vti.h"
@@ -65,6 +68,16 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
65 { NULL } 68 { NULL }
66}; 69};
67 70
71static unsigned long kvm_get_itc(struct kvm_vcpu *vcpu)
72{
73#if defined(CONFIG_IA64_SGI_SN2) || defined(CONFIG_IA64_GENERIC)
74 if (vcpu->kvm->arch.is_sn2)
75 return rtc_time();
76 else
77#endif
78 return ia64_getreg(_IA64_REG_AR_ITC);
79}
80
68static void kvm_flush_icache(unsigned long start, unsigned long len) 81static void kvm_flush_icache(unsigned long start, unsigned long len)
69{ 82{
70 int l; 83 int l;
@@ -119,8 +132,7 @@ void kvm_arch_hardware_enable(void *garbage)
119 unsigned long saved_psr; 132 unsigned long saved_psr;
120 int slot; 133 int slot;
121 134
122 pte = pte_val(mk_pte_phys(__pa(kvm_vmm_base), 135 pte = pte_val(mk_pte_phys(__pa(kvm_vmm_base), PAGE_KERNEL));
123 PAGE_KERNEL));
124 local_irq_save(saved_psr); 136 local_irq_save(saved_psr);
125 slot = ia64_itr_entry(0x3, KVM_VMM_BASE, pte, KVM_VMM_SHIFT); 137 slot = ia64_itr_entry(0x3, KVM_VMM_BASE, pte, KVM_VMM_SHIFT);
126 local_irq_restore(saved_psr); 138 local_irq_restore(saved_psr);
@@ -283,6 +295,18 @@ static int handle_sal_call(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
283 295
284} 296}
285 297
298static int __apic_accept_irq(struct kvm_vcpu *vcpu, uint64_t vector)
299{
300 struct vpd *vpd = to_host(vcpu->kvm, vcpu->arch.vpd);
301
302 if (!test_and_set_bit(vector, &vpd->irr[0])) {
303 vcpu->arch.irq_new_pending = 1;
304 kvm_vcpu_kick(vcpu);
305 return 1;
306 }
307 return 0;
308}
309
286/* 310/*
287 * offset: address offset to IPI space. 311 * offset: address offset to IPI space.
288 * value: deliver value. 312 * value: deliver value.
@@ -292,20 +316,20 @@ static void vcpu_deliver_ipi(struct kvm_vcpu *vcpu, uint64_t dm,
292{ 316{
293 switch (dm) { 317 switch (dm) {
294 case SAPIC_FIXED: 318 case SAPIC_FIXED:
295 kvm_apic_set_irq(vcpu, vector, 0);
296 break; 319 break;
297 case SAPIC_NMI: 320 case SAPIC_NMI:
298 kvm_apic_set_irq(vcpu, 2, 0); 321 vector = 2;
299 break; 322 break;
300 case SAPIC_EXTINT: 323 case SAPIC_EXTINT:
301 kvm_apic_set_irq(vcpu, 0, 0); 324 vector = 0;
302 break; 325 break;
303 case SAPIC_INIT: 326 case SAPIC_INIT:
304 case SAPIC_PMI: 327 case SAPIC_PMI:
305 default: 328 default:
306 printk(KERN_ERR"kvm: Unimplemented Deliver reserved IPI!\n"); 329 printk(KERN_ERR"kvm: Unimplemented Deliver reserved IPI!\n");
307 break; 330 return;
308 } 331 }
332 __apic_accept_irq(vcpu, vector);
309} 333}
310 334
311static struct kvm_vcpu *lid_to_vcpu(struct kvm *kvm, unsigned long id, 335static struct kvm_vcpu *lid_to_vcpu(struct kvm *kvm, unsigned long id,
@@ -413,6 +437,23 @@ static int handle_switch_rr6(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
413 return 1; 437 return 1;
414} 438}
415 439
440static int kvm_sn2_setup_mappings(struct kvm_vcpu *vcpu)
441{
442 unsigned long pte, rtc_phys_addr, map_addr;
443 int slot;
444
445 map_addr = KVM_VMM_BASE + (1UL << KVM_VMM_SHIFT);
446 rtc_phys_addr = LOCAL_MMR_OFFSET | SH_RTC;
447 pte = pte_val(mk_pte_phys(rtc_phys_addr, PAGE_KERNEL_UC));
448 slot = ia64_itr_entry(0x3, map_addr, pte, PAGE_SHIFT);
449 vcpu->arch.sn_rtc_tr_slot = slot;
450 if (slot < 0) {
451 printk(KERN_ERR "Mayday mayday! RTC mapping failed!\n");
452 slot = 0;
453 }
454 return slot;
455}
456
416int kvm_emulate_halt(struct kvm_vcpu *vcpu) 457int kvm_emulate_halt(struct kvm_vcpu *vcpu)
417{ 458{
418 459
@@ -426,7 +467,7 @@ int kvm_emulate_halt(struct kvm_vcpu *vcpu)
426 467
427 if (irqchip_in_kernel(vcpu->kvm)) { 468 if (irqchip_in_kernel(vcpu->kvm)) {
428 469
429 vcpu_now_itc = ia64_getreg(_IA64_REG_AR_ITC) + vcpu->arch.itc_offset; 470 vcpu_now_itc = kvm_get_itc(vcpu) + vcpu->arch.itc_offset;
430 471
431 if (time_after(vcpu_now_itc, vpd->itm)) { 472 if (time_after(vcpu_now_itc, vpd->itm)) {
432 vcpu->arch.timer_check = 1; 473 vcpu->arch.timer_check = 1;
@@ -447,10 +488,10 @@ int kvm_emulate_halt(struct kvm_vcpu *vcpu)
447 hrtimer_cancel(p_ht); 488 hrtimer_cancel(p_ht);
448 vcpu->arch.ht_active = 0; 489 vcpu->arch.ht_active = 0;
449 490
450 if (test_and_clear_bit(KVM_REQ_UNHALT, &vcpu->requests)) 491 if (test_and_clear_bit(KVM_REQ_UNHALT, &vcpu->requests) ||
492 kvm_cpu_has_pending_timer(vcpu))
451 if (vcpu->arch.mp_state == KVM_MP_STATE_HALTED) 493 if (vcpu->arch.mp_state == KVM_MP_STATE_HALTED)
452 vcpu->arch.mp_state = 494 vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
453 KVM_MP_STATE_RUNNABLE;
454 495
455 if (vcpu->arch.mp_state != KVM_MP_STATE_RUNNABLE) 496 if (vcpu->arch.mp_state != KVM_MP_STATE_RUNNABLE)
456 return -EINTR; 497 return -EINTR;
@@ -551,22 +592,35 @@ static int kvm_insert_vmm_mapping(struct kvm_vcpu *vcpu)
551 if (r < 0) 592 if (r < 0)
552 goto out; 593 goto out;
553 vcpu->arch.vm_tr_slot = r; 594 vcpu->arch.vm_tr_slot = r;
595
596#if defined(CONFIG_IA64_SGI_SN2) || defined(CONFIG_IA64_GENERIC)
597 if (kvm->arch.is_sn2) {
598 r = kvm_sn2_setup_mappings(vcpu);
599 if (r < 0)
600 goto out;
601 }
602#endif
603
554 r = 0; 604 r = 0;
555out: 605out:
556 return r; 606 return r;
557
558} 607}
559 608
560static void kvm_purge_vmm_mapping(struct kvm_vcpu *vcpu) 609static void kvm_purge_vmm_mapping(struct kvm_vcpu *vcpu)
561{ 610{
562 611 struct kvm *kvm = vcpu->kvm;
563 ia64_ptr_entry(0x3, vcpu->arch.vmm_tr_slot); 612 ia64_ptr_entry(0x3, vcpu->arch.vmm_tr_slot);
564 ia64_ptr_entry(0x3, vcpu->arch.vm_tr_slot); 613 ia64_ptr_entry(0x3, vcpu->arch.vm_tr_slot);
565 614#if defined(CONFIG_IA64_SGI_SN2) || defined(CONFIG_IA64_GENERIC)
615 if (kvm->arch.is_sn2)
616 ia64_ptr_entry(0x3, vcpu->arch.sn_rtc_tr_slot);
617#endif
566} 618}
567 619
568static int kvm_vcpu_pre_transition(struct kvm_vcpu *vcpu) 620static int kvm_vcpu_pre_transition(struct kvm_vcpu *vcpu)
569{ 621{
622 unsigned long psr;
623 int r;
570 int cpu = smp_processor_id(); 624 int cpu = smp_processor_id();
571 625
572 if (vcpu->arch.last_run_cpu != cpu || 626 if (vcpu->arch.last_run_cpu != cpu ||
@@ -578,36 +632,27 @@ static int kvm_vcpu_pre_transition(struct kvm_vcpu *vcpu)
578 632
579 vcpu->arch.host_rr6 = ia64_get_rr(RR6); 633 vcpu->arch.host_rr6 = ia64_get_rr(RR6);
580 vti_set_rr6(vcpu->arch.vmm_rr); 634 vti_set_rr6(vcpu->arch.vmm_rr);
581 return kvm_insert_vmm_mapping(vcpu); 635 local_irq_save(psr);
636 r = kvm_insert_vmm_mapping(vcpu);
637 local_irq_restore(psr);
638 return r;
582} 639}
640
583static void kvm_vcpu_post_transition(struct kvm_vcpu *vcpu) 641static void kvm_vcpu_post_transition(struct kvm_vcpu *vcpu)
584{ 642{
585 kvm_purge_vmm_mapping(vcpu); 643 kvm_purge_vmm_mapping(vcpu);
586 vti_set_rr6(vcpu->arch.host_rr6); 644 vti_set_rr6(vcpu->arch.host_rr6);
587} 645}
588 646
589static int vti_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 647static int __vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
590{ 648{
591 union context *host_ctx, *guest_ctx; 649 union context *host_ctx, *guest_ctx;
592 int r; 650 int r;
593 651
594 /*Get host and guest context with guest address space.*/ 652 /*
595 host_ctx = kvm_get_host_context(vcpu); 653 * down_read() may sleep and return with interrupts enabled
596 guest_ctx = kvm_get_guest_context(vcpu); 654 */
597 655 down_read(&vcpu->kvm->slots_lock);
598 r = kvm_vcpu_pre_transition(vcpu);
599 if (r < 0)
600 goto out;
601 kvm_vmm_info->tramp_entry(host_ctx, guest_ctx);
602 kvm_vcpu_post_transition(vcpu);
603 r = 0;
604out:
605 return r;
606}
607
608static int __vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
609{
610 int r;
611 656
612again: 657again:
613 if (signal_pending(current)) { 658 if (signal_pending(current)) {
@@ -616,26 +661,31 @@ again:
616 goto out; 661 goto out;
617 } 662 }
618 663
619 /*
620 * down_read() may sleep and return with interrupts enabled
621 */
622 down_read(&vcpu->kvm->slots_lock);
623
624 preempt_disable(); 664 preempt_disable();
625 local_irq_disable(); 665 local_irq_disable();
626 666
627 vcpu->guest_mode = 1; 667 /*Get host and guest context with guest address space.*/
668 host_ctx = kvm_get_host_context(vcpu);
669 guest_ctx = kvm_get_guest_context(vcpu);
670
671 clear_bit(KVM_REQ_KICK, &vcpu->requests);
672
673 r = kvm_vcpu_pre_transition(vcpu);
674 if (r < 0)
675 goto vcpu_run_fail;
676
677 up_read(&vcpu->kvm->slots_lock);
628 kvm_guest_enter(); 678 kvm_guest_enter();
629 r = vti_vcpu_run(vcpu, kvm_run); 679
630 if (r < 0) { 680 /*
631 local_irq_enable(); 681 * Transition to the guest
632 preempt_enable(); 682 */
633 kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY; 683 kvm_vmm_info->tramp_entry(host_ctx, guest_ctx);
634 goto out; 684
635 } 685 kvm_vcpu_post_transition(vcpu);
636 686
637 vcpu->arch.launched = 1; 687 vcpu->arch.launched = 1;
638 vcpu->guest_mode = 0; 688 set_bit(KVM_REQ_KICK, &vcpu->requests);
639 local_irq_enable(); 689 local_irq_enable();
640 690
641 /* 691 /*
@@ -646,9 +696,10 @@ again:
646 */ 696 */
647 barrier(); 697 barrier();
648 kvm_guest_exit(); 698 kvm_guest_exit();
649 up_read(&vcpu->kvm->slots_lock);
650 preempt_enable(); 699 preempt_enable();
651 700
701 down_read(&vcpu->kvm->slots_lock);
702
652 r = kvm_handle_exit(kvm_run, vcpu); 703 r = kvm_handle_exit(kvm_run, vcpu);
653 704
654 if (r > 0) { 705 if (r > 0) {
@@ -657,12 +708,20 @@ again:
657 } 708 }
658 709
659out: 710out:
711 up_read(&vcpu->kvm->slots_lock);
660 if (r > 0) { 712 if (r > 0) {
661 kvm_resched(vcpu); 713 kvm_resched(vcpu);
714 down_read(&vcpu->kvm->slots_lock);
662 goto again; 715 goto again;
663 } 716 }
664 717
665 return r; 718 return r;
719
720vcpu_run_fail:
721 local_irq_enable();
722 preempt_enable();
723 kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
724 goto out;
666} 725}
667 726
668static void kvm_set_mmio_data(struct kvm_vcpu *vcpu) 727static void kvm_set_mmio_data(struct kvm_vcpu *vcpu)
@@ -788,6 +847,9 @@ struct kvm *kvm_arch_create_vm(void)
788 847
789 if (IS_ERR(kvm)) 848 if (IS_ERR(kvm))
790 return ERR_PTR(-ENOMEM); 849 return ERR_PTR(-ENOMEM);
850
851 kvm->arch.is_sn2 = ia64_platform_is("sn2");
852
791 kvm_init_vm(kvm); 853 kvm_init_vm(kvm);
792 854
793 kvm->arch.online_vcpus = 0; 855 kvm->arch.online_vcpus = 0;
@@ -884,7 +946,7 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
884 RESTORE_REGS(saved_gp); 946 RESTORE_REGS(saved_gp);
885 947
886 vcpu->arch.irq_new_pending = 1; 948 vcpu->arch.irq_new_pending = 1;
887 vcpu->arch.itc_offset = regs->saved_itc - ia64_getreg(_IA64_REG_AR_ITC); 949 vcpu->arch.itc_offset = regs->saved_itc - kvm_get_itc(vcpu);
888 set_bit(KVM_REQ_RESUME, &vcpu->requests); 950 set_bit(KVM_REQ_RESUME, &vcpu->requests);
889 951
890 vcpu_put(vcpu); 952 vcpu_put(vcpu);
@@ -1043,10 +1105,6 @@ static void kvm_free_vmm_area(void)
1043 } 1105 }
1044} 1106}
1045 1107
1046static void vti_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
1047{
1048}
1049
1050static int vti_init_vpd(struct kvm_vcpu *vcpu) 1108static int vti_init_vpd(struct kvm_vcpu *vcpu)
1051{ 1109{
1052 int i; 1110 int i;
@@ -1165,7 +1223,7 @@ int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu)
1165 regs->cr_iip = PALE_RESET_ENTRY; 1223 regs->cr_iip = PALE_RESET_ENTRY;
1166 1224
1167 /*Initialize itc offset for vcpus*/ 1225 /*Initialize itc offset for vcpus*/
1168 itc_offset = 0UL - ia64_getreg(_IA64_REG_AR_ITC); 1226 itc_offset = 0UL - kvm_get_itc(vcpu);
1169 for (i = 0; i < kvm->arch.online_vcpus; i++) { 1227 for (i = 0; i < kvm->arch.online_vcpus; i++) {
1170 v = (struct kvm_vcpu *)((char *)vcpu + 1228 v = (struct kvm_vcpu *)((char *)vcpu +
1171 sizeof(struct kvm_vcpu_data) * i); 1229 sizeof(struct kvm_vcpu_data) * i);
@@ -1237,6 +1295,7 @@ static int vti_vcpu_setup(struct kvm_vcpu *vcpu, int id)
1237 1295
1238 local_irq_save(psr); 1296 local_irq_save(psr);
1239 r = kvm_insert_vmm_mapping(vcpu); 1297 r = kvm_insert_vmm_mapping(vcpu);
1298 local_irq_restore(psr);
1240 if (r) 1299 if (r)
1241 goto fail; 1300 goto fail;
1242 r = kvm_vcpu_init(vcpu, vcpu->kvm, id); 1301 r = kvm_vcpu_init(vcpu, vcpu->kvm, id);
@@ -1254,13 +1313,11 @@ static int vti_vcpu_setup(struct kvm_vcpu *vcpu, int id)
1254 goto uninit; 1313 goto uninit;
1255 1314
1256 kvm_purge_vmm_mapping(vcpu); 1315 kvm_purge_vmm_mapping(vcpu);
1257 local_irq_restore(psr);
1258 1316
1259 return 0; 1317 return 0;
1260uninit: 1318uninit:
1261 kvm_vcpu_uninit(vcpu); 1319 kvm_vcpu_uninit(vcpu);
1262fail: 1320fail:
1263 local_irq_restore(psr);
1264 return r; 1321 return r;
1265} 1322}
1266 1323
@@ -1291,7 +1348,6 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
1291 vcpu->kvm = kvm; 1348 vcpu->kvm = kvm;
1292 1349
1293 cpu = get_cpu(); 1350 cpu = get_cpu();
1294 vti_vcpu_load(vcpu, cpu);
1295 r = vti_vcpu_setup(vcpu, id); 1351 r = vti_vcpu_setup(vcpu, id);
1296 put_cpu(); 1352 put_cpu();
1297 1353
@@ -1427,7 +1483,7 @@ int kvm_arch_vcpu_ioctl_get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
1427 } 1483 }
1428 for (i = 0; i < 4; i++) 1484 for (i = 0; i < 4; i++)
1429 regs->insvc[i] = vcpu->arch.insvc[i]; 1485 regs->insvc[i] = vcpu->arch.insvc[i];
1430 regs->saved_itc = vcpu->arch.itc_offset + ia64_getreg(_IA64_REG_AR_ITC); 1486 regs->saved_itc = vcpu->arch.itc_offset + kvm_get_itc(vcpu);
1431 SAVE_REGS(xtp); 1487 SAVE_REGS(xtp);
1432 SAVE_REGS(metaphysical_rr0); 1488 SAVE_REGS(metaphysical_rr0);
1433 SAVE_REGS(metaphysical_rr4); 1489 SAVE_REGS(metaphysical_rr4);
@@ -1574,6 +1630,7 @@ int kvm_arch_set_memory_region(struct kvm *kvm,
1574 1630
1575void kvm_arch_flush_shadow(struct kvm *kvm) 1631void kvm_arch_flush_shadow(struct kvm *kvm)
1576{ 1632{
1633 kvm_flush_remote_tlbs(kvm);
1577} 1634}
1578 1635
1579long kvm_arch_dev_ioctl(struct file *filp, 1636long kvm_arch_dev_ioctl(struct file *filp,
@@ -1616,8 +1673,37 @@ out:
1616 return 0; 1673 return 0;
1617} 1674}
1618 1675
1676
1677/*
1678 * On SN2, the ITC isn't stable, so copy in fast path code to use the
1679 * SN2 RTC, replacing the ITC based default verion.
1680 */
1681static void kvm_patch_vmm(struct kvm_vmm_info *vmm_info,
1682 struct module *module)
1683{
1684 unsigned long new_ar, new_ar_sn2;
1685 unsigned long module_base;
1686
1687 if (!ia64_platform_is("sn2"))
1688 return;
1689
1690 module_base = (unsigned long)module->module_core;
1691
1692 new_ar = kvm_vmm_base + vmm_info->patch_mov_ar - module_base;
1693 new_ar_sn2 = kvm_vmm_base + vmm_info->patch_mov_ar_sn2 - module_base;
1694
1695 printk(KERN_INFO "kvm: Patching ITC emulation to use SGI SN2 RTC "
1696 "as source\n");
1697
1698 /*
1699 * Copy the SN2 version of mov_ar into place. They are both
1700 * the same size, so 6 bundles is sufficient (6 * 0x10).
1701 */
1702 memcpy((void *)new_ar, (void *)new_ar_sn2, 0x60);
1703}
1704
1619static int kvm_relocate_vmm(struct kvm_vmm_info *vmm_info, 1705static int kvm_relocate_vmm(struct kvm_vmm_info *vmm_info,
1620 struct module *module) 1706 struct module *module)
1621{ 1707{
1622 unsigned long module_base; 1708 unsigned long module_base;
1623 unsigned long vmm_size; 1709 unsigned long vmm_size;
@@ -1639,6 +1725,7 @@ static int kvm_relocate_vmm(struct kvm_vmm_info *vmm_info,
1639 return -EFAULT; 1725 return -EFAULT;
1640 1726
1641 memcpy((void *)kvm_vmm_base, (void *)module_base, vmm_size); 1727 memcpy((void *)kvm_vmm_base, (void *)module_base, vmm_size);
1728 kvm_patch_vmm(vmm_info, module);
1642 kvm_flush_icache(kvm_vmm_base, vmm_size); 1729 kvm_flush_icache(kvm_vmm_base, vmm_size);
1643 1730
1644 /*Recalculate kvm_vmm_info based on new VMM*/ 1731 /*Recalculate kvm_vmm_info based on new VMM*/
@@ -1792,38 +1879,24 @@ void kvm_arch_hardware_unsetup(void)
1792{ 1879{
1793} 1880}
1794 1881
1795static void vcpu_kick_intr(void *info)
1796{
1797#ifdef DEBUG
1798 struct kvm_vcpu *vcpu = (struct kvm_vcpu *)info;
1799 printk(KERN_DEBUG"vcpu_kick_intr %p \n", vcpu);
1800#endif
1801}
1802
1803void kvm_vcpu_kick(struct kvm_vcpu *vcpu) 1882void kvm_vcpu_kick(struct kvm_vcpu *vcpu)
1804{ 1883{
1805 int ipi_pcpu = vcpu->cpu; 1884 int me;
1806 int cpu = get_cpu(); 1885 int cpu = vcpu->cpu;
1807 1886
1808 if (waitqueue_active(&vcpu->wq)) 1887 if (waitqueue_active(&vcpu->wq))
1809 wake_up_interruptible(&vcpu->wq); 1888 wake_up_interruptible(&vcpu->wq);
1810 1889
1811 if (vcpu->guest_mode && cpu != ipi_pcpu) 1890 me = get_cpu();
1812 smp_call_function_single(ipi_pcpu, vcpu_kick_intr, vcpu, 0); 1891 if (cpu != me && (unsigned) cpu < nr_cpu_ids && cpu_online(cpu))
1892 if (!test_and_set_bit(KVM_REQ_KICK, &vcpu->requests))
1893 smp_send_reschedule(cpu);
1813 put_cpu(); 1894 put_cpu();
1814} 1895}
1815 1896
1816int kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 trig) 1897int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq)
1817{ 1898{
1818 1899 return __apic_accept_irq(vcpu, irq->vector);
1819 struct vpd *vpd = to_host(vcpu->kvm, vcpu->arch.vpd);
1820
1821 if (!test_and_set_bit(vec, &vpd->irr[0])) {
1822 vcpu->arch.irq_new_pending = 1;
1823 kvm_vcpu_kick(vcpu);
1824 return 1;
1825 }
1826 return 0;
1827} 1900}
1828 1901
1829int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest) 1902int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest)
@@ -1836,20 +1909,18 @@ int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda)
1836 return 0; 1909 return 0;
1837} 1910}
1838 1911
1839struct kvm_vcpu *kvm_get_lowest_prio_vcpu(struct kvm *kvm, u8 vector, 1912int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2)
1840 unsigned long bitmap)
1841{ 1913{
1842 struct kvm_vcpu *lvcpu = kvm->vcpus[0]; 1914 return vcpu1->arch.xtp - vcpu2->arch.xtp;
1843 int i; 1915}
1844
1845 for (i = 1; i < kvm->arch.online_vcpus; i++) {
1846 if (!kvm->vcpus[i])
1847 continue;
1848 if (lvcpu->arch.xtp > kvm->vcpus[i]->arch.xtp)
1849 lvcpu = kvm->vcpus[i];
1850 }
1851 1916
1852 return lvcpu; 1917int kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source,
1918 int short_hand, int dest, int dest_mode)
1919{
1920 struct kvm_lapic *target = vcpu->arch.apic;
1921 return (dest_mode == 0) ?
1922 kvm_apic_match_physical_addr(target, dest) :
1923 kvm_apic_match_logical_addr(target, dest);
1853} 1924}
1854 1925
1855static int find_highest_bits(int *dat) 1926static int find_highest_bits(int *dat)
@@ -1888,6 +1959,12 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu)
1888 return 0; 1959 return 0;
1889} 1960}
1890 1961
1962int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu)
1963{
1964 /* do real check here */
1965 return 1;
1966}
1967
1891int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) 1968int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
1892{ 1969{
1893 return vcpu->arch.timer_fired; 1970 return vcpu->arch.timer_fired;
@@ -1918,6 +1995,7 @@ static int vcpu_reset(struct kvm_vcpu *vcpu)
1918 long psr; 1995 long psr;
1919 local_irq_save(psr); 1996 local_irq_save(psr);
1920 r = kvm_insert_vmm_mapping(vcpu); 1997 r = kvm_insert_vmm_mapping(vcpu);
1998 local_irq_restore(psr);
1921 if (r) 1999 if (r)
1922 goto fail; 2000 goto fail;
1923 2001
@@ -1930,7 +2008,6 @@ static int vcpu_reset(struct kvm_vcpu *vcpu)
1930 kvm_purge_vmm_mapping(vcpu); 2008 kvm_purge_vmm_mapping(vcpu);
1931 r = 0; 2009 r = 0;
1932fail: 2010fail:
1933 local_irq_restore(psr);
1934 return r; 2011 return r;
1935} 2012}
1936 2013
diff --git a/arch/ia64/kvm/kvm_fw.c b/arch/ia64/kvm/kvm_fw.c
index a8ae52ed5635..e4b82319881d 100644
--- a/arch/ia64/kvm/kvm_fw.c
+++ b/arch/ia64/kvm/kvm_fw.c
@@ -21,6 +21,9 @@
21 21
22#include <linux/kvm_host.h> 22#include <linux/kvm_host.h>
23#include <linux/smp.h> 23#include <linux/smp.h>
24#include <asm/sn/addrs.h>
25#include <asm/sn/clksupport.h>
26#include <asm/sn/shub_mmr.h>
24 27
25#include "vti.h" 28#include "vti.h"
26#include "misc.h" 29#include "misc.h"
@@ -188,12 +191,35 @@ static struct ia64_pal_retval pal_freq_base(struct kvm_vcpu *vcpu)
188 return result; 191 return result;
189} 192}
190 193
191static struct ia64_pal_retval pal_freq_ratios(struct kvm_vcpu *vcpu) 194/*
195 * On the SGI SN2, the ITC isn't stable. Emulation backed by the SN2
196 * RTC is used instead. This function patches the ratios from SAL
197 * to match the RTC before providing them to the guest.
198 */
199static void sn2_patch_itc_freq_ratios(struct ia64_pal_retval *result)
192{ 200{
201 struct pal_freq_ratio *ratio;
202 unsigned long sal_freq, sal_drift, factor;
203
204 result->status = ia64_sal_freq_base(SAL_FREQ_BASE_PLATFORM,
205 &sal_freq, &sal_drift);
206 ratio = (struct pal_freq_ratio *)&result->v2;
207 factor = ((sal_freq * 3) + (sn_rtc_cycles_per_second / 2)) /
208 sn_rtc_cycles_per_second;
209
210 ratio->num = 3;
211 ratio->den = factor;
212}
193 213
214static struct ia64_pal_retval pal_freq_ratios(struct kvm_vcpu *vcpu)
215{
194 struct ia64_pal_retval result; 216 struct ia64_pal_retval result;
195 217
196 PAL_CALL(result, PAL_FREQ_RATIOS, 0, 0, 0); 218 PAL_CALL(result, PAL_FREQ_RATIOS, 0, 0, 0);
219
220 if (vcpu->kvm->arch.is_sn2)
221 sn2_patch_itc_freq_ratios(&result);
222
197 return result; 223 return result;
198} 224}
199 225
diff --git a/arch/ia64/kvm/lapic.h b/arch/ia64/kvm/lapic.h
index 6d6cbcb14893..ee541cebcd78 100644
--- a/arch/ia64/kvm/lapic.h
+++ b/arch/ia64/kvm/lapic.h
@@ -20,6 +20,10 @@ void kvm_free_lapic(struct kvm_vcpu *vcpu);
20 20
21int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest); 21int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest);
22int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda); 22int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda);
23int kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 trig); 23int kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source,
24 int short_hand, int dest, int dest_mode);
25int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2);
26int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq);
27#define kvm_apic_present(x) (true)
24 28
25#endif 29#endif
diff --git a/arch/ia64/kvm/optvfault.S b/arch/ia64/kvm/optvfault.S
index 32254ce9a1bd..f793be3effff 100644
--- a/arch/ia64/kvm/optvfault.S
+++ b/arch/ia64/kvm/optvfault.S
@@ -11,6 +11,7 @@
11 11
12#include <asm/asmmacro.h> 12#include <asm/asmmacro.h>
13#include <asm/processor.h> 13#include <asm/processor.h>
14#include <asm/kvm_host.h>
14 15
15#include "vti.h" 16#include "vti.h"
16#include "asm-offsets.h" 17#include "asm-offsets.h"
@@ -140,6 +141,35 @@ GLOBAL_ENTRY(kvm_asm_mov_from_ar)
140 ;; 141 ;;
141END(kvm_asm_mov_from_ar) 142END(kvm_asm_mov_from_ar)
142 143
144/*
145 * Special SGI SN2 optimized version of mov_from_ar using the SN2 RTC
146 * clock as it's source for emulating the ITC. This version will be
147 * copied on top of the original version if the host is determined to
148 * be an SN2.
149 */
150GLOBAL_ENTRY(kvm_asm_mov_from_ar_sn2)
151 add r18=VMM_VCPU_ITC_OFS_OFFSET, r21
152 movl r19 = (KVM_VMM_BASE+(1<<KVM_VMM_SHIFT))
153
154 add r16=VMM_VCPU_LAST_ITC_OFFSET,r21
155 extr.u r17=r25,6,7
156 mov r24=b0
157 ;;
158 ld8 r18=[r18]
159 ld8 r19=[r19]
160 addl r20=@gprel(asm_mov_to_reg),gp
161 ;;
162 add r19=r19,r18
163 shladd r17=r17,4,r20
164 ;;
165 adds r30=kvm_resume_to_guest-asm_mov_to_reg,r20
166 st8 [r16] = r19
167 mov b0=r17
168 br.sptk.few b0
169 ;;
170END(kvm_asm_mov_from_ar_sn2)
171
172
143 173
144// mov r1=rr[r3] 174// mov r1=rr[r3]
145GLOBAL_ENTRY(kvm_asm_mov_from_rr) 175GLOBAL_ENTRY(kvm_asm_mov_from_rr)
diff --git a/arch/ia64/kvm/process.c b/arch/ia64/kvm/process.c
index b1dc80952d91..a8f84da04b49 100644
--- a/arch/ia64/kvm/process.c
+++ b/arch/ia64/kvm/process.c
@@ -652,20 +652,25 @@ void kvm_ia64_handle_break(unsigned long ifa, struct kvm_pt_regs *regs,
652 unsigned long isr, unsigned long iim) 652 unsigned long isr, unsigned long iim)
653{ 653{
654 struct kvm_vcpu *v = current_vcpu; 654 struct kvm_vcpu *v = current_vcpu;
655 long psr;
655 656
656 if (ia64_psr(regs)->cpl == 0) { 657 if (ia64_psr(regs)->cpl == 0) {
657 /* Allow hypercalls only when cpl = 0. */ 658 /* Allow hypercalls only when cpl = 0. */
658 if (iim == DOMN_PAL_REQUEST) { 659 if (iim == DOMN_PAL_REQUEST) {
660 local_irq_save(psr);
659 set_pal_call_data(v); 661 set_pal_call_data(v);
660 vmm_transition(v); 662 vmm_transition(v);
661 get_pal_call_result(v); 663 get_pal_call_result(v);
662 vcpu_increment_iip(v); 664 vcpu_increment_iip(v);
665 local_irq_restore(psr);
663 return; 666 return;
664 } else if (iim == DOMN_SAL_REQUEST) { 667 } else if (iim == DOMN_SAL_REQUEST) {
668 local_irq_save(psr);
665 set_sal_call_data(v); 669 set_sal_call_data(v);
666 vmm_transition(v); 670 vmm_transition(v);
667 get_sal_call_result(v); 671 get_sal_call_result(v);
668 vcpu_increment_iip(v); 672 vcpu_increment_iip(v);
673 local_irq_restore(psr);
669 return; 674 return;
670 } 675 }
671 } 676 }
diff --git a/arch/ia64/kvm/vcpu.c b/arch/ia64/kvm/vcpu.c
index a18ee17b9192..a2c6c15e4761 100644
--- a/arch/ia64/kvm/vcpu.c
+++ b/arch/ia64/kvm/vcpu.c
@@ -788,13 +788,29 @@ void vcpu_set_fpreg(struct kvm_vcpu *vcpu, unsigned long reg,
788 setfpreg(reg, val, regs); /* FIXME: handle NATs later*/ 788 setfpreg(reg, val, regs); /* FIXME: handle NATs later*/
789} 789}
790 790
791/*
792 * The Altix RTC is mapped specially here for the vmm module
793 */
794#define SN_RTC_BASE (u64 *)(KVM_VMM_BASE+(1UL<<KVM_VMM_SHIFT))
795static long kvm_get_itc(struct kvm_vcpu *vcpu)
796{
797#if defined(CONFIG_IA64_SGI_SN2) || defined(CONFIG_IA64_GENERIC)
798 struct kvm *kvm = (struct kvm *)KVM_VM_BASE;
799
800 if (kvm->arch.is_sn2)
801 return (*SN_RTC_BASE);
802 else
803#endif
804 return ia64_getreg(_IA64_REG_AR_ITC);
805}
806
791/************************************************************************ 807/************************************************************************
792 * lsapic timer 808 * lsapic timer
793 ***********************************************************************/ 809 ***********************************************************************/
794u64 vcpu_get_itc(struct kvm_vcpu *vcpu) 810u64 vcpu_get_itc(struct kvm_vcpu *vcpu)
795{ 811{
796 unsigned long guest_itc; 812 unsigned long guest_itc;
797 guest_itc = VMX(vcpu, itc_offset) + ia64_getreg(_IA64_REG_AR_ITC); 813 guest_itc = VMX(vcpu, itc_offset) + kvm_get_itc(vcpu);
798 814
799 if (guest_itc >= VMX(vcpu, last_itc)) { 815 if (guest_itc >= VMX(vcpu, last_itc)) {
800 VMX(vcpu, last_itc) = guest_itc; 816 VMX(vcpu, last_itc) = guest_itc;
@@ -809,7 +825,7 @@ static void vcpu_set_itc(struct kvm_vcpu *vcpu, u64 val)
809 struct kvm_vcpu *v; 825 struct kvm_vcpu *v;
810 struct kvm *kvm; 826 struct kvm *kvm;
811 int i; 827 int i;
812 long itc_offset = val - ia64_getreg(_IA64_REG_AR_ITC); 828 long itc_offset = val - kvm_get_itc(vcpu);
813 unsigned long vitv = VCPU(vcpu, itv); 829 unsigned long vitv = VCPU(vcpu, itv);
814 830
815 kvm = (struct kvm *)KVM_VM_BASE; 831 kvm = (struct kvm *)KVM_VM_BASE;
diff --git a/arch/ia64/kvm/vmm.c b/arch/ia64/kvm/vmm.c
index 9eee5c04bacc..f4b4c899bb6c 100644
--- a/arch/ia64/kvm/vmm.c
+++ b/arch/ia64/kvm/vmm.c
@@ -30,15 +30,19 @@ MODULE_AUTHOR("Intel");
30MODULE_LICENSE("GPL"); 30MODULE_LICENSE("GPL");
31 31
32extern char kvm_ia64_ivt; 32extern char kvm_ia64_ivt;
33extern char kvm_asm_mov_from_ar;
34extern char kvm_asm_mov_from_ar_sn2;
33extern fpswa_interface_t *vmm_fpswa_interface; 35extern fpswa_interface_t *vmm_fpswa_interface;
34 36
35long vmm_sanity = 1; 37long vmm_sanity = 1;
36 38
37struct kvm_vmm_info vmm_info = { 39struct kvm_vmm_info vmm_info = {
38 .module = THIS_MODULE, 40 .module = THIS_MODULE,
39 .vmm_entry = vmm_entry, 41 .vmm_entry = vmm_entry,
40 .tramp_entry = vmm_trampoline, 42 .tramp_entry = vmm_trampoline,
41 .vmm_ivt = (unsigned long)&kvm_ia64_ivt, 43 .vmm_ivt = (unsigned long)&kvm_ia64_ivt,
44 .patch_mov_ar = (unsigned long)&kvm_asm_mov_from_ar,
45 .patch_mov_ar_sn2 = (unsigned long)&kvm_asm_mov_from_ar_sn2,
42}; 46};
43 47
44static int __init kvm_vmm_init(void) 48static int __init kvm_vmm_init(void)
diff --git a/arch/ia64/kvm/vmm_ivt.S b/arch/ia64/kvm/vmm_ivt.S
index 3ef1a017a318..40920c630649 100644
--- a/arch/ia64/kvm/vmm_ivt.S
+++ b/arch/ia64/kvm/vmm_ivt.S
@@ -95,7 +95,7 @@ GLOBAL_ENTRY(kvm_vmm_panic)
95 ;; 95 ;;
96 srlz.i // guarantee that interruption collection is on 96 srlz.i // guarantee that interruption collection is on
97 ;; 97 ;;
98 //(p15) ssm psr.i // restore psr.i 98 (p15) ssm psr.i // restore psr.
99 addl r14=@gprel(ia64_leave_hypervisor),gp 99 addl r14=@gprel(ia64_leave_hypervisor),gp
100 ;; 100 ;;
101 KVM_SAVE_REST 101 KVM_SAVE_REST
@@ -249,7 +249,7 @@ ENTRY(kvm_break_fault)
249 ;; 249 ;;
250 srlz.i // guarantee that interruption collection is on 250 srlz.i // guarantee that interruption collection is on
251 ;; 251 ;;
252 //(p15)ssm psr.i // restore psr.i 252 (p15)ssm psr.i // restore psr.i
253 addl r14=@gprel(ia64_leave_hypervisor),gp 253 addl r14=@gprel(ia64_leave_hypervisor),gp
254 ;; 254 ;;
255 KVM_SAVE_REST 255 KVM_SAVE_REST
@@ -439,7 +439,7 @@ kvm_dispatch_vexirq:
439 ;; 439 ;;
440 srlz.i // guarantee that interruption collection is on 440 srlz.i // guarantee that interruption collection is on
441 ;; 441 ;;
442 //(p15) ssm psr.i // restore psr.i 442 (p15) ssm psr.i // restore psr.i
443 adds r3=8,r2 // set up second base pointer 443 adds r3=8,r2 // set up second base pointer
444 ;; 444 ;;
445 KVM_SAVE_REST 445 KVM_SAVE_REST
@@ -819,7 +819,7 @@ ENTRY(kvm_dtlb_miss_dispatch)
819 ;; 819 ;;
820 srlz.i // guarantee that interruption collection is on 820 srlz.i // guarantee that interruption collection is on
821 ;; 821 ;;
822 //(p15) ssm psr.i // restore psr.i 822 (p15) ssm psr.i // restore psr.i
823 addl r14=@gprel(ia64_leave_hypervisor_prepare),gp 823 addl r14=@gprel(ia64_leave_hypervisor_prepare),gp
824 ;; 824 ;;
825 KVM_SAVE_REST 825 KVM_SAVE_REST
@@ -842,7 +842,7 @@ ENTRY(kvm_itlb_miss_dispatch)
842 ;; 842 ;;
843 srlz.i // guarantee that interruption collection is on 843 srlz.i // guarantee that interruption collection is on
844 ;; 844 ;;
845 //(p15) ssm psr.i // restore psr.i 845 (p15) ssm psr.i // restore psr.i
846 addl r14=@gprel(ia64_leave_hypervisor),gp 846 addl r14=@gprel(ia64_leave_hypervisor),gp
847 ;; 847 ;;
848 KVM_SAVE_REST 848 KVM_SAVE_REST
@@ -871,7 +871,7 @@ ENTRY(kvm_dispatch_reflection)
871 ;; 871 ;;
872 srlz.i // guarantee that interruption collection is on 872 srlz.i // guarantee that interruption collection is on
873 ;; 873 ;;
874 //(p15) ssm psr.i // restore psr.i 874 (p15) ssm psr.i // restore psr.i
875 addl r14=@gprel(ia64_leave_hypervisor),gp 875 addl r14=@gprel(ia64_leave_hypervisor),gp
876 ;; 876 ;;
877 KVM_SAVE_REST 877 KVM_SAVE_REST
@@ -898,7 +898,7 @@ ENTRY(kvm_dispatch_virtualization_fault)
898 ;; 898 ;;
899 srlz.i // guarantee that interruption collection is on 899 srlz.i // guarantee that interruption collection is on
900 ;; 900 ;;
901 //(p15) ssm psr.i // restore psr.i 901 (p15) ssm psr.i // restore psr.i
902 addl r14=@gprel(ia64_leave_hypervisor_prepare),gp 902 addl r14=@gprel(ia64_leave_hypervisor_prepare),gp
903 ;; 903 ;;
904 KVM_SAVE_REST 904 KVM_SAVE_REST
@@ -920,7 +920,7 @@ ENTRY(kvm_dispatch_interrupt)
920 ;; 920 ;;
921 srlz.i 921 srlz.i
922 ;; 922 ;;
923 //(p15) ssm psr.i 923 (p15) ssm psr.i
924 addl r14=@gprel(ia64_leave_hypervisor),gp 924 addl r14=@gprel(ia64_leave_hypervisor),gp
925 ;; 925 ;;
926 KVM_SAVE_REST 926 KVM_SAVE_REST
@@ -1333,7 +1333,7 @@ hostret = r24
1333 ;; 1333 ;;
1334(p7) srlz.i 1334(p7) srlz.i
1335 ;; 1335 ;;
1336//(p6) ssm psr.i 1336(p6) ssm psr.i
1337 ;; 1337 ;;
1338 mov rp=rpsave 1338 mov rp=rpsave
1339 mov ar.pfs=pfssave 1339 mov ar.pfs=pfssave
diff --git a/arch/ia64/kvm/vtlb.c b/arch/ia64/kvm/vtlb.c
index 2c2501f13159..4290a429bf7c 100644
--- a/arch/ia64/kvm/vtlb.c
+++ b/arch/ia64/kvm/vtlb.c
@@ -254,7 +254,8 @@ u64 guest_vhpt_lookup(u64 iha, u64 *pte)
254 "(p7) st8 [%2]=r9;;" 254 "(p7) st8 [%2]=r9;;"
255 "ssm psr.ic;;" 255 "ssm psr.ic;;"
256 "srlz.d;;" 256 "srlz.d;;"
257 /* "ssm psr.i;;" Once interrupts in vmm open, need fix*/ 257 "ssm psr.i;;"
258 "srlz.d;;"
258 : "=r"(ret) : "r"(iha), "r"(pte):"memory"); 259 : "=r"(ret) : "r"(iha), "r"(pte):"memory");
259 260
260 return ret; 261 return ret;
diff --git a/arch/mn10300/Kconfig b/arch/mn10300/Kconfig
index 355926730e8d..89faacad5d17 100644
--- a/arch/mn10300/Kconfig
+++ b/arch/mn10300/Kconfig
@@ -8,6 +8,7 @@ mainmenu "Linux Kernel Configuration"
8config MN10300 8config MN10300
9 def_bool y 9 def_bool y
10 select HAVE_OPROFILE 10 select HAVE_OPROFILE
11 select HAVE_ARCH_TRACEHOOK
11 12
12config AM33 13config AM33
13 def_bool y 14 def_bool y
diff --git a/arch/mn10300/include/asm/elf.h b/arch/mn10300/include/asm/elf.h
index bf09f8bb392e..49105462e6fc 100644
--- a/arch/mn10300/include/asm/elf.h
+++ b/arch/mn10300/include/asm/elf.h
@@ -34,7 +34,7 @@
34 */ 34 */
35typedef unsigned long elf_greg_t; 35typedef unsigned long elf_greg_t;
36 36
37#define ELF_NGREG (sizeof (struct pt_regs) / sizeof(elf_greg_t)) 37#define ELF_NGREG ((sizeof(struct pt_regs) / sizeof(elf_greg_t)) - 1)
38typedef elf_greg_t elf_gregset_t[ELF_NGREG]; 38typedef elf_greg_t elf_gregset_t[ELF_NGREG];
39 39
40#define ELF_NFPREG 32 40#define ELF_NFPREG 32
@@ -76,6 +76,7 @@ do { \
76} while (0) 76} while (0)
77 77
78#define USE_ELF_CORE_DUMP 78#define USE_ELF_CORE_DUMP
79#define CORE_DUMP_USE_REGSET
79#define ELF_EXEC_PAGESIZE 4096 80#define ELF_EXEC_PAGESIZE 4096
80 81
81/* 82/*
diff --git a/arch/mn10300/include/asm/processor.h b/arch/mn10300/include/asm/processor.h
index 73239271873d..f7d4b0d285e8 100644
--- a/arch/mn10300/include/asm/processor.h
+++ b/arch/mn10300/include/asm/processor.h
@@ -143,13 +143,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
143 143
144unsigned long get_wchan(struct task_struct *p); 144unsigned long get_wchan(struct task_struct *p);
145 145
146#define task_pt_regs(task) \ 146#define task_pt_regs(task) ((task)->thread.uregs)
147({ \
148 struct pt_regs *__regs__; \
149 __regs__ = (struct pt_regs *) (KSTK_TOP(task_stack_page(task)) - 8); \
150 __regs__ - 1; \
151})
152
153#define KSTK_EIP(task) (task_pt_regs(task)->pc) 147#define KSTK_EIP(task) (task_pt_regs(task)->pc)
154#define KSTK_ESP(task) (task_pt_regs(task)->sp) 148#define KSTK_ESP(task) (task_pt_regs(task)->sp)
155 149
diff --git a/arch/mn10300/include/asm/ptrace.h b/arch/mn10300/include/asm/ptrace.h
index 7b06cc623d8b..921942ed1b03 100644
--- a/arch/mn10300/include/asm/ptrace.h
+++ b/arch/mn10300/include/asm/ptrace.h
@@ -91,9 +91,17 @@ extern struct pt_regs *__frame; /* current frame pointer */
91#if defined(__KERNEL__) 91#if defined(__KERNEL__)
92 92
93#if !defined(__ASSEMBLY__) 93#if !defined(__ASSEMBLY__)
94struct task_struct;
95
94#define user_mode(regs) (((regs)->epsw & EPSW_nSL) == EPSW_nSL) 96#define user_mode(regs) (((regs)->epsw & EPSW_nSL) == EPSW_nSL)
95#define instruction_pointer(regs) ((regs)->pc) 97#define instruction_pointer(regs) ((regs)->pc)
98#define user_stack_pointer(regs) ((regs)->sp)
96extern void show_regs(struct pt_regs *); 99extern void show_regs(struct pt_regs *);
100
101#define arch_has_single_step() (1)
102extern void user_enable_single_step(struct task_struct *);
103extern void user_disable_single_step(struct task_struct *);
104
97#endif /* !__ASSEMBLY */ 105#endif /* !__ASSEMBLY */
98 106
99#define profile_pc(regs) ((regs)->pc) 107#define profile_pc(regs) ((regs)->pc)
diff --git a/arch/mn10300/kernel/entry.S b/arch/mn10300/kernel/entry.S
index 3dc3e462f92a..7408a27199f3 100644
--- a/arch/mn10300/kernel/entry.S
+++ b/arch/mn10300/kernel/entry.S
@@ -76,7 +76,7 @@ ENTRY(system_call)
76 cmp nr_syscalls,d0 76 cmp nr_syscalls,d0
77 bcc syscall_badsys 77 bcc syscall_badsys
78 btst _TIF_SYSCALL_TRACE,(TI_flags,a2) 78 btst _TIF_SYSCALL_TRACE,(TI_flags,a2)
79 bne syscall_trace_entry 79 bne syscall_entry_trace
80syscall_call: 80syscall_call:
81 add d0,d0,a1 81 add d0,d0,a1
82 add a1,a1 82 add a1,a1
@@ -104,11 +104,10 @@ restore_all:
104syscall_exit_work: 104syscall_exit_work:
105 btst _TIF_SYSCALL_TRACE,d2 105 btst _TIF_SYSCALL_TRACE,d2
106 beq work_pending 106 beq work_pending
107 __sti # could let do_syscall_trace() call 107 __sti # could let syscall_trace_exit() call
108 # schedule() instead 108 # schedule() instead
109 mov fp,d0 109 mov fp,d0
110 mov 1,d1 110 call syscall_trace_exit[],0 # do_syscall_trace(regs)
111 call do_syscall_trace[],0 # do_syscall_trace(regs,entryexit)
112 jmp resume_userspace 111 jmp resume_userspace
113 112
114 ALIGN 113 ALIGN
@@ -138,13 +137,11 @@ work_notifysig:
138 jmp resume_userspace 137 jmp resume_userspace
139 138
140 # perform syscall entry tracing 139 # perform syscall entry tracing
141syscall_trace_entry: 140syscall_entry_trace:
142 mov -ENOSYS,d0 141 mov -ENOSYS,d0
143 mov d0,(REG_D0,fp) 142 mov d0,(REG_D0,fp)
144 mov fp,d0 143 mov fp,d0
145 clr d1 144 call syscall_trace_entry[],0 # returns the syscall number to actually use
146 call do_syscall_trace[],0
147 mov (REG_ORIG_D0,fp),d0
148 mov (REG_D1,fp),d1 145 mov (REG_D1,fp),d1
149 cmp nr_syscalls,d0 146 cmp nr_syscalls,d0
150 bcs syscall_call 147 bcs syscall_call
diff --git a/arch/mn10300/kernel/ptrace.c b/arch/mn10300/kernel/ptrace.c
index d6d6cdc75c52..e143339ad28e 100644
--- a/arch/mn10300/kernel/ptrace.c
+++ b/arch/mn10300/kernel/ptrace.c
@@ -17,6 +17,9 @@
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/ptrace.h> 18#include <linux/ptrace.h>
19#include <linux/user.h> 19#include <linux/user.h>
20#include <linux/regset.h>
21#include <linux/elf.h>
22#include <linux/tracehook.h>
20#include <asm/uaccess.h> 23#include <asm/uaccess.h>
21#include <asm/pgtable.h> 24#include <asm/pgtable.h>
22#include <asm/system.h> 25#include <asm/system.h>
@@ -64,12 +67,6 @@ static inline int get_stack_long(struct task_struct *task, int offset)
64 ((unsigned long) task->thread.uregs + offset); 67 ((unsigned long) task->thread.uregs + offset);
65} 68}
66 69
67/*
68 * this routine will put a word on the processes privileged stack.
69 * the offset is how far from the base addr as stored in the TSS.
70 * this routine assumes that all the privileged stacks are in our
71 * data space.
72 */
73static inline 70static inline
74int put_stack_long(struct task_struct *task, int offset, unsigned long data) 71int put_stack_long(struct task_struct *task, int offset, unsigned long data)
75{ 72{
@@ -80,94 +77,233 @@ int put_stack_long(struct task_struct *task, int offset, unsigned long data)
80 return 0; 77 return 0;
81} 78}
82 79
83static inline unsigned long get_fpregs(struct fpu_state_struct *buf, 80/*
84 struct task_struct *tsk) 81 * retrieve the contents of MN10300 userspace general registers
82 */
83static int genregs_get(struct task_struct *target,
84 const struct user_regset *regset,
85 unsigned int pos, unsigned int count,
86 void *kbuf, void __user *ubuf)
85{ 87{
86 return __copy_to_user(buf, &tsk->thread.fpu_state, 88 const struct pt_regs *regs = task_pt_regs(target);
87 sizeof(struct fpu_state_struct)); 89 int ret;
90
91 /* we need to skip regs->next */
92 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
93 regs, 0, PT_ORIG_D0 * sizeof(long));
94 if (ret < 0)
95 return ret;
96
97 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
98 &regs->orig_d0, PT_ORIG_D0 * sizeof(long),
99 NR_PTREGS * sizeof(long));
100 if (ret < 0)
101 return ret;
102
103 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
104 NR_PTREGS * sizeof(long), -1);
88} 105}
89 106
90static inline unsigned long set_fpregs(struct task_struct *tsk, 107/*
91 struct fpu_state_struct *buf) 108 * update the contents of the MN10300 userspace general registers
109 */
110static int genregs_set(struct task_struct *target,
111 const struct user_regset *regset,
112 unsigned int pos, unsigned int count,
113 const void *kbuf, const void __user *ubuf)
92{ 114{
93 return __copy_from_user(&tsk->thread.fpu_state, buf, 115 struct pt_regs *regs = task_pt_regs(target);
94 sizeof(struct fpu_state_struct)); 116 unsigned long tmp;
117 int ret;
118
119 /* we need to skip regs->next */
120 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
121 regs, 0, PT_ORIG_D0 * sizeof(long));
122 if (ret < 0)
123 return ret;
124
125 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
126 &regs->orig_d0, PT_ORIG_D0 * sizeof(long),
127 PT_EPSW * sizeof(long));
128 if (ret < 0)
129 return ret;
130
131 /* we need to mask off changes to EPSW */
132 tmp = regs->epsw;
133 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
134 &tmp, PT_EPSW * sizeof(long),
135 PT_PC * sizeof(long));
136 tmp &= EPSW_FLAG_V | EPSW_FLAG_C | EPSW_FLAG_N | EPSW_FLAG_Z;
137 tmp |= regs->epsw & ~(EPSW_FLAG_V | EPSW_FLAG_C | EPSW_FLAG_N |
138 EPSW_FLAG_Z);
139 regs->epsw = tmp;
140
141 if (ret < 0)
142 return ret;
143
144 /* and finally load the PC */
145 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
146 &regs->pc, PT_PC * sizeof(long),
147 NR_PTREGS * sizeof(long));
148
149 if (ret < 0)
150 return ret;
151
152 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
153 NR_PTREGS * sizeof(long), -1);
95} 154}
96 155
97static inline void fpsave_init(struct task_struct *task) 156/*
157 * retrieve the contents of MN10300 userspace FPU registers
158 */
159static int fpuregs_get(struct task_struct *target,
160 const struct user_regset *regset,
161 unsigned int pos, unsigned int count,
162 void *kbuf, void __user *ubuf)
98{ 163{
99 memset(&task->thread.fpu_state, 0, sizeof(struct fpu_state_struct)); 164 const struct fpu_state_struct *fpregs = &target->thread.fpu_state;
165 int ret;
166
167 unlazy_fpu(target);
168
169 ret = user_regset_copyout(&pos, &count, &kbuf, &ubuf,
170 fpregs, 0, sizeof(*fpregs));
171 if (ret < 0)
172 return ret;
173
174 return user_regset_copyout_zero(&pos, &count, &kbuf, &ubuf,
175 sizeof(*fpregs), -1);
100} 176}
101 177
102/* 178/*
103 * make sure the single step bit is not set 179 * update the contents of the MN10300 userspace FPU registers
104 */ 180 */
105void ptrace_disable(struct task_struct *child) 181static int fpuregs_set(struct task_struct *target,
182 const struct user_regset *regset,
183 unsigned int pos, unsigned int count,
184 const void *kbuf, const void __user *ubuf)
185{
186 struct fpu_state_struct fpu_state = target->thread.fpu_state;
187 int ret;
188
189 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf,
190 &fpu_state, 0, sizeof(fpu_state));
191 if (ret < 0)
192 return ret;
193
194 fpu_kill_state(target);
195 target->thread.fpu_state = fpu_state;
196 set_using_fpu(target);
197
198 return user_regset_copyin_ignore(&pos, &count, &kbuf, &ubuf,
199 sizeof(fpu_state), -1);
200}
201
202/*
203 * determine if the FPU registers have actually been used
204 */
205static int fpuregs_active(struct task_struct *target,
206 const struct user_regset *regset)
207{
208 return is_using_fpu(target) ? regset->n : 0;
209}
210
211/*
212 * Define the register sets available on the MN10300 under Linux
213 */
214enum mn10300_regset {
215 REGSET_GENERAL,
216 REGSET_FPU,
217};
218
219static const struct user_regset mn10300_regsets[] = {
220 /*
221 * General register format is:
222 * A3, A2, D3, D2, MCVF, MCRL, MCRH, MDRQ
223 * E1, E0, E7...E2, SP, LAR, LIR, MDR
224 * A1, A0, D1, D0, ORIG_D0, EPSW, PC
225 */
226 [REGSET_GENERAL] = {
227 .core_note_type = NT_PRSTATUS,
228 .n = ELF_NGREG,
229 .size = sizeof(long),
230 .align = sizeof(long),
231 .get = genregs_get,
232 .set = genregs_set,
233 },
234 /*
235 * FPU register format is:
236 * FS0-31, FPCR
237 */
238 [REGSET_FPU] = {
239 .core_note_type = NT_PRFPREG,
240 .n = sizeof(struct fpu_state_struct) / sizeof(long),
241 .size = sizeof(long),
242 .align = sizeof(long),
243 .get = fpuregs_get,
244 .set = fpuregs_set,
245 .active = fpuregs_active,
246 },
247};
248
249static const struct user_regset_view user_mn10300_native_view = {
250 .name = "mn10300",
251 .e_machine = EM_MN10300,
252 .regsets = mn10300_regsets,
253 .n = ARRAY_SIZE(mn10300_regsets),
254};
255
256const struct user_regset_view *task_user_regset_view(struct task_struct *task)
257{
258 return &user_mn10300_native_view;
259}
260
261/*
262 * set the single-step bit
263 */
264void user_enable_single_step(struct task_struct *child)
106{ 265{
107#ifndef CONFIG_MN10300_USING_JTAG 266#ifndef CONFIG_MN10300_USING_JTAG
108 struct user *dummy = NULL; 267 struct user *dummy = NULL;
109 long tmp; 268 long tmp;
110 269
111 tmp = get_stack_long(child, (unsigned long) &dummy->regs.epsw); 270 tmp = get_stack_long(child, (unsigned long) &dummy->regs.epsw);
112 tmp &= ~EPSW_T; 271 tmp |= EPSW_T;
113 put_stack_long(child, (unsigned long) &dummy->regs.epsw, tmp); 272 put_stack_long(child, (unsigned long) &dummy->regs.epsw, tmp);
114#endif 273#endif
115} 274}
116 275
117/* 276/*
118 * set the single step bit 277 * make sure the single-step bit is not set
119 */ 278 */
120void ptrace_enable(struct task_struct *child) 279void user_disable_single_step(struct task_struct *child)
121{ 280{
122#ifndef CONFIG_MN10300_USING_JTAG 281#ifndef CONFIG_MN10300_USING_JTAG
123 struct user *dummy = NULL; 282 struct user *dummy = NULL;
124 long tmp; 283 long tmp;
125 284
126 tmp = get_stack_long(child, (unsigned long) &dummy->regs.epsw); 285 tmp = get_stack_long(child, (unsigned long) &dummy->regs.epsw);
127 tmp |= EPSW_T; 286 tmp &= ~EPSW_T;
128 put_stack_long(child, (unsigned long) &dummy->regs.epsw, tmp); 287 put_stack_long(child, (unsigned long) &dummy->regs.epsw, tmp);
129#endif 288#endif
130} 289}
131 290
291void ptrace_disable(struct task_struct *child)
292{
293 user_disable_single_step(child);
294}
295
132/* 296/*
133 * handle the arch-specific side of process tracing 297 * handle the arch-specific side of process tracing
134 */ 298 */
135long arch_ptrace(struct task_struct *child, long request, long addr, long data) 299long arch_ptrace(struct task_struct *child, long request, long addr, long data)
136{ 300{
137 struct fpu_state_struct fpu_state; 301 unsigned long tmp;
138 int i, ret; 302 int ret;
139 303
140 switch (request) { 304 switch (request) {
141 /* read the word at location addr. */
142 case PTRACE_PEEKTEXT: {
143 unsigned long tmp;
144 int copied;
145
146 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
147 ret = -EIO;
148 if (copied != sizeof(tmp))
149 break;
150 ret = put_user(tmp, (unsigned long *) data);
151 break;
152 }
153
154 /* read the word at location addr. */
155 case PTRACE_PEEKDATA: {
156 unsigned long tmp;
157 int copied;
158
159 copied = access_process_vm(child, addr, &tmp, sizeof(tmp), 0);
160 ret = -EIO;
161 if (copied != sizeof(tmp))
162 break;
163 ret = put_user(tmp, (unsigned long *) data);
164 break;
165 }
166
167 /* read the word at location addr in the USER area. */ 305 /* read the word at location addr in the USER area. */
168 case PTRACE_PEEKUSR: { 306 case PTRACE_PEEKUSR:
169 unsigned long tmp;
170
171 ret = -EIO; 307 ret = -EIO;
172 if ((addr & 3) || addr < 0 || 308 if ((addr & 3) || addr < 0 ||
173 addr > sizeof(struct user) - 3) 309 addr > sizeof(struct user) - 3)
@@ -179,17 +315,6 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
179 ptrace_regid_to_frame[addr]); 315 ptrace_regid_to_frame[addr]);
180 ret = put_user(tmp, (unsigned long *) data); 316 ret = put_user(tmp, (unsigned long *) data);
181 break; 317 break;
182 }
183
184 /* write the word at location addr. */
185 case PTRACE_POKETEXT:
186 case PTRACE_POKEDATA:
187 if (access_process_vm(child, addr, &data, sizeof(data), 1) ==
188 sizeof(data))
189 ret = 0;
190 else
191 ret = -EIO;
192 break;
193 318
194 /* write the word at location addr in the USER area */ 319 /* write the word at location addr in the USER area */
195 case PTRACE_POKEUSR: 320 case PTRACE_POKEUSR:
@@ -204,132 +329,32 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
204 data); 329 data);
205 break; 330 break;
206 331
207 /* continue and stop at next (return from) syscall */ 332 case PTRACE_GETREGS: /* Get all integer regs from the child. */
208 case PTRACE_SYSCALL: 333 return copy_regset_to_user(child, &user_mn10300_native_view,
209 /* restart after signal. */ 334 REGSET_GENERAL,
210 case PTRACE_CONT: 335 0, NR_PTREGS * sizeof(long),
211 ret = -EIO; 336 (void __user *)data);
212 if ((unsigned long) data > _NSIG) 337
213 break; 338 case PTRACE_SETREGS: /* Set all integer regs in the child. */
214 if (request == PTRACE_SYSCALL) 339 return copy_regset_from_user(child, &user_mn10300_native_view,
215 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE); 340 REGSET_GENERAL,
216 else 341 0, NR_PTREGS * sizeof(long),
217 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE); 342 (const void __user *)data);
218 child->exit_code = data; 343
219 ptrace_disable(child); 344 case PTRACE_GETFPREGS: /* Get the child FPU state. */
220 wake_up_process(child); 345 return copy_regset_to_user(child, &user_mn10300_native_view,
221 ret = 0; 346 REGSET_FPU,
222 break; 347 0, sizeof(struct fpu_state_struct),
223 348 (void __user *)data);
224 /* 349
225 * make the child exit 350 case PTRACE_SETFPREGS: /* Set the child FPU state. */
226 * - the best I can do is send it a sigkill 351 return copy_regset_from_user(child, &user_mn10300_native_view,
227 * - perhaps it should be put in the status that it wants to 352 REGSET_FPU,
228 * exit 353 0, sizeof(struct fpu_state_struct),
229 */ 354 (const void __user *)data);
230 case PTRACE_KILL:
231 ret = 0;
232 if (child->exit_state == EXIT_ZOMBIE) /* already dead */
233 break;
234 child->exit_code = SIGKILL;
235 clear_tsk_thread_flag(child, TIF_SINGLESTEP);
236 ptrace_disable(child);
237 wake_up_process(child);
238 break;
239
240 case PTRACE_SINGLESTEP: /* set the trap flag. */
241#ifndef CONFIG_MN10300_USING_JTAG
242 ret = -EIO;
243 if ((unsigned long) data > _NSIG)
244 break;
245 clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
246 ptrace_enable(child);
247 child->exit_code = data;
248 wake_up_process(child);
249 ret = 0;
250#else
251 ret = -EINVAL;
252#endif
253 break;
254
255 case PTRACE_DETACH: /* detach a process that was attached. */
256 ret = ptrace_detach(child, data);
257 break;
258
259 /* Get all gp regs from the child. */
260 case PTRACE_GETREGS: {
261 unsigned long tmp;
262
263 if (!access_ok(VERIFY_WRITE, (unsigned *) data, NR_PTREGS << 2)) {
264 ret = -EIO;
265 break;
266 }
267
268 for (i = 0; i < NR_PTREGS << 2; i += 4) {
269 tmp = get_stack_long(child, ptrace_regid_to_frame[i]);
270 __put_user(tmp, (unsigned long *) data);
271 data += sizeof(tmp);
272 }
273 ret = 0;
274 break;
275 }
276
277 case PTRACE_SETREGS: { /* Set all gp regs in the child. */
278 unsigned long tmp;
279
280 if (!access_ok(VERIFY_READ, (unsigned long *)data,
281 sizeof(struct pt_regs))) {
282 ret = -EIO;
283 break;
284 }
285
286 for (i = 0; i < NR_PTREGS << 2; i += 4) {
287 __get_user(tmp, (unsigned long *) data);
288 put_stack_long(child, ptrace_regid_to_frame[i], tmp);
289 data += sizeof(tmp);
290 }
291 ret = 0;
292 break;
293 }
294
295 case PTRACE_GETFPREGS: { /* Get the child FPU state. */
296 if (is_using_fpu(child)) {
297 unlazy_fpu(child);
298 fpu_state = child->thread.fpu_state;
299 } else {
300 memset(&fpu_state, 0, sizeof(fpu_state));
301 }
302
303 ret = -EIO;
304 if (copy_to_user((void *) data, &fpu_state,
305 sizeof(fpu_state)) == 0)
306 ret = 0;
307 break;
308 }
309
310 case PTRACE_SETFPREGS: { /* Set the child FPU state. */
311 ret = -EFAULT;
312 if (copy_from_user(&fpu_state, (const void *) data,
313 sizeof(fpu_state)) == 0) {
314 fpu_kill_state(child);
315 child->thread.fpu_state = fpu_state;
316 set_using_fpu(child);
317 ret = 0;
318 }
319 break;
320 }
321
322 case PTRACE_SETOPTIONS: {
323 if (data & PTRACE_O_TRACESYSGOOD)
324 child->ptrace |= PT_TRACESYSGOOD;
325 else
326 child->ptrace &= ~PT_TRACESYSGOOD;
327 ret = 0;
328 break;
329 }
330 355
331 default: 356 default:
332 ret = -EIO; 357 ret = ptrace_request(child, request, addr, data);
333 break; 358 break;
334 } 359 }
335 360
@@ -337,43 +362,26 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
337} 362}
338 363
339/* 364/*
340 * notification of system call entry/exit 365 * handle tracing of system call entry
341 * - triggered by current->work.syscall_trace 366 * - return the revised system call number or ULONG_MAX to cause ENOSYS
342 */ 367 */
343asmlinkage void do_syscall_trace(struct pt_regs *regs, int entryexit) 368asmlinkage unsigned long syscall_trace_entry(struct pt_regs *regs)
344{ 369{
345#if 0 370 if (tracehook_report_syscall_entry(regs))
346 /* just in case... */ 371 /* tracing decided this syscall should not happen, so
347 printk(KERN_DEBUG "[%d] syscall_%lu(%lx,%lx,%lx,%lx) = %lx\n", 372 * We'll return a bogus call number to get an ENOSYS
348 current->pid, 373 * error, but leave the original number in
349 regs->orig_d0, 374 * regs->orig_d0
350 regs->a0, 375 */
351 regs->d1, 376 return ULONG_MAX;
352 regs->a3,
353 regs->a2,
354 regs->d0);
355 return;
356#endif
357
358 if (!test_thread_flag(TIF_SYSCALL_TRACE) &&
359 !test_thread_flag(TIF_SINGLESTEP))
360 return;
361 if (!(current->ptrace & PT_PTRACED))
362 return;
363 377
364 /* the 0x80 provides a way for the tracing parent to distinguish 378 return regs->orig_d0;
365 between a syscall stop and SIGTRAP delivery */ 379}
366 ptrace_notify(SIGTRAP |
367 ((current->ptrace & PT_TRACESYSGOOD) &&
368 !test_thread_flag(TIF_SINGLESTEP) ? 0x80 : 0));
369 380
370 /* 381/*
371 * this isn't the same as continuing with a signal, but it will do 382 * handle tracing of system call exit
372 * for normal use. strace only continues with a signal if the 383 */
373 * stopping signal is not SIGTRAP. -brl 384asmlinkage void syscall_trace_exit(struct pt_regs *regs)
374 */ 385{
375 if (current->exit_code) { 386 tracehook_report_syscall_exit(regs, 0);
376 send_sig(current->exit_code, current, 1);
377 current->exit_code = 0;
378 }
379} 387}
diff --git a/arch/mn10300/kernel/signal.c b/arch/mn10300/kernel/signal.c
index 841ca9955a18..9f7572a0f578 100644
--- a/arch/mn10300/kernel/signal.c
+++ b/arch/mn10300/kernel/signal.c
@@ -23,6 +23,7 @@
23#include <linux/tty.h> 23#include <linux/tty.h>
24#include <linux/personality.h> 24#include <linux/personality.h>
25#include <linux/suspend.h> 25#include <linux/suspend.h>
26#include <linux/tracehook.h>
26#include <asm/cacheflush.h> 27#include <asm/cacheflush.h>
27#include <asm/ucontext.h> 28#include <asm/ucontext.h>
28#include <asm/uaccess.h> 29#include <asm/uaccess.h>
@@ -511,6 +512,9 @@ static void do_signal(struct pt_regs *regs)
511 * clear the TIF_RESTORE_SIGMASK flag */ 512 * clear the TIF_RESTORE_SIGMASK flag */
512 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 513 if (test_thread_flag(TIF_RESTORE_SIGMASK))
513 clear_thread_flag(TIF_RESTORE_SIGMASK); 514 clear_thread_flag(TIF_RESTORE_SIGMASK);
515
516 tracehook_signal_handler(signr, &info, &ka, regs,
517 test_thread_flag(TIF_SINGLESTEP));
514 } 518 }
515 519
516 return; 520 return;
@@ -561,4 +565,9 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, u32 thread_info_flags)
561 /* deal with pending signal delivery */ 565 /* deal with pending signal delivery */
562 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 566 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
563 do_signal(regs); 567 do_signal(regs);
568
569 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
570 clear_thread_flag(TIF_NOTIFY_RESUME);
571 tracehook_notify_resume(__frame);
572 }
564} 573}
diff --git a/arch/mn10300/mm/tlb-mn10300.S b/arch/mn10300/mm/tlb-mn10300.S
index 789208094e98..7095147dcb8b 100644
--- a/arch/mn10300/mm/tlb-mn10300.S
+++ b/arch/mn10300/mm/tlb-mn10300.S
@@ -165,24 +165,6 @@ ENTRY(itlb_aerror)
165ENTRY(dtlb_aerror) 165ENTRY(dtlb_aerror)
166 and ~EPSW_NMID,epsw 166 and ~EPSW_NMID,epsw
167 add -4,sp 167 add -4,sp
168 mov d1,(sp)
169
170 movhu (MMUFCR_DFC),d1 # is it the initial valid write
171 # to this page?
172 and MMUFCR_xFC_INITWR,d1
173 beq dtlb_pagefault # jump if not
174
175 mov (DPTEL),d1 # set the dirty bit
176 # (don't replace with BSET!)
177 or _PAGE_DIRTY,d1
178 mov d1,(DPTEL)
179 mov (sp),d1
180 add 4,sp
181 rti
182
183 ALIGN
184dtlb_pagefault:
185 mov (sp),d1
186 SAVE_ALL 168 SAVE_ALL
187 add -4,sp # need to pass three params 169 add -4,sp # need to pass three params
188 170
diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 9057335fdc61..2cf915e51e7e 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -41,6 +41,12 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *v)
41 return !!(v->arch.pending_exceptions); 41 return !!(v->arch.pending_exceptions);
42} 42}
43 43
44int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu)
45{
46 /* do real check here */
47 return 1;
48}
49
44int kvm_arch_vcpu_runnable(struct kvm_vcpu *v) 50int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
45{ 51{
46 return !(v->arch.msr & MSR_WE); 52 return !(v->arch.msr & MSR_WE);
diff --git a/arch/powerpc/sysdev/axonram.c b/arch/powerpc/sysdev/axonram.c
index 9e105cbc5e5f..a4779912a5ca 100644
--- a/arch/powerpc/sysdev/axonram.c
+++ b/arch/powerpc/sysdev/axonram.c
@@ -250,7 +250,7 @@ axon_ram_probe(struct of_device *device, const struct of_device_id *device_id)
250 250
251 set_capacity(bank->disk, bank->size >> AXON_RAM_SECTOR_SHIFT); 251 set_capacity(bank->disk, bank->size >> AXON_RAM_SECTOR_SHIFT);
252 blk_queue_make_request(bank->disk->queue, axon_ram_make_request); 252 blk_queue_make_request(bank->disk->queue, axon_ram_make_request);
253 blk_queue_hardsect_size(bank->disk->queue, AXON_RAM_SECTOR_SIZE); 253 blk_queue_logical_block_size(bank->disk->queue, AXON_RAM_SECTOR_SIZE);
254 add_disk(bank->disk); 254 add_disk(bank->disk);
255 255
256 bank->irq_id = irq_of_parse_and_map(device->node, 0); 256 bank->irq_id = irq_of_parse_and_map(device->node, 0);
diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h
index 54ea39f96ecd..a27d0d5a6f86 100644
--- a/arch/s390/include/asm/kvm_host.h
+++ b/arch/s390/include/asm/kvm_host.h
@@ -13,6 +13,8 @@
13 13
14#ifndef ASM_KVM_HOST_H 14#ifndef ASM_KVM_HOST_H
15#define ASM_KVM_HOST_H 15#define ASM_KVM_HOST_H
16#include <linux/hrtimer.h>
17#include <linux/interrupt.h>
16#include <linux/kvm_host.h> 18#include <linux/kvm_host.h>
17#include <asm/debug.h> 19#include <asm/debug.h>
18#include <asm/cpuid.h> 20#include <asm/cpuid.h>
@@ -210,7 +212,8 @@ struct kvm_vcpu_arch {
210 s390_fp_regs guest_fpregs; 212 s390_fp_regs guest_fpregs;
211 unsigned int guest_acrs[NUM_ACRS]; 213 unsigned int guest_acrs[NUM_ACRS];
212 struct kvm_s390_local_interrupt local_int; 214 struct kvm_s390_local_interrupt local_int;
213 struct timer_list ckc_timer; 215 struct hrtimer ckc_timer;
216 struct tasklet_struct tasklet;
214 union { 217 union {
215 cpuid_t cpu_id; 218 cpuid_t cpu_id;
216 u64 stidp_data; 219 u64 stidp_data;
diff --git a/arch/s390/kvm/intercept.c b/arch/s390/kvm/intercept.c
index 9d19803111ba..98997ccba501 100644
--- a/arch/s390/kvm/intercept.c
+++ b/arch/s390/kvm/intercept.c
@@ -154,17 +154,25 @@ static int handle_stop(struct kvm_vcpu *vcpu)
154static int handle_validity(struct kvm_vcpu *vcpu) 154static int handle_validity(struct kvm_vcpu *vcpu)
155{ 155{
156 int viwhy = vcpu->arch.sie_block->ipb >> 16; 156 int viwhy = vcpu->arch.sie_block->ipb >> 16;
157 int rc;
158
157 vcpu->stat.exit_validity++; 159 vcpu->stat.exit_validity++;
158 if (viwhy == 0x37) { 160 if ((viwhy == 0x37) && (vcpu->arch.sie_block->prefix
159 fault_in_pages_writeable((char __user *) 161 <= vcpu->kvm->arch.guest_memsize - 2*PAGE_SIZE)){
160 vcpu->kvm->arch.guest_origin + 162 rc = fault_in_pages_writeable((char __user *)
161 vcpu->arch.sie_block->prefix, 163 vcpu->kvm->arch.guest_origin +
162 PAGE_SIZE); 164 vcpu->arch.sie_block->prefix,
163 return 0; 165 2*PAGE_SIZE);
164 } 166 if (rc)
165 VCPU_EVENT(vcpu, 2, "unhandled validity intercept code %d", 167 /* user will receive sigsegv, exit to user */
166 viwhy); 168 rc = -ENOTSUPP;
167 return -ENOTSUPP; 169 } else
170 rc = -ENOTSUPP;
171
172 if (rc)
173 VCPU_EVENT(vcpu, 2, "unhandled validity intercept code %d",
174 viwhy);
175 return rc;
168} 176}
169 177
170static int handle_instruction(struct kvm_vcpu *vcpu) 178static int handle_instruction(struct kvm_vcpu *vcpu)
diff --git a/arch/s390/kvm/interrupt.c b/arch/s390/kvm/interrupt.c
index 0189356fe209..f04f5301b1b4 100644
--- a/arch/s390/kvm/interrupt.c
+++ b/arch/s390/kvm/interrupt.c
@@ -12,6 +12,8 @@
12 12
13#include <asm/lowcore.h> 13#include <asm/lowcore.h>
14#include <asm/uaccess.h> 14#include <asm/uaccess.h>
15#include <linux/hrtimer.h>
16#include <linux/interrupt.h>
15#include <linux/kvm_host.h> 17#include <linux/kvm_host.h>
16#include <linux/signal.h> 18#include <linux/signal.h>
17#include "kvm-s390.h" 19#include "kvm-s390.h"
@@ -299,13 +301,13 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu)
299 } 301 }
300 302
301 if ((!rc) && atomic_read(&fi->active)) { 303 if ((!rc) && atomic_read(&fi->active)) {
302 spin_lock_bh(&fi->lock); 304 spin_lock(&fi->lock);
303 list_for_each_entry(inti, &fi->list, list) 305 list_for_each_entry(inti, &fi->list, list)
304 if (__interrupt_is_deliverable(vcpu, inti)) { 306 if (__interrupt_is_deliverable(vcpu, inti)) {
305 rc = 1; 307 rc = 1;
306 break; 308 break;
307 } 309 }
308 spin_unlock_bh(&fi->lock); 310 spin_unlock(&fi->lock);
309 } 311 }
310 312
311 if ((!rc) && (vcpu->arch.sie_block->ckc < 313 if ((!rc) && (vcpu->arch.sie_block->ckc <
@@ -318,6 +320,12 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *vcpu)
318 return rc; 320 return rc;
319} 321}
320 322
323int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu)
324{
325 /* do real check here */
326 return 1;
327}
328
321int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu) 329int kvm_cpu_has_pending_timer(struct kvm_vcpu *vcpu)
322{ 330{
323 return 0; 331 return 0;
@@ -355,14 +363,12 @@ int kvm_s390_handle_wait(struct kvm_vcpu *vcpu)
355 return 0; 363 return 0;
356 } 364 }
357 365
358 sltime = (vcpu->arch.sie_block->ckc - now) / (0xf4240000ul / HZ) + 1; 366 sltime = ((vcpu->arch.sie_block->ckc - now)*125)>>9;
359 367
360 vcpu->arch.ckc_timer.expires = jiffies + sltime; 368 hrtimer_start(&vcpu->arch.ckc_timer, ktime_set (0, sltime) , HRTIMER_MODE_REL);
361 369 VCPU_EVENT(vcpu, 5, "enabled wait via clock comparator: %llx ns", sltime);
362 add_timer(&vcpu->arch.ckc_timer);
363 VCPU_EVENT(vcpu, 5, "enabled wait timer:%llx jiffies", sltime);
364no_timer: 370no_timer:
365 spin_lock_bh(&vcpu->arch.local_int.float_int->lock); 371 spin_lock(&vcpu->arch.local_int.float_int->lock);
366 spin_lock_bh(&vcpu->arch.local_int.lock); 372 spin_lock_bh(&vcpu->arch.local_int.lock);
367 add_wait_queue(&vcpu->arch.local_int.wq, &wait); 373 add_wait_queue(&vcpu->arch.local_int.wq, &wait);
368 while (list_empty(&vcpu->arch.local_int.list) && 374 while (list_empty(&vcpu->arch.local_int.list) &&
@@ -371,33 +377,46 @@ no_timer:
371 !signal_pending(current)) { 377 !signal_pending(current)) {
372 set_current_state(TASK_INTERRUPTIBLE); 378 set_current_state(TASK_INTERRUPTIBLE);
373 spin_unlock_bh(&vcpu->arch.local_int.lock); 379 spin_unlock_bh(&vcpu->arch.local_int.lock);
374 spin_unlock_bh(&vcpu->arch.local_int.float_int->lock); 380 spin_unlock(&vcpu->arch.local_int.float_int->lock);
375 vcpu_put(vcpu); 381 vcpu_put(vcpu);
376 schedule(); 382 schedule();
377 vcpu_load(vcpu); 383 vcpu_load(vcpu);
378 spin_lock_bh(&vcpu->arch.local_int.float_int->lock); 384 spin_lock(&vcpu->arch.local_int.float_int->lock);
379 spin_lock_bh(&vcpu->arch.local_int.lock); 385 spin_lock_bh(&vcpu->arch.local_int.lock);
380 } 386 }
381 __unset_cpu_idle(vcpu); 387 __unset_cpu_idle(vcpu);
382 __set_current_state(TASK_RUNNING); 388 __set_current_state(TASK_RUNNING);
383 remove_wait_queue(&vcpu->wq, &wait); 389 remove_wait_queue(&vcpu->wq, &wait);
384 spin_unlock_bh(&vcpu->arch.local_int.lock); 390 spin_unlock_bh(&vcpu->arch.local_int.lock);
385 spin_unlock_bh(&vcpu->arch.local_int.float_int->lock); 391 spin_unlock(&vcpu->arch.local_int.float_int->lock);
386 del_timer(&vcpu->arch.ckc_timer); 392 hrtimer_try_to_cancel(&vcpu->arch.ckc_timer);
387 return 0; 393 return 0;
388} 394}
389 395
390void kvm_s390_idle_wakeup(unsigned long data) 396void kvm_s390_tasklet(unsigned long parm)
391{ 397{
392 struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data; 398 struct kvm_vcpu *vcpu = (struct kvm_vcpu *) parm;
393 399
394 spin_lock_bh(&vcpu->arch.local_int.lock); 400 spin_lock(&vcpu->arch.local_int.lock);
395 vcpu->arch.local_int.timer_due = 1; 401 vcpu->arch.local_int.timer_due = 1;
396 if (waitqueue_active(&vcpu->arch.local_int.wq)) 402 if (waitqueue_active(&vcpu->arch.local_int.wq))
397 wake_up_interruptible(&vcpu->arch.local_int.wq); 403 wake_up_interruptible(&vcpu->arch.local_int.wq);
398 spin_unlock_bh(&vcpu->arch.local_int.lock); 404 spin_unlock(&vcpu->arch.local_int.lock);
399} 405}
400 406
407/*
408 * low level hrtimer wake routine. Because this runs in hardirq context
409 * we schedule a tasklet to do the real work.
410 */
411enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer)
412{
413 struct kvm_vcpu *vcpu;
414
415 vcpu = container_of(timer, struct kvm_vcpu, arch.ckc_timer);
416 tasklet_schedule(&vcpu->arch.tasklet);
417
418 return HRTIMER_NORESTART;
419}
401 420
402void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu) 421void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
403{ 422{
@@ -436,7 +455,7 @@ void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
436 if (atomic_read(&fi->active)) { 455 if (atomic_read(&fi->active)) {
437 do { 456 do {
438 deliver = 0; 457 deliver = 0;
439 spin_lock_bh(&fi->lock); 458 spin_lock(&fi->lock);
440 list_for_each_entry_safe(inti, n, &fi->list, list) { 459 list_for_each_entry_safe(inti, n, &fi->list, list) {
441 if (__interrupt_is_deliverable(vcpu, inti)) { 460 if (__interrupt_is_deliverable(vcpu, inti)) {
442 list_del(&inti->list); 461 list_del(&inti->list);
@@ -447,7 +466,7 @@ void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu)
447 } 466 }
448 if (list_empty(&fi->list)) 467 if (list_empty(&fi->list))
449 atomic_set(&fi->active, 0); 468 atomic_set(&fi->active, 0);
450 spin_unlock_bh(&fi->lock); 469 spin_unlock(&fi->lock);
451 if (deliver) { 470 if (deliver) {
452 __do_deliver_interrupt(vcpu, inti); 471 __do_deliver_interrupt(vcpu, inti);
453 kfree(inti); 472 kfree(inti);
@@ -512,7 +531,7 @@ int kvm_s390_inject_vm(struct kvm *kvm,
512 531
513 mutex_lock(&kvm->lock); 532 mutex_lock(&kvm->lock);
514 fi = &kvm->arch.float_int; 533 fi = &kvm->arch.float_int;
515 spin_lock_bh(&fi->lock); 534 spin_lock(&fi->lock);
516 list_add_tail(&inti->list, &fi->list); 535 list_add_tail(&inti->list, &fi->list);
517 atomic_set(&fi->active, 1); 536 atomic_set(&fi->active, 1);
518 sigcpu = find_first_bit(fi->idle_mask, KVM_MAX_VCPUS); 537 sigcpu = find_first_bit(fi->idle_mask, KVM_MAX_VCPUS);
@@ -529,7 +548,7 @@ int kvm_s390_inject_vm(struct kvm *kvm,
529 if (waitqueue_active(&li->wq)) 548 if (waitqueue_active(&li->wq))
530 wake_up_interruptible(&li->wq); 549 wake_up_interruptible(&li->wq);
531 spin_unlock_bh(&li->lock); 550 spin_unlock_bh(&li->lock);
532 spin_unlock_bh(&fi->lock); 551 spin_unlock(&fi->lock);
533 mutex_unlock(&kvm->lock); 552 mutex_unlock(&kvm->lock);
534 return 0; 553 return 0;
535} 554}
diff --git a/arch/s390/kvm/kvm-s390.c b/arch/s390/kvm/kvm-s390.c
index f4d56e9939c9..10bccd1f8aee 100644
--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -15,6 +15,7 @@
15#include <linux/compiler.h> 15#include <linux/compiler.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/fs.h> 17#include <linux/fs.h>
18#include <linux/hrtimer.h>
18#include <linux/init.h> 19#include <linux/init.h>
19#include <linux/kvm.h> 20#include <linux/kvm.h>
20#include <linux/kvm_host.h> 21#include <linux/kvm_host.h>
@@ -195,6 +196,10 @@ out_nokvm:
195void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu) 196void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)
196{ 197{
197 VCPU_EVENT(vcpu, 3, "%s", "free cpu"); 198 VCPU_EVENT(vcpu, 3, "%s", "free cpu");
199 if (vcpu->kvm->arch.sca->cpu[vcpu->vcpu_id].sda ==
200 (__u64) vcpu->arch.sie_block)
201 vcpu->kvm->arch.sca->cpu[vcpu->vcpu_id].sda = 0;
202 smp_mb();
198 free_page((unsigned long)(vcpu->arch.sie_block)); 203 free_page((unsigned long)(vcpu->arch.sie_block));
199 kvm_vcpu_uninit(vcpu); 204 kvm_vcpu_uninit(vcpu);
200 kfree(vcpu); 205 kfree(vcpu);
@@ -283,8 +288,10 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
283 vcpu->arch.sie_block->gmsor = vcpu->kvm->arch.guest_origin; 288 vcpu->arch.sie_block->gmsor = vcpu->kvm->arch.guest_origin;
284 vcpu->arch.sie_block->ecb = 2; 289 vcpu->arch.sie_block->ecb = 2;
285 vcpu->arch.sie_block->eca = 0xC1002001U; 290 vcpu->arch.sie_block->eca = 0xC1002001U;
286 setup_timer(&vcpu->arch.ckc_timer, kvm_s390_idle_wakeup, 291 hrtimer_init(&vcpu->arch.ckc_timer, CLOCK_REALTIME, HRTIMER_MODE_ABS);
287 (unsigned long) vcpu); 292 tasklet_init(&vcpu->arch.tasklet, kvm_s390_tasklet,
293 (unsigned long) vcpu);
294 vcpu->arch.ckc_timer.function = kvm_s390_idle_wakeup;
288 get_cpu_id(&vcpu->arch.cpu_id); 295 get_cpu_id(&vcpu->arch.cpu_id);
289 vcpu->arch.cpu_id.version = 0xff; 296 vcpu->arch.cpu_id.version = 0xff;
290 return 0; 297 return 0;
@@ -307,19 +314,21 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm,
307 314
308 vcpu->arch.sie_block->icpua = id; 315 vcpu->arch.sie_block->icpua = id;
309 BUG_ON(!kvm->arch.sca); 316 BUG_ON(!kvm->arch.sca);
310 BUG_ON(kvm->arch.sca->cpu[id].sda); 317 if (!kvm->arch.sca->cpu[id].sda)
311 kvm->arch.sca->cpu[id].sda = (__u64) vcpu->arch.sie_block; 318 kvm->arch.sca->cpu[id].sda = (__u64) vcpu->arch.sie_block;
319 else
320 BUG_ON(!kvm->vcpus[id]); /* vcpu does already exist */
312 vcpu->arch.sie_block->scaoh = (__u32)(((__u64)kvm->arch.sca) >> 32); 321 vcpu->arch.sie_block->scaoh = (__u32)(((__u64)kvm->arch.sca) >> 32);
313 vcpu->arch.sie_block->scaol = (__u32)(__u64)kvm->arch.sca; 322 vcpu->arch.sie_block->scaol = (__u32)(__u64)kvm->arch.sca;
314 323
315 spin_lock_init(&vcpu->arch.local_int.lock); 324 spin_lock_init(&vcpu->arch.local_int.lock);
316 INIT_LIST_HEAD(&vcpu->arch.local_int.list); 325 INIT_LIST_HEAD(&vcpu->arch.local_int.list);
317 vcpu->arch.local_int.float_int = &kvm->arch.float_int; 326 vcpu->arch.local_int.float_int = &kvm->arch.float_int;
318 spin_lock_bh(&kvm->arch.float_int.lock); 327 spin_lock(&kvm->arch.float_int.lock);
319 kvm->arch.float_int.local_int[id] = &vcpu->arch.local_int; 328 kvm->arch.float_int.local_int[id] = &vcpu->arch.local_int;
320 init_waitqueue_head(&vcpu->arch.local_int.wq); 329 init_waitqueue_head(&vcpu->arch.local_int.wq);
321 vcpu->arch.local_int.cpuflags = &vcpu->arch.sie_block->cpuflags; 330 vcpu->arch.local_int.cpuflags = &vcpu->arch.sie_block->cpuflags;
322 spin_unlock_bh(&kvm->arch.float_int.lock); 331 spin_unlock(&kvm->arch.float_int.lock);
323 332
324 rc = kvm_vcpu_init(vcpu, kvm, id); 333 rc = kvm_vcpu_init(vcpu, kvm, id);
325 if (rc) 334 if (rc)
@@ -478,6 +487,12 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
478 487
479 vcpu_load(vcpu); 488 vcpu_load(vcpu);
480 489
490 /* verify, that memory has been registered */
491 if (!vcpu->kvm->arch.guest_memsize) {
492 vcpu_put(vcpu);
493 return -EINVAL;
494 }
495
481 if (vcpu->sigset_active) 496 if (vcpu->sigset_active)
482 sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved); 497 sigprocmask(SIG_SETMASK, &vcpu->sigset, &sigsaved);
483 498
@@ -657,6 +672,8 @@ int kvm_arch_set_memory_region(struct kvm *kvm,
657 struct kvm_memory_slot old, 672 struct kvm_memory_slot old,
658 int user_alloc) 673 int user_alloc)
659{ 674{
675 int i;
676
660 /* A few sanity checks. We can have exactly one memory slot which has 677 /* A few sanity checks. We can have exactly one memory slot which has
661 to start at guest virtual zero and which has to be located at a 678 to start at guest virtual zero and which has to be located at a
662 page boundary in userland and which has to end at a page boundary. 679 page boundary in userland and which has to end at a page boundary.
@@ -664,7 +681,7 @@ int kvm_arch_set_memory_region(struct kvm *kvm,
664 vmas. It is okay to mmap() and munmap() stuff in this slot after 681 vmas. It is okay to mmap() and munmap() stuff in this slot after
665 doing this call at any time */ 682 doing this call at any time */
666 683
667 if (mem->slot) 684 if (mem->slot || kvm->arch.guest_memsize)
668 return -EINVAL; 685 return -EINVAL;
669 686
670 if (mem->guest_phys_addr) 687 if (mem->guest_phys_addr)
@@ -676,15 +693,39 @@ int kvm_arch_set_memory_region(struct kvm *kvm,
676 if (mem->memory_size & (PAGE_SIZE - 1)) 693 if (mem->memory_size & (PAGE_SIZE - 1))
677 return -EINVAL; 694 return -EINVAL;
678 695
696 if (!user_alloc)
697 return -EINVAL;
698
699 /* lock all vcpus */
700 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
701 if (!kvm->vcpus[i])
702 continue;
703 if (!mutex_trylock(&kvm->vcpus[i]->mutex))
704 goto fail_out;
705 }
706
679 kvm->arch.guest_origin = mem->userspace_addr; 707 kvm->arch.guest_origin = mem->userspace_addr;
680 kvm->arch.guest_memsize = mem->memory_size; 708 kvm->arch.guest_memsize = mem->memory_size;
681 709
682 /* FIXME: we do want to interrupt running CPUs and update their memory 710 /* update sie control blocks, and unlock all vcpus */
683 configuration now to avoid race conditions. But hey, changing the 711 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
684 memory layout while virtual CPUs are running is usually bad 712 if (kvm->vcpus[i]) {
685 programming practice. */ 713 kvm->vcpus[i]->arch.sie_block->gmsor =
714 kvm->arch.guest_origin;
715 kvm->vcpus[i]->arch.sie_block->gmslm =
716 kvm->arch.guest_memsize +
717 kvm->arch.guest_origin +
718 VIRTIODESCSPACE - 1ul;
719 mutex_unlock(&kvm->vcpus[i]->mutex);
720 }
721 }
686 722
687 return 0; 723 return 0;
724
725fail_out:
726 for (; i >= 0; i--)
727 mutex_unlock(&kvm->vcpus[i]->mutex);
728 return -EINVAL;
688} 729}
689 730
690void kvm_arch_flush_shadow(struct kvm *kvm) 731void kvm_arch_flush_shadow(struct kvm *kvm)
diff --git a/arch/s390/kvm/kvm-s390.h b/arch/s390/kvm/kvm-s390.h
index 00bbe69b78da..748fee872323 100644
--- a/arch/s390/kvm/kvm-s390.h
+++ b/arch/s390/kvm/kvm-s390.h
@@ -14,6 +14,7 @@
14#ifndef ARCH_S390_KVM_S390_H 14#ifndef ARCH_S390_KVM_S390_H
15#define ARCH_S390_KVM_S390_H 15#define ARCH_S390_KVM_S390_H
16 16
17#include <linux/hrtimer.h>
17#include <linux/kvm.h> 18#include <linux/kvm.h>
18#include <linux/kvm_host.h> 19#include <linux/kvm_host.h>
19 20
@@ -41,7 +42,8 @@ static inline int __cpu_is_stopped(struct kvm_vcpu *vcpu)
41} 42}
42 43
43int kvm_s390_handle_wait(struct kvm_vcpu *vcpu); 44int kvm_s390_handle_wait(struct kvm_vcpu *vcpu);
44void kvm_s390_idle_wakeup(unsigned long data); 45enum hrtimer_restart kvm_s390_idle_wakeup(struct hrtimer *timer);
46void kvm_s390_tasklet(unsigned long parm);
45void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu); 47void kvm_s390_deliver_pending_interrupts(struct kvm_vcpu *vcpu);
46int kvm_s390_inject_vm(struct kvm *kvm, 48int kvm_s390_inject_vm(struct kvm *kvm,
47 struct kvm_s390_interrupt *s390int); 49 struct kvm_s390_interrupt *s390int);
diff --git a/arch/s390/kvm/priv.c b/arch/s390/kvm/priv.c
index 4b88834b8dd8..93ecd06e1a74 100644
--- a/arch/s390/kvm/priv.c
+++ b/arch/s390/kvm/priv.c
@@ -204,11 +204,11 @@ static void handle_stsi_3_2_2(struct kvm_vcpu *vcpu, struct sysinfo_3_2_2 *mem)
204 int cpus = 0; 204 int cpus = 0;
205 int n; 205 int n;
206 206
207 spin_lock_bh(&fi->lock); 207 spin_lock(&fi->lock);
208 for (n = 0; n < KVM_MAX_VCPUS; n++) 208 for (n = 0; n < KVM_MAX_VCPUS; n++)
209 if (fi->local_int[n]) 209 if (fi->local_int[n])
210 cpus++; 210 cpus++;
211 spin_unlock_bh(&fi->lock); 211 spin_unlock(&fi->lock);
212 212
213 /* deal with other level 3 hypervisors */ 213 /* deal with other level 3 hypervisors */
214 if (stsi(mem, 3, 2, 2) == -ENOSYS) 214 if (stsi(mem, 3, 2, 2) == -ENOSYS)
diff --git a/arch/s390/kvm/sigp.c b/arch/s390/kvm/sigp.c
index f27dbedf0866..36678835034d 100644
--- a/arch/s390/kvm/sigp.c
+++ b/arch/s390/kvm/sigp.c
@@ -52,7 +52,7 @@ static int __sigp_sense(struct kvm_vcpu *vcpu, u16 cpu_addr,
52 if (cpu_addr >= KVM_MAX_VCPUS) 52 if (cpu_addr >= KVM_MAX_VCPUS)
53 return 3; /* not operational */ 53 return 3; /* not operational */
54 54
55 spin_lock_bh(&fi->lock); 55 spin_lock(&fi->lock);
56 if (fi->local_int[cpu_addr] == NULL) 56 if (fi->local_int[cpu_addr] == NULL)
57 rc = 3; /* not operational */ 57 rc = 3; /* not operational */
58 else if (atomic_read(fi->local_int[cpu_addr]->cpuflags) 58 else if (atomic_read(fi->local_int[cpu_addr]->cpuflags)
@@ -64,7 +64,7 @@ static int __sigp_sense(struct kvm_vcpu *vcpu, u16 cpu_addr,
64 *reg |= SIGP_STAT_STOPPED; 64 *reg |= SIGP_STAT_STOPPED;
65 rc = 1; /* status stored */ 65 rc = 1; /* status stored */
66 } 66 }
67 spin_unlock_bh(&fi->lock); 67 spin_unlock(&fi->lock);
68 68
69 VCPU_EVENT(vcpu, 4, "sensed status of cpu %x rc %x", cpu_addr, rc); 69 VCPU_EVENT(vcpu, 4, "sensed status of cpu %x rc %x", cpu_addr, rc);
70 return rc; 70 return rc;
@@ -86,7 +86,7 @@ static int __sigp_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr)
86 86
87 inti->type = KVM_S390_INT_EMERGENCY; 87 inti->type = KVM_S390_INT_EMERGENCY;
88 88
89 spin_lock_bh(&fi->lock); 89 spin_lock(&fi->lock);
90 li = fi->local_int[cpu_addr]; 90 li = fi->local_int[cpu_addr];
91 if (li == NULL) { 91 if (li == NULL) {
92 rc = 3; /* not operational */ 92 rc = 3; /* not operational */
@@ -102,7 +102,7 @@ static int __sigp_emergency(struct kvm_vcpu *vcpu, u16 cpu_addr)
102 spin_unlock_bh(&li->lock); 102 spin_unlock_bh(&li->lock);
103 rc = 0; /* order accepted */ 103 rc = 0; /* order accepted */
104unlock: 104unlock:
105 spin_unlock_bh(&fi->lock); 105 spin_unlock(&fi->lock);
106 VCPU_EVENT(vcpu, 4, "sent sigp emerg to cpu %x", cpu_addr); 106 VCPU_EVENT(vcpu, 4, "sent sigp emerg to cpu %x", cpu_addr);
107 return rc; 107 return rc;
108} 108}
@@ -123,7 +123,7 @@ static int __sigp_stop(struct kvm_vcpu *vcpu, u16 cpu_addr, int store)
123 123
124 inti->type = KVM_S390_SIGP_STOP; 124 inti->type = KVM_S390_SIGP_STOP;
125 125
126 spin_lock_bh(&fi->lock); 126 spin_lock(&fi->lock);
127 li = fi->local_int[cpu_addr]; 127 li = fi->local_int[cpu_addr];
128 if (li == NULL) { 128 if (li == NULL) {
129 rc = 3; /* not operational */ 129 rc = 3; /* not operational */
@@ -142,7 +142,7 @@ static int __sigp_stop(struct kvm_vcpu *vcpu, u16 cpu_addr, int store)
142 spin_unlock_bh(&li->lock); 142 spin_unlock_bh(&li->lock);
143 rc = 0; /* order accepted */ 143 rc = 0; /* order accepted */
144unlock: 144unlock:
145 spin_unlock_bh(&fi->lock); 145 spin_unlock(&fi->lock);
146 VCPU_EVENT(vcpu, 4, "sent sigp stop to cpu %x", cpu_addr); 146 VCPU_EVENT(vcpu, 4, "sent sigp stop to cpu %x", cpu_addr);
147 return rc; 147 return rc;
148} 148}
@@ -188,7 +188,7 @@ static int __sigp_set_prefix(struct kvm_vcpu *vcpu, u16 cpu_addr, u32 address,
188 if (!inti) 188 if (!inti)
189 return 2; /* busy */ 189 return 2; /* busy */
190 190
191 spin_lock_bh(&fi->lock); 191 spin_lock(&fi->lock);
192 li = fi->local_int[cpu_addr]; 192 li = fi->local_int[cpu_addr];
193 193
194 if ((cpu_addr >= KVM_MAX_VCPUS) || (li == NULL)) { 194 if ((cpu_addr >= KVM_MAX_VCPUS) || (li == NULL)) {
@@ -220,7 +220,7 @@ static int __sigp_set_prefix(struct kvm_vcpu *vcpu, u16 cpu_addr, u32 address,
220out_li: 220out_li:
221 spin_unlock_bh(&li->lock); 221 spin_unlock_bh(&li->lock);
222out_fi: 222out_fi:
223 spin_unlock_bh(&fi->lock); 223 spin_unlock(&fi->lock);
224 return rc; 224 return rc;
225} 225}
226 226
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index e7390dd0283d..586cd045e2db 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -15,6 +15,7 @@ config SUPERH
15 select HAVE_IOREMAP_PROT if MMU 15 select HAVE_IOREMAP_PROT if MMU
16 select HAVE_ARCH_TRACEHOOK 16 select HAVE_ARCH_TRACEHOOK
17 select HAVE_DMA_API_DEBUG 17 select HAVE_DMA_API_DEBUG
18 select RTC_LIB
18 help 19 help
19 The SuperH is a RISC processor targeted for use in embedded systems 20 The SuperH is a RISC processor targeted for use in embedded systems
20 and consumer electronics; it was also used in the Sega Dreamcast 21 and consumer electronics; it was also used in the Sega Dreamcast
@@ -74,14 +75,18 @@ config GENERIC_IOMAP
74 bool 75 bool
75 76
76config GENERIC_TIME 77config GENERIC_TIME
77 def_bool n 78 def_bool y
78 79
79config GENERIC_CLOCKEVENTS 80config GENERIC_CLOCKEVENTS
80 def_bool n 81 def_bool y
81 82
82config GENERIC_CLOCKEVENTS_BROADCAST 83config GENERIC_CLOCKEVENTS_BROADCAST
83 bool 84 bool
84 85
86config GENERIC_CMOS_UPDATE
87 def_bool y
88 depends on SH_SH03 || SH_DREAMCAST
89
85config GENERIC_LOCKBREAK 90config GENERIC_LOCKBREAK
86 def_bool y 91 def_bool y
87 depends on SMP && PREEMPT 92 depends on SMP && PREEMPT
@@ -112,6 +117,12 @@ config SYS_SUPPORTS_PCI
112config SYS_SUPPORTS_CMT 117config SYS_SUPPORTS_CMT
113 bool 118 bool
114 119
120config SYS_SUPPORTS_MTU2
121 bool
122
123config SYS_SUPPORTS_TMU
124 bool
125
115config STACKTRACE_SUPPORT 126config STACKTRACE_SUPPORT
116 def_bool y 127 def_bool y
117 128
@@ -157,13 +168,14 @@ config CPU_SH3
157 bool 168 bool
158 select CPU_HAS_INTEVT 169 select CPU_HAS_INTEVT
159 select CPU_HAS_SR_RB 170 select CPU_HAS_SR_RB
171 select SYS_SUPPORTS_TMU
160 172
161config CPU_SH4 173config CPU_SH4
162 bool 174 bool
163 select CPU_HAS_INTEVT 175 select CPU_HAS_INTEVT
164 select CPU_HAS_SR_RB 176 select CPU_HAS_SR_RB
165 select CPU_HAS_PTEA if !CPU_SH4A || CPU_SHX2
166 select CPU_HAS_FPU if !CPU_SH4AL_DSP 177 select CPU_HAS_FPU if !CPU_SH4AL_DSP
178 select SYS_SUPPORTS_TMU
167 179
168config CPU_SH4A 180config CPU_SH4A
169 bool 181 bool
@@ -177,6 +189,7 @@ config CPU_SH4AL_DSP
177config CPU_SH5 189config CPU_SH5
178 bool 190 bool
179 select CPU_HAS_FPU 191 select CPU_HAS_FPU
192 select SYS_SUPPORTS_TMU
180 193
181config CPU_SHX2 194config CPU_SHX2
182 bool 195 bool
@@ -210,27 +223,32 @@ config CPU_SUBTYPE_SH7201
210 bool "Support SH7201 processor" 223 bool "Support SH7201 processor"
211 select CPU_SH2A 224 select CPU_SH2A
212 select CPU_HAS_FPU 225 select CPU_HAS_FPU
226 select SYS_SUPPORTS_MTU2
213 227
214config CPU_SUBTYPE_SH7203 228config CPU_SUBTYPE_SH7203
215 bool "Support SH7203 processor" 229 bool "Support SH7203 processor"
216 select CPU_SH2A 230 select CPU_SH2A
217 select CPU_HAS_FPU 231 select CPU_HAS_FPU
218 select SYS_SUPPORTS_CMT 232 select SYS_SUPPORTS_CMT
233 select SYS_SUPPORTS_MTU2
219 234
220config CPU_SUBTYPE_SH7206 235config CPU_SUBTYPE_SH7206
221 bool "Support SH7206 processor" 236 bool "Support SH7206 processor"
222 select CPU_SH2A 237 select CPU_SH2A
223 select SYS_SUPPORTS_CMT 238 select SYS_SUPPORTS_CMT
239 select SYS_SUPPORTS_MTU2
224 240
225config CPU_SUBTYPE_SH7263 241config CPU_SUBTYPE_SH7263
226 bool "Support SH7263 processor" 242 bool "Support SH7263 processor"
227 select CPU_SH2A 243 select CPU_SH2A
228 select CPU_HAS_FPU 244 select CPU_HAS_FPU
229 select SYS_SUPPORTS_CMT 245 select SYS_SUPPORTS_CMT
246 select SYS_SUPPORTS_MTU2
230 247
231config CPU_SUBTYPE_MXG 248config CPU_SUBTYPE_MXG
232 bool "Support MX-G processor" 249 bool "Support MX-G processor"
233 select CPU_SH2A 250 select CPU_SH2A
251 select SYS_SUPPORTS_MTU2
234 help 252 help
235 Select MX-G if running on an R8A03022BG part. 253 Select MX-G if running on an R8A03022BG part.
236 254
@@ -283,6 +301,7 @@ config CPU_SUBTYPE_SH7720
283 bool "Support SH7720 processor" 301 bool "Support SH7720 processor"
284 select CPU_SH3 302 select CPU_SH3
285 select CPU_HAS_DSP 303 select CPU_HAS_DSP
304 select SYS_SUPPORTS_CMT
286 help 305 help
287 Select SH7720 if you have a SH3-DSP SH7720 CPU. 306 Select SH7720 if you have a SH3-DSP SH7720 CPU.
288 307
@@ -290,6 +309,7 @@ config CPU_SUBTYPE_SH7721
290 bool "Support SH7721 processor" 309 bool "Support SH7721 processor"
291 select CPU_SH3 310 select CPU_SH3
292 select CPU_HAS_DSP 311 select CPU_HAS_DSP
312 select SYS_SUPPORTS_CMT
293 help 313 help
294 Select SH7721 if you have a SH3-DSP SH7721 CPU. 314 Select SH7721 if you have a SH3-DSP SH7721 CPU.
295 315
@@ -347,6 +367,16 @@ config CPU_SUBTYPE_SH7723
347 help 367 help
348 Select SH7723 if you have an SH-MobileR2 CPU. 368 Select SH7723 if you have an SH-MobileR2 CPU.
349 369
370config CPU_SUBTYPE_SH7724
371 bool "Support SH7724 processor"
372 select CPU_SH4A
373 select CPU_SHX2
374 select ARCH_SHMOBILE
375 select ARCH_SPARSEMEM_ENABLE
376 select SYS_SUPPORTS_CMT
377 help
378 Select SH7724 if you have an SH-MobileR2R CPU.
379
350config CPU_SUBTYPE_SH7763 380config CPU_SUBTYPE_SH7763
351 bool "Support SH7763 processor" 381 bool "Support SH7763 processor"
352 select CPU_SH4A 382 select CPU_SH4A
@@ -442,48 +472,26 @@ source "arch/sh/boards/Kconfig"
442 472
443menu "Timer and clock configuration" 473menu "Timer and clock configuration"
444 474
445config SH_TMU 475config SH_TIMER_TMU
446 bool "TMU timer support" 476 bool "TMU timer driver"
447 depends on CPU_SH3 || CPU_SH4 477 depends on SYS_SUPPORTS_TMU
448 default y 478 default y
449 select GENERIC_TIME
450 select GENERIC_CLOCKEVENTS
451 help 479 help
452 This enables the use of the TMU as the system timer. 480 This enables the build of the TMU timer driver.
453 481
454config SH_CMT 482config SH_TIMER_CMT
455 bool "CMT timer support" 483 bool "CMT timer driver"
456 depends on SYS_SUPPORTS_CMT && CPU_SH2 484 depends on SYS_SUPPORTS_CMT
457 default y 485 default y
458 help 486 help
459 This enables the use of the CMT as the system timer. 487 This enables build of the CMT timer driver.
460 488
461# 489config SH_TIMER_MTU2
462# Support for the new-style CMT driver. This will replace SH_CMT 490 bool "MTU2 timer driver"
463# once its other dependencies are merged. 491 depends on SYS_SUPPORTS_MTU2
464#
465config SH_TIMER_CMT
466 bool "CMT clockevents driver"
467 depends on SYS_SUPPORTS_CMT && !SH_CMT
468 select GENERIC_CLOCKEVENTS
469
470config SH_MTU2
471 bool "MTU2 timer support"
472 depends on CPU_SH2A
473 default y 492 default y
474 help 493 help
475 This enables the use of the MTU2 as the system timer. 494 This enables build of the MTU2 timer driver.
476
477config SH_TIMER_IRQ
478 int
479 default "28" if CPU_SUBTYPE_SH7780 || CPU_SUBTYPE_SH7785 || \
480 CPU_SUBTYPE_SH7763
481 default "86" if CPU_SUBTYPE_SH7619
482 default "140" if CPU_SUBTYPE_SH7206
483 default "142" if CPU_SUBTYPE_SH7203 && SH_CMT
484 default "153" if CPU_SUBTYPE_SH7203 && SH_MTU2
485 default "238" if CPU_SUBTYPE_MXG
486 default "16"
487 495
488config SH_PCLK_FREQ 496config SH_PCLK_FREQ
489 int "Peripheral clock frequency (in Hz)" 497 int "Peripheral clock frequency (in Hz)"
@@ -494,7 +502,7 @@ config SH_PCLK_FREQ
494 CPU_SUBTYPE_SH7760 || CPU_SUBTYPE_SH7705 || \ 502 CPU_SUBTYPE_SH7760 || CPU_SUBTYPE_SH7705 || \
495 CPU_SUBTYPE_SH7203 || CPU_SUBTYPE_SH7206 || \ 503 CPU_SUBTYPE_SH7203 || CPU_SUBTYPE_SH7206 || \
496 CPU_SUBTYPE_SH7263 || CPU_SUBTYPE_MXG || \ 504 CPU_SUBTYPE_SH7263 || CPU_SUBTYPE_MXG || \
497 CPU_SUBTYPE_SH7786 505 CPU_SUBTYPE_SH7786 || CPU_SUBTYPE_SH7724
498 default "60000000" if CPU_SUBTYPE_SH7751 || CPU_SUBTYPE_SH7751R 506 default "60000000" if CPU_SUBTYPE_SH7751 || CPU_SUBTYPE_SH7751R
499 default "66000000" if CPU_SUBTYPE_SH4_202 507 default "66000000" if CPU_SUBTYPE_SH4_202
500 default "50000000" 508 default "50000000"
@@ -503,6 +511,13 @@ config SH_PCLK_FREQ
503 This is necessary for determining the reference clock value on 511 This is necessary for determining the reference clock value on
504 platforms lacking an RTC. 512 platforms lacking an RTC.
505 513
514config SH_CLK_CPG
515 def_bool y
516
517config SH_CLK_CPG_LEGACY
518 depends on SH_CLK_CPG
519 def_bool y if !CPU_SUBTYPE_SH7785 && !ARCH_SHMOBILE
520
506config SH_CLK_MD 521config SH_CLK_MD
507 int "CPU Mode Pin Setting" 522 int "CPU Mode Pin Setting"
508 depends on CPU_SH2 523 depends on CPU_SH2
@@ -663,27 +678,54 @@ config GUSA_RB
663 LLSC, this should be more efficient than the other alternative of 678 LLSC, this should be more efficient than the other alternative of
664 disabling interrupts around the atomic sequence. 679 disabling interrupts around the atomic sequence.
665 680
681config SPARSE_IRQ
682 bool "Support sparse irq numbering"
683 depends on EXPERIMENTAL
684 help
685 This enables support for sparse irqs. This is useful in general
686 as most CPUs have a fairly sparse array of IRQ vectors, which
687 the irq_desc then maps directly on to. Systems with a high
688 number of off-chip IRQs will want to treat this as
689 experimental until they have been independently verified.
690
691 If you don't know what to do here, say N.
692
666endmenu 693endmenu
667 694
668menu "Boot options" 695menu "Boot options"
669 696
670config ZERO_PAGE_OFFSET 697config ZERO_PAGE_OFFSET
671 hex "Zero page offset" 698 hex
672 default "0x00004000" if SH_SH03 699 default "0x00010000" if PAGE_SIZE_64KB || SH_RTS7751R2D || \
673 default "0x00010000" if PAGE_SIZE_64KB 700 SH_7751_SOLUTION_ENGINE
701 default "0x00004000" if PAGE_SIZE_16KB || SH_SH03
674 default "0x00002000" if PAGE_SIZE_8KB 702 default "0x00002000" if PAGE_SIZE_8KB
675 default "0x00001000" 703 default "0x00001000"
676 help 704 help
677 This sets the default offset of zero page. 705 This sets the default offset of zero page.
678 706
679config BOOT_LINK_OFFSET 707config BOOT_LINK_OFFSET
680 hex "Link address offset for booting" 708 hex
709 default "0x00210000" if SH_SHMIN
710 default "0x00400000" if SH_CAYMAN
711 default "0x00810000" if SH_7780_SOLUTION_ENGINE
712 default "0x009e0000" if SH_TITAN
713 default "0x01800000" if SH_SDK7780
714 default "0x02000000" if SH_EDOSK7760
681 default "0x00800000" 715 default "0x00800000"
682 help 716 help
683 This option allows you to set the link address offset of the zImage. 717 This option allows you to set the link address offset of the zImage.
684 This can be useful if you are on a board which has a small amount of 718 This can be useful if you are on a board which has a small amount of
685 memory. 719 memory.
686 720
721config ENTRY_OFFSET
722 hex
723 default "0x00001000" if PAGE_SIZE_4KB
724 default "0x00002000" if PAGE_SIZE_8KB
725 default "0x00004000" if PAGE_SIZE_16KB
726 default "0x00010000" if PAGE_SIZE_64KB
727 default "0x00000000"
728
687config UBC_WAKEUP 729config UBC_WAKEUP
688 bool "Wakeup UBC on startup" 730 bool "Wakeup UBC on startup"
689 depends on CPU_SH4 && !CPU_SH4A 731 depends on CPU_SH4 && !CPU_SH4A
diff --git a/arch/sh/Kconfig.cpu b/arch/sh/Kconfig.cpu
index c7d704381a6d..cd6e3ea598d5 100644
--- a/arch/sh/Kconfig.cpu
+++ b/arch/sh/Kconfig.cpu
@@ -76,11 +76,6 @@ config SPECULATIVE_EXECUTION
76 76
77 If unsure, say N. 77 If unsure, say N.
78 78
79config SH64_USER_MISALIGNED_FIXUP
80 def_bool y
81 prompt "Fixup misaligned loads/stores occurring in user mode"
82 depends on SUPERH64
83
84config SH64_ID2815_WORKAROUND 79config SH64_ID2815_WORKAROUND
85 bool "Include workaround for SH5-101 cut2 silicon defect ID2815" 80 bool "Include workaround for SH5-101 cut2 silicon defect ID2815"
86 depends on CPU_SUBTYPE_SH5_101 81 depends on CPU_SUBTYPE_SH5_101
@@ -101,9 +96,6 @@ config CPU_HAS_SR_RB
101 See <file:Documentation/sh/register-banks.txt> for further 96 See <file:Documentation/sh/register-banks.txt> for further
102 information on SR.RB and register banking in the kernel in general. 97 information on SR.RB and register banking in the kernel in general.
103 98
104config CPU_HAS_PTEA
105 bool
106
107config CPU_HAS_PTEAEX 99config CPU_HAS_PTEAEX
108 bool 100 bool
109 101
diff --git a/arch/sh/Kconfig.debug b/arch/sh/Kconfig.debug
index 0d62681f72a0..8179cc9be9a4 100644
--- a/arch/sh/Kconfig.debug
+++ b/arch/sh/Kconfig.debug
@@ -38,10 +38,10 @@ config EARLY_SCIF_CONSOLE_PORT
38 default "0xffe00000" if CPU_SUBTYPE_SH7780 || CPU_SUBTYPE_SH7763 || \ 38 default "0xffe00000" if CPU_SUBTYPE_SH7780 || CPU_SUBTYPE_SH7763 || \
39 CPU_SUBTYPE_SH7722 || CPU_SUBTYPE_SH7366 || \ 39 CPU_SUBTYPE_SH7722 || CPU_SUBTYPE_SH7366 || \
40 CPU_SUBTYPE_SH7343 40 CPU_SUBTYPE_SH7343
41 default "0xffe80000" if CPU_SH4
42 default "0xffea0000" if CPU_SUBTYPE_SH7785 41 default "0xffea0000" if CPU_SUBTYPE_SH7785
43 default "0xfffe8000" if CPU_SUBTYPE_SH7203 42 default "0xfffe8000" if CPU_SUBTYPE_SH7203
44 default "0xfffe9800" if CPU_SUBTYPE_SH7206 || CPU_SUBTYPE_SH7263 43 default "0xfffe9800" if CPU_SUBTYPE_SH7206 || CPU_SUBTYPE_SH7263
44 default "0xffe80000" if CPU_SH4
45 default "0x00000000" 45 default "0x00000000"
46 46
47config EARLY_PRINTK 47config EARLY_PRINTK
@@ -92,7 +92,7 @@ config 4KSTACKS
92 92
93config IRQSTACKS 93config IRQSTACKS
94 bool "Use separate kernel stacks when processing interrupts" 94 bool "Use separate kernel stacks when processing interrupts"
95 depends on DEBUG_KERNEL && SUPERH32 95 depends on DEBUG_KERNEL && SUPERH32 && BROKEN
96 help 96 help
97 If you say Y here the kernel will use separate kernel stacks 97 If you say Y here the kernel will use separate kernel stacks
98 for handling hard and soft interrupts. This can help avoid 98 for handling hard and soft interrupts. This can help avoid
@@ -122,27 +122,8 @@ config SH_NO_BSS_INIT
122 For all other cases, say N. If this option seems perplexing, or 122 For all other cases, say N. If this option seems perplexing, or
123 you aren't sure, say N. 123 you aren't sure, say N.
124 124
125config MORE_COMPILE_OPTIONS
126 bool "Add any additional compile options"
127 help
128 If you want to add additional CFLAGS to the kernel build, enable this
129 option and then enter what you would like to add in the next question.
130 Note however that -g is already appended with the selection of KGDB.
131
132config COMPILE_OPTIONS
133 string "Additional compile arguments"
134 depends on MORE_COMPILE_OPTIONS
135
136config SH64_SR_WATCH 125config SH64_SR_WATCH
137 bool "Debug: set SR.WATCH to enable hardware watchpoints and trace" 126 bool "Debug: set SR.WATCH to enable hardware watchpoints and trace"
138 depends on SUPERH64 127 depends on SUPERH64
139 128
140config POOR_MANS_STRACE
141 bool "Debug: enable rudimentary strace facility"
142 depends on SUPERH64
143 help
144 This option allows system calls to be traced to the console. It also
145 aids in detecting kernel stack underflow. It is useful for debugging
146 early-userland problems (e.g. init incurring fatal exceptions.)
147
148endmenu 129endmenu
diff --git a/arch/sh/Makefile b/arch/sh/Makefile
index bece1f7535f2..75d049b03f7e 100644
--- a/arch/sh/Makefile
+++ b/arch/sh/Makefile
@@ -70,9 +70,6 @@ cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -ml
70cflags-y += $(call cc-option,-mno-fdpic) 70cflags-y += $(call cc-option,-mno-fdpic)
71cflags-y += $(isaflags-y) -ffreestanding 71cflags-y += $(isaflags-y) -ffreestanding
72 72
73cflags-$(CONFIG_MORE_COMPILE_OPTIONS) += \
74 $(shell echo $(CONFIG_COMPILE_OPTIONS) | sed -e 's/"//g')
75
76OBJCOPYFLAGS := -O binary -R .note -R .note.gnu.build-id -R .comment \ 73OBJCOPYFLAGS := -O binary -R .note -R .note.gnu.build-id -R .comment \
77 -R .stab -R .stabstr -S 74 -R .stab -R .stabstr -S
78 75
@@ -85,7 +82,6 @@ defaultimage-$(CONFIG_SH_7206_SOLUTION_ENGINE) := vmlinux
85defaultimage-$(CONFIG_SH_7619_SOLUTION_ENGINE) := vmlinux 82defaultimage-$(CONFIG_SH_7619_SOLUTION_ENGINE) := vmlinux
86 83
87# Set some sensible Kbuild defaults 84# Set some sensible Kbuild defaults
88KBUILD_DEFCONFIG := shx3_defconfig
89KBUILD_IMAGE := $(defaultimage-y) 85KBUILD_IMAGE := $(defaultimage-y)
90 86
91# 87#
@@ -93,26 +89,38 @@ KBUILD_IMAGE := $(defaultimage-y)
93# error messages during linking. 89# error messages during linking.
94# 90#
95ifdef CONFIG_SUPERH32 91ifdef CONFIG_SUPERH32
96UTS_MACHINE := sh 92UTS_MACHINE := sh
97LDFLAGS_vmlinux += -e _stext 93BITS := 32
94LDFLAGS_vmlinux += -e _stext
95KBUILD_DEFCONFIG := shx3_defconfig
98else 96else
99UTS_MACHINE := sh64 97UTS_MACHINE := sh64
100LDFLAGS_vmlinux += --defsym phys_stext=_stext-$(CONFIG_PAGE_OFFSET) \ 98BITS := 64
101 --defsym phys_stext_shmedia=phys_stext+1 \ 99LDFLAGS_vmlinux += --defsym phys_stext=_stext-$(CONFIG_PAGE_OFFSET) \
102 -e phys_stext_shmedia 100 --defsym phys_stext_shmedia=phys_stext+1 \
101 -e phys_stext_shmedia
102KBUILD_DEFCONFIG := cayman_defconfig
103endif
104
105ifneq ($(SUBARCH),$(ARCH))
106 ifeq ($(CROSS_COMPILE),)
107 CROSS_COMPILE := $(call cc-cross-prefix, $(UTS_MACHINE)-linux- $(UTS_MACHINE)-linux-gnu- $(UTS_MACHINE)-unknown-linux-gnu-)
108 endif
103endif 109endif
104 110
105ifdef CONFIG_CPU_LITTLE_ENDIAN 111ifdef CONFIG_CPU_LITTLE_ENDIAN
106LDFLAGS_vmlinux += --defsym 'jiffies=jiffies_64' 112ld-bfd := elf32-$(UTS_MACHINE)-linux
113LDFLAGS_vmlinux += --defsym 'jiffies=jiffies_64' --oformat $(ld-bfd)
107LDFLAGS += -EL 114LDFLAGS += -EL
108else 115else
109LDFLAGS_vmlinux += --defsym 'jiffies=jiffies_64+4' 116ld-bfd := elf32-$(UTS_MACHINE)big-linux
117LDFLAGS_vmlinux += --defsym 'jiffies=jiffies_64+4' --oformat $(ld-bfd)
110LDFLAGS += -EB 118LDFLAGS += -EB
111endif 119endif
112 120
113head-y := arch/sh/kernel/init_task.o 121export ld-bfd BITS
114head-$(CONFIG_SUPERH32) += arch/sh/kernel/head_32.o 122
115head-$(CONFIG_SUPERH64) += arch/sh/kernel/head_64.o 123head-y := arch/sh/kernel/init_task.o arch/sh/kernel/head_$(BITS).o
116 124
117core-y += arch/sh/kernel/ arch/sh/mm/ arch/sh/boards/ 125core-y += arch/sh/kernel/ arch/sh/mm/ arch/sh/boards/
118core-$(CONFIG_SH_FPU_EMU) += arch/sh/math-emu/ 126core-$(CONFIG_SH_FPU_EMU) += arch/sh/math-emu/
@@ -193,10 +201,11 @@ zImage uImage uImage.srec vmlinux.srec: vmlinux
193 201
194compressed: zImage 202compressed: zImage
195 203
196archprepare: maketools arch/sh/lib64/syscalltab.h 204archprepare: maketools
197 205
198archclean: 206archclean:
199 $(Q)$(MAKE) $(clean)=$(boot) 207 $(Q)$(MAKE) $(clean)=$(boot)
208 $(Q)$(MAKE) $(clean)=arch/sh/kernel/vsyscall
200 209
201define archhelp 210define archhelp
202 @echo '* zImage - Compressed kernel image' 211 @echo '* zImage - Compressed kernel image'
@@ -205,34 +214,4 @@ define archhelp
205 @echo ' uImage.srec - Create an S-record for U-Boot' 214 @echo ' uImage.srec - Create an S-record for U-Boot'
206endef 215endef
207 216
208define filechk_gen-syscalltab 217CLEAN_FILES += include/asm-sh/machtypes.h
209 (set -e; \
210 echo "/*"; \
211 echo " * DO NOT MODIFY."; \
212 echo " *"; \
213 echo " * This file was generated by arch/sh/Makefile"; \
214 echo " * Any changes will be reverted at build time."; \
215 echo " */"; \
216 echo ""; \
217 echo "#ifndef __SYSCALLTAB_H"; \
218 echo "#define __SYSCALLTAB_H"; \
219 echo ""; \
220 echo "#include <linux/kernel.h>"; \
221 echo ""; \
222 echo "struct syscall_info {"; \
223 echo " const char *name;"; \
224 echo "} syscall_info_table[] = {"; \
225 sed -e '/^.*\.long /!d;s// { "/;s/\(\([^/]*\)\/\)\{1\}.*/\2/; \
226 s/[ \t]*$$//g;s/$$/" },/;s/\("\)sys_/\1/g'; \
227 echo "};"; \
228 echo ""; \
229 echo "#define NUM_SYSCALL_INFO_ENTRIES ARRAY_SIZE(syscall_info_table)";\
230 echo ""; \
231 echo "#endif /* __SYSCALLTAB_H */" )
232endef
233
234arch/sh/lib64/syscalltab.h: arch/sh/kernel/syscalls_64.S
235 $(call filechk,gen-syscalltab)
236
237CLEAN_FILES += arch/sh/lib64/syscalltab.h \
238 include/asm-sh/machtypes.h
diff --git a/arch/sh/boards/Kconfig b/arch/sh/boards/Kconfig
index dcc1af8a2cfe..1c91b1f565d5 100644
--- a/arch/sh/boards/Kconfig
+++ b/arch/sh/boards/Kconfig
@@ -46,6 +46,15 @@ config SH_7722_SOLUTION_ENGINE
46 Select 7722 SolutionEngine if configuring for a Hitachi SH772 46 Select 7722 SolutionEngine if configuring for a Hitachi SH772
47 evaluation board. 47 evaluation board.
48 48
49config SH_7724_SOLUTION_ENGINE
50 bool "SolutionEngine7724"
51 select SOLUTION_ENGINE
52 depends on CPU_SUBTYPE_SH7724
53 select ARCH_REQUIRE_GPIOLIB
54 help
55 Select 7724 SolutionEngine if configuring for a Hitachi SH7724
56 evaluation board.
57
49config SH_7751_SOLUTION_ENGINE 58config SH_7751_SOLUTION_ENGINE
50 bool "SolutionEngine7751" 59 bool "SolutionEngine7751"
51 select SOLUTION_ENGINE 60 select SOLUTION_ENGINE
@@ -121,7 +130,7 @@ config SH_RTS7751R2D
121 bool "RTS7751R2D" 130 bool "RTS7751R2D"
122 depends on CPU_SUBTYPE_SH7751R 131 depends on CPU_SUBTYPE_SH7751R
123 select SYS_SUPPORTS_PCI 132 select SYS_SUPPORTS_PCI
124 select IO_TRAPPED 133 select IO_TRAPPED if MMU
125 help 134 help
126 Select RTS7751R2D if configuring for a Renesas Technology 135 Select RTS7751R2D if configuring for a Renesas Technology
127 Sales SH-Graphics board. 136 Sales SH-Graphics board.
@@ -145,13 +154,13 @@ config SH_HIGHLANDER
145 bool "Highlander" 154 bool "Highlander"
146 depends on CPU_SUBTYPE_SH7780 || CPU_SUBTYPE_SH7785 155 depends on CPU_SUBTYPE_SH7780 || CPU_SUBTYPE_SH7785
147 select SYS_SUPPORTS_PCI 156 select SYS_SUPPORTS_PCI
148 select IO_TRAPPED 157 select IO_TRAPPED if MMU
149 158
150config SH_SH7785LCR 159config SH_SH7785LCR
151 bool "SH7785LCR" 160 bool "SH7785LCR"
152 depends on CPU_SUBTYPE_SH7785 161 depends on CPU_SUBTYPE_SH7785
153 select SYS_SUPPORTS_PCI 162 select SYS_SUPPORTS_PCI
154 select IO_TRAPPED 163 select IO_TRAPPED if MMU
155 164
156config SH_SH7785LCR_29BIT_PHYSMAPS 165config SH_SH7785LCR_29BIT_PHYSMAPS
157 bool "SH7785LCR 29bit physmaps" 166 bool "SH7785LCR 29bit physmaps"
diff --git a/arch/sh/boards/board-ap325rxa.c b/arch/sh/boards/board-ap325rxa.c
index f2a29641b6a3..1c4d83ef2a47 100644
--- a/arch/sh/boards/board-ap325rxa.c
+++ b/arch/sh/boards/board-ap325rxa.c
@@ -535,6 +535,18 @@ static int __init ap325rxa_devices_setup(void)
535} 535}
536device_initcall(ap325rxa_devices_setup); 536device_initcall(ap325rxa_devices_setup);
537 537
538/* Return the board specific boot mode pin configuration */
539static int ap325rxa_mode_pins(void)
540{
541 /* MD0=0, MD1=0, MD2=0: Clock Mode 0
542 * MD3=0: 16-bit Area0 Bus Width
543 * MD5=1: Little Endian
544 * TSTMD=1, MD8=1: Test Mode Disabled
545 */
546 return MODE_PIN5 | MODE_PIN8;
547}
548
538static struct sh_machine_vector mv_ap325rxa __initmv = { 549static struct sh_machine_vector mv_ap325rxa __initmv = {
539 .mv_name = "AP-325RXA", 550 .mv_name = "AP-325RXA",
551 .mv_mode_pins = ap325rxa_mode_pins,
540}; 552};
diff --git a/arch/sh/boards/board-sh7785lcr.c b/arch/sh/boards/board-sh7785lcr.c
index 6f94f17adc46..7be56fb06c1f 100644
--- a/arch/sh/boards/board-sh7785lcr.c
+++ b/arch/sh/boards/board-sh7785lcr.c
@@ -2,12 +2,12 @@
2 * Renesas Technology Corp. R0P7785LC0011RL Support. 2 * Renesas Technology Corp. R0P7785LC0011RL Support.
3 * 3 *
4 * Copyright (C) 2008 Yoshihiro Shimoda 4 * Copyright (C) 2008 Yoshihiro Shimoda
5 * Copyright (C) 2009 Paul Mundt
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public 7 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive 8 * License. See the file "COPYING" in the main directory of this archive
8 * for more details. 9 * for more details.
9 */ 10 */
10
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <linux/sm501.h> 13#include <linux/sm501.h>
@@ -19,8 +19,12 @@
19#include <linux/i2c-pca-platform.h> 19#include <linux/i2c-pca-platform.h>
20#include <linux/i2c-algo-pca.h> 20#include <linux/i2c-algo-pca.h>
21#include <linux/irq.h> 21#include <linux/irq.h>
22#include <asm/heartbeat.h> 22#include <linux/clk.h>
23#include <linux/errno.h>
23#include <mach/sh7785lcr.h> 24#include <mach/sh7785lcr.h>
25#include <asm/heartbeat.h>
26#include <asm/clock.h>
27#include <cpu/sh7785.h>
24 28
25/* 29/*
26 * NOTE: This board has 2 physical memory maps. 30 * NOTE: This board has 2 physical memory maps.
@@ -273,6 +277,20 @@ void __init init_sh7785lcr_IRQ(void)
273 plat_irq_setup_pins(IRQ_MODE_IRQ3210); 277 plat_irq_setup_pins(IRQ_MODE_IRQ3210);
274} 278}
275 279
280static int sh7785lcr_clk_init(void)
281{
282 struct clk *clk;
283 int ret;
284
285 clk = clk_get(NULL, "extal");
286 if (!clk || IS_ERR(clk))
287 return PTR_ERR(clk);
288 ret = clk_set_rate(clk, 33333333);
289 clk_put(clk);
290
291 return ret;
292}
293
276static void sh7785lcr_power_off(void) 294static void sh7785lcr_power_off(void)
277{ 295{
278 unsigned char *p; 296 unsigned char *p;
@@ -303,12 +321,34 @@ static void __init sh7785lcr_setup(char **cmdline_p)
303 writel(0x000307c2, sm501_reg); 321 writel(0x000307c2, sm501_reg);
304} 322}
305 323
324/* Return the board specific boot mode pin configuration */
325static int sh7785lcr_mode_pins(void)
326{
327 int value = 0;
328
329 /* These are the factory default settings of S1 and S2.
330 * If you change these dip switches then you will need to
331 * adjust the values below as well.
332 */
333 value |= MODE_PIN4; /* Clock Mode 16 */
334 value |= MODE_PIN5; /* 32-bit Area0 bus width */
335 value |= MODE_PIN6; /* 32-bit Area0 bus width */
336 value |= MODE_PIN7; /* Area 0 SRAM interface [fixed] */
337 value |= MODE_PIN8; /* Little Endian */
338 value |= MODE_PIN9; /* Master Mode */
339 value |= MODE_PIN14; /* No PLL step-up */
340
341 return value;
342}
343
306/* 344/*
307 * The Machine Vector 345 * The Machine Vector
308 */ 346 */
309static struct sh_machine_vector mv_sh7785lcr __initmv = { 347static struct sh_machine_vector mv_sh7785lcr __initmv = {
310 .mv_name = "SH7785LCR", 348 .mv_name = "SH7785LCR",
311 .mv_setup = sh7785lcr_setup, 349 .mv_setup = sh7785lcr_setup,
350 .mv_clk_init = sh7785lcr_clk_init,
312 .mv_init_irq = init_sh7785lcr_IRQ, 351 .mv_init_irq = init_sh7785lcr_IRQ,
352 .mv_mode_pins = sh7785lcr_mode_pins,
313}; 353};
314 354
diff --git a/arch/sh/boards/mach-cayman/Makefile b/arch/sh/boards/mach-cayman/Makefile
index cafe1ac3b29c..00fa3eaecb1b 100644
--- a/arch/sh/boards/mach-cayman/Makefile
+++ b/arch/sh/boards/mach-cayman/Makefile
@@ -1,4 +1,4 @@
1# 1#
2# Makefile for the Hitachi Cayman specific parts of the kernel 2# Makefile for the Hitachi Cayman specific parts of the kernel
3# 3#
4obj-y := setup.o irq.o 4obj-y := setup.o irq.o panic.o
diff --git a/arch/sh/boards/mach-cayman/irq.c b/arch/sh/boards/mach-cayman/irq.c
index da62ad516994..33f770856319 100644
--- a/arch/sh/boards/mach-cayman/irq.c
+++ b/arch/sh/boards/mach-cayman/irq.c
@@ -142,26 +142,11 @@ int cayman_irq_demux(int evt)
142 return irq; 142 return irq;
143} 143}
144 144
145#if defined(CONFIG_PROC_FS) && defined(CONFIG_SYSCTL)
146int cayman_irq_describe(char* p, int irq)
147{
148 if (irq < NR_INTC_IRQS) {
149 return intc_irq_describe(p, irq);
150 } else if (irq < NR_INTC_IRQS + 8) {
151 return sprintf(p, "(SMSC %d)", irq - NR_INTC_IRQS);
152 } else if ((irq >= NR_INTC_IRQS + 24) && (irq < NR_INTC_IRQS + 32)) {
153 return sprintf(p, "(PCI2 %d)", irq - (NR_INTC_IRQS + 24));
154 }
155
156 return 0;
157}
158#endif
159
160void init_cayman_irq(void) 145void init_cayman_irq(void)
161{ 146{
162 int i; 147 int i;
163 148
164 epld_virt = onchip_remap(EPLD_BASE, 1024, "EPLD"); 149 epld_virt = (unsigned long)ioremap_nocache(EPLD_BASE, 1024);
165 if (!epld_virt) { 150 if (!epld_virt) {
166 printk(KERN_ERR "Cayman IRQ: Unable to remap EPLD\n"); 151 printk(KERN_ERR "Cayman IRQ: Unable to remap EPLD\n");
167 return; 152 return;
diff --git a/arch/sh/boards/mach-cayman/panic.c b/arch/sh/boards/mach-cayman/panic.c
new file mode 100644
index 000000000000..d1e67306d07c
--- /dev/null
+++ b/arch/sh/boards/mach-cayman/panic.c
@@ -0,0 +1,49 @@
1/*
2 * Copyright (C) 2003 Richard Curnow, SuperH UK Limited
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 */
8
9#include <linux/kernel.h>
10#include <linux/io.h>
11#include <cpu/registers.h>
12
13/* THIS IS A PHYSICAL ADDRESS */
14#define HDSP2534_ADDR (0x04002100)
15
16static void poor_mans_delay(void)
17{
18 int i;
19
20 for (i = 0; i < 2500000; i++)
21 cpu_relax();
22}
23
24static void show_value(unsigned long x)
25{
26 int i;
27 unsigned nibble;
28 for (i = 0; i < 8; i++) {
29 nibble = ((x >> (i * 4)) & 0xf);
30
31 __raw_writeb(nibble + ((nibble > 9) ? 55 : 48),
32 HDSP2534_ADDR + 0xe0 + ((7 - i) << 2));
33 }
34}
35
36void
37panic_handler(unsigned long panicPC, unsigned long panicSSR,
38 unsigned long panicEXPEVT)
39{
40 while (1) {
41 /* This piece of code displays the PC on the LED display */
42 show_value(panicPC);
43 poor_mans_delay();
44 show_value(panicSSR);
45 poor_mans_delay();
46 show_value(panicEXPEVT);
47 poor_mans_delay();
48 }
49}
diff --git a/arch/sh/boards/mach-cayman/setup.c b/arch/sh/boards/mach-cayman/setup.c
index e7f9cc5f2ff1..7e8216ac31bd 100644
--- a/arch/sh/boards/mach-cayman/setup.c
+++ b/arch/sh/boards/mach-cayman/setup.c
@@ -102,7 +102,7 @@ static int __init smsc_superio_setup(void)
102{ 102{
103 unsigned char devid, devrev; 103 unsigned char devid, devrev;
104 104
105 smsc_superio_virt = onchip_remap(SMSC_SUPERIO_BASE, 1024, "SMSC SuperIO"); 105 smsc_superio_virt = (unsigned long)ioremap_nocache(SMSC_SUPERIO_BASE, 1024);
106 if (!smsc_superio_virt) { 106 if (!smsc_superio_virt) {
107 panic("Unable to remap SMSC SuperIO\n"); 107 panic("Unable to remap SMSC SuperIO\n");
108 } 108 }
diff --git a/arch/sh/boards/mach-dreamcast/setup.c b/arch/sh/boards/mach-dreamcast/setup.c
index d1bee4884cd6..ebe99227d4e6 100644
--- a/arch/sh/boards/mach-dreamcast/setup.c
+++ b/arch/sh/boards/mach-dreamcast/setup.c
@@ -30,7 +30,6 @@
30 30
31extern struct irq_chip systemasic_int; 31extern struct irq_chip systemasic_int;
32extern void aica_time_init(void); 32extern void aica_time_init(void);
33extern int gapspci_init(void);
34extern int systemasic_irq_demux(int); 33extern int systemasic_irq_demux(int);
35 34
36static void __init dreamcast_setup(char **cmdline_p) 35static void __init dreamcast_setup(char **cmdline_p)
@@ -51,11 +50,6 @@ static void __init dreamcast_setup(char **cmdline_p)
51 handle_level_irq); 50 handle_level_irq);
52 51
53 board_time_init = aica_time_init; 52 board_time_init = aica_time_init;
54
55#ifdef CONFIG_PCI
56 if (gapspci_init() < 0)
57 printk(KERN_WARNING "GAPSPCI was not detected.\n");
58#endif
59} 53}
60 54
61static struct sh_machine_vector mv_dreamcast __initmv = { 55static struct sh_machine_vector mv_dreamcast __initmv = {
diff --git a/arch/sh/boards/mach-migor/setup.c b/arch/sh/boards/mach-migor/setup.c
index 1ee1de0bc1c3..6ed401cd3156 100644
--- a/arch/sh/boards/mach-migor/setup.c
+++ b/arch/sh/boards/mach-migor/setup.c
@@ -584,3 +584,22 @@ static int __init migor_devices_setup(void)
584 return platform_add_devices(migor_devices, ARRAY_SIZE(migor_devices)); 584 return platform_add_devices(migor_devices, ARRAY_SIZE(migor_devices));
585} 585}
586__initcall(migor_devices_setup); 586__initcall(migor_devices_setup);
587
588/* Return the board specific boot mode pin configuration */
589static int migor_mode_pins(void)
590{
591 /* MD0=1, MD1=1, MD2=0: Clock Mode 3
592 * MD3=0: 16-bit Area0 Bus Width
593 * MD5=1: Little Endian
594 * TSTMD=1, MD8=0: Test Mode Disabled
595 */
596 return MODE_PIN0 | MODE_PIN1 | MODE_PIN5;
597}
598
599/*
600 * The Machine Vector
601 */
602static struct sh_machine_vector mv_migor __initmv = {
603 .mv_name = "Migo-R",
604 .mv_mode_pins = migor_mode_pins,
605};
diff --git a/arch/sh/boards/mach-r2d/setup.c b/arch/sh/boards/mach-r2d/setup.c
index c585be00956e..a625ecb93e47 100644
--- a/arch/sh/boards/mach-r2d/setup.c
+++ b/arch/sh/boards/mach-r2d/setup.c
@@ -10,6 +10,9 @@
10 */ 10 */
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <linux/mtd/mtd.h>
14#include <linux/mtd/partitions.h>
15#include <linux/mtd/physmap.h>
13#include <linux/ata_platform.h> 16#include <linux/ata_platform.h>
14#include <linux/sm501.h> 17#include <linux/sm501.h>
15#include <linux/sm501-regs.h> 18#include <linux/sm501-regs.h>
@@ -181,6 +184,50 @@ static struct platform_device sm501_device = {
181 .resource = sm501_resources, 184 .resource = sm501_resources,
182}; 185};
183 186
187static struct mtd_partition r2d_partitions[] = {
188 {
189 .name = "U-Boot",
190 .offset = 0x00000000,
191 .size = 0x00040000,
192 .mask_flags = MTD_WRITEABLE,
193 }, {
194 .name = "Environment",
195 .offset = MTDPART_OFS_NXTBLK,
196 .size = 0x00040000,
197 .mask_flags = MTD_WRITEABLE,
198 }, {
199 .name = "Kernel",
200 .offset = MTDPART_OFS_NXTBLK,
201 .size = 0x001c0000,
202 }, {
203 .name = "Flash_FS",
204 .offset = MTDPART_OFS_NXTBLK,
205 .size = MTDPART_SIZ_FULL,
206 }
207};
208
209static struct physmap_flash_data flash_data = {
210 .width = 2,
211 .nr_parts = ARRAY_SIZE(r2d_partitions),
212 .parts = r2d_partitions,
213};
214
215static struct resource flash_resource = {
216 .start = 0x00000000,
217 .end = 0x02000000,
218 .flags = IORESOURCE_MEM,
219};
220
221static struct platform_device flash_device = {
222 .name = "physmap-flash",
223 .id = -1,
224 .resource = &flash_resource,
225 .num_resources = 1,
226 .dev = {
227 .platform_data = &flash_data,
228 },
229};
230
184static struct platform_device *rts7751r2d_devices[] __initdata = { 231static struct platform_device *rts7751r2d_devices[] __initdata = {
185 &sm501_device, 232 &sm501_device,
186 &heartbeat_device, 233 &heartbeat_device,
@@ -203,6 +250,9 @@ static int __init rts7751r2d_devices_setup(void)
203 if (register_trapped_io(&cf_trapped_io) == 0) 250 if (register_trapped_io(&cf_trapped_io) == 0)
204 platform_device_register(&cf_ide_device); 251 platform_device_register(&cf_ide_device);
205 252
253 if (mach_is_r2d_plus())
254 platform_device_register(&flash_device);
255
206 spi_register_board_info(spi_bus, ARRAY_SIZE(spi_bus)); 256 spi_register_board_info(spi_bus, ARRAY_SIZE(spi_bus));
207 257
208 return platform_add_devices(rts7751r2d_devices, 258 return platform_add_devices(rts7751r2d_devices,
diff --git a/arch/sh/boards/mach-se/7724/Makefile b/arch/sh/boards/mach-se/7724/Makefile
new file mode 100644
index 000000000000..349cbd6ce82d
--- /dev/null
+++ b/arch/sh/boards/mach-se/7724/Makefile
@@ -0,0 +1,10 @@
1#
2# Makefile for the HITACHI UL SolutionEngine 7724 specific parts of the kernel
3#
4# This file is subject to the terms and conditions of the GNU General Public
5# License. See the file "COPYING" in the main directory of this archive
6# for more details.
7#
8#
9
10obj-y := setup.o irq.o \ No newline at end of file
diff --git a/arch/sh/boards/mach-se/7724/irq.c b/arch/sh/boards/mach-se/7724/irq.c
new file mode 100644
index 000000000000..f76cf3b49f23
--- /dev/null
+++ b/arch/sh/boards/mach-se/7724/irq.c
@@ -0,0 +1,139 @@
1/*
2 * linux/arch/sh/boards/se/7724/irq.c
3 *
4 * Copyright (C) 2009 Renesas Solutions Corp.
5 *
6 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
7 *
8 * Based on linux/arch/sh/boards/se/7722/irq.c
9 * Copyright (C) 2007 Nobuhiro Iwamatsu
10 *
11 * Hitachi UL SolutionEngine 7724 Support.
12 *
13 * This file is subject to the terms and conditions of the GNU General Public
14 * License. See the file "COPYING" in the main directory of this archive
15 * for more details.
16 */
17#include <linux/init.h>
18#include <linux/irq.h>
19#include <linux/interrupt.h>
20#include <asm/irq.h>
21#include <asm/io.h>
22#include <mach-se/mach/se7724.h>
23
24struct fpga_irq {
25 unsigned long sraddr;
26 unsigned long mraddr;
27 unsigned short mask;
28 unsigned int base;
29};
30
31static unsigned int fpga2irq(unsigned int irq)
32{
33 if (irq >= IRQ0_BASE &&
34 irq <= IRQ0_END)
35 return IRQ0_IRQ;
36 else if (irq >= IRQ1_BASE &&
37 irq <= IRQ1_END)
38 return IRQ1_IRQ;
39 else
40 return IRQ2_IRQ;
41}
42
43static struct fpga_irq get_fpga_irq(unsigned int irq)
44{
45 struct fpga_irq set;
46
47 switch (irq) {
48 case IRQ0_IRQ:
49 set.sraddr = IRQ0_SR;
50 set.mraddr = IRQ0_MR;
51 set.mask = IRQ0_MASK;
52 set.base = IRQ0_BASE;
53 break;
54 case IRQ1_IRQ:
55 set.sraddr = IRQ1_SR;
56 set.mraddr = IRQ1_MR;
57 set.mask = IRQ1_MASK;
58 set.base = IRQ1_BASE;
59 break;
60 default:
61 set.sraddr = IRQ2_SR;
62 set.mraddr = IRQ2_MR;
63 set.mask = IRQ2_MASK;
64 set.base = IRQ2_BASE;
65 break;
66 }
67
68 return set;
69}
70
71static void disable_se7724_irq(unsigned int irq)
72{
73 struct fpga_irq set = get_fpga_irq(fpga2irq(irq));
74 unsigned int bit = irq - set.base;
75 ctrl_outw(ctrl_inw(set.mraddr) | 0x0001 << bit, set.mraddr);
76}
77
78static void enable_se7724_irq(unsigned int irq)
79{
80 struct fpga_irq set = get_fpga_irq(fpga2irq(irq));
81 unsigned int bit = irq - set.base;
82 ctrl_outw(ctrl_inw(set.mraddr) & ~(0x0001 << bit), set.mraddr);
83}
84
85static struct irq_chip se7724_irq_chip __read_mostly = {
86 .name = "SE7724-FPGA",
87 .mask = disable_se7724_irq,
88 .unmask = enable_se7724_irq,
89 .mask_ack = disable_se7724_irq,
90};
91
92static void se7724_irq_demux(unsigned int irq, struct irq_desc *desc)
93{
94 struct fpga_irq set = get_fpga_irq(irq);
95 unsigned short intv = ctrl_inw(set.sraddr);
96 struct irq_desc *ext_desc;
97 unsigned int ext_irq = set.base;
98
99 intv &= set.mask;
100
101 while (intv) {
102 if (intv & 0x0001) {
103 ext_desc = irq_desc + ext_irq;
104 handle_level_irq(ext_irq, ext_desc);
105 }
106 intv >>= 1;
107 ext_irq++;
108 }
109}
110
111/*
112 * Initialize IRQ setting
113 */
114void __init init_se7724_IRQ(void)
115{
116 int i;
117
118 ctrl_outw(0xffff, IRQ0_MR); /* mask all */
119 ctrl_outw(0xffff, IRQ1_MR); /* mask all */
120 ctrl_outw(0xffff, IRQ2_MR); /* mask all */
121 ctrl_outw(0x0000, IRQ0_SR); /* clear irq */
122 ctrl_outw(0x0000, IRQ1_SR); /* clear irq */
123 ctrl_outw(0x0000, IRQ2_SR); /* clear irq */
124 ctrl_outw(0x002a, IRQ_MODE); /* set irq type */
125
126 for (i = 0; i < SE7724_FPGA_IRQ_NR; i++)
127 set_irq_chip_and_handler_name(SE7724_FPGA_IRQ_BASE + i,
128 &se7724_irq_chip,
129 handle_level_irq, "level");
130
131 set_irq_chained_handler(IRQ0_IRQ, se7724_irq_demux);
132 set_irq_type(IRQ0_IRQ, IRQ_TYPE_LEVEL_LOW);
133
134 set_irq_chained_handler(IRQ1_IRQ, se7724_irq_demux);
135 set_irq_type(IRQ1_IRQ, IRQ_TYPE_LEVEL_LOW);
136
137 set_irq_chained_handler(IRQ2_IRQ, se7724_irq_demux);
138 set_irq_type(IRQ2_IRQ, IRQ_TYPE_LEVEL_LOW);
139}
diff --git a/arch/sh/boards/mach-se/7724/setup.c b/arch/sh/boards/mach-se/7724/setup.c
new file mode 100644
index 000000000000..9cd04bd558b8
--- /dev/null
+++ b/arch/sh/boards/mach-se/7724/setup.c
@@ -0,0 +1,448 @@
1/*
2 * linux/arch/sh/boards/se/7724/setup.c
3 *
4 * Copyright (C) 2009 Renesas Solutions Corp.
5 *
6 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12
13#include <linux/init.h>
14#include <linux/device.h>
15#include <linux/interrupt.h>
16#include <linux/platform_device.h>
17#include <linux/mtd/physmap.h>
18#include <linux/delay.h>
19#include <linux/smc91x.h>
20#include <linux/gpio.h>
21#include <linux/input.h>
22#include <video/sh_mobile_lcdc.h>
23#include <media/sh_mobile_ceu.h>
24#include <asm/io.h>
25#include <asm/heartbeat.h>
26#include <asm/sh_keysc.h>
27#include <cpu/sh7724.h>
28#include <mach-se/mach/se7724.h>
29
30/*
31 * SWx 1234 5678
32 * ------------------------------------
33 * SW31 : 1001 1100 : default
34 * SW32 : 0111 1111 : use on board flash
35 *
36 * SW41 : abxx xxxx -> a = 0 : Analog monitor
37 * 1 : Digital monitor
38 * b = 0 : VGA
39 * 1 : SVGA
40 */
41
42/* Heartbeat */
43static struct heartbeat_data heartbeat_data = {
44 .regsize = 16,
45};
46
47static struct resource heartbeat_resources[] = {
48 [0] = {
49 .start = PA_LED,
50 .end = PA_LED,
51 .flags = IORESOURCE_MEM,
52 },
53};
54
55static struct platform_device heartbeat_device = {
56 .name = "heartbeat",
57 .id = -1,
58 .dev = {
59 .platform_data = &heartbeat_data,
60 },
61 .num_resources = ARRAY_SIZE(heartbeat_resources),
62 .resource = heartbeat_resources,
63};
64
65/* LAN91C111 */
66static struct smc91x_platdata smc91x_info = {
67 .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
68};
69
70static struct resource smc91x_eth_resources[] = {
71 [0] = {
72 .name = "SMC91C111" ,
73 .start = 0x1a300300,
74 .end = 0x1a30030f,
75 .flags = IORESOURCE_MEM,
76 },
77 [1] = {
78 .start = IRQ0_SMC,
79 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
80 },
81};
82
83static struct platform_device smc91x_eth_device = {
84 .name = "smc91x",
85 .num_resources = ARRAY_SIZE(smc91x_eth_resources),
86 .resource = smc91x_eth_resources,
87 .dev = {
88 .platform_data = &smc91x_info,
89 },
90};
91
92/* MTD */
93static struct mtd_partition nor_flash_partitions[] = {
94 {
95 .name = "uboot",
96 .offset = 0,
97 .size = (1 * 1024 * 1024),
98 .mask_flags = MTD_WRITEABLE, /* Read-only */
99 }, {
100 .name = "kernel",
101 .offset = MTDPART_OFS_APPEND,
102 .size = (2 * 1024 * 1024),
103 }, {
104 .name = "free-area",
105 .offset = MTDPART_OFS_APPEND,
106 .size = MTDPART_SIZ_FULL,
107 },
108};
109
110static struct physmap_flash_data nor_flash_data = {
111 .width = 2,
112 .parts = nor_flash_partitions,
113 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
114};
115
116static struct resource nor_flash_resources[] = {
117 [0] = {
118 .name = "NOR Flash",
119 .start = 0x00000000,
120 .end = 0x01ffffff,
121 .flags = IORESOURCE_MEM,
122 }
123};
124
125static struct platform_device nor_flash_device = {
126 .name = "physmap-flash",
127 .resource = nor_flash_resources,
128 .num_resources = ARRAY_SIZE(nor_flash_resources),
129 .dev = {
130 .platform_data = &nor_flash_data,
131 },
132};
133
134/* LCDC */
135static struct sh_mobile_lcdc_info lcdc_info = {
136 .clock_source = LCDC_CLK_EXTERNAL,
137 .ch[0] = {
138 .chan = LCDC_CHAN_MAINLCD,
139 .bpp = 16,
140 .clock_divider = 1,
141 .lcd_cfg = {
142 .name = "LB070WV1",
143 .sync = 0, /* hsync and vsync are active low */
144 },
145 .lcd_size_cfg = { /* 7.0 inch */
146 .width = 152,
147 .height = 91,
148 },
149 .board_cfg = {
150 },
151 }
152};
153
154static struct resource lcdc_resources[] = {
155 [0] = {
156 .name = "LCDC",
157 .start = 0xfe940000,
158 .end = 0xfe941fff,
159 .flags = IORESOURCE_MEM,
160 },
161 [1] = {
162 .start = 106,
163 .flags = IORESOURCE_IRQ,
164 },
165};
166
167static struct platform_device lcdc_device = {
168 .name = "sh_mobile_lcdc_fb",
169 .num_resources = ARRAY_SIZE(lcdc_resources),
170 .resource = lcdc_resources,
171 .dev = {
172 .platform_data = &lcdc_info,
173 },
174};
175
176/* CEU0 */
177static struct sh_mobile_ceu_info sh_mobile_ceu0_info = {
178 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
179};
180
181static struct resource ceu0_resources[] = {
182 [0] = {
183 .name = "CEU0",
184 .start = 0xfe910000,
185 .end = 0xfe91009f,
186 .flags = IORESOURCE_MEM,
187 },
188 [1] = {
189 .start = 52,
190 .flags = IORESOURCE_IRQ,
191 },
192 [2] = {
193 /* place holder for contiguous memory */
194 },
195};
196
197static struct platform_device ceu0_device = {
198 .name = "sh_mobile_ceu",
199 .id = 0, /* "ceu0" clock */
200 .num_resources = ARRAY_SIZE(ceu0_resources),
201 .resource = ceu0_resources,
202 .dev = {
203 .platform_data = &sh_mobile_ceu0_info,
204 },
205};
206
207/* CEU1 */
208static struct sh_mobile_ceu_info sh_mobile_ceu1_info = {
209 .flags = SH_CEU_FLAG_USE_8BIT_BUS,
210};
211
212static struct resource ceu1_resources[] = {
213 [0] = {
214 .name = "CEU1",
215 .start = 0xfe914000,
216 .end = 0xfe91409f,
217 .flags = IORESOURCE_MEM,
218 },
219 [1] = {
220 .start = 63,
221 .flags = IORESOURCE_IRQ,
222 },
223 [2] = {
224 /* place holder for contiguous memory */
225 },
226};
227
228static struct platform_device ceu1_device = {
229 .name = "sh_mobile_ceu",
230 .id = 1, /* "ceu1" clock */
231 .num_resources = ARRAY_SIZE(ceu1_resources),
232 .resource = ceu1_resources,
233 .dev = {
234 .platform_data = &sh_mobile_ceu1_info,
235 },
236};
237
238/* KEYSC */
239static struct sh_keysc_info keysc_info = {
240 .mode = SH_KEYSC_MODE_1,
241 .scan_timing = 10,
242 .delay = 50,
243 .keycodes = {
244 KEY_1, KEY_2, KEY_3, KEY_4, KEY_5,
245 KEY_6, KEY_7, KEY_8, KEY_9, KEY_A,
246 KEY_B, KEY_C, KEY_D, KEY_E, KEY_F,
247 KEY_G, KEY_H, KEY_I, KEY_K, KEY_L,
248 KEY_M, KEY_N, KEY_O, KEY_P, KEY_Q,
249 KEY_R, KEY_S, KEY_T, KEY_U, KEY_V,
250 },
251};
252
253static struct resource keysc_resources[] = {
254 [0] = {
255 .start = 0x1a204000,
256 .end = 0x1a20400f,
257 .flags = IORESOURCE_MEM,
258 },
259 [1] = {
260 .start = IRQ0_KEY,
261 .flags = IORESOURCE_IRQ,
262 },
263};
264
265static struct platform_device keysc_device = {
266 .name = "sh_keysc",
267 .id = 0, /* "keysc0" clock */
268 .num_resources = ARRAY_SIZE(keysc_resources),
269 .resource = keysc_resources,
270 .dev = {
271 .platform_data = &keysc_info,
272 },
273};
274
275static struct platform_device *ms7724se_devices[] __initdata = {
276 &heartbeat_device,
277 &smc91x_eth_device,
278 &lcdc_device,
279 &nor_flash_device,
280 &ceu0_device,
281 &ceu1_device,
282 &keysc_device,
283};
284
285#define SW4140 0xBA201000
286#define FPGA_OUT 0xBA200400
287#define PORT_HIZA 0xA4050158
288
289#define SW41_A 0x0100
290#define SW41_B 0x0200
291#define SW41_C 0x0400
292#define SW41_D 0x0800
293#define SW41_E 0x1000
294#define SW41_F 0x2000
295#define SW41_G 0x4000
296#define SW41_H 0x8000
297static int __init devices_setup(void)
298{
299 u16 sw = ctrl_inw(SW4140); /* select camera, monitor */
300
301 /* Reset Release */
302 ctrl_outw(ctrl_inw(FPGA_OUT) &
303 ~((1 << 1) | /* LAN */
304 (1 << 6) | /* VIDEO DAC */
305 (1 << 12)), /* USB0 */
306 FPGA_OUT);
307
308 /* enable IRQ 0,1,2 */
309 gpio_request(GPIO_FN_INTC_IRQ0, NULL);
310 gpio_request(GPIO_FN_INTC_IRQ1, NULL);
311 gpio_request(GPIO_FN_INTC_IRQ2, NULL);
312
313 /* enable SCIFA3 */
314 gpio_request(GPIO_FN_SCIF3_I_SCK, NULL);
315 gpio_request(GPIO_FN_SCIF3_I_RXD, NULL);
316 gpio_request(GPIO_FN_SCIF3_I_TXD, NULL);
317 gpio_request(GPIO_FN_SCIF3_I_CTS, NULL);
318 gpio_request(GPIO_FN_SCIF3_I_RTS, NULL);
319
320 /* enable LCDC */
321 gpio_request(GPIO_FN_LCDD23, NULL);
322 gpio_request(GPIO_FN_LCDD22, NULL);
323 gpio_request(GPIO_FN_LCDD21, NULL);
324 gpio_request(GPIO_FN_LCDD20, NULL);
325 gpio_request(GPIO_FN_LCDD19, NULL);
326 gpio_request(GPIO_FN_LCDD18, NULL);
327 gpio_request(GPIO_FN_LCDD17, NULL);
328 gpio_request(GPIO_FN_LCDD16, NULL);
329 gpio_request(GPIO_FN_LCDD15, NULL);
330 gpio_request(GPIO_FN_LCDD14, NULL);
331 gpio_request(GPIO_FN_LCDD13, NULL);
332 gpio_request(GPIO_FN_LCDD12, NULL);
333 gpio_request(GPIO_FN_LCDD11, NULL);
334 gpio_request(GPIO_FN_LCDD10, NULL);
335 gpio_request(GPIO_FN_LCDD9, NULL);
336 gpio_request(GPIO_FN_LCDD8, NULL);
337 gpio_request(GPIO_FN_LCDD7, NULL);
338 gpio_request(GPIO_FN_LCDD6, NULL);
339 gpio_request(GPIO_FN_LCDD5, NULL);
340 gpio_request(GPIO_FN_LCDD4, NULL);
341 gpio_request(GPIO_FN_LCDD3, NULL);
342 gpio_request(GPIO_FN_LCDD2, NULL);
343 gpio_request(GPIO_FN_LCDD1, NULL);
344 gpio_request(GPIO_FN_LCDD0, NULL);
345 gpio_request(GPIO_FN_LCDDISP, NULL);
346 gpio_request(GPIO_FN_LCDHSYN, NULL);
347 gpio_request(GPIO_FN_LCDDCK, NULL);
348 gpio_request(GPIO_FN_LCDVSYN, NULL);
349 gpio_request(GPIO_FN_LCDDON, NULL);
350 gpio_request(GPIO_FN_LCDVEPWC, NULL);
351 gpio_request(GPIO_FN_LCDVCPWC, NULL);
352 gpio_request(GPIO_FN_LCDRD, NULL);
353 gpio_request(GPIO_FN_LCDLCLK, NULL);
354 ctrl_outw((ctrl_inw(PORT_HIZA) & ~0x0001), PORT_HIZA);
355
356 /* enable CEU0 */
357 gpio_request(GPIO_FN_VIO0_D15, NULL);
358 gpio_request(GPIO_FN_VIO0_D14, NULL);
359 gpio_request(GPIO_FN_VIO0_D13, NULL);
360 gpio_request(GPIO_FN_VIO0_D12, NULL);
361 gpio_request(GPIO_FN_VIO0_D11, NULL);
362 gpio_request(GPIO_FN_VIO0_D10, NULL);
363 gpio_request(GPIO_FN_VIO0_D9, NULL);
364 gpio_request(GPIO_FN_VIO0_D8, NULL);
365 gpio_request(GPIO_FN_VIO0_D7, NULL);
366 gpio_request(GPIO_FN_VIO0_D6, NULL);
367 gpio_request(GPIO_FN_VIO0_D5, NULL);
368 gpio_request(GPIO_FN_VIO0_D4, NULL);
369 gpio_request(GPIO_FN_VIO0_D3, NULL);
370 gpio_request(GPIO_FN_VIO0_D2, NULL);
371 gpio_request(GPIO_FN_VIO0_D1, NULL);
372 gpio_request(GPIO_FN_VIO0_D0, NULL);
373 gpio_request(GPIO_FN_VIO0_VD, NULL);
374 gpio_request(GPIO_FN_VIO0_CLK, NULL);
375 gpio_request(GPIO_FN_VIO0_FLD, NULL);
376 gpio_request(GPIO_FN_VIO0_HD, NULL);
377 platform_resource_setup_memory(&ceu0_device, "ceu", 4 << 20);
378
379 /* enable CEU1 */
380 gpio_request(GPIO_FN_VIO1_D7, NULL);
381 gpio_request(GPIO_FN_VIO1_D6, NULL);
382 gpio_request(GPIO_FN_VIO1_D5, NULL);
383 gpio_request(GPIO_FN_VIO1_D4, NULL);
384 gpio_request(GPIO_FN_VIO1_D3, NULL);
385 gpio_request(GPIO_FN_VIO1_D2, NULL);
386 gpio_request(GPIO_FN_VIO1_D1, NULL);
387 gpio_request(GPIO_FN_VIO1_D0, NULL);
388 gpio_request(GPIO_FN_VIO1_FLD, NULL);
389 gpio_request(GPIO_FN_VIO1_HD, NULL);
390 gpio_request(GPIO_FN_VIO1_VD, NULL);
391 gpio_request(GPIO_FN_VIO1_CLK, NULL);
392 platform_resource_setup_memory(&ceu1_device, "ceu", 4 << 20);
393
394 /* KEYSC */
395 gpio_request(GPIO_FN_KEYOUT5_IN5, NULL);
396 gpio_request(GPIO_FN_KEYOUT4_IN6, NULL);
397 gpio_request(GPIO_FN_KEYIN4, NULL);
398 gpio_request(GPIO_FN_KEYIN3, NULL);
399 gpio_request(GPIO_FN_KEYIN2, NULL);
400 gpio_request(GPIO_FN_KEYIN1, NULL);
401 gpio_request(GPIO_FN_KEYIN0, NULL);
402 gpio_request(GPIO_FN_KEYOUT3, NULL);
403 gpio_request(GPIO_FN_KEYOUT2, NULL);
404 gpio_request(GPIO_FN_KEYOUT1, NULL);
405 gpio_request(GPIO_FN_KEYOUT0, NULL);
406
407 if (sw & SW41_B) {
408 /* SVGA */
409 lcdc_info.ch[0].lcd_cfg.xres = 800;
410 lcdc_info.ch[0].lcd_cfg.yres = 600;
411 lcdc_info.ch[0].lcd_cfg.left_margin = 142;
412 lcdc_info.ch[0].lcd_cfg.right_margin = 52;
413 lcdc_info.ch[0].lcd_cfg.hsync_len = 96;
414 lcdc_info.ch[0].lcd_cfg.upper_margin = 24;
415 lcdc_info.ch[0].lcd_cfg.lower_margin = 2;
416 lcdc_info.ch[0].lcd_cfg.vsync_len = 2;
417 } else {
418 /* VGA */
419 lcdc_info.ch[0].lcd_cfg.xres = 640;
420 lcdc_info.ch[0].lcd_cfg.yres = 480;
421 lcdc_info.ch[0].lcd_cfg.left_margin = 105;
422 lcdc_info.ch[0].lcd_cfg.right_margin = 50;
423 lcdc_info.ch[0].lcd_cfg.hsync_len = 96;
424 lcdc_info.ch[0].lcd_cfg.upper_margin = 33;
425 lcdc_info.ch[0].lcd_cfg.lower_margin = 10;
426 lcdc_info.ch[0].lcd_cfg.vsync_len = 2;
427 }
428
429 if (sw & SW41_A) {
430 /* Digital monitor */
431 lcdc_info.ch[0].interface_type = RGB18;
432 lcdc_info.ch[0].flags = 0;
433 } else {
434 /* Analog monitor */
435 lcdc_info.ch[0].interface_type = RGB24;
436 lcdc_info.ch[0].flags = LCDC_FLAGS_DWPOL;
437 }
438
439 return platform_add_devices(ms7724se_devices,
440 ARRAY_SIZE(ms7724se_devices));
441}
442device_initcall(devices_setup);
443
444static struct sh_machine_vector mv_ms7724se __initmv = {
445 .mv_name = "ms7724se",
446 .mv_init_irq = init_se7724_IRQ,
447 .mv_nr_irqs = SE7724_FPGA_IRQ_BASE + SE7724_FPGA_IRQ_NR,
448};
diff --git a/arch/sh/boards/mach-se/7751/Makefile b/arch/sh/boards/mach-se/7751/Makefile
index dbc29f3a9de5..e6f4341bfe6e 100644
--- a/arch/sh/boards/mach-se/7751/Makefile
+++ b/arch/sh/boards/mach-se/7751/Makefile
@@ -3,5 +3,3 @@
3# 3#
4 4
5obj-y := setup.o io.o irq.o 5obj-y := setup.o io.o irq.o
6
7obj-$(CONFIG_PCI) += pci.o
diff --git a/arch/sh/boards/mach-se/7751/io.c b/arch/sh/boards/mach-se/7751/io.c
index 6287ae570319..6e75bd4459e5 100644
--- a/arch/sh/boards/mach-se/7751/io.c
+++ b/arch/sh/boards/mach-se/7751/io.c
@@ -34,8 +34,6 @@ unsigned char sh7751se_inb(unsigned long port)
34{ 34{
35 if (PXSEG(port)) 35 if (PXSEG(port))
36 return *(volatile unsigned char *)port; 36 return *(volatile unsigned char *)port;
37 else if (is_pci_ioaddr(port))
38 return *(volatile unsigned char *)pci_ioaddr(port);
39 else 37 else
40 return (*port2adr(port)) & 0xff; 38 return (*port2adr(port)) & 0xff;
41} 39}
@@ -46,8 +44,6 @@ unsigned char sh7751se_inb_p(unsigned long port)
46 44
47 if (PXSEG(port)) 45 if (PXSEG(port))
48 v = *(volatile unsigned char *)port; 46 v = *(volatile unsigned char *)port;
49 else if (is_pci_ioaddr(port))
50 v = *(volatile unsigned char *)pci_ioaddr(port);
51 else 47 else
52 v = (*port2adr(port)) & 0xff; 48 v = (*port2adr(port)) & 0xff;
53 ctrl_delay(); 49 ctrl_delay();
@@ -58,8 +54,6 @@ unsigned short sh7751se_inw(unsigned long port)
58{ 54{
59 if (PXSEG(port)) 55 if (PXSEG(port))
60 return *(volatile unsigned short *)port; 56 return *(volatile unsigned short *)port;
61 else if (is_pci_ioaddr(port))
62 return *(volatile unsigned short *)pci_ioaddr(port);
63 else if (port >= 0x2000) 57 else if (port >= 0x2000)
64 return *port2adr(port); 58 return *port2adr(port);
65 else 59 else
@@ -71,8 +65,6 @@ unsigned int sh7751se_inl(unsigned long port)
71{ 65{
72 if (PXSEG(port)) 66 if (PXSEG(port))
73 return *(volatile unsigned long *)port; 67 return *(volatile unsigned long *)port;
74 else if (is_pci_ioaddr(port))
75 return *(volatile unsigned int *)pci_ioaddr(port);
76 else if (port >= 0x2000) 68 else if (port >= 0x2000)
77 return *port2adr(port); 69 return *port2adr(port);
78 else 70 else
@@ -85,8 +77,6 @@ void sh7751se_outb(unsigned char value, unsigned long port)
85 77
86 if (PXSEG(port)) 78 if (PXSEG(port))
87 *(volatile unsigned char *)port = value; 79 *(volatile unsigned char *)port = value;
88 else if (is_pci_ioaddr(port))
89 *((unsigned char*)pci_ioaddr(port)) = value;
90 else 80 else
91 *(port2adr(port)) = value; 81 *(port2adr(port)) = value;
92} 82}
@@ -95,8 +85,6 @@ void sh7751se_outb_p(unsigned char value, unsigned long port)
95{ 85{
96 if (PXSEG(port)) 86 if (PXSEG(port))
97 *(volatile unsigned char *)port = value; 87 *(volatile unsigned char *)port = value;
98 else if (is_pci_ioaddr(port))
99 *((unsigned char*)pci_ioaddr(port)) = value;
100 else 88 else
101 *(port2adr(port)) = value; 89 *(port2adr(port)) = value;
102 ctrl_delay(); 90 ctrl_delay();
@@ -106,8 +94,6 @@ void sh7751se_outw(unsigned short value, unsigned long port)
106{ 94{
107 if (PXSEG(port)) 95 if (PXSEG(port))
108 *(volatile unsigned short *)port = value; 96 *(volatile unsigned short *)port = value;
109 else if (is_pci_ioaddr(port))
110 *((unsigned short *)pci_ioaddr(port)) = value;
111 else if (port >= 0x2000) 97 else if (port >= 0x2000)
112 *port2adr(port) = value; 98 *port2adr(port) = value;
113 else 99 else
@@ -118,8 +104,6 @@ void sh7751se_outl(unsigned int value, unsigned long port)
118{ 104{
119 if (PXSEG(port)) 105 if (PXSEG(port))
120 *(volatile unsigned long *)port = value; 106 *(volatile unsigned long *)port = value;
121 else if (is_pci_ioaddr(port))
122 *((unsigned long*)pci_ioaddr(port)) = value;
123 else 107 else
124 maybebadio(port); 108 maybebadio(port);
125} 109}
diff --git a/arch/sh/boards/mach-se/7751/pci.c b/arch/sh/boards/mach-se/7751/pci.c
deleted file mode 100644
index 203b2923fe7f..000000000000
--- a/arch/sh/boards/mach-se/7751/pci.c
+++ /dev/null
@@ -1,147 +0,0 @@
1/*
2 * linux/arch/sh/boards/se/7751/pci.c
3 *
4 * Author: Ian DaSilva (idasilva@mvista.com)
5 *
6 * Highly leveraged from pci-bigsur.c, written by Dustin McIntire.
7 *
8 * May be copied or modified under the terms of the GNU General Public
9 * License. See linux/COPYING for more information.
10 *
11 * PCI initialization for the Hitachi SH7751 Solution Engine board (MS7751SE01)
12 */
13
14#include <linux/kernel.h>
15#include <linux/types.h>
16#include <linux/init.h>
17#include <linux/delay.h>
18#include <linux/pci.h>
19
20#include <asm/io.h>
21#include "../../../drivers/pci/pci-sh7751.h"
22
23#define PCIMCR_MRSET_OFF 0xBFFFFFFF
24#define PCIMCR_RFSH_OFF 0xFFFFFFFB
25
26/*
27 * Only long word accesses of the PCIC's internal local registers and the
28 * configuration registers from the CPU is supported.
29 */
30#define PCIC_WRITE(x,v) writel((v), PCI_REG(x))
31#define PCIC_READ(x) readl(PCI_REG(x))
32
33/*
34 * Description: This function sets up and initializes the pcic, sets
35 * up the BARS, maps the DRAM into the address space etc, etc.
36 */
37int __init pcibios_init_platform(void)
38{
39 unsigned long bcr1, wcr1, wcr2, wcr3, mcr;
40 unsigned short bcr2;
41
42 /*
43 * Initialize the slave bus controller on the pcic. The values used
44 * here should not be hardcoded, but they should be taken from the bsc
45 * on the processor, to make this function as generic as possible.
46 * (i.e. Another sbc may usr different SDRAM timing settings -- in order
47 * for the pcic to work, its settings need to be exactly the same.)
48 */
49 bcr1 = (*(volatile unsigned long*)(SH7751_BCR1));
50 bcr2 = (*(volatile unsigned short*)(SH7751_BCR2));
51 wcr1 = (*(volatile unsigned long*)(SH7751_WCR1));
52 wcr2 = (*(volatile unsigned long*)(SH7751_WCR2));
53 wcr3 = (*(volatile unsigned long*)(SH7751_WCR3));
54 mcr = (*(volatile unsigned long*)(SH7751_MCR));
55
56 bcr1 = bcr1 | 0x00080000; /* Enable Bit 19, BREQEN */
57 (*(volatile unsigned long*)(SH7751_BCR1)) = bcr1;
58
59 bcr1 = bcr1 | 0x40080000; /* Enable Bit 19 BREQEN, set PCIC to slave */
60 PCIC_WRITE(SH7751_PCIBCR1, bcr1); /* PCIC BCR1 */
61 PCIC_WRITE(SH7751_PCIBCR2, bcr2); /* PCIC BCR2 */
62 PCIC_WRITE(SH7751_PCIWCR1, wcr1); /* PCIC WCR1 */
63 PCIC_WRITE(SH7751_PCIWCR2, wcr2); /* PCIC WCR2 */
64 PCIC_WRITE(SH7751_PCIWCR3, wcr3); /* PCIC WCR3 */
65 mcr = (mcr & PCIMCR_MRSET_OFF) & PCIMCR_RFSH_OFF;
66 PCIC_WRITE(SH7751_PCIMCR, mcr); /* PCIC MCR */
67
68
69 /* Enable all interrupts, so we know what to fix */
70 PCIC_WRITE(SH7751_PCIINTM, 0x0000c3ff);
71 PCIC_WRITE(SH7751_PCIAINTM, 0x0000380f);
72
73 /* Set up standard PCI config registers */
74 PCIC_WRITE(SH7751_PCICONF1, 0xF39000C7); /* Bus Master, Mem & I/O access */
75 PCIC_WRITE(SH7751_PCICONF2, 0x00000000); /* PCI Class code & Revision ID */
76 PCIC_WRITE(SH7751_PCICONF4, 0xab000001); /* PCI I/O address (local regs) */
77 PCIC_WRITE(SH7751_PCICONF5, 0x0c000000); /* PCI MEM address (local RAM) */
78 PCIC_WRITE(SH7751_PCICONF6, 0xd0000000); /* PCI MEM address (unused) */
79 PCIC_WRITE(SH7751_PCICONF11, 0x35051054); /* PCI Subsystem ID & Vendor ID */
80 PCIC_WRITE(SH7751_PCILSR0, 0x03f00000); /* MEM (full 64M exposed) */
81 PCIC_WRITE(SH7751_PCILSR1, 0x00000000); /* MEM (unused) */
82 PCIC_WRITE(SH7751_PCILAR0, 0x0c000000); /* MEM (direct map from PCI) */
83 PCIC_WRITE(SH7751_PCILAR1, 0x00000000); /* MEM (unused) */
84
85 /* Now turn it on... */
86 PCIC_WRITE(SH7751_PCICR, 0xa5000001);
87
88 /*
89 * Set PCIMBR and PCIIOBR here, assuming a single window
90 * (16M MEM, 256K IO) is enough. If a larger space is
91 * needed, the readx/writex and inx/outx functions will
92 * have to do more (e.g. setting registers for each call).
93 */
94
95 /*
96 * Set the MBR so PCI address is one-to-one with window,
97 * meaning all calls go straight through... use BUG_ON to
98 * catch erroneous assumption.
99 */
100 BUG_ON(PCIBIOS_MIN_MEM != SH7751_PCI_MEMORY_BASE);
101
102 PCIC_WRITE(SH7751_PCIMBR, PCIBIOS_MIN_MEM);
103
104 /* Set IOBR for window containing area specified in pci.h */
105 PCIC_WRITE(SH7751_PCIIOBR, (PCIBIOS_MIN_IO & SH7751_PCIIOBR_MASK));
106
107 /* All done, may as well say so... */
108 printk("SH7751 PCI: Finished initialization of the PCI controller\n");
109
110 return 1;
111}
112
113int __init pcibios_map_platform_irq(u8 slot, u8 pin)
114{
115 switch (slot) {
116 case 0: return 13;
117 case 1: return 13; /* AMD Ethernet controller */
118 case 2: return -1;
119 case 3: return -1;
120 case 4: return -1;
121 default:
122 printk("PCI: Bad IRQ mapping request for slot %d\n", slot);
123 return -1;
124 }
125}
126
127static struct resource sh7751_io_resource = {
128 .name = "SH7751 IO",
129 .start = SH7751_PCI_IO_BASE,
130 .end = SH7751_PCI_IO_BASE + SH7751_PCI_IO_SIZE - 1,
131 .flags = IORESOURCE_IO
132};
133
134static struct resource sh7751_mem_resource = {
135 .name = "SH7751 mem",
136 .start = SH7751_PCI_MEMORY_BASE,
137 .end = SH7751_PCI_MEMORY_BASE + SH7751_PCI_MEM_SIZE - 1,
138 .flags = IORESOURCE_MEM
139};
140
141extern struct pci_ops sh7751_pci_ops;
142
143struct pci_channel board_pci_channels[] = {
144 { &sh7751_pci_ops, &sh7751_io_resource, &sh7751_mem_resource, 0, 0xff },
145 { NULL, NULL, NULL, 0, 0 },
146};
147
diff --git a/arch/sh/boards/mach-se/7780/irq.c b/arch/sh/boards/mach-se/7780/irq.c
index 66ad292c9fc3..b8d43b638fcf 100644
--- a/arch/sh/boards/mach-se/7780/irq.c
+++ b/arch/sh/boards/mach-se/7780/irq.c
@@ -12,10 +12,13 @@
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/irq.h> 13#include <linux/irq.h>
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include <asm/irq.h> 15#include <linux/irq.h>
16#include <asm/io.h> 16#include <linux/io.h>
17#include <mach-se/mach/se7780.h> 17#include <mach-se/mach/se7780.h>
18 18
19#define INTC_BASE 0xffd00000
20#define INTC_ICR1 (INTC_BASE+0x1c)
21
19/* 22/*
20 * Initialize IRQ setting 23 * Initialize IRQ setting
21 */ 24 */
@@ -43,4 +46,24 @@ void __init init_se7780_IRQ(void)
43 ctrl_outw((IRQPIN_PCCPW << IRQPOS_PCCPW), FPGA_INTSEL3); 46 ctrl_outw((IRQPIN_PCCPW << IRQPOS_PCCPW), FPGA_INTSEL3);
44 47
45 plat_irq_setup_pins(IRQ_MODE_IRQ); /* install handlers for IRQ0-7 */ 48 plat_irq_setup_pins(IRQ_MODE_IRQ); /* install handlers for IRQ0-7 */
49
50 /* ICR1: detect low level(for 2ndcut) */
51 ctrl_outl(0xAAAA0000, INTC_ICR1);
52
53 /*
54 * FPGA PCISEL register initialize
55 *
56 * CPU || SLOT1 | SLOT2 | S-ATA | USB
57 * -------------------------------------
58 * INTA || INTA | INTD | -- | INTB
59 * -------------------------------------
60 * INTB || INTB | INTA | -- | INTC
61 * -------------------------------------
62 * INTC || INTC | INTB | INTA | --
63 * -------------------------------------
64 * INTD || INTD | INTC | -- | INTA
65 * -------------------------------------
66 */
67 ctrl_outw(0x0013, FPGA_PCI_INTSEL1);
68 ctrl_outw(0xE402, FPGA_PCI_INTSEL2);
46} 69}
diff --git a/arch/sh/boards/mach-se/Makefile b/arch/sh/boards/mach-se/Makefile
index 2de42bae4b4f..b537e238c6bc 100644
--- a/arch/sh/boards/mach-se/Makefile
+++ b/arch/sh/boards/mach-se/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_SH_7751_SOLUTION_ENGINE) += 7751/
7obj-$(CONFIG_SH_7780_SOLUTION_ENGINE) += 7780/ 7obj-$(CONFIG_SH_7780_SOLUTION_ENGINE) += 7780/
8obj-$(CONFIG_SH_7343_SOLUTION_ENGINE) += 7343/ 8obj-$(CONFIG_SH_7343_SOLUTION_ENGINE) += 7343/
9obj-$(CONFIG_SH_7721_SOLUTION_ENGINE) += 7721/ 9obj-$(CONFIG_SH_7721_SOLUTION_ENGINE) += 7721/
10obj-$(CONFIG_SH_7724_SOLUTION_ENGINE) += 7724/
diff --git a/arch/sh/boards/mach-sh03/rtc.c b/arch/sh/boards/mach-sh03/rtc.c
index 0a9266bb51c5..a8b9f844ab5b 100644
--- a/arch/sh/boards/mach-sh03/rtc.c
+++ b/arch/sh/boards/mach-sh03/rtc.c
@@ -35,13 +35,13 @@
35#define RTC_BUSY 1 35#define RTC_BUSY 1
36#define RTC_STOP 2 36#define RTC_STOP 2
37 37
38extern spinlock_t rtc_lock; 38static DEFINE_SPINLOCK(sh03_rtc_lock);
39 39
40unsigned long get_cmos_time(void) 40unsigned long get_cmos_time(void)
41{ 41{
42 unsigned int year, mon, day, hour, min, sec; 42 unsigned int year, mon, day, hour, min, sec;
43 43
44 spin_lock(&rtc_lock); 44 spin_lock(&sh03_rtc_lock);
45 again: 45 again:
46 do { 46 do {
47 sec = (ctrl_inb(RTC_SEC1) & 0xf) + (ctrl_inb(RTC_SEC10) & 0x7) * 10; 47 sec = (ctrl_inb(RTC_SEC1) & 0xf) + (ctrl_inb(RTC_SEC10) & 0x7) * 10;
@@ -73,7 +73,7 @@ unsigned long get_cmos_time(void)
73 goto again; 73 goto again;
74 } 74 }
75 75
76 spin_unlock(&rtc_lock); 76 spin_unlock(&sh03_rtc_lock);
77 return mktime(year, mon, day, hour, min, sec); 77 return mktime(year, mon, day, hour, min, sec);
78} 78}
79 79
@@ -91,7 +91,7 @@ static int set_rtc_mmss(unsigned long nowtime)
91 int i; 91 int i;
92 92
93 /* gets recalled with irq locally disabled */ 93 /* gets recalled with irq locally disabled */
94 spin_lock(&rtc_lock); 94 spin_lock(&sh03_rtc_lock);
95 for (i = 0 ; i < 1000000 ; i++) /* may take up to 1 second... */ 95 for (i = 0 ; i < 1000000 ; i++) /* may take up to 1 second... */
96 if (!(ctrl_inb(RTC_CTL) & RTC_BUSY)) 96 if (!(ctrl_inb(RTC_CTL) & RTC_BUSY))
97 break; 97 break;
@@ -113,7 +113,7 @@ static int set_rtc_mmss(unsigned long nowtime)
113 cmos_minutes, real_minutes); 113 cmos_minutes, real_minutes);
114 retval = -1; 114 retval = -1;
115 } 115 }
116 spin_unlock(&rtc_lock); 116 spin_unlock(&sh03_rtc_lock);
117 117
118 return retval; 118 return retval;
119} 119}
diff --git a/arch/sh/boards/mach-snapgear/io.c b/arch/sh/boards/mach-snapgear/io.c
index 0f4824264557..476650e42dbc 100644
--- a/arch/sh/boards/mach-snapgear/io.c
+++ b/arch/sh/boards/mach-snapgear/io.c
@@ -36,8 +36,6 @@ unsigned char snapgear_inb(unsigned long port)
36{ 36{
37 if (PXSEG(port)) 37 if (PXSEG(port))
38 return *(volatile unsigned char *)port; 38 return *(volatile unsigned char *)port;
39 else if (is_pci_ioaddr(port))
40 return *(volatile unsigned char *)pci_ioaddr(port);
41 else 39 else
42 return (*port2adr(port)) & 0xff; 40 return (*port2adr(port)) & 0xff;
43} 41}
@@ -48,8 +46,6 @@ unsigned char snapgear_inb_p(unsigned long port)
48 46
49 if (PXSEG(port)) 47 if (PXSEG(port))
50 v = *(volatile unsigned char *)port; 48 v = *(volatile unsigned char *)port;
51 else if (is_pci_ioaddr(port))
52 v = *(volatile unsigned char *)pci_ioaddr(port);
53 else 49 else
54 v = (*port2adr(port))&0xff; 50 v = (*port2adr(port))&0xff;
55 ctrl_delay(); 51 ctrl_delay();
@@ -60,8 +56,6 @@ unsigned short snapgear_inw(unsigned long port)
60{ 56{
61 if (PXSEG(port)) 57 if (PXSEG(port))
62 return *(volatile unsigned short *)port; 58 return *(volatile unsigned short *)port;
63 else if (is_pci_ioaddr(port))
64 return *(volatile unsigned short *)pci_ioaddr(port);
65 else if (port >= 0x2000) 59 else if (port >= 0x2000)
66 return *port2adr(port); 60 return *port2adr(port);
67 else 61 else
@@ -73,8 +67,6 @@ unsigned int snapgear_inl(unsigned long port)
73{ 67{
74 if (PXSEG(port)) 68 if (PXSEG(port))
75 return *(volatile unsigned long *)port; 69 return *(volatile unsigned long *)port;
76 else if (is_pci_ioaddr(port))
77 return *(volatile unsigned int *)pci_ioaddr(port);
78 else if (port >= 0x2000) 70 else if (port >= 0x2000)
79 return *port2adr(port); 71 return *port2adr(port);
80 else 72 else
@@ -87,8 +79,6 @@ void snapgear_outb(unsigned char value, unsigned long port)
87 79
88 if (PXSEG(port)) 80 if (PXSEG(port))
89 *(volatile unsigned char *)port = value; 81 *(volatile unsigned char *)port = value;
90 else if (is_pci_ioaddr(port))
91 *((unsigned char*)pci_ioaddr(port)) = value;
92 else 82 else
93 *(port2adr(port)) = value; 83 *(port2adr(port)) = value;
94} 84}
@@ -97,8 +87,6 @@ void snapgear_outb_p(unsigned char value, unsigned long port)
97{ 87{
98 if (PXSEG(port)) 88 if (PXSEG(port))
99 *(volatile unsigned char *)port = value; 89 *(volatile unsigned char *)port = value;
100 else if (is_pci_ioaddr(port))
101 *((unsigned char*)pci_ioaddr(port)) = value;
102 else 90 else
103 *(port2adr(port)) = value; 91 *(port2adr(port)) = value;
104 ctrl_delay(); 92 ctrl_delay();
@@ -108,8 +96,6 @@ void snapgear_outw(unsigned short value, unsigned long port)
108{ 96{
109 if (PXSEG(port)) 97 if (PXSEG(port))
110 *(volatile unsigned short *)port = value; 98 *(volatile unsigned short *)port = value;
111 else if (is_pci_ioaddr(port))
112 *((unsigned short *)pci_ioaddr(port)) = value;
113 else if (port >= 0x2000) 99 else if (port >= 0x2000)
114 *port2adr(port) = value; 100 *port2adr(port) = value;
115 else 101 else
@@ -120,8 +106,6 @@ void snapgear_outl(unsigned int value, unsigned long port)
120{ 106{
121 if (PXSEG(port)) 107 if (PXSEG(port))
122 *(volatile unsigned long *)port = value; 108 *(volatile unsigned long *)port = value;
123 else if (is_pci_ioaddr(port))
124 *((unsigned long*)pci_ioaddr(port)) = value;
125 else 109 else
126 maybebadio(port); 110 maybebadio(port);
127} 111}
diff --git a/arch/sh/boards/mach-systemh/io.c b/arch/sh/boards/mach-systemh/io.c
index dec3db0ee933..15577ff1f715 100644
--- a/arch/sh/boards/mach-systemh/io.c
+++ b/arch/sh/boards/mach-systemh/io.c
@@ -35,8 +35,6 @@ unsigned char sh7751systemh_inb(unsigned long port)
35{ 35{
36 if (PXSEG(port)) 36 if (PXSEG(port))
37 return *(volatile unsigned char *)port; 37 return *(volatile unsigned char *)port;
38 else if (is_pci_ioaddr(port))
39 return *(volatile unsigned char *)pci_ioaddr(port);
40 else if (port <= 0x3F1) 38 else if (port <= 0x3F1)
41 return *(volatile unsigned char *)ETHER_IOMAP(port); 39 return *(volatile unsigned char *)ETHER_IOMAP(port);
42 else 40 else
@@ -49,8 +47,6 @@ unsigned char sh7751systemh_inb_p(unsigned long port)
49 47
50 if (PXSEG(port)) 48 if (PXSEG(port))
51 v = *(volatile unsigned char *)port; 49 v = *(volatile unsigned char *)port;
52 else if (is_pci_ioaddr(port))
53 v = *(volatile unsigned char *)pci_ioaddr(port);
54 else if (port <= 0x3F1) 50 else if (port <= 0x3F1)
55 v = *(volatile unsigned char *)ETHER_IOMAP(port); 51 v = *(volatile unsigned char *)ETHER_IOMAP(port);
56 else 52 else
@@ -63,8 +59,6 @@ unsigned short sh7751systemh_inw(unsigned long port)
63{ 59{
64 if (PXSEG(port)) 60 if (PXSEG(port))
65 return *(volatile unsigned short *)port; 61 return *(volatile unsigned short *)port;
66 else if (is_pci_ioaddr(port))
67 return *(volatile unsigned short *)pci_ioaddr(port);
68 else if (port >= 0x2000) 62 else if (port >= 0x2000)
69 return *port2adr(port); 63 return *port2adr(port);
70 else if (port <= 0x3F1) 64 else if (port <= 0x3F1)
@@ -78,8 +72,6 @@ unsigned int sh7751systemh_inl(unsigned long port)
78{ 72{
79 if (PXSEG(port)) 73 if (PXSEG(port))
80 return *(volatile unsigned long *)port; 74 return *(volatile unsigned long *)port;
81 else if (is_pci_ioaddr(port))
82 return *(volatile unsigned int *)pci_ioaddr(port);
83 else if (port >= 0x2000) 75 else if (port >= 0x2000)
84 return *port2adr(port); 76 return *port2adr(port);
85 else if (port <= 0x3F1) 77 else if (port <= 0x3F1)
@@ -94,8 +86,6 @@ void sh7751systemh_outb(unsigned char value, unsigned long port)
94 86
95 if (PXSEG(port)) 87 if (PXSEG(port))
96 *(volatile unsigned char *)port = value; 88 *(volatile unsigned char *)port = value;
97 else if (is_pci_ioaddr(port))
98 *((unsigned char*)pci_ioaddr(port)) = value;
99 else if (port <= 0x3F1) 89 else if (port <= 0x3F1)
100 *(volatile unsigned char *)ETHER_IOMAP(port) = value; 90 *(volatile unsigned char *)ETHER_IOMAP(port) = value;
101 else 91 else
@@ -106,8 +96,6 @@ void sh7751systemh_outb_p(unsigned char value, unsigned long port)
106{ 96{
107 if (PXSEG(port)) 97 if (PXSEG(port))
108 *(volatile unsigned char *)port = value; 98 *(volatile unsigned char *)port = value;
109 else if (is_pci_ioaddr(port))
110 *((unsigned char*)pci_ioaddr(port)) = value;
111 else if (port <= 0x3F1) 99 else if (port <= 0x3F1)
112 *(volatile unsigned char *)ETHER_IOMAP(port) = value; 100 *(volatile unsigned char *)ETHER_IOMAP(port) = value;
113 else 101 else
@@ -119,8 +107,6 @@ void sh7751systemh_outw(unsigned short value, unsigned long port)
119{ 107{
120 if (PXSEG(port)) 108 if (PXSEG(port))
121 *(volatile unsigned short *)port = value; 109 *(volatile unsigned short *)port = value;
122 else if (is_pci_ioaddr(port))
123 *((unsigned short *)pci_ioaddr(port)) = value;
124 else if (port >= 0x2000) 110 else if (port >= 0x2000)
125 *port2adr(port) = value; 111 *port2adr(port) = value;
126 else if (port <= 0x3F1) 112 else if (port <= 0x3F1)
@@ -133,8 +119,6 @@ void sh7751systemh_outl(unsigned int value, unsigned long port)
133{ 119{
134 if (PXSEG(port)) 120 if (PXSEG(port))
135 *(volatile unsigned long *)port = value; 121 *(volatile unsigned long *)port = value;
136 else if (is_pci_ioaddr(port))
137 *((unsigned long*)pci_ioaddr(port)) = value;
138 else 122 else
139 maybebadio(port); 123 maybebadio(port);
140} 124}
diff --git a/arch/sh/boards/mach-titan/io.c b/arch/sh/boards/mach-titan/io.c
index 4badad4c6f30..0130e9826aca 100644
--- a/arch/sh/boards/mach-titan/io.c
+++ b/arch/sh/boards/mach-titan/io.c
@@ -17,8 +17,6 @@ u8 titan_inb(unsigned long port)
17{ 17{
18 if (PXSEG(port)) 18 if (PXSEG(port))
19 return ctrl_inb(port); 19 return ctrl_inb(port);
20 else if (is_pci_ioaddr(port))
21 return ctrl_inb(pci_ioaddr(port));
22 return ctrl_inw(port2adr(port)) & 0xff; 20 return ctrl_inw(port2adr(port)) & 0xff;
23} 21}
24 22
@@ -28,8 +26,6 @@ u8 titan_inb_p(unsigned long port)
28 26
29 if (PXSEG(port)) 27 if (PXSEG(port))
30 v = ctrl_inb(port); 28 v = ctrl_inb(port);
31 else if (is_pci_ioaddr(port))
32 v = ctrl_inb(pci_ioaddr(port));
33 else 29 else
34 v = ctrl_inw(port2adr(port)) & 0xff; 30 v = ctrl_inw(port2adr(port)) & 0xff;
35 ctrl_delay(); 31 ctrl_delay();
@@ -40,8 +36,6 @@ u16 titan_inw(unsigned long port)
40{ 36{
41 if (PXSEG(port)) 37 if (PXSEG(port))
42 return ctrl_inw(port); 38 return ctrl_inw(port);
43 else if (is_pci_ioaddr(port))
44 return ctrl_inw(pci_ioaddr(port));
45 else if (port >= 0x2000) 39 else if (port >= 0x2000)
46 return ctrl_inw(port2adr(port)); 40 return ctrl_inw(port2adr(port));
47 else 41 else
@@ -53,8 +47,6 @@ u32 titan_inl(unsigned long port)
53{ 47{
54 if (PXSEG(port)) 48 if (PXSEG(port))
55 return ctrl_inl(port); 49 return ctrl_inl(port);
56 else if (is_pci_ioaddr(port))
57 return ctrl_inl(pci_ioaddr(port));
58 else if (port >= 0x2000) 50 else if (port >= 0x2000)
59 return ctrl_inw(port2adr(port)); 51 return ctrl_inw(port2adr(port));
60 else 52 else
@@ -66,8 +58,6 @@ void titan_outb(u8 value, unsigned long port)
66{ 58{
67 if (PXSEG(port)) 59 if (PXSEG(port))
68 ctrl_outb(value, port); 60 ctrl_outb(value, port);
69 else if (is_pci_ioaddr(port))
70 ctrl_outb(value, pci_ioaddr(port));
71 else 61 else
72 ctrl_outw(value, port2adr(port)); 62 ctrl_outw(value, port2adr(port));
73} 63}
@@ -76,8 +66,6 @@ void titan_outb_p(u8 value, unsigned long port)
76{ 66{
77 if (PXSEG(port)) 67 if (PXSEG(port))
78 ctrl_outb(value, port); 68 ctrl_outb(value, port);
79 else if (is_pci_ioaddr(port))
80 ctrl_outb(value, pci_ioaddr(port));
81 else 69 else
82 ctrl_outw(value, port2adr(port)); 70 ctrl_outw(value, port2adr(port));
83 ctrl_delay(); 71 ctrl_delay();
@@ -87,8 +75,6 @@ void titan_outw(u16 value, unsigned long port)
87{ 75{
88 if (PXSEG(port)) 76 if (PXSEG(port))
89 ctrl_outw(value, port); 77 ctrl_outw(value, port);
90 else if (is_pci_ioaddr(port))
91 ctrl_outw(value, pci_ioaddr(port));
92 else if (port >= 0x2000) 78 else if (port >= 0x2000)
93 ctrl_outw(value, port2adr(port)); 79 ctrl_outw(value, port2adr(port));
94 else 80 else
@@ -99,8 +85,6 @@ void titan_outl(u32 value, unsigned long port)
99{ 85{
100 if (PXSEG(port)) 86 if (PXSEG(port))
101 ctrl_outl(value, port); 87 ctrl_outl(value, port);
102 else if (is_pci_ioaddr(port))
103 ctrl_outl(value, pci_ioaddr(port));
104 else 88 else
105 maybebadio(port); 89 maybebadio(port);
106} 90}
@@ -117,10 +101,8 @@ void titan_outsl(unsigned long port, const void *src, unsigned long count)
117 101
118void __iomem *titan_ioport_map(unsigned long port, unsigned int size) 102void __iomem *titan_ioport_map(unsigned long port, unsigned int size)
119{ 103{
120 if (PXSEG(port) || is_pci_memaddr(port)) 104 if (PXSEG(port))
121 return (void __iomem *)port; 105 return (void __iomem *)port;
122 else if (is_pci_ioaddr(port))
123 return (void __iomem *)pci_ioaddr(port);
124 106
125 return (void __iomem *)port2adr(port); 107 return (void __iomem *)port2adr(port);
126} 108}
diff --git a/arch/sh/boot/Makefile b/arch/sh/boot/Makefile
index 95483d161258..78efb04c28f3 100644
--- a/arch/sh/boot/Makefile
+++ b/arch/sh/boot/Makefile
@@ -20,9 +20,6 @@ CONFIG_BOOT_LINK_OFFSET ?= 0x00800000
20CONFIG_ZERO_PAGE_OFFSET ?= 0x00001000 20CONFIG_ZERO_PAGE_OFFSET ?= 0x00001000
21CONFIG_ENTRY_OFFSET ?= 0x00001000 21CONFIG_ENTRY_OFFSET ?= 0x00001000
22 22
23export CONFIG_PAGE_OFFSET CONFIG_MEMORY_START CONFIG_BOOT_LINK_OFFSET \
24 CONFIG_ZERO_PAGE_OFFSET CONFIG_ENTRY_OFFSET
25
26targets := zImage vmlinux.srec uImage uImage.srec 23targets := zImage vmlinux.srec uImage uImage.srec
27subdir- := compressed 24subdir- := compressed
28 25
@@ -43,6 +40,9 @@ KERNEL_MEMORY := $(shell /bin/bash -c 'printf "0x%08x" \
43 $$[$(CONFIG_MEMORY_START)]') 40 $$[$(CONFIG_MEMORY_START)]')
44endif 41endif
45 42
43export CONFIG_PAGE_OFFSET CONFIG_MEMORY_START CONFIG_BOOT_LINK_OFFSET \
44 CONFIG_ZERO_PAGE_OFFSET CONFIG_ENTRY_OFFSET KERNEL_MEMORY
45
46KERNEL_LOAD := $(shell /bin/bash -c 'printf "0x%08x" \ 46KERNEL_LOAD := $(shell /bin/bash -c 'printf "0x%08x" \
47 $$[$(CONFIG_PAGE_OFFSET) + \ 47 $$[$(CONFIG_PAGE_OFFSET) + \
48 $(KERNEL_MEMORY) + \ 48 $(KERNEL_MEMORY) + \
diff --git a/arch/sh/boot/compressed/Makefile b/arch/sh/boot/compressed/Makefile
index efb01dc3c8c3..9531bf1b7c2f 100644
--- a/arch/sh/boot/compressed/Makefile
+++ b/arch/sh/boot/compressed/Makefile
@@ -1,5 +1,47 @@
1ifeq ($(CONFIG_SUPERH32),y) 1#
2include ${srctree}/arch/sh/boot/compressed/Makefile_32 2# linux/arch/sh/boot/compressed/Makefile
3else 3#
4include ${srctree}/arch/sh/boot/compressed/Makefile_64 4# create a compressed vmlinux image from the original vmlinux
5#
6
7targets := vmlinux vmlinux.bin vmlinux.bin.gz \
8 head_$(BITS).o misc_$(BITS).o piggy.o
9
10OBJECTS = $(obj)/head_$(BITS).o $(obj)/misc_$(BITS).o $(obj)/cache.o
11
12ifdef CONFIG_SH_STANDARD_BIOS
13OBJECTS += $(obj)/../../kernel/sh_bios.o
5endif 14endif
15
16#
17# IMAGE_OFFSET is the load offset of the compression loader
18#
19IMAGE_OFFSET := $(shell /bin/bash -c 'printf "0x%08x" \
20 $$[$(CONFIG_PAGE_OFFSET) + \
21 $(KERNEL_MEMORY) + \
22 $(CONFIG_BOOT_LINK_OFFSET)]')
23
24LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name)
25
26ifeq ($(CONFIG_FUNCTION_TRACER),y)
27ORIG_CFLAGS := $(KBUILD_CFLAGS)
28KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
29endif
30
31LDFLAGS_vmlinux := --oformat $(ld-bfd) -Ttext $(IMAGE_OFFSET) -e startup \
32 -T $(obj)/../../kernel/vmlinux.lds
33
34$(obj)/vmlinux: $(OBJECTS) $(obj)/piggy.o $(LIBGCC) FORCE
35 $(call if_changed,ld)
36 @:
37
38$(obj)/vmlinux.bin: vmlinux FORCE
39 $(call if_changed,objcopy)
40
41$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
42 $(call if_changed,gzip)
43
44OBJCOPYFLAGS += -R .empty_zero_page
45
46$(obj)/piggy.o: $(obj)/piggy.S $(obj)/vmlinux.bin.gz FORCE
47 $(call if_changed,as_o_S)
diff --git a/arch/sh/boot/compressed/Makefile_32 b/arch/sh/boot/compressed/Makefile_32
deleted file mode 100644
index b96a055b053e..000000000000
--- a/arch/sh/boot/compressed/Makefile_32
+++ /dev/null
@@ -1,46 +0,0 @@
1#
2# linux/arch/sh/boot/compressed/Makefile
3#
4# create a compressed vmlinux image from the original vmlinux
5#
6
7targets := vmlinux vmlinux.bin vmlinux.bin.gz \
8 head_32.o misc_32.o piggy.o
9
10OBJECTS = $(obj)/head_32.o $(obj)/misc_32.o
11
12ifdef CONFIG_SH_STANDARD_BIOS
13OBJECTS += $(obj)/../../kernel/sh_bios.o
14endif
15
16#
17# IMAGE_OFFSET is the load offset of the compression loader
18#
19IMAGE_OFFSET := $(shell /bin/bash -c 'printf "0x%08x" \
20 $$[$(CONFIG_PAGE_OFFSET) + \
21 $(CONFIG_MEMORY_START) + \
22 $(CONFIG_BOOT_LINK_OFFSET)]')
23
24LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name)
25
26ifeq ($(CONFIG_FUNCTION_TRACER),y)
27ORIG_CFLAGS := $(KBUILD_CFLAGS)
28KBUILD_CFLAGS = $(subst -pg, , $(ORIG_CFLAGS))
29endif
30
31LDFLAGS_vmlinux := -Ttext $(IMAGE_OFFSET) -e startup -T $(obj)/../../kernel/vmlinux.lds
32
33$(obj)/vmlinux: $(OBJECTS) $(obj)/piggy.o $(LIBGCC) FORCE
34 $(call if_changed,ld)
35 @:
36
37$(obj)/vmlinux.bin: vmlinux FORCE
38 $(call if_changed,objcopy)
39
40$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
41 $(call if_changed,gzip)
42
43OBJCOPYFLAGS += -R .empty_zero_page
44
45$(obj)/piggy.o: $(obj)/piggy.S $(obj)/vmlinux.bin.gz FORCE
46 $(call if_changed,as_o_S)
diff --git a/arch/sh/boot/compressed/Makefile_64 b/arch/sh/boot/compressed/Makefile_64
deleted file mode 100644
index 658d4f915556..000000000000
--- a/arch/sh/boot/compressed/Makefile_64
+++ /dev/null
@@ -1,43 +0,0 @@
1#
2# arch/sh/boot/compressed/Makefile_64
3#
4# create a compressed vmlinux image from the original vmlinux
5#
6# Copyright (C) 2002 Stuart Menefy
7# Copyright (C) 2004 Paul Mundt
8#
9# This file is subject to the terms and conditions of the GNU General Public
10# License. See the file "COPYING" in the main directory of this archive
11# for more details.
12#
13
14targets := vmlinux vmlinux.bin vmlinux.bin.gz \
15 head_64.o misc_64.o cache.o piggy.o
16
17OBJECTS := $(obj)/vmlinux_64.lds $(obj)/head_64.o $(obj)/misc_64.o \
18 $(obj)/cache.o
19
20#
21# ZIMAGE_OFFSET is the load offset of the compression loader
22# (4M for the kernel plus 64K for this loader)
23#
24ZIMAGE_OFFSET := $(shell /bin/bash -c 'printf "0x%08x" \
25 $$[$(CONFIG_PAGE_OFFSET)+0x400000+0x10000]')
26
27LDFLAGS_vmlinux := -Ttext $(ZIMAGE_OFFSET) -e startup \
28 -T $(obj)/../../kernel/vmlinux.lds
29
30$(obj)/vmlinux: $(OBJECTS) $(obj)/piggy.o FORCE
31 $(call if_changed,ld)
32 @:
33
34$(obj)/vmlinux.bin: vmlinux FORCE
35 $(call if_changed,objcopy)
36
37$(obj)/vmlinux.bin.gz: $(obj)/vmlinux.bin FORCE
38 $(call if_changed,gzip)
39
40OBJCOPYFLAGS += -R .empty_zero_page
41
42$(obj)/piggy.o: $(obj)/piggy.S $(obj)/vmlinux.bin.gz FORCE
43 $(call if_changed,as_o_S)
diff --git a/arch/sh/boot/compressed/head_64.S b/arch/sh/boot/compressed/head_64.S
index 622eac3cf556..9993113c6713 100644
--- a/arch/sh/boot/compressed/head_64.S
+++ b/arch/sh/boot/compressed/head_64.S
@@ -14,6 +14,7 @@
14 * Copyright (C) 2002 Stuart Menefy (stuart.menefy@st.com) 14 * Copyright (C) 2002 Stuart Menefy (stuart.menefy@st.com)
15 */ 15 */
16#include <asm/cache.h> 16#include <asm/cache.h>
17#include <asm/tlb.h>
17#include <cpu/mmu_context.h> 18#include <cpu/mmu_context.h>
18#include <cpu/registers.h> 19#include <cpu/registers.h>
19 20
@@ -33,11 +34,7 @@
33#define ICCR0_INIT_VAL ICCR0_ON | ICCR0_ICI /* ICE + ICI */ 34#define ICCR0_INIT_VAL ICCR0_ON | ICCR0_ICI /* ICE + ICI */
34#define ICCR1_INIT_VAL ICCR1_NOLOCK /* No locking */ 35#define ICCR1_INIT_VAL ICCR1_NOLOCK /* No locking */
35 36
36#if 1
37#define OCCR0_INIT_VAL OCCR0_ON | OCCR0_OCI | OCCR0_WB /* OCE + OCI + WB */ 37#define OCCR0_INIT_VAL OCCR0_ON | OCCR0_OCI | OCCR0_WB /* OCE + OCI + WB */
38#else
39#define OCCR0_INIT_VAL OCCR0_OFF
40#endif
41#define OCCR1_INIT_VAL OCCR1_NOLOCK /* No locking */ 38#define OCCR1_INIT_VAL OCCR1_NOLOCK /* No locking */
42 39
43 .text 40 .text
diff --git a/arch/sh/boot/compressed/vmlinux_64.lds b/arch/sh/boot/compressed/vmlinux_64.lds
deleted file mode 100644
index 59c2ef4aeda5..000000000000
--- a/arch/sh/boot/compressed/vmlinux_64.lds
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2 * ld script to make compressed SuperH/shmedia Linux kernel+decompression
3 * bootstrap
4 * Modified by Stuart Menefy from arch/sh/vmlinux.lds.S written by Niibe Yutaka
5 */
6
7
8#ifdef CONFIG_LITTLE_ENDIAN
9/* OUTPUT_FORMAT("elf32-sh64l-linux", "elf32-sh64l-linux", "elf32-sh64l-linux") */
10#define NOP 0x6ff0fff0
11#else
12/* OUTPUT_FORMAT("elf32-sh64", "elf32-sh64", "elf32-sh64") */
13#define NOP 0xf0fff06f
14#endif
15
16OUTPUT_FORMAT("elf32-sh64-linux")
17OUTPUT_ARCH(sh)
18ENTRY(_start)
19
20#define ALIGNED_GAP(section, align) (((ADDR(section)+SIZEOF(section)+(align)-1) & ~((align)-1))-ADDR(section))
21#define FOLLOWING(section, align) AT (LOADADDR(section) + ALIGNED_GAP(section,align))
22
23SECTIONS
24{
25 _text = .; /* Text and read-only data */
26
27 .text : {
28 *(.text)
29 *(.text64)
30 *(.text..SHmedia32)
31 *(.fixup)
32 *(.gnu.warning)
33 } = NOP
34 . = ALIGN(4);
35 .rodata : { *(.rodata) }
36
37 /* There is no 'real' reason for eight byte alignment, four would work
38 * as well, but gdb downloads much (*4) faster with this.
39 */
40 . = ALIGN(8);
41 .image : { *(.image) }
42 . = ALIGN(4);
43 _etext = .; /* End of text section */
44
45 .data : /* Data */
46 FOLLOWING(.image, 4)
47 {
48 _data = .;
49 *(.data)
50 }
51 _data_image = LOADADDR(.data);/* Address of data section in ROM */
52
53 _edata = .; /* End of data section */
54
55 .stack : { stack = .; _stack = .; }
56
57 . = ALIGN(4);
58 __bss_start = .; /* BSS */
59 .bss : {
60 *(.bss)
61 }
62 . = ALIGN(4);
63 _end = . ;
64}
diff --git a/arch/sh/cchips/Kconfig b/arch/sh/cchips/Kconfig
index f43d18373f22..a5ab2eccdaa6 100644
--- a/arch/sh/cchips/Kconfig
+++ b/arch/sh/cchips/Kconfig
@@ -34,11 +34,6 @@ config HD64461_IRQ
34 34
35 Do not change this unless you know what you are doing. 35 Do not change this unless you know what you are doing.
36 36
37config HD64461_IOBASE
38 hex "HD64461 start address"
39 depends on HD64461
40 default "0xb0000000"
41
42config HD64461_ENABLER 37config HD64461_ENABLER
43 bool "HD64461 PCMCIA enabler" 38 bool "HD64461 PCMCIA enabler"
44 depends on HD64461 39 depends on HD64461
diff --git a/arch/sh/cchips/hd6446x/hd64461.c b/arch/sh/cchips/hd6446x/hd64461.c
index 25ef91061521..50aa0c1f76ea 100644
--- a/arch/sh/cchips/hd6446x/hd64461.c
+++ b/arch/sh/cchips/hd6446x/hd64461.c
@@ -80,7 +80,7 @@ int __init setup_hd64461(void)
80 80
81 printk(KERN_INFO 81 printk(KERN_INFO
82 "HD64461 configured at 0x%x on irq %d(mapped into %d to %d)\n", 82 "HD64461 configured at 0x%x on irq %d(mapped into %d to %d)\n",
83 CONFIG_HD64461_IOBASE, CONFIG_HD64461_IRQ, HD64461_IRQBASE, 83 HD64461_IOBASE, CONFIG_HD64461_IRQ, HD64461_IRQBASE,
84 HD64461_IRQBASE + 15); 84 HD64461_IRQBASE + 15);
85 85
86/* Should be at processor specific part.. */ 86/* Should be at processor specific part.. */
diff --git a/arch/sh/configs/ap325rxa_defconfig b/arch/sh/configs/ap325rxa_defconfig
index c8d982a8a2e6..022f70e0ea03 100644
--- a/arch/sh/configs/ap325rxa_defconfig
+++ b/arch/sh/configs/ap325rxa_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 17:46:53 2009 4# Mon Apr 27 12:42:06 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -74,6 +75,7 @@ CONFIG_EMBEDDED=y
74CONFIG_UID16=y 75CONFIG_UID16=y
75CONFIG_SYSCTL_SYSCALL=y 76CONFIG_SYSCTL_SYSCALL=y
76# CONFIG_KALLSYMS is not set 77# CONFIG_KALLSYMS is not set
78# CONFIG_STRIP_ASM_SYMS is not set
77CONFIG_HOTPLUG=y 79CONFIG_HOTPLUG=y
78CONFIG_PRINTK=y 80CONFIG_PRINTK=y
79CONFIG_BUG=y 81CONFIG_BUG=y
@@ -92,12 +94,15 @@ CONFIG_SLAB=y
92# CONFIG_SLUB is not set 94# CONFIG_SLUB is not set
93# CONFIG_SLOB is not set 95# CONFIG_SLOB is not set
94# CONFIG_PROFILING is not set 96# CONFIG_PROFILING is not set
97# CONFIG_MARKERS is not set
95CONFIG_HAVE_OPROFILE=y 98CONFIG_HAVE_OPROFILE=y
96CONFIG_HAVE_IOREMAP_PROT=y 99CONFIG_HAVE_IOREMAP_PROT=y
97CONFIG_HAVE_KPROBES=y 100CONFIG_HAVE_KPROBES=y
98CONFIG_HAVE_KRETPROBES=y 101CONFIG_HAVE_KRETPROBES=y
99CONFIG_HAVE_ARCH_TRACEHOOK=y 102CONFIG_HAVE_ARCH_TRACEHOOK=y
100CONFIG_HAVE_CLK=y 103CONFIG_HAVE_CLK=y
104CONFIG_HAVE_DMA_API_DEBUG=y
105# CONFIG_SLOW_WORK is not set
101CONFIG_HAVE_GENERIC_DMA_COHERENT=y 106CONFIG_HAVE_GENERIC_DMA_COHERENT=y
102CONFIG_SLABINFO=y 107CONFIG_SLABINFO=y
103CONFIG_RT_MUTEXES=y 108CONFIG_RT_MUTEXES=y
@@ -110,7 +115,6 @@ CONFIG_MODULE_UNLOAD=y
110# CONFIG_MODULE_SRCVERSION_ALL is not set 115# CONFIG_MODULE_SRCVERSION_ALL is not set
111CONFIG_BLOCK=y 116CONFIG_BLOCK=y
112# CONFIG_LBD is not set 117# CONFIG_LBD is not set
113# CONFIG_BLK_DEV_IO_TRACE is not set
114# CONFIG_BLK_DEV_BSG is not set 118# CONFIG_BLK_DEV_BSG is not set
115# CONFIG_BLK_DEV_INTEGRITY is not set 119# CONFIG_BLK_DEV_INTEGRITY is not set
116 120
@@ -159,6 +163,7 @@ CONFIG_ARCH_SHMOBILE=y
159# CONFIG_CPU_SUBTYPE_SH7760 is not set 163# CONFIG_CPU_SUBTYPE_SH7760 is not set
160# CONFIG_CPU_SUBTYPE_SH4_202 is not set 164# CONFIG_CPU_SUBTYPE_SH4_202 is not set
161CONFIG_CPU_SUBTYPE_SH7723=y 165CONFIG_CPU_SUBTYPE_SH7723=y
166# CONFIG_CPU_SUBTYPE_SH7724 is not set
162# CONFIG_CPU_SUBTYPE_SH7763 is not set 167# CONFIG_CPU_SUBTYPE_SH7763 is not set
163# CONFIG_CPU_SUBTYPE_SH7770 is not set 168# CONFIG_CPU_SUBTYPE_SH7770 is not set
164# CONFIG_CPU_SUBTYPE_SH7780 is not set 169# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -168,8 +173,6 @@ CONFIG_CPU_SUBTYPE_SH7723=y
168# CONFIG_CPU_SUBTYPE_SH7343 is not set 173# CONFIG_CPU_SUBTYPE_SH7343 is not set
169# CONFIG_CPU_SUBTYPE_SH7722 is not set 174# CONFIG_CPU_SUBTYPE_SH7722 is not set
170# CONFIG_CPU_SUBTYPE_SH7366 is not set 175# CONFIG_CPU_SUBTYPE_SH7366 is not set
171# CONFIG_CPU_SUBTYPE_SH5_101 is not set
172# CONFIG_CPU_SUBTYPE_SH5_103 is not set
173 176
174# 177#
175# Memory management options 178# Memory management options
@@ -573,6 +576,7 @@ CONFIG_SCSI_WAIT_SCAN=m
573CONFIG_SCSI_LOWLEVEL=y 576CONFIG_SCSI_LOWLEVEL=y
574# CONFIG_ISCSI_TCP is not set 577# CONFIG_ISCSI_TCP is not set
575# CONFIG_LIBFC is not set 578# CONFIG_LIBFC is not set
579# CONFIG_LIBFCOE is not set
576# CONFIG_SCSI_DEBUG is not set 580# CONFIG_SCSI_DEBUG is not set
577# CONFIG_SCSI_DH is not set 581# CONFIG_SCSI_DH is not set
578# CONFIG_SCSI_OSD_INITIATOR is not set 582# CONFIG_SCSI_OSD_INITIATOR is not set
@@ -695,6 +699,7 @@ CONFIG_DEVKMEM=y
695# 699#
696# Non-8250 serial port support 700# Non-8250 serial port support
697# 701#
702# CONFIG_SERIAL_MAX3100 is not set
698CONFIG_SERIAL_SH_SCI=y 703CONFIG_SERIAL_SH_SCI=y
699CONFIG_SERIAL_SH_SCI_NR_UARTS=6 704CONFIG_SERIAL_SH_SCI_NR_UARTS=6
700CONFIG_SERIAL_SH_SCI_CONSOLE=y 705CONFIG_SERIAL_SH_SCI_CONSOLE=y
@@ -1030,6 +1035,7 @@ CONFIG_EXT2_FS_POSIX_ACL=y
1030CONFIG_EXT2_FS_SECURITY=y 1035CONFIG_EXT2_FS_SECURITY=y
1031# CONFIG_EXT2_FS_XIP is not set 1036# CONFIG_EXT2_FS_XIP is not set
1032CONFIG_EXT3_FS=y 1037CONFIG_EXT3_FS=y
1038# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
1033CONFIG_EXT3_FS_XATTR=y 1039CONFIG_EXT3_FS_XATTR=y
1034CONFIG_EXT3_FS_POSIX_ACL=y 1040CONFIG_EXT3_FS_POSIX_ACL=y
1035CONFIG_EXT3_FS_SECURITY=y 1041CONFIG_EXT3_FS_SECURITY=y
@@ -1052,6 +1058,11 @@ CONFIG_INOTIFY_USER=y
1052# CONFIG_FUSE_FS is not set 1058# CONFIG_FUSE_FS is not set
1053 1059
1054# 1060#
1061# Caches
1062#
1063# CONFIG_FSCACHE is not set
1064
1065#
1055# CD-ROM/DVD Filesystems 1066# CD-ROM/DVD Filesystems
1056# 1067#
1057# CONFIG_ISO9660_FS is not set 1068# CONFIG_ISO9660_FS is not set
@@ -1100,6 +1111,7 @@ CONFIG_MISC_FILESYSTEMS=y
1100# CONFIG_ROMFS_FS is not set 1111# CONFIG_ROMFS_FS is not set
1101# CONFIG_SYSV_FS is not set 1112# CONFIG_SYSV_FS is not set
1102# CONFIG_UFS_FS is not set 1113# CONFIG_UFS_FS is not set
1114# CONFIG_NILFS2_FS is not set
1103CONFIG_NETWORK_FILESYSTEMS=y 1115CONFIG_NETWORK_FILESYSTEMS=y
1104CONFIG_NFS_FS=y 1116CONFIG_NFS_FS=y
1105CONFIG_NFS_V3=y 1117CONFIG_NFS_V3=y
@@ -1191,10 +1203,24 @@ CONFIG_SYSCTL_SYSCALL_CHECK=y
1191CONFIG_HAVE_FUNCTION_TRACER=y 1203CONFIG_HAVE_FUNCTION_TRACER=y
1192CONFIG_HAVE_DYNAMIC_FTRACE=y 1204CONFIG_HAVE_DYNAMIC_FTRACE=y
1193CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1205CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1206CONFIG_TRACING_SUPPORT=y
1194 1207
1195# 1208#
1196# Tracers 1209# Tracers
1197# 1210#
1211# CONFIG_FUNCTION_TRACER is not set
1212# CONFIG_IRQSOFF_TRACER is not set
1213# CONFIG_PREEMPT_TRACER is not set
1214# CONFIG_SCHED_TRACER is not set
1215# CONFIG_CONTEXT_SWITCH_TRACER is not set
1216# CONFIG_EVENT_TRACER is not set
1217# CONFIG_BOOT_TRACER is not set
1218# CONFIG_TRACE_BRANCH_PROFILING is not set
1219# CONFIG_STACK_TRACER is not set
1220# CONFIG_KMEMTRACE is not set
1221# CONFIG_WORKQUEUE_TRACER is not set
1222# CONFIG_BLK_DEV_IO_TRACE is not set
1223# CONFIG_DMA_API_DEBUG is not set
1198# CONFIG_SAMPLES is not set 1224# CONFIG_SAMPLES is not set
1199CONFIG_HAVE_ARCH_KGDB=y 1225CONFIG_HAVE_ARCH_KGDB=y
1200# CONFIG_SH_STANDARD_BIOS is not set 1226# CONFIG_SH_STANDARD_BIOS is not set
@@ -1303,6 +1329,7 @@ CONFIG_CRYPTO_CBC=y
1303# 1329#
1304# CONFIG_CRYPTO_ANSI_CPRNG is not set 1330# CONFIG_CRYPTO_ANSI_CPRNG is not set
1305CONFIG_CRYPTO_HW=y 1331CONFIG_CRYPTO_HW=y
1332# CONFIG_BINARY_PRINTF is not set
1306 1333
1307# 1334#
1308# Library routines 1335# Library routines
diff --git a/arch/sh/configs/cayman_defconfig b/arch/sh/configs/cayman_defconfig
index fa5fc1e1e980..40301f86a45c 100644
--- a/arch/sh/configs/cayman_defconfig
+++ b/arch/sh/configs/cayman_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 17:49:14 2009 4# Mon Apr 27 13:42:53 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7# CONFIG_SUPERH32 is not set 7# CONFIG_SUPERH32 is not set
@@ -40,6 +40,7 @@ CONFIG_LOCALVERSION_AUTO=y
40CONFIG_SWAP=y 40CONFIG_SWAP=y
41# CONFIG_SYSVIPC is not set 41# CONFIG_SYSVIPC is not set
42CONFIG_POSIX_MQUEUE=y 42CONFIG_POSIX_MQUEUE=y
43CONFIG_POSIX_MQUEUE_SYSCTL=y
43# CONFIG_BSD_PROCESS_ACCT is not set 44# CONFIG_BSD_PROCESS_ACCT is not set
44# CONFIG_TASKSTATS is not set 45# CONFIG_TASKSTATS is not set
45# CONFIG_AUDIT is not set 46# CONFIG_AUDIT is not set
@@ -70,6 +71,7 @@ CONFIG_SYSCTL_SYSCALL=y
70CONFIG_KALLSYMS=y 71CONFIG_KALLSYMS=y
71# CONFIG_KALLSYMS_ALL is not set 72# CONFIG_KALLSYMS_ALL is not set
72# CONFIG_KALLSYMS_EXTRA_PASS is not set 73# CONFIG_KALLSYMS_EXTRA_PASS is not set
74# CONFIG_STRIP_ASM_SYMS is not set
73CONFIG_HOTPLUG=y 75CONFIG_HOTPLUG=y
74CONFIG_PRINTK=y 76CONFIG_PRINTK=y
75CONFIG_BUG=y 77CONFIG_BUG=y
@@ -89,10 +91,13 @@ CONFIG_SLAB=y
89# CONFIG_SLUB is not set 91# CONFIG_SLUB is not set
90# CONFIG_SLOB is not set 92# CONFIG_SLOB is not set
91# CONFIG_PROFILING is not set 93# CONFIG_PROFILING is not set
94# CONFIG_MARKERS is not set
92CONFIG_HAVE_OPROFILE=y 95CONFIG_HAVE_OPROFILE=y
93CONFIG_HAVE_IOREMAP_PROT=y 96CONFIG_HAVE_IOREMAP_PROT=y
94CONFIG_HAVE_ARCH_TRACEHOOK=y 97CONFIG_HAVE_ARCH_TRACEHOOK=y
95CONFIG_HAVE_CLK=y 98CONFIG_HAVE_CLK=y
99CONFIG_HAVE_DMA_API_DEBUG=y
100# CONFIG_SLOW_WORK is not set
96CONFIG_HAVE_GENERIC_DMA_COHERENT=y 101CONFIG_HAVE_GENERIC_DMA_COHERENT=y
97CONFIG_SLABINFO=y 102CONFIG_SLABINFO=y
98CONFIG_RT_MUTEXES=y 103CONFIG_RT_MUTEXES=y
@@ -105,7 +110,6 @@ CONFIG_MODULE_UNLOAD=y
105# CONFIG_MODULE_SRCVERSION_ALL is not set 110# CONFIG_MODULE_SRCVERSION_ALL is not set
106CONFIG_BLOCK=y 111CONFIG_BLOCK=y
107# CONFIG_LBD is not set 112# CONFIG_LBD is not set
108# CONFIG_BLK_DEV_IO_TRACE is not set
109# CONFIG_BLK_DEV_BSG is not set 113# CONFIG_BLK_DEV_BSG is not set
110# CONFIG_BLK_DEV_INTEGRITY is not set 114# CONFIG_BLK_DEV_INTEGRITY is not set
111 115
@@ -127,39 +131,6 @@ CONFIG_DEFAULT_IOSCHED="cfq"
127# System type 131# System type
128# 132#
129CONFIG_CPU_SH5=y 133CONFIG_CPU_SH5=y
130# CONFIG_CPU_SUBTYPE_SH7619 is not set
131# CONFIG_CPU_SUBTYPE_SH7201 is not set
132# CONFIG_CPU_SUBTYPE_SH7203 is not set
133# CONFIG_CPU_SUBTYPE_SH7206 is not set
134# CONFIG_CPU_SUBTYPE_SH7263 is not set
135# CONFIG_CPU_SUBTYPE_MXG is not set
136# CONFIG_CPU_SUBTYPE_SH7705 is not set
137# CONFIG_CPU_SUBTYPE_SH7706 is not set
138# CONFIG_CPU_SUBTYPE_SH7707 is not set
139# CONFIG_CPU_SUBTYPE_SH7708 is not set
140# CONFIG_CPU_SUBTYPE_SH7709 is not set
141# CONFIG_CPU_SUBTYPE_SH7710 is not set
142# CONFIG_CPU_SUBTYPE_SH7712 is not set
143# CONFIG_CPU_SUBTYPE_SH7720 is not set
144# CONFIG_CPU_SUBTYPE_SH7721 is not set
145# CONFIG_CPU_SUBTYPE_SH7750 is not set
146# CONFIG_CPU_SUBTYPE_SH7091 is not set
147# CONFIG_CPU_SUBTYPE_SH7750R is not set
148# CONFIG_CPU_SUBTYPE_SH7750S is not set
149# CONFIG_CPU_SUBTYPE_SH7751 is not set
150# CONFIG_CPU_SUBTYPE_SH7751R is not set
151# CONFIG_CPU_SUBTYPE_SH7760 is not set
152# CONFIG_CPU_SUBTYPE_SH4_202 is not set
153# CONFIG_CPU_SUBTYPE_SH7723 is not set
154# CONFIG_CPU_SUBTYPE_SH7763 is not set
155# CONFIG_CPU_SUBTYPE_SH7770 is not set
156# CONFIG_CPU_SUBTYPE_SH7780 is not set
157# CONFIG_CPU_SUBTYPE_SH7785 is not set
158# CONFIG_CPU_SUBTYPE_SH7786 is not set
159# CONFIG_CPU_SUBTYPE_SHX3 is not set
160# CONFIG_CPU_SUBTYPE_SH7343 is not set
161# CONFIG_CPU_SUBTYPE_SH7722 is not set
162# CONFIG_CPU_SUBTYPE_SH7366 is not set
163CONFIG_CPU_SUBTYPE_SH5_101=y 134CONFIG_CPU_SUBTYPE_SH5_101=y
164# CONFIG_CPU_SUBTYPE_SH5_103 is not set 135# CONFIG_CPU_SUBTYPE_SH5_103 is not set
165 136
@@ -279,8 +250,6 @@ CONFIG_BOOT_LINK_OFFSET=0x00800000
279# 250#
280CONFIG_PCI=y 251CONFIG_PCI=y
281CONFIG_SH_PCIDMA_NONCOHERENT=y 252CONFIG_SH_PCIDMA_NONCOHERENT=y
282CONFIG_PCI_AUTO=y
283CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
284# CONFIG_PCIEPORTBUS is not set 253# CONFIG_PCIEPORTBUS is not set
285# CONFIG_ARCH_SUPPORTS_MSI is not set 254# CONFIG_ARCH_SUPPORTS_MSI is not set
286CONFIG_PCI_LEGACY=y 255CONFIG_PCI_LEGACY=y
@@ -492,6 +461,7 @@ CONFIG_SCSI_LOWLEVEL=y
492# CONFIG_SCSI_MPT2SAS is not set 461# CONFIG_SCSI_MPT2SAS is not set
493# CONFIG_SCSI_HPTIOP is not set 462# CONFIG_SCSI_HPTIOP is not set
494# CONFIG_LIBFC is not set 463# CONFIG_LIBFC is not set
464# CONFIG_LIBFCOE is not set
495# CONFIG_FCOE is not set 465# CONFIG_FCOE is not set
496# CONFIG_SCSI_DMX3191D is not set 466# CONFIG_SCSI_DMX3191D is not set
497# CONFIG_SCSI_FUTURE_DOMAIN is not set 467# CONFIG_SCSI_FUTURE_DOMAIN is not set
@@ -568,6 +538,7 @@ CONFIG_NETDEV_1000=y
568# CONFIG_E1000E is not set 538# CONFIG_E1000E is not set
569# CONFIG_IP1000 is not set 539# CONFIG_IP1000 is not set
570# CONFIG_IGB is not set 540# CONFIG_IGB is not set
541# CONFIG_IGBVF is not set
571# CONFIG_NS83820 is not set 542# CONFIG_NS83820 is not set
572# CONFIG_HAMACHI is not set 543# CONFIG_HAMACHI is not set
573# CONFIG_YELLOWFIN is not set 544# CONFIG_YELLOWFIN is not set
@@ -591,6 +562,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
591# CONFIG_IXGBE is not set 562# CONFIG_IXGBE is not set
592# CONFIG_IXGB is not set 563# CONFIG_IXGB is not set
593# CONFIG_S2IO is not set 564# CONFIG_S2IO is not set
565# CONFIG_VXGE is not set
594# CONFIG_MYRI10GE is not set 566# CONFIG_MYRI10GE is not set
595# CONFIG_NETXEN_NIC is not set 567# CONFIG_NETXEN_NIC is not set
596# CONFIG_NIU is not set 568# CONFIG_NIU is not set
@@ -779,6 +751,7 @@ CONFIG_HWMON=y
779# CONFIG_SENSORS_F71805F is not set 751# CONFIG_SENSORS_F71805F is not set
780# CONFIG_SENSORS_F71882FG is not set 752# CONFIG_SENSORS_F71882FG is not set
781# CONFIG_SENSORS_F75375S is not set 753# CONFIG_SENSORS_F75375S is not set
754# CONFIG_SENSORS_G760A is not set
782# CONFIG_SENSORS_GL518SM is not set 755# CONFIG_SENSORS_GL518SM is not set
783# CONFIG_SENSORS_GL520SM is not set 756# CONFIG_SENSORS_GL520SM is not set
784# CONFIG_SENSORS_IT87 is not set 757# CONFIG_SENSORS_IT87 is not set
@@ -1042,7 +1015,6 @@ CONFIG_HID=y
1042# 1015#
1043# Special HID drivers 1016# Special HID drivers
1044# 1017#
1045CONFIG_HID_COMPAT=y
1046CONFIG_USB_SUPPORT=y 1018CONFIG_USB_SUPPORT=y
1047CONFIG_USB_ARCH_HAS_HCD=y 1019CONFIG_USB_ARCH_HAS_HCD=y
1048CONFIG_USB_ARCH_HAS_OHCI=y 1020CONFIG_USB_ARCH_HAS_OHCI=y
@@ -1082,6 +1054,7 @@ CONFIG_EXT2_FS=y
1082# CONFIG_EXT2_FS_XATTR is not set 1054# CONFIG_EXT2_FS_XATTR is not set
1083# CONFIG_EXT2_FS_XIP is not set 1055# CONFIG_EXT2_FS_XIP is not set
1084CONFIG_EXT3_FS=y 1056CONFIG_EXT3_FS=y
1057# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
1085CONFIG_EXT3_FS_XATTR=y 1058CONFIG_EXT3_FS_XATTR=y
1086# CONFIG_EXT3_FS_POSIX_ACL is not set 1059# CONFIG_EXT3_FS_POSIX_ACL is not set
1087# CONFIG_EXT3_FS_SECURITY is not set 1060# CONFIG_EXT3_FS_SECURITY is not set
@@ -1105,6 +1078,11 @@ CONFIG_INOTIFY_USER=y
1105# CONFIG_FUSE_FS is not set 1078# CONFIG_FUSE_FS is not set
1106 1079
1107# 1080#
1081# Caches
1082#
1083# CONFIG_FSCACHE is not set
1084
1085#
1108# CD-ROM/DVD Filesystems 1086# CD-ROM/DVD Filesystems
1109# 1087#
1110# CONFIG_ISO9660_FS is not set 1088# CONFIG_ISO9660_FS is not set
@@ -1146,8 +1124,13 @@ CONFIG_MINIX_FS=y
1146# CONFIG_HPFS_FS is not set 1124# CONFIG_HPFS_FS is not set
1147# CONFIG_QNX4FS_FS is not set 1125# CONFIG_QNX4FS_FS is not set
1148CONFIG_ROMFS_FS=y 1126CONFIG_ROMFS_FS=y
1127CONFIG_ROMFS_BACKED_BY_BLOCK=y
1128# CONFIG_ROMFS_BACKED_BY_MTD is not set
1129# CONFIG_ROMFS_BACKED_BY_BOTH is not set
1130CONFIG_ROMFS_ON_BLOCK=y
1149# CONFIG_SYSV_FS is not set 1131# CONFIG_SYSV_FS is not set
1150# CONFIG_UFS_FS is not set 1132# CONFIG_UFS_FS is not set
1133# CONFIG_NILFS2_FS is not set
1151CONFIG_NETWORK_FILESYSTEMS=y 1134CONFIG_NETWORK_FILESYSTEMS=y
1152CONFIG_NFS_FS=y 1135CONFIG_NFS_FS=y
1153CONFIG_NFS_V3=y 1136CONFIG_NFS_V3=y
@@ -1208,6 +1191,9 @@ CONFIG_DEBUG_KERNEL=y
1208CONFIG_DETECT_SOFTLOCKUP=y 1191CONFIG_DETECT_SOFTLOCKUP=y
1209# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set 1192# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
1210CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0 1193CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
1194CONFIG_DETECT_HUNG_TASK=y
1195# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
1196CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
1211CONFIG_SCHED_DEBUG=y 1197CONFIG_SCHED_DEBUG=y
1212CONFIG_SCHEDSTATS=y 1198CONFIG_SCHEDSTATS=y
1213# CONFIG_TIMER_STATS is not set 1199# CONFIG_TIMER_STATS is not set
@@ -1241,15 +1227,21 @@ CONFIG_FRAME_POINTER=y
1241# CONFIG_LATENCYTOP is not set 1227# CONFIG_LATENCYTOP is not set
1242# CONFIG_SYSCTL_SYSCALL_CHECK is not set 1228# CONFIG_SYSCTL_SYSCALL_CHECK is not set
1243# CONFIG_PAGE_POISONING is not set 1229# CONFIG_PAGE_POISONING is not set
1230CONFIG_TRACING_SUPPORT=y
1244 1231
1245# 1232#
1246# Tracers 1233# Tracers
1247# 1234#
1248# CONFIG_SCHED_TRACER is not set 1235# CONFIG_SCHED_TRACER is not set
1249# CONFIG_CONTEXT_SWITCH_TRACER is not set 1236# CONFIG_CONTEXT_SWITCH_TRACER is not set
1237# CONFIG_EVENT_TRACER is not set
1250# CONFIG_BOOT_TRACER is not set 1238# CONFIG_BOOT_TRACER is not set
1251# CONFIG_TRACE_BRANCH_PROFILING is not set 1239# CONFIG_TRACE_BRANCH_PROFILING is not set
1240# CONFIG_KMEMTRACE is not set
1241# CONFIG_WORKQUEUE_TRACER is not set
1242# CONFIG_BLK_DEV_IO_TRACE is not set
1252# CONFIG_DYNAMIC_DEBUG is not set 1243# CONFIG_DYNAMIC_DEBUG is not set
1244# CONFIG_DMA_API_DEBUG is not set
1253# CONFIG_SAMPLES is not set 1245# CONFIG_SAMPLES is not set
1254# CONFIG_EARLY_SCIF_CONSOLE is not set 1246# CONFIG_EARLY_SCIF_CONSOLE is not set
1255# CONFIG_DEBUG_BOOTMEM is not set 1247# CONFIG_DEBUG_BOOTMEM is not set
@@ -1354,6 +1346,7 @@ CONFIG_CRYPTO=y
1354# CONFIG_CRYPTO_ANSI_CPRNG is not set 1346# CONFIG_CRYPTO_ANSI_CPRNG is not set
1355CONFIG_CRYPTO_HW=y 1347CONFIG_CRYPTO_HW=y
1356# CONFIG_CRYPTO_DEV_HIFN_795X is not set 1348# CONFIG_CRYPTO_DEV_HIFN_795X is not set
1349# CONFIG_BINARY_PRINTF is not set
1357 1350
1358# 1351#
1359# Library routines 1352# Library routines
diff --git a/arch/sh/configs/dreamcast_defconfig b/arch/sh/configs/dreamcast_defconfig
index 5c1123640142..1f3cc98330bf 100644
--- a/arch/sh/configs/dreamcast_defconfig
+++ b/arch/sh/configs/dreamcast_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 17:51:48 2009 4# Mon Apr 27 12:44:27 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -71,6 +72,7 @@ CONFIG_UID16=y
71# CONFIG_SYSCTL_SYSCALL is not set 72# CONFIG_SYSCTL_SYSCALL is not set
72CONFIG_KALLSYMS=y 73CONFIG_KALLSYMS=y
73# CONFIG_KALLSYMS_EXTRA_PASS is not set 74# CONFIG_KALLSYMS_EXTRA_PASS is not set
75# CONFIG_STRIP_ASM_SYMS is not set
74CONFIG_HOTPLUG=y 76CONFIG_HOTPLUG=y
75CONFIG_PRINTK=y 77CONFIG_PRINTK=y
76CONFIG_BUG=y 78CONFIG_BUG=y
@@ -90,6 +92,7 @@ CONFIG_SLAB=y
90# CONFIG_SLUB is not set 92# CONFIG_SLUB is not set
91# CONFIG_SLOB is not set 93# CONFIG_SLOB is not set
92CONFIG_PROFILING=y 94CONFIG_PROFILING=y
95# CONFIG_MARKERS is not set
93# CONFIG_OPROFILE is not set 96# CONFIG_OPROFILE is not set
94CONFIG_HAVE_OPROFILE=y 97CONFIG_HAVE_OPROFILE=y
95# CONFIG_KPROBES is not set 98# CONFIG_KPROBES is not set
@@ -98,6 +101,8 @@ CONFIG_HAVE_KPROBES=y
98CONFIG_HAVE_KRETPROBES=y 101CONFIG_HAVE_KRETPROBES=y
99CONFIG_HAVE_ARCH_TRACEHOOK=y 102CONFIG_HAVE_ARCH_TRACEHOOK=y
100CONFIG_HAVE_CLK=y 103CONFIG_HAVE_CLK=y
104CONFIG_HAVE_DMA_API_DEBUG=y
105# CONFIG_SLOW_WORK is not set
101CONFIG_HAVE_GENERIC_DMA_COHERENT=y 106CONFIG_HAVE_GENERIC_DMA_COHERENT=y
102CONFIG_SLABINFO=y 107CONFIG_SLABINFO=y
103CONFIG_RT_MUTEXES=y 108CONFIG_RT_MUTEXES=y
@@ -110,7 +115,6 @@ CONFIG_MODULE_UNLOAD=y
110# CONFIG_MODULE_SRCVERSION_ALL is not set 115# CONFIG_MODULE_SRCVERSION_ALL is not set
111CONFIG_BLOCK=y 116CONFIG_BLOCK=y
112# CONFIG_LBD is not set 117# CONFIG_LBD is not set
113# CONFIG_BLK_DEV_IO_TRACE is not set
114# CONFIG_BLK_DEV_BSG is not set 118# CONFIG_BLK_DEV_BSG is not set
115# CONFIG_BLK_DEV_INTEGRITY is not set 119# CONFIG_BLK_DEV_INTEGRITY is not set
116 120
@@ -156,6 +160,7 @@ CONFIG_CPU_SUBTYPE_SH7091=y
156# CONFIG_CPU_SUBTYPE_SH7760 is not set 160# CONFIG_CPU_SUBTYPE_SH7760 is not set
157# CONFIG_CPU_SUBTYPE_SH4_202 is not set 161# CONFIG_CPU_SUBTYPE_SH4_202 is not set
158# CONFIG_CPU_SUBTYPE_SH7723 is not set 162# CONFIG_CPU_SUBTYPE_SH7723 is not set
163# CONFIG_CPU_SUBTYPE_SH7724 is not set
159# CONFIG_CPU_SUBTYPE_SH7763 is not set 164# CONFIG_CPU_SUBTYPE_SH7763 is not set
160# CONFIG_CPU_SUBTYPE_SH7770 is not set 165# CONFIG_CPU_SUBTYPE_SH7770 is not set
161# CONFIG_CPU_SUBTYPE_SH7780 is not set 166# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -165,8 +170,6 @@ CONFIG_CPU_SUBTYPE_SH7091=y
165# CONFIG_CPU_SUBTYPE_SH7343 is not set 170# CONFIG_CPU_SUBTYPE_SH7343 is not set
166# CONFIG_CPU_SUBTYPE_SH7722 is not set 171# CONFIG_CPU_SUBTYPE_SH7722 is not set
167# CONFIG_CPU_SUBTYPE_SH7366 is not set 172# CONFIG_CPU_SUBTYPE_SH7366 is not set
168# CONFIG_CPU_SUBTYPE_SH5_101 is not set
169# CONFIG_CPU_SUBTYPE_SH5_103 is not set
170 173
171# 174#
172# Memory management options 175# Memory management options
@@ -271,7 +274,7 @@ CONFIG_CPU_FREQ_GOV_USERSPACE=y
271CONFIG_SH_DMA_API=y 274CONFIG_SH_DMA_API=y
272CONFIG_SH_DMA=y 275CONFIG_SH_DMA=y
273CONFIG_SH_DMA_IRQ_MULTI=y 276CONFIG_SH_DMA_IRQ_MULTI=y
274CONFIG_NR_ONCHIP_DMA_CHANNELS=6 277CONFIG_NR_ONCHIP_DMA_CHANNELS=4
275CONFIG_NR_DMA_CHANNELS_BOOL=y 278CONFIG_NR_DMA_CHANNELS_BOOL=y
276CONFIG_NR_DMA_CHANNELS=9 279CONFIG_NR_DMA_CHANNELS=9
277# CONFIG_PVR2_DMA is not set 280# CONFIG_PVR2_DMA is not set
@@ -320,7 +323,6 @@ CONFIG_CMDLINE="console=ttySC1,115200 panic=3"
320CONFIG_MAPLE=y 323CONFIG_MAPLE=y
321CONFIG_PCI=y 324CONFIG_PCI=y
322CONFIG_SH_PCIDMA_NONCOHERENT=y 325CONFIG_SH_PCIDMA_NONCOHERENT=y
323CONFIG_PCI_AUTO=y
324# CONFIG_PCIEPORTBUS is not set 326# CONFIG_PCIEPORTBUS is not set
325# CONFIG_ARCH_SUPPORTS_MSI is not set 327# CONFIG_ARCH_SUPPORTS_MSI is not set
326CONFIG_PCI_LEGACY=y 328CONFIG_PCI_LEGACY=y
@@ -602,6 +604,7 @@ CONFIG_INPUT_MOUSE=y
602# CONFIG_MOUSE_APPLETOUCH is not set 604# CONFIG_MOUSE_APPLETOUCH is not set
603# CONFIG_MOUSE_BCM5974 is not set 605# CONFIG_MOUSE_BCM5974 is not set
604# CONFIG_MOUSE_VSXXXAA is not set 606# CONFIG_MOUSE_VSXXXAA is not set
607# CONFIG_MOUSE_MAPLE is not set
605# CONFIG_INPUT_JOYSTICK is not set 608# CONFIG_INPUT_JOYSTICK is not set
606# CONFIG_INPUT_TABLET is not set 609# CONFIG_INPUT_TABLET is not set
607# CONFIG_INPUT_TOUCHSCREEN is not set 610# CONFIG_INPUT_TOUCHSCREEN is not set
@@ -812,7 +815,6 @@ CONFIG_HID=y
812# 815#
813# Special HID drivers 816# Special HID drivers
814# 817#
815CONFIG_HID_COMPAT=y
816CONFIG_USB_SUPPORT=y 818CONFIG_USB_SUPPORT=y
817CONFIG_USB_ARCH_HAS_HCD=y 819CONFIG_USB_ARCH_HAS_HCD=y
818CONFIG_USB_ARCH_HAS_OHCI=y 820CONFIG_USB_ARCH_HAS_OHCI=y
@@ -867,6 +869,11 @@ CONFIG_INOTIFY_USER=y
867# CONFIG_FUSE_FS is not set 869# CONFIG_FUSE_FS is not set
868 870
869# 871#
872# Caches
873#
874# CONFIG_FSCACHE is not set
875
876#
870# CD-ROM/DVD Filesystems 877# CD-ROM/DVD Filesystems
871# 878#
872# CONFIG_ISO9660_FS is not set 879# CONFIG_ISO9660_FS is not set
@@ -910,6 +917,7 @@ CONFIG_MISC_FILESYSTEMS=y
910# CONFIG_ROMFS_FS is not set 917# CONFIG_ROMFS_FS is not set
911# CONFIG_SYSV_FS is not set 918# CONFIG_SYSV_FS is not set
912# CONFIG_UFS_FS is not set 919# CONFIG_UFS_FS is not set
920# CONFIG_NILFS2_FS is not set
913CONFIG_NETWORK_FILESYSTEMS=y 921CONFIG_NETWORK_FILESYSTEMS=y
914# CONFIG_NFS_FS is not set 922# CONFIG_NFS_FS is not set
915# CONFIG_NFSD is not set 923# CONFIG_NFSD is not set
@@ -947,10 +955,24 @@ CONFIG_FRAME_WARN=1024
947CONFIG_HAVE_FUNCTION_TRACER=y 955CONFIG_HAVE_FUNCTION_TRACER=y
948CONFIG_HAVE_DYNAMIC_FTRACE=y 956CONFIG_HAVE_DYNAMIC_FTRACE=y
949CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 957CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
958CONFIG_TRACING_SUPPORT=y
950 959
951# 960#
952# Tracers 961# Tracers
953# 962#
963# CONFIG_FUNCTION_TRACER is not set
964# CONFIG_IRQSOFF_TRACER is not set
965# CONFIG_PREEMPT_TRACER is not set
966# CONFIG_SCHED_TRACER is not set
967# CONFIG_CONTEXT_SWITCH_TRACER is not set
968# CONFIG_EVENT_TRACER is not set
969# CONFIG_BOOT_TRACER is not set
970# CONFIG_TRACE_BRANCH_PROFILING is not set
971# CONFIG_STACK_TRACER is not set
972# CONFIG_KMEMTRACE is not set
973# CONFIG_WORKQUEUE_TRACER is not set
974# CONFIG_BLK_DEV_IO_TRACE is not set
975# CONFIG_DMA_API_DEBUG is not set
954# CONFIG_SAMPLES is not set 976# CONFIG_SAMPLES is not set
955CONFIG_HAVE_ARCH_KGDB=y 977CONFIG_HAVE_ARCH_KGDB=y
956# CONFIG_SH_STANDARD_BIOS is not set 978# CONFIG_SH_STANDARD_BIOS is not set
@@ -1051,6 +1073,7 @@ CONFIG_CRYPTO=y
1051# CONFIG_CRYPTO_ANSI_CPRNG is not set 1073# CONFIG_CRYPTO_ANSI_CPRNG is not set
1052CONFIG_CRYPTO_HW=y 1074CONFIG_CRYPTO_HW=y
1053# CONFIG_CRYPTO_DEV_HIFN_795X is not set 1075# CONFIG_CRYPTO_DEV_HIFN_795X is not set
1076# CONFIG_BINARY_PRINTF is not set
1054 1077
1055# 1078#
1056# Library routines 1079# Library routines
diff --git a/arch/sh/configs/edosk7705_defconfig b/arch/sh/configs/edosk7705_defconfig
index f4c34b039312..d7092457ddc7 100644
--- a/arch/sh/configs/edosk7705_defconfig
+++ b/arch/sh/configs/edosk7705_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 17:54:02 2009 4# Mon Apr 27 12:45:04 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_FIND_NEXT_BIT=y 11CONFIG_GENERIC_FIND_NEXT_BIT=y
@@ -56,6 +57,7 @@ CONFIG_EMBEDDED=y
56# CONFIG_UID16 is not set 57# CONFIG_UID16 is not set
57# CONFIG_SYSCTL_SYSCALL is not set 58# CONFIG_SYSCTL_SYSCALL is not set
58# CONFIG_KALLSYMS is not set 59# CONFIG_KALLSYMS is not set
60# CONFIG_STRIP_ASM_SYMS is not set
59# CONFIG_HOTPLUG is not set 61# CONFIG_HOTPLUG is not set
60# CONFIG_PRINTK is not set 62# CONFIG_PRINTK is not set
61# CONFIG_BUG is not set 63# CONFIG_BUG is not set
@@ -74,12 +76,15 @@ CONFIG_SHMEM=y
74CONFIG_SLUB=y 76CONFIG_SLUB=y
75# CONFIG_SLOB is not set 77# CONFIG_SLOB is not set
76# CONFIG_PROFILING is not set 78# CONFIG_PROFILING is not set
79# CONFIG_MARKERS is not set
77CONFIG_HAVE_OPROFILE=y 80CONFIG_HAVE_OPROFILE=y
78CONFIG_HAVE_IOREMAP_PROT=y 81CONFIG_HAVE_IOREMAP_PROT=y
79CONFIG_HAVE_KPROBES=y 82CONFIG_HAVE_KPROBES=y
80CONFIG_HAVE_KRETPROBES=y 83CONFIG_HAVE_KRETPROBES=y
81CONFIG_HAVE_ARCH_TRACEHOOK=y 84CONFIG_HAVE_ARCH_TRACEHOOK=y
82CONFIG_HAVE_CLK=y 85CONFIG_HAVE_CLK=y
86CONFIG_HAVE_DMA_API_DEBUG=y
87# CONFIG_SLOW_WORK is not set
83CONFIG_HAVE_GENERIC_DMA_COHERENT=y 88CONFIG_HAVE_GENERIC_DMA_COHERENT=y
84CONFIG_BASE_SMALL=1 89CONFIG_BASE_SMALL=1
85# CONFIG_MODULES is not set 90# CONFIG_MODULES is not set
@@ -114,6 +119,7 @@ CONFIG_CPU_SUBTYPE_SH7705=y
114# CONFIG_CPU_SUBTYPE_SH7760 is not set 119# CONFIG_CPU_SUBTYPE_SH7760 is not set
115# CONFIG_CPU_SUBTYPE_SH4_202 is not set 120# CONFIG_CPU_SUBTYPE_SH4_202 is not set
116# CONFIG_CPU_SUBTYPE_SH7723 is not set 121# CONFIG_CPU_SUBTYPE_SH7723 is not set
122# CONFIG_CPU_SUBTYPE_SH7724 is not set
117# CONFIG_CPU_SUBTYPE_SH7763 is not set 123# CONFIG_CPU_SUBTYPE_SH7763 is not set
118# CONFIG_CPU_SUBTYPE_SH7770 is not set 124# CONFIG_CPU_SUBTYPE_SH7770 is not set
119# CONFIG_CPU_SUBTYPE_SH7780 is not set 125# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -123,8 +129,6 @@ CONFIG_CPU_SUBTYPE_SH7705=y
123# CONFIG_CPU_SUBTYPE_SH7343 is not set 129# CONFIG_CPU_SUBTYPE_SH7343 is not set
124# CONFIG_CPU_SUBTYPE_SH7722 is not set 130# CONFIG_CPU_SUBTYPE_SH7722 is not set
125# CONFIG_CPU_SUBTYPE_SH7366 is not set 131# CONFIG_CPU_SUBTYPE_SH7366 is not set
126# CONFIG_CPU_SUBTYPE_SH5_101 is not set
127# CONFIG_CPU_SUBTYPE_SH5_103 is not set
128 132
129# 133#
130# Memory management options 134# Memory management options
@@ -382,6 +386,10 @@ CONFIG_SSB_POSSIBLE=y
382# CONFIG_FUSE_FS is not set 386# CONFIG_FUSE_FS is not set
383 387
384# 388#
389# Caches
390#
391
392#
385# Pseudo filesystems 393# Pseudo filesystems
386# 394#
387# CONFIG_PROC_FS is not set 395# CONFIG_PROC_FS is not set
@@ -409,10 +417,22 @@ CONFIG_FRAME_WARN=1024
409CONFIG_HAVE_FUNCTION_TRACER=y 417CONFIG_HAVE_FUNCTION_TRACER=y
410CONFIG_HAVE_DYNAMIC_FTRACE=y 418CONFIG_HAVE_DYNAMIC_FTRACE=y
411CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 419CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
420CONFIG_TRACING_SUPPORT=y
412 421
413# 422#
414# Tracers 423# Tracers
415# 424#
425# CONFIG_FUNCTION_TRACER is not set
426# CONFIG_IRQSOFF_TRACER is not set
427# CONFIG_SCHED_TRACER is not set
428# CONFIG_CONTEXT_SWITCH_TRACER is not set
429# CONFIG_EVENT_TRACER is not set
430# CONFIG_BOOT_TRACER is not set
431# CONFIG_TRACE_BRANCH_PROFILING is not set
432# CONFIG_STACK_TRACER is not set
433# CONFIG_KMEMTRACE is not set
434# CONFIG_WORKQUEUE_TRACER is not set
435# CONFIG_DMA_API_DEBUG is not set
416# CONFIG_SAMPLES is not set 436# CONFIG_SAMPLES is not set
417CONFIG_HAVE_ARCH_KGDB=y 437CONFIG_HAVE_ARCH_KGDB=y
418# CONFIG_SH_STANDARD_BIOS is not set 438# CONFIG_SH_STANDARD_BIOS is not set
@@ -426,6 +446,7 @@ CONFIG_HAVE_ARCH_KGDB=y
426# CONFIG_SECURITYFS is not set 446# CONFIG_SECURITYFS is not set
427# CONFIG_SECURITY_FILE_CAPABILITIES is not set 447# CONFIG_SECURITY_FILE_CAPABILITIES is not set
428# CONFIG_CRYPTO is not set 448# CONFIG_CRYPTO is not set
449# CONFIG_BINARY_PRINTF is not set
429 450
430# 451#
431# Library routines 452# Library routines
diff --git a/arch/sh/configs/edosk7760_defconfig b/arch/sh/configs/edosk7760_defconfig
index 7825c2699f18..a822b1d8c116 100644
--- a/arch/sh/configs/edosk7760_defconfig
+++ b/arch/sh/configs/edosk7760_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 17:54:57 2009 4# Mon Apr 27 12:45:25 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -40,6 +41,7 @@ CONFIG_SWAP=y
40CONFIG_SYSVIPC=y 41CONFIG_SYSVIPC=y
41CONFIG_SYSVIPC_SYSCTL=y 42CONFIG_SYSVIPC_SYSCTL=y
42CONFIG_POSIX_MQUEUE=y 43CONFIG_POSIX_MQUEUE=y
44CONFIG_POSIX_MQUEUE_SYSCTL=y
43CONFIG_BSD_PROCESS_ACCT=y 45CONFIG_BSD_PROCESS_ACCT=y
44# CONFIG_BSD_PROCESS_ACCT_V3 is not set 46# CONFIG_BSD_PROCESS_ACCT_V3 is not set
45# CONFIG_TASKSTATS is not set 47# CONFIG_TASKSTATS is not set
@@ -67,7 +69,6 @@ CONFIG_INITRAMFS_SOURCE=""
67CONFIG_RD_GZIP=y 69CONFIG_RD_GZIP=y
68# CONFIG_RD_BZIP2 is not set 70# CONFIG_RD_BZIP2 is not set
69# CONFIG_RD_LZMA is not set 71# CONFIG_RD_LZMA is not set
70CONFIG_INITRAMFS_COMPRESSION_NONE=y
71CONFIG_CC_OPTIMIZE_FOR_SIZE=y 72CONFIG_CC_OPTIMIZE_FOR_SIZE=y
72CONFIG_SYSCTL=y 73CONFIG_SYSCTL=y
73CONFIG_ANON_INODES=y 74CONFIG_ANON_INODES=y
@@ -77,6 +78,7 @@ CONFIG_SYSCTL_SYSCALL=y
77CONFIG_KALLSYMS=y 78CONFIG_KALLSYMS=y
78CONFIG_KALLSYMS_ALL=y 79CONFIG_KALLSYMS_ALL=y
79# CONFIG_KALLSYMS_EXTRA_PASS is not set 80# CONFIG_KALLSYMS_EXTRA_PASS is not set
81# CONFIG_STRIP_ASM_SYMS is not set
80CONFIG_HOTPLUG=y 82CONFIG_HOTPLUG=y
81CONFIG_PRINTK=y 83CONFIG_PRINTK=y
82CONFIG_BUG=y 84CONFIG_BUG=y
@@ -96,6 +98,7 @@ CONFIG_COMPAT_BRK=y
96CONFIG_SLUB=y 98CONFIG_SLUB=y
97# CONFIG_SLOB is not set 99# CONFIG_SLOB is not set
98# CONFIG_PROFILING is not set 100# CONFIG_PROFILING is not set
101# CONFIG_MARKERS is not set
99CONFIG_HAVE_OPROFILE=y 102CONFIG_HAVE_OPROFILE=y
100# CONFIG_KPROBES is not set 103# CONFIG_KPROBES is not set
101CONFIG_HAVE_IOREMAP_PROT=y 104CONFIG_HAVE_IOREMAP_PROT=y
@@ -103,6 +106,8 @@ CONFIG_HAVE_KPROBES=y
103CONFIG_HAVE_KRETPROBES=y 106CONFIG_HAVE_KRETPROBES=y
104CONFIG_HAVE_ARCH_TRACEHOOK=y 107CONFIG_HAVE_ARCH_TRACEHOOK=y
105CONFIG_HAVE_CLK=y 108CONFIG_HAVE_CLK=y
109CONFIG_HAVE_DMA_API_DEBUG=y
110# CONFIG_SLOW_WORK is not set
106CONFIG_HAVE_GENERIC_DMA_COHERENT=y 111CONFIG_HAVE_GENERIC_DMA_COHERENT=y
107CONFIG_SLABINFO=y 112CONFIG_SLABINFO=y
108CONFIG_RT_MUTEXES=y 113CONFIG_RT_MUTEXES=y
@@ -115,7 +120,6 @@ CONFIG_MODULE_FORCE_UNLOAD=y
115# CONFIG_MODULE_SRCVERSION_ALL is not set 120# CONFIG_MODULE_SRCVERSION_ALL is not set
116CONFIG_BLOCK=y 121CONFIG_BLOCK=y
117# CONFIG_LBD is not set 122# CONFIG_LBD is not set
118# CONFIG_BLK_DEV_IO_TRACE is not set
119# CONFIG_BLK_DEV_BSG is not set 123# CONFIG_BLK_DEV_BSG is not set
120# CONFIG_BLK_DEV_INTEGRITY is not set 124# CONFIG_BLK_DEV_INTEGRITY is not set
121 125
@@ -161,6 +165,7 @@ CONFIG_CPU_SH4=y
161CONFIG_CPU_SUBTYPE_SH7760=y 165CONFIG_CPU_SUBTYPE_SH7760=y
162# CONFIG_CPU_SUBTYPE_SH4_202 is not set 166# CONFIG_CPU_SUBTYPE_SH4_202 is not set
163# CONFIG_CPU_SUBTYPE_SH7723 is not set 167# CONFIG_CPU_SUBTYPE_SH7723 is not set
168# CONFIG_CPU_SUBTYPE_SH7724 is not set
164# CONFIG_CPU_SUBTYPE_SH7763 is not set 169# CONFIG_CPU_SUBTYPE_SH7763 is not set
165# CONFIG_CPU_SUBTYPE_SH7770 is not set 170# CONFIG_CPU_SUBTYPE_SH7770 is not set
166# CONFIG_CPU_SUBTYPE_SH7780 is not set 171# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -170,8 +175,6 @@ CONFIG_CPU_SUBTYPE_SH7760=y
170# CONFIG_CPU_SUBTYPE_SH7343 is not set 175# CONFIG_CPU_SUBTYPE_SH7343 is not set
171# CONFIG_CPU_SUBTYPE_SH7722 is not set 176# CONFIG_CPU_SUBTYPE_SH7722 is not set
172# CONFIG_CPU_SUBTYPE_SH7366 is not set 177# CONFIG_CPU_SUBTYPE_SH7366 is not set
173# CONFIG_CPU_SUBTYPE_SH5_101 is not set
174# CONFIG_CPU_SUBTYPE_SH5_103 is not set
175 178
176# 179#
177# Memory management options 180# Memory management options
@@ -815,6 +818,7 @@ CONFIG_EXT2_FS_XATTR=y
815# CONFIG_EXT2_FS_SECURITY is not set 818# CONFIG_EXT2_FS_SECURITY is not set
816CONFIG_EXT2_FS_XIP=y 819CONFIG_EXT2_FS_XIP=y
817CONFIG_EXT3_FS=y 820CONFIG_EXT3_FS=y
821# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
818CONFIG_EXT3_FS_XATTR=y 822CONFIG_EXT3_FS_XATTR=y
819# CONFIG_EXT3_FS_POSIX_ACL is not set 823# CONFIG_EXT3_FS_POSIX_ACL is not set
820# CONFIG_EXT3_FS_SECURITY is not set 824# CONFIG_EXT3_FS_SECURITY is not set
@@ -839,6 +843,11 @@ CONFIG_INOTIFY_USER=y
839CONFIG_GENERIC_ACL=y 843CONFIG_GENERIC_ACL=y
840 844
841# 845#
846# Caches
847#
848# CONFIG_FSCACHE is not set
849
850#
842# CD-ROM/DVD Filesystems 851# CD-ROM/DVD Filesystems
843# 852#
844# CONFIG_ISO9660_FS is not set 853# CONFIG_ISO9660_FS is not set
@@ -883,6 +892,7 @@ CONFIG_MISC_FILESYSTEMS=y
883# CONFIG_ROMFS_FS is not set 892# CONFIG_ROMFS_FS is not set
884# CONFIG_SYSV_FS is not set 893# CONFIG_SYSV_FS is not set
885# CONFIG_UFS_FS is not set 894# CONFIG_UFS_FS is not set
895# CONFIG_NILFS2_FS is not set
886CONFIG_NETWORK_FILESYSTEMS=y 896CONFIG_NETWORK_FILESYSTEMS=y
887CONFIG_NFS_FS=y 897CONFIG_NFS_FS=y
888# CONFIG_NFS_V3 is not set 898# CONFIG_NFS_V3 is not set
@@ -964,6 +974,9 @@ CONFIG_DEBUG_SHIRQ=y
964CONFIG_DETECT_SOFTLOCKUP=y 974CONFIG_DETECT_SOFTLOCKUP=y
965# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set 975# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
966CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0 976CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
977CONFIG_DETECT_HUNG_TASK=y
978# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
979CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
967# CONFIG_SCHED_DEBUG is not set 980# CONFIG_SCHED_DEBUG is not set
968# CONFIG_SCHEDSTATS is not set 981# CONFIG_SCHEDSTATS is not set
969CONFIG_TIMER_STATS=y 982CONFIG_TIMER_STATS=y
@@ -1001,6 +1014,7 @@ CONFIG_SYSCTL_SYSCALL_CHECK=y
1001CONFIG_HAVE_FUNCTION_TRACER=y 1014CONFIG_HAVE_FUNCTION_TRACER=y
1002CONFIG_HAVE_DYNAMIC_FTRACE=y 1015CONFIG_HAVE_DYNAMIC_FTRACE=y
1003CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1016CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1017CONFIG_TRACING_SUPPORT=y
1004 1018
1005# 1019#
1006# Tracers 1020# Tracers
@@ -1010,9 +1024,14 @@ CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1010# CONFIG_PREEMPT_TRACER is not set 1024# CONFIG_PREEMPT_TRACER is not set
1011# CONFIG_SCHED_TRACER is not set 1025# CONFIG_SCHED_TRACER is not set
1012# CONFIG_CONTEXT_SWITCH_TRACER is not set 1026# CONFIG_CONTEXT_SWITCH_TRACER is not set
1027# CONFIG_EVENT_TRACER is not set
1013# CONFIG_BOOT_TRACER is not set 1028# CONFIG_BOOT_TRACER is not set
1014# CONFIG_TRACE_BRANCH_PROFILING is not set 1029# CONFIG_TRACE_BRANCH_PROFILING is not set
1015# CONFIG_STACK_TRACER is not set 1030# CONFIG_STACK_TRACER is not set
1031# CONFIG_KMEMTRACE is not set
1032# CONFIG_WORKQUEUE_TRACER is not set
1033# CONFIG_BLK_DEV_IO_TRACE is not set
1034# CONFIG_DMA_API_DEBUG is not set
1016# CONFIG_SAMPLES is not set 1035# CONFIG_SAMPLES is not set
1017CONFIG_HAVE_ARCH_KGDB=y 1036CONFIG_HAVE_ARCH_KGDB=y
1018# CONFIG_KGDB is not set 1037# CONFIG_KGDB is not set
@@ -1126,6 +1145,7 @@ CONFIG_CRYPTO_DES=y
1126# 1145#
1127# CONFIG_CRYPTO_ANSI_CPRNG is not set 1146# CONFIG_CRYPTO_ANSI_CPRNG is not set
1128CONFIG_CRYPTO_HW=y 1147CONFIG_CRYPTO_HW=y
1148# CONFIG_BINARY_PRINTF is not set
1129 1149
1130# 1150#
1131# Library routines 1151# Library routines
diff --git a/arch/sh/configs/espt_defconfig b/arch/sh/configs/espt_defconfig
index ebb4c37abaa6..c5b50077913d 100644
--- a/arch/sh/configs/espt_defconfig
+++ b/arch/sh/configs/espt_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 17:58:18 2009 4# Mon Apr 27 12:46:26 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -78,6 +79,7 @@ CONFIG_UID16=y
78# CONFIG_SYSCTL_SYSCALL is not set 79# CONFIG_SYSCTL_SYSCALL is not set
79CONFIG_KALLSYMS=y 80CONFIG_KALLSYMS=y
80# CONFIG_KALLSYMS_EXTRA_PASS is not set 81# CONFIG_KALLSYMS_EXTRA_PASS is not set
82# CONFIG_STRIP_ASM_SYMS is not set
81CONFIG_HOTPLUG=y 83CONFIG_HOTPLUG=y
82CONFIG_PRINTK=y 84CONFIG_PRINTK=y
83CONFIG_BUG=y 85CONFIG_BUG=y
@@ -106,6 +108,8 @@ CONFIG_HAVE_KPROBES=y
106CONFIG_HAVE_KRETPROBES=y 108CONFIG_HAVE_KRETPROBES=y
107CONFIG_HAVE_ARCH_TRACEHOOK=y 109CONFIG_HAVE_ARCH_TRACEHOOK=y
108CONFIG_HAVE_CLK=y 110CONFIG_HAVE_CLK=y
111CONFIG_HAVE_DMA_API_DEBUG=y
112# CONFIG_SLOW_WORK is not set
109CONFIG_HAVE_GENERIC_DMA_COHERENT=y 113CONFIG_HAVE_GENERIC_DMA_COHERENT=y
110CONFIG_SLABINFO=y 114CONFIG_SLABINFO=y
111CONFIG_RT_MUTEXES=y 115CONFIG_RT_MUTEXES=y
@@ -117,7 +121,6 @@ CONFIG_MODULES=y
117# CONFIG_MODULE_SRCVERSION_ALL is not set 121# CONFIG_MODULE_SRCVERSION_ALL is not set
118CONFIG_BLOCK=y 122CONFIG_BLOCK=y
119# CONFIG_LBD is not set 123# CONFIG_LBD is not set
120# CONFIG_BLK_DEV_IO_TRACE is not set
121# CONFIG_BLK_DEV_BSG is not set 124# CONFIG_BLK_DEV_BSG is not set
122# CONFIG_BLK_DEV_INTEGRITY is not set 125# CONFIG_BLK_DEV_INTEGRITY is not set
123 126
@@ -164,6 +167,7 @@ CONFIG_CPU_SH4A=y
164# CONFIG_CPU_SUBTYPE_SH7760 is not set 167# CONFIG_CPU_SUBTYPE_SH7760 is not set
165# CONFIG_CPU_SUBTYPE_SH4_202 is not set 168# CONFIG_CPU_SUBTYPE_SH4_202 is not set
166# CONFIG_CPU_SUBTYPE_SH7723 is not set 169# CONFIG_CPU_SUBTYPE_SH7723 is not set
170# CONFIG_CPU_SUBTYPE_SH7724 is not set
167CONFIG_CPU_SUBTYPE_SH7763=y 171CONFIG_CPU_SUBTYPE_SH7763=y
168# CONFIG_CPU_SUBTYPE_SH7770 is not set 172# CONFIG_CPU_SUBTYPE_SH7770 is not set
169# CONFIG_CPU_SUBTYPE_SH7780 is not set 173# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -173,8 +177,6 @@ CONFIG_CPU_SUBTYPE_SH7763=y
173# CONFIG_CPU_SUBTYPE_SH7343 is not set 177# CONFIG_CPU_SUBTYPE_SH7343 is not set
174# CONFIG_CPU_SUBTYPE_SH7722 is not set 178# CONFIG_CPU_SUBTYPE_SH7722 is not set
175# CONFIG_CPU_SUBTYPE_SH7366 is not set 179# CONFIG_CPU_SUBTYPE_SH7366 is not set
176# CONFIG_CPU_SUBTYPE_SH5_101 is not set
177# CONFIG_CPU_SUBTYPE_SH5_103 is not set
178 180
179# 181#
180# Memory management options 182# Memory management options
@@ -548,6 +550,7 @@ CONFIG_SCSI_WAIT_SCAN=m
548CONFIG_SCSI_LOWLEVEL=y 550CONFIG_SCSI_LOWLEVEL=y
549# CONFIG_ISCSI_TCP is not set 551# CONFIG_ISCSI_TCP is not set
550# CONFIG_LIBFC is not set 552# CONFIG_LIBFC is not set
553# CONFIG_LIBFCOE is not set
551# CONFIG_SCSI_DEBUG is not set 554# CONFIG_SCSI_DEBUG is not set
552# CONFIG_SCSI_DH is not set 555# CONFIG_SCSI_DH is not set
553# CONFIG_SCSI_OSD_INITIATOR is not set 556# CONFIG_SCSI_OSD_INITIATOR is not set
@@ -919,6 +922,7 @@ CONFIG_EXT2_FS=y
919# CONFIG_EXT2_FS_XATTR is not set 922# CONFIG_EXT2_FS_XATTR is not set
920# CONFIG_EXT2_FS_XIP is not set 923# CONFIG_EXT2_FS_XIP is not set
921CONFIG_EXT3_FS=y 924CONFIG_EXT3_FS=y
925# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
922CONFIG_EXT3_FS_XATTR=y 926CONFIG_EXT3_FS_XATTR=y
923# CONFIG_EXT3_FS_POSIX_ACL is not set 927# CONFIG_EXT3_FS_POSIX_ACL is not set
924# CONFIG_EXT3_FS_SECURITY is not set 928# CONFIG_EXT3_FS_SECURITY is not set
@@ -943,6 +947,11 @@ CONFIG_AUTOFS4_FS=y
943CONFIG_GENERIC_ACL=y 947CONFIG_GENERIC_ACL=y
944 948
945# 949#
950# Caches
951#
952# CONFIG_FSCACHE is not set
953
954#
946# CD-ROM/DVD Filesystems 955# CD-ROM/DVD Filesystems
947# 956#
948# CONFIG_ISO9660_FS is not set 957# CONFIG_ISO9660_FS is not set
@@ -985,8 +994,13 @@ CONFIG_CRAMFS=y
985# CONFIG_HPFS_FS is not set 994# CONFIG_HPFS_FS is not set
986# CONFIG_QNX4FS_FS is not set 995# CONFIG_QNX4FS_FS is not set
987CONFIG_ROMFS_FS=y 996CONFIG_ROMFS_FS=y
997CONFIG_ROMFS_BACKED_BY_BLOCK=y
998# CONFIG_ROMFS_BACKED_BY_MTD is not set
999# CONFIG_ROMFS_BACKED_BY_BOTH is not set
1000CONFIG_ROMFS_ON_BLOCK=y
988# CONFIG_SYSV_FS is not set 1001# CONFIG_SYSV_FS is not set
989# CONFIG_UFS_FS is not set 1002# CONFIG_UFS_FS is not set
1003# CONFIG_NILFS2_FS is not set
990CONFIG_NETWORK_FILESYSTEMS=y 1004CONFIG_NETWORK_FILESYSTEMS=y
991CONFIG_NFS_FS=y 1005CONFIG_NFS_FS=y
992# CONFIG_NFS_V3 is not set 1006# CONFIG_NFS_V3 is not set
@@ -1075,11 +1089,25 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
1075CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1089CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1076CONFIG_RING_BUFFER=y 1090CONFIG_RING_BUFFER=y
1077CONFIG_TRACING=y 1091CONFIG_TRACING=y
1092CONFIG_TRACING_SUPPORT=y
1078 1093
1079# 1094#
1080# Tracers 1095# Tracers
1081# 1096#
1097# CONFIG_FUNCTION_TRACER is not set
1098# CONFIG_IRQSOFF_TRACER is not set
1099# CONFIG_SCHED_TRACER is not set
1100# CONFIG_CONTEXT_SWITCH_TRACER is not set
1101# CONFIG_EVENT_TRACER is not set
1102# CONFIG_BOOT_TRACER is not set
1103# CONFIG_TRACE_BRANCH_PROFILING is not set
1104# CONFIG_STACK_TRACER is not set
1105# CONFIG_KMEMTRACE is not set
1106# CONFIG_WORKQUEUE_TRACER is not set
1107# CONFIG_BLK_DEV_IO_TRACE is not set
1108# CONFIG_FTRACE_STARTUP_TEST is not set
1082# CONFIG_DYNAMIC_DEBUG is not set 1109# CONFIG_DYNAMIC_DEBUG is not set
1110# CONFIG_DMA_API_DEBUG is not set
1083# CONFIG_SAMPLES is not set 1111# CONFIG_SAMPLES is not set
1084CONFIG_HAVE_ARCH_KGDB=y 1112CONFIG_HAVE_ARCH_KGDB=y
1085# CONFIG_SH_STANDARD_BIOS is not set 1113# CONFIG_SH_STANDARD_BIOS is not set
@@ -1179,6 +1207,7 @@ CONFIG_CRYPTO=y
1179# 1207#
1180# CONFIG_CRYPTO_ANSI_CPRNG is not set 1208# CONFIG_CRYPTO_ANSI_CPRNG is not set
1181CONFIG_CRYPTO_HW=y 1209CONFIG_CRYPTO_HW=y
1210CONFIG_BINARY_PRINTF=y
1182 1211
1183# 1212#
1184# Library routines 1213# Library routines
diff --git a/arch/sh/configs/hp6xx_defconfig b/arch/sh/configs/hp6xx_defconfig
index 82b113af08d3..8e13027eecc3 100644
--- a/arch/sh/configs/hp6xx_defconfig
+++ b/arch/sh/configs/hp6xx_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:01:05 2009 4# Mon Apr 27 12:47:15 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -67,6 +68,7 @@ CONFIG_UID16=y
67# CONFIG_SYSCTL_SYSCALL is not set 68# CONFIG_SYSCTL_SYSCALL is not set
68CONFIG_KALLSYMS=y 69CONFIG_KALLSYMS=y
69# CONFIG_KALLSYMS_EXTRA_PASS is not set 70# CONFIG_KALLSYMS_EXTRA_PASS is not set
71# CONFIG_STRIP_ASM_SYMS is not set
70CONFIG_HOTPLUG=y 72CONFIG_HOTPLUG=y
71CONFIG_PRINTK=y 73CONFIG_PRINTK=y
72CONFIG_BUG=y 74CONFIG_BUG=y
@@ -85,12 +87,15 @@ CONFIG_SLAB=y
85# CONFIG_SLUB is not set 87# CONFIG_SLUB is not set
86# CONFIG_SLOB is not set 88# CONFIG_SLOB is not set
87# CONFIG_PROFILING is not set 89# CONFIG_PROFILING is not set
90# CONFIG_MARKERS is not set
88CONFIG_HAVE_OPROFILE=y 91CONFIG_HAVE_OPROFILE=y
89CONFIG_HAVE_IOREMAP_PROT=y 92CONFIG_HAVE_IOREMAP_PROT=y
90CONFIG_HAVE_KPROBES=y 93CONFIG_HAVE_KPROBES=y
91CONFIG_HAVE_KRETPROBES=y 94CONFIG_HAVE_KRETPROBES=y
92CONFIG_HAVE_ARCH_TRACEHOOK=y 95CONFIG_HAVE_ARCH_TRACEHOOK=y
93CONFIG_HAVE_CLK=y 96CONFIG_HAVE_CLK=y
97CONFIG_HAVE_DMA_API_DEBUG=y
98# CONFIG_SLOW_WORK is not set
94CONFIG_HAVE_GENERIC_DMA_COHERENT=y 99CONFIG_HAVE_GENERIC_DMA_COHERENT=y
95CONFIG_SLABINFO=y 100CONFIG_SLABINFO=y
96CONFIG_RT_MUTEXES=y 101CONFIG_RT_MUTEXES=y
@@ -98,7 +103,6 @@ CONFIG_BASE_SMALL=0
98# CONFIG_MODULES is not set 103# CONFIG_MODULES is not set
99CONFIG_BLOCK=y 104CONFIG_BLOCK=y
100# CONFIG_LBD is not set 105# CONFIG_LBD is not set
101# CONFIG_BLK_DEV_IO_TRACE is not set
102# CONFIG_BLK_DEV_BSG is not set 106# CONFIG_BLK_DEV_BSG is not set
103# CONFIG_BLK_DEV_INTEGRITY is not set 107# CONFIG_BLK_DEV_INTEGRITY is not set
104 108
@@ -144,6 +148,7 @@ CONFIG_CPU_SUBTYPE_SH7709=y
144# CONFIG_CPU_SUBTYPE_SH7760 is not set 148# CONFIG_CPU_SUBTYPE_SH7760 is not set
145# CONFIG_CPU_SUBTYPE_SH4_202 is not set 149# CONFIG_CPU_SUBTYPE_SH4_202 is not set
146# CONFIG_CPU_SUBTYPE_SH7723 is not set 150# CONFIG_CPU_SUBTYPE_SH7723 is not set
151# CONFIG_CPU_SUBTYPE_SH7724 is not set
147# CONFIG_CPU_SUBTYPE_SH7763 is not set 152# CONFIG_CPU_SUBTYPE_SH7763 is not set
148# CONFIG_CPU_SUBTYPE_SH7770 is not set 153# CONFIG_CPU_SUBTYPE_SH7770 is not set
149# CONFIG_CPU_SUBTYPE_SH7780 is not set 154# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -153,8 +158,6 @@ CONFIG_CPU_SUBTYPE_SH7709=y
153# CONFIG_CPU_SUBTYPE_SH7343 is not set 158# CONFIG_CPU_SUBTYPE_SH7343 is not set
154# CONFIG_CPU_SUBTYPE_SH7722 is not set 159# CONFIG_CPU_SUBTYPE_SH7722 is not set
155# CONFIG_CPU_SUBTYPE_SH7366 is not set 160# CONFIG_CPU_SUBTYPE_SH7366 is not set
156# CONFIG_CPU_SUBTYPE_SH5_101 is not set
157# CONFIG_CPU_SUBTYPE_SH5_103 is not set
158 161
159# 162#
160# Memory management options 163# Memory management options
@@ -385,6 +388,7 @@ CONFIG_BLK_DEV_SD=y
385# CONFIG_SCSI_SRP_ATTRS is not set 388# CONFIG_SCSI_SRP_ATTRS is not set
386CONFIG_SCSI_LOWLEVEL=y 389CONFIG_SCSI_LOWLEVEL=y
387# CONFIG_LIBFC is not set 390# CONFIG_LIBFC is not set
391# CONFIG_LIBFCOE is not set
388# CONFIG_SCSI_DEBUG is not set 392# CONFIG_SCSI_DEBUG is not set
389# CONFIG_SCSI_LOWLEVEL_PCMCIA is not set 393# CONFIG_SCSI_LOWLEVEL_PCMCIA is not set
390# CONFIG_SCSI_DH is not set 394# CONFIG_SCSI_DH is not set
@@ -431,6 +435,7 @@ CONFIG_KEYBOARD_HP6XX=y
431# CONFIG_INPUT_JOYSTICK is not set 435# CONFIG_INPUT_JOYSTICK is not set
432# CONFIG_INPUT_TABLET is not set 436# CONFIG_INPUT_TABLET is not set
433CONFIG_INPUT_TOUCHSCREEN=y 437CONFIG_INPUT_TOUCHSCREEN=y
438# CONFIG_TOUCHSCREEN_AD7879 is not set
434# CONFIG_TOUCHSCREEN_FUJITSU is not set 439# CONFIG_TOUCHSCREEN_FUJITSU is not set
435# CONFIG_TOUCHSCREEN_GUNZE is not set 440# CONFIG_TOUCHSCREEN_GUNZE is not set
436# CONFIG_TOUCHSCREEN_ELO is not set 441# CONFIG_TOUCHSCREEN_ELO is not set
@@ -674,6 +679,11 @@ CONFIG_INOTIFY_USER=y
674# CONFIG_FUSE_FS is not set 679# CONFIG_FUSE_FS is not set
675 680
676# 681#
682# Caches
683#
684# CONFIG_FSCACHE is not set
685
686#
677# CD-ROM/DVD Filesystems 687# CD-ROM/DVD Filesystems
678# 688#
679# CONFIG_ISO9660_FS is not set 689# CONFIG_ISO9660_FS is not set
@@ -719,6 +729,7 @@ CONFIG_MISC_FILESYSTEMS=y
719# CONFIG_ROMFS_FS is not set 729# CONFIG_ROMFS_FS is not set
720# CONFIG_SYSV_FS is not set 730# CONFIG_SYSV_FS is not set
721# CONFIG_UFS_FS is not set 731# CONFIG_UFS_FS is not set
732# CONFIG_NILFS2_FS is not set
722 733
723# 734#
724# Partition Types 735# Partition Types
@@ -786,10 +797,23 @@ CONFIG_FRAME_WARN=1024
786CONFIG_HAVE_FUNCTION_TRACER=y 797CONFIG_HAVE_FUNCTION_TRACER=y
787CONFIG_HAVE_DYNAMIC_FTRACE=y 798CONFIG_HAVE_DYNAMIC_FTRACE=y
788CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 799CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
800CONFIG_TRACING_SUPPORT=y
789 801
790# 802#
791# Tracers 803# Tracers
792# 804#
805# CONFIG_FUNCTION_TRACER is not set
806# CONFIG_IRQSOFF_TRACER is not set
807# CONFIG_SCHED_TRACER is not set
808# CONFIG_CONTEXT_SWITCH_TRACER is not set
809# CONFIG_EVENT_TRACER is not set
810# CONFIG_BOOT_TRACER is not set
811# CONFIG_TRACE_BRANCH_PROFILING is not set
812# CONFIG_STACK_TRACER is not set
813# CONFIG_KMEMTRACE is not set
814# CONFIG_WORKQUEUE_TRACER is not set
815# CONFIG_BLK_DEV_IO_TRACE is not set
816# CONFIG_DMA_API_DEBUG is not set
793# CONFIG_SAMPLES is not set 817# CONFIG_SAMPLES is not set
794CONFIG_HAVE_ARCH_KGDB=y 818CONFIG_HAVE_ARCH_KGDB=y
795# CONFIG_SH_STANDARD_BIOS is not set 819# CONFIG_SH_STANDARD_BIOS is not set
@@ -898,6 +922,7 @@ CONFIG_CRYPTO_MD5=y
898# 922#
899# CONFIG_CRYPTO_ANSI_CPRNG is not set 923# CONFIG_CRYPTO_ANSI_CPRNG is not set
900# CONFIG_CRYPTO_HW is not set 924# CONFIG_CRYPTO_HW is not set
925# CONFIG_BINARY_PRINTF is not set
901 926
902# 927#
903# Library routines 928# Library routines
diff --git a/arch/sh/configs/landisk_defconfig b/arch/sh/configs/landisk_defconfig
index b6fa4a7599d0..7f549aef0dfd 100644
--- a/arch/sh/configs/landisk_defconfig
+++ b/arch/sh/configs/landisk_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:02:54 2009 4# Mon Apr 27 12:47:48 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -69,6 +70,7 @@ CONFIG_UID16=y
69# CONFIG_SYSCTL_SYSCALL is not set 70# CONFIG_SYSCTL_SYSCALL is not set
70CONFIG_KALLSYMS=y 71CONFIG_KALLSYMS=y
71CONFIG_KALLSYMS_EXTRA_PASS=y 72CONFIG_KALLSYMS_EXTRA_PASS=y
73# CONFIG_STRIP_ASM_SYMS is not set
72CONFIG_HOTPLUG=y 74CONFIG_HOTPLUG=y
73CONFIG_PRINTK=y 75CONFIG_PRINTK=y
74CONFIG_BUG=y 76CONFIG_BUG=y
@@ -88,6 +90,7 @@ CONFIG_SLAB=y
88# CONFIG_SLUB is not set 90# CONFIG_SLUB is not set
89# CONFIG_SLOB is not set 91# CONFIG_SLOB is not set
90# CONFIG_PROFILING is not set 92# CONFIG_PROFILING is not set
93# CONFIG_MARKERS is not set
91CONFIG_HAVE_OPROFILE=y 94CONFIG_HAVE_OPROFILE=y
92# CONFIG_KPROBES is not set 95# CONFIG_KPROBES is not set
93CONFIG_HAVE_IOREMAP_PROT=y 96CONFIG_HAVE_IOREMAP_PROT=y
@@ -95,6 +98,8 @@ CONFIG_HAVE_KPROBES=y
95CONFIG_HAVE_KRETPROBES=y 98CONFIG_HAVE_KRETPROBES=y
96CONFIG_HAVE_ARCH_TRACEHOOK=y 99CONFIG_HAVE_ARCH_TRACEHOOK=y
97CONFIG_HAVE_CLK=y 100CONFIG_HAVE_CLK=y
101CONFIG_HAVE_DMA_API_DEBUG=y
102# CONFIG_SLOW_WORK is not set
98CONFIG_HAVE_GENERIC_DMA_COHERENT=y 103CONFIG_HAVE_GENERIC_DMA_COHERENT=y
99CONFIG_SLABINFO=y 104CONFIG_SLABINFO=y
100CONFIG_RT_MUTEXES=y 105CONFIG_RT_MUTEXES=y
@@ -107,7 +112,6 @@ CONFIG_MODULE_FORCE_UNLOAD=y
107# CONFIG_MODULE_SRCVERSION_ALL is not set 112# CONFIG_MODULE_SRCVERSION_ALL is not set
108CONFIG_BLOCK=y 113CONFIG_BLOCK=y
109# CONFIG_LBD is not set 114# CONFIG_LBD is not set
110# CONFIG_BLK_DEV_IO_TRACE is not set
111# CONFIG_BLK_DEV_BSG is not set 115# CONFIG_BLK_DEV_BSG is not set
112# CONFIG_BLK_DEV_INTEGRITY is not set 116# CONFIG_BLK_DEV_INTEGRITY is not set
113 117
@@ -153,6 +157,7 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
153# CONFIG_CPU_SUBTYPE_SH7760 is not set 157# CONFIG_CPU_SUBTYPE_SH7760 is not set
154# CONFIG_CPU_SUBTYPE_SH4_202 is not set 158# CONFIG_CPU_SUBTYPE_SH4_202 is not set
155# CONFIG_CPU_SUBTYPE_SH7723 is not set 159# CONFIG_CPU_SUBTYPE_SH7723 is not set
160# CONFIG_CPU_SUBTYPE_SH7724 is not set
156# CONFIG_CPU_SUBTYPE_SH7763 is not set 161# CONFIG_CPU_SUBTYPE_SH7763 is not set
157# CONFIG_CPU_SUBTYPE_SH7770 is not set 162# CONFIG_CPU_SUBTYPE_SH7770 is not set
158# CONFIG_CPU_SUBTYPE_SH7780 is not set 163# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -162,8 +167,6 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
162# CONFIG_CPU_SUBTYPE_SH7343 is not set 167# CONFIG_CPU_SUBTYPE_SH7343 is not set
163# CONFIG_CPU_SUBTYPE_SH7722 is not set 168# CONFIG_CPU_SUBTYPE_SH7722 is not set
164# CONFIG_CPU_SUBTYPE_SH7366 is not set 169# CONFIG_CPU_SUBTYPE_SH7366 is not set
165# CONFIG_CPU_SUBTYPE_SH5_101 is not set
166# CONFIG_CPU_SUBTYPE_SH5_103 is not set
167 170
168# 171#
169# Memory management options 172# Memory management options
@@ -292,8 +295,6 @@ CONFIG_BOOT_LINK_OFFSET=0x00800000
292# 295#
293CONFIG_PCI=y 296CONFIG_PCI=y
294CONFIG_SH_PCIDMA_NONCOHERENT=y 297CONFIG_SH_PCIDMA_NONCOHERENT=y
295CONFIG_PCI_AUTO=y
296CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
297# CONFIG_PCIEPORTBUS is not set 298# CONFIG_PCIEPORTBUS is not set
298# CONFIG_ARCH_SUPPORTS_MSI is not set 299# CONFIG_ARCH_SUPPORTS_MSI is not set
299CONFIG_PCI_LEGACY=y 300CONFIG_PCI_LEGACY=y
@@ -602,6 +603,7 @@ CONFIG_SCSI_LOWLEVEL=y
602# CONFIG_SCSI_MPT2SAS is not set 603# CONFIG_SCSI_MPT2SAS is not set
603# CONFIG_SCSI_HPTIOP is not set 604# CONFIG_SCSI_HPTIOP is not set
604# CONFIG_LIBFC is not set 605# CONFIG_LIBFC is not set
606# CONFIG_LIBFCOE is not set
605# CONFIG_FCOE is not set 607# CONFIG_FCOE is not set
606# CONFIG_SCSI_DMX3191D is not set 608# CONFIG_SCSI_DMX3191D is not set
607# CONFIG_SCSI_FUTURE_DOMAIN is not set 609# CONFIG_SCSI_FUTURE_DOMAIN is not set
@@ -706,6 +708,7 @@ CONFIG_NETDEV_1000=y
706# CONFIG_E1000E is not set 708# CONFIG_E1000E is not set
707# CONFIG_IP1000 is not set 709# CONFIG_IP1000 is not set
708# CONFIG_IGB is not set 710# CONFIG_IGB is not set
711# CONFIG_IGBVF is not set
709# CONFIG_NS83820 is not set 712# CONFIG_NS83820 is not set
710# CONFIG_HAMACHI is not set 713# CONFIG_HAMACHI is not set
711# CONFIG_YELLOWFIN is not set 714# CONFIG_YELLOWFIN is not set
@@ -729,6 +732,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
729# CONFIG_IXGBE is not set 732# CONFIG_IXGBE is not set
730# CONFIG_IXGB is not set 733# CONFIG_IXGB is not set
731# CONFIG_S2IO is not set 734# CONFIG_S2IO is not set
735# CONFIG_VXGE is not set
732# CONFIG_MYRI10GE is not set 736# CONFIG_MYRI10GE is not set
733# CONFIG_NETXEN_NIC is not set 737# CONFIG_NETXEN_NIC is not set
734# CONFIG_NIU is not set 738# CONFIG_NIU is not set
@@ -922,6 +926,7 @@ CONFIG_VIDEO_HELPER_CHIPS_AUTO=y
922# CONFIG_SOC_CAMERA is not set 926# CONFIG_SOC_CAMERA is not set
923CONFIG_V4L_USB_DRIVERS=y 927CONFIG_V4L_USB_DRIVERS=y
924# CONFIG_USB_VIDEO_CLASS is not set 928# CONFIG_USB_VIDEO_CLASS is not set
929CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV=y
925# CONFIG_USB_GSPCA is not set 930# CONFIG_USB_GSPCA is not set
926# CONFIG_VIDEO_HDPVR is not set 931# CONFIG_VIDEO_HDPVR is not set
927CONFIG_VIDEO_USBVIDEO=m 932CONFIG_VIDEO_USBVIDEO=m
@@ -994,15 +999,17 @@ CONFIG_USB_HID=m
994# 999#
995# Special HID drivers 1000# Special HID drivers
996# 1001#
997CONFIG_HID_COMPAT=y
998CONFIG_HID_A4TECH=m 1002CONFIG_HID_A4TECH=m
999CONFIG_HID_APPLE=m 1003CONFIG_HID_APPLE=m
1000CONFIG_HID_BELKIN=m 1004CONFIG_HID_BELKIN=m
1001CONFIG_HID_CHERRY=m 1005CONFIG_HID_CHERRY=m
1002CONFIG_HID_CHICONY=m 1006CONFIG_HID_CHICONY=m
1003CONFIG_HID_CYPRESS=m 1007CONFIG_HID_CYPRESS=m
1008# CONFIG_DRAGONRISE_FF is not set
1004CONFIG_HID_EZKEY=m 1009CONFIG_HID_EZKEY=m
1010# CONFIG_HID_KYE is not set
1005CONFIG_HID_GYRATION=m 1011CONFIG_HID_GYRATION=m
1012# CONFIG_HID_KENSINGTON is not set
1006CONFIG_HID_LOGITECH=m 1013CONFIG_HID_LOGITECH=m
1007# CONFIG_LOGITECH_FF is not set 1014# CONFIG_LOGITECH_FF is not set
1008# CONFIG_LOGIRUMBLEPAD2_FF is not set 1015# CONFIG_LOGIRUMBLEPAD2_FF is not set
@@ -1197,6 +1204,7 @@ CONFIG_EXT2_FS=y
1197# CONFIG_EXT2_FS_XATTR is not set 1204# CONFIG_EXT2_FS_XATTR is not set
1198# CONFIG_EXT2_FS_XIP is not set 1205# CONFIG_EXT2_FS_XIP is not set
1199CONFIG_EXT3_FS=y 1206CONFIG_EXT3_FS=y
1207# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
1200CONFIG_EXT3_FS_XATTR=y 1208CONFIG_EXT3_FS_XATTR=y
1201# CONFIG_EXT3_FS_POSIX_ACL is not set 1209# CONFIG_EXT3_FS_POSIX_ACL is not set
1202# CONFIG_EXT3_FS_SECURITY is not set 1210# CONFIG_EXT3_FS_SECURITY is not set
@@ -1222,6 +1230,11 @@ CONFIG_INOTIFY_USER=y
1222# CONFIG_FUSE_FS is not set 1230# CONFIG_FUSE_FS is not set
1223 1231
1224# 1232#
1233# Caches
1234#
1235# CONFIG_FSCACHE is not set
1236
1237#
1225# CD-ROM/DVD Filesystems 1238# CD-ROM/DVD Filesystems
1226# 1239#
1227CONFIG_ISO9660_FS=m 1240CONFIG_ISO9660_FS=m
@@ -1270,10 +1283,15 @@ CONFIG_MISC_FILESYSTEMS=y
1270# CONFIG_HPFS_FS is not set 1283# CONFIG_HPFS_FS is not set
1271# CONFIG_QNX4FS_FS is not set 1284# CONFIG_QNX4FS_FS is not set
1272CONFIG_ROMFS_FS=y 1285CONFIG_ROMFS_FS=y
1286CONFIG_ROMFS_BACKED_BY_BLOCK=y
1287# CONFIG_ROMFS_BACKED_BY_MTD is not set
1288# CONFIG_ROMFS_BACKED_BY_BOTH is not set
1289CONFIG_ROMFS_ON_BLOCK=y
1273# CONFIG_SYSV_FS is not set 1290# CONFIG_SYSV_FS is not set
1274CONFIG_UFS_FS=m 1291CONFIG_UFS_FS=m
1275# CONFIG_UFS_FS_WRITE is not set 1292# CONFIG_UFS_FS_WRITE is not set
1276# CONFIG_UFS_DEBUG is not set 1293# CONFIG_UFS_DEBUG is not set
1294# CONFIG_NILFS2_FS is not set
1277CONFIG_NETWORK_FILESYSTEMS=y 1295CONFIG_NETWORK_FILESYSTEMS=y
1278CONFIG_NFS_FS=m 1296CONFIG_NFS_FS=m
1279CONFIG_NFS_V3=y 1297CONFIG_NFS_V3=y
@@ -1364,10 +1382,23 @@ CONFIG_FRAME_WARN=1024
1364CONFIG_HAVE_FUNCTION_TRACER=y 1382CONFIG_HAVE_FUNCTION_TRACER=y
1365CONFIG_HAVE_DYNAMIC_FTRACE=y 1383CONFIG_HAVE_DYNAMIC_FTRACE=y
1366CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1384CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1385CONFIG_TRACING_SUPPORT=y
1367 1386
1368# 1387#
1369# Tracers 1388# Tracers
1370# 1389#
1390# CONFIG_FUNCTION_TRACER is not set
1391# CONFIG_IRQSOFF_TRACER is not set
1392# CONFIG_SCHED_TRACER is not set
1393# CONFIG_CONTEXT_SWITCH_TRACER is not set
1394# CONFIG_EVENT_TRACER is not set
1395# CONFIG_BOOT_TRACER is not set
1396# CONFIG_TRACE_BRANCH_PROFILING is not set
1397# CONFIG_STACK_TRACER is not set
1398# CONFIG_KMEMTRACE is not set
1399# CONFIG_WORKQUEUE_TRACER is not set
1400# CONFIG_BLK_DEV_IO_TRACE is not set
1401# CONFIG_DMA_API_DEBUG is not set
1371# CONFIG_SAMPLES is not set 1402# CONFIG_SAMPLES is not set
1372CONFIG_HAVE_ARCH_KGDB=y 1403CONFIG_HAVE_ARCH_KGDB=y
1373CONFIG_SH_STANDARD_BIOS=y 1404CONFIG_SH_STANDARD_BIOS=y
@@ -1469,6 +1500,7 @@ CONFIG_CRYPTO=y
1469# CONFIG_CRYPTO_ANSI_CPRNG is not set 1500# CONFIG_CRYPTO_ANSI_CPRNG is not set
1470CONFIG_CRYPTO_HW=y 1501CONFIG_CRYPTO_HW=y
1471# CONFIG_CRYPTO_DEV_HIFN_795X is not set 1502# CONFIG_CRYPTO_DEV_HIFN_795X is not set
1503# CONFIG_BINARY_PRINTF is not set
1472 1504
1473# 1505#
1474# Library routines 1506# Library routines
diff --git a/arch/sh/configs/lboxre2_defconfig b/arch/sh/configs/lboxre2_defconfig
index 92c515c4199f..a7db539f2800 100644
--- a/arch/sh/configs/lboxre2_defconfig
+++ b/arch/sh/configs/lboxre2_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:06:51 2009 4# Mon Apr 27 12:48:54 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -69,6 +70,7 @@ CONFIG_UID16=y
69# CONFIG_SYSCTL_SYSCALL is not set 70# CONFIG_SYSCTL_SYSCALL is not set
70CONFIG_KALLSYMS=y 71CONFIG_KALLSYMS=y
71CONFIG_KALLSYMS_EXTRA_PASS=y 72CONFIG_KALLSYMS_EXTRA_PASS=y
73# CONFIG_STRIP_ASM_SYMS is not set
72CONFIG_HOTPLUG=y 74CONFIG_HOTPLUG=y
73CONFIG_PRINTK=y 75CONFIG_PRINTK=y
74CONFIG_BUG=y 76CONFIG_BUG=y
@@ -88,6 +90,7 @@ CONFIG_SLAB=y
88# CONFIG_SLUB is not set 90# CONFIG_SLUB is not set
89# CONFIG_SLOB is not set 91# CONFIG_SLOB is not set
90# CONFIG_PROFILING is not set 92# CONFIG_PROFILING is not set
93# CONFIG_MARKERS is not set
91CONFIG_HAVE_OPROFILE=y 94CONFIG_HAVE_OPROFILE=y
92# CONFIG_KPROBES is not set 95# CONFIG_KPROBES is not set
93CONFIG_HAVE_IOREMAP_PROT=y 96CONFIG_HAVE_IOREMAP_PROT=y
@@ -95,6 +98,8 @@ CONFIG_HAVE_KPROBES=y
95CONFIG_HAVE_KRETPROBES=y 98CONFIG_HAVE_KRETPROBES=y
96CONFIG_HAVE_ARCH_TRACEHOOK=y 99CONFIG_HAVE_ARCH_TRACEHOOK=y
97CONFIG_HAVE_CLK=y 100CONFIG_HAVE_CLK=y
101CONFIG_HAVE_DMA_API_DEBUG=y
102# CONFIG_SLOW_WORK is not set
98CONFIG_HAVE_GENERIC_DMA_COHERENT=y 103CONFIG_HAVE_GENERIC_DMA_COHERENT=y
99CONFIG_SLABINFO=y 104CONFIG_SLABINFO=y
100CONFIG_RT_MUTEXES=y 105CONFIG_RT_MUTEXES=y
@@ -107,7 +112,6 @@ CONFIG_MODULE_FORCE_UNLOAD=y
107# CONFIG_MODULE_SRCVERSION_ALL is not set 112# CONFIG_MODULE_SRCVERSION_ALL is not set
108CONFIG_BLOCK=y 113CONFIG_BLOCK=y
109# CONFIG_LBD is not set 114# CONFIG_LBD is not set
110# CONFIG_BLK_DEV_IO_TRACE is not set
111# CONFIG_BLK_DEV_BSG is not set 115# CONFIG_BLK_DEV_BSG is not set
112# CONFIG_BLK_DEV_INTEGRITY is not set 116# CONFIG_BLK_DEV_INTEGRITY is not set
113 117
@@ -153,6 +157,7 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
153# CONFIG_CPU_SUBTYPE_SH7760 is not set 157# CONFIG_CPU_SUBTYPE_SH7760 is not set
154# CONFIG_CPU_SUBTYPE_SH4_202 is not set 158# CONFIG_CPU_SUBTYPE_SH4_202 is not set
155# CONFIG_CPU_SUBTYPE_SH7723 is not set 159# CONFIG_CPU_SUBTYPE_SH7723 is not set
160# CONFIG_CPU_SUBTYPE_SH7724 is not set
156# CONFIG_CPU_SUBTYPE_SH7763 is not set 161# CONFIG_CPU_SUBTYPE_SH7763 is not set
157# CONFIG_CPU_SUBTYPE_SH7770 is not set 162# CONFIG_CPU_SUBTYPE_SH7770 is not set
158# CONFIG_CPU_SUBTYPE_SH7780 is not set 163# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -162,8 +167,6 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
162# CONFIG_CPU_SUBTYPE_SH7343 is not set 167# CONFIG_CPU_SUBTYPE_SH7343 is not set
163# CONFIG_CPU_SUBTYPE_SH7722 is not set 168# CONFIG_CPU_SUBTYPE_SH7722 is not set
164# CONFIG_CPU_SUBTYPE_SH7366 is not set 169# CONFIG_CPU_SUBTYPE_SH7366 is not set
165# CONFIG_CPU_SUBTYPE_SH5_101 is not set
166# CONFIG_CPU_SUBTYPE_SH5_103 is not set
167 170
168# 171#
169# Memory management options 172# Memory management options
@@ -293,8 +296,6 @@ CONFIG_CMDLINE="console=ttySC1,115200 root=/dev/sda1"
293# 296#
294CONFIG_PCI=y 297CONFIG_PCI=y
295CONFIG_SH_PCIDMA_NONCOHERENT=y 298CONFIG_SH_PCIDMA_NONCOHERENT=y
296CONFIG_PCI_AUTO=y
297CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
298# CONFIG_PCIEPORTBUS is not set 299# CONFIG_PCIEPORTBUS is not set
299# CONFIG_ARCH_SUPPORTS_MSI is not set 300# CONFIG_ARCH_SUPPORTS_MSI is not set
300CONFIG_PCI_LEGACY=y 301CONFIG_PCI_LEGACY=y
@@ -542,6 +543,7 @@ CONFIG_SCSI_LOWLEVEL=y
542# CONFIG_SCSI_MPT2SAS is not set 543# CONFIG_SCSI_MPT2SAS is not set
543# CONFIG_SCSI_HPTIOP is not set 544# CONFIG_SCSI_HPTIOP is not set
544# CONFIG_LIBFC is not set 545# CONFIG_LIBFC is not set
546# CONFIG_LIBFCOE is not set
545# CONFIG_FCOE is not set 547# CONFIG_FCOE is not set
546# CONFIG_SCSI_DMX3191D is not set 548# CONFIG_SCSI_DMX3191D is not set
547# CONFIG_SCSI_FUTURE_DOMAIN is not set 549# CONFIG_SCSI_FUTURE_DOMAIN is not set
@@ -702,6 +704,7 @@ CONFIG_NETDEV_1000=y
702# CONFIG_E1000E is not set 704# CONFIG_E1000E is not set
703# CONFIG_IP1000 is not set 705# CONFIG_IP1000 is not set
704# CONFIG_IGB is not set 706# CONFIG_IGB is not set
707# CONFIG_IGBVF is not set
705# CONFIG_NS83820 is not set 708# CONFIG_NS83820 is not set
706# CONFIG_HAMACHI is not set 709# CONFIG_HAMACHI is not set
707# CONFIG_YELLOWFIN is not set 710# CONFIG_YELLOWFIN is not set
@@ -725,6 +728,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
725# CONFIG_IXGBE is not set 728# CONFIG_IXGBE is not set
726# CONFIG_IXGB is not set 729# CONFIG_IXGB is not set
727# CONFIG_S2IO is not set 730# CONFIG_S2IO is not set
731# CONFIG_VXGE is not set
728# CONFIG_MYRI10GE is not set 732# CONFIG_MYRI10GE is not set
729# CONFIG_NETXEN_NIC is not set 733# CONFIG_NETXEN_NIC is not set
730# CONFIG_NIU is not set 734# CONFIG_NIU is not set
@@ -931,7 +935,6 @@ CONFIG_HID=y
931# 935#
932# Special HID drivers 936# Special HID drivers
933# 937#
934CONFIG_HID_COMPAT=y
935CONFIG_USB_SUPPORT=y 938CONFIG_USB_SUPPORT=y
936CONFIG_USB_ARCH_HAS_HCD=y 939CONFIG_USB_ARCH_HAS_HCD=y
937CONFIG_USB_ARCH_HAS_OHCI=y 940CONFIG_USB_ARCH_HAS_OHCI=y
@@ -1007,6 +1010,7 @@ CONFIG_EXT2_FS=y
1007# CONFIG_EXT2_FS_XATTR is not set 1010# CONFIG_EXT2_FS_XATTR is not set
1008# CONFIG_EXT2_FS_XIP is not set 1011# CONFIG_EXT2_FS_XIP is not set
1009CONFIG_EXT3_FS=y 1012CONFIG_EXT3_FS=y
1013# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
1010CONFIG_EXT3_FS_XATTR=y 1014CONFIG_EXT3_FS_XATTR=y
1011# CONFIG_EXT3_FS_POSIX_ACL is not set 1015# CONFIG_EXT3_FS_POSIX_ACL is not set
1012# CONFIG_EXT3_FS_SECURITY is not set 1016# CONFIG_EXT3_FS_SECURITY is not set
@@ -1029,6 +1033,11 @@ CONFIG_INOTIFY_USER=y
1029# CONFIG_FUSE_FS is not set 1033# CONFIG_FUSE_FS is not set
1030 1034
1031# 1035#
1036# Caches
1037#
1038# CONFIG_FSCACHE is not set
1039
1040#
1032# CD-ROM/DVD Filesystems 1041# CD-ROM/DVD Filesystems
1033# 1042#
1034# CONFIG_ISO9660_FS is not set 1043# CONFIG_ISO9660_FS is not set
@@ -1073,8 +1082,13 @@ CONFIG_MISC_FILESYSTEMS=y
1073# CONFIG_HPFS_FS is not set 1082# CONFIG_HPFS_FS is not set
1074# CONFIG_QNX4FS_FS is not set 1083# CONFIG_QNX4FS_FS is not set
1075CONFIG_ROMFS_FS=y 1084CONFIG_ROMFS_FS=y
1085CONFIG_ROMFS_BACKED_BY_BLOCK=y
1086# CONFIG_ROMFS_BACKED_BY_MTD is not set
1087# CONFIG_ROMFS_BACKED_BY_BOTH is not set
1088CONFIG_ROMFS_ON_BLOCK=y
1076# CONFIG_SYSV_FS is not set 1089# CONFIG_SYSV_FS is not set
1077# CONFIG_UFS_FS is not set 1090# CONFIG_UFS_FS is not set
1091# CONFIG_NILFS2_FS is not set
1078CONFIG_NETWORK_FILESYSTEMS=y 1092CONFIG_NETWORK_FILESYSTEMS=y
1079# CONFIG_NFS_FS is not set 1093# CONFIG_NFS_FS is not set
1080# CONFIG_NFSD is not set 1094# CONFIG_NFSD is not set
@@ -1151,10 +1165,23 @@ CONFIG_FRAME_WARN=1024
1151CONFIG_HAVE_FUNCTION_TRACER=y 1165CONFIG_HAVE_FUNCTION_TRACER=y
1152CONFIG_HAVE_DYNAMIC_FTRACE=y 1166CONFIG_HAVE_DYNAMIC_FTRACE=y
1153CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1167CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1168CONFIG_TRACING_SUPPORT=y
1154 1169
1155# 1170#
1156# Tracers 1171# Tracers
1157# 1172#
1173# CONFIG_FUNCTION_TRACER is not set
1174# CONFIG_IRQSOFF_TRACER is not set
1175# CONFIG_SCHED_TRACER is not set
1176# CONFIG_CONTEXT_SWITCH_TRACER is not set
1177# CONFIG_EVENT_TRACER is not set
1178# CONFIG_BOOT_TRACER is not set
1179# CONFIG_TRACE_BRANCH_PROFILING is not set
1180# CONFIG_STACK_TRACER is not set
1181# CONFIG_KMEMTRACE is not set
1182# CONFIG_WORKQUEUE_TRACER is not set
1183# CONFIG_BLK_DEV_IO_TRACE is not set
1184# CONFIG_DMA_API_DEBUG is not set
1158# CONFIG_SAMPLES is not set 1185# CONFIG_SAMPLES is not set
1159CONFIG_HAVE_ARCH_KGDB=y 1186CONFIG_HAVE_ARCH_KGDB=y
1160CONFIG_SH_STANDARD_BIOS=y 1187CONFIG_SH_STANDARD_BIOS=y
@@ -1256,6 +1283,7 @@ CONFIG_CRYPTO=y
1256# CONFIG_CRYPTO_ANSI_CPRNG is not set 1283# CONFIG_CRYPTO_ANSI_CPRNG is not set
1257CONFIG_CRYPTO_HW=y 1284CONFIG_CRYPTO_HW=y
1258# CONFIG_CRYPTO_DEV_HIFN_795X is not set 1285# CONFIG_CRYPTO_DEV_HIFN_795X is not set
1286# CONFIG_BINARY_PRINTF is not set
1259 1287
1260# 1288#
1261# Library routines 1289# Library routines
diff --git a/arch/sh/configs/magicpanelr2_defconfig b/arch/sh/configs/magicpanelr2_defconfig
index 26586c2d64ca..58bec61506fa 100644
--- a/arch/sh/configs/magicpanelr2_defconfig
+++ b/arch/sh/configs/magicpanelr2_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:07:39 2009 4# Mon Apr 27 12:49:32 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -39,6 +40,7 @@ CONFIG_SWAP=y
39CONFIG_SYSVIPC=y 40CONFIG_SYSVIPC=y
40CONFIG_SYSVIPC_SYSCTL=y 41CONFIG_SYSVIPC_SYSCTL=y
41CONFIG_POSIX_MQUEUE=y 42CONFIG_POSIX_MQUEUE=y
43CONFIG_POSIX_MQUEUE_SYSCTL=y
42CONFIG_BSD_PROCESS_ACCT=y 44CONFIG_BSD_PROCESS_ACCT=y
43CONFIG_BSD_PROCESS_ACCT_V3=y 45CONFIG_BSD_PROCESS_ACCT_V3=y
44# CONFIG_TASKSTATS is not set 46# CONFIG_TASKSTATS is not set
@@ -66,7 +68,6 @@ CONFIG_INITRAMFS_SOURCE=""
66CONFIG_RD_GZIP=y 68CONFIG_RD_GZIP=y
67# CONFIG_RD_BZIP2 is not set 69# CONFIG_RD_BZIP2 is not set
68# CONFIG_RD_LZMA is not set 70# CONFIG_RD_LZMA is not set
69CONFIG_INITRAMFS_COMPRESSION_NONE=y
70# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set 71# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
71CONFIG_SYSCTL=y 72CONFIG_SYSCTL=y
72CONFIG_ANON_INODES=y 73CONFIG_ANON_INODES=y
@@ -76,6 +77,7 @@ CONFIG_SYSCTL_SYSCALL=y
76CONFIG_KALLSYMS=y 77CONFIG_KALLSYMS=y
77CONFIG_KALLSYMS_ALL=y 78CONFIG_KALLSYMS_ALL=y
78# CONFIG_KALLSYMS_EXTRA_PASS is not set 79# CONFIG_KALLSYMS_EXTRA_PASS is not set
80# CONFIG_STRIP_ASM_SYMS is not set
79CONFIG_HOTPLUG=y 81CONFIG_HOTPLUG=y
80CONFIG_PRINTK=y 82CONFIG_PRINTK=y
81CONFIG_BUG=y 83CONFIG_BUG=y
@@ -94,6 +96,7 @@ CONFIG_SLAB=y
94# CONFIG_SLUB is not set 96# CONFIG_SLUB is not set
95# CONFIG_SLOB is not set 97# CONFIG_SLOB is not set
96# CONFIG_PROFILING is not set 98# CONFIG_PROFILING is not set
99# CONFIG_MARKERS is not set
97CONFIG_HAVE_OPROFILE=y 100CONFIG_HAVE_OPROFILE=y
98# CONFIG_KPROBES is not set 101# CONFIG_KPROBES is not set
99CONFIG_HAVE_IOREMAP_PROT=y 102CONFIG_HAVE_IOREMAP_PROT=y
@@ -101,6 +104,8 @@ CONFIG_HAVE_KPROBES=y
101CONFIG_HAVE_KRETPROBES=y 104CONFIG_HAVE_KRETPROBES=y
102CONFIG_HAVE_ARCH_TRACEHOOK=y 105CONFIG_HAVE_ARCH_TRACEHOOK=y
103CONFIG_HAVE_CLK=y 106CONFIG_HAVE_CLK=y
107CONFIG_HAVE_DMA_API_DEBUG=y
108# CONFIG_SLOW_WORK is not set
104CONFIG_HAVE_GENERIC_DMA_COHERENT=y 109CONFIG_HAVE_GENERIC_DMA_COHERENT=y
105CONFIG_SLABINFO=y 110CONFIG_SLABINFO=y
106CONFIG_RT_MUTEXES=y 111CONFIG_RT_MUTEXES=y
@@ -113,7 +118,6 @@ CONFIG_MODVERSIONS=y
113CONFIG_MODULE_SRCVERSION_ALL=y 118CONFIG_MODULE_SRCVERSION_ALL=y
114CONFIG_BLOCK=y 119CONFIG_BLOCK=y
115# CONFIG_LBD is not set 120# CONFIG_LBD is not set
116# CONFIG_BLK_DEV_IO_TRACE is not set
117# CONFIG_BLK_DEV_BSG is not set 121# CONFIG_BLK_DEV_BSG is not set
118# CONFIG_BLK_DEV_INTEGRITY is not set 122# CONFIG_BLK_DEV_INTEGRITY is not set
119 123
@@ -159,6 +163,7 @@ CONFIG_CPU_SUBTYPE_SH7720=y
159# CONFIG_CPU_SUBTYPE_SH7760 is not set 163# CONFIG_CPU_SUBTYPE_SH7760 is not set
160# CONFIG_CPU_SUBTYPE_SH4_202 is not set 164# CONFIG_CPU_SUBTYPE_SH4_202 is not set
161# CONFIG_CPU_SUBTYPE_SH7723 is not set 165# CONFIG_CPU_SUBTYPE_SH7723 is not set
166# CONFIG_CPU_SUBTYPE_SH7724 is not set
162# CONFIG_CPU_SUBTYPE_SH7763 is not set 167# CONFIG_CPU_SUBTYPE_SH7763 is not set
163# CONFIG_CPU_SUBTYPE_SH7770 is not set 168# CONFIG_CPU_SUBTYPE_SH7770 is not set
164# CONFIG_CPU_SUBTYPE_SH7780 is not set 169# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -168,8 +173,6 @@ CONFIG_CPU_SUBTYPE_SH7720=y
168# CONFIG_CPU_SUBTYPE_SH7343 is not set 173# CONFIG_CPU_SUBTYPE_SH7343 is not set
169# CONFIG_CPU_SUBTYPE_SH7722 is not set 174# CONFIG_CPU_SUBTYPE_SH7722 is not set
170# CONFIG_CPU_SUBTYPE_SH7366 is not set 175# CONFIG_CPU_SUBTYPE_SH7366 is not set
171# CONFIG_CPU_SUBTYPE_SH5_101 is not set
172# CONFIG_CPU_SUBTYPE_SH5_103 is not set
173 176
174# 177#
175# Memory management options 178# Memory management options
@@ -813,6 +816,7 @@ CONFIG_EXT2_FS=y
813# CONFIG_EXT2_FS_XATTR is not set 816# CONFIG_EXT2_FS_XATTR is not set
814# CONFIG_EXT2_FS_XIP is not set 817# CONFIG_EXT2_FS_XIP is not set
815CONFIG_EXT3_FS=y 818CONFIG_EXT3_FS=y
819# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
816# CONFIG_EXT3_FS_XATTR is not set 820# CONFIG_EXT3_FS_XATTR is not set
817# CONFIG_EXT4_FS is not set 821# CONFIG_EXT4_FS is not set
818CONFIG_JBD=y 822CONFIG_JBD=y
@@ -831,6 +835,11 @@ CONFIG_FILE_LOCKING=y
831# CONFIG_FUSE_FS is not set 835# CONFIG_FUSE_FS is not set
832 836
833# 837#
838# Caches
839#
840# CONFIG_FSCACHE is not set
841
842#
834# CD-ROM/DVD Filesystems 843# CD-ROM/DVD Filesystems
835# 844#
836# CONFIG_ISO9660_FS is not set 845# CONFIG_ISO9660_FS is not set
@@ -884,6 +893,7 @@ CONFIG_JFFS2_RTIME=y
884# CONFIG_ROMFS_FS is not set 893# CONFIG_ROMFS_FS is not set
885# CONFIG_SYSV_FS is not set 894# CONFIG_SYSV_FS is not set
886# CONFIG_UFS_FS is not set 895# CONFIG_UFS_FS is not set
896# CONFIG_NILFS2_FS is not set
887CONFIG_NETWORK_FILESYSTEMS=y 897CONFIG_NETWORK_FILESYSTEMS=y
888CONFIG_NFS_FS=y 898CONFIG_NFS_FS=y
889CONFIG_NFS_V3=y 899CONFIG_NFS_V3=y
@@ -965,6 +975,7 @@ CONFIG_MAGIC_SYSRQ=y
965CONFIG_DEBUG_KERNEL=y 975CONFIG_DEBUG_KERNEL=y
966# CONFIG_DEBUG_SHIRQ is not set 976# CONFIG_DEBUG_SHIRQ is not set
967# CONFIG_DETECT_SOFTLOCKUP is not set 977# CONFIG_DETECT_SOFTLOCKUP is not set
978# CONFIG_DETECT_HUNG_TASK is not set
968# CONFIG_SCHED_DEBUG is not set 979# CONFIG_SCHED_DEBUG is not set
969# CONFIG_SCHEDSTATS is not set 980# CONFIG_SCHEDSTATS is not set
970# CONFIG_TIMER_STATS is not set 981# CONFIG_TIMER_STATS is not set
@@ -1000,6 +1011,7 @@ CONFIG_SYSCTL_SYSCALL_CHECK=y
1000CONFIG_HAVE_FUNCTION_TRACER=y 1011CONFIG_HAVE_FUNCTION_TRACER=y
1001CONFIG_HAVE_DYNAMIC_FTRACE=y 1012CONFIG_HAVE_DYNAMIC_FTRACE=y
1002CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1013CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1014CONFIG_TRACING_SUPPORT=y
1003 1015
1004# 1016#
1005# Tracers 1017# Tracers
@@ -1008,9 +1020,14 @@ CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1008# CONFIG_IRQSOFF_TRACER is not set 1020# CONFIG_IRQSOFF_TRACER is not set
1009# CONFIG_SCHED_TRACER is not set 1021# CONFIG_SCHED_TRACER is not set
1010# CONFIG_CONTEXT_SWITCH_TRACER is not set 1022# CONFIG_CONTEXT_SWITCH_TRACER is not set
1023# CONFIG_EVENT_TRACER is not set
1011# CONFIG_BOOT_TRACER is not set 1024# CONFIG_BOOT_TRACER is not set
1012# CONFIG_TRACE_BRANCH_PROFILING is not set 1025# CONFIG_TRACE_BRANCH_PROFILING is not set
1013# CONFIG_STACK_TRACER is not set 1026# CONFIG_STACK_TRACER is not set
1027# CONFIG_KMEMTRACE is not set
1028# CONFIG_WORKQUEUE_TRACER is not set
1029# CONFIG_BLK_DEV_IO_TRACE is not set
1030# CONFIG_DMA_API_DEBUG is not set
1014# CONFIG_SAMPLES is not set 1031# CONFIG_SAMPLES is not set
1015CONFIG_HAVE_ARCH_KGDB=y 1032CONFIG_HAVE_ARCH_KGDB=y
1016# CONFIG_KGDB is not set 1033# CONFIG_KGDB is not set
@@ -1035,6 +1052,7 @@ CONFIG_DUMP_CODE=y
1035# CONFIG_SECURITYFS is not set 1052# CONFIG_SECURITYFS is not set
1036# CONFIG_SECURITY_FILE_CAPABILITIES is not set 1053# CONFIG_SECURITY_FILE_CAPABILITIES is not set
1037# CONFIG_CRYPTO is not set 1054# CONFIG_CRYPTO is not set
1055# CONFIG_BINARY_PRINTF is not set
1038 1056
1039# 1057#
1040# Library routines 1058# Library routines
diff --git a/arch/sh/configs/microdev_defconfig b/arch/sh/configs/microdev_defconfig
index 75178355d69a..2886fc84bc1c 100644
--- a/arch/sh/configs/microdev_defconfig
+++ b/arch/sh/configs/microdev_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:11:13 2009 4# Mon Apr 27 12:50:51 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -65,7 +66,6 @@ CONFIG_INITRAMFS_SOURCE=""
65CONFIG_RD_GZIP=y 66CONFIG_RD_GZIP=y
66# CONFIG_RD_BZIP2 is not set 67# CONFIG_RD_BZIP2 is not set
67# CONFIG_RD_LZMA is not set 68# CONFIG_RD_LZMA is not set
68CONFIG_INITRAMFS_COMPRESSION_NONE=y
69# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set 69# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
70CONFIG_SYSCTL=y 70CONFIG_SYSCTL=y
71CONFIG_ANON_INODES=y 71CONFIG_ANON_INODES=y
@@ -74,6 +74,7 @@ CONFIG_UID16=y
74# CONFIG_SYSCTL_SYSCALL is not set 74# CONFIG_SYSCTL_SYSCALL is not set
75CONFIG_KALLSYMS=y 75CONFIG_KALLSYMS=y
76# CONFIG_KALLSYMS_EXTRA_PASS is not set 76# CONFIG_KALLSYMS_EXTRA_PASS is not set
77# CONFIG_STRIP_ASM_SYMS is not set
77CONFIG_HOTPLUG=y 78CONFIG_HOTPLUG=y
78CONFIG_PRINTK=y 79CONFIG_PRINTK=y
79CONFIG_BUG=y 80CONFIG_BUG=y
@@ -92,12 +93,15 @@ CONFIG_SLAB=y
92# CONFIG_SLUB is not set 93# CONFIG_SLUB is not set
93# CONFIG_SLOB is not set 94# CONFIG_SLOB is not set
94# CONFIG_PROFILING is not set 95# CONFIG_PROFILING is not set
96# CONFIG_MARKERS is not set
95CONFIG_HAVE_OPROFILE=y 97CONFIG_HAVE_OPROFILE=y
96CONFIG_HAVE_IOREMAP_PROT=y 98CONFIG_HAVE_IOREMAP_PROT=y
97CONFIG_HAVE_KPROBES=y 99CONFIG_HAVE_KPROBES=y
98CONFIG_HAVE_KRETPROBES=y 100CONFIG_HAVE_KRETPROBES=y
99CONFIG_HAVE_ARCH_TRACEHOOK=y 101CONFIG_HAVE_ARCH_TRACEHOOK=y
100CONFIG_HAVE_CLK=y 102CONFIG_HAVE_CLK=y
103CONFIG_HAVE_DMA_API_DEBUG=y
104# CONFIG_SLOW_WORK is not set
101CONFIG_HAVE_GENERIC_DMA_COHERENT=y 105CONFIG_HAVE_GENERIC_DMA_COHERENT=y
102CONFIG_SLABINFO=y 106CONFIG_SLABINFO=y
103CONFIG_RT_MUTEXES=y 107CONFIG_RT_MUTEXES=y
@@ -105,7 +109,6 @@ CONFIG_BASE_SMALL=0
105# CONFIG_MODULES is not set 109# CONFIG_MODULES is not set
106CONFIG_BLOCK=y 110CONFIG_BLOCK=y
107# CONFIG_LBD is not set 111# CONFIG_LBD is not set
108# CONFIG_BLK_DEV_IO_TRACE is not set
109# CONFIG_BLK_DEV_BSG is not set 112# CONFIG_BLK_DEV_BSG is not set
110# CONFIG_BLK_DEV_INTEGRITY is not set 113# CONFIG_BLK_DEV_INTEGRITY is not set
111 114
@@ -151,6 +154,7 @@ CONFIG_CPU_SH4=y
151# CONFIG_CPU_SUBTYPE_SH7760 is not set 154# CONFIG_CPU_SUBTYPE_SH7760 is not set
152CONFIG_CPU_SUBTYPE_SH4_202=y 155CONFIG_CPU_SUBTYPE_SH4_202=y
153# CONFIG_CPU_SUBTYPE_SH7723 is not set 156# CONFIG_CPU_SUBTYPE_SH7723 is not set
157# CONFIG_CPU_SUBTYPE_SH7724 is not set
154# CONFIG_CPU_SUBTYPE_SH7763 is not set 158# CONFIG_CPU_SUBTYPE_SH7763 is not set
155# CONFIG_CPU_SUBTYPE_SH7770 is not set 159# CONFIG_CPU_SUBTYPE_SH7770 is not set
156# CONFIG_CPU_SUBTYPE_SH7780 is not set 160# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -160,8 +164,6 @@ CONFIG_CPU_SUBTYPE_SH4_202=y
160# CONFIG_CPU_SUBTYPE_SH7343 is not set 164# CONFIG_CPU_SUBTYPE_SH7343 is not set
161# CONFIG_CPU_SUBTYPE_SH7722 is not set 165# CONFIG_CPU_SUBTYPE_SH7722 is not set
162# CONFIG_CPU_SUBTYPE_SH7366 is not set 166# CONFIG_CPU_SUBTYPE_SH7366 is not set
163# CONFIG_CPU_SUBTYPE_SH5_101 is not set
164# CONFIG_CPU_SUBTYPE_SH5_103 is not set
165 167
166# 168#
167# Memory management options 169# Memory management options
@@ -647,6 +649,7 @@ CONFIG_EXT2_FS=y
647# CONFIG_EXT2_FS_XATTR is not set 649# CONFIG_EXT2_FS_XATTR is not set
648# CONFIG_EXT2_FS_XIP is not set 650# CONFIG_EXT2_FS_XIP is not set
649CONFIG_EXT3_FS=y 651CONFIG_EXT3_FS=y
652# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
650CONFIG_EXT3_FS_XATTR=y 653CONFIG_EXT3_FS_XATTR=y
651# CONFIG_EXT3_FS_POSIX_ACL is not set 654# CONFIG_EXT3_FS_POSIX_ACL is not set
652# CONFIG_EXT3_FS_SECURITY is not set 655# CONFIG_EXT3_FS_SECURITY is not set
@@ -669,6 +672,11 @@ CONFIG_INOTIFY_USER=y
669# CONFIG_FUSE_FS is not set 672# CONFIG_FUSE_FS is not set
670 673
671# 674#
675# Caches
676#
677# CONFIG_FSCACHE is not set
678
679#
672# CD-ROM/DVD Filesystems 680# CD-ROM/DVD Filesystems
673# 681#
674# CONFIG_ISO9660_FS is not set 682# CONFIG_ISO9660_FS is not set
@@ -715,6 +723,7 @@ CONFIG_MISC_FILESYSTEMS=y
715# CONFIG_ROMFS_FS is not set 723# CONFIG_ROMFS_FS is not set
716# CONFIG_SYSV_FS is not set 724# CONFIG_SYSV_FS is not set
717# CONFIG_UFS_FS is not set 725# CONFIG_UFS_FS is not set
726# CONFIG_NILFS2_FS is not set
718CONFIG_NETWORK_FILESYSTEMS=y 727CONFIG_NETWORK_FILESYSTEMS=y
719CONFIG_NFS_FS=y 728CONFIG_NFS_FS=y
720CONFIG_NFS_V3=y 729CONFIG_NFS_V3=y
@@ -802,10 +811,24 @@ CONFIG_FRAME_WARN=1024
802CONFIG_HAVE_FUNCTION_TRACER=y 811CONFIG_HAVE_FUNCTION_TRACER=y
803CONFIG_HAVE_DYNAMIC_FTRACE=y 812CONFIG_HAVE_DYNAMIC_FTRACE=y
804CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 813CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
814CONFIG_TRACING_SUPPORT=y
805 815
806# 816#
807# Tracers 817# Tracers
808# 818#
819# CONFIG_FUNCTION_TRACER is not set
820# CONFIG_IRQSOFF_TRACER is not set
821# CONFIG_PREEMPT_TRACER is not set
822# CONFIG_SCHED_TRACER is not set
823# CONFIG_CONTEXT_SWITCH_TRACER is not set
824# CONFIG_EVENT_TRACER is not set
825# CONFIG_BOOT_TRACER is not set
826# CONFIG_TRACE_BRANCH_PROFILING is not set
827# CONFIG_STACK_TRACER is not set
828# CONFIG_KMEMTRACE is not set
829# CONFIG_WORKQUEUE_TRACER is not set
830# CONFIG_BLK_DEV_IO_TRACE is not set
831# CONFIG_DMA_API_DEBUG is not set
809# CONFIG_SAMPLES is not set 832# CONFIG_SAMPLES is not set
810CONFIG_HAVE_ARCH_KGDB=y 833CONFIG_HAVE_ARCH_KGDB=y
811# CONFIG_SH_STANDARD_BIOS is not set 834# CONFIG_SH_STANDARD_BIOS is not set
@@ -914,6 +937,7 @@ CONFIG_CRYPTO_DES=y
914# 937#
915# CONFIG_CRYPTO_ANSI_CPRNG is not set 938# CONFIG_CRYPTO_ANSI_CPRNG is not set
916CONFIG_CRYPTO_HW=y 939CONFIG_CRYPTO_HW=y
940# CONFIG_BINARY_PRINTF is not set
917 941
918# 942#
919# Library routines 943# Library routines
diff --git a/arch/sh/configs/migor_defconfig b/arch/sh/configs/migor_defconfig
index a8720f9c6047..8ecceb4bf27e 100644
--- a/arch/sh/configs/migor_defconfig
+++ b/arch/sh/configs/migor_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:14:03 2009 4# Mon Apr 27 12:51:34 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -67,7 +68,6 @@ CONFIG_INITRAMFS_SOURCE=""
67CONFIG_RD_GZIP=y 68CONFIG_RD_GZIP=y
68# CONFIG_RD_BZIP2 is not set 69# CONFIG_RD_BZIP2 is not set
69# CONFIG_RD_LZMA is not set 70# CONFIG_RD_LZMA is not set
70CONFIG_INITRAMFS_COMPRESSION_NONE=y
71# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set 71# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
72CONFIG_SYSCTL=y 72CONFIG_SYSCTL=y
73CONFIG_ANON_INODES=y 73CONFIG_ANON_INODES=y
@@ -76,6 +76,7 @@ CONFIG_UID16=y
76# CONFIG_SYSCTL_SYSCALL is not set 76# CONFIG_SYSCTL_SYSCALL is not set
77CONFIG_KALLSYMS=y 77CONFIG_KALLSYMS=y
78# CONFIG_KALLSYMS_EXTRA_PASS is not set 78# CONFIG_KALLSYMS_EXTRA_PASS is not set
79# CONFIG_STRIP_ASM_SYMS is not set
79CONFIG_HOTPLUG=y 80CONFIG_HOTPLUG=y
80CONFIG_PRINTK=y 81CONFIG_PRINTK=y
81CONFIG_BUG=y 82CONFIG_BUG=y
@@ -104,6 +105,8 @@ CONFIG_HAVE_KPROBES=y
104CONFIG_HAVE_KRETPROBES=y 105CONFIG_HAVE_KRETPROBES=y
105CONFIG_HAVE_ARCH_TRACEHOOK=y 106CONFIG_HAVE_ARCH_TRACEHOOK=y
106CONFIG_HAVE_CLK=y 107CONFIG_HAVE_CLK=y
108CONFIG_HAVE_DMA_API_DEBUG=y
109# CONFIG_SLOW_WORK is not set
107CONFIG_HAVE_GENERIC_DMA_COHERENT=y 110CONFIG_HAVE_GENERIC_DMA_COHERENT=y
108CONFIG_SLABINFO=y 111CONFIG_SLABINFO=y
109CONFIG_RT_MUTEXES=y 112CONFIG_RT_MUTEXES=y
@@ -115,7 +118,6 @@ CONFIG_MODULES=y
115# CONFIG_MODULE_SRCVERSION_ALL is not set 118# CONFIG_MODULE_SRCVERSION_ALL is not set
116CONFIG_BLOCK=y 119CONFIG_BLOCK=y
117# CONFIG_LBD is not set 120# CONFIG_LBD is not set
118# CONFIG_BLK_DEV_IO_TRACE is not set
119# CONFIG_BLK_DEV_BSG is not set 121# CONFIG_BLK_DEV_BSG is not set
120# CONFIG_BLK_DEV_INTEGRITY is not set 122# CONFIG_BLK_DEV_INTEGRITY is not set
121 123
@@ -165,6 +167,7 @@ CONFIG_ARCH_SHMOBILE=y
165# CONFIG_CPU_SUBTYPE_SH7760 is not set 167# CONFIG_CPU_SUBTYPE_SH7760 is not set
166# CONFIG_CPU_SUBTYPE_SH4_202 is not set 168# CONFIG_CPU_SUBTYPE_SH4_202 is not set
167# CONFIG_CPU_SUBTYPE_SH7723 is not set 169# CONFIG_CPU_SUBTYPE_SH7723 is not set
170# CONFIG_CPU_SUBTYPE_SH7724 is not set
168# CONFIG_CPU_SUBTYPE_SH7763 is not set 171# CONFIG_CPU_SUBTYPE_SH7763 is not set
169# CONFIG_CPU_SUBTYPE_SH7770 is not set 172# CONFIG_CPU_SUBTYPE_SH7770 is not set
170# CONFIG_CPU_SUBTYPE_SH7780 is not set 173# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -174,8 +177,6 @@ CONFIG_ARCH_SHMOBILE=y
174# CONFIG_CPU_SUBTYPE_SH7343 is not set 177# CONFIG_CPU_SUBTYPE_SH7343 is not set
175CONFIG_CPU_SUBTYPE_SH7722=y 178CONFIG_CPU_SUBTYPE_SH7722=y
176# CONFIG_CPU_SUBTYPE_SH7366 is not set 179# CONFIG_CPU_SUBTYPE_SH7366 is not set
177# CONFIG_CPU_SUBTYPE_SH5_101 is not set
178# CONFIG_CPU_SUBTYPE_SH5_103 is not set
179 180
180# 181#
181# Memory management options 182# Memory management options
@@ -577,6 +578,7 @@ CONFIG_SCSI_WAIT_SCAN=m
577CONFIG_SCSI_LOWLEVEL=y 578CONFIG_SCSI_LOWLEVEL=y
578# CONFIG_ISCSI_TCP is not set 579# CONFIG_ISCSI_TCP is not set
579# CONFIG_LIBFC is not set 580# CONFIG_LIBFC is not set
581# CONFIG_LIBFCOE is not set
580# CONFIG_SCSI_DEBUG is not set 582# CONFIG_SCSI_DEBUG is not set
581# CONFIG_SCSI_DH is not set 583# CONFIG_SCSI_DH is not set
582# CONFIG_SCSI_OSD_INITIATOR is not set 584# CONFIG_SCSI_OSD_INITIATOR is not set
@@ -873,7 +875,6 @@ CONFIG_HID=y
873# 875#
874# Special HID drivers 876# Special HID drivers
875# 877#
876CONFIG_HID_COMPAT=y
877CONFIG_USB_SUPPORT=y 878CONFIG_USB_SUPPORT=y
878CONFIG_USB_ARCH_HAS_HCD=y 879CONFIG_USB_ARCH_HAS_HCD=y
879# CONFIG_USB_ARCH_HAS_OHCI is not set 880# CONFIG_USB_ARCH_HAS_OHCI is not set
@@ -1012,6 +1013,11 @@ CONFIG_FILE_LOCKING=y
1012# CONFIG_FUSE_FS is not set 1013# CONFIG_FUSE_FS is not set
1013 1014
1014# 1015#
1016# Caches
1017#
1018# CONFIG_FSCACHE is not set
1019
1020#
1015# CD-ROM/DVD Filesystems 1021# CD-ROM/DVD Filesystems
1016# 1022#
1017# CONFIG_ISO9660_FS is not set 1023# CONFIG_ISO9660_FS is not set
@@ -1056,6 +1062,7 @@ CONFIG_MISC_FILESYSTEMS=y
1056# CONFIG_ROMFS_FS is not set 1062# CONFIG_ROMFS_FS is not set
1057# CONFIG_SYSV_FS is not set 1063# CONFIG_SYSV_FS is not set
1058# CONFIG_UFS_FS is not set 1064# CONFIG_UFS_FS is not set
1065# CONFIG_NILFS2_FS is not set
1059CONFIG_NETWORK_FILESYSTEMS=y 1066CONFIG_NETWORK_FILESYSTEMS=y
1060CONFIG_NFS_FS=y 1067CONFIG_NFS_FS=y
1061# CONFIG_NFS_V3 is not set 1068# CONFIG_NFS_V3 is not set
@@ -1105,11 +1112,25 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
1105CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1112CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1106CONFIG_RING_BUFFER=y 1113CONFIG_RING_BUFFER=y
1107CONFIG_TRACING=y 1114CONFIG_TRACING=y
1115CONFIG_TRACING_SUPPORT=y
1108 1116
1109# 1117#
1110# Tracers 1118# Tracers
1111# 1119#
1120# CONFIG_FUNCTION_TRACER is not set
1121# CONFIG_IRQSOFF_TRACER is not set
1122# CONFIG_SCHED_TRACER is not set
1123# CONFIG_CONTEXT_SWITCH_TRACER is not set
1124# CONFIG_EVENT_TRACER is not set
1125# CONFIG_BOOT_TRACER is not set
1126# CONFIG_TRACE_BRANCH_PROFILING is not set
1127# CONFIG_STACK_TRACER is not set
1128# CONFIG_KMEMTRACE is not set
1129# CONFIG_WORKQUEUE_TRACER is not set
1130# CONFIG_BLK_DEV_IO_TRACE is not set
1131# CONFIG_FTRACE_STARTUP_TEST is not set
1112# CONFIG_DYNAMIC_DEBUG is not set 1132# CONFIG_DYNAMIC_DEBUG is not set
1133# CONFIG_DMA_API_DEBUG is not set
1113# CONFIG_SAMPLES is not set 1134# CONFIG_SAMPLES is not set
1114CONFIG_HAVE_ARCH_KGDB=y 1135CONFIG_HAVE_ARCH_KGDB=y
1115# CONFIG_SH_STANDARD_BIOS is not set 1136# CONFIG_SH_STANDARD_BIOS is not set
@@ -1218,6 +1239,7 @@ CONFIG_CRYPTO_WORKQUEUE=y
1218# 1239#
1219# CONFIG_CRYPTO_ANSI_CPRNG is not set 1240# CONFIG_CRYPTO_ANSI_CPRNG is not set
1220# CONFIG_CRYPTO_HW is not set 1241# CONFIG_CRYPTO_HW is not set
1242CONFIG_BINARY_PRINTF=y
1221 1243
1222# 1244#
1223# Library routines 1245# Library routines
diff --git a/arch/sh/configs/polaris_defconfig b/arch/sh/configs/polaris_defconfig
index df2d177d5346..2b9507286182 100644
--- a/arch/sh/configs/polaris_defconfig
+++ b/arch/sh/configs/polaris_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:16:48 2009 4# Mon Apr 27 12:52:19 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -40,6 +41,7 @@ CONFIG_LOCALVERSION=""
40CONFIG_SYSVIPC=y 41CONFIG_SYSVIPC=y
41CONFIG_SYSVIPC_SYSCTL=y 42CONFIG_SYSVIPC_SYSCTL=y
42CONFIG_POSIX_MQUEUE=y 43CONFIG_POSIX_MQUEUE=y
44CONFIG_POSIX_MQUEUE_SYSCTL=y
43CONFIG_BSD_PROCESS_ACCT=y 45CONFIG_BSD_PROCESS_ACCT=y
44CONFIG_BSD_PROCESS_ACCT_V3=y 46CONFIG_BSD_PROCESS_ACCT_V3=y
45# CONFIG_TASKSTATS is not set 47# CONFIG_TASKSTATS is not set
@@ -76,6 +78,7 @@ CONFIG_SYSCTL_SYSCALL=y
76CONFIG_KALLSYMS=y 78CONFIG_KALLSYMS=y
77CONFIG_KALLSYMS_ALL=y 79CONFIG_KALLSYMS_ALL=y
78# CONFIG_KALLSYMS_EXTRA_PASS is not set 80# CONFIG_KALLSYMS_EXTRA_PASS is not set
81# CONFIG_STRIP_ASM_SYMS is not set
79CONFIG_HOTPLUG=y 82CONFIG_HOTPLUG=y
80CONFIG_PRINTK=y 83CONFIG_PRINTK=y
81CONFIG_BUG=y 84CONFIG_BUG=y
@@ -94,6 +97,7 @@ CONFIG_SLAB=y
94# CONFIG_SLUB is not set 97# CONFIG_SLUB is not set
95# CONFIG_SLOB is not set 98# CONFIG_SLOB is not set
96# CONFIG_PROFILING is not set 99# CONFIG_PROFILING is not set
100# CONFIG_MARKERS is not set
97CONFIG_HAVE_OPROFILE=y 101CONFIG_HAVE_OPROFILE=y
98# CONFIG_KPROBES is not set 102# CONFIG_KPROBES is not set
99CONFIG_HAVE_IOREMAP_PROT=y 103CONFIG_HAVE_IOREMAP_PROT=y
@@ -101,6 +105,8 @@ CONFIG_HAVE_KPROBES=y
101CONFIG_HAVE_KRETPROBES=y 105CONFIG_HAVE_KRETPROBES=y
102CONFIG_HAVE_ARCH_TRACEHOOK=y 106CONFIG_HAVE_ARCH_TRACEHOOK=y
103CONFIG_HAVE_CLK=y 107CONFIG_HAVE_CLK=y
108CONFIG_HAVE_DMA_API_DEBUG=y
109# CONFIG_SLOW_WORK is not set
104CONFIG_HAVE_GENERIC_DMA_COHERENT=y 110CONFIG_HAVE_GENERIC_DMA_COHERENT=y
105CONFIG_SLABINFO=y 111CONFIG_SLABINFO=y
106CONFIG_RT_MUTEXES=y 112CONFIG_RT_MUTEXES=y
@@ -113,7 +119,6 @@ CONFIG_MODVERSIONS=y
113# CONFIG_MODULE_SRCVERSION_ALL is not set 119# CONFIG_MODULE_SRCVERSION_ALL is not set
114CONFIG_BLOCK=y 120CONFIG_BLOCK=y
115# CONFIG_LBD is not set 121# CONFIG_LBD is not set
116# CONFIG_BLK_DEV_IO_TRACE is not set
117# CONFIG_BLK_DEV_BSG is not set 122# CONFIG_BLK_DEV_BSG is not set
118# CONFIG_BLK_DEV_INTEGRITY is not set 123# CONFIG_BLK_DEV_INTEGRITY is not set
119 124
@@ -159,6 +164,7 @@ CONFIG_CPU_SUBTYPE_SH7709=y
159# CONFIG_CPU_SUBTYPE_SH7760 is not set 164# CONFIG_CPU_SUBTYPE_SH7760 is not set
160# CONFIG_CPU_SUBTYPE_SH4_202 is not set 165# CONFIG_CPU_SUBTYPE_SH4_202 is not set
161# CONFIG_CPU_SUBTYPE_SH7723 is not set 166# CONFIG_CPU_SUBTYPE_SH7723 is not set
167# CONFIG_CPU_SUBTYPE_SH7724 is not set
162# CONFIG_CPU_SUBTYPE_SH7763 is not set 168# CONFIG_CPU_SUBTYPE_SH7763 is not set
163# CONFIG_CPU_SUBTYPE_SH7770 is not set 169# CONFIG_CPU_SUBTYPE_SH7770 is not set
164# CONFIG_CPU_SUBTYPE_SH7780 is not set 170# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -168,8 +174,6 @@ CONFIG_CPU_SUBTYPE_SH7709=y
168# CONFIG_CPU_SUBTYPE_SH7343 is not set 174# CONFIG_CPU_SUBTYPE_SH7343 is not set
169# CONFIG_CPU_SUBTYPE_SH7722 is not set 175# CONFIG_CPU_SUBTYPE_SH7722 is not set
170# CONFIG_CPU_SUBTYPE_SH7366 is not set 176# CONFIG_CPU_SUBTYPE_SH7366 is not set
171# CONFIG_CPU_SUBTYPE_SH5_101 is not set
172# CONFIG_CPU_SUBTYPE_SH5_103 is not set
173 177
174# 178#
175# Memory management options 179# Memory management options
@@ -778,6 +782,11 @@ CONFIG_FILE_LOCKING=y
778# CONFIG_FUSE_FS is not set 782# CONFIG_FUSE_FS is not set
779 783
780# 784#
785# Caches
786#
787# CONFIG_FSCACHE is not set
788
789#
781# CD-ROM/DVD Filesystems 790# CD-ROM/DVD Filesystems
782# 791#
783# CONFIG_ISO9660_FS is not set 792# CONFIG_ISO9660_FS is not set
@@ -831,6 +840,7 @@ CONFIG_JFFS2_RTIME=y
831# CONFIG_ROMFS_FS is not set 840# CONFIG_ROMFS_FS is not set
832# CONFIG_SYSV_FS is not set 841# CONFIG_SYSV_FS is not set
833# CONFIG_UFS_FS is not set 842# CONFIG_UFS_FS is not set
843# CONFIG_NILFS2_FS is not set
834CONFIG_NETWORK_FILESYSTEMS=y 844CONFIG_NETWORK_FILESYSTEMS=y
835CONFIG_NFS_FS=y 845CONFIG_NFS_FS=y
836CONFIG_NFS_V3=y 846CONFIG_NFS_V3=y
@@ -874,6 +884,9 @@ CONFIG_DEBUG_SHIRQ=y
874CONFIG_DETECT_SOFTLOCKUP=y 884CONFIG_DETECT_SOFTLOCKUP=y
875# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set 885# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
876CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0 886CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
887CONFIG_DETECT_HUNG_TASK=y
888# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
889CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
877# CONFIG_SCHED_DEBUG is not set 890# CONFIG_SCHED_DEBUG is not set
878# CONFIG_SCHEDSTATS is not set 891# CONFIG_SCHEDSTATS is not set
879# CONFIG_TIMER_STATS is not set 892# CONFIG_TIMER_STATS is not set
@@ -914,6 +927,7 @@ CONFIG_SYSCTL_SYSCALL_CHECK=y
914CONFIG_HAVE_FUNCTION_TRACER=y 927CONFIG_HAVE_FUNCTION_TRACER=y
915CONFIG_HAVE_DYNAMIC_FTRACE=y 928CONFIG_HAVE_DYNAMIC_FTRACE=y
916CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 929CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
930CONFIG_TRACING_SUPPORT=y
917 931
918# 932#
919# Tracers 933# Tracers
@@ -923,9 +937,14 @@ CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
923# CONFIG_PREEMPT_TRACER is not set 937# CONFIG_PREEMPT_TRACER is not set
924# CONFIG_SCHED_TRACER is not set 938# CONFIG_SCHED_TRACER is not set
925# CONFIG_CONTEXT_SWITCH_TRACER is not set 939# CONFIG_CONTEXT_SWITCH_TRACER is not set
940# CONFIG_EVENT_TRACER is not set
926# CONFIG_BOOT_TRACER is not set 941# CONFIG_BOOT_TRACER is not set
927# CONFIG_TRACE_BRANCH_PROFILING is not set 942# CONFIG_TRACE_BRANCH_PROFILING is not set
928# CONFIG_STACK_TRACER is not set 943# CONFIG_STACK_TRACER is not set
944# CONFIG_KMEMTRACE is not set
945# CONFIG_WORKQUEUE_TRACER is not set
946# CONFIG_BLK_DEV_IO_TRACE is not set
947# CONFIG_DMA_API_DEBUG is not set
929# CONFIG_SAMPLES is not set 948# CONFIG_SAMPLES is not set
930CONFIG_HAVE_ARCH_KGDB=y 949CONFIG_HAVE_ARCH_KGDB=y
931# CONFIG_KGDB is not set 950# CONFIG_KGDB is not set
@@ -950,6 +969,7 @@ CONFIG_DUMP_CODE=y
950# CONFIG_SECURITYFS is not set 969# CONFIG_SECURITYFS is not set
951# CONFIG_SECURITY_FILE_CAPABILITIES is not set 970# CONFIG_SECURITY_FILE_CAPABILITIES is not set
952# CONFIG_CRYPTO is not set 971# CONFIG_CRYPTO is not set
972# CONFIG_BINARY_PRINTF is not set
953 973
954# 974#
955# Library routines 975# Library routines
diff --git a/arch/sh/configs/r7780mp_defconfig b/arch/sh/configs/r7780mp_defconfig
index 7def4df46ddb..943da63a3852 100644
--- a/arch/sh/configs/r7780mp_defconfig
+++ b/arch/sh/configs/r7780mp_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:20:17 2009 4# Mon Apr 27 12:53:28 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -78,6 +79,7 @@ CONFIG_UID16=y
78CONFIG_KALLSYMS=y 79CONFIG_KALLSYMS=y
79# CONFIG_KALLSYMS_ALL is not set 80# CONFIG_KALLSYMS_ALL is not set
80# CONFIG_KALLSYMS_EXTRA_PASS is not set 81# CONFIG_KALLSYMS_EXTRA_PASS is not set
82# CONFIG_STRIP_ASM_SYMS is not set
81CONFIG_HOTPLUG=y 83CONFIG_HOTPLUG=y
82CONFIG_PRINTK=y 84CONFIG_PRINTK=y
83CONFIG_BUG=y 85CONFIG_BUG=y
@@ -107,6 +109,8 @@ CONFIG_HAVE_KPROBES=y
107CONFIG_HAVE_KRETPROBES=y 109CONFIG_HAVE_KRETPROBES=y
108CONFIG_HAVE_ARCH_TRACEHOOK=y 110CONFIG_HAVE_ARCH_TRACEHOOK=y
109CONFIG_HAVE_CLK=y 111CONFIG_HAVE_CLK=y
112CONFIG_HAVE_DMA_API_DEBUG=y
113# CONFIG_SLOW_WORK is not set
110CONFIG_HAVE_GENERIC_DMA_COHERENT=y 114CONFIG_HAVE_GENERIC_DMA_COHERENT=y
111CONFIG_SLABINFO=y 115CONFIG_SLABINFO=y
112CONFIG_BASE_SMALL=0 116CONFIG_BASE_SMALL=0
@@ -118,7 +122,6 @@ CONFIG_MODULE_UNLOAD=y
118# CONFIG_MODULE_SRCVERSION_ALL is not set 122# CONFIG_MODULE_SRCVERSION_ALL is not set
119CONFIG_BLOCK=y 123CONFIG_BLOCK=y
120# CONFIG_LBD is not set 124# CONFIG_LBD is not set
121# CONFIG_BLK_DEV_IO_TRACE is not set
122# CONFIG_BLK_DEV_BSG is not set 125# CONFIG_BLK_DEV_BSG is not set
123# CONFIG_BLK_DEV_INTEGRITY is not set 126# CONFIG_BLK_DEV_INTEGRITY is not set
124 127
@@ -165,6 +168,7 @@ CONFIG_CPU_SH4A=y
165# CONFIG_CPU_SUBTYPE_SH7760 is not set 168# CONFIG_CPU_SUBTYPE_SH7760 is not set
166# CONFIG_CPU_SUBTYPE_SH4_202 is not set 169# CONFIG_CPU_SUBTYPE_SH4_202 is not set
167# CONFIG_CPU_SUBTYPE_SH7723 is not set 170# CONFIG_CPU_SUBTYPE_SH7723 is not set
171# CONFIG_CPU_SUBTYPE_SH7724 is not set
168# CONFIG_CPU_SUBTYPE_SH7763 is not set 172# CONFIG_CPU_SUBTYPE_SH7763 is not set
169# CONFIG_CPU_SUBTYPE_SH7770 is not set 173# CONFIG_CPU_SUBTYPE_SH7770 is not set
170CONFIG_CPU_SUBTYPE_SH7780=y 174CONFIG_CPU_SUBTYPE_SH7780=y
@@ -174,8 +178,6 @@ CONFIG_CPU_SUBTYPE_SH7780=y
174# CONFIG_CPU_SUBTYPE_SH7343 is not set 178# CONFIG_CPU_SUBTYPE_SH7343 is not set
175# CONFIG_CPU_SUBTYPE_SH7722 is not set 179# CONFIG_CPU_SUBTYPE_SH7722 is not set
176# CONFIG_CPU_SUBTYPE_SH7366 is not set 180# CONFIG_CPU_SUBTYPE_SH7366 is not set
177# CONFIG_CPU_SUBTYPE_SH5_101 is not set
178# CONFIG_CPU_SUBTYPE_SH5_103 is not set
179 181
180# 182#
181# Memory management options 183# Memory management options
@@ -258,7 +260,7 @@ CONFIG_SH_R7780MP=y
258# 260#
259CONFIG_SH_TMU=y 261CONFIG_SH_TMU=y
260CONFIG_SH_TIMER_IRQ=28 262CONFIG_SH_TIMER_IRQ=28
261CONFIG_SH_PCLK_FREQ=32000000 263CONFIG_SH_PCLK_FREQ=33333333
262# CONFIG_NO_HZ is not set 264# CONFIG_NO_HZ is not set
263# CONFIG_HIGH_RES_TIMERS is not set 265# CONFIG_HIGH_RES_TIMERS is not set
264CONFIG_GENERIC_CLOCKEVENTS_BUILD=y 266CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
@@ -313,8 +315,6 @@ CONFIG_CMDLINE="console=ttySC0,115200 root=/dev/sda1"
313# 315#
314CONFIG_PCI=y 316CONFIG_PCI=y
315CONFIG_SH_PCIDMA_NONCOHERENT=y 317CONFIG_SH_PCIDMA_NONCOHERENT=y
316CONFIG_PCI_AUTO=y
317CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
318# CONFIG_PCIEPORTBUS is not set 318# CONFIG_PCIEPORTBUS is not set
319# CONFIG_ARCH_SUPPORTS_MSI is not set 319# CONFIG_ARCH_SUPPORTS_MSI is not set
320CONFIG_PCI_LEGACY=y 320CONFIG_PCI_LEGACY=y
@@ -536,6 +536,7 @@ CONFIG_SCSI_LOWLEVEL=y
536# CONFIG_SCSI_MPT2SAS is not set 536# CONFIG_SCSI_MPT2SAS is not set
537# CONFIG_SCSI_HPTIOP is not set 537# CONFIG_SCSI_HPTIOP is not set
538# CONFIG_LIBFC is not set 538# CONFIG_LIBFC is not set
539# CONFIG_LIBFCOE is not set
539# CONFIG_FCOE is not set 540# CONFIG_FCOE is not set
540# CONFIG_SCSI_DMX3191D is not set 541# CONFIG_SCSI_DMX3191D is not set
541# CONFIG_SCSI_FUTURE_DOMAIN is not set 542# CONFIG_SCSI_FUTURE_DOMAIN is not set
@@ -696,6 +697,7 @@ CONFIG_E1000=m
696# CONFIG_E1000E is not set 697# CONFIG_E1000E is not set
697# CONFIG_IP1000 is not set 698# CONFIG_IP1000 is not set
698# CONFIG_IGB is not set 699# CONFIG_IGB is not set
700# CONFIG_IGBVF is not set
699# CONFIG_NS83820 is not set 701# CONFIG_NS83820 is not set
700# CONFIG_HAMACHI is not set 702# CONFIG_HAMACHI is not set
701# CONFIG_YELLOWFIN is not set 703# CONFIG_YELLOWFIN is not set
@@ -719,6 +721,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
719# CONFIG_IXGBE is not set 721# CONFIG_IXGBE is not set
720# CONFIG_IXGB is not set 722# CONFIG_IXGB is not set
721# CONFIG_S2IO is not set 723# CONFIG_S2IO is not set
724# CONFIG_VXGE is not set
722# CONFIG_MYRI10GE is not set 725# CONFIG_MYRI10GE is not set
723# CONFIG_NETXEN_NIC is not set 726# CONFIG_NETXEN_NIC is not set
724# CONFIG_NIU is not set 727# CONFIG_NIU is not set
@@ -920,6 +923,7 @@ CONFIG_HWMON=y
920# CONFIG_SENSORS_F71805F is not set 923# CONFIG_SENSORS_F71805F is not set
921# CONFIG_SENSORS_F71882FG is not set 924# CONFIG_SENSORS_F71882FG is not set
922# CONFIG_SENSORS_F75375S is not set 925# CONFIG_SENSORS_F75375S is not set
926# CONFIG_SENSORS_G760A is not set
923# CONFIG_SENSORS_GL518SM is not set 927# CONFIG_SENSORS_GL518SM is not set
924# CONFIG_SENSORS_GL520SM is not set 928# CONFIG_SENSORS_GL520SM is not set
925# CONFIG_SENSORS_IT87 is not set 929# CONFIG_SENSORS_IT87 is not set
@@ -1027,7 +1031,6 @@ CONFIG_HID=y
1027# 1031#
1028# Special HID drivers 1032# Special HID drivers
1029# 1033#
1030CONFIG_HID_COMPAT=y
1031CONFIG_USB_SUPPORT=y 1034CONFIG_USB_SUPPORT=y
1032CONFIG_USB_ARCH_HAS_HCD=y 1035CONFIG_USB_ARCH_HAS_HCD=y
1033CONFIG_USB_ARCH_HAS_OHCI=y 1036CONFIG_USB_ARCH_HAS_OHCI=y
@@ -1120,6 +1123,7 @@ CONFIG_EXT2_FS=y
1120# CONFIG_EXT2_FS_XATTR is not set 1123# CONFIG_EXT2_FS_XATTR is not set
1121# CONFIG_EXT2_FS_XIP is not set 1124# CONFIG_EXT2_FS_XIP is not set
1122CONFIG_EXT3_FS=y 1125CONFIG_EXT3_FS=y
1126# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
1123CONFIG_EXT3_FS_XATTR=y 1127CONFIG_EXT3_FS_XATTR=y
1124# CONFIG_EXT3_FS_POSIX_ACL is not set 1128# CONFIG_EXT3_FS_POSIX_ACL is not set
1125# CONFIG_EXT3_FS_SECURITY is not set 1129# CONFIG_EXT3_FS_SECURITY is not set
@@ -1143,6 +1147,11 @@ CONFIG_INOTIFY_USER=y
1143CONFIG_FUSE_FS=m 1147CONFIG_FUSE_FS=m
1144 1148
1145# 1149#
1150# Caches
1151#
1152# CONFIG_FSCACHE is not set
1153
1154#
1146# CD-ROM/DVD Filesystems 1155# CD-ROM/DVD Filesystems
1147# 1156#
1148# CONFIG_ISO9660_FS is not set 1157# CONFIG_ISO9660_FS is not set
@@ -1191,6 +1200,7 @@ CONFIG_MINIX_FS=y
1191# CONFIG_ROMFS_FS is not set 1200# CONFIG_ROMFS_FS is not set
1192# CONFIG_SYSV_FS is not set 1201# CONFIG_SYSV_FS is not set
1193# CONFIG_UFS_FS is not set 1202# CONFIG_UFS_FS is not set
1203# CONFIG_NILFS2_FS is not set
1194CONFIG_NETWORK_FILESYSTEMS=y 1204CONFIG_NETWORK_FILESYSTEMS=y
1195CONFIG_NFS_FS=y 1205CONFIG_NFS_FS=y
1196CONFIG_NFS_V3=y 1206CONFIG_NFS_V3=y
@@ -1279,6 +1289,9 @@ CONFIG_DEBUG_KERNEL=y
1279CONFIG_DETECT_SOFTLOCKUP=y 1289CONFIG_DETECT_SOFTLOCKUP=y
1280# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set 1290# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
1281CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0 1291CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
1292CONFIG_DETECT_HUNG_TASK=y
1293# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
1294CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
1282CONFIG_SCHED_DEBUG=y 1295CONFIG_SCHED_DEBUG=y
1283# CONFIG_SCHEDSTATS is not set 1296# CONFIG_SCHEDSTATS is not set
1284# CONFIG_TIMER_STATS is not set 1297# CONFIG_TIMER_STATS is not set
@@ -1316,6 +1329,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
1316CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1329CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1317CONFIG_RING_BUFFER=y 1330CONFIG_RING_BUFFER=y
1318CONFIG_TRACING=y 1331CONFIG_TRACING=y
1332CONFIG_TRACING_SUPPORT=y
1319 1333
1320# 1334#
1321# Tracers 1335# Tracers
@@ -1325,11 +1339,16 @@ CONFIG_TRACING=y
1325# CONFIG_PREEMPT_TRACER is not set 1339# CONFIG_PREEMPT_TRACER is not set
1326# CONFIG_SCHED_TRACER is not set 1340# CONFIG_SCHED_TRACER is not set
1327# CONFIG_CONTEXT_SWITCH_TRACER is not set 1341# CONFIG_CONTEXT_SWITCH_TRACER is not set
1342# CONFIG_EVENT_TRACER is not set
1328# CONFIG_BOOT_TRACER is not set 1343# CONFIG_BOOT_TRACER is not set
1329# CONFIG_TRACE_BRANCH_PROFILING is not set 1344# CONFIG_TRACE_BRANCH_PROFILING is not set
1330# CONFIG_STACK_TRACER is not set 1345# CONFIG_STACK_TRACER is not set
1346# CONFIG_KMEMTRACE is not set
1347# CONFIG_WORKQUEUE_TRACER is not set
1348# CONFIG_BLK_DEV_IO_TRACE is not set
1331# CONFIG_FTRACE_STARTUP_TEST is not set 1349# CONFIG_FTRACE_STARTUP_TEST is not set
1332# CONFIG_DYNAMIC_DEBUG is not set 1350# CONFIG_DYNAMIC_DEBUG is not set
1351# CONFIG_DMA_API_DEBUG is not set
1333# CONFIG_SAMPLES is not set 1352# CONFIG_SAMPLES is not set
1334CONFIG_HAVE_ARCH_KGDB=y 1353CONFIG_HAVE_ARCH_KGDB=y
1335# CONFIG_KGDB is not set 1354# CONFIG_KGDB is not set
@@ -1449,6 +1468,7 @@ CONFIG_CRYPTO_DES=y
1449# CONFIG_CRYPTO_ANSI_CPRNG is not set 1468# CONFIG_CRYPTO_ANSI_CPRNG is not set
1450CONFIG_CRYPTO_HW=y 1469CONFIG_CRYPTO_HW=y
1451# CONFIG_CRYPTO_DEV_HIFN_795X is not set 1470# CONFIG_CRYPTO_DEV_HIFN_795X is not set
1471CONFIG_BINARY_PRINTF=y
1452 1472
1453# 1473#
1454# Library routines 1474# Library routines
diff --git a/arch/sh/configs/r7785rp_defconfig b/arch/sh/configs/r7785rp_defconfig
index cb134ffc2118..82658f672398 100644
--- a/arch/sh/configs/r7785rp_defconfig
+++ b/arch/sh/configs/r7785rp_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:24:35 2009 4# Mon Apr 27 12:55:10 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -43,6 +44,7 @@ CONFIG_SWAP=y
43CONFIG_SYSVIPC=y 44CONFIG_SYSVIPC=y
44CONFIG_SYSVIPC_SYSCTL=y 45CONFIG_SYSVIPC_SYSCTL=y
45CONFIG_POSIX_MQUEUE=y 46CONFIG_POSIX_MQUEUE=y
47CONFIG_POSIX_MQUEUE_SYSCTL=y
46CONFIG_BSD_PROCESS_ACCT=y 48CONFIG_BSD_PROCESS_ACCT=y
47# CONFIG_BSD_PROCESS_ACCT_V3 is not set 49# CONFIG_BSD_PROCESS_ACCT_V3 is not set
48# CONFIG_TASKSTATS is not set 50# CONFIG_TASKSTATS is not set
@@ -78,6 +80,7 @@ CONFIG_UID16=y
78CONFIG_KALLSYMS=y 80CONFIG_KALLSYMS=y
79CONFIG_KALLSYMS_ALL=y 81CONFIG_KALLSYMS_ALL=y
80# CONFIG_KALLSYMS_EXTRA_PASS is not set 82# CONFIG_KALLSYMS_EXTRA_PASS is not set
83# CONFIG_STRIP_ASM_SYMS is not set
81CONFIG_HOTPLUG=y 84CONFIG_HOTPLUG=y
82CONFIG_PRINTK=y 85CONFIG_PRINTK=y
83CONFIG_BUG=y 86CONFIG_BUG=y
@@ -108,6 +111,8 @@ CONFIG_HAVE_KPROBES=y
108CONFIG_HAVE_KRETPROBES=y 111CONFIG_HAVE_KRETPROBES=y
109CONFIG_HAVE_ARCH_TRACEHOOK=y 112CONFIG_HAVE_ARCH_TRACEHOOK=y
110CONFIG_HAVE_CLK=y 113CONFIG_HAVE_CLK=y
114CONFIG_HAVE_DMA_API_DEBUG=y
115# CONFIG_SLOW_WORK is not set
111CONFIG_HAVE_GENERIC_DMA_COHERENT=y 116CONFIG_HAVE_GENERIC_DMA_COHERENT=y
112CONFIG_SLABINFO=y 117CONFIG_SLABINFO=y
113CONFIG_RT_MUTEXES=y 118CONFIG_RT_MUTEXES=y
@@ -120,7 +125,6 @@ CONFIG_MODULE_UNLOAD=y
120# CONFIG_MODULE_SRCVERSION_ALL is not set 125# CONFIG_MODULE_SRCVERSION_ALL is not set
121CONFIG_BLOCK=y 126CONFIG_BLOCK=y
122# CONFIG_LBD is not set 127# CONFIG_LBD is not set
123# CONFIG_BLK_DEV_IO_TRACE is not set
124# CONFIG_BLK_DEV_BSG is not set 128# CONFIG_BLK_DEV_BSG is not set
125# CONFIG_BLK_DEV_INTEGRITY is not set 129# CONFIG_BLK_DEV_INTEGRITY is not set
126 130
@@ -168,6 +172,7 @@ CONFIG_CPU_SHX2=y
168# CONFIG_CPU_SUBTYPE_SH7760 is not set 172# CONFIG_CPU_SUBTYPE_SH7760 is not set
169# CONFIG_CPU_SUBTYPE_SH4_202 is not set 173# CONFIG_CPU_SUBTYPE_SH4_202 is not set
170# CONFIG_CPU_SUBTYPE_SH7723 is not set 174# CONFIG_CPU_SUBTYPE_SH7723 is not set
175# CONFIG_CPU_SUBTYPE_SH7724 is not set
171# CONFIG_CPU_SUBTYPE_SH7763 is not set 176# CONFIG_CPU_SUBTYPE_SH7763 is not set
172# CONFIG_CPU_SUBTYPE_SH7770 is not set 177# CONFIG_CPU_SUBTYPE_SH7770 is not set
173# CONFIG_CPU_SUBTYPE_SH7780 is not set 178# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -177,8 +182,6 @@ CONFIG_CPU_SUBTYPE_SH7785=y
177# CONFIG_CPU_SUBTYPE_SH7343 is not set 182# CONFIG_CPU_SUBTYPE_SH7343 is not set
178# CONFIG_CPU_SUBTYPE_SH7722 is not set 183# CONFIG_CPU_SUBTYPE_SH7722 is not set
179# CONFIG_CPU_SUBTYPE_SH7366 is not set 184# CONFIG_CPU_SUBTYPE_SH7366 is not set
180# CONFIG_CPU_SUBTYPE_SH5_101 is not set
181# CONFIG_CPU_SUBTYPE_SH5_103 is not set
182 185
183# 186#
184# Memory management options 187# Memory management options
@@ -266,7 +269,7 @@ CONFIG_SH_R7785RP=y
266# 269#
267CONFIG_SH_TMU=y 270CONFIG_SH_TMU=y
268CONFIG_SH_TIMER_IRQ=28 271CONFIG_SH_TIMER_IRQ=28
269CONFIG_SH_PCLK_FREQ=50000000 272CONFIG_SH_PCLK_FREQ=33333333
270CONFIG_TICK_ONESHOT=y 273CONFIG_TICK_ONESHOT=y
271CONFIG_NO_HZ=y 274CONFIG_NO_HZ=y
272CONFIG_HIGH_RES_TIMERS=y 275CONFIG_HIGH_RES_TIMERS=y
@@ -337,8 +340,6 @@ CONFIG_CMDLINE="console=ttySC0,115200 root=/dev/sda1"
337# 340#
338CONFIG_PCI=y 341CONFIG_PCI=y
339CONFIG_SH_PCIDMA_NONCOHERENT=y 342CONFIG_SH_PCIDMA_NONCOHERENT=y
340CONFIG_PCI_AUTO=y
341CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
342# CONFIG_PCIEPORTBUS is not set 343# CONFIG_PCIEPORTBUS is not set
343# CONFIG_ARCH_SUPPORTS_MSI is not set 344# CONFIG_ARCH_SUPPORTS_MSI is not set
344# CONFIG_PCI_LEGACY is not set 345# CONFIG_PCI_LEGACY is not set
@@ -561,6 +562,7 @@ CONFIG_SCSI_LOWLEVEL=y
561# CONFIG_SCSI_MPT2SAS is not set 562# CONFIG_SCSI_MPT2SAS is not set
562# CONFIG_SCSI_HPTIOP is not set 563# CONFIG_SCSI_HPTIOP is not set
563# CONFIG_LIBFC is not set 564# CONFIG_LIBFC is not set
565# CONFIG_LIBFCOE is not set
564# CONFIG_FCOE is not set 566# CONFIG_FCOE is not set
565# CONFIG_SCSI_DMX3191D is not set 567# CONFIG_SCSI_DMX3191D is not set
566# CONFIG_SCSI_FUTURE_DOMAIN is not set 568# CONFIG_SCSI_FUTURE_DOMAIN is not set
@@ -698,6 +700,7 @@ CONFIG_NETDEV_1000=y
698# CONFIG_E1000E is not set 700# CONFIG_E1000E is not set
699# CONFIG_IP1000 is not set 701# CONFIG_IP1000 is not set
700# CONFIG_IGB is not set 702# CONFIG_IGB is not set
703# CONFIG_IGBVF is not set
701# CONFIG_NS83820 is not set 704# CONFIG_NS83820 is not set
702# CONFIG_HAMACHI is not set 705# CONFIG_HAMACHI is not set
703# CONFIG_YELLOWFIN is not set 706# CONFIG_YELLOWFIN is not set
@@ -721,6 +724,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
721# CONFIG_IXGBE is not set 724# CONFIG_IXGBE is not set
722# CONFIG_IXGB is not set 725# CONFIG_IXGB is not set
723# CONFIG_S2IO is not set 726# CONFIG_S2IO is not set
727# CONFIG_VXGE is not set
724# CONFIG_MYRI10GE is not set 728# CONFIG_MYRI10GE is not set
725# CONFIG_NETXEN_NIC is not set 729# CONFIG_NETXEN_NIC is not set
726# CONFIG_NIU is not set 730# CONFIG_NIU is not set
@@ -948,6 +952,7 @@ CONFIG_HWMON=y
948# CONFIG_SENSORS_F71805F is not set 952# CONFIG_SENSORS_F71805F is not set
949# CONFIG_SENSORS_F71882FG is not set 953# CONFIG_SENSORS_F71882FG is not set
950# CONFIG_SENSORS_F75375S is not set 954# CONFIG_SENSORS_F75375S is not set
955# CONFIG_SENSORS_G760A is not set
951# CONFIG_SENSORS_GL518SM is not set 956# CONFIG_SENSORS_GL518SM is not set
952# CONFIG_SENSORS_GL520SM is not set 957# CONFIG_SENSORS_GL520SM is not set
953# CONFIG_SENSORS_IT87 is not set 958# CONFIG_SENSORS_IT87 is not set
@@ -970,6 +975,7 @@ CONFIG_HWMON=y
970# CONFIG_SENSORS_PC87360 is not set 975# CONFIG_SENSORS_PC87360 is not set
971# CONFIG_SENSORS_PC87427 is not set 976# CONFIG_SENSORS_PC87427 is not set
972# CONFIG_SENSORS_PCF8591 is not set 977# CONFIG_SENSORS_PCF8591 is not set
978# CONFIG_SENSORS_SHT15 is not set
973# CONFIG_SENSORS_SIS5595 is not set 979# CONFIG_SENSORS_SIS5595 is not set
974# CONFIG_SENSORS_DME1737 is not set 980# CONFIG_SENSORS_DME1737 is not set
975# CONFIG_SENSORS_SMSC47M1 is not set 981# CONFIG_SENSORS_SMSC47M1 is not set
@@ -1109,7 +1115,6 @@ CONFIG_HID=y
1109# 1115#
1110# Special HID drivers 1116# Special HID drivers
1111# 1117#
1112CONFIG_HID_COMPAT=y
1113CONFIG_USB_SUPPORT=y 1118CONFIG_USB_SUPPORT=y
1114CONFIG_USB_ARCH_HAS_HCD=y 1119CONFIG_USB_ARCH_HAS_HCD=y
1115CONFIG_USB_ARCH_HAS_OHCI=y 1120CONFIG_USB_ARCH_HAS_OHCI=y
@@ -1202,6 +1207,7 @@ CONFIG_EXT2_FS=y
1202# CONFIG_EXT2_FS_XATTR is not set 1207# CONFIG_EXT2_FS_XATTR is not set
1203# CONFIG_EXT2_FS_XIP is not set 1208# CONFIG_EXT2_FS_XIP is not set
1204CONFIG_EXT3_FS=y 1209CONFIG_EXT3_FS=y
1210# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
1205CONFIG_EXT3_FS_XATTR=y 1211CONFIG_EXT3_FS_XATTR=y
1206# CONFIG_EXT3_FS_POSIX_ACL is not set 1212# CONFIG_EXT3_FS_POSIX_ACL is not set
1207# CONFIG_EXT3_FS_SECURITY is not set 1213# CONFIG_EXT3_FS_SECURITY is not set
@@ -1225,6 +1231,11 @@ CONFIG_INOTIFY_USER=y
1225CONFIG_FUSE_FS=m 1231CONFIG_FUSE_FS=m
1226 1232
1227# 1233#
1234# Caches
1235#
1236# CONFIG_FSCACHE is not set
1237
1238#
1228# CD-ROM/DVD Filesystems 1239# CD-ROM/DVD Filesystems
1229# 1240#
1230# CONFIG_ISO9660_FS is not set 1241# CONFIG_ISO9660_FS is not set
@@ -1273,6 +1284,7 @@ CONFIG_MINIX_FS=y
1273# CONFIG_ROMFS_FS is not set 1284# CONFIG_ROMFS_FS is not set
1274# CONFIG_SYSV_FS is not set 1285# CONFIG_SYSV_FS is not set
1275# CONFIG_UFS_FS is not set 1286# CONFIG_UFS_FS is not set
1287# CONFIG_NILFS2_FS is not set
1276CONFIG_NETWORK_FILESYSTEMS=y 1288CONFIG_NETWORK_FILESYSTEMS=y
1277CONFIG_NFS_FS=y 1289CONFIG_NFS_FS=y
1278CONFIG_NFS_V3=y 1290CONFIG_NFS_V3=y
@@ -1359,6 +1371,7 @@ CONFIG_DEBUG_FS=y
1359CONFIG_DEBUG_KERNEL=y 1371CONFIG_DEBUG_KERNEL=y
1360# CONFIG_DEBUG_SHIRQ is not set 1372# CONFIG_DEBUG_SHIRQ is not set
1361# CONFIG_DETECT_SOFTLOCKUP is not set 1373# CONFIG_DETECT_SOFTLOCKUP is not set
1374# CONFIG_DETECT_HUNG_TASK is not set
1362CONFIG_SCHED_DEBUG=y 1375CONFIG_SCHED_DEBUG=y
1363# CONFIG_SCHEDSTATS is not set 1376# CONFIG_SCHEDSTATS is not set
1364# CONFIG_TIMER_STATS is not set 1377# CONFIG_TIMER_STATS is not set
@@ -1401,6 +1414,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
1401CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1414CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1402CONFIG_RING_BUFFER=y 1415CONFIG_RING_BUFFER=y
1403CONFIG_TRACING=y 1416CONFIG_TRACING=y
1417CONFIG_TRACING_SUPPORT=y
1404 1418
1405# 1419#
1406# Tracers 1420# Tracers
@@ -1410,11 +1424,16 @@ CONFIG_TRACING=y
1410# CONFIG_PREEMPT_TRACER is not set 1424# CONFIG_PREEMPT_TRACER is not set
1411# CONFIG_SCHED_TRACER is not set 1425# CONFIG_SCHED_TRACER is not set
1412# CONFIG_CONTEXT_SWITCH_TRACER is not set 1426# CONFIG_CONTEXT_SWITCH_TRACER is not set
1427# CONFIG_EVENT_TRACER is not set
1413# CONFIG_BOOT_TRACER is not set 1428# CONFIG_BOOT_TRACER is not set
1414# CONFIG_TRACE_BRANCH_PROFILING is not set 1429# CONFIG_TRACE_BRANCH_PROFILING is not set
1415# CONFIG_STACK_TRACER is not set 1430# CONFIG_STACK_TRACER is not set
1431# CONFIG_KMEMTRACE is not set
1432# CONFIG_WORKQUEUE_TRACER is not set
1433# CONFIG_BLK_DEV_IO_TRACE is not set
1416# CONFIG_FTRACE_STARTUP_TEST is not set 1434# CONFIG_FTRACE_STARTUP_TEST is not set
1417# CONFIG_DYNAMIC_DEBUG is not set 1435# CONFIG_DYNAMIC_DEBUG is not set
1436# CONFIG_DMA_API_DEBUG is not set
1418# CONFIG_SAMPLES is not set 1437# CONFIG_SAMPLES is not set
1419CONFIG_HAVE_ARCH_KGDB=y 1438CONFIG_HAVE_ARCH_KGDB=y
1420# CONFIG_KGDB is not set 1439# CONFIG_KGDB is not set
@@ -1534,6 +1553,7 @@ CONFIG_CRYPTO_DES=y
1534# CONFIG_CRYPTO_ANSI_CPRNG is not set 1553# CONFIG_CRYPTO_ANSI_CPRNG is not set
1535CONFIG_CRYPTO_HW=y 1554CONFIG_CRYPTO_HW=y
1536# CONFIG_CRYPTO_DEV_HIFN_795X is not set 1555# CONFIG_CRYPTO_DEV_HIFN_795X is not set
1556CONFIG_BINARY_PRINTF=y
1537 1557
1538# 1558#
1539# Library routines 1559# Library routines
diff --git a/arch/sh/configs/rsk7201_defconfig b/arch/sh/configs/rsk7201_defconfig
index a037c744b798..fa4395768d19 100644
--- a/arch/sh/configs/rsk7201_defconfig
+++ b/arch/sh/configs/rsk7201_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:29:08 2009 4# Mon Apr 27 12:56:29 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -65,7 +66,6 @@ CONFIG_INITRAMFS_SOURCE=""
65CONFIG_RD_GZIP=y 66CONFIG_RD_GZIP=y
66# CONFIG_RD_BZIP2 is not set 67# CONFIG_RD_BZIP2 is not set
67# CONFIG_RD_LZMA is not set 68# CONFIG_RD_LZMA is not set
68CONFIG_INITRAMFS_COMPRESSION_NONE=y
69CONFIG_CC_OPTIMIZE_FOR_SIZE=y 69CONFIG_CC_OPTIMIZE_FOR_SIZE=y
70CONFIG_SYSCTL=y 70CONFIG_SYSCTL=y
71CONFIG_ANON_INODES=y 71CONFIG_ANON_INODES=y
@@ -74,6 +74,7 @@ CONFIG_UID16=y
74CONFIG_SYSCTL_SYSCALL=y 74CONFIG_SYSCTL_SYSCALL=y
75CONFIG_KALLSYMS=y 75CONFIG_KALLSYMS=y
76# CONFIG_KALLSYMS_EXTRA_PASS is not set 76# CONFIG_KALLSYMS_EXTRA_PASS is not set
77# CONFIG_STRIP_ASM_SYMS is not set
77CONFIG_HOTPLUG=y 78CONFIG_HOTPLUG=y
78CONFIG_PRINTK=y 79CONFIG_PRINTK=y
79CONFIG_BUG=y 80CONFIG_BUG=y
@@ -100,6 +101,8 @@ CONFIG_HAVE_KPROBES=y
100CONFIG_HAVE_KRETPROBES=y 101CONFIG_HAVE_KRETPROBES=y
101CONFIG_HAVE_ARCH_TRACEHOOK=y 102CONFIG_HAVE_ARCH_TRACEHOOK=y
102CONFIG_HAVE_CLK=y 103CONFIG_HAVE_CLK=y
104CONFIG_HAVE_DMA_API_DEBUG=y
105# CONFIG_SLOW_WORK is not set
103CONFIG_HAVE_GENERIC_DMA_COHERENT=y 106CONFIG_HAVE_GENERIC_DMA_COHERENT=y
104CONFIG_RT_MUTEXES=y 107CONFIG_RT_MUTEXES=y
105CONFIG_BASE_SMALL=0 108CONFIG_BASE_SMALL=0
@@ -110,7 +113,6 @@ CONFIG_MODULES=y
110# CONFIG_MODULE_SRCVERSION_ALL is not set 113# CONFIG_MODULE_SRCVERSION_ALL is not set
111CONFIG_BLOCK=y 114CONFIG_BLOCK=y
112# CONFIG_LBD is not set 115# CONFIG_LBD is not set
113# CONFIG_BLK_DEV_IO_TRACE is not set
114# CONFIG_BLK_DEV_BSG is not set 116# CONFIG_BLK_DEV_BSG is not set
115# CONFIG_BLK_DEV_INTEGRITY is not set 117# CONFIG_BLK_DEV_INTEGRITY is not set
116 118
@@ -157,6 +159,7 @@ CONFIG_CPU_SUBTYPE_SH7201=y
157# CONFIG_CPU_SUBTYPE_SH7760 is not set 159# CONFIG_CPU_SUBTYPE_SH7760 is not set
158# CONFIG_CPU_SUBTYPE_SH4_202 is not set 160# CONFIG_CPU_SUBTYPE_SH4_202 is not set
159# CONFIG_CPU_SUBTYPE_SH7723 is not set 161# CONFIG_CPU_SUBTYPE_SH7723 is not set
162# CONFIG_CPU_SUBTYPE_SH7724 is not set
160# CONFIG_CPU_SUBTYPE_SH7763 is not set 163# CONFIG_CPU_SUBTYPE_SH7763 is not set
161# CONFIG_CPU_SUBTYPE_SH7770 is not set 164# CONFIG_CPU_SUBTYPE_SH7770 is not set
162# CONFIG_CPU_SUBTYPE_SH7780 is not set 165# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -166,8 +169,6 @@ CONFIG_CPU_SUBTYPE_SH7201=y
166# CONFIG_CPU_SUBTYPE_SH7343 is not set 169# CONFIG_CPU_SUBTYPE_SH7343 is not set
167# CONFIG_CPU_SUBTYPE_SH7722 is not set 170# CONFIG_CPU_SUBTYPE_SH7722 is not set
168# CONFIG_CPU_SUBTYPE_SH7366 is not set 171# CONFIG_CPU_SUBTYPE_SH7366 is not set
169# CONFIG_CPU_SUBTYPE_SH5_101 is not set
170# CONFIG_CPU_SUBTYPE_SH5_103 is not set
171 172
172# 173#
173# Memory management options 174# Memory management options
@@ -603,6 +604,11 @@ CONFIG_EXT2_FS=y
603# CONFIG_FUSE_FS is not set 604# CONFIG_FUSE_FS is not set
604 605
605# 606#
607# Caches
608#
609# CONFIG_FSCACHE is not set
610
611#
606# CD-ROM/DVD Filesystems 612# CD-ROM/DVD Filesystems
607# 613#
608# CONFIG_ISO9660_FS is not set 614# CONFIG_ISO9660_FS is not set
@@ -651,8 +657,13 @@ CONFIG_JFFS2_RTIME=y
651# CONFIG_HPFS_FS is not set 657# CONFIG_HPFS_FS is not set
652# CONFIG_QNX4FS_FS is not set 658# CONFIG_QNX4FS_FS is not set
653CONFIG_ROMFS_FS=y 659CONFIG_ROMFS_FS=y
660CONFIG_ROMFS_BACKED_BY_BLOCK=y
661# CONFIG_ROMFS_BACKED_BY_MTD is not set
662# CONFIG_ROMFS_BACKED_BY_BOTH is not set
663CONFIG_ROMFS_ON_BLOCK=y
654# CONFIG_SYSV_FS is not set 664# CONFIG_SYSV_FS is not set
655# CONFIG_UFS_FS is not set 665# CONFIG_UFS_FS is not set
666# CONFIG_NILFS2_FS is not set
656 667
657# 668#
658# Partition Types 669# Partition Types
@@ -686,11 +697,24 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
686CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 697CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
687CONFIG_RING_BUFFER=y 698CONFIG_RING_BUFFER=y
688CONFIG_TRACING=y 699CONFIG_TRACING=y
700CONFIG_TRACING_SUPPORT=y
689 701
690# 702#
691# Tracers 703# Tracers
692# 704#
705# CONFIG_FUNCTION_TRACER is not set
706# CONFIG_SCHED_TRACER is not set
707# CONFIG_CONTEXT_SWITCH_TRACER is not set
708# CONFIG_EVENT_TRACER is not set
709# CONFIG_BOOT_TRACER is not set
710# CONFIG_TRACE_BRANCH_PROFILING is not set
711# CONFIG_STACK_TRACER is not set
712# CONFIG_KMEMTRACE is not set
713# CONFIG_WORKQUEUE_TRACER is not set
714# CONFIG_BLK_DEV_IO_TRACE is not set
715# CONFIG_FTRACE_STARTUP_TEST is not set
693# CONFIG_DYNAMIC_DEBUG is not set 716# CONFIG_DYNAMIC_DEBUG is not set
717# CONFIG_DMA_API_DEBUG is not set
694# CONFIG_SAMPLES is not set 718# CONFIG_SAMPLES is not set
695CONFIG_HAVE_ARCH_KGDB=y 719CONFIG_HAVE_ARCH_KGDB=y
696# CONFIG_SH_STANDARD_BIOS is not set 720# CONFIG_SH_STANDARD_BIOS is not set
@@ -705,6 +729,7 @@ CONFIG_HAVE_ARCH_KGDB=y
705# CONFIG_SECURITYFS is not set 729# CONFIG_SECURITYFS is not set
706# CONFIG_SECURITY_FILE_CAPABILITIES is not set 730# CONFIG_SECURITY_FILE_CAPABILITIES is not set
707# CONFIG_CRYPTO is not set 731# CONFIG_CRYPTO is not set
732CONFIG_BINARY_PRINTF=y
708 733
709# 734#
710# Library routines 735# Library routines
diff --git a/arch/sh/configs/rsk7203_defconfig b/arch/sh/configs/rsk7203_defconfig
index 9ae28e88426c..e3a65f819f0a 100644
--- a/arch/sh/configs/rsk7203_defconfig
+++ b/arch/sh/configs/rsk7203_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:30:34 2009 4# Mon Apr 27 12:57:06 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -39,6 +40,7 @@ CONFIG_LOCALVERSION=""
39CONFIG_SYSVIPC=y 40CONFIG_SYSVIPC=y
40CONFIG_SYSVIPC_SYSCTL=y 41CONFIG_SYSVIPC_SYSCTL=y
41CONFIG_POSIX_MQUEUE=y 42CONFIG_POSIX_MQUEUE=y
43CONFIG_POSIX_MQUEUE_SYSCTL=y
42CONFIG_BSD_PROCESS_ACCT=y 44CONFIG_BSD_PROCESS_ACCT=y
43# CONFIG_BSD_PROCESS_ACCT_V3 is not set 45# CONFIG_BSD_PROCESS_ACCT_V3 is not set
44# CONFIG_TASKSTATS is not set 46# CONFIG_TASKSTATS is not set
@@ -70,7 +72,6 @@ CONFIG_INITRAMFS_SOURCE=""
70CONFIG_RD_GZIP=y 72CONFIG_RD_GZIP=y
71# CONFIG_RD_BZIP2 is not set 73# CONFIG_RD_BZIP2 is not set
72# CONFIG_RD_LZMA is not set 74# CONFIG_RD_LZMA is not set
73CONFIG_INITRAMFS_COMPRESSION_NONE=y
74CONFIG_CC_OPTIMIZE_FOR_SIZE=y 75CONFIG_CC_OPTIMIZE_FOR_SIZE=y
75CONFIG_SYSCTL=y 76CONFIG_SYSCTL=y
76CONFIG_ANON_INODES=y 77CONFIG_ANON_INODES=y
@@ -80,6 +81,7 @@ CONFIG_SYSCTL_SYSCALL=y
80CONFIG_KALLSYMS=y 81CONFIG_KALLSYMS=y
81CONFIG_KALLSYMS_ALL=y 82CONFIG_KALLSYMS_ALL=y
82# CONFIG_KALLSYMS_EXTRA_PASS is not set 83# CONFIG_KALLSYMS_EXTRA_PASS is not set
84# CONFIG_STRIP_ASM_SYMS is not set
83CONFIG_HOTPLUG=y 85CONFIG_HOTPLUG=y
84CONFIG_PRINTK=y 86CONFIG_PRINTK=y
85CONFIG_BUG=y 87CONFIG_BUG=y
@@ -106,6 +108,8 @@ CONFIG_HAVE_KPROBES=y
106CONFIG_HAVE_KRETPROBES=y 108CONFIG_HAVE_KRETPROBES=y
107CONFIG_HAVE_ARCH_TRACEHOOK=y 109CONFIG_HAVE_ARCH_TRACEHOOK=y
108CONFIG_HAVE_CLK=y 110CONFIG_HAVE_CLK=y
111CONFIG_HAVE_DMA_API_DEBUG=y
112# CONFIG_SLOW_WORK is not set
109CONFIG_HAVE_GENERIC_DMA_COHERENT=y 113CONFIG_HAVE_GENERIC_DMA_COHERENT=y
110CONFIG_RT_MUTEXES=y 114CONFIG_RT_MUTEXES=y
111CONFIG_BASE_SMALL=0 115CONFIG_BASE_SMALL=0
@@ -116,7 +120,6 @@ CONFIG_MODULES=y
116# CONFIG_MODULE_SRCVERSION_ALL is not set 120# CONFIG_MODULE_SRCVERSION_ALL is not set
117CONFIG_BLOCK=y 121CONFIG_BLOCK=y
118# CONFIG_LBD is not set 122# CONFIG_LBD is not set
119# CONFIG_BLK_DEV_IO_TRACE is not set
120# CONFIG_BLK_DEV_BSG is not set 123# CONFIG_BLK_DEV_BSG is not set
121# CONFIG_BLK_DEV_INTEGRITY is not set 124# CONFIG_BLK_DEV_INTEGRITY is not set
122 125
@@ -163,6 +166,7 @@ CONFIG_CPU_SUBTYPE_SH7203=y
163# CONFIG_CPU_SUBTYPE_SH7760 is not set 166# CONFIG_CPU_SUBTYPE_SH7760 is not set
164# CONFIG_CPU_SUBTYPE_SH4_202 is not set 167# CONFIG_CPU_SUBTYPE_SH4_202 is not set
165# CONFIG_CPU_SUBTYPE_SH7723 is not set 168# CONFIG_CPU_SUBTYPE_SH7723 is not set
169# CONFIG_CPU_SUBTYPE_SH7724 is not set
166# CONFIG_CPU_SUBTYPE_SH7763 is not set 170# CONFIG_CPU_SUBTYPE_SH7763 is not set
167# CONFIG_CPU_SUBTYPE_SH7770 is not set 171# CONFIG_CPU_SUBTYPE_SH7770 is not set
168# CONFIG_CPU_SUBTYPE_SH7780 is not set 172# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -172,8 +176,6 @@ CONFIG_CPU_SUBTYPE_SH7203=y
172# CONFIG_CPU_SUBTYPE_SH7343 is not set 176# CONFIG_CPU_SUBTYPE_SH7343 is not set
173# CONFIG_CPU_SUBTYPE_SH7722 is not set 177# CONFIG_CPU_SUBTYPE_SH7722 is not set
174# CONFIG_CPU_SUBTYPE_SH7366 is not set 178# CONFIG_CPU_SUBTYPE_SH7366 is not set
175# CONFIG_CPU_SUBTYPE_SH5_101 is not set
176# CONFIG_CPU_SUBTYPE_SH5_103 is not set
177 179
178# 180#
179# Memory management options 181# Memory management options
@@ -750,15 +752,17 @@ CONFIG_USB_HID=y
750# 752#
751# Special HID drivers 753# Special HID drivers
752# 754#
753CONFIG_HID_COMPAT=y
754CONFIG_HID_A4TECH=y 755CONFIG_HID_A4TECH=y
755CONFIG_HID_APPLE=y 756CONFIG_HID_APPLE=y
756CONFIG_HID_BELKIN=y 757CONFIG_HID_BELKIN=y
757CONFIG_HID_CHERRY=y 758CONFIG_HID_CHERRY=y
758CONFIG_HID_CHICONY=y 759CONFIG_HID_CHICONY=y
759CONFIG_HID_CYPRESS=y 760CONFIG_HID_CYPRESS=y
761# CONFIG_DRAGONRISE_FF is not set
760CONFIG_HID_EZKEY=y 762CONFIG_HID_EZKEY=y
763# CONFIG_HID_KYE is not set
761CONFIG_HID_GYRATION=y 764CONFIG_HID_GYRATION=y
765# CONFIG_HID_KENSINGTON is not set
762CONFIG_HID_LOGITECH=y 766CONFIG_HID_LOGITECH=y
763# CONFIG_LOGITECH_FF is not set 767# CONFIG_LOGITECH_FF is not set
764# CONFIG_LOGIRUMBLEPAD2_FF is not set 768# CONFIG_LOGIRUMBLEPAD2_FF is not set
@@ -874,6 +878,7 @@ CONFIG_LEDS_CLASS=y
874# LED drivers 878# LED drivers
875# 879#
876CONFIG_LEDS_GPIO=y 880CONFIG_LEDS_GPIO=y
881CONFIG_LEDS_GPIO_PLATFORM=y
877 882
878# 883#
879# LED Triggers 884# LED Triggers
@@ -882,6 +887,7 @@ CONFIG_LEDS_TRIGGERS=y
882CONFIG_LEDS_TRIGGER_TIMER=y 887CONFIG_LEDS_TRIGGER_TIMER=y
883CONFIG_LEDS_TRIGGER_HEARTBEAT=y 888CONFIG_LEDS_TRIGGER_HEARTBEAT=y
884CONFIG_LEDS_TRIGGER_BACKLIGHT=y 889CONFIG_LEDS_TRIGGER_BACKLIGHT=y
890# CONFIG_LEDS_TRIGGER_GPIO is not set
885CONFIG_LEDS_TRIGGER_DEFAULT_ON=y 891CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
886 892
887# 893#
@@ -951,6 +957,11 @@ CONFIG_FILE_LOCKING=y
951# CONFIG_FUSE_FS is not set 957# CONFIG_FUSE_FS is not set
952 958
953# 959#
960# Caches
961#
962# CONFIG_FSCACHE is not set
963
964#
954# CD-ROM/DVD Filesystems 965# CD-ROM/DVD Filesystems
955# 966#
956# CONFIG_ISO9660_FS is not set 967# CONFIG_ISO9660_FS is not set
@@ -989,8 +1000,13 @@ CONFIG_MISC_FILESYSTEMS=y
989# CONFIG_HPFS_FS is not set 1000# CONFIG_HPFS_FS is not set
990# CONFIG_QNX4FS_FS is not set 1001# CONFIG_QNX4FS_FS is not set
991CONFIG_ROMFS_FS=y 1002CONFIG_ROMFS_FS=y
1003CONFIG_ROMFS_BACKED_BY_BLOCK=y
1004# CONFIG_ROMFS_BACKED_BY_MTD is not set
1005# CONFIG_ROMFS_BACKED_BY_BOTH is not set
1006CONFIG_ROMFS_ON_BLOCK=y
992# CONFIG_SYSV_FS is not set 1007# CONFIG_SYSV_FS is not set
993# CONFIG_UFS_FS is not set 1008# CONFIG_UFS_FS is not set
1009# CONFIG_NILFS2_FS is not set
994CONFIG_NETWORK_FILESYSTEMS=y 1010CONFIG_NETWORK_FILESYSTEMS=y
995CONFIG_NFS_FS=y 1011CONFIG_NFS_FS=y
996# CONFIG_NFS_V3 is not set 1012# CONFIG_NFS_V3 is not set
@@ -1033,6 +1049,9 @@ CONFIG_DEBUG_SHIRQ=y
1033CONFIG_DETECT_SOFTLOCKUP=y 1049CONFIG_DETECT_SOFTLOCKUP=y
1034# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set 1050# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
1035CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0 1051CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
1052CONFIG_DETECT_HUNG_TASK=y
1053# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
1054CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
1036CONFIG_SCHED_DEBUG=y 1055CONFIG_SCHED_DEBUG=y
1037# CONFIG_SCHEDSTATS is not set 1056# CONFIG_SCHEDSTATS is not set
1038# CONFIG_TIMER_STATS is not set 1057# CONFIG_TIMER_STATS is not set
@@ -1076,6 +1095,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
1076CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1095CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1077CONFIG_RING_BUFFER=y 1096CONFIG_RING_BUFFER=y
1078CONFIG_TRACING=y 1097CONFIG_TRACING=y
1098CONFIG_TRACING_SUPPORT=y
1079 1099
1080# 1100#
1081# Tracers 1101# Tracers
@@ -1083,11 +1103,16 @@ CONFIG_TRACING=y
1083# CONFIG_FUNCTION_TRACER is not set 1103# CONFIG_FUNCTION_TRACER is not set
1084# CONFIG_SCHED_TRACER is not set 1104# CONFIG_SCHED_TRACER is not set
1085# CONFIG_CONTEXT_SWITCH_TRACER is not set 1105# CONFIG_CONTEXT_SWITCH_TRACER is not set
1106# CONFIG_EVENT_TRACER is not set
1086# CONFIG_BOOT_TRACER is not set 1107# CONFIG_BOOT_TRACER is not set
1087# CONFIG_TRACE_BRANCH_PROFILING is not set 1108# CONFIG_TRACE_BRANCH_PROFILING is not set
1088# CONFIG_STACK_TRACER is not set 1109# CONFIG_STACK_TRACER is not set
1110# CONFIG_KMEMTRACE is not set
1111# CONFIG_WORKQUEUE_TRACER is not set
1112# CONFIG_BLK_DEV_IO_TRACE is not set
1089# CONFIG_FTRACE_STARTUP_TEST is not set 1113# CONFIG_FTRACE_STARTUP_TEST is not set
1090# CONFIG_DYNAMIC_DEBUG is not set 1114# CONFIG_DYNAMIC_DEBUG is not set
1115# CONFIG_DMA_API_DEBUG is not set
1091# CONFIG_SAMPLES is not set 1116# CONFIG_SAMPLES is not set
1092CONFIG_HAVE_ARCH_KGDB=y 1117CONFIG_HAVE_ARCH_KGDB=y
1093# CONFIG_KGDB is not set 1118# CONFIG_KGDB is not set
@@ -1111,6 +1136,7 @@ CONFIG_DUMP_CODE=y
1111# CONFIG_SECURITYFS is not set 1136# CONFIG_SECURITYFS is not set
1112# CONFIG_SECURITY_FILE_CAPABILITIES is not set 1137# CONFIG_SECURITY_FILE_CAPABILITIES is not set
1113# CONFIG_CRYPTO is not set 1138# CONFIG_CRYPTO is not set
1139CONFIG_BINARY_PRINTF=y
1114 1140
1115# 1141#
1116# Library routines 1142# Library routines
diff --git a/arch/sh/configs/rts7751r2d1_defconfig b/arch/sh/configs/rts7751r2d1_defconfig
index c0f741af6da8..a4a59f6205ab 100644
--- a/arch/sh/configs/rts7751r2d1_defconfig
+++ b/arch/sh/configs/rts7751r2d1_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:33:25 2009 4# Mon Apr 27 12:58:13 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -70,6 +71,7 @@ CONFIG_UID16=y
70# CONFIG_SYSCTL_SYSCALL is not set 71# CONFIG_SYSCTL_SYSCALL is not set
71CONFIG_KALLSYMS=y 72CONFIG_KALLSYMS=y
72# CONFIG_KALLSYMS_EXTRA_PASS is not set 73# CONFIG_KALLSYMS_EXTRA_PASS is not set
74# CONFIG_STRIP_ASM_SYMS is not set
73CONFIG_HOTPLUG=y 75CONFIG_HOTPLUG=y
74CONFIG_PRINTK=y 76CONFIG_PRINTK=y
75CONFIG_BUG=y 77CONFIG_BUG=y
@@ -99,6 +101,8 @@ CONFIG_HAVE_KPROBES=y
99CONFIG_HAVE_KRETPROBES=y 101CONFIG_HAVE_KRETPROBES=y
100CONFIG_HAVE_ARCH_TRACEHOOK=y 102CONFIG_HAVE_ARCH_TRACEHOOK=y
101CONFIG_HAVE_CLK=y 103CONFIG_HAVE_CLK=y
104CONFIG_HAVE_DMA_API_DEBUG=y
105# CONFIG_SLOW_WORK is not set
102CONFIG_HAVE_GENERIC_DMA_COHERENT=y 106CONFIG_HAVE_GENERIC_DMA_COHERENT=y
103CONFIG_SLABINFO=y 107CONFIG_SLABINFO=y
104CONFIG_RT_MUTEXES=y 108CONFIG_RT_MUTEXES=y
@@ -110,7 +114,6 @@ CONFIG_MODULES=y
110# CONFIG_MODULE_SRCVERSION_ALL is not set 114# CONFIG_MODULE_SRCVERSION_ALL is not set
111CONFIG_BLOCK=y 115CONFIG_BLOCK=y
112# CONFIG_LBD is not set 116# CONFIG_LBD is not set
113# CONFIG_BLK_DEV_IO_TRACE is not set
114# CONFIG_BLK_DEV_BSG is not set 117# CONFIG_BLK_DEV_BSG is not set
115# CONFIG_BLK_DEV_INTEGRITY is not set 118# CONFIG_BLK_DEV_INTEGRITY is not set
116 119
@@ -156,6 +159,7 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
156# CONFIG_CPU_SUBTYPE_SH7760 is not set 159# CONFIG_CPU_SUBTYPE_SH7760 is not set
157# CONFIG_CPU_SUBTYPE_SH4_202 is not set 160# CONFIG_CPU_SUBTYPE_SH4_202 is not set
158# CONFIG_CPU_SUBTYPE_SH7723 is not set 161# CONFIG_CPU_SUBTYPE_SH7723 is not set
162# CONFIG_CPU_SUBTYPE_SH7724 is not set
159# CONFIG_CPU_SUBTYPE_SH7763 is not set 163# CONFIG_CPU_SUBTYPE_SH7763 is not set
160# CONFIG_CPU_SUBTYPE_SH7770 is not set 164# CONFIG_CPU_SUBTYPE_SH7770 is not set
161# CONFIG_CPU_SUBTYPE_SH7780 is not set 165# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -165,8 +169,6 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
165# CONFIG_CPU_SUBTYPE_SH7343 is not set 169# CONFIG_CPU_SUBTYPE_SH7343 is not set
166# CONFIG_CPU_SUBTYPE_SH7722 is not set 170# CONFIG_CPU_SUBTYPE_SH7722 is not set
167# CONFIG_CPU_SUBTYPE_SH7366 is not set 171# CONFIG_CPU_SUBTYPE_SH7366 is not set
168# CONFIG_CPU_SUBTYPE_SH5_101 is not set
169# CONFIG_CPU_SUBTYPE_SH5_103 is not set
170 172
171# 173#
172# Memory management options 174# Memory management options
@@ -302,8 +304,6 @@ CONFIG_CMDLINE="console=tty0 console=ttySC0,115200 root=/dev/sda1 earlyprintk=se
302# 304#
303CONFIG_PCI=y 305CONFIG_PCI=y
304CONFIG_SH_PCIDMA_NONCOHERENT=y 306CONFIG_SH_PCIDMA_NONCOHERENT=y
305CONFIG_PCI_AUTO=y
306CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
307# CONFIG_PCIEPORTBUS is not set 307# CONFIG_PCIEPORTBUS is not set
308# CONFIG_ARCH_SUPPORTS_MSI is not set 308# CONFIG_ARCH_SUPPORTS_MSI is not set
309CONFIG_PCI_LEGACY=y 309CONFIG_PCI_LEGACY=y
@@ -513,6 +513,7 @@ CONFIG_SCSI_LOWLEVEL=y
513# CONFIG_SCSI_MPT2SAS is not set 513# CONFIG_SCSI_MPT2SAS is not set
514# CONFIG_SCSI_HPTIOP is not set 514# CONFIG_SCSI_HPTIOP is not set
515# CONFIG_LIBFC is not set 515# CONFIG_LIBFC is not set
516# CONFIG_LIBFCOE is not set
516# CONFIG_FCOE is not set 517# CONFIG_FCOE is not set
517# CONFIG_SCSI_DMX3191D is not set 518# CONFIG_SCSI_DMX3191D is not set
518# CONFIG_SCSI_FUTURE_DOMAIN is not set 519# CONFIG_SCSI_FUTURE_DOMAIN is not set
@@ -672,6 +673,7 @@ CONFIG_NETDEV_1000=y
672# CONFIG_E1000E is not set 673# CONFIG_E1000E is not set
673# CONFIG_IP1000 is not set 674# CONFIG_IP1000 is not set
674# CONFIG_IGB is not set 675# CONFIG_IGB is not set
676# CONFIG_IGBVF is not set
675# CONFIG_NS83820 is not set 677# CONFIG_NS83820 is not set
676# CONFIG_HAMACHI is not set 678# CONFIG_HAMACHI is not set
677# CONFIG_YELLOWFIN is not set 679# CONFIG_YELLOWFIN is not set
@@ -695,6 +697,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
695# CONFIG_IXGBE is not set 697# CONFIG_IXGBE is not set
696# CONFIG_IXGB is not set 698# CONFIG_IXGB is not set
697# CONFIG_S2IO is not set 699# CONFIG_S2IO is not set
700# CONFIG_VXGE is not set
698# CONFIG_MYRI10GE is not set 701# CONFIG_MYRI10GE is not set
699# CONFIG_NETXEN_NIC is not set 702# CONFIG_NETXEN_NIC is not set
700# CONFIG_NIU is not set 703# CONFIG_NIU is not set
@@ -793,6 +796,7 @@ CONFIG_SERIAL_8250_RUNTIME_UARTS=4
793# 796#
794# Non-8250 serial port support 797# Non-8250 serial port support
795# 798#
799# CONFIG_SERIAL_MAX3100 is not set
796CONFIG_SERIAL_SH_SCI=y 800CONFIG_SERIAL_SH_SCI=y
797CONFIG_SERIAL_SH_SCI_NR_UARTS=1 801CONFIG_SERIAL_SH_SCI_NR_UARTS=1
798CONFIG_SERIAL_SH_SCI_CONSOLE=y 802CONFIG_SERIAL_SH_SCI_CONSOLE=y
@@ -1079,15 +1083,17 @@ CONFIG_USB_HID=y
1079# 1083#
1080# Special HID drivers 1084# Special HID drivers
1081# 1085#
1082CONFIG_HID_COMPAT=y
1083CONFIG_HID_A4TECH=y 1086CONFIG_HID_A4TECH=y
1084CONFIG_HID_APPLE=y 1087CONFIG_HID_APPLE=y
1085CONFIG_HID_BELKIN=y 1088CONFIG_HID_BELKIN=y
1086CONFIG_HID_CHERRY=y 1089CONFIG_HID_CHERRY=y
1087CONFIG_HID_CHICONY=y 1090CONFIG_HID_CHICONY=y
1088CONFIG_HID_CYPRESS=y 1091CONFIG_HID_CYPRESS=y
1092# CONFIG_DRAGONRISE_FF is not set
1089CONFIG_HID_EZKEY=y 1093CONFIG_HID_EZKEY=y
1094# CONFIG_HID_KYE is not set
1090CONFIG_HID_GYRATION=y 1095CONFIG_HID_GYRATION=y
1096# CONFIG_HID_KENSINGTON is not set
1091CONFIG_HID_LOGITECH=y 1097CONFIG_HID_LOGITECH=y
1092# CONFIG_LOGITECH_FF is not set 1098# CONFIG_LOGITECH_FF is not set
1093# CONFIG_LOGIRUMBLEPAD2_FF is not set 1099# CONFIG_LOGIRUMBLEPAD2_FF is not set
@@ -1291,6 +1297,11 @@ CONFIG_INOTIFY_USER=y
1291# CONFIG_FUSE_FS is not set 1297# CONFIG_FUSE_FS is not set
1292 1298
1293# 1299#
1300# Caches
1301#
1302# CONFIG_FSCACHE is not set
1303
1304#
1294# CD-ROM/DVD Filesystems 1305# CD-ROM/DVD Filesystems
1295# 1306#
1296# CONFIG_ISO9660_FS is not set 1307# CONFIG_ISO9660_FS is not set
@@ -1337,6 +1348,7 @@ CONFIG_MINIX_FS=y
1337# CONFIG_ROMFS_FS is not set 1348# CONFIG_ROMFS_FS is not set
1338# CONFIG_SYSV_FS is not set 1349# CONFIG_SYSV_FS is not set
1339# CONFIG_UFS_FS is not set 1350# CONFIG_UFS_FS is not set
1351# CONFIG_NILFS2_FS is not set
1340CONFIG_NETWORK_FILESYSTEMS=y 1352CONFIG_NETWORK_FILESYSTEMS=y
1341# CONFIG_NFS_FS is not set 1353# CONFIG_NFS_FS is not set
1342# CONFIG_NFSD is not set 1354# CONFIG_NFSD is not set
@@ -1417,11 +1429,25 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
1417CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1429CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1418CONFIG_RING_BUFFER=y 1430CONFIG_RING_BUFFER=y
1419CONFIG_TRACING=y 1431CONFIG_TRACING=y
1432CONFIG_TRACING_SUPPORT=y
1420 1433
1421# 1434#
1422# Tracers 1435# Tracers
1423# 1436#
1437# CONFIG_FUNCTION_TRACER is not set
1438# CONFIG_IRQSOFF_TRACER is not set
1439# CONFIG_SCHED_TRACER is not set
1440# CONFIG_CONTEXT_SWITCH_TRACER is not set
1441# CONFIG_EVENT_TRACER is not set
1442# CONFIG_BOOT_TRACER is not set
1443# CONFIG_TRACE_BRANCH_PROFILING is not set
1444# CONFIG_STACK_TRACER is not set
1445# CONFIG_KMEMTRACE is not set
1446# CONFIG_WORKQUEUE_TRACER is not set
1447# CONFIG_BLK_DEV_IO_TRACE is not set
1448# CONFIG_FTRACE_STARTUP_TEST is not set
1424# CONFIG_DYNAMIC_DEBUG is not set 1449# CONFIG_DYNAMIC_DEBUG is not set
1450# CONFIG_DMA_API_DEBUG is not set
1425# CONFIG_SAMPLES is not set 1451# CONFIG_SAMPLES is not set
1426CONFIG_HAVE_ARCH_KGDB=y 1452CONFIG_HAVE_ARCH_KGDB=y
1427# CONFIG_SH_STANDARD_BIOS is not set 1453# CONFIG_SH_STANDARD_BIOS is not set
@@ -1524,6 +1550,7 @@ CONFIG_CRYPTO=y
1524# CONFIG_CRYPTO_ANSI_CPRNG is not set 1550# CONFIG_CRYPTO_ANSI_CPRNG is not set
1525CONFIG_CRYPTO_HW=y 1551CONFIG_CRYPTO_HW=y
1526# CONFIG_CRYPTO_DEV_HIFN_795X is not set 1552# CONFIG_CRYPTO_DEV_HIFN_795X is not set
1553CONFIG_BINARY_PRINTF=y
1527 1554
1528# 1555#
1529# Library routines 1556# Library routines
diff --git a/arch/sh/configs/rts7751r2dplus_defconfig b/arch/sh/configs/rts7751r2dplus_defconfig
index 8feef629e49c..a860435b8847 100644
--- a/arch/sh/configs/rts7751r2dplus_defconfig
+++ b/arch/sh/configs/rts7751r2dplus_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:34:12 2009 4# Mon Apr 27 12:59:01 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -70,6 +71,7 @@ CONFIG_UID16=y
70# CONFIG_SYSCTL_SYSCALL is not set 71# CONFIG_SYSCTL_SYSCALL is not set
71CONFIG_KALLSYMS=y 72CONFIG_KALLSYMS=y
72# CONFIG_KALLSYMS_EXTRA_PASS is not set 73# CONFIG_KALLSYMS_EXTRA_PASS is not set
74# CONFIG_STRIP_ASM_SYMS is not set
73CONFIG_HOTPLUG=y 75CONFIG_HOTPLUG=y
74CONFIG_PRINTK=y 76CONFIG_PRINTK=y
75CONFIG_BUG=y 77CONFIG_BUG=y
@@ -99,6 +101,8 @@ CONFIG_HAVE_KPROBES=y
99CONFIG_HAVE_KRETPROBES=y 101CONFIG_HAVE_KRETPROBES=y
100CONFIG_HAVE_ARCH_TRACEHOOK=y 102CONFIG_HAVE_ARCH_TRACEHOOK=y
101CONFIG_HAVE_CLK=y 103CONFIG_HAVE_CLK=y
104CONFIG_HAVE_DMA_API_DEBUG=y
105# CONFIG_SLOW_WORK is not set
102CONFIG_HAVE_GENERIC_DMA_COHERENT=y 106CONFIG_HAVE_GENERIC_DMA_COHERENT=y
103CONFIG_SLABINFO=y 107CONFIG_SLABINFO=y
104CONFIG_RT_MUTEXES=y 108CONFIG_RT_MUTEXES=y
@@ -110,7 +114,6 @@ CONFIG_MODULES=y
110# CONFIG_MODULE_SRCVERSION_ALL is not set 114# CONFIG_MODULE_SRCVERSION_ALL is not set
111CONFIG_BLOCK=y 115CONFIG_BLOCK=y
112# CONFIG_LBD is not set 116# CONFIG_LBD is not set
113# CONFIG_BLK_DEV_IO_TRACE is not set
114# CONFIG_BLK_DEV_BSG is not set 117# CONFIG_BLK_DEV_BSG is not set
115# CONFIG_BLK_DEV_INTEGRITY is not set 118# CONFIG_BLK_DEV_INTEGRITY is not set
116 119
@@ -156,6 +159,7 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
156# CONFIG_CPU_SUBTYPE_SH7760 is not set 159# CONFIG_CPU_SUBTYPE_SH7760 is not set
157# CONFIG_CPU_SUBTYPE_SH4_202 is not set 160# CONFIG_CPU_SUBTYPE_SH4_202 is not set
158# CONFIG_CPU_SUBTYPE_SH7723 is not set 161# CONFIG_CPU_SUBTYPE_SH7723 is not set
162# CONFIG_CPU_SUBTYPE_SH7724 is not set
159# CONFIG_CPU_SUBTYPE_SH7763 is not set 163# CONFIG_CPU_SUBTYPE_SH7763 is not set
160# CONFIG_CPU_SUBTYPE_SH7770 is not set 164# CONFIG_CPU_SUBTYPE_SH7770 is not set
161# CONFIG_CPU_SUBTYPE_SH7780 is not set 165# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -165,8 +169,6 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
165# CONFIG_CPU_SUBTYPE_SH7343 is not set 169# CONFIG_CPU_SUBTYPE_SH7343 is not set
166# CONFIG_CPU_SUBTYPE_SH7722 is not set 170# CONFIG_CPU_SUBTYPE_SH7722 is not set
167# CONFIG_CPU_SUBTYPE_SH7366 is not set 171# CONFIG_CPU_SUBTYPE_SH7366 is not set
168# CONFIG_CPU_SUBTYPE_SH5_101 is not set
169# CONFIG_CPU_SUBTYPE_SH5_103 is not set
170 172
171# 173#
172# Memory management options 174# Memory management options
@@ -302,8 +304,6 @@ CONFIG_CMDLINE="console=tty0 console=ttySC0,115200 root=/dev/sda1 earlyprintk=se
302# 304#
303CONFIG_PCI=y 305CONFIG_PCI=y
304CONFIG_SH_PCIDMA_NONCOHERENT=y 306CONFIG_SH_PCIDMA_NONCOHERENT=y
305CONFIG_PCI_AUTO=y
306CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
307# CONFIG_PCIEPORTBUS is not set 307# CONFIG_PCIEPORTBUS is not set
308# CONFIG_ARCH_SUPPORTS_MSI is not set 308# CONFIG_ARCH_SUPPORTS_MSI is not set
309CONFIG_PCI_LEGACY=y 309CONFIG_PCI_LEGACY=y
@@ -424,7 +424,92 @@ CONFIG_FIRMWARE_IN_KERNEL=y
424CONFIG_EXTRA_FIRMWARE="" 424CONFIG_EXTRA_FIRMWARE=""
425# CONFIG_SYS_HYPERVISOR is not set 425# CONFIG_SYS_HYPERVISOR is not set
426# CONFIG_CONNECTOR is not set 426# CONFIG_CONNECTOR is not set
427# CONFIG_MTD is not set 427CONFIG_MTD=y
428# CONFIG_MTD_DEBUG is not set
429CONFIG_MTD_CONCAT=y
430CONFIG_MTD_PARTITIONS=y
431# CONFIG_MTD_TESTS is not set
432# CONFIG_MTD_REDBOOT_PARTS is not set
433CONFIG_MTD_CMDLINE_PARTS=y
434# CONFIG_MTD_AR7_PARTS is not set
435
436#
437# User Modules And Translation Layers
438#
439CONFIG_MTD_CHAR=y
440# CONFIG_MTD_BLKDEVS is not set
441# CONFIG_MTD_BLOCK is not set
442# CONFIG_MTD_BLOCK_RO is not set
443# CONFIG_FTL is not set
444# CONFIG_NFTL is not set
445# CONFIG_INFTL is not set
446# CONFIG_RFD_FTL is not set
447# CONFIG_SSFDC is not set
448# CONFIG_MTD_OOPS is not set
449
450#
451# RAM/ROM/Flash chip drivers
452#
453CONFIG_MTD_CFI=y
454# CONFIG_MTD_JEDECPROBE is not set
455CONFIG_MTD_GEN_PROBE=y
456# CONFIG_MTD_CFI_ADV_OPTIONS is not set
457CONFIG_MTD_MAP_BANK_WIDTH_1=y
458CONFIG_MTD_MAP_BANK_WIDTH_2=y
459CONFIG_MTD_MAP_BANK_WIDTH_4=y
460# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
461# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
462# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
463CONFIG_MTD_CFI_I1=y
464CONFIG_MTD_CFI_I2=y
465# CONFIG_MTD_CFI_I4 is not set
466# CONFIG_MTD_CFI_I8 is not set
467# CONFIG_MTD_CFI_INTELEXT is not set
468CONFIG_MTD_CFI_AMDSTD=y
469# CONFIG_MTD_CFI_STAA is not set
470CONFIG_MTD_CFI_UTIL=y
471# CONFIG_MTD_RAM is not set
472# CONFIG_MTD_ROM is not set
473# CONFIG_MTD_ABSENT is not set
474
475#
476# Mapping drivers for chip access
477#
478# CONFIG_MTD_COMPLEX_MAPPINGS is not set
479CONFIG_MTD_PHYSMAP=y
480# CONFIG_MTD_PHYSMAP_COMPAT is not set
481# CONFIG_MTD_INTEL_VR_NOR is not set
482# CONFIG_MTD_PLATRAM is not set
483
484#
485# Self-contained MTD device drivers
486#
487# CONFIG_MTD_PMC551 is not set
488# CONFIG_MTD_DATAFLASH is not set
489# CONFIG_MTD_M25P80 is not set
490# CONFIG_MTD_SLRAM is not set
491# CONFIG_MTD_PHRAM is not set
492# CONFIG_MTD_MTDRAM is not set
493# CONFIG_MTD_BLOCK2MTD is not set
494
495#
496# Disk-On-Chip Device Drivers
497#
498# CONFIG_MTD_DOC2000 is not set
499# CONFIG_MTD_DOC2001 is not set
500# CONFIG_MTD_DOC2001PLUS is not set
501# CONFIG_MTD_NAND is not set
502# CONFIG_MTD_ONENAND is not set
503
504#
505# LPDDR flash memory drivers
506#
507# CONFIG_MTD_LPDDR is not set
508
509#
510# UBI - Unsorted block images
511#
512# CONFIG_MTD_UBI is not set
428# CONFIG_PARPORT is not set 513# CONFIG_PARPORT is not set
429CONFIG_BLK_DEV=y 514CONFIG_BLK_DEV=y
430# CONFIG_BLK_CPQ_CISS_DA is not set 515# CONFIG_BLK_CPQ_CISS_DA is not set
@@ -513,6 +598,7 @@ CONFIG_SCSI_LOWLEVEL=y
513# CONFIG_SCSI_MPT2SAS is not set 598# CONFIG_SCSI_MPT2SAS is not set
514# CONFIG_SCSI_HPTIOP is not set 599# CONFIG_SCSI_HPTIOP is not set
515# CONFIG_LIBFC is not set 600# CONFIG_LIBFC is not set
601# CONFIG_LIBFCOE is not set
516# CONFIG_FCOE is not set 602# CONFIG_FCOE is not set
517# CONFIG_SCSI_DMX3191D is not set 603# CONFIG_SCSI_DMX3191D is not set
518# CONFIG_SCSI_FUTURE_DOMAIN is not set 604# CONFIG_SCSI_FUTURE_DOMAIN is not set
@@ -672,6 +758,7 @@ CONFIG_NETDEV_1000=y
672# CONFIG_E1000E is not set 758# CONFIG_E1000E is not set
673# CONFIG_IP1000 is not set 759# CONFIG_IP1000 is not set
674# CONFIG_IGB is not set 760# CONFIG_IGB is not set
761# CONFIG_IGBVF is not set
675# CONFIG_NS83820 is not set 762# CONFIG_NS83820 is not set
676# CONFIG_HAMACHI is not set 763# CONFIG_HAMACHI is not set
677# CONFIG_YELLOWFIN is not set 764# CONFIG_YELLOWFIN is not set
@@ -695,6 +782,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
695# CONFIG_IXGBE is not set 782# CONFIG_IXGBE is not set
696# CONFIG_IXGB is not set 783# CONFIG_IXGB is not set
697# CONFIG_S2IO is not set 784# CONFIG_S2IO is not set
785# CONFIG_VXGE is not set
698# CONFIG_MYRI10GE is not set 786# CONFIG_MYRI10GE is not set
699# CONFIG_NETXEN_NIC is not set 787# CONFIG_NETXEN_NIC is not set
700# CONFIG_NIU is not set 788# CONFIG_NIU is not set
@@ -793,6 +881,7 @@ CONFIG_SERIAL_8250_RUNTIME_UARTS=4
793# 881#
794# Non-8250 serial port support 882# Non-8250 serial port support
795# 883#
884# CONFIG_SERIAL_MAX3100 is not set
796CONFIG_SERIAL_SH_SCI=y 885CONFIG_SERIAL_SH_SCI=y
797CONFIG_SERIAL_SH_SCI_NR_UARTS=1 886CONFIG_SERIAL_SH_SCI_NR_UARTS=1
798CONFIG_SERIAL_SH_SCI_CONSOLE=y 887CONFIG_SERIAL_SH_SCI_CONSOLE=y
@@ -1079,15 +1168,17 @@ CONFIG_USB_HID=y
1079# 1168#
1080# Special HID drivers 1169# Special HID drivers
1081# 1170#
1082CONFIG_HID_COMPAT=y
1083CONFIG_HID_A4TECH=y 1171CONFIG_HID_A4TECH=y
1084CONFIG_HID_APPLE=y 1172CONFIG_HID_APPLE=y
1085CONFIG_HID_BELKIN=y 1173CONFIG_HID_BELKIN=y
1086CONFIG_HID_CHERRY=y 1174CONFIG_HID_CHERRY=y
1087CONFIG_HID_CHICONY=y 1175CONFIG_HID_CHICONY=y
1088CONFIG_HID_CYPRESS=y 1176CONFIG_HID_CYPRESS=y
1177# CONFIG_DRAGONRISE_FF is not set
1089CONFIG_HID_EZKEY=y 1178CONFIG_HID_EZKEY=y
1179# CONFIG_HID_KYE is not set
1090CONFIG_HID_GYRATION=y 1180CONFIG_HID_GYRATION=y
1181# CONFIG_HID_KENSINGTON is not set
1091CONFIG_HID_LOGITECH=y 1182CONFIG_HID_LOGITECH=y
1092# CONFIG_LOGITECH_FF is not set 1183# CONFIG_LOGITECH_FF is not set
1093# CONFIG_LOGIRUMBLEPAD2_FF is not set 1184# CONFIG_LOGIRUMBLEPAD2_FF is not set
@@ -1291,6 +1382,11 @@ CONFIG_INOTIFY_USER=y
1291# CONFIG_FUSE_FS is not set 1382# CONFIG_FUSE_FS is not set
1292 1383
1293# 1384#
1385# Caches
1386#
1387# CONFIG_FSCACHE is not set
1388
1389#
1294# CD-ROM/DVD Filesystems 1390# CD-ROM/DVD Filesystems
1295# 1391#
1296# CONFIG_ISO9660_FS is not set 1392# CONFIG_ISO9660_FS is not set
@@ -1337,6 +1433,7 @@ CONFIG_MINIX_FS=y
1337# CONFIG_ROMFS_FS is not set 1433# CONFIG_ROMFS_FS is not set
1338# CONFIG_SYSV_FS is not set 1434# CONFIG_SYSV_FS is not set
1339# CONFIG_UFS_FS is not set 1435# CONFIG_UFS_FS is not set
1436# CONFIG_NILFS2_FS is not set
1340CONFIG_NETWORK_FILESYSTEMS=y 1437CONFIG_NETWORK_FILESYSTEMS=y
1341# CONFIG_NFS_FS is not set 1438# CONFIG_NFS_FS is not set
1342# CONFIG_NFSD is not set 1439# CONFIG_NFSD is not set
@@ -1417,11 +1514,25 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
1417CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1514CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1418CONFIG_RING_BUFFER=y 1515CONFIG_RING_BUFFER=y
1419CONFIG_TRACING=y 1516CONFIG_TRACING=y
1517CONFIG_TRACING_SUPPORT=y
1420 1518
1421# 1519#
1422# Tracers 1520# Tracers
1423# 1521#
1522# CONFIG_FUNCTION_TRACER is not set
1523# CONFIG_IRQSOFF_TRACER is not set
1524# CONFIG_SCHED_TRACER is not set
1525# CONFIG_CONTEXT_SWITCH_TRACER is not set
1526# CONFIG_EVENT_TRACER is not set
1527# CONFIG_BOOT_TRACER is not set
1528# CONFIG_TRACE_BRANCH_PROFILING is not set
1529# CONFIG_STACK_TRACER is not set
1530# CONFIG_KMEMTRACE is not set
1531# CONFIG_WORKQUEUE_TRACER is not set
1532# CONFIG_BLK_DEV_IO_TRACE is not set
1533# CONFIG_FTRACE_STARTUP_TEST is not set
1424# CONFIG_DYNAMIC_DEBUG is not set 1534# CONFIG_DYNAMIC_DEBUG is not set
1535# CONFIG_DMA_API_DEBUG is not set
1425# CONFIG_SAMPLES is not set 1536# CONFIG_SAMPLES is not set
1426CONFIG_HAVE_ARCH_KGDB=y 1537CONFIG_HAVE_ARCH_KGDB=y
1427# CONFIG_SH_STANDARD_BIOS is not set 1538# CONFIG_SH_STANDARD_BIOS is not set
@@ -1524,6 +1635,7 @@ CONFIG_CRYPTO=y
1524# CONFIG_CRYPTO_ANSI_CPRNG is not set 1635# CONFIG_CRYPTO_ANSI_CPRNG is not set
1525CONFIG_CRYPTO_HW=y 1636CONFIG_CRYPTO_HW=y
1526# CONFIG_CRYPTO_DEV_HIFN_795X is not set 1637# CONFIG_CRYPTO_DEV_HIFN_795X is not set
1638CONFIG_BINARY_PRINTF=y
1527 1639
1528# 1640#
1529# Library routines 1641# Library routines
diff --git a/arch/sh/configs/sdk7780_defconfig b/arch/sh/configs/sdk7780_defconfig
index 739e2299ae80..a629b79a1844 100644
--- a/arch/sh/configs/sdk7780_defconfig
+++ b/arch/sh/configs/sdk7780_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:34:43 2009 4# Mon Apr 27 12:59:32 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -41,6 +42,7 @@ CONFIG_SWAP=y
41CONFIG_SYSVIPC=y 42CONFIG_SYSVIPC=y
42CONFIG_SYSVIPC_SYSCTL=y 43CONFIG_SYSVIPC_SYSCTL=y
43CONFIG_POSIX_MQUEUE=y 44CONFIG_POSIX_MQUEUE=y
45CONFIG_POSIX_MQUEUE_SYSCTL=y
44CONFIG_BSD_PROCESS_ACCT=y 46CONFIG_BSD_PROCESS_ACCT=y
45# CONFIG_BSD_PROCESS_ACCT_V3 is not set 47# CONFIG_BSD_PROCESS_ACCT_V3 is not set
46# CONFIG_TASKSTATS is not set 48# CONFIG_TASKSTATS is not set
@@ -73,6 +75,7 @@ CONFIG_SYSCTL_SYSCALL=y
73CONFIG_KALLSYMS=y 75CONFIG_KALLSYMS=y
74CONFIG_KALLSYMS_ALL=y 76CONFIG_KALLSYMS_ALL=y
75# CONFIG_KALLSYMS_EXTRA_PASS is not set 77# CONFIG_KALLSYMS_EXTRA_PASS is not set
78# CONFIG_STRIP_ASM_SYMS is not set
76CONFIG_HOTPLUG=y 79CONFIG_HOTPLUG=y
77CONFIG_PRINTK=y 80CONFIG_PRINTK=y
78CONFIG_BUG=y 81CONFIG_BUG=y
@@ -93,6 +96,7 @@ CONFIG_COMPAT_BRK=y
93CONFIG_SLUB=y 96CONFIG_SLUB=y
94# CONFIG_SLOB is not set 97# CONFIG_SLOB is not set
95# CONFIG_PROFILING is not set 98# CONFIG_PROFILING is not set
99# CONFIG_MARKERS is not set
96CONFIG_HAVE_OPROFILE=y 100CONFIG_HAVE_OPROFILE=y
97# CONFIG_KPROBES is not set 101# CONFIG_KPROBES is not set
98CONFIG_HAVE_IOREMAP_PROT=y 102CONFIG_HAVE_IOREMAP_PROT=y
@@ -100,6 +104,8 @@ CONFIG_HAVE_KPROBES=y
100CONFIG_HAVE_KRETPROBES=y 104CONFIG_HAVE_KRETPROBES=y
101CONFIG_HAVE_ARCH_TRACEHOOK=y 105CONFIG_HAVE_ARCH_TRACEHOOK=y
102CONFIG_HAVE_CLK=y 106CONFIG_HAVE_CLK=y
107CONFIG_HAVE_DMA_API_DEBUG=y
108# CONFIG_SLOW_WORK is not set
103CONFIG_HAVE_GENERIC_DMA_COHERENT=y 109CONFIG_HAVE_GENERIC_DMA_COHERENT=y
104CONFIG_SLABINFO=y 110CONFIG_SLABINFO=y
105CONFIG_RT_MUTEXES=y 111CONFIG_RT_MUTEXES=y
@@ -112,7 +118,6 @@ CONFIG_MODULE_FORCE_UNLOAD=y
112# CONFIG_MODULE_SRCVERSION_ALL is not set 118# CONFIG_MODULE_SRCVERSION_ALL is not set
113CONFIG_BLOCK=y 119CONFIG_BLOCK=y
114CONFIG_LBD=y 120CONFIG_LBD=y
115# CONFIG_BLK_DEV_IO_TRACE is not set
116# CONFIG_BLK_DEV_BSG is not set 121# CONFIG_BLK_DEV_BSG is not set
117# CONFIG_BLK_DEV_INTEGRITY is not set 122# CONFIG_BLK_DEV_INTEGRITY is not set
118 123
@@ -159,6 +164,7 @@ CONFIG_CPU_SH4A=y
159# CONFIG_CPU_SUBTYPE_SH7760 is not set 164# CONFIG_CPU_SUBTYPE_SH7760 is not set
160# CONFIG_CPU_SUBTYPE_SH4_202 is not set 165# CONFIG_CPU_SUBTYPE_SH4_202 is not set
161# CONFIG_CPU_SUBTYPE_SH7723 is not set 166# CONFIG_CPU_SUBTYPE_SH7723 is not set
167# CONFIG_CPU_SUBTYPE_SH7724 is not set
162# CONFIG_CPU_SUBTYPE_SH7763 is not set 168# CONFIG_CPU_SUBTYPE_SH7763 is not set
163# CONFIG_CPU_SUBTYPE_SH7770 is not set 169# CONFIG_CPU_SUBTYPE_SH7770 is not set
164CONFIG_CPU_SUBTYPE_SH7780=y 170CONFIG_CPU_SUBTYPE_SH7780=y
@@ -168,8 +174,6 @@ CONFIG_CPU_SUBTYPE_SH7780=y
168# CONFIG_CPU_SUBTYPE_SH7343 is not set 174# CONFIG_CPU_SUBTYPE_SH7343 is not set
169# CONFIG_CPU_SUBTYPE_SH7722 is not set 175# CONFIG_CPU_SUBTYPE_SH7722 is not set
170# CONFIG_CPU_SUBTYPE_SH7366 is not set 176# CONFIG_CPU_SUBTYPE_SH7366 is not set
171# CONFIG_CPU_SUBTYPE_SH5_101 is not set
172# CONFIG_CPU_SUBTYPE_SH5_103 is not set
173 177
174# 178#
175# Memory management options 179# Memory management options
@@ -310,8 +314,6 @@ CONFIG_CMDLINE="mem=128M console=tty0 console=ttySC0,115200 ip=bootp root=/dev/n
310# 314#
311CONFIG_PCI=y 315CONFIG_PCI=y
312CONFIG_SH_PCIDMA_NONCOHERENT=y 316CONFIG_SH_PCIDMA_NONCOHERENT=y
313CONFIG_PCI_AUTO=y
314CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
315# CONFIG_PCIEPORTBUS is not set 317# CONFIG_PCIEPORTBUS is not set
316# CONFIG_ARCH_SUPPORTS_MSI is not set 318# CONFIG_ARCH_SUPPORTS_MSI is not set
317# CONFIG_PCI_LEGACY is not set 319# CONFIG_PCI_LEGACY is not set
@@ -646,6 +648,7 @@ CONFIG_SCSI_LOWLEVEL=y
646# CONFIG_SCSI_MPT2SAS is not set 648# CONFIG_SCSI_MPT2SAS is not set
647# CONFIG_SCSI_HPTIOP is not set 649# CONFIG_SCSI_HPTIOP is not set
648# CONFIG_LIBFC is not set 650# CONFIG_LIBFC is not set
651# CONFIG_LIBFCOE is not set
649# CONFIG_FCOE is not set 652# CONFIG_FCOE is not set
650# CONFIG_SCSI_DMX3191D is not set 653# CONFIG_SCSI_DMX3191D is not set
651# CONFIG_SCSI_FUTURE_DOMAIN is not set 654# CONFIG_SCSI_FUTURE_DOMAIN is not set
@@ -1091,15 +1094,17 @@ CONFIG_USB_HID=y
1091# 1094#
1092# Special HID drivers 1095# Special HID drivers
1093# 1096#
1094CONFIG_HID_COMPAT=y
1095CONFIG_HID_A4TECH=y 1097CONFIG_HID_A4TECH=y
1096CONFIG_HID_APPLE=y 1098CONFIG_HID_APPLE=y
1097CONFIG_HID_BELKIN=y 1099CONFIG_HID_BELKIN=y
1098CONFIG_HID_CHERRY=y 1100CONFIG_HID_CHERRY=y
1099CONFIG_HID_CHICONY=y 1101CONFIG_HID_CHICONY=y
1100CONFIG_HID_CYPRESS=y 1102CONFIG_HID_CYPRESS=y
1103# CONFIG_DRAGONRISE_FF is not set
1101CONFIG_HID_EZKEY=y 1104CONFIG_HID_EZKEY=y
1105# CONFIG_HID_KYE is not set
1102CONFIG_HID_GYRATION=y 1106CONFIG_HID_GYRATION=y
1107# CONFIG_HID_KENSINGTON is not set
1103CONFIG_HID_LOGITECH=y 1108CONFIG_HID_LOGITECH=y
1104# CONFIG_LOGITECH_FF is not set 1109# CONFIG_LOGITECH_FF is not set
1105# CONFIG_LOGIRUMBLEPAD2_FF is not set 1110# CONFIG_LOGIRUMBLEPAD2_FF is not set
@@ -1257,6 +1262,7 @@ CONFIG_EXT2_FS_POSIX_ACL=y
1257# CONFIG_EXT2_FS_SECURITY is not set 1262# CONFIG_EXT2_FS_SECURITY is not set
1258# CONFIG_EXT2_FS_XIP is not set 1263# CONFIG_EXT2_FS_XIP is not set
1259CONFIG_EXT3_FS=y 1264CONFIG_EXT3_FS=y
1265# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
1260CONFIG_EXT3_FS_XATTR=y 1266CONFIG_EXT3_FS_XATTR=y
1261CONFIG_EXT3_FS_POSIX_ACL=y 1267CONFIG_EXT3_FS_POSIX_ACL=y
1262# CONFIG_EXT3_FS_SECURITY is not set 1268# CONFIG_EXT3_FS_SECURITY is not set
@@ -1281,6 +1287,11 @@ CONFIG_AUTOFS4_FS=y
1281CONFIG_GENERIC_ACL=y 1287CONFIG_GENERIC_ACL=y
1282 1288
1283# 1289#
1290# Caches
1291#
1292# CONFIG_FSCACHE is not set
1293
1294#
1284# CD-ROM/DVD Filesystems 1295# CD-ROM/DVD Filesystems
1285# 1296#
1286CONFIG_ISO9660_FS=y 1297CONFIG_ISO9660_FS=y
@@ -1331,6 +1342,7 @@ CONFIG_MINIX_FS=y
1331# CONFIG_ROMFS_FS is not set 1342# CONFIG_ROMFS_FS is not set
1332# CONFIG_SYSV_FS is not set 1343# CONFIG_SYSV_FS is not set
1333# CONFIG_UFS_FS is not set 1344# CONFIG_UFS_FS is not set
1345# CONFIG_NILFS2_FS is not set
1334CONFIG_NETWORK_FILESYSTEMS=y 1346CONFIG_NETWORK_FILESYSTEMS=y
1335CONFIG_NFS_FS=y 1347CONFIG_NFS_FS=y
1336CONFIG_NFS_V3=y 1348CONFIG_NFS_V3=y
@@ -1418,6 +1430,9 @@ CONFIG_DEBUG_KERNEL=y
1418CONFIG_DETECT_SOFTLOCKUP=y 1430CONFIG_DETECT_SOFTLOCKUP=y
1419# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set 1431# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
1420CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0 1432CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
1433CONFIG_DETECT_HUNG_TASK=y
1434# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
1435CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
1421# CONFIG_SCHED_DEBUG is not set 1436# CONFIG_SCHED_DEBUG is not set
1422# CONFIG_SCHEDSTATS is not set 1437# CONFIG_SCHEDSTATS is not set
1423CONFIG_TIMER_STATS=y 1438CONFIG_TIMER_STATS=y
@@ -1455,6 +1470,7 @@ CONFIG_SYSCTL_SYSCALL_CHECK=y
1455CONFIG_HAVE_FUNCTION_TRACER=y 1470CONFIG_HAVE_FUNCTION_TRACER=y
1456CONFIG_HAVE_DYNAMIC_FTRACE=y 1471CONFIG_HAVE_DYNAMIC_FTRACE=y
1457CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1472CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1473CONFIG_TRACING_SUPPORT=y
1458 1474
1459# 1475#
1460# Tracers 1476# Tracers
@@ -1464,9 +1480,14 @@ CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1464# CONFIG_PREEMPT_TRACER is not set 1480# CONFIG_PREEMPT_TRACER is not set
1465# CONFIG_SCHED_TRACER is not set 1481# CONFIG_SCHED_TRACER is not set
1466# CONFIG_CONTEXT_SWITCH_TRACER is not set 1482# CONFIG_CONTEXT_SWITCH_TRACER is not set
1483# CONFIG_EVENT_TRACER is not set
1467# CONFIG_BOOT_TRACER is not set 1484# CONFIG_BOOT_TRACER is not set
1468# CONFIG_TRACE_BRANCH_PROFILING is not set 1485# CONFIG_TRACE_BRANCH_PROFILING is not set
1469# CONFIG_STACK_TRACER is not set 1486# CONFIG_STACK_TRACER is not set
1487# CONFIG_KMEMTRACE is not set
1488# CONFIG_WORKQUEUE_TRACER is not set
1489# CONFIG_BLK_DEV_IO_TRACE is not set
1490# CONFIG_DMA_API_DEBUG is not set
1470# CONFIG_SAMPLES is not set 1491# CONFIG_SAMPLES is not set
1471CONFIG_HAVE_ARCH_KGDB=y 1492CONFIG_HAVE_ARCH_KGDB=y
1472# CONFIG_KGDB is not set 1493# CONFIG_KGDB is not set
@@ -1580,6 +1601,7 @@ CONFIG_CRYPTO_DES=y
1580# CONFIG_CRYPTO_ANSI_CPRNG is not set 1601# CONFIG_CRYPTO_ANSI_CPRNG is not set
1581CONFIG_CRYPTO_HW=y 1602CONFIG_CRYPTO_HW=y
1582# CONFIG_CRYPTO_DEV_HIFN_795X is not set 1603# CONFIG_CRYPTO_DEV_HIFN_795X is not set
1604# CONFIG_BINARY_PRINTF is not set
1583 1605
1584# 1606#
1585# Library routines 1607# Library routines
diff --git a/arch/sh/configs/se7206_defconfig b/arch/sh/configs/se7206_defconfig
index d30e0a7ad9f1..5caf85a3312d 100644
--- a/arch/sh/configs/se7206_defconfig
+++ b/arch/sh/configs/se7206_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:39:37 2009 4# Mon Apr 27 13:01:02 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -40,6 +41,7 @@ CONFIG_LOCALVERSION_AUTO=y
40CONFIG_SYSVIPC=y 41CONFIG_SYSVIPC=y
41CONFIG_SYSVIPC_SYSCTL=y 42CONFIG_SYSVIPC_SYSCTL=y
42CONFIG_POSIX_MQUEUE=y 43CONFIG_POSIX_MQUEUE=y
44CONFIG_POSIX_MQUEUE_SYSCTL=y
43CONFIG_BSD_PROCESS_ACCT=y 45CONFIG_BSD_PROCESS_ACCT=y
44# CONFIG_BSD_PROCESS_ACCT_V3 is not set 46# CONFIG_BSD_PROCESS_ACCT_V3 is not set
45# CONFIG_TASKSTATS is not set 47# CONFIG_TASKSTATS is not set
@@ -63,6 +65,7 @@ CONFIG_CGROUP_DEBUG=y
63CONFIG_CGROUP_NS=y 65CONFIG_CGROUP_NS=y
64# CONFIG_CGROUP_FREEZER is not set 66# CONFIG_CGROUP_FREEZER is not set
65CONFIG_CGROUP_DEVICE=y 67CONFIG_CGROUP_DEVICE=y
68# CONFIG_CPUSETS is not set
66CONFIG_CGROUP_CPUACCT=y 69CONFIG_CGROUP_CPUACCT=y
67CONFIG_RESOURCE_COUNTERS=y 70CONFIG_RESOURCE_COUNTERS=y
68CONFIG_CGROUP_MEM_RES_CTLR=y 71CONFIG_CGROUP_MEM_RES_CTLR=y
@@ -80,7 +83,6 @@ CONFIG_INITRAMFS_SOURCE=""
80CONFIG_RD_GZIP=y 83CONFIG_RD_GZIP=y
81# CONFIG_RD_BZIP2 is not set 84# CONFIG_RD_BZIP2 is not set
82# CONFIG_RD_LZMA is not set 85# CONFIG_RD_LZMA is not set
83CONFIG_INITRAMFS_COMPRESSION_NONE=y
84CONFIG_CC_OPTIMIZE_FOR_SIZE=y 86CONFIG_CC_OPTIMIZE_FOR_SIZE=y
85CONFIG_SYSCTL=y 87CONFIG_SYSCTL=y
86CONFIG_ANON_INODES=y 88CONFIG_ANON_INODES=y
@@ -90,6 +92,7 @@ CONFIG_EMBEDDED=y
90CONFIG_KALLSYMS=y 92CONFIG_KALLSYMS=y
91CONFIG_KALLSYMS_ALL=y 93CONFIG_KALLSYMS_ALL=y
92# CONFIG_KALLSYMS_EXTRA_PASS is not set 94# CONFIG_KALLSYMS_EXTRA_PASS is not set
95# CONFIG_STRIP_ASM_SYMS is not set
93CONFIG_HOTPLUG=y 96CONFIG_HOTPLUG=y
94CONFIG_PRINTK=y 97CONFIG_PRINTK=y
95CONFIG_BUG=y 98CONFIG_BUG=y
@@ -116,6 +119,8 @@ CONFIG_HAVE_KPROBES=y
116CONFIG_HAVE_KRETPROBES=y 119CONFIG_HAVE_KRETPROBES=y
117CONFIG_HAVE_ARCH_TRACEHOOK=y 120CONFIG_HAVE_ARCH_TRACEHOOK=y
118CONFIG_HAVE_CLK=y 121CONFIG_HAVE_CLK=y
122CONFIG_HAVE_DMA_API_DEBUG=y
123# CONFIG_SLOW_WORK is not set
119CONFIG_HAVE_GENERIC_DMA_COHERENT=y 124CONFIG_HAVE_GENERIC_DMA_COHERENT=y
120CONFIG_RT_MUTEXES=y 125CONFIG_RT_MUTEXES=y
121CONFIG_BASE_SMALL=0 126CONFIG_BASE_SMALL=0
@@ -127,7 +132,6 @@ CONFIG_MODULE_UNLOAD=y
127# CONFIG_MODULE_SRCVERSION_ALL is not set 132# CONFIG_MODULE_SRCVERSION_ALL is not set
128CONFIG_BLOCK=y 133CONFIG_BLOCK=y
129# CONFIG_LBD is not set 134# CONFIG_LBD is not set
130# CONFIG_BLK_DEV_IO_TRACE is not set
131# CONFIG_BLK_DEV_BSG is not set 135# CONFIG_BLK_DEV_BSG is not set
132# CONFIG_BLK_DEV_INTEGRITY is not set 136# CONFIG_BLK_DEV_INTEGRITY is not set
133 137
@@ -174,6 +178,7 @@ CONFIG_CPU_SUBTYPE_SH7206=y
174# CONFIG_CPU_SUBTYPE_SH7760 is not set 178# CONFIG_CPU_SUBTYPE_SH7760 is not set
175# CONFIG_CPU_SUBTYPE_SH4_202 is not set 179# CONFIG_CPU_SUBTYPE_SH4_202 is not set
176# CONFIG_CPU_SUBTYPE_SH7723 is not set 180# CONFIG_CPU_SUBTYPE_SH7723 is not set
181# CONFIG_CPU_SUBTYPE_SH7724 is not set
177# CONFIG_CPU_SUBTYPE_SH7763 is not set 182# CONFIG_CPU_SUBTYPE_SH7763 is not set
178# CONFIG_CPU_SUBTYPE_SH7770 is not set 183# CONFIG_CPU_SUBTYPE_SH7770 is not set
179# CONFIG_CPU_SUBTYPE_SH7780 is not set 184# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -183,8 +188,6 @@ CONFIG_CPU_SUBTYPE_SH7206=y
183# CONFIG_CPU_SUBTYPE_SH7343 is not set 188# CONFIG_CPU_SUBTYPE_SH7343 is not set
184# CONFIG_CPU_SUBTYPE_SH7722 is not set 189# CONFIG_CPU_SUBTYPE_SH7722 is not set
185# CONFIG_CPU_SUBTYPE_SH7366 is not set 190# CONFIG_CPU_SUBTYPE_SH7366 is not set
186# CONFIG_CPU_SUBTYPE_SH5_101 is not set
187# CONFIG_CPU_SUBTYPE_SH5_103 is not set
188 191
189# 192#
190# Memory management options 193# Memory management options
@@ -746,6 +749,11 @@ CONFIG_FILE_LOCKING=y
746# CONFIG_FUSE_FS is not set 749# CONFIG_FUSE_FS is not set
747 750
748# 751#
752# Caches
753#
754# CONFIG_FSCACHE is not set
755
756#
749# CD-ROM/DVD Filesystems 757# CD-ROM/DVD Filesystems
750# 758#
751# CONFIG_ISO9660_FS is not set 759# CONFIG_ISO9660_FS is not set
@@ -785,8 +793,13 @@ CONFIG_CRAMFS=y
785# CONFIG_HPFS_FS is not set 793# CONFIG_HPFS_FS is not set
786# CONFIG_QNX4FS_FS is not set 794# CONFIG_QNX4FS_FS is not set
787CONFIG_ROMFS_FS=y 795CONFIG_ROMFS_FS=y
796CONFIG_ROMFS_BACKED_BY_BLOCK=y
797# CONFIG_ROMFS_BACKED_BY_MTD is not set
798# CONFIG_ROMFS_BACKED_BY_BOTH is not set
799CONFIG_ROMFS_ON_BLOCK=y
788# CONFIG_SYSV_FS is not set 800# CONFIG_SYSV_FS is not set
789# CONFIG_UFS_FS is not set 801# CONFIG_UFS_FS is not set
802# CONFIG_NILFS2_FS is not set
790CONFIG_NETWORK_FILESYSTEMS=y 803CONFIG_NETWORK_FILESYSTEMS=y
791CONFIG_NFS_FS=y 804CONFIG_NFS_FS=y
792CONFIG_NFS_V3=y 805CONFIG_NFS_V3=y
@@ -831,6 +844,9 @@ CONFIG_DEBUG_KERNEL=y
831CONFIG_DETECT_SOFTLOCKUP=y 844CONFIG_DETECT_SOFTLOCKUP=y
832# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set 845# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
833CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0 846CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
847CONFIG_DETECT_HUNG_TASK=y
848# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
849CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
834CONFIG_SCHED_DEBUG=y 850CONFIG_SCHED_DEBUG=y
835# CONFIG_SCHEDSTATS is not set 851# CONFIG_SCHEDSTATS is not set
836# CONFIG_TIMER_STATS is not set 852# CONFIG_TIMER_STATS is not set
@@ -869,6 +885,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
869CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 885CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
870CONFIG_RING_BUFFER=y 886CONFIG_RING_BUFFER=y
871CONFIG_TRACING=y 887CONFIG_TRACING=y
888CONFIG_TRACING_SUPPORT=y
872 889
873# 890#
874# Tracers 891# Tracers
@@ -876,11 +893,16 @@ CONFIG_TRACING=y
876# CONFIG_FUNCTION_TRACER is not set 893# CONFIG_FUNCTION_TRACER is not set
877# CONFIG_SCHED_TRACER is not set 894# CONFIG_SCHED_TRACER is not set
878# CONFIG_CONTEXT_SWITCH_TRACER is not set 895# CONFIG_CONTEXT_SWITCH_TRACER is not set
896# CONFIG_EVENT_TRACER is not set
879# CONFIG_BOOT_TRACER is not set 897# CONFIG_BOOT_TRACER is not set
880# CONFIG_TRACE_BRANCH_PROFILING is not set 898# CONFIG_TRACE_BRANCH_PROFILING is not set
881# CONFIG_STACK_TRACER is not set 899# CONFIG_STACK_TRACER is not set
900# CONFIG_KMEMTRACE is not set
901# CONFIG_WORKQUEUE_TRACER is not set
902# CONFIG_BLK_DEV_IO_TRACE is not set
882# CONFIG_FTRACE_STARTUP_TEST is not set 903# CONFIG_FTRACE_STARTUP_TEST is not set
883# CONFIG_DYNAMIC_DEBUG is not set 904# CONFIG_DYNAMIC_DEBUG is not set
905# CONFIG_DMA_API_DEBUG is not set
884# CONFIG_SAMPLES is not set 906# CONFIG_SAMPLES is not set
885CONFIG_HAVE_ARCH_KGDB=y 907CONFIG_HAVE_ARCH_KGDB=y
886# CONFIG_KGDB is not set 908# CONFIG_KGDB is not set
@@ -991,6 +1013,7 @@ CONFIG_CRYPTO_LZO=y
991# 1013#
992# CONFIG_CRYPTO_ANSI_CPRNG is not set 1014# CONFIG_CRYPTO_ANSI_CPRNG is not set
993# CONFIG_CRYPTO_HW is not set 1015# CONFIG_CRYPTO_HW is not set
1016CONFIG_BINARY_PRINTF=y
994 1017
995# 1018#
996# Library routines 1019# Library routines
diff --git a/arch/sh/configs/se7343_defconfig b/arch/sh/configs/se7343_defconfig
index fbb72d029e68..004d531716dc 100644
--- a/arch/sh/configs/se7343_defconfig
+++ b/arch/sh/configs/se7343_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:42:00 2009 4# Mon Apr 27 13:01:44 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -40,6 +41,7 @@ CONFIG_LOCALVERSION_AUTO=y
40CONFIG_SYSVIPC=y 41CONFIG_SYSVIPC=y
41CONFIG_SYSVIPC_SYSCTL=y 42CONFIG_SYSVIPC_SYSCTL=y
42CONFIG_POSIX_MQUEUE=y 43CONFIG_POSIX_MQUEUE=y
44CONFIG_POSIX_MQUEUE_SYSCTL=y
43# CONFIG_BSD_PROCESS_ACCT is not set 45# CONFIG_BSD_PROCESS_ACCT is not set
44# CONFIG_TASKSTATS is not set 46# CONFIG_TASKSTATS is not set
45# CONFIG_AUDIT is not set 47# CONFIG_AUDIT is not set
@@ -73,6 +75,7 @@ CONFIG_UID16=y
73# CONFIG_SYSCTL_SYSCALL is not set 75# CONFIG_SYSCTL_SYSCALL is not set
74CONFIG_KALLSYMS=y 76CONFIG_KALLSYMS=y
75# CONFIG_KALLSYMS_EXTRA_PASS is not set 77# CONFIG_KALLSYMS_EXTRA_PASS is not set
78# CONFIG_STRIP_ASM_SYMS is not set
76CONFIG_HOTPLUG=y 79CONFIG_HOTPLUG=y
77CONFIG_PRINTK=y 80CONFIG_PRINTK=y
78CONFIG_BUG=y 81CONFIG_BUG=y
@@ -91,6 +94,7 @@ CONFIG_SLAB=y
91# CONFIG_SLUB is not set 94# CONFIG_SLUB is not set
92# CONFIG_SLOB is not set 95# CONFIG_SLOB is not set
93# CONFIG_PROFILING is not set 96# CONFIG_PROFILING is not set
97# CONFIG_MARKERS is not set
94CONFIG_HAVE_OPROFILE=y 98CONFIG_HAVE_OPROFILE=y
95# CONFIG_KPROBES is not set 99# CONFIG_KPROBES is not set
96CONFIG_HAVE_IOREMAP_PROT=y 100CONFIG_HAVE_IOREMAP_PROT=y
@@ -98,6 +102,8 @@ CONFIG_HAVE_KPROBES=y
98CONFIG_HAVE_KRETPROBES=y 102CONFIG_HAVE_KRETPROBES=y
99CONFIG_HAVE_ARCH_TRACEHOOK=y 103CONFIG_HAVE_ARCH_TRACEHOOK=y
100CONFIG_HAVE_CLK=y 104CONFIG_HAVE_CLK=y
105CONFIG_HAVE_DMA_API_DEBUG=y
106# CONFIG_SLOW_WORK is not set
101CONFIG_HAVE_GENERIC_DMA_COHERENT=y 107CONFIG_HAVE_GENERIC_DMA_COHERENT=y
102CONFIG_SLABINFO=y 108CONFIG_SLABINFO=y
103CONFIG_BASE_SMALL=0 109CONFIG_BASE_SMALL=0
@@ -109,7 +115,6 @@ CONFIG_MODULE_FORCE_UNLOAD=y
109# CONFIG_MODULE_SRCVERSION_ALL is not set 115# CONFIG_MODULE_SRCVERSION_ALL is not set
110CONFIG_BLOCK=y 116CONFIG_BLOCK=y
111# CONFIG_LBD is not set 117# CONFIG_LBD is not set
112# CONFIG_BLK_DEV_IO_TRACE is not set
113# CONFIG_BLK_DEV_BSG is not set 118# CONFIG_BLK_DEV_BSG is not set
114# CONFIG_BLK_DEV_INTEGRITY is not set 119# CONFIG_BLK_DEV_INTEGRITY is not set
115 120
@@ -158,6 +163,7 @@ CONFIG_ARCH_SHMOBILE=y
158# CONFIG_CPU_SUBTYPE_SH7760 is not set 163# CONFIG_CPU_SUBTYPE_SH7760 is not set
159# CONFIG_CPU_SUBTYPE_SH4_202 is not set 164# CONFIG_CPU_SUBTYPE_SH4_202 is not set
160# CONFIG_CPU_SUBTYPE_SH7723 is not set 165# CONFIG_CPU_SUBTYPE_SH7723 is not set
166# CONFIG_CPU_SUBTYPE_SH7724 is not set
161# CONFIG_CPU_SUBTYPE_SH7763 is not set 167# CONFIG_CPU_SUBTYPE_SH7763 is not set
162# CONFIG_CPU_SUBTYPE_SH7770 is not set 168# CONFIG_CPU_SUBTYPE_SH7770 is not set
163# CONFIG_CPU_SUBTYPE_SH7780 is not set 169# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -167,8 +173,6 @@ CONFIG_ARCH_SHMOBILE=y
167CONFIG_CPU_SUBTYPE_SH7343=y 173CONFIG_CPU_SUBTYPE_SH7343=y
168# CONFIG_CPU_SUBTYPE_SH7722 is not set 174# CONFIG_CPU_SUBTYPE_SH7722 is not set
169# CONFIG_CPU_SUBTYPE_SH7366 is not set 175# CONFIG_CPU_SUBTYPE_SH7366 is not set
170# CONFIG_CPU_SUBTYPE_SH5_101 is not set
171# CONFIG_CPU_SUBTYPE_SH5_103 is not set
172 176
173# 177#
174# Memory management options 178# Memory management options
@@ -769,6 +773,7 @@ CONFIG_VIDEO_HELPER_CHIPS_AUTO=y
769# CONFIG_SOC_CAMERA is not set 773# CONFIG_SOC_CAMERA is not set
770CONFIG_V4L_USB_DRIVERS=y 774CONFIG_V4L_USB_DRIVERS=y
771# CONFIG_USB_VIDEO_CLASS is not set 775# CONFIG_USB_VIDEO_CLASS is not set
776CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV=y
772CONFIG_USB_GSPCA=m 777CONFIG_USB_GSPCA=m
773# CONFIG_USB_M5602 is not set 778# CONFIG_USB_M5602 is not set
774# CONFIG_USB_STV06XX is not set 779# CONFIG_USB_STV06XX is not set
@@ -800,6 +805,7 @@ CONFIG_USB_GSPCA=m
800# CONFIG_VIDEO_PVRUSB2 is not set 805# CONFIG_VIDEO_PVRUSB2 is not set
801# CONFIG_VIDEO_HDPVR is not set 806# CONFIG_VIDEO_HDPVR is not set
802# CONFIG_VIDEO_EM28XX is not set 807# CONFIG_VIDEO_EM28XX is not set
808# CONFIG_VIDEO_CX231XX is not set
803# CONFIG_VIDEO_USBVISION is not set 809# CONFIG_VIDEO_USBVISION is not set
804# CONFIG_USB_VICAM is not set 810# CONFIG_USB_VICAM is not set
805# CONFIG_USB_IBMCAM is not set 811# CONFIG_USB_IBMCAM is not set
@@ -813,6 +819,7 @@ CONFIG_USB_GSPCA=m
813# CONFIG_USB_STV680 is not set 819# CONFIG_USB_STV680 is not set
814# CONFIG_USB_ZC0301 is not set 820# CONFIG_USB_ZC0301 is not set
815# CONFIG_USB_PWC is not set 821# CONFIG_USB_PWC is not set
822CONFIG_USB_PWC_INPUT_EVDEV=y
816# CONFIG_USB_ZR364XX is not set 823# CONFIG_USB_ZR364XX is not set
817# CONFIG_USB_STKWEBCAM is not set 824# CONFIG_USB_STKWEBCAM is not set
818# CONFIG_USB_S2255 is not set 825# CONFIG_USB_S2255 is not set
@@ -914,15 +921,17 @@ CONFIG_USB_HID=y
914# 921#
915# Special HID drivers 922# Special HID drivers
916# 923#
917CONFIG_HID_COMPAT=y
918CONFIG_HID_A4TECH=y 924CONFIG_HID_A4TECH=y
919CONFIG_HID_APPLE=y 925CONFIG_HID_APPLE=y
920CONFIG_HID_BELKIN=y 926CONFIG_HID_BELKIN=y
921CONFIG_HID_CHERRY=y 927CONFIG_HID_CHERRY=y
922CONFIG_HID_CHICONY=y 928CONFIG_HID_CHICONY=y
923CONFIG_HID_CYPRESS=y 929CONFIG_HID_CYPRESS=y
930# CONFIG_DRAGONRISE_FF is not set
924CONFIG_HID_EZKEY=y 931CONFIG_HID_EZKEY=y
932# CONFIG_HID_KYE is not set
925CONFIG_HID_GYRATION=y 933CONFIG_HID_GYRATION=y
934# CONFIG_HID_KENSINGTON is not set
926CONFIG_HID_LOGITECH=y 935CONFIG_HID_LOGITECH=y
927# CONFIG_LOGITECH_FF is not set 936# CONFIG_LOGITECH_FF is not set
928# CONFIG_LOGIRUMBLEPAD2_FF is not set 937# CONFIG_LOGIRUMBLEPAD2_FF is not set
@@ -1050,6 +1059,7 @@ CONFIG_EXT2_FS=y
1050# CONFIG_EXT2_FS_XATTR is not set 1059# CONFIG_EXT2_FS_XATTR is not set
1051# CONFIG_EXT2_FS_XIP is not set 1060# CONFIG_EXT2_FS_XIP is not set
1052CONFIG_EXT3_FS=y 1061CONFIG_EXT3_FS=y
1062# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
1053CONFIG_EXT3_FS_XATTR=y 1063CONFIG_EXT3_FS_XATTR=y
1054# CONFIG_EXT3_FS_POSIX_ACL is not set 1064# CONFIG_EXT3_FS_POSIX_ACL is not set
1055# CONFIG_EXT3_FS_SECURITY is not set 1065# CONFIG_EXT3_FS_SECURITY is not set
@@ -1071,6 +1081,11 @@ CONFIG_FILE_LOCKING=y
1071# CONFIG_FUSE_FS is not set 1081# CONFIG_FUSE_FS is not set
1072 1082
1073# 1083#
1084# Caches
1085#
1086# CONFIG_FSCACHE is not set
1087
1088#
1074# CD-ROM/DVD Filesystems 1089# CD-ROM/DVD Filesystems
1075# 1090#
1076# CONFIG_ISO9660_FS is not set 1091# CONFIG_ISO9660_FS is not set
@@ -1125,6 +1140,7 @@ CONFIG_CRAMFS=y
1125# CONFIG_ROMFS_FS is not set 1140# CONFIG_ROMFS_FS is not set
1126# CONFIG_SYSV_FS is not set 1141# CONFIG_SYSV_FS is not set
1127# CONFIG_UFS_FS is not set 1142# CONFIG_UFS_FS is not set
1143# CONFIG_NILFS2_FS is not set
1128CONFIG_NETWORK_FILESYSTEMS=y 1144CONFIG_NETWORK_FILESYSTEMS=y
1129CONFIG_NFS_FS=y 1145CONFIG_NFS_FS=y
1130CONFIG_NFS_V3=y 1146CONFIG_NFS_V3=y
@@ -1174,10 +1190,23 @@ CONFIG_FRAME_WARN=1024
1174CONFIG_HAVE_FUNCTION_TRACER=y 1190CONFIG_HAVE_FUNCTION_TRACER=y
1175CONFIG_HAVE_DYNAMIC_FTRACE=y 1191CONFIG_HAVE_DYNAMIC_FTRACE=y
1176CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1192CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1193CONFIG_TRACING_SUPPORT=y
1177 1194
1178# 1195#
1179# Tracers 1196# Tracers
1180# 1197#
1198# CONFIG_FUNCTION_TRACER is not set
1199# CONFIG_IRQSOFF_TRACER is not set
1200# CONFIG_SCHED_TRACER is not set
1201# CONFIG_CONTEXT_SWITCH_TRACER is not set
1202# CONFIG_EVENT_TRACER is not set
1203# CONFIG_BOOT_TRACER is not set
1204# CONFIG_TRACE_BRANCH_PROFILING is not set
1205# CONFIG_STACK_TRACER is not set
1206# CONFIG_KMEMTRACE is not set
1207# CONFIG_WORKQUEUE_TRACER is not set
1208# CONFIG_BLK_DEV_IO_TRACE is not set
1209# CONFIG_DMA_API_DEBUG is not set
1181# CONFIG_SAMPLES is not set 1210# CONFIG_SAMPLES is not set
1182CONFIG_HAVE_ARCH_KGDB=y 1211CONFIG_HAVE_ARCH_KGDB=y
1183# CONFIG_SH_STANDARD_BIOS is not set 1212# CONFIG_SH_STANDARD_BIOS is not set
@@ -1279,6 +1308,7 @@ CONFIG_CRYPTO=y
1279# 1308#
1280# CONFIG_CRYPTO_ANSI_CPRNG is not set 1309# CONFIG_CRYPTO_ANSI_CPRNG is not set
1281CONFIG_CRYPTO_HW=y 1310CONFIG_CRYPTO_HW=y
1311# CONFIG_BINARY_PRINTF is not set
1282 1312
1283# 1313#
1284# Library routines 1314# Library routines
diff --git a/arch/sh/configs/se7619_defconfig b/arch/sh/configs/se7619_defconfig
index 125304e80f57..edbece52afc1 100644
--- a/arch/sh/configs/se7619_defconfig
+++ b/arch/sh/configs/se7619_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:44:53 2009 4# Mon Apr 27 13:02:32 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -61,6 +62,7 @@ CONFIG_EMBEDDED=y
61# CONFIG_UID16 is not set 62# CONFIG_UID16 is not set
62# CONFIG_SYSCTL_SYSCALL is not set 63# CONFIG_SYSCTL_SYSCALL is not set
63# CONFIG_KALLSYMS is not set 64# CONFIG_KALLSYMS is not set
65# CONFIG_STRIP_ASM_SYMS is not set
64# CONFIG_HOTPLUG is not set 66# CONFIG_HOTPLUG is not set
65CONFIG_PRINTK=y 67CONFIG_PRINTK=y
66CONFIG_BUG=y 68CONFIG_BUG=y
@@ -78,11 +80,14 @@ CONFIG_SLAB=y
78# CONFIG_SLUB is not set 80# CONFIG_SLUB is not set
79# CONFIG_SLOB is not set 81# CONFIG_SLOB is not set
80# CONFIG_PROFILING is not set 82# CONFIG_PROFILING is not set
83# CONFIG_MARKERS is not set
81CONFIG_HAVE_OPROFILE=y 84CONFIG_HAVE_OPROFILE=y
82CONFIG_HAVE_KPROBES=y 85CONFIG_HAVE_KPROBES=y
83CONFIG_HAVE_KRETPROBES=y 86CONFIG_HAVE_KRETPROBES=y
84CONFIG_HAVE_ARCH_TRACEHOOK=y 87CONFIG_HAVE_ARCH_TRACEHOOK=y
85CONFIG_HAVE_CLK=y 88CONFIG_HAVE_CLK=y
89CONFIG_HAVE_DMA_API_DEBUG=y
90# CONFIG_SLOW_WORK is not set
86CONFIG_HAVE_GENERIC_DMA_COHERENT=y 91CONFIG_HAVE_GENERIC_DMA_COHERENT=y
87CONFIG_SLABINFO=y 92CONFIG_SLABINFO=y
88CONFIG_BASE_SMALL=1 93CONFIG_BASE_SMALL=1
@@ -134,6 +139,7 @@ CONFIG_CPU_SUBTYPE_SH7619=y
134# CONFIG_CPU_SUBTYPE_SH7760 is not set 139# CONFIG_CPU_SUBTYPE_SH7760 is not set
135# CONFIG_CPU_SUBTYPE_SH4_202 is not set 140# CONFIG_CPU_SUBTYPE_SH4_202 is not set
136# CONFIG_CPU_SUBTYPE_SH7723 is not set 141# CONFIG_CPU_SUBTYPE_SH7723 is not set
142# CONFIG_CPU_SUBTYPE_SH7724 is not set
137# CONFIG_CPU_SUBTYPE_SH7763 is not set 143# CONFIG_CPU_SUBTYPE_SH7763 is not set
138# CONFIG_CPU_SUBTYPE_SH7770 is not set 144# CONFIG_CPU_SUBTYPE_SH7770 is not set
139# CONFIG_CPU_SUBTYPE_SH7780 is not set 145# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -143,8 +149,6 @@ CONFIG_CPU_SUBTYPE_SH7619=y
143# CONFIG_CPU_SUBTYPE_SH7343 is not set 149# CONFIG_CPU_SUBTYPE_SH7343 is not set
144# CONFIG_CPU_SUBTYPE_SH7722 is not set 150# CONFIG_CPU_SUBTYPE_SH7722 is not set
145# CONFIG_CPU_SUBTYPE_SH7366 is not set 151# CONFIG_CPU_SUBTYPE_SH7366 is not set
146# CONFIG_CPU_SUBTYPE_SH5_101 is not set
147# CONFIG_CPU_SUBTYPE_SH5_103 is not set
148 152
149# 153#
150# Memory management options 154# Memory management options
@@ -513,7 +517,6 @@ CONFIG_HID=y
513# 517#
514# Special HID drivers 518# Special HID drivers
515# 519#
516CONFIG_HID_COMPAT=y
517CONFIG_USB_SUPPORT=y 520CONFIG_USB_SUPPORT=y
518CONFIG_USB_ARCH_HAS_HCD=y 521CONFIG_USB_ARCH_HAS_HCD=y
519# CONFIG_USB_ARCH_HAS_OHCI is not set 522# CONFIG_USB_ARCH_HAS_OHCI is not set
@@ -564,6 +567,11 @@ CONFIG_FILE_LOCKING=y
564# CONFIG_FUSE_FS is not set 567# CONFIG_FUSE_FS is not set
565 568
566# 569#
570# Caches
571#
572# CONFIG_FSCACHE is not set
573
574#
567# CD-ROM/DVD Filesystems 575# CD-ROM/DVD Filesystems
568# 576#
569# CONFIG_ISO9660_FS is not set 577# CONFIG_ISO9660_FS is not set
@@ -601,8 +609,13 @@ CONFIG_MISC_FILESYSTEMS=y
601# CONFIG_HPFS_FS is not set 609# CONFIG_HPFS_FS is not set
602# CONFIG_QNX4FS_FS is not set 610# CONFIG_QNX4FS_FS is not set
603CONFIG_ROMFS_FS=y 611CONFIG_ROMFS_FS=y
612CONFIG_ROMFS_BACKED_BY_BLOCK=y
613# CONFIG_ROMFS_BACKED_BY_MTD is not set
614# CONFIG_ROMFS_BACKED_BY_BOTH is not set
615CONFIG_ROMFS_ON_BLOCK=y
604# CONFIG_SYSV_FS is not set 616# CONFIG_SYSV_FS is not set
605# CONFIG_UFS_FS is not set 617# CONFIG_UFS_FS is not set
618# CONFIG_NILFS2_FS is not set
606 619
607# 620#
608# Partition Types 621# Partition Types
@@ -630,10 +643,21 @@ CONFIG_FRAME_WARN=1024
630CONFIG_HAVE_FUNCTION_TRACER=y 643CONFIG_HAVE_FUNCTION_TRACER=y
631CONFIG_HAVE_DYNAMIC_FTRACE=y 644CONFIG_HAVE_DYNAMIC_FTRACE=y
632CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 645CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
646CONFIG_TRACING_SUPPORT=y
633 647
634# 648#
635# Tracers 649# Tracers
636# 650#
651# CONFIG_FUNCTION_TRACER is not set
652# CONFIG_SCHED_TRACER is not set
653# CONFIG_CONTEXT_SWITCH_TRACER is not set
654# CONFIG_EVENT_TRACER is not set
655# CONFIG_BOOT_TRACER is not set
656# CONFIG_TRACE_BRANCH_PROFILING is not set
657# CONFIG_STACK_TRACER is not set
658# CONFIG_KMEMTRACE is not set
659# CONFIG_WORKQUEUE_TRACER is not set
660# CONFIG_DMA_API_DEBUG is not set
637# CONFIG_SAMPLES is not set 661# CONFIG_SAMPLES is not set
638CONFIG_HAVE_ARCH_KGDB=y 662CONFIG_HAVE_ARCH_KGDB=y
639# CONFIG_SH_STANDARD_BIOS is not set 663# CONFIG_SH_STANDARD_BIOS is not set
@@ -647,6 +671,7 @@ CONFIG_HAVE_ARCH_KGDB=y
647# CONFIG_SECURITYFS is not set 671# CONFIG_SECURITYFS is not set
648# CONFIG_SECURITY_FILE_CAPABILITIES is not set 672# CONFIG_SECURITY_FILE_CAPABILITIES is not set
649# CONFIG_CRYPTO is not set 673# CONFIG_CRYPTO is not set
674# CONFIG_BINARY_PRINTF is not set
650 675
651# 676#
652# Library routines 677# Library routines
diff --git a/arch/sh/configs/se7705_defconfig b/arch/sh/configs/se7705_defconfig
index 0308abf52384..bae161c66835 100644
--- a/arch/sh/configs/se7705_defconfig
+++ b/arch/sh/configs/se7705_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:45:56 2009 4# Mon Apr 27 13:02:52 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -62,7 +63,6 @@ CONFIG_INITRAMFS_SOURCE=""
62CONFIG_RD_GZIP=y 63CONFIG_RD_GZIP=y
63# CONFIG_RD_BZIP2 is not set 64# CONFIG_RD_BZIP2 is not set
64# CONFIG_RD_LZMA is not set 65# CONFIG_RD_LZMA is not set
65CONFIG_INITRAMFS_COMPRESSION_NONE=y
66# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set 66# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
67CONFIG_SYSCTL=y 67CONFIG_SYSCTL=y
68CONFIG_ANON_INODES=y 68CONFIG_ANON_INODES=y
@@ -70,6 +70,7 @@ CONFIG_EMBEDDED=y
70CONFIG_UID16=y 70CONFIG_UID16=y
71# CONFIG_SYSCTL_SYSCALL is not set 71# CONFIG_SYSCTL_SYSCALL is not set
72# CONFIG_KALLSYMS is not set 72# CONFIG_KALLSYMS is not set
73# CONFIG_STRIP_ASM_SYMS is not set
73# CONFIG_HOTPLUG is not set 74# CONFIG_HOTPLUG is not set
74CONFIG_PRINTK=y 75CONFIG_PRINTK=y
75CONFIG_BUG=y 76CONFIG_BUG=y
@@ -88,12 +89,15 @@ CONFIG_SLAB=y
88# CONFIG_SLUB is not set 89# CONFIG_SLUB is not set
89# CONFIG_SLOB is not set 90# CONFIG_SLOB is not set
90# CONFIG_PROFILING is not set 91# CONFIG_PROFILING is not set
92# CONFIG_MARKERS is not set
91CONFIG_HAVE_OPROFILE=y 93CONFIG_HAVE_OPROFILE=y
92CONFIG_HAVE_IOREMAP_PROT=y 94CONFIG_HAVE_IOREMAP_PROT=y
93CONFIG_HAVE_KPROBES=y 95CONFIG_HAVE_KPROBES=y
94CONFIG_HAVE_KRETPROBES=y 96CONFIG_HAVE_KRETPROBES=y
95CONFIG_HAVE_ARCH_TRACEHOOK=y 97CONFIG_HAVE_ARCH_TRACEHOOK=y
96CONFIG_HAVE_CLK=y 98CONFIG_HAVE_CLK=y
99CONFIG_HAVE_DMA_API_DEBUG=y
100# CONFIG_SLOW_WORK is not set
97CONFIG_HAVE_GENERIC_DMA_COHERENT=y 101CONFIG_HAVE_GENERIC_DMA_COHERENT=y
98CONFIG_SLABINFO=y 102CONFIG_SLABINFO=y
99CONFIG_RT_MUTEXES=y 103CONFIG_RT_MUTEXES=y
@@ -150,6 +154,7 @@ CONFIG_CPU_SUBTYPE_SH7705=y
150# CONFIG_CPU_SUBTYPE_SH7760 is not set 154# CONFIG_CPU_SUBTYPE_SH7760 is not set
151# CONFIG_CPU_SUBTYPE_SH4_202 is not set 155# CONFIG_CPU_SUBTYPE_SH4_202 is not set
152# CONFIG_CPU_SUBTYPE_SH7723 is not set 156# CONFIG_CPU_SUBTYPE_SH7723 is not set
157# CONFIG_CPU_SUBTYPE_SH7724 is not set
153# CONFIG_CPU_SUBTYPE_SH7763 is not set 158# CONFIG_CPU_SUBTYPE_SH7763 is not set
154# CONFIG_CPU_SUBTYPE_SH7770 is not set 159# CONFIG_CPU_SUBTYPE_SH7770 is not set
155# CONFIG_CPU_SUBTYPE_SH7780 is not set 160# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -159,8 +164,6 @@ CONFIG_CPU_SUBTYPE_SH7705=y
159# CONFIG_CPU_SUBTYPE_SH7343 is not set 164# CONFIG_CPU_SUBTYPE_SH7343 is not set
160# CONFIG_CPU_SUBTYPE_SH7722 is not set 165# CONFIG_CPU_SUBTYPE_SH7722 is not set
161# CONFIG_CPU_SUBTYPE_SH7366 is not set 166# CONFIG_CPU_SUBTYPE_SH7366 is not set
162# CONFIG_CPU_SUBTYPE_SH5_101 is not set
163# CONFIG_CPU_SUBTYPE_SH5_103 is not set
164 167
165# 168#
166# Memory management options 169# Memory management options
@@ -698,7 +701,6 @@ CONFIG_HID=y
698# 701#
699# Special HID drivers 702# Special HID drivers
700# 703#
701CONFIG_HID_COMPAT=y
702CONFIG_USB_SUPPORT=y 704CONFIG_USB_SUPPORT=y
703CONFIG_USB_ARCH_HAS_HCD=y 705CONFIG_USB_ARCH_HAS_HCD=y
704# CONFIG_USB_ARCH_HAS_OHCI is not set 706# CONFIG_USB_ARCH_HAS_OHCI is not set
@@ -752,6 +754,11 @@ CONFIG_INOTIFY_USER=y
752# CONFIG_FUSE_FS is not set 754# CONFIG_FUSE_FS is not set
753 755
754# 756#
757# Caches
758#
759# CONFIG_FSCACHE is not set
760
761#
755# CD-ROM/DVD Filesystems 762# CD-ROM/DVD Filesystems
756# 763#
757# CONFIG_ISO9660_FS is not set 764# CONFIG_ISO9660_FS is not set
@@ -804,6 +811,7 @@ CONFIG_JFFS2_RTIME=y
804# CONFIG_ROMFS_FS is not set 811# CONFIG_ROMFS_FS is not set
805# CONFIG_SYSV_FS is not set 812# CONFIG_SYSV_FS is not set
806# CONFIG_UFS_FS is not set 813# CONFIG_UFS_FS is not set
814# CONFIG_NILFS2_FS is not set
807CONFIG_NETWORK_FILESYSTEMS=y 815CONFIG_NETWORK_FILESYSTEMS=y
808CONFIG_NFS_FS=y 816CONFIG_NFS_FS=y
809# CONFIG_NFS_V3 is not set 817# CONFIG_NFS_V3 is not set
@@ -847,10 +855,23 @@ CONFIG_FRAME_WARN=1024
847CONFIG_HAVE_FUNCTION_TRACER=y 855CONFIG_HAVE_FUNCTION_TRACER=y
848CONFIG_HAVE_DYNAMIC_FTRACE=y 856CONFIG_HAVE_DYNAMIC_FTRACE=y
849CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 857CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
858CONFIG_TRACING_SUPPORT=y
850 859
851# 860#
852# Tracers 861# Tracers
853# 862#
863# CONFIG_FUNCTION_TRACER is not set
864# CONFIG_IRQSOFF_TRACER is not set
865# CONFIG_PREEMPT_TRACER is not set
866# CONFIG_SCHED_TRACER is not set
867# CONFIG_CONTEXT_SWITCH_TRACER is not set
868# CONFIG_EVENT_TRACER is not set
869# CONFIG_BOOT_TRACER is not set
870# CONFIG_TRACE_BRANCH_PROFILING is not set
871# CONFIG_STACK_TRACER is not set
872# CONFIG_KMEMTRACE is not set
873# CONFIG_WORKQUEUE_TRACER is not set
874# CONFIG_DMA_API_DEBUG is not set
854# CONFIG_SAMPLES is not set 875# CONFIG_SAMPLES is not set
855CONFIG_HAVE_ARCH_KGDB=y 876CONFIG_HAVE_ARCH_KGDB=y
856# CONFIG_SH_STANDARD_BIOS is not set 877# CONFIG_SH_STANDARD_BIOS is not set
@@ -949,6 +970,7 @@ CONFIG_CRYPTO=y
949# 970#
950# CONFIG_CRYPTO_ANSI_CPRNG is not set 971# CONFIG_CRYPTO_ANSI_CPRNG is not set
951CONFIG_CRYPTO_HW=y 972CONFIG_CRYPTO_HW=y
973# CONFIG_BINARY_PRINTF is not set
952 974
953# 975#
954# Library routines 976# Library routines
diff --git a/arch/sh/configs/se7712_defconfig b/arch/sh/configs/se7712_defconfig
index a8c24b703489..330043f3c316 100644
--- a/arch/sh/configs/se7712_defconfig
+++ b/arch/sh/configs/se7712_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:48:18 2009 4# Mon Apr 27 13:03:27 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_FIND_NEXT_BIT=y 11CONFIG_GENERIC_FIND_NEXT_BIT=y
@@ -38,6 +39,7 @@ CONFIG_LOCALVERSION=""
38CONFIG_SYSVIPC=y 39CONFIG_SYSVIPC=y
39CONFIG_SYSVIPC_SYSCTL=y 40CONFIG_SYSVIPC_SYSCTL=y
40CONFIG_POSIX_MQUEUE=y 41CONFIG_POSIX_MQUEUE=y
42CONFIG_POSIX_MQUEUE_SYSCTL=y
41CONFIG_BSD_PROCESS_ACCT=y 43CONFIG_BSD_PROCESS_ACCT=y
42# CONFIG_BSD_PROCESS_ACCT_V3 is not set 44# CONFIG_BSD_PROCESS_ACCT_V3 is not set
43# CONFIG_TASKSTATS is not set 45# CONFIG_TASKSTATS is not set
@@ -69,6 +71,7 @@ CONFIG_SYSCTL_SYSCALL=y
69CONFIG_KALLSYMS=y 71CONFIG_KALLSYMS=y
70CONFIG_KALLSYMS_ALL=y 72CONFIG_KALLSYMS_ALL=y
71# CONFIG_KALLSYMS_EXTRA_PASS is not set 73# CONFIG_KALLSYMS_EXTRA_PASS is not set
74# CONFIG_STRIP_ASM_SYMS is not set
72CONFIG_HOTPLUG=y 75CONFIG_HOTPLUG=y
73CONFIG_PRINTK=y 76CONFIG_PRINTK=y
74# CONFIG_BUG is not set 77# CONFIG_BUG is not set
@@ -87,6 +90,7 @@ CONFIG_SLAB=y
87# CONFIG_SLUB is not set 90# CONFIG_SLUB is not set
88# CONFIG_SLOB is not set 91# CONFIG_SLOB is not set
89# CONFIG_PROFILING is not set 92# CONFIG_PROFILING is not set
93# CONFIG_MARKERS is not set
90CONFIG_HAVE_OPROFILE=y 94CONFIG_HAVE_OPROFILE=y
91# CONFIG_KPROBES is not set 95# CONFIG_KPROBES is not set
92CONFIG_HAVE_IOREMAP_PROT=y 96CONFIG_HAVE_IOREMAP_PROT=y
@@ -94,6 +98,8 @@ CONFIG_HAVE_KPROBES=y
94CONFIG_HAVE_KRETPROBES=y 98CONFIG_HAVE_KRETPROBES=y
95CONFIG_HAVE_ARCH_TRACEHOOK=y 99CONFIG_HAVE_ARCH_TRACEHOOK=y
96CONFIG_HAVE_CLK=y 100CONFIG_HAVE_CLK=y
101CONFIG_HAVE_DMA_API_DEBUG=y
102# CONFIG_SLOW_WORK is not set
97CONFIG_HAVE_GENERIC_DMA_COHERENT=y 103CONFIG_HAVE_GENERIC_DMA_COHERENT=y
98CONFIG_SLABINFO=y 104CONFIG_SLABINFO=y
99CONFIG_RT_MUTEXES=y 105CONFIG_RT_MUTEXES=y
@@ -105,7 +111,6 @@ CONFIG_MODULES=y
105# CONFIG_MODULE_SRCVERSION_ALL is not set 111# CONFIG_MODULE_SRCVERSION_ALL is not set
106CONFIG_BLOCK=y 112CONFIG_BLOCK=y
107# CONFIG_LBD is not set 113# CONFIG_LBD is not set
108# CONFIG_BLK_DEV_IO_TRACE is not set
109# CONFIG_BLK_DEV_BSG is not set 114# CONFIG_BLK_DEV_BSG is not set
110# CONFIG_BLK_DEV_INTEGRITY is not set 115# CONFIG_BLK_DEV_INTEGRITY is not set
111 116
@@ -151,6 +156,7 @@ CONFIG_CPU_SUBTYPE_SH7712=y
151# CONFIG_CPU_SUBTYPE_SH7760 is not set 156# CONFIG_CPU_SUBTYPE_SH7760 is not set
152# CONFIG_CPU_SUBTYPE_SH4_202 is not set 157# CONFIG_CPU_SUBTYPE_SH4_202 is not set
153# CONFIG_CPU_SUBTYPE_SH7723 is not set 158# CONFIG_CPU_SUBTYPE_SH7723 is not set
159# CONFIG_CPU_SUBTYPE_SH7724 is not set
154# CONFIG_CPU_SUBTYPE_SH7763 is not set 160# CONFIG_CPU_SUBTYPE_SH7763 is not set
155# CONFIG_CPU_SUBTYPE_SH7770 is not set 161# CONFIG_CPU_SUBTYPE_SH7770 is not set
156# CONFIG_CPU_SUBTYPE_SH7780 is not set 162# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -160,8 +166,6 @@ CONFIG_CPU_SUBTYPE_SH7712=y
160# CONFIG_CPU_SUBTYPE_SH7343 is not set 166# CONFIG_CPU_SUBTYPE_SH7343 is not set
161# CONFIG_CPU_SUBTYPE_SH7722 is not set 167# CONFIG_CPU_SUBTYPE_SH7722 is not set
162# CONFIG_CPU_SUBTYPE_SH7366 is not set 168# CONFIG_CPU_SUBTYPE_SH7366 is not set
163# CONFIG_CPU_SUBTYPE_SH5_101 is not set
164# CONFIG_CPU_SUBTYPE_SH5_103 is not set
165 169
166# 170#
167# Memory management options 171# Memory management options
@@ -585,6 +589,7 @@ CONFIG_SCSI_WAIT_SCAN=m
585CONFIG_SCSI_LOWLEVEL=y 589CONFIG_SCSI_LOWLEVEL=y
586# CONFIG_ISCSI_TCP is not set 590# CONFIG_ISCSI_TCP is not set
587# CONFIG_LIBFC is not set 591# CONFIG_LIBFC is not set
592# CONFIG_LIBFCOE is not set
588# CONFIG_SCSI_DEBUG is not set 593# CONFIG_SCSI_DEBUG is not set
589# CONFIG_SCSI_DH is not set 594# CONFIG_SCSI_DH is not set
590# CONFIG_SCSI_OSD_INITIATOR is not set 595# CONFIG_SCSI_OSD_INITIATOR is not set
@@ -812,6 +817,7 @@ CONFIG_EXT2_FS_POSIX_ACL=y
812CONFIG_EXT2_FS_SECURITY=y 817CONFIG_EXT2_FS_SECURITY=y
813# CONFIG_EXT2_FS_XIP is not set 818# CONFIG_EXT2_FS_XIP is not set
814CONFIG_EXT3_FS=y 819CONFIG_EXT3_FS=y
820# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
815CONFIG_EXT3_FS_XATTR=y 821CONFIG_EXT3_FS_XATTR=y
816# CONFIG_EXT3_FS_POSIX_ACL is not set 822# CONFIG_EXT3_FS_POSIX_ACL is not set
817# CONFIG_EXT3_FS_SECURITY is not set 823# CONFIG_EXT3_FS_SECURITY is not set
@@ -833,6 +839,11 @@ CONFIG_FILE_LOCKING=y
833# CONFIG_FUSE_FS is not set 839# CONFIG_FUSE_FS is not set
834 840
835# 841#
842# Caches
843#
844# CONFIG_FSCACHE is not set
845
846#
836# CD-ROM/DVD Filesystems 847# CD-ROM/DVD Filesystems
837# 848#
838# CONFIG_ISO9660_FS is not set 849# CONFIG_ISO9660_FS is not set
@@ -887,6 +898,7 @@ CONFIG_CRAMFS=y
887# CONFIG_ROMFS_FS is not set 898# CONFIG_ROMFS_FS is not set
888# CONFIG_SYSV_FS is not set 899# CONFIG_SYSV_FS is not set
889# CONFIG_UFS_FS is not set 900# CONFIG_UFS_FS is not set
901# CONFIG_NILFS2_FS is not set
890CONFIG_NETWORK_FILESYSTEMS=y 902CONFIG_NETWORK_FILESYSTEMS=y
891CONFIG_NFS_FS=y 903CONFIG_NFS_FS=y
892# CONFIG_NFS_V3 is not set 904# CONFIG_NFS_V3 is not set
@@ -927,6 +939,7 @@ CONFIG_FRAME_WARN=1024
927CONFIG_DEBUG_KERNEL=y 939CONFIG_DEBUG_KERNEL=y
928# CONFIG_DEBUG_SHIRQ is not set 940# CONFIG_DEBUG_SHIRQ is not set
929# CONFIG_DETECT_SOFTLOCKUP is not set 941# CONFIG_DETECT_SOFTLOCKUP is not set
942# CONFIG_DETECT_HUNG_TASK is not set
930CONFIG_SCHED_DEBUG=y 943CONFIG_SCHED_DEBUG=y
931# CONFIG_SCHEDSTATS is not set 944# CONFIG_SCHEDSTATS is not set
932# CONFIG_TIMER_STATS is not set 945# CONFIG_TIMER_STATS is not set
@@ -961,6 +974,7 @@ CONFIG_SYSCTL_SYSCALL_CHECK=y
961CONFIG_HAVE_FUNCTION_TRACER=y 974CONFIG_HAVE_FUNCTION_TRACER=y
962CONFIG_HAVE_DYNAMIC_FTRACE=y 975CONFIG_HAVE_DYNAMIC_FTRACE=y
963CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 976CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
977CONFIG_TRACING_SUPPORT=y
964 978
965# 979#
966# Tracers 980# Tracers
@@ -969,9 +983,14 @@ CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
969# CONFIG_IRQSOFF_TRACER is not set 983# CONFIG_IRQSOFF_TRACER is not set
970# CONFIG_SCHED_TRACER is not set 984# CONFIG_SCHED_TRACER is not set
971# CONFIG_CONTEXT_SWITCH_TRACER is not set 985# CONFIG_CONTEXT_SWITCH_TRACER is not set
986# CONFIG_EVENT_TRACER is not set
972# CONFIG_BOOT_TRACER is not set 987# CONFIG_BOOT_TRACER is not set
973# CONFIG_TRACE_BRANCH_PROFILING is not set 988# CONFIG_TRACE_BRANCH_PROFILING is not set
974# CONFIG_STACK_TRACER is not set 989# CONFIG_STACK_TRACER is not set
990# CONFIG_KMEMTRACE is not set
991# CONFIG_WORKQUEUE_TRACER is not set
992# CONFIG_BLK_DEV_IO_TRACE is not set
993# CONFIG_DMA_API_DEBUG is not set
975# CONFIG_SAMPLES is not set 994# CONFIG_SAMPLES is not set
976CONFIG_HAVE_ARCH_KGDB=y 995CONFIG_HAVE_ARCH_KGDB=y
977# CONFIG_KGDB is not set 996# CONFIG_KGDB is not set
@@ -1090,6 +1109,7 @@ CONFIG_CRYPTO_DEFLATE=y
1090# 1109#
1091# CONFIG_CRYPTO_ANSI_CPRNG is not set 1110# CONFIG_CRYPTO_ANSI_CPRNG is not set
1092CONFIG_CRYPTO_HW=y 1111CONFIG_CRYPTO_HW=y
1112# CONFIG_BINARY_PRINTF is not set
1093 1113
1094# 1114#
1095# Library routines 1115# Library routines
diff --git a/arch/sh/configs/se7721_defconfig b/arch/sh/configs/se7721_defconfig
index 4b79c2567dc8..56478918440d 100644
--- a/arch/sh/configs/se7721_defconfig
+++ b/arch/sh/configs/se7721_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:51:44 2009 4# Mon Apr 27 13:04:19 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_FIND_NEXT_BIT=y 11CONFIG_GENERIC_FIND_NEXT_BIT=y
@@ -38,6 +39,7 @@ CONFIG_LOCALVERSION=""
38CONFIG_SYSVIPC=y 39CONFIG_SYSVIPC=y
39CONFIG_SYSVIPC_SYSCTL=y 40CONFIG_SYSVIPC_SYSCTL=y
40CONFIG_POSIX_MQUEUE=y 41CONFIG_POSIX_MQUEUE=y
42CONFIG_POSIX_MQUEUE_SYSCTL=y
41CONFIG_BSD_PROCESS_ACCT=y 43CONFIG_BSD_PROCESS_ACCT=y
42# CONFIG_BSD_PROCESS_ACCT_V3 is not set 44# CONFIG_BSD_PROCESS_ACCT_V3 is not set
43# CONFIG_TASKSTATS is not set 45# CONFIG_TASKSTATS is not set
@@ -73,6 +75,7 @@ CONFIG_SYSCTL_SYSCALL=y
73CONFIG_KALLSYMS=y 75CONFIG_KALLSYMS=y
74CONFIG_KALLSYMS_ALL=y 76CONFIG_KALLSYMS_ALL=y
75# CONFIG_KALLSYMS_EXTRA_PASS is not set 77# CONFIG_KALLSYMS_EXTRA_PASS is not set
78# CONFIG_STRIP_ASM_SYMS is not set
76CONFIG_HOTPLUG=y 79CONFIG_HOTPLUG=y
77CONFIG_PRINTK=y 80CONFIG_PRINTK=y
78# CONFIG_BUG is not set 81# CONFIG_BUG is not set
@@ -91,6 +94,7 @@ CONFIG_SLAB=y
91# CONFIG_SLUB is not set 94# CONFIG_SLUB is not set
92# CONFIG_SLOB is not set 95# CONFIG_SLOB is not set
93# CONFIG_PROFILING is not set 96# CONFIG_PROFILING is not set
97# CONFIG_MARKERS is not set
94CONFIG_HAVE_OPROFILE=y 98CONFIG_HAVE_OPROFILE=y
95# CONFIG_KPROBES is not set 99# CONFIG_KPROBES is not set
96CONFIG_HAVE_IOREMAP_PROT=y 100CONFIG_HAVE_IOREMAP_PROT=y
@@ -98,6 +102,8 @@ CONFIG_HAVE_KPROBES=y
98CONFIG_HAVE_KRETPROBES=y 102CONFIG_HAVE_KRETPROBES=y
99CONFIG_HAVE_ARCH_TRACEHOOK=y 103CONFIG_HAVE_ARCH_TRACEHOOK=y
100CONFIG_HAVE_CLK=y 104CONFIG_HAVE_CLK=y
105CONFIG_HAVE_DMA_API_DEBUG=y
106# CONFIG_SLOW_WORK is not set
101CONFIG_HAVE_GENERIC_DMA_COHERENT=y 107CONFIG_HAVE_GENERIC_DMA_COHERENT=y
102CONFIG_SLABINFO=y 108CONFIG_SLABINFO=y
103CONFIG_RT_MUTEXES=y 109CONFIG_RT_MUTEXES=y
@@ -109,7 +115,6 @@ CONFIG_MODULES=y
109# CONFIG_MODULE_SRCVERSION_ALL is not set 115# CONFIG_MODULE_SRCVERSION_ALL is not set
110CONFIG_BLOCK=y 116CONFIG_BLOCK=y
111# CONFIG_LBD is not set 117# CONFIG_LBD is not set
112# CONFIG_BLK_DEV_IO_TRACE is not set
113# CONFIG_BLK_DEV_BSG is not set 118# CONFIG_BLK_DEV_BSG is not set
114# CONFIG_BLK_DEV_INTEGRITY is not set 119# CONFIG_BLK_DEV_INTEGRITY is not set
115 120
@@ -155,6 +160,7 @@ CONFIG_CPU_SUBTYPE_SH7721=y
155# CONFIG_CPU_SUBTYPE_SH7760 is not set 160# CONFIG_CPU_SUBTYPE_SH7760 is not set
156# CONFIG_CPU_SUBTYPE_SH4_202 is not set 161# CONFIG_CPU_SUBTYPE_SH4_202 is not set
157# CONFIG_CPU_SUBTYPE_SH7723 is not set 162# CONFIG_CPU_SUBTYPE_SH7723 is not set
163# CONFIG_CPU_SUBTYPE_SH7724 is not set
158# CONFIG_CPU_SUBTYPE_SH7763 is not set 164# CONFIG_CPU_SUBTYPE_SH7763 is not set
159# CONFIG_CPU_SUBTYPE_SH7770 is not set 165# CONFIG_CPU_SUBTYPE_SH7770 is not set
160# CONFIG_CPU_SUBTYPE_SH7780 is not set 166# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -164,8 +170,6 @@ CONFIG_CPU_SUBTYPE_SH7721=y
164# CONFIG_CPU_SUBTYPE_SH7343 is not set 170# CONFIG_CPU_SUBTYPE_SH7343 is not set
165# CONFIG_CPU_SUBTYPE_SH7722 is not set 171# CONFIG_CPU_SUBTYPE_SH7722 is not set
166# CONFIG_CPU_SUBTYPE_SH7366 is not set 172# CONFIG_CPU_SUBTYPE_SH7366 is not set
167# CONFIG_CPU_SUBTYPE_SH5_101 is not set
168# CONFIG_CPU_SUBTYPE_SH5_103 is not set
169 173
170# 174#
171# Memory management options 175# Memory management options
@@ -776,15 +780,17 @@ CONFIG_USB_HID=y
776# 780#
777# Special HID drivers 781# Special HID drivers
778# 782#
779CONFIG_HID_COMPAT=y
780CONFIG_HID_A4TECH=y 783CONFIG_HID_A4TECH=y
781CONFIG_HID_APPLE=y 784CONFIG_HID_APPLE=y
782CONFIG_HID_BELKIN=y 785CONFIG_HID_BELKIN=y
783CONFIG_HID_CHERRY=y 786CONFIG_HID_CHERRY=y
784CONFIG_HID_CHICONY=y 787CONFIG_HID_CHICONY=y
785CONFIG_HID_CYPRESS=y 788CONFIG_HID_CYPRESS=y
789# CONFIG_DRAGONRISE_FF is not set
786CONFIG_HID_EZKEY=y 790CONFIG_HID_EZKEY=y
791# CONFIG_HID_KYE is not set
787CONFIG_HID_GYRATION=y 792CONFIG_HID_GYRATION=y
793# CONFIG_HID_KENSINGTON is not set
788CONFIG_HID_LOGITECH=y 794CONFIG_HID_LOGITECH=y
789# CONFIG_LOGITECH_FF is not set 795# CONFIG_LOGITECH_FF is not set
790# CONFIG_LOGIRUMBLEPAD2_FF is not set 796# CONFIG_LOGIRUMBLEPAD2_FF is not set
@@ -943,6 +949,7 @@ CONFIG_EXT2_FS_POSIX_ACL=y
943CONFIG_EXT2_FS_SECURITY=y 949CONFIG_EXT2_FS_SECURITY=y
944# CONFIG_EXT2_FS_XIP is not set 950# CONFIG_EXT2_FS_XIP is not set
945CONFIG_EXT3_FS=y 951CONFIG_EXT3_FS=y
952# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
946CONFIG_EXT3_FS_XATTR=y 953CONFIG_EXT3_FS_XATTR=y
947# CONFIG_EXT3_FS_POSIX_ACL is not set 954# CONFIG_EXT3_FS_POSIX_ACL is not set
948# CONFIG_EXT3_FS_SECURITY is not set 955# CONFIG_EXT3_FS_SECURITY is not set
@@ -964,6 +971,11 @@ CONFIG_FILE_LOCKING=y
964# CONFIG_FUSE_FS is not set 971# CONFIG_FUSE_FS is not set
965 972
966# 973#
974# Caches
975#
976# CONFIG_FSCACHE is not set
977
978#
967# CD-ROM/DVD Filesystems 979# CD-ROM/DVD Filesystems
968# 980#
969# CONFIG_ISO9660_FS is not set 981# CONFIG_ISO9660_FS is not set
@@ -1021,6 +1033,7 @@ CONFIG_CRAMFS=y
1021# CONFIG_ROMFS_FS is not set 1033# CONFIG_ROMFS_FS is not set
1022# CONFIG_SYSV_FS is not set 1034# CONFIG_SYSV_FS is not set
1023# CONFIG_UFS_FS is not set 1035# CONFIG_UFS_FS is not set
1036# CONFIG_NILFS2_FS is not set
1024# CONFIG_NETWORK_FILESYSTEMS is not set 1037# CONFIG_NETWORK_FILESYSTEMS is not set
1025 1038
1026# 1039#
@@ -1085,6 +1098,7 @@ CONFIG_FRAME_WARN=1024
1085CONFIG_DEBUG_KERNEL=y 1098CONFIG_DEBUG_KERNEL=y
1086# CONFIG_DEBUG_SHIRQ is not set 1099# CONFIG_DEBUG_SHIRQ is not set
1087# CONFIG_DETECT_SOFTLOCKUP is not set 1100# CONFIG_DETECT_SOFTLOCKUP is not set
1101# CONFIG_DETECT_HUNG_TASK is not set
1088CONFIG_SCHED_DEBUG=y 1102CONFIG_SCHED_DEBUG=y
1089# CONFIG_SCHEDSTATS is not set 1103# CONFIG_SCHEDSTATS is not set
1090# CONFIG_TIMER_STATS is not set 1104# CONFIG_TIMER_STATS is not set
@@ -1119,6 +1133,7 @@ CONFIG_FRAME_POINTER=y
1119CONFIG_HAVE_FUNCTION_TRACER=y 1133CONFIG_HAVE_FUNCTION_TRACER=y
1120CONFIG_HAVE_DYNAMIC_FTRACE=y 1134CONFIG_HAVE_DYNAMIC_FTRACE=y
1121CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1135CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1136CONFIG_TRACING_SUPPORT=y
1122 1137
1123# 1138#
1124# Tracers 1139# Tracers
@@ -1127,9 +1142,14 @@ CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1127# CONFIG_IRQSOFF_TRACER is not set 1142# CONFIG_IRQSOFF_TRACER is not set
1128# CONFIG_SCHED_TRACER is not set 1143# CONFIG_SCHED_TRACER is not set
1129# CONFIG_CONTEXT_SWITCH_TRACER is not set 1144# CONFIG_CONTEXT_SWITCH_TRACER is not set
1145# CONFIG_EVENT_TRACER is not set
1130# CONFIG_BOOT_TRACER is not set 1146# CONFIG_BOOT_TRACER is not set
1131# CONFIG_TRACE_BRANCH_PROFILING is not set 1147# CONFIG_TRACE_BRANCH_PROFILING is not set
1132# CONFIG_STACK_TRACER is not set 1148# CONFIG_STACK_TRACER is not set
1149# CONFIG_KMEMTRACE is not set
1150# CONFIG_WORKQUEUE_TRACER is not set
1151# CONFIG_BLK_DEV_IO_TRACE is not set
1152# CONFIG_DMA_API_DEBUG is not set
1133# CONFIG_SAMPLES is not set 1153# CONFIG_SAMPLES is not set
1134CONFIG_HAVE_ARCH_KGDB=y 1154CONFIG_HAVE_ARCH_KGDB=y
1135# CONFIG_KGDB is not set 1155# CONFIG_KGDB is not set
@@ -1248,6 +1268,7 @@ CONFIG_CRYPTO_DEFLATE=y
1248# 1268#
1249# CONFIG_CRYPTO_ANSI_CPRNG is not set 1269# CONFIG_CRYPTO_ANSI_CPRNG is not set
1250CONFIG_CRYPTO_HW=y 1270CONFIG_CRYPTO_HW=y
1271# CONFIG_BINARY_PRINTF is not set
1251 1272
1252# 1273#
1253# Library routines 1274# Library routines
diff --git a/arch/sh/configs/se7722_defconfig b/arch/sh/configs/se7722_defconfig
index 82bdaac45fb5..726fdbdb2807 100644
--- a/arch/sh/configs/se7722_defconfig
+++ b/arch/sh/configs/se7722_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:55:10 2009 4# Mon Apr 27 13:05:29 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -69,7 +70,6 @@ CONFIG_INITRAMFS_SOURCE=""
69CONFIG_RD_GZIP=y 70CONFIG_RD_GZIP=y
70# CONFIG_RD_BZIP2 is not set 71# CONFIG_RD_BZIP2 is not set
71# CONFIG_RD_LZMA is not set 72# CONFIG_RD_LZMA is not set
72CONFIG_INITRAMFS_COMPRESSION_NONE=y
73CONFIG_CC_OPTIMIZE_FOR_SIZE=y 73CONFIG_CC_OPTIMIZE_FOR_SIZE=y
74CONFIG_SYSCTL=y 74CONFIG_SYSCTL=y
75CONFIG_ANON_INODES=y 75CONFIG_ANON_INODES=y
@@ -78,6 +78,7 @@ CONFIG_UID16=y
78CONFIG_SYSCTL_SYSCALL=y 78CONFIG_SYSCTL_SYSCALL=y
79CONFIG_KALLSYMS=y 79CONFIG_KALLSYMS=y
80# CONFIG_KALLSYMS_EXTRA_PASS is not set 80# CONFIG_KALLSYMS_EXTRA_PASS is not set
81# CONFIG_STRIP_ASM_SYMS is not set
81CONFIG_HOTPLUG=y 82CONFIG_HOTPLUG=y
82CONFIG_PRINTK=y 83CONFIG_PRINTK=y
83CONFIG_BUG=y 84CONFIG_BUG=y
@@ -97,6 +98,7 @@ CONFIG_COMPAT_BRK=y
97CONFIG_SLUB=y 98CONFIG_SLUB=y
98# CONFIG_SLOB is not set 99# CONFIG_SLOB is not set
99CONFIG_PROFILING=y 100CONFIG_PROFILING=y
101# CONFIG_MARKERS is not set
100# CONFIG_OPROFILE is not set 102# CONFIG_OPROFILE is not set
101CONFIG_HAVE_OPROFILE=y 103CONFIG_HAVE_OPROFILE=y
102# CONFIG_KPROBES is not set 104# CONFIG_KPROBES is not set
@@ -105,6 +107,8 @@ CONFIG_HAVE_KPROBES=y
105CONFIG_HAVE_KRETPROBES=y 107CONFIG_HAVE_KRETPROBES=y
106CONFIG_HAVE_ARCH_TRACEHOOK=y 108CONFIG_HAVE_ARCH_TRACEHOOK=y
107CONFIG_HAVE_CLK=y 109CONFIG_HAVE_CLK=y
110CONFIG_HAVE_DMA_API_DEBUG=y
111# CONFIG_SLOW_WORK is not set
108CONFIG_HAVE_GENERIC_DMA_COHERENT=y 112CONFIG_HAVE_GENERIC_DMA_COHERENT=y
109CONFIG_SLABINFO=y 113CONFIG_SLABINFO=y
110CONFIG_RT_MUTEXES=y 114CONFIG_RT_MUTEXES=y
@@ -117,7 +121,6 @@ CONFIG_MODULE_UNLOAD=y
117# CONFIG_MODULE_SRCVERSION_ALL is not set 121# CONFIG_MODULE_SRCVERSION_ALL is not set
118CONFIG_BLOCK=y 122CONFIG_BLOCK=y
119# CONFIG_LBD is not set 123# CONFIG_LBD is not set
120# CONFIG_BLK_DEV_IO_TRACE is not set
121# CONFIG_BLK_DEV_BSG is not set 124# CONFIG_BLK_DEV_BSG is not set
122# CONFIG_BLK_DEV_INTEGRITY is not set 125# CONFIG_BLK_DEV_INTEGRITY is not set
123 126
@@ -167,6 +170,7 @@ CONFIG_ARCH_SHMOBILE=y
167# CONFIG_CPU_SUBTYPE_SH7760 is not set 170# CONFIG_CPU_SUBTYPE_SH7760 is not set
168# CONFIG_CPU_SUBTYPE_SH4_202 is not set 171# CONFIG_CPU_SUBTYPE_SH4_202 is not set
169# CONFIG_CPU_SUBTYPE_SH7723 is not set 172# CONFIG_CPU_SUBTYPE_SH7723 is not set
173# CONFIG_CPU_SUBTYPE_SH7724 is not set
170# CONFIG_CPU_SUBTYPE_SH7763 is not set 174# CONFIG_CPU_SUBTYPE_SH7763 is not set
171# CONFIG_CPU_SUBTYPE_SH7770 is not set 175# CONFIG_CPU_SUBTYPE_SH7770 is not set
172# CONFIG_CPU_SUBTYPE_SH7780 is not set 176# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -176,8 +180,6 @@ CONFIG_ARCH_SHMOBILE=y
176# CONFIG_CPU_SUBTYPE_SH7343 is not set 180# CONFIG_CPU_SUBTYPE_SH7343 is not set
177CONFIG_CPU_SUBTYPE_SH7722=y 181CONFIG_CPU_SUBTYPE_SH7722=y
178# CONFIG_CPU_SUBTYPE_SH7366 is not set 182# CONFIG_CPU_SUBTYPE_SH7366 is not set
179# CONFIG_CPU_SUBTYPE_SH5_101 is not set
180# CONFIG_CPU_SUBTYPE_SH5_103 is not set
181 183
182# 184#
183# Memory management options 185# Memory management options
@@ -486,6 +488,7 @@ CONFIG_SCSI_WAIT_SCAN=m
486CONFIG_SCSI_LOWLEVEL=y 488CONFIG_SCSI_LOWLEVEL=y
487# CONFIG_ISCSI_TCP is not set 489# CONFIG_ISCSI_TCP is not set
488# CONFIG_LIBFC is not set 490# CONFIG_LIBFC is not set
491# CONFIG_LIBFCOE is not set
489# CONFIG_SCSI_DEBUG is not set 492# CONFIG_SCSI_DEBUG is not set
490# CONFIG_SCSI_DH is not set 493# CONFIG_SCSI_DH is not set
491# CONFIG_SCSI_OSD_INITIATOR is not set 494# CONFIG_SCSI_OSD_INITIATOR is not set
@@ -692,7 +695,6 @@ CONFIG_HID=y
692# 695#
693# Special HID drivers 696# Special HID drivers
694# 697#
695CONFIG_HID_COMPAT=y
696CONFIG_USB_SUPPORT=y 698CONFIG_USB_SUPPORT=y
697CONFIG_USB_ARCH_HAS_HCD=y 699CONFIG_USB_ARCH_HAS_HCD=y
698# CONFIG_USB_ARCH_HAS_OHCI is not set 700# CONFIG_USB_ARCH_HAS_OHCI is not set
@@ -766,6 +768,7 @@ CONFIG_EXT2_FS=y
766# CONFIG_EXT2_FS_XATTR is not set 768# CONFIG_EXT2_FS_XATTR is not set
767# CONFIG_EXT2_FS_XIP is not set 769# CONFIG_EXT2_FS_XIP is not set
768CONFIG_EXT3_FS=y 770CONFIG_EXT3_FS=y
771# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
769CONFIG_EXT3_FS_XATTR=y 772CONFIG_EXT3_FS_XATTR=y
770# CONFIG_EXT3_FS_POSIX_ACL is not set 773# CONFIG_EXT3_FS_POSIX_ACL is not set
771# CONFIG_EXT3_FS_SECURITY is not set 774# CONFIG_EXT3_FS_SECURITY is not set
@@ -789,6 +792,11 @@ CONFIG_INOTIFY_USER=y
789# CONFIG_FUSE_FS is not set 792# CONFIG_FUSE_FS is not set
790 793
791# 794#
795# Caches
796#
797# CONFIG_FSCACHE is not set
798
799#
792# CD-ROM/DVD Filesystems 800# CD-ROM/DVD Filesystems
793# 801#
794# CONFIG_ISO9660_FS is not set 802# CONFIG_ISO9660_FS is not set
@@ -832,6 +840,7 @@ CONFIG_MISC_FILESYSTEMS=y
832# CONFIG_ROMFS_FS is not set 840# CONFIG_ROMFS_FS is not set
833# CONFIG_SYSV_FS is not set 841# CONFIG_SYSV_FS is not set
834# CONFIG_UFS_FS is not set 842# CONFIG_UFS_FS is not set
843# CONFIG_NILFS2_FS is not set
835CONFIG_NETWORK_FILESYSTEMS=y 844CONFIG_NETWORK_FILESYSTEMS=y
836# CONFIG_NFS_FS is not set 845# CONFIG_NFS_FS is not set
837# CONFIG_NFSD is not set 846# CONFIG_NFSD is not set
@@ -872,11 +881,25 @@ CONFIG_DEBUG_FS=y
872CONFIG_HAVE_FUNCTION_TRACER=y 881CONFIG_HAVE_FUNCTION_TRACER=y
873CONFIG_HAVE_DYNAMIC_FTRACE=y 882CONFIG_HAVE_DYNAMIC_FTRACE=y
874CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 883CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
884CONFIG_TRACING_SUPPORT=y
875 885
876# 886#
877# Tracers 887# Tracers
878# 888#
889# CONFIG_FUNCTION_TRACER is not set
890# CONFIG_IRQSOFF_TRACER is not set
891# CONFIG_PREEMPT_TRACER is not set
892# CONFIG_SCHED_TRACER is not set
893# CONFIG_CONTEXT_SWITCH_TRACER is not set
894# CONFIG_EVENT_TRACER is not set
895# CONFIG_BOOT_TRACER is not set
896# CONFIG_TRACE_BRANCH_PROFILING is not set
897# CONFIG_STACK_TRACER is not set
898# CONFIG_KMEMTRACE is not set
899# CONFIG_WORKQUEUE_TRACER is not set
900# CONFIG_BLK_DEV_IO_TRACE is not set
879# CONFIG_DYNAMIC_DEBUG is not set 901# CONFIG_DYNAMIC_DEBUG is not set
902# CONFIG_DMA_API_DEBUG is not set
880# CONFIG_SAMPLES is not set 903# CONFIG_SAMPLES is not set
881CONFIG_HAVE_ARCH_KGDB=y 904CONFIG_HAVE_ARCH_KGDB=y
882CONFIG_SH_STANDARD_BIOS=y 905CONFIG_SH_STANDARD_BIOS=y
@@ -977,6 +1000,7 @@ CONFIG_CRYPTO=y
977# 1000#
978# CONFIG_CRYPTO_ANSI_CPRNG is not set 1001# CONFIG_CRYPTO_ANSI_CPRNG is not set
979CONFIG_CRYPTO_HW=y 1002CONFIG_CRYPTO_HW=y
1003# CONFIG_BINARY_PRINTF is not set
980 1004
981# 1005#
982# Library routines 1006# Library routines
diff --git a/arch/sh/configs/se7724_defconfig b/arch/sh/configs/se7724_defconfig
new file mode 100644
index 000000000000..96d2587467e6
--- /dev/null
+++ b/arch/sh/configs/se7724_defconfig
@@ -0,0 +1,1552 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.30-rc6
4# Tue May 26 13:18:09 2009
5#
6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
10CONFIG_RWSEM_GENERIC_SPINLOCK=y
11CONFIG_GENERIC_BUG=y
12CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
16CONFIG_GENERIC_IRQ_PROBE=y
17CONFIG_GENERIC_GPIO=y
18CONFIG_GENERIC_TIME=y
19CONFIG_GENERIC_CLOCKEVENTS=y
20CONFIG_ARCH_SUSPEND_POSSIBLE=y
21CONFIG_ARCH_HIBERNATION_POSSIBLE=y
22CONFIG_SYS_SUPPORTS_CMT=y
23CONFIG_SYS_SUPPORTS_TMU=y
24CONFIG_STACKTRACE_SUPPORT=y
25CONFIG_LOCKDEP_SUPPORT=y
26CONFIG_HAVE_LATENCYTOP_SUPPORT=y
27# CONFIG_ARCH_HAS_ILOG2_U32 is not set
28# CONFIG_ARCH_HAS_ILOG2_U64 is not set
29CONFIG_ARCH_NO_VIRT_TO_BUS=y
30CONFIG_ARCH_HAS_DEFAULT_IDLE=y
31CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
32
33#
34# General setup
35#
36CONFIG_EXPERIMENTAL=y
37CONFIG_BROKEN_ON_SMP=y
38CONFIG_LOCK_KERNEL=y
39CONFIG_INIT_ENV_ARG_LIMIT=32
40CONFIG_LOCALVERSION=""
41# CONFIG_LOCALVERSION_AUTO is not set
42CONFIG_SWAP=y
43CONFIG_SYSVIPC=y
44CONFIG_SYSVIPC_SYSCTL=y
45# CONFIG_POSIX_MQUEUE is not set
46CONFIG_BSD_PROCESS_ACCT=y
47# CONFIG_BSD_PROCESS_ACCT_V3 is not set
48# CONFIG_TASKSTATS is not set
49# CONFIG_AUDIT is not set
50
51#
52# RCU Subsystem
53#
54CONFIG_CLASSIC_RCU=y
55# CONFIG_TREE_RCU is not set
56# CONFIG_PREEMPT_RCU is not set
57# CONFIG_TREE_RCU_TRACE is not set
58# CONFIG_PREEMPT_RCU_TRACE is not set
59# CONFIG_IKCONFIG is not set
60CONFIG_LOG_BUF_SHIFT=14
61CONFIG_GROUP_SCHED=y
62CONFIG_FAIR_GROUP_SCHED=y
63# CONFIG_RT_GROUP_SCHED is not set
64CONFIG_USER_SCHED=y
65# CONFIG_CGROUP_SCHED is not set
66# CONFIG_CGROUPS is not set
67CONFIG_SYSFS_DEPRECATED=y
68CONFIG_SYSFS_DEPRECATED_V2=y
69# CONFIG_RELAY is not set
70# CONFIG_NAMESPACES is not set
71# CONFIG_BLK_DEV_INITRD is not set
72CONFIG_CC_OPTIMIZE_FOR_SIZE=y
73CONFIG_SYSCTL=y
74CONFIG_ANON_INODES=y
75CONFIG_EMBEDDED=y
76CONFIG_UID16=y
77CONFIG_SYSCTL_SYSCALL=y
78# CONFIG_KALLSYMS is not set
79# CONFIG_STRIP_ASM_SYMS is not set
80CONFIG_HOTPLUG=y
81CONFIG_PRINTK=y
82CONFIG_BUG=y
83CONFIG_ELF_CORE=y
84CONFIG_BASE_FULL=y
85CONFIG_FUTEX=y
86CONFIG_EPOLL=y
87CONFIG_SIGNALFD=y
88CONFIG_TIMERFD=y
89CONFIG_EVENTFD=y
90CONFIG_SHMEM=y
91CONFIG_AIO=y
92CONFIG_VM_EVENT_COUNTERS=y
93CONFIG_COMPAT_BRK=y
94CONFIG_SLAB=y
95# CONFIG_SLUB is not set
96# CONFIG_SLOB is not set
97# CONFIG_PROFILING is not set
98# CONFIG_MARKERS is not set
99CONFIG_HAVE_OPROFILE=y
100CONFIG_HAVE_IOREMAP_PROT=y
101CONFIG_HAVE_KPROBES=y
102CONFIG_HAVE_KRETPROBES=y
103CONFIG_HAVE_ARCH_TRACEHOOK=y
104CONFIG_HAVE_CLK=y
105CONFIG_HAVE_DMA_API_DEBUG=y
106# CONFIG_SLOW_WORK is not set
107CONFIG_HAVE_GENERIC_DMA_COHERENT=y
108CONFIG_SLABINFO=y
109CONFIG_RT_MUTEXES=y
110CONFIG_BASE_SMALL=0
111CONFIG_MODULES=y
112# CONFIG_MODULE_FORCE_LOAD is not set
113CONFIG_MODULE_UNLOAD=y
114# CONFIG_MODULE_FORCE_UNLOAD is not set
115# CONFIG_MODVERSIONS is not set
116# CONFIG_MODULE_SRCVERSION_ALL is not set
117CONFIG_BLOCK=y
118# CONFIG_LBD is not set
119# CONFIG_BLK_DEV_BSG is not set
120# CONFIG_BLK_DEV_INTEGRITY is not set
121
122#
123# IO Schedulers
124#
125CONFIG_IOSCHED_NOOP=y
126CONFIG_IOSCHED_AS=y
127CONFIG_IOSCHED_DEADLINE=y
128CONFIG_IOSCHED_CFQ=y
129# CONFIG_DEFAULT_AS is not set
130# CONFIG_DEFAULT_DEADLINE is not set
131CONFIG_DEFAULT_CFQ=y
132# CONFIG_DEFAULT_NOOP is not set
133CONFIG_DEFAULT_IOSCHED="cfq"
134# CONFIG_FREEZER is not set
135
136#
137# System type
138#
139CONFIG_CPU_SH4=y
140CONFIG_CPU_SH4A=y
141CONFIG_CPU_SHX2=y
142CONFIG_ARCH_SHMOBILE=y
143# CONFIG_CPU_SUBTYPE_SH7619 is not set
144# CONFIG_CPU_SUBTYPE_SH7201 is not set
145# CONFIG_CPU_SUBTYPE_SH7203 is not set
146# CONFIG_CPU_SUBTYPE_SH7206 is not set
147# CONFIG_CPU_SUBTYPE_SH7263 is not set
148# CONFIG_CPU_SUBTYPE_MXG is not set
149# CONFIG_CPU_SUBTYPE_SH7705 is not set
150# CONFIG_CPU_SUBTYPE_SH7706 is not set
151# CONFIG_CPU_SUBTYPE_SH7707 is not set
152# CONFIG_CPU_SUBTYPE_SH7708 is not set
153# CONFIG_CPU_SUBTYPE_SH7709 is not set
154# CONFIG_CPU_SUBTYPE_SH7710 is not set
155# CONFIG_CPU_SUBTYPE_SH7712 is not set
156# CONFIG_CPU_SUBTYPE_SH7720 is not set
157# CONFIG_CPU_SUBTYPE_SH7721 is not set
158# CONFIG_CPU_SUBTYPE_SH7750 is not set
159# CONFIG_CPU_SUBTYPE_SH7091 is not set
160# CONFIG_CPU_SUBTYPE_SH7750R is not set
161# CONFIG_CPU_SUBTYPE_SH7750S is not set
162# CONFIG_CPU_SUBTYPE_SH7751 is not set
163# CONFIG_CPU_SUBTYPE_SH7751R is not set
164# CONFIG_CPU_SUBTYPE_SH7760 is not set
165# CONFIG_CPU_SUBTYPE_SH4_202 is not set
166# CONFIG_CPU_SUBTYPE_SH7723 is not set
167CONFIG_CPU_SUBTYPE_SH7724=y
168# CONFIG_CPU_SUBTYPE_SH7763 is not set
169# CONFIG_CPU_SUBTYPE_SH7770 is not set
170# CONFIG_CPU_SUBTYPE_SH7780 is not set
171# CONFIG_CPU_SUBTYPE_SH7785 is not set
172# CONFIG_CPU_SUBTYPE_SH7786 is not set
173# CONFIG_CPU_SUBTYPE_SHX3 is not set
174# CONFIG_CPU_SUBTYPE_SH7343 is not set
175# CONFIG_CPU_SUBTYPE_SH7722 is not set
176# CONFIG_CPU_SUBTYPE_SH7366 is not set
177
178#
179# Memory management options
180#
181CONFIG_QUICKLIST=y
182CONFIG_MMU=y
183CONFIG_PAGE_OFFSET=0x80000000
184CONFIG_FORCE_MAX_ZONEORDER=11
185CONFIG_MEMORY_START=0x08000000
186CONFIG_MEMORY_SIZE=0x08000000
187CONFIG_29BIT=y
188# CONFIG_X2TLB is not set
189CONFIG_VSYSCALL=y
190CONFIG_ARCH_FLATMEM_ENABLE=y
191CONFIG_ARCH_SPARSEMEM_ENABLE=y
192CONFIG_ARCH_SPARSEMEM_DEFAULT=y
193CONFIG_MAX_ACTIVE_REGIONS=1
194CONFIG_ARCH_POPULATES_NODE_MAP=y
195CONFIG_ARCH_SELECT_MEMORY_MODEL=y
196CONFIG_PAGE_SIZE_4KB=y
197# CONFIG_PAGE_SIZE_8KB is not set
198# CONFIG_PAGE_SIZE_16KB is not set
199# CONFIG_PAGE_SIZE_64KB is not set
200CONFIG_SELECT_MEMORY_MODEL=y
201CONFIG_FLATMEM_MANUAL=y
202# CONFIG_DISCONTIGMEM_MANUAL is not set
203# CONFIG_SPARSEMEM_MANUAL is not set
204CONFIG_FLATMEM=y
205CONFIG_FLAT_NODE_MEM_MAP=y
206CONFIG_SPARSEMEM_STATIC=y
207CONFIG_PAGEFLAGS_EXTENDED=y
208CONFIG_SPLIT_PTLOCK_CPUS=4
209# CONFIG_PHYS_ADDR_T_64BIT is not set
210CONFIG_ZONE_DMA_FLAG=0
211CONFIG_NR_QUICK=2
212CONFIG_UNEVICTABLE_LRU=y
213CONFIG_HAVE_MLOCK=y
214CONFIG_HAVE_MLOCKED_PAGE_BIT=y
215
216#
217# Cache configuration
218#
219CONFIG_CACHE_WRITEBACK=y
220# CONFIG_CACHE_WRITETHROUGH is not set
221# CONFIG_CACHE_OFF is not set
222
223#
224# Processor features
225#
226CONFIG_CPU_LITTLE_ENDIAN=y
227# CONFIG_CPU_BIG_ENDIAN is not set
228CONFIG_SH_FPU=y
229# CONFIG_SH_STORE_QUEUES is not set
230CONFIG_CPU_HAS_INTEVT=y
231CONFIG_CPU_HAS_SR_RB=y
232CONFIG_CPU_HAS_PTEA=y
233CONFIG_CPU_HAS_FPU=y
234
235#
236# Board support
237#
238CONFIG_SOLUTION_ENGINE=y
239CONFIG_SH_7724_SOLUTION_ENGINE=y
240
241#
242# Timer and clock configuration
243#
244CONFIG_SH_TIMER_TMU=y
245# CONFIG_SH_TIMER_CMT is not set
246CONFIG_SH_PCLK_FREQ=33333333
247# CONFIG_NO_HZ is not set
248# CONFIG_HIGH_RES_TIMERS is not set
249CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
250
251#
252# CPU Frequency scaling
253#
254# CONFIG_CPU_FREQ is not set
255
256#
257# DMA support
258#
259# CONFIG_SH_DMA is not set
260
261#
262# Companion Chips
263#
264
265#
266# Additional SuperH Device Drivers
267#
268CONFIG_HEARTBEAT=y
269# CONFIG_PUSH_SWITCH is not set
270
271#
272# Kernel features
273#
274# CONFIG_HZ_100 is not set
275CONFIG_HZ_250=y
276# CONFIG_HZ_300 is not set
277# CONFIG_HZ_1000 is not set
278CONFIG_HZ=250
279# CONFIG_SCHED_HRTICK is not set
280# CONFIG_KEXEC is not set
281# CONFIG_CRASH_DUMP is not set
282CONFIG_SECCOMP=y
283# CONFIG_PREEMPT_NONE is not set
284# CONFIG_PREEMPT_VOLUNTARY is not set
285CONFIG_PREEMPT=y
286CONFIG_GUSA=y
287
288#
289# Boot options
290#
291CONFIG_ZERO_PAGE_OFFSET=0x00001000
292CONFIG_BOOT_LINK_OFFSET=0x00800000
293CONFIG_ENTRY_OFFSET=0x00001000
294CONFIG_CMDLINE_BOOL=y
295CONFIG_CMDLINE="console=tty1 console=ttySC3,115200 root=/dev/nfs ip=dhcp memchunk.vpu=4m"
296
297#
298# Bus options
299#
300# CONFIG_ARCH_SUPPORTS_MSI is not set
301# CONFIG_PCCARD is not set
302
303#
304# Executable file formats
305#
306CONFIG_BINFMT_ELF=y
307# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
308# CONFIG_HAVE_AOUT is not set
309# CONFIG_BINFMT_MISC is not set
310
311#
312# Power management options (EXPERIMENTAL)
313#
314# CONFIG_PM is not set
315# CONFIG_CPU_IDLE is not set
316CONFIG_NET=y
317
318#
319# Networking options
320#
321CONFIG_PACKET=y
322# CONFIG_PACKET_MMAP is not set
323CONFIG_UNIX=y
324# CONFIG_NET_KEY is not set
325CONFIG_INET=y
326# CONFIG_IP_MULTICAST is not set
327CONFIG_IP_ADVANCED_ROUTER=y
328CONFIG_ASK_IP_FIB_HASH=y
329# CONFIG_IP_FIB_TRIE is not set
330CONFIG_IP_FIB_HASH=y
331# CONFIG_IP_MULTIPLE_TABLES is not set
332# CONFIG_IP_ROUTE_MULTIPATH is not set
333# CONFIG_IP_ROUTE_VERBOSE is not set
334CONFIG_IP_PNP=y
335CONFIG_IP_PNP_DHCP=y
336# CONFIG_IP_PNP_BOOTP is not set
337# CONFIG_IP_PNP_RARP is not set
338# CONFIG_NET_IPIP is not set
339# CONFIG_NET_IPGRE is not set
340# CONFIG_ARPD is not set
341# CONFIG_SYN_COOKIES is not set
342# CONFIG_INET_AH is not set
343# CONFIG_INET_ESP is not set
344# CONFIG_INET_IPCOMP is not set
345# CONFIG_INET_XFRM_TUNNEL is not set
346# CONFIG_INET_TUNNEL is not set
347# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
348# CONFIG_INET_XFRM_MODE_TUNNEL is not set
349# CONFIG_INET_XFRM_MODE_BEET is not set
350# CONFIG_INET_LRO is not set
351CONFIG_INET_DIAG=y
352CONFIG_INET_TCP_DIAG=y
353# CONFIG_TCP_CONG_ADVANCED is not set
354CONFIG_TCP_CONG_CUBIC=y
355CONFIG_DEFAULT_TCP_CONG="cubic"
356# CONFIG_TCP_MD5SIG is not set
357# CONFIG_IPV6 is not set
358# CONFIG_NETWORK_SECMARK is not set
359# CONFIG_NETFILTER is not set
360# CONFIG_IP_DCCP is not set
361# CONFIG_IP_SCTP is not set
362# CONFIG_TIPC is not set
363# CONFIG_ATM is not set
364# CONFIG_BRIDGE is not set
365# CONFIG_NET_DSA is not set
366# CONFIG_VLAN_8021Q is not set
367# CONFIG_DECNET is not set
368# CONFIG_LLC2 is not set
369# CONFIG_IPX is not set
370# CONFIG_ATALK is not set
371# CONFIG_X25 is not set
372# CONFIG_LAPB is not set
373# CONFIG_ECONET is not set
374# CONFIG_WAN_ROUTER is not set
375# CONFIG_PHONET is not set
376# CONFIG_NET_SCHED is not set
377# CONFIG_DCB is not set
378
379#
380# Network testing
381#
382# CONFIG_NET_PKTGEN is not set
383# CONFIG_HAMRADIO is not set
384# CONFIG_CAN is not set
385# CONFIG_IRDA is not set
386# CONFIG_BT is not set
387# CONFIG_AF_RXRPC is not set
388CONFIG_WIRELESS=y
389# CONFIG_CFG80211 is not set
390# CONFIG_WIRELESS_OLD_REGULATORY is not set
391# CONFIG_WIRELESS_EXT is not set
392# CONFIG_LIB80211 is not set
393# CONFIG_MAC80211 is not set
394# CONFIG_WIMAX is not set
395# CONFIG_RFKILL is not set
396# CONFIG_NET_9P is not set
397
398#
399# Device Drivers
400#
401
402#
403# Generic Driver Options
404#
405CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
406CONFIG_STANDALONE=y
407CONFIG_PREVENT_FIRMWARE_BUILD=y
408CONFIG_FW_LOADER=y
409CONFIG_FIRMWARE_IN_KERNEL=y
410CONFIG_EXTRA_FIRMWARE=""
411# CONFIG_SYS_HYPERVISOR is not set
412# CONFIG_CONNECTOR is not set
413CONFIG_MTD=y
414# CONFIG_MTD_DEBUG is not set
415CONFIG_MTD_CONCAT=y
416CONFIG_MTD_PARTITIONS=y
417# CONFIG_MTD_TESTS is not set
418# CONFIG_MTD_REDBOOT_PARTS is not set
419CONFIG_MTD_CMDLINE_PARTS=y
420# CONFIG_MTD_AR7_PARTS is not set
421
422#
423# User Modules And Translation Layers
424#
425CONFIG_MTD_CHAR=y
426CONFIG_MTD_BLKDEVS=y
427CONFIG_MTD_BLOCK=y
428# CONFIG_FTL is not set
429# CONFIG_NFTL is not set
430# CONFIG_INFTL is not set
431# CONFIG_RFD_FTL is not set
432# CONFIG_SSFDC is not set
433# CONFIG_MTD_OOPS is not set
434
435#
436# RAM/ROM/Flash chip drivers
437#
438CONFIG_MTD_CFI=y
439# CONFIG_MTD_JEDECPROBE is not set
440CONFIG_MTD_GEN_PROBE=y
441# CONFIG_MTD_CFI_ADV_OPTIONS is not set
442CONFIG_MTD_MAP_BANK_WIDTH_1=y
443CONFIG_MTD_MAP_BANK_WIDTH_2=y
444CONFIG_MTD_MAP_BANK_WIDTH_4=y
445# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
446# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
447# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
448CONFIG_MTD_CFI_I1=y
449CONFIG_MTD_CFI_I2=y
450# CONFIG_MTD_CFI_I4 is not set
451# CONFIG_MTD_CFI_I8 is not set
452# CONFIG_MTD_CFI_INTELEXT is not set
453CONFIG_MTD_CFI_AMDSTD=y
454# CONFIG_MTD_CFI_STAA is not set
455CONFIG_MTD_CFI_UTIL=y
456# CONFIG_MTD_RAM is not set
457# CONFIG_MTD_ROM is not set
458# CONFIG_MTD_ABSENT is not set
459
460#
461# Mapping drivers for chip access
462#
463# CONFIG_MTD_COMPLEX_MAPPINGS is not set
464CONFIG_MTD_PHYSMAP=y
465# CONFIG_MTD_PHYSMAP_COMPAT is not set
466# CONFIG_MTD_PLATRAM is not set
467
468#
469# Self-contained MTD device drivers
470#
471# CONFIG_MTD_DATAFLASH is not set
472# CONFIG_MTD_M25P80 is not set
473# CONFIG_MTD_SLRAM is not set
474# CONFIG_MTD_PHRAM is not set
475# CONFIG_MTD_MTDRAM is not set
476# CONFIG_MTD_BLOCK2MTD is not set
477
478#
479# Disk-On-Chip Device Drivers
480#
481# CONFIG_MTD_DOC2000 is not set
482# CONFIG_MTD_DOC2001 is not set
483# CONFIG_MTD_DOC2001PLUS is not set
484CONFIG_MTD_NAND=y
485# CONFIG_MTD_NAND_VERIFY_WRITE is not set
486# CONFIG_MTD_NAND_ECC_SMC is not set
487# CONFIG_MTD_NAND_MUSEUM_IDS is not set
488CONFIG_MTD_NAND_IDS=y
489# CONFIG_MTD_NAND_DISKONCHIP is not set
490# CONFIG_MTD_NAND_NANDSIM is not set
491# CONFIG_MTD_NAND_PLATFORM is not set
492# CONFIG_MTD_ALAUDA is not set
493# CONFIG_MTD_ONENAND is not set
494
495#
496# LPDDR flash memory drivers
497#
498# CONFIG_MTD_LPDDR is not set
499
500#
501# UBI - Unsorted block images
502#
503CONFIG_MTD_UBI=y
504CONFIG_MTD_UBI_WL_THRESHOLD=4096
505CONFIG_MTD_UBI_BEB_RESERVE=1
506# CONFIG_MTD_UBI_GLUEBI is not set
507
508#
509# UBI debugging options
510#
511# CONFIG_MTD_UBI_DEBUG is not set
512# CONFIG_PARPORT is not set
513CONFIG_BLK_DEV=y
514# CONFIG_BLK_DEV_COW_COMMON is not set
515# CONFIG_BLK_DEV_LOOP is not set
516# CONFIG_BLK_DEV_NBD is not set
517# CONFIG_BLK_DEV_UB is not set
518CONFIG_BLK_DEV_RAM=y
519CONFIG_BLK_DEV_RAM_COUNT=4
520CONFIG_BLK_DEV_RAM_SIZE=4096
521# CONFIG_BLK_DEV_XIP is not set
522# CONFIG_CDROM_PKTCDVD is not set
523# CONFIG_ATA_OVER_ETH is not set
524# CONFIG_BLK_DEV_HD is not set
525CONFIG_MISC_DEVICES=y
526# CONFIG_ICS932S401 is not set
527# CONFIG_ENCLOSURE_SERVICES is not set
528# CONFIG_ISL29003 is not set
529# CONFIG_C2PORT is not set
530
531#
532# EEPROM support
533#
534# CONFIG_EEPROM_AT24 is not set
535# CONFIG_EEPROM_AT25 is not set
536# CONFIG_EEPROM_LEGACY is not set
537# CONFIG_EEPROM_93CX6 is not set
538CONFIG_HAVE_IDE=y
539# CONFIG_IDE is not set
540
541#
542# SCSI device support
543#
544# CONFIG_RAID_ATTRS is not set
545CONFIG_SCSI=y
546CONFIG_SCSI_DMA=y
547# CONFIG_SCSI_TGT is not set
548# CONFIG_SCSI_NETLINK is not set
549CONFIG_SCSI_PROC_FS=y
550
551#
552# SCSI support type (disk, tape, CD-ROM)
553#
554CONFIG_BLK_DEV_SD=y
555# CONFIG_CHR_DEV_ST is not set
556# CONFIG_CHR_DEV_OSST is not set
557# CONFIG_BLK_DEV_SR is not set
558# CONFIG_CHR_DEV_SG is not set
559# CONFIG_CHR_DEV_SCH is not set
560
561#
562# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
563#
564# CONFIG_SCSI_MULTI_LUN is not set
565# CONFIG_SCSI_CONSTANTS is not set
566# CONFIG_SCSI_LOGGING is not set
567# CONFIG_SCSI_SCAN_ASYNC is not set
568CONFIG_SCSI_WAIT_SCAN=m
569
570#
571# SCSI Transports
572#
573# CONFIG_SCSI_SPI_ATTRS is not set
574# CONFIG_SCSI_FC_ATTRS is not set
575# CONFIG_SCSI_ISCSI_ATTRS is not set
576# CONFIG_SCSI_SAS_LIBSAS is not set
577# CONFIG_SCSI_SRP_ATTRS is not set
578CONFIG_SCSI_LOWLEVEL=y
579# CONFIG_ISCSI_TCP is not set
580# CONFIG_LIBFC is not set
581# CONFIG_LIBFCOE is not set
582# CONFIG_SCSI_DEBUG is not set
583# CONFIG_SCSI_DH is not set
584# CONFIG_SCSI_OSD_INITIATOR is not set
585# CONFIG_ATA is not set
586# CONFIG_MD is not set
587CONFIG_NETDEVICES=y
588CONFIG_COMPAT_NET_DEV_OPS=y
589# CONFIG_DUMMY is not set
590# CONFIG_BONDING is not set
591# CONFIG_MACVLAN is not set
592# CONFIG_EQUALIZER is not set
593# CONFIG_TUN is not set
594# CONFIG_VETH is not set
595CONFIG_PHYLIB=y
596
597#
598# MII PHY device drivers
599#
600# CONFIG_MARVELL_PHY is not set
601# CONFIG_DAVICOM_PHY is not set
602# CONFIG_QSEMI_PHY is not set
603# CONFIG_LXT_PHY is not set
604# CONFIG_CICADA_PHY is not set
605# CONFIG_VITESSE_PHY is not set
606CONFIG_SMSC_PHY=y
607# CONFIG_BROADCOM_PHY is not set
608# CONFIG_ICPLUS_PHY is not set
609# CONFIG_REALTEK_PHY is not set
610# CONFIG_NATIONAL_PHY is not set
611# CONFIG_STE10XP is not set
612# CONFIG_LSI_ET1011C_PHY is not set
613# CONFIG_FIXED_PHY is not set
614CONFIG_MDIO_BITBANG=y
615# CONFIG_MDIO_GPIO is not set
616CONFIG_NET_ETHERNET=y
617CONFIG_MII=y
618# CONFIG_AX88796 is not set
619# CONFIG_STNIC is not set
620CONFIG_SMC91X=y
621# CONFIG_ENC28J60 is not set
622# CONFIG_ETHOC is not set
623# CONFIG_SMC911X is not set
624# CONFIG_SMSC911X is not set
625# CONFIG_DNET is not set
626# CONFIG_IBM_NEW_EMAC_ZMII is not set
627# CONFIG_IBM_NEW_EMAC_RGMII is not set
628# CONFIG_IBM_NEW_EMAC_TAH is not set
629# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
630# CONFIG_IBM_NEW_EMAC_NO_FLOW_CTRL is not set
631# CONFIG_IBM_NEW_EMAC_MAL_CLR_ICINTSTAT is not set
632# CONFIG_IBM_NEW_EMAC_MAL_COMMON_ERR is not set
633# CONFIG_B44 is not set
634# CONFIG_NETDEV_1000 is not set
635# CONFIG_NETDEV_10000 is not set
636
637#
638# Wireless LAN
639#
640# CONFIG_WLAN_PRE80211 is not set
641# CONFIG_WLAN_80211 is not set
642
643#
644# Enable WiMAX (Networking options) to see the WiMAX drivers
645#
646
647#
648# USB Network Adapters
649#
650# CONFIG_USB_CATC is not set
651# CONFIG_USB_KAWETH is not set
652# CONFIG_USB_PEGASUS is not set
653# CONFIG_USB_RTL8150 is not set
654# CONFIG_USB_USBNET is not set
655# CONFIG_WAN is not set
656# CONFIG_PPP is not set
657# CONFIG_SLIP is not set
658# CONFIG_NETCONSOLE is not set
659# CONFIG_NETPOLL is not set
660# CONFIG_NET_POLL_CONTROLLER is not set
661# CONFIG_ISDN is not set
662# CONFIG_PHONE is not set
663
664#
665# Input device support
666#
667CONFIG_INPUT=y
668# CONFIG_INPUT_FF_MEMLESS is not set
669# CONFIG_INPUT_POLLDEV is not set
670
671#
672# Userland interfaces
673#
674# CONFIG_INPUT_MOUSEDEV is not set
675# CONFIG_INPUT_JOYDEV is not set
676CONFIG_INPUT_EVDEV=y
677# CONFIG_INPUT_EVBUG is not set
678
679#
680# Input Device Drivers
681#
682CONFIG_INPUT_KEYBOARD=y
683# CONFIG_KEYBOARD_ATKBD is not set
684# CONFIG_KEYBOARD_SUNKBD is not set
685# CONFIG_KEYBOARD_LKKBD is not set
686# CONFIG_KEYBOARD_XTKBD is not set
687# CONFIG_KEYBOARD_NEWTON is not set
688# CONFIG_KEYBOARD_STOWAWAY is not set
689# CONFIG_KEYBOARD_GPIO is not set
690CONFIG_KEYBOARD_SH_KEYSC=y
691# CONFIG_INPUT_MOUSE is not set
692# CONFIG_INPUT_JOYSTICK is not set
693# CONFIG_INPUT_TABLET is not set
694# CONFIG_INPUT_TOUCHSCREEN is not set
695# CONFIG_INPUT_MISC is not set
696
697#
698# Hardware I/O ports
699#
700# CONFIG_SERIO is not set
701# CONFIG_GAMEPORT is not set
702
703#
704# Character devices
705#
706CONFIG_VT=y
707CONFIG_CONSOLE_TRANSLATIONS=y
708CONFIG_VT_CONSOLE=y
709CONFIG_HW_CONSOLE=y
710CONFIG_VT_HW_CONSOLE_BINDING=y
711CONFIG_DEVKMEM=y
712# CONFIG_SERIAL_NONSTANDARD is not set
713
714#
715# Serial drivers
716#
717# CONFIG_SERIAL_8250 is not set
718
719#
720# Non-8250 serial port support
721#
722# CONFIG_SERIAL_MAX3100 is not set
723CONFIG_SERIAL_SH_SCI=y
724CONFIG_SERIAL_SH_SCI_NR_UARTS=6
725CONFIG_SERIAL_SH_SCI_CONSOLE=y
726CONFIG_SERIAL_CORE=y
727CONFIG_SERIAL_CORE_CONSOLE=y
728CONFIG_UNIX98_PTYS=y
729# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
730CONFIG_LEGACY_PTYS=y
731CONFIG_LEGACY_PTY_COUNT=256
732# CONFIG_IPMI_HANDLER is not set
733CONFIG_HW_RANDOM=y
734# CONFIG_HW_RANDOM_TIMERIOMEM is not set
735# CONFIG_R3964 is not set
736# CONFIG_RAW_DRIVER is not set
737# CONFIG_TCG_TPM is not set
738CONFIG_I2C=y
739CONFIG_I2C_BOARDINFO=y
740CONFIG_I2C_CHARDEV=y
741CONFIG_I2C_HELPER_AUTO=y
742
743#
744# I2C Hardware Bus support
745#
746
747#
748# I2C system bus drivers (mostly embedded / system-on-chip)
749#
750# CONFIG_I2C_GPIO is not set
751# CONFIG_I2C_OCORES is not set
752CONFIG_I2C_SH_MOBILE=y
753# CONFIG_I2C_SIMTEC is not set
754
755#
756# External I2C/SMBus adapter drivers
757#
758# CONFIG_I2C_PARPORT_LIGHT is not set
759# CONFIG_I2C_TAOS_EVM is not set
760# CONFIG_I2C_TINY_USB is not set
761
762#
763# Other I2C/SMBus bus drivers
764#
765# CONFIG_I2C_PCA_PLATFORM is not set
766# CONFIG_I2C_STUB is not set
767
768#
769# Miscellaneous I2C Chip support
770#
771# CONFIG_DS1682 is not set
772# CONFIG_SENSORS_PCF8574 is not set
773# CONFIG_PCF8575 is not set
774# CONFIG_SENSORS_PCA9539 is not set
775# CONFIG_SENSORS_MAX6875 is not set
776# CONFIG_SENSORS_TSL2550 is not set
777# CONFIG_I2C_DEBUG_CORE is not set
778# CONFIG_I2C_DEBUG_ALGO is not set
779# CONFIG_I2C_DEBUG_BUS is not set
780# CONFIG_I2C_DEBUG_CHIP is not set
781CONFIG_SPI=y
782CONFIG_SPI_MASTER=y
783
784#
785# SPI Master Controller Drivers
786#
787CONFIG_SPI_BITBANG=y
788# CONFIG_SPI_GPIO is not set
789# CONFIG_SPI_SH_SCI is not set
790
791#
792# SPI Protocol Masters
793#
794# CONFIG_SPI_SPIDEV is not set
795# CONFIG_SPI_TLE62X0 is not set
796CONFIG_ARCH_REQUIRE_GPIOLIB=y
797CONFIG_GPIOLIB=y
798# CONFIG_GPIO_SYSFS is not set
799
800#
801# Memory mapped GPIO expanders:
802#
803
804#
805# I2C GPIO expanders:
806#
807# CONFIG_GPIO_MAX732X is not set
808# CONFIG_GPIO_PCA953X is not set
809# CONFIG_GPIO_PCF857X is not set
810
811#
812# PCI GPIO expanders:
813#
814
815#
816# SPI GPIO expanders:
817#
818# CONFIG_GPIO_MAX7301 is not set
819# CONFIG_GPIO_MCP23S08 is not set
820# CONFIG_W1 is not set
821# CONFIG_POWER_SUPPLY is not set
822# CONFIG_HWMON is not set
823# CONFIG_THERMAL is not set
824# CONFIG_THERMAL_HWMON is not set
825# CONFIG_WATCHDOG is not set
826CONFIG_SSB_POSSIBLE=y
827
828#
829# Sonics Silicon Backplane
830#
831# CONFIG_SSB is not set
832
833#
834# Multifunction device drivers
835#
836# CONFIG_MFD_CORE is not set
837# CONFIG_MFD_SM501 is not set
838# CONFIG_HTC_PASIC3 is not set
839# CONFIG_TPS65010 is not set
840# CONFIG_TWL4030_CORE is not set
841# CONFIG_MFD_TMIO is not set
842# CONFIG_PMIC_DA903X is not set
843# CONFIG_MFD_WM8400 is not set
844# CONFIG_MFD_WM8350_I2C is not set
845# CONFIG_MFD_PCF50633 is not set
846# CONFIG_REGULATOR is not set
847
848#
849# Multimedia devices
850#
851
852#
853# Multimedia core support
854#
855CONFIG_VIDEO_DEV=y
856CONFIG_VIDEO_V4L2_COMMON=y
857# CONFIG_VIDEO_ALLOW_V4L1 is not set
858CONFIG_VIDEO_V4L1_COMPAT=y
859# CONFIG_DVB_CORE is not set
860CONFIG_VIDEO_MEDIA=y
861
862#
863# Multimedia drivers
864#
865# CONFIG_MEDIA_ATTACH is not set
866CONFIG_MEDIA_TUNER=y
867# CONFIG_MEDIA_TUNER_CUSTOMISE is not set
868CONFIG_MEDIA_TUNER_SIMPLE=y
869CONFIG_MEDIA_TUNER_TDA8290=y
870CONFIG_MEDIA_TUNER_TDA9887=y
871CONFIG_MEDIA_TUNER_TEA5761=y
872CONFIG_MEDIA_TUNER_TEA5767=y
873CONFIG_MEDIA_TUNER_MT20XX=y
874CONFIG_MEDIA_TUNER_XC2028=y
875CONFIG_MEDIA_TUNER_XC5000=y
876CONFIG_MEDIA_TUNER_MC44S803=y
877CONFIG_VIDEO_V4L2=y
878CONFIG_VIDEOBUF_GEN=y
879CONFIG_VIDEOBUF_DMA_CONTIG=y
880CONFIG_VIDEO_CAPTURE_DRIVERS=y
881# CONFIG_VIDEO_ADV_DEBUG is not set
882# CONFIG_VIDEO_FIXED_MINOR_RANGES is not set
883CONFIG_VIDEO_HELPER_CHIPS_AUTO=y
884# CONFIG_VIDEO_VIVI is not set
885# CONFIG_VIDEO_SAA5246A is not set
886# CONFIG_VIDEO_SAA5249 is not set
887CONFIG_SOC_CAMERA=y
888# CONFIG_SOC_CAMERA_MT9M001 is not set
889# CONFIG_SOC_CAMERA_MT9M111 is not set
890# CONFIG_SOC_CAMERA_MT9T031 is not set
891# CONFIG_SOC_CAMERA_MT9V022 is not set
892# CONFIG_SOC_CAMERA_TW9910 is not set
893# CONFIG_SOC_CAMERA_PLATFORM is not set
894CONFIG_SOC_CAMERA_OV772X=y
895CONFIG_VIDEO_SH_MOBILE_CEU=y
896CONFIG_V4L_USB_DRIVERS=y
897# CONFIG_USB_VIDEO_CLASS is not set
898CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV=y
899CONFIG_USB_GSPCA=m
900# CONFIG_USB_M5602 is not set
901# CONFIG_USB_STV06XX is not set
902# CONFIG_USB_GSPCA_CONEX is not set
903# CONFIG_USB_GSPCA_ETOMS is not set
904# CONFIG_USB_GSPCA_FINEPIX is not set
905# CONFIG_USB_GSPCA_MARS is not set
906# CONFIG_USB_GSPCA_MR97310A is not set
907# CONFIG_USB_GSPCA_OV519 is not set
908# CONFIG_USB_GSPCA_OV534 is not set
909# CONFIG_USB_GSPCA_PAC207 is not set
910# CONFIG_USB_GSPCA_PAC7311 is not set
911# CONFIG_USB_GSPCA_SONIXB is not set
912# CONFIG_USB_GSPCA_SONIXJ is not set
913# CONFIG_USB_GSPCA_SPCA500 is not set
914# CONFIG_USB_GSPCA_SPCA501 is not set
915# CONFIG_USB_GSPCA_SPCA505 is not set
916# CONFIG_USB_GSPCA_SPCA506 is not set
917# CONFIG_USB_GSPCA_SPCA508 is not set
918# CONFIG_USB_GSPCA_SPCA561 is not set
919# CONFIG_USB_GSPCA_SQ905 is not set
920# CONFIG_USB_GSPCA_SQ905C is not set
921# CONFIG_USB_GSPCA_STK014 is not set
922# CONFIG_USB_GSPCA_SUNPLUS is not set
923# CONFIG_USB_GSPCA_T613 is not set
924# CONFIG_USB_GSPCA_TV8532 is not set
925# CONFIG_USB_GSPCA_VC032X is not set
926# CONFIG_USB_GSPCA_ZC3XX is not set
927# CONFIG_VIDEO_PVRUSB2 is not set
928# CONFIG_VIDEO_HDPVR is not set
929# CONFIG_VIDEO_EM28XX is not set
930# CONFIG_VIDEO_CX231XX is not set
931# CONFIG_VIDEO_USBVISION is not set
932# CONFIG_USB_ET61X251 is not set
933# CONFIG_USB_SN9C102 is not set
934# CONFIG_USB_ZC0301 is not set
935CONFIG_USB_PWC_INPUT_EVDEV=y
936# CONFIG_USB_ZR364XX is not set
937# CONFIG_USB_STKWEBCAM is not set
938# CONFIG_USB_S2255 is not set
939# CONFIG_RADIO_ADAPTERS is not set
940# CONFIG_DAB is not set
941
942#
943# Graphics support
944#
945# CONFIG_VGASTATE is not set
946# CONFIG_VIDEO_OUTPUT_CONTROL is not set
947CONFIG_FB=y
948# CONFIG_FIRMWARE_EDID is not set
949# CONFIG_FB_DDC is not set
950# CONFIG_FB_BOOT_VESA_SUPPORT is not set
951# CONFIG_FB_CFB_FILLRECT is not set
952# CONFIG_FB_CFB_COPYAREA is not set
953# CONFIG_FB_CFB_IMAGEBLIT is not set
954# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
955CONFIG_FB_SYS_FILLRECT=y
956CONFIG_FB_SYS_COPYAREA=y
957CONFIG_FB_SYS_IMAGEBLIT=y
958# CONFIG_FB_FOREIGN_ENDIAN is not set
959CONFIG_FB_SYS_FOPS=y
960CONFIG_FB_DEFERRED_IO=y
961# CONFIG_FB_SVGALIB is not set
962# CONFIG_FB_MACMODES is not set
963# CONFIG_FB_BACKLIGHT is not set
964# CONFIG_FB_MODE_HELPERS is not set
965# CONFIG_FB_TILEBLITTING is not set
966
967#
968# Frame buffer hardware drivers
969#
970# CONFIG_FB_S1D13XXX is not set
971CONFIG_FB_SH_MOBILE_LCDC=y
972# CONFIG_FB_VIRTUAL is not set
973# CONFIG_FB_METRONOME is not set
974# CONFIG_FB_MB862XX is not set
975# CONFIG_FB_BROADSHEET is not set
976# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
977
978#
979# Display device support
980#
981# CONFIG_DISPLAY_SUPPORT is not set
982
983#
984# Console display driver support
985#
986CONFIG_DUMMY_CONSOLE=y
987CONFIG_FRAMEBUFFER_CONSOLE=y
988# CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY is not set
989# CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
990# CONFIG_FONTS is not set
991CONFIG_FONT_8x8=y
992CONFIG_FONT_8x16=y
993CONFIG_LOGO=y
994# CONFIG_LOGO_LINUX_MONO is not set
995# CONFIG_LOGO_LINUX_VGA16 is not set
996# CONFIG_LOGO_LINUX_CLUT224 is not set
997# CONFIG_LOGO_SUPERH_MONO is not set
998# CONFIG_LOGO_SUPERH_VGA16 is not set
999CONFIG_LOGO_SUPERH_CLUT224=y
1000# CONFIG_SOUND is not set
1001CONFIG_HID_SUPPORT=y
1002CONFIG_HID=y
1003# CONFIG_HID_DEBUG is not set
1004# CONFIG_HIDRAW is not set
1005
1006#
1007# USB Input Devices
1008#
1009CONFIG_USB_HID=y
1010# CONFIG_HID_PID is not set
1011# CONFIG_USB_HIDDEV is not set
1012
1013#
1014# Special HID drivers
1015#
1016# CONFIG_HID_A4TECH is not set
1017# CONFIG_HID_APPLE is not set
1018# CONFIG_HID_BELKIN is not set
1019# CONFIG_HID_CHERRY is not set
1020# CONFIG_HID_CHICONY is not set
1021# CONFIG_HID_CYPRESS is not set
1022# CONFIG_DRAGONRISE_FF is not set
1023# CONFIG_HID_EZKEY is not set
1024# CONFIG_HID_KYE is not set
1025# CONFIG_HID_GYRATION is not set
1026# CONFIG_HID_KENSINGTON is not set
1027# CONFIG_HID_LOGITECH is not set
1028# CONFIG_HID_MICROSOFT is not set
1029# CONFIG_HID_MONTEREY is not set
1030# CONFIG_HID_NTRIG is not set
1031# CONFIG_HID_PANTHERLORD is not set
1032# CONFIG_HID_PETALYNX is not set
1033# CONFIG_HID_SAMSUNG is not set
1034# CONFIG_HID_SONY is not set
1035# CONFIG_HID_SUNPLUS is not set
1036# CONFIG_GREENASIA_FF is not set
1037# CONFIG_HID_TOPSEED is not set
1038# CONFIG_THRUSTMASTER_FF is not set
1039# CONFIG_ZEROPLUS_FF is not set
1040CONFIG_USB_SUPPORT=y
1041CONFIG_USB_ARCH_HAS_HCD=y
1042# CONFIG_USB_ARCH_HAS_OHCI is not set
1043# CONFIG_USB_ARCH_HAS_EHCI is not set
1044CONFIG_USB=y
1045# CONFIG_USB_DEBUG is not set
1046# CONFIG_USB_ANNOUNCE_NEW_DEVICES is not set
1047
1048#
1049# Miscellaneous USB options
1050#
1051# CONFIG_USB_DEVICEFS is not set
1052CONFIG_USB_DEVICE_CLASS=y
1053# CONFIG_USB_DYNAMIC_MINORS is not set
1054# CONFIG_USB_OTG is not set
1055# CONFIG_USB_OTG_WHITELIST is not set
1056# CONFIG_USB_OTG_BLACKLIST_HUB is not set
1057CONFIG_USB_MON=y
1058# CONFIG_USB_WUSB is not set
1059# CONFIG_USB_WUSB_CBAF is not set
1060
1061#
1062# USB Host Controller Drivers
1063#
1064# CONFIG_USB_C67X00_HCD is not set
1065# CONFIG_USB_OXU210HP_HCD is not set
1066# CONFIG_USB_ISP116X_HCD is not set
1067# CONFIG_USB_ISP1760_HCD is not set
1068# CONFIG_USB_SL811_HCD is not set
1069CONFIG_USB_R8A66597_HCD=y
1070# CONFIG_USB_HWA_HCD is not set
1071
1072#
1073# USB Device Class drivers
1074#
1075# CONFIG_USB_ACM is not set
1076# CONFIG_USB_PRINTER is not set
1077# CONFIG_USB_WDM is not set
1078# CONFIG_USB_TMC is not set
1079
1080#
1081# NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may
1082#
1083
1084#
1085# also be needed; see USB_STORAGE Help for more info
1086#
1087CONFIG_USB_STORAGE=y
1088# CONFIG_USB_STORAGE_DEBUG is not set
1089# CONFIG_USB_STORAGE_DATAFAB is not set
1090# CONFIG_USB_STORAGE_FREECOM is not set
1091# CONFIG_USB_STORAGE_ISD200 is not set
1092# CONFIG_USB_STORAGE_USBAT is not set
1093# CONFIG_USB_STORAGE_SDDR09 is not set
1094# CONFIG_USB_STORAGE_SDDR55 is not set
1095# CONFIG_USB_STORAGE_JUMPSHOT is not set
1096# CONFIG_USB_STORAGE_ALAUDA is not set
1097# CONFIG_USB_STORAGE_ONETOUCH is not set
1098# CONFIG_USB_STORAGE_KARMA is not set
1099# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
1100# CONFIG_USB_LIBUSUAL is not set
1101
1102#
1103# USB Imaging devices
1104#
1105# CONFIG_USB_MDC800 is not set
1106# CONFIG_USB_MICROTEK is not set
1107
1108#
1109# USB port drivers
1110#
1111# CONFIG_USB_SERIAL is not set
1112
1113#
1114# USB Miscellaneous drivers
1115#
1116# CONFIG_USB_EMI62 is not set
1117# CONFIG_USB_EMI26 is not set
1118# CONFIG_USB_ADUTUX is not set
1119# CONFIG_USB_SEVSEG is not set
1120# CONFIG_USB_RIO500 is not set
1121# CONFIG_USB_LEGOTOWER is not set
1122# CONFIG_USB_LCD is not set
1123# CONFIG_USB_BERRY_CHARGE is not set
1124# CONFIG_USB_LED is not set
1125# CONFIG_USB_CYPRESS_CY7C63 is not set
1126# CONFIG_USB_CYTHERM is not set
1127# CONFIG_USB_IDMOUSE is not set
1128# CONFIG_USB_FTDI_ELAN is not set
1129# CONFIG_USB_APPLEDISPLAY is not set
1130# CONFIG_USB_LD is not set
1131# CONFIG_USB_TRANCEVIBRATOR is not set
1132# CONFIG_USB_IOWARRIOR is not set
1133# CONFIG_USB_ISIGHTFW is not set
1134# CONFIG_USB_VST is not set
1135# CONFIG_USB_GADGET is not set
1136
1137#
1138# OTG and related infrastructure
1139#
1140# CONFIG_USB_GPIO_VBUS is not set
1141# CONFIG_NOP_USB_XCEIV is not set
1142CONFIG_MMC=y
1143# CONFIG_MMC_DEBUG is not set
1144# CONFIG_MMC_UNSAFE_RESUME is not set
1145
1146#
1147# MMC/SD/SDIO Card Drivers
1148#
1149CONFIG_MMC_BLOCK=y
1150CONFIG_MMC_BLOCK_BOUNCE=y
1151# CONFIG_SDIO_UART is not set
1152# CONFIG_MMC_TEST is not set
1153
1154#
1155# MMC/SD/SDIO Host Controller Drivers
1156#
1157# CONFIG_MMC_SDHCI is not set
1158CONFIG_MMC_SPI=y
1159# CONFIG_MEMSTICK is not set
1160# CONFIG_NEW_LEDS is not set
1161# CONFIG_ACCESSIBILITY is not set
1162CONFIG_RTC_LIB=y
1163CONFIG_RTC_CLASS=y
1164CONFIG_RTC_HCTOSYS=y
1165CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
1166# CONFIG_RTC_DEBUG is not set
1167
1168#
1169# RTC interfaces
1170#
1171CONFIG_RTC_INTF_SYSFS=y
1172CONFIG_RTC_INTF_PROC=y
1173CONFIG_RTC_INTF_DEV=y
1174# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
1175# CONFIG_RTC_DRV_TEST is not set
1176
1177#
1178# I2C RTC drivers
1179#
1180# CONFIG_RTC_DRV_DS1307 is not set
1181# CONFIG_RTC_DRV_DS1374 is not set
1182# CONFIG_RTC_DRV_DS1672 is not set
1183# CONFIG_RTC_DRV_MAX6900 is not set
1184# CONFIG_RTC_DRV_RS5C372 is not set
1185# CONFIG_RTC_DRV_ISL1208 is not set
1186# CONFIG_RTC_DRV_X1205 is not set
1187CONFIG_RTC_DRV_PCF8563=y
1188# CONFIG_RTC_DRV_PCF8583 is not set
1189# CONFIG_RTC_DRV_M41T80 is not set
1190# CONFIG_RTC_DRV_S35390A is not set
1191# CONFIG_RTC_DRV_FM3130 is not set
1192# CONFIG_RTC_DRV_RX8581 is not set
1193
1194#
1195# SPI RTC drivers
1196#
1197# CONFIG_RTC_DRV_M41T94 is not set
1198# CONFIG_RTC_DRV_DS1305 is not set
1199# CONFIG_RTC_DRV_DS1390 is not set
1200# CONFIG_RTC_DRV_MAX6902 is not set
1201# CONFIG_RTC_DRV_R9701 is not set
1202# CONFIG_RTC_DRV_RS5C348 is not set
1203# CONFIG_RTC_DRV_DS3234 is not set
1204
1205#
1206# Platform RTC drivers
1207#
1208# CONFIG_RTC_DRV_DS1286 is not set
1209# CONFIG_RTC_DRV_DS1511 is not set
1210# CONFIG_RTC_DRV_DS1553 is not set
1211# CONFIG_RTC_DRV_DS1742 is not set
1212# CONFIG_RTC_DRV_STK17TA8 is not set
1213# CONFIG_RTC_DRV_M48T86 is not set
1214# CONFIG_RTC_DRV_M48T35 is not set
1215# CONFIG_RTC_DRV_M48T59 is not set
1216# CONFIG_RTC_DRV_BQ4802 is not set
1217# CONFIG_RTC_DRV_V3020 is not set
1218
1219#
1220# on-CPU RTC drivers
1221#
1222# CONFIG_RTC_DRV_SH is not set
1223# CONFIG_RTC_DRV_GENERIC is not set
1224# CONFIG_DMADEVICES is not set
1225# CONFIG_AUXDISPLAY is not set
1226CONFIG_UIO=y
1227# CONFIG_UIO_PDRV is not set
1228CONFIG_UIO_PDRV_GENIRQ=y
1229# CONFIG_UIO_SMX is not set
1230# CONFIG_UIO_SERCOS3 is not set
1231# CONFIG_STAGING is not set
1232
1233#
1234# File systems
1235#
1236CONFIG_EXT2_FS=y
1237CONFIG_EXT2_FS_XATTR=y
1238CONFIG_EXT2_FS_POSIX_ACL=y
1239CONFIG_EXT2_FS_SECURITY=y
1240# CONFIG_EXT2_FS_XIP is not set
1241CONFIG_EXT3_FS=y
1242# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
1243CONFIG_EXT3_FS_XATTR=y
1244CONFIG_EXT3_FS_POSIX_ACL=y
1245CONFIG_EXT3_FS_SECURITY=y
1246# CONFIG_EXT4_FS is not set
1247CONFIG_JBD=y
1248CONFIG_FS_MBCACHE=y
1249# CONFIG_REISERFS_FS is not set
1250# CONFIG_JFS_FS is not set
1251CONFIG_FS_POSIX_ACL=y
1252CONFIG_FILE_LOCKING=y
1253# CONFIG_XFS_FS is not set
1254# CONFIG_OCFS2_FS is not set
1255# CONFIG_BTRFS_FS is not set
1256CONFIG_DNOTIFY=y
1257CONFIG_INOTIFY=y
1258CONFIG_INOTIFY_USER=y
1259# CONFIG_QUOTA is not set
1260# CONFIG_AUTOFS_FS is not set
1261# CONFIG_AUTOFS4_FS is not set
1262# CONFIG_FUSE_FS is not set
1263
1264#
1265# Caches
1266#
1267# CONFIG_FSCACHE is not set
1268
1269#
1270# CD-ROM/DVD Filesystems
1271#
1272# CONFIG_ISO9660_FS is not set
1273# CONFIG_UDF_FS is not set
1274
1275#
1276# DOS/FAT/NT Filesystems
1277#
1278CONFIG_FAT_FS=y
1279# CONFIG_MSDOS_FS is not set
1280CONFIG_VFAT_FS=y
1281CONFIG_FAT_DEFAULT_CODEPAGE=437
1282CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
1283# CONFIG_NTFS_FS is not set
1284
1285#
1286# Pseudo filesystems
1287#
1288CONFIG_PROC_FS=y
1289CONFIG_PROC_KCORE=y
1290CONFIG_PROC_SYSCTL=y
1291CONFIG_PROC_PAGE_MONITOR=y
1292CONFIG_SYSFS=y
1293CONFIG_TMPFS=y
1294# CONFIG_TMPFS_POSIX_ACL is not set
1295# CONFIG_HUGETLBFS is not set
1296# CONFIG_HUGETLB_PAGE is not set
1297# CONFIG_CONFIGFS_FS is not set
1298CONFIG_MISC_FILESYSTEMS=y
1299# CONFIG_ADFS_FS is not set
1300# CONFIG_AFFS_FS is not set
1301# CONFIG_HFS_FS is not set
1302# CONFIG_HFSPLUS_FS is not set
1303# CONFIG_BEFS_FS is not set
1304# CONFIG_BFS_FS is not set
1305# CONFIG_EFS_FS is not set
1306# CONFIG_JFFS2_FS is not set
1307# CONFIG_UBIFS_FS is not set
1308# CONFIG_CRAMFS is not set
1309# CONFIG_SQUASHFS is not set
1310# CONFIG_VXFS_FS is not set
1311# CONFIG_MINIX_FS is not set
1312# CONFIG_OMFS_FS is not set
1313# CONFIG_HPFS_FS is not set
1314# CONFIG_QNX4FS_FS is not set
1315# CONFIG_ROMFS_FS is not set
1316# CONFIG_SYSV_FS is not set
1317# CONFIG_UFS_FS is not set
1318# CONFIG_NILFS2_FS is not set
1319CONFIG_NETWORK_FILESYSTEMS=y
1320CONFIG_NFS_FS=y
1321CONFIG_NFS_V3=y
1322# CONFIG_NFS_V3_ACL is not set
1323# CONFIG_NFS_V4 is not set
1324CONFIG_ROOT_NFS=y
1325CONFIG_NFSD=y
1326CONFIG_NFSD_V3=y
1327# CONFIG_NFSD_V3_ACL is not set
1328# CONFIG_NFSD_V4 is not set
1329CONFIG_LOCKD=y
1330CONFIG_LOCKD_V4=y
1331CONFIG_EXPORTFS=y
1332CONFIG_NFS_COMMON=y
1333CONFIG_SUNRPC=y
1334# CONFIG_RPCSEC_GSS_KRB5 is not set
1335# CONFIG_RPCSEC_GSS_SPKM3 is not set
1336# CONFIG_SMB_FS is not set
1337# CONFIG_CIFS is not set
1338# CONFIG_NCP_FS is not set
1339# CONFIG_CODA_FS is not set
1340# CONFIG_AFS_FS is not set
1341
1342#
1343# Partition Types
1344#
1345# CONFIG_PARTITION_ADVANCED is not set
1346CONFIG_MSDOS_PARTITION=y
1347CONFIG_NLS=y
1348CONFIG_NLS_DEFAULT="iso8859-1"
1349CONFIG_NLS_CODEPAGE_437=y
1350# CONFIG_NLS_CODEPAGE_737 is not set
1351# CONFIG_NLS_CODEPAGE_775 is not set
1352# CONFIG_NLS_CODEPAGE_850 is not set
1353# CONFIG_NLS_CODEPAGE_852 is not set
1354# CONFIG_NLS_CODEPAGE_855 is not set
1355# CONFIG_NLS_CODEPAGE_857 is not set
1356# CONFIG_NLS_CODEPAGE_860 is not set
1357# CONFIG_NLS_CODEPAGE_861 is not set
1358# CONFIG_NLS_CODEPAGE_862 is not set
1359# CONFIG_NLS_CODEPAGE_863 is not set
1360# CONFIG_NLS_CODEPAGE_864 is not set
1361# CONFIG_NLS_CODEPAGE_865 is not set
1362# CONFIG_NLS_CODEPAGE_866 is not set
1363# CONFIG_NLS_CODEPAGE_869 is not set
1364# CONFIG_NLS_CODEPAGE_936 is not set
1365# CONFIG_NLS_CODEPAGE_950 is not set
1366CONFIG_NLS_CODEPAGE_932=y
1367# CONFIG_NLS_CODEPAGE_949 is not set
1368# CONFIG_NLS_CODEPAGE_874 is not set
1369# CONFIG_NLS_ISO8859_8 is not set
1370# CONFIG_NLS_CODEPAGE_1250 is not set
1371# CONFIG_NLS_CODEPAGE_1251 is not set
1372# CONFIG_NLS_ASCII is not set
1373CONFIG_NLS_ISO8859_1=y
1374# CONFIG_NLS_ISO8859_2 is not set
1375# CONFIG_NLS_ISO8859_3 is not set
1376# CONFIG_NLS_ISO8859_4 is not set
1377# CONFIG_NLS_ISO8859_5 is not set
1378# CONFIG_NLS_ISO8859_6 is not set
1379# CONFIG_NLS_ISO8859_7 is not set
1380# CONFIG_NLS_ISO8859_9 is not set
1381# CONFIG_NLS_ISO8859_13 is not set
1382# CONFIG_NLS_ISO8859_14 is not set
1383# CONFIG_NLS_ISO8859_15 is not set
1384# CONFIG_NLS_KOI8_R is not set
1385# CONFIG_NLS_KOI8_U is not set
1386# CONFIG_NLS_UTF8 is not set
1387# CONFIG_DLM is not set
1388
1389#
1390# Kernel hacking
1391#
1392CONFIG_TRACE_IRQFLAGS_SUPPORT=y
1393# CONFIG_PRINTK_TIME is not set
1394CONFIG_ENABLE_WARN_DEPRECATED=y
1395# CONFIG_ENABLE_MUST_CHECK is not set
1396CONFIG_FRAME_WARN=1024
1397# CONFIG_MAGIC_SYSRQ is not set
1398# CONFIG_UNUSED_SYMBOLS is not set
1399# CONFIG_DEBUG_FS is not set
1400# CONFIG_HEADERS_CHECK is not set
1401# CONFIG_DEBUG_KERNEL is not set
1402# CONFIG_DEBUG_BUGVERBOSE is not set
1403# CONFIG_DEBUG_MEMORY_INIT is not set
1404# CONFIG_RCU_CPU_STALL_DETECTOR is not set
1405# CONFIG_LATENCYTOP is not set
1406CONFIG_SYSCTL_SYSCALL_CHECK=y
1407CONFIG_HAVE_FUNCTION_TRACER=y
1408CONFIG_HAVE_DYNAMIC_FTRACE=y
1409CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1410CONFIG_TRACING_SUPPORT=y
1411
1412#
1413# Tracers
1414#
1415# CONFIG_FUNCTION_TRACER is not set
1416# CONFIG_IRQSOFF_TRACER is not set
1417# CONFIG_PREEMPT_TRACER is not set
1418# CONFIG_SCHED_TRACER is not set
1419# CONFIG_CONTEXT_SWITCH_TRACER is not set
1420# CONFIG_EVENT_TRACER is not set
1421# CONFIG_BOOT_TRACER is not set
1422# CONFIG_TRACE_BRANCH_PROFILING is not set
1423# CONFIG_STACK_TRACER is not set
1424# CONFIG_KMEMTRACE is not set
1425# CONFIG_WORKQUEUE_TRACER is not set
1426# CONFIG_BLK_DEV_IO_TRACE is not set
1427# CONFIG_DMA_API_DEBUG is not set
1428# CONFIG_SAMPLES is not set
1429CONFIG_HAVE_ARCH_KGDB=y
1430# CONFIG_SH_STANDARD_BIOS is not set
1431# CONFIG_EARLY_SCIF_CONSOLE is not set
1432
1433#
1434# Security options
1435#
1436# CONFIG_KEYS is not set
1437# CONFIG_SECURITY is not set
1438# CONFIG_SECURITYFS is not set
1439# CONFIG_SECURITY_FILE_CAPABILITIES is not set
1440CONFIG_CRYPTO=y
1441
1442#
1443# Crypto core or helper
1444#
1445# CONFIG_CRYPTO_FIPS is not set
1446CONFIG_CRYPTO_ALGAPI=y
1447CONFIG_CRYPTO_ALGAPI2=y
1448CONFIG_CRYPTO_AEAD2=y
1449CONFIG_CRYPTO_BLKCIPHER=y
1450CONFIG_CRYPTO_BLKCIPHER2=y
1451CONFIG_CRYPTO_HASH2=y
1452CONFIG_CRYPTO_RNG2=y
1453CONFIG_CRYPTO_PCOMP=y
1454CONFIG_CRYPTO_MANAGER=y
1455CONFIG_CRYPTO_MANAGER2=y
1456# CONFIG_CRYPTO_GF128MUL is not set
1457# CONFIG_CRYPTO_NULL is not set
1458CONFIG_CRYPTO_WORKQUEUE=y
1459# CONFIG_CRYPTO_CRYPTD is not set
1460# CONFIG_CRYPTO_AUTHENC is not set
1461# CONFIG_CRYPTO_TEST is not set
1462
1463#
1464# Authenticated Encryption with Associated Data
1465#
1466# CONFIG_CRYPTO_CCM is not set
1467# CONFIG_CRYPTO_GCM is not set
1468# CONFIG_CRYPTO_SEQIV is not set
1469
1470#
1471# Block modes
1472#
1473CONFIG_CRYPTO_CBC=y
1474# CONFIG_CRYPTO_CTR is not set
1475# CONFIG_CRYPTO_CTS is not set
1476# CONFIG_CRYPTO_ECB is not set
1477# CONFIG_CRYPTO_LRW is not set
1478# CONFIG_CRYPTO_PCBC is not set
1479# CONFIG_CRYPTO_XTS is not set
1480
1481#
1482# Hash modes
1483#
1484# CONFIG_CRYPTO_HMAC is not set
1485# CONFIG_CRYPTO_XCBC is not set
1486
1487#
1488# Digest
1489#
1490# CONFIG_CRYPTO_CRC32C is not set
1491# CONFIG_CRYPTO_MD4 is not set
1492# CONFIG_CRYPTO_MD5 is not set
1493# CONFIG_CRYPTO_MICHAEL_MIC is not set
1494# CONFIG_CRYPTO_RMD128 is not set
1495# CONFIG_CRYPTO_RMD160 is not set
1496# CONFIG_CRYPTO_RMD256 is not set
1497# CONFIG_CRYPTO_RMD320 is not set
1498# CONFIG_CRYPTO_SHA1 is not set
1499# CONFIG_CRYPTO_SHA256 is not set
1500# CONFIG_CRYPTO_SHA512 is not set
1501# CONFIG_CRYPTO_TGR192 is not set
1502# CONFIG_CRYPTO_WP512 is not set
1503
1504#
1505# Ciphers
1506#
1507# CONFIG_CRYPTO_AES is not set
1508# CONFIG_CRYPTO_ANUBIS is not set
1509# CONFIG_CRYPTO_ARC4 is not set
1510# CONFIG_CRYPTO_BLOWFISH is not set
1511# CONFIG_CRYPTO_CAMELLIA is not set
1512# CONFIG_CRYPTO_CAST5 is not set
1513# CONFIG_CRYPTO_CAST6 is not set
1514# CONFIG_CRYPTO_DES is not set
1515# CONFIG_CRYPTO_FCRYPT is not set
1516# CONFIG_CRYPTO_KHAZAD is not set
1517# CONFIG_CRYPTO_SALSA20 is not set
1518# CONFIG_CRYPTO_SEED is not set
1519# CONFIG_CRYPTO_SERPENT is not set
1520# CONFIG_CRYPTO_TEA is not set
1521# CONFIG_CRYPTO_TWOFISH is not set
1522
1523#
1524# Compression
1525#
1526# CONFIG_CRYPTO_DEFLATE is not set
1527# CONFIG_CRYPTO_ZLIB is not set
1528# CONFIG_CRYPTO_LZO is not set
1529
1530#
1531# Random Number Generation
1532#
1533# CONFIG_CRYPTO_ANSI_CPRNG is not set
1534CONFIG_CRYPTO_HW=y
1535# CONFIG_BINARY_PRINTF is not set
1536
1537#
1538# Library routines
1539#
1540CONFIG_BITREVERSE=y
1541CONFIG_GENERIC_FIND_LAST_BIT=y
1542# CONFIG_CRC_CCITT is not set
1543# CONFIG_CRC16 is not set
1544CONFIG_CRC_T10DIF=y
1545CONFIG_CRC_ITU_T=y
1546CONFIG_CRC32=y
1547CONFIG_CRC7=y
1548# CONFIG_LIBCRC32C is not set
1549CONFIG_HAS_IOMEM=y
1550CONFIG_HAS_IOPORT=y
1551CONFIG_HAS_DMA=y
1552CONFIG_NLATTR=y
diff --git a/arch/sh/configs/se7750_defconfig b/arch/sh/configs/se7750_defconfig
index ceef6d9138ee..ed1a1230f636 100644
--- a/arch/sh/configs/se7750_defconfig
+++ b/arch/sh/configs/se7750_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:57:31 2009 4# Mon Apr 27 13:06:02 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -70,6 +71,7 @@ CONFIG_UID16=y
70# CONFIG_SYSCTL_SYSCALL is not set 71# CONFIG_SYSCTL_SYSCALL is not set
71CONFIG_KALLSYMS=y 72CONFIG_KALLSYMS=y
72# CONFIG_KALLSYMS_EXTRA_PASS is not set 73# CONFIG_KALLSYMS_EXTRA_PASS is not set
74# CONFIG_STRIP_ASM_SYMS is not set
73# CONFIG_HOTPLUG is not set 75# CONFIG_HOTPLUG is not set
74CONFIG_PRINTK=y 76CONFIG_PRINTK=y
75CONFIG_BUG=y 77CONFIG_BUG=y
@@ -88,6 +90,7 @@ CONFIG_SLAB=y
88# CONFIG_SLUB is not set 90# CONFIG_SLUB is not set
89# CONFIG_SLOB is not set 91# CONFIG_SLOB is not set
90# CONFIG_PROFILING is not set 92# CONFIG_PROFILING is not set
93# CONFIG_MARKERS is not set
91CONFIG_HAVE_OPROFILE=y 94CONFIG_HAVE_OPROFILE=y
92# CONFIG_KPROBES is not set 95# CONFIG_KPROBES is not set
93CONFIG_HAVE_IOREMAP_PROT=y 96CONFIG_HAVE_IOREMAP_PROT=y
@@ -95,6 +98,8 @@ CONFIG_HAVE_KPROBES=y
95CONFIG_HAVE_KRETPROBES=y 98CONFIG_HAVE_KRETPROBES=y
96CONFIG_HAVE_ARCH_TRACEHOOK=y 99CONFIG_HAVE_ARCH_TRACEHOOK=y
97CONFIG_HAVE_CLK=y 100CONFIG_HAVE_CLK=y
101CONFIG_HAVE_DMA_API_DEBUG=y
102# CONFIG_SLOW_WORK is not set
98CONFIG_HAVE_GENERIC_DMA_COHERENT=y 103CONFIG_HAVE_GENERIC_DMA_COHERENT=y
99CONFIG_SLABINFO=y 104CONFIG_SLABINFO=y
100CONFIG_RT_MUTEXES=y 105CONFIG_RT_MUTEXES=y
@@ -106,7 +111,6 @@ CONFIG_MODULES=y
106# CONFIG_MODULE_SRCVERSION_ALL is not set 111# CONFIG_MODULE_SRCVERSION_ALL is not set
107CONFIG_BLOCK=y 112CONFIG_BLOCK=y
108# CONFIG_LBD is not set 113# CONFIG_LBD is not set
109# CONFIG_BLK_DEV_IO_TRACE is not set
110# CONFIG_BLK_DEV_BSG is not set 114# CONFIG_BLK_DEV_BSG is not set
111# CONFIG_BLK_DEV_INTEGRITY is not set 115# CONFIG_BLK_DEV_INTEGRITY is not set
112 116
@@ -152,6 +156,7 @@ CONFIG_CPU_SUBTYPE_SH7750=y
152# CONFIG_CPU_SUBTYPE_SH7760 is not set 156# CONFIG_CPU_SUBTYPE_SH7760 is not set
153# CONFIG_CPU_SUBTYPE_SH4_202 is not set 157# CONFIG_CPU_SUBTYPE_SH4_202 is not set
154# CONFIG_CPU_SUBTYPE_SH7723 is not set 158# CONFIG_CPU_SUBTYPE_SH7723 is not set
159# CONFIG_CPU_SUBTYPE_SH7724 is not set
155# CONFIG_CPU_SUBTYPE_SH7763 is not set 160# CONFIG_CPU_SUBTYPE_SH7763 is not set
156# CONFIG_CPU_SUBTYPE_SH7770 is not set 161# CONFIG_CPU_SUBTYPE_SH7770 is not set
157# CONFIG_CPU_SUBTYPE_SH7780 is not set 162# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -161,8 +166,6 @@ CONFIG_CPU_SUBTYPE_SH7750=y
161# CONFIG_CPU_SUBTYPE_SH7343 is not set 166# CONFIG_CPU_SUBTYPE_SH7343 is not set
162# CONFIG_CPU_SUBTYPE_SH7722 is not set 167# CONFIG_CPU_SUBTYPE_SH7722 is not set
163# CONFIG_CPU_SUBTYPE_SH7366 is not set 168# CONFIG_CPU_SUBTYPE_SH7366 is not set
164# CONFIG_CPU_SUBTYPE_SH5_101 is not set
165# CONFIG_CPU_SUBTYPE_SH5_103 is not set
166 169
167# 170#
168# Memory management options 171# Memory management options
@@ -553,6 +556,7 @@ CONFIG_SCSI_WAIT_SCAN=m
553CONFIG_SCSI_LOWLEVEL=y 556CONFIG_SCSI_LOWLEVEL=y
554# CONFIG_ISCSI_TCP is not set 557# CONFIG_ISCSI_TCP is not set
555# CONFIG_LIBFC is not set 558# CONFIG_LIBFC is not set
559# CONFIG_LIBFCOE is not set
556# CONFIG_SCSI_DEBUG is not set 560# CONFIG_SCSI_DEBUG is not set
557# CONFIG_SCSI_DH is not set 561# CONFIG_SCSI_DH is not set
558# CONFIG_SCSI_OSD_INITIATOR is not set 562# CONFIG_SCSI_OSD_INITIATOR is not set
@@ -775,6 +779,11 @@ CONFIG_INOTIFY_USER=y
775# CONFIG_FUSE_FS is not set 779# CONFIG_FUSE_FS is not set
776 780
777# 781#
782# Caches
783#
784# CONFIG_FSCACHE is not set
785
786#
778# CD-ROM/DVD Filesystems 787# CD-ROM/DVD Filesystems
779# 788#
780# CONFIG_ISO9660_FS is not set 789# CONFIG_ISO9660_FS is not set
@@ -829,6 +838,7 @@ CONFIG_JFFS2_RTIME=y
829# CONFIG_ROMFS_FS is not set 838# CONFIG_ROMFS_FS is not set
830# CONFIG_SYSV_FS is not set 839# CONFIG_SYSV_FS is not set
831# CONFIG_UFS_FS is not set 840# CONFIG_UFS_FS is not set
841# CONFIG_NILFS2_FS is not set
832CONFIG_NETWORK_FILESYSTEMS=y 842CONFIG_NETWORK_FILESYSTEMS=y
833CONFIG_NFS_FS=y 843CONFIG_NFS_FS=y
834# CONFIG_NFS_V3 is not set 844# CONFIG_NFS_V3 is not set
@@ -886,10 +896,23 @@ CONFIG_FRAME_WARN=1024
886CONFIG_HAVE_FUNCTION_TRACER=y 896CONFIG_HAVE_FUNCTION_TRACER=y
887CONFIG_HAVE_DYNAMIC_FTRACE=y 897CONFIG_HAVE_DYNAMIC_FTRACE=y
888CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 898CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
899CONFIG_TRACING_SUPPORT=y
889 900
890# 901#
891# Tracers 902# Tracers
892# 903#
904# CONFIG_FUNCTION_TRACER is not set
905# CONFIG_IRQSOFF_TRACER is not set
906# CONFIG_SCHED_TRACER is not set
907# CONFIG_CONTEXT_SWITCH_TRACER is not set
908# CONFIG_EVENT_TRACER is not set
909# CONFIG_BOOT_TRACER is not set
910# CONFIG_TRACE_BRANCH_PROFILING is not set
911# CONFIG_STACK_TRACER is not set
912# CONFIG_KMEMTRACE is not set
913# CONFIG_WORKQUEUE_TRACER is not set
914# CONFIG_BLK_DEV_IO_TRACE is not set
915# CONFIG_DMA_API_DEBUG is not set
893# CONFIG_SAMPLES is not set 916# CONFIG_SAMPLES is not set
894CONFIG_HAVE_ARCH_KGDB=y 917CONFIG_HAVE_ARCH_KGDB=y
895# CONFIG_SH_STANDARD_BIOS is not set 918# CONFIG_SH_STANDARD_BIOS is not set
@@ -989,6 +1012,7 @@ CONFIG_CRYPTO=y
989# 1012#
990# CONFIG_CRYPTO_ANSI_CPRNG is not set 1013# CONFIG_CRYPTO_ANSI_CPRNG is not set
991CONFIG_CRYPTO_HW=y 1014CONFIG_CRYPTO_HW=y
1015# CONFIG_BINARY_PRINTF is not set
992 1016
993# 1017#
994# Library routines 1018# Library routines
diff --git a/arch/sh/configs/se7751_defconfig b/arch/sh/configs/se7751_defconfig
index 67fc26b3a7d0..55f3b788e0cb 100644
--- a/arch/sh/configs/se7751_defconfig
+++ b/arch/sh/configs/se7751_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 18:59:59 2009 4# Mon Apr 27 13:06:44 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -65,7 +66,6 @@ CONFIG_INITRAMFS_SOURCE=""
65CONFIG_RD_GZIP=y 66CONFIG_RD_GZIP=y
66# CONFIG_RD_BZIP2 is not set 67# CONFIG_RD_BZIP2 is not set
67# CONFIG_RD_LZMA is not set 68# CONFIG_RD_LZMA is not set
68CONFIG_INITRAMFS_COMPRESSION_NONE=y
69# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set 69# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
70CONFIG_SYSCTL=y 70CONFIG_SYSCTL=y
71CONFIG_ANON_INODES=y 71CONFIG_ANON_INODES=y
@@ -74,6 +74,7 @@ CONFIG_UID16=y
74# CONFIG_SYSCTL_SYSCALL is not set 74# CONFIG_SYSCTL_SYSCALL is not set
75CONFIG_KALLSYMS=y 75CONFIG_KALLSYMS=y
76# CONFIG_KALLSYMS_EXTRA_PASS is not set 76# CONFIG_KALLSYMS_EXTRA_PASS is not set
77# CONFIG_STRIP_ASM_SYMS is not set
77# CONFIG_HOTPLUG is not set 78# CONFIG_HOTPLUG is not set
78CONFIG_PRINTK=y 79CONFIG_PRINTK=y
79CONFIG_BUG=y 80CONFIG_BUG=y
@@ -92,6 +93,7 @@ CONFIG_SLAB=y
92# CONFIG_SLUB is not set 93# CONFIG_SLUB is not set
93# CONFIG_SLOB is not set 94# CONFIG_SLOB is not set
94# CONFIG_PROFILING is not set 95# CONFIG_PROFILING is not set
96# CONFIG_MARKERS is not set
95CONFIG_HAVE_OPROFILE=y 97CONFIG_HAVE_OPROFILE=y
96# CONFIG_KPROBES is not set 98# CONFIG_KPROBES is not set
97CONFIG_HAVE_IOREMAP_PROT=y 99CONFIG_HAVE_IOREMAP_PROT=y
@@ -99,6 +101,8 @@ CONFIG_HAVE_KPROBES=y
99CONFIG_HAVE_KRETPROBES=y 101CONFIG_HAVE_KRETPROBES=y
100CONFIG_HAVE_ARCH_TRACEHOOK=y 102CONFIG_HAVE_ARCH_TRACEHOOK=y
101CONFIG_HAVE_CLK=y 103CONFIG_HAVE_CLK=y
104CONFIG_HAVE_DMA_API_DEBUG=y
105# CONFIG_SLOW_WORK is not set
102CONFIG_HAVE_GENERIC_DMA_COHERENT=y 106CONFIG_HAVE_GENERIC_DMA_COHERENT=y
103CONFIG_SLABINFO=y 107CONFIG_SLABINFO=y
104CONFIG_RT_MUTEXES=y 108CONFIG_RT_MUTEXES=y
@@ -110,7 +114,6 @@ CONFIG_MODULES=y
110# CONFIG_MODULE_SRCVERSION_ALL is not set 114# CONFIG_MODULE_SRCVERSION_ALL is not set
111CONFIG_BLOCK=y 115CONFIG_BLOCK=y
112# CONFIG_LBD is not set 116# CONFIG_LBD is not set
113# CONFIG_BLK_DEV_IO_TRACE is not set
114# CONFIG_BLK_DEV_BSG is not set 117# CONFIG_BLK_DEV_BSG is not set
115# CONFIG_BLK_DEV_INTEGRITY is not set 118# CONFIG_BLK_DEV_INTEGRITY is not set
116 119
@@ -156,6 +159,7 @@ CONFIG_CPU_SUBTYPE_SH7751=y
156# CONFIG_CPU_SUBTYPE_SH7760 is not set 159# CONFIG_CPU_SUBTYPE_SH7760 is not set
157# CONFIG_CPU_SUBTYPE_SH4_202 is not set 160# CONFIG_CPU_SUBTYPE_SH4_202 is not set
158# CONFIG_CPU_SUBTYPE_SH7723 is not set 161# CONFIG_CPU_SUBTYPE_SH7723 is not set
162# CONFIG_CPU_SUBTYPE_SH7724 is not set
159# CONFIG_CPU_SUBTYPE_SH7763 is not set 163# CONFIG_CPU_SUBTYPE_SH7763 is not set
160# CONFIG_CPU_SUBTYPE_SH7770 is not set 164# CONFIG_CPU_SUBTYPE_SH7770 is not set
161# CONFIG_CPU_SUBTYPE_SH7780 is not set 165# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -165,8 +169,6 @@ CONFIG_CPU_SUBTYPE_SH7751=y
165# CONFIG_CPU_SUBTYPE_SH7343 is not set 169# CONFIG_CPU_SUBTYPE_SH7343 is not set
166# CONFIG_CPU_SUBTYPE_SH7722 is not set 170# CONFIG_CPU_SUBTYPE_SH7722 is not set
167# CONFIG_CPU_SUBTYPE_SH7366 is not set 171# CONFIG_CPU_SUBTYPE_SH7366 is not set
168# CONFIG_CPU_SUBTYPE_SH5_101 is not set
169# CONFIG_CPU_SUBTYPE_SH5_103 is not set
170 172
171# 173#
172# Memory management options 174# Memory management options
@@ -742,6 +744,11 @@ CONFIG_INOTIFY_USER=y
742# CONFIG_FUSE_FS is not set 744# CONFIG_FUSE_FS is not set
743 745
744# 746#
747# Caches
748#
749# CONFIG_FSCACHE is not set
750
751#
745# CD-ROM/DVD Filesystems 752# CD-ROM/DVD Filesystems
746# 753#
747# CONFIG_ISO9660_FS is not set 754# CONFIG_ISO9660_FS is not set
@@ -796,6 +803,7 @@ CONFIG_JFFS2_RTIME=y
796# CONFIG_ROMFS_FS is not set 803# CONFIG_ROMFS_FS is not set
797# CONFIG_SYSV_FS is not set 804# CONFIG_SYSV_FS is not set
798# CONFIG_UFS_FS is not set 805# CONFIG_UFS_FS is not set
806# CONFIG_NILFS2_FS is not set
799CONFIG_NETWORK_FILESYSTEMS=y 807CONFIG_NETWORK_FILESYSTEMS=y
800# CONFIG_NFS_FS is not set 808# CONFIG_NFS_FS is not set
801# CONFIG_NFSD is not set 809# CONFIG_NFSD is not set
@@ -833,10 +841,23 @@ CONFIG_FRAME_WARN=1024
833CONFIG_HAVE_FUNCTION_TRACER=y 841CONFIG_HAVE_FUNCTION_TRACER=y
834CONFIG_HAVE_DYNAMIC_FTRACE=y 842CONFIG_HAVE_DYNAMIC_FTRACE=y
835CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 843CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
844CONFIG_TRACING_SUPPORT=y
836 845
837# 846#
838# Tracers 847# Tracers
839# 848#
849# CONFIG_FUNCTION_TRACER is not set
850# CONFIG_IRQSOFF_TRACER is not set
851# CONFIG_SCHED_TRACER is not set
852# CONFIG_CONTEXT_SWITCH_TRACER is not set
853# CONFIG_EVENT_TRACER is not set
854# CONFIG_BOOT_TRACER is not set
855# CONFIG_TRACE_BRANCH_PROFILING is not set
856# CONFIG_STACK_TRACER is not set
857# CONFIG_KMEMTRACE is not set
858# CONFIG_WORKQUEUE_TRACER is not set
859# CONFIG_BLK_DEV_IO_TRACE is not set
860# CONFIG_DMA_API_DEBUG is not set
840# CONFIG_SAMPLES is not set 861# CONFIG_SAMPLES is not set
841CONFIG_HAVE_ARCH_KGDB=y 862CONFIG_HAVE_ARCH_KGDB=y
842# CONFIG_SH_STANDARD_BIOS is not set 863# CONFIG_SH_STANDARD_BIOS is not set
@@ -936,6 +957,7 @@ CONFIG_CRYPTO=y
936# 957#
937# CONFIG_CRYPTO_ANSI_CPRNG is not set 958# CONFIG_CRYPTO_ANSI_CPRNG is not set
938CONFIG_CRYPTO_HW=y 959CONFIG_CRYPTO_HW=y
960# CONFIG_BINARY_PRINTF is not set
939 961
940# 962#
941# Library routines 963# Library routines
diff --git a/arch/sh/configs/se7780_defconfig b/arch/sh/configs/se7780_defconfig
index ebce23cc2ad8..c4f0af32efa9 100644
--- a/arch/sh/configs/se7780_defconfig
+++ b/arch/sh/configs/se7780_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 19:02:05 2009 4# Mon Apr 27 13:07:14 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -67,6 +68,7 @@ CONFIG_EMBEDDED=y
67CONFIG_UID16=y 68CONFIG_UID16=y
68CONFIG_SYSCTL_SYSCALL=y 69CONFIG_SYSCTL_SYSCALL=y
69# CONFIG_KALLSYMS is not set 70# CONFIG_KALLSYMS is not set
71# CONFIG_STRIP_ASM_SYMS is not set
70# CONFIG_HOTPLUG is not set 72# CONFIG_HOTPLUG is not set
71CONFIG_PRINTK=y 73CONFIG_PRINTK=y
72CONFIG_BUG=y 74CONFIG_BUG=y
@@ -86,12 +88,15 @@ CONFIG_SLAB=y
86# CONFIG_SLUB is not set 88# CONFIG_SLUB is not set
87# CONFIG_SLOB is not set 89# CONFIG_SLOB is not set
88# CONFIG_PROFILING is not set 90# CONFIG_PROFILING is not set
91# CONFIG_MARKERS is not set
89CONFIG_HAVE_OPROFILE=y 92CONFIG_HAVE_OPROFILE=y
90CONFIG_HAVE_IOREMAP_PROT=y 93CONFIG_HAVE_IOREMAP_PROT=y
91CONFIG_HAVE_KPROBES=y 94CONFIG_HAVE_KPROBES=y
92CONFIG_HAVE_KRETPROBES=y 95CONFIG_HAVE_KRETPROBES=y
93CONFIG_HAVE_ARCH_TRACEHOOK=y 96CONFIG_HAVE_ARCH_TRACEHOOK=y
94CONFIG_HAVE_CLK=y 97CONFIG_HAVE_CLK=y
98CONFIG_HAVE_DMA_API_DEBUG=y
99# CONFIG_SLOW_WORK is not set
95CONFIG_HAVE_GENERIC_DMA_COHERENT=y 100CONFIG_HAVE_GENERIC_DMA_COHERENT=y
96CONFIG_SLABINFO=y 101CONFIG_SLABINFO=y
97CONFIG_RT_MUTEXES=y 102CONFIG_RT_MUTEXES=y
@@ -103,7 +108,6 @@ CONFIG_MODULE_UNLOAD=y
103# CONFIG_MODULE_SRCVERSION_ALL is not set 108# CONFIG_MODULE_SRCVERSION_ALL is not set
104CONFIG_BLOCK=y 109CONFIG_BLOCK=y
105# CONFIG_LBD is not set 110# CONFIG_LBD is not set
106# CONFIG_BLK_DEV_IO_TRACE is not set
107# CONFIG_BLK_DEV_INTEGRITY is not set 111# CONFIG_BLK_DEV_INTEGRITY is not set
108 112
109# 113#
@@ -149,6 +153,7 @@ CONFIG_CPU_SH4A=y
149# CONFIG_CPU_SUBTYPE_SH7760 is not set 153# CONFIG_CPU_SUBTYPE_SH7760 is not set
150# CONFIG_CPU_SUBTYPE_SH4_202 is not set 154# CONFIG_CPU_SUBTYPE_SH4_202 is not set
151# CONFIG_CPU_SUBTYPE_SH7723 is not set 155# CONFIG_CPU_SUBTYPE_SH7723 is not set
156# CONFIG_CPU_SUBTYPE_SH7724 is not set
152# CONFIG_CPU_SUBTYPE_SH7763 is not set 157# CONFIG_CPU_SUBTYPE_SH7763 is not set
153# CONFIG_CPU_SUBTYPE_SH7770 is not set 158# CONFIG_CPU_SUBTYPE_SH7770 is not set
154CONFIG_CPU_SUBTYPE_SH7780=y 159CONFIG_CPU_SUBTYPE_SH7780=y
@@ -158,8 +163,6 @@ CONFIG_CPU_SUBTYPE_SH7780=y
158# CONFIG_CPU_SUBTYPE_SH7343 is not set 163# CONFIG_CPU_SUBTYPE_SH7343 is not set
159# CONFIG_CPU_SUBTYPE_SH7722 is not set 164# CONFIG_CPU_SUBTYPE_SH7722 is not set
160# CONFIG_CPU_SUBTYPE_SH7366 is not set 165# CONFIG_CPU_SUBTYPE_SH7366 is not set
161# CONFIG_CPU_SUBTYPE_SH5_101 is not set
162# CONFIG_CPU_SUBTYPE_SH5_103 is not set
163 166
164# 167#
165# Memory management options 168# Memory management options
@@ -285,8 +288,6 @@ CONFIG_CMDLINE="console=ttySC0.115200 root=/dev/sda1"
285# 288#
286CONFIG_PCI=y 289CONFIG_PCI=y
287CONFIG_SH_PCIDMA_NONCOHERENT=y 290CONFIG_SH_PCIDMA_NONCOHERENT=y
288CONFIG_PCI_AUTO=y
289CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
290# CONFIG_PCIEPORTBUS is not set 291# CONFIG_PCIEPORTBUS is not set
291# CONFIG_ARCH_SUPPORTS_MSI is not set 292# CONFIG_ARCH_SUPPORTS_MSI is not set
292CONFIG_PCI_LEGACY=y 293CONFIG_PCI_LEGACY=y
@@ -558,6 +559,7 @@ CONFIG_SCSI_LOWLEVEL=y
558# CONFIG_SCSI_MPT2SAS is not set 559# CONFIG_SCSI_MPT2SAS is not set
559# CONFIG_SCSI_HPTIOP is not set 560# CONFIG_SCSI_HPTIOP is not set
560# CONFIG_LIBFC is not set 561# CONFIG_LIBFC is not set
562# CONFIG_LIBFCOE is not set
561# CONFIG_FCOE is not set 563# CONFIG_FCOE is not set
562# CONFIG_SCSI_DMX3191D is not set 564# CONFIG_SCSI_DMX3191D is not set
563# CONFIG_SCSI_FUTURE_DOMAIN is not set 565# CONFIG_SCSI_FUTURE_DOMAIN is not set
@@ -957,15 +959,17 @@ CONFIG_USB_HID=y
957# 959#
958# Special HID drivers 960# Special HID drivers
959# 961#
960CONFIG_HID_COMPAT=y
961CONFIG_HID_A4TECH=y 962CONFIG_HID_A4TECH=y
962CONFIG_HID_APPLE=y 963CONFIG_HID_APPLE=y
963CONFIG_HID_BELKIN=y 964CONFIG_HID_BELKIN=y
964CONFIG_HID_CHERRY=y 965CONFIG_HID_CHERRY=y
965CONFIG_HID_CHICONY=y 966CONFIG_HID_CHICONY=y
966CONFIG_HID_CYPRESS=y 967CONFIG_HID_CYPRESS=y
968# CONFIG_DRAGONRISE_FF is not set
967CONFIG_HID_EZKEY=y 969CONFIG_HID_EZKEY=y
970# CONFIG_HID_KYE is not set
968CONFIG_HID_GYRATION=y 971CONFIG_HID_GYRATION=y
972# CONFIG_HID_KENSINGTON is not set
969CONFIG_HID_LOGITECH=y 973CONFIG_HID_LOGITECH=y
970# CONFIG_LOGITECH_FF is not set 974# CONFIG_LOGITECH_FF is not set
971# CONFIG_LOGIRUMBLEPAD2_FF is not set 975# CONFIG_LOGIRUMBLEPAD2_FF is not set
@@ -1122,6 +1126,10 @@ CONFIG_INOTIFY_USER=y
1122# CONFIG_FUSE_FS is not set 1126# CONFIG_FUSE_FS is not set
1123 1127
1124# 1128#
1129# Caches
1130#
1131
1132#
1125# CD-ROM/DVD Filesystems 1133# CD-ROM/DVD Filesystems
1126# 1134#
1127# CONFIG_ISO9660_FS is not set 1135# CONFIG_ISO9660_FS is not set
@@ -1245,11 +1253,24 @@ CONFIG_DEBUG_FS=y
1245CONFIG_HAVE_FUNCTION_TRACER=y 1253CONFIG_HAVE_FUNCTION_TRACER=y
1246CONFIG_HAVE_DYNAMIC_FTRACE=y 1254CONFIG_HAVE_DYNAMIC_FTRACE=y
1247CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1255CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1256CONFIG_TRACING_SUPPORT=y
1248 1257
1249# 1258#
1250# Tracers 1259# Tracers
1251# 1260#
1261# CONFIG_FUNCTION_TRACER is not set
1262# CONFIG_IRQSOFF_TRACER is not set
1263# CONFIG_SCHED_TRACER is not set
1264# CONFIG_CONTEXT_SWITCH_TRACER is not set
1265# CONFIG_EVENT_TRACER is not set
1266# CONFIG_BOOT_TRACER is not set
1267# CONFIG_TRACE_BRANCH_PROFILING is not set
1268# CONFIG_STACK_TRACER is not set
1269# CONFIG_KMEMTRACE is not set
1270# CONFIG_WORKQUEUE_TRACER is not set
1271# CONFIG_BLK_DEV_IO_TRACE is not set
1252# CONFIG_DYNAMIC_DEBUG is not set 1272# CONFIG_DYNAMIC_DEBUG is not set
1273# CONFIG_DMA_API_DEBUG is not set
1253# CONFIG_SAMPLES is not set 1274# CONFIG_SAMPLES is not set
1254CONFIG_HAVE_ARCH_KGDB=y 1275CONFIG_HAVE_ARCH_KGDB=y
1255# CONFIG_SH_STANDARD_BIOS is not set 1276# CONFIG_SH_STANDARD_BIOS is not set
@@ -1345,6 +1366,7 @@ CONFIG_CRYPTO=y
1345# CONFIG_CRYPTO_ANSI_CPRNG is not set 1366# CONFIG_CRYPTO_ANSI_CPRNG is not set
1346CONFIG_CRYPTO_HW=y 1367CONFIG_CRYPTO_HW=y
1347# CONFIG_CRYPTO_DEV_HIFN_795X is not set 1368# CONFIG_CRYPTO_DEV_HIFN_795X is not set
1369# CONFIG_BINARY_PRINTF is not set
1348 1370
1349# 1371#
1350# Library routines 1372# Library routines
diff --git a/arch/sh/configs/sh03_defconfig b/arch/sh/configs/sh03_defconfig
index 6fcdb090cf32..f9c6e51dc0b0 100644
--- a/arch/sh/configs/sh03_defconfig
+++ b/arch/sh/configs/sh03_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 19:04:59 2009 4# Mon Apr 27 13:07:56 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -41,6 +42,7 @@ CONFIG_SWAP=y
41CONFIG_SYSVIPC=y 42CONFIG_SYSVIPC=y
42CONFIG_SYSVIPC_SYSCTL=y 43CONFIG_SYSVIPC_SYSCTL=y
43CONFIG_POSIX_MQUEUE=y 44CONFIG_POSIX_MQUEUE=y
45CONFIG_POSIX_MQUEUE_SYSCTL=y
44CONFIG_BSD_PROCESS_ACCT=y 46CONFIG_BSD_PROCESS_ACCT=y
45# CONFIG_BSD_PROCESS_ACCT_V3 is not set 47# CONFIG_BSD_PROCESS_ACCT_V3 is not set
46# CONFIG_TASKSTATS is not set 48# CONFIG_TASKSTATS is not set
@@ -67,7 +69,6 @@ CONFIG_INITRAMFS_SOURCE=""
67CONFIG_RD_GZIP=y 69CONFIG_RD_GZIP=y
68# CONFIG_RD_BZIP2 is not set 70# CONFIG_RD_BZIP2 is not set
69# CONFIG_RD_LZMA is not set 71# CONFIG_RD_LZMA is not set
70CONFIG_INITRAMFS_COMPRESSION_NONE=y
71CONFIG_CC_OPTIMIZE_FOR_SIZE=y 72CONFIG_CC_OPTIMIZE_FOR_SIZE=y
72CONFIG_SYSCTL=y 73CONFIG_SYSCTL=y
73CONFIG_ANON_INODES=y 74CONFIG_ANON_INODES=y
@@ -76,6 +77,7 @@ CONFIG_UID16=y
76# CONFIG_SYSCTL_SYSCALL is not set 77# CONFIG_SYSCTL_SYSCALL is not set
77CONFIG_KALLSYMS=y 78CONFIG_KALLSYMS=y
78# CONFIG_KALLSYMS_EXTRA_PASS is not set 79# CONFIG_KALLSYMS_EXTRA_PASS is not set
80# CONFIG_STRIP_ASM_SYMS is not set
79CONFIG_HOTPLUG=y 81CONFIG_HOTPLUG=y
80CONFIG_PRINTK=y 82CONFIG_PRINTK=y
81CONFIG_BUG=y 83CONFIG_BUG=y
@@ -105,6 +107,8 @@ CONFIG_HAVE_KPROBES=y
105CONFIG_HAVE_KRETPROBES=y 107CONFIG_HAVE_KRETPROBES=y
106CONFIG_HAVE_ARCH_TRACEHOOK=y 108CONFIG_HAVE_ARCH_TRACEHOOK=y
107CONFIG_HAVE_CLK=y 109CONFIG_HAVE_CLK=y
110CONFIG_HAVE_DMA_API_DEBUG=y
111# CONFIG_SLOW_WORK is not set
108CONFIG_HAVE_GENERIC_DMA_COHERENT=y 112CONFIG_HAVE_GENERIC_DMA_COHERENT=y
109CONFIG_SLABINFO=y 113CONFIG_SLABINFO=y
110CONFIG_RT_MUTEXES=y 114CONFIG_RT_MUTEXES=y
@@ -117,7 +121,6 @@ CONFIG_MODVERSIONS=y
117# CONFIG_MODULE_SRCVERSION_ALL is not set 121# CONFIG_MODULE_SRCVERSION_ALL is not set
118CONFIG_BLOCK=y 122CONFIG_BLOCK=y
119# CONFIG_LBD is not set 123# CONFIG_LBD is not set
120# CONFIG_BLK_DEV_IO_TRACE is not set
121# CONFIG_BLK_DEV_BSG is not set 124# CONFIG_BLK_DEV_BSG is not set
122# CONFIG_BLK_DEV_INTEGRITY is not set 125# CONFIG_BLK_DEV_INTEGRITY is not set
123 126
@@ -163,6 +166,7 @@ CONFIG_CPU_SUBTYPE_SH7751=y
163# CONFIG_CPU_SUBTYPE_SH7760 is not set 166# CONFIG_CPU_SUBTYPE_SH7760 is not set
164# CONFIG_CPU_SUBTYPE_SH4_202 is not set 167# CONFIG_CPU_SUBTYPE_SH4_202 is not set
165# CONFIG_CPU_SUBTYPE_SH7723 is not set 168# CONFIG_CPU_SUBTYPE_SH7723 is not set
169# CONFIG_CPU_SUBTYPE_SH7724 is not set
166# CONFIG_CPU_SUBTYPE_SH7763 is not set 170# CONFIG_CPU_SUBTYPE_SH7763 is not set
167# CONFIG_CPU_SUBTYPE_SH7770 is not set 171# CONFIG_CPU_SUBTYPE_SH7770 is not set
168# CONFIG_CPU_SUBTYPE_SH7780 is not set 172# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -172,8 +176,6 @@ CONFIG_CPU_SUBTYPE_SH7751=y
172# CONFIG_CPU_SUBTYPE_SH7343 is not set 176# CONFIG_CPU_SUBTYPE_SH7343 is not set
173# CONFIG_CPU_SUBTYPE_SH7722 is not set 177# CONFIG_CPU_SUBTYPE_SH7722 is not set
174# CONFIG_CPU_SUBTYPE_SH7366 is not set 178# CONFIG_CPU_SUBTYPE_SH7366 is not set
175# CONFIG_CPU_SUBTYPE_SH5_101 is not set
176# CONFIG_CPU_SUBTYPE_SH5_103 is not set
177 179
178# 180#
179# Memory management options 181# Memory management options
@@ -300,8 +302,6 @@ CONFIG_CMDLINE="console=ttySC1,115200 mem=64M root=/dev/nfs"
300# 302#
301CONFIG_PCI=y 303CONFIG_PCI=y
302CONFIG_SH_PCIDMA_NONCOHERENT=y 304CONFIG_SH_PCIDMA_NONCOHERENT=y
303CONFIG_PCI_AUTO=y
304CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
305# CONFIG_PCIEPORTBUS is not set 305# CONFIG_PCIEPORTBUS is not set
306# CONFIG_ARCH_SUPPORTS_MSI is not set 306# CONFIG_ARCH_SUPPORTS_MSI is not set
307CONFIG_PCI_LEGACY=y 307CONFIG_PCI_LEGACY=y
@@ -562,6 +562,7 @@ CONFIG_SCSI_LOWLEVEL=y
562# CONFIG_SCSI_MPT2SAS is not set 562# CONFIG_SCSI_MPT2SAS is not set
563# CONFIG_SCSI_HPTIOP is not set 563# CONFIG_SCSI_HPTIOP is not set
564# CONFIG_LIBFC is not set 564# CONFIG_LIBFC is not set
565# CONFIG_LIBFCOE is not set
565# CONFIG_FCOE is not set 566# CONFIG_FCOE is not set
566# CONFIG_SCSI_DMX3191D is not set 567# CONFIG_SCSI_DMX3191D is not set
567# CONFIG_SCSI_FUTURE_DOMAIN is not set 568# CONFIG_SCSI_FUTURE_DOMAIN is not set
@@ -656,6 +657,7 @@ CONFIG_NETDEV_1000=y
656# CONFIG_E1000E is not set 657# CONFIG_E1000E is not set
657# CONFIG_IP1000 is not set 658# CONFIG_IP1000 is not set
658# CONFIG_IGB is not set 659# CONFIG_IGB is not set
660# CONFIG_IGBVF is not set
659# CONFIG_NS83820 is not set 661# CONFIG_NS83820 is not set
660# CONFIG_HAMACHI is not set 662# CONFIG_HAMACHI is not set
661# CONFIG_YELLOWFIN is not set 663# CONFIG_YELLOWFIN is not set
@@ -679,6 +681,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
679# CONFIG_IXGBE is not set 681# CONFIG_IXGBE is not set
680# CONFIG_IXGB is not set 682# CONFIG_IXGB is not set
681# CONFIG_S2IO is not set 683# CONFIG_S2IO is not set
684# CONFIG_VXGE is not set
682# CONFIG_MYRI10GE is not set 685# CONFIG_MYRI10GE is not set
683# CONFIG_NETXEN_NIC is not set 686# CONFIG_NETXEN_NIC is not set
684# CONFIG_NIU is not set 687# CONFIG_NIU is not set
@@ -887,7 +890,6 @@ CONFIG_HID=y
887# 890#
888# Special HID drivers 891# Special HID drivers
889# 892#
890CONFIG_HID_COMPAT=y
891CONFIG_USB_SUPPORT=y 893CONFIG_USB_SUPPORT=y
892CONFIG_USB_ARCH_HAS_HCD=y 894CONFIG_USB_ARCH_HAS_HCD=y
893CONFIG_USB_ARCH_HAS_OHCI=y 895CONFIG_USB_ARCH_HAS_OHCI=y
@@ -929,6 +931,7 @@ CONFIG_EXT2_FS_XATTR=y
929# CONFIG_EXT2_FS_SECURITY is not set 931# CONFIG_EXT2_FS_SECURITY is not set
930# CONFIG_EXT2_FS_XIP is not set 932# CONFIG_EXT2_FS_XIP is not set
931CONFIG_EXT3_FS=y 933CONFIG_EXT3_FS=y
934# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
932CONFIG_EXT3_FS_XATTR=y 935CONFIG_EXT3_FS_XATTR=y
933CONFIG_EXT3_FS_POSIX_ACL=y 936CONFIG_EXT3_FS_POSIX_ACL=y
934# CONFIG_EXT3_FS_SECURITY is not set 937# CONFIG_EXT3_FS_SECURITY is not set
@@ -952,6 +955,11 @@ CONFIG_AUTOFS4_FS=y
952# CONFIG_FUSE_FS is not set 955# CONFIG_FUSE_FS is not set
953 956
954# 957#
958# Caches
959#
960# CONFIG_FSCACHE is not set
961
962#
955# CD-ROM/DVD Filesystems 963# CD-ROM/DVD Filesystems
956# 964#
957CONFIG_ISO9660_FS=m 965CONFIG_ISO9660_FS=m
@@ -1001,6 +1009,7 @@ CONFIG_MISC_FILESYSTEMS=y
1001# CONFIG_ROMFS_FS is not set 1009# CONFIG_ROMFS_FS is not set
1002# CONFIG_SYSV_FS is not set 1010# CONFIG_SYSV_FS is not set
1003# CONFIG_UFS_FS is not set 1011# CONFIG_UFS_FS is not set
1012# CONFIG_NILFS2_FS is not set
1004CONFIG_NETWORK_FILESYSTEMS=y 1013CONFIG_NETWORK_FILESYSTEMS=y
1005CONFIG_NFS_FS=y 1014CONFIG_NFS_FS=y
1006CONFIG_NFS_V3=y 1015CONFIG_NFS_V3=y
@@ -1112,11 +1121,26 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
1112CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1121CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1113CONFIG_RING_BUFFER=y 1122CONFIG_RING_BUFFER=y
1114CONFIG_TRACING=y 1123CONFIG_TRACING=y
1124CONFIG_TRACING_SUPPORT=y
1115 1125
1116# 1126#
1117# Tracers 1127# Tracers
1118# 1128#
1129# CONFIG_FUNCTION_TRACER is not set
1130# CONFIG_IRQSOFF_TRACER is not set
1131# CONFIG_PREEMPT_TRACER is not set
1132# CONFIG_SCHED_TRACER is not set
1133# CONFIG_CONTEXT_SWITCH_TRACER is not set
1134# CONFIG_EVENT_TRACER is not set
1135# CONFIG_BOOT_TRACER is not set
1136# CONFIG_TRACE_BRANCH_PROFILING is not set
1137# CONFIG_STACK_TRACER is not set
1138# CONFIG_KMEMTRACE is not set
1139# CONFIG_WORKQUEUE_TRACER is not set
1140# CONFIG_BLK_DEV_IO_TRACE is not set
1141# CONFIG_FTRACE_STARTUP_TEST is not set
1119# CONFIG_DYNAMIC_DEBUG is not set 1142# CONFIG_DYNAMIC_DEBUG is not set
1143# CONFIG_DMA_API_DEBUG is not set
1120# CONFIG_SAMPLES is not set 1144# CONFIG_SAMPLES is not set
1121CONFIG_HAVE_ARCH_KGDB=y 1145CONFIG_HAVE_ARCH_KGDB=y
1122CONFIG_SH_STANDARD_BIOS=y 1146CONFIG_SH_STANDARD_BIOS=y
@@ -1228,6 +1252,7 @@ CONFIG_CRYPTO_DEFLATE=y
1228# CONFIG_CRYPTO_ANSI_CPRNG is not set 1252# CONFIG_CRYPTO_ANSI_CPRNG is not set
1229CONFIG_CRYPTO_HW=y 1253CONFIG_CRYPTO_HW=y
1230# CONFIG_CRYPTO_DEV_HIFN_795X is not set 1254# CONFIG_CRYPTO_DEV_HIFN_795X is not set
1255CONFIG_BINARY_PRINTF=y
1231 1256
1232# 1257#
1233# Library routines 1258# Library routines
diff --git a/arch/sh/configs/sh7710voipgw_defconfig b/arch/sh/configs/sh7710voipgw_defconfig
index 1ab37c01da6e..48b58098cf84 100644
--- a/arch/sh/configs/sh7710voipgw_defconfig
+++ b/arch/sh/configs/sh7710voipgw_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 19:09:01 2009 4# Mon Apr 27 13:09:16 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -39,6 +40,7 @@ CONFIG_LOCALVERSION_AUTO=y
39CONFIG_SYSVIPC=y 40CONFIG_SYSVIPC=y
40CONFIG_SYSVIPC_SYSCTL=y 41CONFIG_SYSVIPC_SYSCTL=y
41CONFIG_POSIX_MQUEUE=y 42CONFIG_POSIX_MQUEUE=y
43CONFIG_POSIX_MQUEUE_SYSCTL=y
42# CONFIG_BSD_PROCESS_ACCT is not set 44# CONFIG_BSD_PROCESS_ACCT is not set
43# CONFIG_TASKSTATS is not set 45# CONFIG_TASKSTATS is not set
44# CONFIG_AUDIT is not set 46# CONFIG_AUDIT is not set
@@ -72,6 +74,7 @@ CONFIG_UID16=y
72# CONFIG_SYSCTL_SYSCALL is not set 74# CONFIG_SYSCTL_SYSCALL is not set
73CONFIG_KALLSYMS=y 75CONFIG_KALLSYMS=y
74# CONFIG_KALLSYMS_EXTRA_PASS is not set 76# CONFIG_KALLSYMS_EXTRA_PASS is not set
77# CONFIG_STRIP_ASM_SYMS is not set
75CONFIG_HOTPLUG=y 78CONFIG_HOTPLUG=y
76CONFIG_PRINTK=y 79CONFIG_PRINTK=y
77CONFIG_BUG=y 80CONFIG_BUG=y
@@ -90,6 +93,7 @@ CONFIG_SLAB=y
90# CONFIG_SLUB is not set 93# CONFIG_SLUB is not set
91# CONFIG_SLOB is not set 94# CONFIG_SLOB is not set
92# CONFIG_PROFILING is not set 95# CONFIG_PROFILING is not set
96# CONFIG_MARKERS is not set
93CONFIG_HAVE_OPROFILE=y 97CONFIG_HAVE_OPROFILE=y
94# CONFIG_KPROBES is not set 98# CONFIG_KPROBES is not set
95CONFIG_HAVE_IOREMAP_PROT=y 99CONFIG_HAVE_IOREMAP_PROT=y
@@ -97,6 +101,8 @@ CONFIG_HAVE_KPROBES=y
97CONFIG_HAVE_KRETPROBES=y 101CONFIG_HAVE_KRETPROBES=y
98CONFIG_HAVE_ARCH_TRACEHOOK=y 102CONFIG_HAVE_ARCH_TRACEHOOK=y
99CONFIG_HAVE_CLK=y 103CONFIG_HAVE_CLK=y
104CONFIG_HAVE_DMA_API_DEBUG=y
105# CONFIG_SLOW_WORK is not set
100CONFIG_HAVE_GENERIC_DMA_COHERENT=y 106CONFIG_HAVE_GENERIC_DMA_COHERENT=y
101CONFIG_SLABINFO=y 107CONFIG_SLABINFO=y
102CONFIG_BASE_SMALL=0 108CONFIG_BASE_SMALL=0
@@ -108,7 +114,6 @@ CONFIG_MODULE_FORCE_UNLOAD=y
108# CONFIG_MODULE_SRCVERSION_ALL is not set 114# CONFIG_MODULE_SRCVERSION_ALL is not set
109CONFIG_BLOCK=y 115CONFIG_BLOCK=y
110# CONFIG_LBD is not set 116# CONFIG_LBD is not set
111# CONFIG_BLK_DEV_IO_TRACE is not set
112# CONFIG_BLK_DEV_BSG is not set 117# CONFIG_BLK_DEV_BSG is not set
113# CONFIG_BLK_DEV_INTEGRITY is not set 118# CONFIG_BLK_DEV_INTEGRITY is not set
114 119
@@ -154,6 +159,7 @@ CONFIG_CPU_SUBTYPE_SH7710=y
154# CONFIG_CPU_SUBTYPE_SH7760 is not set 159# CONFIG_CPU_SUBTYPE_SH7760 is not set
155# CONFIG_CPU_SUBTYPE_SH4_202 is not set 160# CONFIG_CPU_SUBTYPE_SH4_202 is not set
156# CONFIG_CPU_SUBTYPE_SH7723 is not set 161# CONFIG_CPU_SUBTYPE_SH7723 is not set
162# CONFIG_CPU_SUBTYPE_SH7724 is not set
157# CONFIG_CPU_SUBTYPE_SH7763 is not set 163# CONFIG_CPU_SUBTYPE_SH7763 is not set
158# CONFIG_CPU_SUBTYPE_SH7770 is not set 164# CONFIG_CPU_SUBTYPE_SH7770 is not set
159# CONFIG_CPU_SUBTYPE_SH7780 is not set 165# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -163,8 +169,6 @@ CONFIG_CPU_SUBTYPE_SH7710=y
163# CONFIG_CPU_SUBTYPE_SH7343 is not set 169# CONFIG_CPU_SUBTYPE_SH7343 is not set
164# CONFIG_CPU_SUBTYPE_SH7722 is not set 170# CONFIG_CPU_SUBTYPE_SH7722 is not set
165# CONFIG_CPU_SUBTYPE_SH7366 is not set 171# CONFIG_CPU_SUBTYPE_SH7366 is not set
166# CONFIG_CPU_SUBTYPE_SH5_101 is not set
167# CONFIG_CPU_SUBTYPE_SH5_103 is not set
168 172
169# 173#
170# Memory management options 174# Memory management options
@@ -728,7 +732,6 @@ CONFIG_HID=y
728# 732#
729# Special HID drivers 733# Special HID drivers
730# 734#
731CONFIG_HID_COMPAT=y
732CONFIG_USB_SUPPORT=y 735CONFIG_USB_SUPPORT=y
733CONFIG_USB_ARCH_HAS_HCD=y 736CONFIG_USB_ARCH_HAS_HCD=y
734# CONFIG_USB_ARCH_HAS_OHCI is not set 737# CONFIG_USB_ARCH_HAS_OHCI is not set
@@ -780,6 +783,11 @@ CONFIG_FILE_LOCKING=y
780# CONFIG_FUSE_FS is not set 783# CONFIG_FUSE_FS is not set
781 784
782# 785#
786# Caches
787#
788# CONFIG_FSCACHE is not set
789
790#
783# CD-ROM/DVD Filesystems 791# CD-ROM/DVD Filesystems
784# 792#
785# CONFIG_ISO9660_FS is not set 793# CONFIG_ISO9660_FS is not set
@@ -834,6 +842,7 @@ CONFIG_JFFS2_RTIME=y
834# CONFIG_ROMFS_FS is not set 842# CONFIG_ROMFS_FS is not set
835# CONFIG_SYSV_FS is not set 843# CONFIG_SYSV_FS is not set
836# CONFIG_UFS_FS is not set 844# CONFIG_UFS_FS is not set
845# CONFIG_NILFS2_FS is not set
837CONFIG_NETWORK_FILESYSTEMS=y 846CONFIG_NETWORK_FILESYSTEMS=y
838# CONFIG_NFS_FS is not set 847# CONFIG_NFS_FS is not set
839# CONFIG_NFSD is not set 848# CONFIG_NFSD is not set
@@ -871,11 +880,24 @@ CONFIG_DEBUG_FS=y
871CONFIG_HAVE_FUNCTION_TRACER=y 880CONFIG_HAVE_FUNCTION_TRACER=y
872CONFIG_HAVE_DYNAMIC_FTRACE=y 881CONFIG_HAVE_DYNAMIC_FTRACE=y
873CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 882CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
883CONFIG_TRACING_SUPPORT=y
874 884
875# 885#
876# Tracers 886# Tracers
877# 887#
888# CONFIG_FUNCTION_TRACER is not set
889# CONFIG_IRQSOFF_TRACER is not set
890# CONFIG_SCHED_TRACER is not set
891# CONFIG_CONTEXT_SWITCH_TRACER is not set
892# CONFIG_EVENT_TRACER is not set
893# CONFIG_BOOT_TRACER is not set
894# CONFIG_TRACE_BRANCH_PROFILING is not set
895# CONFIG_STACK_TRACER is not set
896# CONFIG_KMEMTRACE is not set
897# CONFIG_WORKQUEUE_TRACER is not set
898# CONFIG_BLK_DEV_IO_TRACE is not set
878# CONFIG_DYNAMIC_DEBUG is not set 899# CONFIG_DYNAMIC_DEBUG is not set
900# CONFIG_DMA_API_DEBUG is not set
879# CONFIG_SAMPLES is not set 901# CONFIG_SAMPLES is not set
880CONFIG_HAVE_ARCH_KGDB=y 902CONFIG_HAVE_ARCH_KGDB=y
881# CONFIG_SH_STANDARD_BIOS is not set 903# CONFIG_SH_STANDARD_BIOS is not set
@@ -975,6 +997,7 @@ CONFIG_CRYPTO=y
975# 997#
976# CONFIG_CRYPTO_ANSI_CPRNG is not set 998# CONFIG_CRYPTO_ANSI_CPRNG is not set
977CONFIG_CRYPTO_HW=y 999CONFIG_CRYPTO_HW=y
1000# CONFIG_BINARY_PRINTF is not set
978 1001
979# 1002#
980# Library routines 1003# Library routines
diff --git a/arch/sh/configs/sh7724_generic_defconfig b/arch/sh/configs/sh7724_generic_defconfig
new file mode 100644
index 000000000000..ec8f18c7684c
--- /dev/null
+++ b/arch/sh/configs/sh7724_generic_defconfig
@@ -0,0 +1,707 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.30-rc3
4# Mon Apr 27 13:09:47 2009
5#
6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
10CONFIG_RWSEM_GENERIC_SPINLOCK=y
11CONFIG_GENERIC_BUG=y
12CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
16CONFIG_GENERIC_IRQ_PROBE=y
17# CONFIG_GENERIC_GPIO is not set
18CONFIG_GENERIC_TIME=y
19CONFIG_GENERIC_CLOCKEVENTS=y
20CONFIG_ARCH_SUSPEND_POSSIBLE=y
21CONFIG_ARCH_HIBERNATION_POSSIBLE=y
22CONFIG_SYS_SUPPORTS_CMT=y
23CONFIG_STACKTRACE_SUPPORT=y
24CONFIG_LOCKDEP_SUPPORT=y
25CONFIG_HAVE_LATENCYTOP_SUPPORT=y
26# CONFIG_ARCH_HAS_ILOG2_U32 is not set
27# CONFIG_ARCH_HAS_ILOG2_U64 is not set
28CONFIG_ARCH_NO_VIRT_TO_BUS=y
29CONFIG_ARCH_HAS_DEFAULT_IDLE=y
30CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
31
32#
33# General setup
34#
35CONFIG_EXPERIMENTAL=y
36CONFIG_BROKEN_ON_SMP=y
37CONFIG_INIT_ENV_ARG_LIMIT=32
38CONFIG_LOCALVERSION=""
39# CONFIG_LOCALVERSION_AUTO is not set
40CONFIG_SWAP=y
41CONFIG_SYSVIPC=y
42CONFIG_SYSVIPC_SYSCTL=y
43# CONFIG_BSD_PROCESS_ACCT is not set
44
45#
46# RCU Subsystem
47#
48# CONFIG_CLASSIC_RCU is not set
49CONFIG_TREE_RCU=y
50# CONFIG_PREEMPT_RCU is not set
51# CONFIG_RCU_TRACE is not set
52CONFIG_RCU_FANOUT=32
53# CONFIG_RCU_FANOUT_EXACT is not set
54# CONFIG_TREE_RCU_TRACE is not set
55# CONFIG_PREEMPT_RCU_TRACE is not set
56# CONFIG_IKCONFIG is not set
57CONFIG_LOG_BUF_SHIFT=17
58CONFIG_GROUP_SCHED=y
59CONFIG_FAIR_GROUP_SCHED=y
60CONFIG_RT_GROUP_SCHED=y
61CONFIG_USER_SCHED=y
62# CONFIG_CGROUP_SCHED is not set
63CONFIG_CGROUPS=y
64# CONFIG_CGROUP_DEBUG is not set
65# CONFIG_CGROUP_NS is not set
66# CONFIG_CGROUP_FREEZER is not set
67# CONFIG_CGROUP_DEVICE is not set
68# CONFIG_CPUSETS is not set
69# CONFIG_CGROUP_CPUACCT is not set
70# CONFIG_RESOURCE_COUNTERS is not set
71# CONFIG_RELAY is not set
72# CONFIG_NAMESPACES is not set
73# CONFIG_BLK_DEV_INITRD is not set
74CONFIG_CC_OPTIMIZE_FOR_SIZE=y
75CONFIG_SYSCTL=y
76CONFIG_ANON_INODES=y
77CONFIG_EMBEDDED=y
78# CONFIG_UID16 is not set
79CONFIG_SYSCTL_SYSCALL=y
80CONFIG_KALLSYMS=y
81# CONFIG_KALLSYMS_EXTRA_PASS is not set
82# CONFIG_STRIP_ASM_SYMS is not set
83CONFIG_HOTPLUG=y
84CONFIG_PRINTK=y
85CONFIG_BUG=y
86CONFIG_ELF_CORE=y
87CONFIG_BASE_FULL=y
88CONFIG_FUTEX=y
89CONFIG_EPOLL=y
90CONFIG_SIGNALFD=y
91CONFIG_TIMERFD=y
92CONFIG_EVENTFD=y
93CONFIG_SHMEM=y
94CONFIG_AIO=y
95CONFIG_VM_EVENT_COUNTERS=y
96# CONFIG_COMPAT_BRK is not set
97# CONFIG_SLAB is not set
98CONFIG_SLUB=y
99# CONFIG_SLOB is not set
100CONFIG_PROFILING=y
101CONFIG_TRACEPOINTS=y
102# CONFIG_MARKERS is not set
103CONFIG_OPROFILE=y
104CONFIG_HAVE_OPROFILE=y
105CONFIG_HAVE_IOREMAP_PROT=y
106CONFIG_HAVE_KPROBES=y
107CONFIG_HAVE_KRETPROBES=y
108CONFIG_HAVE_ARCH_TRACEHOOK=y
109CONFIG_HAVE_CLK=y
110CONFIG_HAVE_DMA_API_DEBUG=y
111# CONFIG_SLOW_WORK is not set
112CONFIG_HAVE_GENERIC_DMA_COHERENT=y
113CONFIG_RT_MUTEXES=y
114CONFIG_BASE_SMALL=0
115# CONFIG_MODULES is not set
116CONFIG_BLOCK=y
117# CONFIG_LBD is not set
118# CONFIG_BLK_DEV_BSG is not set
119# CONFIG_BLK_DEV_INTEGRITY is not set
120
121#
122# IO Schedulers
123#
124CONFIG_IOSCHED_NOOP=y
125CONFIG_IOSCHED_AS=y
126CONFIG_IOSCHED_DEADLINE=y
127CONFIG_IOSCHED_CFQ=y
128CONFIG_DEFAULT_AS=y
129# CONFIG_DEFAULT_DEADLINE is not set
130# CONFIG_DEFAULT_CFQ is not set
131# CONFIG_DEFAULT_NOOP is not set
132CONFIG_DEFAULT_IOSCHED="anticipatory"
133CONFIG_FREEZER=y
134
135#
136# System type
137#
138CONFIG_CPU_SH4=y
139CONFIG_CPU_SH4A=y
140CONFIG_CPU_SHX2=y
141CONFIG_ARCH_SHMOBILE=y
142# CONFIG_CPU_SUBTYPE_SH7619 is not set
143# CONFIG_CPU_SUBTYPE_SH7201 is not set
144# CONFIG_CPU_SUBTYPE_SH7203 is not set
145# CONFIG_CPU_SUBTYPE_SH7206 is not set
146# CONFIG_CPU_SUBTYPE_SH7263 is not set
147# CONFIG_CPU_SUBTYPE_MXG is not set
148# CONFIG_CPU_SUBTYPE_SH7705 is not set
149# CONFIG_CPU_SUBTYPE_SH7706 is not set
150# CONFIG_CPU_SUBTYPE_SH7707 is not set
151# CONFIG_CPU_SUBTYPE_SH7708 is not set
152# CONFIG_CPU_SUBTYPE_SH7709 is not set
153# CONFIG_CPU_SUBTYPE_SH7710 is not set
154# CONFIG_CPU_SUBTYPE_SH7712 is not set
155# CONFIG_CPU_SUBTYPE_SH7720 is not set
156# CONFIG_CPU_SUBTYPE_SH7721 is not set
157# CONFIG_CPU_SUBTYPE_SH7750 is not set
158# CONFIG_CPU_SUBTYPE_SH7091 is not set
159# CONFIG_CPU_SUBTYPE_SH7750R is not set
160# CONFIG_CPU_SUBTYPE_SH7750S is not set
161# CONFIG_CPU_SUBTYPE_SH7751 is not set
162# CONFIG_CPU_SUBTYPE_SH7751R is not set
163# CONFIG_CPU_SUBTYPE_SH7760 is not set
164# CONFIG_CPU_SUBTYPE_SH4_202 is not set
165# CONFIG_CPU_SUBTYPE_SH7723 is not set
166CONFIG_CPU_SUBTYPE_SH7724=y
167# CONFIG_CPU_SUBTYPE_SH7763 is not set
168# CONFIG_CPU_SUBTYPE_SH7770 is not set
169# CONFIG_CPU_SUBTYPE_SH7780 is not set
170# CONFIG_CPU_SUBTYPE_SH7785 is not set
171# CONFIG_CPU_SUBTYPE_SH7786 is not set
172# CONFIG_CPU_SUBTYPE_SHX3 is not set
173# CONFIG_CPU_SUBTYPE_SH7343 is not set
174# CONFIG_CPU_SUBTYPE_SH7722 is not set
175# CONFIG_CPU_SUBTYPE_SH7366 is not set
176
177#
178# Memory management options
179#
180CONFIG_QUICKLIST=y
181CONFIG_MMU=y
182CONFIG_PAGE_OFFSET=0x80000000
183CONFIG_MEMORY_START=0x08000000
184CONFIG_MEMORY_SIZE=0x04000000
185CONFIG_29BIT=y
186# CONFIG_X2TLB is not set
187CONFIG_VSYSCALL=y
188CONFIG_ARCH_FLATMEM_ENABLE=y
189CONFIG_ARCH_SPARSEMEM_ENABLE=y
190CONFIG_ARCH_SPARSEMEM_DEFAULT=y
191CONFIG_MAX_ACTIVE_REGIONS=1
192CONFIG_ARCH_POPULATES_NODE_MAP=y
193CONFIG_ARCH_SELECT_MEMORY_MODEL=y
194CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
195CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
196CONFIG_PAGE_SIZE_4KB=y
197# CONFIG_PAGE_SIZE_8KB is not set
198# CONFIG_PAGE_SIZE_16KB is not set
199# CONFIG_PAGE_SIZE_64KB is not set
200CONFIG_ENTRY_OFFSET=0x00001000
201CONFIG_SELECT_MEMORY_MODEL=y
202# CONFIG_FLATMEM_MANUAL is not set
203# CONFIG_DISCONTIGMEM_MANUAL is not set
204CONFIG_SPARSEMEM_MANUAL=y
205CONFIG_SPARSEMEM=y
206CONFIG_HAVE_MEMORY_PRESENT=y
207CONFIG_SPARSEMEM_STATIC=y
208
209#
210# Memory hotplug is currently incompatible with Software Suspend
211#
212CONFIG_PAGEFLAGS_EXTENDED=y
213CONFIG_SPLIT_PTLOCK_CPUS=4
214CONFIG_MIGRATION=y
215# CONFIG_PHYS_ADDR_T_64BIT is not set
216CONFIG_ZONE_DMA_FLAG=0
217CONFIG_NR_QUICK=2
218CONFIG_UNEVICTABLE_LRU=y
219CONFIG_HAVE_MLOCK=y
220CONFIG_HAVE_MLOCKED_PAGE_BIT=y
221
222#
223# Cache configuration
224#
225CONFIG_CACHE_WRITEBACK=y
226# CONFIG_CACHE_WRITETHROUGH is not set
227# CONFIG_CACHE_OFF is not set
228
229#
230# Processor features
231#
232CONFIG_CPU_LITTLE_ENDIAN=y
233# CONFIG_CPU_BIG_ENDIAN is not set
234CONFIG_SH_FPU=y
235# CONFIG_SH_STORE_QUEUES is not set
236CONFIG_CPU_HAS_INTEVT=y
237CONFIG_CPU_HAS_SR_RB=y
238CONFIG_CPU_HAS_PTEA=y
239CONFIG_CPU_HAS_FPU=y
240
241#
242# Board support
243#
244
245#
246# Timer and clock configuration
247#
248CONFIG_SH_TMU=y
249CONFIG_SH_TIMER_CMT=y
250CONFIG_SH_TIMER_IRQ=16
251CONFIG_SH_PCLK_FREQ=41666666
252CONFIG_TICK_ONESHOT=y
253CONFIG_NO_HZ=y
254CONFIG_HIGH_RES_TIMERS=y
255CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
256
257#
258# CPU Frequency scaling
259#
260CONFIG_CPU_FREQ=y
261CONFIG_CPU_FREQ_TABLE=y
262# CONFIG_CPU_FREQ_DEBUG is not set
263CONFIG_CPU_FREQ_STAT=y
264# CONFIG_CPU_FREQ_STAT_DETAILS is not set
265CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y
266# CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE is not set
267# CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set
268# CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set
269# CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE is not set
270CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
271# CONFIG_CPU_FREQ_GOV_POWERSAVE is not set
272# CONFIG_CPU_FREQ_GOV_USERSPACE is not set
273# CONFIG_CPU_FREQ_GOV_ONDEMAND is not set
274# CONFIG_CPU_FREQ_GOV_CONSERVATIVE is not set
275CONFIG_SH_CPU_FREQ=y
276
277#
278# DMA support
279#
280# CONFIG_SH_DMA is not set
281
282#
283# Companion Chips
284#
285
286#
287# Additional SuperH Device Drivers
288#
289# CONFIG_HEARTBEAT is not set
290# CONFIG_PUSH_SWITCH is not set
291
292#
293# Kernel features
294#
295# CONFIG_HZ_100 is not set
296CONFIG_HZ_250=y
297# CONFIG_HZ_300 is not set
298# CONFIG_HZ_1000 is not set
299CONFIG_HZ=250
300CONFIG_SCHED_HRTICK=y
301CONFIG_KEXEC=y
302# CONFIG_CRASH_DUMP is not set
303CONFIG_KEXEC_JUMP=y
304CONFIG_PREEMPT_NONE=y
305# CONFIG_PREEMPT_VOLUNTARY is not set
306# CONFIG_PREEMPT is not set
307CONFIG_GUSA=y
308
309#
310# Boot options
311#
312CONFIG_ZERO_PAGE_OFFSET=0x00001000
313CONFIG_BOOT_LINK_OFFSET=0x00800000
314# CONFIG_CMDLINE_BOOL is not set
315
316#
317# Bus options
318#
319# CONFIG_ARCH_SUPPORTS_MSI is not set
320# CONFIG_PCCARD is not set
321
322#
323# Executable file formats
324#
325CONFIG_BINFMT_ELF=y
326# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
327# CONFIG_HAVE_AOUT is not set
328# CONFIG_BINFMT_MISC is not set
329
330#
331# Power management options (EXPERIMENTAL)
332#
333CONFIG_PM=y
334# CONFIG_PM_DEBUG is not set
335CONFIG_PM_SLEEP=y
336CONFIG_SUSPEND=y
337CONFIG_SUSPEND_FREEZER=y
338CONFIG_HIBERNATION=y
339CONFIG_PM_STD_PARTITION=""
340CONFIG_CPU_IDLE=y
341CONFIG_CPU_IDLE_GOV_LADDER=y
342CONFIG_CPU_IDLE_GOV_MENU=y
343# CONFIG_NET is not set
344
345#
346# Device Drivers
347#
348
349#
350# Generic Driver Options
351#
352CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
353CONFIG_STANDALONE=y
354# CONFIG_PREVENT_FIRMWARE_BUILD is not set
355CONFIG_FW_LOADER=y
356CONFIG_FIRMWARE_IN_KERNEL=y
357CONFIG_EXTRA_FIRMWARE=""
358# CONFIG_SYS_HYPERVISOR is not set
359# CONFIG_MTD is not set
360# CONFIG_PARPORT is not set
361CONFIG_BLK_DEV=y
362# CONFIG_BLK_DEV_COW_COMMON is not set
363# CONFIG_BLK_DEV_LOOP is not set
364# CONFIG_BLK_DEV_RAM is not set
365# CONFIG_CDROM_PKTCDVD is not set
366# CONFIG_BLK_DEV_HD is not set
367# CONFIG_MISC_DEVICES is not set
368CONFIG_HAVE_IDE=y
369# CONFIG_IDE is not set
370
371#
372# SCSI device support
373#
374# CONFIG_RAID_ATTRS is not set
375# CONFIG_SCSI is not set
376# CONFIG_SCSI_DMA is not set
377# CONFIG_SCSI_NETLINK is not set
378# CONFIG_ATA is not set
379# CONFIG_MD is not set
380# CONFIG_PHONE is not set
381
382#
383# Input device support
384#
385# CONFIG_INPUT is not set
386
387#
388# Hardware I/O ports
389#
390# CONFIG_SERIO is not set
391# CONFIG_GAMEPORT is not set
392
393#
394# Character devices
395#
396# CONFIG_VT is not set
397# CONFIG_DEVKMEM is not set
398# CONFIG_SERIAL_NONSTANDARD is not set
399
400#
401# Serial drivers
402#
403# CONFIG_SERIAL_8250 is not set
404
405#
406# Non-8250 serial port support
407#
408CONFIG_SERIAL_SH_SCI=y
409CONFIG_SERIAL_SH_SCI_NR_UARTS=6
410CONFIG_SERIAL_SH_SCI_CONSOLE=y
411CONFIG_SERIAL_CORE=y
412CONFIG_SERIAL_CORE_CONSOLE=y
413# CONFIG_UNIX98_PTYS is not set
414# CONFIG_LEGACY_PTYS is not set
415# CONFIG_IPMI_HANDLER is not set
416# CONFIG_HW_RANDOM is not set
417# CONFIG_R3964 is not set
418# CONFIG_RAW_DRIVER is not set
419# CONFIG_TCG_TPM is not set
420CONFIG_I2C=y
421CONFIG_I2C_BOARDINFO=y
422CONFIG_I2C_CHARDEV=y
423CONFIG_I2C_HELPER_AUTO=y
424
425#
426# I2C Hardware Bus support
427#
428
429#
430# I2C system bus drivers (mostly embedded / system-on-chip)
431#
432# CONFIG_I2C_OCORES is not set
433CONFIG_I2C_SH_MOBILE=y
434# CONFIG_I2C_SIMTEC is not set
435
436#
437# External I2C/SMBus adapter drivers
438#
439# CONFIG_I2C_PARPORT_LIGHT is not set
440# CONFIG_I2C_TAOS_EVM is not set
441
442#
443# Other I2C/SMBus bus drivers
444#
445# CONFIG_I2C_PCA_PLATFORM is not set
446
447#
448# Miscellaneous I2C Chip support
449#
450# CONFIG_DS1682 is not set
451# CONFIG_SENSORS_PCF8574 is not set
452# CONFIG_PCF8575 is not set
453# CONFIG_SENSORS_PCA9539 is not set
454# CONFIG_SENSORS_MAX6875 is not set
455# CONFIG_SENSORS_TSL2550 is not set
456# CONFIG_I2C_DEBUG_CORE is not set
457# CONFIG_I2C_DEBUG_ALGO is not set
458# CONFIG_I2C_DEBUG_BUS is not set
459# CONFIG_I2C_DEBUG_CHIP is not set
460# CONFIG_SPI is not set
461# CONFIG_W1 is not set
462# CONFIG_POWER_SUPPLY is not set
463# CONFIG_HWMON is not set
464# CONFIG_THERMAL is not set
465# CONFIG_THERMAL_HWMON is not set
466# CONFIG_WATCHDOG is not set
467CONFIG_SSB_POSSIBLE=y
468
469#
470# Sonics Silicon Backplane
471#
472# CONFIG_SSB is not set
473
474#
475# Multifunction device drivers
476#
477# CONFIG_MFD_CORE is not set
478# CONFIG_MFD_SM501 is not set
479# CONFIG_HTC_PASIC3 is not set
480# CONFIG_TWL4030_CORE is not set
481# CONFIG_MFD_TMIO is not set
482# CONFIG_PMIC_DA903X is not set
483# CONFIG_MFD_WM8400 is not set
484# CONFIG_MFD_WM8350_I2C is not set
485# CONFIG_MFD_PCF50633 is not set
486# CONFIG_REGULATOR is not set
487
488#
489# Multimedia devices
490#
491
492#
493# Multimedia core support
494#
495# CONFIG_VIDEO_DEV is not set
496# CONFIG_VIDEO_MEDIA is not set
497
498#
499# Multimedia drivers
500#
501# CONFIG_DAB is not set
502
503#
504# Graphics support
505#
506# CONFIG_VGASTATE is not set
507# CONFIG_VIDEO_OUTPUT_CONTROL is not set
508# CONFIG_FB is not set
509# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
510
511#
512# Display device support
513#
514# CONFIG_DISPLAY_SUPPORT is not set
515# CONFIG_SOUND is not set
516# CONFIG_USB_SUPPORT is not set
517# CONFIG_MMC is not set
518# CONFIG_MEMSTICK is not set
519# CONFIG_NEW_LEDS is not set
520# CONFIG_ACCESSIBILITY is not set
521CONFIG_RTC_LIB=y
522CONFIG_RTC_CLASS=y
523CONFIG_RTC_HCTOSYS=y
524CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
525# CONFIG_RTC_DEBUG is not set
526
527#
528# RTC interfaces
529#
530CONFIG_RTC_INTF_DEV=y
531# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
532# CONFIG_RTC_DRV_TEST is not set
533
534#
535# I2C RTC drivers
536#
537# CONFIG_RTC_DRV_DS1307 is not set
538# CONFIG_RTC_DRV_DS1374 is not set
539# CONFIG_RTC_DRV_DS1672 is not set
540# CONFIG_RTC_DRV_MAX6900 is not set
541# CONFIG_RTC_DRV_RS5C372 is not set
542# CONFIG_RTC_DRV_ISL1208 is not set
543# CONFIG_RTC_DRV_X1205 is not set
544# CONFIG_RTC_DRV_PCF8563 is not set
545# CONFIG_RTC_DRV_PCF8583 is not set
546# CONFIG_RTC_DRV_M41T80 is not set
547# CONFIG_RTC_DRV_S35390A is not set
548# CONFIG_RTC_DRV_FM3130 is not set
549# CONFIG_RTC_DRV_RX8581 is not set
550
551#
552# SPI RTC drivers
553#
554
555#
556# Platform RTC drivers
557#
558# CONFIG_RTC_DRV_DS1286 is not set
559# CONFIG_RTC_DRV_DS1511 is not set
560# CONFIG_RTC_DRV_DS1553 is not set
561# CONFIG_RTC_DRV_DS1742 is not set
562# CONFIG_RTC_DRV_STK17TA8 is not set
563# CONFIG_RTC_DRV_M48T86 is not set
564# CONFIG_RTC_DRV_M48T35 is not set
565# CONFIG_RTC_DRV_M48T59 is not set
566# CONFIG_RTC_DRV_BQ4802 is not set
567# CONFIG_RTC_DRV_V3020 is not set
568
569#
570# on-CPU RTC drivers
571#
572CONFIG_RTC_DRV_SH=y
573# CONFIG_DMADEVICES is not set
574# CONFIG_AUXDISPLAY is not set
575CONFIG_UIO=y
576# CONFIG_UIO_PDRV is not set
577CONFIG_UIO_PDRV_GENIRQ=y
578# CONFIG_UIO_SMX is not set
579# CONFIG_UIO_SERCOS3 is not set
580# CONFIG_STAGING is not set
581
582#
583# File systems
584#
585# CONFIG_EXT2_FS is not set
586# CONFIG_EXT3_FS is not set
587# CONFIG_EXT4_FS is not set
588# CONFIG_REISERFS_FS is not set
589# CONFIG_JFS_FS is not set
590# CONFIG_FS_POSIX_ACL is not set
591CONFIG_FILE_LOCKING=y
592# CONFIG_XFS_FS is not set
593# CONFIG_BTRFS_FS is not set
594# CONFIG_DNOTIFY is not set
595# CONFIG_INOTIFY is not set
596# CONFIG_QUOTA is not set
597# CONFIG_AUTOFS_FS is not set
598# CONFIG_AUTOFS4_FS is not set
599# CONFIG_FUSE_FS is not set
600
601#
602# Caches
603#
604# CONFIG_FSCACHE is not set
605
606#
607# CD-ROM/DVD Filesystems
608#
609# CONFIG_ISO9660_FS is not set
610# CONFIG_UDF_FS is not set
611
612#
613# DOS/FAT/NT Filesystems
614#
615# CONFIG_MSDOS_FS is not set
616# CONFIG_VFAT_FS is not set
617# CONFIG_NTFS_FS is not set
618
619#
620# Pseudo filesystems
621#
622# CONFIG_PROC_FS is not set
623# CONFIG_SYSFS is not set
624# CONFIG_TMPFS is not set
625# CONFIG_HUGETLBFS is not set
626# CONFIG_HUGETLB_PAGE is not set
627# CONFIG_MISC_FILESYSTEMS is not set
628
629#
630# Partition Types
631#
632# CONFIG_PARTITION_ADVANCED is not set
633CONFIG_MSDOS_PARTITION=y
634# CONFIG_NLS is not set
635
636#
637# Kernel hacking
638#
639CONFIG_TRACE_IRQFLAGS_SUPPORT=y
640# CONFIG_PRINTK_TIME is not set
641# CONFIG_ENABLE_WARN_DEPRECATED is not set
642# CONFIG_ENABLE_MUST_CHECK is not set
643CONFIG_FRAME_WARN=1024
644# CONFIG_MAGIC_SYSRQ is not set
645# CONFIG_UNUSED_SYMBOLS is not set
646CONFIG_DEBUG_FS=y
647# CONFIG_HEADERS_CHECK is not set
648# CONFIG_DEBUG_KERNEL is not set
649CONFIG_STACKTRACE=y
650# CONFIG_DEBUG_BUGVERBOSE is not set
651# CONFIG_DEBUG_MEMORY_INIT is not set
652# CONFIG_RCU_CPU_STALL_DETECTOR is not set
653# CONFIG_LATENCYTOP is not set
654# CONFIG_SYSCTL_SYSCALL_CHECK is not set
655CONFIG_NOP_TRACER=y
656CONFIG_HAVE_FUNCTION_TRACER=y
657CONFIG_HAVE_DYNAMIC_FTRACE=y
658CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
659CONFIG_RING_BUFFER=y
660CONFIG_TRACING=y
661CONFIG_TRACING_SUPPORT=y
662
663#
664# Tracers
665#
666# CONFIG_FUNCTION_TRACER is not set
667# CONFIG_IRQSOFF_TRACER is not set
668# CONFIG_SCHED_TRACER is not set
669# CONFIG_CONTEXT_SWITCH_TRACER is not set
670# CONFIG_EVENT_TRACER is not set
671# CONFIG_BOOT_TRACER is not set
672# CONFIG_TRACE_BRANCH_PROFILING is not set
673# CONFIG_STACK_TRACER is not set
674# CONFIG_KMEMTRACE is not set
675# CONFIG_WORKQUEUE_TRACER is not set
676# CONFIG_FTRACE_STARTUP_TEST is not set
677# CONFIG_DYNAMIC_DEBUG is not set
678# CONFIG_DMA_API_DEBUG is not set
679# CONFIG_SAMPLES is not set
680CONFIG_HAVE_ARCH_KGDB=y
681# CONFIG_SH_STANDARD_BIOS is not set
682# CONFIG_EARLY_SCIF_CONSOLE is not set
683# CONFIG_MORE_COMPILE_OPTIONS is not set
684
685#
686# Security options
687#
688# CONFIG_KEYS is not set
689# CONFIG_SECURITYFS is not set
690# CONFIG_SECURITY_FILE_CAPABILITIES is not set
691# CONFIG_CRYPTO is not set
692CONFIG_BINARY_PRINTF=y
693
694#
695# Library routines
696#
697CONFIG_GENERIC_FIND_LAST_BIT=y
698# CONFIG_CRC_CCITT is not set
699# CONFIG_CRC16 is not set
700# CONFIG_CRC_T10DIF is not set
701# CONFIG_CRC_ITU_T is not set
702# CONFIG_CRC32 is not set
703# CONFIG_CRC7 is not set
704# CONFIG_LIBCRC32C is not set
705CONFIG_HAS_IOMEM=y
706CONFIG_HAS_IOPORT=y
707CONFIG_HAS_DMA=y
diff --git a/arch/sh/configs/sh7763rdp_defconfig b/arch/sh/configs/sh7763rdp_defconfig
index c79bb84ec305..f77bc7998d2f 100644
--- a/arch/sh/configs/sh7763rdp_defconfig
+++ b/arch/sh/configs/sh7763rdp_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 19:10:57 2009 4# Mon Apr 27 13:10:12 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -78,6 +79,7 @@ CONFIG_UID16=y
78# CONFIG_SYSCTL_SYSCALL is not set 79# CONFIG_SYSCTL_SYSCALL is not set
79CONFIG_KALLSYMS=y 80CONFIG_KALLSYMS=y
80# CONFIG_KALLSYMS_EXTRA_PASS is not set 81# CONFIG_KALLSYMS_EXTRA_PASS is not set
82# CONFIG_STRIP_ASM_SYMS is not set
81CONFIG_HOTPLUG=y 83CONFIG_HOTPLUG=y
82CONFIG_PRINTK=y 84CONFIG_PRINTK=y
83CONFIG_BUG=y 85CONFIG_BUG=y
@@ -106,6 +108,8 @@ CONFIG_HAVE_KPROBES=y
106CONFIG_HAVE_KRETPROBES=y 108CONFIG_HAVE_KRETPROBES=y
107CONFIG_HAVE_ARCH_TRACEHOOK=y 109CONFIG_HAVE_ARCH_TRACEHOOK=y
108CONFIG_HAVE_CLK=y 110CONFIG_HAVE_CLK=y
111CONFIG_HAVE_DMA_API_DEBUG=y
112# CONFIG_SLOW_WORK is not set
109CONFIG_HAVE_GENERIC_DMA_COHERENT=y 113CONFIG_HAVE_GENERIC_DMA_COHERENT=y
110CONFIG_SLABINFO=y 114CONFIG_SLABINFO=y
111CONFIG_RT_MUTEXES=y 115CONFIG_RT_MUTEXES=y
@@ -117,7 +121,6 @@ CONFIG_MODULES=y
117# CONFIG_MODULE_SRCVERSION_ALL is not set 121# CONFIG_MODULE_SRCVERSION_ALL is not set
118CONFIG_BLOCK=y 122CONFIG_BLOCK=y
119# CONFIG_LBD is not set 123# CONFIG_LBD is not set
120# CONFIG_BLK_DEV_IO_TRACE is not set
121# CONFIG_BLK_DEV_BSG is not set 124# CONFIG_BLK_DEV_BSG is not set
122# CONFIG_BLK_DEV_INTEGRITY is not set 125# CONFIG_BLK_DEV_INTEGRITY is not set
123 126
@@ -164,6 +167,7 @@ CONFIG_CPU_SH4A=y
164# CONFIG_CPU_SUBTYPE_SH7760 is not set 167# CONFIG_CPU_SUBTYPE_SH7760 is not set
165# CONFIG_CPU_SUBTYPE_SH4_202 is not set 168# CONFIG_CPU_SUBTYPE_SH4_202 is not set
166# CONFIG_CPU_SUBTYPE_SH7723 is not set 169# CONFIG_CPU_SUBTYPE_SH7723 is not set
170# CONFIG_CPU_SUBTYPE_SH7724 is not set
167CONFIG_CPU_SUBTYPE_SH7763=y 171CONFIG_CPU_SUBTYPE_SH7763=y
168# CONFIG_CPU_SUBTYPE_SH7770 is not set 172# CONFIG_CPU_SUBTYPE_SH7770 is not set
169# CONFIG_CPU_SUBTYPE_SH7780 is not set 173# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -173,8 +177,6 @@ CONFIG_CPU_SUBTYPE_SH7763=y
173# CONFIG_CPU_SUBTYPE_SH7343 is not set 177# CONFIG_CPU_SUBTYPE_SH7343 is not set
174# CONFIG_CPU_SUBTYPE_SH7722 is not set 178# CONFIG_CPU_SUBTYPE_SH7722 is not set
175# CONFIG_CPU_SUBTYPE_SH7366 is not set 179# CONFIG_CPU_SUBTYPE_SH7366 is not set
176# CONFIG_CPU_SUBTYPE_SH5_101 is not set
177# CONFIG_CPU_SUBTYPE_SH5_103 is not set
178 180
179# 181#
180# Memory management options 182# Memory management options
@@ -555,6 +557,7 @@ CONFIG_SCSI_WAIT_SCAN=m
555CONFIG_SCSI_LOWLEVEL=y 557CONFIG_SCSI_LOWLEVEL=y
556# CONFIG_ISCSI_TCP is not set 558# CONFIG_ISCSI_TCP is not set
557# CONFIG_LIBFC is not set 559# CONFIG_LIBFC is not set
560# CONFIG_LIBFCOE is not set
558# CONFIG_SCSI_DEBUG is not set 561# CONFIG_SCSI_DEBUG is not set
559# CONFIG_SCSI_DH is not set 562# CONFIG_SCSI_DH is not set
560# CONFIG_SCSI_OSD_INITIATOR is not set 563# CONFIG_SCSI_OSD_INITIATOR is not set
@@ -941,6 +944,7 @@ CONFIG_EXT2_FS=y
941# CONFIG_EXT2_FS_XATTR is not set 944# CONFIG_EXT2_FS_XATTR is not set
942# CONFIG_EXT2_FS_XIP is not set 945# CONFIG_EXT2_FS_XIP is not set
943CONFIG_EXT3_FS=y 946CONFIG_EXT3_FS=y
947# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
944CONFIG_EXT3_FS_XATTR=y 948CONFIG_EXT3_FS_XATTR=y
945# CONFIG_EXT3_FS_POSIX_ACL is not set 949# CONFIG_EXT3_FS_POSIX_ACL is not set
946# CONFIG_EXT3_FS_SECURITY is not set 950# CONFIG_EXT3_FS_SECURITY is not set
@@ -965,6 +969,11 @@ CONFIG_AUTOFS4_FS=y
965CONFIG_GENERIC_ACL=y 969CONFIG_GENERIC_ACL=y
966 970
967# 971#
972# Caches
973#
974# CONFIG_FSCACHE is not set
975
976#
968# CD-ROM/DVD Filesystems 977# CD-ROM/DVD Filesystems
969# 978#
970# CONFIG_ISO9660_FS is not set 979# CONFIG_ISO9660_FS is not set
@@ -1012,6 +1021,7 @@ CONFIG_MISC_FILESYSTEMS=y
1012# CONFIG_ROMFS_FS is not set 1021# CONFIG_ROMFS_FS is not set
1013# CONFIG_SYSV_FS is not set 1022# CONFIG_SYSV_FS is not set
1014# CONFIG_UFS_FS is not set 1023# CONFIG_UFS_FS is not set
1024# CONFIG_NILFS2_FS is not set
1015CONFIG_NETWORK_FILESYSTEMS=y 1025CONFIG_NETWORK_FILESYSTEMS=y
1016CONFIG_NFS_FS=y 1026CONFIG_NFS_FS=y
1017# CONFIG_NFS_V3 is not set 1027# CONFIG_NFS_V3 is not set
@@ -1100,11 +1110,25 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
1100CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1110CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1101CONFIG_RING_BUFFER=y 1111CONFIG_RING_BUFFER=y
1102CONFIG_TRACING=y 1112CONFIG_TRACING=y
1113CONFIG_TRACING_SUPPORT=y
1103 1114
1104# 1115#
1105# Tracers 1116# Tracers
1106# 1117#
1118# CONFIG_FUNCTION_TRACER is not set
1119# CONFIG_IRQSOFF_TRACER is not set
1120# CONFIG_SCHED_TRACER is not set
1121# CONFIG_CONTEXT_SWITCH_TRACER is not set
1122# CONFIG_EVENT_TRACER is not set
1123# CONFIG_BOOT_TRACER is not set
1124# CONFIG_TRACE_BRANCH_PROFILING is not set
1125# CONFIG_STACK_TRACER is not set
1126# CONFIG_KMEMTRACE is not set
1127# CONFIG_WORKQUEUE_TRACER is not set
1128# CONFIG_BLK_DEV_IO_TRACE is not set
1129# CONFIG_FTRACE_STARTUP_TEST is not set
1107# CONFIG_DYNAMIC_DEBUG is not set 1130# CONFIG_DYNAMIC_DEBUG is not set
1131# CONFIG_DMA_API_DEBUG is not set
1108# CONFIG_SAMPLES is not set 1132# CONFIG_SAMPLES is not set
1109CONFIG_HAVE_ARCH_KGDB=y 1133CONFIG_HAVE_ARCH_KGDB=y
1110# CONFIG_SH_STANDARD_BIOS is not set 1134# CONFIG_SH_STANDARD_BIOS is not set
@@ -1204,6 +1228,7 @@ CONFIG_CRYPTO=y
1204# 1228#
1205# CONFIG_CRYPTO_ANSI_CPRNG is not set 1229# CONFIG_CRYPTO_ANSI_CPRNG is not set
1206CONFIG_CRYPTO_HW=y 1230CONFIG_CRYPTO_HW=y
1231CONFIG_BINARY_PRINTF=y
1207 1232
1208# 1233#
1209# Library routines 1234# Library routines
diff --git a/arch/sh/configs/sh7770_generic_defconfig b/arch/sh/configs/sh7770_generic_defconfig
new file mode 100644
index 000000000000..d6489b46ca5b
--- /dev/null
+++ b/arch/sh/configs/sh7770_generic_defconfig
@@ -0,0 +1,700 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.30-rc4
4# Tue May 12 14:48:21 2009
5#
6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
10CONFIG_RWSEM_GENERIC_SPINLOCK=y
11CONFIG_GENERIC_BUG=y
12CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
16CONFIG_GENERIC_IRQ_PROBE=y
17# CONFIG_GENERIC_GPIO is not set
18CONFIG_GENERIC_TIME=y
19CONFIG_GENERIC_CLOCKEVENTS=y
20# CONFIG_ARCH_SUSPEND_POSSIBLE is not set
21CONFIG_ARCH_HIBERNATION_POSSIBLE=y
22CONFIG_SYS_SUPPORTS_TMU=y
23CONFIG_STACKTRACE_SUPPORT=y
24CONFIG_LOCKDEP_SUPPORT=y
25CONFIG_HAVE_LATENCYTOP_SUPPORT=y
26# CONFIG_ARCH_HAS_ILOG2_U32 is not set
27# CONFIG_ARCH_HAS_ILOG2_U64 is not set
28CONFIG_ARCH_NO_VIRT_TO_BUS=y
29CONFIG_ARCH_HAS_DEFAULT_IDLE=y
30CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
31
32#
33# General setup
34#
35CONFIG_EXPERIMENTAL=y
36CONFIG_BROKEN_ON_SMP=y
37CONFIG_INIT_ENV_ARG_LIMIT=32
38CONFIG_LOCALVERSION=""
39# CONFIG_LOCALVERSION_AUTO is not set
40CONFIG_SWAP=y
41CONFIG_SYSVIPC=y
42CONFIG_SYSVIPC_SYSCTL=y
43# CONFIG_BSD_PROCESS_ACCT is not set
44
45#
46# RCU Subsystem
47#
48# CONFIG_CLASSIC_RCU is not set
49CONFIG_TREE_RCU=y
50# CONFIG_PREEMPT_RCU is not set
51# CONFIG_RCU_TRACE is not set
52CONFIG_RCU_FANOUT=32
53# CONFIG_RCU_FANOUT_EXACT is not set
54# CONFIG_TREE_RCU_TRACE is not set
55# CONFIG_PREEMPT_RCU_TRACE is not set
56# CONFIG_IKCONFIG is not set
57CONFIG_LOG_BUF_SHIFT=17
58CONFIG_GROUP_SCHED=y
59CONFIG_FAIR_GROUP_SCHED=y
60CONFIG_RT_GROUP_SCHED=y
61CONFIG_USER_SCHED=y
62# CONFIG_CGROUP_SCHED is not set
63CONFIG_CGROUPS=y
64# CONFIG_CGROUP_DEBUG is not set
65# CONFIG_CGROUP_NS is not set
66# CONFIG_CGROUP_FREEZER is not set
67# CONFIG_CGROUP_DEVICE is not set
68# CONFIG_CPUSETS is not set
69# CONFIG_CGROUP_CPUACCT is not set
70# CONFIG_RESOURCE_COUNTERS is not set
71# CONFIG_RELAY is not set
72# CONFIG_NAMESPACES is not set
73# CONFIG_BLK_DEV_INITRD is not set
74CONFIG_CC_OPTIMIZE_FOR_SIZE=y
75CONFIG_SYSCTL=y
76CONFIG_ANON_INODES=y
77CONFIG_EMBEDDED=y
78# CONFIG_UID16 is not set
79CONFIG_SYSCTL_SYSCALL=y
80CONFIG_KALLSYMS=y
81# CONFIG_KALLSYMS_EXTRA_PASS is not set
82# CONFIG_STRIP_ASM_SYMS is not set
83CONFIG_HOTPLUG=y
84CONFIG_PRINTK=y
85CONFIG_BUG=y
86CONFIG_ELF_CORE=y
87CONFIG_BASE_FULL=y
88CONFIG_FUTEX=y
89CONFIG_EPOLL=y
90CONFIG_SIGNALFD=y
91CONFIG_TIMERFD=y
92CONFIG_EVENTFD=y
93CONFIG_SHMEM=y
94CONFIG_AIO=y
95CONFIG_VM_EVENT_COUNTERS=y
96# CONFIG_COMPAT_BRK is not set
97# CONFIG_SLAB is not set
98CONFIG_SLUB=y
99# CONFIG_SLOB is not set
100CONFIG_PROFILING=y
101CONFIG_TRACEPOINTS=y
102# CONFIG_MARKERS is not set
103CONFIG_OPROFILE=y
104CONFIG_HAVE_OPROFILE=y
105CONFIG_HAVE_IOREMAP_PROT=y
106CONFIG_HAVE_KPROBES=y
107CONFIG_HAVE_KRETPROBES=y
108CONFIG_HAVE_ARCH_TRACEHOOK=y
109CONFIG_HAVE_CLK=y
110CONFIG_HAVE_DMA_API_DEBUG=y
111# CONFIG_SLOW_WORK is not set
112CONFIG_HAVE_GENERIC_DMA_COHERENT=y
113CONFIG_RT_MUTEXES=y
114CONFIG_BASE_SMALL=0
115# CONFIG_MODULES is not set
116CONFIG_BLOCK=y
117# CONFIG_LBD is not set
118# CONFIG_BLK_DEV_BSG is not set
119# CONFIG_BLK_DEV_INTEGRITY is not set
120
121#
122# IO Schedulers
123#
124CONFIG_IOSCHED_NOOP=y
125CONFIG_IOSCHED_AS=y
126CONFIG_IOSCHED_DEADLINE=y
127CONFIG_IOSCHED_CFQ=y
128CONFIG_DEFAULT_AS=y
129# CONFIG_DEFAULT_DEADLINE is not set
130# CONFIG_DEFAULT_CFQ is not set
131# CONFIG_DEFAULT_NOOP is not set
132CONFIG_DEFAULT_IOSCHED="anticipatory"
133CONFIG_FREEZER=y
134
135#
136# System type
137#
138CONFIG_CPU_SH4=y
139CONFIG_CPU_SH4A=y
140# CONFIG_CPU_SUBTYPE_SH7619 is not set
141# CONFIG_CPU_SUBTYPE_SH7201 is not set
142# CONFIG_CPU_SUBTYPE_SH7203 is not set
143# CONFIG_CPU_SUBTYPE_SH7206 is not set
144# CONFIG_CPU_SUBTYPE_SH7263 is not set
145# CONFIG_CPU_SUBTYPE_MXG is not set
146# CONFIG_CPU_SUBTYPE_SH7705 is not set
147# CONFIG_CPU_SUBTYPE_SH7706 is not set
148# CONFIG_CPU_SUBTYPE_SH7707 is not set
149# CONFIG_CPU_SUBTYPE_SH7708 is not set
150# CONFIG_CPU_SUBTYPE_SH7709 is not set
151# CONFIG_CPU_SUBTYPE_SH7710 is not set
152# CONFIG_CPU_SUBTYPE_SH7712 is not set
153# CONFIG_CPU_SUBTYPE_SH7720 is not set
154# CONFIG_CPU_SUBTYPE_SH7721 is not set
155# CONFIG_CPU_SUBTYPE_SH7750 is not set
156# CONFIG_CPU_SUBTYPE_SH7091 is not set
157# CONFIG_CPU_SUBTYPE_SH7750R is not set
158# CONFIG_CPU_SUBTYPE_SH7750S is not set
159# CONFIG_CPU_SUBTYPE_SH7751 is not set
160# CONFIG_CPU_SUBTYPE_SH7751R is not set
161# CONFIG_CPU_SUBTYPE_SH7760 is not set
162# CONFIG_CPU_SUBTYPE_SH4_202 is not set
163# CONFIG_CPU_SUBTYPE_SH7723 is not set
164# CONFIG_CPU_SUBTYPE_SH7724 is not set
165# CONFIG_CPU_SUBTYPE_SH7763 is not set
166CONFIG_CPU_SUBTYPE_SH7770=y
167# CONFIG_CPU_SUBTYPE_SH7780 is not set
168# CONFIG_CPU_SUBTYPE_SH7785 is not set
169# CONFIG_CPU_SUBTYPE_SH7786 is not set
170# CONFIG_CPU_SUBTYPE_SHX3 is not set
171# CONFIG_CPU_SUBTYPE_SH7343 is not set
172# CONFIG_CPU_SUBTYPE_SH7722 is not set
173# CONFIG_CPU_SUBTYPE_SH7366 is not set
174
175#
176# Memory management options
177#
178CONFIG_QUICKLIST=y
179CONFIG_MMU=y
180CONFIG_PAGE_OFFSET=0x80000000
181CONFIG_MEMORY_START=0x08000000
182CONFIG_MEMORY_SIZE=0x04000000
183CONFIG_29BIT=y
184CONFIG_VSYSCALL=y
185CONFIG_ARCH_FLATMEM_ENABLE=y
186CONFIG_ARCH_SPARSEMEM_ENABLE=y
187CONFIG_ARCH_SPARSEMEM_DEFAULT=y
188CONFIG_MAX_ACTIVE_REGIONS=1
189CONFIG_ARCH_POPULATES_NODE_MAP=y
190CONFIG_ARCH_SELECT_MEMORY_MODEL=y
191CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
192CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
193CONFIG_PAGE_SIZE_4KB=y
194# CONFIG_PAGE_SIZE_8KB is not set
195# CONFIG_PAGE_SIZE_16KB is not set
196# CONFIG_PAGE_SIZE_64KB is not set
197CONFIG_SELECT_MEMORY_MODEL=y
198# CONFIG_FLATMEM_MANUAL is not set
199# CONFIG_DISCONTIGMEM_MANUAL is not set
200CONFIG_SPARSEMEM_MANUAL=y
201CONFIG_SPARSEMEM=y
202CONFIG_HAVE_MEMORY_PRESENT=y
203CONFIG_SPARSEMEM_STATIC=y
204
205#
206# Memory hotplug is currently incompatible with Software Suspend
207#
208CONFIG_PAGEFLAGS_EXTENDED=y
209CONFIG_SPLIT_PTLOCK_CPUS=4
210CONFIG_MIGRATION=y
211# CONFIG_PHYS_ADDR_T_64BIT is not set
212CONFIG_ZONE_DMA_FLAG=0
213CONFIG_NR_QUICK=2
214CONFIG_UNEVICTABLE_LRU=y
215CONFIG_HAVE_MLOCK=y
216CONFIG_HAVE_MLOCKED_PAGE_BIT=y
217
218#
219# Cache configuration
220#
221CONFIG_CACHE_WRITEBACK=y
222# CONFIG_CACHE_WRITETHROUGH is not set
223# CONFIG_CACHE_OFF is not set
224
225#
226# Processor features
227#
228CONFIG_CPU_LITTLE_ENDIAN=y
229# CONFIG_CPU_BIG_ENDIAN is not set
230CONFIG_SH_FPU=y
231# CONFIG_SH_STORE_QUEUES is not set
232CONFIG_CPU_HAS_INTEVT=y
233CONFIG_CPU_HAS_SR_RB=y
234CONFIG_CPU_HAS_FPU=y
235
236#
237# Board support
238#
239
240#
241# Timer and clock configuration
242#
243CONFIG_SH_TMU=y
244CONFIG_SH_TIMER_IRQ=16
245CONFIG_SH_PCLK_FREQ=41666666
246CONFIG_TICK_ONESHOT=y
247CONFIG_NO_HZ=y
248CONFIG_HIGH_RES_TIMERS=y
249CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
250
251#
252# CPU Frequency scaling
253#
254CONFIG_CPU_FREQ=y
255CONFIG_CPU_FREQ_TABLE=y
256# CONFIG_CPU_FREQ_DEBUG is not set
257CONFIG_CPU_FREQ_STAT=y
258# CONFIG_CPU_FREQ_STAT_DETAILS is not set
259CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y
260# CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE is not set
261# CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set
262# CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND is not set
263# CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE is not set
264CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
265# CONFIG_CPU_FREQ_GOV_POWERSAVE is not set
266# CONFIG_CPU_FREQ_GOV_USERSPACE is not set
267# CONFIG_CPU_FREQ_GOV_ONDEMAND is not set
268# CONFIG_CPU_FREQ_GOV_CONSERVATIVE is not set
269CONFIG_SH_CPU_FREQ=y
270
271#
272# DMA support
273#
274# CONFIG_SH_DMA is not set
275
276#
277# Companion Chips
278#
279
280#
281# Additional SuperH Device Drivers
282#
283# CONFIG_HEARTBEAT is not set
284# CONFIG_PUSH_SWITCH is not set
285
286#
287# Kernel features
288#
289# CONFIG_HZ_100 is not set
290CONFIG_HZ_250=y
291# CONFIG_HZ_300 is not set
292# CONFIG_HZ_1000 is not set
293CONFIG_HZ=250
294CONFIG_SCHED_HRTICK=y
295CONFIG_KEXEC=y
296# CONFIG_CRASH_DUMP is not set
297CONFIG_KEXEC_JUMP=y
298CONFIG_PREEMPT_NONE=y
299# CONFIG_PREEMPT_VOLUNTARY is not set
300# CONFIG_PREEMPT is not set
301CONFIG_GUSA=y
302
303#
304# Boot options
305#
306CONFIG_ZERO_PAGE_OFFSET=0x00001000
307CONFIG_BOOT_LINK_OFFSET=0x00800000
308CONFIG_ENTRY_OFFSET=0x00001000
309# CONFIG_CMDLINE_BOOL is not set
310
311#
312# Bus options
313#
314# CONFIG_ARCH_SUPPORTS_MSI is not set
315# CONFIG_PCCARD is not set
316
317#
318# Executable file formats
319#
320CONFIG_BINFMT_ELF=y
321# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
322# CONFIG_HAVE_AOUT is not set
323# CONFIG_BINFMT_MISC is not set
324
325#
326# Power management options (EXPERIMENTAL)
327#
328CONFIG_PM=y
329# CONFIG_PM_DEBUG is not set
330CONFIG_PM_SLEEP=y
331CONFIG_HIBERNATION=y
332CONFIG_PM_STD_PARTITION=""
333CONFIG_CPU_IDLE=y
334CONFIG_CPU_IDLE_GOV_LADDER=y
335CONFIG_CPU_IDLE_GOV_MENU=y
336# CONFIG_NET is not set
337
338#
339# Device Drivers
340#
341
342#
343# Generic Driver Options
344#
345CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
346CONFIG_STANDALONE=y
347# CONFIG_PREVENT_FIRMWARE_BUILD is not set
348CONFIG_FW_LOADER=y
349CONFIG_FIRMWARE_IN_KERNEL=y
350CONFIG_EXTRA_FIRMWARE=""
351# CONFIG_SYS_HYPERVISOR is not set
352# CONFIG_MTD is not set
353# CONFIG_PARPORT is not set
354CONFIG_BLK_DEV=y
355# CONFIG_BLK_DEV_COW_COMMON is not set
356# CONFIG_BLK_DEV_LOOP is not set
357# CONFIG_BLK_DEV_RAM is not set
358# CONFIG_CDROM_PKTCDVD is not set
359# CONFIG_BLK_DEV_HD is not set
360# CONFIG_MISC_DEVICES is not set
361CONFIG_HAVE_IDE=y
362# CONFIG_IDE is not set
363
364#
365# SCSI device support
366#
367# CONFIG_RAID_ATTRS is not set
368# CONFIG_SCSI is not set
369# CONFIG_SCSI_DMA is not set
370# CONFIG_SCSI_NETLINK is not set
371# CONFIG_ATA is not set
372# CONFIG_MD is not set
373# CONFIG_PHONE is not set
374
375#
376# Input device support
377#
378# CONFIG_INPUT is not set
379
380#
381# Hardware I/O ports
382#
383# CONFIG_SERIO is not set
384# CONFIG_GAMEPORT is not set
385
386#
387# Character devices
388#
389# CONFIG_VT is not set
390# CONFIG_DEVKMEM is not set
391# CONFIG_SERIAL_NONSTANDARD is not set
392
393#
394# Serial drivers
395#
396# CONFIG_SERIAL_8250 is not set
397
398#
399# Non-8250 serial port support
400#
401CONFIG_SERIAL_SH_SCI=y
402CONFIG_SERIAL_SH_SCI_NR_UARTS=6
403CONFIG_SERIAL_SH_SCI_CONSOLE=y
404CONFIG_SERIAL_CORE=y
405CONFIG_SERIAL_CORE_CONSOLE=y
406# CONFIG_UNIX98_PTYS is not set
407# CONFIG_LEGACY_PTYS is not set
408# CONFIG_IPMI_HANDLER is not set
409# CONFIG_HW_RANDOM is not set
410# CONFIG_R3964 is not set
411# CONFIG_RAW_DRIVER is not set
412# CONFIG_TCG_TPM is not set
413CONFIG_I2C=y
414CONFIG_I2C_BOARDINFO=y
415CONFIG_I2C_CHARDEV=y
416CONFIG_I2C_HELPER_AUTO=y
417
418#
419# I2C Hardware Bus support
420#
421
422#
423# I2C system bus drivers (mostly embedded / system-on-chip)
424#
425# CONFIG_I2C_OCORES is not set
426CONFIG_I2C_SH_MOBILE=y
427# CONFIG_I2C_SIMTEC is not set
428
429#
430# External I2C/SMBus adapter drivers
431#
432# CONFIG_I2C_PARPORT_LIGHT is not set
433# CONFIG_I2C_TAOS_EVM is not set
434
435#
436# Other I2C/SMBus bus drivers
437#
438# CONFIG_I2C_PCA_PLATFORM is not set
439
440#
441# Miscellaneous I2C Chip support
442#
443# CONFIG_DS1682 is not set
444# CONFIG_SENSORS_PCF8574 is not set
445# CONFIG_PCF8575 is not set
446# CONFIG_SENSORS_PCA9539 is not set
447# CONFIG_SENSORS_MAX6875 is not set
448# CONFIG_SENSORS_TSL2550 is not set
449# CONFIG_I2C_DEBUG_CORE is not set
450# CONFIG_I2C_DEBUG_ALGO is not set
451# CONFIG_I2C_DEBUG_BUS is not set
452# CONFIG_I2C_DEBUG_CHIP is not set
453# CONFIG_SPI is not set
454# CONFIG_W1 is not set
455# CONFIG_POWER_SUPPLY is not set
456# CONFIG_HWMON is not set
457# CONFIG_THERMAL is not set
458# CONFIG_THERMAL_HWMON is not set
459# CONFIG_WATCHDOG is not set
460CONFIG_SSB_POSSIBLE=y
461
462#
463# Sonics Silicon Backplane
464#
465# CONFIG_SSB is not set
466
467#
468# Multifunction device drivers
469#
470# CONFIG_MFD_CORE is not set
471# CONFIG_MFD_SM501 is not set
472# CONFIG_HTC_PASIC3 is not set
473# CONFIG_TWL4030_CORE is not set
474# CONFIG_MFD_TMIO is not set
475# CONFIG_PMIC_DA903X is not set
476# CONFIG_MFD_WM8400 is not set
477# CONFIG_MFD_WM8350_I2C is not set
478# CONFIG_MFD_PCF50633 is not set
479# CONFIG_REGULATOR is not set
480
481#
482# Multimedia devices
483#
484
485#
486# Multimedia core support
487#
488# CONFIG_VIDEO_DEV is not set
489# CONFIG_VIDEO_MEDIA is not set
490
491#
492# Multimedia drivers
493#
494# CONFIG_DAB is not set
495
496#
497# Graphics support
498#
499# CONFIG_VGASTATE is not set
500# CONFIG_VIDEO_OUTPUT_CONTROL is not set
501# CONFIG_FB is not set
502# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
503
504#
505# Display device support
506#
507# CONFIG_DISPLAY_SUPPORT is not set
508# CONFIG_SOUND is not set
509# CONFIG_USB_SUPPORT is not set
510# CONFIG_MMC is not set
511# CONFIG_MEMSTICK is not set
512# CONFIG_NEW_LEDS is not set
513# CONFIG_ACCESSIBILITY is not set
514CONFIG_RTC_LIB=y
515CONFIG_RTC_CLASS=y
516CONFIG_RTC_HCTOSYS=y
517CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
518# CONFIG_RTC_DEBUG is not set
519
520#
521# RTC interfaces
522#
523CONFIG_RTC_INTF_DEV=y
524# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
525# CONFIG_RTC_DRV_TEST is not set
526
527#
528# I2C RTC drivers
529#
530# CONFIG_RTC_DRV_DS1307 is not set
531# CONFIG_RTC_DRV_DS1374 is not set
532# CONFIG_RTC_DRV_DS1672 is not set
533# CONFIG_RTC_DRV_MAX6900 is not set
534# CONFIG_RTC_DRV_RS5C372 is not set
535# CONFIG_RTC_DRV_ISL1208 is not set
536# CONFIG_RTC_DRV_X1205 is not set
537# CONFIG_RTC_DRV_PCF8563 is not set
538# CONFIG_RTC_DRV_PCF8583 is not set
539# CONFIG_RTC_DRV_M41T80 is not set
540# CONFIG_RTC_DRV_S35390A is not set
541# CONFIG_RTC_DRV_FM3130 is not set
542# CONFIG_RTC_DRV_RX8581 is not set
543
544#
545# SPI RTC drivers
546#
547
548#
549# Platform RTC drivers
550#
551# CONFIG_RTC_DRV_DS1286 is not set
552# CONFIG_RTC_DRV_DS1511 is not set
553# CONFIG_RTC_DRV_DS1553 is not set
554# CONFIG_RTC_DRV_DS1742 is not set
555# CONFIG_RTC_DRV_STK17TA8 is not set
556# CONFIG_RTC_DRV_M48T86 is not set
557# CONFIG_RTC_DRV_M48T35 is not set
558# CONFIG_RTC_DRV_M48T59 is not set
559# CONFIG_RTC_DRV_BQ4802 is not set
560# CONFIG_RTC_DRV_V3020 is not set
561
562#
563# on-CPU RTC drivers
564#
565CONFIG_RTC_DRV_SH=y
566# CONFIG_RTC_DRV_GENERIC is not set
567# CONFIG_DMADEVICES is not set
568# CONFIG_AUXDISPLAY is not set
569CONFIG_UIO=y
570# CONFIG_UIO_PDRV is not set
571CONFIG_UIO_PDRV_GENIRQ=y
572# CONFIG_UIO_SMX is not set
573# CONFIG_UIO_SERCOS3 is not set
574# CONFIG_STAGING is not set
575
576#
577# File systems
578#
579# CONFIG_EXT2_FS is not set
580# CONFIG_EXT3_FS is not set
581# CONFIG_EXT4_FS is not set
582# CONFIG_REISERFS_FS is not set
583# CONFIG_JFS_FS is not set
584# CONFIG_FS_POSIX_ACL is not set
585CONFIG_FILE_LOCKING=y
586# CONFIG_XFS_FS is not set
587# CONFIG_BTRFS_FS is not set
588# CONFIG_DNOTIFY is not set
589# CONFIG_INOTIFY is not set
590# CONFIG_QUOTA is not set
591# CONFIG_AUTOFS_FS is not set
592# CONFIG_AUTOFS4_FS is not set
593# CONFIG_FUSE_FS is not set
594
595#
596# Caches
597#
598# CONFIG_FSCACHE is not set
599
600#
601# CD-ROM/DVD Filesystems
602#
603# CONFIG_ISO9660_FS is not set
604# CONFIG_UDF_FS is not set
605
606#
607# DOS/FAT/NT Filesystems
608#
609# CONFIG_MSDOS_FS is not set
610# CONFIG_VFAT_FS is not set
611# CONFIG_NTFS_FS is not set
612
613#
614# Pseudo filesystems
615#
616# CONFIG_PROC_FS is not set
617# CONFIG_SYSFS is not set
618# CONFIG_TMPFS is not set
619# CONFIG_HUGETLBFS is not set
620# CONFIG_HUGETLB_PAGE is not set
621# CONFIG_MISC_FILESYSTEMS is not set
622
623#
624# Partition Types
625#
626# CONFIG_PARTITION_ADVANCED is not set
627CONFIG_MSDOS_PARTITION=y
628# CONFIG_NLS is not set
629
630#
631# Kernel hacking
632#
633CONFIG_TRACE_IRQFLAGS_SUPPORT=y
634# CONFIG_PRINTK_TIME is not set
635# CONFIG_ENABLE_WARN_DEPRECATED is not set
636# CONFIG_ENABLE_MUST_CHECK is not set
637CONFIG_FRAME_WARN=1024
638# CONFIG_MAGIC_SYSRQ is not set
639# CONFIG_UNUSED_SYMBOLS is not set
640CONFIG_DEBUG_FS=y
641# CONFIG_HEADERS_CHECK is not set
642# CONFIG_DEBUG_KERNEL is not set
643CONFIG_STACKTRACE=y
644# CONFIG_DEBUG_BUGVERBOSE is not set
645# CONFIG_DEBUG_MEMORY_INIT is not set
646# CONFIG_RCU_CPU_STALL_DETECTOR is not set
647# CONFIG_LATENCYTOP is not set
648# CONFIG_SYSCTL_SYSCALL_CHECK is not set
649CONFIG_NOP_TRACER=y
650CONFIG_HAVE_FUNCTION_TRACER=y
651CONFIG_HAVE_DYNAMIC_FTRACE=y
652CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
653CONFIG_RING_BUFFER=y
654CONFIG_TRACING=y
655CONFIG_TRACING_SUPPORT=y
656
657#
658# Tracers
659#
660# CONFIG_FUNCTION_TRACER is not set
661# CONFIG_IRQSOFF_TRACER is not set
662# CONFIG_SCHED_TRACER is not set
663# CONFIG_CONTEXT_SWITCH_TRACER is not set
664# CONFIG_EVENT_TRACER is not set
665# CONFIG_BOOT_TRACER is not set
666# CONFIG_TRACE_BRANCH_PROFILING is not set
667# CONFIG_STACK_TRACER is not set
668# CONFIG_KMEMTRACE is not set
669# CONFIG_WORKQUEUE_TRACER is not set
670# CONFIG_FTRACE_STARTUP_TEST is not set
671# CONFIG_DYNAMIC_DEBUG is not set
672# CONFIG_DMA_API_DEBUG is not set
673# CONFIG_SAMPLES is not set
674CONFIG_HAVE_ARCH_KGDB=y
675# CONFIG_SH_STANDARD_BIOS is not set
676# CONFIG_EARLY_SCIF_CONSOLE is not set
677
678#
679# Security options
680#
681# CONFIG_KEYS is not set
682# CONFIG_SECURITYFS is not set
683# CONFIG_SECURITY_FILE_CAPABILITIES is not set
684# CONFIG_CRYPTO is not set
685CONFIG_BINARY_PRINTF=y
686
687#
688# Library routines
689#
690CONFIG_GENERIC_FIND_LAST_BIT=y
691# CONFIG_CRC_CCITT is not set
692# CONFIG_CRC16 is not set
693# CONFIG_CRC_T10DIF is not set
694# CONFIG_CRC_ITU_T is not set
695# CONFIG_CRC32 is not set
696# CONFIG_CRC7 is not set
697# CONFIG_LIBCRC32C is not set
698CONFIG_HAS_IOMEM=y
699CONFIG_HAS_IOPORT=y
700CONFIG_HAS_DMA=y
diff --git a/arch/sh/configs/sh7785lcr_32bit_defconfig b/arch/sh/configs/sh7785lcr_32bit_defconfig
index a6cf4505741c..1c55b800d124 100644
--- a/arch/sh/configs/sh7785lcr_32bit_defconfig
+++ b/arch/sh/configs/sh7785lcr_32bit_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 19:12:18 2009 4# Mon Apr 27 13:10:53 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -79,6 +80,7 @@ CONFIG_SYSCTL_SYSCALL=y
79CONFIG_KALLSYMS=y 80CONFIG_KALLSYMS=y
80# CONFIG_KALLSYMS_ALL is not set 81# CONFIG_KALLSYMS_ALL is not set
81# CONFIG_KALLSYMS_EXTRA_PASS is not set 82# CONFIG_KALLSYMS_EXTRA_PASS is not set
83# CONFIG_STRIP_ASM_SYMS is not set
82CONFIG_HOTPLUG=y 84CONFIG_HOTPLUG=y
83CONFIG_PRINTK=y 85CONFIG_PRINTK=y
84CONFIG_BUG=y 86CONFIG_BUG=y
@@ -98,6 +100,7 @@ CONFIG_SLAB=y
98# CONFIG_SLUB is not set 100# CONFIG_SLUB is not set
99# CONFIG_SLOB is not set 101# CONFIG_SLOB is not set
100CONFIG_PROFILING=y 102CONFIG_PROFILING=y
103# CONFIG_MARKERS is not set
101# CONFIG_OPROFILE is not set 104# CONFIG_OPROFILE is not set
102CONFIG_HAVE_OPROFILE=y 105CONFIG_HAVE_OPROFILE=y
103# CONFIG_KPROBES is not set 106# CONFIG_KPROBES is not set
@@ -106,6 +109,8 @@ CONFIG_HAVE_KPROBES=y
106CONFIG_HAVE_KRETPROBES=y 109CONFIG_HAVE_KRETPROBES=y
107CONFIG_HAVE_ARCH_TRACEHOOK=y 110CONFIG_HAVE_ARCH_TRACEHOOK=y
108CONFIG_HAVE_CLK=y 111CONFIG_HAVE_CLK=y
112CONFIG_HAVE_DMA_API_DEBUG=y
113# CONFIG_SLOW_WORK is not set
109CONFIG_HAVE_GENERIC_DMA_COHERENT=y 114CONFIG_HAVE_GENERIC_DMA_COHERENT=y
110CONFIG_SLABINFO=y 115CONFIG_SLABINFO=y
111CONFIG_RT_MUTEXES=y 116CONFIG_RT_MUTEXES=y
@@ -118,7 +123,6 @@ CONFIG_MODULE_UNLOAD=y
118# CONFIG_MODULE_SRCVERSION_ALL is not set 123# CONFIG_MODULE_SRCVERSION_ALL is not set
119CONFIG_BLOCK=y 124CONFIG_BLOCK=y
120# CONFIG_LBD is not set 125# CONFIG_LBD is not set
121# CONFIG_BLK_DEV_IO_TRACE is not set
122# CONFIG_BLK_DEV_BSG is not set 126# CONFIG_BLK_DEV_BSG is not set
123# CONFIG_BLK_DEV_INTEGRITY is not set 127# CONFIG_BLK_DEV_INTEGRITY is not set
124 128
@@ -166,6 +170,7 @@ CONFIG_CPU_SHX2=y
166# CONFIG_CPU_SUBTYPE_SH7760 is not set 170# CONFIG_CPU_SUBTYPE_SH7760 is not set
167# CONFIG_CPU_SUBTYPE_SH4_202 is not set 171# CONFIG_CPU_SUBTYPE_SH4_202 is not set
168# CONFIG_CPU_SUBTYPE_SH7723 is not set 172# CONFIG_CPU_SUBTYPE_SH7723 is not set
173# CONFIG_CPU_SUBTYPE_SH7724 is not set
169# CONFIG_CPU_SUBTYPE_SH7763 is not set 174# CONFIG_CPU_SUBTYPE_SH7763 is not set
170# CONFIG_CPU_SUBTYPE_SH7770 is not set 175# CONFIG_CPU_SUBTYPE_SH7770 is not set
171# CONFIG_CPU_SUBTYPE_SH7780 is not set 176# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -175,8 +180,6 @@ CONFIG_CPU_SUBTYPE_SH7785=y
175# CONFIG_CPU_SUBTYPE_SH7343 is not set 180# CONFIG_CPU_SUBTYPE_SH7343 is not set
176# CONFIG_CPU_SUBTYPE_SH7722 is not set 181# CONFIG_CPU_SUBTYPE_SH7722 is not set
177# CONFIG_CPU_SUBTYPE_SH7366 is not set 182# CONFIG_CPU_SUBTYPE_SH7366 is not set
178# CONFIG_CPU_SUBTYPE_SH5_101 is not set
179# CONFIG_CPU_SUBTYPE_SH5_103 is not set
180 183
181# 184#
182# Memory management options 185# Memory management options
@@ -310,8 +313,6 @@ CONFIG_BOOT_LINK_OFFSET=0x00800000
310# 313#
311CONFIG_PCI=y 314CONFIG_PCI=y
312CONFIG_SH_PCIDMA_NONCOHERENT=y 315CONFIG_SH_PCIDMA_NONCOHERENT=y
313CONFIG_PCI_AUTO=y
314CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
315# CONFIG_PCIEPORTBUS is not set 316# CONFIG_PCIEPORTBUS is not set
316# CONFIG_ARCH_SUPPORTS_MSI is not set 317# CONFIG_ARCH_SUPPORTS_MSI is not set
317CONFIG_PCI_LEGACY=y 318CONFIG_PCI_LEGACY=y
@@ -672,6 +673,7 @@ CONFIG_NETDEV_1000=y
672# CONFIG_E1000E is not set 673# CONFIG_E1000E is not set
673# CONFIG_IP1000 is not set 674# CONFIG_IP1000 is not set
674# CONFIG_IGB is not set 675# CONFIG_IGB is not set
676# CONFIG_IGBVF is not set
675# CONFIG_NS83820 is not set 677# CONFIG_NS83820 is not set
676# CONFIG_HAMACHI is not set 678# CONFIG_HAMACHI is not set
677# CONFIG_YELLOWFIN is not set 679# CONFIG_YELLOWFIN is not set
@@ -1009,15 +1011,17 @@ CONFIG_USB_HID=y
1009# 1011#
1010# Special HID drivers 1012# Special HID drivers
1011# 1013#
1012CONFIG_HID_COMPAT=y
1013CONFIG_HID_A4TECH=y 1014CONFIG_HID_A4TECH=y
1014CONFIG_HID_APPLE=y 1015CONFIG_HID_APPLE=y
1015CONFIG_HID_BELKIN=y 1016CONFIG_HID_BELKIN=y
1016CONFIG_HID_CHERRY=y 1017CONFIG_HID_CHERRY=y
1017CONFIG_HID_CHICONY=y 1018CONFIG_HID_CHICONY=y
1018CONFIG_HID_CYPRESS=y 1019CONFIG_HID_CYPRESS=y
1020# CONFIG_DRAGONRISE_FF is not set
1019CONFIG_HID_EZKEY=y 1021CONFIG_HID_EZKEY=y
1022# CONFIG_HID_KYE is not set
1020CONFIG_HID_GYRATION=y 1023CONFIG_HID_GYRATION=y
1024# CONFIG_HID_KENSINGTON is not set
1021CONFIG_HID_LOGITECH=y 1025CONFIG_HID_LOGITECH=y
1022# CONFIG_LOGITECH_FF is not set 1026# CONFIG_LOGITECH_FF is not set
1023# CONFIG_LOGIRUMBLEPAD2_FF is not set 1027# CONFIG_LOGIRUMBLEPAD2_FF is not set
@@ -1218,6 +1222,7 @@ CONFIG_EXT2_FS=y
1218# CONFIG_EXT2_FS_XATTR is not set 1222# CONFIG_EXT2_FS_XATTR is not set
1219# CONFIG_EXT2_FS_XIP is not set 1223# CONFIG_EXT2_FS_XIP is not set
1220CONFIG_EXT3_FS=y 1224CONFIG_EXT3_FS=y
1225# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
1221CONFIG_EXT3_FS_XATTR=y 1226CONFIG_EXT3_FS_XATTR=y
1222# CONFIG_EXT3_FS_POSIX_ACL is not set 1227# CONFIG_EXT3_FS_POSIX_ACL is not set
1223# CONFIG_EXT3_FS_SECURITY is not set 1228# CONFIG_EXT3_FS_SECURITY is not set
@@ -1240,6 +1245,11 @@ CONFIG_INOTIFY_USER=y
1240# CONFIG_FUSE_FS is not set 1245# CONFIG_FUSE_FS is not set
1241 1246
1242# 1247#
1248# Caches
1249#
1250# CONFIG_FSCACHE is not set
1251
1252#
1243# CD-ROM/DVD Filesystems 1253# CD-ROM/DVD Filesystems
1244# 1254#
1245# CONFIG_ISO9660_FS is not set 1255# CONFIG_ISO9660_FS is not set
@@ -1289,6 +1299,7 @@ CONFIG_MINIX_FS=y
1289# CONFIG_ROMFS_FS is not set 1299# CONFIG_ROMFS_FS is not set
1290# CONFIG_SYSV_FS is not set 1300# CONFIG_SYSV_FS is not set
1291# CONFIG_UFS_FS is not set 1301# CONFIG_UFS_FS is not set
1302# CONFIG_NILFS2_FS is not set
1292CONFIG_NETWORK_FILESYSTEMS=y 1303CONFIG_NETWORK_FILESYSTEMS=y
1293CONFIG_NFS_FS=y 1304CONFIG_NFS_FS=y
1294CONFIG_NFS_V3=y 1305CONFIG_NFS_V3=y
@@ -1377,6 +1388,9 @@ CONFIG_DEBUG_KERNEL=y
1377CONFIG_DETECT_SOFTLOCKUP=y 1388CONFIG_DETECT_SOFTLOCKUP=y
1378# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set 1389# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
1379CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0 1390CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
1391CONFIG_DETECT_HUNG_TASK=y
1392# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
1393CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
1380CONFIG_SCHED_DEBUG=y 1394CONFIG_SCHED_DEBUG=y
1381# CONFIG_SCHEDSTATS is not set 1395# CONFIG_SCHEDSTATS is not set
1382# CONFIG_TIMER_STATS is not set 1396# CONFIG_TIMER_STATS is not set
@@ -1413,6 +1427,7 @@ CONFIG_SYSCTL_SYSCALL_CHECK=y
1413CONFIG_HAVE_FUNCTION_TRACER=y 1427CONFIG_HAVE_FUNCTION_TRACER=y
1414CONFIG_HAVE_DYNAMIC_FTRACE=y 1428CONFIG_HAVE_DYNAMIC_FTRACE=y
1415CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1429CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1430CONFIG_TRACING_SUPPORT=y
1416 1431
1417# 1432#
1418# Tracers 1433# Tracers
@@ -1422,9 +1437,14 @@ CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1422# CONFIG_PREEMPT_TRACER is not set 1437# CONFIG_PREEMPT_TRACER is not set
1423# CONFIG_SCHED_TRACER is not set 1438# CONFIG_SCHED_TRACER is not set
1424# CONFIG_CONTEXT_SWITCH_TRACER is not set 1439# CONFIG_CONTEXT_SWITCH_TRACER is not set
1440# CONFIG_EVENT_TRACER is not set
1425# CONFIG_BOOT_TRACER is not set 1441# CONFIG_BOOT_TRACER is not set
1426# CONFIG_TRACE_BRANCH_PROFILING is not set 1442# CONFIG_TRACE_BRANCH_PROFILING is not set
1427# CONFIG_STACK_TRACER is not set 1443# CONFIG_STACK_TRACER is not set
1444# CONFIG_KMEMTRACE is not set
1445# CONFIG_WORKQUEUE_TRACER is not set
1446# CONFIG_BLK_DEV_IO_TRACE is not set
1447# CONFIG_DMA_API_DEBUG is not set
1428# CONFIG_SAMPLES is not set 1448# CONFIG_SAMPLES is not set
1429CONFIG_HAVE_ARCH_KGDB=y 1449CONFIG_HAVE_ARCH_KGDB=y
1430# CONFIG_KGDB is not set 1450# CONFIG_KGDB is not set
@@ -1542,6 +1562,7 @@ CONFIG_CRYPTO_DES=y
1542# 1562#
1543# CONFIG_CRYPTO_ANSI_CPRNG is not set 1563# CONFIG_CRYPTO_ANSI_CPRNG is not set
1544# CONFIG_CRYPTO_HW is not set 1564# CONFIG_CRYPTO_HW is not set
1565# CONFIG_BINARY_PRINTF is not set
1545 1566
1546# 1567#
1547# Library routines 1568# Library routines
diff --git a/arch/sh/configs/sh7785lcr_defconfig b/arch/sh/configs/sh7785lcr_defconfig
index e4fac2efc055..4385fe97a780 100644
--- a/arch/sh/configs/sh7785lcr_defconfig
+++ b/arch/sh/configs/sh7785lcr_defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.30-rc2 3# Linux kernel version: 2.6.30-rc3
4# Wed Apr 22 19:17:56 2009 4# Mon Apr 27 13:11:48 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
@@ -307,8 +307,6 @@ CONFIG_BOOT_LINK_OFFSET=0x00800000
307# 307#
308CONFIG_PCI=y 308CONFIG_PCI=y
309CONFIG_SH_PCIDMA_NONCOHERENT=y 309CONFIG_SH_PCIDMA_NONCOHERENT=y
310CONFIG_PCI_AUTO=y
311CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
312# CONFIG_PCIEPORTBUS is not set 310# CONFIG_PCIEPORTBUS is not set
313# CONFIG_ARCH_SUPPORTS_MSI is not set 311# CONFIG_ARCH_SUPPORTS_MSI is not set
314CONFIG_PCI_LEGACY=y 312CONFIG_PCI_LEGACY=y
diff --git a/arch/sh/configs/shmin_defconfig b/arch/sh/configs/shmin_defconfig
index d695e9061874..4e120256ec63 100644
--- a/arch/sh/configs/shmin_defconfig
+++ b/arch/sh/configs/shmin_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 19:19:03 2009 4# Mon Apr 27 13:12:41 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_FIND_NEXT_BIT=y 11CONFIG_GENERIC_FIND_NEXT_BIT=y
@@ -63,6 +64,7 @@ CONFIG_EMBEDDED=y
63# CONFIG_UID16 is not set 64# CONFIG_UID16 is not set
64# CONFIG_SYSCTL_SYSCALL is not set 65# CONFIG_SYSCTL_SYSCALL is not set
65# CONFIG_KALLSYMS is not set 66# CONFIG_KALLSYMS is not set
67# CONFIG_STRIP_ASM_SYMS is not set
66# CONFIG_HOTPLUG is not set 68# CONFIG_HOTPLUG is not set
67CONFIG_PRINTK=y 69CONFIG_PRINTK=y
68# CONFIG_BUG is not set 70# CONFIG_BUG is not set
@@ -81,12 +83,15 @@ CONFIG_COMPAT_BRK=y
81# CONFIG_SLUB is not set 83# CONFIG_SLUB is not set
82CONFIG_SLOB=y 84CONFIG_SLOB=y
83# CONFIG_PROFILING is not set 85# CONFIG_PROFILING is not set
86# CONFIG_MARKERS is not set
84CONFIG_HAVE_OPROFILE=y 87CONFIG_HAVE_OPROFILE=y
85CONFIG_HAVE_IOREMAP_PROT=y 88CONFIG_HAVE_IOREMAP_PROT=y
86CONFIG_HAVE_KPROBES=y 89CONFIG_HAVE_KPROBES=y
87CONFIG_HAVE_KRETPROBES=y 90CONFIG_HAVE_KRETPROBES=y
88CONFIG_HAVE_ARCH_TRACEHOOK=y 91CONFIG_HAVE_ARCH_TRACEHOOK=y
89CONFIG_HAVE_CLK=y 92CONFIG_HAVE_CLK=y
93CONFIG_HAVE_DMA_API_DEBUG=y
94# CONFIG_SLOW_WORK is not set
90CONFIG_HAVE_GENERIC_DMA_COHERENT=y 95CONFIG_HAVE_GENERIC_DMA_COHERENT=y
91CONFIG_BASE_SMALL=1 96CONFIG_BASE_SMALL=1
92# CONFIG_MODULES is not set 97# CONFIG_MODULES is not set
@@ -137,6 +142,7 @@ CONFIG_CPU_SUBTYPE_SH7706=y
137# CONFIG_CPU_SUBTYPE_SH7760 is not set 142# CONFIG_CPU_SUBTYPE_SH7760 is not set
138# CONFIG_CPU_SUBTYPE_SH4_202 is not set 143# CONFIG_CPU_SUBTYPE_SH4_202 is not set
139# CONFIG_CPU_SUBTYPE_SH7723 is not set 144# CONFIG_CPU_SUBTYPE_SH7723 is not set
145# CONFIG_CPU_SUBTYPE_SH7724 is not set
140# CONFIG_CPU_SUBTYPE_SH7763 is not set 146# CONFIG_CPU_SUBTYPE_SH7763 is not set
141# CONFIG_CPU_SUBTYPE_SH7770 is not set 147# CONFIG_CPU_SUBTYPE_SH7770 is not set
142# CONFIG_CPU_SUBTYPE_SH7780 is not set 148# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -146,8 +152,6 @@ CONFIG_CPU_SUBTYPE_SH7706=y
146# CONFIG_CPU_SUBTYPE_SH7343 is not set 152# CONFIG_CPU_SUBTYPE_SH7343 is not set
147# CONFIG_CPU_SUBTYPE_SH7722 is not set 153# CONFIG_CPU_SUBTYPE_SH7722 is not set
148# CONFIG_CPU_SUBTYPE_SH7366 is not set 154# CONFIG_CPU_SUBTYPE_SH7366 is not set
149# CONFIG_CPU_SUBTYPE_SH5_101 is not set
150# CONFIG_CPU_SUBTYPE_SH5_103 is not set
151 155
152# 156#
153# Memory management options 157# Memory management options
@@ -675,6 +679,11 @@ CONFIG_FILE_LOCKING=y
675# CONFIG_FUSE_FS is not set 679# CONFIG_FUSE_FS is not set
676 680
677# 681#
682# Caches
683#
684# CONFIG_FSCACHE is not set
685
686#
678# CD-ROM/DVD Filesystems 687# CD-ROM/DVD Filesystems
679# 688#
680# CONFIG_ISO9660_FS is not set 689# CONFIG_ISO9660_FS is not set
@@ -718,6 +727,7 @@ CONFIG_CRAMFS=y
718# CONFIG_ROMFS_FS is not set 727# CONFIG_ROMFS_FS is not set
719# CONFIG_SYSV_FS is not set 728# CONFIG_SYSV_FS is not set
720# CONFIG_UFS_FS is not set 729# CONFIG_UFS_FS is not set
730# CONFIG_NILFS2_FS is not set
721CONFIG_NETWORK_FILESYSTEMS=y 731CONFIG_NETWORK_FILESYSTEMS=y
722CONFIG_NFS_FS=y 732CONFIG_NFS_FS=y
723CONFIG_NFS_V3=y 733CONFIG_NFS_V3=y
@@ -762,10 +772,22 @@ CONFIG_FRAME_WARN=1024
762CONFIG_HAVE_FUNCTION_TRACER=y 772CONFIG_HAVE_FUNCTION_TRACER=y
763CONFIG_HAVE_DYNAMIC_FTRACE=y 773CONFIG_HAVE_DYNAMIC_FTRACE=y
764CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 774CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
775CONFIG_TRACING_SUPPORT=y
765 776
766# 777#
767# Tracers 778# Tracers
768# 779#
780# CONFIG_FUNCTION_TRACER is not set
781# CONFIG_IRQSOFF_TRACER is not set
782# CONFIG_SCHED_TRACER is not set
783# CONFIG_CONTEXT_SWITCH_TRACER is not set
784# CONFIG_EVENT_TRACER is not set
785# CONFIG_BOOT_TRACER is not set
786# CONFIG_TRACE_BRANCH_PROFILING is not set
787# CONFIG_STACK_TRACER is not set
788# CONFIG_KMEMTRACE is not set
789# CONFIG_WORKQUEUE_TRACER is not set
790# CONFIG_DMA_API_DEBUG is not set
769# CONFIG_SAMPLES is not set 791# CONFIG_SAMPLES is not set
770CONFIG_HAVE_ARCH_KGDB=y 792CONFIG_HAVE_ARCH_KGDB=y
771CONFIG_SH_STANDARD_BIOS=y 793CONFIG_SH_STANDARD_BIOS=y
@@ -864,6 +886,7 @@ CONFIG_CRYPTO=y
864# 886#
865# CONFIG_CRYPTO_ANSI_CPRNG is not set 887# CONFIG_CRYPTO_ANSI_CPRNG is not set
866CONFIG_CRYPTO_HW=y 888CONFIG_CRYPTO_HW=y
889# CONFIG_BINARY_PRINTF is not set
867 890
868# 891#
869# Library routines 892# Library routines
diff --git a/arch/sh/configs/shx3_defconfig b/arch/sh/configs/shx3_defconfig
index e3651f574399..c088144925fa 100644
--- a/arch/sh/configs/shx3_defconfig
+++ b/arch/sh/configs/shx3_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 19:20:54 2009 4# Mon Apr 27 13:13:12 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -42,6 +43,7 @@ CONFIG_SWAP=y
42CONFIG_SYSVIPC=y 43CONFIG_SYSVIPC=y
43CONFIG_SYSVIPC_SYSCTL=y 44CONFIG_SYSVIPC_SYSCTL=y
44CONFIG_POSIX_MQUEUE=y 45CONFIG_POSIX_MQUEUE=y
46CONFIG_POSIX_MQUEUE_SYSCTL=y
45CONFIG_BSD_PROCESS_ACCT=y 47CONFIG_BSD_PROCESS_ACCT=y
46# CONFIG_BSD_PROCESS_ACCT_V3 is not set 48# CONFIG_BSD_PROCESS_ACCT_V3 is not set
47# CONFIG_TASKSTATS is not set 49# CONFIG_TASKSTATS is not set
@@ -96,6 +98,7 @@ CONFIG_SYSCTL_SYSCALL=y
96CONFIG_KALLSYMS=y 98CONFIG_KALLSYMS=y
97CONFIG_KALLSYMS_ALL=y 99CONFIG_KALLSYMS_ALL=y
98# CONFIG_KALLSYMS_EXTRA_PASS is not set 100# CONFIG_KALLSYMS_EXTRA_PASS is not set
101# CONFIG_STRIP_ASM_SYMS is not set
99CONFIG_HOTPLUG=y 102CONFIG_HOTPLUG=y
100CONFIG_PRINTK=y 103CONFIG_PRINTK=y
101CONFIG_BUG=y 104CONFIG_BUG=y
@@ -126,6 +129,8 @@ CONFIG_HAVE_KRETPROBES=y
126CONFIG_HAVE_ARCH_TRACEHOOK=y 129CONFIG_HAVE_ARCH_TRACEHOOK=y
127CONFIG_USE_GENERIC_SMP_HELPERS=y 130CONFIG_USE_GENERIC_SMP_HELPERS=y
128CONFIG_HAVE_CLK=y 131CONFIG_HAVE_CLK=y
132CONFIG_HAVE_DMA_API_DEBUG=y
133# CONFIG_SLOW_WORK is not set
129CONFIG_HAVE_GENERIC_DMA_COHERENT=y 134CONFIG_HAVE_GENERIC_DMA_COHERENT=y
130CONFIG_RT_MUTEXES=y 135CONFIG_RT_MUTEXES=y
131CONFIG_BASE_SMALL=0 136CONFIG_BASE_SMALL=0
@@ -138,7 +143,6 @@ CONFIG_MODULE_UNLOAD=y
138CONFIG_STOP_MACHINE=y 143CONFIG_STOP_MACHINE=y
139CONFIG_BLOCK=y 144CONFIG_BLOCK=y
140# CONFIG_LBD is not set 145# CONFIG_LBD is not set
141# CONFIG_BLK_DEV_IO_TRACE is not set
142# CONFIG_BLK_DEV_BSG is not set 146# CONFIG_BLK_DEV_BSG is not set
143# CONFIG_BLK_DEV_INTEGRITY is not set 147# CONFIG_BLK_DEV_INTEGRITY is not set
144 148
@@ -186,6 +190,7 @@ CONFIG_CPU_SHX3=y
186# CONFIG_CPU_SUBTYPE_SH7760 is not set 190# CONFIG_CPU_SUBTYPE_SH7760 is not set
187# CONFIG_CPU_SUBTYPE_SH4_202 is not set 191# CONFIG_CPU_SUBTYPE_SH4_202 is not set
188# CONFIG_CPU_SUBTYPE_SH7723 is not set 192# CONFIG_CPU_SUBTYPE_SH7723 is not set
193# CONFIG_CPU_SUBTYPE_SH7724 is not set
189# CONFIG_CPU_SUBTYPE_SH7763 is not set 194# CONFIG_CPU_SUBTYPE_SH7763 is not set
190# CONFIG_CPU_SUBTYPE_SH7770 is not set 195# CONFIG_CPU_SUBTYPE_SH7770 is not set
191# CONFIG_CPU_SUBTYPE_SH7780 is not set 196# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -195,8 +200,6 @@ CONFIG_CPU_SUBTYPE_SHX3=y
195# CONFIG_CPU_SUBTYPE_SH7343 is not set 200# CONFIG_CPU_SUBTYPE_SH7343 is not set
196# CONFIG_CPU_SUBTYPE_SH7722 is not set 201# CONFIG_CPU_SUBTYPE_SH7722 is not set
197# CONFIG_CPU_SUBTYPE_SH7366 is not set 202# CONFIG_CPU_SUBTYPE_SH7366 is not set
198# CONFIG_CPU_SUBTYPE_SH5_101 is not set
199# CONFIG_CPU_SUBTYPE_SH5_103 is not set
200 203
201# 204#
202# Memory management options 205# Memory management options
@@ -553,6 +556,7 @@ CONFIG_SCSI_WAIT_SCAN=m
553CONFIG_SCSI_LOWLEVEL=y 556CONFIG_SCSI_LOWLEVEL=y
554# CONFIG_ISCSI_TCP is not set 557# CONFIG_ISCSI_TCP is not set
555# CONFIG_LIBFC is not set 558# CONFIG_LIBFC is not set
559# CONFIG_LIBFCOE is not set
556# CONFIG_SCSI_DEBUG is not set 560# CONFIG_SCSI_DEBUG is not set
557# CONFIG_SCSI_DH is not set 561# CONFIG_SCSI_DH is not set
558# CONFIG_SCSI_OSD_INITIATOR is not set 562# CONFIG_SCSI_OSD_INITIATOR is not set
@@ -646,6 +650,7 @@ CONFIG_DEVKMEM=y
646# 650#
647# Non-8250 serial port support 651# Non-8250 serial port support
648# 652#
653# CONFIG_SERIAL_MAX3100 is not set
649CONFIG_SERIAL_SH_SCI=y 654CONFIG_SERIAL_SH_SCI=y
650CONFIG_SERIAL_SH_SCI_NR_UARTS=2 655CONFIG_SERIAL_SH_SCI_NR_UARTS=2
651CONFIG_SERIAL_SH_SCI_CONSOLE=y 656CONFIG_SERIAL_SH_SCI_CONSOLE=y
@@ -985,6 +990,7 @@ CONFIG_EXT2_FS=y
985# CONFIG_EXT2_FS_XATTR is not set 990# CONFIG_EXT2_FS_XATTR is not set
986# CONFIG_EXT2_FS_XIP is not set 991# CONFIG_EXT2_FS_XIP is not set
987CONFIG_EXT3_FS=y 992CONFIG_EXT3_FS=y
993# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
988CONFIG_EXT3_FS_XATTR=y 994CONFIG_EXT3_FS_XATTR=y
989# CONFIG_EXT3_FS_POSIX_ACL is not set 995# CONFIG_EXT3_FS_POSIX_ACL is not set
990# CONFIG_EXT3_FS_SECURITY is not set 996# CONFIG_EXT3_FS_SECURITY is not set
@@ -1008,6 +1014,11 @@ CONFIG_INOTIFY_USER=y
1008# CONFIG_FUSE_FS is not set 1014# CONFIG_FUSE_FS is not set
1009 1015
1010# 1016#
1017# Caches
1018#
1019# CONFIG_FSCACHE is not set
1020
1021#
1011# CD-ROM/DVD Filesystems 1022# CD-ROM/DVD Filesystems
1012# 1023#
1013# CONFIG_ISO9660_FS is not set 1024# CONFIG_ISO9660_FS is not set
@@ -1051,6 +1062,7 @@ CONFIG_MISC_FILESYSTEMS=y
1051# CONFIG_ROMFS_FS is not set 1062# CONFIG_ROMFS_FS is not set
1052# CONFIG_SYSV_FS is not set 1063# CONFIG_SYSV_FS is not set
1053# CONFIG_UFS_FS is not set 1064# CONFIG_UFS_FS is not set
1065# CONFIG_NILFS2_FS is not set
1054CONFIG_NETWORK_FILESYSTEMS=y 1066CONFIG_NETWORK_FILESYSTEMS=y
1055# CONFIG_NFS_FS is not set 1067# CONFIG_NFS_FS is not set
1056# CONFIG_NFSD is not set 1068# CONFIG_NFSD is not set
@@ -1085,6 +1097,9 @@ CONFIG_DEBUG_SHIRQ=y
1085CONFIG_DETECT_SOFTLOCKUP=y 1097CONFIG_DETECT_SOFTLOCKUP=y
1086# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set 1098# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
1087CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0 1099CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
1100CONFIG_DETECT_HUNG_TASK=y
1101# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set
1102CONFIG_BOOTPARAM_HUNG_TASK_PANIC_VALUE=0
1088CONFIG_SCHED_DEBUG=y 1103CONFIG_SCHED_DEBUG=y
1089# CONFIG_SCHEDSTATS is not set 1104# CONFIG_SCHEDSTATS is not set
1090# CONFIG_TIMER_STATS is not set 1105# CONFIG_TIMER_STATS is not set
@@ -1124,6 +1139,7 @@ CONFIG_HAVE_DYNAMIC_FTRACE=y
1124CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1139CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1125CONFIG_RING_BUFFER=y 1140CONFIG_RING_BUFFER=y
1126CONFIG_TRACING=y 1141CONFIG_TRACING=y
1142CONFIG_TRACING_SUPPORT=y
1127 1143
1128# 1144#
1129# Tracers 1145# Tracers
@@ -1133,11 +1149,16 @@ CONFIG_TRACING=y
1133# CONFIG_PREEMPT_TRACER is not set 1149# CONFIG_PREEMPT_TRACER is not set
1134# CONFIG_SCHED_TRACER is not set 1150# CONFIG_SCHED_TRACER is not set
1135# CONFIG_CONTEXT_SWITCH_TRACER is not set 1151# CONFIG_CONTEXT_SWITCH_TRACER is not set
1152# CONFIG_EVENT_TRACER is not set
1136# CONFIG_BOOT_TRACER is not set 1153# CONFIG_BOOT_TRACER is not set
1137# CONFIG_TRACE_BRANCH_PROFILING is not set 1154# CONFIG_TRACE_BRANCH_PROFILING is not set
1138# CONFIG_STACK_TRACER is not set 1155# CONFIG_STACK_TRACER is not set
1156# CONFIG_KMEMTRACE is not set
1157# CONFIG_WORKQUEUE_TRACER is not set
1158# CONFIG_BLK_DEV_IO_TRACE is not set
1139# CONFIG_FTRACE_STARTUP_TEST is not set 1159# CONFIG_FTRACE_STARTUP_TEST is not set
1140# CONFIG_DYNAMIC_DEBUG is not set 1160# CONFIG_DYNAMIC_DEBUG is not set
1161# CONFIG_DMA_API_DEBUG is not set
1141# CONFIG_SAMPLES is not set 1162# CONFIG_SAMPLES is not set
1142CONFIG_HAVE_ARCH_KGDB=y 1163CONFIG_HAVE_ARCH_KGDB=y
1143# CONFIG_KGDB is not set 1164# CONFIG_KGDB is not set
@@ -1245,6 +1266,7 @@ CONFIG_CRYPTO=y
1245# 1266#
1246# CONFIG_CRYPTO_ANSI_CPRNG is not set 1267# CONFIG_CRYPTO_ANSI_CPRNG is not set
1247CONFIG_CRYPTO_HW=y 1268CONFIG_CRYPTO_HW=y
1269CONFIG_BINARY_PRINTF=y
1248 1270
1249# 1271#
1250# Library routines 1272# Library routines
diff --git a/arch/sh/configs/snapgear_defconfig b/arch/sh/configs/snapgear_defconfig
index 6960f60bf52e..54a7a3c41f34 100644
--- a/arch/sh/configs/snapgear_defconfig
+++ b/arch/sh/configs/snapgear_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 19:21:39 2009 4# Mon Apr 27 13:14:00 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -64,7 +65,6 @@ CONFIG_INITRAMFS_SOURCE=""
64CONFIG_RD_GZIP=y 65CONFIG_RD_GZIP=y
65# CONFIG_RD_BZIP2 is not set 66# CONFIG_RD_BZIP2 is not set
66# CONFIG_RD_LZMA is not set 67# CONFIG_RD_LZMA is not set
67CONFIG_INITRAMFS_COMPRESSION_NONE=y
68CONFIG_CC_OPTIMIZE_FOR_SIZE=y 68CONFIG_CC_OPTIMIZE_FOR_SIZE=y
69CONFIG_SYSCTL=y 69CONFIG_SYSCTL=y
70CONFIG_ANON_INODES=y 70CONFIG_ANON_INODES=y
@@ -73,6 +73,7 @@ CONFIG_UID16=y
73# CONFIG_SYSCTL_SYSCALL is not set 73# CONFIG_SYSCTL_SYSCALL is not set
74CONFIG_KALLSYMS=y 74CONFIG_KALLSYMS=y
75# CONFIG_KALLSYMS_EXTRA_PASS is not set 75# CONFIG_KALLSYMS_EXTRA_PASS is not set
76# CONFIG_STRIP_ASM_SYMS is not set
76# CONFIG_HOTPLUG is not set 77# CONFIG_HOTPLUG is not set
77CONFIG_PRINTK=y 78CONFIG_PRINTK=y
78CONFIG_BUG=y 79CONFIG_BUG=y
@@ -92,12 +93,15 @@ CONFIG_SLAB=y
92# CONFIG_SLUB is not set 93# CONFIG_SLUB is not set
93# CONFIG_SLOB is not set 94# CONFIG_SLOB is not set
94# CONFIG_PROFILING is not set 95# CONFIG_PROFILING is not set
96# CONFIG_MARKERS is not set
95CONFIG_HAVE_OPROFILE=y 97CONFIG_HAVE_OPROFILE=y
96CONFIG_HAVE_IOREMAP_PROT=y 98CONFIG_HAVE_IOREMAP_PROT=y
97CONFIG_HAVE_KPROBES=y 99CONFIG_HAVE_KPROBES=y
98CONFIG_HAVE_KRETPROBES=y 100CONFIG_HAVE_KRETPROBES=y
99CONFIG_HAVE_ARCH_TRACEHOOK=y 101CONFIG_HAVE_ARCH_TRACEHOOK=y
100CONFIG_HAVE_CLK=y 102CONFIG_HAVE_CLK=y
103CONFIG_HAVE_DMA_API_DEBUG=y
104# CONFIG_SLOW_WORK is not set
101CONFIG_HAVE_GENERIC_DMA_COHERENT=y 105CONFIG_HAVE_GENERIC_DMA_COHERENT=y
102CONFIG_SLABINFO=y 106CONFIG_SLABINFO=y
103CONFIG_RT_MUTEXES=y 107CONFIG_RT_MUTEXES=y
@@ -105,7 +109,6 @@ CONFIG_BASE_SMALL=0
105# CONFIG_MODULES is not set 109# CONFIG_MODULES is not set
106CONFIG_BLOCK=y 110CONFIG_BLOCK=y
107# CONFIG_LBD is not set 111# CONFIG_LBD is not set
108# CONFIG_BLK_DEV_IO_TRACE is not set
109# CONFIG_BLK_DEV_BSG is not set 112# CONFIG_BLK_DEV_BSG is not set
110# CONFIG_BLK_DEV_INTEGRITY is not set 113# CONFIG_BLK_DEV_INTEGRITY is not set
111 114
@@ -151,6 +154,7 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
151# CONFIG_CPU_SUBTYPE_SH7760 is not set 154# CONFIG_CPU_SUBTYPE_SH7760 is not set
152# CONFIG_CPU_SUBTYPE_SH4_202 is not set 155# CONFIG_CPU_SUBTYPE_SH4_202 is not set
153# CONFIG_CPU_SUBTYPE_SH7723 is not set 156# CONFIG_CPU_SUBTYPE_SH7723 is not set
157# CONFIG_CPU_SUBTYPE_SH7724 is not set
154# CONFIG_CPU_SUBTYPE_SH7763 is not set 158# CONFIG_CPU_SUBTYPE_SH7763 is not set
155# CONFIG_CPU_SUBTYPE_SH7770 is not set 159# CONFIG_CPU_SUBTYPE_SH7770 is not set
156# CONFIG_CPU_SUBTYPE_SH7780 is not set 160# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -160,8 +164,6 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
160# CONFIG_CPU_SUBTYPE_SH7343 is not set 164# CONFIG_CPU_SUBTYPE_SH7343 is not set
161# CONFIG_CPU_SUBTYPE_SH7722 is not set 165# CONFIG_CPU_SUBTYPE_SH7722 is not set
162# CONFIG_CPU_SUBTYPE_SH7366 is not set 166# CONFIG_CPU_SUBTYPE_SH7366 is not set
163# CONFIG_CPU_SUBTYPE_SH5_101 is not set
164# CONFIG_CPU_SUBTYPE_SH5_103 is not set
165 167
166# 168#
167# Memory management options 169# Memory management options
@@ -295,8 +297,6 @@ CONFIG_BOOT_LINK_OFFSET=0x00800000
295# 297#
296CONFIG_PCI=y 298CONFIG_PCI=y
297CONFIG_SH_PCIDMA_NONCOHERENT=y 299CONFIG_SH_PCIDMA_NONCOHERENT=y
298CONFIG_PCI_AUTO=y
299CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
300# CONFIG_PCIEPORTBUS is not set 300# CONFIG_PCIEPORTBUS is not set
301# CONFIG_ARCH_SUPPORTS_MSI is not set 301# CONFIG_ARCH_SUPPORTS_MSI is not set
302CONFIG_PCI_LEGACY=y 302CONFIG_PCI_LEGACY=y
@@ -763,6 +763,11 @@ CONFIG_FILE_LOCKING=y
763# CONFIG_FUSE_FS is not set 763# CONFIG_FUSE_FS is not set
764 764
765# 765#
766# Caches
767#
768# CONFIG_FSCACHE is not set
769
770#
766# CD-ROM/DVD Filesystems 771# CD-ROM/DVD Filesystems
767# 772#
768# CONFIG_ISO9660_FS is not set 773# CONFIG_ISO9660_FS is not set
@@ -805,8 +810,13 @@ CONFIG_CRAMFS=y
805# CONFIG_HPFS_FS is not set 810# CONFIG_HPFS_FS is not set
806# CONFIG_QNX4FS_FS is not set 811# CONFIG_QNX4FS_FS is not set
807CONFIG_ROMFS_FS=y 812CONFIG_ROMFS_FS=y
813CONFIG_ROMFS_BACKED_BY_BLOCK=y
814# CONFIG_ROMFS_BACKED_BY_MTD is not set
815# CONFIG_ROMFS_BACKED_BY_BOTH is not set
816CONFIG_ROMFS_ON_BLOCK=y
808# CONFIG_SYSV_FS is not set 817# CONFIG_SYSV_FS is not set
809# CONFIG_UFS_FS is not set 818# CONFIG_UFS_FS is not set
819# CONFIG_NILFS2_FS is not set
810CONFIG_NETWORK_FILESYSTEMS=y 820CONFIG_NETWORK_FILESYSTEMS=y
811# CONFIG_NFS_FS is not set 821# CONFIG_NFS_FS is not set
812# CONFIG_NFSD is not set 822# CONFIG_NFSD is not set
@@ -844,10 +854,23 @@ CONFIG_FRAME_WARN=1024
844CONFIG_HAVE_FUNCTION_TRACER=y 854CONFIG_HAVE_FUNCTION_TRACER=y
845CONFIG_HAVE_DYNAMIC_FTRACE=y 855CONFIG_HAVE_DYNAMIC_FTRACE=y
846CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 856CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
857CONFIG_TRACING_SUPPORT=y
847 858
848# 859#
849# Tracers 860# Tracers
850# 861#
862# CONFIG_FUNCTION_TRACER is not set
863# CONFIG_IRQSOFF_TRACER is not set
864# CONFIG_SCHED_TRACER is not set
865# CONFIG_CONTEXT_SWITCH_TRACER is not set
866# CONFIG_EVENT_TRACER is not set
867# CONFIG_BOOT_TRACER is not set
868# CONFIG_TRACE_BRANCH_PROFILING is not set
869# CONFIG_STACK_TRACER is not set
870# CONFIG_KMEMTRACE is not set
871# CONFIG_WORKQUEUE_TRACER is not set
872# CONFIG_BLK_DEV_IO_TRACE is not set
873# CONFIG_DMA_API_DEBUG is not set
851# CONFIG_SAMPLES is not set 874# CONFIG_SAMPLES is not set
852CONFIG_HAVE_ARCH_KGDB=y 875CONFIG_HAVE_ARCH_KGDB=y
853# CONFIG_SH_STANDARD_BIOS is not set 876# CONFIG_SH_STANDARD_BIOS is not set
@@ -862,6 +885,7 @@ CONFIG_HAVE_ARCH_KGDB=y
862# CONFIG_SECURITYFS is not set 885# CONFIG_SECURITYFS is not set
863# CONFIG_SECURITY_FILE_CAPABILITIES is not set 886# CONFIG_SECURITY_FILE_CAPABILITIES is not set
864# CONFIG_CRYPTO is not set 887# CONFIG_CRYPTO is not set
888# CONFIG_BINARY_PRINTF is not set
865 889
866# 890#
867# Library routines 891# Library routines
diff --git a/arch/sh/configs/systemh_defconfig b/arch/sh/configs/systemh_defconfig
index 7ea639bc5936..dbe7e546f0bb 100644
--- a/arch/sh/configs/systemh_defconfig
+++ b/arch/sh/configs/systemh_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 19:23:31 2009 4# Mon Apr 27 13:14:33 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -61,7 +62,6 @@ CONFIG_INITRAMFS_SOURCE=""
61CONFIG_RD_GZIP=y 62CONFIG_RD_GZIP=y
62# CONFIG_RD_BZIP2 is not set 63# CONFIG_RD_BZIP2 is not set
63# CONFIG_RD_LZMA is not set 64# CONFIG_RD_LZMA is not set
64CONFIG_INITRAMFS_COMPRESSION_NONE=y
65# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set 65# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
66CONFIG_SYSCTL=y 66CONFIG_SYSCTL=y
67CONFIG_ANON_INODES=y 67CONFIG_ANON_INODES=y
@@ -70,6 +70,7 @@ CONFIG_UID16=y
70# CONFIG_SYSCTL_SYSCALL is not set 70# CONFIG_SYSCTL_SYSCALL is not set
71CONFIG_KALLSYMS=y 71CONFIG_KALLSYMS=y
72# CONFIG_KALLSYMS_EXTRA_PASS is not set 72# CONFIG_KALLSYMS_EXTRA_PASS is not set
73# CONFIG_STRIP_ASM_SYMS is not set
73# CONFIG_HOTPLUG is not set 74# CONFIG_HOTPLUG is not set
74CONFIG_PRINTK=y 75CONFIG_PRINTK=y
75CONFIG_BUG=y 76CONFIG_BUG=y
@@ -88,6 +89,7 @@ CONFIG_SLAB=y
88# CONFIG_SLUB is not set 89# CONFIG_SLUB is not set
89# CONFIG_SLOB is not set 90# CONFIG_SLOB is not set
90# CONFIG_PROFILING is not set 91# CONFIG_PROFILING is not set
92# CONFIG_MARKERS is not set
91CONFIG_HAVE_OPROFILE=y 93CONFIG_HAVE_OPROFILE=y
92# CONFIG_KPROBES is not set 94# CONFIG_KPROBES is not set
93CONFIG_HAVE_IOREMAP_PROT=y 95CONFIG_HAVE_IOREMAP_PROT=y
@@ -95,6 +97,8 @@ CONFIG_HAVE_KPROBES=y
95CONFIG_HAVE_KRETPROBES=y 97CONFIG_HAVE_KRETPROBES=y
96CONFIG_HAVE_ARCH_TRACEHOOK=y 98CONFIG_HAVE_ARCH_TRACEHOOK=y
97CONFIG_HAVE_CLK=y 99CONFIG_HAVE_CLK=y
100CONFIG_HAVE_DMA_API_DEBUG=y
101# CONFIG_SLOW_WORK is not set
98CONFIG_HAVE_GENERIC_DMA_COHERENT=y 102CONFIG_HAVE_GENERIC_DMA_COHERENT=y
99CONFIG_SLABINFO=y 103CONFIG_SLABINFO=y
100CONFIG_RT_MUTEXES=y 104CONFIG_RT_MUTEXES=y
@@ -107,7 +111,6 @@ CONFIG_MODULE_UNLOAD=y
107# CONFIG_MODULE_SRCVERSION_ALL is not set 111# CONFIG_MODULE_SRCVERSION_ALL is not set
108CONFIG_BLOCK=y 112CONFIG_BLOCK=y
109# CONFIG_LBD is not set 113# CONFIG_LBD is not set
110# CONFIG_BLK_DEV_IO_TRACE is not set
111# CONFIG_BLK_DEV_BSG is not set 114# CONFIG_BLK_DEV_BSG is not set
112# CONFIG_BLK_DEV_INTEGRITY is not set 115# CONFIG_BLK_DEV_INTEGRITY is not set
113 116
@@ -153,6 +156,7 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
153# CONFIG_CPU_SUBTYPE_SH7760 is not set 156# CONFIG_CPU_SUBTYPE_SH7760 is not set
154# CONFIG_CPU_SUBTYPE_SH4_202 is not set 157# CONFIG_CPU_SUBTYPE_SH4_202 is not set
155# CONFIG_CPU_SUBTYPE_SH7723 is not set 158# CONFIG_CPU_SUBTYPE_SH7723 is not set
159# CONFIG_CPU_SUBTYPE_SH7724 is not set
156# CONFIG_CPU_SUBTYPE_SH7763 is not set 160# CONFIG_CPU_SUBTYPE_SH7763 is not set
157# CONFIG_CPU_SUBTYPE_SH7770 is not set 161# CONFIG_CPU_SUBTYPE_SH7770 is not set
158# CONFIG_CPU_SUBTYPE_SH7780 is not set 162# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -162,8 +166,6 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
162# CONFIG_CPU_SUBTYPE_SH7343 is not set 166# CONFIG_CPU_SUBTYPE_SH7343 is not set
163# CONFIG_CPU_SUBTYPE_SH7722 is not set 167# CONFIG_CPU_SUBTYPE_SH7722 is not set
164# CONFIG_CPU_SUBTYPE_SH7366 is not set 168# CONFIG_CPU_SUBTYPE_SH7366 is not set
165# CONFIG_CPU_SUBTYPE_SH5_101 is not set
166# CONFIG_CPU_SUBTYPE_SH5_103 is not set
167 169
168# 170#
169# Memory management options 171# Memory management options
@@ -506,6 +508,11 @@ CONFIG_INOTIFY_USER=y
506# CONFIG_FUSE_FS is not set 508# CONFIG_FUSE_FS is not set
507 509
508# 510#
511# Caches
512#
513# CONFIG_FSCACHE is not set
514
515#
509# CD-ROM/DVD Filesystems 516# CD-ROM/DVD Filesystems
510# 517#
511# CONFIG_ISO9660_FS is not set 518# CONFIG_ISO9660_FS is not set
@@ -547,8 +554,13 @@ CONFIG_CRAMFS=y
547# CONFIG_HPFS_FS is not set 554# CONFIG_HPFS_FS is not set
548# CONFIG_QNX4FS_FS is not set 555# CONFIG_QNX4FS_FS is not set
549CONFIG_ROMFS_FS=y 556CONFIG_ROMFS_FS=y
557CONFIG_ROMFS_BACKED_BY_BLOCK=y
558# CONFIG_ROMFS_BACKED_BY_MTD is not set
559# CONFIG_ROMFS_BACKED_BY_BOTH is not set
560CONFIG_ROMFS_ON_BLOCK=y
550# CONFIG_SYSV_FS is not set 561# CONFIG_SYSV_FS is not set
551# CONFIG_UFS_FS is not set 562# CONFIG_UFS_FS is not set
563# CONFIG_NILFS2_FS is not set
552 564
553# 565#
554# Partition Types 566# Partition Types
@@ -577,10 +589,24 @@ CONFIG_FRAME_WARN=1024
577CONFIG_HAVE_FUNCTION_TRACER=y 589CONFIG_HAVE_FUNCTION_TRACER=y
578CONFIG_HAVE_DYNAMIC_FTRACE=y 590CONFIG_HAVE_DYNAMIC_FTRACE=y
579CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 591CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
592CONFIG_TRACING_SUPPORT=y
580 593
581# 594#
582# Tracers 595# Tracers
583# 596#
597# CONFIG_FUNCTION_TRACER is not set
598# CONFIG_IRQSOFF_TRACER is not set
599# CONFIG_PREEMPT_TRACER is not set
600# CONFIG_SCHED_TRACER is not set
601# CONFIG_CONTEXT_SWITCH_TRACER is not set
602# CONFIG_EVENT_TRACER is not set
603# CONFIG_BOOT_TRACER is not set
604# CONFIG_TRACE_BRANCH_PROFILING is not set
605# CONFIG_STACK_TRACER is not set
606# CONFIG_KMEMTRACE is not set
607# CONFIG_WORKQUEUE_TRACER is not set
608# CONFIG_BLK_DEV_IO_TRACE is not set
609# CONFIG_DMA_API_DEBUG is not set
584# CONFIG_SAMPLES is not set 610# CONFIG_SAMPLES is not set
585CONFIG_HAVE_ARCH_KGDB=y 611CONFIG_HAVE_ARCH_KGDB=y
586# CONFIG_SH_STANDARD_BIOS is not set 612# CONFIG_SH_STANDARD_BIOS is not set
@@ -595,6 +621,7 @@ CONFIG_HAVE_ARCH_KGDB=y
595# CONFIG_SECURITYFS is not set 621# CONFIG_SECURITYFS is not set
596# CONFIG_SECURITY_FILE_CAPABILITIES is not set 622# CONFIG_SECURITY_FILE_CAPABILITIES is not set
597# CONFIG_CRYPTO is not set 623# CONFIG_CRYPTO is not set
624# CONFIG_BINARY_PRINTF is not set
598 625
599# 626#
600# Library routines 627# Library routines
diff --git a/arch/sh/configs/titan_defconfig b/arch/sh/configs/titan_defconfig
index bbeb4c6ebb95..8ca94ef74278 100644
--- a/arch/sh/configs/titan_defconfig
+++ b/arch/sh/configs/titan_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 19:24:55 2009 4# Mon Apr 27 13:14:55 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -40,6 +41,7 @@ CONFIG_SWAP=y
40CONFIG_SYSVIPC=y 41CONFIG_SYSVIPC=y
41CONFIG_SYSVIPC_SYSCTL=y 42CONFIG_SYSVIPC_SYSCTL=y
42CONFIG_POSIX_MQUEUE=y 43CONFIG_POSIX_MQUEUE=y
44CONFIG_POSIX_MQUEUE_SYSCTL=y
43# CONFIG_BSD_PROCESS_ACCT is not set 45# CONFIG_BSD_PROCESS_ACCT is not set
44# CONFIG_TASKSTATS is not set 46# CONFIG_TASKSTATS is not set
45# CONFIG_AUDIT is not set 47# CONFIG_AUDIT is not set
@@ -66,7 +68,6 @@ CONFIG_INITRAMFS_SOURCE=""
66CONFIG_RD_GZIP=y 68CONFIG_RD_GZIP=y
67# CONFIG_RD_BZIP2 is not set 69# CONFIG_RD_BZIP2 is not set
68# CONFIG_RD_LZMA is not set 70# CONFIG_RD_LZMA is not set
69CONFIG_INITRAMFS_COMPRESSION_NONE=y
70# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set 71# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
71CONFIG_SYSCTL=y 72CONFIG_SYSCTL=y
72CONFIG_ANON_INODES=y 73CONFIG_ANON_INODES=y
@@ -76,6 +77,7 @@ CONFIG_UID16=y
76CONFIG_KALLSYMS=y 77CONFIG_KALLSYMS=y
77# CONFIG_KALLSYMS_ALL is not set 78# CONFIG_KALLSYMS_ALL is not set
78# CONFIG_KALLSYMS_EXTRA_PASS is not set 79# CONFIG_KALLSYMS_EXTRA_PASS is not set
80# CONFIG_STRIP_ASM_SYMS is not set
79CONFIG_HOTPLUG=y 81CONFIG_HOTPLUG=y
80CONFIG_PRINTK=y 82CONFIG_PRINTK=y
81CONFIG_BUG=y 83CONFIG_BUG=y
@@ -95,6 +97,7 @@ CONFIG_SLAB=y
95# CONFIG_SLUB is not set 97# CONFIG_SLUB is not set
96# CONFIG_SLOB is not set 98# CONFIG_SLOB is not set
97# CONFIG_PROFILING is not set 99# CONFIG_PROFILING is not set
100# CONFIG_MARKERS is not set
98CONFIG_HAVE_OPROFILE=y 101CONFIG_HAVE_OPROFILE=y
99# CONFIG_KPROBES is not set 102# CONFIG_KPROBES is not set
100CONFIG_HAVE_IOREMAP_PROT=y 103CONFIG_HAVE_IOREMAP_PROT=y
@@ -102,6 +105,8 @@ CONFIG_HAVE_KPROBES=y
102CONFIG_HAVE_KRETPROBES=y 105CONFIG_HAVE_KRETPROBES=y
103CONFIG_HAVE_ARCH_TRACEHOOK=y 106CONFIG_HAVE_ARCH_TRACEHOOK=y
104CONFIG_HAVE_CLK=y 107CONFIG_HAVE_CLK=y
108CONFIG_HAVE_DMA_API_DEBUG=y
109# CONFIG_SLOW_WORK is not set
105CONFIG_HAVE_GENERIC_DMA_COHERENT=y 110CONFIG_HAVE_GENERIC_DMA_COHERENT=y
106CONFIG_SLABINFO=y 111CONFIG_SLABINFO=y
107CONFIG_RT_MUTEXES=y 112CONFIG_RT_MUTEXES=y
@@ -114,7 +119,6 @@ CONFIG_MODULE_FORCE_UNLOAD=y
114# CONFIG_MODULE_SRCVERSION_ALL is not set 119# CONFIG_MODULE_SRCVERSION_ALL is not set
115CONFIG_BLOCK=y 120CONFIG_BLOCK=y
116# CONFIG_LBD is not set 121# CONFIG_LBD is not set
117# CONFIG_BLK_DEV_IO_TRACE is not set
118# CONFIG_BLK_DEV_BSG is not set 122# CONFIG_BLK_DEV_BSG is not set
119# CONFIG_BLK_DEV_INTEGRITY is not set 123# CONFIG_BLK_DEV_INTEGRITY is not set
120 124
@@ -160,6 +164,7 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
160# CONFIG_CPU_SUBTYPE_SH7760 is not set 164# CONFIG_CPU_SUBTYPE_SH7760 is not set
161# CONFIG_CPU_SUBTYPE_SH4_202 is not set 165# CONFIG_CPU_SUBTYPE_SH4_202 is not set
162# CONFIG_CPU_SUBTYPE_SH7723 is not set 166# CONFIG_CPU_SUBTYPE_SH7723 is not set
167# CONFIG_CPU_SUBTYPE_SH7724 is not set
163# CONFIG_CPU_SUBTYPE_SH7763 is not set 168# CONFIG_CPU_SUBTYPE_SH7763 is not set
164# CONFIG_CPU_SUBTYPE_SH7770 is not set 169# CONFIG_CPU_SUBTYPE_SH7770 is not set
165# CONFIG_CPU_SUBTYPE_SH7780 is not set 170# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -169,8 +174,6 @@ CONFIG_CPU_SUBTYPE_SH7751R=y
169# CONFIG_CPU_SUBTYPE_SH7343 is not set 174# CONFIG_CPU_SUBTYPE_SH7343 is not set
170# CONFIG_CPU_SUBTYPE_SH7722 is not set 175# CONFIG_CPU_SUBTYPE_SH7722 is not set
171# CONFIG_CPU_SUBTYPE_SH7366 is not set 176# CONFIG_CPU_SUBTYPE_SH7366 is not set
172# CONFIG_CPU_SUBTYPE_SH5_101 is not set
173# CONFIG_CPU_SUBTYPE_SH5_103 is not set
174 177
175# 178#
176# Memory management options 179# Memory management options
@@ -305,8 +308,6 @@ CONFIG_CMDLINE="console=ttySC1,38400N81 root=/dev/nfs ip=:::::eth1:autoconf rw"
305# 308#
306CONFIG_PCI=y 309CONFIG_PCI=y
307CONFIG_SH_PCIDMA_NONCOHERENT=y 310CONFIG_SH_PCIDMA_NONCOHERENT=y
308CONFIG_PCI_AUTO=y
309CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
310# CONFIG_PCIEPORTBUS is not set 311# CONFIG_PCIEPORTBUS is not set
311# CONFIG_ARCH_SUPPORTS_MSI is not set 312# CONFIG_ARCH_SUPPORTS_MSI is not set
312CONFIG_PCI_LEGACY=y 313CONFIG_PCI_LEGACY=y
@@ -789,6 +790,7 @@ CONFIG_SCSI_LOWLEVEL=y
789# CONFIG_SCSI_MPT2SAS is not set 790# CONFIG_SCSI_MPT2SAS is not set
790# CONFIG_SCSI_HPTIOP is not set 791# CONFIG_SCSI_HPTIOP is not set
791# CONFIG_LIBFC is not set 792# CONFIG_LIBFC is not set
793# CONFIG_LIBFCOE is not set
792# CONFIG_FCOE is not set 794# CONFIG_FCOE is not set
793# CONFIG_SCSI_DMX3191D is not set 795# CONFIG_SCSI_DMX3191D is not set
794# CONFIG_SCSI_FUTURE_DOMAIN is not set 796# CONFIG_SCSI_FUTURE_DOMAIN is not set
@@ -906,6 +908,7 @@ CONFIG_NETDEV_1000=y
906# CONFIG_E1000E is not set 908# CONFIG_E1000E is not set
907# CONFIG_IP1000 is not set 909# CONFIG_IP1000 is not set
908# CONFIG_IGB is not set 910# CONFIG_IGB is not set
911# CONFIG_IGBVF is not set
909# CONFIG_NS83820 is not set 912# CONFIG_NS83820 is not set
910# CONFIG_HAMACHI is not set 913# CONFIG_HAMACHI is not set
911# CONFIG_YELLOWFIN is not set 914# CONFIG_YELLOWFIN is not set
@@ -929,6 +932,7 @@ CONFIG_CHELSIO_T3_DEPENDS=y
929# CONFIG_IXGBE is not set 932# CONFIG_IXGBE is not set
930# CONFIG_IXGB is not set 933# CONFIG_IXGB is not set
931# CONFIG_S2IO is not set 934# CONFIG_S2IO is not set
935# CONFIG_VXGE is not set
932# CONFIG_MYRI10GE is not set 936# CONFIG_MYRI10GE is not set
933# CONFIG_NETXEN_NIC is not set 937# CONFIG_NETXEN_NIC is not set
934# CONFIG_NIU is not set 938# CONFIG_NIU is not set
@@ -1182,7 +1186,6 @@ CONFIG_HID=y
1182# 1186#
1183# Special HID drivers 1187# Special HID drivers
1184# 1188#
1185CONFIG_HID_COMPAT=y
1186CONFIG_USB_SUPPORT=y 1189CONFIG_USB_SUPPORT=y
1187CONFIG_USB_ARCH_HAS_HCD=y 1190CONFIG_USB_ARCH_HAS_HCD=y
1188CONFIG_USB_ARCH_HAS_OHCI=y 1191CONFIG_USB_ARCH_HAS_OHCI=y
@@ -1393,6 +1396,7 @@ CONFIG_EXT2_FS=y
1393# CONFIG_EXT2_FS_XATTR is not set 1396# CONFIG_EXT2_FS_XATTR is not set
1394# CONFIG_EXT2_FS_XIP is not set 1397# CONFIG_EXT2_FS_XIP is not set
1395CONFIG_EXT3_FS=y 1398CONFIG_EXT3_FS=y
1399# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
1396# CONFIG_EXT3_FS_XATTR is not set 1400# CONFIG_EXT3_FS_XATTR is not set
1397# CONFIG_EXT4_FS is not set 1401# CONFIG_EXT4_FS is not set
1398CONFIG_JBD=y 1402CONFIG_JBD=y
@@ -1419,6 +1423,11 @@ CONFIG_INOTIFY_USER=y
1419CONFIG_FUSE_FS=m 1423CONFIG_FUSE_FS=m
1420 1424
1421# 1425#
1426# Caches
1427#
1428# CONFIG_FSCACHE is not set
1429
1430#
1422# CD-ROM/DVD Filesystems 1431# CD-ROM/DVD Filesystems
1423# 1432#
1424CONFIG_ISO9660_FS=m 1433CONFIG_ISO9660_FS=m
@@ -1467,8 +1476,13 @@ CONFIG_MISC_FILESYSTEMS=y
1467# CONFIG_HPFS_FS is not set 1476# CONFIG_HPFS_FS is not set
1468# CONFIG_QNX4FS_FS is not set 1477# CONFIG_QNX4FS_FS is not set
1469CONFIG_ROMFS_FS=y 1478CONFIG_ROMFS_FS=y
1479CONFIG_ROMFS_BACKED_BY_BLOCK=y
1480# CONFIG_ROMFS_BACKED_BY_MTD is not set
1481# CONFIG_ROMFS_BACKED_BY_BOTH is not set
1482CONFIG_ROMFS_ON_BLOCK=y
1470# CONFIG_SYSV_FS is not set 1483# CONFIG_SYSV_FS is not set
1471# CONFIG_UFS_FS is not set 1484# CONFIG_UFS_FS is not set
1485# CONFIG_NILFS2_FS is not set
1472CONFIG_NETWORK_FILESYSTEMS=y 1486CONFIG_NETWORK_FILESYSTEMS=y
1473CONFIG_NFS_FS=y 1487CONFIG_NFS_FS=y
1474CONFIG_NFS_V3=y 1488CONFIG_NFS_V3=y
@@ -1576,6 +1590,7 @@ CONFIG_MAGIC_SYSRQ=y
1576CONFIG_DEBUG_KERNEL=y 1590CONFIG_DEBUG_KERNEL=y
1577# CONFIG_DEBUG_SHIRQ is not set 1591# CONFIG_DEBUG_SHIRQ is not set
1578# CONFIG_DETECT_SOFTLOCKUP is not set 1592# CONFIG_DETECT_SOFTLOCKUP is not set
1593# CONFIG_DETECT_HUNG_TASK is not set
1579CONFIG_SCHED_DEBUG=y 1594CONFIG_SCHED_DEBUG=y
1580# CONFIG_SCHEDSTATS is not set 1595# CONFIG_SCHEDSTATS is not set
1581# CONFIG_TIMER_STATS is not set 1596# CONFIG_TIMER_STATS is not set
@@ -1610,6 +1625,7 @@ CONFIG_SCHED_DEBUG=y
1610CONFIG_HAVE_FUNCTION_TRACER=y 1625CONFIG_HAVE_FUNCTION_TRACER=y
1611CONFIG_HAVE_DYNAMIC_FTRACE=y 1626CONFIG_HAVE_DYNAMIC_FTRACE=y
1612CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1627CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1628CONFIG_TRACING_SUPPORT=y
1613 1629
1614# 1630#
1615# Tracers 1631# Tracers
@@ -1618,9 +1634,14 @@ CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1618# CONFIG_IRQSOFF_TRACER is not set 1634# CONFIG_IRQSOFF_TRACER is not set
1619# CONFIG_SCHED_TRACER is not set 1635# CONFIG_SCHED_TRACER is not set
1620# CONFIG_CONTEXT_SWITCH_TRACER is not set 1636# CONFIG_CONTEXT_SWITCH_TRACER is not set
1637# CONFIG_EVENT_TRACER is not set
1621# CONFIG_BOOT_TRACER is not set 1638# CONFIG_BOOT_TRACER is not set
1622# CONFIG_TRACE_BRANCH_PROFILING is not set 1639# CONFIG_TRACE_BRANCH_PROFILING is not set
1623# CONFIG_STACK_TRACER is not set 1640# CONFIG_STACK_TRACER is not set
1641# CONFIG_KMEMTRACE is not set
1642# CONFIG_WORKQUEUE_TRACER is not set
1643# CONFIG_BLK_DEV_IO_TRACE is not set
1644# CONFIG_DMA_API_DEBUG is not set
1624# CONFIG_SAMPLES is not set 1645# CONFIG_SAMPLES is not set
1625CONFIG_HAVE_ARCH_KGDB=y 1646CONFIG_HAVE_ARCH_KGDB=y
1626# CONFIG_KGDB is not set 1647# CONFIG_KGDB is not set
@@ -1741,6 +1762,7 @@ CONFIG_CRYPTO_DEFLATE=y
1741# CONFIG_CRYPTO_ANSI_CPRNG is not set 1762# CONFIG_CRYPTO_ANSI_CPRNG is not set
1742CONFIG_CRYPTO_HW=y 1763CONFIG_CRYPTO_HW=y
1743# CONFIG_CRYPTO_DEV_HIFN_795X is not set 1764# CONFIG_CRYPTO_DEV_HIFN_795X is not set
1765# CONFIG_BINARY_PRINTF is not set
1744 1766
1745# 1767#
1746# Library routines 1768# Library routines
diff --git a/arch/sh/configs/ul2_defconfig b/arch/sh/configs/ul2_defconfig
index 34f5192a3241..bfb4d9806892 100644
--- a/arch/sh/configs/ul2_defconfig
+++ b/arch/sh/configs/ul2_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 19:30:27 2009 4# Mon Apr 27 13:17:05 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -69,7 +70,6 @@ CONFIG_INITRAMFS_SOURCE=""
69CONFIG_RD_GZIP=y 70CONFIG_RD_GZIP=y
70# CONFIG_RD_BZIP2 is not set 71# CONFIG_RD_BZIP2 is not set
71# CONFIG_RD_LZMA is not set 72# CONFIG_RD_LZMA is not set
72CONFIG_INITRAMFS_COMPRESSION_NONE=y
73CONFIG_CC_OPTIMIZE_FOR_SIZE=y 73CONFIG_CC_OPTIMIZE_FOR_SIZE=y
74CONFIG_SYSCTL=y 74CONFIG_SYSCTL=y
75CONFIG_ANON_INODES=y 75CONFIG_ANON_INODES=y
@@ -78,6 +78,7 @@ CONFIG_UID16=y
78CONFIG_SYSCTL_SYSCALL=y 78CONFIG_SYSCTL_SYSCALL=y
79CONFIG_KALLSYMS=y 79CONFIG_KALLSYMS=y
80# CONFIG_KALLSYMS_EXTRA_PASS is not set 80# CONFIG_KALLSYMS_EXTRA_PASS is not set
81# CONFIG_STRIP_ASM_SYMS is not set
81CONFIG_HOTPLUG=y 82CONFIG_HOTPLUG=y
82CONFIG_PRINTK=y 83CONFIG_PRINTK=y
83CONFIG_BUG=y 84CONFIG_BUG=y
@@ -97,6 +98,7 @@ CONFIG_COMPAT_BRK=y
97CONFIG_SLUB=y 98CONFIG_SLUB=y
98# CONFIG_SLOB is not set 99# CONFIG_SLOB is not set
99CONFIG_PROFILING=y 100CONFIG_PROFILING=y
101# CONFIG_MARKERS is not set
100# CONFIG_OPROFILE is not set 102# CONFIG_OPROFILE is not set
101CONFIG_HAVE_OPROFILE=y 103CONFIG_HAVE_OPROFILE=y
102# CONFIG_KPROBES is not set 104# CONFIG_KPROBES is not set
@@ -105,6 +107,8 @@ CONFIG_HAVE_KPROBES=y
105CONFIG_HAVE_KRETPROBES=y 107CONFIG_HAVE_KRETPROBES=y
106CONFIG_HAVE_ARCH_TRACEHOOK=y 108CONFIG_HAVE_ARCH_TRACEHOOK=y
107CONFIG_HAVE_CLK=y 109CONFIG_HAVE_CLK=y
110CONFIG_HAVE_DMA_API_DEBUG=y
111# CONFIG_SLOW_WORK is not set
108CONFIG_HAVE_GENERIC_DMA_COHERENT=y 112CONFIG_HAVE_GENERIC_DMA_COHERENT=y
109CONFIG_SLABINFO=y 113CONFIG_SLABINFO=y
110CONFIG_RT_MUTEXES=y 114CONFIG_RT_MUTEXES=y
@@ -117,7 +121,6 @@ CONFIG_MODULE_UNLOAD=y
117# CONFIG_MODULE_SRCVERSION_ALL is not set 121# CONFIG_MODULE_SRCVERSION_ALL is not set
118CONFIG_BLOCK=y 122CONFIG_BLOCK=y
119# CONFIG_LBD is not set 123# CONFIG_LBD is not set
120# CONFIG_BLK_DEV_IO_TRACE is not set
121# CONFIG_BLK_DEV_BSG is not set 124# CONFIG_BLK_DEV_BSG is not set
122# CONFIG_BLK_DEV_INTEGRITY is not set 125# CONFIG_BLK_DEV_INTEGRITY is not set
123 126
@@ -167,6 +170,7 @@ CONFIG_ARCH_SHMOBILE=y
167# CONFIG_CPU_SUBTYPE_SH7760 is not set 170# CONFIG_CPU_SUBTYPE_SH7760 is not set
168# CONFIG_CPU_SUBTYPE_SH4_202 is not set 171# CONFIG_CPU_SUBTYPE_SH4_202 is not set
169# CONFIG_CPU_SUBTYPE_SH7723 is not set 172# CONFIG_CPU_SUBTYPE_SH7723 is not set
173# CONFIG_CPU_SUBTYPE_SH7724 is not set
170# CONFIG_CPU_SUBTYPE_SH7763 is not set 174# CONFIG_CPU_SUBTYPE_SH7763 is not set
171# CONFIG_CPU_SUBTYPE_SH7770 is not set 175# CONFIG_CPU_SUBTYPE_SH7770 is not set
172# CONFIG_CPU_SUBTYPE_SH7780 is not set 176# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -176,8 +180,6 @@ CONFIG_ARCH_SHMOBILE=y
176# CONFIG_CPU_SUBTYPE_SH7343 is not set 180# CONFIG_CPU_SUBTYPE_SH7343 is not set
177# CONFIG_CPU_SUBTYPE_SH7722 is not set 181# CONFIG_CPU_SUBTYPE_SH7722 is not set
178CONFIG_CPU_SUBTYPE_SH7366=y 182CONFIG_CPU_SUBTYPE_SH7366=y
179# CONFIG_CPU_SUBTYPE_SH5_101 is not set
180# CONFIG_CPU_SUBTYPE_SH5_103 is not set
181 183
182# 184#
183# Memory management options 185# Memory management options
@@ -584,6 +586,7 @@ CONFIG_SCSI_WAIT_SCAN=m
584CONFIG_SCSI_LOWLEVEL=y 586CONFIG_SCSI_LOWLEVEL=y
585# CONFIG_ISCSI_TCP is not set 587# CONFIG_ISCSI_TCP is not set
586# CONFIG_LIBFC is not set 588# CONFIG_LIBFC is not set
589# CONFIG_LIBFCOE is not set
587# CONFIG_SCSI_DEBUG is not set 590# CONFIG_SCSI_DEBUG is not set
588# CONFIG_SCSI_DH is not set 591# CONFIG_SCSI_DH is not set
589# CONFIG_SCSI_OSD_INITIATOR is not set 592# CONFIG_SCSI_OSD_INITIATOR is not set
@@ -936,6 +939,7 @@ CONFIG_EXT2_FS=y
936# CONFIG_EXT2_FS_XATTR is not set 939# CONFIG_EXT2_FS_XATTR is not set
937# CONFIG_EXT2_FS_XIP is not set 940# CONFIG_EXT2_FS_XIP is not set
938CONFIG_EXT3_FS=y 941CONFIG_EXT3_FS=y
942# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
939CONFIG_EXT3_FS_XATTR=y 943CONFIG_EXT3_FS_XATTR=y
940# CONFIG_EXT3_FS_POSIX_ACL is not set 944# CONFIG_EXT3_FS_POSIX_ACL is not set
941# CONFIG_EXT3_FS_SECURITY is not set 945# CONFIG_EXT3_FS_SECURITY is not set
@@ -958,6 +962,11 @@ CONFIG_INOTIFY_USER=y
958# CONFIG_FUSE_FS is not set 962# CONFIG_FUSE_FS is not set
959 963
960# 964#
965# Caches
966#
967# CONFIG_FSCACHE is not set
968
969#
961# CD-ROM/DVD Filesystems 970# CD-ROM/DVD Filesystems
962# 971#
963# CONFIG_ISO9660_FS is not set 972# CONFIG_ISO9660_FS is not set
@@ -1005,6 +1014,7 @@ CONFIG_CRAMFS=y
1005# CONFIG_ROMFS_FS is not set 1014# CONFIG_ROMFS_FS is not set
1006# CONFIG_SYSV_FS is not set 1015# CONFIG_SYSV_FS is not set
1007# CONFIG_UFS_FS is not set 1016# CONFIG_UFS_FS is not set
1017# CONFIG_NILFS2_FS is not set
1008CONFIG_NETWORK_FILESYSTEMS=y 1018CONFIG_NETWORK_FILESYSTEMS=y
1009CONFIG_NFS_FS=y 1019CONFIG_NFS_FS=y
1010# CONFIG_NFS_V3 is not set 1020# CONFIG_NFS_V3 is not set
@@ -1095,10 +1105,24 @@ CONFIG_FRAME_WARN=1024
1095CONFIG_HAVE_FUNCTION_TRACER=y 1105CONFIG_HAVE_FUNCTION_TRACER=y
1096CONFIG_HAVE_DYNAMIC_FTRACE=y 1106CONFIG_HAVE_DYNAMIC_FTRACE=y
1097CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1107CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1108CONFIG_TRACING_SUPPORT=y
1098 1109
1099# 1110#
1100# Tracers 1111# Tracers
1101# 1112#
1113# CONFIG_FUNCTION_TRACER is not set
1114# CONFIG_IRQSOFF_TRACER is not set
1115# CONFIG_PREEMPT_TRACER is not set
1116# CONFIG_SCHED_TRACER is not set
1117# CONFIG_CONTEXT_SWITCH_TRACER is not set
1118# CONFIG_EVENT_TRACER is not set
1119# CONFIG_BOOT_TRACER is not set
1120# CONFIG_TRACE_BRANCH_PROFILING is not set
1121# CONFIG_STACK_TRACER is not set
1122# CONFIG_KMEMTRACE is not set
1123# CONFIG_WORKQUEUE_TRACER is not set
1124# CONFIG_BLK_DEV_IO_TRACE is not set
1125# CONFIG_DMA_API_DEBUG is not set
1102# CONFIG_SAMPLES is not set 1126# CONFIG_SAMPLES is not set
1103CONFIG_HAVE_ARCH_KGDB=y 1127CONFIG_HAVE_ARCH_KGDB=y
1104# CONFIG_SH_STANDARD_BIOS is not set 1128# CONFIG_SH_STANDARD_BIOS is not set
@@ -1208,6 +1232,7 @@ CONFIG_CRYPTO_ARC4=y
1208# 1232#
1209# CONFIG_CRYPTO_ANSI_CPRNG is not set 1233# CONFIG_CRYPTO_ANSI_CPRNG is not set
1210CONFIG_CRYPTO_HW=y 1234CONFIG_CRYPTO_HW=y
1235# CONFIG_BINARY_PRINTF is not set
1211 1236
1212# 1237#
1213# Library routines 1238# Library routines
diff --git a/arch/sh/configs/urquell_defconfig b/arch/sh/configs/urquell_defconfig
index d174b1a4d802..512664fed66c 100644
--- a/arch/sh/configs/urquell_defconfig
+++ b/arch/sh/configs/urquell_defconfig
@@ -1,10 +1,11 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29 3# Linux kernel version: 2.6.30-rc3
4# Thu Apr 2 19:33:39 2009 4# Mon Apr 27 14:02:55 2009
5# 5#
6CONFIG_SUPERH=y 6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y 7CONFIG_SUPERH32=y
8# CONFIG_SUPERH64 is not set
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig" 9CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y 10CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y 11CONFIG_GENERIC_BUG=y
@@ -76,6 +77,7 @@ CONFIG_UID16=y
76CONFIG_SYSCTL_SYSCALL=y 77CONFIG_SYSCTL_SYSCALL=y
77CONFIG_KALLSYMS=y 78CONFIG_KALLSYMS=y
78# CONFIG_KALLSYMS_EXTRA_PASS is not set 79# CONFIG_KALLSYMS_EXTRA_PASS is not set
80# CONFIG_STRIP_ASM_SYMS is not set
79CONFIG_HOTPLUG=y 81CONFIG_HOTPLUG=y
80CONFIG_PRINTK=y 82CONFIG_PRINTK=y
81CONFIG_BUG=y 83CONFIG_BUG=y
@@ -94,6 +96,7 @@ CONFIG_SLAB=y
94# CONFIG_SLUB is not set 96# CONFIG_SLUB is not set
95# CONFIG_SLOB is not set 97# CONFIG_SLOB is not set
96CONFIG_PROFILING=y 98CONFIG_PROFILING=y
99# CONFIG_MARKERS is not set
97# CONFIG_OPROFILE is not set 100# CONFIG_OPROFILE is not set
98CONFIG_HAVE_OPROFILE=y 101CONFIG_HAVE_OPROFILE=y
99# CONFIG_KPROBES is not set 102# CONFIG_KPROBES is not set
@@ -102,6 +105,8 @@ CONFIG_HAVE_KPROBES=y
102CONFIG_HAVE_KRETPROBES=y 105CONFIG_HAVE_KRETPROBES=y
103CONFIG_HAVE_ARCH_TRACEHOOK=y 106CONFIG_HAVE_ARCH_TRACEHOOK=y
104CONFIG_HAVE_CLK=y 107CONFIG_HAVE_CLK=y
108CONFIG_HAVE_DMA_API_DEBUG=y
109# CONFIG_SLOW_WORK is not set
105CONFIG_HAVE_GENERIC_DMA_COHERENT=y 110CONFIG_HAVE_GENERIC_DMA_COHERENT=y
106CONFIG_SLABINFO=y 111CONFIG_SLABINFO=y
107CONFIG_RT_MUTEXES=y 112CONFIG_RT_MUTEXES=y
@@ -114,7 +119,6 @@ CONFIG_MODULE_UNLOAD=y
114# CONFIG_MODULE_SRCVERSION_ALL is not set 119# CONFIG_MODULE_SRCVERSION_ALL is not set
115CONFIG_BLOCK=y 120CONFIG_BLOCK=y
116# CONFIG_LBD is not set 121# CONFIG_LBD is not set
117# CONFIG_BLK_DEV_IO_TRACE is not set
118# CONFIG_BLK_DEV_BSG is not set 122# CONFIG_BLK_DEV_BSG is not set
119# CONFIG_BLK_DEV_INTEGRITY is not set 123# CONFIG_BLK_DEV_INTEGRITY is not set
120 124
@@ -162,6 +166,7 @@ CONFIG_CPU_SHX3=y
162# CONFIG_CPU_SUBTYPE_SH7760 is not set 166# CONFIG_CPU_SUBTYPE_SH7760 is not set
163# CONFIG_CPU_SUBTYPE_SH4_202 is not set 167# CONFIG_CPU_SUBTYPE_SH4_202 is not set
164# CONFIG_CPU_SUBTYPE_SH7723 is not set 168# CONFIG_CPU_SUBTYPE_SH7723 is not set
169# CONFIG_CPU_SUBTYPE_SH7724 is not set
165# CONFIG_CPU_SUBTYPE_SH7763 is not set 170# CONFIG_CPU_SUBTYPE_SH7763 is not set
166# CONFIG_CPU_SUBTYPE_SH7770 is not set 171# CONFIG_CPU_SUBTYPE_SH7770 is not set
167# CONFIG_CPU_SUBTYPE_SH7780 is not set 172# CONFIG_CPU_SUBTYPE_SH7780 is not set
@@ -171,8 +176,6 @@ CONFIG_CPU_SUBTYPE_SH7786=y
171# CONFIG_CPU_SUBTYPE_SH7343 is not set 176# CONFIG_CPU_SUBTYPE_SH7343 is not set
172# CONFIG_CPU_SUBTYPE_SH7722 is not set 177# CONFIG_CPU_SUBTYPE_SH7722 is not set
173# CONFIG_CPU_SUBTYPE_SH7366 is not set 178# CONFIG_CPU_SUBTYPE_SH7366 is not set
174# CONFIG_CPU_SUBTYPE_SH5_101 is not set
175# CONFIG_CPU_SUBTYPE_SH5_103 is not set
176 179
177# 180#
178# Memory management options 181# Memory management options
@@ -900,15 +903,17 @@ CONFIG_USB_HID=y
900# 903#
901# Special HID drivers 904# Special HID drivers
902# 905#
903CONFIG_HID_COMPAT=y
904CONFIG_HID_A4TECH=y 906CONFIG_HID_A4TECH=y
905CONFIG_HID_APPLE=y 907CONFIG_HID_APPLE=y
906CONFIG_HID_BELKIN=y 908CONFIG_HID_BELKIN=y
907CONFIG_HID_CHERRY=y 909CONFIG_HID_CHERRY=y
908CONFIG_HID_CHICONY=y 910CONFIG_HID_CHICONY=y
909CONFIG_HID_CYPRESS=y 911CONFIG_HID_CYPRESS=y
912# CONFIG_DRAGONRISE_FF is not set
910CONFIG_HID_EZKEY=y 913CONFIG_HID_EZKEY=y
914# CONFIG_HID_KYE is not set
911CONFIG_HID_GYRATION=y 915CONFIG_HID_GYRATION=y
916# CONFIG_HID_KENSINGTON is not set
912CONFIG_HID_LOGITECH=y 917CONFIG_HID_LOGITECH=y
913# CONFIG_LOGITECH_FF is not set 918# CONFIG_LOGITECH_FF is not set
914# CONFIG_LOGIRUMBLEPAD2_FF is not set 919# CONFIG_LOGIRUMBLEPAD2_FF is not set
@@ -1046,6 +1051,7 @@ CONFIG_EXT2_FS=y
1046# CONFIG_EXT2_FS_XATTR is not set 1051# CONFIG_EXT2_FS_XATTR is not set
1047# CONFIG_EXT2_FS_XIP is not set 1052# CONFIG_EXT2_FS_XIP is not set
1048CONFIG_EXT3_FS=y 1053CONFIG_EXT3_FS=y
1054# CONFIG_EXT3_DEFAULTS_TO_ORDERED is not set
1049CONFIG_EXT3_FS_XATTR=y 1055CONFIG_EXT3_FS_XATTR=y
1050# CONFIG_EXT3_FS_POSIX_ACL is not set 1056# CONFIG_EXT3_FS_POSIX_ACL is not set
1051# CONFIG_EXT3_FS_SECURITY is not set 1057# CONFIG_EXT3_FS_SECURITY is not set
@@ -1068,6 +1074,11 @@ CONFIG_INOTIFY_USER=y
1068# CONFIG_FUSE_FS is not set 1074# CONFIG_FUSE_FS is not set
1069 1075
1070# 1076#
1077# Caches
1078#
1079# CONFIG_FSCACHE is not set
1080
1081#
1071# CD-ROM/DVD Filesystems 1082# CD-ROM/DVD Filesystems
1072# 1083#
1073# CONFIG_ISO9660_FS is not set 1084# CONFIG_ISO9660_FS is not set
@@ -1117,6 +1128,7 @@ CONFIG_MINIX_FS=y
1117# CONFIG_ROMFS_FS is not set 1128# CONFIG_ROMFS_FS is not set
1118# CONFIG_SYSV_FS is not set 1129# CONFIG_SYSV_FS is not set
1119# CONFIG_UFS_FS is not set 1130# CONFIG_UFS_FS is not set
1131# CONFIG_NILFS2_FS is not set
1120CONFIG_NETWORK_FILESYSTEMS=y 1132CONFIG_NETWORK_FILESYSTEMS=y
1121CONFIG_NFS_FS=y 1133CONFIG_NFS_FS=y
1122CONFIG_NFS_V3=y 1134CONFIG_NFS_V3=y
@@ -1209,10 +1221,24 @@ CONFIG_SYSCTL_SYSCALL_CHECK=y
1209CONFIG_HAVE_FUNCTION_TRACER=y 1221CONFIG_HAVE_FUNCTION_TRACER=y
1210CONFIG_HAVE_DYNAMIC_FTRACE=y 1222CONFIG_HAVE_DYNAMIC_FTRACE=y
1211CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y 1223CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1224CONFIG_TRACING_SUPPORT=y
1212 1225
1213# 1226#
1214# Tracers 1227# Tracers
1215# 1228#
1229# CONFIG_FUNCTION_TRACER is not set
1230# CONFIG_IRQSOFF_TRACER is not set
1231# CONFIG_PREEMPT_TRACER is not set
1232# CONFIG_SCHED_TRACER is not set
1233# CONFIG_CONTEXT_SWITCH_TRACER is not set
1234# CONFIG_EVENT_TRACER is not set
1235# CONFIG_BOOT_TRACER is not set
1236# CONFIG_TRACE_BRANCH_PROFILING is not set
1237# CONFIG_STACK_TRACER is not set
1238# CONFIG_KMEMTRACE is not set
1239# CONFIG_WORKQUEUE_TRACER is not set
1240# CONFIG_BLK_DEV_IO_TRACE is not set
1241# CONFIG_DMA_API_DEBUG is not set
1216# CONFIG_SAMPLES is not set 1242# CONFIG_SAMPLES is not set
1217CONFIG_HAVE_ARCH_KGDB=y 1243CONFIG_HAVE_ARCH_KGDB=y
1218# CONFIG_SH_STANDARD_BIOS is not set 1244# CONFIG_SH_STANDARD_BIOS is not set
@@ -1322,6 +1348,7 @@ CONFIG_CRYPTO_DES=y
1322# 1348#
1323# CONFIG_CRYPTO_ANSI_CPRNG is not set 1349# CONFIG_CRYPTO_ANSI_CPRNG is not set
1324# CONFIG_CRYPTO_HW is not set 1350# CONFIG_CRYPTO_HW is not set
1351# CONFIG_BINARY_PRINTF is not set
1325 1352
1326# 1353#
1327# Library routines 1354# Library routines
diff --git a/arch/sh/drivers/dma/Kconfig b/arch/sh/drivers/dma/Kconfig
index 666713ac5fcf..63e9dd30b41c 100644
--- a/arch/sh/drivers/dma/Kconfig
+++ b/arch/sh/drivers/dma/Kconfig
@@ -16,7 +16,8 @@ config SH_DMA_IRQ_MULTI
16 CPU_SUBTYPE_SH7750S || CPU_SUBTYPE_SH7750R || \ 16 CPU_SUBTYPE_SH7750S || CPU_SUBTYPE_SH7750R || \
17 CPU_SUBTYPE_SH7751R || CPU_SUBTYPE_SH7091 || \ 17 CPU_SUBTYPE_SH7751R || CPU_SUBTYPE_SH7091 || \
18 CPU_SUBTYPE_SH7763 || CPU_SUBTYPE_SH7764 || \ 18 CPU_SUBTYPE_SH7763 || CPU_SUBTYPE_SH7764 || \
19 CPU_SUBTYPE_SH7780 || CPU_SUBTYPE_SH7785 19 CPU_SUBTYPE_SH7780 || CPU_SUBTYPE_SH7785 || \
20 CPU_SUBTYPE_SH7760
20 21
21config NR_ONCHIP_DMA_CHANNELS 22config NR_ONCHIP_DMA_CHANNELS
22 int 23 int
diff --git a/arch/sh/drivers/pci/Kconfig b/arch/sh/drivers/pci/Kconfig
index 7e816ededed7..e8db585a6638 100644
--- a/arch/sh/drivers/pci/Kconfig
+++ b/arch/sh/drivers/pci/Kconfig
@@ -17,21 +17,3 @@ config SH_PCIDMA_NONCOHERENT
17 code will not have to flush the CPU's caches. If you have a PCI host 17 code will not have to flush the CPU's caches. If you have a PCI host
18 bridge integrated with your SH CPU, refer carefully to the chip specs 18 bridge integrated with your SH CPU, refer carefully to the chip specs
19 to see if you can say 'N' here. Otherwise, leave it as 'Y'. 19 to see if you can say 'N' here. Otherwise, leave it as 'Y'.
20
21# This is also board-specific
22config PCI_AUTO
23 bool
24 depends on PCI
25 default y
26
27config PCI_AUTO_UPDATE_RESOURCES
28 bool
29 depends on PCI_AUTO
30 default y if !SH_DREAMCAST
31 help
32 Selecting this option will cause the PCI auto code to leave your
33 BAR values alone. Otherwise they will be updated automatically. If
34 for some reason, you have a board that simply refuses to work
35 with its resources updated beyond what they are when the device
36 is powered up, set this to N. Everyone else will want this as Y.
37
diff --git a/arch/sh/drivers/pci/Makefile b/arch/sh/drivers/pci/Makefile
index 847e90894d1b..d2ffc477549a 100644
--- a/arch/sh/drivers/pci/Makefile
+++ b/arch/sh/drivers/pci/Makefile
@@ -1,9 +1,7 @@
1# 1#
2# Makefile for the PCI specific kernel interface routines under Linux. 2# Makefile for the PCI specific kernel interface routines under Linux.
3# 3#
4
5obj-y += pci.o 4obj-y += pci.o
6obj-$(CONFIG_PCI_AUTO) += pci-auto.o
7 5
8obj-$(CONFIG_CPU_SUBTYPE_SH7751) += pci-sh7751.o ops-sh4.o 6obj-$(CONFIG_CPU_SUBTYPE_SH7751) += pci-sh7751.o ops-sh4.o
9obj-$(CONFIG_CPU_SUBTYPE_SH7751R) += pci-sh7751.o ops-sh4.o 7obj-$(CONFIG_CPU_SUBTYPE_SH7751R) += pci-sh7751.o ops-sh4.o
@@ -12,15 +10,17 @@ obj-$(CONFIG_CPU_SUBTYPE_SH7780) += pci-sh7780.o ops-sh4.o
12obj-$(CONFIG_CPU_SUBTYPE_SH7785) += pci-sh7780.o ops-sh4.o 10obj-$(CONFIG_CPU_SUBTYPE_SH7785) += pci-sh7780.o ops-sh4.o
13obj-$(CONFIG_CPU_SH5) += pci-sh5.o ops-sh5.o 11obj-$(CONFIG_CPU_SH5) += pci-sh5.o ops-sh5.o
14 12
15obj-$(CONFIG_SH_DREAMCAST) += ops-dreamcast.o fixups-dreamcast.o 13obj-$(CONFIG_SH_DREAMCAST) += ops-dreamcast.o fixups-dreamcast.o \
16obj-$(CONFIG_SH_SECUREEDGE5410) += ops-snapgear.o 14 pci-dreamcast.o
17obj-$(CONFIG_SH_RTS7751R2D) += ops-rts7751r2d.o fixups-rts7751r2d.o 15obj-$(CONFIG_SH_SECUREEDGE5410) += fixups-snapgear.o
18obj-$(CONFIG_SH_SH03) += ops-sh03.o fixups-sh03.o 16obj-$(CONFIG_SH_7751_SOLUTION_ENGINE) += fixups-se7751.o
19obj-$(CONFIG_SH_HIGHLANDER) += ops-r7780rp.o fixups-r7780rp.o 17obj-$(CONFIG_SH_RTS7751R2D) += fixups-rts7751r2d.o
20obj-$(CONFIG_SH_SDK7780) += ops-sdk7780.o fixups-sdk7780.o 18obj-$(CONFIG_SH_SH03) += fixups-sh03.o
21obj-$(CONFIG_SH_TITAN) += ops-titan.o 19obj-$(CONFIG_SH_HIGHLANDER) += fixups-r7780rp.o
22obj-$(CONFIG_SH_LANDISK) += ops-landisk.o 20obj-$(CONFIG_SH_SH7785LCR) += fixups-r7780rp.o
23obj-$(CONFIG_SH_LBOX_RE2) += ops-lboxre2.o fixups-lboxre2.o 21obj-$(CONFIG_SH_SDK7780) += fixups-sdk7780.o
24obj-$(CONFIG_SH_7780_SOLUTION_ENGINE) += ops-se7780.o fixups-se7780.o 22obj-$(CONFIG_SH_7780_SOLUTION_ENGINE) += fixups-sdk7780.o
25obj-$(CONFIG_SH_CAYMAN) += ops-cayman.o 23obj-$(CONFIG_SH_TITAN) += fixups-titan.o
26obj-$(CONFIG_SH_SH7785LCR) += ops-sh7785lcr.o fixups-sh7785lcr.o 24obj-$(CONFIG_SH_LANDISK) += fixups-landisk.o
25obj-$(CONFIG_SH_LBOX_RE2) += fixups-rts7751r2d.o
26obj-$(CONFIG_SH_CAYMAN) += fixups-cayman.o
diff --git a/arch/sh/drivers/pci/ops-cayman.c b/arch/sh/drivers/pci/fixups-cayman.c
index 38ef76207af6..b68b61d22c6c 100644
--- a/arch/sh/drivers/pci/ops-cayman.c
+++ b/arch/sh/drivers/pci/fixups-cayman.c
@@ -75,15 +75,3 @@ int __init pcibios_map_platform_irq(struct pci_dev *dev, u8 slot, u8 pin)
75 75
76 return result; 76 return result;
77} 77}
78
79struct pci_channel board_pci_channels[] = {
80 { &sh5_pci_ops, NULL, NULL, 0, 0xff },
81 { NULL, NULL, NULL, 0, 0 },
82};
83EXPORT_SYMBOL(board_pci_channels);
84
85int __init pcibios_init_platform(void)
86{
87 return sh5pci_init(__pa(memory_start),
88 __pa(memory_end) - __pa(memory_start));
89}
diff --git a/arch/sh/drivers/pci/fixups-dreamcast.c b/arch/sh/drivers/pci/fixups-dreamcast.c
index 2bf85cf091e1..ed7f489936f1 100644
--- a/arch/sh/drivers/pci/fixups-dreamcast.c
+++ b/arch/sh/drivers/pci/fixups-dreamcast.c
@@ -30,7 +30,7 @@
30 30
31static void __init gapspci_fixup_resources(struct pci_dev *dev) 31static void __init gapspci_fixup_resources(struct pci_dev *dev)
32{ 32{
33 struct pci_channel *p = board_pci_channels; 33 struct pci_channel *p = dev->sysdata;
34 34
35 printk(KERN_NOTICE "PCI: Fixing up device %s\n", pci_name(dev)); 35 printk(KERN_NOTICE "PCI: Fixing up device %s\n", pci_name(dev));
36 36
@@ -41,6 +41,13 @@ static void __init gapspci_fixup_resources(struct pci_dev *dev)
41 */ 41 */
42 dev->resource[1].start = p->io_resource->start + 0x100; 42 dev->resource[1].start = p->io_resource->start + 0x100;
43 dev->resource[1].end = dev->resource[1].start + 0x200 - 1; 43 dev->resource[1].end = dev->resource[1].start + 0x200 - 1;
44
45 /*
46 * This is not a normal BAR, prevent any attempts to move
47 * the BAR, as this will result in a bus lock.
48 */
49 dev->resource[1].flags |= IORESOURCE_PCI_FIXED;
50
44 /* 51 /*
45 * Redirect dma memory allocations to special memory window. 52 * Redirect dma memory allocations to special memory window.
46 */ 53 */
diff --git a/arch/sh/drivers/pci/ops-landisk.c b/arch/sh/drivers/pci/fixups-landisk.c
index bff09ecf3419..bb1a6bb5149e 100644
--- a/arch/sh/drivers/pci/ops-landisk.c
+++ b/arch/sh/drivers/pci/fixups-landisk.c
@@ -15,39 +15,6 @@
15#include <linux/pci.h> 15#include <linux/pci.h>
16#include "pci-sh4.h" 16#include "pci-sh4.h"
17 17
18static struct resource sh7751_io_resource = {
19 .name = "SH7751 IO",
20 .start = SH7751_PCI_IO_BASE,
21 .end = SH7751_PCI_IO_BASE + SH7751_PCI_IO_SIZE - 1,
22 .flags = IORESOURCE_IO
23};
24
25static struct resource sh7751_mem_resource = {
26 .name = "SH7751 mem",
27 .start = SH7751_PCI_MEMORY_BASE,
28 .end = SH7751_PCI_MEMORY_BASE + SH7751_PCI_MEM_SIZE - 1,
29 .flags = IORESOURCE_MEM
30};
31
32struct pci_channel board_pci_channels[] = {
33 {&sh4_pci_ops, &sh7751_io_resource, &sh7751_mem_resource, 0, 0x3ff},
34 {NULL, NULL, NULL, 0, 0},
35};
36
37static struct sh4_pci_address_map sh7751_pci_map = {
38 .window0 = {
39 .base = SH7751_CS3_BASE_ADDR,
40 .size = (64 << 20), /* 64MB */
41 },
42
43 .flags = SH4_PCIC_NO_RESET,
44};
45
46int __init pcibios_init_platform(void)
47{
48 return sh7751_pcic_init(&sh7751_pci_map);
49}
50
51int pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin) 18int pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin)
52{ 19{
53 /* 20 /*
diff --git a/arch/sh/drivers/pci/fixups-lboxre2.c b/arch/sh/drivers/pci/fixups-lboxre2.c
deleted file mode 100644
index 1c1d41255ec0..000000000000
--- a/arch/sh/drivers/pci/fixups-lboxre2.c
+++ /dev/null
@@ -1,41 +0,0 @@
1/*
2 * arch/sh/drivers/pci/fixups-lboxre2.c
3 *
4 * L-BOX RE2 PCI fixups
5 *
6 * Copyright (C) 2007 Nobuhiro Iwamatsu
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12#include "pci-sh4.h"
13
14#define PCIMCR_MRSET_OFF 0xBFFFFFFF
15#define PCIMCR_RFSH_OFF 0xFFFFFFFB
16
17int pci_fixup_pcic(void)
18{
19 unsigned long bcr1, mcr;
20
21 bcr1 = ctrl_inl(SH7751_BCR1);
22 bcr1 |= 0x40080000; /* Enable Bit 19 BREQEN, set PCIC to slave */
23 pci_write_reg(bcr1, SH4_PCIBCR1);
24
25 /* Enable all interrupts, so we known what to fix */
26 pci_write_reg(0x0000c3ff, SH4_PCIINTM);
27 pci_write_reg(0x0000380f, SH4_PCIAINTM);
28 pci_write_reg(0xfb900047, SH7751_PCICONF1);
29 pci_write_reg(0xab000001, SH7751_PCICONF4);
30
31 mcr = ctrl_inl(SH7751_MCR);
32 mcr = (mcr & PCIMCR_MRSET_OFF) & PCIMCR_RFSH_OFF;
33 pci_write_reg(mcr, SH4_PCIMCR);
34
35 pci_write_reg(0x0c000000, SH7751_PCICONF5);
36 pci_write_reg(0xd0000000, SH7751_PCICONF6);
37 pci_write_reg(0x0c000000, SH4_PCILAR0);
38 pci_write_reg(0x00000000, SH4_PCILAR1);
39
40 return 0;
41}
diff --git a/arch/sh/drivers/pci/fixups-r7780rp.c b/arch/sh/drivers/pci/fixups-r7780rp.c
index 3e321df65d22..15ca65cb667e 100644
--- a/arch/sh/drivers/pci/fixups-r7780rp.c
+++ b/arch/sh/drivers/pci/fixups-r7780rp.c
@@ -11,35 +11,26 @@
11 * for more details. 11 * for more details.
12 */ 12 */
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/io.h>
14#include "pci-sh4.h" 15#include "pci-sh4.h"
15#include <asm/io.h>
16 16
17int pci_fixup_pcic(void) 17static char irq_tab[] __initdata = {
18{ 18 65, 66, 67, 68,
19 pci_write_reg(0x000043ff, SH4_PCIINTM); 19};
20 pci_write_reg(0x0000380f, SH4_PCIAINTM);
21
22 pci_write_reg(0xfbb00047, SH7780_PCICMD);
23 pci_write_reg(0x00000000, SH7780_PCIIBAR);
24
25 pci_write_reg(0x00011912, SH7780_PCISVID);
26 pci_write_reg(0x08000000, SH7780_PCICSCR0);
27 pci_write_reg(0x0000001b, SH7780_PCICSAR0);
28 pci_write_reg(0xfd000000, SH7780_PCICSCR1);
29 pci_write_reg(0x0000000f, SH7780_PCICSAR1);
30
31 pci_write_reg(0xfd000000, SH7780_PCIMBR0);
32 pci_write_reg(0x00fc0000, SH7780_PCIMBMR0);
33 20
34#ifdef CONFIG_32BIT 21int __init pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin)
35 pci_write_reg(0xc0000000, SH7780_PCIMBR2); 22{
36 pci_write_reg(0x20000000 - SH7780_PCI_IO_SIZE, SH7780_PCIMBMR2); 23 return irq_tab[slot];
37#endif 24}
38 25
39 /* Set IOBR for windows containing area specified in pci.h */ 26int pci_fixup_pcic(struct pci_channel *chan)
40 pci_write_reg((PCIBIOS_MIN_IO & ~(SH7780_PCI_IO_SIZE - 1)), 27{
41 SH7780_PCIIOBR); 28 pci_write_reg(chan, 0x000043ff, SH4_PCIINTM);
42 pci_write_reg(((SH7780_PCI_IO_SIZE-1) & (7<<18)), SH7780_PCIIOBMR); 29 pci_write_reg(chan, 0x00000000, SH7780_PCIIBAR);
30 pci_write_reg(chan, 0x08000000, SH7780_PCICSCR0);
31 pci_write_reg(chan, 0x0000001b, SH7780_PCICSAR0);
32 pci_write_reg(chan, 0xfd000000, SH7780_PCICSCR1);
33 pci_write_reg(chan, 0x0000000f, SH7780_PCICSAR1);
43 34
44 return 0; 35 return 0;
45} 36}
diff --git a/arch/sh/drivers/pci/fixups-rts7751r2d.c b/arch/sh/drivers/pci/fixups-rts7751r2d.c
index 904bce8768d3..052b354236dc 100644
--- a/arch/sh/drivers/pci/fixups-rts7751r2d.c
+++ b/arch/sh/drivers/pci/fixups-rts7751r2d.c
@@ -1,43 +1,67 @@
1/* 1/*
2 * arch/sh/drivers/pci/fixups-rts7751r2d.c 2 * arch/sh/drivers/pci/fixups-rts7751r2d.c
3 * 3 *
4 * RTS7751R2D PCI fixups 4 * RTS7751R2D / LBOXRE2 PCI fixups
5 * 5 *
6 * Copyright (C) 2003 Lineo uSolutions, Inc. 6 * Copyright (C) 2003 Lineo uSolutions, Inc.
7 * Copyright (C) 2004 Paul Mundt 7 * Copyright (C) 2004 Paul Mundt
8 * Copyright (C) 2007 Nobuhiro Iwamatsu
8 * 9 *
9 * This file is subject to the terms and conditions of the GNU General Public 10 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive 11 * License. See the file "COPYING" in the main directory of this archive
11 * for more details. 12 * for more details.
12 */ 13 */
14#include <linux/pci.h>
15#include <mach/lboxre2.h>
16#include <mach/r2d.h>
13#include "pci-sh4.h" 17#include "pci-sh4.h"
18#include <asm/machtypes.h>
14 19
15#define PCIMCR_MRSET_OFF 0xBFFFFFFF 20#define PCIMCR_MRSET_OFF 0xBFFFFFFF
16#define PCIMCR_RFSH_OFF 0xFFFFFFFB 21#define PCIMCR_RFSH_OFF 0xFFFFFFFB
17 22
18int pci_fixup_pcic(void) 23static u8 rts7751r2d_irq_tab[] __initdata = {
24 IRQ_PCI_INTA,
25 IRQ_PCI_INTB,
26 IRQ_PCI_INTC,
27 IRQ_PCI_INTD,
28};
29
30static char lboxre2_irq_tab[] __initdata = {
31 IRQ_ETH0, IRQ_ETH1, IRQ_INTA, IRQ_INTD,
32};
33
34int __init pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin)
35{
36 if (mach_is_lboxre2())
37 return lboxre2_irq_tab[slot];
38 else
39 return rts7751r2d_irq_tab[slot];
40}
41
42int pci_fixup_pcic(struct pci_channel *chan)
19{ 43{
20 unsigned long bcr1, mcr; 44 unsigned long bcr1, mcr;
21 45
22 bcr1 = ctrl_inl(SH7751_BCR1); 46 bcr1 = ctrl_inl(SH7751_BCR1);
23 bcr1 |= 0x40080000; /* Enable Bit 19 BREQEN, set PCIC to slave */ 47 bcr1 |= 0x40080000; /* Enable Bit 19 BREQEN, set PCIC to slave */
24 pci_write_reg(bcr1, SH4_PCIBCR1); 48 pci_write_reg(chan, bcr1, SH4_PCIBCR1);
25 49
26 /* Enable all interrupts, so we known what to fix */ 50 /* Enable all interrupts, so we known what to fix */
27 pci_write_reg(0x0000c3ff, SH4_PCIINTM); 51 pci_write_reg(chan, 0x0000c3ff, SH4_PCIINTM);
28 pci_write_reg(0x0000380f, SH4_PCIAINTM); 52 pci_write_reg(chan, 0x0000380f, SH4_PCIAINTM);
29 53
30 pci_write_reg(0xfb900047, SH7751_PCICONF1); 54 pci_write_reg(chan, 0xfb900047, SH7751_PCICONF1);
31 pci_write_reg(0xab000001, SH7751_PCICONF4); 55 pci_write_reg(chan, 0xab000001, SH7751_PCICONF4);
32 56
33 mcr = ctrl_inl(SH7751_MCR); 57 mcr = ctrl_inl(SH7751_MCR);
34 mcr = (mcr & PCIMCR_MRSET_OFF) & PCIMCR_RFSH_OFF; 58 mcr = (mcr & PCIMCR_MRSET_OFF) & PCIMCR_RFSH_OFF;
35 pci_write_reg(mcr, SH4_PCIMCR); 59 pci_write_reg(chan, mcr, SH4_PCIMCR);
36 60
37 pci_write_reg(0x0c000000, SH7751_PCICONF5); 61 pci_write_reg(chan, 0x0c000000, SH7751_PCICONF5);
38 pci_write_reg(0xd0000000, SH7751_PCICONF6); 62 pci_write_reg(chan, 0xd0000000, SH7751_PCICONF6);
39 pci_write_reg(0x0c000000, SH4_PCILAR0); 63 pci_write_reg(chan, 0x0c000000, SH4_PCILAR0);
40 pci_write_reg(0x00000000, SH4_PCILAR1); 64 pci_write_reg(chan, 0x00000000, SH4_PCILAR1);
41 65
42 return 0; 66 return 0;
43} 67}
diff --git a/arch/sh/drivers/pci/fixups-sdk7780.c b/arch/sh/drivers/pci/fixups-sdk7780.c
index 2f8863099dd1..250b0edd7365 100644
--- a/arch/sh/drivers/pci/fixups-sdk7780.c
+++ b/arch/sh/drivers/pci/fixups-sdk7780.c
@@ -5,55 +5,48 @@
5 * 5 *
6 * Copyright (C) 2003 Lineo uSolutions, Inc. 6 * Copyright (C) 2003 Lineo uSolutions, Inc.
7 * Copyright (C) 2004 - 2006 Paul Mundt 7 * Copyright (C) 2004 - 2006 Paul Mundt
8 * Copyright (C) 2006 Nobuhiro Iwamatsu
8 * 9 *
9 * This file is subject to the terms and conditions of the GNU General Public 10 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive 11 * License. See the file "COPYING" in the main directory of this archive
11 * for more details. 12 * for more details.
12 */ 13 */
13#include <linux/pci.h> 14#include <linux/pci.h>
15#include <linux/io.h>
14#include "pci-sh4.h" 16#include "pci-sh4.h"
15#include <asm/io.h>
16 17
17int pci_fixup_pcic(void) 18/* IDSEL [16][17][18][19][20][21][22][23][24][25][26][27][28][29][30][31] */
19static char sdk7780_irq_tab[4][16] __initdata = {
20 /* INTA */
21 { 65, 68, 67, 68, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
22 /* INTB */
23 { 66, 65, -1, 65, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
24 /* INTC */
25 { 67, 66, -1, 66, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
26 /* INTD */
27 { 68, 67, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
28};
29
30int __init pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin)
31{
32 return sdk7780_irq_tab[pin-1][slot];
33}
34int pci_fixup_pcic(struct pci_channel *chan)
18{ 35{
19 ctrl_outl(0x00000001, SH7780_PCI_VCR2);
20
21 /* Enable all interrupts, so we know what to fix */ 36 /* Enable all interrupts, so we know what to fix */
22 pci_write_reg(0x0000C3FF, SH7780_PCIIMR); 37 pci_write_reg(chan, 0x0000C3FF, SH7780_PCIIMR);
23 pci_write_reg(0x0000380F, SH7780_PCIAINTM);
24 38
25 /* Set up standard PCI config registers */ 39 /* Set up standard PCI config registers */
26 pci_write_reg(0xFB00, SH7780_PCISTATUS); 40 pci_write_reg(chan, 0x08000000, SH7780_PCIMBAR0); /* PCI */
27 pci_write_reg(0x0047, SH7780_PCICMD); 41 pci_write_reg(chan, 0x08000000, SH4_PCILAR0); /* SHwy */
28 pci_write_reg(0x00, SH7780_PCIPIF); 42 pci_write_reg(chan, 0x07F00001, SH4_PCILSR0); /* size 128M w/ MBAR */
29 pci_write_reg(0x00, SH7780_PCISUB);
30 pci_write_reg(0x06, SH7780_PCIBCC);
31 pci_write_reg(0x1912, SH7780_PCISVID);
32 pci_write_reg(0x0001, SH7780_PCISID);
33
34 pci_write_reg(0x08000000, SH7780_PCIMBAR0); /* PCI */
35 pci_write_reg(0x08000000, SH7780_PCILAR0); /* SHwy */
36 pci_write_reg(0x07F00001, SH7780_PCILSR); /* size 128M w/ MBAR */
37
38 pci_write_reg(0x00000000, SH7780_PCIMBAR1);
39 pci_write_reg(0x00000000, SH7780_PCILAR1);
40 pci_write_reg(0x00000000, SH7780_PCILSR1);
41
42 pci_write_reg(0xAB000801, SH7780_PCIIBAR);
43
44 /*
45 * Set the MBR so PCI address is one-to-one with window,
46 * meaning all calls go straight through... use ifdef to
47 * catch erroneous assumption.
48 */
49 pci_write_reg(0xFD000000 , SH7780_PCIMBR0);
50 pci_write_reg(0x00FC0000 , SH7780_PCIMBMR0); /* 16M */
51 43
52 /* Set IOBR for window containing area specified in pci.h */ 44 pci_write_reg(chan, 0x00000000, SH7780_PCIMBAR1);
53 pci_write_reg(PCIBIOS_MIN_IO & ~(SH7780_PCI_IO_SIZE-1), SH7780_PCIIOBR); 45 pci_write_reg(chan, 0x00000000, SH4_PCILAR1);
54 pci_write_reg((SH7780_PCI_IO_SIZE-1) & (7 << 18), SH7780_PCIIOBMR); 46 pci_write_reg(chan, 0x00000000, SH4_PCILSR1);
55 47
56 pci_write_reg(0xA5000C01, SH7780_PCICR); 48 pci_write_reg(chan, 0xAB000801, SH7780_PCIIBAR);
49 pci_write_reg(chan, 0xA5000C01, SH4_PCICR);
57 50
58 return 0; 51 return 0;
59} 52}
diff --git a/arch/sh/drivers/pci/fixups-se7751.c b/arch/sh/drivers/pci/fixups-se7751.c
new file mode 100644
index 000000000000..475fa9f0fe2c
--- /dev/null
+++ b/arch/sh/drivers/pci/fixups-se7751.c
@@ -0,0 +1,111 @@
1#include <linux/kernel.h>
2#include <linux/types.h>
3#include <linux/init.h>
4#include <linux/delay.h>
5#include <linux/pci.h>
6#include <linux/io.h>
7#include "pci-sh4.h"
8
9int __init pcibios_map_platform_irq(u8 slot, u8 pin)
10{
11 switch (slot) {
12 case 0: return 13;
13 case 1: return 13; /* AMD Ethernet controller */
14 case 2: return -1;
15 case 3: return -1;
16 case 4: return -1;
17 default:
18 printk("PCI: Bad IRQ mapping request for slot %d\n", slot);
19 return -1;
20 }
21}
22
23#define PCIMCR_MRSET_OFF 0xBFFFFFFF
24#define PCIMCR_RFSH_OFF 0xFFFFFFFB
25
26/*
27 * Only long word accesses of the PCIC's internal local registers and the
28 * configuration registers from the CPU is supported.
29 */
30#define PCIC_WRITE(x,v) writel((v), PCI_REG(x))
31#define PCIC_READ(x) readl(PCI_REG(x))
32
33/*
34 * Description: This function sets up and initializes the pcic, sets
35 * up the BARS, maps the DRAM into the address space etc, etc.
36 */
37int pci_fixup_pcic(struct pci_channel *chan)
38{
39 unsigned long bcr1, wcr1, wcr2, wcr3, mcr;
40 unsigned short bcr2;
41
42 /*
43 * Initialize the slave bus controller on the pcic. The values used
44 * here should not be hardcoded, but they should be taken from the bsc
45 * on the processor, to make this function as generic as possible.
46 * (i.e. Another sbc may usr different SDRAM timing settings -- in order
47 * for the pcic to work, its settings need to be exactly the same.)
48 */
49 bcr1 = (*(volatile unsigned long*)(SH7751_BCR1));
50 bcr2 = (*(volatile unsigned short*)(SH7751_BCR2));
51 wcr1 = (*(volatile unsigned long*)(SH7751_WCR1));
52 wcr2 = (*(volatile unsigned long*)(SH7751_WCR2));
53 wcr3 = (*(volatile unsigned long*)(SH7751_WCR3));
54 mcr = (*(volatile unsigned long*)(SH7751_MCR));
55
56 bcr1 = bcr1 | 0x00080000; /* Enable Bit 19, BREQEN */
57 (*(volatile unsigned long*)(SH7751_BCR1)) = bcr1;
58
59 bcr1 = bcr1 | 0x40080000; /* Enable Bit 19 BREQEN, set PCIC to slave */
60 PCIC_WRITE(SH7751_PCIBCR1, bcr1); /* PCIC BCR1 */
61 PCIC_WRITE(SH7751_PCIBCR2, bcr2); /* PCIC BCR2 */
62 PCIC_WRITE(SH7751_PCIWCR1, wcr1); /* PCIC WCR1 */
63 PCIC_WRITE(SH7751_PCIWCR2, wcr2); /* PCIC WCR2 */
64 PCIC_WRITE(SH7751_PCIWCR3, wcr3); /* PCIC WCR3 */
65 mcr = (mcr & PCIMCR_MRSET_OFF) & PCIMCR_RFSH_OFF;
66 PCIC_WRITE(SH7751_PCIMCR, mcr); /* PCIC MCR */
67
68
69 /* Enable all interrupts, so we know what to fix */
70 PCIC_WRITE(SH7751_PCIINTM, 0x0000c3ff);
71 PCIC_WRITE(SH7751_PCIAINTM, 0x0000380f);
72
73 /* Set up standard PCI config registers */
74 PCIC_WRITE(SH7751_PCICONF1, 0xF39000C7); /* Bus Master, Mem & I/O access */
75 PCIC_WRITE(SH7751_PCICONF2, 0x00000000); /* PCI Class code & Revision ID */
76 PCIC_WRITE(SH7751_PCICONF4, 0xab000001); /* PCI I/O address (local regs) */
77 PCIC_WRITE(SH7751_PCICONF5, 0x0c000000); /* PCI MEM address (local RAM) */
78 PCIC_WRITE(SH7751_PCICONF6, 0xd0000000); /* PCI MEM address (unused) */
79 PCIC_WRITE(SH7751_PCICONF11, 0x35051054); /* PCI Subsystem ID & Vendor ID */
80 PCIC_WRITE(SH7751_PCILSR0, 0x03f00000); /* MEM (full 64M exposed) */
81 PCIC_WRITE(SH7751_PCILSR1, 0x00000000); /* MEM (unused) */
82 PCIC_WRITE(SH7751_PCILAR0, 0x0c000000); /* MEM (direct map from PCI) */
83 PCIC_WRITE(SH7751_PCILAR1, 0x00000000); /* MEM (unused) */
84
85 /* Now turn it on... */
86 PCIC_WRITE(SH7751_PCICR, 0xa5000001);
87
88 /*
89 * Set PCIMBR and PCIIOBR here, assuming a single window
90 * (16M MEM, 256K IO) is enough. If a larger space is
91 * needed, the readx/writex and inx/outx functions will
92 * have to do more (e.g. setting registers for each call).
93 */
94
95 /*
96 * Set the MBR so PCI address is one-to-one with window,
97 * meaning all calls go straight through... use BUG_ON to
98 * catch erroneous assumption.
99 */
100 BUG_ON(chan->mem_resource->start != SH7751_PCI_MEMORY_BASE);
101
102 PCIC_WRITE(SH7751_PCIMBR, chan->mem_resource->start);
103
104 /* Set IOBR for window containing area specified in pci.h */
105 PCIC_WRITE(SH7751_PCIIOBR, (chan->io_resource->start & SH7751_PCIIOBR_MASK));
106
107 /* All done, may as well say so... */
108 printk("SH7751 PCI: Finished initialization of the PCI controller\n");
109
110 return 1;
111}
diff --git a/arch/sh/drivers/pci/fixups-se7780.c b/arch/sh/drivers/pci/fixups-se7780.c
deleted file mode 100644
index 880cea1c0d89..000000000000
--- a/arch/sh/drivers/pci/fixups-se7780.c
+++ /dev/null
@@ -1,60 +0,0 @@
1/*
2 * arch/sh/drivers/pci/fixups-se7780.c
3 *
4 * HITACHI UL Solution Engine 7780 PCI fixups
5 *
6 * Copyright (C) 2003 Lineo uSolutions, Inc.
7 * Copyright (C) 2004 - 2006 Paul Mundt
8 * Copyright (C) 2006 Nobuhiro Iwamatsu
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file "COPYING" in the main directory of this archive
12 * for more details.
13 */
14#include <linux/pci.h>
15#include "pci-sh4.h"
16#include <asm/io.h>
17
18int pci_fixup_pcic(void)
19{
20 ctrl_outl(0x00000001, SH7780_PCI_VCR2);
21
22 /* Enable all interrupts, so we know what to fix */
23 pci_write_reg(0x0000C3FF, SH7780_PCIIMR);
24 pci_write_reg(0x0000380F, SH7780_PCIAINTM);
25
26 /* Set up standard PCI config registers */
27 ctrl_outw(0xFB00, PCI_REG(SH7780_PCISTATUS));
28 ctrl_outw(0x0047, PCI_REG(SH7780_PCICMD));
29 ctrl_outb( 0x00, PCI_REG(SH7780_PCIPIF));
30 ctrl_outb( 0x00, PCI_REG(SH7780_PCISUB));
31 ctrl_outb( 0x06, PCI_REG(SH7780_PCIBCC));
32 ctrl_outw(0x1912, PCI_REG(SH7780_PCISVID));
33 ctrl_outw(0x0001, PCI_REG(SH7780_PCISID));
34
35 pci_write_reg(0x08000000, SH7780_PCIMBAR0); /* PCI */
36 pci_write_reg(0x08000000, SH7780_PCILAR0); /* SHwy */
37 pci_write_reg(0x07F00001, SH7780_PCILSR); /* size 128M w/ MBAR */
38
39 pci_write_reg(0x00000000, SH7780_PCIMBAR1);
40 pci_write_reg(0x00000000, SH7780_PCILAR1);
41 pci_write_reg(0x00000000, SH7780_PCILSR1);
42
43 pci_write_reg(0xAB000801, SH7780_PCIIBAR);
44
45 /*
46 * Set the MBR so PCI address is one-to-one with window,
47 * meaning all calls go straight through... use ifdef to
48 * catch erroneous assumption.
49 */
50 pci_write_reg(0xFD000000 , SH7780_PCIMBR0);
51 pci_write_reg(0x00FC0000 , SH7780_PCIMBMR0); /* 16M */
52
53 /* Set IOBR for window containing area specified in pci.h */
54 pci_write_reg(PCIBIOS_MIN_IO & ~(SH7780_PCI_IO_SIZE-1), SH7780_PCIIOBR);
55 pci_write_reg((SH7780_PCI_IO_SIZE-1) & (7 << 18), SH7780_PCIIOBMR);
56
57 pci_write_reg(0xA5000C01, SH7780_PCICR);
58
59 return 0;
60}
diff --git a/arch/sh/drivers/pci/fixups-sh7785lcr.c b/arch/sh/drivers/pci/fixups-sh7785lcr.c
deleted file mode 100644
index 4949e601387a..000000000000
--- a/arch/sh/drivers/pci/fixups-sh7785lcr.c
+++ /dev/null
@@ -1,46 +0,0 @@
1/*
2 * arch/sh/drivers/pci/fixups-sh7785lcr.c
3 *
4 * R0P7785LC0011RL PCI fixups
5 * Copyright (C) 2008 Yoshihiro Shimoda
6 *
7 * Based on arch/sh/drivers/pci/fixups-r7780rp.c
8 * Copyright (C) 2003 Lineo uSolutions, Inc.
9 * Copyright (C) 2004 - 2006 Paul Mundt
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
13 * for more details.
14 */
15#include <linux/pci.h>
16#include "pci-sh4.h"
17
18int pci_fixup_pcic(void)
19{
20 pci_write_reg(0x000043ff, SH4_PCIINTM);
21 pci_write_reg(0x0000380f, SH4_PCIAINTM);
22
23 pci_write_reg(0xfbb00047, SH7780_PCICMD);
24 pci_write_reg(0x00000000, SH7780_PCIIBAR);
25
26 pci_write_reg(0x00011912, SH7780_PCISVID);
27 pci_write_reg(0x08000000, SH7780_PCICSCR0);
28 pci_write_reg(0x0000001b, SH7780_PCICSAR0);
29 pci_write_reg(0xfd000000, SH7780_PCICSCR1);
30 pci_write_reg(0x0000000f, SH7780_PCICSAR1);
31
32 pci_write_reg(0xfd000000, SH7780_PCIMBR0);
33 pci_write_reg(0x00fc0000, SH7780_PCIMBMR0);
34
35#ifdef CONFIG_32BIT
36 pci_write_reg(0xc0000000, SH7780_PCIMBR2);
37 pci_write_reg(0x20000000 - SH7780_PCI_IO_SIZE, SH7780_PCIMBMR2);
38#endif
39
40 /* Set IOBR for windows containing area specified in pci.h */
41 pci_write_reg((PCIBIOS_MIN_IO & ~(SH7780_PCI_IO_SIZE - 1)),
42 SH7780_PCIIOBR);
43 pci_write_reg(((SH7780_PCI_IO_SIZE - 1) & (7 << 18)), SH7780_PCIIOBMR);
44
45 return 0;
46}
diff --git a/arch/sh/drivers/pci/fixups-snapgear.c b/arch/sh/drivers/pci/fixups-snapgear.c
new file mode 100644
index 000000000000..5a39ecc1adb8
--- /dev/null
+++ b/arch/sh/drivers/pci/fixups-snapgear.c
@@ -0,0 +1,38 @@
1/*
2 * arch/sh/drivers/pci/ops-snapgear.c
3 *
4 * Author: David McCullough <davidm@snapgear.com>
5 *
6 * Ported to new API by Paul Mundt <lethal@linux-sh.org>
7 *
8 * Highly leveraged from pci-bigsur.c, written by Dustin McIntire.
9 *
10 * May be copied or modified under the terms of the GNU General Public
11 * License. See linux/COPYING for more information.
12 *
13 * PCI initialization for the SnapGear boards
14 */
15#include <linux/kernel.h>
16#include <linux/types.h>
17#include <linux/init.h>
18#include <linux/pci.h>
19#include "pci-sh4.h"
20
21int __init pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin)
22{
23 int irq = -1;
24
25 switch (slot) {
26 case 8: /* the PCI bridge */ break;
27 case 11: irq = 8; break; /* USB */
28 case 12: irq = 11; break; /* PCMCIA */
29 case 13: irq = 5; break; /* eth0 */
30 case 14: irq = 8; break; /* eth1 */
31 case 15: irq = 11; break; /* safenet (unused) */
32 }
33
34 printk("PCI: Mapping SnapGear IRQ for slot %d, pin %c to irq %d\n",
35 slot, pin - 1 + 'A', irq);
36
37 return irq;
38}
diff --git a/arch/sh/drivers/pci/ops-titan.c b/arch/sh/drivers/pci/fixups-titan.c
index a8f7801a34af..3a79fa8254a6 100644
--- a/arch/sh/drivers/pci/ops-titan.c
+++ b/arch/sh/drivers/pci/fixups-titan.c
@@ -36,42 +36,3 @@ int __init pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin)
36 36
37 return irq; 37 return irq;
38} 38}
39
40static struct resource sh7751_io_resource = {
41 .name = "SH7751_IO",
42 .start = SH7751_PCI_IO_BASE,
43 .end = SH7751_PCI_IO_BASE + SH7751_PCI_IO_SIZE - 1,
44 .flags = IORESOURCE_IO
45};
46
47static struct resource sh7751_mem_resource = {
48 .name = "SH7751_mem",
49 .start = SH7751_PCI_MEMORY_BASE,
50 .end = SH7751_PCI_MEMORY_BASE + SH7751_PCI_MEM_SIZE - 1,
51 .flags = IORESOURCE_MEM
52};
53
54struct pci_channel board_pci_channels[] = {
55 { &sh4_pci_ops, &sh7751_io_resource, &sh7751_mem_resource, 0, 0xff },
56 { NULL, NULL, NULL, 0, 0 },
57};
58EXPORT_SYMBOL(board_pci_channels);
59
60static struct sh4_pci_address_map sh7751_pci_map = {
61 .window0 = {
62 .base = SH7751_CS2_BASE_ADDR,
63 .size = SH7751_MEM_REGION_SIZE*2, /* cs2 and cs3 */
64 },
65
66 .window1 = {
67 .base = SH7751_CS2_BASE_ADDR,
68 .size = SH7751_MEM_REGION_SIZE*2,
69 },
70
71 .flags = SH4_PCIC_NO_RESET,
72};
73
74int __init pcibios_init_platform(void)
75{
76 return sh7751_pcic_init(&sh7751_pci_map);
77}
diff --git a/arch/sh/drivers/pci/ops-dreamcast.c b/arch/sh/drivers/pci/ops-dreamcast.c
index f5d2a2aa6f3f..e83d0d3aabe2 100644
--- a/arch/sh/drivers/pci/ops-dreamcast.c
+++ b/arch/sh/drivers/pci/ops-dreamcast.c
@@ -1,15 +1,9 @@
1/* 1/*
2 * arch/sh/drivers/pci/ops-dreamcast.c
3 *
4 * PCI operations for the Sega Dreamcast 2 * PCI operations for the Sega Dreamcast
5 * 3 *
6 * Copyright (C) 2001, 2002 M. R. Brown 4 * Copyright (C) 2001, 2002 M. R. Brown
7 * Copyright (C) 2002, 2003 Paul Mundt 5 * Copyright (C) 2002, 2003 Paul Mundt
8 * 6 *
9 * This file originally bore the message (with enclosed-$):
10 * Id: pci.c,v 1.3 2003/05/04 19:29:46 lethal Exp
11 * Dreamcast PCI: Supports SEGA Broadband Adaptor only.
12 *
13 * This file is subject to the terms and conditions of the GNU General Public 7 * This file is subject to the terms and conditions of the GNU General Public
14 * License. See the file "COPYING" in the main directory of this archive 8 * License. See the file "COPYING" in the main directory of this archive
15 * for more details. 9 * for more details.
@@ -23,34 +17,10 @@
23#include <linux/irq.h> 17#include <linux/irq.h>
24#include <linux/pci.h> 18#include <linux/pci.h>
25#include <linux/module.h> 19#include <linux/module.h>
26 20#include <linux/io.h>
27#include <asm/io.h> 21#include <linux/irq.h>
28#include <asm/irq.h>
29#include <mach/pci.h> 22#include <mach/pci.h>
30 23
31static struct resource gapspci_io_resource = {
32 .name = "GAPSPCI IO",
33 .start = GAPSPCI_BBA_CONFIG,
34 .end = GAPSPCI_BBA_CONFIG + GAPSPCI_BBA_CONFIG_SIZE - 1,
35 .flags = IORESOURCE_IO,
36};
37
38static struct resource gapspci_mem_resource = {
39 .name = "GAPSPCI mem",
40 .start = GAPSPCI_DMA_BASE,
41 .end = GAPSPCI_DMA_BASE + GAPSPCI_DMA_SIZE - 1,
42 .flags = IORESOURCE_MEM,
43};
44
45static struct pci_ops gapspci_pci_ops;
46
47struct pci_channel board_pci_channels[] = {
48 { &gapspci_pci_ops, &gapspci_io_resource,
49 &gapspci_mem_resource, 0, 1 },
50 { 0, }
51};
52EXPORT_SYMBOL(board_pci_channels);
53
54/* 24/*
55 * The !gapspci_config_access case really shouldn't happen, ever, unless 25 * The !gapspci_config_access case really shouldn't happen, ever, unless
56 * someone implicitly messes around with the last devfn value.. otherwise we 26 * someone implicitly messes around with the last devfn value.. otherwise we
@@ -85,10 +55,10 @@ static int gapspci_read(struct pci_bus *bus, unsigned int devfn, int where, int
85 return PCIBIOS_DEVICE_NOT_FOUND; 55 return PCIBIOS_DEVICE_NOT_FOUND;
86 56
87 switch (size) { 57 switch (size) {
88 case 1: *val = inb(GAPSPCI_BBA_CONFIG+where); break; 58 case 1: *val = inb(GAPSPCI_BBA_CONFIG+where); break;
89 case 2: *val = inw(GAPSPCI_BBA_CONFIG+where); break; 59 case 2: *val = inw(GAPSPCI_BBA_CONFIG+where); break;
90 case 4: *val = inl(GAPSPCI_BBA_CONFIG+where); break; 60 case 4: *val = inl(GAPSPCI_BBA_CONFIG+where); break;
91 } 61 }
92 62
93 return PCIBIOS_SUCCESSFUL; 63 return PCIBIOS_SUCCESSFUL;
94} 64}
@@ -99,72 +69,15 @@ static int gapspci_write(struct pci_bus *bus, unsigned int devfn, int where, int
99 return PCIBIOS_DEVICE_NOT_FOUND; 69 return PCIBIOS_DEVICE_NOT_FOUND;
100 70
101 switch (size) { 71 switch (size) {
102 case 1: outb(( u8)val, GAPSPCI_BBA_CONFIG+where); break; 72 case 1: outb(( u8)val, GAPSPCI_BBA_CONFIG+where); break;
103 case 2: outw((u16)val, GAPSPCI_BBA_CONFIG+where); break; 73 case 2: outw((u16)val, GAPSPCI_BBA_CONFIG+where); break;
104 case 4: outl((u32)val, GAPSPCI_BBA_CONFIG+where); break; 74 case 4: outl((u32)val, GAPSPCI_BBA_CONFIG+where); break;
105 } 75 }
106 76
107 return PCIBIOS_SUCCESSFUL; 77 return PCIBIOS_SUCCESSFUL;
108} 78}
109 79
110static struct pci_ops gapspci_pci_ops = { 80struct pci_ops gapspci_pci_ops = {
111 .read = gapspci_read, 81 .read = gapspci_read,
112 .write = gapspci_write, 82 .write = gapspci_write,
113}; 83};
114
115/*
116 * gapspci init
117 */
118
119int __init gapspci_init(void)
120{
121 char idbuf[16];
122 int i;
123
124 /*
125 * FIXME: All of this wants documenting to some degree,
126 * even some basic register definitions would be nice.
127 *
128 * I haven't seen anything this ugly since.. maple.
129 */
130
131 for (i=0; i<16; i++)
132 idbuf[i] = inb(GAPSPCI_REGS+i);
133
134 if (strncmp(idbuf, "GAPSPCI_BRIDGE_2", 16))
135 return -ENODEV;
136
137 outl(0x5a14a501, GAPSPCI_REGS+0x18);
138
139 for (i=0; i<1000000; i++)
140 ;
141
142 if (inl(GAPSPCI_REGS+0x18) != 1)
143 return -EINVAL;
144
145 outl(0x01000000, GAPSPCI_REGS+0x20);
146 outl(0x01000000, GAPSPCI_REGS+0x24);
147
148 outl(GAPSPCI_DMA_BASE, GAPSPCI_REGS+0x28);
149 outl(GAPSPCI_DMA_BASE+GAPSPCI_DMA_SIZE, GAPSPCI_REGS+0x2c);
150
151 outl(1, GAPSPCI_REGS+0x14);
152 outl(1, GAPSPCI_REGS+0x34);
153
154 /* Setting Broadband Adapter */
155 outw(0xf900, GAPSPCI_BBA_CONFIG+0x06);
156 outl(0x00000000, GAPSPCI_BBA_CONFIG+0x30);
157 outb(0x00, GAPSPCI_BBA_CONFIG+0x3c);
158 outb(0xf0, GAPSPCI_BBA_CONFIG+0x0d);
159 outw(0x0006, GAPSPCI_BBA_CONFIG+0x04);
160 outl(0x00002001, GAPSPCI_BBA_CONFIG+0x10);
161 outl(0x01000000, GAPSPCI_BBA_CONFIG+0x14);
162
163 return 0;
164}
165
166/* Haven't done anything here as yet */
167char * __devinit pcibios_setup(char *str)
168{
169 return str;
170}
diff --git a/arch/sh/drivers/pci/ops-lboxre2.c b/arch/sh/drivers/pci/ops-lboxre2.c
deleted file mode 100644
index 86c0b6fb7375..000000000000
--- a/arch/sh/drivers/pci/ops-lboxre2.c
+++ /dev/null
@@ -1,63 +0,0 @@
1/*
2 * linux/arch/sh/drivers/pci/ops-lboxre2.c
3 *
4 * Copyright (C) 2007 Nobuhiro Iwamatsu
5 *
6 * PCI initialization for the NTT COMWARE L-BOX RE2
7 */
8#include <linux/kernel.h>
9#include <linux/types.h>
10#include <linux/init.h>
11#include <linux/pci.h>
12#include <linux/io.h>
13#include <mach/lboxre2.h>
14#include "pci-sh4.h"
15
16static char lboxre2_irq_tab[] __initdata = {
17 IRQ_ETH0, IRQ_ETH1, IRQ_INTA, IRQ_INTD,
18};
19
20int __init pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin)
21{
22 return lboxre2_irq_tab[slot];
23}
24
25static struct resource sh7751_io_resource = {
26 .name = "SH7751_IO",
27 .start = SH7751_PCI_IO_BASE ,
28 .end = SH7751_PCI_IO_BASE + SH7751_PCI_IO_SIZE - 1,
29 .flags = IORESOURCE_IO
30};
31
32static struct resource sh7751_mem_resource = {
33 .name = "SH7751_mem",
34 .start = SH7751_PCI_MEMORY_BASE,
35 .end = SH7751_PCI_MEMORY_BASE + SH7751_PCI_MEM_SIZE - 1,
36 .flags = IORESOURCE_MEM
37};
38
39extern struct pci_ops sh7751_pci_ops;
40
41struct pci_channel board_pci_channels[] = {
42 { &sh4_pci_ops, &sh7751_io_resource, &sh7751_mem_resource, 0, 0xff },
43 { NULL, NULL, NULL, 0, 0 },
44};
45
46EXPORT_SYMBOL(board_pci_channels);
47
48static struct sh4_pci_address_map sh7751_pci_map = {
49 .window0 = {
50 .base = SH7751_CS3_BASE_ADDR,
51 .size = 0x04000000,
52 },
53 .window1 = {
54 .base = 0x00000000, /* Unused */
55 .size = 0x00000000, /* Unused */
56 },
57 .flags = SH4_PCIC_NO_RESET,
58};
59
60int __init pcibios_init_platform(void)
61{
62 return sh7751_pcic_init(&sh7751_pci_map);
63}
diff --git a/arch/sh/drivers/pci/ops-r7780rp.c b/arch/sh/drivers/pci/ops-r7780rp.c
deleted file mode 100644
index 8555238e63eb..000000000000
--- a/arch/sh/drivers/pci/ops-r7780rp.c
+++ /dev/null
@@ -1,68 +0,0 @@
1/*
2 * Author: Ian DaSilva (idasilva@mvista.com)
3 *
4 * Highly leveraged from pci-bigsur.c, written by Dustin McIntire.
5 *
6 * May be copied or modified under the terms of the GNU General Public
7 * License. See linux/COPYING for more information.
8 *
9 * PCI initialization for the Renesas SH7780 Highlander R7780RP-1 board
10 */
11#include <linux/kernel.h>
12#include <linux/types.h>
13#include <linux/init.h>
14#include <linux/delay.h>
15#include <linux/pci.h>
16#include <mach/highlander.h>
17#include <asm/io.h>
18#include "pci-sh4.h"
19
20static char irq_tab[] __initdata = {
21 65, 66, 67, 68,
22};
23
24int __init pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin)
25{
26 return irq_tab[slot];
27}
28
29static struct resource sh7780_io_resource = {
30 .name = "SH7780_IO",
31 .start = SH7780_PCI_IO_BASE,
32 .end = SH7780_PCI_IO_BASE + SH7780_PCI_IO_SIZE - 1,
33 .flags = IORESOURCE_IO
34};
35
36static struct resource sh7780_mem_resource = {
37 .name = "SH7780_mem",
38 .start = SH7780_PCI_MEMORY_BASE,
39 .end = SH7780_PCI_MEMORY_BASE + SH7780_PCI_MEM_SIZE - 1,
40 .flags = IORESOURCE_MEM
41};
42
43extern struct pci_ops sh7780_pci_ops;
44
45struct pci_channel board_pci_channels[] = {
46 { &sh4_pci_ops, &sh7780_io_resource, &sh7780_mem_resource, 0, 0xff },
47 { NULL, NULL, NULL, 0, 0 },
48};
49EXPORT_SYMBOL(board_pci_channels);
50
51static struct sh4_pci_address_map sh7780_pci_map = {
52 .window0 = {
53 .base = SH7780_CS2_BASE_ADDR,
54 .size = 0x04000000,
55 },
56
57 .window1 = {
58 .base = SH7780_CS3_BASE_ADDR,
59 .size = 0x04000000,
60 },
61
62 .flags = SH4_PCIC_NO_RESET,
63};
64
65int __init pcibios_init_platform(void)
66{
67 return sh7780_pcic_init(&sh7780_pci_map);
68}
diff --git a/arch/sh/drivers/pci/ops-rts7751r2d.c b/arch/sh/drivers/pci/ops-rts7751r2d.c
deleted file mode 100644
index d6ca74b25d5f..000000000000
--- a/arch/sh/drivers/pci/ops-rts7751r2d.c
+++ /dev/null
@@ -1,74 +0,0 @@
1/*
2 * linux/arch/sh/drivers/pci/ops-rts7751r2d.c
3 *
4 * Author: Ian DaSilva (idasilva@mvista.com)
5 *
6 * Highly leveraged from pci-bigsur.c, written by Dustin McIntire.
7 *
8 * May be copied or modified under the terms of the GNU General Public
9 * License. See linux/COPYING for more information.
10 *
11 * PCI initialization for the Renesas SH7751R RTS7751R2D board
12 */
13#include <linux/kernel.h>
14#include <linux/types.h>
15#include <linux/init.h>
16#include <linux/pci.h>
17#include <linux/io.h>
18#include <mach/r2d.h>
19#include "pci-sh4.h"
20
21static u8 rts7751r2d_irq_tab[] __initdata = {
22 IRQ_PCI_INTA,
23 IRQ_PCI_INTB,
24 IRQ_PCI_INTC,
25 IRQ_PCI_INTD,
26};
27
28int __init pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin)
29{
30 return rts7751r2d_irq_tab[slot];
31}
32
33static struct resource sh7751_io_resource = {
34 .name = "SH7751_IO",
35 .start = 0x4000,
36 .end = SH7751_PCI_IO_SIZE - 1,
37 .flags = IORESOURCE_IO
38};
39
40static struct resource sh7751_mem_resource = {
41 .name = "SH7751_mem",
42 .start = SH7751_PCI_MEMORY_BASE,
43 .end = SH7751_PCI_MEMORY_BASE + SH7751_PCI_MEM_SIZE - 1,
44 .flags = IORESOURCE_MEM
45};
46
47extern struct pci_ops sh7751_pci_ops;
48
49struct pci_channel board_pci_channels[] = {
50 { &sh4_pci_ops, &sh7751_io_resource, &sh7751_mem_resource, 0, 0xff },
51 { NULL, NULL, NULL, 0, 0 },
52};
53EXPORT_SYMBOL(board_pci_channels);
54
55static struct sh4_pci_address_map sh7751_pci_map = {
56 .window0 = {
57 .base = SH7751_CS3_BASE_ADDR,
58 .size = 0x04000000,
59 },
60
61 .window1 = {
62 .base = 0x00000000, /* Unused */
63 .size = 0x00000000, /* Unused */
64 },
65
66 .flags = SH4_PCIC_NO_RESET,
67};
68
69int __init pcibios_init_platform(void)
70{
71 __set_io_port_base(SH7751_PCI_IO_BASE);
72 return sh7751_pcic_init(&sh7751_pci_map);
73}
74
diff --git a/arch/sh/drivers/pci/ops-sdk7780.c b/arch/sh/drivers/pci/ops-sdk7780.c
deleted file mode 100644
index 4dcc64184b23..000000000000
--- a/arch/sh/drivers/pci/ops-sdk7780.c
+++ /dev/null
@@ -1,73 +0,0 @@
1/*
2 * linux/arch/sh/drivers/pci/ops-sdk7780.c
3 *
4 * Copyright (C) 2006 Nobuhiro Iwamatsu
5 *
6 * PCI initialization for the SDK7780SE03
7 *
8 * May be copied or modified under the terms of the GNU General Public
9 * License. See linux/COPYING for more information.
10 */
11#include <linux/kernel.h>
12#include <linux/types.h>
13#include <linux/init.h>
14#include <linux/delay.h>
15#include <linux/pci.h>
16#include <mach/sdk7780.h>
17#include <asm/io.h>
18#include "pci-sh4.h"
19
20/* IDSEL [16][17][18][19][20][21][22][23][24][25][26][27][28][29][30][31] */
21static char sdk7780_irq_tab[4][16] __initdata = {
22 /* INTA */
23 { 65, 68, 67, 68, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
24 /* INTB */
25 { 66, 65, -1, 65, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
26 /* INTC */
27 { 67, 66, -1, 66, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
28 /* INTD */
29 { 68, 67, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
30};
31
32int __init pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin)
33{
34 return sdk7780_irq_tab[pin-1][slot];
35}
36
37static struct resource sdk7780_io_resource = {
38 .name = "SH7780_IO",
39 .start = SH7780_PCI_IO_BASE,
40 .end = SH7780_PCI_IO_BASE + SH7780_PCI_IO_SIZE - 1,
41 .flags = IORESOURCE_IO
42};
43
44static struct resource sdk7780_mem_resource = {
45 .name = "SH7780_mem",
46 .start = SH7780_PCI_MEMORY_BASE,
47 .end = SH7780_PCI_MEMORY_BASE + SH7780_PCI_MEM_SIZE - 1,
48 .flags = IORESOURCE_MEM
49};
50
51struct pci_channel board_pci_channels[] = {
52 { &sh4_pci_ops, &sdk7780_io_resource, &sdk7780_mem_resource, 0, 0xff },
53 { NULL, NULL, NULL, 0, 0 },
54};
55EXPORT_SYMBOL(board_pci_channels);
56
57static struct sh4_pci_address_map sdk7780_pci_map = {
58 .window0 = {
59 .base = SH7780_CS2_BASE_ADDR,
60 .size = 0x04000000,
61 },
62 .window1 = {
63 .base = SH7780_CS3_BASE_ADDR,
64 .size = 0x04000000,
65 },
66 .flags = SH4_PCIC_NO_RESET,
67};
68
69int __init pcibios_init_platform(void)
70{
71 printk(KERN_INFO "SH7780 PCI: Finished initializing PCI controller\n");
72 return sh7780_pcic_init(&sdk7780_pci_map);
73}
diff --git a/arch/sh/drivers/pci/ops-se7780.c b/arch/sh/drivers/pci/ops-se7780.c
deleted file mode 100644
index 3145c62484d6..000000000000
--- a/arch/sh/drivers/pci/ops-se7780.c
+++ /dev/null
@@ -1,96 +0,0 @@
1/*
2 * linux/arch/sh/drivers/pci/ops-se7780.c
3 *
4 * Copyright (C) 2006 Nobuhiro Iwamatsu
5 *
6 * PCI initialization for the Hitachi UL Solution Engine 7780SE03
7 *
8 * May be copied or modified under the terms of the GNU General Public
9 * License. See linux/COPYING for more information.
10 */
11#include <linux/kernel.h>
12#include <linux/types.h>
13#include <linux/init.h>
14#include <linux/delay.h>
15#include <linux/pci.h>
16#include <mach-se/mach/se7780.h>
17#include <asm/io.h>
18#include "pci-sh4.h"
19
20/*
21 * IDSEL = AD16 PCI slot
22 * IDSEL = AD17 PCI slot
23 * IDSEL = AD18 Serial ATA Controller (Silicon Image SiL3512A)
24 * IDSEL = AD19 USB Host Controller (NEC uPD7210100A)
25 */
26
27/* IDSEL [16][17][18][19][20][21][22][23][24][25][26][27][28][29][30][31] */
28static char se7780_irq_tab[4][16] __initdata = {
29 /* INTA */
30 { 65, 68, 67, 68, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
31 /* INTB */
32 { 66, 65, -1, 65, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
33 /* INTC */
34 { 67, 66, -1, 66, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
35 /* INTD */
36 { 68, 67, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 },
37};
38
39int __init pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin)
40{
41 return se7780_irq_tab[pin-1][slot];
42}
43
44static struct resource se7780_io_resource = {
45 .name = "SH7780_IO",
46 .start = SH7780_PCI_IO_BASE,
47 .end = SH7780_PCI_IO_BASE + SH7780_PCI_IO_SIZE - 1,
48 .flags = IORESOURCE_IO
49};
50
51static struct resource se7780_mem_resource = {
52 .name = "SH7780_mem",
53 .start = SH7780_PCI_MEMORY_BASE,
54 .end = SH7780_PCI_MEMORY_BASE + SH7780_PCI_MEM_SIZE - 1,
55 .flags = IORESOURCE_MEM
56};
57
58extern struct pci_ops se7780_pci_ops;
59
60struct pci_channel board_pci_channels[] = {
61 { &sh4_pci_ops, &se7780_io_resource, &se7780_mem_resource, 0, 0xff },
62 { NULL, NULL, NULL, 0, 0 },
63};
64EXPORT_SYMBOL(board_pci_channels);
65
66static struct sh4_pci_address_map se7780_pci_map = {
67 .window0 = {
68 .base = SH7780_CS2_BASE_ADDR,
69 .size = 0x04000000,
70 },
71 .flags = SH4_PCIC_NO_RESET,
72};
73
74int __init pcibios_init_platform(void)
75{
76 printk("SH7780 PCI: Finished initialization of the PCI controller\n");
77
78 /*
79 * FPGA PCISEL register initialize
80 *
81 * CPU || SLOT1 | SLOT2 | S-ATA | USB
82 * -------------------------------------
83 * INTA || INTA | INTD | -- | INTB
84 * -------------------------------------
85 * INTB || INTB | INTA | -- | INTC
86 * -------------------------------------
87 * INTC || INTC | INTB | INTA | --
88 * -------------------------------------
89 * INTD || INTD | INTC | -- | INTA
90 * -------------------------------------
91 */
92 ctrl_outw(0x0013, FPGA_PCI_INTSEL1);
93 ctrl_outw(0xE402, FPGA_PCI_INTSEL2);
94
95 return sh7780_pcic_init(&se7780_pci_map);
96}
diff --git a/arch/sh/drivers/pci/ops-sh03.c b/arch/sh/drivers/pci/ops-sh03.c
deleted file mode 100644
index e1703ff5a4d2..000000000000
--- a/arch/sh/drivers/pci/ops-sh03.c
+++ /dev/null
@@ -1,45 +0,0 @@
1/*
2 * linux/arch/sh/drivers/pci/ops-sh03.c
3 *
4 * PCI initialization for the Interface CTP/PCI-SH03 board
5 */
6
7#include <linux/kernel.h>
8#include <linux/types.h>
9#include <linux/init.h>
10#include <linux/delay.h>
11#include <linux/pci.h>
12#include <asm/io.h>
13#include "pci-sh7751.h"
14
15/*
16 * Description: This function sets up and initializes the pcic, sets
17 * up the BARS, maps the DRAM into the address space etc, etc.
18 */
19int __init pcibios_init_platform(void)
20{
21 __set_io_port_base(SH7751_PCI_IO_BASE);
22 return 1;
23}
24
25static struct resource sh7751_io_resource = {
26 .name = "SH03 IO",
27 .start = SH7751_PCI_IO_BASE,
28 .end = SH7751_PCI_IO_BASE + SH7751_PCI_IO_SIZE - 1,
29 .flags = IORESOURCE_IO
30};
31
32static struct resource sh7751_mem_resource = {
33 .name = "SH03 mem",
34 .start = SH7751_PCI_MEMORY_BASE,
35 .end = SH7751_PCI_MEMORY_BASE + SH7751_PCI_MEM_SIZE - 1,
36 .flags = IORESOURCE_MEM
37};
38
39extern struct pci_ops sh4_pci_ops;
40
41struct pci_channel board_pci_channels[] = {
42 { &sh4_pci_ops, &sh7751_io_resource, &sh7751_mem_resource, 0, 0xff },
43 { NULL, NULL, NULL, 0, 0 },
44};
45
diff --git a/arch/sh/drivers/pci/ops-sh4.c b/arch/sh/drivers/pci/ops-sh4.c
index 710a3b0306e5..78bebebdc99c 100644
--- a/arch/sh/drivers/pci/ops-sh4.c
+++ b/arch/sh/drivers/pci/ops-sh4.c
@@ -1,22 +1,22 @@
1/* 1/*
2 * Generic SH-4 / SH-4A PCIC operations (SH7751, SH7780). 2 * Generic SH-4 / SH-4A PCIC operations (SH7751, SH7780).
3 * 3 *
4 * Copyright (C) 2002 - 2006 Paul Mundt 4 * Copyright (C) 2002 - 2009 Paul Mundt
5 * 5 *
6 * This file is subject to the terms and conditions of the GNU General Public 6 * This file is subject to the terms and conditions of the GNU General Public
7 * License v2. See the file "COPYING" in the main directory of this archive 7 * License v2. See the file "COPYING" in the main directory of this archive
8 * for more details. 8 * for more details.
9 */ 9 */
10#include <linux/pci.h> 10#include <linux/pci.h>
11#include <linux/io.h>
11#include <asm/addrspace.h> 12#include <asm/addrspace.h>
12#include <asm/io.h>
13#include "pci-sh4.h" 13#include "pci-sh4.h"
14 14
15/* 15/*
16 * Direct access to PCI hardware... 16 * Direct access to PCI hardware...
17 */ 17 */
18#define CONFIG_CMD(bus, devfn, where) \ 18#define CONFIG_CMD(bus, devfn, where) \
19 P1SEGADDR((bus->number << 16) | (devfn << 8) | (where & ~3)) 19 (P1SEG | (bus->number << 16) | (devfn << 8) | (where & ~3))
20 20
21static DEFINE_SPINLOCK(sh4_pci_lock); 21static DEFINE_SPINLOCK(sh4_pci_lock);
22 22
@@ -26,6 +26,7 @@ static DEFINE_SPINLOCK(sh4_pci_lock);
26static int sh4_pci_read(struct pci_bus *bus, unsigned int devfn, 26static int sh4_pci_read(struct pci_bus *bus, unsigned int devfn,
27 int where, int size, u32 *val) 27 int where, int size, u32 *val)
28{ 28{
29 struct pci_channel *chan = bus->sysdata;
29 unsigned long flags; 30 unsigned long flags;
30 u32 data; 31 u32 data;
31 32
@@ -34,8 +35,8 @@ static int sh4_pci_read(struct pci_bus *bus, unsigned int devfn,
34 * so we must do byte alignment by hand 35 * so we must do byte alignment by hand
35 */ 36 */
36 spin_lock_irqsave(&sh4_pci_lock, flags); 37 spin_lock_irqsave(&sh4_pci_lock, flags);
37 pci_write_reg(CONFIG_CMD(bus, devfn, where), SH4_PCIPAR); 38 pci_write_reg(chan, CONFIG_CMD(bus, devfn, where), SH4_PCIPAR);
38 data = pci_read_reg(SH4_PCIPDR); 39 data = pci_read_reg(chan, SH4_PCIPDR);
39 spin_unlock_irqrestore(&sh4_pci_lock, flags); 40 spin_unlock_irqrestore(&sh4_pci_lock, flags);
40 41
41 switch (size) { 42 switch (size) {
@@ -63,13 +64,14 @@ static int sh4_pci_read(struct pci_bus *bus, unsigned int devfn,
63static int sh4_pci_write(struct pci_bus *bus, unsigned int devfn, 64static int sh4_pci_write(struct pci_bus *bus, unsigned int devfn,
64 int where, int size, u32 val) 65 int where, int size, u32 val)
65{ 66{
67 struct pci_channel *chan = bus->sysdata;
66 unsigned long flags; 68 unsigned long flags;
67 int shift; 69 int shift;
68 u32 data; 70 u32 data;
69 71
70 spin_lock_irqsave(&sh4_pci_lock, flags); 72 spin_lock_irqsave(&sh4_pci_lock, flags);
71 pci_write_reg(CONFIG_CMD(bus, devfn, where), SH4_PCIPAR); 73 pci_write_reg(chan, CONFIG_CMD(bus, devfn, where), SH4_PCIPAR);
72 data = pci_read_reg(SH4_PCIPDR); 74 data = pci_read_reg(chan, SH4_PCIPDR);
73 spin_unlock_irqrestore(&sh4_pci_lock, flags); 75 spin_unlock_irqrestore(&sh4_pci_lock, flags);
74 76
75 switch (size) { 77 switch (size) {
@@ -90,7 +92,7 @@ static int sh4_pci_write(struct pci_bus *bus, unsigned int devfn,
90 return PCIBIOS_FUNC_NOT_SUPPORTED; 92 return PCIBIOS_FUNC_NOT_SUPPORTED;
91 } 93 }
92 94
93 pci_write_reg(data, SH4_PCIPDR); 95 pci_write_reg(chan, data, SH4_PCIPDR);
94 96
95 return PCIBIOS_SUCCESSFUL; 97 return PCIBIOS_SUCCESSFUL;
96} 98}
@@ -104,66 +106,31 @@ struct pci_ops sh4_pci_ops = {
104 * Not really related to pci_ops, but it's common and not worth shoving 106 * Not really related to pci_ops, but it's common and not worth shoving
105 * somewhere else for now.. 107 * somewhere else for now..
106 */ 108 */
107static unsigned int pci_probe = PCI_PROBE_CONF1; 109int __init sh4_pci_check_direct(struct pci_channel *chan)
108
109int __init sh4_pci_check_direct(void)
110{ 110{
111 /* 111 /*
112 * Check if configuration works. 112 * Check if configuration works.
113 */ 113 */
114 if (pci_probe & PCI_PROBE_CONF1) { 114 unsigned int tmp = pci_read_reg(chan, SH4_PCIPAR);
115 unsigned int tmp = pci_read_reg(SH4_PCIPAR);
116
117 pci_write_reg(P1SEG, SH4_PCIPAR);
118 115
119 if (pci_read_reg(SH4_PCIPAR) == P1SEG) { 116 pci_write_reg(chan, P1SEG, SH4_PCIPAR);
120 pci_write_reg(tmp, SH4_PCIPAR);
121 printk(KERN_INFO "PCI: Using configuration type 1\n");
122 request_region(PCI_REG(SH4_PCIPAR), 8, "PCI conf1");
123 117
124 return 0; 118 if (pci_read_reg(chan, SH4_PCIPAR) == P1SEG) {
125 } 119 pci_write_reg(chan, tmp, SH4_PCIPAR);
126 120 printk(KERN_INFO "PCI: Using configuration type 1\n");
127 pci_write_reg(tmp, SH4_PCIPAR); 121 request_region(chan->reg_base + SH4_PCIPAR, 8,
122 "PCI conf1");
123 return 0;
128 } 124 }
129 125
130 pr_debug("PCI: pci_check_direct failed\n"); 126 pci_write_reg(chan, tmp, SH4_PCIPAR);
131 return -EINVAL;
132}
133 127
134/* Handle generic fixups */ 128 printk(KERN_ERR "PCI: %s failed\n", __func__);
135static void __init pci_fixup_ide_bases(struct pci_dev *d)
136{
137 int i;
138 129
139 /* 130 return -EINVAL;
140 * PCI IDE controllers use non-standard I/O port decoding, respect it.
141 */
142 if ((d->class >> 8) != PCI_CLASS_STORAGE_IDE)
143 return;
144 pr_debug("PCI: IDE base address fixup for %s\n", pci_name(d));
145 for(i = 0; i < 4; i++) {
146 struct resource *r = &d->resource[i];
147
148 if ((r->start & ~0x80) == 0x374) {
149 r->start |= 2;
150 r->end = r->start;
151 }
152 }
153}
154DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pci_fixup_ide_bases);
155
156char * __devinit pcibios_setup(char *str)
157{
158 if (!strcmp(str, "off")) {
159 pci_probe = 0;
160 return NULL;
161 }
162
163 return str;
164} 131}
165 132
166int __attribute__((weak)) pci_fixup_pcic(void) 133int __attribute__((weak)) pci_fixup_pcic(struct pci_channel *chan)
167{ 134{
168 /* Nothing to do. */ 135 /* Nothing to do. */
169 return 0; 136 return 0;
diff --git a/arch/sh/drivers/pci/ops-sh5.c b/arch/sh/drivers/pci/ops-sh5.c
index 729e38a6fe07..4ce95a001b80 100644
--- a/arch/sh/drivers/pci/ops-sh5.c
+++ b/arch/sh/drivers/pci/ops-sh5.c
@@ -22,31 +22,6 @@
22#include <asm/io.h> 22#include <asm/io.h>
23#include "pci-sh5.h" 23#include "pci-sh5.h"
24 24
25static void __init pci_fixup_ide_bases(struct pci_dev *d)
26{
27 int i;
28
29 /*
30 * PCI IDE controllers use non-standard I/O port decoding, respect it.
31 */
32 if ((d->class >> 8) != PCI_CLASS_STORAGE_IDE)
33 return;
34 printk("PCI: IDE base address fixup for %s\n", pci_name(d));
35 for(i=0; i<4; i++) {
36 struct resource *r = &d->resource[i];
37 if ((r->start & ~0x80) == 0x374) {
38 r->start |= 2;
39 r->end = r->start;
40 }
41 }
42}
43DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pci_fixup_ide_bases);
44
45char * __devinit pcibios_setup(char *str)
46{
47 return str;
48}
49
50static int sh5pci_read(struct pci_bus *bus, unsigned int devfn, int where, 25static int sh5pci_read(struct pci_bus *bus, unsigned int devfn, int where,
51 int size, u32 *val) 26 int size, u32 *val)
52{ 27{
diff --git a/arch/sh/drivers/pci/ops-sh7785lcr.c b/arch/sh/drivers/pci/ops-sh7785lcr.c
deleted file mode 100644
index fb0869f0bef8..000000000000
--- a/arch/sh/drivers/pci/ops-sh7785lcr.c
+++ /dev/null
@@ -1,66 +0,0 @@
1/*
2 * Author: Ian DaSilva (idasilva@mvista.com)
3 *
4 * Highly leveraged from pci-bigsur.c, written by Dustin McIntire.
5 *
6 * May be copied or modified under the terms of the GNU General Public
7 * License. See linux/COPYING for more information.
8 *
9 * PCI initialization for the Renesas R0P7785LC0011RL board
10 * Based on arch/sh/drivers/pci/ops-r7780rp.c
11 *
12 */
13#include <linux/kernel.h>
14#include <linux/types.h>
15#include <linux/init.h>
16#include <linux/delay.h>
17#include <linux/pci.h>
18#include "pci-sh4.h"
19
20static char irq_tab[] __initdata = {
21 65, 66, 67, 68,
22};
23
24int __init pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin)
25{
26 return irq_tab[slot];
27}
28
29static struct resource sh7785_io_resource = {
30 .name = "SH7785_IO",
31 .start = SH7780_PCI_IO_BASE,
32 .end = SH7780_PCI_IO_BASE + SH7780_PCI_IO_SIZE - 1,
33 .flags = IORESOURCE_IO
34};
35
36static struct resource sh7785_mem_resource = {
37 .name = "SH7785_mem",
38 .start = SH7780_PCI_MEMORY_BASE,
39 .end = SH7780_PCI_MEMORY_BASE + SH7780_PCI_MEM_SIZE - 1,
40 .flags = IORESOURCE_MEM
41};
42
43struct pci_channel board_pci_channels[] = {
44 { &sh4_pci_ops, &sh7785_io_resource, &sh7785_mem_resource, 0, 0xff },
45 { NULL, NULL, NULL, 0, 0 },
46};
47EXPORT_SYMBOL(board_pci_channels);
48
49static struct sh4_pci_address_map sh7785_pci_map = {
50 .window0 = {
51#if defined(CONFIG_32BIT)
52 .base = SH7780_32BIT_DDR_BASE_ADDR,
53 .size = 0x40000000,
54#else
55 .base = SH7780_CS0_BASE_ADDR,
56 .size = 0x20000000,
57#endif
58 },
59
60 .flags = SH4_PCIC_NO_RESET,
61};
62
63int __init pcibios_init_platform(void)
64{
65 return sh7780_pcic_init(&sh7785_pci_map);
66}
diff --git a/arch/sh/drivers/pci/ops-snapgear.c b/arch/sh/drivers/pci/ops-snapgear.c
deleted file mode 100644
index 53dd893d4e54..000000000000
--- a/arch/sh/drivers/pci/ops-snapgear.c
+++ /dev/null
@@ -1,94 +0,0 @@
1/*
2 * arch/sh/drivers/pci/ops-snapgear.c
3 *
4 * Author: David McCullough <davidm@snapgear.com>
5 *
6 * Ported to new API by Paul Mundt <lethal@linux-sh.org>
7 *
8 * Highly leveraged from pci-bigsur.c, written by Dustin McIntire.
9 *
10 * May be copied or modified under the terms of the GNU General Public
11 * License. See linux/COPYING for more information.
12 *
13 * PCI initialization for the SnapGear boards
14 */
15#include <linux/kernel.h>
16#include <linux/types.h>
17#include <linux/init.h>
18#include <linux/pci.h>
19#include "pci-sh4.h"
20
21#define SNAPGEAR_PCI_IO 0x4000
22#define SNAPGEAR_PCI_MEM 0xfd000000
23
24/* PCI: default LOCAL memory window sizes (seen from PCI bus) */
25#define SNAPGEAR_LSR0_SIZE (64*(1<<20)) //64MB
26#define SNAPGEAR_LSR1_SIZE (64*(1<<20)) //64MB
27
28static struct resource sh7751_io_resource = {
29 .name = "SH7751 IO",
30 .start = SNAPGEAR_PCI_IO,
31 .end = SNAPGEAR_PCI_IO + (64*1024) - 1, /* 64KiB I/O */
32 .flags = IORESOURCE_IO,
33};
34
35static struct resource sh7751_mem_resource = {
36 .name = "SH7751 mem",
37 .start = SNAPGEAR_PCI_MEM,
38 .end = SNAPGEAR_PCI_MEM + (64*1024*1024) - 1, /* 64MiB mem */
39 .flags = IORESOURCE_MEM,
40};
41
42struct pci_channel board_pci_channels[] = {
43 { &sh4_pci_ops, &sh7751_io_resource, &sh7751_mem_resource, 0, 0xff },
44 { 0, }
45};
46
47static struct sh4_pci_address_map sh7751_pci_map = {
48 .window0 = {
49 .base = SH7751_CS2_BASE_ADDR,
50 .size = SNAPGEAR_LSR0_SIZE,
51 },
52
53 .window1 = {
54 .base = SH7751_CS2_BASE_ADDR,
55 .size = SNAPGEAR_LSR1_SIZE,
56 },
57
58 .flags = SH4_PCIC_NO_RESET,
59};
60
61/*
62 * Initialize the SnapGear PCI interface
63 * Setup hardware to be Central Funtion
64 * Copy the BSR regs to the PCI interface
65 * Setup PCI windows into local RAM
66 */
67int __init pcibios_init_platform(void)
68{
69 return sh7751_pcic_init(&sh7751_pci_map);
70}
71
72int __init pcibios_map_platform_irq(struct pci_dev *pdev, u8 slot, u8 pin)
73{
74 int irq = -1;
75
76 switch (slot) {
77 case 8: /* the PCI bridge */ break;
78 case 11: irq = 8; break; /* USB */
79 case 12: irq = 11; break; /* PCMCIA */
80 case 13: irq = 5; break; /* eth0 */
81 case 14: irq = 8; break; /* eth1 */
82 case 15: irq = 11; break; /* safenet (unused) */
83 }
84
85 printk("PCI: Mapping SnapGear IRQ for slot %d, pin %c to irq %d\n",
86 slot, pin - 1 + 'A', irq);
87
88 return irq;
89}
90
91void __init pcibios_fixup(void)
92{
93 /* Nothing to fixup .. */
94}
diff --git a/arch/sh/drivers/pci/pci-auto.c b/arch/sh/drivers/pci/pci-auto.c
deleted file mode 100644
index cf48b12ee58c..000000000000
--- a/arch/sh/drivers/pci/pci-auto.c
+++ /dev/null
@@ -1,545 +0,0 @@
1/*
2 * PCI autoconfiguration library
3 *
4 * Author: Matt Porter <mporter@mvista.com>
5 *
6 * Copyright 2000, 2001 MontaVista Software Inc.
7 * Copyright 2001 Bradley D. LaRonde <brad@ltc.com>
8 * Copyright 2003 Paul Mundt <lethal@linux-sh.org>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 */
15
16/*
17 * Modified for MIPS by Jun Sun, jsun@mvista.com
18 *
19 * . Simplify the interface between pci_auto and the rest: a single function.
20 * . Assign resources from low address to upper address.
21 * . change most int to u32.
22 *
23 * Further modified to include it as mips generic code, ppopov@mvista.com.
24 *
25 * 2001-10-26 Bradley D. LaRonde <brad@ltc.com>
26 * - Add a top_bus argument to the "early config" functions so that
27 * they can set a fake parent bus pointer to convince the underlying
28 * pci ops to use type 1 configuration for sub busses.
29 * - Set bridge base and limit registers correctly.
30 * - Align io and memory base properly before and after bridge setup.
31 * - Don't fall through to pci_setup_bars for bridge.
32 * - Reformat the debug output to look more like lspci's output.
33 *
34 * Cloned for SuperH by M. R. Brown, mrbrown@0xd6.org
35 *
36 * 2003-08-05 Paul Mundt <lethal@linux-sh.org>
37 * - Don't update the BAR values on systems that already have valid addresses
38 * and don't want these updated for whatever reason, by way of a new config
39 * option check. However, we still read in the old BAR values so that they
40 * can still be reported through the debug output.
41 */
42
43#include <linux/kernel.h>
44#include <linux/init.h>
45#include <linux/types.h>
46#include <linux/pci.h>
47
48#define DEBUG
49#ifdef DEBUG
50#define DBG(x...) printk(x)
51#else
52#define DBG(x...)
53#endif
54
55/*
56 * These functions are used early on before PCI scanning is done
57 * and all of the pci_dev and pci_bus structures have been created.
58 */
59static struct pci_dev *fake_pci_dev(struct pci_channel *hose,
60 int top_bus, int busnr, int devfn)
61{
62 static struct pci_dev dev;
63 static struct pci_bus bus;
64
65 dev.bus = &bus;
66 dev.sysdata = hose;
67 dev.devfn = devfn;
68 bus.number = busnr;
69 bus.ops = hose->pci_ops;
70
71 if(busnr != top_bus)
72 /* Fake a parent bus structure. */
73 bus.parent = &bus;
74 else
75 bus.parent = NULL;
76
77 return &dev;
78}
79
80#define EARLY_PCI_OP(rw, size, type) \
81static int early_##rw##_config_##size(struct pci_channel *hose, \
82 int top_bus, int bus, int devfn, int offset, type value) \
83{ \
84 return pci_##rw##_config_##size( \
85 fake_pci_dev(hose, top_bus, bus, devfn), \
86 offset, value); \
87}
88
89EARLY_PCI_OP(read, byte, u8 *)
90EARLY_PCI_OP(read, word, u16 *)
91EARLY_PCI_OP(read, dword, u32 *)
92EARLY_PCI_OP(write, byte, u8)
93EARLY_PCI_OP(write, word, u16)
94EARLY_PCI_OP(write, dword, u32)
95
96static struct resource *io_resource_inuse;
97static struct resource *mem_resource_inuse;
98
99static u32 pciauto_lower_iospc;
100static u32 pciauto_upper_iospc;
101
102static u32 pciauto_lower_memspc;
103static u32 pciauto_upper_memspc;
104
105static void __init
106pciauto_setup_bars(struct pci_channel *hose,
107 int top_bus,
108 int current_bus,
109 int pci_devfn,
110 int bar_limit)
111{
112 u32 bar_response, bar_size, bar_value;
113 u32 bar, addr_mask, bar_nr = 0;
114 u32 * upper_limit;
115 u32 * lower_limit;
116 int found_mem64 = 0;
117
118 for (bar = PCI_BASE_ADDRESS_0; bar <= bar_limit; bar+=4) {
119 u32 bar_addr;
120
121 /* Read the old BAR value */
122 early_read_config_dword(hose, top_bus,
123 current_bus,
124 pci_devfn,
125 bar,
126 &bar_addr);
127
128 /* Tickle the BAR and get the response */
129 early_write_config_dword(hose, top_bus,
130 current_bus,
131 pci_devfn,
132 bar,
133 0xffffffff);
134
135 early_read_config_dword(hose, top_bus,
136 current_bus,
137 pci_devfn,
138 bar,
139 &bar_response);
140
141 /*
142 * Write the old BAR value back out, only update the BAR
143 * if we implicitly want resources to be updated, which
144 * is done by the generic code further down. -- PFM.
145 */
146 early_write_config_dword(hose, top_bus,
147 current_bus,
148 pci_devfn,
149 bar,
150 bar_addr);
151
152 /* If BAR is not implemented go to the next BAR */
153 if (!bar_response)
154 continue;
155
156 /*
157 * Workaround for a BAR that doesn't use its upper word,
158 * like the ALi 1535D+ PCI DC-97 Controller Modem (M5457).
159 * bdl <brad@ltc.com>
160 */
161 if (!(bar_response & 0xffff0000))
162 bar_response |= 0xffff0000;
163
164retry:
165 /* Check the BAR type and set our address mask */
166 if (bar_response & PCI_BASE_ADDRESS_SPACE) {
167 addr_mask = PCI_BASE_ADDRESS_IO_MASK;
168 upper_limit = &pciauto_upper_iospc;
169 lower_limit = &pciauto_lower_iospc;
170 DBG(" I/O");
171 } else {
172 if ((bar_response & PCI_BASE_ADDRESS_MEM_TYPE_MASK) ==
173 PCI_BASE_ADDRESS_MEM_TYPE_64)
174 found_mem64 = 1;
175
176 addr_mask = PCI_BASE_ADDRESS_MEM_MASK;
177 upper_limit = &pciauto_upper_memspc;
178 lower_limit = &pciauto_lower_memspc;
179 DBG(" Mem");
180 }
181
182
183 /* Calculate requested size */
184 bar_size = ~(bar_response & addr_mask) + 1;
185
186 /* Allocate a base address */
187 bar_value = ((*lower_limit - 1) & ~(bar_size - 1)) + bar_size;
188
189 if ((bar_value + bar_size) > *upper_limit) {
190 if (bar_response & PCI_BASE_ADDRESS_SPACE) {
191 if (io_resource_inuse->child) {
192 io_resource_inuse =
193 io_resource_inuse->child;
194 pciauto_lower_iospc =
195 io_resource_inuse->start;
196 pciauto_upper_iospc =
197 io_resource_inuse->end + 1;
198 goto retry;
199 }
200
201 } else {
202 if (mem_resource_inuse->child) {
203 mem_resource_inuse =
204 mem_resource_inuse->child;
205 pciauto_lower_memspc =
206 mem_resource_inuse->start;
207 pciauto_upper_memspc =
208 mem_resource_inuse->end + 1;
209 goto retry;
210 }
211 }
212 DBG(" unavailable -- skipping, value %x size %x\n",
213 bar_value, bar_size);
214 continue;
215 }
216
217 if (bar_value < *lower_limit || (bar_value + bar_size) >= *upper_limit) {
218 DBG(" unavailable -- skipping, value %x size %x\n",
219 bar_value, bar_size);
220 continue;
221 }
222
223#ifdef CONFIG_PCI_AUTO_UPDATE_RESOURCES
224 /* Write it out and update our limit */
225 early_write_config_dword(hose, top_bus, current_bus, pci_devfn,
226 bar, bar_value);
227#endif
228
229 *lower_limit = bar_value + bar_size;
230
231 /*
232 * If we are a 64-bit decoder then increment to the
233 * upper 32 bits of the bar and force it to locate
234 * in the lower 4GB of memory.
235 */
236 if (found_mem64) {
237 bar += 4;
238 early_write_config_dword(hose, top_bus,
239 current_bus,
240 pci_devfn,
241 bar,
242 0x00000000);
243 }
244
245 DBG(" at 0x%.8x [size=0x%x]\n", bar_value, bar_size);
246
247 bar_nr++;
248 }
249
250}
251
252static void __init
253pciauto_prescan_setup_bridge(struct pci_channel *hose,
254 int top_bus,
255 int current_bus,
256 int pci_devfn,
257 int sub_bus)
258{
259 /* Configure bus number registers */
260 early_write_config_byte(hose, top_bus, current_bus, pci_devfn,
261 PCI_PRIMARY_BUS, current_bus);
262 early_write_config_byte(hose, top_bus, current_bus, pci_devfn,
263 PCI_SECONDARY_BUS, sub_bus + 1);
264 early_write_config_byte(hose, top_bus, current_bus, pci_devfn,
265 PCI_SUBORDINATE_BUS, 0xff);
266
267 /* Align memory and I/O to 1MB and 4KB boundaries. */
268 pciauto_lower_memspc = (pciauto_lower_memspc + (0x100000 - 1))
269 & ~(0x100000 - 1);
270 pciauto_lower_iospc = (pciauto_lower_iospc + (0x1000 - 1))
271 & ~(0x1000 - 1);
272
273 /* Set base (lower limit) of address range behind bridge. */
274 early_write_config_word(hose, top_bus, current_bus, pci_devfn,
275 PCI_MEMORY_BASE, pciauto_lower_memspc >> 16);
276 early_write_config_byte(hose, top_bus, current_bus, pci_devfn,
277 PCI_IO_BASE, (pciauto_lower_iospc & 0x0000f000) >> 8);
278 early_write_config_word(hose, top_bus, current_bus, pci_devfn,
279 PCI_IO_BASE_UPPER16, pciauto_lower_iospc >> 16);
280
281 /* We don't support prefetchable memory for now, so disable */
282 early_write_config_word(hose, top_bus, current_bus, pci_devfn,
283 PCI_PREF_MEMORY_BASE, 0);
284 early_write_config_word(hose, top_bus, current_bus, pci_devfn,
285 PCI_PREF_MEMORY_LIMIT, 0);
286}
287
288static void __init
289pciauto_postscan_setup_bridge(struct pci_channel *hose,
290 int top_bus,
291 int current_bus,
292 int pci_devfn,
293 int sub_bus)
294{
295 u32 temp;
296
297 /*
298 * [jsun] we always bump up baselines a little, so that if there
299 * nothing behind P2P bridge, we don't wind up overlapping IO/MEM
300 * spaces.
301 */
302 pciauto_lower_memspc += 1;
303 pciauto_lower_iospc += 1;
304
305 /* Configure bus number registers */
306 early_write_config_byte(hose, top_bus, current_bus, pci_devfn,
307 PCI_SUBORDINATE_BUS, sub_bus);
308
309 /* Set upper limit of address range behind bridge. */
310 early_write_config_word(hose, top_bus, current_bus, pci_devfn,
311 PCI_MEMORY_LIMIT, pciauto_lower_memspc >> 16);
312 early_write_config_byte(hose, top_bus, current_bus, pci_devfn,
313 PCI_IO_LIMIT, (pciauto_lower_iospc & 0x0000f000) >> 8);
314 early_write_config_word(hose, top_bus, current_bus, pci_devfn,
315 PCI_IO_LIMIT_UPPER16, pciauto_lower_iospc >> 16);
316
317 /* Align memory and I/O to 1MB and 4KB boundaries. */
318 pciauto_lower_memspc = (pciauto_lower_memspc + (0x100000 - 1))
319 & ~(0x100000 - 1);
320 pciauto_lower_iospc = (pciauto_lower_iospc + (0x1000 - 1))
321 & ~(0x1000 - 1);
322
323 /* Enable memory and I/O accesses, enable bus master */
324 early_read_config_dword(hose, top_bus, current_bus, pci_devfn,
325 PCI_COMMAND, &temp);
326 early_write_config_dword(hose, top_bus, current_bus, pci_devfn,
327 PCI_COMMAND, temp | PCI_COMMAND_IO | PCI_COMMAND_MEMORY
328 | PCI_COMMAND_MASTER);
329}
330
331static void __init
332pciauto_prescan_setup_cardbus_bridge(struct pci_channel *hose,
333 int top_bus,
334 int current_bus,
335 int pci_devfn,
336 int sub_bus)
337{
338 /* Configure bus number registers */
339 early_write_config_byte(hose, top_bus, current_bus, pci_devfn,
340 PCI_PRIMARY_BUS, current_bus);
341 early_write_config_byte(hose, top_bus, current_bus, pci_devfn,
342 PCI_SECONDARY_BUS, sub_bus + 1);
343 early_write_config_byte(hose, top_bus, current_bus, pci_devfn,
344 PCI_SUBORDINATE_BUS, 0xff);
345
346 /* Align memory and I/O to 4KB and 4 byte boundaries. */
347 pciauto_lower_memspc = (pciauto_lower_memspc + (0x1000 - 1))
348 & ~(0x1000 - 1);
349 pciauto_lower_iospc = (pciauto_lower_iospc + (0x4 - 1))
350 & ~(0x4 - 1);
351
352 early_write_config_dword(hose, top_bus, current_bus, pci_devfn,
353 PCI_CB_MEMORY_BASE_0, pciauto_lower_memspc);
354 early_write_config_dword(hose, top_bus, current_bus, pci_devfn,
355 PCI_CB_IO_BASE_0, pciauto_lower_iospc);
356}
357
358static void __init
359pciauto_postscan_setup_cardbus_bridge(struct pci_channel *hose,
360 int top_bus,
361 int current_bus,
362 int pci_devfn,
363 int sub_bus)
364{
365 u32 temp;
366
367 /*
368 * [jsun] we always bump up baselines a little, so that if there
369 * nothing behind P2P bridge, we don't wind up overlapping IO/MEM
370 * spaces.
371 */
372 pciauto_lower_memspc += 1;
373 pciauto_lower_iospc += 1;
374
375 /*
376 * Configure subordinate bus number. The PCI subsystem
377 * bus scan will renumber buses (reserving three additional
378 * for this PCI<->CardBus bridge for the case where a CardBus
379 * adapter contains a P2P or CB2CB bridge.
380 */
381
382 early_write_config_byte(hose, top_bus, current_bus, pci_devfn,
383 PCI_SUBORDINATE_BUS, sub_bus);
384
385 /*
386 * Reserve an additional 4MB for mem space and 16KB for
387 * I/O space. This should cover any additional space
388 * requirement of unusual CardBus devices with
389 * additional bridges that can consume more address space.
390 *
391 * Although pcmcia-cs currently will reprogram bridge
392 * windows, the goal is to add an option to leave them
393 * alone and use the bridge window ranges as the regions
394 * that are searched for free resources upon hot-insertion
395 * of a device. This will allow a PCI<->CardBus bridge
396 * configured by this routine to happily live behind a
397 * P2P bridge in a system.
398 */
399 /* Align memory and I/O to 4KB and 4 byte boundaries. */
400 pciauto_lower_memspc = (pciauto_lower_memspc + (0x1000 - 1))
401 & ~(0x1000 - 1);
402 pciauto_lower_iospc = (pciauto_lower_iospc + (0x4 - 1))
403 & ~(0x4 - 1);
404 /* Set up memory and I/O filter limits, assume 32-bit I/O space */
405 early_write_config_dword(hose, top_bus, current_bus, pci_devfn,
406 PCI_CB_MEMORY_LIMIT_0, pciauto_lower_memspc - 1);
407 early_write_config_dword(hose, top_bus, current_bus, pci_devfn,
408 PCI_CB_IO_LIMIT_0, pciauto_lower_iospc - 1);
409
410 /* Enable memory and I/O accesses, enable bus master */
411 early_read_config_dword(hose, top_bus, current_bus, pci_devfn,
412 PCI_COMMAND, &temp);
413 early_write_config_dword(hose, top_bus, current_bus, pci_devfn,
414 PCI_COMMAND, temp | PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
415 PCI_COMMAND_MASTER);
416}
417
418#define PCIAUTO_IDE_MODE_MASK 0x05
419
420static int __init
421pciauto_bus_scan(struct pci_channel *hose, int top_bus, int current_bus)
422{
423 int sub_bus;
424 u32 pci_devfn, pci_class, cmdstat, found_multi=0;
425 unsigned short vid, did;
426 unsigned char header_type;
427 int devfn_start = 0;
428 int devfn_stop = 0xff;
429
430 sub_bus = current_bus;
431
432 if (hose->first_devfn)
433 devfn_start = hose->first_devfn;
434 if (hose->last_devfn)
435 devfn_stop = hose->last_devfn;
436
437 for (pci_devfn=devfn_start; pci_devfn<devfn_stop; pci_devfn++) {
438
439 if (PCI_FUNC(pci_devfn) && !found_multi)
440 continue;
441
442 early_read_config_word(hose, top_bus, current_bus, pci_devfn,
443 PCI_VENDOR_ID, &vid);
444
445 if (vid == 0xffff) continue;
446
447 early_read_config_byte(hose, top_bus, current_bus, pci_devfn,
448 PCI_HEADER_TYPE, &header_type);
449
450 if (!PCI_FUNC(pci_devfn))
451 found_multi = header_type & 0x80;
452
453 early_read_config_word(hose, top_bus, current_bus, pci_devfn,
454 PCI_DEVICE_ID, &did);
455
456 early_read_config_dword(hose, top_bus, current_bus, pci_devfn,
457 PCI_CLASS_REVISION, &pci_class);
458
459 DBG("%.2x:%.2x.%x Class %.4x: %.4x:%.4x",
460 current_bus, PCI_SLOT(pci_devfn), PCI_FUNC(pci_devfn),
461 pci_class >> 16, vid, did);
462 if (pci_class & 0xff)
463 DBG(" (rev %.2x)", pci_class & 0xff);
464 DBG("\n");
465
466 if ((pci_class >> 16) == PCI_CLASS_BRIDGE_PCI) {
467 DBG(" Bridge: primary=%.2x, secondary=%.2x\n",
468 current_bus, sub_bus + 1);
469 pciauto_prescan_setup_bridge(hose, top_bus, current_bus,
470 pci_devfn, sub_bus);
471 DBG("Scanning sub bus %.2x, I/O 0x%.8x, Mem 0x%.8x\n",
472 sub_bus + 1,
473 pciauto_lower_iospc, pciauto_lower_memspc);
474 sub_bus = pciauto_bus_scan(hose, top_bus, sub_bus+1);
475 DBG("Back to bus %.2x\n", current_bus);
476 pciauto_postscan_setup_bridge(hose, top_bus, current_bus,
477 pci_devfn, sub_bus);
478 continue;
479 } else if ((pci_class >> 16) == PCI_CLASS_BRIDGE_CARDBUS) {
480 DBG(" CARDBUS Bridge: primary=%.2x, secondary=%.2x\n",
481 current_bus, sub_bus + 1);
482 DBG("PCI Autoconfig: Found CardBus bridge, device %d function %d\n", PCI_SLOT(pci_devfn), PCI_FUNC(pci_devfn));
483 /* Place CardBus Socket/ExCA registers */
484 pciauto_setup_bars(hose, top_bus, current_bus, pci_devfn, PCI_BASE_ADDRESS_0);
485
486 pciauto_prescan_setup_cardbus_bridge(hose, top_bus,
487 current_bus, pci_devfn, sub_bus);
488
489 DBG("Scanning sub bus %.2x, I/O 0x%.8x, Mem 0x%.8x\n",
490 sub_bus + 1,
491 pciauto_lower_iospc, pciauto_lower_memspc);
492 sub_bus = pciauto_bus_scan(hose, top_bus, sub_bus+1);
493 DBG("Back to bus %.2x, sub_bus is %x\n", current_bus, sub_bus);
494 pciauto_postscan_setup_cardbus_bridge(hose, top_bus,
495 current_bus, pci_devfn, sub_bus);
496 continue;
497 } else if ((pci_class >> 16) == PCI_CLASS_STORAGE_IDE) {
498
499 unsigned char prg_iface;
500
501 early_read_config_byte(hose, top_bus, current_bus,
502 pci_devfn, PCI_CLASS_PROG, &prg_iface);
503 if (!(prg_iface & PCIAUTO_IDE_MODE_MASK)) {
504 DBG("Skipping legacy mode IDE controller\n");
505 continue;
506 }
507 }
508
509 /*
510 * Found a peripheral, enable some standard
511 * settings
512 */
513 early_read_config_dword(hose, top_bus, current_bus, pci_devfn,
514 PCI_COMMAND, &cmdstat);
515 early_write_config_dword(hose, top_bus, current_bus, pci_devfn,
516 PCI_COMMAND, cmdstat | PCI_COMMAND_IO |
517 PCI_COMMAND_MEMORY |
518 PCI_COMMAND_MASTER);
519 early_write_config_byte(hose, top_bus, current_bus, pci_devfn,
520 PCI_LATENCY_TIMER, 0x80);
521
522 /* Allocate PCI I/O and/or memory space */
523 pciauto_setup_bars(hose, top_bus, current_bus, pci_devfn, PCI_BASE_ADDRESS_5);
524 }
525 return sub_bus;
526}
527
528int __init
529pciauto_assign_resources(int busno, struct pci_channel *hose)
530{
531 /* setup resource limits */
532 io_resource_inuse = hose->io_resource;
533 mem_resource_inuse = hose->mem_resource;
534
535 pciauto_lower_iospc = io_resource_inuse->start;
536 pciauto_upper_iospc = io_resource_inuse->end + 1;
537 pciauto_lower_memspc = mem_resource_inuse->start;
538 pciauto_upper_memspc = mem_resource_inuse->end + 1;
539 DBG("Autoconfig PCI channel 0x%p\n", hose);
540 DBG("Scanning bus %.2x, I/O 0x%.8x:0x%.8x, Mem 0x%.8x:0x%.8x\n",
541 busno, pciauto_lower_iospc, pciauto_upper_iospc,
542 pciauto_lower_memspc, pciauto_upper_memspc);
543
544 return pciauto_bus_scan(hose, busno, busno);
545}
diff --git a/arch/sh/drivers/pci/pci-dreamcast.c b/arch/sh/drivers/pci/pci-dreamcast.c
new file mode 100644
index 000000000000..210f9d4af141
--- /dev/null
+++ b/arch/sh/drivers/pci/pci-dreamcast.c
@@ -0,0 +1,102 @@
1/*
2 * PCI support for the Sega Dreamcast
3 *
4 * Copyright (C) 2001, 2002 M. R. Brown
5 * Copyright (C) 2002, 2003 Paul Mundt
6 *
7 * This file originally bore the message (with enclosed-$):
8 * Id: pci.c,v 1.3 2003/05/04 19:29:46 lethal Exp
9 * Dreamcast PCI: Supports SEGA Broadband Adaptor only.
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
13 * for more details.
14 */
15
16#include <linux/sched.h>
17#include <linux/kernel.h>
18#include <linux/param.h>
19#include <linux/interrupt.h>
20#include <linux/init.h>
21#include <linux/irq.h>
22#include <linux/pci.h>
23#include <linux/module.h>
24#include <asm/io.h>
25#include <asm/irq.h>
26#include <mach/pci.h>
27
28static struct resource gapspci_io_resource = {
29 .name = "GAPSPCI IO",
30 .start = GAPSPCI_BBA_CONFIG,
31 .end = GAPSPCI_BBA_CONFIG + GAPSPCI_BBA_CONFIG_SIZE - 1,
32 .flags = IORESOURCE_IO,
33};
34
35static struct resource gapspci_mem_resource = {
36 .name = "GAPSPCI mem",
37 .start = GAPSPCI_DMA_BASE,
38 .end = GAPSPCI_DMA_BASE + GAPSPCI_DMA_SIZE - 1,
39 .flags = IORESOURCE_MEM,
40};
41
42static struct pci_channel dreamcast_pci_controller = {
43 .pci_ops = &gapspci_pci_ops,
44 .io_resource = &gapspci_io_resource,
45 .io_offset = 0x00000000,
46 .mem_resource = &gapspci_mem_resource,
47 .mem_offset = 0x00000000,
48};
49
50/*
51 * gapspci init
52 */
53
54static int __init gapspci_init(void)
55{
56 char idbuf[16];
57 int i;
58
59 /*
60 * FIXME: All of this wants documenting to some degree,
61 * even some basic register definitions would be nice.
62 *
63 * I haven't seen anything this ugly since.. maple.
64 */
65
66 for (i=0; i<16; i++)
67 idbuf[i] = inb(GAPSPCI_REGS+i);
68
69 if (strncmp(idbuf, "GAPSPCI_BRIDGE_2", 16))
70 return -ENODEV;
71
72 outl(0x5a14a501, GAPSPCI_REGS+0x18);
73
74 for (i=0; i<1000000; i++)
75 cpu_relax();
76
77 if (inl(GAPSPCI_REGS+0x18) != 1)
78 return -EINVAL;
79
80 outl(0x01000000, GAPSPCI_REGS+0x20);
81 outl(0x01000000, GAPSPCI_REGS+0x24);
82
83 outl(GAPSPCI_DMA_BASE, GAPSPCI_REGS+0x28);
84 outl(GAPSPCI_DMA_BASE+GAPSPCI_DMA_SIZE, GAPSPCI_REGS+0x2c);
85
86 outl(1, GAPSPCI_REGS+0x14);
87 outl(1, GAPSPCI_REGS+0x34);
88
89 /* Setting Broadband Adapter */
90 outw(0xf900, GAPSPCI_BBA_CONFIG+0x06);
91 outl(0x00000000, GAPSPCI_BBA_CONFIG+0x30);
92 outb(0x00, GAPSPCI_BBA_CONFIG+0x3c);
93 outb(0xf0, GAPSPCI_BBA_CONFIG+0x0d);
94 outw(0x0006, GAPSPCI_BBA_CONFIG+0x04);
95 outl(0x00002001, GAPSPCI_BBA_CONFIG+0x10);
96 outl(0x01000000, GAPSPCI_BBA_CONFIG+0x14);
97
98 register_pci_controller(&dreamcast_pci_controller);
99
100 return 0;
101}
102arch_initcall(gapspci_init);
diff --git a/arch/sh/drivers/pci/pci-sh4.h b/arch/sh/drivers/pci/pci-sh4.h
index a83dcf70c13b..3d5296cde622 100644
--- a/arch/sh/drivers/pci/pci-sh4.h
+++ b/arch/sh/drivers/pci/pci-sh4.h
@@ -149,13 +149,10 @@
149 #define SH4_PCIPDTR_PB0 0x000000001 /* Port 0 Enable */ 149 #define SH4_PCIPDTR_PB0 0x000000001 /* Port 0 Enable */
150#define SH4_PCIPDR 0x220 /* Port IO Data Register */ 150#define SH4_PCIPDR 0x220 /* Port IO Data Register */
151 151
152/* Flags */
153#define SH4_PCIC_NO_RESET 0x0001
154
155/* arch/sh/kernel/drivers/pci/ops-sh4.c */ 152/* arch/sh/kernel/drivers/pci/ops-sh4.c */
156extern struct pci_ops sh4_pci_ops; 153extern struct pci_ops sh4_pci_ops;
157int sh4_pci_check_direct(void); 154int sh4_pci_check_direct(struct pci_channel *chan);
158int pci_fixup_pcic(void); 155int pci_fixup_pcic(struct pci_channel *chan);
159 156
160struct sh4_pci_address_space { 157struct sh4_pci_address_space {
161 unsigned long base; 158 unsigned long base;
@@ -165,16 +162,18 @@ struct sh4_pci_address_space {
165struct sh4_pci_address_map { 162struct sh4_pci_address_map {
166 struct sh4_pci_address_space window0; 163 struct sh4_pci_address_space window0;
167 struct sh4_pci_address_space window1; 164 struct sh4_pci_address_space window1;
168 unsigned long flags;
169}; 165};
170 166
171static inline void pci_write_reg(unsigned long val, unsigned long reg) 167static inline void pci_write_reg(struct pci_channel *chan,
168 unsigned long val, unsigned long reg)
172{ 169{
173 ctrl_outl(val, PCI_REG(reg)); 170 ctrl_outl(val, chan->reg_base + reg);
174} 171}
175 172
176static inline unsigned long pci_read_reg(unsigned long reg) 173static inline unsigned long pci_read_reg(struct pci_channel *chan,
174 unsigned long reg)
177{ 175{
178 return ctrl_inl(PCI_REG(reg)); 176 return ctrl_inl(chan->reg_base + reg);
179} 177}
178
180#endif /* __PCI_SH4_H */ 179#endif /* __PCI_SH4_H */
diff --git a/arch/sh/drivers/pci/pci-sh5.c b/arch/sh/drivers/pci/pci-sh5.c
index 7a97438762c8..873ed2b44055 100644
--- a/arch/sh/drivers/pci/pci-sh5.c
+++ b/arch/sh/drivers/pci/pci-sh5.c
@@ -89,8 +89,21 @@ static irqreturn_t pcish5_serr_irq(int irq, void *dev_id)
89 return IRQ_NONE; 89 return IRQ_NONE;
90} 90}
91 91
92int __init sh5pci_init(unsigned long memStart, unsigned long memSize) 92static struct resource sh5_io_resource = { /* place holder */ };
93static struct resource sh5_mem_resource = { /* place holder */ };
94
95static struct pci_channel sh5pci_controller = {
96 .pci_ops = &sh5_pci_ops,
97 .mem_resource = &sh5_mem_resource,
98 .mem_offset = 0x00000000,
99 .io_resource = &sh5_io_resource,
100 .io_offset = 0x00000000,
101};
102
103static int __init sh5pci_init(void)
93{ 104{
105 unsigned long memStart = __pa(memory_start);
106 unsigned long memSize = __pa(memory_end) - memStart;
94 u32 lsr0; 107 u32 lsr0;
95 u32 uval; 108 u32 uval;
96 109
@@ -106,12 +119,12 @@ int __init sh5pci_init(unsigned long memStart, unsigned long memSize)
106 return -EINVAL; 119 return -EINVAL;
107 } 120 }
108 121
109 pcicr_virt = onchip_remap(SH5PCI_ICR_BASE, 1024, "PCICR"); 122 pcicr_virt = (unsigned long)ioremap_nocache(SH5PCI_ICR_BASE, 1024);
110 if (!pcicr_virt) { 123 if (!pcicr_virt) {
111 panic("Unable to remap PCICR\n"); 124 panic("Unable to remap PCICR\n");
112 } 125 }
113 126
114 PCI_IO_AREA = onchip_remap(SH5PCI_IO_BASE, 0x10000, "PCIIO"); 127 PCI_IO_AREA = (unsigned long)ioremap_nocache(SH5PCI_IO_BASE, 0x10000);
115 if (!PCI_IO_AREA) { 128 if (!PCI_IO_AREA) {
116 panic("Unable to remap PCIIO\n"); 129 panic("Unable to remap PCIIO\n");
117 } 130 }
@@ -197,32 +210,14 @@ int __init sh5pci_init(unsigned long memStart, unsigned long memSize)
197 SH5PCI_WRITE(AINTM, ~0); 210 SH5PCI_WRITE(AINTM, ~0);
198 SH5PCI_WRITE(PINTM, ~0); 211 SH5PCI_WRITE(PINTM, ~0);
199 212
200 return 0; 213 sh5_io_resource.start = PCI_IO_AREA;
201} 214 sh5_io_resource.end = PCI_IO_AREA + 0x10000;
202 215
203void __devinit pcibios_fixup_bus(struct pci_bus *bus) 216 sh5_mem_resource.start = memStart;
204{ 217 sh5_mem_resource.end = memStart + memSize;
205 struct pci_dev *dev = bus->self; 218
206 int i; 219 register_pci_controller(&sh5pci_controller);
207 220
208 if (dev) { 221 return 0;
209 for (i= 0; i < 3; i++) {
210 bus->resource[i] =
211 &dev->resource[PCI_BRIDGE_RESOURCES+i];
212 bus->resource[i]->name = bus->name;
213 }
214 bus->resource[0]->flags |= IORESOURCE_IO;
215 bus->resource[1]->flags |= IORESOURCE_MEM;
216
217 /* For now, propagate host limits to the bus;
218 * we'll adjust them later. */
219 bus->resource[0]->end = 64*1024 - 1 ;
220 bus->resource[1]->end = PCIBIOS_MIN_MEM+(256*1024*1024)-1;
221 bus->resource[0]->start = PCIBIOS_MIN_IO;
222 bus->resource[1]->start = PCIBIOS_MIN_MEM;
223
224 /* Turn off downstream PF memory address range by default */
225 bus->resource[2]->start = 1024*1024;
226 bus->resource[2]->end = bus->resource[2]->start - 1;
227 }
228} 222}
223arch_initcall(sh5pci_init);
diff --git a/arch/sh/drivers/pci/pci-sh5.h b/arch/sh/drivers/pci/pci-sh5.h
index 7cff3fc04d30..f277628221f3 100644
--- a/arch/sh/drivers/pci/pci-sh5.h
+++ b/arch/sh/drivers/pci/pci-sh5.h
@@ -107,7 +107,4 @@ extern unsigned long pcicr_virt;
107 107
108extern struct pci_ops sh5_pci_ops; 108extern struct pci_ops sh5_pci_ops;
109 109
110/* arch/sh/drivers/pci/pci-sh5.c */
111int sh5pci_init(unsigned long memStart, unsigned long memSize);
112
113#endif /* __PCI_SH5_H */ 110#endif /* __PCI_SH5_H */
diff --git a/arch/sh/drivers/pci/pci-sh7751.c b/arch/sh/drivers/pci/pci-sh7751.c
index 3065eb184f01..70c1999a0ec4 100644
--- a/arch/sh/drivers/pci/pci-sh7751.c
+++ b/arch/sh/drivers/pci/pci-sh7751.c
@@ -1,88 +1,100 @@
1/* 1/*
2 * Low-Level PCI Support for the SH7751 2 * Low-Level PCI Support for the SH7751
3 * 3 *
4 * Dustin McIntire (dustin@sensoria.com) 4 * Copyright (C) 2003 - 2009 Paul Mundt
5 * Derived from arch/i386/kernel/pci-*.c which bore the message: 5 * Copyright (C) 2001 Dustin McIntire
6 * (c) 1999--2000 Martin Mares <mj@ucw.cz>
7 * 6 *
8 * Ported to the new API by Paul Mundt <lethal@linux-sh.org> 7 * With cleanup by Paul van Gool <pvangool@mimotech.com>, 2003.
9 * With cleanup by Paul van Gool <pvangool@mimotech.com>
10 *
11 * May be copied or modified under the terms of the GNU General Public
12 * License. See linux/COPYING for more information.
13 * 8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
14 */ 12 */
15#undef DEBUG
16
17#include <linux/init.h> 13#include <linux/init.h>
18#include <linux/pci.h> 14#include <linux/pci.h>
19#include <linux/types.h> 15#include <linux/types.h>
20#include <linux/errno.h> 16#include <linux/errno.h>
21#include <linux/delay.h> 17#include <linux/io.h>
22#include "pci-sh4.h" 18#include "pci-sh4.h"
23#include <asm/addrspace.h> 19#include <asm/addrspace.h>
24#include <asm/io.h>
25 20
26/* 21static int __init __area_sdram_check(struct pci_channel *chan,
27 * Initialization. Try all known PCI access methods. Note that we support 22 unsigned int area)
28 * using both PCI BIOS and direct access: in such cases, we use I/O ports
29 * to access config space.
30 *
31 * Note that the platform specific initialization (BSC registers, and memory
32 * space mapping) will be called via the platform defined function
33 * pcibios_init_platform().
34 */
35static int __init sh7751_pci_init(void)
36{ 23{
37 unsigned int id; 24 unsigned long word;
38 int ret;
39
40 pr_debug("PCI: Starting intialization.\n");
41 25
42 /* check for SH7751/SH7751R hardware */ 26 word = __raw_readl(SH7751_BCR1);
43 id = pci_read_reg(SH7751_PCICONF0);
44 if (id != ((SH7751_DEVICE_ID << 16) | SH7751_VENDOR_ID) &&
45 id != ((SH7751R_DEVICE_ID << 16) | SH7751_VENDOR_ID)) {
46 pr_debug("PCI: This is not an SH7751(R) (%x)\n", id);
47 return -ENODEV;
48 }
49
50 if ((ret = sh4_pci_check_direct()) != 0)
51 return ret;
52
53 return pcibios_init_platform();
54}
55subsys_initcall(sh7751_pci_init);
56
57static int __init __area_sdram_check(unsigned int area)
58{
59 u32 word;
60
61 word = ctrl_inl(SH7751_BCR1);
62 /* check BCR for SDRAM in area */ 27 /* check BCR for SDRAM in area */
63 if (((word >> area) & 1) == 0) { 28 if (((word >> area) & 1) == 0) {
64 printk("PCI: Area %d is not configured for SDRAM. BCR1=0x%x\n", 29 printk("PCI: Area %d is not configured for SDRAM. BCR1=0x%lx\n",
65 area, word); 30 area, word);
66 return 0; 31 return 0;
67 } 32 }
68 pci_write_reg(word, SH4_PCIBCR1); 33 pci_write_reg(chan, word, SH4_PCIBCR1);
69 34
70 word = (u16)ctrl_inw(SH7751_BCR2); 35 word = __raw_readw(SH7751_BCR2);
71 /* check BCR2 for 32bit SDRAM interface*/ 36 /* check BCR2 for 32bit SDRAM interface*/
72 if (((word >> (area << 1)) & 0x3) != 0x3) { 37 if (((word >> (area << 1)) & 0x3) != 0x3) {
73 printk("PCI: Area %d is not 32 bit SDRAM. BCR2=0x%x\n", 38 printk("PCI: Area %d is not 32 bit SDRAM. BCR2=0x%lx\n",
74 area, word); 39 area, word);
75 return 0; 40 return 0;
76 } 41 }
77 pci_write_reg(word, SH4_PCIBCR2); 42 pci_write_reg(chan, word, SH4_PCIBCR2);
78 43
79 return 1; 44 return 1;
80} 45}
81 46
82int __init sh7751_pcic_init(struct sh4_pci_address_map *map) 47static struct resource sh7751_io_resource = {
48 .name = "SH7751_IO",
49 .start = SH7751_PCI_IO_BASE,
50 .end = SH7751_PCI_IO_BASE + SH7751_PCI_IO_SIZE - 1,
51 .flags = IORESOURCE_IO
52};
53
54static struct resource sh7751_mem_resource = {
55 .name = "SH7751_mem",
56 .start = SH7751_PCI_MEMORY_BASE,
57 .end = SH7751_PCI_MEMORY_BASE + SH7751_PCI_MEM_SIZE - 1,
58 .flags = IORESOURCE_MEM
59};
60
61static struct pci_channel sh7751_pci_controller = {
62 .pci_ops = &sh4_pci_ops,
63 .mem_resource = &sh7751_mem_resource,
64 .mem_offset = 0x00000000,
65 .io_resource = &sh7751_io_resource,
66 .io_offset = 0x00000000,
67 .io_map_base = SH7751_PCI_IO_BASE,
68};
69
70static struct sh4_pci_address_map sh7751_pci_map = {
71 .window0 = {
72 .base = SH7751_CS3_BASE_ADDR,
73 .size = 0x04000000,
74 },
75};
76
77static int __init sh7751_pci_init(void)
83{ 78{
84 u32 reg; 79 struct pci_channel *chan = &sh7751_pci_controller;
85 u32 word; 80 unsigned int id;
81 u32 word, reg;
82 int ret;
83
84 printk(KERN_NOTICE "PCI: Starting intialization.\n");
85
86 chan->reg_base = 0xfe200000;
87
88 /* check for SH7751/SH7751R hardware */
89 id = pci_read_reg(chan, SH7751_PCICONF0);
90 if (id != ((SH7751_DEVICE_ID << 16) | SH7751_VENDOR_ID) &&
91 id != ((SH7751R_DEVICE_ID << 16) | SH7751_VENDOR_ID)) {
92 pr_debug("PCI: This is not an SH7751(R) (%x)\n", id);
93 return -ENODEV;
94 }
95
96 if ((ret = sh4_pci_check_direct(chan)) != 0)
97 return ret;
86 98
87 /* Set the BCR's to enable PCI access */ 99 /* Set the BCR's to enable PCI access */
88 reg = ctrl_inl(SH7751_BCR1); 100 reg = ctrl_inl(SH7751_BCR1);
@@ -90,25 +102,10 @@ int __init sh7751_pcic_init(struct sh4_pci_address_map *map)
90 ctrl_outl(reg, SH7751_BCR1); 102 ctrl_outl(reg, SH7751_BCR1);
91 103
92 /* Turn the clocks back on (not done in reset)*/ 104 /* Turn the clocks back on (not done in reset)*/
93 pci_write_reg(0, SH4_PCICLKR); 105 pci_write_reg(chan, 0, SH4_PCICLKR);
94 /* Clear Powerdown IRQ's (not done in reset) */ 106 /* Clear Powerdown IRQ's (not done in reset) */
95 word = SH4_PCIPINT_D3 | SH4_PCIPINT_D0; 107 word = SH4_PCIPINT_D3 | SH4_PCIPINT_D0;
96 pci_write_reg(word, SH4_PCIPINT); 108 pci_write_reg(chan, word, SH4_PCIPINT);
97
98 /*
99 * This code is unused for some boards as it is done in the
100 * bootloader and doing it here means the MAC addresses loaded
101 * by the bootloader get lost.
102 */
103 if (!(map->flags & SH4_PCIC_NO_RESET)) {
104 /* toggle PCI reset pin */
105 word = SH4_PCICR_PREFIX | SH4_PCICR_PRST;
106 pci_write_reg(word, SH4_PCICR);
107 /* Wait for a long time... not 1 sec. but long enough */
108 mdelay(100);
109 word = SH4_PCICR_PREFIX;
110 pci_write_reg(word, SH4_PCICR);
111 }
112 109
113 /* set the command/status bits to: 110 /* set the command/status bits to:
114 * Wait Cycle Control + Parity Enable + Bus Master + 111 * Wait Cycle Control + Parity Enable + Bus Master +
@@ -116,89 +113,75 @@ int __init sh7751_pcic_init(struct sh4_pci_address_map *map)
116 */ 113 */
117 word = SH7751_PCICONF1_WCC | SH7751_PCICONF1_PER | 114 word = SH7751_PCICONF1_WCC | SH7751_PCICONF1_PER |
118 SH7751_PCICONF1_BUM | SH7751_PCICONF1_MES; 115 SH7751_PCICONF1_BUM | SH7751_PCICONF1_MES;
119 pci_write_reg(word, SH7751_PCICONF1); 116 pci_write_reg(chan, word, SH7751_PCICONF1);
120 117
121 /* define this host as the host bridge */ 118 /* define this host as the host bridge */
122 word = PCI_BASE_CLASS_BRIDGE << 24; 119 word = PCI_BASE_CLASS_BRIDGE << 24;
123 pci_write_reg(word, SH7751_PCICONF2); 120 pci_write_reg(chan, word, SH7751_PCICONF2);
124 121
125 /* Set IO and Mem windows to local address 122 /* Set IO and Mem windows to local address
126 * Make PCI and local address the same for easy 1 to 1 mapping 123 * Make PCI and local address the same for easy 1 to 1 mapping
127 * Window0 = map->window0.size @ non-cached area base = SDRAM
128 * Window1 = map->window1.size @ cached area base = SDRAM
129 */ 124 */
130 word = map->window0.size - 1; 125 word = sh7751_pci_map.window0.size - 1;
131 pci_write_reg(word, SH4_PCILSR0); 126 pci_write_reg(chan, word, SH4_PCILSR0);
132 word = map->window1.size - 1;
133 pci_write_reg(word, SH4_PCILSR1);
134 /* Set the values on window 0 PCI config registers */ 127 /* Set the values on window 0 PCI config registers */
135 word = P2SEGADDR(map->window0.base); 128 word = P2SEGADDR(sh7751_pci_map.window0.base);
136 pci_write_reg(word, SH4_PCILAR0); 129 pci_write_reg(chan, word, SH4_PCILAR0);
137 pci_write_reg(word, SH7751_PCICONF5); 130 pci_write_reg(chan, word, SH7751_PCICONF5);
138 /* Set the values on window 1 PCI config registers */
139 word = PHYSADDR(map->window1.base);
140 pci_write_reg(word, SH4_PCILAR1);
141 pci_write_reg(word, SH7751_PCICONF6);
142 131
143 /* Set the local 16MB PCI memory space window to 132 /* Set the local 16MB PCI memory space window to
144 * the lowest PCI mapped address 133 * the lowest PCI mapped address
145 */ 134 */
146 word = PCIBIOS_MIN_MEM & SH4_PCIMBR_MASK; 135 word = chan->mem_resource->start & SH4_PCIMBR_MASK;
147 pr_debug("PCI: Setting upper bits of Memory window to 0x%x\n", word); 136 pr_debug("PCI: Setting upper bits of Memory window to 0x%x\n", word);
148 pci_write_reg(word , SH4_PCIMBR); 137 pci_write_reg(chan, word , SH4_PCIMBR);
149
150 /* Map IO space into PCI IO window
151 * The IO window is 64K-PCIBIOS_MIN_IO in size
152 * IO addresses will be translated to the
153 * PCI IO window base address
154 */
155 pr_debug("PCI: Mapping IO address 0x%x - 0x%x to base 0x%x\n",
156 PCIBIOS_MIN_IO, (64 << 10),
157 SH7751_PCI_IO_BASE + PCIBIOS_MIN_IO);
158 138
159 /* Make sure the MSB's of IO window are set to access PCI space 139 /* Make sure the MSB's of IO window are set to access PCI space
160 * correctly */ 140 * correctly */
161 word = PCIBIOS_MIN_IO & SH4_PCIIOBR_MASK; 141 word = chan->io_resource->start & SH4_PCIIOBR_MASK;
162 pr_debug("PCI: Setting upper bits of IO window to 0x%x\n", word); 142 pr_debug("PCI: Setting upper bits of IO window to 0x%x\n", word);
163 pci_write_reg(word, SH4_PCIIOBR); 143 pci_write_reg(chan, word, SH4_PCIIOBR);
164 144
165 /* Set PCI WCRx, BCRx's, copy from BSC locations */ 145 /* Set PCI WCRx, BCRx's, copy from BSC locations */
166 146
167 /* check BCR for SDRAM in specified area */ 147 /* check BCR for SDRAM in specified area */
168 switch (map->window0.base) { 148 switch (sh7751_pci_map.window0.base) {
169 case SH7751_CS0_BASE_ADDR: word = __area_sdram_check(0); break; 149 case SH7751_CS0_BASE_ADDR: word = __area_sdram_check(chan, 0); break;
170 case SH7751_CS1_BASE_ADDR: word = __area_sdram_check(1); break; 150 case SH7751_CS1_BASE_ADDR: word = __area_sdram_check(chan, 1); break;
171 case SH7751_CS2_BASE_ADDR: word = __area_sdram_check(2); break; 151 case SH7751_CS2_BASE_ADDR: word = __area_sdram_check(chan, 2); break;
172 case SH7751_CS3_BASE_ADDR: word = __area_sdram_check(3); break; 152 case SH7751_CS3_BASE_ADDR: word = __area_sdram_check(chan, 3); break;
173 case SH7751_CS4_BASE_ADDR: word = __area_sdram_check(4); break; 153 case SH7751_CS4_BASE_ADDR: word = __area_sdram_check(chan, 4); break;
174 case SH7751_CS5_BASE_ADDR: word = __area_sdram_check(5); break; 154 case SH7751_CS5_BASE_ADDR: word = __area_sdram_check(chan, 5); break;
175 case SH7751_CS6_BASE_ADDR: word = __area_sdram_check(6); break; 155 case SH7751_CS6_BASE_ADDR: word = __area_sdram_check(chan, 6); break;
176 } 156 }
177 157
178 if (!word) 158 if (!word)
179 return 0; 159 return -1;
180 160
181 /* configure the wait control registers */ 161 /* configure the wait control registers */
182 word = ctrl_inl(SH7751_WCR1); 162 word = ctrl_inl(SH7751_WCR1);
183 pci_write_reg(word, SH4_PCIWCR1); 163 pci_write_reg(chan, word, SH4_PCIWCR1);
184 word = ctrl_inl(SH7751_WCR2); 164 word = ctrl_inl(SH7751_WCR2);
185 pci_write_reg(word, SH4_PCIWCR2); 165 pci_write_reg(chan, word, SH4_PCIWCR2);
186 word = ctrl_inl(SH7751_WCR3); 166 word = ctrl_inl(SH7751_WCR3);
187 pci_write_reg(word, SH4_PCIWCR3); 167 pci_write_reg(chan, word, SH4_PCIWCR3);
188 word = ctrl_inl(SH7751_MCR); 168 word = ctrl_inl(SH7751_MCR);
189 pci_write_reg(word, SH4_PCIMCR); 169 pci_write_reg(chan, word, SH4_PCIMCR);
190 170
191 /* NOTE: I'm ignoring the PCI error IRQs for now.. 171 /* NOTE: I'm ignoring the PCI error IRQs for now..
192 * TODO: add support for the internal error interrupts and 172 * TODO: add support for the internal error interrupts and
193 * DMA interrupts... 173 * DMA interrupts...
194 */ 174 */
195 175
196 pci_fixup_pcic(); 176 pci_fixup_pcic(chan);
197 177
198 /* SH7751 init done, set central function init complete */ 178 /* SH7751 init done, set central function init complete */
199 /* use round robin mode to stop a device starving/overruning */ 179 /* use round robin mode to stop a device starving/overruning */
200 word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_ARBM; 180 word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_ARBM;
201 pci_write_reg(word, SH4_PCICR); 181 pci_write_reg(chan, word, SH4_PCICR);
202 182
203 return 1; 183 register_pci_controller(chan);
184
185 return 0;
204} 186}
187arch_initcall(sh7751_pci_init);
diff --git a/arch/sh/drivers/pci/pci-sh7751.h b/arch/sh/drivers/pci/pci-sh7751.h
index 68e3cb5e6bec..4983a4d20355 100644
--- a/arch/sh/drivers/pci/pci-sh7751.h
+++ b/arch/sh/drivers/pci/pci-sh7751.h
@@ -26,7 +26,6 @@
26#define SH7751_PCI_IO_SIZE 0x40000 /* Size of IO window */ 26#define SH7751_PCI_IO_SIZE 0x40000 /* Size of IO window */
27 27
28#define SH7751_PCIREG_BASE 0xFE200000 /* PCI regs base address */ 28#define SH7751_PCIREG_BASE 0xFE200000 /* PCI regs base address */
29#define PCI_REG(n) (SH7751_PCIREG_BASE+ n)
30 29
31#define SH7751_PCICONF0 0x0 /* PCI Config Reg 0 */ 30#define SH7751_PCICONF0 0x0 /* PCI Config Reg 0 */
32 #define SH7751_PCICONF0_DEVID 0xFFFF0000 /* Device ID */ 31 #define SH7751_PCICONF0_DEVID 0xFFFF0000 /* Device ID */
@@ -58,7 +57,7 @@
58 #define SH7751_PCICONF2_SCC 0x00FF0000 /* Sub-Class Code */ 57 #define SH7751_PCICONF2_SCC 0x00FF0000 /* Sub-Class Code */
59 #define SH7751_PCICONF2_RLPI 0x0000FF00 /* Programming Interface */ 58 #define SH7751_PCICONF2_RLPI 0x0000FF00 /* Programming Interface */
60 #define SH7751_PCICONF2_REV 0x000000FF /* Revision ID */ 59 #define SH7751_PCICONF2_REV 0x000000FF /* Revision ID */
61#define SH7751_PCICONF3 0xC /* PCI Config Reg 3 */ 60#define SH7751_PCICONF3 0xC /* PCI Config Reg 3 */
62 #define SH7751_PCICONF3_BIST7 0x80000000 /* Bist Supported */ 61 #define SH7751_PCICONF3_BIST7 0x80000000 /* Bist Supported */
63 #define SH7751_PCICONF3_BIST6 0x40000000 /* Bist Executing */ 62 #define SH7751_PCICONF3_BIST6 0x40000000 /* Bist Executing */
64 #define SH7751_PCICONF3_BIST3_0 0x0F000000 /* Bist Passed */ 63 #define SH7751_PCICONF3_BIST3_0 0x0F000000 /* Bist Passed */
@@ -73,12 +72,12 @@
73 #define SH7751_PCICONF5_BASE 0xFFFFFFF0 /* Mem Space Base Addr */ 72 #define SH7751_PCICONF5_BASE 0xFFFFFFF0 /* Mem Space Base Addr */
74 #define SH7751_PCICONF5_LAP 0x00000008 /* Prefetch Enabled */ 73 #define SH7751_PCICONF5_LAP 0x00000008 /* Prefetch Enabled */
75 #define SH7751_PCICONF5_LAT 0x00000006 /* Local Memory type */ 74 #define SH7751_PCICONF5_LAT 0x00000006 /* Local Memory type */
76 #define SH7751_PCICONF5_ASI 0x00000001 /* Address Space Type */ 75 #define SH7751_PCICONF5_ASI 0x00000001 /* Address Space Type */
77#define SH7751_PCICONF6 0x18 /* PCI Config Reg 6 */ 76#define SH7751_PCICONF6 0x18 /* PCI Config Reg 6 */
78 #define SH7751_PCICONF6_BASE 0xFFFFFFF0 /* Mem Space Base Addr */ 77 #define SH7751_PCICONF6_BASE 0xFFFFFFF0 /* Mem Space Base Addr */
79 #define SH7751_PCICONF6_LAP 0x00000008 /* Prefetch Enabled */ 78 #define SH7751_PCICONF6_LAP 0x00000008 /* Prefetch Enabled */
80 #define SH7751_PCICONF6_LAT 0x00000006 /* Local Memory type */ 79 #define SH7751_PCICONF6_LAT 0x00000006 /* Local Memory type */
81 #define SH7751_PCICONF6_ASI 0x00000001 /* Address Space Type */ 80 #define SH7751_PCICONF6_ASI 0x00000001 /* Address Space Type */
82/* PCICONF7 - PCICONF10 are undefined */ 81/* PCICONF7 - PCICONF10 are undefined */
83#define SH7751_PCICONF11 0x2C /* PCI Config Reg 11 */ 82#define SH7751_PCICONF11 0x2C /* PCI Config Reg 11 */
84 #define SH7751_PCICONF11_SSID 0xFFFF0000 /* Subsystem ID */ 83 #define SH7751_PCICONF11_SSID 0xFFFF0000 /* Subsystem ID */
@@ -127,9 +126,4 @@
127#define SH7751_CS5_BASE_ADDR (SH7751_CS4_BASE_ADDR + SH7751_MEM_REGION_SIZE) 126#define SH7751_CS5_BASE_ADDR (SH7751_CS4_BASE_ADDR + SH7751_MEM_REGION_SIZE)
128#define SH7751_CS6_BASE_ADDR (SH7751_CS5_BASE_ADDR + SH7751_MEM_REGION_SIZE) 127#define SH7751_CS6_BASE_ADDR (SH7751_CS5_BASE_ADDR + SH7751_MEM_REGION_SIZE)
129 128
130struct sh4_pci_address_map;
131
132/* arch/sh/drivers/pci/pci-sh7751.c */
133int sh7751_pcic_init(struct sh4_pci_address_map *map);
134
135#endif /* _PCI_SH7751_H_ */ 129#endif /* _PCI_SH7751_H_ */
diff --git a/arch/sh/drivers/pci/pci-sh7780.c b/arch/sh/drivers/pci/pci-sh7780.c
index bae6a2cf047d..323b92d565fe 100644
--- a/arch/sh/drivers/pci/pci-sh7780.c
+++ b/arch/sh/drivers/pci/pci-sh7780.c
@@ -1,19 +1,12 @@
1/* 1/*
2 * Low-Level PCI Support for the SH7780 2 * Low-Level PCI Support for the SH7780
3 * 3 *
4 * Dustin McIntire (dustin@sensoria.com) 4 * Copyright (C) 2005 - 2009 Paul Mundt
5 * Derived from arch/i386/kernel/pci-*.c which bore the message:
6 * (c) 1999--2000 Martin Mares <mj@ucw.cz>
7 *
8 * Ported to the new API by Paul Mundt <lethal@linux-sh.org>
9 * With cleanup by Paul van Gool <pvangool@mimotech.com>
10 *
11 * May be copied or modified under the terms of the GNU General Public
12 * License. See linux/COPYING for more information.
13 * 5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
14 */ 9 */
15#undef DEBUG
16
17#include <linux/types.h> 10#include <linux/types.h>
18#include <linux/kernel.h> 11#include <linux/kernel.h>
19#include <linux/init.h> 12#include <linux/init.h>
@@ -22,135 +15,132 @@
22#include <linux/delay.h> 15#include <linux/delay.h>
23#include "pci-sh4.h" 16#include "pci-sh4.h"
24 17
25#define INTC_BASE 0xffd00000 18static struct resource sh7785_io_resource = {
26#define INTC_ICR0 (INTC_BASE+0x0) 19 .name = "SH7785_IO",
27#define INTC_ICR1 (INTC_BASE+0x1c) 20 .start = SH7780_PCI_IO_BASE,
28#define INTC_INTPRI (INTC_BASE+0x10) 21 .end = SH7780_PCI_IO_BASE + SH7780_PCI_IO_SIZE - 1,
29#define INTC_INTREQ (INTC_BASE+0x24) 22 .flags = IORESOURCE_IO
30#define INTC_INTMSK0 (INTC_BASE+0x44) 23};
31#define INTC_INTMSK1 (INTC_BASE+0x48) 24
32#define INTC_INTMSK2 (INTC_BASE+0x40080) 25static struct resource sh7785_mem_resource = {
33#define INTC_INTMSKCLR0 (INTC_BASE+0x64) 26 .name = "SH7785_mem",
34#define INTC_INTMSKCLR1 (INTC_BASE+0x68) 27 .start = SH7780_PCI_MEMORY_BASE,
35#define INTC_INTMSKCLR2 (INTC_BASE+0x40084) 28 .end = SH7780_PCI_MEMORY_BASE + SH7780_PCI_MEM_SIZE - 1,
36#define INTC_INT2MSKR (INTC_BASE+0x40038) 29 .flags = IORESOURCE_MEM
37#define INTC_INT2MSKCR (INTC_BASE+0x4003c) 30};
31
32static struct pci_channel sh7780_pci_controller = {
33 .pci_ops = &sh4_pci_ops,
34 .mem_resource = &sh7785_mem_resource,
35 .mem_offset = 0x00000000,
36 .io_resource = &sh7785_io_resource,
37 .io_offset = 0x00000000,
38 .io_map_base = SH7780_PCI_IO_BASE,
39};
40
41static struct sh4_pci_address_map sh7780_pci_map = {
42 .window0 = {
43#if defined(CONFIG_32BIT)
44 .base = SH7780_32BIT_DDR_BASE_ADDR,
45 .size = 0x40000000,
46#else
47 .base = SH7780_CS0_BASE_ADDR,
48 .size = 0x20000000,
49#endif
50 },
51};
38 52
39/*
40 * Initialization. Try all known PCI access methods. Note that we support
41 * using both PCI BIOS and direct access: in such cases, we use I/O ports
42 * to access config space.
43 *
44 * Note that the platform specific initialization (BSC registers, and memory
45 * space mapping) will be called via the platform defined function
46 * pcibios_init_platform().
47 */
48static int __init sh7780_pci_init(void) 53static int __init sh7780_pci_init(void)
49{ 54{
55 struct pci_channel *chan = &sh7780_pci_controller;
50 unsigned int id; 56 unsigned int id;
51 int ret, match = 0; 57 const char *type = NULL;
52 58 int ret;
53 pr_debug("PCI: Starting intialization.\n"); 59 u32 word;
54
55 ctrl_outl(0x00000001, SH7780_PCI_VCR2); /* Enable PCIC */
56
57 /* check for SH7780/SH7780R hardware */
58 id = pci_read_reg(SH7780_PCIVID);
59 if ((id & 0xffff) == SH7780_VENDOR_ID) {
60 switch ((id >> 16) & 0xffff) {
61 case SH7763_DEVICE_ID:
62 case SH7780_DEVICE_ID:
63 case SH7781_DEVICE_ID:
64 case SH7785_DEVICE_ID:
65 match = 1;
66 break;
67 }
68 }
69 60
70 if (unlikely(!match)) { 61 printk(KERN_NOTICE "PCI: Starting intialization.\n");
71 printk(KERN_ERR "PCI: This is not an SH7780 (%x)\n", id); 62
63 chan->reg_base = 0xfe040000;
64
65 /* Enable CPU access to the PCIC registers. */
66 __raw_writel(PCIECR_ENBL, PCIECR);
67
68 id = __raw_readw(chan->reg_base + SH7780_PCIVID);
69 if (id != SH7780_VENDOR_ID) {
70 printk(KERN_ERR "PCI: Unknown vendor ID 0x%04x.\n", id);
72 return -ENODEV; 71 return -ENODEV;
73 } 72 }
74 73
75 /* Setup the INTC */ 74 id = __raw_readw(chan->reg_base + SH7780_PCIDID);
76 if (mach_is_7780se()) { 75 type = (id == SH7763_DEVICE_ID) ? "SH7763" :
77 /* ICR0: IRL=use separately */ 76 (id == SH7780_DEVICE_ID) ? "SH7780" :
78 ctrl_outl(0x00C00020, INTC_ICR0); 77 (id == SH7781_DEVICE_ID) ? "SH7781" :
79 /* ICR1: detect low level(for 2ndcut) */ 78 (id == SH7785_DEVICE_ID) ? "SH7785" :
80 ctrl_outl(0xAAAA0000, INTC_ICR1); 79 NULL;
81 /* INTPRI: priority=3(all) */ 80 if (unlikely(!type)) {
82 ctrl_outl(0x33333333, INTC_INTPRI); 81 printk(KERN_ERR "PCI: Found an unsupported Renesas host "
82 "controller, device id 0x%04x.\n", id);
83 return -EINVAL;
83 } 84 }
84 85
85 if ((ret = sh4_pci_check_direct()) != 0) 86 printk(KERN_NOTICE "PCI: Found a Renesas %s host "
86 return ret; 87 "controller, revision %d.\n", type,
88 __raw_readb(chan->reg_base + SH7780_PCIRID));
87 89
88 return pcibios_init_platform(); 90 if ((ret = sh4_pci_check_direct(chan)) != 0)
89} 91 return ret;
90core_initcall(sh7780_pci_init);
91
92int __init sh7780_pcic_init(struct sh4_pci_address_map *map)
93{
94 u32 word;
95 92
96 /* 93 /*
97 * This code is unused for some boards as it is done in the 94 * Set the class and sub-class codes.
98 * bootloader and doing it here means the MAC addresses loaded
99 * by the bootloader get lost.
100 */
101 if (!(map->flags & SH4_PCIC_NO_RESET)) {
102 /* toggle PCI reset pin */
103 word = SH4_PCICR_PREFIX | SH4_PCICR_PRST;
104 pci_write_reg(word, SH4_PCICR);
105 /* Wait for a long time... not 1 sec. but long enough */
106 mdelay(100);
107 word = SH4_PCICR_PREFIX;
108 pci_write_reg(word, SH4_PCICR);
109 }
110
111 /* set the command/status bits to:
112 * Wait Cycle Control + Parity Enable + Bus Master +
113 * Mem space enable
114 */ 95 */
115 pci_write_reg(0x00000046, SH7780_PCICMD); 96 __raw_writeb(PCI_CLASS_BRIDGE_HOST >> 8,
116 97 chan->reg_base + SH7780_PCIBCC);
117 /* define this host as the host bridge */ 98 __raw_writeb(PCI_CLASS_BRIDGE_HOST & 0xff,
118 word = PCI_BASE_CLASS_BRIDGE << 24; 99 chan->reg_base + SH7780_PCISUB);
119 pci_write_reg(word, SH7780_PCIRID);
120 100
121 /* Set IO and Mem windows to local address 101 /*
102 * Set IO and Mem windows to local address
122 * Make PCI and local address the same for easy 1 to 1 mapping 103 * Make PCI and local address the same for easy 1 to 1 mapping
123 */ 104 */
124 pci_write_reg(map->window0.size - 0xfffff, SH4_PCILSR0); 105 pci_write_reg(chan, sh7780_pci_map.window0.size - 0xfffff, SH4_PCILSR0);
125 pci_write_reg(map->window1.size - 0xfffff, SH4_PCILSR1);
126 /* Set the values on window 0 PCI config registers */ 106 /* Set the values on window 0 PCI config registers */
127 pci_write_reg(map->window0.base, SH4_PCILAR0); 107 pci_write_reg(chan, sh7780_pci_map.window0.base, SH4_PCILAR0);
128 pci_write_reg(map->window0.base, SH7780_PCIMBAR0); 108 pci_write_reg(chan, sh7780_pci_map.window0.base, SH7780_PCIMBAR0);
129 /* Set the values on window 1 PCI config registers */
130 pci_write_reg(map->window1.base, SH4_PCILAR1);
131 pci_write_reg(map->window1.base, SH7780_PCIMBAR1);
132
133 /* Map IO space into PCI IO window
134 * The IO window is 64K-PCIBIOS_MIN_IO in size
135 * IO addresses will be translated to the
136 * PCI IO window base address
137 */
138 pr_debug("PCI: Mapping IO address 0x%x - 0x%x to base 0x%x\n",
139 PCIBIOS_MIN_IO, (64 << 10),
140 SH7780_PCI_IO_BASE + PCIBIOS_MIN_IO);
141 109
142 /* NOTE: I'm ignoring the PCI error IRQs for now.. 110 pci_write_reg(chan, 0x0000380f, SH4_PCIAINTM);
143 * TODO: add support for the internal error interrupts and 111
144 * DMA interrupts... 112 /* Set up standard PCI config registers */
145 */ 113 __raw_writew(0xFB00, chan->reg_base + SH7780_PCISTATUS);
114 __raw_writew(0x0047, chan->reg_base + SH7780_PCICMD);
115 __raw_writew(0x1912, chan->reg_base + SH7780_PCISVID);
116 __raw_writew(0x0001, chan->reg_base + SH7780_PCISID);
117
118 __raw_writeb(0x00, chan->reg_base + SH7780_PCIPIF);
146 119
147 /* Apply any last-minute PCIC fixups */ 120 /* Apply any last-minute PCIC fixups */
148 pci_fixup_pcic(); 121 pci_fixup_pcic(chan);
122
123 pci_write_reg(chan, 0xfd000000, SH7780_PCIMBR0);
124 pci_write_reg(chan, 0x00fc0000, SH7780_PCIMBMR0);
125
126#ifdef CONFIG_32BIT
127 pci_write_reg(chan, 0xc0000000, SH7780_PCIMBR2);
128 pci_write_reg(chan, 0x20000000 - SH7780_PCI_IO_SIZE, SH7780_PCIMBMR2);
129#endif
130
131 /* Set IOBR for windows containing area specified in pci.h */
132 pci_write_reg(chan, chan->io_resource->start & ~(SH7780_PCI_IO_SIZE-1),
133 SH7780_PCIIOBR);
134 pci_write_reg(chan, ((SH7780_PCI_IO_SIZE-1) & (7<<18)),
135 SH7780_PCIIOBMR);
149 136
150 /* SH7780 init done, set central function init complete */ 137 /* SH7780 init done, set central function init complete */
151 /* use round robin mode to stop a device starving/overruning */ 138 /* use round robin mode to stop a device starving/overruning */
152 word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO; 139 word = SH4_PCICR_PREFIX | SH4_PCICR_CFIN | SH4_PCICR_FTO;
153 pci_write_reg(word, SH4_PCICR); 140 pci_write_reg(chan, word, SH4_PCICR);
141
142 register_pci_controller(chan);
154 143
155 return 1; 144 return 0;
156} 145}
146arch_initcall(sh7780_pci_init);
diff --git a/arch/sh/drivers/pci/pci-sh7780.h b/arch/sh/drivers/pci/pci-sh7780.h
index 93adc7119b79..4a52478c97cf 100644
--- a/arch/sh/drivers/pci/pci-sh7780.h
+++ b/arch/sh/drivers/pci/pci-sh7780.h
@@ -20,9 +20,8 @@
20#define SH7785_DEVICE_ID 0x0007 20#define SH7785_DEVICE_ID 0x0007
21 21
22/* SH7780 Control Registers */ 22/* SH7780 Control Registers */
23#define SH7780_PCI_VCR0 0xFE000000 23#define PCIECR 0xFE000008
24#define SH7780_PCI_VCR1 0xFE000004 24#define PCIECR_ENBL 0x01
25#define SH7780_PCI_VCR2 0xFE000008
26 25
27/* SH7780 Specific Values */ 26/* SH7780 Specific Values */
28#define SH7780_PCI_CONFIG_BASE 0xFD000000 /* Config space base addr */ 27#define SH7780_PCI_CONFIG_BASE 0xFD000000 /* Config space base addr */
@@ -35,7 +34,6 @@
35#define SH7780_PCI_IO_SIZE 0x00400000 /* Size of IO window */ 34#define SH7780_PCI_IO_SIZE 0x00400000 /* Size of IO window */
36 35
37#define SH7780_PCIREG_BASE 0xFE040000 /* PCI regs base address */ 36#define SH7780_PCIREG_BASE 0xFE040000 /* PCI regs base address */
38#define PCI_REG(n) (SH7780_PCIREG_BASE+n)
39 37
40/* SH7780 PCI Config Registers */ 38/* SH7780 PCI Config Registers */
41#define SH7780_PCIVID 0x000 /* Vendor ID */ 39#define SH7780_PCIVID 0x000 /* Vendor ID */
@@ -67,11 +65,6 @@
67#define SH7780_PCIPMCSR_BSE 0x046 65#define SH7780_PCIPMCSR_BSE 0x046
68#define SH7780_PCICDD 0x047 66#define SH7780_PCICDD 0x047
69 67
70#define SH7780_PCICR 0x100 /* PCI Control Register */
71#define SH7780_PCILSR 0x104 /* PCI Local Space Register0 */
72#define SH7780_PCILSR1 0x108 /* PCI Local Space Register1 */
73#define SH7780_PCILAR0 0x10C /* PCI Local Address Register1 */
74#define SH7780_PCILAR1 0x110 /* PCI Local Address Register1 */
75#define SH7780_PCIIR 0x114 /* PCI Interrupt Register */ 68#define SH7780_PCIIR 0x114 /* PCI Interrupt Register */
76#define SH7780_PCIIMR 0x118 /* PCI Interrupt Mask Register */ 69#define SH7780_PCIIMR 0x118 /* PCI Interrupt Mask Register */
77#define SH7780_PCIAIR 0x11C /* Error Address Register */ 70#define SH7780_PCIAIR 0x11C /* Error Address Register */
@@ -106,9 +99,4 @@
106 99
107#define SH7780_32BIT_DDR_BASE_ADDR 0x40000000 100#define SH7780_32BIT_DDR_BASE_ADDR 0x40000000
108 101
109struct sh4_pci_address_map;
110
111/* arch/sh/drivers/pci/pci-sh7780.c */
112int sh7780_pcic_init(struct sh4_pci_address_map *map);
113
114#endif /* _PCI_SH7780_H_ */ 102#endif /* _PCI_SH7780_H_ */
diff --git a/arch/sh/drivers/pci/pci.c b/arch/sh/drivers/pci/pci.c
index 0d6ac7a1db49..54d77cbb8b39 100644
--- a/arch/sh/drivers/pci/pci.c
+++ b/arch/sh/drivers/pci/pci.c
@@ -1,67 +1,156 @@
1/* 1/*
2 * arch/sh/drivers/pci/pci.c 2 * New-style PCI core.
3 * 3 *
4 * Copyright (c) 2002 M. R. Brown <mrbrown@linux-sh.org> 4 * Copyright (c) 2004 - 2009 Paul Mundt
5 * Copyright (c) 2004 - 2006 Paul Mundt <lethal@linux-sh.org> 5 * Copyright (c) 2002 M. R. Brown
6 * 6 *
7 * These functions are collected here to reduce duplication of common 7 * Modelled after arch/mips/pci/pci.c:
8 * code amongst the many platform-specific PCI support code files. 8 * Copyright (C) 2003, 04 Ralf Baechle (ralf@linux-mips.org)
9 *
10 * These routines require the following board-specific routines:
11 * void pcibios_fixup_irqs();
12 *
13 * See include/asm-sh/pci.h for more information.
14 * 9 *
15 * This file is subject to the terms and conditions of the GNU General Public 10 * This file is subject to the terms and conditions of the GNU General Public
16 * License. See the file "COPYING" in the main directory of this archive 11 * License. See the file "COPYING" in the main directory of this archive
17 * for more details. 12 * for more details.
18 */ 13 */
19#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/mm.h>
20#include <linux/pci.h> 16#include <linux/pci.h>
21#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/types.h>
22#include <linux/dma-debug.h> 19#include <linux/dma-debug.h>
23#include <asm/io.h> 20#include <linux/io.h>
21#include <linux/mutex.h>
24 22
25static int __init pcibios_init(void) 23unsigned long PCIBIOS_MIN_IO = 0x0000;
24unsigned long PCIBIOS_MIN_MEM = 0;
25
26/*
27 * The PCI controller list.
28 */
29static struct pci_channel *hose_head, **hose_tail = &hose_head;
30
31static int pci_initialized;
32
33static void __devinit pcibios_scanbus(struct pci_channel *hose)
26{ 34{
27 struct pci_channel *p; 35 static int next_busno;
28 struct pci_bus *bus; 36 struct pci_bus *bus;
29 int busno;
30 37
31#ifdef CONFIG_PCI_AUTO 38 bus = pci_scan_bus(next_busno, hose->pci_ops, hose);
32 /* assign resources */ 39 if (bus) {
33 busno = 0; 40 next_busno = bus->subordinate + 1;
34 for (p = board_pci_channels; p->pci_ops != NULL; p++) 41 /* Don't allow 8-bit bus number overflow inside the hose -
35 busno = pciauto_assign_resources(busno, p) + 1; 42 reserve some space for bridges. */
36#endif 43 if (next_busno > 224)
44 next_busno = 0;
45
46 pci_bus_size_bridges(bus);
47 pci_bus_assign_resources(bus);
48 pci_enable_bridges(bus);
49 }
50}
51
52static DEFINE_MUTEX(pci_scan_mutex);
37 53
38 /* scan the buses */ 54void __devinit register_pci_controller(struct pci_channel *hose)
39 busno = 0; 55{
40 for (p = board_pci_channels; p->pci_ops != NULL; p++) { 56 if (request_resource(&iomem_resource, hose->mem_resource) < 0)
41 bus = pci_scan_bus(busno, p->pci_ops, p); 57 goto out;
42 busno = bus->subordinate + 1; 58 if (request_resource(&ioport_resource, hose->io_resource) < 0) {
59 release_resource(hose->mem_resource);
60 goto out;
43 } 61 }
44 62
63 *hose_tail = hose;
64 hose_tail = &hose->next;
65
66 /*
67 * Do not panic here but later - this might hapen before console init.
68 */
69 if (!hose->io_map_base) {
70 printk(KERN_WARNING
71 "registering PCI controller with io_map_base unset\n");
72 }
73
74 /*
75 * Scan the bus if it is register after the PCI subsystem
76 * initialization.
77 */
78 if (pci_initialized) {
79 mutex_lock(&pci_scan_mutex);
80 pcibios_scanbus(hose);
81 mutex_unlock(&pci_scan_mutex);
82 }
83
84 return;
85
86out:
87 printk(KERN_WARNING
88 "Skipping PCI bus scan due to resource conflict\n");
89}
90
91static int __init pcibios_init(void)
92{
93 struct pci_channel *hose;
94
95 /* Scan all of the recorded PCI controllers. */
96 for (hose = hose_head; hose; hose = hose->next)
97 pcibios_scanbus(hose);
98
45 pci_fixup_irqs(pci_common_swizzle, pcibios_map_platform_irq); 99 pci_fixup_irqs(pci_common_swizzle, pcibios_map_platform_irq);
46 100
47 dma_debug_add_bus(&pci_bus_type); 101 dma_debug_add_bus(&pci_bus_type);
48 102
103 pci_initialized = 1;
104
49 return 0; 105 return 0;
50} 106}
51subsys_initcall(pcibios_init); 107subsys_initcall(pcibios_init);
52 108
109static void pcibios_fixup_device_resources(struct pci_dev *dev,
110 struct pci_bus *bus)
111{
112 /* Update device resources. */
113 struct pci_channel *hose = bus->sysdata;
114 unsigned long offset = 0;
115 int i;
116
117 for (i = 0; i < PCI_NUM_RESOURCES; i++) {
118 if (!dev->resource[i].start)
119 continue;
120 if (dev->resource[i].flags & IORESOURCE_PCI_FIXED)
121 continue;
122 if (dev->resource[i].flags & IORESOURCE_IO)
123 offset = hose->io_offset;
124 else if (dev->resource[i].flags & IORESOURCE_MEM)
125 offset = hose->mem_offset;
126
127 dev->resource[i].start += offset;
128 dev->resource[i].end += offset;
129 }
130}
131
53/* 132/*
54 * Called after each bus is probed, but before its children 133 * Called after each bus is probed, but before its children
55 * are examined. 134 * are examined.
56 */ 135 */
57void __devinit __weak pcibios_fixup_bus(struct pci_bus *bus) 136void __devinit pcibios_fixup_bus(struct pci_bus *bus)
58{ 137{
59 pci_read_bridge_bases(bus); 138 struct pci_dev *dev = bus->self;
60} 139 struct list_head *ln;
140 struct pci_channel *chan = bus->sysdata;
61 141
62void pcibios_align_resource(void *data, struct resource *res, 142 if (!dev) {
63 resource_size_t size, resource_size_t align) 143 bus->resource[0] = chan->io_resource;
64 __attribute__ ((weak)); 144 bus->resource[1] = chan->mem_resource;
145 }
146
147 for (ln = bus->devices.next; ln != &bus->devices; ln = ln->next) {
148 dev = pci_dev_b(ln);
149
150 if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)
151 pcibios_fixup_device_resources(dev, bus);
152 }
153}
65 154
66/* 155/*
67 * We need to avoid collisions with `mirrored' VGA ports 156 * We need to avoid collisions with `mirrored' VGA ports
@@ -72,14 +161,58 @@ void pcibios_align_resource(void *data, struct resource *res,
72void pcibios_align_resource(void *data, struct resource *res, 161void pcibios_align_resource(void *data, struct resource *res,
73 resource_size_t size, resource_size_t align) 162 resource_size_t size, resource_size_t align)
74{ 163{
164 struct pci_dev *dev = data;
165 struct pci_channel *chan = dev->sysdata;
166 resource_size_t start = res->start;
167
75 if (res->flags & IORESOURCE_IO) { 168 if (res->flags & IORESOURCE_IO) {
76 resource_size_t start = res->start; 169 if (start < PCIBIOS_MIN_IO + chan->io_resource->start)
170 start = PCIBIOS_MIN_IO + chan->io_resource->start;
77 171
172 /*
173 * Put everything into 0x00-0xff region modulo 0x400.
174 */
78 if (start & 0x300) { 175 if (start & 0x300) {
79 start = (start + 0x3ff) & ~0x3ff; 176 start = (start + 0x3ff) & ~0x3ff;
80 res->start = start; 177 res->start = start;
81 } 178 }
179 } else if (res->flags & IORESOURCE_MEM) {
180 if (start < PCIBIOS_MIN_MEM + chan->mem_resource->start)
181 start = PCIBIOS_MIN_MEM + chan->mem_resource->start;
82 } 182 }
183
184 res->start = start;
185}
186
187void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
188 struct resource *res)
189{
190 struct pci_channel *hose = dev->sysdata;
191 unsigned long offset = 0;
192
193 if (res->flags & IORESOURCE_IO)
194 offset = hose->io_offset;
195 else if (res->flags & IORESOURCE_MEM)
196 offset = hose->mem_offset;
197
198 region->start = res->start - offset;
199 region->end = res->end - offset;
200}
201
202void __devinit
203pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
204 struct pci_bus_region *region)
205{
206 struct pci_channel *hose = dev->sysdata;
207 unsigned long offset = 0;
208
209 if (res->flags & IORESOURCE_IO)
210 offset = hose->io_offset;
211 else if (res->flags & IORESOURCE_MEM)
212 offset = hose->mem_offset;
213
214 res->start = region->start + offset;
215 res->end = region->end + offset;
83} 216}
84 217
85int pcibios_enable_device(struct pci_dev *dev, int mask) 218int pcibios_enable_device(struct pci_dev *dev, int mask)
@@ -90,13 +223,21 @@ int pcibios_enable_device(struct pci_dev *dev, int mask)
90 223
91 pci_read_config_word(dev, PCI_COMMAND, &cmd); 224 pci_read_config_word(dev, PCI_COMMAND, &cmd);
92 old_cmd = cmd; 225 old_cmd = cmd;
93 for(idx=0; idx<6; idx++) { 226 for (idx=0; idx < PCI_NUM_RESOURCES; idx++) {
94 if (!(mask & (1 << idx))) 227 /* Only set up the requested stuff */
228 if (!(mask & (1<<idx)))
95 continue; 229 continue;
230
96 r = &dev->resource[idx]; 231 r = &dev->resource[idx];
232 if (!(r->flags & (IORESOURCE_IO | IORESOURCE_MEM)))
233 continue;
234 if ((idx == PCI_ROM_RESOURCE) &&
235 (!(r->flags & IORESOURCE_ROM_ENABLE)))
236 continue;
97 if (!r->start && r->end) { 237 if (!r->start && r->end) {
98 printk(KERN_ERR "PCI: Device %s not available because " 238 printk(KERN_ERR "PCI: Device %s not available "
99 "of resource collisions\n", pci_name(dev)); 239 "because of resource collisions\n",
240 pci_name(dev));
100 return -EINVAL; 241 return -EINVAL;
101 } 242 }
102 if (r->flags & IORESOURCE_IO) 243 if (r->flags & IORESOURCE_IO)
@@ -104,10 +245,8 @@ int pcibios_enable_device(struct pci_dev *dev, int mask)
104 if (r->flags & IORESOURCE_MEM) 245 if (r->flags & IORESOURCE_MEM)
105 cmd |= PCI_COMMAND_MEMORY; 246 cmd |= PCI_COMMAND_MEMORY;
106 } 247 }
107 if (dev->resource[PCI_ROM_RESOURCE].start)
108 cmd |= PCI_COMMAND_MEMORY;
109 if (cmd != old_cmd) { 248 if (cmd != old_cmd) {
110 printk(KERN_INFO "PCI: Enabling device %s (%04x -> %04x)\n", 249 printk("PCI: Enabling device %s (%04x -> %04x)\n",
111 pci_name(dev), old_cmd, cmd); 250 pci_name(dev), old_cmd, cmd);
112 pci_write_config_word(dev, PCI_COMMAND, cmd); 251 pci_write_config_word(dev, PCI_COMMAND, cmd);
113 } 252 }
@@ -140,6 +279,43 @@ void __init pcibios_update_irq(struct pci_dev *dev, int irq)
140 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq); 279 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
141} 280}
142 281
282char * __devinit pcibios_setup(char *str)
283{
284 return str;
285}
286
287int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
288 enum pci_mmap_state mmap_state, int write_combine)
289{
290 /*
291 * I/O space can be accessed via normal processor loads and stores on
292 * this platform but for now we elect not to do this and portable
293 * drivers should not do this anyway.
294 */
295 if (mmap_state == pci_mmap_io)
296 return -EINVAL;
297
298 /*
299 * Ignore write-combine; for now only return uncached mappings.
300 */
301 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
302
303 return remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
304 vma->vm_end - vma->vm_start,
305 vma->vm_page_prot);
306}
307
308static void __iomem *ioport_map_pci(struct pci_dev *dev,
309 unsigned long port, unsigned int nr)
310{
311 struct pci_channel *chan = dev->sysdata;
312
313 if (!chan->io_map_base)
314 chan->io_map_base = generic_io_base;
315
316 return (void __iomem *)(chan->io_map_base + port);
317}
318
143void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen) 319void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
144{ 320{
145 resource_size_t start = pci_resource_start(dev, bar); 321 resource_size_t start = pci_resource_start(dev, bar);
@@ -151,20 +327,24 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
151 if (maxlen && len > maxlen) 327 if (maxlen && len > maxlen)
152 len = maxlen; 328 len = maxlen;
153 329
330 if (flags & IORESOURCE_IO)
331 return ioport_map_pci(dev, start, len);
332
154 /* 333 /*
155 * Presently the IORESOURCE_MEM case is a bit special, most 334 * Presently the IORESOURCE_MEM case is a bit special, most
156 * SH7751 style PCI controllers have PCI memory at a fixed 335 * SH7751 style PCI controllers have PCI memory at a fixed
157 * location in the address space where no remapping is desired 336 * location in the address space where no remapping is desired.
158 * (typically at 0xfd000000, but is_pci_memaddr() will know 337 * With the IORESOURCE_MEM case more care has to be taken
159 * best). With the IORESOURCE_MEM case more care has to be taken
160 * to inhibit page table mapping for legacy cores, but this is 338 * to inhibit page table mapping for legacy cores, but this is
161 * punted off to __ioremap(). 339 * punted off to __ioremap().
162 * -- PFM. 340 * -- PFM.
163 */ 341 */
164 if (flags & IORESOURCE_IO) 342 if (flags & IORESOURCE_MEM) {
165 return ioport_map(start, len); 343 if (flags & IORESOURCE_CACHEABLE)
166 if (flags & IORESOURCE_MEM) 344 return ioremap(start, len);
167 return ioremap(start, len); 345
346 return ioremap_nocache(start, len);
347 }
168 348
169 return NULL; 349 return NULL;
170} 350}
@@ -175,3 +355,10 @@ void pci_iounmap(struct pci_dev *dev, void __iomem *addr)
175 iounmap(addr); 355 iounmap(addr);
176} 356}
177EXPORT_SYMBOL(pci_iounmap); 357EXPORT_SYMBOL(pci_iounmap);
358
359#ifdef CONFIG_HOTPLUG
360EXPORT_SYMBOL(pcibios_resource_to_bus);
361EXPORT_SYMBOL(pcibios_bus_to_resource);
362EXPORT_SYMBOL(PCIBIOS_MIN_IO);
363EXPORT_SYMBOL(PCIBIOS_MIN_MEM);
364#endif
diff --git a/arch/sh/include/asm/atomic-llsc.h b/arch/sh/include/asm/atomic-llsc.h
index 4b00b78e3f4f..b040e1e08610 100644
--- a/arch/sh/include/asm/atomic-llsc.h
+++ b/arch/sh/include/asm/atomic-llsc.h
@@ -104,4 +104,31 @@ static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
104 : "t"); 104 : "t");
105} 105}
106 106
107#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
108
109/**
110 * atomic_add_unless - add unless the number is a given value
111 * @v: pointer of type atomic_t
112 * @a: the amount to add to v...
113 * @u: ...unless v is equal to u.
114 *
115 * Atomically adds @a to @v, so long as it was not @u.
116 * Returns non-zero if @v was not @u, and zero otherwise.
117 */
118static inline int atomic_add_unless(atomic_t *v, int a, int u)
119{
120 int c, old;
121 c = atomic_read(v);
122 for (;;) {
123 if (unlikely(c == (u)))
124 break;
125 old = atomic_cmpxchg((v), c, c + (a));
126 if (likely(old == c))
127 break;
128 c = old;
129 }
130
131 return c != (u);
132}
133
107#endif /* __ASM_SH_ATOMIC_LLSC_H */ 134#endif /* __ASM_SH_ATOMIC_LLSC_H */
diff --git a/arch/sh/include/asm/atomic.h b/arch/sh/include/asm/atomic.h
index 6327ffbb1992..978b58efb1e9 100644
--- a/arch/sh/include/asm/atomic.h
+++ b/arch/sh/include/asm/atomic.h
@@ -45,7 +45,7 @@
45#define atomic_inc(v) atomic_add(1,(v)) 45#define atomic_inc(v) atomic_add(1,(v))
46#define atomic_dec(v) atomic_sub(1,(v)) 46#define atomic_dec(v) atomic_sub(1,(v))
47 47
48#ifndef CONFIG_GUSA_RB 48#if !defined(CONFIG_GUSA_RB) && !defined(CONFIG_CPU_SH4A)
49static inline int atomic_cmpxchg(atomic_t *v, int old, int new) 49static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
50{ 50{
51 int ret; 51 int ret;
@@ -73,7 +73,7 @@ static inline int atomic_add_unless(atomic_t *v, int a, int u)
73 73
74 return ret != u; 74 return ret != u;
75} 75}
76#endif 76#endif /* !CONFIG_GUSA_RB && !CONFIG_CPU_SH4A */
77 77
78#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) 78#define atomic_xchg(v, new) (xchg(&((v)->counter), new))
79#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) 79#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0)
diff --git a/arch/sh/include/asm/cacheflush.h b/arch/sh/include/asm/cacheflush.h
index 09acbc32d6c7..4c5462daa74c 100644
--- a/arch/sh/include/asm/cacheflush.h
+++ b/arch/sh/include/asm/cacheflush.h
@@ -75,7 +75,5 @@ extern void copy_from_user_page(struct vm_area_struct *vma,
75#define flush_cache_vmap(start, end) flush_cache_all() 75#define flush_cache_vmap(start, end) flush_cache_all()
76#define flush_cache_vunmap(start, end) flush_cache_all() 76#define flush_cache_vunmap(start, end) flush_cache_all()
77 77
78#define HAVE_ARCH_UNMAPPED_AREA
79
80#endif /* __KERNEL__ */ 78#endif /* __KERNEL__ */
81#endif /* __ASM_SH_CACHEFLUSH_H */ 79#endif /* __ASM_SH_CACHEFLUSH_H */
diff --git a/arch/sh/include/asm/clock.h b/arch/sh/include/asm/clock.h
index 2f6c9627bc1f..9fe7d7f8af40 100644
--- a/arch/sh/include/asm/clock.h
+++ b/arch/sh/include/asm/clock.h
@@ -1,9 +1,9 @@
1#ifndef __ASM_SH_CLOCK_H 1#ifndef __ASM_SH_CLOCK_H
2#define __ASM_SH_CLOCK_H 2#define __ASM_SH_CLOCK_H
3 3
4#include <linux/kref.h>
5#include <linux/list.h> 4#include <linux/list.h>
6#include <linux/seq_file.h> 5#include <linux/seq_file.h>
6#include <linux/cpufreq.h>
7#include <linux/clk.h> 7#include <linux/clk.h>
8#include <linux/err.h> 8#include <linux/err.h>
9 9
@@ -11,9 +11,9 @@ struct clk;
11 11
12struct clk_ops { 12struct clk_ops {
13 void (*init)(struct clk *clk); 13 void (*init)(struct clk *clk);
14 void (*enable)(struct clk *clk); 14 int (*enable)(struct clk *clk);
15 void (*disable)(struct clk *clk); 15 void (*disable)(struct clk *clk);
16 void (*recalc)(struct clk *clk); 16 unsigned long (*recalc)(struct clk *clk);
17 int (*set_rate)(struct clk *clk, unsigned long rate, int algo_id); 17 int (*set_rate)(struct clk *clk, unsigned long rate, int algo_id);
18 int (*set_parent)(struct clk *clk, struct clk *parent); 18 int (*set_parent)(struct clk *clk, struct clk *parent);
19 long (*round_rate)(struct clk *clk, unsigned long rate); 19 long (*round_rate)(struct clk *clk, unsigned long rate);
@@ -28,43 +28,47 @@ struct clk {
28 struct clk *parent; 28 struct clk *parent;
29 struct clk_ops *ops; 29 struct clk_ops *ops;
30 30
31 struct kref kref; 31 struct list_head children;
32 struct list_head sibling; /* node for children */
33
34 int usecount;
32 35
33 unsigned long rate; 36 unsigned long rate;
34 unsigned long flags; 37 unsigned long flags;
38
39 void __iomem *enable_reg;
40 unsigned int enable_bit;
41
35 unsigned long arch_flags; 42 unsigned long arch_flags;
43 void *priv;
44 struct dentry *dentry;
45 struct cpufreq_frequency_table *freq_table;
46};
47
48struct clk_lookup {
49 struct list_head node;
50 const char *dev_id;
51 const char *con_id;
52 struct clk *clk;
36}; 53};
37 54
38#define CLK_ALWAYS_ENABLED (1 << 0) 55#define CLK_ENABLE_ON_INIT (1 << 0)
39#define CLK_RATE_PROPAGATES (1 << 1)
40 56
41/* Should be defined by processor-specific code */ 57/* Should be defined by processor-specific code */
42void arch_init_clk_ops(struct clk_ops **, int type); 58void __deprecated arch_init_clk_ops(struct clk_ops **, int type);
43int __init arch_clk_init(void); 59int __init arch_clk_init(void);
44 60
45/* arch/sh/kernel/cpu/clock.c */ 61/* arch/sh/kernel/cpu/clock.c */
46int clk_init(void); 62int clk_init(void);
47 63unsigned long followparent_recalc(struct clk *);
48void clk_recalc_rate(struct clk *); 64void recalculate_root_clocks(void);
49 65void propagate_rate(struct clk *);
66int clk_reparent(struct clk *child, struct clk *parent);
50int clk_register(struct clk *); 67int clk_register(struct clk *);
51void clk_unregister(struct clk *); 68void clk_unregister(struct clk *);
52 69
53static inline int clk_always_enable(const char *id) 70/* arch/sh/kernel/cpu/clock-cpg.c */
54{ 71int __init __deprecated cpg_clk_init(void);
55 struct clk *clk;
56 int ret;
57
58 clk = clk_get(NULL, id);
59 if (IS_ERR(clk))
60 return PTR_ERR(clk);
61
62 ret = clk_enable(clk);
63 if (ret)
64 clk_put(clk);
65
66 return ret;
67}
68 72
69/* the exported API, in addition to clk_set_rate */ 73/* the exported API, in addition to clk_set_rate */
70/** 74/**
@@ -96,4 +100,63 @@ enum clk_sh_algo_id {
96 100
97 IP_N1, 101 IP_N1,
98}; 102};
103
104struct clk_div_mult_table {
105 unsigned int *divisors;
106 unsigned int nr_divisors;
107 unsigned int *multipliers;
108 unsigned int nr_multipliers;
109};
110
111struct cpufreq_frequency_table;
112void clk_rate_table_build(struct clk *clk,
113 struct cpufreq_frequency_table *freq_table,
114 int nr_freqs,
115 struct clk_div_mult_table *src_table,
116 unsigned long *bitmap);
117
118long clk_rate_table_round(struct clk *clk,
119 struct cpufreq_frequency_table *freq_table,
120 unsigned long rate);
121
122int clk_rate_table_find(struct clk *clk,
123 struct cpufreq_frequency_table *freq_table,
124 unsigned long rate);
125
126#define SH_CLK_MSTP32(_name, _id, _parent, _enable_reg, \
127 _enable_bit, _flags) \
128{ \
129 .name = _name, \
130 .id = _id, \
131 .parent = _parent, \
132 .enable_reg = (void __iomem *)_enable_reg, \
133 .enable_bit = _enable_bit, \
134 .flags = _flags, \
135}
136
137int sh_clk_mstp32_register(struct clk *clks, int nr);
138
139#define SH_CLK_DIV4(_name, _parent, _reg, _shift, _div_bitmap, _flags) \
140{ \
141 .name = _name, \
142 .parent = _parent, \
143 .enable_reg = (void __iomem *)_reg, \
144 .enable_bit = _shift, \
145 .arch_flags = _div_bitmap, \
146 .flags = _flags, \
147}
148
149int sh_clk_div4_register(struct clk *clks, int nr,
150 struct clk_div_mult_table *table);
151
152#define SH_CLK_DIV6(_name, _parent, _reg, _flags) \
153{ \
154 .name = _name, \
155 .parent = _parent, \
156 .enable_reg = (void __iomem *)_reg, \
157 .flags = _flags, \
158}
159
160int sh_clk_div6_register(struct clk *clks, int nr);
161
99#endif /* __ASM_SH_CLOCK_H */ 162#endif /* __ASM_SH_CLOCK_H */
diff --git a/arch/sh/include/asm/cmpxchg-llsc.h b/arch/sh/include/asm/cmpxchg-llsc.h
index 0fac3da536ca..47136661a203 100644
--- a/arch/sh/include/asm/cmpxchg-llsc.h
+++ b/arch/sh/include/asm/cmpxchg-llsc.h
@@ -55,7 +55,7 @@ __cmpxchg_u32(volatile int *m, unsigned long old, unsigned long new)
55 "mov %0, %1 \n\t" 55 "mov %0, %1 \n\t"
56 "cmp/eq %1, %3 \n\t" 56 "cmp/eq %1, %3 \n\t"
57 "bf 2f \n\t" 57 "bf 2f \n\t"
58 "mov %3, %0 \n\t" 58 "mov %4, %0 \n\t"
59 "2: \n\t" 59 "2: \n\t"
60 "movco.l %0, @%2 \n\t" 60 "movco.l %0, @%2 \n\t"
61 "bf 1b \n\t" 61 "bf 1b \n\t"
diff --git a/arch/sh/include/asm/device.h b/arch/sh/include/asm/device.h
index efd511d0803a..8688a88303ee 100644
--- a/arch/sh/include/asm/device.h
+++ b/arch/sh/include/asm/device.h
@@ -10,3 +10,5 @@ struct platform_device;
10int platform_resource_setup_memory(struct platform_device *pdev, 10int platform_resource_setup_memory(struct platform_device *pdev,
11 char *name, unsigned long memsize); 11 char *name, unsigned long memsize);
12 12
13void plat_early_device_setup(void);
14
diff --git a/arch/sh/include/asm/hd64461.h b/arch/sh/include/asm/hd64461.h
index 52b4b6238277..977355f0a483 100644
--- a/arch/sh/include/asm/hd64461.h
+++ b/arch/sh/include/asm/hd64461.h
@@ -13,18 +13,20 @@
13#define HD64461_PCC_WINDOW 0x01000000 13#define HD64461_PCC_WINDOW 0x01000000
14 14
15/* Area 6 - Slot 0 - memory and/or IO card */ 15/* Area 6 - Slot 0 - memory and/or IO card */
16#define HD64461_PCC0_BASE (CONFIG_HD64461_IOBASE + 0x8000000) 16#define HD64461_IOBASE 0xb0000000
17#define HD64461_IO_OFFSET(x) (HD64461_IOBASE + (x))
18#define HD64461_PCC0_BASE HD64461_IO_OFFSET(0x8000000)
17#define HD64461_PCC0_ATTR (HD64461_PCC0_BASE) /* 0xb80000000 */ 19#define HD64461_PCC0_ATTR (HD64461_PCC0_BASE) /* 0xb80000000 */
18#define HD64461_PCC0_COMM (HD64461_PCC0_BASE+HD64461_PCC_WINDOW) /* 0xb90000000 */ 20#define HD64461_PCC0_COMM (HD64461_PCC0_BASE+HD64461_PCC_WINDOW) /* 0xb90000000 */
19#define HD64461_PCC0_IO (HD64461_PCC0_BASE+2*HD64461_PCC_WINDOW) /* 0xba0000000 */ 21#define HD64461_PCC0_IO (HD64461_PCC0_BASE+2*HD64461_PCC_WINDOW) /* 0xba0000000 */
20 22
21/* Area 5 - Slot 1 - memory card only */ 23/* Area 5 - Slot 1 - memory card only */
22#define HD64461_PCC1_BASE (CONFIG_HD64461_IOBASE + 0x4000000) 24#define HD64461_PCC1_BASE HD64461_IO_OFFSET(0x4000000)
23#define HD64461_PCC1_ATTR (HD64461_PCC1_BASE) /* 0xb4000000 */ 25#define HD64461_PCC1_ATTR (HD64461_PCC1_BASE) /* 0xb4000000 */
24#define HD64461_PCC1_COMM (HD64461_PCC1_BASE+HD64461_PCC_WINDOW) /* 0xb5000000 */ 26#define HD64461_PCC1_COMM (HD64461_PCC1_BASE+HD64461_PCC_WINDOW) /* 0xb5000000 */
25 27
26/* Standby Control Register for HD64461 */ 28/* Standby Control Register for HD64461 */
27#define HD64461_STBCR CONFIG_HD64461_IOBASE 29#define HD64461_STBCR HD64461_IO_OFFSET(0x00000000)
28#define HD64461_STBCR_CKIO_STBY 0x2000 30#define HD64461_STBCR_CKIO_STBY 0x2000
29#define HD64461_STBCR_SAFECKE_IST 0x1000 31#define HD64461_STBCR_SAFECKE_IST 0x1000
30#define HD64461_STBCR_SLCKE_IST 0x0800 32#define HD64461_STBCR_SLCKE_IST 0x0800
@@ -41,19 +43,19 @@
41#define HD64461_STBCR_SURTST 0x0001 43#define HD64461_STBCR_SURTST 0x0001
42 44
43/* System Configuration Register */ 45/* System Configuration Register */
44#define HD64461_SYSCR (CONFIG_HD64461_IOBASE + 0x02) 46#define HD64461_SYSCR HD64461_IO_OFFSET(0x02)
45 47
46/* CPU Data Bus Control Register */ 48/* CPU Data Bus Control Register */
47#define HD64461_SCPUCR (CONFIG_HD64461_IOBASE + 0x04) 49#define HD64461_SCPUCR HD64461_IO_OFFSET(0x04)
48 50
49/* Base Address Register */ 51/* Base Address Register */
50#define HD64461_LCDCBAR (CONFIG_HD64461_IOBASE + 0x1000) 52#define HD64461_LCDCBAR HD64461_IO_OFFSET(0x1000)
51 53
52/* Line increment address */ 54/* Line increment address */
53#define HD64461_LCDCLOR (CONFIG_HD64461_IOBASE + 0x1002) 55#define HD64461_LCDCLOR HD64461_IO_OFFSET(0x1002)
54 56
55/* Controls LCD controller */ 57/* Controls LCD controller */
56#define HD64461_LCDCCR (CONFIG_HD64461_IOBASE + 0x1004) 58#define HD64461_LCDCCR HD64461_IO_OFFSET(0x1004)
57 59
58/* LCCDR control bits */ 60/* LCCDR control bits */
59#define HD64461_LCDCCR_STBACK 0x0400 /* Standby Back */ 61#define HD64461_LCDCCR_STBACK 0x0400 /* Standby Back */
@@ -64,30 +66,30 @@
64#define HD64461_LCDCCR_SPON 0x0010 /* Start Power On */ 66#define HD64461_LCDCCR_SPON 0x0010 /* Start Power On */
65 67
66/* Controls LCD (1) */ 68/* Controls LCD (1) */
67#define HD64461_LDR1 (CONFIG_HD64461_IOBASE + 0x1010) 69#define HD64461_LDR1 HD64461_IO_OFFSET(0x1010)
68#define HD64461_LDR1_DON 0x01 /* Display On */ 70#define HD64461_LDR1_DON 0x01 /* Display On */
69#define HD64461_LDR1_DINV 0x80 /* Display Invert */ 71#define HD64461_LDR1_DINV 0x80 /* Display Invert */
70 72
71/* Controls LCD (2) */ 73/* Controls LCD (2) */
72#define HD64461_LDR2 (CONFIG_HD64461_IOBASE + 0x1012) 74#define HD64461_LDR2 HD64461_IO_OFFSET(0x1012)
73#define HD64461_LDHNCR (CONFIG_HD64461_IOBASE + 0x1014) /* Number of horizontal characters */ 75#define HD64461_LDHNCR HD64461_IO_OFFSET(0x1014) /* Number of horizontal characters */
74#define HD64461_LDHNSR (CONFIG_HD64461_IOBASE + 0x1016) /* Specify output start position + width of CL1 */ 76#define HD64461_LDHNSR HD64461_IO_OFFSET(0x1016) /* Specify output start position + width of CL1 */
75#define HD64461_LDVNTR (CONFIG_HD64461_IOBASE + 0x1018) /* Specify total vertical lines */ 77#define HD64461_LDVNTR HD64461_IO_OFFSET(0x1018) /* Specify total vertical lines */
76#define HD64461_LDVNDR (CONFIG_HD64461_IOBASE + 0x101a) /* specify number of display vertical lines */ 78#define HD64461_LDVNDR HD64461_IO_OFFSET(0x101a) /* specify number of display vertical lines */
77#define HD64461_LDVSPR (CONFIG_HD64461_IOBASE + 0x101c) /* specify vertical synchronization pos and AC nr */ 79#define HD64461_LDVSPR HD64461_IO_OFFSET(0x101c) /* specify vertical synchronization pos and AC nr */
78 80
79/* Controls LCD (3) */ 81/* Controls LCD (3) */
80#define HD64461_LDR3 (CONFIG_HD64461_IOBASE + 0x101e) 82#define HD64461_LDR3 HD64461_IO_OFFSET(0x101e)
81 83
82/* Palette Registers */ 84/* Palette Registers */
83#define HD64461_CPTWAR (CONFIG_HD64461_IOBASE + 0x1030) /* Color Palette Write Address Register */ 85#define HD64461_CPTWAR HD64461_IO_OFFSET(0x1030) /* Color Palette Write Address Register */
84#define HD64461_CPTWDR (CONFIG_HD64461_IOBASE + 0x1032) /* Color Palette Write Data Register */ 86#define HD64461_CPTWDR HD64461_IO_OFFSET(0x1032) /* Color Palette Write Data Register */
85#define HD64461_CPTRAR (CONFIG_HD64461_IOBASE + 0x1034) /* Color Palette Read Address Register */ 87#define HD64461_CPTRAR HD64461_IO_OFFSET(0x1034) /* Color Palette Read Address Register */
86#define HD64461_CPTRDR (CONFIG_HD64461_IOBASE + 0x1036) /* Color Palette Read Data Register */ 88#define HD64461_CPTRDR HD64461_IO_OFFSET(0x1036) /* Color Palette Read Data Register */
87 89
88#define HD64461_GRDOR (CONFIG_HD64461_IOBASE + 0x1040) /* Display Resolution Offset Register */ 90#define HD64461_GRDOR HD64461_IO_OFFSET(0x1040) /* Display Resolution Offset Register */
89#define HD64461_GRSCR (CONFIG_HD64461_IOBASE + 0x1042) /* Solid Color Register */ 91#define HD64461_GRSCR HD64461_IO_OFFSET(0x1042) /* Solid Color Register */
90#define HD64461_GRCFGR (CONFIG_HD64461_IOBASE + 0x1044) /* Accelerator Configuration Register */ 92#define HD64461_GRCFGR HD64461_IO_OFFSET(0x1044) /* Accelerator Configuration Register */
91 93
92#define HD64461_GRCFGR_ACCSTATUS 0x10 /* Accelerator Status */ 94#define HD64461_GRCFGR_ACCSTATUS 0x10 /* Accelerator Status */
93#define HD64461_GRCFGR_ACCRESET 0x08 /* Accelerator Reset */ 95#define HD64461_GRCFGR_ACCRESET 0x08 /* Accelerator Reset */
@@ -97,41 +99,41 @@
97#define HD64461_GRCFGR_COLORDEPTH8 0x01 /* Sets Colordepth 8 for Accelerator */ 99#define HD64461_GRCFGR_COLORDEPTH8 0x01 /* Sets Colordepth 8 for Accelerator */
98 100
99/* Line Drawing Registers */ 101/* Line Drawing Registers */
100#define HD64461_LNSARH (CONFIG_HD64461_IOBASE + 0x1046) /* Line Start Address Register (H) */ 102#define HD64461_LNSARH HD64461_IO_OFFSET(0x1046) /* Line Start Address Register (H) */
101#define HD64461_LNSARL (CONFIG_HD64461_IOBASE + 0x1048) /* Line Start Address Register (L) */ 103#define HD64461_LNSARL HD64461_IO_OFFSET(0x1048) /* Line Start Address Register (L) */
102#define HD64461_LNAXLR (CONFIG_HD64461_IOBASE + 0x104a) /* Axis Pixel Length Register */ 104#define HD64461_LNAXLR HD64461_IO_OFFSET(0x104a) /* Axis Pixel Length Register */
103#define HD64461_LNDGR (CONFIG_HD64461_IOBASE + 0x104c) /* Diagonal Register */ 105#define HD64461_LNDGR HD64461_IO_OFFSET(0x104c) /* Diagonal Register */
104#define HD64461_LNAXR (CONFIG_HD64461_IOBASE + 0x104e) /* Axial Register */ 106#define HD64461_LNAXR HD64461_IO_OFFSET(0x104e) /* Axial Register */
105#define HD64461_LNERTR (CONFIG_HD64461_IOBASE + 0x1050) /* Start Error Term Register */ 107#define HD64461_LNERTR HD64461_IO_OFFSET(0x1050) /* Start Error Term Register */
106#define HD64461_LNMDR (CONFIG_HD64461_IOBASE + 0x1052) /* Line Mode Register */ 108#define HD64461_LNMDR HD64461_IO_OFFSET(0x1052) /* Line Mode Register */
107 109
108/* BitBLT Registers */ 110/* BitBLT Registers */
109#define HD64461_BBTSSARH (CONFIG_HD64461_IOBASE + 0x1054) /* Source Start Address Register (H) */ 111#define HD64461_BBTSSARH HD64461_IO_OFFSET(0x1054) /* Source Start Address Register (H) */
110#define HD64461_BBTSSARL (CONFIG_HD64461_IOBASE + 0x1056) /* Source Start Address Register (L) */ 112#define HD64461_BBTSSARL HD64461_IO_OFFSET(0x1056) /* Source Start Address Register (L) */
111#define HD64461_BBTDSARH (CONFIG_HD64461_IOBASE + 0x1058) /* Destination Start Address Register (H) */ 113#define HD64461_BBTDSARH HD64461_IO_OFFSET(0x1058) /* Destination Start Address Register (H) */
112#define HD64461_BBTDSARL (CONFIG_HD64461_IOBASE + 0x105a) /* Destination Start Address Register (L) */ 114#define HD64461_BBTDSARL HD64461_IO_OFFSET(0x105a) /* Destination Start Address Register (L) */
113#define HD64461_BBTDWR (CONFIG_HD64461_IOBASE + 0x105c) /* Destination Block Width Register */ 115#define HD64461_BBTDWR HD64461_IO_OFFSET(0x105c) /* Destination Block Width Register */
114#define HD64461_BBTDHR (CONFIG_HD64461_IOBASE + 0x105e) /* Destination Block Height Register */ 116#define HD64461_BBTDHR HD64461_IO_OFFSET(0x105e) /* Destination Block Height Register */
115#define HD64461_BBTPARH (CONFIG_HD64461_IOBASE + 0x1060) /* Pattern Start Address Register (H) */ 117#define HD64461_BBTPARH HD64461_IO_OFFSET(0x1060) /* Pattern Start Address Register (H) */
116#define HD64461_BBTPARL (CONFIG_HD64461_IOBASE + 0x1062) /* Pattern Start Address Register (L) */ 118#define HD64461_BBTPARL HD64461_IO_OFFSET(0x1062) /* Pattern Start Address Register (L) */
117#define HD64461_BBTMARH (CONFIG_HD64461_IOBASE + 0x1064) /* Mask Start Address Register (H) */ 119#define HD64461_BBTMARH HD64461_IO_OFFSET(0x1064) /* Mask Start Address Register (H) */
118#define HD64461_BBTMARL (CONFIG_HD64461_IOBASE + 0x1066) /* Mask Start Address Register (L) */ 120#define HD64461_BBTMARL HD64461_IO_OFFSET(0x1066) /* Mask Start Address Register (L) */
119#define HD64461_BBTROPR (CONFIG_HD64461_IOBASE + 0x1068) /* ROP Register */ 121#define HD64461_BBTROPR HD64461_IO_OFFSET(0x1068) /* ROP Register */
120#define HD64461_BBTMDR (CONFIG_HD64461_IOBASE + 0x106a) /* BitBLT Mode Register */ 122#define HD64461_BBTMDR HD64461_IO_OFFSET(0x106a) /* BitBLT Mode Register */
121 123
122/* PC Card Controller Registers */ 124/* PC Card Controller Registers */
123/* Maps to Physical Area 6 */ 125/* Maps to Physical Area 6 */
124#define HD64461_PCC0ISR (CONFIG_HD64461_IOBASE + 0x2000) /* socket 0 interface status */ 126#define HD64461_PCC0ISR HD64461_IO_OFFSET(0x2000) /* socket 0 interface status */
125#define HD64461_PCC0GCR (CONFIG_HD64461_IOBASE + 0x2002) /* socket 0 general control */ 127#define HD64461_PCC0GCR HD64461_IO_OFFSET(0x2002) /* socket 0 general control */
126#define HD64461_PCC0CSCR (CONFIG_HD64461_IOBASE + 0x2004) /* socket 0 card status change */ 128#define HD64461_PCC0CSCR HD64461_IO_OFFSET(0x2004) /* socket 0 card status change */
127#define HD64461_PCC0CSCIER (CONFIG_HD64461_IOBASE + 0x2006) /* socket 0 card status change interrupt enable */ 129#define HD64461_PCC0CSCIER HD64461_IO_OFFSET(0x2006) /* socket 0 card status change interrupt enable */
128#define HD64461_PCC0SCR (CONFIG_HD64461_IOBASE + 0x2008) /* socket 0 software control */ 130#define HD64461_PCC0SCR HD64461_IO_OFFSET(0x2008) /* socket 0 software control */
129/* Maps to Physical Area 5 */ 131/* Maps to Physical Area 5 */
130#define HD64461_PCC1ISR (CONFIG_HD64461_IOBASE + 0x2010) /* socket 1 interface status */ 132#define HD64461_PCC1ISR HD64461_IO_OFFSET(0x2010) /* socket 1 interface status */
131#define HD64461_PCC1GCR (CONFIG_HD64461_IOBASE + 0x2012) /* socket 1 general control */ 133#define HD64461_PCC1GCR HD64461_IO_OFFSET(0x2012) /* socket 1 general control */
132#define HD64461_PCC1CSCR (CONFIG_HD64461_IOBASE + 0x2014) /* socket 1 card status change */ 134#define HD64461_PCC1CSCR HD64461_IO_OFFSET(0x2014) /* socket 1 card status change */
133#define HD64461_PCC1CSCIER (CONFIG_HD64461_IOBASE + 0x2016) /* socket 1 card status change interrupt enable */ 135#define HD64461_PCC1CSCIER HD64461_IO_OFFSET(0x2016) /* socket 1 card status change interrupt enable */
134#define HD64461_PCC1SCR (CONFIG_HD64461_IOBASE + 0x2018) /* socket 1 software control */ 136#define HD64461_PCC1SCR HD64461_IO_OFFSET(0x2018) /* socket 1 software control */
135 137
136/* PCC Interface Status Register */ 138/* PCC Interface Status Register */
137#define HD64461_PCCISR_READY 0x80 /* card ready */ 139#define HD64461_PCCISR_READY 0x80 /* card ready */
@@ -189,41 +191,41 @@
189#define HD64461_PCCSCR_SWP 0x01 /* write protect */ 191#define HD64461_PCCSCR_SWP 0x01 /* write protect */
190 192
191/* PCC0 Output Pins Control Register */ 193/* PCC0 Output Pins Control Register */
192#define HD64461_P0OCR (CONFIG_HD64461_IOBASE + 0x202a) 194#define HD64461_P0OCR HD64461_IO_OFFSET(0x202a)
193 195
194/* PCC1 Output Pins Control Register */ 196/* PCC1 Output Pins Control Register */
195#define HD64461_P1OCR (CONFIG_HD64461_IOBASE + 0x202c) 197#define HD64461_P1OCR HD64461_IO_OFFSET(0x202c)
196 198
197/* PC Card General Control Register */ 199/* PC Card General Control Register */
198#define HD64461_PGCR (CONFIG_HD64461_IOBASE + 0x202e) 200#define HD64461_PGCR HD64461_IO_OFFSET(0x202e)
199 201
200/* Port Control Registers */ 202/* Port Control Registers */
201#define HD64461_GPACR (CONFIG_HD64461_IOBASE + 0x4000) /* Port A - Handles IRDA/TIMER */ 203#define HD64461_GPACR HD64461_IO_OFFSET(0x4000) /* Port A - Handles IRDA/TIMER */
202#define HD64461_GPBCR (CONFIG_HD64461_IOBASE + 0x4002) /* Port B - Handles UART */ 204#define HD64461_GPBCR HD64461_IO_OFFSET(0x4002) /* Port B - Handles UART */
203#define HD64461_GPCCR (CONFIG_HD64461_IOBASE + 0x4004) /* Port C - Handles PCMCIA 1 */ 205#define HD64461_GPCCR HD64461_IO_OFFSET(0x4004) /* Port C - Handles PCMCIA 1 */
204#define HD64461_GPDCR (CONFIG_HD64461_IOBASE + 0x4006) /* Port D - Handles PCMCIA 1 */ 206#define HD64461_GPDCR HD64461_IO_OFFSET(0x4006) /* Port D - Handles PCMCIA 1 */
205 207
206/* Port Control Data Registers */ 208/* Port Control Data Registers */
207#define HD64461_GPADR (CONFIG_HD64461_IOBASE + 0x4010) /* A */ 209#define HD64461_GPADR HD64461_IO_OFFSET(0x4010) /* A */
208#define HD64461_GPBDR (CONFIG_HD64461_IOBASE + 0x4012) /* B */ 210#define HD64461_GPBDR HD64461_IO_OFFSET(0x4012) /* B */
209#define HD64461_GPCDR (CONFIG_HD64461_IOBASE + 0x4014) /* C */ 211#define HD64461_GPCDR HD64461_IO_OFFSET(0x4014) /* C */
210#define HD64461_GPDDR (CONFIG_HD64461_IOBASE + 0x4016) /* D */ 212#define HD64461_GPDDR HD64461_IO_OFFSET(0x4016) /* D */
211 213
212/* Interrupt Control Registers */ 214/* Interrupt Control Registers */
213#define HD64461_GPAICR (CONFIG_HD64461_IOBASE + 0x4020) /* A */ 215#define HD64461_GPAICR HD64461_IO_OFFSET(0x4020) /* A */
214#define HD64461_GPBICR (CONFIG_HD64461_IOBASE + 0x4022) /* B */ 216#define HD64461_GPBICR HD64461_IO_OFFSET(0x4022) /* B */
215#define HD64461_GPCICR (CONFIG_HD64461_IOBASE + 0x4024) /* C */ 217#define HD64461_GPCICR HD64461_IO_OFFSET(0x4024) /* C */
216#define HD64461_GPDICR (CONFIG_HD64461_IOBASE + 0x4026) /* D */ 218#define HD64461_GPDICR HD64461_IO_OFFSET(0x4026) /* D */
217 219
218/* Interrupt Status Registers */ 220/* Interrupt Status Registers */
219#define HD64461_GPAISR (CONFIG_HD64461_IOBASE + 0x4040) /* A */ 221#define HD64461_GPAISR HD64461_IO_OFFSET(0x4040) /* A */
220#define HD64461_GPBISR (CONFIG_HD64461_IOBASE + 0x4042) /* B */ 222#define HD64461_GPBISR HD64461_IO_OFFSET(0x4042) /* B */
221#define HD64461_GPCISR (CONFIG_HD64461_IOBASE + 0x4044) /* C */ 223#define HD64461_GPCISR HD64461_IO_OFFSET(0x4044) /* C */
222#define HD64461_GPDISR (CONFIG_HD64461_IOBASE + 0x4046) /* D */ 224#define HD64461_GPDISR HD64461_IO_OFFSET(0x4046) /* D */
223 225
224/* Interrupt Request Register & Interrupt Mask Register */ 226/* Interrupt Request Register & Interrupt Mask Register */
225#define HD64461_NIRR (CONFIG_HD64461_IOBASE + 0x5000) 227#define HD64461_NIRR HD64461_IO_OFFSET(0x5000)
226#define HD64461_NIMR (CONFIG_HD64461_IOBASE + 0x5002) 228#define HD64461_NIMR HD64461_IO_OFFSET(0x5002)
227 229
228#define HD64461_IRQBASE OFFCHIP_IRQ_BASE 230#define HD64461_IRQBASE OFFCHIP_IRQ_BASE
229#define OFFCHIP_IRQ_BASE 64 231#define OFFCHIP_IRQ_BASE 64
diff --git a/arch/sh/include/asm/io.h b/arch/sh/include/asm/io.h
index 0454f8d68059..25348141674b 100644
--- a/arch/sh/include/asm/io.h
+++ b/arch/sh/include/asm/io.h
@@ -123,10 +123,15 @@ static inline void __raw_reads##bwlq(volatile void __iomem *mem, \
123 123
124__BUILD_MEMORY_STRING(b, u8) 124__BUILD_MEMORY_STRING(b, u8)
125__BUILD_MEMORY_STRING(w, u16) 125__BUILD_MEMORY_STRING(w, u16)
126__BUILD_MEMORY_STRING(q, u64)
127 126
127#ifdef CONFIG_SUPERH32
128void __raw_writesl(void __iomem *addr, const void *data, int longlen); 128void __raw_writesl(void __iomem *addr, const void *data, int longlen);
129void __raw_readsl(const void __iomem *addr, void *data, int longlen); 129void __raw_readsl(const void __iomem *addr, void *data, int longlen);
130#else
131__BUILD_MEMORY_STRING(l, u32)
132#endif
133
134__BUILD_MEMORY_STRING(q, u64)
130 135
131#define writesb __raw_writesb 136#define writesb __raw_writesb
132#define writesw __raw_writesw 137#define writesw __raw_writesw
@@ -224,17 +229,6 @@ void __iomem *__ioremap(unsigned long offset, unsigned long size,
224 unsigned long flags); 229 unsigned long flags);
225void __iounmap(void __iomem *addr); 230void __iounmap(void __iomem *addr);
226 231
227/* arch/sh/mm/ioremap_64.c */
228unsigned long onchip_remap(unsigned long addr, unsigned long size,
229 const char *name);
230extern void onchip_unmap(unsigned long vaddr);
231#else
232#define __ioremap(offset, size, flags) ((void __iomem *)(offset))
233#define __iounmap(addr) do { } while (0)
234#define onchip_remap(addr, size, name) (addr)
235#define onchip_unmap(addr) do { } while (0)
236#endif /* CONFIG_MMU */
237
238static inline void __iomem * 232static inline void __iomem *
239__ioremap_mode(unsigned long offset, unsigned long size, unsigned long flags) 233__ioremap_mode(unsigned long offset, unsigned long size, unsigned long flags)
240{ 234{
@@ -268,6 +262,10 @@ __ioremap_mode(unsigned long offset, unsigned long size, unsigned long flags)
268 262
269 return __ioremap(offset, size, flags); 263 return __ioremap(offset, size, flags);
270} 264}
265#else
266#define __ioremap_mode(offset, size, flags) ((void __iomem *)(offset))
267#define __iounmap(addr) do { } while (0)
268#endif /* CONFIG_MMU */
271 269
272#define ioremap(offset, size) \ 270#define ioremap(offset, size) \
273 __ioremap_mode((offset), (size), 0) 271 __ioremap_mode((offset), (size), 0)
diff --git a/arch/sh/include/asm/irq.h b/arch/sh/include/asm/irq.h
index d319baaf4fbd..a2b8c99cc06f 100644
--- a/arch/sh/include/asm/irq.h
+++ b/arch/sh/include/asm/irq.h
@@ -8,7 +8,8 @@
8 * advised to cap this at the hard limit that they're interested in 8 * advised to cap this at the hard limit that they're interested in
9 * through the machvec. 9 * through the machvec.
10 */ 10 */
11#define NR_IRQS 256 11#define NR_IRQS 256
12#define NR_IRQS_LEGACY 8 /* Legacy external IRQ0-7 */
12 13
13/* 14/*
14 * Convert back and forth between INTEVT and IRQ values. 15 * Convert back and forth between INTEVT and IRQ values.
diff --git a/arch/sh/include/asm/kprobes.h b/arch/sh/include/asm/kprobes.h
index 613644a758e8..036c3311233c 100644
--- a/arch/sh/include/asm/kprobes.h
+++ b/arch/sh/include/asm/kprobes.h
@@ -6,7 +6,7 @@
6#include <linux/types.h> 6#include <linux/types.h>
7#include <linux/ptrace.h> 7#include <linux/ptrace.h>
8 8
9typedef u16 kprobe_opcode_t; 9typedef insn_size_t kprobe_opcode_t;
10#define BREAKPOINT_INSTRUCTION 0xc33a 10#define BREAKPOINT_INSTRUCTION 0xc33a
11 11
12#define MAX_INSN_SIZE 16 12#define MAX_INSN_SIZE 16
diff --git a/arch/sh/include/asm/machvec.h b/arch/sh/include/asm/machvec.h
index 64b1c16a0f03..84dd37761f56 100644
--- a/arch/sh/include/asm/machvec.h
+++ b/arch/sh/include/asm/machvec.h
@@ -46,6 +46,9 @@ struct sh_machine_vector {
46 46
47 void __iomem *(*mv_ioport_map)(unsigned long port, unsigned int size); 47 void __iomem *(*mv_ioport_map)(unsigned long port, unsigned int size);
48 void (*mv_ioport_unmap)(void __iomem *); 48 void (*mv_ioport_unmap)(void __iomem *);
49
50 int (*mv_clk_init)(void);
51 int (*mv_mode_pins)(void);
49}; 52};
50 53
51extern struct sh_machine_vector sh_mv; 54extern struct sh_machine_vector sh_mv;
diff --git a/arch/sh/include/asm/pci.h b/arch/sh/include/asm/pci.h
index df1d383e18a5..ae0da6f48b6d 100644
--- a/arch/sh/include/asm/pci.h
+++ b/arch/sh/include/asm/pci.h
@@ -17,54 +17,29 @@
17 * external) PCI controllers. 17 * external) PCI controllers.
18 */ 18 */
19struct pci_channel { 19struct pci_channel {
20 struct pci_ops *pci_ops; 20 struct pci_channel *next;
21 struct resource *io_resource;
22 struct resource *mem_resource;
23 int first_devfn;
24 int last_devfn;
25};
26 21
27/* 22 struct pci_ops *pci_ops;
28 * Each board initializes this array and terminates it with a NULL entry. 23 struct resource *io_resource;
29 */ 24 struct resource *mem_resource;
30extern struct pci_channel board_pci_channels[];
31 25
32#define PCIBIOS_MIN_IO board_pci_channels->io_resource->start 26 unsigned long io_offset;
33#define PCIBIOS_MIN_MEM board_pci_channels->mem_resource->start 27 unsigned long mem_offset;
34 28
35/* 29 unsigned long reg_base;
36 * I/O routine helpers
37 */
38#if defined(CONFIG_CPU_SUBTYPE_SH7780) || defined(CONFIG_CPU_SUBTYPE_SH7785)
39#define PCI_IO_AREA 0xFE400000
40#define PCI_IO_SIZE 0x00400000
41#elif defined(CONFIG_CPU_SH5)
42extern unsigned long PCI_IO_AREA;
43#define PCI_IO_SIZE 0x00010000
44#else
45#define PCI_IO_AREA 0xFE240000
46#define PCI_IO_SIZE 0x00040000
47#endif
48 30
49#define PCI_MEM_SIZE 0x01000000 31 unsigned long io_map_base;
32};
50 33
51#define SH4_PCIIOBR_MASK 0xFFFC0000 34extern void register_pci_controller(struct pci_channel *hose);
52#define pci_ioaddr(addr) (PCI_IO_AREA + (addr & ~SH4_PCIIOBR_MASK))
53 35
54#if defined(CONFIG_PCI) 36extern unsigned long PCIBIOS_MIN_IO, PCIBIOS_MIN_MEM;
55#define is_pci_ioaddr(port) \
56 (((port) >= PCIBIOS_MIN_IO) && \
57 ((port) < (PCIBIOS_MIN_IO + PCI_IO_SIZE)))
58#define is_pci_memaddr(port) \
59 (((port) >= PCIBIOS_MIN_MEM) && \
60 ((port) < (PCIBIOS_MIN_MEM + PCI_MEM_SIZE)))
61#else
62#define is_pci_ioaddr(port) (0)
63#define is_pci_memaddr(port) (0)
64#endif
65 37
66struct pci_dev; 38struct pci_dev;
67 39
40#define HAVE_PCI_MMAP
41extern int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
42 enum pci_mmap_state mmap_state, int write_combine);
68extern void pcibios_set_master(struct pci_dev *dev); 43extern void pcibios_set_master(struct pci_dev *dev);
69 44
70static inline void pcibios_penalize_isa_irq(int irq, int active) 45static inline void pcibios_penalize_isa_irq(int irq, int active)
@@ -114,31 +89,76 @@ static inline void pcibios_penalize_isa_irq(int irq, int active)
114#endif 89#endif
115 90
116#ifdef CONFIG_PCI 91#ifdef CONFIG_PCI
92/*
93 * None of the SH PCI controllers support MWI, it is always treated as a
94 * direct memory write.
95 */
96#define PCI_DISABLE_MWI
97
117static inline void pci_dma_burst_advice(struct pci_dev *pdev, 98static inline void pci_dma_burst_advice(struct pci_dev *pdev,
118 enum pci_dma_burst_strategy *strat, 99 enum pci_dma_burst_strategy *strat,
119 unsigned long *strategy_parameter) 100 unsigned long *strategy_parameter)
120{ 101{
121 *strat = PCI_DMA_BURST_INFINITY; 102 unsigned long cacheline_size;
122 *strategy_parameter = ~0UL; 103 u8 byte;
104
105 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &byte);
106
107 if (byte == 0)
108 cacheline_size = L1_CACHE_BYTES;
109 else
110 cacheline_size = byte << 2;
111
112 *strat = PCI_DMA_BURST_MULTIPLE;
113 *strategy_parameter = cacheline_size;
123} 114}
124#endif 115#endif
125 116
117#ifdef CONFIG_SUPERH32
118/*
119 * If we're on an SH7751 or SH7780 PCI controller, PCI memory is mapped
120 * at the end of the address space in a special non-translatable area.
121 */
122#define PCI_MEM_FIXED_START 0xfd000000
123#define PCI_MEM_FIXED_END (PCI_MEM_FIXED_START + 0x01000000)
124
125#define is_pci_memory_fixed_range(s, e) \
126 ((s) >= PCI_MEM_FIXED_START && (e) < PCI_MEM_FIXED_END)
127#else
128#define is_pci_memory_fixed_range(s, e) (0)
129#endif
130
126/* Board-specific fixup routines. */ 131/* Board-specific fixup routines. */
127void pcibios_fixup(void);
128int pcibios_init_platform(void);
129int pcibios_map_platform_irq(struct pci_dev *dev, u8 slot, u8 pin); 132int pcibios_map_platform_irq(struct pci_dev *dev, u8 slot, u8 pin);
130 133
131#ifdef CONFIG_PCI_AUTO 134extern void pcibios_resource_to_bus(struct pci_dev *dev,
132int pciauto_assign_resources(int busno, struct pci_channel *hose); 135 struct pci_bus_region *region, struct resource *res);
133#endif
134 136
135#endif /* __KERNEL__ */ 137extern void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
138 struct pci_bus_region *region);
136 139
137/* generic pci stuff */ 140static inline struct resource *
138#include <asm-generic/pci.h> 141pcibios_select_root(struct pci_dev *pdev, struct resource *res)
142{
143 struct resource *root = NULL;
144
145 if (res->flags & IORESOURCE_IO)
146 root = &ioport_resource;
147 if (res->flags & IORESOURCE_MEM)
148 root = &iomem_resource;
149
150 return root;
151}
152
153/* Chances are this interrupt is wired PC-style ... */
154static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
155{
156 return channel ? 15 : 14;
157}
139 158
140/* generic DMA-mapping stuff */ 159/* generic DMA-mapping stuff */
141#include <asm-generic/pci-dma-compat.h> 160#include <asm-generic/pci-dma-compat.h>
142 161
162#endif /* __KERNEL__ */
143#endif /* __ASM_SH_PCI_H */ 163#endif /* __ASM_SH_PCI_H */
144 164
diff --git a/arch/sh/include/asm/pgtable.h b/arch/sh/include/asm/pgtable.h
index b517ae08b9c0..2a011b18090b 100644
--- a/arch/sh/include/asm/pgtable.h
+++ b/arch/sh/include/asm/pgtable.h
@@ -154,6 +154,10 @@ extern void kmap_coherent_init(void);
154#define kmap_coherent_init() do { } while (0) 154#define kmap_coherent_init() do { } while (0)
155#endif 155#endif
156 156
157/* arch/sh/mm/mmap.c */
158#define HAVE_ARCH_UNMAPPED_AREA
159#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
160
157#include <asm-generic/pgtable.h> 161#include <asm-generic/pgtable.h>
158 162
159#endif /* __ASM_SH_PGTABLE_H */ 163#endif /* __ASM_SH_PGTABLE_H */
diff --git a/arch/sh/include/asm/processor.h b/arch/sh/include/asm/processor.h
index 1fd58b421438..ff7daaf9a620 100644
--- a/arch/sh/include/asm/processor.h
+++ b/arch/sh/include/asm/processor.h
@@ -32,7 +32,7 @@ enum cpu_type {
32 32
33 /* SH-4A types */ 33 /* SH-4A types */
34 CPU_SH7763, CPU_SH7770, CPU_SH7780, CPU_SH7781, CPU_SH7785, CPU_SH7786, 34 CPU_SH7763, CPU_SH7770, CPU_SH7780, CPU_SH7781, CPU_SH7785, CPU_SH7786,
35 CPU_SH7723, CPU_SHX3, 35 CPU_SH7723, CPU_SH7724, CPU_SHX3,
36 36
37 /* SH4AL-DSP types */ 37 /* SH4AL-DSP types */
38 CPU_SH7343, CPU_SH7722, CPU_SH7366, 38 CPU_SH7343, CPU_SH7722, CPU_SH7366,
@@ -94,6 +94,27 @@ extern struct pt_regs fake_swapper_regs;
94const char *get_cpu_subtype(struct sh_cpuinfo *c); 94const char *get_cpu_subtype(struct sh_cpuinfo *c);
95extern const struct seq_operations cpuinfo_op; 95extern const struct seq_operations cpuinfo_op;
96 96
97/* processor boot mode configuration */
98#define MODE_PIN0 (1 << 0)
99#define MODE_PIN1 (1 << 1)
100#define MODE_PIN2 (1 << 2)
101#define MODE_PIN3 (1 << 3)
102#define MODE_PIN4 (1 << 4)
103#define MODE_PIN5 (1 << 5)
104#define MODE_PIN6 (1 << 6)
105#define MODE_PIN7 (1 << 7)
106#define MODE_PIN8 (1 << 8)
107#define MODE_PIN9 (1 << 9)
108#define MODE_PIN10 (1 << 10)
109#define MODE_PIN11 (1 << 11)
110#define MODE_PIN12 (1 << 12)
111#define MODE_PIN13 (1 << 13)
112#define MODE_PIN14 (1 << 14)
113#define MODE_PIN15 (1 << 15)
114
115int generic_mode_pins(void);
116int test_mode_pin(int pin);
117
97#ifdef CONFIG_VSYSCALL 118#ifdef CONFIG_VSYSCALL
98int vsyscall_init(void); 119int vsyscall_init(void);
99#else 120#else
diff --git a/arch/sh/include/asm/ptrace.h b/arch/sh/include/asm/ptrace.h
index 68e20ff9aa9b..1dc12cb44a2d 100644
--- a/arch/sh/include/asm/ptrace.h
+++ b/arch/sh/include/asm/ptrace.h
@@ -102,6 +102,11 @@ struct pt_dspregs {
102#define PTRACE_GETDSPREGS 55 /* DSP registers */ 102#define PTRACE_GETDSPREGS 55 /* DSP registers */
103#define PTRACE_SETDSPREGS 56 103#define PTRACE_SETDSPREGS 56
104 104
105#define PT_TEXT_END_ADDR 240
106#define PT_TEXT_ADDR 244 /* &(struct user)->start_code */
107#define PT_DATA_ADDR 248 /* &(struct user)->start_data */
108#define PT_TEXT_LEN 252
109
105#ifdef __KERNEL__ 110#ifdef __KERNEL__
106#include <asm/addrspace.h> 111#include <asm/addrspace.h>
107 112
diff --git a/arch/sh/include/asm/rtc.h b/arch/sh/include/asm/rtc.h
index f7b010d48af7..52b0c2dba979 100644
--- a/arch/sh/include/asm/rtc.h
+++ b/arch/sh/include/asm/rtc.h
@@ -6,6 +6,17 @@ extern void (*board_time_init)(void);
6extern void (*rtc_sh_get_time)(struct timespec *); 6extern void (*rtc_sh_get_time)(struct timespec *);
7extern int (*rtc_sh_set_time)(const time_t); 7extern int (*rtc_sh_set_time)(const time_t);
8 8
9/* some dummy definitions */
10#define RTC_BATT_BAD 0x100 /* battery bad */
11#define RTC_SQWE 0x08 /* enable square-wave output */
12#define RTC_DM_BINARY 0x04 /* all time/date values are BCD if clear */
13#define RTC_24H 0x02 /* 24 hour mode - else hours bit 7 means pm */
14#define RTC_DST_EN 0x01 /* auto switch DST - works f. USA only */
15
16struct rtc_time;
17unsigned int get_rtc_time(struct rtc_time *);
18int set_rtc_time(struct rtc_time *);
19
9#define RTC_CAP_4_DIGIT_YEAR (1 << 0) 20#define RTC_CAP_4_DIGIT_YEAR (1 << 0)
10 21
11struct sh_rtc_platform_info { 22struct sh_rtc_platform_info {
diff --git a/arch/sh/include/asm/spinlock.h b/arch/sh/include/asm/spinlock.h
index 60283565f89b..a28c9f0053fd 100644
--- a/arch/sh/include/asm/spinlock.h
+++ b/arch/sh/include/asm/spinlock.h
@@ -26,7 +26,7 @@
26#define __raw_spin_is_locked(x) ((x)->lock <= 0) 26#define __raw_spin_is_locked(x) ((x)->lock <= 0)
27#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock) 27#define __raw_spin_lock_flags(lock, flags) __raw_spin_lock(lock)
28#define __raw_spin_unlock_wait(x) \ 28#define __raw_spin_unlock_wait(x) \
29 do { cpu_relax(); } while ((x)->lock) 29 do { while (__raw_spin_is_locked(x)) cpu_relax(); } while (0)
30 30
31/* 31/*
32 * Simple spin lock operations. There are two variants, one clears IRQ's 32 * Simple spin lock operations. There are two variants, one clears IRQ's
diff --git a/arch/sh/include/asm/swab.h b/arch/sh/include/asm/swab.h
index e69315935107..0e08fe54ad71 100644
--- a/arch/sh/include/asm/swab.h
+++ b/arch/sh/include/asm/swab.h
@@ -14,15 +14,15 @@ static inline __attribute_const__ __u32 __arch_swab32(__u32 x)
14{ 14{
15 __asm__( 15 __asm__(
16#ifdef __SH5__ 16#ifdef __SH5__
17 "byterev %0, %0\n\t" 17 "byterev %1, %0\n\t"
18 "shari %0, 32, %0" 18 "shari %0, 32, %0"
19#else 19#else
20 "swap.b %0, %0\n\t" 20 "swap.b %1, %0\n\t"
21 "swap.w %0, %0\n\t" 21 "swap.w %0, %0\n\t"
22 "swap.b %0, %0" 22 "swap.b %0, %0"
23#endif 23#endif
24 : "=r" (x) 24 : "=r" (x)
25 : "0" (x)); 25 : "r" (x));
26 26
27 return x; 27 return x;
28} 28}
@@ -32,13 +32,13 @@ static inline __attribute_const__ __u16 __arch_swab16(__u16 x)
32{ 32{
33 __asm__( 33 __asm__(
34#ifdef __SH5__ 34#ifdef __SH5__
35 "byterev %0, %0\n\t" 35 "byterev %1, %0\n\t"
36 "shari %0, 32, %0" 36 "shari %0, 32, %0"
37#else 37#else
38 "swap.b %0, %0" 38 "swap.b %1, %0"
39#endif 39#endif
40 : "=r" (x) 40 : "=r" (x)
41 : "0" (x)); 41 : "r" (x));
42 42
43 return x; 43 return x;
44} 44}
diff --git a/arch/sh/include/asm/system_32.h b/arch/sh/include/asm/system_32.h
index 240b31e1142c..6c68a51f1cc5 100644
--- a/arch/sh/include/asm/system_32.h
+++ b/arch/sh/include/asm/system_32.h
@@ -198,7 +198,7 @@ do { \
198}) 198})
199#endif 199#endif
200 200
201int handle_unaligned_access(opcode_t instruction, struct pt_regs *regs, 201int handle_unaligned_access(insn_size_t instruction, struct pt_regs *regs,
202 struct mem_access *ma); 202 struct mem_access *ma);
203 203
204asmlinkage void do_address_error(struct pt_regs *regs, 204asmlinkage void do_address_error(struct pt_regs *regs,
diff --git a/arch/sh/include/asm/timer.h b/arch/sh/include/asm/timer.h
deleted file mode 100644
index 4c3b66e30af2..000000000000
--- a/arch/sh/include/asm/timer.h
+++ /dev/null
@@ -1,44 +0,0 @@
1#ifndef __ASM_SH_TIMER_H
2#define __ASM_SH_TIMER_H
3
4#include <linux/sysdev.h>
5#include <linux/clocksource.h>
6#include <cpu/timer.h>
7
8struct sys_timer_ops {
9 int (*init)(void);
10 int (*start)(void);
11 int (*stop)(void);
12#ifndef CONFIG_GENERIC_TIME
13 unsigned long (*get_offset)(void);
14#endif
15};
16
17struct sys_timer {
18 const char *name;
19
20 struct sys_device dev;
21 struct sys_timer_ops *ops;
22};
23
24#define TICK_SIZE (tick_nsec / 1000)
25
26extern struct sys_timer tmu_timer, cmt_timer, mtu2_timer;
27extern struct sys_timer *sys_timer;
28
29#ifndef CONFIG_GENERIC_TIME
30static inline unsigned long get_timer_offset(void)
31{
32 return sys_timer->ops->get_offset();
33}
34#endif
35
36/* arch/sh/kernel/timers/timer.c */
37struct sys_timer *get_sys_timer(void);
38
39/* arch/sh/kernel/time.c */
40void handle_timer_tick(void);
41
42extern struct clocksource clocksource_sh;
43
44#endif /* __ASM_SH_TIMER_H */
diff --git a/arch/sh/include/asm/types.h b/arch/sh/include/asm/types.h
index beea4e6f8dfd..b13caca62a76 100644
--- a/arch/sh/include/asm/types.h
+++ b/arch/sh/include/asm/types.h
@@ -23,9 +23,9 @@ typedef unsigned short umode_t;
23typedef u32 dma_addr_t; 23typedef u32 dma_addr_t;
24 24
25#ifdef CONFIG_SUPERH32 25#ifdef CONFIG_SUPERH32
26typedef u16 opcode_t; 26typedef u16 insn_size_t;
27#else 27#else
28typedef u32 opcode_t; 28typedef u32 insn_size_t;
29#endif 29#endif
30 30
31#endif /* __ASSEMBLY__ */ 31#endif /* __ASSEMBLY__ */
diff --git a/arch/sh/include/asm/ubc.h b/arch/sh/include/asm/ubc.h
index a7b9028bbfbb..4ca4b7717371 100644
--- a/arch/sh/include/asm/ubc.h
+++ b/arch/sh/include/asm/ubc.h
@@ -42,12 +42,23 @@
42 42
43#define BRCR_CMFA (1 << 15) 43#define BRCR_CMFA (1 << 15)
44#define BRCR_CMFB (1 << 14) 44#define BRCR_CMFB (1 << 14)
45
46#if defined CONFIG_CPU_SH2A
47#define BRCR_CMFCA (1 << 15)
48#define BRCR_CMFCB (1 << 14)
49#define BRCR_CMFDA (1 << 13)
50#define BRCR_CMFDB (1 << 12)
51#define BRCR_PCBB (1 << 6) /* 1: after execution */
52#define BRCR_PCBA (1 << 5) /* 1: after execution */
53#define BRCR_PCTE 0
54#else
45#define BRCR_PCTE (1 << 11) 55#define BRCR_PCTE (1 << 11)
46#define BRCR_PCBA (1 << 10) /* 1: after execution */ 56#define BRCR_PCBA (1 << 10) /* 1: after execution */
47#define BRCR_DBEB (1 << 7) 57#define BRCR_DBEB (1 << 7)
48#define BRCR_PCBB (1 << 6) 58#define BRCR_PCBB (1 << 6)
49#define BRCR_SEQ (1 << 3) 59#define BRCR_SEQ (1 << 3)
50#define BRCR_UBDE (1 << 0) 60#define BRCR_UBDE (1 << 0)
61#endif
51 62
52#ifndef __ASSEMBLY__ 63#ifndef __ASSEMBLY__
53/* arch/sh/kernel/cpu/ubc.S */ 64/* arch/sh/kernel/cpu/ubc.S */
diff --git a/arch/sh/include/asm/unaligned-sh4a.h b/arch/sh/include/asm/unaligned-sh4a.h
index d8f89770275b..9f4dd252c981 100644
--- a/arch/sh/include/asm/unaligned-sh4a.h
+++ b/arch/sh/include/asm/unaligned-sh4a.h
@@ -3,9 +3,9 @@
3 3
4/* 4/*
5 * SH-4A has support for unaligned 32-bit loads, and 32-bit loads only. 5 * SH-4A has support for unaligned 32-bit loads, and 32-bit loads only.
6 * Support for 16 and 64-bit accesses are done through shifting and 6 * Support for 64-bit accesses are done through shifting and masking
7 * masking relative to the endianness. Unaligned stores are not supported 7 * relative to the endianness. Unaligned stores are not supported by the
8 * by the instruction encoding, so these continue to use the packed 8 * instruction encoding, so these continue to use the packed
9 * struct. 9 * struct.
10 * 10 *
11 * The same note as with the movli.l/movco.l pair applies here, as long 11 * The same note as with the movli.l/movco.l pair applies here, as long
@@ -41,9 +41,9 @@ struct __una_u64 { u64 x __attribute__((packed)); };
41static inline u16 __get_unaligned_cpu16(const u8 *p) 41static inline u16 __get_unaligned_cpu16(const u8 *p)
42{ 42{
43#ifdef __LITTLE_ENDIAN 43#ifdef __LITTLE_ENDIAN
44 return __get_unaligned_cpu32(p) & 0xffff; 44 return p[0] | p[1] << 8;
45#else 45#else
46 return __get_unaligned_cpu32(p) >> 16; 46 return p[0] << 8 | p[1];
47#endif 47#endif
48} 48}
49 49
diff --git a/arch/sh/include/asm/unistd_32.h b/arch/sh/include/asm/unistd_32.h
index 2efb819e2db3..65197086a1c5 100644
--- a/arch/sh/include/asm/unistd_32.h
+++ b/arch/sh/include/asm/unistd_32.h
@@ -343,8 +343,9 @@
343#define __NR_inotify_init1 332 343#define __NR_inotify_init1 332
344#define __NR_preadv 333 344#define __NR_preadv 333
345#define __NR_pwritev 334 345#define __NR_pwritev 334
346#define __NR_rt_tgsigqueueinfo 335
346 347
347#define NR_syscalls 335 348#define NR_syscalls 336
348 349
349#ifdef __KERNEL__ 350#ifdef __KERNEL__
350 351
diff --git a/arch/sh/include/asm/unistd_64.h b/arch/sh/include/asm/unistd_64.h
index 6eb9d2934c0f..8014aea88ec3 100644
--- a/arch/sh/include/asm/unistd_64.h
+++ b/arch/sh/include/asm/unistd_64.h
@@ -383,10 +383,11 @@
383#define __NR_inotify_init1 360 383#define __NR_inotify_init1 360
384#define __NR_preadv 361 384#define __NR_preadv 361
385#define __NR_pwritev 362 385#define __NR_pwritev 362
386#define __NR_rt_tgsigqueueinfo 363
386 387
387#ifdef __KERNEL__ 388#ifdef __KERNEL__
388 389
389#define NR_syscalls 363 390#define NR_syscalls 364
390 391
391#define __ARCH_WANT_IPC_PARSE_VERSION 392#define __ARCH_WANT_IPC_PARSE_VERSION
392#define __ARCH_WANT_OLD_READDIR 393#define __ARCH_WANT_OLD_READDIR
diff --git a/arch/sh/include/cpu-sh2a/cpu/ubc.h b/arch/sh/include/cpu-sh2a/cpu/ubc.h
index 8ce2fc1cf625..1192e1c761a7 100644
--- a/arch/sh/include/cpu-sh2a/cpu/ubc.h
+++ b/arch/sh/include/cpu-sh2a/cpu/ubc.h
@@ -1 +1,28 @@
1#include <cpu-sh2/cpu/ubc.h> 1/*
2 * SH-2A UBC definitions
3 *
4 * Copyright (C) 2008 Kieran Bingham
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#ifndef __ASM_CPU_SH2A_UBC_H
12#define __ASM_CPU_SH2A_UBC_H
13
14#define UBC_BARA 0xfffc0400
15#define UBC_BAMRA 0xfffc0404
16#define UBC_BBRA 0xfffc04a0 /* 16 bit access */
17#define UBC_BDRA 0xfffc0408
18#define UBC_BDMRA 0xfffc040c
19
20#define UBC_BARB 0xfffc0410
21#define UBC_BAMRB 0xfffc0414
22#define UBC_BBRB 0xfffc04b0 /* 16 bit access */
23#define UBC_BDRB 0xfffc0418
24#define UBC_BDMRB 0xfffc041c
25
26#define UBC_BRCR 0xfffc04c0
27
28#endif /* __ASM_CPU_SH2A_UBC_H */
diff --git a/arch/sh/include/cpu-sh3/cpu/timer.h b/arch/sh/include/cpu-sh3/cpu/timer.h
deleted file mode 100644
index 793acf12aa08..000000000000
--- a/arch/sh/include/cpu-sh3/cpu/timer.h
+++ /dev/null
@@ -1,67 +0,0 @@
1/*
2 * include/asm-sh/cpu-sh3/timer.h
3 *
4 * Copyright (C) 2004 Lineo Solutions, Inc.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10#ifndef __ASM_CPU_SH3_TIMER_H
11#define __ASM_CPU_SH3_TIMER_H
12
13/*
14 * ---------------------------------------------------------------------------
15 * TMU Common definitions for SH3 processors
16 * SH7706
17 * SH7709S
18 * SH7727
19 * SH7729R
20 * SH7710
21 * SH7720
22 * SH7710
23 * ---------------------------------------------------------------------------
24 */
25
26#if !defined(CONFIG_CPU_SUBTYPE_SH7720) && !defined(CONFIG_CPU_SUBTYPE_SH7721)
27#define TMU_TOCR 0xfffffe90 /* Byte access */
28#endif
29
30#if defined(CONFIG_CPU_SUBTYPE_SH7710) || \
31 defined(CONFIG_CPU_SUBTYPE_SH7720) || \
32 defined(CONFIG_CPU_SUBTYPE_SH7721)
33#define TMU_012_TSTR 0xa412fe92 /* Byte access */
34
35#define TMU0_TCOR 0xa412fe94 /* Long access */
36#define TMU0_TCNT 0xa412fe98 /* Long access */
37#define TMU0_TCR 0xa412fe9c /* Word access */
38
39#define TMU1_TCOR 0xa412fea0 /* Long access */
40#define TMU1_TCNT 0xa412fea4 /* Long access */
41#define TMU1_TCR 0xa412fea8 /* Word access */
42
43#define TMU2_TCOR 0xa412feac /* Long access */
44#define TMU2_TCNT 0xa412feb0 /* Long access */
45#define TMU2_TCR 0xa412feb4 /* Word access */
46
47#else
48#define TMU_012_TSTR 0xfffffe92 /* Byte access */
49
50#define TMU0_TCOR 0xfffffe94 /* Long access */
51#define TMU0_TCNT 0xfffffe98 /* Long access */
52#define TMU0_TCR 0xfffffe9c /* Word access */
53
54#define TMU1_TCOR 0xfffffea0 /* Long access */
55#define TMU1_TCNT 0xfffffea4 /* Long access */
56#define TMU1_TCR 0xfffffea8 /* Word access */
57
58#define TMU2_TCOR 0xfffffeac /* Long access */
59#define TMU2_TCNT 0xfffffeb0 /* Long access */
60#define TMU2_TCR 0xfffffeb4 /* Word access */
61#if !defined(CONFIG_CPU_SUBTYPE_SH7720) && !defined(CONFIG_CPU_SUBTYPE_SH7721)
62#define TMU2_TCPR2 0xfffffeb8 /* Long access */
63#endif
64#endif
65
66#endif /* __ASM_CPU_SH3_TIMER_H */
67
diff --git a/arch/sh/include/cpu-sh4/cpu/cache.h b/arch/sh/include/cpu-sh4/cpu/cache.h
index 1c61ebf5c8e3..7bfb9e8b069c 100644
--- a/arch/sh/include/cpu-sh4/cpu/cache.h
+++ b/arch/sh/include/cpu-sh4/cpu/cache.h
@@ -38,5 +38,7 @@
38#define CACHE_IC_ADDRESS_ARRAY 0xf0000000 38#define CACHE_IC_ADDRESS_ARRAY 0xf0000000
39#define CACHE_OC_ADDRESS_ARRAY 0xf4000000 39#define CACHE_OC_ADDRESS_ARRAY 0xf4000000
40 40
41#define RAMCR 0xFF000074
42
41#endif /* __ASM_CPU_SH4_CACHE_H */ 43#endif /* __ASM_CPU_SH4_CACHE_H */
42 44
diff --git a/arch/sh/include/cpu-sh4/cpu/freq.h b/arch/sh/include/cpu-sh4/cpu/freq.h
index 749d1c434337..ccf1d999db6d 100644
--- a/arch/sh/include/cpu-sh4/cpu/freq.h
+++ b/arch/sh/include/cpu-sh4/cpu/freq.h
@@ -25,6 +25,24 @@
25#elif defined(CONFIG_CPU_SUBTYPE_SH7763) || \ 25#elif defined(CONFIG_CPU_SUBTYPE_SH7763) || \
26 defined(CONFIG_CPU_SUBTYPE_SH7780) 26 defined(CONFIG_CPU_SUBTYPE_SH7780)
27#define FRQCR 0xffc80000 27#define FRQCR 0xffc80000
28#elif defined(CONFIG_CPU_SUBTYPE_SH7724)
29#define FRQCRA 0xa4150000
30#define FRQCRB 0xa4150004
31#define VCLKCR 0xa4150048
32
33#define FCLKACR 0xa4150008
34#define FCLKBCR 0xa415000c
35#define FRQCR FRQCRA
36#define SCLKACR FCLKACR
37#define SCLKBCR FCLKBCR
38#define FCLKACR 0xa4150008
39#define FCLKBCR 0xa415000c
40#define IrDACLKCR 0xa4150018
41
42#define MSTPCR0 0xa4150030
43#define MSTPCR1 0xa4150034
44#define MSTPCR2 0xa4150038
45
28#elif defined(CONFIG_CPU_SUBTYPE_SH7785) 46#elif defined(CONFIG_CPU_SUBTYPE_SH7785)
29#define FRQCR0 0xffc80000 47#define FRQCR0 0xffc80000
30#define FRQCR1 0xffc80004 48#define FRQCR1 0xffc80004
diff --git a/arch/sh/include/cpu-sh4/cpu/sh7722.h b/arch/sh/include/cpu-sh4/cpu/sh7722.h
index 4b3096f5307b..738ea43c5038 100644
--- a/arch/sh/include/cpu-sh4/cpu/sh7722.h
+++ b/arch/sh/include/cpu-sh4/cpu/sh7722.h
@@ -1,6 +1,20 @@
1#ifndef __ASM_SH7722_H__ 1#ifndef __ASM_SH7722_H__
2#define __ASM_SH7722_H__ 2#define __ASM_SH7722_H__
3 3
4/* Boot Mode Pins:
5 *
6 * MD0: CPG - Clock Mode 0->3
7 * MD1: CPG - Clock Mode 0->3
8 * MD2: CPG - Reserved (L: Normal operation)
9 * MD3: BSC - Area0 Bus Width (16/32-bit) [CS0BCR.9,10]
10 * MD5: BSC - Endian Mode (L: Big, H: Little) [CMNCR.3]
11 * MD8: Test Mode
12 */
13
14/* Pin Function Controller:
15 * GPIO_FN_xx - GPIO used to select pin function
16 * GPIO_Pxx - GPIO mapped to real I/O pin on CPU
17 */
4enum { 18enum {
5 /* PTA */ 19 /* PTA */
6 GPIO_PTA7, GPIO_PTA6, GPIO_PTA5, GPIO_PTA4, 20 GPIO_PTA7, GPIO_PTA6, GPIO_PTA5, GPIO_PTA4,
diff --git a/arch/sh/include/cpu-sh4/cpu/sh7723.h b/arch/sh/include/cpu-sh4/cpu/sh7723.h
index 9d2f6d7aa938..14c8ca936781 100644
--- a/arch/sh/include/cpu-sh4/cpu/sh7723.h
+++ b/arch/sh/include/cpu-sh4/cpu/sh7723.h
@@ -1,6 +1,20 @@
1#ifndef __ASM_SH7723_H__ 1#ifndef __ASM_SH7723_H__
2#define __ASM_SH7723_H__ 2#define __ASM_SH7723_H__
3 3
4/* Boot Mode Pins:
5 *
6 * MD0: CPG - Clock Mode 0->3
7 * MD1: CPG - Clock Mode 0->3
8 * MD2: CPG - Reserved (L: Normal operation)
9 * MD3: BSC - Area0 Bus Width (16/32-bit) [CS0BCR.9,10]
10 * MD5: BSC - Endian Mode (L: Big, H: Little) [CMNCR.3]
11 * MD8: Test Mode
12 */
13
14/* Pin Function Controller:
15 * GPIO_FN_xx - GPIO used to select pin function
16 * GPIO_Pxx - GPIO mapped to real I/O pin on CPU
17 */
4enum { 18enum {
5 /* PTA */ 19 /* PTA */
6 GPIO_PTA7, GPIO_PTA6, GPIO_PTA5, GPIO_PTA4, 20 GPIO_PTA7, GPIO_PTA6, GPIO_PTA5, GPIO_PTA4,
diff --git a/arch/sh/include/cpu-sh4/cpu/sh7724.h b/arch/sh/include/cpu-sh4/cpu/sh7724.h
new file mode 100644
index 000000000000..66fd1184359e
--- /dev/null
+++ b/arch/sh/include/cpu-sh4/cpu/sh7724.h
@@ -0,0 +1,269 @@
1#ifndef __ASM_SH7724_H__
2#define __ASM_SH7724_H__
3
4/* Boot Mode Pins:
5 *
6 * MD0: CPG - Clock Mode 0->7
7 * MD1: CPG - Clock Mode 0->7
8 * MD2: CPG - Clock Mode 0->7
9 * MD3: BSC - Area0 Bus Width (16/32-bit) [CS0BCR.9,10]
10 * MD5: BSC - Endian Mode (L: Big, H: Little) [CMNCR.3]
11 * MD8: Test Mode
12 */
13
14/* Pin Function Controller:
15 * GPIO_FN_xx - GPIO used to select pin function
16 * GPIO_Pxx - GPIO mapped to real I/O pin on CPU
17 */
18enum {
19 /* PTA */
20 GPIO_PTA7, GPIO_PTA6, GPIO_PTA5, GPIO_PTA4,
21 GPIO_PTA3, GPIO_PTA2, GPIO_PTA1, GPIO_PTA0,
22
23 /* PTB */
24 GPIO_PTB7, GPIO_PTB6, GPIO_PTB5, GPIO_PTB4,
25 GPIO_PTB3, GPIO_PTB2, GPIO_PTB1, GPIO_PTB0,
26
27 /* PTC */
28 GPIO_PTC7, GPIO_PTC6, GPIO_PTC5, GPIO_PTC4,
29 GPIO_PTC3, GPIO_PTC2, GPIO_PTC1, GPIO_PTC0,
30
31 /* PTD */
32 GPIO_PTD7, GPIO_PTD6, GPIO_PTD5, GPIO_PTD4,
33 GPIO_PTD3, GPIO_PTD2, GPIO_PTD1, GPIO_PTD0,
34
35 /* PTE */
36 GPIO_PTE7, GPIO_PTE6, GPIO_PTE5, GPIO_PTE4,
37 GPIO_PTE3, GPIO_PTE2, GPIO_PTE1, GPIO_PTE0,
38
39 /* PTF */
40 GPIO_PTF7, GPIO_PTF6, GPIO_PTF5, GPIO_PTF4,
41 GPIO_PTF3, GPIO_PTF2, GPIO_PTF1, GPIO_PTF0,
42
43 /* PTG */
44 GPIO_PTG5, GPIO_PTG4,
45 GPIO_PTG3, GPIO_PTG2, GPIO_PTG1, GPIO_PTG0,
46
47 /* PTH */
48 GPIO_PTH7, GPIO_PTH6, GPIO_PTH5, GPIO_PTH4,
49 GPIO_PTH3, GPIO_PTH2, GPIO_PTH1, GPIO_PTH0,
50
51 /* PTJ */
52 GPIO_PTJ7, GPIO_PTJ6, GPIO_PTJ5,
53 GPIO_PTJ3, GPIO_PTJ2, GPIO_PTJ1, GPIO_PTJ0,
54
55 /* PTK */
56 GPIO_PTK7, GPIO_PTK6, GPIO_PTK5, GPIO_PTK4,
57 GPIO_PTK3, GPIO_PTK2, GPIO_PTK1, GPIO_PTK0,
58
59 /* PTL */
60 GPIO_PTL7, GPIO_PTL6, GPIO_PTL5, GPIO_PTL4,
61 GPIO_PTL3, GPIO_PTL2, GPIO_PTL1, GPIO_PTL0,
62
63 /* PTM */
64 GPIO_PTM7, GPIO_PTM6, GPIO_PTM5, GPIO_PTM4,
65 GPIO_PTM3, GPIO_PTM2, GPIO_PTM1, GPIO_PTM0,
66
67 /* PTN */
68 GPIO_PTN7, GPIO_PTN6, GPIO_PTN5, GPIO_PTN4,
69 GPIO_PTN3, GPIO_PTN2, GPIO_PTN1, GPIO_PTN0,
70
71 /* PTQ */
72 GPIO_PTQ7, GPIO_PTQ6, GPIO_PTQ5, GPIO_PTQ4,
73 GPIO_PTQ3, GPIO_PTQ2, GPIO_PTQ1, GPIO_PTQ0,
74
75 /* PTR */
76 GPIO_PTR7, GPIO_PTR6, GPIO_PTR5, GPIO_PTR4,
77 GPIO_PTR3, GPIO_PTR2, GPIO_PTR1, GPIO_PTR0,
78
79 /* PTS */
80 GPIO_PTS6, GPIO_PTS5, GPIO_PTS4,
81 GPIO_PTS3, GPIO_PTS2, GPIO_PTS1, GPIO_PTS0,
82
83 /* PTT */
84 GPIO_PTT7, GPIO_PTT6, GPIO_PTT5, GPIO_PTT4,
85 GPIO_PTT3, GPIO_PTT2, GPIO_PTT1, GPIO_PTT0,
86
87 /* PTU */
88 GPIO_PTU7, GPIO_PTU6, GPIO_PTU5, GPIO_PTU4,
89 GPIO_PTU3, GPIO_PTU2, GPIO_PTU1, GPIO_PTU0,
90
91 /* PTV */
92 GPIO_PTV7, GPIO_PTV6, GPIO_PTV5, GPIO_PTV4,
93 GPIO_PTV3, GPIO_PTV2, GPIO_PTV1, GPIO_PTV0,
94
95 /* PTW */
96 GPIO_PTW7, GPIO_PTW6, GPIO_PTW5, GPIO_PTW4,
97 GPIO_PTW3, GPIO_PTW2, GPIO_PTW1, GPIO_PTW0,
98
99 /* PTX */
100 GPIO_PTX7, GPIO_PTX6, GPIO_PTX5, GPIO_PTX4,
101 GPIO_PTX3, GPIO_PTX2, GPIO_PTX1, GPIO_PTX0,
102
103 /* PTY */
104 GPIO_PTY7, GPIO_PTY6, GPIO_PTY5, GPIO_PTY4,
105 GPIO_PTY3, GPIO_PTY2, GPIO_PTY1, GPIO_PTY0,
106
107 /* PTZ */
108 GPIO_PTZ7, GPIO_PTZ6, GPIO_PTZ5, GPIO_PTZ4,
109 GPIO_PTZ3, GPIO_PTZ2, GPIO_PTZ1, GPIO_PTZ0,
110
111 /* BSC (PTA/PTB/PTJ/PTQ/PTR/PTT) */
112 GPIO_FN_D31, GPIO_FN_D30, GPIO_FN_D29, GPIO_FN_D28,
113 GPIO_FN_D27, GPIO_FN_D26, GPIO_FN_D25, GPIO_FN_D24,
114 GPIO_FN_D23, GPIO_FN_D22, GPIO_FN_D21, GPIO_FN_D20,
115 GPIO_FN_D19, GPIO_FN_D18, GPIO_FN_D17, GPIO_FN_D16,
116 GPIO_FN_D15, GPIO_FN_D14, GPIO_FN_D13, GPIO_FN_D12,
117 GPIO_FN_D11, GPIO_FN_D10, GPIO_FN_D9, GPIO_FN_D8,
118 GPIO_FN_D7, GPIO_FN_D6, GPIO_FN_D5, GPIO_FN_D4,
119 GPIO_FN_D3, GPIO_FN_D2, GPIO_FN_D1, GPIO_FN_D0,
120 GPIO_FN_A25, GPIO_FN_A24, GPIO_FN_A23, GPIO_FN_A22,
121 GPIO_FN_CS6B_CE1B, GPIO_FN_CS6A_CE2B,
122 GPIO_FN_CS5B_CE1A, GPIO_FN_CS5A_CE2A,
123 GPIO_FN_WE3_ICIOWR, GPIO_FN_WE2_ICIORD,
124 GPIO_FN_IOIS16, GPIO_FN_WAIT,
125 GPIO_FN_BS,
126
127 /* KEYSC (PTA/PTB)*/
128 GPIO_FN_KEYOUT5_IN5, GPIO_FN_KEYOUT4_IN6, GPIO_FN_KEYIN4,
129 GPIO_FN_KEYIN3, GPIO_FN_KEYIN2, GPIO_FN_KEYIN1, GPIO_FN_KEYIN0,
130 GPIO_FN_KEYOUT3, GPIO_FN_KEYOUT2, GPIO_FN_KEYOUT1, GPIO_FN_KEYOUT0,
131
132 /* ATAPI (PTA/PTB/PTK/PTR/PTS/PTW) */
133 GPIO_FN_IDED15, GPIO_FN_IDED14, GPIO_FN_IDED13, GPIO_FN_IDED12,
134 GPIO_FN_IDED11, GPIO_FN_IDED10, GPIO_FN_IDED9, GPIO_FN_IDED8,
135 GPIO_FN_IDED7, GPIO_FN_IDED6, GPIO_FN_IDED5, GPIO_FN_IDED4,
136 GPIO_FN_IDED3, GPIO_FN_IDED2, GPIO_FN_IDED1, GPIO_FN_IDED0,
137 GPIO_FN_IDEA2, GPIO_FN_IDEA1, GPIO_FN_IDEA0, GPIO_FN_IDEIOWR,
138 GPIO_FN_IODREQ, GPIO_FN_IDECS0, GPIO_FN_IDECS1, GPIO_FN_IDEIORD,
139 GPIO_FN_DIRECTION, GPIO_FN_EXBUF_ENB, GPIO_FN_IDERST, GPIO_FN_IODACK,
140 GPIO_FN_IDEINT, GPIO_FN_IDEIORDY,
141
142 /* TPU (PTB/PTR/PTS) */
143 GPIO_FN_TPUTO3, GPIO_FN_TPUTO2, GPIO_FN_TPUTO1, GPIO_FN_TPUTO0,
144 GPIO_FN_TPUTI3, GPIO_FN_TPUTI2,
145
146 /* LCDC (PTC/PTD/PTE/PTF/PTM/PTR) */
147 GPIO_FN_LCDD23, GPIO_FN_LCDD22, GPIO_FN_LCDD21, GPIO_FN_LCDD20,
148 GPIO_FN_LCDD19, GPIO_FN_LCDD18, GPIO_FN_LCDD17, GPIO_FN_LCDD16,
149 GPIO_FN_LCDD15, GPIO_FN_LCDD14, GPIO_FN_LCDD13, GPIO_FN_LCDD12,
150 GPIO_FN_LCDD11, GPIO_FN_LCDD10, GPIO_FN_LCDD9, GPIO_FN_LCDD8,
151 GPIO_FN_LCDD7, GPIO_FN_LCDD6, GPIO_FN_LCDD5, GPIO_FN_LCDD4,
152 GPIO_FN_LCDD3, GPIO_FN_LCDD2, GPIO_FN_LCDD1, GPIO_FN_LCDD0,
153 GPIO_FN_LCDVSYN, GPIO_FN_LCDDISP, GPIO_FN_LCDRS, GPIO_FN_LCDHSYN,
154 GPIO_FN_LCDCS, GPIO_FN_LCDDON, GPIO_FN_LCDDCK, GPIO_FN_LCDWR,
155 GPIO_FN_LCDVEPWC, GPIO_FN_LCDVCPWC, GPIO_FN_LCDRD, GPIO_FN_LCDLCLK,
156
157 /* SCIF0 (PTF/PTM) */
158 GPIO_FN_SCIF0_TXD, GPIO_FN_SCIF0_RXD, GPIO_FN_SCIF0_SCK,
159
160 /* SCIF1 (PTL) */
161 GPIO_FN_SCIF1_SCK, GPIO_FN_SCIF1_RXD, GPIO_FN_SCIF1_TXD,
162
163 /* SCIF2 (PTE/PTF/PTN) with LCDC, VOU */
164 GPIO_FN_SCIF2_L_TXD, GPIO_FN_SCIF2_L_SCK, GPIO_FN_SCIF2_L_RXD,
165 GPIO_FN_SCIF2_V_TXD, GPIO_FN_SCIF2_V_SCK, GPIO_FN_SCIF2_V_RXD,
166
167 /* SCIF3 (PTL/PTN/PTZ) with VOU, IRQ */
168 GPIO_FN_SCIF3_V_SCK, GPIO_FN_SCIF3_V_RXD, GPIO_FN_SCIF3_V_TXD,
169 GPIO_FN_SCIF3_V_CTS, GPIO_FN_SCIF3_V_RTS,
170 GPIO_FN_SCIF3_I_SCK, GPIO_FN_SCIF3_I_RXD, GPIO_FN_SCIF3_I_TXD,
171 GPIO_FN_SCIF3_I_CTS, GPIO_FN_SCIF3_I_RTS,
172
173 /* SCIF4 (PTE) */
174 GPIO_FN_SCIF4_SCK, GPIO_FN_SCIF4_RXD, GPIO_FN_SCIF4_TXD,
175
176 /* SCIF5 (PTS) */
177 GPIO_FN_SCIF5_SCK, GPIO_FN_SCIF5_RXD, GPIO_FN_SCIF5_TXD,
178
179 /* FSI (PTE/PTU/PTV) */
180 GPIO_FN_FSIMCKB, GPIO_FN_FSIMCKA, GPIO_FN_FSIOASD,
181 GPIO_FN_FSIIABCK, GPIO_FN_FSIIALRCK, GPIO_FN_FSIOABCK,
182 GPIO_FN_FSIOALRCK, GPIO_FN_CLKAUDIOAO, GPIO_FN_FSIIBSD,
183 GPIO_FN_FSIOBSD, GPIO_FN_FSIIBBCK, GPIO_FN_FSIIBLRCK,
184 GPIO_FN_FSIOBBCK, GPIO_FN_FSIOBLRCK, GPIO_FN_CLKAUDIOBO,
185 GPIO_FN_FSIIASD,
186
187 /* AUD (PTG) */
188 GPIO_FN_AUDCK, GPIO_FN_AUDSYNC, GPIO_FN_AUDATA3,
189 GPIO_FN_AUDATA2, GPIO_FN_AUDATA1, GPIO_FN_AUDATA0,
190
191 /* VIO (PTS) (common?) */
192 GPIO_FN_VIO_CKO,
193
194 /* VIO0 (PTH/PTK) */
195 GPIO_FN_VIO0_D15, GPIO_FN_VIO0_D14, GPIO_FN_VIO0_D13, GPIO_FN_VIO0_D12,
196 GPIO_FN_VIO0_D11, GPIO_FN_VIO0_D10, GPIO_FN_VIO0_D9, GPIO_FN_VIO0_D8,
197 GPIO_FN_VIO0_D7, GPIO_FN_VIO0_D6, GPIO_FN_VIO0_D5, GPIO_FN_VIO0_D4,
198 GPIO_FN_VIO0_D3, GPIO_FN_VIO0_D2, GPIO_FN_VIO0_D1, GPIO_FN_VIO0_D0,
199 GPIO_FN_VIO0_VD, GPIO_FN_VIO0_CLK,
200 GPIO_FN_VIO0_FLD, GPIO_FN_VIO0_HD,
201
202 /* VIO1 (PTK/PTS) */
203 GPIO_FN_VIO1_D7, GPIO_FN_VIO1_D6, GPIO_FN_VIO1_D5, GPIO_FN_VIO1_D4,
204 GPIO_FN_VIO1_D3, GPIO_FN_VIO1_D2, GPIO_FN_VIO1_D1, GPIO_FN_VIO1_D0,
205 GPIO_FN_VIO1_FLD, GPIO_FN_VIO1_HD, GPIO_FN_VIO1_VD, GPIO_FN_VIO1_CLK,
206
207 /* Eth (PTL/PTN/PTX) */
208 GPIO_FN_RMII_RXD0, GPIO_FN_RMII_RXD1,
209 GPIO_FN_RMII_TXD0, GPIO_FN_RMII_TXD1,
210 GPIO_FN_RMII_REF_CLK, GPIO_FN_RMII_TX_EN,
211 GPIO_FN_RMII_RX_ER, GPIO_FN_RMII_CRS_DV,
212 GPIO_FN_LNKSTA, GPIO_FN_MDIO,
213 GPIO_FN_MDC,
214
215 /* System (PTJ) */
216 GPIO_FN_PDSTATUS, GPIO_FN_STATUS2, GPIO_FN_STATUS0,
217
218 /* VOU (PTL/PTM/PTN*/
219 GPIO_FN_DV_D15, GPIO_FN_DV_D14, GPIO_FN_DV_D13, GPIO_FN_DV_D12,
220 GPIO_FN_DV_D11, GPIO_FN_DV_D10, GPIO_FN_DV_D9, GPIO_FN_DV_D8,
221 GPIO_FN_DV_D7, GPIO_FN_DV_D6, GPIO_FN_DV_D5, GPIO_FN_DV_D4,
222 GPIO_FN_DV_D3, GPIO_FN_DV_D2, GPIO_FN_DV_D1, GPIO_FN_DV_D0,
223 GPIO_FN_DV_CLKI, GPIO_FN_DV_CLK, GPIO_FN_DV_VSYNC, GPIO_FN_DV_HSYNC,
224
225 /* MSIOF0 (PTL/PTM) */
226 GPIO_FN_MSIOF0_RXD, GPIO_FN_MSIOF0_TXD,
227 GPIO_FN_MSIOF0_MCK, GPIO_FN_MSIOF0_TSCK,
228 GPIO_FN_MSIOF0_SS1, GPIO_FN_MSIOF0_SS2,
229 GPIO_FN_MSIOF0_TSYNC, GPIO_FN_MSIOF0_RSCK,
230 GPIO_FN_MSIOF0_RSYNC,
231
232 /* MSIOF1 (PTV) */
233 GPIO_FN_MSIOF1_RXD, GPIO_FN_MSIOF1_TXD,
234 GPIO_FN_MSIOF1_MCK, GPIO_FN_MSIOF1_TSCK,
235 GPIO_FN_MSIOF1_SS1, GPIO_FN_MSIOF1_SS2,
236 GPIO_FN_MSIOF1_TSYNC, GPIO_FN_MSIOF1_RSCK,
237 GPIO_FN_MSIOF1_RSYNC,
238
239 /* DMAC (PTU/PTX) */
240 GPIO_FN_DMAC_DACK0, GPIO_FN_DMAC_DREQ0,
241 GPIO_FN_DMAC_DACK1, GPIO_FN_DMAC_DREQ1,
242
243 /* SDHI0 (PTY) */
244 GPIO_FN_SDHI0CD, GPIO_FN_SDHI0WP, GPIO_FN_SDHI0CMD, GPIO_FN_SDHI0CLK,
245 GPIO_FN_SDHI0D3, GPIO_FN_SDHI0D2, GPIO_FN_SDHI0D1, GPIO_FN_SDHI0D0,
246
247 /* SDHI1 (PTW) */
248 GPIO_FN_SDHI1CD, GPIO_FN_SDHI1WP, GPIO_FN_SDHI1CMD, GPIO_FN_SDHI1CLK,
249 GPIO_FN_SDHI1D3, GPIO_FN_SDHI1D2, GPIO_FN_SDHI1D1, GPIO_FN_SDHI1D0,
250
251 /* MMC (PTW/PTX)*/
252 GPIO_FN_MMC_D7, GPIO_FN_MMC_D6, GPIO_FN_MMC_D5, GPIO_FN_MMC_D4,
253 GPIO_FN_MMC_D3, GPIO_FN_MMC_D2, GPIO_FN_MMC_D1, GPIO_FN_MMC_D0,
254 GPIO_FN_MMC_CLK, GPIO_FN_MMC_CMD,
255
256 /* IrDA (PTX) */
257 GPIO_FN_IRDA_OUT, GPIO_FN_IRDA_IN,
258
259 /* TSIF (PTX) */
260 GPIO_FN_TSIF_TS0_SDAT, GPIO_FN_TSIF_TS0_SCK,
261 GPIO_FN_TSIF_TS0_SDEN, GPIO_FN_TSIF_TS0_SPSYNC,
262
263 /* IRQ (PTZ) */
264 GPIO_FN_INTC_IRQ7, GPIO_FN_INTC_IRQ6, GPIO_FN_INTC_IRQ5,
265 GPIO_FN_INTC_IRQ4, GPIO_FN_INTC_IRQ3, GPIO_FN_INTC_IRQ2,
266 GPIO_FN_INTC_IRQ1, GPIO_FN_INTC_IRQ0,
267};
268
269#endif /* __ASM_SH7724_H__ */
diff --git a/arch/sh/include/cpu-sh4/cpu/sh7785.h b/arch/sh/include/cpu-sh4/cpu/sh7785.h
index e4006afb735e..9dc9d91e0a8e 100644
--- a/arch/sh/include/cpu-sh4/cpu/sh7785.h
+++ b/arch/sh/include/cpu-sh4/cpu/sh7785.h
@@ -1,6 +1,31 @@
1#ifndef __ASM_SH7785_H__ 1#ifndef __ASM_SH7785_H__
2#define __ASM_SH7785_H__ 2#define __ASM_SH7785_H__
3 3
4/* Boot Mode Pins:
5 *
6 * MODE0: CPG - Initial Pck/Bck Frequency [FRQMR1]
7 * MODE1: CPG - Initial Uck/SHck/DDRck Frequency [FRQMR1]
8 * MODE2: CPG - Reserved (L: Normal operation)
9 * MODE3: CPG - Reserved (L: Normal operation)
10 * MODE4: CPG - Initial PLL setting (72x/36x)
11 * MODE5: LBSC - Area0 Memory Type / Bus Width [CS0BCR.8]
12 * MODE6: LBSC - Area0 Memory Type / Bus Width [CS0BCR.9]
13 * MODE7: LBSC - Area0 Memory Type / Bus Width [CS0BCR.3]
14 * MODE8: LBSC - Endian Mode (L: Big, H: Little) [BCR.31]
15 * MODE9: LBSC - Master/Slave Mode (L: Slave) [BCR.30]
16 * MODE10: CPG - Clock Input (L: Ext Clk, H: Crystal)
17 * MODE11: PCI - Pin Mode (LL: PCI host, LH: PCI slave)
18 * MODE12: PCI - Pin Mode (HL: Local bus, HH: DU)
19 * MODE13: Boot Address Mode (L: 29-bit, H: 32-bit)
20 * MODE14: Reserved (H: Normal operation)
21 *
22 * More information in sh7785 manual Rev.1.00, page 1628.
23 */
24
25/* Pin Function Controller:
26 * GPIO_FN_xx - GPIO used to select pin function
27 * GPIO_Pxx - GPIO mapped to real I/O pin on CPU
28 */
4enum { 29enum {
5 /* PA */ 30 /* PA */
6 GPIO_PA7, GPIO_PA6, GPIO_PA5, GPIO_PA4, 31 GPIO_PA7, GPIO_PA6, GPIO_PA5, GPIO_PA4,
diff --git a/arch/sh/include/cpu-sh4/cpu/timer.h b/arch/sh/include/cpu-sh4/cpu/timer.h
deleted file mode 100644
index d1e796b96888..000000000000
--- a/arch/sh/include/cpu-sh4/cpu/timer.h
+++ /dev/null
@@ -1,60 +0,0 @@
1/*
2 * include/asm-sh/cpu-sh4/timer.h
3 *
4 * Copyright (C) 2004 Lineo Solutions, Inc.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10#ifndef __ASM_CPU_SH4_TIMER_H
11#define __ASM_CPU_SH4_TIMER_H
12
13/*
14 * ---------------------------------------------------------------------------
15 * TMU Common definitions for SH4 processors
16 * SH7750S/SH7750R
17 * SH7751/SH7751R
18 * SH7760
19 * SH-X3
20 * ---------------------------------------------------------------------------
21 */
22#ifdef CONFIG_CPU_SUBTYPE_SHX3
23#define TMU_012_BASE 0xffc10000
24#define TMU_345_BASE 0xffc20000
25#else
26#define TMU_012_BASE 0xffd80000
27#define TMU_345_BASE 0xfe100000
28#endif
29
30#define TMU_TOCR TMU_012_BASE /* Not supported on all CPUs */
31
32#define TMU_012_TSTR (TMU_012_BASE + 0x04)
33#define TMU_345_TSTR (TMU_345_BASE + 0x04)
34
35#define TMU0_TCOR (TMU_012_BASE + 0x08)
36#define TMU0_TCNT (TMU_012_BASE + 0x0c)
37#define TMU0_TCR (TMU_012_BASE + 0x10)
38
39#define TMU1_TCOR (TMU_012_BASE + 0x14)
40#define TMU1_TCNT (TMU_012_BASE + 0x18)
41#define TMU1_TCR (TMU_012_BASE + 0x1c)
42
43#define TMU2_TCOR (TMU_012_BASE + 0x20)
44#define TMU2_TCNT (TMU_012_BASE + 0x24)
45#define TMU2_TCR (TMU_012_BASE + 0x28)
46#define TMU2_TCPR (TMU_012_BASE + 0x2c)
47
48#define TMU3_TCOR (TMU_345_BASE + 0x08)
49#define TMU3_TCNT (TMU_345_BASE + 0x0c)
50#define TMU3_TCR (TMU_345_BASE + 0x10)
51
52#define TMU4_TCOR (TMU_345_BASE + 0x14)
53#define TMU4_TCNT (TMU_345_BASE + 0x18)
54#define TMU4_TCR (TMU_345_BASE + 0x1c)
55
56#define TMU5_TCOR (TMU_345_BASE + 0x20)
57#define TMU5_TCNT (TMU_345_BASE + 0x24)
58#define TMU5_TCR (TMU_345_BASE + 0x28)
59
60#endif /* __ASM_CPU_SH4_TIMER_H */
diff --git a/arch/sh/include/cpu-sh5/cpu/irq.h b/arch/sh/include/cpu-sh5/cpu/irq.h
index f0f0756e6e84..0ccf257a72d1 100644
--- a/arch/sh/include/cpu-sh5/cpu/irq.h
+++ b/arch/sh/include/cpu-sh5/cpu/irq.h
@@ -111,7 +111,6 @@
111#define TOP_PRIORITY 15 111#define TOP_PRIORITY 15
112 112
113extern int intc_evt_to_irq[(0xE20/0x20)+1]; 113extern int intc_evt_to_irq[(0xE20/0x20)+1];
114int intc_irq_describe(char* p, int irq);
115extern int platform_int_priority[NR_INTC_IRQS]; 114extern int platform_int_priority[NR_INTC_IRQS];
116 115
117#endif /* __ASM_SH_CPU_SH5_IRQ_H */ 116#endif /* __ASM_SH_CPU_SH5_IRQ_H */
diff --git a/arch/sh/include/mach-common/mach/sh7785lcr.h b/arch/sh/include/mach-common/mach/sh7785lcr.h
index 1ce27d5c7491..90011d435f30 100644
--- a/arch/sh/include/mach-common/mach/sh7785lcr.h
+++ b/arch/sh/include/mach-common/mach/sh7785lcr.h
@@ -9,11 +9,11 @@
9 * -----------------------------+---------------+--------------- 9 * -----------------------------+---------------+---------------
10 * 0x00000000 - 0x03ffffff(CS0) | NOR Flash | NOR Flash 10 * 0x00000000 - 0x03ffffff(CS0) | NOR Flash | NOR Flash
11 * 0x04000000 - 0x05ffffff(CS1) | PLD | PLD 11 * 0x04000000 - 0x05ffffff(CS1) | PLD | PLD
12 * 0x06000000 - 0x07ffffff(CS1) | reserved | I2C 12 * 0x06000000 - 0x07ffffff(CS1) | I2C | I2C
13 * 0x08000000 - 0x0bffffff(CS2) | USB | DDR SDRAM 13 * 0x08000000 - 0x0bffffff(CS2) | USB | DDR SDRAM
14 * 0x0c000000 - 0x0fffffff(CS3) | SD | DDR SDRAM 14 * 0x0c000000 - 0x0fffffff(CS3) | SD | DDR SDRAM
15 * 0x10000000 - 0x13ffffff(CS4) | SM107 | SM107 15 * 0x10000000 - 0x13ffffff(CS4) | SM107 | SM107
16 * 0x14000000 - 0x17ffffff(CS5) | I2C | USB 16 * 0x14000000 - 0x17ffffff(CS5) | reserved | USB
17 * 0x18000000 - 0x1bffffff(CS6) | reserved | SD 17 * 0x18000000 - 0x1bffffff(CS6) | reserved | SD
18 * 0x40000000 - 0x5fffffff | DDR SDRAM | (cannot use) 18 * 0x40000000 - 0x5fffffff | DDR SDRAM | (cannot use)
19 * 19 *
@@ -32,6 +32,9 @@
32#define PLD_VERSR (PLD_BASE_ADDR + 0x0c) 32#define PLD_VERSR (PLD_BASE_ADDR + 0x0c)
33#define PLD_MMSR (PLD_BASE_ADDR + 0x0e) 33#define PLD_MMSR (PLD_BASE_ADDR + 0x0e)
34 34
35#define PCA9564_ADDR 0x06000000 /* I2C */
36#define PCA9564_SIZE 0x00000100
37
35#define SM107_MEM_ADDR 0x10000000 38#define SM107_MEM_ADDR 0x10000000
36#define SM107_MEM_SIZE 0x00e00000 39#define SM107_MEM_SIZE 0x00e00000
37#define SM107_REG_ADDR 0x13e00000 40#define SM107_REG_ADDR 0x13e00000
@@ -40,16 +43,13 @@
40#if defined(CONFIG_SH_SH7785LCR_29BIT_PHYSMAPS) 43#if defined(CONFIG_SH_SH7785LCR_29BIT_PHYSMAPS)
41#define R8A66597_ADDR 0x14000000 /* USB */ 44#define R8A66597_ADDR 0x14000000 /* USB */
42#define CG200_ADDR 0x18000000 /* SD */ 45#define CG200_ADDR 0x18000000 /* SD */
43#define PCA9564_ADDR 0x06000000 /* I2C */
44#else 46#else
45#define R8A66597_ADDR 0x08000000 47#define R8A66597_ADDR 0x08000000
46#define CG200_ADDR 0x0c000000 48#define CG200_ADDR 0x0c000000
47#define PCA9564_ADDR 0x14000000
48#endif 49#endif
49 50
50#define R8A66597_SIZE 0x00000100 51#define R8A66597_SIZE 0x00000100
51#define CG200_SIZE 0x00010000 52#define CG200_SIZE 0x00010000
52#define PCA9564_SIZE 0x00000100
53 53
54#endif /* __ASM_SH_RENESAS_SH7785LCR_H */ 54#endif /* __ASM_SH_RENESAS_SH7785LCR_H */
55 55
diff --git a/arch/sh/include/mach-dreamcast/mach/pci.h b/arch/sh/include/mach-dreamcast/mach/pci.h
index 75fc9009e092..0314d975e626 100644
--- a/arch/sh/include/mach-dreamcast/mach/pci.h
+++ b/arch/sh/include/mach-dreamcast/mach/pci.h
@@ -21,5 +21,7 @@
21 21
22#define GAPSPCI_IRQ HW_EVENT_EXTERNAL 22#define GAPSPCI_IRQ HW_EVENT_EXTERNAL
23 23
24extern struct pci_ops gapspci_pci_ops;
25
24#endif /* __ASM_SH_DREAMCAST_PCI_H */ 26#endif /* __ASM_SH_DREAMCAST_PCI_H */
25 27
diff --git a/arch/sh/include/mach-se/mach/se7724.h b/arch/sh/include/mach-se/mach/se7724.h
new file mode 100644
index 000000000000..74164b60d0db
--- /dev/null
+++ b/arch/sh/include/mach-se/mach/se7724.h
@@ -0,0 +1,67 @@
1#ifndef __ASM_SH_SE7724_H
2#define __ASM_SH_SE7724_H
3
4/*
5 * linux/include/asm-sh/se7724.h
6 *
7 * Copyright (C) 2009 Renesas Solutions Corp.
8 *
9 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
10 *
11 * Hitachi UL SolutionEngine 7724 Support.
12 *
13 * Based on se7722.h
14 * Copyright (C) 2007 Nobuhiro Iwamatsu
15 *
16 * This file is subject to the terms and conditions of the GNU General Public
17 * License. See the file "COPYING" in the main directory of this archive
18 * for more details.
19 *
20 */
21#include <asm/addrspace.h>
22
23#define PA_LED (0xba203000) /* 8bit LED */
24#define IRQ_MODE (0xba200010)
25#define IRQ0_SR (0xba200014)
26#define IRQ1_SR (0xba200018)
27#define IRQ2_SR (0xba20001c)
28#define IRQ0_MR (0xba200020)
29#define IRQ1_MR (0xba200024)
30#define IRQ2_MR (0xba200028)
31
32/* IRQ */
33#define IRQ0_IRQ 32
34#define IRQ1_IRQ 33
35#define IRQ2_IRQ 34
36
37/* Bits in IRQ012 registers */
38#define SE7724_FPGA_IRQ_BASE 220
39
40/* IRQ0 */
41#define IRQ0_BASE SE7724_FPGA_IRQ_BASE
42#define IRQ0_KEY (IRQ0_BASE + 12)
43#define IRQ0_RMII (IRQ0_BASE + 13)
44#define IRQ0_SMC (IRQ0_BASE + 14)
45#define IRQ0_MASK 0x7fff
46#define IRQ0_END IRQ0_SMC
47/* IRQ1 */
48#define IRQ1_BASE (IRQ0_END + 1)
49#define IRQ1_TS (IRQ1_BASE + 0)
50#define IRQ1_MASK 0x0001
51#define IRQ1_END IRQ1_TS
52/* IRQ2 */
53#define IRQ2_BASE (IRQ1_END + 1)
54#define IRQ2_USB0 (IRQ1_BASE + 0)
55#define IRQ2_USB1 (IRQ1_BASE + 1)
56#define IRQ2_MASK 0x0003
57#define IRQ2_END IRQ2_USB1
58
59#define SE7724_FPGA_IRQ_NR (IRQ2_END - IRQ0_BASE)
60
61/* arch/sh/boards/se/7724/irq.c */
62void init_se7724_IRQ(void);
63
64#define __IO_PREFIX se7724
65#include <asm/io_generic.h>
66
67#endif /* __ASM_SH_SE7724_H */
diff --git a/arch/sh/kernel/Makefile_32 b/arch/sh/kernel/Makefile_32
index 82a3a150c00d..9411e3e31e68 100644
--- a/arch/sh/kernel/Makefile_32
+++ b/arch/sh/kernel/Makefile_32
@@ -11,10 +11,10 @@ endif
11 11
12obj-y := debugtraps.o idle.o io.o io_generic.o irq.o \ 12obj-y := debugtraps.o idle.o io.o io_generic.o irq.o \
13 machvec.o process_32.o ptrace_32.o setup.o signal_32.o \ 13 machvec.o process_32.o ptrace_32.o setup.o signal_32.o \
14 sys_sh.o sys_sh32.o syscalls_32.o time_32.o topology.o \ 14 sys_sh.o sys_sh32.o syscalls_32.o time.o topology.o \
15 traps.o traps_32.o 15 traps.o traps_32.o
16 16
17obj-y += cpu/ timers/ 17obj-y += cpu/
18obj-$(CONFIG_VSYSCALL) += vsyscall/ 18obj-$(CONFIG_VSYSCALL) += vsyscall/
19obj-$(CONFIG_SMP) += smp.o 19obj-$(CONFIG_SMP) += smp.o
20obj-$(CONFIG_SH_STANDARD_BIOS) += sh_bios.o 20obj-$(CONFIG_SH_STANDARD_BIOS) += sh_bios.o
@@ -32,4 +32,6 @@ obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o
32obj-$(CONFIG_DUMP_CODE) += disassemble.o 32obj-$(CONFIG_DUMP_CODE) += disassemble.o
33obj-$(CONFIG_HIBERNATION) += swsusp.o 33obj-$(CONFIG_HIBERNATION) += swsusp.o
34 34
35obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) += localtimer.o
36
35EXTRA_CFLAGS += -Werror 37EXTRA_CFLAGS += -Werror
diff --git a/arch/sh/kernel/Makefile_64 b/arch/sh/kernel/Makefile_64
index fe425d7f6871..67b9f6c6326b 100644
--- a/arch/sh/kernel/Makefile_64
+++ b/arch/sh/kernel/Makefile_64
@@ -2,19 +2,18 @@ extra-y := head_64.o init_task.o vmlinux.lds
2 2
3obj-y := debugtraps.o idle.o io.o io_generic.o irq.o machvec.o process_64.o \ 3obj-y := debugtraps.o idle.o io.o io_generic.o irq.o machvec.o process_64.o \
4 ptrace_64.o setup.o signal_64.o sys_sh.o sys_sh64.o \ 4 ptrace_64.o setup.o signal_64.o sys_sh.o sys_sh64.o \
5 syscalls_64.o time_64.o topology.o traps.o traps_64.o 5 syscalls_64.o time.o topology.o traps.o traps_64.o
6 6
7obj-y += cpu/ timers/ 7obj-y += cpu/
8obj-$(CONFIG_VSYSCALL) += vsyscall/
9obj-$(CONFIG_SMP) += smp.o 8obj-$(CONFIG_SMP) += smp.o
10obj-$(CONFIG_SH_STANDARD_BIOS) += sh_bios.o
11obj-$(CONFIG_SH_CPU_FREQ) += cpufreq.o 9obj-$(CONFIG_SH_CPU_FREQ) += cpufreq.o
12obj-$(CONFIG_MODULES) += sh_ksyms_64.o module.o 10obj-$(CONFIG_MODULES) += sh_ksyms_64.o module.o
13obj-$(CONFIG_EARLY_PRINTK) += early_printk.o 11obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
14obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
15obj-$(CONFIG_CRASH_DUMP) += crash_dump.o 12obj-$(CONFIG_CRASH_DUMP) += crash_dump.o
16obj-$(CONFIG_STACKTRACE) += stacktrace.o 13obj-$(CONFIG_STACKTRACE) += stacktrace.o
17obj-$(CONFIG_IO_TRAPPED) += io_trapped.o 14obj-$(CONFIG_IO_TRAPPED) += io_trapped.o
18obj-$(CONFIG_GENERIC_GPIO) += gpio.o 15obj-$(CONFIG_GENERIC_GPIO) += gpio.o
19 16
17obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) += localtimer.o
18
20EXTRA_CFLAGS += -Werror 19EXTRA_CFLAGS += -Werror
diff --git a/arch/sh/kernel/cpu/Makefile b/arch/sh/kernel/cpu/Makefile
index 2600641a483f..eecad7cbd61e 100644
--- a/arch/sh/kernel/cpu/Makefile
+++ b/arch/sh/kernel/cpu/Makefile
@@ -17,5 +17,6 @@ obj-$(CONFIG_ARCH_SHMOBILE) += shmobile/
17 17
18obj-$(CONFIG_UBC_WAKEUP) += ubc.o 18obj-$(CONFIG_UBC_WAKEUP) += ubc.o
19obj-$(CONFIG_SH_ADC) += adc.o 19obj-$(CONFIG_SH_ADC) += adc.o
20obj-$(CONFIG_SH_CLK_CPG) += clock-cpg.o
20 21
21obj-y += irq/ init.o clock.o 22obj-y += irq/ init.o clock.o
diff --git a/arch/sh/kernel/cpu/clock-cpg.c b/arch/sh/kernel/cpu/clock-cpg.c
new file mode 100644
index 000000000000..275942e58e4f
--- /dev/null
+++ b/arch/sh/kernel/cpu/clock-cpg.c
@@ -0,0 +1,256 @@
1#include <linux/clk.h>
2#include <linux/compiler.h>
3#include <linux/bootmem.h>
4#include <linux/io.h>
5#include <asm/clock.h>
6
7static int sh_clk_mstp32_enable(struct clk *clk)
8{
9 __raw_writel(__raw_readl(clk->enable_reg) & ~(1 << clk->enable_bit),
10 clk->enable_reg);
11 return 0;
12}
13
14static void sh_clk_mstp32_disable(struct clk *clk)
15{
16 __raw_writel(__raw_readl(clk->enable_reg) | (1 << clk->enable_bit),
17 clk->enable_reg);
18}
19
20static struct clk_ops sh_clk_mstp32_clk_ops = {
21 .enable = sh_clk_mstp32_enable,
22 .disable = sh_clk_mstp32_disable,
23 .recalc = followparent_recalc,
24};
25
26int __init sh_clk_mstp32_register(struct clk *clks, int nr)
27{
28 struct clk *clkp;
29 int ret = 0;
30 int k;
31
32 for (k = 0; !ret && (k < nr); k++) {
33 clkp = clks + k;
34 clkp->ops = &sh_clk_mstp32_clk_ops;
35 ret |= clk_register(clkp);
36 }
37
38 return ret;
39}
40
41static long sh_clk_div_round_rate(struct clk *clk, unsigned long rate)
42{
43 return clk_rate_table_round(clk, clk->freq_table, rate);
44}
45
46static int sh_clk_div6_divisors[64] = {
47 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
48 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
49 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
50 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
51};
52
53static struct clk_div_mult_table sh_clk_div6_table = {
54 .divisors = sh_clk_div6_divisors,
55 .nr_divisors = ARRAY_SIZE(sh_clk_div6_divisors),
56};
57
58static unsigned long sh_clk_div6_recalc(struct clk *clk)
59{
60 struct clk_div_mult_table *table = &sh_clk_div6_table;
61 unsigned int idx;
62
63 clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
64 table, NULL);
65
66 idx = __raw_readl(clk->enable_reg) & 0x003f;
67
68 return clk->freq_table[idx].frequency;
69}
70
71static int sh_clk_div6_set_rate(struct clk *clk,
72 unsigned long rate, int algo_id)
73{
74 unsigned long value;
75 int idx;
76
77 idx = clk_rate_table_find(clk, clk->freq_table, rate);
78 if (idx < 0)
79 return idx;
80
81 value = __raw_readl(clk->enable_reg);
82 value &= ~0x3f;
83 value |= idx;
84 __raw_writel(value, clk->enable_reg);
85 return 0;
86}
87
88static int sh_clk_div6_enable(struct clk *clk)
89{
90 unsigned long value;
91 int ret;
92
93 ret = sh_clk_div6_set_rate(clk, clk->rate, 0);
94 if (ret == 0) {
95 value = __raw_readl(clk->enable_reg);
96 value &= ~0x100; /* clear stop bit to enable clock */
97 __raw_writel(value, clk->enable_reg);
98 }
99 return ret;
100}
101
102static void sh_clk_div6_disable(struct clk *clk)
103{
104 unsigned long value;
105
106 value = __raw_readl(clk->enable_reg);
107 value |= 0x100; /* stop clock */
108 value |= 0x3f; /* VDIV bits must be non-zero, overwrite divider */
109 __raw_writel(value, clk->enable_reg);
110}
111
112static struct clk_ops sh_clk_div6_clk_ops = {
113 .recalc = sh_clk_div6_recalc,
114 .round_rate = sh_clk_div_round_rate,
115 .set_rate = sh_clk_div6_set_rate,
116 .enable = sh_clk_div6_enable,
117 .disable = sh_clk_div6_disable,
118};
119
120int __init sh_clk_div6_register(struct clk *clks, int nr)
121{
122 struct clk *clkp;
123 void *freq_table;
124 int nr_divs = sh_clk_div6_table.nr_divisors;
125 int freq_table_size = sizeof(struct cpufreq_frequency_table);
126 int ret = 0;
127 int k;
128
129 freq_table_size *= (nr_divs + 1);
130
131 freq_table = alloc_bootmem(freq_table_size * nr);
132 if (!freq_table)
133 return -ENOMEM;
134
135 for (k = 0; !ret && (k < nr); k++) {
136 clkp = clks + k;
137
138 clkp->ops = &sh_clk_div6_clk_ops;
139 clkp->id = -1;
140 clkp->freq_table = freq_table + (k * freq_table_size);
141 clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END;
142
143 ret = clk_register(clkp);
144 }
145
146 return ret;
147}
148
149static unsigned long sh_clk_div4_recalc(struct clk *clk)
150{
151 struct clk_div_mult_table *table = clk->priv;
152 unsigned int idx;
153
154 clk_rate_table_build(clk, clk->freq_table, table->nr_divisors,
155 table, &clk->arch_flags);
156
157 idx = (__raw_readl(clk->enable_reg) >> clk->enable_bit) & 0x000f;
158
159 return clk->freq_table[idx].frequency;
160}
161
162static struct clk_ops sh_clk_div4_clk_ops = {
163 .recalc = sh_clk_div4_recalc,
164 .round_rate = sh_clk_div_round_rate,
165};
166
167int __init sh_clk_div4_register(struct clk *clks, int nr,
168 struct clk_div_mult_table *table)
169{
170 struct clk *clkp;
171 void *freq_table;
172 int nr_divs = table->nr_divisors;
173 int freq_table_size = sizeof(struct cpufreq_frequency_table);
174 int ret = 0;
175 int k;
176
177 freq_table_size *= (nr_divs + 1);
178
179 freq_table = alloc_bootmem(freq_table_size * nr);
180 if (!freq_table)
181 return -ENOMEM;
182
183 for (k = 0; !ret && (k < nr); k++) {
184 clkp = clks + k;
185
186 clkp->ops = &sh_clk_div4_clk_ops;
187 clkp->id = -1;
188 clkp->priv = table;
189
190 clkp->freq_table = freq_table + (k * freq_table_size);
191 clkp->freq_table[nr_divs].frequency = CPUFREQ_TABLE_END;
192
193 ret = clk_register(clkp);
194 }
195
196 return ret;
197}
198
199#ifdef CONFIG_SH_CLK_CPG_LEGACY
200static struct clk master_clk = {
201 .name = "master_clk",
202 .flags = CLK_ENABLE_ON_INIT,
203 .rate = CONFIG_SH_PCLK_FREQ,
204};
205
206static struct clk peripheral_clk = {
207 .name = "peripheral_clk",
208 .parent = &master_clk,
209 .flags = CLK_ENABLE_ON_INIT,
210};
211
212static struct clk bus_clk = {
213 .name = "bus_clk",
214 .parent = &master_clk,
215 .flags = CLK_ENABLE_ON_INIT,
216};
217
218static struct clk cpu_clk = {
219 .name = "cpu_clk",
220 .parent = &master_clk,
221 .flags = CLK_ENABLE_ON_INIT,
222};
223
224/*
225 * The ordering of these clocks matters, do not change it.
226 */
227static struct clk *onchip_clocks[] = {
228 &master_clk,
229 &peripheral_clk,
230 &bus_clk,
231 &cpu_clk,
232};
233
234int __init __deprecated cpg_clk_init(void)
235{
236 int i, ret = 0;
237
238 for (i = 0; i < ARRAY_SIZE(onchip_clocks); i++) {
239 struct clk *clk = onchip_clocks[i];
240 arch_init_clk_ops(&clk->ops, i);
241 if (clk->ops)
242 ret |= clk_register(clk);
243 }
244
245 return ret;
246}
247
248/*
249 * Placeholder for compatability, until the lazy CPUs do this
250 * on their own.
251 */
252int __init __weak arch_clk_init(void)
253{
254 return cpg_clk_init();
255}
256#endif /* CONFIG_SH_CPG_CLK_LEGACY */
diff --git a/arch/sh/kernel/cpu/clock.c b/arch/sh/kernel/cpu/clock.c
index 1dc896483b59..f3a46be2ae81 100644
--- a/arch/sh/kernel/cpu/clock.c
+++ b/arch/sh/kernel/cpu/clock.c
@@ -1,15 +1,19 @@
1/* 1/*
2 * arch/sh/kernel/cpu/clock.c - SuperH clock framework 2 * arch/sh/kernel/cpu/clock.c - SuperH clock framework
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Paul Mundt 4 * Copyright (C) 2005 - 2009 Paul Mundt
5 * 5 *
6 * This clock framework is derived from the OMAP version by: 6 * This clock framework is derived from the OMAP version by:
7 * 7 *
8 * Copyright (C) 2004 - 2005 Nokia Corporation 8 * Copyright (C) 2004 - 2008 Nokia Corporation
9 * Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com> 9 * Written by Tuukka Tikkanen <tuukka.tikkanen@elektrobit.com>
10 * 10 *
11 * Modified for omap shared clock framework by Tony Lindgren <tony@atomide.com> 11 * Modified for omap shared clock framework by Tony Lindgren <tony@atomide.com>
12 * 12 *
13 * With clkdev bits:
14 *
15 * Copyright (C) 2008 Russell King.
16 *
13 * This file is subject to the terms and conditions of the GNU General Public 17 * This file is subject to the terms and conditions of the GNU General Public
14 * License. See the file "COPYING" in the main directory of this archive 18 * License. See the file "COPYING" in the main directory of this archive
15 * for more details. 19 * for more details.
@@ -19,134 +23,159 @@
19#include <linux/module.h> 23#include <linux/module.h>
20#include <linux/mutex.h> 24#include <linux/mutex.h>
21#include <linux/list.h> 25#include <linux/list.h>
22#include <linux/kref.h>
23#include <linux/kobject.h> 26#include <linux/kobject.h>
24#include <linux/sysdev.h> 27#include <linux/sysdev.h>
25#include <linux/seq_file.h> 28#include <linux/seq_file.h>
26#include <linux/err.h> 29#include <linux/err.h>
27#include <linux/platform_device.h> 30#include <linux/platform_device.h>
28#include <linux/proc_fs.h> 31#include <linux/debugfs.h>
32#include <linux/cpufreq.h>
29#include <asm/clock.h> 33#include <asm/clock.h>
30#include <asm/timer.h> 34#include <asm/machvec.h>
31 35
32static LIST_HEAD(clock_list); 36static LIST_HEAD(clock_list);
33static DEFINE_SPINLOCK(clock_lock); 37static DEFINE_SPINLOCK(clock_lock);
34static DEFINE_MUTEX(clock_list_sem); 38static DEFINE_MUTEX(clock_list_sem);
35 39
36/* 40void clk_rate_table_build(struct clk *clk,
37 * Each subtype is expected to define the init routines for these clocks, 41 struct cpufreq_frequency_table *freq_table,
38 * as each subtype (or processor family) will have these clocks at the 42 int nr_freqs,
39 * very least. These are all provided through the CPG, which even some of 43 struct clk_div_mult_table *src_table,
40 * the more quirky parts (such as ST40, SH4-202, etc.) still have. 44 unsigned long *bitmap)
41 * 45{
42 * The processor-specific code is expected to register any additional 46 unsigned long mult, div;
43 * clock sources that are of interest. 47 unsigned long freq;
44 */ 48 int i;
45static struct clk master_clk = {
46 .name = "master_clk",
47 .flags = CLK_ALWAYS_ENABLED | CLK_RATE_PROPAGATES,
48 .rate = CONFIG_SH_PCLK_FREQ,
49};
50 49
51static struct clk module_clk = { 50 for (i = 0; i < nr_freqs; i++) {
52 .name = "module_clk", 51 div = 1;
53 .parent = &master_clk, 52 mult = 1;
54 .flags = CLK_ALWAYS_ENABLED | CLK_RATE_PROPAGATES,
55};
56 53
57static struct clk bus_clk = { 54 if (src_table->divisors && i < src_table->nr_divisors)
58 .name = "bus_clk", 55 div = src_table->divisors[i];
59 .parent = &master_clk,
60 .flags = CLK_ALWAYS_ENABLED | CLK_RATE_PROPAGATES,
61};
62 56
63static struct clk cpu_clk = { 57 if (src_table->multipliers && i < src_table->nr_multipliers)
64 .name = "cpu_clk", 58 mult = src_table->multipliers[i];
65 .parent = &master_clk,
66 .flags = CLK_ALWAYS_ENABLED,
67};
68 59
69/* 60 if (!div || !mult || (bitmap && !test_bit(i, bitmap)))
70 * The ordering of these clocks matters, do not change it. 61 freq = CPUFREQ_ENTRY_INVALID;
71 */ 62 else
72static struct clk *onchip_clocks[] = { 63 freq = clk->parent->rate * mult / div;
73 &master_clk,
74 &module_clk,
75 &bus_clk,
76 &cpu_clk,
77};
78 64
79static void propagate_rate(struct clk *clk) 65 freq_table[i].index = i;
66 freq_table[i].frequency = freq;
67 }
68
69 /* Termination entry */
70 freq_table[i].index = i;
71 freq_table[i].frequency = CPUFREQ_TABLE_END;
72}
73
74long clk_rate_table_round(struct clk *clk,
75 struct cpufreq_frequency_table *freq_table,
76 unsigned long rate)
80{ 77{
81 struct clk *clkp; 78 unsigned long rate_error, rate_error_prev = ~0UL;
79 unsigned long rate_best_fit = rate;
80 unsigned long highest, lowest;
81 int i;
82
83 highest = lowest = 0;
84
85 for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
86 unsigned long freq = freq_table[i].frequency;
82 87
83 list_for_each_entry(clkp, &clock_list, node) { 88 if (freq == CPUFREQ_ENTRY_INVALID)
84 if (likely(clkp->parent != clk))
85 continue; 89 continue;
86 if (likely(clkp->ops && clkp->ops->recalc)) 90
87 clkp->ops->recalc(clkp); 91 if (freq > highest)
88 if (unlikely(clkp->flags & CLK_RATE_PROPAGATES)) 92 highest = freq;
89 propagate_rate(clkp); 93 if (freq < lowest)
94 lowest = freq;
95
96 rate_error = abs(freq - rate);
97 if (rate_error < rate_error_prev) {
98 rate_best_fit = freq;
99 rate_error_prev = rate_error;
100 }
101
102 if (rate_error == 0)
103 break;
90 } 104 }
105
106 if (rate >= highest)
107 rate_best_fit = highest;
108 if (rate <= lowest)
109 rate_best_fit = lowest;
110
111 return rate_best_fit;
91} 112}
92 113
93static int __clk_enable(struct clk *clk) 114int clk_rate_table_find(struct clk *clk,
115 struct cpufreq_frequency_table *freq_table,
116 unsigned long rate)
94{ 117{
95 /* 118 int i;
96 * See if this is the first time we're enabling the clock, some
97 * clocks that are always enabled still require "special"
98 * initialization. This is especially true if the clock mode
99 * changes and the clock needs to hunt for the proper set of
100 * divisors to use before it can effectively recalc.
101 */
102 if (unlikely(atomic_read(&clk->kref.refcount) == 1))
103 if (clk->ops && clk->ops->init)
104 clk->ops->init(clk);
105 119
106 kref_get(&clk->kref); 120 for (i = 0; freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
121 unsigned long freq = freq_table[i].frequency;
107 122
108 if (clk->flags & CLK_ALWAYS_ENABLED) 123 if (freq == CPUFREQ_ENTRY_INVALID)
109 return 0; 124 continue;
110 125
111 if (likely(clk->ops && clk->ops->enable)) 126 if (freq == rate)
112 clk->ops->enable(clk); 127 return i;
128 }
113 129
114 return 0; 130 return -ENOENT;
115} 131}
116 132
117int clk_enable(struct clk *clk) 133/* Used for clocks that always have same value as the parent clock */
134unsigned long followparent_recalc(struct clk *clk)
118{ 135{
119 unsigned long flags; 136 return clk->parent ? clk->parent->rate : 0;
120 int ret; 137}
121
122 if (!clk)
123 return -EINVAL;
124 138
125 clk_enable(clk->parent); 139int clk_reparent(struct clk *child, struct clk *parent)
140{
141 list_del_init(&child->sibling);
142 if (parent)
143 list_add(&child->sibling, &parent->children);
144 child->parent = parent;
126 145
127 spin_lock_irqsave(&clock_lock, flags); 146 /* now do the debugfs renaming to reattach the child
128 ret = __clk_enable(clk); 147 to the proper parent */
129 spin_unlock_irqrestore(&clock_lock, flags);
130 148
131 return ret; 149 return 0;
132} 150}
133EXPORT_SYMBOL_GPL(clk_enable);
134 151
135static void clk_kref_release(struct kref *kref) 152/* Propagate rate to children */
153void propagate_rate(struct clk *tclk)
136{ 154{
137 /* Nothing to do */ 155 struct clk *clkp;
156
157 list_for_each_entry(clkp, &tclk->children, sibling) {
158 if (clkp->ops && clkp->ops->recalc)
159 clkp->rate = clkp->ops->recalc(clkp);
160
161 propagate_rate(clkp);
162 }
138} 163}
139 164
140static void __clk_disable(struct clk *clk) 165static void __clk_disable(struct clk *clk)
141{ 166{
142 int count = kref_put(&clk->kref, clk_kref_release); 167 if (clk->usecount == 0) {
143 168 printk(KERN_ERR "Trying disable clock %s with 0 usecount\n",
144 if (clk->flags & CLK_ALWAYS_ENABLED) 169 clk->name);
170 WARN_ON(1);
145 return; 171 return;
172 }
146 173
147 if (!count) { /* count reaches zero, disable the clock */ 174 if (!(--clk->usecount)) {
148 if (likely(clk->ops && clk->ops->disable)) 175 if (likely(clk->ops && clk->ops->disable))
149 clk->ops->disable(clk); 176 clk->ops->disable(clk);
177 if (likely(clk->parent))
178 __clk_disable(clk->parent);
150 } 179 }
151} 180}
152 181
@@ -160,28 +189,97 @@ void clk_disable(struct clk *clk)
160 spin_lock_irqsave(&clock_lock, flags); 189 spin_lock_irqsave(&clock_lock, flags);
161 __clk_disable(clk); 190 __clk_disable(clk);
162 spin_unlock_irqrestore(&clock_lock, flags); 191 spin_unlock_irqrestore(&clock_lock, flags);
163
164 clk_disable(clk->parent);
165} 192}
166EXPORT_SYMBOL_GPL(clk_disable); 193EXPORT_SYMBOL_GPL(clk_disable);
167 194
195static int __clk_enable(struct clk *clk)
196{
197 int ret = 0;
198
199 if (clk->usecount++ == 0) {
200 if (clk->parent) {
201 ret = __clk_enable(clk->parent);
202 if (unlikely(ret))
203 goto err;
204 }
205
206 if (clk->ops && clk->ops->enable) {
207 ret = clk->ops->enable(clk);
208 if (ret) {
209 if (clk->parent)
210 __clk_disable(clk->parent);
211 goto err;
212 }
213 }
214 }
215
216 return ret;
217err:
218 clk->usecount--;
219 return ret;
220}
221
222int clk_enable(struct clk *clk)
223{
224 unsigned long flags;
225 int ret;
226
227 if (!clk)
228 return -EINVAL;
229
230 spin_lock_irqsave(&clock_lock, flags);
231 ret = __clk_enable(clk);
232 spin_unlock_irqrestore(&clock_lock, flags);
233
234 return ret;
235}
236EXPORT_SYMBOL_GPL(clk_enable);
237
238static LIST_HEAD(root_clks);
239
240/**
241 * recalculate_root_clocks - recalculate and propagate all root clocks
242 *
243 * Recalculates all root clocks (clocks with no parent), which if the
244 * clock's .recalc is set correctly, should also propagate their rates.
245 * Called at init.
246 */
247void recalculate_root_clocks(void)
248{
249 struct clk *clkp;
250
251 list_for_each_entry(clkp, &root_clks, sibling) {
252 if (clkp->ops && clkp->ops->recalc)
253 clkp->rate = clkp->ops->recalc(clkp);
254 propagate_rate(clkp);
255 }
256}
257
168int clk_register(struct clk *clk) 258int clk_register(struct clk *clk)
169{ 259{
260 if (clk == NULL || IS_ERR(clk))
261 return -EINVAL;
262
263 /*
264 * trap out already registered clocks
265 */
266 if (clk->node.next || clk->node.prev)
267 return 0;
268
170 mutex_lock(&clock_list_sem); 269 mutex_lock(&clock_list_sem);
171 270
172 list_add(&clk->node, &clock_list); 271 INIT_LIST_HEAD(&clk->children);
173 kref_init(&clk->kref); 272 clk->usecount = 0;
174 273
175 mutex_unlock(&clock_list_sem); 274 if (clk->parent)
275 list_add(&clk->sibling, &clk->parent->children);
276 else
277 list_add(&clk->sibling, &root_clks);
176 278
177 if (clk->flags & CLK_ALWAYS_ENABLED) { 279 list_add(&clk->node, &clock_list);
178 pr_debug( "Clock '%s' is ALWAYS_ENABLED\n", clk->name); 280 if (clk->ops && clk->ops->init)
179 if (clk->ops && clk->ops->init) 281 clk->ops->init(clk);
180 clk->ops->init(clk); 282 mutex_unlock(&clock_list_sem);
181 if (clk->ops && clk->ops->enable)
182 clk->ops->enable(clk);
183 pr_debug( "Enabled.");
184 }
185 283
186 return 0; 284 return 0;
187} 285}
@@ -190,11 +288,21 @@ EXPORT_SYMBOL_GPL(clk_register);
190void clk_unregister(struct clk *clk) 288void clk_unregister(struct clk *clk)
191{ 289{
192 mutex_lock(&clock_list_sem); 290 mutex_lock(&clock_list_sem);
291 list_del(&clk->sibling);
193 list_del(&clk->node); 292 list_del(&clk->node);
194 mutex_unlock(&clock_list_sem); 293 mutex_unlock(&clock_list_sem);
195} 294}
196EXPORT_SYMBOL_GPL(clk_unregister); 295EXPORT_SYMBOL_GPL(clk_unregister);
197 296
297static void clk_enable_init_clocks(void)
298{
299 struct clk *clkp;
300
301 list_for_each_entry(clkp, &clock_list, node)
302 if (clkp->flags & CLK_ENABLE_ON_INIT)
303 clk_enable(clkp);
304}
305
198unsigned long clk_get_rate(struct clk *clk) 306unsigned long clk_get_rate(struct clk *clk)
199{ 307{
200 return clk->rate; 308 return clk->rate;
@@ -210,56 +318,59 @@ EXPORT_SYMBOL_GPL(clk_set_rate);
210int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id) 318int clk_set_rate_ex(struct clk *clk, unsigned long rate, int algo_id)
211{ 319{
212 int ret = -EOPNOTSUPP; 320 int ret = -EOPNOTSUPP;
321 unsigned long flags;
213 322
214 if (likely(clk->ops && clk->ops->set_rate)) { 323 spin_lock_irqsave(&clock_lock, flags);
215 unsigned long flags;
216 324
217 spin_lock_irqsave(&clock_lock, flags); 325 if (likely(clk->ops && clk->ops->set_rate)) {
218 ret = clk->ops->set_rate(clk, rate, algo_id); 326 ret = clk->ops->set_rate(clk, rate, algo_id);
219 spin_unlock_irqrestore(&clock_lock, flags); 327 if (ret != 0)
328 goto out_unlock;
329 } else {
330 clk->rate = rate;
331 ret = 0;
220 } 332 }
221 333
222 if (unlikely(clk->flags & CLK_RATE_PROPAGATES)) 334 if (clk->ops && clk->ops->recalc)
223 propagate_rate(clk); 335 clk->rate = clk->ops->recalc(clk);
224 336
225 return ret; 337 propagate_rate(clk);
226}
227EXPORT_SYMBOL_GPL(clk_set_rate_ex);
228 338
229void clk_recalc_rate(struct clk *clk) 339out_unlock:
230{ 340 spin_unlock_irqrestore(&clock_lock, flags);
231 if (likely(clk->ops && clk->ops->recalc)) {
232 unsigned long flags;
233
234 spin_lock_irqsave(&clock_lock, flags);
235 clk->ops->recalc(clk);
236 spin_unlock_irqrestore(&clock_lock, flags);
237 }
238 341
239 if (unlikely(clk->flags & CLK_RATE_PROPAGATES)) 342 return ret;
240 propagate_rate(clk);
241} 343}
242EXPORT_SYMBOL_GPL(clk_recalc_rate); 344EXPORT_SYMBOL_GPL(clk_set_rate_ex);
243 345
244int clk_set_parent(struct clk *clk, struct clk *parent) 346int clk_set_parent(struct clk *clk, struct clk *parent)
245{ 347{
348 unsigned long flags;
246 int ret = -EINVAL; 349 int ret = -EINVAL;
247 struct clk *old;
248 350
249 if (!parent || !clk) 351 if (!parent || !clk)
250 return ret; 352 return ret;
353 if (clk->parent == parent)
354 return 0;
251 355
252 old = clk->parent; 356 spin_lock_irqsave(&clock_lock, flags);
253 if (likely(clk->ops && clk->ops->set_parent)) { 357 if (clk->usecount == 0) {
254 unsigned long flags; 358 if (clk->ops->set_parent)
255 spin_lock_irqsave(&clock_lock, flags); 359 ret = clk->ops->set_parent(clk, parent);
256 ret = clk->ops->set_parent(clk, parent); 360 else
257 spin_unlock_irqrestore(&clock_lock, flags); 361 ret = clk_reparent(clk, parent);
258 clk->parent = (ret ? old : parent); 362
259 } 363 if (ret == 0) {
364 pr_debug("clock: set parent of %s to %s (new rate %ld)\n",
365 clk->name, clk->parent->name, clk->rate);
366 if (clk->ops->recalc)
367 clk->rate = clk->ops->recalc(clk);
368 propagate_rate(clk);
369 }
370 } else
371 ret = -EBUSY;
372 spin_unlock_irqrestore(&clock_lock, flags);
260 373
261 if (unlikely(clk->flags & CLK_RATE_PROPAGATES))
262 propagate_rate(clk);
263 return ret; 374 return ret;
264} 375}
265EXPORT_SYMBOL_GPL(clk_set_parent); 376EXPORT_SYMBOL_GPL(clk_set_parent);
@@ -287,14 +398,69 @@ long clk_round_rate(struct clk *clk, unsigned long rate)
287EXPORT_SYMBOL_GPL(clk_round_rate); 398EXPORT_SYMBOL_GPL(clk_round_rate);
288 399
289/* 400/*
401 * Find the correct struct clk for the device and connection ID.
402 * We do slightly fuzzy matching here:
403 * An entry with a NULL ID is assumed to be a wildcard.
404 * If an entry has a device ID, it must match
405 * If an entry has a connection ID, it must match
406 * Then we take the most specific entry - with the following
407 * order of precidence: dev+con > dev only > con only.
408 */
409static struct clk *clk_find(const char *dev_id, const char *con_id)
410{
411 struct clk_lookup *p;
412 struct clk *clk = NULL;
413 int match, best = 0;
414
415 list_for_each_entry(p, &clock_list, node) {
416 match = 0;
417 if (p->dev_id) {
418 if (!dev_id || strcmp(p->dev_id, dev_id))
419 continue;
420 match += 2;
421 }
422 if (p->con_id) {
423 if (!con_id || strcmp(p->con_id, con_id))
424 continue;
425 match += 1;
426 }
427 if (match == 0)
428 continue;
429
430 if (match > best) {
431 clk = p->clk;
432 best = match;
433 }
434 }
435 return clk;
436}
437
438struct clk *clk_get_sys(const char *dev_id, const char *con_id)
439{
440 struct clk *clk;
441
442 mutex_lock(&clock_list_sem);
443 clk = clk_find(dev_id, con_id);
444 mutex_unlock(&clock_list_sem);
445
446 return clk ? clk : ERR_PTR(-ENOENT);
447}
448EXPORT_SYMBOL_GPL(clk_get_sys);
449
450/*
290 * Returns a clock. Note that we first try to use device id on the bus 451 * Returns a clock. Note that we first try to use device id on the bus
291 * and clock name. If this fails, we try to use clock name only. 452 * and clock name. If this fails, we try to use clock name only.
292 */ 453 */
293struct clk *clk_get(struct device *dev, const char *id) 454struct clk *clk_get(struct device *dev, const char *id)
294{ 455{
456 const char *dev_id = dev ? dev_name(dev) : NULL;
295 struct clk *p, *clk = ERR_PTR(-ENOENT); 457 struct clk *p, *clk = ERR_PTR(-ENOENT);
296 int idno; 458 int idno;
297 459
460 clk = clk_get_sys(dev_id, id);
461 if (clk && !IS_ERR(clk))
462 return clk;
463
298 if (dev == NULL || dev->bus != &platform_bus_type) 464 if (dev == NULL || dev->bus != &platform_bus_type)
299 idno = -1; 465 idno = -1;
300 else 466 else
@@ -330,36 +496,6 @@ void clk_put(struct clk *clk)
330} 496}
331EXPORT_SYMBOL_GPL(clk_put); 497EXPORT_SYMBOL_GPL(clk_put);
332 498
333void __init __attribute__ ((weak))
334arch_init_clk_ops(struct clk_ops **ops, int type)
335{
336}
337
338int __init __attribute__ ((weak))
339arch_clk_init(void)
340{
341 return 0;
342}
343
344static int show_clocks(char *buf, char **start, off_t off,
345 int len, int *eof, void *data)
346{
347 struct clk *clk;
348 char *p = buf;
349
350 list_for_each_entry_reverse(clk, &clock_list, node) {
351 unsigned long rate = clk_get_rate(clk);
352
353 p += sprintf(p, "%-12s\t: %ld.%02ldMHz\t%s\n", clk->name,
354 rate / 1000000, (rate % 1000000) / 10000,
355 ((clk->flags & CLK_ALWAYS_ENABLED) ||
356 (atomic_read(&clk->kref.refcount) != 1)) ?
357 "enabled" : "disabled");
358 }
359
360 return p - buf;
361}
362
363#ifdef CONFIG_PM 499#ifdef CONFIG_PM
364static int clks_sysdev_suspend(struct sys_device *dev, pm_message_t state) 500static int clks_sysdev_suspend(struct sys_device *dev, pm_message_t state)
365{ 501{
@@ -369,20 +505,22 @@ static int clks_sysdev_suspend(struct sys_device *dev, pm_message_t state)
369 switch (state.event) { 505 switch (state.event) {
370 case PM_EVENT_ON: 506 case PM_EVENT_ON:
371 /* Resumeing from hibernation */ 507 /* Resumeing from hibernation */
372 if (prev_state.event == PM_EVENT_FREEZE) { 508 if (prev_state.event != PM_EVENT_FREEZE)
373 list_for_each_entry(clkp, &clock_list, node) 509 break;
374 if (likely(clkp->ops)) { 510
375 unsigned long rate = clkp->rate; 511 list_for_each_entry(clkp, &clock_list, node) {
376 512 if (likely(clkp->ops)) {
377 if (likely(clkp->ops->set_parent)) 513 unsigned long rate = clkp->rate;
378 clkp->ops->set_parent(clkp, 514
379 clkp->parent); 515 if (likely(clkp->ops->set_parent))
380 if (likely(clkp->ops->set_rate)) 516 clkp->ops->set_parent(clkp,
381 clkp->ops->set_rate(clkp, 517 clkp->parent);
382 rate, NO_CHANGE); 518 if (likely(clkp->ops->set_rate))
383 else if (likely(clkp->ops->recalc)) 519 clkp->ops->set_rate(clkp,
384 clkp->ops->recalc(clkp); 520 rate, NO_CHANGE);
385 } 521 else if (likely(clkp->ops->recalc))
522 clkp->rate = clkp->ops->recalc(clkp);
523 }
386 } 524 }
387 break; 525 break;
388 case PM_EVENT_FREEZE: 526 case PM_EVENT_FREEZE:
@@ -426,34 +564,116 @@ subsys_initcall(clk_sysdev_init);
426 564
427int __init clk_init(void) 565int __init clk_init(void)
428{ 566{
429 int i, ret = 0; 567 int ret;
430
431 BUG_ON(!master_clk.rate);
432
433 for (i = 0; i < ARRAY_SIZE(onchip_clocks); i++) {
434 struct clk *clk = onchip_clocks[i];
435 568
436 arch_init_clk_ops(&clk->ops, i); 569 ret = arch_clk_init();
437 ret |= clk_register(clk); 570 if (unlikely(ret)) {
571 pr_err("%s: CPU clock registration failed.\n", __func__);
572 return ret;
438 } 573 }
439 574
440 ret |= arch_clk_init(); 575 if (sh_mv.mv_clk_init) {
576 ret = sh_mv.mv_clk_init();
577 if (unlikely(ret)) {
578 pr_err("%s: machvec clock initialization failed.\n",
579 __func__);
580 return ret;
581 }
582 }
441 583
442 /* Kick the child clocks.. */ 584 /* Kick the child clocks.. */
443 propagate_rate(&master_clk); 585 recalculate_root_clocks();
444 propagate_rate(&bus_clk); 586
587 /* Enable the necessary init clocks */
588 clk_enable_init_clocks();
445 589
446 return ret; 590 return ret;
447} 591}
448 592
449static int __init clk_proc_init(void) 593/*
594 * debugfs support to trace clock tree hierarchy and attributes
595 */
596static struct dentry *clk_debugfs_root;
597
598static int clk_debugfs_register_one(struct clk *c)
450{ 599{
451 struct proc_dir_entry *p; 600 int err;
452 p = create_proc_read_entry("clocks", S_IRUSR, NULL, 601 struct dentry *d, *child;
453 show_clocks, NULL); 602 struct clk *pa = c->parent;
454 if (unlikely(!p)) 603 char s[255];
455 return -EINVAL; 604 char *p = s;
605
606 p += sprintf(p, "%s", c->name);
607 if (c->id >= 0)
608 sprintf(p, ":%d", c->id);
609 d = debugfs_create_dir(s, pa ? pa->dentry : clk_debugfs_root);
610 if (!d)
611 return -ENOMEM;
612 c->dentry = d;
613
614 d = debugfs_create_u8("usecount", S_IRUGO, c->dentry, (u8 *)&c->usecount);
615 if (!d) {
616 err = -ENOMEM;
617 goto err_out;
618 }
619 d = debugfs_create_u32("rate", S_IRUGO, c->dentry, (u32 *)&c->rate);
620 if (!d) {
621 err = -ENOMEM;
622 goto err_out;
623 }
624 d = debugfs_create_x32("flags", S_IRUGO, c->dentry, (u32 *)&c->flags);
625 if (!d) {
626 err = -ENOMEM;
627 goto err_out;
628 }
629 return 0;
456 630
631err_out:
632 d = c->dentry;
633 list_for_each_entry(child, &d->d_subdirs, d_u.d_child)
634 debugfs_remove(child);
635 debugfs_remove(c->dentry);
636 return err;
637}
638
639static int clk_debugfs_register(struct clk *c)
640{
641 int err;
642 struct clk *pa = c->parent;
643
644 if (pa && !pa->dentry) {
645 err = clk_debugfs_register(pa);
646 if (err)
647 return err;
648 }
649
650 if (!c->dentry) {
651 err = clk_debugfs_register_one(c);
652 if (err)
653 return err;
654 }
655 return 0;
656}
657
658static int __init clk_debugfs_init(void)
659{
660 struct clk *c;
661 struct dentry *d;
662 int err;
663
664 d = debugfs_create_dir("clock", NULL);
665 if (!d)
666 return -ENOMEM;
667 clk_debugfs_root = d;
668
669 list_for_each_entry(c, &clock_list, node) {
670 err = clk_debugfs_register(c);
671 if (err)
672 goto err_out;
673 }
457 return 0; 674 return 0;
675err_out:
676 debugfs_remove(clk_debugfs_root); /* REVISIT: Cleanup correctly */
677 return err;
458} 678}
459subsys_initcall(clk_proc_init); 679late_initcall(clk_debugfs_init);
diff --git a/arch/sh/kernel/cpu/init.c b/arch/sh/kernel/cpu/init.c
index d29e69c156f0..ad85421099cd 100644
--- a/arch/sh/kernel/cpu/init.c
+++ b/arch/sh/kernel/cpu/init.c
@@ -62,6 +62,11 @@ static void __init speculative_execution_init(void)
62#define speculative_execution_init() do { } while (0) 62#define speculative_execution_init() do { } while (0)
63#endif 63#endif
64 64
65/* 2nd-level cache init */
66void __uses_jump_to_uncached __attribute__ ((weak)) l2_cache_init(void)
67{
68}
69
65/* 70/*
66 * Generic first-level cache init 71 * Generic first-level cache init
67 */ 72 */
@@ -146,6 +151,8 @@ static void __uses_jump_to_uncached cache_init(void)
146 flags &= ~CCR_CACHE_ENABLE; 151 flags &= ~CCR_CACHE_ENABLE;
147#endif 152#endif
148 153
154 l2_cache_init();
155
149 ctrl_outl(flags, CCR); 156 ctrl_outl(flags, CCR);
150 back_to_cached(); 157 back_to_cached();
151} 158}
diff --git a/arch/sh/kernel/cpu/irq/imask.c b/arch/sh/kernel/cpu/irq/imask.c
index 301b505c4278..6b5d191eec3a 100644
--- a/arch/sh/kernel/cpu/irq/imask.c
+++ b/arch/sh/kernel/cpu/irq/imask.c
@@ -18,38 +18,17 @@
18#include <linux/spinlock.h> 18#include <linux/spinlock.h>
19#include <linux/cache.h> 19#include <linux/cache.h>
20#include <linux/irq.h> 20#include <linux/irq.h>
21#include <linux/bitmap.h>
21#include <asm/system.h> 22#include <asm/system.h>
22#include <asm/irq.h> 23#include <asm/irq.h>
23 24
24/* Bitmap of IRQ masked */ 25/* Bitmap of IRQ masked */
25static unsigned long imask_mask = 0x7fff;
26static int interrupt_priority = 0;
27
28static void enable_imask_irq(unsigned int irq);
29static void disable_imask_irq(unsigned int irq);
30static void shutdown_imask_irq(unsigned int irq);
31static void mask_and_ack_imask(unsigned int);
32static void end_imask_irq(unsigned int irq);
33
34#define IMASK_PRIORITY 15 26#define IMASK_PRIORITY 15
35 27
36static unsigned int startup_imask_irq(unsigned int irq) 28static DECLARE_BITMAP(imask_mask, IMASK_PRIORITY);
37{ 29static int interrupt_priority;
38 /* Nothing to do */
39 return 0; /* never anything pending */
40}
41 30
42static struct hw_interrupt_type imask_irq_type = { 31static inline void set_interrupt_registers(int ip)
43 .typename = "SR.IMASK",
44 .startup = startup_imask_irq,
45 .shutdown = shutdown_imask_irq,
46 .enable = enable_imask_irq,
47 .disable = disable_imask_irq,
48 .ack = mask_and_ack_imask,
49 .end = end_imask_irq
50};
51
52void static inline set_interrupt_registers(int ip)
53{ 32{
54 unsigned long __dummy; 33 unsigned long __dummy;
55 34
@@ -72,42 +51,31 @@ void static inline set_interrupt_registers(int ip)
72 : "t"); 51 : "t");
73} 52}
74 53
75static void disable_imask_irq(unsigned int irq) 54static void mask_imask_irq(unsigned int irq)
76{ 55{
77 clear_bit(irq, &imask_mask); 56 clear_bit(irq, imask_mask);
78 if (interrupt_priority < IMASK_PRIORITY - irq) 57 if (interrupt_priority < IMASK_PRIORITY - irq)
79 interrupt_priority = IMASK_PRIORITY - irq; 58 interrupt_priority = IMASK_PRIORITY - irq;
80
81 set_interrupt_registers(interrupt_priority); 59 set_interrupt_registers(interrupt_priority);
82} 60}
83 61
84static void enable_imask_irq(unsigned int irq) 62static void unmask_imask_irq(unsigned int irq)
85{ 63{
86 set_bit(irq, &imask_mask); 64 set_bit(irq, imask_mask);
87 interrupt_priority = IMASK_PRIORITY - ffz(imask_mask); 65 interrupt_priority = IMASK_PRIORITY -
88 66 find_first_zero_bit(imask_mask, IMASK_PRIORITY);
89 set_interrupt_registers(interrupt_priority); 67 set_interrupt_registers(interrupt_priority);
90} 68}
91 69
92static void mask_and_ack_imask(unsigned int irq) 70static struct irq_chip imask_irq_chip = {
93{ 71 .typename = "SR.IMASK",
94 disable_imask_irq(irq); 72 .mask = mask_imask_irq,
95} 73 .unmask = unmask_imask_irq,
96 74 .mask_ack = mask_imask_irq,
97static void end_imask_irq(unsigned int irq) 75};
98{
99 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
100 enable_imask_irq(irq);
101}
102
103static void shutdown_imask_irq(unsigned int irq)
104{
105 /* Nothing to do */
106}
107 76
108void make_imask_irq(unsigned int irq) 77void make_imask_irq(unsigned int irq)
109{ 78{
110 disable_irq_nosync(irq); 79 set_irq_chip_and_handler_name(irq, &imask_irq_chip,
111 irq_desc[irq].chip = &imask_irq_type; 80 handle_level_irq, "level");
112 enable_irq(irq);
113} 81}
diff --git a/arch/sh/kernel/cpu/irq/intc-sh5.c b/arch/sh/kernel/cpu/irq/intc-sh5.c
index 726f0335da76..6c092f1f5557 100644
--- a/arch/sh/kernel/cpu/irq/intc-sh5.c
+++ b/arch/sh/kernel/cpu/irq/intc-sh5.c
@@ -84,7 +84,7 @@ static void disable_intc_irq(unsigned int irq);
84static void mask_and_ack_intc(unsigned int); 84static void mask_and_ack_intc(unsigned int);
85static void end_intc_irq(unsigned int irq); 85static void end_intc_irq(unsigned int irq);
86 86
87static struct hw_interrupt_type intc_irq_type = { 87static struct irq_chip intc_irq_type = {
88 .typename = "INTC", 88 .typename = "INTC",
89 .startup = startup_intc_irq, 89 .startup = startup_intc_irq,
90 .shutdown = shutdown_intc_irq, 90 .shutdown = shutdown_intc_irq,
@@ -152,43 +152,13 @@ static void end_intc_irq(unsigned int irq)
152 enable_intc_irq(irq); 152 enable_intc_irq(irq);
153} 153}
154 154
155/* For future use, if we ever support IRLM=0) */
156void make_intc_irq(unsigned int irq)
157{
158 disable_irq_nosync(irq);
159 irq_desc[irq].chip = &intc_irq_type;
160 disable_intc_irq(irq);
161}
162
163#if defined(CONFIG_PROC_FS) && defined(CONFIG_SYSCTL)
164static int IRQ_to_vectorN[NR_INTC_IRQS] = {
165 0x12, 0x15, 0x18, 0x1B, 0x40, 0x41, 0x42, 0x43, /* 0- 7 */
166 -1, -1, -1, -1, 0x50, 0x51, 0x52, 0x53, /* 8-15 */
167 0x54, 0x55, 0x32, 0x33, 0x34, 0x35, 0x36, -1, /* 16-23 */
168 -1, -1, -1, -1, -1, -1, -1, -1, /* 24-31 */
169 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x38, /* 32-39 */
170 0x39, 0x3A, 0x3B, -1, -1, -1, -1, -1, /* 40-47 */
171 -1, -1, -1, -1, -1, -1, -1, -1, /* 48-55 */
172 -1, -1, -1, -1, -1, -1, -1, 0x2B, /* 56-63 */
173
174};
175
176int intc_irq_describe(char* p, int irq)
177{
178 if (irq < NR_INTC_IRQS)
179 return sprintf(p, "(0x%3x)", IRQ_to_vectorN[irq]*0x20);
180 else
181 return 0;
182}
183#endif
184
185void __init plat_irq_setup(void) 155void __init plat_irq_setup(void)
186{ 156{
187 unsigned long long __dummy0, __dummy1=~0x00000000100000f0; 157 unsigned long long __dummy0, __dummy1=~0x00000000100000f0;
188 unsigned long reg; 158 unsigned long reg;
189 int i; 159 int i;
190 160
191 intc_virt = onchip_remap(INTC_BASE, 1024, "INTC"); 161 intc_virt = (unsigned long)ioremap_nocache(INTC_BASE, 1024);
192 if (!intc_virt) { 162 if (!intc_virt) {
193 panic("Unable to remap INTC\n"); 163 panic("Unable to remap INTC\n");
194 } 164 }
@@ -196,7 +166,7 @@ void __init plat_irq_setup(void)
196 166
197 /* Set default: per-line enable/disable, priority driven ack/eoi */ 167 /* Set default: per-line enable/disable, priority driven ack/eoi */
198 for (i = 0; i < NR_INTC_IRQS; i++) 168 for (i = 0; i < NR_INTC_IRQS; i++)
199 irq_desc[i].chip = &intc_irq_type; 169 set_irq_chip_and_handler(i, &intc_irq_type, handle_level_irq);
200 170
201 171
202 /* Disable all interrupts and set all priorities to 0 to avoid trouble */ 172 /* Disable all interrupts and set all priorities to 0 to avoid trouble */
diff --git a/arch/sh/kernel/cpu/irq/ipr.c b/arch/sh/kernel/cpu/irq/ipr.c
index 3eb17ee5540e..808d99a48efb 100644
--- a/arch/sh/kernel/cpu/irq/ipr.c
+++ b/arch/sh/kernel/cpu/irq/ipr.c
@@ -21,6 +21,7 @@
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/topology.h>
24 25
25static inline struct ipr_desc *get_ipr_desc(unsigned int irq) 26static inline struct ipr_desc *get_ipr_desc(unsigned int irq)
26{ 27{
@@ -59,10 +60,18 @@ void register_ipr_controller(struct ipr_desc *desc)
59 60
60 for (i = 0; i < desc->nr_irqs; i++) { 61 for (i = 0; i < desc->nr_irqs; i++) {
61 struct ipr_data *p = desc->ipr_data + i; 62 struct ipr_data *p = desc->ipr_data + i;
63 struct irq_desc *irq_desc;
62 64
63 BUG_ON(p->ipr_idx >= desc->nr_offsets); 65 BUG_ON(p->ipr_idx >= desc->nr_offsets);
64 BUG_ON(!desc->ipr_offsets[p->ipr_idx]); 66 BUG_ON(!desc->ipr_offsets[p->ipr_idx]);
65 67
68 irq_desc = irq_to_desc_alloc_node(p->irq, numa_node_id());
69 if (unlikely(!irq_desc)) {
70 printk(KERN_INFO "can not get irq_desc for %d\n",
71 p->irq);
72 continue;
73 }
74
66 disable_irq_nosync(p->irq); 75 disable_irq_nosync(p->irq);
67 set_irq_chip_and_handler_name(p->irq, &desc->chip, 76 set_irq_chip_and_handler_name(p->irq, &desc->chip,
68 handle_level_irq, "level"); 77 handle_level_irq, "level");
diff --git a/arch/sh/kernel/cpu/sh2/clock-sh7619.c b/arch/sh/kernel/cpu/sh2/clock-sh7619.c
index d2c157917999..4fe863170e31 100644
--- a/arch/sh/kernel/cpu/sh2/clock-sh7619.c
+++ b/arch/sh/kernel/cpu/sh2/clock-sh7619.c
@@ -38,32 +38,27 @@ static struct clk_ops sh7619_master_clk_ops = {
38 .init = master_clk_init, 38 .init = master_clk_init,
39}; 39};
40 40
41static void module_clk_recalc(struct clk *clk) 41static unsigned long module_clk_recalc(struct clk *clk)
42{ 42{
43 int idx = (ctrl_inw(FREQCR) & 0x0007); 43 int idx = (ctrl_inw(FREQCR) & 0x0007);
44 clk->rate = clk->parent->rate / pfc_divisors[idx]; 44 return clk->parent->rate / pfc_divisors[idx];
45} 45}
46 46
47static struct clk_ops sh7619_module_clk_ops = { 47static struct clk_ops sh7619_module_clk_ops = {
48 .recalc = module_clk_recalc, 48 .recalc = module_clk_recalc,
49}; 49};
50 50
51static void bus_clk_recalc(struct clk *clk) 51static unsigned long bus_clk_recalc(struct clk *clk)
52{ 52{
53 clk->rate = clk->parent->rate / pll1rate[(ctrl_inw(FREQCR) >> 8) & 7]; 53 return clk->parent->rate / pll1rate[(ctrl_inw(FREQCR) >> 8) & 7];
54} 54}
55 55
56static struct clk_ops sh7619_bus_clk_ops = { 56static struct clk_ops sh7619_bus_clk_ops = {
57 .recalc = bus_clk_recalc, 57 .recalc = bus_clk_recalc,
58}; 58};
59 59
60static void cpu_clk_recalc(struct clk *clk)
61{
62 clk->rate = clk->parent->rate;
63}
64
65static struct clk_ops sh7619_cpu_clk_ops = { 60static struct clk_ops sh7619_cpu_clk_ops = {
66 .recalc = cpu_clk_recalc, 61 .recalc = followparent_recalc,
67}; 62};
68 63
69static struct clk_ops *sh7619_clk_ops[] = { 64static struct clk_ops *sh7619_clk_ops[] = {
@@ -78,4 +73,3 @@ void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
78 if (idx < ARRAY_SIZE(sh7619_clk_ops)) 73 if (idx < ARRAY_SIZE(sh7619_clk_ops))
79 *ops = sh7619_clk_ops[idx]; 74 *ops = sh7619_clk_ops[idx];
80} 75}
81
diff --git a/arch/sh/kernel/cpu/sh2/setup-sh7619.c b/arch/sh/kernel/cpu/sh2/setup-sh7619.c
index 0e32d8e448ca..13798733f2db 100644
--- a/arch/sh/kernel/cpu/sh2/setup-sh7619.c
+++ b/arch/sh/kernel/cpu/sh2/setup-sh7619.c
@@ -12,6 +12,8 @@
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/serial.h> 13#include <linux/serial.h>
14#include <linux/serial_sci.h> 14#include <linux/serial_sci.h>
15#include <linux/sh_timer.h>
16#include <linux/io.h>
15 17
16enum { 18enum {
17 UNUSED = 0, 19 UNUSED = 0,
@@ -109,9 +111,75 @@ static struct platform_device eth_device = {
109 .resource = eth_resources, 111 .resource = eth_resources,
110}; 112};
111 113
114static struct sh_timer_config cmt0_platform_data = {
115 .name = "CMT0",
116 .channel_offset = 0x02,
117 .timer_bit = 0,
118 .clk = "peripheral_clk",
119 .clockevent_rating = 125,
120 .clocksource_rating = 0, /* disabled due to code generation issues */
121};
122
123static struct resource cmt0_resources[] = {
124 [0] = {
125 .name = "CMT0",
126 .start = 0xf84a0072,
127 .end = 0xf84a0077,
128 .flags = IORESOURCE_MEM,
129 },
130 [1] = {
131 .start = 86,
132 .flags = IORESOURCE_IRQ,
133 },
134};
135
136static struct platform_device cmt0_device = {
137 .name = "sh_cmt",
138 .id = 0,
139 .dev = {
140 .platform_data = &cmt0_platform_data,
141 },
142 .resource = cmt0_resources,
143 .num_resources = ARRAY_SIZE(cmt0_resources),
144};
145
146static struct sh_timer_config cmt1_platform_data = {
147 .name = "CMT1",
148 .channel_offset = 0x08,
149 .timer_bit = 1,
150 .clk = "peripheral_clk",
151 .clockevent_rating = 125,
152 .clocksource_rating = 0, /* disabled due to code generation issues */
153};
154
155static struct resource cmt1_resources[] = {
156 [0] = {
157 .name = "CMT1",
158 .start = 0xf84a0078,
159 .end = 0xf84a007d,
160 .flags = IORESOURCE_MEM,
161 },
162 [1] = {
163 .start = 87,
164 .flags = IORESOURCE_IRQ,
165 },
166};
167
168static struct platform_device cmt1_device = {
169 .name = "sh_cmt",
170 .id = 1,
171 .dev = {
172 .platform_data = &cmt1_platform_data,
173 },
174 .resource = cmt1_resources,
175 .num_resources = ARRAY_SIZE(cmt1_resources),
176};
177
112static struct platform_device *sh7619_devices[] __initdata = { 178static struct platform_device *sh7619_devices[] __initdata = {
113 &sci_device, 179 &sci_device,
114 &eth_device, 180 &eth_device,
181 &cmt0_device,
182 &cmt1_device,
115}; 183};
116 184
117static int __init sh7619_devices_setup(void) 185static int __init sh7619_devices_setup(void)
@@ -125,3 +193,19 @@ void __init plat_irq_setup(void)
125{ 193{
126 register_intc_controller(&intc_desc); 194 register_intc_controller(&intc_desc);
127} 195}
196
197static struct platform_device *sh7619_early_devices[] __initdata = {
198 &cmt0_device,
199 &cmt1_device,
200};
201
202#define STBCR3 0xf80a0000
203
204void __init plat_early_device_setup(void)
205{
206 /* enable CMT clock */
207 __raw_writeb(__raw_readb(STBCR3) & ~0x10, STBCR3);
208
209 early_platform_add_devices(sh7619_early_devices,
210 ARRAY_SIZE(sh7619_early_devices));
211}
diff --git a/arch/sh/kernel/cpu/sh2a/clock-sh7201.c b/arch/sh/kernel/cpu/sh2a/clock-sh7201.c
index 4a5e59732334..7814c76159a7 100644
--- a/arch/sh/kernel/cpu/sh2a/clock-sh7201.c
+++ b/arch/sh/kernel/cpu/sh2a/clock-sh7201.c
@@ -34,37 +34,37 @@ static const int pfc_divisors[]={1,2,3,4,6,8,12};
34 34
35static void master_clk_init(struct clk *clk) 35static void master_clk_init(struct clk *clk)
36{ 36{
37 clk->rate = 10000000 * PLL2 * pll1rate[(ctrl_inw(FREQCR) >> 8) & 0x0007]; 37 return 10000000 * PLL2 * pll1rate[(ctrl_inw(FREQCR) >> 8) & 0x0007];
38} 38}
39 39
40static struct clk_ops sh7201_master_clk_ops = { 40static struct clk_ops sh7201_master_clk_ops = {
41 .init = master_clk_init, 41 .init = master_clk_init,
42}; 42};
43 43
44static void module_clk_recalc(struct clk *clk) 44static unsigned long module_clk_recalc(struct clk *clk)
45{ 45{
46 int idx = (ctrl_inw(FREQCR) & 0x0007); 46 int idx = (ctrl_inw(FREQCR) & 0x0007);
47 clk->rate = clk->parent->rate / pfc_divisors[idx]; 47 return clk->parent->rate / pfc_divisors[idx];
48} 48}
49 49
50static struct clk_ops sh7201_module_clk_ops = { 50static struct clk_ops sh7201_module_clk_ops = {
51 .recalc = module_clk_recalc, 51 .recalc = module_clk_recalc,
52}; 52};
53 53
54static void bus_clk_recalc(struct clk *clk) 54static unsigned long bus_clk_recalc(struct clk *clk)
55{ 55{
56 int idx = (ctrl_inw(FREQCR) & 0x0007); 56 int idx = (ctrl_inw(FREQCR) & 0x0007);
57 clk->rate = clk->parent->rate / pfc_divisors[idx]; 57 return clk->parent->rate / pfc_divisors[idx];
58} 58}
59 59
60static struct clk_ops sh7201_bus_clk_ops = { 60static struct clk_ops sh7201_bus_clk_ops = {
61 .recalc = bus_clk_recalc, 61 .recalc = bus_clk_recalc,
62}; 62};
63 63
64static void cpu_clk_recalc(struct clk *clk) 64static unsigned long cpu_clk_recalc(struct clk *clk)
65{ 65{
66 int idx = ((ctrl_inw(FREQCR) >> 4) & 0x0007); 66 int idx = ((ctrl_inw(FREQCR) >> 4) & 0x0007);
67 clk->rate = clk->parent->rate / ifc_divisors[idx]; 67 return clk->parent->rate / ifc_divisors[idx];
68} 68}
69 69
70static struct clk_ops sh7201_cpu_clk_ops = { 70static struct clk_ops sh7201_cpu_clk_ops = {
diff --git a/arch/sh/kernel/cpu/sh2a/clock-sh7203.c b/arch/sh/kernel/cpu/sh2a/clock-sh7203.c
index fb781329848a..940986965102 100644
--- a/arch/sh/kernel/cpu/sh2a/clock-sh7203.c
+++ b/arch/sh/kernel/cpu/sh2a/clock-sh7203.c
@@ -46,33 +46,28 @@ static struct clk_ops sh7203_master_clk_ops = {
46 .init = master_clk_init, 46 .init = master_clk_init,
47}; 47};
48 48
49static void module_clk_recalc(struct clk *clk) 49static unsigned long module_clk_recalc(struct clk *clk)
50{ 50{
51 int idx = (ctrl_inw(FREQCR) & 0x0007); 51 int idx = (ctrl_inw(FREQCR) & 0x0007);
52 clk->rate = clk->parent->rate / pfc_divisors[idx]; 52 return clk->parent->rate / pfc_divisors[idx];
53} 53}
54 54
55static struct clk_ops sh7203_module_clk_ops = { 55static struct clk_ops sh7203_module_clk_ops = {
56 .recalc = module_clk_recalc, 56 .recalc = module_clk_recalc,
57}; 57};
58 58
59static void bus_clk_recalc(struct clk *clk) 59static unsigned long bus_clk_recalc(struct clk *clk)
60{ 60{
61 int idx = (ctrl_inw(FREQCR) & 0x0007); 61 int idx = (ctrl_inw(FREQCR) & 0x0007);
62 clk->rate = clk->parent->rate / pfc_divisors[idx-2]; 62 return clk->parent->rate / pfc_divisors[idx-2];
63} 63}
64 64
65static struct clk_ops sh7203_bus_clk_ops = { 65static struct clk_ops sh7203_bus_clk_ops = {
66 .recalc = bus_clk_recalc, 66 .recalc = bus_clk_recalc,
67}; 67};
68 68
69static void cpu_clk_recalc(struct clk *clk)
70{
71 clk->rate = clk->parent->rate;
72}
73
74static struct clk_ops sh7203_cpu_clk_ops = { 69static struct clk_ops sh7203_cpu_clk_ops = {
75 .recalc = cpu_clk_recalc, 70 .recalc = followparent_recalc,
76}; 71};
77 72
78static struct clk_ops *sh7203_clk_ops[] = { 73static struct clk_ops *sh7203_clk_ops[] = {
diff --git a/arch/sh/kernel/cpu/sh2a/clock-sh7206.c b/arch/sh/kernel/cpu/sh2a/clock-sh7206.c
index 82d7f991ef6b..c2268bdeceeb 100644
--- a/arch/sh/kernel/cpu/sh2a/clock-sh7206.c
+++ b/arch/sh/kernel/cpu/sh2a/clock-sh7206.c
@@ -41,29 +41,29 @@ static struct clk_ops sh7206_master_clk_ops = {
41 .init = master_clk_init, 41 .init = master_clk_init,
42}; 42};
43 43
44static void module_clk_recalc(struct clk *clk) 44static unsigned long module_clk_recalc(struct clk *clk)
45{ 45{
46 int idx = (ctrl_inw(FREQCR) & 0x0007); 46 int idx = (ctrl_inw(FREQCR) & 0x0007);
47 clk->rate = clk->parent->rate / pfc_divisors[idx]; 47 return clk->parent->rate / pfc_divisors[idx];
48} 48}
49 49
50static struct clk_ops sh7206_module_clk_ops = { 50static struct clk_ops sh7206_module_clk_ops = {
51 .recalc = module_clk_recalc, 51 .recalc = module_clk_recalc,
52}; 52};
53 53
54static void bus_clk_recalc(struct clk *clk) 54static unsigned long bus_clk_recalc(struct clk *clk)
55{ 55{
56 clk->rate = clk->parent->rate / pll1rate[(ctrl_inw(FREQCR) >> 8) & 0x0007]; 56 return clk->parent->rate / pll1rate[(ctrl_inw(FREQCR) >> 8) & 0x0007];
57} 57}
58 58
59static struct clk_ops sh7206_bus_clk_ops = { 59static struct clk_ops sh7206_bus_clk_ops = {
60 .recalc = bus_clk_recalc, 60 .recalc = bus_clk_recalc,
61}; 61};
62 62
63static void cpu_clk_recalc(struct clk *clk) 63static unsigned long cpu_clk_recalc(struct clk *clk)
64{ 64{
65 int idx = (ctrl_inw(FREQCR) & 0x0007); 65 int idx = (ctrl_inw(FREQCR) & 0x0007);
66 clk->rate = clk->parent->rate / ifc_divisors[idx]; 66 return clk->parent->rate / ifc_divisors[idx];
67} 67}
68 68
69static struct clk_ops sh7206_cpu_clk_ops = { 69static struct clk_ops sh7206_cpu_clk_ops = {
diff --git a/arch/sh/kernel/cpu/sh2a/setup-mxg.c b/arch/sh/kernel/cpu/sh2a/setup-mxg.c
index 844293723cfc..869c2da4820b 100644
--- a/arch/sh/kernel/cpu/sh2a/setup-mxg.c
+++ b/arch/sh/kernel/cpu/sh2a/setup-mxg.c
@@ -11,6 +11,7 @@
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/serial.h> 12#include <linux/serial.h>
13#include <linux/serial_sci.h> 13#include <linux/serial_sci.h>
14#include <linux/sh_timer.h>
14 15
15enum { 16enum {
16 UNUSED = 0, 17 UNUSED = 0,
@@ -24,7 +25,7 @@ enum {
24 25
25 SCIF0, SCIF1, 26 SCIF0, SCIF1,
26 27
27 MTU2_GROUP1, MTU2_GROUP2, MTU2_GROUP3, MTU2_GROUP4, MTU2_GROUP5 28 MTU2_GROUP1, MTU2_GROUP2, MTU2_GROUP3, MTU2_GROUP4, MTU2_GROUP5,
28 MTU2_TGI3B, MTU2_TGI3C, 29 MTU2_TGI3B, MTU2_TGI3C,
29 30
30 /* interrupt groups */ 31 /* interrupt groups */
@@ -113,6 +114,99 @@ static struct intc_mask_reg mask_registers[] __initdata = {
113static DECLARE_INTC_DESC(intc_desc, "mxg", vectors, groups, 114static DECLARE_INTC_DESC(intc_desc, "mxg", vectors, groups,
114 mask_registers, prio_registers, NULL); 115 mask_registers, prio_registers, NULL);
115 116
117static struct sh_timer_config mtu2_0_platform_data = {
118 .name = "MTU2_0",
119 .channel_offset = -0x80,
120 .timer_bit = 0,
121 .clk = "peripheral_clk",
122 .clockevent_rating = 200,
123};
124
125static struct resource mtu2_0_resources[] = {
126 [0] = {
127 .name = "MTU2_0",
128 .start = 0xff801300,
129 .end = 0xff801326,
130 .flags = IORESOURCE_MEM,
131 },
132 [1] = {
133 .start = 228,
134 .flags = IORESOURCE_IRQ,
135 },
136};
137
138static struct platform_device mtu2_0_device = {
139 .name = "sh_mtu2",
140 .id = 0,
141 .dev = {
142 .platform_data = &mtu2_0_platform_data,
143 },
144 .resource = mtu2_0_resources,
145 .num_resources = ARRAY_SIZE(mtu2_0_resources),
146};
147
148static struct sh_timer_config mtu2_1_platform_data = {
149 .name = "MTU2_1",
150 .channel_offset = -0x100,
151 .timer_bit = 1,
152 .clk = "peripheral_clk",
153 .clockevent_rating = 200,
154};
155
156static struct resource mtu2_1_resources[] = {
157 [0] = {
158 .name = "MTU2_1",
159 .start = 0xff801380,
160 .end = 0xff801390,
161 .flags = IORESOURCE_MEM,
162 },
163 [1] = {
164 .start = 234,
165 .flags = IORESOURCE_IRQ,
166 },
167};
168
169static struct platform_device mtu2_1_device = {
170 .name = "sh_mtu2",
171 .id = 1,
172 .dev = {
173 .platform_data = &mtu2_1_platform_data,
174 },
175 .resource = mtu2_1_resources,
176 .num_resources = ARRAY_SIZE(mtu2_1_resources),
177};
178
179static struct sh_timer_config mtu2_2_platform_data = {
180 .name = "MTU2_2",
181 .channel_offset = 0x80,
182 .timer_bit = 2,
183 .clk = "peripheral_clk",
184 .clockevent_rating = 200,
185};
186
187static struct resource mtu2_2_resources[] = {
188 [0] = {
189 .name = "MTU2_2",
190 .start = 0xff801000,
191 .end = 0xff80100a,
192 .flags = IORESOURCE_MEM,
193 },
194 [1] = {
195 .start = 240,
196 .flags = IORESOURCE_IRQ,
197 },
198};
199
200static struct platform_device mtu2_2_device = {
201 .name = "sh_mtu2",
202 .id = 2,
203 .dev = {
204 .platform_data = &mtu2_2_platform_data,
205 },
206 .resource = mtu2_2_resources,
207 .num_resources = ARRAY_SIZE(mtu2_2_resources),
208};
209
116static struct plat_sci_port sci_platform_data[] = { 210static struct plat_sci_port sci_platform_data[] = {
117 { 211 {
118 .mapbase = 0xff804000, 212 .mapbase = 0xff804000,
@@ -134,6 +228,9 @@ static struct platform_device sci_device = {
134 228
135static struct platform_device *mxg_devices[] __initdata = { 229static struct platform_device *mxg_devices[] __initdata = {
136 &sci_device, 230 &sci_device,
231 &mtu2_0_device,
232 &mtu2_1_device,
233 &mtu2_2_device,
137}; 234};
138 235
139static int __init mxg_devices_setup(void) 236static int __init mxg_devices_setup(void)
@@ -147,3 +244,15 @@ void __init plat_irq_setup(void)
147{ 244{
148 register_intc_controller(&intc_desc); 245 register_intc_controller(&intc_desc);
149} 246}
247
248static struct platform_device *mxg_early_devices[] __initdata = {
249 &mtu2_0_device,
250 &mtu2_1_device,
251 &mtu2_2_device,
252};
253
254void __init plat_early_device_setup(void)
255{
256 early_platform_add_devices(mxg_early_devices,
257 ARRAY_SIZE(mxg_early_devices));
258}
diff --git a/arch/sh/kernel/cpu/sh2a/setup-sh7201.c b/arch/sh/kernel/cpu/sh2a/setup-sh7201.c
index 00f42f9e3f5c..d8febe128066 100644
--- a/arch/sh/kernel/cpu/sh2a/setup-sh7201.c
+++ b/arch/sh/kernel/cpu/sh2a/setup-sh7201.c
@@ -12,6 +12,8 @@
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/serial.h> 13#include <linux/serial.h>
14#include <linux/serial_sci.h> 14#include <linux/serial_sci.h>
15#include <linux/sh_timer.h>
16#include <linux/io.h>
15 17
16enum { 18enum {
17 UNUSED = 0, 19 UNUSED = 0,
@@ -249,9 +251,105 @@ static struct platform_device rtc_device = {
249 .resource = rtc_resources, 251 .resource = rtc_resources,
250}; 252};
251 253
254static struct sh_timer_config mtu2_0_platform_data = {
255 .name = "MTU2_0",
256 .channel_offset = -0x80,
257 .timer_bit = 0,
258 .clk = "peripheral_clk",
259 .clockevent_rating = 200,
260};
261
262static struct resource mtu2_0_resources[] = {
263 [0] = {
264 .name = "MTU2_0",
265 .start = 0xfffe4300,
266 .end = 0xfffe4326,
267 .flags = IORESOURCE_MEM,
268 },
269 [1] = {
270 .start = 108,
271 .flags = IORESOURCE_IRQ,
272 },
273};
274
275static struct platform_device mtu2_0_device = {
276 .name = "sh_mtu2",
277 .id = 0,
278 .dev = {
279 .platform_data = &mtu2_0_platform_data,
280 },
281 .resource = mtu2_0_resources,
282 .num_resources = ARRAY_SIZE(mtu2_0_resources),
283};
284
285static struct sh_timer_config mtu2_1_platform_data = {
286 .name = "MTU2_1",
287 .channel_offset = -0x100,
288 .timer_bit = 1,
289 .clk = "peripheral_clk",
290 .clockevent_rating = 200,
291};
292
293static struct resource mtu2_1_resources[] = {
294 [0] = {
295 .name = "MTU2_1",
296 .start = 0xfffe4380,
297 .end = 0xfffe4390,
298 .flags = IORESOURCE_MEM,
299 },
300 [1] = {
301 .start = 116,
302 .flags = IORESOURCE_IRQ,
303 },
304};
305
306static struct platform_device mtu2_1_device = {
307 .name = "sh_mtu2",
308 .id = 1,
309 .dev = {
310 .platform_data = &mtu2_1_platform_data,
311 },
312 .resource = mtu2_1_resources,
313 .num_resources = ARRAY_SIZE(mtu2_1_resources),
314};
315
316static struct sh_timer_config mtu2_2_platform_data = {
317 .name = "MTU2_2",
318 .channel_offset = 0x80,
319 .timer_bit = 2,
320 .clk = "peripheral_clk",
321 .clockevent_rating = 200,
322};
323
324static struct resource mtu2_2_resources[] = {
325 [0] = {
326 .name = "MTU2_2",
327 .start = 0xfffe4000,
328 .end = 0xfffe400a,
329 .flags = IORESOURCE_MEM,
330 },
331 [1] = {
332 .start = 124,
333 .flags = IORESOURCE_IRQ,
334 },
335};
336
337static struct platform_device mtu2_2_device = {
338 .name = "sh_mtu2",
339 .id = 2,
340 .dev = {
341 .platform_data = &mtu2_2_platform_data,
342 },
343 .resource = mtu2_2_resources,
344 .num_resources = ARRAY_SIZE(mtu2_2_resources),
345};
346
252static struct platform_device *sh7201_devices[] __initdata = { 347static struct platform_device *sh7201_devices[] __initdata = {
253 &sci_device, 348 &sci_device,
254 &rtc_device, 349 &rtc_device,
350 &mtu2_0_device,
351 &mtu2_1_device,
352 &mtu2_2_device,
255}; 353};
256 354
257static int __init sh7201_devices_setup(void) 355static int __init sh7201_devices_setup(void)
@@ -265,3 +363,20 @@ void __init plat_irq_setup(void)
265{ 363{
266 register_intc_controller(&intc_desc); 364 register_intc_controller(&intc_desc);
267} 365}
366
367static struct platform_device *sh7201_early_devices[] __initdata = {
368 &mtu2_0_device,
369 &mtu2_1_device,
370 &mtu2_2_device,
371};
372
373#define STBCR3 0xfffe0408
374
375void __init plat_early_device_setup(void)
376{
377 /* enable MTU2 clock */
378 __raw_writeb(__raw_readb(STBCR3) & ~0x20, STBCR3);
379
380 early_platform_add_devices(sh7201_early_devices,
381 ARRAY_SIZE(sh7201_early_devices));
382}
diff --git a/arch/sh/kernel/cpu/sh2a/setup-sh7203.c b/arch/sh/kernel/cpu/sh2a/setup-sh7203.c
index 820dfb2e8656..62e3039d2398 100644
--- a/arch/sh/kernel/cpu/sh2a/setup-sh7203.c
+++ b/arch/sh/kernel/cpu/sh2a/setup-sh7203.c
@@ -11,6 +11,8 @@
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/serial.h> 12#include <linux/serial.h>
13#include <linux/serial_sci.h> 13#include <linux/serial_sci.h>
14#include <linux/sh_timer.h>
15#include <linux/io.h>
14 16
15enum { 17enum {
16 UNUSED = 0, 18 UNUSED = 0,
@@ -205,6 +207,132 @@ static struct platform_device sci_device = {
205 }, 207 },
206}; 208};
207 209
210static struct sh_timer_config cmt0_platform_data = {
211 .name = "CMT0",
212 .channel_offset = 0x02,
213 .timer_bit = 0,
214 .clk = "peripheral_clk",
215 .clockevent_rating = 125,
216 .clocksource_rating = 0, /* disabled due to code generation issues */
217};
218
219static struct resource cmt0_resources[] = {
220 [0] = {
221 .name = "CMT0",
222 .start = 0xfffec002,
223 .end = 0xfffec007,
224 .flags = IORESOURCE_MEM,
225 },
226 [1] = {
227 .start = 142,
228 .flags = IORESOURCE_IRQ,
229 },
230};
231
232static struct platform_device cmt0_device = {
233 .name = "sh_cmt",
234 .id = 0,
235 .dev = {
236 .platform_data = &cmt0_platform_data,
237 },
238 .resource = cmt0_resources,
239 .num_resources = ARRAY_SIZE(cmt0_resources),
240};
241
242static struct sh_timer_config cmt1_platform_data = {
243 .name = "CMT1",
244 .channel_offset = 0x08,
245 .timer_bit = 1,
246 .clk = "peripheral_clk",
247 .clockevent_rating = 125,
248 .clocksource_rating = 0, /* disabled due to code generation issues */
249};
250
251static struct resource cmt1_resources[] = {
252 [0] = {
253 .name = "CMT1",
254 .start = 0xfffec008,
255 .end = 0xfffec00d,
256 .flags = IORESOURCE_MEM,
257 },
258 [1] = {
259 .start = 143,
260 .flags = IORESOURCE_IRQ,
261 },
262};
263
264static struct platform_device cmt1_device = {
265 .name = "sh_cmt",
266 .id = 1,
267 .dev = {
268 .platform_data = &cmt1_platform_data,
269 },
270 .resource = cmt1_resources,
271 .num_resources = ARRAY_SIZE(cmt1_resources),
272};
273
274static struct sh_timer_config mtu2_0_platform_data = {
275 .name = "MTU2_0",
276 .channel_offset = -0x80,
277 .timer_bit = 0,
278 .clk = "peripheral_clk",
279 .clockevent_rating = 200,
280};
281
282static struct resource mtu2_0_resources[] = {
283 [0] = {
284 .name = "MTU2_0",
285 .start = 0xfffe4300,
286 .end = 0xfffe4326,
287 .flags = IORESOURCE_MEM,
288 },
289 [1] = {
290 .start = 146,
291 .flags = IORESOURCE_IRQ,
292 },
293};
294
295static struct platform_device mtu2_0_device = {
296 .name = "sh_mtu2",
297 .id = 0,
298 .dev = {
299 .platform_data = &mtu2_0_platform_data,
300 },
301 .resource = mtu2_0_resources,
302 .num_resources = ARRAY_SIZE(mtu2_0_resources),
303};
304
305static struct sh_timer_config mtu2_1_platform_data = {
306 .name = "MTU2_1",
307 .channel_offset = -0x100,
308 .timer_bit = 1,
309 .clk = "peripheral_clk",
310 .clockevent_rating = 200,
311};
312
313static struct resource mtu2_1_resources[] = {
314 [0] = {
315 .name = "MTU2_1",
316 .start = 0xfffe4380,
317 .end = 0xfffe4390,
318 .flags = IORESOURCE_MEM,
319 },
320 [1] = {
321 .start = 153,
322 .flags = IORESOURCE_IRQ,
323 },
324};
325
326static struct platform_device mtu2_1_device = {
327 .name = "sh_mtu2",
328 .id = 1,
329 .dev = {
330 .platform_data = &mtu2_1_platform_data,
331 },
332 .resource = mtu2_1_resources,
333 .num_resources = ARRAY_SIZE(mtu2_1_resources),
334};
335
208static struct resource rtc_resources[] = { 336static struct resource rtc_resources[] = {
209 [0] = { 337 [0] = {
210 .start = 0xffff2000, 338 .start = 0xffff2000,
@@ -227,6 +355,10 @@ static struct platform_device rtc_device = {
227 355
228static struct platform_device *sh7203_devices[] __initdata = { 356static struct platform_device *sh7203_devices[] __initdata = {
229 &sci_device, 357 &sci_device,
358 &cmt0_device,
359 &cmt1_device,
360 &mtu2_0_device,
361 &mtu2_1_device,
230 &rtc_device, 362 &rtc_device,
231}; 363};
232 364
@@ -241,3 +373,25 @@ void __init plat_irq_setup(void)
241{ 373{
242 register_intc_controller(&intc_desc); 374 register_intc_controller(&intc_desc);
243} 375}
376
377static struct platform_device *sh7203_early_devices[] __initdata = {
378 &cmt0_device,
379 &cmt1_device,
380 &mtu2_0_device,
381 &mtu2_1_device,
382};
383
384#define STBCR3 0xfffe0408
385#define STBCR4 0xfffe040c
386
387void __init plat_early_device_setup(void)
388{
389 /* enable CMT clock */
390 __raw_writeb(__raw_readb(STBCR4) & ~0x04, STBCR4);
391
392 /* enable MTU2 clock */
393 __raw_writeb(__raw_readb(STBCR3) & ~0x20, STBCR3);
394
395 early_platform_add_devices(sh7203_early_devices,
396 ARRAY_SIZE(sh7203_early_devices));
397}
diff --git a/arch/sh/kernel/cpu/sh2a/setup-sh7206.c b/arch/sh/kernel/cpu/sh2a/setup-sh7206.c
index c46a8355726d..3e6f3d7a58be 100644
--- a/arch/sh/kernel/cpu/sh2a/setup-sh7206.c
+++ b/arch/sh/kernel/cpu/sh2a/setup-sh7206.c
@@ -12,6 +12,8 @@
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/serial.h> 13#include <linux/serial.h>
14#include <linux/serial_sci.h> 14#include <linux/serial_sci.h>
15#include <linux/sh_timer.h>
16#include <linux/io.h>
15 17
16enum { 18enum {
17 UNUSED = 0, 19 UNUSED = 0,
@@ -165,8 +167,170 @@ static struct platform_device sci_device = {
165 }, 167 },
166}; 168};
167 169
170static struct sh_timer_config cmt0_platform_data = {
171 .name = "CMT0",
172 .channel_offset = 0x02,
173 .timer_bit = 0,
174 .clk = "peripheral_clk",
175 .clockevent_rating = 125,
176 .clocksource_rating = 0, /* disabled due to code generation issues */
177};
178
179static struct resource cmt0_resources[] = {
180 [0] = {
181 .name = "CMT0",
182 .start = 0xfffec002,
183 .end = 0xfffec007,
184 .flags = IORESOURCE_MEM,
185 },
186 [1] = {
187 .start = 140,
188 .flags = IORESOURCE_IRQ,
189 },
190};
191
192static struct platform_device cmt0_device = {
193 .name = "sh_cmt",
194 .id = 0,
195 .dev = {
196 .platform_data = &cmt0_platform_data,
197 },
198 .resource = cmt0_resources,
199 .num_resources = ARRAY_SIZE(cmt0_resources),
200};
201
202static struct sh_timer_config cmt1_platform_data = {
203 .name = "CMT1",
204 .channel_offset = 0x08,
205 .timer_bit = 1,
206 .clk = "peripheral_clk",
207 .clockevent_rating = 125,
208 .clocksource_rating = 0, /* disabled due to code generation issues */
209};
210
211static struct resource cmt1_resources[] = {
212 [0] = {
213 .name = "CMT1",
214 .start = 0xfffec008,
215 .end = 0xfffec00d,
216 .flags = IORESOURCE_MEM,
217 },
218 [1] = {
219 .start = 144,
220 .flags = IORESOURCE_IRQ,
221 },
222};
223
224static struct platform_device cmt1_device = {
225 .name = "sh_cmt",
226 .id = 1,
227 .dev = {
228 .platform_data = &cmt1_platform_data,
229 },
230 .resource = cmt1_resources,
231 .num_resources = ARRAY_SIZE(cmt1_resources),
232};
233
234static struct sh_timer_config mtu2_0_platform_data = {
235 .name = "MTU2_0",
236 .channel_offset = -0x80,
237 .timer_bit = 0,
238 .clk = "peripheral_clk",
239 .clockevent_rating = 200,
240};
241
242static struct resource mtu2_0_resources[] = {
243 [0] = {
244 .name = "MTU2_0",
245 .start = 0xfffe4300,
246 .end = 0xfffe4326,
247 .flags = IORESOURCE_MEM,
248 },
249 [1] = {
250 .start = 156,
251 .flags = IORESOURCE_IRQ,
252 },
253};
254
255static struct platform_device mtu2_0_device = {
256 .name = "sh_mtu2",
257 .id = 0,
258 .dev = {
259 .platform_data = &mtu2_0_platform_data,
260 },
261 .resource = mtu2_0_resources,
262 .num_resources = ARRAY_SIZE(mtu2_0_resources),
263};
264
265static struct sh_timer_config mtu2_1_platform_data = {
266 .name = "MTU2_1",
267 .channel_offset = -0x100,
268 .timer_bit = 1,
269 .clk = "peripheral_clk",
270 .clockevent_rating = 200,
271};
272
273static struct resource mtu2_1_resources[] = {
274 [0] = {
275 .name = "MTU2_1",
276 .start = 0xfffe4380,
277 .end = 0xfffe4390,
278 .flags = IORESOURCE_MEM,
279 },
280 [1] = {
281 .start = 164,
282 .flags = IORESOURCE_IRQ,
283 },
284};
285
286static struct platform_device mtu2_1_device = {
287 .name = "sh_mtu2",
288 .id = 1,
289 .dev = {
290 .platform_data = &mtu2_1_platform_data,
291 },
292 .resource = mtu2_1_resources,
293 .num_resources = ARRAY_SIZE(mtu2_1_resources),
294};
295
296static struct sh_timer_config mtu2_2_platform_data = {
297 .name = "MTU2_2",
298 .channel_offset = 0x80,
299 .timer_bit = 2,
300 .clk = "peripheral_clk",
301 .clockevent_rating = 200,
302};
303
304static struct resource mtu2_2_resources[] = {
305 [0] = {
306 .name = "MTU2_2",
307 .start = 0xfffe4000,
308 .end = 0xfffe400a,
309 .flags = IORESOURCE_MEM,
310 },
311 [1] = {
312 .start = 180,
313 .flags = IORESOURCE_IRQ,
314 },
315};
316
317static struct platform_device mtu2_2_device = {
318 .name = "sh_mtu2",
319 .id = 2,
320 .dev = {
321 .platform_data = &mtu2_2_platform_data,
322 },
323 .resource = mtu2_2_resources,
324 .num_resources = ARRAY_SIZE(mtu2_2_resources),
325};
326
168static struct platform_device *sh7206_devices[] __initdata = { 327static struct platform_device *sh7206_devices[] __initdata = {
169 &sci_device, 328 &sci_device,
329 &cmt0_device,
330 &cmt1_device,
331 &mtu2_0_device,
332 &mtu2_1_device,
333 &mtu2_2_device,
170}; 334};
171 335
172static int __init sh7206_devices_setup(void) 336static int __init sh7206_devices_setup(void)
@@ -180,3 +344,26 @@ void __init plat_irq_setup(void)
180{ 344{
181 register_intc_controller(&intc_desc); 345 register_intc_controller(&intc_desc);
182} 346}
347
348static struct platform_device *sh7206_early_devices[] __initdata = {
349 &cmt0_device,
350 &cmt1_device,
351 &mtu2_0_device,
352 &mtu2_1_device,
353 &mtu2_2_device,
354};
355
356#define STBCR3 0xfffe0408
357#define STBCR4 0xfffe040c
358
359void __init plat_early_device_setup(void)
360{
361 /* enable CMT clock */
362 __raw_writeb(__raw_readb(STBCR4) & ~0x04, STBCR4);
363
364 /* enable MTU2 clock */
365 __raw_writeb(__raw_readb(STBCR3) & ~0x20, STBCR3);
366
367 early_platform_add_devices(sh7206_early_devices,
368 ARRAY_SIZE(sh7206_early_devices));
369}
diff --git a/arch/sh/kernel/cpu/sh3/clock-sh3.c b/arch/sh/kernel/cpu/sh3/clock-sh3.c
index c3c945958baf..27b8738f0b09 100644
--- a/arch/sh/kernel/cpu/sh3/clock-sh3.c
+++ b/arch/sh/kernel/cpu/sh3/clock-sh3.c
@@ -38,36 +38,36 @@ static struct clk_ops sh3_master_clk_ops = {
38 .init = master_clk_init, 38 .init = master_clk_init,
39}; 39};
40 40
41static void module_clk_recalc(struct clk *clk) 41static unsigned long module_clk_recalc(struct clk *clk)
42{ 42{
43 int frqcr = ctrl_inw(FRQCR); 43 int frqcr = ctrl_inw(FRQCR);
44 int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003); 44 int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003);
45 45
46 clk->rate = clk->parent->rate / pfc_divisors[idx]; 46 return clk->parent->rate / pfc_divisors[idx];
47} 47}
48 48
49static struct clk_ops sh3_module_clk_ops = { 49static struct clk_ops sh3_module_clk_ops = {
50 .recalc = module_clk_recalc, 50 .recalc = module_clk_recalc,
51}; 51};
52 52
53static void bus_clk_recalc(struct clk *clk) 53static unsigned long bus_clk_recalc(struct clk *clk)
54{ 54{
55 int frqcr = ctrl_inw(FRQCR); 55 int frqcr = ctrl_inw(FRQCR);
56 int idx = ((frqcr & 0x8000) >> 13) | ((frqcr & 0x0030) >> 4); 56 int idx = ((frqcr & 0x8000) >> 13) | ((frqcr & 0x0030) >> 4);
57 57
58 clk->rate = clk->parent->rate / stc_multipliers[idx]; 58 return clk->parent->rate / stc_multipliers[idx];
59} 59}
60 60
61static struct clk_ops sh3_bus_clk_ops = { 61static struct clk_ops sh3_bus_clk_ops = {
62 .recalc = bus_clk_recalc, 62 .recalc = bus_clk_recalc,
63}; 63};
64 64
65static void cpu_clk_recalc(struct clk *clk) 65static unsigned long cpu_clk_recalc(struct clk *clk)
66{ 66{
67 int frqcr = ctrl_inw(FRQCR); 67 int frqcr = ctrl_inw(FRQCR);
68 int idx = ((frqcr & 0x4000) >> 12) | ((frqcr & 0x000c) >> 2); 68 int idx = ((frqcr & 0x4000) >> 12) | ((frqcr & 0x000c) >> 2);
69 69
70 clk->rate = clk->parent->rate / ifc_divisors[idx]; 70 return clk->parent->rate / ifc_divisors[idx];
71} 71}
72 72
73static struct clk_ops sh3_cpu_clk_ops = { 73static struct clk_ops sh3_cpu_clk_ops = {
diff --git a/arch/sh/kernel/cpu/sh3/clock-sh7705.c b/arch/sh/kernel/cpu/sh3/clock-sh7705.c
index dfdbf3277fd7..0ca8f2c3646c 100644
--- a/arch/sh/kernel/cpu/sh3/clock-sh7705.c
+++ b/arch/sh/kernel/cpu/sh3/clock-sh7705.c
@@ -39,30 +39,30 @@ static struct clk_ops sh7705_master_clk_ops = {
39 .init = master_clk_init, 39 .init = master_clk_init,
40}; 40};
41 41
42static void module_clk_recalc(struct clk *clk) 42static unsigned long module_clk_recalc(struct clk *clk)
43{ 43{
44 int idx = ctrl_inw(FRQCR) & 0x0003; 44 int idx = ctrl_inw(FRQCR) & 0x0003;
45 clk->rate = clk->parent->rate / pfc_divisors[idx]; 45 return clk->parent->rate / pfc_divisors[idx];
46} 46}
47 47
48static struct clk_ops sh7705_module_clk_ops = { 48static struct clk_ops sh7705_module_clk_ops = {
49 .recalc = module_clk_recalc, 49 .recalc = module_clk_recalc,
50}; 50};
51 51
52static void bus_clk_recalc(struct clk *clk) 52static unsigned long bus_clk_recalc(struct clk *clk)
53{ 53{
54 int idx = (ctrl_inw(FRQCR) & 0x0300) >> 8; 54 int idx = (ctrl_inw(FRQCR) & 0x0300) >> 8;
55 clk->rate = clk->parent->rate / stc_multipliers[idx]; 55 return clk->parent->rate / stc_multipliers[idx];
56} 56}
57 57
58static struct clk_ops sh7705_bus_clk_ops = { 58static struct clk_ops sh7705_bus_clk_ops = {
59 .recalc = bus_clk_recalc, 59 .recalc = bus_clk_recalc,
60}; 60};
61 61
62static void cpu_clk_recalc(struct clk *clk) 62static unsigned long cpu_clk_recalc(struct clk *clk)
63{ 63{
64 int idx = (ctrl_inw(FRQCR) & 0x0030) >> 4; 64 int idx = (ctrl_inw(FRQCR) & 0x0030) >> 4;
65 clk->rate = clk->parent->rate / ifc_divisors[idx]; 65 return clk->parent->rate / ifc_divisors[idx];
66} 66}
67 67
68static struct clk_ops sh7705_cpu_clk_ops = { 68static struct clk_ops sh7705_cpu_clk_ops = {
diff --git a/arch/sh/kernel/cpu/sh3/clock-sh7706.c b/arch/sh/kernel/cpu/sh3/clock-sh7706.c
index 0cf96f9833bc..4bf7887d310a 100644
--- a/arch/sh/kernel/cpu/sh3/clock-sh7706.c
+++ b/arch/sh/kernel/cpu/sh3/clock-sh7706.c
@@ -34,36 +34,36 @@ static struct clk_ops sh7706_master_clk_ops = {
34 .init = master_clk_init, 34 .init = master_clk_init,
35}; 35};
36 36
37static void module_clk_recalc(struct clk *clk) 37static unsigned long module_clk_recalc(struct clk *clk)
38{ 38{
39 int frqcr = ctrl_inw(FRQCR); 39 int frqcr = ctrl_inw(FRQCR);
40 int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003); 40 int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003);
41 41
42 clk->rate = clk->parent->rate / pfc_divisors[idx]; 42 return clk->parent->rate / pfc_divisors[idx];
43} 43}
44 44
45static struct clk_ops sh7706_module_clk_ops = { 45static struct clk_ops sh7706_module_clk_ops = {
46 .recalc = module_clk_recalc, 46 .recalc = module_clk_recalc,
47}; 47};
48 48
49static void bus_clk_recalc(struct clk *clk) 49static unsigned long bus_clk_recalc(struct clk *clk)
50{ 50{
51 int frqcr = ctrl_inw(FRQCR); 51 int frqcr = ctrl_inw(FRQCR);
52 int idx = ((frqcr & 0x8000) >> 13) | ((frqcr & 0x0030) >> 4); 52 int idx = ((frqcr & 0x8000) >> 13) | ((frqcr & 0x0030) >> 4);
53 53
54 clk->rate = clk->parent->rate / stc_multipliers[idx]; 54 return clk->parent->rate / stc_multipliers[idx];
55} 55}
56 56
57static struct clk_ops sh7706_bus_clk_ops = { 57static struct clk_ops sh7706_bus_clk_ops = {
58 .recalc = bus_clk_recalc, 58 .recalc = bus_clk_recalc,
59}; 59};
60 60
61static void cpu_clk_recalc(struct clk *clk) 61static unsigned long cpu_clk_recalc(struct clk *clk)
62{ 62{
63 int frqcr = ctrl_inw(FRQCR); 63 int frqcr = ctrl_inw(FRQCR);
64 int idx = ((frqcr & 0x4000) >> 12) | ((frqcr & 0x000c) >> 2); 64 int idx = ((frqcr & 0x4000) >> 12) | ((frqcr & 0x000c) >> 2);
65 65
66 clk->rate = clk->parent->rate / ifc_divisors[idx]; 66 return clk->parent->rate / ifc_divisors[idx];
67} 67}
68 68
69static struct clk_ops sh7706_cpu_clk_ops = { 69static struct clk_ops sh7706_cpu_clk_ops = {
diff --git a/arch/sh/kernel/cpu/sh3/clock-sh7709.c b/arch/sh/kernel/cpu/sh3/clock-sh7709.c
index b791a29fdb62..fa30b6017730 100644
--- a/arch/sh/kernel/cpu/sh3/clock-sh7709.c
+++ b/arch/sh/kernel/cpu/sh3/clock-sh7709.c
@@ -41,12 +41,12 @@ static struct clk_ops sh7709_master_clk_ops = {
41 .init = master_clk_init, 41 .init = master_clk_init,
42}; 42};
43 43
44static void module_clk_recalc(struct clk *clk) 44static unsigned long module_clk_recalc(struct clk *clk)
45{ 45{
46 int frqcr = ctrl_inw(FRQCR); 46 int frqcr = ctrl_inw(FRQCR);
47 int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003); 47 int idx = ((frqcr & 0x2000) >> 11) | (frqcr & 0x0003);
48 48
49 clk->rate = clk->parent->rate / pfc_divisors[idx]; 49 return clk->parent->rate / pfc_divisors[idx];
50} 50}
51 51
52static struct clk_ops sh7709_module_clk_ops = { 52static struct clk_ops sh7709_module_clk_ops = {
@@ -56,25 +56,25 @@ static struct clk_ops sh7709_module_clk_ops = {
56 .recalc = module_clk_recalc, 56 .recalc = module_clk_recalc,
57}; 57};
58 58
59static void bus_clk_recalc(struct clk *clk) 59static unsigned long bus_clk_recalc(struct clk *clk)
60{ 60{
61 int frqcr = ctrl_inw(FRQCR); 61 int frqcr = ctrl_inw(FRQCR);
62 int idx = (frqcr & 0x0080) ? 62 int idx = (frqcr & 0x0080) ?
63 ((frqcr & 0x8000) >> 13) | ((frqcr & 0x0030) >> 4) : 1; 63 ((frqcr & 0x8000) >> 13) | ((frqcr & 0x0030) >> 4) : 1;
64 64
65 clk->rate = clk->parent->rate * stc_multipliers[idx]; 65 return clk->parent->rate * stc_multipliers[idx];
66} 66}
67 67
68static struct clk_ops sh7709_bus_clk_ops = { 68static struct clk_ops sh7709_bus_clk_ops = {
69 .recalc = bus_clk_recalc, 69 .recalc = bus_clk_recalc,
70}; 70};
71 71
72static void cpu_clk_recalc(struct clk *clk) 72static unsigned long cpu_clk_recalc(struct clk *clk)
73{ 73{
74 int frqcr = ctrl_inw(FRQCR); 74 int frqcr = ctrl_inw(FRQCR);
75 int idx = ((frqcr & 0x4000) >> 12) | ((frqcr & 0x000c) >> 2); 75 int idx = ((frqcr & 0x4000) >> 12) | ((frqcr & 0x000c) >> 2);
76 76
77 clk->rate = clk->parent->rate / ifc_divisors[idx]; 77 return clk->parent->rate / ifc_divisors[idx];
78} 78}
79 79
80static struct clk_ops sh7709_cpu_clk_ops = { 80static struct clk_ops sh7709_cpu_clk_ops = {
diff --git a/arch/sh/kernel/cpu/sh3/clock-sh7710.c b/arch/sh/kernel/cpu/sh3/clock-sh7710.c
index 4744c50ec449..030a58ba18a5 100644
--- a/arch/sh/kernel/cpu/sh3/clock-sh7710.c
+++ b/arch/sh/kernel/cpu/sh3/clock-sh7710.c
@@ -33,30 +33,30 @@ static struct clk_ops sh7710_master_clk_ops = {
33 .init = master_clk_init, 33 .init = master_clk_init,
34}; 34};
35 35
36static void module_clk_recalc(struct clk *clk) 36static unsigned long module_clk_recalc(struct clk *clk)
37{ 37{
38 int idx = (ctrl_inw(FRQCR) & 0x0007); 38 int idx = (ctrl_inw(FRQCR) & 0x0007);
39 clk->rate = clk->parent->rate / md_table[idx]; 39 return clk->parent->rate / md_table[idx];
40} 40}
41 41
42static struct clk_ops sh7710_module_clk_ops = { 42static struct clk_ops sh7710_module_clk_ops = {
43 .recalc = module_clk_recalc, 43 .recalc = module_clk_recalc,
44}; 44};
45 45
46static void bus_clk_recalc(struct clk *clk) 46static unsigned long bus_clk_recalc(struct clk *clk)
47{ 47{
48 int idx = (ctrl_inw(FRQCR) & 0x0700) >> 8; 48 int idx = (ctrl_inw(FRQCR) & 0x0700) >> 8;
49 clk->rate = clk->parent->rate / md_table[idx]; 49 return clk->parent->rate / md_table[idx];
50} 50}
51 51
52static struct clk_ops sh7710_bus_clk_ops = { 52static struct clk_ops sh7710_bus_clk_ops = {
53 .recalc = bus_clk_recalc, 53 .recalc = bus_clk_recalc,
54}; 54};
55 55
56static void cpu_clk_recalc(struct clk *clk) 56static unsigned long cpu_clk_recalc(struct clk *clk)
57{ 57{
58 int idx = (ctrl_inw(FRQCR) & 0x0070) >> 4; 58 int idx = (ctrl_inw(FRQCR) & 0x0070) >> 4;
59 clk->rate = clk->parent->rate / md_table[idx]; 59 return clk->parent->rate / md_table[idx];
60} 60}
61 61
62static struct clk_ops sh7710_cpu_clk_ops = { 62static struct clk_ops sh7710_cpu_clk_ops = {
diff --git a/arch/sh/kernel/cpu/sh3/clock-sh7712.c b/arch/sh/kernel/cpu/sh3/clock-sh7712.c
index 54f54df51ef0..6428ee6c77ed 100644
--- a/arch/sh/kernel/cpu/sh3/clock-sh7712.c
+++ b/arch/sh/kernel/cpu/sh3/clock-sh7712.c
@@ -33,24 +33,24 @@ static struct clk_ops sh7712_master_clk_ops = {
33 .init = master_clk_init, 33 .init = master_clk_init,
34}; 34};
35 35
36static void module_clk_recalc(struct clk *clk) 36static unsigned long module_clk_recalc(struct clk *clk)
37{ 37{
38 int frqcr = ctrl_inw(FRQCR); 38 int frqcr = ctrl_inw(FRQCR);
39 int idx = frqcr & 0x0007; 39 int idx = frqcr & 0x0007;
40 40
41 clk->rate = clk->parent->rate / divisors[idx]; 41 return clk->parent->rate / divisors[idx];
42} 42}
43 43
44static struct clk_ops sh7712_module_clk_ops = { 44static struct clk_ops sh7712_module_clk_ops = {
45 .recalc = module_clk_recalc, 45 .recalc = module_clk_recalc,
46}; 46};
47 47
48static void cpu_clk_recalc(struct clk *clk) 48static unsigned long cpu_clk_recalc(struct clk *clk)
49{ 49{
50 int frqcr = ctrl_inw(FRQCR); 50 int frqcr = ctrl_inw(FRQCR);
51 int idx = (frqcr & 0x0030) >> 4; 51 int idx = (frqcr & 0x0030) >> 4;
52 52
53 clk->rate = clk->parent->rate / divisors[idx]; 53 return clk->parent->rate / divisors[idx];
54} 54}
55 55
56static struct clk_ops sh7712_cpu_clk_ops = { 56static struct clk_ops sh7712_cpu_clk_ops = {
diff --git a/arch/sh/kernel/cpu/sh3/setup-sh7705.c b/arch/sh/kernel/cpu/sh3/setup-sh7705.c
index 63b67badd67e..88f742fed9ed 100644
--- a/arch/sh/kernel/cpu/sh3/setup-sh7705.c
+++ b/arch/sh/kernel/cpu/sh3/setup-sh7705.c
@@ -13,6 +13,7 @@
13#include <linux/irq.h> 13#include <linux/irq.h>
14#include <linux/serial.h> 14#include <linux/serial.h>
15#include <linux/serial_sci.h> 15#include <linux/serial_sci.h>
16#include <linux/sh_timer.h>
16#include <asm/rtc.h> 17#include <asm/rtc.h>
17 18
18enum { 19enum {
@@ -116,7 +117,102 @@ static struct platform_device rtc_device = {
116 }, 117 },
117}; 118};
118 119
120static struct sh_timer_config tmu0_platform_data = {
121 .name = "TMU0",
122 .channel_offset = 0x02,
123 .timer_bit = 0,
124 .clk = "peripheral_clk",
125 .clockevent_rating = 200,
126};
127
128static struct resource tmu0_resources[] = {
129 [0] = {
130 .name = "TMU0",
131 .start = 0xfffffe94,
132 .end = 0xfffffe9f,
133 .flags = IORESOURCE_MEM,
134 },
135 [1] = {
136 .start = 16,
137 .flags = IORESOURCE_IRQ,
138 },
139};
140
141static struct platform_device tmu0_device = {
142 .name = "sh_tmu",
143 .id = 0,
144 .dev = {
145 .platform_data = &tmu0_platform_data,
146 },
147 .resource = tmu0_resources,
148 .num_resources = ARRAY_SIZE(tmu0_resources),
149};
150
151static struct sh_timer_config tmu1_platform_data = {
152 .name = "TMU1",
153 .channel_offset = 0xe,
154 .timer_bit = 1,
155 .clk = "peripheral_clk",
156 .clocksource_rating = 200,
157};
158
159static struct resource tmu1_resources[] = {
160 [0] = {
161 .name = "TMU1",
162 .start = 0xfffffea0,
163 .end = 0xfffffeab,
164 .flags = IORESOURCE_MEM,
165 },
166 [1] = {
167 .start = 17,
168 .flags = IORESOURCE_IRQ,
169 },
170};
171
172static struct platform_device tmu1_device = {
173 .name = "sh_tmu",
174 .id = 1,
175 .dev = {
176 .platform_data = &tmu1_platform_data,
177 },
178 .resource = tmu1_resources,
179 .num_resources = ARRAY_SIZE(tmu1_resources),
180};
181
182static struct sh_timer_config tmu2_platform_data = {
183 .name = "TMU2",
184 .channel_offset = 0x1a,
185 .timer_bit = 2,
186 .clk = "peripheral_clk",
187};
188
189static struct resource tmu2_resources[] = {
190 [0] = {
191 .name = "TMU2",
192 .start = 0xfffffeac,
193 .end = 0xfffffebb,
194 .flags = IORESOURCE_MEM,
195 },
196 [1] = {
197 .start = 18,
198 .flags = IORESOURCE_IRQ,
199 },
200};
201
202static struct platform_device tmu2_device = {
203 .name = "sh_tmu",
204 .id = 2,
205 .dev = {
206 .platform_data = &tmu2_platform_data,
207 },
208 .resource = tmu2_resources,
209 .num_resources = ARRAY_SIZE(tmu2_resources),
210};
211
119static struct platform_device *sh7705_devices[] __initdata = { 212static struct platform_device *sh7705_devices[] __initdata = {
213 &tmu0_device,
214 &tmu1_device,
215 &tmu2_device,
120 &sci_device, 216 &sci_device,
121 &rtc_device, 217 &rtc_device,
122}; 218};
@@ -128,6 +224,18 @@ static int __init sh7705_devices_setup(void)
128} 224}
129__initcall(sh7705_devices_setup); 225__initcall(sh7705_devices_setup);
130 226
227static struct platform_device *sh7705_early_devices[] __initdata = {
228 &tmu0_device,
229 &tmu1_device,
230 &tmu2_device,
231};
232
233void __init plat_early_device_setup(void)
234{
235 early_platform_add_devices(sh7705_early_devices,
236 ARRAY_SIZE(sh7705_early_devices));
237}
238
131void __init plat_irq_setup(void) 239void __init plat_irq_setup(void)
132{ 240{
133 register_intc_controller(&intc_desc); 241 register_intc_controller(&intc_desc);
diff --git a/arch/sh/kernel/cpu/sh3/setup-sh770x.c b/arch/sh/kernel/cpu/sh3/setup-sh770x.c
index a74f960b5e79..c56306798584 100644
--- a/arch/sh/kernel/cpu/sh3/setup-sh770x.c
+++ b/arch/sh/kernel/cpu/sh3/setup-sh770x.c
@@ -18,6 +18,7 @@
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/serial.h> 19#include <linux/serial.h>
20#include <linux/serial_sci.h> 20#include <linux/serial_sci.h>
21#include <linux/sh_timer.h>
21 22
22enum { 23enum {
23 UNUSED = 0, 24 UNUSED = 0,
@@ -144,7 +145,102 @@ static struct platform_device sci_device = {
144 }, 145 },
145}; 146};
146 147
148static struct sh_timer_config tmu0_platform_data = {
149 .name = "TMU0",
150 .channel_offset = 0x02,
151 .timer_bit = 0,
152 .clk = "peripheral_clk",
153 .clockevent_rating = 200,
154};
155
156static struct resource tmu0_resources[] = {
157 [0] = {
158 .name = "TMU0",
159 .start = 0xfffffe94,
160 .end = 0xfffffe9f,
161 .flags = IORESOURCE_MEM,
162 },
163 [1] = {
164 .start = 16,
165 .flags = IORESOURCE_IRQ,
166 },
167};
168
169static struct platform_device tmu0_device = {
170 .name = "sh_tmu",
171 .id = 0,
172 .dev = {
173 .platform_data = &tmu0_platform_data,
174 },
175 .resource = tmu0_resources,
176 .num_resources = ARRAY_SIZE(tmu0_resources),
177};
178
179static struct sh_timer_config tmu1_platform_data = {
180 .name = "TMU1",
181 .channel_offset = 0xe,
182 .timer_bit = 1,
183 .clk = "peripheral_clk",
184 .clocksource_rating = 200,
185};
186
187static struct resource tmu1_resources[] = {
188 [0] = {
189 .name = "TMU1",
190 .start = 0xfffffea0,
191 .end = 0xfffffeab,
192 .flags = IORESOURCE_MEM,
193 },
194 [1] = {
195 .start = 17,
196 .flags = IORESOURCE_IRQ,
197 },
198};
199
200static struct platform_device tmu1_device = {
201 .name = "sh_tmu",
202 .id = 1,
203 .dev = {
204 .platform_data = &tmu1_platform_data,
205 },
206 .resource = tmu1_resources,
207 .num_resources = ARRAY_SIZE(tmu1_resources),
208};
209
210static struct sh_timer_config tmu2_platform_data = {
211 .name = "TMU2",
212 .channel_offset = 0x1a,
213 .timer_bit = 2,
214 .clk = "peripheral_clk",
215};
216
217static struct resource tmu2_resources[] = {
218 [0] = {
219 .name = "TMU2",
220 .start = 0xfffffeac,
221 .end = 0xfffffebb,
222 .flags = IORESOURCE_MEM,
223 },
224 [1] = {
225 .start = 18,
226 .flags = IORESOURCE_IRQ,
227 },
228};
229
230static struct platform_device tmu2_device = {
231 .name = "sh_tmu",
232 .id = 2,
233 .dev = {
234 .platform_data = &tmu2_platform_data,
235 },
236 .resource = tmu2_resources,
237 .num_resources = ARRAY_SIZE(tmu2_resources),
238};
239
147static struct platform_device *sh770x_devices[] __initdata = { 240static struct platform_device *sh770x_devices[] __initdata = {
241 &tmu0_device,
242 &tmu1_device,
243 &tmu2_device,
148 &sci_device, 244 &sci_device,
149 &rtc_device, 245 &rtc_device,
150}; 246};
@@ -156,6 +252,18 @@ static int __init sh770x_devices_setup(void)
156} 252}
157__initcall(sh770x_devices_setup); 253__initcall(sh770x_devices_setup);
158 254
255static struct platform_device *sh770x_early_devices[] __initdata = {
256 &tmu0_device,
257 &tmu1_device,
258 &tmu2_device,
259};
260
261void __init plat_early_device_setup(void)
262{
263 early_platform_add_devices(sh770x_early_devices,
264 ARRAY_SIZE(sh770x_early_devices));
265}
266
159void __init plat_irq_setup(void) 267void __init plat_irq_setup(void)
160{ 268{
161 register_intc_controller(&intc_desc); 269 register_intc_controller(&intc_desc);
diff --git a/arch/sh/kernel/cpu/sh3/setup-sh7710.c b/arch/sh/kernel/cpu/sh3/setup-sh7710.c
index 335098b66e2f..efa76c8148f4 100644
--- a/arch/sh/kernel/cpu/sh3/setup-sh7710.c
+++ b/arch/sh/kernel/cpu/sh3/setup-sh7710.c
@@ -13,6 +13,7 @@
13#include <linux/irq.h> 13#include <linux/irq.h>
14#include <linux/serial.h> 14#include <linux/serial.h>
15#include <linux/serial_sci.h> 15#include <linux/serial_sci.h>
16#include <linux/sh_timer.h>
16#include <asm/rtc.h> 17#include <asm/rtc.h>
17 18
18enum { 19enum {
@@ -120,7 +121,102 @@ static struct platform_device sci_device = {
120 }, 121 },
121}; 122};
122 123
124static struct sh_timer_config tmu0_platform_data = {
125 .name = "TMU0",
126 .channel_offset = 0x02,
127 .timer_bit = 0,
128 .clk = "peripheral_clk",
129 .clockevent_rating = 200,
130};
131
132static struct resource tmu0_resources[] = {
133 [0] = {
134 .name = "TMU0",
135 .start = 0xa412fe94,
136 .end = 0xa412fe9f,
137 .flags = IORESOURCE_MEM,
138 },
139 [1] = {
140 .start = 16,
141 .flags = IORESOURCE_IRQ,
142 },
143};
144
145static struct platform_device tmu0_device = {
146 .name = "sh_tmu",
147 .id = 0,
148 .dev = {
149 .platform_data = &tmu0_platform_data,
150 },
151 .resource = tmu0_resources,
152 .num_resources = ARRAY_SIZE(tmu0_resources),
153};
154
155static struct sh_timer_config tmu1_platform_data = {
156 .name = "TMU1",
157 .channel_offset = 0xe,
158 .timer_bit = 1,
159 .clk = "peripheral_clk",
160 .clocksource_rating = 200,
161};
162
163static struct resource tmu1_resources[] = {
164 [0] = {
165 .name = "TMU1",
166 .start = 0xa412fea0,
167 .end = 0xa412feab,
168 .flags = IORESOURCE_MEM,
169 },
170 [1] = {
171 .start = 17,
172 .flags = IORESOURCE_IRQ,
173 },
174};
175
176static struct platform_device tmu1_device = {
177 .name = "sh_tmu",
178 .id = 1,
179 .dev = {
180 .platform_data = &tmu1_platform_data,
181 },
182 .resource = tmu1_resources,
183 .num_resources = ARRAY_SIZE(tmu1_resources),
184};
185
186static struct sh_timer_config tmu2_platform_data = {
187 .name = "TMU2",
188 .channel_offset = 0x1a,
189 .timer_bit = 2,
190 .clk = "peripheral_clk",
191};
192
193static struct resource tmu2_resources[] = {
194 [0] = {
195 .name = "TMU2",
196 .start = 0xa412feac,
197 .end = 0xa412feb5,
198 .flags = IORESOURCE_MEM,
199 },
200 [1] = {
201 .start = 18,
202 .flags = IORESOURCE_IRQ,
203 },
204};
205
206static struct platform_device tmu2_device = {
207 .name = "sh_tmu",
208 .id = 2,
209 .dev = {
210 .platform_data = &tmu2_platform_data,
211 },
212 .resource = tmu2_resources,
213 .num_resources = ARRAY_SIZE(tmu2_resources),
214};
215
123static struct platform_device *sh7710_devices[] __initdata = { 216static struct platform_device *sh7710_devices[] __initdata = {
217 &tmu0_device,
218 &tmu1_device,
219 &tmu2_device,
124 &sci_device, 220 &sci_device,
125 &rtc_device, 221 &rtc_device,
126}; 222};
@@ -132,6 +228,18 @@ static int __init sh7710_devices_setup(void)
132} 228}
133__initcall(sh7710_devices_setup); 229__initcall(sh7710_devices_setup);
134 230
231static struct platform_device *sh7710_early_devices[] __initdata = {
232 &tmu0_device,
233 &tmu1_device,
234 &tmu2_device,
235};
236
237void __init plat_early_device_setup(void)
238{
239 early_platform_add_devices(sh7710_early_devices,
240 ARRAY_SIZE(sh7710_early_devices));
241}
242
135void __init plat_irq_setup(void) 243void __init plat_irq_setup(void)
136{ 244{
137 register_intc_controller(&intc_desc); 245 register_intc_controller(&intc_desc);
diff --git a/arch/sh/kernel/cpu/sh3/setup-sh7720.c b/arch/sh/kernel/cpu/sh3/setup-sh7720.c
index 003874a2fd2a..5b2107798edb 100644
--- a/arch/sh/kernel/cpu/sh3/setup-sh7720.c
+++ b/arch/sh/kernel/cpu/sh3/setup-sh7720.c
@@ -18,6 +18,7 @@
18#include <linux/serial.h> 18#include <linux/serial.h>
19#include <linux/io.h> 19#include <linux/io.h>
20#include <linux/serial_sci.h> 20#include <linux/serial_sci.h>
21#include <linux/sh_timer.h>
21#include <asm/rtc.h> 22#include <asm/rtc.h>
22 23
23static struct resource rtc_resources[] = { 24static struct resource rtc_resources[] = {
@@ -123,7 +124,259 @@ static struct platform_device usbf_device = {
123 .resource = usbf_resources, 124 .resource = usbf_resources,
124}; 125};
125 126
127static struct sh_timer_config cmt0_platform_data = {
128 .name = "CMT0",
129 .channel_offset = 0x10,
130 .timer_bit = 0,
131 .clk = "peripheral_clk",
132 .clockevent_rating = 125,
133 .clocksource_rating = 125,
134};
135
136static struct resource cmt0_resources[] = {
137 [0] = {
138 .name = "CMT0",
139 .start = 0x044a0010,
140 .end = 0x044a001b,
141 .flags = IORESOURCE_MEM,
142 },
143 [1] = {
144 .start = 104,
145 .flags = IORESOURCE_IRQ,
146 },
147};
148
149static struct platform_device cmt0_device = {
150 .name = "sh_cmt",
151 .id = 0,
152 .dev = {
153 .platform_data = &cmt0_platform_data,
154 },
155 .resource = cmt0_resources,
156 .num_resources = ARRAY_SIZE(cmt0_resources),
157};
158
159static struct sh_timer_config cmt1_platform_data = {
160 .name = "CMT1",
161 .channel_offset = 0x20,
162 .timer_bit = 1,
163 .clk = "peripheral_clk",
164};
165
166static struct resource cmt1_resources[] = {
167 [0] = {
168 .name = "CMT1",
169 .start = 0x044a0020,
170 .end = 0x044a002b,
171 .flags = IORESOURCE_MEM,
172 },
173 [1] = {
174 .start = 104,
175 .flags = IORESOURCE_IRQ,
176 },
177};
178
179static struct platform_device cmt1_device = {
180 .name = "sh_cmt",
181 .id = 1,
182 .dev = {
183 .platform_data = &cmt1_platform_data,
184 },
185 .resource = cmt1_resources,
186 .num_resources = ARRAY_SIZE(cmt1_resources),
187};
188
189static struct sh_timer_config cmt2_platform_data = {
190 .name = "CMT2",
191 .channel_offset = 0x30,
192 .timer_bit = 2,
193 .clk = "peripheral_clk",
194};
195
196static struct resource cmt2_resources[] = {
197 [0] = {
198 .name = "CMT2",
199 .start = 0x044a0030,
200 .end = 0x044a003b,
201 .flags = IORESOURCE_MEM,
202 },
203 [1] = {
204 .start = 104,
205 .flags = IORESOURCE_IRQ,
206 },
207};
208
209static struct platform_device cmt2_device = {
210 .name = "sh_cmt",
211 .id = 2,
212 .dev = {
213 .platform_data = &cmt2_platform_data,
214 },
215 .resource = cmt2_resources,
216 .num_resources = ARRAY_SIZE(cmt2_resources),
217};
218
219static struct sh_timer_config cmt3_platform_data = {
220 .name = "CMT3",
221 .channel_offset = 0x40,
222 .timer_bit = 3,
223 .clk = "peripheral_clk",
224};
225
226static struct resource cmt3_resources[] = {
227 [0] = {
228 .name = "CMT3",
229 .start = 0x044a0040,
230 .end = 0x044a004b,
231 .flags = IORESOURCE_MEM,
232 },
233 [1] = {
234 .start = 104,
235 .flags = IORESOURCE_IRQ,
236 },
237};
238
239static struct platform_device cmt3_device = {
240 .name = "sh_cmt",
241 .id = 3,
242 .dev = {
243 .platform_data = &cmt3_platform_data,
244 },
245 .resource = cmt3_resources,
246 .num_resources = ARRAY_SIZE(cmt3_resources),
247};
248
249static struct sh_timer_config cmt4_platform_data = {
250 .name = "CMT4",
251 .channel_offset = 0x50,
252 .timer_bit = 4,
253 .clk = "peripheral_clk",
254};
255
256static struct resource cmt4_resources[] = {
257 [0] = {
258 .name = "CMT4",
259 .start = 0x044a0050,
260 .end = 0x044a005b,
261 .flags = IORESOURCE_MEM,
262 },
263 [1] = {
264 .start = 104,
265 .flags = IORESOURCE_IRQ,
266 },
267};
268
269static struct platform_device cmt4_device = {
270 .name = "sh_cmt",
271 .id = 4,
272 .dev = {
273 .platform_data = &cmt4_platform_data,
274 },
275 .resource = cmt4_resources,
276 .num_resources = ARRAY_SIZE(cmt4_resources),
277};
278
279static struct sh_timer_config tmu0_platform_data = {
280 .name = "TMU0",
281 .channel_offset = 0x02,
282 .timer_bit = 0,
283 .clk = "peripheral_clk",
284 .clockevent_rating = 200,
285};
286
287static struct resource tmu0_resources[] = {
288 [0] = {
289 .name = "TMU0",
290 .start = 0xa412fe94,
291 .end = 0xa412fe9f,
292 .flags = IORESOURCE_MEM,
293 },
294 [1] = {
295 .start = 16,
296 .flags = IORESOURCE_IRQ,
297 },
298};
299
300static struct platform_device tmu0_device = {
301 .name = "sh_tmu",
302 .id = 0,
303 .dev = {
304 .platform_data = &tmu0_platform_data,
305 },
306 .resource = tmu0_resources,
307 .num_resources = ARRAY_SIZE(tmu0_resources),
308};
309
310static struct sh_timer_config tmu1_platform_data = {
311 .name = "TMU1",
312 .channel_offset = 0xe,
313 .timer_bit = 1,
314 .clk = "peripheral_clk",
315 .clocksource_rating = 200,
316};
317
318static struct resource tmu1_resources[] = {
319 [0] = {
320 .name = "TMU1",
321 .start = 0xa412fea0,
322 .end = 0xa412feab,
323 .flags = IORESOURCE_MEM,
324 },
325 [1] = {
326 .start = 17,
327 .flags = IORESOURCE_IRQ,
328 },
329};
330
331static struct platform_device tmu1_device = {
332 .name = "sh_tmu",
333 .id = 1,
334 .dev = {
335 .platform_data = &tmu1_platform_data,
336 },
337 .resource = tmu1_resources,
338 .num_resources = ARRAY_SIZE(tmu1_resources),
339};
340
341static struct sh_timer_config tmu2_platform_data = {
342 .name = "TMU2",
343 .channel_offset = 0x1a,
344 .timer_bit = 2,
345 .clk = "peripheral_clk",
346};
347
348static struct resource tmu2_resources[] = {
349 [0] = {
350 .name = "TMU2",
351 .start = 0xa412feac,
352 .end = 0xa412feb5,
353 .flags = IORESOURCE_MEM,
354 },
355 [1] = {
356 .start = 18,
357 .flags = IORESOURCE_IRQ,
358 },
359};
360
361static struct platform_device tmu2_device = {
362 .name = "sh_tmu",
363 .id = 2,
364 .dev = {
365 .platform_data = &tmu2_platform_data,
366 },
367 .resource = tmu2_resources,
368 .num_resources = ARRAY_SIZE(tmu2_resources),
369};
370
126static struct platform_device *sh7720_devices[] __initdata = { 371static struct platform_device *sh7720_devices[] __initdata = {
372 &cmt0_device,
373 &cmt1_device,
374 &cmt2_device,
375 &cmt3_device,
376 &cmt4_device,
377 &tmu0_device,
378 &tmu1_device,
379 &tmu2_device,
127 &rtc_device, 380 &rtc_device,
128 &sci_device, 381 &sci_device,
129 &usb_ohci_device, 382 &usb_ohci_device,
@@ -137,6 +390,23 @@ static int __init sh7720_devices_setup(void)
137} 390}
138__initcall(sh7720_devices_setup); 391__initcall(sh7720_devices_setup);
139 392
393static struct platform_device *sh7720_early_devices[] __initdata = {
394 &cmt0_device,
395 &cmt1_device,
396 &cmt2_device,
397 &cmt3_device,
398 &cmt4_device,
399 &tmu0_device,
400 &tmu1_device,
401 &tmu2_device,
402};
403
404void __init plat_early_device_setup(void)
405{
406 early_platform_add_devices(sh7720_early_devices,
407 ARRAY_SIZE(sh7720_early_devices));
408}
409
140enum { 410enum {
141 UNUSED = 0, 411 UNUSED = 0,
142 412
diff --git a/arch/sh/kernel/cpu/sh4/clock-sh4-202.c b/arch/sh/kernel/cpu/sh4/clock-sh4-202.c
index a33429463e96..21421e34e7d5 100644
--- a/arch/sh/kernel/cpu/sh4/clock-sh4-202.c
+++ b/arch/sh/kernel/cpu/sh4/clock-sh4-202.c
@@ -21,10 +21,10 @@
21static int frqcr3_divisors[] = { 1, 2, 3, 4, 6, 8, 16 }; 21static int frqcr3_divisors[] = { 1, 2, 3, 4, 6, 8, 16 };
22static int frqcr3_values[] = { 0, 1, 2, 3, 4, 5, 6 }; 22static int frqcr3_values[] = { 0, 1, 2, 3, 4, 5, 6 };
23 23
24static void emi_clk_recalc(struct clk *clk) 24static unsigned long emi_clk_recalc(struct clk *clk)
25{ 25{
26 int idx = ctrl_inl(CPG2_FRQCR3) & 0x0007; 26 int idx = ctrl_inl(CPG2_FRQCR3) & 0x0007;
27 clk->rate = clk->parent->rate / frqcr3_divisors[idx]; 27 return clk->parent->rate / frqcr3_divisors[idx];
28} 28}
29 29
30static inline int frqcr3_lookup(struct clk *clk, unsigned long rate) 30static inline int frqcr3_lookup(struct clk *clk, unsigned long rate)
@@ -46,14 +46,14 @@ static struct clk_ops sh4202_emi_clk_ops = {
46 46
47static struct clk sh4202_emi_clk = { 47static struct clk sh4202_emi_clk = {
48 .name = "emi_clk", 48 .name = "emi_clk",
49 .flags = CLK_ALWAYS_ENABLED, 49 .flags = CLK_ENABLE_ON_INIT,
50 .ops = &sh4202_emi_clk_ops, 50 .ops = &sh4202_emi_clk_ops,
51}; 51};
52 52
53static void femi_clk_recalc(struct clk *clk) 53static unsigned long femi_clk_recalc(struct clk *clk)
54{ 54{
55 int idx = (ctrl_inl(CPG2_FRQCR3) >> 3) & 0x0007; 55 int idx = (ctrl_inl(CPG2_FRQCR3) >> 3) & 0x0007;
56 clk->rate = clk->parent->rate / frqcr3_divisors[idx]; 56 return clk->parent->rate / frqcr3_divisors[idx];
57} 57}
58 58
59static struct clk_ops sh4202_femi_clk_ops = { 59static struct clk_ops sh4202_femi_clk_ops = {
@@ -62,7 +62,7 @@ static struct clk_ops sh4202_femi_clk_ops = {
62 62
63static struct clk sh4202_femi_clk = { 63static struct clk sh4202_femi_clk = {
64 .name = "femi_clk", 64 .name = "femi_clk",
65 .flags = CLK_ALWAYS_ENABLED, 65 .flags = CLK_ENABLE_ON_INIT,
66 .ops = &sh4202_femi_clk_ops, 66 .ops = &sh4202_femi_clk_ops,
67}; 67};
68 68
@@ -90,10 +90,10 @@ static void shoc_clk_init(struct clk *clk)
90 WARN_ON(i == ARRAY_SIZE(frqcr3_divisors)); /* Undefined clock */ 90 WARN_ON(i == ARRAY_SIZE(frqcr3_divisors)); /* Undefined clock */
91} 91}
92 92
93static void shoc_clk_recalc(struct clk *clk) 93static unsigned long shoc_clk_recalc(struct clk *clk)
94{ 94{
95 int idx = (ctrl_inl(CPG2_FRQCR3) >> 6) & 0x0007; 95 int idx = (ctrl_inl(CPG2_FRQCR3) >> 6) & 0x0007;
96 clk->rate = clk->parent->rate / frqcr3_divisors[idx]; 96 return clk->parent->rate / frqcr3_divisors[idx];
97} 97}
98 98
99static int shoc_clk_verify_rate(struct clk *clk, unsigned long rate) 99static int shoc_clk_verify_rate(struct clk *clk, unsigned long rate)
@@ -140,7 +140,7 @@ static struct clk_ops sh4202_shoc_clk_ops = {
140 140
141static struct clk sh4202_shoc_clk = { 141static struct clk sh4202_shoc_clk = {
142 .name = "shoc_clk", 142 .name = "shoc_clk",
143 .flags = CLK_ALWAYS_ENABLED, 143 .flags = CLK_ENABLE_ON_INIT,
144 .ops = &sh4202_shoc_clk_ops, 144 .ops = &sh4202_shoc_clk_ops,
145}; 145};
146 146
@@ -150,31 +150,22 @@ static struct clk *sh4202_onchip_clocks[] = {
150 &sh4202_shoc_clk, 150 &sh4202_shoc_clk,
151}; 151};
152 152
153static int __init sh4202_clk_init(void) 153int __init arch_clk_init(void)
154{ 154{
155 struct clk *clk = clk_get(NULL, "master_clk"); 155 struct clk *clk;
156 int i; 156 int i, ret = 0;
157
158 cpg_clk_init();
157 159
160 clk = clk_get(NULL, "master_clk");
158 for (i = 0; i < ARRAY_SIZE(sh4202_onchip_clocks); i++) { 161 for (i = 0; i < ARRAY_SIZE(sh4202_onchip_clocks); i++) {
159 struct clk *clkp = sh4202_onchip_clocks[i]; 162 struct clk *clkp = sh4202_onchip_clocks[i];
160 163
161 clkp->parent = clk; 164 clkp->parent = clk;
162 clk_register(clkp); 165 ret |= clk_register(clkp);
163 clk_enable(clkp);
164 } 166 }
165 167
166 /*
167 * Now that we have the rest of the clocks registered, we need to
168 * force the parent clock to propagate so that these clocks will
169 * automatically figure out their rate. We cheat by handing the
170 * parent clock its current rate and forcing child propagation.
171 */
172 clk_set_rate(clk, clk_get_rate(clk));
173
174 clk_put(clk); 168 clk_put(clk);
175 169
176 return 0; 170 return ret;
177} 171}
178
179arch_initcall(sh4202_clk_init);
180
diff --git a/arch/sh/kernel/cpu/sh4/clock-sh4.c b/arch/sh/kernel/cpu/sh4/clock-sh4.c
index dca9f87a12d6..73294d9cd049 100644
--- a/arch/sh/kernel/cpu/sh4/clock-sh4.c
+++ b/arch/sh/kernel/cpu/sh4/clock-sh4.c
@@ -35,30 +35,30 @@ static struct clk_ops sh4_master_clk_ops = {
35 .init = master_clk_init, 35 .init = master_clk_init,
36}; 36};
37 37
38static void module_clk_recalc(struct clk *clk) 38static unsigned long module_clk_recalc(struct clk *clk)
39{ 39{
40 int idx = (ctrl_inw(FRQCR) & 0x0007); 40 int idx = (ctrl_inw(FRQCR) & 0x0007);
41 clk->rate = clk->parent->rate / pfc_divisors[idx]; 41 return clk->parent->rate / pfc_divisors[idx];
42} 42}
43 43
44static struct clk_ops sh4_module_clk_ops = { 44static struct clk_ops sh4_module_clk_ops = {
45 .recalc = module_clk_recalc, 45 .recalc = module_clk_recalc,
46}; 46};
47 47
48static void bus_clk_recalc(struct clk *clk) 48static unsigned long bus_clk_recalc(struct clk *clk)
49{ 49{
50 int idx = (ctrl_inw(FRQCR) >> 3) & 0x0007; 50 int idx = (ctrl_inw(FRQCR) >> 3) & 0x0007;
51 clk->rate = clk->parent->rate / bfc_divisors[idx]; 51 return clk->parent->rate / bfc_divisors[idx];
52} 52}
53 53
54static struct clk_ops sh4_bus_clk_ops = { 54static struct clk_ops sh4_bus_clk_ops = {
55 .recalc = bus_clk_recalc, 55 .recalc = bus_clk_recalc,
56}; 56};
57 57
58static void cpu_clk_recalc(struct clk *clk) 58static unsigned long cpu_clk_recalc(struct clk *clk)
59{ 59{
60 int idx = (ctrl_inw(FRQCR) >> 6) & 0x0007; 60 int idx = (ctrl_inw(FRQCR) >> 6) & 0x0007;
61 clk->rate = clk->parent->rate / ifc_divisors[idx]; 61 return clk->parent->rate / ifc_divisors[idx];
62} 62}
63 63
64static struct clk_ops sh4_cpu_clk_ops = { 64static struct clk_ops sh4_cpu_clk_ops = {
diff --git a/arch/sh/kernel/cpu/sh4/probe.c b/arch/sh/kernel/cpu/sh4/probe.c
index 91e3677ae09d..6c78d0a9c857 100644
--- a/arch/sh/kernel/cpu/sh4/probe.c
+++ b/arch/sh/kernel/cpu/sh4/probe.c
@@ -60,12 +60,18 @@ int __init detect_cpu_and_cache_system(void)
60 if ((cvr & 0x10000000) == 0) 60 if ((cvr & 0x10000000) == 0)
61 boot_cpu_data.flags |= CPU_HAS_DSP; 61 boot_cpu_data.flags |= CPU_HAS_DSP;
62 62
63 boot_cpu_data.flags |= CPU_HAS_LLSC; 63 boot_cpu_data.flags |= CPU_HAS_LLSC | CPU_HAS_PERF_COUNTER;
64 boot_cpu_data.cut_major = pvr & 0x7f; 64 boot_cpu_data.cut_major = pvr & 0x7f;
65
66 boot_cpu_data.icache.ways = 4;
67 boot_cpu_data.dcache.ways = 4;
68 } else {
69 /* And some SH-4 defaults.. */
70 boot_cpu_data.flags |= CPU_HAS_PTEA;
65 } 71 }
66 72
67 /* FPU detection works for everyone */ 73 /* FPU detection works for everyone */
68 if ((cvr & 0x20000000) == 1) 74 if ((cvr & 0x20000000))
69 boot_cpu_data.flags |= CPU_HAS_FPU; 75 boot_cpu_data.flags |= CPU_HAS_FPU;
70 76
71 /* Mask off the upper chip ID */ 77 /* Mask off the upper chip ID */
@@ -78,25 +84,20 @@ int __init detect_cpu_and_cache_system(void)
78 switch (pvr) { 84 switch (pvr) {
79 case 0x205: 85 case 0x205:
80 boot_cpu_data.type = CPU_SH7750; 86 boot_cpu_data.type = CPU_SH7750;
81 boot_cpu_data.flags |= CPU_HAS_P2_FLUSH_BUG | CPU_HAS_FPU | 87 boot_cpu_data.flags |= CPU_HAS_P2_FLUSH_BUG |
82 CPU_HAS_PERF_COUNTER; 88 CPU_HAS_PERF_COUNTER;
83 break; 89 break;
84 case 0x206: 90 case 0x206:
85 boot_cpu_data.type = CPU_SH7750S; 91 boot_cpu_data.type = CPU_SH7750S;
86 boot_cpu_data.flags |= CPU_HAS_P2_FLUSH_BUG | CPU_HAS_FPU | 92 boot_cpu_data.flags |= CPU_HAS_P2_FLUSH_BUG |
87 CPU_HAS_PERF_COUNTER; 93 CPU_HAS_PERF_COUNTER;
88 break; 94 break;
89 case 0x1100: 95 case 0x1100:
90 boot_cpu_data.type = CPU_SH7751; 96 boot_cpu_data.type = CPU_SH7751;
91 boot_cpu_data.flags |= CPU_HAS_FPU;
92 break; 97 break;
93 case 0x2001: 98 case 0x2001:
94 case 0x2004: 99 case 0x2004:
95 boot_cpu_data.type = CPU_SH7770; 100 boot_cpu_data.type = CPU_SH7770;
96 boot_cpu_data.icache.ways = 4;
97 boot_cpu_data.dcache.ways = 4;
98
99 boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_LLSC;
100 break; 101 break;
101 case 0x2006: 102 case 0x2006:
102 case 0x200A: 103 case 0x200A:
@@ -107,45 +108,26 @@ int __init detect_cpu_and_cache_system(void)
107 else 108 else
108 boot_cpu_data.type = CPU_SH7780; 109 boot_cpu_data.type = CPU_SH7780;
109 110
110 boot_cpu_data.icache.ways = 4;
111 boot_cpu_data.dcache.ways = 4;
112
113 boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
114 CPU_HAS_LLSC;
115 break; 111 break;
116 case 0x3000: 112 case 0x3000:
117 case 0x3003: 113 case 0x3003:
118 case 0x3009: 114 case 0x3009:
119 boot_cpu_data.type = CPU_SH7343; 115 boot_cpu_data.type = CPU_SH7343;
120 boot_cpu_data.icache.ways = 4;
121 boot_cpu_data.dcache.ways = 4;
122 boot_cpu_data.flags |= CPU_HAS_LLSC;
123 break; 116 break;
124 case 0x3004: 117 case 0x3004:
125 case 0x3007: 118 case 0x3007:
126 boot_cpu_data.type = CPU_SH7785; 119 boot_cpu_data.type = CPU_SH7785;
127 boot_cpu_data.icache.ways = 4;
128 boot_cpu_data.dcache.ways = 4;
129 boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
130 CPU_HAS_LLSC;
131 break; 120 break;
132 case 0x4004: 121 case 0x4004:
133 boot_cpu_data.type = CPU_SH7786; 122 boot_cpu_data.type = CPU_SH7786;
134 boot_cpu_data.icache.ways = 4; 123 boot_cpu_data.flags |= CPU_HAS_PTEAEX | CPU_HAS_L2_CACHE;
135 boot_cpu_data.dcache.ways = 4;
136 boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
137 CPU_HAS_LLSC | CPU_HAS_PTEAEX;
138 break; 124 break;
139 case 0x3008: 125 case 0x3008:
140 boot_cpu_data.icache.ways = 4;
141 boot_cpu_data.dcache.ways = 4;
142 boot_cpu_data.flags |= CPU_HAS_LLSC;
143
144 switch (prr) { 126 switch (prr) {
145 case 0x50: 127 case 0x50:
146 case 0x51: 128 case 0x51:
147 boot_cpu_data.type = CPU_SH7723; 129 boot_cpu_data.type = CPU_SH7723;
148 boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_L2_CACHE; 130 boot_cpu_data.flags |= CPU_HAS_L2_CACHE;
149 break; 131 break;
150 case 0x70: 132 case 0x70:
151 boot_cpu_data.type = CPU_SH7366; 133 boot_cpu_data.type = CPU_SH7366;
@@ -156,13 +138,13 @@ int __init detect_cpu_and_cache_system(void)
156 break; 138 break;
157 } 139 }
158 break; 140 break;
141 case 0x300b:
142 boot_cpu_data.type = CPU_SH7724;
143 boot_cpu_data.flags |= CPU_HAS_L2_CACHE;
144 break;
159 case 0x4000: /* 1st cut */ 145 case 0x4000: /* 1st cut */
160 case 0x4001: /* 2nd cut */ 146 case 0x4001: /* 2nd cut */
161 boot_cpu_data.type = CPU_SHX3; 147 boot_cpu_data.type = CPU_SHX3;
162 boot_cpu_data.icache.ways = 4;
163 boot_cpu_data.dcache.ways = 4;
164 boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
165 CPU_HAS_LLSC;
166 break; 148 break;
167 case 0x700: 149 case 0x700:
168 boot_cpu_data.type = CPU_SH4_501; 150 boot_cpu_data.type = CPU_SH4_501;
@@ -173,7 +155,6 @@ int __init detect_cpu_and_cache_system(void)
173 boot_cpu_data.type = CPU_SH4_202; 155 boot_cpu_data.type = CPU_SH4_202;
174 boot_cpu_data.icache.ways = 2; 156 boot_cpu_data.icache.ways = 2;
175 boot_cpu_data.dcache.ways = 2; 157 boot_cpu_data.dcache.ways = 2;
176 boot_cpu_data.flags |= CPU_HAS_FPU;
177 break; 158 break;
178 case 0x500 ... 0x501: 159 case 0x500 ... 0x501:
179 switch (prr) { 160 switch (prr) {
@@ -191,18 +172,12 @@ int __init detect_cpu_and_cache_system(void)
191 boot_cpu_data.icache.ways = 2; 172 boot_cpu_data.icache.ways = 2;
192 boot_cpu_data.dcache.ways = 2; 173 boot_cpu_data.dcache.ways = 2;
193 174
194 boot_cpu_data.flags |= CPU_HAS_FPU;
195
196 break; 175 break;
197 default: 176 default:
198 boot_cpu_data.type = CPU_SH_NONE; 177 boot_cpu_data.type = CPU_SH_NONE;
199 break; 178 break;
200 } 179 }
201 180
202#ifdef CONFIG_CPU_HAS_PTEA
203 boot_cpu_data.flags |= CPU_HAS_PTEA;
204#endif
205
206 /* 181 /*
207 * On anything that's not a direct-mapped cache, look to the CVR 182 * On anything that's not a direct-mapped cache, look to the CVR
208 * for I/D-cache specifics. 183 * for I/D-cache specifics.
@@ -222,43 +197,48 @@ int __init detect_cpu_and_cache_system(void)
222 } 197 }
223 198
224 /* 199 /*
225 * Setup the L2 cache desc
226 *
227 * SH-4A's have an optional PIPT L2. 200 * SH-4A's have an optional PIPT L2.
228 */ 201 */
229 if (boot_cpu_data.flags & CPU_HAS_L2_CACHE) { 202 if (boot_cpu_data.flags & CPU_HAS_L2_CACHE) {
230 /* Bug if we can't decode the L2 info */
231 BUG_ON(!(cvr & 0xf));
232
233 /* Silicon and specifications have clearly never met.. */
234 cvr ^= 0xf;
235
236 /* 203 /*
237 * Size calculation is much more sensible 204 * Verify that it really has something hooked up, this
238 * than it is for the L1. 205 * is the safety net for CPUs that have optional L2
239 * 206 * support yet do not implement it.
240 * Sizes are 128KB, 258KB, 512KB, and 1MB.
241 */ 207 */
242 size = (cvr & 0xf) << 17; 208 if ((cvr & 0xf) == 0)
243 209 boot_cpu_data.flags &= ~CPU_HAS_L2_CACHE;
244 BUG_ON(!size); 210 else {
245 211 /*
246 boot_cpu_data.scache.way_incr = (1 << 16); 212 * Silicon and specifications have clearly never
247 boot_cpu_data.scache.entry_shift = 5; 213 * met..
248 boot_cpu_data.scache.ways = 4; 214 */
249 boot_cpu_data.scache.linesz = L1_CACHE_BYTES; 215 cvr ^= 0xf;
250 216
251 boot_cpu_data.scache.entry_mask = 217 /*
252 (boot_cpu_data.scache.way_incr - 218 * Size calculation is much more sensible
253 boot_cpu_data.scache.linesz); 219 * than it is for the L1.
254 220 *
255 boot_cpu_data.scache.sets = size / 221 * Sizes are 128KB, 258KB, 512KB, and 1MB.
256 (boot_cpu_data.scache.linesz * 222 */
257 boot_cpu_data.scache.ways); 223 size = (cvr & 0xf) << 17;
258 224
259 boot_cpu_data.scache.way_size = 225 boot_cpu_data.scache.way_incr = (1 << 16);
260 (boot_cpu_data.scache.sets * 226 boot_cpu_data.scache.entry_shift = 5;
261 boot_cpu_data.scache.linesz); 227 boot_cpu_data.scache.ways = 4;
228 boot_cpu_data.scache.linesz = L1_CACHE_BYTES;
229
230 boot_cpu_data.scache.entry_mask =
231 (boot_cpu_data.scache.way_incr -
232 boot_cpu_data.scache.linesz);
233
234 boot_cpu_data.scache.sets = size /
235 (boot_cpu_data.scache.linesz *
236 boot_cpu_data.scache.ways);
237
238 boot_cpu_data.scache.way_size =
239 (boot_cpu_data.scache.sets *
240 boot_cpu_data.scache.linesz);
241 }
262 } 242 }
263 243
264 return 0; 244 return 0;
diff --git a/arch/sh/kernel/cpu/sh4/setup-sh4-202.c b/arch/sh/kernel/cpu/sh4/setup-sh4-202.c
index 7371abf64f80..6d088d123591 100644
--- a/arch/sh/kernel/cpu/sh4/setup-sh4-202.c
+++ b/arch/sh/kernel/cpu/sh4/setup-sh4-202.c
@@ -2,6 +2,7 @@
2 * SH4-202 Setup 2 * SH4-202 Setup
3 * 3 *
4 * Copyright (C) 2006 Paul Mundt 4 * Copyright (C) 2006 Paul Mundt
5 * Copyright (C) 2009 Magnus Damm
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public 7 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive 8 * License. See the file "COPYING" in the main directory of this archive
@@ -11,6 +12,8 @@
11#include <linux/init.h> 12#include <linux/init.h>
12#include <linux/serial.h> 13#include <linux/serial.h>
13#include <linux/serial_sci.h> 14#include <linux/serial_sci.h>
15#include <linux/sh_timer.h>
16#include <linux/io.h>
14 17
15static struct plat_sci_port sci_platform_data[] = { 18static struct plat_sci_port sci_platform_data[] = {
16 { 19 {
@@ -31,8 +34,103 @@ static struct platform_device sci_device = {
31 }, 34 },
32}; 35};
33 36
37static struct sh_timer_config tmu0_platform_data = {
38 .name = "TMU0",
39 .channel_offset = 0x04,
40 .timer_bit = 0,
41 .clk = "peripheral_clk",
42 .clockevent_rating = 200,
43};
44
45static struct resource tmu0_resources[] = {
46 [0] = {
47 .name = "TMU0",
48 .start = 0xffd80008,
49 .end = 0xffd80013,
50 .flags = IORESOURCE_MEM,
51 },
52 [1] = {
53 .start = 16,
54 .flags = IORESOURCE_IRQ,
55 },
56};
57
58static struct platform_device tmu0_device = {
59 .name = "sh_tmu",
60 .id = 0,
61 .dev = {
62 .platform_data = &tmu0_platform_data,
63 },
64 .resource = tmu0_resources,
65 .num_resources = ARRAY_SIZE(tmu0_resources),
66};
67
68static struct sh_timer_config tmu1_platform_data = {
69 .name = "TMU1",
70 .channel_offset = 0x10,
71 .timer_bit = 1,
72 .clk = "peripheral_clk",
73 .clocksource_rating = 200,
74};
75
76static struct resource tmu1_resources[] = {
77 [0] = {
78 .name = "TMU1",
79 .start = 0xffd80014,
80 .end = 0xffd8001f,
81 .flags = IORESOURCE_MEM,
82 },
83 [1] = {
84 .start = 17,
85 .flags = IORESOURCE_IRQ,
86 },
87};
88
89static struct platform_device tmu1_device = {
90 .name = "sh_tmu",
91 .id = 1,
92 .dev = {
93 .platform_data = &tmu1_platform_data,
94 },
95 .resource = tmu1_resources,
96 .num_resources = ARRAY_SIZE(tmu1_resources),
97};
98
99static struct sh_timer_config tmu2_platform_data = {
100 .name = "TMU2",
101 .channel_offset = 0x1c,
102 .timer_bit = 2,
103 .clk = "peripheral_clk",
104};
105
106static struct resource tmu2_resources[] = {
107 [0] = {
108 .name = "TMU2",
109 .start = 0xffd80020,
110 .end = 0xffd8002f,
111 .flags = IORESOURCE_MEM,
112 },
113 [1] = {
114 .start = 18,
115 .flags = IORESOURCE_IRQ,
116 },
117};
118
119static struct platform_device tmu2_device = {
120 .name = "sh_tmu",
121 .id = 2,
122 .dev = {
123 .platform_data = &tmu2_platform_data,
124 },
125 .resource = tmu2_resources,
126 .num_resources = ARRAY_SIZE(tmu2_resources),
127};
128
34static struct platform_device *sh4202_devices[] __initdata = { 129static struct platform_device *sh4202_devices[] __initdata = {
35 &sci_device, 130 &sci_device,
131 &tmu0_device,
132 &tmu1_device,
133 &tmu2_device,
36}; 134};
37 135
38static int __init sh4202_devices_setup(void) 136static int __init sh4202_devices_setup(void)
@@ -42,7 +140,71 @@ static int __init sh4202_devices_setup(void)
42} 140}
43__initcall(sh4202_devices_setup); 141__initcall(sh4202_devices_setup);
44 142
143static struct platform_device *sh4202_early_devices[] __initdata = {
144 &tmu0_device,
145 &tmu1_device,
146 &tmu2_device,
147};
148
149void __init plat_early_device_setup(void)
150{
151 early_platform_add_devices(sh4202_early_devices,
152 ARRAY_SIZE(sh4202_early_devices));
153}
154
155enum {
156 UNUSED = 0,
157
158 /* interrupt sources */
159 IRL0, IRL1, IRL2, IRL3, /* only IRLM mode supported */
160 HUDI, TMU0, TMU1, TMU2, RTC, SCIF, WDT,
161};
162
163static struct intc_vect vectors[] __initdata = {
164 INTC_VECT(HUDI, 0x600),
165 INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
166 INTC_VECT(TMU2, 0x440), INTC_VECT(TMU2, 0x460),
167 INTC_VECT(RTC, 0x480), INTC_VECT(RTC, 0x4a0),
168 INTC_VECT(RTC, 0x4c0),
169 INTC_VECT(SCIF, 0x700), INTC_VECT(SCIF, 0x720),
170 INTC_VECT(SCIF, 0x740), INTC_VECT(SCIF, 0x760),
171 INTC_VECT(WDT, 0x560),
172};
173
174static struct intc_prio_reg prio_registers[] __initdata = {
175 { 0xffd00004, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } },
176 { 0xffd00008, 0, 16, 4, /* IPRB */ { WDT, 0, 0, 0 } },
177 { 0xffd0000c, 0, 16, 4, /* IPRC */ { 0, 0, SCIF, HUDI } },
178 { 0xffd00010, 0, 16, 4, /* IPRD */ { IRL0, IRL1, IRL2, IRL3 } },
179};
180
181static DECLARE_INTC_DESC(intc_desc, "sh4-202", vectors, NULL,
182 NULL, prio_registers, NULL);
183
184static struct intc_vect vectors_irlm[] __initdata = {
185 INTC_VECT(IRL0, 0x240), INTC_VECT(IRL1, 0x2a0),
186 INTC_VECT(IRL2, 0x300), INTC_VECT(IRL3, 0x360),
187};
188
189static DECLARE_INTC_DESC(intc_desc_irlm, "sh4-202_irlm", vectors_irlm, NULL,
190 NULL, prio_registers, NULL);
191
45void __init plat_irq_setup(void) 192void __init plat_irq_setup(void)
46{ 193{
47 /* do nothing - all IRL interrupts are handled by the board code */ 194 register_intc_controller(&intc_desc);
195}
196
197#define INTC_ICR 0xffd00000UL
198#define INTC_ICR_IRLM (1<<7)
199
200void __init plat_irq_setup_pins(int mode)
201{
202 switch (mode) {
203 case IRQ_MODE_IRQ: /* individual interrupt mode for IRL3-0 */
204 ctrl_outw(ctrl_inw(INTC_ICR) | INTC_ICR_IRLM, INTC_ICR);
205 register_intc_controller(&intc_desc_irlm);
206 break;
207 default:
208 BUG();
209 }
48} 210}
diff --git a/arch/sh/kernel/cpu/sh4/setup-sh7750.c b/arch/sh/kernel/cpu/sh4/setup-sh7750.c
index a1c80d909cd6..851672d15cf4 100644
--- a/arch/sh/kernel/cpu/sh4/setup-sh7750.c
+++ b/arch/sh/kernel/cpu/sh4/setup-sh7750.c
@@ -12,6 +12,7 @@
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/serial.h> 13#include <linux/serial.h>
14#include <linux/io.h> 14#include <linux/io.h>
15#include <linux/sh_timer.h>
15#include <linux/serial_sci.h> 16#include <linux/serial_sci.h>
16 17
17static struct resource rtc_resources[] = { 18static struct resource rtc_resources[] = {
@@ -60,9 +61,177 @@ static struct platform_device sci_device = {
60 }, 61 },
61}; 62};
62 63
64static struct sh_timer_config tmu0_platform_data = {
65 .name = "TMU0",
66 .channel_offset = 0x04,
67 .timer_bit = 0,
68 .clk = "peripheral_clk",
69 .clockevent_rating = 200,
70};
71
72static struct resource tmu0_resources[] = {
73 [0] = {
74 .name = "TMU0",
75 .start = 0xffd80008,
76 .end = 0xffd80013,
77 .flags = IORESOURCE_MEM,
78 },
79 [1] = {
80 .start = 16,
81 .flags = IORESOURCE_IRQ,
82 },
83};
84
85static struct platform_device tmu0_device = {
86 .name = "sh_tmu",
87 .id = 0,
88 .dev = {
89 .platform_data = &tmu0_platform_data,
90 },
91 .resource = tmu0_resources,
92 .num_resources = ARRAY_SIZE(tmu0_resources),
93};
94
95static struct sh_timer_config tmu1_platform_data = {
96 .name = "TMU1",
97 .channel_offset = 0x10,
98 .timer_bit = 1,
99 .clk = "peripheral_clk",
100 .clocksource_rating = 200,
101};
102
103static struct resource tmu1_resources[] = {
104 [0] = {
105 .name = "TMU1",
106 .start = 0xffd80014,
107 .end = 0xffd8001f,
108 .flags = IORESOURCE_MEM,
109 },
110 [1] = {
111 .start = 17,
112 .flags = IORESOURCE_IRQ,
113 },
114};
115
116static struct platform_device tmu1_device = {
117 .name = "sh_tmu",
118 .id = 1,
119 .dev = {
120 .platform_data = &tmu1_platform_data,
121 },
122 .resource = tmu1_resources,
123 .num_resources = ARRAY_SIZE(tmu1_resources),
124};
125
126static struct sh_timer_config tmu2_platform_data = {
127 .name = "TMU2",
128 .channel_offset = 0x1c,
129 .timer_bit = 2,
130 .clk = "peripheral_clk",
131};
132
133static struct resource tmu2_resources[] = {
134 [0] = {
135 .name = "TMU2",
136 .start = 0xffd80020,
137 .end = 0xffd8002f,
138 .flags = IORESOURCE_MEM,
139 },
140 [1] = {
141 .start = 18,
142 .flags = IORESOURCE_IRQ,
143 },
144};
145
146static struct platform_device tmu2_device = {
147 .name = "sh_tmu",
148 .id = 2,
149 .dev = {
150 .platform_data = &tmu2_platform_data,
151 },
152 .resource = tmu2_resources,
153 .num_resources = ARRAY_SIZE(tmu2_resources),
154};
155
156/* SH7750R, SH7751 and SH7751R all have two extra timer channels */
157#if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
158 defined(CONFIG_CPU_SUBTYPE_SH7751) || \
159 defined(CONFIG_CPU_SUBTYPE_SH7751R)
160
161static struct sh_timer_config tmu3_platform_data = {
162 .name = "TMU3",
163 .channel_offset = 0x04,
164 .timer_bit = 0,
165 .clk = "peripheral_clk",
166};
167
168static struct resource tmu3_resources[] = {
169 [0] = {
170 .name = "TMU3",
171 .start = 0xfe100008,
172 .end = 0xfe100013,
173 .flags = IORESOURCE_MEM,
174 },
175 [1] = {
176 .start = 72,
177 .flags = IORESOURCE_IRQ,
178 },
179};
180
181static struct platform_device tmu3_device = {
182 .name = "sh_tmu",
183 .id = 3,
184 .dev = {
185 .platform_data = &tmu3_platform_data,
186 },
187 .resource = tmu3_resources,
188 .num_resources = ARRAY_SIZE(tmu3_resources),
189};
190
191static struct sh_timer_config tmu4_platform_data = {
192 .name = "TMU4",
193 .channel_offset = 0x10,
194 .timer_bit = 1,
195 .clk = "peripheral_clk",
196};
197
198static struct resource tmu4_resources[] = {
199 [0] = {
200 .name = "TMU4",
201 .start = 0xfe100014,
202 .end = 0xfe10001f,
203 .flags = IORESOURCE_MEM,
204 },
205 [1] = {
206 .start = 76,
207 .flags = IORESOURCE_IRQ,
208 },
209};
210
211static struct platform_device tmu4_device = {
212 .name = "sh_tmu",
213 .id = 4,
214 .dev = {
215 .platform_data = &tmu4_platform_data,
216 },
217 .resource = tmu4_resources,
218 .num_resources = ARRAY_SIZE(tmu4_resources),
219};
220
221#endif
222
63static struct platform_device *sh7750_devices[] __initdata = { 223static struct platform_device *sh7750_devices[] __initdata = {
64 &rtc_device, 224 &rtc_device,
65 &sci_device, 225 &sci_device,
226 &tmu0_device,
227 &tmu1_device,
228 &tmu2_device,
229#if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
230 defined(CONFIG_CPU_SUBTYPE_SH7751) || \
231 defined(CONFIG_CPU_SUBTYPE_SH7751R)
232 &tmu3_device,
233 &tmu4_device,
234#endif
66}; 235};
67 236
68static int __init sh7750_devices_setup(void) 237static int __init sh7750_devices_setup(void)
@@ -72,6 +241,24 @@ static int __init sh7750_devices_setup(void)
72} 241}
73__initcall(sh7750_devices_setup); 242__initcall(sh7750_devices_setup);
74 243
244static struct platform_device *sh7750_early_devices[] __initdata = {
245 &tmu0_device,
246 &tmu1_device,
247 &tmu2_device,
248#if defined(CONFIG_CPU_SUBTYPE_SH7750R) || \
249 defined(CONFIG_CPU_SUBTYPE_SH7751) || \
250 defined(CONFIG_CPU_SUBTYPE_SH7751R)
251 &tmu3_device,
252 &tmu4_device,
253#endif
254};
255
256void __init plat_early_device_setup(void)
257{
258 early_platform_add_devices(sh7750_early_devices,
259 ARRAY_SIZE(sh7750_early_devices));
260}
261
75enum { 262enum {
76 UNUSED = 0, 263 UNUSED = 0,
77 264
diff --git a/arch/sh/kernel/cpu/sh4/setup-sh7760.c b/arch/sh/kernel/cpu/sh4/setup-sh7760.c
index d9bdc931ac09..5b822519bd90 100644
--- a/arch/sh/kernel/cpu/sh4/setup-sh7760.c
+++ b/arch/sh/kernel/cpu/sh4/setup-sh7760.c
@@ -10,6 +10,7 @@
10#include <linux/platform_device.h> 10#include <linux/platform_device.h>
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/serial.h> 12#include <linux/serial.h>
13#include <linux/sh_timer.h>
13#include <linux/serial_sci.h> 14#include <linux/serial_sci.h>
14#include <linux/io.h> 15#include <linux/io.h>
15 16
@@ -18,10 +19,7 @@ enum {
18 19
19 /* interrupt sources */ 20 /* interrupt sources */
20 IRL0, IRL1, IRL2, IRL3, 21 IRL0, IRL1, IRL2, IRL3,
21 HUDI, GPIOI, 22 HUDI, GPIOI, DMAC,
22 DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2, DMAC_DMTE3,
23 DMAC_DMTE4, DMAC_DMTE5, DMAC_DMTE6, DMAC_DMTE7,
24 DMAC_DMAE,
25 IRQ4, IRQ5, IRQ6, IRQ7, 23 IRQ4, IRQ5, IRQ6, IRQ7,
26 HCAN20, HCAN21, 24 HCAN20, HCAN21,
27 SSI0, SSI1, 25 SSI0, SSI1,
@@ -36,21 +34,20 @@ enum {
36 HSPI, 34 HSPI,
37 MMCIF0, MMCIF1, MMCIF2, MMCIF3, 35 MMCIF0, MMCIF1, MMCIF2, MMCIF3,
38 MFI, ADC, CMT, 36 MFI, ADC, CMT,
39 TMU0, TMU1, TMU2_TUNI, TMU2_TICPI, 37 TMU0, TMU1, TMU2,
40 WDT, 38 WDT, REF,
41 REF_RCMI, REF_ROVI,
42 39
43 /* interrupt groups */ 40 /* interrupt groups */
44 DMAC, DMABRG, SCIF0, SCIF1, SCIF2, SIM, MMCIF, TMU2, REF, 41 DMABRG, SCIF0, SCIF1, SCIF2, SIM, MMCIF,
45}; 42};
46 43
47static struct intc_vect vectors[] __initdata = { 44static struct intc_vect vectors[] __initdata = {
48 INTC_VECT(HUDI, 0x600), INTC_VECT(GPIOI, 0x620), 45 INTC_VECT(HUDI, 0x600), INTC_VECT(GPIOI, 0x620),
49 INTC_VECT(DMAC_DMTE0, 0x640), INTC_VECT(DMAC_DMTE1, 0x660), 46 INTC_VECT(DMAC, 0x640), INTC_VECT(DMAC, 0x660),
50 INTC_VECT(DMAC_DMTE2, 0x680), INTC_VECT(DMAC_DMTE3, 0x6a0), 47 INTC_VECT(DMAC, 0x680), INTC_VECT(DMAC, 0x6a0),
51 INTC_VECT(DMAC_DMTE4, 0x780), INTC_VECT(DMAC_DMTE5, 0x7a0), 48 INTC_VECT(DMAC, 0x780), INTC_VECT(DMAC, 0x7a0),
52 INTC_VECT(DMAC_DMTE6, 0x7c0), INTC_VECT(DMAC_DMTE7, 0x7e0), 49 INTC_VECT(DMAC, 0x7c0), INTC_VECT(DMAC, 0x7e0),
53 INTC_VECT(DMAC_DMAE, 0x6c0), 50 INTC_VECT(DMAC, 0x6c0),
54 INTC_VECT(IRQ4, 0x800), INTC_VECT(IRQ5, 0x820), 51 INTC_VECT(IRQ4, 0x800), INTC_VECT(IRQ5, 0x820),
55 INTC_VECT(IRQ6, 0x840), INTC_VECT(IRQ6, 0x860), 52 INTC_VECT(IRQ6, 0x840), INTC_VECT(IRQ6, 0x860),
56 INTC_VECT(HCAN20, 0x900), INTC_VECT(HCAN21, 0x920), 53 INTC_VECT(HCAN20, 0x900), INTC_VECT(HCAN21, 0x920),
@@ -74,23 +71,18 @@ static struct intc_vect vectors[] __initdata = {
74 INTC_VECT(MFI, 0xe80), /* 0xf80 according to data sheet */ 71 INTC_VECT(MFI, 0xe80), /* 0xf80 according to data sheet */
75 INTC_VECT(ADC, 0xf80), INTC_VECT(CMT, 0xfa0), 72 INTC_VECT(ADC, 0xf80), INTC_VECT(CMT, 0xfa0),
76 INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420), 73 INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
77 INTC_VECT(TMU2_TUNI, 0x440), INTC_VECT(TMU2_TICPI, 0x460), 74 INTC_VECT(TMU2, 0x440), INTC_VECT(TMU2, 0x460),
78 INTC_VECT(WDT, 0x560), 75 INTC_VECT(WDT, 0x560),
79 INTC_VECT(REF_RCMI, 0x580), INTC_VECT(REF_ROVI, 0x5a0), 76 INTC_VECT(REF, 0x580), INTC_VECT(REF, 0x5a0),
80}; 77};
81 78
82static struct intc_group groups[] __initdata = { 79static struct intc_group groups[] __initdata = {
83 INTC_GROUP(DMAC, DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2,
84 DMAC_DMTE3, DMAC_DMTE4, DMAC_DMTE5,
85 DMAC_DMTE6, DMAC_DMTE7, DMAC_DMAE),
86 INTC_GROUP(DMABRG, DMABRG0, DMABRG1, DMABRG2), 80 INTC_GROUP(DMABRG, DMABRG0, DMABRG1, DMABRG2),
87 INTC_GROUP(SCIF0, SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI), 81 INTC_GROUP(SCIF0, SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI),
88 INTC_GROUP(SCIF1, SCIF1_ERI, SCIF1_RXI, SCIF1_BRI, SCIF1_TXI), 82 INTC_GROUP(SCIF1, SCIF1_ERI, SCIF1_RXI, SCIF1_BRI, SCIF1_TXI),
89 INTC_GROUP(SCIF2, SCIF2_ERI, SCIF2_RXI, SCIF2_BRI, SCIF2_TXI), 83 INTC_GROUP(SCIF2, SCIF2_ERI, SCIF2_RXI, SCIF2_BRI, SCIF2_TXI),
90 INTC_GROUP(SIM, SIM_ERI, SIM_RXI, SIM_TXI, SIM_TEI), 84 INTC_GROUP(SIM, SIM_ERI, SIM_RXI, SIM_TXI, SIM_TEI),
91 INTC_GROUP(MMCIF, MMCIF0, MMCIF1, MMCIF2, MMCIF3), 85 INTC_GROUP(MMCIF, MMCIF0, MMCIF1, MMCIF2, MMCIF3),
92 INTC_GROUP(TMU2, TMU2_TUNI, TMU2_TICPI),
93 INTC_GROUP(REF, REF_RCMI, REF_ROVI),
94}; 86};
95 87
96static struct intc_mask_reg mask_registers[] __initdata = { 88static struct intc_mask_reg mask_registers[] __initdata = {
@@ -168,8 +160,104 @@ static struct platform_device sci_device = {
168 }, 160 },
169}; 161};
170 162
163static struct sh_timer_config tmu0_platform_data = {
164 .name = "TMU0",
165 .channel_offset = 0x04,
166 .timer_bit = 0,
167 .clk = "peripheral_clk",
168 .clockevent_rating = 200,
169};
170
171static struct resource tmu0_resources[] = {
172 [0] = {
173 .name = "TMU0",
174 .start = 0xffd80008,
175 .end = 0xffd80013,
176 .flags = IORESOURCE_MEM,
177 },
178 [1] = {
179 .start = 16,
180 .flags = IORESOURCE_IRQ,
181 },
182};
183
184static struct platform_device tmu0_device = {
185 .name = "sh_tmu",
186 .id = 0,
187 .dev = {
188 .platform_data = &tmu0_platform_data,
189 },
190 .resource = tmu0_resources,
191 .num_resources = ARRAY_SIZE(tmu0_resources),
192};
193
194static struct sh_timer_config tmu1_platform_data = {
195 .name = "TMU1",
196 .channel_offset = 0x10,
197 .timer_bit = 1,
198 .clk = "peripheral_clk",
199 .clocksource_rating = 200,
200};
201
202static struct resource tmu1_resources[] = {
203 [0] = {
204 .name = "TMU1",
205 .start = 0xffd80014,
206 .end = 0xffd8001f,
207 .flags = IORESOURCE_MEM,
208 },
209 [1] = {
210 .start = 17,
211 .flags = IORESOURCE_IRQ,
212 },
213};
214
215static struct platform_device tmu1_device = {
216 .name = "sh_tmu",
217 .id = 1,
218 .dev = {
219 .platform_data = &tmu1_platform_data,
220 },
221 .resource = tmu1_resources,
222 .num_resources = ARRAY_SIZE(tmu1_resources),
223};
224
225static struct sh_timer_config tmu2_platform_data = {
226 .name = "TMU2",
227 .channel_offset = 0x1c,
228 .timer_bit = 2,
229 .clk = "peripheral_clk",
230};
231
232static struct resource tmu2_resources[] = {
233 [0] = {
234 .name = "TMU2",
235 .start = 0xffd80020,
236 .end = 0xffd8002f,
237 .flags = IORESOURCE_MEM,
238 },
239 [1] = {
240 .start = 18,
241 .flags = IORESOURCE_IRQ,
242 },
243};
244
245static struct platform_device tmu2_device = {
246 .name = "sh_tmu",
247 .id = 2,
248 .dev = {
249 .platform_data = &tmu2_platform_data,
250 },
251 .resource = tmu2_resources,
252 .num_resources = ARRAY_SIZE(tmu2_resources),
253};
254
255
171static struct platform_device *sh7760_devices[] __initdata = { 256static struct platform_device *sh7760_devices[] __initdata = {
172 &sci_device, 257 &sci_device,
258 &tmu0_device,
259 &tmu1_device,
260 &tmu2_device,
173}; 261};
174 262
175static int __init sh7760_devices_setup(void) 263static int __init sh7760_devices_setup(void)
@@ -179,6 +267,18 @@ static int __init sh7760_devices_setup(void)
179} 267}
180__initcall(sh7760_devices_setup); 268__initcall(sh7760_devices_setup);
181 269
270static struct platform_device *sh7760_early_devices[] __initdata = {
271 &tmu0_device,
272 &tmu1_device,
273 &tmu2_device,
274};
275
276void __init plat_early_device_setup(void)
277{
278 early_platform_add_devices(sh7760_early_devices,
279 ARRAY_SIZE(sh7760_early_devices));
280}
281
182#define INTC_ICR 0xffd00000UL 282#define INTC_ICR 0xffd00000UL
183#define INTC_ICR_IRLM (1 << 7) 283#define INTC_ICR_IRLM (1 << 7)
184 284
diff --git a/arch/sh/kernel/cpu/sh4a/Makefile b/arch/sh/kernel/cpu/sh4a/Makefile
index 1a92361feeb9..96ea09ca8cc1 100644
--- a/arch/sh/kernel/cpu/sh4a/Makefile
+++ b/arch/sh/kernel/cpu/sh4a/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_CPU_SUBTYPE_SH7786) += setup-sh7786.o
11obj-$(CONFIG_CPU_SUBTYPE_SH7343) += setup-sh7343.o 11obj-$(CONFIG_CPU_SUBTYPE_SH7343) += setup-sh7343.o
12obj-$(CONFIG_CPU_SUBTYPE_SH7722) += setup-sh7722.o 12obj-$(CONFIG_CPU_SUBTYPE_SH7722) += setup-sh7722.o
13obj-$(CONFIG_CPU_SUBTYPE_SH7723) += setup-sh7723.o 13obj-$(CONFIG_CPU_SUBTYPE_SH7723) += setup-sh7723.o
14obj-$(CONFIG_CPU_SUBTYPE_SH7724) += setup-sh7724.o
14obj-$(CONFIG_CPU_SUBTYPE_SH7366) += setup-sh7366.o 15obj-$(CONFIG_CPU_SUBTYPE_SH7366) += setup-sh7366.o
15obj-$(CONFIG_CPU_SUBTYPE_SHX3) += setup-shx3.o 16obj-$(CONFIG_CPU_SUBTYPE_SHX3) += setup-shx3.o
16 17
@@ -23,15 +24,17 @@ clock-$(CONFIG_CPU_SUBTYPE_SH7770) := clock-sh7770.o
23clock-$(CONFIG_CPU_SUBTYPE_SH7780) := clock-sh7780.o 24clock-$(CONFIG_CPU_SUBTYPE_SH7780) := clock-sh7780.o
24clock-$(CONFIG_CPU_SUBTYPE_SH7785) := clock-sh7785.o 25clock-$(CONFIG_CPU_SUBTYPE_SH7785) := clock-sh7785.o
25clock-$(CONFIG_CPU_SUBTYPE_SH7786) := clock-sh7786.o 26clock-$(CONFIG_CPU_SUBTYPE_SH7786) := clock-sh7786.o
26clock-$(CONFIG_CPU_SUBTYPE_SH7343) := clock-sh7722.o 27clock-$(CONFIG_CPU_SUBTYPE_SH7343) := clock-sh7343.o
27clock-$(CONFIG_CPU_SUBTYPE_SH7722) := clock-sh7722.o 28clock-$(CONFIG_CPU_SUBTYPE_SH7722) := clock-sh7722.o
28clock-$(CONFIG_CPU_SUBTYPE_SH7723) := clock-sh7722.o 29clock-$(CONFIG_CPU_SUBTYPE_SH7723) := clock-sh7723.o
29clock-$(CONFIG_CPU_SUBTYPE_SH7366) := clock-sh7722.o 30clock-$(CONFIG_CPU_SUBTYPE_SH7724) := clock-sh7724.o
31clock-$(CONFIG_CPU_SUBTYPE_SH7366) := clock-sh7366.o
30clock-$(CONFIG_CPU_SUBTYPE_SHX3) := clock-shx3.o 32clock-$(CONFIG_CPU_SUBTYPE_SHX3) := clock-shx3.o
31 33
32# Pinmux setup 34# Pinmux setup
33pinmux-$(CONFIG_CPU_SUBTYPE_SH7722) := pinmux-sh7722.o 35pinmux-$(CONFIG_CPU_SUBTYPE_SH7722) := pinmux-sh7722.o
34pinmux-$(CONFIG_CPU_SUBTYPE_SH7723) := pinmux-sh7723.o 36pinmux-$(CONFIG_CPU_SUBTYPE_SH7723) := pinmux-sh7723.o
37pinmux-$(CONFIG_CPU_SUBTYPE_SH7724) := pinmux-sh7724.o
35pinmux-$(CONFIG_CPU_SUBTYPE_SH7785) := pinmux-sh7785.o 38pinmux-$(CONFIG_CPU_SUBTYPE_SH7785) := pinmux-sh7785.o
36pinmux-$(CONFIG_CPU_SUBTYPE_SH7786) := pinmux-sh7786.o 39pinmux-$(CONFIG_CPU_SUBTYPE_SH7786) := pinmux-sh7786.o
37 40
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7343.c b/arch/sh/kernel/cpu/sh4a/clock-sh7343.c
new file mode 100644
index 000000000000..0ee3ee861252
--- /dev/null
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7343.c
@@ -0,0 +1,211 @@
1/*
2 * arch/sh/kernel/cpu/sh4a/clock-sh7343.c
3 *
4 * SH7343 clock framework support
5 *
6 * Copyright (C) 2009 Magnus Damm
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21#include <linux/init.h>
22#include <linux/kernel.h>
23#include <linux/io.h>
24#include <asm/clock.h>
25
26/* SH7343 registers */
27#define FRQCR 0xa4150000
28#define VCLKCR 0xa4150004
29#define SCLKACR 0xa4150008
30#define SCLKBCR 0xa415000c
31#define PLLCR 0xa4150024
32#define MSTPCR0 0xa4150030
33#define MSTPCR1 0xa4150034
34#define MSTPCR2 0xa4150038
35#define DLLFRQ 0xa4150050
36
37/* Fixed 32 KHz root clock for RTC and Power Management purposes */
38static struct clk r_clk = {
39 .name = "rclk",
40 .id = -1,
41 .rate = 32768,
42};
43
44/*
45 * Default rate for the root input clock, reset this with clk_set_rate()
46 * from the platform code.
47 */
48struct clk extal_clk = {
49 .name = "extal",
50 .id = -1,
51 .rate = 33333333,
52};
53
54/* The dll block multiplies the 32khz r_clk, may be used instead of extal */
55static unsigned long dll_recalc(struct clk *clk)
56{
57 unsigned long mult;
58
59 if (__raw_readl(PLLCR) & 0x1000)
60 mult = __raw_readl(DLLFRQ);
61 else
62 mult = 0;
63
64 return clk->parent->rate * mult;
65}
66
67static struct clk_ops dll_clk_ops = {
68 .recalc = dll_recalc,
69};
70
71static struct clk dll_clk = {
72 .name = "dll_clk",
73 .id = -1,
74 .ops = &dll_clk_ops,
75 .parent = &r_clk,
76 .flags = CLK_ENABLE_ON_INIT,
77};
78
79static unsigned long pll_recalc(struct clk *clk)
80{
81 unsigned long mult = 1;
82
83 if (__raw_readl(PLLCR) & 0x4000)
84 mult = (((__raw_readl(FRQCR) >> 24) & 0x1f) + 1);
85
86 return clk->parent->rate * mult;
87}
88
89static struct clk_ops pll_clk_ops = {
90 .recalc = pll_recalc,
91};
92
93static struct clk pll_clk = {
94 .name = "pll_clk",
95 .id = -1,
96 .ops = &pll_clk_ops,
97 .flags = CLK_ENABLE_ON_INIT,
98};
99
100struct clk *main_clks[] = {
101 &r_clk,
102 &extal_clk,
103 &dll_clk,
104 &pll_clk,
105};
106
107static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
108static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
109
110static struct clk_div_mult_table div4_table = {
111 .divisors = divisors,
112 .nr_divisors = ARRAY_SIZE(divisors),
113 .multipliers = multipliers,
114 .nr_multipliers = ARRAY_SIZE(multipliers),
115};
116
117enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P,
118 DIV4_SIUA, DIV4_SIUB, DIV4_NR };
119
120#define DIV4(_str, _reg, _bit, _mask, _flags) \
121 SH_CLK_DIV4(_str, &pll_clk, _reg, _bit, _mask, _flags)
122
123struct clk div4_clks[DIV4_NR] = {
124 [DIV4_I] = DIV4("cpu_clk", FRQCR, 20, 0x1fff, CLK_ENABLE_ON_INIT),
125 [DIV4_U] = DIV4("umem_clk", FRQCR, 16, 0x1fff, CLK_ENABLE_ON_INIT),
126 [DIV4_SH] = DIV4("shyway_clk", FRQCR, 12, 0x1fff, CLK_ENABLE_ON_INIT),
127 [DIV4_B] = DIV4("bus_clk", FRQCR, 8, 0x1fff, CLK_ENABLE_ON_INIT),
128 [DIV4_B3] = DIV4("b3_clk", FRQCR, 4, 0x1fff, CLK_ENABLE_ON_INIT),
129 [DIV4_P] = DIV4("peripheral_clk", FRQCR, 0, 0x1fff, 0),
130 [DIV4_SIUA] = DIV4("siua_clk", SCLKACR, 0, 0x1fff, 0),
131 [DIV4_SIUB] = DIV4("siub_clk", SCLKBCR, 0, 0x1fff, 0),
132};
133
134struct clk div6_clks[] = {
135 SH_CLK_DIV6("video_clk", &pll_clk, VCLKCR, 0),
136};
137
138#define MSTP(_str, _parent, _reg, _bit, _flags) \
139 SH_CLK_MSTP32(_str, -1, _parent, _reg, _bit, _flags)
140
141static struct clk mstp_clks[] = {
142 MSTP("tlb0", &div4_clks[DIV4_I], MSTPCR0, 31, CLK_ENABLE_ON_INIT),
143 MSTP("ic0", &div4_clks[DIV4_I], MSTPCR0, 30, CLK_ENABLE_ON_INIT),
144 MSTP("oc0", &div4_clks[DIV4_I], MSTPCR0, 29, CLK_ENABLE_ON_INIT),
145 MSTP("uram0", &div4_clks[DIV4_U], MSTPCR0, 28, CLK_ENABLE_ON_INIT),
146 MSTP("xymem0", &div4_clks[DIV4_B], MSTPCR0, 26, CLK_ENABLE_ON_INIT),
147 MSTP("intc3", &div4_clks[DIV4_P], MSTPCR0, 23, 0),
148 MSTP("intc0", &div4_clks[DIV4_P], MSTPCR0, 22, 0),
149 MSTP("dmac0", &div4_clks[DIV4_P], MSTPCR0, 21, 0),
150 MSTP("sh0", &div4_clks[DIV4_P], MSTPCR0, 20, 0),
151 MSTP("hudi0", &div4_clks[DIV4_P], MSTPCR0, 19, 0),
152 MSTP("ubc0", &div4_clks[DIV4_P], MSTPCR0, 17, 0),
153 MSTP("tmu0", &div4_clks[DIV4_P], MSTPCR0, 15, 0),
154 MSTP("cmt0", &r_clk, MSTPCR0, 14, 0),
155 MSTP("rwdt0", &r_clk, MSTPCR0, 13, 0),
156 MSTP("mfi0", &div4_clks[DIV4_P], MSTPCR0, 11, 0),
157 MSTP("flctl0", &div4_clks[DIV4_P], MSTPCR0, 10, 0),
158 MSTP("scif0", &div4_clks[DIV4_P], MSTPCR0, 7, 0),
159 MSTP("scif1", &div4_clks[DIV4_P], MSTPCR0, 6, 0),
160 MSTP("scif2", &div4_clks[DIV4_P], MSTPCR0, 5, 0),
161 MSTP("scif3", &div4_clks[DIV4_P], MSTPCR0, 4, 0),
162 MSTP("sio0", &div4_clks[DIV4_P], MSTPCR0, 3, 0),
163 MSTP("siof0", &div4_clks[DIV4_P], MSTPCR0, 2, 0),
164 MSTP("siof1", &div4_clks[DIV4_P], MSTPCR0, 1, 0),
165
166 MSTP("i2c0", &div4_clks[DIV4_P], MSTPCR1, 9, 0),
167 MSTP("i2c1", &div4_clks[DIV4_P], MSTPCR1, 8, 0),
168
169 MSTP("tpu0", &div4_clks[DIV4_P], MSTPCR2, 25, 0),
170 MSTP("irda0", &div4_clks[DIV4_P], MSTPCR2, 24, 0),
171 MSTP("sdhi0", &div4_clks[DIV4_P], MSTPCR2, 18, 0),
172 MSTP("mmcif0", &div4_clks[DIV4_P], MSTPCR2, 17, 0),
173 MSTP("sim0", &div4_clks[DIV4_P], MSTPCR2, 16, 0),
174 MSTP("keysc0", &r_clk, MSTPCR2, 14, 0),
175 MSTP("tsif0", &div4_clks[DIV4_P], MSTPCR2, 13, 0),
176 MSTP("s3d40", &div4_clks[DIV4_P], MSTPCR2, 12, 0),
177 MSTP("usbf0", &div4_clks[DIV4_P], MSTPCR2, 11, 0),
178 MSTP("siu0", &div4_clks[DIV4_B], MSTPCR2, 8, 0),
179 MSTP("jpu0", &div4_clks[DIV4_B], MSTPCR2, 6, CLK_ENABLE_ON_INIT),
180 MSTP("vou0", &div4_clks[DIV4_B], MSTPCR2, 5, 0),
181 MSTP("beu0", &div4_clks[DIV4_B], MSTPCR2, 4, 0),
182 MSTP("ceu0", &div4_clks[DIV4_B], MSTPCR2, 3, 0),
183 MSTP("veu0", &div4_clks[DIV4_B], MSTPCR2, 2, CLK_ENABLE_ON_INIT),
184 MSTP("vpu0", &div4_clks[DIV4_B], MSTPCR2, 1, CLK_ENABLE_ON_INIT),
185 MSTP("lcdc0", &div4_clks[DIV4_B], MSTPCR2, 0, 0),
186};
187
188int __init arch_clk_init(void)
189{
190 int k, ret = 0;
191
192 /* autodetect extal or dll configuration */
193 if (__raw_readl(PLLCR) & 0x1000)
194 pll_clk.parent = &dll_clk;
195 else
196 pll_clk.parent = &extal_clk;
197
198 for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
199 ret = clk_register(main_clks[k]);
200
201 if (!ret)
202 ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
203
204 if (!ret)
205 ret = sh_clk_div6_register(div6_clks, ARRAY_SIZE(div6_clks));
206
207 if (!ret)
208 ret = sh_clk_mstp32_register(mstp_clks, ARRAY_SIZE(mstp_clks));
209
210 return ret;
211}
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7366.c b/arch/sh/kernel/cpu/sh4a/clock-sh7366.c
new file mode 100644
index 000000000000..a95ebaba095c
--- /dev/null
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7366.c
@@ -0,0 +1,211 @@
1/*
2 * arch/sh/kernel/cpu/sh4a/clock-sh7366.c
3 *
4 * SH7366 clock framework support
5 *
6 * Copyright (C) 2009 Magnus Damm
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21#include <linux/init.h>
22#include <linux/kernel.h>
23#include <linux/io.h>
24#include <asm/clock.h>
25
26/* SH7366 registers */
27#define FRQCR 0xa4150000
28#define VCLKCR 0xa4150004
29#define SCLKACR 0xa4150008
30#define SCLKBCR 0xa415000c
31#define PLLCR 0xa4150024
32#define MSTPCR0 0xa4150030
33#define MSTPCR1 0xa4150034
34#define MSTPCR2 0xa4150038
35#define DLLFRQ 0xa4150050
36
37/* Fixed 32 KHz root clock for RTC and Power Management purposes */
38static struct clk r_clk = {
39 .name = "rclk",
40 .id = -1,
41 .rate = 32768,
42};
43
44/*
45 * Default rate for the root input clock, reset this with clk_set_rate()
46 * from the platform code.
47 */
48struct clk extal_clk = {
49 .name = "extal",
50 .id = -1,
51 .rate = 33333333,
52};
53
54/* The dll block multiplies the 32khz r_clk, may be used instead of extal */
55static unsigned long dll_recalc(struct clk *clk)
56{
57 unsigned long mult;
58
59 if (__raw_readl(PLLCR) & 0x1000)
60 mult = __raw_readl(DLLFRQ);
61 else
62 mult = 0;
63
64 return clk->parent->rate * mult;
65}
66
67static struct clk_ops dll_clk_ops = {
68 .recalc = dll_recalc,
69};
70
71static struct clk dll_clk = {
72 .name = "dll_clk",
73 .id = -1,
74 .ops = &dll_clk_ops,
75 .parent = &r_clk,
76 .flags = CLK_ENABLE_ON_INIT,
77};
78
79static unsigned long pll_recalc(struct clk *clk)
80{
81 unsigned long mult = 1;
82 unsigned long div = 1;
83
84 if (__raw_readl(PLLCR) & 0x4000)
85 mult = (((__raw_readl(FRQCR) >> 24) & 0x1f) + 1);
86 else
87 div = 2;
88
89 return (clk->parent->rate * mult) / div;
90}
91
92static struct clk_ops pll_clk_ops = {
93 .recalc = pll_recalc,
94};
95
96static struct clk pll_clk = {
97 .name = "pll_clk",
98 .id = -1,
99 .ops = &pll_clk_ops,
100 .flags = CLK_ENABLE_ON_INIT,
101};
102
103struct clk *main_clks[] = {
104 &r_clk,
105 &extal_clk,
106 &dll_clk,
107 &pll_clk,
108};
109
110static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
111static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
112
113static struct clk_div_mult_table div4_table = {
114 .divisors = divisors,
115 .nr_divisors = ARRAY_SIZE(divisors),
116 .multipliers = multipliers,
117 .nr_multipliers = ARRAY_SIZE(multipliers),
118};
119
120enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P,
121 DIV4_SIUA, DIV4_SIUB, DIV4_NR };
122
123#define DIV4(_str, _reg, _bit, _mask, _flags) \
124 SH_CLK_DIV4(_str, &pll_clk, _reg, _bit, _mask, _flags)
125
126struct clk div4_clks[DIV4_NR] = {
127 [DIV4_I] = DIV4("cpu_clk", FRQCR, 20, 0x1fef, CLK_ENABLE_ON_INIT),
128 [DIV4_U] = DIV4("umem_clk", FRQCR, 16, 0x1fff, CLK_ENABLE_ON_INIT),
129 [DIV4_SH] = DIV4("shyway_clk", FRQCR, 12, 0x1fff, CLK_ENABLE_ON_INIT),
130 [DIV4_B] = DIV4("bus_clk", FRQCR, 8, 0x1fff, CLK_ENABLE_ON_INIT),
131 [DIV4_B3] = DIV4("b3_clk", FRQCR, 4, 0x1fff, CLK_ENABLE_ON_INIT),
132 [DIV4_P] = DIV4("peripheral_clk", FRQCR, 0, 0x1fff, 0),
133 [DIV4_SIUA] = DIV4("siua_clk", SCLKACR, 0, 0x1fff, 0),
134 [DIV4_SIUB] = DIV4("siub_clk", SCLKBCR, 0, 0x1fff, 0),
135};
136
137struct clk div6_clks[] = {
138 SH_CLK_DIV6("video_clk", &pll_clk, VCLKCR, 0),
139};
140
141#define MSTP(_str, _parent, _reg, _bit, _flags) \
142 SH_CLK_MSTP32(_str, -1, _parent, _reg, _bit, _flags)
143
144static struct clk mstp_clks[] = {
145 /* See page 52 of Datasheet V0.40: Overview -> Block Diagram */
146 MSTP("tlb0", &div4_clks[DIV4_I], MSTPCR0, 31, CLK_ENABLE_ON_INIT),
147 MSTP("ic0", &div4_clks[DIV4_I], MSTPCR0, 30, CLK_ENABLE_ON_INIT),
148 MSTP("oc0", &div4_clks[DIV4_I], MSTPCR0, 29, CLK_ENABLE_ON_INIT),
149 MSTP("rsmem0", &div4_clks[DIV4_SH], MSTPCR0, 28, CLK_ENABLE_ON_INIT),
150 MSTP("xymem0", &div4_clks[DIV4_B], MSTPCR0, 26, CLK_ENABLE_ON_INIT),
151 MSTP("intc3", &div4_clks[DIV4_P], MSTPCR0, 23, 0),
152 MSTP("intc0", &div4_clks[DIV4_P], MSTPCR0, 22, 0),
153 MSTP("dmac0", &div4_clks[DIV4_P], MSTPCR0, 21, 0),
154 MSTP("sh0", &div4_clks[DIV4_P], MSTPCR0, 20, 0),
155 MSTP("hudi0", &div4_clks[DIV4_P], MSTPCR0, 19, 0),
156 MSTP("ubc0", &div4_clks[DIV4_P], MSTPCR0, 17, 0),
157 MSTP("tmu0", &div4_clks[DIV4_P], MSTPCR0, 15, 0),
158 MSTP("cmt0", &r_clk, MSTPCR0, 14, 0),
159 MSTP("rwdt0", &r_clk, MSTPCR0, 13, 0),
160 MSTP("mfi0", &div4_clks[DIV4_P], MSTPCR0, 11, 0),
161 MSTP("flctl0", &div4_clks[DIV4_P], MSTPCR0, 10, 0),
162 MSTP("scif0", &div4_clks[DIV4_P], MSTPCR0, 7, 0),
163 MSTP("scif1", &div4_clks[DIV4_P], MSTPCR0, 6, 0),
164 MSTP("scif2", &div4_clks[DIV4_P], MSTPCR0, 5, 0),
165 MSTP("msiof0", &div4_clks[DIV4_P], MSTPCR0, 2, 0),
166 MSTP("sbr0", &div4_clks[DIV4_P], MSTPCR0, 1, 0),
167
168 MSTP("i2c0", &div4_clks[DIV4_P], MSTPCR1, 9, 0),
169
170 MSTP("icb0", &div4_clks[DIV4_P], MSTPCR2, 27, 0),
171 MSTP("meram0", &div4_clks[DIV4_P], MSTPCR2, 26, 0),
172 MSTP("dacy1", &div4_clks[DIV4_P], MSTPCR2, 24, 0),
173 MSTP("dacy0", &div4_clks[DIV4_P], MSTPCR2, 23, 0),
174 MSTP("tsif0", &div4_clks[DIV4_P], MSTPCR2, 22, 0),
175 MSTP("sdhi0", &div4_clks[DIV4_P], MSTPCR2, 18, 0),
176 MSTP("mmcif0", &div4_clks[DIV4_P], MSTPCR2, 17, 0),
177 MSTP("usbf0", &div4_clks[DIV4_P], MSTPCR2, 11, 0),
178 MSTP("siu0", &div4_clks[DIV4_B], MSTPCR2, 9, 0),
179 MSTP("veu1", &div4_clks[DIV4_B], MSTPCR2, 7, CLK_ENABLE_ON_INIT),
180 MSTP("vou0", &div4_clks[DIV4_B], MSTPCR2, 5, 0),
181 MSTP("beu0", &div4_clks[DIV4_B], MSTPCR2, 4, 0),
182 MSTP("ceu0", &div4_clks[DIV4_B], MSTPCR2, 3, 0),
183 MSTP("veu0", &div4_clks[DIV4_B], MSTPCR2, 2, CLK_ENABLE_ON_INIT),
184 MSTP("vpu0", &div4_clks[DIV4_B], MSTPCR2, 1, CLK_ENABLE_ON_INIT),
185 MSTP("lcdc0", &div4_clks[DIV4_B], MSTPCR2, 0, 0),
186};
187
188int __init arch_clk_init(void)
189{
190 int k, ret = 0;
191
192 /* autodetect extal or dll configuration */
193 if (__raw_readl(PLLCR) & 0x1000)
194 pll_clk.parent = &dll_clk;
195 else
196 pll_clk.parent = &extal_clk;
197
198 for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
199 ret = clk_register(main_clks[k]);
200
201 if (!ret)
202 ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
203
204 if (!ret)
205 ret = sh_clk_div6_register(div6_clks, ARRAY_SIZE(div6_clks));
206
207 if (!ret)
208 ret = sh_clk_mstp32_register(mstp_clks, ARRAY_SIZE(mstp_clks));
209
210 return ret;
211}
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7722.c b/arch/sh/kernel/cpu/sh4a/clock-sh7722.c
index 0e174af21874..40f859354f79 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7722.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7722.c
@@ -1,844 +1,197 @@
1/* 1/*
2 * arch/sh/kernel/cpu/sh4a/clock-sh7722.c 2 * arch/sh/kernel/cpu/sh4a/clock-sh7722.c
3 * 3 *
4 * SH7343, SH7722, SH7723 & SH7366 support for the clock framework 4 * SH7722 clock framework support
5 * 5 *
6 * Copyright (c) 2006-2007 Nomad Global Solutions Inc 6 * Copyright (C) 2009 Magnus Damm
7 * Based on code for sh7343 by Paul Mundt
8 * 7 *
9 * This file is subject to the terms and conditions of the GNU General Public 8 * This program is free software; you can redistribute it and/or modify
10 * License. See the file "COPYING" in the main directory of this archive 9 * it under the terms of the GNU General Public License as published by
11 * for more details. 10 * the Free Software Foundation; either version 2 of the License
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
12 */ 20 */
13#include <linux/init.h> 21#include <linux/init.h>
14#include <linux/kernel.h> 22#include <linux/kernel.h>
15#include <linux/io.h> 23#include <linux/io.h>
16#include <linux/errno.h>
17#include <linux/stringify.h>
18#include <asm/clock.h> 24#include <asm/clock.h>
19#include <asm/freq.h>
20
21#define N (-1)
22#define NM (-2)
23#define ROUND_NEAREST 0
24#define ROUND_DOWN -1
25#define ROUND_UP +1
26
27static int adjust_algos[][3] = {
28 {}, /* NO_CHANGE */
29 { NM, N, 1 }, /* N:1, N:1 */
30 { 3, 2, 2 }, /* 3:2:2 */
31 { 5, 2, 2 }, /* 5:2:2 */
32 { N, 1, 1 }, /* N:1:1 */
33
34 { N, 1 }, /* N:1 */
35 25
36 { N, 1 }, /* N:1 */ 26/* SH7722 registers */
37 { 3, 2 }, 27#define FRQCR 0xa4150000
38 { 4, 3 }, 28#define VCLKCR 0xa4150004
39 { 5, 4 }, 29#define SCLKACR 0xa4150008
40 30#define SCLKBCR 0xa415000c
41 { N, 1 } 31#define IRDACLKCR 0xa4150018
32#define PLLCR 0xa4150024
33#define MSTPCR0 0xa4150030
34#define MSTPCR1 0xa4150034
35#define MSTPCR2 0xa4150038
36#define DLLFRQ 0xa4150050
37
38/* Fixed 32 KHz root clock for RTC and Power Management purposes */
39static struct clk r_clk = {
40 .name = "rclk",
41 .id = -1,
42 .rate = 32768,
42}; 43};
43 44
44static unsigned long adjust_pair_of_clocks(unsigned long r1, unsigned long r2,
45 int m1, int m2, int round_flag)
46{
47 unsigned long rem, div;
48 int the_one = 0;
49
50 pr_debug( "Actual values: r1 = %ld\n", r1);
51 pr_debug( "...............r2 = %ld\n", r2);
52
53 if (m1 == m2) {
54 r2 = r1;
55 pr_debug( "setting equal rates: r2 now %ld\n", r2);
56 } else if ((m2 == N && m1 == 1) ||
57 (m2 == NM && m1 == N)) { /* N:1 or NM:N */
58 pr_debug( "Setting rates as 1:N (N:N*M)\n");
59 rem = r2 % r1;
60 pr_debug( "...remainder = %ld\n", rem);
61 if (rem) {
62 div = r2 / r1;
63 pr_debug( "...div = %ld\n", div);
64 switch (round_flag) {
65 case ROUND_NEAREST:
66 the_one = rem >= r1/2 ? 1 : 0; break;
67 case ROUND_UP:
68 the_one = 1; break;
69 case ROUND_DOWN:
70 the_one = 0; break;
71 }
72
73 r2 = r1 * (div + the_one);
74 pr_debug( "...setting r2 to %ld\n", r2);
75 }
76 } else if ((m2 == 1 && m1 == N) ||
77 (m2 == N && m1 == NM)) { /* 1:N or N:NM */
78 pr_debug( "Setting rates as N:1 (N*M:N)\n");
79 rem = r1 % r2;
80 pr_debug( "...remainder = %ld\n", rem);
81 if (rem) {
82 div = r1 / r2;
83 pr_debug( "...div = %ld\n", div);
84 switch (round_flag) {
85 case ROUND_NEAREST:
86 the_one = rem > r2/2 ? 1 : 0; break;
87 case ROUND_UP:
88 the_one = 0; break;
89 case ROUND_DOWN:
90 the_one = 1; break;
91 }
92
93 r2 = r1 / (div + the_one);
94 pr_debug( "...setting r2 to %ld\n", r2);
95 }
96 } else { /* value:value */
97 pr_debug( "Setting rates as %d:%d\n", m1, m2);
98 div = r1 / m1;
99 r2 = div * m2;
100 pr_debug( "...div = %ld\n", div);
101 pr_debug( "...setting r2 to %ld\n", r2);
102 }
103
104 return r2;
105}
106
107static void adjust_clocks(int originate, int *l, unsigned long v[],
108 int n_in_line)
109{
110 int x;
111
112 pr_debug( "Go down from %d...\n", originate);
113 /* go up recalculation clocks */
114 for (x = originate; x>0; x -- )
115 v[x-1] = adjust_pair_of_clocks(v[x], v[x-1],
116 l[x], l[x-1],
117 ROUND_UP);
118
119 pr_debug( "Go up from %d...\n", originate);
120 /* go down recalculation clocks */
121 for (x = originate; x<n_in_line - 1; x ++ )
122 v[x+1] = adjust_pair_of_clocks(v[x], v[x+1],
123 l[x], l[x+1],
124 ROUND_UP);
125}
126
127
128/* 45/*
129 * SH7722 uses a common set of multipliers and divisors, so this 46 * Default rate for the root input clock, reset this with clk_set_rate()
130 * is quite simple.. 47 * from the platform code.
131 */ 48 */
132 49struct clk extal_clk = {
133/* 50 .name = "extal",
134 * Instead of having two separate multipliers/divisors set, like this: 51 .id = -1,
135 * 52 .rate = 33333333,
136 * static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
137 * static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
138 *
139 * I created the divisors2 array, which is used to calculate rate like
140 * rate = parent * 2 / divisors2[ divisor ];
141*/
142static int divisors2[] = { 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32, 40 };
143
144static void master_clk_recalc(struct clk *clk)
145{
146 unsigned frqcr = ctrl_inl(FRQCR);
147
148 clk->rate = CONFIG_SH_PCLK_FREQ * (((frqcr >> 24) & 0x1f) + 1);
149}
150
151static void master_clk_init(struct clk *clk)
152{
153 clk->parent = NULL;
154 clk->flags |= CLK_RATE_PROPAGATES;
155 clk->rate = CONFIG_SH_PCLK_FREQ;
156 master_clk_recalc(clk);
157}
158
159
160static void module_clk_recalc(struct clk *clk)
161{
162 unsigned long frqcr = ctrl_inl(FRQCR);
163
164 clk->rate = clk->parent->rate / (((frqcr >> 24) & 0x1f) + 1);
165}
166
167static int master_clk_setrate(struct clk *clk, unsigned long rate, int id)
168{
169 int div = rate / clk->rate;
170 int master_divs[] = { 2, 3, 4, 6, 8, 16 };
171 int index;
172 unsigned long frqcr;
173
174 for (index = 1; index < ARRAY_SIZE(master_divs); index++)
175 if (div >= master_divs[index - 1] && div < master_divs[index])
176 break;
177
178 if (index >= ARRAY_SIZE(master_divs))
179 index = ARRAY_SIZE(master_divs);
180 div = master_divs[index - 1];
181
182 frqcr = ctrl_inl(FRQCR);
183 frqcr &= ~(0xF << 24);
184 frqcr |= ( (div-1) << 24);
185 ctrl_outl(frqcr, FRQCR);
186
187 return 0;
188}
189
190static struct clk_ops sh7722_master_clk_ops = {
191 .init = master_clk_init,
192 .recalc = master_clk_recalc,
193 .set_rate = master_clk_setrate,
194};
195
196static struct clk_ops sh7722_module_clk_ops = {
197 .recalc = module_clk_recalc,
198};
199
200struct frqcr_context {
201 unsigned mask;
202 unsigned shift;
203};
204
205struct frqcr_context sh7722_get_clk_context(const char *name)
206{
207 struct frqcr_context ctx = { 0, };
208
209 if (!strcmp(name, "peripheral_clk")) {
210 ctx.shift = 0;
211 ctx.mask = 0xF;
212 } else if (!strcmp(name, "sdram_clk")) {
213 ctx.shift = 4;
214 ctx.mask = 0xF;
215 } else if (!strcmp(name, "bus_clk")) {
216 ctx.shift = 8;
217 ctx.mask = 0xF;
218 } else if (!strcmp(name, "sh_clk")) {
219 ctx.shift = 12;
220 ctx.mask = 0xF;
221 } else if (!strcmp(name, "umem_clk")) {
222 ctx.shift = 16;
223 ctx.mask = 0xF;
224 } else if (!strcmp(name, "cpu_clk")) {
225 ctx.shift = 20;
226 ctx.mask = 7;
227 }
228 return ctx;
229}
230
231/**
232 * sh7722_find_div_index - find divisor for setting rate
233 *
234 * All sh7722 clocks use the same set of multipliers/divisors. This function
235 * chooses correct divisor to set the rate of clock with parent clock that
236 * generates frequency of 'parent_rate'
237 *
238 * @parent_rate: rate of parent clock
239 * @rate: requested rate to be set
240 */
241static int sh7722_find_div_index(unsigned long parent_rate, unsigned rate)
242{
243 unsigned div2 = parent_rate * 2 / rate;
244 int index;
245
246 if (rate > parent_rate)
247 return -EINVAL;
248
249 for (index = 1; index < ARRAY_SIZE(divisors2); index++) {
250 if (div2 > divisors2[index - 1] && div2 <= divisors2[index])
251 break;
252 }
253 if (index >= ARRAY_SIZE(divisors2))
254 index = ARRAY_SIZE(divisors2) - 1;
255 return index;
256}
257
258static void sh7722_frqcr_recalc(struct clk *clk)
259{
260 struct frqcr_context ctx = sh7722_get_clk_context(clk->name);
261 unsigned long frqcr = ctrl_inl(FRQCR);
262 int index;
263
264 index = (frqcr >> ctx.shift) & ctx.mask;
265 clk->rate = clk->parent->rate * 2 / divisors2[index];
266}
267
268static int sh7722_frqcr_set_rate(struct clk *clk, unsigned long rate,
269 int algo_id)
270{
271 struct frqcr_context ctx = sh7722_get_clk_context(clk->name);
272 unsigned long parent_rate = clk->parent->rate;
273 int div;
274 unsigned long frqcr;
275 int err = 0;
276
277 /* pretty invalid */
278 if (parent_rate < rate)
279 return -EINVAL;
280
281 /* look for multiplier/divisor pair */
282 div = sh7722_find_div_index(parent_rate, rate);
283 if (div<0)
284 return div;
285
286 /* calculate new value of clock rate */
287 clk->rate = parent_rate * 2 / divisors2[div];
288 frqcr = ctrl_inl(FRQCR);
289
290 /* FIXME: adjust as algo_id specifies */
291 if (algo_id != NO_CHANGE) {
292 int originator;
293 char *algo_group_1[] = { "cpu_clk", "umem_clk", "sh_clk" };
294 char *algo_group_2[] = { "sh_clk", "bus_clk" };
295 char *algo_group_3[] = { "sh_clk", "sdram_clk" };
296 char *algo_group_4[] = { "bus_clk", "peripheral_clk" };
297 char *algo_group_5[] = { "cpu_clk", "peripheral_clk" };
298 char **algo_current = NULL;
299 /* 3 is the maximum number of clocks in relation */
300 struct clk *ck[3];
301 unsigned long values[3]; /* the same comment as above */
302 int part_length = -1;
303 int i;
304
305 /*
306 * all the steps below only required if adjustion was
307 * requested
308 */
309 if (algo_id == IUS_N1_N1 ||
310 algo_id == IUS_322 ||
311 algo_id == IUS_522 ||
312 algo_id == IUS_N11) {
313 algo_current = algo_group_1;
314 part_length = 3;
315 }
316 if (algo_id == SB_N1) {
317 algo_current = algo_group_2;
318 part_length = 2;
319 }
320 if (algo_id == SB3_N1 ||
321 algo_id == SB3_32 ||
322 algo_id == SB3_43 ||
323 algo_id == SB3_54) {
324 algo_current = algo_group_3;
325 part_length = 2;
326 }
327 if (algo_id == BP_N1) {
328 algo_current = algo_group_4;
329 part_length = 2;
330 }
331 if (algo_id == IP_N1) {
332 algo_current = algo_group_5;
333 part_length = 2;
334 }
335 if (!algo_current)
336 goto incorrect_algo_id;
337
338 originator = -1;
339 for (i = 0; i < part_length; i ++ ) {
340 if (originator >= 0 && !strcmp(clk->name,
341 algo_current[i]))
342 originator = i;
343 ck[i] = clk_get(NULL, algo_current[i]);
344 values[i] = clk_get_rate(ck[i]);
345 }
346
347 if (originator >= 0)
348 adjust_clocks(originator, adjust_algos[algo_id],
349 values, part_length);
350
351 for (i = 0; i < part_length; i ++ ) {
352 struct frqcr_context part_ctx;
353 int part_div;
354
355 if (likely(!err)) {
356 part_div = sh7722_find_div_index(parent_rate,
357 rate);
358 if (part_div > 0) {
359 part_ctx = sh7722_get_clk_context(
360 ck[i]->name);
361 frqcr &= ~(part_ctx.mask <<
362 part_ctx.shift);
363 frqcr |= part_div << part_ctx.shift;
364 } else
365 err = part_div;
366 }
367
368 ck[i]->ops->recalc(ck[i]);
369 clk_put(ck[i]);
370 }
371 }
372
373 /* was there any error during recalculation ? If so, bail out.. */
374 if (unlikely(err!=0))
375 goto out_err;
376
377 /* clear FRQCR bits */
378 frqcr &= ~(ctx.mask << ctx.shift);
379 frqcr |= div << ctx.shift;
380
381 /* ...and perform actual change */
382 ctrl_outl(frqcr, FRQCR);
383 return 0;
384
385incorrect_algo_id:
386 return -EINVAL;
387out_err:
388 return err;
389}
390
391static long sh7722_frqcr_round_rate(struct clk *clk, unsigned long rate)
392{
393 unsigned long parent_rate = clk->parent->rate;
394 int div;
395
396 /* look for multiplier/divisor pair */
397 div = sh7722_find_div_index(parent_rate, rate);
398 if (div < 0)
399 return clk->rate;
400
401 /* calculate new value of clock rate */
402 return parent_rate * 2 / divisors2[div];
403}
404
405static struct clk_ops sh7722_frqcr_clk_ops = {
406 .recalc = sh7722_frqcr_recalc,
407 .set_rate = sh7722_frqcr_set_rate,
408 .round_rate = sh7722_frqcr_round_rate,
409}; 53};
410 54
411/* 55/* The dll block multiplies the 32khz r_clk, may be used instead of extal */
412 * clock ops methods for SIU A/B and IrDA clock 56static unsigned long dll_recalc(struct clk *clk)
413 *
414 */
415
416#ifndef CONFIG_CPU_SUBTYPE_SH7343
417
418static int sh7722_siu_set_rate(struct clk *clk, unsigned long rate, int algo_id)
419{
420 unsigned long r;
421 int div;
422
423 r = ctrl_inl(clk->arch_flags);
424 div = sh7722_find_div_index(clk->parent->rate, rate);
425 if (div < 0)
426 return div;
427 r = (r & ~0xF) | div;
428 ctrl_outl(r, clk->arch_flags);
429 return 0;
430}
431
432static void sh7722_siu_recalc(struct clk *clk)
433{
434 unsigned long r;
435
436 r = ctrl_inl(clk->arch_flags);
437 clk->rate = clk->parent->rate * 2 / divisors2[r & 0xF];
438}
439
440static int sh7722_siu_start_stop(struct clk *clk, int enable)
441{ 57{
442 unsigned long r; 58 unsigned long mult;
443 59
444 r = ctrl_inl(clk->arch_flags); 60 if (__raw_readl(PLLCR) & 0x1000)
445 if (enable) 61 mult = __raw_readl(DLLFRQ);
446 ctrl_outl(r & ~(1 << 8), clk->arch_flags);
447 else 62 else
448 ctrl_outl(r | (1 << 8), clk->arch_flags); 63 mult = 0;
449 return 0;
450}
451
452static void sh7722_siu_enable(struct clk *clk)
453{
454 sh7722_siu_start_stop(clk, 1);
455}
456 64
457static void sh7722_siu_disable(struct clk *clk) 65 return clk->parent->rate * mult;
458{
459 sh7722_siu_start_stop(clk, 0);
460} 66}
461 67
462static struct clk_ops sh7722_siu_clk_ops = { 68static struct clk_ops dll_clk_ops = {
463 .recalc = sh7722_siu_recalc, 69 .recalc = dll_recalc,
464 .set_rate = sh7722_siu_set_rate,
465 .enable = sh7722_siu_enable,
466 .disable = sh7722_siu_disable,
467}; 70};
468 71
469#endif /* CONFIG_CPU_SUBTYPE_SH7343 */ 72static struct clk dll_clk = {
470 73 .name = "dll_clk",
471static void sh7722_video_enable(struct clk *clk) 74 .id = -1,
472{ 75 .ops = &dll_clk_ops,
473 unsigned long r; 76 .parent = &r_clk,
474 77 .flags = CLK_ENABLE_ON_INIT,
475 r = ctrl_inl(VCLKCR); 78};
476 ctrl_outl( r & ~(1<<8), VCLKCR);
477}
478
479static void sh7722_video_disable(struct clk *clk)
480{
481 unsigned long r;
482
483 r = ctrl_inl(VCLKCR);
484 ctrl_outl( r | (1<<8), VCLKCR);
485}
486 79
487static int sh7722_video_set_rate(struct clk *clk, unsigned long rate, 80static unsigned long pll_recalc(struct clk *clk)
488 int algo_id)
489{ 81{
490 unsigned long r; 82 unsigned long mult = 1;
491 83 unsigned long div = 1;
492 r = ctrl_inl(VCLKCR);
493 r &= ~0x3F;
494 r |= ((clk->parent->rate / rate - 1) & 0x3F);
495 ctrl_outl(r, VCLKCR);
496 return 0;
497}
498 84
499static void sh7722_video_recalc(struct clk *clk) 85 if (__raw_readl(PLLCR) & 0x4000)
500{ 86 mult = (((__raw_readl(FRQCR) >> 24) & 0x1f) + 1);
501 unsigned long r; 87 else
88 div = 2;
502 89
503 r = ctrl_inl(VCLKCR); 90 return (clk->parent->rate * mult) / div;
504 clk->rate = clk->parent->rate / ((r & 0x3F) + 1);
505} 91}
506 92
507static struct clk_ops sh7722_video_clk_ops = { 93static struct clk_ops pll_clk_ops = {
508 .recalc = sh7722_video_recalc, 94 .recalc = pll_recalc,
509 .set_rate = sh7722_video_set_rate,
510 .enable = sh7722_video_enable,
511 .disable = sh7722_video_disable,
512};
513/*
514 * and at last, clock definitions themselves
515 */
516static struct clk sh7722_umem_clock = {
517 .name = "umem_clk",
518 .ops = &sh7722_frqcr_clk_ops,
519 .flags = CLK_RATE_PROPAGATES,
520}; 95};
521 96
522static struct clk sh7722_sh_clock = { 97static struct clk pll_clk = {
523 .name = "sh_clk", 98 .name = "pll_clk",
524 .ops = &sh7722_frqcr_clk_ops, 99 .id = -1,
525 .flags = CLK_RATE_PROPAGATES, 100 .ops = &pll_clk_ops,
101 .flags = CLK_ENABLE_ON_INIT,
526}; 102};
527 103
528static struct clk sh7722_peripheral_clock = { 104struct clk *main_clks[] = {
529 .name = "peripheral_clk", 105 &r_clk,
530 .ops = &sh7722_frqcr_clk_ops, 106 &extal_clk,
531 .flags = CLK_RATE_PROPAGATES, 107 &dll_clk,
108 &pll_clk,
532}; 109};
533 110
534static struct clk sh7722_sdram_clock = { 111static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
535 .name = "sdram_clk", 112static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
536 .ops = &sh7722_frqcr_clk_ops,
537};
538 113
539static struct clk sh7722_r_clock = { 114static struct clk_div_mult_table div4_table = {
540 .name = "r_clk", 115 .divisors = divisors,
541 .rate = 32768, 116 .nr_divisors = ARRAY_SIZE(divisors),
542 .flags = CLK_RATE_PROPAGATES, 117 .multipliers = multipliers,
118 .nr_multipliers = ARRAY_SIZE(multipliers),
543}; 119};
544 120
545#ifndef CONFIG_CPU_SUBTYPE_SH7343 121enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P,
546 122 DIV4_SIUA, DIV4_SIUB, DIV4_IRDA, DIV4_NR };
547/*
548 * these three clocks - SIU A, SIU B, IrDA - share the same clk_ops
549 * methods of clk_ops determine which register they should access by
550 * examining clk->name field
551 */
552static struct clk sh7722_siu_a_clock = {
553 .name = "siu_a_clk",
554 .arch_flags = SCLKACR,
555 .ops = &sh7722_siu_clk_ops,
556};
557 123
558static struct clk sh7722_siu_b_clock = { 124#define DIV4(_str, _reg, _bit, _mask, _flags) \
559 .name = "siu_b_clk", 125 SH_CLK_DIV4(_str, &pll_clk, _reg, _bit, _mask, _flags)
560 .arch_flags = SCLKBCR,
561 .ops = &sh7722_siu_clk_ops,
562};
563 126
564#if defined(CONFIG_CPU_SUBTYPE_SH7722) 127struct clk div4_clks[DIV4_NR] = {
565static struct clk sh7722_irda_clock = { 128 [DIV4_I] = DIV4("cpu_clk", FRQCR, 20, 0x1fef, CLK_ENABLE_ON_INIT),
566 .name = "irda_clk", 129 [DIV4_U] = DIV4("umem_clk", FRQCR, 16, 0x1fff, CLK_ENABLE_ON_INIT),
567 .arch_flags = IrDACLKCR, 130 [DIV4_SH] = DIV4("shyway_clk", FRQCR, 12, 0x1fff, CLK_ENABLE_ON_INIT),
568 .ops = &sh7722_siu_clk_ops, 131 [DIV4_B] = DIV4("bus_clk", FRQCR, 8, 0x1fff, CLK_ENABLE_ON_INIT),
132 [DIV4_B3] = DIV4("b3_clk", FRQCR, 4, 0x1fff, CLK_ENABLE_ON_INIT),
133 [DIV4_P] = DIV4("peripheral_clk", FRQCR, 0, 0x1fff, 0),
134 [DIV4_SIUA] = DIV4("siua_clk", SCLKACR, 0, 0x1fff, 0),
135 [DIV4_SIUB] = DIV4("siub_clk", SCLKBCR, 0, 0x1fff, 0),
136 [DIV4_IRDA] = DIV4("irda_clk", IRDACLKCR, 0, 0x1fff, 0),
569}; 137};
570#endif
571#endif /* CONFIG_CPU_SUBTYPE_SH7343 */
572 138
573static struct clk sh7722_video_clock = { 139struct clk div6_clks[] = {
574 .name = "video_clk", 140 SH_CLK_DIV6("video_clk", &pll_clk, VCLKCR, 0),
575 .ops = &sh7722_video_clk_ops,
576}; 141};
577 142
578#define MSTPCR_ARCH_FLAGS(reg, bit) (((reg) << 8) | (bit)) 143#define MSTP(_str, _parent, _reg, _bit, _flags) \
579#define MSTPCR_ARCH_FLAGS_REG(value) ((value) >> 8) 144 SH_CLK_MSTP32(_str, -1, _parent, _reg, _bit, _flags)
580#define MSTPCR_ARCH_FLAGS_BIT(value) ((value) & 0xff)
581
582static int sh7722_mstpcr_start_stop(struct clk *clk, int enable)
583{
584 unsigned long bit = MSTPCR_ARCH_FLAGS_BIT(clk->arch_flags);
585 unsigned long reg;
586 unsigned long r;
587
588 switch(MSTPCR_ARCH_FLAGS_REG(clk->arch_flags)) {
589 case 0:
590 reg = MSTPCR0;
591 break;
592 case 1:
593 reg = MSTPCR1;
594 break;
595 case 2:
596 reg = MSTPCR2;
597 break;
598 default:
599 return -EINVAL;
600 }
601
602 r = ctrl_inl(reg);
603
604 if (enable)
605 r &= ~(1 << bit);
606 else
607 r |= (1 << bit);
608 145
609 ctrl_outl(r, reg); 146static struct clk mstp_clks[] = {
610 return 0; 147 MSTP("uram0", &div4_clks[DIV4_U], MSTPCR0, 28, CLK_ENABLE_ON_INIT),
611} 148 MSTP("xymem0", &div4_clks[DIV4_B], MSTPCR0, 26, CLK_ENABLE_ON_INIT),
149 MSTP("tmu0", &div4_clks[DIV4_P], MSTPCR0, 15, 0),
150 MSTP("cmt0", &r_clk, MSTPCR0, 14, 0),
151 MSTP("rwdt0", &r_clk, MSTPCR0, 13, 0),
152 MSTP("flctl0", &div4_clks[DIV4_P], MSTPCR0, 10, 0),
153 MSTP("scif0", &div4_clks[DIV4_P], MSTPCR0, 7, 0),
154 MSTP("scif1", &div4_clks[DIV4_P], MSTPCR0, 6, 0),
155 MSTP("scif2", &div4_clks[DIV4_P], MSTPCR0, 5, 0),
612 156
613static void sh7722_mstpcr_enable(struct clk *clk) 157 MSTP("i2c0", &div4_clks[DIV4_P], MSTPCR1, 9, 0),
614{ 158 MSTP("rtc0", &r_clk, MSTPCR1, 8, 0),
615 sh7722_mstpcr_start_stop(clk, 1);
616}
617 159
618static void sh7722_mstpcr_disable(struct clk *clk) 160 MSTP("sdhi0", &div4_clks[DIV4_P], MSTPCR2, 18, 0),
619{ 161 MSTP("keysc0", &r_clk, MSTPCR2, 14, 0),
620 sh7722_mstpcr_start_stop(clk, 0); 162 MSTP("usbf0", &div4_clks[DIV4_P], MSTPCR2, 11, 0),
621} 163 MSTP("2dg0", &div4_clks[DIV4_B], MSTPCR2, 9, 0),
622 164 MSTP("siu0", &div4_clks[DIV4_B], MSTPCR2, 8, 0),
623static void sh7722_mstpcr_recalc(struct clk *clk) 165 MSTP("vou0", &div4_clks[DIV4_B], MSTPCR2, 5, 0),
624{ 166 MSTP("jpu0", &div4_clks[DIV4_B], MSTPCR2, 6, CLK_ENABLE_ON_INIT),
625 if (clk->parent) 167 MSTP("beu0", &div4_clks[DIV4_B], MSTPCR2, 4, 0),
626 clk->rate = clk->parent->rate; 168 MSTP("ceu0", &div4_clks[DIV4_B], MSTPCR2, 3, 0),
627} 169 MSTP("veu0", &div4_clks[DIV4_B], MSTPCR2, 2, CLK_ENABLE_ON_INIT),
628 170 MSTP("vpu0", &div4_clks[DIV4_B], MSTPCR2, 1, CLK_ENABLE_ON_INIT),
629static struct clk_ops sh7722_mstpcr_clk_ops = { 171 MSTP("lcdc0", &div4_clks[DIV4_B], MSTPCR2, 0, 0),
630 .enable = sh7722_mstpcr_enable,
631 .disable = sh7722_mstpcr_disable,
632 .recalc = sh7722_mstpcr_recalc,
633};
634
635#define MSTPCR(_name, _parent, regnr, bitnr) \
636{ \
637 .name = _name, \
638 .arch_flags = MSTPCR_ARCH_FLAGS(regnr, bitnr), \
639 .ops = (void *)_parent, \
640}
641
642static struct clk sh7722_mstpcr_clocks[] = {
643#if defined(CONFIG_CPU_SUBTYPE_SH7722)
644 MSTPCR("uram0", "umem_clk", 0, 28),
645 MSTPCR("xymem0", "bus_clk", 0, 26),
646 MSTPCR("tmu0", "peripheral_clk", 0, 15),
647 MSTPCR("cmt0", "r_clk", 0, 14),
648 MSTPCR("rwdt0", "r_clk", 0, 13),
649 MSTPCR("flctl0", "peripheral_clk", 0, 10),
650 MSTPCR("scif0", "peripheral_clk", 0, 7),
651 MSTPCR("scif1", "peripheral_clk", 0, 6),
652 MSTPCR("scif2", "peripheral_clk", 0, 5),
653 MSTPCR("i2c0", "peripheral_clk", 1, 9),
654 MSTPCR("rtc0", "r_clk", 1, 8),
655 MSTPCR("sdhi0", "peripheral_clk", 2, 18),
656 MSTPCR("keysc0", "r_clk", 2, 14),
657 MSTPCR("usbf0", "peripheral_clk", 2, 11),
658 MSTPCR("2dg0", "bus_clk", 2, 9),
659 MSTPCR("siu0", "bus_clk", 2, 8),
660 MSTPCR("vou0", "bus_clk", 2, 5),
661 MSTPCR("jpu0", "bus_clk", 2, 6),
662 MSTPCR("beu0", "bus_clk", 2, 4),
663 MSTPCR("ceu0", "bus_clk", 2, 3),
664 MSTPCR("veu0", "bus_clk", 2, 2),
665 MSTPCR("vpu0", "bus_clk", 2, 1),
666 MSTPCR("lcdc0", "bus_clk", 2, 0),
667#endif
668#if defined(CONFIG_CPU_SUBTYPE_SH7723)
669 /* See page 60 of Datasheet V1.0: Overview -> Block Diagram */
670 MSTPCR("tlb0", "cpu_clk", 0, 31),
671 MSTPCR("ic0", "cpu_clk", 0, 30),
672 MSTPCR("oc0", "cpu_clk", 0, 29),
673 MSTPCR("l2c0", "sh_clk", 0, 28),
674 MSTPCR("ilmem0", "cpu_clk", 0, 27),
675 MSTPCR("fpu0", "cpu_clk", 0, 24),
676 MSTPCR("intc0", "cpu_clk", 0, 22),
677 MSTPCR("dmac0", "bus_clk", 0, 21),
678 MSTPCR("sh0", "sh_clk", 0, 20),
679 MSTPCR("hudi0", "peripheral_clk", 0, 19),
680 MSTPCR("ubc0", "cpu_clk", 0, 17),
681 MSTPCR("tmu0", "peripheral_clk", 0, 15),
682 MSTPCR("cmt0", "r_clk", 0, 14),
683 MSTPCR("rwdt0", "r_clk", 0, 13),
684 MSTPCR("dmac1", "bus_clk", 0, 12),
685 MSTPCR("tmu1", "peripheral_clk", 0, 11),
686 MSTPCR("flctl0", "peripheral_clk", 0, 10),
687 MSTPCR("scif0", "peripheral_clk", 0, 9),
688 MSTPCR("scif1", "peripheral_clk", 0, 8),
689 MSTPCR("scif2", "peripheral_clk", 0, 7),
690 MSTPCR("scif3", "bus_clk", 0, 6),
691 MSTPCR("scif4", "bus_clk", 0, 5),
692 MSTPCR("scif5", "bus_clk", 0, 4),
693 MSTPCR("msiof0", "bus_clk", 0, 2),
694 MSTPCR("msiof1", "bus_clk", 0, 1),
695 MSTPCR("meram0", "sh_clk", 0, 0),
696 MSTPCR("i2c0", "peripheral_clk", 1, 9),
697 MSTPCR("rtc0", "r_clk", 1, 8),
698 MSTPCR("atapi0", "sh_clk", 2, 28),
699 MSTPCR("adc0", "peripheral_clk", 2, 28),
700 MSTPCR("tpu0", "bus_clk", 2, 25),
701 MSTPCR("irda0", "peripheral_clk", 2, 24),
702 MSTPCR("tsif0", "bus_clk", 2, 22),
703 MSTPCR("icb0", "bus_clk", 2, 21),
704 MSTPCR("sdhi0", "bus_clk", 2, 18),
705 MSTPCR("sdhi1", "bus_clk", 2, 17),
706 MSTPCR("keysc0", "r_clk", 2, 14),
707 MSTPCR("usb0", "bus_clk", 2, 11),
708 MSTPCR("2dg0", "bus_clk", 2, 10),
709 MSTPCR("siu0", "bus_clk", 2, 8),
710 MSTPCR("veu1", "bus_clk", 2, 6),
711 MSTPCR("vou0", "bus_clk", 2, 5),
712 MSTPCR("beu0", "bus_clk", 2, 4),
713 MSTPCR("ceu0", "bus_clk", 2, 3),
714 MSTPCR("veu0", "bus_clk", 2, 2),
715 MSTPCR("vpu0", "bus_clk", 2, 1),
716 MSTPCR("lcdc0", "bus_clk", 2, 0),
717#endif
718#if defined(CONFIG_CPU_SUBTYPE_SH7343)
719 MSTPCR("uram0", "umem_clk", 0, 28),
720 MSTPCR("xymem0", "bus_clk", 0, 26),
721 MSTPCR("tmu0", "peripheral_clk", 0, 15),
722 MSTPCR("cmt0", "r_clk", 0, 14),
723 MSTPCR("rwdt0", "r_clk", 0, 13),
724 MSTPCR("scif0", "peripheral_clk", 0, 7),
725 MSTPCR("scif1", "peripheral_clk", 0, 6),
726 MSTPCR("scif2", "peripheral_clk", 0, 5),
727 MSTPCR("scif3", "peripheral_clk", 0, 4),
728 MSTPCR("i2c0", "peripheral_clk", 1, 9),
729 MSTPCR("i2c1", "peripheral_clk", 1, 8),
730 MSTPCR("sdhi0", "peripheral_clk", 2, 18),
731 MSTPCR("keysc0", "r_clk", 2, 14),
732 MSTPCR("usbf0", "peripheral_clk", 2, 11),
733 MSTPCR("siu0", "bus_clk", 2, 8),
734 MSTPCR("jpu0", "bus_clk", 2, 6),
735 MSTPCR("vou0", "bus_clk", 2, 5),
736 MSTPCR("beu0", "bus_clk", 2, 4),
737 MSTPCR("ceu0", "bus_clk", 2, 3),
738 MSTPCR("veu0", "bus_clk", 2, 2),
739 MSTPCR("vpu0", "bus_clk", 2, 1),
740 MSTPCR("lcdc0", "bus_clk", 2, 0),
741#endif
742#if defined(CONFIG_CPU_SUBTYPE_SH7366)
743 /* See page 52 of Datasheet V0.40: Overview -> Block Diagram */
744 MSTPCR("tlb0", "cpu_clk", 0, 31),
745 MSTPCR("ic0", "cpu_clk", 0, 30),
746 MSTPCR("oc0", "cpu_clk", 0, 29),
747 MSTPCR("rsmem0", "sh_clk", 0, 28),
748 MSTPCR("xymem0", "cpu_clk", 0, 26),
749 MSTPCR("intc30", "peripheral_clk", 0, 23),
750 MSTPCR("intc0", "peripheral_clk", 0, 22),
751 MSTPCR("dmac0", "bus_clk", 0, 21),
752 MSTPCR("sh0", "sh_clk", 0, 20),
753 MSTPCR("hudi0", "peripheral_clk", 0, 19),
754 MSTPCR("ubc0", "cpu_clk", 0, 17),
755 MSTPCR("tmu0", "peripheral_clk", 0, 15),
756 MSTPCR("cmt0", "r_clk", 0, 14),
757 MSTPCR("rwdt0", "r_clk", 0, 13),
758 MSTPCR("flctl0", "peripheral_clk", 0, 10),
759 MSTPCR("scif0", "peripheral_clk", 0, 7),
760 MSTPCR("scif1", "bus_clk", 0, 6),
761 MSTPCR("scif2", "bus_clk", 0, 5),
762 MSTPCR("msiof0", "peripheral_clk", 0, 2),
763 MSTPCR("sbr0", "peripheral_clk", 0, 1),
764 MSTPCR("i2c0", "peripheral_clk", 1, 9),
765 MSTPCR("icb0", "bus_clk", 2, 27),
766 MSTPCR("meram0", "sh_clk", 2, 26),
767 MSTPCR("dacc0", "peripheral_clk", 2, 24),
768 MSTPCR("dacy0", "peripheral_clk", 2, 23),
769 MSTPCR("tsif0", "bus_clk", 2, 22),
770 MSTPCR("sdhi0", "bus_clk", 2, 18),
771 MSTPCR("mmcif0", "bus_clk", 2, 17),
772 MSTPCR("usb0", "bus_clk", 2, 11),
773 MSTPCR("siu0", "bus_clk", 2, 8),
774 MSTPCR("veu1", "bus_clk", 2, 7),
775 MSTPCR("vou0", "bus_clk", 2, 5),
776 MSTPCR("beu0", "bus_clk", 2, 4),
777 MSTPCR("ceu0", "bus_clk", 2, 3),
778 MSTPCR("veu0", "bus_clk", 2, 2),
779 MSTPCR("vpu0", "bus_clk", 2, 1),
780 MSTPCR("lcdc0", "bus_clk", 2, 0),
781#endif
782};
783
784static struct clk *sh7722_clocks[] = {
785 &sh7722_umem_clock,
786 &sh7722_sh_clock,
787 &sh7722_peripheral_clock,
788 &sh7722_sdram_clock,
789#ifndef CONFIG_CPU_SUBTYPE_SH7343
790 &sh7722_siu_a_clock,
791 &sh7722_siu_b_clock,
792#if defined(CONFIG_CPU_SUBTYPE_SH7722)
793 &sh7722_irda_clock,
794#endif
795#endif
796 &sh7722_video_clock,
797}; 172};
798 173
799/*
800 * init in order: master, module, bus, cpu
801 */
802struct clk_ops *onchip_ops[] = {
803 &sh7722_master_clk_ops,
804 &sh7722_module_clk_ops,
805 &sh7722_frqcr_clk_ops,
806 &sh7722_frqcr_clk_ops,
807};
808
809void __init
810arch_init_clk_ops(struct clk_ops **ops, int type)
811{
812 BUG_ON(type < 0 || type > ARRAY_SIZE(onchip_ops));
813 *ops = onchip_ops[type];
814}
815
816int __init arch_clk_init(void) 174int __init arch_clk_init(void)
817{ 175{
818 struct clk *clk; 176 int k, ret = 0;
819 int i; 177
178 /* autodetect extal or dll configuration */
179 if (__raw_readl(PLLCR) & 0x1000)
180 pll_clk.parent = &dll_clk;
181 else
182 pll_clk.parent = &extal_clk;
820 183
821 clk = clk_get(NULL, "master_clk"); 184 for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
822 for (i = 0; i < ARRAY_SIZE(sh7722_clocks); i++) { 185 ret = clk_register(main_clks[k]);
823 pr_debug( "Registering clock '%s'\n", sh7722_clocks[i]->name);
824 sh7722_clocks[i]->parent = clk;
825 clk_register(sh7722_clocks[i]);
826 }
827 clk_put(clk);
828 186
829 clk_register(&sh7722_r_clock); 187 if (!ret)
188 ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
830 189
831 for (i = 0; i < ARRAY_SIZE(sh7722_mstpcr_clocks); i++) { 190 if (!ret)
832 pr_debug( "Registering mstpcr clock '%s'\n", 191 ret = sh_clk_div6_register(div6_clks, ARRAY_SIZE(div6_clks));
833 sh7722_mstpcr_clocks[i].name);
834 clk = clk_get(NULL, (void *) sh7722_mstpcr_clocks[i].ops);
835 sh7722_mstpcr_clocks[i].parent = clk;
836 sh7722_mstpcr_clocks[i].ops = &sh7722_mstpcr_clk_ops;
837 clk_register(&sh7722_mstpcr_clocks[i]);
838 clk_put(clk);
839 }
840 192
841 clk_recalc_rate(&sh7722_r_clock); /* make sure rate gets propagated */ 193 if (!ret)
194 ret = sh_clk_mstp32_register(mstp_clks, ARRAY_SIZE(mstp_clks));
842 195
843 return 0; 196 return ret;
844} 197}
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7723.c b/arch/sh/kernel/cpu/sh4a/clock-sh7723.c
new file mode 100644
index 000000000000..e67c2678b8ae
--- /dev/null
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7723.c
@@ -0,0 +1,222 @@
1/*
2 * arch/sh/kernel/cpu/sh4a/clock-sh7723.c
3 *
4 * SH7723 clock framework support
5 *
6 * Copyright (C) 2009 Magnus Damm
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21#include <linux/init.h>
22#include <linux/kernel.h>
23#include <linux/io.h>
24#include <asm/clock.h>
25
26/* SH7723 registers */
27#define FRQCR 0xa4150000
28#define VCLKCR 0xa4150004
29#define SCLKACR 0xa4150008
30#define SCLKBCR 0xa415000c
31#define IRDACLKCR 0xa4150018
32#define PLLCR 0xa4150024
33#define MSTPCR0 0xa4150030
34#define MSTPCR1 0xa4150034
35#define MSTPCR2 0xa4150038
36#define DLLFRQ 0xa4150050
37
38/* Fixed 32 KHz root clock for RTC and Power Management purposes */
39static struct clk r_clk = {
40 .name = "rclk",
41 .id = -1,
42 .rate = 32768,
43};
44
45/*
46 * Default rate for the root input clock, reset this with clk_set_rate()
47 * from the platform code.
48 */
49struct clk extal_clk = {
50 .name = "extal",
51 .id = -1,
52 .rate = 33333333,
53};
54
55/* The dll multiplies the 32khz r_clk, may be used instead of extal */
56static unsigned long dll_recalc(struct clk *clk)
57{
58 unsigned long mult;
59
60 if (__raw_readl(PLLCR) & 0x1000)
61 mult = __raw_readl(DLLFRQ);
62 else
63 mult = 0;
64
65 return clk->parent->rate * mult;
66}
67
68static struct clk_ops dll_clk_ops = {
69 .recalc = dll_recalc,
70};
71
72static struct clk dll_clk = {
73 .name = "dll_clk",
74 .id = -1,
75 .ops = &dll_clk_ops,
76 .parent = &r_clk,
77 .flags = CLK_ENABLE_ON_INIT,
78};
79
80static unsigned long pll_recalc(struct clk *clk)
81{
82 unsigned long mult = 1;
83 unsigned long div = 1;
84
85 if (__raw_readl(PLLCR) & 0x4000)
86 mult = (((__raw_readl(FRQCR) >> 24) & 0x1f) + 1);
87 else
88 div = 2;
89
90 return (clk->parent->rate * mult) / div;
91}
92
93static struct clk_ops pll_clk_ops = {
94 .recalc = pll_recalc,
95};
96
97static struct clk pll_clk = {
98 .name = "pll_clk",
99 .id = -1,
100 .ops = &pll_clk_ops,
101 .flags = CLK_ENABLE_ON_INIT,
102};
103
104struct clk *main_clks[] = {
105 &r_clk,
106 &extal_clk,
107 &dll_clk,
108 &pll_clk,
109};
110
111static int multipliers[] = { 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
112static int divisors[] = { 1, 3, 2, 5, 3, 4, 5, 6, 8, 10, 12, 16, 20 };
113
114static struct clk_div_mult_table div4_table = {
115 .divisors = divisors,
116 .nr_divisors = ARRAY_SIZE(divisors),
117 .multipliers = multipliers,
118 .nr_multipliers = ARRAY_SIZE(multipliers),
119};
120
121enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_B3, DIV4_P,
122 DIV4_SIUA, DIV4_SIUB, DIV4_IRDA, DIV4_NR };
123
124#define DIV4(_str, _reg, _bit, _mask, _flags) \
125 SH_CLK_DIV4(_str, &pll_clk, _reg, _bit, _mask, _flags)
126
127struct clk div4_clks[DIV4_NR] = {
128 [DIV4_I] = DIV4("cpu_clk", FRQCR, 20, 0x0dbf, CLK_ENABLE_ON_INIT),
129 [DIV4_U] = DIV4("umem_clk", FRQCR, 16, 0x0dbf, CLK_ENABLE_ON_INIT),
130 [DIV4_SH] = DIV4("shyway_clk", FRQCR, 12, 0x0dbf, CLK_ENABLE_ON_INIT),
131 [DIV4_B] = DIV4("bus_clk", FRQCR, 8, 0x0dbf, CLK_ENABLE_ON_INIT),
132 [DIV4_B3] = DIV4("b3_clk", FRQCR, 4, 0x0db4, CLK_ENABLE_ON_INIT),
133 [DIV4_P] = DIV4("peripheral_clk", FRQCR, 0, 0x0dbf, 0),
134 [DIV4_SIUA] = DIV4("siua_clk", SCLKACR, 0, 0x0dbf, 0),
135 [DIV4_SIUB] = DIV4("siub_clk", SCLKBCR, 0, 0x0dbf, 0),
136 [DIV4_IRDA] = DIV4("irda_clk", IRDACLKCR, 0, 0x0dbf, 0),
137};
138
139struct clk div6_clks[] = {
140 SH_CLK_DIV6("video_clk", &pll_clk, VCLKCR, 0),
141};
142
143#define MSTP(_str, _parent, _reg, _bit, _force_on, _need_cpg, _need_ram) \
144 SH_CLK_MSTP32(_str, -1, _parent, _reg, _bit, _force_on * CLK_ENABLE_ON_INIT)
145
146static struct clk mstp_clks[] = {
147 /* See page 60 of Datasheet V1.0: Overview -> Block Diagram */
148 MSTP("tlb0", &div4_clks[DIV4_I], MSTPCR0, 31, 1, 1, 0),
149 MSTP("ic0", &div4_clks[DIV4_I], MSTPCR0, 30, 1, 1, 0),
150 MSTP("oc0", &div4_clks[DIV4_I], MSTPCR0, 29, 1, 1, 0),
151 MSTP("l2c0", &div4_clks[DIV4_SH], MSTPCR0, 28, 1, 1, 0),
152 MSTP("ilmem0", &div4_clks[DIV4_I], MSTPCR0, 27, 1, 1, 0),
153 MSTP("fpu0", &div4_clks[DIV4_I], MSTPCR0, 24, 1, 1, 0),
154 MSTP("intc0", &div4_clks[DIV4_I], MSTPCR0, 22, 1, 1, 0),
155 MSTP("dmac0", &div4_clks[DIV4_B], MSTPCR0, 21, 0, 1, 1),
156 MSTP("sh0", &div4_clks[DIV4_SH], MSTPCR0, 20, 0, 1, 0),
157 MSTP("hudi0", &div4_clks[DIV4_P], MSTPCR0, 19, 0, 1, 0),
158 MSTP("ubc0", &div4_clks[DIV4_I], MSTPCR0, 17, 0, 1, 0),
159 MSTP("tmu0", &div4_clks[DIV4_P], MSTPCR0, 15, 0, 1, 0),
160 MSTP("cmt0", &r_clk, MSTPCR0, 14, 0, 0, 0),
161 MSTP("rwdt0", &r_clk, MSTPCR0, 13, 0, 0, 0),
162 MSTP("dmac1", &div4_clks[DIV4_B], MSTPCR0, 12, 0, 1, 1),
163 MSTP("tmu1", &div4_clks[DIV4_P], MSTPCR0, 11, 0, 1, 0),
164 MSTP("flctl0", &div4_clks[DIV4_P], MSTPCR0, 10, 0, 1, 0),
165 MSTP("scif0", &div4_clks[DIV4_P], MSTPCR0, 9, 0, 1, 0),
166 MSTP("scif1", &div4_clks[DIV4_P], MSTPCR0, 8, 0, 1, 0),
167 MSTP("scif2", &div4_clks[DIV4_P], MSTPCR0, 7, 0, 1, 0),
168 MSTP("scif3", &div4_clks[DIV4_B], MSTPCR0, 6, 0, 1, 0),
169 MSTP("scif4", &div4_clks[DIV4_B], MSTPCR0, 5, 0, 1, 0),
170 MSTP("scif5", &div4_clks[DIV4_B], MSTPCR0, 4, 0, 1, 0),
171 MSTP("msiof0", &div4_clks[DIV4_B], MSTPCR0, 2, 0, 1, 0),
172 MSTP("msiof1", &div4_clks[DIV4_B], MSTPCR0, 1, 0, 1, 0),
173 MSTP("meram0", &div4_clks[DIV4_SH], MSTPCR0, 0, 1, 1, 0),
174
175 MSTP("i2c0", &div4_clks[DIV4_P], MSTPCR1, 9, 0, 1, 0),
176 MSTP("rtc0", &r_clk, MSTPCR1, 8, 0, 0, 0),
177
178 MSTP("atapi0", &div4_clks[DIV4_SH], MSTPCR2, 28, 0, 1, 0),
179 MSTP("adc0", &div4_clks[DIV4_P], MSTPCR2, 27, 0, 1, 0),
180 MSTP("tpu0", &div4_clks[DIV4_B], MSTPCR2, 25, 0, 1, 0),
181 MSTP("irda0", &div4_clks[DIV4_P], MSTPCR2, 24, 0, 1, 0),
182 MSTP("tsif0", &div4_clks[DIV4_B], MSTPCR2, 22, 0, 1, 0),
183 MSTP("icb0", &div4_clks[DIV4_B], MSTPCR2, 21, 0, 1, 1),
184 MSTP("sdhi0", &div4_clks[DIV4_B], MSTPCR2, 18, 0, 1, 0),
185 MSTP("sdhi1", &div4_clks[DIV4_B], MSTPCR2, 17, 0, 1, 0),
186 MSTP("keysc0", &r_clk, MSTPCR2, 14, 0, 0, 0),
187 MSTP("usb0", &div4_clks[DIV4_B], MSTPCR2, 11, 0, 1, 0),
188 MSTP("2dg0", &div4_clks[DIV4_B], MSTPCR2, 10, 0, 1, 1),
189 MSTP("siu0", &div4_clks[DIV4_B], MSTPCR2, 8, 0, 1, 0),
190 MSTP("veu1", &div4_clks[DIV4_B], MSTPCR2, 6, 1, 1, 1),
191 MSTP("vou0", &div4_clks[DIV4_B], MSTPCR2, 5, 0, 1, 1),
192 MSTP("beu0", &div4_clks[DIV4_B], MSTPCR2, 4, 0, 1, 1),
193 MSTP("ceu0", &div4_clks[DIV4_B], MSTPCR2, 3, 0, 1, 1),
194 MSTP("veu0", &div4_clks[DIV4_B], MSTPCR2, 2, 1, 1, 1),
195 MSTP("vpu0", &div4_clks[DIV4_B], MSTPCR2, 1, 1, 1, 1),
196 MSTP("lcdc0", &div4_clks[DIV4_B], MSTPCR2, 0, 0, 1, 1),
197};
198
199int __init arch_clk_init(void)
200{
201 int k, ret = 0;
202
203 /* autodetect extal or dll configuration */
204 if (__raw_readl(PLLCR) & 0x1000)
205 pll_clk.parent = &dll_clk;
206 else
207 pll_clk.parent = &extal_clk;
208
209 for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
210 ret = clk_register(main_clks[k]);
211
212 if (!ret)
213 ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
214
215 if (!ret)
216 ret = sh_clk_div6_register(div6_clks, ARRAY_SIZE(div6_clks));
217
218 if (!ret)
219 ret = sh_clk_mstp32_register(mstp_clks, ARRAY_SIZE(mstp_clks));
220
221 return ret;
222}
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7724.c b/arch/sh/kernel/cpu/sh4a/clock-sh7724.c
new file mode 100644
index 000000000000..5d5c9b952883
--- /dev/null
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7724.c
@@ -0,0 +1,242 @@
1/*
2 * arch/sh/kernel/cpu/sh4a/clock-sh7724.c
3 *
4 * SH7724 clock framework support
5 *
6 * Copyright (C) 2009 Magnus Damm
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21#include <linux/init.h>
22#include <linux/kernel.h>
23#include <linux/io.h>
24#include <asm/clock.h>
25
26/* SH7724 registers */
27#define FRQCRA 0xa4150000
28#define FRQCRB 0xa4150004
29#define VCLKCR 0xa4150048
30#define FCLKACR 0xa4150008
31#define FCLKBCR 0xa415000c
32#define IRDACLKCR 0xa4150018
33#define PLLCR 0xa4150024
34#define MSTPCR0 0xa4150030
35#define MSTPCR1 0xa4150034
36#define MSTPCR2 0xa4150038
37#define SPUCLKCR 0xa415003c
38#define FLLFRQ 0xa4150050
39#define LSTATS 0xa4150060
40
41/* Fixed 32 KHz root clock for RTC and Power Management purposes */
42static struct clk r_clk = {
43 .name = "rclk",
44 .id = -1,
45 .rate = 32768,
46};
47
48/*
49 * Default rate for the root input clock, reset this with clk_set_rate()
50 * from the platform code.
51 */
52struct clk extal_clk = {
53 .name = "extal",
54 .id = -1,
55 .rate = 33333333,
56};
57
58/* The fll multiplies the 32khz r_clk, may be used instead of extal */
59static unsigned long fll_recalc(struct clk *clk)
60{
61 unsigned long mult = 0;
62 unsigned long div = 1;
63
64 if (__raw_readl(PLLCR) & 0x1000)
65 mult = __raw_readl(FLLFRQ) & 0x3ff;
66
67 if (__raw_readl(FLLFRQ) & 0x4000)
68 div = 2;
69
70 return (clk->parent->rate * mult) / div;
71}
72
73static struct clk_ops fll_clk_ops = {
74 .recalc = fll_recalc,
75};
76
77static struct clk fll_clk = {
78 .name = "fll_clk",
79 .id = -1,
80 .ops = &fll_clk_ops,
81 .parent = &r_clk,
82 .flags = CLK_ENABLE_ON_INIT,
83};
84
85static unsigned long pll_recalc(struct clk *clk)
86{
87 unsigned long mult = 1;
88
89 if (__raw_readl(PLLCR) & 0x4000)
90 mult = (((__raw_readl(FRQCRA) >> 24) & 0x3f) + 1) * 2;
91
92 return clk->parent->rate * mult;
93}
94
95static struct clk_ops pll_clk_ops = {
96 .recalc = pll_recalc,
97};
98
99static struct clk pll_clk = {
100 .name = "pll_clk",
101 .id = -1,
102 .ops = &pll_clk_ops,
103 .flags = CLK_ENABLE_ON_INIT,
104};
105
106/* A fixed divide-by-3 block use by the div6 clocks */
107static unsigned long div3_recalc(struct clk *clk)
108{
109 return clk->parent->rate / 3;
110}
111
112static struct clk_ops div3_clk_ops = {
113 .recalc = div3_recalc,
114};
115
116static struct clk div3_clk = {
117 .name = "div3_clk",
118 .id = -1,
119 .ops = &div3_clk_ops,
120 .parent = &pll_clk,
121};
122
123struct clk *main_clks[] = {
124 &r_clk,
125 &extal_clk,
126 &fll_clk,
127 &pll_clk,
128 &div3_clk,
129};
130
131static int divisors[] = { 2, 0, 4, 6, 8, 12, 16, 0, 24, 32, 36, 48, 0, 72 };
132
133static struct clk_div_mult_table div4_table = {
134 .divisors = divisors,
135 .nr_divisors = ARRAY_SIZE(divisors),
136};
137
138enum { DIV4_I, DIV4_SH, DIV4_B, DIV4_P, DIV4_M1, DIV4_NR };
139
140#define DIV4(_str, _reg, _bit, _mask, _flags) \
141 SH_CLK_DIV4(_str, &pll_clk, _reg, _bit, _mask, _flags)
142
143struct clk div4_clks[DIV4_NR] = {
144 [DIV4_I] = DIV4("cpu_clk", FRQCRA, 20, 0x2f7d, CLK_ENABLE_ON_INIT),
145 [DIV4_SH] = DIV4("shyway_clk", FRQCRA, 12, 0x2f7c, CLK_ENABLE_ON_INIT),
146 [DIV4_B] = DIV4("bus_clk", FRQCRA, 8, 0x2f7c, CLK_ENABLE_ON_INIT),
147 [DIV4_P] = DIV4("peripheral_clk", FRQCRA, 0, 0x2f7c, 0),
148 [DIV4_M1] = DIV4("vpu_clk", FRQCRB, 4, 0x2f7c, 0),
149};
150
151struct clk div6_clks[] = {
152 SH_CLK_DIV6("video_clk", &div3_clk, VCLKCR, 0),
153 SH_CLK_DIV6("fsia_clk", &div3_clk, FCLKACR, 0),
154 SH_CLK_DIV6("fsib_clk", &div3_clk, FCLKBCR, 0),
155 SH_CLK_DIV6("irda_clk", &div3_clk, IRDACLKCR, 0),
156 SH_CLK_DIV6("spu_clk", &div3_clk, SPUCLKCR, 0),
157};
158
159#define MSTP(_str, _parent, _reg, _bit, _force_on, _need_cpg, _need_ram) \
160 SH_CLK_MSTP32(_str, -1, _parent, _reg, _bit, _force_on * CLK_ENABLE_ON_INIT)
161
162static struct clk mstp_clks[] = {
163 MSTP("tlb0", &div4_clks[DIV4_I], MSTPCR0, 31, 1, 1, 0),
164 MSTP("ic0", &div4_clks[DIV4_I], MSTPCR0, 30, 1, 1, 0),
165 MSTP("oc0", &div4_clks[DIV4_I], MSTPCR0, 29, 1, 1, 0),
166 MSTP("rs0", &div4_clks[DIV4_B], MSTPCR0, 28, 1, 1, 0),
167 MSTP("ilmem0", &div4_clks[DIV4_I], MSTPCR0, 27, 1, 1, 0),
168 MSTP("l2c0", &div4_clks[DIV4_SH], MSTPCR0, 26, 1, 1, 0),
169 MSTP("fpu0", &div4_clks[DIV4_I], MSTPCR0, 24, 1, 1, 0),
170 MSTP("intc0", &div4_clks[DIV4_P], MSTPCR0, 22, 1, 1, 0),
171 MSTP("dmac0", &div4_clks[DIV4_B], MSTPCR0, 21, 0, 1, 1),
172 MSTP("sh0", &div4_clks[DIV4_SH], MSTPCR0, 20, 0, 1, 0),
173 MSTP("hudi0", &div4_clks[DIV4_P], MSTPCR0, 19, 0, 1, 0),
174 MSTP("ubc0", &div4_clks[DIV4_I], MSTPCR0, 17, 0, 1, 0),
175 MSTP("tmu0", &div4_clks[DIV4_P], MSTPCR0, 15, 0, 1, 0),
176 MSTP("cmt0", &r_clk, MSTPCR0, 14, 0, 0, 0),
177 MSTP("rwdt0", &r_clk, MSTPCR0, 13, 0, 0, 0),
178 MSTP("dmac1", &div4_clks[DIV4_B], MSTPCR0, 12, 0, 1, 1),
179 MSTP("tmu1", &div4_clks[DIV4_P], MSTPCR0, 10, 0, 1, 0),
180 MSTP("scif0", &div4_clks[DIV4_P], MSTPCR0, 9, 0, 1, 0),
181 MSTP("scif1", &div4_clks[DIV4_P], MSTPCR0, 8, 0, 1, 0),
182 MSTP("scif2", &div4_clks[DIV4_P], MSTPCR0, 7, 0, 1, 0),
183 MSTP("scif3", &div4_clks[DIV4_B], MSTPCR0, 6, 0, 1, 0),
184 MSTP("scif4", &div4_clks[DIV4_B], MSTPCR0, 5, 0, 1, 0),
185 MSTP("scif5", &div4_clks[DIV4_B], MSTPCR0, 4, 0, 1, 0),
186 MSTP("msiof0", &div4_clks[DIV4_B], MSTPCR0, 2, 0, 1, 0),
187 MSTP("msiof1", &div4_clks[DIV4_B], MSTPCR0, 1, 0, 1, 0),
188
189 MSTP("keysc0", &r_clk, MSTPCR1, 12, 0, 0, 0),
190 MSTP("rtc0", &r_clk, MSTPCR1, 11, 0, 0, 0),
191 MSTP("i2c0", &div4_clks[DIV4_P], MSTPCR1, 9, 0, 1, 0),
192 MSTP("i2c1", &div4_clks[DIV4_P], MSTPCR1, 8, 0, 1, 0),
193
194 MSTP("mmc0", &div4_clks[DIV4_B], MSTPCR2, 29, 0, 1, 0),
195 MSTP("eth0", &div4_clks[DIV4_B], MSTPCR2, 28, 0, 1, 0),
196 MSTP("atapi0", &div4_clks[DIV4_B], MSTPCR2, 26, 0, 1, 0),
197 MSTP("tpu0", &div4_clks[DIV4_B], MSTPCR2, 25, 0, 1, 0),
198 MSTP("irda0", &div4_clks[DIV4_P], MSTPCR2, 24, 0, 1, 0),
199 MSTP("tsif0", &div4_clks[DIV4_B], MSTPCR2, 22, 0, 1, 0),
200 MSTP("usb1", &div4_clks[DIV4_B], MSTPCR2, 21, 0, 1, 1),
201 MSTP("usb0", &div4_clks[DIV4_B], MSTPCR2, 20, 0, 1, 1),
202 MSTP("2dg0", &div4_clks[DIV4_B], MSTPCR2, 19, 0, 1, 1),
203 MSTP("sdhi0", &div4_clks[DIV4_B], MSTPCR2, 18, 0, 1, 0),
204 MSTP("sdhi1", &div4_clks[DIV4_B], MSTPCR2, 17, 0, 1, 0),
205 MSTP("veu1", &div4_clks[DIV4_B], MSTPCR2, 15, 1, 1, 1),
206 MSTP("ceu1", &div4_clks[DIV4_B], MSTPCR2, 13, 0, 1, 1),
207 MSTP("beu1", &div4_clks[DIV4_B], MSTPCR2, 12, 0, 1, 1),
208 MSTP("2ddmac0", &div4_clks[DIV4_SH], MSTPCR2, 10, 0, 1, 1),
209 MSTP("spu0", &div4_clks[DIV4_B], MSTPCR2, 9, 0, 1, 0),
210 MSTP("jpu0", &div4_clks[DIV4_B], MSTPCR2, 6, 1, 1, 1),
211 MSTP("vou0", &div4_clks[DIV4_B], MSTPCR2, 5, 0, 1, 1),
212 MSTP("beu0", &div4_clks[DIV4_B], MSTPCR2, 4, 0, 1, 1),
213 MSTP("ceu0", &div4_clks[DIV4_B], MSTPCR2, 3, 0, 1, 1),
214 MSTP("veu0", &div4_clks[DIV4_B], MSTPCR2, 2, 1, 1, 1),
215 MSTP("vpu0", &div4_clks[DIV4_B], MSTPCR2, 1, 1, 1, 1),
216 MSTP("lcdc0", &div4_clks[DIV4_B], MSTPCR2, 0, 0, 1, 1),
217};
218
219int __init arch_clk_init(void)
220{
221 int k, ret = 0;
222
223 /* autodetect extal or fll configuration */
224 if (__raw_readl(PLLCR) & 0x1000)
225 pll_clk.parent = &fll_clk;
226 else
227 pll_clk.parent = &extal_clk;
228
229 for (k = 0; !ret && (k < ARRAY_SIZE(main_clks)); k++)
230 ret = clk_register(main_clks[k]);
231
232 if (!ret)
233 ret = sh_clk_div4_register(div4_clks, DIV4_NR, &div4_table);
234
235 if (!ret)
236 ret = sh_clk_div6_register(div6_clks, ARRAY_SIZE(div6_clks));
237
238 if (!ret)
239 ret = sh_clk_mstp32_register(mstp_clks, ARRAY_SIZE(mstp_clks));
240
241 return ret;
242}
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7763.c b/arch/sh/kernel/cpu/sh4a/clock-sh7763.c
index 3177d0d1e06d..370cd47642ef 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7763.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7763.c
@@ -29,33 +29,28 @@ static struct clk_ops sh7763_master_clk_ops = {
29 .init = master_clk_init, 29 .init = master_clk_init,
30}; 30};
31 31
32static void module_clk_recalc(struct clk *clk) 32static unsigned long module_clk_recalc(struct clk *clk)
33{ 33{
34 int idx = ((ctrl_inl(FRQCR) >> 4) & 0x07); 34 int idx = ((ctrl_inl(FRQCR) >> 4) & 0x07);
35 clk->rate = clk->parent->rate / p0fc_divisors[idx]; 35 return clk->parent->rate / p0fc_divisors[idx];
36} 36}
37 37
38static struct clk_ops sh7763_module_clk_ops = { 38static struct clk_ops sh7763_module_clk_ops = {
39 .recalc = module_clk_recalc, 39 .recalc = module_clk_recalc,
40}; 40};
41 41
42static void bus_clk_recalc(struct clk *clk) 42static unsigned long bus_clk_recalc(struct clk *clk)
43{ 43{
44 int idx = ((ctrl_inl(FRQCR) >> 16) & 0x07); 44 int idx = ((ctrl_inl(FRQCR) >> 16) & 0x07);
45 clk->rate = clk->parent->rate / bfc_divisors[idx]; 45 return clk->parent->rate / bfc_divisors[idx];
46} 46}
47 47
48static struct clk_ops sh7763_bus_clk_ops = { 48static struct clk_ops sh7763_bus_clk_ops = {
49 .recalc = bus_clk_recalc, 49 .recalc = bus_clk_recalc,
50}; 50};
51 51
52static void cpu_clk_recalc(struct clk *clk)
53{
54 clk->rate = clk->parent->rate;
55}
56
57static struct clk_ops sh7763_cpu_clk_ops = { 52static struct clk_ops sh7763_cpu_clk_ops = {
58 .recalc = cpu_clk_recalc, 53 .recalc = followparent_recalc,
59}; 54};
60 55
61static struct clk_ops *sh7763_clk_ops[] = { 56static struct clk_ops *sh7763_clk_ops[] = {
@@ -71,10 +66,10 @@ void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
71 *ops = sh7763_clk_ops[idx]; 66 *ops = sh7763_clk_ops[idx];
72} 67}
73 68
74static void shyway_clk_recalc(struct clk *clk) 69static unsigned long shyway_clk_recalc(struct clk *clk)
75{ 70{
76 int idx = ((ctrl_inl(FRQCR) >> 20) & 0x07); 71 int idx = ((ctrl_inl(FRQCR) >> 20) & 0x07);
77 clk->rate = clk->parent->rate / cfc_divisors[idx]; 72 return clk->parent->rate / cfc_divisors[idx];
78} 73}
79 74
80static struct clk_ops sh7763_shyway_clk_ops = { 75static struct clk_ops sh7763_shyway_clk_ops = {
@@ -83,7 +78,7 @@ static struct clk_ops sh7763_shyway_clk_ops = {
83 78
84static struct clk sh7763_shyway_clk = { 79static struct clk sh7763_shyway_clk = {
85 .name = "shyway_clk", 80 .name = "shyway_clk",
86 .flags = CLK_ALWAYS_ENABLED, 81 .flags = CLK_ENABLE_ON_INIT,
87 .ops = &sh7763_shyway_clk_ops, 82 .ops = &sh7763_shyway_clk_ops,
88}; 83};
89 84
@@ -95,31 +90,22 @@ static struct clk *sh7763_onchip_clocks[] = {
95 &sh7763_shyway_clk, 90 &sh7763_shyway_clk,
96}; 91};
97 92
98static int __init sh7763_clk_init(void) 93int __init arch_clk_init(void)
99{ 94{
100 struct clk *clk = clk_get(NULL, "master_clk"); 95 struct clk *clk;
101 int i; 96 int i, ret = 0;
97
98 cpg_clk_init();
102 99
100 clk = clk_get(NULL, "master_clk");
103 for (i = 0; i < ARRAY_SIZE(sh7763_onchip_clocks); i++) { 101 for (i = 0; i < ARRAY_SIZE(sh7763_onchip_clocks); i++) {
104 struct clk *clkp = sh7763_onchip_clocks[i]; 102 struct clk *clkp = sh7763_onchip_clocks[i];
105 103
106 clkp->parent = clk; 104 clkp->parent = clk;
107 clk_register(clkp); 105 ret |= clk_register(clkp);
108 clk_enable(clkp);
109 } 106 }
110 107
111 /*
112 * Now that we have the rest of the clocks registered, we need to
113 * force the parent clock to propagate so that these clocks will
114 * automatically figure out their rate. We cheat by handing the
115 * parent clock its current rate and forcing child propagation.
116 */
117 clk_set_rate(clk, clk_get_rate(clk));
118
119 clk_put(clk); 108 clk_put(clk);
120 109
121 return 0; 110 return ret;
122} 111}
123
124arch_initcall(sh7763_clk_init);
125
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7770.c b/arch/sh/kernel/cpu/sh4a/clock-sh7770.c
index 8e236062c721..e0b896769205 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7770.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7770.c
@@ -28,30 +28,30 @@ static struct clk_ops sh7770_master_clk_ops = {
28 .init = master_clk_init, 28 .init = master_clk_init,
29}; 29};
30 30
31static void module_clk_recalc(struct clk *clk) 31static unsigned long module_clk_recalc(struct clk *clk)
32{ 32{
33 int idx = ((ctrl_inl(FRQCR) >> 28) & 0x000f); 33 int idx = ((ctrl_inl(FRQCR) >> 28) & 0x000f);
34 clk->rate = clk->parent->rate / pfc_divisors[idx]; 34 return clk->parent->rate / pfc_divisors[idx];
35} 35}
36 36
37static struct clk_ops sh7770_module_clk_ops = { 37static struct clk_ops sh7770_module_clk_ops = {
38 .recalc = module_clk_recalc, 38 .recalc = module_clk_recalc,
39}; 39};
40 40
41static void bus_clk_recalc(struct clk *clk) 41static unsigned long bus_clk_recalc(struct clk *clk)
42{ 42{
43 int idx = (ctrl_inl(FRQCR) & 0x000f); 43 int idx = (ctrl_inl(FRQCR) & 0x000f);
44 clk->rate = clk->parent->rate / bfc_divisors[idx]; 44 return clk->parent->rate / bfc_divisors[idx];
45} 45}
46 46
47static struct clk_ops sh7770_bus_clk_ops = { 47static struct clk_ops sh7770_bus_clk_ops = {
48 .recalc = bus_clk_recalc, 48 .recalc = bus_clk_recalc,
49}; 49};
50 50
51static void cpu_clk_recalc(struct clk *clk) 51static unsigned long cpu_clk_recalc(struct clk *clk)
52{ 52{
53 int idx = ((ctrl_inl(FRQCR) >> 24) & 0x000f); 53 int idx = ((ctrl_inl(FRQCR) >> 24) & 0x000f);
54 clk->rate = clk->parent->rate / ifc_divisors[idx]; 54 return clk->parent->rate / ifc_divisors[idx];
55} 55}
56 56
57static struct clk_ops sh7770_cpu_clk_ops = { 57static struct clk_ops sh7770_cpu_clk_ops = {
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7780.c b/arch/sh/kernel/cpu/sh4a/clock-sh7780.c
index 01f3da619d3d..a249d823578e 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7780.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7780.c
@@ -29,30 +29,30 @@ static struct clk_ops sh7780_master_clk_ops = {
29 .init = master_clk_init, 29 .init = master_clk_init,
30}; 30};
31 31
32static void module_clk_recalc(struct clk *clk) 32static unsigned long module_clk_recalc(struct clk *clk)
33{ 33{
34 int idx = (ctrl_inl(FRQCR) & 0x0003); 34 int idx = (ctrl_inl(FRQCR) & 0x0003);
35 clk->rate = clk->parent->rate / pfc_divisors[idx]; 35 return clk->parent->rate / pfc_divisors[idx];
36} 36}
37 37
38static struct clk_ops sh7780_module_clk_ops = { 38static struct clk_ops sh7780_module_clk_ops = {
39 .recalc = module_clk_recalc, 39 .recalc = module_clk_recalc,
40}; 40};
41 41
42static void bus_clk_recalc(struct clk *clk) 42static unsigned long bus_clk_recalc(struct clk *clk)
43{ 43{
44 int idx = ((ctrl_inl(FRQCR) >> 16) & 0x0007); 44 int idx = ((ctrl_inl(FRQCR) >> 16) & 0x0007);
45 clk->rate = clk->parent->rate / bfc_divisors[idx]; 45 return clk->parent->rate / bfc_divisors[idx];
46} 46}
47 47
48static struct clk_ops sh7780_bus_clk_ops = { 48static struct clk_ops sh7780_bus_clk_ops = {
49 .recalc = bus_clk_recalc, 49 .recalc = bus_clk_recalc,
50}; 50};
51 51
52static void cpu_clk_recalc(struct clk *clk) 52static unsigned long cpu_clk_recalc(struct clk *clk)
53{ 53{
54 int idx = ((ctrl_inl(FRQCR) >> 24) & 0x0001); 54 int idx = ((ctrl_inl(FRQCR) >> 24) & 0x0001);
55 clk->rate = clk->parent->rate / ifc_divisors[idx]; 55 return clk->parent->rate / ifc_divisors[idx];
56} 56}
57 57
58static struct clk_ops sh7780_cpu_clk_ops = { 58static struct clk_ops sh7780_cpu_clk_ops = {
@@ -72,10 +72,10 @@ void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
72 *ops = sh7780_clk_ops[idx]; 72 *ops = sh7780_clk_ops[idx];
73} 73}
74 74
75static void shyway_clk_recalc(struct clk *clk) 75static unsigned long shyway_clk_recalc(struct clk *clk)
76{ 76{
77 int idx = ((ctrl_inl(FRQCR) >> 20) & 0x0007); 77 int idx = ((ctrl_inl(FRQCR) >> 20) & 0x0007);
78 clk->rate = clk->parent->rate / cfc_divisors[idx]; 78 return clk->parent->rate / cfc_divisors[idx];
79} 79}
80 80
81static struct clk_ops sh7780_shyway_clk_ops = { 81static struct clk_ops sh7780_shyway_clk_ops = {
@@ -84,7 +84,7 @@ static struct clk_ops sh7780_shyway_clk_ops = {
84 84
85static struct clk sh7780_shyway_clk = { 85static struct clk sh7780_shyway_clk = {
86 .name = "shyway_clk", 86 .name = "shyway_clk",
87 .flags = CLK_ALWAYS_ENABLED, 87 .flags = CLK_ENABLE_ON_INIT,
88 .ops = &sh7780_shyway_clk_ops, 88 .ops = &sh7780_shyway_clk_ops,
89}; 89};
90 90
@@ -96,31 +96,22 @@ static struct clk *sh7780_onchip_clocks[] = {
96 &sh7780_shyway_clk, 96 &sh7780_shyway_clk,
97}; 97};
98 98
99static int __init sh7780_clk_init(void) 99int __init arch_clk_init(void)
100{ 100{
101 struct clk *clk = clk_get(NULL, "master_clk"); 101 struct clk *clk;
102 int i; 102 int i, ret = 0;
103 103
104 cpg_clk_init();
105
106 clk = clk_get(NULL, "master_clk");
104 for (i = 0; i < ARRAY_SIZE(sh7780_onchip_clocks); i++) { 107 for (i = 0; i < ARRAY_SIZE(sh7780_onchip_clocks); i++) {
105 struct clk *clkp = sh7780_onchip_clocks[i]; 108 struct clk *clkp = sh7780_onchip_clocks[i];
106 109
107 clkp->parent = clk; 110 clkp->parent = clk;
108 clk_register(clkp); 111 ret |= clk_register(clkp);
109 clk_enable(clkp);
110 } 112 }
111 113
112 /*
113 * Now that we have the rest of the clocks registered, we need to
114 * force the parent clock to propagate so that these clocks will
115 * automatically figure out their rate. We cheat by handing the
116 * parent clock its current rate and forcing child propagation.
117 */
118 clk_set_rate(clk, clk_get_rate(clk));
119
120 clk_put(clk); 114 clk_put(clk);
121 115
122 return 0; 116 return ret;
123} 117}
124
125arch_initcall(sh7780_clk_init);
126
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7785.c b/arch/sh/kernel/cpu/sh4a/clock-sh7785.c
index 27fa81bef6a0..73abfbf2f16d 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7785.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7785.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * SH7785 support for the clock framework 4 * SH7785 support for the clock framework
5 * 5 *
6 * Copyright (C) 2007 Paul Mundt 6 * Copyright (C) 2007 - 2009 Paul Mundt
7 * 7 *
8 * This file is subject to the terms and conditions of the GNU General Public 8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive 9 * License. See the file "COPYING" in the main directory of this archive
@@ -11,152 +11,116 @@
11 */ 11 */
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/clk.h>
15#include <linux/io.h>
16#include <linux/cpufreq.h>
14#include <asm/clock.h> 17#include <asm/clock.h>
15#include <asm/freq.h> 18#include <asm/freq.h>
16#include <asm/io.h> 19#include <cpu/sh7785.h>
17
18static int ifc_divisors[] = { 1, 2, 4, 6 };
19static int ufc_divisors[] = { 1, 1, 4, 6 };
20static int sfc_divisors[] = { 1, 1, 4, 6 };
21static int bfc_divisors[] = { 1, 1, 1, 1, 1, 12, 16, 18,
22 24, 32, 36, 48, 1, 1, 1, 1 };
23static int mfc_divisors[] = { 1, 1, 4, 6 };
24static int pfc_divisors[] = { 1, 1, 1, 1, 1, 1, 1, 18,
25 24, 32, 36, 48, 1, 1, 1, 1 };
26
27static void master_clk_init(struct clk *clk)
28{
29 clk->rate *= pfc_divisors[ctrl_inl(FRQMR1) & 0x000f];
30}
31 20
32static struct clk_ops sh7785_master_clk_ops = { 21/*
33 .init = master_clk_init, 22 * Default rate for the root input clock, reset this with clk_set_rate()
23 * from the platform code.
24 */
25static struct clk extal_clk = {
26 .name = "extal",
27 .id = -1,
28 .rate = 33333333,
34}; 29};
35 30
36static void module_clk_recalc(struct clk *clk) 31static unsigned long pll_recalc(struct clk *clk)
37{ 32{
38 int idx = (ctrl_inl(FRQMR1) & 0x000f); 33 int multiplier;
39 clk->rate = clk->parent->rate / pfc_divisors[idx];
40}
41 34
42static struct clk_ops sh7785_module_clk_ops = { 35 multiplier = test_mode_pin(MODE_PIN4) ? 36 : 72;
43 .recalc = module_clk_recalc,
44};
45 36
46static void bus_clk_recalc(struct clk *clk) 37 return clk->parent->rate * multiplier;
47{
48 int idx = ((ctrl_inl(FRQMR1) >> 16) & 0x000f);
49 clk->rate = clk->parent->rate / bfc_divisors[idx];
50} 38}
51 39
52static struct clk_ops sh7785_bus_clk_ops = { 40static struct clk_ops pll_clk_ops = {
53 .recalc = bus_clk_recalc, 41 .recalc = pll_recalc,
54}; 42};
55 43
56static void cpu_clk_recalc(struct clk *clk) 44static struct clk pll_clk = {
57{ 45 .name = "pll_clk",
58 int idx = ((ctrl_inl(FRQMR1) >> 28) & 0x0003); 46 .id = -1,
59 clk->rate = clk->parent->rate / ifc_divisors[idx]; 47 .ops = &pll_clk_ops,
60} 48 .parent = &extal_clk,
61 49 .flags = CLK_ENABLE_ON_INIT,
62static struct clk_ops sh7785_cpu_clk_ops = {
63 .recalc = cpu_clk_recalc,
64}; 50};
65 51
66static struct clk_ops *sh7785_clk_ops[] = { 52static struct clk *clks[] = {
67 &sh7785_master_clk_ops, 53 &extal_clk,
68 &sh7785_module_clk_ops, 54 &pll_clk,
69 &sh7785_bus_clk_ops,
70 &sh7785_cpu_clk_ops,
71}; 55};
72 56
73void __init arch_init_clk_ops(struct clk_ops **ops, int idx) 57static unsigned int div2[] = { 1, 2, 4, 6, 8, 12, 16, 18,
74{ 58 24, 32, 36, 48 };
75 if (idx < ARRAY_SIZE(sh7785_clk_ops))
76 *ops = sh7785_clk_ops[idx];
77}
78
79static void shyway_clk_recalc(struct clk *clk)
80{
81 int idx = ((ctrl_inl(FRQMR1) >> 20) & 0x0003);
82 clk->rate = clk->parent->rate / sfc_divisors[idx];
83}
84 59
85static struct clk_ops sh7785_shyway_clk_ops = { 60static struct clk_div_mult_table div4_table = {
86 .recalc = shyway_clk_recalc, 61 .divisors = div2,
62 .nr_divisors = ARRAY_SIZE(div2),
87}; 63};
88 64
89static struct clk sh7785_shyway_clk = { 65enum { DIV4_I, DIV4_U, DIV4_SH, DIV4_B, DIV4_DDR, DIV4_GA,
90 .name = "shyway_clk", 66 DIV4_DU, DIV4_P, DIV4_NR };
91 .flags = CLK_ALWAYS_ENABLED, 67
92 .ops = &sh7785_shyway_clk_ops, 68#define DIV4(_str, _bit, _mask, _flags) \
69 SH_CLK_DIV4(_str, &pll_clk, FRQMR1, _bit, _mask, _flags)
70
71struct clk div4_clks[DIV4_NR] = {
72 [DIV4_P] = DIV4("peripheral_clk", 0, 0x0f80, 0),
73 [DIV4_DU] = DIV4("du_clk", 4, 0x0ff0, 0),
74 [DIV4_GA] = DIV4("ga_clk", 8, 0x0030, 0),
75 [DIV4_DDR] = DIV4("ddr_clk", 12, 0x000c, CLK_ENABLE_ON_INIT),
76 [DIV4_B] = DIV4("bus_clk", 16, 0x0fe0, CLK_ENABLE_ON_INIT),
77 [DIV4_SH] = DIV4("shyway_clk", 20, 0x000c, CLK_ENABLE_ON_INIT),
78 [DIV4_U] = DIV4("umem_clk", 24, 0x000c, CLK_ENABLE_ON_INIT),
79 [DIV4_I] = DIV4("cpu_clk", 28, 0x000e, CLK_ENABLE_ON_INIT),
93}; 80};
94 81
95static void ddr_clk_recalc(struct clk *clk) 82#define MSTPCR0 0xffc80030
96{ 83#define MSTPCR1 0xffc80034
97 int idx = ((ctrl_inl(FRQMR1) >> 12) & 0x0003); 84
98 clk->rate = clk->parent->rate / mfc_divisors[idx]; 85static struct clk mstp_clks[] = {
99} 86 /* MSTPCR0 */
100 87 SH_CLK_MSTP32("scif_fck", 5, &div4_clks[DIV4_P], MSTPCR0, 29, 0),
101static struct clk_ops sh7785_ddr_clk_ops = { 88 SH_CLK_MSTP32("scif_fck", 4, &div4_clks[DIV4_P], MSTPCR0, 28, 0),
102 .recalc = ddr_clk_recalc, 89 SH_CLK_MSTP32("scif_fck", 3, &div4_clks[DIV4_P], MSTPCR0, 27, 0),
103}; 90 SH_CLK_MSTP32("scif_fck", 2, &div4_clks[DIV4_P], MSTPCR0, 26, 0),
104 91 SH_CLK_MSTP32("scif_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 25, 0),
105static struct clk sh7785_ddr_clk = { 92 SH_CLK_MSTP32("scif_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 24, 0),
106 .name = "ddr_clk", 93 SH_CLK_MSTP32("ssi_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 21, 0),
107 .flags = CLK_ALWAYS_ENABLED, 94 SH_CLK_MSTP32("ssi_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 20, 0),
108 .ops = &sh7785_ddr_clk_ops, 95 SH_CLK_MSTP32("hac_fck", 1, &div4_clks[DIV4_P], MSTPCR0, 17, 0),
109}; 96 SH_CLK_MSTP32("hac_fck", 0, &div4_clks[DIV4_P], MSTPCR0, 16, 0),
110 97 SH_CLK_MSTP32("mmcif_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 13, 0),
111static void ram_clk_recalc(struct clk *clk) 98 SH_CLK_MSTP32("flctl_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 12, 0),
112{ 99 SH_CLK_MSTP32("tmu345_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 9, 0),
113 int idx = ((ctrl_inl(FRQMR1) >> 24) & 0x0003); 100 SH_CLK_MSTP32("tmu012_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 8, 0),
114 clk->rate = clk->parent->rate / ufc_divisors[idx]; 101 SH_CLK_MSTP32("siof_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 3, 0),
115} 102 SH_CLK_MSTP32("hspi_fck", -1, &div4_clks[DIV4_P], MSTPCR0, 2, 0),
116 103
117static struct clk_ops sh7785_ram_clk_ops = { 104 /* MSTPCR1 */
118 .recalc = ram_clk_recalc, 105 SH_CLK_MSTP32("hudi_fck", -1, NULL, MSTPCR1, 19, 0),
106 SH_CLK_MSTP32("ubc_fck", -1, NULL, MSTPCR1, 17, 0),
107 SH_CLK_MSTP32("dmac_11_6_fck", -1, NULL, MSTPCR1, 5, 0),
108 SH_CLK_MSTP32("dmac_5_0_fck", -1, NULL, MSTPCR1, 4, 0),
109 SH_CLK_MSTP32("gdta_fck", -1, NULL, MSTPCR1, 0, 0),
119}; 110};
120 111
121static struct clk sh7785_ram_clk = { 112int __init arch_clk_init(void)
122 .name = "ram_clk",
123 .flags = CLK_ALWAYS_ENABLED,
124 .ops = &sh7785_ram_clk_ops,
125};
126
127/*
128 * Additional SH7785-specific on-chip clocks that aren't already part of the
129 * clock framework
130 */
131static struct clk *sh7785_onchip_clocks[] = {
132 &sh7785_shyway_clk,
133 &sh7785_ddr_clk,
134 &sh7785_ram_clk,
135};
136
137static int __init sh7785_clk_init(void)
138{ 113{
139 struct clk *clk = clk_get(NULL, "master_clk"); 114 int i, ret = 0;
140 int i;
141
142 for (i = 0; i < ARRAY_SIZE(sh7785_onchip_clocks); i++) {
143 struct clk *clkp = sh7785_onchip_clocks[i];
144
145 clkp->parent = clk;
146 clk_register(clkp);
147 clk_enable(clkp);
148 }
149 115
150 /* 116 for (i = 0; i < ARRAY_SIZE(clks); i++)
151 * Now that we have the rest of the clocks registered, we need to 117 ret |= clk_register(clks[i]);
152 * force the parent clock to propagate so that these clocks will
153 * automatically figure out their rate. We cheat by handing the
154 * parent clock its current rate and forcing child propagation.
155 */
156 clk_set_rate(clk, clk_get_rate(clk));
157 118
158 clk_put(clk); 119 if (!ret)
120 ret = sh_clk_div4_register(div4_clks, ARRAY_SIZE(div4_clks),
121 &div4_table);
122 if (!ret)
123 ret = sh_clk_mstp32_register(mstp_clks, ARRAY_SIZE(mstp_clks));
159 124
160 return 0; 125 return ret;
161} 126}
162arch_initcall(sh7785_clk_init);
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7786.c b/arch/sh/kernel/cpu/sh4a/clock-sh7786.c
index f84a9c134471..a0e8869071ac 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-sh7786.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7786.c
@@ -36,30 +36,30 @@ static struct clk_ops sh7786_master_clk_ops = {
36 .init = master_clk_init, 36 .init = master_clk_init,
37}; 37};
38 38
39static void module_clk_recalc(struct clk *clk) 39static unsigned long module_clk_recalc(struct clk *clk)
40{ 40{
41 int idx = (ctrl_inl(FRQMR1) & 0x000f); 41 int idx = (ctrl_inl(FRQMR1) & 0x000f);
42 clk->rate = clk->parent->rate / pfc_divisors[idx]; 42 return clk->parent->rate / pfc_divisors[idx];
43} 43}
44 44
45static struct clk_ops sh7786_module_clk_ops = { 45static struct clk_ops sh7786_module_clk_ops = {
46 .recalc = module_clk_recalc, 46 .recalc = module_clk_recalc,
47}; 47};
48 48
49static void bus_clk_recalc(struct clk *clk) 49static unsigned long bus_clk_recalc(struct clk *clk)
50{ 50{
51 int idx = ((ctrl_inl(FRQMR1) >> 16) & 0x000f); 51 int idx = ((ctrl_inl(FRQMR1) >> 16) & 0x000f);
52 clk->rate = clk->parent->rate / bfc_divisors[idx]; 52 return clk->parent->rate / bfc_divisors[idx];
53} 53}
54 54
55static struct clk_ops sh7786_bus_clk_ops = { 55static struct clk_ops sh7786_bus_clk_ops = {
56 .recalc = bus_clk_recalc, 56 .recalc = bus_clk_recalc,
57}; 57};
58 58
59static void cpu_clk_recalc(struct clk *clk) 59static unsigned long cpu_clk_recalc(struct clk *clk)
60{ 60{
61 int idx = ((ctrl_inl(FRQMR1) >> 28) & 0x0003); 61 int idx = ((ctrl_inl(FRQMR1) >> 28) & 0x0003);
62 clk->rate = clk->parent->rate / ifc_divisors[idx]; 62 return clk->parent->rate / ifc_divisors[idx];
63} 63}
64 64
65static struct clk_ops sh7786_cpu_clk_ops = { 65static struct clk_ops sh7786_cpu_clk_ops = {
@@ -79,10 +79,10 @@ void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
79 *ops = sh7786_clk_ops[idx]; 79 *ops = sh7786_clk_ops[idx];
80} 80}
81 81
82static void shyway_clk_recalc(struct clk *clk) 82static unsigned long shyway_clk_recalc(struct clk *clk)
83{ 83{
84 int idx = ((ctrl_inl(FRQMR1) >> 20) & 0x0003); 84 int idx = ((ctrl_inl(FRQMR1) >> 20) & 0x0003);
85 clk->rate = clk->parent->rate / sfc_divisors[idx]; 85 return clk->parent->rate / sfc_divisors[idx];
86} 86}
87 87
88static struct clk_ops sh7786_shyway_clk_ops = { 88static struct clk_ops sh7786_shyway_clk_ops = {
@@ -91,14 +91,14 @@ static struct clk_ops sh7786_shyway_clk_ops = {
91 91
92static struct clk sh7786_shyway_clk = { 92static struct clk sh7786_shyway_clk = {
93 .name = "shyway_clk", 93 .name = "shyway_clk",
94 .flags = CLK_ALWAYS_ENABLED, 94 .flags = CLK_ENABLE_ON_INIT,
95 .ops = &sh7786_shyway_clk_ops, 95 .ops = &sh7786_shyway_clk_ops,
96}; 96};
97 97
98static void ddr_clk_recalc(struct clk *clk) 98static unsigned long ddr_clk_recalc(struct clk *clk)
99{ 99{
100 int idx = ((ctrl_inl(FRQMR1) >> 12) & 0x0003); 100 int idx = ((ctrl_inl(FRQMR1) >> 12) & 0x0003);
101 clk->rate = clk->parent->rate / mfc_divisors[idx]; 101 return clk->parent->rate / mfc_divisors[idx];
102} 102}
103 103
104static struct clk_ops sh7786_ddr_clk_ops = { 104static struct clk_ops sh7786_ddr_clk_ops = {
@@ -107,7 +107,7 @@ static struct clk_ops sh7786_ddr_clk_ops = {
107 107
108static struct clk sh7786_ddr_clk = { 108static struct clk sh7786_ddr_clk = {
109 .name = "ddr_clk", 109 .name = "ddr_clk",
110 .flags = CLK_ALWAYS_ENABLED, 110 .flags = CLK_ENABLE_ON_INIT,
111 .ops = &sh7786_ddr_clk_ops, 111 .ops = &sh7786_ddr_clk_ops,
112}; 112};
113 113
@@ -120,29 +120,22 @@ static struct clk *sh7786_onchip_clocks[] = {
120 &sh7786_ddr_clk, 120 &sh7786_ddr_clk,
121}; 121};
122 122
123static int __init sh7786_clk_init(void) 123int __init arch_clk_init(void)
124{ 124{
125 struct clk *clk = clk_get(NULL, "master_clk"); 125 struct clk *clk;
126 int i; 126 int i, ret = 0;
127 127
128 cpg_clk_init();
129
130 clk = clk_get(NULL, "master_clk");
128 for (i = 0; i < ARRAY_SIZE(sh7786_onchip_clocks); i++) { 131 for (i = 0; i < ARRAY_SIZE(sh7786_onchip_clocks); i++) {
129 struct clk *clkp = sh7786_onchip_clocks[i]; 132 struct clk *clkp = sh7786_onchip_clocks[i];
130 133
131 clkp->parent = clk; 134 clkp->parent = clk;
132 clk_register(clkp); 135 ret |= clk_register(clkp);
133 clk_enable(clkp);
134 } 136 }
135 137
136 /*
137 * Now that we have the rest of the clocks registered, we need to
138 * force the parent clock to propagate so that these clocks will
139 * automatically figure out their rate. We cheat by handing the
140 * parent clock its current rate and forcing child propagation.
141 */
142 clk_set_rate(clk, clk_get_rate(clk));
143
144 clk_put(clk); 138 clk_put(clk);
145 139
146 return 0; 140 return ret;
147} 141}
148arch_initcall(sh7786_clk_init);
diff --git a/arch/sh/kernel/cpu/sh4a/clock-shx3.c b/arch/sh/kernel/cpu/sh4a/clock-shx3.c
index c630b29e06a8..23c27d32d982 100644
--- a/arch/sh/kernel/cpu/sh4a/clock-shx3.c
+++ b/arch/sh/kernel/cpu/sh4a/clock-shx3.c
@@ -40,30 +40,30 @@ static struct clk_ops shx3_master_clk_ops = {
40 .init = master_clk_init, 40 .init = master_clk_init,
41}; 41};
42 42
43static void module_clk_recalc(struct clk *clk) 43static unsigned long module_clk_recalc(struct clk *clk)
44{ 44{
45 int idx = ((ctrl_inl(FRQCR) >> PFC_POS) & PFC_MSK); 45 int idx = ((ctrl_inl(FRQCR) >> PFC_POS) & PFC_MSK);
46 clk->rate = clk->parent->rate / pfc_divisors[idx]; 46 return clk->parent->rate / pfc_divisors[idx];
47} 47}
48 48
49static struct clk_ops shx3_module_clk_ops = { 49static struct clk_ops shx3_module_clk_ops = {
50 .recalc = module_clk_recalc, 50 .recalc = module_clk_recalc,
51}; 51};
52 52
53static void bus_clk_recalc(struct clk *clk) 53static unsigned long bus_clk_recalc(struct clk *clk)
54{ 54{
55 int idx = ((ctrl_inl(FRQCR) >> BFC_POS) & BFC_MSK); 55 int idx = ((ctrl_inl(FRQCR) >> BFC_POS) & BFC_MSK);
56 clk->rate = clk->parent->rate / bfc_divisors[idx]; 56 return clk->parent->rate / bfc_divisors[idx];
57} 57}
58 58
59static struct clk_ops shx3_bus_clk_ops = { 59static struct clk_ops shx3_bus_clk_ops = {
60 .recalc = bus_clk_recalc, 60 .recalc = bus_clk_recalc,
61}; 61};
62 62
63static void cpu_clk_recalc(struct clk *clk) 63static unsigned long cpu_clk_recalc(struct clk *clk)
64{ 64{
65 int idx = ((ctrl_inl(FRQCR) >> IFC_POS) & IFC_MSK); 65 int idx = ((ctrl_inl(FRQCR) >> IFC_POS) & IFC_MSK);
66 clk->rate = clk->parent->rate / ifc_divisors[idx]; 66 return clk->parent->rate / ifc_divisors[idx];
67} 67}
68 68
69static struct clk_ops shx3_cpu_clk_ops = { 69static struct clk_ops shx3_cpu_clk_ops = {
@@ -83,10 +83,10 @@ void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
83 *ops = shx3_clk_ops[idx]; 83 *ops = shx3_clk_ops[idx];
84} 84}
85 85
86static void shyway_clk_recalc(struct clk *clk) 86static unsigned long shyway_clk_recalc(struct clk *clk)
87{ 87{
88 int idx = ((ctrl_inl(FRQCR) >> CFC_POS) & CFC_MSK); 88 int idx = ((ctrl_inl(FRQCR) >> CFC_POS) & CFC_MSK);
89 clk->rate = clk->parent->rate / cfc_divisors[idx]; 89 return clk->parent->rate / cfc_divisors[idx];
90} 90}
91 91
92static struct clk_ops shx3_shyway_clk_ops = { 92static struct clk_ops shx3_shyway_clk_ops = {
@@ -95,7 +95,7 @@ static struct clk_ops shx3_shyway_clk_ops = {
95 95
96static struct clk shx3_shyway_clk = { 96static struct clk shx3_shyway_clk = {
97 .name = "shyway_clk", 97 .name = "shyway_clk",
98 .flags = CLK_ALWAYS_ENABLED, 98 .flags = CLK_ENABLE_ON_INIT,
99 .ops = &shx3_shyway_clk_ops, 99 .ops = &shx3_shyway_clk_ops,
100}; 100};
101 101
@@ -107,29 +107,22 @@ static struct clk *shx3_onchip_clocks[] = {
107 &shx3_shyway_clk, 107 &shx3_shyway_clk,
108}; 108};
109 109
110static int __init shx3_clk_init(void) 110int __init arch_clk_init(void)
111{ 111{
112 struct clk *clk = clk_get(NULL, "master_clk"); 112 struct clk *clk;
113 int i; 113 int i, ret = 0;
114 114
115 cpg_clk_init();
116
117 clk = clk_get(NULL, "master_clk");
115 for (i = 0; i < ARRAY_SIZE(shx3_onchip_clocks); i++) { 118 for (i = 0; i < ARRAY_SIZE(shx3_onchip_clocks); i++) {
116 struct clk *clkp = shx3_onchip_clocks[i]; 119 struct clk *clkp = shx3_onchip_clocks[i];
117 120
118 clkp->parent = clk; 121 clkp->parent = clk;
119 clk_register(clkp); 122 ret |= clk_register(clkp);
120 clk_enable(clkp);
121 } 123 }
122 124
123 /*
124 * Now that we have the rest of the clocks registered, we need to
125 * force the parent clock to propagate so that these clocks will
126 * automatically figure out their rate. We cheat by handing the
127 * parent clock its current rate and forcing child propagation.
128 */
129 clk_set_rate(clk, clk_get_rate(clk));
130
131 clk_put(clk); 125 clk_put(clk);
132 126
133 return 0; 127 return ret;
134} 128}
135arch_initcall(shx3_clk_init);
diff --git a/arch/sh/kernel/cpu/sh4a/pinmux-sh7724.c b/arch/sh/kernel/cpu/sh4a/pinmux-sh7724.c
new file mode 100644
index 000000000000..1af0f9586379
--- /dev/null
+++ b/arch/sh/kernel/cpu/sh4a/pinmux-sh7724.c
@@ -0,0 +1,2230 @@
1/*
2 * SH7724 Pinmux
3 *
4 * Copyright (C) 2009 Renesas Solutions Corp.
5 *
6 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
7 *
8 * Based on SH7723 Pinmux
9 * Copyright (C) 2008 Magnus Damm
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
13 * for more details.
14 */
15
16#include <linux/init.h>
17#include <linux/kernel.h>
18#include <linux/gpio.h>
19#include <cpu/sh7724.h>
20
21enum {
22 PINMUX_RESERVED = 0,
23
24 PINMUX_DATA_BEGIN,
25 PTA7_DATA, PTA6_DATA, PTA5_DATA, PTA4_DATA,
26 PTA3_DATA, PTA2_DATA, PTA1_DATA, PTA0_DATA,
27 PTB7_DATA, PTB6_DATA, PTB5_DATA, PTB4_DATA,
28 PTB3_DATA, PTB2_DATA, PTB1_DATA, PTB0_DATA,
29 PTC7_DATA, PTC6_DATA, PTC5_DATA, PTC4_DATA,
30 PTC3_DATA, PTC2_DATA, PTC1_DATA, PTC0_DATA,
31 PTD7_DATA, PTD6_DATA, PTD5_DATA, PTD4_DATA,
32 PTD3_DATA, PTD2_DATA, PTD1_DATA, PTD0_DATA,
33 PTE7_DATA, PTE6_DATA, PTE5_DATA, PTE4_DATA,
34 PTE3_DATA, PTE2_DATA, PTE1_DATA, PTE0_DATA,
35 PTF7_DATA, PTF6_DATA, PTF5_DATA, PTF4_DATA,
36 PTF3_DATA, PTF2_DATA, PTF1_DATA, PTF0_DATA,
37 PTG5_DATA, PTG4_DATA,
38 PTG3_DATA, PTG2_DATA, PTG1_DATA, PTG0_DATA,
39 PTH7_DATA, PTH6_DATA, PTH5_DATA, PTH4_DATA,
40 PTH3_DATA, PTH2_DATA, PTH1_DATA, PTH0_DATA,
41 PTJ7_DATA, PTJ6_DATA, PTJ5_DATA,
42 PTJ3_DATA, PTJ2_DATA, PTJ1_DATA, PTJ0_DATA,
43 PTK7_DATA, PTK6_DATA, PTK5_DATA, PTK4_DATA,
44 PTK3_DATA, PTK2_DATA, PTK1_DATA, PTK0_DATA,
45 PTL7_DATA, PTL6_DATA, PTL5_DATA, PTL4_DATA,
46 PTL3_DATA, PTL2_DATA, PTL1_DATA, PTL0_DATA,
47 PTM7_DATA, PTM6_DATA, PTM5_DATA, PTM4_DATA,
48 PTM3_DATA, PTM2_DATA, PTM1_DATA, PTM0_DATA,
49 PTN7_DATA, PTN6_DATA, PTN5_DATA, PTN4_DATA,
50 PTN3_DATA, PTN2_DATA, PTN1_DATA, PTN0_DATA,
51 PTQ7_DATA, PTQ6_DATA, PTQ5_DATA, PTQ4_DATA,
52 PTQ3_DATA, PTQ2_DATA, PTQ1_DATA, PTQ0_DATA,
53 PTR7_DATA, PTR6_DATA, PTR5_DATA, PTR4_DATA,
54 PTR3_DATA, PTR2_DATA, PTR1_DATA, PTR0_DATA,
55 PTS6_DATA, PTS5_DATA, PTS4_DATA,
56 PTS3_DATA, PTS2_DATA, PTS1_DATA, PTS0_DATA,
57 PTT7_DATA, PTT6_DATA, PTT5_DATA, PTT4_DATA,
58 PTT3_DATA, PTT2_DATA, PTT1_DATA, PTT0_DATA,
59 PTU7_DATA, PTU6_DATA, PTU5_DATA, PTU4_DATA,
60 PTU3_DATA, PTU2_DATA, PTU1_DATA, PTU0_DATA,
61 PTV7_DATA, PTV6_DATA, PTV5_DATA, PTV4_DATA,
62 PTV3_DATA, PTV2_DATA, PTV1_DATA, PTV0_DATA,
63 PTW7_DATA, PTW6_DATA, PTW5_DATA, PTW4_DATA,
64 PTW3_DATA, PTW2_DATA, PTW1_DATA, PTW0_DATA,
65 PTX7_DATA, PTX6_DATA, PTX5_DATA, PTX4_DATA,
66 PTX3_DATA, PTX2_DATA, PTX1_DATA, PTX0_DATA,
67 PTY7_DATA, PTY6_DATA, PTY5_DATA, PTY4_DATA,
68 PTY3_DATA, PTY2_DATA, PTY1_DATA, PTY0_DATA,
69 PTZ7_DATA, PTZ6_DATA, PTZ5_DATA, PTZ4_DATA,
70 PTZ3_DATA, PTZ2_DATA, PTZ1_DATA, PTZ0_DATA,
71 PINMUX_DATA_END,
72
73 PINMUX_INPUT_BEGIN,
74 PTA7_IN, PTA6_IN, PTA5_IN, PTA4_IN,
75 PTA3_IN, PTA2_IN, PTA1_IN, PTA0_IN,
76 PTB7_IN, PTB6_IN, PTB5_IN, PTB4_IN,
77 PTB3_IN, PTB2_IN, PTB1_IN, PTB0_IN,
78 PTC7_IN, PTC6_IN, PTC5_IN, PTC4_IN,
79 PTC3_IN, PTC2_IN, PTC1_IN, PTC0_IN,
80 PTD7_IN, PTD6_IN, PTD5_IN, PTD4_IN,
81 PTD3_IN, PTD2_IN, PTD1_IN, PTD0_IN,
82 PTE7_IN, PTE6_IN, PTE5_IN, PTE4_IN,
83 PTE3_IN, PTE2_IN, PTE1_IN, PTE0_IN,
84 PTF7_IN, PTF6_IN, PTF5_IN, PTF4_IN,
85 PTF3_IN, PTF2_IN, PTF1_IN, PTF0_IN,
86 PTH7_IN, PTH6_IN, PTH5_IN, PTH4_IN,
87 PTH3_IN, PTH2_IN, PTH1_IN, PTH0_IN,
88 PTJ3_IN, PTJ2_IN, PTJ1_IN, PTJ0_IN,
89 PTK7_IN, PTK6_IN, PTK5_IN, PTK4_IN,
90 PTK3_IN, PTK2_IN, PTK1_IN, PTK0_IN,
91 PTL7_IN, PTL6_IN, PTL5_IN, PTL4_IN,
92 PTL3_IN, PTL2_IN, PTL1_IN, PTL0_IN,
93 PTM7_IN, PTM6_IN, PTM5_IN, PTM4_IN,
94 PTM3_IN, PTM2_IN, PTM1_IN, PTM0_IN,
95 PTN7_IN, PTN6_IN, PTN5_IN, PTN4_IN,
96 PTN3_IN, PTN2_IN, PTN1_IN, PTN0_IN,
97 PTQ7_IN, PTQ6_IN, PTQ5_IN, PTQ4_IN,
98 PTQ3_IN, PTQ2_IN, PTQ1_IN, PTQ0_IN,
99 PTR7_IN, PTR6_IN, PTR5_IN, PTR4_IN,
100 PTR3_IN, PTR2_IN, PTR1_IN, PTR0_IN,
101 PTS6_IN, PTS5_IN, PTS4_IN,
102 PTS3_IN, PTS2_IN, PTS1_IN, PTS0_IN,
103 PTT7_IN, PTT6_IN, PTT5_IN, PTT4_IN,
104 PTT3_IN, PTT2_IN, PTT1_IN, PTT0_IN,
105 PTU7_IN, PTU6_IN, PTU5_IN, PTU4_IN,
106 PTU3_IN, PTU2_IN, PTU1_IN, PTU0_IN,
107 PTV7_IN, PTV6_IN, PTV5_IN, PTV4_IN,
108 PTV3_IN, PTV2_IN, PTV1_IN, PTV0_IN,
109 PTW7_IN, PTW6_IN, PTW5_IN, PTW4_IN,
110 PTW3_IN, PTW2_IN, PTW1_IN, PTW0_IN,
111 PTX7_IN, PTX6_IN, PTX5_IN, PTX4_IN,
112 PTX3_IN, PTX2_IN, PTX1_IN, PTX0_IN,
113 PTY7_IN, PTY6_IN, PTY5_IN, PTY4_IN,
114 PTY3_IN, PTY2_IN, PTY1_IN, PTY0_IN,
115 PTZ7_IN, PTZ6_IN, PTZ5_IN, PTZ4_IN,
116 PTZ3_IN, PTZ2_IN, PTZ1_IN, PTZ0_IN,
117 PINMUX_INPUT_END,
118
119 PINMUX_INPUT_PULLUP_BEGIN,
120 PTA7_IN_PU, PTA6_IN_PU, PTA5_IN_PU, PTA4_IN_PU,
121 PTA3_IN_PU, PTA2_IN_PU, PTA1_IN_PU, PTA0_IN_PU,
122 PTB7_IN_PU, PTB6_IN_PU, PTB5_IN_PU, PTB4_IN_PU,
123 PTB3_IN_PU, PTB2_IN_PU, PTB1_IN_PU, PTB0_IN_PU,
124 PTC7_IN_PU, PTC6_IN_PU, PTC5_IN_PU, PTC4_IN_PU,
125 PTC3_IN_PU, PTC2_IN_PU, PTC1_IN_PU, PTC0_IN_PU,
126 PTD7_IN_PU, PTD6_IN_PU, PTD5_IN_PU, PTD4_IN_PU,
127 PTD3_IN_PU, PTD2_IN_PU, PTD1_IN_PU, PTD0_IN_PU,
128 PTE7_IN_PU, PTE6_IN_PU, PTE5_IN_PU, PTE4_IN_PU,
129 PTE3_IN_PU, PTE2_IN_PU, PTE1_IN_PU, PTE0_IN_PU,
130 PTF7_IN_PU, PTF6_IN_PU, PTF5_IN_PU, PTF4_IN_PU,
131 PTF3_IN_PU, PTF2_IN_PU, PTF1_IN_PU, PTF0_IN_PU,
132 PTH7_IN_PU, PTH6_IN_PU, PTH5_IN_PU, PTH4_IN_PU,
133 PTH3_IN_PU, PTH2_IN_PU, PTH1_IN_PU, PTH0_IN_PU,
134 PTJ3_IN_PU, PTJ2_IN_PU, PTJ1_IN_PU, PTJ0_IN_PU,
135 PTK7_IN_PU, PTK6_IN_PU, PTK5_IN_PU, PTK4_IN_PU,
136 PTK3_IN_PU, PTK2_IN_PU, PTK1_IN_PU, PTK0_IN_PU,
137 PTL7_IN_PU, PTL6_IN_PU, PTL5_IN_PU, PTL4_IN_PU,
138 PTL3_IN_PU, PTL2_IN_PU, PTL1_IN_PU, PTL0_IN_PU,
139 PTM7_IN_PU, PTM6_IN_PU, PTM5_IN_PU, PTM4_IN_PU,
140 PTM3_IN_PU, PTM2_IN_PU, PTM1_IN_PU, PTM0_IN_PU,
141 PTN7_IN_PU, PTN6_IN_PU, PTN5_IN_PU, PTN4_IN_PU,
142 PTN3_IN_PU, PTN2_IN_PU, PTN1_IN_PU, PTN0_IN_PU,
143 PTQ7_IN_PU, PTQ6_IN_PU, PTQ5_IN_PU, PTQ4_IN_PU,
144 PTQ3_IN_PU, PTQ2_IN_PU, PTQ1_IN_PU, PTQ0_IN_PU,
145 PTR7_IN_PU, PTR6_IN_PU, PTR5_IN_PU, PTR4_IN_PU,
146 PTR3_IN_PU, PTR2_IN_PU, PTR1_IN_PU, PTR0_IN_PU,
147 PTS6_IN_PU, PTS5_IN_PU, PTS4_IN_PU,
148 PTS3_IN_PU, PTS2_IN_PU, PTS1_IN_PU, PTS0_IN_PU,
149 PTT7_IN_PU, PTT6_IN_PU, PTT5_IN_PU, PTT4_IN_PU,
150 PTT3_IN_PU, PTT2_IN_PU, PTT1_IN_PU, PTT0_IN_PU,
151 PTU7_IN_PU, PTU6_IN_PU, PTU5_IN_PU, PTU4_IN_PU,
152 PTU3_IN_PU, PTU2_IN_PU, PTU1_IN_PU, PTU0_IN_PU,
153 PTV7_IN_PU, PTV6_IN_PU, PTV5_IN_PU, PTV4_IN_PU,
154 PTV3_IN_PU, PTV2_IN_PU, PTV1_IN_PU, PTV0_IN_PU,
155 PTW7_IN_PU, PTW6_IN_PU, PTW5_IN_PU, PTW4_IN_PU,
156 PTW3_IN_PU, PTW2_IN_PU, PTW1_IN_PU, PTW0_IN_PU,
157 PTX7_IN_PU, PTX6_IN_PU, PTX5_IN_PU, PTX4_IN_PU,
158 PTX3_IN_PU, PTX2_IN_PU, PTX1_IN_PU, PTX0_IN_PU,
159 PTY7_IN_PU, PTY6_IN_PU, PTY5_IN_PU, PTY4_IN_PU,
160 PTY3_IN_PU, PTY2_IN_PU, PTY1_IN_PU, PTY0_IN_PU,
161 PTZ7_IN_PU, PTZ6_IN_PU, PTZ5_IN_PU, PTZ4_IN_PU,
162 PTZ3_IN_PU, PTZ2_IN_PU, PTZ1_IN_PU, PTZ0_IN_PU,
163 PINMUX_INPUT_PULLUP_END,
164
165 PINMUX_OUTPUT_BEGIN,
166 PTA7_OUT, PTA6_OUT, PTA5_OUT, PTA4_OUT,
167 PTA3_OUT, PTA2_OUT, PTA1_OUT, PTA0_OUT,
168 PTB7_OUT, PTB6_OUT, PTB5_OUT, PTB4_OUT,
169 PTB3_OUT, PTB2_OUT, PTB1_OUT, PTB0_OUT,
170 PTC7_OUT, PTC6_OUT, PTC5_OUT, PTC4_OUT,
171 PTC3_OUT, PTC2_OUT, PTC1_OUT, PTC0_OUT,
172 PTD7_OUT, PTD6_OUT, PTD5_OUT, PTD4_OUT,
173 PTD3_OUT, PTD2_OUT, PTD1_OUT, PTD0_OUT,
174 PTE7_OUT, PTE6_OUT, PTE5_OUT, PTE4_OUT,
175 PTE3_OUT, PTE2_OUT, PTE1_OUT, PTE0_OUT,
176 PTF7_OUT, PTF6_OUT, PTF5_OUT, PTF4_OUT,
177 PTF3_OUT, PTF2_OUT, PTF1_OUT, PTF0_OUT,
178 PTG5_OUT, PTG4_OUT,
179 PTG3_OUT, PTG2_OUT, PTG1_OUT, PTG0_OUT,
180 PTH7_OUT, PTH6_OUT, PTH5_OUT, PTH4_OUT,
181 PTH3_OUT, PTH2_OUT, PTH1_OUT, PTH0_OUT,
182 PTJ7_OUT, PTJ6_OUT, PTJ5_OUT,
183 PTJ3_OUT, PTJ2_OUT, PTJ1_OUT, PTJ0_OUT,
184 PTK7_OUT, PTK6_OUT, PTK5_OUT, PTK4_OUT,
185 PTK3_OUT, PTK2_OUT, PTK1_OUT, PTK0_OUT,
186 PTL7_OUT, PTL6_OUT, PTL5_OUT, PTL4_OUT,
187 PTL3_OUT, PTL2_OUT, PTL1_OUT, PTL0_OUT,
188 PTM7_OUT, PTM6_OUT, PTM5_OUT, PTM4_OUT,
189 PTM3_OUT, PTM2_OUT, PTM1_OUT, PTM0_OUT,
190 PTN7_OUT, PTN6_OUT, PTN5_OUT, PTN4_OUT,
191 PTN3_OUT, PTN2_OUT, PTN1_OUT, PTN0_OUT,
192 PTQ7_OUT, PTQ6_OUT, PTQ5_OUT, PTQ4_OUT,
193 PTQ3_OUT, PTQ2_OUT, PTQ1_OUT, PTQ0_OUT,
194 PTR7_OUT, PTR6_OUT, PTR5_OUT, PTR4_OUT,
195 PTR1_OUT, PTR0_OUT,
196 PTS6_OUT, PTS5_OUT, PTS4_OUT,
197 PTS3_OUT, PTS2_OUT, PTS1_OUT, PTS0_OUT,
198 PTT7_OUT, PTT6_OUT, PTT5_OUT, PTT4_OUT,
199 PTT3_OUT, PTT2_OUT, PTT1_OUT, PTT0_OUT,
200 PTU7_OUT, PTU6_OUT, PTU5_OUT, PTU4_OUT,
201 PTU3_OUT, PTU2_OUT, PTU1_OUT, PTU0_OUT,
202 PTV7_OUT, PTV6_OUT, PTV5_OUT, PTV4_OUT,
203 PTV3_OUT, PTV2_OUT, PTV1_OUT, PTV0_OUT,
204 PTW7_OUT, PTW6_OUT, PTW5_OUT, PTW4_OUT,
205 PTW3_OUT, PTW2_OUT, PTW1_OUT, PTW0_OUT,
206 PTX7_OUT, PTX6_OUT, PTX5_OUT, PTX4_OUT,
207 PTX3_OUT, PTX2_OUT, PTX1_OUT, PTX0_OUT,
208 PTY7_OUT, PTY6_OUT, PTY5_OUT, PTY4_OUT,
209 PTY3_OUT, PTY2_OUT, PTY1_OUT, PTY0_OUT,
210 PTZ7_OUT, PTZ6_OUT, PTZ5_OUT, PTZ4_OUT,
211 PTZ3_OUT, PTZ2_OUT, PTZ1_OUT, PTZ0_OUT,
212 PINMUX_OUTPUT_END,
213
214 PINMUX_FUNCTION_BEGIN,
215 PTA7_FN, PTA6_FN, PTA5_FN, PTA4_FN,
216 PTA3_FN, PTA2_FN, PTA1_FN, PTA0_FN,
217 PTB7_FN, PTB6_FN, PTB5_FN, PTB4_FN,
218 PTB3_FN, PTB2_FN, PTB1_FN, PTB0_FN,
219 PTC7_FN, PTC6_FN, PTC5_FN, PTC4_FN,
220 PTC3_FN, PTC2_FN, PTC1_FN, PTC0_FN,
221 PTD7_FN, PTD6_FN, PTD5_FN, PTD4_FN,
222 PTD3_FN, PTD2_FN, PTD1_FN, PTD0_FN,
223 PTE7_FN, PTE6_FN, PTE5_FN, PTE4_FN,
224 PTE3_FN, PTE2_FN, PTE1_FN, PTE0_FN,
225 PTF7_FN, PTF6_FN, PTF5_FN, PTF4_FN,
226 PTF3_FN, PTF2_FN, PTF1_FN, PTF0_FN,
227 PTG5_FN, PTG4_FN,
228 PTG3_FN, PTG2_FN, PTG1_FN, PTG0_FN,
229 PTH7_FN, PTH6_FN, PTH5_FN, PTH4_FN,
230 PTH3_FN, PTH2_FN, PTH1_FN, PTH0_FN,
231 PTJ7_FN, PTJ6_FN, PTJ5_FN,
232 PTJ3_FN, PTJ2_FN, PTJ1_FN, PTJ0_FN,
233 PTK7_FN, PTK6_FN, PTK5_FN, PTK4_FN,
234 PTK3_FN, PTK2_FN, PTK1_FN, PTK0_FN,
235 PTL7_FN, PTL6_FN, PTL5_FN, PTL4_FN,
236 PTL3_FN, PTL2_FN, PTL1_FN, PTL0_FN,
237 PTM7_FN, PTM6_FN, PTM5_FN, PTM4_FN,
238 PTM3_FN, PTM2_FN, PTM1_FN, PTM0_FN,
239 PTN7_FN, PTN6_FN, PTN5_FN, PTN4_FN,
240 PTN3_FN, PTN2_FN, PTN1_FN, PTN0_FN,
241 PTQ7_FN, PTQ6_FN, PTQ5_FN, PTQ4_FN,
242 PTQ3_FN, PTQ2_FN, PTQ1_FN, PTQ0_FN,
243 PTR7_FN, PTR6_FN, PTR5_FN, PTR4_FN,
244 PTR3_FN, PTR2_FN, PTR1_FN, PTR0_FN,
245 PTS6_FN, PTS5_FN, PTS4_FN,
246 PTS3_FN, PTS2_FN, PTS1_FN, PTS0_FN,
247 PTT7_FN, PTT6_FN, PTT5_FN, PTT4_FN,
248 PTT3_FN, PTT2_FN, PTT1_FN, PTT0_FN,
249 PTU7_FN, PTU6_FN, PTU5_FN, PTU4_FN,
250 PTU3_FN, PTU2_FN, PTU1_FN, PTU0_FN,
251 PTV7_FN, PTV6_FN, PTV5_FN, PTV4_FN,
252 PTV3_FN, PTV2_FN, PTV1_FN, PTV0_FN,
253 PTW7_FN, PTW6_FN, PTW5_FN, PTW4_FN,
254 PTW3_FN, PTW2_FN, PTW1_FN, PTW0_FN,
255 PTX7_FN, PTX6_FN, PTX5_FN, PTX4_FN,
256 PTX3_FN, PTX2_FN, PTX1_FN, PTX0_FN,
257 PTY7_FN, PTY6_FN, PTY5_FN, PTY4_FN,
258 PTY3_FN, PTY2_FN, PTY1_FN, PTY0_FN,
259 PTZ7_FN, PTZ6_FN, PTZ5_FN, PTZ4_FN,
260 PTZ3_FN, PTZ2_FN, PTZ1_FN, PTZ0_FN,
261
262
263 PSA15_0, PSA15_1,
264 PSA14_0, PSA14_1,
265 PSA13_0, PSA13_1,
266 PSA12_0, PSA12_1,
267 PSA10_0, PSA10_1,
268 PSA9_0, PSA9_1,
269 PSA8_0, PSA8_1,
270 PSA7_0, PSA7_1,
271 PSA6_0, PSA6_1,
272 PSA5_0, PSA5_1,
273 PSA3_0, PSA3_1,
274 PSA2_0, PSA2_1,
275 PSA1_0, PSA1_1,
276 PSA0_0, PSA0_1,
277
278 PSB14_0, PSB14_1,
279 PSB13_0, PSB13_1,
280 PSB12_0, PSB12_1,
281 PSB11_0, PSB11_1,
282 PSB10_0, PSB10_1,
283 PSB9_0, PSB9_1,
284 PSB8_0, PSB8_1,
285 PSB7_0, PSB7_1,
286 PSB6_0, PSB6_1,
287 PSB5_0, PSB5_1,
288 PSB4_0, PSB4_1,
289 PSB3_0, PSB3_1,
290 PSB2_0, PSB2_1,
291 PSB1_0, PSB1_1,
292 PSB0_0, PSB0_1,
293
294 PSC15_0, PSC15_1,
295 PSC14_0, PSC14_1,
296 PSC13_0, PSC13_1,
297 PSC12_0, PSC12_1,
298 PSC11_0, PSC11_1,
299 PSC10_0, PSC10_1,
300 PSC9_0, PSC9_1,
301 PSC8_0, PSC8_1,
302 PSC7_0, PSC7_1,
303 PSC6_0, PSC6_1,
304 PSC5_0, PSC5_1,
305 PSC4_0, PSC4_1,
306 PSC2_0, PSC2_1,
307 PSC1_0, PSC1_1,
308 PSC0_0, PSC0_1,
309
310 PSD15_0, PSD15_1,
311 PSD14_0, PSD14_1,
312 PSD13_0, PSD13_1,
313 PSD12_0, PSD12_1,
314 PSD11_0, PSD11_1,
315 PSD10_0, PSD10_1,
316 PSD9_0, PSD9_1,
317 PSD8_0, PSD8_1,
318 PSD7_0, PSD7_1,
319 PSD6_0, PSD6_1,
320 PSD5_0, PSD5_1,
321 PSD4_0, PSD4_1,
322 PSD3_0, PSD3_1,
323 PSD2_0, PSD2_1,
324 PSD1_0, PSD1_1,
325 PSD0_0, PSD0_1,
326
327 PSE15_0, PSE15_1,
328 PSE14_0, PSE14_1,
329 PSE13_0, PSE13_1,
330 PSE12_0, PSE12_1,
331 PSE11_0, PSE11_1,
332 PSE10_0, PSE10_1,
333 PSE9_0, PSE9_1,
334 PSE8_0, PSE8_1,
335 PSE7_0, PSE7_1,
336 PSE6_0, PSE6_1,
337 PSE5_0, PSE5_1,
338 PSE4_0, PSE4_1,
339 PSE3_0, PSE3_1,
340 PSE2_0, PSE2_1,
341 PSE1_0, PSE1_1,
342 PSE0_0, PSE0_1,
343 PINMUX_FUNCTION_END,
344
345 PINMUX_MARK_BEGIN,
346 /*PTA*/
347 D23_MARK, KEYOUT2_MARK, IDED15_MARK,
348 D22_MARK, KEYOUT1_MARK, IDED14_MARK,
349 D21_MARK, KEYOUT0_MARK, IDED13_MARK,
350 D20_MARK, KEYIN4_MARK, IDED12_MARK,
351 D19_MARK, KEYIN3_MARK, IDED11_MARK,
352 D18_MARK, KEYIN2_MARK, IDED10_MARK,
353 D17_MARK, KEYIN1_MARK, IDED9_MARK,
354 D16_MARK, KEYIN0_MARK, IDED8_MARK,
355
356 /*PTB*/
357 D31_MARK, TPUTO1_MARK, IDEA1_MARK,
358 D30_MARK, TPUTO0_MARK, IDEA0_MARK,
359 D29_MARK, IODREQ_MARK,
360 D28_MARK, IDECS0_MARK,
361 D27_MARK, IDECS1_MARK,
362 D26_MARK, KEYOUT5_IN5_MARK, IDEIORD_MARK,
363 D25_MARK, KEYOUT4_IN6_MARK, IDEIOWR_MARK,
364 D24_MARK, KEYOUT3_MARK, IDEINT_MARK,
365
366 /*PTC*/
367 LCDD7_MARK,
368 LCDD6_MARK,
369 LCDD5_MARK,
370 LCDD4_MARK,
371 LCDD3_MARK,
372 LCDD2_MARK,
373 LCDD1_MARK,
374 LCDD0_MARK,
375
376 /*PTD*/
377 LCDD15_MARK,
378 LCDD14_MARK,
379 LCDD13_MARK,
380 LCDD12_MARK,
381 LCDD11_MARK,
382 LCDD10_MARK,
383 LCDD9_MARK,
384 LCDD8_MARK,
385
386 /*PTE*/
387 FSIMCKB_MARK,
388 FSIMCKA_MARK,
389 LCDD21_MARK, SCIF2_L_TXD_MARK,
390 LCDD20_MARK, SCIF4_SCK_MARK,
391 LCDD19_MARK, SCIF4_RXD_MARK,
392 LCDD18_MARK, SCIF4_TXD_MARK,
393 LCDD17_MARK,
394 LCDD16_MARK,
395
396 /*PTF*/
397 LCDVSYN_MARK,
398 LCDDISP_MARK, LCDRS_MARK,
399 LCDHSYN_MARK, LCDCS_MARK,
400 LCDDON_MARK,
401 LCDDCK_MARK, LCDWR_MARK,
402 LCDVEPWC_MARK, SCIF0_TXD_MARK,
403 LCDD23_MARK, SCIF2_L_SCK_MARK,
404 LCDD22_MARK, SCIF2_L_RXD_MARK,
405
406 /*PTG*/
407 AUDCK_MARK,
408 AUDSYNC_MARK,
409 AUDATA3_MARK,
410 AUDATA2_MARK,
411 AUDATA1_MARK,
412 AUDATA0_MARK,
413
414 /*PTH*/
415 VIO0_VD_MARK,
416 VIO0_CLK_MARK,
417 VIO0_D7_MARK,
418 VIO0_D6_MARK,
419 VIO0_D5_MARK,
420 VIO0_D4_MARK,
421 VIO0_D3_MARK,
422 VIO0_D2_MARK,
423
424 /*PTJ*/
425 PDSTATUS_MARK,
426 STATUS2_MARK,
427 STATUS0_MARK,
428 A25_MARK, BS_MARK,
429 A24_MARK,
430 A23_MARK,
431 A22_MARK,
432
433 /*PTK*/
434 VIO1_D5_MARK, VIO0_D13_MARK, IDED5_MARK,
435 VIO1_D4_MARK, VIO0_D12_MARK, IDED4_MARK,
436 VIO1_D3_MARK, VIO0_D11_MARK, IDED3_MARK,
437 VIO1_D2_MARK, VIO0_D10_MARK, IDED2_MARK,
438 VIO1_D1_MARK, VIO0_D9_MARK, IDED1_MARK,
439 VIO1_D0_MARK, VIO0_D8_MARK, IDED0_MARK,
440 VIO0_FLD_MARK,
441 VIO0_HD_MARK,
442
443 /*PTL*/
444 DV_D5_MARK, SCIF3_V_SCK_MARK, RMII_RXD0_MARK,
445 DV_D4_MARK, SCIF3_V_RXD_MARK, RMII_RXD1_MARK,
446 DV_D3_MARK, SCIF3_V_TXD_MARK, RMII_REF_CLK_MARK,
447 DV_D2_MARK, SCIF1_SCK_MARK, RMII_TX_EN_MARK,
448 DV_D1_MARK, SCIF1_RXD_MARK, RMII_TXD0_MARK,
449 DV_D0_MARK, SCIF1_TXD_MARK, RMII_TXD1_MARK,
450 DV_D15_MARK,
451 DV_D14_MARK, MSIOF0_MCK_MARK,
452
453 /*PTM*/
454 DV_D13_MARK, MSIOF0_TSCK_MARK,
455 DV_D12_MARK, MSIOF0_RXD_MARK,
456 DV_D11_MARK, MSIOF0_TXD_MARK,
457 DV_D10_MARK, MSIOF0_TSYNC_MARK,
458 DV_D9_MARK, MSIOF0_SS1_MARK, MSIOF0_RSCK_MARK,
459 DV_D8_MARK, MSIOF0_SS2_MARK, MSIOF0_RSYNC_MARK,
460 LCDVCPWC_MARK, SCIF0_RXD_MARK,
461 LCDRD_MARK, SCIF0_SCK_MARK,
462
463 /*PTN*/
464 VIO0_D1_MARK,
465 VIO0_D0_MARK,
466 DV_CLKI_MARK,
467 DV_CLK_MARK, SCIF2_V_SCK_MARK,
468 DV_VSYNC_MARK, SCIF2_V_RXD_MARK,
469 DV_HSYNC_MARK, SCIF2_V_TXD_MARK,
470 DV_D7_MARK, SCIF3_V_CTS_MARK, RMII_RX_ER_MARK,
471 DV_D6_MARK, SCIF3_V_RTS_MARK, RMII_CRS_DV_MARK,
472
473 /*PTQ*/
474 D7_MARK,
475 D6_MARK,
476 D5_MARK,
477 D4_MARK,
478 D3_MARK,
479 D2_MARK,
480 D1_MARK,
481 D0_MARK,
482
483 /*PTR*/
484 CS6B_CE1B_MARK,
485 CS6A_CE2B_MARK,
486 CS5B_CE1A_MARK,
487 CS5A_CE2A_MARK,
488 IOIS16_MARK, LCDLCLK_MARK,
489 WAIT_MARK,
490 WE3_ICIOWR_MARK, TPUTO3_MARK, TPUTI3_MARK,
491 WE2_ICIORD_MARK, TPUTO2_MARK, IDEA2_MARK,
492
493 /*PTS*/
494 VIO_CKO_MARK,
495 VIO1_FLD_MARK, TPUTI2_MARK, IDEIORDY_MARK,
496 VIO1_HD_MARK, SCIF5_SCK_MARK,
497 VIO1_VD_MARK, SCIF5_RXD_MARK,
498 VIO1_CLK_MARK, SCIF5_TXD_MARK,
499 VIO1_D7_MARK, VIO0_D15_MARK, IDED7_MARK,
500 VIO1_D6_MARK, VIO0_D14_MARK, IDED6_MARK,
501
502 /*PTT*/
503 D15_MARK,
504 D14_MARK,
505 D13_MARK,
506 D12_MARK,
507 D11_MARK,
508 D10_MARK,
509 D9_MARK,
510 D8_MARK,
511
512 /*PTU*/
513 DMAC_DACK0_MARK,
514 DMAC_DREQ0_MARK,
515 FSIOASD_MARK,
516 FSIIABCK_MARK,
517 FSIIALRCK_MARK,
518 FSIOABCK_MARK,
519 FSIOALRCK_MARK,
520 CLKAUDIOAO_MARK,
521
522 /*PTV*/
523 FSIIBSD_MARK, MSIOF1_SS2_MARK, MSIOF1_RSYNC_MARK,
524 FSIOBSD_MARK, MSIOF1_SS1_MARK, MSIOF1_RSCK_MARK,
525 FSIIBBCK_MARK, MSIOF1_RXD_MARK,
526 FSIIBLRCK_MARK, MSIOF1_TSYNC_MARK,
527 FSIOBBCK_MARK, MSIOF1_TSCK_MARK,
528 FSIOBLRCK_MARK, MSIOF1_TXD_MARK,
529 CLKAUDIOBO_MARK, MSIOF1_MCK_MARK,
530 FSIIASD_MARK,
531
532 /*PTW*/
533 MMC_D7_MARK, SDHI1CD_MARK, IODACK_MARK,
534 MMC_D6_MARK, SDHI1WP_MARK, IDERST_MARK,
535 MMC_D5_MARK, SDHI1D3_MARK, EXBUF_ENB_MARK,
536 MMC_D4_MARK, SDHI1D2_MARK, DIRECTION_MARK,
537 MMC_D3_MARK, SDHI1D1_MARK,
538 MMC_D2_MARK, SDHI1D0_MARK,
539 MMC_D1_MARK, SDHI1CMD_MARK,
540 MMC_D0_MARK, SDHI1CLK_MARK,
541
542 /*PTX*/
543 DMAC_DACK1_MARK, IRDA_OUT_MARK,
544 DMAC_DREQ1_MARK, IRDA_IN_MARK,
545 TSIF_TS0_SDAT_MARK, LNKSTA_MARK,
546 TSIF_TS0_SCK_MARK, MDIO_MARK,
547 TSIF_TS0_SDEN_MARK, MDC_MARK,
548 TSIF_TS0_SPSYNC_MARK,
549 MMC_CLK_MARK,
550 MMC_CMD_MARK,
551
552 /*PTY*/
553 SDHI0CD_MARK,
554 SDHI0WP_MARK,
555 SDHI0D3_MARK,
556 SDHI0D2_MARK,
557 SDHI0D1_MARK,
558 SDHI0D0_MARK,
559 SDHI0CMD_MARK,
560 SDHI0CLK_MARK,
561
562 /*PTZ*/
563 INTC_IRQ7_MARK, SCIF3_I_CTS_MARK,
564 INTC_IRQ6_MARK, SCIF3_I_RTS_MARK,
565 INTC_IRQ5_MARK, SCIF3_I_SCK_MARK,
566 INTC_IRQ4_MARK, SCIF3_I_RXD_MARK,
567 INTC_IRQ3_MARK, SCIF3_I_TXD_MARK,
568 INTC_IRQ2_MARK,
569 INTC_IRQ1_MARK,
570 INTC_IRQ0_MARK,
571 PINMUX_MARK_END,
572};
573
574static pinmux_enum_t pinmux_data[] = {
575 /* PTA GPIO */
576 PINMUX_DATA(PTA7_DATA, PTA7_IN, PTA7_OUT, PTA7_IN_PU),
577 PINMUX_DATA(PTA6_DATA, PTA6_IN, PTA6_OUT, PTA6_IN_PU),
578 PINMUX_DATA(PTA5_DATA, PTA5_IN, PTA5_OUT, PTA5_IN_PU),
579 PINMUX_DATA(PTA4_DATA, PTA4_IN, PTA4_OUT, PTA4_IN_PU),
580 PINMUX_DATA(PTA3_DATA, PTA3_IN, PTA3_OUT, PTA3_IN_PU),
581 PINMUX_DATA(PTA2_DATA, PTA2_IN, PTA2_OUT, PTA2_IN_PU),
582 PINMUX_DATA(PTA1_DATA, PTA1_IN, PTA1_OUT, PTA1_IN_PU),
583 PINMUX_DATA(PTA0_DATA, PTA0_IN, PTA0_OUT, PTA0_IN_PU),
584
585 /* PTB GPIO */
586 PINMUX_DATA(PTB7_DATA, PTB7_IN, PTB7_OUT, PTB7_IN_PU),
587 PINMUX_DATA(PTB6_DATA, PTB6_IN, PTB6_OUT, PTB6_IN_PU),
588 PINMUX_DATA(PTB5_DATA, PTB5_IN, PTB5_OUT, PTB5_IN_PU),
589 PINMUX_DATA(PTB4_DATA, PTB4_IN, PTB4_OUT, PTB4_IN_PU),
590 PINMUX_DATA(PTB3_DATA, PTB3_IN, PTB3_OUT, PTB3_IN_PU),
591 PINMUX_DATA(PTB2_DATA, PTB2_IN, PTB2_OUT, PTB2_IN_PU),
592 PINMUX_DATA(PTB1_DATA, PTB1_IN, PTB1_OUT, PTB1_IN_PU),
593 PINMUX_DATA(PTB0_DATA, PTB0_IN, PTB0_OUT, PTB0_IN_PU),
594
595 /* PTC GPIO */
596 PINMUX_DATA(PTC7_DATA, PTC7_IN, PTC7_OUT, PTC7_IN_PU),
597 PINMUX_DATA(PTC6_DATA, PTC6_IN, PTC6_OUT, PTC6_IN_PU),
598 PINMUX_DATA(PTC5_DATA, PTC5_IN, PTC5_OUT, PTC5_IN_PU),
599 PINMUX_DATA(PTC4_DATA, PTC4_IN, PTC4_OUT, PTC4_IN_PU),
600 PINMUX_DATA(PTC3_DATA, PTC3_IN, PTC3_OUT, PTC3_IN_PU),
601 PINMUX_DATA(PTC2_DATA, PTC2_IN, PTC2_OUT, PTC2_IN_PU),
602 PINMUX_DATA(PTC1_DATA, PTC1_IN, PTC1_OUT, PTC1_IN_PU),
603 PINMUX_DATA(PTC0_DATA, PTC0_IN, PTC0_OUT, PTC0_IN_PU),
604
605 /* PTD GPIO */
606 PINMUX_DATA(PTD7_DATA, PTD7_IN, PTD7_OUT, PTD7_IN_PU),
607 PINMUX_DATA(PTD6_DATA, PTD6_IN, PTD6_OUT, PTD6_IN_PU),
608 PINMUX_DATA(PTD5_DATA, PTD5_IN, PTD5_OUT, PTD5_IN_PU),
609 PINMUX_DATA(PTD4_DATA, PTD4_IN, PTD4_OUT, PTD4_IN_PU),
610 PINMUX_DATA(PTD3_DATA, PTD3_IN, PTD3_OUT, PTD3_IN_PU),
611 PINMUX_DATA(PTD2_DATA, PTD2_IN, PTD2_OUT, PTD2_IN_PU),
612 PINMUX_DATA(PTD1_DATA, PTD1_IN, PTD1_OUT, PTD1_IN_PU),
613 PINMUX_DATA(PTD0_DATA, PTD0_IN, PTD0_OUT, PTD0_IN_PU),
614
615 /* PTE GPIO */
616 PINMUX_DATA(PTE7_DATA, PTE7_IN, PTE7_OUT, PTE7_IN_PU),
617 PINMUX_DATA(PTE6_DATA, PTE6_IN, PTE6_OUT, PTE6_IN_PU),
618 PINMUX_DATA(PTE5_DATA, PTE5_IN, PTE5_OUT, PTE5_IN_PU),
619 PINMUX_DATA(PTE4_DATA, PTE4_IN, PTE4_OUT, PTE4_IN_PU),
620 PINMUX_DATA(PTE3_DATA, PTE3_IN, PTE3_OUT, PTE3_IN_PU),
621 PINMUX_DATA(PTE2_DATA, PTE2_IN, PTE2_OUT, PTE2_IN_PU),
622 PINMUX_DATA(PTE1_DATA, PTE1_IN, PTE1_OUT, PTE1_IN_PU),
623 PINMUX_DATA(PTE0_DATA, PTE0_IN, PTE0_OUT, PTE0_IN_PU),
624
625 /* PTF GPIO */
626 PINMUX_DATA(PTF7_DATA, PTF7_IN, PTF7_OUT, PTF7_IN_PU),
627 PINMUX_DATA(PTF6_DATA, PTF6_IN, PTF6_OUT, PTF6_IN_PU),
628 PINMUX_DATA(PTF5_DATA, PTF5_IN, PTF5_OUT, PTF5_IN_PU),
629 PINMUX_DATA(PTF4_DATA, PTF4_IN, PTF4_OUT, PTF4_IN_PU),
630 PINMUX_DATA(PTF3_DATA, PTF3_IN, PTF3_OUT, PTF3_IN_PU),
631 PINMUX_DATA(PTF2_DATA, PTF2_IN, PTF2_OUT, PTF2_IN_PU),
632 PINMUX_DATA(PTF1_DATA, PTF1_IN, PTF1_OUT, PTF1_IN_PU),
633 PINMUX_DATA(PTF0_DATA, PTF0_IN, PTF0_OUT, PTF0_IN_PU),
634
635 /* PTG GPIO */
636 PINMUX_DATA(PTG5_DATA, PTG5_OUT),
637 PINMUX_DATA(PTG4_DATA, PTG4_OUT),
638 PINMUX_DATA(PTG3_DATA, PTG3_OUT),
639 PINMUX_DATA(PTG2_DATA, PTG2_OUT),
640 PINMUX_DATA(PTG1_DATA, PTG1_OUT),
641 PINMUX_DATA(PTG0_DATA, PTG0_OUT),
642
643 /* PTH GPIO */
644 PINMUX_DATA(PTH7_DATA, PTH7_IN, PTH7_OUT, PTH7_IN_PU),
645 PINMUX_DATA(PTH6_DATA, PTH6_IN, PTH6_OUT, PTH6_IN_PU),
646 PINMUX_DATA(PTH5_DATA, PTH5_IN, PTH5_OUT, PTH5_IN_PU),
647 PINMUX_DATA(PTH4_DATA, PTH4_IN, PTH4_OUT, PTH4_IN_PU),
648 PINMUX_DATA(PTH3_DATA, PTH3_IN, PTH3_OUT, PTH3_IN_PU),
649 PINMUX_DATA(PTH2_DATA, PTH2_IN, PTH2_OUT, PTH2_IN_PU),
650 PINMUX_DATA(PTH1_DATA, PTH1_IN, PTH1_OUT, PTH1_IN_PU),
651 PINMUX_DATA(PTH0_DATA, PTH0_IN, PTH0_OUT, PTH0_IN_PU),
652
653 /* PTJ GPIO */
654 PINMUX_DATA(PTJ7_DATA, PTJ7_OUT),
655 PINMUX_DATA(PTJ6_DATA, PTJ6_OUT),
656 PINMUX_DATA(PTJ5_DATA, PTJ5_OUT),
657 PINMUX_DATA(PTJ3_DATA, PTJ3_IN, PTJ3_OUT, PTJ3_IN_PU),
658 PINMUX_DATA(PTJ2_DATA, PTJ2_IN, PTJ2_OUT, PTJ2_IN_PU),
659 PINMUX_DATA(PTJ1_DATA, PTJ1_IN, PTJ1_OUT, PTJ1_IN_PU),
660 PINMUX_DATA(PTJ0_DATA, PTJ0_IN, PTJ0_OUT, PTJ0_IN_PU),
661
662 /* PTK GPIO */
663 PINMUX_DATA(PTK7_DATA, PTK7_IN, PTK7_OUT, PTK7_IN_PU),
664 PINMUX_DATA(PTK6_DATA, PTK6_IN, PTK6_OUT, PTK6_IN_PU),
665 PINMUX_DATA(PTK5_DATA, PTK5_IN, PTK5_OUT, PTK5_IN_PU),
666 PINMUX_DATA(PTK4_DATA, PTK4_IN, PTK4_OUT, PTK4_IN_PU),
667 PINMUX_DATA(PTK3_DATA, PTK3_IN, PTK3_OUT, PTK3_IN_PU),
668 PINMUX_DATA(PTK2_DATA, PTK2_IN, PTK2_OUT, PTK2_IN_PU),
669 PINMUX_DATA(PTK1_DATA, PTK1_IN, PTK1_OUT, PTK1_IN_PU),
670 PINMUX_DATA(PTK0_DATA, PTK0_IN, PTK0_OUT, PTK0_IN_PU),
671
672 /* PTL GPIO */
673 PINMUX_DATA(PTL7_DATA, PTL7_IN, PTL7_OUT, PTL7_IN_PU),
674 PINMUX_DATA(PTL6_DATA, PTL6_IN, PTL6_OUT, PTL6_IN_PU),
675 PINMUX_DATA(PTL5_DATA, PTL5_IN, PTL5_OUT, PTL5_IN_PU),
676 PINMUX_DATA(PTL4_DATA, PTL4_IN, PTL4_OUT, PTL4_IN_PU),
677 PINMUX_DATA(PTL3_DATA, PTL3_IN, PTL3_OUT, PTL3_IN_PU),
678 PINMUX_DATA(PTL2_DATA, PTL2_IN, PTL2_OUT, PTL2_IN_PU),
679 PINMUX_DATA(PTL1_DATA, PTL1_IN, PTL1_OUT, PTL1_IN_PU),
680 PINMUX_DATA(PTL0_DATA, PTL0_IN, PTL0_OUT, PTL0_IN_PU),
681
682 /* PTM GPIO */
683 PINMUX_DATA(PTM7_DATA, PTM7_IN, PTM7_OUT, PTM7_IN_PU),
684 PINMUX_DATA(PTM6_DATA, PTM6_IN, PTM6_OUT, PTM6_IN_PU),
685 PINMUX_DATA(PTM5_DATA, PTM5_IN, PTM5_OUT, PTM5_IN_PU),
686 PINMUX_DATA(PTM4_DATA, PTM4_IN, PTM4_OUT, PTM4_IN_PU),
687 PINMUX_DATA(PTM3_DATA, PTM3_IN, PTM3_OUT, PTM3_IN_PU),
688 PINMUX_DATA(PTM2_DATA, PTM2_IN, PTM2_OUT, PTM2_IN_PU),
689 PINMUX_DATA(PTM1_DATA, PTM1_IN, PTM1_OUT, PTM1_IN_PU),
690 PINMUX_DATA(PTM0_DATA, PTM0_IN, PTM0_OUT, PTM0_IN_PU),
691
692 /* PTN GPIO */
693 PINMUX_DATA(PTN7_DATA, PTN7_IN, PTN7_OUT, PTN7_IN_PU),
694 PINMUX_DATA(PTN6_DATA, PTN6_IN, PTN6_OUT, PTN6_IN_PU),
695 PINMUX_DATA(PTN5_DATA, PTN5_IN, PTN5_OUT, PTN5_IN_PU),
696 PINMUX_DATA(PTN4_DATA, PTN4_IN, PTN4_OUT, PTN4_IN_PU),
697 PINMUX_DATA(PTN3_DATA, PTN3_IN, PTN3_OUT, PTN3_IN_PU),
698 PINMUX_DATA(PTN2_DATA, PTN2_IN, PTN2_OUT, PTN2_IN_PU),
699 PINMUX_DATA(PTN1_DATA, PTN1_IN, PTN1_OUT, PTN1_IN_PU),
700 PINMUX_DATA(PTN0_DATA, PTN0_IN, PTN0_OUT, PTN0_IN_PU),
701
702 /* PTQ GPIO */
703 PINMUX_DATA(PTQ7_DATA, PTQ7_IN, PTQ7_OUT, PTQ7_IN_PU),
704 PINMUX_DATA(PTQ6_DATA, PTQ6_IN, PTQ6_OUT, PTQ6_IN_PU),
705 PINMUX_DATA(PTQ5_DATA, PTQ5_IN, PTQ5_OUT, PTQ5_IN_PU),
706 PINMUX_DATA(PTQ4_DATA, PTQ4_IN, PTQ4_OUT, PTQ4_IN_PU),
707 PINMUX_DATA(PTQ3_DATA, PTQ3_IN, PTQ3_OUT, PTQ3_IN_PU),
708 PINMUX_DATA(PTQ2_DATA, PTQ2_IN, PTQ2_OUT, PTQ2_IN_PU),
709 PINMUX_DATA(PTQ1_DATA, PTQ1_IN, PTQ1_OUT, PTQ1_IN_PU),
710 PINMUX_DATA(PTQ0_DATA, PTQ0_IN, PTQ0_OUT, PTQ0_IN_PU),
711
712 /* PTR GPIO */
713 PINMUX_DATA(PTR7_DATA, PTR7_IN, PTR7_OUT, PTR7_IN_PU),
714 PINMUX_DATA(PTR6_DATA, PTR6_IN, PTR6_OUT, PTR6_IN_PU),
715 PINMUX_DATA(PTR5_DATA, PTR5_IN, PTR5_OUT, PTR5_IN_PU),
716 PINMUX_DATA(PTR4_DATA, PTR4_IN, PTR4_OUT, PTR4_IN_PU),
717 PINMUX_DATA(PTR3_DATA, PTR3_IN, PTR3_IN_PU),
718 PINMUX_DATA(PTR2_DATA, PTR2_IN, PTR2_IN_PU),
719 PINMUX_DATA(PTR1_DATA, PTR1_IN, PTR1_OUT, PTR1_IN_PU),
720 PINMUX_DATA(PTR0_DATA, PTR0_IN, PTR0_OUT, PTR0_IN_PU),
721
722 /* PTS GPIO */
723 PINMUX_DATA(PTS6_DATA, PTS6_IN, PTS6_OUT, PTS6_IN_PU),
724 PINMUX_DATA(PTS5_DATA, PTS5_IN, PTS5_OUT, PTS5_IN_PU),
725 PINMUX_DATA(PTS4_DATA, PTS4_IN, PTS4_OUT, PTS4_IN_PU),
726 PINMUX_DATA(PTS3_DATA, PTS3_IN, PTS3_OUT, PTS3_IN_PU),
727 PINMUX_DATA(PTS2_DATA, PTS2_IN, PTS2_OUT, PTS2_IN_PU),
728 PINMUX_DATA(PTS1_DATA, PTS1_IN, PTS1_OUT, PTS1_IN_PU),
729 PINMUX_DATA(PTS0_DATA, PTS0_IN, PTS0_OUT, PTS0_IN_PU),
730
731 /* PTT GPIO */
732 PINMUX_DATA(PTT7_DATA, PTT7_IN, PTT7_OUT, PTT7_IN_PU),
733 PINMUX_DATA(PTT6_DATA, PTT6_IN, PTT6_OUT, PTT6_IN_PU),
734 PINMUX_DATA(PTT5_DATA, PTT5_IN, PTT5_OUT, PTT5_IN_PU),
735 PINMUX_DATA(PTT4_DATA, PTT4_IN, PTT4_OUT, PTT4_IN_PU),
736 PINMUX_DATA(PTT3_DATA, PTT3_IN, PTT3_OUT, PTT3_IN_PU),
737 PINMUX_DATA(PTT2_DATA, PTT2_IN, PTT2_OUT, PTT2_IN_PU),
738 PINMUX_DATA(PTT1_DATA, PTT1_IN, PTT1_OUT, PTT1_IN_PU),
739 PINMUX_DATA(PTT0_DATA, PTT0_IN, PTT0_OUT, PTT0_IN_PU),
740
741 /* PTU GPIO */
742 PINMUX_DATA(PTU7_DATA, PTU7_IN, PTU7_OUT, PTU7_IN_PU),
743 PINMUX_DATA(PTU6_DATA, PTU6_IN, PTU6_OUT, PTU6_IN_PU),
744 PINMUX_DATA(PTU5_DATA, PTU5_IN, PTU5_OUT, PTU5_IN_PU),
745 PINMUX_DATA(PTU4_DATA, PTU4_IN, PTU4_OUT, PTU4_IN_PU),
746 PINMUX_DATA(PTU3_DATA, PTU3_IN, PTU3_OUT, PTU3_IN_PU),
747 PINMUX_DATA(PTU2_DATA, PTU2_IN, PTU2_OUT, PTU2_IN_PU),
748 PINMUX_DATA(PTU1_DATA, PTU1_IN, PTU1_OUT, PTU1_IN_PU),
749 PINMUX_DATA(PTU0_DATA, PTU0_IN, PTU0_OUT, PTU0_IN_PU),
750
751 /* PTV GPIO */
752 PINMUX_DATA(PTV7_DATA, PTV7_IN, PTV7_OUT, PTV7_IN_PU),
753 PINMUX_DATA(PTV6_DATA, PTV6_IN, PTV6_OUT, PTV6_IN_PU),
754 PINMUX_DATA(PTV5_DATA, PTV5_IN, PTV5_OUT, PTV5_IN_PU),
755 PINMUX_DATA(PTV4_DATA, PTV4_IN, PTV4_OUT, PTV4_IN_PU),
756 PINMUX_DATA(PTV3_DATA, PTV3_IN, PTV3_OUT, PTV3_IN_PU),
757 PINMUX_DATA(PTV2_DATA, PTV2_IN, PTV2_OUT, PTV2_IN_PU),
758 PINMUX_DATA(PTV1_DATA, PTV1_IN, PTV1_OUT, PTV1_IN_PU),
759 PINMUX_DATA(PTV0_DATA, PTV0_IN, PTV0_OUT, PTV0_IN_PU),
760
761 /* PTW GPIO */
762 PINMUX_DATA(PTW7_DATA, PTW7_IN, PTW7_OUT, PTW7_IN_PU),
763 PINMUX_DATA(PTW6_DATA, PTW6_IN, PTW6_OUT, PTW6_IN_PU),
764 PINMUX_DATA(PTW5_DATA, PTW5_IN, PTW5_OUT, PTW5_IN_PU),
765 PINMUX_DATA(PTW4_DATA, PTW4_IN, PTW4_OUT, PTW4_IN_PU),
766 PINMUX_DATA(PTW3_DATA, PTW3_IN, PTW3_OUT, PTW3_IN_PU),
767 PINMUX_DATA(PTW2_DATA, PTW2_IN, PTW2_OUT, PTW2_IN_PU),
768 PINMUX_DATA(PTW1_DATA, PTW1_IN, PTW1_OUT, PTW1_IN_PU),
769 PINMUX_DATA(PTW0_DATA, PTW0_IN, PTW0_OUT, PTW0_IN_PU),
770
771 /* PTX GPIO */
772 PINMUX_DATA(PTX7_DATA, PTX7_IN, PTX7_OUT, PTX7_IN_PU),
773 PINMUX_DATA(PTX6_DATA, PTX6_IN, PTX6_OUT, PTX6_IN_PU),
774 PINMUX_DATA(PTX5_DATA, PTX5_IN, PTX5_OUT, PTX5_IN_PU),
775 PINMUX_DATA(PTX4_DATA, PTX4_IN, PTX4_OUT, PTX4_IN_PU),
776 PINMUX_DATA(PTX3_DATA, PTX3_IN, PTX3_OUT, PTX3_IN_PU),
777 PINMUX_DATA(PTX2_DATA, PTX2_IN, PTX2_OUT, PTX2_IN_PU),
778 PINMUX_DATA(PTX1_DATA, PTX1_IN, PTX1_OUT, PTX1_IN_PU),
779 PINMUX_DATA(PTX0_DATA, PTX0_IN, PTX0_OUT, PTX0_IN_PU),
780
781 /* PTY GPIO */
782 PINMUX_DATA(PTY7_DATA, PTY7_IN, PTY7_OUT, PTY7_IN_PU),
783 PINMUX_DATA(PTY6_DATA, PTY6_IN, PTY6_OUT, PTY6_IN_PU),
784 PINMUX_DATA(PTY5_DATA, PTY5_IN, PTY5_OUT, PTY5_IN_PU),
785 PINMUX_DATA(PTY4_DATA, PTY4_IN, PTY4_OUT, PTY4_IN_PU),
786 PINMUX_DATA(PTY3_DATA, PTY3_IN, PTY3_OUT, PTY3_IN_PU),
787 PINMUX_DATA(PTY2_DATA, PTY2_IN, PTY2_OUT, PTY2_IN_PU),
788 PINMUX_DATA(PTY1_DATA, PTY1_IN, PTY1_OUT, PTY1_IN_PU),
789 PINMUX_DATA(PTY0_DATA, PTY0_IN, PTY0_OUT, PTY0_IN_PU),
790
791 /* PTZ GPIO */
792 PINMUX_DATA(PTZ7_DATA, PTZ7_IN, PTZ7_OUT, PTZ7_IN_PU),
793 PINMUX_DATA(PTZ6_DATA, PTZ6_IN, PTZ6_OUT, PTZ6_IN_PU),
794 PINMUX_DATA(PTZ5_DATA, PTZ5_IN, PTZ5_OUT, PTZ5_IN_PU),
795 PINMUX_DATA(PTZ4_DATA, PTZ4_IN, PTZ4_OUT, PTZ4_IN_PU),
796 PINMUX_DATA(PTZ3_DATA, PTZ3_IN, PTZ3_OUT, PTZ3_IN_PU),
797 PINMUX_DATA(PTZ2_DATA, PTZ2_IN, PTZ2_OUT, PTZ2_IN_PU),
798 PINMUX_DATA(PTZ1_DATA, PTZ1_IN, PTZ1_OUT, PTZ1_IN_PU),
799 PINMUX_DATA(PTZ0_DATA, PTZ0_IN, PTZ0_OUT, PTZ0_IN_PU),
800
801 /* PTA FN */
802 PINMUX_DATA(D23_MARK, PSA15_0, PSA14_0, PTA7_FN),
803 PINMUX_DATA(D22_MARK, PSA15_0, PSA14_0, PTA6_FN),
804 PINMUX_DATA(D21_MARK, PSA15_0, PSA14_0, PTA5_FN),
805 PINMUX_DATA(D20_MARK, PSA15_0, PSA14_0, PTA4_FN),
806 PINMUX_DATA(D19_MARK, PSA15_0, PSA14_0, PTA3_FN),
807 PINMUX_DATA(D18_MARK, PSA15_0, PSA14_0, PTA2_FN),
808 PINMUX_DATA(D17_MARK, PSA15_0, PSA14_0, PTA1_FN),
809 PINMUX_DATA(D16_MARK, PSA15_0, PSA14_0, PTA0_FN),
810
811 PINMUX_DATA(KEYOUT2_MARK, PSA15_0, PSA14_1, PTA7_FN),
812 PINMUX_DATA(KEYOUT1_MARK, PSA15_0, PSA14_1, PTA6_FN),
813 PINMUX_DATA(KEYOUT0_MARK, PSA15_0, PSA14_1, PTA5_FN),
814 PINMUX_DATA(KEYIN4_MARK, PSA15_0, PSA14_1, PTA4_FN),
815 PINMUX_DATA(KEYIN3_MARK, PSA15_0, PSA14_1, PTA3_FN),
816 PINMUX_DATA(KEYIN2_MARK, PSA15_0, PSA14_1, PTA2_FN),
817 PINMUX_DATA(KEYIN1_MARK, PSA15_0, PSA14_1, PTA1_FN),
818 PINMUX_DATA(KEYIN0_MARK, PSA15_0, PSA14_1, PTA0_FN),
819
820 PINMUX_DATA(IDED15_MARK, PSA15_1, PSA14_0, PTA7_FN),
821 PINMUX_DATA(IDED14_MARK, PSA15_1, PSA14_0, PTA6_FN),
822 PINMUX_DATA(IDED13_MARK, PSA15_1, PSA14_0, PTA5_FN),
823 PINMUX_DATA(IDED12_MARK, PSA15_1, PSA14_0, PTA4_FN),
824 PINMUX_DATA(IDED11_MARK, PSA15_1, PSA14_0, PTA3_FN),
825 PINMUX_DATA(IDED10_MARK, PSA15_1, PSA14_0, PTA2_FN),
826 PINMUX_DATA(IDED9_MARK, PSA15_1, PSA14_0, PTA1_FN),
827 PINMUX_DATA(IDED8_MARK, PSA15_1, PSA14_0, PTA0_FN),
828
829 /* PTB FN */
830 PINMUX_DATA(D31_MARK, PSE15_0, PSE14_0, PTB7_FN),
831 PINMUX_DATA(D30_MARK, PSE15_0, PSE14_0, PTB6_FN),
832 PINMUX_DATA(D29_MARK, PSE11_0, PTB5_FN),
833 PINMUX_DATA(D28_MARK, PSE11_0, PTB4_FN),
834 PINMUX_DATA(D27_MARK, PSE11_0, PTB3_FN),
835 PINMUX_DATA(D26_MARK, PSA15_0, PSA14_0, PTB2_FN),
836 PINMUX_DATA(D25_MARK, PSA15_0, PSA14_0, PTB1_FN),
837 PINMUX_DATA(D24_MARK, PSA15_0, PSA14_0, PTB0_FN),
838
839 PINMUX_DATA(IDEA1_MARK, PSE15_1, PSE14_0, PTB7_FN),
840 PINMUX_DATA(IDEA0_MARK, PSE15_1, PSE14_0, PTB6_FN),
841 PINMUX_DATA(IODREQ_MARK, PSE11_1, PTB5_FN),
842 PINMUX_DATA(IDECS0_MARK, PSE11_1, PTB4_FN),
843 PINMUX_DATA(IDECS1_MARK, PSE11_1, PTB3_FN),
844 PINMUX_DATA(IDEIORD_MARK, PSA15_1, PSA14_0, PTB2_FN),
845 PINMUX_DATA(IDEIOWR_MARK, PSA15_1, PSA14_0, PTB1_FN),
846 PINMUX_DATA(IDEINT_MARK, PSA15_1, PSA14_0, PTB0_FN),
847
848 PINMUX_DATA(TPUTO1_MARK, PSE15_0, PSE14_1, PTB7_FN),
849 PINMUX_DATA(TPUTO0_MARK, PSE15_0, PSE14_1, PTB6_FN),
850
851 PINMUX_DATA(KEYOUT5_IN5_MARK, PSA15_0, PSA14_1, PTB2_FN),
852 PINMUX_DATA(KEYOUT4_IN6_MARK, PSA15_0, PSA14_1, PTB1_FN),
853 PINMUX_DATA(KEYOUT3_MARK, PSA15_0, PSA14_1, PTB0_FN),
854
855 /* PTC FN */
856 PINMUX_DATA(LCDD7_MARK, PSD5_0, PTC7_FN),
857 PINMUX_DATA(LCDD6_MARK, PSD5_0, PTC6_FN),
858 PINMUX_DATA(LCDD5_MARK, PSD5_0, PTC5_FN),
859 PINMUX_DATA(LCDD4_MARK, PSD5_0, PTC4_FN),
860 PINMUX_DATA(LCDD3_MARK, PSD5_0, PTC3_FN),
861 PINMUX_DATA(LCDD2_MARK, PSD5_0, PTC2_FN),
862 PINMUX_DATA(LCDD1_MARK, PSD5_0, PTC1_FN),
863 PINMUX_DATA(LCDD0_MARK, PSD5_0, PTC0_FN),
864
865 /* PTD FN */
866 PINMUX_DATA(LCDD15_MARK, PSD5_0, PTD7_FN),
867 PINMUX_DATA(LCDD14_MARK, PSD5_0, PTD6_FN),
868 PINMUX_DATA(LCDD13_MARK, PSD5_0, PTD5_FN),
869 PINMUX_DATA(LCDD12_MARK, PSD5_0, PTD4_FN),
870 PINMUX_DATA(LCDD11_MARK, PSD5_0, PTD3_FN),
871 PINMUX_DATA(LCDD10_MARK, PSD5_0, PTD2_FN),
872 PINMUX_DATA(LCDD9_MARK, PSD5_0, PTD1_FN),
873 PINMUX_DATA(LCDD8_MARK, PSD5_0, PTD0_FN),
874
875 /* PTE FN */
876 PINMUX_DATA(FSIMCKB_MARK, PTE7_FN),
877 PINMUX_DATA(FSIMCKA_MARK, PTE6_FN),
878
879 PINMUX_DATA(LCDD21_MARK, PSC5_0, PSC4_0, PTE5_FN),
880 PINMUX_DATA(LCDD20_MARK, PSD3_0, PSD2_0, PTE4_FN),
881 PINMUX_DATA(LCDD19_MARK, PSA3_0, PSA2_0, PTE3_FN),
882 PINMUX_DATA(LCDD18_MARK, PSA3_0, PSA2_0, PTE2_FN),
883 PINMUX_DATA(LCDD17_MARK, PSD5_0, PTE1_FN),
884 PINMUX_DATA(LCDD16_MARK, PSD5_0, PTE0_FN),
885
886 PINMUX_DATA(SCIF2_L_TXD_MARK, PSC5_0, PSC4_1, PTE5_FN),
887 PINMUX_DATA(SCIF4_SCK_MARK, PSD3_0, PSD2_1, PTE4_FN),
888 PINMUX_DATA(SCIF4_RXD_MARK, PSA3_0, PSA2_1, PTE3_FN),
889 PINMUX_DATA(SCIF4_TXD_MARK, PSA3_0, PSA2_1, PTE2_FN),
890
891 /* PTF FN */
892 PINMUX_DATA(LCDVSYN_MARK, PSD8_0, PTF7_FN),
893 PINMUX_DATA(LCDDISP_MARK, PSD10_0, PSD9_0, PTF6_FN),
894 PINMUX_DATA(LCDHSYN_MARK, PSD10_0, PSD9_0, PTF5_FN),
895 PINMUX_DATA(LCDDON_MARK, PSD8_0, PTF4_FN),
896 PINMUX_DATA(LCDDCK_MARK, PSD10_0, PSD9_0, PTF3_FN),
897 PINMUX_DATA(LCDVEPWC_MARK, PSA6_0, PTF2_FN),
898 PINMUX_DATA(LCDD23_MARK, PSC7_0, PSC6_0, PTF1_FN),
899 PINMUX_DATA(LCDD22_MARK, PSC5_0, PSC4_0, PTF0_FN),
900
901 PINMUX_DATA(LCDRS_MARK, PSD10_0, PSD9_1, PTF6_FN),
902 PINMUX_DATA(LCDCS_MARK, PSD10_0, PSD9_1, PTF5_FN),
903 PINMUX_DATA(LCDWR_MARK, PSD10_0, PSD9_1, PTF3_FN),
904
905 PINMUX_DATA(SCIF0_TXD_MARK, PSA6_1, PTF2_FN),
906 PINMUX_DATA(SCIF2_L_SCK_MARK, PSC7_0, PSC6_1, PTF1_FN),
907 PINMUX_DATA(SCIF2_L_RXD_MARK, PSC5_0, PSC4_1, PTF0_FN),
908
909 /* PTG FN */
910 PINMUX_DATA(AUDCK_MARK, PTG5_FN),
911 PINMUX_DATA(AUDSYNC_MARK, PTG4_FN),
912 PINMUX_DATA(AUDATA3_MARK, PTG3_FN),
913 PINMUX_DATA(AUDATA2_MARK, PTG2_FN),
914 PINMUX_DATA(AUDATA1_MARK, PTG1_FN),
915 PINMUX_DATA(AUDATA0_MARK, PTG0_FN),
916
917 /* PTH FN */
918 PINMUX_DATA(VIO0_VD_MARK, PTH7_FN),
919 PINMUX_DATA(VIO0_CLK_MARK, PTH6_FN),
920 PINMUX_DATA(VIO0_D7_MARK, PTH5_FN),
921 PINMUX_DATA(VIO0_D6_MARK, PTH4_FN),
922 PINMUX_DATA(VIO0_D5_MARK, PTH3_FN),
923 PINMUX_DATA(VIO0_D4_MARK, PTH2_FN),
924 PINMUX_DATA(VIO0_D3_MARK, PTH1_FN),
925 PINMUX_DATA(VIO0_D2_MARK, PTH0_FN),
926
927 /* PTJ FN */
928 PINMUX_DATA(PDSTATUS_MARK, PTJ7_FN),
929 PINMUX_DATA(STATUS2_MARK, PTJ6_FN),
930 PINMUX_DATA(STATUS0_MARK, PTJ5_FN),
931 PINMUX_DATA(A25_MARK, PSA8_0, PTJ3_FN),
932 PINMUX_DATA(BS_MARK, PSA8_1, PTJ3_FN),
933 PINMUX_DATA(A24_MARK, PTJ2_FN),
934 PINMUX_DATA(A23_MARK, PTJ1_FN),
935 PINMUX_DATA(A22_MARK, PTJ0_FN),
936
937 /* PTK FN */
938 PINMUX_DATA(VIO1_D5_MARK, PSB7_0, PSB6_0, PTK7_FN),
939 PINMUX_DATA(VIO1_D4_MARK, PSB7_0, PSB6_0, PTK6_FN),
940 PINMUX_DATA(VIO1_D3_MARK, PSB7_0, PSB6_0, PTK5_FN),
941 PINMUX_DATA(VIO1_D2_MARK, PSB7_0, PSB6_0, PTK4_FN),
942 PINMUX_DATA(VIO1_D1_MARK, PSB7_0, PSB6_0, PTK3_FN),
943 PINMUX_DATA(VIO1_D0_MARK, PSB7_0, PSB6_0, PTK2_FN),
944
945 PINMUX_DATA(VIO0_D13_MARK, PSB7_0, PSB6_1, PTK7_FN),
946 PINMUX_DATA(VIO0_D12_MARK, PSB7_0, PSB6_1, PTK6_FN),
947 PINMUX_DATA(VIO0_D11_MARK, PSB7_0, PSB6_1, PTK5_FN),
948 PINMUX_DATA(VIO0_D10_MARK, PSB7_0, PSB6_1, PTK4_FN),
949 PINMUX_DATA(VIO0_D9_MARK, PSB7_0, PSB6_1, PTK3_FN),
950 PINMUX_DATA(VIO0_D8_MARK, PSB7_0, PSB6_1, PTK2_FN),
951
952 PINMUX_DATA(IDED5_MARK, PSB7_1, PSB6_0, PTK7_FN),
953 PINMUX_DATA(IDED4_MARK, PSB7_1, PSB6_0, PTK6_FN),
954 PINMUX_DATA(IDED3_MARK, PSB7_1, PSB6_0, PTK5_FN),
955 PINMUX_DATA(IDED2_MARK, PSB7_1, PSB6_0, PTK4_FN),
956 PINMUX_DATA(IDED1_MARK, PSB7_1, PSB6_0, PTK3_FN),
957 PINMUX_DATA(IDED0_MARK, PSB7_1, PSB6_0, PTK2_FN),
958
959 PINMUX_DATA(VIO0_FLD_MARK, PTK1_FN),
960 PINMUX_DATA(VIO0_HD_MARK, PTK0_FN),
961
962 /* PTL FN */
963 PINMUX_DATA(DV_D5_MARK, PSB9_0, PSB8_0, PTL7_FN),
964 PINMUX_DATA(DV_D4_MARK, PSB9_0, PSB8_0, PTL6_FN),
965 PINMUX_DATA(DV_D3_MARK, PSE7_0, PSE6_0, PTL5_FN),
966 PINMUX_DATA(DV_D2_MARK, PSC9_0, PSC8_0, PTL4_FN),
967 PINMUX_DATA(DV_D1_MARK, PSC9_0, PSC8_0, PTL3_FN),
968 PINMUX_DATA(DV_D0_MARK, PSC9_0, PSC8_0, PTL2_FN),
969 PINMUX_DATA(DV_D15_MARK, PSD4_0, PTL1_FN),
970 PINMUX_DATA(DV_D14_MARK, PSE5_0, PSE4_0, PTL0_FN),
971
972 PINMUX_DATA(SCIF3_V_SCK_MARK, PSB9_0, PSB8_1, PTL7_FN),
973 PINMUX_DATA(SCIF3_V_RXD_MARK, PSB9_0, PSB8_1, PTL6_FN),
974 PINMUX_DATA(SCIF3_V_TXD_MARK, PSE7_0, PSE6_1, PTL5_FN),
975 PINMUX_DATA(SCIF1_SCK_MARK, PSC9_0, PSC8_1, PTL4_FN),
976 PINMUX_DATA(SCIF1_RXD_MARK, PSC9_0, PSC8_1, PTL3_FN),
977 PINMUX_DATA(SCIF1_TXD_MARK, PSC9_0, PSC8_1, PTL2_FN),
978
979 PINMUX_DATA(RMII_RXD0_MARK, PSB9_1, PSB8_0, PTL7_FN),
980 PINMUX_DATA(RMII_RXD1_MARK, PSB9_1, PSB8_0, PTL6_FN),
981 PINMUX_DATA(RMII_REF_CLK_MARK, PSE7_1, PSE6_0, PTL5_FN),
982 PINMUX_DATA(RMII_TX_EN_MARK, PSC9_1, PSC8_0, PTL4_FN),
983 PINMUX_DATA(RMII_TXD0_MARK, PSC9_1, PSC8_0, PTL3_FN),
984 PINMUX_DATA(RMII_TXD1_MARK, PSC9_1, PSC8_0, PTL2_FN),
985
986 PINMUX_DATA(MSIOF0_MCK_MARK, PSE5_0, PSE4_1, PTL0_FN),
987
988 /* PTM FN */
989 PINMUX_DATA(DV_D13_MARK, PSC13_0, PSC12_0, PTM7_FN),
990 PINMUX_DATA(DV_D12_MARK, PSC13_0, PSC12_0, PTM6_FN),
991 PINMUX_DATA(DV_D11_MARK, PSC13_0, PSC12_0, PTM5_FN),
992 PINMUX_DATA(DV_D10_MARK, PSC13_0, PSC12_0, PTM4_FN),
993 PINMUX_DATA(DV_D9_MARK, PSC11_0, PSC10_0, PTM3_FN),
994 PINMUX_DATA(DV_D8_MARK, PSC11_0, PSC10_0, PTM2_FN),
995
996 PINMUX_DATA(MSIOF0_TSCK_MARK, PSC13_0, PSC12_1, PTM7_FN),
997 PINMUX_DATA(MSIOF0_RXD_MARK, PSC13_0, PSC12_1, PTM6_FN),
998 PINMUX_DATA(MSIOF0_TXD_MARK, PSC13_0, PSC12_1, PTM5_FN),
999 PINMUX_DATA(MSIOF0_TSYNC_MARK, PSC13_0, PSC12_1, PTM4_FN),
1000 PINMUX_DATA(MSIOF0_SS1_MARK, PSC11_0, PSC10_1, PTM3_FN),
1001 PINMUX_DATA(MSIOF0_RSCK_MARK, PSC11_1, PSC10_0, PTM3_FN),
1002 PINMUX_DATA(MSIOF0_SS2_MARK, PSC11_0, PSC10_1, PTM2_FN),
1003 PINMUX_DATA(MSIOF0_RSYNC_MARK, PSC11_1, PSC10_0, PTM2_FN),
1004
1005 PINMUX_DATA(LCDVCPWC_MARK, PSA6_0, PTM1_FN),
1006 PINMUX_DATA(LCDRD_MARK, PSA7_0, PTM0_FN),
1007
1008 PINMUX_DATA(SCIF0_RXD_MARK, PSA6_1, PTM1_FN),
1009 PINMUX_DATA(SCIF0_SCK_MARK, PSA7_1, PTM0_FN),
1010
1011 /* PTN FN */
1012 PINMUX_DATA(VIO0_D1_MARK, PTN7_FN),
1013 PINMUX_DATA(VIO0_D0_MARK, PTN6_FN),
1014
1015 PINMUX_DATA(DV_CLKI_MARK, PSD11_0, PTN5_FN),
1016 PINMUX_DATA(DV_CLK_MARK, PSD13_0, PSD12_0, PTN4_FN),
1017 PINMUX_DATA(DV_VSYNC_MARK, PSD15_0, PSD14_0, PTN3_FN),
1018 PINMUX_DATA(DV_HSYNC_MARK, PSB5_0, PSB4_0, PTN2_FN),
1019 PINMUX_DATA(DV_D7_MARK, PSB3_0, PSB2_0, PTN1_FN),
1020 PINMUX_DATA(DV_D6_MARK, PSB1_0, PSB0_0, PTN0_FN),
1021
1022 PINMUX_DATA(SCIF2_V_SCK_MARK, PSD13_0, PSD12_1, PTN4_FN),
1023 PINMUX_DATA(SCIF2_V_RXD_MARK, PSD15_0, PSD14_1, PTN3_FN),
1024 PINMUX_DATA(SCIF2_V_TXD_MARK, PSB5_0, PSB4_1, PTN2_FN),
1025 PINMUX_DATA(SCIF3_V_CTS_MARK, PSB3_0, PSB2_1, PTN1_FN),
1026 PINMUX_DATA(SCIF3_V_RTS_MARK, PSB1_0, PSB0_1, PTN0_FN),
1027
1028 PINMUX_DATA(RMII_RX_ER_MARK, PSB3_1, PSB2_0, PTN1_FN),
1029 PINMUX_DATA(RMII_CRS_DV_MARK, PSB1_1, PSB0_0, PTN0_FN),
1030
1031 /* PTQ FN */
1032 PINMUX_DATA(D7_MARK, PTQ7_FN),
1033 PINMUX_DATA(D6_MARK, PTQ6_FN),
1034 PINMUX_DATA(D5_MARK, PTQ5_FN),
1035 PINMUX_DATA(D4_MARK, PTQ4_FN),
1036 PINMUX_DATA(D3_MARK, PTQ3_FN),
1037 PINMUX_DATA(D2_MARK, PTQ2_FN),
1038 PINMUX_DATA(D1_MARK, PTQ1_FN),
1039 PINMUX_DATA(D0_MARK, PTQ0_FN),
1040
1041 /* PTR FN */
1042 PINMUX_DATA(CS6B_CE1B_MARK, PTR7_FN),
1043 PINMUX_DATA(CS6A_CE2B_MARK, PTR6_FN),
1044 PINMUX_DATA(CS5B_CE1A_MARK, PTR5_FN),
1045 PINMUX_DATA(CS5A_CE2A_MARK, PTR4_FN),
1046 PINMUX_DATA(IOIS16_MARK, PSA5_0, PTR3_FN),
1047 PINMUX_DATA(WAIT_MARK, PTR2_FN),
1048 PINMUX_DATA(WE3_ICIOWR_MARK, PSA1_0, PSA0_0, PTR1_FN),
1049 PINMUX_DATA(WE2_ICIORD_MARK, PSD1_0, PSD0_0, PTR0_FN),
1050
1051 PINMUX_DATA(LCDLCLK_MARK, PSA5_1, PTR3_FN),
1052
1053 PINMUX_DATA(IDEA2_MARK, PSD1_1, PSD0_0, PTR0_FN),
1054
1055 PINMUX_DATA(TPUTO3_MARK, PSA1_0, PSA0_1, PTR1_FN),
1056 PINMUX_DATA(TPUTI3_MARK, PSA1_1, PSA0_0, PTR1_FN),
1057 PINMUX_DATA(TPUTO2_MARK, PSD1_0, PSD0_1, PTR0_FN),
1058
1059 /* PTS FN */
1060 PINMUX_DATA(VIO_CKO_MARK, PTS6_FN),
1061
1062 PINMUX_DATA(TPUTI2_MARK, PSE9_0, PSE8_1, PTS5_FN),
1063
1064 PINMUX_DATA(IDEIORDY_MARK, PSE9_1, PSE8_0, PTS5_FN),
1065
1066 PINMUX_DATA(VIO1_FLD_MARK, PSE9_0, PSE8_0, PTS5_FN),
1067 PINMUX_DATA(VIO1_HD_MARK, PSA10_0, PTS4_FN),
1068 PINMUX_DATA(VIO1_VD_MARK, PSA9_0, PTS3_FN),
1069 PINMUX_DATA(VIO1_CLK_MARK, PSA9_0, PTS2_FN),
1070 PINMUX_DATA(VIO1_D7_MARK, PSB7_0, PSB6_0, PTS1_FN),
1071 PINMUX_DATA(VIO1_D6_MARK, PSB7_0, PSB6_0, PTS0_FN),
1072
1073 PINMUX_DATA(SCIF5_SCK_MARK, PSA10_1, PTS4_FN),
1074 PINMUX_DATA(SCIF5_RXD_MARK, PSA9_1, PTS3_FN),
1075 PINMUX_DATA(SCIF5_TXD_MARK, PSA9_1, PTS2_FN),
1076
1077 PINMUX_DATA(VIO0_D15_MARK, PSB7_0, PSB6_1, PTS1_FN),
1078 PINMUX_DATA(VIO0_D14_MARK, PSB7_0, PSB6_1, PTS0_FN),
1079
1080 PINMUX_DATA(IDED7_MARK, PSB7_1, PSB6_0, PTS1_FN),
1081 PINMUX_DATA(IDED6_MARK, PSB7_1, PSB6_0, PTS0_FN),
1082
1083 /* PTT FN */
1084 PINMUX_DATA(D15_MARK, PTT7_FN),
1085 PINMUX_DATA(D14_MARK, PTT6_FN),
1086 PINMUX_DATA(D13_MARK, PTT5_FN),
1087 PINMUX_DATA(D12_MARK, PTT4_FN),
1088 PINMUX_DATA(D11_MARK, PTT3_FN),
1089 PINMUX_DATA(D10_MARK, PTT2_FN),
1090 PINMUX_DATA(D9_MARK, PTT1_FN),
1091 PINMUX_DATA(D8_MARK, PTT0_FN),
1092
1093 /* PTU FN */
1094 PINMUX_DATA(DMAC_DACK0_MARK, PTU7_FN),
1095 PINMUX_DATA(DMAC_DREQ0_MARK, PTU6_FN),
1096
1097 PINMUX_DATA(FSIOASD_MARK, PSE1_0, PTU5_FN),
1098 PINMUX_DATA(FSIIABCK_MARK, PSE1_0, PTU4_FN),
1099 PINMUX_DATA(FSIIALRCK_MARK, PSE1_0, PTU3_FN),
1100 PINMUX_DATA(FSIOABCK_MARK, PSE1_0, PTU2_FN),
1101 PINMUX_DATA(FSIOALRCK_MARK, PSE1_0, PTU1_FN),
1102 PINMUX_DATA(CLKAUDIOAO_MARK, PSE0_0, PTU0_FN),
1103
1104 /* PTV FN */
1105 PINMUX_DATA(FSIIBSD_MARK, PSD7_0, PSD6_0, PTV7_FN),
1106 PINMUX_DATA(FSIOBSD_MARK, PSD7_0, PSD6_0, PTV6_FN),
1107 PINMUX_DATA(FSIIBBCK_MARK, PSC15_0, PSC14_0, PTV5_FN),
1108 PINMUX_DATA(FSIIBLRCK_MARK, PSC15_0, PSC14_0, PTV4_FN),
1109 PINMUX_DATA(FSIOBBCK_MARK, PSC15_0, PSC14_0, PTV3_FN),
1110 PINMUX_DATA(FSIOBLRCK_MARK, PSC15_0, PSC14_0, PTV2_FN),
1111 PINMUX_DATA(CLKAUDIOBO_MARK, PSE3_0, PSE2_0, PTV1_FN),
1112 PINMUX_DATA(FSIIASD_MARK, PSE10_0, PTV0_FN),
1113
1114 PINMUX_DATA(MSIOF1_SS2_MARK, PSD7_0, PSD6_1, PTV7_FN),
1115 PINMUX_DATA(MSIOF1_RSYNC_MARK, PSD7_1, PSD6_0, PTV7_FN),
1116 PINMUX_DATA(MSIOF1_SS1_MARK, PSD7_0, PSD6_1, PTV6_FN),
1117 PINMUX_DATA(MSIOF1_RSCK_MARK, PSD7_1, PSD6_0, PTV6_FN),
1118 PINMUX_DATA(MSIOF1_RXD_MARK, PSC15_0, PSC14_1, PTV5_FN),
1119 PINMUX_DATA(MSIOF1_TSYNC_MARK, PSC15_0, PSC14_1, PTV4_FN),
1120 PINMUX_DATA(MSIOF1_TSCK_MARK, PSC15_0, PSC14_1, PTV3_FN),
1121 PINMUX_DATA(MSIOF1_TXD_MARK, PSC15_0, PSC14_1, PTV2_FN),
1122 PINMUX_DATA(MSIOF1_MCK_MARK, PSE3_0, PSE2_1, PTV1_FN),
1123
1124 /* PTW FN */
1125 PINMUX_DATA(MMC_D7_MARK, PSE13_0, PSE12_0, PTW7_FN),
1126 PINMUX_DATA(MMC_D6_MARK, PSE13_0, PSE12_0, PTW6_FN),
1127 PINMUX_DATA(MMC_D5_MARK, PSE13_0, PSE12_0, PTW5_FN),
1128 PINMUX_DATA(MMC_D4_MARK, PSE13_0, PSE12_0, PTW4_FN),
1129 PINMUX_DATA(MMC_D3_MARK, PSA13_0, PTW3_FN),
1130 PINMUX_DATA(MMC_D2_MARK, PSA13_0, PTW2_FN),
1131 PINMUX_DATA(MMC_D1_MARK, PSA13_0, PTW1_FN),
1132 PINMUX_DATA(MMC_D0_MARK, PSA13_0, PTW0_FN),
1133
1134 PINMUX_DATA(SDHI1CD_MARK, PSE13_0, PSE12_1, PTW7_FN),
1135 PINMUX_DATA(SDHI1WP_MARK, PSE13_0, PSE12_1, PTW6_FN),
1136 PINMUX_DATA(SDHI1D3_MARK, PSE13_0, PSE12_1, PTW5_FN),
1137 PINMUX_DATA(SDHI1D2_MARK, PSE13_0, PSE12_1, PTW4_FN),
1138 PINMUX_DATA(SDHI1D1_MARK, PSA13_1, PTW3_FN),
1139 PINMUX_DATA(SDHI1D0_MARK, PSA13_1, PTW2_FN),
1140 PINMUX_DATA(SDHI1CMD_MARK, PSA13_1, PTW1_FN),
1141 PINMUX_DATA(SDHI1CLK_MARK, PSA13_1, PTW0_FN),
1142
1143 PINMUX_DATA(IODACK_MARK, PSE13_1, PSE12_0, PTW7_FN),
1144 PINMUX_DATA(IDERST_MARK, PSE13_1, PSE12_0, PTW6_FN),
1145 PINMUX_DATA(EXBUF_ENB_MARK, PSE13_1, PSE12_0, PTW5_FN),
1146 PINMUX_DATA(DIRECTION_MARK, PSE13_1, PSE12_0, PTW4_FN),
1147
1148 /* PTX FN */
1149 PINMUX_DATA(DMAC_DACK1_MARK, PSA12_0, PTX7_FN),
1150 PINMUX_DATA(DMAC_DREQ1_MARK, PSA12_0, PTX6_FN),
1151
1152 PINMUX_DATA(IRDA_OUT_MARK, PSA12_1, PTX7_FN),
1153 PINMUX_DATA(IRDA_IN_MARK, PSA12_1, PTX6_FN),
1154
1155 PINMUX_DATA(TSIF_TS0_SDAT_MARK, PSC0_0, PTX5_FN),
1156 PINMUX_DATA(TSIF_TS0_SCK_MARK, PSC1_0, PTX4_FN),
1157 PINMUX_DATA(TSIF_TS0_SDEN_MARK, PSC2_0, PTX3_FN),
1158 PINMUX_DATA(TSIF_TS0_SPSYNC_MARK, PTX2_FN),
1159
1160 PINMUX_DATA(LNKSTA_MARK, PSC0_1, PTX5_FN),
1161 PINMUX_DATA(MDIO_MARK, PSC1_1, PTX4_FN),
1162 PINMUX_DATA(MDC_MARK, PSC2_1, PTX3_FN),
1163
1164 PINMUX_DATA(MMC_CLK_MARK, PTX1_FN),
1165 PINMUX_DATA(MMC_CMD_MARK, PTX0_FN),
1166
1167 /* PTY FN */
1168 PINMUX_DATA(SDHI0CD_MARK, PTY7_FN),
1169 PINMUX_DATA(SDHI0WP_MARK, PTY6_FN),
1170 PINMUX_DATA(SDHI0D3_MARK, PTY5_FN),
1171 PINMUX_DATA(SDHI0D2_MARK, PTY4_FN),
1172 PINMUX_DATA(SDHI0D1_MARK, PTY3_FN),
1173 PINMUX_DATA(SDHI0D0_MARK, PTY2_FN),
1174 PINMUX_DATA(SDHI0CMD_MARK, PTY1_FN),
1175 PINMUX_DATA(SDHI0CLK_MARK, PTY0_FN),
1176
1177 /* PTZ FN */
1178 PINMUX_DATA(INTC_IRQ7_MARK, PSB10_0, PTZ7_FN),
1179 PINMUX_DATA(INTC_IRQ6_MARK, PSB11_0, PTZ6_FN),
1180 PINMUX_DATA(INTC_IRQ5_MARK, PSB12_0, PTZ5_FN),
1181 PINMUX_DATA(INTC_IRQ4_MARK, PSB13_0, PTZ4_FN),
1182 PINMUX_DATA(INTC_IRQ3_MARK, PSB14_0, PTZ3_FN),
1183 PINMUX_DATA(INTC_IRQ2_MARK, PTZ2_FN),
1184 PINMUX_DATA(INTC_IRQ1_MARK, PTZ1_FN),
1185 PINMUX_DATA(INTC_IRQ0_MARK, PTZ0_FN),
1186
1187 PINMUX_DATA(SCIF3_I_CTS_MARK, PSB10_1, PTZ7_FN),
1188 PINMUX_DATA(SCIF3_I_RTS_MARK, PSB11_1, PTZ6_FN),
1189 PINMUX_DATA(SCIF3_I_SCK_MARK, PSB12_1, PTZ5_FN),
1190 PINMUX_DATA(SCIF3_I_RXD_MARK, PSB13_1, PTZ4_FN),
1191 PINMUX_DATA(SCIF3_I_TXD_MARK, PSB14_1, PTZ3_FN),
1192};
1193
1194static struct pinmux_gpio pinmux_gpios[] = {
1195 /* PTA */
1196 PINMUX_GPIO(GPIO_PTA7, PTA7_DATA),
1197 PINMUX_GPIO(GPIO_PTA6, PTA6_DATA),
1198 PINMUX_GPIO(GPIO_PTA5, PTA5_DATA),
1199 PINMUX_GPIO(GPIO_PTA4, PTA4_DATA),
1200 PINMUX_GPIO(GPIO_PTA3, PTA3_DATA),
1201 PINMUX_GPIO(GPIO_PTA2, PTA2_DATA),
1202 PINMUX_GPIO(GPIO_PTA1, PTA1_DATA),
1203 PINMUX_GPIO(GPIO_PTA0, PTA0_DATA),
1204
1205 /* PTB */
1206 PINMUX_GPIO(GPIO_PTB7, PTB7_DATA),
1207 PINMUX_GPIO(GPIO_PTB6, PTB6_DATA),
1208 PINMUX_GPIO(GPIO_PTB5, PTB5_DATA),
1209 PINMUX_GPIO(GPIO_PTB4, PTB4_DATA),
1210 PINMUX_GPIO(GPIO_PTB3, PTB3_DATA),
1211 PINMUX_GPIO(GPIO_PTB2, PTB2_DATA),
1212 PINMUX_GPIO(GPIO_PTB1, PTB1_DATA),
1213 PINMUX_GPIO(GPIO_PTB0, PTB0_DATA),
1214
1215 /* PTC */
1216 PINMUX_GPIO(GPIO_PTC7, PTC7_DATA),
1217 PINMUX_GPIO(GPIO_PTC6, PTC6_DATA),
1218 PINMUX_GPIO(GPIO_PTC5, PTC5_DATA),
1219 PINMUX_GPIO(GPIO_PTC4, PTC4_DATA),
1220 PINMUX_GPIO(GPIO_PTC3, PTC3_DATA),
1221 PINMUX_GPIO(GPIO_PTC2, PTC2_DATA),
1222 PINMUX_GPIO(GPIO_PTC1, PTC1_DATA),
1223 PINMUX_GPIO(GPIO_PTC0, PTC0_DATA),
1224
1225 /* PTD */
1226 PINMUX_GPIO(GPIO_PTD7, PTD7_DATA),
1227 PINMUX_GPIO(GPIO_PTD6, PTD6_DATA),
1228 PINMUX_GPIO(GPIO_PTD5, PTD5_DATA),
1229 PINMUX_GPIO(GPIO_PTD4, PTD4_DATA),
1230 PINMUX_GPIO(GPIO_PTD3, PTD3_DATA),
1231 PINMUX_GPIO(GPIO_PTD2, PTD2_DATA),
1232 PINMUX_GPIO(GPIO_PTD1, PTD1_DATA),
1233 PINMUX_GPIO(GPIO_PTD0, PTD0_DATA),
1234
1235 /* PTE */
1236 PINMUX_GPIO(GPIO_PTE7, PTE7_DATA),
1237 PINMUX_GPIO(GPIO_PTE6, PTE6_DATA),
1238 PINMUX_GPIO(GPIO_PTE5, PTE5_DATA),
1239 PINMUX_GPIO(GPIO_PTE4, PTE4_DATA),
1240 PINMUX_GPIO(GPIO_PTE3, PTE3_DATA),
1241 PINMUX_GPIO(GPIO_PTE2, PTE2_DATA),
1242 PINMUX_GPIO(GPIO_PTE1, PTE1_DATA),
1243 PINMUX_GPIO(GPIO_PTE0, PTE0_DATA),
1244
1245 /* PTF */
1246 PINMUX_GPIO(GPIO_PTF7, PTF7_DATA),
1247 PINMUX_GPIO(GPIO_PTF6, PTF6_DATA),
1248 PINMUX_GPIO(GPIO_PTF5, PTF5_DATA),
1249 PINMUX_GPIO(GPIO_PTF4, PTF4_DATA),
1250 PINMUX_GPIO(GPIO_PTF3, PTF3_DATA),
1251 PINMUX_GPIO(GPIO_PTF2, PTF2_DATA),
1252 PINMUX_GPIO(GPIO_PTF1, PTF1_DATA),
1253 PINMUX_GPIO(GPIO_PTF0, PTF0_DATA),
1254
1255 /* PTG */
1256 PINMUX_GPIO(GPIO_PTG5, PTG5_DATA),
1257 PINMUX_GPIO(GPIO_PTG4, PTG4_DATA),
1258 PINMUX_GPIO(GPIO_PTG3, PTG3_DATA),
1259 PINMUX_GPIO(GPIO_PTG2, PTG2_DATA),
1260 PINMUX_GPIO(GPIO_PTG1, PTG1_DATA),
1261 PINMUX_GPIO(GPIO_PTG0, PTG0_DATA),
1262
1263 /* PTH */
1264 PINMUX_GPIO(GPIO_PTH7, PTH7_DATA),
1265 PINMUX_GPIO(GPIO_PTH6, PTH6_DATA),
1266 PINMUX_GPIO(GPIO_PTH5, PTH5_DATA),
1267 PINMUX_GPIO(GPIO_PTH4, PTH4_DATA),
1268 PINMUX_GPIO(GPIO_PTH3, PTH3_DATA),
1269 PINMUX_GPIO(GPIO_PTH2, PTH2_DATA),
1270 PINMUX_GPIO(GPIO_PTH1, PTH1_DATA),
1271 PINMUX_GPIO(GPIO_PTH0, PTH0_DATA),
1272
1273 /* PTJ */
1274 PINMUX_GPIO(GPIO_PTJ7, PTJ7_DATA),
1275 PINMUX_GPIO(GPIO_PTJ6, PTJ6_DATA),
1276 PINMUX_GPIO(GPIO_PTJ5, PTJ5_DATA),
1277 PINMUX_GPIO(GPIO_PTJ3, PTJ3_DATA),
1278 PINMUX_GPIO(GPIO_PTJ2, PTJ2_DATA),
1279 PINMUX_GPIO(GPIO_PTJ1, PTJ1_DATA),
1280 PINMUX_GPIO(GPIO_PTJ0, PTJ0_DATA),
1281
1282 /* PTK */
1283 PINMUX_GPIO(GPIO_PTK7, PTK7_DATA),
1284 PINMUX_GPIO(GPIO_PTK6, PTK6_DATA),
1285 PINMUX_GPIO(GPIO_PTK5, PTK5_DATA),
1286 PINMUX_GPIO(GPIO_PTK4, PTK4_DATA),
1287 PINMUX_GPIO(GPIO_PTK3, PTK3_DATA),
1288 PINMUX_GPIO(GPIO_PTK2, PTK2_DATA),
1289 PINMUX_GPIO(GPIO_PTK1, PTK1_DATA),
1290 PINMUX_GPIO(GPIO_PTK0, PTK0_DATA),
1291
1292 /* PTL */
1293 PINMUX_GPIO(GPIO_PTL7, PTL7_DATA),
1294 PINMUX_GPIO(GPIO_PTL6, PTL6_DATA),
1295 PINMUX_GPIO(GPIO_PTL5, PTL5_DATA),
1296 PINMUX_GPIO(GPIO_PTL4, PTL4_DATA),
1297 PINMUX_GPIO(GPIO_PTL3, PTL3_DATA),
1298 PINMUX_GPIO(GPIO_PTL2, PTL2_DATA),
1299 PINMUX_GPIO(GPIO_PTL1, PTL1_DATA),
1300 PINMUX_GPIO(GPIO_PTL0, PTL0_DATA),
1301
1302 /* PTM */
1303 PINMUX_GPIO(GPIO_PTM7, PTM7_DATA),
1304 PINMUX_GPIO(GPIO_PTM6, PTM6_DATA),
1305 PINMUX_GPIO(GPIO_PTM5, PTM5_DATA),
1306 PINMUX_GPIO(GPIO_PTM4, PTM4_DATA),
1307 PINMUX_GPIO(GPIO_PTM3, PTM3_DATA),
1308 PINMUX_GPIO(GPIO_PTM2, PTM2_DATA),
1309 PINMUX_GPIO(GPIO_PTM1, PTM1_DATA),
1310 PINMUX_GPIO(GPIO_PTM0, PTM0_DATA),
1311
1312 /* PTN */
1313 PINMUX_GPIO(GPIO_PTN7, PTN7_DATA),
1314 PINMUX_GPIO(GPIO_PTN6, PTN6_DATA),
1315 PINMUX_GPIO(GPIO_PTN5, PTN5_DATA),
1316 PINMUX_GPIO(GPIO_PTN4, PTN4_DATA),
1317 PINMUX_GPIO(GPIO_PTN3, PTN3_DATA),
1318 PINMUX_GPIO(GPIO_PTN2, PTN2_DATA),
1319 PINMUX_GPIO(GPIO_PTN1, PTN1_DATA),
1320 PINMUX_GPIO(GPIO_PTN0, PTN0_DATA),
1321
1322 /* PTQ */
1323 PINMUX_GPIO(GPIO_PTQ7, PTQ7_DATA),
1324 PINMUX_GPIO(GPIO_PTQ6, PTQ6_DATA),
1325 PINMUX_GPIO(GPIO_PTQ5, PTQ5_DATA),
1326 PINMUX_GPIO(GPIO_PTQ4, PTQ4_DATA),
1327 PINMUX_GPIO(GPIO_PTQ3, PTQ3_DATA),
1328 PINMUX_GPIO(GPIO_PTQ2, PTQ2_DATA),
1329 PINMUX_GPIO(GPIO_PTQ1, PTQ1_DATA),
1330 PINMUX_GPIO(GPIO_PTQ0, PTQ0_DATA),
1331
1332 /* PTR */
1333 PINMUX_GPIO(GPIO_PTR7, PTR7_DATA),
1334 PINMUX_GPIO(GPIO_PTR6, PTR6_DATA),
1335 PINMUX_GPIO(GPIO_PTR5, PTR5_DATA),
1336 PINMUX_GPIO(GPIO_PTR4, PTR4_DATA),
1337 PINMUX_GPIO(GPIO_PTR3, PTR3_DATA),
1338 PINMUX_GPIO(GPIO_PTR2, PTR2_DATA),
1339 PINMUX_GPIO(GPIO_PTR1, PTR1_DATA),
1340 PINMUX_GPIO(GPIO_PTR0, PTR0_DATA),
1341
1342 /* PTS */
1343 PINMUX_GPIO(GPIO_PTS6, PTS6_DATA),
1344 PINMUX_GPIO(GPIO_PTS5, PTS5_DATA),
1345 PINMUX_GPIO(GPIO_PTS4, PTS4_DATA),
1346 PINMUX_GPIO(GPIO_PTS3, PTS3_DATA),
1347 PINMUX_GPIO(GPIO_PTS2, PTS2_DATA),
1348 PINMUX_GPIO(GPIO_PTS1, PTS1_DATA),
1349 PINMUX_GPIO(GPIO_PTS0, PTS0_DATA),
1350
1351 /* PTT */
1352 PINMUX_GPIO(GPIO_PTT7, PTT7_DATA),
1353 PINMUX_GPIO(GPIO_PTT6, PTT6_DATA),
1354 PINMUX_GPIO(GPIO_PTT5, PTT5_DATA),
1355 PINMUX_GPIO(GPIO_PTT4, PTT4_DATA),
1356 PINMUX_GPIO(GPIO_PTT3, PTT3_DATA),
1357 PINMUX_GPIO(GPIO_PTT2, PTT2_DATA),
1358 PINMUX_GPIO(GPIO_PTT1, PTT1_DATA),
1359 PINMUX_GPIO(GPIO_PTT0, PTT0_DATA),
1360
1361 /* PTU */
1362 PINMUX_GPIO(GPIO_PTU7, PTU7_DATA),
1363 PINMUX_GPIO(GPIO_PTU6, PTU6_DATA),
1364 PINMUX_GPIO(GPIO_PTU5, PTU5_DATA),
1365 PINMUX_GPIO(GPIO_PTU4, PTU4_DATA),
1366 PINMUX_GPIO(GPIO_PTU3, PTU3_DATA),
1367 PINMUX_GPIO(GPIO_PTU2, PTU2_DATA),
1368 PINMUX_GPIO(GPIO_PTU1, PTU1_DATA),
1369 PINMUX_GPIO(GPIO_PTU0, PTU0_DATA),
1370
1371 /* PTV */
1372 PINMUX_GPIO(GPIO_PTV7, PTV7_DATA),
1373 PINMUX_GPIO(GPIO_PTV6, PTV6_DATA),
1374 PINMUX_GPIO(GPIO_PTV5, PTV5_DATA),
1375 PINMUX_GPIO(GPIO_PTV4, PTV4_DATA),
1376 PINMUX_GPIO(GPIO_PTV3, PTV3_DATA),
1377 PINMUX_GPIO(GPIO_PTV2, PTV2_DATA),
1378 PINMUX_GPIO(GPIO_PTV1, PTV1_DATA),
1379 PINMUX_GPIO(GPIO_PTV0, PTV0_DATA),
1380
1381 /* PTW */
1382 PINMUX_GPIO(GPIO_PTW7, PTW7_DATA),
1383 PINMUX_GPIO(GPIO_PTW6, PTW6_DATA),
1384 PINMUX_GPIO(GPIO_PTW5, PTW5_DATA),
1385 PINMUX_GPIO(GPIO_PTW4, PTW4_DATA),
1386 PINMUX_GPIO(GPIO_PTW3, PTW3_DATA),
1387 PINMUX_GPIO(GPIO_PTW2, PTW2_DATA),
1388 PINMUX_GPIO(GPIO_PTW1, PTW1_DATA),
1389 PINMUX_GPIO(GPIO_PTW0, PTW0_DATA),
1390
1391 /* PTX */
1392 PINMUX_GPIO(GPIO_PTX7, PTX7_DATA),
1393 PINMUX_GPIO(GPIO_PTX6, PTX6_DATA),
1394 PINMUX_GPIO(GPIO_PTX5, PTX5_DATA),
1395 PINMUX_GPIO(GPIO_PTX4, PTX4_DATA),
1396 PINMUX_GPIO(GPIO_PTX3, PTX3_DATA),
1397 PINMUX_GPIO(GPIO_PTX2, PTX2_DATA),
1398 PINMUX_GPIO(GPIO_PTX1, PTX1_DATA),
1399 PINMUX_GPIO(GPIO_PTX0, PTX0_DATA),
1400
1401 /* PTY */
1402 PINMUX_GPIO(GPIO_PTY7, PTY7_DATA),
1403 PINMUX_GPIO(GPIO_PTY6, PTY6_DATA),
1404 PINMUX_GPIO(GPIO_PTY5, PTY5_DATA),
1405 PINMUX_GPIO(GPIO_PTY4, PTY4_DATA),
1406 PINMUX_GPIO(GPIO_PTY3, PTY3_DATA),
1407 PINMUX_GPIO(GPIO_PTY2, PTY2_DATA),
1408 PINMUX_GPIO(GPIO_PTY1, PTY1_DATA),
1409 PINMUX_GPIO(GPIO_PTY0, PTY0_DATA),
1410
1411 /* PTZ */
1412 PINMUX_GPIO(GPIO_PTZ7, PTZ7_DATA),
1413 PINMUX_GPIO(GPIO_PTZ6, PTZ6_DATA),
1414 PINMUX_GPIO(GPIO_PTZ5, PTZ5_DATA),
1415 PINMUX_GPIO(GPIO_PTZ4, PTZ4_DATA),
1416 PINMUX_GPIO(GPIO_PTZ3, PTZ3_DATA),
1417 PINMUX_GPIO(GPIO_PTZ2, PTZ2_DATA),
1418 PINMUX_GPIO(GPIO_PTZ1, PTZ1_DATA),
1419 PINMUX_GPIO(GPIO_PTZ0, PTZ0_DATA),
1420
1421 /* BSC */
1422 PINMUX_GPIO(GPIO_FN_D31, D31_MARK),
1423 PINMUX_GPIO(GPIO_FN_D30, D30_MARK),
1424 PINMUX_GPIO(GPIO_FN_D29, D29_MARK),
1425 PINMUX_GPIO(GPIO_FN_D28, D28_MARK),
1426 PINMUX_GPIO(GPIO_FN_D27, D27_MARK),
1427 PINMUX_GPIO(GPIO_FN_D26, D26_MARK),
1428 PINMUX_GPIO(GPIO_FN_D25, D25_MARK),
1429 PINMUX_GPIO(GPIO_FN_D24, D24_MARK),
1430 PINMUX_GPIO(GPIO_FN_D23, D23_MARK),
1431 PINMUX_GPIO(GPIO_FN_D22, D22_MARK),
1432 PINMUX_GPIO(GPIO_FN_D21, D21_MARK),
1433 PINMUX_GPIO(GPIO_FN_D20, D20_MARK),
1434 PINMUX_GPIO(GPIO_FN_D19, D19_MARK),
1435 PINMUX_GPIO(GPIO_FN_D18, D18_MARK),
1436 PINMUX_GPIO(GPIO_FN_D17, D17_MARK),
1437 PINMUX_GPIO(GPIO_FN_D16, D16_MARK),
1438 PINMUX_GPIO(GPIO_FN_D15, D15_MARK),
1439 PINMUX_GPIO(GPIO_FN_D14, D14_MARK),
1440 PINMUX_GPIO(GPIO_FN_D13, D13_MARK),
1441 PINMUX_GPIO(GPIO_FN_D12, D12_MARK),
1442 PINMUX_GPIO(GPIO_FN_D11, D11_MARK),
1443 PINMUX_GPIO(GPIO_FN_D10, D10_MARK),
1444 PINMUX_GPIO(GPIO_FN_D9, D9_MARK),
1445 PINMUX_GPIO(GPIO_FN_D8, D8_MARK),
1446 PINMUX_GPIO(GPIO_FN_D7, D7_MARK),
1447 PINMUX_GPIO(GPIO_FN_D6, D6_MARK),
1448 PINMUX_GPIO(GPIO_FN_D5, D5_MARK),
1449 PINMUX_GPIO(GPIO_FN_D4, D4_MARK),
1450 PINMUX_GPIO(GPIO_FN_D3, D3_MARK),
1451 PINMUX_GPIO(GPIO_FN_D2, D2_MARK),
1452 PINMUX_GPIO(GPIO_FN_D1, D1_MARK),
1453 PINMUX_GPIO(GPIO_FN_D0, D0_MARK),
1454 PINMUX_GPIO(GPIO_FN_A25, A25_MARK),
1455 PINMUX_GPIO(GPIO_FN_A24, A24_MARK),
1456 PINMUX_GPIO(GPIO_FN_A23, A23_MARK),
1457 PINMUX_GPIO(GPIO_FN_A22, A22_MARK),
1458 PINMUX_GPIO(GPIO_FN_CS6B_CE1B, CS6B_CE1B_MARK),
1459 PINMUX_GPIO(GPIO_FN_CS6A_CE2B, CS6A_CE2B_MARK),
1460 PINMUX_GPIO(GPIO_FN_CS5B_CE1A, CS5B_CE1A_MARK),
1461 PINMUX_GPIO(GPIO_FN_CS5A_CE2A, CS5A_CE2A_MARK),
1462 PINMUX_GPIO(GPIO_FN_WE3_ICIOWR, WE3_ICIOWR_MARK),
1463 PINMUX_GPIO(GPIO_FN_WE2_ICIORD, WE2_ICIORD_MARK),
1464 PINMUX_GPIO(GPIO_FN_IOIS16, IOIS16_MARK),
1465 PINMUX_GPIO(GPIO_FN_WAIT, WAIT_MARK),
1466 PINMUX_GPIO(GPIO_FN_BS, BS_MARK),
1467
1468 /* KEYSC */
1469 PINMUX_GPIO(GPIO_FN_KEYOUT5_IN5, KEYOUT5_IN5_MARK),
1470 PINMUX_GPIO(GPIO_FN_KEYOUT4_IN6, KEYOUT4_IN6_MARK),
1471 PINMUX_GPIO(GPIO_FN_KEYIN4, KEYIN4_MARK),
1472 PINMUX_GPIO(GPIO_FN_KEYIN3, KEYIN3_MARK),
1473 PINMUX_GPIO(GPIO_FN_KEYIN2, KEYIN2_MARK),
1474 PINMUX_GPIO(GPIO_FN_KEYIN1, KEYIN1_MARK),
1475 PINMUX_GPIO(GPIO_FN_KEYIN0, KEYIN0_MARK),
1476 PINMUX_GPIO(GPIO_FN_KEYOUT3, KEYOUT3_MARK),
1477 PINMUX_GPIO(GPIO_FN_KEYOUT2, KEYOUT2_MARK),
1478 PINMUX_GPIO(GPIO_FN_KEYOUT1, KEYOUT1_MARK),
1479 PINMUX_GPIO(GPIO_FN_KEYOUT0, KEYOUT0_MARK),
1480
1481 /* ATAPI */
1482 PINMUX_GPIO(GPIO_FN_IDED15, IDED15_MARK),
1483 PINMUX_GPIO(GPIO_FN_IDED14, IDED14_MARK),
1484 PINMUX_GPIO(GPIO_FN_IDED13, IDED13_MARK),
1485 PINMUX_GPIO(GPIO_FN_IDED12, IDED12_MARK),
1486 PINMUX_GPIO(GPIO_FN_IDED11, IDED11_MARK),
1487 PINMUX_GPIO(GPIO_FN_IDED10, IDED10_MARK),
1488 PINMUX_GPIO(GPIO_FN_IDED9, IDED9_MARK),
1489 PINMUX_GPIO(GPIO_FN_IDED8, IDED8_MARK),
1490 PINMUX_GPIO(GPIO_FN_IDED7, IDED7_MARK),
1491 PINMUX_GPIO(GPIO_FN_IDED6, IDED6_MARK),
1492 PINMUX_GPIO(GPIO_FN_IDED5, IDED5_MARK),
1493 PINMUX_GPIO(GPIO_FN_IDED4, IDED4_MARK),
1494 PINMUX_GPIO(GPIO_FN_IDED3, IDED3_MARK),
1495 PINMUX_GPIO(GPIO_FN_IDED2, IDED2_MARK),
1496 PINMUX_GPIO(GPIO_FN_IDED1, IDED1_MARK),
1497 PINMUX_GPIO(GPIO_FN_IDED0, IDED0_MARK),
1498 PINMUX_GPIO(GPIO_FN_IDEA2, IDEA2_MARK),
1499 PINMUX_GPIO(GPIO_FN_IDEA1, IDEA1_MARK),
1500 PINMUX_GPIO(GPIO_FN_IDEA0, IDEA0_MARK),
1501 PINMUX_GPIO(GPIO_FN_IDEIOWR, IDEIOWR_MARK),
1502 PINMUX_GPIO(GPIO_FN_IODREQ, IODREQ_MARK),
1503 PINMUX_GPIO(GPIO_FN_IDECS0, IDECS0_MARK),
1504 PINMUX_GPIO(GPIO_FN_IDECS1, IDECS1_MARK),
1505 PINMUX_GPIO(GPIO_FN_IDEIORD, IDEIORD_MARK),
1506 PINMUX_GPIO(GPIO_FN_DIRECTION, DIRECTION_MARK),
1507 PINMUX_GPIO(GPIO_FN_EXBUF_ENB, EXBUF_ENB_MARK),
1508 PINMUX_GPIO(GPIO_FN_IDERST, IDERST_MARK),
1509 PINMUX_GPIO(GPIO_FN_IODACK, IODACK_MARK),
1510 PINMUX_GPIO(GPIO_FN_IDEINT, IDEINT_MARK),
1511 PINMUX_GPIO(GPIO_FN_IDEIORDY, IDEIORDY_MARK),
1512
1513 /* TPU */
1514 PINMUX_GPIO(GPIO_FN_TPUTO3, TPUTO3_MARK),
1515 PINMUX_GPIO(GPIO_FN_TPUTO2, TPUTO2_MARK),
1516 PINMUX_GPIO(GPIO_FN_TPUTO1, TPUTO1_MARK),
1517 PINMUX_GPIO(GPIO_FN_TPUTO0, TPUTO0_MARK),
1518 PINMUX_GPIO(GPIO_FN_TPUTI3, TPUTI3_MARK),
1519 PINMUX_GPIO(GPIO_FN_TPUTI2, TPUTI2_MARK),
1520
1521 /* LCDC */
1522 PINMUX_GPIO(GPIO_FN_LCDD23, LCDD23_MARK),
1523 PINMUX_GPIO(GPIO_FN_LCDD22, LCDD22_MARK),
1524 PINMUX_GPIO(GPIO_FN_LCDD21, LCDD21_MARK),
1525 PINMUX_GPIO(GPIO_FN_LCDD20, LCDD20_MARK),
1526 PINMUX_GPIO(GPIO_FN_LCDD19, LCDD19_MARK),
1527 PINMUX_GPIO(GPIO_FN_LCDD18, LCDD18_MARK),
1528 PINMUX_GPIO(GPIO_FN_LCDD17, LCDD17_MARK),
1529 PINMUX_GPIO(GPIO_FN_LCDD16, LCDD16_MARK),
1530 PINMUX_GPIO(GPIO_FN_LCDD15, LCDD15_MARK),
1531 PINMUX_GPIO(GPIO_FN_LCDD14, LCDD14_MARK),
1532 PINMUX_GPIO(GPIO_FN_LCDD13, LCDD13_MARK),
1533 PINMUX_GPIO(GPIO_FN_LCDD12, LCDD12_MARK),
1534 PINMUX_GPIO(GPIO_FN_LCDD11, LCDD11_MARK),
1535 PINMUX_GPIO(GPIO_FN_LCDD10, LCDD10_MARK),
1536 PINMUX_GPIO(GPIO_FN_LCDD9, LCDD9_MARK),
1537 PINMUX_GPIO(GPIO_FN_LCDD8, LCDD8_MARK),
1538 PINMUX_GPIO(GPIO_FN_LCDD7, LCDD7_MARK),
1539 PINMUX_GPIO(GPIO_FN_LCDD6, LCDD6_MARK),
1540 PINMUX_GPIO(GPIO_FN_LCDD5, LCDD5_MARK),
1541 PINMUX_GPIO(GPIO_FN_LCDD4, LCDD4_MARK),
1542 PINMUX_GPIO(GPIO_FN_LCDD3, LCDD3_MARK),
1543 PINMUX_GPIO(GPIO_FN_LCDD2, LCDD2_MARK),
1544 PINMUX_GPIO(GPIO_FN_LCDD1, LCDD1_MARK),
1545 PINMUX_GPIO(GPIO_FN_LCDD0, LCDD0_MARK),
1546 PINMUX_GPIO(GPIO_FN_LCDVSYN, LCDVSYN_MARK),
1547 PINMUX_GPIO(GPIO_FN_LCDDISP, LCDDISP_MARK),
1548 PINMUX_GPIO(GPIO_FN_LCDRS, LCDRS_MARK),
1549 PINMUX_GPIO(GPIO_FN_LCDHSYN, LCDHSYN_MARK),
1550 PINMUX_GPIO(GPIO_FN_LCDCS, LCDCS_MARK),
1551 PINMUX_GPIO(GPIO_FN_LCDDON, LCDDON_MARK),
1552 PINMUX_GPIO(GPIO_FN_LCDDCK, LCDDCK_MARK),
1553 PINMUX_GPIO(GPIO_FN_LCDWR, LCDWR_MARK),
1554 PINMUX_GPIO(GPIO_FN_LCDVEPWC, LCDVEPWC_MARK),
1555 PINMUX_GPIO(GPIO_FN_LCDVCPWC, LCDVCPWC_MARK),
1556 PINMUX_GPIO(GPIO_FN_LCDRD, LCDRD_MARK),
1557 PINMUX_GPIO(GPIO_FN_LCDLCLK, LCDLCLK_MARK),
1558
1559 /* SCIF0 */
1560 PINMUX_GPIO(GPIO_FN_SCIF0_TXD, SCIF0_TXD_MARK),
1561 PINMUX_GPIO(GPIO_FN_SCIF0_RXD, SCIF0_RXD_MARK),
1562 PINMUX_GPIO(GPIO_FN_SCIF0_SCK, SCIF0_SCK_MARK),
1563
1564 /* SCIF1 */
1565 PINMUX_GPIO(GPIO_FN_SCIF1_SCK, SCIF1_SCK_MARK),
1566 PINMUX_GPIO(GPIO_FN_SCIF1_RXD, SCIF1_RXD_MARK),
1567 PINMUX_GPIO(GPIO_FN_SCIF1_TXD, SCIF1_TXD_MARK),
1568
1569 /* SCIF2 */
1570 PINMUX_GPIO(GPIO_FN_SCIF2_L_TXD, SCIF2_L_TXD_MARK),
1571 PINMUX_GPIO(GPIO_FN_SCIF2_L_SCK, SCIF2_L_SCK_MARK),
1572 PINMUX_GPIO(GPIO_FN_SCIF2_L_RXD, SCIF2_L_RXD_MARK),
1573 PINMUX_GPIO(GPIO_FN_SCIF2_V_TXD, SCIF2_V_TXD_MARK),
1574 PINMUX_GPIO(GPIO_FN_SCIF2_V_SCK, SCIF2_V_SCK_MARK),
1575 PINMUX_GPIO(GPIO_FN_SCIF2_V_RXD, SCIF2_V_RXD_MARK),
1576
1577 /* SCIF3 */
1578 PINMUX_GPIO(GPIO_FN_SCIF3_V_SCK, SCIF3_V_SCK_MARK),
1579 PINMUX_GPIO(GPIO_FN_SCIF3_V_RXD, SCIF3_V_RXD_MARK),
1580 PINMUX_GPIO(GPIO_FN_SCIF3_V_TXD, SCIF3_V_TXD_MARK),
1581 PINMUX_GPIO(GPIO_FN_SCIF3_V_CTS, SCIF3_V_CTS_MARK),
1582 PINMUX_GPIO(GPIO_FN_SCIF3_V_RTS, SCIF3_V_RTS_MARK),
1583 PINMUX_GPIO(GPIO_FN_SCIF3_I_SCK, SCIF3_I_SCK_MARK),
1584 PINMUX_GPIO(GPIO_FN_SCIF3_I_RXD, SCIF3_I_RXD_MARK),
1585 PINMUX_GPIO(GPIO_FN_SCIF3_I_TXD, SCIF3_I_TXD_MARK),
1586 PINMUX_GPIO(GPIO_FN_SCIF3_I_CTS, SCIF3_I_CTS_MARK),
1587 PINMUX_GPIO(GPIO_FN_SCIF3_I_RTS, SCIF3_I_RTS_MARK),
1588
1589 /* SCIF4 */
1590 PINMUX_GPIO(GPIO_FN_SCIF4_SCK, SCIF4_SCK_MARK),
1591 PINMUX_GPIO(GPIO_FN_SCIF4_RXD, SCIF4_RXD_MARK),
1592 PINMUX_GPIO(GPIO_FN_SCIF4_TXD, SCIF4_TXD_MARK),
1593
1594 /* SCIF5 */
1595 PINMUX_GPIO(GPIO_FN_SCIF5_SCK, SCIF5_SCK_MARK),
1596 PINMUX_GPIO(GPIO_FN_SCIF5_RXD, SCIF5_RXD_MARK),
1597 PINMUX_GPIO(GPIO_FN_SCIF5_TXD, SCIF5_TXD_MARK),
1598
1599 /* FSI */
1600 PINMUX_GPIO(GPIO_FN_FSIMCKB, FSIMCKB_MARK),
1601 PINMUX_GPIO(GPIO_FN_FSIMCKA, FSIMCKA_MARK),
1602 PINMUX_GPIO(GPIO_FN_FSIOASD, FSIOASD_MARK),
1603 PINMUX_GPIO(GPIO_FN_FSIIABCK, FSIIABCK_MARK),
1604 PINMUX_GPIO(GPIO_FN_FSIIALRCK, FSIIALRCK_MARK),
1605 PINMUX_GPIO(GPIO_FN_FSIOABCK, FSIOABCK_MARK),
1606 PINMUX_GPIO(GPIO_FN_FSIOALRCK, FSIOALRCK_MARK),
1607 PINMUX_GPIO(GPIO_FN_CLKAUDIOAO, CLKAUDIOAO_MARK),
1608 PINMUX_GPIO(GPIO_FN_FSIIBSD, FSIIBSD_MARK),
1609 PINMUX_GPIO(GPIO_FN_FSIOBSD, FSIOBSD_MARK),
1610 PINMUX_GPIO(GPIO_FN_FSIIBBCK, FSIIBBCK_MARK),
1611 PINMUX_GPIO(GPIO_FN_FSIIBLRCK, FSIIBLRCK_MARK),
1612 PINMUX_GPIO(GPIO_FN_FSIOBBCK, FSIOBBCK_MARK),
1613 PINMUX_GPIO(GPIO_FN_FSIOBLRCK, FSIOBLRCK_MARK),
1614 PINMUX_GPIO(GPIO_FN_CLKAUDIOBO, CLKAUDIOBO_MARK),
1615 PINMUX_GPIO(GPIO_FN_FSIIASD, FSIIASD_MARK),
1616
1617 /* AUD */
1618 PINMUX_GPIO(GPIO_FN_AUDCK, AUDCK_MARK),
1619 PINMUX_GPIO(GPIO_FN_AUDSYNC, AUDSYNC_MARK),
1620 PINMUX_GPIO(GPIO_FN_AUDATA3, AUDATA3_MARK),
1621 PINMUX_GPIO(GPIO_FN_AUDATA2, AUDATA2_MARK),
1622 PINMUX_GPIO(GPIO_FN_AUDATA1, AUDATA1_MARK),
1623 PINMUX_GPIO(GPIO_FN_AUDATA0, AUDATA0_MARK),
1624
1625 /* VIO */
1626 PINMUX_GPIO(GPIO_FN_VIO_CKO, VIO_CKO_MARK),
1627
1628 /* VIO0 */
1629 PINMUX_GPIO(GPIO_FN_VIO0_D15, VIO0_D15_MARK),
1630 PINMUX_GPIO(GPIO_FN_VIO0_D14, VIO0_D14_MARK),
1631 PINMUX_GPIO(GPIO_FN_VIO0_D13, VIO0_D13_MARK),
1632 PINMUX_GPIO(GPIO_FN_VIO0_D12, VIO0_D12_MARK),
1633 PINMUX_GPIO(GPIO_FN_VIO0_D11, VIO0_D11_MARK),
1634 PINMUX_GPIO(GPIO_FN_VIO0_D10, VIO0_D10_MARK),
1635 PINMUX_GPIO(GPIO_FN_VIO0_D9, VIO0_D9_MARK),
1636 PINMUX_GPIO(GPIO_FN_VIO0_D8, VIO0_D8_MARK),
1637 PINMUX_GPIO(GPIO_FN_VIO0_D7, VIO0_D7_MARK),
1638 PINMUX_GPIO(GPIO_FN_VIO0_D6, VIO0_D6_MARK),
1639 PINMUX_GPIO(GPIO_FN_VIO0_D5, VIO0_D5_MARK),
1640 PINMUX_GPIO(GPIO_FN_VIO0_D4, VIO0_D4_MARK),
1641 PINMUX_GPIO(GPIO_FN_VIO0_D3, VIO0_D3_MARK),
1642 PINMUX_GPIO(GPIO_FN_VIO0_D2, VIO0_D2_MARK),
1643 PINMUX_GPIO(GPIO_FN_VIO0_D1, VIO0_D1_MARK),
1644 PINMUX_GPIO(GPIO_FN_VIO0_D0, VIO0_D0_MARK),
1645 PINMUX_GPIO(GPIO_FN_VIO0_VD, VIO0_VD_MARK),
1646 PINMUX_GPIO(GPIO_FN_VIO0_CLK, VIO0_CLK_MARK),
1647 PINMUX_GPIO(GPIO_FN_VIO0_FLD, VIO0_FLD_MARK),
1648 PINMUX_GPIO(GPIO_FN_VIO0_HD, VIO0_HD_MARK),
1649
1650 /* VIO1 */
1651 PINMUX_GPIO(GPIO_FN_VIO1_D7, VIO1_D7_MARK),
1652 PINMUX_GPIO(GPIO_FN_VIO1_D6, VIO1_D6_MARK),
1653 PINMUX_GPIO(GPIO_FN_VIO1_D5, VIO1_D5_MARK),
1654 PINMUX_GPIO(GPIO_FN_VIO1_D4, VIO1_D4_MARK),
1655 PINMUX_GPIO(GPIO_FN_VIO1_D3, VIO1_D3_MARK),
1656 PINMUX_GPIO(GPIO_FN_VIO1_D2, VIO1_D2_MARK),
1657 PINMUX_GPIO(GPIO_FN_VIO1_D1, VIO1_D1_MARK),
1658 PINMUX_GPIO(GPIO_FN_VIO1_D0, VIO1_D0_MARK),
1659 PINMUX_GPIO(GPIO_FN_VIO1_FLD, VIO1_FLD_MARK),
1660 PINMUX_GPIO(GPIO_FN_VIO1_HD, VIO1_HD_MARK),
1661 PINMUX_GPIO(GPIO_FN_VIO1_VD, VIO1_VD_MARK),
1662 PINMUX_GPIO(GPIO_FN_VIO1_CLK, VIO1_CLK_MARK),
1663
1664 /* Eth */
1665 PINMUX_GPIO(GPIO_FN_RMII_RXD0, RMII_RXD0_MARK),
1666 PINMUX_GPIO(GPIO_FN_RMII_RXD1, RMII_RXD1_MARK),
1667 PINMUX_GPIO(GPIO_FN_RMII_TXD0, RMII_TXD0_MARK),
1668 PINMUX_GPIO(GPIO_FN_RMII_TXD1, RMII_TXD1_MARK),
1669 PINMUX_GPIO(GPIO_FN_RMII_REF_CLK, RMII_REF_CLK_MARK),
1670 PINMUX_GPIO(GPIO_FN_RMII_TX_EN, RMII_TX_EN_MARK),
1671 PINMUX_GPIO(GPIO_FN_RMII_RX_ER, RMII_RX_ER_MARK),
1672 PINMUX_GPIO(GPIO_FN_RMII_CRS_DV, RMII_CRS_DV_MARK),
1673 PINMUX_GPIO(GPIO_FN_LNKSTA, LNKSTA_MARK),
1674 PINMUX_GPIO(GPIO_FN_MDIO, MDIO_MARK),
1675 PINMUX_GPIO(GPIO_FN_MDC, MDC_MARK),
1676
1677 /* System */
1678 PINMUX_GPIO(GPIO_FN_PDSTATUS, PDSTATUS_MARK),
1679 PINMUX_GPIO(GPIO_FN_STATUS2, STATUS2_MARK),
1680 PINMUX_GPIO(GPIO_FN_STATUS0, STATUS0_MARK),
1681
1682 /* VOU */
1683 PINMUX_GPIO(GPIO_FN_DV_D15, DV_D15_MARK),
1684 PINMUX_GPIO(GPIO_FN_DV_D14, DV_D14_MARK),
1685 PINMUX_GPIO(GPIO_FN_DV_D13, DV_D13_MARK),
1686 PINMUX_GPIO(GPIO_FN_DV_D12, DV_D12_MARK),
1687 PINMUX_GPIO(GPIO_FN_DV_D11, DV_D11_MARK),
1688 PINMUX_GPIO(GPIO_FN_DV_D10, DV_D10_MARK),
1689 PINMUX_GPIO(GPIO_FN_DV_D9, DV_D9_MARK),
1690 PINMUX_GPIO(GPIO_FN_DV_D8, DV_D8_MARK),
1691 PINMUX_GPIO(GPIO_FN_DV_D7, DV_D7_MARK),
1692 PINMUX_GPIO(GPIO_FN_DV_D6, DV_D6_MARK),
1693 PINMUX_GPIO(GPIO_FN_DV_D5, DV_D5_MARK),
1694 PINMUX_GPIO(GPIO_FN_DV_D4, DV_D4_MARK),
1695 PINMUX_GPIO(GPIO_FN_DV_D3, DV_D3_MARK),
1696 PINMUX_GPIO(GPIO_FN_DV_D2, DV_D2_MARK),
1697 PINMUX_GPIO(GPIO_FN_DV_D1, DV_D1_MARK),
1698 PINMUX_GPIO(GPIO_FN_DV_D0, DV_D0_MARK),
1699 PINMUX_GPIO(GPIO_FN_DV_CLKI, DV_CLKI_MARK),
1700 PINMUX_GPIO(GPIO_FN_DV_CLK, DV_CLK_MARK),
1701 PINMUX_GPIO(GPIO_FN_DV_VSYNC, DV_VSYNC_MARK),
1702 PINMUX_GPIO(GPIO_FN_DV_HSYNC, DV_HSYNC_MARK),
1703
1704 /* MSIOF0 */
1705 PINMUX_GPIO(GPIO_FN_MSIOF0_RXD, MSIOF0_RXD_MARK),
1706 PINMUX_GPIO(GPIO_FN_MSIOF0_TXD, MSIOF0_TXD_MARK),
1707 PINMUX_GPIO(GPIO_FN_MSIOF0_MCK, MSIOF0_MCK_MARK),
1708 PINMUX_GPIO(GPIO_FN_MSIOF0_TSCK, MSIOF0_TSCK_MARK),
1709 PINMUX_GPIO(GPIO_FN_MSIOF0_SS1, MSIOF0_SS1_MARK),
1710 PINMUX_GPIO(GPIO_FN_MSIOF0_SS2, MSIOF0_SS2_MARK),
1711 PINMUX_GPIO(GPIO_FN_MSIOF0_TSYNC, MSIOF0_TSYNC_MARK),
1712 PINMUX_GPIO(GPIO_FN_MSIOF0_RSCK, MSIOF0_RSCK_MARK),
1713 PINMUX_GPIO(GPIO_FN_MSIOF0_RSYNC, MSIOF0_RSYNC_MARK),
1714
1715 /* MSIOF1 */
1716 PINMUX_GPIO(GPIO_FN_MSIOF1_RXD, MSIOF1_RXD_MARK),
1717 PINMUX_GPIO(GPIO_FN_MSIOF1_TXD, MSIOF1_TXD_MARK),
1718 PINMUX_GPIO(GPIO_FN_MSIOF1_MCK, MSIOF1_MCK_MARK),
1719 PINMUX_GPIO(GPIO_FN_MSIOF1_TSCK, MSIOF1_TSCK_MARK),
1720 PINMUX_GPIO(GPIO_FN_MSIOF1_SS1, MSIOF1_SS1_MARK),
1721 PINMUX_GPIO(GPIO_FN_MSIOF1_SS2, MSIOF1_SS2_MARK),
1722 PINMUX_GPIO(GPIO_FN_MSIOF1_TSYNC, MSIOF1_TSYNC_MARK),
1723 PINMUX_GPIO(GPIO_FN_MSIOF1_RSCK, MSIOF1_RSCK_MARK),
1724 PINMUX_GPIO(GPIO_FN_MSIOF1_RSYNC, MSIOF1_RSYNC_MARK),
1725
1726 /* DMAC */
1727 PINMUX_GPIO(GPIO_FN_DMAC_DACK0, DMAC_DACK0_MARK),
1728 PINMUX_GPIO(GPIO_FN_DMAC_DREQ0, DMAC_DREQ0_MARK),
1729 PINMUX_GPIO(GPIO_FN_DMAC_DACK1, DMAC_DACK1_MARK),
1730 PINMUX_GPIO(GPIO_FN_DMAC_DREQ1, DMAC_DREQ1_MARK),
1731
1732 /* SDHI0 */
1733 PINMUX_GPIO(GPIO_FN_SDHI0CD, SDHI0CD_MARK),
1734 PINMUX_GPIO(GPIO_FN_SDHI0WP, SDHI0WP_MARK),
1735 PINMUX_GPIO(GPIO_FN_SDHI0CMD, SDHI0CMD_MARK),
1736 PINMUX_GPIO(GPIO_FN_SDHI0CLK, SDHI0CLK_MARK),
1737 PINMUX_GPIO(GPIO_FN_SDHI0D3, SDHI0D3_MARK),
1738 PINMUX_GPIO(GPIO_FN_SDHI0D2, SDHI0D2_MARK),
1739 PINMUX_GPIO(GPIO_FN_SDHI0D1, SDHI0D1_MARK),
1740 PINMUX_GPIO(GPIO_FN_SDHI0D0, SDHI0D0_MARK),
1741
1742 /* SDHI1 */
1743 PINMUX_GPIO(GPIO_FN_SDHI1CD, SDHI1CD_MARK),
1744 PINMUX_GPIO(GPIO_FN_SDHI1WP, SDHI1WP_MARK),
1745 PINMUX_GPIO(GPIO_FN_SDHI1CMD, SDHI1CMD_MARK),
1746 PINMUX_GPIO(GPIO_FN_SDHI1CLK, SDHI1CLK_MARK),
1747 PINMUX_GPIO(GPIO_FN_SDHI1D3, SDHI1D3_MARK),
1748 PINMUX_GPIO(GPIO_FN_SDHI1D2, SDHI1D2_MARK),
1749 PINMUX_GPIO(GPIO_FN_SDHI1D1, SDHI1D1_MARK),
1750 PINMUX_GPIO(GPIO_FN_SDHI1D0, SDHI1D0_MARK),
1751
1752 /* MMC */
1753 PINMUX_GPIO(GPIO_FN_MMC_D7, MMC_D7_MARK),
1754 PINMUX_GPIO(GPIO_FN_MMC_D6, MMC_D6_MARK),
1755 PINMUX_GPIO(GPIO_FN_MMC_D5, MMC_D5_MARK),
1756 PINMUX_GPIO(GPIO_FN_MMC_D4, MMC_D4_MARK),
1757 PINMUX_GPIO(GPIO_FN_MMC_D3, MMC_D3_MARK),
1758 PINMUX_GPIO(GPIO_FN_MMC_D2, MMC_D2_MARK),
1759 PINMUX_GPIO(GPIO_FN_MMC_D1, MMC_D1_MARK),
1760 PINMUX_GPIO(GPIO_FN_MMC_D0, MMC_D0_MARK),
1761 PINMUX_GPIO(GPIO_FN_MMC_CLK, MMC_CLK_MARK),
1762 PINMUX_GPIO(GPIO_FN_MMC_CMD, MMC_CMD_MARK),
1763
1764 /* IrDA */
1765 PINMUX_GPIO(GPIO_FN_IRDA_OUT, IRDA_OUT_MARK),
1766 PINMUX_GPIO(GPIO_FN_IRDA_IN, IRDA_IN_MARK),
1767
1768 /* TSIF */
1769 PINMUX_GPIO(GPIO_FN_TSIF_TS0_SDAT, TSIF_TS0_SDAT_MARK),
1770 PINMUX_GPIO(GPIO_FN_TSIF_TS0_SCK, TSIF_TS0_SCK_MARK),
1771 PINMUX_GPIO(GPIO_FN_TSIF_TS0_SDEN, TSIF_TS0_SDEN_MARK),
1772 PINMUX_GPIO(GPIO_FN_TSIF_TS0_SPSYNC, TSIF_TS0_SPSYNC_MARK),
1773
1774 /* IRQ */
1775 PINMUX_GPIO(GPIO_FN_INTC_IRQ7, INTC_IRQ7_MARK),
1776 PINMUX_GPIO(GPIO_FN_INTC_IRQ6, INTC_IRQ6_MARK),
1777 PINMUX_GPIO(GPIO_FN_INTC_IRQ5, INTC_IRQ5_MARK),
1778 PINMUX_GPIO(GPIO_FN_INTC_IRQ4, INTC_IRQ4_MARK),
1779 PINMUX_GPIO(GPIO_FN_INTC_IRQ3, INTC_IRQ3_MARK),
1780 PINMUX_GPIO(GPIO_FN_INTC_IRQ2, INTC_IRQ2_MARK),
1781 PINMUX_GPIO(GPIO_FN_INTC_IRQ1, INTC_IRQ1_MARK),
1782 PINMUX_GPIO(GPIO_FN_INTC_IRQ0, INTC_IRQ0_MARK),
1783 };
1784
1785static struct pinmux_cfg_reg pinmux_config_regs[] = {
1786 { PINMUX_CFG_REG("PACR", 0xa4050100, 16, 2) {
1787 PTA7_FN, PTA7_OUT, PTA7_IN_PU, PTA7_IN,
1788 PTA6_FN, PTA6_OUT, PTA6_IN_PU, PTA6_IN,
1789 PTA5_FN, PTA5_OUT, PTA5_IN_PU, PTA5_IN,
1790 PTA4_FN, PTA4_OUT, PTA4_IN_PU, PTA4_IN,
1791 PTA3_FN, PTA3_OUT, PTA3_IN_PU, PTA3_IN,
1792 PTA2_FN, PTA2_OUT, PTA2_IN_PU, PTA2_IN,
1793 PTA1_FN, PTA1_OUT, PTA1_IN_PU, PTA1_IN,
1794 PTA0_FN, PTA0_OUT, PTA0_IN_PU, PTA0_IN }
1795 },
1796 { PINMUX_CFG_REG("PBCR", 0xa4050102, 16, 2) {
1797 PTB7_FN, PTB7_OUT, PTB7_IN_PU, PTB7_IN,
1798 PTB6_FN, PTB6_OUT, PTB6_IN_PU, PTB6_IN,
1799 PTB5_FN, PTB5_OUT, PTB5_IN_PU, PTB5_IN,
1800 PTB4_FN, PTB4_OUT, PTB4_IN_PU, PTB4_IN,
1801 PTB3_FN, PTB3_OUT, PTB3_IN_PU, PTB3_IN,
1802 PTB2_FN, PTB2_OUT, PTB2_IN_PU, PTB2_IN,
1803 PTB1_FN, PTB1_OUT, PTB1_IN_PU, PTB1_IN,
1804 PTB0_FN, PTB0_OUT, PTB0_IN_PU, PTB0_IN }
1805 },
1806 { PINMUX_CFG_REG("PCCR", 0xa4050104, 16, 2) {
1807 PTC7_FN, PTC7_OUT, PTC7_IN_PU, PTC7_IN,
1808 PTC6_FN, PTC6_OUT, PTC6_IN_PU, PTC6_IN,
1809 PTC5_FN, PTC5_OUT, PTC5_IN_PU, PTC5_IN,
1810 PTC4_FN, PTC4_OUT, PTC4_IN_PU, PTC4_IN,
1811 PTC3_FN, PTC3_OUT, PTC3_IN_PU, PTC3_IN,
1812 PTC2_FN, PTC2_OUT, PTC2_IN_PU, PTC2_IN,
1813 PTC1_FN, PTC1_OUT, PTC1_IN_PU, PTC1_IN,
1814 PTC0_FN, PTC0_OUT, PTC0_IN_PU, PTC0_IN }
1815 },
1816 { PINMUX_CFG_REG("PDCR", 0xa4050106, 16, 2) {
1817 PTD7_FN, PTD7_OUT, PTD7_IN_PU, PTD7_IN,
1818 PTD6_FN, PTD6_OUT, PTD6_IN_PU, PTD6_IN,
1819 PTD5_FN, PTD5_OUT, PTD5_IN_PU, PTD5_IN,
1820 PTD4_FN, PTD4_OUT, PTD4_IN_PU, PTD4_IN,
1821 PTD3_FN, PTD3_OUT, PTD3_IN_PU, PTD3_IN,
1822 PTD2_FN, PTD2_OUT, PTD2_IN_PU, PTD2_IN,
1823 PTD1_FN, PTD1_OUT, PTD1_IN_PU, PTD1_IN,
1824 PTD0_FN, PTD0_OUT, PTD0_IN_PU, PTD0_IN }
1825 },
1826 { PINMUX_CFG_REG("PECR", 0xa4050108, 16, 2) {
1827 PTE7_FN, PTE7_OUT, PTE7_IN_PU, PTE7_IN,
1828 PTE6_FN, PTE6_OUT, PTE6_IN_PU, PTE6_IN,
1829 PTE5_FN, PTE5_OUT, PTE5_IN_PU, PTE5_IN,
1830 PTE4_FN, PTE4_OUT, PTE4_IN_PU, PTE4_IN,
1831 PTE3_FN, PTE3_OUT, PTE3_IN_PU, PTE3_IN,
1832 PTE2_FN, PTE2_OUT, PTE2_IN_PU, PTE2_IN,
1833 PTE1_FN, PTE1_OUT, PTE1_IN_PU, PTE1_IN,
1834 PTE0_FN, PTE0_OUT, PTE0_IN_PU, PTE0_IN }
1835 },
1836 { PINMUX_CFG_REG("PFCR", 0xa405010a, 16, 2) {
1837 PTF7_FN, PTF7_OUT, PTF7_IN_PU, PTF7_IN,
1838 PTF6_FN, PTF6_OUT, PTF6_IN_PU, PTF6_IN,
1839 PTF5_FN, PTF5_OUT, PTF5_IN_PU, PTF5_IN,
1840 PTF4_FN, PTF4_OUT, PTF4_IN_PU, PTF4_IN,
1841 PTF3_FN, PTF3_OUT, PTF3_IN_PU, PTF3_IN,
1842 PTF2_FN, PTF2_OUT, PTF2_IN_PU, PTF2_IN,
1843 PTF1_FN, PTF1_OUT, PTF1_IN_PU, PTF1_IN,
1844 PTF0_FN, PTF0_OUT, PTF0_IN_PU, PTF0_IN }
1845 },
1846 { PINMUX_CFG_REG("PGCR", 0xa405010c, 16, 2) {
1847 0, 0, 0, 0,
1848 0, 0, 0, 0,
1849 PTG5_FN, PTG5_OUT, 0, 0,
1850 PTG4_FN, PTG4_OUT, 0, 0,
1851 PTG3_FN, PTG3_OUT, 0, 0,
1852 PTG2_FN, PTG2_OUT, 0, 0,
1853 PTG1_FN, PTG1_OUT, 0, 0,
1854 PTG0_FN, PTG0_OUT, 0, 0 }
1855 },
1856 { PINMUX_CFG_REG("PHCR", 0xa405010e, 16, 2) {
1857 PTH7_FN, PTH7_OUT, PTH7_IN_PU, PTH7_IN,
1858 PTH6_FN, PTH6_OUT, PTH6_IN_PU, PTH6_IN,
1859 PTH5_FN, PTH5_OUT, PTH5_IN_PU, PTH5_IN,
1860 PTH4_FN, PTH4_OUT, PTH4_IN_PU, PTH4_IN,
1861 PTH3_FN, PTH3_OUT, PTH3_IN_PU, PTH3_IN,
1862 PTH2_FN, PTH2_OUT, PTH2_IN_PU, PTH2_IN,
1863 PTH1_FN, PTH1_OUT, PTH1_IN_PU, PTH1_IN,
1864 PTH0_FN, PTH0_OUT, PTH0_IN_PU, PTH0_IN }
1865 },
1866 { PINMUX_CFG_REG("PJCR", 0xa4050110, 16, 2) {
1867 PTJ7_FN, PTJ7_OUT, 0, 0,
1868 PTJ6_FN, PTJ6_OUT, 0, 0,
1869 PTJ5_FN, PTJ5_OUT, 0, 0,
1870 0, 0, 0, 0,
1871 PTJ3_FN, PTJ3_OUT, PTJ3_IN_PU, PTJ3_IN,
1872 PTJ2_FN, PTJ2_OUT, PTJ2_IN_PU, PTJ2_IN,
1873 PTJ1_FN, PTJ1_OUT, PTJ1_IN_PU, PTJ1_IN,
1874 PTJ0_FN, PTJ0_OUT, PTJ0_IN_PU, PTJ0_IN }
1875 },
1876 { PINMUX_CFG_REG("PKCR", 0xa4050112, 16, 2) {
1877 PTK7_FN, PTK7_OUT, PTK7_IN_PU, PTK7_IN,
1878 PTK6_FN, PTK6_OUT, PTK6_IN_PU, PTK6_IN,
1879 PTK5_FN, PTK5_OUT, PTK5_IN_PU, PTK5_IN,
1880 PTK4_FN, PTK4_OUT, PTK4_IN_PU, PTK4_IN,
1881 PTK3_FN, PTK3_OUT, PTK3_IN_PU, PTK3_IN,
1882 PTK2_FN, PTK2_OUT, PTK2_IN_PU, PTK2_IN,
1883 PTK1_FN, PTK1_OUT, PTK1_IN_PU, PTK1_IN,
1884 PTK0_FN, PTK0_OUT, PTK0_IN_PU, PTK0_IN }
1885 },
1886 { PINMUX_CFG_REG("PLCR", 0xa4050114, 16, 2) {
1887 PTL7_FN, PTL7_OUT, PTL7_IN_PU, PTL7_IN,
1888 PTL6_FN, PTL6_OUT, PTL6_IN_PU, PTL6_IN,
1889 PTL5_FN, PTL5_OUT, PTL5_IN_PU, PTL5_IN,
1890 PTL4_FN, PTL4_OUT, PTL4_IN_PU, PTL4_IN,
1891 PTL3_FN, PTL3_OUT, PTL3_IN_PU, PTL3_IN,
1892 PTL2_FN, PTL2_OUT, PTL2_IN_PU, PTL2_IN,
1893 PTL1_FN, PTL1_OUT, PTL1_IN_PU, PTL1_IN,
1894 PTL0_FN, PTL0_OUT, PTL0_IN_PU, PTL0_IN }
1895 },
1896 { PINMUX_CFG_REG("PMCR", 0xa4050116, 16, 2) {
1897 PTM7_FN, PTM7_OUT, PTM7_IN_PU, PTM7_IN,
1898 PTM6_FN, PTM6_OUT, PTM6_IN_PU, PTM6_IN,
1899 PTM5_FN, PTM5_OUT, PTM5_IN_PU, PTM5_IN,
1900 PTM4_FN, PTM4_OUT, PTM4_IN_PU, PTM4_IN,
1901 PTM3_FN, PTM3_OUT, PTM3_IN_PU, PTM3_IN,
1902 PTM2_FN, PTM2_OUT, PTM2_IN_PU, PTM2_IN,
1903 PTM1_FN, PTM1_OUT, PTM1_IN_PU, PTM1_IN,
1904 PTM0_FN, PTM0_OUT, PTM0_IN_PU, PTM0_IN }
1905 },
1906 { PINMUX_CFG_REG("PNCR", 0xa4050118, 16, 2) {
1907 PTN7_FN, PTN7_OUT, PTN7_IN_PU, PTN7_IN,
1908 PTN6_FN, PTN6_OUT, PTN6_IN_PU, PTN6_IN,
1909 PTN5_FN, PTN5_OUT, PTN5_IN_PU, PTN5_IN,
1910 PTN4_FN, PTN4_OUT, PTN4_IN_PU, PTN4_IN,
1911 PTN3_FN, PTN3_OUT, PTN3_IN_PU, PTN3_IN,
1912 PTN2_FN, PTN2_OUT, PTN2_IN_PU, PTN2_IN,
1913 PTN1_FN, PTN1_OUT, PTN1_IN_PU, PTN1_IN,
1914 PTN0_FN, PTN0_OUT, PTN0_IN_PU, PTN0_IN }
1915 },
1916 { PINMUX_CFG_REG("PQCR", 0xa405011a, 16, 2) {
1917 PTQ7_FN, PTQ7_OUT, PTQ7_IN_PU, PTQ7_IN,
1918 PTQ6_FN, PTQ6_OUT, PTQ6_IN_PU, PTQ6_IN,
1919 PTQ5_FN, PTQ5_OUT, PTQ5_IN_PU, PTQ5_IN,
1920 PTQ4_FN, PTQ4_OUT, PTQ4_IN_PU, PTQ4_IN,
1921 PTQ3_FN, PTQ3_OUT, PTQ3_IN_PU, PTQ3_IN,
1922 PTQ2_FN, PTQ2_OUT, PTQ2_IN_PU, PTQ2_IN,
1923 PTQ1_FN, PTQ1_OUT, PTQ1_IN_PU, PTQ1_IN,
1924 PTQ0_FN, PTQ0_OUT, PTQ0_IN_PU, PTQ0_IN }
1925 },
1926 { PINMUX_CFG_REG("PRCR", 0xa405011c, 16, 2) {
1927 PTR7_FN, PTR7_OUT, PTR7_IN_PU, PTR7_IN,
1928 PTR6_FN, PTR6_OUT, PTR6_IN_PU, PTR6_IN,
1929 PTR5_FN, PTR5_OUT, PTR5_IN_PU, PTR5_IN,
1930 PTR4_FN, PTR4_OUT, PTR4_IN_PU, PTR4_IN,
1931 PTR3_FN, 0, PTR3_IN_PU, PTR3_IN,
1932 PTR2_FN, 0, PTR2_IN_PU, PTR2_IN,
1933 PTR1_FN, PTR1_OUT, PTR1_IN_PU, PTR1_IN,
1934 PTR0_FN, PTR0_OUT, PTR0_IN_PU, PTR0_IN }
1935 },
1936 { PINMUX_CFG_REG("PSCR", 0xa405011e, 16, 2) {
1937 0, 0, 0, 0,
1938 PTS6_FN, PTS6_OUT, PTS6_IN_PU, PTS6_IN,
1939 PTS5_FN, PTS5_OUT, PTS5_IN_PU, PTS5_IN,
1940 PTS4_FN, PTS4_OUT, PTS4_IN_PU, PTS4_IN,
1941 PTS3_FN, PTS3_OUT, PTS3_IN_PU, PTS3_IN,
1942 PTS2_FN, PTS2_OUT, PTS2_IN_PU, PTS2_IN,
1943 PTS1_FN, PTS1_OUT, PTS1_IN_PU, PTS1_IN,
1944 PTS0_FN, PTS0_OUT, PTS0_IN_PU, PTS0_IN }
1945 },
1946 { PINMUX_CFG_REG("PTCR", 0xa4050140, 16, 2) {
1947 PTT7_FN, PTT7_OUT, PTT7_IN_PU, PTT7_IN,
1948 PTT6_FN, PTT6_OUT, PTT6_IN_PU, PTT6_IN,
1949 PTT5_FN, PTT5_OUT, PTT5_IN_PU, PTT5_IN,
1950 PTT4_FN, PTT4_OUT, PTT4_IN_PU, PTT4_IN,
1951 PTT3_FN, PTT3_OUT, PTT3_IN_PU, PTT3_IN,
1952 PTT2_FN, PTT2_OUT, PTT2_IN_PU, PTT2_IN,
1953 PTT1_FN, PTT1_OUT, PTT1_IN_PU, PTT1_IN,
1954 PTT0_FN, PTT0_OUT, PTT0_IN_PU, PTT0_IN }
1955 },
1956 { PINMUX_CFG_REG("PUCR", 0xa4050142, 16, 2) {
1957 PTU7_FN, PTU7_OUT, PTU7_IN_PU, PTU7_IN,
1958 PTU6_FN, PTU6_OUT, PTU6_IN_PU, PTU6_IN,
1959 PTU5_FN, PTU5_OUT, PTU5_IN_PU, PTU5_IN,
1960 PTU4_FN, PTU4_OUT, PTU4_IN_PU, PTU4_IN,
1961 PTU3_FN, PTU3_OUT, PTU3_IN_PU, PTU3_IN,
1962 PTU2_FN, PTU2_OUT, PTU2_IN_PU, PTU2_IN,
1963 PTU1_FN, PTU1_OUT, PTU1_IN_PU, PTU1_IN,
1964 PTU0_FN, PTU0_OUT, PTU0_IN_PU, PTU0_IN }
1965 },
1966 { PINMUX_CFG_REG("PVCR", 0xa4050144, 16, 2) {
1967 PTV7_FN, PTV7_OUT, PTV7_IN_PU, PTV7_IN,
1968 PTV6_FN, PTV6_OUT, PTV6_IN_PU, PTV6_IN,
1969 PTV5_FN, PTV5_OUT, PTV5_IN_PU, PTV5_IN,
1970 PTV4_FN, PTV4_OUT, PTV4_IN_PU, PTV4_IN,
1971 PTV3_FN, PTV3_OUT, PTV3_IN_PU, PTV3_IN,
1972 PTV2_FN, PTV2_OUT, PTV2_IN_PU, PTV2_IN,
1973 PTV1_FN, PTV1_OUT, PTV1_IN_PU, PTV1_IN,
1974 PTV0_FN, PTV0_OUT, PTV0_IN_PU, PTV0_IN }
1975 },
1976 { PINMUX_CFG_REG("PWCR", 0xa4050146, 16, 2) {
1977 PTW7_FN, PTW7_OUT, PTW7_IN_PU, PTW7_IN,
1978 PTW6_FN, PTW6_OUT, PTW6_IN_PU, PTW6_IN,
1979 PTW5_FN, PTW5_OUT, PTW5_IN_PU, PTW5_IN,
1980 PTW4_FN, PTW4_OUT, PTW4_IN_PU, PTW4_IN,
1981 PTW3_FN, PTW3_OUT, PTW3_IN_PU, PTW3_IN,
1982 PTW2_FN, PTW2_OUT, PTW2_IN_PU, PTW2_IN,
1983 PTW1_FN, PTW1_OUT, PTW1_IN_PU, PTW1_IN,
1984 PTW0_FN, PTW0_OUT, PTW0_IN_PU, PTW0_IN }
1985 },
1986 { PINMUX_CFG_REG("PXCR", 0xa4050148, 16, 2) {
1987 PTX7_FN, PTX7_OUT, PTX7_IN_PU, PTX7_IN,
1988 PTX6_FN, PTX6_OUT, PTX6_IN_PU, PTX6_IN,
1989 PTX5_FN, PTX5_OUT, PTX5_IN_PU, PTX5_IN,
1990 PTX4_FN, PTX4_OUT, PTX4_IN_PU, PTX4_IN,
1991 PTX3_FN, PTX3_OUT, PTX3_IN_PU, PTX3_IN,
1992 PTX2_FN, PTX2_OUT, PTX2_IN_PU, PTX2_IN,
1993 PTX1_FN, PTX1_OUT, PTX1_IN_PU, PTX1_IN,
1994 PTX0_FN, PTX0_OUT, PTX0_IN_PU, PTX0_IN }
1995 },
1996 { PINMUX_CFG_REG("PYCR", 0xa405014a, 16, 2) {
1997 PTY7_FN, PTY7_OUT, PTY7_IN_PU, PTY7_IN,
1998 PTY6_FN, PTY6_OUT, PTY6_IN_PU, PTY6_IN,
1999 PTY5_FN, PTY5_OUT, PTY5_IN_PU, PTY5_IN,
2000 PTY4_FN, PTY4_OUT, PTY4_IN_PU, PTY4_IN,
2001 PTY3_FN, PTY3_OUT, PTY3_IN_PU, PTY3_IN,
2002 PTY2_FN, PTY2_OUT, PTY2_IN_PU, PTY2_IN,
2003 PTY1_FN, PTY1_OUT, PTY1_IN_PU, PTY1_IN,
2004 PTY0_FN, PTY0_OUT, PTY0_IN_PU, PTY0_IN }
2005 },
2006 { PINMUX_CFG_REG("PZCR", 0xa405014c, 16, 2) {
2007 PTZ7_FN, PTZ7_OUT, PTZ7_IN_PU, PTZ7_IN,
2008 PTZ6_FN, PTZ6_OUT, PTZ6_IN_PU, PTZ6_IN,
2009 PTZ5_FN, PTZ5_OUT, PTZ5_IN_PU, PTZ5_IN,
2010 PTZ4_FN, PTZ4_OUT, PTZ4_IN_PU, PTZ4_IN,
2011 PTZ3_FN, PTZ3_OUT, PTZ3_IN_PU, PTZ3_IN,
2012 PTZ2_FN, PTZ2_OUT, PTZ2_IN_PU, PTZ2_IN,
2013 PTZ1_FN, PTZ1_OUT, PTZ1_IN_PU, PTZ1_IN,
2014 PTZ0_FN, PTZ0_OUT, PTZ0_IN_PU, PTZ0_IN }
2015 },
2016 { PINMUX_CFG_REG("PSELA", 0xa405014e, 16, 1) {
2017 PSA15_0, PSA15_1,
2018 PSA14_0, PSA14_1,
2019 PSA13_0, PSA13_1,
2020 PSA12_0, PSA12_1,
2021 0, 0,
2022 PSA10_0, PSA10_1,
2023 PSA9_0, PSA9_1,
2024 PSA8_0, PSA8_1,
2025 PSA7_0, PSA7_1,
2026 PSA6_0, PSA6_1,
2027 PSA5_0, PSA5_1,
2028 0, 0,
2029 PSA3_0, PSA3_1,
2030 PSA2_0, PSA2_1,
2031 PSA1_0, PSA1_1,
2032 PSA0_0, PSA0_1}
2033 },
2034 { PINMUX_CFG_REG("PSELB", 0xa4050150, 16, 1) {
2035 0, 0,
2036 PSB14_0, PSB14_1,
2037 PSB13_0, PSB13_1,
2038 PSB12_0, PSB12_1,
2039 PSB11_0, PSB11_1,
2040 PSB10_0, PSB10_1,
2041 PSB9_0, PSB9_1,
2042 PSB8_0, PSB8_1,
2043 PSB7_0, PSB7_1,
2044 PSB6_0, PSB6_1,
2045 PSB5_0, PSB5_1,
2046 PSB4_0, PSB4_1,
2047 PSB3_0, PSB3_1,
2048 PSB2_0, PSB2_1,
2049 PSB1_0, PSB1_1,
2050 PSB0_0, PSB0_1}
2051 },
2052 { PINMUX_CFG_REG("PSELC", 0xa4050152, 16, 1) {
2053 PSC15_0, PSC15_1,
2054 PSC14_0, PSC14_1,
2055 PSC13_0, PSC13_1,
2056 PSC12_0, PSC12_1,
2057 PSC11_0, PSC11_1,
2058 PSC10_0, PSC10_1,
2059 PSC9_0, PSC9_1,
2060 PSC8_0, PSC8_1,
2061 PSC7_0, PSC7_1,
2062 PSC6_0, PSC6_1,
2063 PSC5_0, PSC5_1,
2064 PSC4_0, PSC4_1,
2065 0, 0,
2066 PSC2_0, PSC2_1,
2067 PSC1_0, PSC1_1,
2068 PSC0_0, PSC0_1}
2069 },
2070 { PINMUX_CFG_REG("PSELD", 0xa4050154, 16, 1) {
2071 PSD15_0, PSD15_1,
2072 PSD14_0, PSD14_1,
2073 PSD13_0, PSD13_1,
2074 PSD12_0, PSD12_1,
2075 PSD11_0, PSD11_1,
2076 PSD10_0, PSD10_1,
2077 PSD9_0, PSD9_1,
2078 PSD8_0, PSD8_1,
2079 PSD7_0, PSD7_1,
2080 PSD6_0, PSD6_1,
2081 PSD5_0, PSD5_1,
2082 PSD4_0, PSD4_1,
2083 PSD3_0, PSD3_1,
2084 PSD2_0, PSD2_1,
2085 PSD1_0, PSD1_1,
2086 PSD0_0, PSD0_1}
2087 },
2088 { PINMUX_CFG_REG("PSELE", 0xa4050156, 16, 1) {
2089 PSE15_0, PSE15_1,
2090 PSE14_0, PSE14_1,
2091 PSE13_0, PSE13_1,
2092 PSE12_0, PSE12_1,
2093 PSE11_0, PSE11_1,
2094 PSE10_0, PSE10_1,
2095 PSE9_0, PSE9_1,
2096 PSE8_0, PSE8_1,
2097 PSE7_0, PSE7_1,
2098 PSE6_0, PSE6_1,
2099 PSE5_0, PSE5_1,
2100 PSE4_0, PSE4_1,
2101 PSE3_0, PSE3_1,
2102 PSE2_0, PSE2_1,
2103 PSE1_0, PSE1_1,
2104 PSE0_0, PSE0_1}
2105 },
2106 {}
2107};
2108
2109static struct pinmux_data_reg pinmux_data_regs[] = {
2110 { PINMUX_DATA_REG("PADR", 0xa4050120, 8) {
2111 PTA7_DATA, PTA6_DATA, PTA5_DATA, PTA4_DATA,
2112 PTA3_DATA, PTA2_DATA, PTA1_DATA, PTA0_DATA }
2113 },
2114 { PINMUX_DATA_REG("PBDR", 0xa4050122, 8) {
2115 PTB7_DATA, PTB6_DATA, PTB5_DATA, PTB4_DATA,
2116 PTB3_DATA, PTB2_DATA, PTB1_DATA, PTB0_DATA }
2117 },
2118 { PINMUX_DATA_REG("PCDR", 0xa4050124, 8) {
2119 PTC7_DATA, PTC6_DATA, PTC5_DATA, PTC4_DATA,
2120 PTC3_DATA, PTC2_DATA, PTC1_DATA, PTC0_DATA }
2121 },
2122 { PINMUX_DATA_REG("PDDR", 0xa4050126, 8) {
2123 PTD7_DATA, PTD6_DATA, PTD5_DATA, PTD4_DATA,
2124 PTD3_DATA, PTD2_DATA, PTD1_DATA, PTD0_DATA }
2125 },
2126 { PINMUX_DATA_REG("PEDR", 0xa4050128, 8) {
2127 PTE7_DATA, PTE6_DATA, PTE5_DATA, PTE4_DATA,
2128 PTE3_DATA, PTE2_DATA, PTE1_DATA, PTE0_DATA }
2129 },
2130 { PINMUX_DATA_REG("PFDR", 0xa405012a, 8) {
2131 PTF7_DATA, PTF6_DATA, PTF5_DATA, PTF4_DATA,
2132 PTF3_DATA, PTF2_DATA, PTF1_DATA, PTF0_DATA }
2133 },
2134 { PINMUX_DATA_REG("PGDR", 0xa405012c, 8) {
2135 0, 0, PTG5_DATA, PTG4_DATA,
2136 PTG3_DATA, PTG2_DATA, PTG1_DATA, PTG0_DATA }
2137 },
2138 { PINMUX_DATA_REG("PHDR", 0xa405012e, 8) {
2139 PTH7_DATA, PTH6_DATA, PTH5_DATA, PTH4_DATA,
2140 PTH3_DATA, PTH2_DATA, PTH1_DATA, PTH0_DATA }
2141 },
2142 { PINMUX_DATA_REG("PJDR", 0xa4050130, 8) {
2143 PTJ7_DATA, PTJ6_DATA, PTJ5_DATA, 0,
2144 PTJ3_DATA, PTJ2_DATA, PTJ1_DATA, PTJ0_DATA }
2145 },
2146 { PINMUX_DATA_REG("PKDR", 0xa4050132, 8) {
2147 PTK7_DATA, PTK6_DATA, PTK5_DATA, PTK4_DATA,
2148 PTK3_DATA, PTK2_DATA, PTK1_DATA, PTK0_DATA }
2149 },
2150 { PINMUX_DATA_REG("PLDR", 0xa4050134, 8) {
2151 PTL7_DATA, PTL6_DATA, PTL5_DATA, PTL4_DATA,
2152 PTL3_DATA, PTL2_DATA, PTL1_DATA, PTL0_DATA }
2153 },
2154 { PINMUX_DATA_REG("PMDR", 0xa4050136, 8) {
2155 PTM7_DATA, PTM6_DATA, PTM5_DATA, PTM4_DATA,
2156 PTM3_DATA, PTM2_DATA, PTM1_DATA, PTM0_DATA }
2157 },
2158 { PINMUX_DATA_REG("PNDR", 0xa4050138, 8) {
2159 PTN7_DATA, PTN6_DATA, PTN5_DATA, PTN4_DATA,
2160 PTN3_DATA, PTN2_DATA, PTN1_DATA, PTN0_DATA }
2161 },
2162 { PINMUX_DATA_REG("PQDR", 0xa405013a, 8) {
2163 PTQ7_DATA, PTQ6_DATA, PTQ5_DATA, PTQ4_DATA,
2164 PTQ3_DATA, PTQ2_DATA, PTQ1_DATA, PTQ0_DATA }
2165 },
2166 { PINMUX_DATA_REG("PRDR", 0xa405013c, 8) {
2167 PTR7_DATA, PTR6_DATA, PTR5_DATA, PTR4_DATA,
2168 PTR3_DATA, PTR2_DATA, PTR1_DATA, PTR0_DATA }
2169 },
2170 { PINMUX_DATA_REG("PSDR", 0xa405013e, 8) {
2171 0, PTS6_DATA, PTS5_DATA, PTS4_DATA,
2172 PTS3_DATA, PTS2_DATA, PTS1_DATA, PTS0_DATA }
2173 },
2174 { PINMUX_DATA_REG("PTDR", 0xa4050160, 8) {
2175 PTT7_DATA, PTT6_DATA, PTT5_DATA, PTT4_DATA,
2176 PTT3_DATA, PTT2_DATA, PTT1_DATA, PTT0_DATA }
2177 },
2178 { PINMUX_DATA_REG("PUDR", 0xa4050162, 8) {
2179 PTU7_DATA, PTU6_DATA, PTU5_DATA, PTU4_DATA,
2180 PTU3_DATA, PTU2_DATA, PTU1_DATA, PTU0_DATA }
2181 },
2182 { PINMUX_DATA_REG("PVDR", 0xa4050164, 8) {
2183 PTV7_DATA, PTV6_DATA, PTV5_DATA, PTV4_DATA,
2184 PTV3_DATA, PTV2_DATA, PTV1_DATA, PTV0_DATA }
2185 },
2186 { PINMUX_DATA_REG("PWDR", 0xa4050166, 8) {
2187 PTW7_DATA, PTW6_DATA, PTW5_DATA, PTW4_DATA,
2188 PTW3_DATA, PTW2_DATA, PTW1_DATA, PTW0_DATA }
2189 },
2190 { PINMUX_DATA_REG("PXDR", 0xa4050168, 8) {
2191 PTX7_DATA, PTX6_DATA, PTX5_DATA, PTX4_DATA,
2192 PTX3_DATA, PTX2_DATA, PTX1_DATA, PTX0_DATA }
2193 },
2194 { PINMUX_DATA_REG("PYDR", 0xa405016a, 8) {
2195 PTY7_DATA, PTY6_DATA, PTY5_DATA, PTY4_DATA,
2196 PTY3_DATA, PTY2_DATA, PTY1_DATA, PTY0_DATA }
2197 },
2198 { PINMUX_DATA_REG("PZDR", 0xa405016c, 8) {
2199 PTZ7_DATA, PTZ6_DATA, PTZ5_DATA, PTZ4_DATA,
2200 PTZ3_DATA, PTZ2_DATA, PTZ1_DATA, PTZ0_DATA }
2201 },
2202 { },
2203};
2204
2205static struct pinmux_info sh7724_pinmux_info = {
2206 .name = "sh7724_pfc",
2207 .reserved_id = PINMUX_RESERVED,
2208 .data = { PINMUX_DATA_BEGIN, PINMUX_DATA_END },
2209 .input = { PINMUX_INPUT_BEGIN, PINMUX_INPUT_END },
2210 .input_pu = { PINMUX_INPUT_PULLUP_BEGIN, PINMUX_INPUT_PULLUP_END },
2211 .output = { PINMUX_OUTPUT_BEGIN, PINMUX_OUTPUT_END },
2212 .mark = { PINMUX_MARK_BEGIN, PINMUX_MARK_END },
2213 .function = { PINMUX_FUNCTION_BEGIN, PINMUX_FUNCTION_END },
2214
2215 .first_gpio = GPIO_PTA7,
2216 .last_gpio = GPIO_FN_INTC_IRQ0,
2217
2218 .gpios = pinmux_gpios,
2219 .cfg_regs = pinmux_config_regs,
2220 .data_regs = pinmux_data_regs,
2221
2222 .gpio_data = pinmux_data,
2223 .gpio_data_size = ARRAY_SIZE(pinmux_data),
2224};
2225
2226static int __init plat_pinmux_setup(void)
2227{
2228 return register_pinmux(&sh7724_pinmux_info);
2229}
2230arch_initcall(plat_pinmux_setup);
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7343.c b/arch/sh/kernel/cpu/sh4a/setup-sh7343.c
index c1549382c87c..6307e087c864 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7343.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7343.c
@@ -12,7 +12,7 @@
12#include <linux/serial.h> 12#include <linux/serial.h>
13#include <linux/serial_sci.h> 13#include <linux/serial_sci.h>
14#include <linux/uio_driver.h> 14#include <linux/uio_driver.h>
15#include <linux/sh_cmt.h> 15#include <linux/sh_timer.h>
16#include <asm/clock.h> 16#include <asm/clock.h>
17 17
18static struct resource iic0_resources[] = { 18static struct resource iic0_resources[] = {
@@ -141,7 +141,7 @@ static struct platform_device jpu_device = {
141 .num_resources = ARRAY_SIZE(jpu_resources), 141 .num_resources = ARRAY_SIZE(jpu_resources),
142}; 142};
143 143
144static struct sh_cmt_config cmt_platform_data = { 144static struct sh_timer_config cmt_platform_data = {
145 .name = "CMT", 145 .name = "CMT",
146 .channel_offset = 0x60, 146 .channel_offset = 0x60,
147 .timer_bit = 5, 147 .timer_bit = 5,
@@ -173,27 +173,123 @@ static struct platform_device cmt_device = {
173 .num_resources = ARRAY_SIZE(cmt_resources), 173 .num_resources = ARRAY_SIZE(cmt_resources),
174}; 174};
175 175
176static struct sh_timer_config tmu0_platform_data = {
177 .name = "TMU0",
178 .channel_offset = 0x04,
179 .timer_bit = 0,
180 .clk = "tmu0",
181 .clockevent_rating = 200,
182};
183
184static struct resource tmu0_resources[] = {
185 [0] = {
186 .name = "TMU0",
187 .start = 0xffd80008,
188 .end = 0xffd80013,
189 .flags = IORESOURCE_MEM,
190 },
191 [1] = {
192 .start = 16,
193 .flags = IORESOURCE_IRQ,
194 },
195};
196
197static struct platform_device tmu0_device = {
198 .name = "sh_tmu",
199 .id = 0,
200 .dev = {
201 .platform_data = &tmu0_platform_data,
202 },
203 .resource = tmu0_resources,
204 .num_resources = ARRAY_SIZE(tmu0_resources),
205};
206
207static struct sh_timer_config tmu1_platform_data = {
208 .name = "TMU1",
209 .channel_offset = 0x10,
210 .timer_bit = 1,
211 .clk = "tmu0",
212 .clocksource_rating = 200,
213};
214
215static struct resource tmu1_resources[] = {
216 [0] = {
217 .name = "TMU1",
218 .start = 0xffd80014,
219 .end = 0xffd8001f,
220 .flags = IORESOURCE_MEM,
221 },
222 [1] = {
223 .start = 17,
224 .flags = IORESOURCE_IRQ,
225 },
226};
227
228static struct platform_device tmu1_device = {
229 .name = "sh_tmu",
230 .id = 1,
231 .dev = {
232 .platform_data = &tmu1_platform_data,
233 },
234 .resource = tmu1_resources,
235 .num_resources = ARRAY_SIZE(tmu1_resources),
236};
237
238static struct sh_timer_config tmu2_platform_data = {
239 .name = "TMU2",
240 .channel_offset = 0x1c,
241 .timer_bit = 2,
242 .clk = "tmu0",
243};
244
245static struct resource tmu2_resources[] = {
246 [0] = {
247 .name = "TMU2",
248 .start = 0xffd80020,
249 .end = 0xffd8002b,
250 .flags = IORESOURCE_MEM,
251 },
252 [1] = {
253 .start = 18,
254 .flags = IORESOURCE_IRQ,
255 },
256};
257
258static struct platform_device tmu2_device = {
259 .name = "sh_tmu",
260 .id = 2,
261 .dev = {
262 .platform_data = &tmu2_platform_data,
263 },
264 .resource = tmu2_resources,
265 .num_resources = ARRAY_SIZE(tmu2_resources),
266};
267
176static struct plat_sci_port sci_platform_data[] = { 268static struct plat_sci_port sci_platform_data[] = {
177 { 269 {
178 .mapbase = 0xffe00000, 270 .mapbase = 0xffe00000,
179 .flags = UPF_BOOT_AUTOCONF, 271 .flags = UPF_BOOT_AUTOCONF,
180 .type = PORT_SCIF, 272 .type = PORT_SCIF,
181 .irqs = { 80, 80, 80, 80 }, 273 .irqs = { 80, 80, 80, 80 },
274 .clk = "scif0",
182 }, { 275 }, {
183 .mapbase = 0xffe10000, 276 .mapbase = 0xffe10000,
184 .flags = UPF_BOOT_AUTOCONF, 277 .flags = UPF_BOOT_AUTOCONF,
185 .type = PORT_SCIF, 278 .type = PORT_SCIF,
186 .irqs = { 81, 81, 81, 81 }, 279 .irqs = { 81, 81, 81, 81 },
280 .clk = "scif1",
187 }, { 281 }, {
188 .mapbase = 0xffe20000, 282 .mapbase = 0xffe20000,
189 .flags = UPF_BOOT_AUTOCONF, 283 .flags = UPF_BOOT_AUTOCONF,
190 .type = PORT_SCIF, 284 .type = PORT_SCIF,
191 .irqs = { 82, 82, 82, 82 }, 285 .irqs = { 82, 82, 82, 82 },
286 .clk = "scif2",
192 }, { 287 }, {
193 .mapbase = 0xffe30000, 288 .mapbase = 0xffe30000,
194 .flags = UPF_BOOT_AUTOCONF, 289 .flags = UPF_BOOT_AUTOCONF,
195 .type = PORT_SCIF, 290 .type = PORT_SCIF,
196 .irqs = { 83, 83, 83, 83 }, 291 .irqs = { 83, 83, 83, 83 },
292 .clk = "scif3",
197 }, { 293 }, {
198 .flags = 0, 294 .flags = 0,
199 } 295 }
@@ -209,6 +305,9 @@ static struct platform_device sci_device = {
209 305
210static struct platform_device *sh7343_devices[] __initdata = { 306static struct platform_device *sh7343_devices[] __initdata = {
211 &cmt_device, 307 &cmt_device,
308 &tmu0_device,
309 &tmu1_device,
310 &tmu2_device,
212 &iic0_device, 311 &iic0_device,
213 &iic1_device, 312 &iic1_device,
214 &sci_device, 313 &sci_device,
@@ -219,12 +318,6 @@ static struct platform_device *sh7343_devices[] __initdata = {
219 318
220static int __init sh7343_devices_setup(void) 319static int __init sh7343_devices_setup(void)
221{ 320{
222 clk_always_enable("uram0"); /* URAM */
223 clk_always_enable("xymem0"); /* XYMEM */
224 clk_always_enable("veu0"); /* VEU */
225 clk_always_enable("vpu0"); /* VPU */
226 clk_always_enable("jpu0"); /* JPU */
227
228 platform_resource_setup_memory(&vpu_device, "vpu", 1 << 20); 321 platform_resource_setup_memory(&vpu_device, "vpu", 1 << 20);
229 platform_resource_setup_memory(&veu_device, "veu", 2 << 20); 322 platform_resource_setup_memory(&veu_device, "veu", 2 << 20);
230 platform_resource_setup_memory(&jpu_device, "jpu", 2 << 20); 323 platform_resource_setup_memory(&jpu_device, "jpu", 2 << 20);
@@ -234,6 +327,19 @@ static int __init sh7343_devices_setup(void)
234} 327}
235__initcall(sh7343_devices_setup); 328__initcall(sh7343_devices_setup);
236 329
330static struct platform_device *sh7343_early_devices[] __initdata = {
331 &cmt_device,
332 &tmu0_device,
333 &tmu1_device,
334 &tmu2_device,
335};
336
337void __init plat_early_device_setup(void)
338{
339 early_platform_add_devices(sh7343_early_devices,
340 ARRAY_SIZE(sh7343_early_devices));
341}
342
237enum { 343enum {
238 UNUSED = 0, 344 UNUSED = 0,
239 345
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7366.c b/arch/sh/kernel/cpu/sh4a/setup-sh7366.c
index 93ecf8ed5c6c..318516f6bfad 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7366.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7366.c
@@ -14,7 +14,7 @@
14#include <linux/serial.h> 14#include <linux/serial.h>
15#include <linux/serial_sci.h> 15#include <linux/serial_sci.h>
16#include <linux/uio_driver.h> 16#include <linux/uio_driver.h>
17#include <linux/sh_cmt.h> 17#include <linux/sh_timer.h>
18#include <asm/clock.h> 18#include <asm/clock.h>
19 19
20static struct resource iic_resources[] = { 20static struct resource iic_resources[] = {
@@ -148,7 +148,7 @@ static struct platform_device veu1_device = {
148 .num_resources = ARRAY_SIZE(veu1_resources), 148 .num_resources = ARRAY_SIZE(veu1_resources),
149}; 149};
150 150
151static struct sh_cmt_config cmt_platform_data = { 151static struct sh_timer_config cmt_platform_data = {
152 .name = "CMT", 152 .name = "CMT",
153 .channel_offset = 0x60, 153 .channel_offset = 0x60,
154 .timer_bit = 5, 154 .timer_bit = 5,
@@ -180,12 +180,105 @@ static struct platform_device cmt_device = {
180 .num_resources = ARRAY_SIZE(cmt_resources), 180 .num_resources = ARRAY_SIZE(cmt_resources),
181}; 181};
182 182
183static struct sh_timer_config tmu0_platform_data = {
184 .name = "TMU0",
185 .channel_offset = 0x04,
186 .timer_bit = 0,
187 .clk = "tmu0",
188 .clockevent_rating = 200,
189};
190
191static struct resource tmu0_resources[] = {
192 [0] = {
193 .name = "TMU0",
194 .start = 0xffd80008,
195 .end = 0xffd80013,
196 .flags = IORESOURCE_MEM,
197 },
198 [1] = {
199 .start = 16,
200 .flags = IORESOURCE_IRQ,
201 },
202};
203
204static struct platform_device tmu0_device = {
205 .name = "sh_tmu",
206 .id = 0,
207 .dev = {
208 .platform_data = &tmu0_platform_data,
209 },
210 .resource = tmu0_resources,
211 .num_resources = ARRAY_SIZE(tmu0_resources),
212};
213
214static struct sh_timer_config tmu1_platform_data = {
215 .name = "TMU1",
216 .channel_offset = 0x10,
217 .timer_bit = 1,
218 .clk = "tmu0",
219 .clocksource_rating = 200,
220};
221
222static struct resource tmu1_resources[] = {
223 [0] = {
224 .name = "TMU1",
225 .start = 0xffd80014,
226 .end = 0xffd8001f,
227 .flags = IORESOURCE_MEM,
228 },
229 [1] = {
230 .start = 17,
231 .flags = IORESOURCE_IRQ,
232 },
233};
234
235static struct platform_device tmu1_device = {
236 .name = "sh_tmu",
237 .id = 1,
238 .dev = {
239 .platform_data = &tmu1_platform_data,
240 },
241 .resource = tmu1_resources,
242 .num_resources = ARRAY_SIZE(tmu1_resources),
243};
244
245static struct sh_timer_config tmu2_platform_data = {
246 .name = "TMU2",
247 .channel_offset = 0x1c,
248 .timer_bit = 2,
249 .clk = "tmu0",
250};
251
252static struct resource tmu2_resources[] = {
253 [0] = {
254 .name = "TMU2",
255 .start = 0xffd80020,
256 .end = 0xffd8002b,
257 .flags = IORESOURCE_MEM,
258 },
259 [1] = {
260 .start = 18,
261 .flags = IORESOURCE_IRQ,
262 },
263};
264
265static struct platform_device tmu2_device = {
266 .name = "sh_tmu",
267 .id = 2,
268 .dev = {
269 .platform_data = &tmu2_platform_data,
270 },
271 .resource = tmu2_resources,
272 .num_resources = ARRAY_SIZE(tmu2_resources),
273};
274
183static struct plat_sci_port sci_platform_data[] = { 275static struct plat_sci_port sci_platform_data[] = {
184 { 276 {
185 .mapbase = 0xffe00000, 277 .mapbase = 0xffe00000,
186 .flags = UPF_BOOT_AUTOCONF, 278 .flags = UPF_BOOT_AUTOCONF,
187 .type = PORT_SCIF, 279 .type = PORT_SCIF,
188 .irqs = { 80, 80, 80, 80 }, 280 .irqs = { 80, 80, 80, 80 },
281 .clk = "scif0",
189 }, { 282 }, {
190 .flags = 0, 283 .flags = 0,
191 } 284 }
@@ -201,6 +294,9 @@ static struct platform_device sci_device = {
201 294
202static struct platform_device *sh7366_devices[] __initdata = { 295static struct platform_device *sh7366_devices[] __initdata = {
203 &cmt_device, 296 &cmt_device,
297 &tmu0_device,
298 &tmu1_device,
299 &tmu2_device,
204 &iic_device, 300 &iic_device,
205 &sci_device, 301 &sci_device,
206 &usb_host_device, 302 &usb_host_device,
@@ -211,12 +307,6 @@ static struct platform_device *sh7366_devices[] __initdata = {
211 307
212static int __init sh7366_devices_setup(void) 308static int __init sh7366_devices_setup(void)
213{ 309{
214 clk_always_enable("rsmem0"); /* RSMEM */
215 clk_always_enable("xymem0"); /* XYMEM */
216 clk_always_enable("veu1"); /* VEU-2 */
217 clk_always_enable("veu0"); /* VEU-1 */
218 clk_always_enable("vpu0"); /* VPU */
219
220 platform_resource_setup_memory(&vpu_device, "vpu", 2 << 20); 310 platform_resource_setup_memory(&vpu_device, "vpu", 2 << 20);
221 platform_resource_setup_memory(&veu0_device, "veu0", 2 << 20); 311 platform_resource_setup_memory(&veu0_device, "veu0", 2 << 20);
222 platform_resource_setup_memory(&veu1_device, "veu1", 2 << 20); 312 platform_resource_setup_memory(&veu1_device, "veu1", 2 << 20);
@@ -226,6 +316,19 @@ static int __init sh7366_devices_setup(void)
226} 316}
227__initcall(sh7366_devices_setup); 317__initcall(sh7366_devices_setup);
228 318
319static struct platform_device *sh7366_early_devices[] __initdata = {
320 &cmt_device,
321 &tmu0_device,
322 &tmu1_device,
323 &tmu2_device,
324};
325
326void __init plat_early_device_setup(void)
327{
328 early_platform_add_devices(sh7366_early_devices,
329 ARRAY_SIZE(sh7366_early_devices));
330}
331
229enum { 332enum {
230 UNUSED=0, 333 UNUSED=0,
231 334
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7722.c b/arch/sh/kernel/cpu/sh4a/setup-sh7722.c
index 406747f07dc0..ea524a2da3e4 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7722.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7722.c
@@ -13,7 +13,7 @@
13#include <linux/serial_sci.h> 13#include <linux/serial_sci.h>
14#include <linux/mm.h> 14#include <linux/mm.h>
15#include <linux/uio_driver.h> 15#include <linux/uio_driver.h>
16#include <linux/sh_cmt.h> 16#include <linux/sh_timer.h>
17#include <asm/clock.h> 17#include <asm/clock.h>
18#include <asm/mmzone.h> 18#include <asm/mmzone.h>
19 19
@@ -177,13 +177,13 @@ static struct platform_device jpu_device = {
177 .num_resources = ARRAY_SIZE(jpu_resources), 177 .num_resources = ARRAY_SIZE(jpu_resources),
178}; 178};
179 179
180static struct sh_cmt_config cmt_platform_data = { 180static struct sh_timer_config cmt_platform_data = {
181 .name = "CMT", 181 .name = "CMT",
182 .channel_offset = 0x60, 182 .channel_offset = 0x60,
183 .timer_bit = 5, 183 .timer_bit = 5,
184 .clk = "cmt0", 184 .clk = "cmt0",
185 .clockevent_rating = 125, 185 .clockevent_rating = 125,
186 .clocksource_rating = 200, 186 .clocksource_rating = 125,
187}; 187};
188 188
189static struct resource cmt_resources[] = { 189static struct resource cmt_resources[] = {
@@ -209,24 +209,119 @@ static struct platform_device cmt_device = {
209 .num_resources = ARRAY_SIZE(cmt_resources), 209 .num_resources = ARRAY_SIZE(cmt_resources),
210}; 210};
211 211
212static struct sh_timer_config tmu0_platform_data = {
213 .name = "TMU0",
214 .channel_offset = 0x04,
215 .timer_bit = 0,
216 .clk = "tmu0",
217 .clockevent_rating = 200,
218};
219
220static struct resource tmu0_resources[] = {
221 [0] = {
222 .name = "TMU0",
223 .start = 0xffd80008,
224 .end = 0xffd80013,
225 .flags = IORESOURCE_MEM,
226 },
227 [1] = {
228 .start = 16,
229 .flags = IORESOURCE_IRQ,
230 },
231};
232
233static struct platform_device tmu0_device = {
234 .name = "sh_tmu",
235 .id = 0,
236 .dev = {
237 .platform_data = &tmu0_platform_data,
238 },
239 .resource = tmu0_resources,
240 .num_resources = ARRAY_SIZE(tmu0_resources),
241};
242
243static struct sh_timer_config tmu1_platform_data = {
244 .name = "TMU1",
245 .channel_offset = 0x10,
246 .timer_bit = 1,
247 .clk = "tmu0",
248 .clocksource_rating = 200,
249};
250
251static struct resource tmu1_resources[] = {
252 [0] = {
253 .name = "TMU1",
254 .start = 0xffd80014,
255 .end = 0xffd8001f,
256 .flags = IORESOURCE_MEM,
257 },
258 [1] = {
259 .start = 17,
260 .flags = IORESOURCE_IRQ,
261 },
262};
263
264static struct platform_device tmu1_device = {
265 .name = "sh_tmu",
266 .id = 1,
267 .dev = {
268 .platform_data = &tmu1_platform_data,
269 },
270 .resource = tmu1_resources,
271 .num_resources = ARRAY_SIZE(tmu1_resources),
272};
273
274static struct sh_timer_config tmu2_platform_data = {
275 .name = "TMU2",
276 .channel_offset = 0x1c,
277 .timer_bit = 2,
278 .clk = "tmu0",
279};
280
281static struct resource tmu2_resources[] = {
282 [0] = {
283 .name = "TMU2",
284 .start = 0xffd80020,
285 .end = 0xffd8002b,
286 .flags = IORESOURCE_MEM,
287 },
288 [1] = {
289 .start = 18,
290 .flags = IORESOURCE_IRQ,
291 },
292};
293
294static struct platform_device tmu2_device = {
295 .name = "sh_tmu",
296 .id = 2,
297 .dev = {
298 .platform_data = &tmu2_platform_data,
299 },
300 .resource = tmu2_resources,
301 .num_resources = ARRAY_SIZE(tmu2_resources),
302};
303
212static struct plat_sci_port sci_platform_data[] = { 304static struct plat_sci_port sci_platform_data[] = {
213 { 305 {
214 .mapbase = 0xffe00000, 306 .mapbase = 0xffe00000,
215 .flags = UPF_BOOT_AUTOCONF, 307 .flags = UPF_BOOT_AUTOCONF,
216 .type = PORT_SCIF, 308 .type = PORT_SCIF,
217 .irqs = { 80, 80, 80, 80 }, 309 .irqs = { 80, 80, 80, 80 },
310 .clk = "scif0",
218 }, 311 },
219 { 312 {
220 .mapbase = 0xffe10000, 313 .mapbase = 0xffe10000,
221 .flags = UPF_BOOT_AUTOCONF, 314 .flags = UPF_BOOT_AUTOCONF,
222 .type = PORT_SCIF, 315 .type = PORT_SCIF,
223 .irqs = { 81, 81, 81, 81 }, 316 .irqs = { 81, 81, 81, 81 },
317 .clk = "scif1",
224 }, 318 },
225 { 319 {
226 .mapbase = 0xffe20000, 320 .mapbase = 0xffe20000,
227 .flags = UPF_BOOT_AUTOCONF, 321 .flags = UPF_BOOT_AUTOCONF,
228 .type = PORT_SCIF, 322 .type = PORT_SCIF,
229 .irqs = { 82, 82, 82, 82 }, 323 .irqs = { 82, 82, 82, 82 },
324 .clk = "scif2",
230 }, 325 },
231 { 326 {
232 .flags = 0, 327 .flags = 0,
@@ -243,6 +338,9 @@ static struct platform_device sci_device = {
243 338
244static struct platform_device *sh7722_devices[] __initdata = { 339static struct platform_device *sh7722_devices[] __initdata = {
245 &cmt_device, 340 &cmt_device,
341 &tmu0_device,
342 &tmu1_device,
343 &tmu2_device,
246 &rtc_device, 344 &rtc_device,
247 &usbf_device, 345 &usbf_device,
248 &iic_device, 346 &iic_device,
@@ -254,12 +352,6 @@ static struct platform_device *sh7722_devices[] __initdata = {
254 352
255static int __init sh7722_devices_setup(void) 353static int __init sh7722_devices_setup(void)
256{ 354{
257 clk_always_enable("uram0"); /* URAM */
258 clk_always_enable("xymem0"); /* XYMEM */
259 clk_always_enable("veu0"); /* VEU */
260 clk_always_enable("vpu0"); /* VPU */
261 clk_always_enable("jpu0"); /* JPU */
262
263 platform_resource_setup_memory(&vpu_device, "vpu", 1 << 20); 355 platform_resource_setup_memory(&vpu_device, "vpu", 1 << 20);
264 platform_resource_setup_memory(&veu_device, "veu", 2 << 20); 356 platform_resource_setup_memory(&veu_device, "veu", 2 << 20);
265 platform_resource_setup_memory(&jpu_device, "jpu", 2 << 20); 357 platform_resource_setup_memory(&jpu_device, "jpu", 2 << 20);
@@ -269,6 +361,19 @@ static int __init sh7722_devices_setup(void)
269} 361}
270__initcall(sh7722_devices_setup); 362__initcall(sh7722_devices_setup);
271 363
364static struct platform_device *sh7722_early_devices[] __initdata = {
365 &cmt_device,
366 &tmu0_device,
367 &tmu1_device,
368 &tmu2_device,
369};
370
371void __init plat_early_device_setup(void)
372{
373 early_platform_add_devices(sh7722_early_devices,
374 ARRAY_SIZE(sh7722_early_devices));
375}
376
272enum { 377enum {
273 UNUSED=0, 378 UNUSED=0,
274 379
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7723.c b/arch/sh/kernel/cpu/sh4a/setup-sh7723.c
index a800466b938c..d8f4a13aeff9 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7723.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7723.c
@@ -13,7 +13,8 @@
13#include <linux/mm.h> 13#include <linux/mm.h>
14#include <linux/serial_sci.h> 14#include <linux/serial_sci.h>
15#include <linux/uio_driver.h> 15#include <linux/uio_driver.h>
16#include <linux/sh_cmt.h> 16#include <linux/sh_timer.h>
17#include <linux/io.h>
17#include <asm/clock.h> 18#include <asm/clock.h>
18#include <asm/mmzone.h> 19#include <asm/mmzone.h>
19 20
@@ -101,13 +102,13 @@ static struct platform_device veu1_device = {
101 .num_resources = ARRAY_SIZE(veu1_resources), 102 .num_resources = ARRAY_SIZE(veu1_resources),
102}; 103};
103 104
104static struct sh_cmt_config cmt_platform_data = { 105static struct sh_timer_config cmt_platform_data = {
105 .name = "CMT", 106 .name = "CMT",
106 .channel_offset = 0x60, 107 .channel_offset = 0x60,
107 .timer_bit = 5, 108 .timer_bit = 5,
108 .clk = "cmt0", 109 .clk = "cmt0",
109 .clockevent_rating = 125, 110 .clockevent_rating = 125,
110 .clocksource_rating = 200, 111 .clocksource_rating = 125,
111}; 112};
112 113
113static struct resource cmt_resources[] = { 114static struct resource cmt_resources[] = {
@@ -133,37 +134,225 @@ static struct platform_device cmt_device = {
133 .num_resources = ARRAY_SIZE(cmt_resources), 134 .num_resources = ARRAY_SIZE(cmt_resources),
134}; 135};
135 136
137static struct sh_timer_config tmu0_platform_data = {
138 .name = "TMU0",
139 .channel_offset = 0x04,
140 .timer_bit = 0,
141 .clk = "tmu0",
142 .clockevent_rating = 200,
143};
144
145static struct resource tmu0_resources[] = {
146 [0] = {
147 .name = "TMU0",
148 .start = 0xffd80008,
149 .end = 0xffd80013,
150 .flags = IORESOURCE_MEM,
151 },
152 [1] = {
153 .start = 16,
154 .flags = IORESOURCE_IRQ,
155 },
156};
157
158static struct platform_device tmu0_device = {
159 .name = "sh_tmu",
160 .id = 0,
161 .dev = {
162 .platform_data = &tmu0_platform_data,
163 },
164 .resource = tmu0_resources,
165 .num_resources = ARRAY_SIZE(tmu0_resources),
166};
167
168static struct sh_timer_config tmu1_platform_data = {
169 .name = "TMU1",
170 .channel_offset = 0x10,
171 .timer_bit = 1,
172 .clk = "tmu0",
173 .clocksource_rating = 200,
174};
175
176static struct resource tmu1_resources[] = {
177 [0] = {
178 .name = "TMU1",
179 .start = 0xffd80014,
180 .end = 0xffd8001f,
181 .flags = IORESOURCE_MEM,
182 },
183 [1] = {
184 .start = 17,
185 .flags = IORESOURCE_IRQ,
186 },
187};
188
189static struct platform_device tmu1_device = {
190 .name = "sh_tmu",
191 .id = 1,
192 .dev = {
193 .platform_data = &tmu1_platform_data,
194 },
195 .resource = tmu1_resources,
196 .num_resources = ARRAY_SIZE(tmu1_resources),
197};
198
199static struct sh_timer_config tmu2_platform_data = {
200 .name = "TMU2",
201 .channel_offset = 0x1c,
202 .timer_bit = 2,
203 .clk = "tmu0",
204};
205
206static struct resource tmu2_resources[] = {
207 [0] = {
208 .name = "TMU2",
209 .start = 0xffd80020,
210 .end = 0xffd8002b,
211 .flags = IORESOURCE_MEM,
212 },
213 [1] = {
214 .start = 18,
215 .flags = IORESOURCE_IRQ,
216 },
217};
218
219static struct platform_device tmu2_device = {
220 .name = "sh_tmu",
221 .id = 2,
222 .dev = {
223 .platform_data = &tmu2_platform_data,
224 },
225 .resource = tmu2_resources,
226 .num_resources = ARRAY_SIZE(tmu2_resources),
227};
228
229static struct sh_timer_config tmu3_platform_data = {
230 .name = "TMU3",
231 .channel_offset = 0x04,
232 .timer_bit = 0,
233 .clk = "tmu1",
234};
235
236static struct resource tmu3_resources[] = {
237 [0] = {
238 .name = "TMU3",
239 .start = 0xffd90008,
240 .end = 0xffd90013,
241 .flags = IORESOURCE_MEM,
242 },
243 [1] = {
244 .start = 57,
245 .flags = IORESOURCE_IRQ,
246 },
247};
248
249static struct platform_device tmu3_device = {
250 .name = "sh_tmu",
251 .id = 3,
252 .dev = {
253 .platform_data = &tmu3_platform_data,
254 },
255 .resource = tmu3_resources,
256 .num_resources = ARRAY_SIZE(tmu3_resources),
257};
258
259static struct sh_timer_config tmu4_platform_data = {
260 .name = "TMU4",
261 .channel_offset = 0x10,
262 .timer_bit = 1,
263 .clk = "tmu1",
264};
265
266static struct resource tmu4_resources[] = {
267 [0] = {
268 .name = "TMU4",
269 .start = 0xffd90014,
270 .end = 0xffd9001f,
271 .flags = IORESOURCE_MEM,
272 },
273 [1] = {
274 .start = 58,
275 .flags = IORESOURCE_IRQ,
276 },
277};
278
279static struct platform_device tmu4_device = {
280 .name = "sh_tmu",
281 .id = 4,
282 .dev = {
283 .platform_data = &tmu4_platform_data,
284 },
285 .resource = tmu4_resources,
286 .num_resources = ARRAY_SIZE(tmu4_resources),
287};
288
289static struct sh_timer_config tmu5_platform_data = {
290 .name = "TMU5",
291 .channel_offset = 0x1c,
292 .timer_bit = 2,
293 .clk = "tmu1",
294};
295
296static struct resource tmu5_resources[] = {
297 [0] = {
298 .name = "TMU5",
299 .start = 0xffd90020,
300 .end = 0xffd9002b,
301 .flags = IORESOURCE_MEM,
302 },
303 [1] = {
304 .start = 57,
305 .flags = IORESOURCE_IRQ,
306 },
307};
308
309static struct platform_device tmu5_device = {
310 .name = "sh_tmu",
311 .id = 5,
312 .dev = {
313 .platform_data = &tmu5_platform_data,
314 },
315 .resource = tmu5_resources,
316 .num_resources = ARRAY_SIZE(tmu5_resources),
317};
318
136static struct plat_sci_port sci_platform_data[] = { 319static struct plat_sci_port sci_platform_data[] = {
137 { 320 {
138 .mapbase = 0xffe00000, 321 .mapbase = 0xffe00000,
139 .flags = UPF_BOOT_AUTOCONF, 322 .flags = UPF_BOOT_AUTOCONF,
140 .type = PORT_SCIF, 323 .type = PORT_SCIF,
141 .irqs = { 80, 80, 80, 80 }, 324 .irqs = { 80, 80, 80, 80 },
325 .clk = "scif0",
142 },{ 326 },{
143 .mapbase = 0xffe10000, 327 .mapbase = 0xffe10000,
144 .flags = UPF_BOOT_AUTOCONF, 328 .flags = UPF_BOOT_AUTOCONF,
145 .type = PORT_SCIF, 329 .type = PORT_SCIF,
146 .irqs = { 81, 81, 81, 81 }, 330 .irqs = { 81, 81, 81, 81 },
331 .clk = "scif1",
147 },{ 332 },{
148 .mapbase = 0xffe20000, 333 .mapbase = 0xffe20000,
149 .flags = UPF_BOOT_AUTOCONF, 334 .flags = UPF_BOOT_AUTOCONF,
150 .type = PORT_SCIF, 335 .type = PORT_SCIF,
151 .irqs = { 82, 82, 82, 82 }, 336 .irqs = { 82, 82, 82, 82 },
337 .clk = "scif2",
152 },{ 338 },{
153 .mapbase = 0xa4e30000, 339 .mapbase = 0xa4e30000,
154 .flags = UPF_BOOT_AUTOCONF, 340 .flags = UPF_BOOT_AUTOCONF,
155 .type = PORT_SCIFA, 341 .type = PORT_SCIFA,
156 .irqs = { 56, 56, 56, 56 }, 342 .irqs = { 56, 56, 56, 56 },
343 .clk = "scif3",
157 },{ 344 },{
158 .mapbase = 0xa4e40000, 345 .mapbase = 0xa4e40000,
159 .flags = UPF_BOOT_AUTOCONF, 346 .flags = UPF_BOOT_AUTOCONF,
160 .type = PORT_SCIFA, 347 .type = PORT_SCIFA,
161 .irqs = { 88, 88, 88, 88 }, 348 .irqs = { 88, 88, 88, 88 },
349 .clk = "scif4",
162 },{ 350 },{
163 .mapbase = 0xa4e50000, 351 .mapbase = 0xa4e50000,
164 .flags = UPF_BOOT_AUTOCONF, 352 .flags = UPF_BOOT_AUTOCONF,
165 .type = PORT_SCIFA, 353 .type = PORT_SCIFA,
166 .irqs = { 109, 109, 109, 109 }, 354 .irqs = { 109, 109, 109, 109 },
355 .clk = "scif5",
167 }, { 356 }, {
168 .flags = 0, 357 .flags = 0,
169 } 358 }
@@ -255,6 +444,12 @@ static struct platform_device iic_device = {
255 444
256static struct platform_device *sh7723_devices[] __initdata = { 445static struct platform_device *sh7723_devices[] __initdata = {
257 &cmt_device, 446 &cmt_device,
447 &tmu0_device,
448 &tmu1_device,
449 &tmu2_device,
450 &tmu3_device,
451 &tmu4_device,
452 &tmu5_device,
258 &sci_device, 453 &sci_device,
259 &rtc_device, 454 &rtc_device,
260 &iic_device, 455 &iic_device,
@@ -266,11 +461,6 @@ static struct platform_device *sh7723_devices[] __initdata = {
266 461
267static int __init sh7723_devices_setup(void) 462static int __init sh7723_devices_setup(void)
268{ 463{
269 clk_always_enable("meram0"); /* MERAM */
270 clk_always_enable("veu1"); /* VEU2H1 */
271 clk_always_enable("veu0"); /* VEU2H0 */
272 clk_always_enable("vpu0"); /* VPU */
273
274 platform_resource_setup_memory(&vpu_device, "vpu", 2 << 20); 464 platform_resource_setup_memory(&vpu_device, "vpu", 2 << 20);
275 platform_resource_setup_memory(&veu0_device, "veu0", 2 << 20); 465 platform_resource_setup_memory(&veu0_device, "veu0", 2 << 20);
276 platform_resource_setup_memory(&veu1_device, "veu1", 2 << 20); 466 platform_resource_setup_memory(&veu1_device, "veu1", 2 << 20);
@@ -280,6 +470,31 @@ static int __init sh7723_devices_setup(void)
280} 470}
281__initcall(sh7723_devices_setup); 471__initcall(sh7723_devices_setup);
282 472
473static struct platform_device *sh7723_early_devices[] __initdata = {
474 &cmt_device,
475 &tmu0_device,
476 &tmu1_device,
477 &tmu2_device,
478 &tmu3_device,
479 &tmu4_device,
480 &tmu5_device,
481};
482
483void __init plat_early_device_setup(void)
484{
485 early_platform_add_devices(sh7723_early_devices,
486 ARRAY_SIZE(sh7723_early_devices));
487}
488
489#define RAMCR_CACHE_L2FC 0x0002
490#define RAMCR_CACHE_L2E 0x0001
491#define L2_CACHE_ENABLE (RAMCR_CACHE_L2E|RAMCR_CACHE_L2FC)
492void __uses_jump_to_uncached l2_cache_init(void)
493{
494 /* Enable L2 cache */
495 ctrl_outl(L2_CACHE_ENABLE, RAMCR);
496}
497
283enum { 498enum {
284 UNUSED=0, 499 UNUSED=0,
285 500
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7724.c b/arch/sh/kernel/cpu/sh4a/setup-sh7724.c
new file mode 100644
index 000000000000..e5ac9eb11c63
--- /dev/null
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7724.c
@@ -0,0 +1,786 @@
1/*
2 * SH7724 Setup
3 *
4 * Copyright (C) 2009 Renesas Solutions Corp.
5 *
6 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
7 *
8 * Based on SH7723 Setup
9 * Copyright (C) 2008 Paul Mundt
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
13 * for more details.
14 */
15#include <linux/platform_device.h>
16#include <linux/init.h>
17#include <linux/serial.h>
18#include <linux/mm.h>
19#include <linux/serial_sci.h>
20#include <linux/uio_driver.h>
21#include <linux/sh_timer.h>
22#include <linux/io.h>
23#include <asm/clock.h>
24#include <asm/mmzone.h>
25
26/* Serial */
27static struct plat_sci_port sci_platform_data[] = {
28 {
29 .mapbase = 0xffe00000,
30 .flags = UPF_BOOT_AUTOCONF,
31 .type = PORT_SCIF,
32 .irqs = { 80, 80, 80, 80 },
33 .clk = "scif0",
34 }, {
35 .mapbase = 0xffe10000,
36 .flags = UPF_BOOT_AUTOCONF,
37 .type = PORT_SCIF,
38 .irqs = { 81, 81, 81, 81 },
39 .clk = "scif1",
40 }, {
41 .mapbase = 0xffe20000,
42 .flags = UPF_BOOT_AUTOCONF,
43 .type = PORT_SCIF,
44 .irqs = { 82, 82, 82, 82 },
45 .clk = "scif2",
46 }, {
47 .mapbase = 0xa4e30000,
48 .flags = UPF_BOOT_AUTOCONF,
49 .type = PORT_SCIFA,
50 .irqs = { 56, 56, 56, 56 },
51 .clk = "scif3",
52 }, {
53 .mapbase = 0xa4e40000,
54 .flags = UPF_BOOT_AUTOCONF,
55 .type = PORT_SCIFA,
56 .irqs = { 88, 88, 88, 88 },
57 .clk = "scif4",
58 }, {
59 .mapbase = 0xa4e50000,
60 .flags = UPF_BOOT_AUTOCONF,
61 .type = PORT_SCIFA,
62 .irqs = { 109, 109, 109, 109 },
63 .clk = "scif5",
64 }, {
65 .flags = 0,
66 }
67};
68
69static struct platform_device sci_device = {
70 .name = "sh-sci",
71 .id = -1,
72 .dev = {
73 .platform_data = sci_platform_data,
74 },
75};
76
77/* RTC */
78static struct resource rtc_resources[] = {
79 [0] = {
80 .start = 0xa465fec0,
81 .end = 0xa465fec0 + 0x58 - 1,
82 .flags = IORESOURCE_IO,
83 },
84 [1] = {
85 /* Period IRQ */
86 .start = 69,
87 .flags = IORESOURCE_IRQ,
88 },
89 [2] = {
90 /* Carry IRQ */
91 .start = 70,
92 .flags = IORESOURCE_IRQ,
93 },
94 [3] = {
95 /* Alarm IRQ */
96 .start = 68,
97 .flags = IORESOURCE_IRQ,
98 },
99};
100
101static struct platform_device rtc_device = {
102 .name = "sh-rtc",
103 .id = -1,
104 .num_resources = ARRAY_SIZE(rtc_resources),
105 .resource = rtc_resources,
106};
107
108/* I2C0 */
109static struct resource iic0_resources[] = {
110 [0] = {
111 .name = "IIC0",
112 .start = 0x04470000,
113 .end = 0x04470018 - 1,
114 .flags = IORESOURCE_MEM,
115 },
116 [1] = {
117 .start = 96,
118 .end = 99,
119 .flags = IORESOURCE_IRQ,
120 },
121};
122
123static struct platform_device iic0_device = {
124 .name = "i2c-sh_mobile",
125 .id = 0, /* "i2c0" clock */
126 .num_resources = ARRAY_SIZE(iic0_resources),
127 .resource = iic0_resources,
128};
129
130/* I2C1 */
131static struct resource iic1_resources[] = {
132 [0] = {
133 .name = "IIC1",
134 .start = 0x04750000,
135 .end = 0x04750018 - 1,
136 .flags = IORESOURCE_MEM,
137 },
138 [1] = {
139 .start = 92,
140 .end = 95,
141 .flags = IORESOURCE_IRQ,
142 },
143};
144
145static struct platform_device iic1_device = {
146 .name = "i2c-sh_mobile",
147 .id = 1, /* "i2c1" clock */
148 .num_resources = ARRAY_SIZE(iic1_resources),
149 .resource = iic1_resources,
150};
151
152/* VPU */
153static struct uio_info vpu_platform_data = {
154 .name = "VPU5F",
155 .version = "0",
156 .irq = 60,
157};
158
159static struct resource vpu_resources[] = {
160 [0] = {
161 .name = "VPU",
162 .start = 0xfe900000,
163 .end = 0xfe902807,
164 .flags = IORESOURCE_MEM,
165 },
166 [1] = {
167 /* place holder for contiguous memory */
168 },
169};
170
171static struct platform_device vpu_device = {
172 .name = "uio_pdrv_genirq",
173 .id = 0,
174 .dev = {
175 .platform_data = &vpu_platform_data,
176 },
177 .resource = vpu_resources,
178 .num_resources = ARRAY_SIZE(vpu_resources),
179};
180
181/* VEU0 */
182static struct uio_info veu0_platform_data = {
183 .name = "VEU3F0",
184 .version = "0",
185 .irq = 83,
186};
187
188static struct resource veu0_resources[] = {
189 [0] = {
190 .name = "VEU3F0",
191 .start = 0xfe920000,
192 .end = 0xfe9200cb - 1,
193 .flags = IORESOURCE_MEM,
194 },
195 [1] = {
196 /* place holder for contiguous memory */
197 },
198};
199
200static struct platform_device veu0_device = {
201 .name = "uio_pdrv_genirq",
202 .id = 1,
203 .dev = {
204 .platform_data = &veu0_platform_data,
205 },
206 .resource = veu0_resources,
207 .num_resources = ARRAY_SIZE(veu0_resources),
208};
209
210/* VEU1 */
211static struct uio_info veu1_platform_data = {
212 .name = "VEU3F1",
213 .version = "0",
214 .irq = 54,
215};
216
217static struct resource veu1_resources[] = {
218 [0] = {
219 .name = "VEU3F1",
220 .start = 0xfe924000,
221 .end = 0xfe9240cb - 1,
222 .flags = IORESOURCE_MEM,
223 },
224 [1] = {
225 /* place holder for contiguous memory */
226 },
227};
228
229static struct platform_device veu1_device = {
230 .name = "uio_pdrv_genirq",
231 .id = 2,
232 .dev = {
233 .platform_data = &veu1_platform_data,
234 },
235 .resource = veu1_resources,
236 .num_resources = ARRAY_SIZE(veu1_resources),
237};
238
239static struct sh_timer_config cmt_platform_data = {
240 .name = "CMT",
241 .channel_offset = 0x60,
242 .timer_bit = 5,
243 .clk = "cmt0",
244 .clockevent_rating = 125,
245 .clocksource_rating = 200,
246};
247
248static struct resource cmt_resources[] = {
249 [0] = {
250 .name = "CMT",
251 .start = 0x044a0060,
252 .end = 0x044a006b,
253 .flags = IORESOURCE_MEM,
254 },
255 [1] = {
256 .start = 104,
257 .flags = IORESOURCE_IRQ,
258 },
259};
260
261static struct platform_device cmt_device = {
262 .name = "sh_cmt",
263 .id = 0,
264 .dev = {
265 .platform_data = &cmt_platform_data,
266 },
267 .resource = cmt_resources,
268 .num_resources = ARRAY_SIZE(cmt_resources),
269};
270
271static struct sh_timer_config tmu0_platform_data = {
272 .name = "TMU0",
273 .channel_offset = 0x04,
274 .timer_bit = 0,
275 .clk = "tmu0",
276 .clockevent_rating = 200,
277};
278
279static struct resource tmu0_resources[] = {
280 [0] = {
281 .name = "TMU0",
282 .start = 0xffd80008,
283 .end = 0xffd80013,
284 .flags = IORESOURCE_MEM,
285 },
286 [1] = {
287 .start = 16,
288 .flags = IORESOURCE_IRQ,
289 },
290};
291
292static struct platform_device tmu0_device = {
293 .name = "sh_tmu",
294 .id = 0,
295 .dev = {
296 .platform_data = &tmu0_platform_data,
297 },
298 .resource = tmu0_resources,
299 .num_resources = ARRAY_SIZE(tmu0_resources),
300};
301
302static struct sh_timer_config tmu1_platform_data = {
303 .name = "TMU1",
304 .channel_offset = 0x10,
305 .timer_bit = 1,
306 .clk = "tmu0",
307 .clocksource_rating = 200,
308};
309
310static struct resource tmu1_resources[] = {
311 [0] = {
312 .name = "TMU1",
313 .start = 0xffd80014,
314 .end = 0xffd8001f,
315 .flags = IORESOURCE_MEM,
316 },
317 [1] = {
318 .start = 17,
319 .flags = IORESOURCE_IRQ,
320 },
321};
322
323static struct platform_device tmu1_device = {
324 .name = "sh_tmu",
325 .id = 1,
326 .dev = {
327 .platform_data = &tmu1_platform_data,
328 },
329 .resource = tmu1_resources,
330 .num_resources = ARRAY_SIZE(tmu1_resources),
331};
332
333static struct sh_timer_config tmu2_platform_data = {
334 .name = "TMU2",
335 .channel_offset = 0x1c,
336 .timer_bit = 2,
337 .clk = "tmu0",
338};
339
340static struct resource tmu2_resources[] = {
341 [0] = {
342 .name = "TMU2",
343 .start = 0xffd80020,
344 .end = 0xffd8002b,
345 .flags = IORESOURCE_MEM,
346 },
347 [1] = {
348 .start = 18,
349 .flags = IORESOURCE_IRQ,
350 },
351};
352
353static struct platform_device tmu2_device = {
354 .name = "sh_tmu",
355 .id = 2,
356 .dev = {
357 .platform_data = &tmu2_platform_data,
358 },
359 .resource = tmu2_resources,
360 .num_resources = ARRAY_SIZE(tmu2_resources),
361};
362
363
364static struct sh_timer_config tmu3_platform_data = {
365 .name = "TMU3",
366 .channel_offset = 0x04,
367 .timer_bit = 0,
368 .clk = "tmu1",
369};
370
371static struct resource tmu3_resources[] = {
372 [0] = {
373 .name = "TMU3",
374 .start = 0xffd90008,
375 .end = 0xffd90013,
376 .flags = IORESOURCE_MEM,
377 },
378 [1] = {
379 .start = 57,
380 .flags = IORESOURCE_IRQ,
381 },
382};
383
384static struct platform_device tmu3_device = {
385 .name = "sh_tmu",
386 .id = 3,
387 .dev = {
388 .platform_data = &tmu3_platform_data,
389 },
390 .resource = tmu3_resources,
391 .num_resources = ARRAY_SIZE(tmu3_resources),
392};
393
394static struct sh_timer_config tmu4_platform_data = {
395 .name = "TMU4",
396 .channel_offset = 0x10,
397 .timer_bit = 1,
398 .clk = "tmu1",
399};
400
401static struct resource tmu4_resources[] = {
402 [0] = {
403 .name = "TMU4",
404 .start = 0xffd90014,
405 .end = 0xffd9001f,
406 .flags = IORESOURCE_MEM,
407 },
408 [1] = {
409 .start = 58,
410 .flags = IORESOURCE_IRQ,
411 },
412};
413
414static struct platform_device tmu4_device = {
415 .name = "sh_tmu",
416 .id = 4,
417 .dev = {
418 .platform_data = &tmu4_platform_data,
419 },
420 .resource = tmu4_resources,
421 .num_resources = ARRAY_SIZE(tmu4_resources),
422};
423
424static struct sh_timer_config tmu5_platform_data = {
425 .name = "TMU5",
426 .channel_offset = 0x1c,
427 .timer_bit = 2,
428 .clk = "tmu1",
429};
430
431static struct resource tmu5_resources[] = {
432 [0] = {
433 .name = "TMU5",
434 .start = 0xffd90020,
435 .end = 0xffd9002b,
436 .flags = IORESOURCE_MEM,
437 },
438 [1] = {
439 .start = 57,
440 .flags = IORESOURCE_IRQ,
441 },
442};
443
444static struct platform_device tmu5_device = {
445 .name = "sh_tmu",
446 .id = 5,
447 .dev = {
448 .platform_data = &tmu5_platform_data,
449 },
450 .resource = tmu5_resources,
451 .num_resources = ARRAY_SIZE(tmu5_resources),
452};
453
454/* JPU */
455static struct uio_info jpu_platform_data = {
456 .name = "JPU",
457 .version = "0",
458 .irq = 27,
459};
460
461static struct resource jpu_resources[] = {
462 [0] = {
463 .name = "JPU",
464 .start = 0xfe980000,
465 .end = 0xfe9902d3,
466 .flags = IORESOURCE_MEM,
467 },
468 [1] = {
469 /* place holder for contiguous memory */
470 },
471};
472
473static struct platform_device jpu_device = {
474 .name = "uio_pdrv_genirq",
475 .id = 3,
476 .dev = {
477 .platform_data = &jpu_platform_data,
478 },
479 .resource = jpu_resources,
480 .num_resources = ARRAY_SIZE(jpu_resources),
481};
482
483static struct platform_device *sh7724_devices[] __initdata = {
484 &cmt_device,
485 &tmu0_device,
486 &tmu1_device,
487 &tmu2_device,
488 &tmu3_device,
489 &tmu4_device,
490 &tmu5_device,
491 &sci_device,
492 &rtc_device,
493 &iic0_device,
494 &iic1_device,
495 &vpu_device,
496 &veu0_device,
497 &veu1_device,
498 &jpu_device,
499};
500
501static int __init sh7724_devices_setup(void)
502{
503 platform_resource_setup_memory(&vpu_device, "vpu", 2 << 20);
504 platform_resource_setup_memory(&veu0_device, "veu0", 2 << 20);
505 platform_resource_setup_memory(&veu1_device, "veu1", 2 << 20);
506 platform_resource_setup_memory(&jpu_device, "jpu", 2 << 20);
507
508 return platform_add_devices(sh7724_devices,
509 ARRAY_SIZE(sh7724_devices));
510}
511device_initcall(sh7724_devices_setup);
512
513static struct platform_device *sh7724_early_devices[] __initdata = {
514 &cmt_device,
515 &tmu0_device,
516 &tmu1_device,
517 &tmu2_device,
518 &tmu3_device,
519 &tmu4_device,
520 &tmu5_device,
521};
522
523void __init plat_early_device_setup(void)
524{
525 early_platform_add_devices(sh7724_early_devices,
526 ARRAY_SIZE(sh7724_early_devices));
527}
528
529#define RAMCR_CACHE_L2FC 0x0002
530#define RAMCR_CACHE_L2E 0x0001
531#define L2_CACHE_ENABLE (RAMCR_CACHE_L2E|RAMCR_CACHE_L2FC)
532void __uses_jump_to_uncached l2_cache_init(void)
533{
534 /* Enable L2 cache */
535 ctrl_outl(L2_CACHE_ENABLE, RAMCR);
536}
537
538enum {
539 UNUSED = 0,
540
541 /* interrupt sources */
542 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7,
543 HUDI,
544 DMAC1A_DEI0, DMAC1A_DEI1, DMAC1A_DEI2, DMAC1A_DEI3,
545 _2DG_TRI, _2DG_INI, _2DG_CEI,
546 DMAC0A_DEI0, DMAC0A_DEI1, DMAC0A_DEI2, DMAC0A_DEI3,
547 VIO_CEU0, VIO_BEU0, VIO_VEU1, VIO_VOU,
548 SCIFA3,
549 VPU,
550 TPU,
551 CEU1,
552 BEU1,
553 USB0, USB1,
554 ATAPI,
555 RTC_ATI, RTC_PRI, RTC_CUI,
556 DMAC1B_DEI4, DMAC1B_DEI5, DMAC1B_DADERR,
557 DMAC0B_DEI4, DMAC0B_DEI5, DMAC0B_DADERR,
558 KEYSC,
559 SCIF_SCIF0, SCIF_SCIF1, SCIF_SCIF2,
560 VEU0,
561 MSIOF_MSIOFI0, MSIOF_MSIOFI1,
562 SPU_SPUI0, SPU_SPUI1,
563 SCIFA4,
564 ICB,
565 ETHI,
566 I2C1_ALI, I2C1_TACKI, I2C1_WAITI, I2C1_DTEI,
567 I2C0_ALI, I2C0_TACKI, I2C0_WAITI, I2C0_DTEI,
568 SDHI0_SDHII0, SDHI0_SDHII1, SDHI0_SDHII2, SDHI0_SDHII3,
569 CMT,
570 TSIF,
571 FSI,
572 SCIFA5,
573 TMU0_TUNI0, TMU0_TUNI1, TMU0_TUNI2,
574 IRDA,
575 SDHI1_SDHII0, SDHI1_SDHII1, SDHI1_SDHII2,
576 JPU,
577 _2DDMAC,
578 MMC_MMC2I, MMC_MMC3I,
579 LCDC,
580 TMU1_TUNI0, TMU1_TUNI1, TMU1_TUNI2,
581
582 /* interrupt groups */
583 DMAC1A, _2DG, DMAC0A, VIO, USB, RTC,
584 DMAC1B, DMAC0B, I2C0, I2C1, SDHI0, SDHI1, SPU, MMCIF,
585};
586
587static struct intc_vect vectors[] __initdata = {
588 INTC_VECT(IRQ0, 0x600), INTC_VECT(IRQ1, 0x620),
589 INTC_VECT(IRQ2, 0x640), INTC_VECT(IRQ3, 0x660),
590 INTC_VECT(IRQ4, 0x680), INTC_VECT(IRQ5, 0x6a0),
591 INTC_VECT(IRQ6, 0x6c0), INTC_VECT(IRQ7, 0x6e0),
592
593 INTC_VECT(DMAC1A_DEI0, 0x700),
594 INTC_VECT(DMAC1A_DEI1, 0x720),
595 INTC_VECT(DMAC1A_DEI2, 0x740),
596 INTC_VECT(DMAC1A_DEI3, 0x760),
597
598 INTC_VECT(_2DG_TRI, 0x780),
599 INTC_VECT(_2DG_INI, 0x7A0),
600 INTC_VECT(_2DG_CEI, 0x7C0),
601
602 INTC_VECT(DMAC0A_DEI0, 0x800),
603 INTC_VECT(DMAC0A_DEI1, 0x820),
604 INTC_VECT(DMAC0A_DEI2, 0x840),
605 INTC_VECT(DMAC0A_DEI3, 0x860),
606
607 INTC_VECT(VIO_CEU0, 0x880),
608 INTC_VECT(VIO_BEU0, 0x8A0),
609 INTC_VECT(VIO_VEU1, 0x8C0),
610 INTC_VECT(VIO_VOU, 0x8E0),
611
612 INTC_VECT(SCIFA3, 0x900),
613 INTC_VECT(VPU, 0x980),
614 INTC_VECT(TPU, 0x9A0),
615 INTC_VECT(CEU1, 0x9E0),
616 INTC_VECT(BEU1, 0xA00),
617 INTC_VECT(USB0, 0xA20),
618 INTC_VECT(USB1, 0xA40),
619 INTC_VECT(ATAPI, 0xA60),
620
621 INTC_VECT(RTC_ATI, 0xA80),
622 INTC_VECT(RTC_PRI, 0xAA0),
623 INTC_VECT(RTC_CUI, 0xAC0),
624
625 INTC_VECT(DMAC1B_DEI4, 0xB00),
626 INTC_VECT(DMAC1B_DEI5, 0xB20),
627 INTC_VECT(DMAC1B_DADERR, 0xB40),
628
629 INTC_VECT(DMAC0B_DEI4, 0xB80),
630 INTC_VECT(DMAC0B_DEI5, 0xBA0),
631 INTC_VECT(DMAC0B_DADERR, 0xBC0),
632
633 INTC_VECT(KEYSC, 0xBE0),
634 INTC_VECT(SCIF_SCIF0, 0xC00),
635 INTC_VECT(SCIF_SCIF1, 0xC20),
636 INTC_VECT(SCIF_SCIF2, 0xC40),
637 INTC_VECT(VEU0, 0xC60),
638 INTC_VECT(MSIOF_MSIOFI0, 0xC80),
639 INTC_VECT(MSIOF_MSIOFI1, 0xCA0),
640 INTC_VECT(SPU_SPUI0, 0xCC0),
641 INTC_VECT(SPU_SPUI1, 0xCE0),
642 INTC_VECT(SCIFA4, 0xD00),
643
644 INTC_VECT(ICB, 0xD20),
645 INTC_VECT(ETHI, 0xD60),
646
647 INTC_VECT(I2C1_ALI, 0xD80),
648 INTC_VECT(I2C1_TACKI, 0xDA0),
649 INTC_VECT(I2C1_WAITI, 0xDC0),
650 INTC_VECT(I2C1_DTEI, 0xDE0),
651
652 INTC_VECT(I2C0_ALI, 0xE00),
653 INTC_VECT(I2C0_TACKI, 0xE20),
654 INTC_VECT(I2C0_WAITI, 0xE40),
655 INTC_VECT(I2C0_DTEI, 0xE60),
656
657 INTC_VECT(SDHI0_SDHII0, 0xE80),
658 INTC_VECT(SDHI0_SDHII1, 0xEA0),
659 INTC_VECT(SDHI0_SDHII2, 0xEC0),
660 INTC_VECT(SDHI0_SDHII3, 0xEE0),
661
662 INTC_VECT(CMT, 0xF00),
663 INTC_VECT(TSIF, 0xF20),
664 INTC_VECT(FSI, 0xF80),
665 INTC_VECT(SCIFA5, 0xFA0),
666
667 INTC_VECT(TMU0_TUNI0, 0x400),
668 INTC_VECT(TMU0_TUNI1, 0x420),
669 INTC_VECT(TMU0_TUNI2, 0x440),
670
671 INTC_VECT(IRDA, 0x480),
672
673 INTC_VECT(SDHI1_SDHII0, 0x4E0),
674 INTC_VECT(SDHI1_SDHII1, 0x500),
675 INTC_VECT(SDHI1_SDHII2, 0x520),
676
677 INTC_VECT(JPU, 0x560),
678 INTC_VECT(_2DDMAC, 0x4A0),
679
680 INTC_VECT(MMC_MMC2I, 0x5A0),
681 INTC_VECT(MMC_MMC3I, 0x5C0),
682
683 INTC_VECT(LCDC, 0xF40),
684
685 INTC_VECT(TMU1_TUNI0, 0x920),
686 INTC_VECT(TMU1_TUNI1, 0x940),
687 INTC_VECT(TMU1_TUNI2, 0x960),
688};
689
690static struct intc_group groups[] __initdata = {
691 INTC_GROUP(DMAC1A, DMAC1A_DEI0, DMAC1A_DEI1, DMAC1A_DEI2, DMAC1A_DEI3),
692 INTC_GROUP(_2DG, _2DG_TRI, _2DG_INI, _2DG_CEI),
693 INTC_GROUP(DMAC0A, DMAC0A_DEI0, DMAC0A_DEI1, DMAC0A_DEI2, DMAC0A_DEI3),
694 INTC_GROUP(VIO, VIO_CEU0, VIO_BEU0, VIO_VEU1, VIO_VOU),
695 INTC_GROUP(USB, USB0, USB1),
696 INTC_GROUP(RTC, RTC_ATI, RTC_PRI, RTC_CUI),
697 INTC_GROUP(DMAC1B, DMAC1B_DEI4, DMAC1B_DEI5, DMAC1B_DADERR),
698 INTC_GROUP(DMAC0B, DMAC0B_DEI4, DMAC0B_DEI5, DMAC0B_DADERR),
699 INTC_GROUP(I2C0, I2C0_ALI, I2C0_TACKI, I2C0_WAITI, I2C0_DTEI),
700 INTC_GROUP(I2C1, I2C1_ALI, I2C1_TACKI, I2C1_WAITI, I2C1_DTEI),
701 INTC_GROUP(SDHI0, SDHI0_SDHII0, SDHI0_SDHII1, SDHI0_SDHII2, SDHI0_SDHII3),
702 INTC_GROUP(SDHI1, SDHI1_SDHII0, SDHI1_SDHII1, SDHI1_SDHII2),
703 INTC_GROUP(SPU, SPU_SPUI0, SPU_SPUI1),
704 INTC_GROUP(MMCIF, MMC_MMC2I, MMC_MMC3I),
705};
706
707static struct intc_mask_reg mask_registers[] __initdata = {
708 { 0xa4080080, 0xa40800c0, 8, /* IMR0 / IMCR0 */
709 { 0, TMU1_TUNI2, TMU1_TUNI1, TMU1_TUNI0,
710 0, SDHI1_SDHII2, SDHI1_SDHII1, SDHI1_SDHII0 } },
711 { 0xa4080084, 0xa40800c4, 8, /* IMR1 / IMCR1 */
712 { VIO_VOU, VIO_VEU1, VIO_BEU0, VIO_CEU0,
713 DMAC0A_DEI3, DMAC0A_DEI2, DMAC0A_DEI1, DMAC0A_DEI0 } },
714 { 0xa4080088, 0xa40800c8, 8, /* IMR2 / IMCR2 */
715 { 0, 0, 0, VPU, ATAPI, ETHI, 0, SCIFA3 } },
716 { 0xa408008c, 0xa40800cc, 8, /* IMR3 / IMCR3 */
717 { DMAC1A_DEI3, DMAC1A_DEI2, DMAC1A_DEI1, DMAC1A_DEI0,
718 SPU_SPUI1, SPU_SPUI0, BEU1, IRDA } },
719 { 0xa4080090, 0xa40800d0, 8, /* IMR4 / IMCR4 */
720 { 0, TMU0_TUNI2, TMU0_TUNI1, TMU0_TUNI0,
721 JPU, 0, 0, LCDC } },
722 { 0xa4080094, 0xa40800d4, 8, /* IMR5 / IMCR5 */
723 { KEYSC, DMAC0B_DADERR, DMAC0B_DEI5, DMAC0B_DEI4,
724 VEU0, SCIF_SCIF2, SCIF_SCIF1, SCIF_SCIF0 } },
725 { 0xa4080098, 0xa40800d8, 8, /* IMR6 / IMCR6 */
726 { 0, 0, ICB, SCIFA4,
727 CEU1, 0, MSIOF_MSIOFI1, MSIOF_MSIOFI0 } },
728 { 0xa408009c, 0xa40800dc, 8, /* IMR7 / IMCR7 */
729 { I2C0_DTEI, I2C0_WAITI, I2C0_TACKI, I2C0_ALI,
730 I2C1_DTEI, I2C1_WAITI, I2C1_TACKI, I2C1_ALI } },
731 { 0xa40800a0, 0xa40800e0, 8, /* IMR8 / IMCR8 */
732 { SDHI0_SDHII3, SDHI0_SDHII2, SDHI0_SDHII1, SDHI0_SDHII0,
733 0, 0, SCIFA5, FSI } },
734 { 0xa40800a4, 0xa40800e4, 8, /* IMR9 / IMCR9 */
735 { 0, 0, 0, CMT, 0, USB1, USB0, 0 } },
736 { 0xa40800a8, 0xa40800e8, 8, /* IMR10 / IMCR10 */
737 { 0, DMAC1B_DADERR, DMAC1B_DEI5, DMAC1B_DEI4,
738 0, RTC_CUI, RTC_PRI, RTC_ATI } },
739 { 0xa40800ac, 0xa40800ec, 8, /* IMR11 / IMCR11 */
740 { 0, _2DG_CEI, _2DG_INI, _2DG_TRI,
741 0, TPU, 0, TSIF } },
742 { 0xa40800b0, 0xa40800f0, 8, /* IMR12 / IMCR12 */
743 { 0, 0, MMC_MMC3I, MMC_MMC2I, 0, 0, 0, _2DDMAC } },
744 { 0xa4140044, 0xa4140064, 8, /* INTMSK00 / INTMSKCLR00 */
745 { IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7 } },
746};
747
748static struct intc_prio_reg prio_registers[] __initdata = {
749 { 0xa4080000, 0, 16, 4, /* IPRA */ { TMU0_TUNI0, TMU0_TUNI1,
750 TMU0_TUNI2, IRDA } },
751 { 0xa4080004, 0, 16, 4, /* IPRB */ { JPU, LCDC, DMAC1A, BEU1 } },
752 { 0xa4080008, 0, 16, 4, /* IPRC */ { TMU1_TUNI0, TMU1_TUNI1,
753 TMU1_TUNI2, SPU } },
754 { 0xa408000c, 0, 16, 4, /* IPRD */ { 0, MMCIF, 0, ATAPI } },
755 { 0xa4080010, 0, 16, 4, /* IPRE */ { DMAC0A, VIO, SCIFA3, VPU } },
756 { 0xa4080014, 0, 16, 4, /* IPRF */ { KEYSC, DMAC0B, USB, CMT } },
757 { 0xa4080018, 0, 16, 4, /* IPRG */ { SCIF_SCIF0, SCIF_SCIF1,
758 SCIF_SCIF2, VEU0 } },
759 { 0xa408001c, 0, 16, 4, /* IPRH */ { MSIOF_MSIOFI0, MSIOF_MSIOFI1,
760 I2C1, I2C0 } },
761 { 0xa4080020, 0, 16, 4, /* IPRI */ { SCIFA4, ICB, TSIF, _2DG } },
762 { 0xa4080024, 0, 16, 4, /* IPRJ */ { CEU1, ETHI, FSI, SDHI1 } },
763 { 0xa4080028, 0, 16, 4, /* IPRK */ { RTC, DMAC1B, 0, SDHI0 } },
764 { 0xa408002c, 0, 16, 4, /* IPRL */ { SCIFA5, 0, TPU, _2DDMAC } },
765 { 0xa4140010, 0, 32, 4, /* INTPRI00 */
766 { IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7 } },
767};
768
769static struct intc_sense_reg sense_registers[] __initdata = {
770 { 0xa414001c, 16, 2, /* ICR1 */
771 { IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7 } },
772};
773
774static struct intc_mask_reg ack_registers[] __initdata = {
775 { 0xa4140024, 0, 8, /* INTREQ00 */
776 { IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7 } },
777};
778
779static DECLARE_INTC_DESC_ACK(intc_desc, "sh7724", vectors, groups,
780 mask_registers, prio_registers, sense_registers,
781 ack_registers);
782
783void __init plat_irq_setup(void)
784{
785 register_intc_controller(&intc_desc);
786}
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7763.c b/arch/sh/kernel/cpu/sh4a/setup-sh7763.c
index bdf0f61ae1ed..f1e0c0d36da7 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7763.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7763.c
@@ -12,6 +12,7 @@
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/serial.h> 14#include <linux/serial.h>
15#include <linux/sh_timer.h>
15#include <linux/io.h> 16#include <linux/io.h>
16#include <linux/serial_sci.h> 17#include <linux/serial_sci.h>
17 18
@@ -113,7 +114,195 @@ static struct platform_device usbf_device = {
113 .resource = usbf_resources, 114 .resource = usbf_resources,
114}; 115};
115 116
117static struct sh_timer_config tmu0_platform_data = {
118 .name = "TMU0",
119 .channel_offset = 0x04,
120 .timer_bit = 0,
121 .clk = "peripheral_clk",
122 .clockevent_rating = 200,
123};
124
125static struct resource tmu0_resources[] = {
126 [0] = {
127 .name = "TMU0",
128 .start = 0xffd80008,
129 .end = 0xffd80013,
130 .flags = IORESOURCE_MEM,
131 },
132 [1] = {
133 .start = 28,
134 .flags = IORESOURCE_IRQ,
135 },
136};
137
138static struct platform_device tmu0_device = {
139 .name = "sh_tmu",
140 .id = 0,
141 .dev = {
142 .platform_data = &tmu0_platform_data,
143 },
144 .resource = tmu0_resources,
145 .num_resources = ARRAY_SIZE(tmu0_resources),
146};
147
148static struct sh_timer_config tmu1_platform_data = {
149 .name = "TMU1",
150 .channel_offset = 0x10,
151 .timer_bit = 1,
152 .clk = "peripheral_clk",
153 .clocksource_rating = 200,
154};
155
156static struct resource tmu1_resources[] = {
157 [0] = {
158 .name = "TMU1",
159 .start = 0xffd80014,
160 .end = 0xffd8001f,
161 .flags = IORESOURCE_MEM,
162 },
163 [1] = {
164 .start = 29,
165 .flags = IORESOURCE_IRQ,
166 },
167};
168
169static struct platform_device tmu1_device = {
170 .name = "sh_tmu",
171 .id = 1,
172 .dev = {
173 .platform_data = &tmu1_platform_data,
174 },
175 .resource = tmu1_resources,
176 .num_resources = ARRAY_SIZE(tmu1_resources),
177};
178
179static struct sh_timer_config tmu2_platform_data = {
180 .name = "TMU2",
181 .channel_offset = 0x1c,
182 .timer_bit = 2,
183 .clk = "peripheral_clk",
184};
185
186static struct resource tmu2_resources[] = {
187 [0] = {
188 .name = "TMU2",
189 .start = 0xffd80020,
190 .end = 0xffd8002f,
191 .flags = IORESOURCE_MEM,
192 },
193 [1] = {
194 .start = 30,
195 .flags = IORESOURCE_IRQ,
196 },
197};
198
199static struct platform_device tmu2_device = {
200 .name = "sh_tmu",
201 .id = 2,
202 .dev = {
203 .platform_data = &tmu2_platform_data,
204 },
205 .resource = tmu2_resources,
206 .num_resources = ARRAY_SIZE(tmu2_resources),
207};
208
209static struct sh_timer_config tmu3_platform_data = {
210 .name = "TMU3",
211 .channel_offset = 0x04,
212 .timer_bit = 0,
213 .clk = "peripheral_clk",
214};
215
216static struct resource tmu3_resources[] = {
217 [0] = {
218 .name = "TMU3",
219 .start = 0xffd88008,
220 .end = 0xffd88013,
221 .flags = IORESOURCE_MEM,
222 },
223 [1] = {
224 .start = 96,
225 .flags = IORESOURCE_IRQ,
226 },
227};
228
229static struct platform_device tmu3_device = {
230 .name = "sh_tmu",
231 .id = 3,
232 .dev = {
233 .platform_data = &tmu3_platform_data,
234 },
235 .resource = tmu3_resources,
236 .num_resources = ARRAY_SIZE(tmu3_resources),
237};
238
239static struct sh_timer_config tmu4_platform_data = {
240 .name = "TMU4",
241 .channel_offset = 0x10,
242 .timer_bit = 1,
243 .clk = "peripheral_clk",
244};
245
246static struct resource tmu4_resources[] = {
247 [0] = {
248 .name = "TMU4",
249 .start = 0xffd88014,
250 .end = 0xffd8801f,
251 .flags = IORESOURCE_MEM,
252 },
253 [1] = {
254 .start = 97,
255 .flags = IORESOURCE_IRQ,
256 },
257};
258
259static struct platform_device tmu4_device = {
260 .name = "sh_tmu",
261 .id = 4,
262 .dev = {
263 .platform_data = &tmu4_platform_data,
264 },
265 .resource = tmu4_resources,
266 .num_resources = ARRAY_SIZE(tmu4_resources),
267};
268
269static struct sh_timer_config tmu5_platform_data = {
270 .name = "TMU5",
271 .channel_offset = 0x1c,
272 .timer_bit = 2,
273 .clk = "peripheral_clk",
274};
275
276static struct resource tmu5_resources[] = {
277 [0] = {
278 .name = "TMU5",
279 .start = 0xffd88020,
280 .end = 0xffd8802b,
281 .flags = IORESOURCE_MEM,
282 },
283 [1] = {
284 .start = 98,
285 .flags = IORESOURCE_IRQ,
286 },
287};
288
289static struct platform_device tmu5_device = {
290 .name = "sh_tmu",
291 .id = 5,
292 .dev = {
293 .platform_data = &tmu5_platform_data,
294 },
295 .resource = tmu5_resources,
296 .num_resources = ARRAY_SIZE(tmu5_resources),
297};
298
116static struct platform_device *sh7763_devices[] __initdata = { 299static struct platform_device *sh7763_devices[] __initdata = {
300 &tmu0_device,
301 &tmu1_device,
302 &tmu2_device,
303 &tmu3_device,
304 &tmu4_device,
305 &tmu5_device,
117 &rtc_device, 306 &rtc_device,
118 &sci_device, 307 &sci_device,
119 &usb_ohci_device, 308 &usb_ohci_device,
@@ -127,6 +316,21 @@ static int __init sh7763_devices_setup(void)
127} 316}
128__initcall(sh7763_devices_setup); 317__initcall(sh7763_devices_setup);
129 318
319static struct platform_device *sh7763_early_devices[] __initdata = {
320 &tmu0_device,
321 &tmu1_device,
322 &tmu2_device,
323 &tmu3_device,
324 &tmu4_device,
325 &tmu5_device,
326};
327
328void __init plat_early_device_setup(void)
329{
330 early_platform_add_devices(sh7763_early_devices,
331 ARRAY_SIZE(sh7763_early_devices));
332}
333
130enum { 334enum {
131 UNUSED = 0, 335 UNUSED = 0,
132 336
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7770.c b/arch/sh/kernel/cpu/sh4a/setup-sh7770.c
index b73578ee295d..1e86209db284 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7770.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7770.c
@@ -11,6 +11,8 @@
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/serial.h> 12#include <linux/serial.h>
13#include <linux/serial_sci.h> 13#include <linux/serial_sci.h>
14#include <linux/sh_timer.h>
15#include <linux/io.h>
14 16
15static struct plat_sci_port sci_platform_data[] = { 17static struct plat_sci_port sci_platform_data[] = {
16 { 18 {
@@ -76,7 +78,288 @@ static struct platform_device sci_device = {
76 }, 78 },
77}; 79};
78 80
81static struct sh_timer_config tmu0_platform_data = {
82 .name = "TMU0",
83 .channel_offset = 0x04,
84 .timer_bit = 0,
85 .clk = "peripheral_clk",
86 .clockevent_rating = 200,
87};
88
89static struct resource tmu0_resources[] = {
90 [0] = {
91 .name = "TMU0",
92 .start = 0xffd80008,
93 .end = 0xffd80013,
94 .flags = IORESOURCE_MEM,
95 },
96 [1] = {
97 .start = 16,
98 .flags = IORESOURCE_IRQ,
99 },
100};
101
102static struct platform_device tmu0_device = {
103 .name = "sh_tmu",
104 .id = 0,
105 .dev = {
106 .platform_data = &tmu0_platform_data,
107 },
108 .resource = tmu0_resources,
109 .num_resources = ARRAY_SIZE(tmu0_resources),
110};
111
112static struct sh_timer_config tmu1_platform_data = {
113 .name = "TMU1",
114 .channel_offset = 0x10,
115 .timer_bit = 1,
116 .clk = "peripheral_clk",
117 .clocksource_rating = 200,
118};
119
120static struct resource tmu1_resources[] = {
121 [0] = {
122 .name = "TMU1",
123 .start = 0xffd80014,
124 .end = 0xffd8001f,
125 .flags = IORESOURCE_MEM,
126 },
127 [1] = {
128 .start = 17,
129 .flags = IORESOURCE_IRQ,
130 },
131};
132
133static struct platform_device tmu1_device = {
134 .name = "sh_tmu",
135 .id = 1,
136 .dev = {
137 .platform_data = &tmu1_platform_data,
138 },
139 .resource = tmu1_resources,
140 .num_resources = ARRAY_SIZE(tmu1_resources),
141};
142
143static struct sh_timer_config tmu2_platform_data = {
144 .name = "TMU2",
145 .channel_offset = 0x1c,
146 .timer_bit = 2,
147 .clk = "peripheral_clk",
148};
149
150static struct resource tmu2_resources[] = {
151 [0] = {
152 .name = "TMU2",
153 .start = 0xffd80020,
154 .end = 0xffd8002f,
155 .flags = IORESOURCE_MEM,
156 },
157 [1] = {
158 .start = 18,
159 .flags = IORESOURCE_IRQ,
160 },
161};
162
163static struct platform_device tmu2_device = {
164 .name = "sh_tmu",
165 .id = 2,
166 .dev = {
167 .platform_data = &tmu2_platform_data,
168 },
169 .resource = tmu2_resources,
170 .num_resources = ARRAY_SIZE(tmu2_resources),
171};
172
173static struct sh_timer_config tmu3_platform_data = {
174 .name = "TMU3",
175 .channel_offset = 0x04,
176 .timer_bit = 0,
177 .clk = "peripheral_clk",
178};
179
180static struct resource tmu3_resources[] = {
181 [0] = {
182 .name = "TMU3",
183 .start = 0xffd81008,
184 .end = 0xffd81013,
185 .flags = IORESOURCE_MEM,
186 },
187 [1] = {
188 .start = 19,
189 .flags = IORESOURCE_IRQ,
190 },
191};
192
193static struct platform_device tmu3_device = {
194 .name = "sh_tmu",
195 .id = 3,
196 .dev = {
197 .platform_data = &tmu3_platform_data,
198 },
199 .resource = tmu3_resources,
200 .num_resources = ARRAY_SIZE(tmu3_resources),
201};
202
203static struct sh_timer_config tmu4_platform_data = {
204 .name = "TMU4",
205 .channel_offset = 0x10,
206 .timer_bit = 1,
207 .clk = "peripheral_clk",
208};
209
210static struct resource tmu4_resources[] = {
211 [0] = {
212 .name = "TMU4",
213 .start = 0xffd81014,
214 .end = 0xffd8101f,
215 .flags = IORESOURCE_MEM,
216 },
217 [1] = {
218 .start = 20,
219 .flags = IORESOURCE_IRQ,
220 },
221};
222
223static struct platform_device tmu4_device = {
224 .name = "sh_tmu",
225 .id = 4,
226 .dev = {
227 .platform_data = &tmu4_platform_data,
228 },
229 .resource = tmu4_resources,
230 .num_resources = ARRAY_SIZE(tmu4_resources),
231};
232
233static struct sh_timer_config tmu5_platform_data = {
234 .name = "TMU5",
235 .channel_offset = 0x1c,
236 .timer_bit = 2,
237 .clk = "peripheral_clk",
238};
239
240static struct resource tmu5_resources[] = {
241 [0] = {
242 .name = "TMU5",
243 .start = 0xffd81020,
244 .end = 0xffd8102f,
245 .flags = IORESOURCE_MEM,
246 },
247 [1] = {
248 .start = 21,
249 .flags = IORESOURCE_IRQ,
250 },
251};
252
253static struct platform_device tmu5_device = {
254 .name = "sh_tmu",
255 .id = 5,
256 .dev = {
257 .platform_data = &tmu5_platform_data,
258 },
259 .resource = tmu5_resources,
260 .num_resources = ARRAY_SIZE(tmu5_resources),
261};
262
263static struct sh_timer_config tmu6_platform_data = {
264 .name = "TMU6",
265 .channel_offset = 0x04,
266 .timer_bit = 0,
267 .clk = "peripheral_clk",
268};
269
270static struct resource tmu6_resources[] = {
271 [0] = {
272 .name = "TMU6",
273 .start = 0xffd82008,
274 .end = 0xffd82013,
275 .flags = IORESOURCE_MEM,
276 },
277 [1] = {
278 .start = 22,
279 .flags = IORESOURCE_IRQ,
280 },
281};
282
283static struct platform_device tmu6_device = {
284 .name = "sh_tmu",
285 .id = 6,
286 .dev = {
287 .platform_data = &tmu6_platform_data,
288 },
289 .resource = tmu6_resources,
290 .num_resources = ARRAY_SIZE(tmu6_resources),
291};
292
293static struct sh_timer_config tmu7_platform_data = {
294 .name = "TMU7",
295 .channel_offset = 0x10,
296 .timer_bit = 1,
297 .clk = "peripheral_clk",
298};
299
300static struct resource tmu7_resources[] = {
301 [0] = {
302 .name = "TMU7",
303 .start = 0xffd82014,
304 .end = 0xffd8201f,
305 .flags = IORESOURCE_MEM,
306 },
307 [1] = {
308 .start = 23,
309 .flags = IORESOURCE_IRQ,
310 },
311};
312
313static struct platform_device tmu7_device = {
314 .name = "sh_tmu",
315 .id = 7,
316 .dev = {
317 .platform_data = &tmu7_platform_data,
318 },
319 .resource = tmu7_resources,
320 .num_resources = ARRAY_SIZE(tmu7_resources),
321};
322
323static struct sh_timer_config tmu8_platform_data = {
324 .name = "TMU8",
325 .channel_offset = 0x1c,
326 .timer_bit = 2,
327 .clk = "peripheral_clk",
328};
329
330static struct resource tmu8_resources[] = {
331 [0] = {
332 .name = "TMU8",
333 .start = 0xffd82020,
334 .end = 0xffd8202b,
335 .flags = IORESOURCE_MEM,
336 },
337 [1] = {
338 .start = 24,
339 .flags = IORESOURCE_IRQ,
340 },
341};
342
343static struct platform_device tmu8_device = {
344 .name = "sh_tmu",
345 .id = 8,
346 .dev = {
347 .platform_data = &tmu8_platform_data,
348 },
349 .resource = tmu8_resources,
350 .num_resources = ARRAY_SIZE(tmu8_resources),
351};
352
79static struct platform_device *sh7770_devices[] __initdata = { 353static struct platform_device *sh7770_devices[] __initdata = {
354 &tmu0_device,
355 &tmu1_device,
356 &tmu2_device,
357 &tmu3_device,
358 &tmu4_device,
359 &tmu5_device,
360 &tmu6_device,
361 &tmu7_device,
362 &tmu8_device,
80 &sci_device, 363 &sci_device,
81}; 364};
82 365
@@ -87,6 +370,269 @@ static int __init sh7770_devices_setup(void)
87} 370}
88__initcall(sh7770_devices_setup); 371__initcall(sh7770_devices_setup);
89 372
373static struct platform_device *sh7770_early_devices[] __initdata = {
374 &tmu0_device,
375 &tmu1_device,
376 &tmu2_device,
377 &tmu3_device,
378 &tmu4_device,
379 &tmu5_device,
380 &tmu6_device,
381 &tmu7_device,
382 &tmu8_device,
383};
384
385void __init plat_early_device_setup(void)
386{
387 early_platform_add_devices(sh7770_early_devices,
388 ARRAY_SIZE(sh7770_early_devices));
389}
390
391enum {
392 UNUSED = 0,
393
394 /* interrupt sources */
395 IRL_LLLL, IRL_LLLH, IRL_LLHL, IRL_LLHH,
396 IRL_LHLL, IRL_LHLH, IRL_LHHL, IRL_LHHH,
397 IRL_HLLL, IRL_HLLH, IRL_HLHL, IRL_HLHH,
398 IRL_HHLL, IRL_HHLH, IRL_HHHL,
399
400 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5,
401
402 GPIO,
403 TMU0, TMU1, TMU2, TMU2_TICPI,
404 TMU3, TMU4, TMU5, TMU5_TICPI,
405 TMU6, TMU7, TMU8,
406 HAC, IPI, SPDIF, HUDI, I2C,
407 DMAC0_DMINT0, DMAC0_DMINT1, DMAC0_DMINT2,
408 I2S0, I2S1, I2S2, I2S3,
409 SRC_RX, SRC_TX, SRC_SPDIF,
410 DU, VIDEO_IN, REMOTE, YUV, USB, ATAPI, CAN, GPS, GFX2D,
411 GFX3D_MBX, GFX3D_DMAC,
412 EXBUS_ATA,
413 SPI0, SPI1,
414 SCIF089, SCIF1234, SCIF567,
415 ADC,
416 BBDMAC_0_3, BBDMAC_4_7, BBDMAC_8_10, BBDMAC_11_14,
417 BBDMAC_15_18, BBDMAC_19_22, BBDMAC_23_26, BBDMAC_27,
418 BBDMAC_28, BBDMAC_29, BBDMAC_30, BBDMAC_31,
419
420 /* interrupt groups */
421 TMU, DMAC, I2S, SRC, GFX3D, SPI, SCIF, BBDMAC,
422};
423
424static struct intc_vect vectors[] __initdata = {
425 INTC_VECT(GPIO, 0x3e0),
426 INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
427 INTC_VECT(TMU2, 0x440), INTC_VECT(TMU2_TICPI, 0x460),
428 INTC_VECT(TMU3, 0x480), INTC_VECT(TMU4, 0x4a0),
429 INTC_VECT(TMU5, 0x4c0), INTC_VECT(TMU5_TICPI, 0x4e0),
430 INTC_VECT(TMU6, 0x500), INTC_VECT(TMU7, 0x520),
431 INTC_VECT(TMU8, 0x540),
432 INTC_VECT(HAC, 0x580), INTC_VECT(IPI, 0x5c0),
433 INTC_VECT(SPDIF, 0x5e0),
434 INTC_VECT(HUDI, 0x600), INTC_VECT(I2C, 0x620),
435 INTC_VECT(DMAC0_DMINT0, 0x640), INTC_VECT(DMAC0_DMINT1, 0x660),
436 INTC_VECT(DMAC0_DMINT2, 0x680),
437 INTC_VECT(I2S0, 0x6a0), INTC_VECT(I2S1, 0x6c0),
438 INTC_VECT(I2S2, 0x6e0), INTC_VECT(I2S3, 0x700),
439 INTC_VECT(SRC_RX, 0x720), INTC_VECT(SRC_TX, 0x740),
440 INTC_VECT(SRC_SPDIF, 0x760),
441 INTC_VECT(DU, 0x780), INTC_VECT(VIDEO_IN, 0x7a0),
442 INTC_VECT(REMOTE, 0x7c0), INTC_VECT(YUV, 0x7e0),
443 INTC_VECT(USB, 0x840), INTC_VECT(ATAPI, 0x860),
444 INTC_VECT(CAN, 0x880), INTC_VECT(GPS, 0x8a0),
445 INTC_VECT(GFX2D, 0x8c0),
446 INTC_VECT(GFX3D_MBX, 0x900), INTC_VECT(GFX3D_DMAC, 0x920),
447 INTC_VECT(EXBUS_ATA, 0x940),
448 INTC_VECT(SPI0, 0x960), INTC_VECT(SPI1, 0x980),
449 INTC_VECT(SCIF089, 0x9a0), INTC_VECT(SCIF1234, 0x9c0),
450 INTC_VECT(SCIF1234, 0x9e0), INTC_VECT(SCIF1234, 0xa00),
451 INTC_VECT(SCIF1234, 0xa20), INTC_VECT(SCIF567, 0xa40),
452 INTC_VECT(SCIF567, 0xa60), INTC_VECT(SCIF567, 0xa80),
453 INTC_VECT(SCIF089, 0xaa0), INTC_VECT(SCIF089, 0xac0),
454 INTC_VECT(ADC, 0xb20),
455 INTC_VECT(BBDMAC_0_3, 0xba0), INTC_VECT(BBDMAC_0_3, 0xbc0),
456 INTC_VECT(BBDMAC_0_3, 0xbe0), INTC_VECT(BBDMAC_0_3, 0xc00),
457 INTC_VECT(BBDMAC_4_7, 0xc20), INTC_VECT(BBDMAC_4_7, 0xc40),
458 INTC_VECT(BBDMAC_4_7, 0xc60), INTC_VECT(BBDMAC_4_7, 0xc80),
459 INTC_VECT(BBDMAC_8_10, 0xca0), INTC_VECT(BBDMAC_8_10, 0xcc0),
460 INTC_VECT(BBDMAC_8_10, 0xce0), INTC_VECT(BBDMAC_11_14, 0xd00),
461 INTC_VECT(BBDMAC_11_14, 0xd20), INTC_VECT(BBDMAC_11_14, 0xd40),
462 INTC_VECT(BBDMAC_11_14, 0xd60), INTC_VECT(BBDMAC_15_18, 0xd80),
463 INTC_VECT(BBDMAC_15_18, 0xda0), INTC_VECT(BBDMAC_15_18, 0xdc0),
464 INTC_VECT(BBDMAC_15_18, 0xde0), INTC_VECT(BBDMAC_19_22, 0xe00),
465 INTC_VECT(BBDMAC_19_22, 0xe20), INTC_VECT(BBDMAC_19_22, 0xe40),
466 INTC_VECT(BBDMAC_19_22, 0xe60), INTC_VECT(BBDMAC_23_26, 0xe80),
467 INTC_VECT(BBDMAC_23_26, 0xea0), INTC_VECT(BBDMAC_23_26, 0xec0),
468 INTC_VECT(BBDMAC_23_26, 0xee0), INTC_VECT(BBDMAC_27, 0xf00),
469 INTC_VECT(BBDMAC_28, 0xf20), INTC_VECT(BBDMAC_29, 0xf40),
470 INTC_VECT(BBDMAC_30, 0xf60), INTC_VECT(BBDMAC_31, 0xf80),
471};
472
473static struct intc_group groups[] __initdata = {
474 INTC_GROUP(TMU, TMU0, TMU1, TMU2, TMU2_TICPI, TMU3, TMU4, TMU5,
475 TMU5_TICPI, TMU6, TMU7, TMU8),
476 INTC_GROUP(DMAC, DMAC0_DMINT0, DMAC0_DMINT1, DMAC0_DMINT2),
477 INTC_GROUP(I2S, I2S0, I2S1, I2S2, I2S3),
478 INTC_GROUP(SRC, SRC_RX, SRC_TX, SRC_SPDIF),
479 INTC_GROUP(GFX3D, GFX3D_MBX, GFX3D_DMAC),
480 INTC_GROUP(SPI, SPI0, SPI1),
481 INTC_GROUP(SCIF, SCIF089, SCIF1234, SCIF567),
482 INTC_GROUP(BBDMAC,
483 BBDMAC_0_3, BBDMAC_4_7, BBDMAC_8_10, BBDMAC_11_14,
484 BBDMAC_15_18, BBDMAC_19_22, BBDMAC_23_26, BBDMAC_27,
485 BBDMAC_28, BBDMAC_29, BBDMAC_30, BBDMAC_31),
486};
487
488static struct intc_mask_reg mask_registers[] __initdata = {
489 { 0xffe00040, 0xffe00044, 32, /* INT2MSKR / INT2MSKCR */
490 { 0, BBDMAC, ADC, SCIF, SPI, EXBUS_ATA, GFX3D, GFX2D,
491 GPS, CAN, ATAPI, USB, YUV, REMOTE, VIDEO_IN, DU, SRC, I2S,
492 DMAC, I2C, HUDI, SPDIF, IPI, HAC, TMU, GPIO } },
493};
494
495static struct intc_prio_reg prio_registers[] __initdata = {
496 { 0xffe00000, 0, 32, 8, /* INT2PRI0 */ { GPIO, TMU0, 0, HAC } },
497 { 0xffe00004, 0, 32, 8, /* INT2PRI1 */ { IPI, SPDIF, HUDI, I2C } },
498 { 0xffe00008, 0, 32, 8, /* INT2PRI2 */ { DMAC, I2S, SRC, DU } },
499 { 0xffe0000c, 0, 32, 8, /* INT2PRI3 */ { VIDEO_IN, REMOTE, YUV, USB } },
500 { 0xffe00010, 0, 32, 8, /* INT2PRI4 */ { ATAPI, CAN, GPS, GFX2D } },
501 { 0xffe00014, 0, 32, 8, /* INT2PRI5 */ { 0, GFX3D, EXBUS_ATA, SPI } },
502 { 0xffe00018, 0, 32, 8, /* INT2PRI6 */ { SCIF1234, SCIF567, SCIF089 } },
503 { 0xffe0001c, 0, 32, 8, /* INT2PRI7 */ { ADC, 0, 0, BBDMAC_0_3 } },
504 { 0xffe00020, 0, 32, 8, /* INT2PRI8 */
505 { BBDMAC_4_7, BBDMAC_8_10, BBDMAC_11_14, BBDMAC_15_18 } },
506 { 0xffe00024, 0, 32, 8, /* INT2PRI9 */
507 { BBDMAC_19_22, BBDMAC_23_26, BBDMAC_27, BBDMAC_28 } },
508 { 0xffe00028, 0, 32, 8, /* INT2PRI10 */
509 { BBDMAC_29, BBDMAC_30, BBDMAC_31 } },
510 { 0xffe0002c, 0, 32, 8, /* INT2PRI11 */
511 { TMU1, TMU2, TMU2_TICPI, TMU3 } },
512 { 0xffe00030, 0, 32, 8, /* INT2PRI12 */
513 { TMU4, TMU5, TMU5_TICPI, TMU6 } },
514 { 0xffe00034, 0, 32, 8, /* INT2PRI13 */
515 { TMU7, TMU8 } },
516};
517
518static DECLARE_INTC_DESC(intc_desc, "sh7770", vectors, groups,
519 mask_registers, prio_registers, NULL);
520
521/* Support for external interrupt pins in IRQ mode */
522static struct intc_vect irq_vectors[] __initdata = {
523 INTC_VECT(IRQ0, 0x240), INTC_VECT(IRQ1, 0x280),
524 INTC_VECT(IRQ2, 0x2c0), INTC_VECT(IRQ3, 0x300),
525 INTC_VECT(IRQ4, 0x340), INTC_VECT(IRQ5, 0x380),
526};
527
528static struct intc_mask_reg irq_mask_registers[] __initdata = {
529 { 0xffd00044, 0xffd00064, 32, /* INTMSK0 / INTMSKCLR0 */
530 { IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, } },
531};
532
533static struct intc_prio_reg irq_prio_registers[] __initdata = {
534 { 0xffd00010, 0, 32, 4, /* INTPRI */ { IRQ0, IRQ1, IRQ2, IRQ3,
535 IRQ4, IRQ5, } },
536};
537
538static struct intc_sense_reg irq_sense_registers[] __initdata = {
539 { 0xffd0001c, 32, 2, /* ICR1 */ { IRQ0, IRQ1, IRQ2, IRQ3,
540 IRQ4, IRQ5, } },
541};
542
543static DECLARE_INTC_DESC(intc_irq_desc, "sh7770-irq", irq_vectors,
544 NULL, irq_mask_registers, irq_prio_registers,
545 irq_sense_registers);
546
547/* External interrupt pins in IRL mode */
548static struct intc_vect irl_vectors[] __initdata = {
549 INTC_VECT(IRL_LLLL, 0x200), INTC_VECT(IRL_LLLH, 0x220),
550 INTC_VECT(IRL_LLHL, 0x240), INTC_VECT(IRL_LLHH, 0x260),
551 INTC_VECT(IRL_LHLL, 0x280), INTC_VECT(IRL_LHLH, 0x2a0),
552 INTC_VECT(IRL_LHHL, 0x2c0), INTC_VECT(IRL_LHHH, 0x2e0),
553 INTC_VECT(IRL_HLLL, 0x300), INTC_VECT(IRL_HLLH, 0x320),
554 INTC_VECT(IRL_HLHL, 0x340), INTC_VECT(IRL_HLHH, 0x360),
555 INTC_VECT(IRL_HHLL, 0x380), INTC_VECT(IRL_HHLH, 0x3a0),
556 INTC_VECT(IRL_HHHL, 0x3c0),
557};
558
559static struct intc_mask_reg irl3210_mask_registers[] __initdata = {
560 { 0xffd40080, 0xffd40084, 32, /* INTMSK2 / INTMSKCLR2 */
561 { IRL_LLLL, IRL_LLLH, IRL_LLHL, IRL_LLHH,
562 IRL_LHLL, IRL_LHLH, IRL_LHHL, IRL_LHHH,
563 IRL_HLLL, IRL_HLLH, IRL_HLHL, IRL_HLHH,
564 IRL_HHLL, IRL_HHLH, IRL_HHHL, } },
565};
566
567static struct intc_mask_reg irl7654_mask_registers[] __initdata = {
568 { 0xffd40080, 0xffd40084, 32, /* INTMSK2 / INTMSKCLR2 */
569 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
570 IRL_LLLL, IRL_LLLH, IRL_LLHL, IRL_LLHH,
571 IRL_LHLL, IRL_LHLH, IRL_LHHL, IRL_LHHH,
572 IRL_HLLL, IRL_HLLH, IRL_HLHL, IRL_HLHH,
573 IRL_HHLL, IRL_HHLH, IRL_HHHL, } },
574};
575
576static DECLARE_INTC_DESC(intc_irl7654_desc, "sh7780-irl7654", irl_vectors,
577 NULL, irl7654_mask_registers, NULL, NULL);
578
579static DECLARE_INTC_DESC(intc_irl3210_desc, "sh7780-irl3210", irl_vectors,
580 NULL, irl3210_mask_registers, NULL, NULL);
581
582#define INTC_ICR0 0xffd00000
583#define INTC_INTMSK0 0xffd00044
584#define INTC_INTMSK1 0xffd00048
585#define INTC_INTMSK2 0xffd40080
586#define INTC_INTMSKCLR1 0xffd00068
587#define INTC_INTMSKCLR2 0xffd40084
588
90void __init plat_irq_setup(void) 589void __init plat_irq_setup(void)
91{ 590{
591 /* disable IRQ7-0 */
592 ctrl_outl(0xff000000, INTC_INTMSK0);
593
594 /* disable IRL3-0 + IRL7-4 */
595 ctrl_outl(0xc0000000, INTC_INTMSK1);
596 ctrl_outl(0xfffefffe, INTC_INTMSK2);
597
598 /* select IRL mode for IRL3-0 + IRL7-4 */
599 ctrl_outl(ctrl_inl(INTC_ICR0) & ~0x00c00000, INTC_ICR0);
600
601 /* disable holding function, ie enable "SH-4 Mode" */
602 ctrl_outl(ctrl_inl(INTC_ICR0) | 0x00200000, INTC_ICR0);
603
604 register_intc_controller(&intc_desc);
605}
606
607void __init plat_irq_setup_pins(int mode)
608{
609 switch (mode) {
610 case IRQ_MODE_IRQ:
611 /* select IRQ mode for IRL3-0 + IRL7-4 */
612 ctrl_outl(ctrl_inl(INTC_ICR0) | 0x00c00000, INTC_ICR0);
613 register_intc_controller(&intc_irq_desc);
614 break;
615 case IRQ_MODE_IRL7654:
616 /* enable IRL7-4 but don't provide any masking */
617 ctrl_outl(0x40000000, INTC_INTMSKCLR1);
618 ctrl_outl(0x0000fffe, INTC_INTMSKCLR2);
619 break;
620 case IRQ_MODE_IRL3210:
621 /* enable IRL0-3 but don't provide any masking */
622 ctrl_outl(0x80000000, INTC_INTMSKCLR1);
623 ctrl_outl(0xfffe0000, INTC_INTMSKCLR2);
624 break;
625 case IRQ_MODE_IRL7654_MASK:
626 /* enable IRL7-4 and mask using cpu intc controller */
627 ctrl_outl(0x40000000, INTC_INTMSKCLR1);
628 register_intc_controller(&intc_irl7654_desc);
629 break;
630 case IRQ_MODE_IRL3210_MASK:
631 /* enable IRL0-3 and mask using cpu intc controller */
632 ctrl_outl(0x80000000, INTC_INTMSKCLR1);
633 register_intc_controller(&intc_irl3210_desc);
634 break;
635 default:
636 BUG();
637 }
92} 638}
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7780.c b/arch/sh/kernel/cpu/sh4a/setup-sh7780.c
index 6f7227cd65bf..715e05b431e5 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7780.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7780.c
@@ -12,6 +12,189 @@
12#include <linux/serial.h> 12#include <linux/serial.h>
13#include <linux/io.h> 13#include <linux/io.h>
14#include <linux/serial_sci.h> 14#include <linux/serial_sci.h>
15#include <linux/sh_timer.h>
16
17static struct sh_timer_config tmu0_platform_data = {
18 .name = "TMU0",
19 .channel_offset = 0x04,
20 .timer_bit = 0,
21 .clk = "peripheral_clk",
22 .clockevent_rating = 200,
23};
24
25static struct resource tmu0_resources[] = {
26 [0] = {
27 .name = "TMU0",
28 .start = 0xffd80008,
29 .end = 0xffd80013,
30 .flags = IORESOURCE_MEM,
31 },
32 [1] = {
33 .start = 28,
34 .flags = IORESOURCE_IRQ,
35 },
36};
37
38static struct platform_device tmu0_device = {
39 .name = "sh_tmu",
40 .id = 0,
41 .dev = {
42 .platform_data = &tmu0_platform_data,
43 },
44 .resource = tmu0_resources,
45 .num_resources = ARRAY_SIZE(tmu0_resources),
46};
47
48static struct sh_timer_config tmu1_platform_data = {
49 .name = "TMU1",
50 .channel_offset = 0x10,
51 .timer_bit = 1,
52 .clk = "peripheral_clk",
53 .clocksource_rating = 200,
54};
55
56static struct resource tmu1_resources[] = {
57 [0] = {
58 .name = "TMU1",
59 .start = 0xffd80014,
60 .end = 0xffd8001f,
61 .flags = IORESOURCE_MEM,
62 },
63 [1] = {
64 .start = 29,
65 .flags = IORESOURCE_IRQ,
66 },
67};
68
69static struct platform_device tmu1_device = {
70 .name = "sh_tmu",
71 .id = 1,
72 .dev = {
73 .platform_data = &tmu1_platform_data,
74 },
75 .resource = tmu1_resources,
76 .num_resources = ARRAY_SIZE(tmu1_resources),
77};
78
79static struct sh_timer_config tmu2_platform_data = {
80 .name = "TMU2",
81 .channel_offset = 0x1c,
82 .timer_bit = 2,
83 .clk = "peripheral_clk",
84};
85
86static struct resource tmu2_resources[] = {
87 [0] = {
88 .name = "TMU2",
89 .start = 0xffd80020,
90 .end = 0xffd8002f,
91 .flags = IORESOURCE_MEM,
92 },
93 [1] = {
94 .start = 30,
95 .flags = IORESOURCE_IRQ,
96 },
97};
98
99static struct platform_device tmu2_device = {
100 .name = "sh_tmu",
101 .id = 2,
102 .dev = {
103 .platform_data = &tmu2_platform_data,
104 },
105 .resource = tmu2_resources,
106 .num_resources = ARRAY_SIZE(tmu2_resources),
107};
108
109static struct sh_timer_config tmu3_platform_data = {
110 .name = "TMU3",
111 .channel_offset = 0x04,
112 .timer_bit = 0,
113 .clk = "peripheral_clk",
114};
115
116static struct resource tmu3_resources[] = {
117 [0] = {
118 .name = "TMU3",
119 .start = 0xffdc0008,
120 .end = 0xffdc0013,
121 .flags = IORESOURCE_MEM,
122 },
123 [1] = {
124 .start = 96,
125 .flags = IORESOURCE_IRQ,
126 },
127};
128
129static struct platform_device tmu3_device = {
130 .name = "sh_tmu",
131 .id = 3,
132 .dev = {
133 .platform_data = &tmu3_platform_data,
134 },
135 .resource = tmu3_resources,
136 .num_resources = ARRAY_SIZE(tmu3_resources),
137};
138
139static struct sh_timer_config tmu4_platform_data = {
140 .name = "TMU4",
141 .channel_offset = 0x10,
142 .timer_bit = 1,
143 .clk = "peripheral_clk",
144};
145
146static struct resource tmu4_resources[] = {
147 [0] = {
148 .name = "TMU4",
149 .start = 0xffdc0014,
150 .end = 0xffdc001f,
151 .flags = IORESOURCE_MEM,
152 },
153 [1] = {
154 .start = 97,
155 .flags = IORESOURCE_IRQ,
156 },
157};
158
159static struct platform_device tmu4_device = {
160 .name = "sh_tmu",
161 .id = 4,
162 .dev = {
163 .platform_data = &tmu4_platform_data,
164 },
165 .resource = tmu4_resources,
166 .num_resources = ARRAY_SIZE(tmu4_resources),
167};
168
169static struct sh_timer_config tmu5_platform_data = {
170 .name = "TMU5",
171 .channel_offset = 0x1c,
172 .timer_bit = 2,
173 .clk = "peripheral_clk",
174};
175
176static struct resource tmu5_resources[] = {
177 [0] = {
178 .name = "TMU5",
179 .start = 0xffdc0020,
180 .end = 0xffdc002b,
181 .flags = IORESOURCE_MEM,
182 },
183 [1] = {
184 .start = 98,
185 .flags = IORESOURCE_IRQ,
186 },
187};
188
189static struct platform_device tmu5_device = {
190 .name = "sh_tmu",
191 .id = 5,
192 .dev = {
193 .platform_data = &tmu5_platform_data,
194 },
195 .resource = tmu5_resources,
196 .num_resources = ARRAY_SIZE(tmu5_resources),
197};
15 198
16static struct resource rtc_resources[] = { 199static struct resource rtc_resources[] = {
17 [0] = { 200 [0] = {
@@ -58,6 +241,12 @@ static struct platform_device sci_device = {
58}; 241};
59 242
60static struct platform_device *sh7780_devices[] __initdata = { 243static struct platform_device *sh7780_devices[] __initdata = {
244 &tmu0_device,
245 &tmu1_device,
246 &tmu2_device,
247 &tmu3_device,
248 &tmu4_device,
249 &tmu5_device,
61 &rtc_device, 250 &rtc_device,
62 &sci_device, 251 &sci_device,
63}; 252};
@@ -69,6 +258,21 @@ static int __init sh7780_devices_setup(void)
69} 258}
70__initcall(sh7780_devices_setup); 259__initcall(sh7780_devices_setup);
71 260
261static struct platform_device *sh7780_early_devices[] __initdata = {
262 &tmu0_device,
263 &tmu1_device,
264 &tmu2_device,
265 &tmu3_device,
266 &tmu4_device,
267 &tmu5_device,
268};
269
270void __init plat_early_device_setup(void)
271{
272 early_platform_add_devices(sh7780_early_devices,
273 ARRAY_SIZE(sh7780_early_devices));
274}
275
72enum { 276enum {
73 UNUSED = 0, 277 UNUSED = 0,
74 278
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7785.c b/arch/sh/kernel/cpu/sh4a/setup-sh7785.c
index d80802a49dbd..af561402570b 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7785.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7785.c
@@ -13,39 +13,228 @@
13#include <linux/serial_sci.h> 13#include <linux/serial_sci.h>
14#include <linux/io.h> 14#include <linux/io.h>
15#include <linux/mm.h> 15#include <linux/mm.h>
16#include <linux/sh_timer.h>
16#include <asm/mmzone.h> 17#include <asm/mmzone.h>
17 18
19static struct sh_timer_config tmu0_platform_data = {
20 .name = "TMU0",
21 .channel_offset = 0x04,
22 .timer_bit = 0,
23 .clk = "tmu012_fck",
24 .clockevent_rating = 200,
25};
26
27static struct resource tmu0_resources[] = {
28 [0] = {
29 .name = "TMU0",
30 .start = 0xffd80008,
31 .end = 0xffd80013,
32 .flags = IORESOURCE_MEM,
33 },
34 [1] = {
35 .start = 28,
36 .flags = IORESOURCE_IRQ,
37 },
38};
39
40static struct platform_device tmu0_device = {
41 .name = "sh_tmu",
42 .id = 0,
43 .dev = {
44 .platform_data = &tmu0_platform_data,
45 },
46 .resource = tmu0_resources,
47 .num_resources = ARRAY_SIZE(tmu0_resources),
48};
49
50static struct sh_timer_config tmu1_platform_data = {
51 .name = "TMU1",
52 .channel_offset = 0x10,
53 .timer_bit = 1,
54 .clk = "tmu012_fck",
55 .clocksource_rating = 200,
56};
57
58static struct resource tmu1_resources[] = {
59 [0] = {
60 .name = "TMU1",
61 .start = 0xffd80014,
62 .end = 0xffd8001f,
63 .flags = IORESOURCE_MEM,
64 },
65 [1] = {
66 .start = 29,
67 .flags = IORESOURCE_IRQ,
68 },
69};
70
71static struct platform_device tmu1_device = {
72 .name = "sh_tmu",
73 .id = 1,
74 .dev = {
75 .platform_data = &tmu1_platform_data,
76 },
77 .resource = tmu1_resources,
78 .num_resources = ARRAY_SIZE(tmu1_resources),
79};
80
81static struct sh_timer_config tmu2_platform_data = {
82 .name = "TMU2",
83 .channel_offset = 0x1c,
84 .timer_bit = 2,
85 .clk = "tmu012_fck",
86};
87
88static struct resource tmu2_resources[] = {
89 [0] = {
90 .name = "TMU2",
91 .start = 0xffd80020,
92 .end = 0xffd8002f,
93 .flags = IORESOURCE_MEM,
94 },
95 [1] = {
96 .start = 30,
97 .flags = IORESOURCE_IRQ,
98 },
99};
100
101static struct platform_device tmu2_device = {
102 .name = "sh_tmu",
103 .id = 2,
104 .dev = {
105 .platform_data = &tmu2_platform_data,
106 },
107 .resource = tmu2_resources,
108 .num_resources = ARRAY_SIZE(tmu2_resources),
109};
110
111static struct sh_timer_config tmu3_platform_data = {
112 .name = "TMU3",
113 .channel_offset = 0x04,
114 .timer_bit = 0,
115 .clk = "tmu345_fck",
116};
117
118static struct resource tmu3_resources[] = {
119 [0] = {
120 .name = "TMU3",
121 .start = 0xffdc0008,
122 .end = 0xffdc0013,
123 .flags = IORESOURCE_MEM,
124 },
125 [1] = {
126 .start = 96,
127 .flags = IORESOURCE_IRQ,
128 },
129};
130
131static struct platform_device tmu3_device = {
132 .name = "sh_tmu",
133 .id = 3,
134 .dev = {
135 .platform_data = &tmu3_platform_data,
136 },
137 .resource = tmu3_resources,
138 .num_resources = ARRAY_SIZE(tmu3_resources),
139};
140
141static struct sh_timer_config tmu4_platform_data = {
142 .name = "TMU4",
143 .channel_offset = 0x10,
144 .timer_bit = 1,
145 .clk = "tmu345_fck",
146};
147
148static struct resource tmu4_resources[] = {
149 [0] = {
150 .name = "TMU4",
151 .start = 0xffdc0014,
152 .end = 0xffdc001f,
153 .flags = IORESOURCE_MEM,
154 },
155 [1] = {
156 .start = 97,
157 .flags = IORESOURCE_IRQ,
158 },
159};
160
161static struct platform_device tmu4_device = {
162 .name = "sh_tmu",
163 .id = 4,
164 .dev = {
165 .platform_data = &tmu4_platform_data,
166 },
167 .resource = tmu4_resources,
168 .num_resources = ARRAY_SIZE(tmu4_resources),
169};
170
171static struct sh_timer_config tmu5_platform_data = {
172 .name = "TMU5",
173 .channel_offset = 0x1c,
174 .timer_bit = 2,
175 .clk = "tmu345_fck",
176};
177
178static struct resource tmu5_resources[] = {
179 [0] = {
180 .name = "TMU5",
181 .start = 0xffdc0020,
182 .end = 0xffdc002b,
183 .flags = IORESOURCE_MEM,
184 },
185 [1] = {
186 .start = 98,
187 .flags = IORESOURCE_IRQ,
188 },
189};
190
191static struct platform_device tmu5_device = {
192 .name = "sh_tmu",
193 .id = 5,
194 .dev = {
195 .platform_data = &tmu5_platform_data,
196 },
197 .resource = tmu5_resources,
198 .num_resources = ARRAY_SIZE(tmu5_resources),
199};
200
18static struct plat_sci_port sci_platform_data[] = { 201static struct plat_sci_port sci_platform_data[] = {
19 { 202 {
20 .mapbase = 0xffea0000, 203 .mapbase = 0xffea0000,
21 .flags = UPF_BOOT_AUTOCONF, 204 .flags = UPF_BOOT_AUTOCONF,
22 .type = PORT_SCIF, 205 .type = PORT_SCIF,
23 .irqs = { 40, 40, 40, 40 }, 206 .irqs = { 40, 40, 40, 40 },
207 .clk = "scif_fck",
24 }, { 208 }, {
25 .mapbase = 0xffeb0000, 209 .mapbase = 0xffeb0000,
26 .flags = UPF_BOOT_AUTOCONF, 210 .flags = UPF_BOOT_AUTOCONF,
27 .type = PORT_SCIF, 211 .type = PORT_SCIF,
28 .irqs = { 44, 44, 44, 44 }, 212 .irqs = { 44, 44, 44, 44 },
213 .clk = "scif_fck",
29 }, { 214 }, {
30 .mapbase = 0xffec0000, 215 .mapbase = 0xffec0000,
31 .flags = UPF_BOOT_AUTOCONF, 216 .flags = UPF_BOOT_AUTOCONF,
32 .type = PORT_SCIF, 217 .type = PORT_SCIF,
33 .irqs = { 60, 60, 60, 60 }, 218 .irqs = { 60, 60, 60, 60 },
219 .clk = "scif_fck",
34 }, { 220 }, {
35 .mapbase = 0xffed0000, 221 .mapbase = 0xffed0000,
36 .flags = UPF_BOOT_AUTOCONF, 222 .flags = UPF_BOOT_AUTOCONF,
37 .type = PORT_SCIF, 223 .type = PORT_SCIF,
38 .irqs = { 61, 61, 61, 61 }, 224 .irqs = { 61, 61, 61, 61 },
225 .clk = "scif_fck",
39 }, { 226 }, {
40 .mapbase = 0xffee0000, 227 .mapbase = 0xffee0000,
41 .flags = UPF_BOOT_AUTOCONF, 228 .flags = UPF_BOOT_AUTOCONF,
42 .type = PORT_SCIF, 229 .type = PORT_SCIF,
43 .irqs = { 62, 62, 62, 62 }, 230 .irqs = { 62, 62, 62, 62 },
231 .clk = "scif_fck",
44 }, { 232 }, {
45 .mapbase = 0xffef0000, 233 .mapbase = 0xffef0000,
46 .flags = UPF_BOOT_AUTOCONF, 234 .flags = UPF_BOOT_AUTOCONF,
47 .type = PORT_SCIF, 235 .type = PORT_SCIF,
48 .irqs = { 63, 63, 63, 63 }, 236 .irqs = { 63, 63, 63, 63 },
237 .clk = "scif_fck",
49 }, { 238 }, {
50 .flags = 0, 239 .flags = 0,
51 } 240 }
@@ -60,6 +249,12 @@ static struct platform_device sci_device = {
60}; 249};
61 250
62static struct platform_device *sh7785_devices[] __initdata = { 251static struct platform_device *sh7785_devices[] __initdata = {
252 &tmu0_device,
253 &tmu1_device,
254 &tmu2_device,
255 &tmu3_device,
256 &tmu4_device,
257 &tmu5_device,
63 &sci_device, 258 &sci_device,
64}; 259};
65 260
@@ -70,6 +265,21 @@ static int __init sh7785_devices_setup(void)
70} 265}
71__initcall(sh7785_devices_setup); 266__initcall(sh7785_devices_setup);
72 267
268static struct platform_device *sh7785_early_devices[] __initdata = {
269 &tmu0_device,
270 &tmu1_device,
271 &tmu2_device,
272 &tmu3_device,
273 &tmu4_device,
274 &tmu5_device,
275};
276
277void __init plat_early_device_setup(void)
278{
279 early_platform_add_devices(sh7785_early_devices,
280 ARRAY_SIZE(sh7785_early_devices));
281}
282
73enum { 283enum {
74 UNUSED = 0, 284 UNUSED = 0,
75 285
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7786.c b/arch/sh/kernel/cpu/sh4a/setup-sh7786.c
index 90e8cfff55fd..93e0d2c017e8 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7786.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7786.c
@@ -3,6 +3,7 @@
3 * 3 *
4 * Copyright (C) 2009 Renesas Solutions Corp. 4 * Copyright (C) 2009 Renesas Solutions Corp.
5 * Kuninori Morimoto <morimoto.kuninori@renesas.com> 5 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
6 * Paul Mundt <paul.mundt@renesas.com>
6 * 7 *
7 * Based on SH7785 Setup 8 * Based on SH7785 Setup
8 * 9 *
@@ -19,6 +20,7 @@
19#include <linux/io.h> 20#include <linux/io.h>
20#include <linux/mm.h> 21#include <linux/mm.h>
21#include <linux/dma-mapping.h> 22#include <linux/dma-mapping.h>
23#include <linux/sh_timer.h>
22#include <asm/mmzone.h> 24#include <asm/mmzone.h>
23 25
24static struct plat_sci_port sci_platform_data[] = { 26static struct plat_sci_port sci_platform_data[] = {
@@ -69,6 +71,368 @@ static struct platform_device sci_device = {
69 }, 71 },
70}; 72};
71 73
74static struct sh_timer_config tmu0_platform_data = {
75 .name = "TMU0",
76 .channel_offset = 0x04,
77 .timer_bit = 0,
78 .clk = "peripheral_clk",
79 .clockevent_rating = 200,
80};
81
82static struct resource tmu0_resources[] = {
83 [0] = {
84 .name = "TMU0",
85 .start = 0xffd80008,
86 .end = 0xffd80013,
87 .flags = IORESOURCE_MEM,
88 },
89 [1] = {
90 .start = 16,
91 .flags = IORESOURCE_IRQ,
92 },
93};
94
95static struct platform_device tmu0_device = {
96 .name = "sh_tmu",
97 .id = 0,
98 .dev = {
99 .platform_data = &tmu0_platform_data,
100 },
101 .resource = tmu0_resources,
102 .num_resources = ARRAY_SIZE(tmu0_resources),
103};
104
105static struct sh_timer_config tmu1_platform_data = {
106 .name = "TMU1",
107 .channel_offset = 0x10,
108 .timer_bit = 1,
109 .clk = "peripheral_clk",
110 .clocksource_rating = 200,
111};
112
113static struct resource tmu1_resources[] = {
114 [0] = {
115 .name = "TMU1",
116 .start = 0xffd80014,
117 .end = 0xffd8001f,
118 .flags = IORESOURCE_MEM,
119 },
120 [1] = {
121 .start = 17,
122 .flags = IORESOURCE_IRQ,
123 },
124};
125
126static struct platform_device tmu1_device = {
127 .name = "sh_tmu",
128 .id = 1,
129 .dev = {
130 .platform_data = &tmu1_platform_data,
131 },
132 .resource = tmu1_resources,
133 .num_resources = ARRAY_SIZE(tmu1_resources),
134};
135
136static struct sh_timer_config tmu2_platform_data = {
137 .name = "TMU2",
138 .channel_offset = 0x1c,
139 .timer_bit = 2,
140 .clk = "peripheral_clk",
141};
142
143static struct resource tmu2_resources[] = {
144 [0] = {
145 .name = "TMU2",
146 .start = 0xffd80020,
147 .end = 0xffd8002f,
148 .flags = IORESOURCE_MEM,
149 },
150 [1] = {
151 .start = 18,
152 .flags = IORESOURCE_IRQ,
153 },
154};
155
156static struct platform_device tmu2_device = {
157 .name = "sh_tmu",
158 .id = 2,
159 .dev = {
160 .platform_data = &tmu2_platform_data,
161 },
162 .resource = tmu2_resources,
163 .num_resources = ARRAY_SIZE(tmu2_resources),
164};
165
166static struct sh_timer_config tmu3_platform_data = {
167 .name = "TMU3",
168 .channel_offset = 0x04,
169 .timer_bit = 0,
170 .clk = "peripheral_clk",
171};
172
173static struct resource tmu3_resources[] = {
174 [0] = {
175 .name = "TMU3",
176 .start = 0xffda0008,
177 .end = 0xffda0013,
178 .flags = IORESOURCE_MEM,
179 },
180 [1] = {
181 .start = 20,
182 .flags = IORESOURCE_IRQ,
183 },
184};
185
186static struct platform_device tmu3_device = {
187 .name = "sh_tmu",
188 .id = 3,
189 .dev = {
190 .platform_data = &tmu3_platform_data,
191 },
192 .resource = tmu3_resources,
193 .num_resources = ARRAY_SIZE(tmu3_resources),
194};
195
196static struct sh_timer_config tmu4_platform_data = {
197 .name = "TMU4",
198 .channel_offset = 0x10,
199 .timer_bit = 1,
200 .clk = "peripheral_clk",
201};
202
203static struct resource tmu4_resources[] = {
204 [0] = {
205 .name = "TMU4",
206 .start = 0xffda0014,
207 .end = 0xffda001f,
208 .flags = IORESOURCE_MEM,
209 },
210 [1] = {
211 .start = 21,
212 .flags = IORESOURCE_IRQ,
213 },
214};
215
216static struct platform_device tmu4_device = {
217 .name = "sh_tmu",
218 .id = 4,
219 .dev = {
220 .platform_data = &tmu4_platform_data,
221 },
222 .resource = tmu4_resources,
223 .num_resources = ARRAY_SIZE(tmu4_resources),
224};
225
226static struct sh_timer_config tmu5_platform_data = {
227 .name = "TMU5",
228 .channel_offset = 0x1c,
229 .timer_bit = 2,
230 .clk = "peripheral_clk",
231};
232
233static struct resource tmu5_resources[] = {
234 [0] = {
235 .name = "TMU5",
236 .start = 0xffda0020,
237 .end = 0xffda002b,
238 .flags = IORESOURCE_MEM,
239 },
240 [1] = {
241 .start = 22,
242 .flags = IORESOURCE_IRQ,
243 },
244};
245
246static struct platform_device tmu5_device = {
247 .name = "sh_tmu",
248 .id = 5,
249 .dev = {
250 .platform_data = &tmu5_platform_data,
251 },
252 .resource = tmu5_resources,
253 .num_resources = ARRAY_SIZE(tmu5_resources),
254};
255
256static struct sh_timer_config tmu6_platform_data = {
257 .name = "TMU6",
258 .channel_offset = 0x04,
259 .timer_bit = 0,
260 .clk = "peripheral_clk",
261};
262
263static struct resource tmu6_resources[] = {
264 [0] = {
265 .name = "TMU6",
266 .start = 0xffdc0008,
267 .end = 0xffdc0013,
268 .flags = IORESOURCE_MEM,
269 },
270 [1] = {
271 .start = 45,
272 .flags = IORESOURCE_IRQ,
273 },
274};
275
276static struct platform_device tmu6_device = {
277 .name = "sh_tmu",
278 .id = 6,
279 .dev = {
280 .platform_data = &tmu6_platform_data,
281 },
282 .resource = tmu6_resources,
283 .num_resources = ARRAY_SIZE(tmu6_resources),
284};
285
286static struct sh_timer_config tmu7_platform_data = {
287 .name = "TMU7",
288 .channel_offset = 0x10,
289 .timer_bit = 1,
290 .clk = "peripheral_clk",
291};
292
293static struct resource tmu7_resources[] = {
294 [0] = {
295 .name = "TMU7",
296 .start = 0xffdc0014,
297 .end = 0xffdc001f,
298 .flags = IORESOURCE_MEM,
299 },
300 [1] = {
301 .start = 45,
302 .flags = IORESOURCE_IRQ,
303 },
304};
305
306static struct platform_device tmu7_device = {
307 .name = "sh_tmu",
308 .id = 7,
309 .dev = {
310 .platform_data = &tmu7_platform_data,
311 },
312 .resource = tmu7_resources,
313 .num_resources = ARRAY_SIZE(tmu7_resources),
314};
315
316static struct sh_timer_config tmu8_platform_data = {
317 .name = "TMU8",
318 .channel_offset = 0x1c,
319 .timer_bit = 2,
320 .clk = "peripheral_clk",
321};
322
323static struct resource tmu8_resources[] = {
324 [0] = {
325 .name = "TMU8",
326 .start = 0xffdc0020,
327 .end = 0xffdc002b,
328 .flags = IORESOURCE_MEM,
329 },
330 [1] = {
331 .start = 45,
332 .flags = IORESOURCE_IRQ,
333 },
334};
335
336static struct platform_device tmu8_device = {
337 .name = "sh_tmu",
338 .id = 8,
339 .dev = {
340 .platform_data = &tmu8_platform_data,
341 },
342 .resource = tmu8_resources,
343 .num_resources = ARRAY_SIZE(tmu8_resources),
344};
345
346static struct sh_timer_config tmu9_platform_data = {
347 .name = "TMU9",
348 .channel_offset = 0x04,
349 .timer_bit = 0,
350 .clk = "peripheral_clk",
351};
352
353static struct resource tmu9_resources[] = {
354 [0] = {
355 .name = "TMU9",
356 .start = 0xffde0008,
357 .end = 0xffde0013,
358 .flags = IORESOURCE_MEM,
359 },
360 [1] = {
361 .start = 46,
362 .flags = IORESOURCE_IRQ,
363 },
364};
365
366static struct platform_device tmu9_device = {
367 .name = "sh_tmu",
368 .id = 9,
369 .dev = {
370 .platform_data = &tmu9_platform_data,
371 },
372 .resource = tmu9_resources,
373 .num_resources = ARRAY_SIZE(tmu9_resources),
374};
375
376static struct sh_timer_config tmu10_platform_data = {
377 .name = "TMU10",
378 .channel_offset = 0x10,
379 .timer_bit = 1,
380 .clk = "peripheral_clk",
381};
382
383static struct resource tmu10_resources[] = {
384 [0] = {
385 .name = "TMU10",
386 .start = 0xffde0014,
387 .end = 0xffde001f,
388 .flags = IORESOURCE_MEM,
389 },
390 [1] = {
391 .start = 46,
392 .flags = IORESOURCE_IRQ,
393 },
394};
395
396static struct platform_device tmu10_device = {
397 .name = "sh_tmu",
398 .id = 10,
399 .dev = {
400 .platform_data = &tmu10_platform_data,
401 },
402 .resource = tmu10_resources,
403 .num_resources = ARRAY_SIZE(tmu10_resources),
404};
405
406static struct sh_timer_config tmu11_platform_data = {
407 .name = "TMU11",
408 .channel_offset = 0x1c,
409 .timer_bit = 2,
410 .clk = "peripheral_clk",
411};
412
413static struct resource tmu11_resources[] = {
414 [0] = {
415 .name = "TMU11",
416 .start = 0xffde0020,
417 .end = 0xffde002b,
418 .flags = IORESOURCE_MEM,
419 },
420 [1] = {
421 .start = 46,
422 .flags = IORESOURCE_IRQ,
423 },
424};
425
426static struct platform_device tmu11_device = {
427 .name = "sh_tmu",
428 .id = 11,
429 .dev = {
430 .platform_data = &tmu11_platform_data,
431 },
432 .resource = tmu11_resources,
433 .num_resources = ARRAY_SIZE(tmu11_resources),
434};
435
72static struct resource usb_ohci_resources[] = { 436static struct resource usb_ohci_resources[] = {
73 [0] = { 437 [0] = {
74 .start = 0xffe70400, 438 .start = 0xffe70400,
@@ -94,6 +458,21 @@ static struct platform_device usb_ohci_device = {
94 .resource = usb_ohci_resources, 458 .resource = usb_ohci_resources,
95}; 459};
96 460
461static struct platform_device *sh7786_early_devices[] __initdata = {
462 &tmu0_device,
463 &tmu1_device,
464 &tmu2_device,
465 &tmu3_device,
466 &tmu4_device,
467 &tmu5_device,
468 &tmu6_device,
469 &tmu7_device,
470 &tmu8_device,
471 &tmu9_device,
472 &tmu10_device,
473 &tmu11_device,
474};
475
97static struct platform_device *sh7786_devices[] __initdata = { 476static struct platform_device *sh7786_devices[] __initdata = {
98 &sci_device, 477 &sci_device,
99 &usb_ohci_device, 478 &usb_ohci_device,
@@ -156,12 +535,26 @@ static void __init sh7786_usb_setup(void)
156 535
157static int __init sh7786_devices_setup(void) 536static int __init sh7786_devices_setup(void)
158{ 537{
538 int ret;
539
159 sh7786_usb_setup(); 540 sh7786_usb_setup();
541
542 ret = platform_add_devices(sh7786_early_devices,
543 ARRAY_SIZE(sh7786_early_devices));
544 if (unlikely(ret != 0))
545 return ret;
546
160 return platform_add_devices(sh7786_devices, 547 return platform_add_devices(sh7786_devices,
161 ARRAY_SIZE(sh7786_devices)); 548 ARRAY_SIZE(sh7786_devices));
162} 549}
163device_initcall(sh7786_devices_setup); 550device_initcall(sh7786_devices_setup);
164 551
552void __init plat_early_device_setup(void)
553{
554 early_platform_add_devices(sh7786_early_devices,
555 ARRAY_SIZE(sh7786_early_devices));
556}
557
165enum { 558enum {
166 UNUSED = 0, 559 UNUSED = 0,
167 560
diff --git a/arch/sh/kernel/cpu/sh4a/setup-shx3.c b/arch/sh/kernel/cpu/sh4a/setup-shx3.c
index bd35f32534b9..53c65fd9ccef 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-shx3.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-shx3.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * SH-X3 Setup 2 * SH-X3 Prototype Setup
3 * 3 *
4 * Copyright (C) 2007 Paul Mundt 4 * Copyright (C) 2007 - 2009 Paul Mundt
5 * 5 *
6 * This file is subject to the terms and conditions of the GNU General Public 6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive 7 * License. See the file "COPYING" in the main directory of this archive
@@ -12,6 +12,7 @@
12#include <linux/serial.h> 12#include <linux/serial.h>
13#include <linux/serial_sci.h> 13#include <linux/serial_sci.h>
14#include <linux/io.h> 14#include <linux/io.h>
15#include <linux/sh_timer.h>
15#include <asm/mmzone.h> 16#include <asm/mmzone.h>
16 17
17static struct plat_sci_port sci_platform_data[] = { 18static struct plat_sci_port sci_platform_data[] = {
@@ -48,17 +49,221 @@ static struct platform_device sci_device = {
48 }, 49 },
49}; 50};
50 51
52static struct sh_timer_config tmu0_platform_data = {
53 .name = "TMU0",
54 .channel_offset = 0x04,
55 .timer_bit = 0,
56 .clk = "peripheral_clk",
57 .clockevent_rating = 200,
58};
59
60static struct resource tmu0_resources[] = {
61 [0] = {
62 .name = "TMU0",
63 .start = 0xffc10008,
64 .end = 0xffc10013,
65 .flags = IORESOURCE_MEM,
66 },
67 [1] = {
68 .start = 16,
69 .flags = IORESOURCE_IRQ,
70 },
71};
72
73static struct platform_device tmu0_device = {
74 .name = "sh_tmu",
75 .id = 0,
76 .dev = {
77 .platform_data = &tmu0_platform_data,
78 },
79 .resource = tmu0_resources,
80 .num_resources = ARRAY_SIZE(tmu0_resources),
81};
82
83static struct sh_timer_config tmu1_platform_data = {
84 .name = "TMU1",
85 .channel_offset = 0x10,
86 .timer_bit = 1,
87 .clk = "peripheral_clk",
88 .clocksource_rating = 200,
89};
90
91static struct resource tmu1_resources[] = {
92 [0] = {
93 .name = "TMU1",
94 .start = 0xffc10014,
95 .end = 0xffc1001f,
96 .flags = IORESOURCE_MEM,
97 },
98 [1] = {
99 .start = 17,
100 .flags = IORESOURCE_IRQ,
101 },
102};
103
104static struct platform_device tmu1_device = {
105 .name = "sh_tmu",
106 .id = 1,
107 .dev = {
108 .platform_data = &tmu1_platform_data,
109 },
110 .resource = tmu1_resources,
111 .num_resources = ARRAY_SIZE(tmu1_resources),
112};
113
114static struct sh_timer_config tmu2_platform_data = {
115 .name = "TMU2",
116 .channel_offset = 0x1c,
117 .timer_bit = 2,
118 .clk = "peripheral_clk",
119};
120
121static struct resource tmu2_resources[] = {
122 [0] = {
123 .name = "TMU2",
124 .start = 0xffc10020,
125 .end = 0xffc1002f,
126 .flags = IORESOURCE_MEM,
127 },
128 [1] = {
129 .start = 18,
130 .flags = IORESOURCE_IRQ,
131 },
132};
133
134static struct platform_device tmu2_device = {
135 .name = "sh_tmu",
136 .id = 2,
137 .dev = {
138 .platform_data = &tmu2_platform_data,
139 },
140 .resource = tmu2_resources,
141 .num_resources = ARRAY_SIZE(tmu2_resources),
142};
143
144static struct sh_timer_config tmu3_platform_data = {
145 .name = "TMU3",
146 .channel_offset = 0x04,
147 .timer_bit = 0,
148 .clk = "peripheral_clk",
149};
150
151static struct resource tmu3_resources[] = {
152 [0] = {
153 .name = "TMU3",
154 .start = 0xffc20008,
155 .end = 0xffc20013,
156 .flags = IORESOURCE_MEM,
157 },
158 [1] = {
159 .start = 19,
160 .flags = IORESOURCE_IRQ,
161 },
162};
163
164static struct platform_device tmu3_device = {
165 .name = "sh_tmu",
166 .id = 3,
167 .dev = {
168 .platform_data = &tmu3_platform_data,
169 },
170 .resource = tmu3_resources,
171 .num_resources = ARRAY_SIZE(tmu3_resources),
172};
173
174static struct sh_timer_config tmu4_platform_data = {
175 .name = "TMU4",
176 .channel_offset = 0x10,
177 .timer_bit = 1,
178 .clk = "peripheral_clk",
179};
180
181static struct resource tmu4_resources[] = {
182 [0] = {
183 .name = "TMU4",
184 .start = 0xffc20014,
185 .end = 0xffc2001f,
186 .flags = IORESOURCE_MEM,
187 },
188 [1] = {
189 .start = 20,
190 .flags = IORESOURCE_IRQ,
191 },
192};
193
194static struct platform_device tmu4_device = {
195 .name = "sh_tmu",
196 .id = 4,
197 .dev = {
198 .platform_data = &tmu4_platform_data,
199 },
200 .resource = tmu4_resources,
201 .num_resources = ARRAY_SIZE(tmu4_resources),
202};
203
204static struct sh_timer_config tmu5_platform_data = {
205 .name = "TMU5",
206 .channel_offset = 0x1c,
207 .timer_bit = 2,
208 .clk = "peripheral_clk",
209};
210
211static struct resource tmu5_resources[] = {
212 [0] = {
213 .name = "TMU5",
214 .start = 0xffc20020,
215 .end = 0xffc2002b,
216 .flags = IORESOURCE_MEM,
217 },
218 [1] = {
219 .start = 21,
220 .flags = IORESOURCE_IRQ,
221 },
222};
223
224static struct platform_device tmu5_device = {
225 .name = "sh_tmu",
226 .id = 5,
227 .dev = {
228 .platform_data = &tmu5_platform_data,
229 },
230 .resource = tmu5_resources,
231 .num_resources = ARRAY_SIZE(tmu5_resources),
232};
233
234static struct platform_device *shx3_early_devices[] __initdata = {
235 &tmu0_device,
236 &tmu1_device,
237 &tmu2_device,
238 &tmu3_device,
239 &tmu4_device,
240 &tmu5_device,
241};
242
51static struct platform_device *shx3_devices[] __initdata = { 243static struct platform_device *shx3_devices[] __initdata = {
52 &sci_device, 244 &sci_device,
53}; 245};
54 246
55static int __init shx3_devices_setup(void) 247static int __init shx3_devices_setup(void)
56{ 248{
249 int ret;
250
251 ret = platform_add_devices(shx3_early_devices,
252 ARRAY_SIZE(shx3_early_devices));
253 if (unlikely(ret != 0))
254 return ret;
255
57 return platform_add_devices(shx3_devices, 256 return platform_add_devices(shx3_devices,
58 ARRAY_SIZE(shx3_devices)); 257 ARRAY_SIZE(shx3_devices));
59} 258}
60__initcall(shx3_devices_setup); 259__initcall(shx3_devices_setup);
61 260
261void __init plat_early_device_setup(void)
262{
263 early_platform_add_devices(shx3_early_devices,
264 ARRAY_SIZE(shx3_early_devices));
265}
266
62enum { 267enum {
63 UNUSED = 0, 268 UNUSED = 0,
64 269
diff --git a/arch/sh/kernel/cpu/sh5/Makefile b/arch/sh/kernel/cpu/sh5/Makefile
index ce4602ea23a8..a184a31e686e 100644
--- a/arch/sh/kernel/cpu/sh5/Makefile
+++ b/arch/sh/kernel/cpu/sh5/Makefile
@@ -6,6 +6,9 @@ obj-y := entry.o probe.o switchto.o
6obj-$(CONFIG_SH_FPU) += fpu.o 6obj-$(CONFIG_SH_FPU) += fpu.o
7obj-$(CONFIG_KALLSYMS) += unwind.o 7obj-$(CONFIG_KALLSYMS) += unwind.o
8 8
9# CPU subtype setup
10obj-$(CONFIG_CPU_SH5) += setup-sh5.o
11
9# Primary on-chip clocks (common) 12# Primary on-chip clocks (common)
10clock-$(CONFIG_CPU_SH5) := clock-sh5.o 13clock-$(CONFIG_CPU_SH5) := clock-sh5.o
11 14
diff --git a/arch/sh/kernel/cpu/sh5/clock-sh5.c b/arch/sh/kernel/cpu/sh5/clock-sh5.c
index 52c49248833a..7f864ebc51d3 100644
--- a/arch/sh/kernel/cpu/sh5/clock-sh5.c
+++ b/arch/sh/kernel/cpu/sh5/clock-sh5.c
@@ -32,30 +32,30 @@ static struct clk_ops sh5_master_clk_ops = {
32 .init = master_clk_init, 32 .init = master_clk_init,
33}; 33};
34 34
35static void module_clk_recalc(struct clk *clk) 35static unsigned long module_clk_recalc(struct clk *clk)
36{ 36{
37 int idx = (ctrl_inw(cprc_base) >> 12) & 0x0007; 37 int idx = (ctrl_inw(cprc_base) >> 12) & 0x0007;
38 clk->rate = clk->parent->rate / ifc_table[idx]; 38 return clk->parent->rate / ifc_table[idx];
39} 39}
40 40
41static struct clk_ops sh5_module_clk_ops = { 41static struct clk_ops sh5_module_clk_ops = {
42 .recalc = module_clk_recalc, 42 .recalc = module_clk_recalc,
43}; 43};
44 44
45static void bus_clk_recalc(struct clk *clk) 45static unsigned long bus_clk_recalc(struct clk *clk)
46{ 46{
47 int idx = (ctrl_inw(cprc_base) >> 3) & 0x0007; 47 int idx = (ctrl_inw(cprc_base) >> 3) & 0x0007;
48 clk->rate = clk->parent->rate / ifc_table[idx]; 48 return clk->parent->rate / ifc_table[idx];
49} 49}
50 50
51static struct clk_ops sh5_bus_clk_ops = { 51static struct clk_ops sh5_bus_clk_ops = {
52 .recalc = bus_clk_recalc, 52 .recalc = bus_clk_recalc,
53}; 53};
54 54
55static void cpu_clk_recalc(struct clk *clk) 55static unsigned long cpu_clk_recalc(struct clk *clk)
56{ 56{
57 int idx = (ctrl_inw(cprc_base) & 0x0007); 57 int idx = (ctrl_inw(cprc_base) & 0x0007);
58 clk->rate = clk->parent->rate / ifc_table[idx]; 58 return clk->parent->rate / ifc_table[idx];
59} 59}
60 60
61static struct clk_ops sh5_cpu_clk_ops = { 61static struct clk_ops sh5_cpu_clk_ops = {
@@ -71,7 +71,7 @@ static struct clk_ops *sh5_clk_ops[] = {
71 71
72void __init arch_init_clk_ops(struct clk_ops **ops, int idx) 72void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
73{ 73{
74 cprc_base = onchip_remap(CPRC_BASE, 1024, "CPRC"); 74 cprc_base = (unsigned long)ioremap_nocache(CPRC_BASE, 1024);
75 BUG_ON(!cprc_base); 75 BUG_ON(!cprc_base);
76 76
77 if (idx < ARRAY_SIZE(sh5_clk_ops)) 77 if (idx < ARRAY_SIZE(sh5_clk_ops))
diff --git a/arch/sh/kernel/cpu/sh5/entry.S b/arch/sh/kernel/cpu/sh5/entry.S
index 7e49cb812f8b..b0aacf675258 100644
--- a/arch/sh/kernel/cpu/sh5/entry.S
+++ b/arch/sh/kernel/cpu/sh5/entry.S
@@ -812,27 +812,6 @@ no_underflow:
812 ! exceptions 812 ! exceptions
813 add SP, ZERO, r14 813 add SP, ZERO, r14
814 814
815#ifdef CONFIG_POOR_MANS_STRACE
816 /* We've pushed all the registers now, so only r2-r4 hold anything
817 * useful. Move them into callee save registers */
818 or r2, ZERO, r28
819 or r3, ZERO, r29
820 or r4, ZERO, r30
821
822 /* Preserve r2 as the event code */
823 movi evt_debug, r3
824 ori r3, 1, r3
825 ptabs r3, tr0
826
827 or SP, ZERO, r6
828 getcon TRA, r5
829 blink tr0, LINK
830
831 or r28, ZERO, r2
832 or r29, ZERO, r3
833 or r30, ZERO, r4
834#endif
835
836 /* For syscall and debug race condition, get TRA now */ 815 /* For syscall and debug race condition, get TRA now */
837 getcon TRA, r5 816 getcon TRA, r5
838 817
@@ -887,11 +866,6 @@ no_underflow:
887 */ 866 */
888 .global ret_from_irq 867 .global ret_from_irq
889ret_from_irq: 868ret_from_irq:
890#ifdef CONFIG_POOR_MANS_STRACE
891 pta evt_debug_ret_from_irq, tr0
892 ori SP, 0, r2
893 blink tr0, LINK
894#endif
895 ld.q SP, FRAME_S(FSSR), r6 869 ld.q SP, FRAME_S(FSSR), r6
896 shlri r6, 30, r6 870 shlri r6, 30, r6
897 andi r6, 1, r6 871 andi r6, 1, r6
@@ -905,12 +879,6 @@ ret_from_irq:
905ret_from_exception: 879ret_from_exception:
906 preempt_stop() 880 preempt_stop()
907 881
908#ifdef CONFIG_POOR_MANS_STRACE
909 pta evt_debug_ret_from_exc, tr0
910 ori SP, 0, r2
911 blink tr0, LINK
912#endif
913
914 ld.q SP, FRAME_S(FSSR), r6 882 ld.q SP, FRAME_S(FSSR), r6
915 shlri r6, 30, r6 883 shlri r6, 30, r6
916 andi r6, 1, r6 884 andi r6, 1, r6
@@ -1236,18 +1204,6 @@ syscall_bad:
1236 .global syscall_ret 1204 .global syscall_ret
1237syscall_ret: 1205syscall_ret:
1238 st.q SP, FRAME_R(9), r2 /* Expecting SP back to BASIC frame */ 1206 st.q SP, FRAME_R(9), r2 /* Expecting SP back to BASIC frame */
1239
1240#ifdef CONFIG_POOR_MANS_STRACE
1241 /* nothing useful in registers at this point */
1242
1243 movi evt_debug2, r5
1244 ori r5, 1, r5
1245 ptabs r5, tr0
1246 ld.q SP, FRAME_R(9), r2
1247 or SP, ZERO, r3
1248 blink tr0, LINK
1249#endif
1250
1251 ld.q SP, FRAME_S(FSPC), r2 1207 ld.q SP, FRAME_S(FSPC), r2
1252 addi r2, 4, r2 /* Move PC, being pre-execution event */ 1208 addi r2, 4, r2 /* Move PC, being pre-execution event */
1253 st.q SP, FRAME_S(FSPC), r2 1209 st.q SP, FRAME_S(FSPC), r2
@@ -1268,25 +1224,12 @@ ret_from_fork:
1268 ptabs r5, tr0 1224 ptabs r5, tr0
1269 blink tr0, LINK 1225 blink tr0, LINK
1270 1226
1271#ifdef CONFIG_POOR_MANS_STRACE
1272 /* nothing useful in registers at this point */
1273
1274 movi evt_debug2, r5
1275 ori r5, 1, r5
1276 ptabs r5, tr0
1277 ld.q SP, FRAME_R(9), r2
1278 or SP, ZERO, r3
1279 blink tr0, LINK
1280#endif
1281
1282 ld.q SP, FRAME_S(FSPC), r2 1227 ld.q SP, FRAME_S(FSPC), r2
1283 addi r2, 4, r2 /* Move PC, being pre-execution event */ 1228 addi r2, 4, r2 /* Move PC, being pre-execution event */
1284 st.q SP, FRAME_S(FSPC), r2 1229 st.q SP, FRAME_S(FSPC), r2
1285 pta ret_from_syscall, tr0 1230 pta ret_from_syscall, tr0
1286 blink tr0, ZERO 1231 blink tr0, ZERO
1287 1232
1288
1289
1290syscall_allowed: 1233syscall_allowed:
1291 /* Use LINK to deflect the exit point, default is syscall_ret */ 1234 /* Use LINK to deflect the exit point, default is syscall_ret */
1292 pta syscall_ret, tr0 1235 pta syscall_ret, tr0
@@ -1410,8 +1353,8 @@ peek_real_address_q:
1410 r2(out) : result quadword 1353 r2(out) : result quadword
1411 1354
1412 This is provided as a cheapskate way of manipulating device 1355 This is provided as a cheapskate way of manipulating device
1413 registers for debugging (to avoid the need to onchip_remap the debug 1356 registers for debugging (to avoid the need to ioremap the debug
1414 module, and to avoid the need to onchip_remap the watchpoint 1357 module, and to avoid the need to ioremap the watchpoint
1415 controller in a way that identity maps sufficient bits to avoid the 1358 controller in a way that identity maps sufficient bits to avoid the
1416 SH5-101 cut2 silicon defect). 1359 SH5-101 cut2 silicon defect).
1417 1360
@@ -1459,8 +1402,8 @@ poke_real_address_q:
1459 r3 : quadword value to write. 1402 r3 : quadword value to write.
1460 1403
1461 This is provided as a cheapskate way of manipulating device 1404 This is provided as a cheapskate way of manipulating device
1462 registers for debugging (to avoid the need to onchip_remap the debug 1405 registers for debugging (to avoid the need to ioremap the debug
1463 module, and to avoid the need to onchip_remap the watchpoint 1406 module, and to avoid the need to ioremap the watchpoint
1464 controller in a way that identity maps sufficient bits to avoid the 1407 controller in a way that identity maps sufficient bits to avoid the
1465 SH5-101 cut2 silicon defect). 1408 SH5-101 cut2 silicon defect).
1466 1409
diff --git a/arch/sh/kernel/cpu/sh5/setup-sh5.c b/arch/sh/kernel/cpu/sh5/setup-sh5.c
new file mode 100644
index 000000000000..f5ff1ac57fc2
--- /dev/null
+++ b/arch/sh/kernel/cpu/sh5/setup-sh5.c
@@ -0,0 +1,195 @@
1/*
2 * SH5-101/SH5-103 CPU Setup
3 *
4 * Copyright (C) 2009 Paul Mundt
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10#include <linux/platform_device.h>
11#include <linux/init.h>
12#include <linux/serial.h>
13#include <linux/serial_sci.h>
14#include <linux/io.h>
15#include <linux/mm.h>
16#include <linux/sh_timer.h>
17#include <asm/addrspace.h>
18
19static struct plat_sci_port sci_platform_data[] = {
20 {
21 .mapbase = PHYS_PERIPHERAL_BLOCK + 0x01030000,
22 .flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP,
23 .type = PORT_SCIF,
24 .irqs = { 39, 40, 42, 0 },
25 }, {
26 .flags = 0,
27 }
28};
29
30static struct platform_device sci_device = {
31 .name = "sh-sci",
32 .id = -1,
33 .dev = {
34 .platform_data = sci_platform_data,
35 },
36};
37
38static struct resource rtc_resources[] = {
39 [0] = {
40 .start = PHYS_PERIPHERAL_BLOCK + 0x01040000,
41 .end = PHYS_PERIPHERAL_BLOCK + 0x01040000 + 0x58 - 1,
42 .flags = IORESOURCE_IO,
43 },
44 [1] = {
45 /* Period IRQ */
46 .start = IRQ_PRI,
47 .flags = IORESOURCE_IRQ,
48 },
49 [2] = {
50 /* Carry IRQ */
51 .start = IRQ_CUI,
52 .flags = IORESOURCE_IRQ,
53 },
54 [3] = {
55 /* Alarm IRQ */
56 .start = IRQ_ATI,
57 .flags = IORESOURCE_IRQ,
58 },
59};
60
61static struct platform_device rtc_device = {
62 .name = "sh-rtc",
63 .id = -1,
64 .num_resources = ARRAY_SIZE(rtc_resources),
65 .resource = rtc_resources,
66};
67
68#define TMU_BLOCK_OFF 0x01020000
69#define TMU_BASE PHYS_PERIPHERAL_BLOCK + TMU_BLOCK_OFF
70#define TMU0_BASE (TMU_BASE + 0x8 + (0xc * 0x0))
71#define TMU1_BASE (TMU_BASE + 0x8 + (0xc * 0x1))
72#define TMU2_BASE (TMU_BASE + 0x8 + (0xc * 0x2))
73
74static struct sh_timer_config tmu0_platform_data = {
75 .name = "TMU0",
76 .channel_offset = 0x04,
77 .timer_bit = 0,
78 .clk = "peripheral_clk",
79 .clockevent_rating = 200,
80};
81
82static struct resource tmu0_resources[] = {
83 [0] = {
84 .name = "TMU0",
85 .start = TMU0_BASE,
86 .end = TMU0_BASE + 0xc - 1,
87 .flags = IORESOURCE_MEM,
88 },
89 [1] = {
90 .start = IRQ_TUNI0,
91 .flags = IORESOURCE_IRQ,
92 },
93};
94
95static struct platform_device tmu0_device = {
96 .name = "sh_tmu",
97 .id = 0,
98 .dev = {
99 .platform_data = &tmu0_platform_data,
100 },
101 .resource = tmu0_resources,
102 .num_resources = ARRAY_SIZE(tmu0_resources),
103};
104
105static struct sh_timer_config tmu1_platform_data = {
106 .name = "TMU1",
107 .channel_offset = 0x10,
108 .timer_bit = 1,
109 .clk = "peripheral_clk",
110 .clocksource_rating = 200,
111};
112
113static struct resource tmu1_resources[] = {
114 [0] = {
115 .name = "TMU1",
116 .start = TMU1_BASE,
117 .end = TMU1_BASE + 0xc - 1,
118 .flags = IORESOURCE_MEM,
119 },
120 [1] = {
121 .start = IRQ_TUNI1,
122 .flags = IORESOURCE_IRQ,
123 },
124};
125
126static struct platform_device tmu1_device = {
127 .name = "sh_tmu",
128 .id = 1,
129 .dev = {
130 .platform_data = &tmu1_platform_data,
131 },
132 .resource = tmu1_resources,
133 .num_resources = ARRAY_SIZE(tmu1_resources),
134};
135
136static struct sh_timer_config tmu2_platform_data = {
137 .name = "TMU2",
138 .channel_offset = 0x1c,
139 .timer_bit = 2,
140 .clk = "peripheral_clk",
141};
142
143static struct resource tmu2_resources[] = {
144 [0] = {
145 .name = "TMU2",
146 .start = TMU2_BASE,
147 .end = TMU2_BASE + 0xc - 1,
148 .flags = IORESOURCE_MEM,
149 },
150 [1] = {
151 .start = IRQ_TUNI2,
152 .flags = IORESOURCE_IRQ,
153 },
154};
155
156static struct platform_device tmu2_device = {
157 .name = "sh_tmu",
158 .id = 2,
159 .dev = {
160 .platform_data = &tmu2_platform_data,
161 },
162 .resource = tmu2_resources,
163 .num_resources = ARRAY_SIZE(tmu2_resources),
164};
165
166static struct platform_device *sh5_early_devices[] __initdata = {
167 &tmu0_device,
168 &tmu1_device,
169 &tmu2_device,
170};
171
172static struct platform_device *sh5_devices[] __initdata = {
173 &sci_device,
174 &rtc_device,
175};
176
177static int __init sh5_devices_setup(void)
178{
179 int ret;
180
181 ret = platform_add_devices(sh5_early_devices,
182 ARRAY_SIZE(sh5_early_devices));
183 if (unlikely(ret != 0))
184 return ret;
185
186 return platform_add_devices(sh5_devices,
187 ARRAY_SIZE(sh5_devices));
188}
189__initcall(sh5_devices_setup);
190
191void __init plat_early_device_setup(void)
192{
193 early_platform_add_devices(sh5_early_devices,
194 ARRAY_SIZE(sh5_early_devices));
195}
diff --git a/arch/sh/kernel/io.c b/arch/sh/kernel/io.c
index 29cf4588fc05..4f85fffaa557 100644
--- a/arch/sh/kernel/io.c
+++ b/arch/sh/kernel/io.c
@@ -12,6 +12,7 @@
12 * for more details. 12 * for more details.
13 */ 13 */
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/pci.h>
15#include <asm/machvec.h> 16#include <asm/machvec.h>
16#include <asm/io.h> 17#include <asm/io.h>
17 18
diff --git a/arch/sh/kernel/io_trapped.c b/arch/sh/kernel/io_trapped.c
index c22853b059ef..77dfecb64373 100644
--- a/arch/sh/kernel/io_trapped.c
+++ b/arch/sh/kernel/io_trapped.c
@@ -267,7 +267,7 @@ static struct mem_access trapped_io_access = {
267int handle_trapped_io(struct pt_regs *regs, unsigned long address) 267int handle_trapped_io(struct pt_regs *regs, unsigned long address)
268{ 268{
269 mm_segment_t oldfs; 269 mm_segment_t oldfs;
270 opcode_t instruction; 270 insn_size_t instruction;
271 int tmp; 271 int tmp;
272 272
273 if (!lookup_tiop(address)) 273 if (!lookup_tiop(address))
diff --git a/arch/sh/kernel/irq.c b/arch/sh/kernel/irq.c
index 3f1372eb0091..3d09062f4682 100644
--- a/arch/sh/kernel/irq.c
+++ b/arch/sh/kernel/irq.c
@@ -31,39 +31,64 @@ void ack_bad_irq(unsigned int irq)
31} 31}
32 32
33#if defined(CONFIG_PROC_FS) 33#if defined(CONFIG_PROC_FS)
34/*
35 * /proc/interrupts printing:
36 */
37static int show_other_interrupts(struct seq_file *p, int prec)
38{
39 seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
40 return 0;
41}
42
34int show_interrupts(struct seq_file *p, void *v) 43int show_interrupts(struct seq_file *p, void *v)
35{ 44{
36 int i = *(loff_t *) v, j; 45 unsigned long flags, any_count = 0;
37 struct irqaction * action; 46 int i = *(loff_t *)v, j, prec;
38 unsigned long flags; 47 struct irqaction *action;
48 struct irq_desc *desc;
49
50 if (i > nr_irqs)
51 return 0;
52
53 for (prec = 3, j = 1000; prec < 10 && j <= nr_irqs; ++prec)
54 j *= 10;
55
56 if (i == nr_irqs)
57 return show_other_interrupts(p, prec);
39 58
40 if (i == 0) { 59 if (i == 0) {
41 seq_puts(p, " "); 60 seq_printf(p, "%*s", prec + 8, "");
42 for_each_online_cpu(j) 61 for_each_online_cpu(j)
43 seq_printf(p, "CPU%d ",j); 62 seq_printf(p, "CPU%-8d", j);
44 seq_putc(p, '\n'); 63 seq_putc(p, '\n');
45 } 64 }
46 65
47 if (i < sh_mv.mv_nr_irqs) { 66 desc = irq_to_desc(i);
48 spin_lock_irqsave(&irq_desc[i].lock, flags); 67 if (!desc)
49 action = irq_desc[i].action; 68 return 0;
50 if (!action) 69
51 goto unlock; 70 spin_lock_irqsave(&desc->lock, flags);
52 seq_printf(p, "%3d: ",i); 71 for_each_online_cpu(j)
53 for_each_online_cpu(j) 72 any_count |= kstat_irqs_cpu(i, j);
54 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j)); 73 action = desc->action;
55 seq_printf(p, " %14s", irq_desc[i].chip->name); 74 if (!action && !any_count)
56 seq_printf(p, "-%-8s", irq_desc[i].name); 75 goto out;
57 seq_printf(p, " %s", action->name); 76
77 seq_printf(p, "%*d: ", prec, i);
78 for_each_online_cpu(j)
79 seq_printf(p, "%10u ", kstat_irqs_cpu(i, j));
80 seq_printf(p, " %14s", desc->chip->name);
81 seq_printf(p, "-%-8s", desc->name);
58 82
59 for (action=action->next; action; action = action->next) 83 if (action) {
84 seq_printf(p, " %s", action->name);
85 while ((action = action->next) != NULL)
60 seq_printf(p, ", %s", action->name); 86 seq_printf(p, ", %s", action->name);
61 seq_putc(p, '\n'); 87 }
62unlock:
63 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
64 } else if (i == sh_mv.mv_nr_irqs)
65 seq_printf(p, "Err: %10u\n", atomic_read(&irq_err_count));
66 88
89 seq_putc(p, '\n');
90out:
91 spin_unlock_irqrestore(&desc->lock, flags);
67 return 0; 92 return 0;
68} 93}
69#endif 94#endif
@@ -254,3 +279,11 @@ void __init init_IRQ(void)
254 279
255 irq_ctx_init(smp_processor_id()); 280 irq_ctx_init(smp_processor_id());
256} 281}
282
283#ifdef CONFIG_SPARSE_IRQ
284int __init arch_probe_nr_irqs(void)
285{
286 nr_irqs = sh_mv.mv_nr_irqs;
287 return 0;
288}
289#endif
diff --git a/arch/sh/kernel/kgdb.c b/arch/sh/kernel/kgdb.c
index 7c747e7d71b8..305aad742aec 100644
--- a/arch/sh/kernel/kgdb.c
+++ b/arch/sh/kernel/kgdb.c
@@ -47,7 +47,7 @@ char in_nmi = 0; /* Set during NMI to prevent re-entry */
47/* Calculate the new address for after a step */ 47/* Calculate the new address for after a step */
48static short *get_step_address(struct pt_regs *linux_regs) 48static short *get_step_address(struct pt_regs *linux_regs)
49{ 49{
50 opcode_t op = __raw_readw(linux_regs->pc); 50 insn_size_t op = __raw_readw(linux_regs->pc);
51 long addr; 51 long addr;
52 52
53 /* BT */ 53 /* BT */
@@ -134,7 +134,7 @@ static short *get_step_address(struct pt_regs *linux_regs)
134 */ 134 */
135 135
136static unsigned long stepped_address; 136static unsigned long stepped_address;
137static opcode_t stepped_opcode; 137static insn_size_t stepped_opcode;
138 138
139static void do_single_step(struct pt_regs *linux_regs) 139static void do_single_step(struct pt_regs *linux_regs)
140{ 140{
diff --git a/arch/sh/kernel/timers/timer-broadcast.c b/arch/sh/kernel/localtimer.c
index 96e8eaea1e62..96e8eaea1e62 100644
--- a/arch/sh/kernel/timers/timer-broadcast.c
+++ b/arch/sh/kernel/localtimer.c
diff --git a/arch/sh/kernel/machvec.c b/arch/sh/kernel/machvec.c
index c1ea41e5812a..548f6607fd0f 100644
--- a/arch/sh/kernel/machvec.c
+++ b/arch/sh/kernel/machvec.c
@@ -129,6 +129,7 @@ void __init sh_mv_setup(void)
129 mv_set(ioport_map); 129 mv_set(ioport_map);
130 mv_set(ioport_unmap); 130 mv_set(ioport_unmap);
131 mv_set(irq_demux); 131 mv_set(irq_demux);
132 mv_set(mode_pins);
132 133
133 if (!sh_mv.mv_nr_irqs) 134 if (!sh_mv.mv_nr_irqs)
134 sh_mv.mv_nr_irqs = NR_IRQS; 135 sh_mv.mv_nr_irqs = NR_IRQS;
diff --git a/arch/sh/kernel/module.c b/arch/sh/kernel/module.c
index c43081039dd5..c19b0f7d2cc1 100644
--- a/arch/sh/kernel/module.c
+++ b/arch/sh/kernel/module.c
@@ -90,7 +90,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
90 * SHmedia, the LSB of the symbol needs to be asserted 90 * SHmedia, the LSB of the symbol needs to be asserted
91 * for the CPU to be in SHmedia mode when it starts executing 91 * for the CPU to be in SHmedia mode when it starts executing
92 * the branch target. */ 92 * the branch target. */
93 relocation |= (sym->st_other & 4); 93 relocation |= !!(sym->st_other & 4);
94#endif 94#endif
95 95
96 switch (ELF32_R_TYPE(rel[i].r_info)) { 96 switch (ELF32_R_TYPE(rel[i].r_info)) {
diff --git a/arch/sh/kernel/process_32.c b/arch/sh/kernel/process_32.c
index 6d94725d22f2..9289ede29c7b 100644
--- a/arch/sh/kernel/process_32.c
+++ b/arch/sh/kernel/process_32.c
@@ -251,7 +251,8 @@ static void ubc_set_tracing(int asid, unsigned long pc)
251 251
252 if (current_cpu_data.type == CPU_SH7729 || 252 if (current_cpu_data.type == CPU_SH7729 ||
253 current_cpu_data.type == CPU_SH7710 || 253 current_cpu_data.type == CPU_SH7710 ||
254 current_cpu_data.type == CPU_SH7712) { 254 current_cpu_data.type == CPU_SH7712 ||
255 current_cpu_data.type == CPU_SH7203){
255 ctrl_outw(BBR_INST | BBR_READ | BBR_CPU, UBC_BBRA); 256 ctrl_outw(BBR_INST | BBR_READ | BBR_CPU, UBC_BBRA);
256 ctrl_outl(BRCR_PCBA | BRCR_PCTE, UBC_BRCR); 257 ctrl_outl(BRCR_PCBA | BRCR_PCTE, UBC_BRCR);
257 } else { 258 } else {
@@ -407,6 +408,7 @@ asmlinkage void break_point_trap(void)
407#else 408#else
408 ctrl_outw(0, UBC_BBRA); 409 ctrl_outw(0, UBC_BBRA);
409 ctrl_outw(0, UBC_BBRB); 410 ctrl_outw(0, UBC_BBRB);
411 ctrl_outl(0, UBC_BRCR);
410#endif 412#endif
411 current->thread.ubc_pc = 0; 413 current->thread.ubc_pc = 0;
412 ubc_usercnt -= 1; 414 ubc_usercnt -= 1;
diff --git a/arch/sh/kernel/ptrace_32.c b/arch/sh/kernel/ptrace_32.c
index f7b22dd83b0c..3392e835a374 100644
--- a/arch/sh/kernel/ptrace_32.c
+++ b/arch/sh/kernel/ptrace_32.c
@@ -334,6 +334,14 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
334 [(addr - (long)&dummy->fpu) >> 2]; 334 [(addr - (long)&dummy->fpu) >> 2];
335 } else if (addr == (long) &dummy->u_fpvalid) 335 } else if (addr == (long) &dummy->u_fpvalid)
336 tmp = !!tsk_used_math(child); 336 tmp = !!tsk_used_math(child);
337 else if (addr == PT_TEXT_ADDR)
338 tmp = child->mm->start_code;
339 else if (addr == PT_DATA_ADDR)
340 tmp = child->mm->start_data;
341 else if (addr == PT_TEXT_END_ADDR)
342 tmp = child->mm->end_code;
343 else if (addr == PT_TEXT_LEN)
344 tmp = child->mm->end_code - child->mm->start_code;
337 else 345 else
338 tmp = 0; 346 tmp = 0;
339 ret = put_user(tmp, datap); 347 ret = put_user(tmp, datap);
diff --git a/arch/sh/kernel/setup.c b/arch/sh/kernel/setup.c
index 04a6004fccc4..dd38338553ef 100644
--- a/arch/sh/kernel/setup.c
+++ b/arch/sh/kernel/setup.c
@@ -29,6 +29,7 @@
29#include <linux/mmzone.h> 29#include <linux/mmzone.h>
30#include <linux/clk.h> 30#include <linux/clk.h>
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/platform_device.h>
32#include <asm/uaccess.h> 33#include <asm/uaccess.h>
33#include <asm/io.h> 34#include <asm/io.h>
34#include <asm/page.h> 35#include <asm/page.h>
@@ -155,7 +156,7 @@ static void __init reserve_crashkernel(void)
155 &crash_size, &crash_base); 156 &crash_size, &crash_base);
156 if (ret == 0 && crash_size) { 157 if (ret == 0 && crash_size) {
157 if (crash_base <= 0) { 158 if (crash_base <= 0) {
158 vp = alloc_bootmem_nopanic(crash_size); 159 vp = alloc_bootmem_nopanic(crash_size);
159 if (!vp) { 160 if (!vp) {
160 printk(KERN_INFO "crashkernel allocation " 161 printk(KERN_INFO "crashkernel allocation "
161 "failed\n"); 162 "failed\n");
@@ -184,7 +185,6 @@ static inline void __init reserve_crashkernel(void)
184{} 185{}
185#endif 186#endif
186 187
187#ifndef CONFIG_GENERIC_CALIBRATE_DELAY
188void __cpuinit calibrate_delay(void) 188void __cpuinit calibrate_delay(void)
189{ 189{
190 struct clk *clk = clk_get(NULL, "cpu_clk"); 190 struct clk *clk = clk_get(NULL, "cpu_clk");
@@ -200,7 +200,6 @@ void __cpuinit calibrate_delay(void)
200 (loops_per_jiffy/(5000/HZ)) % 100, 200 (loops_per_jiffy/(5000/HZ)) % 100,
201 loops_per_jiffy); 201 loops_per_jiffy);
202} 202}
203#endif
204 203
205void __init __add_active_range(unsigned int nid, unsigned long start_pfn, 204void __init __add_active_range(unsigned int nid, unsigned long start_pfn,
206 unsigned long end_pfn) 205 unsigned long end_pfn)
@@ -328,6 +327,10 @@ static int __init parse_elfcorehdr(char *arg)
328early_param("elfcorehdr", parse_elfcorehdr); 327early_param("elfcorehdr", parse_elfcorehdr);
329#endif 328#endif
330 329
330void __init __attribute__ ((weak)) plat_early_device_setup(void)
331{
332}
333
331void __init setup_arch(char **cmdline_p) 334void __init setup_arch(char **cmdline_p)
332{ 335{
333 enable_mmu(); 336 enable_mmu();
@@ -381,6 +384,8 @@ void __init setup_arch(char **cmdline_p)
381 384
382 parse_early_param(); 385 parse_early_param();
383 386
387 plat_early_device_setup();
388
384 sh_mv_setup(); 389 sh_mv_setup();
385 390
386 /* 391 /*
@@ -415,6 +420,18 @@ void __init setup_arch(char **cmdline_p)
415#endif 420#endif
416} 421}
417 422
423/* processor boot mode configuration */
424int generic_mode_pins(void)
425{
426 pr_warning("generic_mode_pins(): missing mode pin configuration\n");
427 return 0;
428}
429
430int test_mode_pin(int pin)
431{
432 return sh_mv.mv_mode_pins() & pin;
433}
434
418static const char *cpu_name[] = { 435static const char *cpu_name[] = {
419 [CPU_SH7201] = "SH7201", 436 [CPU_SH7201] = "SH7201",
420 [CPU_SH7203] = "SH7203", [CPU_SH7263] = "SH7263", 437 [CPU_SH7203] = "SH7203", [CPU_SH7263] = "SH7263",
@@ -435,7 +452,8 @@ static const char *cpu_name[] = {
435 [CPU_SH7722] = "SH7722", [CPU_SHX3] = "SH-X3", 452 [CPU_SH7722] = "SH7722", [CPU_SHX3] = "SH-X3",
436 [CPU_SH5_101] = "SH5-101", [CPU_SH5_103] = "SH5-103", 453 [CPU_SH5_101] = "SH5-101", [CPU_SH5_103] = "SH5-103",
437 [CPU_MXG] = "MX-G", [CPU_SH7723] = "SH7723", 454 [CPU_MXG] = "MX-G", [CPU_SH7723] = "SH7723",
438 [CPU_SH7366] = "SH7366", [CPU_SH_NONE] = "Unknown" 455 [CPU_SH7366] = "SH7366", [CPU_SH7724] = "SH7724",
456 [CPU_SH_NONE] = "Unknown"
439}; 457};
440 458
441const char *get_cpu_subtype(struct sh_cpuinfo *c) 459const char *get_cpu_subtype(struct sh_cpuinfo *c)
diff --git a/arch/sh/kernel/sh_ksyms_32.c b/arch/sh/kernel/sh_ksyms_32.c
index 528de2955c81..fcc5de31f83b 100644
--- a/arch/sh/kernel/sh_ksyms_32.c
+++ b/arch/sh/kernel/sh_ksyms_32.c
@@ -19,14 +19,10 @@
19#include <asm/ftrace.h> 19#include <asm/ftrace.h>
20 20
21extern int dump_fpu(struct pt_regs *, elf_fpregset_t *); 21extern int dump_fpu(struct pt_regs *, elf_fpregset_t *);
22extern struct hw_interrupt_type no_irq_type;
23 22
24/* platform dependent support */ 23/* platform dependent support */
25EXPORT_SYMBOL(dump_fpu); 24EXPORT_SYMBOL(dump_fpu);
26EXPORT_SYMBOL(kernel_thread); 25EXPORT_SYMBOL(kernel_thread);
27EXPORT_SYMBOL(irq_desc);
28EXPORT_SYMBOL(no_irq_type);
29
30EXPORT_SYMBOL(strlen); 26EXPORT_SYMBOL(strlen);
31 27
32/* PCI exports */ 28/* PCI exports */
@@ -41,11 +37,6 @@ EXPORT_SYMBOL(memcpy);
41EXPORT_SYMBOL(memset); 37EXPORT_SYMBOL(memset);
42EXPORT_SYMBOL(memmove); 38EXPORT_SYMBOL(memmove);
43EXPORT_SYMBOL(__copy_user); 39EXPORT_SYMBOL(__copy_user);
44
45#ifdef CONFIG_MMU
46EXPORT_SYMBOL(get_vm_area);
47#endif
48
49EXPORT_SYMBOL(__udelay); 40EXPORT_SYMBOL(__udelay);
50EXPORT_SYMBOL(__ndelay); 41EXPORT_SYMBOL(__ndelay);
51EXPORT_SYMBOL(__const_udelay); 42EXPORT_SYMBOL(__const_udelay);
diff --git a/arch/sh/kernel/sh_ksyms_64.c b/arch/sh/kernel/sh_ksyms_64.c
index 0d74d6b8774e..8f54ef0cfbca 100644
--- a/arch/sh/kernel/sh_ksyms_64.c
+++ b/arch/sh/kernel/sh_ksyms_64.c
@@ -76,5 +76,7 @@ EXPORT_SYMBOL(strcpy);
76#define DECLARE_EXPORT(name) extern void name(void);EXPORT_SYMBOL(name) 76#define DECLARE_EXPORT(name) extern void name(void);EXPORT_SYMBOL(name)
77 77
78DECLARE_EXPORT(__sdivsi3); 78DECLARE_EXPORT(__sdivsi3);
79DECLARE_EXPORT(__sdivsi3_1);
80DECLARE_EXPORT(__sdivsi3_2);
79DECLARE_EXPORT(__udivsi3); 81DECLARE_EXPORT(__udivsi3);
80DECLARE_EXPORT(__div_table); 82DECLARE_EXPORT(__div_table);
diff --git a/arch/sh/kernel/syscalls_32.S b/arch/sh/kernel/syscalls_32.S
index 05202edd8e21..a9fff9f731ec 100644
--- a/arch/sh/kernel/syscalls_32.S
+++ b/arch/sh/kernel/syscalls_32.S
@@ -350,4 +350,5 @@ ENTRY(sys_call_table)
350 .long sys_pipe2 350 .long sys_pipe2
351 .long sys_inotify_init1 351 .long sys_inotify_init1
352 .long sys_preadv 352 .long sys_preadv
353 .long sys_writev 353 .long sys_pwritev
354 .long sys_rt_tgsigqueueinfo /* 335 */
diff --git a/arch/sh/kernel/syscalls_64.S b/arch/sh/kernel/syscalls_64.S
index a083609f9284..75c1889af1ed 100644
--- a/arch/sh/kernel/syscalls_64.S
+++ b/arch/sh/kernel/syscalls_64.S
@@ -389,3 +389,4 @@ sys_call_table:
389 .long sys_inotify_init1 /* 360 */ 389 .long sys_inotify_init1 /* 360 */
390 .long sys_preadv 390 .long sys_preadv
391 .long sys_pwritev 391 .long sys_pwritev
392 .long sys_rt_tgsigqueueinfo
diff --git a/arch/sh/kernel/time.c b/arch/sh/kernel/time.c
new file mode 100644
index 000000000000..2edde32c764b
--- /dev/null
+++ b/arch/sh/kernel/time.c
@@ -0,0 +1,125 @@
1/*
2 * arch/sh/kernel/time.c
3 *
4 * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
5 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
6 * Copyright (C) 2002 - 2009 Paul Mundt
7 * Copyright (C) 2002 M. R. Brown <mrbrown@linux-sh.org>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
12 */
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/profile.h>
17#include <linux/timex.h>
18#include <linux/sched.h>
19#include <linux/clockchips.h>
20#include <linux/platform_device.h>
21#include <linux/smp.h>
22#include <linux/rtc.h>
23#include <asm/clock.h>
24#include <asm/rtc.h>
25
26/* Dummy RTC ops */
27static void null_rtc_get_time(struct timespec *tv)
28{
29 tv->tv_sec = mktime(2000, 1, 1, 0, 0, 0);
30 tv->tv_nsec = 0;
31}
32
33static int null_rtc_set_time(const time_t secs)
34{
35 return 0;
36}
37
38void (*rtc_sh_get_time)(struct timespec *) = null_rtc_get_time;
39int (*rtc_sh_set_time)(const time_t) = null_rtc_set_time;
40
41#ifdef CONFIG_GENERIC_CMOS_UPDATE
42unsigned long read_persistent_clock(void)
43{
44 struct timespec tv;
45 rtc_sh_get_time(&tv);
46 return tv.tv_sec;
47}
48
49int update_persistent_clock(struct timespec now)
50{
51 return rtc_sh_set_time(now.tv_sec);
52}
53#endif
54
55unsigned int get_rtc_time(struct rtc_time *tm)
56{
57 if (rtc_sh_get_time != null_rtc_get_time) {
58 struct timespec tv;
59
60 rtc_sh_get_time(&tv);
61 rtc_time_to_tm(tv.tv_sec, tm);
62 }
63
64 return RTC_24H;
65}
66EXPORT_SYMBOL(get_rtc_time);
67
68int set_rtc_time(struct rtc_time *tm)
69{
70 unsigned long secs;
71
72 rtc_tm_to_time(tm, &secs);
73 return rtc_sh_set_time(secs);
74}
75EXPORT_SYMBOL(set_rtc_time);
76
77static int __init rtc_generic_init(void)
78{
79 struct platform_device *pdev;
80
81 if (rtc_sh_get_time == null_rtc_get_time)
82 return -ENODEV;
83
84 pdev = platform_device_register_simple("rtc-generic", -1, NULL, 0);
85 if (IS_ERR(pdev))
86 return PTR_ERR(pdev);
87
88 return 0;
89}
90module_init(rtc_generic_init);
91
92void (*board_time_init)(void);
93
94unsigned long long sched_clock(void)
95{
96 return (jiffies_64 - INITIAL_JIFFIES) * (NSEC_PER_SEC / HZ);
97}
98
99static void __init sh_late_time_init(void)
100{
101 /*
102 * Make sure all compiled-in early timers register themselves.
103 * Run probe() for one "earlytimer" device.
104 */
105 early_platform_driver_register_all("earlytimer");
106 early_platform_driver_probe("earlytimer", 1, 0);
107}
108
109void __init time_init(void)
110{
111 if (board_time_init)
112 board_time_init();
113
114 clk_init();
115
116 rtc_sh_get_time(&xtime);
117 set_normalized_timespec(&wall_to_monotonic,
118 -xtime.tv_sec, -xtime.tv_nsec);
119
120#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
121 local_timer_setup(smp_processor_id());
122#endif
123
124 late_time_init = sh_late_time_init;
125}
diff --git a/arch/sh/kernel/time_32.c b/arch/sh/kernel/time_32.c
deleted file mode 100644
index 1700d2465f6c..000000000000
--- a/arch/sh/kernel/time_32.c
+++ /dev/null
@@ -1,240 +0,0 @@
1/*
2 * arch/sh/kernel/time_32.c
3 *
4 * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
5 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
6 * Copyright (C) 2002 - 2008 Paul Mundt
7 * Copyright (C) 2002 M. R. Brown <mrbrown@linux-sh.org>
8 *
9 * Some code taken from i386 version.
10 * Copyright (C) 1991, 1992, 1995 Linus Torvalds
11 */
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/profile.h>
16#include <linux/timex.h>
17#include <linux/sched.h>
18#include <linux/clockchips.h>
19#include <linux/mc146818rtc.h> /* for rtc_lock */
20#include <linux/smp.h>
21#include <asm/clock.h>
22#include <asm/rtc.h>
23#include <asm/timer.h>
24#include <asm/kgdb.h>
25
26struct sys_timer *sys_timer;
27
28/* Move this somewhere more sensible.. */
29DEFINE_SPINLOCK(rtc_lock);
30EXPORT_SYMBOL(rtc_lock);
31
32/* Dummy RTC ops */
33static void null_rtc_get_time(struct timespec *tv)
34{
35 tv->tv_sec = mktime(2000, 1, 1, 0, 0, 0);
36 tv->tv_nsec = 0;
37}
38
39static int null_rtc_set_time(const time_t secs)
40{
41 return 0;
42}
43
44void (*rtc_sh_get_time)(struct timespec *) = null_rtc_get_time;
45int (*rtc_sh_set_time)(const time_t) = null_rtc_set_time;
46
47#ifndef CONFIG_GENERIC_TIME
48void do_gettimeofday(struct timeval *tv)
49{
50 unsigned long flags;
51 unsigned long seq;
52 unsigned long usec, sec;
53
54 do {
55 /*
56 * Turn off IRQs when grabbing xtime_lock, so that
57 * the sys_timer get_offset code doesn't have to handle it.
58 */
59 seq = read_seqbegin_irqsave(&xtime_lock, flags);
60 usec = get_timer_offset();
61 sec = xtime.tv_sec;
62 usec += xtime.tv_nsec / NSEC_PER_USEC;
63 } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
64
65 while (usec >= 1000000) {
66 usec -= 1000000;
67 sec++;
68 }
69
70 tv->tv_sec = sec;
71 tv->tv_usec = usec;
72}
73EXPORT_SYMBOL(do_gettimeofday);
74
75int do_settimeofday(struct timespec *tv)
76{
77 time_t wtm_sec, sec = tv->tv_sec;
78 long wtm_nsec, nsec = tv->tv_nsec;
79
80 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
81 return -EINVAL;
82
83 write_seqlock_irq(&xtime_lock);
84 /*
85 * This is revolting. We need to set "xtime" correctly. However, the
86 * value in this location is the value at the most recent update of
87 * wall time. Discover what correction gettimeofday() would have
88 * made, and then undo it!
89 */
90 nsec -= get_timer_offset() * NSEC_PER_USEC;
91
92 wtm_sec = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
93 wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
94
95 set_normalized_timespec(&xtime, sec, nsec);
96 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
97
98 ntp_clear();
99 write_sequnlock_irq(&xtime_lock);
100 clock_was_set();
101
102 return 0;
103}
104EXPORT_SYMBOL(do_settimeofday);
105#endif /* !CONFIG_GENERIC_TIME */
106
107/* last time the RTC clock got updated */
108static long last_rtc_update;
109
110/*
111 * handle_timer_tick() needs to keep up the real-time clock,
112 * as well as call the "do_timer()" routine every clocktick
113 */
114void handle_timer_tick(void)
115{
116 if (current->pid)
117 profile_tick(CPU_PROFILING);
118
119 /*
120 * Here we are in the timer irq handler. We just have irqs locally
121 * disabled but we don't know if the timer_bh is running on the other
122 * CPU. We need to avoid to SMP race with it. NOTE: we don' t need
123 * the irq version of write_lock because as just said we have irq
124 * locally disabled. -arca
125 */
126 write_seqlock(&xtime_lock);
127 do_timer(1);
128
129 /*
130 * If we have an externally synchronized Linux clock, then update
131 * RTC clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
132 * called as close as possible to 500 ms before the new second starts.
133 */
134 if (ntp_synced() &&
135 xtime.tv_sec > last_rtc_update + 660 &&
136 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
137 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
138 if (rtc_sh_set_time(xtime.tv_sec) == 0)
139 last_rtc_update = xtime.tv_sec;
140 else
141 /* do it again in 60s */
142 last_rtc_update = xtime.tv_sec - 600;
143 }
144 write_sequnlock(&xtime_lock);
145
146#ifndef CONFIG_SMP
147 update_process_times(user_mode(get_irq_regs()));
148#endif
149}
150
151#ifdef CONFIG_PM
152int timer_suspend(struct sys_device *dev, pm_message_t state)
153{
154 struct sys_timer *sys_timer = container_of(dev, struct sys_timer, dev);
155
156 sys_timer->ops->stop();
157
158 return 0;
159}
160
161int timer_resume(struct sys_device *dev)
162{
163 struct sys_timer *sys_timer = container_of(dev, struct sys_timer, dev);
164
165 sys_timer->ops->start();
166
167 return 0;
168}
169#else
170#define timer_suspend NULL
171#define timer_resume NULL
172#endif
173
174static struct sysdev_class timer_sysclass = {
175 .name = "timer",
176 .suspend = timer_suspend,
177 .resume = timer_resume,
178};
179
180static int __init timer_init_sysfs(void)
181{
182 int ret;
183
184 if (!sys_timer)
185 return 0;
186
187 ret = sysdev_class_register(&timer_sysclass);
188 if (ret != 0)
189 return ret;
190
191 sys_timer->dev.cls = &timer_sysclass;
192 return sysdev_register(&sys_timer->dev);
193}
194device_initcall(timer_init_sysfs);
195
196void (*board_time_init)(void);
197
198struct clocksource clocksource_sh = {
199 .name = "SuperH",
200};
201
202#ifdef CONFIG_GENERIC_TIME
203unsigned long long sched_clock(void)
204{
205 unsigned long long cycles;
206
207 /* jiffies based sched_clock if no clocksource is installed */
208 if (!clocksource_sh.rating)
209 return (unsigned long long)jiffies * (NSEC_PER_SEC / HZ);
210
211 cycles = clocksource_sh.read(&clocksource_sh);
212 return cyc2ns(&clocksource_sh, cycles);
213}
214#endif
215
216void __init time_init(void)
217{
218 if (board_time_init)
219 board_time_init();
220
221 clk_init();
222
223 rtc_sh_get_time(&xtime);
224 set_normalized_timespec(&wall_to_monotonic,
225 -xtime.tv_sec, -xtime.tv_nsec);
226
227#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
228 local_timer_setup(smp_processor_id());
229#endif
230
231 /*
232 * Find the timer to use as the system timer, it will be
233 * initialized for us.
234 */
235 sys_timer = get_sys_timer();
236 if (unlikely(!sys_timer))
237 panic("System timer missing.\n");
238
239 printk(KERN_INFO "Using %s for system timer\n", sys_timer->name);
240}
diff --git a/arch/sh/kernel/time_64.c b/arch/sh/kernel/time_64.c
deleted file mode 100644
index 988c77c37231..000000000000
--- a/arch/sh/kernel/time_64.c
+++ /dev/null
@@ -1,363 +0,0 @@
1/*
2 * arch/sh/kernel/time_64.c
3 *
4 * Copyright (C) 2000, 2001 Paolo Alberelli
5 * Copyright (C) 2003 - 2007 Paul Mundt
6 * Copyright (C) 2003 Richard Curnow
7 *
8 * Original TMU/RTC code taken from sh version.
9 * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
10 * Some code taken from i386 version.
11 * Copyright (C) 1991, 1992, 1995 Linus Torvalds
12 *
13 * This file is subject to the terms and conditions of the GNU General Public
14 * License. See the file "COPYING" in the main directory of this archive
15 * for more details.
16 */
17#include <linux/errno.h>
18#include <linux/rwsem.h>
19#include <linux/sched.h>
20#include <linux/kernel.h>
21#include <linux/param.h>
22#include <linux/string.h>
23#include <linux/mm.h>
24#include <linux/interrupt.h>
25#include <linux/time.h>
26#include <linux/delay.h>
27#include <linux/init.h>
28#include <linux/profile.h>
29#include <linux/smp.h>
30#include <linux/module.h>
31#include <linux/bcd.h>
32#include <linux/timex.h>
33#include <linux/irq.h>
34#include <linux/io.h>
35#include <linux/platform_device.h>
36#include <cpu/registers.h> /* required by inline __asm__ stmt. */
37#include <cpu/irq.h>
38#include <asm/addrspace.h>
39#include <asm/processor.h>
40#include <asm/uaccess.h>
41#include <asm/delay.h>
42#include <asm/clock.h>
43
44#define TMU_TOCR_INIT 0x00
45#define TMU0_TCR_INIT 0x0020
46#define TMU_TSTR_INIT 1
47#define TMU_TSTR_OFF 0
48
49/* Real Time Clock */
50#define RTC_BLOCK_OFF 0x01040000
51#define RTC_BASE PHYS_PERIPHERAL_BLOCK + RTC_BLOCK_OFF
52#define RTC_RCR1_CIE 0x10 /* Carry Interrupt Enable */
53#define RTC_RCR1 (rtc_base + 0x38)
54
55/* Time Management Unit */
56#define TMU_BLOCK_OFF 0x01020000
57#define TMU_BASE PHYS_PERIPHERAL_BLOCK + TMU_BLOCK_OFF
58#define TMU0_BASE tmu_base + 0x8 + (0xc * 0x0)
59#define TMU1_BASE tmu_base + 0x8 + (0xc * 0x1)
60#define TMU2_BASE tmu_base + 0x8 + (0xc * 0x2)
61
62#define TMU_TOCR tmu_base+0x0 /* Byte access */
63#define TMU_TSTR tmu_base+0x4 /* Byte access */
64
65#define TMU0_TCOR TMU0_BASE+0x0 /* Long access */
66#define TMU0_TCNT TMU0_BASE+0x4 /* Long access */
67#define TMU0_TCR TMU0_BASE+0x8 /* Word access */
68
69#define TICK_SIZE (tick_nsec / 1000)
70
71static unsigned long tmu_base, rtc_base;
72unsigned long cprc_base;
73
74/* Variables to allow interpolation of time of day to resolution better than a
75 * jiffy. */
76
77/* This is effectively protected by xtime_lock */
78static unsigned long ctc_last_interrupt;
79static unsigned long long usecs_per_jiffy = 1000000/HZ; /* Approximation */
80
81#define CTC_JIFFY_SCALE_SHIFT 40
82
83/* 2**CTC_JIFFY_SCALE_SHIFT / ctc_ticks_per_jiffy */
84static unsigned long long scaled_recip_ctc_ticks_per_jiffy;
85
86/* Estimate number of microseconds that have elapsed since the last timer tick,
87 by scaling the delta that has occurred in the CTC register.
88
89 WARNING WARNING WARNING : This algorithm relies on the CTC decrementing at
90 the CPU clock rate. If the CPU sleeps, the CTC stops counting. Bear this
91 in mind if enabling SLEEP_WORKS in process.c. In that case, this algorithm
92 probably needs to use TMU.TCNT0 instead. This will work even if the CPU is
93 sleeping, though will be coarser.
94
95 FIXME : What if usecs_per_tick is moving around too much, e.g. if an adjtime
96 is running or if the freq or tick arguments of adjtimex are modified after
97 we have calibrated the scaling factor? This will result in either a jump at
98 the end of a tick period, or a wrap backwards at the start of the next one,
99 if the application is reading the time of day often enough. I think we
100 ought to do better than this. For this reason, usecs_per_jiffy is left
101 separated out in the calculation below. This allows some future hook into
102 the adjtime-related stuff in kernel/timer.c to remove this hazard.
103
104*/
105
106static unsigned long usecs_since_tick(void)
107{
108 unsigned long long current_ctc;
109 long ctc_ticks_since_interrupt;
110 unsigned long long ull_ctc_ticks_since_interrupt;
111 unsigned long result;
112
113 unsigned long long mul1_out;
114 unsigned long long mul1_out_high;
115 unsigned long long mul2_out_low, mul2_out_high;
116
117 /* Read CTC register */
118 asm ("getcon cr62, %0" : "=r" (current_ctc));
119 /* Note, the CTC counts down on each CPU clock, not up.
120 Note(2), use long type to get correct wraparound arithmetic when
121 the counter crosses zero. */
122 ctc_ticks_since_interrupt = (long) ctc_last_interrupt - (long) current_ctc;
123 ull_ctc_ticks_since_interrupt = (unsigned long long) ctc_ticks_since_interrupt;
124
125 /* Inline assembly to do 32x32x32->64 multiplier */
126 asm volatile ("mulu.l %1, %2, %0" :
127 "=r" (mul1_out) :
128 "r" (ull_ctc_ticks_since_interrupt), "r" (usecs_per_jiffy));
129
130 mul1_out_high = mul1_out >> 32;
131
132 asm volatile ("mulu.l %1, %2, %0" :
133 "=r" (mul2_out_low) :
134 "r" (mul1_out), "r" (scaled_recip_ctc_ticks_per_jiffy));
135
136#if 1
137 asm volatile ("mulu.l %1, %2, %0" :
138 "=r" (mul2_out_high) :
139 "r" (mul1_out_high), "r" (scaled_recip_ctc_ticks_per_jiffy));
140#endif
141
142 result = (unsigned long) (((mul2_out_high << 32) + mul2_out_low) >> CTC_JIFFY_SCALE_SHIFT);
143
144 return result;
145}
146
147void do_gettimeofday(struct timeval *tv)
148{
149 unsigned long flags;
150 unsigned long seq;
151 unsigned long usec, sec;
152
153 do {
154 seq = read_seqbegin_irqsave(&xtime_lock, flags);
155 usec = usecs_since_tick();
156 sec = xtime.tv_sec;
157 usec += xtime.tv_nsec / 1000;
158 } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
159
160 while (usec >= 1000000) {
161 usec -= 1000000;
162 sec++;
163 }
164
165 tv->tv_sec = sec;
166 tv->tv_usec = usec;
167}
168EXPORT_SYMBOL(do_gettimeofday);
169
170int do_settimeofday(struct timespec *tv)
171{
172 time_t wtm_sec, sec = tv->tv_sec;
173 long wtm_nsec, nsec = tv->tv_nsec;
174
175 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
176 return -EINVAL;
177
178 write_seqlock_irq(&xtime_lock);
179 /*
180 * This is revolting. We need to set "xtime" correctly. However, the
181 * value in this location is the value at the most recent update of
182 * wall time. Discover what correction gettimeofday() would have
183 * made, and then undo it!
184 */
185 nsec -= 1000 * usecs_since_tick();
186
187 wtm_sec = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
188 wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
189
190 set_normalized_timespec(&xtime, sec, nsec);
191 set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
192
193 ntp_clear();
194 write_sequnlock_irq(&xtime_lock);
195 clock_was_set();
196
197 return 0;
198}
199EXPORT_SYMBOL(do_settimeofday);
200
201/* Dummy RTC ops */
202static void null_rtc_get_time(struct timespec *tv)
203{
204 tv->tv_sec = mktime(2000, 1, 1, 0, 0, 0);
205 tv->tv_nsec = 0;
206}
207
208static int null_rtc_set_time(const time_t secs)
209{
210 return 0;
211}
212
213void (*rtc_sh_get_time)(struct timespec *) = null_rtc_get_time;
214int (*rtc_sh_set_time)(const time_t) = null_rtc_set_time;
215
216/* last time the RTC clock got updated */
217static long last_rtc_update;
218
219/*
220 * timer_interrupt() needs to keep up the real-time clock,
221 * as well as call the "do_timer()" routine every clocktick
222 */
223static inline void do_timer_interrupt(void)
224{
225 unsigned long long current_ctc;
226
227 if (current->pid)
228 profile_tick(CPU_PROFILING);
229
230 /*
231 * Here we are in the timer irq handler. We just have irqs locally
232 * disabled but we don't know if the timer_bh is running on the other
233 * CPU. We need to avoid to SMP race with it. NOTE: we don' t need
234 * the irq version of write_lock because as just said we have irq
235 * locally disabled. -arca
236 */
237 write_seqlock(&xtime_lock);
238 asm ("getcon cr62, %0" : "=r" (current_ctc));
239 ctc_last_interrupt = (unsigned long) current_ctc;
240
241 do_timer(1);
242
243 /*
244 * If we have an externally synchronized Linux clock, then update
245 * RTC clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
246 * called as close as possible to 500 ms before the new second starts.
247 */
248 if (ntp_synced() &&
249 xtime.tv_sec > last_rtc_update + 660 &&
250 (xtime.tv_nsec / 1000) >= 500000 - ((unsigned) TICK_SIZE) / 2 &&
251 (xtime.tv_nsec / 1000) <= 500000 + ((unsigned) TICK_SIZE) / 2) {
252 if (rtc_sh_set_time(xtime.tv_sec) == 0)
253 last_rtc_update = xtime.tv_sec;
254 else
255 /* do it again in 60 s */
256 last_rtc_update = xtime.tv_sec - 600;
257 }
258 write_sequnlock(&xtime_lock);
259
260#ifndef CONFIG_SMP
261 update_process_times(user_mode(get_irq_regs()));
262#endif
263}
264
265/*
266 * This is the same as the above, except we _also_ save the current
267 * Time Stamp Counter value at the time of the timer interrupt, so that
268 * we later on can estimate the time of day more exactly.
269 */
270static irqreturn_t timer_interrupt(int irq, void *dev_id)
271{
272 unsigned long timer_status;
273
274 /* Clear UNF bit */
275 timer_status = ctrl_inw(TMU0_TCR);
276 timer_status &= ~0x100;
277 ctrl_outw(timer_status, TMU0_TCR);
278
279 do_timer_interrupt();
280
281 return IRQ_HANDLED;
282}
283
284static struct irqaction irq0 = {
285 .handler = timer_interrupt,
286 .flags = IRQF_DISABLED,
287 .name = "timer",
288};
289
290void __init time_init(void)
291{
292 unsigned long interval;
293 struct clk *clk;
294
295 tmu_base = onchip_remap(TMU_BASE, 1024, "TMU");
296 if (!tmu_base) {
297 panic("Unable to remap TMU\n");
298 }
299
300 rtc_base = onchip_remap(RTC_BASE, 1024, "RTC");
301 if (!rtc_base) {
302 panic("Unable to remap RTC\n");
303 }
304
305 clk = clk_get(NULL, "cpu_clk");
306 scaled_recip_ctc_ticks_per_jiffy = ((1ULL << CTC_JIFFY_SCALE_SHIFT) /
307 (unsigned long long)(clk_get_rate(clk) / HZ));
308
309 rtc_sh_get_time(&xtime);
310
311 setup_irq(TIMER_IRQ, &irq0);
312
313 clk = clk_get(NULL, "module_clk");
314 interval = (clk_get_rate(clk)/(HZ*4));
315
316 printk("Interval = %ld\n", interval);
317
318 /* Start TMU0 */
319 ctrl_outb(TMU_TSTR_OFF, TMU_TSTR);
320 ctrl_outb(TMU_TOCR_INIT, TMU_TOCR);
321 ctrl_outw(TMU0_TCR_INIT, TMU0_TCR);
322 ctrl_outl(interval, TMU0_TCOR);
323 ctrl_outl(interval, TMU0_TCNT);
324 ctrl_outb(TMU_TSTR_INIT, TMU_TSTR);
325}
326
327static struct resource rtc_resources[] = {
328 [0] = {
329 /* RTC base, filled in by rtc_init */
330 .flags = IORESOURCE_IO,
331 },
332 [1] = {
333 /* Period IRQ */
334 .start = IRQ_PRI,
335 .flags = IORESOURCE_IRQ,
336 },
337 [2] = {
338 /* Carry IRQ */
339 .start = IRQ_CUI,
340 .flags = IORESOURCE_IRQ,
341 },
342 [3] = {
343 /* Alarm IRQ */
344 .start = IRQ_ATI,
345 .flags = IORESOURCE_IRQ,
346 },
347};
348
349static struct platform_device rtc_device = {
350 .name = "sh-rtc",
351 .id = -1,
352 .num_resources = ARRAY_SIZE(rtc_resources),
353 .resource = rtc_resources,
354};
355
356static int __init rtc_init(void)
357{
358 rtc_resources[0].start = rtc_base;
359 rtc_resources[0].end = rtc_resources[0].start + 0x58 - 1;
360
361 return platform_device_register(&rtc_device);
362}
363device_initcall(rtc_init);
diff --git a/arch/sh/kernel/timers/Makefile b/arch/sh/kernel/timers/Makefile
deleted file mode 100644
index 0b7f8577193f..000000000000
--- a/arch/sh/kernel/timers/Makefile
+++ /dev/null
@@ -1,11 +0,0 @@
1#
2# Makefile for the various Linux/SuperH timers
3#
4
5obj-y := timer.o
6
7obj-$(CONFIG_SH_TMU) += timer-tmu.o
8obj-$(CONFIG_SH_MTU2) += timer-mtu2.o
9obj-$(CONFIG_SH_CMT) += timer-cmt.o
10
11obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) += timer-broadcast.o
diff --git a/arch/sh/kernel/timers/timer-cmt.c b/arch/sh/kernel/timers/timer-cmt.c
deleted file mode 100644
index 9aa348658ae3..000000000000
--- a/arch/sh/kernel/timers/timer-cmt.c
+++ /dev/null
@@ -1,188 +0,0 @@
1/*
2 * arch/sh/kernel/timers/timer-cmt.c - CMT Timer Support
3 *
4 * Copyright (C) 2005 Yoshinori Sato
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/init.h>
12#include <linux/kernel.h>
13#include <linux/interrupt.h>
14#include <linux/seqlock.h>
15#include <asm/timer.h>
16#include <asm/rtc.h>
17#include <asm/io.h>
18#include <asm/irq.h>
19#include <asm/clock.h>
20
21#if defined(CONFIG_CPU_SUBTYPE_SH7619)
22#define CMT_CMSTR 0xf84a0070
23#define CMT_CMCSR_0 0xf84a0072
24#define CMT_CMCNT_0 0xf84a0074
25#define CMT_CMCOR_0 0xf84a0076
26#define CMT_CMCSR_1 0xf84a0078
27#define CMT_CMCNT_1 0xf84a007a
28#define CMT_CMCOR_1 0xf84a007c
29
30#define STBCR3 0xf80a0000
31#define cmt_clock_enable() do { ctrl_outb(ctrl_inb(STBCR3) & ~0x10, STBCR3); } while(0)
32#define CMT_CMCSR_INIT 0x0040
33#define CMT_CMCSR_CALIB 0x0000
34#elif defined(CONFIG_CPU_SUBTYPE_SH7203) || \
35 defined(CONFIG_CPU_SUBTYPE_SH7206) || \
36 defined(CONFIG_CPU_SUBTYPE_SH7263)
37#define CMT_CMSTR 0xfffec000
38#define CMT_CMCSR_0 0xfffec002
39#define CMT_CMCNT_0 0xfffec004
40#define CMT_CMCOR_0 0xfffec006
41
42#define STBCR4 0xfffe040c
43#define cmt_clock_enable() do { ctrl_outb(ctrl_inb(STBCR4) & ~0x04, STBCR4); } while(0)
44#define CMT_CMCSR_INIT 0x0040
45#define CMT_CMCSR_CALIB 0x0000
46#else
47#error "Unknown CPU SUBTYPE"
48#endif
49
50static unsigned long cmt_timer_get_offset(void)
51{
52 int count;
53 static unsigned short count_p = 0xffff; /* for the first call after boot */
54 static unsigned long jiffies_p = 0;
55
56 /*
57 * cache volatile jiffies temporarily; we have IRQs turned off.
58 */
59 unsigned long jiffies_t;
60
61 /* timer count may underflow right here */
62 count = ctrl_inw(CMT_CMCOR_0);
63 count -= ctrl_inw(CMT_CMCNT_0);
64
65 jiffies_t = jiffies;
66
67 /*
68 * avoiding timer inconsistencies (they are rare, but they happen)...
69 * there is one kind of problem that must be avoided here:
70 * 1. the timer counter underflows
71 */
72
73 if (jiffies_t == jiffies_p) {
74 if (count > count_p) {
75 /* the nutcase */
76 if (ctrl_inw(CMT_CMCSR_0) & 0x80) { /* Check CMF bit */
77 count -= LATCH;
78 } else {
79 printk("%s (): hardware timer problem?\n",
80 __func__);
81 }
82 }
83 } else
84 jiffies_p = jiffies_t;
85
86 count_p = count;
87
88 count = ((LATCH-1) - count) * TICK_SIZE;
89 count = (count + LATCH/2) / LATCH;
90
91 return count;
92}
93
94static irqreturn_t cmt_timer_interrupt(int irq, void *dev_id)
95{
96 unsigned long timer_status;
97
98 /* Clear CMF bit */
99 timer_status = ctrl_inw(CMT_CMCSR_0);
100 timer_status &= ~0x80;
101 ctrl_outw(timer_status, CMT_CMCSR_0);
102
103 handle_timer_tick();
104
105 return IRQ_HANDLED;
106}
107
108static struct irqaction cmt_irq = {
109 .name = "timer",
110 .handler = cmt_timer_interrupt,
111 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
112};
113
114static void cmt_clk_init(struct clk *clk)
115{
116 u8 divisor = CMT_CMCSR_INIT & 0x3;
117 ctrl_inw(CMT_CMCSR_0);
118 ctrl_outw(CMT_CMCSR_INIT, CMT_CMCSR_0);
119 clk->parent = clk_get(NULL, "module_clk");
120 clk->rate = clk->parent->rate / (8 << (divisor << 1));
121}
122
123static void cmt_clk_recalc(struct clk *clk)
124{
125 u8 divisor = ctrl_inw(CMT_CMCSR_0) & 0x3;
126 clk->rate = clk->parent->rate / (8 << (divisor << 1));
127}
128
129static struct clk_ops cmt_clk_ops = {
130 .init = cmt_clk_init,
131 .recalc = cmt_clk_recalc,
132};
133
134static struct clk cmt0_clk = {
135 .name = "cmt0_clk",
136 .ops = &cmt_clk_ops,
137};
138
139static int cmt_timer_start(void)
140{
141 ctrl_outw(ctrl_inw(CMT_CMSTR) | 0x01, CMT_CMSTR);
142 return 0;
143}
144
145static int cmt_timer_stop(void)
146{
147 ctrl_outw(ctrl_inw(CMT_CMSTR) & ~0x01, CMT_CMSTR);
148 return 0;
149}
150
151static int cmt_timer_init(void)
152{
153 unsigned long interval;
154
155 cmt_clock_enable();
156
157 setup_irq(CONFIG_SH_TIMER_IRQ, &cmt_irq);
158
159 cmt0_clk.parent = clk_get(NULL, "module_clk");
160
161 cmt_timer_stop();
162
163 interval = cmt0_clk.parent->rate / 8 / HZ;
164 printk(KERN_INFO "Interval = %ld\n", interval);
165
166 ctrl_outw(interval, CMT_CMCOR_0);
167
168 clk_register(&cmt0_clk);
169 clk_enable(&cmt0_clk);
170
171 cmt_timer_start();
172
173 return 0;
174}
175
176static struct sys_timer_ops cmt_timer_ops = {
177 .init = cmt_timer_init,
178 .start = cmt_timer_start,
179 .stop = cmt_timer_stop,
180#ifndef CONFIG_GENERIC_TIME
181 .get_offset = cmt_timer_get_offset,
182#endif
183};
184
185struct sys_timer cmt_timer = {
186 .name = "cmt",
187 .ops = &cmt_timer_ops,
188};
diff --git a/arch/sh/kernel/timers/timer-mtu2.c b/arch/sh/kernel/timers/timer-mtu2.c
deleted file mode 100644
index 9b0ef0126479..000000000000
--- a/arch/sh/kernel/timers/timer-mtu2.c
+++ /dev/null
@@ -1,202 +0,0 @@
1/*
2 * arch/sh/kernel/timers/timer-mtu2.c - MTU2 Timer Support
3 *
4 * Copyright (C) 2005 Paul Mundt
5 *
6 * Based off of arch/sh/kernel/timers/timer-tmu.c
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/interrupt.h>
15#include <linux/seqlock.h>
16#include <asm/timer.h>
17#include <asm/io.h>
18#include <asm/irq.h>
19#include <asm/clock.h>
20
21/*
22 * We use channel 1 for our lowly system timer. Channel 2 would be the other
23 * likely candidate, but we leave it alone as it has higher divisors that
24 * would be of more use to other more interesting applications.
25 *
26 * TODO: Presently we only implement a 16-bit single-channel system timer.
27 * However, we can implement channel cascade if we go the overflow route and
28 * get away with using 2 MTU2 channels as a 32-bit timer.
29 */
30#define MTU2_TSTR 0xfffe4280
31#define MTU2_TCR_1 0xfffe4380
32#define MTU2_TMDR_1 0xfffe4381
33#define MTU2_TIOR_1 0xfffe4382
34#define MTU2_TIER_1 0xfffe4384
35#define MTU2_TSR_1 0xfffe4385
36#define MTU2_TCNT_1 0xfffe4386 /* 16-bit counter */
37
38#if defined(CONFIG_CPU_SUBTYPE_SH7201) || \
39 defined(CONFIG_CPU_SUBTYPE_SH7203)
40#define MTU2_TGRA_1 0xfffe4388
41#else
42#define MTU2_TGRA_1 0xfffe438a
43#endif
44
45#define STBCR3 0xfffe0408
46
47#define MTU2_TSTR_CST1 (1 << 1) /* Counter Start 1 */
48
49#define MTU2_TSR_TGFA (1 << 0) /* GRA compare match */
50
51#define MTU2_TIER_TGIEA (1 << 0) /* GRA compare match interrupt enable */
52
53#define MTU2_TCR_INIT 0x22
54
55#define MTU2_TCR_CALIB 0x00
56
57static unsigned long mtu2_timer_get_offset(void)
58{
59 int count;
60 static int count_p = 0x7fff; /* for the first call after boot */
61 static unsigned long jiffies_p = 0;
62
63 /*
64 * cache volatile jiffies temporarily; we have IRQs turned off.
65 */
66 unsigned long jiffies_t;
67
68 /* timer count may underflow right here */
69 count = ctrl_inw(MTU2_TCNT_1); /* read the latched count */
70
71 jiffies_t = jiffies;
72
73 /*
74 * avoiding timer inconsistencies (they are rare, but they happen)...
75 * there is one kind of problem that must be avoided here:
76 * 1. the timer counter underflows
77 */
78
79 if (jiffies_t == jiffies_p) {
80 if (count > count_p) {
81 if (ctrl_inb(MTU2_TSR_1) & MTU2_TSR_TGFA) {
82 count -= LATCH;
83 } else {
84 printk("%s (): hardware timer problem?\n",
85 __func__);
86 }
87 }
88 } else
89 jiffies_p = jiffies_t;
90
91 count_p = count;
92
93 count = ((LATCH-1) - count) * TICK_SIZE;
94 count = (count + LATCH/2) / LATCH;
95
96 return count;
97}
98
99static irqreturn_t mtu2_timer_interrupt(int irq, void *dev_id)
100{
101 unsigned long timer_status;
102
103 /* Clear TGFA bit */
104 timer_status = ctrl_inb(MTU2_TSR_1);
105 timer_status &= ~MTU2_TSR_TGFA;
106 ctrl_outb(timer_status, MTU2_TSR_1);
107
108 /* Do timer tick */
109 handle_timer_tick();
110
111 return IRQ_HANDLED;
112}
113
114static struct irqaction mtu2_irq = {
115 .name = "timer",
116 .handler = mtu2_timer_interrupt,
117 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
118};
119
120static unsigned int divisors[] = { 1, 4, 16, 64, 1, 1, 256 };
121
122static void mtu2_clk_init(struct clk *clk)
123{
124 u8 idx = MTU2_TCR_INIT & 0x7;
125
126 clk->rate = clk->parent->rate / divisors[idx];
127 /* Start TCNT counting */
128 ctrl_outb(ctrl_inb(MTU2_TSTR) | MTU2_TSTR_CST1, MTU2_TSTR);
129
130}
131
132static void mtu2_clk_recalc(struct clk *clk)
133{
134 u8 idx = ctrl_inb(MTU2_TCR_1) & 0x7;
135 clk->rate = clk->parent->rate / divisors[idx];
136}
137
138static struct clk_ops mtu2_clk_ops = {
139 .init = mtu2_clk_init,
140 .recalc = mtu2_clk_recalc,
141};
142
143static struct clk mtu2_clk1 = {
144 .name = "mtu2_clk1",
145 .ops = &mtu2_clk_ops,
146};
147
148static int mtu2_timer_start(void)
149{
150 ctrl_outb(ctrl_inb(MTU2_TSTR) | MTU2_TSTR_CST1, MTU2_TSTR);
151 return 0;
152}
153
154static int mtu2_timer_stop(void)
155{
156 ctrl_outb(ctrl_inb(MTU2_TSTR) & ~MTU2_TSTR_CST1, MTU2_TSTR);
157 return 0;
158}
159
160static int mtu2_timer_init(void)
161{
162 unsigned long interval;
163
164 setup_irq(CONFIG_SH_TIMER_IRQ, &mtu2_irq);
165
166 mtu2_clk1.parent = clk_get(NULL, "module_clk");
167
168 ctrl_outb(ctrl_inb(STBCR3) & (~0x20), STBCR3);
169
170 /* Normal operation */
171 ctrl_outb(0, MTU2_TMDR_1);
172 ctrl_outb(MTU2_TCR_INIT, MTU2_TCR_1);
173 ctrl_outb(0x01, MTU2_TIOR_1);
174
175 /* Enable underflow interrupt */
176 ctrl_outb(ctrl_inb(MTU2_TIER_1) | MTU2_TIER_TGIEA, MTU2_TIER_1);
177
178 interval = CONFIG_SH_PCLK_FREQ / 16 / HZ;
179 printk(KERN_INFO "Interval = %ld\n", interval);
180
181 ctrl_outw(interval, MTU2_TGRA_1);
182 ctrl_outw(0, MTU2_TCNT_1);
183
184 clk_register(&mtu2_clk1);
185 clk_enable(&mtu2_clk1);
186
187 return 0;
188}
189
190struct sys_timer_ops mtu2_timer_ops = {
191 .init = mtu2_timer_init,
192 .start = mtu2_timer_start,
193 .stop = mtu2_timer_stop,
194#ifndef CONFIG_GENERIC_TIME
195 .get_offset = mtu2_timer_get_offset,
196#endif
197};
198
199struct sys_timer mtu2_timer = {
200 .name = "mtu2",
201 .ops = &mtu2_timer_ops,
202};
diff --git a/arch/sh/kernel/timers/timer-tmu.c b/arch/sh/kernel/timers/timer-tmu.c
deleted file mode 100644
index fe8d8930ccb6..000000000000
--- a/arch/sh/kernel/timers/timer-tmu.c
+++ /dev/null
@@ -1,297 +0,0 @@
1/*
2 * arch/sh/kernel/timers/timer-tmu.c - TMU Timer Support
3 *
4 * Copyright (C) 2005 - 2007 Paul Mundt
5 *
6 * TMU handling code hacked out of arch/sh/kernel/time.c
7 *
8 * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
9 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
10 * Copyright (C) 2002, 2003, 2004 Paul Mundt
11 * Copyright (C) 2002 M. R. Brown <mrbrown@linux-sh.org>
12 *
13 * This file is subject to the terms and conditions of the GNU General Public
14 * License. See the file "COPYING" in the main directory of this archive
15 * for more details.
16 */
17#include <linux/init.h>
18#include <linux/kernel.h>
19#include <linux/interrupt.h>
20#include <linux/seqlock.h>
21#include <linux/clockchips.h>
22#include <asm/timer.h>
23#include <asm/rtc.h>
24#include <asm/io.h>
25#include <asm/irq.h>
26#include <asm/clock.h>
27
28#define TMU_TOCR_INIT 0x00
29#define TMU_TCR_INIT 0x0020
30
31#define TMU0 (0)
32#define TMU1 (1)
33
34static inline void _tmu_start(int tmu_num)
35{
36 ctrl_outb(ctrl_inb(TMU_012_TSTR) | (0x1<<tmu_num), TMU_012_TSTR);
37}
38
39static inline void _tmu_set_irq(int tmu_num, int enabled)
40{
41 register unsigned long tmu_tcr = TMU0_TCR + (0xc*tmu_num);
42 ctrl_outw( (enabled ? ctrl_inw(tmu_tcr) | (1<<5) : ctrl_inw(tmu_tcr) & ~(1<<5)), tmu_tcr);
43}
44
45static inline void _tmu_stop(int tmu_num)
46{
47 ctrl_outb(ctrl_inb(TMU_012_TSTR) & ~(0x1<<tmu_num), TMU_012_TSTR);
48}
49
50static inline void _tmu_clear_status(int tmu_num)
51{
52 register unsigned long tmu_tcr = TMU0_TCR + (0xc*tmu_num);
53 /* Clear UNF bit */
54 ctrl_outw(ctrl_inw(tmu_tcr) & ~0x100, tmu_tcr);
55}
56
57static inline unsigned long _tmu_read(int tmu_num)
58{
59 return ctrl_inl(TMU0_TCNT+0xC*tmu_num);
60}
61
62static int tmu_timer_start(void)
63{
64 _tmu_start(TMU0);
65 _tmu_start(TMU1);
66 _tmu_set_irq(TMU0,1);
67 return 0;
68}
69
70static int tmu_timer_stop(void)
71{
72 _tmu_stop(TMU0);
73 _tmu_stop(TMU1);
74 _tmu_clear_status(TMU0);
75 return 0;
76}
77
78/*
79 * also when the module_clk is scaled the TMU1
80 * will show the same frequency
81 */
82static int tmus_are_scaled;
83
84static cycle_t tmu_timer_read(struct clocksource *cs)
85{
86 return ((cycle_t)(~_tmu_read(TMU1)))<<tmus_are_scaled;
87}
88
89
90static unsigned long tmu_latest_interval[3];
91static void tmu_timer_set_interval(int tmu_num, unsigned long interval, unsigned int reload)
92{
93 unsigned long tmu_tcnt = TMU0_TCNT + tmu_num*0xC;
94 unsigned long tmu_tcor = TMU0_TCOR + tmu_num*0xC;
95
96 _tmu_stop(tmu_num);
97
98 ctrl_outl(interval, tmu_tcnt);
99 tmu_latest_interval[tmu_num] = interval;
100
101 /*
102 * TCNT reloads from TCOR on underflow, clear it if we don't
103 * intend to auto-reload
104 */
105 ctrl_outl( reload ? interval : 0 , tmu_tcor);
106
107 _tmu_start(tmu_num);
108}
109
110static int tmu_set_next_event(unsigned long cycles,
111 struct clock_event_device *evt)
112{
113 tmu_timer_set_interval(TMU0,cycles, evt->mode == CLOCK_EVT_MODE_PERIODIC);
114 _tmu_set_irq(TMU0,1);
115 return 0;
116}
117
118static void tmu_set_mode(enum clock_event_mode mode,
119 struct clock_event_device *evt)
120{
121 switch (mode) {
122 case CLOCK_EVT_MODE_PERIODIC:
123 ctrl_outl(tmu_latest_interval[TMU0], TMU0_TCOR);
124 break;
125 case CLOCK_EVT_MODE_ONESHOT:
126 ctrl_outl(0, TMU0_TCOR);
127 break;
128 case CLOCK_EVT_MODE_UNUSED:
129 case CLOCK_EVT_MODE_SHUTDOWN:
130 case CLOCK_EVT_MODE_RESUME:
131 break;
132 }
133}
134
135static struct clock_event_device tmu0_clockevent = {
136 .name = "tmu0",
137 .shift = 32,
138 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
139 .set_mode = tmu_set_mode,
140 .set_next_event = tmu_set_next_event,
141};
142
143static irqreturn_t tmu_timer_interrupt(int irq, void *dummy)
144{
145 struct clock_event_device *evt = &tmu0_clockevent;
146 _tmu_clear_status(TMU0);
147 _tmu_set_irq(TMU0,tmu0_clockevent.mode != CLOCK_EVT_MODE_ONESHOT);
148
149 switch (tmu0_clockevent.mode) {
150 case CLOCK_EVT_MODE_ONESHOT:
151 case CLOCK_EVT_MODE_PERIODIC:
152 evt->event_handler(evt);
153 break;
154 default:
155 break;
156 }
157
158 return IRQ_HANDLED;
159}
160
161static struct irqaction tmu0_irq = {
162 .name = "periodic/oneshot timer",
163 .handler = tmu_timer_interrupt,
164 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
165};
166
167static void __init tmu_clk_init(struct clk *clk)
168{
169 u8 divisor = TMU_TCR_INIT & 0x7;
170 int tmu_num = clk->name[3]-'0';
171 ctrl_outw(TMU_TCR_INIT, TMU0_TCR+(tmu_num*0xC));
172 clk->rate = clk_get_rate(clk->parent) / (4 << (divisor << 1));
173}
174
175static void tmu_clk_recalc(struct clk *clk)
176{
177 int tmu_num = clk->name[3]-'0';
178 unsigned long prev_rate = clk_get_rate(clk);
179 unsigned long flags;
180 u8 divisor = ctrl_inw(TMU0_TCR+tmu_num*0xC) & 0x7;
181 clk->rate = clk_get_rate(clk->parent) / (4 << (divisor << 1));
182
183 if(prev_rate==clk_get_rate(clk))
184 return;
185
186 if(tmu_num)
187 return; /* No more work on TMU1 */
188
189 local_irq_save(flags);
190 tmus_are_scaled = (prev_rate > clk->rate);
191
192 _tmu_stop(TMU0);
193
194 tmu0_clockevent.mult = div_sc(clk->rate, NSEC_PER_SEC,
195 tmu0_clockevent.shift);
196 tmu0_clockevent.max_delta_ns =
197 clockevent_delta2ns(-1, &tmu0_clockevent);
198 tmu0_clockevent.min_delta_ns =
199 clockevent_delta2ns(1, &tmu0_clockevent);
200
201 if (tmus_are_scaled)
202 tmu_latest_interval[TMU0] >>= 1;
203 else
204 tmu_latest_interval[TMU0] <<= 1;
205
206 tmu_timer_set_interval(TMU0,
207 tmu_latest_interval[TMU0],
208 tmu0_clockevent.mode == CLOCK_EVT_MODE_PERIODIC);
209
210 _tmu_start(TMU0);
211
212 local_irq_restore(flags);
213}
214
215static struct clk_ops tmu_clk_ops = {
216 .init = tmu_clk_init,
217 .recalc = tmu_clk_recalc,
218};
219
220static struct clk tmu0_clk = {
221 .name = "tmu0_clk",
222 .ops = &tmu_clk_ops,
223};
224
225static struct clk tmu1_clk = {
226 .name = "tmu1_clk",
227 .ops = &tmu_clk_ops,
228};
229
230static int tmu_timer_init(void)
231{
232 unsigned long interval;
233 unsigned long frequency;
234
235 setup_irq(CONFIG_SH_TIMER_IRQ, &tmu0_irq);
236
237 tmu0_clk.parent = clk_get(NULL, "module_clk");
238 tmu1_clk.parent = clk_get(NULL, "module_clk");
239
240 tmu_timer_stop();
241
242#if !defined(CONFIG_CPU_SUBTYPE_SH7720) && \
243 !defined(CONFIG_CPU_SUBTYPE_SH7721) && \
244 !defined(CONFIG_CPU_SUBTYPE_SH7760) && \
245 !defined(CONFIG_CPU_SUBTYPE_SH7785) && \
246 !defined(CONFIG_CPU_SUBTYPE_SH7786) && \
247 !defined(CONFIG_CPU_SUBTYPE_SHX3)
248 ctrl_outb(TMU_TOCR_INIT, TMU_TOCR);
249#endif
250
251 clk_register(&tmu0_clk);
252 clk_register(&tmu1_clk);
253 clk_enable(&tmu0_clk);
254 clk_enable(&tmu1_clk);
255
256 frequency = clk_get_rate(&tmu0_clk);
257 interval = (frequency + HZ / 2) / HZ;
258
259 tmu_timer_set_interval(TMU0,interval, 1);
260 tmu_timer_set_interval(TMU1,~0,1);
261
262 _tmu_start(TMU1);
263
264 clocksource_sh.rating = 200;
265 clocksource_sh.mask = CLOCKSOURCE_MASK(32);
266 clocksource_sh.read = tmu_timer_read;
267 clocksource_sh.shift = 10;
268 clocksource_sh.mult = clocksource_hz2mult(clk_get_rate(&tmu1_clk),
269 clocksource_sh.shift);
270 clocksource_sh.flags = CLOCK_SOURCE_IS_CONTINUOUS;
271 clocksource_register(&clocksource_sh);
272
273 tmu0_clockevent.mult = div_sc(frequency, NSEC_PER_SEC,
274 tmu0_clockevent.shift);
275 tmu0_clockevent.max_delta_ns =
276 clockevent_delta2ns(-1, &tmu0_clockevent);
277 tmu0_clockevent.min_delta_ns =
278 clockevent_delta2ns(1, &tmu0_clockevent);
279
280 tmu0_clockevent.cpumask = cpumask_of(0);
281 tmu0_clockevent.rating = 100;
282
283 clockevents_register_device(&tmu0_clockevent);
284
285 return 0;
286}
287
288static struct sys_timer_ops tmu_timer_ops = {
289 .init = tmu_timer_init,
290 .start = tmu_timer_start,
291 .stop = tmu_timer_stop,
292};
293
294struct sys_timer tmu_timer = {
295 .name = "tmu",
296 .ops = &tmu_timer_ops,
297};
diff --git a/arch/sh/kernel/timers/timer.c b/arch/sh/kernel/timers/timer.c
deleted file mode 100644
index 4e7e747d1b69..000000000000
--- a/arch/sh/kernel/timers/timer.c
+++ /dev/null
@@ -1,55 +0,0 @@
1/*
2 * arch/sh/kernel/timers/timer.c - Common timer code
3 *
4 * Copyright (C) 2005 Paul Mundt
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/timer.h>
13#include <linux/string.h>
14#include <asm/timer.h>
15
16static struct sys_timer *sys_timers[] = {
17#ifdef CONFIG_SH_TMU
18 &tmu_timer,
19#endif
20#ifdef CONFIG_SH_MTU2
21 &mtu2_timer,
22#endif
23#ifdef CONFIG_SH_CMT
24 &cmt_timer,
25#endif
26 NULL,
27};
28
29static char timer_override[10];
30static int __init timer_setup(char *str)
31{
32 if (str)
33 strlcpy(timer_override, str, sizeof(timer_override));
34 return 1;
35}
36__setup("timer=", timer_setup);
37
38struct sys_timer *get_sys_timer(void)
39{
40 int i;
41
42 for (i = 0; i < ARRAY_SIZE(sys_timers); i++) {
43 struct sys_timer *t = sys_timers[i];
44
45 if (unlikely(!t))
46 break;
47 if (unlikely(timer_override[0]))
48 if ((strcmp(timer_override, t->name) != 0))
49 continue;
50 if (likely(t->ops->init() == 0))
51 return t;
52 }
53
54 return NULL;
55}
diff --git a/arch/sh/kernel/traps.c b/arch/sh/kernel/traps.c
index 438f1ebcc453..46348ed07cc3 100644
--- a/arch/sh/kernel/traps.c
+++ b/arch/sh/kernel/traps.c
@@ -22,11 +22,11 @@ static void handle_BUG(struct pt_regs *regs)
22 22
23int is_valid_bugaddr(unsigned long addr) 23int is_valid_bugaddr(unsigned long addr)
24{ 24{
25 unsigned short opcode; 25 insn_size_t opcode;
26 26
27 if (addr < PAGE_OFFSET) 27 if (addr < PAGE_OFFSET)
28 return 0; 28 return 0;
29 if (probe_kernel_address((u16 *)addr, opcode)) 29 if (probe_kernel_address((insn_size_t *)addr, opcode))
30 return 0; 30 return 0;
31 31
32 return opcode == TRAPA_BUG_OPCODE; 32 return opcode == TRAPA_BUG_OPCODE;
@@ -66,7 +66,7 @@ BUILD_TRAP_HANDLER(bug)
66 66
67#ifdef CONFIG_BUG 67#ifdef CONFIG_BUG
68 if (__kernel_text_address(instruction_pointer(regs))) { 68 if (__kernel_text_address(instruction_pointer(regs))) {
69 opcode_t insn = *(opcode_t *)instruction_pointer(regs); 69 insn_size_t insn = *(insn_size_t *)instruction_pointer(regs);
70 if (insn == TRAPA_BUG_OPCODE) 70 if (insn == TRAPA_BUG_OPCODE)
71 handle_BUG(regs); 71 handle_BUG(regs);
72 } 72 }
diff --git a/arch/sh/kernel/traps_32.c b/arch/sh/kernel/traps_32.c
index 30ca9c51e52d..2b772776fcda 100644
--- a/arch/sh/kernel/traps_32.c
+++ b/arch/sh/kernel/traps_32.c
@@ -34,6 +34,7 @@
34# define TRAP_ILLEGAL_SLOT_INST 6 34# define TRAP_ILLEGAL_SLOT_INST 6
35# define TRAP_ADDRESS_ERROR 9 35# define TRAP_ADDRESS_ERROR 9
36# ifdef CONFIG_CPU_SH2A 36# ifdef CONFIG_CPU_SH2A
37# define TRAP_UBC 12
37# define TRAP_FPU_ERROR 13 38# define TRAP_FPU_ERROR 13
38# define TRAP_DIVZERO_ERROR 17 39# define TRAP_DIVZERO_ERROR 17
39# define TRAP_DIVOVF_ERROR 18 40# define TRAP_DIVOVF_ERROR 18
@@ -176,7 +177,7 @@ static struct mem_access user_mem_access = {
176 * (if that instruction is in a branch delay slot) 177 * (if that instruction is in a branch delay slot)
177 * - return 0 if emulation okay, -EFAULT on existential error 178 * - return 0 if emulation okay, -EFAULT on existential error
178 */ 179 */
179static int handle_unaligned_ins(opcode_t instruction, struct pt_regs *regs, 180static int handle_unaligned_ins(insn_size_t instruction, struct pt_regs *regs,
180 struct mem_access *ma) 181 struct mem_access *ma)
181{ 182{
182 int ret, index, count; 183 int ret, index, count;
@@ -321,10 +322,10 @@ static int handle_unaligned_ins(opcode_t instruction, struct pt_regs *regs,
321 * - fetches the instruction from PC+2 322 * - fetches the instruction from PC+2
322 */ 323 */
323static inline int handle_delayslot(struct pt_regs *regs, 324static inline int handle_delayslot(struct pt_regs *regs,
324 opcode_t old_instruction, 325 insn_size_t old_instruction,
325 struct mem_access *ma) 326 struct mem_access *ma)
326{ 327{
327 opcode_t instruction; 328 insn_size_t instruction;
328 void __user *addr = (void __user *)(regs->pc + 329 void __user *addr = (void __user *)(regs->pc +
329 instruction_size(old_instruction)); 330 instruction_size(old_instruction));
330 331
@@ -364,7 +365,7 @@ static inline int handle_delayslot(struct pt_regs *regs,
364 365
365static int handle_unaligned_notify_count = 10; 366static int handle_unaligned_notify_count = 10;
366 367
367int handle_unaligned_access(opcode_t instruction, struct pt_regs *regs, 368int handle_unaligned_access(insn_size_t instruction, struct pt_regs *regs,
368 struct mem_access *ma) 369 struct mem_access *ma)
369{ 370{
370 u_int rm; 371 u_int rm;
@@ -522,7 +523,7 @@ asmlinkage void do_address_error(struct pt_regs *regs,
522 unsigned long error_code = 0; 523 unsigned long error_code = 0;
523 mm_segment_t oldfs; 524 mm_segment_t oldfs;
524 siginfo_t info; 525 siginfo_t info;
525 opcode_t instruction; 526 insn_size_t instruction;
526 int tmp; 527 int tmp;
527 528
528 /* Intentional ifdef */ 529 /* Intentional ifdef */
@@ -849,6 +850,10 @@ void __init trap_init(void)
849#endif 850#endif
850#endif 851#endif
851 852
853#ifdef TRAP_UBC
854 set_exception_table_vec(TRAP_UBC, break_point_trap);
855#endif
856
852 /* Setup VBR for boot cpu */ 857 /* Setup VBR for boot cpu */
853 per_cpu_trap_init(); 858 per_cpu_trap_init();
854} 859}
diff --git a/arch/sh/kernel/traps_64.c b/arch/sh/kernel/traps_64.c
index a85831cbf18b..267e5ebbb475 100644
--- a/arch/sh/kernel/traps_64.c
+++ b/arch/sh/kernel/traps_64.c
@@ -370,7 +370,6 @@ static int generate_and_check_address(struct pt_regs *regs,
370 return -1; 370 return -1;
371 } 371 }
372 372
373#if defined(CONFIG_SH64_USER_MISALIGNED_FIXUP)
374 /* Check accessible. For misaligned access in the kernel, assume the 373 /* Check accessible. For misaligned access in the kernel, assume the
375 address is always accessible (and if not, just fault when the 374 address is always accessible (and if not, just fault when the
376 load/store gets done.) */ 375 load/store gets done.) */
@@ -380,18 +379,13 @@ static int generate_and_check_address(struct pt_regs *regs,
380 } 379 }
381 /* Do access_ok check later - it depends on whether it's a load or a store. */ 380 /* Do access_ok check later - it depends on whether it's a load or a store. */
382 } 381 }
383#endif
384 382
385 *address = addr; 383 *address = addr;
386 return 0; 384 return 0;
387} 385}
388 386
389/* Default value as for sh */
390#if defined(CONFIG_SH64_USER_MISALIGNED_FIXUP)
391static int user_mode_unaligned_fixup_count = 10; 387static int user_mode_unaligned_fixup_count = 10;
392static int user_mode_unaligned_fixup_enable = 1; 388static int user_mode_unaligned_fixup_enable = 1;
393#endif
394
395static int kernel_mode_unaligned_fixup_count = 32; 389static int kernel_mode_unaligned_fixup_count = 32;
396 390
397static void misaligned_kernel_word_load(__u64 address, int do_sign_extend, __u64 *result) 391static void misaligned_kernel_word_load(__u64 address, int do_sign_extend, __u64 *result)
@@ -440,7 +434,6 @@ static int misaligned_load(struct pt_regs *regs,
440 } 434 }
441 435
442 destreg = (opcode >> 4) & 0x3f; 436 destreg = (opcode >> 4) & 0x3f;
443#if defined(CONFIG_SH64_USER_MISALIGNED_FIXUP)
444 if (user_mode(regs)) { 437 if (user_mode(regs)) {
445 __u64 buffer; 438 __u64 buffer;
446 439
@@ -470,9 +463,7 @@ static int misaligned_load(struct pt_regs *regs,
470 width_shift, (unsigned long) regs->pc); 463 width_shift, (unsigned long) regs->pc);
471 break; 464 break;
472 } 465 }
473 } else 466 } else {
474#endif
475 {
476 /* kernel mode - we can take short cuts since if we fault, it's a genuine bug */ 467 /* kernel mode - we can take short cuts since if we fault, it's a genuine bug */
477 __u64 lo, hi; 468 __u64 lo, hi;
478 469
@@ -519,7 +510,6 @@ static int misaligned_store(struct pt_regs *regs,
519 } 510 }
520 511
521 srcreg = (opcode >> 4) & 0x3f; 512 srcreg = (opcode >> 4) & 0x3f;
522#if defined(CONFIG_SH64_USER_MISALIGNED_FIXUP)
523 if (user_mode(regs)) { 513 if (user_mode(regs)) {
524 __u64 buffer; 514 __u64 buffer;
525 515
@@ -546,9 +536,7 @@ static int misaligned_store(struct pt_regs *regs,
546 if (__copy_user((void *)(int)address, &buffer, (1 << width_shift)) > 0) { 536 if (__copy_user((void *)(int)address, &buffer, (1 << width_shift)) > 0) {
547 return -1; /* fault */ 537 return -1; /* fault */
548 } 538 }
549 } else 539 } else {
550#endif
551 {
552 /* kernel mode - we can take short cuts since if we fault, it's a genuine bug */ 540 /* kernel mode - we can take short cuts since if we fault, it's a genuine bug */
553 __u64 val = regs->regs[srcreg]; 541 __u64 val = regs->regs[srcreg];
554 542
@@ -576,7 +564,6 @@ static int misaligned_store(struct pt_regs *regs,
576 564
577} 565}
578 566
579#if defined(CONFIG_SH64_USER_MISALIGNED_FIXUP)
580/* Never need to fix up misaligned FPU accesses within the kernel since that's a real 567/* Never need to fix up misaligned FPU accesses within the kernel since that's a real
581 error. */ 568 error. */
582static int misaligned_fpu_load(struct pt_regs *regs, 569static int misaligned_fpu_load(struct pt_regs *regs,
@@ -727,7 +714,6 @@ static int misaligned_fpu_store(struct pt_regs *regs,
727 return -1; 714 return -1;
728 } 715 }
729} 716}
730#endif
731 717
732static int misaligned_fixup(struct pt_regs *regs) 718static int misaligned_fixup(struct pt_regs *regs)
733{ 719{
@@ -735,12 +721,8 @@ static int misaligned_fixup(struct pt_regs *regs)
735 int error; 721 int error;
736 int major, minor; 722 int major, minor;
737 723
738#if !defined(CONFIG_SH64_USER_MISALIGNED_FIXUP) 724 if (!user_mode_unaligned_fixup_enable)
739 /* Never fixup user mode misaligned accesses without this option enabled. */ 725 return -1;
740 return -1;
741#else
742 if (!user_mode_unaligned_fixup_enable) return -1;
743#endif
744 726
745 error = read_opcode(regs->pc, &opcode, user_mode(regs)); 727 error = read_opcode(regs->pc, &opcode, user_mode(regs));
746 if (error < 0) { 728 if (error < 0) {
@@ -749,15 +731,12 @@ static int misaligned_fixup(struct pt_regs *regs)
749 major = (opcode >> 26) & 0x3f; 731 major = (opcode >> 26) & 0x3f;
750 minor = (opcode >> 16) & 0xf; 732 minor = (opcode >> 16) & 0xf;
751 733
752#if defined(CONFIG_SH64_USER_MISALIGNED_FIXUP)
753 if (user_mode(regs) && (user_mode_unaligned_fixup_count > 0)) { 734 if (user_mode(regs) && (user_mode_unaligned_fixup_count > 0)) {
754 --user_mode_unaligned_fixup_count; 735 --user_mode_unaligned_fixup_count;
755 /* Only do 'count' worth of these reports, to remove a potential DoS against syslog */ 736 /* Only do 'count' worth of these reports, to remove a potential DoS against syslog */
756 printk("Fixing up unaligned userspace access in \"%s\" pid=%d pc=0x%08x ins=0x%08lx\n", 737 printk("Fixing up unaligned userspace access in \"%s\" pid=%d pc=0x%08x ins=0x%08lx\n",
757 current->comm, task_pid_nr(current), (__u32)regs->pc, opcode); 738 current->comm, task_pid_nr(current), (__u32)regs->pc, opcode);
758 } else 739 } else if (!user_mode(regs) && (kernel_mode_unaligned_fixup_count > 0)) {
759#endif
760 if (!user_mode(regs) && (kernel_mode_unaligned_fixup_count > 0)) {
761 --kernel_mode_unaligned_fixup_count; 740 --kernel_mode_unaligned_fixup_count;
762 if (in_interrupt()) { 741 if (in_interrupt()) {
763 printk("Fixing up unaligned kernelspace access in interrupt pc=0x%08x ins=0x%08lx\n", 742 printk("Fixing up unaligned kernelspace access in interrupt pc=0x%08x ins=0x%08lx\n",
@@ -830,7 +809,6 @@ static int misaligned_fixup(struct pt_regs *regs)
830 } 809 }
831 break; 810 break;
832 811
833#if defined(CONFIG_SH64_USER_MISALIGNED_FIXUP)
834 case (0x94>>2): /* FLD.S */ 812 case (0x94>>2): /* FLD.S */
835 error = misaligned_fpu_load(regs, opcode, 1, 2, 0); 813 error = misaligned_fpu_load(regs, opcode, 1, 2, 0);
836 break; 814 break;
@@ -881,7 +859,6 @@ static int misaligned_fixup(struct pt_regs *regs)
881 break; 859 break;
882 } 860 }
883 break; 861 break;
884#endif
885 862
886 default: 863 default:
887 /* Fault */ 864 /* Fault */
@@ -907,7 +884,6 @@ static ctl_table unaligned_table[] = {
907 .mode = 0644, 884 .mode = 0644,
908 .proc_handler = &proc_dointvec 885 .proc_handler = &proc_dointvec
909 }, 886 },
910#if defined(CONFIG_SH64_USER_MISALIGNED_FIXUP)
911 { 887 {
912 .ctl_name = CTL_UNNUMBERED, 888 .ctl_name = CTL_UNNUMBERED,
913 .procname = "user_reports", 889 .procname = "user_reports",
@@ -923,7 +899,6 @@ static ctl_table unaligned_table[] = {
923 .maxlen = sizeof(int), 899 .maxlen = sizeof(int),
924 .mode = 0644, 900 .mode = 0644,
925 .proc_handler = &proc_dointvec}, 901 .proc_handler = &proc_dointvec},
926#endif
927 {} 902 {}
928}; 903};
929 904
diff --git a/arch/sh/kernel/vmlinux.lds.S b/arch/sh/kernel/vmlinux.lds.S
index d7d4991f32af..f53c76acaede 100644
--- a/arch/sh/kernel/vmlinux.lds.S
+++ b/arch/sh/kernel/vmlinux.lds.S
@@ -1,5 +1,178 @@
1#ifdef CONFIG_SUPERH32 1/*
2# include "vmlinux_32.lds.S" 2 * ld script to make SuperH Linux kernel
3 * Written by Niibe Yutaka and Paul Mundt
4 */
5#ifdef CONFIG_SUPERH64
6#define LOAD_OFFSET CONFIG_PAGE_OFFSET
7OUTPUT_ARCH(sh:sh5)
3#else 8#else
4# include "vmlinux_64.lds.S" 9#define LOAD_OFFSET 0
10OUTPUT_ARCH(sh)
5#endif 11#endif
12
13#include <asm/thread_info.h>
14#include <asm/cache.h>
15#include <asm-generic/vmlinux.lds.h>
16
17ENTRY(_start)
18SECTIONS
19{
20#ifdef CONFIG_PMB_FIXED
21 . = CONFIG_PAGE_OFFSET + (CONFIG_MEMORY_START & 0x1fffffff) +
22 CONFIG_ZERO_PAGE_OFFSET;
23#elif defined(CONFIG_32BIT)
24 . = CONFIG_PAGE_OFFSET + CONFIG_ZERO_PAGE_OFFSET;
25#else
26 . = CONFIG_PAGE_OFFSET + CONFIG_MEMORY_START + CONFIG_ZERO_PAGE_OFFSET;
27#endif
28
29 _text = .; /* Text and read-only data */
30
31 .empty_zero_page : AT(ADDR(.empty_zero_page) - LOAD_OFFSET) {
32 *(.empty_zero_page)
33 } = 0
34
35 .text : AT(ADDR(.text) - LOAD_OFFSET) {
36 HEAD_TEXT
37 TEXT_TEXT
38
39#ifdef CONFIG_SUPERH64
40 *(.text64)
41 *(.text..SHmedia32)
42#endif
43
44 SCHED_TEXT
45 LOCK_TEXT
46 KPROBES_TEXT
47 IRQENTRY_TEXT
48 *(.fixup)
49 *(.gnu.warning)
50 _etext = .; /* End of text section */
51 } = 0x0009
52
53 . = ALIGN(16); /* Exception table */
54 __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
55 __start___ex_table = .;
56 *(__ex_table)
57 __stop___ex_table = .;
58 }
59
60 NOTES
61 RO_DATA(PAGE_SIZE)
62
63 /*
64 * Code which must be executed uncached and the associated data
65 */
66 . = ALIGN(PAGE_SIZE);
67 .uncached : AT(ADDR(.uncached) - LOAD_OFFSET) {
68 __uncached_start = .;
69 *(.uncached.text)
70 *(.uncached.data)
71 __uncached_end = .;
72 }
73
74 . = ALIGN(THREAD_SIZE);
75 .data : AT(ADDR(.data) - LOAD_OFFSET) { /* Data */
76 *(.data.init_task)
77
78 . = ALIGN(L1_CACHE_BYTES);
79 *(.data.cacheline_aligned)
80
81 . = ALIGN(L1_CACHE_BYTES);
82 *(.data.read_mostly)
83
84 . = ALIGN(PAGE_SIZE);
85 *(.data.page_aligned)
86
87 __nosave_begin = .;
88 *(.data.nosave)
89 . = ALIGN(PAGE_SIZE);
90 __nosave_end = .;
91
92 DATA_DATA
93 CONSTRUCTORS
94 }
95
96 _edata = .; /* End of data section */
97
98 . = ALIGN(PAGE_SIZE); /* Init code and data */
99 .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
100 __init_begin = .;
101 _sinittext = .;
102 INIT_TEXT
103 _einittext = .;
104 }
105
106 .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) { INIT_DATA }
107
108 . = ALIGN(16);
109 .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) {
110 __setup_start = .;
111 *(.init.setup)
112 __setup_end = .;
113 }
114
115 .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) {
116 __initcall_start = .;
117 INITCALLS
118 __initcall_end = .;
119 }
120
121 .con_initcall.init : AT(ADDR(.con_initcall.init) - LOAD_OFFSET) {
122 __con_initcall_start = .;
123 *(.con_initcall.init)
124 __con_initcall_end = .;
125 }
126
127 SECURITY_INIT
128
129#ifdef CONFIG_BLK_DEV_INITRD
130 . = ALIGN(PAGE_SIZE);
131 .init.ramfs : AT(ADDR(.init.ramfs) - LOAD_OFFSET) {
132 __initramfs_start = .;
133 *(.init.ramfs)
134 __initramfs_end = .;
135 }
136#endif
137
138 . = ALIGN(4);
139 .machvec.init : AT(ADDR(.machvec.init) - LOAD_OFFSET) {
140 __machvec_start = .;
141 *(.machvec.init)
142 __machvec_end = .;
143 }
144
145 PERCPU(PAGE_SIZE)
146
147 /*
148 * .exit.text is discarded at runtime, not link time, to deal with
149 * references from __bug_table
150 */
151 .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) { EXIT_TEXT }
152 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) { EXIT_DATA }
153
154 . = ALIGN(PAGE_SIZE);
155 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
156 __init_end = .;
157 __bss_start = .; /* BSS */
158 *(.bss.page_aligned)
159 *(.bss)
160 *(COMMON)
161 . = ALIGN(4);
162 _ebss = .; /* uClinux MTD sucks */
163 _end = . ;
164 }
165
166 /*
167 * When something in the kernel is NOT compiled as a module, the
168 * module cleanup code and data are put into these segments. Both
169 * can then be thrown away, as cleanup code is never called unless
170 * it's a module.
171 */
172 /DISCARD/ : {
173 *(.exitcall.exit)
174 }
175
176 STABS_DEBUG
177 DWARF_DEBUG
178}
diff --git a/arch/sh/kernel/vmlinux_32.lds.S b/arch/sh/kernel/vmlinux_32.lds.S
deleted file mode 100644
index dd9b2ee1312d..000000000000
--- a/arch/sh/kernel/vmlinux_32.lds.S
+++ /dev/null
@@ -1,154 +0,0 @@
1/*
2 * ld script to make SuperH Linux kernel
3 * Written by Niibe Yutaka
4 */
5#include <asm/thread_info.h>
6#include <asm/cache.h>
7#include <asm-generic/vmlinux.lds.h>
8
9#ifdef CONFIG_CPU_LITTLE_ENDIAN
10OUTPUT_FORMAT("elf32-sh-linux", "elf32-sh-linux", "elf32-sh-linux")
11#else
12OUTPUT_FORMAT("elf32-shbig-linux", "elf32-shbig-linux", "elf32-shbig-linux")
13#endif
14OUTPUT_ARCH(sh)
15ENTRY(_start)
16SECTIONS
17{
18#ifdef CONFIG_PMB_FIXED
19 . = CONFIG_PAGE_OFFSET + (CONFIG_MEMORY_START & 0x1fffffff) +
20 CONFIG_ZERO_PAGE_OFFSET;
21#elif defined(CONFIG_32BIT)
22 . = CONFIG_PAGE_OFFSET + CONFIG_ZERO_PAGE_OFFSET;
23#else
24 . = CONFIG_PAGE_OFFSET + CONFIG_MEMORY_START + CONFIG_ZERO_PAGE_OFFSET;
25#endif
26
27 _text = .; /* Text and read-only data */
28
29 .empty_zero_page : {
30 *(.empty_zero_page)
31 } = 0
32
33 .text : {
34 HEAD_TEXT
35 TEXT_TEXT
36 SCHED_TEXT
37 LOCK_TEXT
38 KPROBES_TEXT
39 *(.fixup)
40 *(.gnu.warning)
41 } = 0x0009
42
43 . = ALIGN(16); /* Exception table */
44 __start___ex_table = .;
45 __ex_table : { *(__ex_table) }
46 __stop___ex_table = .;
47
48 _etext = .; /* End of text section */
49
50 NOTES
51 RO_DATA(PAGE_SIZE)
52
53 /*
54 * Code which must be executed uncached and the associated data
55 */
56 . = ALIGN(PAGE_SIZE);
57 __uncached_start = .;
58 .uncached.text : { *(.uncached.text) }
59 .uncached.data : { *(.uncached.data) }
60 __uncached_end = .;
61
62 . = ALIGN(THREAD_SIZE);
63 .data : { /* Data */
64 *(.data.init_task)
65
66 . = ALIGN(L1_CACHE_BYTES);
67 *(.data.cacheline_aligned)
68
69 . = ALIGN(L1_CACHE_BYTES);
70 *(.data.read_mostly)
71
72 . = ALIGN(PAGE_SIZE);
73 *(.data.page_aligned)
74
75 __nosave_begin = .;
76 *(.data.nosave)
77 . = ALIGN(PAGE_SIZE);
78 __nosave_end = .;
79
80 DATA_DATA
81 CONSTRUCTORS
82 }
83
84 _edata = .; /* End of data section */
85
86 . = ALIGN(PAGE_SIZE); /* Init code and data */
87 __init_begin = .;
88 _sinittext = .;
89 .init.text : { INIT_TEXT }
90 _einittext = .;
91 .init.data : { INIT_DATA }
92
93 . = ALIGN(16);
94 __setup_start = .;
95 .init.setup : { *(.init.setup) }
96 __setup_end = .;
97
98 __initcall_start = .;
99 .initcall.init : {
100 INITCALLS
101 }
102 __initcall_end = .;
103 __con_initcall_start = .;
104 .con_initcall.init : { *(.con_initcall.init) }
105 __con_initcall_end = .;
106
107 SECURITY_INIT
108
109#ifdef CONFIG_BLK_DEV_INITRD
110 . = ALIGN(PAGE_SIZE);
111 __initramfs_start = .;
112 .init.ramfs : { *(.init.ramfs) }
113 __initramfs_end = .;
114#endif
115
116 . = ALIGN(4);
117 __machvec_start = .;
118 .machvec.init : { *(.machvec.init) }
119 __machvec_end = .;
120
121 PERCPU(PAGE_SIZE)
122
123 /*
124 * .exit.text is discarded at runtime, not link time, to deal with
125 * references from __bug_table
126 */
127 .exit.text : { EXIT_TEXT }
128 .exit.data : { EXIT_DATA }
129
130 . = ALIGN(PAGE_SIZE);
131 .bss : {
132 __init_end = .;
133 __bss_start = .; /* BSS */
134 *(.bss.page_aligned)
135 *(.bss)
136 *(COMMON)
137 . = ALIGN(4);
138 _ebss = .; /* uClinux MTD sucks */
139 _end = . ;
140 }
141
142 /*
143 * When something in the kernel is NOT compiled as a module, the
144 * module cleanup code and data are put into these segments. Both
145 * can then be thrown away, as cleanup code is never called unless
146 * it's a module.
147 */
148 /DISCARD/ : {
149 *(.exitcall.exit)
150 }
151
152 STABS_DEBUG
153 DWARF_DEBUG
154}
diff --git a/arch/sh/kernel/vmlinux_64.lds.S b/arch/sh/kernel/vmlinux_64.lds.S
deleted file mode 100644
index 69664460c688..000000000000
--- a/arch/sh/kernel/vmlinux_64.lds.S
+++ /dev/null
@@ -1,163 +0,0 @@
1/*
2 * ld script to make SH64 Linux kernel
3 *
4 * Copyright (C) 2000, 2001 Paolo Alberelli
5 *
6 * benedict.gaster@superh.com: 2nd May 2002
7 * Add definition of empty_zero_page to be the first page of kernel image.
8 *
9 * benedict.gaster@superh.com: 3rd May 2002
10 * Added support for ramdisk, removing statically linked romfs at the
11 * same time.
12 *
13 * lethal@linux-sh.org: 9th May 2003
14 * Kill off GLOBAL_NAME() usage and other CDC-isms.
15 *
16 * lethal@linux-sh.org: 19th May 2003
17 * Remove support for ancient toolchains.
18 *
19 * This file is subject to the terms and conditions of the GNU General Public
20 * License. See the file "COPYING" in the main directory of this archive
21 * for more details.
22 */
23#include <asm/page.h>
24#include <asm/cache.h>
25#include <asm/thread_info.h>
26
27#define LOAD_OFFSET CONFIG_PAGE_OFFSET
28#include <asm-generic/vmlinux.lds.h>
29
30OUTPUT_ARCH(sh:sh5)
31
32#define C_PHYS(x) AT (ADDR(x) - LOAD_OFFSET)
33
34ENTRY(__start)
35SECTIONS
36{
37 . = CONFIG_PAGE_OFFSET + CONFIG_MEMORY_START + PAGE_SIZE;
38 _text = .; /* Text and read-only data */
39
40 .empty_zero_page : C_PHYS(.empty_zero_page) {
41 *(.empty_zero_page)
42 } = 0
43
44 .text : C_PHYS(.text) {
45 HEAD_TEXT
46 TEXT_TEXT
47 *(.text64)
48 *(.text..SHmedia32)
49 SCHED_TEXT
50 LOCK_TEXT
51 KPROBES_TEXT
52 *(.fixup)
53 *(.gnu.warning)
54#ifdef CONFIG_CPU_LITTLE_ENDIAN
55 } = 0x6ff0fff0
56#else
57 } = 0xf0fff06f
58#endif
59
60 /* We likely want __ex_table to be Cache Line aligned */
61 . = ALIGN(L1_CACHE_BYTES); /* Exception table */
62 __start___ex_table = .;
63 __ex_table : C_PHYS(__ex_table) { *(__ex_table) }
64 __stop___ex_table = .;
65
66 _etext = .; /* End of text section */
67
68 NOTES
69 RO_DATA(PAGE_SIZE)
70
71 . = ALIGN(THREAD_SIZE);
72 .data : C_PHYS(.data) { /* Data */
73 *(.data.init_task)
74
75 . = ALIGN(L1_CACHE_BYTES);
76 *(.data.cacheline_aligned)
77
78 . = ALIGN(L1_CACHE_BYTES);
79 *(.data.read_mostly)
80
81 . = ALIGN(PAGE_SIZE);
82 *(.data.page_aligned)
83
84 __nosave_begin = .;
85 *(.data.nosave)
86 . = ALIGN(PAGE_SIZE);
87 __nosave_end = .;
88
89 DATA_DATA
90 CONSTRUCTORS
91 }
92
93 _edata = .; /* End of data section */
94
95 . = ALIGN(PAGE_SIZE); /* Init code and data */
96 __init_begin = .;
97 _sinittext = .;
98 .init.text : C_PHYS(.init.text) { INIT_TEXT }
99 _einittext = .;
100 .init.data : C_PHYS(.init.data) { INIT_DATA }
101 . = ALIGN(L1_CACHE_BYTES); /* Better if Cache Line aligned */
102 __setup_start = .;
103 .init.setup : C_PHYS(.init.setup) { *(.init.setup) }
104 __setup_end = .;
105 __initcall_start = .;
106 .initcall.init : C_PHYS(.initcall.init) {
107 INITCALLS
108 }
109 __initcall_end = .;
110 __con_initcall_start = .;
111 .con_initcall.init : C_PHYS(.con_initcall.init) {
112 *(.con_initcall.init)
113 }
114 __con_initcall_end = .;
115
116 SECURITY_INIT
117
118#ifdef CONFIG_BLK_DEV_INITRD
119 . = ALIGN(PAGE_SIZE);
120 __initramfs_start = .;
121 .init.ramfs : C_PHYS(.init.ramfs) { *(.init.ramfs) }
122 __initramfs_end = .;
123#endif
124
125 . = ALIGN(8);
126 __machvec_start = .;
127 .machvec.init : C_PHYS(.machvec.init) { *(.machvec.init) }
128 __machvec_end = .;
129
130 PERCPU(PAGE_SIZE)
131
132 /*
133 * .exit.text is discarded at runtime, not link time, to deal with
134 * references from __bug_table
135 */
136 .exit.text : C_PHYS(.exit.text) { EXIT_TEXT }
137 .exit.data : C_PHYS(.exit.data) { EXIT_DATA }
138
139 . = ALIGN(PAGE_SIZE);
140 .bss : C_PHYS(.bss) {
141 __init_end = .;
142 __bss_start = .; /* BSS */
143 *(.bss.page_aligned)
144 *(.bss)
145 *(COMMON)
146 . = ALIGN(4);
147 _ebss = .; /* uClinux MTD sucks */
148 _end = . ;
149 }
150
151 /*
152 * When something in the kernel is NOT compiled as a module, the
153 * module cleanup code and data are put into these segments. Both
154 * can then be thrown away, as cleanup code is never called unless
155 * it's a module.
156 */
157 /DISCARD/ : {
158 *(.exitcall.exit)
159 }
160
161 STABS_DEBUG
162 DWARF_DEBUG
163}
diff --git a/arch/sh/lib64/.gitignore b/arch/sh/lib64/.gitignore
deleted file mode 100644
index 3508c2cb23c4..000000000000
--- a/arch/sh/lib64/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
1syscalltab.h
diff --git a/arch/sh/lib64/dbg.c b/arch/sh/lib64/dbg.c
index 2fb8eaf6de60..6152a6a6d9c6 100644
--- a/arch/sh/lib64/dbg.c
+++ b/arch/sh/lib64/dbg.c
@@ -135,140 +135,6 @@ void print_itlb(void)
135 (" =============================================================\n"); 135 (" =============================================================\n");
136} 136}
137 137
138/* ======================================================================= */
139
140#ifdef CONFIG_POOR_MANS_STRACE
141
142#include "syscalltab.h"
143
144struct ring_node {
145 int evt;
146 int ret_addr;
147 int event;
148 int tra;
149 int pid;
150 unsigned long sp;
151 unsigned long pc;
152};
153
154static struct ring_node event_ring[16];
155static int event_ptr = 0;
156
157struct stored_syscall_data {
158 int pid;
159 int syscall_number;
160};
161
162#define N_STORED_SYSCALLS 16
163
164static struct stored_syscall_data stored_syscalls[N_STORED_SYSCALLS];
165static int syscall_next=0;
166static int syscall_next_print=0;
167
168void evt_debug(int evt, int ret_addr, int event, int tra, struct pt_regs *regs)
169{
170 int syscallno = tra & 0xff;
171 unsigned long sp;
172 unsigned long stack_bottom;
173 int pid;
174 struct ring_node *rr;
175
176 pid = current->pid;
177 stack_bottom = (unsigned long) task_stack_page(current);
178 asm volatile("ori r15, 0, %0" : "=r" (sp));
179 rr = event_ring + event_ptr;
180 rr->evt = evt;
181 rr->ret_addr = ret_addr;
182 rr->event = event;
183 rr->tra = tra;
184 rr->pid = pid;
185 rr->sp = sp;
186 rr->pc = regs->pc;
187
188 if (sp < stack_bottom + 3092) {
189 int i, j;
190 printk("evt_debug : stack underflow report\n");
191 for (j=0, i = event_ptr; j<16; j++) {
192 rr = event_ring + i;
193 printk("evt=%08x event=%08x tra=%08x pid=%5d sp=%08lx pc=%08lx\n",
194 rr->evt, rr->event, rr->tra, rr->pid, rr->sp, rr->pc);
195 i--;
196 i &= 15;
197 }
198 panic("STACK UNDERFLOW\n");
199 }
200
201 event_ptr = (event_ptr + 1) & 15;
202
203 if ((event == 2) && (evt == 0x160)) {
204 if (syscallno < NUM_SYSCALL_INFO_ENTRIES) {
205 /* Store the syscall information to print later. We
206 * can't print this now - currently we're running with
207 * SR.BL=1, so we can't take a tlbmiss (which could occur
208 * in the console drivers under printk).
209 *
210 * Just overwrite old entries on ring overflow - this
211 * is only for last-hope debugging. */
212 stored_syscalls[syscall_next].pid = current->pid;
213 stored_syscalls[syscall_next].syscall_number = syscallno;
214 syscall_next++;
215 syscall_next &= (N_STORED_SYSCALLS - 1);
216 }
217 }
218}
219
220static void drain_syscalls(void) {
221 while (syscall_next_print != syscall_next) {
222 printk("Task %d: %s()\n",
223 stored_syscalls[syscall_next_print].pid,
224 syscall_info_table[stored_syscalls[syscall_next_print].syscall_number].name);
225 syscall_next_print++;
226 syscall_next_print &= (N_STORED_SYSCALLS - 1);
227 }
228}
229
230void evt_debug2(unsigned int ret)
231{
232 drain_syscalls();
233 printk("Task %d: syscall returns %08x\n", current->pid, ret);
234}
235
236void evt_debug_ret_from_irq(struct pt_regs *regs)
237{
238 int pid;
239 struct ring_node *rr;
240
241 pid = current->pid;
242 rr = event_ring + event_ptr;
243 rr->evt = 0xffff;
244 rr->ret_addr = 0;
245 rr->event = 0;
246 rr->tra = 0;
247 rr->pid = pid;
248 rr->pc = regs->pc;
249 event_ptr = (event_ptr + 1) & 15;
250}
251
252void evt_debug_ret_from_exc(struct pt_regs *regs)
253{
254 int pid;
255 struct ring_node *rr;
256
257 pid = current->pid;
258 rr = event_ring + event_ptr;
259 rr->evt = 0xfffe;
260 rr->ret_addr = 0;
261 rr->event = 0;
262 rr->tra = 0;
263 rr->pid = pid;
264 rr->pc = regs->pc;
265 event_ptr = (event_ptr + 1) & 15;
266}
267
268#endif /* CONFIG_POOR_MANS_STRACE */
269
270/* ======================================================================= */
271
272void show_excp_regs(char *from, int trapnr, int signr, struct pt_regs *regs) 138void show_excp_regs(char *from, int trapnr, int signr, struct pt_regs *regs)
273{ 139{
274 140
@@ -380,51 +246,3 @@ void show_excp_regs(char *from, int trapnr, int signr, struct pt_regs *regs)
380 print_dtlb(); 246 print_dtlb();
381 print_itlb(); 247 print_itlb();
382} 248}
383
384/* ======================================================================= */
385
386/*
387** Depending on <base> scan the MMU, Data or Instruction side
388** looking for a valid mapping matching Eaddr & asid.
389** Return -1 if not found or the TLB id entry otherwise.
390** Note: it works only for 4k pages!
391*/
392static unsigned long
393lookup_mmu_side(unsigned long base, unsigned long Eaddr, unsigned long asid)
394{
395 regType_t pteH;
396 unsigned long epn;
397 int count;
398
399 epn = Eaddr & 0xfffff000;
400
401 for (count = 0; count < MAX_TLBs; count++, base += TLB_STEP) {
402 pteH = getConfigReg(base);
403 if (GET_VALID(pteH))
404 if ((unsigned long) GET_EPN(pteH) == epn)
405 if ((unsigned long) GET_ASID(pteH) == asid)
406 break;
407 }
408 return ((unsigned long) ((count < MAX_TLBs) ? base : -1));
409}
410
411unsigned long lookup_dtlb(unsigned long Eaddr)
412{
413 unsigned long asid = get_asid();
414 return (lookup_mmu_side((u64) DTLB_BASE, Eaddr, asid));
415}
416
417unsigned long lookup_itlb(unsigned long Eaddr)
418{
419 unsigned long asid = get_asid();
420 return (lookup_mmu_side((u64) ITLB_BASE, Eaddr, asid));
421}
422
423void print_page(struct page *page)
424{
425 printk(" page[%p] -> index 0x%lx, count 0x%x, flags 0x%lx\n",
426 page, page->index, page_count(page), page->flags);
427 printk(" address_space = %p, pages =%ld\n", page->mapping,
428 page->mapping->nrpages);
429
430}
diff --git a/arch/sh/lib64/panic.c b/arch/sh/lib64/panic.c
index da32ba7b5fcc..38c954e04f6a 100644
--- a/arch/sh/lib64/panic.c
+++ b/arch/sh/lib64/panic.c
@@ -6,53 +6,10 @@
6 * for more details. 6 * for more details.
7 */ 7 */
8 8
9#include <linux/kernel.h>
10#include <asm/io.h>
11#include <cpu/registers.h>
12
13/* THIS IS A PHYSICAL ADDRESS */
14#define HDSP2534_ADDR (0x04002100)
15
16#ifdef CONFIG_SH_CAYMAN
17
18static void poor_mans_delay(void)
19{
20 int i;
21 for (i = 0; i < 2500000; i++) {
22 } /* poor man's delay */
23}
24
25static void show_value(unsigned long x)
26{
27 int i;
28 unsigned nibble;
29 for (i = 0; i < 8; i++) {
30 nibble = ((x >> (i * 4)) & 0xf);
31
32 ctrl_outb(nibble + ((nibble > 9) ? 55 : 48),
33 HDSP2534_ADDR + 0xe0 + ((7 - i) << 2));
34 }
35}
36
37#endif
38
39void 9void
40panic_handler(unsigned long panicPC, unsigned long panicSSR, 10panic_handler(unsigned long panicPC, unsigned long panicSSR,
41 unsigned long panicEXPEVT) 11 unsigned long panicEXPEVT)
42{ 12{
43#ifdef CONFIG_SH_CAYMAN
44 while (1) {
45 /* This piece of code displays the PC on the LED display */
46 show_value(panicPC);
47 poor_mans_delay();
48 show_value(panicSSR);
49 poor_mans_delay();
50 show_value(panicEXPEVT);
51 poor_mans_delay();
52 }
53#endif
54
55 /* Never return from the panic handler */ 13 /* Never return from the panic handler */
56 for (;;) ; 14 for (;;) ;
57
58} 15}
diff --git a/arch/sh/lib64/sdivsi3.S b/arch/sh/lib64/sdivsi3.S
index 6a800c6a4904..1963bbd42288 100644
--- a/arch/sh/lib64/sdivsi3.S
+++ b/arch/sh/lib64/sdivsi3.S
@@ -1,4 +1,6 @@
1 .global __sdivsi3 1 .global __sdivsi3
2 .global __sdivsi3_1
3 .global __sdivsi3_2
2 .section .text..SHmedia32,"ax" 4 .section .text..SHmedia32,"ax"
3 .align 2 5 .align 2
4 6
@@ -6,13 +8,15 @@
6 /* clobbered: r1,r18,r19,r20,r21,r25,tr0 */ 8 /* clobbered: r1,r18,r19,r20,r21,r25,tr0 */
7 /* result in r0 */ 9 /* result in r0 */
8__sdivsi3: 10__sdivsi3:
11__sdivsi3_1:
9 ptb __div_table,tr0 12 ptb __div_table,tr0
13 gettr tr0,r20
10 14
15__sdivsi3_2:
11 nsb r5, r1 16 nsb r5, r1
12 shlld r5, r1, r25 /* normalize; [-2 ..1, 1..2) in s2.62 */ 17 shlld r5, r1, r25 /* normalize; [-2 ..1, 1..2) in s2.62 */
13 shari r25, 58, r21 /* extract 5(6) bit index (s2.4 with hole -1..1) */ 18 shari r25, 58, r21 /* extract 5(6) bit index (s2.4 with hole -1..1) */
14 /* bubble */ 19 /* bubble */
15 gettr tr0,r20
16 ldx.ub r20, r21, r19 /* u0.8 */ 20 ldx.ub r20, r21, r19 /* u0.8 */
17 shari r25, 32, r25 /* normalize to s2.30 */ 21 shari r25, 32, r25 /* normalize to s2.30 */
18 shlli r21, 1, r21 22 shlli r21, 1, r21
diff --git a/arch/sh/lib64/udelay.c b/arch/sh/lib64/udelay.c
index d76bd801194f..f215b063da70 100644
--- a/arch/sh/lib64/udelay.c
+++ b/arch/sh/lib64/udelay.c
@@ -33,7 +33,7 @@ void __delay(unsigned long loops)
33 :"0"(loops)); 33 :"0"(loops));
34} 34}
35 35
36inline void __const_udelay(unsigned long xloops) 36void __const_udelay(unsigned long xloops)
37{ 37{
38 __delay(xloops * (HZ * cpu_data[raw_smp_processor_id()].loops_per_jiffy)); 38 __delay(xloops * (HZ * cpu_data[raw_smp_processor_id()].loops_per_jiffy));
39} 39}
diff --git a/arch/sh/mm/Kconfig b/arch/sh/mm/Kconfig
index d4079cab2d58..2795618e4f07 100644
--- a/arch/sh/mm/Kconfig
+++ b/arch/sh/mm/Kconfig
@@ -21,6 +21,29 @@ config PAGE_OFFSET
21 default "0x20000000" if MMU && SUPERH64 21 default "0x20000000" if MMU && SUPERH64
22 default "0x00000000" 22 default "0x00000000"
23 23
24config FORCE_MAX_ZONEORDER
25 int "Maximum zone order"
26 range 9 64 if PAGE_SIZE_16KB
27 default "9" if PAGE_SIZE_16KB
28 range 7 64 if PAGE_SIZE_64KB
29 default "7" if PAGE_SIZE_64KB
30 range 11 64
31 default "14" if !MMU
32 default "11"
33 help
34 The kernel memory allocator divides physically contiguous memory
35 blocks into "zones", where each zone is a power of two number of
36 pages. This option selects the largest power of two that the kernel
37 keeps in the memory allocator. If you need to allocate very large
38 blocks of physically contiguous memory, then you may need to
39 increase this value.
40
41 This config option is actually maximum order plus one. For example,
42 a value of 11 means that the largest free memory block is 2^10 pages.
43
44 The page size is not necessarily 4KB. Keep this in mind when
45 choosing a value for this option.
46
24config MEMORY_START 47config MEMORY_START
25 hex "Physical memory start address" 48 hex "Physical memory start address"
26 default "0x08000000" 49 default "0x08000000"
@@ -201,14 +224,6 @@ config PAGE_SIZE_64KB
201 224
202endchoice 225endchoice
203 226
204config ENTRY_OFFSET
205 hex
206 default "0x00001000" if PAGE_SIZE_4KB
207 default "0x00002000" if PAGE_SIZE_8KB
208 default "0x00004000" if PAGE_SIZE_16KB
209 default "0x00010000" if PAGE_SIZE_64KB
210 default "0x00000000"
211
212choice 227choice
213 prompt "HugeTLB page size" 228 prompt "HugeTLB page size"
214 depends on HUGETLB_PAGE && (CPU_SH4 || CPU_SH5) && MMU 229 depends on HUGETLB_PAGE && (CPU_SH4 || CPU_SH5) && MMU
diff --git a/arch/sh/mm/cache-sh5.c b/arch/sh/mm/cache-sh5.c
index 9e277ec7d536..86762092508c 100644
--- a/arch/sh/mm/cache-sh5.c
+++ b/arch/sh/mm/cache-sh5.c
@@ -60,7 +60,7 @@ static inline void sh64_teardown_dtlb_cache_slot(void)
60static inline void sh64_icache_inv_all(void) 60static inline void sh64_icache_inv_all(void)
61{ 61{
62 unsigned long long addr, flag, data; 62 unsigned long long addr, flag, data;
63 unsigned int flags; 63 unsigned long flags;
64 64
65 addr = ICCR0; 65 addr = ICCR0;
66 flag = ICCR0_ICI; 66 flag = ICCR0_ICI;
@@ -172,7 +172,7 @@ static void sh64_icache_inv_user_page_range(struct mm_struct *mm,
172 unsigned long eaddr; 172 unsigned long eaddr;
173 unsigned long after_last_page_start; 173 unsigned long after_last_page_start;
174 unsigned long mm_asid, current_asid; 174 unsigned long mm_asid, current_asid;
175 unsigned long long flags = 0ULL; 175 unsigned long flags = 0;
176 176
177 mm_asid = cpu_asid(smp_processor_id(), mm); 177 mm_asid = cpu_asid(smp_processor_id(), mm);
178 current_asid = get_asid(); 178 current_asid = get_asid();
@@ -236,7 +236,7 @@ static void sh64_icache_inv_user_small_range(struct mm_struct *mm,
236 unsigned long long eaddr = start; 236 unsigned long long eaddr = start;
237 unsigned long long eaddr_end = start + len; 237 unsigned long long eaddr_end = start + len;
238 unsigned long current_asid, mm_asid; 238 unsigned long current_asid, mm_asid;
239 unsigned long long flags; 239 unsigned long flags;
240 unsigned long long epage_start; 240 unsigned long long epage_start;
241 241
242 /* 242 /*
@@ -342,7 +342,7 @@ static void inline sh64_dcache_purge_sets(int sets_to_purge_base, int n_sets)
342 * alloco is a NOP if the cache is write-through. 342 * alloco is a NOP if the cache is write-through.
343 */ 343 */
344 if (test_bit(SH_CACHE_MODE_WT, &(cpu_data->dcache.flags))) 344 if (test_bit(SH_CACHE_MODE_WT, &(cpu_data->dcache.flags)))
345 ctrl_inb(eaddr); 345 __raw_readb((unsigned long)eaddr);
346 } 346 }
347 } 347 }
348 348
diff --git a/arch/sh/mm/init.c b/arch/sh/mm/init.c
index 3edf297c829b..ee8e6bbe882c 100644
--- a/arch/sh/mm/init.c
+++ b/arch/sh/mm/init.c
@@ -184,7 +184,6 @@ void __init paging_init(void)
184} 184}
185 185
186static struct kcore_list kcore_mem, kcore_vmalloc; 186static struct kcore_list kcore_mem, kcore_vmalloc;
187int after_bootmem = 0;
188 187
189void __init mem_init(void) 188void __init mem_init(void)
190{ 189{
@@ -217,8 +216,6 @@ void __init mem_init(void)
217 memset(empty_zero_page, 0, PAGE_SIZE); 216 memset(empty_zero_page, 0, PAGE_SIZE);
218 __flush_wback_region(empty_zero_page, PAGE_SIZE); 217 __flush_wback_region(empty_zero_page, PAGE_SIZE);
219 218
220 after_bootmem = 1;
221
222 codesize = (unsigned long) &_etext - (unsigned long) &_text; 219 codesize = (unsigned long) &_etext - (unsigned long) &_text;
223 datasize = (unsigned long) &_edata - (unsigned long) &_etext; 220 datasize = (unsigned long) &_edata - (unsigned long) &_etext;
224 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin; 221 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
diff --git a/arch/sh/mm/ioremap_32.c b/arch/sh/mm/ioremap_32.c
index 60cc486d2c2c..da2f4186f2cd 100644
--- a/arch/sh/mm/ioremap_32.c
+++ b/arch/sh/mm/ioremap_32.c
@@ -46,17 +46,15 @@ void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
46 return NULL; 46 return NULL;
47 47
48 /* 48 /*
49 * If we're on an SH7751 or SH7780 PCI controller, PCI memory is 49 * If we're in the fixed PCI memory range, mapping through page
50 * mapped at the end of the address space (typically 0xfd000000) 50 * tables is not only pointless, but also fundamentally broken.
51 * in a non-translatable area, so mapping through page tables for 51 * Just return the physical address instead.
52 * this area is not only pointless, but also fundamentally
53 * broken. Just return the physical address instead.
54 * 52 *
55 * For boards that map a small PCI memory aperture somewhere in 53 * For boards that map a small PCI memory aperture somewhere in
56 * P1/P2 space, ioremap() will already do the right thing, 54 * P1/P2 space, ioremap() will already do the right thing,
57 * and we'll never get this far. 55 * and we'll never get this far.
58 */ 56 */
59 if (is_pci_memaddr(phys_addr) && is_pci_memaddr(last_addr)) 57 if (is_pci_memory_fixed_range(phys_addr, size))
60 return (void __iomem *)phys_addr; 58 return (void __iomem *)phys_addr;
61 59
62#if !defined(CONFIG_PMB_FIXED) 60#if !defined(CONFIG_PMB_FIXED)
@@ -121,7 +119,9 @@ void __iounmap(void __iomem *addr)
121 unsigned long seg = PXSEG(vaddr); 119 unsigned long seg = PXSEG(vaddr);
122 struct vm_struct *p; 120 struct vm_struct *p;
123 121
124 if (seg < P3SEG || vaddr >= P3_ADDR_MAX || is_pci_memaddr(vaddr)) 122 if (seg < P3SEG || vaddr >= P3_ADDR_MAX)
123 return;
124 if (is_pci_memory_fixed_range(vaddr, 0))
125 return; 125 return;
126 126
127#ifdef CONFIG_PMB 127#ifdef CONFIG_PMB
diff --git a/arch/sh/mm/ioremap_64.c b/arch/sh/mm/ioremap_64.c
index 31e1bb5effbe..828c8597219d 100644
--- a/arch/sh/mm/ioremap_64.c
+++ b/arch/sh/mm/ioremap_64.c
@@ -20,6 +20,7 @@
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/bootmem.h> 21#include <linux/bootmem.h>
22#include <linux/proc_fs.h> 22#include <linux/proc_fs.h>
23#include <linux/slab.h>
23#include <asm/page.h> 24#include <asm/page.h>
24#include <asm/pgalloc.h> 25#include <asm/pgalloc.h>
25#include <asm/addrspace.h> 26#include <asm/addrspace.h>
@@ -27,88 +28,17 @@
27#include <asm/tlbflush.h> 28#include <asm/tlbflush.h>
28#include <asm/mmu.h> 29#include <asm/mmu.h>
29 30
30static void shmedia_mapioaddr(unsigned long, unsigned long);
31static unsigned long shmedia_ioremap(struct resource *, u32, int);
32
33/*
34 * Generic mapping function (not visible outside):
35 */
36
37/*
38 * Remap an arbitrary physical address space into the kernel virtual
39 * address space. Needed when the kernel wants to access high addresses
40 * directly.
41 *
42 * NOTE! We need to allow non-page-aligned mappings too: we will obviously
43 * have to convert them into an offset in a page-aligned mapping, but the
44 * caller shouldn't need to know that small detail.
45 */
46void *__ioremap(unsigned long phys_addr, unsigned long size,
47 unsigned long flags)
48{
49 void * addr;
50 struct vm_struct * area;
51 unsigned long offset, last_addr;
52 pgprot_t pgprot;
53
54 /* Don't allow wraparound or zero size */
55 last_addr = phys_addr + size - 1;
56 if (!size || last_addr < phys_addr)
57 return NULL;
58
59 pgprot = __pgprot(_PAGE_PRESENT | _PAGE_READ |
60 _PAGE_WRITE | _PAGE_DIRTY |
61 _PAGE_ACCESSED | _PAGE_SHARED | flags);
62
63 /*
64 * Mappings have to be page-aligned
65 */
66 offset = phys_addr & ~PAGE_MASK;
67 phys_addr &= PAGE_MASK;
68 size = PAGE_ALIGN(last_addr + 1) - phys_addr;
69
70 /*
71 * Ok, go for it..
72 */
73 area = get_vm_area(size, VM_IOREMAP);
74 if (!area)
75 return NULL;
76 pr_debug("Get vm_area returns %p addr %p\n", area, area->addr);
77 area->phys_addr = phys_addr;
78 addr = area->addr;
79 if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size,
80 phys_addr, pgprot)) {
81 vunmap(addr);
82 return NULL;
83 }
84 return (void *) (offset + (char *)addr);
85}
86EXPORT_SYMBOL(__ioremap);
87
88void __iounmap(void *addr)
89{
90 struct vm_struct *area;
91
92 vfree((void *) (PAGE_MASK & (unsigned long) addr));
93 area = remove_vm_area((void *) (PAGE_MASK & (unsigned long) addr));
94 if (!area) {
95 printk(KERN_ERR "iounmap: bad address %p\n", addr);
96 return;
97 }
98
99 kfree(area);
100}
101EXPORT_SYMBOL(__iounmap);
102
103static struct resource shmedia_iomap = { 31static struct resource shmedia_iomap = {
104 .name = "shmedia_iomap", 32 .name = "shmedia_iomap",
105 .start = IOBASE_VADDR + PAGE_SIZE, 33 .start = IOBASE_VADDR + PAGE_SIZE,
106 .end = IOBASE_END - 1, 34 .end = IOBASE_END - 1,
107}; 35};
108 36
109static void shmedia_mapioaddr(unsigned long pa, unsigned long va); 37static void shmedia_mapioaddr(unsigned long pa, unsigned long va,
38 unsigned long flags);
110static void shmedia_unmapioaddr(unsigned long vaddr); 39static void shmedia_unmapioaddr(unsigned long vaddr);
111static unsigned long shmedia_ioremap(struct resource *res, u32 pa, int sz); 40static void __iomem *shmedia_ioremap(struct resource *res, u32 pa,
41 int sz, unsigned long flags);
112 42
113/* 43/*
114 * We have the same problem as the SPARC, so lets have the same comment: 44 * We have the same problem as the SPARC, so lets have the same comment:
@@ -130,18 +60,18 @@ static struct xresource xresv[XNRES];
130 60
131static struct xresource *xres_alloc(void) 61static struct xresource *xres_alloc(void)
132{ 62{
133 struct xresource *xrp; 63 struct xresource *xrp;
134 int n; 64 int n;
135 65
136 xrp = xresv; 66 xrp = xresv;
137 for (n = 0; n < XNRES; n++) { 67 for (n = 0; n < XNRES; n++) {
138 if (xrp->xflag == 0) { 68 if (xrp->xflag == 0) {
139 xrp->xflag = 1; 69 xrp->xflag = 1;
140 return xrp; 70 return xrp;
141 } 71 }
142 xrp++; 72 xrp++;
143 } 73 }
144 return NULL; 74 return NULL;
145} 75}
146 76
147static void xres_free(struct xresource *xrp) 77static void xres_free(struct xresource *xrp)
@@ -161,76 +91,71 @@ static struct resource *shmedia_find_resource(struct resource *root,
161 return NULL; 91 return NULL;
162} 92}
163 93
164static unsigned long shmedia_alloc_io(unsigned long phys, unsigned long size, 94static void __iomem *shmedia_alloc_io(unsigned long phys, unsigned long size,
165 const char *name) 95 const char *name, unsigned long flags)
166{ 96{
167 static int printed_full = 0; 97 static int printed_full;
168 struct xresource *xres; 98 struct xresource *xres;
169 struct resource *res; 99 struct resource *res;
170 char *tack; 100 char *tack;
171 int tlen; 101 int tlen;
172 102
173 if (name == NULL) name = "???"; 103 if (name == NULL)
174 104 name = "???";
175 if ((xres = xres_alloc()) != 0) { 105
176 tack = xres->xname; 106 xres = xres_alloc();
177 res = &xres->xres; 107 if (xres != 0) {
178 } else { 108 tack = xres->xname;
179 if (!printed_full) { 109 res = &xres->xres;
180 printk("%s: done with statics, switching to kmalloc\n", 110 } else {
181 __func__); 111 if (!printed_full) {
182 printed_full = 1; 112 printk(KERN_NOTICE "%s: done with statics, "
183 } 113 "switching to kmalloc\n", __func__);
184 tlen = strlen(name); 114 printed_full = 1;
185 tack = kmalloc(sizeof (struct resource) + tlen + 1, GFP_KERNEL); 115 }
186 if (!tack) 116 tlen = strlen(name);
187 return -ENOMEM; 117 tack = kmalloc(sizeof(struct resource) + tlen + 1, GFP_KERNEL);
188 memset(tack, 0, sizeof(struct resource)); 118 if (!tack)
189 res = (struct resource *) tack; 119 return NULL;
190 tack += sizeof (struct resource); 120 memset(tack, 0, sizeof(struct resource));
191 } 121 res = (struct resource *) tack;
192 122 tack += sizeof(struct resource);
193 strncpy(tack, name, XNMLN); 123 }
194 tack[XNMLN] = 0; 124
195 res->name = tack; 125 strncpy(tack, name, XNMLN);
196 126 tack[XNMLN] = 0;
197 return shmedia_ioremap(res, phys, size); 127 res->name = tack;
128
129 return shmedia_ioremap(res, phys, size, flags);
198} 130}
199 131
200static unsigned long shmedia_ioremap(struct resource *res, u32 pa, int sz) 132static void __iomem *shmedia_ioremap(struct resource *res, u32 pa, int sz,
133 unsigned long flags)
201{ 134{
202 unsigned long offset = ((unsigned long) pa) & (~PAGE_MASK); 135 unsigned long offset = ((unsigned long) pa) & (~PAGE_MASK);
203 unsigned long round_sz = (offset + sz + PAGE_SIZE-1) & PAGE_MASK; 136 unsigned long round_sz = (offset + sz + PAGE_SIZE-1) & PAGE_MASK;
204 unsigned long va; 137 unsigned long va;
205 unsigned int psz; 138 unsigned int psz;
206 139
207 if (allocate_resource(&shmedia_iomap, res, round_sz, 140 if (allocate_resource(&shmedia_iomap, res, round_sz,
208 shmedia_iomap.start, shmedia_iomap.end, 141 shmedia_iomap.start, shmedia_iomap.end,
209 PAGE_SIZE, NULL, NULL) != 0) { 142 PAGE_SIZE, NULL, NULL) != 0) {
210 panic("alloc_io_res(%s): cannot occupy\n", 143 panic("alloc_io_res(%s): cannot occupy\n",
211 (res->name != NULL)? res->name: "???"); 144 (res->name != NULL) ? res->name : "???");
212 } 145 }
213 146
214 va = res->start; 147 va = res->start;
215 pa &= PAGE_MASK; 148 pa &= PAGE_MASK;
216 149
217 psz = (res->end - res->start + (PAGE_SIZE - 1)) / PAGE_SIZE; 150 psz = (res->end - res->start + (PAGE_SIZE - 1)) / PAGE_SIZE;
218 151
219 /* log at boot time ... */ 152 for (psz = res->end - res->start + 1; psz != 0; psz -= PAGE_SIZE) {
220 printk("mapioaddr: %6s [%2d page%s] va 0x%08lx pa 0x%08x\n", 153 shmedia_mapioaddr(pa, va, flags);
221 ((res->name != NULL) ? res->name : "???"), 154 va += PAGE_SIZE;
222 psz, psz == 1 ? " " : "s", va, pa); 155 pa += PAGE_SIZE;
223 156 }
224 for (psz = res->end - res->start + 1; psz != 0; psz -= PAGE_SIZE) {
225 shmedia_mapioaddr(pa, va);
226 va += PAGE_SIZE;
227 pa += PAGE_SIZE;
228 }
229
230 res->start += offset;
231 res->end = res->start + sz - 1; /* not strictly necessary.. */
232 157
233 return res->start; 158 return (void __iomem *)(unsigned long)(res->start + offset);
234} 159}
235 160
236static void shmedia_free_io(struct resource *res) 161static void shmedia_free_io(struct resource *res)
@@ -249,14 +174,12 @@ static void shmedia_free_io(struct resource *res)
249 174
250static __init_refok void *sh64_get_page(void) 175static __init_refok void *sh64_get_page(void)
251{ 176{
252 extern int after_bootmem;
253 void *page; 177 void *page;
254 178
255 if (after_bootmem) { 179 if (slab_is_available())
256 page = (void *)get_zeroed_page(GFP_ATOMIC); 180 page = (void *)get_zeroed_page(GFP_KERNEL);
257 } else { 181 else
258 page = alloc_bootmem_pages(PAGE_SIZE); 182 page = alloc_bootmem_pages(PAGE_SIZE);
259 }
260 183
261 if (!page || ((unsigned long)page & ~PAGE_MASK)) 184 if (!page || ((unsigned long)page & ~PAGE_MASK))
262 panic("sh64_get_page: Out of memory already?\n"); 185 panic("sh64_get_page: Out of memory already?\n");
@@ -264,17 +187,20 @@ static __init_refok void *sh64_get_page(void)
264 return page; 187 return page;
265} 188}
266 189
267static void shmedia_mapioaddr(unsigned long pa, unsigned long va) 190static void shmedia_mapioaddr(unsigned long pa, unsigned long va,
191 unsigned long flags)
268{ 192{
269 pgd_t *pgdp; 193 pgd_t *pgdp;
270 pud_t *pudp; 194 pud_t *pudp;
271 pmd_t *pmdp; 195 pmd_t *pmdp;
272 pte_t *ptep, pte; 196 pte_t *ptep, pte;
273 pgprot_t prot; 197 pgprot_t prot;
274 unsigned long flags = 1; /* 1 = CB0-1 device */
275 198
276 pr_debug("shmedia_mapiopage pa %08lx va %08lx\n", pa, va); 199 pr_debug("shmedia_mapiopage pa %08lx va %08lx\n", pa, va);
277 200
201 if (!flags)
202 flags = 1; /* 1 = CB0-1 device */
203
278 pgdp = pgd_offset_k(va); 204 pgdp = pgd_offset_k(va);
279 if (pgd_none(*pgdp) || !pgd_present(*pgdp)) { 205 if (pgd_none(*pgdp) || !pgd_present(*pgdp)) {
280 pudp = (pud_t *)sh64_get_page(); 206 pudp = (pud_t *)sh64_get_page();
@@ -288,7 +214,7 @@ static void shmedia_mapioaddr(unsigned long pa, unsigned long va)
288 } 214 }
289 215
290 pmdp = pmd_offset(pudp, va); 216 pmdp = pmd_offset(pudp, va);
291 if (pmd_none(*pmdp) || !pmd_present(*pmdp) ) { 217 if (pmd_none(*pmdp) || !pmd_present(*pmdp)) {
292 ptep = (pte_t *)sh64_get_page(); 218 ptep = (pte_t *)sh64_get_page();
293 set_pmd(pmdp, __pmd((unsigned long)ptep + _PAGE_TABLE)); 219 set_pmd(pmdp, __pmd((unsigned long)ptep + _PAGE_TABLE));
294 } 220 }
@@ -336,17 +262,19 @@ static void shmedia_unmapioaddr(unsigned long vaddr)
336 pte_clear(&init_mm, vaddr, ptep); 262 pte_clear(&init_mm, vaddr, ptep);
337} 263}
338 264
339unsigned long onchip_remap(unsigned long phys, unsigned long size, const char *name) 265void __iomem *__ioremap(unsigned long offset, unsigned long size,
266 unsigned long flags)
340{ 267{
341 if (size < PAGE_SIZE) 268 char name[14];
342 size = PAGE_SIZE;
343 269
344 return shmedia_alloc_io(phys, size, name); 270 sprintf(name, "phys_%08x", (u32)offset);
271 return shmedia_alloc_io(offset, size, name, flags);
345} 272}
346EXPORT_SYMBOL(onchip_remap); 273EXPORT_SYMBOL(__ioremap);
347 274
348void onchip_unmap(unsigned long vaddr) 275void __iounmap(void __iomem *virtual)
349{ 276{
277 unsigned long vaddr = (unsigned long)virtual & PAGE_MASK;
350 struct resource *res; 278 struct resource *res;
351 unsigned int psz; 279 unsigned int psz;
352 280
@@ -357,10 +285,7 @@ void onchip_unmap(unsigned long vaddr)
357 return; 285 return;
358 } 286 }
359 287
360 psz = (res->end - res->start + (PAGE_SIZE - 1)) / PAGE_SIZE; 288 psz = (res->end - res->start + (PAGE_SIZE - 1)) / PAGE_SIZE;
361
362 printk(KERN_DEBUG "unmapioaddr: %6s [%2d page%s] freed\n",
363 res->name, psz, psz == 1 ? " " : "s");
364 289
365 shmedia_free_io(res); 290 shmedia_free_io(res);
366 291
@@ -371,9 +296,8 @@ void onchip_unmap(unsigned long vaddr)
371 kfree(res); 296 kfree(res);
372 } 297 }
373} 298}
374EXPORT_SYMBOL(onchip_unmap); 299EXPORT_SYMBOL(__iounmap);
375 300
376#ifdef CONFIG_PROC_FS
377static int 301static int
378ioremap_proc_info(char *buf, char **start, off_t fpos, int length, int *eof, 302ioremap_proc_info(char *buf, char **start, off_t fpos, int length, int *eof,
379 void *data) 303 void *data)
@@ -385,7 +309,10 @@ ioremap_proc_info(char *buf, char **start, off_t fpos, int length, int *eof,
385 for (r = ((struct resource *)data)->child; r != NULL; r = r->sibling) { 309 for (r = ((struct resource *)data)->child; r != NULL; r = r->sibling) {
386 if (p + 32 >= e) /* Better than nothing */ 310 if (p + 32 >= e) /* Better than nothing */
387 break; 311 break;
388 if ((nm = r->name) == 0) nm = "???"; 312 nm = r->name;
313 if (nm == NULL)
314 nm = "???";
315
389 p += sprintf(p, "%08lx-%08lx: %s\n", 316 p += sprintf(p, "%08lx-%08lx: %s\n",
390 (unsigned long)r->start, 317 (unsigned long)r->start,
391 (unsigned long)r->end, nm); 318 (unsigned long)r->end, nm);
@@ -393,14 +320,11 @@ ioremap_proc_info(char *buf, char **start, off_t fpos, int length, int *eof,
393 320
394 return p-buf; 321 return p-buf;
395} 322}
396#endif /* CONFIG_PROC_FS */
397 323
398static int __init register_proc_onchip(void) 324static int __init register_proc_onchip(void)
399{ 325{
400#ifdef CONFIG_PROC_FS 326 create_proc_read_entry("io_map", 0, 0, ioremap_proc_info,
401 create_proc_read_entry("io_map",0,0, ioremap_proc_info, &shmedia_iomap); 327 &shmedia_iomap);
402#endif
403 return 0; 328 return 0;
404} 329}
405 330late_initcall(register_proc_onchip);
406__initcall(register_proc_onchip);
diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
index 931f4d003fa0..1b5fdfb4e0c2 100644
--- a/arch/sh/mm/mmap.c
+++ b/arch/sh/mm/mmap.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * arch/sh/mm/mmap.c 2 * arch/sh/mm/mmap.c
3 * 3 *
4 * Copyright (C) 2008 Paul Mundt 4 * Copyright (C) 2008 - 2009 Paul Mundt
5 * 5 *
6 * This file is subject to the terms and conditions of the GNU General Public 6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive 7 * License. See the file "COPYING" in the main directory of this archive
@@ -21,9 +21,26 @@ EXPORT_SYMBOL(shm_align_mask);
21/* 21/*
22 * To avoid cache aliases, we map the shared page with same color. 22 * To avoid cache aliases, we map the shared page with same color.
23 */ 23 */
24#define COLOUR_ALIGN(addr, pgoff) \ 24static inline unsigned long COLOUR_ALIGN(unsigned long addr,
25 ((((addr) + shm_align_mask) & ~shm_align_mask) + \ 25 unsigned long pgoff)
26 (((pgoff) << PAGE_SHIFT) & shm_align_mask)) 26{
27 unsigned long base = (addr + shm_align_mask) & ~shm_align_mask;
28 unsigned long off = (pgoff << PAGE_SHIFT) & shm_align_mask;
29
30 return base + off;
31}
32
33static inline unsigned long COLOUR_ALIGN_DOWN(unsigned long addr,
34 unsigned long pgoff)
35{
36 unsigned long base = addr & ~shm_align_mask;
37 unsigned long off = (pgoff << PAGE_SHIFT) & shm_align_mask;
38
39 if (base + off <= addr)
40 return base + off;
41
42 return base - off;
43}
27 44
28unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, 45unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
29 unsigned long len, unsigned long pgoff, unsigned long flags) 46 unsigned long len, unsigned long pgoff, unsigned long flags)
@@ -103,6 +120,117 @@ full_search:
103 addr = COLOUR_ALIGN(addr, pgoff); 120 addr = COLOUR_ALIGN(addr, pgoff);
104 } 121 }
105} 122}
123
124unsigned long
125arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
126 const unsigned long len, const unsigned long pgoff,
127 const unsigned long flags)
128{
129 struct vm_area_struct *vma;
130 struct mm_struct *mm = current->mm;
131 unsigned long addr = addr0;
132 int do_colour_align;
133
134 if (flags & MAP_FIXED) {
135 /* We do not accept a shared mapping if it would violate
136 * cache aliasing constraints.
137 */
138 if ((flags & MAP_SHARED) &&
139 ((addr - (pgoff << PAGE_SHIFT)) & shm_align_mask))
140 return -EINVAL;
141 return addr;
142 }
143
144 if (unlikely(len > TASK_SIZE))
145 return -ENOMEM;
146
147 do_colour_align = 0;
148 if (filp || (flags & MAP_SHARED))
149 do_colour_align = 1;
150
151 /* requesting a specific address */
152 if (addr) {
153 if (do_colour_align)
154 addr = COLOUR_ALIGN(addr, pgoff);
155 else
156 addr = PAGE_ALIGN(addr);
157
158 vma = find_vma(mm, addr);
159 if (TASK_SIZE - len >= addr &&
160 (!vma || addr + len <= vma->vm_start))
161 return addr;
162 }
163
164 /* check if free_area_cache is useful for us */
165 if (len <= mm->cached_hole_size) {
166 mm->cached_hole_size = 0;
167 mm->free_area_cache = mm->mmap_base;
168 }
169
170 /* either no address requested or can't fit in requested address hole */
171 addr = mm->free_area_cache;
172 if (do_colour_align) {
173 unsigned long base = COLOUR_ALIGN_DOWN(addr-len, pgoff);
174
175 addr = base + len;
176 }
177
178 /* make sure it can fit in the remaining address space */
179 if (likely(addr > len)) {
180 vma = find_vma(mm, addr-len);
181 if (!vma || addr <= vma->vm_start) {
182 /* remember the address as a hint for next time */
183 return (mm->free_area_cache = addr-len);
184 }
185 }
186
187 if (unlikely(mm->mmap_base < len))
188 goto bottomup;
189
190 addr = mm->mmap_base-len;
191 if (do_colour_align)
192 addr = COLOUR_ALIGN_DOWN(addr, pgoff);
193
194 do {
195 /*
196 * Lookup failure means no vma is above this address,
197 * else if new region fits below vma->vm_start,
198 * return with success:
199 */
200 vma = find_vma(mm, addr);
201 if (likely(!vma || addr+len <= vma->vm_start)) {
202 /* remember the address as a hint for next time */
203 return (mm->free_area_cache = addr);
204 }
205
206 /* remember the largest hole we saw so far */
207 if (addr + mm->cached_hole_size < vma->vm_start)
208 mm->cached_hole_size = vma->vm_start - addr;
209
210 /* try just below the current vma->vm_start */
211 addr = vma->vm_start-len;
212 if (do_colour_align)
213 addr = COLOUR_ALIGN_DOWN(addr, pgoff);
214 } while (likely(len < vma->vm_start));
215
216bottomup:
217 /*
218 * A failed mmap() very likely causes application failure,
219 * so fall back to the bottom-up function here. This scenario
220 * can happen with large stack limits and large mmap()
221 * allocations.
222 */
223 mm->cached_hole_size = ~0UL;
224 mm->free_area_cache = TASK_UNMAPPED_BASE;
225 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
226 /*
227 * Restore the topdown base:
228 */
229 mm->free_area_cache = mm->mmap_base;
230 mm->cached_hole_size = ~0UL;
231
232 return addr;
233}
106#endif /* CONFIG_MMU */ 234#endif /* CONFIG_MMU */
107 235
108/* 236/*
diff --git a/arch/sh/oprofile/common.c b/arch/sh/oprofile/common.c
index 1b9d4304b3bf..44f4e31c6d63 100644
--- a/arch/sh/oprofile/common.c
+++ b/arch/sh/oprofile/common.c
@@ -109,6 +109,7 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
109 case CPU_SH7785: 109 case CPU_SH7785:
110 case CPU_SH7786: 110 case CPU_SH7786:
111 case CPU_SH7723: 111 case CPU_SH7723:
112 case CPU_SH7724:
112 case CPU_SHX3: 113 case CPU_SHX3:
113 lmodel = &op_model_sh4a_ops; 114 lmodel = &op_model_sh4a_ops;
114 break; 115 break;
diff --git a/arch/sh/tools/mach-types b/arch/sh/tools/mach-types
index 8477b5d884fd..fec3a53b8650 100644
--- a/arch/sh/tools/mach-types
+++ b/arch/sh/tools/mach-types
@@ -23,6 +23,7 @@ HD64461 HD64461
237619SE SH_7619_SOLUTION_ENGINE 237619SE SH_7619_SOLUTION_ENGINE
247721SE SH_7721_SOLUTION_ENGINE 247721SE SH_7721_SOLUTION_ENGINE
257722SE SH_7722_SOLUTION_ENGINE 257722SE SH_7722_SOLUTION_ENGINE
267724SE SH_7724_SOLUTION_ENGINE
267751SE SH_7751_SOLUTION_ENGINE 277751SE SH_7751_SOLUTION_ENGINE
277780SE SH_7780_SOLUTION_ENGINE 287780SE SH_7780_SOLUTION_ENGINE
287751SYSTEMH SH_7751_SYSTEMH 297751SYSTEMH SH_7751_SYSTEMH
diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index f934225fd8ef..aa9e926e13d7 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -451,23 +451,6 @@ static void do_ubd_request(struct request_queue * q);
451 451
452/* Only changed by ubd_init, which is an initcall. */ 452/* Only changed by ubd_init, which is an initcall. */
453static int thread_fd = -1; 453static int thread_fd = -1;
454
455static void ubd_end_request(struct request *req, int bytes, int error)
456{
457 blk_end_request(req, error, bytes);
458}
459
460/* Callable only from interrupt context - otherwise you need to do
461 * spin_lock_irq()/spin_lock_irqsave() */
462static inline void ubd_finish(struct request *req, int bytes)
463{
464 if(bytes < 0){
465 ubd_end_request(req, 0, -EIO);
466 return;
467 }
468 ubd_end_request(req, bytes, 0);
469}
470
471static LIST_HEAD(restart); 454static LIST_HEAD(restart);
472 455
473/* XXX - move this inside ubd_intr. */ 456/* XXX - move this inside ubd_intr. */
@@ -475,7 +458,6 @@ static LIST_HEAD(restart);
475static void ubd_handler(void) 458static void ubd_handler(void)
476{ 459{
477 struct io_thread_req *req; 460 struct io_thread_req *req;
478 struct request *rq;
479 struct ubd *ubd; 461 struct ubd *ubd;
480 struct list_head *list, *next_ele; 462 struct list_head *list, *next_ele;
481 unsigned long flags; 463 unsigned long flags;
@@ -492,10 +474,7 @@ static void ubd_handler(void)
492 return; 474 return;
493 } 475 }
494 476
495 rq = req->req; 477 blk_end_request(req->req, 0, req->length);
496 rq->nr_sectors -= req->length >> 9;
497 if(rq->nr_sectors == 0)
498 ubd_finish(rq, rq->hard_nr_sectors << 9);
499 kfree(req); 478 kfree(req);
500 } 479 }
501 reactivate_fd(thread_fd, UBD_IRQ); 480 reactivate_fd(thread_fd, UBD_IRQ);
@@ -1243,27 +1222,26 @@ static void do_ubd_request(struct request_queue *q)
1243{ 1222{
1244 struct io_thread_req *io_req; 1223 struct io_thread_req *io_req;
1245 struct request *req; 1224 struct request *req;
1246 int n, last_sectors; 1225 sector_t sector;
1226 int n;
1247 1227
1248 while(1){ 1228 while(1){
1249 struct ubd *dev = q->queuedata; 1229 struct ubd *dev = q->queuedata;
1250 if(dev->end_sg == 0){ 1230 if(dev->end_sg == 0){
1251 struct request *req = elv_next_request(q); 1231 struct request *req = blk_fetch_request(q);
1252 if(req == NULL) 1232 if(req == NULL)
1253 return; 1233 return;
1254 1234
1255 dev->request = req; 1235 dev->request = req;
1256 blkdev_dequeue_request(req);
1257 dev->start_sg = 0; 1236 dev->start_sg = 0;
1258 dev->end_sg = blk_rq_map_sg(q, req, dev->sg); 1237 dev->end_sg = blk_rq_map_sg(q, req, dev->sg);
1259 } 1238 }
1260 1239
1261 req = dev->request; 1240 req = dev->request;
1262 last_sectors = 0; 1241 sector = blk_rq_pos(req);
1263 while(dev->start_sg < dev->end_sg){ 1242 while(dev->start_sg < dev->end_sg){
1264 struct scatterlist *sg = &dev->sg[dev->start_sg]; 1243 struct scatterlist *sg = &dev->sg[dev->start_sg];
1265 1244
1266 req->sector += last_sectors;
1267 io_req = kmalloc(sizeof(struct io_thread_req), 1245 io_req = kmalloc(sizeof(struct io_thread_req),
1268 GFP_ATOMIC); 1246 GFP_ATOMIC);
1269 if(io_req == NULL){ 1247 if(io_req == NULL){
@@ -1272,10 +1250,10 @@ static void do_ubd_request(struct request_queue *q)
1272 return; 1250 return;
1273 } 1251 }
1274 prepare_request(req, io_req, 1252 prepare_request(req, io_req,
1275 (unsigned long long) req->sector << 9, 1253 (unsigned long long)sector << 9,
1276 sg->offset, sg->length, sg_page(sg)); 1254 sg->offset, sg->length, sg_page(sg));
1277 1255
1278 last_sectors = sg->length >> 9; 1256 sector += sg->length >> 9;
1279 n = os_write_file(thread_fd, &io_req, 1257 n = os_write_file(thread_fd, &io_req,
1280 sizeof(struct io_thread_req *)); 1258 sizeof(struct io_thread_req *));
1281 if(n != sizeof(struct io_thread_req *)){ 1259 if(n != sizeof(struct io_thread_req *)){
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index 19af42138f78..4a28d22d4793 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -116,6 +116,8 @@
116#define X86_FEATURE_XMM4_1 (4*32+19) /* "sse4_1" SSE-4.1 */ 116#define X86_FEATURE_XMM4_1 (4*32+19) /* "sse4_1" SSE-4.1 */
117#define X86_FEATURE_XMM4_2 (4*32+20) /* "sse4_2" SSE-4.2 */ 117#define X86_FEATURE_XMM4_2 (4*32+20) /* "sse4_2" SSE-4.2 */
118#define X86_FEATURE_X2APIC (4*32+21) /* x2APIC */ 118#define X86_FEATURE_X2APIC (4*32+21) /* x2APIC */
119#define X86_FEATURE_MOVBE (4*32+22) /* MOVBE instruction */
120#define X86_FEATURE_POPCNT (4*32+23) /* POPCNT instruction */
119#define X86_FEATURE_AES (4*32+25) /* AES instructions */ 121#define X86_FEATURE_AES (4*32+25) /* AES instructions */
120#define X86_FEATURE_XSAVE (4*32+26) /* XSAVE/XRSTOR/XSETBV/XGETBV */ 122#define X86_FEATURE_XSAVE (4*32+26) /* XSAVE/XRSTOR/XSETBV/XGETBV */
121#define X86_FEATURE_OSXSAVE (4*32+27) /* "" XSAVE enabled in the OS */ 123#define X86_FEATURE_OSXSAVE (4*32+27) /* "" XSAVE enabled in the OS */
diff --git a/arch/x86/include/asm/kvm.h b/arch/x86/include/asm/kvm.h
index dc3f6cf11704..125be8b19568 100644
--- a/arch/x86/include/asm/kvm.h
+++ b/arch/x86/include/asm/kvm.h
@@ -16,6 +16,7 @@
16#define __KVM_HAVE_MSI 16#define __KVM_HAVE_MSI
17#define __KVM_HAVE_USER_NMI 17#define __KVM_HAVE_USER_NMI
18#define __KVM_HAVE_GUEST_DEBUG 18#define __KVM_HAVE_GUEST_DEBUG
19#define __KVM_HAVE_MSIX
19 20
20/* Architectural interrupt line count. */ 21/* Architectural interrupt line count. */
21#define KVM_NR_INTERRUPTS 256 22#define KVM_NR_INTERRUPTS 256
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index f0faf58044ff..eabdc1cfab5c 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -185,6 +185,7 @@ union kvm_mmu_page_role {
185 unsigned access:3; 185 unsigned access:3;
186 unsigned invalid:1; 186 unsigned invalid:1;
187 unsigned cr4_pge:1; 187 unsigned cr4_pge:1;
188 unsigned nxe:1;
188 }; 189 };
189}; 190};
190 191
@@ -212,7 +213,6 @@ struct kvm_mmu_page {
212 int multimapped; /* More than one parent_pte? */ 213 int multimapped; /* More than one parent_pte? */
213 int root_count; /* Currently serving as active root */ 214 int root_count; /* Currently serving as active root */
214 bool unsync; 215 bool unsync;
215 bool global;
216 unsigned int unsync_children; 216 unsigned int unsync_children;
217 union { 217 union {
218 u64 *parent_pte; /* !multimapped */ 218 u64 *parent_pte; /* !multimapped */
@@ -261,13 +261,11 @@ struct kvm_mmu {
261 union kvm_mmu_page_role base_role; 261 union kvm_mmu_page_role base_role;
262 262
263 u64 *pae_root; 263 u64 *pae_root;
264 u64 rsvd_bits_mask[2][4];
264}; 265};
265 266
266struct kvm_vcpu_arch { 267struct kvm_vcpu_arch {
267 u64 host_tsc; 268 u64 host_tsc;
268 int interrupt_window_open;
269 unsigned long irq_summary; /* bit vector: 1 per word in irq_pending */
270 DECLARE_BITMAP(irq_pending, KVM_NR_INTERRUPTS);
271 /* 269 /*
272 * rip and regs accesses must go through 270 * rip and regs accesses must go through
273 * kvm_{register,rip}_{read,write} functions. 271 * kvm_{register,rip}_{read,write} functions.
@@ -286,6 +284,7 @@ struct kvm_vcpu_arch {
286 u64 shadow_efer; 284 u64 shadow_efer;
287 u64 apic_base; 285 u64 apic_base;
288 struct kvm_lapic *apic; /* kernel irqchip context */ 286 struct kvm_lapic *apic; /* kernel irqchip context */
287 int32_t apic_arb_prio;
289 int mp_state; 288 int mp_state;
290 int sipi_vector; 289 int sipi_vector;
291 u64 ia32_misc_enable_msr; 290 u64 ia32_misc_enable_msr;
@@ -320,6 +319,8 @@ struct kvm_vcpu_arch {
320 struct kvm_pio_request pio; 319 struct kvm_pio_request pio;
321 void *pio_data; 320 void *pio_data;
322 321
322 u8 event_exit_inst_len;
323
323 struct kvm_queued_exception { 324 struct kvm_queued_exception {
324 bool pending; 325 bool pending;
325 bool has_error_code; 326 bool has_error_code;
@@ -329,11 +330,12 @@ struct kvm_vcpu_arch {
329 330
330 struct kvm_queued_interrupt { 331 struct kvm_queued_interrupt {
331 bool pending; 332 bool pending;
333 bool soft;
332 u8 nr; 334 u8 nr;
333 } interrupt; 335 } interrupt;
334 336
335 struct { 337 struct {
336 int active; 338 int vm86_active;
337 u8 save_iopl; 339 u8 save_iopl;
338 struct kvm_save_segment { 340 struct kvm_save_segment {
339 u16 selector; 341 u16 selector;
@@ -356,9 +358,9 @@ struct kvm_vcpu_arch {
356 unsigned int time_offset; 358 unsigned int time_offset;
357 struct page *time_page; 359 struct page *time_page;
358 360
361 bool singlestep; /* guest is single stepped by KVM */
359 bool nmi_pending; 362 bool nmi_pending;
360 bool nmi_injected; 363 bool nmi_injected;
361 bool nmi_window_open;
362 364
363 struct mtrr_state_type mtrr_state; 365 struct mtrr_state_type mtrr_state;
364 u32 pat; 366 u32 pat;
@@ -392,15 +394,14 @@ struct kvm_arch{
392 */ 394 */
393 struct list_head active_mmu_pages; 395 struct list_head active_mmu_pages;
394 struct list_head assigned_dev_head; 396 struct list_head assigned_dev_head;
395 struct list_head oos_global_pages;
396 struct iommu_domain *iommu_domain; 397 struct iommu_domain *iommu_domain;
398 int iommu_flags;
397 struct kvm_pic *vpic; 399 struct kvm_pic *vpic;
398 struct kvm_ioapic *vioapic; 400 struct kvm_ioapic *vioapic;
399 struct kvm_pit *vpit; 401 struct kvm_pit *vpit;
400 struct hlist_head irq_ack_notifier_list; 402 struct hlist_head irq_ack_notifier_list;
401 int vapics_in_nmi_mode; 403 int vapics_in_nmi_mode;
402 404
403 int round_robin_prev_vcpu;
404 unsigned int tss_addr; 405 unsigned int tss_addr;
405 struct page *apic_access_page; 406 struct page *apic_access_page;
406 407
@@ -423,7 +424,6 @@ struct kvm_vm_stat {
423 u32 mmu_recycled; 424 u32 mmu_recycled;
424 u32 mmu_cache_miss; 425 u32 mmu_cache_miss;
425 u32 mmu_unsync; 426 u32 mmu_unsync;
426 u32 mmu_unsync_global;
427 u32 remote_tlb_flush; 427 u32 remote_tlb_flush;
428 u32 lpages; 428 u32 lpages;
429}; 429};
@@ -443,7 +443,6 @@ struct kvm_vcpu_stat {
443 u32 halt_exits; 443 u32 halt_exits;
444 u32 halt_wakeup; 444 u32 halt_wakeup;
445 u32 request_irq_exits; 445 u32 request_irq_exits;
446 u32 request_nmi_exits;
447 u32 irq_exits; 446 u32 irq_exits;
448 u32 host_state_reload; 447 u32 host_state_reload;
449 u32 efer_reload; 448 u32 efer_reload;
@@ -511,20 +510,22 @@ struct kvm_x86_ops {
511 void (*run)(struct kvm_vcpu *vcpu, struct kvm_run *run); 510 void (*run)(struct kvm_vcpu *vcpu, struct kvm_run *run);
512 int (*handle_exit)(struct kvm_run *run, struct kvm_vcpu *vcpu); 511 int (*handle_exit)(struct kvm_run *run, struct kvm_vcpu *vcpu);
513 void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu); 512 void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu);
513 void (*set_interrupt_shadow)(struct kvm_vcpu *vcpu, int mask);
514 u32 (*get_interrupt_shadow)(struct kvm_vcpu *vcpu, int mask);
514 void (*patch_hypercall)(struct kvm_vcpu *vcpu, 515 void (*patch_hypercall)(struct kvm_vcpu *vcpu,
515 unsigned char *hypercall_addr); 516 unsigned char *hypercall_addr);
516 int (*get_irq)(struct kvm_vcpu *vcpu); 517 void (*set_irq)(struct kvm_vcpu *vcpu);
517 void (*set_irq)(struct kvm_vcpu *vcpu, int vec); 518 void (*set_nmi)(struct kvm_vcpu *vcpu);
518 void (*queue_exception)(struct kvm_vcpu *vcpu, unsigned nr, 519 void (*queue_exception)(struct kvm_vcpu *vcpu, unsigned nr,
519 bool has_error_code, u32 error_code); 520 bool has_error_code, u32 error_code);
520 bool (*exception_injected)(struct kvm_vcpu *vcpu); 521 int (*interrupt_allowed)(struct kvm_vcpu *vcpu);
521 void (*inject_pending_irq)(struct kvm_vcpu *vcpu); 522 int (*nmi_allowed)(struct kvm_vcpu *vcpu);
522 void (*inject_pending_vectors)(struct kvm_vcpu *vcpu, 523 void (*enable_nmi_window)(struct kvm_vcpu *vcpu);
523 struct kvm_run *run); 524 void (*enable_irq_window)(struct kvm_vcpu *vcpu);
524 525 void (*update_cr8_intercept)(struct kvm_vcpu *vcpu, int tpr, int irr);
525 int (*set_tss_addr)(struct kvm *kvm, unsigned int addr); 526 int (*set_tss_addr)(struct kvm *kvm, unsigned int addr);
526 int (*get_tdp_level)(void); 527 int (*get_tdp_level)(void);
527 int (*get_mt_mask_shift)(void); 528 u64 (*get_mt_mask)(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio);
528}; 529};
529 530
530extern struct kvm_x86_ops *kvm_x86_ops; 531extern struct kvm_x86_ops *kvm_x86_ops;
@@ -538,7 +539,7 @@ int kvm_mmu_setup(struct kvm_vcpu *vcpu);
538void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte); 539void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte);
539void kvm_mmu_set_base_ptes(u64 base_pte); 540void kvm_mmu_set_base_ptes(u64 base_pte);
540void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask, 541void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask,
541 u64 dirty_mask, u64 nx_mask, u64 x_mask, u64 mt_mask); 542 u64 dirty_mask, u64 nx_mask, u64 x_mask);
542 543
543int kvm_mmu_reset_context(struct kvm_vcpu *vcpu); 544int kvm_mmu_reset_context(struct kvm_vcpu *vcpu);
544void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot); 545void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot);
@@ -552,6 +553,7 @@ int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
552 const void *val, int bytes); 553 const void *val, int bytes);
553int kvm_pv_mmu_op(struct kvm_vcpu *vcpu, unsigned long bytes, 554int kvm_pv_mmu_op(struct kvm_vcpu *vcpu, unsigned long bytes,
554 gpa_t addr, unsigned long *ret); 555 gpa_t addr, unsigned long *ret);
556u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn);
555 557
556extern bool tdp_enabled; 558extern bool tdp_enabled;
557 559
@@ -563,6 +565,7 @@ enum emulation_result {
563 565
564#define EMULTYPE_NO_DECODE (1 << 0) 566#define EMULTYPE_NO_DECODE (1 << 0)
565#define EMULTYPE_TRAP_UD (1 << 1) 567#define EMULTYPE_TRAP_UD (1 << 1)
568#define EMULTYPE_SKIP (1 << 2)
566int emulate_instruction(struct kvm_vcpu *vcpu, struct kvm_run *run, 569int emulate_instruction(struct kvm_vcpu *vcpu, struct kvm_run *run,
567 unsigned long cr2, u16 error_code, int emulation_type); 570 unsigned long cr2, u16 error_code, int emulation_type);
568void kvm_report_emulation_failure(struct kvm_vcpu *cvpu, const char *context); 571void kvm_report_emulation_failure(struct kvm_vcpu *cvpu, const char *context);
@@ -638,7 +641,6 @@ void __kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
638int kvm_mmu_load(struct kvm_vcpu *vcpu); 641int kvm_mmu_load(struct kvm_vcpu *vcpu);
639void kvm_mmu_unload(struct kvm_vcpu *vcpu); 642void kvm_mmu_unload(struct kvm_vcpu *vcpu);
640void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu); 643void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu);
641void kvm_mmu_sync_global(struct kvm_vcpu *vcpu);
642 644
643int kvm_emulate_hypercall(struct kvm_vcpu *vcpu); 645int kvm_emulate_hypercall(struct kvm_vcpu *vcpu);
644 646
@@ -769,6 +771,8 @@ enum {
769#define HF_GIF_MASK (1 << 0) 771#define HF_GIF_MASK (1 << 0)
770#define HF_HIF_MASK (1 << 1) 772#define HF_HIF_MASK (1 << 1)
771#define HF_VINTR_MASK (1 << 2) 773#define HF_VINTR_MASK (1 << 2)
774#define HF_NMI_MASK (1 << 3)
775#define HF_IRET_MASK (1 << 4)
772 776
773/* 777/*
774 * Hardware virtualization extension instructions may fault if a 778 * Hardware virtualization extension instructions may fault if a
@@ -791,5 +795,6 @@ asmlinkage void kvm_handle_fault_on_reboot(void);
791#define KVM_ARCH_WANT_MMU_NOTIFIER 795#define KVM_ARCH_WANT_MMU_NOTIFIER
792int kvm_unmap_hva(struct kvm *kvm, unsigned long hva); 796int kvm_unmap_hva(struct kvm *kvm, unsigned long hva);
793int kvm_age_hva(struct kvm *kvm, unsigned long hva); 797int kvm_age_hva(struct kvm *kvm, unsigned long hva);
798int cpuid_maxphyaddr(struct kvm_vcpu *vcpu);
794 799
795#endif /* _ASM_X86_KVM_HOST_H */ 800#endif /* _ASM_X86_KVM_HOST_H */
diff --git a/arch/x86/include/asm/kvm_x86_emulate.h b/arch/x86/include/asm/kvm_x86_emulate.h
index 6a159732881a..b7ed2c423116 100644
--- a/arch/x86/include/asm/kvm_x86_emulate.h
+++ b/arch/x86/include/asm/kvm_x86_emulate.h
@@ -143,6 +143,9 @@ struct decode_cache {
143 struct fetch_cache fetch; 143 struct fetch_cache fetch;
144}; 144};
145 145
146#define X86_SHADOW_INT_MOV_SS 1
147#define X86_SHADOW_INT_STI 2
148
146struct x86_emulate_ctxt { 149struct x86_emulate_ctxt {
147 /* Register state before/after emulation. */ 150 /* Register state before/after emulation. */
148 struct kvm_vcpu *vcpu; 151 struct kvm_vcpu *vcpu;
@@ -152,6 +155,9 @@ struct x86_emulate_ctxt {
152 int mode; 155 int mode;
153 u32 cs_base; 156 u32 cs_base;
154 157
158 /* interruptibility state, as a result of execution of STI or MOV SS */
159 int interruptibility;
160
155 /* decode cache */ 161 /* decode cache */
156 struct decode_cache decode; 162 struct decode_cache decode;
157}; 163};
diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h
index 638bf6241807..22603764e7db 100644
--- a/arch/x86/include/asm/msr.h
+++ b/arch/x86/include/asm/msr.h
@@ -12,6 +12,17 @@
12 12
13#include <asm/asm.h> 13#include <asm/asm.h>
14#include <asm/errno.h> 14#include <asm/errno.h>
15#include <asm/cpumask.h>
16
17struct msr {
18 union {
19 struct {
20 u32 l;
21 u32 h;
22 };
23 u64 q;
24 };
25};
15 26
16static inline unsigned long long native_read_tscp(unsigned int *aux) 27static inline unsigned long long native_read_tscp(unsigned int *aux)
17{ 28{
@@ -216,6 +227,8 @@ do { \
216#ifdef CONFIG_SMP 227#ifdef CONFIG_SMP
217int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h); 228int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
218int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h); 229int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
230void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs);
231void wrmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs);
219int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h); 232int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h);
220int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h); 233int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h);
221#else /* CONFIG_SMP */ 234#else /* CONFIG_SMP */
@@ -229,6 +242,16 @@ static inline int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
229 wrmsr(msr_no, l, h); 242 wrmsr(msr_no, l, h);
230 return 0; 243 return 0;
231} 244}
245static inline void rdmsr_on_cpus(const cpumask_t *m, u32 msr_no,
246 struct msr *msrs)
247{
248 rdmsr_on_cpu(0, msr_no, &(msrs[0].l), &(msrs[0].h));
249}
250static inline void wrmsr_on_cpus(const cpumask_t *m, u32 msr_no,
251 struct msr *msrs)
252{
253 wrmsr_on_cpu(0, msr_no, msrs[0].l, msrs[0].h);
254}
232static inline int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, 255static inline int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no,
233 u32 *l, u32 *h) 256 u32 *l, u32 *h)
234{ 257{
diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
index 82ada75f3ebf..85574b7c1bc1 100644
--- a/arch/x86/include/asm/svm.h
+++ b/arch/x86/include/asm/svm.h
@@ -225,6 +225,7 @@ struct __attribute__ ((__packed__)) vmcb {
225#define SVM_EVTINJ_VALID_ERR (1 << 11) 225#define SVM_EVTINJ_VALID_ERR (1 << 11)
226 226
227#define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK 227#define SVM_EXITINTINFO_VEC_MASK SVM_EVTINJ_VEC_MASK
228#define SVM_EXITINTINFO_TYPE_MASK SVM_EVTINJ_TYPE_MASK
228 229
229#define SVM_EXITINTINFO_TYPE_INTR SVM_EVTINJ_TYPE_INTR 230#define SVM_EXITINTINFO_TYPE_INTR SVM_EVTINJ_TYPE_INTR
230#define SVM_EXITINTINFO_TYPE_NMI SVM_EVTINJ_TYPE_NMI 231#define SVM_EXITINTINFO_TYPE_NMI SVM_EVTINJ_TYPE_NMI
diff --git a/arch/x86/include/asm/termios.h b/arch/x86/include/asm/termios.h
index f72956331c49..c4ee8056baca 100644
--- a/arch/x86/include/asm/termios.h
+++ b/arch/x86/include/asm/termios.h
@@ -67,6 +67,7 @@ static inline int user_termio_to_kernel_termios(struct ktermios *termios,
67 SET_LOW_TERMIOS_BITS(termios, termio, c_oflag); 67 SET_LOW_TERMIOS_BITS(termios, termio, c_oflag);
68 SET_LOW_TERMIOS_BITS(termios, termio, c_cflag); 68 SET_LOW_TERMIOS_BITS(termios, termio, c_cflag);
69 SET_LOW_TERMIOS_BITS(termios, termio, c_lflag); 69 SET_LOW_TERMIOS_BITS(termios, termio, c_lflag);
70 get_user(termios->c_line, &termio->c_line);
70 return copy_from_user(termios->c_cc, termio->c_cc, NCC); 71 return copy_from_user(termios->c_cc, termio->c_cc, NCC);
71} 72}
72 73
diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h
index 498f944010b9..11be5ad2e0e9 100644
--- a/arch/x86/include/asm/vmx.h
+++ b/arch/x86/include/asm/vmx.h
@@ -247,6 +247,7 @@ enum vmcs_field {
247#define EXIT_REASON_MSR_READ 31 247#define EXIT_REASON_MSR_READ 31
248#define EXIT_REASON_MSR_WRITE 32 248#define EXIT_REASON_MSR_WRITE 32
249#define EXIT_REASON_MWAIT_INSTRUCTION 36 249#define EXIT_REASON_MWAIT_INSTRUCTION 36
250#define EXIT_REASON_MCE_DURING_VMENTRY 41
250#define EXIT_REASON_TPR_BELOW_THRESHOLD 43 251#define EXIT_REASON_TPR_BELOW_THRESHOLD 43
251#define EXIT_REASON_APIC_ACCESS 44 252#define EXIT_REASON_APIC_ACCESS 44
252#define EXIT_REASON_EPT_VIOLATION 48 253#define EXIT_REASON_EPT_VIOLATION 48
diff --git a/arch/x86/kernel/cpu/mcheck/mce_64.c b/arch/x86/kernel/cpu/mcheck/mce_64.c
index 09dd1d414fc3..289cc4815028 100644
--- a/arch/x86/kernel/cpu/mcheck/mce_64.c
+++ b/arch/x86/kernel/cpu/mcheck/mce_64.c
@@ -420,6 +420,7 @@ void do_machine_check(struct pt_regs * regs, long error_code)
420 out2: 420 out2:
421 atomic_dec(&mce_entry); 421 atomic_dec(&mce_entry);
422} 422}
423EXPORT_SYMBOL_GPL(do_machine_check);
423 424
424#ifdef CONFIG_X86_MCE_INTEL 425#ifdef CONFIG_X86_MCE_INTEL
425/*** 426/***
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index 6551dedee20c..a78ecad0c900 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -27,6 +27,7 @@
27#include <linux/mm.h> 27#include <linux/mm.h>
28#include <linux/highmem.h> 28#include <linux/highmem.h>
29#include <linux/hardirq.h> 29#include <linux/hardirq.h>
30#include <asm/timer.h>
30 31
31#define MMU_QUEUE_SIZE 1024 32#define MMU_QUEUE_SIZE 1024
32 33
@@ -230,6 +231,9 @@ static void paravirt_ops_setup(void)
230 pv_mmu_ops.lazy_mode.enter = kvm_enter_lazy_mmu; 231 pv_mmu_ops.lazy_mode.enter = kvm_enter_lazy_mmu;
231 pv_mmu_ops.lazy_mode.leave = kvm_leave_lazy_mmu; 232 pv_mmu_ops.lazy_mode.leave = kvm_leave_lazy_mmu;
232 } 233 }
234#ifdef CONFIG_X86_IO_APIC
235 no_timer_check = 1;
236#endif
233} 237}
234 238
235void __init kvm_guest_init(void) 239void __init kvm_guest_init(void)
diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
index f6db48c405b8..28f5fb495a66 100644
--- a/arch/x86/kernel/smp.c
+++ b/arch/x86/kernel/smp.c
@@ -172,6 +172,9 @@ void smp_reschedule_interrupt(struct pt_regs *regs)
172{ 172{
173 ack_APIC_irq(); 173 ack_APIC_irq();
174 inc_irq_stat(irq_resched_count); 174 inc_irq_stat(irq_resched_count);
175 /*
176 * KVM uses this interrupt to force a cpu out of guest mode
177 */
175} 178}
176 179
177void smp_call_function_interrupt(struct pt_regs *regs) 180void smp_call_function_interrupt(struct pt_regs *regs)
diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig
index a58504ea78cc..8600a09e0c6c 100644
--- a/arch/x86/kvm/Kconfig
+++ b/arch/x86/kvm/Kconfig
@@ -50,6 +50,9 @@ config KVM_INTEL
50 Provides support for KVM on Intel processors equipped with the VT 50 Provides support for KVM on Intel processors equipped with the VT
51 extensions. 51 extensions.
52 52
53 To compile this as a module, choose M here: the module
54 will be called kvm-intel.
55
53config KVM_AMD 56config KVM_AMD
54 tristate "KVM for AMD processors support" 57 tristate "KVM for AMD processors support"
55 depends on KVM 58 depends on KVM
@@ -57,6 +60,9 @@ config KVM_AMD
57 Provides support for KVM on AMD processors equipped with the AMD-V 60 Provides support for KVM on AMD processors equipped with the AMD-V
58 (SVM) extensions. 61 (SVM) extensions.
59 62
63 To compile this as a module, choose M here: the module
64 will be called kvm-amd.
65
60config KVM_TRACE 66config KVM_TRACE
61 bool "KVM trace support" 67 bool "KVM trace support"
62 depends on KVM && SYSFS 68 depends on KVM && SYSFS
diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
index d3ec292f00f2..b43c4efafe80 100644
--- a/arch/x86/kvm/Makefile
+++ b/arch/x86/kvm/Makefile
@@ -14,7 +14,7 @@ endif
14EXTRA_CFLAGS += -Ivirt/kvm -Iarch/x86/kvm 14EXTRA_CFLAGS += -Ivirt/kvm -Iarch/x86/kvm
15 15
16kvm-objs := $(common-objs) x86.o mmu.o x86_emulate.o i8259.o irq.o lapic.o \ 16kvm-objs := $(common-objs) x86.o mmu.o x86_emulate.o i8259.o irq.o lapic.o \
17 i8254.o 17 i8254.o timer.o
18obj-$(CONFIG_KVM) += kvm.o 18obj-$(CONFIG_KVM) += kvm.o
19kvm-intel-objs = vmx.o 19kvm-intel-objs = vmx.o
20obj-$(CONFIG_KVM_INTEL) += kvm-intel.o 20obj-$(CONFIG_KVM_INTEL) += kvm-intel.o
diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c
index c13bb92d3157..4d6f0d293ee2 100644
--- a/arch/x86/kvm/i8254.c
+++ b/arch/x86/kvm/i8254.c
@@ -98,6 +98,37 @@ static int pit_get_gate(struct kvm *kvm, int channel)
98 return kvm->arch.vpit->pit_state.channels[channel].gate; 98 return kvm->arch.vpit->pit_state.channels[channel].gate;
99} 99}
100 100
101static s64 __kpit_elapsed(struct kvm *kvm)
102{
103 s64 elapsed;
104 ktime_t remaining;
105 struct kvm_kpit_state *ps = &kvm->arch.vpit->pit_state;
106
107 /*
108 * The Counter does not stop when it reaches zero. In
109 * Modes 0, 1, 4, and 5 the Counter ``wraps around'' to
110 * the highest count, either FFFF hex for binary counting
111 * or 9999 for BCD counting, and continues counting.
112 * Modes 2 and 3 are periodic; the Counter reloads
113 * itself with the initial count and continues counting
114 * from there.
115 */
116 remaining = hrtimer_expires_remaining(&ps->pit_timer.timer);
117 elapsed = ps->pit_timer.period - ktime_to_ns(remaining);
118 elapsed = mod_64(elapsed, ps->pit_timer.period);
119
120 return elapsed;
121}
122
123static s64 kpit_elapsed(struct kvm *kvm, struct kvm_kpit_channel_state *c,
124 int channel)
125{
126 if (channel == 0)
127 return __kpit_elapsed(kvm);
128
129 return ktime_to_ns(ktime_sub(ktime_get(), c->count_load_time));
130}
131
101static int pit_get_count(struct kvm *kvm, int channel) 132static int pit_get_count(struct kvm *kvm, int channel)
102{ 133{
103 struct kvm_kpit_channel_state *c = 134 struct kvm_kpit_channel_state *c =
@@ -107,7 +138,7 @@ static int pit_get_count(struct kvm *kvm, int channel)
107 138
108 WARN_ON(!mutex_is_locked(&kvm->arch.vpit->pit_state.lock)); 139 WARN_ON(!mutex_is_locked(&kvm->arch.vpit->pit_state.lock));
109 140
110 t = ktime_to_ns(ktime_sub(ktime_get(), c->count_load_time)); 141 t = kpit_elapsed(kvm, c, channel);
111 d = muldiv64(t, KVM_PIT_FREQ, NSEC_PER_SEC); 142 d = muldiv64(t, KVM_PIT_FREQ, NSEC_PER_SEC);
112 143
113 switch (c->mode) { 144 switch (c->mode) {
@@ -137,7 +168,7 @@ static int pit_get_out(struct kvm *kvm, int channel)
137 168
138 WARN_ON(!mutex_is_locked(&kvm->arch.vpit->pit_state.lock)); 169 WARN_ON(!mutex_is_locked(&kvm->arch.vpit->pit_state.lock));
139 170
140 t = ktime_to_ns(ktime_sub(ktime_get(), c->count_load_time)); 171 t = kpit_elapsed(kvm, c, channel);
141 d = muldiv64(t, KVM_PIT_FREQ, NSEC_PER_SEC); 172 d = muldiv64(t, KVM_PIT_FREQ, NSEC_PER_SEC);
142 173
143 switch (c->mode) { 174 switch (c->mode) {
@@ -193,28 +224,6 @@ static void pit_latch_status(struct kvm *kvm, int channel)
193 } 224 }
194} 225}
195 226
196static int __pit_timer_fn(struct kvm_kpit_state *ps)
197{
198 struct kvm_vcpu *vcpu0 = ps->pit->kvm->vcpus[0];
199 struct kvm_kpit_timer *pt = &ps->pit_timer;
200
201 if (!atomic_inc_and_test(&pt->pending))
202 set_bit(KVM_REQ_PENDING_TIMER, &vcpu0->requests);
203
204 if (!pt->reinject)
205 atomic_set(&pt->pending, 1);
206
207 if (vcpu0 && waitqueue_active(&vcpu0->wq))
208 wake_up_interruptible(&vcpu0->wq);
209
210 hrtimer_add_expires_ns(&pt->timer, pt->period);
211 pt->scheduled = hrtimer_get_expires_ns(&pt->timer);
212 if (pt->period)
213 ps->channels[0].count_load_time = ktime_get();
214
215 return (pt->period == 0 ? 0 : 1);
216}
217
218int pit_has_pending_timer(struct kvm_vcpu *vcpu) 227int pit_has_pending_timer(struct kvm_vcpu *vcpu)
219{ 228{
220 struct kvm_pit *pit = vcpu->kvm->arch.vpit; 229 struct kvm_pit *pit = vcpu->kvm->arch.vpit;
@@ -235,21 +244,6 @@ static void kvm_pit_ack_irq(struct kvm_irq_ack_notifier *kian)
235 spin_unlock(&ps->inject_lock); 244 spin_unlock(&ps->inject_lock);
236} 245}
237 246
238static enum hrtimer_restart pit_timer_fn(struct hrtimer *data)
239{
240 struct kvm_kpit_state *ps;
241 int restart_timer = 0;
242
243 ps = container_of(data, struct kvm_kpit_state, pit_timer.timer);
244
245 restart_timer = __pit_timer_fn(ps);
246
247 if (restart_timer)
248 return HRTIMER_RESTART;
249 else
250 return HRTIMER_NORESTART;
251}
252
253void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu) 247void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu)
254{ 248{
255 struct kvm_pit *pit = vcpu->kvm->arch.vpit; 249 struct kvm_pit *pit = vcpu->kvm->arch.vpit;
@@ -263,15 +257,26 @@ void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu)
263 hrtimer_start_expires(timer, HRTIMER_MODE_ABS); 257 hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
264} 258}
265 259
266static void destroy_pit_timer(struct kvm_kpit_timer *pt) 260static void destroy_pit_timer(struct kvm_timer *pt)
267{ 261{
268 pr_debug("pit: execute del timer!\n"); 262 pr_debug("pit: execute del timer!\n");
269 hrtimer_cancel(&pt->timer); 263 hrtimer_cancel(&pt->timer);
270} 264}
271 265
266static bool kpit_is_periodic(struct kvm_timer *ktimer)
267{
268 struct kvm_kpit_state *ps = container_of(ktimer, struct kvm_kpit_state,
269 pit_timer);
270 return ps->is_periodic;
271}
272
273static struct kvm_timer_ops kpit_ops = {
274 .is_periodic = kpit_is_periodic,
275};
276
272static void create_pit_timer(struct kvm_kpit_state *ps, u32 val, int is_period) 277static void create_pit_timer(struct kvm_kpit_state *ps, u32 val, int is_period)
273{ 278{
274 struct kvm_kpit_timer *pt = &ps->pit_timer; 279 struct kvm_timer *pt = &ps->pit_timer;
275 s64 interval; 280 s64 interval;
276 281
277 interval = muldiv64(val, NSEC_PER_SEC, KVM_PIT_FREQ); 282 interval = muldiv64(val, NSEC_PER_SEC, KVM_PIT_FREQ);
@@ -280,8 +285,14 @@ static void create_pit_timer(struct kvm_kpit_state *ps, u32 val, int is_period)
280 285
281 /* TODO The new value only affected after the retriggered */ 286 /* TODO The new value only affected after the retriggered */
282 hrtimer_cancel(&pt->timer); 287 hrtimer_cancel(&pt->timer);
283 pt->period = (is_period == 0) ? 0 : interval; 288 pt->period = interval;
284 pt->timer.function = pit_timer_fn; 289 ps->is_periodic = is_period;
290
291 pt->timer.function = kvm_timer_fn;
292 pt->t_ops = &kpit_ops;
293 pt->kvm = ps->pit->kvm;
294 pt->vcpu_id = 0;
295
285 atomic_set(&pt->pending, 0); 296 atomic_set(&pt->pending, 0);
286 ps->irq_ack = 1; 297 ps->irq_ack = 1;
287 298
@@ -298,23 +309,23 @@ static void pit_load_count(struct kvm *kvm, int channel, u32 val)
298 pr_debug("pit: load_count val is %d, channel is %d\n", val, channel); 309 pr_debug("pit: load_count val is %d, channel is %d\n", val, channel);
299 310
300 /* 311 /*
301 * Though spec said the state of 8254 is undefined after power-up, 312 * The largest possible initial count is 0; this is equivalent
302 * seems some tricky OS like Windows XP depends on IRQ0 interrupt 313 * to 216 for binary counting and 104 for BCD counting.
303 * when booting up.
304 * So here setting initialize rate for it, and not a specific number
305 */ 314 */
306 if (val == 0) 315 if (val == 0)
307 val = 0x10000; 316 val = 0x10000;
308 317
309 ps->channels[channel].count_load_time = ktime_get();
310 ps->channels[channel].count = val; 318 ps->channels[channel].count = val;
311 319
312 if (channel != 0) 320 if (channel != 0) {
321 ps->channels[channel].count_load_time = ktime_get();
313 return; 322 return;
323 }
314 324
315 /* Two types of timer 325 /* Two types of timer
316 * mode 1 is one shot, mode 2 is period, otherwise del timer */ 326 * mode 1 is one shot, mode 2 is period, otherwise del timer */
317 switch (ps->channels[0].mode) { 327 switch (ps->channels[0].mode) {
328 case 0:
318 case 1: 329 case 1:
319 /* FIXME: enhance mode 4 precision */ 330 /* FIXME: enhance mode 4 precision */
320 case 4: 331 case 4:
diff --git a/arch/x86/kvm/i8254.h b/arch/x86/kvm/i8254.h
index 6acbe4b505d5..bbd863ff60b7 100644
--- a/arch/x86/kvm/i8254.h
+++ b/arch/x86/kvm/i8254.h
@@ -3,15 +3,6 @@
3 3
4#include "iodev.h" 4#include "iodev.h"
5 5
6struct kvm_kpit_timer {
7 struct hrtimer timer;
8 int irq;
9 s64 period; /* unit: ns */
10 s64 scheduled;
11 atomic_t pending;
12 bool reinject;
13};
14
15struct kvm_kpit_channel_state { 6struct kvm_kpit_channel_state {
16 u32 count; /* can be 65536 */ 7 u32 count; /* can be 65536 */
17 u16 latched_count; 8 u16 latched_count;
@@ -30,7 +21,8 @@ struct kvm_kpit_channel_state {
30 21
31struct kvm_kpit_state { 22struct kvm_kpit_state {
32 struct kvm_kpit_channel_state channels[3]; 23 struct kvm_kpit_channel_state channels[3];
33 struct kvm_kpit_timer pit_timer; 24 struct kvm_timer pit_timer;
25 bool is_periodic;
34 u32 speaker_data_on; 26 u32 speaker_data_on;
35 struct mutex lock; 27 struct mutex lock;
36 struct kvm_pit *pit; 28 struct kvm_pit *pit;
diff --git a/arch/x86/kvm/irq.c b/arch/x86/kvm/irq.c
index cf17ed52f6fb..96dfbb6ad2a9 100644
--- a/arch/x86/kvm/irq.c
+++ b/arch/x86/kvm/irq.c
@@ -24,6 +24,7 @@
24 24
25#include "irq.h" 25#include "irq.h"
26#include "i8254.h" 26#include "i8254.h"
27#include "x86.h"
27 28
28/* 29/*
29 * check if there are pending timer events 30 * check if there are pending timer events
@@ -48,6 +49,9 @@ int kvm_cpu_has_interrupt(struct kvm_vcpu *v)
48{ 49{
49 struct kvm_pic *s; 50 struct kvm_pic *s;
50 51
52 if (!irqchip_in_kernel(v->kvm))
53 return v->arch.interrupt.pending;
54
51 if (kvm_apic_has_interrupt(v) == -1) { /* LAPIC */ 55 if (kvm_apic_has_interrupt(v) == -1) { /* LAPIC */
52 if (kvm_apic_accept_pic_intr(v)) { 56 if (kvm_apic_accept_pic_intr(v)) {
53 s = pic_irqchip(v->kvm); /* PIC */ 57 s = pic_irqchip(v->kvm); /* PIC */
@@ -67,6 +71,9 @@ int kvm_cpu_get_interrupt(struct kvm_vcpu *v)
67 struct kvm_pic *s; 71 struct kvm_pic *s;
68 int vector; 72 int vector;
69 73
74 if (!irqchip_in_kernel(v->kvm))
75 return v->arch.interrupt.nr;
76
70 vector = kvm_get_apic_interrupt(v); /* APIC */ 77 vector = kvm_get_apic_interrupt(v); /* APIC */
71 if (vector == -1) { 78 if (vector == -1) {
72 if (kvm_apic_accept_pic_intr(v)) { 79 if (kvm_apic_accept_pic_intr(v)) {
diff --git a/arch/x86/kvm/kvm_timer.h b/arch/x86/kvm/kvm_timer.h
new file mode 100644
index 000000000000..26bd6ba74e1c
--- /dev/null
+++ b/arch/x86/kvm/kvm_timer.h
@@ -0,0 +1,18 @@
1
2struct kvm_timer {
3 struct hrtimer timer;
4 s64 period; /* unit: ns */
5 atomic_t pending; /* accumulated triggered timers */
6 bool reinject;
7 struct kvm_timer_ops *t_ops;
8 struct kvm *kvm;
9 int vcpu_id;
10};
11
12struct kvm_timer_ops {
13 bool (*is_periodic)(struct kvm_timer *);
14};
15
16
17enum hrtimer_restart kvm_timer_fn(struct hrtimer *data);
18
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index f0b67f2cdd69..ae99d83f81a3 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -196,20 +196,15 @@ int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu)
196} 196}
197EXPORT_SYMBOL_GPL(kvm_lapic_find_highest_irr); 197EXPORT_SYMBOL_GPL(kvm_lapic_find_highest_irr);
198 198
199int kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 trig) 199static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
200 int vector, int level, int trig_mode);
201
202int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq)
200{ 203{
201 struct kvm_lapic *apic = vcpu->arch.apic; 204 struct kvm_lapic *apic = vcpu->arch.apic;
202 205
203 if (!apic_test_and_set_irr(vec, apic)) { 206 return __apic_accept_irq(apic, irq->delivery_mode, irq->vector,
204 /* a new pending irq is set in IRR */ 207 irq->level, irq->trig_mode);
205 if (trig)
206 apic_set_vector(vec, apic->regs + APIC_TMR);
207 else
208 apic_clear_vector(vec, apic->regs + APIC_TMR);
209 kvm_vcpu_kick(apic->vcpu);
210 return 1;
211 }
212 return 0;
213} 208}
214 209
215static inline int apic_find_highest_isr(struct kvm_lapic *apic) 210static inline int apic_find_highest_isr(struct kvm_lapic *apic)
@@ -250,7 +245,7 @@ static void apic_set_tpr(struct kvm_lapic *apic, u32 tpr)
250 245
251int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest) 246int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest)
252{ 247{
253 return kvm_apic_id(apic) == dest; 248 return dest == 0xff || kvm_apic_id(apic) == dest;
254} 249}
255 250
256int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda) 251int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda)
@@ -279,37 +274,34 @@ int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda)
279 return result; 274 return result;
280} 275}
281 276
282static int apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source, 277int kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source,
283 int short_hand, int dest, int dest_mode) 278 int short_hand, int dest, int dest_mode)
284{ 279{
285 int result = 0; 280 int result = 0;
286 struct kvm_lapic *target = vcpu->arch.apic; 281 struct kvm_lapic *target = vcpu->arch.apic;
287 282
288 apic_debug("target %p, source %p, dest 0x%x, " 283 apic_debug("target %p, source %p, dest 0x%x, "
289 "dest_mode 0x%x, short_hand 0x%x", 284 "dest_mode 0x%x, short_hand 0x%x\n",
290 target, source, dest, dest_mode, short_hand); 285 target, source, dest, dest_mode, short_hand);
291 286
292 ASSERT(!target); 287 ASSERT(!target);
293 switch (short_hand) { 288 switch (short_hand) {
294 case APIC_DEST_NOSHORT: 289 case APIC_DEST_NOSHORT:
295 if (dest_mode == 0) { 290 if (dest_mode == 0)
296 /* Physical mode. */ 291 /* Physical mode. */
297 if ((dest == 0xFF) || (dest == kvm_apic_id(target))) 292 result = kvm_apic_match_physical_addr(target, dest);
298 result = 1; 293 else
299 } else
300 /* Logical mode. */ 294 /* Logical mode. */
301 result = kvm_apic_match_logical_addr(target, dest); 295 result = kvm_apic_match_logical_addr(target, dest);
302 break; 296 break;
303 case APIC_DEST_SELF: 297 case APIC_DEST_SELF:
304 if (target == source) 298 result = (target == source);
305 result = 1;
306 break; 299 break;
307 case APIC_DEST_ALLINC: 300 case APIC_DEST_ALLINC:
308 result = 1; 301 result = 1;
309 break; 302 break;
310 case APIC_DEST_ALLBUT: 303 case APIC_DEST_ALLBUT:
311 if (target != source) 304 result = (target != source);
312 result = 1;
313 break; 305 break;
314 default: 306 default:
315 printk(KERN_WARNING "Bad dest shorthand value %x\n", 307 printk(KERN_WARNING "Bad dest shorthand value %x\n",
@@ -327,20 +319,22 @@ static int apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source,
327static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, 319static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
328 int vector, int level, int trig_mode) 320 int vector, int level, int trig_mode)
329{ 321{
330 int orig_irr, result = 0; 322 int result = 0;
331 struct kvm_vcpu *vcpu = apic->vcpu; 323 struct kvm_vcpu *vcpu = apic->vcpu;
332 324
333 switch (delivery_mode) { 325 switch (delivery_mode) {
334 case APIC_DM_FIXED:
335 case APIC_DM_LOWEST: 326 case APIC_DM_LOWEST:
327 vcpu->arch.apic_arb_prio++;
328 case APIC_DM_FIXED:
336 /* FIXME add logic for vcpu on reset */ 329 /* FIXME add logic for vcpu on reset */
337 if (unlikely(!apic_enabled(apic))) 330 if (unlikely(!apic_enabled(apic)))
338 break; 331 break;
339 332
340 orig_irr = apic_test_and_set_irr(vector, apic); 333 result = !apic_test_and_set_irr(vector, apic);
341 if (orig_irr && trig_mode) { 334 if (!result) {
342 apic_debug("level trig mode repeatedly for vector %d", 335 if (trig_mode)
343 vector); 336 apic_debug("level trig mode repeatedly for "
337 "vector %d", vector);
344 break; 338 break;
345 } 339 }
346 340
@@ -349,10 +343,7 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
349 apic_set_vector(vector, apic->regs + APIC_TMR); 343 apic_set_vector(vector, apic->regs + APIC_TMR);
350 } else 344 } else
351 apic_clear_vector(vector, apic->regs + APIC_TMR); 345 apic_clear_vector(vector, apic->regs + APIC_TMR);
352
353 kvm_vcpu_kick(vcpu); 346 kvm_vcpu_kick(vcpu);
354
355 result = (orig_irr == 0);
356 break; 347 break;
357 348
358 case APIC_DM_REMRD: 349 case APIC_DM_REMRD:
@@ -364,12 +355,14 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
364 break; 355 break;
365 356
366 case APIC_DM_NMI: 357 case APIC_DM_NMI:
358 result = 1;
367 kvm_inject_nmi(vcpu); 359 kvm_inject_nmi(vcpu);
368 kvm_vcpu_kick(vcpu); 360 kvm_vcpu_kick(vcpu);
369 break; 361 break;
370 362
371 case APIC_DM_INIT: 363 case APIC_DM_INIT:
372 if (level) { 364 if (level) {
365 result = 1;
373 if (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE) 366 if (vcpu->arch.mp_state == KVM_MP_STATE_RUNNABLE)
374 printk(KERN_DEBUG 367 printk(KERN_DEBUG
375 "INIT on a runnable vcpu %d\n", 368 "INIT on a runnable vcpu %d\n",
@@ -386,6 +379,7 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
386 apic_debug("SIPI to vcpu %d vector 0x%02x\n", 379 apic_debug("SIPI to vcpu %d vector 0x%02x\n",
387 vcpu->vcpu_id, vector); 380 vcpu->vcpu_id, vector);
388 if (vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED) { 381 if (vcpu->arch.mp_state == KVM_MP_STATE_INIT_RECEIVED) {
382 result = 1;
389 vcpu->arch.sipi_vector = vector; 383 vcpu->arch.sipi_vector = vector;
390 vcpu->arch.mp_state = KVM_MP_STATE_SIPI_RECEIVED; 384 vcpu->arch.mp_state = KVM_MP_STATE_SIPI_RECEIVED;
391 kvm_vcpu_kick(vcpu); 385 kvm_vcpu_kick(vcpu);
@@ -408,43 +402,9 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
408 return result; 402 return result;
409} 403}
410 404
411static struct kvm_lapic *kvm_apic_round_robin(struct kvm *kvm, u8 vector, 405int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2)
412 unsigned long bitmap)
413{
414 int last;
415 int next;
416 struct kvm_lapic *apic = NULL;
417
418 last = kvm->arch.round_robin_prev_vcpu;
419 next = last;
420
421 do {
422 if (++next == KVM_MAX_VCPUS)
423 next = 0;
424 if (kvm->vcpus[next] == NULL || !test_bit(next, &bitmap))
425 continue;
426 apic = kvm->vcpus[next]->arch.apic;
427 if (apic && apic_enabled(apic))
428 break;
429 apic = NULL;
430 } while (next != last);
431 kvm->arch.round_robin_prev_vcpu = next;
432
433 if (!apic)
434 printk(KERN_DEBUG "vcpu not ready for apic_round_robin\n");
435
436 return apic;
437}
438
439struct kvm_vcpu *kvm_get_lowest_prio_vcpu(struct kvm *kvm, u8 vector,
440 unsigned long bitmap)
441{ 406{
442 struct kvm_lapic *apic; 407 return vcpu1->arch.apic_arb_prio - vcpu2->arch.apic_arb_prio;
443
444 apic = kvm_apic_round_robin(kvm, vector, bitmap);
445 if (apic)
446 return apic->vcpu;
447 return NULL;
448} 408}
449 409
450static void apic_set_eoi(struct kvm_lapic *apic) 410static void apic_set_eoi(struct kvm_lapic *apic)
@@ -472,47 +432,24 @@ static void apic_send_ipi(struct kvm_lapic *apic)
472{ 432{
473 u32 icr_low = apic_get_reg(apic, APIC_ICR); 433 u32 icr_low = apic_get_reg(apic, APIC_ICR);
474 u32 icr_high = apic_get_reg(apic, APIC_ICR2); 434 u32 icr_high = apic_get_reg(apic, APIC_ICR2);
435 struct kvm_lapic_irq irq;
475 436
476 unsigned int dest = GET_APIC_DEST_FIELD(icr_high); 437 irq.vector = icr_low & APIC_VECTOR_MASK;
477 unsigned int short_hand = icr_low & APIC_SHORT_MASK; 438 irq.delivery_mode = icr_low & APIC_MODE_MASK;
478 unsigned int trig_mode = icr_low & APIC_INT_LEVELTRIG; 439 irq.dest_mode = icr_low & APIC_DEST_MASK;
479 unsigned int level = icr_low & APIC_INT_ASSERT; 440 irq.level = icr_low & APIC_INT_ASSERT;
480 unsigned int dest_mode = icr_low & APIC_DEST_MASK; 441 irq.trig_mode = icr_low & APIC_INT_LEVELTRIG;
481 unsigned int delivery_mode = icr_low & APIC_MODE_MASK; 442 irq.shorthand = icr_low & APIC_SHORT_MASK;
482 unsigned int vector = icr_low & APIC_VECTOR_MASK; 443 irq.dest_id = GET_APIC_DEST_FIELD(icr_high);
483
484 struct kvm_vcpu *target;
485 struct kvm_vcpu *vcpu;
486 unsigned long lpr_map = 0;
487 int i;
488 444
489 apic_debug("icr_high 0x%x, icr_low 0x%x, " 445 apic_debug("icr_high 0x%x, icr_low 0x%x, "
490 "short_hand 0x%x, dest 0x%x, trig_mode 0x%x, level 0x%x, " 446 "short_hand 0x%x, dest 0x%x, trig_mode 0x%x, level 0x%x, "
491 "dest_mode 0x%x, delivery_mode 0x%x, vector 0x%x\n", 447 "dest_mode 0x%x, delivery_mode 0x%x, vector 0x%x\n",
492 icr_high, icr_low, short_hand, dest, 448 icr_high, icr_low, irq.shorthand, irq.dest_id,
493 trig_mode, level, dest_mode, delivery_mode, vector); 449 irq.trig_mode, irq.level, irq.dest_mode, irq.delivery_mode,
494 450 irq.vector);
495 for (i = 0; i < KVM_MAX_VCPUS; i++) {
496 vcpu = apic->vcpu->kvm->vcpus[i];
497 if (!vcpu)
498 continue;
499
500 if (vcpu->arch.apic &&
501 apic_match_dest(vcpu, apic, short_hand, dest, dest_mode)) {
502 if (delivery_mode == APIC_DM_LOWEST)
503 set_bit(vcpu->vcpu_id, &lpr_map);
504 else
505 __apic_accept_irq(vcpu->arch.apic, delivery_mode,
506 vector, level, trig_mode);
507 }
508 }
509 451
510 if (delivery_mode == APIC_DM_LOWEST) { 452 kvm_irq_delivery_to_apic(apic->vcpu->kvm, apic, &irq);
511 target = kvm_get_lowest_prio_vcpu(vcpu->kvm, vector, lpr_map);
512 if (target != NULL)
513 __apic_accept_irq(target->arch.apic, delivery_mode,
514 vector, level, trig_mode);
515 }
516} 453}
517 454
518static u32 apic_get_tmcct(struct kvm_lapic *apic) 455static u32 apic_get_tmcct(struct kvm_lapic *apic)
@@ -527,12 +464,13 @@ static u32 apic_get_tmcct(struct kvm_lapic *apic)
527 if (apic_get_reg(apic, APIC_TMICT) == 0) 464 if (apic_get_reg(apic, APIC_TMICT) == 0)
528 return 0; 465 return 0;
529 466
530 remaining = hrtimer_expires_remaining(&apic->timer.dev); 467 remaining = hrtimer_expires_remaining(&apic->lapic_timer.timer);
531 if (ktime_to_ns(remaining) < 0) 468 if (ktime_to_ns(remaining) < 0)
532 remaining = ktime_set(0, 0); 469 remaining = ktime_set(0, 0);
533 470
534 ns = mod_64(ktime_to_ns(remaining), apic->timer.period); 471 ns = mod_64(ktime_to_ns(remaining), apic->lapic_timer.period);
535 tmcct = div64_u64(ns, (APIC_BUS_CYCLE_NS * apic->timer.divide_count)); 472 tmcct = div64_u64(ns,
473 (APIC_BUS_CYCLE_NS * apic->divide_count));
536 474
537 return tmcct; 475 return tmcct;
538} 476}
@@ -619,25 +557,25 @@ static void update_divide_count(struct kvm_lapic *apic)
619 tdcr = apic_get_reg(apic, APIC_TDCR); 557 tdcr = apic_get_reg(apic, APIC_TDCR);
620 tmp1 = tdcr & 0xf; 558 tmp1 = tdcr & 0xf;
621 tmp2 = ((tmp1 & 0x3) | ((tmp1 & 0x8) >> 1)) + 1; 559 tmp2 = ((tmp1 & 0x3) | ((tmp1 & 0x8) >> 1)) + 1;
622 apic->timer.divide_count = 0x1 << (tmp2 & 0x7); 560 apic->divide_count = 0x1 << (tmp2 & 0x7);
623 561
624 apic_debug("timer divide count is 0x%x\n", 562 apic_debug("timer divide count is 0x%x\n",
625 apic->timer.divide_count); 563 apic->divide_count);
626} 564}
627 565
628static void start_apic_timer(struct kvm_lapic *apic) 566static void start_apic_timer(struct kvm_lapic *apic)
629{ 567{
630 ktime_t now = apic->timer.dev.base->get_time(); 568 ktime_t now = apic->lapic_timer.timer.base->get_time();
631 569
632 apic->timer.period = apic_get_reg(apic, APIC_TMICT) * 570 apic->lapic_timer.period = apic_get_reg(apic, APIC_TMICT) *
633 APIC_BUS_CYCLE_NS * apic->timer.divide_count; 571 APIC_BUS_CYCLE_NS * apic->divide_count;
634 atomic_set(&apic->timer.pending, 0); 572 atomic_set(&apic->lapic_timer.pending, 0);
635 573
636 if (!apic->timer.period) 574 if (!apic->lapic_timer.period)
637 return; 575 return;
638 576
639 hrtimer_start(&apic->timer.dev, 577 hrtimer_start(&apic->lapic_timer.timer,
640 ktime_add_ns(now, apic->timer.period), 578 ktime_add_ns(now, apic->lapic_timer.period),
641 HRTIMER_MODE_ABS); 579 HRTIMER_MODE_ABS);
642 580
643 apic_debug("%s: bus cycle is %" PRId64 "ns, now 0x%016" 581 apic_debug("%s: bus cycle is %" PRId64 "ns, now 0x%016"
@@ -646,9 +584,9 @@ static void start_apic_timer(struct kvm_lapic *apic)
646 "expire @ 0x%016" PRIx64 ".\n", __func__, 584 "expire @ 0x%016" PRIx64 ".\n", __func__,
647 APIC_BUS_CYCLE_NS, ktime_to_ns(now), 585 APIC_BUS_CYCLE_NS, ktime_to_ns(now),
648 apic_get_reg(apic, APIC_TMICT), 586 apic_get_reg(apic, APIC_TMICT),
649 apic->timer.period, 587 apic->lapic_timer.period,
650 ktime_to_ns(ktime_add_ns(now, 588 ktime_to_ns(ktime_add_ns(now,
651 apic->timer.period))); 589 apic->lapic_timer.period)));
652} 590}
653 591
654static void apic_manage_nmi_watchdog(struct kvm_lapic *apic, u32 lvt0_val) 592static void apic_manage_nmi_watchdog(struct kvm_lapic *apic, u32 lvt0_val)
@@ -730,7 +668,7 @@ static void apic_mmio_write(struct kvm_io_device *this,
730 apic_set_reg(apic, APIC_LVTT + 0x10 * i, 668 apic_set_reg(apic, APIC_LVTT + 0x10 * i,
731 lvt_val | APIC_LVT_MASKED); 669 lvt_val | APIC_LVT_MASKED);
732 } 670 }
733 atomic_set(&apic->timer.pending, 0); 671 atomic_set(&apic->lapic_timer.pending, 0);
734 672
735 } 673 }
736 break; 674 break;
@@ -762,7 +700,7 @@ static void apic_mmio_write(struct kvm_io_device *this,
762 break; 700 break;
763 701
764 case APIC_TMICT: 702 case APIC_TMICT:
765 hrtimer_cancel(&apic->timer.dev); 703 hrtimer_cancel(&apic->lapic_timer.timer);
766 apic_set_reg(apic, APIC_TMICT, val); 704 apic_set_reg(apic, APIC_TMICT, val);
767 start_apic_timer(apic); 705 start_apic_timer(apic);
768 return; 706 return;
@@ -802,7 +740,7 @@ void kvm_free_lapic(struct kvm_vcpu *vcpu)
802 if (!vcpu->arch.apic) 740 if (!vcpu->arch.apic)
803 return; 741 return;
804 742
805 hrtimer_cancel(&vcpu->arch.apic->timer.dev); 743 hrtimer_cancel(&vcpu->arch.apic->lapic_timer.timer);
806 744
807 if (vcpu->arch.apic->regs_page) 745 if (vcpu->arch.apic->regs_page)
808 __free_page(vcpu->arch.apic->regs_page); 746 __free_page(vcpu->arch.apic->regs_page);
@@ -880,7 +818,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu)
880 ASSERT(apic != NULL); 818 ASSERT(apic != NULL);
881 819
882 /* Stop the timer in case it's a reset to an active apic */ 820 /* Stop the timer in case it's a reset to an active apic */
883 hrtimer_cancel(&apic->timer.dev); 821 hrtimer_cancel(&apic->lapic_timer.timer);
884 822
885 apic_set_reg(apic, APIC_ID, vcpu->vcpu_id << 24); 823 apic_set_reg(apic, APIC_ID, vcpu->vcpu_id << 24);
886 apic_set_reg(apic, APIC_LVR, APIC_VERSION); 824 apic_set_reg(apic, APIC_LVR, APIC_VERSION);
@@ -905,11 +843,13 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu)
905 apic_set_reg(apic, APIC_TMR + 0x10 * i, 0); 843 apic_set_reg(apic, APIC_TMR + 0x10 * i, 0);
906 } 844 }
907 update_divide_count(apic); 845 update_divide_count(apic);
908 atomic_set(&apic->timer.pending, 0); 846 atomic_set(&apic->lapic_timer.pending, 0);
909 if (vcpu->vcpu_id == 0) 847 if (vcpu->vcpu_id == 0)
910 vcpu->arch.apic_base |= MSR_IA32_APICBASE_BSP; 848 vcpu->arch.apic_base |= MSR_IA32_APICBASE_BSP;
911 apic_update_ppr(apic); 849 apic_update_ppr(apic);
912 850
851 vcpu->arch.apic_arb_prio = 0;
852
913 apic_debug(KERN_INFO "%s: vcpu=%p, id=%d, base_msr=" 853 apic_debug(KERN_INFO "%s: vcpu=%p, id=%d, base_msr="
914 "0x%016" PRIx64 ", base_address=0x%0lx.\n", __func__, 854 "0x%016" PRIx64 ", base_address=0x%0lx.\n", __func__,
915 vcpu, kvm_apic_id(apic), 855 vcpu, kvm_apic_id(apic),
@@ -917,16 +857,14 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu)
917} 857}
918EXPORT_SYMBOL_GPL(kvm_lapic_reset); 858EXPORT_SYMBOL_GPL(kvm_lapic_reset);
919 859
920int kvm_lapic_enabled(struct kvm_vcpu *vcpu) 860bool kvm_apic_present(struct kvm_vcpu *vcpu)
921{ 861{
922 struct kvm_lapic *apic = vcpu->arch.apic; 862 return vcpu->arch.apic && apic_hw_enabled(vcpu->arch.apic);
923 int ret = 0; 863}
924
925 if (!apic)
926 return 0;
927 ret = apic_enabled(apic);
928 864
929 return ret; 865int kvm_lapic_enabled(struct kvm_vcpu *vcpu)
866{
867 return kvm_apic_present(vcpu) && apic_sw_enabled(vcpu->arch.apic);
930} 868}
931EXPORT_SYMBOL_GPL(kvm_lapic_enabled); 869EXPORT_SYMBOL_GPL(kvm_lapic_enabled);
932 870
@@ -936,22 +874,11 @@ EXPORT_SYMBOL_GPL(kvm_lapic_enabled);
936 *---------------------------------------------------------------------- 874 *----------------------------------------------------------------------
937 */ 875 */
938 876
939/* TODO: make sure __apic_timer_fn runs in current pCPU */ 877static bool lapic_is_periodic(struct kvm_timer *ktimer)
940static int __apic_timer_fn(struct kvm_lapic *apic)
941{ 878{
942 int result = 0; 879 struct kvm_lapic *apic = container_of(ktimer, struct kvm_lapic,
943 wait_queue_head_t *q = &apic->vcpu->wq; 880 lapic_timer);
944 881 return apic_lvtt_period(apic);
945 if(!atomic_inc_and_test(&apic->timer.pending))
946 set_bit(KVM_REQ_PENDING_TIMER, &apic->vcpu->requests);
947 if (waitqueue_active(q))
948 wake_up_interruptible(q);
949
950 if (apic_lvtt_period(apic)) {
951 result = 1;
952 hrtimer_add_expires_ns(&apic->timer.dev, apic->timer.period);
953 }
954 return result;
955} 882}
956 883
957int apic_has_pending_timer(struct kvm_vcpu *vcpu) 884int apic_has_pending_timer(struct kvm_vcpu *vcpu)
@@ -959,7 +886,7 @@ int apic_has_pending_timer(struct kvm_vcpu *vcpu)
959 struct kvm_lapic *lapic = vcpu->arch.apic; 886 struct kvm_lapic *lapic = vcpu->arch.apic;
960 887
961 if (lapic && apic_enabled(lapic) && apic_lvt_enabled(lapic, APIC_LVTT)) 888 if (lapic && apic_enabled(lapic) && apic_lvt_enabled(lapic, APIC_LVTT))
962 return atomic_read(&lapic->timer.pending); 889 return atomic_read(&lapic->lapic_timer.pending);
963 890
964 return 0; 891 return 0;
965} 892}
@@ -986,20 +913,9 @@ void kvm_apic_nmi_wd_deliver(struct kvm_vcpu *vcpu)
986 kvm_apic_local_deliver(apic, APIC_LVT0); 913 kvm_apic_local_deliver(apic, APIC_LVT0);
987} 914}
988 915
989static enum hrtimer_restart apic_timer_fn(struct hrtimer *data) 916static struct kvm_timer_ops lapic_timer_ops = {
990{ 917 .is_periodic = lapic_is_periodic,
991 struct kvm_lapic *apic; 918};
992 int restart_timer = 0;
993
994 apic = container_of(data, struct kvm_lapic, timer.dev);
995
996 restart_timer = __apic_timer_fn(apic);
997
998 if (restart_timer)
999 return HRTIMER_RESTART;
1000 else
1001 return HRTIMER_NORESTART;
1002}
1003 919
1004int kvm_create_lapic(struct kvm_vcpu *vcpu) 920int kvm_create_lapic(struct kvm_vcpu *vcpu)
1005{ 921{
@@ -1024,8 +940,13 @@ int kvm_create_lapic(struct kvm_vcpu *vcpu)
1024 memset(apic->regs, 0, PAGE_SIZE); 940 memset(apic->regs, 0, PAGE_SIZE);
1025 apic->vcpu = vcpu; 941 apic->vcpu = vcpu;
1026 942
1027 hrtimer_init(&apic->timer.dev, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); 943 hrtimer_init(&apic->lapic_timer.timer, CLOCK_MONOTONIC,
1028 apic->timer.dev.function = apic_timer_fn; 944 HRTIMER_MODE_ABS);
945 apic->lapic_timer.timer.function = kvm_timer_fn;
946 apic->lapic_timer.t_ops = &lapic_timer_ops;
947 apic->lapic_timer.kvm = vcpu->kvm;
948 apic->lapic_timer.vcpu_id = vcpu->vcpu_id;
949
1029 apic->base_address = APIC_DEFAULT_PHYS_BASE; 950 apic->base_address = APIC_DEFAULT_PHYS_BASE;
1030 vcpu->arch.apic_base = APIC_DEFAULT_PHYS_BASE; 951 vcpu->arch.apic_base = APIC_DEFAULT_PHYS_BASE;
1031 952
@@ -1078,9 +999,9 @@ void kvm_inject_apic_timer_irqs(struct kvm_vcpu *vcpu)
1078{ 999{
1079 struct kvm_lapic *apic = vcpu->arch.apic; 1000 struct kvm_lapic *apic = vcpu->arch.apic;
1080 1001
1081 if (apic && atomic_read(&apic->timer.pending) > 0) { 1002 if (apic && atomic_read(&apic->lapic_timer.pending) > 0) {
1082 if (kvm_apic_local_deliver(apic, APIC_LVTT)) 1003 if (kvm_apic_local_deliver(apic, APIC_LVTT))
1083 atomic_dec(&apic->timer.pending); 1004 atomic_dec(&apic->lapic_timer.pending);
1084 } 1005 }
1085} 1006}
1086 1007
@@ -1106,7 +1027,7 @@ void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu)
1106 MSR_IA32_APICBASE_BASE; 1027 MSR_IA32_APICBASE_BASE;
1107 apic_set_reg(apic, APIC_LVR, APIC_VERSION); 1028 apic_set_reg(apic, APIC_LVR, APIC_VERSION);
1108 apic_update_ppr(apic); 1029 apic_update_ppr(apic);
1109 hrtimer_cancel(&apic->timer.dev); 1030 hrtimer_cancel(&apic->lapic_timer.timer);
1110 update_divide_count(apic); 1031 update_divide_count(apic);
1111 start_apic_timer(apic); 1032 start_apic_timer(apic);
1112} 1033}
@@ -1119,7 +1040,7 @@ void __kvm_migrate_apic_timer(struct kvm_vcpu *vcpu)
1119 if (!apic) 1040 if (!apic)
1120 return; 1041 return;
1121 1042
1122 timer = &apic->timer.dev; 1043 timer = &apic->lapic_timer.timer;
1123 if (hrtimer_cancel(timer)) 1044 if (hrtimer_cancel(timer))
1124 hrtimer_start_expires(timer, HRTIMER_MODE_ABS); 1045 hrtimer_start_expires(timer, HRTIMER_MODE_ABS);
1125} 1046}
diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
index 45ab6ee71209..a587f8349c46 100644
--- a/arch/x86/kvm/lapic.h
+++ b/arch/x86/kvm/lapic.h
@@ -2,18 +2,15 @@
2#define __KVM_X86_LAPIC_H 2#define __KVM_X86_LAPIC_H
3 3
4#include "iodev.h" 4#include "iodev.h"
5#include "kvm_timer.h"
5 6
6#include <linux/kvm_host.h> 7#include <linux/kvm_host.h>
7 8
8struct kvm_lapic { 9struct kvm_lapic {
9 unsigned long base_address; 10 unsigned long base_address;
10 struct kvm_io_device dev; 11 struct kvm_io_device dev;
11 struct { 12 struct kvm_timer lapic_timer;
12 atomic_t pending; 13 u32 divide_count;
13 s64 period; /* unit: ns */
14 u32 divide_count;
15 struct hrtimer dev;
16 } timer;
17 struct kvm_vcpu *vcpu; 14 struct kvm_vcpu *vcpu;
18 struct page *regs_page; 15 struct page *regs_page;
19 void *regs; 16 void *regs;
@@ -34,12 +31,13 @@ u64 kvm_lapic_get_base(struct kvm_vcpu *vcpu);
34 31
35int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest); 32int kvm_apic_match_physical_addr(struct kvm_lapic *apic, u16 dest);
36int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda); 33int kvm_apic_match_logical_addr(struct kvm_lapic *apic, u8 mda);
37int kvm_apic_set_irq(struct kvm_vcpu *vcpu, u8 vec, u8 trig); 34int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq);
38 35
39u64 kvm_get_apic_base(struct kvm_vcpu *vcpu); 36u64 kvm_get_apic_base(struct kvm_vcpu *vcpu);
40void kvm_set_apic_base(struct kvm_vcpu *vcpu, u64 data); 37void kvm_set_apic_base(struct kvm_vcpu *vcpu, u64 data);
41void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu); 38void kvm_apic_post_state_restore(struct kvm_vcpu *vcpu);
42int kvm_lapic_enabled(struct kvm_vcpu *vcpu); 39int kvm_lapic_enabled(struct kvm_vcpu *vcpu);
40bool kvm_apic_present(struct kvm_vcpu *vcpu);
43int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu); 41int kvm_lapic_find_highest_irr(struct kvm_vcpu *vcpu);
44 42
45void kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr); 43void kvm_lapic_set_vapic_addr(struct kvm_vcpu *vcpu, gpa_t vapic_addr);
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 32cf11e5728a..5c3d6e81a7dc 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -126,6 +126,7 @@ module_param(oos_shadow, bool, 0644);
126#define PFERR_PRESENT_MASK (1U << 0) 126#define PFERR_PRESENT_MASK (1U << 0)
127#define PFERR_WRITE_MASK (1U << 1) 127#define PFERR_WRITE_MASK (1U << 1)
128#define PFERR_USER_MASK (1U << 2) 128#define PFERR_USER_MASK (1U << 2)
129#define PFERR_RSVD_MASK (1U << 3)
129#define PFERR_FETCH_MASK (1U << 4) 130#define PFERR_FETCH_MASK (1U << 4)
130 131
131#define PT_DIRECTORY_LEVEL 2 132#define PT_DIRECTORY_LEVEL 2
@@ -177,7 +178,11 @@ static u64 __read_mostly shadow_x_mask; /* mutual exclusive with nx_mask */
177static u64 __read_mostly shadow_user_mask; 178static u64 __read_mostly shadow_user_mask;
178static u64 __read_mostly shadow_accessed_mask; 179static u64 __read_mostly shadow_accessed_mask;
179static u64 __read_mostly shadow_dirty_mask; 180static u64 __read_mostly shadow_dirty_mask;
180static u64 __read_mostly shadow_mt_mask; 181
182static inline u64 rsvd_bits(int s, int e)
183{
184 return ((1ULL << (e - s + 1)) - 1) << s;
185}
181 186
182void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte) 187void kvm_mmu_set_nonpresent_ptes(u64 trap_pte, u64 notrap_pte)
183{ 188{
@@ -193,14 +198,13 @@ void kvm_mmu_set_base_ptes(u64 base_pte)
193EXPORT_SYMBOL_GPL(kvm_mmu_set_base_ptes); 198EXPORT_SYMBOL_GPL(kvm_mmu_set_base_ptes);
194 199
195void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask, 200void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask,
196 u64 dirty_mask, u64 nx_mask, u64 x_mask, u64 mt_mask) 201 u64 dirty_mask, u64 nx_mask, u64 x_mask)
197{ 202{
198 shadow_user_mask = user_mask; 203 shadow_user_mask = user_mask;
199 shadow_accessed_mask = accessed_mask; 204 shadow_accessed_mask = accessed_mask;
200 shadow_dirty_mask = dirty_mask; 205 shadow_dirty_mask = dirty_mask;
201 shadow_nx_mask = nx_mask; 206 shadow_nx_mask = nx_mask;
202 shadow_x_mask = x_mask; 207 shadow_x_mask = x_mask;
203 shadow_mt_mask = mt_mask;
204} 208}
205EXPORT_SYMBOL_GPL(kvm_mmu_set_mask_ptes); 209EXPORT_SYMBOL_GPL(kvm_mmu_set_mask_ptes);
206 210
@@ -219,11 +223,6 @@ static int is_nx(struct kvm_vcpu *vcpu)
219 return vcpu->arch.shadow_efer & EFER_NX; 223 return vcpu->arch.shadow_efer & EFER_NX;
220} 224}
221 225
222static int is_present_pte(unsigned long pte)
223{
224 return pte & PT_PRESENT_MASK;
225}
226
227static int is_shadow_present_pte(u64 pte) 226static int is_shadow_present_pte(u64 pte)
228{ 227{
229 return pte != shadow_trap_nonpresent_pte 228 return pte != shadow_trap_nonpresent_pte
@@ -1074,18 +1073,10 @@ static struct kvm_mmu_page *kvm_mmu_lookup_page(struct kvm *kvm, gfn_t gfn)
1074 return NULL; 1073 return NULL;
1075} 1074}
1076 1075
1077static void kvm_unlink_unsync_global(struct kvm *kvm, struct kvm_mmu_page *sp)
1078{
1079 list_del(&sp->oos_link);
1080 --kvm->stat.mmu_unsync_global;
1081}
1082
1083static void kvm_unlink_unsync_page(struct kvm *kvm, struct kvm_mmu_page *sp) 1076static void kvm_unlink_unsync_page(struct kvm *kvm, struct kvm_mmu_page *sp)
1084{ 1077{
1085 WARN_ON(!sp->unsync); 1078 WARN_ON(!sp->unsync);
1086 sp->unsync = 0; 1079 sp->unsync = 0;
1087 if (sp->global)
1088 kvm_unlink_unsync_global(kvm, sp);
1089 --kvm->stat.mmu_unsync; 1080 --kvm->stat.mmu_unsync;
1090} 1081}
1091 1082
@@ -1248,7 +1239,6 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
1248 pgprintk("%s: adding gfn %lx role %x\n", __func__, gfn, role.word); 1239 pgprintk("%s: adding gfn %lx role %x\n", __func__, gfn, role.word);
1249 sp->gfn = gfn; 1240 sp->gfn = gfn;
1250 sp->role = role; 1241 sp->role = role;
1251 sp->global = 0;
1252 hlist_add_head(&sp->hash_link, bucket); 1242 hlist_add_head(&sp->hash_link, bucket);
1253 if (!direct) { 1243 if (!direct) {
1254 if (rmap_write_protect(vcpu->kvm, gfn)) 1244 if (rmap_write_protect(vcpu->kvm, gfn))
@@ -1616,7 +1606,7 @@ static int get_mtrr_type(struct mtrr_state_type *mtrr_state,
1616 return mtrr_state->def_type; 1606 return mtrr_state->def_type;
1617} 1607}
1618 1608
1619static u8 get_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn) 1609u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn)
1620{ 1610{
1621 u8 mtrr; 1611 u8 mtrr;
1622 1612
@@ -1626,6 +1616,7 @@ static u8 get_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn)
1626 mtrr = MTRR_TYPE_WRBACK; 1616 mtrr = MTRR_TYPE_WRBACK;
1627 return mtrr; 1617 return mtrr;
1628} 1618}
1619EXPORT_SYMBOL_GPL(kvm_get_guest_memory_type);
1629 1620
1630static int kvm_unsync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp) 1621static int kvm_unsync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
1631{ 1622{
@@ -1646,11 +1637,7 @@ static int kvm_unsync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
1646 ++vcpu->kvm->stat.mmu_unsync; 1637 ++vcpu->kvm->stat.mmu_unsync;
1647 sp->unsync = 1; 1638 sp->unsync = 1;
1648 1639
1649 if (sp->global) { 1640 kvm_mmu_mark_parents_unsync(vcpu, sp);
1650 list_add(&sp->oos_link, &vcpu->kvm->arch.oos_global_pages);
1651 ++vcpu->kvm->stat.mmu_unsync_global;
1652 } else
1653 kvm_mmu_mark_parents_unsync(vcpu, sp);
1654 1641
1655 mmu_convert_notrap(sp); 1642 mmu_convert_notrap(sp);
1656 return 0; 1643 return 0;
@@ -1677,21 +1664,11 @@ static int mmu_need_write_protect(struct kvm_vcpu *vcpu, gfn_t gfn,
1677static int set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte, 1664static int set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte,
1678 unsigned pte_access, int user_fault, 1665 unsigned pte_access, int user_fault,
1679 int write_fault, int dirty, int largepage, 1666 int write_fault, int dirty, int largepage,
1680 int global, gfn_t gfn, pfn_t pfn, bool speculative, 1667 gfn_t gfn, pfn_t pfn, bool speculative,
1681 bool can_unsync) 1668 bool can_unsync)
1682{ 1669{
1683 u64 spte; 1670 u64 spte;
1684 int ret = 0; 1671 int ret = 0;
1685 u64 mt_mask = shadow_mt_mask;
1686 struct kvm_mmu_page *sp = page_header(__pa(shadow_pte));
1687
1688 if (!global && sp->global) {
1689 sp->global = 0;
1690 if (sp->unsync) {
1691 kvm_unlink_unsync_global(vcpu->kvm, sp);
1692 kvm_mmu_mark_parents_unsync(vcpu, sp);
1693 }
1694 }
1695 1672
1696 /* 1673 /*
1697 * We don't set the accessed bit, since we sometimes want to see 1674 * We don't set the accessed bit, since we sometimes want to see
@@ -1711,16 +1688,9 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte,
1711 spte |= shadow_user_mask; 1688 spte |= shadow_user_mask;
1712 if (largepage) 1689 if (largepage)
1713 spte |= PT_PAGE_SIZE_MASK; 1690 spte |= PT_PAGE_SIZE_MASK;
1714 if (mt_mask) { 1691 if (tdp_enabled)
1715 if (!kvm_is_mmio_pfn(pfn)) { 1692 spte |= kvm_x86_ops->get_mt_mask(vcpu, gfn,
1716 mt_mask = get_memory_type(vcpu, gfn) << 1693 kvm_is_mmio_pfn(pfn));
1717 kvm_x86_ops->get_mt_mask_shift();
1718 mt_mask |= VMX_EPT_IGMT_BIT;
1719 } else
1720 mt_mask = MTRR_TYPE_UNCACHABLE <<
1721 kvm_x86_ops->get_mt_mask_shift();
1722 spte |= mt_mask;
1723 }
1724 1694
1725 spte |= (u64)pfn << PAGE_SHIFT; 1695 spte |= (u64)pfn << PAGE_SHIFT;
1726 1696
@@ -1765,8 +1735,8 @@ set_pte:
1765static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte, 1735static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte,
1766 unsigned pt_access, unsigned pte_access, 1736 unsigned pt_access, unsigned pte_access,
1767 int user_fault, int write_fault, int dirty, 1737 int user_fault, int write_fault, int dirty,
1768 int *ptwrite, int largepage, int global, 1738 int *ptwrite, int largepage, gfn_t gfn,
1769 gfn_t gfn, pfn_t pfn, bool speculative) 1739 pfn_t pfn, bool speculative)
1770{ 1740{
1771 int was_rmapped = 0; 1741 int was_rmapped = 0;
1772 int was_writeble = is_writeble_pte(*shadow_pte); 1742 int was_writeble = is_writeble_pte(*shadow_pte);
@@ -1795,7 +1765,7 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte,
1795 was_rmapped = 1; 1765 was_rmapped = 1;
1796 } 1766 }
1797 if (set_spte(vcpu, shadow_pte, pte_access, user_fault, write_fault, 1767 if (set_spte(vcpu, shadow_pte, pte_access, user_fault, write_fault,
1798 dirty, largepage, global, gfn, pfn, speculative, true)) { 1768 dirty, largepage, gfn, pfn, speculative, true)) {
1799 if (write_fault) 1769 if (write_fault)
1800 *ptwrite = 1; 1770 *ptwrite = 1;
1801 kvm_x86_ops->tlb_flush(vcpu); 1771 kvm_x86_ops->tlb_flush(vcpu);
@@ -1843,7 +1813,7 @@ static int __direct_map(struct kvm_vcpu *vcpu, gpa_t v, int write,
1843 || (largepage && iterator.level == PT_DIRECTORY_LEVEL)) { 1813 || (largepage && iterator.level == PT_DIRECTORY_LEVEL)) {
1844 mmu_set_spte(vcpu, iterator.sptep, ACC_ALL, ACC_ALL, 1814 mmu_set_spte(vcpu, iterator.sptep, ACC_ALL, ACC_ALL,
1845 0, write, 1, &pt_write, 1815 0, write, 1, &pt_write,
1846 largepage, 0, gfn, pfn, false); 1816 largepage, gfn, pfn, false);
1847 ++vcpu->stat.pf_fixed; 1817 ++vcpu->stat.pf_fixed;
1848 break; 1818 break;
1849 } 1819 }
@@ -1942,7 +1912,19 @@ static void mmu_free_roots(struct kvm_vcpu *vcpu)
1942 vcpu->arch.mmu.root_hpa = INVALID_PAGE; 1912 vcpu->arch.mmu.root_hpa = INVALID_PAGE;
1943} 1913}
1944 1914
1945static void mmu_alloc_roots(struct kvm_vcpu *vcpu) 1915static int mmu_check_root(struct kvm_vcpu *vcpu, gfn_t root_gfn)
1916{
1917 int ret = 0;
1918
1919 if (!kvm_is_visible_gfn(vcpu->kvm, root_gfn)) {
1920 set_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests);
1921 ret = 1;
1922 }
1923
1924 return ret;
1925}
1926
1927static int mmu_alloc_roots(struct kvm_vcpu *vcpu)
1946{ 1928{
1947 int i; 1929 int i;
1948 gfn_t root_gfn; 1930 gfn_t root_gfn;
@@ -1957,13 +1939,15 @@ static void mmu_alloc_roots(struct kvm_vcpu *vcpu)
1957 ASSERT(!VALID_PAGE(root)); 1939 ASSERT(!VALID_PAGE(root));
1958 if (tdp_enabled) 1940 if (tdp_enabled)
1959 direct = 1; 1941 direct = 1;
1942 if (mmu_check_root(vcpu, root_gfn))
1943 return 1;
1960 sp = kvm_mmu_get_page(vcpu, root_gfn, 0, 1944 sp = kvm_mmu_get_page(vcpu, root_gfn, 0,
1961 PT64_ROOT_LEVEL, direct, 1945 PT64_ROOT_LEVEL, direct,
1962 ACC_ALL, NULL); 1946 ACC_ALL, NULL);
1963 root = __pa(sp->spt); 1947 root = __pa(sp->spt);
1964 ++sp->root_count; 1948 ++sp->root_count;
1965 vcpu->arch.mmu.root_hpa = root; 1949 vcpu->arch.mmu.root_hpa = root;
1966 return; 1950 return 0;
1967 } 1951 }
1968 direct = !is_paging(vcpu); 1952 direct = !is_paging(vcpu);
1969 if (tdp_enabled) 1953 if (tdp_enabled)
@@ -1980,6 +1964,8 @@ static void mmu_alloc_roots(struct kvm_vcpu *vcpu)
1980 root_gfn = vcpu->arch.pdptrs[i] >> PAGE_SHIFT; 1964 root_gfn = vcpu->arch.pdptrs[i] >> PAGE_SHIFT;
1981 } else if (vcpu->arch.mmu.root_level == 0) 1965 } else if (vcpu->arch.mmu.root_level == 0)
1982 root_gfn = 0; 1966 root_gfn = 0;
1967 if (mmu_check_root(vcpu, root_gfn))
1968 return 1;
1983 sp = kvm_mmu_get_page(vcpu, root_gfn, i << 30, 1969 sp = kvm_mmu_get_page(vcpu, root_gfn, i << 30,
1984 PT32_ROOT_LEVEL, direct, 1970 PT32_ROOT_LEVEL, direct,
1985 ACC_ALL, NULL); 1971 ACC_ALL, NULL);
@@ -1988,6 +1974,7 @@ static void mmu_alloc_roots(struct kvm_vcpu *vcpu)
1988 vcpu->arch.mmu.pae_root[i] = root | PT_PRESENT_MASK; 1974 vcpu->arch.mmu.pae_root[i] = root | PT_PRESENT_MASK;
1989 } 1975 }
1990 vcpu->arch.mmu.root_hpa = __pa(vcpu->arch.mmu.pae_root); 1976 vcpu->arch.mmu.root_hpa = __pa(vcpu->arch.mmu.pae_root);
1977 return 0;
1991} 1978}
1992 1979
1993static void mmu_sync_roots(struct kvm_vcpu *vcpu) 1980static void mmu_sync_roots(struct kvm_vcpu *vcpu)
@@ -2006,7 +1993,7 @@ static void mmu_sync_roots(struct kvm_vcpu *vcpu)
2006 for (i = 0; i < 4; ++i) { 1993 for (i = 0; i < 4; ++i) {
2007 hpa_t root = vcpu->arch.mmu.pae_root[i]; 1994 hpa_t root = vcpu->arch.mmu.pae_root[i];
2008 1995
2009 if (root) { 1996 if (root && VALID_PAGE(root)) {
2010 root &= PT64_BASE_ADDR_MASK; 1997 root &= PT64_BASE_ADDR_MASK;
2011 sp = page_header(root); 1998 sp = page_header(root);
2012 mmu_sync_children(vcpu, sp); 1999 mmu_sync_children(vcpu, sp);
@@ -2014,15 +2001,6 @@ static void mmu_sync_roots(struct kvm_vcpu *vcpu)
2014 } 2001 }
2015} 2002}
2016 2003
2017static void mmu_sync_global(struct kvm_vcpu *vcpu)
2018{
2019 struct kvm *kvm = vcpu->kvm;
2020 struct kvm_mmu_page *sp, *n;
2021
2022 list_for_each_entry_safe(sp, n, &kvm->arch.oos_global_pages, oos_link)
2023 kvm_sync_page(vcpu, sp);
2024}
2025
2026void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu) 2004void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu)
2027{ 2005{
2028 spin_lock(&vcpu->kvm->mmu_lock); 2006 spin_lock(&vcpu->kvm->mmu_lock);
@@ -2030,13 +2008,6 @@ void kvm_mmu_sync_roots(struct kvm_vcpu *vcpu)
2030 spin_unlock(&vcpu->kvm->mmu_lock); 2008 spin_unlock(&vcpu->kvm->mmu_lock);
2031} 2009}
2032 2010
2033void kvm_mmu_sync_global(struct kvm_vcpu *vcpu)
2034{
2035 spin_lock(&vcpu->kvm->mmu_lock);
2036 mmu_sync_global(vcpu);
2037 spin_unlock(&vcpu->kvm->mmu_lock);
2038}
2039
2040static gpa_t nonpaging_gva_to_gpa(struct kvm_vcpu *vcpu, gva_t vaddr) 2011static gpa_t nonpaging_gva_to_gpa(struct kvm_vcpu *vcpu, gva_t vaddr)
2041{ 2012{
2042 return vaddr; 2013 return vaddr;
@@ -2151,6 +2122,14 @@ static void paging_free(struct kvm_vcpu *vcpu)
2151 nonpaging_free(vcpu); 2122 nonpaging_free(vcpu);
2152} 2123}
2153 2124
2125static bool is_rsvd_bits_set(struct kvm_vcpu *vcpu, u64 gpte, int level)
2126{
2127 int bit7;
2128
2129 bit7 = (gpte >> 7) & 1;
2130 return (gpte & vcpu->arch.mmu.rsvd_bits_mask[bit7][level-1]) != 0;
2131}
2132
2154#define PTTYPE 64 2133#define PTTYPE 64
2155#include "paging_tmpl.h" 2134#include "paging_tmpl.h"
2156#undef PTTYPE 2135#undef PTTYPE
@@ -2159,6 +2138,59 @@ static void paging_free(struct kvm_vcpu *vcpu)
2159#include "paging_tmpl.h" 2138#include "paging_tmpl.h"
2160#undef PTTYPE 2139#undef PTTYPE
2161 2140
2141static void reset_rsvds_bits_mask(struct kvm_vcpu *vcpu, int level)
2142{
2143 struct kvm_mmu *context = &vcpu->arch.mmu;
2144 int maxphyaddr = cpuid_maxphyaddr(vcpu);
2145 u64 exb_bit_rsvd = 0;
2146
2147 if (!is_nx(vcpu))
2148 exb_bit_rsvd = rsvd_bits(63, 63);
2149 switch (level) {
2150 case PT32_ROOT_LEVEL:
2151 /* no rsvd bits for 2 level 4K page table entries */
2152 context->rsvd_bits_mask[0][1] = 0;
2153 context->rsvd_bits_mask[0][0] = 0;
2154 if (is_cpuid_PSE36())
2155 /* 36bits PSE 4MB page */
2156 context->rsvd_bits_mask[1][1] = rsvd_bits(17, 21);
2157 else
2158 /* 32 bits PSE 4MB page */
2159 context->rsvd_bits_mask[1][1] = rsvd_bits(13, 21);
2160 context->rsvd_bits_mask[1][0] = ~0ull;
2161 break;
2162 case PT32E_ROOT_LEVEL:
2163 context->rsvd_bits_mask[0][2] =
2164 rsvd_bits(maxphyaddr, 63) |
2165 rsvd_bits(7, 8) | rsvd_bits(1, 2); /* PDPTE */
2166 context->rsvd_bits_mask[0][1] = exb_bit_rsvd |
2167 rsvd_bits(maxphyaddr, 62); /* PDE */
2168 context->rsvd_bits_mask[0][0] = exb_bit_rsvd |
2169 rsvd_bits(maxphyaddr, 62); /* PTE */
2170 context->rsvd_bits_mask[1][1] = exb_bit_rsvd |
2171 rsvd_bits(maxphyaddr, 62) |
2172 rsvd_bits(13, 20); /* large page */
2173 context->rsvd_bits_mask[1][0] = ~0ull;
2174 break;
2175 case PT64_ROOT_LEVEL:
2176 context->rsvd_bits_mask[0][3] = exb_bit_rsvd |
2177 rsvd_bits(maxphyaddr, 51) | rsvd_bits(7, 8);
2178 context->rsvd_bits_mask[0][2] = exb_bit_rsvd |
2179 rsvd_bits(maxphyaddr, 51) | rsvd_bits(7, 8);
2180 context->rsvd_bits_mask[0][1] = exb_bit_rsvd |
2181 rsvd_bits(maxphyaddr, 51);
2182 context->rsvd_bits_mask[0][0] = exb_bit_rsvd |
2183 rsvd_bits(maxphyaddr, 51);
2184 context->rsvd_bits_mask[1][3] = context->rsvd_bits_mask[0][3];
2185 context->rsvd_bits_mask[1][2] = context->rsvd_bits_mask[0][2];
2186 context->rsvd_bits_mask[1][1] = exb_bit_rsvd |
2187 rsvd_bits(maxphyaddr, 51) |
2188 rsvd_bits(13, 20); /* large page */
2189 context->rsvd_bits_mask[1][0] = ~0ull;
2190 break;
2191 }
2192}
2193
2162static int paging64_init_context_common(struct kvm_vcpu *vcpu, int level) 2194static int paging64_init_context_common(struct kvm_vcpu *vcpu, int level)
2163{ 2195{
2164 struct kvm_mmu *context = &vcpu->arch.mmu; 2196 struct kvm_mmu *context = &vcpu->arch.mmu;
@@ -2179,6 +2211,7 @@ static int paging64_init_context_common(struct kvm_vcpu *vcpu, int level)
2179 2211
2180static int paging64_init_context(struct kvm_vcpu *vcpu) 2212static int paging64_init_context(struct kvm_vcpu *vcpu)
2181{ 2213{
2214 reset_rsvds_bits_mask(vcpu, PT64_ROOT_LEVEL);
2182 return paging64_init_context_common(vcpu, PT64_ROOT_LEVEL); 2215 return paging64_init_context_common(vcpu, PT64_ROOT_LEVEL);
2183} 2216}
2184 2217
@@ -2186,6 +2219,7 @@ static int paging32_init_context(struct kvm_vcpu *vcpu)
2186{ 2219{
2187 struct kvm_mmu *context = &vcpu->arch.mmu; 2220 struct kvm_mmu *context = &vcpu->arch.mmu;
2188 2221
2222 reset_rsvds_bits_mask(vcpu, PT32_ROOT_LEVEL);
2189 context->new_cr3 = paging_new_cr3; 2223 context->new_cr3 = paging_new_cr3;
2190 context->page_fault = paging32_page_fault; 2224 context->page_fault = paging32_page_fault;
2191 context->gva_to_gpa = paging32_gva_to_gpa; 2225 context->gva_to_gpa = paging32_gva_to_gpa;
@@ -2201,6 +2235,7 @@ static int paging32_init_context(struct kvm_vcpu *vcpu)
2201 2235
2202static int paging32E_init_context(struct kvm_vcpu *vcpu) 2236static int paging32E_init_context(struct kvm_vcpu *vcpu)
2203{ 2237{
2238 reset_rsvds_bits_mask(vcpu, PT32E_ROOT_LEVEL);
2204 return paging64_init_context_common(vcpu, PT32E_ROOT_LEVEL); 2239 return paging64_init_context_common(vcpu, PT32E_ROOT_LEVEL);
2205} 2240}
2206 2241
@@ -2221,12 +2256,15 @@ static int init_kvm_tdp_mmu(struct kvm_vcpu *vcpu)
2221 context->gva_to_gpa = nonpaging_gva_to_gpa; 2256 context->gva_to_gpa = nonpaging_gva_to_gpa;
2222 context->root_level = 0; 2257 context->root_level = 0;
2223 } else if (is_long_mode(vcpu)) { 2258 } else if (is_long_mode(vcpu)) {
2259 reset_rsvds_bits_mask(vcpu, PT64_ROOT_LEVEL);
2224 context->gva_to_gpa = paging64_gva_to_gpa; 2260 context->gva_to_gpa = paging64_gva_to_gpa;
2225 context->root_level = PT64_ROOT_LEVEL; 2261 context->root_level = PT64_ROOT_LEVEL;
2226 } else if (is_pae(vcpu)) { 2262 } else if (is_pae(vcpu)) {
2263 reset_rsvds_bits_mask(vcpu, PT32E_ROOT_LEVEL);
2227 context->gva_to_gpa = paging64_gva_to_gpa; 2264 context->gva_to_gpa = paging64_gva_to_gpa;
2228 context->root_level = PT32E_ROOT_LEVEL; 2265 context->root_level = PT32E_ROOT_LEVEL;
2229 } else { 2266 } else {
2267 reset_rsvds_bits_mask(vcpu, PT32_ROOT_LEVEL);
2230 context->gva_to_gpa = paging32_gva_to_gpa; 2268 context->gva_to_gpa = paging32_gva_to_gpa;
2231 context->root_level = PT32_ROOT_LEVEL; 2269 context->root_level = PT32_ROOT_LEVEL;
2232 } 2270 }
@@ -2290,9 +2328,11 @@ int kvm_mmu_load(struct kvm_vcpu *vcpu)
2290 goto out; 2328 goto out;
2291 spin_lock(&vcpu->kvm->mmu_lock); 2329 spin_lock(&vcpu->kvm->mmu_lock);
2292 kvm_mmu_free_some_pages(vcpu); 2330 kvm_mmu_free_some_pages(vcpu);
2293 mmu_alloc_roots(vcpu); 2331 r = mmu_alloc_roots(vcpu);
2294 mmu_sync_roots(vcpu); 2332 mmu_sync_roots(vcpu);
2295 spin_unlock(&vcpu->kvm->mmu_lock); 2333 spin_unlock(&vcpu->kvm->mmu_lock);
2334 if (r)
2335 goto out;
2296 kvm_x86_ops->set_cr3(vcpu, vcpu->arch.mmu.root_hpa); 2336 kvm_x86_ops->set_cr3(vcpu, vcpu->arch.mmu.root_hpa);
2297 kvm_mmu_flush_tlb(vcpu); 2337 kvm_mmu_flush_tlb(vcpu);
2298out: 2338out:
@@ -2638,14 +2678,6 @@ EXPORT_SYMBOL_GPL(kvm_disable_tdp);
2638 2678
2639static void free_mmu_pages(struct kvm_vcpu *vcpu) 2679static void free_mmu_pages(struct kvm_vcpu *vcpu)
2640{ 2680{
2641 struct kvm_mmu_page *sp;
2642
2643 while (!list_empty(&vcpu->kvm->arch.active_mmu_pages)) {
2644 sp = container_of(vcpu->kvm->arch.active_mmu_pages.next,
2645 struct kvm_mmu_page, link);
2646 kvm_mmu_zap_page(vcpu->kvm, sp);
2647 cond_resched();
2648 }
2649 free_page((unsigned long)vcpu->arch.mmu.pae_root); 2681 free_page((unsigned long)vcpu->arch.mmu.pae_root);
2650} 2682}
2651 2683
@@ -2710,7 +2742,6 @@ void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot)
2710{ 2742{
2711 struct kvm_mmu_page *sp; 2743 struct kvm_mmu_page *sp;
2712 2744
2713 spin_lock(&kvm->mmu_lock);
2714 list_for_each_entry(sp, &kvm->arch.active_mmu_pages, link) { 2745 list_for_each_entry(sp, &kvm->arch.active_mmu_pages, link) {
2715 int i; 2746 int i;
2716 u64 *pt; 2747 u64 *pt;
@@ -2725,7 +2756,6 @@ void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot)
2725 pt[i] &= ~PT_WRITABLE_MASK; 2756 pt[i] &= ~PT_WRITABLE_MASK;
2726 } 2757 }
2727 kvm_flush_remote_tlbs(kvm); 2758 kvm_flush_remote_tlbs(kvm);
2728 spin_unlock(&kvm->mmu_lock);
2729} 2759}
2730 2760
2731void kvm_mmu_zap_all(struct kvm *kvm) 2761void kvm_mmu_zap_all(struct kvm *kvm)
@@ -3007,11 +3037,13 @@ static void audit_mappings_page(struct kvm_vcpu *vcpu, u64 page_pte,
3007 " in nonleaf level: levels %d gva %lx" 3037 " in nonleaf level: levels %d gva %lx"
3008 " level %d pte %llx\n", audit_msg, 3038 " level %d pte %llx\n", audit_msg,
3009 vcpu->arch.mmu.root_level, va, level, ent); 3039 vcpu->arch.mmu.root_level, va, level, ent);
3010 3040 else
3011 audit_mappings_page(vcpu, ent, va, level - 1); 3041 audit_mappings_page(vcpu, ent, va, level - 1);
3012 } else { 3042 } else {
3013 gpa_t gpa = vcpu->arch.mmu.gva_to_gpa(vcpu, va); 3043 gpa_t gpa = vcpu->arch.mmu.gva_to_gpa(vcpu, va);
3014 hpa_t hpa = (hpa_t)gpa_to_pfn(vcpu, gpa) << PAGE_SHIFT; 3044 gfn_t gfn = gpa >> PAGE_SHIFT;
3045 pfn_t pfn = gfn_to_pfn(vcpu->kvm, gfn);
3046 hpa_t hpa = (hpa_t)pfn << PAGE_SHIFT;
3015 3047
3016 if (is_shadow_present_pte(ent) 3048 if (is_shadow_present_pte(ent)
3017 && (ent & PT64_BASE_ADDR_MASK) != hpa) 3049 && (ent & PT64_BASE_ADDR_MASK) != hpa)
diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h
index eaab2145f62b..3494a2fb136e 100644
--- a/arch/x86/kvm/mmu.h
+++ b/arch/x86/kvm/mmu.h
@@ -75,4 +75,9 @@ static inline int is_paging(struct kvm_vcpu *vcpu)
75 return vcpu->arch.cr0 & X86_CR0_PG; 75 return vcpu->arch.cr0 & X86_CR0_PG;
76} 76}
77 77
78static inline int is_present_pte(unsigned long pte)
79{
80 return pte & PT_PRESENT_MASK;
81}
82
78#endif 83#endif
diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
index 6bd70206c561..258e4591e1ca 100644
--- a/arch/x86/kvm/paging_tmpl.h
+++ b/arch/x86/kvm/paging_tmpl.h
@@ -123,6 +123,7 @@ static int FNAME(walk_addr)(struct guest_walker *walker,
123 gfn_t table_gfn; 123 gfn_t table_gfn;
124 unsigned index, pt_access, pte_access; 124 unsigned index, pt_access, pte_access;
125 gpa_t pte_gpa; 125 gpa_t pte_gpa;
126 int rsvd_fault = 0;
126 127
127 pgprintk("%s: addr %lx\n", __func__, addr); 128 pgprintk("%s: addr %lx\n", __func__, addr);
128walk: 129walk:
@@ -157,6 +158,10 @@ walk:
157 if (!is_present_pte(pte)) 158 if (!is_present_pte(pte))
158 goto not_present; 159 goto not_present;
159 160
161 rsvd_fault = is_rsvd_bits_set(vcpu, pte, walker->level);
162 if (rsvd_fault)
163 goto access_error;
164
160 if (write_fault && !is_writeble_pte(pte)) 165 if (write_fault && !is_writeble_pte(pte))
161 if (user_fault || is_write_protection(vcpu)) 166 if (user_fault || is_write_protection(vcpu))
162 goto access_error; 167 goto access_error;
@@ -209,7 +214,6 @@ walk:
209 if (ret) 214 if (ret)
210 goto walk; 215 goto walk;
211 pte |= PT_DIRTY_MASK; 216 pte |= PT_DIRTY_MASK;
212 kvm_mmu_pte_write(vcpu, pte_gpa, (u8 *)&pte, sizeof(pte), 0);
213 walker->ptes[walker->level - 1] = pte; 217 walker->ptes[walker->level - 1] = pte;
214 } 218 }
215 219
@@ -233,6 +237,8 @@ err:
233 walker->error_code |= PFERR_USER_MASK; 237 walker->error_code |= PFERR_USER_MASK;
234 if (fetch_fault) 238 if (fetch_fault)
235 walker->error_code |= PFERR_FETCH_MASK; 239 walker->error_code |= PFERR_FETCH_MASK;
240 if (rsvd_fault)
241 walker->error_code |= PFERR_RSVD_MASK;
236 return 0; 242 return 0;
237} 243}
238 244
@@ -262,8 +268,7 @@ static void FNAME(update_pte)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *page,
262 kvm_get_pfn(pfn); 268 kvm_get_pfn(pfn);
263 mmu_set_spte(vcpu, spte, page->role.access, pte_access, 0, 0, 269 mmu_set_spte(vcpu, spte, page->role.access, pte_access, 0, 0,
264 gpte & PT_DIRTY_MASK, NULL, largepage, 270 gpte & PT_DIRTY_MASK, NULL, largepage,
265 gpte & PT_GLOBAL_MASK, gpte_to_gfn(gpte), 271 gpte_to_gfn(gpte), pfn, true);
266 pfn, true);
267} 272}
268 273
269/* 274/*
@@ -297,7 +302,6 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr,
297 user_fault, write_fault, 302 user_fault, write_fault,
298 gw->ptes[gw->level-1] & PT_DIRTY_MASK, 303 gw->ptes[gw->level-1] & PT_DIRTY_MASK,
299 ptwrite, largepage, 304 ptwrite, largepage,
300 gw->ptes[gw->level-1] & PT_GLOBAL_MASK,
301 gw->gfn, pfn, false); 305 gw->gfn, pfn, false);
302 break; 306 break;
303 } 307 }
@@ -380,7 +384,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
380 return r; 384 return r;
381 385
382 /* 386 /*
383 * Look up the shadow pte for the faulting address. 387 * Look up the guest pte for the faulting address.
384 */ 388 */
385 r = FNAME(walk_addr)(&walker, vcpu, addr, write_fault, user_fault, 389 r = FNAME(walk_addr)(&walker, vcpu, addr, write_fault, user_fault,
386 fetch_fault); 390 fetch_fault);
@@ -586,7 +590,7 @@ static int FNAME(sync_page)(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp)
586 nr_present++; 590 nr_present++;
587 pte_access = sp->role.access & FNAME(gpte_access)(vcpu, gpte); 591 pte_access = sp->role.access & FNAME(gpte_access)(vcpu, gpte);
588 set_spte(vcpu, &sp->spt[i], pte_access, 0, 0, 592 set_spte(vcpu, &sp->spt[i], pte_access, 0, 0,
589 is_dirty_pte(gpte), 0, gpte & PT_GLOBAL_MASK, gfn, 593 is_dirty_pte(gpte), 0, gfn,
590 spte_to_pfn(sp->spt[i]), true, false); 594 spte_to_pfn(sp->spt[i]), true, false);
591 } 595 }
592 596
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 1f8510c51d6e..71510e07e69e 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -19,6 +19,7 @@
19#include "irq.h" 19#include "irq.h"
20#include "mmu.h" 20#include "mmu.h"
21#include "kvm_cache_regs.h" 21#include "kvm_cache_regs.h"
22#include "x86.h"
22 23
23#include <linux/module.h> 24#include <linux/module.h>
24#include <linux/kernel.h> 25#include <linux/kernel.h>
@@ -69,7 +70,6 @@ module_param(npt, int, S_IRUGO);
69static int nested = 0; 70static int nested = 0;
70module_param(nested, int, S_IRUGO); 71module_param(nested, int, S_IRUGO);
71 72
72static void kvm_reput_irq(struct vcpu_svm *svm);
73static void svm_flush_tlb(struct kvm_vcpu *vcpu); 73static void svm_flush_tlb(struct kvm_vcpu *vcpu);
74 74
75static int nested_svm_exit_handled(struct vcpu_svm *svm, bool kvm_override); 75static int nested_svm_exit_handled(struct vcpu_svm *svm, bool kvm_override);
@@ -132,24 +132,6 @@ static inline u32 svm_has(u32 feat)
132 return svm_features & feat; 132 return svm_features & feat;
133} 133}
134 134
135static inline u8 pop_irq(struct kvm_vcpu *vcpu)
136{
137 int word_index = __ffs(vcpu->arch.irq_summary);
138 int bit_index = __ffs(vcpu->arch.irq_pending[word_index]);
139 int irq = word_index * BITS_PER_LONG + bit_index;
140
141 clear_bit(bit_index, &vcpu->arch.irq_pending[word_index]);
142 if (!vcpu->arch.irq_pending[word_index])
143 clear_bit(word_index, &vcpu->arch.irq_summary);
144 return irq;
145}
146
147static inline void push_irq(struct kvm_vcpu *vcpu, u8 irq)
148{
149 set_bit(irq, vcpu->arch.irq_pending);
150 set_bit(irq / BITS_PER_LONG, &vcpu->arch.irq_summary);
151}
152
153static inline void clgi(void) 135static inline void clgi(void)
154{ 136{
155 asm volatile (__ex(SVM_CLGI)); 137 asm volatile (__ex(SVM_CLGI));
@@ -214,17 +196,31 @@ static void svm_queue_exception(struct kvm_vcpu *vcpu, unsigned nr,
214 svm->vmcb->control.event_inj_err = error_code; 196 svm->vmcb->control.event_inj_err = error_code;
215} 197}
216 198
217static bool svm_exception_injected(struct kvm_vcpu *vcpu) 199static int is_external_interrupt(u32 info)
200{
201 info &= SVM_EVTINJ_TYPE_MASK | SVM_EVTINJ_VALID;
202 return info == (SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_INTR);
203}
204
205static u32 svm_get_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)
218{ 206{
219 struct vcpu_svm *svm = to_svm(vcpu); 207 struct vcpu_svm *svm = to_svm(vcpu);
208 u32 ret = 0;
220 209
221 return !(svm->vmcb->control.exit_int_info & SVM_EXITINTINFO_VALID); 210 if (svm->vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK)
211 ret |= X86_SHADOW_INT_STI | X86_SHADOW_INT_MOV_SS;
212 return ret & mask;
222} 213}
223 214
224static int is_external_interrupt(u32 info) 215static void svm_set_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)
225{ 216{
226 info &= SVM_EVTINJ_TYPE_MASK | SVM_EVTINJ_VALID; 217 struct vcpu_svm *svm = to_svm(vcpu);
227 return info == (SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_INTR); 218
219 if (mask == 0)
220 svm->vmcb->control.int_state &= ~SVM_INTERRUPT_SHADOW_MASK;
221 else
222 svm->vmcb->control.int_state |= SVM_INTERRUPT_SHADOW_MASK;
223
228} 224}
229 225
230static void skip_emulated_instruction(struct kvm_vcpu *vcpu) 226static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
@@ -232,7 +228,9 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
232 struct vcpu_svm *svm = to_svm(vcpu); 228 struct vcpu_svm *svm = to_svm(vcpu);
233 229
234 if (!svm->next_rip) { 230 if (!svm->next_rip) {
235 printk(KERN_DEBUG "%s: NOP\n", __func__); 231 if (emulate_instruction(vcpu, vcpu->run, 0, 0, EMULTYPE_SKIP) !=
232 EMULATE_DONE)
233 printk(KERN_DEBUG "%s: NOP\n", __func__);
236 return; 234 return;
237 } 235 }
238 if (svm->next_rip - kvm_rip_read(vcpu) > MAX_INST_SIZE) 236 if (svm->next_rip - kvm_rip_read(vcpu) > MAX_INST_SIZE)
@@ -240,9 +238,7 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
240 __func__, kvm_rip_read(vcpu), svm->next_rip); 238 __func__, kvm_rip_read(vcpu), svm->next_rip);
241 239
242 kvm_rip_write(vcpu, svm->next_rip); 240 kvm_rip_write(vcpu, svm->next_rip);
243 svm->vmcb->control.int_state &= ~SVM_INTERRUPT_SHADOW_MASK; 241 svm_set_interrupt_shadow(vcpu, 0);
244
245 vcpu->arch.interrupt_window_open = (svm->vcpu.arch.hflags & HF_GIF_MASK);
246} 242}
247 243
248static int has_svm(void) 244static int has_svm(void)
@@ -830,6 +826,15 @@ static void svm_get_segment(struct kvm_vcpu *vcpu,
830 if (!var->unusable) 826 if (!var->unusable)
831 var->type |= 0x1; 827 var->type |= 0x1;
832 break; 828 break;
829 case VCPU_SREG_SS:
830 /* On AMD CPUs sometimes the DB bit in the segment
831 * descriptor is left as 1, although the whole segment has
832 * been made unusable. Clear it here to pass an Intel VMX
833 * entry check when cross vendor migrating.
834 */
835 if (var->unusable)
836 var->db = 0;
837 break;
833 } 838 }
834} 839}
835 840
@@ -960,15 +965,16 @@ static void svm_set_segment(struct kvm_vcpu *vcpu,
960 965
961} 966}
962 967
963static int svm_guest_debug(struct kvm_vcpu *vcpu, struct kvm_guest_debug *dbg) 968static void update_db_intercept(struct kvm_vcpu *vcpu)
964{ 969{
965 int old_debug = vcpu->guest_debug;
966 struct vcpu_svm *svm = to_svm(vcpu); 970 struct vcpu_svm *svm = to_svm(vcpu);
967 971
968 vcpu->guest_debug = dbg->control;
969
970 svm->vmcb->control.intercept_exceptions &= 972 svm->vmcb->control.intercept_exceptions &=
971 ~((1 << DB_VECTOR) | (1 << BP_VECTOR)); 973 ~((1 << DB_VECTOR) | (1 << BP_VECTOR));
974
975 if (vcpu->arch.singlestep)
976 svm->vmcb->control.intercept_exceptions |= (1 << DB_VECTOR);
977
972 if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) { 978 if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) {
973 if (vcpu->guest_debug & 979 if (vcpu->guest_debug &
974 (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP)) 980 (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))
@@ -979,6 +985,16 @@ static int svm_guest_debug(struct kvm_vcpu *vcpu, struct kvm_guest_debug *dbg)
979 1 << BP_VECTOR; 985 1 << BP_VECTOR;
980 } else 986 } else
981 vcpu->guest_debug = 0; 987 vcpu->guest_debug = 0;
988}
989
990static int svm_guest_debug(struct kvm_vcpu *vcpu, struct kvm_guest_debug *dbg)
991{
992 int old_debug = vcpu->guest_debug;
993 struct vcpu_svm *svm = to_svm(vcpu);
994
995 vcpu->guest_debug = dbg->control;
996
997 update_db_intercept(vcpu);
982 998
983 if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP) 999 if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)
984 svm->vmcb->save.dr7 = dbg->arch.debugreg[7]; 1000 svm->vmcb->save.dr7 = dbg->arch.debugreg[7];
@@ -993,16 +1009,6 @@ static int svm_guest_debug(struct kvm_vcpu *vcpu, struct kvm_guest_debug *dbg)
993 return 0; 1009 return 0;
994} 1010}
995 1011
996static int svm_get_irq(struct kvm_vcpu *vcpu)
997{
998 struct vcpu_svm *svm = to_svm(vcpu);
999 u32 exit_int_info = svm->vmcb->control.exit_int_info;
1000
1001 if (is_external_interrupt(exit_int_info))
1002 return exit_int_info & SVM_EVTINJ_VEC_MASK;
1003 return -1;
1004}
1005
1006static void load_host_msrs(struct kvm_vcpu *vcpu) 1012static void load_host_msrs(struct kvm_vcpu *vcpu)
1007{ 1013{
1008#ifdef CONFIG_X86_64 1014#ifdef CONFIG_X86_64
@@ -1107,17 +1113,8 @@ static void svm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long value,
1107 1113
1108static int pf_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) 1114static int pf_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
1109{ 1115{
1110 u32 exit_int_info = svm->vmcb->control.exit_int_info;
1111 struct kvm *kvm = svm->vcpu.kvm;
1112 u64 fault_address; 1116 u64 fault_address;
1113 u32 error_code; 1117 u32 error_code;
1114 bool event_injection = false;
1115
1116 if (!irqchip_in_kernel(kvm) &&
1117 is_external_interrupt(exit_int_info)) {
1118 event_injection = true;
1119 push_irq(&svm->vcpu, exit_int_info & SVM_EVTINJ_VEC_MASK);
1120 }
1121 1118
1122 fault_address = svm->vmcb->control.exit_info_2; 1119 fault_address = svm->vmcb->control.exit_info_2;
1123 error_code = svm->vmcb->control.exit_info_1; 1120 error_code = svm->vmcb->control.exit_info_1;
@@ -1137,23 +1134,40 @@ static int pf_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
1137 */ 1134 */
1138 if (npt_enabled) 1135 if (npt_enabled)
1139 svm_flush_tlb(&svm->vcpu); 1136 svm_flush_tlb(&svm->vcpu);
1140 1137 else {
1141 if (!npt_enabled && event_injection) 1138 if (kvm_event_needs_reinjection(&svm->vcpu))
1142 kvm_mmu_unprotect_page_virt(&svm->vcpu, fault_address); 1139 kvm_mmu_unprotect_page_virt(&svm->vcpu, fault_address);
1140 }
1143 return kvm_mmu_page_fault(&svm->vcpu, fault_address, error_code); 1141 return kvm_mmu_page_fault(&svm->vcpu, fault_address, error_code);
1144} 1142}
1145 1143
1146static int db_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) 1144static int db_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
1147{ 1145{
1148 if (!(svm->vcpu.guest_debug & 1146 if (!(svm->vcpu.guest_debug &
1149 (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))) { 1147 (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP)) &&
1148 !svm->vcpu.arch.singlestep) {
1150 kvm_queue_exception(&svm->vcpu, DB_VECTOR); 1149 kvm_queue_exception(&svm->vcpu, DB_VECTOR);
1151 return 1; 1150 return 1;
1152 } 1151 }
1153 kvm_run->exit_reason = KVM_EXIT_DEBUG; 1152
1154 kvm_run->debug.arch.pc = svm->vmcb->save.cs.base + svm->vmcb->save.rip; 1153 if (svm->vcpu.arch.singlestep) {
1155 kvm_run->debug.arch.exception = DB_VECTOR; 1154 svm->vcpu.arch.singlestep = false;
1156 return 0; 1155 if (!(svm->vcpu.guest_debug & KVM_GUESTDBG_SINGLESTEP))
1156 svm->vmcb->save.rflags &=
1157 ~(X86_EFLAGS_TF | X86_EFLAGS_RF);
1158 update_db_intercept(&svm->vcpu);
1159 }
1160
1161 if (svm->vcpu.guest_debug &
1162 (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP)){
1163 kvm_run->exit_reason = KVM_EXIT_DEBUG;
1164 kvm_run->debug.arch.pc =
1165 svm->vmcb->save.cs.base + svm->vmcb->save.rip;
1166 kvm_run->debug.arch.exception = DB_VECTOR;
1167 return 0;
1168 }
1169
1170 return 1;
1157} 1171}
1158 1172
1159static int bp_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) 1173static int bp_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
@@ -1842,17 +1856,51 @@ static int task_switch_interception(struct vcpu_svm *svm,
1842 struct kvm_run *kvm_run) 1856 struct kvm_run *kvm_run)
1843{ 1857{
1844 u16 tss_selector; 1858 u16 tss_selector;
1859 int reason;
1860 int int_type = svm->vmcb->control.exit_int_info &
1861 SVM_EXITINTINFO_TYPE_MASK;
1862 int int_vec = svm->vmcb->control.exit_int_info & SVM_EVTINJ_VEC_MASK;
1863 uint32_t type =
1864 svm->vmcb->control.exit_int_info & SVM_EXITINTINFO_TYPE_MASK;
1865 uint32_t idt_v =
1866 svm->vmcb->control.exit_int_info & SVM_EXITINTINFO_VALID;
1845 1867
1846 tss_selector = (u16)svm->vmcb->control.exit_info_1; 1868 tss_selector = (u16)svm->vmcb->control.exit_info_1;
1869
1847 if (svm->vmcb->control.exit_info_2 & 1870 if (svm->vmcb->control.exit_info_2 &
1848 (1ULL << SVM_EXITINFOSHIFT_TS_REASON_IRET)) 1871 (1ULL << SVM_EXITINFOSHIFT_TS_REASON_IRET))
1849 return kvm_task_switch(&svm->vcpu, tss_selector, 1872 reason = TASK_SWITCH_IRET;
1850 TASK_SWITCH_IRET); 1873 else if (svm->vmcb->control.exit_info_2 &
1851 if (svm->vmcb->control.exit_info_2 & 1874 (1ULL << SVM_EXITINFOSHIFT_TS_REASON_JMP))
1852 (1ULL << SVM_EXITINFOSHIFT_TS_REASON_JMP)) 1875 reason = TASK_SWITCH_JMP;
1853 return kvm_task_switch(&svm->vcpu, tss_selector, 1876 else if (idt_v)
1854 TASK_SWITCH_JMP); 1877 reason = TASK_SWITCH_GATE;
1855 return kvm_task_switch(&svm->vcpu, tss_selector, TASK_SWITCH_CALL); 1878 else
1879 reason = TASK_SWITCH_CALL;
1880
1881 if (reason == TASK_SWITCH_GATE) {
1882 switch (type) {
1883 case SVM_EXITINTINFO_TYPE_NMI:
1884 svm->vcpu.arch.nmi_injected = false;
1885 break;
1886 case SVM_EXITINTINFO_TYPE_EXEPT:
1887 kvm_clear_exception_queue(&svm->vcpu);
1888 break;
1889 case SVM_EXITINTINFO_TYPE_INTR:
1890 kvm_clear_interrupt_queue(&svm->vcpu);
1891 break;
1892 default:
1893 break;
1894 }
1895 }
1896
1897 if (reason != TASK_SWITCH_GATE ||
1898 int_type == SVM_EXITINTINFO_TYPE_SOFT ||
1899 (int_type == SVM_EXITINTINFO_TYPE_EXEPT &&
1900 (int_vec == OF_VECTOR || int_vec == BP_VECTOR)))
1901 skip_emulated_instruction(&svm->vcpu);
1902
1903 return kvm_task_switch(&svm->vcpu, tss_selector, reason);
1856} 1904}
1857 1905
1858static int cpuid_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) 1906static int cpuid_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
@@ -1862,6 +1910,14 @@ static int cpuid_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
1862 return 1; 1910 return 1;
1863} 1911}
1864 1912
1913static int iret_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
1914{
1915 ++svm->vcpu.stat.nmi_window_exits;
1916 svm->vmcb->control.intercept &= ~(1UL << INTERCEPT_IRET);
1917 svm->vcpu.arch.hflags |= HF_IRET_MASK;
1918 return 1;
1919}
1920
1865static int invlpg_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) 1921static int invlpg_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
1866{ 1922{
1867 if (emulate_instruction(&svm->vcpu, kvm_run, 0, 0, 0) != EMULATE_DONE) 1923 if (emulate_instruction(&svm->vcpu, kvm_run, 0, 0, 0) != EMULATE_DONE)
@@ -1879,8 +1935,14 @@ static int emulate_on_interception(struct vcpu_svm *svm,
1879 1935
1880static int cr8_write_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run) 1936static int cr8_write_interception(struct vcpu_svm *svm, struct kvm_run *kvm_run)
1881{ 1937{
1938 u8 cr8_prev = kvm_get_cr8(&svm->vcpu);
1939 /* instruction emulation calls kvm_set_cr8() */
1882 emulate_instruction(&svm->vcpu, NULL, 0, 0, 0); 1940 emulate_instruction(&svm->vcpu, NULL, 0, 0, 0);
1883 if (irqchip_in_kernel(svm->vcpu.kvm)) 1941 if (irqchip_in_kernel(svm->vcpu.kvm)) {
1942 svm->vmcb->control.intercept_cr_write &= ~INTERCEPT_CR8_MASK;
1943 return 1;
1944 }
1945 if (cr8_prev <= kvm_get_cr8(&svm->vcpu))
1884 return 1; 1946 return 1;
1885 kvm_run->exit_reason = KVM_EXIT_SET_TPR; 1947 kvm_run->exit_reason = KVM_EXIT_SET_TPR;
1886 return 0; 1948 return 0;
@@ -2090,8 +2152,9 @@ static int interrupt_window_interception(struct vcpu_svm *svm,
2090 * If the user space waits to inject interrupts, exit as soon as 2152 * If the user space waits to inject interrupts, exit as soon as
2091 * possible 2153 * possible
2092 */ 2154 */
2093 if (kvm_run->request_interrupt_window && 2155 if (!irqchip_in_kernel(svm->vcpu.kvm) &&
2094 !svm->vcpu.arch.irq_summary) { 2156 kvm_run->request_interrupt_window &&
2157 !kvm_cpu_has_interrupt(&svm->vcpu)) {
2095 ++svm->vcpu.stat.irq_window_exits; 2158 ++svm->vcpu.stat.irq_window_exits;
2096 kvm_run->exit_reason = KVM_EXIT_IRQ_WINDOW_OPEN; 2159 kvm_run->exit_reason = KVM_EXIT_IRQ_WINDOW_OPEN;
2097 return 0; 2160 return 0;
@@ -2134,6 +2197,7 @@ static int (*svm_exit_handlers[])(struct vcpu_svm *svm,
2134 [SVM_EXIT_VINTR] = interrupt_window_interception, 2197 [SVM_EXIT_VINTR] = interrupt_window_interception,
2135 /* [SVM_EXIT_CR0_SEL_WRITE] = emulate_on_interception, */ 2198 /* [SVM_EXIT_CR0_SEL_WRITE] = emulate_on_interception, */
2136 [SVM_EXIT_CPUID] = cpuid_interception, 2199 [SVM_EXIT_CPUID] = cpuid_interception,
2200 [SVM_EXIT_IRET] = iret_interception,
2137 [SVM_EXIT_INVD] = emulate_on_interception, 2201 [SVM_EXIT_INVD] = emulate_on_interception,
2138 [SVM_EXIT_HLT] = halt_interception, 2202 [SVM_EXIT_HLT] = halt_interception,
2139 [SVM_EXIT_INVLPG] = invlpg_interception, 2203 [SVM_EXIT_INVLPG] = invlpg_interception,
@@ -2194,7 +2258,6 @@ static int handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
2194 } 2258 }
2195 } 2259 }
2196 2260
2197 kvm_reput_irq(svm);
2198 2261
2199 if (svm->vmcb->control.exit_code == SVM_EXIT_ERR) { 2262 if (svm->vmcb->control.exit_code == SVM_EXIT_ERR) {
2200 kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY; 2263 kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
@@ -2205,7 +2268,7 @@ static int handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
2205 2268
2206 if (is_external_interrupt(svm->vmcb->control.exit_int_info) && 2269 if (is_external_interrupt(svm->vmcb->control.exit_int_info) &&
2207 exit_code != SVM_EXIT_EXCP_BASE + PF_VECTOR && 2270 exit_code != SVM_EXIT_EXCP_BASE + PF_VECTOR &&
2208 exit_code != SVM_EXIT_NPF) 2271 exit_code != SVM_EXIT_NPF && exit_code != SVM_EXIT_TASK_SWITCH)
2209 printk(KERN_ERR "%s: unexpected exit_ini_info 0x%x " 2272 printk(KERN_ERR "%s: unexpected exit_ini_info 0x%x "
2210 "exit_code 0x%x\n", 2273 "exit_code 0x%x\n",
2211 __func__, svm->vmcb->control.exit_int_info, 2274 __func__, svm->vmcb->control.exit_int_info,
@@ -2242,6 +2305,15 @@ static void pre_svm_run(struct vcpu_svm *svm)
2242 new_asid(svm, svm_data); 2305 new_asid(svm, svm_data);
2243} 2306}
2244 2307
2308static void svm_inject_nmi(struct kvm_vcpu *vcpu)
2309{
2310 struct vcpu_svm *svm = to_svm(vcpu);
2311
2312 svm->vmcb->control.event_inj = SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_NMI;
2313 vcpu->arch.hflags |= HF_NMI_MASK;
2314 svm->vmcb->control.intercept |= (1UL << INTERCEPT_IRET);
2315 ++vcpu->stat.nmi_injections;
2316}
2245 2317
2246static inline void svm_inject_irq(struct vcpu_svm *svm, int irq) 2318static inline void svm_inject_irq(struct vcpu_svm *svm, int irq)
2247{ 2319{
@@ -2257,134 +2329,71 @@ static inline void svm_inject_irq(struct vcpu_svm *svm, int irq)
2257 ((/*control->int_vector >> 4*/ 0xf) << V_INTR_PRIO_SHIFT); 2329 ((/*control->int_vector >> 4*/ 0xf) << V_INTR_PRIO_SHIFT);
2258} 2330}
2259 2331
2260static void svm_set_irq(struct kvm_vcpu *vcpu, int irq) 2332static void svm_queue_irq(struct kvm_vcpu *vcpu, unsigned nr)
2261{ 2333{
2262 struct vcpu_svm *svm = to_svm(vcpu); 2334 struct vcpu_svm *svm = to_svm(vcpu);
2263 2335
2264 nested_svm_intr(svm); 2336 svm->vmcb->control.event_inj = nr |
2265 2337 SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_INTR;
2266 svm_inject_irq(svm, irq);
2267} 2338}
2268 2339
2269static void update_cr8_intercept(struct kvm_vcpu *vcpu) 2340static void svm_set_irq(struct kvm_vcpu *vcpu)
2270{ 2341{
2271 struct vcpu_svm *svm = to_svm(vcpu); 2342 struct vcpu_svm *svm = to_svm(vcpu);
2272 struct vmcb *vmcb = svm->vmcb;
2273 int max_irr, tpr;
2274 2343
2275 if (!irqchip_in_kernel(vcpu->kvm) || vcpu->arch.apic->vapic_addr) 2344 nested_svm_intr(svm);
2276 return;
2277 2345
2278 vmcb->control.intercept_cr_write &= ~INTERCEPT_CR8_MASK; 2346 svm_queue_irq(vcpu, vcpu->arch.interrupt.nr);
2347}
2279 2348
2280 max_irr = kvm_lapic_find_highest_irr(vcpu); 2349static void update_cr8_intercept(struct kvm_vcpu *vcpu, int tpr, int irr)
2281 if (max_irr == -1) 2350{
2282 return; 2351 struct vcpu_svm *svm = to_svm(vcpu);
2283 2352
2284 tpr = kvm_lapic_get_cr8(vcpu) << 4; 2353 if (irr == -1)
2354 return;
2285 2355
2286 if (tpr >= (max_irr & 0xf0)) 2356 if (tpr >= irr)
2287 vmcb->control.intercept_cr_write |= INTERCEPT_CR8_MASK; 2357 svm->vmcb->control.intercept_cr_write |= INTERCEPT_CR8_MASK;
2288} 2358}
2289 2359
2290static void svm_intr_assist(struct kvm_vcpu *vcpu) 2360static int svm_nmi_allowed(struct kvm_vcpu *vcpu)
2291{ 2361{
2292 struct vcpu_svm *svm = to_svm(vcpu); 2362 struct vcpu_svm *svm = to_svm(vcpu);
2293 struct vmcb *vmcb = svm->vmcb; 2363 struct vmcb *vmcb = svm->vmcb;
2294 int intr_vector = -1; 2364 return !(vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) &&
2295 2365 !(svm->vcpu.arch.hflags & HF_NMI_MASK);
2296 if ((vmcb->control.exit_int_info & SVM_EVTINJ_VALID) &&
2297 ((vmcb->control.exit_int_info & SVM_EVTINJ_TYPE_MASK) == 0)) {
2298 intr_vector = vmcb->control.exit_int_info &
2299 SVM_EVTINJ_VEC_MASK;
2300 vmcb->control.exit_int_info = 0;
2301 svm_inject_irq(svm, intr_vector);
2302 goto out;
2303 }
2304
2305 if (vmcb->control.int_ctl & V_IRQ_MASK)
2306 goto out;
2307
2308 if (!kvm_cpu_has_interrupt(vcpu))
2309 goto out;
2310
2311 if (nested_svm_intr(svm))
2312 goto out;
2313
2314 if (!(svm->vcpu.arch.hflags & HF_GIF_MASK))
2315 goto out;
2316
2317 if (!(vmcb->save.rflags & X86_EFLAGS_IF) ||
2318 (vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) ||
2319 (vmcb->control.event_inj & SVM_EVTINJ_VALID)) {
2320 /* unable to deliver irq, set pending irq */
2321 svm_set_vintr(svm);
2322 svm_inject_irq(svm, 0x0);
2323 goto out;
2324 }
2325 /* Okay, we can deliver the interrupt: grab it and update PIC state. */
2326 intr_vector = kvm_cpu_get_interrupt(vcpu);
2327 svm_inject_irq(svm, intr_vector);
2328out:
2329 update_cr8_intercept(vcpu);
2330} 2366}
2331 2367
2332static void kvm_reput_irq(struct vcpu_svm *svm) 2368static int svm_interrupt_allowed(struct kvm_vcpu *vcpu)
2333{ 2369{
2334 struct vmcb_control_area *control = &svm->vmcb->control; 2370 struct vcpu_svm *svm = to_svm(vcpu);
2335 2371 struct vmcb *vmcb = svm->vmcb;
2336 if ((control->int_ctl & V_IRQ_MASK) 2372 return (vmcb->save.rflags & X86_EFLAGS_IF) &&
2337 && !irqchip_in_kernel(svm->vcpu.kvm)) { 2373 !(vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK) &&
2338 control->int_ctl &= ~V_IRQ_MASK; 2374 (svm->vcpu.arch.hflags & HF_GIF_MASK);
2339 push_irq(&svm->vcpu, control->int_vector);
2340 }
2341
2342 svm->vcpu.arch.interrupt_window_open =
2343 !(control->int_state & SVM_INTERRUPT_SHADOW_MASK) &&
2344 (svm->vcpu.arch.hflags & HF_GIF_MASK);
2345} 2375}
2346 2376
2347static void svm_do_inject_vector(struct vcpu_svm *svm) 2377static void enable_irq_window(struct kvm_vcpu *vcpu)
2348{ 2378{
2349 struct kvm_vcpu *vcpu = &svm->vcpu; 2379 svm_set_vintr(to_svm(vcpu));
2350 int word_index = __ffs(vcpu->arch.irq_summary); 2380 svm_inject_irq(to_svm(vcpu), 0x0);
2351 int bit_index = __ffs(vcpu->arch.irq_pending[word_index]);
2352 int irq = word_index * BITS_PER_LONG + bit_index;
2353
2354 clear_bit(bit_index, &vcpu->arch.irq_pending[word_index]);
2355 if (!vcpu->arch.irq_pending[word_index])
2356 clear_bit(word_index, &vcpu->arch.irq_summary);
2357 svm_inject_irq(svm, irq);
2358} 2381}
2359 2382
2360static void do_interrupt_requests(struct kvm_vcpu *vcpu, 2383static void enable_nmi_window(struct kvm_vcpu *vcpu)
2361 struct kvm_run *kvm_run)
2362{ 2384{
2363 struct vcpu_svm *svm = to_svm(vcpu); 2385 struct vcpu_svm *svm = to_svm(vcpu);
2364 struct vmcb_control_area *control = &svm->vmcb->control;
2365
2366 if (nested_svm_intr(svm))
2367 return;
2368 2386
2369 svm->vcpu.arch.interrupt_window_open = 2387 if ((svm->vcpu.arch.hflags & (HF_NMI_MASK | HF_IRET_MASK))
2370 (!(control->int_state & SVM_INTERRUPT_SHADOW_MASK) && 2388 == HF_NMI_MASK)
2371 (svm->vmcb->save.rflags & X86_EFLAGS_IF) && 2389 return; /* IRET will cause a vm exit */
2372 (svm->vcpu.arch.hflags & HF_GIF_MASK));
2373 2390
2374 if (svm->vcpu.arch.interrupt_window_open && svm->vcpu.arch.irq_summary) 2391 /* Something prevents NMI from been injected. Single step over
2375 /* 2392 possible problem (IRET or exception injection or interrupt
2376 * If interrupts enabled, and not blocked by sti or mov ss. Good. 2393 shadow) */
2377 */ 2394 vcpu->arch.singlestep = true;
2378 svm_do_inject_vector(svm); 2395 svm->vmcb->save.rflags |= (X86_EFLAGS_TF | X86_EFLAGS_RF);
2379 2396 update_db_intercept(vcpu);
2380 /*
2381 * Interrupts blocked. Wait for unblock.
2382 */
2383 if (!svm->vcpu.arch.interrupt_window_open &&
2384 (svm->vcpu.arch.irq_summary || kvm_run->request_interrupt_window))
2385 svm_set_vintr(svm);
2386 else
2387 svm_clear_vintr(svm);
2388} 2397}
2389 2398
2390static int svm_set_tss_addr(struct kvm *kvm, unsigned int addr) 2399static int svm_set_tss_addr(struct kvm *kvm, unsigned int addr)
@@ -2407,7 +2416,7 @@ static inline void sync_cr8_to_lapic(struct kvm_vcpu *vcpu)
2407 2416
2408 if (!(svm->vmcb->control.intercept_cr_write & INTERCEPT_CR8_MASK)) { 2417 if (!(svm->vmcb->control.intercept_cr_write & INTERCEPT_CR8_MASK)) {
2409 int cr8 = svm->vmcb->control.int_ctl & V_TPR_MASK; 2418 int cr8 = svm->vmcb->control.int_ctl & V_TPR_MASK;
2410 kvm_lapic_set_tpr(vcpu, cr8); 2419 kvm_set_cr8(vcpu, cr8);
2411 } 2420 }
2412} 2421}
2413 2422
@@ -2416,14 +2425,54 @@ static inline void sync_lapic_to_cr8(struct kvm_vcpu *vcpu)
2416 struct vcpu_svm *svm = to_svm(vcpu); 2425 struct vcpu_svm *svm = to_svm(vcpu);
2417 u64 cr8; 2426 u64 cr8;
2418 2427
2419 if (!irqchip_in_kernel(vcpu->kvm))
2420 return;
2421
2422 cr8 = kvm_get_cr8(vcpu); 2428 cr8 = kvm_get_cr8(vcpu);
2423 svm->vmcb->control.int_ctl &= ~V_TPR_MASK; 2429 svm->vmcb->control.int_ctl &= ~V_TPR_MASK;
2424 svm->vmcb->control.int_ctl |= cr8 & V_TPR_MASK; 2430 svm->vmcb->control.int_ctl |= cr8 & V_TPR_MASK;
2425} 2431}
2426 2432
2433static void svm_complete_interrupts(struct vcpu_svm *svm)
2434{
2435 u8 vector;
2436 int type;
2437 u32 exitintinfo = svm->vmcb->control.exit_int_info;
2438
2439 if (svm->vcpu.arch.hflags & HF_IRET_MASK)
2440 svm->vcpu.arch.hflags &= ~(HF_NMI_MASK | HF_IRET_MASK);
2441
2442 svm->vcpu.arch.nmi_injected = false;
2443 kvm_clear_exception_queue(&svm->vcpu);
2444 kvm_clear_interrupt_queue(&svm->vcpu);
2445
2446 if (!(exitintinfo & SVM_EXITINTINFO_VALID))
2447 return;
2448
2449 vector = exitintinfo & SVM_EXITINTINFO_VEC_MASK;
2450 type = exitintinfo & SVM_EXITINTINFO_TYPE_MASK;
2451
2452 switch (type) {
2453 case SVM_EXITINTINFO_TYPE_NMI:
2454 svm->vcpu.arch.nmi_injected = true;
2455 break;
2456 case SVM_EXITINTINFO_TYPE_EXEPT:
2457 /* In case of software exception do not reinject an exception
2458 vector, but re-execute and instruction instead */
2459 if (kvm_exception_is_soft(vector))
2460 break;
2461 if (exitintinfo & SVM_EXITINTINFO_VALID_ERR) {
2462 u32 err = svm->vmcb->control.exit_int_info_err;
2463 kvm_queue_exception_e(&svm->vcpu, vector, err);
2464
2465 } else
2466 kvm_queue_exception(&svm->vcpu, vector);
2467 break;
2468 case SVM_EXITINTINFO_TYPE_INTR:
2469 kvm_queue_interrupt(&svm->vcpu, vector, false);
2470 break;
2471 default:
2472 break;
2473 }
2474}
2475
2427#ifdef CONFIG_X86_64 2476#ifdef CONFIG_X86_64
2428#define R "r" 2477#define R "r"
2429#else 2478#else
@@ -2552,6 +2601,8 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2552 sync_cr8_to_lapic(vcpu); 2601 sync_cr8_to_lapic(vcpu);
2553 2602
2554 svm->next_rip = 0; 2603 svm->next_rip = 0;
2604
2605 svm_complete_interrupts(svm);
2555} 2606}
2556 2607
2557#undef R 2608#undef R
@@ -2617,7 +2668,7 @@ static int get_npt_level(void)
2617#endif 2668#endif
2618} 2669}
2619 2670
2620static int svm_get_mt_mask_shift(void) 2671static u64 svm_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)
2621{ 2672{
2622 return 0; 2673 return 0;
2623} 2674}
@@ -2667,17 +2718,21 @@ static struct kvm_x86_ops svm_x86_ops = {
2667 .run = svm_vcpu_run, 2718 .run = svm_vcpu_run,
2668 .handle_exit = handle_exit, 2719 .handle_exit = handle_exit,
2669 .skip_emulated_instruction = skip_emulated_instruction, 2720 .skip_emulated_instruction = skip_emulated_instruction,
2721 .set_interrupt_shadow = svm_set_interrupt_shadow,
2722 .get_interrupt_shadow = svm_get_interrupt_shadow,
2670 .patch_hypercall = svm_patch_hypercall, 2723 .patch_hypercall = svm_patch_hypercall,
2671 .get_irq = svm_get_irq,
2672 .set_irq = svm_set_irq, 2724 .set_irq = svm_set_irq,
2725 .set_nmi = svm_inject_nmi,
2673 .queue_exception = svm_queue_exception, 2726 .queue_exception = svm_queue_exception,
2674 .exception_injected = svm_exception_injected, 2727 .interrupt_allowed = svm_interrupt_allowed,
2675 .inject_pending_irq = svm_intr_assist, 2728 .nmi_allowed = svm_nmi_allowed,
2676 .inject_pending_vectors = do_interrupt_requests, 2729 .enable_nmi_window = enable_nmi_window,
2730 .enable_irq_window = enable_irq_window,
2731 .update_cr8_intercept = update_cr8_intercept,
2677 2732
2678 .set_tss_addr = svm_set_tss_addr, 2733 .set_tss_addr = svm_set_tss_addr,
2679 .get_tdp_level = get_npt_level, 2734 .get_tdp_level = get_npt_level,
2680 .get_mt_mask_shift = svm_get_mt_mask_shift, 2735 .get_mt_mask = svm_get_mt_mask,
2681}; 2736};
2682 2737
2683static int __init svm_init(void) 2738static int __init svm_init(void)
diff --git a/arch/x86/kvm/timer.c b/arch/x86/kvm/timer.c
new file mode 100644
index 000000000000..86dbac072d0c
--- /dev/null
+++ b/arch/x86/kvm/timer.c
@@ -0,0 +1,46 @@
1#include <linux/kvm_host.h>
2#include <linux/kvm.h>
3#include <linux/hrtimer.h>
4#include <asm/atomic.h>
5#include "kvm_timer.h"
6
7static int __kvm_timer_fn(struct kvm_vcpu *vcpu, struct kvm_timer *ktimer)
8{
9 int restart_timer = 0;
10 wait_queue_head_t *q = &vcpu->wq;
11
12 /* FIXME: this code should not know anything about vcpus */
13 if (!atomic_inc_and_test(&ktimer->pending))
14 set_bit(KVM_REQ_PENDING_TIMER, &vcpu->requests);
15
16 if (!ktimer->reinject)
17 atomic_set(&ktimer->pending, 1);
18
19 if (waitqueue_active(q))
20 wake_up_interruptible(q);
21
22 if (ktimer->t_ops->is_periodic(ktimer)) {
23 hrtimer_add_expires_ns(&ktimer->timer, ktimer->period);
24 restart_timer = 1;
25 }
26
27 return restart_timer;
28}
29
30enum hrtimer_restart kvm_timer_fn(struct hrtimer *data)
31{
32 int restart_timer;
33 struct kvm_vcpu *vcpu;
34 struct kvm_timer *ktimer = container_of(data, struct kvm_timer, timer);
35
36 vcpu = ktimer->kvm->vcpus[ktimer->vcpu_id];
37 if (!vcpu)
38 return HRTIMER_NORESTART;
39
40 restart_timer = __kvm_timer_fn(vcpu, ktimer);
41 if (restart_timer)
42 return HRTIMER_RESTART;
43 else
44 return HRTIMER_NORESTART;
45}
46
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index bb481330716f..32d6ae8fb60e 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -32,26 +32,27 @@
32#include <asm/desc.h> 32#include <asm/desc.h>
33#include <asm/vmx.h> 33#include <asm/vmx.h>
34#include <asm/virtext.h> 34#include <asm/virtext.h>
35#include <asm/mce.h>
35 36
36#define __ex(x) __kvm_handle_fault_on_reboot(x) 37#define __ex(x) __kvm_handle_fault_on_reboot(x)
37 38
38MODULE_AUTHOR("Qumranet"); 39MODULE_AUTHOR("Qumranet");
39MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
40 41
41static int bypass_guest_pf = 1; 42static int __read_mostly bypass_guest_pf = 1;
42module_param(bypass_guest_pf, bool, 0); 43module_param(bypass_guest_pf, bool, S_IRUGO);
43 44
44static int enable_vpid = 1; 45static int __read_mostly enable_vpid = 1;
45module_param(enable_vpid, bool, 0); 46module_param_named(vpid, enable_vpid, bool, 0444);
46 47
47static int flexpriority_enabled = 1; 48static int __read_mostly flexpriority_enabled = 1;
48module_param(flexpriority_enabled, bool, 0); 49module_param_named(flexpriority, flexpriority_enabled, bool, S_IRUGO);
49 50
50static int enable_ept = 1; 51static int __read_mostly enable_ept = 1;
51module_param(enable_ept, bool, 0); 52module_param_named(ept, enable_ept, bool, S_IRUGO);
52 53
53static int emulate_invalid_guest_state = 0; 54static int __read_mostly emulate_invalid_guest_state = 0;
54module_param(emulate_invalid_guest_state, bool, 0); 55module_param(emulate_invalid_guest_state, bool, S_IRUGO);
55 56
56struct vmcs { 57struct vmcs {
57 u32 revision_id; 58 u32 revision_id;
@@ -97,6 +98,7 @@ struct vcpu_vmx {
97 int soft_vnmi_blocked; 98 int soft_vnmi_blocked;
98 ktime_t entry_time; 99 ktime_t entry_time;
99 s64 vnmi_blocked_time; 100 s64 vnmi_blocked_time;
101 u32 exit_reason;
100}; 102};
101 103
102static inline struct vcpu_vmx *to_vmx(struct kvm_vcpu *vcpu) 104static inline struct vcpu_vmx *to_vmx(struct kvm_vcpu *vcpu)
@@ -111,9 +113,10 @@ static DEFINE_PER_CPU(struct vmcs *, vmxarea);
111static DEFINE_PER_CPU(struct vmcs *, current_vmcs); 113static DEFINE_PER_CPU(struct vmcs *, current_vmcs);
112static DEFINE_PER_CPU(struct list_head, vcpus_on_cpu); 114static DEFINE_PER_CPU(struct list_head, vcpus_on_cpu);
113 115
114static struct page *vmx_io_bitmap_a; 116static unsigned long *vmx_io_bitmap_a;
115static struct page *vmx_io_bitmap_b; 117static unsigned long *vmx_io_bitmap_b;
116static struct page *vmx_msr_bitmap; 118static unsigned long *vmx_msr_bitmap_legacy;
119static unsigned long *vmx_msr_bitmap_longmode;
117 120
118static DECLARE_BITMAP(vmx_vpid_bitmap, VMX_NR_VPIDS); 121static DECLARE_BITMAP(vmx_vpid_bitmap, VMX_NR_VPIDS);
119static DEFINE_SPINLOCK(vmx_vpid_lock); 122static DEFINE_SPINLOCK(vmx_vpid_lock);
@@ -213,70 +216,78 @@ static inline int is_external_interrupt(u32 intr_info)
213 == (INTR_TYPE_EXT_INTR | INTR_INFO_VALID_MASK); 216 == (INTR_TYPE_EXT_INTR | INTR_INFO_VALID_MASK);
214} 217}
215 218
219static inline int is_machine_check(u32 intr_info)
220{
221 return (intr_info & (INTR_INFO_INTR_TYPE_MASK | INTR_INFO_VECTOR_MASK |
222 INTR_INFO_VALID_MASK)) ==
223 (INTR_TYPE_HARD_EXCEPTION | MC_VECTOR | INTR_INFO_VALID_MASK);
224}
225
216static inline int cpu_has_vmx_msr_bitmap(void) 226static inline int cpu_has_vmx_msr_bitmap(void)
217{ 227{
218 return (vmcs_config.cpu_based_exec_ctrl & CPU_BASED_USE_MSR_BITMAPS); 228 return vmcs_config.cpu_based_exec_ctrl & CPU_BASED_USE_MSR_BITMAPS;
219} 229}
220 230
221static inline int cpu_has_vmx_tpr_shadow(void) 231static inline int cpu_has_vmx_tpr_shadow(void)
222{ 232{
223 return (vmcs_config.cpu_based_exec_ctrl & CPU_BASED_TPR_SHADOW); 233 return vmcs_config.cpu_based_exec_ctrl & CPU_BASED_TPR_SHADOW;
224} 234}
225 235
226static inline int vm_need_tpr_shadow(struct kvm *kvm) 236static inline int vm_need_tpr_shadow(struct kvm *kvm)
227{ 237{
228 return ((cpu_has_vmx_tpr_shadow()) && (irqchip_in_kernel(kvm))); 238 return (cpu_has_vmx_tpr_shadow()) && (irqchip_in_kernel(kvm));
229} 239}
230 240
231static inline int cpu_has_secondary_exec_ctrls(void) 241static inline int cpu_has_secondary_exec_ctrls(void)
232{ 242{
233 return (vmcs_config.cpu_based_exec_ctrl & 243 return vmcs_config.cpu_based_exec_ctrl &
234 CPU_BASED_ACTIVATE_SECONDARY_CONTROLS); 244 CPU_BASED_ACTIVATE_SECONDARY_CONTROLS;
235} 245}
236 246
237static inline bool cpu_has_vmx_virtualize_apic_accesses(void) 247static inline bool cpu_has_vmx_virtualize_apic_accesses(void)
238{ 248{
239 return flexpriority_enabled 249 return vmcs_config.cpu_based_2nd_exec_ctrl &
240 && (vmcs_config.cpu_based_2nd_exec_ctrl & 250 SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES;
241 SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES); 251}
252
253static inline bool cpu_has_vmx_flexpriority(void)
254{
255 return cpu_has_vmx_tpr_shadow() &&
256 cpu_has_vmx_virtualize_apic_accesses();
242} 257}
243 258
244static inline int cpu_has_vmx_invept_individual_addr(void) 259static inline int cpu_has_vmx_invept_individual_addr(void)
245{ 260{
246 return (!!(vmx_capability.ept & VMX_EPT_EXTENT_INDIVIDUAL_BIT)); 261 return !!(vmx_capability.ept & VMX_EPT_EXTENT_INDIVIDUAL_BIT);
247} 262}
248 263
249static inline int cpu_has_vmx_invept_context(void) 264static inline int cpu_has_vmx_invept_context(void)
250{ 265{
251 return (!!(vmx_capability.ept & VMX_EPT_EXTENT_CONTEXT_BIT)); 266 return !!(vmx_capability.ept & VMX_EPT_EXTENT_CONTEXT_BIT);
252} 267}
253 268
254static inline int cpu_has_vmx_invept_global(void) 269static inline int cpu_has_vmx_invept_global(void)
255{ 270{
256 return (!!(vmx_capability.ept & VMX_EPT_EXTENT_GLOBAL_BIT)); 271 return !!(vmx_capability.ept & VMX_EPT_EXTENT_GLOBAL_BIT);
257} 272}
258 273
259static inline int cpu_has_vmx_ept(void) 274static inline int cpu_has_vmx_ept(void)
260{ 275{
261 return (vmcs_config.cpu_based_2nd_exec_ctrl & 276 return vmcs_config.cpu_based_2nd_exec_ctrl &
262 SECONDARY_EXEC_ENABLE_EPT); 277 SECONDARY_EXEC_ENABLE_EPT;
263}
264
265static inline int vm_need_ept(void)
266{
267 return (cpu_has_vmx_ept() && enable_ept);
268} 278}
269 279
270static inline int vm_need_virtualize_apic_accesses(struct kvm *kvm) 280static inline int vm_need_virtualize_apic_accesses(struct kvm *kvm)
271{ 281{
272 return ((cpu_has_vmx_virtualize_apic_accesses()) && 282 return flexpriority_enabled &&
273 (irqchip_in_kernel(kvm))); 283 (cpu_has_vmx_virtualize_apic_accesses()) &&
284 (irqchip_in_kernel(kvm));
274} 285}
275 286
276static inline int cpu_has_vmx_vpid(void) 287static inline int cpu_has_vmx_vpid(void)
277{ 288{
278 return (vmcs_config.cpu_based_2nd_exec_ctrl & 289 return vmcs_config.cpu_based_2nd_exec_ctrl &
279 SECONDARY_EXEC_ENABLE_VPID); 290 SECONDARY_EXEC_ENABLE_VPID;
280} 291}
281 292
282static inline int cpu_has_virtual_nmis(void) 293static inline int cpu_has_virtual_nmis(void)
@@ -284,6 +295,11 @@ static inline int cpu_has_virtual_nmis(void)
284 return vmcs_config.pin_based_exec_ctrl & PIN_BASED_VIRTUAL_NMIS; 295 return vmcs_config.pin_based_exec_ctrl & PIN_BASED_VIRTUAL_NMIS;
285} 296}
286 297
298static inline bool report_flexpriority(void)
299{
300 return flexpriority_enabled;
301}
302
287static int __find_msr_index(struct vcpu_vmx *vmx, u32 msr) 303static int __find_msr_index(struct vcpu_vmx *vmx, u32 msr)
288{ 304{
289 int i; 305 int i;
@@ -381,7 +397,7 @@ static inline void ept_sync_global(void)
381 397
382static inline void ept_sync_context(u64 eptp) 398static inline void ept_sync_context(u64 eptp)
383{ 399{
384 if (vm_need_ept()) { 400 if (enable_ept) {
385 if (cpu_has_vmx_invept_context()) 401 if (cpu_has_vmx_invept_context())
386 __invept(VMX_EPT_EXTENT_CONTEXT, eptp, 0); 402 __invept(VMX_EPT_EXTENT_CONTEXT, eptp, 0);
387 else 403 else
@@ -391,7 +407,7 @@ static inline void ept_sync_context(u64 eptp)
391 407
392static inline void ept_sync_individual_addr(u64 eptp, gpa_t gpa) 408static inline void ept_sync_individual_addr(u64 eptp, gpa_t gpa)
393{ 409{
394 if (vm_need_ept()) { 410 if (enable_ept) {
395 if (cpu_has_vmx_invept_individual_addr()) 411 if (cpu_has_vmx_invept_individual_addr())
396 __invept(VMX_EPT_EXTENT_INDIVIDUAL_ADDR, 412 __invept(VMX_EPT_EXTENT_INDIVIDUAL_ADDR,
397 eptp, gpa); 413 eptp, gpa);
@@ -478,7 +494,7 @@ static void update_exception_bitmap(struct kvm_vcpu *vcpu)
478{ 494{
479 u32 eb; 495 u32 eb;
480 496
481 eb = (1u << PF_VECTOR) | (1u << UD_VECTOR); 497 eb = (1u << PF_VECTOR) | (1u << UD_VECTOR) | (1u << MC_VECTOR);
482 if (!vcpu->fpu_active) 498 if (!vcpu->fpu_active)
483 eb |= 1u << NM_VECTOR; 499 eb |= 1u << NM_VECTOR;
484 if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) { 500 if (vcpu->guest_debug & KVM_GUESTDBG_ENABLE) {
@@ -488,9 +504,9 @@ static void update_exception_bitmap(struct kvm_vcpu *vcpu)
488 if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP) 504 if (vcpu->guest_debug & KVM_GUESTDBG_USE_SW_BP)
489 eb |= 1u << BP_VECTOR; 505 eb |= 1u << BP_VECTOR;
490 } 506 }
491 if (vcpu->arch.rmode.active) 507 if (vcpu->arch.rmode.vm86_active)
492 eb = ~0; 508 eb = ~0;
493 if (vm_need_ept()) 509 if (enable_ept)
494 eb &= ~(1u << PF_VECTOR); /* bypass_guest_pf = 0 */ 510 eb &= ~(1u << PF_VECTOR); /* bypass_guest_pf = 0 */
495 vmcs_write32(EXCEPTION_BITMAP, eb); 511 vmcs_write32(EXCEPTION_BITMAP, eb);
496} 512}
@@ -724,29 +740,50 @@ static unsigned long vmx_get_rflags(struct kvm_vcpu *vcpu)
724 740
725static void vmx_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags) 741static void vmx_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags)
726{ 742{
727 if (vcpu->arch.rmode.active) 743 if (vcpu->arch.rmode.vm86_active)
728 rflags |= X86_EFLAGS_IOPL | X86_EFLAGS_VM; 744 rflags |= X86_EFLAGS_IOPL | X86_EFLAGS_VM;
729 vmcs_writel(GUEST_RFLAGS, rflags); 745 vmcs_writel(GUEST_RFLAGS, rflags);
730} 746}
731 747
748static u32 vmx_get_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)
749{
750 u32 interruptibility = vmcs_read32(GUEST_INTERRUPTIBILITY_INFO);
751 int ret = 0;
752
753 if (interruptibility & GUEST_INTR_STATE_STI)
754 ret |= X86_SHADOW_INT_STI;
755 if (interruptibility & GUEST_INTR_STATE_MOV_SS)
756 ret |= X86_SHADOW_INT_MOV_SS;
757
758 return ret & mask;
759}
760
761static void vmx_set_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)
762{
763 u32 interruptibility_old = vmcs_read32(GUEST_INTERRUPTIBILITY_INFO);
764 u32 interruptibility = interruptibility_old;
765
766 interruptibility &= ~(GUEST_INTR_STATE_STI | GUEST_INTR_STATE_MOV_SS);
767
768 if (mask & X86_SHADOW_INT_MOV_SS)
769 interruptibility |= GUEST_INTR_STATE_MOV_SS;
770 if (mask & X86_SHADOW_INT_STI)
771 interruptibility |= GUEST_INTR_STATE_STI;
772
773 if ((interruptibility != interruptibility_old))
774 vmcs_write32(GUEST_INTERRUPTIBILITY_INFO, interruptibility);
775}
776
732static void skip_emulated_instruction(struct kvm_vcpu *vcpu) 777static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
733{ 778{
734 unsigned long rip; 779 unsigned long rip;
735 u32 interruptibility;
736 780
737 rip = kvm_rip_read(vcpu); 781 rip = kvm_rip_read(vcpu);
738 rip += vmcs_read32(VM_EXIT_INSTRUCTION_LEN); 782 rip += vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
739 kvm_rip_write(vcpu, rip); 783 kvm_rip_write(vcpu, rip);
740 784
741 /* 785 /* skipping an emulated instruction also counts */
742 * We emulated an instruction, so temporary interrupt blocking 786 vmx_set_interrupt_shadow(vcpu, 0);
743 * should be removed, if set.
744 */
745 interruptibility = vmcs_read32(GUEST_INTERRUPTIBILITY_INFO);
746 if (interruptibility & 3)
747 vmcs_write32(GUEST_INTERRUPTIBILITY_INFO,
748 interruptibility & ~3);
749 vcpu->arch.interrupt_window_open = 1;
750} 787}
751 788
752static void vmx_queue_exception(struct kvm_vcpu *vcpu, unsigned nr, 789static void vmx_queue_exception(struct kvm_vcpu *vcpu, unsigned nr,
@@ -760,7 +797,7 @@ static void vmx_queue_exception(struct kvm_vcpu *vcpu, unsigned nr,
760 intr_info |= INTR_INFO_DELIVER_CODE_MASK; 797 intr_info |= INTR_INFO_DELIVER_CODE_MASK;
761 } 798 }
762 799
763 if (vcpu->arch.rmode.active) { 800 if (vcpu->arch.rmode.vm86_active) {
764 vmx->rmode.irq.pending = true; 801 vmx->rmode.irq.pending = true;
765 vmx->rmode.irq.vector = nr; 802 vmx->rmode.irq.vector = nr;
766 vmx->rmode.irq.rip = kvm_rip_read(vcpu); 803 vmx->rmode.irq.rip = kvm_rip_read(vcpu);
@@ -773,8 +810,9 @@ static void vmx_queue_exception(struct kvm_vcpu *vcpu, unsigned nr,
773 return; 810 return;
774 } 811 }
775 812
776 if (nr == BP_VECTOR || nr == OF_VECTOR) { 813 if (kvm_exception_is_soft(nr)) {
777 vmcs_write32(VM_ENTRY_INSTRUCTION_LEN, 1); 814 vmcs_write32(VM_ENTRY_INSTRUCTION_LEN,
815 vmx->vcpu.arch.event_exit_inst_len);
778 intr_info |= INTR_TYPE_SOFT_EXCEPTION; 816 intr_info |= INTR_TYPE_SOFT_EXCEPTION;
779 } else 817 } else
780 intr_info |= INTR_TYPE_HARD_EXCEPTION; 818 intr_info |= INTR_TYPE_HARD_EXCEPTION;
@@ -782,11 +820,6 @@ static void vmx_queue_exception(struct kvm_vcpu *vcpu, unsigned nr,
782 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, intr_info); 820 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, intr_info);
783} 821}
784 822
785static bool vmx_exception_injected(struct kvm_vcpu *vcpu)
786{
787 return false;
788}
789
790/* 823/*
791 * Swap MSR entry in host/guest MSR entry array. 824 * Swap MSR entry in host/guest MSR entry array.
792 */ 825 */
@@ -812,6 +845,7 @@ static void move_msr_up(struct vcpu_vmx *vmx, int from, int to)
812static void setup_msrs(struct vcpu_vmx *vmx) 845static void setup_msrs(struct vcpu_vmx *vmx)
813{ 846{
814 int save_nmsrs; 847 int save_nmsrs;
848 unsigned long *msr_bitmap;
815 849
816 vmx_load_host_state(vmx); 850 vmx_load_host_state(vmx);
817 save_nmsrs = 0; 851 save_nmsrs = 0;
@@ -847,6 +881,15 @@ static void setup_msrs(struct vcpu_vmx *vmx)
847 __find_msr_index(vmx, MSR_KERNEL_GS_BASE); 881 __find_msr_index(vmx, MSR_KERNEL_GS_BASE);
848#endif 882#endif
849 vmx->msr_offset_efer = __find_msr_index(vmx, MSR_EFER); 883 vmx->msr_offset_efer = __find_msr_index(vmx, MSR_EFER);
884
885 if (cpu_has_vmx_msr_bitmap()) {
886 if (is_long_mode(&vmx->vcpu))
887 msr_bitmap = vmx_msr_bitmap_longmode;
888 else
889 msr_bitmap = vmx_msr_bitmap_legacy;
890
891 vmcs_write64(MSR_BITMAP, __pa(msr_bitmap));
892 }
850} 893}
851 894
852/* 895/*
@@ -1034,13 +1077,6 @@ static int set_guest_debug(struct kvm_vcpu *vcpu, struct kvm_guest_debug *dbg)
1034 return 0; 1077 return 0;
1035} 1078}
1036 1079
1037static int vmx_get_irq(struct kvm_vcpu *vcpu)
1038{
1039 if (!vcpu->arch.interrupt.pending)
1040 return -1;
1041 return vcpu->arch.interrupt.nr;
1042}
1043
1044static __init int cpu_has_kvm_support(void) 1080static __init int cpu_has_kvm_support(void)
1045{ 1081{
1046 return cpu_has_vmx(); 1082 return cpu_has_vmx();
@@ -1294,6 +1330,18 @@ static __init int hardware_setup(void)
1294 if (boot_cpu_has(X86_FEATURE_NX)) 1330 if (boot_cpu_has(X86_FEATURE_NX))
1295 kvm_enable_efer_bits(EFER_NX); 1331 kvm_enable_efer_bits(EFER_NX);
1296 1332
1333 if (!cpu_has_vmx_vpid())
1334 enable_vpid = 0;
1335
1336 if (!cpu_has_vmx_ept())
1337 enable_ept = 0;
1338
1339 if (!cpu_has_vmx_flexpriority())
1340 flexpriority_enabled = 0;
1341
1342 if (!cpu_has_vmx_tpr_shadow())
1343 kvm_x86_ops->update_cr8_intercept = NULL;
1344
1297 return alloc_kvm_area(); 1345 return alloc_kvm_area();
1298} 1346}
1299 1347
@@ -1324,7 +1372,7 @@ static void enter_pmode(struct kvm_vcpu *vcpu)
1324 struct vcpu_vmx *vmx = to_vmx(vcpu); 1372 struct vcpu_vmx *vmx = to_vmx(vcpu);
1325 1373
1326 vmx->emulation_required = 1; 1374 vmx->emulation_required = 1;
1327 vcpu->arch.rmode.active = 0; 1375 vcpu->arch.rmode.vm86_active = 0;
1328 1376
1329 vmcs_writel(GUEST_TR_BASE, vcpu->arch.rmode.tr.base); 1377 vmcs_writel(GUEST_TR_BASE, vcpu->arch.rmode.tr.base);
1330 vmcs_write32(GUEST_TR_LIMIT, vcpu->arch.rmode.tr.limit); 1378 vmcs_write32(GUEST_TR_LIMIT, vcpu->arch.rmode.tr.limit);
@@ -1386,7 +1434,7 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
1386 struct vcpu_vmx *vmx = to_vmx(vcpu); 1434 struct vcpu_vmx *vmx = to_vmx(vcpu);
1387 1435
1388 vmx->emulation_required = 1; 1436 vmx->emulation_required = 1;
1389 vcpu->arch.rmode.active = 1; 1437 vcpu->arch.rmode.vm86_active = 1;
1390 1438
1391 vcpu->arch.rmode.tr.base = vmcs_readl(GUEST_TR_BASE); 1439 vcpu->arch.rmode.tr.base = vmcs_readl(GUEST_TR_BASE);
1392 vmcs_writel(GUEST_TR_BASE, rmode_tss_base(vcpu->kvm)); 1440 vmcs_writel(GUEST_TR_BASE, rmode_tss_base(vcpu->kvm));
@@ -1485,7 +1533,7 @@ static void exit_lmode(struct kvm_vcpu *vcpu)
1485static void vmx_flush_tlb(struct kvm_vcpu *vcpu) 1533static void vmx_flush_tlb(struct kvm_vcpu *vcpu)
1486{ 1534{
1487 vpid_sync_vcpu_all(to_vmx(vcpu)); 1535 vpid_sync_vcpu_all(to_vmx(vcpu));
1488 if (vm_need_ept()) 1536 if (enable_ept)
1489 ept_sync_context(construct_eptp(vcpu->arch.mmu.root_hpa)); 1537 ept_sync_context(construct_eptp(vcpu->arch.mmu.root_hpa));
1490} 1538}
1491 1539
@@ -1555,10 +1603,10 @@ static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
1555 1603
1556 vmx_fpu_deactivate(vcpu); 1604 vmx_fpu_deactivate(vcpu);
1557 1605
1558 if (vcpu->arch.rmode.active && (cr0 & X86_CR0_PE)) 1606 if (vcpu->arch.rmode.vm86_active && (cr0 & X86_CR0_PE))
1559 enter_pmode(vcpu); 1607 enter_pmode(vcpu);
1560 1608
1561 if (!vcpu->arch.rmode.active && !(cr0 & X86_CR0_PE)) 1609 if (!vcpu->arch.rmode.vm86_active && !(cr0 & X86_CR0_PE))
1562 enter_rmode(vcpu); 1610 enter_rmode(vcpu);
1563 1611
1564#ifdef CONFIG_X86_64 1612#ifdef CONFIG_X86_64
@@ -1570,7 +1618,7 @@ static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
1570 } 1618 }
1571#endif 1619#endif
1572 1620
1573 if (vm_need_ept()) 1621 if (enable_ept)
1574 ept_update_paging_mode_cr0(&hw_cr0, cr0, vcpu); 1622 ept_update_paging_mode_cr0(&hw_cr0, cr0, vcpu);
1575 1623
1576 vmcs_writel(CR0_READ_SHADOW, cr0); 1624 vmcs_writel(CR0_READ_SHADOW, cr0);
@@ -1599,7 +1647,7 @@ static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
1599 u64 eptp; 1647 u64 eptp;
1600 1648
1601 guest_cr3 = cr3; 1649 guest_cr3 = cr3;
1602 if (vm_need_ept()) { 1650 if (enable_ept) {
1603 eptp = construct_eptp(cr3); 1651 eptp = construct_eptp(cr3);
1604 vmcs_write64(EPT_POINTER, eptp); 1652 vmcs_write64(EPT_POINTER, eptp);
1605 ept_sync_context(eptp); 1653 ept_sync_context(eptp);
@@ -1616,11 +1664,11 @@ static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3)
1616 1664
1617static void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) 1665static void vmx_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
1618{ 1666{
1619 unsigned long hw_cr4 = cr4 | (vcpu->arch.rmode.active ? 1667 unsigned long hw_cr4 = cr4 | (vcpu->arch.rmode.vm86_active ?
1620 KVM_RMODE_VM_CR4_ALWAYS_ON : KVM_PMODE_VM_CR4_ALWAYS_ON); 1668 KVM_RMODE_VM_CR4_ALWAYS_ON : KVM_PMODE_VM_CR4_ALWAYS_ON);
1621 1669
1622 vcpu->arch.cr4 = cr4; 1670 vcpu->arch.cr4 = cr4;
1623 if (vm_need_ept()) 1671 if (enable_ept)
1624 ept_update_paging_mode_cr4(&hw_cr4, vcpu); 1672 ept_update_paging_mode_cr4(&hw_cr4, vcpu);
1625 1673
1626 vmcs_writel(CR4_READ_SHADOW, cr4); 1674 vmcs_writel(CR4_READ_SHADOW, cr4);
@@ -1699,7 +1747,7 @@ static void vmx_set_segment(struct kvm_vcpu *vcpu,
1699 struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg]; 1747 struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
1700 u32 ar; 1748 u32 ar;
1701 1749
1702 if (vcpu->arch.rmode.active && seg == VCPU_SREG_TR) { 1750 if (vcpu->arch.rmode.vm86_active && seg == VCPU_SREG_TR) {
1703 vcpu->arch.rmode.tr.selector = var->selector; 1751 vcpu->arch.rmode.tr.selector = var->selector;
1704 vcpu->arch.rmode.tr.base = var->base; 1752 vcpu->arch.rmode.tr.base = var->base;
1705 vcpu->arch.rmode.tr.limit = var->limit; 1753 vcpu->arch.rmode.tr.limit = var->limit;
@@ -1709,7 +1757,7 @@ static void vmx_set_segment(struct kvm_vcpu *vcpu,
1709 vmcs_writel(sf->base, var->base); 1757 vmcs_writel(sf->base, var->base);
1710 vmcs_write32(sf->limit, var->limit); 1758 vmcs_write32(sf->limit, var->limit);
1711 vmcs_write16(sf->selector, var->selector); 1759 vmcs_write16(sf->selector, var->selector);
1712 if (vcpu->arch.rmode.active && var->s) { 1760 if (vcpu->arch.rmode.vm86_active && var->s) {
1713 /* 1761 /*
1714 * Hack real-mode segments into vm86 compatibility. 1762 * Hack real-mode segments into vm86 compatibility.
1715 */ 1763 */
@@ -1982,7 +2030,7 @@ static int init_rmode_identity_map(struct kvm *kvm)
1982 pfn_t identity_map_pfn; 2030 pfn_t identity_map_pfn;
1983 u32 tmp; 2031 u32 tmp;
1984 2032
1985 if (!vm_need_ept()) 2033 if (!enable_ept)
1986 return 1; 2034 return 1;
1987 if (unlikely(!kvm->arch.ept_identity_pagetable)) { 2035 if (unlikely(!kvm->arch.ept_identity_pagetable)) {
1988 printk(KERN_ERR "EPT: identity-mapping pagetable " 2036 printk(KERN_ERR "EPT: identity-mapping pagetable "
@@ -2071,7 +2119,7 @@ static void allocate_vpid(struct vcpu_vmx *vmx)
2071 int vpid; 2119 int vpid;
2072 2120
2073 vmx->vpid = 0; 2121 vmx->vpid = 0;
2074 if (!enable_vpid || !cpu_has_vmx_vpid()) 2122 if (!enable_vpid)
2075 return; 2123 return;
2076 spin_lock(&vmx_vpid_lock); 2124 spin_lock(&vmx_vpid_lock);
2077 vpid = find_first_zero_bit(vmx_vpid_bitmap, VMX_NR_VPIDS); 2125 vpid = find_first_zero_bit(vmx_vpid_bitmap, VMX_NR_VPIDS);
@@ -2082,9 +2130,9 @@ static void allocate_vpid(struct vcpu_vmx *vmx)
2082 spin_unlock(&vmx_vpid_lock); 2130 spin_unlock(&vmx_vpid_lock);
2083} 2131}
2084 2132
2085static void vmx_disable_intercept_for_msr(struct page *msr_bitmap, u32 msr) 2133static void __vmx_disable_intercept_for_msr(unsigned long *msr_bitmap, u32 msr)
2086{ 2134{
2087 void *va; 2135 int f = sizeof(unsigned long);
2088 2136
2089 if (!cpu_has_vmx_msr_bitmap()) 2137 if (!cpu_has_vmx_msr_bitmap())
2090 return; 2138 return;
@@ -2094,16 +2142,21 @@ static void vmx_disable_intercept_for_msr(struct page *msr_bitmap, u32 msr)
2094 * have the write-low and read-high bitmap offsets the wrong way round. 2142 * have the write-low and read-high bitmap offsets the wrong way round.
2095 * We can control MSRs 0x00000000-0x00001fff and 0xc0000000-0xc0001fff. 2143 * We can control MSRs 0x00000000-0x00001fff and 0xc0000000-0xc0001fff.
2096 */ 2144 */
2097 va = kmap(msr_bitmap);
2098 if (msr <= 0x1fff) { 2145 if (msr <= 0x1fff) {
2099 __clear_bit(msr, va + 0x000); /* read-low */ 2146 __clear_bit(msr, msr_bitmap + 0x000 / f); /* read-low */
2100 __clear_bit(msr, va + 0x800); /* write-low */ 2147 __clear_bit(msr, msr_bitmap + 0x800 / f); /* write-low */
2101 } else if ((msr >= 0xc0000000) && (msr <= 0xc0001fff)) { 2148 } else if ((msr >= 0xc0000000) && (msr <= 0xc0001fff)) {
2102 msr &= 0x1fff; 2149 msr &= 0x1fff;
2103 __clear_bit(msr, va + 0x400); /* read-high */ 2150 __clear_bit(msr, msr_bitmap + 0x400 / f); /* read-high */
2104 __clear_bit(msr, va + 0xc00); /* write-high */ 2151 __clear_bit(msr, msr_bitmap + 0xc00 / f); /* write-high */
2105 } 2152 }
2106 kunmap(msr_bitmap); 2153}
2154
2155static void vmx_disable_intercept_for_msr(u32 msr, bool longmode_only)
2156{
2157 if (!longmode_only)
2158 __vmx_disable_intercept_for_msr(vmx_msr_bitmap_legacy, msr);
2159 __vmx_disable_intercept_for_msr(vmx_msr_bitmap_longmode, msr);
2107} 2160}
2108 2161
2109/* 2162/*
@@ -2121,11 +2174,11 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
2121 u32 exec_control; 2174 u32 exec_control;
2122 2175
2123 /* I/O */ 2176 /* I/O */
2124 vmcs_write64(IO_BITMAP_A, page_to_phys(vmx_io_bitmap_a)); 2177 vmcs_write64(IO_BITMAP_A, __pa(vmx_io_bitmap_a));
2125 vmcs_write64(IO_BITMAP_B, page_to_phys(vmx_io_bitmap_b)); 2178 vmcs_write64(IO_BITMAP_B, __pa(vmx_io_bitmap_b));
2126 2179
2127 if (cpu_has_vmx_msr_bitmap()) 2180 if (cpu_has_vmx_msr_bitmap())
2128 vmcs_write64(MSR_BITMAP, page_to_phys(vmx_msr_bitmap)); 2181 vmcs_write64(MSR_BITMAP, __pa(vmx_msr_bitmap_legacy));
2129 2182
2130 vmcs_write64(VMCS_LINK_POINTER, -1ull); /* 22.3.1.5 */ 2183 vmcs_write64(VMCS_LINK_POINTER, -1ull); /* 22.3.1.5 */
2131 2184
@@ -2141,7 +2194,7 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
2141 CPU_BASED_CR8_LOAD_EXITING; 2194 CPU_BASED_CR8_LOAD_EXITING;
2142#endif 2195#endif
2143 } 2196 }
2144 if (!vm_need_ept()) 2197 if (!enable_ept)
2145 exec_control |= CPU_BASED_CR3_STORE_EXITING | 2198 exec_control |= CPU_BASED_CR3_STORE_EXITING |
2146 CPU_BASED_CR3_LOAD_EXITING | 2199 CPU_BASED_CR3_LOAD_EXITING |
2147 CPU_BASED_INVLPG_EXITING; 2200 CPU_BASED_INVLPG_EXITING;
@@ -2154,7 +2207,7 @@ static int vmx_vcpu_setup(struct vcpu_vmx *vmx)
2154 ~SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES; 2207 ~SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES;
2155 if (vmx->vpid == 0) 2208 if (vmx->vpid == 0)
2156 exec_control &= ~SECONDARY_EXEC_ENABLE_VPID; 2209 exec_control &= ~SECONDARY_EXEC_ENABLE_VPID;
2157 if (!vm_need_ept()) 2210 if (!enable_ept)
2158 exec_control &= ~SECONDARY_EXEC_ENABLE_EPT; 2211 exec_control &= ~SECONDARY_EXEC_ENABLE_EPT;
2159 vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control); 2212 vmcs_write32(SECONDARY_VM_EXEC_CONTROL, exec_control);
2160 } 2213 }
@@ -2273,7 +2326,7 @@ static int vmx_vcpu_reset(struct kvm_vcpu *vcpu)
2273 goto out; 2326 goto out;
2274 } 2327 }
2275 2328
2276 vmx->vcpu.arch.rmode.active = 0; 2329 vmx->vcpu.arch.rmode.vm86_active = 0;
2277 2330
2278 vmx->soft_vnmi_blocked = 0; 2331 vmx->soft_vnmi_blocked = 0;
2279 2332
@@ -2402,14 +2455,16 @@ static void enable_nmi_window(struct kvm_vcpu *vcpu)
2402 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control); 2455 vmcs_write32(CPU_BASED_VM_EXEC_CONTROL, cpu_based_vm_exec_control);
2403} 2456}
2404 2457
2405static void vmx_inject_irq(struct kvm_vcpu *vcpu, int irq) 2458static void vmx_inject_irq(struct kvm_vcpu *vcpu)
2406{ 2459{
2407 struct vcpu_vmx *vmx = to_vmx(vcpu); 2460 struct vcpu_vmx *vmx = to_vmx(vcpu);
2461 uint32_t intr;
2462 int irq = vcpu->arch.interrupt.nr;
2408 2463
2409 KVMTRACE_1D(INJ_VIRQ, vcpu, (u32)irq, handler); 2464 KVMTRACE_1D(INJ_VIRQ, vcpu, (u32)irq, handler);
2410 2465
2411 ++vcpu->stat.irq_injections; 2466 ++vcpu->stat.irq_injections;
2412 if (vcpu->arch.rmode.active) { 2467 if (vcpu->arch.rmode.vm86_active) {
2413 vmx->rmode.irq.pending = true; 2468 vmx->rmode.irq.pending = true;
2414 vmx->rmode.irq.vector = irq; 2469 vmx->rmode.irq.vector = irq;
2415 vmx->rmode.irq.rip = kvm_rip_read(vcpu); 2470 vmx->rmode.irq.rip = kvm_rip_read(vcpu);
@@ -2419,8 +2474,14 @@ static void vmx_inject_irq(struct kvm_vcpu *vcpu, int irq)
2419 kvm_rip_write(vcpu, vmx->rmode.irq.rip - 1); 2474 kvm_rip_write(vcpu, vmx->rmode.irq.rip - 1);
2420 return; 2475 return;
2421 } 2476 }
2422 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, 2477 intr = irq | INTR_INFO_VALID_MASK;
2423 irq | INTR_TYPE_EXT_INTR | INTR_INFO_VALID_MASK); 2478 if (vcpu->arch.interrupt.soft) {
2479 intr |= INTR_TYPE_SOFT_INTR;
2480 vmcs_write32(VM_ENTRY_INSTRUCTION_LEN,
2481 vmx->vcpu.arch.event_exit_inst_len);
2482 } else
2483 intr |= INTR_TYPE_EXT_INTR;
2484 vmcs_write32(VM_ENTRY_INTR_INFO_FIELD, intr);
2424} 2485}
2425 2486
2426static void vmx_inject_nmi(struct kvm_vcpu *vcpu) 2487static void vmx_inject_nmi(struct kvm_vcpu *vcpu)
@@ -2441,7 +2502,7 @@ static void vmx_inject_nmi(struct kvm_vcpu *vcpu)
2441 } 2502 }
2442 2503
2443 ++vcpu->stat.nmi_injections; 2504 ++vcpu->stat.nmi_injections;
2444 if (vcpu->arch.rmode.active) { 2505 if (vcpu->arch.rmode.vm86_active) {
2445 vmx->rmode.irq.pending = true; 2506 vmx->rmode.irq.pending = true;
2446 vmx->rmode.irq.vector = NMI_VECTOR; 2507 vmx->rmode.irq.vector = NMI_VECTOR;
2447 vmx->rmode.irq.rip = kvm_rip_read(vcpu); 2508 vmx->rmode.irq.rip = kvm_rip_read(vcpu);
@@ -2456,76 +2517,21 @@ static void vmx_inject_nmi(struct kvm_vcpu *vcpu)
2456 INTR_TYPE_NMI_INTR | INTR_INFO_VALID_MASK | NMI_VECTOR); 2517 INTR_TYPE_NMI_INTR | INTR_INFO_VALID_MASK | NMI_VECTOR);
2457} 2518}
2458 2519
2459static void vmx_update_window_states(struct kvm_vcpu *vcpu) 2520static int vmx_nmi_allowed(struct kvm_vcpu *vcpu)
2460{ 2521{
2461 u32 guest_intr = vmcs_read32(GUEST_INTERRUPTIBILITY_INFO);
2462
2463 vcpu->arch.nmi_window_open =
2464 !(guest_intr & (GUEST_INTR_STATE_STI |
2465 GUEST_INTR_STATE_MOV_SS |
2466 GUEST_INTR_STATE_NMI));
2467 if (!cpu_has_virtual_nmis() && to_vmx(vcpu)->soft_vnmi_blocked) 2522 if (!cpu_has_virtual_nmis() && to_vmx(vcpu)->soft_vnmi_blocked)
2468 vcpu->arch.nmi_window_open = 0; 2523 return 0;
2469
2470 vcpu->arch.interrupt_window_open =
2471 ((vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_IF) &&
2472 !(guest_intr & (GUEST_INTR_STATE_STI |
2473 GUEST_INTR_STATE_MOV_SS)));
2474}
2475
2476static void kvm_do_inject_irq(struct kvm_vcpu *vcpu)
2477{
2478 int word_index = __ffs(vcpu->arch.irq_summary);
2479 int bit_index = __ffs(vcpu->arch.irq_pending[word_index]);
2480 int irq = word_index * BITS_PER_LONG + bit_index;
2481 2524
2482 clear_bit(bit_index, &vcpu->arch.irq_pending[word_index]); 2525 return !(vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) &
2483 if (!vcpu->arch.irq_pending[word_index]) 2526 (GUEST_INTR_STATE_STI | GUEST_INTR_STATE_MOV_SS |
2484 clear_bit(word_index, &vcpu->arch.irq_summary); 2527 GUEST_INTR_STATE_NMI));
2485 kvm_queue_interrupt(vcpu, irq);
2486} 2528}
2487 2529
2488static void do_interrupt_requests(struct kvm_vcpu *vcpu, 2530static int vmx_interrupt_allowed(struct kvm_vcpu *vcpu)
2489 struct kvm_run *kvm_run)
2490{ 2531{
2491 vmx_update_window_states(vcpu); 2532 return (vmcs_readl(GUEST_RFLAGS) & X86_EFLAGS_IF) &&
2492 2533 !(vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) &
2493 if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP) 2534 (GUEST_INTR_STATE_STI | GUEST_INTR_STATE_MOV_SS));
2494 vmcs_clear_bits(GUEST_INTERRUPTIBILITY_INFO,
2495 GUEST_INTR_STATE_STI |
2496 GUEST_INTR_STATE_MOV_SS);
2497
2498 if (vcpu->arch.nmi_pending && !vcpu->arch.nmi_injected) {
2499 if (vcpu->arch.interrupt.pending) {
2500 enable_nmi_window(vcpu);
2501 } else if (vcpu->arch.nmi_window_open) {
2502 vcpu->arch.nmi_pending = false;
2503 vcpu->arch.nmi_injected = true;
2504 } else {
2505 enable_nmi_window(vcpu);
2506 return;
2507 }
2508 }
2509 if (vcpu->arch.nmi_injected) {
2510 vmx_inject_nmi(vcpu);
2511 if (vcpu->arch.nmi_pending)
2512 enable_nmi_window(vcpu);
2513 else if (vcpu->arch.irq_summary
2514 || kvm_run->request_interrupt_window)
2515 enable_irq_window(vcpu);
2516 return;
2517 }
2518
2519 if (vcpu->arch.interrupt_window_open) {
2520 if (vcpu->arch.irq_summary && !vcpu->arch.interrupt.pending)
2521 kvm_do_inject_irq(vcpu);
2522
2523 if (vcpu->arch.interrupt.pending)
2524 vmx_inject_irq(vcpu, vcpu->arch.interrupt.nr);
2525 }
2526 if (!vcpu->arch.interrupt_window_open &&
2527 (vcpu->arch.irq_summary || kvm_run->request_interrupt_window))
2528 enable_irq_window(vcpu);
2529} 2535}
2530 2536
2531static int vmx_set_tss_addr(struct kvm *kvm, unsigned int addr) 2537static int vmx_set_tss_addr(struct kvm *kvm, unsigned int addr)
@@ -2585,6 +2591,31 @@ static int handle_rmode_exception(struct kvm_vcpu *vcpu,
2585 return 0; 2591 return 0;
2586} 2592}
2587 2593
2594/*
2595 * Trigger machine check on the host. We assume all the MSRs are already set up
2596 * by the CPU and that we still run on the same CPU as the MCE occurred on.
2597 * We pass a fake environment to the machine check handler because we want
2598 * the guest to be always treated like user space, no matter what context
2599 * it used internally.
2600 */
2601static void kvm_machine_check(void)
2602{
2603#if defined(CONFIG_X86_MCE) && defined(CONFIG_X86_64)
2604 struct pt_regs regs = {
2605 .cs = 3, /* Fake ring 3 no matter what the guest ran on */
2606 .flags = X86_EFLAGS_IF,
2607 };
2608
2609 do_machine_check(&regs, 0);
2610#endif
2611}
2612
2613static int handle_machine_check(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2614{
2615 /* already handled by vcpu_run */
2616 return 1;
2617}
2618
2588static int handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 2619static int handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2589{ 2620{
2590 struct vcpu_vmx *vmx = to_vmx(vcpu); 2621 struct vcpu_vmx *vmx = to_vmx(vcpu);
@@ -2596,17 +2627,14 @@ static int handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2596 vect_info = vmx->idt_vectoring_info; 2627 vect_info = vmx->idt_vectoring_info;
2597 intr_info = vmcs_read32(VM_EXIT_INTR_INFO); 2628 intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
2598 2629
2630 if (is_machine_check(intr_info))
2631 return handle_machine_check(vcpu, kvm_run);
2632
2599 if ((vect_info & VECTORING_INFO_VALID_MASK) && 2633 if ((vect_info & VECTORING_INFO_VALID_MASK) &&
2600 !is_page_fault(intr_info)) 2634 !is_page_fault(intr_info))
2601 printk(KERN_ERR "%s: unexpected, vectoring info 0x%x " 2635 printk(KERN_ERR "%s: unexpected, vectoring info 0x%x "
2602 "intr info 0x%x\n", __func__, vect_info, intr_info); 2636 "intr info 0x%x\n", __func__, vect_info, intr_info);
2603 2637
2604 if (!irqchip_in_kernel(vcpu->kvm) && is_external_interrupt(vect_info)) {
2605 int irq = vect_info & VECTORING_INFO_VECTOR_MASK;
2606 set_bit(irq, vcpu->arch.irq_pending);
2607 set_bit(irq / BITS_PER_LONG, &vcpu->arch.irq_summary);
2608 }
2609
2610 if ((intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR) 2638 if ((intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR)
2611 return 1; /* already handled by vmx_vcpu_run() */ 2639 return 1; /* already handled by vmx_vcpu_run() */
2612 2640
@@ -2628,17 +2656,17 @@ static int handle_exception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2628 error_code = vmcs_read32(VM_EXIT_INTR_ERROR_CODE); 2656 error_code = vmcs_read32(VM_EXIT_INTR_ERROR_CODE);
2629 if (is_page_fault(intr_info)) { 2657 if (is_page_fault(intr_info)) {
2630 /* EPT won't cause page fault directly */ 2658 /* EPT won't cause page fault directly */
2631 if (vm_need_ept()) 2659 if (enable_ept)
2632 BUG(); 2660 BUG();
2633 cr2 = vmcs_readl(EXIT_QUALIFICATION); 2661 cr2 = vmcs_readl(EXIT_QUALIFICATION);
2634 KVMTRACE_3D(PAGE_FAULT, vcpu, error_code, (u32)cr2, 2662 KVMTRACE_3D(PAGE_FAULT, vcpu, error_code, (u32)cr2,
2635 (u32)((u64)cr2 >> 32), handler); 2663 (u32)((u64)cr2 >> 32), handler);
2636 if (vcpu->arch.interrupt.pending || vcpu->arch.exception.pending) 2664 if (kvm_event_needs_reinjection(vcpu))
2637 kvm_mmu_unprotect_page_virt(vcpu, cr2); 2665 kvm_mmu_unprotect_page_virt(vcpu, cr2);
2638 return kvm_mmu_page_fault(vcpu, cr2, error_code); 2666 return kvm_mmu_page_fault(vcpu, cr2, error_code);
2639 } 2667 }
2640 2668
2641 if (vcpu->arch.rmode.active && 2669 if (vcpu->arch.rmode.vm86_active &&
2642 handle_rmode_exception(vcpu, intr_info & INTR_INFO_VECTOR_MASK, 2670 handle_rmode_exception(vcpu, intr_info & INTR_INFO_VECTOR_MASK,
2643 error_code)) { 2671 error_code)) {
2644 if (vcpu->arch.halt_request) { 2672 if (vcpu->arch.halt_request) {
@@ -2753,13 +2781,18 @@ static int handle_cr(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2753 kvm_set_cr4(vcpu, kvm_register_read(vcpu, reg)); 2781 kvm_set_cr4(vcpu, kvm_register_read(vcpu, reg));
2754 skip_emulated_instruction(vcpu); 2782 skip_emulated_instruction(vcpu);
2755 return 1; 2783 return 1;
2756 case 8: 2784 case 8: {
2757 kvm_set_cr8(vcpu, kvm_register_read(vcpu, reg)); 2785 u8 cr8_prev = kvm_get_cr8(vcpu);
2758 skip_emulated_instruction(vcpu); 2786 u8 cr8 = kvm_register_read(vcpu, reg);
2759 if (irqchip_in_kernel(vcpu->kvm)) 2787 kvm_set_cr8(vcpu, cr8);
2760 return 1; 2788 skip_emulated_instruction(vcpu);
2761 kvm_run->exit_reason = KVM_EXIT_SET_TPR; 2789 if (irqchip_in_kernel(vcpu->kvm))
2762 return 0; 2790 return 1;
2791 if (cr8_prev <= cr8)
2792 return 1;
2793 kvm_run->exit_reason = KVM_EXIT_SET_TPR;
2794 return 0;
2795 }
2763 }; 2796 };
2764 break; 2797 break;
2765 case 2: /* clts */ 2798 case 2: /* clts */
@@ -2957,8 +2990,9 @@ static int handle_interrupt_window(struct kvm_vcpu *vcpu,
2957 * If the user space waits to inject interrupts, exit as soon as 2990 * If the user space waits to inject interrupts, exit as soon as
2958 * possible 2991 * possible
2959 */ 2992 */
2960 if (kvm_run->request_interrupt_window && 2993 if (!irqchip_in_kernel(vcpu->kvm) &&
2961 !vcpu->arch.irq_summary) { 2994 kvm_run->request_interrupt_window &&
2995 !kvm_cpu_has_interrupt(vcpu)) {
2962 kvm_run->exit_reason = KVM_EXIT_IRQ_WINDOW_OPEN; 2996 kvm_run->exit_reason = KVM_EXIT_IRQ_WINDOW_OPEN;
2963 return 0; 2997 return 0;
2964 } 2998 }
@@ -2980,7 +3014,7 @@ static int handle_vmcall(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2980 3014
2981static int handle_invlpg(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 3015static int handle_invlpg(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2982{ 3016{
2983 u64 exit_qualification = vmcs_read64(EXIT_QUALIFICATION); 3017 unsigned long exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
2984 3018
2985 kvm_mmu_invlpg(vcpu, exit_qualification); 3019 kvm_mmu_invlpg(vcpu, exit_qualification);
2986 skip_emulated_instruction(vcpu); 3020 skip_emulated_instruction(vcpu);
@@ -2996,11 +3030,11 @@ static int handle_wbinvd(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2996 3030
2997static int handle_apic_access(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 3031static int handle_apic_access(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2998{ 3032{
2999 u64 exit_qualification; 3033 unsigned long exit_qualification;
3000 enum emulation_result er; 3034 enum emulation_result er;
3001 unsigned long offset; 3035 unsigned long offset;
3002 3036
3003 exit_qualification = vmcs_read64(EXIT_QUALIFICATION); 3037 exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
3004 offset = exit_qualification & 0xffful; 3038 offset = exit_qualification & 0xffful;
3005 3039
3006 er = emulate_instruction(vcpu, kvm_run, 0, 0, 0); 3040 er = emulate_instruction(vcpu, kvm_run, 0, 0, 0);
@@ -3019,22 +3053,41 @@ static int handle_task_switch(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3019 struct vcpu_vmx *vmx = to_vmx(vcpu); 3053 struct vcpu_vmx *vmx = to_vmx(vcpu);
3020 unsigned long exit_qualification; 3054 unsigned long exit_qualification;
3021 u16 tss_selector; 3055 u16 tss_selector;
3022 int reason; 3056 int reason, type, idt_v;
3057
3058 idt_v = (vmx->idt_vectoring_info & VECTORING_INFO_VALID_MASK);
3059 type = (vmx->idt_vectoring_info & VECTORING_INFO_TYPE_MASK);
3023 3060
3024 exit_qualification = vmcs_readl(EXIT_QUALIFICATION); 3061 exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
3025 3062
3026 reason = (u32)exit_qualification >> 30; 3063 reason = (u32)exit_qualification >> 30;
3027 if (reason == TASK_SWITCH_GATE && vmx->vcpu.arch.nmi_injected && 3064 if (reason == TASK_SWITCH_GATE && idt_v) {
3028 (vmx->idt_vectoring_info & VECTORING_INFO_VALID_MASK) && 3065 switch (type) {
3029 (vmx->idt_vectoring_info & VECTORING_INFO_TYPE_MASK) 3066 case INTR_TYPE_NMI_INTR:
3030 == INTR_TYPE_NMI_INTR) { 3067 vcpu->arch.nmi_injected = false;
3031 vcpu->arch.nmi_injected = false; 3068 if (cpu_has_virtual_nmis())
3032 if (cpu_has_virtual_nmis()) 3069 vmcs_set_bits(GUEST_INTERRUPTIBILITY_INFO,
3033 vmcs_set_bits(GUEST_INTERRUPTIBILITY_INFO, 3070 GUEST_INTR_STATE_NMI);
3034 GUEST_INTR_STATE_NMI); 3071 break;
3072 case INTR_TYPE_EXT_INTR:
3073 case INTR_TYPE_SOFT_INTR:
3074 kvm_clear_interrupt_queue(vcpu);
3075 break;
3076 case INTR_TYPE_HARD_EXCEPTION:
3077 case INTR_TYPE_SOFT_EXCEPTION:
3078 kvm_clear_exception_queue(vcpu);
3079 break;
3080 default:
3081 break;
3082 }
3035 } 3083 }
3036 tss_selector = exit_qualification; 3084 tss_selector = exit_qualification;
3037 3085
3086 if (!idt_v || (type != INTR_TYPE_HARD_EXCEPTION &&
3087 type != INTR_TYPE_EXT_INTR &&
3088 type != INTR_TYPE_NMI_INTR))
3089 skip_emulated_instruction(vcpu);
3090
3038 if (!kvm_task_switch(vcpu, tss_selector, reason)) 3091 if (!kvm_task_switch(vcpu, tss_selector, reason))
3039 return 0; 3092 return 0;
3040 3093
@@ -3051,11 +3104,11 @@ static int handle_task_switch(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3051 3104
3052static int handle_ept_violation(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 3105static int handle_ept_violation(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3053{ 3106{
3054 u64 exit_qualification; 3107 unsigned long exit_qualification;
3055 gpa_t gpa; 3108 gpa_t gpa;
3056 int gla_validity; 3109 int gla_validity;
3057 3110
3058 exit_qualification = vmcs_read64(EXIT_QUALIFICATION); 3111 exit_qualification = vmcs_readl(EXIT_QUALIFICATION);
3059 3112
3060 if (exit_qualification & (1 << 6)) { 3113 if (exit_qualification & (1 << 6)) {
3061 printk(KERN_ERR "EPT: GPA exceeds GAW!\n"); 3114 printk(KERN_ERR "EPT: GPA exceeds GAW!\n");
@@ -3067,7 +3120,7 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3067 printk(KERN_ERR "EPT: Handling EPT violation failed!\n"); 3120 printk(KERN_ERR "EPT: Handling EPT violation failed!\n");
3068 printk(KERN_ERR "EPT: GPA: 0x%lx, GVA: 0x%lx\n", 3121 printk(KERN_ERR "EPT: GPA: 0x%lx, GVA: 0x%lx\n",
3069 (long unsigned int)vmcs_read64(GUEST_PHYSICAL_ADDRESS), 3122 (long unsigned int)vmcs_read64(GUEST_PHYSICAL_ADDRESS),
3070 (long unsigned int)vmcs_read64(GUEST_LINEAR_ADDRESS)); 3123 vmcs_readl(GUEST_LINEAR_ADDRESS));
3071 printk(KERN_ERR "EPT: Exit qualification is 0x%lx\n", 3124 printk(KERN_ERR "EPT: Exit qualification is 0x%lx\n",
3072 (long unsigned int)exit_qualification); 3125 (long unsigned int)exit_qualification);
3073 kvm_run->exit_reason = KVM_EXIT_UNKNOWN; 3126 kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
@@ -3150,6 +3203,7 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu,
3150 [EXIT_REASON_WBINVD] = handle_wbinvd, 3203 [EXIT_REASON_WBINVD] = handle_wbinvd,
3151 [EXIT_REASON_TASK_SWITCH] = handle_task_switch, 3204 [EXIT_REASON_TASK_SWITCH] = handle_task_switch,
3152 [EXIT_REASON_EPT_VIOLATION] = handle_ept_violation, 3205 [EXIT_REASON_EPT_VIOLATION] = handle_ept_violation,
3206 [EXIT_REASON_MCE_DURING_VMENTRY] = handle_machine_check,
3153}; 3207};
3154 3208
3155static const int kvm_vmx_max_exit_handlers = 3209static const int kvm_vmx_max_exit_handlers =
@@ -3159,10 +3213,10 @@ static const int kvm_vmx_max_exit_handlers =
3159 * The guest has exited. See if we can fix it or if we need userspace 3213 * The guest has exited. See if we can fix it or if we need userspace
3160 * assistance. 3214 * assistance.
3161 */ 3215 */
3162static int kvm_handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) 3216static int vmx_handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
3163{ 3217{
3164 u32 exit_reason = vmcs_read32(VM_EXIT_REASON);
3165 struct vcpu_vmx *vmx = to_vmx(vcpu); 3218 struct vcpu_vmx *vmx = to_vmx(vcpu);
3219 u32 exit_reason = vmx->exit_reason;
3166 u32 vectoring_info = vmx->idt_vectoring_info; 3220 u32 vectoring_info = vmx->idt_vectoring_info;
3167 3221
3168 KVMTRACE_3D(VMEXIT, vcpu, exit_reason, (u32)kvm_rip_read(vcpu), 3222 KVMTRACE_3D(VMEXIT, vcpu, exit_reason, (u32)kvm_rip_read(vcpu),
@@ -3178,7 +3232,7 @@ static int kvm_handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
3178 3232
3179 /* Access CR3 don't cause VMExit in paging mode, so we need 3233 /* Access CR3 don't cause VMExit in paging mode, so we need
3180 * to sync with guest real CR3. */ 3234 * to sync with guest real CR3. */
3181 if (vm_need_ept() && is_paging(vcpu)) { 3235 if (enable_ept && is_paging(vcpu)) {
3182 vcpu->arch.cr3 = vmcs_readl(GUEST_CR3); 3236 vcpu->arch.cr3 = vmcs_readl(GUEST_CR3);
3183 ept_load_pdptrs(vcpu); 3237 ept_load_pdptrs(vcpu);
3184 } 3238 }
@@ -3199,9 +3253,8 @@ static int kvm_handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
3199 __func__, vectoring_info, exit_reason); 3253 __func__, vectoring_info, exit_reason);
3200 3254
3201 if (unlikely(!cpu_has_virtual_nmis() && vmx->soft_vnmi_blocked)) { 3255 if (unlikely(!cpu_has_virtual_nmis() && vmx->soft_vnmi_blocked)) {
3202 if (vcpu->arch.interrupt_window_open) { 3256 if (vmx_interrupt_allowed(vcpu)) {
3203 vmx->soft_vnmi_blocked = 0; 3257 vmx->soft_vnmi_blocked = 0;
3204 vcpu->arch.nmi_window_open = 1;
3205 } else if (vmx->vnmi_blocked_time > 1000000000LL && 3258 } else if (vmx->vnmi_blocked_time > 1000000000LL &&
3206 vcpu->arch.nmi_pending) { 3259 vcpu->arch.nmi_pending) {
3207 /* 3260 /*
@@ -3214,7 +3267,6 @@ static int kvm_handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
3214 "state on VCPU %d after 1 s timeout\n", 3267 "state on VCPU %d after 1 s timeout\n",
3215 __func__, vcpu->vcpu_id); 3268 __func__, vcpu->vcpu_id);
3216 vmx->soft_vnmi_blocked = 0; 3269 vmx->soft_vnmi_blocked = 0;
3217 vmx->vcpu.arch.nmi_window_open = 1;
3218 } 3270 }
3219 } 3271 }
3220 3272
@@ -3228,122 +3280,107 @@ static int kvm_handle_exit(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
3228 return 0; 3280 return 0;
3229} 3281}
3230 3282
3231static void update_tpr_threshold(struct kvm_vcpu *vcpu) 3283static void update_cr8_intercept(struct kvm_vcpu *vcpu, int tpr, int irr)
3232{ 3284{
3233 int max_irr, tpr; 3285 if (irr == -1 || tpr < irr) {
3234
3235 if (!vm_need_tpr_shadow(vcpu->kvm))
3236 return;
3237
3238 if (!kvm_lapic_enabled(vcpu) ||
3239 ((max_irr = kvm_lapic_find_highest_irr(vcpu)) == -1)) {
3240 vmcs_write32(TPR_THRESHOLD, 0); 3286 vmcs_write32(TPR_THRESHOLD, 0);
3241 return; 3287 return;
3242 } 3288 }
3243 3289
3244 tpr = (kvm_lapic_get_cr8(vcpu) & 0x0f) << 4; 3290 vmcs_write32(TPR_THRESHOLD, irr);
3245 vmcs_write32(TPR_THRESHOLD, (max_irr > tpr) ? tpr >> 4 : max_irr >> 4);
3246} 3291}
3247 3292
3248static void vmx_complete_interrupts(struct vcpu_vmx *vmx) 3293static void vmx_complete_interrupts(struct vcpu_vmx *vmx)
3249{ 3294{
3250 u32 exit_intr_info; 3295 u32 exit_intr_info;
3251 u32 idt_vectoring_info; 3296 u32 idt_vectoring_info = vmx->idt_vectoring_info;
3252 bool unblock_nmi; 3297 bool unblock_nmi;
3253 u8 vector; 3298 u8 vector;
3254 int type; 3299 int type;
3255 bool idtv_info_valid; 3300 bool idtv_info_valid;
3256 u32 error;
3257 3301
3258 exit_intr_info = vmcs_read32(VM_EXIT_INTR_INFO); 3302 exit_intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
3303
3304 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
3305
3306 /* Handle machine checks before interrupts are enabled */
3307 if ((vmx->exit_reason == EXIT_REASON_MCE_DURING_VMENTRY)
3308 || (vmx->exit_reason == EXIT_REASON_EXCEPTION_NMI
3309 && is_machine_check(exit_intr_info)))
3310 kvm_machine_check();
3311
3312 /* We need to handle NMIs before interrupts are enabled */
3313 if ((exit_intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR &&
3314 (exit_intr_info & INTR_INFO_VALID_MASK)) {
3315 KVMTRACE_0D(NMI, &vmx->vcpu, handler);
3316 asm("int $2");
3317 }
3318
3319 idtv_info_valid = idt_vectoring_info & VECTORING_INFO_VALID_MASK;
3320
3259 if (cpu_has_virtual_nmis()) { 3321 if (cpu_has_virtual_nmis()) {
3260 unblock_nmi = (exit_intr_info & INTR_INFO_UNBLOCK_NMI) != 0; 3322 unblock_nmi = (exit_intr_info & INTR_INFO_UNBLOCK_NMI) != 0;
3261 vector = exit_intr_info & INTR_INFO_VECTOR_MASK; 3323 vector = exit_intr_info & INTR_INFO_VECTOR_MASK;
3262 /* 3324 /*
3263 * SDM 3: 25.7.1.2 3325 * SDM 3: 27.7.1.2 (September 2008)
3264 * Re-set bit "block by NMI" before VM entry if vmexit caused by 3326 * Re-set bit "block by NMI" before VM entry if vmexit caused by
3265 * a guest IRET fault. 3327 * a guest IRET fault.
3328 * SDM 3: 23.2.2 (September 2008)
3329 * Bit 12 is undefined in any of the following cases:
3330 * If the VM exit sets the valid bit in the IDT-vectoring
3331 * information field.
3332 * If the VM exit is due to a double fault.
3266 */ 3333 */
3267 if (unblock_nmi && vector != DF_VECTOR) 3334 if ((exit_intr_info & INTR_INFO_VALID_MASK) && unblock_nmi &&
3335 vector != DF_VECTOR && !idtv_info_valid)
3268 vmcs_set_bits(GUEST_INTERRUPTIBILITY_INFO, 3336 vmcs_set_bits(GUEST_INTERRUPTIBILITY_INFO,
3269 GUEST_INTR_STATE_NMI); 3337 GUEST_INTR_STATE_NMI);
3270 } else if (unlikely(vmx->soft_vnmi_blocked)) 3338 } else if (unlikely(vmx->soft_vnmi_blocked))
3271 vmx->vnmi_blocked_time += 3339 vmx->vnmi_blocked_time +=
3272 ktime_to_ns(ktime_sub(ktime_get(), vmx->entry_time)); 3340 ktime_to_ns(ktime_sub(ktime_get(), vmx->entry_time));
3273 3341
3274 idt_vectoring_info = vmx->idt_vectoring_info; 3342 vmx->vcpu.arch.nmi_injected = false;
3275 idtv_info_valid = idt_vectoring_info & VECTORING_INFO_VALID_MASK; 3343 kvm_clear_exception_queue(&vmx->vcpu);
3344 kvm_clear_interrupt_queue(&vmx->vcpu);
3345
3346 if (!idtv_info_valid)
3347 return;
3348
3276 vector = idt_vectoring_info & VECTORING_INFO_VECTOR_MASK; 3349 vector = idt_vectoring_info & VECTORING_INFO_VECTOR_MASK;
3277 type = idt_vectoring_info & VECTORING_INFO_TYPE_MASK; 3350 type = idt_vectoring_info & VECTORING_INFO_TYPE_MASK;
3278 if (vmx->vcpu.arch.nmi_injected) { 3351
3352 switch (type) {
3353 case INTR_TYPE_NMI_INTR:
3354 vmx->vcpu.arch.nmi_injected = true;
3279 /* 3355 /*
3280 * SDM 3: 25.7.1.2 3356 * SDM 3: 27.7.1.2 (September 2008)
3281 * Clear bit "block by NMI" before VM entry if a NMI delivery 3357 * Clear bit "block by NMI" before VM entry if a NMI
3282 * faulted. 3358 * delivery faulted.
3283 */ 3359 */
3284 if (idtv_info_valid && type == INTR_TYPE_NMI_INTR) 3360 vmcs_clear_bits(GUEST_INTERRUPTIBILITY_INFO,
3285 vmcs_clear_bits(GUEST_INTERRUPTIBILITY_INFO, 3361 GUEST_INTR_STATE_NMI);
3286 GUEST_INTR_STATE_NMI); 3362 break;
3287 else 3363 case INTR_TYPE_SOFT_EXCEPTION:
3288 vmx->vcpu.arch.nmi_injected = false; 3364 vmx->vcpu.arch.event_exit_inst_len =
3289 } 3365 vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
3290 kvm_clear_exception_queue(&vmx->vcpu); 3366 /* fall through */
3291 if (idtv_info_valid && (type == INTR_TYPE_HARD_EXCEPTION || 3367 case INTR_TYPE_HARD_EXCEPTION:
3292 type == INTR_TYPE_SOFT_EXCEPTION)) {
3293 if (idt_vectoring_info & VECTORING_INFO_DELIVER_CODE_MASK) { 3368 if (idt_vectoring_info & VECTORING_INFO_DELIVER_CODE_MASK) {
3294 error = vmcs_read32(IDT_VECTORING_ERROR_CODE); 3369 u32 err = vmcs_read32(IDT_VECTORING_ERROR_CODE);
3295 kvm_queue_exception_e(&vmx->vcpu, vector, error); 3370 kvm_queue_exception_e(&vmx->vcpu, vector, err);
3296 } else 3371 } else
3297 kvm_queue_exception(&vmx->vcpu, vector); 3372 kvm_queue_exception(&vmx->vcpu, vector);
3298 vmx->idt_vectoring_info = 0; 3373 break;
3299 } 3374 case INTR_TYPE_SOFT_INTR:
3300 kvm_clear_interrupt_queue(&vmx->vcpu); 3375 vmx->vcpu.arch.event_exit_inst_len =
3301 if (idtv_info_valid && type == INTR_TYPE_EXT_INTR) { 3376 vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
3302 kvm_queue_interrupt(&vmx->vcpu, vector); 3377 /* fall through */
3303 vmx->idt_vectoring_info = 0; 3378 case INTR_TYPE_EXT_INTR:
3304 } 3379 kvm_queue_interrupt(&vmx->vcpu, vector,
3305} 3380 type == INTR_TYPE_SOFT_INTR);
3306 3381 break;
3307static void vmx_intr_assist(struct kvm_vcpu *vcpu) 3382 default:
3308{ 3383 break;
3309 update_tpr_threshold(vcpu);
3310
3311 vmx_update_window_states(vcpu);
3312
3313 if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
3314 vmcs_clear_bits(GUEST_INTERRUPTIBILITY_INFO,
3315 GUEST_INTR_STATE_STI |
3316 GUEST_INTR_STATE_MOV_SS);
3317
3318 if (vcpu->arch.nmi_pending && !vcpu->arch.nmi_injected) {
3319 if (vcpu->arch.interrupt.pending) {
3320 enable_nmi_window(vcpu);
3321 } else if (vcpu->arch.nmi_window_open) {
3322 vcpu->arch.nmi_pending = false;
3323 vcpu->arch.nmi_injected = true;
3324 } else {
3325 enable_nmi_window(vcpu);
3326 return;
3327 }
3328 }
3329 if (vcpu->arch.nmi_injected) {
3330 vmx_inject_nmi(vcpu);
3331 if (vcpu->arch.nmi_pending)
3332 enable_nmi_window(vcpu);
3333 else if (kvm_cpu_has_interrupt(vcpu))
3334 enable_irq_window(vcpu);
3335 return;
3336 }
3337 if (!vcpu->arch.interrupt.pending && kvm_cpu_has_interrupt(vcpu)) {
3338 if (vcpu->arch.interrupt_window_open)
3339 kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu));
3340 else
3341 enable_irq_window(vcpu);
3342 }
3343 if (vcpu->arch.interrupt.pending) {
3344 vmx_inject_irq(vcpu, vcpu->arch.interrupt.nr);
3345 if (kvm_cpu_has_interrupt(vcpu))
3346 enable_irq_window(vcpu);
3347 } 3384 }
3348} 3385}
3349 3386
@@ -3381,7 +3418,6 @@ static void fixup_rmode_irq(struct vcpu_vmx *vmx)
3381static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 3418static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3382{ 3419{
3383 struct vcpu_vmx *vmx = to_vmx(vcpu); 3420 struct vcpu_vmx *vmx = to_vmx(vcpu);
3384 u32 intr_info;
3385 3421
3386 /* Record the guest's net vcpu time for enforced NMI injections. */ 3422 /* Record the guest's net vcpu time for enforced NMI injections. */
3387 if (unlikely(!cpu_has_virtual_nmis() && vmx->soft_vnmi_blocked)) 3423 if (unlikely(!cpu_has_virtual_nmis() && vmx->soft_vnmi_blocked))
@@ -3505,20 +3541,9 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3505 if (vmx->rmode.irq.pending) 3541 if (vmx->rmode.irq.pending)
3506 fixup_rmode_irq(vmx); 3542 fixup_rmode_irq(vmx);
3507 3543
3508 vmx_update_window_states(vcpu);
3509
3510 asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS)); 3544 asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
3511 vmx->launched = 1; 3545 vmx->launched = 1;
3512 3546
3513 intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
3514
3515 /* We need to handle NMIs before interrupts are enabled */
3516 if ((intr_info & INTR_INFO_INTR_TYPE_MASK) == INTR_TYPE_NMI_INTR &&
3517 (intr_info & INTR_INFO_VALID_MASK)) {
3518 KVMTRACE_0D(NMI, vcpu, handler);
3519 asm("int $2");
3520 }
3521
3522 vmx_complete_interrupts(vmx); 3547 vmx_complete_interrupts(vmx);
3523} 3548}
3524 3549
@@ -3593,7 +3618,7 @@ static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
3593 if (alloc_apic_access_page(kvm) != 0) 3618 if (alloc_apic_access_page(kvm) != 0)
3594 goto free_vmcs; 3619 goto free_vmcs;
3595 3620
3596 if (vm_need_ept()) 3621 if (enable_ept)
3597 if (alloc_identity_pagetable(kvm) != 0) 3622 if (alloc_identity_pagetable(kvm) != 0)
3598 goto free_vmcs; 3623 goto free_vmcs;
3599 3624
@@ -3631,9 +3656,32 @@ static int get_ept_level(void)
3631 return VMX_EPT_DEFAULT_GAW + 1; 3656 return VMX_EPT_DEFAULT_GAW + 1;
3632} 3657}
3633 3658
3634static int vmx_get_mt_mask_shift(void) 3659static u64 vmx_get_mt_mask(struct kvm_vcpu *vcpu, gfn_t gfn, bool is_mmio)
3635{ 3660{
3636 return VMX_EPT_MT_EPTE_SHIFT; 3661 u64 ret;
3662
3663 /* For VT-d and EPT combination
3664 * 1. MMIO: always map as UC
3665 * 2. EPT with VT-d:
3666 * a. VT-d without snooping control feature: can't guarantee the
3667 * result, try to trust guest.
3668 * b. VT-d with snooping control feature: snooping control feature of
3669 * VT-d engine can guarantee the cache correctness. Just set it
3670 * to WB to keep consistent with host. So the same as item 3.
3671 * 3. EPT without VT-d: always map as WB and set IGMT=1 to keep
3672 * consistent with host MTRR
3673 */
3674 if (is_mmio)
3675 ret = MTRR_TYPE_UNCACHABLE << VMX_EPT_MT_EPTE_SHIFT;
3676 else if (vcpu->kvm->arch.iommu_domain &&
3677 !(vcpu->kvm->arch.iommu_flags & KVM_IOMMU_CACHE_COHERENCY))
3678 ret = kvm_get_guest_memory_type(vcpu, gfn) <<
3679 VMX_EPT_MT_EPTE_SHIFT;
3680 else
3681 ret = (MTRR_TYPE_WRBACK << VMX_EPT_MT_EPTE_SHIFT)
3682 | VMX_EPT_IGMT_BIT;
3683
3684 return ret;
3637} 3685}
3638 3686
3639static struct kvm_x86_ops vmx_x86_ops = { 3687static struct kvm_x86_ops vmx_x86_ops = {
@@ -3644,7 +3692,7 @@ static struct kvm_x86_ops vmx_x86_ops = {
3644 .check_processor_compatibility = vmx_check_processor_compat, 3692 .check_processor_compatibility = vmx_check_processor_compat,
3645 .hardware_enable = hardware_enable, 3693 .hardware_enable = hardware_enable,
3646 .hardware_disable = hardware_disable, 3694 .hardware_disable = hardware_disable,
3647 .cpu_has_accelerated_tpr = cpu_has_vmx_virtualize_apic_accesses, 3695 .cpu_has_accelerated_tpr = report_flexpriority,
3648 3696
3649 .vcpu_create = vmx_create_vcpu, 3697 .vcpu_create = vmx_create_vcpu,
3650 .vcpu_free = vmx_free_vcpu, 3698 .vcpu_free = vmx_free_vcpu,
@@ -3678,78 +3726,82 @@ static struct kvm_x86_ops vmx_x86_ops = {
3678 .tlb_flush = vmx_flush_tlb, 3726 .tlb_flush = vmx_flush_tlb,
3679 3727
3680 .run = vmx_vcpu_run, 3728 .run = vmx_vcpu_run,
3681 .handle_exit = kvm_handle_exit, 3729 .handle_exit = vmx_handle_exit,
3682 .skip_emulated_instruction = skip_emulated_instruction, 3730 .skip_emulated_instruction = skip_emulated_instruction,
3731 .set_interrupt_shadow = vmx_set_interrupt_shadow,
3732 .get_interrupt_shadow = vmx_get_interrupt_shadow,
3683 .patch_hypercall = vmx_patch_hypercall, 3733 .patch_hypercall = vmx_patch_hypercall,
3684 .get_irq = vmx_get_irq,
3685 .set_irq = vmx_inject_irq, 3734 .set_irq = vmx_inject_irq,
3735 .set_nmi = vmx_inject_nmi,
3686 .queue_exception = vmx_queue_exception, 3736 .queue_exception = vmx_queue_exception,
3687 .exception_injected = vmx_exception_injected, 3737 .interrupt_allowed = vmx_interrupt_allowed,
3688 .inject_pending_irq = vmx_intr_assist, 3738 .nmi_allowed = vmx_nmi_allowed,
3689 .inject_pending_vectors = do_interrupt_requests, 3739 .enable_nmi_window = enable_nmi_window,
3740 .enable_irq_window = enable_irq_window,
3741 .update_cr8_intercept = update_cr8_intercept,
3690 3742
3691 .set_tss_addr = vmx_set_tss_addr, 3743 .set_tss_addr = vmx_set_tss_addr,
3692 .get_tdp_level = get_ept_level, 3744 .get_tdp_level = get_ept_level,
3693 .get_mt_mask_shift = vmx_get_mt_mask_shift, 3745 .get_mt_mask = vmx_get_mt_mask,
3694}; 3746};
3695 3747
3696static int __init vmx_init(void) 3748static int __init vmx_init(void)
3697{ 3749{
3698 void *va;
3699 int r; 3750 int r;
3700 3751
3701 vmx_io_bitmap_a = alloc_page(GFP_KERNEL | __GFP_HIGHMEM); 3752 vmx_io_bitmap_a = (unsigned long *)__get_free_page(GFP_KERNEL);
3702 if (!vmx_io_bitmap_a) 3753 if (!vmx_io_bitmap_a)
3703 return -ENOMEM; 3754 return -ENOMEM;
3704 3755
3705 vmx_io_bitmap_b = alloc_page(GFP_KERNEL | __GFP_HIGHMEM); 3756 vmx_io_bitmap_b = (unsigned long *)__get_free_page(GFP_KERNEL);
3706 if (!vmx_io_bitmap_b) { 3757 if (!vmx_io_bitmap_b) {
3707 r = -ENOMEM; 3758 r = -ENOMEM;
3708 goto out; 3759 goto out;
3709 } 3760 }
3710 3761
3711 vmx_msr_bitmap = alloc_page(GFP_KERNEL | __GFP_HIGHMEM); 3762 vmx_msr_bitmap_legacy = (unsigned long *)__get_free_page(GFP_KERNEL);
3712 if (!vmx_msr_bitmap) { 3763 if (!vmx_msr_bitmap_legacy) {
3713 r = -ENOMEM; 3764 r = -ENOMEM;
3714 goto out1; 3765 goto out1;
3715 } 3766 }
3716 3767
3768 vmx_msr_bitmap_longmode = (unsigned long *)__get_free_page(GFP_KERNEL);
3769 if (!vmx_msr_bitmap_longmode) {
3770 r = -ENOMEM;
3771 goto out2;
3772 }
3773
3717 /* 3774 /*
3718 * Allow direct access to the PC debug port (it is often used for I/O 3775 * Allow direct access to the PC debug port (it is often used for I/O
3719 * delays, but the vmexits simply slow things down). 3776 * delays, but the vmexits simply slow things down).
3720 */ 3777 */
3721 va = kmap(vmx_io_bitmap_a); 3778 memset(vmx_io_bitmap_a, 0xff, PAGE_SIZE);
3722 memset(va, 0xff, PAGE_SIZE); 3779 clear_bit(0x80, vmx_io_bitmap_a);
3723 clear_bit(0x80, va);
3724 kunmap(vmx_io_bitmap_a);
3725 3780
3726 va = kmap(vmx_io_bitmap_b); 3781 memset(vmx_io_bitmap_b, 0xff, PAGE_SIZE);
3727 memset(va, 0xff, PAGE_SIZE);
3728 kunmap(vmx_io_bitmap_b);
3729 3782
3730 va = kmap(vmx_msr_bitmap); 3783 memset(vmx_msr_bitmap_legacy, 0xff, PAGE_SIZE);
3731 memset(va, 0xff, PAGE_SIZE); 3784 memset(vmx_msr_bitmap_longmode, 0xff, PAGE_SIZE);
3732 kunmap(vmx_msr_bitmap);
3733 3785
3734 set_bit(0, vmx_vpid_bitmap); /* 0 is reserved for host */ 3786 set_bit(0, vmx_vpid_bitmap); /* 0 is reserved for host */
3735 3787
3736 r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx), THIS_MODULE); 3788 r = kvm_init(&vmx_x86_ops, sizeof(struct vcpu_vmx), THIS_MODULE);
3737 if (r) 3789 if (r)
3738 goto out2; 3790 goto out3;
3739 3791
3740 vmx_disable_intercept_for_msr(vmx_msr_bitmap, MSR_FS_BASE); 3792 vmx_disable_intercept_for_msr(MSR_FS_BASE, false);
3741 vmx_disable_intercept_for_msr(vmx_msr_bitmap, MSR_GS_BASE); 3793 vmx_disable_intercept_for_msr(MSR_GS_BASE, false);
3742 vmx_disable_intercept_for_msr(vmx_msr_bitmap, MSR_IA32_SYSENTER_CS); 3794 vmx_disable_intercept_for_msr(MSR_KERNEL_GS_BASE, true);
3743 vmx_disable_intercept_for_msr(vmx_msr_bitmap, MSR_IA32_SYSENTER_ESP); 3795 vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_CS, false);
3744 vmx_disable_intercept_for_msr(vmx_msr_bitmap, MSR_IA32_SYSENTER_EIP); 3796 vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_ESP, false);
3797 vmx_disable_intercept_for_msr(MSR_IA32_SYSENTER_EIP, false);
3745 3798
3746 if (vm_need_ept()) { 3799 if (enable_ept) {
3747 bypass_guest_pf = 0; 3800 bypass_guest_pf = 0;
3748 kvm_mmu_set_base_ptes(VMX_EPT_READABLE_MASK | 3801 kvm_mmu_set_base_ptes(VMX_EPT_READABLE_MASK |
3749 VMX_EPT_WRITABLE_MASK); 3802 VMX_EPT_WRITABLE_MASK);
3750 kvm_mmu_set_mask_ptes(0ull, 0ull, 0ull, 0ull, 3803 kvm_mmu_set_mask_ptes(0ull, 0ull, 0ull, 0ull,
3751 VMX_EPT_EXECUTABLE_MASK, 3804 VMX_EPT_EXECUTABLE_MASK);
3752 VMX_EPT_DEFAULT_MT << VMX_EPT_MT_EPTE_SHIFT);
3753 kvm_enable_tdp(); 3805 kvm_enable_tdp();
3754 } else 3806 } else
3755 kvm_disable_tdp(); 3807 kvm_disable_tdp();
@@ -3761,20 +3813,23 @@ static int __init vmx_init(void)
3761 3813
3762 return 0; 3814 return 0;
3763 3815
3816out3:
3817 free_page((unsigned long)vmx_msr_bitmap_longmode);
3764out2: 3818out2:
3765 __free_page(vmx_msr_bitmap); 3819 free_page((unsigned long)vmx_msr_bitmap_legacy);
3766out1: 3820out1:
3767 __free_page(vmx_io_bitmap_b); 3821 free_page((unsigned long)vmx_io_bitmap_b);
3768out: 3822out:
3769 __free_page(vmx_io_bitmap_a); 3823 free_page((unsigned long)vmx_io_bitmap_a);
3770 return r; 3824 return r;
3771} 3825}
3772 3826
3773static void __exit vmx_exit(void) 3827static void __exit vmx_exit(void)
3774{ 3828{
3775 __free_page(vmx_msr_bitmap); 3829 free_page((unsigned long)vmx_msr_bitmap_legacy);
3776 __free_page(vmx_io_bitmap_b); 3830 free_page((unsigned long)vmx_msr_bitmap_longmode);
3777 __free_page(vmx_io_bitmap_a); 3831 free_page((unsigned long)vmx_io_bitmap_b);
3832 free_page((unsigned long)vmx_io_bitmap_a);
3778 3833
3779 kvm_exit(); 3834 kvm_exit();
3780} 3835}
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 3944e917e794..249540f98513 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -91,7 +91,6 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
91 { "halt_wakeup", VCPU_STAT(halt_wakeup) }, 91 { "halt_wakeup", VCPU_STAT(halt_wakeup) },
92 { "hypercalls", VCPU_STAT(hypercalls) }, 92 { "hypercalls", VCPU_STAT(hypercalls) },
93 { "request_irq", VCPU_STAT(request_irq_exits) }, 93 { "request_irq", VCPU_STAT(request_irq_exits) },
94 { "request_nmi", VCPU_STAT(request_nmi_exits) },
95 { "irq_exits", VCPU_STAT(irq_exits) }, 94 { "irq_exits", VCPU_STAT(irq_exits) },
96 { "host_state_reload", VCPU_STAT(host_state_reload) }, 95 { "host_state_reload", VCPU_STAT(host_state_reload) },
97 { "efer_reload", VCPU_STAT(efer_reload) }, 96 { "efer_reload", VCPU_STAT(efer_reload) },
@@ -108,7 +107,6 @@ struct kvm_stats_debugfs_item debugfs_entries[] = {
108 { "mmu_recycled", VM_STAT(mmu_recycled) }, 107 { "mmu_recycled", VM_STAT(mmu_recycled) },
109 { "mmu_cache_miss", VM_STAT(mmu_cache_miss) }, 108 { "mmu_cache_miss", VM_STAT(mmu_cache_miss) },
110 { "mmu_unsync", VM_STAT(mmu_unsync) }, 109 { "mmu_unsync", VM_STAT(mmu_unsync) },
111 { "mmu_unsync_global", VM_STAT(mmu_unsync_global) },
112 { "remote_tlb_flush", VM_STAT(remote_tlb_flush) }, 110 { "remote_tlb_flush", VM_STAT(remote_tlb_flush) },
113 { "largepages", VM_STAT(lpages) }, 111 { "largepages", VM_STAT(lpages) },
114 { NULL } 112 { NULL }
@@ -234,7 +232,8 @@ int load_pdptrs(struct kvm_vcpu *vcpu, unsigned long cr3)
234 goto out; 232 goto out;
235 } 233 }
236 for (i = 0; i < ARRAY_SIZE(pdpte); ++i) { 234 for (i = 0; i < ARRAY_SIZE(pdpte); ++i) {
237 if ((pdpte[i] & 1) && (pdpte[i] & 0xfffffff0000001e6ull)) { 235 if (is_present_pte(pdpte[i]) &&
236 (pdpte[i] & vcpu->arch.mmu.rsvd_bits_mask[0][2])) {
238 ret = 0; 237 ret = 0;
239 goto out; 238 goto out;
240 } 239 }
@@ -321,7 +320,6 @@ void kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
321 kvm_x86_ops->set_cr0(vcpu, cr0); 320 kvm_x86_ops->set_cr0(vcpu, cr0);
322 vcpu->arch.cr0 = cr0; 321 vcpu->arch.cr0 = cr0;
323 322
324 kvm_mmu_sync_global(vcpu);
325 kvm_mmu_reset_context(vcpu); 323 kvm_mmu_reset_context(vcpu);
326 return; 324 return;
327} 325}
@@ -370,7 +368,6 @@ void kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
370 kvm_x86_ops->set_cr4(vcpu, cr4); 368 kvm_x86_ops->set_cr4(vcpu, cr4);
371 vcpu->arch.cr4 = cr4; 369 vcpu->arch.cr4 = cr4;
372 vcpu->arch.mmu.base_role.cr4_pge = (cr4 & X86_CR4_PGE) && !tdp_enabled; 370 vcpu->arch.mmu.base_role.cr4_pge = (cr4 & X86_CR4_PGE) && !tdp_enabled;
373 kvm_mmu_sync_global(vcpu);
374 kvm_mmu_reset_context(vcpu); 371 kvm_mmu_reset_context(vcpu);
375} 372}
376EXPORT_SYMBOL_GPL(kvm_set_cr4); 373EXPORT_SYMBOL_GPL(kvm_set_cr4);
@@ -523,6 +520,9 @@ static void set_efer(struct kvm_vcpu *vcpu, u64 efer)
523 efer |= vcpu->arch.shadow_efer & EFER_LMA; 520 efer |= vcpu->arch.shadow_efer & EFER_LMA;
524 521
525 vcpu->arch.shadow_efer = efer; 522 vcpu->arch.shadow_efer = efer;
523
524 vcpu->arch.mmu.base_role.nxe = (efer & EFER_NX) && !tdp_enabled;
525 kvm_mmu_reset_context(vcpu);
526} 526}
527 527
528void kvm_enable_efer_bits(u64 mask) 528void kvm_enable_efer_bits(u64 mask)
@@ -630,14 +630,17 @@ static void kvm_write_guest_time(struct kvm_vcpu *v)
630 unsigned long flags; 630 unsigned long flags;
631 struct kvm_vcpu_arch *vcpu = &v->arch; 631 struct kvm_vcpu_arch *vcpu = &v->arch;
632 void *shared_kaddr; 632 void *shared_kaddr;
633 unsigned long this_tsc_khz;
633 634
634 if ((!vcpu->time_page)) 635 if ((!vcpu->time_page))
635 return; 636 return;
636 637
637 if (unlikely(vcpu->hv_clock_tsc_khz != __get_cpu_var(cpu_tsc_khz))) { 638 this_tsc_khz = get_cpu_var(cpu_tsc_khz);
638 kvm_set_time_scale(__get_cpu_var(cpu_tsc_khz), &vcpu->hv_clock); 639 if (unlikely(vcpu->hv_clock_tsc_khz != this_tsc_khz)) {
639 vcpu->hv_clock_tsc_khz = __get_cpu_var(cpu_tsc_khz); 640 kvm_set_time_scale(this_tsc_khz, &vcpu->hv_clock);
641 vcpu->hv_clock_tsc_khz = this_tsc_khz;
640 } 642 }
643 put_cpu_var(cpu_tsc_khz);
641 644
642 /* Keep irq disabled to prevent changes to the clock */ 645 /* Keep irq disabled to prevent changes to the clock */
643 local_irq_save(flags); 646 local_irq_save(flags);
@@ -893,6 +896,8 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
893 case MSR_IA32_LASTINTFROMIP: 896 case MSR_IA32_LASTINTFROMIP:
894 case MSR_IA32_LASTINTTOIP: 897 case MSR_IA32_LASTINTTOIP:
895 case MSR_VM_HSAVE_PA: 898 case MSR_VM_HSAVE_PA:
899 case MSR_P6_EVNTSEL0:
900 case MSR_P6_EVNTSEL1:
896 data = 0; 901 data = 0;
897 break; 902 break;
898 case MSR_MTRRcap: 903 case MSR_MTRRcap:
@@ -1024,6 +1029,7 @@ int kvm_dev_ioctl_check_extension(long ext)
1024 case KVM_CAP_SYNC_MMU: 1029 case KVM_CAP_SYNC_MMU:
1025 case KVM_CAP_REINJECT_CONTROL: 1030 case KVM_CAP_REINJECT_CONTROL:
1026 case KVM_CAP_IRQ_INJECT_STATUS: 1031 case KVM_CAP_IRQ_INJECT_STATUS:
1032 case KVM_CAP_ASSIGN_DEV_IRQ:
1027 r = 1; 1033 r = 1;
1028 break; 1034 break;
1029 case KVM_CAP_COALESCED_MMIO: 1035 case KVM_CAP_COALESCED_MMIO:
@@ -1241,41 +1247,53 @@ static void do_cpuid_1_ent(struct kvm_cpuid_entry2 *entry, u32 function,
1241 entry->flags = 0; 1247 entry->flags = 0;
1242} 1248}
1243 1249
1250#define F(x) bit(X86_FEATURE_##x)
1251
1244static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, 1252static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
1245 u32 index, int *nent, int maxnent) 1253 u32 index, int *nent, int maxnent)
1246{ 1254{
1247 const u32 kvm_supported_word0_x86_features = bit(X86_FEATURE_FPU) | 1255 unsigned f_nx = is_efer_nx() ? F(NX) : 0;
1248 bit(X86_FEATURE_VME) | bit(X86_FEATURE_DE) |
1249 bit(X86_FEATURE_PSE) | bit(X86_FEATURE_TSC) |
1250 bit(X86_FEATURE_MSR) | bit(X86_FEATURE_PAE) |
1251 bit(X86_FEATURE_CX8) | bit(X86_FEATURE_APIC) |
1252 bit(X86_FEATURE_SEP) | bit(X86_FEATURE_PGE) |
1253 bit(X86_FEATURE_CMOV) | bit(X86_FEATURE_PSE36) |
1254 bit(X86_FEATURE_CLFLSH) | bit(X86_FEATURE_MMX) |
1255 bit(X86_FEATURE_FXSR) | bit(X86_FEATURE_XMM) |
1256 bit(X86_FEATURE_XMM2) | bit(X86_FEATURE_SELFSNOOP);
1257 const u32 kvm_supported_word1_x86_features = bit(X86_FEATURE_FPU) |
1258 bit(X86_FEATURE_VME) | bit(X86_FEATURE_DE) |
1259 bit(X86_FEATURE_PSE) | bit(X86_FEATURE_TSC) |
1260 bit(X86_FEATURE_MSR) | bit(X86_FEATURE_PAE) |
1261 bit(X86_FEATURE_CX8) | bit(X86_FEATURE_APIC) |
1262 bit(X86_FEATURE_PGE) |
1263 bit(X86_FEATURE_CMOV) | bit(X86_FEATURE_PSE36) |
1264 bit(X86_FEATURE_MMX) | bit(X86_FEATURE_FXSR) |
1265 bit(X86_FEATURE_SYSCALL) |
1266 (is_efer_nx() ? bit(X86_FEATURE_NX) : 0) |
1267#ifdef CONFIG_X86_64 1256#ifdef CONFIG_X86_64
1268 bit(X86_FEATURE_LM) | 1257 unsigned f_lm = F(LM);
1258#else
1259 unsigned f_lm = 0;
1269#endif 1260#endif
1270 bit(X86_FEATURE_FXSR_OPT) | 1261
1271 bit(X86_FEATURE_MMXEXT) | 1262 /* cpuid 1.edx */
1272 bit(X86_FEATURE_3DNOWEXT) | 1263 const u32 kvm_supported_word0_x86_features =
1273 bit(X86_FEATURE_3DNOW); 1264 F(FPU) | F(VME) | F(DE) | F(PSE) |
1274 const u32 kvm_supported_word3_x86_features = 1265 F(TSC) | F(MSR) | F(PAE) | F(MCE) |
1275 bit(X86_FEATURE_XMM3) | bit(X86_FEATURE_CX16); 1266 F(CX8) | F(APIC) | 0 /* Reserved */ | F(SEP) |
1267 F(MTRR) | F(PGE) | F(MCA) | F(CMOV) |
1268 F(PAT) | F(PSE36) | 0 /* PSN */ | F(CLFLSH) |
1269 0 /* Reserved, DS, ACPI */ | F(MMX) |
1270 F(FXSR) | F(XMM) | F(XMM2) | F(SELFSNOOP) |
1271 0 /* HTT, TM, Reserved, PBE */;
1272 /* cpuid 0x80000001.edx */
1273 const u32 kvm_supported_word1_x86_features =
1274 F(FPU) | F(VME) | F(DE) | F(PSE) |
1275 F(TSC) | F(MSR) | F(PAE) | F(MCE) |
1276 F(CX8) | F(APIC) | 0 /* Reserved */ | F(SYSCALL) |
1277 F(MTRR) | F(PGE) | F(MCA) | F(CMOV) |
1278 F(PAT) | F(PSE36) | 0 /* Reserved */ |
1279 f_nx | 0 /* Reserved */ | F(MMXEXT) | F(MMX) |
1280 F(FXSR) | F(FXSR_OPT) | 0 /* GBPAGES */ | 0 /* RDTSCP */ |
1281 0 /* Reserved */ | f_lm | F(3DNOWEXT) | F(3DNOW);
1282 /* cpuid 1.ecx */
1283 const u32 kvm_supported_word4_x86_features =
1284 F(XMM3) | 0 /* Reserved, DTES64, MONITOR */ |
1285 0 /* DS-CPL, VMX, SMX, EST */ |
1286 0 /* TM2 */ | F(SSSE3) | 0 /* CNXT-ID */ | 0 /* Reserved */ |
1287 0 /* Reserved */ | F(CX16) | 0 /* xTPR Update, PDCM */ |
1288 0 /* Reserved, DCA */ | F(XMM4_1) |
1289 F(XMM4_2) | 0 /* x2APIC */ | F(MOVBE) | F(POPCNT) |
1290 0 /* Reserved, XSAVE, OSXSAVE */;
1291 /* cpuid 0x80000001.ecx */
1276 const u32 kvm_supported_word6_x86_features = 1292 const u32 kvm_supported_word6_x86_features =
1277 bit(X86_FEATURE_LAHF_LM) | bit(X86_FEATURE_CMP_LEGACY) | 1293 F(LAHF_LM) | F(CMP_LEGACY) | F(SVM) | 0 /* ExtApicSpace */ |
1278 bit(X86_FEATURE_SVM); 1294 F(CR8_LEGACY) | F(ABM) | F(SSE4A) | F(MISALIGNSSE) |
1295 F(3DNOWPREFETCH) | 0 /* OSVW */ | 0 /* IBS */ | F(SSE5) |
1296 0 /* SKINIT */ | 0 /* WDT */;
1279 1297
1280 /* all calls to cpuid_count() should be made on the same cpu */ 1298 /* all calls to cpuid_count() should be made on the same cpu */
1281 get_cpu(); 1299 get_cpu();
@@ -1288,7 +1306,7 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
1288 break; 1306 break;
1289 case 1: 1307 case 1:
1290 entry->edx &= kvm_supported_word0_x86_features; 1308 entry->edx &= kvm_supported_word0_x86_features;
1291 entry->ecx &= kvm_supported_word3_x86_features; 1309 entry->ecx &= kvm_supported_word4_x86_features;
1292 break; 1310 break;
1293 /* function 2 entries are STATEFUL. That is, repeated cpuid commands 1311 /* function 2 entries are STATEFUL. That is, repeated cpuid commands
1294 * may return different values. This forces us to get_cpu() before 1312 * may return different values. This forces us to get_cpu() before
@@ -1350,6 +1368,8 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
1350 put_cpu(); 1368 put_cpu();
1351} 1369}
1352 1370
1371#undef F
1372
1353static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid, 1373static int kvm_dev_ioctl_get_supported_cpuid(struct kvm_cpuid2 *cpuid,
1354 struct kvm_cpuid_entry2 __user *entries) 1374 struct kvm_cpuid_entry2 __user *entries)
1355{ 1375{
@@ -1421,8 +1441,7 @@ static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
1421 return -ENXIO; 1441 return -ENXIO;
1422 vcpu_load(vcpu); 1442 vcpu_load(vcpu);
1423 1443
1424 set_bit(irq->irq, vcpu->arch.irq_pending); 1444 kvm_queue_interrupt(vcpu, irq->irq, false);
1425 set_bit(irq->irq / BITS_PER_LONG, &vcpu->arch.irq_summary);
1426 1445
1427 vcpu_put(vcpu); 1446 vcpu_put(vcpu);
1428 1447
@@ -1584,8 +1603,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
1584 r = -EINVAL; 1603 r = -EINVAL;
1585 } 1604 }
1586out: 1605out:
1587 if (lapic) 1606 kfree(lapic);
1588 kfree(lapic);
1589 return r; 1607 return r;
1590} 1608}
1591 1609
@@ -1606,10 +1624,12 @@ static int kvm_vm_ioctl_set_nr_mmu_pages(struct kvm *kvm,
1606 return -EINVAL; 1624 return -EINVAL;
1607 1625
1608 down_write(&kvm->slots_lock); 1626 down_write(&kvm->slots_lock);
1627 spin_lock(&kvm->mmu_lock);
1609 1628
1610 kvm_mmu_change_mmu_pages(kvm, kvm_nr_mmu_pages); 1629 kvm_mmu_change_mmu_pages(kvm, kvm_nr_mmu_pages);
1611 kvm->arch.n_requested_mmu_pages = kvm_nr_mmu_pages; 1630 kvm->arch.n_requested_mmu_pages = kvm_nr_mmu_pages;
1612 1631
1632 spin_unlock(&kvm->mmu_lock);
1613 up_write(&kvm->slots_lock); 1633 up_write(&kvm->slots_lock);
1614 return 0; 1634 return 0;
1615} 1635}
@@ -1785,7 +1805,9 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
1785 1805
1786 /* If nothing is dirty, don't bother messing with page tables. */ 1806 /* If nothing is dirty, don't bother messing with page tables. */
1787 if (is_dirty) { 1807 if (is_dirty) {
1808 spin_lock(&kvm->mmu_lock);
1788 kvm_mmu_slot_remove_write_access(kvm, log->slot); 1809 kvm_mmu_slot_remove_write_access(kvm, log->slot);
1810 spin_unlock(&kvm->mmu_lock);
1789 kvm_flush_remote_tlbs(kvm); 1811 kvm_flush_remote_tlbs(kvm);
1790 memslot = &kvm->memslots[log->slot]; 1812 memslot = &kvm->memslots[log->slot];
1791 n = ALIGN(memslot->npages, BITS_PER_LONG) / 8; 1813 n = ALIGN(memslot->npages, BITS_PER_LONG) / 8;
@@ -2360,7 +2382,7 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
2360 u16 error_code, 2382 u16 error_code,
2361 int emulation_type) 2383 int emulation_type)
2362{ 2384{
2363 int r; 2385 int r, shadow_mask;
2364 struct decode_cache *c; 2386 struct decode_cache *c;
2365 2387
2366 kvm_clear_exception_queue(vcpu); 2388 kvm_clear_exception_queue(vcpu);
@@ -2408,7 +2430,16 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
2408 } 2430 }
2409 } 2431 }
2410 2432
2433 if (emulation_type & EMULTYPE_SKIP) {
2434 kvm_rip_write(vcpu, vcpu->arch.emulate_ctxt.decode.eip);
2435 return EMULATE_DONE;
2436 }
2437
2411 r = x86_emulate_insn(&vcpu->arch.emulate_ctxt, &emulate_ops); 2438 r = x86_emulate_insn(&vcpu->arch.emulate_ctxt, &emulate_ops);
2439 shadow_mask = vcpu->arch.emulate_ctxt.interruptibility;
2440
2441 if (r == 0)
2442 kvm_x86_ops->set_interrupt_shadow(vcpu, shadow_mask);
2412 2443
2413 if (vcpu->arch.pio.string) 2444 if (vcpu->arch.pio.string)
2414 return EMULATE_DO_MMIO; 2445 return EMULATE_DO_MMIO;
@@ -2761,7 +2792,7 @@ int kvm_arch_init(void *opaque)
2761 kvm_mmu_set_nonpresent_ptes(0ull, 0ull); 2792 kvm_mmu_set_nonpresent_ptes(0ull, 0ull);
2762 kvm_mmu_set_base_ptes(PT_PRESENT_MASK); 2793 kvm_mmu_set_base_ptes(PT_PRESENT_MASK);
2763 kvm_mmu_set_mask_ptes(PT_USER_MASK, PT_ACCESSED_MASK, 2794 kvm_mmu_set_mask_ptes(PT_USER_MASK, PT_ACCESSED_MASK,
2764 PT_DIRTY_MASK, PT64_NX_MASK, 0, 0); 2795 PT_DIRTY_MASK, PT64_NX_MASK, 0);
2765 2796
2766 for_each_possible_cpu(cpu) 2797 for_each_possible_cpu(cpu)
2767 per_cpu(cpu_tsc_khz, cpu) = tsc_khz; 2798 per_cpu(cpu_tsc_khz, cpu) = tsc_khz;
@@ -3012,6 +3043,16 @@ struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
3012 return best; 3043 return best;
3013} 3044}
3014 3045
3046int cpuid_maxphyaddr(struct kvm_vcpu *vcpu)
3047{
3048 struct kvm_cpuid_entry2 *best;
3049
3050 best = kvm_find_cpuid_entry(vcpu, 0x80000008, 0);
3051 if (best)
3052 return best->eax & 0xff;
3053 return 36;
3054}
3055
3015void kvm_emulate_cpuid(struct kvm_vcpu *vcpu) 3056void kvm_emulate_cpuid(struct kvm_vcpu *vcpu)
3016{ 3057{
3017 u32 function, index; 3058 u32 function, index;
@@ -3048,10 +3089,9 @@ EXPORT_SYMBOL_GPL(kvm_emulate_cpuid);
3048static int dm_request_for_irq_injection(struct kvm_vcpu *vcpu, 3089static int dm_request_for_irq_injection(struct kvm_vcpu *vcpu,
3049 struct kvm_run *kvm_run) 3090 struct kvm_run *kvm_run)
3050{ 3091{
3051 return (!vcpu->arch.irq_summary && 3092 return (!irqchip_in_kernel(vcpu->kvm) && !kvm_cpu_has_interrupt(vcpu) &&
3052 kvm_run->request_interrupt_window && 3093 kvm_run->request_interrupt_window &&
3053 vcpu->arch.interrupt_window_open && 3094 kvm_arch_interrupt_allowed(vcpu));
3054 (kvm_x86_ops->get_rflags(vcpu) & X86_EFLAGS_IF));
3055} 3095}
3056 3096
3057static void post_kvm_run_save(struct kvm_vcpu *vcpu, 3097static void post_kvm_run_save(struct kvm_vcpu *vcpu,
@@ -3064,8 +3104,9 @@ static void post_kvm_run_save(struct kvm_vcpu *vcpu,
3064 kvm_run->ready_for_interrupt_injection = 1; 3104 kvm_run->ready_for_interrupt_injection = 1;
3065 else 3105 else
3066 kvm_run->ready_for_interrupt_injection = 3106 kvm_run->ready_for_interrupt_injection =
3067 (vcpu->arch.interrupt_window_open && 3107 kvm_arch_interrupt_allowed(vcpu) &&
3068 vcpu->arch.irq_summary == 0); 3108 !kvm_cpu_has_interrupt(vcpu) &&
3109 !kvm_event_needs_reinjection(vcpu);
3069} 3110}
3070 3111
3071static void vapic_enter(struct kvm_vcpu *vcpu) 3112static void vapic_enter(struct kvm_vcpu *vcpu)
@@ -3094,9 +3135,63 @@ static void vapic_exit(struct kvm_vcpu *vcpu)
3094 up_read(&vcpu->kvm->slots_lock); 3135 up_read(&vcpu->kvm->slots_lock);
3095} 3136}
3096 3137
3138static void update_cr8_intercept(struct kvm_vcpu *vcpu)
3139{
3140 int max_irr, tpr;
3141
3142 if (!kvm_x86_ops->update_cr8_intercept)
3143 return;
3144
3145 if (!vcpu->arch.apic->vapic_addr)
3146 max_irr = kvm_lapic_find_highest_irr(vcpu);
3147 else
3148 max_irr = -1;
3149
3150 if (max_irr != -1)
3151 max_irr >>= 4;
3152
3153 tpr = kvm_lapic_get_cr8(vcpu);
3154
3155 kvm_x86_ops->update_cr8_intercept(vcpu, tpr, max_irr);
3156}
3157
3158static void inject_pending_irq(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3159{
3160 if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
3161 kvm_x86_ops->set_interrupt_shadow(vcpu, 0);
3162
3163 /* try to reinject previous events if any */
3164 if (vcpu->arch.nmi_injected) {
3165 kvm_x86_ops->set_nmi(vcpu);
3166 return;
3167 }
3168
3169 if (vcpu->arch.interrupt.pending) {
3170 kvm_x86_ops->set_irq(vcpu);
3171 return;
3172 }
3173
3174 /* try to inject new event if pending */
3175 if (vcpu->arch.nmi_pending) {
3176 if (kvm_x86_ops->nmi_allowed(vcpu)) {
3177 vcpu->arch.nmi_pending = false;
3178 vcpu->arch.nmi_injected = true;
3179 kvm_x86_ops->set_nmi(vcpu);
3180 }
3181 } else if (kvm_cpu_has_interrupt(vcpu)) {
3182 if (kvm_x86_ops->interrupt_allowed(vcpu)) {
3183 kvm_queue_interrupt(vcpu, kvm_cpu_get_interrupt(vcpu),
3184 false);
3185 kvm_x86_ops->set_irq(vcpu);
3186 }
3187 }
3188}
3189
3097static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 3190static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3098{ 3191{
3099 int r; 3192 int r;
3193 bool req_int_win = !irqchip_in_kernel(vcpu->kvm) &&
3194 kvm_run->request_interrupt_window;
3100 3195
3101 if (vcpu->requests) 3196 if (vcpu->requests)
3102 if (test_and_clear_bit(KVM_REQ_MMU_RELOAD, &vcpu->requests)) 3197 if (test_and_clear_bit(KVM_REQ_MMU_RELOAD, &vcpu->requests))
@@ -3128,9 +3223,6 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3128 } 3223 }
3129 } 3224 }
3130 3225
3131 clear_bit(KVM_REQ_PENDING_TIMER, &vcpu->requests);
3132 kvm_inject_pending_timer_irqs(vcpu);
3133
3134 preempt_disable(); 3226 preempt_disable();
3135 3227
3136 kvm_x86_ops->prepare_guest_switch(vcpu); 3228 kvm_x86_ops->prepare_guest_switch(vcpu);
@@ -3138,6 +3230,9 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3138 3230
3139 local_irq_disable(); 3231 local_irq_disable();
3140 3232
3233 clear_bit(KVM_REQ_KICK, &vcpu->requests);
3234 smp_mb__after_clear_bit();
3235
3141 if (vcpu->requests || need_resched() || signal_pending(current)) { 3236 if (vcpu->requests || need_resched() || signal_pending(current)) {
3142 local_irq_enable(); 3237 local_irq_enable();
3143 preempt_enable(); 3238 preempt_enable();
@@ -3145,21 +3240,21 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3145 goto out; 3240 goto out;
3146 } 3241 }
3147 3242
3148 vcpu->guest_mode = 1;
3149 /*
3150 * Make sure that guest_mode assignment won't happen after
3151 * testing the pending IRQ vector bitmap.
3152 */
3153 smp_wmb();
3154
3155 if (vcpu->arch.exception.pending) 3243 if (vcpu->arch.exception.pending)
3156 __queue_exception(vcpu); 3244 __queue_exception(vcpu);
3157 else if (irqchip_in_kernel(vcpu->kvm))
3158 kvm_x86_ops->inject_pending_irq(vcpu);
3159 else 3245 else
3160 kvm_x86_ops->inject_pending_vectors(vcpu, kvm_run); 3246 inject_pending_irq(vcpu, kvm_run);
3161 3247
3162 kvm_lapic_sync_to_vapic(vcpu); 3248 /* enable NMI/IRQ window open exits if needed */
3249 if (vcpu->arch.nmi_pending)
3250 kvm_x86_ops->enable_nmi_window(vcpu);
3251 else if (kvm_cpu_has_interrupt(vcpu) || req_int_win)
3252 kvm_x86_ops->enable_irq_window(vcpu);
3253
3254 if (kvm_lapic_enabled(vcpu)) {
3255 update_cr8_intercept(vcpu);
3256 kvm_lapic_sync_to_vapic(vcpu);
3257 }
3163 3258
3164 up_read(&vcpu->kvm->slots_lock); 3259 up_read(&vcpu->kvm->slots_lock);
3165 3260
@@ -3193,7 +3288,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3193 set_debugreg(vcpu->arch.host_dr6, 6); 3288 set_debugreg(vcpu->arch.host_dr6, 6);
3194 set_debugreg(vcpu->arch.host_dr7, 7); 3289 set_debugreg(vcpu->arch.host_dr7, 7);
3195 3290
3196 vcpu->guest_mode = 0; 3291 set_bit(KVM_REQ_KICK, &vcpu->requests);
3197 local_irq_enable(); 3292 local_irq_enable();
3198 3293
3199 ++vcpu->stat.exits; 3294 ++vcpu->stat.exits;
@@ -3220,8 +3315,6 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3220 profile_hit(KVM_PROFILING, (void *)rip); 3315 profile_hit(KVM_PROFILING, (void *)rip);
3221 } 3316 }
3222 3317
3223 if (vcpu->arch.exception.pending && kvm_x86_ops->exception_injected(vcpu))
3224 vcpu->arch.exception.pending = false;
3225 3318
3226 kvm_lapic_sync_from_vapic(vcpu); 3319 kvm_lapic_sync_from_vapic(vcpu);
3227 3320
@@ -3230,6 +3323,7 @@ out:
3230 return r; 3323 return r;
3231} 3324}
3232 3325
3326
3233static int __vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 3327static int __vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3234{ 3328{
3235 int r; 3329 int r;
@@ -3256,29 +3350,42 @@ static int __vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
3256 kvm_vcpu_block(vcpu); 3350 kvm_vcpu_block(vcpu);
3257 down_read(&vcpu->kvm->slots_lock); 3351 down_read(&vcpu->kvm->slots_lock);
3258 if (test_and_clear_bit(KVM_REQ_UNHALT, &vcpu->requests)) 3352 if (test_and_clear_bit(KVM_REQ_UNHALT, &vcpu->requests))
3259 if (vcpu->arch.mp_state == KVM_MP_STATE_HALTED) 3353 {
3354 switch(vcpu->arch.mp_state) {
3355 case KVM_MP_STATE_HALTED:
3260 vcpu->arch.mp_state = 3356 vcpu->arch.mp_state =
3261 KVM_MP_STATE_RUNNABLE; 3357 KVM_MP_STATE_RUNNABLE;
3262 if (vcpu->arch.mp_state != KVM_MP_STATE_RUNNABLE) 3358 case KVM_MP_STATE_RUNNABLE:
3263 r = -EINTR; 3359 break;
3360 case KVM_MP_STATE_SIPI_RECEIVED:
3361 default:
3362 r = -EINTR;
3363 break;
3364 }
3365 }
3264 } 3366 }
3265 3367
3266 if (r > 0) { 3368 if (r <= 0)
3267 if (dm_request_for_irq_injection(vcpu, kvm_run)) { 3369 break;
3268 r = -EINTR; 3370
3269 kvm_run->exit_reason = KVM_EXIT_INTR; 3371 clear_bit(KVM_REQ_PENDING_TIMER, &vcpu->requests);
3270 ++vcpu->stat.request_irq_exits; 3372 if (kvm_cpu_has_pending_timer(vcpu))
3271 } 3373 kvm_inject_pending_timer_irqs(vcpu);
3272 if (signal_pending(current)) { 3374
3273 r = -EINTR; 3375 if (dm_request_for_irq_injection(vcpu, kvm_run)) {
3274 kvm_run->exit_reason = KVM_EXIT_INTR; 3376 r = -EINTR;
3275 ++vcpu->stat.signal_exits; 3377 kvm_run->exit_reason = KVM_EXIT_INTR;
3276 } 3378 ++vcpu->stat.request_irq_exits;
3277 if (need_resched()) { 3379 }
3278 up_read(&vcpu->kvm->slots_lock); 3380 if (signal_pending(current)) {
3279 kvm_resched(vcpu); 3381 r = -EINTR;
3280 down_read(&vcpu->kvm->slots_lock); 3382 kvm_run->exit_reason = KVM_EXIT_INTR;
3281 } 3383 ++vcpu->stat.signal_exits;
3384 }
3385 if (need_resched()) {
3386 up_read(&vcpu->kvm->slots_lock);
3387 kvm_resched(vcpu);
3388 down_read(&vcpu->kvm->slots_lock);
3282 } 3389 }
3283 } 3390 }
3284 3391
@@ -3442,7 +3549,6 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
3442 struct kvm_sregs *sregs) 3549 struct kvm_sregs *sregs)
3443{ 3550{
3444 struct descriptor_table dt; 3551 struct descriptor_table dt;
3445 int pending_vec;
3446 3552
3447 vcpu_load(vcpu); 3553 vcpu_load(vcpu);
3448 3554
@@ -3472,16 +3578,11 @@ int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
3472 sregs->efer = vcpu->arch.shadow_efer; 3578 sregs->efer = vcpu->arch.shadow_efer;
3473 sregs->apic_base = kvm_get_apic_base(vcpu); 3579 sregs->apic_base = kvm_get_apic_base(vcpu);
3474 3580
3475 if (irqchip_in_kernel(vcpu->kvm)) { 3581 memset(sregs->interrupt_bitmap, 0, sizeof sregs->interrupt_bitmap);
3476 memset(sregs->interrupt_bitmap, 0, 3582
3477 sizeof sregs->interrupt_bitmap); 3583 if (vcpu->arch.interrupt.pending && !vcpu->arch.interrupt.soft)
3478 pending_vec = kvm_x86_ops->get_irq(vcpu); 3584 set_bit(vcpu->arch.interrupt.nr,
3479 if (pending_vec >= 0) 3585 (unsigned long *)sregs->interrupt_bitmap);
3480 set_bit(pending_vec,
3481 (unsigned long *)sregs->interrupt_bitmap);
3482 } else
3483 memcpy(sregs->interrupt_bitmap, vcpu->arch.irq_pending,
3484 sizeof sregs->interrupt_bitmap);
3485 3586
3486 vcpu_put(vcpu); 3587 vcpu_put(vcpu);
3487 3588
@@ -3688,7 +3789,6 @@ static void save_state_to_tss32(struct kvm_vcpu *vcpu,
3688 tss->fs = get_segment_selector(vcpu, VCPU_SREG_FS); 3789 tss->fs = get_segment_selector(vcpu, VCPU_SREG_FS);
3689 tss->gs = get_segment_selector(vcpu, VCPU_SREG_GS); 3790 tss->gs = get_segment_selector(vcpu, VCPU_SREG_GS);
3690 tss->ldt_selector = get_segment_selector(vcpu, VCPU_SREG_LDTR); 3791 tss->ldt_selector = get_segment_selector(vcpu, VCPU_SREG_LDTR);
3691 tss->prev_task_link = get_segment_selector(vcpu, VCPU_SREG_TR);
3692} 3792}
3693 3793
3694static int load_state_from_tss32(struct kvm_vcpu *vcpu, 3794static int load_state_from_tss32(struct kvm_vcpu *vcpu,
@@ -3785,8 +3885,8 @@ static int load_state_from_tss16(struct kvm_vcpu *vcpu,
3785} 3885}
3786 3886
3787static int kvm_task_switch_16(struct kvm_vcpu *vcpu, u16 tss_selector, 3887static int kvm_task_switch_16(struct kvm_vcpu *vcpu, u16 tss_selector,
3788 u32 old_tss_base, 3888 u16 old_tss_sel, u32 old_tss_base,
3789 struct desc_struct *nseg_desc) 3889 struct desc_struct *nseg_desc)
3790{ 3890{
3791 struct tss_segment_16 tss_segment_16; 3891 struct tss_segment_16 tss_segment_16;
3792 int ret = 0; 3892 int ret = 0;
@@ -3805,6 +3905,16 @@ static int kvm_task_switch_16(struct kvm_vcpu *vcpu, u16 tss_selector,
3805 &tss_segment_16, sizeof tss_segment_16)) 3905 &tss_segment_16, sizeof tss_segment_16))
3806 goto out; 3906 goto out;
3807 3907
3908 if (old_tss_sel != 0xffff) {
3909 tss_segment_16.prev_task_link = old_tss_sel;
3910
3911 if (kvm_write_guest(vcpu->kvm,
3912 get_tss_base_addr(vcpu, nseg_desc),
3913 &tss_segment_16.prev_task_link,
3914 sizeof tss_segment_16.prev_task_link))
3915 goto out;
3916 }
3917
3808 if (load_state_from_tss16(vcpu, &tss_segment_16)) 3918 if (load_state_from_tss16(vcpu, &tss_segment_16))
3809 goto out; 3919 goto out;
3810 3920
@@ -3814,7 +3924,7 @@ out:
3814} 3924}
3815 3925
3816static int kvm_task_switch_32(struct kvm_vcpu *vcpu, u16 tss_selector, 3926static int kvm_task_switch_32(struct kvm_vcpu *vcpu, u16 tss_selector,
3817 u32 old_tss_base, 3927 u16 old_tss_sel, u32 old_tss_base,
3818 struct desc_struct *nseg_desc) 3928 struct desc_struct *nseg_desc)
3819{ 3929{
3820 struct tss_segment_32 tss_segment_32; 3930 struct tss_segment_32 tss_segment_32;
@@ -3834,6 +3944,16 @@ static int kvm_task_switch_32(struct kvm_vcpu *vcpu, u16 tss_selector,
3834 &tss_segment_32, sizeof tss_segment_32)) 3944 &tss_segment_32, sizeof tss_segment_32))
3835 goto out; 3945 goto out;
3836 3946
3947 if (old_tss_sel != 0xffff) {
3948 tss_segment_32.prev_task_link = old_tss_sel;
3949
3950 if (kvm_write_guest(vcpu->kvm,
3951 get_tss_base_addr(vcpu, nseg_desc),
3952 &tss_segment_32.prev_task_link,
3953 sizeof tss_segment_32.prev_task_link))
3954 goto out;
3955 }
3956
3837 if (load_state_from_tss32(vcpu, &tss_segment_32)) 3957 if (load_state_from_tss32(vcpu, &tss_segment_32))
3838 goto out; 3958 goto out;
3839 3959
@@ -3887,14 +4007,22 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int reason)
3887 kvm_x86_ops->set_rflags(vcpu, eflags & ~X86_EFLAGS_NT); 4007 kvm_x86_ops->set_rflags(vcpu, eflags & ~X86_EFLAGS_NT);
3888 } 4008 }
3889 4009
3890 kvm_x86_ops->skip_emulated_instruction(vcpu); 4010 /* set back link to prev task only if NT bit is set in eflags
4011 note that old_tss_sel is not used afetr this point */
4012 if (reason != TASK_SWITCH_CALL && reason != TASK_SWITCH_GATE)
4013 old_tss_sel = 0xffff;
4014
4015 /* set back link to prev task only if NT bit is set in eflags
4016 note that old_tss_sel is not used afetr this point */
4017 if (reason != TASK_SWITCH_CALL && reason != TASK_SWITCH_GATE)
4018 old_tss_sel = 0xffff;
3891 4019
3892 if (nseg_desc.type & 8) 4020 if (nseg_desc.type & 8)
3893 ret = kvm_task_switch_32(vcpu, tss_selector, old_tss_base, 4021 ret = kvm_task_switch_32(vcpu, tss_selector, old_tss_sel,
3894 &nseg_desc); 4022 old_tss_base, &nseg_desc);
3895 else 4023 else
3896 ret = kvm_task_switch_16(vcpu, tss_selector, old_tss_base, 4024 ret = kvm_task_switch_16(vcpu, tss_selector, old_tss_sel,
3897 &nseg_desc); 4025 old_tss_base, &nseg_desc);
3898 4026
3899 if (reason == TASK_SWITCH_CALL || reason == TASK_SWITCH_GATE) { 4027 if (reason == TASK_SWITCH_CALL || reason == TASK_SWITCH_GATE) {
3900 u32 eflags = kvm_x86_ops->get_rflags(vcpu); 4028 u32 eflags = kvm_x86_ops->get_rflags(vcpu);
@@ -3920,7 +4048,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
3920 struct kvm_sregs *sregs) 4048 struct kvm_sregs *sregs)
3921{ 4049{
3922 int mmu_reset_needed = 0; 4050 int mmu_reset_needed = 0;
3923 int i, pending_vec, max_bits; 4051 int pending_vec, max_bits;
3924 struct descriptor_table dt; 4052 struct descriptor_table dt;
3925 4053
3926 vcpu_load(vcpu); 4054 vcpu_load(vcpu);
@@ -3934,7 +4062,13 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
3934 4062
3935 vcpu->arch.cr2 = sregs->cr2; 4063 vcpu->arch.cr2 = sregs->cr2;
3936 mmu_reset_needed |= vcpu->arch.cr3 != sregs->cr3; 4064 mmu_reset_needed |= vcpu->arch.cr3 != sregs->cr3;
3937 vcpu->arch.cr3 = sregs->cr3; 4065
4066 down_read(&vcpu->kvm->slots_lock);
4067 if (gfn_to_memslot(vcpu->kvm, sregs->cr3 >> PAGE_SHIFT))
4068 vcpu->arch.cr3 = sregs->cr3;
4069 else
4070 set_bit(KVM_REQ_TRIPLE_FAULT, &vcpu->requests);
4071 up_read(&vcpu->kvm->slots_lock);
3938 4072
3939 kvm_set_cr8(vcpu, sregs->cr8); 4073 kvm_set_cr8(vcpu, sregs->cr8);
3940 4074
@@ -3956,25 +4090,14 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
3956 if (mmu_reset_needed) 4090 if (mmu_reset_needed)
3957 kvm_mmu_reset_context(vcpu); 4091 kvm_mmu_reset_context(vcpu);
3958 4092
3959 if (!irqchip_in_kernel(vcpu->kvm)) { 4093 max_bits = (sizeof sregs->interrupt_bitmap) << 3;
3960 memcpy(vcpu->arch.irq_pending, sregs->interrupt_bitmap, 4094 pending_vec = find_first_bit(
3961 sizeof vcpu->arch.irq_pending); 4095 (const unsigned long *)sregs->interrupt_bitmap, max_bits);
3962 vcpu->arch.irq_summary = 0; 4096 if (pending_vec < max_bits) {
3963 for (i = 0; i < ARRAY_SIZE(vcpu->arch.irq_pending); ++i) 4097 kvm_queue_interrupt(vcpu, pending_vec, false);
3964 if (vcpu->arch.irq_pending[i]) 4098 pr_debug("Set back pending irq %d\n", pending_vec);
3965 __set_bit(i, &vcpu->arch.irq_summary); 4099 if (irqchip_in_kernel(vcpu->kvm))
3966 } else { 4100 kvm_pic_clear_isr_ack(vcpu->kvm);
3967 max_bits = (sizeof sregs->interrupt_bitmap) << 3;
3968 pending_vec = find_first_bit(
3969 (const unsigned long *)sregs->interrupt_bitmap,
3970 max_bits);
3971 /* Only pending external irq is handled here */
3972 if (pending_vec < max_bits) {
3973 kvm_x86_ops->set_irq(vcpu, pending_vec);
3974 pr_debug("Set back pending irq %d\n",
3975 pending_vec);
3976 }
3977 kvm_pic_clear_isr_ack(vcpu->kvm);
3978 } 4101 }
3979 4102
3980 kvm_set_segment(vcpu, &sregs->cs, VCPU_SREG_CS); 4103 kvm_set_segment(vcpu, &sregs->cs, VCPU_SREG_CS);
@@ -4308,7 +4431,6 @@ struct kvm *kvm_arch_create_vm(void)
4308 return ERR_PTR(-ENOMEM); 4431 return ERR_PTR(-ENOMEM);
4309 4432
4310 INIT_LIST_HEAD(&kvm->arch.active_mmu_pages); 4433 INIT_LIST_HEAD(&kvm->arch.active_mmu_pages);
4311 INIT_LIST_HEAD(&kvm->arch.oos_global_pages);
4312 INIT_LIST_HEAD(&kvm->arch.assigned_dev_head); 4434 INIT_LIST_HEAD(&kvm->arch.assigned_dev_head);
4313 4435
4314 /* Reserve bit 0 of irq_sources_bitmap for userspace irq source */ 4436 /* Reserve bit 0 of irq_sources_bitmap for userspace irq source */
@@ -4411,12 +4533,14 @@ int kvm_arch_set_memory_region(struct kvm *kvm,
4411 } 4533 }
4412 } 4534 }
4413 4535
4536 spin_lock(&kvm->mmu_lock);
4414 if (!kvm->arch.n_requested_mmu_pages) { 4537 if (!kvm->arch.n_requested_mmu_pages) {
4415 unsigned int nr_mmu_pages = kvm_mmu_calculate_mmu_pages(kvm); 4538 unsigned int nr_mmu_pages = kvm_mmu_calculate_mmu_pages(kvm);
4416 kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages); 4539 kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
4417 } 4540 }
4418 4541
4419 kvm_mmu_slot_remove_write_access(kvm, mem->slot); 4542 kvm_mmu_slot_remove_write_access(kvm, mem->slot);
4543 spin_unlock(&kvm->mmu_lock);
4420 kvm_flush_remote_tlbs(kvm); 4544 kvm_flush_remote_tlbs(kvm);
4421 4545
4422 return 0; 4546 return 0;
@@ -4425,6 +4549,7 @@ int kvm_arch_set_memory_region(struct kvm *kvm,
4425void kvm_arch_flush_shadow(struct kvm *kvm) 4549void kvm_arch_flush_shadow(struct kvm *kvm)
4426{ 4550{
4427 kvm_mmu_zap_all(kvm); 4551 kvm_mmu_zap_all(kvm);
4552 kvm_reload_remote_mmus(kvm);
4428} 4553}
4429 4554
4430int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu) 4555int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
@@ -4434,28 +4559,24 @@ int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
4434 || vcpu->arch.nmi_pending; 4559 || vcpu->arch.nmi_pending;
4435} 4560}
4436 4561
4437static void vcpu_kick_intr(void *info)
4438{
4439#ifdef DEBUG
4440 struct kvm_vcpu *vcpu = (struct kvm_vcpu *)info;
4441 printk(KERN_DEBUG "vcpu_kick_intr %p \n", vcpu);
4442#endif
4443}
4444
4445void kvm_vcpu_kick(struct kvm_vcpu *vcpu) 4562void kvm_vcpu_kick(struct kvm_vcpu *vcpu)
4446{ 4563{
4447 int ipi_pcpu = vcpu->cpu; 4564 int me;
4448 int cpu = get_cpu(); 4565 int cpu = vcpu->cpu;
4449 4566
4450 if (waitqueue_active(&vcpu->wq)) { 4567 if (waitqueue_active(&vcpu->wq)) {
4451 wake_up_interruptible(&vcpu->wq); 4568 wake_up_interruptible(&vcpu->wq);
4452 ++vcpu->stat.halt_wakeup; 4569 ++vcpu->stat.halt_wakeup;
4453 } 4570 }
4454 /* 4571
4455 * We may be called synchronously with irqs disabled in guest mode, 4572 me = get_cpu();
4456 * So need not to call smp_call_function_single() in that case. 4573 if (cpu != me && (unsigned)cpu < nr_cpu_ids && cpu_online(cpu))
4457 */ 4574 if (!test_and_set_bit(KVM_REQ_KICK, &vcpu->requests))
4458 if (vcpu->guest_mode && vcpu->cpu != cpu) 4575 smp_send_reschedule(cpu);
4459 smp_call_function_single(ipi_pcpu, vcpu_kick_intr, vcpu, 0);
4460 put_cpu(); 4576 put_cpu();
4461} 4577}
4578
4579int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu)
4580{
4581 return kvm_x86_ops->interrupt_allowed(vcpu);
4582}
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 6a4be78a7384..4c8e10af78e8 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -8,9 +8,11 @@ static inline void kvm_clear_exception_queue(struct kvm_vcpu *vcpu)
8 vcpu->arch.exception.pending = false; 8 vcpu->arch.exception.pending = false;
9} 9}
10 10
11static inline void kvm_queue_interrupt(struct kvm_vcpu *vcpu, u8 vector) 11static inline void kvm_queue_interrupt(struct kvm_vcpu *vcpu, u8 vector,
12 bool soft)
12{ 13{
13 vcpu->arch.interrupt.pending = true; 14 vcpu->arch.interrupt.pending = true;
15 vcpu->arch.interrupt.soft = soft;
14 vcpu->arch.interrupt.nr = vector; 16 vcpu->arch.interrupt.nr = vector;
15} 17}
16 18
@@ -19,4 +21,14 @@ static inline void kvm_clear_interrupt_queue(struct kvm_vcpu *vcpu)
19 vcpu->arch.interrupt.pending = false; 21 vcpu->arch.interrupt.pending = false;
20} 22}
21 23
24static inline bool kvm_event_needs_reinjection(struct kvm_vcpu *vcpu)
25{
26 return vcpu->arch.exception.pending || vcpu->arch.interrupt.pending ||
27 vcpu->arch.nmi_injected;
28}
29
30static inline bool kvm_exception_is_soft(unsigned int nr)
31{
32 return (nr == BP_VECTOR) || (nr == OF_VECTOR);
33}
22#endif 34#endif
diff --git a/arch/x86/kvm/x86_emulate.c b/arch/x86/kvm/x86_emulate.c
index ca91749d2083..c1b6c232e02b 100644
--- a/arch/x86/kvm/x86_emulate.c
+++ b/arch/x86/kvm/x86_emulate.c
@@ -59,13 +59,14 @@
59#define SrcImm (5<<4) /* Immediate operand. */ 59#define SrcImm (5<<4) /* Immediate operand. */
60#define SrcImmByte (6<<4) /* 8-bit sign-extended immediate operand. */ 60#define SrcImmByte (6<<4) /* 8-bit sign-extended immediate operand. */
61#define SrcOne (7<<4) /* Implied '1' */ 61#define SrcOne (7<<4) /* Implied '1' */
62#define SrcMask (7<<4) 62#define SrcImmUByte (8<<4) /* 8-bit unsigned immediate operand. */
63#define SrcMask (0xf<<4)
63/* Generic ModRM decode. */ 64/* Generic ModRM decode. */
64#define ModRM (1<<7) 65#define ModRM (1<<8)
65/* Destination is only written; never read. */ 66/* Destination is only written; never read. */
66#define Mov (1<<8) 67#define Mov (1<<9)
67#define BitOp (1<<9) 68#define BitOp (1<<10)
68#define MemAbs (1<<10) /* Memory operand is absolute displacement */ 69#define MemAbs (1<<11) /* Memory operand is absolute displacement */
69#define String (1<<12) /* String instruction (rep capable) */ 70#define String (1<<12) /* String instruction (rep capable) */
70#define Stack (1<<13) /* Stack instruction (push/pop) */ 71#define Stack (1<<13) /* Stack instruction (push/pop) */
71#define Group (1<<14) /* Bits 3:5 of modrm byte extend opcode */ 72#define Group (1<<14) /* Bits 3:5 of modrm byte extend opcode */
@@ -76,6 +77,7 @@
76#define Src2CL (1<<29) 77#define Src2CL (1<<29)
77#define Src2ImmByte (2<<29) 78#define Src2ImmByte (2<<29)
78#define Src2One (3<<29) 79#define Src2One (3<<29)
80#define Src2Imm16 (4<<29)
79#define Src2Mask (7<<29) 81#define Src2Mask (7<<29)
80 82
81enum { 83enum {
@@ -135,11 +137,11 @@ static u32 opcode_table[256] = {
135 SrcNone | ByteOp | ImplicitOps, SrcNone | ImplicitOps, /* insb, insw/insd */ 137 SrcNone | ByteOp | ImplicitOps, SrcNone | ImplicitOps, /* insb, insw/insd */
136 SrcNone | ByteOp | ImplicitOps, SrcNone | ImplicitOps, /* outsb, outsw/outsd */ 138 SrcNone | ByteOp | ImplicitOps, SrcNone | ImplicitOps, /* outsb, outsw/outsd */
137 /* 0x70 - 0x77 */ 139 /* 0x70 - 0x77 */
138 ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, 140 SrcImmByte, SrcImmByte, SrcImmByte, SrcImmByte,
139 ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, 141 SrcImmByte, SrcImmByte, SrcImmByte, SrcImmByte,
140 /* 0x78 - 0x7F */ 142 /* 0x78 - 0x7F */
141 ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, 143 SrcImmByte, SrcImmByte, SrcImmByte, SrcImmByte,
142 ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, 144 SrcImmByte, SrcImmByte, SrcImmByte, SrcImmByte,
143 /* 0x80 - 0x87 */ 145 /* 0x80 - 0x87 */
144 Group | Group1_80, Group | Group1_81, 146 Group | Group1_80, Group | Group1_81,
145 Group | Group1_82, Group | Group1_83, 147 Group | Group1_82, Group | Group1_83,
@@ -153,7 +155,8 @@ static u32 opcode_table[256] = {
153 /* 0x90 - 0x97 */ 155 /* 0x90 - 0x97 */
154 DstReg, DstReg, DstReg, DstReg, DstReg, DstReg, DstReg, DstReg, 156 DstReg, DstReg, DstReg, DstReg, DstReg, DstReg, DstReg, DstReg,
155 /* 0x98 - 0x9F */ 157 /* 0x98 - 0x9F */
156 0, 0, 0, 0, ImplicitOps | Stack, ImplicitOps | Stack, 0, 0, 158 0, 0, SrcImm | Src2Imm16, 0,
159 ImplicitOps | Stack, ImplicitOps | Stack, 0, 0,
157 /* 0xA0 - 0xA7 */ 160 /* 0xA0 - 0xA7 */
158 ByteOp | DstReg | SrcMem | Mov | MemAbs, DstReg | SrcMem | Mov | MemAbs, 161 ByteOp | DstReg | SrcMem | Mov | MemAbs, DstReg | SrcMem | Mov | MemAbs,
159 ByteOp | DstMem | SrcReg | Mov | MemAbs, DstMem | SrcReg | Mov | MemAbs, 162 ByteOp | DstMem | SrcReg | Mov | MemAbs, DstMem | SrcReg | Mov | MemAbs,
@@ -178,7 +181,8 @@ static u32 opcode_table[256] = {
178 0, ImplicitOps | Stack, 0, 0, 181 0, ImplicitOps | Stack, 0, 0,
179 ByteOp | DstMem | SrcImm | ModRM | Mov, DstMem | SrcImm | ModRM | Mov, 182 ByteOp | DstMem | SrcImm | ModRM | Mov, DstMem | SrcImm | ModRM | Mov,
180 /* 0xC8 - 0xCF */ 183 /* 0xC8 - 0xCF */
181 0, 0, 0, ImplicitOps | Stack, 0, 0, 0, 0, 184 0, 0, 0, ImplicitOps | Stack,
185 ImplicitOps, SrcImmByte, ImplicitOps, ImplicitOps,
182 /* 0xD0 - 0xD7 */ 186 /* 0xD0 - 0xD7 */
183 ByteOp | DstMem | SrcImplicit | ModRM, DstMem | SrcImplicit | ModRM, 187 ByteOp | DstMem | SrcImplicit | ModRM, DstMem | SrcImplicit | ModRM,
184 ByteOp | DstMem | SrcImplicit | ModRM, DstMem | SrcImplicit | ModRM, 188 ByteOp | DstMem | SrcImplicit | ModRM, DstMem | SrcImplicit | ModRM,
@@ -187,11 +191,11 @@ static u32 opcode_table[256] = {
187 0, 0, 0, 0, 0, 0, 0, 0, 191 0, 0, 0, 0, 0, 0, 0, 0,
188 /* 0xE0 - 0xE7 */ 192 /* 0xE0 - 0xE7 */
189 0, 0, 0, 0, 193 0, 0, 0, 0,
190 SrcNone | ByteOp | ImplicitOps, SrcNone | ImplicitOps, 194 ByteOp | SrcImmUByte, SrcImmUByte,
191 SrcNone | ByteOp | ImplicitOps, SrcNone | ImplicitOps, 195 ByteOp | SrcImmUByte, SrcImmUByte,
192 /* 0xE8 - 0xEF */ 196 /* 0xE8 - 0xEF */
193 ImplicitOps | Stack, SrcImm | ImplicitOps, 197 SrcImm | Stack, SrcImm | ImplicitOps,
194 ImplicitOps, SrcImmByte | ImplicitOps, 198 SrcImm | Src2Imm16, SrcImmByte | ImplicitOps,
195 SrcNone | ByteOp | ImplicitOps, SrcNone | ImplicitOps, 199 SrcNone | ByteOp | ImplicitOps, SrcNone | ImplicitOps,
196 SrcNone | ByteOp | ImplicitOps, SrcNone | ImplicitOps, 200 SrcNone | ByteOp | ImplicitOps, SrcNone | ImplicitOps,
197 /* 0xF0 - 0xF7 */ 201 /* 0xF0 - 0xF7 */
@@ -230,10 +234,8 @@ static u32 twobyte_table[256] = {
230 /* 0x70 - 0x7F */ 234 /* 0x70 - 0x7F */
231 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 235 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
232 /* 0x80 - 0x8F */ 236 /* 0x80 - 0x8F */
233 ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, 237 SrcImm, SrcImm, SrcImm, SrcImm, SrcImm, SrcImm, SrcImm, SrcImm,
234 ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps, 238 SrcImm, SrcImm, SrcImm, SrcImm, SrcImm, SrcImm, SrcImm, SrcImm,
235 ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
236 ImplicitOps, ImplicitOps, ImplicitOps, ImplicitOps,
237 /* 0x90 - 0x9F */ 239 /* 0x90 - 0x9F */
238 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
239 /* 0xA0 - 0xA7 */ 241 /* 0xA0 - 0xA7 */
@@ -1044,10 +1046,14 @@ done_prefixes:
1044 } 1046 }
1045 break; 1047 break;
1046 case SrcImmByte: 1048 case SrcImmByte:
1049 case SrcImmUByte:
1047 c->src.type = OP_IMM; 1050 c->src.type = OP_IMM;
1048 c->src.ptr = (unsigned long *)c->eip; 1051 c->src.ptr = (unsigned long *)c->eip;
1049 c->src.bytes = 1; 1052 c->src.bytes = 1;
1050 c->src.val = insn_fetch(s8, 1, c->eip); 1053 if ((c->d & SrcMask) == SrcImmByte)
1054 c->src.val = insn_fetch(s8, 1, c->eip);
1055 else
1056 c->src.val = insn_fetch(u8, 1, c->eip);
1051 break; 1057 break;
1052 case SrcOne: 1058 case SrcOne:
1053 c->src.bytes = 1; 1059 c->src.bytes = 1;
@@ -1072,6 +1078,12 @@ done_prefixes:
1072 c->src2.bytes = 1; 1078 c->src2.bytes = 1;
1073 c->src2.val = insn_fetch(u8, 1, c->eip); 1079 c->src2.val = insn_fetch(u8, 1, c->eip);
1074 break; 1080 break;
1081 case Src2Imm16:
1082 c->src2.type = OP_IMM;
1083 c->src2.ptr = (unsigned long *)c->eip;
1084 c->src2.bytes = 2;
1085 c->src2.val = insn_fetch(u16, 2, c->eip);
1086 break;
1075 case Src2One: 1087 case Src2One:
1076 c->src2.bytes = 1; 1088 c->src2.bytes = 1;
1077 c->src2.val = 1; 1089 c->src2.val = 1;
@@ -1349,6 +1361,20 @@ static inline int writeback(struct x86_emulate_ctxt *ctxt,
1349 return 0; 1361 return 0;
1350} 1362}
1351 1363
1364void toggle_interruptibility(struct x86_emulate_ctxt *ctxt, u32 mask)
1365{
1366 u32 int_shadow = kvm_x86_ops->get_interrupt_shadow(ctxt->vcpu, mask);
1367 /*
1368 * an sti; sti; sequence only disable interrupts for the first
1369 * instruction. So, if the last instruction, be it emulated or
1370 * not, left the system with the INT_STI flag enabled, it
1371 * means that the last instruction is an sti. We should not
1372 * leave the flag on in this case. The same goes for mov ss
1373 */
1374 if (!(int_shadow & mask))
1375 ctxt->interruptibility = mask;
1376}
1377
1352int 1378int
1353x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops) 1379x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
1354{ 1380{
@@ -1360,6 +1386,8 @@ x86_emulate_insn(struct x86_emulate_ctxt *ctxt, struct x86_emulate_ops *ops)
1360 int io_dir_in; 1386 int io_dir_in;
1361 int rc = 0; 1387 int rc = 0;
1362 1388
1389 ctxt->interruptibility = 0;
1390
1363 /* Shadow copy of register state. Committed on successful emulation. 1391 /* Shadow copy of register state. Committed on successful emulation.
1364 * NOTE: we can copy them from vcpu as x86_decode_insn() doesn't 1392 * NOTE: we can copy them from vcpu as x86_decode_insn() doesn't
1365 * modify them. 1393 * modify them.
@@ -1531,13 +1559,10 @@ special_insn:
1531 return -1; 1559 return -1;
1532 } 1560 }
1533 return 0; 1561 return 0;
1534 case 0x70 ... 0x7f: /* jcc (short) */ { 1562 case 0x70 ... 0x7f: /* jcc (short) */
1535 int rel = insn_fetch(s8, 1, c->eip);
1536
1537 if (test_cc(c->b, ctxt->eflags)) 1563 if (test_cc(c->b, ctxt->eflags))
1538 jmp_rel(c, rel); 1564 jmp_rel(c, c->src.val);
1539 break; 1565 break;
1540 }
1541 case 0x80 ... 0x83: /* Grp1 */ 1566 case 0x80 ... 0x83: /* Grp1 */
1542 switch (c->modrm_reg) { 1567 switch (c->modrm_reg) {
1543 case 0: 1568 case 0:
@@ -1609,6 +1634,9 @@ special_insn:
1609 int err; 1634 int err;
1610 1635
1611 sel = c->src.val; 1636 sel = c->src.val;
1637 if (c->modrm_reg == VCPU_SREG_SS)
1638 toggle_interruptibility(ctxt, X86_SHADOW_INT_MOV_SS);
1639
1612 if (c->modrm_reg <= 5) { 1640 if (c->modrm_reg <= 5) {
1613 type_bits = (c->modrm_reg == 1) ? 9 : 1; 1641 type_bits = (c->modrm_reg == 1) ? 9 : 1;
1614 err = kvm_load_segment_descriptor(ctxt->vcpu, sel, 1642 err = kvm_load_segment_descriptor(ctxt->vcpu, sel,
@@ -1769,59 +1797,32 @@ special_insn:
1769 break; 1797 break;
1770 case 0xe4: /* inb */ 1798 case 0xe4: /* inb */
1771 case 0xe5: /* in */ 1799 case 0xe5: /* in */
1772 port = insn_fetch(u8, 1, c->eip); 1800 port = c->src.val;
1773 io_dir_in = 1; 1801 io_dir_in = 1;
1774 goto do_io; 1802 goto do_io;
1775 case 0xe6: /* outb */ 1803 case 0xe6: /* outb */
1776 case 0xe7: /* out */ 1804 case 0xe7: /* out */
1777 port = insn_fetch(u8, 1, c->eip); 1805 port = c->src.val;
1778 io_dir_in = 0; 1806 io_dir_in = 0;
1779 goto do_io; 1807 goto do_io;
1780 case 0xe8: /* call (near) */ { 1808 case 0xe8: /* call (near) */ {
1781 long int rel; 1809 long int rel = c->src.val;
1782 switch (c->op_bytes) {
1783 case 2:
1784 rel = insn_fetch(s16, 2, c->eip);
1785 break;
1786 case 4:
1787 rel = insn_fetch(s32, 4, c->eip);
1788 break;
1789 default:
1790 DPRINTF("Call: Invalid op_bytes\n");
1791 goto cannot_emulate;
1792 }
1793 c->src.val = (unsigned long) c->eip; 1810 c->src.val = (unsigned long) c->eip;
1794 jmp_rel(c, rel); 1811 jmp_rel(c, rel);
1795 c->op_bytes = c->ad_bytes;
1796 emulate_push(ctxt); 1812 emulate_push(ctxt);
1797 break; 1813 break;
1798 } 1814 }
1799 case 0xe9: /* jmp rel */ 1815 case 0xe9: /* jmp rel */
1800 goto jmp; 1816 goto jmp;
1801 case 0xea: /* jmp far */ { 1817 case 0xea: /* jmp far */
1802 uint32_t eip; 1818 if (kvm_load_segment_descriptor(ctxt->vcpu, c->src2.val, 9,
1803 uint16_t sel; 1819 VCPU_SREG_CS) < 0) {
1804
1805 switch (c->op_bytes) {
1806 case 2:
1807 eip = insn_fetch(u16, 2, c->eip);
1808 break;
1809 case 4:
1810 eip = insn_fetch(u32, 4, c->eip);
1811 break;
1812 default:
1813 DPRINTF("jmp far: Invalid op_bytes\n");
1814 goto cannot_emulate;
1815 }
1816 sel = insn_fetch(u16, 2, c->eip);
1817 if (kvm_load_segment_descriptor(ctxt->vcpu, sel, 9, VCPU_SREG_CS) < 0) {
1818 DPRINTF("jmp far: Failed to load CS descriptor\n"); 1820 DPRINTF("jmp far: Failed to load CS descriptor\n");
1819 goto cannot_emulate; 1821 goto cannot_emulate;
1820 } 1822 }
1821 1823
1822 c->eip = eip; 1824 c->eip = c->src.val;
1823 break; 1825 break;
1824 }
1825 case 0xeb: 1826 case 0xeb:
1826 jmp: /* jmp rel short */ 1827 jmp: /* jmp rel short */
1827 jmp_rel(c, c->src.val); 1828 jmp_rel(c, c->src.val);
@@ -1865,6 +1866,7 @@ special_insn:
1865 c->dst.type = OP_NONE; /* Disable writeback. */ 1866 c->dst.type = OP_NONE; /* Disable writeback. */
1866 break; 1867 break;
1867 case 0xfb: /* sti */ 1868 case 0xfb: /* sti */
1869 toggle_interruptibility(ctxt, X86_SHADOW_INT_STI);
1868 ctxt->eflags |= X86_EFLAGS_IF; 1870 ctxt->eflags |= X86_EFLAGS_IF;
1869 c->dst.type = OP_NONE; /* Disable writeback. */ 1871 c->dst.type = OP_NONE; /* Disable writeback. */
1870 break; 1872 break;
@@ -2039,28 +2041,11 @@ twobyte_insn:
2039 if (!test_cc(c->b, ctxt->eflags)) 2041 if (!test_cc(c->b, ctxt->eflags))
2040 c->dst.type = OP_NONE; /* no writeback */ 2042 c->dst.type = OP_NONE; /* no writeback */
2041 break; 2043 break;
2042 case 0x80 ... 0x8f: /* jnz rel, etc*/ { 2044 case 0x80 ... 0x8f: /* jnz rel, etc*/
2043 long int rel;
2044
2045 switch (c->op_bytes) {
2046 case 2:
2047 rel = insn_fetch(s16, 2, c->eip);
2048 break;
2049 case 4:
2050 rel = insn_fetch(s32, 4, c->eip);
2051 break;
2052 case 8:
2053 rel = insn_fetch(s64, 8, c->eip);
2054 break;
2055 default:
2056 DPRINTF("jnz: Invalid op_bytes\n");
2057 goto cannot_emulate;
2058 }
2059 if (test_cc(c->b, ctxt->eflags)) 2045 if (test_cc(c->b, ctxt->eflags))
2060 jmp_rel(c, rel); 2046 jmp_rel(c, c->src.val);
2061 c->dst.type = OP_NONE; 2047 c->dst.type = OP_NONE;
2062 break; 2048 break;
2063 }
2064 case 0xa3: 2049 case 0xa3:
2065 bt: /* bt */ 2050 bt: /* bt */
2066 c->dst.type = OP_NONE; 2051 c->dst.type = OP_NONE;
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index 55e11aa6d66c..f9d35632666b 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -2,7 +2,7 @@
2# Makefile for x86 specific library files. 2# Makefile for x86 specific library files.
3# 3#
4 4
5obj-$(CONFIG_SMP) := msr-on-cpu.o 5obj-$(CONFIG_SMP) := msr.o
6 6
7lib-y := delay.o 7lib-y := delay.o
8lib-y += thunk_$(BITS).o 8lib-y += thunk_$(BITS).o
diff --git a/arch/x86/lib/msr-on-cpu.c b/arch/x86/lib/msr-on-cpu.c
deleted file mode 100644
index 321cf720dbb6..000000000000
--- a/arch/x86/lib/msr-on-cpu.c
+++ /dev/null
@@ -1,97 +0,0 @@
1#include <linux/module.h>
2#include <linux/preempt.h>
3#include <linux/smp.h>
4#include <asm/msr.h>
5
6struct msr_info {
7 u32 msr_no;
8 u32 l, h;
9 int err;
10};
11
12static void __rdmsr_on_cpu(void *info)
13{
14 struct msr_info *rv = info;
15
16 rdmsr(rv->msr_no, rv->l, rv->h);
17}
18
19static void __wrmsr_on_cpu(void *info)
20{
21 struct msr_info *rv = info;
22
23 wrmsr(rv->msr_no, rv->l, rv->h);
24}
25
26int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h)
27{
28 int err;
29 struct msr_info rv;
30
31 rv.msr_no = msr_no;
32 err = smp_call_function_single(cpu, __rdmsr_on_cpu, &rv, 1);
33 *l = rv.l;
34 *h = rv.h;
35
36 return err;
37}
38
39int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
40{
41 int err;
42 struct msr_info rv;
43
44 rv.msr_no = msr_no;
45 rv.l = l;
46 rv.h = h;
47 err = smp_call_function_single(cpu, __wrmsr_on_cpu, &rv, 1);
48
49 return err;
50}
51
52/* These "safe" variants are slower and should be used when the target MSR
53 may not actually exist. */
54static void __rdmsr_safe_on_cpu(void *info)
55{
56 struct msr_info *rv = info;
57
58 rv->err = rdmsr_safe(rv->msr_no, &rv->l, &rv->h);
59}
60
61static void __wrmsr_safe_on_cpu(void *info)
62{
63 struct msr_info *rv = info;
64
65 rv->err = wrmsr_safe(rv->msr_no, rv->l, rv->h);
66}
67
68int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h)
69{
70 int err;
71 struct msr_info rv;
72
73 rv.msr_no = msr_no;
74 err = smp_call_function_single(cpu, __rdmsr_safe_on_cpu, &rv, 1);
75 *l = rv.l;
76 *h = rv.h;
77
78 return err ? err : rv.err;
79}
80
81int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
82{
83 int err;
84 struct msr_info rv;
85
86 rv.msr_no = msr_no;
87 rv.l = l;
88 rv.h = h;
89 err = smp_call_function_single(cpu, __wrmsr_safe_on_cpu, &rv, 1);
90
91 return err ? err : rv.err;
92}
93
94EXPORT_SYMBOL(rdmsr_on_cpu);
95EXPORT_SYMBOL(wrmsr_on_cpu);
96EXPORT_SYMBOL(rdmsr_safe_on_cpu);
97EXPORT_SYMBOL(wrmsr_safe_on_cpu);
diff --git a/arch/x86/lib/msr.c b/arch/x86/lib/msr.c
new file mode 100644
index 000000000000..1440b9c0547e
--- /dev/null
+++ b/arch/x86/lib/msr.c
@@ -0,0 +1,183 @@
1#include <linux/module.h>
2#include <linux/preempt.h>
3#include <linux/smp.h>
4#include <asm/msr.h>
5
6struct msr_info {
7 u32 msr_no;
8 struct msr reg;
9 struct msr *msrs;
10 int off;
11 int err;
12};
13
14static void __rdmsr_on_cpu(void *info)
15{
16 struct msr_info *rv = info;
17 struct msr *reg;
18 int this_cpu = raw_smp_processor_id();
19
20 if (rv->msrs)
21 reg = &rv->msrs[this_cpu - rv->off];
22 else
23 reg = &rv->reg;
24
25 rdmsr(rv->msr_no, reg->l, reg->h);
26}
27
28static void __wrmsr_on_cpu(void *info)
29{
30 struct msr_info *rv = info;
31 struct msr *reg;
32 int this_cpu = raw_smp_processor_id();
33
34 if (rv->msrs)
35 reg = &rv->msrs[this_cpu - rv->off];
36 else
37 reg = &rv->reg;
38
39 wrmsr(rv->msr_no, reg->l, reg->h);
40}
41
42int rdmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h)
43{
44 int err;
45 struct msr_info rv;
46
47 memset(&rv, 0, sizeof(rv));
48
49 rv.msr_no = msr_no;
50 err = smp_call_function_single(cpu, __rdmsr_on_cpu, &rv, 1);
51 *l = rv.reg.l;
52 *h = rv.reg.h;
53
54 return err;
55}
56EXPORT_SYMBOL(rdmsr_on_cpu);
57
58int wrmsr_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
59{
60 int err;
61 struct msr_info rv;
62
63 memset(&rv, 0, sizeof(rv));
64
65 rv.msr_no = msr_no;
66 rv.reg.l = l;
67 rv.reg.h = h;
68 err = smp_call_function_single(cpu, __wrmsr_on_cpu, &rv, 1);
69
70 return err;
71}
72EXPORT_SYMBOL(wrmsr_on_cpu);
73
74/* rdmsr on a bunch of CPUs
75 *
76 * @mask: which CPUs
77 * @msr_no: which MSR
78 * @msrs: array of MSR values
79 *
80 */
81void rdmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
82{
83 struct msr_info rv;
84 int this_cpu;
85
86 memset(&rv, 0, sizeof(rv));
87
88 rv.off = cpumask_first(mask);
89 rv.msrs = msrs;
90 rv.msr_no = msr_no;
91
92 preempt_disable();
93 /*
94 * FIXME: handle the CPU we're executing on separately for now until
95 * smp_call_function_many has been fixed to not skip it.
96 */
97 this_cpu = raw_smp_processor_id();
98 smp_call_function_single(this_cpu, __rdmsr_on_cpu, &rv, 1);
99
100 smp_call_function_many(mask, __rdmsr_on_cpu, &rv, 1);
101 preempt_enable();
102}
103EXPORT_SYMBOL(rdmsr_on_cpus);
104
105/*
106 * wrmsr on a bunch of CPUs
107 *
108 * @mask: which CPUs
109 * @msr_no: which MSR
110 * @msrs: array of MSR values
111 *
112 */
113void wrmsr_on_cpus(const cpumask_t *mask, u32 msr_no, struct msr *msrs)
114{
115 struct msr_info rv;
116 int this_cpu;
117
118 memset(&rv, 0, sizeof(rv));
119
120 rv.off = cpumask_first(mask);
121 rv.msrs = msrs;
122 rv.msr_no = msr_no;
123
124 preempt_disable();
125 /*
126 * FIXME: handle the CPU we're executing on separately for now until
127 * smp_call_function_many has been fixed to not skip it.
128 */
129 this_cpu = raw_smp_processor_id();
130 smp_call_function_single(this_cpu, __wrmsr_on_cpu, &rv, 1);
131
132 smp_call_function_many(mask, __wrmsr_on_cpu, &rv, 1);
133 preempt_enable();
134}
135EXPORT_SYMBOL(wrmsr_on_cpus);
136
137/* These "safe" variants are slower and should be used when the target MSR
138 may not actually exist. */
139static void __rdmsr_safe_on_cpu(void *info)
140{
141 struct msr_info *rv = info;
142
143 rv->err = rdmsr_safe(rv->msr_no, &rv->reg.l, &rv->reg.h);
144}
145
146static void __wrmsr_safe_on_cpu(void *info)
147{
148 struct msr_info *rv = info;
149
150 rv->err = wrmsr_safe(rv->msr_no, rv->reg.l, rv->reg.h);
151}
152
153int rdmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 *l, u32 *h)
154{
155 int err;
156 struct msr_info rv;
157
158 memset(&rv, 0, sizeof(rv));
159
160 rv.msr_no = msr_no;
161 err = smp_call_function_single(cpu, __rdmsr_safe_on_cpu, &rv, 1);
162 *l = rv.reg.l;
163 *h = rv.reg.h;
164
165 return err ? err : rv.err;
166}
167EXPORT_SYMBOL(rdmsr_safe_on_cpu);
168
169int wrmsr_safe_on_cpu(unsigned int cpu, u32 msr_no, u32 l, u32 h)
170{
171 int err;
172 struct msr_info rv;
173
174 memset(&rv, 0, sizeof(rv));
175
176 rv.msr_no = msr_no;
177 rv.reg.l = l;
178 rv.reg.h = h;
179 err = smp_call_function_single(cpu, __wrmsr_safe_on_cpu, &rv, 1);
180
181 return err ? err : rv.err;
182}
183EXPORT_SYMBOL(wrmsr_safe_on_cpu);
diff --git a/block/Kconfig b/block/Kconfig
index e7d12782bcfb..2c39527aa7db 100644
--- a/block/Kconfig
+++ b/block/Kconfig
@@ -26,6 +26,7 @@ if BLOCK
26config LBD 26config LBD
27 bool "Support for large block devices and files" 27 bool "Support for large block devices and files"
28 depends on !64BIT 28 depends on !64BIT
29 default y
29 help 30 help
30 Enable block devices or files of size 2TB and larger. 31 Enable block devices or files of size 2TB and larger.
31 32
@@ -38,11 +39,13 @@ config LBD
38 39
39 The ext4 filesystem requires that this feature be enabled in 40 The ext4 filesystem requires that this feature be enabled in
40 order to support filesystems that have the huge_file feature 41 order to support filesystems that have the huge_file feature
41 enabled. Otherwise, it will refuse to mount any filesystems 42 enabled. Otherwise, it will refuse to mount in the read-write
42 that use the huge_file feature, which is enabled by default 43 mode any filesystems that use the huge_file feature, which is
43 by mke2fs.ext4. The GFS2 filesystem also requires this feature. 44 enabled by default by mke2fs.ext4.
44 45
45 If unsure, say N. 46 The GFS2 filesystem also requires this feature.
47
48 If unsure, say Y.
46 49
47config BLK_DEV_BSG 50config BLK_DEV_BSG
48 bool "Block layer SG support v4 (EXPERIMENTAL)" 51 bool "Block layer SG support v4 (EXPERIMENTAL)"
diff --git a/block/as-iosched.c b/block/as-iosched.c
index c48fa670d221..7a12cf6ee1d3 100644
--- a/block/as-iosched.c
+++ b/block/as-iosched.c
@@ -306,8 +306,8 @@ as_choose_req(struct as_data *ad, struct request *rq1, struct request *rq2)
306 data_dir = rq_is_sync(rq1); 306 data_dir = rq_is_sync(rq1);
307 307
308 last = ad->last_sector[data_dir]; 308 last = ad->last_sector[data_dir];
309 s1 = rq1->sector; 309 s1 = blk_rq_pos(rq1);
310 s2 = rq2->sector; 310 s2 = blk_rq_pos(rq2);
311 311
312 BUG_ON(data_dir != rq_is_sync(rq2)); 312 BUG_ON(data_dir != rq_is_sync(rq2));
313 313
@@ -566,13 +566,15 @@ static void as_update_iohist(struct as_data *ad, struct as_io_context *aic,
566 as_update_thinktime(ad, aic, thinktime); 566 as_update_thinktime(ad, aic, thinktime);
567 567
568 /* Calculate read -> read seek distance */ 568 /* Calculate read -> read seek distance */
569 if (aic->last_request_pos < rq->sector) 569 if (aic->last_request_pos < blk_rq_pos(rq))
570 seek_dist = rq->sector - aic->last_request_pos; 570 seek_dist = blk_rq_pos(rq) -
571 aic->last_request_pos;
571 else 572 else
572 seek_dist = aic->last_request_pos - rq->sector; 573 seek_dist = aic->last_request_pos -
574 blk_rq_pos(rq);
573 as_update_seekdist(ad, aic, seek_dist); 575 as_update_seekdist(ad, aic, seek_dist);
574 } 576 }
575 aic->last_request_pos = rq->sector + rq->nr_sectors; 577 aic->last_request_pos = blk_rq_pos(rq) + blk_rq_sectors(rq);
576 set_bit(AS_TASK_IOSTARTED, &aic->state); 578 set_bit(AS_TASK_IOSTARTED, &aic->state);
577 spin_unlock(&aic->lock); 579 spin_unlock(&aic->lock);
578 } 580 }
@@ -587,7 +589,7 @@ static int as_close_req(struct as_data *ad, struct as_io_context *aic,
587{ 589{
588 unsigned long delay; /* jiffies */ 590 unsigned long delay; /* jiffies */
589 sector_t last = ad->last_sector[ad->batch_data_dir]; 591 sector_t last = ad->last_sector[ad->batch_data_dir];
590 sector_t next = rq->sector; 592 sector_t next = blk_rq_pos(rq);
591 sector_t delta; /* acceptable close offset (in sectors) */ 593 sector_t delta; /* acceptable close offset (in sectors) */
592 sector_t s; 594 sector_t s;
593 595
@@ -981,7 +983,7 @@ static void as_move_to_dispatch(struct as_data *ad, struct request *rq)
981 * This has to be set in order to be correctly updated by 983 * This has to be set in order to be correctly updated by
982 * as_find_next_rq 984 * as_find_next_rq
983 */ 985 */
984 ad->last_sector[data_dir] = rq->sector + rq->nr_sectors; 986 ad->last_sector[data_dir] = blk_rq_pos(rq) + blk_rq_sectors(rq);
985 987
986 if (data_dir == BLK_RW_SYNC) { 988 if (data_dir == BLK_RW_SYNC) {
987 struct io_context *ioc = RQ_IOC(rq); 989 struct io_context *ioc = RQ_IOC(rq);
@@ -1312,12 +1314,8 @@ static void as_merged_requests(struct request_queue *q, struct request *req,
1312static void as_work_handler(struct work_struct *work) 1314static void as_work_handler(struct work_struct *work)
1313{ 1315{
1314 struct as_data *ad = container_of(work, struct as_data, antic_work); 1316 struct as_data *ad = container_of(work, struct as_data, antic_work);
1315 struct request_queue *q = ad->q;
1316 unsigned long flags;
1317 1317
1318 spin_lock_irqsave(q->queue_lock, flags); 1318 blk_run_queue(ad->q);
1319 blk_start_queueing(q);
1320 spin_unlock_irqrestore(q->queue_lock, flags);
1321} 1319}
1322 1320
1323static int as_may_queue(struct request_queue *q, int rw) 1321static int as_may_queue(struct request_queue *q, int rw)
diff --git a/block/blk-barrier.c b/block/blk-barrier.c
index 20b4111fa050..30022b4e2f63 100644
--- a/block/blk-barrier.c
+++ b/block/blk-barrier.c
@@ -106,10 +106,7 @@ bool blk_ordered_complete_seq(struct request_queue *q, unsigned seq, int error)
106 */ 106 */
107 q->ordseq = 0; 107 q->ordseq = 0;
108 rq = q->orig_bar_rq; 108 rq = q->orig_bar_rq;
109 109 __blk_end_request_all(rq, q->orderr);
110 if (__blk_end_request(rq, q->orderr, blk_rq_bytes(rq)))
111 BUG();
112
113 return true; 110 return true;
114} 111}
115 112
@@ -166,7 +163,7 @@ static inline bool start_ordered(struct request_queue *q, struct request **rqp)
166 * For an empty barrier, there's no actual BAR request, which 163 * For an empty barrier, there's no actual BAR request, which
167 * in turn makes POSTFLUSH unnecessary. Mask them off. 164 * in turn makes POSTFLUSH unnecessary. Mask them off.
168 */ 165 */
169 if (!rq->hard_nr_sectors) { 166 if (!blk_rq_sectors(rq)) {
170 q->ordered &= ~(QUEUE_ORDERED_DO_BAR | 167 q->ordered &= ~(QUEUE_ORDERED_DO_BAR |
171 QUEUE_ORDERED_DO_POSTFLUSH); 168 QUEUE_ORDERED_DO_POSTFLUSH);
172 /* 169 /*
@@ -183,7 +180,7 @@ static inline bool start_ordered(struct request_queue *q, struct request **rqp)
183 } 180 }
184 181
185 /* stash away the original request */ 182 /* stash away the original request */
186 elv_dequeue_request(q, rq); 183 blk_dequeue_request(rq);
187 q->orig_bar_rq = rq; 184 q->orig_bar_rq = rq;
188 rq = NULL; 185 rq = NULL;
189 186
@@ -221,7 +218,7 @@ static inline bool start_ordered(struct request_queue *q, struct request **rqp)
221 } else 218 } else
222 skip |= QUEUE_ORDSEQ_PREFLUSH; 219 skip |= QUEUE_ORDSEQ_PREFLUSH;
223 220
224 if ((q->ordered & QUEUE_ORDERED_BY_DRAIN) && q->in_flight) 221 if ((q->ordered & QUEUE_ORDERED_BY_DRAIN) && queue_in_flight(q))
225 rq = NULL; 222 rq = NULL;
226 else 223 else
227 skip |= QUEUE_ORDSEQ_DRAIN; 224 skip |= QUEUE_ORDSEQ_DRAIN;
@@ -251,10 +248,8 @@ bool blk_do_ordered(struct request_queue *q, struct request **rqp)
251 * Queue ordering not supported. Terminate 248 * Queue ordering not supported. Terminate
252 * with prejudice. 249 * with prejudice.
253 */ 250 */
254 elv_dequeue_request(q, rq); 251 blk_dequeue_request(rq);
255 if (__blk_end_request(rq, -EOPNOTSUPP, 252 __blk_end_request_all(rq, -EOPNOTSUPP);
256 blk_rq_bytes(rq)))
257 BUG();
258 *rqp = NULL; 253 *rqp = NULL;
259 return false; 254 return false;
260 } 255 }
@@ -329,7 +324,7 @@ int blkdev_issue_flush(struct block_device *bdev, sector_t *error_sector)
329 /* 324 /*
330 * The driver must store the error location in ->bi_sector, if 325 * The driver must store the error location in ->bi_sector, if
331 * it supports it. For non-stacked drivers, this should be copied 326 * it supports it. For non-stacked drivers, this should be copied
332 * from rq->sector. 327 * from blk_rq_pos(rq).
333 */ 328 */
334 if (error_sector) 329 if (error_sector)
335 *error_sector = bio->bi_sector; 330 *error_sector = bio->bi_sector;
@@ -393,10 +388,10 @@ int blkdev_issue_discard(struct block_device *bdev,
393 388
394 bio->bi_sector = sector; 389 bio->bi_sector = sector;
395 390
396 if (nr_sects > q->max_hw_sectors) { 391 if (nr_sects > queue_max_hw_sectors(q)) {
397 bio->bi_size = q->max_hw_sectors << 9; 392 bio->bi_size = queue_max_hw_sectors(q) << 9;
398 nr_sects -= q->max_hw_sectors; 393 nr_sects -= queue_max_hw_sectors(q);
399 sector += q->max_hw_sectors; 394 sector += queue_max_hw_sectors(q);
400 } else { 395 } else {
401 bio->bi_size = nr_sects << 9; 396 bio->bi_size = nr_sects << 9;
402 nr_sects = 0; 397 nr_sects = 0;
diff --git a/block/blk-core.c b/block/blk-core.c
index 9475bf99b891..d17d71c71d4f 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -60,11 +60,11 @@ static void drive_stat_acct(struct request *rq, int new_io)
60 int rw = rq_data_dir(rq); 60 int rw = rq_data_dir(rq);
61 int cpu; 61 int cpu;
62 62
63 if (!blk_fs_request(rq) || !blk_do_io_stat(rq)) 63 if (!blk_do_io_stat(rq))
64 return; 64 return;
65 65
66 cpu = part_stat_lock(); 66 cpu = part_stat_lock();
67 part = disk_map_sector_rcu(rq->rq_disk, rq->sector); 67 part = disk_map_sector_rcu(rq->rq_disk, blk_rq_pos(rq));
68 68
69 if (!new_io) 69 if (!new_io)
70 part_stat_inc(cpu, part, merges[rw]); 70 part_stat_inc(cpu, part, merges[rw]);
@@ -119,13 +119,14 @@ void blk_rq_init(struct request_queue *q, struct request *rq)
119 INIT_LIST_HEAD(&rq->timeout_list); 119 INIT_LIST_HEAD(&rq->timeout_list);
120 rq->cpu = -1; 120 rq->cpu = -1;
121 rq->q = q; 121 rq->q = q;
122 rq->sector = rq->hard_sector = (sector_t) -1; 122 rq->__sector = (sector_t) -1;
123 INIT_HLIST_NODE(&rq->hash); 123 INIT_HLIST_NODE(&rq->hash);
124 RB_CLEAR_NODE(&rq->rb_node); 124 RB_CLEAR_NODE(&rq->rb_node);
125 rq->cmd = rq->__cmd; 125 rq->cmd = rq->__cmd;
126 rq->cmd_len = BLK_MAX_CDB; 126 rq->cmd_len = BLK_MAX_CDB;
127 rq->tag = -1; 127 rq->tag = -1;
128 rq->ref_count = 1; 128 rq->ref_count = 1;
129 rq->start_time = jiffies;
129} 130}
130EXPORT_SYMBOL(blk_rq_init); 131EXPORT_SYMBOL(blk_rq_init);
131 132
@@ -176,14 +177,11 @@ void blk_dump_rq_flags(struct request *rq, char *msg)
176 rq->rq_disk ? rq->rq_disk->disk_name : "?", rq->cmd_type, 177 rq->rq_disk ? rq->rq_disk->disk_name : "?", rq->cmd_type,
177 rq->cmd_flags); 178 rq->cmd_flags);
178 179
179 printk(KERN_INFO " sector %llu, nr/cnr %lu/%u\n", 180 printk(KERN_INFO " sector %llu, nr/cnr %u/%u\n",
180 (unsigned long long)rq->sector, 181 (unsigned long long)blk_rq_pos(rq),
181 rq->nr_sectors, 182 blk_rq_sectors(rq), blk_rq_cur_sectors(rq));
182 rq->current_nr_sectors); 183 printk(KERN_INFO " bio %p, biotail %p, buffer %p, len %u\n",
183 printk(KERN_INFO " bio %p, biotail %p, buffer %p, data %p, len %u\n", 184 rq->bio, rq->biotail, rq->buffer, blk_rq_bytes(rq));
184 rq->bio, rq->biotail,
185 rq->buffer, rq->data,
186 rq->data_len);
187 185
188 if (blk_pc_request(rq)) { 186 if (blk_pc_request(rq)) {
189 printk(KERN_INFO " cdb: "); 187 printk(KERN_INFO " cdb: ");
@@ -325,24 +323,6 @@ void blk_unplug(struct request_queue *q)
325} 323}
326EXPORT_SYMBOL(blk_unplug); 324EXPORT_SYMBOL(blk_unplug);
327 325
328static void blk_invoke_request_fn(struct request_queue *q)
329{
330 if (unlikely(blk_queue_stopped(q)))
331 return;
332
333 /*
334 * one level of recursion is ok and is much faster than kicking
335 * the unplug handling
336 */
337 if (!queue_flag_test_and_set(QUEUE_FLAG_REENTER, q)) {
338 q->request_fn(q);
339 queue_flag_clear(QUEUE_FLAG_REENTER, q);
340 } else {
341 queue_flag_set(QUEUE_FLAG_PLUGGED, q);
342 kblockd_schedule_work(q, &q->unplug_work);
343 }
344}
345
346/** 326/**
347 * blk_start_queue - restart a previously stopped queue 327 * blk_start_queue - restart a previously stopped queue
348 * @q: The &struct request_queue in question 328 * @q: The &struct request_queue in question
@@ -357,7 +337,7 @@ void blk_start_queue(struct request_queue *q)
357 WARN_ON(!irqs_disabled()); 337 WARN_ON(!irqs_disabled());
358 338
359 queue_flag_clear(QUEUE_FLAG_STOPPED, q); 339 queue_flag_clear(QUEUE_FLAG_STOPPED, q);
360 blk_invoke_request_fn(q); 340 __blk_run_queue(q);
361} 341}
362EXPORT_SYMBOL(blk_start_queue); 342EXPORT_SYMBOL(blk_start_queue);
363 343
@@ -417,12 +397,23 @@ void __blk_run_queue(struct request_queue *q)
417{ 397{
418 blk_remove_plug(q); 398 blk_remove_plug(q);
419 399
400 if (unlikely(blk_queue_stopped(q)))
401 return;
402
403 if (elv_queue_empty(q))
404 return;
405
420 /* 406 /*
421 * Only recurse once to avoid overrunning the stack, let the unplug 407 * Only recurse once to avoid overrunning the stack, let the unplug
422 * handling reinvoke the handler shortly if we already got there. 408 * handling reinvoke the handler shortly if we already got there.
423 */ 409 */
424 if (!elv_queue_empty(q)) 410 if (!queue_flag_test_and_set(QUEUE_FLAG_REENTER, q)) {
425 blk_invoke_request_fn(q); 411 q->request_fn(q);
412 queue_flag_clear(QUEUE_FLAG_REENTER, q);
413 } else {
414 queue_flag_set(QUEUE_FLAG_PLUGGED, q);
415 kblockd_schedule_work(q, &q->unplug_work);
416 }
426} 417}
427EXPORT_SYMBOL(__blk_run_queue); 418EXPORT_SYMBOL(__blk_run_queue);
428 419
@@ -432,9 +423,7 @@ EXPORT_SYMBOL(__blk_run_queue);
432 * 423 *
433 * Description: 424 * Description:
434 * Invoke request handling on this queue, if it has pending work to do. 425 * Invoke request handling on this queue, if it has pending work to do.
435 * May be used to restart queueing when a request has completed. Also 426 * May be used to restart queueing when a request has completed.
436 * See @blk_start_queueing.
437 *
438 */ 427 */
439void blk_run_queue(struct request_queue *q) 428void blk_run_queue(struct request_queue *q)
440{ 429{
@@ -894,26 +883,58 @@ struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask)
894EXPORT_SYMBOL(blk_get_request); 883EXPORT_SYMBOL(blk_get_request);
895 884
896/** 885/**
897 * blk_start_queueing - initiate dispatch of requests to device 886 * blk_make_request - given a bio, allocate a corresponding struct request.
898 * @q: request queue to kick into gear 887 *
888 * @bio: The bio describing the memory mappings that will be submitted for IO.
889 * It may be a chained-bio properly constructed by block/bio layer.
899 * 890 *
900 * This is basically a helper to remove the need to know whether a queue 891 * blk_make_request is the parallel of generic_make_request for BLOCK_PC
901 * is plugged or not if someone just wants to initiate dispatch of requests 892 * type commands. Where the struct request needs to be farther initialized by
902 * for this queue. Should be used to start queueing on a device outside 893 * the caller. It is passed a &struct bio, which describes the memory info of
903 * of ->request_fn() context. Also see @blk_run_queue. 894 * the I/O transfer.
904 * 895 *
905 * The queue lock must be held with interrupts disabled. 896 * The caller of blk_make_request must make sure that bi_io_vec
897 * are set to describe the memory buffers. That bio_data_dir() will return
898 * the needed direction of the request. (And all bio's in the passed bio-chain
899 * are properly set accordingly)
900 *
901 * If called under none-sleepable conditions, mapped bio buffers must not
902 * need bouncing, by calling the appropriate masked or flagged allocator,
903 * suitable for the target device. Otherwise the call to blk_queue_bounce will
904 * BUG.
905 *
906 * WARNING: When allocating/cloning a bio-chain, careful consideration should be
907 * given to how you allocate bios. In particular, you cannot use __GFP_WAIT for
908 * anything but the first bio in the chain. Otherwise you risk waiting for IO
909 * completion of a bio that hasn't been submitted yet, thus resulting in a
910 * deadlock. Alternatively bios should be allocated using bio_kmalloc() instead
911 * of bio_alloc(), as that avoids the mempool deadlock.
912 * If possible a big IO should be split into smaller parts when allocation
913 * fails. Partial allocation should not be an error, or you risk a live-lock.
906 */ 914 */
907void blk_start_queueing(struct request_queue *q) 915struct request *blk_make_request(struct request_queue *q, struct bio *bio,
916 gfp_t gfp_mask)
908{ 917{
909 if (!blk_queue_plugged(q)) { 918 struct request *rq = blk_get_request(q, bio_data_dir(bio), gfp_mask);
910 if (unlikely(blk_queue_stopped(q))) 919
911 return; 920 if (unlikely(!rq))
912 q->request_fn(q); 921 return ERR_PTR(-ENOMEM);
913 } else 922
914 __generic_unplug_device(q); 923 for_each_bio(bio) {
924 struct bio *bounce_bio = bio;
925 int ret;
926
927 blk_queue_bounce(q, &bounce_bio);
928 ret = blk_rq_append_bio(q, rq, bounce_bio);
929 if (unlikely(ret)) {
930 blk_put_request(rq);
931 return ERR_PTR(ret);
932 }
933 }
934
935 return rq;
915} 936}
916EXPORT_SYMBOL(blk_start_queueing); 937EXPORT_SYMBOL(blk_make_request);
917 938
918/** 939/**
919 * blk_requeue_request - put a request back on queue 940 * blk_requeue_request - put a request back on queue
@@ -934,6 +955,8 @@ void blk_requeue_request(struct request_queue *q, struct request *rq)
934 if (blk_rq_tagged(rq)) 955 if (blk_rq_tagged(rq))
935 blk_queue_end_tag(q, rq); 956 blk_queue_end_tag(q, rq);
936 957
958 BUG_ON(blk_queued_rq(rq));
959
937 elv_requeue_request(q, rq); 960 elv_requeue_request(q, rq);
938} 961}
939EXPORT_SYMBOL(blk_requeue_request); 962EXPORT_SYMBOL(blk_requeue_request);
@@ -969,7 +992,6 @@ void blk_insert_request(struct request_queue *q, struct request *rq,
969 * barrier 992 * barrier
970 */ 993 */
971 rq->cmd_type = REQ_TYPE_SPECIAL; 994 rq->cmd_type = REQ_TYPE_SPECIAL;
972 rq->cmd_flags |= REQ_SOFTBARRIER;
973 995
974 rq->special = data; 996 rq->special = data;
975 997
@@ -983,7 +1005,7 @@ void blk_insert_request(struct request_queue *q, struct request *rq,
983 1005
984 drive_stat_acct(rq, 1); 1006 drive_stat_acct(rq, 1);
985 __elv_add_request(q, rq, where, 0); 1007 __elv_add_request(q, rq, where, 0);
986 blk_start_queueing(q); 1008 __blk_run_queue(q);
987 spin_unlock_irqrestore(q->queue_lock, flags); 1009 spin_unlock_irqrestore(q->queue_lock, flags);
988} 1010}
989EXPORT_SYMBOL(blk_insert_request); 1011EXPORT_SYMBOL(blk_insert_request);
@@ -1105,16 +1127,13 @@ void init_request_from_bio(struct request *req, struct bio *bio)
1105 if (bio_failfast_driver(bio)) 1127 if (bio_failfast_driver(bio))
1106 req->cmd_flags |= REQ_FAILFAST_DRIVER; 1128 req->cmd_flags |= REQ_FAILFAST_DRIVER;
1107 1129
1108 /*
1109 * REQ_BARRIER implies no merging, but lets make it explicit
1110 */
1111 if (unlikely(bio_discard(bio))) { 1130 if (unlikely(bio_discard(bio))) {
1112 req->cmd_flags |= REQ_DISCARD; 1131 req->cmd_flags |= REQ_DISCARD;
1113 if (bio_barrier(bio)) 1132 if (bio_barrier(bio))
1114 req->cmd_flags |= REQ_SOFTBARRIER; 1133 req->cmd_flags |= REQ_SOFTBARRIER;
1115 req->q->prepare_discard_fn(req->q, req); 1134 req->q->prepare_discard_fn(req->q, req);
1116 } else if (unlikely(bio_barrier(bio))) 1135 } else if (unlikely(bio_barrier(bio)))
1117 req->cmd_flags |= (REQ_HARDBARRIER | REQ_NOMERGE); 1136 req->cmd_flags |= REQ_HARDBARRIER;
1118 1137
1119 if (bio_sync(bio)) 1138 if (bio_sync(bio))
1120 req->cmd_flags |= REQ_RW_SYNC; 1139 req->cmd_flags |= REQ_RW_SYNC;
@@ -1124,9 +1143,8 @@ void init_request_from_bio(struct request *req, struct bio *bio)
1124 req->cmd_flags |= REQ_NOIDLE; 1143 req->cmd_flags |= REQ_NOIDLE;
1125 1144
1126 req->errors = 0; 1145 req->errors = 0;
1127 req->hard_sector = req->sector = bio->bi_sector; 1146 req->__sector = bio->bi_sector;
1128 req->ioprio = bio_prio(bio); 1147 req->ioprio = bio_prio(bio);
1129 req->start_time = jiffies;
1130 blk_rq_bio_prep(req->q, req, bio); 1148 blk_rq_bio_prep(req->q, req, bio);
1131} 1149}
1132 1150
@@ -1142,14 +1160,13 @@ static inline bool queue_should_plug(struct request_queue *q)
1142static int __make_request(struct request_queue *q, struct bio *bio) 1160static int __make_request(struct request_queue *q, struct bio *bio)
1143{ 1161{
1144 struct request *req; 1162 struct request *req;
1145 int el_ret, nr_sectors; 1163 int el_ret;
1164 unsigned int bytes = bio->bi_size;
1146 const unsigned short prio = bio_prio(bio); 1165 const unsigned short prio = bio_prio(bio);
1147 const int sync = bio_sync(bio); 1166 const int sync = bio_sync(bio);
1148 const int unplug = bio_unplug(bio); 1167 const int unplug = bio_unplug(bio);
1149 int rw_flags; 1168 int rw_flags;
1150 1169
1151 nr_sectors = bio_sectors(bio);
1152
1153 /* 1170 /*
1154 * low level driver can indicate that it wants pages above a 1171 * low level driver can indicate that it wants pages above a
1155 * certain limit bounced to low memory (ie for highmem, or even 1172 * certain limit bounced to low memory (ie for highmem, or even
@@ -1174,7 +1191,7 @@ static int __make_request(struct request_queue *q, struct bio *bio)
1174 1191
1175 req->biotail->bi_next = bio; 1192 req->biotail->bi_next = bio;
1176 req->biotail = bio; 1193 req->biotail = bio;
1177 req->nr_sectors = req->hard_nr_sectors += nr_sectors; 1194 req->__data_len += bytes;
1178 req->ioprio = ioprio_best(req->ioprio, prio); 1195 req->ioprio = ioprio_best(req->ioprio, prio);
1179 if (!blk_rq_cpu_valid(req)) 1196 if (!blk_rq_cpu_valid(req))
1180 req->cpu = bio->bi_comp_cpu; 1197 req->cpu = bio->bi_comp_cpu;
@@ -1200,10 +1217,8 @@ static int __make_request(struct request_queue *q, struct bio *bio)
1200 * not touch req->buffer either... 1217 * not touch req->buffer either...
1201 */ 1218 */
1202 req->buffer = bio_data(bio); 1219 req->buffer = bio_data(bio);
1203 req->current_nr_sectors = bio_cur_sectors(bio); 1220 req->__sector = bio->bi_sector;
1204 req->hard_cur_sectors = req->current_nr_sectors; 1221 req->__data_len += bytes;
1205 req->sector = req->hard_sector = bio->bi_sector;
1206 req->nr_sectors = req->hard_nr_sectors += nr_sectors;
1207 req->ioprio = ioprio_best(req->ioprio, prio); 1222 req->ioprio = ioprio_best(req->ioprio, prio);
1208 if (!blk_rq_cpu_valid(req)) 1223 if (!blk_rq_cpu_valid(req))
1209 req->cpu = bio->bi_comp_cpu; 1224 req->cpu = bio->bi_comp_cpu;
@@ -1414,11 +1429,11 @@ static inline void __generic_make_request(struct bio *bio)
1414 goto end_io; 1429 goto end_io;
1415 } 1430 }
1416 1431
1417 if (unlikely(nr_sectors > q->max_hw_sectors)) { 1432 if (unlikely(nr_sectors > queue_max_hw_sectors(q))) {
1418 printk(KERN_ERR "bio too big device %s (%u > %u)\n", 1433 printk(KERN_ERR "bio too big device %s (%u > %u)\n",
1419 bdevname(bio->bi_bdev, b), 1434 bdevname(bio->bi_bdev, b),
1420 bio_sectors(bio), 1435 bio_sectors(bio),
1421 q->max_hw_sectors); 1436 queue_max_hw_sectors(q));
1422 goto end_io; 1437 goto end_io;
1423 } 1438 }
1424 1439
@@ -1584,8 +1599,8 @@ EXPORT_SYMBOL(submit_bio);
1584 */ 1599 */
1585int blk_rq_check_limits(struct request_queue *q, struct request *rq) 1600int blk_rq_check_limits(struct request_queue *q, struct request *rq)
1586{ 1601{
1587 if (rq->nr_sectors > q->max_sectors || 1602 if (blk_rq_sectors(rq) > queue_max_sectors(q) ||
1588 rq->data_len > q->max_hw_sectors << 9) { 1603 blk_rq_bytes(rq) > queue_max_hw_sectors(q) << 9) {
1589 printk(KERN_ERR "%s: over max size limit.\n", __func__); 1604 printk(KERN_ERR "%s: over max size limit.\n", __func__);
1590 return -EIO; 1605 return -EIO;
1591 } 1606 }
@@ -1597,8 +1612,8 @@ int blk_rq_check_limits(struct request_queue *q, struct request *rq)
1597 * limitation. 1612 * limitation.
1598 */ 1613 */
1599 blk_recalc_rq_segments(rq); 1614 blk_recalc_rq_segments(rq);
1600 if (rq->nr_phys_segments > q->max_phys_segments || 1615 if (rq->nr_phys_segments > queue_max_phys_segments(q) ||
1601 rq->nr_phys_segments > q->max_hw_segments) { 1616 rq->nr_phys_segments > queue_max_hw_segments(q)) {
1602 printk(KERN_ERR "%s: over max segments limit.\n", __func__); 1617 printk(KERN_ERR "%s: over max segments limit.\n", __func__);
1603 return -EIO; 1618 return -EIO;
1604 } 1619 }
@@ -1642,40 +1657,15 @@ int blk_insert_cloned_request(struct request_queue *q, struct request *rq)
1642} 1657}
1643EXPORT_SYMBOL_GPL(blk_insert_cloned_request); 1658EXPORT_SYMBOL_GPL(blk_insert_cloned_request);
1644 1659
1645/**
1646 * blkdev_dequeue_request - dequeue request and start timeout timer
1647 * @req: request to dequeue
1648 *
1649 * Dequeue @req and start timeout timer on it. This hands off the
1650 * request to the driver.
1651 *
1652 * Block internal functions which don't want to start timer should
1653 * call elv_dequeue_request().
1654 */
1655void blkdev_dequeue_request(struct request *req)
1656{
1657 elv_dequeue_request(req->q, req);
1658
1659 /*
1660 * We are now handing the request to the hardware, add the
1661 * timeout handler.
1662 */
1663 blk_add_timer(req);
1664}
1665EXPORT_SYMBOL(blkdev_dequeue_request);
1666
1667static void blk_account_io_completion(struct request *req, unsigned int bytes) 1660static void blk_account_io_completion(struct request *req, unsigned int bytes)
1668{ 1661{
1669 if (!blk_do_io_stat(req)) 1662 if (blk_do_io_stat(req)) {
1670 return;
1671
1672 if (blk_fs_request(req)) {
1673 const int rw = rq_data_dir(req); 1663 const int rw = rq_data_dir(req);
1674 struct hd_struct *part; 1664 struct hd_struct *part;
1675 int cpu; 1665 int cpu;
1676 1666
1677 cpu = part_stat_lock(); 1667 cpu = part_stat_lock();
1678 part = disk_map_sector_rcu(req->rq_disk, req->sector); 1668 part = disk_map_sector_rcu(req->rq_disk, blk_rq_pos(req));
1679 part_stat_add(cpu, part, sectors[rw], bytes >> 9); 1669 part_stat_add(cpu, part, sectors[rw], bytes >> 9);
1680 part_stat_unlock(); 1670 part_stat_unlock();
1681 } 1671 }
@@ -1683,22 +1673,19 @@ static void blk_account_io_completion(struct request *req, unsigned int bytes)
1683 1673
1684static void blk_account_io_done(struct request *req) 1674static void blk_account_io_done(struct request *req)
1685{ 1675{
1686 if (!blk_do_io_stat(req))
1687 return;
1688
1689 /* 1676 /*
1690 * Account IO completion. bar_rq isn't accounted as a normal 1677 * Account IO completion. bar_rq isn't accounted as a normal
1691 * IO on queueing nor completion. Accounting the containing 1678 * IO on queueing nor completion. Accounting the containing
1692 * request is enough. 1679 * request is enough.
1693 */ 1680 */
1694 if (blk_fs_request(req) && req != &req->q->bar_rq) { 1681 if (blk_do_io_stat(req) && req != &req->q->bar_rq) {
1695 unsigned long duration = jiffies - req->start_time; 1682 unsigned long duration = jiffies - req->start_time;
1696 const int rw = rq_data_dir(req); 1683 const int rw = rq_data_dir(req);
1697 struct hd_struct *part; 1684 struct hd_struct *part;
1698 int cpu; 1685 int cpu;
1699 1686
1700 cpu = part_stat_lock(); 1687 cpu = part_stat_lock();
1701 part = disk_map_sector_rcu(req->rq_disk, req->sector); 1688 part = disk_map_sector_rcu(req->rq_disk, blk_rq_pos(req));
1702 1689
1703 part_stat_inc(cpu, part, ios[rw]); 1690 part_stat_inc(cpu, part, ios[rw]);
1704 part_stat_add(cpu, part, ticks[rw], duration); 1691 part_stat_add(cpu, part, ticks[rw], duration);
@@ -1710,38 +1697,226 @@ static void blk_account_io_done(struct request *req)
1710} 1697}
1711 1698
1712/** 1699/**
1713 * __end_that_request_first - end I/O on a request 1700 * blk_peek_request - peek at the top of a request queue
1714 * @req: the request being processed 1701 * @q: request queue to peek at
1702 *
1703 * Description:
1704 * Return the request at the top of @q. The returned request
1705 * should be started using blk_start_request() before LLD starts
1706 * processing it.
1707 *
1708 * Return:
1709 * Pointer to the request at the top of @q if available. Null
1710 * otherwise.
1711 *
1712 * Context:
1713 * queue_lock must be held.
1714 */
1715struct request *blk_peek_request(struct request_queue *q)
1716{
1717 struct request *rq;
1718 int ret;
1719
1720 while ((rq = __elv_next_request(q)) != NULL) {
1721 if (!(rq->cmd_flags & REQ_STARTED)) {
1722 /*
1723 * This is the first time the device driver
1724 * sees this request (possibly after
1725 * requeueing). Notify IO scheduler.
1726 */
1727 if (blk_sorted_rq(rq))
1728 elv_activate_rq(q, rq);
1729
1730 /*
1731 * just mark as started even if we don't start
1732 * it, a request that has been delayed should
1733 * not be passed by new incoming requests
1734 */
1735 rq->cmd_flags |= REQ_STARTED;
1736 trace_block_rq_issue(q, rq);
1737 }
1738
1739 if (!q->boundary_rq || q->boundary_rq == rq) {
1740 q->end_sector = rq_end_sector(rq);
1741 q->boundary_rq = NULL;
1742 }
1743
1744 if (rq->cmd_flags & REQ_DONTPREP)
1745 break;
1746
1747 if (q->dma_drain_size && blk_rq_bytes(rq)) {
1748 /*
1749 * make sure space for the drain appears we
1750 * know we can do this because max_hw_segments
1751 * has been adjusted to be one fewer than the
1752 * device can handle
1753 */
1754 rq->nr_phys_segments++;
1755 }
1756
1757 if (!q->prep_rq_fn)
1758 break;
1759
1760 ret = q->prep_rq_fn(q, rq);
1761 if (ret == BLKPREP_OK) {
1762 break;
1763 } else if (ret == BLKPREP_DEFER) {
1764 /*
1765 * the request may have been (partially) prepped.
1766 * we need to keep this request in the front to
1767 * avoid resource deadlock. REQ_STARTED will
1768 * prevent other fs requests from passing this one.
1769 */
1770 if (q->dma_drain_size && blk_rq_bytes(rq) &&
1771 !(rq->cmd_flags & REQ_DONTPREP)) {
1772 /*
1773 * remove the space for the drain we added
1774 * so that we don't add it again
1775 */
1776 --rq->nr_phys_segments;
1777 }
1778
1779 rq = NULL;
1780 break;
1781 } else if (ret == BLKPREP_KILL) {
1782 rq->cmd_flags |= REQ_QUIET;
1783 /*
1784 * Mark this request as started so we don't trigger
1785 * any debug logic in the end I/O path.
1786 */
1787 blk_start_request(rq);
1788 __blk_end_request_all(rq, -EIO);
1789 } else {
1790 printk(KERN_ERR "%s: bad return=%d\n", __func__, ret);
1791 break;
1792 }
1793 }
1794
1795 return rq;
1796}
1797EXPORT_SYMBOL(blk_peek_request);
1798
1799void blk_dequeue_request(struct request *rq)
1800{
1801 struct request_queue *q = rq->q;
1802
1803 BUG_ON(list_empty(&rq->queuelist));
1804 BUG_ON(ELV_ON_HASH(rq));
1805
1806 list_del_init(&rq->queuelist);
1807
1808 /*
1809 * the time frame between a request being removed from the lists
1810 * and to it is freed is accounted as io that is in progress at
1811 * the driver side.
1812 */
1813 if (blk_account_rq(rq))
1814 q->in_flight[rq_is_sync(rq)]++;
1815}
1816
1817/**
1818 * blk_start_request - start request processing on the driver
1819 * @req: request to dequeue
1820 *
1821 * Description:
1822 * Dequeue @req and start timeout timer on it. This hands off the
1823 * request to the driver.
1824 *
1825 * Block internal functions which don't want to start timer should
1826 * call blk_dequeue_request().
1827 *
1828 * Context:
1829 * queue_lock must be held.
1830 */
1831void blk_start_request(struct request *req)
1832{
1833 blk_dequeue_request(req);
1834
1835 /*
1836 * We are now handing the request to the hardware, initialize
1837 * resid_len to full count and add the timeout handler.
1838 */
1839 req->resid_len = blk_rq_bytes(req);
1840 if (unlikely(blk_bidi_rq(req)))
1841 req->next_rq->resid_len = blk_rq_bytes(req->next_rq);
1842
1843 blk_add_timer(req);
1844}
1845EXPORT_SYMBOL(blk_start_request);
1846
1847/**
1848 * blk_fetch_request - fetch a request from a request queue
1849 * @q: request queue to fetch a request from
1850 *
1851 * Description:
1852 * Return the request at the top of @q. The request is started on
1853 * return and LLD can start processing it immediately.
1854 *
1855 * Return:
1856 * Pointer to the request at the top of @q if available. Null
1857 * otherwise.
1858 *
1859 * Context:
1860 * queue_lock must be held.
1861 */
1862struct request *blk_fetch_request(struct request_queue *q)
1863{
1864 struct request *rq;
1865
1866 rq = blk_peek_request(q);
1867 if (rq)
1868 blk_start_request(rq);
1869 return rq;
1870}
1871EXPORT_SYMBOL(blk_fetch_request);
1872
1873/**
1874 * blk_update_request - Special helper function for request stacking drivers
1875 * @rq: the request being processed
1715 * @error: %0 for success, < %0 for error 1876 * @error: %0 for success, < %0 for error
1716 * @nr_bytes: number of bytes to complete 1877 * @nr_bytes: number of bytes to complete @rq
1717 * 1878 *
1718 * Description: 1879 * Description:
1719 * Ends I/O on a number of bytes attached to @req, and sets it up 1880 * Ends I/O on a number of bytes attached to @rq, but doesn't complete
1720 * for the next range of segments (if any) in the cluster. 1881 * the request structure even if @rq doesn't have leftover.
1882 * If @rq has leftover, sets it up for the next range of segments.
1883 *
1884 * This special helper function is only for request stacking drivers
1885 * (e.g. request-based dm) so that they can handle partial completion.
1886 * Actual device drivers should use blk_end_request instead.
1887 *
1888 * Passing the result of blk_rq_bytes() as @nr_bytes guarantees
1889 * %false return from this function.
1721 * 1890 *
1722 * Return: 1891 * Return:
1723 * %0 - we are done with this request, call end_that_request_last() 1892 * %false - this request doesn't have any more data
1724 * %1 - still buffers pending for this request 1893 * %true - this request has more data
1725 **/ 1894 **/
1726static int __end_that_request_first(struct request *req, int error, 1895bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
1727 int nr_bytes)
1728{ 1896{
1729 int total_bytes, bio_nbytes, next_idx = 0; 1897 int total_bytes, bio_nbytes, next_idx = 0;
1730 struct bio *bio; 1898 struct bio *bio;
1731 1899
1900 if (!req->bio)
1901 return false;
1902
1732 trace_block_rq_complete(req->q, req); 1903 trace_block_rq_complete(req->q, req);
1733 1904
1734 /* 1905 /*
1735 * for a REQ_TYPE_BLOCK_PC request, we want to carry any eventual 1906 * For fs requests, rq is just carrier of independent bio's
1736 * sense key with us all the way through 1907 * and each partial completion should be handled separately.
1908 * Reset per-request error on each partial completion.
1909 *
1910 * TODO: tj: This is too subtle. It would be better to let
1911 * low level drivers do what they see fit.
1737 */ 1912 */
1738 if (!blk_pc_request(req)) 1913 if (blk_fs_request(req))
1739 req->errors = 0; 1914 req->errors = 0;
1740 1915
1741 if (error && (blk_fs_request(req) && !(req->cmd_flags & REQ_QUIET))) { 1916 if (error && (blk_fs_request(req) && !(req->cmd_flags & REQ_QUIET))) {
1742 printk(KERN_ERR "end_request: I/O error, dev %s, sector %llu\n", 1917 printk(KERN_ERR "end_request: I/O error, dev %s, sector %llu\n",
1743 req->rq_disk ? req->rq_disk->disk_name : "?", 1918 req->rq_disk ? req->rq_disk->disk_name : "?",
1744 (unsigned long long)req->sector); 1919 (unsigned long long)blk_rq_pos(req));
1745 } 1920 }
1746 1921
1747 blk_account_io_completion(req, nr_bytes); 1922 blk_account_io_completion(req, nr_bytes);
@@ -1801,8 +1976,15 @@ static int __end_that_request_first(struct request *req, int error,
1801 /* 1976 /*
1802 * completely done 1977 * completely done
1803 */ 1978 */
1804 if (!req->bio) 1979 if (!req->bio) {
1805 return 0; 1980 /*
1981 * Reset counters so that the request stacking driver
1982 * can find how many bytes remain in the request
1983 * later.
1984 */
1985 req->__data_len = 0;
1986 return false;
1987 }
1806 1988
1807 /* 1989 /*
1808 * if the request wasn't completed, update state 1990 * if the request wasn't completed, update state
@@ -1814,21 +1996,55 @@ static int __end_that_request_first(struct request *req, int error,
1814 bio_iovec(bio)->bv_len -= nr_bytes; 1996 bio_iovec(bio)->bv_len -= nr_bytes;
1815 } 1997 }
1816 1998
1817 blk_recalc_rq_sectors(req, total_bytes >> 9); 1999 req->__data_len -= total_bytes;
2000 req->buffer = bio_data(req->bio);
2001
2002 /* update sector only for requests with clear definition of sector */
2003 if (blk_fs_request(req) || blk_discard_rq(req))
2004 req->__sector += total_bytes >> 9;
2005
2006 /*
2007 * If total number of sectors is less than the first segment
2008 * size, something has gone terribly wrong.
2009 */
2010 if (blk_rq_bytes(req) < blk_rq_cur_bytes(req)) {
2011 printk(KERN_ERR "blk: request botched\n");
2012 req->__data_len = blk_rq_cur_bytes(req);
2013 }
2014
2015 /* recalculate the number of segments */
1818 blk_recalc_rq_segments(req); 2016 blk_recalc_rq_segments(req);
1819 return 1; 2017
2018 return true;
2019}
2020EXPORT_SYMBOL_GPL(blk_update_request);
2021
2022static bool blk_update_bidi_request(struct request *rq, int error,
2023 unsigned int nr_bytes,
2024 unsigned int bidi_bytes)
2025{
2026 if (blk_update_request(rq, error, nr_bytes))
2027 return true;
2028
2029 /* Bidi request must be completed as a whole */
2030 if (unlikely(blk_bidi_rq(rq)) &&
2031 blk_update_request(rq->next_rq, error, bidi_bytes))
2032 return true;
2033
2034 add_disk_randomness(rq->rq_disk);
2035
2036 return false;
1820} 2037}
1821 2038
1822/* 2039/*
1823 * queue lock must be held 2040 * queue lock must be held
1824 */ 2041 */
1825static void end_that_request_last(struct request *req, int error) 2042static void blk_finish_request(struct request *req, int error)
1826{ 2043{
1827 if (blk_rq_tagged(req)) 2044 if (blk_rq_tagged(req))
1828 blk_queue_end_tag(req->q, req); 2045 blk_queue_end_tag(req->q, req);
1829 2046
1830 if (blk_queued_rq(req)) 2047 BUG_ON(blk_queued_rq(req));
1831 elv_dequeue_request(req->q, req);
1832 2048
1833 if (unlikely(laptop_mode) && blk_fs_request(req)) 2049 if (unlikely(laptop_mode) && blk_fs_request(req))
1834 laptop_io_completion(); 2050 laptop_io_completion();
@@ -1848,117 +2064,62 @@ static void end_that_request_last(struct request *req, int error)
1848} 2064}
1849 2065
1850/** 2066/**
1851 * blk_rq_bytes - Returns bytes left to complete in the entire request 2067 * blk_end_bidi_request - Complete a bidi request
1852 * @rq: the request being processed 2068 * @rq: the request to complete
1853 **/ 2069 * @error: %0 for success, < %0 for error
1854unsigned int blk_rq_bytes(struct request *rq) 2070 * @nr_bytes: number of bytes to complete @rq
1855{ 2071 * @bidi_bytes: number of bytes to complete @rq->next_rq
1856 if (blk_fs_request(rq))
1857 return rq->hard_nr_sectors << 9;
1858
1859 return rq->data_len;
1860}
1861EXPORT_SYMBOL_GPL(blk_rq_bytes);
1862
1863/**
1864 * blk_rq_cur_bytes - Returns bytes left to complete in the current segment
1865 * @rq: the request being processed
1866 **/
1867unsigned int blk_rq_cur_bytes(struct request *rq)
1868{
1869 if (blk_fs_request(rq))
1870 return rq->current_nr_sectors << 9;
1871
1872 if (rq->bio)
1873 return rq->bio->bi_size;
1874
1875 return rq->data_len;
1876}
1877EXPORT_SYMBOL_GPL(blk_rq_cur_bytes);
1878
1879/**
1880 * end_request - end I/O on the current segment of the request
1881 * @req: the request being processed
1882 * @uptodate: error value or %0/%1 uptodate flag
1883 * 2072 *
1884 * Description: 2073 * Description:
1885 * Ends I/O on the current segment of a request. If that is the only 2074 * Ends I/O on a number of bytes attached to @rq and @rq->next_rq.
1886 * remaining segment, the request is also completed and freed. 2075 * Drivers that supports bidi can safely call this member for any
1887 * 2076 * type of request, bidi or uni. In the later case @bidi_bytes is
1888 * This is a remnant of how older block drivers handled I/O completions. 2077 * just ignored.
1889 * Modern drivers typically end I/O on the full request in one go, unless 2078 *
1890 * they have a residual value to account for. For that case this function 2079 * Return:
1891 * isn't really useful, unless the residual just happens to be the 2080 * %false - we are done with this request
1892 * full current segment. In other words, don't use this function in new 2081 * %true - still buffers pending for this request
1893 * code. Use blk_end_request() or __blk_end_request() to end a request.
1894 **/ 2082 **/
1895void end_request(struct request *req, int uptodate) 2083static bool blk_end_bidi_request(struct request *rq, int error,
1896{
1897 int error = 0;
1898
1899 if (uptodate <= 0)
1900 error = uptodate ? uptodate : -EIO;
1901
1902 __blk_end_request(req, error, req->hard_cur_sectors << 9);
1903}
1904EXPORT_SYMBOL(end_request);
1905
1906static int end_that_request_data(struct request *rq, int error,
1907 unsigned int nr_bytes, unsigned int bidi_bytes) 2084 unsigned int nr_bytes, unsigned int bidi_bytes)
1908{ 2085{
1909 if (rq->bio) { 2086 struct request_queue *q = rq->q;
1910 if (__end_that_request_first(rq, error, nr_bytes)) 2087 unsigned long flags;
1911 return 1;
1912 2088
1913 /* Bidi request must be completed as a whole */ 2089 if (blk_update_bidi_request(rq, error, nr_bytes, bidi_bytes))
1914 if (blk_bidi_rq(rq) && 2090 return true;
1915 __end_that_request_first(rq->next_rq, error, bidi_bytes))
1916 return 1;
1917 }
1918 2091
1919 return 0; 2092 spin_lock_irqsave(q->queue_lock, flags);
2093 blk_finish_request(rq, error);
2094 spin_unlock_irqrestore(q->queue_lock, flags);
2095
2096 return false;
1920} 2097}
1921 2098
1922/** 2099/**
1923 * blk_end_io - Generic end_io function to complete a request. 2100 * __blk_end_bidi_request - Complete a bidi request with queue lock held
1924 * @rq: the request being processed 2101 * @rq: the request to complete
1925 * @error: %0 for success, < %0 for error 2102 * @error: %0 for success, < %0 for error
1926 * @nr_bytes: number of bytes to complete @rq 2103 * @nr_bytes: number of bytes to complete @rq
1927 * @bidi_bytes: number of bytes to complete @rq->next_rq 2104 * @bidi_bytes: number of bytes to complete @rq->next_rq
1928 * @drv_callback: function called between completion of bios in the request
1929 * and completion of the request.
1930 * If the callback returns non %0, this helper returns without
1931 * completion of the request.
1932 * 2105 *
1933 * Description: 2106 * Description:
1934 * Ends I/O on a number of bytes attached to @rq and @rq->next_rq. 2107 * Identical to blk_end_bidi_request() except that queue lock is
1935 * If @rq has leftover, sets it up for the next range of segments. 2108 * assumed to be locked on entry and remains so on return.
1936 * 2109 *
1937 * Return: 2110 * Return:
1938 * %0 - we are done with this request 2111 * %false - we are done with this request
1939 * %1 - this request is not freed yet, it still has pending buffers. 2112 * %true - still buffers pending for this request
1940 **/ 2113 **/
1941static int blk_end_io(struct request *rq, int error, unsigned int nr_bytes, 2114static bool __blk_end_bidi_request(struct request *rq, int error,
1942 unsigned int bidi_bytes, 2115 unsigned int nr_bytes, unsigned int bidi_bytes)
1943 int (drv_callback)(struct request *))
1944{ 2116{
1945 struct request_queue *q = rq->q; 2117 if (blk_update_bidi_request(rq, error, nr_bytes, bidi_bytes))
1946 unsigned long flags = 0UL; 2118 return true;
1947
1948 if (end_that_request_data(rq, error, nr_bytes, bidi_bytes))
1949 return 1;
1950
1951 /* Special feature for tricky drivers */
1952 if (drv_callback && drv_callback(rq))
1953 return 1;
1954
1955 add_disk_randomness(rq->rq_disk);
1956 2119
1957 spin_lock_irqsave(q->queue_lock, flags); 2120 blk_finish_request(rq, error);
1958 end_that_request_last(rq, error);
1959 spin_unlock_irqrestore(q->queue_lock, flags);
1960 2121
1961 return 0; 2122 return false;
1962} 2123}
1963 2124
1964/** 2125/**
@@ -1972,124 +2133,112 @@ static int blk_end_io(struct request *rq, int error, unsigned int nr_bytes,
1972 * If @rq has leftover, sets it up for the next range of segments. 2133 * If @rq has leftover, sets it up for the next range of segments.
1973 * 2134 *
1974 * Return: 2135 * Return:
1975 * %0 - we are done with this request 2136 * %false - we are done with this request
1976 * %1 - still buffers pending for this request 2137 * %true - still buffers pending for this request
1977 **/ 2138 **/
1978int blk_end_request(struct request *rq, int error, unsigned int nr_bytes) 2139bool blk_end_request(struct request *rq, int error, unsigned int nr_bytes)
1979{ 2140{
1980 return blk_end_io(rq, error, nr_bytes, 0, NULL); 2141 return blk_end_bidi_request(rq, error, nr_bytes, 0);
1981} 2142}
1982EXPORT_SYMBOL_GPL(blk_end_request); 2143EXPORT_SYMBOL_GPL(blk_end_request);
1983 2144
1984/** 2145/**
1985 * __blk_end_request - Helper function for drivers to complete the request. 2146 * blk_end_request_all - Helper function for drives to finish the request.
1986 * @rq: the request being processed 2147 * @rq: the request to finish
1987 * @error: %0 for success, < %0 for error 2148 * @err: %0 for success, < %0 for error
1988 * @nr_bytes: number of bytes to complete
1989 * 2149 *
1990 * Description: 2150 * Description:
1991 * Must be called with queue lock held unlike blk_end_request(). 2151 * Completely finish @rq.
1992 * 2152 */
1993 * Return: 2153void blk_end_request_all(struct request *rq, int error)
1994 * %0 - we are done with this request
1995 * %1 - still buffers pending for this request
1996 **/
1997int __blk_end_request(struct request *rq, int error, unsigned int nr_bytes)
1998{ 2154{
1999 if (rq->bio && __end_that_request_first(rq, error, nr_bytes)) 2155 bool pending;
2000 return 1; 2156 unsigned int bidi_bytes = 0;
2001 2157
2002 add_disk_randomness(rq->rq_disk); 2158 if (unlikely(blk_bidi_rq(rq)))
2159 bidi_bytes = blk_rq_bytes(rq->next_rq);
2003 2160
2004 end_that_request_last(rq, error); 2161 pending = blk_end_bidi_request(rq, error, blk_rq_bytes(rq), bidi_bytes);
2162 BUG_ON(pending);
2163}
2164EXPORT_SYMBOL_GPL(blk_end_request_all);
2005 2165
2006 return 0; 2166/**
2167 * blk_end_request_cur - Helper function to finish the current request chunk.
2168 * @rq: the request to finish the current chunk for
2169 * @err: %0 for success, < %0 for error
2170 *
2171 * Description:
2172 * Complete the current consecutively mapped chunk from @rq.
2173 *
2174 * Return:
2175 * %false - we are done with this request
2176 * %true - still buffers pending for this request
2177 */
2178bool blk_end_request_cur(struct request *rq, int error)
2179{
2180 return blk_end_request(rq, error, blk_rq_cur_bytes(rq));
2007} 2181}
2008EXPORT_SYMBOL_GPL(__blk_end_request); 2182EXPORT_SYMBOL_GPL(blk_end_request_cur);
2009 2183
2010/** 2184/**
2011 * blk_end_bidi_request - Helper function for drivers to complete bidi request. 2185 * __blk_end_request - Helper function for drivers to complete the request.
2012 * @rq: the bidi request being processed 2186 * @rq: the request being processed
2013 * @error: %0 for success, < %0 for error 2187 * @error: %0 for success, < %0 for error
2014 * @nr_bytes: number of bytes to complete @rq 2188 * @nr_bytes: number of bytes to complete
2015 * @bidi_bytes: number of bytes to complete @rq->next_rq
2016 * 2189 *
2017 * Description: 2190 * Description:
2018 * Ends I/O on a number of bytes attached to @rq and @rq->next_rq. 2191 * Must be called with queue lock held unlike blk_end_request().
2019 * 2192 *
2020 * Return: 2193 * Return:
2021 * %0 - we are done with this request 2194 * %false - we are done with this request
2022 * %1 - still buffers pending for this request 2195 * %true - still buffers pending for this request
2023 **/ 2196 **/
2024int blk_end_bidi_request(struct request *rq, int error, unsigned int nr_bytes, 2197bool __blk_end_request(struct request *rq, int error, unsigned int nr_bytes)
2025 unsigned int bidi_bytes)
2026{ 2198{
2027 return blk_end_io(rq, error, nr_bytes, bidi_bytes, NULL); 2199 return __blk_end_bidi_request(rq, error, nr_bytes, 0);
2028} 2200}
2029EXPORT_SYMBOL_GPL(blk_end_bidi_request); 2201EXPORT_SYMBOL_GPL(__blk_end_request);
2030 2202
2031/** 2203/**
2032 * blk_update_request - Special helper function for request stacking drivers 2204 * __blk_end_request_all - Helper function for drives to finish the request.
2033 * @rq: the request being processed 2205 * @rq: the request to finish
2034 * @error: %0 for success, < %0 for error 2206 * @err: %0 for success, < %0 for error
2035 * @nr_bytes: number of bytes to complete @rq
2036 * 2207 *
2037 * Description: 2208 * Description:
2038 * Ends I/O on a number of bytes attached to @rq, but doesn't complete 2209 * Completely finish @rq. Must be called with queue lock held.
2039 * the request structure even if @rq doesn't have leftover.
2040 * If @rq has leftover, sets it up for the next range of segments.
2041 *
2042 * This special helper function is only for request stacking drivers
2043 * (e.g. request-based dm) so that they can handle partial completion.
2044 * Actual device drivers should use blk_end_request instead.
2045 */ 2210 */
2046void blk_update_request(struct request *rq, int error, unsigned int nr_bytes) 2211void __blk_end_request_all(struct request *rq, int error)
2047{ 2212{
2048 if (!end_that_request_data(rq, error, nr_bytes, 0)) { 2213 bool pending;
2049 /* 2214 unsigned int bidi_bytes = 0;
2050 * These members are not updated in end_that_request_data() 2215
2051 * when all bios are completed. 2216 if (unlikely(blk_bidi_rq(rq)))
2052 * Update them so that the request stacking driver can find 2217 bidi_bytes = blk_rq_bytes(rq->next_rq);
2053 * how many bytes remain in the request later. 2218
2054 */ 2219 pending = __blk_end_bidi_request(rq, error, blk_rq_bytes(rq), bidi_bytes);
2055 rq->nr_sectors = rq->hard_nr_sectors = 0; 2220 BUG_ON(pending);
2056 rq->current_nr_sectors = rq->hard_cur_sectors = 0;
2057 }
2058} 2221}
2059EXPORT_SYMBOL_GPL(blk_update_request); 2222EXPORT_SYMBOL_GPL(__blk_end_request_all);
2060 2223
2061/** 2224/**
2062 * blk_end_request_callback - Special helper function for tricky drivers 2225 * __blk_end_request_cur - Helper function to finish the current request chunk.
2063 * @rq: the request being processed 2226 * @rq: the request to finish the current chunk for
2064 * @error: %0 for success, < %0 for error 2227 * @err: %0 for success, < %0 for error
2065 * @nr_bytes: number of bytes to complete
2066 * @drv_callback: function called between completion of bios in the request
2067 * and completion of the request.
2068 * If the callback returns non %0, this helper returns without
2069 * completion of the request.
2070 * 2228 *
2071 * Description: 2229 * Description:
2072 * Ends I/O on a number of bytes attached to @rq. 2230 * Complete the current consecutively mapped chunk from @rq. Must
2073 * If @rq has leftover, sets it up for the next range of segments. 2231 * be called with queue lock held.
2074 *
2075 * This special helper function is used only for existing tricky drivers.
2076 * (e.g. cdrom_newpc_intr() of ide-cd)
2077 * This interface will be removed when such drivers are rewritten.
2078 * Don't use this interface in other places anymore.
2079 * 2232 *
2080 * Return: 2233 * Return:
2081 * %0 - we are done with this request 2234 * %false - we are done with this request
2082 * %1 - this request is not freed yet. 2235 * %true - still buffers pending for this request
2083 * this request still has pending buffers or 2236 */
2084 * the driver doesn't want to finish this request yet. 2237bool __blk_end_request_cur(struct request *rq, int error)
2085 **/
2086int blk_end_request_callback(struct request *rq, int error,
2087 unsigned int nr_bytes,
2088 int (drv_callback)(struct request *))
2089{ 2238{
2090 return blk_end_io(rq, error, nr_bytes, 0, drv_callback); 2239 return __blk_end_request(rq, error, blk_rq_cur_bytes(rq));
2091} 2240}
2092EXPORT_SYMBOL_GPL(blk_end_request_callback); 2241EXPORT_SYMBOL_GPL(__blk_end_request_cur);
2093 2242
2094void blk_rq_bio_prep(struct request_queue *q, struct request *rq, 2243void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
2095 struct bio *bio) 2244 struct bio *bio)
@@ -2102,11 +2251,7 @@ void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
2102 rq->nr_phys_segments = bio_phys_segments(q, bio); 2251 rq->nr_phys_segments = bio_phys_segments(q, bio);
2103 rq->buffer = bio_data(bio); 2252 rq->buffer = bio_data(bio);
2104 } 2253 }
2105 rq->current_nr_sectors = bio_cur_sectors(bio); 2254 rq->__data_len = bio->bi_size;
2106 rq->hard_cur_sectors = rq->current_nr_sectors;
2107 rq->hard_nr_sectors = rq->nr_sectors = bio_sectors(bio);
2108 rq->data_len = bio->bi_size;
2109
2110 rq->bio = rq->biotail = bio; 2255 rq->bio = rq->biotail = bio;
2111 2256
2112 if (bio->bi_bdev) 2257 if (bio->bi_bdev)
@@ -2141,6 +2286,106 @@ int blk_lld_busy(struct request_queue *q)
2141} 2286}
2142EXPORT_SYMBOL_GPL(blk_lld_busy); 2287EXPORT_SYMBOL_GPL(blk_lld_busy);
2143 2288
2289/**
2290 * blk_rq_unprep_clone - Helper function to free all bios in a cloned request
2291 * @rq: the clone request to be cleaned up
2292 *
2293 * Description:
2294 * Free all bios in @rq for a cloned request.
2295 */
2296void blk_rq_unprep_clone(struct request *rq)
2297{
2298 struct bio *bio;
2299
2300 while ((bio = rq->bio) != NULL) {
2301 rq->bio = bio->bi_next;
2302
2303 bio_put(bio);
2304 }
2305}
2306EXPORT_SYMBOL_GPL(blk_rq_unprep_clone);
2307
2308/*
2309 * Copy attributes of the original request to the clone request.
2310 * The actual data parts (e.g. ->cmd, ->buffer, ->sense) are not copied.
2311 */
2312static void __blk_rq_prep_clone(struct request *dst, struct request *src)
2313{
2314 dst->cpu = src->cpu;
2315 dst->cmd_flags = (rq_data_dir(src) | REQ_NOMERGE);
2316 dst->cmd_type = src->cmd_type;
2317 dst->__sector = blk_rq_pos(src);
2318 dst->__data_len = blk_rq_bytes(src);
2319 dst->nr_phys_segments = src->nr_phys_segments;
2320 dst->ioprio = src->ioprio;
2321 dst->extra_len = src->extra_len;
2322}
2323
2324/**
2325 * blk_rq_prep_clone - Helper function to setup clone request
2326 * @rq: the request to be setup
2327 * @rq_src: original request to be cloned
2328 * @bs: bio_set that bios for clone are allocated from
2329 * @gfp_mask: memory allocation mask for bio
2330 * @bio_ctr: setup function to be called for each clone bio.
2331 * Returns %0 for success, non %0 for failure.
2332 * @data: private data to be passed to @bio_ctr
2333 *
2334 * Description:
2335 * Clones bios in @rq_src to @rq, and copies attributes of @rq_src to @rq.
2336 * The actual data parts of @rq_src (e.g. ->cmd, ->buffer, ->sense)
2337 * are not copied, and copying such parts is the caller's responsibility.
2338 * Also, pages which the original bios are pointing to are not copied
2339 * and the cloned bios just point same pages.
2340 * So cloned bios must be completed before original bios, which means
2341 * the caller must complete @rq before @rq_src.
2342 */
2343int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
2344 struct bio_set *bs, gfp_t gfp_mask,
2345 int (*bio_ctr)(struct bio *, struct bio *, void *),
2346 void *data)
2347{
2348 struct bio *bio, *bio_src;
2349
2350 if (!bs)
2351 bs = fs_bio_set;
2352
2353 blk_rq_init(NULL, rq);
2354
2355 __rq_for_each_bio(bio_src, rq_src) {
2356 bio = bio_alloc_bioset(gfp_mask, bio_src->bi_max_vecs, bs);
2357 if (!bio)
2358 goto free_and_out;
2359
2360 __bio_clone(bio, bio_src);
2361
2362 if (bio_integrity(bio_src) &&
2363 bio_integrity_clone(bio, bio_src, gfp_mask))
2364 goto free_and_out;
2365
2366 if (bio_ctr && bio_ctr(bio, bio_src, data))
2367 goto free_and_out;
2368
2369 if (rq->bio) {
2370 rq->biotail->bi_next = bio;
2371 rq->biotail = bio;
2372 } else
2373 rq->bio = rq->biotail = bio;
2374 }
2375
2376 __blk_rq_prep_clone(rq, rq_src);
2377
2378 return 0;
2379
2380free_and_out:
2381 if (bio)
2382 bio_free(bio, bs);
2383 blk_rq_unprep_clone(rq);
2384
2385 return -ENOMEM;
2386}
2387EXPORT_SYMBOL_GPL(blk_rq_prep_clone);
2388
2144int kblockd_schedule_work(struct request_queue *q, struct work_struct *work) 2389int kblockd_schedule_work(struct request_queue *q, struct work_struct *work)
2145{ 2390{
2146 return queue_work(kblockd_workqueue, work); 2391 return queue_work(kblockd_workqueue, work);
@@ -2149,6 +2394,9 @@ EXPORT_SYMBOL(kblockd_schedule_work);
2149 2394
2150int __init blk_dev_init(void) 2395int __init blk_dev_init(void)
2151{ 2396{
2397 BUILD_BUG_ON(__REQ_NR_BITS > 8 *
2398 sizeof(((struct request *)0)->cmd_flags));
2399
2152 kblockd_workqueue = create_workqueue("kblockd"); 2400 kblockd_workqueue = create_workqueue("kblockd");
2153 if (!kblockd_workqueue) 2401 if (!kblockd_workqueue)
2154 panic("Failed to create kblockd\n"); 2402 panic("Failed to create kblockd\n");
diff --git a/block/blk-exec.c b/block/blk-exec.c
index 6af716d1e54e..49557e91f0da 100644
--- a/block/blk-exec.c
+++ b/block/blk-exec.c
@@ -51,7 +51,6 @@ void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk,
51 int where = at_head ? ELEVATOR_INSERT_FRONT : ELEVATOR_INSERT_BACK; 51 int where = at_head ? ELEVATOR_INSERT_FRONT : ELEVATOR_INSERT_BACK;
52 52
53 rq->rq_disk = bd_disk; 53 rq->rq_disk = bd_disk;
54 rq->cmd_flags |= REQ_NOMERGE;
55 rq->end_io = done; 54 rq->end_io = done;
56 WARN_ON(irqs_disabled()); 55 WARN_ON(irqs_disabled());
57 spin_lock_irq(q->queue_lock); 56 spin_lock_irq(q->queue_lock);
diff --git a/block/blk-integrity.c b/block/blk-integrity.c
index 91fa8e06b6a5..73e28d355688 100644
--- a/block/blk-integrity.c
+++ b/block/blk-integrity.c
@@ -340,7 +340,7 @@ int blk_integrity_register(struct gendisk *disk, struct blk_integrity *template)
340 kobject_uevent(&bi->kobj, KOBJ_ADD); 340 kobject_uevent(&bi->kobj, KOBJ_ADD);
341 341
342 bi->flags |= INTEGRITY_FLAG_READ | INTEGRITY_FLAG_WRITE; 342 bi->flags |= INTEGRITY_FLAG_READ | INTEGRITY_FLAG_WRITE;
343 bi->sector_size = disk->queue->hardsect_size; 343 bi->sector_size = queue_logical_block_size(disk->queue);
344 disk->integrity = bi; 344 disk->integrity = bi;
345 } else 345 } else
346 bi = disk->integrity; 346 bi = disk->integrity;
diff --git a/block/blk-ioc.c b/block/blk-ioc.c
index 012f065ac8e2..d4ed6000147d 100644
--- a/block/blk-ioc.c
+++ b/block/blk-ioc.c
@@ -35,9 +35,9 @@ int put_io_context(struct io_context *ioc)
35 if (ioc == NULL) 35 if (ioc == NULL)
36 return 1; 36 return 1;
37 37
38 BUG_ON(atomic_read(&ioc->refcount) == 0); 38 BUG_ON(atomic_long_read(&ioc->refcount) == 0);
39 39
40 if (atomic_dec_and_test(&ioc->refcount)) { 40 if (atomic_long_dec_and_test(&ioc->refcount)) {
41 rcu_read_lock(); 41 rcu_read_lock();
42 if (ioc->aic && ioc->aic->dtor) 42 if (ioc->aic && ioc->aic->dtor)
43 ioc->aic->dtor(ioc->aic); 43 ioc->aic->dtor(ioc->aic);
@@ -90,7 +90,7 @@ struct io_context *alloc_io_context(gfp_t gfp_flags, int node)
90 90
91 ret = kmem_cache_alloc_node(iocontext_cachep, gfp_flags, node); 91 ret = kmem_cache_alloc_node(iocontext_cachep, gfp_flags, node);
92 if (ret) { 92 if (ret) {
93 atomic_set(&ret->refcount, 1); 93 atomic_long_set(&ret->refcount, 1);
94 atomic_set(&ret->nr_tasks, 1); 94 atomic_set(&ret->nr_tasks, 1);
95 spin_lock_init(&ret->lock); 95 spin_lock_init(&ret->lock);
96 ret->ioprio_changed = 0; 96 ret->ioprio_changed = 0;
@@ -151,7 +151,7 @@ struct io_context *get_io_context(gfp_t gfp_flags, int node)
151 ret = current_io_context(gfp_flags, node); 151 ret = current_io_context(gfp_flags, node);
152 if (unlikely(!ret)) 152 if (unlikely(!ret))
153 break; 153 break;
154 } while (!atomic_inc_not_zero(&ret->refcount)); 154 } while (!atomic_long_inc_not_zero(&ret->refcount));
155 155
156 return ret; 156 return ret;
157} 157}
@@ -163,8 +163,8 @@ void copy_io_context(struct io_context **pdst, struct io_context **psrc)
163 struct io_context *dst = *pdst; 163 struct io_context *dst = *pdst;
164 164
165 if (src) { 165 if (src) {
166 BUG_ON(atomic_read(&src->refcount) == 0); 166 BUG_ON(atomic_long_read(&src->refcount) == 0);
167 atomic_inc(&src->refcount); 167 atomic_long_inc(&src->refcount);
168 put_io_context(dst); 168 put_io_context(dst);
169 *pdst = src; 169 *pdst = src;
170 } 170 }
diff --git a/block/blk-map.c b/block/blk-map.c
index f103729b462f..9083cf0180cc 100644
--- a/block/blk-map.c
+++ b/block/blk-map.c
@@ -20,11 +20,10 @@ int blk_rq_append_bio(struct request_queue *q, struct request *rq,
20 rq->biotail->bi_next = bio; 20 rq->biotail->bi_next = bio;
21 rq->biotail = bio; 21 rq->biotail = bio;
22 22
23 rq->data_len += bio->bi_size; 23 rq->__data_len += bio->bi_size;
24 } 24 }
25 return 0; 25 return 0;
26} 26}
27EXPORT_SYMBOL(blk_rq_append_bio);
28 27
29static int __blk_rq_unmap_user(struct bio *bio) 28static int __blk_rq_unmap_user(struct bio *bio)
30{ 29{
@@ -116,7 +115,7 @@ int blk_rq_map_user(struct request_queue *q, struct request *rq,
116 struct bio *bio = NULL; 115 struct bio *bio = NULL;
117 int ret; 116 int ret;
118 117
119 if (len > (q->max_hw_sectors << 9)) 118 if (len > (queue_max_hw_sectors(q) << 9))
120 return -EINVAL; 119 return -EINVAL;
121 if (!len) 120 if (!len)
122 return -EINVAL; 121 return -EINVAL;
@@ -156,7 +155,7 @@ int blk_rq_map_user(struct request_queue *q, struct request *rq,
156 if (!bio_flagged(bio, BIO_USER_MAPPED)) 155 if (!bio_flagged(bio, BIO_USER_MAPPED))
157 rq->cmd_flags |= REQ_COPY_USER; 156 rq->cmd_flags |= REQ_COPY_USER;
158 157
159 rq->buffer = rq->data = NULL; 158 rq->buffer = NULL;
160 return 0; 159 return 0;
161unmap_rq: 160unmap_rq:
162 blk_rq_unmap_user(bio); 161 blk_rq_unmap_user(bio);
@@ -235,7 +234,7 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
235 blk_queue_bounce(q, &bio); 234 blk_queue_bounce(q, &bio);
236 bio_get(bio); 235 bio_get(bio);
237 blk_rq_bio_prep(q, rq, bio); 236 blk_rq_bio_prep(q, rq, bio);
238 rq->buffer = rq->data = NULL; 237 rq->buffer = NULL;
239 return 0; 238 return 0;
240} 239}
241EXPORT_SYMBOL(blk_rq_map_user_iov); 240EXPORT_SYMBOL(blk_rq_map_user_iov);
@@ -282,7 +281,8 @@ EXPORT_SYMBOL(blk_rq_unmap_user);
282 * 281 *
283 * Description: 282 * Description:
284 * Data will be mapped directly if possible. Otherwise a bounce 283 * Data will be mapped directly if possible. Otherwise a bounce
285 * buffer is used. 284 * buffer is used. Can be called multple times to append multple
285 * buffers.
286 */ 286 */
287int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf, 287int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
288 unsigned int len, gfp_t gfp_mask) 288 unsigned int len, gfp_t gfp_mask)
@@ -290,8 +290,9 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
290 int reading = rq_data_dir(rq) == READ; 290 int reading = rq_data_dir(rq) == READ;
291 int do_copy = 0; 291 int do_copy = 0;
292 struct bio *bio; 292 struct bio *bio;
293 int ret;
293 294
294 if (len > (q->max_hw_sectors << 9)) 295 if (len > (queue_max_hw_sectors(q) << 9))
295 return -EINVAL; 296 return -EINVAL;
296 if (!len || !kbuf) 297 if (!len || !kbuf)
297 return -EINVAL; 298 return -EINVAL;
@@ -311,9 +312,15 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
311 if (do_copy) 312 if (do_copy)
312 rq->cmd_flags |= REQ_COPY_USER; 313 rq->cmd_flags |= REQ_COPY_USER;
313 314
314 blk_rq_bio_prep(q, rq, bio); 315 ret = blk_rq_append_bio(q, rq, bio);
316 if (unlikely(ret)) {
317 /* request is too big */
318 bio_put(bio);
319 return ret;
320 }
321
315 blk_queue_bounce(q, &rq->bio); 322 blk_queue_bounce(q, &rq->bio);
316 rq->buffer = rq->data = NULL; 323 rq->buffer = NULL;
317 return 0; 324 return 0;
318} 325}
319EXPORT_SYMBOL(blk_rq_map_kern); 326EXPORT_SYMBOL(blk_rq_map_kern);
diff --git a/block/blk-merge.c b/block/blk-merge.c
index 23d2a6fe34a3..39ce64432ba6 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -9,35 +9,6 @@
9 9
10#include "blk.h" 10#include "blk.h"
11 11
12void blk_recalc_rq_sectors(struct request *rq, int nsect)
13{
14 if (blk_fs_request(rq) || blk_discard_rq(rq)) {
15 rq->hard_sector += nsect;
16 rq->hard_nr_sectors -= nsect;
17
18 /*
19 * Move the I/O submission pointers ahead if required.
20 */
21 if ((rq->nr_sectors >= rq->hard_nr_sectors) &&
22 (rq->sector <= rq->hard_sector)) {
23 rq->sector = rq->hard_sector;
24 rq->nr_sectors = rq->hard_nr_sectors;
25 rq->hard_cur_sectors = bio_cur_sectors(rq->bio);
26 rq->current_nr_sectors = rq->hard_cur_sectors;
27 rq->buffer = bio_data(rq->bio);
28 }
29
30 /*
31 * if total number of sectors is less than the first segment
32 * size, something has gone terribly wrong
33 */
34 if (rq->nr_sectors < rq->current_nr_sectors) {
35 printk(KERN_ERR "blk: request botched\n");
36 rq->nr_sectors = rq->current_nr_sectors;
37 }
38 }
39}
40
41static unsigned int __blk_recalc_rq_segments(struct request_queue *q, 12static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
42 struct bio *bio) 13 struct bio *bio)
43{ 14{
@@ -61,11 +32,12 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
61 * never considered part of another segment, since that 32 * never considered part of another segment, since that
62 * might change with the bounce page. 33 * might change with the bounce page.
63 */ 34 */
64 high = page_to_pfn(bv->bv_page) > q->bounce_pfn; 35 high = page_to_pfn(bv->bv_page) > queue_bounce_pfn(q);
65 if (high || highprv) 36 if (high || highprv)
66 goto new_segment; 37 goto new_segment;
67 if (cluster) { 38 if (cluster) {
68 if (seg_size + bv->bv_len > q->max_segment_size) 39 if (seg_size + bv->bv_len
40 > queue_max_segment_size(q))
69 goto new_segment; 41 goto new_segment;
70 if (!BIOVEC_PHYS_MERGEABLE(bvprv, bv)) 42 if (!BIOVEC_PHYS_MERGEABLE(bvprv, bv))
71 goto new_segment; 43 goto new_segment;
@@ -120,7 +92,7 @@ static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio,
120 return 0; 92 return 0;
121 93
122 if (bio->bi_seg_back_size + nxt->bi_seg_front_size > 94 if (bio->bi_seg_back_size + nxt->bi_seg_front_size >
123 q->max_segment_size) 95 queue_max_segment_size(q))
124 return 0; 96 return 0;
125 97
126 if (!bio_has_data(bio)) 98 if (!bio_has_data(bio))
@@ -163,7 +135,7 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,
163 int nbytes = bvec->bv_len; 135 int nbytes = bvec->bv_len;
164 136
165 if (bvprv && cluster) { 137 if (bvprv && cluster) {
166 if (sg->length + nbytes > q->max_segment_size) 138 if (sg->length + nbytes > queue_max_segment_size(q))
167 goto new_segment; 139 goto new_segment;
168 140
169 if (!BIOVEC_PHYS_MERGEABLE(bvprv, bvec)) 141 if (!BIOVEC_PHYS_MERGEABLE(bvprv, bvec))
@@ -199,8 +171,9 @@ new_segment:
199 171
200 172
201 if (unlikely(rq->cmd_flags & REQ_COPY_USER) && 173 if (unlikely(rq->cmd_flags & REQ_COPY_USER) &&
202 (rq->data_len & q->dma_pad_mask)) { 174 (blk_rq_bytes(rq) & q->dma_pad_mask)) {
203 unsigned int pad_len = (q->dma_pad_mask & ~rq->data_len) + 1; 175 unsigned int pad_len =
176 (q->dma_pad_mask & ~blk_rq_bytes(rq)) + 1;
204 177
205 sg->length += pad_len; 178 sg->length += pad_len;
206 rq->extra_len += pad_len; 179 rq->extra_len += pad_len;
@@ -233,8 +206,8 @@ static inline int ll_new_hw_segment(struct request_queue *q,
233{ 206{
234 int nr_phys_segs = bio_phys_segments(q, bio); 207 int nr_phys_segs = bio_phys_segments(q, bio);
235 208
236 if (req->nr_phys_segments + nr_phys_segs > q->max_hw_segments 209 if (req->nr_phys_segments + nr_phys_segs > queue_max_hw_segments(q) ||
237 || req->nr_phys_segments + nr_phys_segs > q->max_phys_segments) { 210 req->nr_phys_segments + nr_phys_segs > queue_max_phys_segments(q)) {
238 req->cmd_flags |= REQ_NOMERGE; 211 req->cmd_flags |= REQ_NOMERGE;
239 if (req == q->last_merge) 212 if (req == q->last_merge)
240 q->last_merge = NULL; 213 q->last_merge = NULL;
@@ -255,11 +228,11 @@ int ll_back_merge_fn(struct request_queue *q, struct request *req,
255 unsigned short max_sectors; 228 unsigned short max_sectors;
256 229
257 if (unlikely(blk_pc_request(req))) 230 if (unlikely(blk_pc_request(req)))
258 max_sectors = q->max_hw_sectors; 231 max_sectors = queue_max_hw_sectors(q);
259 else 232 else
260 max_sectors = q->max_sectors; 233 max_sectors = queue_max_sectors(q);
261 234
262 if (req->nr_sectors + bio_sectors(bio) > max_sectors) { 235 if (blk_rq_sectors(req) + bio_sectors(bio) > max_sectors) {
263 req->cmd_flags |= REQ_NOMERGE; 236 req->cmd_flags |= REQ_NOMERGE;
264 if (req == q->last_merge) 237 if (req == q->last_merge)
265 q->last_merge = NULL; 238 q->last_merge = NULL;
@@ -279,12 +252,12 @@ int ll_front_merge_fn(struct request_queue *q, struct request *req,
279 unsigned short max_sectors; 252 unsigned short max_sectors;
280 253
281 if (unlikely(blk_pc_request(req))) 254 if (unlikely(blk_pc_request(req)))
282 max_sectors = q->max_hw_sectors; 255 max_sectors = queue_max_hw_sectors(q);
283 else 256 else
284 max_sectors = q->max_sectors; 257 max_sectors = queue_max_sectors(q);
285 258
286 259
287 if (req->nr_sectors + bio_sectors(bio) > max_sectors) { 260 if (blk_rq_sectors(req) + bio_sectors(bio) > max_sectors) {
288 req->cmd_flags |= REQ_NOMERGE; 261 req->cmd_flags |= REQ_NOMERGE;
289 if (req == q->last_merge) 262 if (req == q->last_merge)
290 q->last_merge = NULL; 263 q->last_merge = NULL;
@@ -315,7 +288,7 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
315 /* 288 /*
316 * Will it become too large? 289 * Will it become too large?
317 */ 290 */
318 if ((req->nr_sectors + next->nr_sectors) > q->max_sectors) 291 if ((blk_rq_sectors(req) + blk_rq_sectors(next)) > queue_max_sectors(q))
319 return 0; 292 return 0;
320 293
321 total_phys_segments = req->nr_phys_segments + next->nr_phys_segments; 294 total_phys_segments = req->nr_phys_segments + next->nr_phys_segments;
@@ -327,10 +300,10 @@ static int ll_merge_requests_fn(struct request_queue *q, struct request *req,
327 total_phys_segments--; 300 total_phys_segments--;
328 } 301 }
329 302
330 if (total_phys_segments > q->max_phys_segments) 303 if (total_phys_segments > queue_max_phys_segments(q))
331 return 0; 304 return 0;
332 305
333 if (total_phys_segments > q->max_hw_segments) 306 if (total_phys_segments > queue_max_hw_segments(q))
334 return 0; 307 return 0;
335 308
336 /* Merge is OK... */ 309 /* Merge is OK... */
@@ -345,7 +318,7 @@ static void blk_account_io_merge(struct request *req)
345 int cpu; 318 int cpu;
346 319
347 cpu = part_stat_lock(); 320 cpu = part_stat_lock();
348 part = disk_map_sector_rcu(req->rq_disk, req->sector); 321 part = disk_map_sector_rcu(req->rq_disk, blk_rq_pos(req));
349 322
350 part_round_stats(cpu, part); 323 part_round_stats(cpu, part);
351 part_dec_in_flight(part); 324 part_dec_in_flight(part);
@@ -366,7 +339,7 @@ static int attempt_merge(struct request_queue *q, struct request *req,
366 /* 339 /*
367 * not contiguous 340 * not contiguous
368 */ 341 */
369 if (req->sector + req->nr_sectors != next->sector) 342 if (blk_rq_pos(req) + blk_rq_sectors(req) != blk_rq_pos(next))
370 return 0; 343 return 0;
371 344
372 if (rq_data_dir(req) != rq_data_dir(next) 345 if (rq_data_dir(req) != rq_data_dir(next)
@@ -398,7 +371,7 @@ static int attempt_merge(struct request_queue *q, struct request *req,
398 req->biotail->bi_next = next->bio; 371 req->biotail->bi_next = next->bio;
399 req->biotail = next->biotail; 372 req->biotail = next->biotail;
400 373
401 req->nr_sectors = req->hard_nr_sectors += next->hard_nr_sectors; 374 req->__data_len += blk_rq_bytes(next);
402 375
403 elv_merge_requests(q, req, next); 376 elv_merge_requests(q, req, next);
404 377
diff --git a/block/blk-settings.c b/block/blk-settings.c
index 57af728d94bb..1c4df9bf6813 100644
--- a/block/blk-settings.c
+++ b/block/blk-settings.c
@@ -134,7 +134,7 @@ void blk_queue_make_request(struct request_queue *q, make_request_fn *mfn)
134 q->backing_dev_info.state = 0; 134 q->backing_dev_info.state = 0;
135 q->backing_dev_info.capabilities = BDI_CAP_MAP_COPY; 135 q->backing_dev_info.capabilities = BDI_CAP_MAP_COPY;
136 blk_queue_max_sectors(q, SAFE_MAX_SECTORS); 136 blk_queue_max_sectors(q, SAFE_MAX_SECTORS);
137 blk_queue_hardsect_size(q, 512); 137 blk_queue_logical_block_size(q, 512);
138 blk_queue_dma_alignment(q, 511); 138 blk_queue_dma_alignment(q, 511);
139 blk_queue_congestion_threshold(q); 139 blk_queue_congestion_threshold(q);
140 q->nr_batching = BLK_BATCH_REQ; 140 q->nr_batching = BLK_BATCH_REQ;
@@ -179,16 +179,16 @@ void blk_queue_bounce_limit(struct request_queue *q, u64 dma_mask)
179 */ 179 */
180 if (b_pfn < (min_t(u64, 0xffffffffUL, BLK_BOUNCE_HIGH) >> PAGE_SHIFT)) 180 if (b_pfn < (min_t(u64, 0xffffffffUL, BLK_BOUNCE_HIGH) >> PAGE_SHIFT))
181 dma = 1; 181 dma = 1;
182 q->bounce_pfn = max_low_pfn; 182 q->limits.bounce_pfn = max_low_pfn;
183#else 183#else
184 if (b_pfn < blk_max_low_pfn) 184 if (b_pfn < blk_max_low_pfn)
185 dma = 1; 185 dma = 1;
186 q->bounce_pfn = b_pfn; 186 q->limits.bounce_pfn = b_pfn;
187#endif 187#endif
188 if (dma) { 188 if (dma) {
189 init_emergency_isa_pool(); 189 init_emergency_isa_pool();
190 q->bounce_gfp = GFP_NOIO | GFP_DMA; 190 q->bounce_gfp = GFP_NOIO | GFP_DMA;
191 q->bounce_pfn = b_pfn; 191 q->limits.bounce_pfn = b_pfn;
192 } 192 }
193} 193}
194EXPORT_SYMBOL(blk_queue_bounce_limit); 194EXPORT_SYMBOL(blk_queue_bounce_limit);
@@ -211,14 +211,23 @@ void blk_queue_max_sectors(struct request_queue *q, unsigned int max_sectors)
211 } 211 }
212 212
213 if (BLK_DEF_MAX_SECTORS > max_sectors) 213 if (BLK_DEF_MAX_SECTORS > max_sectors)
214 q->max_hw_sectors = q->max_sectors = max_sectors; 214 q->limits.max_hw_sectors = q->limits.max_sectors = max_sectors;
215 else { 215 else {
216 q->max_sectors = BLK_DEF_MAX_SECTORS; 216 q->limits.max_sectors = BLK_DEF_MAX_SECTORS;
217 q->max_hw_sectors = max_sectors; 217 q->limits.max_hw_sectors = max_sectors;
218 } 218 }
219} 219}
220EXPORT_SYMBOL(blk_queue_max_sectors); 220EXPORT_SYMBOL(blk_queue_max_sectors);
221 221
222void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_sectors)
223{
224 if (BLK_DEF_MAX_SECTORS > max_sectors)
225 q->limits.max_hw_sectors = BLK_DEF_MAX_SECTORS;
226 else
227 q->limits.max_hw_sectors = max_sectors;
228}
229EXPORT_SYMBOL(blk_queue_max_hw_sectors);
230
222/** 231/**
223 * blk_queue_max_phys_segments - set max phys segments for a request for this queue 232 * blk_queue_max_phys_segments - set max phys segments for a request for this queue
224 * @q: the request queue for the device 233 * @q: the request queue for the device
@@ -238,7 +247,7 @@ void blk_queue_max_phys_segments(struct request_queue *q,
238 __func__, max_segments); 247 __func__, max_segments);
239 } 248 }
240 249
241 q->max_phys_segments = max_segments; 250 q->limits.max_phys_segments = max_segments;
242} 251}
243EXPORT_SYMBOL(blk_queue_max_phys_segments); 252EXPORT_SYMBOL(blk_queue_max_phys_segments);
244 253
@@ -262,7 +271,7 @@ void blk_queue_max_hw_segments(struct request_queue *q,
262 __func__, max_segments); 271 __func__, max_segments);
263 } 272 }
264 273
265 q->max_hw_segments = max_segments; 274 q->limits.max_hw_segments = max_segments;
266} 275}
267EXPORT_SYMBOL(blk_queue_max_hw_segments); 276EXPORT_SYMBOL(blk_queue_max_hw_segments);
268 277
@@ -283,26 +292,110 @@ void blk_queue_max_segment_size(struct request_queue *q, unsigned int max_size)
283 __func__, max_size); 292 __func__, max_size);
284 } 293 }
285 294
286 q->max_segment_size = max_size; 295 q->limits.max_segment_size = max_size;
287} 296}
288EXPORT_SYMBOL(blk_queue_max_segment_size); 297EXPORT_SYMBOL(blk_queue_max_segment_size);
289 298
290/** 299/**
291 * blk_queue_hardsect_size - set hardware sector size for the queue 300 * blk_queue_logical_block_size - set logical block size for the queue
292 * @q: the request queue for the device 301 * @q: the request queue for the device
293 * @size: the hardware sector size, in bytes 302 * @size: the logical block size, in bytes
294 * 303 *
295 * Description: 304 * Description:
296 * This should typically be set to the lowest possible sector size 305 * This should be set to the lowest possible block size that the
297 * that the hardware can operate on (possible without reverting to 306 * storage device can address. The default of 512 covers most
298 * even internal read-modify-write operations). Usually the default 307 * hardware.
299 * of 512 covers most hardware.
300 **/ 308 **/
301void blk_queue_hardsect_size(struct request_queue *q, unsigned short size) 309void blk_queue_logical_block_size(struct request_queue *q, unsigned short size)
310{
311 q->limits.logical_block_size = size;
312
313 if (q->limits.physical_block_size < size)
314 q->limits.physical_block_size = size;
315
316 if (q->limits.io_min < q->limits.physical_block_size)
317 q->limits.io_min = q->limits.physical_block_size;
318}
319EXPORT_SYMBOL(blk_queue_logical_block_size);
320
321/**
322 * blk_queue_physical_block_size - set physical block size for the queue
323 * @q: the request queue for the device
324 * @size: the physical block size, in bytes
325 *
326 * Description:
327 * This should be set to the lowest possible sector size that the
328 * hardware can operate on without reverting to read-modify-write
329 * operations.
330 */
331void blk_queue_physical_block_size(struct request_queue *q, unsigned short size)
332{
333 q->limits.physical_block_size = size;
334
335 if (q->limits.physical_block_size < q->limits.logical_block_size)
336 q->limits.physical_block_size = q->limits.logical_block_size;
337
338 if (q->limits.io_min < q->limits.physical_block_size)
339 q->limits.io_min = q->limits.physical_block_size;
340}
341EXPORT_SYMBOL(blk_queue_physical_block_size);
342
343/**
344 * blk_queue_alignment_offset - set physical block alignment offset
345 * @q: the request queue for the device
346 * @alignment: alignment offset in bytes
347 *
348 * Description:
349 * Some devices are naturally misaligned to compensate for things like
350 * the legacy DOS partition table 63-sector offset. Low-level drivers
351 * should call this function for devices whose first sector is not
352 * naturally aligned.
353 */
354void blk_queue_alignment_offset(struct request_queue *q, unsigned int offset)
302{ 355{
303 q->hardsect_size = size; 356 q->limits.alignment_offset =
357 offset & (q->limits.physical_block_size - 1);
358 q->limits.misaligned = 0;
304} 359}
305EXPORT_SYMBOL(blk_queue_hardsect_size); 360EXPORT_SYMBOL(blk_queue_alignment_offset);
361
362/**
363 * blk_queue_io_min - set minimum request size for the queue
364 * @q: the request queue for the device
365 * @io_min: smallest I/O size in bytes
366 *
367 * Description:
368 * Some devices have an internal block size bigger than the reported
369 * hardware sector size. This function can be used to signal the
370 * smallest I/O the device can perform without incurring a performance
371 * penalty.
372 */
373void blk_queue_io_min(struct request_queue *q, unsigned int min)
374{
375 q->limits.io_min = min;
376
377 if (q->limits.io_min < q->limits.logical_block_size)
378 q->limits.io_min = q->limits.logical_block_size;
379
380 if (q->limits.io_min < q->limits.physical_block_size)
381 q->limits.io_min = q->limits.physical_block_size;
382}
383EXPORT_SYMBOL(blk_queue_io_min);
384
385/**
386 * blk_queue_io_opt - set optimal request size for the queue
387 * @q: the request queue for the device
388 * @io_opt: optimal request size in bytes
389 *
390 * Description:
391 * Drivers can call this function to set the preferred I/O request
392 * size for devices that report such a value.
393 */
394void blk_queue_io_opt(struct request_queue *q, unsigned int opt)
395{
396 q->limits.io_opt = opt;
397}
398EXPORT_SYMBOL(blk_queue_io_opt);
306 399
307/* 400/*
308 * Returns the minimum that is _not_ zero, unless both are zero. 401 * Returns the minimum that is _not_ zero, unless both are zero.
@@ -317,14 +410,27 @@ EXPORT_SYMBOL(blk_queue_hardsect_size);
317void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b) 410void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b)
318{ 411{
319 /* zero is "infinity" */ 412 /* zero is "infinity" */
320 t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors); 413 t->limits.max_sectors = min_not_zero(queue_max_sectors(t),
321 t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors); 414 queue_max_sectors(b));
322 t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask, b->seg_boundary_mask); 415
416 t->limits.max_hw_sectors = min_not_zero(queue_max_hw_sectors(t),
417 queue_max_hw_sectors(b));
418
419 t->limits.seg_boundary_mask = min_not_zero(queue_segment_boundary(t),
420 queue_segment_boundary(b));
421
422 t->limits.max_phys_segments = min_not_zero(queue_max_phys_segments(t),
423 queue_max_phys_segments(b));
424
425 t->limits.max_hw_segments = min_not_zero(queue_max_hw_segments(t),
426 queue_max_hw_segments(b));
427
428 t->limits.max_segment_size = min_not_zero(queue_max_segment_size(t),
429 queue_max_segment_size(b));
430
431 t->limits.logical_block_size = max(queue_logical_block_size(t),
432 queue_logical_block_size(b));
323 433
324 t->max_phys_segments = min_not_zero(t->max_phys_segments, b->max_phys_segments);
325 t->max_hw_segments = min_not_zero(t->max_hw_segments, b->max_hw_segments);
326 t->max_segment_size = min_not_zero(t->max_segment_size, b->max_segment_size);
327 t->hardsect_size = max(t->hardsect_size, b->hardsect_size);
328 if (!t->queue_lock) 434 if (!t->queue_lock)
329 WARN_ON_ONCE(1); 435 WARN_ON_ONCE(1);
330 else if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags)) { 436 else if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags)) {
@@ -337,6 +443,109 @@ void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b)
337EXPORT_SYMBOL(blk_queue_stack_limits); 443EXPORT_SYMBOL(blk_queue_stack_limits);
338 444
339/** 445/**
446 * blk_stack_limits - adjust queue_limits for stacked devices
447 * @t: the stacking driver limits (top)
448 * @b: the underlying queue limits (bottom)
449 * @offset: offset to beginning of data within component device
450 *
451 * Description:
452 * Merges two queue_limit structs. Returns 0 if alignment didn't
453 * change. Returns -1 if adding the bottom device caused
454 * misalignment.
455 */
456int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
457 sector_t offset)
458{
459 t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors);
460 t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors);
461 t->bounce_pfn = min_not_zero(t->bounce_pfn, b->bounce_pfn);
462
463 t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask,
464 b->seg_boundary_mask);
465
466 t->max_phys_segments = min_not_zero(t->max_phys_segments,
467 b->max_phys_segments);
468
469 t->max_hw_segments = min_not_zero(t->max_hw_segments,
470 b->max_hw_segments);
471
472 t->max_segment_size = min_not_zero(t->max_segment_size,
473 b->max_segment_size);
474
475 t->logical_block_size = max(t->logical_block_size,
476 b->logical_block_size);
477
478 t->physical_block_size = max(t->physical_block_size,
479 b->physical_block_size);
480
481 t->io_min = max(t->io_min, b->io_min);
482 t->no_cluster |= b->no_cluster;
483
484 /* Bottom device offset aligned? */
485 if (offset &&
486 (offset & (b->physical_block_size - 1)) != b->alignment_offset) {
487 t->misaligned = 1;
488 return -1;
489 }
490
491 /* If top has no alignment offset, inherit from bottom */
492 if (!t->alignment_offset)
493 t->alignment_offset =
494 b->alignment_offset & (b->physical_block_size - 1);
495
496 /* Top device aligned on logical block boundary? */
497 if (t->alignment_offset & (t->logical_block_size - 1)) {
498 t->misaligned = 1;
499 return -1;
500 }
501
502 return 0;
503}
504EXPORT_SYMBOL(blk_stack_limits);
505
506/**
507 * disk_stack_limits - adjust queue limits for stacked drivers
508 * @disk: MD/DM gendisk (top)
509 * @bdev: the underlying block device (bottom)
510 * @offset: offset to beginning of data within component device
511 *
512 * Description:
513 * Merges the limits for two queues. Returns 0 if alignment
514 * didn't change. Returns -1 if adding the bottom device caused
515 * misalignment.
516 */
517void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
518 sector_t offset)
519{
520 struct request_queue *t = disk->queue;
521 struct request_queue *b = bdev_get_queue(bdev);
522
523 offset += get_start_sect(bdev) << 9;
524
525 if (blk_stack_limits(&t->limits, &b->limits, offset) < 0) {
526 char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE];
527
528 disk_name(disk, 0, top);
529 bdevname(bdev, bottom);
530
531 printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n",
532 top, bottom);
533 }
534
535 if (!t->queue_lock)
536 WARN_ON_ONCE(1);
537 else if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags)) {
538 unsigned long flags;
539
540 spin_lock_irqsave(t->queue_lock, flags);
541 if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags))
542 queue_flag_clear(QUEUE_FLAG_CLUSTER, t);
543 spin_unlock_irqrestore(t->queue_lock, flags);
544 }
545}
546EXPORT_SYMBOL(disk_stack_limits);
547
548/**
340 * blk_queue_dma_pad - set pad mask 549 * blk_queue_dma_pad - set pad mask
341 * @q: the request queue for the device 550 * @q: the request queue for the device
342 * @mask: pad mask 551 * @mask: pad mask
@@ -396,11 +605,11 @@ int blk_queue_dma_drain(struct request_queue *q,
396 dma_drain_needed_fn *dma_drain_needed, 605 dma_drain_needed_fn *dma_drain_needed,
397 void *buf, unsigned int size) 606 void *buf, unsigned int size)
398{ 607{
399 if (q->max_hw_segments < 2 || q->max_phys_segments < 2) 608 if (queue_max_hw_segments(q) < 2 || queue_max_phys_segments(q) < 2)
400 return -EINVAL; 609 return -EINVAL;
401 /* make room for appending the drain */ 610 /* make room for appending the drain */
402 --q->max_hw_segments; 611 blk_queue_max_hw_segments(q, queue_max_hw_segments(q) - 1);
403 --q->max_phys_segments; 612 blk_queue_max_phys_segments(q, queue_max_phys_segments(q) - 1);
404 q->dma_drain_needed = dma_drain_needed; 613 q->dma_drain_needed = dma_drain_needed;
405 q->dma_drain_buffer = buf; 614 q->dma_drain_buffer = buf;
406 q->dma_drain_size = size; 615 q->dma_drain_size = size;
@@ -422,7 +631,7 @@ void blk_queue_segment_boundary(struct request_queue *q, unsigned long mask)
422 __func__, mask); 631 __func__, mask);
423 } 632 }
424 633
425 q->seg_boundary_mask = mask; 634 q->limits.seg_boundary_mask = mask;
426} 635}
427EXPORT_SYMBOL(blk_queue_segment_boundary); 636EXPORT_SYMBOL(blk_queue_segment_boundary);
428 637
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 26f9ec28f56c..b1cd04087d6a 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -95,21 +95,36 @@ queue_ra_store(struct request_queue *q, const char *page, size_t count)
95 95
96static ssize_t queue_max_sectors_show(struct request_queue *q, char *page) 96static ssize_t queue_max_sectors_show(struct request_queue *q, char *page)
97{ 97{
98 int max_sectors_kb = q->max_sectors >> 1; 98 int max_sectors_kb = queue_max_sectors(q) >> 1;
99 99
100 return queue_var_show(max_sectors_kb, (page)); 100 return queue_var_show(max_sectors_kb, (page));
101} 101}
102 102
103static ssize_t queue_hw_sector_size_show(struct request_queue *q, char *page) 103static ssize_t queue_logical_block_size_show(struct request_queue *q, char *page)
104{ 104{
105 return queue_var_show(q->hardsect_size, page); 105 return queue_var_show(queue_logical_block_size(q), page);
106}
107
108static ssize_t queue_physical_block_size_show(struct request_queue *q, char *page)
109{
110 return queue_var_show(queue_physical_block_size(q), page);
111}
112
113static ssize_t queue_io_min_show(struct request_queue *q, char *page)
114{
115 return queue_var_show(queue_io_min(q), page);
116}
117
118static ssize_t queue_io_opt_show(struct request_queue *q, char *page)
119{
120 return queue_var_show(queue_io_opt(q), page);
106} 121}
107 122
108static ssize_t 123static ssize_t
109queue_max_sectors_store(struct request_queue *q, const char *page, size_t count) 124queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
110{ 125{
111 unsigned long max_sectors_kb, 126 unsigned long max_sectors_kb,
112 max_hw_sectors_kb = q->max_hw_sectors >> 1, 127 max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1,
113 page_kb = 1 << (PAGE_CACHE_SHIFT - 10); 128 page_kb = 1 << (PAGE_CACHE_SHIFT - 10);
114 ssize_t ret = queue_var_store(&max_sectors_kb, page, count); 129 ssize_t ret = queue_var_store(&max_sectors_kb, page, count);
115 130
@@ -117,7 +132,7 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
117 return -EINVAL; 132 return -EINVAL;
118 133
119 spin_lock_irq(q->queue_lock); 134 spin_lock_irq(q->queue_lock);
120 q->max_sectors = max_sectors_kb << 1; 135 blk_queue_max_sectors(q, max_sectors_kb << 1);
121 spin_unlock_irq(q->queue_lock); 136 spin_unlock_irq(q->queue_lock);
122 137
123 return ret; 138 return ret;
@@ -125,7 +140,7 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
125 140
126static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page) 141static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page)
127{ 142{
128 int max_hw_sectors_kb = q->max_hw_sectors >> 1; 143 int max_hw_sectors_kb = queue_max_hw_sectors(q) >> 1;
129 144
130 return queue_var_show(max_hw_sectors_kb, (page)); 145 return queue_var_show(max_hw_sectors_kb, (page));
131} 146}
@@ -249,7 +264,27 @@ static struct queue_sysfs_entry queue_iosched_entry = {
249 264
250static struct queue_sysfs_entry queue_hw_sector_size_entry = { 265static struct queue_sysfs_entry queue_hw_sector_size_entry = {
251 .attr = {.name = "hw_sector_size", .mode = S_IRUGO }, 266 .attr = {.name = "hw_sector_size", .mode = S_IRUGO },
252 .show = queue_hw_sector_size_show, 267 .show = queue_logical_block_size_show,
268};
269
270static struct queue_sysfs_entry queue_logical_block_size_entry = {
271 .attr = {.name = "logical_block_size", .mode = S_IRUGO },
272 .show = queue_logical_block_size_show,
273};
274
275static struct queue_sysfs_entry queue_physical_block_size_entry = {
276 .attr = {.name = "physical_block_size", .mode = S_IRUGO },
277 .show = queue_physical_block_size_show,
278};
279
280static struct queue_sysfs_entry queue_io_min_entry = {
281 .attr = {.name = "minimum_io_size", .mode = S_IRUGO },
282 .show = queue_io_min_show,
283};
284
285static struct queue_sysfs_entry queue_io_opt_entry = {
286 .attr = {.name = "optimal_io_size", .mode = S_IRUGO },
287 .show = queue_io_opt_show,
253}; 288};
254 289
255static struct queue_sysfs_entry queue_nonrot_entry = { 290static struct queue_sysfs_entry queue_nonrot_entry = {
@@ -283,6 +318,10 @@ static struct attribute *default_attrs[] = {
283 &queue_max_sectors_entry.attr, 318 &queue_max_sectors_entry.attr,
284 &queue_iosched_entry.attr, 319 &queue_iosched_entry.attr,
285 &queue_hw_sector_size_entry.attr, 320 &queue_hw_sector_size_entry.attr,
321 &queue_logical_block_size_entry.attr,
322 &queue_physical_block_size_entry.attr,
323 &queue_io_min_entry.attr,
324 &queue_io_opt_entry.attr,
286 &queue_nonrot_entry.attr, 325 &queue_nonrot_entry.attr,
287 &queue_nomerges_entry.attr, 326 &queue_nomerges_entry.attr,
288 &queue_rq_affinity_entry.attr, 327 &queue_rq_affinity_entry.attr,
@@ -394,16 +433,15 @@ int blk_register_queue(struct gendisk *disk)
394 if (ret) 433 if (ret)
395 return ret; 434 return ret;
396 435
397 if (!q->request_fn) 436 ret = kobject_add(&q->kobj, kobject_get(&dev->kobj), "%s", "queue");
398 return 0;
399
400 ret = kobject_add(&q->kobj, kobject_get(&dev->kobj),
401 "%s", "queue");
402 if (ret < 0) 437 if (ret < 0)
403 return ret; 438 return ret;
404 439
405 kobject_uevent(&q->kobj, KOBJ_ADD); 440 kobject_uevent(&q->kobj, KOBJ_ADD);
406 441
442 if (!q->request_fn)
443 return 0;
444
407 ret = elv_register_queue(q); 445 ret = elv_register_queue(q);
408 if (ret) { 446 if (ret) {
409 kobject_uevent(&q->kobj, KOBJ_REMOVE); 447 kobject_uevent(&q->kobj, KOBJ_REMOVE);
diff --git a/block/blk-tag.c b/block/blk-tag.c
index 3c518e3303ae..2e5cfeb59333 100644
--- a/block/blk-tag.c
+++ b/block/blk-tag.c
@@ -336,7 +336,7 @@ EXPORT_SYMBOL(blk_queue_end_tag);
336int blk_queue_start_tag(struct request_queue *q, struct request *rq) 336int blk_queue_start_tag(struct request_queue *q, struct request *rq)
337{ 337{
338 struct blk_queue_tag *bqt = q->queue_tags; 338 struct blk_queue_tag *bqt = q->queue_tags;
339 unsigned max_depth, offset; 339 unsigned max_depth;
340 int tag; 340 int tag;
341 341
342 if (unlikely((rq->cmd_flags & REQ_QUEUED))) { 342 if (unlikely((rq->cmd_flags & REQ_QUEUED))) {
@@ -355,13 +355,16 @@ int blk_queue_start_tag(struct request_queue *q, struct request *rq)
355 * to starve sync IO on behalf of flooding async IO. 355 * to starve sync IO on behalf of flooding async IO.
356 */ 356 */
357 max_depth = bqt->max_depth; 357 max_depth = bqt->max_depth;
358 if (rq_is_sync(rq)) 358 if (!rq_is_sync(rq) && max_depth > 1) {
359 offset = 0; 359 max_depth -= 2;
360 else 360 if (!max_depth)
361 offset = max_depth >> 2; 361 max_depth = 1;
362 if (q->in_flight[0] > max_depth)
363 return 1;
364 }
362 365
363 do { 366 do {
364 tag = find_next_zero_bit(bqt->tag_map, max_depth, offset); 367 tag = find_first_zero_bit(bqt->tag_map, max_depth);
365 if (tag >= max_depth) 368 if (tag >= max_depth)
366 return 1; 369 return 1;
367 370
@@ -374,7 +377,7 @@ int blk_queue_start_tag(struct request_queue *q, struct request *rq)
374 rq->cmd_flags |= REQ_QUEUED; 377 rq->cmd_flags |= REQ_QUEUED;
375 rq->tag = tag; 378 rq->tag = tag;
376 bqt->tag_index[tag] = rq; 379 bqt->tag_index[tag] = rq;
377 blkdev_dequeue_request(rq); 380 blk_start_request(rq);
378 list_add(&rq->queuelist, &q->tag_busy_list); 381 list_add(&rq->queuelist, &q->tag_busy_list);
379 return 0; 382 return 0;
380} 383}
diff --git a/block/blk-timeout.c b/block/blk-timeout.c
index 1ec0d503cacd..1ba7e0aca878 100644
--- a/block/blk-timeout.c
+++ b/block/blk-timeout.c
@@ -122,10 +122,8 @@ void blk_rq_timed_out_timer(unsigned long data)
122 if (blk_mark_rq_complete(rq)) 122 if (blk_mark_rq_complete(rq))
123 continue; 123 continue;
124 blk_rq_timed_out(rq); 124 blk_rq_timed_out(rq);
125 } else { 125 } else if (!next || time_after(next, rq->deadline))
126 if (!next || time_after(next, rq->deadline)) 126 next = rq->deadline;
127 next = rq->deadline;
128 }
129 } 127 }
130 128
131 /* 129 /*
@@ -176,16 +174,14 @@ void blk_add_timer(struct request *req)
176 BUG_ON(!list_empty(&req->timeout_list)); 174 BUG_ON(!list_empty(&req->timeout_list));
177 BUG_ON(test_bit(REQ_ATOM_COMPLETE, &req->atomic_flags)); 175 BUG_ON(test_bit(REQ_ATOM_COMPLETE, &req->atomic_flags));
178 176
179 if (req->timeout) 177 /*
180 req->deadline = jiffies + req->timeout; 178 * Some LLDs, like scsi, peek at the timeout to prevent a
181 else { 179 * command from being retried forever.
182 req->deadline = jiffies + q->rq_timeout; 180 */
183 /* 181 if (!req->timeout)
184 * Some LLDs, like scsi, peek at the timeout to prevent
185 * a command from being retried forever.
186 */
187 req->timeout = q->rq_timeout; 182 req->timeout = q->rq_timeout;
188 } 183
184 req->deadline = jiffies + req->timeout;
189 list_add_tail(&req->timeout_list, &q->timeout_list); 185 list_add_tail(&req->timeout_list, &q->timeout_list);
190 186
191 /* 187 /*
diff --git a/block/blk.h b/block/blk.h
index 79c85f7c9ff5..3fae6add5430 100644
--- a/block/blk.h
+++ b/block/blk.h
@@ -13,6 +13,9 @@ extern struct kobj_type blk_queue_ktype;
13void init_request_from_bio(struct request *req, struct bio *bio); 13void init_request_from_bio(struct request *req, struct bio *bio);
14void blk_rq_bio_prep(struct request_queue *q, struct request *rq, 14void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
15 struct bio *bio); 15 struct bio *bio);
16int blk_rq_append_bio(struct request_queue *q, struct request *rq,
17 struct bio *bio);
18void blk_dequeue_request(struct request *rq);
16void __blk_queue_free_tags(struct request_queue *q); 19void __blk_queue_free_tags(struct request_queue *q);
17 20
18void blk_unplug_work(struct work_struct *work); 21void blk_unplug_work(struct work_struct *work);
@@ -43,6 +46,43 @@ static inline void blk_clear_rq_complete(struct request *rq)
43 clear_bit(REQ_ATOM_COMPLETE, &rq->atomic_flags); 46 clear_bit(REQ_ATOM_COMPLETE, &rq->atomic_flags);
44} 47}
45 48
49/*
50 * Internal elevator interface
51 */
52#define ELV_ON_HASH(rq) (!hlist_unhashed(&(rq)->hash))
53
54static inline struct request *__elv_next_request(struct request_queue *q)
55{
56 struct request *rq;
57
58 while (1) {
59 while (!list_empty(&q->queue_head)) {
60 rq = list_entry_rq(q->queue_head.next);
61 if (blk_do_ordered(q, &rq))
62 return rq;
63 }
64
65 if (!q->elevator->ops->elevator_dispatch_fn(q, 0))
66 return NULL;
67 }
68}
69
70static inline void elv_activate_rq(struct request_queue *q, struct request *rq)
71{
72 struct elevator_queue *e = q->elevator;
73
74 if (e->ops->elevator_activate_req_fn)
75 e->ops->elevator_activate_req_fn(q, rq);
76}
77
78static inline void elv_deactivate_rq(struct request_queue *q, struct request *rq)
79{
80 struct elevator_queue *e = q->elevator;
81
82 if (e->ops->elevator_deactivate_req_fn)
83 e->ops->elevator_deactivate_req_fn(q, rq);
84}
85
46#ifdef CONFIG_FAIL_IO_TIMEOUT 86#ifdef CONFIG_FAIL_IO_TIMEOUT
47int blk_should_fake_timeout(struct request_queue *); 87int blk_should_fake_timeout(struct request_queue *);
48ssize_t part_timeout_show(struct device *, struct device_attribute *, char *); 88ssize_t part_timeout_show(struct device *, struct device_attribute *, char *);
@@ -64,7 +104,6 @@ int ll_front_merge_fn(struct request_queue *q, struct request *req,
64int attempt_back_merge(struct request_queue *q, struct request *rq); 104int attempt_back_merge(struct request_queue *q, struct request *rq);
65int attempt_front_merge(struct request_queue *q, struct request *rq); 105int attempt_front_merge(struct request_queue *q, struct request *rq);
66void blk_recalc_rq_segments(struct request *rq); 106void blk_recalc_rq_segments(struct request *rq);
67void blk_recalc_rq_sectors(struct request *rq, int nsect);
68 107
69void blk_queue_congestion_threshold(struct request_queue *q); 108void blk_queue_congestion_threshold(struct request_queue *q);
70 109
@@ -112,9 +151,17 @@ static inline int blk_cpu_to_group(int cpu)
112#endif 151#endif
113} 152}
114 153
154/*
155 * Contribute to IO statistics IFF:
156 *
157 * a) it's attached to a gendisk, and
158 * b) the queue had IO stats enabled when this request was started, and
159 * c) it's a file system request or a discard request
160 */
115static inline int blk_do_io_stat(struct request *rq) 161static inline int blk_do_io_stat(struct request *rq)
116{ 162{
117 return rq->rq_disk && blk_rq_io_stat(rq); 163 return rq->rq_disk && blk_rq_io_stat(rq) &&
164 (blk_fs_request(rq) || blk_discard_rq(rq));
118} 165}
119 166
120#endif 167#endif
diff --git a/block/bsg.c b/block/bsg.c
index dd81be455e00..5358f9ae13c1 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -446,15 +446,15 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
446 } 446 }
447 447
448 if (rq->next_rq) { 448 if (rq->next_rq) {
449 hdr->dout_resid = rq->data_len; 449 hdr->dout_resid = rq->resid_len;
450 hdr->din_resid = rq->next_rq->data_len; 450 hdr->din_resid = rq->next_rq->resid_len;
451 blk_rq_unmap_user(bidi_bio); 451 blk_rq_unmap_user(bidi_bio);
452 rq->next_rq->bio = NULL; 452 rq->next_rq->bio = NULL;
453 blk_put_request(rq->next_rq); 453 blk_put_request(rq->next_rq);
454 } else if (rq_data_dir(rq) == READ) 454 } else if (rq_data_dir(rq) == READ)
455 hdr->din_resid = rq->data_len; 455 hdr->din_resid = rq->resid_len;
456 else 456 else
457 hdr->dout_resid = rq->data_len; 457 hdr->dout_resid = rq->resid_len;
458 458
459 /* 459 /*
460 * If the request generated a negative error number, return it 460 * If the request generated a negative error number, return it
diff --git a/block/cfq-iosched.c b/block/cfq-iosched.c
index a55a9bd75bd1..ef2f72d42434 100644
--- a/block/cfq-iosched.c
+++ b/block/cfq-iosched.c
@@ -349,8 +349,8 @@ cfq_choose_req(struct cfq_data *cfqd, struct request *rq1, struct request *rq2)
349 else if (rq_is_meta(rq2) && !rq_is_meta(rq1)) 349 else if (rq_is_meta(rq2) && !rq_is_meta(rq1))
350 return rq2; 350 return rq2;
351 351
352 s1 = rq1->sector; 352 s1 = blk_rq_pos(rq1);
353 s2 = rq2->sector; 353 s2 = blk_rq_pos(rq2);
354 354
355 last = cfqd->last_position; 355 last = cfqd->last_position;
356 356
@@ -579,9 +579,9 @@ cfq_prio_tree_lookup(struct cfq_data *cfqd, struct rb_root *root,
579 * Sort strictly based on sector. Smallest to the left, 579 * Sort strictly based on sector. Smallest to the left,
580 * largest to the right. 580 * largest to the right.
581 */ 581 */
582 if (sector > cfqq->next_rq->sector) 582 if (sector > blk_rq_pos(cfqq->next_rq))
583 n = &(*p)->rb_right; 583 n = &(*p)->rb_right;
584 else if (sector < cfqq->next_rq->sector) 584 else if (sector < blk_rq_pos(cfqq->next_rq))
585 n = &(*p)->rb_left; 585 n = &(*p)->rb_left;
586 else 586 else
587 break; 587 break;
@@ -611,8 +611,8 @@ static void cfq_prio_tree_add(struct cfq_data *cfqd, struct cfq_queue *cfqq)
611 return; 611 return;
612 612
613 cfqq->p_root = &cfqd->prio_trees[cfqq->org_ioprio]; 613 cfqq->p_root = &cfqd->prio_trees[cfqq->org_ioprio];
614 __cfqq = cfq_prio_tree_lookup(cfqd, cfqq->p_root, cfqq->next_rq->sector, 614 __cfqq = cfq_prio_tree_lookup(cfqd, cfqq->p_root,
615 &parent, &p); 615 blk_rq_pos(cfqq->next_rq), &parent, &p);
616 if (!__cfqq) { 616 if (!__cfqq) {
617 rb_link_node(&cfqq->p_node, parent, p); 617 rb_link_node(&cfqq->p_node, parent, p);
618 rb_insert_color(&cfqq->p_node, cfqq->p_root); 618 rb_insert_color(&cfqq->p_node, cfqq->p_root);
@@ -760,7 +760,7 @@ static void cfq_activate_request(struct request_queue *q, struct request *rq)
760 cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "activate rq, drv=%d", 760 cfq_log_cfqq(cfqd, RQ_CFQQ(rq), "activate rq, drv=%d",
761 cfqd->rq_in_driver); 761 cfqd->rq_in_driver);
762 762
763 cfqd->last_position = rq->hard_sector + rq->hard_nr_sectors; 763 cfqd->last_position = blk_rq_pos(rq) + blk_rq_sectors(rq);
764} 764}
765 765
766static void cfq_deactivate_request(struct request_queue *q, struct request *rq) 766static void cfq_deactivate_request(struct request_queue *q, struct request *rq)
@@ -949,10 +949,10 @@ static struct cfq_queue *cfq_set_active_queue(struct cfq_data *cfqd,
949static inline sector_t cfq_dist_from_last(struct cfq_data *cfqd, 949static inline sector_t cfq_dist_from_last(struct cfq_data *cfqd,
950 struct request *rq) 950 struct request *rq)
951{ 951{
952 if (rq->sector >= cfqd->last_position) 952 if (blk_rq_pos(rq) >= cfqd->last_position)
953 return rq->sector - cfqd->last_position; 953 return blk_rq_pos(rq) - cfqd->last_position;
954 else 954 else
955 return cfqd->last_position - rq->sector; 955 return cfqd->last_position - blk_rq_pos(rq);
956} 956}
957 957
958#define CIC_SEEK_THR 8 * 1024 958#define CIC_SEEK_THR 8 * 1024
@@ -996,7 +996,7 @@ static struct cfq_queue *cfqq_close(struct cfq_data *cfqd,
996 if (cfq_rq_close(cfqd, __cfqq->next_rq)) 996 if (cfq_rq_close(cfqd, __cfqq->next_rq))
997 return __cfqq; 997 return __cfqq;
998 998
999 if (__cfqq->next_rq->sector < sector) 999 if (blk_rq_pos(__cfqq->next_rq) < sector)
1000 node = rb_next(&__cfqq->p_node); 1000 node = rb_next(&__cfqq->p_node);
1001 else 1001 else
1002 node = rb_prev(&__cfqq->p_node); 1002 node = rb_prev(&__cfqq->p_node);
@@ -1282,7 +1282,7 @@ static void cfq_dispatch_request(struct cfq_data *cfqd, struct cfq_queue *cfqq)
1282 if (!cfqd->active_cic) { 1282 if (!cfqd->active_cic) {
1283 struct cfq_io_context *cic = RQ_CIC(rq); 1283 struct cfq_io_context *cic = RQ_CIC(rq);
1284 1284
1285 atomic_inc(&cic->ioc->refcount); 1285 atomic_long_inc(&cic->ioc->refcount);
1286 cfqd->active_cic = cic; 1286 cfqd->active_cic = cic;
1287 } 1287 }
1288} 1288}
@@ -1918,10 +1918,10 @@ cfq_update_io_seektime(struct cfq_data *cfqd, struct cfq_io_context *cic,
1918 1918
1919 if (!cic->last_request_pos) 1919 if (!cic->last_request_pos)
1920 sdist = 0; 1920 sdist = 0;
1921 else if (cic->last_request_pos < rq->sector) 1921 else if (cic->last_request_pos < blk_rq_pos(rq))
1922 sdist = rq->sector - cic->last_request_pos; 1922 sdist = blk_rq_pos(rq) - cic->last_request_pos;
1923 else 1923 else
1924 sdist = cic->last_request_pos - rq->sector; 1924 sdist = cic->last_request_pos - blk_rq_pos(rq);
1925 1925
1926 /* 1926 /*
1927 * Don't allow the seek distance to get too large from the 1927 * Don't allow the seek distance to get too large from the
@@ -2071,7 +2071,7 @@ cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
2071 cfq_update_io_seektime(cfqd, cic, rq); 2071 cfq_update_io_seektime(cfqd, cic, rq);
2072 cfq_update_idle_window(cfqd, cfqq, cic); 2072 cfq_update_idle_window(cfqd, cfqq, cic);
2073 2073
2074 cic->last_request_pos = rq->sector + rq->nr_sectors; 2074 cic->last_request_pos = blk_rq_pos(rq) + blk_rq_sectors(rq);
2075 2075
2076 if (cfqq == cfqd->active_queue) { 2076 if (cfqq == cfqd->active_queue) {
2077 /* 2077 /*
@@ -2088,7 +2088,7 @@ cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
2088 if (blk_rq_bytes(rq) > PAGE_CACHE_SIZE || 2088 if (blk_rq_bytes(rq) > PAGE_CACHE_SIZE ||
2089 cfqd->busy_queues > 1) { 2089 cfqd->busy_queues > 1) {
2090 del_timer(&cfqd->idle_slice_timer); 2090 del_timer(&cfqd->idle_slice_timer);
2091 blk_start_queueing(cfqd->queue); 2091 __blk_run_queue(cfqd->queue);
2092 } 2092 }
2093 cfq_mark_cfqq_must_dispatch(cfqq); 2093 cfq_mark_cfqq_must_dispatch(cfqq);
2094 } 2094 }
@@ -2100,7 +2100,7 @@ cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
2100 * this new queue is RT and the current one is BE 2100 * this new queue is RT and the current one is BE
2101 */ 2101 */
2102 cfq_preempt_queue(cfqd, cfqq); 2102 cfq_preempt_queue(cfqd, cfqq);
2103 blk_start_queueing(cfqd->queue); 2103 __blk_run_queue(cfqd->queue);
2104 } 2104 }
2105} 2105}
2106 2106
@@ -2345,7 +2345,7 @@ static void cfq_kick_queue(struct work_struct *work)
2345 struct request_queue *q = cfqd->queue; 2345 struct request_queue *q = cfqd->queue;
2346 2346
2347 spin_lock_irq(q->queue_lock); 2347 spin_lock_irq(q->queue_lock);
2348 blk_start_queueing(q); 2348 __blk_run_queue(cfqd->queue);
2349 spin_unlock_irq(q->queue_lock); 2349 spin_unlock_irq(q->queue_lock);
2350} 2350}
2351 2351
diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
index f8c218cd08e1..7865a34e0faa 100644
--- a/block/compat_ioctl.c
+++ b/block/compat_ioctl.c
@@ -763,10 +763,10 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
763 case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ 763 case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */
764 return compat_put_int(arg, block_size(bdev)); 764 return compat_put_int(arg, block_size(bdev));
765 case BLKSSZGET: /* get block device hardware sector size */ 765 case BLKSSZGET: /* get block device hardware sector size */
766 return compat_put_int(arg, bdev_hardsect_size(bdev)); 766 return compat_put_int(arg, bdev_logical_block_size(bdev));
767 case BLKSECTGET: 767 case BLKSECTGET:
768 return compat_put_ushort(arg, 768 return compat_put_ushort(arg,
769 bdev_get_queue(bdev)->max_sectors); 769 queue_max_sectors(bdev_get_queue(bdev)));
770 case BLKRASET: /* compatible, but no compat_ptr (!) */ 770 case BLKRASET: /* compatible, but no compat_ptr (!) */
771 case BLKFRASET: 771 case BLKFRASET:
772 if (!capable(CAP_SYS_ADMIN)) 772 if (!capable(CAP_SYS_ADMIN))
diff --git a/block/deadline-iosched.c b/block/deadline-iosched.c
index c4d991d4adef..b547cbca7b23 100644
--- a/block/deadline-iosched.c
+++ b/block/deadline-iosched.c
@@ -138,7 +138,7 @@ deadline_merge(struct request_queue *q, struct request **req, struct bio *bio)
138 138
139 __rq = elv_rb_find(&dd->sort_list[bio_data_dir(bio)], sector); 139 __rq = elv_rb_find(&dd->sort_list[bio_data_dir(bio)], sector);
140 if (__rq) { 140 if (__rq) {
141 BUG_ON(sector != __rq->sector); 141 BUG_ON(sector != blk_rq_pos(__rq));
142 142
143 if (elv_rq_merge_ok(__rq, bio)) { 143 if (elv_rq_merge_ok(__rq, bio)) {
144 ret = ELEVATOR_FRONT_MERGE; 144 ret = ELEVATOR_FRONT_MERGE;
diff --git a/block/elevator.c b/block/elevator.c
index e220f0c543e3..ca861927ba41 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -51,8 +51,7 @@ static const int elv_hash_shift = 6;
51#define ELV_HASH_FN(sec) \ 51#define ELV_HASH_FN(sec) \
52 (hash_long(ELV_HASH_BLOCK((sec)), elv_hash_shift)) 52 (hash_long(ELV_HASH_BLOCK((sec)), elv_hash_shift))
53#define ELV_HASH_ENTRIES (1 << elv_hash_shift) 53#define ELV_HASH_ENTRIES (1 << elv_hash_shift)
54#define rq_hash_key(rq) ((rq)->sector + (rq)->nr_sectors) 54#define rq_hash_key(rq) (blk_rq_pos(rq) + blk_rq_sectors(rq))
55#define ELV_ON_HASH(rq) (!hlist_unhashed(&(rq)->hash))
56 55
57/* 56/*
58 * Query io scheduler to see if the current process issuing bio may be 57 * Query io scheduler to see if the current process issuing bio may be
@@ -116,9 +115,9 @@ static inline int elv_try_merge(struct request *__rq, struct bio *bio)
116 * we can merge and sequence is ok, check if it's possible 115 * we can merge and sequence is ok, check if it's possible
117 */ 116 */
118 if (elv_rq_merge_ok(__rq, bio)) { 117 if (elv_rq_merge_ok(__rq, bio)) {
119 if (__rq->sector + __rq->nr_sectors == bio->bi_sector) 118 if (blk_rq_pos(__rq) + blk_rq_sectors(__rq) == bio->bi_sector)
120 ret = ELEVATOR_BACK_MERGE; 119 ret = ELEVATOR_BACK_MERGE;
121 else if (__rq->sector - bio_sectors(bio) == bio->bi_sector) 120 else if (blk_rq_pos(__rq) - bio_sectors(bio) == bio->bi_sector)
122 ret = ELEVATOR_FRONT_MERGE; 121 ret = ELEVATOR_FRONT_MERGE;
123 } 122 }
124 123
@@ -306,22 +305,6 @@ void elevator_exit(struct elevator_queue *e)
306} 305}
307EXPORT_SYMBOL(elevator_exit); 306EXPORT_SYMBOL(elevator_exit);
308 307
309static void elv_activate_rq(struct request_queue *q, struct request *rq)
310{
311 struct elevator_queue *e = q->elevator;
312
313 if (e->ops->elevator_activate_req_fn)
314 e->ops->elevator_activate_req_fn(q, rq);
315}
316
317static void elv_deactivate_rq(struct request_queue *q, struct request *rq)
318{
319 struct elevator_queue *e = q->elevator;
320
321 if (e->ops->elevator_deactivate_req_fn)
322 e->ops->elevator_deactivate_req_fn(q, rq);
323}
324
325static inline void __elv_rqhash_del(struct request *rq) 308static inline void __elv_rqhash_del(struct request *rq)
326{ 309{
327 hlist_del_init(&rq->hash); 310 hlist_del_init(&rq->hash);
@@ -383,9 +366,9 @@ struct request *elv_rb_add(struct rb_root *root, struct request *rq)
383 parent = *p; 366 parent = *p;
384 __rq = rb_entry(parent, struct request, rb_node); 367 __rq = rb_entry(parent, struct request, rb_node);
385 368
386 if (rq->sector < __rq->sector) 369 if (blk_rq_pos(rq) < blk_rq_pos(__rq))
387 p = &(*p)->rb_left; 370 p = &(*p)->rb_left;
388 else if (rq->sector > __rq->sector) 371 else if (blk_rq_pos(rq) > blk_rq_pos(__rq))
389 p = &(*p)->rb_right; 372 p = &(*p)->rb_right;
390 else 373 else
391 return __rq; 374 return __rq;
@@ -413,9 +396,9 @@ struct request *elv_rb_find(struct rb_root *root, sector_t sector)
413 while (n) { 396 while (n) {
414 rq = rb_entry(n, struct request, rb_node); 397 rq = rb_entry(n, struct request, rb_node);
415 398
416 if (sector < rq->sector) 399 if (sector < blk_rq_pos(rq))
417 n = n->rb_left; 400 n = n->rb_left;
418 else if (sector > rq->sector) 401 else if (sector > blk_rq_pos(rq))
419 n = n->rb_right; 402 n = n->rb_right;
420 else 403 else
421 return rq; 404 return rq;
@@ -454,14 +437,14 @@ void elv_dispatch_sort(struct request_queue *q, struct request *rq)
454 break; 437 break;
455 if (pos->cmd_flags & stop_flags) 438 if (pos->cmd_flags & stop_flags)
456 break; 439 break;
457 if (rq->sector >= boundary) { 440 if (blk_rq_pos(rq) >= boundary) {
458 if (pos->sector < boundary) 441 if (blk_rq_pos(pos) < boundary)
459 continue; 442 continue;
460 } else { 443 } else {
461 if (pos->sector >= boundary) 444 if (blk_rq_pos(pos) >= boundary)
462 break; 445 break;
463 } 446 }
464 if (rq->sector >= pos->sector) 447 if (blk_rq_pos(rq) >= blk_rq_pos(pos))
465 break; 448 break;
466 } 449 }
467 450
@@ -559,7 +542,7 @@ void elv_requeue_request(struct request_queue *q, struct request *rq)
559 * in_flight count again 542 * in_flight count again
560 */ 543 */
561 if (blk_account_rq(rq)) { 544 if (blk_account_rq(rq)) {
562 q->in_flight--; 545 q->in_flight[rq_is_sync(rq)]--;
563 if (blk_sorted_rq(rq)) 546 if (blk_sorted_rq(rq))
564 elv_deactivate_rq(q, rq); 547 elv_deactivate_rq(q, rq);
565 } 548 }
@@ -588,6 +571,9 @@ void elv_drain_elevator(struct request_queue *q)
588 */ 571 */
589void elv_quiesce_start(struct request_queue *q) 572void elv_quiesce_start(struct request_queue *q)
590{ 573{
574 if (!q->elevator)
575 return;
576
591 queue_flag_set(QUEUE_FLAG_ELVSWITCH, q); 577 queue_flag_set(QUEUE_FLAG_ELVSWITCH, q);
592 578
593 /* 579 /*
@@ -595,7 +581,7 @@ void elv_quiesce_start(struct request_queue *q)
595 */ 581 */
596 elv_drain_elevator(q); 582 elv_drain_elevator(q);
597 while (q->rq.elvpriv) { 583 while (q->rq.elvpriv) {
598 blk_start_queueing(q); 584 __blk_run_queue(q);
599 spin_unlock_irq(q->queue_lock); 585 spin_unlock_irq(q->queue_lock);
600 msleep(10); 586 msleep(10);
601 spin_lock_irq(q->queue_lock); 587 spin_lock_irq(q->queue_lock);
@@ -639,8 +625,7 @@ void elv_insert(struct request_queue *q, struct request *rq, int where)
639 * with anything. There's no point in delaying queue 625 * with anything. There's no point in delaying queue
640 * processing. 626 * processing.
641 */ 627 */
642 blk_remove_plug(q); 628 __blk_run_queue(q);
643 blk_start_queueing(q);
644 break; 629 break;
645 630
646 case ELEVATOR_INSERT_SORT: 631 case ELEVATOR_INSERT_SORT:
@@ -699,7 +684,7 @@ void elv_insert(struct request_queue *q, struct request *rq, int where)
699 684
700 if (unplug_it && blk_queue_plugged(q)) { 685 if (unplug_it && blk_queue_plugged(q)) {
701 int nrq = q->rq.count[BLK_RW_SYNC] + q->rq.count[BLK_RW_ASYNC] 686 int nrq = q->rq.count[BLK_RW_SYNC] + q->rq.count[BLK_RW_ASYNC]
702 - q->in_flight; 687 - queue_in_flight(q);
703 688
704 if (nrq >= q->unplug_thresh) 689 if (nrq >= q->unplug_thresh)
705 __generic_unplug_device(q); 690 __generic_unplug_device(q);
@@ -755,117 +740,6 @@ void elv_add_request(struct request_queue *q, struct request *rq, int where,
755} 740}
756EXPORT_SYMBOL(elv_add_request); 741EXPORT_SYMBOL(elv_add_request);
757 742
758static inline struct request *__elv_next_request(struct request_queue *q)
759{
760 struct request *rq;
761
762 while (1) {
763 while (!list_empty(&q->queue_head)) {
764 rq = list_entry_rq(q->queue_head.next);
765 if (blk_do_ordered(q, &rq))
766 return rq;
767 }
768
769 if (!q->elevator->ops->elevator_dispatch_fn(q, 0))
770 return NULL;
771 }
772}
773
774struct request *elv_next_request(struct request_queue *q)
775{
776 struct request *rq;
777 int ret;
778
779 while ((rq = __elv_next_request(q)) != NULL) {
780 if (!(rq->cmd_flags & REQ_STARTED)) {
781 /*
782 * This is the first time the device driver
783 * sees this request (possibly after
784 * requeueing). Notify IO scheduler.
785 */
786 if (blk_sorted_rq(rq))
787 elv_activate_rq(q, rq);
788
789 /*
790 * just mark as started even if we don't start
791 * it, a request that has been delayed should
792 * not be passed by new incoming requests
793 */
794 rq->cmd_flags |= REQ_STARTED;
795 trace_block_rq_issue(q, rq);
796 }
797
798 if (!q->boundary_rq || q->boundary_rq == rq) {
799 q->end_sector = rq_end_sector(rq);
800 q->boundary_rq = NULL;
801 }
802
803 if (rq->cmd_flags & REQ_DONTPREP)
804 break;
805
806 if (q->dma_drain_size && rq->data_len) {
807 /*
808 * make sure space for the drain appears we
809 * know we can do this because max_hw_segments
810 * has been adjusted to be one fewer than the
811 * device can handle
812 */
813 rq->nr_phys_segments++;
814 }
815
816 if (!q->prep_rq_fn)
817 break;
818
819 ret = q->prep_rq_fn(q, rq);
820 if (ret == BLKPREP_OK) {
821 break;
822 } else if (ret == BLKPREP_DEFER) {
823 /*
824 * the request may have been (partially) prepped.
825 * we need to keep this request in the front to
826 * avoid resource deadlock. REQ_STARTED will
827 * prevent other fs requests from passing this one.
828 */
829 if (q->dma_drain_size && rq->data_len &&
830 !(rq->cmd_flags & REQ_DONTPREP)) {
831 /*
832 * remove the space for the drain we added
833 * so that we don't add it again
834 */
835 --rq->nr_phys_segments;
836 }
837
838 rq = NULL;
839 break;
840 } else if (ret == BLKPREP_KILL) {
841 rq->cmd_flags |= REQ_QUIET;
842 __blk_end_request(rq, -EIO, blk_rq_bytes(rq));
843 } else {
844 printk(KERN_ERR "%s: bad return=%d\n", __func__, ret);
845 break;
846 }
847 }
848
849 return rq;
850}
851EXPORT_SYMBOL(elv_next_request);
852
853void elv_dequeue_request(struct request_queue *q, struct request *rq)
854{
855 BUG_ON(list_empty(&rq->queuelist));
856 BUG_ON(ELV_ON_HASH(rq));
857
858 list_del_init(&rq->queuelist);
859
860 /*
861 * the time frame between a request being removed from the lists
862 * and to it is freed is accounted as io that is in progress at
863 * the driver side.
864 */
865 if (blk_account_rq(rq))
866 q->in_flight++;
867}
868
869int elv_queue_empty(struct request_queue *q) 743int elv_queue_empty(struct request_queue *q)
870{ 744{
871 struct elevator_queue *e = q->elevator; 745 struct elevator_queue *e = q->elevator;
@@ -935,7 +809,12 @@ void elv_abort_queue(struct request_queue *q)
935 rq = list_entry_rq(q->queue_head.next); 809 rq = list_entry_rq(q->queue_head.next);
936 rq->cmd_flags |= REQ_QUIET; 810 rq->cmd_flags |= REQ_QUIET;
937 trace_block_rq_abort(q, rq); 811 trace_block_rq_abort(q, rq);
938 __blk_end_request(rq, -EIO, blk_rq_bytes(rq)); 812 /*
813 * Mark this request as started so we don't trigger
814 * any debug logic in the end I/O path.
815 */
816 blk_start_request(rq);
817 __blk_end_request_all(rq, -EIO);
939 } 818 }
940} 819}
941EXPORT_SYMBOL(elv_abort_queue); 820EXPORT_SYMBOL(elv_abort_queue);
@@ -948,7 +827,7 @@ void elv_completed_request(struct request_queue *q, struct request *rq)
948 * request is released from the driver, io must be done 827 * request is released from the driver, io must be done
949 */ 828 */
950 if (blk_account_rq(rq)) { 829 if (blk_account_rq(rq)) {
951 q->in_flight--; 830 q->in_flight[rq_is_sync(rq)]--;
952 if (blk_sorted_rq(rq) && e->ops->elevator_completed_req_fn) 831 if (blk_sorted_rq(rq) && e->ops->elevator_completed_req_fn)
953 e->ops->elevator_completed_req_fn(q, rq); 832 e->ops->elevator_completed_req_fn(q, rq);
954 } 833 }
@@ -963,11 +842,11 @@ void elv_completed_request(struct request_queue *q, struct request *rq)
963 if (!list_empty(&q->queue_head)) 842 if (!list_empty(&q->queue_head))
964 next = list_entry_rq(q->queue_head.next); 843 next = list_entry_rq(q->queue_head.next);
965 844
966 if (!q->in_flight && 845 if (!queue_in_flight(q) &&
967 blk_ordered_cur_seq(q) == QUEUE_ORDSEQ_DRAIN && 846 blk_ordered_cur_seq(q) == QUEUE_ORDSEQ_DRAIN &&
968 (!next || blk_ordered_req_seq(next) > QUEUE_ORDSEQ_DRAIN)) { 847 (!next || blk_ordered_req_seq(next) > QUEUE_ORDSEQ_DRAIN)) {
969 blk_ordered_complete_seq(q, QUEUE_ORDSEQ_DRAIN, 0); 848 blk_ordered_complete_seq(q, QUEUE_ORDSEQ_DRAIN, 0);
970 blk_start_queueing(q); 849 __blk_run_queue(q);
971 } 850 }
972 } 851 }
973} 852}
@@ -1175,6 +1054,9 @@ ssize_t elv_iosched_store(struct request_queue *q, const char *name,
1175 char elevator_name[ELV_NAME_MAX]; 1054 char elevator_name[ELV_NAME_MAX];
1176 struct elevator_type *e; 1055 struct elevator_type *e;
1177 1056
1057 if (!q->elevator)
1058 return count;
1059
1178 strlcpy(elevator_name, name, sizeof(elevator_name)); 1060 strlcpy(elevator_name, name, sizeof(elevator_name));
1179 strstrip(elevator_name); 1061 strstrip(elevator_name);
1180 1062
@@ -1198,10 +1080,15 @@ ssize_t elv_iosched_store(struct request_queue *q, const char *name,
1198ssize_t elv_iosched_show(struct request_queue *q, char *name) 1080ssize_t elv_iosched_show(struct request_queue *q, char *name)
1199{ 1081{
1200 struct elevator_queue *e = q->elevator; 1082 struct elevator_queue *e = q->elevator;
1201 struct elevator_type *elv = e->elevator_type; 1083 struct elevator_type *elv;
1202 struct elevator_type *__e; 1084 struct elevator_type *__e;
1203 int len = 0; 1085 int len = 0;
1204 1086
1087 if (!q->elevator)
1088 return sprintf(name, "none\n");
1089
1090 elv = e->elevator_type;
1091
1205 spin_lock(&elv_list_lock); 1092 spin_lock(&elv_list_lock);
1206 list_for_each_entry(__e, &elv_list, list) { 1093 list_for_each_entry(__e, &elv_list, list) {
1207 if (!strcmp(elv->elevator_name, __e->elevator_name)) 1094 if (!strcmp(elv->elevator_name, __e->elevator_name))
diff --git a/block/genhd.c b/block/genhd.c
index 1a4916e01732..fe7ccc0a618f 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -852,11 +852,21 @@ static ssize_t disk_capability_show(struct device *dev,
852 return sprintf(buf, "%x\n", disk->flags); 852 return sprintf(buf, "%x\n", disk->flags);
853} 853}
854 854
855static ssize_t disk_alignment_offset_show(struct device *dev,
856 struct device_attribute *attr,
857 char *buf)
858{
859 struct gendisk *disk = dev_to_disk(dev);
860
861 return sprintf(buf, "%d\n", queue_alignment_offset(disk->queue));
862}
863
855static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL); 864static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL);
856static DEVICE_ATTR(ext_range, S_IRUGO, disk_ext_range_show, NULL); 865static DEVICE_ATTR(ext_range, S_IRUGO, disk_ext_range_show, NULL);
857static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL); 866static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL);
858static DEVICE_ATTR(ro, S_IRUGO, disk_ro_show, NULL); 867static DEVICE_ATTR(ro, S_IRUGO, disk_ro_show, NULL);
859static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL); 868static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL);
869static DEVICE_ATTR(alignment_offset, S_IRUGO, disk_alignment_offset_show, NULL);
860static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL); 870static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL);
861static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL); 871static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL);
862#ifdef CONFIG_FAIL_MAKE_REQUEST 872#ifdef CONFIG_FAIL_MAKE_REQUEST
@@ -875,6 +885,7 @@ static struct attribute *disk_attrs[] = {
875 &dev_attr_removable.attr, 885 &dev_attr_removable.attr,
876 &dev_attr_ro.attr, 886 &dev_attr_ro.attr,
877 &dev_attr_size.attr, 887 &dev_attr_size.attr,
888 &dev_attr_alignment_offset.attr,
878 &dev_attr_capability.attr, 889 &dev_attr_capability.attr,
879 &dev_attr_stat.attr, 890 &dev_attr_stat.attr,
880#ifdef CONFIG_FAIL_MAKE_REQUEST 891#ifdef CONFIG_FAIL_MAKE_REQUEST
diff --git a/block/ioctl.c b/block/ioctl.c
index ad474d4bbcce..500e4c73cc52 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -152,10 +152,10 @@ static int blk_ioctl_discard(struct block_device *bdev, uint64_t start,
152 bio->bi_private = &wait; 152 bio->bi_private = &wait;
153 bio->bi_sector = start; 153 bio->bi_sector = start;
154 154
155 if (len > q->max_hw_sectors) { 155 if (len > queue_max_hw_sectors(q)) {
156 bio->bi_size = q->max_hw_sectors << 9; 156 bio->bi_size = queue_max_hw_sectors(q) << 9;
157 len -= q->max_hw_sectors; 157 len -= queue_max_hw_sectors(q);
158 start += q->max_hw_sectors; 158 start += queue_max_hw_sectors(q);
159 } else { 159 } else {
160 bio->bi_size = len << 9; 160 bio->bi_size = len << 9;
161 len = 0; 161 len = 0;
@@ -311,9 +311,9 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
311 case BLKBSZGET: /* get the logical block size (cf. BLKSSZGET) */ 311 case BLKBSZGET: /* get the logical block size (cf. BLKSSZGET) */
312 return put_int(arg, block_size(bdev)); 312 return put_int(arg, block_size(bdev));
313 case BLKSSZGET: /* get block device hardware sector size */ 313 case BLKSSZGET: /* get block device hardware sector size */
314 return put_int(arg, bdev_hardsect_size(bdev)); 314 return put_int(arg, bdev_logical_block_size(bdev));
315 case BLKSECTGET: 315 case BLKSECTGET:
316 return put_ushort(arg, bdev_get_queue(bdev)->max_sectors); 316 return put_ushort(arg, queue_max_sectors(bdev_get_queue(bdev)));
317 case BLKRASET: 317 case BLKRASET:
318 case BLKFRASET: 318 case BLKFRASET:
319 if(!capable(CAP_SYS_ADMIN)) 319 if(!capable(CAP_SYS_ADMIN))
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 82a0ca2f6729..5f8e798ede4e 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -75,7 +75,7 @@ static int sg_set_timeout(struct request_queue *q, int __user *p)
75 75
76static int sg_get_reserved_size(struct request_queue *q, int __user *p) 76static int sg_get_reserved_size(struct request_queue *q, int __user *p)
77{ 77{
78 unsigned val = min(q->sg_reserved_size, q->max_sectors << 9); 78 unsigned val = min(q->sg_reserved_size, queue_max_sectors(q) << 9);
79 79
80 return put_user(val, p); 80 return put_user(val, p);
81} 81}
@@ -89,8 +89,8 @@ static int sg_set_reserved_size(struct request_queue *q, int __user *p)
89 89
90 if (size < 0) 90 if (size < 0)
91 return -EINVAL; 91 return -EINVAL;
92 if (size > (q->max_sectors << 9)) 92 if (size > (queue_max_sectors(q) << 9))
93 size = q->max_sectors << 9; 93 size = queue_max_sectors(q) << 9;
94 94
95 q->sg_reserved_size = size; 95 q->sg_reserved_size = size;
96 return 0; 96 return 0;
@@ -230,7 +230,7 @@ static int blk_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr,
230 hdr->info = 0; 230 hdr->info = 0;
231 if (hdr->masked_status || hdr->host_status || hdr->driver_status) 231 if (hdr->masked_status || hdr->host_status || hdr->driver_status)
232 hdr->info |= SG_INFO_CHECK; 232 hdr->info |= SG_INFO_CHECK;
233 hdr->resid = rq->data_len; 233 hdr->resid = rq->resid_len;
234 hdr->sb_len_wr = 0; 234 hdr->sb_len_wr = 0;
235 235
236 if (rq->sense_len && hdr->sbp) { 236 if (rq->sense_len && hdr->sbp) {
@@ -264,7 +264,7 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
264 if (hdr->cmd_len > BLK_MAX_CDB) 264 if (hdr->cmd_len > BLK_MAX_CDB)
265 return -EINVAL; 265 return -EINVAL;
266 266
267 if (hdr->dxfer_len > (q->max_hw_sectors << 9)) 267 if (hdr->dxfer_len > (queue_max_hw_sectors(q) << 9))
268 return -EIO; 268 return -EIO;
269 269
270 if (hdr->dxfer_len) 270 if (hdr->dxfer_len)
@@ -500,9 +500,6 @@ static int __blk_send_generic(struct request_queue *q, struct gendisk *bd_disk,
500 500
501 rq = blk_get_request(q, WRITE, __GFP_WAIT); 501 rq = blk_get_request(q, WRITE, __GFP_WAIT);
502 rq->cmd_type = REQ_TYPE_BLOCK_PC; 502 rq->cmd_type = REQ_TYPE_BLOCK_PC;
503 rq->data = NULL;
504 rq->data_len = 0;
505 rq->extra_len = 0;
506 rq->timeout = BLK_DEFAULT_SG_TIMEOUT; 503 rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
507 rq->cmd[0] = cmd; 504 rq->cmd[0] = cmd;
508 rq->cmd[4] = data; 505 rq->cmd[4] = data;
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 6b91c26a4635..15a23031833f 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -77,8 +77,6 @@ static ssize_t ahci_led_store(struct ata_port *ap, const char *buf,
77 size_t size); 77 size_t size);
78static ssize_t ahci_transmit_led_message(struct ata_port *ap, u32 state, 78static ssize_t ahci_transmit_led_message(struct ata_port *ap, u32 state,
79 ssize_t size); 79 ssize_t size);
80#define MAX_SLOTS 8
81#define MAX_RETRY 15
82 80
83enum { 81enum {
84 AHCI_PCI_BAR = 5, 82 AHCI_PCI_BAR = 5,
@@ -231,6 +229,10 @@ enum {
231 229
232 ICH_MAP = 0x90, /* ICH MAP register */ 230 ICH_MAP = 0x90, /* ICH MAP register */
233 231
232 /* em constants */
233 EM_MAX_SLOTS = 8,
234 EM_MAX_RETRY = 5,
235
234 /* em_ctl bits */ 236 /* em_ctl bits */
235 EM_CTL_RST = (1 << 9), /* Reset */ 237 EM_CTL_RST = (1 << 9), /* Reset */
236 EM_CTL_TM = (1 << 8), /* Transmit Message */ 238 EM_CTL_TM = (1 << 8), /* Transmit Message */
@@ -282,8 +284,8 @@ struct ahci_port_priv {
282 unsigned int ncq_saw_dmas:1; 284 unsigned int ncq_saw_dmas:1;
283 unsigned int ncq_saw_sdb:1; 285 unsigned int ncq_saw_sdb:1;
284 u32 intr_mask; /* interrupts to enable */ 286 u32 intr_mask; /* interrupts to enable */
285 struct ahci_em_priv em_priv[MAX_SLOTS];/* enclosure management info 287 /* enclosure management info per PM slot */
286 * per PM slot */ 288 struct ahci_em_priv em_priv[EM_MAX_SLOTS];
287}; 289};
288 290
289static int ahci_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val); 291static int ahci_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
@@ -313,7 +315,6 @@ static void ahci_error_handler(struct ata_port *ap);
313static void ahci_post_internal_cmd(struct ata_queued_cmd *qc); 315static void ahci_post_internal_cmd(struct ata_queued_cmd *qc);
314static int ahci_port_resume(struct ata_port *ap); 316static int ahci_port_resume(struct ata_port *ap);
315static void ahci_dev_config(struct ata_device *dev); 317static void ahci_dev_config(struct ata_device *dev);
316static unsigned int ahci_fill_sg(struct ata_queued_cmd *qc, void *cmd_tbl);
317static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag, 318static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
318 u32 opts); 319 u32 opts);
319#ifdef CONFIG_PM 320#ifdef CONFIG_PM
@@ -404,14 +405,14 @@ static struct ata_port_operations ahci_sb600_ops = {
404#define AHCI_HFLAGS(flags) .private_data = (void *)(flags) 405#define AHCI_HFLAGS(flags) .private_data = (void *)(flags)
405 406
406static const struct ata_port_info ahci_port_info[] = { 407static const struct ata_port_info ahci_port_info[] = {
407 /* board_ahci */ 408 [board_ahci] =
408 { 409 {
409 .flags = AHCI_FLAG_COMMON, 410 .flags = AHCI_FLAG_COMMON,
410 .pio_mask = ATA_PIO4, 411 .pio_mask = ATA_PIO4,
411 .udma_mask = ATA_UDMA6, 412 .udma_mask = ATA_UDMA6,
412 .port_ops = &ahci_ops, 413 .port_ops = &ahci_ops,
413 }, 414 },
414 /* board_ahci_vt8251 */ 415 [board_ahci_vt8251] =
415 { 416 {
416 AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_PMP), 417 AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_PMP),
417 .flags = AHCI_FLAG_COMMON, 418 .flags = AHCI_FLAG_COMMON,
@@ -419,7 +420,7 @@ static const struct ata_port_info ahci_port_info[] = {
419 .udma_mask = ATA_UDMA6, 420 .udma_mask = ATA_UDMA6,
420 .port_ops = &ahci_vt8251_ops, 421 .port_ops = &ahci_vt8251_ops,
421 }, 422 },
422 /* board_ahci_ign_iferr */ 423 [board_ahci_ign_iferr] =
423 { 424 {
424 AHCI_HFLAGS (AHCI_HFLAG_IGN_IRQ_IF_ERR), 425 AHCI_HFLAGS (AHCI_HFLAG_IGN_IRQ_IF_ERR),
425 .flags = AHCI_FLAG_COMMON, 426 .flags = AHCI_FLAG_COMMON,
@@ -427,17 +428,16 @@ static const struct ata_port_info ahci_port_info[] = {
427 .udma_mask = ATA_UDMA6, 428 .udma_mask = ATA_UDMA6,
428 .port_ops = &ahci_ops, 429 .port_ops = &ahci_ops,
429 }, 430 },
430 /* board_ahci_sb600 */ 431 [board_ahci_sb600] =
431 { 432 {
432 AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL | 433 AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL |
433 AHCI_HFLAG_32BIT_ONLY | AHCI_HFLAG_NO_MSI | 434 AHCI_HFLAG_NO_MSI | AHCI_HFLAG_SECT255),
434 AHCI_HFLAG_SECT255),
435 .flags = AHCI_FLAG_COMMON, 435 .flags = AHCI_FLAG_COMMON,
436 .pio_mask = ATA_PIO4, 436 .pio_mask = ATA_PIO4,
437 .udma_mask = ATA_UDMA6, 437 .udma_mask = ATA_UDMA6,
438 .port_ops = &ahci_sb600_ops, 438 .port_ops = &ahci_sb600_ops,
439 }, 439 },
440 /* board_ahci_mv */ 440 [board_ahci_mv] =
441 { 441 {
442 AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_MSI | 442 AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_MSI |
443 AHCI_HFLAG_MV_PATA | AHCI_HFLAG_NO_PMP), 443 AHCI_HFLAG_MV_PATA | AHCI_HFLAG_NO_PMP),
@@ -447,7 +447,7 @@ static const struct ata_port_info ahci_port_info[] = {
447 .udma_mask = ATA_UDMA6, 447 .udma_mask = ATA_UDMA6,
448 .port_ops = &ahci_ops, 448 .port_ops = &ahci_ops,
449 }, 449 },
450 /* board_ahci_sb700, for SB700 and SB800 */ 450 [board_ahci_sb700] = /* for SB700 and SB800 */
451 { 451 {
452 AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL), 452 AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL),
453 .flags = AHCI_FLAG_COMMON, 453 .flags = AHCI_FLAG_COMMON,
@@ -455,7 +455,7 @@ static const struct ata_port_info ahci_port_info[] = {
455 .udma_mask = ATA_UDMA6, 455 .udma_mask = ATA_UDMA6,
456 .port_ops = &ahci_sb600_ops, 456 .port_ops = &ahci_sb600_ops,
457 }, 457 },
458 /* board_ahci_mcp65 */ 458 [board_ahci_mcp65] =
459 { 459 {
460 AHCI_HFLAGS (AHCI_HFLAG_YES_NCQ), 460 AHCI_HFLAGS (AHCI_HFLAG_YES_NCQ),
461 .flags = AHCI_FLAG_COMMON, 461 .flags = AHCI_FLAG_COMMON,
@@ -463,7 +463,7 @@ static const struct ata_port_info ahci_port_info[] = {
463 .udma_mask = ATA_UDMA6, 463 .udma_mask = ATA_UDMA6,
464 .port_ops = &ahci_ops, 464 .port_ops = &ahci_ops,
465 }, 465 },
466 /* board_ahci_nopmp */ 466 [board_ahci_nopmp] =
467 { 467 {
468 AHCI_HFLAGS (AHCI_HFLAG_NO_PMP), 468 AHCI_HFLAGS (AHCI_HFLAG_NO_PMP),
469 .flags = AHCI_FLAG_COMMON, 469 .flags = AHCI_FLAG_COMMON,
@@ -1141,12 +1141,12 @@ static void ahci_start_port(struct ata_port *ap)
1141 emp = &pp->em_priv[link->pmp]; 1141 emp = &pp->em_priv[link->pmp];
1142 1142
1143 /* EM Transmit bit maybe busy during init */ 1143 /* EM Transmit bit maybe busy during init */
1144 for (i = 0; i < MAX_RETRY; i++) { 1144 for (i = 0; i < EM_MAX_RETRY; i++) {
1145 rc = ahci_transmit_led_message(ap, 1145 rc = ahci_transmit_led_message(ap,
1146 emp->led_state, 1146 emp->led_state,
1147 4); 1147 4);
1148 if (rc == -EBUSY) 1148 if (rc == -EBUSY)
1149 udelay(100); 1149 msleep(1);
1150 else 1150 else
1151 break; 1151 break;
1152 } 1152 }
@@ -1340,7 +1340,7 @@ static ssize_t ahci_transmit_led_message(struct ata_port *ap, u32 state,
1340 1340
1341 /* get the slot number from the message */ 1341 /* get the slot number from the message */
1342 pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8; 1342 pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8;
1343 if (pmp < MAX_SLOTS) 1343 if (pmp < EM_MAX_SLOTS)
1344 emp = &pp->em_priv[pmp]; 1344 emp = &pp->em_priv[pmp];
1345 else 1345 else
1346 return -EINVAL; 1346 return -EINVAL;
@@ -1408,7 +1408,7 @@ static ssize_t ahci_led_store(struct ata_port *ap, const char *buf,
1408 1408
1409 /* get the slot number from the message */ 1409 /* get the slot number from the message */
1410 pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8; 1410 pmp = (state & EM_MSG_LED_PMP_SLOT) >> 8;
1411 if (pmp < MAX_SLOTS) 1411 if (pmp < EM_MAX_SLOTS)
1412 emp = &pp->em_priv[pmp]; 1412 emp = &pp->em_priv[pmp];
1413 else 1413 else
1414 return -EINVAL; 1414 return -EINVAL;
@@ -2584,6 +2584,51 @@ static void ahci_p5wdh_workaround(struct ata_host *host)
2584 } 2584 }
2585} 2585}
2586 2586
2587/*
2588 * SB600 ahci controller on ASUS M2A-VM can't do 64bit DMA with older
2589 * BIOS. The oldest version known to be broken is 0901 and working is
2590 * 1501 which was released on 2007-10-26. Force 32bit DMA on anything
2591 * older than 1501. Please read bko#9412 for more info.
2592 */
2593static bool ahci_asus_m2a_vm_32bit_only(struct pci_dev *pdev)
2594{
2595 static const struct dmi_system_id sysids[] = {
2596 {
2597 .ident = "ASUS M2A-VM",
2598 .matches = {
2599 DMI_MATCH(DMI_BOARD_VENDOR,
2600 "ASUSTeK Computer INC."),
2601 DMI_MATCH(DMI_BOARD_NAME, "M2A-VM"),
2602 },
2603 },
2604 { }
2605 };
2606 const char *cutoff_mmdd = "10/26";
2607 const char *date;
2608 int year;
2609
2610 if (pdev->bus->number != 0 || pdev->devfn != PCI_DEVFN(0x12, 0) ||
2611 !dmi_check_system(sysids))
2612 return false;
2613
2614 /*
2615 * Argh.... both version and date are free form strings.
2616 * Let's hope they're using the same date format across
2617 * different versions.
2618 */
2619 date = dmi_get_system_info(DMI_BIOS_DATE);
2620 year = dmi_get_year(DMI_BIOS_DATE);
2621 if (date && strlen(date) >= 10 && date[2] == '/' && date[5] == '/' &&
2622 (year > 2007 ||
2623 (year == 2007 && strncmp(date, cutoff_mmdd, 5) >= 0)))
2624 return false;
2625
2626 dev_printk(KERN_WARNING, &pdev->dev, "ASUS M2A-VM: BIOS too old, "
2627 "forcing 32bit DMA, update BIOS\n");
2628
2629 return true;
2630}
2631
2587static bool ahci_broken_system_poweroff(struct pci_dev *pdev) 2632static bool ahci_broken_system_poweroff(struct pci_dev *pdev)
2588{ 2633{
2589 static const struct dmi_system_id broken_systems[] = { 2634 static const struct dmi_system_id broken_systems[] = {
@@ -2744,6 +2789,10 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2744 if (board_id == board_ahci_sb700 && pdev->revision >= 0x40) 2789 if (board_id == board_ahci_sb700 && pdev->revision >= 0x40)
2745 hpriv->flags &= ~AHCI_HFLAG_IGN_SERR_INTERNAL; 2790 hpriv->flags &= ~AHCI_HFLAG_IGN_SERR_INTERNAL;
2746 2791
2792 /* apply ASUS M2A_VM quirk */
2793 if (ahci_asus_m2a_vm_32bit_only(pdev))
2794 hpriv->flags |= AHCI_HFLAG_32BIT_ONLY;
2795
2747 if (!(hpriv->flags & AHCI_HFLAG_NO_MSI)) 2796 if (!(hpriv->flags & AHCI_HFLAG_NO_MSI))
2748 pci_enable_msi(pdev); 2797 pci_enable_msi(pdev);
2749 2798
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index 1aeb7082b0c4..d0a14cf2bd74 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -223,10 +223,8 @@ static const struct pci_device_id piix_pci_tbl[] = {
223 /* ICH8 Mobile PATA Controller */ 223 /* ICH8 Mobile PATA Controller */
224 { 0x8086, 0x2850, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, 224 { 0x8086, 0x2850, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
225 225
226 /* NOTE: The following PCI ids must be kept in sync with the 226 /* SATA ports */
227 * list in drivers/pci/quirks.c. 227
228 */
229
230 /* 82801EB (ICH5) */ 228 /* 82801EB (ICH5) */
231 { 0x8086, 0x24d1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata }, 229 { 0x8086, 0x24d1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich5_sata },
232 /* 82801EB (ICH5) */ 230 /* 82801EB (ICH5) */
@@ -1509,8 +1507,8 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
1509 dev_printk(KERN_DEBUG, &pdev->dev, 1507 dev_printk(KERN_DEBUG, &pdev->dev,
1510 "version " DRV_VERSION "\n"); 1508 "version " DRV_VERSION "\n");
1511 1509
1512 /* no hotplugging support (FIXME) */ 1510 /* no hotplugging support for later devices (FIXME) */
1513 if (!in_module_init) 1511 if (!in_module_init && ent->driver_data >= ich5_sata)
1514 return -ENODEV; 1512 return -ENODEV;
1515 1513
1516 if (piix_broken_system_poweroff(pdev)) { 1514 if (piix_broken_system_poweroff(pdev)) {
@@ -1591,6 +1589,7 @@ static int __devinit piix_init_one(struct pci_dev *pdev,
1591 host->ports[1]->mwdma_mask = 0; 1589 host->ports[1]->mwdma_mask = 0;
1592 host->ports[1]->udma_mask = 0; 1590 host->ports[1]->udma_mask = 0;
1593 } 1591 }
1592 host->flags |= ATA_HOST_PARALLEL_SCAN;
1594 1593
1595 pci_set_master(pdev); 1594 pci_set_master(pdev);
1596 return ata_pci_sff_activate_host(host, ata_sff_interrupt, &piix_sht); 1595 return ata_pci_sff_activate_host(host, ata_sff_interrupt, &piix_sht);
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index c9242301cfa1..ca4d208ddf3b 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -5031,7 +5031,6 @@ int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active)
5031{ 5031{
5032 int nr_done = 0; 5032 int nr_done = 0;
5033 u32 done_mask; 5033 u32 done_mask;
5034 int i;
5035 5034
5036 done_mask = ap->qc_active ^ qc_active; 5035 done_mask = ap->qc_active ^ qc_active;
5037 5036
@@ -5041,16 +5040,16 @@ int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active)
5041 return -EINVAL; 5040 return -EINVAL;
5042 } 5041 }
5043 5042
5044 for (i = 0; i < ATA_MAX_QUEUE; i++) { 5043 while (done_mask) {
5045 struct ata_queued_cmd *qc; 5044 struct ata_queued_cmd *qc;
5045 unsigned int tag = __ffs(done_mask);
5046 5046
5047 if (!(done_mask & (1 << i))) 5047 qc = ata_qc_from_tag(ap, tag);
5048 continue; 5048 if (qc) {
5049
5050 if ((qc = ata_qc_from_tag(ap, i))) {
5051 ata_qc_complete(qc); 5049 ata_qc_complete(qc);
5052 nr_done++; 5050 nr_done++;
5053 } 5051 }
5052 done_mask &= ~(1 << tag);
5054 } 5053 }
5055 5054
5056 return nr_done; 5055 return nr_done;
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 342316064e9f..d0dfeef55db5 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -1084,7 +1084,7 @@ static int atapi_drain_needed(struct request *rq)
1084 if (likely(!blk_pc_request(rq))) 1084 if (likely(!blk_pc_request(rq)))
1085 return 0; 1085 return 0;
1086 1086
1087 if (!rq->data_len || (rq->cmd_flags & REQ_RW)) 1087 if (!blk_rq_bytes(rq) || (rq->cmd_flags & REQ_RW))
1088 return 0; 1088 return 0;
1089 1089
1090 return atapi_cmd_type(rq->cmd[0]) == ATAPI_MISC; 1090 return atapi_cmd_type(rq->cmd[0]) == ATAPI_MISC;
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index bb18415d3d63..bbbb1fab1755 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -727,17 +727,23 @@ unsigned int ata_sff_data_xfer(struct ata_device *dev, unsigned char *buf,
727 else 727 else
728 iowrite16_rep(data_addr, buf, words); 728 iowrite16_rep(data_addr, buf, words);
729 729
730 /* Transfer trailing 1 byte, if any. */ 730 /* Transfer trailing byte, if any. */
731 if (unlikely(buflen & 0x01)) { 731 if (unlikely(buflen & 0x01)) {
732 __le16 align_buf[1] = { 0 }; 732 unsigned char pad[2];
733 unsigned char *trailing_buf = buf + buflen - 1;
734 733
734 /* Point buf to the tail of buffer */
735 buf += buflen - 1;
736
737 /*
738 * Use io*16_rep() accessors here as well to avoid pointlessly
739 * swapping bytes to and fro on the big endian machines...
740 */
735 if (rw == READ) { 741 if (rw == READ) {
736 align_buf[0] = cpu_to_le16(ioread16(data_addr)); 742 ioread16_rep(data_addr, pad, 1);
737 memcpy(trailing_buf, align_buf, 1); 743 *buf = pad[0];
738 } else { 744 } else {
739 memcpy(align_buf, trailing_buf, 1); 745 pad[0] = *buf;
740 iowrite16(le16_to_cpu(align_buf[0]), data_addr); 746 iowrite16_rep(data_addr, pad, 1);
741 } 747 }
742 words++; 748 words++;
743 } 749 }
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index 6cda12ba8122..b2d11f300c39 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -305,8 +305,8 @@ static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance);
305static int nv_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val); 305static int nv_scr_read(struct ata_link *link, unsigned int sc_reg, u32 *val);
306static int nv_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val); 306static int nv_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val);
307 307
308static int nv_noclassify_hardreset(struct ata_link *link, unsigned int *class, 308static int nv_hardreset(struct ata_link *link, unsigned int *class,
309 unsigned long deadline); 309 unsigned long deadline);
310static void nv_nf2_freeze(struct ata_port *ap); 310static void nv_nf2_freeze(struct ata_port *ap);
311static void nv_nf2_thaw(struct ata_port *ap); 311static void nv_nf2_thaw(struct ata_port *ap);
312static void nv_ck804_freeze(struct ata_port *ap); 312static void nv_ck804_freeze(struct ata_port *ap);
@@ -406,49 +406,82 @@ static struct scsi_host_template nv_swncq_sht = {
406 .slave_configure = nv_swncq_slave_config, 406 .slave_configure = nv_swncq_slave_config,
407}; 407};
408 408
409static struct ata_port_operations nv_common_ops = { 409/*
410 * NV SATA controllers have various different problems with hardreset
411 * protocol depending on the specific controller and device.
412 *
413 * GENERIC:
414 *
415 * bko11195 reports that link doesn't come online after hardreset on
416 * generic nv's and there have been several other similar reports on
417 * linux-ide.
418 *
419 * bko12351#c23 reports that warmplug on MCP61 doesn't work with
420 * softreset.
421 *
422 * NF2/3:
423 *
424 * bko3352 reports nf2/3 controllers can't determine device signature
425 * reliably after hardreset. The following thread reports detection
426 * failure on cold boot with the standard debouncing timing.
427 *
428 * http://thread.gmane.org/gmane.linux.ide/34098
429 *
430 * bko12176 reports that hardreset fails to bring up the link during
431 * boot on nf2.
432 *
433 * CK804:
434 *
435 * For initial probing after boot and hot plugging, hardreset mostly
436 * works fine on CK804 but curiously, reprobing on the initial port
437 * by rescanning or rmmod/insmod fails to acquire the initial D2H Reg
438 * FIS in somewhat undeterministic way.
439 *
440 * SWNCQ:
441 *
442 * bko12351 reports that when SWNCQ is enabled, for hotplug to work,
443 * hardreset should be used and hardreset can't report proper
444 * signature, which suggests that mcp5x is closer to nf2 as long as
445 * reset quirkiness is concerned.
446 *
447 * bko12703 reports that boot probing fails for intel SSD with
448 * hardreset. Link fails to come online. Softreset works fine.
449 *
450 * The failures are varied but the following patterns seem true for
451 * all flavors.
452 *
453 * - Softreset during boot always works.
454 *
455 * - Hardreset during boot sometimes fails to bring up the link on
456 * certain comibnations and device signature acquisition is
457 * unreliable.
458 *
459 * - Hardreset is often necessary after hotplug.
460 *
461 * So, preferring softreset for boot probing and error handling (as
462 * hardreset might bring down the link) but using hardreset for
463 * post-boot probing should work around the above issues in most
464 * cases. Define nv_hardreset() which only kicks in for post-boot
465 * probing and use it for all variants.
466 */
467static struct ata_port_operations nv_generic_ops = {
410 .inherits = &ata_bmdma_port_ops, 468 .inherits = &ata_bmdma_port_ops,
411 .lost_interrupt = ATA_OP_NULL, 469 .lost_interrupt = ATA_OP_NULL,
412 .scr_read = nv_scr_read, 470 .scr_read = nv_scr_read,
413 .scr_write = nv_scr_write, 471 .scr_write = nv_scr_write,
472 .hardreset = nv_hardreset,
414}; 473};
415 474
416/* OSDL bz11195 reports that link doesn't come online after hardreset
417 * on generic nv's and there have been several other similar reports
418 * on linux-ide. Disable hardreset for generic nv's.
419 */
420static struct ata_port_operations nv_generic_ops = {
421 .inherits = &nv_common_ops,
422 .hardreset = ATA_OP_NULL,
423};
424
425/* nf2 is ripe with hardreset related problems.
426 *
427 * kernel bz#3352 reports nf2/3 controllers can't determine device
428 * signature reliably. The following thread reports detection failure
429 * on cold boot with the standard debouncing timing.
430 *
431 * http://thread.gmane.org/gmane.linux.ide/34098
432 *
433 * And bz#12176 reports that hardreset simply doesn't work on nf2.
434 * Give up on it and just don't do hardreset.
435 */
436static struct ata_port_operations nv_nf2_ops = { 475static struct ata_port_operations nv_nf2_ops = {
437 .inherits = &nv_generic_ops, 476 .inherits = &nv_generic_ops,
438 .freeze = nv_nf2_freeze, 477 .freeze = nv_nf2_freeze,
439 .thaw = nv_nf2_thaw, 478 .thaw = nv_nf2_thaw,
440}; 479};
441 480
442/* For initial probing after boot and hot plugging, hardreset mostly
443 * works fine on CK804 but curiously, reprobing on the initial port by
444 * rescanning or rmmod/insmod fails to acquire the initial D2H Reg FIS
445 * in somewhat undeterministic way. Use noclassify hardreset.
446 */
447static struct ata_port_operations nv_ck804_ops = { 481static struct ata_port_operations nv_ck804_ops = {
448 .inherits = &nv_common_ops, 482 .inherits = &nv_generic_ops,
449 .freeze = nv_ck804_freeze, 483 .freeze = nv_ck804_freeze,
450 .thaw = nv_ck804_thaw, 484 .thaw = nv_ck804_thaw,
451 .hardreset = nv_noclassify_hardreset,
452 .host_stop = nv_ck804_host_stop, 485 .host_stop = nv_ck804_host_stop,
453}; 486};
454 487
@@ -476,19 +509,8 @@ static struct ata_port_operations nv_adma_ops = {
476 .host_stop = nv_adma_host_stop, 509 .host_stop = nv_adma_host_stop,
477}; 510};
478 511
479/* Kernel bz#12351 reports that when SWNCQ is enabled, for hotplug to
480 * work, hardreset should be used and hardreset can't report proper
481 * signature, which suggests that mcp5x is closer to nf2 as long as
482 * reset quirkiness is concerned. Define separate ops for mcp5x with
483 * nv_noclassify_hardreset().
484 */
485static struct ata_port_operations nv_mcp5x_ops = {
486 .inherits = &nv_common_ops,
487 .hardreset = nv_noclassify_hardreset,
488};
489
490static struct ata_port_operations nv_swncq_ops = { 512static struct ata_port_operations nv_swncq_ops = {
491 .inherits = &nv_mcp5x_ops, 513 .inherits = &nv_generic_ops,
492 514
493 .qc_defer = ata_std_qc_defer, 515 .qc_defer = ata_std_qc_defer,
494 .qc_prep = nv_swncq_qc_prep, 516 .qc_prep = nv_swncq_qc_prep,
@@ -557,7 +579,7 @@ static const struct ata_port_info nv_port_info[] = {
557 .pio_mask = NV_PIO_MASK, 579 .pio_mask = NV_PIO_MASK,
558 .mwdma_mask = NV_MWDMA_MASK, 580 .mwdma_mask = NV_MWDMA_MASK,
559 .udma_mask = NV_UDMA_MASK, 581 .udma_mask = NV_UDMA_MASK,
560 .port_ops = &nv_mcp5x_ops, 582 .port_ops = &nv_generic_ops,
561 .private_data = NV_PI_PRIV(nv_generic_interrupt, &nv_sht), 583 .private_data = NV_PI_PRIV(nv_generic_interrupt, &nv_sht),
562 }, 584 },
563 /* SWNCQ */ 585 /* SWNCQ */
@@ -1559,15 +1581,24 @@ static int nv_scr_write(struct ata_link *link, unsigned int sc_reg, u32 val)
1559 return 0; 1581 return 0;
1560} 1582}
1561 1583
1562static int nv_noclassify_hardreset(struct ata_link *link, unsigned int *class, 1584static int nv_hardreset(struct ata_link *link, unsigned int *class,
1563 unsigned long deadline) 1585 unsigned long deadline)
1564{ 1586{
1565 bool online; 1587 struct ata_eh_context *ehc = &link->eh_context;
1566 int rc;
1567 1588
1568 rc = sata_link_hardreset(link, sata_deb_timing_hotplug, deadline, 1589 /* Do hardreset iff it's post-boot probing, please read the
1569 &online, NULL); 1590 * comment above port ops for details.
1570 return online ? -EAGAIN : rc; 1591 */
1592 if (!(link->ap->pflags & ATA_PFLAG_LOADING) &&
1593 !ata_dev_enabled(link->device))
1594 sata_link_hardreset(link, sata_deb_timing_hotplug, deadline,
1595 NULL, NULL);
1596 else if (!(ehc->i.flags & ATA_EHI_QUIET))
1597 ata_link_printk(link, KERN_INFO,
1598 "nv: skipping hardreset on occupied port\n");
1599
1600 /* device signature acquisition is unreliable */
1601 return -EAGAIN;
1571} 1602}
1572 1603
1573static void nv_nf2_freeze(struct ata_port *ap) 1604static void nv_nf2_freeze(struct ata_port *ap)
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index e67ce8e5caa5..030ec079b184 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -183,7 +183,7 @@ static struct scsi_host_template sil_sht = {
183}; 183};
184 184
185static struct ata_port_operations sil_ops = { 185static struct ata_port_operations sil_ops = {
186 .inherits = &ata_bmdma_port_ops, 186 .inherits = &ata_bmdma32_port_ops,
187 .dev_config = sil_dev_config, 187 .dev_config = sil_dev_config,
188 .set_mode = sil_set_mode, 188 .set_mode = sil_set_mode,
189 .bmdma_setup = sil_bmdma_setup, 189 .bmdma_setup = sil_bmdma_setup,
diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
index eb05a3c82a9e..bbcf970068ad 100644
--- a/drivers/ata/sata_sx4.c
+++ b/drivers/ata/sata_sx4.c
@@ -193,6 +193,7 @@ enum {
193 PDC_TIMER_MASK_INT, 193 PDC_TIMER_MASK_INT,
194}; 194};
195 195
196#define ECC_ERASE_BUF_SZ (128 * 1024)
196 197
197struct pdc_port_priv { 198struct pdc_port_priv {
198 u8 dimm_buf[(ATA_PRD_SZ * ATA_MAX_PRD) + 512]; 199 u8 dimm_buf[(ATA_PRD_SZ * ATA_MAX_PRD) + 512];
@@ -1280,7 +1281,6 @@ static unsigned int pdc20621_dimm_init(struct ata_host *host)
1280{ 1281{
1281 int speed, size, length; 1282 int speed, size, length;
1282 u32 addr, spd0, pci_status; 1283 u32 addr, spd0, pci_status;
1283 u32 tmp = 0;
1284 u32 time_period = 0; 1284 u32 time_period = 0;
1285 u32 tcount = 0; 1285 u32 tcount = 0;
1286 u32 ticks = 0; 1286 u32 ticks = 0;
@@ -1395,14 +1395,17 @@ static unsigned int pdc20621_dimm_init(struct ata_host *host)
1395 pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS, 1395 pdc20621_i2c_read(host, PDC_DIMM0_SPD_DEV_ADDRESS,
1396 PDC_DIMM_SPD_TYPE, &spd0); 1396 PDC_DIMM_SPD_TYPE, &spd0);
1397 if (spd0 == 0x02) { 1397 if (spd0 == 0x02) {
1398 void *buf;
1398 VPRINTK("Start ECC initialization\n"); 1399 VPRINTK("Start ECC initialization\n");
1399 addr = 0; 1400 addr = 0;
1400 length = size * 1024 * 1024; 1401 length = size * 1024 * 1024;
1402 buf = kzalloc(ECC_ERASE_BUF_SZ, GFP_KERNEL);
1401 while (addr < length) { 1403 while (addr < length) {
1402 pdc20621_put_to_dimm(host, (void *) &tmp, addr, 1404 pdc20621_put_to_dimm(host, buf, addr,
1403 sizeof(u32)); 1405 ECC_ERASE_BUF_SZ);
1404 addr += sizeof(u32); 1406 addr += ECC_ERASE_BUF_SZ;
1405 } 1407 }
1408 kfree(buf);
1406 VPRINTK("Finish ECC initialization\n"); 1409 VPRINTK("Finish ECC initialization\n");
1407 } 1410 }
1408 return 0; 1411 return 0;
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index f22ed6cc69f2..668dc234b8e2 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -3321,7 +3321,7 @@ static int DAC960_process_queue(DAC960_Controller_T *Controller, struct request_
3321 DAC960_Command_T *Command; 3321 DAC960_Command_T *Command;
3322 3322
3323 while(1) { 3323 while(1) {
3324 Request = elv_next_request(req_q); 3324 Request = blk_peek_request(req_q);
3325 if (!Request) 3325 if (!Request)
3326 return 1; 3326 return 1;
3327 3327
@@ -3338,10 +3338,10 @@ static int DAC960_process_queue(DAC960_Controller_T *Controller, struct request_
3338 } 3338 }
3339 Command->Completion = Request->end_io_data; 3339 Command->Completion = Request->end_io_data;
3340 Command->LogicalDriveNumber = (long)Request->rq_disk->private_data; 3340 Command->LogicalDriveNumber = (long)Request->rq_disk->private_data;
3341 Command->BlockNumber = Request->sector; 3341 Command->BlockNumber = blk_rq_pos(Request);
3342 Command->BlockCount = Request->nr_sectors; 3342 Command->BlockCount = blk_rq_sectors(Request);
3343 Command->Request = Request; 3343 Command->Request = Request;
3344 blkdev_dequeue_request(Request); 3344 blk_start_request(Request);
3345 Command->SegmentCount = blk_rq_map_sg(req_q, 3345 Command->SegmentCount = blk_rq_map_sg(req_q,
3346 Command->Request, Command->cmd_sglist); 3346 Command->Request, Command->cmd_sglist);
3347 /* pci_map_sg MAY change the value of SegCount */ 3347 /* pci_map_sg MAY change the value of SegCount */
@@ -3431,7 +3431,7 @@ static void DAC960_queue_partial_rw(DAC960_Command_T *Command)
3431 * successfully as possible. 3431 * successfully as possible.
3432 */ 3432 */
3433 Command->SegmentCount = 1; 3433 Command->SegmentCount = 1;
3434 Command->BlockNumber = Request->sector; 3434 Command->BlockNumber = blk_rq_pos(Request);
3435 Command->BlockCount = 1; 3435 Command->BlockCount = 1;
3436 DAC960_QueueReadWriteCommand(Command); 3436 DAC960_QueueReadWriteCommand(Command);
3437 return; 3437 return;
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index ddea8e485cc9..f42fa50d3550 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -412,7 +412,7 @@ config ATA_OVER_ETH
412 412
413config MG_DISK 413config MG_DISK
414 tristate "mGine mflash, gflash support" 414 tristate "mGine mflash, gflash support"
415 depends on ARM && ATA && GPIOLIB 415 depends on ARM && GPIOLIB
416 help 416 help
417 mGine mFlash(gFlash) block device driver 417 mGine mFlash(gFlash) block device driver
418 418
diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c
index 8df436ff7068..9c6e5b0fe894 100644
--- a/drivers/block/amiflop.c
+++ b/drivers/block/amiflop.c
@@ -112,8 +112,6 @@ module_param(fd_def_df0, ulong, 0);
112MODULE_LICENSE("GPL"); 112MODULE_LICENSE("GPL");
113 113
114static struct request_queue *floppy_queue; 114static struct request_queue *floppy_queue;
115#define QUEUE (floppy_queue)
116#define CURRENT elv_next_request(floppy_queue)
117 115
118/* 116/*
119 * Macros 117 * Macros
@@ -1335,64 +1333,60 @@ static int get_track(int drive, int track)
1335 1333
1336static void redo_fd_request(void) 1334static void redo_fd_request(void)
1337{ 1335{
1336 struct request *rq;
1338 unsigned int cnt, block, track, sector; 1337 unsigned int cnt, block, track, sector;
1339 int drive; 1338 int drive;
1340 struct amiga_floppy_struct *floppy; 1339 struct amiga_floppy_struct *floppy;
1341 char *data; 1340 char *data;
1342 unsigned long flags; 1341 unsigned long flags;
1342 int err;
1343 1343
1344 repeat: 1344next_req:
1345 if (!CURRENT) { 1345 rq = blk_fetch_request(floppy_queue);
1346 if (!rq) {
1346 /* Nothing left to do */ 1347 /* Nothing left to do */
1347 return; 1348 return;
1348 } 1349 }
1349 1350
1350 floppy = CURRENT->rq_disk->private_data; 1351 floppy = rq->rq_disk->private_data;
1351 drive = floppy - unit; 1352 drive = floppy - unit;
1352 1353
1354next_segment:
1353 /* Here someone could investigate to be more efficient */ 1355 /* Here someone could investigate to be more efficient */
1354 for (cnt = 0; cnt < CURRENT->current_nr_sectors; cnt++) { 1356 for (cnt = 0, err = 0; cnt < blk_rq_cur_sectors(rq); cnt++) {
1355#ifdef DEBUG 1357#ifdef DEBUG
1356 printk("fd: sector %ld + %d requested for %s\n", 1358 printk("fd: sector %ld + %d requested for %s\n",
1357 CURRENT->sector,cnt, 1359 blk_rq_pos(rq), cnt,
1358 (rq_data_dir(CURRENT) == READ) ? "read" : "write"); 1360 (rq_data_dir(rq) == READ) ? "read" : "write");
1359#endif 1361#endif
1360 block = CURRENT->sector + cnt; 1362 block = blk_rq_pos(rq) + cnt;
1361 if ((int)block > floppy->blocks) { 1363 if ((int)block > floppy->blocks) {
1362 end_request(CURRENT, 0); 1364 err = -EIO;
1363 goto repeat; 1365 break;
1364 } 1366 }
1365 1367
1366 track = block / (floppy->dtype->sects * floppy->type->sect_mult); 1368 track = block / (floppy->dtype->sects * floppy->type->sect_mult);
1367 sector = block % (floppy->dtype->sects * floppy->type->sect_mult); 1369 sector = block % (floppy->dtype->sects * floppy->type->sect_mult);
1368 data = CURRENT->buffer + 512 * cnt; 1370 data = rq->buffer + 512 * cnt;
1369#ifdef DEBUG 1371#ifdef DEBUG
1370 printk("access to track %d, sector %d, with buffer at " 1372 printk("access to track %d, sector %d, with buffer at "
1371 "0x%08lx\n", track, sector, data); 1373 "0x%08lx\n", track, sector, data);
1372#endif 1374#endif
1373 1375
1374 if ((rq_data_dir(CURRENT) != READ) && (rq_data_dir(CURRENT) != WRITE)) {
1375 printk(KERN_WARNING "do_fd_request: unknown command\n");
1376 end_request(CURRENT, 0);
1377 goto repeat;
1378 }
1379 if (get_track(drive, track) == -1) { 1376 if (get_track(drive, track) == -1) {
1380 end_request(CURRENT, 0); 1377 err = -EIO;
1381 goto repeat; 1378 break;
1382 } 1379 }
1383 1380
1384 switch (rq_data_dir(CURRENT)) { 1381 if (rq_data_dir(rq) == READ) {
1385 case READ:
1386 memcpy(data, floppy->trackbuf + sector * 512, 512); 1382 memcpy(data, floppy->trackbuf + sector * 512, 512);
1387 break; 1383 } else {
1388
1389 case WRITE:
1390 memcpy(floppy->trackbuf + sector * 512, data, 512); 1384 memcpy(floppy->trackbuf + sector * 512, data, 512);
1391 1385
1392 /* keep the drive spinning while writes are scheduled */ 1386 /* keep the drive spinning while writes are scheduled */
1393 if (!fd_motor_on(drive)) { 1387 if (!fd_motor_on(drive)) {
1394 end_request(CURRENT, 0); 1388 err = -EIO;
1395 goto repeat; 1389 break;
1396 } 1390 }
1397 /* 1391 /*
1398 * setup a callback to write the track buffer 1392 * setup a callback to write the track buffer
@@ -1404,14 +1398,12 @@ static void redo_fd_request(void)
1404 /* reset the timer */ 1398 /* reset the timer */
1405 mod_timer (flush_track_timer + drive, jiffies + 1); 1399 mod_timer (flush_track_timer + drive, jiffies + 1);
1406 local_irq_restore(flags); 1400 local_irq_restore(flags);
1407 break;
1408 } 1401 }
1409 } 1402 }
1410 CURRENT->nr_sectors -= CURRENT->current_nr_sectors;
1411 CURRENT->sector += CURRENT->current_nr_sectors;
1412 1403
1413 end_request(CURRENT, 1); 1404 if (__blk_end_request_cur(rq, err))
1414 goto repeat; 1405 goto next_segment;
1406 goto next_req;
1415} 1407}
1416 1408
1417static void do_fd_request(struct request_queue * q) 1409static void do_fd_request(struct request_queue * q)
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 4234c11c1e4c..f5e7180d7f47 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -79,9 +79,7 @@
79#undef DEBUG 79#undef DEBUG
80 80
81static struct request_queue *floppy_queue; 81static struct request_queue *floppy_queue;
82 82static struct request *fd_request;
83#define QUEUE (floppy_queue)
84#define CURRENT elv_next_request(floppy_queue)
85 83
86/* Disk types: DD, HD, ED */ 84/* Disk types: DD, HD, ED */
87static struct atari_disk_type { 85static struct atari_disk_type {
@@ -376,6 +374,12 @@ static DEFINE_TIMER(readtrack_timer, fd_readtrack_check, 0, 0);
376static DEFINE_TIMER(timeout_timer, fd_times_out, 0, 0); 374static DEFINE_TIMER(timeout_timer, fd_times_out, 0, 0);
377static DEFINE_TIMER(fd_timer, check_change, 0, 0); 375static DEFINE_TIMER(fd_timer, check_change, 0, 0);
378 376
377static void fd_end_request_cur(int err)
378{
379 if (!__blk_end_request_cur(fd_request, err))
380 fd_request = NULL;
381}
382
379static inline void start_motor_off_timer(void) 383static inline void start_motor_off_timer(void)
380{ 384{
381 mod_timer(&motor_off_timer, jiffies + FD_MOTOR_OFF_DELAY); 385 mod_timer(&motor_off_timer, jiffies + FD_MOTOR_OFF_DELAY);
@@ -606,15 +610,15 @@ static void fd_error( void )
606 return; 610 return;
607 } 611 }
608 612
609 if (!CURRENT) 613 if (!fd_request)
610 return; 614 return;
611 615
612 CURRENT->errors++; 616 fd_request->errors++;
613 if (CURRENT->errors >= MAX_ERRORS) { 617 if (fd_request->errors >= MAX_ERRORS) {
614 printk(KERN_ERR "fd%d: too many errors.\n", SelectedDrive ); 618 printk(KERN_ERR "fd%d: too many errors.\n", SelectedDrive );
615 end_request(CURRENT, 0); 619 fd_end_request_cur(-EIO);
616 } 620 }
617 else if (CURRENT->errors == RECALIBRATE_ERRORS) { 621 else if (fd_request->errors == RECALIBRATE_ERRORS) {
618 printk(KERN_WARNING "fd%d: recalibrating\n", SelectedDrive ); 622 printk(KERN_WARNING "fd%d: recalibrating\n", SelectedDrive );
619 if (SelectedDrive != -1) 623 if (SelectedDrive != -1)
620 SUD.track = -1; 624 SUD.track = -1;
@@ -725,16 +729,14 @@ static void do_fd_action( int drive )
725 if (IS_BUFFERED( drive, ReqSide, ReqTrack )) { 729 if (IS_BUFFERED( drive, ReqSide, ReqTrack )) {
726 if (ReqCmd == READ) { 730 if (ReqCmd == READ) {
727 copy_buffer( SECTOR_BUFFER(ReqSector), ReqData ); 731 copy_buffer( SECTOR_BUFFER(ReqSector), ReqData );
728 if (++ReqCnt < CURRENT->current_nr_sectors) { 732 if (++ReqCnt < blk_rq_cur_sectors(fd_request)) {
729 /* read next sector */ 733 /* read next sector */
730 setup_req_params( drive ); 734 setup_req_params( drive );
731 goto repeat; 735 goto repeat;
732 } 736 }
733 else { 737 else {
734 /* all sectors finished */ 738 /* all sectors finished */
735 CURRENT->nr_sectors -= CURRENT->current_nr_sectors; 739 fd_end_request_cur(0);
736 CURRENT->sector += CURRENT->current_nr_sectors;
737 end_request(CURRENT, 1);
738 redo_fd_request(); 740 redo_fd_request();
739 return; 741 return;
740 } 742 }
@@ -1132,16 +1134,14 @@ static void fd_rwsec_done1(int status)
1132 } 1134 }
1133 } 1135 }
1134 1136
1135 if (++ReqCnt < CURRENT->current_nr_sectors) { 1137 if (++ReqCnt < blk_rq_cur_sectors(fd_request)) {
1136 /* read next sector */ 1138 /* read next sector */
1137 setup_req_params( SelectedDrive ); 1139 setup_req_params( SelectedDrive );
1138 do_fd_action( SelectedDrive ); 1140 do_fd_action( SelectedDrive );
1139 } 1141 }
1140 else { 1142 else {
1141 /* all sectors finished */ 1143 /* all sectors finished */
1142 CURRENT->nr_sectors -= CURRENT->current_nr_sectors; 1144 fd_end_request_cur(0);
1143 CURRENT->sector += CURRENT->current_nr_sectors;
1144 end_request(CURRENT, 1);
1145 redo_fd_request(); 1145 redo_fd_request();
1146 } 1146 }
1147 return; 1147 return;
@@ -1382,7 +1382,7 @@ static void setup_req_params( int drive )
1382 ReqData = ReqBuffer + 512 * ReqCnt; 1382 ReqData = ReqBuffer + 512 * ReqCnt;
1383 1383
1384 if (UseTrackbuffer) 1384 if (UseTrackbuffer)
1385 read_track = (ReqCmd == READ && CURRENT->errors == 0); 1385 read_track = (ReqCmd == READ && fd_request->errors == 0);
1386 else 1386 else
1387 read_track = 0; 1387 read_track = 0;
1388 1388
@@ -1396,25 +1396,27 @@ static void redo_fd_request(void)
1396 int drive, type; 1396 int drive, type;
1397 struct atari_floppy_struct *floppy; 1397 struct atari_floppy_struct *floppy;
1398 1398
1399 DPRINT(("redo_fd_request: CURRENT=%p dev=%s CURRENT->sector=%ld\n", 1399 DPRINT(("redo_fd_request: fd_request=%p dev=%s fd_request->sector=%ld\n",
1400 CURRENT, CURRENT ? CURRENT->rq_disk->disk_name : "", 1400 fd_request, fd_request ? fd_request->rq_disk->disk_name : "",
1401 CURRENT ? CURRENT->sector : 0 )); 1401 fd_request ? blk_rq_pos(fd_request) : 0 ));
1402 1402
1403 IsFormatting = 0; 1403 IsFormatting = 0;
1404 1404
1405repeat: 1405repeat:
1406 if (!fd_request) {
1407 fd_request = blk_fetch_request(floppy_queue);
1408 if (!fd_request)
1409 goto the_end;
1410 }
1406 1411
1407 if (!CURRENT) 1412 floppy = fd_request->rq_disk->private_data;
1408 goto the_end;
1409
1410 floppy = CURRENT->rq_disk->private_data;
1411 drive = floppy - unit; 1413 drive = floppy - unit;
1412 type = floppy->type; 1414 type = floppy->type;
1413 1415
1414 if (!UD.connected) { 1416 if (!UD.connected) {
1415 /* drive not connected */ 1417 /* drive not connected */
1416 printk(KERN_ERR "Unknown Device: fd%d\n", drive ); 1418 printk(KERN_ERR "Unknown Device: fd%d\n", drive );
1417 end_request(CURRENT, 0); 1419 fd_end_request_cur(-EIO);
1418 goto repeat; 1420 goto repeat;
1419 } 1421 }
1420 1422
@@ -1430,12 +1432,12 @@ repeat:
1430 /* user supplied disk type */ 1432 /* user supplied disk type */
1431 if (--type >= NUM_DISK_MINORS) { 1433 if (--type >= NUM_DISK_MINORS) {
1432 printk(KERN_WARNING "fd%d: invalid disk format", drive ); 1434 printk(KERN_WARNING "fd%d: invalid disk format", drive );
1433 end_request(CURRENT, 0); 1435 fd_end_request_cur(-EIO);
1434 goto repeat; 1436 goto repeat;
1435 } 1437 }
1436 if (minor2disktype[type].drive_types > DriveType) { 1438 if (minor2disktype[type].drive_types > DriveType) {
1437 printk(KERN_WARNING "fd%d: unsupported disk format", drive ); 1439 printk(KERN_WARNING "fd%d: unsupported disk format", drive );
1438 end_request(CURRENT, 0); 1440 fd_end_request_cur(-EIO);
1439 goto repeat; 1441 goto repeat;
1440 } 1442 }
1441 type = minor2disktype[type].index; 1443 type = minor2disktype[type].index;
@@ -1444,8 +1446,8 @@ repeat:
1444 UD.autoprobe = 0; 1446 UD.autoprobe = 0;
1445 } 1447 }
1446 1448
1447 if (CURRENT->sector + 1 > UDT->blocks) { 1449 if (blk_rq_pos(fd_request) + 1 > UDT->blocks) {
1448 end_request(CURRENT, 0); 1450 fd_end_request_cur(-EIO);
1449 goto repeat; 1451 goto repeat;
1450 } 1452 }
1451 1453
@@ -1453,9 +1455,9 @@ repeat:
1453 del_timer( &motor_off_timer ); 1455 del_timer( &motor_off_timer );
1454 1456
1455 ReqCnt = 0; 1457 ReqCnt = 0;
1456 ReqCmd = rq_data_dir(CURRENT); 1458 ReqCmd = rq_data_dir(fd_request);
1457 ReqBlock = CURRENT->sector; 1459 ReqBlock = blk_rq_pos(fd_request);
1458 ReqBuffer = CURRENT->buffer; 1460 ReqBuffer = fd_request->buffer;
1459 setup_req_params( drive ); 1461 setup_req_params( drive );
1460 do_fd_action( drive ); 1462 do_fd_action( drive );
1461 1463
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 5f7e64ba87e5..4bf8705b3ace 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -407,12 +407,7 @@ static int __init ramdisk_size(char *str)
407 rd_size = simple_strtol(str, NULL, 0); 407 rd_size = simple_strtol(str, NULL, 0);
408 return 1; 408 return 1;
409} 409}
410static int __init ramdisk_size2(char *str) 410__setup("ramdisk_size=", ramdisk_size);
411{
412 return ramdisk_size(str);
413}
414__setup("ramdisk=", ramdisk_size);
415__setup("ramdisk_size=", ramdisk_size2);
416#endif 411#endif
417 412
418/* 413/*
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 4d4d5e0d3fa6..b22cec97ea19 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -180,11 +180,13 @@ static void __devinit cciss_interrupt_mode(ctlr_info_t *, struct pci_dev *,
180 __u32); 180 __u32);
181static void start_io(ctlr_info_t *h); 181static void start_io(ctlr_info_t *h);
182static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size, 182static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size,
183 unsigned int use_unit_num, unsigned int log_unit,
184 __u8 page_code, unsigned char *scsi3addr, int cmd_type); 183 __u8 page_code, unsigned char *scsi3addr, int cmd_type);
185static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size, 184static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size,
186 unsigned int use_unit_num, unsigned int log_unit, 185 __u8 page_code, unsigned char scsi3addr[],
187 __u8 page_code, int cmd_type); 186 int cmd_type);
187static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
188 int attempt_retry);
189static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c);
188 190
189static void fail_all_cmds(unsigned long ctlr); 191static void fail_all_cmds(unsigned long ctlr);
190static int scan_thread(void *data); 192static int scan_thread(void *data);
@@ -437,6 +439,194 @@ static void __devinit cciss_procinit(int i)
437} 439}
438#endif /* CONFIG_PROC_FS */ 440#endif /* CONFIG_PROC_FS */
439 441
442#define MAX_PRODUCT_NAME_LEN 19
443
444#define to_hba(n) container_of(n, struct ctlr_info, dev)
445#define to_drv(n) container_of(n, drive_info_struct, dev)
446
447static struct device_type cciss_host_type = {
448 .name = "cciss_host",
449};
450
451static ssize_t dev_show_unique_id(struct device *dev,
452 struct device_attribute *attr,
453 char *buf)
454{
455 drive_info_struct *drv = to_drv(dev);
456 struct ctlr_info *h = to_hba(drv->dev.parent);
457 __u8 sn[16];
458 unsigned long flags;
459 int ret = 0;
460
461 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
462 if (h->busy_configuring)
463 ret = -EBUSY;
464 else
465 memcpy(sn, drv->serial_no, sizeof(sn));
466 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
467
468 if (ret)
469 return ret;
470 else
471 return snprintf(buf, 16 * 2 + 2,
472 "%02X%02X%02X%02X%02X%02X%02X%02X"
473 "%02X%02X%02X%02X%02X%02X%02X%02X\n",
474 sn[0], sn[1], sn[2], sn[3],
475 sn[4], sn[5], sn[6], sn[7],
476 sn[8], sn[9], sn[10], sn[11],
477 sn[12], sn[13], sn[14], sn[15]);
478}
479DEVICE_ATTR(unique_id, S_IRUGO, dev_show_unique_id, NULL);
480
481static ssize_t dev_show_vendor(struct device *dev,
482 struct device_attribute *attr,
483 char *buf)
484{
485 drive_info_struct *drv = to_drv(dev);
486 struct ctlr_info *h = to_hba(drv->dev.parent);
487 char vendor[VENDOR_LEN + 1];
488 unsigned long flags;
489 int ret = 0;
490
491 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
492 if (h->busy_configuring)
493 ret = -EBUSY;
494 else
495 memcpy(vendor, drv->vendor, VENDOR_LEN + 1);
496 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
497
498 if (ret)
499 return ret;
500 else
501 return snprintf(buf, sizeof(vendor) + 1, "%s\n", drv->vendor);
502}
503DEVICE_ATTR(vendor, S_IRUGO, dev_show_vendor, NULL);
504
505static ssize_t dev_show_model(struct device *dev,
506 struct device_attribute *attr,
507 char *buf)
508{
509 drive_info_struct *drv = to_drv(dev);
510 struct ctlr_info *h = to_hba(drv->dev.parent);
511 char model[MODEL_LEN + 1];
512 unsigned long flags;
513 int ret = 0;
514
515 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
516 if (h->busy_configuring)
517 ret = -EBUSY;
518 else
519 memcpy(model, drv->model, MODEL_LEN + 1);
520 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
521
522 if (ret)
523 return ret;
524 else
525 return snprintf(buf, sizeof(model) + 1, "%s\n", drv->model);
526}
527DEVICE_ATTR(model, S_IRUGO, dev_show_model, NULL);
528
529static ssize_t dev_show_rev(struct device *dev,
530 struct device_attribute *attr,
531 char *buf)
532{
533 drive_info_struct *drv = to_drv(dev);
534 struct ctlr_info *h = to_hba(drv->dev.parent);
535 char rev[REV_LEN + 1];
536 unsigned long flags;
537 int ret = 0;
538
539 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
540 if (h->busy_configuring)
541 ret = -EBUSY;
542 else
543 memcpy(rev, drv->rev, REV_LEN + 1);
544 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
545
546 if (ret)
547 return ret;
548 else
549 return snprintf(buf, sizeof(rev) + 1, "%s\n", drv->rev);
550}
551DEVICE_ATTR(rev, S_IRUGO, dev_show_rev, NULL);
552
553static struct attribute *cciss_dev_attrs[] = {
554 &dev_attr_unique_id.attr,
555 &dev_attr_model.attr,
556 &dev_attr_vendor.attr,
557 &dev_attr_rev.attr,
558 NULL
559};
560
561static struct attribute_group cciss_dev_attr_group = {
562 .attrs = cciss_dev_attrs,
563};
564
565static struct attribute_group *cciss_dev_attr_groups[] = {
566 &cciss_dev_attr_group,
567 NULL
568};
569
570static struct device_type cciss_dev_type = {
571 .name = "cciss_device",
572 .groups = cciss_dev_attr_groups,
573};
574
575static struct bus_type cciss_bus_type = {
576 .name = "cciss",
577};
578
579
580/*
581 * Initialize sysfs entry for each controller. This sets up and registers
582 * the 'cciss#' directory for each individual controller under
583 * /sys/bus/pci/devices/<dev>/.
584 */
585static int cciss_create_hba_sysfs_entry(struct ctlr_info *h)
586{
587 device_initialize(&h->dev);
588 h->dev.type = &cciss_host_type;
589 h->dev.bus = &cciss_bus_type;
590 dev_set_name(&h->dev, "%s", h->devname);
591 h->dev.parent = &h->pdev->dev;
592
593 return device_add(&h->dev);
594}
595
596/*
597 * Remove sysfs entries for an hba.
598 */
599static void cciss_destroy_hba_sysfs_entry(struct ctlr_info *h)
600{
601 device_del(&h->dev);
602}
603
604/*
605 * Initialize sysfs for each logical drive. This sets up and registers
606 * the 'c#d#' directory for each individual logical drive under
607 * /sys/bus/pci/devices/<dev/ccis#/. We also create a link from
608 * /sys/block/cciss!c#d# to this entry.
609 */
610static int cciss_create_ld_sysfs_entry(struct ctlr_info *h,
611 drive_info_struct *drv,
612 int drv_index)
613{
614 device_initialize(&drv->dev);
615 drv->dev.type = &cciss_dev_type;
616 drv->dev.bus = &cciss_bus_type;
617 dev_set_name(&drv->dev, "c%dd%d", h->ctlr, drv_index);
618 drv->dev.parent = &h->dev;
619 return device_add(&drv->dev);
620}
621
622/*
623 * Remove sysfs entries for a logical drive.
624 */
625static void cciss_destroy_ld_sysfs_entry(drive_info_struct *drv)
626{
627 device_del(&drv->dev);
628}
629
440/* 630/*
441 * For operations that cannot sleep, a command block is allocated at init, 631 * For operations that cannot sleep, a command block is allocated at init,
442 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track 632 * and managed by cmd_alloc() and cmd_free() using a simple bitmap to track
@@ -1299,7 +1489,6 @@ static void cciss_softirq_done(struct request *rq)
1299{ 1489{
1300 CommandList_struct *cmd = rq->completion_data; 1490 CommandList_struct *cmd = rq->completion_data;
1301 ctlr_info_t *h = hba[cmd->ctlr]; 1491 ctlr_info_t *h = hba[cmd->ctlr];
1302 unsigned int nr_bytes;
1303 unsigned long flags; 1492 unsigned long flags;
1304 u64bit temp64; 1493 u64bit temp64;
1305 int i, ddir; 1494 int i, ddir;
@@ -1321,15 +1510,11 @@ static void cciss_softirq_done(struct request *rq)
1321 printk("Done with %p\n", rq); 1510 printk("Done with %p\n", rq);
1322#endif /* CCISS_DEBUG */ 1511#endif /* CCISS_DEBUG */
1323 1512
1324 /* 1513 /* set the residual count for pc requests */
1325 * Store the full size and set the residual count for pc requests
1326 */
1327 nr_bytes = blk_rq_bytes(rq);
1328 if (blk_pc_request(rq)) 1514 if (blk_pc_request(rq))
1329 rq->data_len = cmd->err_info->ResidualCnt; 1515 rq->resid_len = cmd->err_info->ResidualCnt;
1330 1516
1331 if (blk_end_request(rq, (rq->errors == 0) ? 0 : -EIO, nr_bytes)) 1517 blk_end_request_all(rq, (rq->errors == 0) ? 0 : -EIO);
1332 BUG();
1333 1518
1334 spin_lock_irqsave(&h->lock, flags); 1519 spin_lock_irqsave(&h->lock, flags);
1335 cmd_free(h, cmd, 1); 1520 cmd_free(h, cmd, 1);
@@ -1337,6 +1522,56 @@ static void cciss_softirq_done(struct request *rq)
1337 spin_unlock_irqrestore(&h->lock, flags); 1522 spin_unlock_irqrestore(&h->lock, flags);
1338} 1523}
1339 1524
1525static void log_unit_to_scsi3addr(ctlr_info_t *h, unsigned char scsi3addr[],
1526 uint32_t log_unit)
1527{
1528 log_unit = h->drv[log_unit].LunID & 0x03fff;
1529 memset(&scsi3addr[4], 0, 4);
1530 memcpy(&scsi3addr[0], &log_unit, 4);
1531 scsi3addr[3] |= 0x40;
1532}
1533
1534/* This function gets the SCSI vendor, model, and revision of a logical drive
1535 * via the inquiry page 0. Model, vendor, and rev are set to empty strings if
1536 * they cannot be read.
1537 */
1538static void cciss_get_device_descr(int ctlr, int logvol, int withirq,
1539 char *vendor, char *model, char *rev)
1540{
1541 int rc;
1542 InquiryData_struct *inq_buf;
1543 unsigned char scsi3addr[8];
1544
1545 *vendor = '\0';
1546 *model = '\0';
1547 *rev = '\0';
1548
1549 inq_buf = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
1550 if (!inq_buf)
1551 return;
1552
1553 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
1554 if (withirq)
1555 rc = sendcmd_withirq(CISS_INQUIRY, ctlr, inq_buf,
1556 sizeof(InquiryData_struct), 0,
1557 scsi3addr, TYPE_CMD);
1558 else
1559 rc = sendcmd(CISS_INQUIRY, ctlr, inq_buf,
1560 sizeof(InquiryData_struct), 0,
1561 scsi3addr, TYPE_CMD);
1562 if (rc == IO_OK) {
1563 memcpy(vendor, &inq_buf->data_byte[8], VENDOR_LEN);
1564 vendor[VENDOR_LEN] = '\0';
1565 memcpy(model, &inq_buf->data_byte[16], MODEL_LEN);
1566 model[MODEL_LEN] = '\0';
1567 memcpy(rev, &inq_buf->data_byte[32], REV_LEN);
1568 rev[REV_LEN] = '\0';
1569 }
1570
1571 kfree(inq_buf);
1572 return;
1573}
1574
1340/* This function gets the serial number of a logical drive via 1575/* This function gets the serial number of a logical drive via
1341 * inquiry page 0x83. Serial no. is 16 bytes. If the serial 1576 * inquiry page 0x83. Serial no. is 16 bytes. If the serial
1342 * number cannot be had, for whatever reason, 16 bytes of 0xff 1577 * number cannot be had, for whatever reason, 16 bytes of 0xff
@@ -1348,6 +1583,7 @@ static void cciss_get_serial_no(int ctlr, int logvol, int withirq,
1348#define PAGE_83_INQ_BYTES 64 1583#define PAGE_83_INQ_BYTES 64
1349 int rc; 1584 int rc;
1350 unsigned char *buf; 1585 unsigned char *buf;
1586 unsigned char scsi3addr[8];
1351 1587
1352 if (buflen > 16) 1588 if (buflen > 16)
1353 buflen = 16; 1589 buflen = 16;
@@ -1356,12 +1592,13 @@ static void cciss_get_serial_no(int ctlr, int logvol, int withirq,
1356 if (!buf) 1592 if (!buf)
1357 return; 1593 return;
1358 memset(serial_no, 0, buflen); 1594 memset(serial_no, 0, buflen);
1595 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
1359 if (withirq) 1596 if (withirq)
1360 rc = sendcmd_withirq(CISS_INQUIRY, ctlr, buf, 1597 rc = sendcmd_withirq(CISS_INQUIRY, ctlr, buf,
1361 PAGE_83_INQ_BYTES, 1, logvol, 0x83, TYPE_CMD); 1598 PAGE_83_INQ_BYTES, 0x83, scsi3addr, TYPE_CMD);
1362 else 1599 else
1363 rc = sendcmd(CISS_INQUIRY, ctlr, buf, 1600 rc = sendcmd(CISS_INQUIRY, ctlr, buf,
1364 PAGE_83_INQ_BYTES, 1, logvol, 0x83, NULL, TYPE_CMD); 1601 PAGE_83_INQ_BYTES, 0x83, scsi3addr, TYPE_CMD);
1365 if (rc == IO_OK) 1602 if (rc == IO_OK)
1366 memcpy(serial_no, &buf[8], buflen); 1603 memcpy(serial_no, &buf[8], buflen);
1367 kfree(buf); 1604 kfree(buf);
@@ -1377,7 +1614,7 @@ static void cciss_add_disk(ctlr_info_t *h, struct gendisk *disk,
1377 disk->first_minor = drv_index << NWD_SHIFT; 1614 disk->first_minor = drv_index << NWD_SHIFT;
1378 disk->fops = &cciss_fops; 1615 disk->fops = &cciss_fops;
1379 disk->private_data = &h->drv[drv_index]; 1616 disk->private_data = &h->drv[drv_index];
1380 disk->driverfs_dev = &h->pdev->dev; 1617 disk->driverfs_dev = &h->drv[drv_index].dev;
1381 1618
1382 /* Set up queue information */ 1619 /* Set up queue information */
1383 blk_queue_bounce_limit(disk->queue, h->pdev->dma_mask); 1620 blk_queue_bounce_limit(disk->queue, h->pdev->dma_mask);
@@ -1394,8 +1631,8 @@ static void cciss_add_disk(ctlr_info_t *h, struct gendisk *disk,
1394 1631
1395 disk->queue->queuedata = h; 1632 disk->queue->queuedata = h;
1396 1633
1397 blk_queue_hardsect_size(disk->queue, 1634 blk_queue_logical_block_size(disk->queue,
1398 h->drv[drv_index].block_size); 1635 h->drv[drv_index].block_size);
1399 1636
1400 /* Make sure all queue data is written out before */ 1637 /* Make sure all queue data is written out before */
1401 /* setting h->drv[drv_index].queue, as setting this */ 1638 /* setting h->drv[drv_index].queue, as setting this */
@@ -1468,6 +1705,8 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time)
1468 drvinfo->block_size = block_size; 1705 drvinfo->block_size = block_size;
1469 drvinfo->nr_blocks = total_size + 1; 1706 drvinfo->nr_blocks = total_size + 1;
1470 1707
1708 cciss_get_device_descr(ctlr, drv_index, 1, drvinfo->vendor,
1709 drvinfo->model, drvinfo->rev);
1471 cciss_get_serial_no(ctlr, drv_index, 1, drvinfo->serial_no, 1710 cciss_get_serial_no(ctlr, drv_index, 1, drvinfo->serial_no,
1472 sizeof(drvinfo->serial_no)); 1711 sizeof(drvinfo->serial_no));
1473 1712
@@ -1517,6 +1756,9 @@ static void cciss_update_drive_info(int ctlr, int drv_index, int first_time)
1517 h->drv[drv_index].cylinders = drvinfo->cylinders; 1756 h->drv[drv_index].cylinders = drvinfo->cylinders;
1518 h->drv[drv_index].raid_level = drvinfo->raid_level; 1757 h->drv[drv_index].raid_level = drvinfo->raid_level;
1519 memcpy(h->drv[drv_index].serial_no, drvinfo->serial_no, 16); 1758 memcpy(h->drv[drv_index].serial_no, drvinfo->serial_no, 16);
1759 memcpy(h->drv[drv_index].vendor, drvinfo->vendor, VENDOR_LEN + 1);
1760 memcpy(h->drv[drv_index].model, drvinfo->model, MODEL_LEN + 1);
1761 memcpy(h->drv[drv_index].rev, drvinfo->rev, REV_LEN + 1);
1520 1762
1521 ++h->num_luns; 1763 ++h->num_luns;
1522 disk = h->gendisk[drv_index]; 1764 disk = h->gendisk[drv_index];
@@ -1591,6 +1833,8 @@ static int cciss_add_gendisk(ctlr_info_t *h, __u32 lunid, int controller_node)
1591 } 1833 }
1592 } 1834 }
1593 h->drv[drv_index].LunID = lunid; 1835 h->drv[drv_index].LunID = lunid;
1836 if (cciss_create_ld_sysfs_entry(h, &h->drv[drv_index], drv_index))
1837 goto err_free_disk;
1594 1838
1595 /* Don't need to mark this busy because nobody */ 1839 /* Don't need to mark this busy because nobody */
1596 /* else knows about this disk yet to contend */ 1840 /* else knows about this disk yet to contend */
@@ -1598,6 +1842,11 @@ static int cciss_add_gendisk(ctlr_info_t *h, __u32 lunid, int controller_node)
1598 h->drv[drv_index].busy_configuring = 0; 1842 h->drv[drv_index].busy_configuring = 0;
1599 wmb(); 1843 wmb();
1600 return drv_index; 1844 return drv_index;
1845
1846err_free_disk:
1847 put_disk(h->gendisk[drv_index]);
1848 h->gendisk[drv_index] = NULL;
1849 return -1;
1601} 1850}
1602 1851
1603/* This is for the special case of a controller which 1852/* This is for the special case of a controller which
@@ -1668,8 +1917,8 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time)
1668 goto mem_msg; 1917 goto mem_msg;
1669 1918
1670 return_code = sendcmd_withirq(CISS_REPORT_LOG, ctlr, ld_buff, 1919 return_code = sendcmd_withirq(CISS_REPORT_LOG, ctlr, ld_buff,
1671 sizeof(ReportLunData_struct), 0, 1920 sizeof(ReportLunData_struct),
1672 0, 0, TYPE_CMD); 1921 0, CTLR_LUNID, TYPE_CMD);
1673 1922
1674 if (return_code == IO_OK) 1923 if (return_code == IO_OK)
1675 listlength = be32_to_cpu(*(__be32 *) ld_buff->LUNListLength); 1924 listlength = be32_to_cpu(*(__be32 *) ld_buff->LUNListLength);
@@ -1718,6 +1967,7 @@ static int rebuild_lun_table(ctlr_info_t *h, int first_time)
1718 h->drv[i].busy_configuring = 1; 1967 h->drv[i].busy_configuring = 1;
1719 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags); 1968 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
1720 return_code = deregister_disk(h, i, 1); 1969 return_code = deregister_disk(h, i, 1);
1970 cciss_destroy_ld_sysfs_entry(&h->drv[i]);
1721 h->drv[i].busy_configuring = 0; 1971 h->drv[i].busy_configuring = 0;
1722 } 1972 }
1723 } 1973 }
@@ -1877,11 +2127,9 @@ static int deregister_disk(ctlr_info_t *h, int drv_index,
1877 return 0; 2127 return 0;
1878} 2128}
1879 2129
1880static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_t size, unsigned int use_unit_num, /* 0: address the controller, 2130static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff,
1881 1: address logical volume log_unit, 2131 size_t size, __u8 page_code, unsigned char *scsi3addr,
1882 2: periph device address is scsi3addr */ 2132 int cmd_type)
1883 unsigned int log_unit, __u8 page_code,
1884 unsigned char *scsi3addr, int cmd_type)
1885{ 2133{
1886 ctlr_info_t *h = hba[ctlr]; 2134 ctlr_info_t *h = hba[ctlr];
1887 u64bit buff_dma_handle; 2135 u64bit buff_dma_handle;
@@ -1897,27 +2145,12 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1897 c->Header.SGTotal = 0; 2145 c->Header.SGTotal = 0;
1898 } 2146 }
1899 c->Header.Tag.lower = c->busaddr; 2147 c->Header.Tag.lower = c->busaddr;
2148 memcpy(c->Header.LUN.LunAddrBytes, scsi3addr, 8);
1900 2149
1901 c->Request.Type.Type = cmd_type; 2150 c->Request.Type.Type = cmd_type;
1902 if (cmd_type == TYPE_CMD) { 2151 if (cmd_type == TYPE_CMD) {
1903 switch (cmd) { 2152 switch (cmd) {
1904 case CISS_INQUIRY: 2153 case CISS_INQUIRY:
1905 /* If the logical unit number is 0 then, this is going
1906 to controller so It's a physical command
1907 mode = 0 target = 0. So we have nothing to write.
1908 otherwise, if use_unit_num == 1,
1909 mode = 1(volume set addressing) target = LUNID
1910 otherwise, if use_unit_num == 2,
1911 mode = 0(periph dev addr) target = scsi3addr */
1912 if (use_unit_num == 1) {
1913 c->Header.LUN.LogDev.VolId =
1914 h->drv[log_unit].LunID;
1915 c->Header.LUN.LogDev.Mode = 1;
1916 } else if (use_unit_num == 2) {
1917 memcpy(c->Header.LUN.LunAddrBytes, scsi3addr,
1918 8);
1919 c->Header.LUN.LogDev.Mode = 0;
1920 }
1921 /* are we trying to read a vital product page */ 2154 /* are we trying to read a vital product page */
1922 if (page_code != 0) { 2155 if (page_code != 0) {
1923 c->Request.CDB[1] = 0x01; 2156 c->Request.CDB[1] = 0x01;
@@ -1947,8 +2180,6 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1947 break; 2180 break;
1948 2181
1949 case CCISS_READ_CAPACITY: 2182 case CCISS_READ_CAPACITY:
1950 c->Header.LUN.LogDev.VolId = h->drv[log_unit].LunID;
1951 c->Header.LUN.LogDev.Mode = 1;
1952 c->Request.CDBLen = 10; 2183 c->Request.CDBLen = 10;
1953 c->Request.Type.Attribute = ATTR_SIMPLE; 2184 c->Request.Type.Attribute = ATTR_SIMPLE;
1954 c->Request.Type.Direction = XFER_READ; 2185 c->Request.Type.Direction = XFER_READ;
@@ -1956,8 +2187,6 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1956 c->Request.CDB[0] = cmd; 2187 c->Request.CDB[0] = cmd;
1957 break; 2188 break;
1958 case CCISS_READ_CAPACITY_16: 2189 case CCISS_READ_CAPACITY_16:
1959 c->Header.LUN.LogDev.VolId = h->drv[log_unit].LunID;
1960 c->Header.LUN.LogDev.Mode = 1;
1961 c->Request.CDBLen = 16; 2190 c->Request.CDBLen = 16;
1962 c->Request.Type.Attribute = ATTR_SIMPLE; 2191 c->Request.Type.Attribute = ATTR_SIMPLE;
1963 c->Request.Type.Direction = XFER_READ; 2192 c->Request.Type.Direction = XFER_READ;
@@ -1979,6 +2208,12 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1979 c->Request.CDB[0] = BMIC_WRITE; 2208 c->Request.CDB[0] = BMIC_WRITE;
1980 c->Request.CDB[6] = BMIC_CACHE_FLUSH; 2209 c->Request.CDB[6] = BMIC_CACHE_FLUSH;
1981 break; 2210 break;
2211 case TEST_UNIT_READY:
2212 c->Request.CDBLen = 6;
2213 c->Request.Type.Attribute = ATTR_SIMPLE;
2214 c->Request.Type.Direction = XFER_NONE;
2215 c->Request.Timeout = 0;
2216 break;
1982 default: 2217 default:
1983 printk(KERN_WARNING 2218 printk(KERN_WARNING
1984 "cciss%d: Unknown Command 0x%c\n", ctlr, cmd); 2219 "cciss%d: Unknown Command 0x%c\n", ctlr, cmd);
@@ -1997,13 +2232,13 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
1997 memcpy(&c->Request.CDB[4], buff, 8); 2232 memcpy(&c->Request.CDB[4], buff, 8);
1998 break; 2233 break;
1999 case 1: /* RESET message */ 2234 case 1: /* RESET message */
2000 c->Request.CDBLen = 12; 2235 c->Request.CDBLen = 16;
2001 c->Request.Type.Attribute = ATTR_SIMPLE; 2236 c->Request.Type.Attribute = ATTR_SIMPLE;
2002 c->Request.Type.Direction = XFER_WRITE; 2237 c->Request.Type.Direction = XFER_NONE;
2003 c->Request.Timeout = 0; 2238 c->Request.Timeout = 0;
2004 memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB)); 2239 memset(&c->Request.CDB[0], 0, sizeof(c->Request.CDB));
2005 c->Request.CDB[0] = cmd; /* reset */ 2240 c->Request.CDB[0] = cmd; /* reset */
2006 c->Request.CDB[1] = 0x04; /* reset a LUN */ 2241 c->Request.CDB[1] = 0x03; /* reset a target */
2007 break; 2242 break;
2008 case 3: /* No-Op message */ 2243 case 3: /* No-Op message */
2009 c->Request.CDBLen = 1; 2244 c->Request.CDBLen = 1;
@@ -2035,114 +2270,152 @@ static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff, size_
2035 return status; 2270 return status;
2036} 2271}
2037 2272
2038static int sendcmd_withirq(__u8 cmd, 2273static int check_target_status(ctlr_info_t *h, CommandList_struct *c)
2039 int ctlr,
2040 void *buff,
2041 size_t size,
2042 unsigned int use_unit_num,
2043 unsigned int log_unit, __u8 page_code, int cmd_type)
2044{ 2274{
2045 ctlr_info_t *h = hba[ctlr]; 2275 switch (c->err_info->ScsiStatus) {
2046 CommandList_struct *c; 2276 case SAM_STAT_GOOD:
2277 return IO_OK;
2278 case SAM_STAT_CHECK_CONDITION:
2279 switch (0xf & c->err_info->SenseInfo[2]) {
2280 case 0: return IO_OK; /* no sense */
2281 case 1: return IO_OK; /* recovered error */
2282 default:
2283 printk(KERN_WARNING "cciss%d: cmd 0x%02x "
2284 "check condition, sense key = 0x%02x\n",
2285 h->ctlr, c->Request.CDB[0],
2286 c->err_info->SenseInfo[2]);
2287 }
2288 break;
2289 default:
2290 printk(KERN_WARNING "cciss%d: cmd 0x%02x"
2291 "scsi status = 0x%02x\n", h->ctlr,
2292 c->Request.CDB[0], c->err_info->ScsiStatus);
2293 break;
2294 }
2295 return IO_ERROR;
2296}
2297
2298static int process_sendcmd_error(ctlr_info_t *h, CommandList_struct *c)
2299{
2300 int return_status = IO_OK;
2301
2302 if (c->err_info->CommandStatus == CMD_SUCCESS)
2303 return IO_OK;
2304
2305 switch (c->err_info->CommandStatus) {
2306 case CMD_TARGET_STATUS:
2307 return_status = check_target_status(h, c);
2308 break;
2309 case CMD_DATA_UNDERRUN:
2310 case CMD_DATA_OVERRUN:
2311 /* expected for inquiry and report lun commands */
2312 break;
2313 case CMD_INVALID:
2314 printk(KERN_WARNING "cciss: cmd 0x%02x is "
2315 "reported invalid\n", c->Request.CDB[0]);
2316 return_status = IO_ERROR;
2317 break;
2318 case CMD_PROTOCOL_ERR:
2319 printk(KERN_WARNING "cciss: cmd 0x%02x has "
2320 "protocol error \n", c->Request.CDB[0]);
2321 return_status = IO_ERROR;
2322 break;
2323 case CMD_HARDWARE_ERR:
2324 printk(KERN_WARNING "cciss: cmd 0x%02x had "
2325 " hardware error\n", c->Request.CDB[0]);
2326 return_status = IO_ERROR;
2327 break;
2328 case CMD_CONNECTION_LOST:
2329 printk(KERN_WARNING "cciss: cmd 0x%02x had "
2330 "connection lost\n", c->Request.CDB[0]);
2331 return_status = IO_ERROR;
2332 break;
2333 case CMD_ABORTED:
2334 printk(KERN_WARNING "cciss: cmd 0x%02x was "
2335 "aborted\n", c->Request.CDB[0]);
2336 return_status = IO_ERROR;
2337 break;
2338 case CMD_ABORT_FAILED:
2339 printk(KERN_WARNING "cciss: cmd 0x%02x reports "
2340 "abort failed\n", c->Request.CDB[0]);
2341 return_status = IO_ERROR;
2342 break;
2343 case CMD_UNSOLICITED_ABORT:
2344 printk(KERN_WARNING
2345 "cciss%d: unsolicited abort 0x%02x\n", h->ctlr,
2346 c->Request.CDB[0]);
2347 return_status = IO_NEEDS_RETRY;
2348 break;
2349 default:
2350 printk(KERN_WARNING "cciss: cmd 0x%02x returned "
2351 "unknown status %x\n", c->Request.CDB[0],
2352 c->err_info->CommandStatus);
2353 return_status = IO_ERROR;
2354 }
2355 return return_status;
2356}
2357
2358static int sendcmd_withirq_core(ctlr_info_t *h, CommandList_struct *c,
2359 int attempt_retry)
2360{
2361 DECLARE_COMPLETION_ONSTACK(wait);
2047 u64bit buff_dma_handle; 2362 u64bit buff_dma_handle;
2048 unsigned long flags; 2363 unsigned long flags;
2049 int return_status; 2364 int return_status = IO_OK;
2050 DECLARE_COMPLETION_ONSTACK(wait);
2051 2365
2052 if ((c = cmd_alloc(h, 0)) == NULL) 2366resend_cmd2:
2053 return -ENOMEM;
2054 return_status = fill_cmd(c, cmd, ctlr, buff, size, use_unit_num,
2055 log_unit, page_code, NULL, cmd_type);
2056 if (return_status != IO_OK) {
2057 cmd_free(h, c, 0);
2058 return return_status;
2059 }
2060 resend_cmd2:
2061 c->waiting = &wait; 2367 c->waiting = &wait;
2062
2063 /* Put the request on the tail of the queue and send it */ 2368 /* Put the request on the tail of the queue and send it */
2064 spin_lock_irqsave(CCISS_LOCK(ctlr), flags); 2369 spin_lock_irqsave(CCISS_LOCK(h->ctlr), flags);
2065 addQ(&h->reqQ, c); 2370 addQ(&h->reqQ, c);
2066 h->Qdepth++; 2371 h->Qdepth++;
2067 start_io(h); 2372 start_io(h);
2068 spin_unlock_irqrestore(CCISS_LOCK(ctlr), flags); 2373 spin_unlock_irqrestore(CCISS_LOCK(h->ctlr), flags);
2069 2374
2070 wait_for_completion(&wait); 2375 wait_for_completion(&wait);
2071 2376
2072 if (c->err_info->CommandStatus != 0) { /* an error has occurred */ 2377 if (c->err_info->CommandStatus == 0 || !attempt_retry)
2073 switch (c->err_info->CommandStatus) { 2378 goto command_done;
2074 case CMD_TARGET_STATUS:
2075 printk(KERN_WARNING "cciss: cmd %p has "
2076 " completed with errors\n", c);
2077 if (c->err_info->ScsiStatus) {
2078 printk(KERN_WARNING "cciss: cmd %p "
2079 "has SCSI Status = %x\n",
2080 c, c->err_info->ScsiStatus);
2081 }
2082 2379
2083 break; 2380 return_status = process_sendcmd_error(h, c);
2084 case CMD_DATA_UNDERRUN: 2381
2085 case CMD_DATA_OVERRUN: 2382 if (return_status == IO_NEEDS_RETRY &&
2086 /* expected for inquire and report lun commands */ 2383 c->retry_count < MAX_CMD_RETRIES) {
2087 break; 2384 printk(KERN_WARNING "cciss%d: retrying 0x%02x\n", h->ctlr,
2088 case CMD_INVALID: 2385 c->Request.CDB[0]);
2089 printk(KERN_WARNING "cciss: Cmd %p is " 2386 c->retry_count++;
2090 "reported invalid\n", c); 2387 /* erase the old error information */
2091 return_status = IO_ERROR; 2388 memset(c->err_info, 0, sizeof(ErrorInfo_struct));
2092 break; 2389 return_status = IO_OK;
2093 case CMD_PROTOCOL_ERR: 2390 INIT_COMPLETION(wait);
2094 printk(KERN_WARNING "cciss: cmd %p has " 2391 goto resend_cmd2;
2095 "protocol error \n", c);
2096 return_status = IO_ERROR;
2097 break;
2098 case CMD_HARDWARE_ERR:
2099 printk(KERN_WARNING "cciss: cmd %p had "
2100 " hardware error\n", c);
2101 return_status = IO_ERROR;
2102 break;
2103 case CMD_CONNECTION_LOST:
2104 printk(KERN_WARNING "cciss: cmd %p had "
2105 "connection lost\n", c);
2106 return_status = IO_ERROR;
2107 break;
2108 case CMD_ABORTED:
2109 printk(KERN_WARNING "cciss: cmd %p was "
2110 "aborted\n", c);
2111 return_status = IO_ERROR;
2112 break;
2113 case CMD_ABORT_FAILED:
2114 printk(KERN_WARNING "cciss: cmd %p reports "
2115 "abort failed\n", c);
2116 return_status = IO_ERROR;
2117 break;
2118 case CMD_UNSOLICITED_ABORT:
2119 printk(KERN_WARNING
2120 "cciss%d: unsolicited abort %p\n", ctlr, c);
2121 if (c->retry_count < MAX_CMD_RETRIES) {
2122 printk(KERN_WARNING
2123 "cciss%d: retrying %p\n", ctlr, c);
2124 c->retry_count++;
2125 /* erase the old error information */
2126 memset(c->err_info, 0,
2127 sizeof(ErrorInfo_struct));
2128 return_status = IO_OK;
2129 INIT_COMPLETION(wait);
2130 goto resend_cmd2;
2131 }
2132 return_status = IO_ERROR;
2133 break;
2134 default:
2135 printk(KERN_WARNING "cciss: cmd %p returned "
2136 "unknown status %x\n", c,
2137 c->err_info->CommandStatus);
2138 return_status = IO_ERROR;
2139 }
2140 } 2392 }
2393
2394command_done:
2141 /* unlock the buffers from DMA */ 2395 /* unlock the buffers from DMA */
2142 buff_dma_handle.val32.lower = c->SG[0].Addr.lower; 2396 buff_dma_handle.val32.lower = c->SG[0].Addr.lower;
2143 buff_dma_handle.val32.upper = c->SG[0].Addr.upper; 2397 buff_dma_handle.val32.upper = c->SG[0].Addr.upper;
2144 pci_unmap_single(h->pdev, (dma_addr_t) buff_dma_handle.val, 2398 pci_unmap_single(h->pdev, (dma_addr_t) buff_dma_handle.val,
2145 c->SG[0].Len, PCI_DMA_BIDIRECTIONAL); 2399 c->SG[0].Len, PCI_DMA_BIDIRECTIONAL);
2400 return return_status;
2401}
2402
2403static int sendcmd_withirq(__u8 cmd, int ctlr, void *buff, size_t size,
2404 __u8 page_code, unsigned char scsi3addr[],
2405 int cmd_type)
2406{
2407 ctlr_info_t *h = hba[ctlr];
2408 CommandList_struct *c;
2409 int return_status;
2410
2411 c = cmd_alloc(h, 0);
2412 if (!c)
2413 return -ENOMEM;
2414 return_status = fill_cmd(c, cmd, ctlr, buff, size, page_code,
2415 scsi3addr, cmd_type);
2416 if (return_status == IO_OK)
2417 return_status = sendcmd_withirq_core(h, c, 1);
2418
2146 cmd_free(h, c, 0); 2419 cmd_free(h, c, 0);
2147 return return_status; 2420 return return_status;
2148} 2421}
@@ -2155,15 +2428,17 @@ static void cciss_geometry_inquiry(int ctlr, int logvol,
2155{ 2428{
2156 int return_code; 2429 int return_code;
2157 unsigned long t; 2430 unsigned long t;
2431 unsigned char scsi3addr[8];
2158 2432
2159 memset(inq_buff, 0, sizeof(InquiryData_struct)); 2433 memset(inq_buff, 0, sizeof(InquiryData_struct));
2434 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
2160 if (withirq) 2435 if (withirq)
2161 return_code = sendcmd_withirq(CISS_INQUIRY, ctlr, 2436 return_code = sendcmd_withirq(CISS_INQUIRY, ctlr,
2162 inq_buff, sizeof(*inq_buff), 1, 2437 inq_buff, sizeof(*inq_buff),
2163 logvol, 0xC1, TYPE_CMD); 2438 0xC1, scsi3addr, TYPE_CMD);
2164 else 2439 else
2165 return_code = sendcmd(CISS_INQUIRY, ctlr, inq_buff, 2440 return_code = sendcmd(CISS_INQUIRY, ctlr, inq_buff,
2166 sizeof(*inq_buff), 1, logvol, 0xC1, NULL, 2441 sizeof(*inq_buff), 0xC1, scsi3addr,
2167 TYPE_CMD); 2442 TYPE_CMD);
2168 if (return_code == IO_OK) { 2443 if (return_code == IO_OK) {
2169 if (inq_buff->data_byte[8] == 0xFF) { 2444 if (inq_buff->data_byte[8] == 0xFF) {
@@ -2204,6 +2479,7 @@ cciss_read_capacity(int ctlr, int logvol, int withirq, sector_t *total_size,
2204{ 2479{
2205 ReadCapdata_struct *buf; 2480 ReadCapdata_struct *buf;
2206 int return_code; 2481 int return_code;
2482 unsigned char scsi3addr[8];
2207 2483
2208 buf = kzalloc(sizeof(ReadCapdata_struct), GFP_KERNEL); 2484 buf = kzalloc(sizeof(ReadCapdata_struct), GFP_KERNEL);
2209 if (!buf) { 2485 if (!buf) {
@@ -2211,14 +2487,15 @@ cciss_read_capacity(int ctlr, int logvol, int withirq, sector_t *total_size,
2211 return; 2487 return;
2212 } 2488 }
2213 2489
2490 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
2214 if (withirq) 2491 if (withirq)
2215 return_code = sendcmd_withirq(CCISS_READ_CAPACITY, 2492 return_code = sendcmd_withirq(CCISS_READ_CAPACITY,
2216 ctlr, buf, sizeof(ReadCapdata_struct), 2493 ctlr, buf, sizeof(ReadCapdata_struct),
2217 1, logvol, 0, TYPE_CMD); 2494 0, scsi3addr, TYPE_CMD);
2218 else 2495 else
2219 return_code = sendcmd(CCISS_READ_CAPACITY, 2496 return_code = sendcmd(CCISS_READ_CAPACITY,
2220 ctlr, buf, sizeof(ReadCapdata_struct), 2497 ctlr, buf, sizeof(ReadCapdata_struct),
2221 1, logvol, 0, NULL, TYPE_CMD); 2498 0, scsi3addr, TYPE_CMD);
2222 if (return_code == IO_OK) { 2499 if (return_code == IO_OK) {
2223 *total_size = be32_to_cpu(*(__be32 *) buf->total_size); 2500 *total_size = be32_to_cpu(*(__be32 *) buf->total_size);
2224 *block_size = be32_to_cpu(*(__be32 *) buf->block_size); 2501 *block_size = be32_to_cpu(*(__be32 *) buf->block_size);
@@ -2238,6 +2515,7 @@ cciss_read_capacity_16(int ctlr, int logvol, int withirq, sector_t *total_size,
2238{ 2515{
2239 ReadCapdata_struct_16 *buf; 2516 ReadCapdata_struct_16 *buf;
2240 int return_code; 2517 int return_code;
2518 unsigned char scsi3addr[8];
2241 2519
2242 buf = kzalloc(sizeof(ReadCapdata_struct_16), GFP_KERNEL); 2520 buf = kzalloc(sizeof(ReadCapdata_struct_16), GFP_KERNEL);
2243 if (!buf) { 2521 if (!buf) {
@@ -2245,15 +2523,16 @@ cciss_read_capacity_16(int ctlr, int logvol, int withirq, sector_t *total_size,
2245 return; 2523 return;
2246 } 2524 }
2247 2525
2526 log_unit_to_scsi3addr(hba[ctlr], scsi3addr, logvol);
2248 if (withirq) { 2527 if (withirq) {
2249 return_code = sendcmd_withirq(CCISS_READ_CAPACITY_16, 2528 return_code = sendcmd_withirq(CCISS_READ_CAPACITY_16,
2250 ctlr, buf, sizeof(ReadCapdata_struct_16), 2529 ctlr, buf, sizeof(ReadCapdata_struct_16),
2251 1, logvol, 0, TYPE_CMD); 2530 0, scsi3addr, TYPE_CMD);
2252 } 2531 }
2253 else { 2532 else {
2254 return_code = sendcmd(CCISS_READ_CAPACITY_16, 2533 return_code = sendcmd(CCISS_READ_CAPACITY_16,
2255 ctlr, buf, sizeof(ReadCapdata_struct_16), 2534 ctlr, buf, sizeof(ReadCapdata_struct_16),
2256 1, logvol, 0, NULL, TYPE_CMD); 2535 0, scsi3addr, TYPE_CMD);
2257 } 2536 }
2258 if (return_code == IO_OK) { 2537 if (return_code == IO_OK) {
2259 *total_size = be64_to_cpu(*(__be64 *) buf->total_size); 2538 *total_size = be64_to_cpu(*(__be64 *) buf->total_size);
@@ -2303,7 +2582,7 @@ static int cciss_revalidate(struct gendisk *disk)
2303 cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size, 2582 cciss_geometry_inquiry(h->ctlr, logvol, 1, total_size, block_size,
2304 inq_buff, drv); 2583 inq_buff, drv);
2305 2584
2306 blk_queue_hardsect_size(drv->queue, drv->block_size); 2585 blk_queue_logical_block_size(drv->queue, drv->block_size);
2307 set_capacity(disk, drv->nr_blocks); 2586 set_capacity(disk, drv->nr_blocks);
2308 2587
2309 kfree(inq_buff); 2588 kfree(inq_buff);
@@ -2333,86 +2612,21 @@ static unsigned long pollcomplete(int ctlr)
2333 return 1; 2612 return 1;
2334} 2613}
2335 2614
2336static int add_sendcmd_reject(__u8 cmd, int ctlr, unsigned long complete) 2615/* Send command c to controller h and poll for it to complete.
2337{ 2616 * Turns interrupts off on the board. Used at driver init time
2338 /* We get in here if sendcmd() is polling for completions 2617 * and during SCSI error recovery.
2339 and gets some command back that it wasn't expecting --
2340 something other than that which it just sent down.
2341 Ordinarily, that shouldn't happen, but it can happen when
2342 the scsi tape stuff gets into error handling mode, and
2343 starts using sendcmd() to try to abort commands and
2344 reset tape drives. In that case, sendcmd may pick up
2345 completions of commands that were sent to logical drives
2346 through the block i/o system, or cciss ioctls completing, etc.
2347 In that case, we need to save those completions for later
2348 processing by the interrupt handler.
2349 */
2350
2351#ifdef CONFIG_CISS_SCSI_TAPE
2352 struct sendcmd_reject_list *srl = &hba[ctlr]->scsi_rejects;
2353
2354 /* If it's not the scsi tape stuff doing error handling, (abort */
2355 /* or reset) then we don't expect anything weird. */
2356 if (cmd != CCISS_RESET_MSG && cmd != CCISS_ABORT_MSG) {
2357#endif
2358 printk(KERN_WARNING "cciss cciss%d: SendCmd "
2359 "Invalid command list address returned! (%lx)\n",
2360 ctlr, complete);
2361 /* not much we can do. */
2362#ifdef CONFIG_CISS_SCSI_TAPE
2363 return 1;
2364 }
2365
2366 /* We've sent down an abort or reset, but something else
2367 has completed */
2368 if (srl->ncompletions >= (hba[ctlr]->nr_cmds + 2)) {
2369 /* Uh oh. No room to save it for later... */
2370 printk(KERN_WARNING "cciss%d: Sendcmd: Invalid command addr, "
2371 "reject list overflow, command lost!\n", ctlr);
2372 return 1;
2373 }
2374 /* Save it for later */
2375 srl->complete[srl->ncompletions] = complete;
2376 srl->ncompletions++;
2377#endif
2378 return 0;
2379}
2380
2381/*
2382 * Send a command to the controller, and wait for it to complete.
2383 * Only used at init time.
2384 */ 2618 */
2385static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size, unsigned int use_unit_num, /* 0: address the controller, 2619static int sendcmd_core(ctlr_info_t *h, CommandList_struct *c)
2386 1: address logical volume log_unit,
2387 2: periph device address is scsi3addr */
2388 unsigned int log_unit,
2389 __u8 page_code, unsigned char *scsi3addr, int cmd_type)
2390{ 2620{
2391 CommandList_struct *c;
2392 int i; 2621 int i;
2393 unsigned long complete; 2622 unsigned long complete;
2394 ctlr_info_t *info_p = hba[ctlr]; 2623 int status = IO_ERROR;
2395 u64bit buff_dma_handle; 2624 u64bit buff_dma_handle;
2396 int status, done = 0;
2397 2625
2398 if ((c = cmd_alloc(info_p, 1)) == NULL) { 2626resend_cmd1:
2399 printk(KERN_WARNING "cciss: unable to get memory"); 2627
2400 return IO_ERROR; 2628 /* Disable interrupt on the board. */
2401 } 2629 h->access.set_intr_mask(h, CCISS_INTR_OFF);
2402 status = fill_cmd(c, cmd, ctlr, buff, size, use_unit_num,
2403 log_unit, page_code, scsi3addr, cmd_type);
2404 if (status != IO_OK) {
2405 cmd_free(info_p, c, 1);
2406 return status;
2407 }
2408 resend_cmd1:
2409 /*
2410 * Disable interrupt
2411 */
2412#ifdef CCISS_DEBUG
2413 printk(KERN_DEBUG "cciss: turning intr off\n");
2414#endif /* CCISS_DEBUG */
2415 info_p->access.set_intr_mask(info_p, CCISS_INTR_OFF);
2416 2630
2417 /* Make sure there is room in the command FIFO */ 2631 /* Make sure there is room in the command FIFO */
2418 /* Actually it should be completely empty at this time */ 2632 /* Actually it should be completely empty at this time */
@@ -2420,21 +2634,15 @@ static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size, unsigned int use
2420 /* tape side of the driver. */ 2634 /* tape side of the driver. */
2421 for (i = 200000; i > 0; i--) { 2635 for (i = 200000; i > 0; i--) {
2422 /* if fifo isn't full go */ 2636 /* if fifo isn't full go */
2423 if (!(info_p->access.fifo_full(info_p))) { 2637 if (!(h->access.fifo_full(h)))
2424
2425 break; 2638 break;
2426 }
2427 udelay(10); 2639 udelay(10);
2428 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full," 2640 printk(KERN_WARNING "cciss cciss%d: SendCmd FIFO full,"
2429 " waiting!\n", ctlr); 2641 " waiting!\n", h->ctlr);
2430 } 2642 }
2431 /* 2643 h->access.submit_command(h, c); /* Send the cmd */
2432 * Send the cmd
2433 */
2434 info_p->access.submit_command(info_p, c);
2435 done = 0;
2436 do { 2644 do {
2437 complete = pollcomplete(ctlr); 2645 complete = pollcomplete(h->ctlr);
2438 2646
2439#ifdef CCISS_DEBUG 2647#ifdef CCISS_DEBUG
2440 printk(KERN_DEBUG "cciss: command completed\n"); 2648 printk(KERN_DEBUG "cciss: command completed\n");
@@ -2443,97 +2651,102 @@ static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size, unsigned int use
2443 if (complete == 1) { 2651 if (complete == 1) {
2444 printk(KERN_WARNING 2652 printk(KERN_WARNING
2445 "cciss cciss%d: SendCmd Timeout out, " 2653 "cciss cciss%d: SendCmd Timeout out, "
2446 "No command list address returned!\n", ctlr); 2654 "No command list address returned!\n", h->ctlr);
2447 status = IO_ERROR; 2655 status = IO_ERROR;
2448 done = 1;
2449 break; 2656 break;
2450 } 2657 }
2451 2658
2452 /* This will need to change for direct lookup completions */ 2659 /* Make sure it's the command we're expecting. */
2453 if ((complete & CISS_ERROR_BIT) 2660 if ((complete & ~CISS_ERROR_BIT) != c->busaddr) {
2454 && (complete & ~CISS_ERROR_BIT) == c->busaddr) { 2661 printk(KERN_WARNING "cciss%d: Unexpected command "
2455 /* if data overrun or underun on Report command 2662 "completion.\n", h->ctlr);
2456 ignore it 2663 continue;
2457 */ 2664 }
2458 if (((c->Request.CDB[0] == CISS_REPORT_LOG) || 2665
2459 (c->Request.CDB[0] == CISS_REPORT_PHYS) || 2666 /* It is our command. If no error, we're done. */
2460 (c->Request.CDB[0] == CISS_INQUIRY)) && 2667 if (!(complete & CISS_ERROR_BIT)) {
2461 ((c->err_info->CommandStatus == 2668 status = IO_OK;
2462 CMD_DATA_OVERRUN) || 2669 break;
2463 (c->err_info->CommandStatus == CMD_DATA_UNDERRUN)
2464 )) {
2465 complete = c->busaddr;
2466 } else {
2467 if (c->err_info->CommandStatus ==
2468 CMD_UNSOLICITED_ABORT) {
2469 printk(KERN_WARNING "cciss%d: "
2470 "unsolicited abort %p\n",
2471 ctlr, c);
2472 if (c->retry_count < MAX_CMD_RETRIES) {
2473 printk(KERN_WARNING
2474 "cciss%d: retrying %p\n",
2475 ctlr, c);
2476 c->retry_count++;
2477 /* erase the old error */
2478 /* information */
2479 memset(c->err_info, 0,
2480 sizeof
2481 (ErrorInfo_struct));
2482 goto resend_cmd1;
2483 } else {
2484 printk(KERN_WARNING
2485 "cciss%d: retried %p too "
2486 "many times\n", ctlr, c);
2487 status = IO_ERROR;
2488 goto cleanup1;
2489 }
2490 } else if (c->err_info->CommandStatus ==
2491 CMD_UNABORTABLE) {
2492 printk(KERN_WARNING
2493 "cciss%d: command could not be aborted.\n",
2494 ctlr);
2495 status = IO_ERROR;
2496 goto cleanup1;
2497 }
2498 printk(KERN_WARNING "ciss ciss%d: sendcmd"
2499 " Error %x \n", ctlr,
2500 c->err_info->CommandStatus);
2501 printk(KERN_WARNING "ciss ciss%d: sendcmd"
2502 " offensive info\n"
2503 " size %x\n num %x value %x\n",
2504 ctlr,
2505 c->err_info->MoreErrInfo.Invalid_Cmd.
2506 offense_size,
2507 c->err_info->MoreErrInfo.Invalid_Cmd.
2508 offense_num,
2509 c->err_info->MoreErrInfo.Invalid_Cmd.
2510 offense_value);
2511 status = IO_ERROR;
2512 goto cleanup1;
2513 }
2514 } 2670 }
2515 /* This will need changing for direct lookup completions */ 2671
2516 if (complete != c->busaddr) { 2672 /* There is an error... */
2517 if (add_sendcmd_reject(cmd, ctlr, complete) != 0) { 2673
2518 BUG(); /* we are pretty much hosed if we get here. */ 2674 /* if data overrun or underun on Report command ignore it */
2675 if (((c->Request.CDB[0] == CISS_REPORT_LOG) ||
2676 (c->Request.CDB[0] == CISS_REPORT_PHYS) ||
2677 (c->Request.CDB[0] == CISS_INQUIRY)) &&
2678 ((c->err_info->CommandStatus == CMD_DATA_OVERRUN) ||
2679 (c->err_info->CommandStatus == CMD_DATA_UNDERRUN))) {
2680 complete = c->busaddr;
2681 status = IO_OK;
2682 break;
2683 }
2684
2685 if (c->err_info->CommandStatus == CMD_UNSOLICITED_ABORT) {
2686 printk(KERN_WARNING "cciss%d: unsolicited abort %p\n",
2687 h->ctlr, c);
2688 if (c->retry_count < MAX_CMD_RETRIES) {
2689 printk(KERN_WARNING "cciss%d: retrying %p\n",
2690 h->ctlr, c);
2691 c->retry_count++;
2692 /* erase the old error information */
2693 memset(c->err_info, 0, sizeof(c->err_info));
2694 goto resend_cmd1;
2519 } 2695 }
2520 continue; 2696 printk(KERN_WARNING "cciss%d: retried %p too many "
2521 } else 2697 "times\n", h->ctlr, c);
2522 done = 1; 2698 status = IO_ERROR;
2523 } while (!done); 2699 break;
2700 }
2701
2702 if (c->err_info->CommandStatus == CMD_UNABORTABLE) {
2703 printk(KERN_WARNING "cciss%d: command could not be "
2704 "aborted.\n", h->ctlr);
2705 status = IO_ERROR;
2706 break;
2707 }
2708
2709 if (c->err_info->CommandStatus == CMD_TARGET_STATUS) {
2710 status = check_target_status(h, c);
2711 break;
2712 }
2713
2714 printk(KERN_WARNING "cciss%d: sendcmd error\n", h->ctlr);
2715 printk(KERN_WARNING "cmd = 0x%02x, CommandStatus = 0x%02x\n",
2716 c->Request.CDB[0], c->err_info->CommandStatus);
2717 status = IO_ERROR;
2718 break;
2719
2720 } while (1);
2524 2721
2525 cleanup1:
2526 /* unlock the data buffer from DMA */ 2722 /* unlock the data buffer from DMA */
2527 buff_dma_handle.val32.lower = c->SG[0].Addr.lower; 2723 buff_dma_handle.val32.lower = c->SG[0].Addr.lower;
2528 buff_dma_handle.val32.upper = c->SG[0].Addr.upper; 2724 buff_dma_handle.val32.upper = c->SG[0].Addr.upper;
2529 pci_unmap_single(info_p->pdev, (dma_addr_t) buff_dma_handle.val, 2725 pci_unmap_single(h->pdev, (dma_addr_t) buff_dma_handle.val,
2530 c->SG[0].Len, PCI_DMA_BIDIRECTIONAL); 2726 c->SG[0].Len, PCI_DMA_BIDIRECTIONAL);
2531#ifdef CONFIG_CISS_SCSI_TAPE 2727 return status;
2532 /* if we saved some commands for later, process them now. */ 2728}
2533 if (info_p->scsi_rejects.ncompletions > 0) 2729
2534 do_cciss_intr(0, info_p); 2730/*
2535#endif 2731 * Send a command to the controller, and wait for it to complete.
2536 cmd_free(info_p, c, 1); 2732 * Used at init time, and during SCSI error recovery.
2733 */
2734static int sendcmd(__u8 cmd, int ctlr, void *buff, size_t size,
2735 __u8 page_code, unsigned char *scsi3addr, int cmd_type)
2736{
2737 CommandList_struct *c;
2738 int status;
2739
2740 c = cmd_alloc(hba[ctlr], 1);
2741 if (!c) {
2742 printk(KERN_WARNING "cciss: unable to get memory");
2743 return IO_ERROR;
2744 }
2745 status = fill_cmd(c, cmd, ctlr, buff, size, page_code,
2746 scsi3addr, cmd_type);
2747 if (status == IO_OK)
2748 status = sendcmd_core(hba[ctlr], c);
2749 cmd_free(hba[ctlr], c, 1);
2537 return status; 2750 return status;
2538} 2751}
2539 2752
@@ -2691,7 +2904,7 @@ static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd,
2691 printk(KERN_WARNING "cciss: cmd %p has" 2904 printk(KERN_WARNING "cciss: cmd %p has"
2692 " completed with data underrun " 2905 " completed with data underrun "
2693 "reported\n", cmd); 2906 "reported\n", cmd);
2694 cmd->rq->data_len = cmd->err_info->ResidualCnt; 2907 cmd->rq->resid_len = cmd->err_info->ResidualCnt;
2695 } 2908 }
2696 break; 2909 break;
2697 case CMD_DATA_OVERRUN: 2910 case CMD_DATA_OVERRUN:
@@ -2806,7 +3019,7 @@ static void do_cciss_request(struct request_queue *q)
2806 goto startio; 3019 goto startio;
2807 3020
2808 queue: 3021 queue:
2809 creq = elv_next_request(q); 3022 creq = blk_peek_request(q);
2810 if (!creq) 3023 if (!creq)
2811 goto startio; 3024 goto startio;
2812 3025
@@ -2815,7 +3028,7 @@ static void do_cciss_request(struct request_queue *q)
2815 if ((c = cmd_alloc(h, 1)) == NULL) 3028 if ((c = cmd_alloc(h, 1)) == NULL)
2816 goto full; 3029 goto full;
2817 3030
2818 blkdev_dequeue_request(creq); 3031 blk_start_request(creq);
2819 3032
2820 spin_unlock_irq(q->queue_lock); 3033 spin_unlock_irq(q->queue_lock);
2821 3034
@@ -2840,10 +3053,10 @@ static void do_cciss_request(struct request_queue *q)
2840 c->Request.Timeout = 0; // Don't time out 3053 c->Request.Timeout = 0; // Don't time out
2841 c->Request.CDB[0] = 3054 c->Request.CDB[0] =
2842 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write; 3055 (rq_data_dir(creq) == READ) ? h->cciss_read : h->cciss_write;
2843 start_blk = creq->sector; 3056 start_blk = blk_rq_pos(creq);
2844#ifdef CCISS_DEBUG 3057#ifdef CCISS_DEBUG
2845 printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n", (int)creq->sector, 3058 printk(KERN_DEBUG "ciss: sector =%d nr_sectors=%d\n",
2846 (int)creq->nr_sectors); 3059 (int)blk_rq_pos(creq), (int)blk_rq_sectors(creq));
2847#endif /* CCISS_DEBUG */ 3060#endif /* CCISS_DEBUG */
2848 3061
2849 sg_init_table(tmp_sg, MAXSGENTRIES); 3062 sg_init_table(tmp_sg, MAXSGENTRIES);
@@ -2869,8 +3082,8 @@ static void do_cciss_request(struct request_queue *q)
2869 h->maxSG = seg; 3082 h->maxSG = seg;
2870 3083
2871#ifdef CCISS_DEBUG 3084#ifdef CCISS_DEBUG
2872 printk(KERN_DEBUG "cciss: Submitting %lu sectors in %d segments\n", 3085 printk(KERN_DEBUG "cciss: Submitting %u sectors in %d segments\n",
2873 creq->nr_sectors, seg); 3086 blk_rq_sectors(creq), seg);
2874#endif /* CCISS_DEBUG */ 3087#endif /* CCISS_DEBUG */
2875 3088
2876 c->Header.SGList = c->Header.SGTotal = seg; 3089 c->Header.SGList = c->Header.SGTotal = seg;
@@ -2882,8 +3095,8 @@ static void do_cciss_request(struct request_queue *q)
2882 c->Request.CDB[4] = (start_blk >> 8) & 0xff; 3095 c->Request.CDB[4] = (start_blk >> 8) & 0xff;
2883 c->Request.CDB[5] = start_blk & 0xff; 3096 c->Request.CDB[5] = start_blk & 0xff;
2884 c->Request.CDB[6] = 0; // (sect >> 24) & 0xff; MSB 3097 c->Request.CDB[6] = 0; // (sect >> 24) & 0xff; MSB
2885 c->Request.CDB[7] = (creq->nr_sectors >> 8) & 0xff; 3098 c->Request.CDB[7] = (blk_rq_sectors(creq) >> 8) & 0xff;
2886 c->Request.CDB[8] = creq->nr_sectors & 0xff; 3099 c->Request.CDB[8] = blk_rq_sectors(creq) & 0xff;
2887 c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0; 3100 c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0;
2888 } else { 3101 } else {
2889 u32 upper32 = upper_32_bits(start_blk); 3102 u32 upper32 = upper_32_bits(start_blk);
@@ -2898,10 +3111,10 @@ static void do_cciss_request(struct request_queue *q)
2898 c->Request.CDB[7]= (start_blk >> 16) & 0xff; 3111 c->Request.CDB[7]= (start_blk >> 16) & 0xff;
2899 c->Request.CDB[8]= (start_blk >> 8) & 0xff; 3112 c->Request.CDB[8]= (start_blk >> 8) & 0xff;
2900 c->Request.CDB[9]= start_blk & 0xff; 3113 c->Request.CDB[9]= start_blk & 0xff;
2901 c->Request.CDB[10]= (creq->nr_sectors >> 24) & 0xff; 3114 c->Request.CDB[10]= (blk_rq_sectors(creq) >> 24) & 0xff;
2902 c->Request.CDB[11]= (creq->nr_sectors >> 16) & 0xff; 3115 c->Request.CDB[11]= (blk_rq_sectors(creq) >> 16) & 0xff;
2903 c->Request.CDB[12]= (creq->nr_sectors >> 8) & 0xff; 3116 c->Request.CDB[12]= (blk_rq_sectors(creq) >> 8) & 0xff;
2904 c->Request.CDB[13]= creq->nr_sectors & 0xff; 3117 c->Request.CDB[13]= blk_rq_sectors(creq) & 0xff;
2905 c->Request.CDB[14] = c->Request.CDB[15] = 0; 3118 c->Request.CDB[14] = c->Request.CDB[15] = 0;
2906 } 3119 }
2907 } else if (blk_pc_request(creq)) { 3120 } else if (blk_pc_request(creq)) {
@@ -2931,44 +3144,18 @@ startio:
2931 3144
2932static inline unsigned long get_next_completion(ctlr_info_t *h) 3145static inline unsigned long get_next_completion(ctlr_info_t *h)
2933{ 3146{
2934#ifdef CONFIG_CISS_SCSI_TAPE
2935 /* Any rejects from sendcmd() lying around? Process them first */
2936 if (h->scsi_rejects.ncompletions == 0)
2937 return h->access.command_completed(h);
2938 else {
2939 struct sendcmd_reject_list *srl;
2940 int n;
2941 srl = &h->scsi_rejects;
2942 n = --srl->ncompletions;
2943 /* printk("cciss%d: processing saved reject\n", h->ctlr); */
2944 printk("p");
2945 return srl->complete[n];
2946 }
2947#else
2948 return h->access.command_completed(h); 3147 return h->access.command_completed(h);
2949#endif
2950} 3148}
2951 3149
2952static inline int interrupt_pending(ctlr_info_t *h) 3150static inline int interrupt_pending(ctlr_info_t *h)
2953{ 3151{
2954#ifdef CONFIG_CISS_SCSI_TAPE
2955 return (h->access.intr_pending(h)
2956 || (h->scsi_rejects.ncompletions > 0));
2957#else
2958 return h->access.intr_pending(h); 3152 return h->access.intr_pending(h);
2959#endif
2960} 3153}
2961 3154
2962static inline long interrupt_not_for_us(ctlr_info_t *h) 3155static inline long interrupt_not_for_us(ctlr_info_t *h)
2963{ 3156{
2964#ifdef CONFIG_CISS_SCSI_TAPE
2965 return (((h->access.intr_pending(h) == 0) ||
2966 (h->interrupts_enabled == 0))
2967 && (h->scsi_rejects.ncompletions == 0));
2968#else
2969 return (((h->access.intr_pending(h) == 0) || 3157 return (((h->access.intr_pending(h) == 0) ||
2970 (h->interrupts_enabled == 0))); 3158 (h->interrupts_enabled == 0)));
2971#endif
2972} 3159}
2973 3160
2974static irqreturn_t do_cciss_intr(int irq, void *dev_id) 3161static irqreturn_t do_cciss_intr(int irq, void *dev_id)
@@ -3723,12 +3910,15 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3723 INIT_HLIST_HEAD(&hba[i]->reqQ); 3910 INIT_HLIST_HEAD(&hba[i]->reqQ);
3724 3911
3725 if (cciss_pci_init(hba[i], pdev) != 0) 3912 if (cciss_pci_init(hba[i], pdev) != 0)
3726 goto clean1; 3913 goto clean0;
3727 3914
3728 sprintf(hba[i]->devname, "cciss%d", i); 3915 sprintf(hba[i]->devname, "cciss%d", i);
3729 hba[i]->ctlr = i; 3916 hba[i]->ctlr = i;
3730 hba[i]->pdev = pdev; 3917 hba[i]->pdev = pdev;
3731 3918
3919 if (cciss_create_hba_sysfs_entry(hba[i]))
3920 goto clean0;
3921
3732 /* configure PCI DMA stuff */ 3922 /* configure PCI DMA stuff */
3733 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) 3923 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)))
3734 dac = 1; 3924 dac = 1;
@@ -3787,15 +3977,6 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3787 printk(KERN_ERR "cciss: out of memory"); 3977 printk(KERN_ERR "cciss: out of memory");
3788 goto clean4; 3978 goto clean4;
3789 } 3979 }
3790#ifdef CONFIG_CISS_SCSI_TAPE
3791 hba[i]->scsi_rejects.complete =
3792 kmalloc(sizeof(hba[i]->scsi_rejects.complete[0]) *
3793 (hba[i]->nr_cmds + 5), GFP_KERNEL);
3794 if (hba[i]->scsi_rejects.complete == NULL) {
3795 printk(KERN_ERR "cciss: out of memory");
3796 goto clean4;
3797 }
3798#endif
3799 spin_lock_init(&hba[i]->lock); 3980 spin_lock_init(&hba[i]->lock);
3800 3981
3801 /* Initialize the pdev driver private data. 3982 /* Initialize the pdev driver private data.
@@ -3828,7 +4009,7 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3828 } 4009 }
3829 4010
3830 return_code = sendcmd_withirq(CISS_INQUIRY, i, inq_buff, 4011 return_code = sendcmd_withirq(CISS_INQUIRY, i, inq_buff,
3831 sizeof(InquiryData_struct), 0, 0 , 0, TYPE_CMD); 4012 sizeof(InquiryData_struct), 0, CTLR_LUNID, TYPE_CMD);
3832 if (return_code == IO_OK) { 4013 if (return_code == IO_OK) {
3833 hba[i]->firm_ver[0] = inq_buff->data_byte[32]; 4014 hba[i]->firm_ver[0] = inq_buff->data_byte[32];
3834 hba[i]->firm_ver[1] = inq_buff->data_byte[33]; 4015 hba[i]->firm_ver[1] = inq_buff->data_byte[33];
@@ -3855,9 +4036,6 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3855 4036
3856clean4: 4037clean4:
3857 kfree(inq_buff); 4038 kfree(inq_buff);
3858#ifdef CONFIG_CISS_SCSI_TAPE
3859 kfree(hba[i]->scsi_rejects.complete);
3860#endif
3861 kfree(hba[i]->cmd_pool_bits); 4039 kfree(hba[i]->cmd_pool_bits);
3862 if (hba[i]->cmd_pool) 4040 if (hba[i]->cmd_pool)
3863 pci_free_consistent(hba[i]->pdev, 4041 pci_free_consistent(hba[i]->pdev,
@@ -3872,6 +4050,8 @@ clean4:
3872clean2: 4050clean2:
3873 unregister_blkdev(hba[i]->major, hba[i]->devname); 4051 unregister_blkdev(hba[i]->major, hba[i]->devname);
3874clean1: 4052clean1:
4053 cciss_destroy_hba_sysfs_entry(hba[i]);
4054clean0:
3875 hba[i]->busy_initializing = 0; 4055 hba[i]->busy_initializing = 0;
3876 /* cleanup any queues that may have been initialized */ 4056 /* cleanup any queues that may have been initialized */
3877 for (j=0; j <= hba[i]->highest_lun; j++){ 4057 for (j=0; j <= hba[i]->highest_lun; j++){
@@ -3907,8 +4087,8 @@ static void cciss_shutdown(struct pci_dev *pdev)
3907 /* sendcmd will turn off interrupt, and send the flush... 4087 /* sendcmd will turn off interrupt, and send the flush...
3908 * To write all data in the battery backed cache to disks */ 4088 * To write all data in the battery backed cache to disks */
3909 memset(flush_buf, 0, 4); 4089 memset(flush_buf, 0, 4);
3910 return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4, 0, 0, 0, NULL, 4090 return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4, 0,
3911 TYPE_CMD); 4091 CTLR_LUNID, TYPE_CMD);
3912 if (return_code == IO_OK) { 4092 if (return_code == IO_OK) {
3913 printk(KERN_INFO "Completed flushing cache on controller %d\n", i); 4093 printk(KERN_INFO "Completed flushing cache on controller %d\n", i);
3914 } else { 4094 } else {
@@ -3973,15 +4153,13 @@ static void __devexit cciss_remove_one(struct pci_dev *pdev)
3973 pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(ErrorInfo_struct), 4153 pci_free_consistent(hba[i]->pdev, hba[i]->nr_cmds * sizeof(ErrorInfo_struct),
3974 hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle); 4154 hba[i]->errinfo_pool, hba[i]->errinfo_pool_dhandle);
3975 kfree(hba[i]->cmd_pool_bits); 4155 kfree(hba[i]->cmd_pool_bits);
3976#ifdef CONFIG_CISS_SCSI_TAPE
3977 kfree(hba[i]->scsi_rejects.complete);
3978#endif
3979 /* 4156 /*
3980 * Deliberately omit pci_disable_device(): it does something nasty to 4157 * Deliberately omit pci_disable_device(): it does something nasty to
3981 * Smart Array controllers that pci_enable_device does not undo 4158 * Smart Array controllers that pci_enable_device does not undo
3982 */ 4159 */
3983 pci_release_regions(pdev); 4160 pci_release_regions(pdev);
3984 pci_set_drvdata(pdev, NULL); 4161 pci_set_drvdata(pdev, NULL);
4162 cciss_destroy_hba_sysfs_entry(hba[i]);
3985 free_hba(i); 4163 free_hba(i);
3986} 4164}
3987 4165
@@ -3999,6 +4177,8 @@ static struct pci_driver cciss_pci_driver = {
3999 */ 4177 */
4000static int __init cciss_init(void) 4178static int __init cciss_init(void)
4001{ 4179{
4180 int err;
4181
4002 /* 4182 /*
4003 * The hardware requires that commands are aligned on a 64-bit 4183 * The hardware requires that commands are aligned on a 64-bit
4004 * boundary. Given that we use pci_alloc_consistent() to allocate an 4184 * boundary. Given that we use pci_alloc_consistent() to allocate an
@@ -4008,8 +4188,20 @@ static int __init cciss_init(void)
4008 4188
4009 printk(KERN_INFO DRIVER_NAME "\n"); 4189 printk(KERN_INFO DRIVER_NAME "\n");
4010 4190
4191 err = bus_register(&cciss_bus_type);
4192 if (err)
4193 return err;
4194
4011 /* Register for our PCI devices */ 4195 /* Register for our PCI devices */
4012 return pci_register_driver(&cciss_pci_driver); 4196 err = pci_register_driver(&cciss_pci_driver);
4197 if (err)
4198 goto err_bus_register;
4199
4200 return 0;
4201
4202err_bus_register:
4203 bus_unregister(&cciss_bus_type);
4204 return err;
4013} 4205}
4014 4206
4015static void __exit cciss_cleanup(void) 4207static void __exit cciss_cleanup(void)
@@ -4026,6 +4218,7 @@ static void __exit cciss_cleanup(void)
4026 } 4218 }
4027 } 4219 }
4028 remove_proc_entry("driver/cciss", NULL); 4220 remove_proc_entry("driver/cciss", NULL);
4221 bus_unregister(&cciss_bus_type);
4029} 4222}
4030 4223
4031static void fail_all_cmds(unsigned long ctlr) 4224static void fail_all_cmds(unsigned long ctlr)
diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
index 703e08038fb9..06a5db25b298 100644
--- a/drivers/block/cciss.h
+++ b/drivers/block/cciss.h
@@ -11,6 +11,11 @@
11 11
12#define IO_OK 0 12#define IO_OK 0
13#define IO_ERROR 1 13#define IO_ERROR 1
14#define IO_NEEDS_RETRY 3
15
16#define VENDOR_LEN 8
17#define MODEL_LEN 16
18#define REV_LEN 4
14 19
15struct ctlr_info; 20struct ctlr_info;
16typedef struct ctlr_info ctlr_info_t; 21typedef struct ctlr_info ctlr_info_t;
@@ -34,23 +39,20 @@ typedef struct _drive_info_struct
34 int cylinders; 39 int cylinders;
35 int raid_level; /* set to -1 to indicate that 40 int raid_level; /* set to -1 to indicate that
36 * the drive is not in use/configured 41 * the drive is not in use/configured
37 */ 42 */
38 int busy_configuring; /*This is set when the drive is being removed 43 int busy_configuring; /* This is set when a drive is being removed
39 *to prevent it from being opened or it's queue 44 * to prevent it from being opened or it's
40 *from being started. 45 * queue from being started.
41 */ 46 */
42 __u8 serial_no[16]; /* from inquiry page 0x83, */ 47 struct device dev;
43 /* not necc. null terminated. */ 48 __u8 serial_no[16]; /* from inquiry page 0x83,
49 * not necc. null terminated.
50 */
51 char vendor[VENDOR_LEN + 1]; /* SCSI vendor string */
52 char model[MODEL_LEN + 1]; /* SCSI model string */
53 char rev[REV_LEN + 1]; /* SCSI revision string */
44} drive_info_struct; 54} drive_info_struct;
45 55
46#ifdef CONFIG_CISS_SCSI_TAPE
47
48struct sendcmd_reject_list {
49 int ncompletions;
50 unsigned long *complete; /* array of NR_CMDS tags */
51};
52
53#endif
54struct ctlr_info 56struct ctlr_info
55{ 57{
56 int ctlr; 58 int ctlr;
@@ -118,11 +120,11 @@ struct ctlr_info
118 void *scsi_ctlr; /* ptr to structure containing scsi related stuff */ 120 void *scsi_ctlr; /* ptr to structure containing scsi related stuff */
119 /* list of block side commands the scsi error handling sucked up */ 121 /* list of block side commands the scsi error handling sucked up */
120 /* and saved for later processing */ 122 /* and saved for later processing */
121 struct sendcmd_reject_list scsi_rejects;
122#endif 123#endif
123 unsigned char alive; 124 unsigned char alive;
124 struct completion *rescan_wait; 125 struct completion *rescan_wait;
125 struct task_struct *cciss_scan_thread; 126 struct task_struct *cciss_scan_thread;
127 struct device dev;
126}; 128};
127 129
128/* Defining the diffent access_menthods */ 130/* Defining the diffent access_menthods */
diff --git a/drivers/block/cciss_cmd.h b/drivers/block/cciss_cmd.h
index 40b1b92dae7f..cd665b00c7c5 100644
--- a/drivers/block/cciss_cmd.h
+++ b/drivers/block/cciss_cmd.h
@@ -217,6 +217,8 @@ typedef union _LUNAddr_struct {
217 LogDevAddr_struct LogDev; 217 LogDevAddr_struct LogDev;
218} LUNAddr_struct; 218} LUNAddr_struct;
219 219
220#define CTLR_LUNID "\0\0\0\0\0\0\0\0"
221
220typedef struct _CommandListHeader_struct { 222typedef struct _CommandListHeader_struct {
221 BYTE ReplyQueue; 223 BYTE ReplyQueue;
222 BYTE SGList; 224 BYTE SGList;
diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c
index a3fd87b41444..3315268b4ec7 100644
--- a/drivers/block/cciss_scsi.c
+++ b/drivers/block/cciss_scsi.c
@@ -44,20 +44,13 @@
44#define CCISS_ABORT_MSG 0x00 44#define CCISS_ABORT_MSG 0x00
45#define CCISS_RESET_MSG 0x01 45#define CCISS_RESET_MSG 0x01
46 46
47/* some prototypes... */ 47static int fill_cmd(CommandList_struct *c, __u8 cmd, int ctlr, void *buff,
48static int sendcmd( 48 size_t size,
49 __u8 cmd, 49 __u8 page_code, unsigned char *scsi3addr,
50 int ctlr,
51 void *buff,
52 size_t size,
53 unsigned int use_unit_num, /* 0: address the controller,
54 1: address logical volume log_unit,
55 2: address is in scsi3addr */
56 unsigned int log_unit,
57 __u8 page_code,
58 unsigned char *scsi3addr,
59 int cmd_type); 50 int cmd_type);
60 51
52static CommandList_struct *cmd_alloc(ctlr_info_t *h, int get_from_pool);
53static void cmd_free(ctlr_info_t *h, CommandList_struct *c, int got_from_pool);
61 54
62static int cciss_scsi_proc_info( 55static int cciss_scsi_proc_info(
63 struct Scsi_Host *sh, 56 struct Scsi_Host *sh,
@@ -1575,6 +1568,75 @@ cciss_seq_tape_report(struct seq_file *seq, int ctlr)
1575 CPQ_TAPE_UNLOCK(ctlr, flags); 1568 CPQ_TAPE_UNLOCK(ctlr, flags);
1576} 1569}
1577 1570
1571static int wait_for_device_to_become_ready(ctlr_info_t *h,
1572 unsigned char lunaddr[])
1573{
1574 int rc;
1575 int count = 0;
1576 int waittime = HZ;
1577 CommandList_struct *c;
1578
1579 c = cmd_alloc(h, 1);
1580 if (!c) {
1581 printk(KERN_WARNING "cciss%d: out of memory in "
1582 "wait_for_device_to_become_ready.\n", h->ctlr);
1583 return IO_ERROR;
1584 }
1585
1586 /* Send test unit ready until device ready, or give up. */
1587 while (count < 20) {
1588
1589 /* Wait for a bit. do this first, because if we send
1590 * the TUR right away, the reset will just abort it.
1591 */
1592 schedule_timeout_uninterruptible(waittime);
1593 count++;
1594
1595 /* Increase wait time with each try, up to a point. */
1596 if (waittime < (HZ * 30))
1597 waittime = waittime * 2;
1598
1599 /* Send the Test Unit Ready */
1600 rc = fill_cmd(c, TEST_UNIT_READY, h->ctlr, NULL, 0, 0,
1601 lunaddr, TYPE_CMD);
1602 if (rc == 0)
1603 rc = sendcmd_withirq_core(h, c, 0);
1604
1605 (void) process_sendcmd_error(h, c);
1606
1607 if (rc != 0)
1608 goto retry_tur;
1609
1610 if (c->err_info->CommandStatus == CMD_SUCCESS)
1611 break;
1612
1613 if (c->err_info->CommandStatus == CMD_TARGET_STATUS &&
1614 c->err_info->ScsiStatus == SAM_STAT_CHECK_CONDITION) {
1615 if (c->err_info->SenseInfo[2] == NO_SENSE)
1616 break;
1617 if (c->err_info->SenseInfo[2] == UNIT_ATTENTION) {
1618 unsigned char asc;
1619 asc = c->err_info->SenseInfo[12];
1620 check_for_unit_attention(h, c);
1621 if (asc == POWER_OR_RESET)
1622 break;
1623 }
1624 }
1625retry_tur:
1626 printk(KERN_WARNING "cciss%d: Waiting %d secs "
1627 "for device to become ready.\n",
1628 h->ctlr, waittime / HZ);
1629 rc = 1; /* device not ready. */
1630 }
1631
1632 if (rc)
1633 printk("cciss%d: giving up on device.\n", h->ctlr);
1634 else
1635 printk(KERN_WARNING "cciss%d: device is ready.\n", h->ctlr);
1636
1637 cmd_free(h, c, 1);
1638 return rc;
1639}
1578 1640
1579/* Need at least one of these error handlers to keep ../scsi/hosts.c from 1641/* Need at least one of these error handlers to keep ../scsi/hosts.c from
1580 * complaining. Doing a host- or bus-reset can't do anything good here. 1642 * complaining. Doing a host- or bus-reset can't do anything good here.
@@ -1591,6 +1653,7 @@ static int cciss_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
1591{ 1653{
1592 int rc; 1654 int rc;
1593 CommandList_struct *cmd_in_trouble; 1655 CommandList_struct *cmd_in_trouble;
1656 unsigned char lunaddr[8];
1594 ctlr_info_t **c; 1657 ctlr_info_t **c;
1595 int ctlr; 1658 int ctlr;
1596 1659
@@ -1600,19 +1663,15 @@ static int cciss_eh_device_reset_handler(struct scsi_cmnd *scsicmd)
1600 return FAILED; 1663 return FAILED;
1601 ctlr = (*c)->ctlr; 1664 ctlr = (*c)->ctlr;
1602 printk(KERN_WARNING "cciss%d: resetting tape drive or medium changer.\n", ctlr); 1665 printk(KERN_WARNING "cciss%d: resetting tape drive or medium changer.\n", ctlr);
1603
1604 /* find the command that's giving us trouble */ 1666 /* find the command that's giving us trouble */
1605 cmd_in_trouble = (CommandList_struct *) scsicmd->host_scribble; 1667 cmd_in_trouble = (CommandList_struct *) scsicmd->host_scribble;
1606 if (cmd_in_trouble == NULL) { /* paranoia */ 1668 if (cmd_in_trouble == NULL) /* paranoia */
1607 return FAILED; 1669 return FAILED;
1608 } 1670 memcpy(lunaddr, &cmd_in_trouble->Header.LUN.LunAddrBytes[0], 8);
1609 /* send a reset to the SCSI LUN which the command was sent to */ 1671 /* send a reset to the SCSI LUN which the command was sent to */
1610 rc = sendcmd(CCISS_RESET_MSG, ctlr, NULL, 0, 2, 0, 0, 1672 rc = sendcmd_withirq(CCISS_RESET_MSG, ctlr, NULL, 0, 0, lunaddr,
1611 (unsigned char *) &cmd_in_trouble->Header.LUN.LunAddrBytes[0],
1612 TYPE_MSG); 1673 TYPE_MSG);
1613 /* sendcmd turned off interrupts on the board, turn 'em back on. */ 1674 if (rc == 0 && wait_for_device_to_become_ready(*c, lunaddr) == 0)
1614 (*c)->access.set_intr_mask(*c, CCISS_INTR_ON);
1615 if (rc == 0)
1616 return SUCCESS; 1675 return SUCCESS;
1617 printk(KERN_WARNING "cciss%d: resetting device failed.\n", ctlr); 1676 printk(KERN_WARNING "cciss%d: resetting device failed.\n", ctlr);
1618 return FAILED; 1677 return FAILED;
@@ -1622,6 +1681,7 @@ static int cciss_eh_abort_handler(struct scsi_cmnd *scsicmd)
1622{ 1681{
1623 int rc; 1682 int rc;
1624 CommandList_struct *cmd_to_abort; 1683 CommandList_struct *cmd_to_abort;
1684 unsigned char lunaddr[8];
1625 ctlr_info_t **c; 1685 ctlr_info_t **c;
1626 int ctlr; 1686 int ctlr;
1627 1687
@@ -1636,12 +1696,9 @@ static int cciss_eh_abort_handler(struct scsi_cmnd *scsicmd)
1636 cmd_to_abort = (CommandList_struct *) scsicmd->host_scribble; 1696 cmd_to_abort = (CommandList_struct *) scsicmd->host_scribble;
1637 if (cmd_to_abort == NULL) /* paranoia */ 1697 if (cmd_to_abort == NULL) /* paranoia */
1638 return FAILED; 1698 return FAILED;
1639 rc = sendcmd(CCISS_ABORT_MSG, ctlr, &cmd_to_abort->Header.Tag, 1699 memcpy(lunaddr, &cmd_to_abort->Header.LUN.LunAddrBytes[0], 8);
1640 0, 2, 0, 0, 1700 rc = sendcmd_withirq(CCISS_ABORT_MSG, ctlr, &cmd_to_abort->Header.Tag,
1641 (unsigned char *) &cmd_to_abort->Header.LUN.LunAddrBytes[0], 1701 0, 0, lunaddr, TYPE_MSG);
1642 TYPE_MSG);
1643 /* sendcmd turned off interrupts on the board, turn 'em back on. */
1644 (*c)->access.set_intr_mask(*c, CCISS_INTR_ON);
1645 if (rc == 0) 1702 if (rc == 0)
1646 return SUCCESS; 1703 return SUCCESS;
1647 return FAILED; 1704 return FAILED;
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index ca268ca11159..44fa2018f6b0 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -474,7 +474,7 @@ static int __init cpqarray_register_ctlr( int i, struct pci_dev *pdev)
474 disk->fops = &ida_fops; 474 disk->fops = &ida_fops;
475 if (j && !drv->nr_blks) 475 if (j && !drv->nr_blks)
476 continue; 476 continue;
477 blk_queue_hardsect_size(hba[i]->queue, drv->blk_size); 477 blk_queue_logical_block_size(hba[i]->queue, drv->blk_size);
478 set_capacity(disk, drv->nr_blks); 478 set_capacity(disk, drv->nr_blks);
479 disk->queue = hba[i]->queue; 479 disk->queue = hba[i]->queue;
480 disk->private_data = drv; 480 disk->private_data = drv;
@@ -903,7 +903,7 @@ static void do_ida_request(struct request_queue *q)
903 goto startio; 903 goto startio;
904 904
905queue_next: 905queue_next:
906 creq = elv_next_request(q); 906 creq = blk_peek_request(q);
907 if (!creq) 907 if (!creq)
908 goto startio; 908 goto startio;
909 909
@@ -912,17 +912,18 @@ queue_next:
912 if ((c = cmd_alloc(h,1)) == NULL) 912 if ((c = cmd_alloc(h,1)) == NULL)
913 goto startio; 913 goto startio;
914 914
915 blkdev_dequeue_request(creq); 915 blk_start_request(creq);
916 916
917 c->ctlr = h->ctlr; 917 c->ctlr = h->ctlr;
918 c->hdr.unit = (drv_info_t *)(creq->rq_disk->private_data) - h->drv; 918 c->hdr.unit = (drv_info_t *)(creq->rq_disk->private_data) - h->drv;
919 c->hdr.size = sizeof(rblk_t) >> 2; 919 c->hdr.size = sizeof(rblk_t) >> 2;
920 c->size += sizeof(rblk_t); 920 c->size += sizeof(rblk_t);
921 921
922 c->req.hdr.blk = creq->sector; 922 c->req.hdr.blk = blk_rq_pos(creq);
923 c->rq = creq; 923 c->rq = creq;
924DBGPX( 924DBGPX(
925 printk("sector=%d, nr_sectors=%d\n", creq->sector, creq->nr_sectors); 925 printk("sector=%d, nr_sectors=%u\n",
926 blk_rq_pos(creq), blk_rq_sectors(creq));
926); 927);
927 sg_init_table(tmp_sg, SG_MAX); 928 sg_init_table(tmp_sg, SG_MAX);
928 seg = blk_rq_map_sg(q, creq, tmp_sg); 929 seg = blk_rq_map_sg(q, creq, tmp_sg);
@@ -940,9 +941,9 @@ DBGPX(
940 tmp_sg[i].offset, 941 tmp_sg[i].offset,
941 tmp_sg[i].length, dir); 942 tmp_sg[i].length, dir);
942 } 943 }
943DBGPX( printk("Submitting %d sectors in %d segments\n", creq->nr_sectors, seg); ); 944DBGPX( printk("Submitting %u sectors in %d segments\n", blk_rq_sectors(creq), seg); );
944 c->req.hdr.sg_cnt = seg; 945 c->req.hdr.sg_cnt = seg;
945 c->req.hdr.blk_cnt = creq->nr_sectors; 946 c->req.hdr.blk_cnt = blk_rq_sectors(creq);
946 c->req.hdr.cmd = (rq_data_dir(creq) == READ) ? IDA_READ : IDA_WRITE; 947 c->req.hdr.cmd = (rq_data_dir(creq) == READ) ? IDA_READ : IDA_WRITE;
947 c->type = CMD_RWREQ; 948 c->type = CMD_RWREQ;
948 949
@@ -1024,8 +1025,7 @@ static inline void complete_command(cmdlist_t *cmd, int timeout)
1024 cmd->req.sg[i].size, ddir); 1025 cmd->req.sg[i].size, ddir);
1025 1026
1026 DBGPX(printk("Done with %p\n", rq);); 1027 DBGPX(printk("Done with %p\n", rq););
1027 if (__blk_end_request(rq, error, blk_rq_bytes(rq))) 1028 __blk_end_request_all(rq, error);
1028 BUG();
1029} 1029}
1030 1030
1031/* 1031/*
@@ -1546,7 +1546,7 @@ static int revalidate_allvol(ctlr_info_t *host)
1546 drv_info_t *drv = &host->drv[i]; 1546 drv_info_t *drv = &host->drv[i];
1547 if (i && !drv->nr_blks) 1547 if (i && !drv->nr_blks)
1548 continue; 1548 continue;
1549 blk_queue_hardsect_size(host->queue, drv->blk_size); 1549 blk_queue_logical_block_size(host->queue, drv->blk_size);
1550 set_capacity(disk, drv->nr_blks); 1550 set_capacity(disk, drv->nr_blks);
1551 disk->queue = host->queue; 1551 disk->queue = host->queue;
1552 disk->private_data = drv; 1552 disk->private_data = drv;
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 1300df6f1642..862b40c90181 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -931,7 +931,7 @@ static inline void unlock_fdc(void)
931 del_timer(&fd_timeout); 931 del_timer(&fd_timeout);
932 cont = NULL; 932 cont = NULL;
933 clear_bit(0, &fdc_busy); 933 clear_bit(0, &fdc_busy);
934 if (elv_next_request(floppy_queue)) 934 if (current_req || blk_peek_request(floppy_queue))
935 do_fd_request(floppy_queue); 935 do_fd_request(floppy_queue);
936 spin_unlock_irqrestore(&floppy_lock, flags); 936 spin_unlock_irqrestore(&floppy_lock, flags);
937 wake_up(&fdc_wait); 937 wake_up(&fdc_wait);
@@ -2303,7 +2303,7 @@ static void floppy_end_request(struct request *req, int error)
2303 2303
2304 /* current_count_sectors can be zero if transfer failed */ 2304 /* current_count_sectors can be zero if transfer failed */
2305 if (error) 2305 if (error)
2306 nr_sectors = req->current_nr_sectors; 2306 nr_sectors = blk_rq_cur_sectors(req);
2307 if (__blk_end_request(req, error, nr_sectors << 9)) 2307 if (__blk_end_request(req, error, nr_sectors << 9))
2308 return; 2308 return;
2309 2309
@@ -2332,7 +2332,7 @@ static void request_done(int uptodate)
2332 if (uptodate) { 2332 if (uptodate) {
2333 /* maintain values for invalidation on geometry 2333 /* maintain values for invalidation on geometry
2334 * change */ 2334 * change */
2335 block = current_count_sectors + req->sector; 2335 block = current_count_sectors + blk_rq_pos(req);
2336 INFBOUND(DRS->maxblock, block); 2336 INFBOUND(DRS->maxblock, block);
2337 if (block > _floppy->sect) 2337 if (block > _floppy->sect)
2338 DRS->maxtrack = 1; 2338 DRS->maxtrack = 1;
@@ -2346,10 +2346,10 @@ static void request_done(int uptodate)
2346 /* record write error information */ 2346 /* record write error information */
2347 DRWE->write_errors++; 2347 DRWE->write_errors++;
2348 if (DRWE->write_errors == 1) { 2348 if (DRWE->write_errors == 1) {
2349 DRWE->first_error_sector = req->sector; 2349 DRWE->first_error_sector = blk_rq_pos(req);
2350 DRWE->first_error_generation = DRS->generation; 2350 DRWE->first_error_generation = DRS->generation;
2351 } 2351 }
2352 DRWE->last_error_sector = req->sector; 2352 DRWE->last_error_sector = blk_rq_pos(req);
2353 DRWE->last_error_generation = DRS->generation; 2353 DRWE->last_error_generation = DRS->generation;
2354 } 2354 }
2355 spin_lock_irqsave(q->queue_lock, flags); 2355 spin_lock_irqsave(q->queue_lock, flags);
@@ -2503,24 +2503,23 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
2503 2503
2504 max_sector = transfer_size(ssize, 2504 max_sector = transfer_size(ssize,
2505 min(max_sector, max_sector_2), 2505 min(max_sector, max_sector_2),
2506 current_req->nr_sectors); 2506 blk_rq_sectors(current_req));
2507 2507
2508 if (current_count_sectors <= 0 && CT(COMMAND) == FD_WRITE && 2508 if (current_count_sectors <= 0 && CT(COMMAND) == FD_WRITE &&
2509 buffer_max > fsector_t + current_req->nr_sectors) 2509 buffer_max > fsector_t + blk_rq_sectors(current_req))
2510 current_count_sectors = min_t(int, buffer_max - fsector_t, 2510 current_count_sectors = min_t(int, buffer_max - fsector_t,
2511 current_req->nr_sectors); 2511 blk_rq_sectors(current_req));
2512 2512
2513 remaining = current_count_sectors << 9; 2513 remaining = current_count_sectors << 9;
2514#ifdef FLOPPY_SANITY_CHECK 2514#ifdef FLOPPY_SANITY_CHECK
2515 if ((remaining >> 9) > current_req->nr_sectors && 2515 if (remaining > blk_rq_bytes(current_req) && CT(COMMAND) == FD_WRITE) {
2516 CT(COMMAND) == FD_WRITE) {
2517 DPRINT("in copy buffer\n"); 2516 DPRINT("in copy buffer\n");
2518 printk("current_count_sectors=%ld\n", current_count_sectors); 2517 printk("current_count_sectors=%ld\n", current_count_sectors);
2519 printk("remaining=%d\n", remaining >> 9); 2518 printk("remaining=%d\n", remaining >> 9);
2520 printk("current_req->nr_sectors=%ld\n", 2519 printk("current_req->nr_sectors=%u\n",
2521 current_req->nr_sectors); 2520 blk_rq_sectors(current_req));
2522 printk("current_req->current_nr_sectors=%u\n", 2521 printk("current_req->current_nr_sectors=%u\n",
2523 current_req->current_nr_sectors); 2522 blk_rq_cur_sectors(current_req));
2524 printk("max_sector=%d\n", max_sector); 2523 printk("max_sector=%d\n", max_sector);
2525 printk("ssize=%d\n", ssize); 2524 printk("ssize=%d\n", ssize);
2526 } 2525 }
@@ -2530,7 +2529,7 @@ static void copy_buffer(int ssize, int max_sector, int max_sector_2)
2530 2529
2531 dma_buffer = floppy_track_buffer + ((fsector_t - buffer_min) << 9); 2530 dma_buffer = floppy_track_buffer + ((fsector_t - buffer_min) << 9);
2532 2531
2533 size = current_req->current_nr_sectors << 9; 2532 size = blk_rq_cur_bytes(current_req);
2534 2533
2535 rq_for_each_segment(bv, current_req, iter) { 2534 rq_for_each_segment(bv, current_req, iter) {
2536 if (!remaining) 2535 if (!remaining)
@@ -2648,10 +2647,10 @@ static int make_raw_rw_request(void)
2648 2647
2649 max_sector = _floppy->sect * _floppy->head; 2648 max_sector = _floppy->sect * _floppy->head;
2650 2649
2651 TRACK = (int)current_req->sector / max_sector; 2650 TRACK = (int)blk_rq_pos(current_req) / max_sector;
2652 fsector_t = (int)current_req->sector % max_sector; 2651 fsector_t = (int)blk_rq_pos(current_req) % max_sector;
2653 if (_floppy->track && TRACK >= _floppy->track) { 2652 if (_floppy->track && TRACK >= _floppy->track) {
2654 if (current_req->current_nr_sectors & 1) { 2653 if (blk_rq_cur_sectors(current_req) & 1) {
2655 current_count_sectors = 1; 2654 current_count_sectors = 1;
2656 return 1; 2655 return 1;
2657 } else 2656 } else
@@ -2669,7 +2668,7 @@ static int make_raw_rw_request(void)
2669 if (fsector_t >= max_sector) { 2668 if (fsector_t >= max_sector) {
2670 current_count_sectors = 2669 current_count_sectors =
2671 min_t(int, _floppy->sect - fsector_t, 2670 min_t(int, _floppy->sect - fsector_t,
2672 current_req->nr_sectors); 2671 blk_rq_sectors(current_req));
2673 return 1; 2672 return 1;
2674 } 2673 }
2675 SIZECODE = 2; 2674 SIZECODE = 2;
@@ -2720,7 +2719,7 @@ static int make_raw_rw_request(void)
2720 2719
2721 in_sector_offset = (fsector_t % _floppy->sect) % ssize; 2720 in_sector_offset = (fsector_t % _floppy->sect) % ssize;
2722 aligned_sector_t = fsector_t - in_sector_offset; 2721 aligned_sector_t = fsector_t - in_sector_offset;
2723 max_size = current_req->nr_sectors; 2722 max_size = blk_rq_sectors(current_req);
2724 if ((raw_cmd->track == buffer_track) && 2723 if ((raw_cmd->track == buffer_track) &&
2725 (current_drive == buffer_drive) && 2724 (current_drive == buffer_drive) &&
2726 (fsector_t >= buffer_min) && (fsector_t < buffer_max)) { 2725 (fsector_t >= buffer_min) && (fsector_t < buffer_max)) {
@@ -2729,10 +2728,10 @@ static int make_raw_rw_request(void)
2729 copy_buffer(1, max_sector, buffer_max); 2728 copy_buffer(1, max_sector, buffer_max);
2730 return 1; 2729 return 1;
2731 } 2730 }
2732 } else if (in_sector_offset || current_req->nr_sectors < ssize) { 2731 } else if (in_sector_offset || blk_rq_sectors(current_req) < ssize) {
2733 if (CT(COMMAND) == FD_WRITE) { 2732 if (CT(COMMAND) == FD_WRITE) {
2734 if (fsector_t + current_req->nr_sectors > ssize && 2733 if (fsector_t + blk_rq_sectors(current_req) > ssize &&
2735 fsector_t + current_req->nr_sectors < ssize + ssize) 2734 fsector_t + blk_rq_sectors(current_req) < ssize + ssize)
2736 max_size = ssize + ssize; 2735 max_size = ssize + ssize;
2737 else 2736 else
2738 max_size = ssize; 2737 max_size = ssize;
@@ -2776,7 +2775,7 @@ static int make_raw_rw_request(void)
2776 (indirect * 2 > direct * 3 && 2775 (indirect * 2 > direct * 3 &&
2777 *errors < DP->max_errors.read_track && ((!probing 2776 *errors < DP->max_errors.read_track && ((!probing
2778 || (DP->read_track & (1 << DRS->probed_format)))))) { 2777 || (DP->read_track & (1 << DRS->probed_format)))))) {
2779 max_size = current_req->nr_sectors; 2778 max_size = blk_rq_sectors(current_req);
2780 } else { 2779 } else {
2781 raw_cmd->kernel_data = current_req->buffer; 2780 raw_cmd->kernel_data = current_req->buffer;
2782 raw_cmd->length = current_count_sectors << 9; 2781 raw_cmd->length = current_count_sectors << 9;
@@ -2801,7 +2800,7 @@ static int make_raw_rw_request(void)
2801 fsector_t > buffer_max || 2800 fsector_t > buffer_max ||
2802 fsector_t < buffer_min || 2801 fsector_t < buffer_min ||
2803 ((CT(COMMAND) == FD_READ || 2802 ((CT(COMMAND) == FD_READ ||
2804 (!in_sector_offset && current_req->nr_sectors >= ssize)) && 2803 (!in_sector_offset && blk_rq_sectors(current_req) >= ssize)) &&
2805 max_sector > 2 * max_buffer_sectors + buffer_min && 2804 max_sector > 2 * max_buffer_sectors + buffer_min &&
2806 max_size + fsector_t > 2 * max_buffer_sectors + buffer_min) 2805 max_size + fsector_t > 2 * max_buffer_sectors + buffer_min)
2807 /* not enough space */ 2806 /* not enough space */
@@ -2879,8 +2878,8 @@ static int make_raw_rw_request(void)
2879 printk("write\n"); 2878 printk("write\n");
2880 return 0; 2879 return 0;
2881 } 2880 }
2882 } else if (raw_cmd->length > current_req->nr_sectors << 9 || 2881 } else if (raw_cmd->length > blk_rq_bytes(current_req) ||
2883 current_count_sectors > current_req->nr_sectors) { 2882 current_count_sectors > blk_rq_sectors(current_req)) {
2884 DPRINT("buffer overrun in direct transfer\n"); 2883 DPRINT("buffer overrun in direct transfer\n");
2885 return 0; 2884 return 0;
2886 } else if (raw_cmd->length < current_count_sectors << 9) { 2885 } else if (raw_cmd->length < current_count_sectors << 9) {
@@ -2913,7 +2912,7 @@ static void redo_fd_request(void)
2913 struct request *req; 2912 struct request *req;
2914 2913
2915 spin_lock_irq(floppy_queue->queue_lock); 2914 spin_lock_irq(floppy_queue->queue_lock);
2916 req = elv_next_request(floppy_queue); 2915 req = blk_fetch_request(floppy_queue);
2917 spin_unlock_irq(floppy_queue->queue_lock); 2916 spin_unlock_irq(floppy_queue->queue_lock);
2918 if (!req) { 2917 if (!req) {
2919 do_floppy = NULL; 2918 do_floppy = NULL;
@@ -2990,8 +2989,9 @@ static void do_fd_request(struct request_queue * q)
2990 if (usage_count == 0) { 2989 if (usage_count == 0) {
2991 printk("warning: usage count=0, current_req=%p exiting\n", 2990 printk("warning: usage count=0, current_req=%p exiting\n",
2992 current_req); 2991 current_req);
2993 printk("sect=%ld type=%x flags=%x\n", (long)current_req->sector, 2992 printk("sect=%ld type=%x flags=%x\n",
2994 current_req->cmd_type, current_req->cmd_flags); 2993 (long)blk_rq_pos(current_req), current_req->cmd_type,
2994 current_req->cmd_flags);
2995 return; 2995 return;
2996 } 2996 }
2997 if (test_bit(0, &fdc_busy)) { 2997 if (test_bit(0, &fdc_busy)) {
@@ -4148,6 +4148,24 @@ static void floppy_device_release(struct device *dev)
4148{ 4148{
4149} 4149}
4150 4150
4151static int floppy_resume(struct platform_device *dev)
4152{
4153 int fdc;
4154
4155 for (fdc = 0; fdc < N_FDC; fdc++)
4156 if (FDCS->address != -1)
4157 user_reset_fdc(-1, FD_RESET_ALWAYS, 0);
4158
4159 return 0;
4160}
4161
4162static struct platform_driver floppy_driver = {
4163 .resume = floppy_resume,
4164 .driver = {
4165 .name = "floppy",
4166 },
4167};
4168
4151static struct platform_device floppy_device[N_DRIVE]; 4169static struct platform_device floppy_device[N_DRIVE];
4152 4170
4153static struct kobject *floppy_find(dev_t dev, int *part, void *data) 4171static struct kobject *floppy_find(dev_t dev, int *part, void *data)
@@ -4196,10 +4214,14 @@ static int __init floppy_init(void)
4196 if (err) 4214 if (err)
4197 goto out_put_disk; 4215 goto out_put_disk;
4198 4216
4217 err = platform_driver_register(&floppy_driver);
4218 if (err)
4219 goto out_unreg_blkdev;
4220
4199 floppy_queue = blk_init_queue(do_fd_request, &floppy_lock); 4221 floppy_queue = blk_init_queue(do_fd_request, &floppy_lock);
4200 if (!floppy_queue) { 4222 if (!floppy_queue) {
4201 err = -ENOMEM; 4223 err = -ENOMEM;
4202 goto out_unreg_blkdev; 4224 goto out_unreg_driver;
4203 } 4225 }
4204 blk_queue_max_sectors(floppy_queue, 64); 4226 blk_queue_max_sectors(floppy_queue, 64);
4205 4227
@@ -4346,6 +4368,8 @@ out_flush_work:
4346out_unreg_region: 4368out_unreg_region:
4347 blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); 4369 blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256);
4348 blk_cleanup_queue(floppy_queue); 4370 blk_cleanup_queue(floppy_queue);
4371out_unreg_driver:
4372 platform_driver_unregister(&floppy_driver);
4349out_unreg_blkdev: 4373out_unreg_blkdev:
4350 unregister_blkdev(FLOPPY_MAJOR, "fd"); 4374 unregister_blkdev(FLOPPY_MAJOR, "fd");
4351out_put_disk: 4375out_put_disk:
@@ -4566,6 +4590,7 @@ static void __exit floppy_module_exit(void)
4566 4590
4567 blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256); 4591 blk_unregister_region(MKDEV(FLOPPY_MAJOR, 0), 256);
4568 unregister_blkdev(FLOPPY_MAJOR, "fd"); 4592 unregister_blkdev(FLOPPY_MAJOR, "fd");
4593 platform_driver_unregister(&floppy_driver);
4569 4594
4570 for (drive = 0; drive < N_DRIVE; drive++) { 4595 for (drive = 0; drive < N_DRIVE; drive++) {
4571 del_timer_sync(&motor_off_timer[drive]); 4596 del_timer_sync(&motor_off_timer[drive]);
diff --git a/drivers/block/hd.c b/drivers/block/hd.c
index baaa9e486e50..f65b3f369eb0 100644
--- a/drivers/block/hd.c
+++ b/drivers/block/hd.c
@@ -98,10 +98,9 @@
98 98
99static DEFINE_SPINLOCK(hd_lock); 99static DEFINE_SPINLOCK(hd_lock);
100static struct request_queue *hd_queue; 100static struct request_queue *hd_queue;
101static struct request *hd_req;
101 102
102#define MAJOR_NR HD_MAJOR 103#define MAJOR_NR HD_MAJOR
103#define QUEUE (hd_queue)
104#define CURRENT elv_next_request(hd_queue)
105 104
106#define TIMEOUT_VALUE (6*HZ) 105#define TIMEOUT_VALUE (6*HZ)
107#define HD_DELAY 0 106#define HD_DELAY 0
@@ -195,11 +194,24 @@ static void __init hd_setup(char *str, int *ints)
195 NR_HD = hdind+1; 194 NR_HD = hdind+1;
196} 195}
197 196
197static bool hd_end_request(int err, unsigned int bytes)
198{
199 if (__blk_end_request(hd_req, err, bytes))
200 return true;
201 hd_req = NULL;
202 return false;
203}
204
205static bool hd_end_request_cur(int err)
206{
207 return hd_end_request(err, blk_rq_cur_bytes(hd_req));
208}
209
198static void dump_status(const char *msg, unsigned int stat) 210static void dump_status(const char *msg, unsigned int stat)
199{ 211{
200 char *name = "hd?"; 212 char *name = "hd?";
201 if (CURRENT) 213 if (hd_req)
202 name = CURRENT->rq_disk->disk_name; 214 name = hd_req->rq_disk->disk_name;
203 215
204#ifdef VERBOSE_ERRORS 216#ifdef VERBOSE_ERRORS
205 printk("%s: %s: status=0x%02x { ", name, msg, stat & 0xff); 217 printk("%s: %s: status=0x%02x { ", name, msg, stat & 0xff);
@@ -227,8 +239,8 @@ static void dump_status(const char *msg, unsigned int stat)
227 if (hd_error & (BBD_ERR|ECC_ERR|ID_ERR|MARK_ERR)) { 239 if (hd_error & (BBD_ERR|ECC_ERR|ID_ERR|MARK_ERR)) {
228 printk(", CHS=%d/%d/%d", (inb(HD_HCYL)<<8) + inb(HD_LCYL), 240 printk(", CHS=%d/%d/%d", (inb(HD_HCYL)<<8) + inb(HD_LCYL),
229 inb(HD_CURRENT) & 0xf, inb(HD_SECTOR)); 241 inb(HD_CURRENT) & 0xf, inb(HD_SECTOR));
230 if (CURRENT) 242 if (hd_req)
231 printk(", sector=%ld", CURRENT->sector); 243 printk(", sector=%ld", blk_rq_pos(hd_req));
232 } 244 }
233 printk("\n"); 245 printk("\n");
234 } 246 }
@@ -406,11 +418,12 @@ static void unexpected_hd_interrupt(void)
406 */ 418 */
407static void bad_rw_intr(void) 419static void bad_rw_intr(void)
408{ 420{
409 struct request *req = CURRENT; 421 struct request *req = hd_req;
422
410 if (req != NULL) { 423 if (req != NULL) {
411 struct hd_i_struct *disk = req->rq_disk->private_data; 424 struct hd_i_struct *disk = req->rq_disk->private_data;
412 if (++req->errors >= MAX_ERRORS || (hd_error & BBD_ERR)) { 425 if (++req->errors >= MAX_ERRORS || (hd_error & BBD_ERR)) {
413 end_request(req, 0); 426 hd_end_request_cur(-EIO);
414 disk->special_op = disk->recalibrate = 1; 427 disk->special_op = disk->recalibrate = 1;
415 } else if (req->errors % RESET_FREQ == 0) 428 } else if (req->errors % RESET_FREQ == 0)
416 reset = 1; 429 reset = 1;
@@ -452,37 +465,30 @@ static void read_intr(void)
452 bad_rw_intr(); 465 bad_rw_intr();
453 hd_request(); 466 hd_request();
454 return; 467 return;
468
455ok_to_read: 469ok_to_read:
456 req = CURRENT; 470 req = hd_req;
457 insw(HD_DATA, req->buffer, 256); 471 insw(HD_DATA, req->buffer, 256);
458 req->sector++;
459 req->buffer += 512;
460 req->errors = 0;
461 i = --req->nr_sectors;
462 --req->current_nr_sectors;
463#ifdef DEBUG 472#ifdef DEBUG
464 printk("%s: read: sector %ld, remaining = %ld, buffer=%p\n", 473 printk("%s: read: sector %ld, remaining = %u, buffer=%p\n",
465 req->rq_disk->disk_name, req->sector, req->nr_sectors, 474 req->rq_disk->disk_name, blk_rq_pos(req) + 1,
466 req->buffer+512); 475 blk_rq_sectors(req) - 1, req->buffer+512);
467#endif 476#endif
468 if (req->current_nr_sectors <= 0) 477 if (hd_end_request(0, 512)) {
469 end_request(req, 1);
470 if (i > 0) {
471 SET_HANDLER(&read_intr); 478 SET_HANDLER(&read_intr);
472 return; 479 return;
473 } 480 }
481
474 (void) inb_p(HD_STATUS); 482 (void) inb_p(HD_STATUS);
475#if (HD_DELAY > 0) 483#if (HD_DELAY > 0)
476 last_req = read_timer(); 484 last_req = read_timer();
477#endif 485#endif
478 if (elv_next_request(QUEUE)) 486 hd_request();
479 hd_request();
480 return;
481} 487}
482 488
483static void write_intr(void) 489static void write_intr(void)
484{ 490{
485 struct request *req = CURRENT; 491 struct request *req = hd_req;
486 int i; 492 int i;
487 int retries = 100000; 493 int retries = 100000;
488 494
@@ -492,30 +498,25 @@ static void write_intr(void)
492 continue; 498 continue;
493 if (!OK_STATUS(i)) 499 if (!OK_STATUS(i))
494 break; 500 break;
495 if ((req->nr_sectors <= 1) || (i & DRQ_STAT)) 501 if ((blk_rq_sectors(req) <= 1) || (i & DRQ_STAT))
496 goto ok_to_write; 502 goto ok_to_write;
497 } while (--retries > 0); 503 } while (--retries > 0);
498 dump_status("write_intr", i); 504 dump_status("write_intr", i);
499 bad_rw_intr(); 505 bad_rw_intr();
500 hd_request(); 506 hd_request();
501 return; 507 return;
508
502ok_to_write: 509ok_to_write:
503 req->sector++; 510 if (hd_end_request(0, 512)) {
504 i = --req->nr_sectors;
505 --req->current_nr_sectors;
506 req->buffer += 512;
507 if (!i || (req->bio && req->current_nr_sectors <= 0))
508 end_request(req, 1);
509 if (i > 0) {
510 SET_HANDLER(&write_intr); 511 SET_HANDLER(&write_intr);
511 outsw(HD_DATA, req->buffer, 256); 512 outsw(HD_DATA, req->buffer, 256);
512 } else { 513 return;
514 }
515
513#if (HD_DELAY > 0) 516#if (HD_DELAY > 0)
514 last_req = read_timer(); 517 last_req = read_timer();
515#endif 518#endif
516 hd_request(); 519 hd_request();
517 }
518 return;
519} 520}
520 521
521static void recal_intr(void) 522static void recal_intr(void)
@@ -537,18 +538,18 @@ static void hd_times_out(unsigned long dummy)
537 538
538 do_hd = NULL; 539 do_hd = NULL;
539 540
540 if (!CURRENT) 541 if (!hd_req)
541 return; 542 return;
542 543
543 spin_lock_irq(hd_queue->queue_lock); 544 spin_lock_irq(hd_queue->queue_lock);
544 reset = 1; 545 reset = 1;
545 name = CURRENT->rq_disk->disk_name; 546 name = hd_req->rq_disk->disk_name;
546 printk("%s: timeout\n", name); 547 printk("%s: timeout\n", name);
547 if (++CURRENT->errors >= MAX_ERRORS) { 548 if (++hd_req->errors >= MAX_ERRORS) {
548#ifdef DEBUG 549#ifdef DEBUG
549 printk("%s: too many errors\n", name); 550 printk("%s: too many errors\n", name);
550#endif 551#endif
551 end_request(CURRENT, 0); 552 hd_end_request_cur(-EIO);
552 } 553 }
553 hd_request(); 554 hd_request();
554 spin_unlock_irq(hd_queue->queue_lock); 555 spin_unlock_irq(hd_queue->queue_lock);
@@ -563,7 +564,7 @@ static int do_special_op(struct hd_i_struct *disk, struct request *req)
563 } 564 }
564 if (disk->head > 16) { 565 if (disk->head > 16) {
565 printk("%s: cannot handle device with more than 16 heads - giving up\n", req->rq_disk->disk_name); 566 printk("%s: cannot handle device with more than 16 heads - giving up\n", req->rq_disk->disk_name);
566 end_request(req, 0); 567 hd_end_request_cur(-EIO);
567 } 568 }
568 disk->special_op = 0; 569 disk->special_op = 0;
569 return 1; 570 return 1;
@@ -590,24 +591,27 @@ static void hd_request(void)
590repeat: 591repeat:
591 del_timer(&device_timer); 592 del_timer(&device_timer);
592 593
593 req = CURRENT; 594 if (!hd_req) {
594 if (!req) { 595 hd_req = blk_fetch_request(hd_queue);
595 do_hd = NULL; 596 if (!hd_req) {
596 return; 597 do_hd = NULL;
598 return;
599 }
597 } 600 }
601 req = hd_req;
598 602
599 if (reset) { 603 if (reset) {
600 reset_hd(); 604 reset_hd();
601 return; 605 return;
602 } 606 }
603 disk = req->rq_disk->private_data; 607 disk = req->rq_disk->private_data;
604 block = req->sector; 608 block = blk_rq_pos(req);
605 nsect = req->nr_sectors; 609 nsect = blk_rq_sectors(req);
606 if (block >= get_capacity(req->rq_disk) || 610 if (block >= get_capacity(req->rq_disk) ||
607 ((block+nsect) > get_capacity(req->rq_disk))) { 611 ((block+nsect) > get_capacity(req->rq_disk))) {
608 printk("%s: bad access: block=%d, count=%d\n", 612 printk("%s: bad access: block=%d, count=%d\n",
609 req->rq_disk->disk_name, block, nsect); 613 req->rq_disk->disk_name, block, nsect);
610 end_request(req, 0); 614 hd_end_request_cur(-EIO);
611 goto repeat; 615 goto repeat;
612 } 616 }
613 617
@@ -647,7 +651,7 @@ repeat:
647 break; 651 break;
648 default: 652 default:
649 printk("unknown hd-command\n"); 653 printk("unknown hd-command\n");
650 end_request(req, 0); 654 hd_end_request_cur(-EIO);
651 break; 655 break;
652 } 656 }
653 } 657 }
@@ -720,7 +724,7 @@ static int __init hd_init(void)
720 blk_queue_max_sectors(hd_queue, 255); 724 blk_queue_max_sectors(hd_queue, 255);
721 init_timer(&device_timer); 725 init_timer(&device_timer);
722 device_timer.function = hd_times_out; 726 device_timer.function = hd_times_out;
723 blk_queue_hardsect_size(hd_queue, 512); 727 blk_queue_logical_block_size(hd_queue, 512);
724 728
725 if (!NR_HD) { 729 if (!NR_HD) {
726 /* 730 /*
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index ddae80825899..801f4ab83302 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -511,11 +511,7 @@ out:
511 */ 511 */
512static void loop_add_bio(struct loop_device *lo, struct bio *bio) 512static void loop_add_bio(struct loop_device *lo, struct bio *bio)
513{ 513{
514 if (lo->lo_biotail) { 514 bio_list_add(&lo->lo_bio_list, bio);
515 lo->lo_biotail->bi_next = bio;
516 lo->lo_biotail = bio;
517 } else
518 lo->lo_bio = lo->lo_biotail = bio;
519} 515}
520 516
521/* 517/*
@@ -523,16 +519,7 @@ static void loop_add_bio(struct loop_device *lo, struct bio *bio)
523 */ 519 */
524static struct bio *loop_get_bio(struct loop_device *lo) 520static struct bio *loop_get_bio(struct loop_device *lo)
525{ 521{
526 struct bio *bio; 522 return bio_list_pop(&lo->lo_bio_list);
527
528 if ((bio = lo->lo_bio)) {
529 if (bio == lo->lo_biotail)
530 lo->lo_biotail = NULL;
531 lo->lo_bio = bio->bi_next;
532 bio->bi_next = NULL;
533 }
534
535 return bio;
536} 523}
537 524
538static int loop_make_request(struct request_queue *q, struct bio *old_bio) 525static int loop_make_request(struct request_queue *q, struct bio *old_bio)
@@ -609,12 +596,13 @@ static int loop_thread(void *data)
609 596
610 set_user_nice(current, -20); 597 set_user_nice(current, -20);
611 598
612 while (!kthread_should_stop() || lo->lo_bio) { 599 while (!kthread_should_stop() || !bio_list_empty(&lo->lo_bio_list)) {
613 600
614 wait_event_interruptible(lo->lo_event, 601 wait_event_interruptible(lo->lo_event,
615 lo->lo_bio || kthread_should_stop()); 602 !bio_list_empty(&lo->lo_bio_list) ||
603 kthread_should_stop());
616 604
617 if (!lo->lo_bio) 605 if (bio_list_empty(&lo->lo_bio_list))
618 continue; 606 continue;
619 spin_lock_irq(&lo->lo_lock); 607 spin_lock_irq(&lo->lo_lock);
620 bio = loop_get_bio(lo); 608 bio = loop_get_bio(lo);
@@ -721,10 +709,6 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
721 if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode)) 709 if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))
722 goto out_putf; 710 goto out_putf;
723 711
724 /* new backing store needs to support loop (eg splice_read) */
725 if (!inode->i_fop->splice_read)
726 goto out_putf;
727
728 /* size of the new backing store needs to be the same */ 712 /* size of the new backing store needs to be the same */
729 if (get_loop_size(lo, file) != get_loop_size(lo, old_file)) 713 if (get_loop_size(lo, file) != get_loop_size(lo, old_file))
730 goto out_putf; 714 goto out_putf;
@@ -800,12 +784,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
800 error = -EINVAL; 784 error = -EINVAL;
801 if (S_ISREG(inode->i_mode) || S_ISBLK(inode->i_mode)) { 785 if (S_ISREG(inode->i_mode) || S_ISBLK(inode->i_mode)) {
802 const struct address_space_operations *aops = mapping->a_ops; 786 const struct address_space_operations *aops = mapping->a_ops;
803 /* 787
804 * If we can't read - sorry. If we only can't write - well,
805 * it's going to be read-only.
806 */
807 if (!file->f_op->splice_read)
808 goto out_putf;
809 if (aops->write_begin) 788 if (aops->write_begin)
810 lo_flags |= LO_FLAGS_USE_AOPS; 789 lo_flags |= LO_FLAGS_USE_AOPS;
811 if (!(lo_flags & LO_FLAGS_USE_AOPS) && !file->f_op->write) 790 if (!(lo_flags & LO_FLAGS_USE_AOPS) && !file->f_op->write)
@@ -841,7 +820,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
841 lo->old_gfp_mask = mapping_gfp_mask(mapping); 820 lo->old_gfp_mask = mapping_gfp_mask(mapping);
842 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS)); 821 mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
843 822
844 lo->lo_bio = lo->lo_biotail = NULL; 823 bio_list_init(&lo->lo_bio_list);
845 824
846 /* 825 /*
847 * set queue make_request_fn, and add limits based on lower level 826 * set queue make_request_fn, and add limits based on lower level
diff --git a/drivers/block/mg_disk.c b/drivers/block/mg_disk.c
index f3898353d0a8..60de5a01e71e 100644
--- a/drivers/block/mg_disk.c
+++ b/drivers/block/mg_disk.c
@@ -17,71 +17,220 @@
17#include <linux/fs.h> 17#include <linux/fs.h>
18#include <linux/blkdev.h> 18#include <linux/blkdev.h>
19#include <linux/hdreg.h> 19#include <linux/hdreg.h>
20#include <linux/libata.h> 20#include <linux/ata.h>
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/mg_disk.h>
26 25
27#define MG_RES_SEC (CONFIG_MG_DISK_RES << 1) 26#define MG_RES_SEC (CONFIG_MG_DISK_RES << 1)
28 27
28/* name for block device */
29#define MG_DISK_NAME "mgd"
30/* name for platform device */
31#define MG_DEV_NAME "mg_disk"
32
33#define MG_DISK_MAJ 0
34#define MG_DISK_MAX_PART 16
35#define MG_SECTOR_SIZE 512
36#define MG_MAX_SECTS 256
37
38/* Register offsets */
39#define MG_BUFF_OFFSET 0x8000
40#define MG_STORAGE_BUFFER_SIZE 0x200
41#define MG_REG_OFFSET 0xC000
42#define MG_REG_FEATURE (MG_REG_OFFSET + 2) /* write case */
43#define MG_REG_ERROR (MG_REG_OFFSET + 2) /* read case */
44#define MG_REG_SECT_CNT (MG_REG_OFFSET + 4)
45#define MG_REG_SECT_NUM (MG_REG_OFFSET + 6)
46#define MG_REG_CYL_LOW (MG_REG_OFFSET + 8)
47#define MG_REG_CYL_HIGH (MG_REG_OFFSET + 0xA)
48#define MG_REG_DRV_HEAD (MG_REG_OFFSET + 0xC)
49#define MG_REG_COMMAND (MG_REG_OFFSET + 0xE) /* write case */
50#define MG_REG_STATUS (MG_REG_OFFSET + 0xE) /* read case */
51#define MG_REG_DRV_CTRL (MG_REG_OFFSET + 0x10)
52#define MG_REG_BURST_CTRL (MG_REG_OFFSET + 0x12)
53
54/* handy status */
55#define MG_STAT_READY (ATA_DRDY | ATA_DSC)
56#define MG_READY_OK(s) (((s) & (MG_STAT_READY | (ATA_BUSY | ATA_DF | \
57 ATA_ERR))) == MG_STAT_READY)
58
59/* error code for others */
60#define MG_ERR_NONE 0
61#define MG_ERR_TIMEOUT 0x100
62#define MG_ERR_INIT_STAT 0x101
63#define MG_ERR_TRANSLATION 0x102
64#define MG_ERR_CTRL_RST 0x103
65#define MG_ERR_INV_STAT 0x104
66#define MG_ERR_RSTOUT 0x105
67
68#define MG_MAX_ERRORS 6 /* Max read/write errors */
69
70/* command */
71#define MG_CMD_RD 0x20
72#define MG_CMD_WR 0x30
73#define MG_CMD_SLEEP 0x99
74#define MG_CMD_WAKEUP 0xC3
75#define MG_CMD_ID 0xEC
76#define MG_CMD_WR_CONF 0x3C
77#define MG_CMD_RD_CONF 0x40
78
79/* operation mode */
80#define MG_OP_CASCADE (1 << 0)
81#define MG_OP_CASCADE_SYNC_RD (1 << 1)
82#define MG_OP_CASCADE_SYNC_WR (1 << 2)
83#define MG_OP_INTERLEAVE (1 << 3)
84
85/* synchronous */
86#define MG_BURST_LAT_4 (3 << 4)
87#define MG_BURST_LAT_5 (4 << 4)
88#define MG_BURST_LAT_6 (5 << 4)
89#define MG_BURST_LAT_7 (6 << 4)
90#define MG_BURST_LAT_8 (7 << 4)
91#define MG_BURST_LEN_4 (1 << 1)
92#define MG_BURST_LEN_8 (2 << 1)
93#define MG_BURST_LEN_16 (3 << 1)
94#define MG_BURST_LEN_32 (4 << 1)
95#define MG_BURST_LEN_CONT (0 << 1)
96
97/* timeout value (unit: ms) */
98#define MG_TMAX_CONF_TO_CMD 1
99#define MG_TMAX_WAIT_RD_DRQ 10
100#define MG_TMAX_WAIT_WR_DRQ 500
101#define MG_TMAX_RST_TO_BUSY 10
102#define MG_TMAX_HDRST_TO_RDY 500
103#define MG_TMAX_SWRST_TO_RDY 500
104#define MG_TMAX_RSTOUT 3000
105
106/* device attribution */
107/* use mflash as boot device */
108#define MG_BOOT_DEV (1 << 0)
109/* use mflash as storage device */
110#define MG_STORAGE_DEV (1 << 1)
111/* same as MG_STORAGE_DEV, but bootloader already done reset sequence */
112#define MG_STORAGE_DEV_SKIP_RST (1 << 2)
113
114#define MG_DEV_MASK (MG_BOOT_DEV | MG_STORAGE_DEV | MG_STORAGE_DEV_SKIP_RST)
115
116/* names of GPIO resource */
117#define MG_RST_PIN "mg_rst"
118/* except MG_BOOT_DEV, reset-out pin should be assigned */
119#define MG_RSTOUT_PIN "mg_rstout"
120
121/* private driver data */
122struct mg_drv_data {
123 /* disk resource */
124 u32 use_polling;
125
126 /* device attribution */
127 u32 dev_attr;
128
129 /* internally used */
130 struct mg_host *host;
131};
132
133/* main structure for mflash driver */
134struct mg_host {
135 struct device *dev;
136
137 struct request_queue *breq;
138 struct request *req;
139 spinlock_t lock;
140 struct gendisk *gd;
141
142 struct timer_list timer;
143 void (*mg_do_intr) (struct mg_host *);
144
145 u16 id[ATA_ID_WORDS];
146
147 u16 cyls;
148 u16 heads;
149 u16 sectors;
150 u32 n_sectors;
151 u32 nres_sectors;
152
153 void __iomem *dev_base;
154 unsigned int irq;
155 unsigned int rst;
156 unsigned int rstout;
157
158 u32 major;
159 u32 error;
160};
161
162/*
163 * Debugging macro and defines
164 */
165#undef DO_MG_DEBUG
166#ifdef DO_MG_DEBUG
167# define MG_DBG(fmt, args...) \
168 printk(KERN_DEBUG "%s:%d "fmt, __func__, __LINE__, ##args)
169#else /* CONFIG_MG_DEBUG */
170# define MG_DBG(fmt, args...) do { } while (0)
171#endif /* CONFIG_MG_DEBUG */
172
29static void mg_request(struct request_queue *); 173static void mg_request(struct request_queue *);
30 174
175static bool mg_end_request(struct mg_host *host, int err, unsigned int nr_bytes)
176{
177 if (__blk_end_request(host->req, err, nr_bytes))
178 return true;
179
180 host->req = NULL;
181 return false;
182}
183
184static bool mg_end_request_cur(struct mg_host *host, int err)
185{
186 return mg_end_request(host, err, blk_rq_cur_bytes(host->req));
187}
188
31static void mg_dump_status(const char *msg, unsigned int stat, 189static void mg_dump_status(const char *msg, unsigned int stat,
32 struct mg_host *host) 190 struct mg_host *host)
33{ 191{
34 char *name = MG_DISK_NAME; 192 char *name = MG_DISK_NAME;
35 struct request *req;
36 193
37 if (host->breq) { 194 if (host->req)
38 req = elv_next_request(host->breq); 195 name = host->req->rq_disk->disk_name;
39 if (req)
40 name = req->rq_disk->disk_name;
41 }
42 196
43 printk(KERN_ERR "%s: %s: status=0x%02x { ", name, msg, stat & 0xff); 197 printk(KERN_ERR "%s: %s: status=0x%02x { ", name, msg, stat & 0xff);
44 if (stat & MG_REG_STATUS_BIT_BUSY) 198 if (stat & ATA_BUSY)
45 printk("Busy "); 199 printk("Busy ");
46 if (stat & MG_REG_STATUS_BIT_READY) 200 if (stat & ATA_DRDY)
47 printk("DriveReady "); 201 printk("DriveReady ");
48 if (stat & MG_REG_STATUS_BIT_WRITE_FAULT) 202 if (stat & ATA_DF)
49 printk("WriteFault "); 203 printk("WriteFault ");
50 if (stat & MG_REG_STATUS_BIT_SEEK_DONE) 204 if (stat & ATA_DSC)
51 printk("SeekComplete "); 205 printk("SeekComplete ");
52 if (stat & MG_REG_STATUS_BIT_DATA_REQ) 206 if (stat & ATA_DRQ)
53 printk("DataRequest "); 207 printk("DataRequest ");
54 if (stat & MG_REG_STATUS_BIT_CORRECTED_ERROR) 208 if (stat & ATA_CORR)
55 printk("CorrectedError "); 209 printk("CorrectedError ");
56 if (stat & MG_REG_STATUS_BIT_ERROR) 210 if (stat & ATA_ERR)
57 printk("Error "); 211 printk("Error ");
58 printk("}\n"); 212 printk("}\n");
59 if ((stat & MG_REG_STATUS_BIT_ERROR) == 0) { 213 if ((stat & ATA_ERR) == 0) {
60 host->error = 0; 214 host->error = 0;
61 } else { 215 } else {
62 host->error = inb((unsigned long)host->dev_base + MG_REG_ERROR); 216 host->error = inb((unsigned long)host->dev_base + MG_REG_ERROR);
63 printk(KERN_ERR "%s: %s: error=0x%02x { ", name, msg, 217 printk(KERN_ERR "%s: %s: error=0x%02x { ", name, msg,
64 host->error & 0xff); 218 host->error & 0xff);
65 if (host->error & MG_REG_ERR_BBK) 219 if (host->error & ATA_BBK)
66 printk("BadSector "); 220 printk("BadSector ");
67 if (host->error & MG_REG_ERR_UNC) 221 if (host->error & ATA_UNC)
68 printk("UncorrectableError "); 222 printk("UncorrectableError ");
69 if (host->error & MG_REG_ERR_IDNF) 223 if (host->error & ATA_IDNF)
70 printk("SectorIdNotFound "); 224 printk("SectorIdNotFound ");
71 if (host->error & MG_REG_ERR_ABRT) 225 if (host->error & ATA_ABORTED)
72 printk("DriveStatusError "); 226 printk("DriveStatusError ");
73 if (host->error & MG_REG_ERR_AMNF) 227 if (host->error & ATA_AMNF)
74 printk("AddrMarkNotFound "); 228 printk("AddrMarkNotFound ");
75 printk("}"); 229 printk("}");
76 if (host->error & 230 if (host->error & (ATA_BBK | ATA_UNC | ATA_IDNF | ATA_AMNF)) {
77 (MG_REG_ERR_BBK | MG_REG_ERR_UNC | 231 if (host->req)
78 MG_REG_ERR_IDNF | MG_REG_ERR_AMNF)) { 232 printk(", sector=%u",
79 if (host->breq) { 233 (unsigned int)blk_rq_pos(host->req));
80 req = elv_next_request(host->breq);
81 if (req)
82 printk(", sector=%u", (u32)req->sector);
83 }
84
85 } 234 }
86 printk("\n"); 235 printk("\n");
87 } 236 }
@@ -100,12 +249,12 @@ static unsigned int mg_wait(struct mg_host *host, u32 expect, u32 msec)
100 249
101 do { 250 do {
102 cur_jiffies = jiffies; 251 cur_jiffies = jiffies;
103 if (status & MG_REG_STATUS_BIT_BUSY) { 252 if (status & ATA_BUSY) {
104 if (expect == MG_REG_STATUS_BIT_BUSY) 253 if (expect == ATA_BUSY)
105 break; 254 break;
106 } else { 255 } else {
107 /* Check the error condition! */ 256 /* Check the error condition! */
108 if (status & MG_REG_STATUS_BIT_ERROR) { 257 if (status & ATA_ERR) {
109 mg_dump_status("mg_wait", status, host); 258 mg_dump_status("mg_wait", status, host);
110 break; 259 break;
111 } 260 }
@@ -114,8 +263,8 @@ static unsigned int mg_wait(struct mg_host *host, u32 expect, u32 msec)
114 if (MG_READY_OK(status)) 263 if (MG_READY_OK(status))
115 break; 264 break;
116 265
117 if (expect == MG_REG_STATUS_BIT_DATA_REQ) 266 if (expect == ATA_DRQ)
118 if (status & MG_REG_STATUS_BIT_DATA_REQ) 267 if (status & ATA_DRQ)
119 break; 268 break;
120 } 269 }
121 if (!msec) { 270 if (!msec) {
@@ -173,6 +322,42 @@ static irqreturn_t mg_irq(int irq, void *dev_id)
173 return IRQ_HANDLED; 322 return IRQ_HANDLED;
174} 323}
175 324
325/* local copy of ata_id_string() */
326static void mg_id_string(const u16 *id, unsigned char *s,
327 unsigned int ofs, unsigned int len)
328{
329 unsigned int c;
330
331 BUG_ON(len & 1);
332
333 while (len > 0) {
334 c = id[ofs] >> 8;
335 *s = c;
336 s++;
337
338 c = id[ofs] & 0xff;
339 *s = c;
340 s++;
341
342 ofs++;
343 len -= 2;
344 }
345}
346
347/* local copy of ata_id_c_string() */
348static void mg_id_c_string(const u16 *id, unsigned char *s,
349 unsigned int ofs, unsigned int len)
350{
351 unsigned char *p;
352
353 mg_id_string(id, s, ofs, len - 1);
354
355 p = s + strnlen(s, len - 1);
356 while (p > s && p[-1] == ' ')
357 p--;
358 *p = '\0';
359}
360
176static int mg_get_disk_id(struct mg_host *host) 361static int mg_get_disk_id(struct mg_host *host)
177{ 362{
178 u32 i; 363 u32 i;
@@ -184,12 +369,10 @@ static int mg_get_disk_id(struct mg_host *host)
184 char serial[ATA_ID_SERNO_LEN + 1]; 369 char serial[ATA_ID_SERNO_LEN + 1];
185 370
186 if (!prv_data->use_polling) 371 if (!prv_data->use_polling)
187 outb(MG_REG_CTRL_INTR_DISABLE, 372 outb(ATA_NIEN, (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
188 (unsigned long)host->dev_base +
189 MG_REG_DRV_CTRL);
190 373
191 outb(MG_CMD_ID, (unsigned long)host->dev_base + MG_REG_COMMAND); 374 outb(MG_CMD_ID, (unsigned long)host->dev_base + MG_REG_COMMAND);
192 err = mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, MG_TMAX_WAIT_RD_DRQ); 375 err = mg_wait(host, ATA_DRQ, MG_TMAX_WAIT_RD_DRQ);
193 if (err) 376 if (err)
194 return err; 377 return err;
195 378
@@ -219,9 +402,9 @@ static int mg_get_disk_id(struct mg_host *host)
219 host->n_sectors -= host->nres_sectors; 402 host->n_sectors -= host->nres_sectors;
220 } 403 }
221 404
222 ata_id_c_string(id, fwrev, ATA_ID_FW_REV, sizeof(fwrev)); 405 mg_id_c_string(id, fwrev, ATA_ID_FW_REV, sizeof(fwrev));
223 ata_id_c_string(id, model, ATA_ID_PROD, sizeof(model)); 406 mg_id_c_string(id, model, ATA_ID_PROD, sizeof(model));
224 ata_id_c_string(id, serial, ATA_ID_SERNO, sizeof(serial)); 407 mg_id_c_string(id, serial, ATA_ID_SERNO, sizeof(serial));
225 printk(KERN_INFO "mg_disk: model: %s\n", model); 408 printk(KERN_INFO "mg_disk: model: %s\n", model);
226 printk(KERN_INFO "mg_disk: firm: %.8s\n", fwrev); 409 printk(KERN_INFO "mg_disk: firm: %.8s\n", fwrev);
227 printk(KERN_INFO "mg_disk: serial: %s\n", serial); 410 printk(KERN_INFO "mg_disk: serial: %s\n", serial);
@@ -229,8 +412,7 @@ static int mg_get_disk_id(struct mg_host *host)
229 host->n_sectors, host->nres_sectors); 412 host->n_sectors, host->nres_sectors);
230 413
231 if (!prv_data->use_polling) 414 if (!prv_data->use_polling)
232 outb(MG_REG_CTRL_INTR_ENABLE, (unsigned long)host->dev_base + 415 outb(0, (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
233 MG_REG_DRV_CTRL);
234 416
235 return err; 417 return err;
236} 418}
@@ -244,7 +426,7 @@ static int mg_disk_init(struct mg_host *host)
244 426
245 /* hdd rst low */ 427 /* hdd rst low */
246 gpio_set_value(host->rst, 0); 428 gpio_set_value(host->rst, 0);
247 err = mg_wait(host, MG_REG_STATUS_BIT_BUSY, MG_TMAX_RST_TO_BUSY); 429 err = mg_wait(host, ATA_BUSY, MG_TMAX_RST_TO_BUSY);
248 if (err) 430 if (err)
249 return err; 431 return err;
250 432
@@ -255,17 +437,14 @@ static int mg_disk_init(struct mg_host *host)
255 return err; 437 return err;
256 438
257 /* soft reset on */ 439 /* soft reset on */
258 outb(MG_REG_CTRL_RESET | 440 outb(ATA_SRST | (prv_data->use_polling ? ATA_NIEN : 0),
259 (prv_data->use_polling ? MG_REG_CTRL_INTR_DISABLE :
260 MG_REG_CTRL_INTR_ENABLE),
261 (unsigned long)host->dev_base + MG_REG_DRV_CTRL); 441 (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
262 err = mg_wait(host, MG_REG_STATUS_BIT_BUSY, MG_TMAX_RST_TO_BUSY); 442 err = mg_wait(host, ATA_BUSY, MG_TMAX_RST_TO_BUSY);
263 if (err) 443 if (err)
264 return err; 444 return err;
265 445
266 /* soft reset off */ 446 /* soft reset off */
267 outb(prv_data->use_polling ? MG_REG_CTRL_INTR_DISABLE : 447 outb(prv_data->use_polling ? ATA_NIEN : 0,
268 MG_REG_CTRL_INTR_ENABLE,
269 (unsigned long)host->dev_base + MG_REG_DRV_CTRL); 448 (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
270 err = mg_wait(host, MG_STAT_READY, MG_TMAX_SWRST_TO_RDY); 449 err = mg_wait(host, MG_STAT_READY, MG_TMAX_SWRST_TO_RDY);
271 if (err) 450 if (err)
@@ -281,11 +460,10 @@ static int mg_disk_init(struct mg_host *host)
281 460
282static void mg_bad_rw_intr(struct mg_host *host) 461static void mg_bad_rw_intr(struct mg_host *host)
283{ 462{
284 struct request *req = elv_next_request(host->breq); 463 if (host->req)
285 if (req != NULL) 464 if (++host->req->errors >= MG_MAX_ERRORS ||
286 if (++req->errors >= MG_MAX_ERRORS || 465 host->error == MG_ERR_TIMEOUT)
287 host->error == MG_ERR_TIMEOUT) 466 mg_end_request_cur(host, -EIO);
288 end_request(req, 0);
289} 467}
290 468
291static unsigned int mg_out(struct mg_host *host, 469static unsigned int mg_out(struct mg_host *host,
@@ -311,7 +489,7 @@ static unsigned int mg_out(struct mg_host *host,
311 MG_REG_CYL_LOW); 489 MG_REG_CYL_LOW);
312 outb((u8)(sect_num >> 16), (unsigned long)host->dev_base + 490 outb((u8)(sect_num >> 16), (unsigned long)host->dev_base +
313 MG_REG_CYL_HIGH); 491 MG_REG_CYL_HIGH);
314 outb((u8)((sect_num >> 24) | MG_REG_HEAD_LBA_MODE), 492 outb((u8)((sect_num >> 24) | ATA_LBA | ATA_DEVICE_OBS),
315 (unsigned long)host->dev_base + MG_REG_DRV_HEAD); 493 (unsigned long)host->dev_base + MG_REG_DRV_HEAD);
316 outb(cmd, (unsigned long)host->dev_base + MG_REG_COMMAND); 494 outb(cmd, (unsigned long)host->dev_base + MG_REG_COMMAND);
317 return MG_ERR_NONE; 495 return MG_ERR_NONE;
@@ -319,105 +497,77 @@ static unsigned int mg_out(struct mg_host *host,
319 497
320static void mg_read(struct request *req) 498static void mg_read(struct request *req)
321{ 499{
322 u32 remains, j; 500 u32 j;
323 struct mg_host *host = req->rq_disk->private_data; 501 struct mg_host *host = req->rq_disk->private_data;
324 502
325 remains = req->nr_sectors; 503 if (mg_out(host, blk_rq_pos(req), blk_rq_sectors(req),
326 504 MG_CMD_RD, NULL) != MG_ERR_NONE)
327 if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_RD, NULL) !=
328 MG_ERR_NONE)
329 mg_bad_rw_intr(host); 505 mg_bad_rw_intr(host);
330 506
331 MG_DBG("requested %d sects (from %ld), buffer=0x%p\n", 507 MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
332 remains, req->sector, req->buffer); 508 blk_rq_sectors(req), blk_rq_pos(req), req->buffer);
509
510 do {
511 u16 *buff = (u16 *)req->buffer;
333 512
334 while (remains) { 513 if (mg_wait(host, ATA_DRQ,
335 if (mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, 514 MG_TMAX_WAIT_RD_DRQ) != MG_ERR_NONE) {
336 MG_TMAX_WAIT_RD_DRQ) != MG_ERR_NONE) {
337 mg_bad_rw_intr(host); 515 mg_bad_rw_intr(host);
338 return; 516 return;
339 } 517 }
340 for (j = 0; j < MG_SECTOR_SIZE >> 1; j++) { 518 for (j = 0; j < MG_SECTOR_SIZE >> 1; j++)
341 *(u16 *)req->buffer = 519 *buff++ = inw((unsigned long)host->dev_base +
342 inw((unsigned long)host->dev_base + 520 MG_BUFF_OFFSET + (j << 1));
343 MG_BUFF_OFFSET + (j << 1));
344 req->buffer += 2;
345 }
346
347 req->sector++;
348 req->errors = 0;
349 remains = --req->nr_sectors;
350 --req->current_nr_sectors;
351
352 if (req->current_nr_sectors <= 0) {
353 MG_DBG("remain : %d sects\n", remains);
354 end_request(req, 1);
355 if (remains > 0)
356 req = elv_next_request(host->breq);
357 }
358 521
359 outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base + 522 outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base +
360 MG_REG_COMMAND); 523 MG_REG_COMMAND);
361 } 524 } while (mg_end_request(host, 0, MG_SECTOR_SIZE));
362} 525}
363 526
364static void mg_write(struct request *req) 527static void mg_write(struct request *req)
365{ 528{
366 u32 remains, j; 529 u32 j;
367 struct mg_host *host = req->rq_disk->private_data; 530 struct mg_host *host = req->rq_disk->private_data;
368 531
369 remains = req->nr_sectors; 532 if (mg_out(host, blk_rq_pos(req), blk_rq_sectors(req),
370 533 MG_CMD_WR, NULL) != MG_ERR_NONE) {
371 if (mg_out(host, req->sector, req->nr_sectors, MG_CMD_WR, NULL) !=
372 MG_ERR_NONE) {
373 mg_bad_rw_intr(host); 534 mg_bad_rw_intr(host);
374 return; 535 return;
375 } 536 }
376 537
377
378 MG_DBG("requested %d sects (from %ld), buffer=0x%p\n", 538 MG_DBG("requested %d sects (from %ld), buffer=0x%p\n",
379 remains, req->sector, req->buffer); 539 blk_rq_sectors(req), blk_rq_pos(req), req->buffer);
380 while (remains) { 540
381 if (mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, 541 do {
382 MG_TMAX_WAIT_WR_DRQ) != MG_ERR_NONE) { 542 u16 *buff = (u16 *)req->buffer;
543
544 if (mg_wait(host, ATA_DRQ, MG_TMAX_WAIT_WR_DRQ) != MG_ERR_NONE) {
383 mg_bad_rw_intr(host); 545 mg_bad_rw_intr(host);
384 return; 546 return;
385 } 547 }
386 for (j = 0; j < MG_SECTOR_SIZE >> 1; j++) { 548 for (j = 0; j < MG_SECTOR_SIZE >> 1; j++)
387 outw(*(u16 *)req->buffer, 549 outw(*buff++, (unsigned long)host->dev_base +
388 (unsigned long)host->dev_base + 550 MG_BUFF_OFFSET + (j << 1));
389 MG_BUFF_OFFSET + (j << 1));
390 req->buffer += 2;
391 }
392 req->sector++;
393 remains = --req->nr_sectors;
394 --req->current_nr_sectors;
395
396 if (req->current_nr_sectors <= 0) {
397 MG_DBG("remain : %d sects\n", remains);
398 end_request(req, 1);
399 if (remains > 0)
400 req = elv_next_request(host->breq);
401 }
402 551
403 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base + 552 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base +
404 MG_REG_COMMAND); 553 MG_REG_COMMAND);
405 } 554 } while (mg_end_request(host, 0, MG_SECTOR_SIZE));
406} 555}
407 556
408static void mg_read_intr(struct mg_host *host) 557static void mg_read_intr(struct mg_host *host)
409{ 558{
559 struct request *req = host->req;
410 u32 i; 560 u32 i;
411 struct request *req; 561 u16 *buff;
412 562
413 /* check status */ 563 /* check status */
414 do { 564 do {
415 i = inb((unsigned long)host->dev_base + MG_REG_STATUS); 565 i = inb((unsigned long)host->dev_base + MG_REG_STATUS);
416 if (i & MG_REG_STATUS_BIT_BUSY) 566 if (i & ATA_BUSY)
417 break; 567 break;
418 if (!MG_READY_OK(i)) 568 if (!MG_READY_OK(i))
419 break; 569 break;
420 if (i & MG_REG_STATUS_BIT_DATA_REQ) 570 if (i & ATA_DRQ)
421 goto ok_to_read; 571 goto ok_to_read;
422 } while (0); 572 } while (0);
423 mg_dump_status("mg_read_intr", i, host); 573 mg_dump_status("mg_read_intr", i, host);
@@ -427,60 +577,42 @@ static void mg_read_intr(struct mg_host *host)
427 577
428ok_to_read: 578ok_to_read:
429 /* get current segment of request */ 579 /* get current segment of request */
430 req = elv_next_request(host->breq); 580 buff = (u16 *)req->buffer;
431 581
432 /* read 1 sector */ 582 /* read 1 sector */
433 for (i = 0; i < MG_SECTOR_SIZE >> 1; i++) { 583 for (i = 0; i < MG_SECTOR_SIZE >> 1; i++)
434 *(u16 *)req->buffer = 584 *buff++ = inw((unsigned long)host->dev_base + MG_BUFF_OFFSET +
435 inw((unsigned long)host->dev_base + MG_BUFF_OFFSET + 585 (i << 1));
436 (i << 1));
437 req->buffer += 2;
438 }
439 586
440 /* manipulate request */
441 MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n", 587 MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
442 req->sector, req->nr_sectors - 1, req->buffer); 588 blk_rq_pos(req), blk_rq_sectors(req) - 1, req->buffer);
443
444 req->sector++;
445 req->errors = 0;
446 i = --req->nr_sectors;
447 --req->current_nr_sectors;
448
449 /* let know if current segment done */
450 if (req->current_nr_sectors <= 0)
451 end_request(req, 1);
452
453 /* set handler if read remains */
454 if (i > 0) {
455 host->mg_do_intr = mg_read_intr;
456 mod_timer(&host->timer, jiffies + 3 * HZ);
457 }
458 589
459 /* send read confirm */ 590 /* send read confirm */
460 outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND); 591 outb(MG_CMD_RD_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND);
461 592
462 /* goto next request */ 593 if (mg_end_request(host, 0, MG_SECTOR_SIZE)) {
463 if (!i) 594 /* set handler if read remains */
595 host->mg_do_intr = mg_read_intr;
596 mod_timer(&host->timer, jiffies + 3 * HZ);
597 } else /* goto next request */
464 mg_request(host->breq); 598 mg_request(host->breq);
465} 599}
466 600
467static void mg_write_intr(struct mg_host *host) 601static void mg_write_intr(struct mg_host *host)
468{ 602{
603 struct request *req = host->req;
469 u32 i, j; 604 u32 i, j;
470 u16 *buff; 605 u16 *buff;
471 struct request *req; 606 bool rem;
472
473 /* get current segment of request */
474 req = elv_next_request(host->breq);
475 607
476 /* check status */ 608 /* check status */
477 do { 609 do {
478 i = inb((unsigned long)host->dev_base + MG_REG_STATUS); 610 i = inb((unsigned long)host->dev_base + MG_REG_STATUS);
479 if (i & MG_REG_STATUS_BIT_BUSY) 611 if (i & ATA_BUSY)
480 break; 612 break;
481 if (!MG_READY_OK(i)) 613 if (!MG_READY_OK(i))
482 break; 614 break;
483 if ((req->nr_sectors <= 1) || (i & MG_REG_STATUS_BIT_DATA_REQ)) 615 if ((blk_rq_sectors(req) <= 1) || (i & ATA_DRQ))
484 goto ok_to_write; 616 goto ok_to_write;
485 } while (0); 617 } while (0);
486 mg_dump_status("mg_write_intr", i, host); 618 mg_dump_status("mg_write_intr", i, host);
@@ -489,18 +621,8 @@ static void mg_write_intr(struct mg_host *host)
489 return; 621 return;
490 622
491ok_to_write: 623ok_to_write:
492 /* manipulate request */ 624 if ((rem = mg_end_request(host, 0, MG_SECTOR_SIZE))) {
493 req->sector++; 625 /* write 1 sector and set handler if remains */
494 i = --req->nr_sectors;
495 --req->current_nr_sectors;
496 req->buffer += MG_SECTOR_SIZE;
497
498 /* let know if current segment or all done */
499 if (!i || (req->bio && req->current_nr_sectors <= 0))
500 end_request(req, 1);
501
502 /* write 1 sector and set handler if remains */
503 if (i > 0) {
504 buff = (u16 *)req->buffer; 626 buff = (u16 *)req->buffer;
505 for (j = 0; j < MG_STORAGE_BUFFER_SIZE >> 1; j++) { 627 for (j = 0; j < MG_STORAGE_BUFFER_SIZE >> 1; j++) {
506 outw(*buff, (unsigned long)host->dev_base + 628 outw(*buff, (unsigned long)host->dev_base +
@@ -508,7 +630,7 @@ ok_to_write:
508 buff++; 630 buff++;
509 } 631 }
510 MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n", 632 MG_DBG("sector %ld, remaining=%ld, buffer=0x%p\n",
511 req->sector, req->nr_sectors, req->buffer); 633 blk_rq_pos(req), blk_rq_sectors(req), req->buffer);
512 host->mg_do_intr = mg_write_intr; 634 host->mg_do_intr = mg_write_intr;
513 mod_timer(&host->timer, jiffies + 3 * HZ); 635 mod_timer(&host->timer, jiffies + 3 * HZ);
514 } 636 }
@@ -516,7 +638,7 @@ ok_to_write:
516 /* send write confirm */ 638 /* send write confirm */
517 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND); 639 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base + MG_REG_COMMAND);
518 640
519 if (!i) 641 if (!rem)
520 mg_request(host->breq); 642 mg_request(host->breq);
521} 643}
522 644
@@ -524,49 +646,45 @@ void mg_times_out(unsigned long data)
524{ 646{
525 struct mg_host *host = (struct mg_host *)data; 647 struct mg_host *host = (struct mg_host *)data;
526 char *name; 648 char *name;
527 struct request *req;
528 649
529 spin_lock_irq(&host->lock); 650 spin_lock_irq(&host->lock);
530 651
531 req = elv_next_request(host->breq); 652 if (!host->req)
532 if (!req)
533 goto out_unlock; 653 goto out_unlock;
534 654
535 host->mg_do_intr = NULL; 655 host->mg_do_intr = NULL;
536 656
537 name = req->rq_disk->disk_name; 657 name = host->req->rq_disk->disk_name;
538 printk(KERN_DEBUG "%s: timeout\n", name); 658 printk(KERN_DEBUG "%s: timeout\n", name);
539 659
540 host->error = MG_ERR_TIMEOUT; 660 host->error = MG_ERR_TIMEOUT;
541 mg_bad_rw_intr(host); 661 mg_bad_rw_intr(host);
542 662
543 mg_request(host->breq);
544out_unlock: 663out_unlock:
664 mg_request(host->breq);
545 spin_unlock_irq(&host->lock); 665 spin_unlock_irq(&host->lock);
546} 666}
547 667
548static void mg_request_poll(struct request_queue *q) 668static void mg_request_poll(struct request_queue *q)
549{ 669{
550 struct request *req; 670 struct mg_host *host = q->queuedata;
551 struct mg_host *host;
552 671
553 while ((req = elv_next_request(q)) != NULL) { 672 while (1) {
554 host = req->rq_disk->private_data; 673 if (!host->req) {
555 if (blk_fs_request(req)) { 674 host->req = blk_fetch_request(q);
556 switch (rq_data_dir(req)) { 675 if (!host->req)
557 case READ:
558 mg_read(req);
559 break;
560 case WRITE:
561 mg_write(req);
562 break;
563 default:
564 printk(KERN_WARNING "%s:%d unknown command\n",
565 __func__, __LINE__);
566 end_request(req, 0);
567 break; 676 break;
568 }
569 } 677 }
678
679 if (unlikely(!blk_fs_request(host->req))) {
680 mg_end_request_cur(host, -EIO);
681 continue;
682 }
683
684 if (rq_data_dir(host->req) == READ)
685 mg_read(host->req);
686 else
687 mg_write(host->req);
570 } 688 }
571} 689}
572 690
@@ -588,18 +706,15 @@ static unsigned int mg_issue_req(struct request *req,
588 break; 706 break;
589 case WRITE: 707 case WRITE:
590 /* TODO : handler */ 708 /* TODO : handler */
591 outb(MG_REG_CTRL_INTR_DISABLE, 709 outb(ATA_NIEN, (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
592 (unsigned long)host->dev_base +
593 MG_REG_DRV_CTRL);
594 if (mg_out(host, sect_num, sect_cnt, MG_CMD_WR, &mg_write_intr) 710 if (mg_out(host, sect_num, sect_cnt, MG_CMD_WR, &mg_write_intr)
595 != MG_ERR_NONE) { 711 != MG_ERR_NONE) {
596 mg_bad_rw_intr(host); 712 mg_bad_rw_intr(host);
597 return host->error; 713 return host->error;
598 } 714 }
599 del_timer(&host->timer); 715 del_timer(&host->timer);
600 mg_wait(host, MG_REG_STATUS_BIT_DATA_REQ, MG_TMAX_WAIT_WR_DRQ); 716 mg_wait(host, ATA_DRQ, MG_TMAX_WAIT_WR_DRQ);
601 outb(MG_REG_CTRL_INTR_ENABLE, (unsigned long)host->dev_base + 717 outb(0, (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
602 MG_REG_DRV_CTRL);
603 if (host->error) { 718 if (host->error) {
604 mg_bad_rw_intr(host); 719 mg_bad_rw_intr(host);
605 return host->error; 720 return host->error;
@@ -614,11 +729,6 @@ static unsigned int mg_issue_req(struct request *req,
614 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base + 729 outb(MG_CMD_WR_CONF, (unsigned long)host->dev_base +
615 MG_REG_COMMAND); 730 MG_REG_COMMAND);
616 break; 731 break;
617 default:
618 printk(KERN_WARNING "%s:%d unknown command\n",
619 __func__, __LINE__);
620 end_request(req, 0);
621 break;
622 } 732 }
623 return MG_ERR_NONE; 733 return MG_ERR_NONE;
624} 734}
@@ -626,16 +736,17 @@ static unsigned int mg_issue_req(struct request *req,
626/* This function also called from IRQ context */ 736/* This function also called from IRQ context */
627static void mg_request(struct request_queue *q) 737static void mg_request(struct request_queue *q)
628{ 738{
739 struct mg_host *host = q->queuedata;
629 struct request *req; 740 struct request *req;
630 struct mg_host *host;
631 u32 sect_num, sect_cnt; 741 u32 sect_num, sect_cnt;
632 742
633 while (1) { 743 while (1) {
634 req = elv_next_request(q); 744 if (!host->req) {
635 if (!req) 745 host->req = blk_fetch_request(q);
636 return; 746 if (!host->req)
637 747 break;
638 host = req->rq_disk->private_data; 748 }
749 req = host->req;
639 750
640 /* check unwanted request call */ 751 /* check unwanted request call */
641 if (host->mg_do_intr) 752 if (host->mg_do_intr)
@@ -643,9 +754,9 @@ static void mg_request(struct request_queue *q)
643 754
644 del_timer(&host->timer); 755 del_timer(&host->timer);
645 756
646 sect_num = req->sector; 757 sect_num = blk_rq_pos(req);
647 /* deal whole segments */ 758 /* deal whole segments */
648 sect_cnt = req->nr_sectors; 759 sect_cnt = blk_rq_sectors(req);
649 760
650 /* sanity check */ 761 /* sanity check */
651 if (sect_num >= get_capacity(req->rq_disk) || 762 if (sect_num >= get_capacity(req->rq_disk) ||
@@ -655,12 +766,14 @@ static void mg_request(struct request_queue *q)
655 "%s: bad access: sector=%d, count=%d\n", 766 "%s: bad access: sector=%d, count=%d\n",
656 req->rq_disk->disk_name, 767 req->rq_disk->disk_name,
657 sect_num, sect_cnt); 768 sect_num, sect_cnt);
658 end_request(req, 0); 769 mg_end_request_cur(host, -EIO);
659 continue; 770 continue;
660 } 771 }
661 772
662 if (!blk_fs_request(req)) 773 if (unlikely(!blk_fs_request(req))) {
663 return; 774 mg_end_request_cur(host, -EIO);
775 continue;
776 }
664 777
665 if (!mg_issue_req(req, host, sect_num, sect_cnt)) 778 if (!mg_issue_req(req, host, sect_num, sect_cnt))
666 return; 779 return;
@@ -690,9 +803,7 @@ static int mg_suspend(struct platform_device *plat_dev, pm_message_t state)
690 return -EIO; 803 return -EIO;
691 804
692 if (!prv_data->use_polling) 805 if (!prv_data->use_polling)
693 outb(MG_REG_CTRL_INTR_DISABLE, 806 outb(ATA_NIEN, (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
694 (unsigned long)host->dev_base +
695 MG_REG_DRV_CTRL);
696 807
697 outb(MG_CMD_SLEEP, (unsigned long)host->dev_base + MG_REG_COMMAND); 808 outb(MG_CMD_SLEEP, (unsigned long)host->dev_base + MG_REG_COMMAND);
698 /* wait until mflash deep sleep */ 809 /* wait until mflash deep sleep */
@@ -700,9 +811,7 @@ static int mg_suspend(struct platform_device *plat_dev, pm_message_t state)
700 811
701 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD)) { 812 if (mg_wait(host, MG_STAT_READY, MG_TMAX_CONF_TO_CMD)) {
702 if (!prv_data->use_polling) 813 if (!prv_data->use_polling)
703 outb(MG_REG_CTRL_INTR_ENABLE, 814 outb(0, (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
704 (unsigned long)host->dev_base +
705 MG_REG_DRV_CTRL);
706 return -EIO; 815 return -EIO;
707 } 816 }
708 817
@@ -725,8 +834,7 @@ static int mg_resume(struct platform_device *plat_dev)
725 return -EIO; 834 return -EIO;
726 835
727 if (!prv_data->use_polling) 836 if (!prv_data->use_polling)
728 outb(MG_REG_CTRL_INTR_ENABLE, (unsigned long)host->dev_base + 837 outb(0, (unsigned long)host->dev_base + MG_REG_DRV_CTRL);
729 MG_REG_DRV_CTRL);
730 838
731 return 0; 839 return 0;
732} 840}
@@ -877,6 +985,7 @@ static int mg_probe(struct platform_device *plat_dev)
877 __func__, __LINE__); 985 __func__, __LINE__);
878 goto probe_err_5; 986 goto probe_err_5;
879 } 987 }
988 host->breq->queuedata = host;
880 989
881 /* mflash is random device, thanx for the noop */ 990 /* mflash is random device, thanx for the noop */
882 elevator_exit(host->breq->elevator); 991 elevator_exit(host->breq->elevator);
@@ -887,7 +996,7 @@ static int mg_probe(struct platform_device *plat_dev)
887 goto probe_err_6; 996 goto probe_err_6;
888 } 997 }
889 blk_queue_max_sectors(host->breq, MG_MAX_SECTS); 998 blk_queue_max_sectors(host->breq, MG_MAX_SECTS);
890 blk_queue_hardsect_size(host->breq, MG_SECTOR_SIZE); 999 blk_queue_logical_block_size(host->breq, MG_SECTOR_SIZE);
891 1000
892 init_timer(&host->timer); 1001 init_timer(&host->timer);
893 host->timer.function = mg_times_out; 1002 host->timer.function = mg_times_out;
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 4d6de4f15ccb..5d23ffad7c77 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -110,7 +110,7 @@ static void nbd_end_request(struct request *req)
110 req, error ? "failed" : "done"); 110 req, error ? "failed" : "done");
111 111
112 spin_lock_irqsave(q->queue_lock, flags); 112 spin_lock_irqsave(q->queue_lock, flags);
113 __blk_end_request(req, error, req->nr_sectors << 9); 113 __blk_end_request_all(req, error);
114 spin_unlock_irqrestore(q->queue_lock, flags); 114 spin_unlock_irqrestore(q->queue_lock, flags);
115} 115}
116 116
@@ -231,19 +231,19 @@ static int nbd_send_req(struct nbd_device *lo, struct request *req)
231{ 231{
232 int result, flags; 232 int result, flags;
233 struct nbd_request request; 233 struct nbd_request request;
234 unsigned long size = req->nr_sectors << 9; 234 unsigned long size = blk_rq_bytes(req);
235 235
236 request.magic = htonl(NBD_REQUEST_MAGIC); 236 request.magic = htonl(NBD_REQUEST_MAGIC);
237 request.type = htonl(nbd_cmd(req)); 237 request.type = htonl(nbd_cmd(req));
238 request.from = cpu_to_be64((u64) req->sector << 9); 238 request.from = cpu_to_be64((u64)blk_rq_pos(req) << 9);
239 request.len = htonl(size); 239 request.len = htonl(size);
240 memcpy(request.handle, &req, sizeof(req)); 240 memcpy(request.handle, &req, sizeof(req));
241 241
242 dprintk(DBG_TX, "%s: request %p: sending control (%s@%llu,%luB)\n", 242 dprintk(DBG_TX, "%s: request %p: sending control (%s@%llu,%uB)\n",
243 lo->disk->disk_name, req, 243 lo->disk->disk_name, req,
244 nbdcmd_to_ascii(nbd_cmd(req)), 244 nbdcmd_to_ascii(nbd_cmd(req)),
245 (unsigned long long)req->sector << 9, 245 (unsigned long long)blk_rq_pos(req) << 9,
246 req->nr_sectors << 9); 246 blk_rq_bytes(req));
247 result = sock_xmit(lo, 1, &request, sizeof(request), 247 result = sock_xmit(lo, 1, &request, sizeof(request),
248 (nbd_cmd(req) == NBD_CMD_WRITE) ? MSG_MORE : 0); 248 (nbd_cmd(req) == NBD_CMD_WRITE) ? MSG_MORE : 0);
249 if (result <= 0) { 249 if (result <= 0) {
@@ -533,11 +533,9 @@ static void do_nbd_request(struct request_queue *q)
533{ 533{
534 struct request *req; 534 struct request *req;
535 535
536 while ((req = elv_next_request(q)) != NULL) { 536 while ((req = blk_fetch_request(q)) != NULL) {
537 struct nbd_device *lo; 537 struct nbd_device *lo;
538 538
539 blkdev_dequeue_request(req);
540
541 spin_unlock_irq(q->queue_lock); 539 spin_unlock_irq(q->queue_lock);
542 540
543 dprintk(DBG_BLKDEV, "%s: request %p: dequeued (flags=%x)\n", 541 dprintk(DBG_BLKDEV, "%s: request %p: dequeued (flags=%x)\n",
@@ -580,13 +578,6 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
580 blk_rq_init(NULL, &sreq); 578 blk_rq_init(NULL, &sreq);
581 sreq.cmd_type = REQ_TYPE_SPECIAL; 579 sreq.cmd_type = REQ_TYPE_SPECIAL;
582 nbd_cmd(&sreq) = NBD_CMD_DISC; 580 nbd_cmd(&sreq) = NBD_CMD_DISC;
583 /*
584 * Set these to sane values in case server implementation
585 * fails to check the request type first and also to keep
586 * debugging output cleaner.
587 */
588 sreq.sector = 0;
589 sreq.nr_sectors = 0;
590 if (!lo->sock) 581 if (!lo->sock)
591 return -EINVAL; 582 return -EINVAL;
592 nbd_send_req(lo, &sreq); 583 nbd_send_req(lo, &sreq);
diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c
index e91d4b4b014f..911dfd98d813 100644
--- a/drivers/block/paride/pcd.c
+++ b/drivers/block/paride/pcd.c
@@ -719,32 +719,37 @@ static void do_pcd_request(struct request_queue * q)
719 if (pcd_busy) 719 if (pcd_busy)
720 return; 720 return;
721 while (1) { 721 while (1) {
722 pcd_req = elv_next_request(q); 722 if (!pcd_req) {
723 if (!pcd_req) 723 pcd_req = blk_fetch_request(q);
724 return; 724 if (!pcd_req)
725 return;
726 }
725 727
726 if (rq_data_dir(pcd_req) == READ) { 728 if (rq_data_dir(pcd_req) == READ) {
727 struct pcd_unit *cd = pcd_req->rq_disk->private_data; 729 struct pcd_unit *cd = pcd_req->rq_disk->private_data;
728 if (cd != pcd_current) 730 if (cd != pcd_current)
729 pcd_bufblk = -1; 731 pcd_bufblk = -1;
730 pcd_current = cd; 732 pcd_current = cd;
731 pcd_sector = pcd_req->sector; 733 pcd_sector = blk_rq_pos(pcd_req);
732 pcd_count = pcd_req->current_nr_sectors; 734 pcd_count = blk_rq_cur_sectors(pcd_req);
733 pcd_buf = pcd_req->buffer; 735 pcd_buf = pcd_req->buffer;
734 pcd_busy = 1; 736 pcd_busy = 1;
735 ps_set_intr(do_pcd_read, NULL, 0, nice); 737 ps_set_intr(do_pcd_read, NULL, 0, nice);
736 return; 738 return;
737 } else 739 } else {
738 end_request(pcd_req, 0); 740 __blk_end_request_all(pcd_req, -EIO);
741 pcd_req = NULL;
742 }
739 } 743 }
740} 744}
741 745
742static inline void next_request(int success) 746static inline void next_request(int err)
743{ 747{
744 unsigned long saved_flags; 748 unsigned long saved_flags;
745 749
746 spin_lock_irqsave(&pcd_lock, saved_flags); 750 spin_lock_irqsave(&pcd_lock, saved_flags);
747 end_request(pcd_req, success); 751 if (!__blk_end_request_cur(pcd_req, err))
752 pcd_req = NULL;
748 pcd_busy = 0; 753 pcd_busy = 0;
749 do_pcd_request(pcd_queue); 754 do_pcd_request(pcd_queue);
750 spin_unlock_irqrestore(&pcd_lock, saved_flags); 755 spin_unlock_irqrestore(&pcd_lock, saved_flags);
@@ -781,7 +786,7 @@ static void pcd_start(void)
781 786
782 if (pcd_command(pcd_current, rd_cmd, 2048, "read block")) { 787 if (pcd_command(pcd_current, rd_cmd, 2048, "read block")) {
783 pcd_bufblk = -1; 788 pcd_bufblk = -1;
784 next_request(0); 789 next_request(-EIO);
785 return; 790 return;
786 } 791 }
787 792
@@ -796,7 +801,7 @@ static void do_pcd_read(void)
796 pcd_retries = 0; 801 pcd_retries = 0;
797 pcd_transfer(); 802 pcd_transfer();
798 if (!pcd_count) { 803 if (!pcd_count) {
799 next_request(1); 804 next_request(0);
800 return; 805 return;
801 } 806 }
802 807
@@ -815,7 +820,7 @@ static void do_pcd_read_drq(void)
815 return; 820 return;
816 } 821 }
817 pcd_bufblk = -1; 822 pcd_bufblk = -1;
818 next_request(0); 823 next_request(-EIO);
819 return; 824 return;
820 } 825 }
821 826
diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c
index 9299455b0af6..bf5955b3d873 100644
--- a/drivers/block/paride/pd.c
+++ b/drivers/block/paride/pd.c
@@ -410,10 +410,12 @@ static void run_fsm(void)
410 pd_claimed = 0; 410 pd_claimed = 0;
411 phase = NULL; 411 phase = NULL;
412 spin_lock_irqsave(&pd_lock, saved_flags); 412 spin_lock_irqsave(&pd_lock, saved_flags);
413 end_request(pd_req, res); 413 if (!__blk_end_request_cur(pd_req,
414 pd_req = elv_next_request(pd_queue); 414 res == Ok ? 0 : -EIO)) {
415 if (!pd_req) 415 pd_req = blk_fetch_request(pd_queue);
416 stop = 1; 416 if (!pd_req)
417 stop = 1;
418 }
417 spin_unlock_irqrestore(&pd_lock, saved_flags); 419 spin_unlock_irqrestore(&pd_lock, saved_flags);
418 if (stop) 420 if (stop)
419 return; 421 return;
@@ -443,11 +445,11 @@ static enum action do_pd_io_start(void)
443 445
444 pd_cmd = rq_data_dir(pd_req); 446 pd_cmd = rq_data_dir(pd_req);
445 if (pd_cmd == READ || pd_cmd == WRITE) { 447 if (pd_cmd == READ || pd_cmd == WRITE) {
446 pd_block = pd_req->sector; 448 pd_block = blk_rq_pos(pd_req);
447 pd_count = pd_req->current_nr_sectors; 449 pd_count = blk_rq_cur_sectors(pd_req);
448 if (pd_block + pd_count > get_capacity(pd_req->rq_disk)) 450 if (pd_block + pd_count > get_capacity(pd_req->rq_disk))
449 return Fail; 451 return Fail;
450 pd_run = pd_req->nr_sectors; 452 pd_run = blk_rq_sectors(pd_req);
451 pd_buf = pd_req->buffer; 453 pd_buf = pd_req->buffer;
452 pd_retries = 0; 454 pd_retries = 0;
453 if (pd_cmd == READ) 455 if (pd_cmd == READ)
@@ -477,8 +479,8 @@ static int pd_next_buf(void)
477 if (pd_count) 479 if (pd_count)
478 return 0; 480 return 0;
479 spin_lock_irqsave(&pd_lock, saved_flags); 481 spin_lock_irqsave(&pd_lock, saved_flags);
480 end_request(pd_req, 1); 482 __blk_end_request_cur(pd_req, 0);
481 pd_count = pd_req->current_nr_sectors; 483 pd_count = blk_rq_cur_sectors(pd_req);
482 pd_buf = pd_req->buffer; 484 pd_buf = pd_req->buffer;
483 spin_unlock_irqrestore(&pd_lock, saved_flags); 485 spin_unlock_irqrestore(&pd_lock, saved_flags);
484 return 0; 486 return 0;
@@ -702,7 +704,7 @@ static void do_pd_request(struct request_queue * q)
702{ 704{
703 if (pd_req) 705 if (pd_req)
704 return; 706 return;
705 pd_req = elv_next_request(q); 707 pd_req = blk_fetch_request(q);
706 if (!pd_req) 708 if (!pd_req)
707 return; 709 return;
708 710
diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c
index bef3b997ba3e..68a90834e993 100644
--- a/drivers/block/paride/pf.c
+++ b/drivers/block/paride/pf.c
@@ -750,12 +750,10 @@ static int pf_ready(void)
750 750
751static struct request_queue *pf_queue; 751static struct request_queue *pf_queue;
752 752
753static void pf_end_request(int uptodate) 753static void pf_end_request(int err)
754{ 754{
755 if (pf_req) { 755 if (pf_req && !__blk_end_request_cur(pf_req, err))
756 end_request(pf_req, uptodate);
757 pf_req = NULL; 756 pf_req = NULL;
758 }
759} 757}
760 758
761static void do_pf_request(struct request_queue * q) 759static void do_pf_request(struct request_queue * q)
@@ -763,17 +761,19 @@ static void do_pf_request(struct request_queue * q)
763 if (pf_busy) 761 if (pf_busy)
764 return; 762 return;
765repeat: 763repeat:
766 pf_req = elv_next_request(q); 764 if (!pf_req) {
767 if (!pf_req) 765 pf_req = blk_fetch_request(q);
768 return; 766 if (!pf_req)
767 return;
768 }
769 769
770 pf_current = pf_req->rq_disk->private_data; 770 pf_current = pf_req->rq_disk->private_data;
771 pf_block = pf_req->sector; 771 pf_block = blk_rq_pos(pf_req);
772 pf_run = pf_req->nr_sectors; 772 pf_run = blk_rq_sectors(pf_req);
773 pf_count = pf_req->current_nr_sectors; 773 pf_count = blk_rq_cur_sectors(pf_req);
774 774
775 if (pf_block + pf_count > get_capacity(pf_req->rq_disk)) { 775 if (pf_block + pf_count > get_capacity(pf_req->rq_disk)) {
776 pf_end_request(0); 776 pf_end_request(-EIO);
777 goto repeat; 777 goto repeat;
778 } 778 }
779 779
@@ -788,7 +788,7 @@ repeat:
788 pi_do_claimed(pf_current->pi, do_pf_write); 788 pi_do_claimed(pf_current->pi, do_pf_write);
789 else { 789 else {
790 pf_busy = 0; 790 pf_busy = 0;
791 pf_end_request(0); 791 pf_end_request(-EIO);
792 goto repeat; 792 goto repeat;
793 } 793 }
794} 794}
@@ -805,23 +805,22 @@ static int pf_next_buf(void)
805 return 1; 805 return 1;
806 if (!pf_count) { 806 if (!pf_count) {
807 spin_lock_irqsave(&pf_spin_lock, saved_flags); 807 spin_lock_irqsave(&pf_spin_lock, saved_flags);
808 pf_end_request(1); 808 pf_end_request(0);
809 pf_req = elv_next_request(pf_queue);
810 spin_unlock_irqrestore(&pf_spin_lock, saved_flags); 809 spin_unlock_irqrestore(&pf_spin_lock, saved_flags);
811 if (!pf_req) 810 if (!pf_req)
812 return 1; 811 return 1;
813 pf_count = pf_req->current_nr_sectors; 812 pf_count = blk_rq_cur_sectors(pf_req);
814 pf_buf = pf_req->buffer; 813 pf_buf = pf_req->buffer;
815 } 814 }
816 return 0; 815 return 0;
817} 816}
818 817
819static inline void next_request(int success) 818static inline void next_request(int err)
820{ 819{
821 unsigned long saved_flags; 820 unsigned long saved_flags;
822 821
823 spin_lock_irqsave(&pf_spin_lock, saved_flags); 822 spin_lock_irqsave(&pf_spin_lock, saved_flags);
824 pf_end_request(success); 823 pf_end_request(err);
825 pf_busy = 0; 824 pf_busy = 0;
826 do_pf_request(pf_queue); 825 do_pf_request(pf_queue);
827 spin_unlock_irqrestore(&pf_spin_lock, saved_flags); 826 spin_unlock_irqrestore(&pf_spin_lock, saved_flags);
@@ -844,7 +843,7 @@ static void do_pf_read_start(void)
844 pi_do_claimed(pf_current->pi, do_pf_read_start); 843 pi_do_claimed(pf_current->pi, do_pf_read_start);
845 return; 844 return;
846 } 845 }
847 next_request(0); 846 next_request(-EIO);
848 return; 847 return;
849 } 848 }
850 pf_mask = STAT_DRQ; 849 pf_mask = STAT_DRQ;
@@ -863,7 +862,7 @@ static void do_pf_read_drq(void)
863 pi_do_claimed(pf_current->pi, do_pf_read_start); 862 pi_do_claimed(pf_current->pi, do_pf_read_start);
864 return; 863 return;
865 } 864 }
866 next_request(0); 865 next_request(-EIO);
867 return; 866 return;
868 } 867 }
869 pi_read_block(pf_current->pi, pf_buf, 512); 868 pi_read_block(pf_current->pi, pf_buf, 512);
@@ -871,7 +870,7 @@ static void do_pf_read_drq(void)
871 break; 870 break;
872 } 871 }
873 pi_disconnect(pf_current->pi); 872 pi_disconnect(pf_current->pi);
874 next_request(1); 873 next_request(0);
875} 874}
876 875
877static void do_pf_write(void) 876static void do_pf_write(void)
@@ -890,7 +889,7 @@ static void do_pf_write_start(void)
890 pi_do_claimed(pf_current->pi, do_pf_write_start); 889 pi_do_claimed(pf_current->pi, do_pf_write_start);
891 return; 890 return;
892 } 891 }
893 next_request(0); 892 next_request(-EIO);
894 return; 893 return;
895 } 894 }
896 895
@@ -903,7 +902,7 @@ static void do_pf_write_start(void)
903 pi_do_claimed(pf_current->pi, do_pf_write_start); 902 pi_do_claimed(pf_current->pi, do_pf_write_start);
904 return; 903 return;
905 } 904 }
906 next_request(0); 905 next_request(-EIO);
907 return; 906 return;
908 } 907 }
909 pi_write_block(pf_current->pi, pf_buf, 512); 908 pi_write_block(pf_current->pi, pf_buf, 512);
@@ -923,11 +922,11 @@ static void do_pf_write_done(void)
923 pi_do_claimed(pf_current->pi, do_pf_write_start); 922 pi_do_claimed(pf_current->pi, do_pf_write_start);
924 return; 923 return;
925 } 924 }
926 next_request(0); 925 next_request(-EIO);
927 return; 926 return;
928 } 927 }
929 pi_disconnect(pf_current->pi); 928 pi_disconnect(pf_current->pi);
930 next_request(1); 929 next_request(0);
931} 930}
932 931
933static int __init pf_init(void) 932static int __init pf_init(void)
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index dc7a8c352da2..d57f11759480 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -991,13 +991,15 @@ static void pkt_iosched_process_queue(struct pktcdvd_device *pd)
991 */ 991 */
992static int pkt_set_segment_merging(struct pktcdvd_device *pd, struct request_queue *q) 992static int pkt_set_segment_merging(struct pktcdvd_device *pd, struct request_queue *q)
993{ 993{
994 if ((pd->settings.size << 9) / CD_FRAMESIZE <= q->max_phys_segments) { 994 if ((pd->settings.size << 9) / CD_FRAMESIZE
995 <= queue_max_phys_segments(q)) {
995 /* 996 /*
996 * The cdrom device can handle one segment/frame 997 * The cdrom device can handle one segment/frame
997 */ 998 */
998 clear_bit(PACKET_MERGE_SEGS, &pd->flags); 999 clear_bit(PACKET_MERGE_SEGS, &pd->flags);
999 return 0; 1000 return 0;
1000 } else if ((pd->settings.size << 9) / PAGE_SIZE <= q->max_phys_segments) { 1001 } else if ((pd->settings.size << 9) / PAGE_SIZE
1002 <= queue_max_phys_segments(q)) {
1001 /* 1003 /*
1002 * We can handle this case at the expense of some extra memory 1004 * We can handle this case at the expense of some extra memory
1003 * copies during write operations 1005 * copies during write operations
@@ -2657,7 +2659,7 @@ static void pkt_init_queue(struct pktcdvd_device *pd)
2657 struct request_queue *q = pd->disk->queue; 2659 struct request_queue *q = pd->disk->queue;
2658 2660
2659 blk_queue_make_request(q, pkt_make_request); 2661 blk_queue_make_request(q, pkt_make_request);
2660 blk_queue_hardsect_size(q, CD_FRAMESIZE); 2662 blk_queue_logical_block_size(q, CD_FRAMESIZE);
2661 blk_queue_max_sectors(q, PACKET_MAX_SECTORS); 2663 blk_queue_max_sectors(q, PACKET_MAX_SECTORS);
2662 blk_queue_merge_bvec(q, pkt_merge_bvec); 2664 blk_queue_merge_bvec(q, pkt_merge_bvec);
2663 q->queuedata = pd; 2665 q->queuedata = pd;
diff --git a/drivers/block/ps3disk.c b/drivers/block/ps3disk.c
index bccc42bb9212..aaeeb544228a 100644
--- a/drivers/block/ps3disk.c
+++ b/drivers/block/ps3disk.c
@@ -134,13 +134,12 @@ static int ps3disk_submit_request_sg(struct ps3_storage_device *dev,
134 rq_for_each_segment(bv, req, iter) 134 rq_for_each_segment(bv, req, iter)
135 n++; 135 n++;
136 dev_dbg(&dev->sbd.core, 136 dev_dbg(&dev->sbd.core,
137 "%s:%u: %s req has %u bvecs for %lu sectors %lu hard sectors\n", 137 "%s:%u: %s req has %u bvecs for %u sectors\n",
138 __func__, __LINE__, op, n, req->nr_sectors, 138 __func__, __LINE__, op, n, blk_rq_sectors(req));
139 req->hard_nr_sectors);
140#endif 139#endif
141 140
142 start_sector = req->sector * priv->blocking_factor; 141 start_sector = blk_rq_pos(req) * priv->blocking_factor;
143 sectors = req->nr_sectors * priv->blocking_factor; 142 sectors = blk_rq_sectors(req) * priv->blocking_factor;
144 dev_dbg(&dev->sbd.core, "%s:%u: %s %llu sectors starting at %llu\n", 143 dev_dbg(&dev->sbd.core, "%s:%u: %s %llu sectors starting at %llu\n",
145 __func__, __LINE__, op, sectors, start_sector); 144 __func__, __LINE__, op, sectors, start_sector);
146 145
@@ -158,7 +157,7 @@ static int ps3disk_submit_request_sg(struct ps3_storage_device *dev,
158 if (res) { 157 if (res) {
159 dev_err(&dev->sbd.core, "%s:%u: %s failed %d\n", __func__, 158 dev_err(&dev->sbd.core, "%s:%u: %s failed %d\n", __func__,
160 __LINE__, op, res); 159 __LINE__, op, res);
161 end_request(req, 0); 160 __blk_end_request_all(req, -EIO);
162 return 0; 161 return 0;
163 } 162 }
164 163
@@ -180,7 +179,7 @@ static int ps3disk_submit_flush_request(struct ps3_storage_device *dev,
180 if (res) { 179 if (res) {
181 dev_err(&dev->sbd.core, "%s:%u: sync cache failed 0x%llx\n", 180 dev_err(&dev->sbd.core, "%s:%u: sync cache failed 0x%llx\n",
182 __func__, __LINE__, res); 181 __func__, __LINE__, res);
183 end_request(req, 0); 182 __blk_end_request_all(req, -EIO);
184 return 0; 183 return 0;
185 } 184 }
186 185
@@ -195,7 +194,7 @@ static void ps3disk_do_request(struct ps3_storage_device *dev,
195 194
196 dev_dbg(&dev->sbd.core, "%s:%u\n", __func__, __LINE__); 195 dev_dbg(&dev->sbd.core, "%s:%u\n", __func__, __LINE__);
197 196
198 while ((req = elv_next_request(q))) { 197 while ((req = blk_fetch_request(q))) {
199 if (blk_fs_request(req)) { 198 if (blk_fs_request(req)) {
200 if (ps3disk_submit_request_sg(dev, req)) 199 if (ps3disk_submit_request_sg(dev, req))
201 break; 200 break;
@@ -205,7 +204,7 @@ static void ps3disk_do_request(struct ps3_storage_device *dev,
205 break; 204 break;
206 } else { 205 } else {
207 blk_dump_rq_flags(req, DEVICE_NAME " bad request"); 206 blk_dump_rq_flags(req, DEVICE_NAME " bad request");
208 end_request(req, 0); 207 __blk_end_request_all(req, -EIO);
209 continue; 208 continue;
210 } 209 }
211 } 210 }
@@ -231,7 +230,6 @@ static irqreturn_t ps3disk_interrupt(int irq, void *data)
231 struct request *req; 230 struct request *req;
232 int res, read, error; 231 int res, read, error;
233 u64 tag, status; 232 u64 tag, status;
234 unsigned long num_sectors;
235 const char *op; 233 const char *op;
236 234
237 res = lv1_storage_get_async_status(dev->sbd.dev_id, &tag, &status); 235 res = lv1_storage_get_async_status(dev->sbd.dev_id, &tag, &status);
@@ -261,11 +259,9 @@ static irqreturn_t ps3disk_interrupt(int irq, void *data)
261 if (req->cmd_type == REQ_TYPE_LINUX_BLOCK && 259 if (req->cmd_type == REQ_TYPE_LINUX_BLOCK &&
262 req->cmd[0] == REQ_LB_OP_FLUSH) { 260 req->cmd[0] == REQ_LB_OP_FLUSH) {
263 read = 0; 261 read = 0;
264 num_sectors = req->hard_cur_sectors;
265 op = "flush"; 262 op = "flush";
266 } else { 263 } else {
267 read = !rq_data_dir(req); 264 read = !rq_data_dir(req);
268 num_sectors = req->nr_sectors;
269 op = read ? "read" : "write"; 265 op = read ? "read" : "write";
270 } 266 }
271 if (status) { 267 if (status) {
@@ -281,7 +277,7 @@ static irqreturn_t ps3disk_interrupt(int irq, void *data)
281 } 277 }
282 278
283 spin_lock(&priv->lock); 279 spin_lock(&priv->lock);
284 __blk_end_request(req, error, num_sectors << 9); 280 __blk_end_request_all(req, error);
285 priv->req = NULL; 281 priv->req = NULL;
286 ps3disk_do_request(dev, priv->queue); 282 ps3disk_do_request(dev, priv->queue);
287 spin_unlock(&priv->lock); 283 spin_unlock(&priv->lock);
@@ -481,7 +477,7 @@ static int __devinit ps3disk_probe(struct ps3_system_bus_device *_dev)
481 blk_queue_max_sectors(queue, dev->bounce_size >> 9); 477 blk_queue_max_sectors(queue, dev->bounce_size >> 9);
482 blk_queue_segment_boundary(queue, -1UL); 478 blk_queue_segment_boundary(queue, -1UL);
483 blk_queue_dma_alignment(queue, dev->blk_size-1); 479 blk_queue_dma_alignment(queue, dev->blk_size-1);
484 blk_queue_hardsect_size(queue, dev->blk_size); 480 blk_queue_logical_block_size(queue, dev->blk_size);
485 481
486 blk_queue_ordered(queue, QUEUE_ORDERED_DRAIN_FLUSH, 482 blk_queue_ordered(queue, QUEUE_ORDERED_DRAIN_FLUSH,
487 ps3disk_prepare_flush); 483 ps3disk_prepare_flush);
diff --git a/drivers/block/sunvdc.c b/drivers/block/sunvdc.c
index 5861e33efe63..cbfd9c0aef03 100644
--- a/drivers/block/sunvdc.c
+++ b/drivers/block/sunvdc.c
@@ -212,11 +212,6 @@ static void vdc_end_special(struct vdc_port *port, struct vio_disk_desc *desc)
212 vdc_finish(&port->vio, -err, WAITING_FOR_GEN_CMD); 212 vdc_finish(&port->vio, -err, WAITING_FOR_GEN_CMD);
213} 213}
214 214
215static void vdc_end_request(struct request *req, int error, int num_sectors)
216{
217 __blk_end_request(req, error, num_sectors << 9);
218}
219
220static void vdc_end_one(struct vdc_port *port, struct vio_dring_state *dr, 215static void vdc_end_one(struct vdc_port *port, struct vio_dring_state *dr,
221 unsigned int index) 216 unsigned int index)
222{ 217{
@@ -239,7 +234,7 @@ static void vdc_end_one(struct vdc_port *port, struct vio_dring_state *dr,
239 234
240 rqe->req = NULL; 235 rqe->req = NULL;
241 236
242 vdc_end_request(req, (desc->status ? -EIO : 0), desc->size >> 9); 237 __blk_end_request(req, (desc->status ? -EIO : 0), desc->size);
243 238
244 if (blk_queue_stopped(port->disk->queue)) 239 if (blk_queue_stopped(port->disk->queue))
245 blk_start_queue(port->disk->queue); 240 blk_start_queue(port->disk->queue);
@@ -421,7 +416,7 @@ static int __send_request(struct request *req)
421 desc->slice = 0; 416 desc->slice = 0;
422 } 417 }
423 desc->status = ~0; 418 desc->status = ~0;
424 desc->offset = (req->sector << 9) / port->vdisk_block_size; 419 desc->offset = (blk_rq_pos(req) << 9) / port->vdisk_block_size;
425 desc->size = len; 420 desc->size = len;
426 desc->ncookies = err; 421 desc->ncookies = err;
427 422
@@ -446,14 +441,13 @@ out:
446static void do_vdc_request(struct request_queue *q) 441static void do_vdc_request(struct request_queue *q)
447{ 442{
448 while (1) { 443 while (1) {
449 struct request *req = elv_next_request(q); 444 struct request *req = blk_fetch_request(q);
450 445
451 if (!req) 446 if (!req)
452 break; 447 break;
453 448
454 blkdev_dequeue_request(req);
455 if (__send_request(req) < 0) 449 if (__send_request(req) < 0)
456 vdc_end_request(req, -EIO, req->hard_nr_sectors); 450 __blk_end_request_all(req, -EIO);
457 } 451 }
458} 452}
459 453
diff --git a/drivers/block/swim.c b/drivers/block/swim.c
index d22cc3856937..cf7877fb8a7d 100644
--- a/drivers/block/swim.c
+++ b/drivers/block/swim.c
@@ -514,7 +514,7 @@ static int floppy_read_sectors(struct floppy_state *fs,
514 ret = swim_read_sector(fs, side, track, sector, 514 ret = swim_read_sector(fs, side, track, sector,
515 buffer); 515 buffer);
516 if (try-- == 0) 516 if (try-- == 0)
517 return -1; 517 return -EIO;
518 } while (ret != 512); 518 } while (ret != 512);
519 519
520 buffer += ret; 520 buffer += ret;
@@ -528,45 +528,31 @@ static void redo_fd_request(struct request_queue *q)
528 struct request *req; 528 struct request *req;
529 struct floppy_state *fs; 529 struct floppy_state *fs;
530 530
531 while ((req = elv_next_request(q))) { 531 req = blk_fetch_request(q);
532 while (req) {
533 int err = -EIO;
532 534
533 fs = req->rq_disk->private_data; 535 fs = req->rq_disk->private_data;
534 if (req->sector < 0 || req->sector >= fs->total_secs) { 536 if (blk_rq_pos(req) >= fs->total_secs)
535 end_request(req, 0); 537 goto done;
536 continue; 538 if (!fs->disk_in)
537 } 539 goto done;
538 if (req->current_nr_sectors == 0) { 540 if (rq_data_dir(req) == WRITE && fs->write_protected)
539 end_request(req, 1); 541 goto done;
540 continue; 542
541 }
542 if (!fs->disk_in) {
543 end_request(req, 0);
544 continue;
545 }
546 if (rq_data_dir(req) == WRITE) {
547 if (fs->write_protected) {
548 end_request(req, 0);
549 continue;
550 }
551 }
552 switch (rq_data_dir(req)) { 543 switch (rq_data_dir(req)) {
553 case WRITE: 544 case WRITE:
554 /* NOT IMPLEMENTED */ 545 /* NOT IMPLEMENTED */
555 end_request(req, 0);
556 break; 546 break;
557 case READ: 547 case READ:
558 if (floppy_read_sectors(fs, req->sector, 548 err = floppy_read_sectors(fs, blk_rq_pos(req),
559 req->current_nr_sectors, 549 blk_rq_cur_sectors(req),
560 req->buffer)) { 550 req->buffer);
561 end_request(req, 0);
562 continue;
563 }
564 req->nr_sectors -= req->current_nr_sectors;
565 req->sector += req->current_nr_sectors;
566 req->buffer += req->current_nr_sectors * 512;
567 end_request(req, 1);
568 break; 551 break;
569 } 552 }
553 done:
554 if (!__blk_end_request_cur(req, err))
555 req = blk_fetch_request(q);
570 } 556 }
571} 557}
572 558
diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c
index 612965307ba0..80df93e3cdd0 100644
--- a/drivers/block/swim3.c
+++ b/drivers/block/swim3.c
@@ -251,6 +251,20 @@ static int floppy_release(struct gendisk *disk, fmode_t mode);
251static int floppy_check_change(struct gendisk *disk); 251static int floppy_check_change(struct gendisk *disk);
252static int floppy_revalidate(struct gendisk *disk); 252static int floppy_revalidate(struct gendisk *disk);
253 253
254static bool swim3_end_request(int err, unsigned int nr_bytes)
255{
256 if (__blk_end_request(fd_req, err, nr_bytes))
257 return true;
258
259 fd_req = NULL;
260 return false;
261}
262
263static bool swim3_end_request_cur(int err)
264{
265 return swim3_end_request(err, blk_rq_cur_bytes(fd_req));
266}
267
254static void swim3_select(struct floppy_state *fs, int sel) 268static void swim3_select(struct floppy_state *fs, int sel)
255{ 269{
256 struct swim3 __iomem *sw = fs->swim3; 270 struct swim3 __iomem *sw = fs->swim3;
@@ -310,25 +324,27 @@ static void start_request(struct floppy_state *fs)
310 wake_up(&fs->wait); 324 wake_up(&fs->wait);
311 return; 325 return;
312 } 326 }
313 while (fs->state == idle && (req = elv_next_request(swim3_queue))) { 327 while (fs->state == idle) {
328 if (!fd_req) {
329 fd_req = blk_fetch_request(swim3_queue);
330 if (!fd_req)
331 break;
332 }
333 req = fd_req;
314#if 0 334#if 0
315 printk("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%ld buf=%p\n", 335 printk("do_fd_req: dev=%s cmd=%d sec=%ld nr_sec=%u buf=%p\n",
316 req->rq_disk->disk_name, req->cmd, 336 req->rq_disk->disk_name, req->cmd,
317 (long)req->sector, req->nr_sectors, req->buffer); 337 (long)blk_rq_pos(req), blk_rq_sectors(req), req->buffer);
318 printk(" errors=%d current_nr_sectors=%ld\n", 338 printk(" errors=%d current_nr_sectors=%u\n",
319 req->errors, req->current_nr_sectors); 339 req->errors, blk_rq_cur_sectors(req));
320#endif 340#endif
321 341
322 if (req->sector < 0 || req->sector >= fs->total_secs) { 342 if (blk_rq_pos(req) >= fs->total_secs) {
323 end_request(req, 0); 343 swim3_end_request_cur(-EIO);
324 continue;
325 }
326 if (req->current_nr_sectors == 0) {
327 end_request(req, 1);
328 continue; 344 continue;
329 } 345 }
330 if (fs->ejected) { 346 if (fs->ejected) {
331 end_request(req, 0); 347 swim3_end_request_cur(-EIO);
332 continue; 348 continue;
333 } 349 }
334 350
@@ -336,18 +352,19 @@ static void start_request(struct floppy_state *fs)
336 if (fs->write_prot < 0) 352 if (fs->write_prot < 0)
337 fs->write_prot = swim3_readbit(fs, WRITE_PROT); 353 fs->write_prot = swim3_readbit(fs, WRITE_PROT);
338 if (fs->write_prot) { 354 if (fs->write_prot) {
339 end_request(req, 0); 355 swim3_end_request_cur(-EIO);
340 continue; 356 continue;
341 } 357 }
342 } 358 }
343 359
344 /* Do not remove the cast. req->sector is now a sector_t and 360 /* Do not remove the cast. blk_rq_pos(req) is now a
345 * can be 64 bits, but it will never go past 32 bits for this 361 * sector_t and can be 64 bits, but it will never go
346 * driver anyway, so we can safely cast it down and not have 362 * past 32 bits for this driver anyway, so we can
347 * to do a 64/32 division 363 * safely cast it down and not have to do a 64/32
364 * division
348 */ 365 */
349 fs->req_cyl = ((long)req->sector) / fs->secpercyl; 366 fs->req_cyl = ((long)blk_rq_pos(req)) / fs->secpercyl;
350 x = ((long)req->sector) % fs->secpercyl; 367 x = ((long)blk_rq_pos(req)) % fs->secpercyl;
351 fs->head = x / fs->secpertrack; 368 fs->head = x / fs->secpertrack;
352 fs->req_sector = x % fs->secpertrack + 1; 369 fs->req_sector = x % fs->secpertrack + 1;
353 fd_req = req; 370 fd_req = req;
@@ -424,7 +441,7 @@ static inline void setup_transfer(struct floppy_state *fs)
424 struct dbdma_cmd *cp = fs->dma_cmd; 441 struct dbdma_cmd *cp = fs->dma_cmd;
425 struct dbdma_regs __iomem *dr = fs->dma; 442 struct dbdma_regs __iomem *dr = fs->dma;
426 443
427 if (fd_req->current_nr_sectors <= 0) { 444 if (blk_rq_cur_sectors(fd_req) <= 0) {
428 printk(KERN_ERR "swim3: transfer 0 sectors?\n"); 445 printk(KERN_ERR "swim3: transfer 0 sectors?\n");
429 return; 446 return;
430 } 447 }
@@ -432,8 +449,8 @@ static inline void setup_transfer(struct floppy_state *fs)
432 n = 1; 449 n = 1;
433 else { 450 else {
434 n = fs->secpertrack - fs->req_sector + 1; 451 n = fs->secpertrack - fs->req_sector + 1;
435 if (n > fd_req->current_nr_sectors) 452 if (n > blk_rq_cur_sectors(fd_req))
436 n = fd_req->current_nr_sectors; 453 n = blk_rq_cur_sectors(fd_req);
437 } 454 }
438 fs->scount = n; 455 fs->scount = n;
439 swim3_select(fs, fs->head? READ_DATA_1: READ_DATA_0); 456 swim3_select(fs, fs->head? READ_DATA_1: READ_DATA_0);
@@ -508,7 +525,7 @@ static void act(struct floppy_state *fs)
508 case do_transfer: 525 case do_transfer:
509 if (fs->cur_cyl != fs->req_cyl) { 526 if (fs->cur_cyl != fs->req_cyl) {
510 if (fs->retries > 5) { 527 if (fs->retries > 5) {
511 end_request(fd_req, 0); 528 swim3_end_request_cur(-EIO);
512 fs->state = idle; 529 fs->state = idle;
513 return; 530 return;
514 } 531 }
@@ -540,7 +557,7 @@ static void scan_timeout(unsigned long data)
540 out_8(&sw->intr_enable, 0); 557 out_8(&sw->intr_enable, 0);
541 fs->cur_cyl = -1; 558 fs->cur_cyl = -1;
542 if (fs->retries > 5) { 559 if (fs->retries > 5) {
543 end_request(fd_req, 0); 560 swim3_end_request_cur(-EIO);
544 fs->state = idle; 561 fs->state = idle;
545 start_request(fs); 562 start_request(fs);
546 } else { 563 } else {
@@ -559,7 +576,7 @@ static void seek_timeout(unsigned long data)
559 out_8(&sw->select, RELAX); 576 out_8(&sw->select, RELAX);
560 out_8(&sw->intr_enable, 0); 577 out_8(&sw->intr_enable, 0);
561 printk(KERN_ERR "swim3: seek timeout\n"); 578 printk(KERN_ERR "swim3: seek timeout\n");
562 end_request(fd_req, 0); 579 swim3_end_request_cur(-EIO);
563 fs->state = idle; 580 fs->state = idle;
564 start_request(fs); 581 start_request(fs);
565} 582}
@@ -583,7 +600,7 @@ static void settle_timeout(unsigned long data)
583 return; 600 return;
584 } 601 }
585 printk(KERN_ERR "swim3: seek settle timeout\n"); 602 printk(KERN_ERR "swim3: seek settle timeout\n");
586 end_request(fd_req, 0); 603 swim3_end_request_cur(-EIO);
587 fs->state = idle; 604 fs->state = idle;
588 start_request(fs); 605 start_request(fs);
589} 606}
@@ -593,8 +610,6 @@ static void xfer_timeout(unsigned long data)
593 struct floppy_state *fs = (struct floppy_state *) data; 610 struct floppy_state *fs = (struct floppy_state *) data;
594 struct swim3 __iomem *sw = fs->swim3; 611 struct swim3 __iomem *sw = fs->swim3;
595 struct dbdma_regs __iomem *dr = fs->dma; 612 struct dbdma_regs __iomem *dr = fs->dma;
596 struct dbdma_cmd *cp = fs->dma_cmd;
597 unsigned long s;
598 int n; 613 int n;
599 614
600 fs->timeout_pending = 0; 615 fs->timeout_pending = 0;
@@ -605,17 +620,10 @@ static void xfer_timeout(unsigned long data)
605 out_8(&sw->intr_enable, 0); 620 out_8(&sw->intr_enable, 0);
606 out_8(&sw->control_bic, WRITE_SECTORS | DO_ACTION); 621 out_8(&sw->control_bic, WRITE_SECTORS | DO_ACTION);
607 out_8(&sw->select, RELAX); 622 out_8(&sw->select, RELAX);
608 if (rq_data_dir(fd_req) == WRITE)
609 ++cp;
610 if (ld_le16(&cp->xfer_status) != 0)
611 s = fs->scount - ((ld_le16(&cp->res_count) + 511) >> 9);
612 else
613 s = 0;
614 fd_req->sector += s;
615 fd_req->current_nr_sectors -= s;
616 printk(KERN_ERR "swim3: timeout %sing sector %ld\n", 623 printk(KERN_ERR "swim3: timeout %sing sector %ld\n",
617 (rq_data_dir(fd_req)==WRITE? "writ": "read"), (long)fd_req->sector); 624 (rq_data_dir(fd_req)==WRITE? "writ": "read"),
618 end_request(fd_req, 0); 625 (long)blk_rq_pos(fd_req));
626 swim3_end_request_cur(-EIO);
619 fs->state = idle; 627 fs->state = idle;
620 start_request(fs); 628 start_request(fs);
621} 629}
@@ -646,7 +654,7 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id)
646 printk(KERN_ERR "swim3: seen sector but cyl=ff?\n"); 654 printk(KERN_ERR "swim3: seen sector but cyl=ff?\n");
647 fs->cur_cyl = -1; 655 fs->cur_cyl = -1;
648 if (fs->retries > 5) { 656 if (fs->retries > 5) {
649 end_request(fd_req, 0); 657 swim3_end_request_cur(-EIO);
650 fs->state = idle; 658 fs->state = idle;
651 start_request(fs); 659 start_request(fs);
652 } else { 660 } else {
@@ -719,9 +727,7 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id)
719 if (intr & ERROR_INTR) { 727 if (intr & ERROR_INTR) {
720 n = fs->scount - 1 - resid / 512; 728 n = fs->scount - 1 - resid / 512;
721 if (n > 0) { 729 if (n > 0) {
722 fd_req->sector += n; 730 blk_update_request(fd_req, 0, n << 9);
723 fd_req->current_nr_sectors -= n;
724 fd_req->buffer += n * 512;
725 fs->req_sector += n; 731 fs->req_sector += n;
726 } 732 }
727 if (fs->retries < 5) { 733 if (fs->retries < 5) {
@@ -730,8 +736,8 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id)
730 } else { 736 } else {
731 printk("swim3: error %sing block %ld (err=%x)\n", 737 printk("swim3: error %sing block %ld (err=%x)\n",
732 rq_data_dir(fd_req) == WRITE? "writ": "read", 738 rq_data_dir(fd_req) == WRITE? "writ": "read",
733 (long)fd_req->sector, err); 739 (long)blk_rq_pos(fd_req), err);
734 end_request(fd_req, 0); 740 swim3_end_request_cur(-EIO);
735 fs->state = idle; 741 fs->state = idle;
736 } 742 }
737 } else { 743 } else {
@@ -740,18 +746,12 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id)
740 printk(KERN_ERR "swim3: fd dma: stat=%x resid=%d\n", stat, resid); 746 printk(KERN_ERR "swim3: fd dma: stat=%x resid=%d\n", stat, resid);
741 printk(KERN_ERR " state=%d, dir=%x, intr=%x, err=%x\n", 747 printk(KERN_ERR " state=%d, dir=%x, intr=%x, err=%x\n",
742 fs->state, rq_data_dir(fd_req), intr, err); 748 fs->state, rq_data_dir(fd_req), intr, err);
743 end_request(fd_req, 0); 749 swim3_end_request_cur(-EIO);
744 fs->state = idle; 750 fs->state = idle;
745 start_request(fs); 751 start_request(fs);
746 break; 752 break;
747 } 753 }
748 fd_req->sector += fs->scount; 754 if (swim3_end_request(0, fs->scount << 9)) {
749 fd_req->current_nr_sectors -= fs->scount;
750 fd_req->buffer += fs->scount * 512;
751 if (fd_req->current_nr_sectors <= 0) {
752 end_request(fd_req, 1);
753 fs->state = idle;
754 } else {
755 fs->req_sector += fs->scount; 755 fs->req_sector += fs->scount;
756 if (fs->req_sector > fs->secpertrack) { 756 if (fs->req_sector > fs->secpertrack) {
757 fs->req_sector -= fs->secpertrack; 757 fs->req_sector -= fs->secpertrack;
@@ -761,7 +761,8 @@ static irqreturn_t swim3_interrupt(int irq, void *dev_id)
761 } 761 }
762 } 762 }
763 act(fs); 763 act(fs);
764 } 764 } else
765 fs->state = idle;
765 } 766 }
766 if (fs->state == idle) 767 if (fs->state == idle)
767 start_request(fs); 768 start_request(fs);
diff --git a/drivers/block/sx8.c b/drivers/block/sx8.c
index ff0448e4bf03..da403b6a7f43 100644
--- a/drivers/block/sx8.c
+++ b/drivers/block/sx8.c
@@ -749,8 +749,7 @@ static inline void carm_end_request_queued(struct carm_host *host,
749 struct request *req = crq->rq; 749 struct request *req = crq->rq;
750 int rc; 750 int rc;
751 751
752 rc = __blk_end_request(req, error, blk_rq_bytes(req)); 752 __blk_end_request_all(req, error);
753 assert(rc == 0);
754 753
755 rc = carm_put_request(host, crq); 754 rc = carm_put_request(host, crq);
756 assert(rc == 0); 755 assert(rc == 0);
@@ -811,12 +810,10 @@ static void carm_oob_rq_fn(struct request_queue *q)
811 810
812 while (1) { 811 while (1) {
813 DPRINTK("get req\n"); 812 DPRINTK("get req\n");
814 rq = elv_next_request(q); 813 rq = blk_fetch_request(q);
815 if (!rq) 814 if (!rq)
816 break; 815 break;
817 816
818 blkdev_dequeue_request(rq);
819
820 crq = rq->special; 817 crq = rq->special;
821 assert(crq != NULL); 818 assert(crq != NULL);
822 assert(crq->rq == rq); 819 assert(crq->rq == rq);
@@ -847,7 +844,7 @@ static void carm_rq_fn(struct request_queue *q)
847 844
848queue_one_request: 845queue_one_request:
849 VPRINTK("get req\n"); 846 VPRINTK("get req\n");
850 rq = elv_next_request(q); 847 rq = blk_peek_request(q);
851 if (!rq) 848 if (!rq)
852 return; 849 return;
853 850
@@ -858,7 +855,7 @@ queue_one_request:
858 } 855 }
859 crq->rq = rq; 856 crq->rq = rq;
860 857
861 blkdev_dequeue_request(rq); 858 blk_start_request(rq);
862 859
863 if (rq_data_dir(rq) == WRITE) { 860 if (rq_data_dir(rq) == WRITE) {
864 writing = 1; 861 writing = 1;
@@ -904,10 +901,10 @@ queue_one_request:
904 msg->sg_count = n_elem; 901 msg->sg_count = n_elem;
905 msg->sg_type = SGT_32BIT; 902 msg->sg_type = SGT_32BIT;
906 msg->handle = cpu_to_le32(TAG_ENCODE(crq->tag)); 903 msg->handle = cpu_to_le32(TAG_ENCODE(crq->tag));
907 msg->lba = cpu_to_le32(rq->sector & 0xffffffff); 904 msg->lba = cpu_to_le32(blk_rq_pos(rq) & 0xffffffff);
908 tmp = (rq->sector >> 16) >> 16; 905 tmp = (blk_rq_pos(rq) >> 16) >> 16;
909 msg->lba_high = cpu_to_le16( (u16) tmp ); 906 msg->lba_high = cpu_to_le16( (u16) tmp );
910 msg->lba_count = cpu_to_le16(rq->nr_sectors); 907 msg->lba_count = cpu_to_le16(blk_rq_sectors(rq));
911 908
912 msg_size = sizeof(struct carm_msg_rw) - sizeof(msg->sg); 909 msg_size = sizeof(struct carm_msg_rw) - sizeof(msg->sg);
913 for (i = 0; i < n_elem; i++) { 910 for (i = 0; i < n_elem; i++) {
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index 689cd27ac890..cc54473b8e77 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -360,8 +360,7 @@ static void ub_cmd_build_block(struct ub_dev *sc, struct ub_lun *lun,
360static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun, 360static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
361 struct ub_scsi_cmd *cmd, struct ub_request *urq); 361 struct ub_scsi_cmd *cmd, struct ub_request *urq);
362static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd); 362static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
363static void ub_end_rq(struct request *rq, unsigned int status, 363static void ub_end_rq(struct request *rq, unsigned int status);
364 unsigned int cmd_len);
365static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun, 364static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun,
366 struct ub_request *urq, struct ub_scsi_cmd *cmd); 365 struct ub_request *urq, struct ub_scsi_cmd *cmd);
367static int ub_submit_scsi(struct ub_dev *sc, struct ub_scsi_cmd *cmd); 366static int ub_submit_scsi(struct ub_dev *sc, struct ub_scsi_cmd *cmd);
@@ -627,7 +626,7 @@ static void ub_request_fn(struct request_queue *q)
627 struct ub_lun *lun = q->queuedata; 626 struct ub_lun *lun = q->queuedata;
628 struct request *rq; 627 struct request *rq;
629 628
630 while ((rq = elv_next_request(q)) != NULL) { 629 while ((rq = blk_peek_request(q)) != NULL) {
631 if (ub_request_fn_1(lun, rq) != 0) { 630 if (ub_request_fn_1(lun, rq) != 0) {
632 blk_stop_queue(q); 631 blk_stop_queue(q);
633 break; 632 break;
@@ -643,14 +642,14 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq)
643 int n_elem; 642 int n_elem;
644 643
645 if (atomic_read(&sc->poison)) { 644 if (atomic_read(&sc->poison)) {
646 blkdev_dequeue_request(rq); 645 blk_start_request(rq);
647 ub_end_rq(rq, DID_NO_CONNECT << 16, blk_rq_bytes(rq)); 646 ub_end_rq(rq, DID_NO_CONNECT << 16);
648 return 0; 647 return 0;
649 } 648 }
650 649
651 if (lun->changed && !blk_pc_request(rq)) { 650 if (lun->changed && !blk_pc_request(rq)) {
652 blkdev_dequeue_request(rq); 651 blk_start_request(rq);
653 ub_end_rq(rq, SAM_STAT_CHECK_CONDITION, blk_rq_bytes(rq)); 652 ub_end_rq(rq, SAM_STAT_CHECK_CONDITION);
654 return 0; 653 return 0;
655 } 654 }
656 655
@@ -660,7 +659,7 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq)
660 return -1; 659 return -1;
661 memset(cmd, 0, sizeof(struct ub_scsi_cmd)); 660 memset(cmd, 0, sizeof(struct ub_scsi_cmd));
662 661
663 blkdev_dequeue_request(rq); 662 blk_start_request(rq);
664 663
665 urq = &lun->urq; 664 urq = &lun->urq;
666 memset(urq, 0, sizeof(struct ub_request)); 665 memset(urq, 0, sizeof(struct ub_request));
@@ -702,7 +701,7 @@ static int ub_request_fn_1(struct ub_lun *lun, struct request *rq)
702 701
703drop: 702drop:
704 ub_put_cmd(lun, cmd); 703 ub_put_cmd(lun, cmd);
705 ub_end_rq(rq, DID_ERROR << 16, blk_rq_bytes(rq)); 704 ub_end_rq(rq, DID_ERROR << 16);
706 return 0; 705 return 0;
707} 706}
708 707
@@ -723,11 +722,11 @@ static void ub_cmd_build_block(struct ub_dev *sc, struct ub_lun *lun,
723 /* 722 /*
724 * build the command 723 * build the command
725 * 724 *
726 * The call to blk_queue_hardsect_size() guarantees that request 725 * The call to blk_queue_logical_block_size() guarantees that request
727 * is aligned, but it is given in terms of 512 byte units, always. 726 * is aligned, but it is given in terms of 512 byte units, always.
728 */ 727 */
729 block = rq->sector >> lun->capacity.bshift; 728 block = blk_rq_pos(rq) >> lun->capacity.bshift;
730 nblks = rq->nr_sectors >> lun->capacity.bshift; 729 nblks = blk_rq_sectors(rq) >> lun->capacity.bshift;
731 730
732 cmd->cdb[0] = (cmd->dir == UB_DIR_READ)? READ_10: WRITE_10; 731 cmd->cdb[0] = (cmd->dir == UB_DIR_READ)? READ_10: WRITE_10;
733 /* 10-byte uses 4 bytes of LBA: 2147483648KB, 2097152MB, 2048GB */ 732 /* 10-byte uses 4 bytes of LBA: 2147483648KB, 2097152MB, 2048GB */
@@ -739,7 +738,7 @@ static void ub_cmd_build_block(struct ub_dev *sc, struct ub_lun *lun,
739 cmd->cdb[8] = nblks; 738 cmd->cdb[8] = nblks;
740 cmd->cdb_len = 10; 739 cmd->cdb_len = 10;
741 740
742 cmd->len = rq->nr_sectors * 512; 741 cmd->len = blk_rq_bytes(rq);
743} 742}
744 743
745static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun, 744static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
@@ -747,7 +746,7 @@ static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
747{ 746{
748 struct request *rq = urq->rq; 747 struct request *rq = urq->rq;
749 748
750 if (rq->data_len == 0) { 749 if (blk_rq_bytes(rq) == 0) {
751 cmd->dir = UB_DIR_NONE; 750 cmd->dir = UB_DIR_NONE;
752 } else { 751 } else {
753 if (rq_data_dir(rq) == WRITE) 752 if (rq_data_dir(rq) == WRITE)
@@ -762,7 +761,7 @@ static void ub_cmd_build_packet(struct ub_dev *sc, struct ub_lun *lun,
762 memcpy(&cmd->cdb, rq->cmd, rq->cmd_len); 761 memcpy(&cmd->cdb, rq->cmd, rq->cmd_len);
763 cmd->cdb_len = rq->cmd_len; 762 cmd->cdb_len = rq->cmd_len;
764 763
765 cmd->len = rq->data_len; 764 cmd->len = blk_rq_bytes(rq);
766 765
767 /* 766 /*
768 * To reapply this to every URB is not as incorrect as it looks. 767 * To reapply this to every URB is not as incorrect as it looks.
@@ -777,16 +776,15 @@ static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
777 struct ub_request *urq = cmd->back; 776 struct ub_request *urq = cmd->back;
778 struct request *rq; 777 struct request *rq;
779 unsigned int scsi_status; 778 unsigned int scsi_status;
780 unsigned int cmd_len;
781 779
782 rq = urq->rq; 780 rq = urq->rq;
783 781
784 if (cmd->error == 0) { 782 if (cmd->error == 0) {
785 if (blk_pc_request(rq)) { 783 if (blk_pc_request(rq)) {
786 if (cmd->act_len >= rq->data_len) 784 if (cmd->act_len >= rq->resid_len)
787 rq->data_len = 0; 785 rq->resid_len = 0;
788 else 786 else
789 rq->data_len -= cmd->act_len; 787 rq->resid_len -= cmd->act_len;
790 scsi_status = 0; 788 scsi_status = 0;
791 } else { 789 } else {
792 if (cmd->act_len != cmd->len) { 790 if (cmd->act_len != cmd->len) {
@@ -818,17 +816,14 @@ static void ub_rw_cmd_done(struct ub_dev *sc, struct ub_scsi_cmd *cmd)
818 816
819 urq->rq = NULL; 817 urq->rq = NULL;
820 818
821 cmd_len = cmd->len;
822 ub_put_cmd(lun, cmd); 819 ub_put_cmd(lun, cmd);
823 ub_end_rq(rq, scsi_status, cmd_len); 820 ub_end_rq(rq, scsi_status);
824 blk_start_queue(lun->disk->queue); 821 blk_start_queue(lun->disk->queue);
825} 822}
826 823
827static void ub_end_rq(struct request *rq, unsigned int scsi_status, 824static void ub_end_rq(struct request *rq, unsigned int scsi_status)
828 unsigned int cmd_len)
829{ 825{
830 int error; 826 int error;
831 long rqlen;
832 827
833 if (scsi_status == 0) { 828 if (scsi_status == 0) {
834 error = 0; 829 error = 0;
@@ -836,12 +831,7 @@ static void ub_end_rq(struct request *rq, unsigned int scsi_status,
836 error = -EIO; 831 error = -EIO;
837 rq->errors = scsi_status; 832 rq->errors = scsi_status;
838 } 833 }
839 rqlen = blk_rq_bytes(rq); /* Oddly enough, this is the residue. */ 834 __blk_end_request_all(rq, error);
840 if (__blk_end_request(rq, error, cmd_len)) {
841 printk(KERN_WARNING DRV_NAME
842 ": __blk_end_request blew, %s-cmd total %u rqlen %ld\n",
843 blk_pc_request(rq)? "pc": "fs", cmd_len, rqlen);
844 }
845} 835}
846 836
847static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun, 837static int ub_rw_cmd_retry(struct ub_dev *sc, struct ub_lun *lun,
@@ -1759,7 +1749,7 @@ static int ub_bd_revalidate(struct gendisk *disk)
1759 ub_revalidate(lun->udev, lun); 1749 ub_revalidate(lun->udev, lun);
1760 1750
1761 /* XXX Support sector size switching like in sr.c */ 1751 /* XXX Support sector size switching like in sr.c */
1762 blk_queue_hardsect_size(disk->queue, lun->capacity.bsize); 1752 blk_queue_logical_block_size(disk->queue, lun->capacity.bsize);
1763 set_capacity(disk, lun->capacity.nsec); 1753 set_capacity(disk, lun->capacity.nsec);
1764 // set_disk_ro(sdkp->disk, lun->readonly); 1754 // set_disk_ro(sdkp->disk, lun->readonly);
1765 1755
@@ -2334,7 +2324,7 @@ static int ub_probe_lun(struct ub_dev *sc, int lnum)
2334 blk_queue_max_phys_segments(q, UB_MAX_REQ_SG); 2324 blk_queue_max_phys_segments(q, UB_MAX_REQ_SG);
2335 blk_queue_segment_boundary(q, 0xffffffff); /* Dubious. */ 2325 blk_queue_segment_boundary(q, 0xffffffff); /* Dubious. */
2336 blk_queue_max_sectors(q, UB_MAX_SECTORS); 2326 blk_queue_max_sectors(q, UB_MAX_SECTORS);
2337 blk_queue_hardsect_size(q, lun->capacity.bsize); 2327 blk_queue_logical_block_size(q, lun->capacity.bsize);
2338 2328
2339 lun->disk = disk; 2329 lun->disk = disk;
2340 q->queuedata = lun; 2330 q->queuedata = lun;
diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c
index ecccf65dce2f..390d69bb7c48 100644
--- a/drivers/block/viodasd.c
+++ b/drivers/block/viodasd.c
@@ -252,7 +252,7 @@ static int send_request(struct request *req)
252 struct viodasd_device *d; 252 struct viodasd_device *d;
253 unsigned long flags; 253 unsigned long flags;
254 254
255 start = (u64)req->sector << 9; 255 start = (u64)blk_rq_pos(req) << 9;
256 256
257 if (rq_data_dir(req) == READ) { 257 if (rq_data_dir(req) == READ) {
258 direction = DMA_FROM_DEVICE; 258 direction = DMA_FROM_DEVICE;
@@ -361,19 +361,17 @@ static void do_viodasd_request(struct request_queue *q)
361 * back later. 361 * back later.
362 */ 362 */
363 while (num_req_outstanding < VIOMAXREQ) { 363 while (num_req_outstanding < VIOMAXREQ) {
364 req = elv_next_request(q); 364 req = blk_fetch_request(q);
365 if (req == NULL) 365 if (req == NULL)
366 return; 366 return;
367 /* dequeue the current request from the queue */
368 blkdev_dequeue_request(req);
369 /* check that request contains a valid command */ 367 /* check that request contains a valid command */
370 if (!blk_fs_request(req)) { 368 if (!blk_fs_request(req)) {
371 viodasd_end_request(req, -EIO, req->hard_nr_sectors); 369 viodasd_end_request(req, -EIO, blk_rq_sectors(req));
372 continue; 370 continue;
373 } 371 }
374 /* Try sending the request */ 372 /* Try sending the request */
375 if (send_request(req) != 0) 373 if (send_request(req) != 0)
376 viodasd_end_request(req, -EIO, req->hard_nr_sectors); 374 viodasd_end_request(req, -EIO, blk_rq_sectors(req));
377 } 375 }
378} 376}
379 377
@@ -590,7 +588,7 @@ static int viodasd_handle_read_write(struct vioblocklpevent *bevent)
590 err = vio_lookup_rc(viodasd_err_table, bevent->sub_result); 588 err = vio_lookup_rc(viodasd_err_table, bevent->sub_result);
591 printk(VIOD_KERN_WARNING "read/write error %d:0x%04x (%s)\n", 589 printk(VIOD_KERN_WARNING "read/write error %d:0x%04x (%s)\n",
592 event->xRc, bevent->sub_result, err->msg); 590 event->xRc, bevent->sub_result, err->msg);
593 num_sect = req->hard_nr_sectors; 591 num_sect = blk_rq_sectors(req);
594 } 592 }
595 qlock = req->q->queue_lock; 593 qlock = req->q->queue_lock;
596 spin_lock_irqsave(qlock, irq_flags); 594 spin_lock_irqsave(qlock, irq_flags);
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 5d34764c8a87..c0facaa55cf4 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -37,6 +37,7 @@ struct virtblk_req
37 struct list_head list; 37 struct list_head list;
38 struct request *req; 38 struct request *req;
39 struct virtio_blk_outhdr out_hdr; 39 struct virtio_blk_outhdr out_hdr;
40 struct virtio_scsi_inhdr in_hdr;
40 u8 status; 41 u8 status;
41}; 42};
42 43
@@ -50,6 +51,7 @@ static void blk_done(struct virtqueue *vq)
50 spin_lock_irqsave(&vblk->lock, flags); 51 spin_lock_irqsave(&vblk->lock, flags);
51 while ((vbr = vblk->vq->vq_ops->get_buf(vblk->vq, &len)) != NULL) { 52 while ((vbr = vblk->vq->vq_ops->get_buf(vblk->vq, &len)) != NULL) {
52 int error; 53 int error;
54
53 switch (vbr->status) { 55 switch (vbr->status) {
54 case VIRTIO_BLK_S_OK: 56 case VIRTIO_BLK_S_OK:
55 error = 0; 57 error = 0;
@@ -62,7 +64,13 @@ static void blk_done(struct virtqueue *vq)
62 break; 64 break;
63 } 65 }
64 66
65 __blk_end_request(vbr->req, error, blk_rq_bytes(vbr->req)); 67 if (blk_pc_request(vbr->req)) {
68 vbr->req->resid_len = vbr->in_hdr.residual;
69 vbr->req->sense_len = vbr->in_hdr.sense_len;
70 vbr->req->errors = vbr->in_hdr.errors;
71 }
72
73 __blk_end_request_all(vbr->req, error);
66 list_del(&vbr->list); 74 list_del(&vbr->list);
67 mempool_free(vbr, vblk->pool); 75 mempool_free(vbr, vblk->pool);
68 } 76 }
@@ -74,7 +82,7 @@ static void blk_done(struct virtqueue *vq)
74static bool do_req(struct request_queue *q, struct virtio_blk *vblk, 82static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
75 struct request *req) 83 struct request *req)
76{ 84{
77 unsigned long num, out, in; 85 unsigned long num, out = 0, in = 0;
78 struct virtblk_req *vbr; 86 struct virtblk_req *vbr;
79 87
80 vbr = mempool_alloc(vblk->pool, GFP_ATOMIC); 88 vbr = mempool_alloc(vblk->pool, GFP_ATOMIC);
@@ -85,7 +93,7 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
85 vbr->req = req; 93 vbr->req = req;
86 if (blk_fs_request(vbr->req)) { 94 if (blk_fs_request(vbr->req)) {
87 vbr->out_hdr.type = 0; 95 vbr->out_hdr.type = 0;
88 vbr->out_hdr.sector = vbr->req->sector; 96 vbr->out_hdr.sector = blk_rq_pos(vbr->req);
89 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req); 97 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
90 } else if (blk_pc_request(vbr->req)) { 98 } else if (blk_pc_request(vbr->req)) {
91 vbr->out_hdr.type = VIRTIO_BLK_T_SCSI_CMD; 99 vbr->out_hdr.type = VIRTIO_BLK_T_SCSI_CMD;
@@ -99,18 +107,36 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
99 if (blk_barrier_rq(vbr->req)) 107 if (blk_barrier_rq(vbr->req))
100 vbr->out_hdr.type |= VIRTIO_BLK_T_BARRIER; 108 vbr->out_hdr.type |= VIRTIO_BLK_T_BARRIER;
101 109
102 sg_set_buf(&vblk->sg[0], &vbr->out_hdr, sizeof(vbr->out_hdr)); 110 sg_set_buf(&vblk->sg[out++], &vbr->out_hdr, sizeof(vbr->out_hdr));
103 num = blk_rq_map_sg(q, vbr->req, vblk->sg+1);
104 sg_set_buf(&vblk->sg[num+1], &vbr->status, sizeof(vbr->status));
105 111
106 if (rq_data_dir(vbr->req) == WRITE) { 112 /*
107 vbr->out_hdr.type |= VIRTIO_BLK_T_OUT; 113 * If this is a packet command we need a couple of additional headers.
108 out = 1 + num; 114 * Behind the normal outhdr we put a segment with the scsi command
109 in = 1; 115 * block, and before the normal inhdr we put the sense data and the
110 } else { 116 * inhdr with additional status information before the normal inhdr.
111 vbr->out_hdr.type |= VIRTIO_BLK_T_IN; 117 */
112 out = 1; 118 if (blk_pc_request(vbr->req))
113 in = 1 + num; 119 sg_set_buf(&vblk->sg[out++], vbr->req->cmd, vbr->req->cmd_len);
120
121 num = blk_rq_map_sg(q, vbr->req, vblk->sg + out);
122
123 if (blk_pc_request(vbr->req)) {
124 sg_set_buf(&vblk->sg[num + out + in++], vbr->req->sense, 96);
125 sg_set_buf(&vblk->sg[num + out + in++], &vbr->in_hdr,
126 sizeof(vbr->in_hdr));
127 }
128
129 sg_set_buf(&vblk->sg[num + out + in++], &vbr->status,
130 sizeof(vbr->status));
131
132 if (num) {
133 if (rq_data_dir(vbr->req) == WRITE) {
134 vbr->out_hdr.type |= VIRTIO_BLK_T_OUT;
135 out += num;
136 } else {
137 vbr->out_hdr.type |= VIRTIO_BLK_T_IN;
138 in += num;
139 }
114 } 140 }
115 141
116 if (vblk->vq->vq_ops->add_buf(vblk->vq, vblk->sg, out, in, vbr)) { 142 if (vblk->vq->vq_ops->add_buf(vblk->vq, vblk->sg, out, in, vbr)) {
@@ -124,12 +150,11 @@ static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
124 150
125static void do_virtblk_request(struct request_queue *q) 151static void do_virtblk_request(struct request_queue *q)
126{ 152{
127 struct virtio_blk *vblk = NULL; 153 struct virtio_blk *vblk = q->queuedata;
128 struct request *req; 154 struct request *req;
129 unsigned int issued = 0; 155 unsigned int issued = 0;
130 156
131 while ((req = elv_next_request(q)) != NULL) { 157 while ((req = blk_peek_request(q)) != NULL) {
132 vblk = req->rq_disk->private_data;
133 BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems); 158 BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems);
134 159
135 /* If this request fails, stop queue and wait for something to 160 /* If this request fails, stop queue and wait for something to
@@ -138,7 +163,7 @@ static void do_virtblk_request(struct request_queue *q)
138 blk_stop_queue(q); 163 blk_stop_queue(q);
139 break; 164 break;
140 } 165 }
141 blkdev_dequeue_request(req); 166 blk_start_request(req);
142 issued++; 167 issued++;
143 } 168 }
144 169
@@ -146,12 +171,51 @@ static void do_virtblk_request(struct request_queue *q)
146 vblk->vq->vq_ops->kick(vblk->vq); 171 vblk->vq->vq_ops->kick(vblk->vq);
147} 172}
148 173
174/* return ATA identify data
175 */
176static int virtblk_identify(struct gendisk *disk, void *argp)
177{
178 struct virtio_blk *vblk = disk->private_data;
179 void *opaque;
180 int err = -ENOMEM;
181
182 opaque = kmalloc(VIRTIO_BLK_ID_BYTES, GFP_KERNEL);
183 if (!opaque)
184 goto out;
185
186 err = virtio_config_buf(vblk->vdev, VIRTIO_BLK_F_IDENTIFY,
187 offsetof(struct virtio_blk_config, identify), opaque,
188 VIRTIO_BLK_ID_BYTES);
189
190 if (err)
191 goto out_kfree;
192
193 if (copy_to_user(argp, opaque, VIRTIO_BLK_ID_BYTES))
194 err = -EFAULT;
195
196out_kfree:
197 kfree(opaque);
198out:
199 return err;
200}
201
149static int virtblk_ioctl(struct block_device *bdev, fmode_t mode, 202static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
150 unsigned cmd, unsigned long data) 203 unsigned cmd, unsigned long data)
151{ 204{
152 return scsi_cmd_ioctl(bdev->bd_disk->queue, 205 struct gendisk *disk = bdev->bd_disk;
153 bdev->bd_disk, mode, cmd, 206 struct virtio_blk *vblk = disk->private_data;
154 (void __user *)data); 207 void __user *argp = (void __user *)data;
208
209 if (cmd == HDIO_GET_IDENTITY)
210 return virtblk_identify(disk, argp);
211
212 /*
213 * Only allow the generic SCSI ioctls if the host can support it.
214 */
215 if (!virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_SCSI))
216 return -ENOIOCTLCMD;
217
218 return scsi_cmd_ioctl(disk->queue, disk, mode, cmd, argp);
155} 219}
156 220
157/* We provide getgeo only to please some old bootloader/partitioning tools */ 221/* We provide getgeo only to please some old bootloader/partitioning tools */
@@ -249,6 +313,7 @@ static int virtblk_probe(struct virtio_device *vdev)
249 goto out_put_disk; 313 goto out_put_disk;
250 } 314 }
251 315
316 vblk->disk->queue->queuedata = vblk;
252 queue_flag_set_unlocked(QUEUE_FLAG_VIRT, vblk->disk->queue); 317 queue_flag_set_unlocked(QUEUE_FLAG_VIRT, vblk->disk->queue);
253 318
254 if (index < 26) { 319 if (index < 26) {
@@ -313,7 +378,7 @@ static int virtblk_probe(struct virtio_device *vdev)
313 offsetof(struct virtio_blk_config, blk_size), 378 offsetof(struct virtio_blk_config, blk_size),
314 &blk_size); 379 &blk_size);
315 if (!err) 380 if (!err)
316 blk_queue_hardsect_size(vblk->disk->queue, blk_size); 381 blk_queue_logical_block_size(vblk->disk->queue, blk_size);
317 382
318 add_disk(vblk->disk); 383 add_disk(vblk->disk);
319 return 0; 384 return 0;
@@ -356,6 +421,7 @@ static struct virtio_device_id id_table[] = {
356static unsigned int features[] = { 421static unsigned int features[] = {
357 VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, 422 VIRTIO_BLK_F_BARRIER, VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX,
358 VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE, 423 VIRTIO_BLK_F_GEOMETRY, VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE,
424 VIRTIO_BLK_F_SCSI, VIRTIO_BLK_F_IDENTIFY
359}; 425};
360 426
361static struct virtio_driver virtio_blk = { 427static struct virtio_driver virtio_blk = {
diff --git a/drivers/block/xd.c b/drivers/block/xd.c
index 64b496fce98b..ce2429219925 100644
--- a/drivers/block/xd.c
+++ b/drivers/block/xd.c
@@ -305,30 +305,25 @@ static void do_xd_request (struct request_queue * q)
305 if (xdc_busy) 305 if (xdc_busy)
306 return; 306 return;
307 307
308 while ((req = elv_next_request(q)) != NULL) { 308 req = blk_fetch_request(q);
309 unsigned block = req->sector; 309 while (req) {
310 unsigned count = req->nr_sectors; 310 unsigned block = blk_rq_pos(req);
311 int rw = rq_data_dir(req); 311 unsigned count = blk_rq_cur_sectors(req);
312 XD_INFO *disk = req->rq_disk->private_data; 312 XD_INFO *disk = req->rq_disk->private_data;
313 int res = 0; 313 int res = -EIO;
314 int retry; 314 int retry;
315 315
316 if (!blk_fs_request(req)) { 316 if (!blk_fs_request(req))
317 end_request(req, 0); 317 goto done;
318 continue; 318 if (block + count > get_capacity(req->rq_disk))
319 } 319 goto done;
320 if (block + count > get_capacity(req->rq_disk)) {
321 end_request(req, 0);
322 continue;
323 }
324 if (rw != READ && rw != WRITE) {
325 printk("do_xd_request: unknown request\n");
326 end_request(req, 0);
327 continue;
328 }
329 for (retry = 0; (retry < XD_RETRIES) && !res; retry++) 320 for (retry = 0; (retry < XD_RETRIES) && !res; retry++)
330 res = xd_readwrite(rw, disk, req->buffer, block, count); 321 res = xd_readwrite(rq_data_dir(req), disk, req->buffer,
331 end_request(req, res); /* wrap up, 0 = fail, 1 = success */ 322 block, count);
323 done:
324 /* wrap up, 0 = success, -errno = fail */
325 if (!__blk_end_request_cur(req, res))
326 req = blk_fetch_request(q);
332 } 327 }
333} 328}
334 329
@@ -418,7 +413,7 @@ static int xd_readwrite (u_char operation,XD_INFO *p,char *buffer,u_int block,u_
418 printk("xd%c: %s timeout, recalibrating drive\n",'a'+drive,(operation == READ ? "read" : "write")); 413 printk("xd%c: %s timeout, recalibrating drive\n",'a'+drive,(operation == READ ? "read" : "write"));
419 xd_recalibrate(drive); 414 xd_recalibrate(drive);
420 spin_lock_irq(&xd_lock); 415 spin_lock_irq(&xd_lock);
421 return (0); 416 return -EIO;
422 case 2: 417 case 2:
423 if (sense[0] & 0x30) { 418 if (sense[0] & 0x30) {
424 printk("xd%c: %s - ",'a'+drive,(operation == READ ? "reading" : "writing")); 419 printk("xd%c: %s - ",'a'+drive,(operation == READ ? "reading" : "writing"));
@@ -439,7 +434,7 @@ static int xd_readwrite (u_char operation,XD_INFO *p,char *buffer,u_int block,u_
439 else 434 else
440 printk(" - no valid disk address\n"); 435 printk(" - no valid disk address\n");
441 spin_lock_irq(&xd_lock); 436 spin_lock_irq(&xd_lock);
442 return (0); 437 return -EIO;
443 } 438 }
444 if (xd_dma_buffer) 439 if (xd_dma_buffer)
445 for (i=0; i < (temp * 0x200); i++) 440 for (i=0; i < (temp * 0x200); i++)
@@ -448,7 +443,7 @@ static int xd_readwrite (u_char operation,XD_INFO *p,char *buffer,u_int block,u_
448 count -= temp, buffer += temp * 0x200, block += temp; 443 count -= temp, buffer += temp * 0x200, block += temp;
449 } 444 }
450 spin_lock_irq(&xd_lock); 445 spin_lock_irq(&xd_lock);
451 return (1); 446 return 0;
452} 447}
453 448
454/* xd_recalibrate: recalibrate a given drive and reset controller if necessary */ 449/* xd_recalibrate: recalibrate a given drive and reset controller if necessary */
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index a6cbf7b808e6..c1996829d5ec 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -122,7 +122,7 @@ static DEFINE_SPINLOCK(blkif_io_lock);
122static int get_id_from_freelist(struct blkfront_info *info) 122static int get_id_from_freelist(struct blkfront_info *info)
123{ 123{
124 unsigned long free = info->shadow_free; 124 unsigned long free = info->shadow_free;
125 BUG_ON(free > BLK_RING_SIZE); 125 BUG_ON(free >= BLK_RING_SIZE);
126 info->shadow_free = info->shadow[free].req.id; 126 info->shadow_free = info->shadow[free].req.id;
127 info->shadow[free].req.id = 0x0fffffee; /* debug */ 127 info->shadow[free].req.id = 0x0fffffee; /* debug */
128 return free; 128 return free;
@@ -231,7 +231,7 @@ static int blkif_queue_request(struct request *req)
231 info->shadow[id].request = (unsigned long)req; 231 info->shadow[id].request = (unsigned long)req;
232 232
233 ring_req->id = id; 233 ring_req->id = id;
234 ring_req->sector_number = (blkif_sector_t)req->sector; 234 ring_req->sector_number = (blkif_sector_t)blk_rq_pos(req);
235 ring_req->handle = info->handle; 235 ring_req->handle = info->handle;
236 236
237 ring_req->operation = rq_data_dir(req) ? 237 ring_req->operation = rq_data_dir(req) ?
@@ -299,25 +299,25 @@ static void do_blkif_request(struct request_queue *rq)
299 299
300 queued = 0; 300 queued = 0;
301 301
302 while ((req = elv_next_request(rq)) != NULL) { 302 while ((req = blk_peek_request(rq)) != NULL) {
303 info = req->rq_disk->private_data; 303 info = req->rq_disk->private_data;
304 if (!blk_fs_request(req)) {
305 end_request(req, 0);
306 continue;
307 }
308 304
309 if (RING_FULL(&info->ring)) 305 if (RING_FULL(&info->ring))
310 goto wait; 306 goto wait;
311 307
312 pr_debug("do_blk_req %p: cmd %p, sec %lx, " 308 blk_start_request(req);
313 "(%u/%li) buffer:%p [%s]\n",
314 req, req->cmd, (unsigned long)req->sector,
315 req->current_nr_sectors,
316 req->nr_sectors, req->buffer,
317 rq_data_dir(req) ? "write" : "read");
318 309
310 if (!blk_fs_request(req)) {
311 __blk_end_request_all(req, -EIO);
312 continue;
313 }
314
315 pr_debug("do_blk_req %p: cmd %p, sec %lx, "
316 "(%u/%u) buffer:%p [%s]\n",
317 req, req->cmd, (unsigned long)blk_rq_pos(req),
318 blk_rq_cur_sectors(req), blk_rq_sectors(req),
319 req->buffer, rq_data_dir(req) ? "write" : "read");
319 320
320 blkdev_dequeue_request(req);
321 if (blkif_queue_request(req)) { 321 if (blkif_queue_request(req)) {
322 blk_requeue_request(rq, req); 322 blk_requeue_request(rq, req);
323wait: 323wait:
@@ -344,7 +344,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
344 queue_flag_set_unlocked(QUEUE_FLAG_VIRT, rq); 344 queue_flag_set_unlocked(QUEUE_FLAG_VIRT, rq);
345 345
346 /* Hard sector size and max sectors impersonate the equiv. hardware. */ 346 /* Hard sector size and max sectors impersonate the equiv. hardware. */
347 blk_queue_hardsect_size(rq, sector_size); 347 blk_queue_logical_block_size(rq, sector_size);
348 blk_queue_max_sectors(rq, 512); 348 blk_queue_max_sectors(rq, 512);
349 349
350 /* Each segment in a request is up to an aligned page in size. */ 350 /* Each segment in a request is up to an aligned page in size. */
@@ -551,7 +551,6 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
551 551
552 for (i = info->ring.rsp_cons; i != rp; i++) { 552 for (i = info->ring.rsp_cons; i != rp; i++) {
553 unsigned long id; 553 unsigned long id;
554 int ret;
555 554
556 bret = RING_GET_RESPONSE(&info->ring, i); 555 bret = RING_GET_RESPONSE(&info->ring, i);
557 id = bret->id; 556 id = bret->id;
@@ -578,8 +577,7 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
578 dev_dbg(&info->xbdev->dev, "Bad return from blkdev data " 577 dev_dbg(&info->xbdev->dev, "Bad return from blkdev data "
579 "request: %x\n", bret->status); 578 "request: %x\n", bret->status);
580 579
581 ret = __blk_end_request(req, error, blk_rq_bytes(req)); 580 __blk_end_request_all(req, error);
582 BUG_ON(ret);
583 break; 581 break;
584 default: 582 default:
585 BUG(); 583 BUG();
diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c
index 4aecf5dc6a93..f08491a3a813 100644
--- a/drivers/block/xsysace.c
+++ b/drivers/block/xsysace.c
@@ -463,10 +463,11 @@ struct request *ace_get_next_request(struct request_queue * q)
463{ 463{
464 struct request *req; 464 struct request *req;
465 465
466 while ((req = elv_next_request(q)) != NULL) { 466 while ((req = blk_peek_request(q)) != NULL) {
467 if (blk_fs_request(req)) 467 if (blk_fs_request(req))
468 break; 468 break;
469 end_request(req, 0); 469 blk_start_request(req);
470 __blk_end_request_all(req, -EIO);
470 } 471 }
471 return req; 472 return req;
472} 473}
@@ -492,9 +493,13 @@ static void ace_fsm_dostate(struct ace_device *ace)
492 set_capacity(ace->gd, 0); 493 set_capacity(ace->gd, 0);
493 dev_info(ace->dev, "No CF in slot\n"); 494 dev_info(ace->dev, "No CF in slot\n");
494 495
495 /* Drop all pending requests */ 496 /* Drop all in-flight and pending requests */
496 while ((req = elv_next_request(ace->queue)) != NULL) 497 if (ace->req) {
497 end_request(req, 0); 498 __blk_end_request_all(ace->req, -EIO);
499 ace->req = NULL;
500 }
501 while ((req = blk_fetch_request(ace->queue)) != NULL)
502 __blk_end_request_all(req, -EIO);
498 503
499 /* Drop back to IDLE state and notify waiters */ 504 /* Drop back to IDLE state and notify waiters */
500 ace->fsm_state = ACE_FSM_STATE_IDLE; 505 ace->fsm_state = ACE_FSM_STATE_IDLE;
@@ -642,19 +647,21 @@ static void ace_fsm_dostate(struct ace_device *ace)
642 ace->fsm_state = ACE_FSM_STATE_IDLE; 647 ace->fsm_state = ACE_FSM_STATE_IDLE;
643 break; 648 break;
644 } 649 }
650 blk_start_request(req);
645 651
646 /* Okay, it's a data request, set it up for transfer */ 652 /* Okay, it's a data request, set it up for transfer */
647 dev_dbg(ace->dev, 653 dev_dbg(ace->dev,
648 "request: sec=%llx hcnt=%lx, ccnt=%x, dir=%i\n", 654 "request: sec=%llx hcnt=%x, ccnt=%x, dir=%i\n",
649 (unsigned long long) req->sector, req->hard_nr_sectors, 655 (unsigned long long)blk_rq_pos(req),
650 req->current_nr_sectors, rq_data_dir(req)); 656 blk_rq_sectors(req), blk_rq_cur_sectors(req),
657 rq_data_dir(req));
651 658
652 ace->req = req; 659 ace->req = req;
653 ace->data_ptr = req->buffer; 660 ace->data_ptr = req->buffer;
654 ace->data_count = req->current_nr_sectors * ACE_BUF_PER_SECTOR; 661 ace->data_count = blk_rq_cur_sectors(req) * ACE_BUF_PER_SECTOR;
655 ace_out32(ace, ACE_MPULBA, req->sector & 0x0FFFFFFF); 662 ace_out32(ace, ACE_MPULBA, blk_rq_pos(req) & 0x0FFFFFFF);
656 663
657 count = req->hard_nr_sectors; 664 count = blk_rq_sectors(req);
658 if (rq_data_dir(req)) { 665 if (rq_data_dir(req)) {
659 /* Kick off write request */ 666 /* Kick off write request */
660 dev_dbg(ace->dev, "write data\n"); 667 dev_dbg(ace->dev, "write data\n");
@@ -688,7 +695,7 @@ static void ace_fsm_dostate(struct ace_device *ace)
688 dev_dbg(ace->dev, 695 dev_dbg(ace->dev,
689 "CFBSY set; t=%i iter=%i c=%i dc=%i irq=%i\n", 696 "CFBSY set; t=%i iter=%i c=%i dc=%i irq=%i\n",
690 ace->fsm_task, ace->fsm_iter_num, 697 ace->fsm_task, ace->fsm_iter_num,
691 ace->req->current_nr_sectors * 16, 698 blk_rq_cur_sectors(ace->req) * 16,
692 ace->data_count, ace->in_irq); 699 ace->data_count, ace->in_irq);
693 ace_fsm_yield(ace); /* need to poll CFBSY bit */ 700 ace_fsm_yield(ace); /* need to poll CFBSY bit */
694 break; 701 break;
@@ -697,7 +704,7 @@ static void ace_fsm_dostate(struct ace_device *ace)
697 dev_dbg(ace->dev, 704 dev_dbg(ace->dev,
698 "DATABUF not set; t=%i iter=%i c=%i dc=%i irq=%i\n", 705 "DATABUF not set; t=%i iter=%i c=%i dc=%i irq=%i\n",
699 ace->fsm_task, ace->fsm_iter_num, 706 ace->fsm_task, ace->fsm_iter_num,
700 ace->req->current_nr_sectors * 16, 707 blk_rq_cur_sectors(ace->req) * 16,
701 ace->data_count, ace->in_irq); 708 ace->data_count, ace->in_irq);
702 ace_fsm_yieldirq(ace); 709 ace_fsm_yieldirq(ace);
703 break; 710 break;
@@ -717,14 +724,13 @@ static void ace_fsm_dostate(struct ace_device *ace)
717 } 724 }
718 725
719 /* bio finished; is there another one? */ 726 /* bio finished; is there another one? */
720 if (__blk_end_request(ace->req, 0, 727 if (__blk_end_request_cur(ace->req, 0)) {
721 blk_rq_cur_bytes(ace->req))) { 728 /* dev_dbg(ace->dev, "next block; h=%u c=%u\n",
722 /* dev_dbg(ace->dev, "next block; h=%li c=%i\n", 729 * blk_rq_sectors(ace->req),
723 * ace->req->hard_nr_sectors, 730 * blk_rq_cur_sectors(ace->req));
724 * ace->req->current_nr_sectors);
725 */ 731 */
726 ace->data_ptr = ace->req->buffer; 732 ace->data_ptr = ace->req->buffer;
727 ace->data_count = ace->req->current_nr_sectors * 16; 733 ace->data_count = blk_rq_cur_sectors(ace->req) * 16;
728 ace_fsm_yieldirq(ace); 734 ace_fsm_yieldirq(ace);
729 break; 735 break;
730 } 736 }
@@ -978,7 +984,7 @@ static int __devinit ace_setup(struct ace_device *ace)
978 ace->queue = blk_init_queue(ace_request, &ace->lock); 984 ace->queue = blk_init_queue(ace_request, &ace->lock);
979 if (ace->queue == NULL) 985 if (ace->queue == NULL)
980 goto err_blk_initq; 986 goto err_blk_initq;
981 blk_queue_hardsect_size(ace->queue, 512); 987 blk_queue_logical_block_size(ace->queue, 512);
982 988
983 /* 989 /*
984 * Allocate and initialize GD structure 990 * Allocate and initialize GD structure
diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index 80754cdd3119..4575171e5beb 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -70,15 +70,18 @@ static struct gendisk *z2ram_gendisk;
70static void do_z2_request(struct request_queue *q) 70static void do_z2_request(struct request_queue *q)
71{ 71{
72 struct request *req; 72 struct request *req;
73 while ((req = elv_next_request(q)) != NULL) { 73
74 unsigned long start = req->sector << 9; 74 req = blk_fetch_request(q);
75 unsigned long len = req->current_nr_sectors << 9; 75 while (req) {
76 unsigned long start = blk_rq_pos(req) << 9;
77 unsigned long len = blk_rq_cur_bytes(req);
78 int err = 0;
76 79
77 if (start + len > z2ram_size) { 80 if (start + len > z2ram_size) {
78 printk( KERN_ERR DEVICE_NAME ": bad access: block=%lu, count=%u\n", 81 printk( KERN_ERR DEVICE_NAME ": bad access: block=%lu, count=%u\n",
79 req->sector, req->current_nr_sectors); 82 blk_rq_pos(req), blk_rq_cur_sectors(req));
80 end_request(req, 0); 83 err = -EIO;
81 continue; 84 goto done;
82 } 85 }
83 while (len) { 86 while (len) {
84 unsigned long addr = start & Z2RAM_CHUNKMASK; 87 unsigned long addr = start & Z2RAM_CHUNKMASK;
@@ -93,7 +96,9 @@ static void do_z2_request(struct request_queue *q)
93 start += size; 96 start += size;
94 len -= size; 97 len -= size;
95 } 98 }
96 end_request(req, 1); 99 done:
100 if (!__blk_end_request_cur(req, err))
101 req = blk_fetch_request(q);
97 } 102 }
98} 103}
99 104
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index af761dc434f6..4895f0e05322 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -277,8 +277,8 @@ static int hci_uart_tty_open(struct tty_struct *tty)
277 /* FIXME: why is this needed. Note don't use ldisc_ref here as the 277 /* FIXME: why is this needed. Note don't use ldisc_ref here as the
278 open path is before the ldisc is referencable */ 278 open path is before the ldisc is referencable */
279 279
280 if (tty->ldisc.ops->flush_buffer) 280 if (tty->ldisc->ops->flush_buffer)
281 tty->ldisc.ops->flush_buffer(tty); 281 tty->ldisc->ops->flush_buffer(tty);
282 tty_driver_flush_buffer(tty); 282 tty_driver_flush_buffer(tty);
283 283
284 return 0; 284 return 0;
@@ -463,7 +463,6 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file,
463 clear_bit(HCI_UART_PROTO_SET, &hu->flags); 463 clear_bit(HCI_UART_PROTO_SET, &hu->flags);
464 return err; 464 return err;
465 } 465 }
466 tty->low_latency = 1;
467 } else 466 } else
468 return -EBUSY; 467 return -EBUSY;
469 break; 468 break;
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index cceace61ef28..71d1b9bab70b 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -2101,8 +2101,8 @@ static int cdrom_read_cdda_bpc(struct cdrom_device_info *cdi, __u8 __user *ubuf,
2101 nr = nframes; 2101 nr = nframes;
2102 if (cdi->cdda_method == CDDA_BPC_SINGLE) 2102 if (cdi->cdda_method == CDDA_BPC_SINGLE)
2103 nr = 1; 2103 nr = 1;
2104 if (nr * CD_FRAMESIZE_RAW > (q->max_sectors << 9)) 2104 if (nr * CD_FRAMESIZE_RAW > (queue_max_sectors(q) << 9))
2105 nr = (q->max_sectors << 9) / CD_FRAMESIZE_RAW; 2105 nr = (queue_max_sectors(q) << 9) / CD_FRAMESIZE_RAW;
2106 2106
2107 len = nr * CD_FRAMESIZE_RAW; 2107 len = nr * CD_FRAMESIZE_RAW;
2108 2108
diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index 2eecb779437b..b5621f27c4be 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -584,8 +584,8 @@ static void gdrom_readdisk_dma(struct work_struct *work)
584 list_for_each_safe(elem, next, &gdrom_deferred) { 584 list_for_each_safe(elem, next, &gdrom_deferred) {
585 req = list_entry(elem, struct request, queuelist); 585 req = list_entry(elem, struct request, queuelist);
586 spin_unlock(&gdrom_lock); 586 spin_unlock(&gdrom_lock);
587 block = req->sector/GD_TO_BLK + GD_SESSION_OFFSET; 587 block = blk_rq_pos(req)/GD_TO_BLK + GD_SESSION_OFFSET;
588 block_cnt = req->nr_sectors/GD_TO_BLK; 588 block_cnt = blk_rq_sectors(req)/GD_TO_BLK;
589 ctrl_outl(PHYSADDR(req->buffer), GDROM_DMA_STARTADDR_REG); 589 ctrl_outl(PHYSADDR(req->buffer), GDROM_DMA_STARTADDR_REG);
590 ctrl_outl(block_cnt * GDROM_HARD_SECTOR, GDROM_DMA_LENGTH_REG); 590 ctrl_outl(block_cnt * GDROM_HARD_SECTOR, GDROM_DMA_LENGTH_REG);
591 ctrl_outl(1, GDROM_DMA_DIRECTION_REG); 591 ctrl_outl(1, GDROM_DMA_DIRECTION_REG);
@@ -632,39 +632,35 @@ static void gdrom_readdisk_dma(struct work_struct *work)
632 * before handling ending the request */ 632 * before handling ending the request */
633 spin_lock(&gdrom_lock); 633 spin_lock(&gdrom_lock);
634 list_del_init(&req->queuelist); 634 list_del_init(&req->queuelist);
635 __blk_end_request(req, err, blk_rq_bytes(req)); 635 __blk_end_request_all(req, err);
636 } 636 }
637 spin_unlock(&gdrom_lock); 637 spin_unlock(&gdrom_lock);
638 kfree(read_command); 638 kfree(read_command);
639} 639}
640 640
641static void gdrom_request_handler_dma(struct request *req)
642{
643 /* dequeue, add to list of deferred work
644 * and then schedule workqueue */
645 blkdev_dequeue_request(req);
646 list_add_tail(&req->queuelist, &gdrom_deferred);
647 schedule_work(&work);
648}
649
650static void gdrom_request(struct request_queue *rq) 641static void gdrom_request(struct request_queue *rq)
651{ 642{
652 struct request *req; 643 struct request *req;
653 644
654 while ((req = elv_next_request(rq)) != NULL) { 645 while ((req = blk_fetch_request(rq)) != NULL) {
655 if (!blk_fs_request(req)) { 646 if (!blk_fs_request(req)) {
656 printk(KERN_DEBUG "GDROM: Non-fs request ignored\n"); 647 printk(KERN_DEBUG "GDROM: Non-fs request ignored\n");
657 end_request(req, 0); 648 __blk_end_request_all(req, -EIO);
649 continue;
658 } 650 }
659 if (rq_data_dir(req) != READ) { 651 if (rq_data_dir(req) != READ) {
660 printk(KERN_NOTICE "GDROM: Read only device -"); 652 printk(KERN_NOTICE "GDROM: Read only device -");
661 printk(" write request ignored\n"); 653 printk(" write request ignored\n");
662 end_request(req, 0); 654 __blk_end_request_all(req, -EIO);
655 continue;
663 } 656 }
664 if (req->nr_sectors) 657
665 gdrom_request_handler_dma(req); 658 /*
666 else 659 * Add to list of deferred work and then schedule
667 end_request(req, 0); 660 * workqueue.
661 */
662 list_add_tail(&req->queuelist, &gdrom_deferred);
663 schedule_work(&work);
668 } 664 }
669} 665}
670 666
@@ -743,7 +739,7 @@ static void __devinit probe_gdrom_setupdisk(void)
743 739
744static int __devinit probe_gdrom_setupqueue(void) 740static int __devinit probe_gdrom_setupqueue(void)
745{ 741{
746 blk_queue_hardsect_size(gd.gdrom_rq, GDROM_HARD_SECTOR); 742 blk_queue_logical_block_size(gd.gdrom_rq, GDROM_HARD_SECTOR);
747 /* using DMA so memory will need to be contiguous */ 743 /* using DMA so memory will need to be contiguous */
748 blk_queue_max_hw_segments(gd.gdrom_rq, 1); 744 blk_queue_max_hw_segments(gd.gdrom_rq, 1);
749 /* set a large max size to get most from DMA */ 745 /* set a large max size to get most from DMA */
diff --git a/drivers/cdrom/viocd.c b/drivers/cdrom/viocd.c
index 9b1624e0ddeb..0fff646cc2f0 100644
--- a/drivers/cdrom/viocd.c
+++ b/drivers/cdrom/viocd.c
@@ -282,7 +282,7 @@ static int send_request(struct request *req)
282 viopath_targetinst(viopath_hostLp), 282 viopath_targetinst(viopath_hostLp),
283 (u64)req, VIOVERSION << 16, 283 (u64)req, VIOVERSION << 16,
284 ((u64)DEVICE_NR(diskinfo) << 48) | dmaaddr, 284 ((u64)DEVICE_NR(diskinfo) << 48) | dmaaddr,
285 (u64)req->sector * 512, len, 0); 285 (u64)blk_rq_pos(req) * 512, len, 0);
286 if (hvrc != HvLpEvent_Rc_Good) { 286 if (hvrc != HvLpEvent_Rc_Good) {
287 printk(VIOCD_KERN_WARNING "hv error on op %d\n", (int)hvrc); 287 printk(VIOCD_KERN_WARNING "hv error on op %d\n", (int)hvrc);
288 return -1; 288 return -1;
@@ -291,36 +291,19 @@ static int send_request(struct request *req)
291 return 0; 291 return 0;
292} 292}
293 293
294static void viocd_end_request(struct request *req, int error)
295{
296 int nsectors = req->hard_nr_sectors;
297
298 /*
299 * Make sure it's fully ended, and ensure that we process
300 * at least one sector.
301 */
302 if (blk_pc_request(req))
303 nsectors = (req->data_len + 511) >> 9;
304 if (!nsectors)
305 nsectors = 1;
306
307 if (__blk_end_request(req, error, nsectors << 9))
308 BUG();
309}
310
311static int rwreq; 294static int rwreq;
312 295
313static void do_viocd_request(struct request_queue *q) 296static void do_viocd_request(struct request_queue *q)
314{ 297{
315 struct request *req; 298 struct request *req;
316 299
317 while ((rwreq == 0) && ((req = elv_next_request(q)) != NULL)) { 300 while ((rwreq == 0) && ((req = blk_fetch_request(q)) != NULL)) {
318 if (!blk_fs_request(req)) 301 if (!blk_fs_request(req))
319 viocd_end_request(req, -EIO); 302 __blk_end_request_all(req, -EIO);
320 else if (send_request(req) < 0) { 303 else if (send_request(req) < 0) {
321 printk(VIOCD_KERN_WARNING 304 printk(VIOCD_KERN_WARNING
322 "unable to send message to OS/400!"); 305 "unable to send message to OS/400!");
323 viocd_end_request(req, -EIO); 306 __blk_end_request_all(req, -EIO);
324 } else 307 } else
325 rwreq++; 308 rwreq++;
326 } 309 }
@@ -486,8 +469,8 @@ static void vio_handle_cd_event(struct HvLpEvent *event)
486 case viocdopen: 469 case viocdopen:
487 if (event->xRc == 0) { 470 if (event->xRc == 0) {
488 di = &viocd_diskinfo[bevent->disk]; 471 di = &viocd_diskinfo[bevent->disk];
489 blk_queue_hardsect_size(di->viocd_disk->queue, 472 blk_queue_logical_block_size(di->viocd_disk->queue,
490 bevent->block_size); 473 bevent->block_size);
491 set_capacity(di->viocd_disk, 474 set_capacity(di->viocd_disk,
492 bevent->media_size * 475 bevent->media_size *
493 bevent->block_size / 512); 476 bevent->block_size / 512);
@@ -531,9 +514,9 @@ return_complete:
531 "with rc %d:0x%04X: %s\n", 514 "with rc %d:0x%04X: %s\n",
532 req, event->xRc, 515 req, event->xRc,
533 bevent->sub_result, err->msg); 516 bevent->sub_result, err->msg);
534 viocd_end_request(req, -EIO); 517 __blk_end_request_all(req, -EIO);
535 } else 518 } else
536 viocd_end_request(req, 0); 519 __blk_end_request_all(req, 0);
537 520
538 /* restart handling of incoming requests */ 521 /* restart handling of incoming requests */
539 spin_unlock_irqrestore(&viocd_reqlock, flags); 522 spin_unlock_irqrestore(&viocd_reqlock, flags);
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 735bbe2be51a..02ecfd5fa61c 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -97,6 +97,19 @@ config DEVKMEM
97 kind of kernel debugging operations. 97 kind of kernel debugging operations.
98 When in doubt, say "N". 98 When in doubt, say "N".
99 99
100config BFIN_JTAG_COMM
101 tristate "Blackfin JTAG Communication"
102 depends on BLACKFIN
103 help
104 Add support for emulating a TTY device over the Blackfin JTAG.
105
106 To compile this driver as a module, choose M here: the
107 module will be called bfin_jtag_comm.
108
109config BFIN_JTAG_COMM_CONSOLE
110 bool "Console on Blackfin JTAG"
111 depends on BFIN_JTAG_COMM=y
112
100config SERIAL_NONSTANDARD 113config SERIAL_NONSTANDARD
101 bool "Non-standard serial port support" 114 bool "Non-standard serial port support"
102 depends on HAS_IOMEM 115 depends on HAS_IOMEM
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 9caf5b5ad1c0..189efcff08ce 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_LEGACY_PTYS) += pty.o
13obj-$(CONFIG_UNIX98_PTYS) += pty.o 13obj-$(CONFIG_UNIX98_PTYS) += pty.o
14obj-y += misc.o 14obj-y += misc.o
15obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o selection.o keyboard.o 15obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o selection.o keyboard.o
16obj-$(CONFIG_BFIN_JTAG_COMM) += bfin_jtag_comm.o
16obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o 17obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o
17obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o 18obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o
18obj-$(CONFIG_AUDIT) += tty_audit.o 19obj-$(CONFIG_AUDIT) += tty_audit.o
diff --git a/drivers/char/bfin_jtag_comm.c b/drivers/char/bfin_jtag_comm.c
new file mode 100644
index 000000000000..44c113d56045
--- /dev/null
+++ b/drivers/char/bfin_jtag_comm.c
@@ -0,0 +1,365 @@
1/*
2 * TTY over Blackfin JTAG Communication
3 *
4 * Copyright 2008-2009 Analog Devices Inc.
5 *
6 * Enter bugs at http://blackfin.uclinux.org/
7 *
8 * Licensed under the GPL-2 or later.
9 */
10
11#include <linux/circ_buf.h>
12#include <linux/console.h>
13#include <linux/delay.h>
14#include <linux/err.h>
15#include <linux/kernel.h>
16#include <linux/kthread.h>
17#include <linux/module.h>
18#include <linux/mutex.h>
19#include <linux/sched.h>
20#include <linux/tty.h>
21#include <linux/tty_driver.h>
22#include <linux/tty_flip.h>
23#include <asm/atomic.h>
24
25/* See the Debug/Emulation chapter in the HRM */
26#define EMUDOF 0x00000001 /* EMUDAT_OUT full & valid */
27#define EMUDIF 0x00000002 /* EMUDAT_IN full & valid */
28#define EMUDOOVF 0x00000004 /* EMUDAT_OUT overflow */
29#define EMUDIOVF 0x00000008 /* EMUDAT_IN overflow */
30
31#define DRV_NAME "bfin-jtag-comm"
32#define DEV_NAME "ttyBFJC"
33
34#define pr_init(fmt, args...) ({ static const __initdata char __fmt[] = fmt; printk(__fmt, ## args); })
35#define debug(fmt, args...) pr_debug(DRV_NAME ": " fmt, ## args)
36
37static inline uint32_t bfin_write_emudat(uint32_t emudat)
38{
39 __asm__ __volatile__("emudat = %0;" : : "d"(emudat));
40 return emudat;
41}
42
43static inline uint32_t bfin_read_emudat(void)
44{
45 uint32_t emudat;
46 __asm__ __volatile__("%0 = emudat;" : "=d"(emudat));
47 return emudat;
48}
49
50static inline uint32_t bfin_write_emudat_chars(char a, char b, char c, char d)
51{
52 return bfin_write_emudat((a << 0) | (b << 8) | (c << 16) | (d << 24));
53}
54
55#define CIRC_SIZE 2048 /* see comment in tty_io.c:do_tty_write() */
56#define CIRC_MASK (CIRC_SIZE - 1)
57#define circ_empty(circ) ((circ)->head == (circ)->tail)
58#define circ_free(circ) CIRC_SPACE((circ)->head, (circ)->tail, CIRC_SIZE)
59#define circ_cnt(circ) CIRC_CNT((circ)->head, (circ)->tail, CIRC_SIZE)
60#define circ_byte(circ, idx) ((circ)->buf[(idx) & CIRC_MASK])
61
62static struct tty_driver *bfin_jc_driver;
63static struct task_struct *bfin_jc_kthread;
64static struct tty_struct * volatile bfin_jc_tty;
65static unsigned long bfin_jc_count;
66static DEFINE_MUTEX(bfin_jc_tty_mutex);
67static volatile struct circ_buf bfin_jc_write_buf;
68
69static int
70bfin_jc_emudat_manager(void *arg)
71{
72 uint32_t inbound_len = 0, outbound_len = 0;
73
74 while (!kthread_should_stop()) {
75 /* no one left to give data to, so sleep */
76 if (bfin_jc_tty == NULL && circ_empty(&bfin_jc_write_buf)) {
77 debug("waiting for readers\n");
78 __set_current_state(TASK_UNINTERRUPTIBLE);
79 schedule();
80 __set_current_state(TASK_RUNNING);
81 }
82
83 /* no data available, so just chill */
84 if (!(bfin_read_DBGSTAT() & EMUDIF) && circ_empty(&bfin_jc_write_buf)) {
85 debug("waiting for data (in_len = %i) (circ: %i %i)\n",
86 inbound_len, bfin_jc_write_buf.tail, bfin_jc_write_buf.head);
87 if (inbound_len)
88 schedule();
89 else
90 schedule_timeout_interruptible(HZ);
91 continue;
92 }
93
94 /* if incoming data is ready, eat it */
95 if (bfin_read_DBGSTAT() & EMUDIF) {
96 struct tty_struct *tty;
97 mutex_lock(&bfin_jc_tty_mutex);
98 tty = (struct tty_struct *)bfin_jc_tty;
99 if (tty != NULL) {
100 uint32_t emudat = bfin_read_emudat();
101 if (inbound_len == 0) {
102 debug("incoming length: 0x%08x\n", emudat);
103 inbound_len = emudat;
104 } else {
105 size_t num_chars = (4 <= inbound_len ? 4 : inbound_len);
106 debug(" incoming data: 0x%08x (pushing %zu)\n", emudat, num_chars);
107 inbound_len -= num_chars;
108 tty_insert_flip_string(tty, (unsigned char *)&emudat, num_chars);
109 tty_flip_buffer_push(tty);
110 }
111 }
112 mutex_unlock(&bfin_jc_tty_mutex);
113 }
114
115 /* if outgoing data is ready, post it */
116 if (!(bfin_read_DBGSTAT() & EMUDOF) && !circ_empty(&bfin_jc_write_buf)) {
117 if (outbound_len == 0) {
118 outbound_len = circ_cnt(&bfin_jc_write_buf);
119 bfin_write_emudat(outbound_len);
120 debug("outgoing length: 0x%08x\n", outbound_len);
121 } else {
122 struct tty_struct *tty;
123 int tail = bfin_jc_write_buf.tail;
124 size_t ate = (4 <= outbound_len ? 4 : outbound_len);
125 uint32_t emudat =
126 bfin_write_emudat_chars(
127 circ_byte(&bfin_jc_write_buf, tail + 0),
128 circ_byte(&bfin_jc_write_buf, tail + 1),
129 circ_byte(&bfin_jc_write_buf, tail + 2),
130 circ_byte(&bfin_jc_write_buf, tail + 3)
131 );
132 bfin_jc_write_buf.tail += ate;
133 outbound_len -= ate;
134 mutex_lock(&bfin_jc_tty_mutex);
135 tty = (struct tty_struct *)bfin_jc_tty;
136 if (tty)
137 tty_wakeup(tty);
138 mutex_unlock(&bfin_jc_tty_mutex);
139 debug(" outgoing data: 0x%08x (pushing %zu)\n", emudat, ate);
140 }
141 }
142 }
143
144 __set_current_state(TASK_RUNNING);
145 return 0;
146}
147
148static int
149bfin_jc_open(struct tty_struct *tty, struct file *filp)
150{
151 mutex_lock(&bfin_jc_tty_mutex);
152 debug("open %lu\n", bfin_jc_count);
153 ++bfin_jc_count;
154 bfin_jc_tty = tty;
155 wake_up_process(bfin_jc_kthread);
156 mutex_unlock(&bfin_jc_tty_mutex);
157 return 0;
158}
159
160static void
161bfin_jc_close(struct tty_struct *tty, struct file *filp)
162{
163 mutex_lock(&bfin_jc_tty_mutex);
164 debug("close %lu\n", bfin_jc_count);
165 if (--bfin_jc_count == 0)
166 bfin_jc_tty = NULL;
167 wake_up_process(bfin_jc_kthread);
168 mutex_unlock(&bfin_jc_tty_mutex);
169}
170
171/* XXX: we dont handle the put_char() case where we must handle count = 1 */
172static int
173bfin_jc_circ_write(const unsigned char *buf, int count)
174{
175 int i;
176 count = min(count, circ_free(&bfin_jc_write_buf));
177 debug("going to write chunk of %i bytes\n", count);
178 for (i = 0; i < count; ++i)
179 circ_byte(&bfin_jc_write_buf, bfin_jc_write_buf.head + i) = buf[i];
180 bfin_jc_write_buf.head += i;
181 return i;
182}
183
184#ifndef CONFIG_BFIN_JTAG_COMM_CONSOLE
185# define acquire_console_sem()
186# define release_console_sem()
187#endif
188static int
189bfin_jc_write(struct tty_struct *tty, const unsigned char *buf, int count)
190{
191 int i;
192 acquire_console_sem();
193 i = bfin_jc_circ_write(buf, count);
194 release_console_sem();
195 wake_up_process(bfin_jc_kthread);
196 return i;
197}
198
199static void
200bfin_jc_flush_chars(struct tty_struct *tty)
201{
202 wake_up_process(bfin_jc_kthread);
203}
204
205static int
206bfin_jc_write_room(struct tty_struct *tty)
207{
208 return circ_free(&bfin_jc_write_buf);
209}
210
211static int
212bfin_jc_chars_in_buffer(struct tty_struct *tty)
213{
214 return circ_cnt(&bfin_jc_write_buf);
215}
216
217static void
218bfin_jc_wait_until_sent(struct tty_struct *tty, int timeout)
219{
220 unsigned long expire = jiffies + timeout;
221 while (!circ_empty(&bfin_jc_write_buf)) {
222 if (signal_pending(current))
223 break;
224 if (time_after(jiffies, expire))
225 break;
226 }
227}
228
229static struct tty_operations bfin_jc_ops = {
230 .open = bfin_jc_open,
231 .close = bfin_jc_close,
232 .write = bfin_jc_write,
233 /*.put_char = bfin_jc_put_char,*/
234 .flush_chars = bfin_jc_flush_chars,
235 .write_room = bfin_jc_write_room,
236 .chars_in_buffer = bfin_jc_chars_in_buffer,
237 .wait_until_sent = bfin_jc_wait_until_sent,
238};
239
240static int __init bfin_jc_init(void)
241{
242 int ret;
243
244 bfin_jc_kthread = kthread_create(bfin_jc_emudat_manager, NULL, DRV_NAME);
245 if (IS_ERR(bfin_jc_kthread))
246 return PTR_ERR(bfin_jc_kthread);
247
248 ret = -ENOMEM;
249
250 bfin_jc_write_buf.head = bfin_jc_write_buf.tail = 0;
251 bfin_jc_write_buf.buf = kmalloc(CIRC_SIZE, GFP_KERNEL);
252 if (!bfin_jc_write_buf.buf)
253 goto err;
254
255 bfin_jc_driver = alloc_tty_driver(1);
256 if (!bfin_jc_driver)
257 goto err;
258
259 bfin_jc_driver->owner = THIS_MODULE;
260 bfin_jc_driver->driver_name = DRV_NAME;
261 bfin_jc_driver->name = DEV_NAME;
262 bfin_jc_driver->type = TTY_DRIVER_TYPE_SERIAL;
263 bfin_jc_driver->subtype = SERIAL_TYPE_NORMAL;
264 bfin_jc_driver->init_termios = tty_std_termios;
265 tty_set_operations(bfin_jc_driver, &bfin_jc_ops);
266
267 ret = tty_register_driver(bfin_jc_driver);
268 if (ret)
269 goto err;
270
271 pr_init(KERN_INFO DRV_NAME ": initialized\n");
272
273 return 0;
274
275 err:
276 put_tty_driver(bfin_jc_driver);
277 kfree(bfin_jc_write_buf.buf);
278 kthread_stop(bfin_jc_kthread);
279 return ret;
280}
281module_init(bfin_jc_init);
282
283static void __exit bfin_jc_exit(void)
284{
285 kthread_stop(bfin_jc_kthread);
286 kfree(bfin_jc_write_buf.buf);
287 tty_unregister_driver(bfin_jc_driver);
288 put_tty_driver(bfin_jc_driver);
289}
290module_exit(bfin_jc_exit);
291
292#if defined(CONFIG_BFIN_JTAG_COMM_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
293static void
294bfin_jc_straight_buffer_write(const char *buf, unsigned count)
295{
296 unsigned ate = 0;
297 while (bfin_read_DBGSTAT() & EMUDOF)
298 continue;
299 bfin_write_emudat(count);
300 while (ate < count) {
301 while (bfin_read_DBGSTAT() & EMUDOF)
302 continue;
303 bfin_write_emudat_chars(buf[ate], buf[ate+1], buf[ate+2], buf[ate+3]);
304 ate += 4;
305 }
306}
307#endif
308
309#ifdef CONFIG_BFIN_JTAG_COMM_CONSOLE
310static void
311bfin_jc_console_write(struct console *co, const char *buf, unsigned count)
312{
313 if (bfin_jc_kthread == NULL)
314 bfin_jc_straight_buffer_write(buf, count);
315 else
316 bfin_jc_circ_write(buf, count);
317}
318
319static struct tty_driver *
320bfin_jc_console_device(struct console *co, int *index)
321{
322 *index = co->index;
323 return bfin_jc_driver;
324}
325
326static struct console bfin_jc_console = {
327 .name = DEV_NAME,
328 .write = bfin_jc_console_write,
329 .device = bfin_jc_console_device,
330 .flags = CON_ANYTIME | CON_PRINTBUFFER,
331 .index = -1,
332};
333
334static int __init bfin_jc_console_init(void)
335{
336 register_console(&bfin_jc_console);
337 return 0;
338}
339console_initcall(bfin_jc_console_init);
340#endif
341
342#ifdef CONFIG_EARLY_PRINTK
343static void __init
344bfin_jc_early_write(struct console *co, const char *buf, unsigned int count)
345{
346 bfin_jc_straight_buffer_write(buf, count);
347}
348
349static struct __initdata console bfin_jc_early_console = {
350 .name = "early_BFJC",
351 .write = bfin_jc_early_write,
352 .flags = CON_ANYTIME | CON_PRINTBUFFER,
353 .index = -1,
354};
355
356struct console * __init
357bfin_jc_early_init(unsigned int port, unsigned int cflag)
358{
359 return &bfin_jc_early_console;
360}
361#endif
362
363MODULE_AUTHOR("Mike Frysinger <vapier@gentoo.org>");
364MODULE_DESCRIPTION("TTY over Blackfin JTAG Communication");
365MODULE_LICENSE("GPL");
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index 1fdb9f657d8f..f3366d3f06cf 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -604,7 +604,6 @@
604 604
605#define NR_PORTS 256 605#define NR_PORTS 256
606 606
607#define ZE_V1_NPORTS 64
608#define ZO_V1 0 607#define ZO_V1 0
609#define ZO_V2 1 608#define ZO_V2 1
610#define ZE_V1 2 609#define ZE_V1 2
@@ -663,18 +662,6 @@
663static void cy_throttle(struct tty_struct *tty); 662static void cy_throttle(struct tty_struct *tty);
664static void cy_send_xchar(struct tty_struct *tty, char ch); 663static void cy_send_xchar(struct tty_struct *tty, char ch);
665 664
666#define IS_CYC_Z(card) ((card).num_chips == (unsigned int)-1)
667
668#define Z_FPGA_CHECK(card) \
669 ((readl(&((struct RUNTIME_9060 __iomem *) \
670 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)
671
672#define ISZLOADED(card) (((ZO_V1 == readl(&((struct RUNTIME_9060 __iomem *) \
673 ((card).ctl_addr))->mail_box_0)) || \
674 Z_FPGA_CHECK(card)) && \
675 (ZFIRM_ID == readl(&((struct FIRM_ID __iomem *) \
676 ((card).base_addr+ID_ADDRESS))->signature)))
677
678#ifndef SERIAL_XMIT_SIZE 665#ifndef SERIAL_XMIT_SIZE
679#define SERIAL_XMIT_SIZE (min(PAGE_SIZE, 4096)) 666#define SERIAL_XMIT_SIZE (min(PAGE_SIZE, 4096))
680#endif 667#endif
@@ -687,8 +674,6 @@ static void cy_send_xchar(struct tty_struct *tty, char ch);
687#define DRIVER_VERSION 0x02010203 674#define DRIVER_VERSION 0x02010203
688#define RAM_SIZE 0x80000 675#define RAM_SIZE 0x80000
689 676
690#define Z_FPGA_LOADED(X) ((readl(&(X)->init_ctrl) & (1<<17)) != 0)
691
692enum zblock_type { 677enum zblock_type {
693 ZBLOCK_PRG = 0, 678 ZBLOCK_PRG = 0,
694 ZBLOCK_FPGA = 1 679 ZBLOCK_FPGA = 1
@@ -883,6 +868,29 @@ static void cyz_rx_restart(unsigned long);
883static struct timer_list cyz_rx_full_timer[NR_PORTS]; 868static struct timer_list cyz_rx_full_timer[NR_PORTS];
884#endif /* CONFIG_CYZ_INTR */ 869#endif /* CONFIG_CYZ_INTR */
885 870
871static inline bool cy_is_Z(struct cyclades_card *card)
872{
873 return card->num_chips == (unsigned int)-1;
874}
875
876static inline bool __cyz_fpga_loaded(struct RUNTIME_9060 __iomem *ctl_addr)
877{
878 return readl(&ctl_addr->init_ctrl) & (1 << 17);
879}
880
881static inline bool cyz_fpga_loaded(struct cyclades_card *card)
882{
883 return __cyz_fpga_loaded(card->ctl_addr.p9060);
884}
885
886static inline bool cyz_is_loaded(struct cyclades_card *card)
887{
888 struct FIRM_ID __iomem *fw_id = card->base_addr + ID_ADDRESS;
889
890 return (card->hw_ver == ZO_V1 || cyz_fpga_loaded(card)) &&
891 readl(&fw_id->signature) == ZFIRM_ID;
892}
893
886static inline int serial_paranoia_check(struct cyclades_port *info, 894static inline int serial_paranoia_check(struct cyclades_port *info,
887 char *name, const char *routine) 895 char *name, const char *routine)
888{ 896{
@@ -1395,19 +1403,15 @@ cyz_fetch_msg(struct cyclades_card *cinfo,
1395 unsigned long loc_doorbell; 1403 unsigned long loc_doorbell;
1396 1404
1397 firm_id = cinfo->base_addr + ID_ADDRESS; 1405 firm_id = cinfo->base_addr + ID_ADDRESS;
1398 if (!ISZLOADED(*cinfo))
1399 return -1;
1400 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); 1406 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
1401 board_ctrl = &zfw_ctrl->board_ctrl; 1407 board_ctrl = &zfw_ctrl->board_ctrl;
1402 1408
1403 loc_doorbell = readl(&((struct RUNTIME_9060 __iomem *) 1409 loc_doorbell = readl(&cinfo->ctl_addr.p9060->loc_doorbell);
1404 (cinfo->ctl_addr))->loc_doorbell);
1405 if (loc_doorbell) { 1410 if (loc_doorbell) {
1406 *cmd = (char)(0xff & loc_doorbell); 1411 *cmd = (char)(0xff & loc_doorbell);
1407 *channel = readl(&board_ctrl->fwcmd_channel); 1412 *channel = readl(&board_ctrl->fwcmd_channel);
1408 *param = (__u32) readl(&board_ctrl->fwcmd_param); 1413 *param = (__u32) readl(&board_ctrl->fwcmd_param);
1409 cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))-> 1414 cy_writel(&cinfo->ctl_addr.p9060->loc_doorbell, 0xffffffff);
1410 loc_doorbell, 0xffffffff);
1411 return 1; 1415 return 1;
1412 } 1416 }
1413 return 0; 1417 return 0;
@@ -1424,15 +1428,14 @@ cyz_issue_cmd(struct cyclades_card *cinfo,
1424 unsigned int index; 1428 unsigned int index;
1425 1429
1426 firm_id = cinfo->base_addr + ID_ADDRESS; 1430 firm_id = cinfo->base_addr + ID_ADDRESS;
1427 if (!ISZLOADED(*cinfo)) 1431 if (!cyz_is_loaded(cinfo))
1428 return -1; 1432 return -1;
1429 1433
1430 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); 1434 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
1431 board_ctrl = &zfw_ctrl->board_ctrl; 1435 board_ctrl = &zfw_ctrl->board_ctrl;
1432 1436
1433 index = 0; 1437 index = 0;
1434 pci_doorbell = 1438 pci_doorbell = &cinfo->ctl_addr.p9060->pci_doorbell;
1435 &((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->pci_doorbell;
1436 while ((readl(pci_doorbell) & 0xff) != 0) { 1439 while ((readl(pci_doorbell) & 0xff) != 0) {
1437 if (index++ == 1000) 1440 if (index++ == 1000)
1438 return (int)(readl(pci_doorbell) & 0xff); 1441 return (int)(readl(pci_doorbell) & 0xff);
@@ -1624,10 +1627,8 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
1624 static struct BOARD_CTRL __iomem *board_ctrl; 1627 static struct BOARD_CTRL __iomem *board_ctrl;
1625 static struct CH_CTRL __iomem *ch_ctrl; 1628 static struct CH_CTRL __iomem *ch_ctrl;
1626 static struct BUF_CTRL __iomem *buf_ctrl; 1629 static struct BUF_CTRL __iomem *buf_ctrl;
1627 __u32 channel; 1630 __u32 channel, param, fw_ver;
1628 __u8 cmd; 1631 __u8 cmd;
1629 __u32 param;
1630 __u32 hw_ver, fw_ver;
1631 int special_count; 1632 int special_count;
1632 int delta_count; 1633 int delta_count;
1633 1634
@@ -1635,8 +1636,6 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
1635 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); 1636 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
1636 board_ctrl = &zfw_ctrl->board_ctrl; 1637 board_ctrl = &zfw_ctrl->board_ctrl;
1637 fw_ver = readl(&board_ctrl->fw_version); 1638 fw_ver = readl(&board_ctrl->fw_version);
1638 hw_ver = readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->
1639 mail_box_0);
1640 1639
1641 while (cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1) { 1640 while (cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1) {
1642 special_count = 0; 1641 special_count = 0;
@@ -1737,15 +1736,7 @@ static irqreturn_t cyz_interrupt(int irq, void *dev_id)
1737{ 1736{
1738 struct cyclades_card *cinfo = dev_id; 1737 struct cyclades_card *cinfo = dev_id;
1739 1738
1740 if (unlikely(cinfo == NULL)) { 1739 if (unlikely(!cyz_is_loaded(cinfo))) {
1741#ifdef CY_DEBUG_INTERRUPTS
1742 printk(KERN_DEBUG "cyz_interrupt: spurious interrupt %d\n",
1743 irq);
1744#endif
1745 return IRQ_NONE; /* spurious interrupt */
1746 }
1747
1748 if (unlikely(!ISZLOADED(*cinfo))) {
1749#ifdef CY_DEBUG_INTERRUPTS 1740#ifdef CY_DEBUG_INTERRUPTS
1750 printk(KERN_DEBUG "cyz_interrupt: board not yet loaded " 1741 printk(KERN_DEBUG "cyz_interrupt: board not yet loaded "
1751 "(IRQ%d).\n", irq); 1742 "(IRQ%d).\n", irq);
@@ -1785,7 +1776,6 @@ static void cyz_poll(unsigned long arg)
1785 struct tty_struct *tty; 1776 struct tty_struct *tty;
1786 struct FIRM_ID __iomem *firm_id; 1777 struct FIRM_ID __iomem *firm_id;
1787 struct ZFW_CTRL __iomem *zfw_ctrl; 1778 struct ZFW_CTRL __iomem *zfw_ctrl;
1788 struct BOARD_CTRL __iomem *board_ctrl;
1789 struct BUF_CTRL __iomem *buf_ctrl; 1779 struct BUF_CTRL __iomem *buf_ctrl;
1790 unsigned long expires = jiffies + HZ; 1780 unsigned long expires = jiffies + HZ;
1791 unsigned int port, card; 1781 unsigned int port, card;
@@ -1793,19 +1783,17 @@ static void cyz_poll(unsigned long arg)
1793 for (card = 0; card < NR_CARDS; card++) { 1783 for (card = 0; card < NR_CARDS; card++) {
1794 cinfo = &cy_card[card]; 1784 cinfo = &cy_card[card];
1795 1785
1796 if (!IS_CYC_Z(*cinfo)) 1786 if (!cy_is_Z(cinfo))
1797 continue; 1787 continue;
1798 if (!ISZLOADED(*cinfo)) 1788 if (!cyz_is_loaded(cinfo))
1799 continue; 1789 continue;
1800 1790
1801 firm_id = cinfo->base_addr + ID_ADDRESS; 1791 firm_id = cinfo->base_addr + ID_ADDRESS;
1802 zfw_ctrl = cinfo->base_addr + 1792 zfw_ctrl = cinfo->base_addr +
1803 (readl(&firm_id->zfwctrl_addr) & 0xfffff); 1793 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
1804 board_ctrl = &(zfw_ctrl->board_ctrl);
1805 1794
1806 /* Skip first polling cycle to avoid racing conditions with the FW */ 1795 /* Skip first polling cycle to avoid racing conditions with the FW */
1807 if (!cinfo->intr_enabled) { 1796 if (!cinfo->intr_enabled) {
1808 cinfo->nports = (int)readl(&board_ctrl->n_channel);
1809 cinfo->intr_enabled = 1; 1797 cinfo->intr_enabled = 1;
1810 continue; 1798 continue;
1811 } 1799 }
@@ -1874,7 +1862,7 @@ static int startup(struct cyclades_port *info)
1874 1862
1875 set_line_char(info); 1863 set_line_char(info);
1876 1864
1877 if (!IS_CYC_Z(*card)) { 1865 if (!cy_is_Z(card)) {
1878 chip = channel >> 2; 1866 chip = channel >> 2;
1879 channel &= 0x03; 1867 channel &= 0x03;
1880 index = card->bus_index; 1868 index = card->bus_index;
@@ -1931,7 +1919,7 @@ static int startup(struct cyclades_port *info)
1931 base_addr = card->base_addr; 1919 base_addr = card->base_addr;
1932 1920
1933 firm_id = base_addr + ID_ADDRESS; 1921 firm_id = base_addr + ID_ADDRESS;
1934 if (!ISZLOADED(*card)) 1922 if (!cyz_is_loaded(card))
1935 return -ENODEV; 1923 return -ENODEV;
1936 1924
1937 zfw_ctrl = card->base_addr + 1925 zfw_ctrl = card->base_addr +
@@ -2026,7 +2014,7 @@ static void start_xmit(struct cyclades_port *info)
2026 2014
2027 card = info->card; 2015 card = info->card;
2028 channel = info->line - card->first_line; 2016 channel = info->line - card->first_line;
2029 if (!IS_CYC_Z(*card)) { 2017 if (!cy_is_Z(card)) {
2030 chip = channel >> 2; 2018 chip = channel >> 2;
2031 channel &= 0x03; 2019 channel &= 0x03;
2032 index = card->bus_index; 2020 index = card->bus_index;
@@ -2070,7 +2058,7 @@ static void shutdown(struct cyclades_port *info)
2070 2058
2071 card = info->card; 2059 card = info->card;
2072 channel = info->line - card->first_line; 2060 channel = info->line - card->first_line;
2073 if (!IS_CYC_Z(*card)) { 2061 if (!cy_is_Z(card)) {
2074 chip = channel >> 2; 2062 chip = channel >> 2;
2075 channel &= 0x03; 2063 channel &= 0x03;
2076 index = card->bus_index; 2064 index = card->bus_index;
@@ -2126,7 +2114,7 @@ static void shutdown(struct cyclades_port *info)
2126#endif 2114#endif
2127 2115
2128 firm_id = base_addr + ID_ADDRESS; 2116 firm_id = base_addr + ID_ADDRESS;
2129 if (!ISZLOADED(*card)) 2117 if (!cyz_is_loaded(card))
2130 return; 2118 return;
2131 2119
2132 zfw_ctrl = card->base_addr + 2120 zfw_ctrl = card->base_addr +
@@ -2233,7 +2221,7 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2233#endif 2221#endif
2234 info->port.blocked_open++; 2222 info->port.blocked_open++;
2235 2223
2236 if (!IS_CYC_Z(*cinfo)) { 2224 if (!cy_is_Z(cinfo)) {
2237 chip = channel >> 2; 2225 chip = channel >> 2;
2238 channel &= 0x03; 2226 channel &= 0x03;
2239 index = cinfo->bus_index; 2227 index = cinfo->bus_index;
@@ -2296,7 +2284,7 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2296 2284
2297 base_addr = cinfo->base_addr; 2285 base_addr = cinfo->base_addr;
2298 firm_id = base_addr + ID_ADDRESS; 2286 firm_id = base_addr + ID_ADDRESS;
2299 if (!ISZLOADED(*cinfo)) { 2287 if (!cyz_is_loaded(cinfo)) {
2300 __set_current_state(TASK_RUNNING); 2288 __set_current_state(TASK_RUNNING);
2301 remove_wait_queue(&info->port.open_wait, &wait); 2289 remove_wait_queue(&info->port.open_wait, &wait);
2302 return -EINVAL; 2290 return -EINVAL;
@@ -2397,16 +2385,14 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2397 treat it as absent from the system. This 2385 treat it as absent from the system. This
2398 will make the user pay attention. 2386 will make the user pay attention.
2399 */ 2387 */
2400 if (IS_CYC_Z(*info->card)) { 2388 if (cy_is_Z(info->card)) {
2401 struct cyclades_card *cinfo = info->card; 2389 struct cyclades_card *cinfo = info->card;
2402 struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS; 2390 struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS;
2403 2391
2404 if (!ISZLOADED(*cinfo)) { 2392 if (!cyz_is_loaded(cinfo)) {
2405 if (((ZE_V1 == readl(&((struct RUNTIME_9060 __iomem *) 2393 if (cinfo->hw_ver == ZE_V1 && cyz_fpga_loaded(cinfo) &&
2406 (cinfo->ctl_addr))->mail_box_0)) && 2394 readl(&firm_id->signature) ==
2407 Z_FPGA_CHECK(*cinfo)) && 2395 ZFIRM_HLT) {
2408 (ZFIRM_HLT == readl(
2409 &firm_id->signature))) {
2410 printk(KERN_ERR "cyc:Cyclades-Z Error: you " 2396 printk(KERN_ERR "cyc:Cyclades-Z Error: you "
2411 "need an external power supply for " 2397 "need an external power supply for "
2412 "this number of ports.\nFirmware " 2398 "this number of ports.\nFirmware "
@@ -2423,18 +2409,13 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2423 interrupts should be enabled as soon as the first open 2409 interrupts should be enabled as soon as the first open
2424 happens to one of its ports. */ 2410 happens to one of its ports. */
2425 if (!cinfo->intr_enabled) { 2411 if (!cinfo->intr_enabled) {
2426 struct ZFW_CTRL __iomem *zfw_ctrl; 2412 u16 intr;
2427 struct BOARD_CTRL __iomem *board_ctrl;
2428
2429 zfw_ctrl = cinfo->base_addr +
2430 (readl(&firm_id->zfwctrl_addr) &
2431 0xfffff);
2432
2433 board_ctrl = &zfw_ctrl->board_ctrl;
2434 2413
2435 /* Enable interrupts on the PLX chip */ 2414 /* Enable interrupts on the PLX chip */
2436 cy_writew(cinfo->ctl_addr + 0x68, 2415 intr = readw(&cinfo->ctl_addr.p9060->
2437 readw(cinfo->ctl_addr + 0x68) | 0x0900); 2416 intr_ctrl_stat) | 0x0900;
2417 cy_writew(&cinfo->ctl_addr.p9060->
2418 intr_ctrl_stat, intr);
2438 /* Enable interrupts on the FW */ 2419 /* Enable interrupts on the FW */
2439 retval = cyz_issue_cmd(cinfo, 0, 2420 retval = cyz_issue_cmd(cinfo, 0,
2440 C_CM_IRQ_ENBL, 0L); 2421 C_CM_IRQ_ENBL, 0L);
@@ -2442,8 +2423,6 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2442 printk(KERN_ERR "cyc:IRQ enable retval " 2423 printk(KERN_ERR "cyc:IRQ enable retval "
2443 "was %x\n", retval); 2424 "was %x\n", retval);
2444 } 2425 }
2445 cinfo->nports =
2446 (int)readl(&board_ctrl->n_channel);
2447 cinfo->intr_enabled = 1; 2426 cinfo->intr_enabled = 1;
2448 } 2427 }
2449 } 2428 }
@@ -2556,7 +2535,7 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
2556#endif 2535#endif
2557 card = info->card; 2536 card = info->card;
2558 channel = (info->line) - (card->first_line); 2537 channel = (info->line) - (card->first_line);
2559 if (!IS_CYC_Z(*card)) { 2538 if (!cy_is_Z(card)) {
2560 chip = channel >> 2; 2539 chip = channel >> 2;
2561 channel &= 0x03; 2540 channel &= 0x03;
2562 index = card->bus_index; 2541 index = card->bus_index;
@@ -2601,7 +2580,7 @@ static void cy_flush_buffer(struct tty_struct *tty)
2601 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 2580 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2602 spin_unlock_irqrestore(&card->card_lock, flags); 2581 spin_unlock_irqrestore(&card->card_lock, flags);
2603 2582
2604 if (IS_CYC_Z(*card)) { /* If it is a Z card, flush the on-board 2583 if (cy_is_Z(card)) { /* If it is a Z card, flush the on-board
2605 buffers as well */ 2584 buffers as well */
2606 spin_lock_irqsave(&card->card_lock, flags); 2585 spin_lock_irqsave(&card->card_lock, flags);
2607 retval = cyz_issue_cmd(card, channel, C_CM_FLUSH_TX, 0L); 2586 retval = cyz_issue_cmd(card, channel, C_CM_FLUSH_TX, 0L);
@@ -2682,7 +2661,7 @@ static void cy_close(struct tty_struct *tty, struct file *filp)
2682 2661
2683 spin_lock_irqsave(&card->card_lock, flags); 2662 spin_lock_irqsave(&card->card_lock, flags);
2684 2663
2685 if (!IS_CYC_Z(*card)) { 2664 if (!cy_is_Z(card)) {
2686 int channel = info->line - card->first_line; 2665 int channel = info->line - card->first_line;
2687 int index = card->bus_index; 2666 int index = card->bus_index;
2688 void __iomem *base_addr = card->base_addr + 2667 void __iomem *base_addr = card->base_addr +
@@ -2902,7 +2881,7 @@ static int cy_chars_in_buffer(struct tty_struct *tty)
2902 channel = (info->line) - (card->first_line); 2881 channel = (info->line) - (card->first_line);
2903 2882
2904#ifdef Z_EXT_CHARS_IN_BUFFER 2883#ifdef Z_EXT_CHARS_IN_BUFFER
2905 if (!IS_CYC_Z(cy_card[card])) { 2884 if (!cy_is_Z(card)) {
2906#endif /* Z_EXT_CHARS_IN_BUFFER */ 2885#endif /* Z_EXT_CHARS_IN_BUFFER */
2907#ifdef CY_DEBUG_IO 2886#ifdef CY_DEBUG_IO
2908 printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n", 2887 printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n",
@@ -2984,7 +2963,6 @@ static void set_line_char(struct cyclades_port *info)
2984 void __iomem *base_addr; 2963 void __iomem *base_addr;
2985 int chip, channel, index; 2964 int chip, channel, index;
2986 unsigned cflag, iflag; 2965 unsigned cflag, iflag;
2987 unsigned short chip_number;
2988 int baud, baud_rate = 0; 2966 int baud, baud_rate = 0;
2989 int i; 2967 int i;
2990 2968
@@ -3013,9 +2991,8 @@ static void set_line_char(struct cyclades_port *info)
3013 2991
3014 card = info->card; 2992 card = info->card;
3015 channel = info->line - card->first_line; 2993 channel = info->line - card->first_line;
3016 chip_number = channel / 4;
3017 2994
3018 if (!IS_CYC_Z(*card)) { 2995 if (!cy_is_Z(card)) {
3019 2996
3020 index = card->bus_index; 2997 index = card->bus_index;
3021 2998
@@ -3233,21 +3210,17 @@ static void set_line_char(struct cyclades_port *info)
3233 } else { 3210 } else {
3234 struct FIRM_ID __iomem *firm_id; 3211 struct FIRM_ID __iomem *firm_id;
3235 struct ZFW_CTRL __iomem *zfw_ctrl; 3212 struct ZFW_CTRL __iomem *zfw_ctrl;
3236 struct BOARD_CTRL __iomem *board_ctrl;
3237 struct CH_CTRL __iomem *ch_ctrl; 3213 struct CH_CTRL __iomem *ch_ctrl;
3238 struct BUF_CTRL __iomem *buf_ctrl;
3239 __u32 sw_flow; 3214 __u32 sw_flow;
3240 int retval; 3215 int retval;
3241 3216
3242 firm_id = card->base_addr + ID_ADDRESS; 3217 firm_id = card->base_addr + ID_ADDRESS;
3243 if (!ISZLOADED(*card)) 3218 if (!cyz_is_loaded(card))
3244 return; 3219 return;
3245 3220
3246 zfw_ctrl = card->base_addr + 3221 zfw_ctrl = card->base_addr +
3247 (readl(&firm_id->zfwctrl_addr) & 0xfffff); 3222 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
3248 board_ctrl = &zfw_ctrl->board_ctrl;
3249 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]); 3223 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
3250 buf_ctrl = &zfw_ctrl->buf_ctrl[channel];
3251 3224
3252 /* baud rate */ 3225 /* baud rate */
3253 baud = tty_get_baud_rate(info->port.tty); 3226 baud = tty_get_baud_rate(info->port.tty);
@@ -3457,7 +3430,7 @@ static int get_lsr_info(struct cyclades_port *info, unsigned int __user *value)
3457 3430
3458 card = info->card; 3431 card = info->card;
3459 channel = (info->line) - (card->first_line); 3432 channel = (info->line) - (card->first_line);
3460 if (!IS_CYC_Z(*card)) { 3433 if (!cy_is_Z(card)) {
3461 chip = channel >> 2; 3434 chip = channel >> 2;
3462 channel &= 0x03; 3435 channel &= 0x03;
3463 index = card->bus_index; 3436 index = card->bus_index;
@@ -3497,7 +3470,7 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file)
3497 3470
3498 card = info->card; 3471 card = info->card;
3499 channel = info->line - card->first_line; 3472 channel = info->line - card->first_line;
3500 if (!IS_CYC_Z(*card)) { 3473 if (!cy_is_Z(card)) {
3501 chip = channel >> 2; 3474 chip = channel >> 2;
3502 channel &= 0x03; 3475 channel &= 0x03;
3503 index = card->bus_index; 3476 index = card->bus_index;
@@ -3523,7 +3496,7 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file)
3523 } else { 3496 } else {
3524 base_addr = card->base_addr; 3497 base_addr = card->base_addr;
3525 firm_id = card->base_addr + ID_ADDRESS; 3498 firm_id = card->base_addr + ID_ADDRESS;
3526 if (ISZLOADED(*card)) { 3499 if (cyz_is_loaded(card)) {
3527 zfw_ctrl = card->base_addr + 3500 zfw_ctrl = card->base_addr +
3528 (readl(&firm_id->zfwctrl_addr) & 0xfffff); 3501 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
3529 board_ctrl = &zfw_ctrl->board_ctrl; 3502 board_ctrl = &zfw_ctrl->board_ctrl;
@@ -3566,7 +3539,7 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
3566 3539
3567 card = info->card; 3540 card = info->card;
3568 channel = (info->line) - (card->first_line); 3541 channel = (info->line) - (card->first_line);
3569 if (!IS_CYC_Z(*card)) { 3542 if (!cy_is_Z(card)) {
3570 chip = channel >> 2; 3543 chip = channel >> 2;
3571 channel &= 0x03; 3544 channel &= 0x03;
3572 index = card->bus_index; 3545 index = card->bus_index;
@@ -3641,7 +3614,7 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
3641 base_addr = card->base_addr; 3614 base_addr = card->base_addr;
3642 3615
3643 firm_id = card->base_addr + ID_ADDRESS; 3616 firm_id = card->base_addr + ID_ADDRESS;
3644 if (ISZLOADED(*card)) { 3617 if (cyz_is_loaded(card)) {
3645 zfw_ctrl = card->base_addr + 3618 zfw_ctrl = card->base_addr +
3646 (readl(&firm_id->zfwctrl_addr) & 0xfffff); 3619 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
3647 board_ctrl = &zfw_ctrl->board_ctrl; 3620 board_ctrl = &zfw_ctrl->board_ctrl;
@@ -3713,7 +3686,7 @@ static int cy_break(struct tty_struct *tty, int break_state)
3713 card = info->card; 3686 card = info->card;
3714 3687
3715 spin_lock_irqsave(&card->card_lock, flags); 3688 spin_lock_irqsave(&card->card_lock, flags);
3716 if (!IS_CYC_Z(*card)) { 3689 if (!cy_is_Z(card)) {
3717 /* Let the transmit ISR take care of this (since it 3690 /* Let the transmit ISR take care of this (since it
3718 requires stuffing characters into the output stream). 3691 requires stuffing characters into the output stream).
3719 */ 3692 */
@@ -3782,7 +3755,7 @@ static int set_threshold(struct cyclades_port *info, unsigned long value)
3782 3755
3783 card = info->card; 3756 card = info->card;
3784 channel = info->line - card->first_line; 3757 channel = info->line - card->first_line;
3785 if (!IS_CYC_Z(*card)) { 3758 if (!cy_is_Z(card)) {
3786 chip = channel >> 2; 3759 chip = channel >> 2;
3787 channel &= 0x03; 3760 channel &= 0x03;
3788 index = card->bus_index; 3761 index = card->bus_index;
@@ -3810,7 +3783,7 @@ static int get_threshold(struct cyclades_port *info,
3810 3783
3811 card = info->card; 3784 card = info->card;
3812 channel = info->line - card->first_line; 3785 channel = info->line - card->first_line;
3813 if (!IS_CYC_Z(*card)) { 3786 if (!cy_is_Z(card)) {
3814 chip = channel >> 2; 3787 chip = channel >> 2;
3815 channel &= 0x03; 3788 channel &= 0x03;
3816 index = card->bus_index; 3789 index = card->bus_index;
@@ -3844,7 +3817,7 @@ static int set_timeout(struct cyclades_port *info, unsigned long value)
3844 3817
3845 card = info->card; 3818 card = info->card;
3846 channel = info->line - card->first_line; 3819 channel = info->line - card->first_line;
3847 if (!IS_CYC_Z(*card)) { 3820 if (!cy_is_Z(card)) {
3848 chip = channel >> 2; 3821 chip = channel >> 2;
3849 channel &= 0x03; 3822 channel &= 0x03;
3850 index = card->bus_index; 3823 index = card->bus_index;
@@ -3867,7 +3840,7 @@ static int get_timeout(struct cyclades_port *info,
3867 3840
3868 card = info->card; 3841 card = info->card;
3869 channel = info->line - card->first_line; 3842 channel = info->line - card->first_line;
3870 if (!IS_CYC_Z(*card)) { 3843 if (!cy_is_Z(card)) {
3871 chip = channel >> 2; 3844 chip = channel >> 2;
3872 channel &= 0x03; 3845 channel &= 0x03;
3873 index = card->bus_index; 3846 index = card->bus_index;
@@ -4121,7 +4094,7 @@ static void cy_send_xchar(struct tty_struct *tty, char ch)
4121 card = info->card; 4094 card = info->card;
4122 channel = info->line - card->first_line; 4095 channel = info->line - card->first_line;
4123 4096
4124 if (IS_CYC_Z(*card)) { 4097 if (cy_is_Z(card)) {
4125 if (ch == STOP_CHAR(tty)) 4098 if (ch == STOP_CHAR(tty))
4126 cyz_issue_cmd(card, channel, C_CM_SENDXOFF, 0L); 4099 cyz_issue_cmd(card, channel, C_CM_SENDXOFF, 0L);
4127 else if (ch == START_CHAR(tty)) 4100 else if (ch == START_CHAR(tty))
@@ -4154,7 +4127,7 @@ static void cy_throttle(struct tty_struct *tty)
4154 card = info->card; 4127 card = info->card;
4155 4128
4156 if (I_IXOFF(tty)) { 4129 if (I_IXOFF(tty)) {
4157 if (!IS_CYC_Z(*card)) 4130 if (!cy_is_Z(card))
4158 cy_send_xchar(tty, STOP_CHAR(tty)); 4131 cy_send_xchar(tty, STOP_CHAR(tty));
4159 else 4132 else
4160 info->throttle = 1; 4133 info->throttle = 1;
@@ -4162,7 +4135,7 @@ static void cy_throttle(struct tty_struct *tty)
4162 4135
4163 if (tty->termios->c_cflag & CRTSCTS) { 4136 if (tty->termios->c_cflag & CRTSCTS) {
4164 channel = info->line - card->first_line; 4137 channel = info->line - card->first_line;
4165 if (!IS_CYC_Z(*card)) { 4138 if (!cy_is_Z(card)) {
4166 chip = channel >> 2; 4139 chip = channel >> 2;
4167 channel &= 0x03; 4140 channel &= 0x03;
4168 index = card->bus_index; 4141 index = card->bus_index;
@@ -4219,7 +4192,7 @@ static void cy_unthrottle(struct tty_struct *tty)
4219 if (tty->termios->c_cflag & CRTSCTS) { 4192 if (tty->termios->c_cflag & CRTSCTS) {
4220 card = info->card; 4193 card = info->card;
4221 channel = info->line - card->first_line; 4194 channel = info->line - card->first_line;
4222 if (!IS_CYC_Z(*card)) { 4195 if (!cy_is_Z(card)) {
4223 chip = channel >> 2; 4196 chip = channel >> 2;
4224 channel &= 0x03; 4197 channel &= 0x03;
4225 index = card->bus_index; 4198 index = card->bus_index;
@@ -4263,7 +4236,7 @@ static void cy_stop(struct tty_struct *tty)
4263 4236
4264 cinfo = info->card; 4237 cinfo = info->card;
4265 channel = info->line - cinfo->first_line; 4238 channel = info->line - cinfo->first_line;
4266 if (!IS_CYC_Z(*cinfo)) { 4239 if (!cy_is_Z(cinfo)) {
4267 index = cinfo->bus_index; 4240 index = cinfo->bus_index;
4268 chip = channel >> 2; 4241 chip = channel >> 2;
4269 channel &= 0x03; 4242 channel &= 0x03;
@@ -4296,7 +4269,7 @@ static void cy_start(struct tty_struct *tty)
4296 cinfo = info->card; 4269 cinfo = info->card;
4297 channel = info->line - cinfo->first_line; 4270 channel = info->line - cinfo->first_line;
4298 index = cinfo->bus_index; 4271 index = cinfo->bus_index;
4299 if (!IS_CYC_Z(*cinfo)) { 4272 if (!cy_is_Z(cinfo)) {
4300 chip = channel >> 2; 4273 chip = channel >> 2;
4301 channel &= 0x03; 4274 channel &= 0x03;
4302 base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index); 4275 base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index);
@@ -4347,33 +4320,20 @@ static void cy_hangup(struct tty_struct *tty)
4347static int __devinit cy_init_card(struct cyclades_card *cinfo) 4320static int __devinit cy_init_card(struct cyclades_card *cinfo)
4348{ 4321{
4349 struct cyclades_port *info; 4322 struct cyclades_port *info;
4350 u32 uninitialized_var(mailbox); 4323 unsigned int port;
4351 unsigned int nports, port;
4352 unsigned short chip_number; 4324 unsigned short chip_number;
4353 int uninitialized_var(index);
4354 4325
4355 spin_lock_init(&cinfo->card_lock); 4326 spin_lock_init(&cinfo->card_lock);
4327 cinfo->intr_enabled = 0;
4356 4328
4357 if (IS_CYC_Z(*cinfo)) { /* Cyclades-Z */ 4329 cinfo->ports = kcalloc(cinfo->nports, sizeof(*cinfo->ports),
4358 mailbox = readl(&((struct RUNTIME_9060 __iomem *) 4330 GFP_KERNEL);
4359 cinfo->ctl_addr)->mail_box_0);
4360 nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8;
4361 cinfo->intr_enabled = 0;
4362 cinfo->nports = 0; /* Will be correctly set later, after
4363 Z FW is loaded */
4364 } else {
4365 index = cinfo->bus_index;
4366 nports = cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips;
4367 }
4368
4369 cinfo->ports = kzalloc(sizeof(*cinfo->ports) * nports, GFP_KERNEL);
4370 if (cinfo->ports == NULL) { 4331 if (cinfo->ports == NULL) {
4371 printk(KERN_ERR "Cyclades: cannot allocate ports\n"); 4332 printk(KERN_ERR "Cyclades: cannot allocate ports\n");
4372 cinfo->nports = 0;
4373 return -ENOMEM; 4333 return -ENOMEM;
4374 } 4334 }
4375 4335
4376 for (port = cinfo->first_line; port < cinfo->first_line + nports; 4336 for (port = cinfo->first_line; port < cinfo->first_line + cinfo->nports;
4377 port++) { 4337 port++) {
4378 info = &cinfo->ports[port - cinfo->first_line]; 4338 info = &cinfo->ports[port - cinfo->first_line];
4379 tty_port_init(&info->port); 4339 tty_port_init(&info->port);
@@ -4387,9 +4347,9 @@ static int __devinit cy_init_card(struct cyclades_card *cinfo)
4387 init_completion(&info->shutdown_wait); 4347 init_completion(&info->shutdown_wait);
4388 init_waitqueue_head(&info->delta_msr_wait); 4348 init_waitqueue_head(&info->delta_msr_wait);
4389 4349
4390 if (IS_CYC_Z(*cinfo)) { 4350 if (cy_is_Z(cinfo)) {
4391 info->type = PORT_STARTECH; 4351 info->type = PORT_STARTECH;
4392 if (mailbox == ZO_V1) 4352 if (cinfo->hw_ver == ZO_V1)
4393 info->xmit_fifo_size = CYZ_FIFO_SIZE; 4353 info->xmit_fifo_size = CYZ_FIFO_SIZE;
4394 else 4354 else
4395 info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE; 4355 info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE;
@@ -4398,6 +4358,7 @@ static int __devinit cy_init_card(struct cyclades_card *cinfo)
4398 cyz_rx_restart, (unsigned long)info); 4358 cyz_rx_restart, (unsigned long)info);
4399#endif 4359#endif
4400 } else { 4360 } else {
4361 int index = cinfo->bus_index;
4401 info->type = PORT_CIRRUS; 4362 info->type = PORT_CIRRUS;
4402 info->xmit_fifo_size = CyMAX_CHAR_FIFO; 4363 info->xmit_fifo_size = CyMAX_CHAR_FIFO;
4403 info->cor1 = CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS; 4364 info->cor1 = CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS;
@@ -4430,7 +4391,7 @@ static int __devinit cy_init_card(struct cyclades_card *cinfo)
4430 } 4391 }
4431 4392
4432#ifndef CONFIG_CYZ_INTR 4393#ifndef CONFIG_CYZ_INTR
4433 if (IS_CYC_Z(*cinfo) && !timer_pending(&cyz_timerlist)) { 4394 if (cy_is_Z(cinfo) && !timer_pending(&cyz_timerlist)) {
4434 mod_timer(&cyz_timerlist, jiffies + 1); 4395 mod_timer(&cyz_timerlist, jiffies + 1);
4435#ifdef CY_PCI_DEBUG 4396#ifdef CY_PCI_DEBUG
4436 printk(KERN_DEBUG "Cyclades-Z polling initialized\n"); 4397 printk(KERN_DEBUG "Cyclades-Z polling initialized\n");
@@ -4621,11 +4582,12 @@ static int __init cy_detect_isa(void)
4621 4582
4622 /* set cy_card */ 4583 /* set cy_card */
4623 cy_card[j].base_addr = cy_isa_address; 4584 cy_card[j].base_addr = cy_isa_address;
4624 cy_card[j].ctl_addr = NULL; 4585 cy_card[j].ctl_addr.p9050 = NULL;
4625 cy_card[j].irq = (int)cy_isa_irq; 4586 cy_card[j].irq = (int)cy_isa_irq;
4626 cy_card[j].bus_index = 0; 4587 cy_card[j].bus_index = 0;
4627 cy_card[j].first_line = cy_next_channel; 4588 cy_card[j].first_line = cy_next_channel;
4628 cy_card[j].num_chips = cy_isa_nchan / 4; 4589 cy_card[j].num_chips = cy_isa_nchan / CyPORTS_PER_CHIP;
4590 cy_card[j].nports = cy_isa_nchan;
4629 if (cy_init_card(&cy_card[j])) { 4591 if (cy_init_card(&cy_card[j])) {
4630 cy_card[j].base_addr = NULL; 4592 cy_card[j].base_addr = NULL;
4631 free_irq(cy_isa_irq, &cy_card[j]); 4593 free_irq(cy_isa_irq, &cy_card[j]);
@@ -4781,7 +4743,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4781 struct CUSTOM_REG __iomem *cust = base_addr; 4743 struct CUSTOM_REG __iomem *cust = base_addr;
4782 struct ZFW_CTRL __iomem *pt_zfwctrl; 4744 struct ZFW_CTRL __iomem *pt_zfwctrl;
4783 void __iomem *tmp; 4745 void __iomem *tmp;
4784 u32 mailbox, status; 4746 u32 mailbox, status, nchan;
4785 unsigned int i; 4747 unsigned int i;
4786 int retval; 4748 int retval;
4787 4749
@@ -4793,7 +4755,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4793 4755
4794 /* Check whether the firmware is already loaded and running. If 4756 /* Check whether the firmware is already loaded and running. If
4795 positive, skip this board */ 4757 positive, skip this board */
4796 if (Z_FPGA_LOADED(ctl_addr) && readl(&fid->signature) == ZFIRM_ID) { 4758 if (__cyz_fpga_loaded(ctl_addr) && readl(&fid->signature) == ZFIRM_ID) {
4797 u32 cntval = readl(base_addr + 0x190); 4759 u32 cntval = readl(base_addr + 0x190);
4798 4760
4799 udelay(100); 4761 udelay(100);
@@ -4812,7 +4774,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4812 4774
4813 mailbox = readl(&ctl_addr->mail_box_0); 4775 mailbox = readl(&ctl_addr->mail_box_0);
4814 4776
4815 if (mailbox == 0 || Z_FPGA_LOADED(ctl_addr)) { 4777 if (mailbox == 0 || __cyz_fpga_loaded(ctl_addr)) {
4816 /* stops CPU and set window to beginning of RAM */ 4778 /* stops CPU and set window to beginning of RAM */
4817 cy_writel(&ctl_addr->loc_addr_base, WIN_CREG); 4779 cy_writel(&ctl_addr->loc_addr_base, WIN_CREG);
4818 cy_writel(&cust->cpu_stop, 0); 4780 cy_writel(&cust->cpu_stop, 0);
@@ -4828,7 +4790,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4828 base_addr); 4790 base_addr);
4829 if (retval) 4791 if (retval)
4830 goto err_rel; 4792 goto err_rel;
4831 if (!Z_FPGA_LOADED(ctl_addr)) { 4793 if (!__cyz_fpga_loaded(ctl_addr)) {
4832 dev_err(&pdev->dev, "fw upload successful, but fw is " 4794 dev_err(&pdev->dev, "fw upload successful, but fw is "
4833 "not loaded\n"); 4795 "not loaded\n");
4834 goto err_rel; 4796 goto err_rel;
@@ -4887,7 +4849,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4887 "system before loading the new FW to the " 4849 "system before loading the new FW to the "
4888 "Cyclades-Z.\n"); 4850 "Cyclades-Z.\n");
4889 4851
4890 if (Z_FPGA_LOADED(ctl_addr)) 4852 if (__cyz_fpga_loaded(ctl_addr))
4891 plx_init(pdev, irq, ctl_addr); 4853 plx_init(pdev, irq, ctl_addr);
4892 4854
4893 retval = -EIO; 4855 retval = -EIO;
@@ -4902,16 +4864,16 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4902 base_addr + ID_ADDRESS, readl(&fid->zfwctrl_addr), 4864 base_addr + ID_ADDRESS, readl(&fid->zfwctrl_addr),
4903 base_addr + readl(&fid->zfwctrl_addr)); 4865 base_addr + readl(&fid->zfwctrl_addr));
4904 4866
4867 nchan = readl(&pt_zfwctrl->board_ctrl.n_channel);
4905 dev_info(&pdev->dev, "Cyclades-Z FW loaded: version = %x, ports = %u\n", 4868 dev_info(&pdev->dev, "Cyclades-Z FW loaded: version = %x, ports = %u\n",
4906 readl(&pt_zfwctrl->board_ctrl.fw_version), 4869 readl(&pt_zfwctrl->board_ctrl.fw_version), nchan);
4907 readl(&pt_zfwctrl->board_ctrl.n_channel));
4908 4870
4909 if (readl(&pt_zfwctrl->board_ctrl.n_channel) == 0) { 4871 if (nchan == 0) {
4910 dev_warn(&pdev->dev, "no Cyclades-Z ports were found. Please " 4872 dev_warn(&pdev->dev, "no Cyclades-Z ports were found. Please "
4911 "check the connection between the Z host card and the " 4873 "check the connection between the Z host card and the "
4912 "serial expanders.\n"); 4874 "serial expanders.\n");
4913 4875
4914 if (Z_FPGA_LOADED(ctl_addr)) 4876 if (__cyz_fpga_loaded(ctl_addr))
4915 plx_init(pdev, irq, ctl_addr); 4877 plx_init(pdev, irq, ctl_addr);
4916 4878
4917 dev_info(&pdev->dev, "Null number of ports detected. Board " 4879 dev_info(&pdev->dev, "Null number of ports detected. Board "
@@ -4932,9 +4894,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4932 cy_writel(&ctl_addr->intr_ctrl_stat, readl(&ctl_addr->intr_ctrl_stat) | 4894 cy_writel(&ctl_addr->intr_ctrl_stat, readl(&ctl_addr->intr_ctrl_stat) |
4933 0x00030800UL); 4895 0x00030800UL);
4934 4896
4935 plx_init(pdev, irq, ctl_addr); 4897 return nchan;
4936
4937 return 0;
4938err_rel: 4898err_rel:
4939 release_firmware(fw); 4899 release_firmware(fw);
4940err: 4900err:
@@ -4946,7 +4906,7 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
4946{ 4906{
4947 void __iomem *addr0 = NULL, *addr2 = NULL; 4907 void __iomem *addr0 = NULL, *addr2 = NULL;
4948 char *card_name = NULL; 4908 char *card_name = NULL;
4949 u32 mailbox; 4909 u32 uninitialized_var(mailbox);
4950 unsigned int device_id, nchan = 0, card_no, i; 4910 unsigned int device_id, nchan = 0, card_no, i;
4951 unsigned char plx_ver; 4911 unsigned char plx_ver;
4952 int retval, irq; 4912 int retval, irq;
@@ -5023,11 +4983,12 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5023 } 4983 }
5024 4984
5025 /* Disable interrupts on the PLX before resetting it */ 4985 /* Disable interrupts on the PLX before resetting it */
5026 cy_writew(addr0 + 0x68, readw(addr0 + 0x68) & ~0x0900); 4986 cy_writew(&ctl_addr->intr_ctrl_stat,
4987 readw(&ctl_addr->intr_ctrl_stat) & ~0x0900);
5027 4988
5028 plx_init(pdev, irq, addr0); 4989 plx_init(pdev, irq, addr0);
5029 4990
5030 mailbox = (u32)readl(&ctl_addr->mail_box_0); 4991 mailbox = readl(&ctl_addr->mail_box_0);
5031 4992
5032 addr2 = ioremap_nocache(pci_resource_start(pdev, 2), 4993 addr2 = ioremap_nocache(pci_resource_start(pdev, 2),
5033 mailbox == ZE_V1 ? CyPCI_Ze_win : CyPCI_Zwin); 4994 mailbox == ZE_V1 ? CyPCI_Ze_win : CyPCI_Zwin);
@@ -5038,12 +4999,8 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5038 4999
5039 if (mailbox == ZE_V1) { 5000 if (mailbox == ZE_V1) {
5040 card_name = "Cyclades-Ze"; 5001 card_name = "Cyclades-Ze";
5041
5042 readl(&ctl_addr->mail_box_0);
5043 nchan = ZE_V1_NPORTS;
5044 } else { 5002 } else {
5045 card_name = "Cyclades-8Zo"; 5003 card_name = "Cyclades-8Zo";
5046
5047#ifdef CY_PCI_DEBUG 5004#ifdef CY_PCI_DEBUG
5048 if (mailbox == ZO_V1) { 5005 if (mailbox == ZO_V1) {
5049 cy_writel(&ctl_addr->loc_addr_base, WIN_CREG); 5006 cy_writel(&ctl_addr->loc_addr_base, WIN_CREG);
@@ -5065,15 +5022,12 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5065 */ 5022 */
5066 if ((mailbox == ZO_V1) || (mailbox == ZO_V2)) 5023 if ((mailbox == ZO_V1) || (mailbox == ZO_V2))
5067 cy_writel(addr2 + ID_ADDRESS, 0L); 5024 cy_writel(addr2 + ID_ADDRESS, 0L);
5068
5069 retval = cyz_load_fw(pdev, addr2, addr0, irq);
5070 if (retval)
5071 goto err_unmap;
5072 /* This must be a Cyclades-8Zo/PCI. The extendable
5073 version will have a different device_id and will
5074 be allocated its maximum number of ports. */
5075 nchan = 8;
5076 } 5025 }
5026
5027 retval = cyz_load_fw(pdev, addr2, addr0, irq);
5028 if (retval <= 0)
5029 goto err_unmap;
5030 nchan = retval;
5077 } 5031 }
5078 5032
5079 if ((cy_next_channel + nchan) > NR_PORTS) { 5033 if ((cy_next_channel + nchan) > NR_PORTS) {
@@ -5103,8 +5057,10 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5103 dev_err(&pdev->dev, "could not allocate IRQ\n"); 5057 dev_err(&pdev->dev, "could not allocate IRQ\n");
5104 goto err_unmap; 5058 goto err_unmap;
5105 } 5059 }
5106 cy_card[card_no].num_chips = nchan / 4; 5060 cy_card[card_no].num_chips = nchan / CyPORTS_PER_CHIP;
5107 } else { 5061 } else {
5062 cy_card[card_no].hw_ver = mailbox;
5063 cy_card[card_no].num_chips = (unsigned int)-1;
5108#ifdef CONFIG_CYZ_INTR 5064#ifdef CONFIG_CYZ_INTR
5109 /* allocate IRQ only if board has an IRQ */ 5065 /* allocate IRQ only if board has an IRQ */
5110 if (irq != 0 && irq != 255) { 5066 if (irq != 0 && irq != 255) {
@@ -5117,15 +5073,15 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5117 } 5073 }
5118 } 5074 }
5119#endif /* CONFIG_CYZ_INTR */ 5075#endif /* CONFIG_CYZ_INTR */
5120 cy_card[card_no].num_chips = (unsigned int)-1;
5121 } 5076 }
5122 5077
5123 /* set cy_card */ 5078 /* set cy_card */
5124 cy_card[card_no].base_addr = addr2; 5079 cy_card[card_no].base_addr = addr2;
5125 cy_card[card_no].ctl_addr = addr0; 5080 cy_card[card_no].ctl_addr.p9050 = addr0;
5126 cy_card[card_no].irq = irq; 5081 cy_card[card_no].irq = irq;
5127 cy_card[card_no].bus_index = 1; 5082 cy_card[card_no].bus_index = 1;
5128 cy_card[card_no].first_line = cy_next_channel; 5083 cy_card[card_no].first_line = cy_next_channel;
5084 cy_card[card_no].nports = nchan;
5129 retval = cy_init_card(&cy_card[card_no]); 5085 retval = cy_init_card(&cy_card[card_no]);
5130 if (retval) 5086 if (retval)
5131 goto err_null; 5087 goto err_null;
@@ -5138,17 +5094,20 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5138 plx_ver = readb(addr2 + CyPLX_VER) & 0x0f; 5094 plx_ver = readb(addr2 + CyPLX_VER) & 0x0f;
5139 switch (plx_ver) { 5095 switch (plx_ver) {
5140 case PLX_9050: 5096 case PLX_9050:
5141
5142 cy_writeb(addr0 + 0x4c, 0x43); 5097 cy_writeb(addr0 + 0x4c, 0x43);
5143 break; 5098 break;
5144 5099
5145 case PLX_9060: 5100 case PLX_9060:
5146 case PLX_9080: 5101 case PLX_9080:
5147 default: /* Old boards, use PLX_9060 */ 5102 default: /* Old boards, use PLX_9060 */
5148 plx_init(pdev, irq, addr0); 5103 {
5149 cy_writew(addr0 + 0x68, readw(addr0 + 0x68) | 0x0900); 5104 struct RUNTIME_9060 __iomem *ctl_addr = addr0;
5105 plx_init(pdev, irq, ctl_addr);
5106 cy_writew(&ctl_addr->intr_ctrl_stat,
5107 readw(&ctl_addr->intr_ctrl_stat) | 0x0900);
5150 break; 5108 break;
5151 } 5109 }
5110 }
5152 } 5111 }
5153 5112
5154 dev_info(&pdev->dev, "%s/PCI #%d found: %d channels starting from " 5113 dev_info(&pdev->dev, "%s/PCI #%d found: %d channels starting from "
@@ -5179,22 +5138,23 @@ static void __devexit cy_pci_remove(struct pci_dev *pdev)
5179 unsigned int i; 5138 unsigned int i;
5180 5139
5181 /* non-Z with old PLX */ 5140 /* non-Z with old PLX */
5182 if (!IS_CYC_Z(*cinfo) && (readb(cinfo->base_addr + CyPLX_VER) & 0x0f) == 5141 if (!cy_is_Z(cinfo) && (readb(cinfo->base_addr + CyPLX_VER) & 0x0f) ==
5183 PLX_9050) 5142 PLX_9050)
5184 cy_writeb(cinfo->ctl_addr + 0x4c, 0); 5143 cy_writeb(cinfo->ctl_addr.p9050 + 0x4c, 0);
5185 else 5144 else
5186#ifndef CONFIG_CYZ_INTR 5145#ifndef CONFIG_CYZ_INTR
5187 if (!IS_CYC_Z(*cinfo)) 5146 if (!cy_is_Z(cinfo))
5188#endif 5147#endif
5189 cy_writew(cinfo->ctl_addr + 0x68, 5148 cy_writew(&cinfo->ctl_addr.p9060->intr_ctrl_stat,
5190 readw(cinfo->ctl_addr + 0x68) & ~0x0900); 5149 readw(&cinfo->ctl_addr.p9060->intr_ctrl_stat) &
5150 ~0x0900);
5191 5151
5192 iounmap(cinfo->base_addr); 5152 iounmap(cinfo->base_addr);
5193 if (cinfo->ctl_addr) 5153 if (cinfo->ctl_addr.p9050)
5194 iounmap(cinfo->ctl_addr); 5154 iounmap(cinfo->ctl_addr.p9050);
5195 if (cinfo->irq 5155 if (cinfo->irq
5196#ifndef CONFIG_CYZ_INTR 5156#ifndef CONFIG_CYZ_INTR
5197 && !IS_CYC_Z(*cinfo) 5157 && !cy_is_Z(cinfo)
5198#endif /* CONFIG_CYZ_INTR */ 5158#endif /* CONFIG_CYZ_INTR */
5199 ) 5159 )
5200 free_irq(cinfo->irq, cinfo); 5160 free_irq(cinfo->irq, cinfo);
@@ -5240,7 +5200,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
5240 (cur_jifs - info->idle_stats.recv_idle)/ 5200 (cur_jifs - info->idle_stats.recv_idle)/
5241 HZ, info->idle_stats.overruns, 5201 HZ, info->idle_stats.overruns,
5242 /* FIXME: double check locking */ 5202 /* FIXME: double check locking */
5243 (long)info->port.tty->ldisc.ops->num); 5203 (long)info->port.tty->ldisc->ops->num);
5244 else 5204 else
5245 seq_printf(m, "%3d %8lu %10lu %8lu " 5205 seq_printf(m, "%3d %8lu %10lu %8lu "
5246 "%10lu %8lu %9lu %6ld\n", 5206 "%10lu %8lu %9lu %6ld\n",
@@ -5386,11 +5346,11 @@ static void __exit cy_cleanup_module(void)
5386 /* clear interrupt */ 5346 /* clear interrupt */
5387 cy_writeb(card->base_addr + Cy_ClrIntr, 0); 5347 cy_writeb(card->base_addr + Cy_ClrIntr, 0);
5388 iounmap(card->base_addr); 5348 iounmap(card->base_addr);
5389 if (card->ctl_addr) 5349 if (card->ctl_addr.p9050)
5390 iounmap(card->ctl_addr); 5350 iounmap(card->ctl_addr.p9050);
5391 if (card->irq 5351 if (card->irq
5392#ifndef CONFIG_CYZ_INTR 5352#ifndef CONFIG_CYZ_INTR
5393 && !IS_CYC_Z(*card) 5353 && !cy_is_Z(card)
5394#endif /* CONFIG_CYZ_INTR */ 5354#endif /* CONFIG_CYZ_INTR */
5395 ) 5355 )
5396 free_irq(card->irq, card); 5356 free_irq(card->irq, card);
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index af7c13ca9493..abef1f7d84fe 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -745,7 +745,7 @@ static int epca_carrier_raised(struct tty_port *port)
745 return 0; 745 return 0;
746} 746}
747 747
748static void epca_raise_dtr_rts(struct tty_port *port) 748static void epca_dtr_rts(struct tty_port *port, int onoff)
749{ 749{
750} 750}
751 751
@@ -925,7 +925,7 @@ static const struct tty_operations pc_ops = {
925 925
926static const struct tty_port_operations epca_port_ops = { 926static const struct tty_port_operations epca_port_ops = {
927 .carrier_raised = epca_carrier_raised, 927 .carrier_raised = epca_carrier_raised,
928 .raise_dtr_rts = epca_raise_dtr_rts, 928 .dtr_rts = epca_dtr_rts,
929}; 929};
930 930
931static int info_open(struct tty_struct *tty, struct file *filp) 931static int info_open(struct tty_struct *tty, struct file *filp)
@@ -1518,7 +1518,7 @@ static void doevent(int crd)
1518 if (event & MODEMCHG_IND) { 1518 if (event & MODEMCHG_IND) {
1519 /* A modem signal change has been indicated */ 1519 /* A modem signal change has been indicated */
1520 ch->imodem = mstat; 1520 ch->imodem = mstat;
1521 if (test_bit(ASYNC_CHECK_CD, &ch->port.flags)) { 1521 if (test_bit(ASYNCB_CHECK_CD, &ch->port.flags)) {
1522 /* We are now receiving dcd */ 1522 /* We are now receiving dcd */
1523 if (mstat & ch->dcd) 1523 if (mstat & ch->dcd)
1524 wake_up_interruptible(&ch->port.open_wait); 1524 wake_up_interruptible(&ch->port.open_wait);
@@ -1765,9 +1765,9 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch)
1765 * that the driver will wait on carrier detect. 1765 * that the driver will wait on carrier detect.
1766 */ 1766 */
1767 if (ts->c_cflag & CLOCAL) 1767 if (ts->c_cflag & CLOCAL)
1768 clear_bit(ASYNC_CHECK_CD, &ch->port.flags); 1768 clear_bit(ASYNCB_CHECK_CD, &ch->port.flags);
1769 else 1769 else
1770 set_bit(ASYNC_CHECK_CD, &ch->port.flags); 1770 set_bit(ASYNCB_CHECK_CD, &ch->port.flags);
1771 mval = ch->m_dtr | ch->m_rts; 1771 mval = ch->m_dtr | ch->m_rts;
1772 } /* End CBAUD not detected */ 1772 } /* End CBAUD not detected */
1773 iflag = termios2digi_i(ch, ts->c_iflag); 1773 iflag = termios2digi_i(ch, ts->c_iflag);
@@ -2114,8 +2114,8 @@ static int pc_ioctl(struct tty_struct *tty, struct file *file,
2114 tty_wait_until_sent(tty, 0); 2114 tty_wait_until_sent(tty, 0);
2115 } else { 2115 } else {
2116 /* ldisc lock already held in ioctl */ 2116 /* ldisc lock already held in ioctl */
2117 if (tty->ldisc.ops->flush_buffer) 2117 if (tty->ldisc->ops->flush_buffer)
2118 tty->ldisc.ops->flush_buffer(tty); 2118 tty->ldisc->ops->flush_buffer(tty);
2119 } 2119 }
2120 unlock_kernel(); 2120 unlock_kernel();
2121 /* Fall Thru */ 2121 /* Fall Thru */
@@ -2244,7 +2244,8 @@ static void do_softint(struct work_struct *work)
2244 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { 2244 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
2245 tty_hangup(tty); 2245 tty_hangup(tty);
2246 wake_up_interruptible(&ch->port.open_wait); 2246 wake_up_interruptible(&ch->port.open_wait);
2247 clear_bit(ASYNC_NORMAL_ACTIVE, &ch->port.flags); 2247 clear_bit(ASYNCB_NORMAL_ACTIVE,
2248 &ch->port.flags);
2248 } 2249 }
2249 } 2250 }
2250 tty_kref_put(tty); 2251 tty_kref_put(tty);
diff --git a/drivers/char/ip2/i2lib.c b/drivers/char/ip2/i2lib.c
index 0061e18aff60..0d10b89218ed 100644
--- a/drivers/char/ip2/i2lib.c
+++ b/drivers/char/ip2/i2lib.c
@@ -868,11 +868,11 @@ i2Input(i2ChanStrPtr pCh)
868 amountToMove = count; 868 amountToMove = count;
869 } 869 }
870 // Move the first block 870 // Move the first block
871 pCh->pTTY->ldisc.ops->receive_buf( pCh->pTTY, 871 pCh->pTTY->ldisc->ops->receive_buf( pCh->pTTY,
872 &(pCh->Ibuf[stripIndex]), NULL, amountToMove ); 872 &(pCh->Ibuf[stripIndex]), NULL, amountToMove );
873 // If we needed to wrap, do the second data move 873 // If we needed to wrap, do the second data move
874 if (count > amountToMove) { 874 if (count > amountToMove) {
875 pCh->pTTY->ldisc.ops->receive_buf( pCh->pTTY, 875 pCh->pTTY->ldisc->ops->receive_buf( pCh->pTTY,
876 pCh->Ibuf, NULL, count - amountToMove ); 876 pCh->Ibuf, NULL, count - amountToMove );
877 } 877 }
878 // Bump and wrap the stripIndex all at once by the amount of data read. This 878 // Bump and wrap the stripIndex all at once by the amount of data read. This
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index afd9247cf082..517271c762e6 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -1315,8 +1315,8 @@ static inline void isig(int sig, struct tty_struct *tty, int flush)
1315 if (tty->pgrp) 1315 if (tty->pgrp)
1316 kill_pgrp(tty->pgrp, sig, 1); 1316 kill_pgrp(tty->pgrp, sig, 1);
1317 if (flush || !L_NOFLSH(tty)) { 1317 if (flush || !L_NOFLSH(tty)) {
1318 if ( tty->ldisc.ops->flush_buffer ) 1318 if ( tty->ldisc->ops->flush_buffer )
1319 tty->ldisc.ops->flush_buffer(tty); 1319 tty->ldisc->ops->flush_buffer(tty);
1320 i2InputFlush( tty->driver_data ); 1320 i2InputFlush( tty->driver_data );
1321 } 1321 }
1322} 1322}
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index a59eac584d16..4d745a89504f 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -329,7 +329,7 @@ static inline void drop_rts(struct isi_port *port)
329 329
330/* card->lock MUST NOT be held */ 330/* card->lock MUST NOT be held */
331 331
332static void isicom_raise_dtr_rts(struct tty_port *port) 332static void isicom_dtr_rts(struct tty_port *port, int on)
333{ 333{
334 struct isi_port *ip = container_of(port, struct isi_port, port); 334 struct isi_port *ip = container_of(port, struct isi_port, port);
335 struct isi_board *card = ip->card; 335 struct isi_board *card = ip->card;
@@ -339,10 +339,17 @@ static void isicom_raise_dtr_rts(struct tty_port *port)
339 if (!lock_card(card)) 339 if (!lock_card(card))
340 return; 340 return;
341 341
342 outw(0x8000 | (channel << card->shift_count) | 0x02, base); 342 if (on) {
343 outw(0x0f04, base); 343 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
344 InterruptTheCard(base); 344 outw(0x0f04, base);
345 ip->status |= (ISI_DTR | ISI_RTS); 345 InterruptTheCard(base);
346 ip->status |= (ISI_DTR | ISI_RTS);
347 } else {
348 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
349 outw(0x0C04, base);
350 InterruptTheCard(base);
351 ip->status &= ~(ISI_DTR | ISI_RTS);
352 }
346 unlock_card(card); 353 unlock_card(card);
347} 354}
348 355
@@ -1339,7 +1346,7 @@ static const struct tty_operations isicom_ops = {
1339 1346
1340static const struct tty_port_operations isicom_port_ops = { 1347static const struct tty_port_operations isicom_port_ops = {
1341 .carrier_raised = isicom_carrier_raised, 1348 .carrier_raised = isicom_carrier_raised,
1342 .raise_dtr_rts = isicom_raise_dtr_rts, 1349 .dtr_rts = isicom_dtr_rts,
1343}; 1350};
1344 1351
1345static int __devinit reset_card(struct pci_dev *pdev, 1352static int __devinit reset_card(struct pci_dev *pdev,
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index fff19f7e29d2..e18800c400b1 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -1140,14 +1140,14 @@ static int stli_carrier_raised(struct tty_port *port)
1140 return (portp->sigs & TIOCM_CD) ? 1 : 0; 1140 return (portp->sigs & TIOCM_CD) ? 1 : 0;
1141} 1141}
1142 1142
1143static void stli_raise_dtr_rts(struct tty_port *port) 1143static void stli_dtr_rts(struct tty_port *port, int on)
1144{ 1144{
1145 struct stliport *portp = container_of(port, struct stliport, port); 1145 struct stliport *portp = container_of(port, struct stliport, port);
1146 struct stlibrd *brdp = stli_brds[portp->brdnr]; 1146 struct stlibrd *brdp = stli_brds[portp->brdnr];
1147 stli_mkasysigs(&portp->asig, 1, 1); 1147 stli_mkasysigs(&portp->asig, on, on);
1148 if (stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, 1148 if (stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1149 sizeof(asysigs_t), 0) < 0) 1149 sizeof(asysigs_t), 0) < 0)
1150 printk(KERN_WARNING "istallion: dtr raise failed.\n"); 1150 printk(KERN_WARNING "istallion: dtr set failed.\n");
1151} 1151}
1152 1152
1153 1153
@@ -4417,7 +4417,7 @@ static const struct tty_operations stli_ops = {
4417 4417
4418static const struct tty_port_operations stli_port_ops = { 4418static const struct tty_port_operations stli_port_ops = {
4419 .carrier_raised = stli_carrier_raised, 4419 .carrier_raised = stli_carrier_raised,
4420 .raise_dtr_rts = stli_raise_dtr_rts, 4420 .dtr_rts = stli_dtr_rts,
4421}; 4421};
4422 4422
4423/*****************************************************************************/ 4423/*****************************************************************************/
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 4a4cab73d0be..65b6ff2442c6 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -1184,6 +1184,11 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
1184 return -ENODEV; 1184 return -ENODEV;
1185 } 1185 }
1186 1186
1187 if (port % MAX_PORTS_PER_BOARD >= brd->numPorts) {
1188 mutex_unlock(&moxa_openlock);
1189 return -ENODEV;
1190 }
1191
1187 ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; 1192 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
1188 ch->port.count++; 1193 ch->port.count++;
1189 tty->driver_data = ch; 1194 tty->driver_data = ch;
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 13f8871e5b21..9533f43a30bb 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -547,14 +547,18 @@ static int mxser_carrier_raised(struct tty_port *port)
547 return (inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD)?1:0; 547 return (inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD)?1:0;
548} 548}
549 549
550static void mxser_raise_dtr_rts(struct tty_port *port) 550static void mxser_dtr_rts(struct tty_port *port, int on)
551{ 551{
552 struct mxser_port *mp = container_of(port, struct mxser_port, port); 552 struct mxser_port *mp = container_of(port, struct mxser_port, port);
553 unsigned long flags; 553 unsigned long flags;
554 554
555 spin_lock_irqsave(&mp->slock, flags); 555 spin_lock_irqsave(&mp->slock, flags);
556 outb(inb(mp->ioaddr + UART_MCR) | 556 if (on)
557 UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR); 557 outb(inb(mp->ioaddr + UART_MCR) |
558 UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR);
559 else
560 outb(inb(mp->ioaddr + UART_MCR)&~(UART_MCR_DTR | UART_MCR_RTS),
561 mp->ioaddr + UART_MCR);
558 spin_unlock_irqrestore(&mp->slock, flags); 562 spin_unlock_irqrestore(&mp->slock, flags);
559} 563}
560 564
@@ -2356,7 +2360,7 @@ static const struct tty_operations mxser_ops = {
2356 2360
2357struct tty_port_operations mxser_port_ops = { 2361struct tty_port_operations mxser_port_ops = {
2358 .carrier_raised = mxser_carrier_raised, 2362 .carrier_raised = mxser_carrier_raised,
2359 .raise_dtr_rts = mxser_raise_dtr_rts, 2363 .dtr_rts = mxser_dtr_rts,
2360}; 2364};
2361 2365
2362/* 2366/*
diff --git a/drivers/char/n_hdlc.c b/drivers/char/n_hdlc.c
index bacb3e2872ae..461ece591a5b 100644
--- a/drivers/char/n_hdlc.c
+++ b/drivers/char/n_hdlc.c
@@ -342,8 +342,8 @@ static int n_hdlc_tty_open (struct tty_struct *tty)
342#endif 342#endif
343 343
344 /* Flush any pending characters in the driver and discipline. */ 344 /* Flush any pending characters in the driver and discipline. */
345 if (tty->ldisc.ops->flush_buffer) 345 if (tty->ldisc->ops->flush_buffer)
346 tty->ldisc.ops->flush_buffer(tty); 346 tty->ldisc->ops->flush_buffer(tty);
347 347
348 tty_driver_flush_buffer(tty); 348 tty_driver_flush_buffer(tty);
349 349
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index f6f0e4ec2b51..94a5d5020abc 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -73,24 +73,6 @@
73#define ECHO_OP_SET_CANON_COL 0x81 73#define ECHO_OP_SET_CANON_COL 0x81
74#define ECHO_OP_ERASE_TAB 0x82 74#define ECHO_OP_ERASE_TAB 0x82
75 75
76static inline unsigned char *alloc_buf(void)
77{
78 gfp_t prio = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
79
80 if (PAGE_SIZE != N_TTY_BUF_SIZE)
81 return kmalloc(N_TTY_BUF_SIZE, prio);
82 else
83 return (unsigned char *)__get_free_page(prio);
84}
85
86static inline void free_buf(unsigned char *buf)
87{
88 if (PAGE_SIZE != N_TTY_BUF_SIZE)
89 kfree(buf);
90 else
91 free_page((unsigned long) buf);
92}
93
94static inline int tty_put_user(struct tty_struct *tty, unsigned char x, 76static inline int tty_put_user(struct tty_struct *tty, unsigned char x,
95 unsigned char __user *ptr) 77 unsigned char __user *ptr)
96{ 78{
@@ -1558,11 +1540,11 @@ static void n_tty_close(struct tty_struct *tty)
1558{ 1540{
1559 n_tty_flush_buffer(tty); 1541 n_tty_flush_buffer(tty);
1560 if (tty->read_buf) { 1542 if (tty->read_buf) {
1561 free_buf(tty->read_buf); 1543 kfree(tty->read_buf);
1562 tty->read_buf = NULL; 1544 tty->read_buf = NULL;
1563 } 1545 }
1564 if (tty->echo_buf) { 1546 if (tty->echo_buf) {
1565 free_buf(tty->echo_buf); 1547 kfree(tty->echo_buf);
1566 tty->echo_buf = NULL; 1548 tty->echo_buf = NULL;
1567 } 1549 }
1568} 1550}
@@ -1584,17 +1566,16 @@ static int n_tty_open(struct tty_struct *tty)
1584 1566
1585 /* These are ugly. Currently a malloc failure here can panic */ 1567 /* These are ugly. Currently a malloc failure here can panic */
1586 if (!tty->read_buf) { 1568 if (!tty->read_buf) {
1587 tty->read_buf = alloc_buf(); 1569 tty->read_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
1588 if (!tty->read_buf) 1570 if (!tty->read_buf)
1589 return -ENOMEM; 1571 return -ENOMEM;
1590 } 1572 }
1591 if (!tty->echo_buf) { 1573 if (!tty->echo_buf) {
1592 tty->echo_buf = alloc_buf(); 1574 tty->echo_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
1575
1593 if (!tty->echo_buf) 1576 if (!tty->echo_buf)
1594 return -ENOMEM; 1577 return -ENOMEM;
1595 } 1578 }
1596 memset(tty->read_buf, 0, N_TTY_BUF_SIZE);
1597 memset(tty->echo_buf, 0, N_TTY_BUF_SIZE);
1598 reset_buffer_flags(tty); 1579 reset_buffer_flags(tty);
1599 tty->column = 0; 1580 tty->column = 0;
1600 n_tty_set_termios(tty, NULL); 1581 n_tty_set_termios(tty, NULL);
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 19d79fc54461..77b364889224 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -383,7 +383,7 @@ static void async_mode(MGSLPC_INFO *info);
383static void tx_timeout(unsigned long context); 383static void tx_timeout(unsigned long context);
384 384
385static int carrier_raised(struct tty_port *port); 385static int carrier_raised(struct tty_port *port);
386static void raise_dtr_rts(struct tty_port *port); 386static void dtr_rts(struct tty_port *port, int onoff);
387 387
388#if SYNCLINK_GENERIC_HDLC 388#if SYNCLINK_GENERIC_HDLC
389#define dev_to_port(D) (dev_to_hdlc(D)->priv) 389#define dev_to_port(D) (dev_to_hdlc(D)->priv)
@@ -513,7 +513,7 @@ static void ldisc_receive_buf(struct tty_struct *tty,
513 513
514static const struct tty_port_operations mgslpc_port_ops = { 514static const struct tty_port_operations mgslpc_port_ops = {
515 .carrier_raised = carrier_raised, 515 .carrier_raised = carrier_raised,
516 .raise_dtr_rts = raise_dtr_rts 516 .dtr_rts = dtr_rts
517}; 517};
518 518
519static int mgslpc_probe(struct pcmcia_device *link) 519static int mgslpc_probe(struct pcmcia_device *link)
@@ -2528,13 +2528,16 @@ static int carrier_raised(struct tty_port *port)
2528 return 0; 2528 return 0;
2529} 2529}
2530 2530
2531static void raise_dtr_rts(struct tty_port *port) 2531static void dtr_rts(struct tty_port *port, int onoff)
2532{ 2532{
2533 MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port); 2533 MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port);
2534 unsigned long flags; 2534 unsigned long flags;
2535 2535
2536 spin_lock_irqsave(&info->lock,flags); 2536 spin_lock_irqsave(&info->lock,flags);
2537 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; 2537 if (onoff)
2538 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
2539 else
2540 info->serial_signals &= ~SerialSignal_RTS + SerialSignal_DTR;
2538 set_signals(info); 2541 set_signals(info);
2539 spin_unlock_irqrestore(&info->lock,flags); 2542 spin_unlock_irqrestore(&info->lock,flags);
2540} 2543}
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index 31038a0052a2..5acd29e6e043 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -30,7 +30,6 @@
30 30
31#include <asm/system.h> 31#include <asm/system.h>
32 32
33/* These are global because they are accessed in tty_io.c */
34#ifdef CONFIG_UNIX98_PTYS 33#ifdef CONFIG_UNIX98_PTYS
35static struct tty_driver *ptm_driver; 34static struct tty_driver *ptm_driver;
36static struct tty_driver *pts_driver; 35static struct tty_driver *pts_driver;
@@ -111,7 +110,7 @@ static int pty_write(struct tty_struct *tty, const unsigned char *buf,
111 c = to->receive_room; 110 c = to->receive_room;
112 if (c > count) 111 if (c > count)
113 c = count; 112 c = count;
114 to->ldisc.ops->receive_buf(to, buf, NULL, c); 113 to->ldisc->ops->receive_buf(to, buf, NULL, c);
115 114
116 return c; 115 return c;
117} 116}
@@ -149,11 +148,11 @@ static int pty_chars_in_buffer(struct tty_struct *tty)
149 int count; 148 int count;
150 149
151 /* We should get the line discipline lock for "tty->link" */ 150 /* We should get the line discipline lock for "tty->link" */
152 if (!to || !to->ldisc.ops->chars_in_buffer) 151 if (!to || !to->ldisc->ops->chars_in_buffer)
153 return 0; 152 return 0;
154 153
155 /* The ldisc must report 0 if no characters available to be read */ 154 /* The ldisc must report 0 if no characters available to be read */
156 count = to->ldisc.ops->chars_in_buffer(to); 155 count = to->ldisc->ops->chars_in_buffer(to);
157 156
158 if (tty->driver->subtype == PTY_TYPE_SLAVE) 157 if (tty->driver->subtype == PTY_TYPE_SLAVE)
159 return count; 158 return count;
@@ -187,8 +186,8 @@ static void pty_flush_buffer(struct tty_struct *tty)
187 if (!to) 186 if (!to)
188 return; 187 return;
189 188
190 if (to->ldisc.ops->flush_buffer) 189 if (to->ldisc->ops->flush_buffer)
191 to->ldisc.ops->flush_buffer(to); 190 to->ldisc->ops->flush_buffer(to);
192 191
193 if (to->packet) { 192 if (to->packet) {
194 spin_lock_irqsave(&tty->ctrl_lock, flags); 193 spin_lock_irqsave(&tty->ctrl_lock, flags);
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 20d90e6a6e50..db32f0e4c7dd 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -71,7 +71,7 @@ static int raw_open(struct inode *inode, struct file *filp)
71 err = bd_claim(bdev, raw_open); 71 err = bd_claim(bdev, raw_open);
72 if (err) 72 if (err)
73 goto out1; 73 goto out1;
74 err = set_blocksize(bdev, bdev_hardsect_size(bdev)); 74 err = set_blocksize(bdev, bdev_logical_block_size(bdev));
75 if (err) 75 if (err)
76 goto out2; 76 goto out2;
77 filp->f_flags |= O_DIRECT; 77 filp->f_flags |= O_DIRECT;
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index f59fc5cea067..63d5b628477a 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -872,11 +872,16 @@ static int carrier_raised(struct tty_port *port)
872 return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0; 872 return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0;
873} 873}
874 874
875static void raise_dtr_rts(struct tty_port *port) 875static void dtr_rts(struct tty_port *port, int on)
876{ 876{
877 struct r_port *info = container_of(port, struct r_port, port); 877 struct r_port *info = container_of(port, struct r_port, port);
878 sSetDTR(&info->channel); 878 if (on) {
879 sSetRTS(&info->channel); 879 sSetDTR(&info->channel);
880 sSetRTS(&info->channel);
881 } else {
882 sClrDTR(&info->channel);
883 sClrRTS(&info->channel);
884 }
880} 885}
881 886
882/* 887/*
@@ -934,7 +939,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
934 /* 939 /*
935 * Info->count is now 1; so it's safe to sleep now. 940 * Info->count is now 1; so it's safe to sleep now.
936 */ 941 */
937 if (!test_bit(ASYNC_INITIALIZED, &port->flags)) { 942 if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) {
938 cp = &info->channel; 943 cp = &info->channel;
939 sSetRxTrigger(cp, TRIG_1); 944 sSetRxTrigger(cp, TRIG_1);
940 if (sGetChanStatus(cp) & CD_ACT) 945 if (sGetChanStatus(cp) & CD_ACT)
@@ -958,7 +963,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
958 sEnRxFIFO(cp); 963 sEnRxFIFO(cp);
959 sEnTransmit(cp); 964 sEnTransmit(cp);
960 965
961 set_bit(ASYNC_INITIALIZED, &info->port.flags); 966 set_bit(ASYNCB_INITIALIZED, &info->port.flags);
962 967
963 /* 968 /*
964 * Set up the tty->alt_speed kludge 969 * Set up the tty->alt_speed kludge
@@ -1641,7 +1646,7 @@ static int rp_write(struct tty_struct *tty,
1641 /* Write remaining data into the port's xmit_buf */ 1646 /* Write remaining data into the port's xmit_buf */
1642 while (1) { 1647 while (1) {
1643 /* Hung up ? */ 1648 /* Hung up ? */
1644 if (!test_bit(ASYNC_NORMAL_ACTIVE, &info->port.flags)) 1649 if (!test_bit(ASYNCB_NORMAL_ACTIVE, &info->port.flags))
1645 goto end; 1650 goto end;
1646 c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1); 1651 c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1);
1647 c = min(c, XMIT_BUF_SIZE - info->xmit_head); 1652 c = min(c, XMIT_BUF_SIZE - info->xmit_head);
@@ -2250,7 +2255,7 @@ static const struct tty_operations rocket_ops = {
2250 2255
2251static const struct tty_port_operations rocket_port_ops = { 2256static const struct tty_port_operations rocket_port_ops = {
2252 .carrier_raised = carrier_raised, 2257 .carrier_raised = carrier_raised,
2253 .raise_dtr_rts = raise_dtr_rts, 2258 .dtr_rts = dtr_rts,
2254}; 2259};
2255 2260
2256/* 2261/*
diff --git a/drivers/char/selection.c b/drivers/char/selection.c
index cb8ca5698963..f97b9e848064 100644
--- a/drivers/char/selection.c
+++ b/drivers/char/selection.c
@@ -327,7 +327,7 @@ int paste_selection(struct tty_struct *tty)
327 } 327 }
328 count = sel_buffer_lth - pasted; 328 count = sel_buffer_lth - pasted;
329 count = min(count, tty->receive_room); 329 count = min(count, tty->receive_room);
330 tty->ldisc.ops->receive_buf(tty, sel_buffer + pasted, 330 tty->ldisc->ops->receive_buf(tty, sel_buffer + pasted,
331 NULL, count); 331 NULL, count);
332 pasted += count; 332 pasted += count;
333 } 333 }
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 2ad813a801dc..53e504f41b20 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -772,11 +772,11 @@ static int stl_carrier_raised(struct tty_port *port)
772 return (portp->sigs & TIOCM_CD) ? 1 : 0; 772 return (portp->sigs & TIOCM_CD) ? 1 : 0;
773} 773}
774 774
775static void stl_raise_dtr_rts(struct tty_port *port) 775static void stl_dtr_rts(struct tty_port *port, int on)
776{ 776{
777 struct stlport *portp = container_of(port, struct stlport, port); 777 struct stlport *portp = container_of(port, struct stlport, port);
778 /* Takes brd_lock internally */ 778 /* Takes brd_lock internally */
779 stl_setsignals(portp, 1, 1); 779 stl_setsignals(portp, on, on);
780} 780}
781 781
782/*****************************************************************************/ 782/*****************************************************************************/
@@ -2547,7 +2547,7 @@ static const struct tty_operations stl_ops = {
2547 2547
2548static const struct tty_port_operations stl_port_ops = { 2548static const struct tty_port_operations stl_port_ops = {
2549 .carrier_raised = stl_carrier_raised, 2549 .carrier_raised = stl_carrier_raised,
2550 .raise_dtr_rts = stl_raise_dtr_rts, 2550 .dtr_rts = stl_dtr_rts,
2551}; 2551};
2552 2552
2553/*****************************************************************************/ 2553/*****************************************************************************/
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index afd0b26ca056..afded3a2379c 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -3247,13 +3247,16 @@ static int carrier_raised(struct tty_port *port)
3247 return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; 3247 return (info->serial_signals & SerialSignal_DCD) ? 1 : 0;
3248} 3248}
3249 3249
3250static void raise_dtr_rts(struct tty_port *port) 3250static void dtr_rts(struct tty_port *port, int on)
3251{ 3251{
3252 struct mgsl_struct *info = container_of(port, struct mgsl_struct, port); 3252 struct mgsl_struct *info = container_of(port, struct mgsl_struct, port);
3253 unsigned long flags; 3253 unsigned long flags;
3254 3254
3255 spin_lock_irqsave(&info->irq_spinlock,flags); 3255 spin_lock_irqsave(&info->irq_spinlock,flags);
3256 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; 3256 if (on)
3257 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
3258 else
3259 info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
3257 usc_set_serial_signals(info); 3260 usc_set_serial_signals(info);
3258 spin_unlock_irqrestore(&info->irq_spinlock,flags); 3261 spin_unlock_irqrestore(&info->irq_spinlock,flags);
3259} 3262}
@@ -4258,7 +4261,7 @@ static void mgsl_add_device( struct mgsl_struct *info )
4258 4261
4259static const struct tty_port_operations mgsl_port_ops = { 4262static const struct tty_port_operations mgsl_port_ops = {
4260 .carrier_raised = carrier_raised, 4263 .carrier_raised = carrier_raised,
4261 .raise_dtr_rts = raise_dtr_rts, 4264 .dtr_rts = dtr_rts,
4262}; 4265};
4263 4266
4264 4267
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index 5e256494686a..1386625fc4ca 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -214,6 +214,7 @@ struct slgt_desc
214#define set_desc_next(a,b) (a).next = cpu_to_le32((unsigned int)(b)) 214#define set_desc_next(a,b) (a).next = cpu_to_le32((unsigned int)(b))
215#define set_desc_count(a,b)(a).count = cpu_to_le16((unsigned short)(b)) 215#define set_desc_count(a,b)(a).count = cpu_to_le16((unsigned short)(b))
216#define set_desc_eof(a,b) (a).status = cpu_to_le16((b) ? (le16_to_cpu((a).status) | BIT0) : (le16_to_cpu((a).status) & ~BIT0)) 216#define set_desc_eof(a,b) (a).status = cpu_to_le16((b) ? (le16_to_cpu((a).status) | BIT0) : (le16_to_cpu((a).status) & ~BIT0))
217#define set_desc_status(a, b) (a).status = cpu_to_le16((unsigned short)(b))
217#define desc_count(a) (le16_to_cpu((a).count)) 218#define desc_count(a) (le16_to_cpu((a).count))
218#define desc_status(a) (le16_to_cpu((a).status)) 219#define desc_status(a) (le16_to_cpu((a).status))
219#define desc_complete(a) (le16_to_cpu((a).status) & BIT15) 220#define desc_complete(a) (le16_to_cpu((a).status) & BIT15)
@@ -297,6 +298,7 @@ struct slgt_info {
297 u32 max_frame_size; /* as set by device config */ 298 u32 max_frame_size; /* as set by device config */
298 299
299 unsigned int rbuf_fill_level; 300 unsigned int rbuf_fill_level;
301 unsigned int rx_pio;
300 unsigned int if_mode; 302 unsigned int if_mode;
301 unsigned int base_clock; 303 unsigned int base_clock;
302 304
@@ -331,6 +333,8 @@ struct slgt_info {
331 struct slgt_desc *rbufs; 333 struct slgt_desc *rbufs;
332 unsigned int rbuf_current; 334 unsigned int rbuf_current;
333 unsigned int rbuf_index; 335 unsigned int rbuf_index;
336 unsigned int rbuf_fill_index;
337 unsigned short rbuf_fill_count;
334 338
335 unsigned int tbuf_count; 339 unsigned int tbuf_count;
336 struct slgt_desc *tbufs; 340 struct slgt_desc *tbufs;
@@ -2110,6 +2114,40 @@ static void ri_change(struct slgt_info *info, unsigned short status)
2110 info->pending_bh |= BH_STATUS; 2114 info->pending_bh |= BH_STATUS;
2111} 2115}
2112 2116
2117static void isr_rxdata(struct slgt_info *info)
2118{
2119 unsigned int count = info->rbuf_fill_count;
2120 unsigned int i = info->rbuf_fill_index;
2121 unsigned short reg;
2122
2123 while (rd_reg16(info, SSR) & IRQ_RXDATA) {
2124 reg = rd_reg16(info, RDR);
2125 DBGISR(("isr_rxdata %s RDR=%04X\n", info->device_name, reg));
2126 if (desc_complete(info->rbufs[i])) {
2127 /* all buffers full */
2128 rx_stop(info);
2129 info->rx_restart = 1;
2130 continue;
2131 }
2132 info->rbufs[i].buf[count++] = (unsigned char)reg;
2133 /* async mode saves status byte to buffer for each data byte */
2134 if (info->params.mode == MGSL_MODE_ASYNC)
2135 info->rbufs[i].buf[count++] = (unsigned char)(reg >> 8);
2136 if (count == info->rbuf_fill_level || (reg & BIT10)) {
2137 /* buffer full or end of frame */
2138 set_desc_count(info->rbufs[i], count);
2139 set_desc_status(info->rbufs[i], BIT15 | (reg >> 8));
2140 info->rbuf_fill_count = count = 0;
2141 if (++i == info->rbuf_count)
2142 i = 0;
2143 info->pending_bh |= BH_RECEIVE;
2144 }
2145 }
2146
2147 info->rbuf_fill_index = i;
2148 info->rbuf_fill_count = count;
2149}
2150
2113static void isr_serial(struct slgt_info *info) 2151static void isr_serial(struct slgt_info *info)
2114{ 2152{
2115 unsigned short status = rd_reg16(info, SSR); 2153 unsigned short status = rd_reg16(info, SSR);
@@ -2125,6 +2163,8 @@ static void isr_serial(struct slgt_info *info)
2125 if (info->tx_count) 2163 if (info->tx_count)
2126 isr_txeom(info, status); 2164 isr_txeom(info, status);
2127 } 2165 }
2166 if (info->rx_pio && (status & IRQ_RXDATA))
2167 isr_rxdata(info);
2128 if ((status & IRQ_RXBREAK) && (status & RXBREAK)) { 2168 if ((status & IRQ_RXBREAK) && (status & RXBREAK)) {
2129 info->icount.brk++; 2169 info->icount.brk++;
2130 /* process break detection if tty control allows */ 2170 /* process break detection if tty control allows */
@@ -2141,7 +2181,8 @@ static void isr_serial(struct slgt_info *info)
2141 } else { 2181 } else {
2142 if (status & (IRQ_TXIDLE + IRQ_TXUNDER)) 2182 if (status & (IRQ_TXIDLE + IRQ_TXUNDER))
2143 isr_txeom(info, status); 2183 isr_txeom(info, status);
2144 2184 if (info->rx_pio && (status & IRQ_RXDATA))
2185 isr_rxdata(info);
2145 if (status & IRQ_RXIDLE) { 2186 if (status & IRQ_RXIDLE) {
2146 if (status & RXIDLE) 2187 if (status & RXIDLE)
2147 info->icount.rxidle++; 2188 info->icount.rxidle++;
@@ -2642,6 +2683,10 @@ static int rx_enable(struct slgt_info *info, int enable)
2642 return -EINVAL; 2683 return -EINVAL;
2643 } 2684 }
2644 info->rbuf_fill_level = rbuf_fill_level; 2685 info->rbuf_fill_level = rbuf_fill_level;
2686 if (rbuf_fill_level < 128)
2687 info->rx_pio = 1; /* PIO mode */
2688 else
2689 info->rx_pio = 0; /* DMA mode */
2645 rx_stop(info); /* restart receiver to use new fill level */ 2690 rx_stop(info); /* restart receiver to use new fill level */
2646 } 2691 }
2647 2692
@@ -3099,13 +3144,16 @@ static int carrier_raised(struct tty_port *port)
3099 return (info->signals & SerialSignal_DCD) ? 1 : 0; 3144 return (info->signals & SerialSignal_DCD) ? 1 : 0;
3100} 3145}
3101 3146
3102static void raise_dtr_rts(struct tty_port *port) 3147static void dtr_rts(struct tty_port *port, int on)
3103{ 3148{
3104 unsigned long flags; 3149 unsigned long flags;
3105 struct slgt_info *info = container_of(port, struct slgt_info, port); 3150 struct slgt_info *info = container_of(port, struct slgt_info, port);
3106 3151
3107 spin_lock_irqsave(&info->lock,flags); 3152 spin_lock_irqsave(&info->lock,flags);
3108 info->signals |= SerialSignal_RTS + SerialSignal_DTR; 3153 if (on)
3154 info->signals |= SerialSignal_RTS + SerialSignal_DTR;
3155 else
3156 info->signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
3109 set_signals(info); 3157 set_signals(info);
3110 spin_unlock_irqrestore(&info->lock,flags); 3158 spin_unlock_irqrestore(&info->lock,flags);
3111} 3159}
@@ -3419,7 +3467,7 @@ static void add_device(struct slgt_info *info)
3419 3467
3420static const struct tty_port_operations slgt_port_ops = { 3468static const struct tty_port_operations slgt_port_ops = {
3421 .carrier_raised = carrier_raised, 3469 .carrier_raised = carrier_raised,
3422 .raise_dtr_rts = raise_dtr_rts, 3470 .dtr_rts = dtr_rts,
3423}; 3471};
3424 3472
3425/* 3473/*
@@ -3841,15 +3889,27 @@ static void rx_start(struct slgt_info *info)
3841 rdma_reset(info); 3889 rdma_reset(info);
3842 reset_rbufs(info); 3890 reset_rbufs(info);
3843 3891
3844 /* set 1st descriptor address */ 3892 if (info->rx_pio) {
3845 wr_reg32(info, RDDAR, info->rbufs[0].pdesc); 3893 /* rx request when rx FIFO not empty */
3846 3894 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) & ~BIT14));
3847 if (info->params.mode != MGSL_MODE_ASYNC) { 3895 slgt_irq_on(info, IRQ_RXDATA);
3848 /* enable rx DMA and DMA interrupt */ 3896 if (info->params.mode == MGSL_MODE_ASYNC) {
3849 wr_reg32(info, RDCSR, (BIT2 + BIT0)); 3897 /* enable saving of rx status */
3898 wr_reg32(info, RDCSR, BIT6);
3899 }
3850 } else { 3900 } else {
3851 /* enable saving of rx status, rx DMA and DMA interrupt */ 3901 /* rx request when rx FIFO half full */
3852 wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0)); 3902 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT14));
3903 /* set 1st descriptor address */
3904 wr_reg32(info, RDDAR, info->rbufs[0].pdesc);
3905
3906 if (info->params.mode != MGSL_MODE_ASYNC) {
3907 /* enable rx DMA and DMA interrupt */
3908 wr_reg32(info, RDCSR, (BIT2 + BIT0));
3909 } else {
3910 /* enable saving of rx status, rx DMA and DMA interrupt */
3911 wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0));
3912 }
3853 } 3913 }
3854 3914
3855 slgt_irq_on(info, IRQ_RXOVER); 3915 slgt_irq_on(info, IRQ_RXOVER);
@@ -4467,6 +4527,8 @@ static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last
4467static void reset_rbufs(struct slgt_info *info) 4527static void reset_rbufs(struct slgt_info *info)
4468{ 4528{
4469 free_rbufs(info, 0, info->rbuf_count - 1); 4529 free_rbufs(info, 0, info->rbuf_count - 1);
4530 info->rbuf_fill_index = 0;
4531 info->rbuf_fill_count = 0;
4470} 4532}
4471 4533
4472/* 4534/*
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 26de60efe4b2..6f727e3c53ad 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -3277,13 +3277,16 @@ static int carrier_raised(struct tty_port *port)
3277 return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; 3277 return (info->serial_signals & SerialSignal_DCD) ? 1 : 0;
3278} 3278}
3279 3279
3280static void raise_dtr_rts(struct tty_port *port) 3280static void dtr_rts(struct tty_port *port, int on)
3281{ 3281{
3282 SLMP_INFO *info = container_of(port, SLMP_INFO, port); 3282 SLMP_INFO *info = container_of(port, SLMP_INFO, port);
3283 unsigned long flags; 3283 unsigned long flags;
3284 3284
3285 spin_lock_irqsave(&info->lock,flags); 3285 spin_lock_irqsave(&info->lock,flags);
3286 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; 3286 if (on)
3287 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
3288 else
3289 info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
3287 set_signals(info); 3290 set_signals(info);
3288 spin_unlock_irqrestore(&info->lock,flags); 3291 spin_unlock_irqrestore(&info->lock,flags);
3289} 3292}
@@ -3746,7 +3749,7 @@ static void add_device(SLMP_INFO *info)
3746 3749
3747static const struct tty_port_operations port_ops = { 3750static const struct tty_port_operations port_ops = {
3748 .carrier_raised = carrier_raised, 3751 .carrier_raised = carrier_raised,
3749 .raise_dtr_rts = raise_dtr_rts, 3752 .dtr_rts = dtr_rts,
3750}; 3753};
3751 3754
3752/* Allocate and initialize a device instance structure 3755/* Allocate and initialize a device instance structure
diff --git a/drivers/char/tty_audit.c b/drivers/char/tty_audit.c
index 55ba6f142883..ac16fbec72d0 100644
--- a/drivers/char/tty_audit.c
+++ b/drivers/char/tty_audit.c
@@ -29,10 +29,7 @@ static struct tty_audit_buf *tty_audit_buf_alloc(int major, int minor,
29 buf = kmalloc(sizeof(*buf), GFP_KERNEL); 29 buf = kmalloc(sizeof(*buf), GFP_KERNEL);
30 if (!buf) 30 if (!buf)
31 goto err; 31 goto err;
32 if (PAGE_SIZE != N_TTY_BUF_SIZE) 32 buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
33 buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
34 else
35 buf->data = (unsigned char *)__get_free_page(GFP_KERNEL);
36 if (!buf->data) 33 if (!buf->data)
37 goto err_buf; 34 goto err_buf;
38 atomic_set(&buf->count, 1); 35 atomic_set(&buf->count, 1);
@@ -52,10 +49,7 @@ err:
52static void tty_audit_buf_free(struct tty_audit_buf *buf) 49static void tty_audit_buf_free(struct tty_audit_buf *buf)
53{ 50{
54 WARN_ON(buf->valid != 0); 51 WARN_ON(buf->valid != 0);
55 if (PAGE_SIZE != N_TTY_BUF_SIZE) 52 kfree(buf->data);
56 kfree(buf->data);
57 else
58 free_page((unsigned long)buf->data);
59 kfree(buf); 53 kfree(buf);
60} 54}
61 55
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 66b99a2049e3..939e198d7670 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -295,7 +295,7 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line)
295 struct tty_driver *p, *res = NULL; 295 struct tty_driver *p, *res = NULL;
296 int tty_line = 0; 296 int tty_line = 0;
297 int len; 297 int len;
298 char *str; 298 char *str, *stp;
299 299
300 for (str = name; *str; str++) 300 for (str = name; *str; str++)
301 if ((*str >= '0' && *str <= '9') || *str == ',') 301 if ((*str >= '0' && *str <= '9') || *str == ',')
@@ -311,13 +311,14 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line)
311 list_for_each_entry(p, &tty_drivers, tty_drivers) { 311 list_for_each_entry(p, &tty_drivers, tty_drivers) {
312 if (strncmp(name, p->name, len) != 0) 312 if (strncmp(name, p->name, len) != 0)
313 continue; 313 continue;
314 if (*str == ',') 314 stp = str;
315 str++; 315 if (*stp == ',')
316 if (*str == '\0') 316 stp++;
317 str = NULL; 317 if (*stp == '\0')
318 stp = NULL;
318 319
319 if (tty_line >= 0 && tty_line <= p->num && p->ops && 320 if (tty_line >= 0 && tty_line <= p->num && p->ops &&
320 p->ops->poll_init && !p->ops->poll_init(p, tty_line, str)) { 321 p->ops->poll_init && !p->ops->poll_init(p, tty_line, stp)) {
321 res = tty_driver_kref_get(p); 322 res = tty_driver_kref_get(p);
322 *line = tty_line; 323 *line = tty_line;
323 break; 324 break;
@@ -470,43 +471,6 @@ void tty_wakeup(struct tty_struct *tty)
470EXPORT_SYMBOL_GPL(tty_wakeup); 471EXPORT_SYMBOL_GPL(tty_wakeup);
471 472
472/** 473/**
473 * tty_ldisc_flush - flush line discipline queue
474 * @tty: tty
475 *
476 * Flush the line discipline queue (if any) for this tty. If there
477 * is no line discipline active this is a no-op.
478 */
479
480void tty_ldisc_flush(struct tty_struct *tty)
481{
482 struct tty_ldisc *ld = tty_ldisc_ref(tty);
483 if (ld) {
484 if (ld->ops->flush_buffer)
485 ld->ops->flush_buffer(tty);
486 tty_ldisc_deref(ld);
487 }
488 tty_buffer_flush(tty);
489}
490
491EXPORT_SYMBOL_GPL(tty_ldisc_flush);
492
493/**
494 * tty_reset_termios - reset terminal state
495 * @tty: tty to reset
496 *
497 * Restore a terminal to the driver default state
498 */
499
500static void tty_reset_termios(struct tty_struct *tty)
501{
502 mutex_lock(&tty->termios_mutex);
503 *tty->termios = tty->driver->init_termios;
504 tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios);
505 tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
506 mutex_unlock(&tty->termios_mutex);
507}
508
509/**
510 * do_tty_hangup - actual handler for hangup events 474 * do_tty_hangup - actual handler for hangup events
511 * @work: tty device 475 * @work: tty device
512 * 476 *
@@ -535,7 +499,6 @@ static void do_tty_hangup(struct work_struct *work)
535 struct file *cons_filp = NULL; 499 struct file *cons_filp = NULL;
536 struct file *filp, *f = NULL; 500 struct file *filp, *f = NULL;
537 struct task_struct *p; 501 struct task_struct *p;
538 struct tty_ldisc *ld;
539 int closecount = 0, n; 502 int closecount = 0, n;
540 unsigned long flags; 503 unsigned long flags;
541 int refs = 0; 504 int refs = 0;
@@ -566,40 +529,8 @@ static void do_tty_hangup(struct work_struct *work)
566 filp->f_op = &hung_up_tty_fops; 529 filp->f_op = &hung_up_tty_fops;
567 } 530 }
568 file_list_unlock(); 531 file_list_unlock();
569 /*
570 * FIXME! What are the locking issues here? This may me overdoing
571 * things... This question is especially important now that we've
572 * removed the irqlock.
573 */
574 ld = tty_ldisc_ref(tty);
575 if (ld != NULL) {
576 /* We may have no line discipline at this point */
577 if (ld->ops->flush_buffer)
578 ld->ops->flush_buffer(tty);
579 tty_driver_flush_buffer(tty);
580 if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) &&
581 ld->ops->write_wakeup)
582 ld->ops->write_wakeup(tty);
583 if (ld->ops->hangup)
584 ld->ops->hangup(tty);
585 }
586 /*
587 * FIXME: Once we trust the LDISC code better we can wait here for
588 * ldisc completion and fix the driver call race
589 */
590 wake_up_interruptible_poll(&tty->write_wait, POLLOUT);
591 wake_up_interruptible_poll(&tty->read_wait, POLLIN);
592 /*
593 * Shutdown the current line discipline, and reset it to
594 * N_TTY.
595 */
596 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS)
597 tty_reset_termios(tty);
598 /* Defer ldisc switch */
599 /* tty_deferred_ldisc_switch(N_TTY);
600 532
601 This should get done automatically when the port closes and 533 tty_ldisc_hangup(tty);
602 tty_release is called */
603 534
604 read_lock(&tasklist_lock); 535 read_lock(&tasklist_lock);
605 if (tty->session) { 536 if (tty->session) {
@@ -628,12 +559,15 @@ static void do_tty_hangup(struct work_struct *work)
628 read_unlock(&tasklist_lock); 559 read_unlock(&tasklist_lock);
629 560
630 spin_lock_irqsave(&tty->ctrl_lock, flags); 561 spin_lock_irqsave(&tty->ctrl_lock, flags);
631 tty->flags = 0; 562 clear_bit(TTY_THROTTLED, &tty->flags);
563 clear_bit(TTY_PUSH, &tty->flags);
564 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
632 put_pid(tty->session); 565 put_pid(tty->session);
633 put_pid(tty->pgrp); 566 put_pid(tty->pgrp);
634 tty->session = NULL; 567 tty->session = NULL;
635 tty->pgrp = NULL; 568 tty->pgrp = NULL;
636 tty->ctrl_status = 0; 569 tty->ctrl_status = 0;
570 set_bit(TTY_HUPPED, &tty->flags);
637 spin_unlock_irqrestore(&tty->ctrl_lock, flags); 571 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
638 572
639 /* Account for the p->signal references we killed */ 573 /* Account for the p->signal references we killed */
@@ -659,10 +593,7 @@ static void do_tty_hangup(struct work_struct *work)
659 * can't yet guarantee all that. 593 * can't yet guarantee all that.
660 */ 594 */
661 set_bit(TTY_HUPPED, &tty->flags); 595 set_bit(TTY_HUPPED, &tty->flags);
662 if (ld) { 596 tty_ldisc_enable(tty);
663 tty_ldisc_enable(tty);
664 tty_ldisc_deref(ld);
665 }
666 unlock_kernel(); 597 unlock_kernel();
667 if (f) 598 if (f)
668 fput(f); 599 fput(f);
@@ -2480,6 +2411,24 @@ static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int
2480 return tty->ops->tiocmset(tty, file, set, clear); 2411 return tty->ops->tiocmset(tty, file, set, clear);
2481} 2412}
2482 2413
2414struct tty_struct *tty_pair_get_tty(struct tty_struct *tty)
2415{
2416 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
2417 tty->driver->subtype == PTY_TYPE_MASTER)
2418 tty = tty->link;
2419 return tty;
2420}
2421EXPORT_SYMBOL(tty_pair_get_tty);
2422
2423struct tty_struct *tty_pair_get_pty(struct tty_struct *tty)
2424{
2425 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
2426 tty->driver->subtype == PTY_TYPE_MASTER)
2427 return tty;
2428 return tty->link;
2429}
2430EXPORT_SYMBOL(tty_pair_get_pty);
2431
2483/* 2432/*
2484 * Split this up, as gcc can choke on it otherwise.. 2433 * Split this up, as gcc can choke on it otherwise..
2485 */ 2434 */
@@ -2495,11 +2444,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2495 if (tty_paranoia_check(tty, inode, "tty_ioctl")) 2444 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
2496 return -EINVAL; 2445 return -EINVAL;
2497 2446
2498 real_tty = tty; 2447 real_tty = tty_pair_get_tty(tty);
2499 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
2500 tty->driver->subtype == PTY_TYPE_MASTER)
2501 real_tty = tty->link;
2502
2503 2448
2504 /* 2449 /*
2505 * Factor out some common prep work 2450 * Factor out some common prep work
@@ -2555,7 +2500,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2555 case TIOCGSID: 2500 case TIOCGSID:
2556 return tiocgsid(tty, real_tty, p); 2501 return tiocgsid(tty, real_tty, p);
2557 case TIOCGETD: 2502 case TIOCGETD:
2558 return put_user(tty->ldisc.ops->num, (int __user *)p); 2503 return put_user(tty->ldisc->ops->num, (int __user *)p);
2559 case TIOCSETD: 2504 case TIOCSETD:
2560 return tiocsetd(tty, p); 2505 return tiocsetd(tty, p);
2561 /* 2506 /*
@@ -2770,6 +2715,7 @@ void initialize_tty_struct(struct tty_struct *tty,
2770 tty->buf.head = tty->buf.tail = NULL; 2715 tty->buf.head = tty->buf.tail = NULL;
2771 tty_buffer_init(tty); 2716 tty_buffer_init(tty);
2772 mutex_init(&tty->termios_mutex); 2717 mutex_init(&tty->termios_mutex);
2718 mutex_init(&tty->ldisc_mutex);
2773 init_waitqueue_head(&tty->write_wait); 2719 init_waitqueue_head(&tty->write_wait);
2774 init_waitqueue_head(&tty->read_wait); 2720 init_waitqueue_head(&tty->read_wait);
2775 INIT_WORK(&tty->hangup_work, do_tty_hangup); 2721 INIT_WORK(&tty->hangup_work, do_tty_hangup);
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index 6f4c7d0a53bf..8116bb1c8f80 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -97,14 +97,19 @@ EXPORT_SYMBOL(tty_driver_flush_buffer);
97 * @tty: terminal 97 * @tty: terminal
98 * 98 *
99 * Indicate that a tty should stop transmitting data down the stack. 99 * Indicate that a tty should stop transmitting data down the stack.
100 * Takes the termios mutex to protect against parallel throttle/unthrottle
101 * and also to ensure the driver can consistently reference its own
102 * termios data at this point when implementing software flow control.
100 */ 103 */
101 104
102void tty_throttle(struct tty_struct *tty) 105void tty_throttle(struct tty_struct *tty)
103{ 106{
107 mutex_lock(&tty->termios_mutex);
104 /* check TTY_THROTTLED first so it indicates our state */ 108 /* check TTY_THROTTLED first so it indicates our state */
105 if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) && 109 if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) &&
106 tty->ops->throttle) 110 tty->ops->throttle)
107 tty->ops->throttle(tty); 111 tty->ops->throttle(tty);
112 mutex_unlock(&tty->termios_mutex);
108} 113}
109EXPORT_SYMBOL(tty_throttle); 114EXPORT_SYMBOL(tty_throttle);
110 115
@@ -113,13 +118,21 @@ EXPORT_SYMBOL(tty_throttle);
113 * @tty: terminal 118 * @tty: terminal
114 * 119 *
115 * Indicate that a tty may continue transmitting data down the stack. 120 * Indicate that a tty may continue transmitting data down the stack.
121 * Takes the termios mutex to protect against parallel throttle/unthrottle
122 * and also to ensure the driver can consistently reference its own
123 * termios data at this point when implementing software flow control.
124 *
125 * Drivers should however remember that the stack can issue a throttle,
126 * then change flow control method, then unthrottle.
116 */ 127 */
117 128
118void tty_unthrottle(struct tty_struct *tty) 129void tty_unthrottle(struct tty_struct *tty)
119{ 130{
131 mutex_lock(&tty->termios_mutex);
120 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && 132 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) &&
121 tty->ops->unthrottle) 133 tty->ops->unthrottle)
122 tty->ops->unthrottle(tty); 134 tty->ops->unthrottle(tty);
135 mutex_unlock(&tty->termios_mutex);
123} 136}
124EXPORT_SYMBOL(tty_unthrottle); 137EXPORT_SYMBOL(tty_unthrottle);
125 138
@@ -613,9 +626,25 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt)
613 return 0; 626 return 0;
614} 627}
615 628
629static void copy_termios(struct tty_struct *tty, struct ktermios *kterm)
630{
631 mutex_lock(&tty->termios_mutex);
632 memcpy(kterm, tty->termios, sizeof(struct ktermios));
633 mutex_unlock(&tty->termios_mutex);
634}
635
636static void copy_termios_locked(struct tty_struct *tty, struct ktermios *kterm)
637{
638 mutex_lock(&tty->termios_mutex);
639 memcpy(kterm, tty->termios_locked, sizeof(struct ktermios));
640 mutex_unlock(&tty->termios_mutex);
641}
642
616static int get_termio(struct tty_struct *tty, struct termio __user *termio) 643static int get_termio(struct tty_struct *tty, struct termio __user *termio)
617{ 644{
618 if (kernel_termios_to_user_termio(termio, tty->termios)) 645 struct ktermios kterm;
646 copy_termios(tty, &kterm);
647 if (kernel_termios_to_user_termio(termio, &kterm))
619 return -EFAULT; 648 return -EFAULT;
620 return 0; 649 return 0;
621} 650}
@@ -917,6 +946,8 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
917 struct tty_struct *real_tty; 946 struct tty_struct *real_tty;
918 void __user *p = (void __user *)arg; 947 void __user *p = (void __user *)arg;
919 int ret = 0; 948 int ret = 0;
949 struct ktermios kterm;
950 struct termiox ktermx;
920 951
921 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 952 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
922 tty->driver->subtype == PTY_TYPE_MASTER) 953 tty->driver->subtype == PTY_TYPE_MASTER)
@@ -952,23 +983,20 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
952 return set_termios(real_tty, p, TERMIOS_OLD); 983 return set_termios(real_tty, p, TERMIOS_OLD);
953#ifndef TCGETS2 984#ifndef TCGETS2
954 case TCGETS: 985 case TCGETS:
955 mutex_lock(&real_tty->termios_mutex); 986 copy_termios(real_tty, &kterm);
956 if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios)) 987 if (kernel_termios_to_user_termios((struct termios __user *)arg, &kterm))
957 ret = -EFAULT; 988 ret = -EFAULT;
958 mutex_unlock(&real_tty->termios_mutex);
959 return ret; 989 return ret;
960#else 990#else
961 case TCGETS: 991 case TCGETS:
962 mutex_lock(&real_tty->termios_mutex); 992 copy_termios(real_tty, &kterm);
963 if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios)) 993 if (kernel_termios_to_user_termios_1((struct termios __user *)arg, &kterm))
964 ret = -EFAULT; 994 ret = -EFAULT;
965 mutex_unlock(&real_tty->termios_mutex);
966 return ret; 995 return ret;
967 case TCGETS2: 996 case TCGETS2:
968 mutex_lock(&real_tty->termios_mutex); 997 copy_termios(real_tty, &kterm);
969 if (kernel_termios_to_user_termios((struct termios2 __user *)arg, real_tty->termios)) 998 if (kernel_termios_to_user_termios((struct termios2 __user *)arg, &kterm))
970 ret = -EFAULT; 999 ret = -EFAULT;
971 mutex_unlock(&real_tty->termios_mutex);
972 return ret; 1000 return ret;
973 case TCSETSF2: 1001 case TCSETSF2:
974 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT); 1002 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT);
@@ -987,34 +1015,36 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
987 return set_termios(real_tty, p, TERMIOS_TERMIO); 1015 return set_termios(real_tty, p, TERMIOS_TERMIO);
988#ifndef TCGETS2 1016#ifndef TCGETS2
989 case TIOCGLCKTRMIOS: 1017 case TIOCGLCKTRMIOS:
990 mutex_lock(&real_tty->termios_mutex); 1018 copy_termios_locked(real_tty, &kterm);
991 if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios_locked)) 1019 if (kernel_termios_to_user_termios((struct termios __user *)arg, &kterm))
992 ret = -EFAULT; 1020 ret = -EFAULT;
993 mutex_unlock(&real_tty->termios_mutex);
994 return ret; 1021 return ret;
995 case TIOCSLCKTRMIOS: 1022 case TIOCSLCKTRMIOS:
996 if (!capable(CAP_SYS_ADMIN)) 1023 if (!capable(CAP_SYS_ADMIN))
997 return -EPERM; 1024 return -EPERM;
998 mutex_lock(&real_tty->termios_mutex); 1025 copy_termios_locked(real_tty, &kterm);
999 if (user_termios_to_kernel_termios(real_tty->termios_locked, 1026 if (user_termios_to_kernel_termios(&kterm,
1000 (struct termios __user *) arg)) 1027 (struct termios __user *) arg))
1001 ret = -EFAULT; 1028 return -EFAULT;
1029 mutex_lock(&real_tty->termios_mutex);
1030 memcpy(real_tty->termios_locked, &kterm, sizeof(struct ktermios));
1002 mutex_unlock(&real_tty->termios_mutex); 1031 mutex_unlock(&real_tty->termios_mutex);
1003 return ret; 1032 return 0;
1004#else 1033#else
1005 case TIOCGLCKTRMIOS: 1034 case TIOCGLCKTRMIOS:
1006 mutex_lock(&real_tty->termios_mutex); 1035 copy_termios_locked(real_tty, &kterm);
1007 if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios_locked)) 1036 if (kernel_termios_to_user_termios_1((struct termios __user *)arg, &kterm))
1008 ret = -EFAULT; 1037 ret = -EFAULT;
1009 mutex_unlock(&real_tty->termios_mutex);
1010 return ret; 1038 return ret;
1011 case TIOCSLCKTRMIOS: 1039 case TIOCSLCKTRMIOS:
1012 if (!capable(CAP_SYS_ADMIN)) 1040 if (!capable(CAP_SYS_ADMIN))
1013 ret = -EPERM; 1041 return -EPERM;
1014 mutex_lock(&real_tty->termios_mutex); 1042 copy_termios_locked(real_tty, &kterm);
1015 if (user_termios_to_kernel_termios_1(real_tty->termios_locked, 1043 if (user_termios_to_kernel_termios_1(&kterm,
1016 (struct termios __user *) arg)) 1044 (struct termios __user *) arg))
1017 ret = -EFAULT; 1045 return -EFAULT;
1046 mutex_lock(&real_tty->termios_mutex);
1047 memcpy(real_tty->termios_locked, &kterm, sizeof(struct ktermios));
1018 mutex_unlock(&real_tty->termios_mutex); 1048 mutex_unlock(&real_tty->termios_mutex);
1019 return ret; 1049 return ret;
1020#endif 1050#endif
@@ -1023,9 +1053,10 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
1023 if (real_tty->termiox == NULL) 1053 if (real_tty->termiox == NULL)
1024 return -EINVAL; 1054 return -EINVAL;
1025 mutex_lock(&real_tty->termios_mutex); 1055 mutex_lock(&real_tty->termios_mutex);
1026 if (copy_to_user(p, real_tty->termiox, sizeof(struct termiox))) 1056 memcpy(&ktermx, real_tty->termiox, sizeof(struct termiox));
1027 ret = -EFAULT;
1028 mutex_unlock(&real_tty->termios_mutex); 1057 mutex_unlock(&real_tty->termios_mutex);
1058 if (copy_to_user(p, &ktermx, sizeof(struct termiox)))
1059 ret = -EFAULT;
1029 return ret; 1060 return ret;
1030 case TCSETX: 1061 case TCSETX:
1031 return set_termiox(real_tty, p, 0); 1062 return set_termiox(real_tty, p, 0);
@@ -1035,10 +1066,9 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
1035 return set_termiox(real_tty, p, TERMIOS_FLUSH); 1066 return set_termiox(real_tty, p, TERMIOS_FLUSH);
1036#endif 1067#endif
1037 case TIOCGSOFTCAR: 1068 case TIOCGSOFTCAR:
1038 mutex_lock(&real_tty->termios_mutex); 1069 copy_termios(real_tty, &kterm);
1039 ret = put_user(C_CLOCAL(real_tty) ? 1 : 0, 1070 ret = put_user((kterm.c_cflag & CLOCAL) ? 1 : 0,
1040 (int __user *)arg); 1071 (int __user *)arg);
1041 mutex_unlock(&real_tty->termios_mutex);
1042 return ret; 1072 return ret;
1043 case TIOCSSOFTCAR: 1073 case TIOCSSOFTCAR:
1044 if (get_user(arg, (unsigned int __user *) arg)) 1074 if (get_user(arg, (unsigned int __user *) arg))
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
index f78f5b0127a8..39c8f86dedd4 100644
--- a/drivers/char/tty_ldisc.c
+++ b/drivers/char/tty_ldisc.c
@@ -115,19 +115,22 @@ EXPORT_SYMBOL(tty_unregister_ldisc);
115/** 115/**
116 * tty_ldisc_try_get - try and reference an ldisc 116 * tty_ldisc_try_get - try and reference an ldisc
117 * @disc: ldisc number 117 * @disc: ldisc number
118 * @ld: tty ldisc structure to complete
119 * 118 *
120 * Attempt to open and lock a line discipline into place. Return 119 * Attempt to open and lock a line discipline into place. Return
121 * the line discipline refcounted and assigned in ld. On an error 120 * the line discipline refcounted or an error.
122 * report the error code back
123 */ 121 */
124 122
125static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld) 123static struct tty_ldisc *tty_ldisc_try_get(int disc)
126{ 124{
127 unsigned long flags; 125 unsigned long flags;
126 struct tty_ldisc *ld;
128 struct tty_ldisc_ops *ldops; 127 struct tty_ldisc_ops *ldops;
129 int err = -EINVAL; 128 int err = -EINVAL;
130 129
130 ld = kmalloc(sizeof(struct tty_ldisc), GFP_KERNEL);
131 if (ld == NULL)
132 return ERR_PTR(-ENOMEM);
133
131 spin_lock_irqsave(&tty_ldisc_lock, flags); 134 spin_lock_irqsave(&tty_ldisc_lock, flags);
132 ld->ops = NULL; 135 ld->ops = NULL;
133 ldops = tty_ldiscs[disc]; 136 ldops = tty_ldiscs[disc];
@@ -140,17 +143,19 @@ static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld)
140 /* lock it */ 143 /* lock it */
141 ldops->refcount++; 144 ldops->refcount++;
142 ld->ops = ldops; 145 ld->ops = ldops;
146 ld->refcount = 0;
143 err = 0; 147 err = 0;
144 } 148 }
145 } 149 }
146 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 150 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
147 return err; 151 if (err)
152 return ERR_PTR(err);
153 return ld;
148} 154}
149 155
150/** 156/**
151 * tty_ldisc_get - take a reference to an ldisc 157 * tty_ldisc_get - take a reference to an ldisc
152 * @disc: ldisc number 158 * @disc: ldisc number
153 * @ld: tty line discipline structure to use
154 * 159 *
155 * Takes a reference to a line discipline. Deals with refcounts and 160 * Takes a reference to a line discipline. Deals with refcounts and
156 * module locking counts. Returns NULL if the discipline is not available. 161 * module locking counts. Returns NULL if the discipline is not available.
@@ -161,52 +166,54 @@ static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld)
161 * takes tty_ldisc_lock to guard against ldisc races 166 * takes tty_ldisc_lock to guard against ldisc races
162 */ 167 */
163 168
164static int tty_ldisc_get(int disc, struct tty_ldisc *ld) 169static struct tty_ldisc *tty_ldisc_get(int disc)
165{ 170{
166 int err; 171 struct tty_ldisc *ld;
167 172
168 if (disc < N_TTY || disc >= NR_LDISCS) 173 if (disc < N_TTY || disc >= NR_LDISCS)
169 return -EINVAL; 174 return ERR_PTR(-EINVAL);
170 err = tty_ldisc_try_get(disc, ld); 175 ld = tty_ldisc_try_get(disc);
171 if (err < 0) { 176 if (IS_ERR(ld)) {
172 request_module("tty-ldisc-%d", disc); 177 request_module("tty-ldisc-%d", disc);
173 err = tty_ldisc_try_get(disc, ld); 178 ld = tty_ldisc_try_get(disc);
174 } 179 }
175 return err; 180 return ld;
176} 181}
177 182
178/** 183/**
179 * tty_ldisc_put - drop ldisc reference 184 * tty_ldisc_put - drop ldisc reference
180 * @disc: ldisc number 185 * @ld: ldisc
181 * 186 *
182 * Drop a reference to a line discipline. Manage refcounts and 187 * Drop a reference to a line discipline. Manage refcounts and
183 * module usage counts 188 * module usage counts. Free the ldisc once the recount hits zero.
184 * 189 *
185 * Locking: 190 * Locking:
186 * takes tty_ldisc_lock to guard against ldisc races 191 * takes tty_ldisc_lock to guard against ldisc races
187 */ 192 */
188 193
189static void tty_ldisc_put(struct tty_ldisc_ops *ld) 194static void tty_ldisc_put(struct tty_ldisc *ld)
190{ 195{
191 unsigned long flags; 196 unsigned long flags;
192 int disc = ld->num; 197 int disc = ld->ops->num;
198 struct tty_ldisc_ops *ldo;
193 199
194 BUG_ON(disc < N_TTY || disc >= NR_LDISCS); 200 BUG_ON(disc < N_TTY || disc >= NR_LDISCS);
195 201
196 spin_lock_irqsave(&tty_ldisc_lock, flags); 202 spin_lock_irqsave(&tty_ldisc_lock, flags);
197 ld = tty_ldiscs[disc]; 203 ldo = tty_ldiscs[disc];
198 BUG_ON(ld->refcount == 0); 204 BUG_ON(ldo->refcount == 0);
199 ld->refcount--; 205 ldo->refcount--;
200 module_put(ld->owner); 206 module_put(ldo->owner);
201 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 207 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
208 kfree(ld);
202} 209}
203 210
204static void * tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos) 211static void *tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos)
205{ 212{
206 return (*pos < NR_LDISCS) ? pos : NULL; 213 return (*pos < NR_LDISCS) ? pos : NULL;
207} 214}
208 215
209static void * tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos) 216static void *tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos)
210{ 217{
211 (*pos)++; 218 (*pos)++;
212 return (*pos < NR_LDISCS) ? pos : NULL; 219 return (*pos < NR_LDISCS) ? pos : NULL;
@@ -219,12 +226,13 @@ static void tty_ldiscs_seq_stop(struct seq_file *m, void *v)
219static int tty_ldiscs_seq_show(struct seq_file *m, void *v) 226static int tty_ldiscs_seq_show(struct seq_file *m, void *v)
220{ 227{
221 int i = *(loff_t *)v; 228 int i = *(loff_t *)v;
222 struct tty_ldisc ld; 229 struct tty_ldisc *ld;
223 230
224 if (tty_ldisc_get(i, &ld) < 0) 231 ld = tty_ldisc_try_get(i);
232 if (IS_ERR(ld))
225 return 0; 233 return 0;
226 seq_printf(m, "%-10s %2d\n", ld.ops->name ? ld.ops->name : "???", i); 234 seq_printf(m, "%-10s %2d\n", ld->ops->name ? ld->ops->name : "???", i);
227 tty_ldisc_put(ld.ops); 235 tty_ldisc_put(ld);
228 return 0; 236 return 0;
229} 237}
230 238
@@ -263,8 +271,7 @@ const struct file_operations tty_ldiscs_proc_fops = {
263 271
264static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld) 272static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld)
265{ 273{
266 ld->refcount = 0; 274 tty->ldisc = ld;
267 tty->ldisc = *ld;
268} 275}
269 276
270/** 277/**
@@ -286,7 +293,7 @@ static int tty_ldisc_try(struct tty_struct *tty)
286 int ret = 0; 293 int ret = 0;
287 294
288 spin_lock_irqsave(&tty_ldisc_lock, flags); 295 spin_lock_irqsave(&tty_ldisc_lock, flags);
289 ld = &tty->ldisc; 296 ld = tty->ldisc;
290 if (test_bit(TTY_LDISC, &tty->flags)) { 297 if (test_bit(TTY_LDISC, &tty->flags)) {
291 ld->refcount++; 298 ld->refcount++;
292 ret = 1; 299 ret = 1;
@@ -315,10 +322,9 @@ struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
315{ 322{
316 /* wait_event is a macro */ 323 /* wait_event is a macro */
317 wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); 324 wait_event(tty_ldisc_wait, tty_ldisc_try(tty));
318 WARN_ON(tty->ldisc.refcount == 0); 325 WARN_ON(tty->ldisc->refcount == 0);
319 return &tty->ldisc; 326 return tty->ldisc;
320} 327}
321
322EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait); 328EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
323 329
324/** 330/**
@@ -335,10 +341,9 @@ EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
335struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) 341struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty)
336{ 342{
337 if (tty_ldisc_try(tty)) 343 if (tty_ldisc_try(tty))
338 return &tty->ldisc; 344 return tty->ldisc;
339 return NULL; 345 return NULL;
340} 346}
341
342EXPORT_SYMBOL_GPL(tty_ldisc_ref); 347EXPORT_SYMBOL_GPL(tty_ldisc_ref);
343 348
344/** 349/**
@@ -366,7 +371,6 @@ void tty_ldisc_deref(struct tty_ldisc *ld)
366 wake_up(&tty_ldisc_wait); 371 wake_up(&tty_ldisc_wait);
367 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 372 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
368} 373}
369
370EXPORT_SYMBOL_GPL(tty_ldisc_deref); 374EXPORT_SYMBOL_GPL(tty_ldisc_deref);
371 375
372/** 376/**
@@ -389,6 +393,26 @@ void tty_ldisc_enable(struct tty_struct *tty)
389} 393}
390 394
391/** 395/**
396 * tty_ldisc_flush - flush line discipline queue
397 * @tty: tty
398 *
399 * Flush the line discipline queue (if any) for this tty. If there
400 * is no line discipline active this is a no-op.
401 */
402
403void tty_ldisc_flush(struct tty_struct *tty)
404{
405 struct tty_ldisc *ld = tty_ldisc_ref(tty);
406 if (ld) {
407 if (ld->ops->flush_buffer)
408 ld->ops->flush_buffer(tty);
409 tty_ldisc_deref(ld);
410 }
411 tty_buffer_flush(tty);
412}
413EXPORT_SYMBOL_GPL(tty_ldisc_flush);
414
415/**
392 * tty_set_termios_ldisc - set ldisc field 416 * tty_set_termios_ldisc - set ldisc field
393 * @tty: tty structure 417 * @tty: tty structure
394 * @num: line discipline number 418 * @num: line discipline number
@@ -407,6 +431,39 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
407 mutex_unlock(&tty->termios_mutex); 431 mutex_unlock(&tty->termios_mutex);
408} 432}
409 433
434/**
435 * tty_ldisc_open - open a line discipline
436 * @tty: tty we are opening the ldisc on
437 * @ld: discipline to open
438 *
439 * A helper opening method. Also a convenient debugging and check
440 * point.
441 */
442
443static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
444{
445 WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags));
446 if (ld->ops->open)
447 return ld->ops->open(tty);
448 return 0;
449}
450
451/**
452 * tty_ldisc_close - close a line discipline
453 * @tty: tty we are opening the ldisc on
454 * @ld: discipline to close
455 *
456 * A helper close method. Also a convenient debugging and check
457 * point.
458 */
459
460static void tty_ldisc_close(struct tty_struct *tty, struct tty_ldisc *ld)
461{
462 WARN_ON(!test_bit(TTY_LDISC_OPEN, &tty->flags));
463 clear_bit(TTY_LDISC_OPEN, &tty->flags);
464 if (ld->ops->close)
465 ld->ops->close(tty);
466}
410 467
411/** 468/**
412 * tty_ldisc_restore - helper for tty ldisc change 469 * tty_ldisc_restore - helper for tty ldisc change
@@ -420,66 +477,136 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
420static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old) 477static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
421{ 478{
422 char buf[64]; 479 char buf[64];
423 struct tty_ldisc new_ldisc; 480 struct tty_ldisc *new_ldisc;
481 int r;
424 482
425 /* There is an outstanding reference here so this is safe */ 483 /* There is an outstanding reference here so this is safe */
426 tty_ldisc_get(old->ops->num, old); 484 old = tty_ldisc_get(old->ops->num);
485 WARN_ON(IS_ERR(old));
427 tty_ldisc_assign(tty, old); 486 tty_ldisc_assign(tty, old);
428 tty_set_termios_ldisc(tty, old->ops->num); 487 tty_set_termios_ldisc(tty, old->ops->num);
429 if (old->ops->open && (old->ops->open(tty) < 0)) { 488 if (tty_ldisc_open(tty, old) < 0) {
430 tty_ldisc_put(old->ops); 489 tty_ldisc_put(old);
431 /* This driver is always present */ 490 /* This driver is always present */
432 if (tty_ldisc_get(N_TTY, &new_ldisc) < 0) 491 new_ldisc = tty_ldisc_get(N_TTY);
492 if (IS_ERR(new_ldisc))
433 panic("n_tty: get"); 493 panic("n_tty: get");
434 tty_ldisc_assign(tty, &new_ldisc); 494 tty_ldisc_assign(tty, new_ldisc);
435 tty_set_termios_ldisc(tty, N_TTY); 495 tty_set_termios_ldisc(tty, N_TTY);
436 if (new_ldisc.ops->open) { 496 r = tty_ldisc_open(tty, new_ldisc);
437 int r = new_ldisc.ops->open(tty); 497 if (r < 0)
438 if (r < 0) 498 panic("Couldn't open N_TTY ldisc for "
439 panic("Couldn't open N_TTY ldisc for " 499 "%s --- error %d.",
440 "%s --- error %d.", 500 tty_name(tty, buf), r);
441 tty_name(tty, buf), r);
442 }
443 } 501 }
444} 502}
445 503
446/** 504/**
505 * tty_ldisc_halt - shut down the line discipline
506 * @tty: tty device
507 *
508 * Shut down the line discipline and work queue for this tty device.
509 * The TTY_LDISC flag being cleared ensures no further references can
510 * be obtained while the delayed work queue halt ensures that no more
511 * data is fed to the ldisc.
512 *
513 * In order to wait for any existing references to complete see
514 * tty_ldisc_wait_idle.
515 */
516
517static int tty_ldisc_halt(struct tty_struct *tty)
518{
519 clear_bit(TTY_LDISC, &tty->flags);
520 return cancel_delayed_work(&tty->buf.work);
521}
522
523/**
524 * tty_ldisc_wait_idle - wait for the ldisc to become idle
525 * @tty: tty to wait for
526 *
527 * Wait for the line discipline to become idle. The discipline must
528 * have been halted for this to guarantee it remains idle.
529 *
530 * tty_ldisc_lock protects the ref counts currently.
531 */
532
533static int tty_ldisc_wait_idle(struct tty_struct *tty)
534{
535 unsigned long flags;
536 spin_lock_irqsave(&tty_ldisc_lock, flags);
537 while (tty->ldisc->refcount) {
538 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
539 if (wait_event_timeout(tty_ldisc_wait,
540 tty->ldisc->refcount == 0, 5 * HZ) == 0)
541 return -EBUSY;
542 spin_lock_irqsave(&tty_ldisc_lock, flags);
543 }
544 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
545 return 0;
546}
547
548/**
447 * tty_set_ldisc - set line discipline 549 * tty_set_ldisc - set line discipline
448 * @tty: the terminal to set 550 * @tty: the terminal to set
449 * @ldisc: the line discipline 551 * @ldisc: the line discipline
450 * 552 *
451 * Set the discipline of a tty line. Must be called from a process 553 * Set the discipline of a tty line. Must be called from a process
452 * context. 554 * context. The ldisc change logic has to protect itself against any
555 * overlapping ldisc change (including on the other end of pty pairs),
556 * the close of one side of a tty/pty pair, and eventually hangup.
453 * 557 *
454 * Locking: takes tty_ldisc_lock. 558 * Locking: takes tty_ldisc_lock, termios_mutex
455 * called functions take termios_mutex
456 */ 559 */
457 560
458int tty_set_ldisc(struct tty_struct *tty, int ldisc) 561int tty_set_ldisc(struct tty_struct *tty, int ldisc)
459{ 562{
460 int retval; 563 int retval;
461 struct tty_ldisc o_ldisc, new_ldisc; 564 struct tty_ldisc *o_ldisc, *new_ldisc;
462 int work; 565 int work, o_work = 0;
463 unsigned long flags;
464 struct tty_struct *o_tty; 566 struct tty_struct *o_tty;
465 567
466restart: 568 new_ldisc = tty_ldisc_get(ldisc);
467 /* This is a bit ugly for now but means we can break the 'ldisc 569 if (IS_ERR(new_ldisc))
468 is part of the tty struct' assumption later */ 570 return PTR_ERR(new_ldisc);
469 retval = tty_ldisc_get(ldisc, &new_ldisc); 571
470 if (retval) 572 /*
471 return retval; 573 * We need to look at the tty locking here for pty/tty pairs
574 * when both sides try to change in parallel.
575 */
576
577 o_tty = tty->link; /* o_tty is the pty side or NULL */
578
579
580 /*
581 * Check the no-op case
582 */
583
584 if (tty->ldisc->ops->num == ldisc) {
585 tty_ldisc_put(new_ldisc);
586 return 0;
587 }
472 588
473 /* 589 /*
474 * Problem: What do we do if this blocks ? 590 * Problem: What do we do if this blocks ?
591 * We could deadlock here
475 */ 592 */
476 593
477 tty_wait_until_sent(tty, 0); 594 tty_wait_until_sent(tty, 0);
478 595
479 if (tty->ldisc.ops->num == ldisc) { 596 mutex_lock(&tty->ldisc_mutex);
480 tty_ldisc_put(new_ldisc.ops); 597
481 return 0; 598 /*
599 * We could be midstream of another ldisc change which has
600 * dropped the lock during processing. If so we need to wait.
601 */
602
603 while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) {
604 mutex_unlock(&tty->ldisc_mutex);
605 wait_event(tty_ldisc_wait,
606 test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0);
607 mutex_lock(&tty->ldisc_mutex);
482 } 608 }
609 set_bit(TTY_LDISC_CHANGING, &tty->flags);
483 610
484 /* 611 /*
485 * No more input please, we are switching. The new ldisc 612 * No more input please, we are switching. The new ldisc
@@ -489,8 +616,6 @@ restart:
489 tty->receive_room = 0; 616 tty->receive_room = 0;
490 617
491 o_ldisc = tty->ldisc; 618 o_ldisc = tty->ldisc;
492 o_tty = tty->link;
493
494 /* 619 /*
495 * Make sure we don't change while someone holds a 620 * Make sure we don't change while someone holds a
496 * reference to the line discipline. The TTY_LDISC bit 621 * reference to the line discipline. The TTY_LDISC bit
@@ -501,108 +626,181 @@ restart:
501 * with a userspace app continually trying to use the tty in 626 * with a userspace app continually trying to use the tty in
502 * parallel to the change and re-referencing the tty. 627 * parallel to the change and re-referencing the tty.
503 */ 628 */
504 clear_bit(TTY_LDISC, &tty->flags);
505 if (o_tty)
506 clear_bit(TTY_LDISC, &o_tty->flags);
507 629
508 spin_lock_irqsave(&tty_ldisc_lock, flags); 630 work = tty_ldisc_halt(tty);
509 if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) {
510 if (tty->ldisc.refcount) {
511 /* Free the new ldisc we grabbed. Must drop the lock
512 first. */
513 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
514 tty_ldisc_put(o_ldisc.ops);
515 /*
516 * There are several reasons we may be busy, including
517 * random momentary I/O traffic. We must therefore
518 * retry. We could distinguish between blocking ops
519 * and retries if we made tty_ldisc_wait() smarter.
520 * That is up for discussion.
521 */
522 if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0)
523 return -ERESTARTSYS;
524 goto restart;
525 }
526 if (o_tty && o_tty->ldisc.refcount) {
527 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
528 tty_ldisc_put(o_tty->ldisc.ops);
529 if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount == 0) < 0)
530 return -ERESTARTSYS;
531 goto restart;
532 }
533 }
534 /*
535 * If the TTY_LDISC bit is set, then we are racing against
536 * another ldisc change
537 */
538 if (test_bit(TTY_LDISC_CHANGING, &tty->flags)) {
539 struct tty_ldisc *ld;
540 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
541 tty_ldisc_put(new_ldisc.ops);
542 ld = tty_ldisc_ref_wait(tty);
543 tty_ldisc_deref(ld);
544 goto restart;
545 }
546 /*
547 * This flag is used to avoid two parallel ldisc changes. Once
548 * open and close are fine grained locked this may work better
549 * as a mutex shared with the open/close/hup paths
550 */
551 set_bit(TTY_LDISC_CHANGING, &tty->flags);
552 if (o_tty) 631 if (o_tty)
553 set_bit(TTY_LDISC_CHANGING, &o_tty->flags); 632 o_work = tty_ldisc_halt(o_tty);
554 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
555
556 /*
557 * From this point on we know nobody has an ldisc
558 * usage reference, nor can they obtain one until
559 * we say so later on.
560 */
561 633
562 work = cancel_delayed_work(&tty->buf.work);
563 /* 634 /*
564 * Wait for ->hangup_work and ->buf.work handlers to terminate 635 * Wait for ->hangup_work and ->buf.work handlers to terminate.
565 * MUST NOT hold locks here. 636 * We must drop the mutex here in case a hangup is also in process.
566 */ 637 */
638
639 mutex_unlock(&tty->ldisc_mutex);
640
567 flush_scheduled_work(); 641 flush_scheduled_work();
642
643 /* Let any existing reference holders finish */
644 retval = tty_ldisc_wait_idle(tty);
645 if (retval < 0) {
646 clear_bit(TTY_LDISC_CHANGING, &tty->flags);
647 tty_ldisc_put(new_ldisc);
648 return retval;
649 }
650
651 mutex_lock(&tty->ldisc_mutex);
652 if (test_bit(TTY_HUPPED, &tty->flags)) {
653 /* We were raced by the hangup method. It will have stomped
654 the ldisc data and closed the ldisc down */
655 clear_bit(TTY_LDISC_CHANGING, &tty->flags);
656 mutex_unlock(&tty->ldisc_mutex);
657 tty_ldisc_put(new_ldisc);
658 return -EIO;
659 }
660
568 /* Shutdown the current discipline. */ 661 /* Shutdown the current discipline. */
569 if (o_ldisc.ops->close) 662 tty_ldisc_close(tty, o_ldisc);
570 (o_ldisc.ops->close)(tty);
571 663
572 /* Now set up the new line discipline. */ 664 /* Now set up the new line discipline. */
573 tty_ldisc_assign(tty, &new_ldisc); 665 tty_ldisc_assign(tty, new_ldisc);
574 tty_set_termios_ldisc(tty, ldisc); 666 tty_set_termios_ldisc(tty, ldisc);
575 if (new_ldisc.ops->open) 667
576 retval = (new_ldisc.ops->open)(tty); 668 retval = tty_ldisc_open(tty, new_ldisc);
577 if (retval < 0) { 669 if (retval < 0) {
578 tty_ldisc_put(new_ldisc.ops); 670 /* Back to the old one or N_TTY if we can't */
579 tty_ldisc_restore(tty, &o_ldisc); 671 tty_ldisc_put(new_ldisc);
672 tty_ldisc_restore(tty, o_ldisc);
580 } 673 }
674
581 /* At this point we hold a reference to the new ldisc and a 675 /* At this point we hold a reference to the new ldisc and a
582 a reference to the old ldisc. If we ended up flipping back 676 a reference to the old ldisc. If we ended up flipping back
583 to the existing ldisc we have two references to it */ 677 to the existing ldisc we have two references to it */
584 678
585 if (tty->ldisc.ops->num != o_ldisc.ops->num && tty->ops->set_ldisc) 679 if (tty->ldisc->ops->num != o_ldisc->ops->num && tty->ops->set_ldisc)
586 tty->ops->set_ldisc(tty); 680 tty->ops->set_ldisc(tty);
587 681
588 tty_ldisc_put(o_ldisc.ops); 682 tty_ldisc_put(o_ldisc);
589 683
590 /* 684 /*
591 * Allow ldisc referencing to occur as soon as the driver 685 * Allow ldisc referencing to occur again
592 * ldisc callback completes.
593 */ 686 */
594 687
595 tty_ldisc_enable(tty); 688 tty_ldisc_enable(tty);
596 if (o_tty) 689 if (o_tty)
597 tty_ldisc_enable(o_tty); 690 tty_ldisc_enable(o_tty);
598 691
599 /* Restart it in case no characters kick it off. Safe if 692 /* Restart the work queue in case no characters kick it off. Safe if
600 already running */ 693 already running */
601 if (work) 694 if (work)
602 schedule_delayed_work(&tty->buf.work, 1); 695 schedule_delayed_work(&tty->buf.work, 1);
696 if (o_work)
697 schedule_delayed_work(&o_tty->buf.work, 1);
698 mutex_unlock(&tty->ldisc_mutex);
603 return retval; 699 return retval;
604} 700}
605 701
702/**
703 * tty_reset_termios - reset terminal state
704 * @tty: tty to reset
705 *
706 * Restore a terminal to the driver default state.
707 */
708
709static void tty_reset_termios(struct tty_struct *tty)
710{
711 mutex_lock(&tty->termios_mutex);
712 *tty->termios = tty->driver->init_termios;
713 tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios);
714 tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
715 mutex_unlock(&tty->termios_mutex);
716}
717
718
719/**
720 * tty_ldisc_reinit - reinitialise the tty ldisc
721 * @tty: tty to reinit
722 *
723 * Switch the tty back to N_TTY line discipline and leave the
724 * ldisc state closed
725 */
726
727static void tty_ldisc_reinit(struct tty_struct *tty)
728{
729 struct tty_ldisc *ld;
730
731 tty_ldisc_close(tty, tty->ldisc);
732 tty_ldisc_put(tty->ldisc);
733 tty->ldisc = NULL;
734 /*
735 * Switch the line discipline back
736 */
737 ld = tty_ldisc_get(N_TTY);
738 BUG_ON(IS_ERR(ld));
739 tty_ldisc_assign(tty, ld);
740 tty_set_termios_ldisc(tty, N_TTY);
741}
742
743/**
744 * tty_ldisc_hangup - hangup ldisc reset
745 * @tty: tty being hung up
746 *
747 * Some tty devices reset their termios when they receive a hangup
748 * event. In that situation we must also switch back to N_TTY properly
749 * before we reset the termios data.
750 *
751 * Locking: We can take the ldisc mutex as the rest of the code is
752 * careful to allow for this.
753 *
754 * In the pty pair case this occurs in the close() path of the
755 * tty itself so we must be careful about locking rules.
756 */
757
758void tty_ldisc_hangup(struct tty_struct *tty)
759{
760 struct tty_ldisc *ld;
761
762 /*
763 * FIXME! What are the locking issues here? This may me overdoing
764 * things... This question is especially important now that we've
765 * removed the irqlock.
766 */
767 ld = tty_ldisc_ref(tty);
768 if (ld != NULL) {
769 /* We may have no line discipline at this point */
770 if (ld->ops->flush_buffer)
771 ld->ops->flush_buffer(tty);
772 tty_driver_flush_buffer(tty);
773 if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) &&
774 ld->ops->write_wakeup)
775 ld->ops->write_wakeup(tty);
776 if (ld->ops->hangup)
777 ld->ops->hangup(tty);
778 tty_ldisc_deref(ld);
779 }
780 /*
781 * FIXME: Once we trust the LDISC code better we can wait here for
782 * ldisc completion and fix the driver call race
783 */
784 wake_up_interruptible_poll(&tty->write_wait, POLLOUT);
785 wake_up_interruptible_poll(&tty->read_wait, POLLIN);
786 /*
787 * Shutdown the current line discipline, and reset it to
788 * N_TTY.
789 */
790 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) {
791 /* Avoid racing set_ldisc */
792 mutex_lock(&tty->ldisc_mutex);
793 /* Switch back to N_TTY */
794 tty_ldisc_reinit(tty);
795 /* At this point we have a closed ldisc and we want to
796 reopen it. We could defer this to the next open but
797 it means auditing a lot of other paths so this is a FIXME */
798 WARN_ON(tty_ldisc_open(tty, tty->ldisc));
799 tty_ldisc_enable(tty);
800 mutex_unlock(&tty->ldisc_mutex);
801 tty_reset_termios(tty);
802 }
803}
606 804
607/** 805/**
608 * tty_ldisc_setup - open line discipline 806 * tty_ldisc_setup - open line discipline
@@ -610,24 +808,23 @@ restart:
610 * @o_tty: pair tty for pty/tty pairs 808 * @o_tty: pair tty for pty/tty pairs
611 * 809 *
612 * Called during the initial open of a tty/pty pair in order to set up the 810 * Called during the initial open of a tty/pty pair in order to set up the
613 * line discplines and bind them to the tty. 811 * line disciplines and bind them to the tty. This has no locking issues
812 * as the device isn't yet active.
614 */ 813 */
615 814
616int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty) 815int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
617{ 816{
618 struct tty_ldisc *ld = &tty->ldisc; 817 struct tty_ldisc *ld = tty->ldisc;
619 int retval; 818 int retval;
620 819
621 if (ld->ops->open) { 820 retval = tty_ldisc_open(tty, ld);
622 retval = (ld->ops->open)(tty); 821 if (retval)
623 if (retval) 822 return retval;
624 return retval; 823
625 } 824 if (o_tty) {
626 if (o_tty && o_tty->ldisc.ops->open) { 825 retval = tty_ldisc_open(o_tty, o_tty->ldisc);
627 retval = (o_tty->ldisc.ops->open)(o_tty);
628 if (retval) { 826 if (retval) {
629 if (ld->ops->close) 827 tty_ldisc_close(tty, ld);
630 (ld->ops->close)(tty);
631 return retval; 828 return retval;
632 } 829 }
633 tty_ldisc_enable(o_tty); 830 tty_ldisc_enable(o_tty);
@@ -635,32 +832,25 @@ int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
635 tty_ldisc_enable(tty); 832 tty_ldisc_enable(tty);
636 return 0; 833 return 0;
637} 834}
638
639/** 835/**
640 * tty_ldisc_release - release line discipline 836 * tty_ldisc_release - release line discipline
641 * @tty: tty being shut down 837 * @tty: tty being shut down
642 * @o_tty: pair tty for pty/tty pairs 838 * @o_tty: pair tty for pty/tty pairs
643 * 839 *
644 * Called during the final close of a tty/pty pair in order to shut down the 840 * Called during the final close of a tty/pty pair in order to shut down
645 * line discpline layer. 841 * the line discpline layer. On exit the ldisc assigned is N_TTY and the
842 * ldisc has not been opened.
646 */ 843 */
647 844
648void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) 845void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
649{ 846{
650 unsigned long flags;
651 struct tty_ldisc ld;
652 /* 847 /*
653 * Prevent flush_to_ldisc() from rescheduling the work for later. Then 848 * Prevent flush_to_ldisc() from rescheduling the work for later. Then
654 * kill any delayed work. As this is the final close it does not 849 * kill any delayed work. As this is the final close it does not
655 * race with the set_ldisc code path. 850 * race with the set_ldisc code path.
656 */ 851 */
657 clear_bit(TTY_LDISC, &tty->flags);
658 cancel_delayed_work(&tty->buf.work);
659
660 /*
661 * Wait for ->hangup_work and ->buf.work handlers to terminate
662 */
663 852
853 tty_ldisc_halt(tty);
664 flush_scheduled_work(); 854 flush_scheduled_work();
665 855
666 /* 856 /*
@@ -668,38 +858,19 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
668 * side waiters as the file is closing so user count on the file 858 * side waiters as the file is closing so user count on the file
669 * side is zero. 859 * side is zero.
670 */ 860 */
671 spin_lock_irqsave(&tty_ldisc_lock, flags); 861
672 while (tty->ldisc.refcount) { 862 tty_ldisc_wait_idle(tty);
673 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 863
674 wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0);
675 spin_lock_irqsave(&tty_ldisc_lock, flags);
676 }
677 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
678 /* 864 /*
679 * Shutdown the current line discipline, and reset it to N_TTY. 865 * Shutdown the current line discipline, and reset it to N_TTY.
680 * 866 *
681 * FIXME: this MUST get fixed for the new reflocking 867 * FIXME: this MUST get fixed for the new reflocking
682 */ 868 */
683 if (tty->ldisc.ops->close)
684 (tty->ldisc.ops->close)(tty);
685 tty_ldisc_put(tty->ldisc.ops);
686 869
687 /* 870 tty_ldisc_reinit(tty);
688 * Switch the line discipline back 871 /* This will need doing differently if we need to lock */
689 */ 872 if (o_tty)
690 WARN_ON(tty_ldisc_get(N_TTY, &ld)); 873 tty_ldisc_release(o_tty, NULL);
691 tty_ldisc_assign(tty, &ld);
692 tty_set_termios_ldisc(tty, N_TTY);
693 if (o_tty) {
694 /* FIXME: could o_tty be in setldisc here ? */
695 clear_bit(TTY_LDISC, &o_tty->flags);
696 if (o_tty->ldisc.ops->close)
697 (o_tty->ldisc.ops->close)(o_tty);
698 tty_ldisc_put(o_tty->ldisc.ops);
699 WARN_ON(tty_ldisc_get(N_TTY, &ld));
700 tty_ldisc_assign(o_tty, &ld);
701 tty_set_termios_ldisc(o_tty, N_TTY);
702 }
703} 874}
704 875
705/** 876/**
@@ -712,10 +883,10 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
712 883
713void tty_ldisc_init(struct tty_struct *tty) 884void tty_ldisc_init(struct tty_struct *tty)
714{ 885{
715 struct tty_ldisc ld; 886 struct tty_ldisc *ld = tty_ldisc_get(N_TTY);
716 if (tty_ldisc_get(N_TTY, &ld) < 0) 887 if (IS_ERR(ld))
717 panic("n_tty: init_tty"); 888 panic("n_tty: init_tty");
718 tty_ldisc_assign(tty, &ld); 889 tty_ldisc_assign(tty, ld);
719} 890}
720 891
721void tty_ldisc_begin(void) 892void tty_ldisc_begin(void)
diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c
index 9b8004c72686..62dadfc95e34 100644
--- a/drivers/char/tty_port.c
+++ b/drivers/char/tty_port.c
@@ -137,7 +137,7 @@ int tty_port_carrier_raised(struct tty_port *port)
137EXPORT_SYMBOL(tty_port_carrier_raised); 137EXPORT_SYMBOL(tty_port_carrier_raised);
138 138
139/** 139/**
140 * tty_port_raise_dtr_rts - Riase DTR/RTS 140 * tty_port_raise_dtr_rts - Raise DTR/RTS
141 * @port: tty port 141 * @port: tty port
142 * 142 *
143 * Wrapper for the DTR/RTS raise logic. For the moment this is used 143 * Wrapper for the DTR/RTS raise logic. For the moment this is used
@@ -147,12 +147,28 @@ EXPORT_SYMBOL(tty_port_carrier_raised);
147 147
148void tty_port_raise_dtr_rts(struct tty_port *port) 148void tty_port_raise_dtr_rts(struct tty_port *port)
149{ 149{
150 if (port->ops->raise_dtr_rts) 150 if (port->ops->dtr_rts)
151 port->ops->raise_dtr_rts(port); 151 port->ops->dtr_rts(port, 1);
152} 152}
153EXPORT_SYMBOL(tty_port_raise_dtr_rts); 153EXPORT_SYMBOL(tty_port_raise_dtr_rts);
154 154
155/** 155/**
156 * tty_port_lower_dtr_rts - Lower DTR/RTS
157 * @port: tty port
158 *
159 * Wrapper for the DTR/RTS raise logic. For the moment this is used
160 * to hide some internal details. This will eventually become entirely
161 * internal to the tty port.
162 */
163
164void tty_port_lower_dtr_rts(struct tty_port *port)
165{
166 if (port->ops->dtr_rts)
167 port->ops->dtr_rts(port, 0);
168}
169EXPORT_SYMBOL(tty_port_lower_dtr_rts);
170
171/**
156 * tty_port_block_til_ready - Waiting logic for tty open 172 * tty_port_block_til_ready - Waiting logic for tty open
157 * @port: the tty port being opened 173 * @port: the tty port being opened
158 * @tty: the tty device being bound 174 * @tty: the tty device being bound
@@ -167,7 +183,7 @@ EXPORT_SYMBOL(tty_port_raise_dtr_rts);
167 * - port flags and counts 183 * - port flags and counts
168 * 184 *
169 * The passed tty_port must implement the carrier_raised method if it can 185 * The passed tty_port must implement the carrier_raised method if it can
170 * do carrier detect and the raise_dtr_rts method if it supports software 186 * do carrier detect and the dtr_rts method if it supports software
171 * management of these lines. Note that the dtr/rts raise is done each 187 * management of these lines. Note that the dtr/rts raise is done each
172 * iteration as a hangup may have previously dropped them while we wait. 188 * iteration as a hangup may have previously dropped them while we wait.
173 */ 189 */
@@ -182,7 +198,8 @@ int tty_port_block_til_ready(struct tty_port *port,
182 198
183 /* block if port is in the process of being closed */ 199 /* block if port is in the process of being closed */
184 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { 200 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
185 interruptible_sleep_on(&port->close_wait); 201 wait_event_interruptible(port->close_wait,
202 !(port->flags & ASYNC_CLOSING));
186 if (port->flags & ASYNC_HUP_NOTIFY) 203 if (port->flags & ASYNC_HUP_NOTIFY)
187 return -EAGAIN; 204 return -EAGAIN;
188 else 205 else
@@ -205,7 +222,6 @@ int tty_port_block_til_ready(struct tty_port *port,
205 before the next open may complete */ 222 before the next open may complete */
206 223
207 retval = 0; 224 retval = 0;
208 add_wait_queue(&port->open_wait, &wait);
209 225
210 /* The port lock protects the port counts */ 226 /* The port lock protects the port counts */
211 spin_lock_irqsave(&port->lock, flags); 227 spin_lock_irqsave(&port->lock, flags);
@@ -219,7 +235,7 @@ int tty_port_block_til_ready(struct tty_port *port,
219 if (tty->termios->c_cflag & CBAUD) 235 if (tty->termios->c_cflag & CBAUD)
220 tty_port_raise_dtr_rts(port); 236 tty_port_raise_dtr_rts(port);
221 237
222 set_current_state(TASK_INTERRUPTIBLE); 238 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE);
223 /* Check for a hangup or uninitialised port. Return accordingly */ 239 /* Check for a hangup or uninitialised port. Return accordingly */
224 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { 240 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) {
225 if (port->flags & ASYNC_HUP_NOTIFY) 241 if (port->flags & ASYNC_HUP_NOTIFY)
@@ -240,8 +256,7 @@ int tty_port_block_til_ready(struct tty_port *port,
240 } 256 }
241 schedule(); 257 schedule();
242 } 258 }
243 set_current_state(TASK_RUNNING); 259 finish_wait(&port->open_wait, &wait);
244 remove_wait_queue(&port->open_wait, &wait);
245 260
246 /* Update counts. A parallel hangup will have set count to zero and 261 /* Update counts. A parallel hangup will have set count to zero and
247 we must not mess that up further */ 262 we must not mess that up further */
@@ -292,6 +307,17 @@ int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct f
292 if (port->flags & ASYNC_INITIALIZED && 307 if (port->flags & ASYNC_INITIALIZED &&
293 port->closing_wait != ASYNC_CLOSING_WAIT_NONE) 308 port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
294 tty_wait_until_sent(tty, port->closing_wait); 309 tty_wait_until_sent(tty, port->closing_wait);
310 if (port->drain_delay) {
311 unsigned int bps = tty_get_baud_rate(tty);
312 long timeout;
313
314 if (bps > 1200)
315 timeout = max_t(long, (HZ * 10 * port->drain_delay) / bps,
316 HZ / 10);
317 else
318 timeout = 2 * HZ;
319 schedule_timeout_interruptible(timeout);
320 }
295 return 1; 321 return 1;
296} 322}
297EXPORT_SYMBOL(tty_port_close_start); 323EXPORT_SYMBOL(tty_port_close_start);
@@ -302,6 +328,9 @@ void tty_port_close_end(struct tty_port *port, struct tty_struct *tty)
302 328
303 tty_ldisc_flush(tty); 329 tty_ldisc_flush(tty);
304 330
331 if (tty->termios->c_cflag & HUPCL)
332 tty_port_lower_dtr_rts(port);
333
305 spin_lock_irqsave(&port->lock, flags); 334 spin_lock_irqsave(&port->lock, flags);
306 tty->closing = 0; 335 tty->closing = 0;
307 336
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index 1efb2879a94f..eef216f7f61d 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -3,3 +3,5 @@ obj-$(CONFIG_X86_CYCLONE_TIMER) += cyclone.o
3obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o 3obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o
4obj-$(CONFIG_SCx200HR_TIMER) += scx200_hrt.o 4obj-$(CONFIG_SCx200HR_TIMER) += scx200_hrt.o
5obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o 5obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o
6obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o
7obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o
diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c
index 1c92c39a53aa..cf56a2af5fe1 100644
--- a/drivers/clocksource/sh_cmt.c
+++ b/drivers/clocksource/sh_cmt.c
@@ -18,7 +18,6 @@
18 */ 18 */
19 19
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/bootmem.h>
22#include <linux/platform_device.h> 21#include <linux/platform_device.h>
23#include <linux/spinlock.h> 22#include <linux/spinlock.h>
24#include <linux/interrupt.h> 23#include <linux/interrupt.h>
@@ -29,7 +28,7 @@
29#include <linux/err.h> 28#include <linux/err.h>
30#include <linux/clocksource.h> 29#include <linux/clocksource.h>
31#include <linux/clockchips.h> 30#include <linux/clockchips.h>
32#include <linux/sh_cmt.h> 31#include <linux/sh_timer.h>
33 32
34struct sh_cmt_priv { 33struct sh_cmt_priv {
35 void __iomem *mapbase; 34 void __iomem *mapbase;
@@ -47,6 +46,7 @@ struct sh_cmt_priv {
47 unsigned long rate; 46 unsigned long rate;
48 spinlock_t lock; 47 spinlock_t lock;
49 struct clock_event_device ced; 48 struct clock_event_device ced;
49 struct clocksource cs;
50 unsigned long total_cycles; 50 unsigned long total_cycles;
51}; 51};
52 52
@@ -59,7 +59,7 @@ static DEFINE_SPINLOCK(sh_cmt_lock);
59 59
60static inline unsigned long sh_cmt_read(struct sh_cmt_priv *p, int reg_nr) 60static inline unsigned long sh_cmt_read(struct sh_cmt_priv *p, int reg_nr)
61{ 61{
62 struct sh_cmt_config *cfg = p->pdev->dev.platform_data; 62 struct sh_timer_config *cfg = p->pdev->dev.platform_data;
63 void __iomem *base = p->mapbase; 63 void __iomem *base = p->mapbase;
64 unsigned long offs; 64 unsigned long offs;
65 65
@@ -83,7 +83,7 @@ static inline unsigned long sh_cmt_read(struct sh_cmt_priv *p, int reg_nr)
83static inline void sh_cmt_write(struct sh_cmt_priv *p, int reg_nr, 83static inline void sh_cmt_write(struct sh_cmt_priv *p, int reg_nr,
84 unsigned long value) 84 unsigned long value)
85{ 85{
86 struct sh_cmt_config *cfg = p->pdev->dev.platform_data; 86 struct sh_timer_config *cfg = p->pdev->dev.platform_data;
87 void __iomem *base = p->mapbase; 87 void __iomem *base = p->mapbase;
88 unsigned long offs; 88 unsigned long offs;
89 89
@@ -110,23 +110,28 @@ static unsigned long sh_cmt_get_counter(struct sh_cmt_priv *p,
110 int *has_wrapped) 110 int *has_wrapped)
111{ 111{
112 unsigned long v1, v2, v3; 112 unsigned long v1, v2, v3;
113 int o1, o2;
114
115 o1 = sh_cmt_read(p, CMCSR) & p->overflow_bit;
113 116
114 /* Make sure the timer value is stable. Stolen from acpi_pm.c */ 117 /* Make sure the timer value is stable. Stolen from acpi_pm.c */
115 do { 118 do {
119 o2 = o1;
116 v1 = sh_cmt_read(p, CMCNT); 120 v1 = sh_cmt_read(p, CMCNT);
117 v2 = sh_cmt_read(p, CMCNT); 121 v2 = sh_cmt_read(p, CMCNT);
118 v3 = sh_cmt_read(p, CMCNT); 122 v3 = sh_cmt_read(p, CMCNT);
119 } while (unlikely((v1 > v2 && v1 < v3) || (v2 > v3 && v2 < v1) 123 o1 = sh_cmt_read(p, CMCSR) & p->overflow_bit;
120 || (v3 > v1 && v3 < v2))); 124 } while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3)
125 || (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2)));
121 126
122 *has_wrapped = sh_cmt_read(p, CMCSR) & p->overflow_bit; 127 *has_wrapped = o1;
123 return v2; 128 return v2;
124} 129}
125 130
126 131
127static void sh_cmt_start_stop_ch(struct sh_cmt_priv *p, int start) 132static void sh_cmt_start_stop_ch(struct sh_cmt_priv *p, int start)
128{ 133{
129 struct sh_cmt_config *cfg = p->pdev->dev.platform_data; 134 struct sh_timer_config *cfg = p->pdev->dev.platform_data;
130 unsigned long flags, value; 135 unsigned long flags, value;
131 136
132 /* start stop register shared by multiple timer channels */ 137 /* start stop register shared by multiple timer channels */
@@ -144,7 +149,7 @@ static void sh_cmt_start_stop_ch(struct sh_cmt_priv *p, int start)
144 149
145static int sh_cmt_enable(struct sh_cmt_priv *p, unsigned long *rate) 150static int sh_cmt_enable(struct sh_cmt_priv *p, unsigned long *rate)
146{ 151{
147 struct sh_cmt_config *cfg = p->pdev->dev.platform_data; 152 struct sh_timer_config *cfg = p->pdev->dev.platform_data;
148 int ret; 153 int ret;
149 154
150 /* enable clock */ 155 /* enable clock */
@@ -153,16 +158,18 @@ static int sh_cmt_enable(struct sh_cmt_priv *p, unsigned long *rate)
153 pr_err("sh_cmt: cannot enable clock \"%s\"\n", cfg->clk); 158 pr_err("sh_cmt: cannot enable clock \"%s\"\n", cfg->clk);
154 return ret; 159 return ret;
155 } 160 }
156 *rate = clk_get_rate(p->clk) / 8;
157 161
158 /* make sure channel is disabled */ 162 /* make sure channel is disabled */
159 sh_cmt_start_stop_ch(p, 0); 163 sh_cmt_start_stop_ch(p, 0);
160 164
161 /* configure channel, periodic mode and maximum timeout */ 165 /* configure channel, periodic mode and maximum timeout */
162 if (p->width == 16) 166 if (p->width == 16) {
163 sh_cmt_write(p, CMCSR, 0); 167 *rate = clk_get_rate(p->clk) / 512;
164 else 168 sh_cmt_write(p, CMCSR, 0x43);
169 } else {
170 *rate = clk_get_rate(p->clk) / 8;
165 sh_cmt_write(p, CMCSR, 0x01a4); 171 sh_cmt_write(p, CMCSR, 0x01a4);
172 }
166 173
167 sh_cmt_write(p, CMCOR, 0xffffffff); 174 sh_cmt_write(p, CMCOR, 0xffffffff);
168 sh_cmt_write(p, CMCNT, 0); 175 sh_cmt_write(p, CMCNT, 0);
@@ -376,6 +383,68 @@ static void sh_cmt_stop(struct sh_cmt_priv *p, unsigned long flag)
376 spin_unlock_irqrestore(&p->lock, flags); 383 spin_unlock_irqrestore(&p->lock, flags);
377} 384}
378 385
386static struct sh_cmt_priv *cs_to_sh_cmt(struct clocksource *cs)
387{
388 return container_of(cs, struct sh_cmt_priv, cs);
389}
390
391static cycle_t sh_cmt_clocksource_read(struct clocksource *cs)
392{
393 struct sh_cmt_priv *p = cs_to_sh_cmt(cs);
394 unsigned long flags, raw;
395 unsigned long value;
396 int has_wrapped;
397
398 spin_lock_irqsave(&p->lock, flags);
399 value = p->total_cycles;
400 raw = sh_cmt_get_counter(p, &has_wrapped);
401
402 if (unlikely(has_wrapped))
403 raw += p->match_value;
404 spin_unlock_irqrestore(&p->lock, flags);
405
406 return value + raw;
407}
408
409static int sh_cmt_clocksource_enable(struct clocksource *cs)
410{
411 struct sh_cmt_priv *p = cs_to_sh_cmt(cs);
412 int ret;
413
414 p->total_cycles = 0;
415
416 ret = sh_cmt_start(p, FLAG_CLOCKSOURCE);
417 if (ret)
418 return ret;
419
420 /* TODO: calculate good shift from rate and counter bit width */
421 cs->shift = 0;
422 cs->mult = clocksource_hz2mult(p->rate, cs->shift);
423 return 0;
424}
425
426static void sh_cmt_clocksource_disable(struct clocksource *cs)
427{
428 sh_cmt_stop(cs_to_sh_cmt(cs), FLAG_CLOCKSOURCE);
429}
430
431static int sh_cmt_register_clocksource(struct sh_cmt_priv *p,
432 char *name, unsigned long rating)
433{
434 struct clocksource *cs = &p->cs;
435
436 cs->name = name;
437 cs->rating = rating;
438 cs->read = sh_cmt_clocksource_read;
439 cs->enable = sh_cmt_clocksource_enable;
440 cs->disable = sh_cmt_clocksource_disable;
441 cs->mask = CLOCKSOURCE_MASK(sizeof(unsigned long) * 8);
442 cs->flags = CLOCK_SOURCE_IS_CONTINUOUS;
443 pr_info("sh_cmt: %s used as clock source\n", cs->name);
444 clocksource_register(cs);
445 return 0;
446}
447
379static struct sh_cmt_priv *ced_to_sh_cmt(struct clock_event_device *ced) 448static struct sh_cmt_priv *ced_to_sh_cmt(struct clock_event_device *ced)
380{ 449{
381 return container_of(ced, struct sh_cmt_priv, ced); 450 return container_of(ced, struct sh_cmt_priv, ced);
@@ -468,9 +537,9 @@ static void sh_cmt_register_clockevent(struct sh_cmt_priv *p,
468 clockevents_register_device(ced); 537 clockevents_register_device(ced);
469} 538}
470 539
471int sh_cmt_register(struct sh_cmt_priv *p, char *name, 540static int sh_cmt_register(struct sh_cmt_priv *p, char *name,
472 unsigned long clockevent_rating, 541 unsigned long clockevent_rating,
473 unsigned long clocksource_rating) 542 unsigned long clocksource_rating)
474{ 543{
475 if (p->width == (sizeof(p->max_match_value) * 8)) 544 if (p->width == (sizeof(p->max_match_value) * 8))
476 p->max_match_value = ~0; 545 p->max_match_value = ~0;
@@ -483,12 +552,15 @@ int sh_cmt_register(struct sh_cmt_priv *p, char *name,
483 if (clockevent_rating) 552 if (clockevent_rating)
484 sh_cmt_register_clockevent(p, name, clockevent_rating); 553 sh_cmt_register_clockevent(p, name, clockevent_rating);
485 554
555 if (clocksource_rating)
556 sh_cmt_register_clocksource(p, name, clocksource_rating);
557
486 return 0; 558 return 0;
487} 559}
488 560
489static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev) 561static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev)
490{ 562{
491 struct sh_cmt_config *cfg = pdev->dev.platform_data; 563 struct sh_timer_config *cfg = pdev->dev.platform_data;
492 struct resource *res; 564 struct resource *res;
493 int irq, ret; 565 int irq, ret;
494 ret = -ENXIO; 566 ret = -ENXIO;
@@ -545,7 +617,7 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev)
545 if (resource_size(res) == 6) { 617 if (resource_size(res) == 6) {
546 p->width = 16; 618 p->width = 16;
547 p->overflow_bit = 0x80; 619 p->overflow_bit = 0x80;
548 p->clear_bits = ~0xc0; 620 p->clear_bits = ~0x80;
549 } else { 621 } else {
550 p->width = 32; 622 p->width = 32;
551 p->overflow_bit = 0x8000; 623 p->overflow_bit = 0x8000;
@@ -566,8 +638,14 @@ static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev)
566static int __devinit sh_cmt_probe(struct platform_device *pdev) 638static int __devinit sh_cmt_probe(struct platform_device *pdev)
567{ 639{
568 struct sh_cmt_priv *p = platform_get_drvdata(pdev); 640 struct sh_cmt_priv *p = platform_get_drvdata(pdev);
641 struct sh_timer_config *cfg = pdev->dev.platform_data;
569 int ret; 642 int ret;
570 643
644 if (p) {
645 pr_info("sh_cmt: %s kept as earlytimer\n", cfg->name);
646 return 0;
647 }
648
571 p = kmalloc(sizeof(*p), GFP_KERNEL); 649 p = kmalloc(sizeof(*p), GFP_KERNEL);
572 if (p == NULL) { 650 if (p == NULL) {
573 dev_err(&pdev->dev, "failed to allocate driver data\n"); 651 dev_err(&pdev->dev, "failed to allocate driver data\n");
@@ -577,7 +655,6 @@ static int __devinit sh_cmt_probe(struct platform_device *pdev)
577 ret = sh_cmt_setup(p, pdev); 655 ret = sh_cmt_setup(p, pdev);
578 if (ret) { 656 if (ret) {
579 kfree(p); 657 kfree(p);
580
581 platform_set_drvdata(pdev, NULL); 658 platform_set_drvdata(pdev, NULL);
582 } 659 }
583 return ret; 660 return ret;
@@ -606,6 +683,7 @@ static void __exit sh_cmt_exit(void)
606 platform_driver_unregister(&sh_cmt_device_driver); 683 platform_driver_unregister(&sh_cmt_device_driver);
607} 684}
608 685
686early_platform_init("earlytimer", &sh_cmt_device_driver);
609module_init(sh_cmt_init); 687module_init(sh_cmt_init);
610module_exit(sh_cmt_exit); 688module_exit(sh_cmt_exit);
611 689
diff --git a/drivers/clocksource/sh_mtu2.c b/drivers/clocksource/sh_mtu2.c
new file mode 100644
index 000000000000..d1ae75454d10
--- /dev/null
+++ b/drivers/clocksource/sh_mtu2.c
@@ -0,0 +1,357 @@
1/*
2 * SuperH Timer Support - MTU2
3 *
4 * Copyright (C) 2009 Magnus Damm
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/init.h>
21#include <linux/platform_device.h>
22#include <linux/spinlock.h>
23#include <linux/interrupt.h>
24#include <linux/ioport.h>
25#include <linux/delay.h>
26#include <linux/io.h>
27#include <linux/clk.h>
28#include <linux/irq.h>
29#include <linux/err.h>
30#include <linux/clockchips.h>
31#include <linux/sh_timer.h>
32
33struct sh_mtu2_priv {
34 void __iomem *mapbase;
35 struct clk *clk;
36 struct irqaction irqaction;
37 struct platform_device *pdev;
38 unsigned long rate;
39 unsigned long periodic;
40 struct clock_event_device ced;
41};
42
43static DEFINE_SPINLOCK(sh_mtu2_lock);
44
45#define TSTR -1 /* shared register */
46#define TCR 0 /* channel register */
47#define TMDR 1 /* channel register */
48#define TIOR 2 /* channel register */
49#define TIER 3 /* channel register */
50#define TSR 4 /* channel register */
51#define TCNT 5 /* channel register */
52#define TGR 6 /* channel register */
53
54static unsigned long mtu2_reg_offs[] = {
55 [TCR] = 0,
56 [TMDR] = 1,
57 [TIOR] = 2,
58 [TIER] = 4,
59 [TSR] = 5,
60 [TCNT] = 6,
61 [TGR] = 8,
62};
63
64static inline unsigned long sh_mtu2_read(struct sh_mtu2_priv *p, int reg_nr)
65{
66 struct sh_timer_config *cfg = p->pdev->dev.platform_data;
67 void __iomem *base = p->mapbase;
68 unsigned long offs;
69
70 if (reg_nr == TSTR)
71 return ioread8(base + cfg->channel_offset);
72
73 offs = mtu2_reg_offs[reg_nr];
74
75 if ((reg_nr == TCNT) || (reg_nr == TGR))
76 return ioread16(base + offs);
77 else
78 return ioread8(base + offs);
79}
80
81static inline void sh_mtu2_write(struct sh_mtu2_priv *p, int reg_nr,
82 unsigned long value)
83{
84 struct sh_timer_config *cfg = p->pdev->dev.platform_data;
85 void __iomem *base = p->mapbase;
86 unsigned long offs;
87
88 if (reg_nr == TSTR) {
89 iowrite8(value, base + cfg->channel_offset);
90 return;
91 }
92
93 offs = mtu2_reg_offs[reg_nr];
94
95 if ((reg_nr == TCNT) || (reg_nr == TGR))
96 iowrite16(value, base + offs);
97 else
98 iowrite8(value, base + offs);
99}
100
101static void sh_mtu2_start_stop_ch(struct sh_mtu2_priv *p, int start)
102{
103 struct sh_timer_config *cfg = p->pdev->dev.platform_data;
104 unsigned long flags, value;
105
106 /* start stop register shared by multiple timer channels */
107 spin_lock_irqsave(&sh_mtu2_lock, flags);
108 value = sh_mtu2_read(p, TSTR);
109
110 if (start)
111 value |= 1 << cfg->timer_bit;
112 else
113 value &= ~(1 << cfg->timer_bit);
114
115 sh_mtu2_write(p, TSTR, value);
116 spin_unlock_irqrestore(&sh_mtu2_lock, flags);
117}
118
119static int sh_mtu2_enable(struct sh_mtu2_priv *p)
120{
121 struct sh_timer_config *cfg = p->pdev->dev.platform_data;
122 int ret;
123
124 /* enable clock */
125 ret = clk_enable(p->clk);
126 if (ret) {
127 pr_err("sh_mtu2: cannot enable clock \"%s\"\n", cfg->clk);
128 return ret;
129 }
130
131 /* make sure channel is disabled */
132 sh_mtu2_start_stop_ch(p, 0);
133
134 p->rate = clk_get_rate(p->clk) / 64;
135 p->periodic = (p->rate + HZ/2) / HZ;
136
137 /* "Periodic Counter Operation" */
138 sh_mtu2_write(p, TCR, 0x23); /* TGRA clear, divide clock by 64 */
139 sh_mtu2_write(p, TIOR, 0);
140 sh_mtu2_write(p, TGR, p->periodic);
141 sh_mtu2_write(p, TCNT, 0);
142 sh_mtu2_write(p, TMDR, 0);
143 sh_mtu2_write(p, TIER, 0x01);
144
145 /* enable channel */
146 sh_mtu2_start_stop_ch(p, 1);
147
148 return 0;
149}
150
151static void sh_mtu2_disable(struct sh_mtu2_priv *p)
152{
153 /* disable channel */
154 sh_mtu2_start_stop_ch(p, 0);
155
156 /* stop clock */
157 clk_disable(p->clk);
158}
159
160static irqreturn_t sh_mtu2_interrupt(int irq, void *dev_id)
161{
162 struct sh_mtu2_priv *p = dev_id;
163
164 /* acknowledge interrupt */
165 sh_mtu2_read(p, TSR);
166 sh_mtu2_write(p, TSR, 0xfe);
167
168 /* notify clockevent layer */
169 p->ced.event_handler(&p->ced);
170 return IRQ_HANDLED;
171}
172
173static struct sh_mtu2_priv *ced_to_sh_mtu2(struct clock_event_device *ced)
174{
175 return container_of(ced, struct sh_mtu2_priv, ced);
176}
177
178static void sh_mtu2_clock_event_mode(enum clock_event_mode mode,
179 struct clock_event_device *ced)
180{
181 struct sh_mtu2_priv *p = ced_to_sh_mtu2(ced);
182 int disabled = 0;
183
184 /* deal with old setting first */
185 switch (ced->mode) {
186 case CLOCK_EVT_MODE_PERIODIC:
187 sh_mtu2_disable(p);
188 disabled = 1;
189 break;
190 default:
191 break;
192 }
193
194 switch (mode) {
195 case CLOCK_EVT_MODE_PERIODIC:
196 pr_info("sh_mtu2: %s used for periodic clock events\n",
197 ced->name);
198 sh_mtu2_enable(p);
199 break;
200 case CLOCK_EVT_MODE_UNUSED:
201 if (!disabled)
202 sh_mtu2_disable(p);
203 break;
204 case CLOCK_EVT_MODE_SHUTDOWN:
205 default:
206 break;
207 }
208}
209
210static void sh_mtu2_register_clockevent(struct sh_mtu2_priv *p,
211 char *name, unsigned long rating)
212{
213 struct clock_event_device *ced = &p->ced;
214 int ret;
215
216 memset(ced, 0, sizeof(*ced));
217
218 ced->name = name;
219 ced->features = CLOCK_EVT_FEAT_PERIODIC;
220 ced->rating = rating;
221 ced->cpumask = cpumask_of(0);
222 ced->set_mode = sh_mtu2_clock_event_mode;
223
224 ret = setup_irq(p->irqaction.irq, &p->irqaction);
225 if (ret) {
226 pr_err("sh_mtu2: failed to request irq %d\n",
227 p->irqaction.irq);
228 return;
229 }
230
231 pr_info("sh_mtu2: %s used for clock events\n", ced->name);
232 clockevents_register_device(ced);
233}
234
235static int sh_mtu2_register(struct sh_mtu2_priv *p, char *name,
236 unsigned long clockevent_rating)
237{
238 if (clockevent_rating)
239 sh_mtu2_register_clockevent(p, name, clockevent_rating);
240
241 return 0;
242}
243
244static int sh_mtu2_setup(struct sh_mtu2_priv *p, struct platform_device *pdev)
245{
246 struct sh_timer_config *cfg = pdev->dev.platform_data;
247 struct resource *res;
248 int irq, ret;
249 ret = -ENXIO;
250
251 memset(p, 0, sizeof(*p));
252 p->pdev = pdev;
253
254 if (!cfg) {
255 dev_err(&p->pdev->dev, "missing platform data\n");
256 goto err0;
257 }
258
259 platform_set_drvdata(pdev, p);
260
261 res = platform_get_resource(p->pdev, IORESOURCE_MEM, 0);
262 if (!res) {
263 dev_err(&p->pdev->dev, "failed to get I/O memory\n");
264 goto err0;
265 }
266
267 irq = platform_get_irq(p->pdev, 0);
268 if (irq < 0) {
269 dev_err(&p->pdev->dev, "failed to get irq\n");
270 goto err0;
271 }
272
273 /* map memory, let mapbase point to our channel */
274 p->mapbase = ioremap_nocache(res->start, resource_size(res));
275 if (p->mapbase == NULL) {
276 pr_err("sh_mtu2: failed to remap I/O memory\n");
277 goto err0;
278 }
279
280 /* setup data for setup_irq() (too early for request_irq()) */
281 p->irqaction.name = cfg->name;
282 p->irqaction.handler = sh_mtu2_interrupt;
283 p->irqaction.dev_id = p;
284 p->irqaction.irq = irq;
285 p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL;
286 p->irqaction.mask = CPU_MASK_NONE;
287
288 /* get hold of clock */
289 p->clk = clk_get(&p->pdev->dev, cfg->clk);
290 if (IS_ERR(p->clk)) {
291 pr_err("sh_mtu2: cannot get clock \"%s\"\n", cfg->clk);
292 ret = PTR_ERR(p->clk);
293 goto err1;
294 }
295
296 return sh_mtu2_register(p, cfg->name, cfg->clockevent_rating);
297 err1:
298 iounmap(p->mapbase);
299 err0:
300 return ret;
301}
302
303static int __devinit sh_mtu2_probe(struct platform_device *pdev)
304{
305 struct sh_mtu2_priv *p = platform_get_drvdata(pdev);
306 struct sh_timer_config *cfg = pdev->dev.platform_data;
307 int ret;
308
309 if (p) {
310 pr_info("sh_mtu2: %s kept as earlytimer\n", cfg->name);
311 return 0;
312 }
313
314 p = kmalloc(sizeof(*p), GFP_KERNEL);
315 if (p == NULL) {
316 dev_err(&pdev->dev, "failed to allocate driver data\n");
317 return -ENOMEM;
318 }
319
320 ret = sh_mtu2_setup(p, pdev);
321 if (ret) {
322 kfree(p);
323 platform_set_drvdata(pdev, NULL);
324 }
325 return ret;
326}
327
328static int __devexit sh_mtu2_remove(struct platform_device *pdev)
329{
330 return -EBUSY; /* cannot unregister clockevent */
331}
332
333static struct platform_driver sh_mtu2_device_driver = {
334 .probe = sh_mtu2_probe,
335 .remove = __devexit_p(sh_mtu2_remove),
336 .driver = {
337 .name = "sh_mtu2",
338 }
339};
340
341static int __init sh_mtu2_init(void)
342{
343 return platform_driver_register(&sh_mtu2_device_driver);
344}
345
346static void __exit sh_mtu2_exit(void)
347{
348 platform_driver_unregister(&sh_mtu2_device_driver);
349}
350
351early_platform_init("earlytimer", &sh_mtu2_device_driver);
352module_init(sh_mtu2_init);
353module_exit(sh_mtu2_exit);
354
355MODULE_AUTHOR("Magnus Damm");
356MODULE_DESCRIPTION("SuperH MTU2 Timer Driver");
357MODULE_LICENSE("GPL v2");
diff --git a/drivers/clocksource/sh_tmu.c b/drivers/clocksource/sh_tmu.c
new file mode 100644
index 000000000000..d6ea4398bf62
--- /dev/null
+++ b/drivers/clocksource/sh_tmu.c
@@ -0,0 +1,461 @@
1/*
2 * SuperH Timer Support - TMU
3 *
4 * Copyright (C) 2009 Magnus Damm
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/init.h>
21#include <linux/platform_device.h>
22#include <linux/spinlock.h>
23#include <linux/interrupt.h>
24#include <linux/ioport.h>
25#include <linux/delay.h>
26#include <linux/io.h>
27#include <linux/clk.h>
28#include <linux/irq.h>
29#include <linux/err.h>
30#include <linux/clocksource.h>
31#include <linux/clockchips.h>
32#include <linux/sh_timer.h>
33
34struct sh_tmu_priv {
35 void __iomem *mapbase;
36 struct clk *clk;
37 struct irqaction irqaction;
38 struct platform_device *pdev;
39 unsigned long rate;
40 unsigned long periodic;
41 struct clock_event_device ced;
42 struct clocksource cs;
43};
44
45static DEFINE_SPINLOCK(sh_tmu_lock);
46
47#define TSTR -1 /* shared register */
48#define TCOR 0 /* channel register */
49#define TCNT 1 /* channel register */
50#define TCR 2 /* channel register */
51
52static inline unsigned long sh_tmu_read(struct sh_tmu_priv *p, int reg_nr)
53{
54 struct sh_timer_config *cfg = p->pdev->dev.platform_data;
55 void __iomem *base = p->mapbase;
56 unsigned long offs;
57
58 if (reg_nr == TSTR)
59 return ioread8(base - cfg->channel_offset);
60
61 offs = reg_nr << 2;
62
63 if (reg_nr == TCR)
64 return ioread16(base + offs);
65 else
66 return ioread32(base + offs);
67}
68
69static inline void sh_tmu_write(struct sh_tmu_priv *p, int reg_nr,
70 unsigned long value)
71{
72 struct sh_timer_config *cfg = p->pdev->dev.platform_data;
73 void __iomem *base = p->mapbase;
74 unsigned long offs;
75
76 if (reg_nr == TSTR) {
77 iowrite8(value, base - cfg->channel_offset);
78 return;
79 }
80
81 offs = reg_nr << 2;
82
83 if (reg_nr == TCR)
84 iowrite16(value, base + offs);
85 else
86 iowrite32(value, base + offs);
87}
88
89static void sh_tmu_start_stop_ch(struct sh_tmu_priv *p, int start)
90{
91 struct sh_timer_config *cfg = p->pdev->dev.platform_data;
92 unsigned long flags, value;
93
94 /* start stop register shared by multiple timer channels */
95 spin_lock_irqsave(&sh_tmu_lock, flags);
96 value = sh_tmu_read(p, TSTR);
97
98 if (start)
99 value |= 1 << cfg->timer_bit;
100 else
101 value &= ~(1 << cfg->timer_bit);
102
103 sh_tmu_write(p, TSTR, value);
104 spin_unlock_irqrestore(&sh_tmu_lock, flags);
105}
106
107static int sh_tmu_enable(struct sh_tmu_priv *p)
108{
109 struct sh_timer_config *cfg = p->pdev->dev.platform_data;
110 int ret;
111
112 /* enable clock */
113 ret = clk_enable(p->clk);
114 if (ret) {
115 pr_err("sh_tmu: cannot enable clock \"%s\"\n", cfg->clk);
116 return ret;
117 }
118
119 /* make sure channel is disabled */
120 sh_tmu_start_stop_ch(p, 0);
121
122 /* maximum timeout */
123 sh_tmu_write(p, TCOR, 0xffffffff);
124 sh_tmu_write(p, TCNT, 0xffffffff);
125
126 /* configure channel to parent clock / 4, irq off */
127 p->rate = clk_get_rate(p->clk) / 4;
128 sh_tmu_write(p, TCR, 0x0000);
129
130 /* enable channel */
131 sh_tmu_start_stop_ch(p, 1);
132
133 return 0;
134}
135
136static void sh_tmu_disable(struct sh_tmu_priv *p)
137{
138 /* disable channel */
139 sh_tmu_start_stop_ch(p, 0);
140
141 /* stop clock */
142 clk_disable(p->clk);
143}
144
145static void sh_tmu_set_next(struct sh_tmu_priv *p, unsigned long delta,
146 int periodic)
147{
148 /* stop timer */
149 sh_tmu_start_stop_ch(p, 0);
150
151 /* acknowledge interrupt */
152 sh_tmu_read(p, TCR);
153
154 /* enable interrupt */
155 sh_tmu_write(p, TCR, 0x0020);
156
157 /* reload delta value in case of periodic timer */
158 if (periodic)
159 sh_tmu_write(p, TCOR, delta);
160 else
161 sh_tmu_write(p, TCOR, 0);
162
163 sh_tmu_write(p, TCNT, delta);
164
165 /* start timer */
166 sh_tmu_start_stop_ch(p, 1);
167}
168
169static irqreturn_t sh_tmu_interrupt(int irq, void *dev_id)
170{
171 struct sh_tmu_priv *p = dev_id;
172
173 /* disable or acknowledge interrupt */
174 if (p->ced.mode == CLOCK_EVT_MODE_ONESHOT)
175 sh_tmu_write(p, TCR, 0x0000);
176 else
177 sh_tmu_write(p, TCR, 0x0020);
178
179 /* notify clockevent layer */
180 p->ced.event_handler(&p->ced);
181 return IRQ_HANDLED;
182}
183
184static struct sh_tmu_priv *cs_to_sh_tmu(struct clocksource *cs)
185{
186 return container_of(cs, struct sh_tmu_priv, cs);
187}
188
189static cycle_t sh_tmu_clocksource_read(struct clocksource *cs)
190{
191 struct sh_tmu_priv *p = cs_to_sh_tmu(cs);
192
193 return sh_tmu_read(p, TCNT) ^ 0xffffffff;
194}
195
196static int sh_tmu_clocksource_enable(struct clocksource *cs)
197{
198 struct sh_tmu_priv *p = cs_to_sh_tmu(cs);
199 int ret;
200
201 ret = sh_tmu_enable(p);
202 if (ret)
203 return ret;
204
205 /* TODO: calculate good shift from rate and counter bit width */
206 cs->shift = 10;
207 cs->mult = clocksource_hz2mult(p->rate, cs->shift);
208 return 0;
209}
210
211static void sh_tmu_clocksource_disable(struct clocksource *cs)
212{
213 sh_tmu_disable(cs_to_sh_tmu(cs));
214}
215
216static int sh_tmu_register_clocksource(struct sh_tmu_priv *p,
217 char *name, unsigned long rating)
218{
219 struct clocksource *cs = &p->cs;
220
221 cs->name = name;
222 cs->rating = rating;
223 cs->read = sh_tmu_clocksource_read;
224 cs->enable = sh_tmu_clocksource_enable;
225 cs->disable = sh_tmu_clocksource_disable;
226 cs->mask = CLOCKSOURCE_MASK(32);
227 cs->flags = CLOCK_SOURCE_IS_CONTINUOUS;
228 pr_info("sh_tmu: %s used as clock source\n", cs->name);
229 clocksource_register(cs);
230 return 0;
231}
232
233static struct sh_tmu_priv *ced_to_sh_tmu(struct clock_event_device *ced)
234{
235 return container_of(ced, struct sh_tmu_priv, ced);
236}
237
238static void sh_tmu_clock_event_start(struct sh_tmu_priv *p, int periodic)
239{
240 struct clock_event_device *ced = &p->ced;
241
242 sh_tmu_enable(p);
243
244 /* TODO: calculate good shift from rate and counter bit width */
245
246 ced->shift = 32;
247 ced->mult = div_sc(p->rate, NSEC_PER_SEC, ced->shift);
248 ced->max_delta_ns = clockevent_delta2ns(0xffffffff, ced);
249 ced->min_delta_ns = 5000;
250
251 if (periodic) {
252 p->periodic = (p->rate + HZ/2) / HZ;
253 sh_tmu_set_next(p, p->periodic, 1);
254 }
255}
256
257static void sh_tmu_clock_event_mode(enum clock_event_mode mode,
258 struct clock_event_device *ced)
259{
260 struct sh_tmu_priv *p = ced_to_sh_tmu(ced);
261 int disabled = 0;
262
263 /* deal with old setting first */
264 switch (ced->mode) {
265 case CLOCK_EVT_MODE_PERIODIC:
266 case CLOCK_EVT_MODE_ONESHOT:
267 sh_tmu_disable(p);
268 disabled = 1;
269 break;
270 default:
271 break;
272 }
273
274 switch (mode) {
275 case CLOCK_EVT_MODE_PERIODIC:
276 pr_info("sh_tmu: %s used for periodic clock events\n",
277 ced->name);
278 sh_tmu_clock_event_start(p, 1);
279 break;
280 case CLOCK_EVT_MODE_ONESHOT:
281 pr_info("sh_tmu: %s used for oneshot clock events\n",
282 ced->name);
283 sh_tmu_clock_event_start(p, 0);
284 break;
285 case CLOCK_EVT_MODE_UNUSED:
286 if (!disabled)
287 sh_tmu_disable(p);
288 break;
289 case CLOCK_EVT_MODE_SHUTDOWN:
290 default:
291 break;
292 }
293}
294
295static int sh_tmu_clock_event_next(unsigned long delta,
296 struct clock_event_device *ced)
297{
298 struct sh_tmu_priv *p = ced_to_sh_tmu(ced);
299
300 BUG_ON(ced->mode != CLOCK_EVT_MODE_ONESHOT);
301
302 /* program new delta value */
303 sh_tmu_set_next(p, delta, 0);
304 return 0;
305}
306
307static void sh_tmu_register_clockevent(struct sh_tmu_priv *p,
308 char *name, unsigned long rating)
309{
310 struct clock_event_device *ced = &p->ced;
311 int ret;
312
313 memset(ced, 0, sizeof(*ced));
314
315 ced->name = name;
316 ced->features = CLOCK_EVT_FEAT_PERIODIC;
317 ced->features |= CLOCK_EVT_FEAT_ONESHOT;
318 ced->rating = rating;
319 ced->cpumask = cpumask_of(0);
320 ced->set_next_event = sh_tmu_clock_event_next;
321 ced->set_mode = sh_tmu_clock_event_mode;
322
323 ret = setup_irq(p->irqaction.irq, &p->irqaction);
324 if (ret) {
325 pr_err("sh_tmu: failed to request irq %d\n",
326 p->irqaction.irq);
327 return;
328 }
329
330 pr_info("sh_tmu: %s used for clock events\n", ced->name);
331 clockevents_register_device(ced);
332}
333
334static int sh_tmu_register(struct sh_tmu_priv *p, char *name,
335 unsigned long clockevent_rating,
336 unsigned long clocksource_rating)
337{
338 if (clockevent_rating)
339 sh_tmu_register_clockevent(p, name, clockevent_rating);
340 else if (clocksource_rating)
341 sh_tmu_register_clocksource(p, name, clocksource_rating);
342
343 return 0;
344}
345
346static int sh_tmu_setup(struct sh_tmu_priv *p, struct platform_device *pdev)
347{
348 struct sh_timer_config *cfg = pdev->dev.platform_data;
349 struct resource *res;
350 int irq, ret;
351 ret = -ENXIO;
352
353 memset(p, 0, sizeof(*p));
354 p->pdev = pdev;
355
356 if (!cfg) {
357 dev_err(&p->pdev->dev, "missing platform data\n");
358 goto err0;
359 }
360
361 platform_set_drvdata(pdev, p);
362
363 res = platform_get_resource(p->pdev, IORESOURCE_MEM, 0);
364 if (!res) {
365 dev_err(&p->pdev->dev, "failed to get I/O memory\n");
366 goto err0;
367 }
368
369 irq = platform_get_irq(p->pdev, 0);
370 if (irq < 0) {
371 dev_err(&p->pdev->dev, "failed to get irq\n");
372 goto err0;
373 }
374
375 /* map memory, let mapbase point to our channel */
376 p->mapbase = ioremap_nocache(res->start, resource_size(res));
377 if (p->mapbase == NULL) {
378 pr_err("sh_tmu: failed to remap I/O memory\n");
379 goto err0;
380 }
381
382 /* setup data for setup_irq() (too early for request_irq()) */
383 p->irqaction.name = cfg->name;
384 p->irqaction.handler = sh_tmu_interrupt;
385 p->irqaction.dev_id = p;
386 p->irqaction.irq = irq;
387 p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL;
388 p->irqaction.mask = CPU_MASK_NONE;
389
390 /* get hold of clock */
391 p->clk = clk_get(&p->pdev->dev, cfg->clk);
392 if (IS_ERR(p->clk)) {
393 pr_err("sh_tmu: cannot get clock \"%s\"\n", cfg->clk);
394 ret = PTR_ERR(p->clk);
395 goto err1;
396 }
397
398 return sh_tmu_register(p, cfg->name,
399 cfg->clockevent_rating,
400 cfg->clocksource_rating);
401 err1:
402 iounmap(p->mapbase);
403 err0:
404 return ret;
405}
406
407static int __devinit sh_tmu_probe(struct platform_device *pdev)
408{
409 struct sh_tmu_priv *p = platform_get_drvdata(pdev);
410 struct sh_timer_config *cfg = pdev->dev.platform_data;
411 int ret;
412
413 if (p) {
414 pr_info("sh_tmu: %s kept as earlytimer\n", cfg->name);
415 return 0;
416 }
417
418 p = kmalloc(sizeof(*p), GFP_KERNEL);
419 if (p == NULL) {
420 dev_err(&pdev->dev, "failed to allocate driver data\n");
421 return -ENOMEM;
422 }
423
424 ret = sh_tmu_setup(p, pdev);
425 if (ret) {
426 kfree(p);
427 platform_set_drvdata(pdev, NULL);
428 }
429 return ret;
430}
431
432static int __devexit sh_tmu_remove(struct platform_device *pdev)
433{
434 return -EBUSY; /* cannot unregister clockevent and clocksource */
435}
436
437static struct platform_driver sh_tmu_device_driver = {
438 .probe = sh_tmu_probe,
439 .remove = __devexit_p(sh_tmu_remove),
440 .driver = {
441 .name = "sh_tmu",
442 }
443};
444
445static int __init sh_tmu_init(void)
446{
447 return platform_driver_register(&sh_tmu_device_driver);
448}
449
450static void __exit sh_tmu_exit(void)
451{
452 platform_driver_unregister(&sh_tmu_device_driver);
453}
454
455early_platform_init("earlytimer", &sh_tmu_device_driver);
456module_init(sh_tmu_init);
457module_exit(sh_tmu_exit);
458
459MODULE_AUTHOR("Magnus Damm");
460MODULE_DESCRIPTION("SuperH TMU Timer Driver");
461MODULE_LICENSE("GPL v2");
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index 956982f8739b..ab4f3592a11c 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -49,7 +49,6 @@ config EDAC_DEBUG_VERBOSE
49 49
50config EDAC_MM_EDAC 50config EDAC_MM_EDAC
51 tristate "Main Memory EDAC (Error Detection And Correction) reporting" 51 tristate "Main Memory EDAC (Error Detection And Correction) reporting"
52 default y
53 help 52 help
54 Some systems are able to detect and correct errors in main 53 Some systems are able to detect and correct errors in main
55 memory. EDAC can report statistics on memory error 54 memory. EDAC can report statistics on memory error
@@ -58,6 +57,31 @@ config EDAC_MM_EDAC
58 occurred so that a particular failing memory module can be 57 occurred so that a particular failing memory module can be
59 replaced. If unsure, select 'Y'. 58 replaced. If unsure, select 'Y'.
60 59
60config EDAC_AMD64
61 tristate "AMD64 (Opteron, Athlon64) K8, F10h, F11h"
62 depends on EDAC_MM_EDAC && K8_NB && X86_64 && PCI
63 help
64 Support for error detection and correction on the AMD 64
65 Families of Memory Controllers (K8, F10h and F11h)
66
67config EDAC_AMD64_ERROR_INJECTION
68 bool "Sysfs Error Injection facilities"
69 depends on EDAC_AMD64
70 help
71 Recent Opterons (Family 10h and later) provide for Memory Error
72 Injection into the ECC detection circuits. The amd64_edac module
73 allows the operator/user to inject Uncorrectable and Correctable
74 errors into DRAM.
75
76 When enabled, in each of the respective memory controller directories
77 (/sys/devices/system/edac/mc/mcX), there are 3 input files:
78
79 - inject_section (0..3, 16-byte section of 64-byte cacheline),
80 - inject_word (0..8, 16-bit word of 16-byte section),
81 - inject_ecc_vector (hex ecc vector: select bits of inject word)
82
83 In addition, there are two control files, inject_read and inject_write,
84 which trigger the DRAM ECC Read and Write respectively.
61 85
62config EDAC_AMD76X 86config EDAC_AMD76X
63 tristate "AMD 76x (760, 762, 768)" 87 tristate "AMD 76x (760, 762, 768)"
diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
index 59076819135d..633dc5604ee3 100644
--- a/drivers/edac/Makefile
+++ b/drivers/edac/Makefile
@@ -30,6 +30,13 @@ obj-$(CONFIG_EDAC_I3000) += i3000_edac.o
30obj-$(CONFIG_EDAC_X38) += x38_edac.o 30obj-$(CONFIG_EDAC_X38) += x38_edac.o
31obj-$(CONFIG_EDAC_I82860) += i82860_edac.o 31obj-$(CONFIG_EDAC_I82860) += i82860_edac.o
32obj-$(CONFIG_EDAC_R82600) += r82600_edac.o 32obj-$(CONFIG_EDAC_R82600) += r82600_edac.o
33
34amd64_edac_mod-y := amd64_edac_err_types.o amd64_edac.o
35amd64_edac_mod-$(CONFIG_EDAC_DEBUG) += amd64_edac_dbg.o
36amd64_edac_mod-$(CONFIG_EDAC_AMD64_ERROR_INJECTION) += amd64_edac_inj.o
37
38obj-$(CONFIG_EDAC_AMD64) += amd64_edac_mod.o
39
33obj-$(CONFIG_EDAC_PASEMI) += pasemi_edac.o 40obj-$(CONFIG_EDAC_PASEMI) += pasemi_edac.o
34obj-$(CONFIG_EDAC_MPC85XX) += mpc85xx_edac.o 41obj-$(CONFIG_EDAC_MPC85XX) += mpc85xx_edac.o
35obj-$(CONFIG_EDAC_MV64X60) += mv64x60_edac.o 42obj-$(CONFIG_EDAC_MV64X60) += mv64x60_edac.o
diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
new file mode 100644
index 000000000000..c36bf40568cf
--- /dev/null
+++ b/drivers/edac/amd64_edac.c
@@ -0,0 +1,3354 @@
1#include "amd64_edac.h"
2#include <asm/k8.h>
3
4static struct edac_pci_ctl_info *amd64_ctl_pci;
5
6static int report_gart_errors;
7module_param(report_gart_errors, int, 0644);
8
9/*
10 * Set by command line parameter. If BIOS has enabled the ECC, this override is
11 * cleared to prevent re-enabling the hardware by this driver.
12 */
13static int ecc_enable_override;
14module_param(ecc_enable_override, int, 0644);
15
16/* Lookup table for all possible MC control instances */
17struct amd64_pvt;
18static struct mem_ctl_info *mci_lookup[MAX_NUMNODES];
19static struct amd64_pvt *pvt_lookup[MAX_NUMNODES];
20
21/*
22 * Memory scrubber control interface. For K8, memory scrubbing is handled by
23 * hardware and can involve L2 cache, dcache as well as the main memory. With
24 * F10, this is extended to L3 cache scrubbing on CPU models sporting that
25 * functionality.
26 *
27 * This causes the "units" for the scrubbing speed to vary from 64 byte blocks
28 * (dram) over to cache lines. This is nasty, so we will use bandwidth in
29 * bytes/sec for the setting.
30 *
31 * Currently, we only do dram scrubbing. If the scrubbing is done in software on
32 * other archs, we might not have access to the caches directly.
33 */
34
35/*
36 * scan the scrub rate mapping table for a close or matching bandwidth value to
37 * issue. If requested is too big, then use last maximum value found.
38 */
39static int amd64_search_set_scrub_rate(struct pci_dev *ctl, u32 new_bw,
40 u32 min_scrubrate)
41{
42 u32 scrubval;
43 int i;
44
45 /*
46 * map the configured rate (new_bw) to a value specific to the AMD64
47 * memory controller and apply to register. Search for the first
48 * bandwidth entry that is greater or equal than the setting requested
49 * and program that. If at last entry, turn off DRAM scrubbing.
50 */
51 for (i = 0; i < ARRAY_SIZE(scrubrates); i++) {
52 /*
53 * skip scrub rates which aren't recommended
54 * (see F10 BKDG, F3x58)
55 */
56 if (scrubrates[i].scrubval < min_scrubrate)
57 continue;
58
59 if (scrubrates[i].bandwidth <= new_bw)
60 break;
61
62 /*
63 * if no suitable bandwidth found, turn off DRAM scrubbing
64 * entirely by falling back to the last element in the
65 * scrubrates array.
66 */
67 }
68
69 scrubval = scrubrates[i].scrubval;
70 if (scrubval)
71 edac_printk(KERN_DEBUG, EDAC_MC,
72 "Setting scrub rate bandwidth: %u\n",
73 scrubrates[i].bandwidth);
74 else
75 edac_printk(KERN_DEBUG, EDAC_MC, "Turning scrubbing off.\n");
76
77 pci_write_bits32(ctl, K8_SCRCTRL, scrubval, 0x001F);
78
79 return 0;
80}
81
82static int amd64_set_scrub_rate(struct mem_ctl_info *mci, u32 *bandwidth)
83{
84 struct amd64_pvt *pvt = mci->pvt_info;
85 u32 min_scrubrate = 0x0;
86
87 switch (boot_cpu_data.x86) {
88 case 0xf:
89 min_scrubrate = K8_MIN_SCRUB_RATE_BITS;
90 break;
91 case 0x10:
92 min_scrubrate = F10_MIN_SCRUB_RATE_BITS;
93 break;
94 case 0x11:
95 min_scrubrate = F11_MIN_SCRUB_RATE_BITS;
96 break;
97
98 default:
99 amd64_printk(KERN_ERR, "Unsupported family!\n");
100 break;
101 }
102 return amd64_search_set_scrub_rate(pvt->misc_f3_ctl, *bandwidth,
103 min_scrubrate);
104}
105
106static int amd64_get_scrub_rate(struct mem_ctl_info *mci, u32 *bw)
107{
108 struct amd64_pvt *pvt = mci->pvt_info;
109 u32 scrubval = 0;
110 int status = -1, i, ret = 0;
111
112 ret = pci_read_config_dword(pvt->misc_f3_ctl, K8_SCRCTRL, &scrubval);
113 if (ret)
114 debugf0("Reading K8_SCRCTRL failed\n");
115
116 scrubval = scrubval & 0x001F;
117
118 edac_printk(KERN_DEBUG, EDAC_MC,
119 "pci-read, sdram scrub control value: %d \n", scrubval);
120
121 for (i = 0; ARRAY_SIZE(scrubrates); i++) {
122 if (scrubrates[i].scrubval == scrubval) {
123 *bw = scrubrates[i].bandwidth;
124 status = 0;
125 break;
126 }
127 }
128
129 return status;
130}
131
132/* Map from a CSROW entry to the mask entry that operates on it */
133static inline u32 amd64_map_to_dcs_mask(struct amd64_pvt *pvt, int csrow)
134{
135 return csrow >> (pvt->num_dcsm >> 3);
136}
137
138/* return the 'base' address the i'th CS entry of the 'dct' DRAM controller */
139static u32 amd64_get_dct_base(struct amd64_pvt *pvt, int dct, int csrow)
140{
141 if (dct == 0)
142 return pvt->dcsb0[csrow];
143 else
144 return pvt->dcsb1[csrow];
145}
146
147/*
148 * Return the 'mask' address the i'th CS entry. This function is needed because
149 * there number of DCSM registers on Rev E and prior vs Rev F and later is
150 * different.
151 */
152static u32 amd64_get_dct_mask(struct amd64_pvt *pvt, int dct, int csrow)
153{
154 if (dct == 0)
155 return pvt->dcsm0[amd64_map_to_dcs_mask(pvt, csrow)];
156 else
157 return pvt->dcsm1[amd64_map_to_dcs_mask(pvt, csrow)];
158}
159
160
161/*
162 * In *base and *limit, pass back the full 40-bit base and limit physical
163 * addresses for the node given by node_id. This information is obtained from
164 * DRAM Base (section 3.4.4.1) and DRAM Limit (section 3.4.4.2) registers. The
165 * base and limit addresses are of type SysAddr, as defined at the start of
166 * section 3.4.4 (p. 70). They are the lowest and highest physical addresses
167 * in the address range they represent.
168 */
169static void amd64_get_base_and_limit(struct amd64_pvt *pvt, int node_id,
170 u64 *base, u64 *limit)
171{
172 *base = pvt->dram_base[node_id];
173 *limit = pvt->dram_limit[node_id];
174}
175
176/*
177 * Return 1 if the SysAddr given by sys_addr matches the base/limit associated
178 * with node_id
179 */
180static int amd64_base_limit_match(struct amd64_pvt *pvt,
181 u64 sys_addr, int node_id)
182{
183 u64 base, limit, addr;
184
185 amd64_get_base_and_limit(pvt, node_id, &base, &limit);
186
187 /* The K8 treats this as a 40-bit value. However, bits 63-40 will be
188 * all ones if the most significant implemented address bit is 1.
189 * Here we discard bits 63-40. See section 3.4.2 of AMD publication
190 * 24592: AMD x86-64 Architecture Programmer's Manual Volume 1
191 * Application Programming.
192 */
193 addr = sys_addr & 0x000000ffffffffffull;
194
195 return (addr >= base) && (addr <= limit);
196}
197
198/*
199 * Attempt to map a SysAddr to a node. On success, return a pointer to the
200 * mem_ctl_info structure for the node that the SysAddr maps to.
201 *
202 * On failure, return NULL.
203 */
204static struct mem_ctl_info *find_mc_by_sys_addr(struct mem_ctl_info *mci,
205 u64 sys_addr)
206{
207 struct amd64_pvt *pvt;
208 int node_id;
209 u32 intlv_en, bits;
210
211 /*
212 * Here we use the DRAM Base (section 3.4.4.1) and DRAM Limit (section
213 * 3.4.4.2) registers to map the SysAddr to a node ID.
214 */
215 pvt = mci->pvt_info;
216
217 /*
218 * The value of this field should be the same for all DRAM Base
219 * registers. Therefore we arbitrarily choose to read it from the
220 * register for node 0.
221 */
222 intlv_en = pvt->dram_IntlvEn[0];
223
224 if (intlv_en == 0) {
225 for (node_id = 0; ; ) {
226 if (amd64_base_limit_match(pvt, sys_addr, node_id))
227 break;
228
229 if (++node_id >= DRAM_REG_COUNT)
230 goto err_no_match;
231 }
232 goto found;
233 }
234
235 if (unlikely((intlv_en != (0x01 << 8)) &&
236 (intlv_en != (0x03 << 8)) &&
237 (intlv_en != (0x07 << 8)))) {
238 amd64_printk(KERN_WARNING, "junk value of 0x%x extracted from "
239 "IntlvEn field of DRAM Base Register for node 0: "
240 "This probably indicates a BIOS bug.\n", intlv_en);
241 return NULL;
242 }
243
244 bits = (((u32) sys_addr) >> 12) & intlv_en;
245
246 for (node_id = 0; ; ) {
247 if ((pvt->dram_limit[node_id] & intlv_en) == bits)
248 break; /* intlv_sel field matches */
249
250 if (++node_id >= DRAM_REG_COUNT)
251 goto err_no_match;
252 }
253
254 /* sanity test for sys_addr */
255 if (unlikely(!amd64_base_limit_match(pvt, sys_addr, node_id))) {
256 amd64_printk(KERN_WARNING,
257 "%s(): sys_addr 0x%lx falls outside base/limit "
258 "address range for node %d with node interleaving "
259 "enabled.\n", __func__, (unsigned long)sys_addr,
260 node_id);
261 return NULL;
262 }
263
264found:
265 return edac_mc_find(node_id);
266
267err_no_match:
268 debugf2("sys_addr 0x%lx doesn't match any node\n",
269 (unsigned long)sys_addr);
270
271 return NULL;
272}
273
274/*
275 * Extract the DRAM CS base address from selected csrow register.
276 */
277static u64 base_from_dct_base(struct amd64_pvt *pvt, int csrow)
278{
279 return ((u64) (amd64_get_dct_base(pvt, 0, csrow) & pvt->dcsb_base)) <<
280 pvt->dcs_shift;
281}
282
283/*
284 * Extract the mask from the dcsb0[csrow] entry in a CPU revision-specific way.
285 */
286static u64 mask_from_dct_mask(struct amd64_pvt *pvt, int csrow)
287{
288 u64 dcsm_bits, other_bits;
289 u64 mask;
290
291 /* Extract bits from DRAM CS Mask. */
292 dcsm_bits = amd64_get_dct_mask(pvt, 0, csrow) & pvt->dcsm_mask;
293
294 other_bits = pvt->dcsm_mask;
295 other_bits = ~(other_bits << pvt->dcs_shift);
296
297 /*
298 * The extracted bits from DCSM belong in the spaces represented by
299 * the cleared bits in other_bits.
300 */
301 mask = (dcsm_bits << pvt->dcs_shift) | other_bits;
302
303 return mask;
304}
305
306/*
307 * @input_addr is an InputAddr associated with the node given by mci. Return the
308 * csrow that input_addr maps to, or -1 on failure (no csrow claims input_addr).
309 */
310static int input_addr_to_csrow(struct mem_ctl_info *mci, u64 input_addr)
311{
312 struct amd64_pvt *pvt;
313 int csrow;
314 u64 base, mask;
315
316 pvt = mci->pvt_info;
317
318 /*
319 * Here we use the DRAM CS Base and DRAM CS Mask registers. For each CS
320 * base/mask register pair, test the condition shown near the start of
321 * section 3.5.4 (p. 84, BKDG #26094, K8, revA-E).
322 */
323 for (csrow = 0; csrow < CHIPSELECT_COUNT; csrow++) {
324
325 /* This DRAM chip select is disabled on this node */
326 if ((pvt->dcsb0[csrow] & K8_DCSB_CS_ENABLE) == 0)
327 continue;
328
329 base = base_from_dct_base(pvt, csrow);
330 mask = ~mask_from_dct_mask(pvt, csrow);
331
332 if ((input_addr & mask) == (base & mask)) {
333 debugf2("InputAddr 0x%lx matches csrow %d (node %d)\n",
334 (unsigned long)input_addr, csrow,
335 pvt->mc_node_id);
336
337 return csrow;
338 }
339 }
340
341 debugf2("no matching csrow for InputAddr 0x%lx (MC node %d)\n",
342 (unsigned long)input_addr, pvt->mc_node_id);
343
344 return -1;
345}
346
347/*
348 * Return the base value defined by the DRAM Base register for the node
349 * represented by mci. This function returns the full 40-bit value despite the
350 * fact that the register only stores bits 39-24 of the value. See section
351 * 3.4.4.1 (BKDG #26094, K8, revA-E)
352 */
353static inline u64 get_dram_base(struct mem_ctl_info *mci)
354{
355 struct amd64_pvt *pvt = mci->pvt_info;
356
357 return pvt->dram_base[pvt->mc_node_id];
358}
359
360/*
361 * Obtain info from the DRAM Hole Address Register (section 3.4.8, pub #26094)
362 * for the node represented by mci. Info is passed back in *hole_base,
363 * *hole_offset, and *hole_size. Function returns 0 if info is valid or 1 if
364 * info is invalid. Info may be invalid for either of the following reasons:
365 *
366 * - The revision of the node is not E or greater. In this case, the DRAM Hole
367 * Address Register does not exist.
368 *
369 * - The DramHoleValid bit is cleared in the DRAM Hole Address Register,
370 * indicating that its contents are not valid.
371 *
372 * The values passed back in *hole_base, *hole_offset, and *hole_size are
373 * complete 32-bit values despite the fact that the bitfields in the DHAR
374 * only represent bits 31-24 of the base and offset values.
375 */
376int amd64_get_dram_hole_info(struct mem_ctl_info *mci, u64 *hole_base,
377 u64 *hole_offset, u64 *hole_size)
378{
379 struct amd64_pvt *pvt = mci->pvt_info;
380 u64 base;
381
382 /* only revE and later have the DRAM Hole Address Register */
383 if (boot_cpu_data.x86 == 0xf && pvt->ext_model < OPTERON_CPU_REV_E) {
384 debugf1(" revision %d for node %d does not support DHAR\n",
385 pvt->ext_model, pvt->mc_node_id);
386 return 1;
387 }
388
389 /* only valid for Fam10h */
390 if (boot_cpu_data.x86 == 0x10 &&
391 (pvt->dhar & F10_DRAM_MEM_HOIST_VALID) == 0) {
392 debugf1(" Dram Memory Hoisting is DISABLED on this system\n");
393 return 1;
394 }
395
396 if ((pvt->dhar & DHAR_VALID) == 0) {
397 debugf1(" Dram Memory Hoisting is DISABLED on this node %d\n",
398 pvt->mc_node_id);
399 return 1;
400 }
401
402 /* This node has Memory Hoisting */
403
404 /* +------------------+--------------------+--------------------+-----
405 * | memory | DRAM hole | relocated |
406 * | [0, (x - 1)] | [x, 0xffffffff] | addresses from |
407 * | | | DRAM hole |
408 * | | | [0x100000000, |
409 * | | | (0x100000000+ |
410 * | | | (0xffffffff-x))] |
411 * +------------------+--------------------+--------------------+-----
412 *
413 * Above is a diagram of physical memory showing the DRAM hole and the
414 * relocated addresses from the DRAM hole. As shown, the DRAM hole
415 * starts at address x (the base address) and extends through address
416 * 0xffffffff. The DRAM Hole Address Register (DHAR) relocates the
417 * addresses in the hole so that they start at 0x100000000.
418 */
419
420 base = dhar_base(pvt->dhar);
421
422 *hole_base = base;
423 *hole_size = (0x1ull << 32) - base;
424
425 if (boot_cpu_data.x86 > 0xf)
426 *hole_offset = f10_dhar_offset(pvt->dhar);
427 else
428 *hole_offset = k8_dhar_offset(pvt->dhar);
429
430 debugf1(" DHAR info for node %d base 0x%lx offset 0x%lx size 0x%lx\n",
431 pvt->mc_node_id, (unsigned long)*hole_base,
432 (unsigned long)*hole_offset, (unsigned long)*hole_size);
433
434 return 0;
435}
436EXPORT_SYMBOL_GPL(amd64_get_dram_hole_info);
437
438/*
439 * Return the DramAddr that the SysAddr given by @sys_addr maps to. It is
440 * assumed that sys_addr maps to the node given by mci.
441 *
442 * The first part of section 3.4.4 (p. 70) shows how the DRAM Base (section
443 * 3.4.4.1) and DRAM Limit (section 3.4.4.2) registers are used to translate a
444 * SysAddr to a DramAddr. If the DRAM Hole Address Register (DHAR) is enabled,
445 * then it is also involved in translating a SysAddr to a DramAddr. Sections
446 * 3.4.8 and 3.5.8.2 describe the DHAR and how it is used for memory hoisting.
447 * These parts of the documentation are unclear. I interpret them as follows:
448 *
449 * When node n receives a SysAddr, it processes the SysAddr as follows:
450 *
451 * 1. It extracts the DRAMBase and DRAMLimit values from the DRAM Base and DRAM
452 * Limit registers for node n. If the SysAddr is not within the range
453 * specified by the base and limit values, then node n ignores the Sysaddr
454 * (since it does not map to node n). Otherwise continue to step 2 below.
455 *
456 * 2. If the DramHoleValid bit of the DHAR for node n is clear, the DHAR is
457 * disabled so skip to step 3 below. Otherwise see if the SysAddr is within
458 * the range of relocated addresses (starting at 0x100000000) from the DRAM
459 * hole. If not, skip to step 3 below. Else get the value of the
460 * DramHoleOffset field from the DHAR. To obtain the DramAddr, subtract the
461 * offset defined by this value from the SysAddr.
462 *
463 * 3. Obtain the base address for node n from the DRAMBase field of the DRAM
464 * Base register for node n. To obtain the DramAddr, subtract the base
465 * address from the SysAddr, as shown near the start of section 3.4.4 (p.70).
466 */
467static u64 sys_addr_to_dram_addr(struct mem_ctl_info *mci, u64 sys_addr)
468{
469 u64 dram_base, hole_base, hole_offset, hole_size, dram_addr;
470 int ret = 0;
471
472 dram_base = get_dram_base(mci);
473
474 ret = amd64_get_dram_hole_info(mci, &hole_base, &hole_offset,
475 &hole_size);
476 if (!ret) {
477 if ((sys_addr >= (1ull << 32)) &&
478 (sys_addr < ((1ull << 32) + hole_size))) {
479 /* use DHAR to translate SysAddr to DramAddr */
480 dram_addr = sys_addr - hole_offset;
481
482 debugf2("using DHAR to translate SysAddr 0x%lx to "
483 "DramAddr 0x%lx\n",
484 (unsigned long)sys_addr,
485 (unsigned long)dram_addr);
486
487 return dram_addr;
488 }
489 }
490
491 /*
492 * Translate the SysAddr to a DramAddr as shown near the start of
493 * section 3.4.4 (p. 70). Although sys_addr is a 64-bit value, the k8
494 * only deals with 40-bit values. Therefore we discard bits 63-40 of
495 * sys_addr below. If bit 39 of sys_addr is 1 then the bits we
496 * discard are all 1s. Otherwise the bits we discard are all 0s. See
497 * section 3.4.2 of AMD publication 24592: AMD x86-64 Architecture
498 * Programmer's Manual Volume 1 Application Programming.
499 */
500 dram_addr = (sys_addr & 0xffffffffffull) - dram_base;
501
502 debugf2("using DRAM Base register to translate SysAddr 0x%lx to "
503 "DramAddr 0x%lx\n", (unsigned long)sys_addr,
504 (unsigned long)dram_addr);
505 return dram_addr;
506}
507
508/*
509 * @intlv_en is the value of the IntlvEn field from a DRAM Base register
510 * (section 3.4.4.1). Return the number of bits from a SysAddr that are used
511 * for node interleaving.
512 */
513static int num_node_interleave_bits(unsigned intlv_en)
514{
515 static const int intlv_shift_table[] = { 0, 1, 0, 2, 0, 0, 0, 3 };
516 int n;
517
518 BUG_ON(intlv_en > 7);
519 n = intlv_shift_table[intlv_en];
520 return n;
521}
522
523/* Translate the DramAddr given by @dram_addr to an InputAddr. */
524static u64 dram_addr_to_input_addr(struct mem_ctl_info *mci, u64 dram_addr)
525{
526 struct amd64_pvt *pvt;
527 int intlv_shift;
528 u64 input_addr;
529
530 pvt = mci->pvt_info;
531
532 /*
533 * See the start of section 3.4.4 (p. 70, BKDG #26094, K8, revA-E)
534 * concerning translating a DramAddr to an InputAddr.
535 */
536 intlv_shift = num_node_interleave_bits(pvt->dram_IntlvEn[0]);
537 input_addr = ((dram_addr >> intlv_shift) & 0xffffff000ull) +
538 (dram_addr & 0xfff);
539
540 debugf2(" Intlv Shift=%d DramAddr=0x%lx maps to InputAddr=0x%lx\n",
541 intlv_shift, (unsigned long)dram_addr,
542 (unsigned long)input_addr);
543
544 return input_addr;
545}
546
547/*
548 * Translate the SysAddr represented by @sys_addr to an InputAddr. It is
549 * assumed that @sys_addr maps to the node given by mci.
550 */
551static u64 sys_addr_to_input_addr(struct mem_ctl_info *mci, u64 sys_addr)
552{
553 u64 input_addr;
554
555 input_addr =
556 dram_addr_to_input_addr(mci, sys_addr_to_dram_addr(mci, sys_addr));
557
558 debugf2("SysAdddr 0x%lx translates to InputAddr 0x%lx\n",
559 (unsigned long)sys_addr, (unsigned long)input_addr);
560
561 return input_addr;
562}
563
564
565/*
566 * @input_addr is an InputAddr associated with the node represented by mci.
567 * Translate @input_addr to a DramAddr and return the result.
568 */
569static u64 input_addr_to_dram_addr(struct mem_ctl_info *mci, u64 input_addr)
570{
571 struct amd64_pvt *pvt;
572 int node_id, intlv_shift;
573 u64 bits, dram_addr;
574 u32 intlv_sel;
575
576 /*
577 * Near the start of section 3.4.4 (p. 70, BKDG #26094, K8, revA-E)
578 * shows how to translate a DramAddr to an InputAddr. Here we reverse
579 * this procedure. When translating from a DramAddr to an InputAddr, the
580 * bits used for node interleaving are discarded. Here we recover these
581 * bits from the IntlvSel field of the DRAM Limit register (section
582 * 3.4.4.2) for the node that input_addr is associated with.
583 */
584 pvt = mci->pvt_info;
585 node_id = pvt->mc_node_id;
586 BUG_ON((node_id < 0) || (node_id > 7));
587
588 intlv_shift = num_node_interleave_bits(pvt->dram_IntlvEn[0]);
589
590 if (intlv_shift == 0) {
591 debugf1(" InputAddr 0x%lx translates to DramAddr of "
592 "same value\n", (unsigned long)input_addr);
593
594 return input_addr;
595 }
596
597 bits = ((input_addr & 0xffffff000ull) << intlv_shift) +
598 (input_addr & 0xfff);
599
600 intlv_sel = pvt->dram_IntlvSel[node_id] & ((1 << intlv_shift) - 1);
601 dram_addr = bits + (intlv_sel << 12);
602
603 debugf1("InputAddr 0x%lx translates to DramAddr 0x%lx "
604 "(%d node interleave bits)\n", (unsigned long)input_addr,
605 (unsigned long)dram_addr, intlv_shift);
606
607 return dram_addr;
608}
609
610/*
611 * @dram_addr is a DramAddr that maps to the node represented by mci. Convert
612 * @dram_addr to a SysAddr.
613 */
614static u64 dram_addr_to_sys_addr(struct mem_ctl_info *mci, u64 dram_addr)
615{
616 struct amd64_pvt *pvt = mci->pvt_info;
617 u64 hole_base, hole_offset, hole_size, base, limit, sys_addr;
618 int ret = 0;
619
620 ret = amd64_get_dram_hole_info(mci, &hole_base, &hole_offset,
621 &hole_size);
622 if (!ret) {
623 if ((dram_addr >= hole_base) &&
624 (dram_addr < (hole_base + hole_size))) {
625 sys_addr = dram_addr + hole_offset;
626
627 debugf1("using DHAR to translate DramAddr 0x%lx to "
628 "SysAddr 0x%lx\n", (unsigned long)dram_addr,
629 (unsigned long)sys_addr);
630
631 return sys_addr;
632 }
633 }
634
635 amd64_get_base_and_limit(pvt, pvt->mc_node_id, &base, &limit);
636 sys_addr = dram_addr + base;
637
638 /*
639 * The sys_addr we have computed up to this point is a 40-bit value
640 * because the k8 deals with 40-bit values. However, the value we are
641 * supposed to return is a full 64-bit physical address. The AMD
642 * x86-64 architecture specifies that the most significant implemented
643 * address bit through bit 63 of a physical address must be either all
644 * 0s or all 1s. Therefore we sign-extend the 40-bit sys_addr to a
645 * 64-bit value below. See section 3.4.2 of AMD publication 24592:
646 * AMD x86-64 Architecture Programmer's Manual Volume 1 Application
647 * Programming.
648 */
649 sys_addr |= ~((sys_addr & (1ull << 39)) - 1);
650
651 debugf1(" Node %d, DramAddr 0x%lx to SysAddr 0x%lx\n",
652 pvt->mc_node_id, (unsigned long)dram_addr,
653 (unsigned long)sys_addr);
654
655 return sys_addr;
656}
657
658/*
659 * @input_addr is an InputAddr associated with the node given by mci. Translate
660 * @input_addr to a SysAddr.
661 */
662static inline u64 input_addr_to_sys_addr(struct mem_ctl_info *mci,
663 u64 input_addr)
664{
665 return dram_addr_to_sys_addr(mci,
666 input_addr_to_dram_addr(mci, input_addr));
667}
668
669/*
670 * Find the minimum and maximum InputAddr values that map to the given @csrow.
671 * Pass back these values in *input_addr_min and *input_addr_max.
672 */
673static void find_csrow_limits(struct mem_ctl_info *mci, int csrow,
674 u64 *input_addr_min, u64 *input_addr_max)
675{
676 struct amd64_pvt *pvt;
677 u64 base, mask;
678
679 pvt = mci->pvt_info;
680 BUG_ON((csrow < 0) || (csrow >= CHIPSELECT_COUNT));
681
682 base = base_from_dct_base(pvt, csrow);
683 mask = mask_from_dct_mask(pvt, csrow);
684
685 *input_addr_min = base & ~mask;
686 *input_addr_max = base | mask | pvt->dcs_mask_notused;
687}
688
689/*
690 * Extract error address from MCA NB Address Low (section 3.6.4.5) and MCA NB
691 * Address High (section 3.6.4.6) register values and return the result. Address
692 * is located in the info structure (nbeah and nbeal), the encoding is device
693 * specific.
694 */
695static u64 extract_error_address(struct mem_ctl_info *mci,
696 struct amd64_error_info_regs *info)
697{
698 struct amd64_pvt *pvt = mci->pvt_info;
699
700 return pvt->ops->get_error_address(mci, info);
701}
702
703
704/* Map the Error address to a PAGE and PAGE OFFSET. */
705static inline void error_address_to_page_and_offset(u64 error_address,
706 u32 *page, u32 *offset)
707{
708 *page = (u32) (error_address >> PAGE_SHIFT);
709 *offset = ((u32) error_address) & ~PAGE_MASK;
710}
711
712/*
713 * @sys_addr is an error address (a SysAddr) extracted from the MCA NB Address
714 * Low (section 3.6.4.5) and MCA NB Address High (section 3.6.4.6) registers
715 * of a node that detected an ECC memory error. mci represents the node that
716 * the error address maps to (possibly different from the node that detected
717 * the error). Return the number of the csrow that sys_addr maps to, or -1 on
718 * error.
719 */
720static int sys_addr_to_csrow(struct mem_ctl_info *mci, u64 sys_addr)
721{
722 int csrow;
723
724 csrow = input_addr_to_csrow(mci, sys_addr_to_input_addr(mci, sys_addr));
725
726 if (csrow == -1)
727 amd64_mc_printk(mci, KERN_ERR,
728 "Failed to translate InputAddr to csrow for "
729 "address 0x%lx\n", (unsigned long)sys_addr);
730 return csrow;
731}
732
733static int get_channel_from_ecc_syndrome(unsigned short syndrome);
734
735static void amd64_cpu_display_info(struct amd64_pvt *pvt)
736{
737 if (boot_cpu_data.x86 == 0x11)
738 edac_printk(KERN_DEBUG, EDAC_MC, "F11h CPU detected\n");
739 else if (boot_cpu_data.x86 == 0x10)
740 edac_printk(KERN_DEBUG, EDAC_MC, "F10h CPU detected\n");
741 else if (boot_cpu_data.x86 == 0xf)
742 edac_printk(KERN_DEBUG, EDAC_MC, "%s detected\n",
743 (pvt->ext_model >= OPTERON_CPU_REV_F) ?
744 "Rev F or later" : "Rev E or earlier");
745 else
746 /* we'll hardly ever ever get here */
747 edac_printk(KERN_ERR, EDAC_MC, "Unknown cpu!\n");
748}
749
750/*
751 * Determine if the DIMMs have ECC enabled. ECC is enabled ONLY if all the DIMMs
752 * are ECC capable.
753 */
754static enum edac_type amd64_determine_edac_cap(struct amd64_pvt *pvt)
755{
756 int bit;
757 enum dev_type edac_cap = EDAC_NONE;
758
759 bit = (boot_cpu_data.x86 > 0xf || pvt->ext_model >= OPTERON_CPU_REV_F)
760 ? 19
761 : 17;
762
763 if (pvt->dclr0 >> BIT(bit))
764 edac_cap = EDAC_FLAG_SECDED;
765
766 return edac_cap;
767}
768
769
770static void f10_debug_display_dimm_sizes(int ctrl, struct amd64_pvt *pvt,
771 int ganged);
772
773/* Display and decode various NB registers for debug purposes. */
774static void amd64_dump_misc_regs(struct amd64_pvt *pvt)
775{
776 int ganged;
777
778 debugf1(" nbcap:0x%8.08x DctDualCap=%s DualNode=%s 8-Node=%s\n",
779 pvt->nbcap,
780 (pvt->nbcap & K8_NBCAP_DCT_DUAL) ? "True" : "False",
781 (pvt->nbcap & K8_NBCAP_DUAL_NODE) ? "True" : "False",
782 (pvt->nbcap & K8_NBCAP_8_NODE) ? "True" : "False");
783 debugf1(" ECC Capable=%s ChipKill Capable=%s\n",
784 (pvt->nbcap & K8_NBCAP_SECDED) ? "True" : "False",
785 (pvt->nbcap & K8_NBCAP_CHIPKILL) ? "True" : "False");
786 debugf1(" DramCfg0-low=0x%08x DIMM-ECC=%s Parity=%s Width=%s\n",
787 pvt->dclr0,
788 (pvt->dclr0 & BIT(19)) ? "Enabled" : "Disabled",
789 (pvt->dclr0 & BIT(8)) ? "Enabled" : "Disabled",
790 (pvt->dclr0 & BIT(11)) ? "128b" : "64b");
791 debugf1(" DIMM x4 Present: L0=%s L1=%s L2=%s L3=%s DIMM Type=%s\n",
792 (pvt->dclr0 & BIT(12)) ? "Y" : "N",
793 (pvt->dclr0 & BIT(13)) ? "Y" : "N",
794 (pvt->dclr0 & BIT(14)) ? "Y" : "N",
795 (pvt->dclr0 & BIT(15)) ? "Y" : "N",
796 (pvt->dclr0 & BIT(16)) ? "UN-Buffered" : "Buffered");
797
798
799 debugf1(" online-spare: 0x%8.08x\n", pvt->online_spare);
800
801 if (boot_cpu_data.x86 == 0xf) {
802 debugf1(" dhar: 0x%8.08x Base=0x%08x Offset=0x%08x\n",
803 pvt->dhar, dhar_base(pvt->dhar),
804 k8_dhar_offset(pvt->dhar));
805 debugf1(" DramHoleValid=%s\n",
806 (pvt->dhar & DHAR_VALID) ? "True" : "False");
807
808 debugf1(" dbam-dkt: 0x%8.08x\n", pvt->dbam0);
809
810 /* everything below this point is Fam10h and above */
811 return;
812
813 } else {
814 debugf1(" dhar: 0x%8.08x Base=0x%08x Offset=0x%08x\n",
815 pvt->dhar, dhar_base(pvt->dhar),
816 f10_dhar_offset(pvt->dhar));
817 debugf1(" DramMemHoistValid=%s DramHoleValid=%s\n",
818 (pvt->dhar & F10_DRAM_MEM_HOIST_VALID) ?
819 "True" : "False",
820 (pvt->dhar & DHAR_VALID) ?
821 "True" : "False");
822 }
823
824 /* Only if NOT ganged does dcl1 have valid info */
825 if (!dct_ganging_enabled(pvt)) {
826 debugf1(" DramCfg1-low=0x%08x DIMM-ECC=%s Parity=%s "
827 "Width=%s\n", pvt->dclr1,
828 (pvt->dclr1 & BIT(19)) ? "Enabled" : "Disabled",
829 (pvt->dclr1 & BIT(8)) ? "Enabled" : "Disabled",
830 (pvt->dclr1 & BIT(11)) ? "128b" : "64b");
831 debugf1(" DIMM x4 Present: L0=%s L1=%s L2=%s L3=%s "
832 "DIMM Type=%s\n",
833 (pvt->dclr1 & BIT(12)) ? "Y" : "N",
834 (pvt->dclr1 & BIT(13)) ? "Y" : "N",
835 (pvt->dclr1 & BIT(14)) ? "Y" : "N",
836 (pvt->dclr1 & BIT(15)) ? "Y" : "N",
837 (pvt->dclr1 & BIT(16)) ? "UN-Buffered" : "Buffered");
838 }
839
840 /*
841 * Determine if ganged and then dump memory sizes for first controller,
842 * and if NOT ganged dump info for 2nd controller.
843 */
844 ganged = dct_ganging_enabled(pvt);
845
846 f10_debug_display_dimm_sizes(0, pvt, ganged);
847
848 if (!ganged)
849 f10_debug_display_dimm_sizes(1, pvt, ganged);
850}
851
852/* Read in both of DBAM registers */
853static void amd64_read_dbam_reg(struct amd64_pvt *pvt)
854{
855 int err = 0;
856 unsigned int reg;
857
858 reg = DBAM0;
859 err = pci_read_config_dword(pvt->dram_f2_ctl, reg, &pvt->dbam0);
860 if (err)
861 goto err_reg;
862
863 if (boot_cpu_data.x86 >= 0x10) {
864 reg = DBAM1;
865 err = pci_read_config_dword(pvt->dram_f2_ctl, reg, &pvt->dbam1);
866
867 if (err)
868 goto err_reg;
869 }
870
871err_reg:
872 debugf0("Error reading F2x%03x.\n", reg);
873}
874
875/*
876 * NOTE: CPU Revision Dependent code: Rev E and Rev F
877 *
878 * Set the DCSB and DCSM mask values depending on the CPU revision value. Also
879 * set the shift factor for the DCSB and DCSM values.
880 *
881 * ->dcs_mask_notused, RevE:
882 *
883 * To find the max InputAddr for the csrow, start with the base address and set
884 * all bits that are "don't care" bits in the test at the start of section
885 * 3.5.4 (p. 84).
886 *
887 * The "don't care" bits are all set bits in the mask and all bits in the gaps
888 * between bit ranges [35:25] and [19:13]. The value REV_E_DCS_NOTUSED_BITS
889 * represents bits [24:20] and [12:0], which are all bits in the above-mentioned
890 * gaps.
891 *
892 * ->dcs_mask_notused, RevF and later:
893 *
894 * To find the max InputAddr for the csrow, start with the base address and set
895 * all bits that are "don't care" bits in the test at the start of NPT section
896 * 4.5.4 (p. 87).
897 *
898 * The "don't care" bits are all set bits in the mask and all bits in the gaps
899 * between bit ranges [36:27] and [21:13].
900 *
901 * The value REV_F_F1Xh_DCS_NOTUSED_BITS represents bits [26:22] and [12:0],
902 * which are all bits in the above-mentioned gaps.
903 */
904static void amd64_set_dct_base_and_mask(struct amd64_pvt *pvt)
905{
906 if (pvt->ext_model >= OPTERON_CPU_REV_F) {
907 pvt->dcsb_base = REV_F_F1Xh_DCSB_BASE_BITS;
908 pvt->dcsm_mask = REV_F_F1Xh_DCSM_MASK_BITS;
909 pvt->dcs_mask_notused = REV_F_F1Xh_DCS_NOTUSED_BITS;
910 pvt->dcs_shift = REV_F_F1Xh_DCS_SHIFT;
911
912 switch (boot_cpu_data.x86) {
913 case 0xf:
914 pvt->num_dcsm = REV_F_DCSM_COUNT;
915 break;
916
917 case 0x10:
918 pvt->num_dcsm = F10_DCSM_COUNT;
919 break;
920
921 case 0x11:
922 pvt->num_dcsm = F11_DCSM_COUNT;
923 break;
924
925 default:
926 amd64_printk(KERN_ERR, "Unsupported family!\n");
927 break;
928 }
929 } else {
930 pvt->dcsb_base = REV_E_DCSB_BASE_BITS;
931 pvt->dcsm_mask = REV_E_DCSM_MASK_BITS;
932 pvt->dcs_mask_notused = REV_E_DCS_NOTUSED_BITS;
933 pvt->dcs_shift = REV_E_DCS_SHIFT;
934 pvt->num_dcsm = REV_E_DCSM_COUNT;
935 }
936}
937
938/*
939 * Function 2 Offset F10_DCSB0; read in the DCS Base and DCS Mask hw registers
940 */
941static void amd64_read_dct_base_mask(struct amd64_pvt *pvt)
942{
943 int cs, reg, err = 0;
944
945 amd64_set_dct_base_and_mask(pvt);
946
947 for (cs = 0; cs < CHIPSELECT_COUNT; cs++) {
948 reg = K8_DCSB0 + (cs * 4);
949 err = pci_read_config_dword(pvt->dram_f2_ctl, reg,
950 &pvt->dcsb0[cs]);
951 if (unlikely(err))
952 debugf0("Reading K8_DCSB0[%d] failed\n", cs);
953 else
954 debugf0(" DCSB0[%d]=0x%08x reg: F2x%x\n",
955 cs, pvt->dcsb0[cs], reg);
956
957 /* If DCT are NOT ganged, then read in DCT1's base */
958 if (boot_cpu_data.x86 >= 0x10 && !dct_ganging_enabled(pvt)) {
959 reg = F10_DCSB1 + (cs * 4);
960 err = pci_read_config_dword(pvt->dram_f2_ctl, reg,
961 &pvt->dcsb1[cs]);
962 if (unlikely(err))
963 debugf0("Reading F10_DCSB1[%d] failed\n", cs);
964 else
965 debugf0(" DCSB1[%d]=0x%08x reg: F2x%x\n",
966 cs, pvt->dcsb1[cs], reg);
967 } else {
968 pvt->dcsb1[cs] = 0;
969 }
970 }
971
972 for (cs = 0; cs < pvt->num_dcsm; cs++) {
973 reg = K8_DCSB0 + (cs * 4);
974 err = pci_read_config_dword(pvt->dram_f2_ctl, reg,
975 &pvt->dcsm0[cs]);
976 if (unlikely(err))
977 debugf0("Reading K8_DCSM0 failed\n");
978 else
979 debugf0(" DCSM0[%d]=0x%08x reg: F2x%x\n",
980 cs, pvt->dcsm0[cs], reg);
981
982 /* If DCT are NOT ganged, then read in DCT1's mask */
983 if (boot_cpu_data.x86 >= 0x10 && !dct_ganging_enabled(pvt)) {
984 reg = F10_DCSM1 + (cs * 4);
985 err = pci_read_config_dword(pvt->dram_f2_ctl, reg,
986 &pvt->dcsm1[cs]);
987 if (unlikely(err))
988 debugf0("Reading F10_DCSM1[%d] failed\n", cs);
989 else
990 debugf0(" DCSM1[%d]=0x%08x reg: F2x%x\n",
991 cs, pvt->dcsm1[cs], reg);
992 } else
993 pvt->dcsm1[cs] = 0;
994 }
995}
996
997static enum mem_type amd64_determine_memory_type(struct amd64_pvt *pvt)
998{
999 enum mem_type type;
1000
1001 if (boot_cpu_data.x86 >= 0x10 || pvt->ext_model >= OPTERON_CPU_REV_F) {
1002 /* Rev F and later */
1003 type = (pvt->dclr0 & BIT(16)) ? MEM_DDR2 : MEM_RDDR2;
1004 } else {
1005 /* Rev E and earlier */
1006 type = (pvt->dclr0 & BIT(18)) ? MEM_DDR : MEM_RDDR;
1007 }
1008
1009 debugf1(" Memory type is: %s\n",
1010 (type == MEM_DDR2) ? "MEM_DDR2" :
1011 (type == MEM_RDDR2) ? "MEM_RDDR2" :
1012 (type == MEM_DDR) ? "MEM_DDR" : "MEM_RDDR");
1013
1014 return type;
1015}
1016
1017/*
1018 * Read the DRAM Configuration Low register. It differs between CG, D & E revs
1019 * and the later RevF memory controllers (DDR vs DDR2)
1020 *
1021 * Return:
1022 * number of memory channels in operation
1023 * Pass back:
1024 * contents of the DCL0_LOW register
1025 */
1026static int k8_early_channel_count(struct amd64_pvt *pvt)
1027{
1028 int flag, err = 0;
1029
1030 err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCLR_0, &pvt->dclr0);
1031 if (err)
1032 return err;
1033
1034 if ((boot_cpu_data.x86_model >> 4) >= OPTERON_CPU_REV_F) {
1035 /* RevF (NPT) and later */
1036 flag = pvt->dclr0 & F10_WIDTH_128;
1037 } else {
1038 /* RevE and earlier */
1039 flag = pvt->dclr0 & REVE_WIDTH_128;
1040 }
1041
1042 /* not used */
1043 pvt->dclr1 = 0;
1044
1045 return (flag) ? 2 : 1;
1046}
1047
1048/* extract the ERROR ADDRESS for the K8 CPUs */
1049static u64 k8_get_error_address(struct mem_ctl_info *mci,
1050 struct amd64_error_info_regs *info)
1051{
1052 return (((u64) (info->nbeah & 0xff)) << 32) +
1053 (info->nbeal & ~0x03);
1054}
1055
1056/*
1057 * Read the Base and Limit registers for K8 based Memory controllers; extract
1058 * fields from the 'raw' reg into separate data fields
1059 *
1060 * Isolates: BASE, LIMIT, IntlvEn, IntlvSel, RW_EN
1061 */
1062static void k8_read_dram_base_limit(struct amd64_pvt *pvt, int dram)
1063{
1064 u32 low;
1065 u32 off = dram << 3; /* 8 bytes between DRAM entries */
1066 int err;
1067
1068 err = pci_read_config_dword(pvt->addr_f1_ctl,
1069 K8_DRAM_BASE_LOW + off, &low);
1070 if (err)
1071 debugf0("Reading K8_DRAM_BASE_LOW failed\n");
1072
1073 /* Extract parts into separate data entries */
1074 pvt->dram_base[dram] = ((u64) low & 0xFFFF0000) << 8;
1075 pvt->dram_IntlvEn[dram] = (low >> 8) & 0x7;
1076 pvt->dram_rw_en[dram] = (low & 0x3);
1077
1078 err = pci_read_config_dword(pvt->addr_f1_ctl,
1079 K8_DRAM_LIMIT_LOW + off, &low);
1080 if (err)
1081 debugf0("Reading K8_DRAM_LIMIT_LOW failed\n");
1082
1083 /*
1084 * Extract parts into separate data entries. Limit is the HIGHEST memory
1085 * location of the region, so lower 24 bits need to be all ones
1086 */
1087 pvt->dram_limit[dram] = (((u64) low & 0xFFFF0000) << 8) | 0x00FFFFFF;
1088 pvt->dram_IntlvSel[dram] = (low >> 8) & 0x7;
1089 pvt->dram_DstNode[dram] = (low & 0x7);
1090}
1091
1092static void k8_map_sysaddr_to_csrow(struct mem_ctl_info *mci,
1093 struct amd64_error_info_regs *info,
1094 u64 SystemAddress)
1095{
1096 struct mem_ctl_info *src_mci;
1097 unsigned short syndrome;
1098 int channel, csrow;
1099 u32 page, offset;
1100
1101 /* Extract the syndrome parts and form a 16-bit syndrome */
1102 syndrome = EXTRACT_HIGH_SYNDROME(info->nbsl) << 8;
1103 syndrome |= EXTRACT_LOW_SYNDROME(info->nbsh);
1104
1105 /* CHIPKILL enabled */
1106 if (info->nbcfg & K8_NBCFG_CHIPKILL) {
1107 channel = get_channel_from_ecc_syndrome(syndrome);
1108 if (channel < 0) {
1109 /*
1110 * Syndrome didn't map, so we don't know which of the
1111 * 2 DIMMs is in error. So we need to ID 'both' of them
1112 * as suspect.
1113 */
1114 amd64_mc_printk(mci, KERN_WARNING,
1115 "unknown syndrome 0x%x - possible error "
1116 "reporting race\n", syndrome);
1117 edac_mc_handle_ce_no_info(mci, EDAC_MOD_STR);
1118 return;
1119 }
1120 } else {
1121 /*
1122 * non-chipkill ecc mode
1123 *
1124 * The k8 documentation is unclear about how to determine the
1125 * channel number when using non-chipkill memory. This method
1126 * was obtained from email communication with someone at AMD.
1127 * (Wish the email was placed in this comment - norsk)
1128 */
1129 channel = ((SystemAddress & BIT(3)) != 0);
1130 }
1131
1132 /*
1133 * Find out which node the error address belongs to. This may be
1134 * different from the node that detected the error.
1135 */
1136 src_mci = find_mc_by_sys_addr(mci, SystemAddress);
1137 if (src_mci) {
1138 amd64_mc_printk(mci, KERN_ERR,
1139 "failed to map error address 0x%lx to a node\n",
1140 (unsigned long)SystemAddress);
1141 edac_mc_handle_ce_no_info(mci, EDAC_MOD_STR);
1142 return;
1143 }
1144
1145 /* Now map the SystemAddress to a CSROW */
1146 csrow = sys_addr_to_csrow(src_mci, SystemAddress);
1147 if (csrow < 0) {
1148 edac_mc_handle_ce_no_info(src_mci, EDAC_MOD_STR);
1149 } else {
1150 error_address_to_page_and_offset(SystemAddress, &page, &offset);
1151
1152 edac_mc_handle_ce(src_mci, page, offset, syndrome, csrow,
1153 channel, EDAC_MOD_STR);
1154 }
1155}
1156
1157/*
1158 * determrine the number of PAGES in for this DIMM's size based on its DRAM
1159 * Address Mapping.
1160 *
1161 * First step is to calc the number of bits to shift a value of 1 left to
1162 * indicate show many pages. Start with the DBAM value as the starting bits,
1163 * then proceed to adjust those shift bits, based on CPU rev and the table.
1164 * See BKDG on the DBAM
1165 */
1166static int k8_dbam_map_to_pages(struct amd64_pvt *pvt, int dram_map)
1167{
1168 int nr_pages;
1169
1170 if (pvt->ext_model >= OPTERON_CPU_REV_F) {
1171 nr_pages = 1 << (revf_quad_ddr2_shift[dram_map] - PAGE_SHIFT);
1172 } else {
1173 /*
1174 * RevE and less section; this line is tricky. It collapses the
1175 * table used by RevD and later to one that matches revisions CG
1176 * and earlier.
1177 */
1178 dram_map -= (pvt->ext_model >= OPTERON_CPU_REV_D) ?
1179 (dram_map > 8 ? 4 : (dram_map > 5 ?
1180 3 : (dram_map > 2 ? 1 : 0))) : 0;
1181
1182 /* 25 shift is 32MiB minimum DIMM size in RevE and prior */
1183 nr_pages = 1 << (dram_map + 25 - PAGE_SHIFT);
1184 }
1185
1186 return nr_pages;
1187}
1188
1189/*
1190 * Get the number of DCT channels in use.
1191 *
1192 * Return:
1193 * number of Memory Channels in operation
1194 * Pass back:
1195 * contents of the DCL0_LOW register
1196 */
1197static int f10_early_channel_count(struct amd64_pvt *pvt)
1198{
1199 int err = 0, channels = 0;
1200 u32 dbam;
1201
1202 err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCLR_0, &pvt->dclr0);
1203 if (err)
1204 goto err_reg;
1205
1206 err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCLR_1, &pvt->dclr1);
1207 if (err)
1208 goto err_reg;
1209
1210 /* If we are in 128 bit mode, then we are using 2 channels */
1211 if (pvt->dclr0 & F10_WIDTH_128) {
1212 debugf0("Data WIDTH is 128 bits - 2 channels\n");
1213 channels = 2;
1214 return channels;
1215 }
1216
1217 /*
1218 * Need to check if in UN-ganged mode: In such, there are 2 channels,
1219 * but they are NOT in 128 bit mode and thus the above 'dcl0' status bit
1220 * will be OFF.
1221 *
1222 * Need to check DCT0[0] and DCT1[0] to see if only one of them has
1223 * their CSEnable bit on. If so, then SINGLE DIMM case.
1224 */
1225 debugf0("Data WIDTH is NOT 128 bits - need more decoding\n");
1226
1227 /*
1228 * Check DRAM Bank Address Mapping values for each DIMM to see if there
1229 * is more than just one DIMM present in unganged mode. Need to check
1230 * both controllers since DIMMs can be placed in either one.
1231 */
1232 channels = 0;
1233 err = pci_read_config_dword(pvt->dram_f2_ctl, DBAM0, &dbam);
1234 if (err)
1235 goto err_reg;
1236
1237 if (DBAM_DIMM(0, dbam) > 0)
1238 channels++;
1239 if (DBAM_DIMM(1, dbam) > 0)
1240 channels++;
1241 if (DBAM_DIMM(2, dbam) > 0)
1242 channels++;
1243 if (DBAM_DIMM(3, dbam) > 0)
1244 channels++;
1245
1246 /* If more than 2 DIMMs are present, then we have 2 channels */
1247 if (channels > 2)
1248 channels = 2;
1249 else if (channels == 0) {
1250 /* No DIMMs on DCT0, so look at DCT1 */
1251 err = pci_read_config_dword(pvt->dram_f2_ctl, DBAM1, &dbam);
1252 if (err)
1253 goto err_reg;
1254
1255 if (DBAM_DIMM(0, dbam) > 0)
1256 channels++;
1257 if (DBAM_DIMM(1, dbam) > 0)
1258 channels++;
1259 if (DBAM_DIMM(2, dbam) > 0)
1260 channels++;
1261 if (DBAM_DIMM(3, dbam) > 0)
1262 channels++;
1263
1264 if (channels > 2)
1265 channels = 2;
1266 }
1267
1268 /* If we found ALL 0 values, then assume just ONE DIMM-ONE Channel */
1269 if (channels == 0)
1270 channels = 1;
1271
1272 debugf0("DIMM count= %d\n", channels);
1273
1274 return channels;
1275
1276err_reg:
1277 return -1;
1278
1279}
1280
1281static int f10_dbam_map_to_pages(struct amd64_pvt *pvt, int dram_map)
1282{
1283 return 1 << (revf_quad_ddr2_shift[dram_map] - PAGE_SHIFT);
1284}
1285
1286/* Enable extended configuration access via 0xCF8 feature */
1287static void amd64_setup(struct amd64_pvt *pvt)
1288{
1289 u32 reg;
1290
1291 pci_read_config_dword(pvt->misc_f3_ctl, F10_NB_CFG_HIGH, &reg);
1292
1293 pvt->flags.cf8_extcfg = !!(reg & F10_NB_CFG_LOW_ENABLE_EXT_CFG);
1294 reg |= F10_NB_CFG_LOW_ENABLE_EXT_CFG;
1295 pci_write_config_dword(pvt->misc_f3_ctl, F10_NB_CFG_HIGH, reg);
1296}
1297
1298/* Restore the extended configuration access via 0xCF8 feature */
1299static void amd64_teardown(struct amd64_pvt *pvt)
1300{
1301 u32 reg;
1302
1303 pci_read_config_dword(pvt->misc_f3_ctl, F10_NB_CFG_HIGH, &reg);
1304
1305 reg &= ~F10_NB_CFG_LOW_ENABLE_EXT_CFG;
1306 if (pvt->flags.cf8_extcfg)
1307 reg |= F10_NB_CFG_LOW_ENABLE_EXT_CFG;
1308 pci_write_config_dword(pvt->misc_f3_ctl, F10_NB_CFG_HIGH, reg);
1309}
1310
1311static u64 f10_get_error_address(struct mem_ctl_info *mci,
1312 struct amd64_error_info_regs *info)
1313{
1314 return (((u64) (info->nbeah & 0xffff)) << 32) +
1315 (info->nbeal & ~0x01);
1316}
1317
1318/*
1319 * Read the Base and Limit registers for F10 based Memory controllers. Extract
1320 * fields from the 'raw' reg into separate data fields.
1321 *
1322 * Isolates: BASE, LIMIT, IntlvEn, IntlvSel, RW_EN.
1323 */
1324static void f10_read_dram_base_limit(struct amd64_pvt *pvt, int dram)
1325{
1326 u32 high_offset, low_offset, high_base, low_base, high_limit, low_limit;
1327
1328 low_offset = K8_DRAM_BASE_LOW + (dram << 3);
1329 high_offset = F10_DRAM_BASE_HIGH + (dram << 3);
1330
1331 /* read the 'raw' DRAM BASE Address register */
1332 pci_read_config_dword(pvt->addr_f1_ctl, low_offset, &low_base);
1333
1334 /* Read from the ECS data register */
1335 pci_read_config_dword(pvt->addr_f1_ctl, high_offset, &high_base);
1336
1337 /* Extract parts into separate data entries */
1338 pvt->dram_rw_en[dram] = (low_base & 0x3);
1339
1340 if (pvt->dram_rw_en[dram] == 0)
1341 return;
1342
1343 pvt->dram_IntlvEn[dram] = (low_base >> 8) & 0x7;
1344
1345 pvt->dram_base[dram] = (((((u64) high_base & 0x000000FF) << 32) |
1346 ((u64) low_base & 0xFFFF0000))) << 8;
1347
1348 low_offset = K8_DRAM_LIMIT_LOW + (dram << 3);
1349 high_offset = F10_DRAM_LIMIT_HIGH + (dram << 3);
1350
1351 /* read the 'raw' LIMIT registers */
1352 pci_read_config_dword(pvt->addr_f1_ctl, low_offset, &low_limit);
1353
1354 /* Read from the ECS data register for the HIGH portion */
1355 pci_read_config_dword(pvt->addr_f1_ctl, high_offset, &high_limit);
1356
1357 debugf0(" HW Regs: BASE=0x%08x-%08x LIMIT= 0x%08x-%08x\n",
1358 high_base, low_base, high_limit, low_limit);
1359
1360 pvt->dram_DstNode[dram] = (low_limit & 0x7);
1361 pvt->dram_IntlvSel[dram] = (low_limit >> 8) & 0x7;
1362
1363 /*
1364 * Extract address values and form a LIMIT address. Limit is the HIGHEST
1365 * memory location of the region, so low 24 bits need to be all ones.
1366 */
1367 low_limit |= 0x0000FFFF;
1368 pvt->dram_limit[dram] =
1369 ((((u64) high_limit << 32) + (u64) low_limit) << 8) | (0xFF);
1370}
1371
1372static void f10_read_dram_ctl_register(struct amd64_pvt *pvt)
1373{
1374 int err = 0;
1375
1376 err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCTL_SEL_LOW,
1377 &pvt->dram_ctl_select_low);
1378 if (err) {
1379 debugf0("Reading F10_DCTL_SEL_LOW failed\n");
1380 } else {
1381 debugf0("DRAM_DCTL_SEL_LOW=0x%x DctSelBaseAddr=0x%x\n",
1382 pvt->dram_ctl_select_low, dct_sel_baseaddr(pvt));
1383
1384 debugf0(" DRAM DCTs are=%s DRAM Is=%s DRAM-Ctl-"
1385 "sel-hi-range=%s\n",
1386 (dct_ganging_enabled(pvt) ? "GANGED" : "NOT GANGED"),
1387 (dct_dram_enabled(pvt) ? "Enabled" : "Disabled"),
1388 (dct_high_range_enabled(pvt) ? "Enabled" : "Disabled"));
1389
1390 debugf0(" DctDatIntLv=%s MemCleared=%s DctSelIntLvAddr=0x%x\n",
1391 (dct_data_intlv_enabled(pvt) ? "Enabled" : "Disabled"),
1392 (dct_memory_cleared(pvt) ? "True " : "False "),
1393 dct_sel_interleave_addr(pvt));
1394 }
1395
1396 err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCTL_SEL_HIGH,
1397 &pvt->dram_ctl_select_high);
1398 if (err)
1399 debugf0("Reading F10_DCTL_SEL_HIGH failed\n");
1400}
1401
1402/*
1403 * determine channel based on the interleaving mode: F10h BKDG, 2.8.9 Memory
1404 * Interleaving Modes.
1405 */
1406static u32 f10_determine_channel(struct amd64_pvt *pvt, u64 sys_addr,
1407 int hi_range_sel, u32 intlv_en)
1408{
1409 u32 cs, temp, dct_sel_high = (pvt->dram_ctl_select_low >> 1) & 1;
1410
1411 if (dct_ganging_enabled(pvt))
1412 cs = 0;
1413 else if (hi_range_sel)
1414 cs = dct_sel_high;
1415 else if (dct_interleave_enabled(pvt)) {
1416 /*
1417 * see F2x110[DctSelIntLvAddr] - channel interleave mode
1418 */
1419 if (dct_sel_interleave_addr(pvt) == 0)
1420 cs = sys_addr >> 6 & 1;
1421 else if ((dct_sel_interleave_addr(pvt) >> 1) & 1) {
1422 temp = hweight_long((u32) ((sys_addr >> 16) & 0x1F)) % 2;
1423
1424 if (dct_sel_interleave_addr(pvt) & 1)
1425 cs = (sys_addr >> 9 & 1) ^ temp;
1426 else
1427 cs = (sys_addr >> 6 & 1) ^ temp;
1428 } else if (intlv_en & 4)
1429 cs = sys_addr >> 15 & 1;
1430 else if (intlv_en & 2)
1431 cs = sys_addr >> 14 & 1;
1432 else if (intlv_en & 1)
1433 cs = sys_addr >> 13 & 1;
1434 else
1435 cs = sys_addr >> 12 & 1;
1436 } else if (dct_high_range_enabled(pvt) && !dct_ganging_enabled(pvt))
1437 cs = ~dct_sel_high & 1;
1438 else
1439 cs = 0;
1440
1441 return cs;
1442}
1443
1444static inline u32 f10_map_intlv_en_to_shift(u32 intlv_en)
1445{
1446 if (intlv_en == 1)
1447 return 1;
1448 else if (intlv_en == 3)
1449 return 2;
1450 else if (intlv_en == 7)
1451 return 3;
1452
1453 return 0;
1454}
1455
1456/* See F10h BKDG, 2.8.10.2 DctSelBaseOffset Programming */
1457static inline u64 f10_get_base_addr_offset(u64 sys_addr, int hi_range_sel,
1458 u32 dct_sel_base_addr,
1459 u64 dct_sel_base_off,
1460 u32 hole_valid, u32 hole_off,
1461 u64 dram_base)
1462{
1463 u64 chan_off;
1464
1465 if (hi_range_sel) {
1466 if (!(dct_sel_base_addr & 0xFFFFF800) &&
1467 hole_valid && (sys_addr >= 0x100000000ULL))
1468 chan_off = hole_off << 16;
1469 else
1470 chan_off = dct_sel_base_off;
1471 } else {
1472 if (hole_valid && (sys_addr >= 0x100000000ULL))
1473 chan_off = hole_off << 16;
1474 else
1475 chan_off = dram_base & 0xFFFFF8000000ULL;
1476 }
1477
1478 return (sys_addr & 0x0000FFFFFFFFFFC0ULL) -
1479 (chan_off & 0x0000FFFFFF800000ULL);
1480}
1481
1482/* Hack for the time being - Can we get this from BIOS?? */
1483#define CH0SPARE_RANK 0
1484#define CH1SPARE_RANK 1
1485
1486/*
1487 * checks if the csrow passed in is marked as SPARED, if so returns the new
1488 * spare row
1489 */
1490static inline int f10_process_possible_spare(int csrow,
1491 u32 cs, struct amd64_pvt *pvt)
1492{
1493 u32 swap_done;
1494 u32 bad_dram_cs;
1495
1496 /* Depending on channel, isolate respective SPARING info */
1497 if (cs) {
1498 swap_done = F10_ONLINE_SPARE_SWAPDONE1(pvt->online_spare);
1499 bad_dram_cs = F10_ONLINE_SPARE_BADDRAM_CS1(pvt->online_spare);
1500 if (swap_done && (csrow == bad_dram_cs))
1501 csrow = CH1SPARE_RANK;
1502 } else {
1503 swap_done = F10_ONLINE_SPARE_SWAPDONE0(pvt->online_spare);
1504 bad_dram_cs = F10_ONLINE_SPARE_BADDRAM_CS0(pvt->online_spare);
1505 if (swap_done && (csrow == bad_dram_cs))
1506 csrow = CH0SPARE_RANK;
1507 }
1508 return csrow;
1509}
1510
1511/*
1512 * Iterate over the DRAM DCT "base" and "mask" registers looking for a
1513 * SystemAddr match on the specified 'ChannelSelect' and 'NodeID'
1514 *
1515 * Return:
1516 * -EINVAL: NOT FOUND
1517 * 0..csrow = Chip-Select Row
1518 */
1519static int f10_lookup_addr_in_dct(u32 in_addr, u32 nid, u32 cs)
1520{
1521 struct mem_ctl_info *mci;
1522 struct amd64_pvt *pvt;
1523 u32 cs_base, cs_mask;
1524 int cs_found = -EINVAL;
1525 int csrow;
1526
1527 mci = mci_lookup[nid];
1528 if (!mci)
1529 return cs_found;
1530
1531 pvt = mci->pvt_info;
1532
1533 debugf1("InputAddr=0x%x channelselect=%d\n", in_addr, cs);
1534
1535 for (csrow = 0; csrow < CHIPSELECT_COUNT; csrow++) {
1536
1537 cs_base = amd64_get_dct_base(pvt, cs, csrow);
1538 if (!(cs_base & K8_DCSB_CS_ENABLE))
1539 continue;
1540
1541 /*
1542 * We have an ENABLED CSROW, Isolate just the MASK bits of the
1543 * target: [28:19] and [13:5], which map to [36:27] and [21:13]
1544 * of the actual address.
1545 */
1546 cs_base &= REV_F_F1Xh_DCSB_BASE_BITS;
1547
1548 /*
1549 * Get the DCT Mask, and ENABLE the reserved bits: [18:16] and
1550 * [4:0] to become ON. Then mask off bits [28:0] ([36:8])
1551 */
1552 cs_mask = amd64_get_dct_mask(pvt, cs, csrow);
1553
1554 debugf1(" CSROW=%d CSBase=0x%x RAW CSMask=0x%x\n",
1555 csrow, cs_base, cs_mask);
1556
1557 cs_mask = (cs_mask | 0x0007C01F) & 0x1FFFFFFF;
1558
1559 debugf1(" Final CSMask=0x%x\n", cs_mask);
1560 debugf1(" (InputAddr & ~CSMask)=0x%x "
1561 "(CSBase & ~CSMask)=0x%x\n",
1562 (in_addr & ~cs_mask), (cs_base & ~cs_mask));
1563
1564 if ((in_addr & ~cs_mask) == (cs_base & ~cs_mask)) {
1565 cs_found = f10_process_possible_spare(csrow, cs, pvt);
1566
1567 debugf1(" MATCH csrow=%d\n", cs_found);
1568 break;
1569 }
1570 }
1571 return cs_found;
1572}
1573
1574/* For a given @dram_range, check if @sys_addr falls within it. */
1575static int f10_match_to_this_node(struct amd64_pvt *pvt, int dram_range,
1576 u64 sys_addr, int *nid, int *chan_sel)
1577{
1578 int node_id, cs_found = -EINVAL, high_range = 0;
1579 u32 intlv_en, intlv_sel, intlv_shift, hole_off;
1580 u32 hole_valid, tmp, dct_sel_base, channel;
1581 u64 dram_base, chan_addr, dct_sel_base_off;
1582
1583 dram_base = pvt->dram_base[dram_range];
1584 intlv_en = pvt->dram_IntlvEn[dram_range];
1585
1586 node_id = pvt->dram_DstNode[dram_range];
1587 intlv_sel = pvt->dram_IntlvSel[dram_range];
1588
1589 debugf1("(dram=%d) Base=0x%llx SystemAddr= 0x%llx Limit=0x%llx\n",
1590 dram_range, dram_base, sys_addr, pvt->dram_limit[dram_range]);
1591
1592 /*
1593 * This assumes that one node's DHAR is the same as all the other
1594 * nodes' DHAR.
1595 */
1596 hole_off = (pvt->dhar & 0x0000FF80);
1597 hole_valid = (pvt->dhar & 0x1);
1598 dct_sel_base_off = (pvt->dram_ctl_select_high & 0xFFFFFC00) << 16;
1599
1600 debugf1(" HoleOffset=0x%x HoleValid=0x%x IntlvSel=0x%x\n",
1601 hole_off, hole_valid, intlv_sel);
1602
1603 if (intlv_en ||
1604 (intlv_sel != ((sys_addr >> 12) & intlv_en)))
1605 return -EINVAL;
1606
1607 dct_sel_base = dct_sel_baseaddr(pvt);
1608
1609 /*
1610 * check whether addresses >= DctSelBaseAddr[47:27] are to be used to
1611 * select between DCT0 and DCT1.
1612 */
1613 if (dct_high_range_enabled(pvt) &&
1614 !dct_ganging_enabled(pvt) &&
1615 ((sys_addr >> 27) >= (dct_sel_base >> 11)))
1616 high_range = 1;
1617
1618 channel = f10_determine_channel(pvt, sys_addr, high_range, intlv_en);
1619
1620 chan_addr = f10_get_base_addr_offset(sys_addr, high_range, dct_sel_base,
1621 dct_sel_base_off, hole_valid,
1622 hole_off, dram_base);
1623
1624 intlv_shift = f10_map_intlv_en_to_shift(intlv_en);
1625
1626 /* remove Node ID (in case of memory interleaving) */
1627 tmp = chan_addr & 0xFC0;
1628
1629 chan_addr = ((chan_addr >> intlv_shift) & 0xFFFFFFFFF000ULL) | tmp;
1630
1631 /* remove channel interleave and hash */
1632 if (dct_interleave_enabled(pvt) &&
1633 !dct_high_range_enabled(pvt) &&
1634 !dct_ganging_enabled(pvt)) {
1635 if (dct_sel_interleave_addr(pvt) != 1)
1636 chan_addr = (chan_addr >> 1) & 0xFFFFFFFFFFFFFFC0ULL;
1637 else {
1638 tmp = chan_addr & 0xFC0;
1639 chan_addr = ((chan_addr & 0xFFFFFFFFFFFFC000ULL) >> 1)
1640 | tmp;
1641 }
1642 }
1643
1644 debugf1(" (ChannelAddrLong=0x%llx) >> 8 becomes InputAddr=0x%x\n",
1645 chan_addr, (u32)(chan_addr >> 8));
1646
1647 cs_found = f10_lookup_addr_in_dct(chan_addr >> 8, node_id, channel);
1648
1649 if (cs_found >= 0) {
1650 *nid = node_id;
1651 *chan_sel = channel;
1652 }
1653 return cs_found;
1654}
1655
1656static int f10_translate_sysaddr_to_cs(struct amd64_pvt *pvt, u64 sys_addr,
1657 int *node, int *chan_sel)
1658{
1659 int dram_range, cs_found = -EINVAL;
1660 u64 dram_base, dram_limit;
1661
1662 for (dram_range = 0; dram_range < DRAM_REG_COUNT; dram_range++) {
1663
1664 if (!pvt->dram_rw_en[dram_range])
1665 continue;
1666
1667 dram_base = pvt->dram_base[dram_range];
1668 dram_limit = pvt->dram_limit[dram_range];
1669
1670 if ((dram_base <= sys_addr) && (sys_addr <= dram_limit)) {
1671
1672 cs_found = f10_match_to_this_node(pvt, dram_range,
1673 sys_addr, node,
1674 chan_sel);
1675 if (cs_found >= 0)
1676 break;
1677 }
1678 }
1679 return cs_found;
1680}
1681
1682/*
1683 * This the F10h reference code from AMD to map a @sys_addr to NodeID,
1684 * CSROW, Channel.
1685 *
1686 * The @sys_addr is usually an error address received from the hardware.
1687 */
1688static void f10_map_sysaddr_to_csrow(struct mem_ctl_info *mci,
1689 struct amd64_error_info_regs *info,
1690 u64 sys_addr)
1691{
1692 struct amd64_pvt *pvt = mci->pvt_info;
1693 u32 page, offset;
1694 unsigned short syndrome;
1695 int nid, csrow, chan = 0;
1696
1697 csrow = f10_translate_sysaddr_to_cs(pvt, sys_addr, &nid, &chan);
1698
1699 if (csrow >= 0) {
1700 error_address_to_page_and_offset(sys_addr, &page, &offset);
1701
1702 syndrome = EXTRACT_HIGH_SYNDROME(info->nbsl) << 8;
1703 syndrome |= EXTRACT_LOW_SYNDROME(info->nbsh);
1704
1705 /*
1706 * Is CHIPKILL on? If so, then we can attempt to use the
1707 * syndrome to isolate which channel the error was on.
1708 */
1709 if (pvt->nbcfg & K8_NBCFG_CHIPKILL)
1710 chan = get_channel_from_ecc_syndrome(syndrome);
1711
1712 if (chan >= 0) {
1713 edac_mc_handle_ce(mci, page, offset, syndrome,
1714 csrow, chan, EDAC_MOD_STR);
1715 } else {
1716 /*
1717 * Channel unknown, report all channels on this
1718 * CSROW as failed.
1719 */
1720 for (chan = 0; chan < mci->csrows[csrow].nr_channels;
1721 chan++) {
1722 edac_mc_handle_ce(mci, page, offset,
1723 syndrome,
1724 csrow, chan,
1725 EDAC_MOD_STR);
1726 }
1727 }
1728
1729 } else {
1730 edac_mc_handle_ce_no_info(mci, EDAC_MOD_STR);
1731 }
1732}
1733
1734/*
1735 * Input (@index) is the DBAM DIMM value (1 of 4) used as an index into a shift
1736 * table (revf_quad_ddr2_shift) which starts at 128MB DIMM size. Index of 0
1737 * indicates an empty DIMM slot, as reported by Hardware on empty slots.
1738 *
1739 * Normalize to 128MB by subracting 27 bit shift.
1740 */
1741static int map_dbam_to_csrow_size(int index)
1742{
1743 int mega_bytes = 0;
1744
1745 if (index > 0 && index <= DBAM_MAX_VALUE)
1746 mega_bytes = ((128 << (revf_quad_ddr2_shift[index]-27)));
1747
1748 return mega_bytes;
1749}
1750
1751/*
1752 * debug routine to display the memory sizes of a DIMM (ganged or not) and it
1753 * CSROWs as well
1754 */
1755static void f10_debug_display_dimm_sizes(int ctrl, struct amd64_pvt *pvt,
1756 int ganged)
1757{
1758 int dimm, size0, size1;
1759 u32 dbam;
1760 u32 *dcsb;
1761
1762 debugf1(" dbam%d: 0x%8.08x CSROW is %s\n", ctrl,
1763 ctrl ? pvt->dbam1 : pvt->dbam0,
1764 ganged ? "GANGED - dbam1 not used" : "NON-GANGED");
1765
1766 dbam = ctrl ? pvt->dbam1 : pvt->dbam0;
1767 dcsb = ctrl ? pvt->dcsb1 : pvt->dcsb0;
1768
1769 /* Dump memory sizes for DIMM and its CSROWs */
1770 for (dimm = 0; dimm < 4; dimm++) {
1771
1772 size0 = 0;
1773 if (dcsb[dimm*2] & K8_DCSB_CS_ENABLE)
1774 size0 = map_dbam_to_csrow_size(DBAM_DIMM(dimm, dbam));
1775
1776 size1 = 0;
1777 if (dcsb[dimm*2 + 1] & K8_DCSB_CS_ENABLE)
1778 size1 = map_dbam_to_csrow_size(DBAM_DIMM(dimm, dbam));
1779
1780 debugf1(" CTRL-%d DIMM-%d=%5dMB CSROW-%d=%5dMB "
1781 "CSROW-%d=%5dMB\n",
1782 ctrl,
1783 dimm,
1784 size0 + size1,
1785 dimm * 2,
1786 size0,
1787 dimm * 2 + 1,
1788 size1);
1789 }
1790}
1791
1792/*
1793 * Very early hardware probe on pci_probe thread to determine if this module
1794 * supports the hardware.
1795 *
1796 * Return:
1797 * 0 for OK
1798 * 1 for error
1799 */
1800static int f10_probe_valid_hardware(struct amd64_pvt *pvt)
1801{
1802 int ret = 0;
1803
1804 /*
1805 * If we are on a DDR3 machine, we don't know yet if
1806 * we support that properly at this time
1807 */
1808 if ((pvt->dchr0 & F10_DCHR_Ddr3Mode) ||
1809 (pvt->dchr1 & F10_DCHR_Ddr3Mode)) {
1810
1811 amd64_printk(KERN_WARNING,
1812 "%s() This machine is running with DDR3 memory. "
1813 "This is not currently supported. "
1814 "DCHR0=0x%x DCHR1=0x%x\n",
1815 __func__, pvt->dchr0, pvt->dchr1);
1816
1817 amd64_printk(KERN_WARNING,
1818 " Contact '%s' module MAINTAINER to help add"
1819 " support.\n",
1820 EDAC_MOD_STR);
1821
1822 ret = 1;
1823
1824 }
1825 return ret;
1826}
1827
1828/*
1829 * There currently are 3 types type of MC devices for AMD Athlon/Opterons
1830 * (as per PCI DEVICE_IDs):
1831 *
1832 * Family K8: That is the Athlon64 and Opteron CPUs. They all have the same PCI
1833 * DEVICE ID, even though there is differences between the different Revisions
1834 * (CG,D,E,F).
1835 *
1836 * Family F10h and F11h.
1837 *
1838 */
1839static struct amd64_family_type amd64_family_types[] = {
1840 [K8_CPUS] = {
1841 .ctl_name = "RevF",
1842 .addr_f1_ctl = PCI_DEVICE_ID_AMD_K8_NB_ADDRMAP,
1843 .misc_f3_ctl = PCI_DEVICE_ID_AMD_K8_NB_MISC,
1844 .ops = {
1845 .early_channel_count = k8_early_channel_count,
1846 .get_error_address = k8_get_error_address,
1847 .read_dram_base_limit = k8_read_dram_base_limit,
1848 .map_sysaddr_to_csrow = k8_map_sysaddr_to_csrow,
1849 .dbam_map_to_pages = k8_dbam_map_to_pages,
1850 }
1851 },
1852 [F10_CPUS] = {
1853 .ctl_name = "Family 10h",
1854 .addr_f1_ctl = PCI_DEVICE_ID_AMD_10H_NB_MAP,
1855 .misc_f3_ctl = PCI_DEVICE_ID_AMD_10H_NB_MISC,
1856 .ops = {
1857 .probe_valid_hardware = f10_probe_valid_hardware,
1858 .early_channel_count = f10_early_channel_count,
1859 .get_error_address = f10_get_error_address,
1860 .read_dram_base_limit = f10_read_dram_base_limit,
1861 .read_dram_ctl_register = f10_read_dram_ctl_register,
1862 .map_sysaddr_to_csrow = f10_map_sysaddr_to_csrow,
1863 .dbam_map_to_pages = f10_dbam_map_to_pages,
1864 }
1865 },
1866 [F11_CPUS] = {
1867 .ctl_name = "Family 11h",
1868 .addr_f1_ctl = PCI_DEVICE_ID_AMD_11H_NB_MAP,
1869 .misc_f3_ctl = PCI_DEVICE_ID_AMD_11H_NB_MISC,
1870 .ops = {
1871 .probe_valid_hardware = f10_probe_valid_hardware,
1872 .early_channel_count = f10_early_channel_count,
1873 .get_error_address = f10_get_error_address,
1874 .read_dram_base_limit = f10_read_dram_base_limit,
1875 .read_dram_ctl_register = f10_read_dram_ctl_register,
1876 .map_sysaddr_to_csrow = f10_map_sysaddr_to_csrow,
1877 .dbam_map_to_pages = f10_dbam_map_to_pages,
1878 }
1879 },
1880};
1881
1882static struct pci_dev *pci_get_related_function(unsigned int vendor,
1883 unsigned int device,
1884 struct pci_dev *related)
1885{
1886 struct pci_dev *dev = NULL;
1887
1888 dev = pci_get_device(vendor, device, dev);
1889 while (dev) {
1890 if ((dev->bus->number == related->bus->number) &&
1891 (PCI_SLOT(dev->devfn) == PCI_SLOT(related->devfn)))
1892 break;
1893 dev = pci_get_device(vendor, device, dev);
1894 }
1895
1896 return dev;
1897}
1898
1899/*
1900 * syndrome mapping table for ECC ChipKill devices
1901 *
1902 * The comment in each row is the token (nibble) number that is in error.
1903 * The least significant nibble of the syndrome is the mask for the bits
1904 * that are in error (need to be toggled) for the particular nibble.
1905 *
1906 * Each row contains 16 entries.
1907 * The first entry (0th) is the channel number for that row of syndromes.
1908 * The remaining 15 entries are the syndromes for the respective Error
1909 * bit mask index.
1910 *
1911 * 1st index entry is 0x0001 mask, indicating that the rightmost bit is the
1912 * bit in error.
1913 * The 2nd index entry is 0x0010 that the second bit is damaged.
1914 * The 3rd index entry is 0x0011 indicating that the rightmost 2 bits
1915 * are damaged.
1916 * Thus so on until index 15, 0x1111, whose entry has the syndrome
1917 * indicating that all 4 bits are damaged.
1918 *
1919 * A search is performed on this table looking for a given syndrome.
1920 *
1921 * See the AMD documentation for ECC syndromes. This ECC table is valid
1922 * across all the versions of the AMD64 processors.
1923 *
1924 * A fast lookup is to use the LAST four bits of the 16-bit syndrome as a
1925 * COLUMN index, then search all ROWS of that column, looking for a match
1926 * with the input syndrome. The ROW value will be the token number.
1927 *
1928 * The 0'th entry on that row, can be returned as the CHANNEL (0 or 1) of this
1929 * error.
1930 */
1931#define NUMBER_ECC_ROWS 36
1932static const unsigned short ecc_chipkill_syndromes[NUMBER_ECC_ROWS][16] = {
1933 /* Channel 0 syndromes */
1934 {/*0*/ 0, 0xe821, 0x7c32, 0x9413, 0xbb44, 0x5365, 0xc776, 0x2f57,
1935 0xdd88, 0x35a9, 0xa1ba, 0x499b, 0x66cc, 0x8eed, 0x1afe, 0xf2df },
1936 {/*1*/ 0, 0x5d31, 0xa612, 0xfb23, 0x9584, 0xc8b5, 0x3396, 0x6ea7,
1937 0xeac8, 0xb7f9, 0x4cda, 0x11eb, 0x7f4c, 0x227d, 0xd95e, 0x846f },
1938 {/*2*/ 0, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
1939 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f },
1940 {/*3*/ 0, 0x2021, 0x3032, 0x1013, 0x4044, 0x6065, 0x7076, 0x5057,
1941 0x8088, 0xa0a9, 0xb0ba, 0x909b, 0xc0cc, 0xe0ed, 0xf0fe, 0xd0df },
1942 {/*4*/ 0, 0x5041, 0xa082, 0xf0c3, 0x9054, 0xc015, 0x30d6, 0x6097,
1943 0xe0a8, 0xb0e9, 0x402a, 0x106b, 0x70fc, 0x20bd, 0xd07e, 0x803f },
1944 {/*5*/ 0, 0xbe21, 0xd732, 0x6913, 0x2144, 0x9f65, 0xf676, 0x4857,
1945 0x3288, 0x8ca9, 0xe5ba, 0x5b9b, 0x13cc, 0xaded, 0xc4fe, 0x7adf },
1946 {/*6*/ 0, 0x4951, 0x8ea2, 0xc7f3, 0x5394, 0x1ac5, 0xdd36, 0x9467,
1947 0xa1e8, 0xe8b9, 0x2f4a, 0x661b, 0xf27c, 0xbb2d, 0x7cde, 0x358f },
1948 {/*7*/ 0, 0x74e1, 0x9872, 0xec93, 0xd6b4, 0xa255, 0x4ec6, 0x3a27,
1949 0x6bd8, 0x1f39, 0xf3aa, 0x874b, 0xbd6c, 0xc98d, 0x251e, 0x51ff },
1950 {/*8*/ 0, 0x15c1, 0x2a42, 0x3f83, 0xcef4, 0xdb35, 0xe4b6, 0xf177,
1951 0x4758, 0x5299, 0x6d1a, 0x78db, 0x89ac, 0x9c6d, 0xa3ee, 0xb62f },
1952 {/*9*/ 0, 0x3d01, 0x1602, 0x2b03, 0x8504, 0xb805, 0x9306, 0xae07,
1953 0xca08, 0xf709, 0xdc0a, 0xe10b, 0x4f0c, 0x720d, 0x590e, 0x640f },
1954 {/*a*/ 0, 0x9801, 0xec02, 0x7403, 0x6b04, 0xf305, 0x8706, 0x1f07,
1955 0xbd08, 0x2509, 0x510a, 0xc90b, 0xd60c, 0x4e0d, 0x3a0e, 0xa20f },
1956 {/*b*/ 0, 0xd131, 0x6212, 0xb323, 0x3884, 0xe9b5, 0x5a96, 0x8ba7,
1957 0x1cc8, 0xcdf9, 0x7eda, 0xafeb, 0x244c, 0xf57d, 0x465e, 0x976f },
1958 {/*c*/ 0, 0xe1d1, 0x7262, 0x93b3, 0xb834, 0x59e5, 0xca56, 0x2b87,
1959 0xdc18, 0x3dc9, 0xae7a, 0x4fab, 0x542c, 0x85fd, 0x164e, 0xf79f },
1960 {/*d*/ 0, 0x6051, 0xb0a2, 0xd0f3, 0x1094, 0x70c5, 0xa036, 0xc067,
1961 0x20e8, 0x40b9, 0x904a, 0x601b, 0x307c, 0x502d, 0x80de, 0xe08f },
1962 {/*e*/ 0, 0xa4c1, 0xf842, 0x5c83, 0xe6f4, 0x4235, 0x1eb6, 0xba77,
1963 0x7b58, 0xdf99, 0x831a, 0x27db, 0x9dac, 0x396d, 0x65ee, 0xc12f },
1964 {/*f*/ 0, 0x11c1, 0x2242, 0x3383, 0xc8f4, 0xd935, 0xeab6, 0xfb77,
1965 0x4c58, 0x5d99, 0x6e1a, 0x7fdb, 0x84ac, 0x956d, 0xa6ee, 0xb72f },
1966
1967 /* Channel 1 syndromes */
1968 {/*10*/ 1, 0x45d1, 0x8a62, 0xcfb3, 0x5e34, 0x1be5, 0xd456, 0x9187,
1969 0xa718, 0xe2c9, 0x2d7a, 0x68ab, 0xf92c, 0xbcfd, 0x734e, 0x369f },
1970 {/*11*/ 1, 0x63e1, 0xb172, 0xd293, 0x14b4, 0x7755, 0xa5c6, 0xc627,
1971 0x28d8, 0x4b39, 0x99aa, 0xfa4b, 0x3c6c, 0x5f8d, 0x8d1e, 0xeeff },
1972 {/*12*/ 1, 0xb741, 0xd982, 0x6ec3, 0x2254, 0x9515, 0xfbd6, 0x4c97,
1973 0x33a8, 0x84e9, 0xea2a, 0x5d6b, 0x11fc, 0xa6bd, 0xc87e, 0x7f3f },
1974 {/*13*/ 1, 0xdd41, 0x6682, 0xbbc3, 0x3554, 0xe815, 0x53d6, 0xce97,
1975 0x1aa8, 0xc7e9, 0x7c2a, 0xa1fb, 0x2ffc, 0xf2bd, 0x497e, 0x943f },
1976 {/*14*/ 1, 0x2bd1, 0x3d62, 0x16b3, 0x4f34, 0x64e5, 0x7256, 0x5987,
1977 0x8518, 0xaec9, 0xb87a, 0x93ab, 0xca2c, 0xe1fd, 0xf74e, 0xdc9f },
1978 {/*15*/ 1, 0x83c1, 0xc142, 0x4283, 0xa4f4, 0x2735, 0x65b6, 0xe677,
1979 0xf858, 0x7b99, 0x391a, 0xbadb, 0x5cac, 0xdf6d, 0x9dee, 0x1e2f },
1980 {/*16*/ 1, 0x8fd1, 0xc562, 0x4ab3, 0xa934, 0x26e5, 0x6c56, 0xe387,
1981 0xfe18, 0x71c9, 0x3b7a, 0xb4ab, 0x572c, 0xd8fd, 0x924e, 0x1d9f },
1982 {/*17*/ 1, 0x4791, 0x89e2, 0xce73, 0x5264, 0x15f5, 0xdb86, 0x9c17,
1983 0xa3b8, 0xe429, 0x2a5a, 0x6dcb, 0xf1dc, 0xb64d, 0x783e, 0x3faf },
1984 {/*18*/ 1, 0x5781, 0xa9c2, 0xfe43, 0x92a4, 0xc525, 0x3b66, 0x6ce7,
1985 0xe3f8, 0xb479, 0x4a3a, 0x1dbb, 0x715c, 0x26dd, 0xd89e, 0x8f1f },
1986 {/*19*/ 1, 0xbf41, 0xd582, 0x6ac3, 0x2954, 0x9615, 0xfcd6, 0x4397,
1987 0x3ea8, 0x81e9, 0xeb2a, 0x546b, 0x17fc, 0xa8bd, 0xc27e, 0x7d3f },
1988 {/*1a*/ 1, 0x9891, 0xe1e2, 0x7273, 0x6464, 0xf7f5, 0x8586, 0x1617,
1989 0xb8b8, 0x2b29, 0x595a, 0xcacb, 0xdcdc, 0x4f4d, 0x3d3e, 0xaeaf },
1990 {/*1b*/ 1, 0xcce1, 0x4472, 0x8893, 0xfdb4, 0x3f55, 0xb9c6, 0x7527,
1991 0x56d8, 0x9a39, 0x12aa, 0xde4b, 0xab6c, 0x678d, 0xef1e, 0x23ff },
1992 {/*1c*/ 1, 0xa761, 0xf9b2, 0x5ed3, 0xe214, 0x4575, 0x1ba6, 0xbcc7,
1993 0x7328, 0xd449, 0x8a9a, 0x2dfb, 0x913c, 0x365d, 0x688e, 0xcfef },
1994 {/*1d*/ 1, 0xff61, 0x55b2, 0xaad3, 0x7914, 0x8675, 0x2ca6, 0xd3c7,
1995 0x9e28, 0x6149, 0xcb9a, 0x34fb, 0xe73c, 0x185d, 0xb28e, 0x4def },
1996 {/*1e*/ 1, 0x5451, 0xa8a2, 0xfcf3, 0x9694, 0xc2c5, 0x3e36, 0x6a67,
1997 0xebe8, 0xbfb9, 0x434a, 0x171b, 0x7d7c, 0x292d, 0xd5de, 0x818f },
1998 {/*1f*/ 1, 0x6fc1, 0xb542, 0xda83, 0x19f4, 0x7635, 0xacb6, 0xc377,
1999 0x2e58, 0x4199, 0x9b1a, 0xf4db, 0x37ac, 0x586d, 0x82ee, 0xed2f },
2000
2001 /* ECC bits are also in the set of tokens and they too can go bad
2002 * first 2 cover channel 0, while the second 2 cover channel 1
2003 */
2004 {/*20*/ 0, 0xbe01, 0xd702, 0x6903, 0x2104, 0x9f05, 0xf606, 0x4807,
2005 0x3208, 0x8c09, 0xe50a, 0x5b0b, 0x130c, 0xad0d, 0xc40e, 0x7a0f },
2006 {/*21*/ 0, 0x4101, 0x8202, 0xc303, 0x5804, 0x1905, 0xda06, 0x9b07,
2007 0xac08, 0xed09, 0x2e0a, 0x6f0b, 0x640c, 0xb50d, 0x760e, 0x370f },
2008 {/*22*/ 1, 0xc441, 0x4882, 0x8cc3, 0xf654, 0x3215, 0xbed6, 0x7a97,
2009 0x5ba8, 0x9fe9, 0x132a, 0xd76b, 0xadfc, 0x69bd, 0xe57e, 0x213f },
2010 {/*23*/ 1, 0x7621, 0x9b32, 0xed13, 0xda44, 0xac65, 0x4176, 0x3757,
2011 0x6f88, 0x19a9, 0xf4ba, 0x829b, 0xb5cc, 0xc3ed, 0x2efe, 0x58df }
2012};
2013
2014/*
2015 * Given the syndrome argument, scan each of the channel tables for a syndrome
2016 * match. Depending on which table it is found, return the channel number.
2017 */
2018static int get_channel_from_ecc_syndrome(unsigned short syndrome)
2019{
2020 int row;
2021 int column;
2022
2023 /* Determine column to scan */
2024 column = syndrome & 0xF;
2025
2026 /* Scan all rows, looking for syndrome, or end of table */
2027 for (row = 0; row < NUMBER_ECC_ROWS; row++) {
2028 if (ecc_chipkill_syndromes[row][column] == syndrome)
2029 return ecc_chipkill_syndromes[row][0];
2030 }
2031
2032 debugf0("syndrome(%x) not found\n", syndrome);
2033 return -1;
2034}
2035
2036/*
2037 * Check for valid error in the NB Status High register. If so, proceed to read
2038 * NB Status Low, NB Address Low and NB Address High registers and store data
2039 * into error structure.
2040 *
2041 * Returns:
2042 * - 1: if hardware regs contains valid error info
2043 * - 0: if no valid error is indicated
2044 */
2045static int amd64_get_error_info_regs(struct mem_ctl_info *mci,
2046 struct amd64_error_info_regs *regs)
2047{
2048 struct amd64_pvt *pvt;
2049 struct pci_dev *misc_f3_ctl;
2050 int err = 0;
2051
2052 pvt = mci->pvt_info;
2053 misc_f3_ctl = pvt->misc_f3_ctl;
2054
2055 err = pci_read_config_dword(misc_f3_ctl, K8_NBSH, &regs->nbsh);
2056 if (err)
2057 goto err_reg;
2058
2059 if (!(regs->nbsh & K8_NBSH_VALID_BIT))
2060 return 0;
2061
2062 /* valid error, read remaining error information registers */
2063 err = pci_read_config_dword(misc_f3_ctl, K8_NBSL, &regs->nbsl);
2064 if (err)
2065 goto err_reg;
2066
2067 err = pci_read_config_dword(misc_f3_ctl, K8_NBEAL, &regs->nbeal);
2068 if (err)
2069 goto err_reg;
2070
2071 err = pci_read_config_dword(misc_f3_ctl, K8_NBEAH, &regs->nbeah);
2072 if (err)
2073 goto err_reg;
2074
2075 err = pci_read_config_dword(misc_f3_ctl, K8_NBCFG, &regs->nbcfg);
2076 if (err)
2077 goto err_reg;
2078
2079 return 1;
2080
2081err_reg:
2082 debugf0("Reading error info register failed\n");
2083 return 0;
2084}
2085
2086/*
2087 * This function is called to retrieve the error data from hardware and store it
2088 * in the info structure.
2089 *
2090 * Returns:
2091 * - 1: if a valid error is found
2092 * - 0: if no error is found
2093 */
2094static int amd64_get_error_info(struct mem_ctl_info *mci,
2095 struct amd64_error_info_regs *info)
2096{
2097 struct amd64_pvt *pvt;
2098 struct amd64_error_info_regs regs;
2099
2100 pvt = mci->pvt_info;
2101
2102 if (!amd64_get_error_info_regs(mci, info))
2103 return 0;
2104
2105 /*
2106 * Here's the problem with the K8's EDAC reporting: There are four
2107 * registers which report pieces of error information. They are shared
2108 * between CEs and UEs. Furthermore, contrary to what is stated in the
2109 * BKDG, the overflow bit is never used! Every error always updates the
2110 * reporting registers.
2111 *
2112 * Can you see the race condition? All four error reporting registers
2113 * must be read before a new error updates them! There is no way to read
2114 * all four registers atomically. The best than can be done is to detect
2115 * that a race has occured and then report the error without any kind of
2116 * precision.
2117 *
2118 * What is still positive is that errors are still reported and thus
2119 * problems can still be detected - just not localized because the
2120 * syndrome and address are spread out across registers.
2121 *
2122 * Grrrrr!!!!! Here's hoping that AMD fixes this in some future K8 rev.
2123 * UEs and CEs should have separate register sets with proper overflow
2124 * bits that are used! At very least the problem can be fixed by
2125 * honoring the ErrValid bit in 'nbsh' and not updating registers - just
2126 * set the overflow bit - unless the current error is CE and the new
2127 * error is UE which would be the only situation for overwriting the
2128 * current values.
2129 */
2130
2131 regs = *info;
2132
2133 /* Use info from the second read - most current */
2134 if (unlikely(!amd64_get_error_info_regs(mci, info)))
2135 return 0;
2136
2137 /* clear the error bits in hardware */
2138 pci_write_bits32(pvt->misc_f3_ctl, K8_NBSH, 0, K8_NBSH_VALID_BIT);
2139
2140 /* Check for the possible race condition */
2141 if ((regs.nbsh != info->nbsh) ||
2142 (regs.nbsl != info->nbsl) ||
2143 (regs.nbeah != info->nbeah) ||
2144 (regs.nbeal != info->nbeal)) {
2145 amd64_mc_printk(mci, KERN_WARNING,
2146 "hardware STATUS read access race condition "
2147 "detected!\n");
2148 return 0;
2149 }
2150 return 1;
2151}
2152
2153static inline void amd64_decode_gart_tlb_error(struct mem_ctl_info *mci,
2154 struct amd64_error_info_regs *info)
2155{
2156 u32 err_code;
2157 u32 ec_tt; /* error code transaction type (2b) */
2158 u32 ec_ll; /* error code cache level (2b) */
2159
2160 err_code = EXTRACT_ERROR_CODE(info->nbsl);
2161 ec_ll = EXTRACT_LL_CODE(err_code);
2162 ec_tt = EXTRACT_TT_CODE(err_code);
2163
2164 amd64_mc_printk(mci, KERN_ERR,
2165 "GART TLB event: transaction type(%s), "
2166 "cache level(%s)\n", tt_msgs[ec_tt], ll_msgs[ec_ll]);
2167}
2168
2169static inline void amd64_decode_mem_cache_error(struct mem_ctl_info *mci,
2170 struct amd64_error_info_regs *info)
2171{
2172 u32 err_code;
2173 u32 ec_rrrr; /* error code memory transaction (4b) */
2174 u32 ec_tt; /* error code transaction type (2b) */
2175 u32 ec_ll; /* error code cache level (2b) */
2176
2177 err_code = EXTRACT_ERROR_CODE(info->nbsl);
2178 ec_ll = EXTRACT_LL_CODE(err_code);
2179 ec_tt = EXTRACT_TT_CODE(err_code);
2180 ec_rrrr = EXTRACT_RRRR_CODE(err_code);
2181
2182 amd64_mc_printk(mci, KERN_ERR,
2183 "cache hierarchy error: memory transaction type(%s), "
2184 "transaction type(%s), cache level(%s)\n",
2185 rrrr_msgs[ec_rrrr], tt_msgs[ec_tt], ll_msgs[ec_ll]);
2186}
2187
2188
2189/*
2190 * Handle any Correctable Errors (CEs) that have occurred. Check for valid ERROR
2191 * ADDRESS and process.
2192 */
2193static void amd64_handle_ce(struct mem_ctl_info *mci,
2194 struct amd64_error_info_regs *info)
2195{
2196 struct amd64_pvt *pvt = mci->pvt_info;
2197 u64 SystemAddress;
2198
2199 /* Ensure that the Error Address is VALID */
2200 if ((info->nbsh & K8_NBSH_VALID_ERROR_ADDR) == 0) {
2201 amd64_mc_printk(mci, KERN_ERR,
2202 "HW has no ERROR_ADDRESS available\n");
2203 edac_mc_handle_ce_no_info(mci, EDAC_MOD_STR);
2204 return;
2205 }
2206
2207 SystemAddress = extract_error_address(mci, info);
2208
2209 amd64_mc_printk(mci, KERN_ERR,
2210 "CE ERROR_ADDRESS= 0x%llx\n", SystemAddress);
2211
2212 pvt->ops->map_sysaddr_to_csrow(mci, info, SystemAddress);
2213}
2214
2215/* Handle any Un-correctable Errors (UEs) */
2216static void amd64_handle_ue(struct mem_ctl_info *mci,
2217 struct amd64_error_info_regs *info)
2218{
2219 int csrow;
2220 u64 SystemAddress;
2221 u32 page, offset;
2222 struct mem_ctl_info *log_mci, *src_mci = NULL;
2223
2224 log_mci = mci;
2225
2226 if ((info->nbsh & K8_NBSH_VALID_ERROR_ADDR) == 0) {
2227 amd64_mc_printk(mci, KERN_CRIT,
2228 "HW has no ERROR_ADDRESS available\n");
2229 edac_mc_handle_ue_no_info(log_mci, EDAC_MOD_STR);
2230 return;
2231 }
2232
2233 SystemAddress = extract_error_address(mci, info);
2234
2235 /*
2236 * Find out which node the error address belongs to. This may be
2237 * different from the node that detected the error.
2238 */
2239 src_mci = find_mc_by_sys_addr(mci, SystemAddress);
2240 if (!src_mci) {
2241 amd64_mc_printk(mci, KERN_CRIT,
2242 "ERROR ADDRESS (0x%lx) value NOT mapped to a MC\n",
2243 (unsigned long)SystemAddress);
2244 edac_mc_handle_ue_no_info(log_mci, EDAC_MOD_STR);
2245 return;
2246 }
2247
2248 log_mci = src_mci;
2249
2250 csrow = sys_addr_to_csrow(log_mci, SystemAddress);
2251 if (csrow < 0) {
2252 amd64_mc_printk(mci, KERN_CRIT,
2253 "ERROR_ADDRESS (0x%lx) value NOT mapped to 'csrow'\n",
2254 (unsigned long)SystemAddress);
2255 edac_mc_handle_ue_no_info(log_mci, EDAC_MOD_STR);
2256 } else {
2257 error_address_to_page_and_offset(SystemAddress, &page, &offset);
2258 edac_mc_handle_ue(log_mci, page, offset, csrow, EDAC_MOD_STR);
2259 }
2260}
2261
2262static void amd64_decode_bus_error(struct mem_ctl_info *mci,
2263 struct amd64_error_info_regs *info)
2264{
2265 u32 err_code, ext_ec;
2266 u32 ec_pp; /* error code participating processor (2p) */
2267 u32 ec_to; /* error code timed out (1b) */
2268 u32 ec_rrrr; /* error code memory transaction (4b) */
2269 u32 ec_ii; /* error code memory or I/O (2b) */
2270 u32 ec_ll; /* error code cache level (2b) */
2271
2272 ext_ec = EXTRACT_EXT_ERROR_CODE(info->nbsl);
2273 err_code = EXTRACT_ERROR_CODE(info->nbsl);
2274
2275 ec_ll = EXTRACT_LL_CODE(err_code);
2276 ec_ii = EXTRACT_II_CODE(err_code);
2277 ec_rrrr = EXTRACT_RRRR_CODE(err_code);
2278 ec_to = EXTRACT_TO_CODE(err_code);
2279 ec_pp = EXTRACT_PP_CODE(err_code);
2280
2281 amd64_mc_printk(mci, KERN_ERR,
2282 "BUS ERROR:\n"
2283 " time-out(%s) mem or i/o(%s)\n"
2284 " participating processor(%s)\n"
2285 " memory transaction type(%s)\n"
2286 " cache level(%s) Error Found by: %s\n",
2287 to_msgs[ec_to],
2288 ii_msgs[ec_ii],
2289 pp_msgs[ec_pp],
2290 rrrr_msgs[ec_rrrr],
2291 ll_msgs[ec_ll],
2292 (info->nbsh & K8_NBSH_ERR_SCRUBER) ?
2293 "Scrubber" : "Normal Operation");
2294
2295 /* If this was an 'observed' error, early out */
2296 if (ec_pp == K8_NBSL_PP_OBS)
2297 return; /* We aren't the node involved */
2298
2299 /* Parse out the extended error code for ECC events */
2300 switch (ext_ec) {
2301 /* F10 changed to one Extended ECC error code */
2302 case F10_NBSL_EXT_ERR_RES: /* Reserved field */
2303 case F10_NBSL_EXT_ERR_ECC: /* F10 ECC ext err code */
2304 break;
2305
2306 default:
2307 amd64_mc_printk(mci, KERN_ERR, "NOT ECC: no special error "
2308 "handling for this error\n");
2309 return;
2310 }
2311
2312 if (info->nbsh & K8_NBSH_CECC)
2313 amd64_handle_ce(mci, info);
2314 else if (info->nbsh & K8_NBSH_UECC)
2315 amd64_handle_ue(mci, info);
2316
2317 /*
2318 * If main error is CE then overflow must be CE. If main error is UE
2319 * then overflow is unknown. We'll call the overflow a CE - if
2320 * panic_on_ue is set then we're already panic'ed and won't arrive
2321 * here. Else, then apparently someone doesn't think that UE's are
2322 * catastrophic.
2323 */
2324 if (info->nbsh & K8_NBSH_OVERFLOW)
2325 edac_mc_handle_ce_no_info(mci, EDAC_MOD_STR
2326 "Error Overflow set");
2327}
2328
2329int amd64_process_error_info(struct mem_ctl_info *mci,
2330 struct amd64_error_info_regs *info,
2331 int handle_errors)
2332{
2333 struct amd64_pvt *pvt;
2334 struct amd64_error_info_regs *regs;
2335 u32 err_code, ext_ec;
2336 int gart_tlb_error = 0;
2337
2338 pvt = mci->pvt_info;
2339
2340 /* If caller doesn't want us to process the error, return */
2341 if (!handle_errors)
2342 return 1;
2343
2344 regs = info;
2345
2346 debugf1("NorthBridge ERROR: mci(0x%p)\n", mci);
2347 debugf1(" MC node(%d) Error-Address(0x%.8x-%.8x)\n",
2348 pvt->mc_node_id, regs->nbeah, regs->nbeal);
2349 debugf1(" nbsh(0x%.8x) nbsl(0x%.8x)\n",
2350 regs->nbsh, regs->nbsl);
2351 debugf1(" Valid Error=%s Overflow=%s\n",
2352 (regs->nbsh & K8_NBSH_VALID_BIT) ? "True" : "False",
2353 (regs->nbsh & K8_NBSH_OVERFLOW) ? "True" : "False");
2354 debugf1(" Err Uncorrected=%s MCA Error Reporting=%s\n",
2355 (regs->nbsh & K8_NBSH_UNCORRECTED_ERR) ?
2356 "True" : "False",
2357 (regs->nbsh & K8_NBSH_ERR_ENABLE) ?
2358 "True" : "False");
2359 debugf1(" MiscErr Valid=%s ErrAddr Valid=%s PCC=%s\n",
2360 (regs->nbsh & K8_NBSH_MISC_ERR_VALID) ?
2361 "True" : "False",
2362 (regs->nbsh & K8_NBSH_VALID_ERROR_ADDR) ?
2363 "True" : "False",
2364 (regs->nbsh & K8_NBSH_PCC) ?
2365 "True" : "False");
2366 debugf1(" CECC=%s UECC=%s Found by Scruber=%s\n",
2367 (regs->nbsh & K8_NBSH_CECC) ?
2368 "True" : "False",
2369 (regs->nbsh & K8_NBSH_UECC) ?
2370 "True" : "False",
2371 (regs->nbsh & K8_NBSH_ERR_SCRUBER) ?
2372 "True" : "False");
2373 debugf1(" CORE0=%s CORE1=%s CORE2=%s CORE3=%s\n",
2374 (regs->nbsh & K8_NBSH_CORE0) ? "True" : "False",
2375 (regs->nbsh & K8_NBSH_CORE1) ? "True" : "False",
2376 (regs->nbsh & K8_NBSH_CORE2) ? "True" : "False",
2377 (regs->nbsh & K8_NBSH_CORE3) ? "True" : "False");
2378
2379
2380 err_code = EXTRACT_ERROR_CODE(regs->nbsl);
2381
2382 /* Determine which error type:
2383 * 1) GART errors - non-fatal, developmental events
2384 * 2) MEMORY errors
2385 * 3) BUS errors
2386 * 4) Unknown error
2387 */
2388 if (TEST_TLB_ERROR(err_code)) {
2389 /*
2390 * GART errors are intended to help graphics driver developers
2391 * to detect bad GART PTEs. It is recommended by AMD to disable
2392 * GART table walk error reporting by default[1] (currently
2393 * being disabled in mce_cpu_quirks()) and according to the
2394 * comment in mce_cpu_quirks(), such GART errors can be
2395 * incorrectly triggered. We may see these errors anyway and
2396 * unless requested by the user, they won't be reported.
2397 *
2398 * [1] section 13.10.1 on BIOS and Kernel Developers Guide for
2399 * AMD NPT family 0Fh processors
2400 */
2401 if (report_gart_errors == 0)
2402 return 1;
2403
2404 /*
2405 * Only if GART error reporting is requested should we generate
2406 * any logs.
2407 */
2408 gart_tlb_error = 1;
2409
2410 debugf1("GART TLB error\n");
2411 amd64_decode_gart_tlb_error(mci, info);
2412 } else if (TEST_MEM_ERROR(err_code)) {
2413 debugf1("Memory/Cache error\n");
2414 amd64_decode_mem_cache_error(mci, info);
2415 } else if (TEST_BUS_ERROR(err_code)) {
2416 debugf1("Bus (Link/DRAM) error\n");
2417 amd64_decode_bus_error(mci, info);
2418 } else {
2419 /* shouldn't reach here! */
2420 amd64_mc_printk(mci, KERN_WARNING,
2421 "%s(): unknown MCE error 0x%x\n", __func__,
2422 err_code);
2423 }
2424
2425 ext_ec = EXTRACT_EXT_ERROR_CODE(regs->nbsl);
2426 amd64_mc_printk(mci, KERN_ERR,
2427 "ExtErr=(0x%x) %s\n", ext_ec, ext_msgs[ext_ec]);
2428
2429 if (((ext_ec >= F10_NBSL_EXT_ERR_CRC &&
2430 ext_ec <= F10_NBSL_EXT_ERR_TGT) ||
2431 (ext_ec == F10_NBSL_EXT_ERR_RMW)) &&
2432 EXTRACT_LDT_LINK(info->nbsh)) {
2433
2434 amd64_mc_printk(mci, KERN_ERR,
2435 "Error on hypertransport link: %s\n",
2436 htlink_msgs[
2437 EXTRACT_LDT_LINK(info->nbsh)]);
2438 }
2439
2440 /*
2441 * Check the UE bit of the NB status high register, if set generate some
2442 * logs. If NOT a GART error, then process the event as a NO-INFO event.
2443 * If it was a GART error, skip that process.
2444 */
2445 if (regs->nbsh & K8_NBSH_UNCORRECTED_ERR) {
2446 amd64_mc_printk(mci, KERN_CRIT, "uncorrected error\n");
2447 if (!gart_tlb_error)
2448 edac_mc_handle_ue_no_info(mci, "UE bit is set\n");
2449 }
2450
2451 if (regs->nbsh & K8_NBSH_PCC)
2452 amd64_mc_printk(mci, KERN_CRIT,
2453 "PCC (processor context corrupt) set\n");
2454
2455 return 1;
2456}
2457EXPORT_SYMBOL_GPL(amd64_process_error_info);
2458
2459/*
2460 * The main polling 'check' function, called FROM the edac core to perform the
2461 * error checking and if an error is encountered, error processing.
2462 */
2463static void amd64_check(struct mem_ctl_info *mci)
2464{
2465 struct amd64_error_info_regs info;
2466
2467 if (amd64_get_error_info(mci, &info))
2468 amd64_process_error_info(mci, &info, 1);
2469}
2470
2471/*
2472 * Input:
2473 * 1) struct amd64_pvt which contains pvt->dram_f2_ctl pointer
2474 * 2) AMD Family index value
2475 *
2476 * Ouput:
2477 * Upon return of 0, the following filled in:
2478 *
2479 * struct pvt->addr_f1_ctl
2480 * struct pvt->misc_f3_ctl
2481 *
2482 * Filled in with related device funcitions of 'dram_f2_ctl'
2483 * These devices are "reserved" via the pci_get_device()
2484 *
2485 * Upon return of 1 (error status):
2486 *
2487 * Nothing reserved
2488 */
2489static int amd64_reserve_mc_sibling_devices(struct amd64_pvt *pvt, int mc_idx)
2490{
2491 const struct amd64_family_type *amd64_dev = &amd64_family_types[mc_idx];
2492
2493 /* Reserve the ADDRESS MAP Device */
2494 pvt->addr_f1_ctl = pci_get_related_function(pvt->dram_f2_ctl->vendor,
2495 amd64_dev->addr_f1_ctl,
2496 pvt->dram_f2_ctl);
2497
2498 if (!pvt->addr_f1_ctl) {
2499 amd64_printk(KERN_ERR, "error address map device not found: "
2500 "vendor %x device 0x%x (broken BIOS?)\n",
2501 PCI_VENDOR_ID_AMD, amd64_dev->addr_f1_ctl);
2502 return 1;
2503 }
2504
2505 /* Reserve the MISC Device */
2506 pvt->misc_f3_ctl = pci_get_related_function(pvt->dram_f2_ctl->vendor,
2507 amd64_dev->misc_f3_ctl,
2508 pvt->dram_f2_ctl);
2509
2510 if (!pvt->misc_f3_ctl) {
2511 pci_dev_put(pvt->addr_f1_ctl);
2512 pvt->addr_f1_ctl = NULL;
2513
2514 amd64_printk(KERN_ERR, "error miscellaneous device not found: "
2515 "vendor %x device 0x%x (broken BIOS?)\n",
2516 PCI_VENDOR_ID_AMD, amd64_dev->misc_f3_ctl);
2517 return 1;
2518 }
2519
2520 debugf1(" Addr Map device PCI Bus ID:\t%s\n",
2521 pci_name(pvt->addr_f1_ctl));
2522 debugf1(" DRAM MEM-CTL PCI Bus ID:\t%s\n",
2523 pci_name(pvt->dram_f2_ctl));
2524 debugf1(" Misc device PCI Bus ID:\t%s\n",
2525 pci_name(pvt->misc_f3_ctl));
2526
2527 return 0;
2528}
2529
2530static void amd64_free_mc_sibling_devices(struct amd64_pvt *pvt)
2531{
2532 pci_dev_put(pvt->addr_f1_ctl);
2533 pci_dev_put(pvt->misc_f3_ctl);
2534}
2535
2536/*
2537 * Retrieve the hardware registers of the memory controller (this includes the
2538 * 'Address Map' and 'Misc' device regs)
2539 */
2540static void amd64_read_mc_registers(struct amd64_pvt *pvt)
2541{
2542 u64 msr_val;
2543 int dram, err = 0;
2544
2545 /*
2546 * Retrieve TOP_MEM and TOP_MEM2; no masking off of reserved bits since
2547 * those are Read-As-Zero
2548 */
2549 rdmsrl(MSR_K8_TOP_MEM1, msr_val);
2550 pvt->top_mem = msr_val >> 23;
2551 debugf0(" TOP_MEM=0x%08llx\n", pvt->top_mem);
2552
2553 /* check first whether TOP_MEM2 is enabled */
2554 rdmsrl(MSR_K8_SYSCFG, msr_val);
2555 if (msr_val & (1U << 21)) {
2556 rdmsrl(MSR_K8_TOP_MEM2, msr_val);
2557 pvt->top_mem2 = msr_val >> 23;
2558 debugf0(" TOP_MEM2=0x%08llx\n", pvt->top_mem2);
2559 } else
2560 debugf0(" TOP_MEM2 disabled.\n");
2561
2562 amd64_cpu_display_info(pvt);
2563
2564 err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCAP, &pvt->nbcap);
2565 if (err)
2566 goto err_reg;
2567
2568 if (pvt->ops->read_dram_ctl_register)
2569 pvt->ops->read_dram_ctl_register(pvt);
2570
2571 for (dram = 0; dram < DRAM_REG_COUNT; dram++) {
2572 /*
2573 * Call CPU specific READ function to get the DRAM Base and
2574 * Limit values from the DCT.
2575 */
2576 pvt->ops->read_dram_base_limit(pvt, dram);
2577
2578 /*
2579 * Only print out debug info on rows with both R and W Enabled.
2580 * Normal processing, compiler should optimize this whole 'if'
2581 * debug output block away.
2582 */
2583 if (pvt->dram_rw_en[dram] != 0) {
2584 debugf1(" DRAM_BASE[%d]: 0x%8.08x-%8.08x "
2585 "DRAM_LIMIT: 0x%8.08x-%8.08x\n",
2586 dram,
2587 (u32)(pvt->dram_base[dram] >> 32),
2588 (u32)(pvt->dram_base[dram] & 0xFFFFFFFF),
2589 (u32)(pvt->dram_limit[dram] >> 32),
2590 (u32)(pvt->dram_limit[dram] & 0xFFFFFFFF));
2591 debugf1(" IntlvEn=%s %s %s "
2592 "IntlvSel=%d DstNode=%d\n",
2593 pvt->dram_IntlvEn[dram] ?
2594 "Enabled" : "Disabled",
2595 (pvt->dram_rw_en[dram] & 0x2) ? "W" : "!W",
2596 (pvt->dram_rw_en[dram] & 0x1) ? "R" : "!R",
2597 pvt->dram_IntlvSel[dram],
2598 pvt->dram_DstNode[dram]);
2599 }
2600 }
2601
2602 amd64_read_dct_base_mask(pvt);
2603
2604 err = pci_read_config_dword(pvt->addr_f1_ctl, K8_DHAR, &pvt->dhar);
2605 if (err)
2606 goto err_reg;
2607
2608 amd64_read_dbam_reg(pvt);
2609
2610 err = pci_read_config_dword(pvt->misc_f3_ctl,
2611 F10_ONLINE_SPARE, &pvt->online_spare);
2612 if (err)
2613 goto err_reg;
2614
2615 err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCLR_0, &pvt->dclr0);
2616 if (err)
2617 goto err_reg;
2618
2619 err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCHR_0, &pvt->dchr0);
2620 if (err)
2621 goto err_reg;
2622
2623 if (!dct_ganging_enabled(pvt)) {
2624 err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCLR_1,
2625 &pvt->dclr1);
2626 if (err)
2627 goto err_reg;
2628
2629 err = pci_read_config_dword(pvt->dram_f2_ctl, F10_DCHR_1,
2630 &pvt->dchr1);
2631 if (err)
2632 goto err_reg;
2633 }
2634
2635 amd64_dump_misc_regs(pvt);
2636
2637err_reg:
2638 debugf0("Reading an MC register failed\n");
2639
2640}
2641
2642/*
2643 * NOTE: CPU Revision Dependent code
2644 *
2645 * Input:
2646 * @csrow_nr ChipSelect Row Number (0..CHIPSELECT_COUNT-1)
2647 * k8 private pointer to -->
2648 * DRAM Bank Address mapping register
2649 * node_id
2650 * DCL register where dual_channel_active is
2651 *
2652 * The DBAM register consists of 4 sets of 4 bits each definitions:
2653 *
2654 * Bits: CSROWs
2655 * 0-3 CSROWs 0 and 1
2656 * 4-7 CSROWs 2 and 3
2657 * 8-11 CSROWs 4 and 5
2658 * 12-15 CSROWs 6 and 7
2659 *
2660 * Values range from: 0 to 15
2661 * The meaning of the values depends on CPU revision and dual-channel state,
2662 * see relevant BKDG more info.
2663 *
2664 * The memory controller provides for total of only 8 CSROWs in its current
2665 * architecture. Each "pair" of CSROWs normally represents just one DIMM in
2666 * single channel or two (2) DIMMs in dual channel mode.
2667 *
2668 * The following code logic collapses the various tables for CSROW based on CPU
2669 * revision.
2670 *
2671 * Returns:
2672 * The number of PAGE_SIZE pages on the specified CSROW number it
2673 * encompasses
2674 *
2675 */
2676static u32 amd64_csrow_nr_pages(int csrow_nr, struct amd64_pvt *pvt)
2677{
2678 u32 dram_map, nr_pages;
2679
2680 /*
2681 * The math on this doesn't look right on the surface because x/2*4 can
2682 * be simplified to x*2 but this expression makes use of the fact that
2683 * it is integral math where 1/2=0. This intermediate value becomes the
2684 * number of bits to shift the DBAM register to extract the proper CSROW
2685 * field.
2686 */
2687 dram_map = (pvt->dbam0 >> ((csrow_nr / 2) * 4)) & 0xF;
2688
2689 nr_pages = pvt->ops->dbam_map_to_pages(pvt, dram_map);
2690
2691 /*
2692 * If dual channel then double the memory size of single channel.
2693 * Channel count is 1 or 2
2694 */
2695 nr_pages <<= (pvt->channel_count - 1);
2696
2697 debugf0(" (csrow=%d) DBAM map index= %d\n", csrow_nr, dram_map);
2698 debugf0(" nr_pages= %u channel-count = %d\n",
2699 nr_pages, pvt->channel_count);
2700
2701 return nr_pages;
2702}
2703
2704/*
2705 * Initialize the array of csrow attribute instances, based on the values
2706 * from pci config hardware registers.
2707 */
2708static int amd64_init_csrows(struct mem_ctl_info *mci)
2709{
2710 struct csrow_info *csrow;
2711 struct amd64_pvt *pvt;
2712 u64 input_addr_min, input_addr_max, sys_addr;
2713 int i, err = 0, empty = 1;
2714
2715 pvt = mci->pvt_info;
2716
2717 err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCFG, &pvt->nbcfg);
2718 if (err)
2719 debugf0("Reading K8_NBCFG failed\n");
2720
2721 debugf0("NBCFG= 0x%x CHIPKILL= %s DRAM ECC= %s\n", pvt->nbcfg,
2722 (pvt->nbcfg & K8_NBCFG_CHIPKILL) ? "Enabled" : "Disabled",
2723 (pvt->nbcfg & K8_NBCFG_ECC_ENABLE) ? "Enabled" : "Disabled"
2724 );
2725
2726 for (i = 0; i < CHIPSELECT_COUNT; i++) {
2727 csrow = &mci->csrows[i];
2728
2729 if ((pvt->dcsb0[i] & K8_DCSB_CS_ENABLE) == 0) {
2730 debugf1("----CSROW %d EMPTY for node %d\n", i,
2731 pvt->mc_node_id);
2732 continue;
2733 }
2734
2735 debugf1("----CSROW %d VALID for MC node %d\n",
2736 i, pvt->mc_node_id);
2737
2738 empty = 0;
2739 csrow->nr_pages = amd64_csrow_nr_pages(i, pvt);
2740 find_csrow_limits(mci, i, &input_addr_min, &input_addr_max);
2741 sys_addr = input_addr_to_sys_addr(mci, input_addr_min);
2742 csrow->first_page = (u32) (sys_addr >> PAGE_SHIFT);
2743 sys_addr = input_addr_to_sys_addr(mci, input_addr_max);
2744 csrow->last_page = (u32) (sys_addr >> PAGE_SHIFT);
2745 csrow->page_mask = ~mask_from_dct_mask(pvt, i);
2746 /* 8 bytes of resolution */
2747
2748 csrow->mtype = amd64_determine_memory_type(pvt);
2749
2750 debugf1(" for MC node %d csrow %d:\n", pvt->mc_node_id, i);
2751 debugf1(" input_addr_min: 0x%lx input_addr_max: 0x%lx\n",
2752 (unsigned long)input_addr_min,
2753 (unsigned long)input_addr_max);
2754 debugf1(" sys_addr: 0x%lx page_mask: 0x%lx\n",
2755 (unsigned long)sys_addr, csrow->page_mask);
2756 debugf1(" nr_pages: %u first_page: 0x%lx "
2757 "last_page: 0x%lx\n",
2758 (unsigned)csrow->nr_pages,
2759 csrow->first_page, csrow->last_page);
2760
2761 /*
2762 * determine whether CHIPKILL or JUST ECC or NO ECC is operating
2763 */
2764 if (pvt->nbcfg & K8_NBCFG_ECC_ENABLE)
2765 csrow->edac_mode =
2766 (pvt->nbcfg & K8_NBCFG_CHIPKILL) ?
2767 EDAC_S4ECD4ED : EDAC_SECDED;
2768 else
2769 csrow->edac_mode = EDAC_NONE;
2770 }
2771
2772 return empty;
2773}
2774
2775/*
2776 * Only if 'ecc_enable_override' is set AND BIOS had ECC disabled, do "we"
2777 * enable it.
2778 */
2779static void amd64_enable_ecc_error_reporting(struct mem_ctl_info *mci)
2780{
2781 struct amd64_pvt *pvt = mci->pvt_info;
2782 const cpumask_t *cpumask = cpumask_of_node(pvt->mc_node_id);
2783 int cpu, idx = 0, err = 0;
2784 struct msr msrs[cpumask_weight(cpumask)];
2785 u32 value;
2786 u32 mask = K8_NBCTL_CECCEn | K8_NBCTL_UECCEn;
2787
2788 if (!ecc_enable_override)
2789 return;
2790
2791 memset(msrs, 0, sizeof(msrs));
2792
2793 amd64_printk(KERN_WARNING,
2794 "'ecc_enable_override' parameter is active, "
2795 "Enabling AMD ECC hardware now: CAUTION\n");
2796
2797 err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCTL, &value);
2798 if (err)
2799 debugf0("Reading K8_NBCTL failed\n");
2800
2801 /* turn on UECCn and CECCEn bits */
2802 pvt->old_nbctl = value & mask;
2803 pvt->nbctl_mcgctl_saved = 1;
2804
2805 value |= mask;
2806 pci_write_config_dword(pvt->misc_f3_ctl, K8_NBCTL, value);
2807
2808 rdmsr_on_cpus(cpumask, K8_MSR_MCGCTL, msrs);
2809
2810 for_each_cpu(cpu, cpumask) {
2811 if (msrs[idx].l & K8_MSR_MCGCTL_NBE)
2812 set_bit(idx, &pvt->old_mcgctl);
2813
2814 msrs[idx].l |= K8_MSR_MCGCTL_NBE;
2815 idx++;
2816 }
2817 wrmsr_on_cpus(cpumask, K8_MSR_MCGCTL, msrs);
2818
2819 err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCFG, &value);
2820 if (err)
2821 debugf0("Reading K8_NBCFG failed\n");
2822
2823 debugf0("NBCFG(1)= 0x%x CHIPKILL= %s ECC_ENABLE= %s\n", value,
2824 (value & K8_NBCFG_CHIPKILL) ? "Enabled" : "Disabled",
2825 (value & K8_NBCFG_ECC_ENABLE) ? "Enabled" : "Disabled");
2826
2827 if (!(value & K8_NBCFG_ECC_ENABLE)) {
2828 amd64_printk(KERN_WARNING,
2829 "This node reports that DRAM ECC is "
2830 "currently Disabled; ENABLING now\n");
2831
2832 /* Attempt to turn on DRAM ECC Enable */
2833 value |= K8_NBCFG_ECC_ENABLE;
2834 pci_write_config_dword(pvt->misc_f3_ctl, K8_NBCFG, value);
2835
2836 err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCFG, &value);
2837 if (err)
2838 debugf0("Reading K8_NBCFG failed\n");
2839
2840 if (!(value & K8_NBCFG_ECC_ENABLE)) {
2841 amd64_printk(KERN_WARNING,
2842 "Hardware rejects Enabling DRAM ECC checking\n"
2843 "Check memory DIMM configuration\n");
2844 } else {
2845 amd64_printk(KERN_DEBUG,
2846 "Hardware accepted DRAM ECC Enable\n");
2847 }
2848 }
2849 debugf0("NBCFG(2)= 0x%x CHIPKILL= %s ECC_ENABLE= %s\n", value,
2850 (value & K8_NBCFG_CHIPKILL) ? "Enabled" : "Disabled",
2851 (value & K8_NBCFG_ECC_ENABLE) ? "Enabled" : "Disabled");
2852
2853 pvt->ctl_error_info.nbcfg = value;
2854}
2855
2856static void amd64_restore_ecc_error_reporting(struct amd64_pvt *pvt)
2857{
2858 const cpumask_t *cpumask = cpumask_of_node(pvt->mc_node_id);
2859 int cpu, idx = 0, err = 0;
2860 struct msr msrs[cpumask_weight(cpumask)];
2861 u32 value;
2862 u32 mask = K8_NBCTL_CECCEn | K8_NBCTL_UECCEn;
2863
2864 if (!pvt->nbctl_mcgctl_saved)
2865 return;
2866
2867 memset(msrs, 0, sizeof(msrs));
2868
2869 err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCTL, &value);
2870 if (err)
2871 debugf0("Reading K8_NBCTL failed\n");
2872 value &= ~mask;
2873 value |= pvt->old_nbctl;
2874
2875 /* restore the NB Enable MCGCTL bit */
2876 pci_write_config_dword(pvt->misc_f3_ctl, K8_NBCTL, value);
2877
2878 rdmsr_on_cpus(cpumask, K8_MSR_MCGCTL, msrs);
2879
2880 for_each_cpu(cpu, cpumask) {
2881 msrs[idx].l &= ~K8_MSR_MCGCTL_NBE;
2882 msrs[idx].l |=
2883 test_bit(idx, &pvt->old_mcgctl) << K8_MSR_MCGCTL_NBE;
2884 idx++;
2885 }
2886
2887 wrmsr_on_cpus(cpumask, K8_MSR_MCGCTL, msrs);
2888}
2889
2890static void check_mcg_ctl(void *ret)
2891{
2892 u64 msr_val = 0;
2893 u8 nbe;
2894
2895 rdmsrl(MSR_IA32_MCG_CTL, msr_val);
2896 nbe = msr_val & K8_MSR_MCGCTL_NBE;
2897
2898 debugf0("core: %u, MCG_CTL: 0x%llx, NB MSR is %s\n",
2899 raw_smp_processor_id(), msr_val,
2900 (nbe ? "enabled" : "disabled"));
2901
2902 if (!nbe)
2903 *(int *)ret = 0;
2904}
2905
2906/* check MCG_CTL on all the cpus on this node */
2907static int amd64_mcg_ctl_enabled_on_cpus(const cpumask_t *mask)
2908{
2909 int ret = 1;
2910 preempt_disable();
2911 smp_call_function_many(mask, check_mcg_ctl, &ret, 1);
2912 preempt_enable();
2913
2914 return ret;
2915}
2916
2917/*
2918 * EDAC requires that the BIOS have ECC enabled before taking over the
2919 * processing of ECC errors. This is because the BIOS can properly initialize
2920 * the memory system completely. A command line option allows to force-enable
2921 * hardware ECC later in amd64_enable_ecc_error_reporting().
2922 */
2923static int amd64_check_ecc_enabled(struct amd64_pvt *pvt)
2924{
2925 u32 value;
2926 int err = 0, ret = 0;
2927 u8 ecc_enabled = 0;
2928
2929 err = pci_read_config_dword(pvt->misc_f3_ctl, K8_NBCFG, &value);
2930 if (err)
2931 debugf0("Reading K8_NBCTL failed\n");
2932
2933 ecc_enabled = !!(value & K8_NBCFG_ECC_ENABLE);
2934
2935 ret = amd64_mcg_ctl_enabled_on_cpus(cpumask_of_node(pvt->mc_node_id));
2936
2937 debugf0("K8_NBCFG=0x%x, DRAM ECC is %s\n", value,
2938 (value & K8_NBCFG_ECC_ENABLE ? "enabled" : "disabled"));
2939
2940 if (!ecc_enabled || !ret) {
2941 if (!ecc_enabled) {
2942 amd64_printk(KERN_WARNING, "This node reports that "
2943 "Memory ECC is currently "
2944 "disabled.\n");
2945
2946 amd64_printk(KERN_WARNING, "bit 0x%lx in register "
2947 "F3x%x of the MISC_CONTROL device (%s) "
2948 "should be enabled\n", K8_NBCFG_ECC_ENABLE,
2949 K8_NBCFG, pci_name(pvt->misc_f3_ctl));
2950 }
2951 if (!ret) {
2952 amd64_printk(KERN_WARNING, "bit 0x%016lx in MSR 0x%08x "
2953 "of node %d should be enabled\n",
2954 K8_MSR_MCGCTL_NBE, MSR_IA32_MCG_CTL,
2955 pvt->mc_node_id);
2956 }
2957 if (!ecc_enable_override) {
2958 amd64_printk(KERN_WARNING, "WARNING: ECC is NOT "
2959 "currently enabled by the BIOS. Module "
2960 "will NOT be loaded.\n"
2961 " Either Enable ECC in the BIOS, "
2962 "or use the 'ecc_enable_override' "
2963 "parameter.\n"
2964 " Might be a BIOS bug, if BIOS says "
2965 "ECC is enabled\n"
2966 " Use of the override can cause "
2967 "unknown side effects.\n");
2968 ret = -ENODEV;
2969 }
2970 } else {
2971 amd64_printk(KERN_INFO,
2972 "ECC is enabled by BIOS, Proceeding "
2973 "with EDAC module initialization\n");
2974
2975 /* CLEAR the override, since BIOS controlled it */
2976 ecc_enable_override = 0;
2977 }
2978
2979 return ret;
2980}
2981
2982struct mcidev_sysfs_attribute sysfs_attrs[ARRAY_SIZE(amd64_dbg_attrs) +
2983 ARRAY_SIZE(amd64_inj_attrs) +
2984 1];
2985
2986struct mcidev_sysfs_attribute terminator = { .attr = { .name = NULL } };
2987
2988static void amd64_set_mc_sysfs_attributes(struct mem_ctl_info *mci)
2989{
2990 unsigned int i = 0, j = 0;
2991
2992 for (; i < ARRAY_SIZE(amd64_dbg_attrs); i++)
2993 sysfs_attrs[i] = amd64_dbg_attrs[i];
2994
2995 for (j = 0; j < ARRAY_SIZE(amd64_inj_attrs); j++, i++)
2996 sysfs_attrs[i] = amd64_inj_attrs[j];
2997
2998 sysfs_attrs[i] = terminator;
2999
3000 mci->mc_driver_sysfs_attributes = sysfs_attrs;
3001}
3002
3003static void amd64_setup_mci_misc_attributes(struct mem_ctl_info *mci)
3004{
3005 struct amd64_pvt *pvt = mci->pvt_info;
3006
3007 mci->mtype_cap = MEM_FLAG_DDR2 | MEM_FLAG_RDDR2;
3008 mci->edac_ctl_cap = EDAC_FLAG_NONE;
3009 mci->edac_cap = EDAC_FLAG_NONE;
3010
3011 if (pvt->nbcap & K8_NBCAP_SECDED)
3012 mci->edac_ctl_cap |= EDAC_FLAG_SECDED;
3013
3014 if (pvt->nbcap & K8_NBCAP_CHIPKILL)
3015 mci->edac_ctl_cap |= EDAC_FLAG_S4ECD4ED;
3016
3017 mci->edac_cap = amd64_determine_edac_cap(pvt);
3018 mci->mod_name = EDAC_MOD_STR;
3019 mci->mod_ver = EDAC_AMD64_VERSION;
3020 mci->ctl_name = get_amd_family_name(pvt->mc_type_index);
3021 mci->dev_name = pci_name(pvt->dram_f2_ctl);
3022 mci->ctl_page_to_phys = NULL;
3023
3024 /* IMPORTANT: Set the polling 'check' function in this module */
3025 mci->edac_check = amd64_check;
3026
3027 /* memory scrubber interface */
3028 mci->set_sdram_scrub_rate = amd64_set_scrub_rate;
3029 mci->get_sdram_scrub_rate = amd64_get_scrub_rate;
3030}
3031
3032/*
3033 * Init stuff for this DRAM Controller device.
3034 *
3035 * Due to a hardware feature on Fam10h CPUs, the Enable Extended Configuration
3036 * Space feature MUST be enabled on ALL Processors prior to actually reading
3037 * from the ECS registers. Since the loading of the module can occur on any
3038 * 'core', and cores don't 'see' all the other processors ECS data when the
3039 * others are NOT enabled. Our solution is to first enable ECS access in this
3040 * routine on all processors, gather some data in a amd64_pvt structure and
3041 * later come back in a finish-setup function to perform that final
3042 * initialization. See also amd64_init_2nd_stage() for that.
3043 */
3044static int amd64_probe_one_instance(struct pci_dev *dram_f2_ctl,
3045 int mc_type_index)
3046{
3047 struct amd64_pvt *pvt = NULL;
3048 int err = 0, ret;
3049
3050 ret = -ENOMEM;
3051 pvt = kzalloc(sizeof(struct amd64_pvt), GFP_KERNEL);
3052 if (!pvt)
3053 goto err_exit;
3054
3055 pvt->mc_node_id = get_mc_node_id_from_pdev(dram_f2_ctl);
3056
3057 pvt->dram_f2_ctl = dram_f2_ctl;
3058 pvt->ext_model = boot_cpu_data.x86_model >> 4;
3059 pvt->mc_type_index = mc_type_index;
3060 pvt->ops = family_ops(mc_type_index);
3061 pvt->old_mcgctl = 0;
3062
3063 /*
3064 * We have the dram_f2_ctl device as an argument, now go reserve its
3065 * sibling devices from the PCI system.
3066 */
3067 ret = -ENODEV;
3068 err = amd64_reserve_mc_sibling_devices(pvt, mc_type_index);
3069 if (err)
3070 goto err_free;
3071
3072 ret = -EINVAL;
3073 err = amd64_check_ecc_enabled(pvt);
3074 if (err)
3075 goto err_put;
3076
3077 /*
3078 * Key operation here: setup of HW prior to performing ops on it. Some
3079 * setup is required to access ECS data. After this is performed, the
3080 * 'teardown' function must be called upon error and normal exit paths.
3081 */
3082 if (boot_cpu_data.x86 >= 0x10)
3083 amd64_setup(pvt);
3084
3085 /*
3086 * Save the pointer to the private data for use in 2nd initialization
3087 * stage
3088 */
3089 pvt_lookup[pvt->mc_node_id] = pvt;
3090
3091 return 0;
3092
3093err_put:
3094 amd64_free_mc_sibling_devices(pvt);
3095
3096err_free:
3097 kfree(pvt);
3098
3099err_exit:
3100 return ret;
3101}
3102
3103/*
3104 * This is the finishing stage of the init code. Needs to be performed after all
3105 * MCs' hardware have been prepped for accessing extended config space.
3106 */
3107static int amd64_init_2nd_stage(struct amd64_pvt *pvt)
3108{
3109 int node_id = pvt->mc_node_id;
3110 struct mem_ctl_info *mci;
3111 int ret, err = 0;
3112
3113 amd64_read_mc_registers(pvt);
3114
3115 ret = -ENODEV;
3116 if (pvt->ops->probe_valid_hardware) {
3117 err = pvt->ops->probe_valid_hardware(pvt);
3118 if (err)
3119 goto err_exit;
3120 }
3121
3122 /*
3123 * We need to determine how many memory channels there are. Then use
3124 * that information for calculating the size of the dynamic instance
3125 * tables in the 'mci' structure
3126 */
3127 pvt->channel_count = pvt->ops->early_channel_count(pvt);
3128 if (pvt->channel_count < 0)
3129 goto err_exit;
3130
3131 ret = -ENOMEM;
3132 mci = edac_mc_alloc(0, CHIPSELECT_COUNT, pvt->channel_count, node_id);
3133 if (!mci)
3134 goto err_exit;
3135
3136 mci->pvt_info = pvt;
3137
3138 mci->dev = &pvt->dram_f2_ctl->dev;
3139 amd64_setup_mci_misc_attributes(mci);
3140
3141 if (amd64_init_csrows(mci))
3142 mci->edac_cap = EDAC_FLAG_NONE;
3143
3144 amd64_enable_ecc_error_reporting(mci);
3145 amd64_set_mc_sysfs_attributes(mci);
3146
3147 ret = -ENODEV;
3148 if (edac_mc_add_mc(mci)) {
3149 debugf1("failed edac_mc_add_mc()\n");
3150 goto err_add_mc;
3151 }
3152
3153 mci_lookup[node_id] = mci;
3154 pvt_lookup[node_id] = NULL;
3155 return 0;
3156
3157err_add_mc:
3158 edac_mc_free(mci);
3159
3160err_exit:
3161 debugf0("failure to init 2nd stage: ret=%d\n", ret);
3162
3163 amd64_restore_ecc_error_reporting(pvt);
3164
3165 if (boot_cpu_data.x86 > 0xf)
3166 amd64_teardown(pvt);
3167
3168 amd64_free_mc_sibling_devices(pvt);
3169
3170 kfree(pvt_lookup[pvt->mc_node_id]);
3171 pvt_lookup[node_id] = NULL;
3172
3173 return ret;
3174}
3175
3176
3177static int __devinit amd64_init_one_instance(struct pci_dev *pdev,
3178 const struct pci_device_id *mc_type)
3179{
3180 int ret = 0;
3181
3182 debugf0("(MC node=%d,mc_type='%s')\n",
3183 get_mc_node_id_from_pdev(pdev),
3184 get_amd_family_name(mc_type->driver_data));
3185
3186 ret = pci_enable_device(pdev);
3187 if (ret < 0)
3188 ret = -EIO;
3189 else
3190 ret = amd64_probe_one_instance(pdev, mc_type->driver_data);
3191
3192 if (ret < 0)
3193 debugf0("ret=%d\n", ret);
3194
3195 return ret;
3196}
3197
3198static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
3199{
3200 struct mem_ctl_info *mci;
3201 struct amd64_pvt *pvt;
3202
3203 /* Remove from EDAC CORE tracking list */
3204 mci = edac_mc_del_mc(&pdev->dev);
3205 if (!mci)
3206 return;
3207
3208 pvt = mci->pvt_info;
3209
3210 amd64_restore_ecc_error_reporting(pvt);
3211
3212 if (boot_cpu_data.x86 > 0xf)
3213 amd64_teardown(pvt);
3214
3215 amd64_free_mc_sibling_devices(pvt);
3216
3217 kfree(pvt);
3218 mci->pvt_info = NULL;
3219
3220 mci_lookup[pvt->mc_node_id] = NULL;
3221
3222 /* Free the EDAC CORE resources */
3223 edac_mc_free(mci);
3224}
3225
3226/*
3227 * This table is part of the interface for loading drivers for PCI devices. The
3228 * PCI core identifies what devices are on a system during boot, and then
3229 * inquiry this table to see if this driver is for a given device found.
3230 */
3231static const struct pci_device_id amd64_pci_table[] __devinitdata = {
3232 {
3233 .vendor = PCI_VENDOR_ID_AMD,
3234 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
3235 .subvendor = PCI_ANY_ID,
3236 .subdevice = PCI_ANY_ID,
3237 .class = 0,
3238 .class_mask = 0,
3239 .driver_data = K8_CPUS
3240 },
3241 {
3242 .vendor = PCI_VENDOR_ID_AMD,
3243 .device = PCI_DEVICE_ID_AMD_10H_NB_DRAM,
3244 .subvendor = PCI_ANY_ID,
3245 .subdevice = PCI_ANY_ID,
3246 .class = 0,
3247 .class_mask = 0,
3248 .driver_data = F10_CPUS
3249 },
3250 {
3251 .vendor = PCI_VENDOR_ID_AMD,
3252 .device = PCI_DEVICE_ID_AMD_11H_NB_DRAM,
3253 .subvendor = PCI_ANY_ID,
3254 .subdevice = PCI_ANY_ID,
3255 .class = 0,
3256 .class_mask = 0,
3257 .driver_data = F11_CPUS
3258 },
3259 {0, }
3260};
3261MODULE_DEVICE_TABLE(pci, amd64_pci_table);
3262
3263static struct pci_driver amd64_pci_driver = {
3264 .name = EDAC_MOD_STR,
3265 .probe = amd64_init_one_instance,
3266 .remove = __devexit_p(amd64_remove_one_instance),
3267 .id_table = amd64_pci_table,
3268};
3269
3270static void amd64_setup_pci_device(void)
3271{
3272 struct mem_ctl_info *mci;
3273 struct amd64_pvt *pvt;
3274
3275 if (amd64_ctl_pci)
3276 return;
3277
3278 mci = mci_lookup[0];
3279 if (mci) {
3280
3281 pvt = mci->pvt_info;
3282 amd64_ctl_pci =
3283 edac_pci_create_generic_ctl(&pvt->dram_f2_ctl->dev,
3284 EDAC_MOD_STR);
3285
3286 if (!amd64_ctl_pci) {
3287 pr_warning("%s(): Unable to create PCI control\n",
3288 __func__);
3289
3290 pr_warning("%s(): PCI error report via EDAC not set\n",
3291 __func__);
3292 }
3293 }
3294}
3295
3296static int __init amd64_edac_init(void)
3297{
3298 int nb, err = -ENODEV;
3299
3300 edac_printk(KERN_INFO, EDAC_MOD_STR, EDAC_AMD64_VERSION "\n");
3301
3302 opstate_init();
3303
3304 if (cache_k8_northbridges() < 0)
3305 goto err_exit;
3306
3307 err = pci_register_driver(&amd64_pci_driver);
3308 if (err)
3309 return err;
3310
3311 /*
3312 * At this point, the array 'pvt_lookup[]' contains pointers to alloc'd
3313 * amd64_pvt structs. These will be used in the 2nd stage init function
3314 * to finish initialization of the MC instances.
3315 */
3316 for (nb = 0; nb < num_k8_northbridges; nb++) {
3317 if (!pvt_lookup[nb])
3318 continue;
3319
3320 err = amd64_init_2nd_stage(pvt_lookup[nb]);
3321 if (err)
3322 goto err_exit;
3323 }
3324
3325 amd64_setup_pci_device();
3326
3327 return 0;
3328
3329err_exit:
3330 debugf0("'finish_setup' stage failed\n");
3331 pci_unregister_driver(&amd64_pci_driver);
3332
3333 return err;
3334}
3335
3336static void __exit amd64_edac_exit(void)
3337{
3338 if (amd64_ctl_pci)
3339 edac_pci_release_generic_ctl(amd64_ctl_pci);
3340
3341 pci_unregister_driver(&amd64_pci_driver);
3342}
3343
3344module_init(amd64_edac_init);
3345module_exit(amd64_edac_exit);
3346
3347MODULE_LICENSE("GPL");
3348MODULE_AUTHOR("SoftwareBitMaker: Doug Thompson, "
3349 "Dave Peterson, Thayne Harbaugh");
3350MODULE_DESCRIPTION("MC support for AMD64 memory controllers - "
3351 EDAC_AMD64_VERSION);
3352
3353module_param(edac_op_state, int, 0444);
3354MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
diff --git a/drivers/edac/amd64_edac.h b/drivers/edac/amd64_edac.h
new file mode 100644
index 000000000000..a159957e167b
--- /dev/null
+++ b/drivers/edac/amd64_edac.h
@@ -0,0 +1,644 @@
1/*
2 * AMD64 class Memory Controller kernel module
3 *
4 * Copyright (c) 2009 SoftwareBitMaker.
5 * Copyright (c) 2009 Advanced Micro Devices, Inc.
6 *
7 * This file may be distributed under the terms of the
8 * GNU General Public License.
9 *
10 * Originally Written by Thayne Harbaugh
11 *
12 * Changes by Douglas "norsk" Thompson <dougthompson@xmission.com>:
13 * - K8 CPU Revision D and greater support
14 *
15 * Changes by Dave Peterson <dsp@llnl.gov> <dave_peterson@pobox.com>:
16 * - Module largely rewritten, with new (and hopefully correct)
17 * code for dealing with node and chip select interleaving,
18 * various code cleanup, and bug fixes
19 * - Added support for memory hoisting using DRAM hole address
20 * register
21 *
22 * Changes by Douglas "norsk" Thompson <dougthompson@xmission.com>:
23 * -K8 Rev (1207) revision support added, required Revision
24 * specific mini-driver code to support Rev F as well as
25 * prior revisions
26 *
27 * Changes by Douglas "norsk" Thompson <dougthompson@xmission.com>:
28 * -Family 10h revision support added. New PCI Device IDs,
29 * indicating new changes. Actual registers modified
30 * were slight, less than the Rev E to Rev F transition
31 * but changing the PCI Device ID was the proper thing to
32 * do, as it provides for almost automactic family
33 * detection. The mods to Rev F required more family
34 * information detection.
35 *
36 * Changes/Fixes by Borislav Petkov <borislav.petkov@amd.com>:
37 * - misc fixes and code cleanups
38 *
39 * This module is based on the following documents
40 * (available from http://www.amd.com/):
41 *
42 * Title: BIOS and Kernel Developer's Guide for AMD Athlon 64 and AMD
43 * Opteron Processors
44 * AMD publication #: 26094
45 *` Revision: 3.26
46 *
47 * Title: BIOS and Kernel Developer's Guide for AMD NPT Family 0Fh
48 * Processors
49 * AMD publication #: 32559
50 * Revision: 3.00
51 * Issue Date: May 2006
52 *
53 * Title: BIOS and Kernel Developer's Guide (BKDG) For AMD Family 10h
54 * Processors
55 * AMD publication #: 31116
56 * Revision: 3.00
57 * Issue Date: September 07, 2007
58 *
59 * Sections in the first 2 documents are no longer in sync with each other.
60 * The Family 10h BKDG was totally re-written from scratch with a new
61 * presentation model.
62 * Therefore, comments that refer to a Document section might be off.
63 */
64
65#include <linux/module.h>
66#include <linux/ctype.h>
67#include <linux/init.h>
68#include <linux/pci.h>
69#include <linux/pci_ids.h>
70#include <linux/slab.h>
71#include <linux/mmzone.h>
72#include <linux/edac.h>
73#include <asm/msr.h>
74#include "edac_core.h"
75
76#define amd64_printk(level, fmt, arg...) \
77 edac_printk(level, "amd64", fmt, ##arg)
78
79#define amd64_mc_printk(mci, level, fmt, arg...) \
80 edac_mc_chipset_printk(mci, level, "amd64", fmt, ##arg)
81
82/*
83 * Throughout the comments in this code, the following terms are used:
84 *
85 * SysAddr, DramAddr, and InputAddr
86 *
87 * These terms come directly from the amd64 documentation
88 * (AMD publication #26094). They are defined as follows:
89 *
90 * SysAddr:
91 * This is a physical address generated by a CPU core or a device
92 * doing DMA. If generated by a CPU core, a SysAddr is the result of
93 * a virtual to physical address translation by the CPU core's address
94 * translation mechanism (MMU).
95 *
96 * DramAddr:
97 * A DramAddr is derived from a SysAddr by subtracting an offset that
98 * depends on which node the SysAddr maps to and whether the SysAddr
99 * is within a range affected by memory hoisting. The DRAM Base
100 * (section 3.4.4.1) and DRAM Limit (section 3.4.4.2) registers
101 * determine which node a SysAddr maps to.
102 *
103 * If the DRAM Hole Address Register (DHAR) is enabled and the SysAddr
104 * is within the range of addresses specified by this register, then
105 * a value x from the DHAR is subtracted from the SysAddr to produce a
106 * DramAddr. Here, x represents the base address for the node that
107 * the SysAddr maps to plus an offset due to memory hoisting. See
108 * section 3.4.8 and the comments in amd64_get_dram_hole_info() and
109 * sys_addr_to_dram_addr() below for more information.
110 *
111 * If the SysAddr is not affected by the DHAR then a value y is
112 * subtracted from the SysAddr to produce a DramAddr. Here, y is the
113 * base address for the node that the SysAddr maps to. See section
114 * 3.4.4 and the comments in sys_addr_to_dram_addr() below for more
115 * information.
116 *
117 * InputAddr:
118 * A DramAddr is translated to an InputAddr before being passed to the
119 * memory controller for the node that the DramAddr is associated
120 * with. The memory controller then maps the InputAddr to a csrow.
121 * If node interleaving is not in use, then the InputAddr has the same
122 * value as the DramAddr. Otherwise, the InputAddr is produced by
123 * discarding the bits used for node interleaving from the DramAddr.
124 * See section 3.4.4 for more information.
125 *
126 * The memory controller for a given node uses its DRAM CS Base and
127 * DRAM CS Mask registers to map an InputAddr to a csrow. See
128 * sections 3.5.4 and 3.5.5 for more information.
129 */
130
131#define EDAC_AMD64_VERSION " Ver: 3.2.0 " __DATE__
132#define EDAC_MOD_STR "amd64_edac"
133
134/* Extended Model from CPUID, for CPU Revision numbers */
135#define OPTERON_CPU_LE_REV_C 0
136#define OPTERON_CPU_REV_D 1
137#define OPTERON_CPU_REV_E 2
138
139/* NPT processors have the following Extended Models */
140#define OPTERON_CPU_REV_F 4
141#define OPTERON_CPU_REV_FA 5
142
143/* Hardware limit on ChipSelect rows per MC and processors per system */
144#define CHIPSELECT_COUNT 8
145#define DRAM_REG_COUNT 8
146
147
148/*
149 * PCI-defined configuration space registers
150 */
151
152
153/*
154 * Function 1 - Address Map
155 */
156#define K8_DRAM_BASE_LOW 0x40
157#define K8_DRAM_LIMIT_LOW 0x44
158#define K8_DHAR 0xf0
159
160#define DHAR_VALID BIT(0)
161#define F10_DRAM_MEM_HOIST_VALID BIT(1)
162
163#define DHAR_BASE_MASK 0xff000000
164#define dhar_base(dhar) (dhar & DHAR_BASE_MASK)
165
166#define K8_DHAR_OFFSET_MASK 0x0000ff00
167#define k8_dhar_offset(dhar) ((dhar & K8_DHAR_OFFSET_MASK) << 16)
168
169#define F10_DHAR_OFFSET_MASK 0x0000ff80
170 /* NOTE: Extra mask bit vs K8 */
171#define f10_dhar_offset(dhar) ((dhar & F10_DHAR_OFFSET_MASK) << 16)
172
173
174/* F10 High BASE/LIMIT registers */
175#define F10_DRAM_BASE_HIGH 0x140
176#define F10_DRAM_LIMIT_HIGH 0x144
177
178
179/*
180 * Function 2 - DRAM controller
181 */
182#define K8_DCSB0 0x40
183#define F10_DCSB1 0x140
184
185#define K8_DCSB_CS_ENABLE BIT(0)
186#define K8_DCSB_NPT_SPARE BIT(1)
187#define K8_DCSB_NPT_TESTFAIL BIT(2)
188
189/*
190 * REV E: select [31:21] and [15:9] from DCSB and the shift amount to form
191 * the address
192 */
193#define REV_E_DCSB_BASE_BITS (0xFFE0FE00ULL)
194#define REV_E_DCS_SHIFT 4
195#define REV_E_DCSM_COUNT 8
196
197#define REV_F_F1Xh_DCSB_BASE_BITS (0x1FF83FE0ULL)
198#define REV_F_F1Xh_DCS_SHIFT 8
199
200/*
201 * REV F and later: selects [28:19] and [13:5] from DCSB and the shift amount
202 * to form the address
203 */
204#define REV_F_DCSB_BASE_BITS (0x1FF83FE0ULL)
205#define REV_F_DCS_SHIFT 8
206#define REV_F_DCSM_COUNT 4
207#define F10_DCSM_COUNT 4
208#define F11_DCSM_COUNT 2
209
210/* DRAM CS Mask Registers */
211#define K8_DCSM0 0x60
212#define F10_DCSM1 0x160
213
214/* REV E: select [29:21] and [15:9] from DCSM */
215#define REV_E_DCSM_MASK_BITS 0x3FE0FE00
216
217/* unused bits [24:20] and [12:0] */
218#define REV_E_DCS_NOTUSED_BITS 0x01F01FFF
219
220/* REV F and later: select [28:19] and [13:5] from DCSM */
221#define REV_F_F1Xh_DCSM_MASK_BITS 0x1FF83FE0
222
223/* unused bits [26:22] and [12:0] */
224#define REV_F_F1Xh_DCS_NOTUSED_BITS 0x07C01FFF
225
226#define DBAM0 0x80
227#define DBAM1 0x180
228
229/* Extract the DIMM 'type' on the i'th DIMM from the DBAM reg value passed */
230#define DBAM_DIMM(i, reg) ((((reg) >> (4*i))) & 0xF)
231
232#define DBAM_MAX_VALUE 11
233
234
235#define F10_DCLR_0 0x90
236#define F10_DCLR_1 0x190
237#define REVE_WIDTH_128 BIT(16)
238#define F10_WIDTH_128 BIT(11)
239
240
241#define F10_DCHR_0 0x94
242#define F10_DCHR_1 0x194
243
244#define F10_DCHR_FOUR_RANK_DIMM BIT(18)
245#define F10_DCHR_Ddr3Mode BIT(8)
246#define F10_DCHR_MblMode BIT(6)
247
248
249#define F10_DCTL_SEL_LOW 0x110
250
251#define dct_sel_baseaddr(pvt) \
252 ((pvt->dram_ctl_select_low) & 0xFFFFF800)
253
254#define dct_sel_interleave_addr(pvt) \
255 (((pvt->dram_ctl_select_low) >> 6) & 0x3)
256
257enum {
258 F10_DCTL_SEL_LOW_DctSelHiRngEn = BIT(0),
259 F10_DCTL_SEL_LOW_DctSelIntLvEn = BIT(2),
260 F10_DCTL_SEL_LOW_DctGangEn = BIT(4),
261 F10_DCTL_SEL_LOW_DctDatIntLv = BIT(5),
262 F10_DCTL_SEL_LOW_DramEnable = BIT(8),
263 F10_DCTL_SEL_LOW_MemCleared = BIT(10),
264};
265
266#define dct_high_range_enabled(pvt) \
267 (pvt->dram_ctl_select_low & F10_DCTL_SEL_LOW_DctSelHiRngEn)
268
269#define dct_interleave_enabled(pvt) \
270 (pvt->dram_ctl_select_low & F10_DCTL_SEL_LOW_DctSelIntLvEn)
271
272#define dct_ganging_enabled(pvt) \
273 (pvt->dram_ctl_select_low & F10_DCTL_SEL_LOW_DctGangEn)
274
275#define dct_data_intlv_enabled(pvt) \
276 (pvt->dram_ctl_select_low & F10_DCTL_SEL_LOW_DctDatIntLv)
277
278#define dct_dram_enabled(pvt) \
279 (pvt->dram_ctl_select_low & F10_DCTL_SEL_LOW_DramEnable)
280
281#define dct_memory_cleared(pvt) \
282 (pvt->dram_ctl_select_low & F10_DCTL_SEL_LOW_MemCleared)
283
284
285#define F10_DCTL_SEL_HIGH 0x114
286
287
288/*
289 * Function 3 - Misc Control
290 */
291#define K8_NBCTL 0x40
292
293/* Correctable ECC error reporting enable */
294#define K8_NBCTL_CECCEn BIT(0)
295
296/* UnCorrectable ECC error reporting enable */
297#define K8_NBCTL_UECCEn BIT(1)
298
299#define K8_NBCFG 0x44
300#define K8_NBCFG_CHIPKILL BIT(23)
301#define K8_NBCFG_ECC_ENABLE BIT(22)
302
303#define K8_NBSL 0x48
304
305
306#define EXTRACT_HIGH_SYNDROME(x) (((x) >> 24) & 0xff)
307#define EXTRACT_EXT_ERROR_CODE(x) (((x) >> 16) & 0x1f)
308
309/* Family F10h: Normalized Extended Error Codes */
310#define F10_NBSL_EXT_ERR_RES 0x0
311#define F10_NBSL_EXT_ERR_CRC 0x1
312#define F10_NBSL_EXT_ERR_SYNC 0x2
313#define F10_NBSL_EXT_ERR_MST 0x3
314#define F10_NBSL_EXT_ERR_TGT 0x4
315#define F10_NBSL_EXT_ERR_GART 0x5
316#define F10_NBSL_EXT_ERR_RMW 0x6
317#define F10_NBSL_EXT_ERR_WDT 0x7
318#define F10_NBSL_EXT_ERR_ECC 0x8
319#define F10_NBSL_EXT_ERR_DEV 0x9
320#define F10_NBSL_EXT_ERR_LINK_DATA 0xA
321
322/* Next two are overloaded values */
323#define F10_NBSL_EXT_ERR_LINK_PROTO 0xB
324#define F10_NBSL_EXT_ERR_L3_PROTO 0xB
325
326#define F10_NBSL_EXT_ERR_NB_ARRAY 0xC
327#define F10_NBSL_EXT_ERR_DRAM_PARITY 0xD
328#define F10_NBSL_EXT_ERR_LINK_RETRY 0xE
329
330/* Next two are overloaded values */
331#define F10_NBSL_EXT_ERR_GART_WALK 0xF
332#define F10_NBSL_EXT_ERR_DEV_WALK 0xF
333
334/* 0x10 to 0x1B: Reserved */
335#define F10_NBSL_EXT_ERR_L3_DATA 0x1C
336#define F10_NBSL_EXT_ERR_L3_TAG 0x1D
337#define F10_NBSL_EXT_ERR_L3_LRU 0x1E
338
339/* K8: Normalized Extended Error Codes */
340#define K8_NBSL_EXT_ERR_ECC 0x0
341#define K8_NBSL_EXT_ERR_CRC 0x1
342#define K8_NBSL_EXT_ERR_SYNC 0x2
343#define K8_NBSL_EXT_ERR_MST 0x3
344#define K8_NBSL_EXT_ERR_TGT 0x4
345#define K8_NBSL_EXT_ERR_GART 0x5
346#define K8_NBSL_EXT_ERR_RMW 0x6
347#define K8_NBSL_EXT_ERR_WDT 0x7
348#define K8_NBSL_EXT_ERR_CHIPKILL_ECC 0x8
349#define K8_NBSL_EXT_ERR_DRAM_PARITY 0xD
350
351#define EXTRACT_ERROR_CODE(x) ((x) & 0xffff)
352#define TEST_TLB_ERROR(x) (((x) & 0xFFF0) == 0x0010)
353#define TEST_MEM_ERROR(x) (((x) & 0xFF00) == 0x0100)
354#define TEST_BUS_ERROR(x) (((x) & 0xF800) == 0x0800)
355#define EXTRACT_TT_CODE(x) (((x) >> 2) & 0x3)
356#define EXTRACT_II_CODE(x) (((x) >> 2) & 0x3)
357#define EXTRACT_LL_CODE(x) (((x) >> 0) & 0x3)
358#define EXTRACT_RRRR_CODE(x) (((x) >> 4) & 0xf)
359#define EXTRACT_TO_CODE(x) (((x) >> 8) & 0x1)
360#define EXTRACT_PP_CODE(x) (((x) >> 9) & 0x3)
361
362/*
363 * The following are for BUS type errors AFTER values have been normalized by
364 * shifting right
365 */
366#define K8_NBSL_PP_SRC 0x0
367#define K8_NBSL_PP_RES 0x1
368#define K8_NBSL_PP_OBS 0x2
369#define K8_NBSL_PP_GENERIC 0x3
370
371
372#define K8_NBSH 0x4C
373
374#define K8_NBSH_VALID_BIT BIT(31)
375#define K8_NBSH_OVERFLOW BIT(30)
376#define K8_NBSH_UNCORRECTED_ERR BIT(29)
377#define K8_NBSH_ERR_ENABLE BIT(28)
378#define K8_NBSH_MISC_ERR_VALID BIT(27)
379#define K8_NBSH_VALID_ERROR_ADDR BIT(26)
380#define K8_NBSH_PCC BIT(25)
381#define K8_NBSH_CECC BIT(14)
382#define K8_NBSH_UECC BIT(13)
383#define K8_NBSH_ERR_SCRUBER BIT(8)
384#define K8_NBSH_CORE3 BIT(3)
385#define K8_NBSH_CORE2 BIT(2)
386#define K8_NBSH_CORE1 BIT(1)
387#define K8_NBSH_CORE0 BIT(0)
388
389#define EXTRACT_LDT_LINK(x) (((x) >> 4) & 0x7)
390#define EXTRACT_ERR_CPU_MAP(x) ((x) & 0xF)
391#define EXTRACT_LOW_SYNDROME(x) (((x) >> 15) & 0xff)
392
393
394#define K8_NBEAL 0x50
395#define K8_NBEAH 0x54
396#define K8_SCRCTRL 0x58
397
398#define F10_NB_CFG_LOW 0x88
399#define F10_NB_CFG_LOW_ENABLE_EXT_CFG BIT(14)
400
401#define F10_NB_CFG_HIGH 0x8C
402
403#define F10_ONLINE_SPARE 0xB0
404#define F10_ONLINE_SPARE_SWAPDONE0(x) ((x) & BIT(1))
405#define F10_ONLINE_SPARE_SWAPDONE1(x) ((x) & BIT(3))
406#define F10_ONLINE_SPARE_BADDRAM_CS0(x) (((x) >> 4) & 0x00000007)
407#define F10_ONLINE_SPARE_BADDRAM_CS1(x) (((x) >> 8) & 0x00000007)
408
409#define F10_NB_ARRAY_ADDR 0xB8
410
411#define F10_NB_ARRAY_DRAM_ECC 0x80000000
412
413/* Bits [2:1] are used to select 16-byte section within a 64-byte cacheline */
414#define SET_NB_ARRAY_ADDRESS(section) (((section) & 0x3) << 1)
415
416#define F10_NB_ARRAY_DATA 0xBC
417
418#define SET_NB_DRAM_INJECTION_WRITE(word, bits) \
419 (BIT(((word) & 0xF) + 20) | \
420 BIT(17) | \
421 ((bits) & 0xF))
422
423#define SET_NB_DRAM_INJECTION_READ(word, bits) \
424 (BIT(((word) & 0xF) + 20) | \
425 BIT(16) | \
426 ((bits) & 0xF))
427
428#define K8_NBCAP 0xE8
429#define K8_NBCAP_CORES (BIT(12)|BIT(13))
430#define K8_NBCAP_CHIPKILL BIT(4)
431#define K8_NBCAP_SECDED BIT(3)
432#define K8_NBCAP_8_NODE BIT(2)
433#define K8_NBCAP_DUAL_NODE BIT(1)
434#define K8_NBCAP_DCT_DUAL BIT(0)
435
436/*
437 * MSR Regs
438 */
439#define K8_MSR_MCGCTL 0x017b
440#define K8_MSR_MCGCTL_NBE BIT(4)
441
442#define K8_MSR_MC4CTL 0x0410
443#define K8_MSR_MC4STAT 0x0411
444#define K8_MSR_MC4ADDR 0x0412
445
446/* AMD sets the first MC device at device ID 0x18. */
447static inline int get_mc_node_id_from_pdev(struct pci_dev *pdev)
448{
449 return PCI_SLOT(pdev->devfn) - 0x18;
450}
451
452enum amd64_chipset_families {
453 K8_CPUS = 0,
454 F10_CPUS,
455 F11_CPUS,
456};
457
458/*
459 * Structure to hold:
460 *
461 * 1) dynamically read status and error address HW registers
462 * 2) sysfs entered values
463 * 3) MCE values
464 *
465 * Depends on entry into the modules
466 */
467struct amd64_error_info_regs {
468 u32 nbcfg;
469 u32 nbsh;
470 u32 nbsl;
471 u32 nbeah;
472 u32 nbeal;
473};
474
475/* Error injection control structure */
476struct error_injection {
477 u32 section;
478 u32 word;
479 u32 bit_map;
480};
481
482struct amd64_pvt {
483 /* pci_device handles which we utilize */
484 struct pci_dev *addr_f1_ctl;
485 struct pci_dev *dram_f2_ctl;
486 struct pci_dev *misc_f3_ctl;
487
488 int mc_node_id; /* MC index of this MC node */
489 int ext_model; /* extended model value of this node */
490
491 struct low_ops *ops; /* pointer to per PCI Device ID func table */
492
493 int channel_count;
494
495 /* Raw registers */
496 u32 dclr0; /* DRAM Configuration Low DCT0 reg */
497 u32 dclr1; /* DRAM Configuration Low DCT1 reg */
498 u32 dchr0; /* DRAM Configuration High DCT0 reg */
499 u32 dchr1; /* DRAM Configuration High DCT1 reg */
500 u32 nbcap; /* North Bridge Capabilities */
501 u32 nbcfg; /* F10 North Bridge Configuration */
502 u32 ext_nbcfg; /* Extended F10 North Bridge Configuration */
503 u32 dhar; /* DRAM Hoist reg */
504 u32 dbam0; /* DRAM Base Address Mapping reg for DCT0 */
505 u32 dbam1; /* DRAM Base Address Mapping reg for DCT1 */
506
507 /* DRAM CS Base Address Registers F2x[1,0][5C:40] */
508 u32 dcsb0[CHIPSELECT_COUNT];
509 u32 dcsb1[CHIPSELECT_COUNT];
510
511 /* DRAM CS Mask Registers F2x[1,0][6C:60] */
512 u32 dcsm0[CHIPSELECT_COUNT];
513 u32 dcsm1[CHIPSELECT_COUNT];
514
515 /*
516 * Decoded parts of DRAM BASE and LIMIT Registers
517 * F1x[78,70,68,60,58,50,48,40]
518 */
519 u64 dram_base[DRAM_REG_COUNT];
520 u64 dram_limit[DRAM_REG_COUNT];
521 u8 dram_IntlvSel[DRAM_REG_COUNT];
522 u8 dram_IntlvEn[DRAM_REG_COUNT];
523 u8 dram_DstNode[DRAM_REG_COUNT];
524 u8 dram_rw_en[DRAM_REG_COUNT];
525
526 /*
527 * The following fields are set at (load) run time, after CPU revision
528 * has been determined, since the dct_base and dct_mask registers vary
529 * based on revision
530 */
531 u32 dcsb_base; /* DCSB base bits */
532 u32 dcsm_mask; /* DCSM mask bits */
533 u32 num_dcsm; /* Number of DCSM registers */
534 u32 dcs_mask_notused; /* DCSM notused mask bits */
535 u32 dcs_shift; /* DCSB and DCSM shift value */
536
537 u64 top_mem; /* top of memory below 4GB */
538 u64 top_mem2; /* top of memory above 4GB */
539
540 u32 dram_ctl_select_low; /* DRAM Controller Select Low Reg */
541 u32 dram_ctl_select_high; /* DRAM Controller Select High Reg */
542 u32 online_spare; /* On-Line spare Reg */
543
544 /* temp storage for when input is received from sysfs */
545 struct amd64_error_info_regs ctl_error_info;
546
547 /* place to store error injection parameters prior to issue */
548 struct error_injection injection;
549
550 /* Save old hw registers' values before we modified them */
551 u32 nbctl_mcgctl_saved; /* When true, following 2 are valid */
552 u32 old_nbctl;
553 unsigned long old_mcgctl; /* per core on this node */
554
555 /* MC Type Index value: socket F vs Family 10h */
556 u32 mc_type_index;
557
558 /* misc settings */
559 struct flags {
560 unsigned long cf8_extcfg:1;
561 } flags;
562};
563
564struct scrubrate {
565 u32 scrubval; /* bit pattern for scrub rate */
566 u32 bandwidth; /* bandwidth consumed (bytes/sec) */
567};
568
569extern struct scrubrate scrubrates[23];
570extern u32 revf_quad_ddr2_shift[16];
571extern const char *tt_msgs[4];
572extern const char *ll_msgs[4];
573extern const char *rrrr_msgs[16];
574extern const char *to_msgs[2];
575extern const char *pp_msgs[4];
576extern const char *ii_msgs[4];
577extern const char *ext_msgs[32];
578extern const char *htlink_msgs[8];
579
580#ifdef CONFIG_EDAC_DEBUG
581#define NUM_DBG_ATTRS 9
582#else
583#define NUM_DBG_ATTRS 0
584#endif
585
586#ifdef CONFIG_EDAC_AMD64_ERROR_INJECTION
587#define NUM_INJ_ATTRS 5
588#else
589#define NUM_INJ_ATTRS 0
590#endif
591
592extern struct mcidev_sysfs_attribute amd64_dbg_attrs[NUM_DBG_ATTRS],
593 amd64_inj_attrs[NUM_INJ_ATTRS];
594
595/*
596 * Each of the PCI Device IDs types have their own set of hardware accessor
597 * functions and per device encoding/decoding logic.
598 */
599struct low_ops {
600 int (*probe_valid_hardware)(struct amd64_pvt *pvt);
601 int (*early_channel_count)(struct amd64_pvt *pvt);
602
603 u64 (*get_error_address)(struct mem_ctl_info *mci,
604 struct amd64_error_info_regs *info);
605 void (*read_dram_base_limit)(struct amd64_pvt *pvt, int dram);
606 void (*read_dram_ctl_register)(struct amd64_pvt *pvt);
607 void (*map_sysaddr_to_csrow)(struct mem_ctl_info *mci,
608 struct amd64_error_info_regs *info,
609 u64 SystemAddr);
610 int (*dbam_map_to_pages)(struct amd64_pvt *pvt, int dram_map);
611};
612
613struct amd64_family_type {
614 const char *ctl_name;
615 u16 addr_f1_ctl;
616 u16 misc_f3_ctl;
617 struct low_ops ops;
618};
619
620static struct amd64_family_type amd64_family_types[];
621
622static inline const char *get_amd_family_name(int index)
623{
624 return amd64_family_types[index].ctl_name;
625}
626
627static inline struct low_ops *family_ops(int index)
628{
629 return &amd64_family_types[index].ops;
630}
631
632/*
633 * For future CPU versions, verify the following as new 'slow' rates appear and
634 * modify the necessary skip values for the supported CPU.
635 */
636#define K8_MIN_SCRUB_RATE_BITS 0x0
637#define F10_MIN_SCRUB_RATE_BITS 0x5
638#define F11_MIN_SCRUB_RATE_BITS 0x6
639
640int amd64_process_error_info(struct mem_ctl_info *mci,
641 struct amd64_error_info_regs *info,
642 int handle_errors);
643int amd64_get_dram_hole_info(struct mem_ctl_info *mci, u64 *hole_base,
644 u64 *hole_offset, u64 *hole_size);
diff --git a/drivers/edac/amd64_edac_dbg.c b/drivers/edac/amd64_edac_dbg.c
new file mode 100644
index 000000000000..0a41b248a4ad
--- /dev/null
+++ b/drivers/edac/amd64_edac_dbg.c
@@ -0,0 +1,255 @@
1#include "amd64_edac.h"
2
3/*
4 * accept a hex value and store it into the virtual error register file, field:
5 * nbeal and nbeah. Assume virtual error values have already been set for: NBSL,
6 * NBSH and NBCFG. Then proceed to map the error values to a MC, CSROW and
7 * CHANNEL
8 */
9static ssize_t amd64_nbea_store(struct mem_ctl_info *mci, const char *data,
10 size_t count)
11{
12 struct amd64_pvt *pvt = mci->pvt_info;
13 unsigned long long value;
14 int ret = 0;
15
16 ret = strict_strtoull(data, 16, &value);
17 if (ret != -EINVAL) {
18 debugf0("received NBEA= 0x%llx\n", value);
19
20 /* place the value into the virtual error packet */
21 pvt->ctl_error_info.nbeal = (u32) value;
22 value >>= 32;
23 pvt->ctl_error_info.nbeah = (u32) value;
24
25 /* Process the Mapping request */
26 /* TODO: Add race prevention */
27 amd64_process_error_info(mci, &pvt->ctl_error_info, 1);
28
29 return count;
30 }
31 return ret;
32}
33
34/* display back what the last NBEA (MCA NB Address (MC4_ADDR)) was written */
35static ssize_t amd64_nbea_show(struct mem_ctl_info *mci, char *data)
36{
37 struct amd64_pvt *pvt = mci->pvt_info;
38 u64 value;
39
40 value = pvt->ctl_error_info.nbeah;
41 value <<= 32;
42 value |= pvt->ctl_error_info.nbeal;
43
44 return sprintf(data, "%llx\n", value);
45}
46
47/* store the NBSL (MCA NB Status Low (MC4_STATUS)) value user desires */
48static ssize_t amd64_nbsl_store(struct mem_ctl_info *mci, const char *data,
49 size_t count)
50{
51 struct amd64_pvt *pvt = mci->pvt_info;
52 unsigned long value;
53 int ret = 0;
54
55 ret = strict_strtoul(data, 16, &value);
56 if (ret != -EINVAL) {
57 debugf0("received NBSL= 0x%lx\n", value);
58
59 pvt->ctl_error_info.nbsl = (u32) value;
60
61 return count;
62 }
63 return ret;
64}
65
66/* display back what the last NBSL value written */
67static ssize_t amd64_nbsl_show(struct mem_ctl_info *mci, char *data)
68{
69 struct amd64_pvt *pvt = mci->pvt_info;
70 u32 value;
71
72 value = pvt->ctl_error_info.nbsl;
73
74 return sprintf(data, "%x\n", value);
75}
76
77/* store the NBSH (MCA NB Status High) value user desires */
78static ssize_t amd64_nbsh_store(struct mem_ctl_info *mci, const char *data,
79 size_t count)
80{
81 struct amd64_pvt *pvt = mci->pvt_info;
82 unsigned long value;
83 int ret = 0;
84
85 ret = strict_strtoul(data, 16, &value);
86 if (ret != -EINVAL) {
87 debugf0("received NBSH= 0x%lx\n", value);
88
89 pvt->ctl_error_info.nbsh = (u32) value;
90
91 return count;
92 }
93 return ret;
94}
95
96/* display back what the last NBSH value written */
97static ssize_t amd64_nbsh_show(struct mem_ctl_info *mci, char *data)
98{
99 struct amd64_pvt *pvt = mci->pvt_info;
100 u32 value;
101
102 value = pvt->ctl_error_info.nbsh;
103
104 return sprintf(data, "%x\n", value);
105}
106
107/* accept and store the NBCFG (MCA NB Configuration) value user desires */
108static ssize_t amd64_nbcfg_store(struct mem_ctl_info *mci,
109 const char *data, size_t count)
110{
111 struct amd64_pvt *pvt = mci->pvt_info;
112 unsigned long value;
113 int ret = 0;
114
115 ret = strict_strtoul(data, 16, &value);
116 if (ret != -EINVAL) {
117 debugf0("received NBCFG= 0x%lx\n", value);
118
119 pvt->ctl_error_info.nbcfg = (u32) value;
120
121 return count;
122 }
123 return ret;
124}
125
126/* various show routines for the controls of a MCI */
127static ssize_t amd64_nbcfg_show(struct mem_ctl_info *mci, char *data)
128{
129 struct amd64_pvt *pvt = mci->pvt_info;
130
131 return sprintf(data, "%x\n", pvt->ctl_error_info.nbcfg);
132}
133
134
135static ssize_t amd64_dhar_show(struct mem_ctl_info *mci, char *data)
136{
137 struct amd64_pvt *pvt = mci->pvt_info;
138
139 return sprintf(data, "%x\n", pvt->dhar);
140}
141
142
143static ssize_t amd64_dbam_show(struct mem_ctl_info *mci, char *data)
144{
145 struct amd64_pvt *pvt = mci->pvt_info;
146
147 return sprintf(data, "%x\n", pvt->dbam0);
148}
149
150
151static ssize_t amd64_topmem_show(struct mem_ctl_info *mci, char *data)
152{
153 struct amd64_pvt *pvt = mci->pvt_info;
154
155 return sprintf(data, "%llx\n", pvt->top_mem);
156}
157
158
159static ssize_t amd64_topmem2_show(struct mem_ctl_info *mci, char *data)
160{
161 struct amd64_pvt *pvt = mci->pvt_info;
162
163 return sprintf(data, "%llx\n", pvt->top_mem2);
164}
165
166static ssize_t amd64_hole_show(struct mem_ctl_info *mci, char *data)
167{
168 u64 hole_base = 0;
169 u64 hole_offset = 0;
170 u64 hole_size = 0;
171
172 amd64_get_dram_hole_info(mci, &hole_base, &hole_offset, &hole_size);
173
174 return sprintf(data, "%llx %llx %llx\n", hole_base, hole_offset,
175 hole_size);
176}
177
178/*
179 * update NUM_DBG_ATTRS in case you add new members
180 */
181struct mcidev_sysfs_attribute amd64_dbg_attrs[] = {
182
183 {
184 .attr = {
185 .name = "nbea_ctl",
186 .mode = (S_IRUGO | S_IWUSR)
187 },
188 .show = amd64_nbea_show,
189 .store = amd64_nbea_store,
190 },
191 {
192 .attr = {
193 .name = "nbsl_ctl",
194 .mode = (S_IRUGO | S_IWUSR)
195 },
196 .show = amd64_nbsl_show,
197 .store = amd64_nbsl_store,
198 },
199 {
200 .attr = {
201 .name = "nbsh_ctl",
202 .mode = (S_IRUGO | S_IWUSR)
203 },
204 .show = amd64_nbsh_show,
205 .store = amd64_nbsh_store,
206 },
207 {
208 .attr = {
209 .name = "nbcfg_ctl",
210 .mode = (S_IRUGO | S_IWUSR)
211 },
212 .show = amd64_nbcfg_show,
213 .store = amd64_nbcfg_store,
214 },
215 {
216 .attr = {
217 .name = "dhar",
218 .mode = (S_IRUGO)
219 },
220 .show = amd64_dhar_show,
221 .store = NULL,
222 },
223 {
224 .attr = {
225 .name = "dbam",
226 .mode = (S_IRUGO)
227 },
228 .show = amd64_dbam_show,
229 .store = NULL,
230 },
231 {
232 .attr = {
233 .name = "topmem",
234 .mode = (S_IRUGO)
235 },
236 .show = amd64_topmem_show,
237 .store = NULL,
238 },
239 {
240 .attr = {
241 .name = "topmem2",
242 .mode = (S_IRUGO)
243 },
244 .show = amd64_topmem2_show,
245 .store = NULL,
246 },
247 {
248 .attr = {
249 .name = "dram_hole",
250 .mode = (S_IRUGO)
251 },
252 .show = amd64_hole_show,
253 .store = NULL,
254 },
255};
diff --git a/drivers/edac/amd64_edac_err_types.c b/drivers/edac/amd64_edac_err_types.c
new file mode 100644
index 000000000000..f212ff12a9d8
--- /dev/null
+++ b/drivers/edac/amd64_edac_err_types.c
@@ -0,0 +1,161 @@
1#include "amd64_edac.h"
2
3/*
4 * See F2x80 for K8 and F2x[1,0]80 for Fam10 and later. The table below is only
5 * for DDR2 DRAM mapping.
6 */
7u32 revf_quad_ddr2_shift[] = {
8 0, /* 0000b NULL DIMM (128mb) */
9 28, /* 0001b 256mb */
10 29, /* 0010b 512mb */
11 29, /* 0011b 512mb */
12 29, /* 0100b 512mb */
13 30, /* 0101b 1gb */
14 30, /* 0110b 1gb */
15 31, /* 0111b 2gb */
16 31, /* 1000b 2gb */
17 32, /* 1001b 4gb */
18 32, /* 1010b 4gb */
19 33, /* 1011b 8gb */
20 0, /* 1100b future */
21 0, /* 1101b future */
22 0, /* 1110b future */
23 0 /* 1111b future */
24};
25
26/*
27 * Valid scrub rates for the K8 hardware memory scrubber. We map the scrubbing
28 * bandwidth to a valid bit pattern. The 'set' operation finds the 'matching-
29 * or higher value'.
30 *
31 *FIXME: Produce a better mapping/linearisation.
32 */
33
34struct scrubrate scrubrates[] = {
35 { 0x01, 1600000000UL},
36 { 0x02, 800000000UL},
37 { 0x03, 400000000UL},
38 { 0x04, 200000000UL},
39 { 0x05, 100000000UL},
40 { 0x06, 50000000UL},
41 { 0x07, 25000000UL},
42 { 0x08, 12284069UL},
43 { 0x09, 6274509UL},
44 { 0x0A, 3121951UL},
45 { 0x0B, 1560975UL},
46 { 0x0C, 781440UL},
47 { 0x0D, 390720UL},
48 { 0x0E, 195300UL},
49 { 0x0F, 97650UL},
50 { 0x10, 48854UL},
51 { 0x11, 24427UL},
52 { 0x12, 12213UL},
53 { 0x13, 6101UL},
54 { 0x14, 3051UL},
55 { 0x15, 1523UL},
56 { 0x16, 761UL},
57 { 0x00, 0UL}, /* scrubbing off */
58};
59
60/*
61 * string representation for the different MCA reported error types, see F3x48
62 * or MSR0000_0411.
63 */
64const char *tt_msgs[] = { /* transaction type */
65 "instruction",
66 "data",
67 "generic",
68 "reserved"
69};
70
71const char *ll_msgs[] = { /* cache level */
72 "L0",
73 "L1",
74 "L2",
75 "L3/generic"
76};
77
78const char *rrrr_msgs[] = {
79 "generic",
80 "generic read",
81 "generic write",
82 "data read",
83 "data write",
84 "inst fetch",
85 "prefetch",
86 "evict",
87 "snoop",
88 "reserved RRRR= 9",
89 "reserved RRRR= 10",
90 "reserved RRRR= 11",
91 "reserved RRRR= 12",
92 "reserved RRRR= 13",
93 "reserved RRRR= 14",
94 "reserved RRRR= 15"
95};
96
97const char *pp_msgs[] = { /* participating processor */
98 "local node originated (SRC)",
99 "local node responded to request (RES)",
100 "local node observed as 3rd party (OBS)",
101 "generic"
102};
103
104const char *to_msgs[] = {
105 "no timeout",
106 "timed out"
107};
108
109const char *ii_msgs[] = { /* memory or i/o */
110 "mem access",
111 "reserved",
112 "i/o access",
113 "generic"
114};
115
116/* Map the 5 bits of Extended Error code to the string table. */
117const char *ext_msgs[] = { /* extended error */
118 "K8 ECC error/F10 reserved", /* 0_0000b */
119 "CRC error", /* 0_0001b */
120 "sync error", /* 0_0010b */
121 "mst abort", /* 0_0011b */
122 "tgt abort", /* 0_0100b */
123 "GART error", /* 0_0101b */
124 "RMW error", /* 0_0110b */
125 "Wdog timer error", /* 0_0111b */
126 "F10-ECC/K8-Chipkill error", /* 0_1000b */
127 "DEV Error", /* 0_1001b */
128 "Link Data error", /* 0_1010b */
129 "Link or L3 Protocol error", /* 0_1011b */
130 "NB Array error", /* 0_1100b */
131 "DRAM Parity error", /* 0_1101b */
132 "Link Retry/GART Table Walk/DEV Table Walk error", /* 0_1110b */
133 "Res 0x0ff error", /* 0_1111b */
134 "Res 0x100 error", /* 1_0000b */
135 "Res 0x101 error", /* 1_0001b */
136 "Res 0x102 error", /* 1_0010b */
137 "Res 0x103 error", /* 1_0011b */
138 "Res 0x104 error", /* 1_0100b */
139 "Res 0x105 error", /* 1_0101b */
140 "Res 0x106 error", /* 1_0110b */
141 "Res 0x107 error", /* 1_0111b */
142 "Res 0x108 error", /* 1_1000b */
143 "Res 0x109 error", /* 1_1001b */
144 "Res 0x10A error", /* 1_1010b */
145 "Res 0x10B error", /* 1_1011b */
146 "L3 Cache Data error", /* 1_1100b */
147 "L3 CacheTag error", /* 1_1101b */
148 "L3 Cache LRU error", /* 1_1110b */
149 "Res 0x1FF error" /* 1_1111b */
150};
151
152const char *htlink_msgs[] = {
153 "none",
154 "1",
155 "2",
156 "1 2",
157 "3",
158 "1 3",
159 "2 3",
160 "1 2 3"
161};
diff --git a/drivers/edac/amd64_edac_inj.c b/drivers/edac/amd64_edac_inj.c
new file mode 100644
index 000000000000..d3675b76b3a7
--- /dev/null
+++ b/drivers/edac/amd64_edac_inj.c
@@ -0,0 +1,185 @@
1#include "amd64_edac.h"
2
3/*
4 * store error injection section value which refers to one of 4 16-byte sections
5 * within a 64-byte cacheline
6 *
7 * range: 0..3
8 */
9static ssize_t amd64_inject_section_store(struct mem_ctl_info *mci,
10 const char *data, size_t count)
11{
12 struct amd64_pvt *pvt = mci->pvt_info;
13 unsigned long value;
14 int ret = 0;
15
16 ret = strict_strtoul(data, 10, &value);
17 if (ret != -EINVAL) {
18 pvt->injection.section = (u32) value;
19 return count;
20 }
21 return ret;
22}
23
24/*
25 * store error injection word value which refers to one of 9 16-bit word of the
26 * 16-byte (128-bit + ECC bits) section
27 *
28 * range: 0..8
29 */
30static ssize_t amd64_inject_word_store(struct mem_ctl_info *mci,
31 const char *data, size_t count)
32{
33 struct amd64_pvt *pvt = mci->pvt_info;
34 unsigned long value;
35 int ret = 0;
36
37 ret = strict_strtoul(data, 10, &value);
38 if (ret != -EINVAL) {
39
40 value = (value <= 8) ? value : 0;
41 pvt->injection.word = (u32) value;
42
43 return count;
44 }
45 return ret;
46}
47
48/*
49 * store 16 bit error injection vector which enables injecting errors to the
50 * corresponding bit within the error injection word above. When used during a
51 * DRAM ECC read, it holds the contents of the of the DRAM ECC bits.
52 */
53static ssize_t amd64_inject_ecc_vector_store(struct mem_ctl_info *mci,
54 const char *data, size_t count)
55{
56 struct amd64_pvt *pvt = mci->pvt_info;
57 unsigned long value;
58 int ret = 0;
59
60 ret = strict_strtoul(data, 16, &value);
61 if (ret != -EINVAL) {
62
63 pvt->injection.bit_map = (u32) value & 0xFFFF;
64
65 return count;
66 }
67 return ret;
68}
69
70/*
71 * Do a DRAM ECC read. Assemble staged values in the pvt area, format into
72 * fields needed by the injection registers and read the NB Array Data Port.
73 */
74static ssize_t amd64_inject_read_store(struct mem_ctl_info *mci,
75 const char *data, size_t count)
76{
77 struct amd64_pvt *pvt = mci->pvt_info;
78 unsigned long value;
79 u32 section, word_bits;
80 int ret = 0;
81
82 ret = strict_strtoul(data, 10, &value);
83 if (ret != -EINVAL) {
84
85 /* Form value to choose 16-byte section of cacheline */
86 section = F10_NB_ARRAY_DRAM_ECC |
87 SET_NB_ARRAY_ADDRESS(pvt->injection.section);
88 pci_write_config_dword(pvt->misc_f3_ctl,
89 F10_NB_ARRAY_ADDR, section);
90
91 word_bits = SET_NB_DRAM_INJECTION_READ(pvt->injection.word,
92 pvt->injection.bit_map);
93
94 /* Issue 'word' and 'bit' along with the READ request */
95 pci_write_config_dword(pvt->misc_f3_ctl,
96 F10_NB_ARRAY_DATA, word_bits);
97
98 debugf0("section=0x%x word_bits=0x%x\n", section, word_bits);
99
100 return count;
101 }
102 return ret;
103}
104
105/*
106 * Do a DRAM ECC write. Assemble staged values in the pvt area and format into
107 * fields needed by the injection registers.
108 */
109static ssize_t amd64_inject_write_store(struct mem_ctl_info *mci,
110 const char *data, size_t count)
111{
112 struct amd64_pvt *pvt = mci->pvt_info;
113 unsigned long value;
114 u32 section, word_bits;
115 int ret = 0;
116
117 ret = strict_strtoul(data, 10, &value);
118 if (ret != -EINVAL) {
119
120 /* Form value to choose 16-byte section of cacheline */
121 section = F10_NB_ARRAY_DRAM_ECC |
122 SET_NB_ARRAY_ADDRESS(pvt->injection.section);
123 pci_write_config_dword(pvt->misc_f3_ctl,
124 F10_NB_ARRAY_ADDR, section);
125
126 word_bits = SET_NB_DRAM_INJECTION_WRITE(pvt->injection.word,
127 pvt->injection.bit_map);
128
129 /* Issue 'word' and 'bit' along with the READ request */
130 pci_write_config_dword(pvt->misc_f3_ctl,
131 F10_NB_ARRAY_DATA, word_bits);
132
133 debugf0("section=0x%x word_bits=0x%x\n", section, word_bits);
134
135 return count;
136 }
137 return ret;
138}
139
140/*
141 * update NUM_INJ_ATTRS in case you add new members
142 */
143struct mcidev_sysfs_attribute amd64_inj_attrs[] = {
144
145 {
146 .attr = {
147 .name = "inject_section",
148 .mode = (S_IRUGO | S_IWUSR)
149 },
150 .show = NULL,
151 .store = amd64_inject_section_store,
152 },
153 {
154 .attr = {
155 .name = "inject_word",
156 .mode = (S_IRUGO | S_IWUSR)
157 },
158 .show = NULL,
159 .store = amd64_inject_word_store,
160 },
161 {
162 .attr = {
163 .name = "inject_ecc_vector",
164 .mode = (S_IRUGO | S_IWUSR)
165 },
166 .show = NULL,
167 .store = amd64_inject_ecc_vector_store,
168 },
169 {
170 .attr = {
171 .name = "inject_write",
172 .mode = (S_IRUGO | S_IWUSR)
173 },
174 .show = NULL,
175 .store = amd64_inject_write_store,
176 },
177 {
178 .attr = {
179 .name = "inject_read",
180 .mode = (S_IRUGO | S_IWUSR)
181 },
182 .show = NULL,
183 .store = amd64_inject_read_store,
184 },
185};
diff --git a/drivers/edac/edac_core.h b/drivers/edac/edac_core.h
index 6ad95c8d6363..48d3b1409834 100644
--- a/drivers/edac/edac_core.h
+++ b/drivers/edac/edac_core.h
@@ -76,10 +76,11 @@
76extern int edac_debug_level; 76extern int edac_debug_level;
77 77
78#ifndef CONFIG_EDAC_DEBUG_VERBOSE 78#ifndef CONFIG_EDAC_DEBUG_VERBOSE
79#define edac_debug_printk(level, fmt, arg...) \ 79#define edac_debug_printk(level, fmt, arg...) \
80 do { \ 80 do { \
81 if (level <= edac_debug_level) \ 81 if (level <= edac_debug_level) \
82 edac_printk(KERN_DEBUG, EDAC_DEBUG, fmt, ##arg); \ 82 edac_printk(KERN_DEBUG, EDAC_DEBUG, \
83 "%s: " fmt, __func__, ##arg); \
83 } while (0) 84 } while (0)
84#else /* CONFIG_EDAC_DEBUG_VERBOSE */ 85#else /* CONFIG_EDAC_DEBUG_VERBOSE */
85#define edac_debug_printk(level, fmt, arg...) \ 86#define edac_debug_printk(level, fmt, arg...) \
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index 5f1b5400d96a..24c84ae81527 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -596,6 +596,7 @@ int dmi_get_year(int field)
596 596
597 return year; 597 return year;
598} 598}
599EXPORT_SYMBOL(dmi_get_year);
599 600
600/** 601/**
601 * dmi_walk - Walk the DMI table and get called back for every record 602 * dmi_walk - Walk the DMI table and get called back for every record
diff --git a/drivers/i2c/busses/i2c-sh7760.c b/drivers/i2c/busses/i2c-sh7760.c
index baa28b73ae42..b9680f50f541 100644
--- a/drivers/i2c/busses/i2c-sh7760.c
+++ b/drivers/i2c/busses/i2c-sh7760.c
@@ -396,7 +396,7 @@ static int __devinit calc_CCR(unsigned long scl_hz)
396 signed char cdf, cdfm; 396 signed char cdf, cdfm;
397 int scgd, scgdm, scgds; 397 int scgd, scgdm, scgds;
398 398
399 mclk = clk_get(NULL, "module_clk"); 399 mclk = clk_get(NULL, "peripheral_clk");
400 if (IS_ERR(mclk)) { 400 if (IS_ERR(mclk)) {
401 return PTR_ERR(mclk); 401 return PTR_ERR(mclk);
402 } else { 402 } else {
diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
index 537da1cde16d..e59b6dee9ae2 100644
--- a/drivers/ide/alim15x3.c
+++ b/drivers/ide/alim15x3.c
@@ -402,27 +402,23 @@ static u8 ali_cable_detect(ide_hwif_t *hwif)
402 return cbl; 402 return cbl;
403} 403}
404 404
405#if !defined(CONFIG_SPARC64) && !defined(CONFIG_PPC) 405#ifndef CONFIG_SPARC64
406/** 406/**
407 * init_hwif_ali15x3 - Initialize the ALI IDE x86 stuff 407 * init_hwif_ali15x3 - Initialize the ALI IDE x86 stuff
408 * @hwif: interface to configure 408 * @hwif: interface to configure
409 * 409 *
410 * Obtain the IRQ tables for an ALi based IDE solution on the PC 410 * Obtain the IRQ tables for an ALi based IDE solution on the PC
411 * class platforms. This part of the code isn't applicable to the 411 * class platforms. This part of the code isn't applicable to the
412 * Sparc and PowerPC systems. 412 * Sparc systems.
413 */ 413 */
414 414
415static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif) 415static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif)
416{ 416{
417 struct pci_dev *dev = to_pci_dev(hwif->dev);
418 u8 ideic, inmir; 417 u8 ideic, inmir;
419 s8 irq_routing_table[] = { -1, 9, 3, 10, 4, 5, 7, 6, 418 s8 irq_routing_table[] = { -1, 9, 3, 10, 4, 5, 7, 6,
420 1, 11, 0, 12, 0, 14, 0, 15 }; 419 1, 11, 0, 12, 0, 14, 0, 15 };
421 int irq = -1; 420 int irq = -1;
422 421
423 if (dev->device == PCI_DEVICE_ID_AL_M5229)
424 hwif->irq = hwif->channel ? 15 : 14;
425
426 if (isa_dev) { 422 if (isa_dev) {
427 /* 423 /*
428 * read IDE interface control 424 * read IDE interface control
@@ -455,7 +451,7 @@ static void __devinit init_hwif_ali15x3 (ide_hwif_t *hwif)
455} 451}
456#else 452#else
457#define init_hwif_ali15x3 NULL 453#define init_hwif_ali15x3 NULL
458#endif /* !defined(CONFIG_SPARC64) && !defined(CONFIG_PPC) */ 454#endif /* CONFIG_SPARC64 */
459 455
460/** 456/**
461 * init_dma_ali15x3 - set up DMA on ALi15x3 457 * init_dma_ali15x3 - set up DMA on ALi15x3
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index 7201b176d75b..757e5956b132 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -80,34 +80,6 @@ void ide_init_pc(struct ide_atapi_pc *pc)
80EXPORT_SYMBOL_GPL(ide_init_pc); 80EXPORT_SYMBOL_GPL(ide_init_pc);
81 81
82/* 82/*
83 * Generate a new packet command request in front of the request queue, before
84 * the current request, so that it will be processed immediately, on the next
85 * pass through the driver.
86 */
87static void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
88 struct ide_atapi_pc *pc, struct request *rq)
89{
90 blk_rq_init(NULL, rq);
91 rq->cmd_type = REQ_TYPE_SPECIAL;
92 rq->cmd_flags |= REQ_PREEMPT;
93 rq->buffer = (char *)pc;
94 rq->rq_disk = disk;
95
96 if (pc->req_xfer) {
97 rq->data = pc->buf;
98 rq->data_len = pc->req_xfer;
99 }
100
101 memcpy(rq->cmd, pc->c, 12);
102 if (drive->media == ide_tape)
103 rq->cmd[13] = REQ_IDETAPE_PC1;
104
105 drive->hwif->rq = NULL;
106
107 elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 0);
108}
109
110/*
111 * Add a special packet command request to the tail of the request queue, 83 * Add a special packet command request to the tail of the request queue,
112 * and wait for it to be serviced. 84 * and wait for it to be serviced.
113 */ 85 */
@@ -119,19 +91,21 @@ int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk,
119 91
120 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 92 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
121 rq->cmd_type = REQ_TYPE_SPECIAL; 93 rq->cmd_type = REQ_TYPE_SPECIAL;
122 rq->buffer = (char *)pc; 94 rq->special = (char *)pc;
123 95
124 if (pc->req_xfer) { 96 if (pc->req_xfer) {
125 rq->data = pc->buf; 97 error = blk_rq_map_kern(drive->queue, rq, pc->buf, pc->req_xfer,
126 rq->data_len = pc->req_xfer; 98 GFP_NOIO);
99 if (error)
100 goto put_req;
127 } 101 }
128 102
129 memcpy(rq->cmd, pc->c, 12); 103 memcpy(rq->cmd, pc->c, 12);
130 if (drive->media == ide_tape) 104 if (drive->media == ide_tape)
131 rq->cmd[13] = REQ_IDETAPE_PC1; 105 rq->cmd[13] = REQ_IDETAPE_PC1;
132 error = blk_execute_rq(drive->queue, disk, rq, 0); 106 error = blk_execute_rq(drive->queue, disk, rq, 0);
107put_req:
133 blk_put_request(rq); 108 blk_put_request(rq);
134
135 return error; 109 return error;
136} 110}
137EXPORT_SYMBOL_GPL(ide_queue_pc_tail); 111EXPORT_SYMBOL_GPL(ide_queue_pc_tail);
@@ -191,20 +165,113 @@ void ide_create_request_sense_cmd(ide_drive_t *drive, struct ide_atapi_pc *pc)
191} 165}
192EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd); 166EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd);
193 167
168void ide_prep_sense(ide_drive_t *drive, struct request *rq)
169{
170 struct request_sense *sense = &drive->sense_data;
171 struct request *sense_rq = &drive->sense_rq;
172 unsigned int cmd_len, sense_len;
173 int err;
174
175 debug_log("%s: enter\n", __func__);
176
177 switch (drive->media) {
178 case ide_floppy:
179 cmd_len = 255;
180 sense_len = 18;
181 break;
182 case ide_tape:
183 cmd_len = 20;
184 sense_len = 20;
185 break;
186 default:
187 cmd_len = 18;
188 sense_len = 18;
189 }
190
191 BUG_ON(sense_len > sizeof(*sense));
192
193 if (blk_sense_request(rq) || drive->sense_rq_armed)
194 return;
195
196 memset(sense, 0, sizeof(*sense));
197
198 blk_rq_init(rq->q, sense_rq);
199
200 err = blk_rq_map_kern(drive->queue, sense_rq, sense, sense_len,
201 GFP_NOIO);
202 if (unlikely(err)) {
203 if (printk_ratelimit())
204 printk(KERN_WARNING "%s: failed to map sense buffer\n",
205 drive->name);
206 return;
207 }
208
209 sense_rq->rq_disk = rq->rq_disk;
210 sense_rq->cmd[0] = GPCMD_REQUEST_SENSE;
211 sense_rq->cmd[4] = cmd_len;
212 sense_rq->cmd_type = REQ_TYPE_SENSE;
213 sense_rq->cmd_flags |= REQ_PREEMPT;
214
215 if (drive->media == ide_tape)
216 sense_rq->cmd[13] = REQ_IDETAPE_PC1;
217
218 drive->sense_rq_armed = true;
219}
220EXPORT_SYMBOL_GPL(ide_prep_sense);
221
222int ide_queue_sense_rq(ide_drive_t *drive, void *special)
223{
224 /* deferred failure from ide_prep_sense() */
225 if (!drive->sense_rq_armed) {
226 printk(KERN_WARNING "%s: failed queue sense request\n",
227 drive->name);
228 return -ENOMEM;
229 }
230
231 drive->sense_rq.special = special;
232 drive->sense_rq_armed = false;
233
234 drive->hwif->rq = NULL;
235
236 elv_add_request(drive->queue, &drive->sense_rq,
237 ELEVATOR_INSERT_FRONT, 0);
238 return 0;
239}
240EXPORT_SYMBOL_GPL(ide_queue_sense_rq);
241
194/* 242/*
195 * Called when an error was detected during the last packet command. 243 * Called when an error was detected during the last packet command.
196 * We queue a request sense packet command in the head of the request list. 244 * We queue a request sense packet command at the head of the request
245 * queue.
197 */ 246 */
198void ide_retry_pc(ide_drive_t *drive, struct gendisk *disk) 247void ide_retry_pc(ide_drive_t *drive)
199{ 248{
200 struct request *rq = &drive->request_sense_rq; 249 struct request *failed_rq = drive->hwif->rq;
250 struct request *sense_rq = &drive->sense_rq;
201 struct ide_atapi_pc *pc = &drive->request_sense_pc; 251 struct ide_atapi_pc *pc = &drive->request_sense_pc;
202 252
203 (void)ide_read_error(drive); 253 (void)ide_read_error(drive);
204 ide_create_request_sense_cmd(drive, pc); 254
255 /* init pc from sense_rq */
256 ide_init_pc(pc);
257 memcpy(pc->c, sense_rq->cmd, 12);
258 pc->buf = bio_data(sense_rq->bio); /* pointer to mapped address */
259 pc->req_xfer = blk_rq_bytes(sense_rq);
260
205 if (drive->media == ide_tape) 261 if (drive->media == ide_tape)
206 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags); 262 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
207 ide_queue_pc_head(drive, disk, pc, rq); 263
264 /*
265 * Push back the failed request and put request sense on top
266 * of it. The failed command will be retried after sense data
267 * is acquired.
268 */
269 blk_requeue_request(failed_rq->q, failed_rq);
270 drive->hwif->rq = NULL;
271 if (ide_queue_sense_rq(drive, pc)) {
272 blk_start_request(failed_rq);
273 ide_complete_rq(drive, -EIO, blk_rq_bytes(failed_rq));
274 }
208} 275}
209EXPORT_SYMBOL_GPL(ide_retry_pc); 276EXPORT_SYMBOL_GPL(ide_retry_pc);
210 277
@@ -246,7 +313,7 @@ int ide_cd_get_xferlen(struct request *rq)
246 return 32768; 313 return 32768;
247 else if (blk_sense_request(rq) || blk_pc_request(rq) || 314 else if (blk_sense_request(rq) || blk_pc_request(rq) ||
248 rq->cmd_type == REQ_TYPE_ATA_PC) 315 rq->cmd_type == REQ_TYPE_ATA_PC)
249 return rq->data_len; 316 return blk_rq_bytes(rq);
250 else 317 else
251 return 0; 318 return 0;
252} 319}
@@ -276,7 +343,6 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
276 struct ide_cmd *cmd = &hwif->cmd; 343 struct ide_cmd *cmd = &hwif->cmd;
277 struct request *rq = hwif->rq; 344 struct request *rq = hwif->rq;
278 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 345 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
279 xfer_func_t *xferfunc;
280 unsigned int timeout, done; 346 unsigned int timeout, done;
281 u16 bcount; 347 u16 bcount;
282 u8 stat, ireason, dsc = 0; 348 u8 stat, ireason, dsc = 0;
@@ -303,18 +369,14 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
303 drive->name, rq_data_dir(pc->rq) 369 drive->name, rq_data_dir(pc->rq)
304 ? "write" : "read"); 370 ? "write" : "read");
305 pc->flags |= PC_FLAG_DMA_ERROR; 371 pc->flags |= PC_FLAG_DMA_ERROR;
306 } else { 372 } else
307 pc->xferred = pc->req_xfer; 373 pc->xferred = pc->req_xfer;
308 if (drive->pc_update_buffers)
309 drive->pc_update_buffers(drive, pc);
310 }
311 debug_log("%s: DMA finished\n", drive->name); 374 debug_log("%s: DMA finished\n", drive->name);
312 } 375 }
313 376
314 /* No more interrupts */ 377 /* No more interrupts */
315 if ((stat & ATA_DRQ) == 0) { 378 if ((stat & ATA_DRQ) == 0) {
316 int uptodate, error; 379 int uptodate, error;
317 unsigned int done;
318 380
319 debug_log("Packet command completed, %d bytes transferred\n", 381 debug_log("Packet command completed, %d bytes transferred\n",
320 pc->xferred); 382 pc->xferred);
@@ -343,7 +405,7 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
343 debug_log("[cmd %x]: check condition\n", rq->cmd[0]); 405 debug_log("[cmd %x]: check condition\n", rq->cmd[0]);
344 406
345 /* Retry operation */ 407 /* Retry operation */
346 ide_retry_pc(drive, rq->rq_disk); 408 ide_retry_pc(drive);
347 409
348 /* queued, but not started */ 410 /* queued, but not started */
349 return ide_stopped; 411 return ide_stopped;
@@ -353,6 +415,12 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
353 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0) 415 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0)
354 dsc = 1; 416 dsc = 1;
355 417
418 /*
419 * ->pc_callback() might change rq->data_len for
420 * residual count, cache total length.
421 */
422 done = blk_rq_bytes(rq);
423
356 /* Command finished - Call the callback function */ 424 /* Command finished - Call the callback function */
357 uptodate = drive->pc_callback(drive, dsc); 425 uptodate = drive->pc_callback(drive, dsc);
358 426
@@ -361,7 +429,6 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
361 429
362 if (blk_special_request(rq)) { 430 if (blk_special_request(rq)) {
363 rq->errors = 0; 431 rq->errors = 0;
364 done = blk_rq_bytes(rq);
365 error = 0; 432 error = 0;
366 } else { 433 } else {
367 434
@@ -370,15 +437,10 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
370 rq->errors = -EIO; 437 rq->errors = -EIO;
371 } 438 }
372 439
373 if (drive->media == ide_tape)
374 done = ide_rq_bytes(rq); /* FIXME */
375 else
376 done = blk_rq_bytes(rq);
377
378 error = uptodate ? 0 : -EIO; 440 error = uptodate ? 0 : -EIO;
379 } 441 }
380 442
381 ide_complete_rq(drive, error, done); 443 ide_complete_rq(drive, error, blk_rq_bytes(rq));
382 return ide_stopped; 444 return ide_stopped;
383 } 445 }
384 446
@@ -407,21 +469,11 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
407 return ide_do_reset(drive); 469 return ide_do_reset(drive);
408 } 470 }
409 471
410 xferfunc = write ? tp_ops->output_data : tp_ops->input_data; 472 done = min_t(unsigned int, bcount, cmd->nleft);
411 473 ide_pio_bytes(drive, cmd, write, done);
412 if (drive->media == ide_floppy && pc->buf == NULL) {
413 done = min_t(unsigned int, bcount, cmd->nleft);
414 ide_pio_bytes(drive, cmd, write, done);
415 } else if (drive->media == ide_tape && pc->bh) {
416 done = drive->pc_io_buffers(drive, pc, bcount, write);
417 } else {
418 done = min_t(unsigned int, bcount, pc->req_xfer - pc->xferred);
419 xferfunc(drive, NULL, pc->cur_pos, done);
420 }
421 474
422 /* Update the current position */ 475 /* Update transferred byte count */
423 pc->xferred += done; 476 pc->xferred += done;
424 pc->cur_pos += done;
425 477
426 bcount -= done; 478 bcount -= done;
427 479
@@ -599,7 +651,6 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_cmd *cmd)
599 651
600 /* We haven't transferred any data yet */ 652 /* We haven't transferred any data yet */
601 pc->xferred = 0; 653 pc->xferred = 0;
602 pc->cur_pos = pc->buf;
603 654
604 valid_tf = IDE_VALID_DEVICE; 655 valid_tf = IDE_VALID_DEVICE;
605 bcount = ((drive->media == ide_tape) ? 656 bcount = ((drive->media == ide_tape) ?
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 925eb9e245d1..424140c6c400 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -182,7 +182,7 @@ static void cdrom_analyze_sense_data(ide_drive_t *drive,
182 (sense->information[2] << 8) | 182 (sense->information[2] << 8) |
183 (sense->information[3]); 183 (sense->information[3]);
184 184
185 if (drive->queue->hardsect_size == 2048) 185 if (queue_logical_block_size(drive->queue) == 2048)
186 /* device sector size is 2K */ 186 /* device sector size is 2K */
187 sector <<= 2; 187 sector <<= 2;
188 188
@@ -206,54 +206,25 @@ static void cdrom_analyze_sense_data(ide_drive_t *drive,
206 ide_cd_log_error(drive->name, failed_command, sense); 206 ide_cd_log_error(drive->name, failed_command, sense);
207} 207}
208 208
209static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
210 struct request *failed_command)
211{
212 struct cdrom_info *info = drive->driver_data;
213 struct request *rq = &drive->request_sense_rq;
214
215 ide_debug_log(IDE_DBG_SENSE, "enter");
216
217 if (sense == NULL)
218 sense = &info->sense_data;
219
220 /* stuff the sense request in front of our current request */
221 blk_rq_init(NULL, rq);
222 rq->cmd_type = REQ_TYPE_ATA_PC;
223 rq->rq_disk = info->disk;
224
225 rq->data = sense;
226 rq->cmd[0] = GPCMD_REQUEST_SENSE;
227 rq->cmd[4] = 18;
228 rq->data_len = 18;
229
230 rq->cmd_type = REQ_TYPE_SENSE;
231 rq->cmd_flags |= REQ_PREEMPT;
232
233 /* NOTE! Save the failed command in "rq->buffer" */
234 rq->buffer = (void *) failed_command;
235
236 if (failed_command)
237 ide_debug_log(IDE_DBG_SENSE, "failed_cmd: 0x%x",
238 failed_command->cmd[0]);
239
240 drive->hwif->rq = NULL;
241
242 elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 0);
243}
244
245static void ide_cd_complete_failed_rq(ide_drive_t *drive, struct request *rq) 209static void ide_cd_complete_failed_rq(ide_drive_t *drive, struct request *rq)
246{ 210{
247 /* 211 /*
248 * For REQ_TYPE_SENSE, "rq->buffer" points to the original 212 * For REQ_TYPE_SENSE, "rq->special" points to the original
249 * failed request 213 * failed request. Also, the sense data should be read
214 * directly from rq which might be different from the original
215 * sense buffer if it got copied during mapping.
250 */ 216 */
251 struct request *failed = (struct request *)rq->buffer; 217 struct request *failed = (struct request *)rq->special;
252 struct cdrom_info *info = drive->driver_data; 218 void *sense = bio_data(rq->bio);
253 void *sense = &info->sense_data;
254 219
255 if (failed) { 220 if (failed) {
256 if (failed->sense) { 221 if (failed->sense) {
222 /*
223 * Sense is always read into drive->sense_data.
224 * Copy back if the failed request has its
225 * sense pointer set.
226 */
227 memcpy(failed->sense, sense, 18);
257 sense = failed->sense; 228 sense = failed->sense;
258 failed->sense_len = rq->sense_len; 229 failed->sense_len = rq->sense_len;
259 } 230 }
@@ -428,22 +399,13 @@ static int cdrom_decode_status(ide_drive_t *drive, u8 stat)
428 399
429 /* if we got a CHECK_CONDITION status, queue a request sense command */ 400 /* if we got a CHECK_CONDITION status, queue a request sense command */
430 if (stat & ATA_ERR) 401 if (stat & ATA_ERR)
431 cdrom_queue_request_sense(drive, NULL, NULL); 402 return ide_queue_sense_rq(drive, NULL) ? 2 : 1;
432 return 1; 403 return 1;
433 404
434end_request: 405end_request:
435 if (stat & ATA_ERR) { 406 if (stat & ATA_ERR) {
436 struct request_queue *q = drive->queue;
437 unsigned long flags;
438
439 spin_lock_irqsave(q->queue_lock, flags);
440 blkdev_dequeue_request(rq);
441 spin_unlock_irqrestore(q->queue_lock, flags);
442
443 hwif->rq = NULL; 407 hwif->rq = NULL;
444 408 return ide_queue_sense_rq(drive, rq) ? 2 : 1;
445 cdrom_queue_request_sense(drive, rq->sense, rq);
446 return 1;
447 } else 409 } else
448 return 2; 410 return 2;
449} 411}
@@ -503,14 +465,8 @@ static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct ide_cmd *cmd)
503 * and some drives don't send them. Sigh. 465 * and some drives don't send them. Sigh.
504 */ 466 */
505 if (rq->cmd[0] == GPCMD_REQUEST_SENSE && 467 if (rq->cmd[0] == GPCMD_REQUEST_SENSE &&
506 cmd->nleft > 0 && cmd->nleft <= 5) { 468 cmd->nleft > 0 && cmd->nleft <= 5)
507 unsigned int ofs = cmd->nbytes - cmd->nleft; 469 cmd->nleft = 0;
508
509 while (cmd->nleft > 0) {
510 *((u8 *)rq->data + ofs++) = 0;
511 cmd->nleft--;
512 }
513 }
514} 470}
515 471
516int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd, 472int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
@@ -543,14 +499,18 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
543 rq->cmd_flags |= cmd_flags; 499 rq->cmd_flags |= cmd_flags;
544 rq->timeout = timeout; 500 rq->timeout = timeout;
545 if (buffer) { 501 if (buffer) {
546 rq->data = buffer; 502 error = blk_rq_map_kern(drive->queue, rq, buffer,
547 rq->data_len = *bufflen; 503 *bufflen, GFP_NOIO);
504 if (error) {
505 blk_put_request(rq);
506 return error;
507 }
548 } 508 }
549 509
550 error = blk_execute_rq(drive->queue, info->disk, rq, 0); 510 error = blk_execute_rq(drive->queue, info->disk, rq, 0);
551 511
552 if (buffer) 512 if (buffer)
553 *bufflen = rq->data_len; 513 *bufflen = rq->resid_len;
554 514
555 flags = rq->cmd_flags; 515 flags = rq->cmd_flags;
556 blk_put_request(rq); 516 blk_put_request(rq);
@@ -608,7 +568,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
608 struct request *rq = hwif->rq; 568 struct request *rq = hwif->rq;
609 ide_expiry_t *expiry = NULL; 569 ide_expiry_t *expiry = NULL;
610 int dma_error = 0, dma, thislen, uptodate = 0; 570 int dma_error = 0, dma, thislen, uptodate = 0;
611 int write = (rq_data_dir(rq) == WRITE) ? 1 : 0, rc = 0, nsectors; 571 int write = (rq_data_dir(rq) == WRITE) ? 1 : 0, rc = 0;
612 int sense = blk_sense_request(rq); 572 int sense = blk_sense_request(rq);
613 unsigned int timeout; 573 unsigned int timeout;
614 u16 len; 574 u16 len;
@@ -738,13 +698,8 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
738 698
739out_end: 699out_end:
740 if (blk_pc_request(rq) && rc == 0) { 700 if (blk_pc_request(rq) && rc == 0) {
741 unsigned int dlen = rq->data_len; 701 rq->resid_len = 0;
742 702 blk_end_request_all(rq, 0);
743 rq->data_len = 0;
744
745 if (blk_end_request(rq, 0, dlen))
746 BUG();
747
748 hwif->rq = NULL; 703 hwif->rq = NULL;
749 } else { 704 } else {
750 if (sense && uptodate) 705 if (sense && uptodate)
@@ -762,21 +717,13 @@ out_end:
762 ide_cd_error_cmd(drive, cmd); 717 ide_cd_error_cmd(drive, cmd);
763 718
764 /* make sure it's fully ended */ 719 /* make sure it's fully ended */
765 if (blk_pc_request(rq))
766 nsectors = (rq->data_len + 511) >> 9;
767 else
768 nsectors = rq->hard_nr_sectors;
769
770 if (nsectors == 0)
771 nsectors = 1;
772
773 if (blk_fs_request(rq) == 0) { 720 if (blk_fs_request(rq) == 0) {
774 rq->data_len -= (cmd->nbytes - cmd->nleft); 721 rq->resid_len -= cmd->nbytes - cmd->nleft;
775 if (uptodate == 0 && (cmd->tf_flags & IDE_TFLAG_WRITE)) 722 if (uptodate == 0 && (cmd->tf_flags & IDE_TFLAG_WRITE))
776 rq->data_len += cmd->last_xfer_len; 723 rq->resid_len += cmd->last_xfer_len;
777 } 724 }
778 725
779 ide_complete_rq(drive, uptodate ? 0 : -EIO, nsectors << 9); 726 ide_complete_rq(drive, uptodate ? 0 : -EIO, blk_rq_bytes(rq));
780 727
781 if (sense && rc == 2) 728 if (sense && rc == 2)
782 ide_error(drive, "request sense failure", stat); 729 ide_error(drive, "request sense failure", stat);
@@ -790,7 +737,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
790 struct request_queue *q = drive->queue; 737 struct request_queue *q = drive->queue;
791 int write = rq_data_dir(rq) == WRITE; 738 int write = rq_data_dir(rq) == WRITE;
792 unsigned short sectors_per_frame = 739 unsigned short sectors_per_frame =
793 queue_hardsect_size(q) >> SECTOR_BITS; 740 queue_logical_block_size(q) >> SECTOR_BITS;
794 741
795 ide_debug_log(IDE_DBG_RQ, "rq->cmd[0]: 0x%x, rq->cmd_flags: 0x%x, " 742 ide_debug_log(IDE_DBG_RQ, "rq->cmd[0]: 0x%x, rq->cmd_flags: 0x%x, "
796 "secs_per_frame: %u", 743 "secs_per_frame: %u",
@@ -809,8 +756,8 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
809 } 756 }
810 757
811 /* fs requests *must* be hardware frame aligned */ 758 /* fs requests *must* be hardware frame aligned */
812 if ((rq->nr_sectors & (sectors_per_frame - 1)) || 759 if ((blk_rq_sectors(rq) & (sectors_per_frame - 1)) ||
813 (rq->sector & (sectors_per_frame - 1))) 760 (blk_rq_pos(rq) & (sectors_per_frame - 1)))
814 return ide_stopped; 761 return ide_stopped;
815 762
816 /* use DMA, if possible */ 763 /* use DMA, if possible */
@@ -838,15 +785,10 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
838 drive->dma = 0; 785 drive->dma = 0;
839 786
840 /* sg request */ 787 /* sg request */
841 if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) { 788 if (rq->bio) {
842 struct request_queue *q = drive->queue; 789 struct request_queue *q = drive->queue;
790 char *buf = bio_data(rq->bio);
843 unsigned int alignment; 791 unsigned int alignment;
844 char *buf;
845
846 if (rq->bio)
847 buf = bio_data(rq->bio);
848 else
849 buf = rq->data;
850 792
851 drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA); 793 drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
852 794
@@ -858,7 +800,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
858 */ 800 */
859 alignment = queue_dma_alignment(q) | q->dma_pad_mask; 801 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
860 if ((unsigned long)buf & alignment 802 if ((unsigned long)buf & alignment
861 || rq->data_len & q->dma_pad_mask 803 || blk_rq_bytes(rq) & q->dma_pad_mask
862 || object_is_on_stack(buf)) 804 || object_is_on_stack(buf))
863 drive->dma = 0; 805 drive->dma = 0;
864 } 806 }
@@ -896,6 +838,9 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
896 goto out_end; 838 goto out_end;
897 } 839 }
898 840
841 /* prepare sense request for this command */
842 ide_prep_sense(drive, rq);
843
899 memset(&cmd, 0, sizeof(cmd)); 844 memset(&cmd, 0, sizeof(cmd));
900 845
901 if (rq_data_dir(rq)) 846 if (rq_data_dir(rq))
@@ -903,15 +848,14 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
903 848
904 cmd.rq = rq; 849 cmd.rq = rq;
905 850
906 if (blk_fs_request(rq) || rq->data_len) { 851 if (blk_fs_request(rq) || blk_rq_bytes(rq)) {
907 ide_init_sg_cmd(&cmd, blk_fs_request(rq) ? (rq->nr_sectors << 9) 852 ide_init_sg_cmd(&cmd, blk_rq_bytes(rq));
908 : rq->data_len);
909 ide_map_sg(drive, &cmd); 853 ide_map_sg(drive, &cmd);
910 } 854 }
911 855
912 return ide_issue_pc(drive, &cmd); 856 return ide_issue_pc(drive, &cmd);
913out_end: 857out_end:
914 nsectors = rq->hard_nr_sectors; 858 nsectors = blk_rq_sectors(rq);
915 859
916 if (nsectors == 0) 860 if (nsectors == 0)
917 nsectors = 1; 861 nsectors = 1;
@@ -1077,8 +1021,8 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
1077 /* save a private copy of the TOC capacity for error handling */ 1021 /* save a private copy of the TOC capacity for error handling */
1078 drive->probed_capacity = toc->capacity * sectors_per_frame; 1022 drive->probed_capacity = toc->capacity * sectors_per_frame;
1079 1023
1080 blk_queue_hardsect_size(drive->queue, 1024 blk_queue_logical_block_size(drive->queue,
1081 sectors_per_frame << SECTOR_BITS); 1025 sectors_per_frame << SECTOR_BITS);
1082 1026
1083 /* first read just the header, so we know how long the TOC is */ 1027 /* first read just the header, so we know how long the TOC is */
1084 stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr, 1028 stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr,
@@ -1394,9 +1338,9 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1394/* standard prep_rq_fn that builds 10 byte cmds */ 1338/* standard prep_rq_fn that builds 10 byte cmds */
1395static int ide_cdrom_prep_fs(struct request_queue *q, struct request *rq) 1339static int ide_cdrom_prep_fs(struct request_queue *q, struct request *rq)
1396{ 1340{
1397 int hard_sect = queue_hardsect_size(q); 1341 int hard_sect = queue_logical_block_size(q);
1398 long block = (long)rq->hard_sector / (hard_sect >> 9); 1342 long block = (long)blk_rq_pos(rq) / (hard_sect >> 9);
1399 unsigned long blocks = rq->hard_nr_sectors / (hard_sect >> 9); 1343 unsigned long blocks = blk_rq_sectors(rq) / (hard_sect >> 9);
1400 1344
1401 memset(rq->cmd, 0, BLK_MAX_CDB); 1345 memset(rq->cmd, 0, BLK_MAX_CDB);
1402 1346
@@ -1599,7 +1543,7 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1599 1543
1600 nslots = ide_cdrom_probe_capabilities(drive); 1544 nslots = ide_cdrom_probe_capabilities(drive);
1601 1545
1602 blk_queue_hardsect_size(q, CD_FRAMESIZE); 1546 blk_queue_logical_block_size(q, CD_FRAMESIZE);
1603 1547
1604 if (ide_cdrom_register(drive, nslots)) { 1548 if (ide_cdrom_register(drive, nslots)) {
1605 printk(KERN_ERR PFX "%s: %s failed to register device with the" 1549 printk(KERN_ERR PFX "%s: %s failed to register device with the"
diff --git a/drivers/ide/ide-cd.h b/drivers/ide/ide-cd.h
index 1d97101099ce..93a3cf1b0f3f 100644
--- a/drivers/ide/ide-cd.h
+++ b/drivers/ide/ide-cd.h
@@ -87,10 +87,6 @@ struct cdrom_info {
87 87
88 struct atapi_toc *toc; 88 struct atapi_toc *toc;
89 89
90 /* The result of the last successful request sense command
91 on this device. */
92 struct request_sense sense_data;
93
94 u8 max_speed; /* Max speed of the drive. */ 90 u8 max_speed; /* Max speed of the drive. */
95 u8 current_speed; /* Current speed of the drive. */ 91 u8 current_speed; /* Current speed of the drive. */
96 92
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index a9fbe2c31210..c6f7fcfb9d67 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -82,7 +82,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
82 sector_t block) 82 sector_t block)
83{ 83{
84 ide_hwif_t *hwif = drive->hwif; 84 ide_hwif_t *hwif = drive->hwif;
85 u16 nsectors = (u16)rq->nr_sectors; 85 u16 nsectors = (u16)blk_rq_sectors(rq);
86 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); 86 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
87 u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA); 87 u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
88 struct ide_cmd cmd; 88 struct ide_cmd cmd;
@@ -90,7 +90,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
90 ide_startstop_t rc; 90 ide_startstop_t rc;
91 91
92 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && lba48 && dma) { 92 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && lba48 && dma) {
93 if (block + rq->nr_sectors > 1ULL << 28) 93 if (block + blk_rq_sectors(rq) > 1ULL << 28)
94 dma = 0; 94 dma = 0;
95 else 95 else
96 lba48 = 0; 96 lba48 = 0;
@@ -195,9 +195,9 @@ static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
195 195
196 ledtrig_ide_activity(); 196 ledtrig_ide_activity();
197 197
198 pr_debug("%s: %sing: block=%llu, sectors=%lu, buffer=0x%08lx\n", 198 pr_debug("%s: %sing: block=%llu, sectors=%u, buffer=0x%08lx\n",
199 drive->name, rq_data_dir(rq) == READ ? "read" : "writ", 199 drive->name, rq_data_dir(rq) == READ ? "read" : "writ",
200 (unsigned long long)block, rq->nr_sectors, 200 (unsigned long long)block, blk_rq_sectors(rq),
201 (unsigned long)rq->buffer); 201 (unsigned long)rq->buffer);
202 202
203 if (hwif->rw_disk) 203 if (hwif->rw_disk)
@@ -411,7 +411,6 @@ static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
411 cmd->protocol = ATA_PROT_NODATA; 411 cmd->protocol = ATA_PROT_NODATA;
412 412
413 rq->cmd_type = REQ_TYPE_ATA_TASKFILE; 413 rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
414 rq->cmd_flags |= REQ_SOFTBARRIER;
415 rq->special = cmd; 414 rq->special = cmd;
416} 415}
417 416
@@ -640,7 +639,7 @@ static void ide_disk_setup(ide_drive_t *drive)
640 } 639 }
641 640
642 printk(KERN_INFO "%s: max request size: %dKiB\n", drive->name, 641 printk(KERN_INFO "%s: max request size: %dKiB\n", drive->name,
643 q->max_sectors / 2); 642 queue_max_sectors(q) / 2);
644 643
645 if (ata_id_is_ssd(id)) 644 if (ata_id_is_ssd(id))
646 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q); 645 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index a0b8cab1d9a6..001f68f0bb28 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -103,7 +103,7 @@ ide_startstop_t ide_dma_intr(ide_drive_t *drive)
103 ide_finish_cmd(drive, cmd, stat); 103 ide_finish_cmd(drive, cmd, stat);
104 else 104 else
105 ide_complete_rq(drive, 0, 105 ide_complete_rq(drive, 0,
106 cmd->rq->nr_sectors << 9); 106 blk_rq_sectors(cmd->rq) << 9);
107 return ide_stopped; 107 return ide_stopped;
108 } 108 }
109 printk(KERN_ERR "%s: %s: bad DMA status (0x%02x)\n", 109 printk(KERN_ERR "%s: %s: bad DMA status (0x%02x)\n",
@@ -510,23 +510,11 @@ ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
510 /* 510 /*
511 * un-busy drive etc and make sure request is sane 511 * un-busy drive etc and make sure request is sane
512 */ 512 */
513
514 rq = hwif->rq; 513 rq = hwif->rq;
515 if (!rq) 514 if (rq) {
516 goto out; 515 hwif->rq = NULL;
517 516 rq->errors = 0;
518 hwif->rq = NULL; 517 }
519
520 rq->errors = 0;
521
522 if (!rq->bio)
523 goto out;
524
525 rq->sector = rq->bio->bi_sector;
526 rq->current_nr_sectors = bio_iovec(rq->bio)->bv_len >> 9;
527 rq->hard_cur_sectors = rq->current_nr_sectors;
528 rq->buffer = bio_data(rq->bio);
529out:
530 return ret; 518 return ret;
531} 519}
532 520
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 2b4868d95f8b..650981758f15 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -134,13 +134,17 @@ static ide_startstop_t ide_floppy_issue_pc(ide_drive_t *drive,
134 drive->pc = pc; 134 drive->pc = pc;
135 135
136 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) { 136 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) {
137 unsigned int done = blk_rq_bytes(drive->hwif->rq);
138
137 if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR)) 139 if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR))
138 ide_floppy_report_error(floppy, pc); 140 ide_floppy_report_error(floppy, pc);
141
139 /* Giving up */ 142 /* Giving up */
140 pc->error = IDE_DRV_ERROR_GENERAL; 143 pc->error = IDE_DRV_ERROR_GENERAL;
141 144
142 drive->failed_pc = NULL; 145 drive->failed_pc = NULL;
143 drive->pc_callback(drive, 0); 146 drive->pc_callback(drive, 0);
147 ide_complete_rq(drive, -EIO, done);
144 return ide_stopped; 148 return ide_stopped;
145 } 149 }
146 150
@@ -190,7 +194,7 @@ static void idefloppy_create_rw_cmd(ide_drive_t *drive,
190{ 194{
191 struct ide_disk_obj *floppy = drive->driver_data; 195 struct ide_disk_obj *floppy = drive->driver_data;
192 int block = sector / floppy->bs_factor; 196 int block = sector / floppy->bs_factor;
193 int blocks = rq->nr_sectors / floppy->bs_factor; 197 int blocks = blk_rq_sectors(rq) / floppy->bs_factor;
194 int cmd = rq_data_dir(rq); 198 int cmd = rq_data_dir(rq);
195 199
196 ide_debug_log(IDE_DBG_FUNC, "block: %d, blocks: %d", block, blocks); 200 ide_debug_log(IDE_DBG_FUNC, "block: %d, blocks: %d", block, blocks);
@@ -216,16 +220,14 @@ static void idefloppy_blockpc_cmd(struct ide_disk_obj *floppy,
216 ide_init_pc(pc); 220 ide_init_pc(pc);
217 memcpy(pc->c, rq->cmd, sizeof(pc->c)); 221 memcpy(pc->c, rq->cmd, sizeof(pc->c));
218 pc->rq = rq; 222 pc->rq = rq;
219 if (rq->data_len && rq_data_dir(rq) == WRITE) 223 if (blk_rq_bytes(rq)) {
220 pc->flags |= PC_FLAG_WRITING;
221 pc->buf = rq->data;
222 if (rq->bio)
223 pc->flags |= PC_FLAG_DMA_OK; 224 pc->flags |= PC_FLAG_DMA_OK;
224 /* 225 if (rq_data_dir(rq) == WRITE)
225 * possibly problematic, doesn't look like ide-floppy correctly 226 pc->flags |= PC_FLAG_WRITING;
226 * handled scattered requests if dma fails... 227 }
227 */ 228 /* pio will be performed by ide_pio_bytes() which handles sg fine */
228 pc->req_xfer = pc->buf_size = rq->data_len; 229 pc->buf = NULL;
230 pc->req_xfer = pc->buf_size = blk_rq_bytes(rq);
229} 231}
230 232
231static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive, 233static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
@@ -257,16 +259,16 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
257 goto out_end; 259 goto out_end;
258 } 260 }
259 if (blk_fs_request(rq)) { 261 if (blk_fs_request(rq)) {
260 if (((long)rq->sector % floppy->bs_factor) || 262 if (((long)blk_rq_pos(rq) % floppy->bs_factor) ||
261 (rq->nr_sectors % floppy->bs_factor)) { 263 (blk_rq_sectors(rq) % floppy->bs_factor)) {
262 printk(KERN_ERR PFX "%s: unsupported r/w rq size\n", 264 printk(KERN_ERR PFX "%s: unsupported r/w rq size\n",
263 drive->name); 265 drive->name);
264 goto out_end; 266 goto out_end;
265 } 267 }
266 pc = &floppy->queued_pc; 268 pc = &floppy->queued_pc;
267 idefloppy_create_rw_cmd(drive, pc, rq, (unsigned long)block); 269 idefloppy_create_rw_cmd(drive, pc, rq, (unsigned long)block);
268 } else if (blk_special_request(rq)) { 270 } else if (blk_special_request(rq) || blk_sense_request(rq)) {
269 pc = (struct ide_atapi_pc *) rq->buffer; 271 pc = (struct ide_atapi_pc *)rq->special;
270 } else if (blk_pc_request(rq)) { 272 } else if (blk_pc_request(rq)) {
271 pc = &floppy->queued_pc; 273 pc = &floppy->queued_pc;
272 idefloppy_blockpc_cmd(floppy, pc, rq); 274 idefloppy_blockpc_cmd(floppy, pc, rq);
@@ -275,6 +277,8 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
275 goto out_end; 277 goto out_end;
276 } 278 }
277 279
280 ide_prep_sense(drive, rq);
281
278 memset(&cmd, 0, sizeof(cmd)); 282 memset(&cmd, 0, sizeof(cmd));
279 283
280 if (rq_data_dir(rq)) 284 if (rq_data_dir(rq))
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 6415a2e2ba87..bba4297f2f03 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -116,9 +116,9 @@ void ide_complete_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 stat, u8 err)
116unsigned int ide_rq_bytes(struct request *rq) 116unsigned int ide_rq_bytes(struct request *rq)
117{ 117{
118 if (blk_pc_request(rq)) 118 if (blk_pc_request(rq))
119 return rq->data_len; 119 return blk_rq_bytes(rq);
120 else 120 else
121 return rq->hard_cur_sectors << 9; 121 return blk_rq_cur_sectors(rq) << 9;
122} 122}
123EXPORT_SYMBOL_GPL(ide_rq_bytes); 123EXPORT_SYMBOL_GPL(ide_rq_bytes);
124 124
@@ -133,7 +133,7 @@ int ide_complete_rq(ide_drive_t *drive, int error, unsigned int nr_bytes)
133 * and complete the whole request right now 133 * and complete the whole request right now
134 */ 134 */
135 if (blk_noretry_request(rq) && error <= 0) 135 if (blk_noretry_request(rq) && error <= 0)
136 nr_bytes = rq->hard_nr_sectors << 9; 136 nr_bytes = blk_rq_sectors(rq) << 9;
137 137
138 rc = ide_end_rq(drive, rq, error, nr_bytes); 138 rc = ide_end_rq(drive, rq, error, nr_bytes);
139 if (rc == 0) 139 if (rc == 0)
@@ -248,14 +248,7 @@ void ide_map_sg(ide_drive_t *drive, struct ide_cmd *cmd)
248 struct scatterlist *sg = hwif->sg_table; 248 struct scatterlist *sg = hwif->sg_table;
249 struct request *rq = cmd->rq; 249 struct request *rq = cmd->rq;
250 250
251 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) { 251 cmd->sg_nents = blk_rq_map_sg(drive->queue, rq, sg);
252 sg_init_one(sg, rq->buffer, rq->nr_sectors * SECTOR_SIZE);
253 cmd->sg_nents = 1;
254 } else if (!rq->bio) {
255 sg_init_one(sg, rq->data, rq->data_len);
256 cmd->sg_nents = 1;
257 } else
258 cmd->sg_nents = blk_rq_map_sg(drive->queue, rq, sg);
259} 252}
260EXPORT_SYMBOL_GPL(ide_map_sg); 253EXPORT_SYMBOL_GPL(ide_map_sg);
261 254
@@ -286,7 +279,7 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
286 279
287 if (cmd) { 280 if (cmd) {
288 if (cmd->protocol == ATA_PROT_PIO) { 281 if (cmd->protocol == ATA_PROT_PIO) {
289 ide_init_sg_cmd(cmd, rq->nr_sectors << 9); 282 ide_init_sg_cmd(cmd, blk_rq_sectors(rq) << 9);
290 ide_map_sg(drive, cmd); 283 ide_map_sg(drive, cmd);
291 } 284 }
292 285
@@ -371,7 +364,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
371 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) 364 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
372 return execute_drive_cmd(drive, rq); 365 return execute_drive_cmd(drive, rq);
373 else if (blk_pm_request(rq)) { 366 else if (blk_pm_request(rq)) {
374 struct request_pm_state *pm = rq->data; 367 struct request_pm_state *pm = rq->special;
375#ifdef DEBUG_PM 368#ifdef DEBUG_PM
376 printk("%s: start_power_step(step: %d)\n", 369 printk("%s: start_power_step(step: %d)\n",
377 drive->name, pm->pm_step); 370 drive->name, pm->pm_step);
@@ -394,7 +387,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
394 387
395 drv = *(struct ide_driver **)rq->rq_disk->private_data; 388 drv = *(struct ide_driver **)rq->rq_disk->private_data;
396 389
397 return drv->do_request(drive, rq, rq->sector); 390 return drv->do_request(drive, rq, blk_rq_pos(rq));
398 } 391 }
399 return do_special(drive); 392 return do_special(drive);
400kill_rq: 393kill_rq:
@@ -484,6 +477,9 @@ void do_ide_request(struct request_queue *q)
484 477
485 spin_unlock_irq(q->queue_lock); 478 spin_unlock_irq(q->queue_lock);
486 479
480 /* HLD do_request() callback might sleep, make sure it's okay */
481 might_sleep();
482
487 if (ide_lock_host(host, hwif)) 483 if (ide_lock_host(host, hwif))
488 goto plug_device_2; 484 goto plug_device_2;
489 485
@@ -491,10 +487,10 @@ void do_ide_request(struct request_queue *q)
491 487
492 if (!ide_lock_port(hwif)) { 488 if (!ide_lock_port(hwif)) {
493 ide_hwif_t *prev_port; 489 ide_hwif_t *prev_port;
490
491 WARN_ON_ONCE(hwif->rq);
494repeat: 492repeat:
495 prev_port = hwif->host->cur_port; 493 prev_port = hwif->host->cur_port;
496 hwif->rq = NULL;
497
498 if (drive->dev_flags & IDE_DFLAG_SLEEPING && 494 if (drive->dev_flags & IDE_DFLAG_SLEEPING &&
499 time_after(drive->sleep, jiffies)) { 495 time_after(drive->sleep, jiffies)) {
500 ide_unlock_port(hwif); 496 ide_unlock_port(hwif);
@@ -523,7 +519,9 @@ repeat:
523 * we know that the queue isn't empty, but this can happen 519 * we know that the queue isn't empty, but this can happen
524 * if the q->prep_rq_fn() decides to kill a request 520 * if the q->prep_rq_fn() decides to kill a request
525 */ 521 */
526 rq = elv_next_request(drive->queue); 522 if (!rq)
523 rq = blk_fetch_request(drive->queue);
524
527 spin_unlock_irq(q->queue_lock); 525 spin_unlock_irq(q->queue_lock);
528 spin_lock_irq(&hwif->lock); 526 spin_lock_irq(&hwif->lock);
529 527
@@ -535,7 +533,7 @@ repeat:
535 /* 533 /*
536 * Sanity: don't accept a request that isn't a PM request 534 * Sanity: don't accept a request that isn't a PM request
537 * if we are currently power managed. This is very important as 535 * if we are currently power managed. This is very important as
538 * blk_stop_queue() doesn't prevent the elv_next_request() 536 * blk_stop_queue() doesn't prevent the blk_fetch_request()
539 * above to return us whatever is in the queue. Since we call 537 * above to return us whatever is in the queue. Since we call
540 * ide_do_request() ourselves, we end up taking requests while 538 * ide_do_request() ourselves, we end up taking requests while
541 * the queue is blocked... 539 * the queue is blocked...
@@ -559,8 +557,11 @@ repeat:
559 startstop = start_request(drive, rq); 557 startstop = start_request(drive, rq);
560 spin_lock_irq(&hwif->lock); 558 spin_lock_irq(&hwif->lock);
561 559
562 if (startstop == ide_stopped) 560 if (startstop == ide_stopped) {
561 rq = hwif->rq;
562 hwif->rq = NULL;
563 goto repeat; 563 goto repeat;
564 }
564 } else 565 } else
565 goto plug_device; 566 goto plug_device;
566out: 567out:
@@ -576,18 +577,24 @@ plug_device:
576plug_device_2: 577plug_device_2:
577 spin_lock_irq(q->queue_lock); 578 spin_lock_irq(q->queue_lock);
578 579
580 if (rq)
581 blk_requeue_request(q, rq);
579 if (!elv_queue_empty(q)) 582 if (!elv_queue_empty(q))
580 blk_plug_device(q); 583 blk_plug_device(q);
581} 584}
582 585
583static void ide_plug_device(ide_drive_t *drive) 586static void ide_requeue_and_plug(ide_drive_t *drive, struct request *rq)
584{ 587{
585 struct request_queue *q = drive->queue; 588 struct request_queue *q = drive->queue;
586 unsigned long flags; 589 unsigned long flags;
587 590
588 spin_lock_irqsave(q->queue_lock, flags); 591 spin_lock_irqsave(q->queue_lock, flags);
592
593 if (rq)
594 blk_requeue_request(q, rq);
589 if (!elv_queue_empty(q)) 595 if (!elv_queue_empty(q))
590 blk_plug_device(q); 596 blk_plug_device(q);
597
591 spin_unlock_irqrestore(q->queue_lock, flags); 598 spin_unlock_irqrestore(q->queue_lock, flags);
592} 599}
593 600
@@ -636,6 +643,7 @@ void ide_timer_expiry (unsigned long data)
636 unsigned long flags; 643 unsigned long flags;
637 int wait = -1; 644 int wait = -1;
638 int plug_device = 0; 645 int plug_device = 0;
646 struct request *uninitialized_var(rq_in_flight);
639 647
640 spin_lock_irqsave(&hwif->lock, flags); 648 spin_lock_irqsave(&hwif->lock, flags);
641 649
@@ -697,6 +705,8 @@ void ide_timer_expiry (unsigned long data)
697 spin_lock_irq(&hwif->lock); 705 spin_lock_irq(&hwif->lock);
698 enable_irq(hwif->irq); 706 enable_irq(hwif->irq);
699 if (startstop == ide_stopped && hwif->polling == 0) { 707 if (startstop == ide_stopped && hwif->polling == 0) {
708 rq_in_flight = hwif->rq;
709 hwif->rq = NULL;
700 ide_unlock_port(hwif); 710 ide_unlock_port(hwif);
701 plug_device = 1; 711 plug_device = 1;
702 } 712 }
@@ -705,7 +715,7 @@ void ide_timer_expiry (unsigned long data)
705 715
706 if (plug_device) { 716 if (plug_device) {
707 ide_unlock_host(hwif->host); 717 ide_unlock_host(hwif->host);
708 ide_plug_device(drive); 718 ide_requeue_and_plug(drive, rq_in_flight);
709 } 719 }
710} 720}
711 721
@@ -791,6 +801,7 @@ irqreturn_t ide_intr (int irq, void *dev_id)
791 ide_startstop_t startstop; 801 ide_startstop_t startstop;
792 irqreturn_t irq_ret = IRQ_NONE; 802 irqreturn_t irq_ret = IRQ_NONE;
793 int plug_device = 0; 803 int plug_device = 0;
804 struct request *uninitialized_var(rq_in_flight);
794 805
795 if (host->host_flags & IDE_HFLAG_SERIALIZE) { 806 if (host->host_flags & IDE_HFLAG_SERIALIZE) {
796 if (hwif != host->cur_port) 807 if (hwif != host->cur_port)
@@ -870,6 +881,8 @@ irqreturn_t ide_intr (int irq, void *dev_id)
870 */ 881 */
871 if (startstop == ide_stopped && hwif->polling == 0) { 882 if (startstop == ide_stopped && hwif->polling == 0) {
872 BUG_ON(hwif->handler); 883 BUG_ON(hwif->handler);
884 rq_in_flight = hwif->rq;
885 hwif->rq = NULL;
873 ide_unlock_port(hwif); 886 ide_unlock_port(hwif);
874 plug_device = 1; 887 plug_device = 1;
875 } 888 }
@@ -879,7 +892,7 @@ out:
879out_early: 892out_early:
880 if (plug_device) { 893 if (plug_device) {
881 ide_unlock_host(hwif->host); 894 ide_unlock_host(hwif->host);
882 ide_plug_device(drive); 895 ide_requeue_and_plug(drive, rq_in_flight);
883 } 896 }
884 897
885 return irq_ret; 898 return irq_ret;
diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c
index c1c25ebbaa1f..5991b23793f2 100644
--- a/drivers/ide/ide-ioctls.c
+++ b/drivers/ide/ide-ioctls.c
@@ -231,7 +231,6 @@ static int generic_drive_reset(ide_drive_t *drive)
231 rq->cmd_type = REQ_TYPE_SPECIAL; 231 rq->cmd_type = REQ_TYPE_SPECIAL;
232 rq->cmd_len = 1; 232 rq->cmd_len = 1;
233 rq->cmd[0] = REQ_DRIVE_RESET; 233 rq->cmd[0] = REQ_DRIVE_RESET;
234 rq->cmd_flags |= REQ_SOFTBARRIER;
235 if (blk_execute_rq(drive->queue, NULL, rq, 1)) 234 if (blk_execute_rq(drive->queue, NULL, rq, 1))
236 ret = rq->errors; 235 ret = rq->errors;
237 blk_put_request(rq); 236 blk_put_request(rq);
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 2148df836ce7..e386a32dc9ba 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -96,7 +96,7 @@ static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
96 96
97 if (rq) 97 if (rq)
98 printk(KERN_CONT ", sector=%llu", 98 printk(KERN_CONT ", sector=%llu",
99 (unsigned long long)rq->sector); 99 (unsigned long long)blk_rq_pos(rq));
100 } 100 }
101 printk(KERN_CONT "\n"); 101 printk(KERN_CONT "\n");
102} 102}
diff --git a/drivers/ide/ide-park.c b/drivers/ide/ide-park.c
index 310d03f2b5b7..a914023d6d03 100644
--- a/drivers/ide/ide-park.c
+++ b/drivers/ide/ide-park.c
@@ -24,11 +24,8 @@ static void issue_park_cmd(ide_drive_t *drive, unsigned long timeout)
24 start_queue = 1; 24 start_queue = 1;
25 spin_unlock_irq(&hwif->lock); 25 spin_unlock_irq(&hwif->lock);
26 26
27 if (start_queue) { 27 if (start_queue)
28 spin_lock_irq(q->queue_lock); 28 blk_run_queue(q);
29 blk_start_queueing(q);
30 spin_unlock_irq(q->queue_lock);
31 }
32 return; 29 return;
33 } 30 }
34 spin_unlock_irq(&hwif->lock); 31 spin_unlock_irq(&hwif->lock);
diff --git a/drivers/ide/ide-pm.c b/drivers/ide/ide-pm.c
index 0d8a151c0a01..ba1488bd8430 100644
--- a/drivers/ide/ide-pm.c
+++ b/drivers/ide/ide-pm.c
@@ -7,7 +7,6 @@ int generic_ide_suspend(struct device *dev, pm_message_t mesg)
7 ide_hwif_t *hwif = drive->hwif; 7 ide_hwif_t *hwif = drive->hwif;
8 struct request *rq; 8 struct request *rq;
9 struct request_pm_state rqpm; 9 struct request_pm_state rqpm;
10 struct ide_cmd cmd;
11 int ret; 10 int ret;
12 11
13 /* call ACPI _GTM only once */ 12 /* call ACPI _GTM only once */
@@ -15,11 +14,9 @@ int generic_ide_suspend(struct device *dev, pm_message_t mesg)
15 ide_acpi_get_timing(hwif); 14 ide_acpi_get_timing(hwif);
16 15
17 memset(&rqpm, 0, sizeof(rqpm)); 16 memset(&rqpm, 0, sizeof(rqpm));
18 memset(&cmd, 0, sizeof(cmd));
19 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 17 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
20 rq->cmd_type = REQ_TYPE_PM_SUSPEND; 18 rq->cmd_type = REQ_TYPE_PM_SUSPEND;
21 rq->special = &cmd; 19 rq->special = &rqpm;
22 rq->data = &rqpm;
23 rqpm.pm_step = IDE_PM_START_SUSPEND; 20 rqpm.pm_step = IDE_PM_START_SUSPEND;
24 if (mesg.event == PM_EVENT_PRETHAW) 21 if (mesg.event == PM_EVENT_PRETHAW)
25 mesg.event = PM_EVENT_FREEZE; 22 mesg.event = PM_EVENT_FREEZE;
@@ -41,7 +38,6 @@ int generic_ide_resume(struct device *dev)
41 ide_hwif_t *hwif = drive->hwif; 38 ide_hwif_t *hwif = drive->hwif;
42 struct request *rq; 39 struct request *rq;
43 struct request_pm_state rqpm; 40 struct request_pm_state rqpm;
44 struct ide_cmd cmd;
45 int err; 41 int err;
46 42
47 /* call ACPI _PS0 / _STM only once */ 43 /* call ACPI _PS0 / _STM only once */
@@ -53,12 +49,10 @@ int generic_ide_resume(struct device *dev)
53 ide_acpi_exec_tfs(drive); 49 ide_acpi_exec_tfs(drive);
54 50
55 memset(&rqpm, 0, sizeof(rqpm)); 51 memset(&rqpm, 0, sizeof(rqpm));
56 memset(&cmd, 0, sizeof(cmd));
57 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 52 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
58 rq->cmd_type = REQ_TYPE_PM_RESUME; 53 rq->cmd_type = REQ_TYPE_PM_RESUME;
59 rq->cmd_flags |= REQ_PREEMPT; 54 rq->cmd_flags |= REQ_PREEMPT;
60 rq->special = &cmd; 55 rq->special = &rqpm;
61 rq->data = &rqpm;
62 rqpm.pm_step = IDE_PM_START_RESUME; 56 rqpm.pm_step = IDE_PM_START_RESUME;
63 rqpm.pm_state = PM_EVENT_ON; 57 rqpm.pm_state = PM_EVENT_ON;
64 58
@@ -77,7 +71,7 @@ int generic_ide_resume(struct device *dev)
77 71
78void ide_complete_power_step(ide_drive_t *drive, struct request *rq) 72void ide_complete_power_step(ide_drive_t *drive, struct request *rq)
79{ 73{
80 struct request_pm_state *pm = rq->data; 74 struct request_pm_state *pm = rq->special;
81 75
82#ifdef DEBUG_PM 76#ifdef DEBUG_PM
83 printk(KERN_INFO "%s: complete_power_step(step: %d)\n", 77 printk(KERN_INFO "%s: complete_power_step(step: %d)\n",
@@ -107,10 +101,8 @@ void ide_complete_power_step(ide_drive_t *drive, struct request *rq)
107 101
108ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq) 102ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
109{ 103{
110 struct request_pm_state *pm = rq->data; 104 struct request_pm_state *pm = rq->special;
111 struct ide_cmd *cmd = rq->special; 105 struct ide_cmd cmd = { };
112
113 memset(cmd, 0, sizeof(*cmd));
114 106
115 switch (pm->pm_step) { 107 switch (pm->pm_step) {
116 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */ 108 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
@@ -123,12 +115,12 @@ ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
123 return ide_stopped; 115 return ide_stopped;
124 } 116 }
125 if (ata_id_flush_ext_enabled(drive->id)) 117 if (ata_id_flush_ext_enabled(drive->id))
126 cmd->tf.command = ATA_CMD_FLUSH_EXT; 118 cmd.tf.command = ATA_CMD_FLUSH_EXT;
127 else 119 else
128 cmd->tf.command = ATA_CMD_FLUSH; 120 cmd.tf.command = ATA_CMD_FLUSH;
129 goto out_do_tf; 121 goto out_do_tf;
130 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */ 122 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
131 cmd->tf.command = ATA_CMD_STANDBYNOW1; 123 cmd.tf.command = ATA_CMD_STANDBYNOW1;
132 goto out_do_tf; 124 goto out_do_tf;
133 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */ 125 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
134 ide_set_max_pio(drive); 126 ide_set_max_pio(drive);
@@ -141,7 +133,7 @@ ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
141 ide_complete_power_step(drive, rq); 133 ide_complete_power_step(drive, rq);
142 return ide_stopped; 134 return ide_stopped;
143 case IDE_PM_IDLE: /* Resume step 2 (idle) */ 135 case IDE_PM_IDLE: /* Resume step 2 (idle) */
144 cmd->tf.command = ATA_CMD_IDLEIMMEDIATE; 136 cmd.tf.command = ATA_CMD_IDLEIMMEDIATE;
145 goto out_do_tf; 137 goto out_do_tf;
146 case IDE_PM_RESTORE_DMA: /* Resume step 3 (restore DMA) */ 138 case IDE_PM_RESTORE_DMA: /* Resume step 3 (restore DMA) */
147 /* 139 /*
@@ -163,11 +155,11 @@ ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
163 return ide_stopped; 155 return ide_stopped;
164 156
165out_do_tf: 157out_do_tf:
166 cmd->valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE; 158 cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
167 cmd->valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE; 159 cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
168 cmd->protocol = ATA_PROT_NODATA; 160 cmd.protocol = ATA_PROT_NODATA;
169 161
170 return do_rw_taskfile(drive, cmd); 162 return do_rw_taskfile(drive, &cmd);
171} 163}
172 164
173/** 165/**
@@ -181,7 +173,7 @@ out_do_tf:
181void ide_complete_pm_rq(ide_drive_t *drive, struct request *rq) 173void ide_complete_pm_rq(ide_drive_t *drive, struct request *rq)
182{ 174{
183 struct request_queue *q = drive->queue; 175 struct request_queue *q = drive->queue;
184 struct request_pm_state *pm = rq->data; 176 struct request_pm_state *pm = rq->special;
185 unsigned long flags; 177 unsigned long flags;
186 178
187 ide_complete_power_step(drive, rq); 179 ide_complete_power_step(drive, rq);
@@ -207,7 +199,7 @@ void ide_complete_pm_rq(ide_drive_t *drive, struct request *rq)
207 199
208void ide_check_pm_state(ide_drive_t *drive, struct request *rq) 200void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
209{ 201{
210 struct request_pm_state *pm = rq->data; 202 struct request_pm_state *pm = rq->special;
211 203
212 if (blk_pm_suspend_request(rq) && 204 if (blk_pm_suspend_request(rq) &&
213 pm->pm_step == IDE_PM_START_SUSPEND) 205 pm->pm_step == IDE_PM_START_SUSPEND)
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 3a53e0834cf7..d9764f0bc82f 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -131,13 +131,6 @@ enum {
131 IDETAPE_DIR_WRITE = (1 << 2), 131 IDETAPE_DIR_WRITE = (1 << 2),
132}; 132};
133 133
134struct idetape_bh {
135 u32 b_size;
136 atomic_t b_count;
137 struct idetape_bh *b_reqnext;
138 char *b_data;
139};
140
141/* Tape door status */ 134/* Tape door status */
142#define DOOR_UNLOCKED 0 135#define DOOR_UNLOCKED 0
143#define DOOR_LOCKED 1 136#define DOOR_LOCKED 1
@@ -219,18 +212,12 @@ typedef struct ide_tape_obj {
219 212
220 /* Data buffer size chosen based on the tape's recommendation */ 213 /* Data buffer size chosen based on the tape's recommendation */
221 int buffer_size; 214 int buffer_size;
222 /* merge buffer */ 215 /* Staging buffer of buffer_size bytes */
223 struct idetape_bh *merge_bh; 216 void *buf;
224 /* size of the merge buffer */ 217 /* The read/write cursor */
225 int merge_bh_size; 218 void *cur;
226 /* pointer to current buffer head within the merge buffer */ 219 /* The number of valid bytes in buf */
227 struct idetape_bh *bh; 220 size_t valid;
228 char *b_data;
229 int b_count;
230
231 int pages_per_buffer;
232 /* Wasted space in each stage */
233 int excess_bh_size;
234 221
235 /* Measures average tape speed */ 222 /* Measures average tape speed */
236 unsigned long avg_time; 223 unsigned long avg_time;
@@ -297,84 +284,6 @@ static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
297 return tape; 284 return tape;
298} 285}
299 286
300static int idetape_input_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
301 unsigned int bcount)
302{
303 struct idetape_bh *bh = pc->bh;
304 int count;
305
306 while (bcount) {
307 if (bh == NULL)
308 break;
309 count = min(
310 (unsigned int)(bh->b_size - atomic_read(&bh->b_count)),
311 bcount);
312 drive->hwif->tp_ops->input_data(drive, NULL, bh->b_data +
313 atomic_read(&bh->b_count), count);
314 bcount -= count;
315 atomic_add(count, &bh->b_count);
316 if (atomic_read(&bh->b_count) == bh->b_size) {
317 bh = bh->b_reqnext;
318 if (bh)
319 atomic_set(&bh->b_count, 0);
320 }
321 }
322
323 pc->bh = bh;
324
325 return bcount;
326}
327
328static int idetape_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
329 unsigned int bcount)
330{
331 struct idetape_bh *bh = pc->bh;
332 int count;
333
334 while (bcount) {
335 if (bh == NULL)
336 break;
337 count = min((unsigned int)pc->b_count, (unsigned int)bcount);
338 drive->hwif->tp_ops->output_data(drive, NULL, pc->b_data, count);
339 bcount -= count;
340 pc->b_data += count;
341 pc->b_count -= count;
342 if (!pc->b_count) {
343 bh = bh->b_reqnext;
344 pc->bh = bh;
345 if (bh) {
346 pc->b_data = bh->b_data;
347 pc->b_count = atomic_read(&bh->b_count);
348 }
349 }
350 }
351
352 return bcount;
353}
354
355static void idetape_update_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc)
356{
357 struct idetape_bh *bh = pc->bh;
358 int count;
359 unsigned int bcount = pc->xferred;
360
361 if (pc->flags & PC_FLAG_WRITING)
362 return;
363 while (bcount) {
364 if (bh == NULL) {
365 printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
366 __func__);
367 return;
368 }
369 count = min((unsigned int)bh->b_size, (unsigned int)bcount);
370 atomic_set(&bh->b_count, count);
371 if (atomic_read(&bh->b_count) == bh->b_size)
372 bh = bh->b_reqnext;
373 bcount -= count;
374 }
375 pc->bh = bh;
376}
377
378/* 287/*
379 * called on each failed packet command retry to analyze the request sense. We 288 * called on each failed packet command retry to analyze the request sense. We
380 * currently do not utilize this information. 289 * currently do not utilize this information.
@@ -392,12 +301,10 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
392 pc->c[0], tape->sense_key, tape->asc, tape->ascq); 301 pc->c[0], tape->sense_key, tape->asc, tape->ascq);
393 302
394 /* Correct pc->xferred by asking the tape. */ 303 /* Correct pc->xferred by asking the tape. */
395 if (pc->flags & PC_FLAG_DMA_ERROR) { 304 if (pc->flags & PC_FLAG_DMA_ERROR)
396 pc->xferred = pc->req_xfer - 305 pc->xferred = pc->req_xfer -
397 tape->blk_size * 306 tape->blk_size *
398 get_unaligned_be32(&sense[3]); 307 get_unaligned_be32(&sense[3]);
399 idetape_update_buffers(drive, pc);
400 }
401 308
402 /* 309 /*
403 * If error was the result of a zero-length read or write command, 310 * If error was the result of a zero-length read or write command,
@@ -436,29 +343,6 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
436 } 343 }
437} 344}
438 345
439/* Free data buffers completely. */
440static void ide_tape_kfree_buffer(idetape_tape_t *tape)
441{
442 struct idetape_bh *prev_bh, *bh = tape->merge_bh;
443
444 while (bh) {
445 u32 size = bh->b_size;
446
447 while (size) {
448 unsigned int order = fls(size >> PAGE_SHIFT)-1;
449
450 if (bh->b_data)
451 free_pages((unsigned long)bh->b_data, order);
452
453 size &= (order-1);
454 bh->b_data += (1 << order) * PAGE_SIZE;
455 }
456 prev_bh = bh;
457 bh = bh->b_reqnext;
458 kfree(prev_bh);
459 }
460}
461
462static void ide_tape_handle_dsc(ide_drive_t *); 346static void ide_tape_handle_dsc(ide_drive_t *);
463 347
464static int ide_tape_callback(ide_drive_t *drive, int dsc) 348static int ide_tape_callback(ide_drive_t *drive, int dsc)
@@ -496,7 +380,7 @@ static int ide_tape_callback(ide_drive_t *drive, int dsc)
496 } 380 }
497 381
498 tape->first_frame += blocks; 382 tape->first_frame += blocks;
499 rq->current_nr_sectors -= blocks; 383 rq->resid_len -= blocks * tape->blk_size;
500 384
501 if (pc->error) { 385 if (pc->error) {
502 uptodate = 0; 386 uptodate = 0;
@@ -558,19 +442,6 @@ static void ide_tape_handle_dsc(ide_drive_t *drive)
558 idetape_postpone_request(drive); 442 idetape_postpone_request(drive);
559} 443}
560 444
561static int ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
562 unsigned int bcount, int write)
563{
564 unsigned int bleft;
565
566 if (write)
567 bleft = idetape_output_buffers(drive, pc, bcount);
568 else
569 bleft = idetape_input_buffers(drive, pc, bcount);
570
571 return bcount - bleft;
572}
573
574/* 445/*
575 * Packet Command Interface 446 * Packet Command Interface
576 * 447 *
@@ -622,6 +493,8 @@ static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
622 493
623 if (pc->retries > IDETAPE_MAX_PC_RETRIES || 494 if (pc->retries > IDETAPE_MAX_PC_RETRIES ||
624 (pc->flags & PC_FLAG_ABORT)) { 495 (pc->flags & PC_FLAG_ABORT)) {
496 unsigned int done = blk_rq_bytes(drive->hwif->rq);
497
625 /* 498 /*
626 * We will "abort" retrying a packet command in case legitimate 499 * We will "abort" retrying a packet command in case legitimate
627 * error code was received (crossing a filemark, or end of the 500 * error code was received (crossing a filemark, or end of the
@@ -641,8 +514,10 @@ static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
641 /* Giving up */ 514 /* Giving up */
642 pc->error = IDE_DRV_ERROR_GENERAL; 515 pc->error = IDE_DRV_ERROR_GENERAL;
643 } 516 }
517
644 drive->failed_pc = NULL; 518 drive->failed_pc = NULL;
645 drive->pc_callback(drive, 0); 519 drive->pc_callback(drive, 0);
520 ide_complete_rq(drive, -EIO, done);
646 return ide_stopped; 521 return ide_stopped;
647 } 522 }
648 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]); 523 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
@@ -695,7 +570,7 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
695 printk(KERN_ERR "ide-tape: %s: I/O error, ", 570 printk(KERN_ERR "ide-tape: %s: I/O error, ",
696 tape->name); 571 tape->name);
697 /* Retry operation */ 572 /* Retry operation */
698 ide_retry_pc(drive, tape->disk); 573 ide_retry_pc(drive);
699 return ide_stopped; 574 return ide_stopped;
700 } 575 }
701 pc->error = 0; 576 pc->error = 0;
@@ -711,27 +586,22 @@ static void ide_tape_create_rw_cmd(idetape_tape_t *tape,
711 struct ide_atapi_pc *pc, struct request *rq, 586 struct ide_atapi_pc *pc, struct request *rq,
712 u8 opcode) 587 u8 opcode)
713{ 588{
714 struct idetape_bh *bh = (struct idetape_bh *)rq->special; 589 unsigned int length = blk_rq_sectors(rq);
715 unsigned int length = rq->current_nr_sectors;
716 590
717 ide_init_pc(pc); 591 ide_init_pc(pc);
718 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]); 592 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
719 pc->c[1] = 1; 593 pc->c[1] = 1;
720 pc->bh = bh;
721 pc->buf = NULL; 594 pc->buf = NULL;
722 pc->buf_size = length * tape->blk_size; 595 pc->buf_size = length * tape->blk_size;
723 pc->req_xfer = pc->buf_size; 596 pc->req_xfer = pc->buf_size;
724 if (pc->req_xfer == tape->buffer_size) 597 if (pc->req_xfer == tape->buffer_size)
725 pc->flags |= PC_FLAG_DMA_OK; 598 pc->flags |= PC_FLAG_DMA_OK;
726 599
727 if (opcode == READ_6) { 600 if (opcode == READ_6)
728 pc->c[0] = READ_6; 601 pc->c[0] = READ_6;
729 atomic_set(&bh->b_count, 0); 602 else if (opcode == WRITE_6) {
730 } else if (opcode == WRITE_6) {
731 pc->c[0] = WRITE_6; 603 pc->c[0] = WRITE_6;
732 pc->flags |= PC_FLAG_WRITING; 604 pc->flags |= PC_FLAG_WRITING;
733 pc->b_data = bh->b_data;
734 pc->b_count = atomic_read(&bh->b_count);
735 } 605 }
736 606
737 memcpy(rq->cmd, pc->c, 12); 607 memcpy(rq->cmd, pc->c, 12);
@@ -747,12 +617,10 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
747 struct ide_cmd cmd; 617 struct ide_cmd cmd;
748 u8 stat; 618 u8 stat;
749 619
750 debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %lu," 620 debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %u\n"
751 " current_nr_sectors: %u\n", 621 (unsigned long long)blk_rq_pos(rq), blk_rq_sectors(rq));
752 (unsigned long long)rq->sector, rq->nr_sectors,
753 rq->current_nr_sectors);
754 622
755 if (!blk_special_request(rq)) { 623 if (!(blk_special_request(rq) || blk_sense_request(rq))) {
756 /* We do not support buffer cache originated requests. */ 624 /* We do not support buffer cache originated requests. */
757 printk(KERN_NOTICE "ide-tape: %s: Unsupported request in " 625 printk(KERN_NOTICE "ide-tape: %s: Unsupported request in "
758 "request queue (%d)\n", drive->name, rq->cmd_type); 626 "request queue (%d)\n", drive->name, rq->cmd_type);
@@ -828,7 +696,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
828 goto out; 696 goto out;
829 } 697 }
830 if (rq->cmd[13] & REQ_IDETAPE_PC1) { 698 if (rq->cmd[13] & REQ_IDETAPE_PC1) {
831 pc = (struct ide_atapi_pc *) rq->buffer; 699 pc = (struct ide_atapi_pc *)rq->special;
832 rq->cmd[13] &= ~(REQ_IDETAPE_PC1); 700 rq->cmd[13] &= ~(REQ_IDETAPE_PC1);
833 rq->cmd[13] |= REQ_IDETAPE_PC2; 701 rq->cmd[13] |= REQ_IDETAPE_PC2;
834 goto out; 702 goto out;
@@ -840,6 +708,9 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
840 BUG(); 708 BUG();
841 709
842out: 710out:
711 /* prepare sense request for this command */
712 ide_prep_sense(drive, rq);
713
843 memset(&cmd, 0, sizeof(cmd)); 714 memset(&cmd, 0, sizeof(cmd));
844 715
845 if (rq_data_dir(rq)) 716 if (rq_data_dir(rq))
@@ -847,167 +718,10 @@ out:
847 718
848 cmd.rq = rq; 719 cmd.rq = rq;
849 720
850 return ide_tape_issue_pc(drive, &cmd, pc); 721 ide_init_sg_cmd(&cmd, pc->req_xfer);
851} 722 ide_map_sg(drive, &cmd);
852
853/*
854 * The function below uses __get_free_pages to allocate a data buffer of size
855 * tape->buffer_size (or a bit more). We attempt to combine sequential pages as
856 * much as possible.
857 *
858 * It returns a pointer to the newly allocated buffer, or NULL in case of
859 * failure.
860 */
861static struct idetape_bh *ide_tape_kmalloc_buffer(idetape_tape_t *tape,
862 int full, int clear)
863{
864 struct idetape_bh *prev_bh, *bh, *merge_bh;
865 int pages = tape->pages_per_buffer;
866 unsigned int order, b_allocd;
867 char *b_data = NULL;
868
869 merge_bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL);
870 bh = merge_bh;
871 if (bh == NULL)
872 goto abort;
873
874 order = fls(pages) - 1;
875 bh->b_data = (char *) __get_free_pages(GFP_KERNEL, order);
876 if (!bh->b_data)
877 goto abort;
878 b_allocd = (1 << order) * PAGE_SIZE;
879 pages &= (order-1);
880
881 if (clear)
882 memset(bh->b_data, 0, b_allocd);
883 bh->b_reqnext = NULL;
884 bh->b_size = b_allocd;
885 atomic_set(&bh->b_count, full ? bh->b_size : 0);
886
887 while (pages) {
888 order = fls(pages) - 1;
889 b_data = (char *) __get_free_pages(GFP_KERNEL, order);
890 if (!b_data)
891 goto abort;
892 b_allocd = (1 << order) * PAGE_SIZE;
893
894 if (clear)
895 memset(b_data, 0, b_allocd);
896
897 /* newly allocated page frames below buffer header or ...*/
898 if (bh->b_data == b_data + b_allocd) {
899 bh->b_size += b_allocd;
900 bh->b_data -= b_allocd;
901 if (full)
902 atomic_add(b_allocd, &bh->b_count);
903 continue;
904 }
905 /* they are above the header */
906 if (b_data == bh->b_data + bh->b_size) {
907 bh->b_size += b_allocd;
908 if (full)
909 atomic_add(b_allocd, &bh->b_count);
910 continue;
911 }
912 prev_bh = bh;
913 bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL);
914 if (!bh) {
915 free_pages((unsigned long) b_data, order);
916 goto abort;
917 }
918 bh->b_reqnext = NULL;
919 bh->b_data = b_data;
920 bh->b_size = b_allocd;
921 atomic_set(&bh->b_count, full ? bh->b_size : 0);
922 prev_bh->b_reqnext = bh;
923
924 pages &= (order-1);
925 }
926
927 bh->b_size -= tape->excess_bh_size;
928 if (full)
929 atomic_sub(tape->excess_bh_size, &bh->b_count);
930 return merge_bh;
931abort:
932 ide_tape_kfree_buffer(tape);
933 return NULL;
934}
935 723
936static int idetape_copy_stage_from_user(idetape_tape_t *tape, 724 return ide_tape_issue_pc(drive, &cmd, pc);
937 const char __user *buf, int n)
938{
939 struct idetape_bh *bh = tape->bh;
940 int count;
941 int ret = 0;
942
943 while (n) {
944 if (bh == NULL) {
945 printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
946 __func__);
947 return 1;
948 }
949 count = min((unsigned int)
950 (bh->b_size - atomic_read(&bh->b_count)),
951 (unsigned int)n);
952 if (copy_from_user(bh->b_data + atomic_read(&bh->b_count), buf,
953 count))
954 ret = 1;
955 n -= count;
956 atomic_add(count, &bh->b_count);
957 buf += count;
958 if (atomic_read(&bh->b_count) == bh->b_size) {
959 bh = bh->b_reqnext;
960 if (bh)
961 atomic_set(&bh->b_count, 0);
962 }
963 }
964 tape->bh = bh;
965 return ret;
966}
967
968static int idetape_copy_stage_to_user(idetape_tape_t *tape, char __user *buf,
969 int n)
970{
971 struct idetape_bh *bh = tape->bh;
972 int count;
973 int ret = 0;
974
975 while (n) {
976 if (bh == NULL) {
977 printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
978 __func__);
979 return 1;
980 }
981 count = min(tape->b_count, n);
982 if (copy_to_user(buf, tape->b_data, count))
983 ret = 1;
984 n -= count;
985 tape->b_data += count;
986 tape->b_count -= count;
987 buf += count;
988 if (!tape->b_count) {
989 bh = bh->b_reqnext;
990 tape->bh = bh;
991 if (bh) {
992 tape->b_data = bh->b_data;
993 tape->b_count = atomic_read(&bh->b_count);
994 }
995 }
996 }
997 return ret;
998}
999
1000static void idetape_init_merge_buffer(idetape_tape_t *tape)
1001{
1002 struct idetape_bh *bh = tape->merge_bh;
1003 tape->bh = tape->merge_bh;
1004
1005 if (tape->chrdev_dir == IDETAPE_DIR_WRITE)
1006 atomic_set(&bh->b_count, 0);
1007 else {
1008 tape->b_data = bh->b_data;
1009 tape->b_count = atomic_read(&bh->b_count);
1010 }
1011} 725}
1012 726
1013/* 727/*
@@ -1107,10 +821,10 @@ static void __ide_tape_discard_merge_buffer(ide_drive_t *drive)
1107 return; 821 return;
1108 822
1109 clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags); 823 clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags);
1110 tape->merge_bh_size = 0; 824 tape->valid = 0;
1111 if (tape->merge_bh != NULL) { 825 if (tape->buf != NULL) {
1112 ide_tape_kfree_buffer(tape); 826 kfree(tape->buf);
1113 tape->merge_bh = NULL; 827 tape->buf = NULL;
1114 } 828 }
1115 829
1116 tape->chrdev_dir = IDETAPE_DIR_NONE; 830 tape->chrdev_dir = IDETAPE_DIR_NONE;
@@ -1164,36 +878,44 @@ static void ide_tape_discard_merge_buffer(ide_drive_t *drive,
1164 * Generate a read/write request for the block device interface and wait for it 878 * Generate a read/write request for the block device interface and wait for it
1165 * to be serviced. 879 * to be serviced.
1166 */ 880 */
1167static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks, 881static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int size)
1168 struct idetape_bh *bh)
1169{ 882{
1170 idetape_tape_t *tape = drive->driver_data; 883 idetape_tape_t *tape = drive->driver_data;
1171 struct request *rq; 884 struct request *rq;
1172 int ret, errors; 885 int ret;
1173 886
1174 debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd); 887 debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd);
888 BUG_ON(cmd != REQ_IDETAPE_READ && cmd != REQ_IDETAPE_WRITE);
889 BUG_ON(size < 0 || size % tape->blk_size);
1175 890
1176 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 891 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
1177 rq->cmd_type = REQ_TYPE_SPECIAL; 892 rq->cmd_type = REQ_TYPE_SPECIAL;
1178 rq->cmd[13] = cmd; 893 rq->cmd[13] = cmd;
1179 rq->rq_disk = tape->disk; 894 rq->rq_disk = tape->disk;
1180 rq->special = (void *)bh; 895 rq->__sector = tape->first_frame;
1181 rq->sector = tape->first_frame;
1182 rq->nr_sectors = blocks;
1183 rq->current_nr_sectors = blocks;
1184 blk_execute_rq(drive->queue, tape->disk, rq, 0);
1185 896
1186 errors = rq->errors; 897 if (size) {
1187 ret = tape->blk_size * (blocks - rq->current_nr_sectors); 898 ret = blk_rq_map_kern(drive->queue, rq, tape->buf, size,
1188 blk_put_request(rq); 899 __GFP_WAIT);
900 if (ret)
901 goto out_put;
902 }
1189 903
1190 if ((cmd & (REQ_IDETAPE_READ | REQ_IDETAPE_WRITE)) == 0) 904 blk_execute_rq(drive->queue, tape->disk, rq, 0);
1191 return 0;
1192 905
1193 if (tape->merge_bh) 906 /* calculate the number of transferred bytes and update buffer state */
1194 idetape_init_merge_buffer(tape); 907 size -= rq->resid_len;
1195 if (errors == IDE_DRV_ERROR_GENERAL) 908 tape->cur = tape->buf;
1196 return -EIO; 909 if (cmd == REQ_IDETAPE_READ)
910 tape->valid = size;
911 else
912 tape->valid = 0;
913
914 ret = size;
915 if (rq->errors == IDE_DRV_ERROR_GENERAL)
916 ret = -EIO;
917out_put:
918 blk_put_request(rq);
1197 return ret; 919 return ret;
1198} 920}
1199 921
@@ -1230,153 +952,87 @@ static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
1230 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 952 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1231} 953}
1232 954
1233/* Queue up a character device originated write request. */
1234static int idetape_add_chrdev_write_request(ide_drive_t *drive, int blocks)
1235{
1236 idetape_tape_t *tape = drive->driver_data;
1237
1238 debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
1239
1240 return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE,
1241 blocks, tape->merge_bh);
1242}
1243
1244static void ide_tape_flush_merge_buffer(ide_drive_t *drive) 955static void ide_tape_flush_merge_buffer(ide_drive_t *drive)
1245{ 956{
1246 idetape_tape_t *tape = drive->driver_data; 957 idetape_tape_t *tape = drive->driver_data;
1247 int blocks, min;
1248 struct idetape_bh *bh;
1249 958
1250 if (tape->chrdev_dir != IDETAPE_DIR_WRITE) { 959 if (tape->chrdev_dir != IDETAPE_DIR_WRITE) {
1251 printk(KERN_ERR "ide-tape: bug: Trying to empty merge buffer" 960 printk(KERN_ERR "ide-tape: bug: Trying to empty merge buffer"
1252 " but we are not writing.\n"); 961 " but we are not writing.\n");
1253 return; 962 return;
1254 } 963 }
1255 if (tape->merge_bh_size > tape->buffer_size) { 964 if (tape->buf) {
1256 printk(KERN_ERR "ide-tape: bug: merge_buffer too big\n"); 965 size_t aligned = roundup(tape->valid, tape->blk_size);
1257 tape->merge_bh_size = tape->buffer_size; 966
1258 } 967 memset(tape->cur, 0, aligned - tape->valid);
1259 if (tape->merge_bh_size) { 968 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, aligned);
1260 blocks = tape->merge_bh_size / tape->blk_size; 969 kfree(tape->buf);
1261 if (tape->merge_bh_size % tape->blk_size) { 970 tape->buf = NULL;
1262 unsigned int i;
1263
1264 blocks++;
1265 i = tape->blk_size - tape->merge_bh_size %
1266 tape->blk_size;
1267 bh = tape->bh->b_reqnext;
1268 while (bh) {
1269 atomic_set(&bh->b_count, 0);
1270 bh = bh->b_reqnext;
1271 }
1272 bh = tape->bh;
1273 while (i) {
1274 if (bh == NULL) {
1275 printk(KERN_INFO "ide-tape: bug,"
1276 " bh NULL\n");
1277 break;
1278 }
1279 min = min(i, (unsigned int)(bh->b_size -
1280 atomic_read(&bh->b_count)));
1281 memset(bh->b_data + atomic_read(&bh->b_count),
1282 0, min);
1283 atomic_add(min, &bh->b_count);
1284 i -= min;
1285 bh = bh->b_reqnext;
1286 }
1287 }
1288 (void) idetape_add_chrdev_write_request(drive, blocks);
1289 tape->merge_bh_size = 0;
1290 }
1291 if (tape->merge_bh != NULL) {
1292 ide_tape_kfree_buffer(tape);
1293 tape->merge_bh = NULL;
1294 } 971 }
1295 tape->chrdev_dir = IDETAPE_DIR_NONE; 972 tape->chrdev_dir = IDETAPE_DIR_NONE;
1296} 973}
1297 974
1298static int idetape_init_read(ide_drive_t *drive) 975static int idetape_init_rw(ide_drive_t *drive, int dir)
1299{ 976{
1300 idetape_tape_t *tape = drive->driver_data; 977 idetape_tape_t *tape = drive->driver_data;
1301 int bytes_read; 978 int rc;
1302 979
1303 /* Initialize read operation */ 980 BUG_ON(dir != IDETAPE_DIR_READ && dir != IDETAPE_DIR_WRITE);
1304 if (tape->chrdev_dir != IDETAPE_DIR_READ) {
1305 if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
1306 ide_tape_flush_merge_buffer(drive);
1307 idetape_flush_tape_buffers(drive);
1308 }
1309 if (tape->merge_bh || tape->merge_bh_size) {
1310 printk(KERN_ERR "ide-tape: merge_bh_size should be"
1311 " 0 now\n");
1312 tape->merge_bh_size = 0;
1313 }
1314 tape->merge_bh = ide_tape_kmalloc_buffer(tape, 0, 0);
1315 if (!tape->merge_bh)
1316 return -ENOMEM;
1317 tape->chrdev_dir = IDETAPE_DIR_READ;
1318 981
1319 /* 982 if (tape->chrdev_dir == dir)
1320 * Issue a read 0 command to ensure that DSC handshake is 983 return 0;
1321 * switched from completion mode to buffer available mode.
1322 * No point in issuing this if DSC overlap isn't supported, some
1323 * drives (Seagate STT3401A) will return an error.
1324 */
1325 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
1326 bytes_read = idetape_queue_rw_tail(drive,
1327 REQ_IDETAPE_READ, 0,
1328 tape->merge_bh);
1329 if (bytes_read < 0) {
1330 ide_tape_kfree_buffer(tape);
1331 tape->merge_bh = NULL;
1332 tape->chrdev_dir = IDETAPE_DIR_NONE;
1333 return bytes_read;
1334 }
1335 }
1336 }
1337 984
1338 return 0; 985 if (tape->chrdev_dir == IDETAPE_DIR_READ)
1339} 986 ide_tape_discard_merge_buffer(drive, 1);
987 else if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
988 ide_tape_flush_merge_buffer(drive);
989 idetape_flush_tape_buffers(drive);
990 }
1340 991
1341/* called from idetape_chrdev_read() to service a chrdev read request. */ 992 if (tape->buf || tape->valid) {
1342static int idetape_add_chrdev_read_request(ide_drive_t *drive, int blocks) 993 printk(KERN_ERR "ide-tape: valid should be 0 now\n");
1343{ 994 tape->valid = 0;
1344 idetape_tape_t *tape = drive->driver_data; 995 }
1345 996
1346 debug_log(DBG_PROCS, "Enter %s, %d blocks\n", __func__, blocks); 997 tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL);
998 if (!tape->buf)
999 return -ENOMEM;
1000 tape->chrdev_dir = dir;
1001 tape->cur = tape->buf;
1347 1002
1348 /* If we are at a filemark, return a read length of 0 */ 1003 /*
1349 if (test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags)) 1004 * Issue a 0 rw command to ensure that DSC handshake is
1350 return 0; 1005 * switched from completion mode to buffer available mode. No
1351 1006 * point in issuing this if DSC overlap isn't supported, some
1352 idetape_init_read(drive); 1007 * drives (Seagate STT3401A) will return an error.
1008 */
1009 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
1010 int cmd = dir == IDETAPE_DIR_READ ? REQ_IDETAPE_READ
1011 : REQ_IDETAPE_WRITE;
1012
1013 rc = idetape_queue_rw_tail(drive, cmd, 0);
1014 if (rc < 0) {
1015 kfree(tape->buf);
1016 tape->buf = NULL;
1017 tape->chrdev_dir = IDETAPE_DIR_NONE;
1018 return rc;
1019 }
1020 }
1353 1021
1354 return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks, 1022 return 0;
1355 tape->merge_bh);
1356} 1023}
1357 1024
1358static void idetape_pad_zeros(ide_drive_t *drive, int bcount) 1025static void idetape_pad_zeros(ide_drive_t *drive, int bcount)
1359{ 1026{
1360 idetape_tape_t *tape = drive->driver_data; 1027 idetape_tape_t *tape = drive->driver_data;
1361 struct idetape_bh *bh; 1028
1362 int blocks; 1029 memset(tape->buf, 0, tape->buffer_size);
1363 1030
1364 while (bcount) { 1031 while (bcount) {
1365 unsigned int count; 1032 unsigned int count = min(tape->buffer_size, bcount);
1366 1033
1367 bh = tape->merge_bh; 1034 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, count);
1368 count = min(tape->buffer_size, bcount);
1369 bcount -= count; 1035 bcount -= count;
1370 blocks = count / tape->blk_size;
1371 while (count) {
1372 atomic_set(&bh->b_count,
1373 min(count, (unsigned int)bh->b_size));
1374 memset(bh->b_data, 0, atomic_read(&bh->b_count));
1375 count -= atomic_read(&bh->b_count);
1376 bh = bh->b_reqnext;
1377 }
1378 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks,
1379 tape->merge_bh);
1380 } 1036 }
1381} 1037}
1382 1038
@@ -1456,7 +1112,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
1456 } 1112 }
1457 1113
1458 if (tape->chrdev_dir == IDETAPE_DIR_READ) { 1114 if (tape->chrdev_dir == IDETAPE_DIR_READ) {
1459 tape->merge_bh_size = 0; 1115 tape->valid = 0;
1460 if (test_and_clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags)) 1116 if (test_and_clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags))
1461 ++count; 1117 ++count;
1462 ide_tape_discard_merge_buffer(drive, 0); 1118 ide_tape_discard_merge_buffer(drive, 0);
@@ -1505,9 +1161,9 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
1505{ 1161{
1506 struct ide_tape_obj *tape = file->private_data; 1162 struct ide_tape_obj *tape = file->private_data;
1507 ide_drive_t *drive = tape->drive; 1163 ide_drive_t *drive = tape->drive;
1508 ssize_t bytes_read, temp, actually_read = 0, rc; 1164 size_t done = 0;
1509 ssize_t ret = 0; 1165 ssize_t ret = 0;
1510 u16 ctl = *(u16 *)&tape->caps[12]; 1166 int rc;
1511 1167
1512 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count); 1168 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
1513 1169
@@ -1517,49 +1173,43 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
1517 (count % tape->blk_size) == 0) 1173 (count % tape->blk_size) == 0)
1518 tape->user_bs_factor = count / tape->blk_size; 1174 tape->user_bs_factor = count / tape->blk_size;
1519 } 1175 }
1520 rc = idetape_init_read(drive); 1176
1177 rc = idetape_init_rw(drive, IDETAPE_DIR_READ);
1521 if (rc < 0) 1178 if (rc < 0)
1522 return rc; 1179 return rc;
1523 if (count == 0) 1180
1524 return (0); 1181 while (done < count) {
1525 if (tape->merge_bh_size) { 1182 size_t todo;
1526 actually_read = min((unsigned int)(tape->merge_bh_size), 1183
1527 (unsigned int)count); 1184 /* refill if staging buffer is empty */
1528 if (idetape_copy_stage_to_user(tape, buf, actually_read)) 1185 if (!tape->valid) {
1529 ret = -EFAULT; 1186 /* If we are at a filemark, nothing more to read */
1530 buf += actually_read; 1187 if (test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags))
1531 tape->merge_bh_size -= actually_read; 1188 break;
1532 count -= actually_read; 1189 /* read */
1533 } 1190 if (idetape_queue_rw_tail(drive, REQ_IDETAPE_READ,
1534 while (count >= tape->buffer_size) { 1191 tape->buffer_size) <= 0)
1535 bytes_read = idetape_add_chrdev_read_request(drive, ctl); 1192 break;
1536 if (bytes_read <= 0) 1193 }
1537 goto finish; 1194
1538 if (idetape_copy_stage_to_user(tape, buf, bytes_read)) 1195 /* copy out */
1539 ret = -EFAULT; 1196 todo = min_t(size_t, count - done, tape->valid);
1540 buf += bytes_read; 1197 if (copy_to_user(buf + done, tape->cur, todo))
1541 count -= bytes_read;
1542 actually_read += bytes_read;
1543 }
1544 if (count) {
1545 bytes_read = idetape_add_chrdev_read_request(drive, ctl);
1546 if (bytes_read <= 0)
1547 goto finish;
1548 temp = min((unsigned long)count, (unsigned long)bytes_read);
1549 if (idetape_copy_stage_to_user(tape, buf, temp))
1550 ret = -EFAULT; 1198 ret = -EFAULT;
1551 actually_read += temp; 1199
1552 tape->merge_bh_size = bytes_read-temp; 1200 tape->cur += todo;
1201 tape->valid -= todo;
1202 done += todo;
1553 } 1203 }
1554finish: 1204
1555 if (!actually_read && test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags)) { 1205 if (!done && test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags)) {
1556 debug_log(DBG_SENSE, "%s: spacing over filemark\n", tape->name); 1206 debug_log(DBG_SENSE, "%s: spacing over filemark\n", tape->name);
1557 1207
1558 idetape_space_over_filemarks(drive, MTFSF, 1); 1208 idetape_space_over_filemarks(drive, MTFSF, 1);
1559 return 0; 1209 return 0;
1560 } 1210 }
1561 1211
1562 return ret ? ret : actually_read; 1212 return ret ? ret : done;
1563} 1213}
1564 1214
1565static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf, 1215static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
@@ -1567,9 +1217,9 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1567{ 1217{
1568 struct ide_tape_obj *tape = file->private_data; 1218 struct ide_tape_obj *tape = file->private_data;
1569 ide_drive_t *drive = tape->drive; 1219 ide_drive_t *drive = tape->drive;
1570 ssize_t actually_written = 0; 1220 size_t done = 0;
1571 ssize_t ret = 0; 1221 ssize_t ret = 0;
1572 u16 ctl = *(u16 *)&tape->caps[12]; 1222 int rc;
1573 1223
1574 /* The drive is write protected. */ 1224 /* The drive is write protected. */
1575 if (tape->write_prot) 1225 if (tape->write_prot)
@@ -1578,80 +1228,31 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1578 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count); 1228 debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
1579 1229
1580 /* Initialize write operation */ 1230 /* Initialize write operation */
1581 if (tape->chrdev_dir != IDETAPE_DIR_WRITE) { 1231 rc = idetape_init_rw(drive, IDETAPE_DIR_WRITE);
1582 if (tape->chrdev_dir == IDETAPE_DIR_READ) 1232 if (rc < 0)
1583 ide_tape_discard_merge_buffer(drive, 1); 1233 return rc;
1584 if (tape->merge_bh || tape->merge_bh_size) {
1585 printk(KERN_ERR "ide-tape: merge_bh_size "
1586 "should be 0 now\n");
1587 tape->merge_bh_size = 0;
1588 }
1589 tape->merge_bh = ide_tape_kmalloc_buffer(tape, 0, 0);
1590 if (!tape->merge_bh)
1591 return -ENOMEM;
1592 tape->chrdev_dir = IDETAPE_DIR_WRITE;
1593 idetape_init_merge_buffer(tape);
1594 1234
1595 /* 1235 while (done < count) {
1596 * Issue a write 0 command to ensure that DSC handshake is 1236 size_t todo;
1597 * switched from completion mode to buffer available mode. No 1237
1598 * point in issuing this if DSC overlap isn't supported, some 1238 /* flush if staging buffer is full */
1599 * drives (Seagate STT3401A) will return an error. 1239 if (tape->valid == tape->buffer_size &&
1600 */ 1240 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE,
1601 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) { 1241 tape->buffer_size) <= 0)
1602 ssize_t retval = idetape_queue_rw_tail(drive, 1242 return rc;
1603 REQ_IDETAPE_WRITE, 0, 1243
1604 tape->merge_bh); 1244 /* copy in */
1605 if (retval < 0) { 1245 todo = min_t(size_t, count - done,
1606 ide_tape_kfree_buffer(tape); 1246 tape->buffer_size - tape->valid);
1607 tape->merge_bh = NULL; 1247 if (copy_from_user(tape->cur, buf + done, todo))
1608 tape->chrdev_dir = IDETAPE_DIR_NONE;
1609 return retval;
1610 }
1611 }
1612 }
1613 if (count == 0)
1614 return (0);
1615 if (tape->merge_bh_size) {
1616 if (tape->merge_bh_size >= tape->buffer_size) {
1617 printk(KERN_ERR "ide-tape: bug: merge buf too big\n");
1618 tape->merge_bh_size = 0;
1619 }
1620 actually_written = min((unsigned int)
1621 (tape->buffer_size - tape->merge_bh_size),
1622 (unsigned int)count);
1623 if (idetape_copy_stage_from_user(tape, buf, actually_written))
1624 ret = -EFAULT;
1625 buf += actually_written;
1626 tape->merge_bh_size += actually_written;
1627 count -= actually_written;
1628
1629 if (tape->merge_bh_size == tape->buffer_size) {
1630 ssize_t retval;
1631 tape->merge_bh_size = 0;
1632 retval = idetape_add_chrdev_write_request(drive, ctl);
1633 if (retval <= 0)
1634 return (retval);
1635 }
1636 }
1637 while (count >= tape->buffer_size) {
1638 ssize_t retval;
1639 if (idetape_copy_stage_from_user(tape, buf, tape->buffer_size))
1640 ret = -EFAULT;
1641 buf += tape->buffer_size;
1642 count -= tape->buffer_size;
1643 retval = idetape_add_chrdev_write_request(drive, ctl);
1644 actually_written += tape->buffer_size;
1645 if (retval <= 0)
1646 return (retval);
1647 }
1648 if (count) {
1649 actually_written += count;
1650 if (idetape_copy_stage_from_user(tape, buf, count))
1651 ret = -EFAULT; 1248 ret = -EFAULT;
1652 tape->merge_bh_size += count; 1249
1250 tape->cur += todo;
1251 tape->valid += todo;
1252 done += todo;
1653 } 1253 }
1654 return ret ? ret : actually_written; 1254
1255 return ret ? ret : done;
1655} 1256}
1656 1257
1657static int idetape_write_filemark(ide_drive_t *drive) 1258static int idetape_write_filemark(ide_drive_t *drive)
@@ -1812,7 +1413,7 @@ static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
1812 idetape_flush_tape_buffers(drive); 1413 idetape_flush_tape_buffers(drive);
1813 } 1414 }
1814 if (cmd == MTIOCGET || cmd == MTIOCPOS) { 1415 if (cmd == MTIOCGET || cmd == MTIOCPOS) {
1815 block_offset = tape->merge_bh_size / 1416 block_offset = tape->valid /
1816 (tape->blk_size * tape->user_bs_factor); 1417 (tape->blk_size * tape->user_bs_factor);
1817 position = idetape_read_position(drive); 1418 position = idetape_read_position(drive);
1818 if (position < 0) 1419 if (position < 0)
@@ -1960,12 +1561,12 @@ static void idetape_write_release(ide_drive_t *drive, unsigned int minor)
1960 idetape_tape_t *tape = drive->driver_data; 1561 idetape_tape_t *tape = drive->driver_data;
1961 1562
1962 ide_tape_flush_merge_buffer(drive); 1563 ide_tape_flush_merge_buffer(drive);
1963 tape->merge_bh = ide_tape_kmalloc_buffer(tape, 1, 0); 1564 tape->buf = kmalloc(tape->buffer_size, GFP_KERNEL);
1964 if (tape->merge_bh != NULL) { 1565 if (tape->buf != NULL) {
1965 idetape_pad_zeros(drive, tape->blk_size * 1566 idetape_pad_zeros(drive, tape->blk_size *
1966 (tape->user_bs_factor - 1)); 1567 (tape->user_bs_factor - 1));
1967 ide_tape_kfree_buffer(tape); 1568 kfree(tape->buf);
1968 tape->merge_bh = NULL; 1569 tape->buf = NULL;
1969 } 1570 }
1970 idetape_write_filemark(drive); 1571 idetape_write_filemark(drive);
1971 idetape_flush_tape_buffers(drive); 1572 idetape_flush_tape_buffers(drive);
@@ -2159,8 +1760,6 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2159 u16 *ctl = (u16 *)&tape->caps[12]; 1760 u16 *ctl = (u16 *)&tape->caps[12];
2160 1761
2161 drive->pc_callback = ide_tape_callback; 1762 drive->pc_callback = ide_tape_callback;
2162 drive->pc_update_buffers = idetape_update_buffers;
2163 drive->pc_io_buffers = ide_tape_io_buffers;
2164 1763
2165 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP; 1764 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
2166 1765
@@ -2191,11 +1790,6 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2191 tape->buffer_size = *ctl * tape->blk_size; 1790 tape->buffer_size = *ctl * tape->blk_size;
2192 } 1791 }
2193 buffer_size = tape->buffer_size; 1792 buffer_size = tape->buffer_size;
2194 tape->pages_per_buffer = buffer_size / PAGE_SIZE;
2195 if (buffer_size % PAGE_SIZE) {
2196 tape->pages_per_buffer++;
2197 tape->excess_bh_size = PAGE_SIZE - buffer_size % PAGE_SIZE;
2198 }
2199 1793
2200 /* select the "best" DSC read/write polling freq */ 1794 /* select the "best" DSC read/write polling freq */
2201 speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]); 1795 speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]);
@@ -2238,7 +1832,7 @@ static void ide_tape_release(struct device *dev)
2238 ide_drive_t *drive = tape->drive; 1832 ide_drive_t *drive = tape->drive;
2239 struct gendisk *g = tape->disk; 1833 struct gendisk *g = tape->disk;
2240 1834
2241 BUG_ON(tape->merge_bh_size); 1835 BUG_ON(tape->valid);
2242 1836
2243 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP; 1837 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2244 drive->driver_data = NULL; 1838 drive->driver_data = NULL;
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 4aa6223c11be..a0c3e1b2f73c 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -385,7 +385,7 @@ out_end:
385 if ((cmd->tf_flags & IDE_TFLAG_FS) == 0) 385 if ((cmd->tf_flags & IDE_TFLAG_FS) == 0)
386 ide_finish_cmd(drive, cmd, stat); 386 ide_finish_cmd(drive, cmd, stat);
387 else 387 else
388 ide_complete_rq(drive, 0, cmd->rq->nr_sectors << 9); 388 ide_complete_rq(drive, 0, blk_rq_sectors(cmd->rq) << 9);
389 return ide_stopped; 389 return ide_stopped;
390out_err: 390out_err:
391 ide_error_cmd(drive, cmd); 391 ide_error_cmd(drive, cmd);
@@ -424,7 +424,9 @@ int ide_raw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd, u8 *buf,
424 424
425 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 425 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
426 rq->cmd_type = REQ_TYPE_ATA_TASKFILE; 426 rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
427 rq->buffer = buf; 427
428 if (cmd->tf_flags & IDE_TFLAG_WRITE)
429 rq->cmd_flags |= REQ_RW;
428 430
429 /* 431 /*
430 * (ks) We transfer currently only whole sectors. 432 * (ks) We transfer currently only whole sectors.
@@ -432,18 +434,20 @@ int ide_raw_taskfile(ide_drive_t *drive, struct ide_cmd *cmd, u8 *buf,
432 * if we would find a solution to transfer any size. 434 * if we would find a solution to transfer any size.
433 * To support special commands like READ LONG. 435 * To support special commands like READ LONG.
434 */ 436 */
435 rq->hard_nr_sectors = rq->nr_sectors = nsect; 437 if (nsect) {
436 rq->hard_cur_sectors = rq->current_nr_sectors = nsect; 438 error = blk_rq_map_kern(drive->queue, rq, buf,
437 439 nsect * SECTOR_SIZE, __GFP_WAIT);
438 if (cmd->tf_flags & IDE_TFLAG_WRITE) 440 if (error)
439 rq->cmd_flags |= REQ_RW; 441 goto put_req;
442 }
440 443
441 rq->special = cmd; 444 rq->special = cmd;
442 cmd->rq = rq; 445 cmd->rq = rq;
443 446
444 error = blk_execute_rq(drive->queue, NULL, rq, 0); 447 error = blk_execute_rq(drive->queue, NULL, rq, 0);
445 blk_put_request(rq);
446 448
449put_req:
450 blk_put_request(rq);
447 return error; 451 return error;
448} 452}
449 453
diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
index b3bc96f930a6..e24ecc87a9b1 100644
--- a/drivers/ide/pdc202xx_old.c
+++ b/drivers/ide/pdc202xx_old.c
@@ -177,7 +177,7 @@ static void pdc202xx_dma_start(ide_drive_t *drive)
177 u8 clock = inb(high_16 + 0x11); 177 u8 clock = inb(high_16 + 0x11);
178 178
179 outb(clock | (hwif->channel ? 0x08 : 0x02), high_16 + 0x11); 179 outb(clock | (hwif->channel ? 0x08 : 0x02), high_16 + 0x11);
180 word_count = (rq->nr_sectors << 8); 180 word_count = (blk_rq_sectors(rq) << 8);
181 word_count = (rq_data_dir(rq) == READ) ? 181 word_count = (rq_data_dir(rq) == READ) ?
182 word_count | 0x05000000 : 182 word_count | 0x05000000 :
183 word_count | 0x06000000; 183 word_count | 0x06000000;
diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
index b4cf42dc8a6f..05a93d6baecc 100644
--- a/drivers/ide/tc86c001.c
+++ b/drivers/ide/tc86c001.c
@@ -112,7 +112,7 @@ static void tc86c001_dma_start(ide_drive_t *drive)
112 ide_hwif_t *hwif = drive->hwif; 112 ide_hwif_t *hwif = drive->hwif;
113 unsigned long sc_base = hwif->config_data; 113 unsigned long sc_base = hwif->config_data;
114 unsigned long twcr_port = sc_base + (drive->dn ? 0x06 : 0x04); 114 unsigned long twcr_port = sc_base + (drive->dn ? 0x06 : 0x04);
115 unsigned long nsectors = hwif->rq->nr_sectors; 115 unsigned long nsectors = blk_rq_sectors(hwif->rq);
116 116
117 /* 117 /*
118 * We have to manually load the sector count and size into 118 * We have to manually load the sector count and size into
diff --git a/drivers/ide/tx4939ide.c b/drivers/ide/tx4939ide.c
index 564422d23976..5ca76224f6d1 100644
--- a/drivers/ide/tx4939ide.c
+++ b/drivers/ide/tx4939ide.c
@@ -307,7 +307,7 @@ static int tx4939ide_dma_setup(ide_drive_t *drive, struct ide_cmd *cmd)
307 tx4939ide_writew(SECTOR_SIZE / 2, base, drive->dn ? 307 tx4939ide_writew(SECTOR_SIZE / 2, base, drive->dn ?
308 TX4939IDE_Xfer_Cnt_2 : TX4939IDE_Xfer_Cnt_1); 308 TX4939IDE_Xfer_Cnt_2 : TX4939IDE_Xfer_Cnt_1);
309 309
310 tx4939ide_writew(cmd->rq->nr_sectors, base, TX4939IDE_Sec_Cnt); 310 tx4939ide_writew(blk_rq_sectors(cmd->rq), base, TX4939IDE_Sec_Cnt);
311 311
312 return 0; 312 return 0;
313} 313}
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 56df1cee8fb3..3319c2fec28e 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -232,7 +232,7 @@ static struct page *read_sb_page(mddev_t *mddev, long offset,
232 target = rdev->sb_start + offset + index * (PAGE_SIZE/512); 232 target = rdev->sb_start + offset + index * (PAGE_SIZE/512);
233 233
234 if (sync_page_io(rdev->bdev, target, 234 if (sync_page_io(rdev->bdev, target,
235 roundup(size, bdev_hardsect_size(rdev->bdev)), 235 roundup(size, bdev_logical_block_size(rdev->bdev)),
236 page, READ)) { 236 page, READ)) {
237 page->index = index; 237 page->index = index;
238 attach_page_buffers(page, NULL); /* so that free_buffer will 238 attach_page_buffers(page, NULL); /* so that free_buffer will
@@ -287,7 +287,7 @@ static int write_sb_page(struct bitmap *bitmap, struct page *page, int wait)
287 int size = PAGE_SIZE; 287 int size = PAGE_SIZE;
288 if (page->index == bitmap->file_pages-1) 288 if (page->index == bitmap->file_pages-1)
289 size = roundup(bitmap->last_page_size, 289 size = roundup(bitmap->last_page_size,
290 bdev_hardsect_size(rdev->bdev)); 290 bdev_logical_block_size(rdev->bdev));
291 /* Just make sure we aren't corrupting data or 291 /* Just make sure we aren't corrupting data or
292 * metadata 292 * metadata
293 */ 293 */
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c
index a2e26c242141..75d8081a9041 100644
--- a/drivers/md/dm-exception-store.c
+++ b/drivers/md/dm-exception-store.c
@@ -178,7 +178,7 @@ static int set_chunk_size(struct dm_exception_store *store,
178 } 178 }
179 179
180 /* Validate the chunk size against the device block size */ 180 /* Validate the chunk size against the device block size */
181 if (chunk_size_ulong % (bdev_hardsect_size(store->cow->bdev) >> 9)) { 181 if (chunk_size_ulong % (bdev_logical_block_size(store->cow->bdev) >> 9)) {
182 *error = "Chunk size is not a multiple of device blocksize"; 182 *error = "Chunk size is not a multiple of device blocksize";
183 return -EINVAL; 183 return -EINVAL;
184 } 184 }
diff --git a/drivers/md/dm-log.c b/drivers/md/dm-log.c
index be233bc4d917..6fa8ccf91c70 100644
--- a/drivers/md/dm-log.c
+++ b/drivers/md/dm-log.c
@@ -413,7 +413,8 @@ static int create_log_context(struct dm_dirty_log *log, struct dm_target *ti,
413 * Buffer holds both header and bitset. 413 * Buffer holds both header and bitset.
414 */ 414 */
415 buf_size = dm_round_up((LOG_OFFSET << SECTOR_SHIFT) + 415 buf_size = dm_round_up((LOG_OFFSET << SECTOR_SHIFT) +
416 bitset_size, ti->limits.hardsect_size); 416 bitset_size,
417 ti->limits.logical_block_size);
417 418
418 if (buf_size > dev->bdev->bd_inode->i_size) { 419 if (buf_size > dev->bdev->bd_inode->i_size) {
419 DMWARN("log device %s too small: need %llu bytes", 420 DMWARN("log device %s too small: need %llu bytes",
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c
index e75c6dd76a9a..2662a41337e7 100644
--- a/drivers/md/dm-snap-persistent.c
+++ b/drivers/md/dm-snap-persistent.c
@@ -282,7 +282,7 @@ static int read_header(struct pstore *ps, int *new_snapshot)
282 */ 282 */
283 if (!ps->store->chunk_size) { 283 if (!ps->store->chunk_size) {
284 ps->store->chunk_size = max(DM_CHUNK_SIZE_DEFAULT_SECTORS, 284 ps->store->chunk_size = max(DM_CHUNK_SIZE_DEFAULT_SECTORS,
285 bdev_hardsect_size(ps->store->cow->bdev) >> 9); 285 bdev_logical_block_size(ps->store->cow->bdev) >> 9);
286 ps->store->chunk_mask = ps->store->chunk_size - 1; 286 ps->store->chunk_mask = ps->store->chunk_size - 1;
287 ps->store->chunk_shift = ffs(ps->store->chunk_size) - 1; 287 ps->store->chunk_shift = ffs(ps->store->chunk_size) - 1;
288 chunk_size_supplied = 0; 288 chunk_size_supplied = 0;
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 429b50b975d5..e9a73bb242b0 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -108,7 +108,8 @@ static void combine_restrictions_low(struct io_restrictions *lhs,
108 lhs->max_hw_segments = 108 lhs->max_hw_segments =
109 min_not_zero(lhs->max_hw_segments, rhs->max_hw_segments); 109 min_not_zero(lhs->max_hw_segments, rhs->max_hw_segments);
110 110
111 lhs->hardsect_size = max(lhs->hardsect_size, rhs->hardsect_size); 111 lhs->logical_block_size = max(lhs->logical_block_size,
112 rhs->logical_block_size);
112 113
113 lhs->max_segment_size = 114 lhs->max_segment_size =
114 min_not_zero(lhs->max_segment_size, rhs->max_segment_size); 115 min_not_zero(lhs->max_segment_size, rhs->max_segment_size);
@@ -509,7 +510,7 @@ void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev)
509 * combine_restrictions_low() 510 * combine_restrictions_low()
510 */ 511 */
511 rs->max_sectors = 512 rs->max_sectors =
512 min_not_zero(rs->max_sectors, q->max_sectors); 513 min_not_zero(rs->max_sectors, queue_max_sectors(q));
513 514
514 /* 515 /*
515 * Check if merge fn is supported. 516 * Check if merge fn is supported.
@@ -524,24 +525,25 @@ void dm_set_device_limits(struct dm_target *ti, struct block_device *bdev)
524 525
525 rs->max_phys_segments = 526 rs->max_phys_segments =
526 min_not_zero(rs->max_phys_segments, 527 min_not_zero(rs->max_phys_segments,
527 q->max_phys_segments); 528 queue_max_phys_segments(q));
528 529
529 rs->max_hw_segments = 530 rs->max_hw_segments =
530 min_not_zero(rs->max_hw_segments, q->max_hw_segments); 531 min_not_zero(rs->max_hw_segments, queue_max_hw_segments(q));
531 532
532 rs->hardsect_size = max(rs->hardsect_size, q->hardsect_size); 533 rs->logical_block_size = max(rs->logical_block_size,
534 queue_logical_block_size(q));
533 535
534 rs->max_segment_size = 536 rs->max_segment_size =
535 min_not_zero(rs->max_segment_size, q->max_segment_size); 537 min_not_zero(rs->max_segment_size, queue_max_segment_size(q));
536 538
537 rs->max_hw_sectors = 539 rs->max_hw_sectors =
538 min_not_zero(rs->max_hw_sectors, q->max_hw_sectors); 540 min_not_zero(rs->max_hw_sectors, queue_max_hw_sectors(q));
539 541
540 rs->seg_boundary_mask = 542 rs->seg_boundary_mask =
541 min_not_zero(rs->seg_boundary_mask, 543 min_not_zero(rs->seg_boundary_mask,
542 q->seg_boundary_mask); 544 queue_segment_boundary(q));
543 545
544 rs->bounce_pfn = min_not_zero(rs->bounce_pfn, q->bounce_pfn); 546 rs->bounce_pfn = min_not_zero(rs->bounce_pfn, queue_bounce_pfn(q));
545 547
546 rs->no_cluster |= !test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags); 548 rs->no_cluster |= !test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
547} 549}
@@ -683,8 +685,8 @@ static void check_for_valid_limits(struct io_restrictions *rs)
683 rs->max_phys_segments = MAX_PHYS_SEGMENTS; 685 rs->max_phys_segments = MAX_PHYS_SEGMENTS;
684 if (!rs->max_hw_segments) 686 if (!rs->max_hw_segments)
685 rs->max_hw_segments = MAX_HW_SEGMENTS; 687 rs->max_hw_segments = MAX_HW_SEGMENTS;
686 if (!rs->hardsect_size) 688 if (!rs->logical_block_size)
687 rs->hardsect_size = 1 << SECTOR_SHIFT; 689 rs->logical_block_size = 1 << SECTOR_SHIFT;
688 if (!rs->max_segment_size) 690 if (!rs->max_segment_size)
689 rs->max_segment_size = MAX_SEGMENT_SIZE; 691 rs->max_segment_size = MAX_SEGMENT_SIZE;
690 if (!rs->seg_boundary_mask) 692 if (!rs->seg_boundary_mask)
@@ -912,13 +914,13 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q)
912 * restrictions. 914 * restrictions.
913 */ 915 */
914 blk_queue_max_sectors(q, t->limits.max_sectors); 916 blk_queue_max_sectors(q, t->limits.max_sectors);
915 q->max_phys_segments = t->limits.max_phys_segments; 917 blk_queue_max_phys_segments(q, t->limits.max_phys_segments);
916 q->max_hw_segments = t->limits.max_hw_segments; 918 blk_queue_max_hw_segments(q, t->limits.max_hw_segments);
917 q->hardsect_size = t->limits.hardsect_size; 919 blk_queue_logical_block_size(q, t->limits.logical_block_size);
918 q->max_segment_size = t->limits.max_segment_size; 920 blk_queue_max_segment_size(q, t->limits.max_segment_size);
919 q->max_hw_sectors = t->limits.max_hw_sectors; 921 blk_queue_max_hw_sectors(q, t->limits.max_hw_sectors);
920 q->seg_boundary_mask = t->limits.seg_boundary_mask; 922 blk_queue_segment_boundary(q, t->limits.seg_boundary_mask);
921 q->bounce_pfn = t->limits.bounce_pfn; 923 blk_queue_bounce_limit(q, t->limits.bounce_pfn);
922 924
923 if (t->limits.no_cluster) 925 if (t->limits.no_cluster)
924 queue_flag_clear_unlocked(QUEUE_FLAG_CLUSTER, q); 926 queue_flag_clear_unlocked(QUEUE_FLAG_CLUSTER, q);
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index 7a36e38393a1..64f1f3e046e0 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -146,7 +146,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
146 * a one page request is never in violation. 146 * a one page request is never in violation.
147 */ 147 */
148 if (rdev->bdev->bd_disk->queue->merge_bvec_fn && 148 if (rdev->bdev->bd_disk->queue->merge_bvec_fn &&
149 mddev->queue->max_sectors > (PAGE_SIZE>>9)) 149 queue_max_sectors(mddev->queue) > (PAGE_SIZE>>9))
150 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); 150 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
151 151
152 disk->num_sectors = rdev->sectors; 152 disk->num_sectors = rdev->sectors;
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 641b211fe3fe..20f6ac338349 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1202,7 +1202,7 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1202 atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read)); 1202 atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
1203 1203
1204 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256; 1204 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
1205 bmask = queue_hardsect_size(rdev->bdev->bd_disk->queue)-1; 1205 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
1206 if (rdev->sb_size & bmask) 1206 if (rdev->sb_size & bmask)
1207 rdev->sb_size = (rdev->sb_size | bmask) + 1; 1207 rdev->sb_size = (rdev->sb_size | bmask) + 1;
1208 1208
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 41ced0cbe823..4ee31aa13c40 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -303,7 +303,7 @@ static int multipath_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
303 * merge_bvec_fn will be involved in multipath.) 303 * merge_bvec_fn will be involved in multipath.)
304 */ 304 */
305 if (q->merge_bvec_fn && 305 if (q->merge_bvec_fn &&
306 mddev->queue->max_sectors > (PAGE_SIZE>>9)) 306 queue_max_sectors(q) > (PAGE_SIZE>>9))
307 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); 307 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
308 308
309 conf->working_disks++; 309 conf->working_disks++;
@@ -467,7 +467,7 @@ static int multipath_run (mddev_t *mddev)
467 * violating it, not that we ever expect a device with 467 * violating it, not that we ever expect a device with
468 * a merge_bvec_fn to be involved in multipath */ 468 * a merge_bvec_fn to be involved in multipath */
469 if (rdev->bdev->bd_disk->queue->merge_bvec_fn && 469 if (rdev->bdev->bd_disk->queue->merge_bvec_fn &&
470 mddev->queue->max_sectors > (PAGE_SIZE>>9)) 470 queue_max_sectors(mddev->queue) > (PAGE_SIZE>>9))
471 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); 471 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
472 472
473 if (!test_bit(Faulty, &rdev->flags)) 473 if (!test_bit(Faulty, &rdev->flags))
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index c08d7559be55..925507e7d673 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -144,7 +144,7 @@ static int create_strip_zones (mddev_t *mddev)
144 */ 144 */
145 145
146 if (rdev1->bdev->bd_disk->queue->merge_bvec_fn && 146 if (rdev1->bdev->bd_disk->queue->merge_bvec_fn &&
147 mddev->queue->max_sectors > (PAGE_SIZE>>9)) 147 queue_max_sectors(mddev->queue) > (PAGE_SIZE>>9))
148 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); 148 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
149 149
150 if (!smallest || (rdev1->sectors < smallest->sectors)) 150 if (!smallest || (rdev1->sectors < smallest->sectors))
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 36df9109cde1..e23758b4a34e 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -1130,7 +1130,7 @@ static int raid1_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
1130 * a one page request is never in violation. 1130 * a one page request is never in violation.
1131 */ 1131 */
1132 if (rdev->bdev->bd_disk->queue->merge_bvec_fn && 1132 if (rdev->bdev->bd_disk->queue->merge_bvec_fn &&
1133 mddev->queue->max_sectors > (PAGE_SIZE>>9)) 1133 queue_max_sectors(mddev->queue) > (PAGE_SIZE>>9))
1134 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); 1134 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
1135 1135
1136 p->head_position = 0; 1136 p->head_position = 0;
@@ -1996,7 +1996,7 @@ static int run(mddev_t *mddev)
1996 * a one page request is never in violation. 1996 * a one page request is never in violation.
1997 */ 1997 */
1998 if (rdev->bdev->bd_disk->queue->merge_bvec_fn && 1998 if (rdev->bdev->bd_disk->queue->merge_bvec_fn &&
1999 mddev->queue->max_sectors > (PAGE_SIZE>>9)) 1999 queue_max_sectors(mddev->queue) > (PAGE_SIZE>>9))
2000 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); 2000 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
2001 2001
2002 disk->head_position = 0; 2002 disk->head_position = 0;
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 499620afb44b..750550c1166f 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -1158,8 +1158,8 @@ static int raid10_add_disk(mddev_t *mddev, mdk_rdev_t *rdev)
1158 * a one page request is never in violation. 1158 * a one page request is never in violation.
1159 */ 1159 */
1160 if (rdev->bdev->bd_disk->queue->merge_bvec_fn && 1160 if (rdev->bdev->bd_disk->queue->merge_bvec_fn &&
1161 mddev->queue->max_sectors > (PAGE_SIZE>>9)) 1161 queue_max_sectors(mddev->queue) > (PAGE_SIZE>>9))
1162 mddev->queue->max_sectors = (PAGE_SIZE>>9); 1162 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
1163 1163
1164 p->head_position = 0; 1164 p->head_position = 0;
1165 rdev->raid_disk = mirror; 1165 rdev->raid_disk = mirror;
@@ -2145,8 +2145,8 @@ static int run(mddev_t *mddev)
2145 * a one page request is never in violation. 2145 * a one page request is never in violation.
2146 */ 2146 */
2147 if (rdev->bdev->bd_disk->queue->merge_bvec_fn && 2147 if (rdev->bdev->bd_disk->queue->merge_bvec_fn &&
2148 mddev->queue->max_sectors > (PAGE_SIZE>>9)) 2148 queue_max_sectors(mddev->queue) > (PAGE_SIZE>>9))
2149 mddev->queue->max_sectors = (PAGE_SIZE>>9); 2149 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
2150 2150
2151 disk->head_position = 0; 2151 disk->head_position = 0;
2152 } 2152 }
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index bb37fb1b2d82..bef876698232 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -3463,10 +3463,10 @@ static int bio_fits_rdev(struct bio *bi)
3463{ 3463{
3464 struct request_queue *q = bdev_get_queue(bi->bi_bdev); 3464 struct request_queue *q = bdev_get_queue(bi->bi_bdev);
3465 3465
3466 if ((bi->bi_size>>9) > q->max_sectors) 3466 if ((bi->bi_size>>9) > queue_max_sectors(q))
3467 return 0; 3467 return 0;
3468 blk_recount_segments(q, bi); 3468 blk_recount_segments(q, bi);
3469 if (bi->bi_phys_segments > q->max_phys_segments) 3469 if (bi->bi_phys_segments > queue_max_phys_segments(q))
3470 return 0; 3470 return 0;
3471 3471
3472 if (q->merge_bvec_fn) 3472 if (q->merge_bvec_fn)
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index de143deb06f0..7847bbc1440d 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -672,15 +672,14 @@ try_again:
672 msb->req_sg); 672 msb->req_sg);
673 673
674 if (!msb->seg_count) { 674 if (!msb->seg_count) {
675 chunk = __blk_end_request(msb->block_req, -ENOMEM, 675 chunk = __blk_end_request_cur(msb->block_req, -ENOMEM);
676 blk_rq_cur_bytes(msb->block_req));
677 continue; 676 continue;
678 } 677 }
679 678
680 t_sec = msb->block_req->sector << 9; 679 t_sec = blk_rq_pos(msb->block_req) << 9;
681 sector_div(t_sec, msb->page_size); 680 sector_div(t_sec, msb->page_size);
682 681
683 count = msb->block_req->nr_sectors << 9; 682 count = blk_rq_bytes(msb->block_req);
684 count /= msb->page_size; 683 count /= msb->page_size;
685 684
686 param.system = msb->system; 685 param.system = msb->system;
@@ -705,8 +704,8 @@ try_again:
705 return 0; 704 return 0;
706 } 705 }
707 706
708 dev_dbg(&card->dev, "elv_next\n"); 707 dev_dbg(&card->dev, "blk_fetch\n");
709 msb->block_req = elv_next_request(msb->queue); 708 msb->block_req = blk_fetch_request(msb->queue);
710 if (!msb->block_req) { 709 if (!msb->block_req) {
711 dev_dbg(&card->dev, "issue end\n"); 710 dev_dbg(&card->dev, "issue end\n");
712 return -EAGAIN; 711 return -EAGAIN;
@@ -745,7 +744,7 @@ static int mspro_block_complete_req(struct memstick_dev *card, int error)
745 t_len *= msb->page_size; 744 t_len *= msb->page_size;
746 } 745 }
747 } else 746 } else
748 t_len = msb->block_req->nr_sectors << 9; 747 t_len = blk_rq_bytes(msb->block_req);
749 748
750 dev_dbg(&card->dev, "transferred %x (%d)\n", t_len, error); 749 dev_dbg(&card->dev, "transferred %x (%d)\n", t_len, error);
751 750
@@ -825,8 +824,8 @@ static void mspro_block_submit_req(struct request_queue *q)
825 return; 824 return;
826 825
827 if (msb->eject) { 826 if (msb->eject) {
828 while ((req = elv_next_request(q)) != NULL) 827 while ((req = blk_fetch_request(q)) != NULL)
829 __blk_end_request(req, -ENODEV, blk_rq_bytes(req)); 828 __blk_end_request_all(req, -ENODEV);
830 829
831 return; 830 return;
832 } 831 }
@@ -1243,7 +1242,7 @@ static int mspro_block_init_disk(struct memstick_dev *card)
1243 1242
1244 sprintf(msb->disk->disk_name, "mspblk%d", disk_id); 1243 sprintf(msb->disk->disk_name, "mspblk%d", disk_id);
1245 1244
1246 blk_queue_hardsect_size(msb->queue, msb->page_size); 1245 blk_queue_logical_block_size(msb->queue, msb->page_size);
1247 1246
1248 capacity = be16_to_cpu(sys_info->user_block_count); 1247 capacity = be16_to_cpu(sys_info->user_block_count);
1249 capacity *= be16_to_cpu(sys_info->block_size); 1248 capacity *= be16_to_cpu(sys_info->block_size);
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index a9019f081b97..79f5433359f9 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -1277,8 +1277,8 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1277 /* do we need to support multiple segments? */ 1277 /* do we need to support multiple segments? */
1278 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) { 1278 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
1279 printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u %u, rsp %u %u\n", 1279 printk(MYIOC_s_ERR_FMT "%s: multiple segments req %u %u, rsp %u %u\n",
1280 ioc->name, __func__, req->bio->bi_vcnt, req->data_len, 1280 ioc->name, __func__, req->bio->bi_vcnt, blk_rq_bytes(req),
1281 rsp->bio->bi_vcnt, rsp->data_len); 1281 rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
1282 return -EINVAL; 1282 return -EINVAL;
1283 } 1283 }
1284 1284
@@ -1295,7 +1295,7 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1295 smpreq = (SmpPassthroughRequest_t *)mf; 1295 smpreq = (SmpPassthroughRequest_t *)mf;
1296 memset(smpreq, 0, sizeof(*smpreq)); 1296 memset(smpreq, 0, sizeof(*smpreq));
1297 1297
1298 smpreq->RequestDataLength = cpu_to_le16(req->data_len - 4); 1298 smpreq->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4);
1299 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH; 1299 smpreq->Function = MPI_FUNCTION_SMP_PASSTHROUGH;
1300 1300
1301 if (rphy) 1301 if (rphy)
@@ -1321,10 +1321,10 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1321 MPI_SGE_FLAGS_END_OF_BUFFER | 1321 MPI_SGE_FLAGS_END_OF_BUFFER |
1322 MPI_SGE_FLAGS_DIRECTION | 1322 MPI_SGE_FLAGS_DIRECTION |
1323 mpt_addr_size()) << MPI_SGE_FLAGS_SHIFT; 1323 mpt_addr_size()) << MPI_SGE_FLAGS_SHIFT;
1324 flagsLength |= (req->data_len - 4); 1324 flagsLength |= (blk_rq_bytes(req) - 4);
1325 1325
1326 dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio), 1326 dma_addr_out = pci_map_single(ioc->pcidev, bio_data(req->bio),
1327 req->data_len, PCI_DMA_BIDIRECTIONAL); 1327 blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL);
1328 if (!dma_addr_out) 1328 if (!dma_addr_out)
1329 goto put_mf; 1329 goto put_mf;
1330 mpt_add_sge(psge, flagsLength, dma_addr_out); 1330 mpt_add_sge(psge, flagsLength, dma_addr_out);
@@ -1332,9 +1332,9 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1332 1332
1333 /* response */ 1333 /* response */
1334 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ; 1334 flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
1335 flagsLength |= rsp->data_len + 4; 1335 flagsLength |= blk_rq_bytes(rsp) + 4;
1336 dma_addr_in = pci_map_single(ioc->pcidev, bio_data(rsp->bio), 1336 dma_addr_in = pci_map_single(ioc->pcidev, bio_data(rsp->bio),
1337 rsp->data_len, PCI_DMA_BIDIRECTIONAL); 1337 blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL);
1338 if (!dma_addr_in) 1338 if (!dma_addr_in)
1339 goto unmap; 1339 goto unmap;
1340 mpt_add_sge(psge, flagsLength, dma_addr_in); 1340 mpt_add_sge(psge, flagsLength, dma_addr_in);
@@ -1357,8 +1357,8 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1357 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply; 1357 smprep = (SmpPassthroughReply_t *)ioc->sas_mgmt.reply;
1358 memcpy(req->sense, smprep, sizeof(*smprep)); 1358 memcpy(req->sense, smprep, sizeof(*smprep));
1359 req->sense_len = sizeof(*smprep); 1359 req->sense_len = sizeof(*smprep);
1360 req->data_len = 0; 1360 req->resid_len = 0;
1361 rsp->data_len -= smprep->ResponseDataLength; 1361 rsp->resid_len -= smprep->ResponseDataLength;
1362 } else { 1362 } else {
1363 printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n", 1363 printk(MYIOC_s_ERR_FMT "%s: smp passthru reply failed to be returned\n",
1364 ioc->name, __func__); 1364 ioc->name, __func__);
@@ -1366,10 +1366,10 @@ static int mptsas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1366 } 1366 }
1367unmap: 1367unmap:
1368 if (dma_addr_out) 1368 if (dma_addr_out)
1369 pci_unmap_single(ioc->pcidev, dma_addr_out, req->data_len, 1369 pci_unmap_single(ioc->pcidev, dma_addr_out, blk_rq_bytes(req),
1370 PCI_DMA_BIDIRECTIONAL); 1370 PCI_DMA_BIDIRECTIONAL);
1371 if (dma_addr_in) 1371 if (dma_addr_in)
1372 pci_unmap_single(ioc->pcidev, dma_addr_in, rsp->data_len, 1372 pci_unmap_single(ioc->pcidev, dma_addr_in, blk_rq_bytes(rsp),
1373 PCI_DMA_BIDIRECTIONAL); 1373 PCI_DMA_BIDIRECTIONAL);
1374put_mf: 1374put_mf:
1375 if (mf) 1375 if (mf)
diff --git a/drivers/message/i2o/i2o_block.c b/drivers/message/i2o/i2o_block.c
index a443e136dc41..335d4c78a775 100644
--- a/drivers/message/i2o/i2o_block.c
+++ b/drivers/message/i2o/i2o_block.c
@@ -426,15 +426,9 @@ static void i2o_block_end_request(struct request *req, int error,
426 struct request_queue *q = req->q; 426 struct request_queue *q = req->q;
427 unsigned long flags; 427 unsigned long flags;
428 428
429 if (blk_end_request(req, error, nr_bytes)) { 429 if (blk_end_request(req, error, nr_bytes))
430 int leftover = (req->hard_nr_sectors << KERNEL_SECTOR_SHIFT);
431
432 if (blk_pc_request(req))
433 leftover = req->data_len;
434
435 if (error) 430 if (error)
436 blk_end_request(req, -EIO, leftover); 431 blk_end_request_all(req, -EIO);
437 }
438 432
439 spin_lock_irqsave(q->queue_lock, flags); 433 spin_lock_irqsave(q->queue_lock, flags);
440 434
@@ -761,7 +755,7 @@ static int i2o_block_transfer(struct request *req)
761 break; 755 break;
762 756
763 case CACHE_SMARTFETCH: 757 case CACHE_SMARTFETCH:
764 if (req->nr_sectors > 16) 758 if (blk_rq_sectors(req) > 16)
765 ctl_flags = 0x201F0008; 759 ctl_flags = 0x201F0008;
766 else 760 else
767 ctl_flags = 0x001F0000; 761 ctl_flags = 0x001F0000;
@@ -781,13 +775,13 @@ static int i2o_block_transfer(struct request *req)
781 ctl_flags = 0x001F0010; 775 ctl_flags = 0x001F0010;
782 break; 776 break;
783 case CACHE_SMARTBACK: 777 case CACHE_SMARTBACK:
784 if (req->nr_sectors > 16) 778 if (blk_rq_sectors(req) > 16)
785 ctl_flags = 0x001F0004; 779 ctl_flags = 0x001F0004;
786 else 780 else
787 ctl_flags = 0x001F0010; 781 ctl_flags = 0x001F0010;
788 break; 782 break;
789 case CACHE_SMARTTHROUGH: 783 case CACHE_SMARTTHROUGH:
790 if (req->nr_sectors > 16) 784 if (blk_rq_sectors(req) > 16)
791 ctl_flags = 0x001F0004; 785 ctl_flags = 0x001F0004;
792 else 786 else
793 ctl_flags = 0x001F0010; 787 ctl_flags = 0x001F0010;
@@ -800,8 +794,9 @@ static int i2o_block_transfer(struct request *req)
800 if (c->adaptec) { 794 if (c->adaptec) {
801 u8 cmd[10]; 795 u8 cmd[10];
802 u32 scsi_flags; 796 u32 scsi_flags;
803 u16 hwsec = queue_hardsect_size(req->q) >> KERNEL_SECTOR_SHIFT; 797 u16 hwsec;
804 798
799 hwsec = queue_logical_block_size(req->q) >> KERNEL_SECTOR_SHIFT;
805 memset(cmd, 0, 10); 800 memset(cmd, 0, 10);
806 801
807 sgl_offset = SGL_OFFSET_12; 802 sgl_offset = SGL_OFFSET_12;
@@ -827,22 +822,22 @@ static int i2o_block_transfer(struct request *req)
827 822
828 *mptr++ = cpu_to_le32(scsi_flags); 823 *mptr++ = cpu_to_le32(scsi_flags);
829 824
830 *((u32 *) & cmd[2]) = cpu_to_be32(req->sector * hwsec); 825 *((u32 *) & cmd[2]) = cpu_to_be32(blk_rq_pos(req) * hwsec);
831 *((u16 *) & cmd[7]) = cpu_to_be16(req->nr_sectors * hwsec); 826 *((u16 *) & cmd[7]) = cpu_to_be16(blk_rq_sectors(req) * hwsec);
832 827
833 memcpy(mptr, cmd, 10); 828 memcpy(mptr, cmd, 10);
834 mptr += 4; 829 mptr += 4;
835 *mptr++ = cpu_to_le32(req->nr_sectors << KERNEL_SECTOR_SHIFT); 830 *mptr++ = cpu_to_le32(blk_rq_bytes(req));
836 } else 831 } else
837#endif 832#endif
838 { 833 {
839 msg->u.head[1] = cpu_to_le32(cmd | HOST_TID << 12 | tid); 834 msg->u.head[1] = cpu_to_le32(cmd | HOST_TID << 12 | tid);
840 *mptr++ = cpu_to_le32(ctl_flags); 835 *mptr++ = cpu_to_le32(ctl_flags);
841 *mptr++ = cpu_to_le32(req->nr_sectors << KERNEL_SECTOR_SHIFT); 836 *mptr++ = cpu_to_le32(blk_rq_bytes(req));
842 *mptr++ = 837 *mptr++ =
843 cpu_to_le32((u32) (req->sector << KERNEL_SECTOR_SHIFT)); 838 cpu_to_le32((u32) (blk_rq_pos(req) << KERNEL_SECTOR_SHIFT));
844 *mptr++ = 839 *mptr++ =
845 cpu_to_le32(req->sector >> (32 - KERNEL_SECTOR_SHIFT)); 840 cpu_to_le32(blk_rq_pos(req) >> (32 - KERNEL_SECTOR_SHIFT));
846 } 841 }
847 842
848 if (!i2o_block_sglist_alloc(c, ireq, &mptr)) { 843 if (!i2o_block_sglist_alloc(c, ireq, &mptr)) {
@@ -883,7 +878,7 @@ static void i2o_block_request_fn(struct request_queue *q)
883 struct request *req; 878 struct request *req;
884 879
885 while (!blk_queue_plugged(q)) { 880 while (!blk_queue_plugged(q)) {
886 req = elv_next_request(q); 881 req = blk_peek_request(q);
887 if (!req) 882 if (!req)
888 break; 883 break;
889 884
@@ -896,7 +891,7 @@ static void i2o_block_request_fn(struct request_queue *q)
896 891
897 if (queue_depth < I2O_BLOCK_MAX_OPEN_REQUESTS) { 892 if (queue_depth < I2O_BLOCK_MAX_OPEN_REQUESTS) {
898 if (!i2o_block_transfer(req)) { 893 if (!i2o_block_transfer(req)) {
899 blkdev_dequeue_request(req); 894 blk_start_request(req);
900 continue; 895 continue;
901 } else 896 } else
902 osm_info("transfer error\n"); 897 osm_info("transfer error\n");
@@ -922,8 +917,10 @@ static void i2o_block_request_fn(struct request_queue *q)
922 blk_stop_queue(q); 917 blk_stop_queue(q);
923 break; 918 break;
924 } 919 }
925 } else 920 } else {
926 end_request(req, 0); 921 blk_start_request(req);
922 __blk_end_request_all(req, -EIO);
923 }
927 } 924 }
928}; 925};
929 926
@@ -1082,7 +1079,7 @@ static int i2o_block_probe(struct device *dev)
1082 */ 1079 */
1083 if (!i2o_parm_field_get(i2o_dev, 0x0004, 1, &blocksize, 4) || 1080 if (!i2o_parm_field_get(i2o_dev, 0x0004, 1, &blocksize, 4) ||
1084 !i2o_parm_field_get(i2o_dev, 0x0000, 3, &blocksize, 4)) { 1081 !i2o_parm_field_get(i2o_dev, 0x0000, 3, &blocksize, 4)) {
1085 blk_queue_hardsect_size(queue, le32_to_cpu(blocksize)); 1082 blk_queue_logical_block_size(queue, le32_to_cpu(blocksize));
1086 } else 1083 } else
1087 osm_warn("unable to get blocksize of %s\n", gd->disk_name); 1084 osm_warn("unable to get blocksize of %s\n", gd->disk_name);
1088 1085
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index b25e9b6516ae..98ffc41eaf2c 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -243,7 +243,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
243 brq.mrq.cmd = &brq.cmd; 243 brq.mrq.cmd = &brq.cmd;
244 brq.mrq.data = &brq.data; 244 brq.mrq.data = &brq.data;
245 245
246 brq.cmd.arg = req->sector; 246 brq.cmd.arg = blk_rq_pos(req);
247 if (!mmc_card_blockaddr(card)) 247 if (!mmc_card_blockaddr(card))
248 brq.cmd.arg <<= 9; 248 brq.cmd.arg <<= 9;
249 brq.cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; 249 brq.cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
@@ -251,7 +251,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
251 brq.stop.opcode = MMC_STOP_TRANSMISSION; 251 brq.stop.opcode = MMC_STOP_TRANSMISSION;
252 brq.stop.arg = 0; 252 brq.stop.arg = 0;
253 brq.stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; 253 brq.stop.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC;
254 brq.data.blocks = req->nr_sectors; 254 brq.data.blocks = blk_rq_sectors(req);
255 255
256 /* 256 /*
257 * The block layer doesn't support all sector count 257 * The block layer doesn't support all sector count
@@ -301,7 +301,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
301 * Adjust the sg list so it is the same size as the 301 * Adjust the sg list so it is the same size as the
302 * request. 302 * request.
303 */ 303 */
304 if (brq.data.blocks != req->nr_sectors) { 304 if (brq.data.blocks != blk_rq_sectors(req)) {
305 int i, data_size = brq.data.blocks << 9; 305 int i, data_size = brq.data.blocks << 9;
306 struct scatterlist *sg; 306 struct scatterlist *sg;
307 307
@@ -352,8 +352,8 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req)
352 printk(KERN_ERR "%s: error %d transferring data," 352 printk(KERN_ERR "%s: error %d transferring data,"
353 " sector %u, nr %u, card status %#x\n", 353 " sector %u, nr %u, card status %#x\n",
354 req->rq_disk->disk_name, brq.data.error, 354 req->rq_disk->disk_name, brq.data.error,
355 (unsigned)req->sector, 355 (unsigned)blk_rq_pos(req),
356 (unsigned)req->nr_sectors, status); 356 (unsigned)blk_rq_sectors(req), status);
357 } 357 }
358 358
359 if (brq.stop.error) { 359 if (brq.stop.error) {
@@ -521,7 +521,7 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
521 521
522 sprintf(md->disk->disk_name, "mmcblk%d", devidx); 522 sprintf(md->disk->disk_name, "mmcblk%d", devidx);
523 523
524 blk_queue_hardsect_size(md->queue.queue, 512); 524 blk_queue_logical_block_size(md->queue.queue, 512);
525 525
526 if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) { 526 if (!mmc_card_sd(card) && mmc_card_blockaddr(card)) {
527 /* 527 /*
diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
index 7a72e75d5c67..49e582356c65 100644
--- a/drivers/mmc/card/queue.c
+++ b/drivers/mmc/card/queue.c
@@ -55,7 +55,7 @@ static int mmc_queue_thread(void *d)
55 spin_lock_irq(q->queue_lock); 55 spin_lock_irq(q->queue_lock);
56 set_current_state(TASK_INTERRUPTIBLE); 56 set_current_state(TASK_INTERRUPTIBLE);
57 if (!blk_queue_plugged(q)) 57 if (!blk_queue_plugged(q))
58 req = elv_next_request(q); 58 req = blk_fetch_request(q);
59 mq->req = req; 59 mq->req = req;
60 spin_unlock_irq(q->queue_lock); 60 spin_unlock_irq(q->queue_lock);
61 61
@@ -88,16 +88,11 @@ static void mmc_request(struct request_queue *q)
88{ 88{
89 struct mmc_queue *mq = q->queuedata; 89 struct mmc_queue *mq = q->queuedata;
90 struct request *req; 90 struct request *req;
91 int ret;
92 91
93 if (!mq) { 92 if (!mq) {
94 printk(KERN_ERR "MMC: killing requests for dead queue\n"); 93 printk(KERN_ERR "MMC: killing requests for dead queue\n");
95 while ((req = elv_next_request(q)) != NULL) { 94 while ((req = blk_fetch_request(q)) != NULL)
96 do { 95 __blk_end_request_all(req, -EIO);
97 ret = __blk_end_request(req, -EIO,
98 blk_rq_cur_bytes(req));
99 } while (ret);
100 }
101 return; 96 return;
102 } 97 }
103 98
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index a49a9c8f2cb1..aaac3b6800b7 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -47,40 +47,41 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,
47 unsigned long block, nsect; 47 unsigned long block, nsect;
48 char *buf; 48 char *buf;
49 49
50 block = req->sector << 9 >> tr->blkshift; 50 block = blk_rq_pos(req) << 9 >> tr->blkshift;
51 nsect = req->current_nr_sectors << 9 >> tr->blkshift; 51 nsect = blk_rq_cur_bytes(req) >> tr->blkshift;
52 52
53 buf = req->buffer; 53 buf = req->buffer;
54 54
55 if (req->cmd_type == REQ_TYPE_LINUX_BLOCK && 55 if (req->cmd_type == REQ_TYPE_LINUX_BLOCK &&
56 req->cmd[0] == REQ_LB_OP_DISCARD) 56 req->cmd[0] == REQ_LB_OP_DISCARD)
57 return !tr->discard(dev, block, nsect); 57 return tr->discard(dev, block, nsect);
58 58
59 if (!blk_fs_request(req)) 59 if (!blk_fs_request(req))
60 return 0; 60 return -EIO;
61 61
62 if (req->sector + req->current_nr_sectors > get_capacity(req->rq_disk)) 62 if (blk_rq_pos(req) + blk_rq_cur_sectors(req) >
63 return 0; 63 get_capacity(req->rq_disk))
64 return -EIO;
64 65
65 switch(rq_data_dir(req)) { 66 switch(rq_data_dir(req)) {
66 case READ: 67 case READ:
67 for (; nsect > 0; nsect--, block++, buf += tr->blksize) 68 for (; nsect > 0; nsect--, block++, buf += tr->blksize)
68 if (tr->readsect(dev, block, buf)) 69 if (tr->readsect(dev, block, buf))
69 return 0; 70 return -EIO;
70 return 1; 71 return 0;
71 72
72 case WRITE: 73 case WRITE:
73 if (!tr->writesect) 74 if (!tr->writesect)
74 return 0; 75 return -EIO;
75 76
76 for (; nsect > 0; nsect--, block++, buf += tr->blksize) 77 for (; nsect > 0; nsect--, block++, buf += tr->blksize)
77 if (tr->writesect(dev, block, buf)) 78 if (tr->writesect(dev, block, buf))
78 return 0; 79 return -EIO;
79 return 1; 80 return 0;
80 81
81 default: 82 default:
82 printk(KERN_NOTICE "Unknown request %u\n", rq_data_dir(req)); 83 printk(KERN_NOTICE "Unknown request %u\n", rq_data_dir(req));
83 return 0; 84 return -EIO;
84 } 85 }
85} 86}
86 87
@@ -88,19 +89,18 @@ static int mtd_blktrans_thread(void *arg)
88{ 89{
89 struct mtd_blktrans_ops *tr = arg; 90 struct mtd_blktrans_ops *tr = arg;
90 struct request_queue *rq = tr->blkcore_priv->rq; 91 struct request_queue *rq = tr->blkcore_priv->rq;
92 struct request *req = NULL;
91 93
92 /* we might get involved when memory gets low, so use PF_MEMALLOC */ 94 /* we might get involved when memory gets low, so use PF_MEMALLOC */
93 current->flags |= PF_MEMALLOC; 95 current->flags |= PF_MEMALLOC;
94 96
95 spin_lock_irq(rq->queue_lock); 97 spin_lock_irq(rq->queue_lock);
98
96 while (!kthread_should_stop()) { 99 while (!kthread_should_stop()) {
97 struct request *req;
98 struct mtd_blktrans_dev *dev; 100 struct mtd_blktrans_dev *dev;
99 int res = 0; 101 int res;
100
101 req = elv_next_request(rq);
102 102
103 if (!req) { 103 if (!req && !(req = blk_fetch_request(rq))) {
104 set_current_state(TASK_INTERRUPTIBLE); 104 set_current_state(TASK_INTERRUPTIBLE);
105 spin_unlock_irq(rq->queue_lock); 105 spin_unlock_irq(rq->queue_lock);
106 schedule(); 106 schedule();
@@ -119,8 +119,13 @@ static int mtd_blktrans_thread(void *arg)
119 119
120 spin_lock_irq(rq->queue_lock); 120 spin_lock_irq(rq->queue_lock);
121 121
122 end_request(req, res); 122 if (!__blk_end_request_cur(req, res))
123 req = NULL;
123 } 124 }
125
126 if (req)
127 __blk_end_request_all(req, -EIO);
128
124 spin_unlock_irq(rq->queue_lock); 129 spin_unlock_irq(rq->queue_lock);
125 130
126 return 0; 131 return 0;
@@ -373,7 +378,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
373 } 378 }
374 379
375 tr->blkcore_priv->rq->queuedata = tr; 380 tr->blkcore_priv->rq->queuedata = tr;
376 blk_queue_hardsect_size(tr->blkcore_priv->rq, tr->blksize); 381 blk_queue_logical_block_size(tr->blkcore_priv->rq, tr->blksize);
377 if (tr->discard) 382 if (tr->discard)
378 blk_queue_set_discard(tr->blkcore_priv->rq, 383 blk_queue_set_discard(tr->blkcore_priv->rq,
379 blktrans_discard_request); 384 blktrans_discard_request);
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
index 4e63cc9e2778..151bf5bc8afe 100644
--- a/drivers/parport/parport_pc.c
+++ b/drivers/parport/parport_pc.c
@@ -1,5 +1,5 @@
1/* Low-level parallel-port routines for 8255-based PC-style hardware. 1/* Low-level parallel-port routines for 8255-based PC-style hardware.
2 * 2 *
3 * Authors: Phil Blundell <philb@gnu.org> 3 * Authors: Phil Blundell <philb@gnu.org>
4 * Tim Waugh <tim@cyberelk.demon.co.uk> 4 * Tim Waugh <tim@cyberelk.demon.co.uk>
5 * Jose Renau <renau@acm.org> 5 * Jose Renau <renau@acm.org>
@@ -11,7 +11,7 @@
11 * Cleaned up include files - Russell King <linux@arm.uk.linux.org> 11 * Cleaned up include files - Russell King <linux@arm.uk.linux.org>
12 * DMA support - Bert De Jonghe <bert@sophis.be> 12 * DMA support - Bert De Jonghe <bert@sophis.be>
13 * Many ECP bugs fixed. Fred Barnes & Jamie Lokier, 1999 13 * Many ECP bugs fixed. Fred Barnes & Jamie Lokier, 1999
14 * More PCI support now conditional on CONFIG_PCI, 03/2001, Paul G. 14 * More PCI support now conditional on CONFIG_PCI, 03/2001, Paul G.
15 * Various hacks, Fred Barnes, 04/2001 15 * Various hacks, Fred Barnes, 04/2001
16 * Updated probing logic - Adam Belay <ambx1@neo.rr.com> 16 * Updated probing logic - Adam Belay <ambx1@neo.rr.com>
17 */ 17 */
@@ -56,10 +56,10 @@
56#include <linux/pnp.h> 56#include <linux/pnp.h>
57#include <linux/platform_device.h> 57#include <linux/platform_device.h>
58#include <linux/sysctl.h> 58#include <linux/sysctl.h>
59#include <linux/io.h>
60#include <linux/uaccess.h>
59 61
60#include <asm/io.h>
61#include <asm/dma.h> 62#include <asm/dma.h>
62#include <asm/uaccess.h>
63 63
64#include <linux/parport.h> 64#include <linux/parport.h>
65#include <linux/parport_pc.h> 65#include <linux/parport_pc.h>
@@ -82,7 +82,7 @@
82#define ECR_TST 06 82#define ECR_TST 06
83#define ECR_CNF 07 83#define ECR_CNF 07
84#define ECR_MODE_MASK 0xe0 84#define ECR_MODE_MASK 0xe0
85#define ECR_WRITE(p,v) frob_econtrol((p),0xff,(v)) 85#define ECR_WRITE(p, v) frob_econtrol((p), 0xff, (v))
86 86
87#undef DEBUG 87#undef DEBUG
88 88
@@ -109,27 +109,27 @@ static int pci_registered_parport;
109static int pnp_registered_parport; 109static int pnp_registered_parport;
110 110
111/* frob_control, but for ECR */ 111/* frob_control, but for ECR */
112static void frob_econtrol (struct parport *pb, unsigned char m, 112static void frob_econtrol(struct parport *pb, unsigned char m,
113 unsigned char v) 113 unsigned char v)
114{ 114{
115 unsigned char ectr = 0; 115 unsigned char ectr = 0;
116 116
117 if (m != 0xff) 117 if (m != 0xff)
118 ectr = inb (ECONTROL (pb)); 118 ectr = inb(ECONTROL(pb));
119 119
120 DPRINTK (KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x\n", 120 DPRINTK(KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x\n",
121 m, v, ectr, (ectr & ~m) ^ v); 121 m, v, ectr, (ectr & ~m) ^ v);
122 122
123 outb ((ectr & ~m) ^ v, ECONTROL (pb)); 123 outb((ectr & ~m) ^ v, ECONTROL(pb));
124} 124}
125 125
126static __inline__ void frob_set_mode (struct parport *p, int mode) 126static inline void frob_set_mode(struct parport *p, int mode)
127{ 127{
128 frob_econtrol (p, ECR_MODE_MASK, mode << 5); 128 frob_econtrol(p, ECR_MODE_MASK, mode << 5);
129} 129}
130 130
131#ifdef CONFIG_PARPORT_PC_FIFO 131#ifdef CONFIG_PARPORT_PC_FIFO
132/* Safely change the mode bits in the ECR 132/* Safely change the mode bits in the ECR
133 Returns: 133 Returns:
134 0 : Success 134 0 : Success
135 -EBUSY: Could not drain FIFO in some finite amount of time, 135 -EBUSY: Could not drain FIFO in some finite amount of time,
@@ -141,17 +141,18 @@ static int change_mode(struct parport *p, int m)
141 unsigned char oecr; 141 unsigned char oecr;
142 int mode; 142 int mode;
143 143
144 DPRINTK(KERN_INFO "parport change_mode ECP-ISA to mode 0x%02x\n",m); 144 DPRINTK(KERN_INFO "parport change_mode ECP-ISA to mode 0x%02x\n", m);
145 145
146 if (!priv->ecr) { 146 if (!priv->ecr) {
147 printk (KERN_DEBUG "change_mode: but there's no ECR!\n"); 147 printk(KERN_DEBUG "change_mode: but there's no ECR!\n");
148 return 0; 148 return 0;
149 } 149 }
150 150
151 /* Bits <7:5> contain the mode. */ 151 /* Bits <7:5> contain the mode. */
152 oecr = inb (ECONTROL (p)); 152 oecr = inb(ECONTROL(p));
153 mode = (oecr >> 5) & 0x7; 153 mode = (oecr >> 5) & 0x7;
154 if (mode == m) return 0; 154 if (mode == m)
155 return 0;
155 156
156 if (mode >= 2 && !(priv->ctr & 0x20)) { 157 if (mode >= 2 && !(priv->ctr & 0x20)) {
157 /* This mode resets the FIFO, so we may 158 /* This mode resets the FIFO, so we may
@@ -163,19 +164,21 @@ static int change_mode(struct parport *p, int m)
163 case ECR_ECP: /* ECP Parallel Port mode */ 164 case ECR_ECP: /* ECP Parallel Port mode */
164 /* Busy wait for 200us */ 165 /* Busy wait for 200us */
165 for (counter = 0; counter < 40; counter++) { 166 for (counter = 0; counter < 40; counter++) {
166 if (inb (ECONTROL (p)) & 0x01) 167 if (inb(ECONTROL(p)) & 0x01)
168 break;
169 if (signal_pending(current))
167 break; 170 break;
168 if (signal_pending (current)) break; 171 udelay(5);
169 udelay (5);
170 } 172 }
171 173
172 /* Poll slowly. */ 174 /* Poll slowly. */
173 while (!(inb (ECONTROL (p)) & 0x01)) { 175 while (!(inb(ECONTROL(p)) & 0x01)) {
174 if (time_after_eq (jiffies, expire)) 176 if (time_after_eq(jiffies, expire))
175 /* The FIFO is stuck. */ 177 /* The FIFO is stuck. */
176 return -EBUSY; 178 return -EBUSY;
177 schedule_timeout_interruptible(msecs_to_jiffies(10)); 179 schedule_timeout_interruptible(
178 if (signal_pending (current)) 180 msecs_to_jiffies(10));
181 if (signal_pending(current))
179 break; 182 break;
180 } 183 }
181 } 184 }
@@ -185,20 +188,20 @@ static int change_mode(struct parport *p, int m)
185 /* We have to go through mode 001 */ 188 /* We have to go through mode 001 */
186 oecr &= ~(7 << 5); 189 oecr &= ~(7 << 5);
187 oecr |= ECR_PS2 << 5; 190 oecr |= ECR_PS2 << 5;
188 ECR_WRITE (p, oecr); 191 ECR_WRITE(p, oecr);
189 } 192 }
190 193
191 /* Set the mode. */ 194 /* Set the mode. */
192 oecr &= ~(7 << 5); 195 oecr &= ~(7 << 5);
193 oecr |= m << 5; 196 oecr |= m << 5;
194 ECR_WRITE (p, oecr); 197 ECR_WRITE(p, oecr);
195 return 0; 198 return 0;
196} 199}
197 200
198#ifdef CONFIG_PARPORT_1284 201#ifdef CONFIG_PARPORT_1284
199/* Find FIFO lossage; FIFO is reset */ 202/* Find FIFO lossage; FIFO is reset */
200#if 0 203#if 0
201static int get_fifo_residue (struct parport *p) 204static int get_fifo_residue(struct parport *p)
202{ 205{
203 int residue; 206 int residue;
204 int cnfga; 207 int cnfga;
@@ -206,26 +209,26 @@ static int get_fifo_residue (struct parport *p)
206 209
207 /* Adjust for the contents of the FIFO. */ 210 /* Adjust for the contents of the FIFO. */
208 for (residue = priv->fifo_depth; ; residue--) { 211 for (residue = priv->fifo_depth; ; residue--) {
209 if (inb (ECONTROL (p)) & 0x2) 212 if (inb(ECONTROL(p)) & 0x2)
210 /* Full up. */ 213 /* Full up. */
211 break; 214 break;
212 215
213 outb (0, FIFO (p)); 216 outb(0, FIFO(p));
214 } 217 }
215 218
216 printk (KERN_DEBUG "%s: %d PWords were left in FIFO\n", p->name, 219 printk(KERN_DEBUG "%s: %d PWords were left in FIFO\n", p->name,
217 residue); 220 residue);
218 221
219 /* Reset the FIFO. */ 222 /* Reset the FIFO. */
220 frob_set_mode (p, ECR_PS2); 223 frob_set_mode(p, ECR_PS2);
221 224
222 /* Now change to config mode and clean up. FIXME */ 225 /* Now change to config mode and clean up. FIXME */
223 frob_set_mode (p, ECR_CNF); 226 frob_set_mode(p, ECR_CNF);
224 cnfga = inb (CONFIGA (p)); 227 cnfga = inb(CONFIGA(p));
225 printk (KERN_DEBUG "%s: cnfgA contains 0x%02x\n", p->name, cnfga); 228 printk(KERN_DEBUG "%s: cnfgA contains 0x%02x\n", p->name, cnfga);
226 229
227 if (!(cnfga & (1<<2))) { 230 if (!(cnfga & (1<<2))) {
228 printk (KERN_DEBUG "%s: Accounting for extra byte\n", p->name); 231 printk(KERN_DEBUG "%s: Accounting for extra byte\n", p->name);
229 residue++; 232 residue++;
230 } 233 }
231 234
@@ -233,9 +236,11 @@ static int get_fifo_residue (struct parport *p)
233 * PWord != 1 byte. */ 236 * PWord != 1 byte. */
234 237
235 /* Back to PS2 mode. */ 238 /* Back to PS2 mode. */
236 frob_set_mode (p, ECR_PS2); 239 frob_set_mode(p, ECR_PS2);
237 240
238 DPRINTK (KERN_DEBUG "*** get_fifo_residue: done residue collecting (ecr = 0x%2.2x)\n", inb (ECONTROL (p))); 241 DPRINTK(KERN_DEBUG
242 "*** get_fifo_residue: done residue collecting (ecr = 0x%2.2x)\n",
243 inb(ECONTROL(p)));
239 return residue; 244 return residue;
240} 245}
241#endif /* 0 */ 246#endif /* 0 */
@@ -257,8 +262,8 @@ static int clear_epp_timeout(struct parport *pb)
257 /* To clear timeout some chips require double read */ 262 /* To clear timeout some chips require double read */
258 parport_pc_read_status(pb); 263 parport_pc_read_status(pb);
259 r = parport_pc_read_status(pb); 264 r = parport_pc_read_status(pb);
260 outb (r | 0x01, STATUS (pb)); /* Some reset by writing 1 */ 265 outb(r | 0x01, STATUS(pb)); /* Some reset by writing 1 */
261 outb (r & 0xfe, STATUS (pb)); /* Others by writing 0 */ 266 outb(r & 0xfe, STATUS(pb)); /* Others by writing 0 */
262 r = parport_pc_read_status(pb); 267 r = parport_pc_read_status(pb);
263 268
264 return !(r & 0x01); 269 return !(r & 0x01);
@@ -272,7 +277,8 @@ static int clear_epp_timeout(struct parport *pb)
272 * of these are in parport_pc.h. 277 * of these are in parport_pc.h.
273 */ 278 */
274 279
275static void parport_pc_init_state(struct pardevice *dev, struct parport_state *s) 280static void parport_pc_init_state(struct pardevice *dev,
281 struct parport_state *s)
276{ 282{
277 s->u.pc.ctr = 0xc; 283 s->u.pc.ctr = 0xc;
278 if (dev->irq_func && 284 if (dev->irq_func &&
@@ -289,22 +295,23 @@ static void parport_pc_save_state(struct parport *p, struct parport_state *s)
289 const struct parport_pc_private *priv = p->physport->private_data; 295 const struct parport_pc_private *priv = p->physport->private_data;
290 s->u.pc.ctr = priv->ctr; 296 s->u.pc.ctr = priv->ctr;
291 if (priv->ecr) 297 if (priv->ecr)
292 s->u.pc.ecr = inb (ECONTROL (p)); 298 s->u.pc.ecr = inb(ECONTROL(p));
293} 299}
294 300
295static void parport_pc_restore_state(struct parport *p, struct parport_state *s) 301static void parport_pc_restore_state(struct parport *p,
302 struct parport_state *s)
296{ 303{
297 struct parport_pc_private *priv = p->physport->private_data; 304 struct parport_pc_private *priv = p->physport->private_data;
298 register unsigned char c = s->u.pc.ctr & priv->ctr_writable; 305 register unsigned char c = s->u.pc.ctr & priv->ctr_writable;
299 outb (c, CONTROL (p)); 306 outb(c, CONTROL(p));
300 priv->ctr = c; 307 priv->ctr = c;
301 if (priv->ecr) 308 if (priv->ecr)
302 ECR_WRITE (p, s->u.pc.ecr); 309 ECR_WRITE(p, s->u.pc.ecr);
303} 310}
304 311
305#ifdef CONFIG_PARPORT_1284 312#ifdef CONFIG_PARPORT_1284
306static size_t parport_pc_epp_read_data (struct parport *port, void *buf, 313static size_t parport_pc_epp_read_data(struct parport *port, void *buf,
307 size_t length, int flags) 314 size_t length, int flags)
308{ 315{
309 size_t got = 0; 316 size_t got = 0;
310 317
@@ -316,54 +323,52 @@ static size_t parport_pc_epp_read_data (struct parport *port, void *buf,
316 * nFault is 0 if there is at least 1 byte in the Warp's FIFO 323 * nFault is 0 if there is at least 1 byte in the Warp's FIFO
317 * pError is 1 if there are 16 bytes in the Warp's FIFO 324 * pError is 1 if there are 16 bytes in the Warp's FIFO
318 */ 325 */
319 status = inb (STATUS (port)); 326 status = inb(STATUS(port));
320 327
321 while (!(status & 0x08) && (got < length)) { 328 while (!(status & 0x08) && got < length) {
322 if ((left >= 16) && (status & 0x20) && !(status & 0x08)) { 329 if (left >= 16 && (status & 0x20) && !(status & 0x08)) {
323 /* can grab 16 bytes from warp fifo */ 330 /* can grab 16 bytes from warp fifo */
324 if (!((long)buf & 0x03)) { 331 if (!((long)buf & 0x03))
325 insl (EPPDATA (port), buf, 4); 332 insl(EPPDATA(port), buf, 4);
326 } else { 333 else
327 insb (EPPDATA (port), buf, 16); 334 insb(EPPDATA(port), buf, 16);
328 }
329 buf += 16; 335 buf += 16;
330 got += 16; 336 got += 16;
331 left -= 16; 337 left -= 16;
332 } else { 338 } else {
333 /* grab single byte from the warp fifo */ 339 /* grab single byte from the warp fifo */
334 *((char *)buf) = inb (EPPDATA (port)); 340 *((char *)buf) = inb(EPPDATA(port));
335 buf++; 341 buf++;
336 got++; 342 got++;
337 left--; 343 left--;
338 } 344 }
339 status = inb (STATUS (port)); 345 status = inb(STATUS(port));
340 if (status & 0x01) { 346 if (status & 0x01) {
341 /* EPP timeout should never occur... */ 347 /* EPP timeout should never occur... */
342 printk (KERN_DEBUG "%s: EPP timeout occurred while talking to " 348 printk(KERN_DEBUG
343 "w91284pic (should not have done)\n", port->name); 349"%s: EPP timeout occurred while talking to w91284pic (should not have done)\n", port->name);
344 clear_epp_timeout (port); 350 clear_epp_timeout(port);
345 } 351 }
346 } 352 }
347 return got; 353 return got;
348 } 354 }
349 if ((flags & PARPORT_EPP_FAST) && (length > 1)) { 355 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
350 if (!(((long)buf | length) & 0x03)) { 356 if (!(((long)buf | length) & 0x03))
351 insl (EPPDATA (port), buf, (length >> 2)); 357 insl(EPPDATA(port), buf, (length >> 2));
352 } else { 358 else
353 insb (EPPDATA (port), buf, length); 359 insb(EPPDATA(port), buf, length);
354 } 360 if (inb(STATUS(port)) & 0x01) {
355 if (inb (STATUS (port)) & 0x01) { 361 clear_epp_timeout(port);
356 clear_epp_timeout (port);
357 return -EIO; 362 return -EIO;
358 } 363 }
359 return length; 364 return length;
360 } 365 }
361 for (; got < length; got++) { 366 for (; got < length; got++) {
362 *((char*)buf) = inb (EPPDATA(port)); 367 *((char *)buf) = inb(EPPDATA(port));
363 buf++; 368 buf++;
364 if (inb (STATUS (port)) & 0x01) { 369 if (inb(STATUS(port)) & 0x01) {
365 /* EPP timeout */ 370 /* EPP timeout */
366 clear_epp_timeout (port); 371 clear_epp_timeout(port);
367 break; 372 break;
368 } 373 }
369 } 374 }
@@ -371,28 +376,27 @@ static size_t parport_pc_epp_read_data (struct parport *port, void *buf,
371 return got; 376 return got;
372} 377}
373 378
374static size_t parport_pc_epp_write_data (struct parport *port, const void *buf, 379static size_t parport_pc_epp_write_data(struct parport *port, const void *buf,
375 size_t length, int flags) 380 size_t length, int flags)
376{ 381{
377 size_t written = 0; 382 size_t written = 0;
378 383
379 if ((flags & PARPORT_EPP_FAST) && (length > 1)) { 384 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
380 if (!(((long)buf | length) & 0x03)) { 385 if (!(((long)buf | length) & 0x03))
381 outsl (EPPDATA (port), buf, (length >> 2)); 386 outsl(EPPDATA(port), buf, (length >> 2));
382 } else { 387 else
383 outsb (EPPDATA (port), buf, length); 388 outsb(EPPDATA(port), buf, length);
384 } 389 if (inb(STATUS(port)) & 0x01) {
385 if (inb (STATUS (port)) & 0x01) { 390 clear_epp_timeout(port);
386 clear_epp_timeout (port);
387 return -EIO; 391 return -EIO;
388 } 392 }
389 return length; 393 return length;
390 } 394 }
391 for (; written < length; written++) { 395 for (; written < length; written++) {
392 outb (*((char*)buf), EPPDATA(port)); 396 outb(*((char *)buf), EPPDATA(port));
393 buf++; 397 buf++;
394 if (inb (STATUS(port)) & 0x01) { 398 if (inb(STATUS(port)) & 0x01) {
395 clear_epp_timeout (port); 399 clear_epp_timeout(port);
396 break; 400 break;
397 } 401 }
398 } 402 }
@@ -400,24 +404,24 @@ static size_t parport_pc_epp_write_data (struct parport *port, const void *buf,
400 return written; 404 return written;
401} 405}
402 406
403static size_t parport_pc_epp_read_addr (struct parport *port, void *buf, 407static size_t parport_pc_epp_read_addr(struct parport *port, void *buf,
404 size_t length, int flags) 408 size_t length, int flags)
405{ 409{
406 size_t got = 0; 410 size_t got = 0;
407 411
408 if ((flags & PARPORT_EPP_FAST) && (length > 1)) { 412 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
409 insb (EPPADDR (port), buf, length); 413 insb(EPPADDR(port), buf, length);
410 if (inb (STATUS (port)) & 0x01) { 414 if (inb(STATUS(port)) & 0x01) {
411 clear_epp_timeout (port); 415 clear_epp_timeout(port);
412 return -EIO; 416 return -EIO;
413 } 417 }
414 return length; 418 return length;
415 } 419 }
416 for (; got < length; got++) { 420 for (; got < length; got++) {
417 *((char*)buf) = inb (EPPADDR (port)); 421 *((char *)buf) = inb(EPPADDR(port));
418 buf++; 422 buf++;
419 if (inb (STATUS (port)) & 0x01) { 423 if (inb(STATUS(port)) & 0x01) {
420 clear_epp_timeout (port); 424 clear_epp_timeout(port);
421 break; 425 break;
422 } 426 }
423 } 427 }
@@ -425,25 +429,25 @@ static size_t parport_pc_epp_read_addr (struct parport *port, void *buf,
425 return got; 429 return got;
426} 430}
427 431
428static size_t parport_pc_epp_write_addr (struct parport *port, 432static size_t parport_pc_epp_write_addr(struct parport *port,
429 const void *buf, size_t length, 433 const void *buf, size_t length,
430 int flags) 434 int flags)
431{ 435{
432 size_t written = 0; 436 size_t written = 0;
433 437
434 if ((flags & PARPORT_EPP_FAST) && (length > 1)) { 438 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
435 outsb (EPPADDR (port), buf, length); 439 outsb(EPPADDR(port), buf, length);
436 if (inb (STATUS (port)) & 0x01) { 440 if (inb(STATUS(port)) & 0x01) {
437 clear_epp_timeout (port); 441 clear_epp_timeout(port);
438 return -EIO; 442 return -EIO;
439 } 443 }
440 return length; 444 return length;
441 } 445 }
442 for (; written < length; written++) { 446 for (; written < length; written++) {
443 outb (*((char*)buf), EPPADDR (port)); 447 outb(*((char *)buf), EPPADDR(port));
444 buf++; 448 buf++;
445 if (inb (STATUS (port)) & 0x01) { 449 if (inb(STATUS(port)) & 0x01) {
446 clear_epp_timeout (port); 450 clear_epp_timeout(port);
447 break; 451 break;
448 } 452 }
449 } 453 }
@@ -451,74 +455,74 @@ static size_t parport_pc_epp_write_addr (struct parport *port,
451 return written; 455 return written;
452} 456}
453 457
454static size_t parport_pc_ecpepp_read_data (struct parport *port, void *buf, 458static size_t parport_pc_ecpepp_read_data(struct parport *port, void *buf,
455 size_t length, int flags) 459 size_t length, int flags)
456{ 460{
457 size_t got; 461 size_t got;
458 462
459 frob_set_mode (port, ECR_EPP); 463 frob_set_mode(port, ECR_EPP);
460 parport_pc_data_reverse (port); 464 parport_pc_data_reverse(port);
461 parport_pc_write_control (port, 0x4); 465 parport_pc_write_control(port, 0x4);
462 got = parport_pc_epp_read_data (port, buf, length, flags); 466 got = parport_pc_epp_read_data(port, buf, length, flags);
463 frob_set_mode (port, ECR_PS2); 467 frob_set_mode(port, ECR_PS2);
464 468
465 return got; 469 return got;
466} 470}
467 471
468static size_t parport_pc_ecpepp_write_data (struct parport *port, 472static size_t parport_pc_ecpepp_write_data(struct parport *port,
469 const void *buf, size_t length, 473 const void *buf, size_t length,
470 int flags) 474 int flags)
471{ 475{
472 size_t written; 476 size_t written;
473 477
474 frob_set_mode (port, ECR_EPP); 478 frob_set_mode(port, ECR_EPP);
475 parport_pc_write_control (port, 0x4); 479 parport_pc_write_control(port, 0x4);
476 parport_pc_data_forward (port); 480 parport_pc_data_forward(port);
477 written = parport_pc_epp_write_data (port, buf, length, flags); 481 written = parport_pc_epp_write_data(port, buf, length, flags);
478 frob_set_mode (port, ECR_PS2); 482 frob_set_mode(port, ECR_PS2);
479 483
480 return written; 484 return written;
481} 485}
482 486
483static size_t parport_pc_ecpepp_read_addr (struct parport *port, void *buf, 487static size_t parport_pc_ecpepp_read_addr(struct parport *port, void *buf,
484 size_t length, int flags) 488 size_t length, int flags)
485{ 489{
486 size_t got; 490 size_t got;
487 491
488 frob_set_mode (port, ECR_EPP); 492 frob_set_mode(port, ECR_EPP);
489 parport_pc_data_reverse (port); 493 parport_pc_data_reverse(port);
490 parport_pc_write_control (port, 0x4); 494 parport_pc_write_control(port, 0x4);
491 got = parport_pc_epp_read_addr (port, buf, length, flags); 495 got = parport_pc_epp_read_addr(port, buf, length, flags);
492 frob_set_mode (port, ECR_PS2); 496 frob_set_mode(port, ECR_PS2);
493 497
494 return got; 498 return got;
495} 499}
496 500
497static size_t parport_pc_ecpepp_write_addr (struct parport *port, 501static size_t parport_pc_ecpepp_write_addr(struct parport *port,
498 const void *buf, size_t length, 502 const void *buf, size_t length,
499 int flags) 503 int flags)
500{ 504{
501 size_t written; 505 size_t written;
502 506
503 frob_set_mode (port, ECR_EPP); 507 frob_set_mode(port, ECR_EPP);
504 parport_pc_write_control (port, 0x4); 508 parport_pc_write_control(port, 0x4);
505 parport_pc_data_forward (port); 509 parport_pc_data_forward(port);
506 written = parport_pc_epp_write_addr (port, buf, length, flags); 510 written = parport_pc_epp_write_addr(port, buf, length, flags);
507 frob_set_mode (port, ECR_PS2); 511 frob_set_mode(port, ECR_PS2);
508 512
509 return written; 513 return written;
510} 514}
511#endif /* IEEE 1284 support */ 515#endif /* IEEE 1284 support */
512 516
513#ifdef CONFIG_PARPORT_PC_FIFO 517#ifdef CONFIG_PARPORT_PC_FIFO
514static size_t parport_pc_fifo_write_block_pio (struct parport *port, 518static size_t parport_pc_fifo_write_block_pio(struct parport *port,
515 const void *buf, size_t length) 519 const void *buf, size_t length)
516{ 520{
517 int ret = 0; 521 int ret = 0;
518 const unsigned char *bufp = buf; 522 const unsigned char *bufp = buf;
519 size_t left = length; 523 size_t left = length;
520 unsigned long expire = jiffies + port->physport->cad->timeout; 524 unsigned long expire = jiffies + port->physport->cad->timeout;
521 const int fifo = FIFO (port); 525 const int fifo = FIFO(port);
522 int poll_for = 8; /* 80 usecs */ 526 int poll_for = 8; /* 80 usecs */
523 const struct parport_pc_private *priv = port->physport->private_data; 527 const struct parport_pc_private *priv = port->physport->private_data;
524 const int fifo_depth = priv->fifo_depth; 528 const int fifo_depth = priv->fifo_depth;
@@ -526,25 +530,25 @@ static size_t parport_pc_fifo_write_block_pio (struct parport *port,
526 port = port->physport; 530 port = port->physport;
527 531
528 /* We don't want to be interrupted every character. */ 532 /* We don't want to be interrupted every character. */
529 parport_pc_disable_irq (port); 533 parport_pc_disable_irq(port);
530 /* set nErrIntrEn and serviceIntr */ 534 /* set nErrIntrEn and serviceIntr */
531 frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2)); 535 frob_econtrol(port, (1<<4) | (1<<2), (1<<4) | (1<<2));
532 536
533 /* Forward mode. */ 537 /* Forward mode. */
534 parport_pc_data_forward (port); /* Must be in PS2 mode */ 538 parport_pc_data_forward(port); /* Must be in PS2 mode */
535 539
536 while (left) { 540 while (left) {
537 unsigned char byte; 541 unsigned char byte;
538 unsigned char ecrval = inb (ECONTROL (port)); 542 unsigned char ecrval = inb(ECONTROL(port));
539 int i = 0; 543 int i = 0;
540 544
541 if (need_resched() && time_before (jiffies, expire)) 545 if (need_resched() && time_before(jiffies, expire))
542 /* Can't yield the port. */ 546 /* Can't yield the port. */
543 schedule (); 547 schedule();
544 548
545 /* Anyone else waiting for the port? */ 549 /* Anyone else waiting for the port? */
546 if (port->waithead) { 550 if (port->waithead) {
547 printk (KERN_DEBUG "Somebody wants the port\n"); 551 printk(KERN_DEBUG "Somebody wants the port\n");
548 break; 552 break;
549 } 553 }
550 554
@@ -552,21 +556,22 @@ static size_t parport_pc_fifo_write_block_pio (struct parport *port,
552 /* FIFO is full. Wait for interrupt. */ 556 /* FIFO is full. Wait for interrupt. */
553 557
554 /* Clear serviceIntr */ 558 /* Clear serviceIntr */
555 ECR_WRITE (port, ecrval & ~(1<<2)); 559 ECR_WRITE(port, ecrval & ~(1<<2));
556 false_alarm: 560false_alarm:
557 ret = parport_wait_event (port, HZ); 561 ret = parport_wait_event(port, HZ);
558 if (ret < 0) break; 562 if (ret < 0)
563 break;
559 ret = 0; 564 ret = 0;
560 if (!time_before (jiffies, expire)) { 565 if (!time_before(jiffies, expire)) {
561 /* Timed out. */ 566 /* Timed out. */
562 printk (KERN_DEBUG "FIFO write timed out\n"); 567 printk(KERN_DEBUG "FIFO write timed out\n");
563 break; 568 break;
564 } 569 }
565 ecrval = inb (ECONTROL (port)); 570 ecrval = inb(ECONTROL(port));
566 if (!(ecrval & (1<<2))) { 571 if (!(ecrval & (1<<2))) {
567 if (need_resched() && 572 if (need_resched() &&
568 time_before (jiffies, expire)) 573 time_before(jiffies, expire))
569 schedule (); 574 schedule();
570 575
571 goto false_alarm; 576 goto false_alarm;
572 } 577 }
@@ -577,38 +582,38 @@ static size_t parport_pc_fifo_write_block_pio (struct parport *port,
577 /* Can't fail now. */ 582 /* Can't fail now. */
578 expire = jiffies + port->cad->timeout; 583 expire = jiffies + port->cad->timeout;
579 584
580 poll: 585poll:
581 if (signal_pending (current)) 586 if (signal_pending(current))
582 break; 587 break;
583 588
584 if (ecrval & 0x01) { 589 if (ecrval & 0x01) {
585 /* FIFO is empty. Blast it full. */ 590 /* FIFO is empty. Blast it full. */
586 const int n = left < fifo_depth ? left : fifo_depth; 591 const int n = left < fifo_depth ? left : fifo_depth;
587 outsb (fifo, bufp, n); 592 outsb(fifo, bufp, n);
588 bufp += n; 593 bufp += n;
589 left -= n; 594 left -= n;
590 595
591 /* Adjust the poll time. */ 596 /* Adjust the poll time. */
592 if (i < (poll_for - 2)) poll_for--; 597 if (i < (poll_for - 2))
598 poll_for--;
593 continue; 599 continue;
594 } else if (i++ < poll_for) { 600 } else if (i++ < poll_for) {
595 udelay (10); 601 udelay(10);
596 ecrval = inb (ECONTROL (port)); 602 ecrval = inb(ECONTROL(port));
597 goto poll; 603 goto poll;
598 } 604 }
599 605
600 /* Half-full (call me an optimist) */ 606 /* Half-full(call me an optimist) */
601 byte = *bufp++; 607 byte = *bufp++;
602 outb (byte, fifo); 608 outb(byte, fifo);
603 left--; 609 left--;
604 } 610 }
605 611 dump_parport_state("leave fifo_write_block_pio", port);
606dump_parport_state ("leave fifo_write_block_pio", port);
607 return length - left; 612 return length - left;
608} 613}
609 614
610#ifdef HAS_DMA 615#ifdef HAS_DMA
611static size_t parport_pc_fifo_write_block_dma (struct parport *port, 616static size_t parport_pc_fifo_write_block_dma(struct parport *port,
612 const void *buf, size_t length) 617 const void *buf, size_t length)
613{ 618{
614 int ret = 0; 619 int ret = 0;
@@ -621,7 +626,7 @@ static size_t parport_pc_fifo_write_block_dma (struct parport *port,
621 unsigned long start = (unsigned long) buf; 626 unsigned long start = (unsigned long) buf;
622 unsigned long end = (unsigned long) buf + length - 1; 627 unsigned long end = (unsigned long) buf + length - 1;
623 628
624dump_parport_state ("enter fifo_write_block_dma", port); 629 dump_parport_state("enter fifo_write_block_dma", port);
625 if (end < MAX_DMA_ADDRESS) { 630 if (end < MAX_DMA_ADDRESS) {
626 /* If it would cross a 64k boundary, cap it at the end. */ 631 /* If it would cross a 64k boundary, cap it at the end. */
627 if ((start ^ end) & ~0xffffUL) 632 if ((start ^ end) & ~0xffffUL)
@@ -629,8 +634,9 @@ dump_parport_state ("enter fifo_write_block_dma", port);
629 634
630 dma_addr = dma_handle = dma_map_single(dev, (void *)buf, length, 635 dma_addr = dma_handle = dma_map_single(dev, (void *)buf, length,
631 DMA_TO_DEVICE); 636 DMA_TO_DEVICE);
632 } else { 637 } else {
633 /* above 16 MB we use a bounce buffer as ISA-DMA is not possible */ 638 /* above 16 MB we use a bounce buffer as ISA-DMA
639 is not possible */
634 maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */ 640 maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */
635 dma_addr = priv->dma_handle; 641 dma_addr = priv->dma_handle;
636 dma_handle = 0; 642 dma_handle = 0;
@@ -639,12 +645,12 @@ dump_parport_state ("enter fifo_write_block_dma", port);
639 port = port->physport; 645 port = port->physport;
640 646
641 /* We don't want to be interrupted every character. */ 647 /* We don't want to be interrupted every character. */
642 parport_pc_disable_irq (port); 648 parport_pc_disable_irq(port);
643 /* set nErrIntrEn and serviceIntr */ 649 /* set nErrIntrEn and serviceIntr */
644 frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2)); 650 frob_econtrol(port, (1<<4) | (1<<2), (1<<4) | (1<<2));
645 651
646 /* Forward mode. */ 652 /* Forward mode. */
647 parport_pc_data_forward (port); /* Must be in PS2 mode */ 653 parport_pc_data_forward(port); /* Must be in PS2 mode */
648 654
649 while (left) { 655 while (left) {
650 unsigned long expire = jiffies + port->physport->cad->timeout; 656 unsigned long expire = jiffies + port->physport->cad->timeout;
@@ -665,10 +671,10 @@ dump_parport_state ("enter fifo_write_block_dma", port);
665 set_dma_count(port->dma, count); 671 set_dma_count(port->dma, count);
666 672
667 /* Set DMA mode */ 673 /* Set DMA mode */
668 frob_econtrol (port, 1<<3, 1<<3); 674 frob_econtrol(port, 1<<3, 1<<3);
669 675
670 /* Clear serviceIntr */ 676 /* Clear serviceIntr */
671 frob_econtrol (port, 1<<2, 0); 677 frob_econtrol(port, 1<<2, 0);
672 678
673 enable_dma(port->dma); 679 enable_dma(port->dma);
674 release_dma_lock(dmaflag); 680 release_dma_lock(dmaflag);
@@ -676,20 +682,22 @@ dump_parport_state ("enter fifo_write_block_dma", port);
676 /* assume DMA will be successful */ 682 /* assume DMA will be successful */
677 left -= count; 683 left -= count;
678 buf += count; 684 buf += count;
679 if (dma_handle) dma_addr += count; 685 if (dma_handle)
686 dma_addr += count;
680 687
681 /* Wait for interrupt. */ 688 /* Wait for interrupt. */
682 false_alarm: 689false_alarm:
683 ret = parport_wait_event (port, HZ); 690 ret = parport_wait_event(port, HZ);
684 if (ret < 0) break; 691 if (ret < 0)
692 break;
685 ret = 0; 693 ret = 0;
686 if (!time_before (jiffies, expire)) { 694 if (!time_before(jiffies, expire)) {
687 /* Timed out. */ 695 /* Timed out. */
688 printk (KERN_DEBUG "DMA write timed out\n"); 696 printk(KERN_DEBUG "DMA write timed out\n");
689 break; 697 break;
690 } 698 }
691 /* Is serviceIntr set? */ 699 /* Is serviceIntr set? */
692 if (!(inb (ECONTROL (port)) & (1<<2))) { 700 if (!(inb(ECONTROL(port)) & (1<<2))) {
693 cond_resched(); 701 cond_resched();
694 702
695 goto false_alarm; 703 goto false_alarm;
@@ -705,14 +713,15 @@ dump_parport_state ("enter fifo_write_block_dma", port);
705 713
706 /* Anyone else waiting for the port? */ 714 /* Anyone else waiting for the port? */
707 if (port->waithead) { 715 if (port->waithead) {
708 printk (KERN_DEBUG "Somebody wants the port\n"); 716 printk(KERN_DEBUG "Somebody wants the port\n");
709 break; 717 break;
710 } 718 }
711 719
712 /* update for possible DMA residue ! */ 720 /* update for possible DMA residue ! */
713 buf -= count; 721 buf -= count;
714 left += count; 722 left += count;
715 if (dma_handle) dma_addr -= count; 723 if (dma_handle)
724 dma_addr -= count;
716 } 725 }
717 726
718 /* Maybe got here through break, so adjust for DMA residue! */ 727 /* Maybe got here through break, so adjust for DMA residue! */
@@ -723,12 +732,12 @@ dump_parport_state ("enter fifo_write_block_dma", port);
723 release_dma_lock(dmaflag); 732 release_dma_lock(dmaflag);
724 733
725 /* Turn off DMA mode */ 734 /* Turn off DMA mode */
726 frob_econtrol (port, 1<<3, 0); 735 frob_econtrol(port, 1<<3, 0);
727 736
728 if (dma_handle) 737 if (dma_handle)
729 dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE); 738 dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE);
730 739
731dump_parport_state ("leave fifo_write_block_dma", port); 740 dump_parport_state("leave fifo_write_block_dma", port);
732 return length - left; 741 return length - left;
733} 742}
734#endif 743#endif
@@ -738,13 +747,13 @@ static inline size_t parport_pc_fifo_write_block(struct parport *port,
738{ 747{
739#ifdef HAS_DMA 748#ifdef HAS_DMA
740 if (port->dma != PARPORT_DMA_NONE) 749 if (port->dma != PARPORT_DMA_NONE)
741 return parport_pc_fifo_write_block_dma (port, buf, length); 750 return parport_pc_fifo_write_block_dma(port, buf, length);
742#endif 751#endif
743 return parport_pc_fifo_write_block_pio (port, buf, length); 752 return parport_pc_fifo_write_block_pio(port, buf, length);
744} 753}
745 754
746/* Parallel Port FIFO mode (ECP chipsets) */ 755/* Parallel Port FIFO mode (ECP chipsets) */
747static size_t parport_pc_compat_write_block_pio (struct parport *port, 756static size_t parport_pc_compat_write_block_pio(struct parport *port,
748 const void *buf, size_t length, 757 const void *buf, size_t length,
749 int flags) 758 int flags)
750{ 759{
@@ -756,14 +765,16 @@ static size_t parport_pc_compat_write_block_pio (struct parport *port,
756 /* Special case: a timeout of zero means we cannot call schedule(). 765 /* Special case: a timeout of zero means we cannot call schedule().
757 * Also if O_NONBLOCK is set then use the default implementation. */ 766 * Also if O_NONBLOCK is set then use the default implementation. */
758 if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) 767 if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
759 return parport_ieee1284_write_compat (port, buf, 768 return parport_ieee1284_write_compat(port, buf,
760 length, flags); 769 length, flags);
761 770
762 /* Set up parallel port FIFO mode.*/ 771 /* Set up parallel port FIFO mode.*/
763 parport_pc_data_forward (port); /* Must be in PS2 mode */ 772 parport_pc_data_forward(port); /* Must be in PS2 mode */
764 parport_pc_frob_control (port, PARPORT_CONTROL_STROBE, 0); 773 parport_pc_frob_control(port, PARPORT_CONTROL_STROBE, 0);
765 r = change_mode (port, ECR_PPF); /* Parallel port FIFO */ 774 r = change_mode(port, ECR_PPF); /* Parallel port FIFO */
766 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_PPF failed\n", port->name); 775 if (r)
776 printk(KERN_DEBUG "%s: Warning change_mode ECR_PPF failed\n",
777 port->name);
767 778
768 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA; 779 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
769 780
@@ -775,40 +786,39 @@ static size_t parport_pc_compat_write_block_pio (struct parport *port,
775 * the FIFO is empty, so allow 4 seconds for each position 786 * the FIFO is empty, so allow 4 seconds for each position
776 * in the fifo. 787 * in the fifo.
777 */ 788 */
778 expire = jiffies + (priv->fifo_depth * HZ * 4); 789 expire = jiffies + (priv->fifo_depth * HZ * 4);
779 do { 790 do {
780 /* Wait for the FIFO to empty */ 791 /* Wait for the FIFO to empty */
781 r = change_mode (port, ECR_PS2); 792 r = change_mode(port, ECR_PS2);
782 if (r != -EBUSY) { 793 if (r != -EBUSY)
783 break; 794 break;
784 } 795 } while (time_before(jiffies, expire));
785 } while (time_before (jiffies, expire));
786 if (r == -EBUSY) { 796 if (r == -EBUSY) {
787 797
788 printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name); 798 printk(KERN_DEBUG "%s: FIFO is stuck\n", port->name);
789 799
790 /* Prevent further data transfer. */ 800 /* Prevent further data transfer. */
791 frob_set_mode (port, ECR_TST); 801 frob_set_mode(port, ECR_TST);
792 802
793 /* Adjust for the contents of the FIFO. */ 803 /* Adjust for the contents of the FIFO. */
794 for (written -= priv->fifo_depth; ; written++) { 804 for (written -= priv->fifo_depth; ; written++) {
795 if (inb (ECONTROL (port)) & 0x2) { 805 if (inb(ECONTROL(port)) & 0x2) {
796 /* Full up. */ 806 /* Full up. */
797 break; 807 break;
798 } 808 }
799 outb (0, FIFO (port)); 809 outb(0, FIFO(port));
800 } 810 }
801 811
802 /* Reset the FIFO and return to PS2 mode. */ 812 /* Reset the FIFO and return to PS2 mode. */
803 frob_set_mode (port, ECR_PS2); 813 frob_set_mode(port, ECR_PS2);
804 } 814 }
805 815
806 r = parport_wait_peripheral (port, 816 r = parport_wait_peripheral(port,
807 PARPORT_STATUS_BUSY, 817 PARPORT_STATUS_BUSY,
808 PARPORT_STATUS_BUSY); 818 PARPORT_STATUS_BUSY);
809 if (r) 819 if (r)
810 printk (KERN_DEBUG 820 printk(KERN_DEBUG
811 "%s: BUSY timeout (%d) in compat_write_block_pio\n", 821 "%s: BUSY timeout (%d) in compat_write_block_pio\n",
812 port->name, r); 822 port->name, r);
813 823
814 port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE; 824 port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
@@ -818,7 +828,7 @@ static size_t parport_pc_compat_write_block_pio (struct parport *port,
818 828
819/* ECP */ 829/* ECP */
820#ifdef CONFIG_PARPORT_1284 830#ifdef CONFIG_PARPORT_1284
821static size_t parport_pc_ecp_write_block_pio (struct parport *port, 831static size_t parport_pc_ecp_write_block_pio(struct parport *port,
822 const void *buf, size_t length, 832 const void *buf, size_t length,
823 int flags) 833 int flags)
824{ 834{
@@ -830,36 +840,38 @@ static size_t parport_pc_ecp_write_block_pio (struct parport *port,
830 /* Special case: a timeout of zero means we cannot call schedule(). 840 /* Special case: a timeout of zero means we cannot call schedule().
831 * Also if O_NONBLOCK is set then use the default implementation. */ 841 * Also if O_NONBLOCK is set then use the default implementation. */
832 if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) 842 if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
833 return parport_ieee1284_ecp_write_data (port, buf, 843 return parport_ieee1284_ecp_write_data(port, buf,
834 length, flags); 844 length, flags);
835 845
836 /* Switch to forward mode if necessary. */ 846 /* Switch to forward mode if necessary. */
837 if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) { 847 if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) {
838 /* Event 47: Set nInit high. */ 848 /* Event 47: Set nInit high. */
839 parport_frob_control (port, 849 parport_frob_control(port,
840 PARPORT_CONTROL_INIT 850 PARPORT_CONTROL_INIT
841 | PARPORT_CONTROL_AUTOFD, 851 | PARPORT_CONTROL_AUTOFD,
842 PARPORT_CONTROL_INIT 852 PARPORT_CONTROL_INIT
843 | PARPORT_CONTROL_AUTOFD); 853 | PARPORT_CONTROL_AUTOFD);
844 854
845 /* Event 49: PError goes high. */ 855 /* Event 49: PError goes high. */
846 r = parport_wait_peripheral (port, 856 r = parport_wait_peripheral(port,
847 PARPORT_STATUS_PAPEROUT, 857 PARPORT_STATUS_PAPEROUT,
848 PARPORT_STATUS_PAPEROUT); 858 PARPORT_STATUS_PAPEROUT);
849 if (r) { 859 if (r) {
850 printk (KERN_DEBUG "%s: PError timeout (%d) " 860 printk(KERN_DEBUG "%s: PError timeout (%d) "
851 "in ecp_write_block_pio\n", port->name, r); 861 "in ecp_write_block_pio\n", port->name, r);
852 } 862 }
853 } 863 }
854 864
855 /* Set up ECP parallel port mode.*/ 865 /* Set up ECP parallel port mode.*/
856 parport_pc_data_forward (port); /* Must be in PS2 mode */ 866 parport_pc_data_forward(port); /* Must be in PS2 mode */
857 parport_pc_frob_control (port, 867 parport_pc_frob_control(port,
858 PARPORT_CONTROL_STROBE | 868 PARPORT_CONTROL_STROBE |
859 PARPORT_CONTROL_AUTOFD, 869 PARPORT_CONTROL_AUTOFD,
860 0); 870 0);
861 r = change_mode (port, ECR_ECP); /* ECP FIFO */ 871 r = change_mode(port, ECR_ECP); /* ECP FIFO */
862 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name); 872 if (r)
873 printk(KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n",
874 port->name);
863 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA; 875 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
864 876
865 /* Write the data to the FIFO. */ 877 /* Write the data to the FIFO. */
@@ -873,55 +885,54 @@ static size_t parport_pc_ecp_write_block_pio (struct parport *port,
873 expire = jiffies + (priv->fifo_depth * (HZ * 4)); 885 expire = jiffies + (priv->fifo_depth * (HZ * 4));
874 do { 886 do {
875 /* Wait for the FIFO to empty */ 887 /* Wait for the FIFO to empty */
876 r = change_mode (port, ECR_PS2); 888 r = change_mode(port, ECR_PS2);
877 if (r != -EBUSY) { 889 if (r != -EBUSY)
878 break; 890 break;
879 } 891 } while (time_before(jiffies, expire));
880 } while (time_before (jiffies, expire));
881 if (r == -EBUSY) { 892 if (r == -EBUSY) {
882 893
883 printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name); 894 printk(KERN_DEBUG "%s: FIFO is stuck\n", port->name);
884 895
885 /* Prevent further data transfer. */ 896 /* Prevent further data transfer. */
886 frob_set_mode (port, ECR_TST); 897 frob_set_mode(port, ECR_TST);
887 898
888 /* Adjust for the contents of the FIFO. */ 899 /* Adjust for the contents of the FIFO. */
889 for (written -= priv->fifo_depth; ; written++) { 900 for (written -= priv->fifo_depth; ; written++) {
890 if (inb (ECONTROL (port)) & 0x2) { 901 if (inb(ECONTROL(port)) & 0x2) {
891 /* Full up. */ 902 /* Full up. */
892 break; 903 break;
893 } 904 }
894 outb (0, FIFO (port)); 905 outb(0, FIFO(port));
895 } 906 }
896 907
897 /* Reset the FIFO and return to PS2 mode. */ 908 /* Reset the FIFO and return to PS2 mode. */
898 frob_set_mode (port, ECR_PS2); 909 frob_set_mode(port, ECR_PS2);
899 910
900 /* Host transfer recovery. */ 911 /* Host transfer recovery. */
901 parport_pc_data_reverse (port); /* Must be in PS2 mode */ 912 parport_pc_data_reverse(port); /* Must be in PS2 mode */
902 udelay (5); 913 udelay(5);
903 parport_frob_control (port, PARPORT_CONTROL_INIT, 0); 914 parport_frob_control(port, PARPORT_CONTROL_INIT, 0);
904 r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0); 915 r = parport_wait_peripheral(port, PARPORT_STATUS_PAPEROUT, 0);
905 if (r) 916 if (r)
906 printk (KERN_DEBUG "%s: PE,1 timeout (%d) " 917 printk(KERN_DEBUG "%s: PE,1 timeout (%d) "
907 "in ecp_write_block_pio\n", port->name, r); 918 "in ecp_write_block_pio\n", port->name, r);
908 919
909 parport_frob_control (port, 920 parport_frob_control(port,
910 PARPORT_CONTROL_INIT, 921 PARPORT_CONTROL_INIT,
911 PARPORT_CONTROL_INIT); 922 PARPORT_CONTROL_INIT);
912 r = parport_wait_peripheral (port, 923 r = parport_wait_peripheral(port,
913 PARPORT_STATUS_PAPEROUT, 924 PARPORT_STATUS_PAPEROUT,
914 PARPORT_STATUS_PAPEROUT); 925 PARPORT_STATUS_PAPEROUT);
915 if (r) 926 if (r)
916 printk (KERN_DEBUG "%s: PE,2 timeout (%d) " 927 printk(KERN_DEBUG "%s: PE,2 timeout (%d) "
917 "in ecp_write_block_pio\n", port->name, r); 928 "in ecp_write_block_pio\n", port->name, r);
918 } 929 }
919 930
920 r = parport_wait_peripheral (port, 931 r = parport_wait_peripheral(port,
921 PARPORT_STATUS_BUSY, 932 PARPORT_STATUS_BUSY,
922 PARPORT_STATUS_BUSY); 933 PARPORT_STATUS_BUSY);
923 if(r) 934 if (r)
924 printk (KERN_DEBUG 935 printk(KERN_DEBUG
925 "%s: BUSY timeout (%d) in ecp_write_block_pio\n", 936 "%s: BUSY timeout (%d) in ecp_write_block_pio\n",
926 port->name, r); 937 port->name, r);
927 938
@@ -931,7 +942,7 @@ static size_t parport_pc_ecp_write_block_pio (struct parport *port,
931} 942}
932 943
933#if 0 944#if 0
934static size_t parport_pc_ecp_read_block_pio (struct parport *port, 945static size_t parport_pc_ecp_read_block_pio(struct parport *port,
935 void *buf, size_t length, 946 void *buf, size_t length,
936 int flags) 947 int flags)
937{ 948{
@@ -944,13 +955,13 @@ static size_t parport_pc_ecp_read_block_pio (struct parport *port,
944 char *bufp = buf; 955 char *bufp = buf;
945 956
946 port = port->physport; 957 port = port->physport;
947DPRINTK (KERN_DEBUG "parport_pc: parport_pc_ecp_read_block_pio\n"); 958 DPRINTK(KERN_DEBUG "parport_pc: parport_pc_ecp_read_block_pio\n");
948dump_parport_state ("enter fcn", port); 959 dump_parport_state("enter fcn", port);
949 960
950 /* Special case: a timeout of zero means we cannot call schedule(). 961 /* Special case: a timeout of zero means we cannot call schedule().
951 * Also if O_NONBLOCK is set then use the default implementation. */ 962 * Also if O_NONBLOCK is set then use the default implementation. */
952 if (port->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) 963 if (port->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
953 return parport_ieee1284_ecp_read_data (port, buf, 964 return parport_ieee1284_ecp_read_data(port, buf,
954 length, flags); 965 length, flags);
955 966
956 if (port->ieee1284.mode == IEEE1284_MODE_ECPRLE) { 967 if (port->ieee1284.mode == IEEE1284_MODE_ECPRLE) {
@@ -966,173 +977,178 @@ dump_parport_state ("enter fcn", port);
966 * go through software emulation. Otherwise we may have to throw 977 * go through software emulation. Otherwise we may have to throw
967 * away data. */ 978 * away data. */
968 if (length < fifofull) 979 if (length < fifofull)
969 return parport_ieee1284_ecp_read_data (port, buf, 980 return parport_ieee1284_ecp_read_data(port, buf,
970 length, flags); 981 length, flags);
971 982
972 if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE) { 983 if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE) {
973 /* change to reverse-idle phase (must be in forward-idle) */ 984 /* change to reverse-idle phase (must be in forward-idle) */
974 985
975 /* Event 38: Set nAutoFd low (also make sure nStrobe is high) */ 986 /* Event 38: Set nAutoFd low (also make sure nStrobe is high) */
976 parport_frob_control (port, 987 parport_frob_control(port,
977 PARPORT_CONTROL_AUTOFD 988 PARPORT_CONTROL_AUTOFD
978 | PARPORT_CONTROL_STROBE, 989 | PARPORT_CONTROL_STROBE,
979 PARPORT_CONTROL_AUTOFD); 990 PARPORT_CONTROL_AUTOFD);
980 parport_pc_data_reverse (port); /* Must be in PS2 mode */ 991 parport_pc_data_reverse(port); /* Must be in PS2 mode */
981 udelay (5); 992 udelay(5);
982 /* Event 39: Set nInit low to initiate bus reversal */ 993 /* Event 39: Set nInit low to initiate bus reversal */
983 parport_frob_control (port, 994 parport_frob_control(port,
984 PARPORT_CONTROL_INIT, 995 PARPORT_CONTROL_INIT,
985 0); 996 0);
986 /* Event 40: Wait for nAckReverse (PError) to go low */ 997 /* Event 40: Wait for nAckReverse (PError) to go low */
987 r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0); 998 r = parport_wait_peripheral(port, PARPORT_STATUS_PAPEROUT, 0);
988 if (r) { 999 if (r) {
989 printk (KERN_DEBUG "%s: PE timeout Event 40 (%d) " 1000 printk(KERN_DEBUG "%s: PE timeout Event 40 (%d) "
990 "in ecp_read_block_pio\n", port->name, r); 1001 "in ecp_read_block_pio\n", port->name, r);
991 return 0; 1002 return 0;
992 } 1003 }
993 } 1004 }
994 1005
995 /* Set up ECP FIFO mode.*/ 1006 /* Set up ECP FIFO mode.*/
996/* parport_pc_frob_control (port, 1007/* parport_pc_frob_control(port,
997 PARPORT_CONTROL_STROBE | 1008 PARPORT_CONTROL_STROBE |
998 PARPORT_CONTROL_AUTOFD, 1009 PARPORT_CONTROL_AUTOFD,
999 PARPORT_CONTROL_AUTOFD); */ 1010 PARPORT_CONTROL_AUTOFD); */
1000 r = change_mode (port, ECR_ECP); /* ECP FIFO */ 1011 r = change_mode(port, ECR_ECP); /* ECP FIFO */
1001 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name); 1012 if (r)
1013 printk(KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n",
1014 port->name);
1002 1015
1003 port->ieee1284.phase = IEEE1284_PH_REV_DATA; 1016 port->ieee1284.phase = IEEE1284_PH_REV_DATA;
1004 1017
1005 /* the first byte must be collected manually */ 1018 /* the first byte must be collected manually */
1006dump_parport_state ("pre 43", port); 1019 dump_parport_state("pre 43", port);
1007 /* Event 43: Wait for nAck to go low */ 1020 /* Event 43: Wait for nAck to go low */
1008 r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0); 1021 r = parport_wait_peripheral(port, PARPORT_STATUS_ACK, 0);
1009 if (r) { 1022 if (r) {
1010 /* timed out while reading -- no data */ 1023 /* timed out while reading -- no data */
1011 printk (KERN_DEBUG "PIO read timed out (initial byte)\n"); 1024 printk(KERN_DEBUG "PIO read timed out (initial byte)\n");
1012 goto out_no_data; 1025 goto out_no_data;
1013 } 1026 }
1014 /* read byte */ 1027 /* read byte */
1015 *bufp++ = inb (DATA (port)); 1028 *bufp++ = inb(DATA(port));
1016 left--; 1029 left--;
1017dump_parport_state ("43-44", port); 1030 dump_parport_state("43-44", port);
1018 /* Event 44: nAutoFd (HostAck) goes high to acknowledge */ 1031 /* Event 44: nAutoFd (HostAck) goes high to acknowledge */
1019 parport_pc_frob_control (port, 1032 parport_pc_frob_control(port,
1020 PARPORT_CONTROL_AUTOFD, 1033 PARPORT_CONTROL_AUTOFD,
1021 0); 1034 0);
1022dump_parport_state ("pre 45", port); 1035 dump_parport_state("pre 45", port);
1023 /* Event 45: Wait for nAck to go high */ 1036 /* Event 45: Wait for nAck to go high */
1024/* r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, PARPORT_STATUS_ACK); */ 1037 /* r = parport_wait_peripheral(port, PARPORT_STATUS_ACK,
1025dump_parport_state ("post 45", port); 1038 PARPORT_STATUS_ACK); */
1026r = 0; 1039 dump_parport_state("post 45", port);
1040 r = 0;
1027 if (r) { 1041 if (r) {
1028 /* timed out while waiting for peripheral to respond to ack */ 1042 /* timed out while waiting for peripheral to respond to ack */
1029 printk (KERN_DEBUG "ECP PIO read timed out (waiting for nAck)\n"); 1043 printk(KERN_DEBUG "ECP PIO read timed out (waiting for nAck)\n");
1030 1044
1031 /* keep hold of the byte we've got already */ 1045 /* keep hold of the byte we've got already */
1032 goto out_no_data; 1046 goto out_no_data;
1033 } 1047 }
1034 /* Event 46: nAutoFd (HostAck) goes low to accept more data */ 1048 /* Event 46: nAutoFd (HostAck) goes low to accept more data */
1035 parport_pc_frob_control (port, 1049 parport_pc_frob_control(port,
1036 PARPORT_CONTROL_AUTOFD, 1050 PARPORT_CONTROL_AUTOFD,
1037 PARPORT_CONTROL_AUTOFD); 1051 PARPORT_CONTROL_AUTOFD);
1038 1052
1039 1053
1040dump_parport_state ("rev idle", port); 1054 dump_parport_state("rev idle", port);
1041 /* Do the transfer. */ 1055 /* Do the transfer. */
1042 while (left > fifofull) { 1056 while (left > fifofull) {
1043 int ret; 1057 int ret;
1044 unsigned long expire = jiffies + port->cad->timeout; 1058 unsigned long expire = jiffies + port->cad->timeout;
1045 unsigned char ecrval = inb (ECONTROL (port)); 1059 unsigned char ecrval = inb(ECONTROL(port));
1046 1060
1047 if (need_resched() && time_before (jiffies, expire)) 1061 if (need_resched() && time_before(jiffies, expire))
1048 /* Can't yield the port. */ 1062 /* Can't yield the port. */
1049 schedule (); 1063 schedule();
1050 1064
1051 /* At this point, the FIFO may already be full. In 1065 /* At this point, the FIFO may already be full. In
1052 * that case ECP is already holding back the 1066 * that case ECP is already holding back the
1053 * peripheral (assuming proper design) with a delayed 1067 * peripheral (assuming proper design) with a delayed
1054 * handshake. Work fast to avoid a peripheral 1068 * handshake. Work fast to avoid a peripheral
1055 * timeout. */ 1069 * timeout. */
1056 1070
1057 if (ecrval & 0x01) { 1071 if (ecrval & 0x01) {
1058 /* FIFO is empty. Wait for interrupt. */ 1072 /* FIFO is empty. Wait for interrupt. */
1059dump_parport_state ("FIFO empty", port); 1073 dump_parport_state("FIFO empty", port);
1060 1074
1061 /* Anyone else waiting for the port? */ 1075 /* Anyone else waiting for the port? */
1062 if (port->waithead) { 1076 if (port->waithead) {
1063 printk (KERN_DEBUG "Somebody wants the port\n"); 1077 printk(KERN_DEBUG "Somebody wants the port\n");
1064 break; 1078 break;
1065 } 1079 }
1066 1080
1067 /* Clear serviceIntr */ 1081 /* Clear serviceIntr */
1068 ECR_WRITE (port, ecrval & ~(1<<2)); 1082 ECR_WRITE(port, ecrval & ~(1<<2));
1069 false_alarm: 1083false_alarm:
1070dump_parport_state ("waiting", port); 1084 dump_parport_state("waiting", port);
1071 ret = parport_wait_event (port, HZ); 1085 ret = parport_wait_event(port, HZ);
1072DPRINTK (KERN_DEBUG "parport_wait_event returned %d\n", ret); 1086 DPRINTK(KERN_DEBUG "parport_wait_event returned %d\n",
1087 ret);
1073 if (ret < 0) 1088 if (ret < 0)
1074 break; 1089 break;
1075 ret = 0; 1090 ret = 0;
1076 if (!time_before (jiffies, expire)) { 1091 if (!time_before(jiffies, expire)) {
1077 /* Timed out. */ 1092 /* Timed out. */
1078dump_parport_state ("timeout", port); 1093 dump_parport_state("timeout", port);
1079 printk (KERN_DEBUG "PIO read timed out\n"); 1094 printk(KERN_DEBUG "PIO read timed out\n");
1080 break; 1095 break;
1081 } 1096 }
1082 ecrval = inb (ECONTROL (port)); 1097 ecrval = inb(ECONTROL(port));
1083 if (!(ecrval & (1<<2))) { 1098 if (!(ecrval & (1<<2))) {
1084 if (need_resched() && 1099 if (need_resched() &&
1085 time_before (jiffies, expire)) { 1100 time_before(jiffies, expire)) {
1086 schedule (); 1101 schedule();
1087 } 1102 }
1088 goto false_alarm; 1103 goto false_alarm;
1089 } 1104 }
1090 1105
1091 /* Depending on how the FIFO threshold was 1106 /* Depending on how the FIFO threshold was
1092 * set, how long interrupt service took, and 1107 * set, how long interrupt service took, and
1093 * how fast the peripheral is, we might be 1108 * how fast the peripheral is, we might be
1094 * lucky and have a just filled FIFO. */ 1109 * lucky and have a just filled FIFO. */
1095 continue; 1110 continue;
1096 } 1111 }
1097 1112
1098 if (ecrval & 0x02) { 1113 if (ecrval & 0x02) {
1099 /* FIFO is full. */ 1114 /* FIFO is full. */
1100dump_parport_state ("FIFO full", port); 1115 dump_parport_state("FIFO full", port);
1101 insb (fifo, bufp, fifo_depth); 1116 insb(fifo, bufp, fifo_depth);
1102 bufp += fifo_depth; 1117 bufp += fifo_depth;
1103 left -= fifo_depth; 1118 left -= fifo_depth;
1104 continue; 1119 continue;
1105 } 1120 }
1106 1121
1107DPRINTK (KERN_DEBUG "*** ecp_read_block_pio: reading one byte from the FIFO\n"); 1122 DPRINTK(KERN_DEBUG
1123 "*** ecp_read_block_pio: reading one byte from the FIFO\n");
1108 1124
1109 /* FIFO not filled. We will cycle this loop for a while 1125 /* FIFO not filled. We will cycle this loop for a while
1110 * and either the peripheral will fill it faster, 1126 * and either the peripheral will fill it faster,
1111 * tripping a fast empty with insb, or we empty it. */ 1127 * tripping a fast empty with insb, or we empty it. */
1112 *bufp++ = inb (fifo); 1128 *bufp++ = inb(fifo);
1113 left--; 1129 left--;
1114 } 1130 }
1115 1131
1116 /* scoop up anything left in the FIFO */ 1132 /* scoop up anything left in the FIFO */
1117 while (left && !(inb (ECONTROL (port) & 0x01))) { 1133 while (left && !(inb(ECONTROL(port) & 0x01))) {
1118 *bufp++ = inb (fifo); 1134 *bufp++ = inb(fifo);
1119 left--; 1135 left--;
1120 } 1136 }
1121 1137
1122 port->ieee1284.phase = IEEE1284_PH_REV_IDLE; 1138 port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
1123dump_parport_state ("rev idle2", port); 1139 dump_parport_state("rev idle2", port);
1124 1140
1125out_no_data: 1141out_no_data:
1126 1142
1127 /* Go to forward idle mode to shut the peripheral up (event 47). */ 1143 /* Go to forward idle mode to shut the peripheral up (event 47). */
1128 parport_frob_control (port, PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT); 1144 parport_frob_control(port, PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT);
1129 1145
1130 /* event 49: PError goes high */ 1146 /* event 49: PError goes high */
1131 r = parport_wait_peripheral (port, 1147 r = parport_wait_peripheral(port,
1132 PARPORT_STATUS_PAPEROUT, 1148 PARPORT_STATUS_PAPEROUT,
1133 PARPORT_STATUS_PAPEROUT); 1149 PARPORT_STATUS_PAPEROUT);
1134 if (r) { 1150 if (r) {
1135 printk (KERN_DEBUG 1151 printk(KERN_DEBUG
1136 "%s: PE timeout FWDIDLE (%d) in ecp_read_block_pio\n", 1152 "%s: PE timeout FWDIDLE (%d) in ecp_read_block_pio\n",
1137 port->name, r); 1153 port->name, r);
1138 } 1154 }
@@ -1141,14 +1157,14 @@ out_no_data:
1141 1157
1142 /* Finish up. */ 1158 /* Finish up. */
1143 { 1159 {
1144 int lost = get_fifo_residue (port); 1160 int lost = get_fifo_residue(port);
1145 if (lost) 1161 if (lost)
1146 /* Shouldn't happen with compliant peripherals. */ 1162 /* Shouldn't happen with compliant peripherals. */
1147 printk (KERN_DEBUG "%s: DATA LOSS (%d bytes)!\n", 1163 printk(KERN_DEBUG "%s: DATA LOSS (%d bytes)!\n",
1148 port->name, lost); 1164 port->name, lost);
1149 } 1165 }
1150 1166
1151dump_parport_state ("fwd idle", port); 1167 dump_parport_state("fwd idle", port);
1152 return length - left; 1168 return length - left;
1153} 1169}
1154#endif /* 0 */ 1170#endif /* 0 */
@@ -1164,8 +1180,7 @@ dump_parport_state ("fwd idle", port);
1164 1180
1165/* GCC is not inlining extern inline function later overwriten to non-inline, 1181/* GCC is not inlining extern inline function later overwriten to non-inline,
1166 so we use outlined_ variants here. */ 1182 so we use outlined_ variants here. */
1167static const struct parport_operations parport_pc_ops = 1183static const struct parport_operations parport_pc_ops = {
1168{
1169 .write_data = parport_pc_write_data, 1184 .write_data = parport_pc_write_data,
1170 .read_data = parport_pc_read_data, 1185 .read_data = parport_pc_read_data,
1171 1186
@@ -1202,88 +1217,107 @@ static const struct parport_operations parport_pc_ops =
1202}; 1217};
1203 1218
1204#ifdef CONFIG_PARPORT_PC_SUPERIO 1219#ifdef CONFIG_PARPORT_PC_SUPERIO
1220
1221static struct superio_struct *find_free_superio(void)
1222{
1223 int i;
1224 for (i = 0; i < NR_SUPERIOS; i++)
1225 if (superios[i].io == 0)
1226 return &superios[i];
1227 return NULL;
1228}
1229
1230
1205/* Super-IO chipset detection, Winbond, SMSC */ 1231/* Super-IO chipset detection, Winbond, SMSC */
1206static void __devinit show_parconfig_smsc37c669(int io, int key) 1232static void __devinit show_parconfig_smsc37c669(int io, int key)
1207{ 1233{
1208 int cr1,cr4,cra,cr23,cr26,cr27,i=0; 1234 int cr1, cr4, cra, cr23, cr26, cr27;
1209 static const char *const modes[]={ 1235 struct superio_struct *s;
1236
1237 static const char *const modes[] = {
1210 "SPP and Bidirectional (PS/2)", 1238 "SPP and Bidirectional (PS/2)",
1211 "EPP and SPP", 1239 "EPP and SPP",
1212 "ECP", 1240 "ECP",
1213 "ECP and EPP" }; 1241 "ECP and EPP" };
1214 1242
1215 outb(key,io); 1243 outb(key, io);
1216 outb(key,io); 1244 outb(key, io);
1217 outb(1,io); 1245 outb(1, io);
1218 cr1=inb(io+1); 1246 cr1 = inb(io + 1);
1219 outb(4,io); 1247 outb(4, io);
1220 cr4=inb(io+1); 1248 cr4 = inb(io + 1);
1221 outb(0x0a,io); 1249 outb(0x0a, io);
1222 cra=inb(io+1); 1250 cra = inb(io + 1);
1223 outb(0x23,io); 1251 outb(0x23, io);
1224 cr23=inb(io+1); 1252 cr23 = inb(io + 1);
1225 outb(0x26,io); 1253 outb(0x26, io);
1226 cr26=inb(io+1); 1254 cr26 = inb(io + 1);
1227 outb(0x27,io); 1255 outb(0x27, io);
1228 cr27=inb(io+1); 1256 cr27 = inb(io + 1);
1229 outb(0xaa,io); 1257 outb(0xaa, io);
1230 1258
1231 if (verbose_probing) { 1259 if (verbose_probing) {
1232 printk (KERN_INFO "SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, " 1260 printk(KERN_INFO
1261 "SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, "
1233 "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n", 1262 "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n",
1234 cr1,cr4,cra,cr23,cr26,cr27); 1263 cr1, cr4, cra, cr23, cr26, cr27);
1235 1264
1236 /* The documentation calls DMA and IRQ-Lines by letters, so 1265 /* The documentation calls DMA and IRQ-Lines by letters, so
1237 the board maker can/will wire them 1266 the board maker can/will wire them
1238 appropriately/randomly... G=reserved H=IDE-irq, */ 1267 appropriately/randomly... G=reserved H=IDE-irq, */
1239 printk (KERN_INFO "SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, " 1268 printk(KERN_INFO
1240 "fifo threshold=%d\n", cr23*4, 1269 "SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, fifo threshold=%d\n",
1241 (cr27 &0x0f) ? 'A'-1+(cr27 &0x0f): '-', 1270 cr23 * 4,
1242 (cr26 &0x0f) ? 'A'-1+(cr26 &0x0f): '-', cra & 0x0f); 1271 (cr27 & 0x0f) ? 'A' - 1 + (cr27 & 0x0f) : '-',
1272 (cr26 & 0x0f) ? 'A' - 1 + (cr26 & 0x0f) : '-',
1273 cra & 0x0f);
1243 printk(KERN_INFO "SMSC LPT Config: enabled=%s power=%s\n", 1274 printk(KERN_INFO "SMSC LPT Config: enabled=%s power=%s\n",
1244 (cr23*4 >=0x100) ?"yes":"no", (cr1 & 4) ? "yes" : "no"); 1275 (cr23 * 4 >= 0x100) ? "yes" : "no",
1245 printk(KERN_INFO "SMSC LPT Config: Port mode=%s, EPP version =%s\n", 1276 (cr1 & 4) ? "yes" : "no");
1246 (cr1 & 0x08 ) ? "Standard mode only (SPP)" : modes[cr4 & 0x03], 1277 printk(KERN_INFO
1247 (cr4 & 0x40) ? "1.7" : "1.9"); 1278 "SMSC LPT Config: Port mode=%s, EPP version =%s\n",
1279 (cr1 & 0x08) ? "Standard mode only (SPP)"
1280 : modes[cr4 & 0x03],
1281 (cr4 & 0x40) ? "1.7" : "1.9");
1248 } 1282 }
1249 1283
1250 /* Heuristics ! BIOS setup for this mainboard device limits 1284 /* Heuristics ! BIOS setup for this mainboard device limits
1251 the choices to standard settings, i.e. io-address and IRQ 1285 the choices to standard settings, i.e. io-address and IRQ
1252 are related, however DMA can be 1 or 3, assume DMA_A=DMA1, 1286 are related, however DMA can be 1 or 3, assume DMA_A=DMA1,
1253 DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */ 1287 DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */
1254 if(cr23*4 >=0x100) { /* if active */ 1288 if (cr23 * 4 >= 0x100) { /* if active */
1255 while((superios[i].io!= 0) && (i<NR_SUPERIOS)) 1289 s = find_free_superio();
1256 i++; 1290 if (s == NULL)
1257 if(i==NR_SUPERIOS)
1258 printk(KERN_INFO "Super-IO: too many chips!\n"); 1291 printk(KERN_INFO "Super-IO: too many chips!\n");
1259 else { 1292 else {
1260 int d; 1293 int d;
1261 switch (cr23*4) { 1294 switch (cr23 * 4) {
1262 case 0x3bc: 1295 case 0x3bc:
1263 superios[i].io = 0x3bc; 1296 s->io = 0x3bc;
1264 superios[i].irq = 7; 1297 s->irq = 7;
1265 break; 1298 break;
1266 case 0x378: 1299 case 0x378:
1267 superios[i].io = 0x378; 1300 s->io = 0x378;
1268 superios[i].irq = 7; 1301 s->irq = 7;
1269 break; 1302 break;
1270 case 0x278: 1303 case 0x278:
1271 superios[i].io = 0x278; 1304 s->io = 0x278;
1272 superios[i].irq = 5; 1305 s->irq = 5;
1273 } 1306 }
1274 d=(cr26 &0x0f); 1307 d = (cr26 & 0x0f);
1275 if((d==1) || (d==3)) 1308 if (d == 1 || d == 3)
1276 superios[i].dma= d; 1309 s->dma = d;
1277 else 1310 else
1278 superios[i].dma= PARPORT_DMA_NONE; 1311 s->dma = PARPORT_DMA_NONE;
1279 } 1312 }
1280 } 1313 }
1281} 1314}
1282 1315
1283 1316
1284static void __devinit show_parconfig_winbond(int io, int key) 1317static void __devinit show_parconfig_winbond(int io, int key)
1285{ 1318{
1286 int cr30,cr60,cr61,cr70,cr74,crf0,i=0; 1319 int cr30, cr60, cr61, cr70, cr74, crf0;
1320 struct superio_struct *s;
1287 static const char *const modes[] = { 1321 static const char *const modes[] = {
1288 "Standard (SPP) and Bidirectional(PS/2)", /* 0 */ 1322 "Standard (SPP) and Bidirectional(PS/2)", /* 0 */
1289 "EPP-1.9 and SPP", 1323 "EPP-1.9 and SPP",
@@ -1296,110 +1330,134 @@ static void __devinit show_parconfig_winbond(int io, int key)
1296 static char *const irqtypes[] = { 1330 static char *const irqtypes[] = {
1297 "pulsed low, high-Z", 1331 "pulsed low, high-Z",
1298 "follows nACK" }; 1332 "follows nACK" };
1299 1333
1300 /* The registers are called compatible-PnP because the 1334 /* The registers are called compatible-PnP because the
1301 register layout is modelled after ISA-PnP, the access 1335 register layout is modelled after ISA-PnP, the access
1302 method is just another ... */ 1336 method is just another ... */
1303 outb(key,io); 1337 outb(key, io);
1304 outb(key,io); 1338 outb(key, io);
1305 outb(0x07,io); /* Register 7: Select Logical Device */ 1339 outb(0x07, io); /* Register 7: Select Logical Device */
1306 outb(0x01,io+1); /* LD1 is Parallel Port */ 1340 outb(0x01, io + 1); /* LD1 is Parallel Port */
1307 outb(0x30,io); 1341 outb(0x30, io);
1308 cr30=inb(io+1); 1342 cr30 = inb(io + 1);
1309 outb(0x60,io); 1343 outb(0x60, io);
1310 cr60=inb(io+1); 1344 cr60 = inb(io + 1);
1311 outb(0x61,io); 1345 outb(0x61, io);
1312 cr61=inb(io+1); 1346 cr61 = inb(io + 1);
1313 outb(0x70,io); 1347 outb(0x70, io);
1314 cr70=inb(io+1); 1348 cr70 = inb(io + 1);
1315 outb(0x74,io); 1349 outb(0x74, io);
1316 cr74=inb(io+1); 1350 cr74 = inb(io + 1);
1317 outb(0xf0,io); 1351 outb(0xf0, io);
1318 crf0=inb(io+1); 1352 crf0 = inb(io + 1);
1319 outb(0xaa,io); 1353 outb(0xaa, io);
1320 1354
1321 if (verbose_probing) { 1355 if (verbose_probing) {
1322 printk(KERN_INFO "Winbond LPT Config: cr_30=%02x 60,61=%02x%02x " 1356 printk(KERN_INFO
1323 "70=%02x 74=%02x, f0=%02x\n", cr30,cr60,cr61,cr70,cr74,crf0); 1357 "Winbond LPT Config: cr_30=%02x 60,61=%02x%02x 70=%02x 74=%02x, f0=%02x\n",
1324 printk(KERN_INFO "Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ", 1358 cr30, cr60, cr61, cr70, cr74, crf0);
1325 (cr30 & 0x01) ? "yes":"no", cr60,cr61,cr70&0x0f ); 1359 printk(KERN_INFO "Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ",
1360 (cr30 & 0x01) ? "yes" : "no", cr60, cr61, cr70 & 0x0f);
1326 if ((cr74 & 0x07) > 3) 1361 if ((cr74 & 0x07) > 3)
1327 printk("dma=none\n"); 1362 printk("dma=none\n");
1328 else 1363 else
1329 printk("dma=%d\n",cr74 & 0x07); 1364 printk("dma=%d\n", cr74 & 0x07);
1330 printk(KERN_INFO "Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n", 1365 printk(KERN_INFO
1331 irqtypes[crf0>>7], (crf0>>3)&0x0f); 1366 "Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n",
1332 printk(KERN_INFO "Winbond LPT Config: Port mode=%s\n", modes[crf0 & 0x07]); 1367 irqtypes[crf0>>7], (crf0>>3)&0x0f);
1368 printk(KERN_INFO "Winbond LPT Config: Port mode=%s\n",
1369 modes[crf0 & 0x07]);
1333 } 1370 }
1334 1371
1335 if(cr30 & 0x01) { /* the settings can be interrogated later ... */ 1372 if (cr30 & 0x01) { /* the settings can be interrogated later ... */
1336 while((superios[i].io!= 0) && (i<NR_SUPERIOS)) 1373 s = find_free_superio();
1337 i++; 1374 if (s == NULL)
1338 if(i==NR_SUPERIOS)
1339 printk(KERN_INFO "Super-IO: too many chips!\n"); 1375 printk(KERN_INFO "Super-IO: too many chips!\n");
1340 else { 1376 else {
1341 superios[i].io = (cr60<<8)|cr61; 1377 s->io = (cr60 << 8) | cr61;
1342 superios[i].irq = cr70&0x0f; 1378 s->irq = cr70 & 0x0f;
1343 superios[i].dma = (((cr74 & 0x07) > 3) ? 1379 s->dma = (((cr74 & 0x07) > 3) ?
1344 PARPORT_DMA_NONE : (cr74 & 0x07)); 1380 PARPORT_DMA_NONE : (cr74 & 0x07));
1345 } 1381 }
1346 } 1382 }
1347} 1383}
1348 1384
1349static void __devinit decode_winbond(int efer, int key, int devid, int devrev, int oldid) 1385static void __devinit decode_winbond(int efer, int key, int devid,
1386 int devrev, int oldid)
1350{ 1387{
1351 const char *type = "unknown"; 1388 const char *type = "unknown";
1352 int id,progif=2; 1389 int id, progif = 2;
1353 1390
1354 if (devid == devrev) 1391 if (devid == devrev)
1355 /* simple heuristics, we happened to read some 1392 /* simple heuristics, we happened to read some
1356 non-winbond register */ 1393 non-winbond register */
1357 return; 1394 return;
1358 1395
1359 id=(devid<<8) | devrev; 1396 id = (devid << 8) | devrev;
1360 1397
1361 /* Values are from public data sheets pdf files, I can just 1398 /* Values are from public data sheets pdf files, I can just
1362 confirm 83977TF is correct :-) */ 1399 confirm 83977TF is correct :-) */
1363 if (id == 0x9771) type="83977F/AF"; 1400 if (id == 0x9771)
1364 else if (id == 0x9773) type="83977TF / SMSC 97w33x/97w34x"; 1401 type = "83977F/AF";
1365 else if (id == 0x9774) type="83977ATF"; 1402 else if (id == 0x9773)
1366 else if ((id & ~0x0f) == 0x5270) type="83977CTF / SMSC 97w36x"; 1403 type = "83977TF / SMSC 97w33x/97w34x";
1367 else if ((id & ~0x0f) == 0x52f0) type="83977EF / SMSC 97w35x"; 1404 else if (id == 0x9774)
1368 else if ((id & ~0x0f) == 0x5210) type="83627"; 1405 type = "83977ATF";
1369 else if ((id & ~0x0f) == 0x6010) type="83697HF"; 1406 else if ((id & ~0x0f) == 0x5270)
1370 else if ((oldid &0x0f ) == 0x0a) { type="83877F"; progif=1;} 1407 type = "83977CTF / SMSC 97w36x";
1371 else if ((oldid &0x0f ) == 0x0b) { type="83877AF"; progif=1;} 1408 else if ((id & ~0x0f) == 0x52f0)
1372 else if ((oldid &0x0f ) == 0x0c) { type="83877TF"; progif=1;} 1409 type = "83977EF / SMSC 97w35x";
1373 else if ((oldid &0x0f ) == 0x0d) { type="83877ATF"; progif=1;} 1410 else if ((id & ~0x0f) == 0x5210)
1374 else progif=0; 1411 type = "83627";
1412 else if ((id & ~0x0f) == 0x6010)
1413 type = "83697HF";
1414 else if ((oldid & 0x0f) == 0x0a) {
1415 type = "83877F";
1416 progif = 1;
1417 } else if ((oldid & 0x0f) == 0x0b) {
1418 type = "83877AF";
1419 progif = 1;
1420 } else if ((oldid & 0x0f) == 0x0c) {
1421 type = "83877TF";
1422 progif = 1;
1423 } else if ((oldid & 0x0f) == 0x0d) {
1424 type = "83877ATF";
1425 progif = 1;
1426 } else
1427 progif = 0;
1375 1428
1376 if (verbose_probing) 1429 if (verbose_probing)
1377 printk(KERN_INFO "Winbond chip at EFER=0x%x key=0x%02x " 1430 printk(KERN_INFO "Winbond chip at EFER=0x%x key=0x%02x "
1378 "devid=%02x devrev=%02x oldid=%02x type=%s\n", 1431 "devid=%02x devrev=%02x oldid=%02x type=%s\n",
1379 efer, key, devid, devrev, oldid, type); 1432 efer, key, devid, devrev, oldid, type);
1380 1433
1381 if (progif == 2) 1434 if (progif == 2)
1382 show_parconfig_winbond(efer,key); 1435 show_parconfig_winbond(efer, key);
1383} 1436}
1384 1437
1385static void __devinit decode_smsc(int efer, int key, int devid, int devrev) 1438static void __devinit decode_smsc(int efer, int key, int devid, int devrev)
1386{ 1439{
1387 const char *type = "unknown"; 1440 const char *type = "unknown";
1388 void (*func)(int io, int key); 1441 void (*func)(int io, int key);
1389 int id; 1442 int id;
1390 1443
1391 if (devid == devrev) 1444 if (devid == devrev)
1392 /* simple heuristics, we happened to read some 1445 /* simple heuristics, we happened to read some
1393 non-smsc register */ 1446 non-smsc register */
1394 return; 1447 return;
1395 1448
1396 func=NULL; 1449 func = NULL;
1397 id=(devid<<8) | devrev; 1450 id = (devid << 8) | devrev;
1398 1451
1399 if (id==0x0302) {type="37c669"; func=show_parconfig_smsc37c669;} 1452 if (id == 0x0302) {
1400 else if (id==0x6582) type="37c665IR"; 1453 type = "37c669";
1401 else if (devid==0x65) type="37c665GT"; 1454 func = show_parconfig_smsc37c669;
1402 else if (devid==0x66) type="37c666GT"; 1455 } else if (id == 0x6582)
1456 type = "37c665IR";
1457 else if (devid == 0x65)
1458 type = "37c665GT";
1459 else if (devid == 0x66)
1460 type = "37c666GT";
1403 1461
1404 if (verbose_probing) 1462 if (verbose_probing)
1405 printk(KERN_INFO "SMSC chip at EFER=0x%x " 1463 printk(KERN_INFO "SMSC chip at EFER=0x%x "
@@ -1407,138 +1465,138 @@ static void __devinit decode_smsc(int efer, int key, int devid, int devrev)
1407 efer, key, devid, devrev, type); 1465 efer, key, devid, devrev, type);
1408 1466
1409 if (func) 1467 if (func)
1410 func(efer,key); 1468 func(efer, key);
1411} 1469}
1412 1470
1413 1471
1414static void __devinit winbond_check(int io, int key) 1472static void __devinit winbond_check(int io, int key)
1415{ 1473{
1416 int devid,devrev,oldid,x_devid,x_devrev,x_oldid; 1474 int devid, devrev, oldid, x_devid, x_devrev, x_oldid;
1417 1475
1418 if (!request_region(io, 3, __func__)) 1476 if (!request_region(io, 3, __func__))
1419 return; 1477 return;
1420 1478
1421 /* First probe without key */ 1479 /* First probe without key */
1422 outb(0x20,io); 1480 outb(0x20, io);
1423 x_devid=inb(io+1); 1481 x_devid = inb(io + 1);
1424 outb(0x21,io); 1482 outb(0x21, io);
1425 x_devrev=inb(io+1); 1483 x_devrev = inb(io + 1);
1426 outb(0x09,io); 1484 outb(0x09, io);
1427 x_oldid=inb(io+1); 1485 x_oldid = inb(io + 1);
1428 1486
1429 outb(key,io); 1487 outb(key, io);
1430 outb(key,io); /* Write Magic Sequence to EFER, extended 1488 outb(key, io); /* Write Magic Sequence to EFER, extended
1431 funtion enable register */ 1489 funtion enable register */
1432 outb(0x20,io); /* Write EFIR, extended function index register */ 1490 outb(0x20, io); /* Write EFIR, extended function index register */
1433 devid=inb(io+1); /* Read EFDR, extended function data register */ 1491 devid = inb(io + 1); /* Read EFDR, extended function data register */
1434 outb(0x21,io); 1492 outb(0x21, io);
1435 devrev=inb(io+1); 1493 devrev = inb(io + 1);
1436 outb(0x09,io); 1494 outb(0x09, io);
1437 oldid=inb(io+1); 1495 oldid = inb(io + 1);
1438 outb(0xaa,io); /* Magic Seal */ 1496 outb(0xaa, io); /* Magic Seal */
1439 1497
1440 if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid)) 1498 if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid))
1441 goto out; /* protection against false positives */ 1499 goto out; /* protection against false positives */
1442 1500
1443 decode_winbond(io,key,devid,devrev,oldid); 1501 decode_winbond(io, key, devid, devrev, oldid);
1444out: 1502out:
1445 release_region(io, 3); 1503 release_region(io, 3);
1446} 1504}
1447 1505
1448static void __devinit winbond_check2(int io,int key) 1506static void __devinit winbond_check2(int io, int key)
1449{ 1507{
1450 int devid,devrev,oldid,x_devid,x_devrev,x_oldid; 1508 int devid, devrev, oldid, x_devid, x_devrev, x_oldid;
1451 1509
1452 if (!request_region(io, 3, __func__)) 1510 if (!request_region(io, 3, __func__))
1453 return; 1511 return;
1454 1512
1455 /* First probe without the key */ 1513 /* First probe without the key */
1456 outb(0x20,io+2); 1514 outb(0x20, io + 2);
1457 x_devid=inb(io+2); 1515 x_devid = inb(io + 2);
1458 outb(0x21,io+1); 1516 outb(0x21, io + 1);
1459 x_devrev=inb(io+2); 1517 x_devrev = inb(io + 2);
1460 outb(0x09,io+1); 1518 outb(0x09, io + 1);
1461 x_oldid=inb(io+2); 1519 x_oldid = inb(io + 2);
1462 1520
1463 outb(key,io); /* Write Magic Byte to EFER, extended 1521 outb(key, io); /* Write Magic Byte to EFER, extended
1464 funtion enable register */ 1522 funtion enable register */
1465 outb(0x20,io+2); /* Write EFIR, extended function index register */ 1523 outb(0x20, io + 2); /* Write EFIR, extended function index register */
1466 devid=inb(io+2); /* Read EFDR, extended function data register */ 1524 devid = inb(io + 2); /* Read EFDR, extended function data register */
1467 outb(0x21,io+1); 1525 outb(0x21, io + 1);
1468 devrev=inb(io+2); 1526 devrev = inb(io + 2);
1469 outb(0x09,io+1); 1527 outb(0x09, io + 1);
1470 oldid=inb(io+2); 1528 oldid = inb(io + 2);
1471 outb(0xaa,io); /* Magic Seal */ 1529 outb(0xaa, io); /* Magic Seal */
1472 1530
1473 if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid)) 1531 if (x_devid == devid && x_devrev == devrev && x_oldid == oldid)
1474 goto out; /* protection against false positives */ 1532 goto out; /* protection against false positives */
1475 1533
1476 decode_winbond(io,key,devid,devrev,oldid); 1534 decode_winbond(io, key, devid, devrev, oldid);
1477out: 1535out:
1478 release_region(io, 3); 1536 release_region(io, 3);
1479} 1537}
1480 1538
1481static void __devinit smsc_check(int io, int key) 1539static void __devinit smsc_check(int io, int key)
1482{ 1540{
1483 int id,rev,oldid,oldrev,x_id,x_rev,x_oldid,x_oldrev; 1541 int id, rev, oldid, oldrev, x_id, x_rev, x_oldid, x_oldrev;
1484 1542
1485 if (!request_region(io, 3, __func__)) 1543 if (!request_region(io, 3, __func__))
1486 return; 1544 return;
1487 1545
1488 /* First probe without the key */ 1546 /* First probe without the key */
1489 outb(0x0d,io); 1547 outb(0x0d, io);
1490 x_oldid=inb(io+1); 1548 x_oldid = inb(io + 1);
1491 outb(0x0e,io); 1549 outb(0x0e, io);
1492 x_oldrev=inb(io+1); 1550 x_oldrev = inb(io + 1);
1493 outb(0x20,io); 1551 outb(0x20, io);
1494 x_id=inb(io+1); 1552 x_id = inb(io + 1);
1495 outb(0x21,io); 1553 outb(0x21, io);
1496 x_rev=inb(io+1); 1554 x_rev = inb(io + 1);
1497 1555
1498 outb(key,io); 1556 outb(key, io);
1499 outb(key,io); /* Write Magic Sequence to EFER, extended 1557 outb(key, io); /* Write Magic Sequence to EFER, extended
1500 funtion enable register */ 1558 funtion enable register */
1501 outb(0x0d,io); /* Write EFIR, extended function index register */ 1559 outb(0x0d, io); /* Write EFIR, extended function index register */
1502 oldid=inb(io+1); /* Read EFDR, extended function data register */ 1560 oldid = inb(io + 1); /* Read EFDR, extended function data register */
1503 outb(0x0e,io); 1561 outb(0x0e, io);
1504 oldrev=inb(io+1); 1562 oldrev = inb(io + 1);
1505 outb(0x20,io); 1563 outb(0x20, io);
1506 id=inb(io+1); 1564 id = inb(io + 1);
1507 outb(0x21,io); 1565 outb(0x21, io);
1508 rev=inb(io+1); 1566 rev = inb(io + 1);
1509 outb(0xaa,io); /* Magic Seal */ 1567 outb(0xaa, io); /* Magic Seal */
1510 1568
1511 if ((x_id == id) && (x_oldrev == oldrev) && 1569 if (x_id == id && x_oldrev == oldrev &&
1512 (x_oldid == oldid) && (x_rev == rev)) 1570 x_oldid == oldid && x_rev == rev)
1513 goto out; /* protection against false positives */ 1571 goto out; /* protection against false positives */
1514 1572
1515 decode_smsc(io,key,oldid,oldrev); 1573 decode_smsc(io, key, oldid, oldrev);
1516out: 1574out:
1517 release_region(io, 3); 1575 release_region(io, 3);
1518} 1576}
1519 1577
1520 1578
1521static void __devinit detect_and_report_winbond (void) 1579static void __devinit detect_and_report_winbond(void)
1522{ 1580{
1523 if (verbose_probing) 1581 if (verbose_probing)
1524 printk(KERN_DEBUG "Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n"); 1582 printk(KERN_DEBUG "Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n");
1525 winbond_check(0x3f0,0x87); 1583 winbond_check(0x3f0, 0x87);
1526 winbond_check(0x370,0x87); 1584 winbond_check(0x370, 0x87);
1527 winbond_check(0x2e ,0x87); 1585 winbond_check(0x2e , 0x87);
1528 winbond_check(0x4e ,0x87); 1586 winbond_check(0x4e , 0x87);
1529 winbond_check(0x3f0,0x86); 1587 winbond_check(0x3f0, 0x86);
1530 winbond_check2(0x250,0x88); 1588 winbond_check2(0x250, 0x88);
1531 winbond_check2(0x250,0x89); 1589 winbond_check2(0x250, 0x89);
1532} 1590}
1533 1591
1534static void __devinit detect_and_report_smsc (void) 1592static void __devinit detect_and_report_smsc(void)
1535{ 1593{
1536 if (verbose_probing) 1594 if (verbose_probing)
1537 printk(KERN_DEBUG "SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n"); 1595 printk(KERN_DEBUG "SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n");
1538 smsc_check(0x3f0,0x55); 1596 smsc_check(0x3f0, 0x55);
1539 smsc_check(0x370,0x55); 1597 smsc_check(0x370, 0x55);
1540 smsc_check(0x3f0,0x44); 1598 smsc_check(0x3f0, 0x44);
1541 smsc_check(0x370,0x44); 1599 smsc_check(0x370, 0x44);
1542} 1600}
1543 1601
1544static void __devinit detect_and_report_it87(void) 1602static void __devinit detect_and_report_it87(void)
@@ -1573,34 +1631,39 @@ static void __devinit detect_and_report_it87(void)
1573} 1631}
1574#endif /* CONFIG_PARPORT_PC_SUPERIO */ 1632#endif /* CONFIG_PARPORT_PC_SUPERIO */
1575 1633
1576static int get_superio_dma (struct parport *p) 1634static struct superio_struct *find_superio(struct parport *p)
1577{ 1635{
1578 int i=0; 1636 int i;
1579 while( (superios[i].io != p->base) && (i<NR_SUPERIOS)) 1637 for (i = 0; i < NR_SUPERIOS; i++)
1580 i++; 1638 if (superios[i].io != p->base)
1581 if (i!=NR_SUPERIOS) 1639 return &superios[i];
1582 return superios[i].dma; 1640 return NULL;
1641}
1642
1643static int get_superio_dma(struct parport *p)
1644{
1645 struct superio_struct *s = find_superio(p);
1646 if (s)
1647 return s->dma;
1583 return PARPORT_DMA_NONE; 1648 return PARPORT_DMA_NONE;
1584} 1649}
1585 1650
1586static int get_superio_irq (struct parport *p) 1651static int get_superio_irq(struct parport *p)
1587{ 1652{
1588 int i=0; 1653 struct superio_struct *s = find_superio(p);
1589 while( (superios[i].io != p->base) && (i<NR_SUPERIOS)) 1654 if (s)
1590 i++; 1655 return s->irq;
1591 if (i!=NR_SUPERIOS) 1656 return PARPORT_IRQ_NONE;
1592 return superios[i].irq;
1593 return PARPORT_IRQ_NONE;
1594} 1657}
1595 1658
1596 1659
1597/* --- Mode detection ------------------------------------- */ 1660/* --- Mode detection ------------------------------------- */
1598 1661
1599/* 1662/*
1600 * Checks for port existence, all ports support SPP MODE 1663 * Checks for port existence, all ports support SPP MODE
1601 * Returns: 1664 * Returns:
1602 * 0 : No parallel port at this address 1665 * 0 : No parallel port at this address
1603 * PARPORT_MODE_PCSPP : SPP port detected 1666 * PARPORT_MODE_PCSPP : SPP port detected
1604 * (if the user specified an ioport himself, 1667 * (if the user specified an ioport himself,
1605 * this shall always be the case!) 1668 * this shall always be the case!)
1606 * 1669 *
@@ -1610,7 +1673,7 @@ static int parport_SPP_supported(struct parport *pb)
1610 unsigned char r, w; 1673 unsigned char r, w;
1611 1674
1612 /* 1675 /*
1613 * first clear an eventually pending EPP timeout 1676 * first clear an eventually pending EPP timeout
1614 * I (sailer@ife.ee.ethz.ch) have an SMSC chipset 1677 * I (sailer@ife.ee.ethz.ch) have an SMSC chipset
1615 * that does not even respond to SPP cycles if an EPP 1678 * that does not even respond to SPP cycles if an EPP
1616 * timeout is pending 1679 * timeout is pending
@@ -1619,19 +1682,19 @@ static int parport_SPP_supported(struct parport *pb)
1619 1682
1620 /* Do a simple read-write test to make sure the port exists. */ 1683 /* Do a simple read-write test to make sure the port exists. */
1621 w = 0xc; 1684 w = 0xc;
1622 outb (w, CONTROL (pb)); 1685 outb(w, CONTROL(pb));
1623 1686
1624 /* Is there a control register that we can read from? Some 1687 /* Is there a control register that we can read from? Some
1625 * ports don't allow reads, so read_control just returns a 1688 * ports don't allow reads, so read_control just returns a
1626 * software copy. Some ports _do_ allow reads, so bypass the 1689 * software copy. Some ports _do_ allow reads, so bypass the
1627 * software copy here. In addition, some bits aren't 1690 * software copy here. In addition, some bits aren't
1628 * writable. */ 1691 * writable. */
1629 r = inb (CONTROL (pb)); 1692 r = inb(CONTROL(pb));
1630 if ((r & 0xf) == w) { 1693 if ((r & 0xf) == w) {
1631 w = 0xe; 1694 w = 0xe;
1632 outb (w, CONTROL (pb)); 1695 outb(w, CONTROL(pb));
1633 r = inb (CONTROL (pb)); 1696 r = inb(CONTROL(pb));
1634 outb (0xc, CONTROL (pb)); 1697 outb(0xc, CONTROL(pb));
1635 if ((r & 0xf) == w) 1698 if ((r & 0xf) == w)
1636 return PARPORT_MODE_PCSPP; 1699 return PARPORT_MODE_PCSPP;
1637 } 1700 }
@@ -1639,18 +1702,18 @@ static int parport_SPP_supported(struct parport *pb)
1639 if (user_specified) 1702 if (user_specified)
1640 /* That didn't work, but the user thinks there's a 1703 /* That didn't work, but the user thinks there's a
1641 * port here. */ 1704 * port here. */
1642 printk (KERN_INFO "parport 0x%lx (WARNING): CTR: " 1705 printk(KERN_INFO "parport 0x%lx (WARNING): CTR: "
1643 "wrote 0x%02x, read 0x%02x\n", pb->base, w, r); 1706 "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
1644 1707
1645 /* Try the data register. The data lines aren't tri-stated at 1708 /* Try the data register. The data lines aren't tri-stated at
1646 * this stage, so we expect back what we wrote. */ 1709 * this stage, so we expect back what we wrote. */
1647 w = 0xaa; 1710 w = 0xaa;
1648 parport_pc_write_data (pb, w); 1711 parport_pc_write_data(pb, w);
1649 r = parport_pc_read_data (pb); 1712 r = parport_pc_read_data(pb);
1650 if (r == w) { 1713 if (r == w) {
1651 w = 0x55; 1714 w = 0x55;
1652 parport_pc_write_data (pb, w); 1715 parport_pc_write_data(pb, w);
1653 r = parport_pc_read_data (pb); 1716 r = parport_pc_read_data(pb);
1654 if (r == w) 1717 if (r == w)
1655 return PARPORT_MODE_PCSPP; 1718 return PARPORT_MODE_PCSPP;
1656 } 1719 }
@@ -1658,9 +1721,9 @@ static int parport_SPP_supported(struct parport *pb)
1658 if (user_specified) { 1721 if (user_specified) {
1659 /* Didn't work, but the user is convinced this is the 1722 /* Didn't work, but the user is convinced this is the
1660 * place. */ 1723 * place. */
1661 printk (KERN_INFO "parport 0x%lx (WARNING): DATA: " 1724 printk(KERN_INFO "parport 0x%lx (WARNING): DATA: "
1662 "wrote 0x%02x, read 0x%02x\n", pb->base, w, r); 1725 "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
1663 printk (KERN_INFO "parport 0x%lx: You gave this address, " 1726 printk(KERN_INFO "parport 0x%lx: You gave this address, "
1664 "but there is probably no parallel port there!\n", 1727 "but there is probably no parallel port there!\n",
1665 pb->base); 1728 pb->base);
1666 } 1729 }
@@ -1691,33 +1754,33 @@ static int parport_ECR_present(struct parport *pb)
1691 struct parport_pc_private *priv = pb->private_data; 1754 struct parport_pc_private *priv = pb->private_data;
1692 unsigned char r = 0xc; 1755 unsigned char r = 0xc;
1693 1756
1694 outb (r, CONTROL (pb)); 1757 outb(r, CONTROL(pb));
1695 if ((inb (ECONTROL (pb)) & 0x3) == (r & 0x3)) { 1758 if ((inb(ECONTROL(pb)) & 0x3) == (r & 0x3)) {
1696 outb (r ^ 0x2, CONTROL (pb)); /* Toggle bit 1 */ 1759 outb(r ^ 0x2, CONTROL(pb)); /* Toggle bit 1 */
1697 1760
1698 r = inb (CONTROL (pb)); 1761 r = inb(CONTROL(pb));
1699 if ((inb (ECONTROL (pb)) & 0x2) == (r & 0x2)) 1762 if ((inb(ECONTROL(pb)) & 0x2) == (r & 0x2))
1700 goto no_reg; /* Sure that no ECR register exists */ 1763 goto no_reg; /* Sure that no ECR register exists */
1701 } 1764 }
1702 1765
1703 if ((inb (ECONTROL (pb)) & 0x3 ) != 0x1) 1766 if ((inb(ECONTROL(pb)) & 0x3) != 0x1)
1704 goto no_reg; 1767 goto no_reg;
1705 1768
1706 ECR_WRITE (pb, 0x34); 1769 ECR_WRITE(pb, 0x34);
1707 if (inb (ECONTROL (pb)) != 0x35) 1770 if (inb(ECONTROL(pb)) != 0x35)
1708 goto no_reg; 1771 goto no_reg;
1709 1772
1710 priv->ecr = 1; 1773 priv->ecr = 1;
1711 outb (0xc, CONTROL (pb)); 1774 outb(0xc, CONTROL(pb));
1712 1775
1713 /* Go to mode 000 */ 1776 /* Go to mode 000 */
1714 frob_set_mode (pb, ECR_SPP); 1777 frob_set_mode(pb, ECR_SPP);
1715 1778
1716 return 1; 1779 return 1;
1717 1780
1718 no_reg: 1781 no_reg:
1719 outb (0xc, CONTROL (pb)); 1782 outb(0xc, CONTROL(pb));
1720 return 0; 1783 return 0;
1721} 1784}
1722 1785
1723#ifdef CONFIG_PARPORT_1284 1786#ifdef CONFIG_PARPORT_1284
@@ -1727,7 +1790,7 @@ static int parport_ECR_present(struct parport *pb)
1727 * allows us to read data from the data lines. In theory we would get back 1790 * allows us to read data from the data lines. In theory we would get back
1728 * 0xff but any peripheral attached to the port may drag some or all of the 1791 * 0xff but any peripheral attached to the port may drag some or all of the
1729 * lines down to zero. So if we get back anything that isn't the contents 1792 * lines down to zero. So if we get back anything that isn't the contents
1730 * of the data register we deem PS/2 support to be present. 1793 * of the data register we deem PS/2 support to be present.
1731 * 1794 *
1732 * Some SPP ports have "half PS/2" ability - you can't turn off the line 1795 * Some SPP ports have "half PS/2" ability - you can't turn off the line
1733 * drivers, but an external peripheral with sufficiently beefy drivers of 1796 * drivers, but an external peripheral with sufficiently beefy drivers of
@@ -1735,26 +1798,28 @@ static int parport_ECR_present(struct parport *pb)
1735 * where they can then be read back as normal. Ports with this property 1798 * where they can then be read back as normal. Ports with this property
1736 * and the right type of device attached are likely to fail the SPP test, 1799 * and the right type of device attached are likely to fail the SPP test,
1737 * (as they will appear to have stuck bits) and so the fact that they might 1800 * (as they will appear to have stuck bits) and so the fact that they might
1738 * be misdetected here is rather academic. 1801 * be misdetected here is rather academic.
1739 */ 1802 */
1740 1803
1741static int parport_PS2_supported(struct parport *pb) 1804static int parport_PS2_supported(struct parport *pb)
1742{ 1805{
1743 int ok = 0; 1806 int ok = 0;
1744 1807
1745 clear_epp_timeout(pb); 1808 clear_epp_timeout(pb);
1746 1809
1747 /* try to tri-state the buffer */ 1810 /* try to tri-state the buffer */
1748 parport_pc_data_reverse (pb); 1811 parport_pc_data_reverse(pb);
1749 1812
1750 parport_pc_write_data(pb, 0x55); 1813 parport_pc_write_data(pb, 0x55);
1751 if (parport_pc_read_data(pb) != 0x55) ok++; 1814 if (parport_pc_read_data(pb) != 0x55)
1815 ok++;
1752 1816
1753 parport_pc_write_data(pb, 0xaa); 1817 parport_pc_write_data(pb, 0xaa);
1754 if (parport_pc_read_data(pb) != 0xaa) ok++; 1818 if (parport_pc_read_data(pb) != 0xaa)
1819 ok++;
1755 1820
1756 /* cancel input mode */ 1821 /* cancel input mode */
1757 parport_pc_data_forward (pb); 1822 parport_pc_data_forward(pb);
1758 1823
1759 if (ok) { 1824 if (ok) {
1760 pb->modes |= PARPORT_MODE_TRISTATE; 1825 pb->modes |= PARPORT_MODE_TRISTATE;
@@ -1773,68 +1838,68 @@ static int parport_ECP_supported(struct parport *pb)
1773 int config, configb; 1838 int config, configb;
1774 int pword; 1839 int pword;
1775 struct parport_pc_private *priv = pb->private_data; 1840 struct parport_pc_private *priv = pb->private_data;
1776 /* Translate ECP intrLine to ISA irq value */ 1841 /* Translate ECP intrLine to ISA irq value */
1777 static const int intrline[]= { 0, 7, 9, 10, 11, 14, 15, 5 }; 1842 static const int intrline[] = { 0, 7, 9, 10, 11, 14, 15, 5 };
1778 1843
1779 /* If there is no ECR, we have no hope of supporting ECP. */ 1844 /* If there is no ECR, we have no hope of supporting ECP. */
1780 if (!priv->ecr) 1845 if (!priv->ecr)
1781 return 0; 1846 return 0;
1782 1847
1783 /* Find out FIFO depth */ 1848 /* Find out FIFO depth */
1784 ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */ 1849 ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */
1785 ECR_WRITE (pb, ECR_TST << 5); /* TEST FIFO */ 1850 ECR_WRITE(pb, ECR_TST << 5); /* TEST FIFO */
1786 for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02); i++) 1851 for (i = 0; i < 1024 && !(inb(ECONTROL(pb)) & 0x02); i++)
1787 outb (0xaa, FIFO (pb)); 1852 outb(0xaa, FIFO(pb));
1788 1853
1789 /* 1854 /*
1790 * Using LGS chipset it uses ECR register, but 1855 * Using LGS chipset it uses ECR register, but
1791 * it doesn't support ECP or FIFO MODE 1856 * it doesn't support ECP or FIFO MODE
1792 */ 1857 */
1793 if (i == 1024) { 1858 if (i == 1024) {
1794 ECR_WRITE (pb, ECR_SPP << 5); 1859 ECR_WRITE(pb, ECR_SPP << 5);
1795 return 0; 1860 return 0;
1796 } 1861 }
1797 1862
1798 priv->fifo_depth = i; 1863 priv->fifo_depth = i;
1799 if (verbose_probing) 1864 if (verbose_probing)
1800 printk (KERN_DEBUG "0x%lx: FIFO is %d bytes\n", pb->base, i); 1865 printk(KERN_DEBUG "0x%lx: FIFO is %d bytes\n", pb->base, i);
1801 1866
1802 /* Find out writeIntrThreshold */ 1867 /* Find out writeIntrThreshold */
1803 frob_econtrol (pb, 1<<2, 1<<2); 1868 frob_econtrol(pb, 1<<2, 1<<2);
1804 frob_econtrol (pb, 1<<2, 0); 1869 frob_econtrol(pb, 1<<2, 0);
1805 for (i = 1; i <= priv->fifo_depth; i++) { 1870 for (i = 1; i <= priv->fifo_depth; i++) {
1806 inb (FIFO (pb)); 1871 inb(FIFO(pb));
1807 udelay (50); 1872 udelay(50);
1808 if (inb (ECONTROL (pb)) & (1<<2)) 1873 if (inb(ECONTROL(pb)) & (1<<2))
1809 break; 1874 break;
1810 } 1875 }
1811 1876
1812 if (i <= priv->fifo_depth) { 1877 if (i <= priv->fifo_depth) {
1813 if (verbose_probing) 1878 if (verbose_probing)
1814 printk (KERN_DEBUG "0x%lx: writeIntrThreshold is %d\n", 1879 printk(KERN_DEBUG "0x%lx: writeIntrThreshold is %d\n",
1815 pb->base, i); 1880 pb->base, i);
1816 } else 1881 } else
1817 /* Number of bytes we know we can write if we get an 1882 /* Number of bytes we know we can write if we get an
1818 interrupt. */ 1883 interrupt. */
1819 i = 0; 1884 i = 0;
1820 1885
1821 priv->writeIntrThreshold = i; 1886 priv->writeIntrThreshold = i;
1822 1887
1823 /* Find out readIntrThreshold */ 1888 /* Find out readIntrThreshold */
1824 frob_set_mode (pb, ECR_PS2); /* Reset FIFO and enable PS2 */ 1889 frob_set_mode(pb, ECR_PS2); /* Reset FIFO and enable PS2 */
1825 parport_pc_data_reverse (pb); /* Must be in PS2 mode */ 1890 parport_pc_data_reverse(pb); /* Must be in PS2 mode */
1826 frob_set_mode (pb, ECR_TST); /* Test FIFO */ 1891 frob_set_mode(pb, ECR_TST); /* Test FIFO */
1827 frob_econtrol (pb, 1<<2, 1<<2); 1892 frob_econtrol(pb, 1<<2, 1<<2);
1828 frob_econtrol (pb, 1<<2, 0); 1893 frob_econtrol(pb, 1<<2, 0);
1829 for (i = 1; i <= priv->fifo_depth; i++) { 1894 for (i = 1; i <= priv->fifo_depth; i++) {
1830 outb (0xaa, FIFO (pb)); 1895 outb(0xaa, FIFO(pb));
1831 if (inb (ECONTROL (pb)) & (1<<2)) 1896 if (inb(ECONTROL(pb)) & (1<<2))
1832 break; 1897 break;
1833 } 1898 }
1834 1899
1835 if (i <= priv->fifo_depth) { 1900 if (i <= priv->fifo_depth) {
1836 if (verbose_probing) 1901 if (verbose_probing)
1837 printk (KERN_INFO "0x%lx: readIntrThreshold is %d\n", 1902 printk(KERN_INFO "0x%lx: readIntrThreshold is %d\n",
1838 pb->base, i); 1903 pb->base, i);
1839 } else 1904 } else
1840 /* Number of bytes we can read if we get an interrupt. */ 1905 /* Number of bytes we can read if we get an interrupt. */
@@ -1842,23 +1907,23 @@ static int parport_ECP_supported(struct parport *pb)
1842 1907
1843 priv->readIntrThreshold = i; 1908 priv->readIntrThreshold = i;
1844 1909
1845 ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */ 1910 ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */
1846 ECR_WRITE (pb, 0xf4); /* Configuration mode */ 1911 ECR_WRITE(pb, 0xf4); /* Configuration mode */
1847 config = inb (CONFIGA (pb)); 1912 config = inb(CONFIGA(pb));
1848 pword = (config >> 4) & 0x7; 1913 pword = (config >> 4) & 0x7;
1849 switch (pword) { 1914 switch (pword) {
1850 case 0: 1915 case 0:
1851 pword = 2; 1916 pword = 2;
1852 printk (KERN_WARNING "0x%lx: Unsupported pword size!\n", 1917 printk(KERN_WARNING "0x%lx: Unsupported pword size!\n",
1853 pb->base); 1918 pb->base);
1854 break; 1919 break;
1855 case 2: 1920 case 2:
1856 pword = 4; 1921 pword = 4;
1857 printk (KERN_WARNING "0x%lx: Unsupported pword size!\n", 1922 printk(KERN_WARNING "0x%lx: Unsupported pword size!\n",
1858 pb->base); 1923 pb->base);
1859 break; 1924 break;
1860 default: 1925 default:
1861 printk (KERN_WARNING "0x%lx: Unknown implementation ID\n", 1926 printk(KERN_WARNING "0x%lx: Unknown implementation ID\n",
1862 pb->base); 1927 pb->base);
1863 /* Assume 1 */ 1928 /* Assume 1 */
1864 case 1: 1929 case 1:
@@ -1867,28 +1932,29 @@ static int parport_ECP_supported(struct parport *pb)
1867 priv->pword = pword; 1932 priv->pword = pword;
1868 1933
1869 if (verbose_probing) { 1934 if (verbose_probing) {
1870 printk (KERN_DEBUG "0x%lx: PWord is %d bits\n", pb->base, 8 * pword); 1935 printk(KERN_DEBUG "0x%lx: PWord is %d bits\n",
1871 1936 pb->base, 8 * pword);
1872 printk (KERN_DEBUG "0x%lx: Interrupts are ISA-%s\n", pb->base, 1937
1938 printk(KERN_DEBUG "0x%lx: Interrupts are ISA-%s\n", pb->base,
1873 config & 0x80 ? "Level" : "Pulses"); 1939 config & 0x80 ? "Level" : "Pulses");
1874 1940
1875 configb = inb (CONFIGB (pb)); 1941 configb = inb(CONFIGB(pb));
1876 printk (KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n", 1942 printk(KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n",
1877 pb->base, config, configb); 1943 pb->base, config, configb);
1878 printk (KERN_DEBUG "0x%lx: ECP settings irq=", pb->base); 1944 printk(KERN_DEBUG "0x%lx: ECP settings irq=", pb->base);
1879 if ((configb >>3) & 0x07) 1945 if ((configb >> 3) & 0x07)
1880 printk("%d",intrline[(configb >>3) & 0x07]); 1946 printk("%d", intrline[(configb >> 3) & 0x07]);
1881 else 1947 else
1882 printk("<none or set by other means>"); 1948 printk("<none or set by other means>");
1883 printk (" dma="); 1949 printk(" dma=");
1884 if( (configb & 0x03 ) == 0x00) 1950 if ((configb & 0x03) == 0x00)
1885 printk("<none or set by other means>\n"); 1951 printk("<none or set by other means>\n");
1886 else 1952 else
1887 printk("%d\n",configb & 0x07); 1953 printk("%d\n", configb & 0x07);
1888 } 1954 }
1889 1955
1890 /* Go back to mode 000 */ 1956 /* Go back to mode 000 */
1891 frob_set_mode (pb, ECR_SPP); 1957 frob_set_mode(pb, ECR_SPP);
1892 1958
1893 return 1; 1959 return 1;
1894} 1960}
@@ -1903,10 +1969,10 @@ static int parport_ECPPS2_supported(struct parport *pb)
1903 if (!priv->ecr) 1969 if (!priv->ecr)
1904 return 0; 1970 return 0;
1905 1971
1906 oecr = inb (ECONTROL (pb)); 1972 oecr = inb(ECONTROL(pb));
1907 ECR_WRITE (pb, ECR_PS2 << 5); 1973 ECR_WRITE(pb, ECR_PS2 << 5);
1908 result = parport_PS2_supported(pb); 1974 result = parport_PS2_supported(pb);
1909 ECR_WRITE (pb, oecr); 1975 ECR_WRITE(pb, oecr);
1910 return result; 1976 return result;
1911} 1977}
1912 1978
@@ -1930,16 +1996,15 @@ static int parport_EPP_supported(struct parport *pb)
1930 */ 1996 */
1931 1997
1932 /* If EPP timeout bit clear then EPP available */ 1998 /* If EPP timeout bit clear then EPP available */
1933 if (!clear_epp_timeout(pb)) { 1999 if (!clear_epp_timeout(pb))
1934 return 0; /* No way to clear timeout */ 2000 return 0; /* No way to clear timeout */
1935 }
1936 2001
1937 /* Check for Intel bug. */ 2002 /* Check for Intel bug. */
1938 if (priv->ecr) { 2003 if (priv->ecr) {
1939 unsigned char i; 2004 unsigned char i;
1940 for (i = 0x00; i < 0x80; i += 0x20) { 2005 for (i = 0x00; i < 0x80; i += 0x20) {
1941 ECR_WRITE (pb, i); 2006 ECR_WRITE(pb, i);
1942 if (clear_epp_timeout (pb)) { 2007 if (clear_epp_timeout(pb)) {
1943 /* Phony EPP in ECP. */ 2008 /* Phony EPP in ECP. */
1944 return 0; 2009 return 0;
1945 } 2010 }
@@ -1963,17 +2028,16 @@ static int parport_ECPEPP_supported(struct parport *pb)
1963 int result; 2028 int result;
1964 unsigned char oecr; 2029 unsigned char oecr;
1965 2030
1966 if (!priv->ecr) { 2031 if (!priv->ecr)
1967 return 0; 2032 return 0;
1968 }
1969 2033
1970 oecr = inb (ECONTROL (pb)); 2034 oecr = inb(ECONTROL(pb));
1971 /* Search for SMC style EPP+ECP mode */ 2035 /* Search for SMC style EPP+ECP mode */
1972 ECR_WRITE (pb, 0x80); 2036 ECR_WRITE(pb, 0x80);
1973 outb (0x04, CONTROL (pb)); 2037 outb(0x04, CONTROL(pb));
1974 result = parport_EPP_supported(pb); 2038 result = parport_EPP_supported(pb);
1975 2039
1976 ECR_WRITE (pb, oecr); 2040 ECR_WRITE(pb, oecr);
1977 2041
1978 if (result) { 2042 if (result) {
1979 /* Set up access functions to use ECP+EPP hardware. */ 2043 /* Set up access functions to use ECP+EPP hardware. */
@@ -1991,11 +2055,25 @@ static int parport_ECPEPP_supported(struct parport *pb)
1991/* Don't bother probing for modes we know we won't use. */ 2055/* Don't bother probing for modes we know we won't use. */
1992static int __devinit parport_PS2_supported(struct parport *pb) { return 0; } 2056static int __devinit parport_PS2_supported(struct parport *pb) { return 0; }
1993#ifdef CONFIG_PARPORT_PC_FIFO 2057#ifdef CONFIG_PARPORT_PC_FIFO
1994static int parport_ECP_supported(struct parport *pb) { return 0; } 2058static int parport_ECP_supported(struct parport *pb)
2059{
2060 return 0;
2061}
1995#endif 2062#endif
1996static int __devinit parport_EPP_supported(struct parport *pb) { return 0; } 2063static int __devinit parport_EPP_supported(struct parport *pb)
1997static int __devinit parport_ECPEPP_supported(struct parport *pb){return 0;} 2064{
1998static int __devinit parport_ECPPS2_supported(struct parport *pb){return 0;} 2065 return 0;
2066}
2067
2068static int __devinit parport_ECPEPP_supported(struct parport *pb)
2069{
2070 return 0;
2071}
2072
2073static int __devinit parport_ECPPS2_supported(struct parport *pb)
2074{
2075 return 0;
2076}
1999 2077
2000#endif /* No IEEE 1284 support */ 2078#endif /* No IEEE 1284 support */
2001 2079
@@ -2005,17 +2083,17 @@ static int __devinit parport_ECPPS2_supported(struct parport *pb){return 0;}
2005static int programmable_irq_support(struct parport *pb) 2083static int programmable_irq_support(struct parport *pb)
2006{ 2084{
2007 int irq, intrLine; 2085 int irq, intrLine;
2008 unsigned char oecr = inb (ECONTROL (pb)); 2086 unsigned char oecr = inb(ECONTROL(pb));
2009 static const int lookup[8] = { 2087 static const int lookup[8] = {
2010 PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5 2088 PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5
2011 }; 2089 };
2012 2090
2013 ECR_WRITE (pb, ECR_CNF << 5); /* Configuration MODE */ 2091 ECR_WRITE(pb, ECR_CNF << 5); /* Configuration MODE */
2014 2092
2015 intrLine = (inb (CONFIGB (pb)) >> 3) & 0x07; 2093 intrLine = (inb(CONFIGB(pb)) >> 3) & 0x07;
2016 irq = lookup[intrLine]; 2094 irq = lookup[intrLine];
2017 2095
2018 ECR_WRITE (pb, oecr); 2096 ECR_WRITE(pb, oecr);
2019 return irq; 2097 return irq;
2020} 2098}
2021 2099
@@ -2025,17 +2103,17 @@ static int irq_probe_ECP(struct parport *pb)
2025 unsigned long irqs; 2103 unsigned long irqs;
2026 2104
2027 irqs = probe_irq_on(); 2105 irqs = probe_irq_on();
2028 2106
2029 ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */ 2107 ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */
2030 ECR_WRITE (pb, (ECR_TST << 5) | 0x04); 2108 ECR_WRITE(pb, (ECR_TST << 5) | 0x04);
2031 ECR_WRITE (pb, ECR_TST << 5); 2109 ECR_WRITE(pb, ECR_TST << 5);
2032 2110
2033 /* If Full FIFO sure that writeIntrThreshold is generated */ 2111 /* If Full FIFO sure that writeIntrThreshold is generated */
2034 for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02) ; i++) 2112 for (i = 0; i < 1024 && !(inb(ECONTROL(pb)) & 0x02) ; i++)
2035 outb (0xaa, FIFO (pb)); 2113 outb(0xaa, FIFO(pb));
2036 2114
2037 pb->irq = probe_irq_off(irqs); 2115 pb->irq = probe_irq_off(irqs);
2038 ECR_WRITE (pb, ECR_SPP << 5); 2116 ECR_WRITE(pb, ECR_SPP << 5);
2039 2117
2040 if (pb->irq <= 0) 2118 if (pb->irq <= 0)
2041 pb->irq = PARPORT_IRQ_NONE; 2119 pb->irq = PARPORT_IRQ_NONE;
@@ -2045,7 +2123,7 @@ static int irq_probe_ECP(struct parport *pb)
2045 2123
2046/* 2124/*
2047 * This detection seems that only works in National Semiconductors 2125 * This detection seems that only works in National Semiconductors
2048 * This doesn't work in SMC, LGS, and Winbond 2126 * This doesn't work in SMC, LGS, and Winbond
2049 */ 2127 */
2050static int irq_probe_EPP(struct parport *pb) 2128static int irq_probe_EPP(struct parport *pb)
2051{ 2129{
@@ -2056,16 +2134,16 @@ static int irq_probe_EPP(struct parport *pb)
2056 unsigned char oecr; 2134 unsigned char oecr;
2057 2135
2058 if (pb->modes & PARPORT_MODE_PCECR) 2136 if (pb->modes & PARPORT_MODE_PCECR)
2059 oecr = inb (ECONTROL (pb)); 2137 oecr = inb(ECONTROL(pb));
2060 2138
2061 irqs = probe_irq_on(); 2139 irqs = probe_irq_on();
2062 2140
2063 if (pb->modes & PARPORT_MODE_PCECR) 2141 if (pb->modes & PARPORT_MODE_PCECR)
2064 frob_econtrol (pb, 0x10, 0x10); 2142 frob_econtrol(pb, 0x10, 0x10);
2065 2143
2066 clear_epp_timeout(pb); 2144 clear_epp_timeout(pb);
2067 parport_pc_frob_control (pb, 0x20, 0x20); 2145 parport_pc_frob_control(pb, 0x20, 0x20);
2068 parport_pc_frob_control (pb, 0x10, 0x10); 2146 parport_pc_frob_control(pb, 0x10, 0x10);
2069 clear_epp_timeout(pb); 2147 clear_epp_timeout(pb);
2070 2148
2071 /* Device isn't expecting an EPP read 2149 /* Device isn't expecting an EPP read
@@ -2074,9 +2152,9 @@ static int irq_probe_EPP(struct parport *pb)
2074 parport_pc_read_epp(pb); 2152 parport_pc_read_epp(pb);
2075 udelay(20); 2153 udelay(20);
2076 2154
2077 pb->irq = probe_irq_off (irqs); 2155 pb->irq = probe_irq_off(irqs);
2078 if (pb->modes & PARPORT_MODE_PCECR) 2156 if (pb->modes & PARPORT_MODE_PCECR)
2079 ECR_WRITE (pb, oecr); 2157 ECR_WRITE(pb, oecr);
2080 parport_pc_write_control(pb, 0xc); 2158 parport_pc_write_control(pb, 0xc);
2081 2159
2082 if (pb->irq <= 0) 2160 if (pb->irq <= 0)
@@ -2133,28 +2211,28 @@ static int parport_irq_probe(struct parport *pb)
2133/* --- DMA detection -------------------------------------- */ 2211/* --- DMA detection -------------------------------------- */
2134 2212
2135/* Only if chipset conforms to ECP ISA Interface Standard */ 2213/* Only if chipset conforms to ECP ISA Interface Standard */
2136static int programmable_dma_support (struct parport *p) 2214static int programmable_dma_support(struct parport *p)
2137{ 2215{
2138 unsigned char oecr = inb (ECONTROL (p)); 2216 unsigned char oecr = inb(ECONTROL(p));
2139 int dma; 2217 int dma;
2140 2218
2141 frob_set_mode (p, ECR_CNF); 2219 frob_set_mode(p, ECR_CNF);
2142 2220
2143 dma = inb (CONFIGB(p)) & 0x07; 2221 dma = inb(CONFIGB(p)) & 0x07;
2144 /* 000: Indicates jumpered 8-bit DMA if read-only. 2222 /* 000: Indicates jumpered 8-bit DMA if read-only.
2145 100: Indicates jumpered 16-bit DMA if read-only. */ 2223 100: Indicates jumpered 16-bit DMA if read-only. */
2146 if ((dma & 0x03) == 0) 2224 if ((dma & 0x03) == 0)
2147 dma = PARPORT_DMA_NONE; 2225 dma = PARPORT_DMA_NONE;
2148 2226
2149 ECR_WRITE (p, oecr); 2227 ECR_WRITE(p, oecr);
2150 return dma; 2228 return dma;
2151} 2229}
2152 2230
2153static int parport_dma_probe (struct parport *p) 2231static int parport_dma_probe(struct parport *p)
2154{ 2232{
2155 const struct parport_pc_private *priv = p->private_data; 2233 const struct parport_pc_private *priv = p->private_data;
2156 if (priv->ecr) 2234 if (priv->ecr) /* ask ECP chipset first */
2157 p->dma = programmable_dma_support(p); /* ask ECP chipset first */ 2235 p->dma = programmable_dma_support(p);
2158 if (p->dma == PARPORT_DMA_NONE) { 2236 if (p->dma == PARPORT_DMA_NONE) {
2159 /* ask known Super-IO chips proper, although these 2237 /* ask known Super-IO chips proper, although these
2160 claim ECP compatible, some don't report their DMA 2238 claim ECP compatible, some don't report their DMA
@@ -2212,7 +2290,7 @@ struct parport *parport_pc_probe_port(unsigned long int base,
2212 if (!base_res) 2290 if (!base_res)
2213 goto out4; 2291 goto out4;
2214 2292
2215 memcpy(ops, &parport_pc_ops, sizeof (struct parport_operations)); 2293 memcpy(ops, &parport_pc_ops, sizeof(struct parport_operations));
2216 priv->ctr = 0xc; 2294 priv->ctr = 0xc;
2217 priv->ctr_writable = ~0x10; 2295 priv->ctr_writable = ~0x10;
2218 priv->ecr = 0; 2296 priv->ecr = 0;
@@ -2239,7 +2317,7 @@ struct parport *parport_pc_probe_port(unsigned long int base,
2239 if (!parport_EPP_supported(p)) 2317 if (!parport_EPP_supported(p))
2240 parport_ECPEPP_supported(p); 2318 parport_ECPEPP_supported(p);
2241 } 2319 }
2242 if (!parport_SPP_supported (p)) 2320 if (!parport_SPP_supported(p))
2243 /* No port. */ 2321 /* No port. */
2244 goto out5; 2322 goto out5;
2245 if (priv->ecr) 2323 if (priv->ecr)
@@ -2247,7 +2325,7 @@ struct parport *parport_pc_probe_port(unsigned long int base,
2247 else 2325 else
2248 parport_PS2_supported(p); 2326 parport_PS2_supported(p);
2249 2327
2250 p->size = (p->modes & PARPORT_MODE_EPP)?8:3; 2328 p->size = (p->modes & PARPORT_MODE_EPP) ? 8 : 3;
2251 2329
2252 printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base); 2330 printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
2253 if (p->base_hi && priv->ecr) 2331 if (p->base_hi && priv->ecr)
@@ -2271,7 +2349,7 @@ struct parport *parport_pc_probe_port(unsigned long int base,
2271 } 2349 }
2272 } 2350 }
2273 if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq 2351 if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq
2274 is mandatory (see above) */ 2352 is mandatory (see above) */
2275 p->dma = PARPORT_DMA_NONE; 2353 p->dma = PARPORT_DMA_NONE;
2276 2354
2277#ifdef CONFIG_PARPORT_PC_FIFO 2355#ifdef CONFIG_PARPORT_PC_FIFO
@@ -2288,16 +2366,23 @@ struct parport *parport_pc_probe_port(unsigned long int base,
2288 if (p->dma != PARPORT_DMA_NONE) { 2366 if (p->dma != PARPORT_DMA_NONE) {
2289 printk(", dma %d", p->dma); 2367 printk(", dma %d", p->dma);
2290 p->modes |= PARPORT_MODE_DMA; 2368 p->modes |= PARPORT_MODE_DMA;
2291 } 2369 } else
2292 else printk(", using FIFO"); 2370 printk(", using FIFO");
2293 } 2371 } else
2294 else
2295 /* We can't use the DMA channel after all. */ 2372 /* We can't use the DMA channel after all. */
2296 p->dma = PARPORT_DMA_NONE; 2373 p->dma = PARPORT_DMA_NONE;
2297#endif /* Allowed to use FIFO/DMA */ 2374#endif /* Allowed to use FIFO/DMA */
2298 2375
2299 printk(" ["); 2376 printk(" [");
2300#define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}} 2377
2378#define printmode(x) \
2379 {\
2380 if (p->modes & PARPORT_MODE_##x) {\
2381 printk("%s%s", f ? "," : "", #x);\
2382 f++;\
2383 } \
2384 }
2385
2301 { 2386 {
2302 int f = 0; 2387 int f = 0;
2303 printmode(PCSPP); 2388 printmode(PCSPP);
@@ -2309,10 +2394,10 @@ struct parport *parport_pc_probe_port(unsigned long int base,
2309 } 2394 }
2310#undef printmode 2395#undef printmode
2311#ifndef CONFIG_PARPORT_1284 2396#ifndef CONFIG_PARPORT_1284
2312 printk ("(,...)"); 2397 printk("(,...)");
2313#endif /* CONFIG_PARPORT_1284 */ 2398#endif /* CONFIG_PARPORT_1284 */
2314 printk("]\n"); 2399 printk("]\n");
2315 if (probedirq != PARPORT_IRQ_NONE) 2400 if (probedirq != PARPORT_IRQ_NONE)
2316 printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq); 2401 printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq);
2317 2402
2318 /* If No ECP release the ports grabbed above. */ 2403 /* If No ECP release the ports grabbed above. */
@@ -2328,7 +2413,7 @@ struct parport *parport_pc_probe_port(unsigned long int base,
2328 if (p->irq != PARPORT_IRQ_NONE) { 2413 if (p->irq != PARPORT_IRQ_NONE) {
2329 if (request_irq(p->irq, parport_irq_handler, 2414 if (request_irq(p->irq, parport_irq_handler,
2330 irqflags, p->name, p)) { 2415 irqflags, p->name, p)) {
2331 printk (KERN_WARNING "%s: irq %d in use, " 2416 printk(KERN_WARNING "%s: irq %d in use, "
2332 "resorting to polled operation\n", 2417 "resorting to polled operation\n",
2333 p->name, p->irq); 2418 p->name, p->irq);
2334 p->irq = PARPORT_IRQ_NONE; 2419 p->irq = PARPORT_IRQ_NONE;
@@ -2338,8 +2423,8 @@ struct parport *parport_pc_probe_port(unsigned long int base,
2338#ifdef CONFIG_PARPORT_PC_FIFO 2423#ifdef CONFIG_PARPORT_PC_FIFO
2339#ifdef HAS_DMA 2424#ifdef HAS_DMA
2340 if (p->dma != PARPORT_DMA_NONE) { 2425 if (p->dma != PARPORT_DMA_NONE) {
2341 if (request_dma (p->dma, p->name)) { 2426 if (request_dma(p->dma, p->name)) {
2342 printk (KERN_WARNING "%s: dma %d in use, " 2427 printk(KERN_WARNING "%s: dma %d in use, "
2343 "resorting to PIO operation\n", 2428 "resorting to PIO operation\n",
2344 p->name, p->dma); 2429 p->name, p->dma);
2345 p->dma = PARPORT_DMA_NONE; 2430 p->dma = PARPORT_DMA_NONE;
@@ -2349,8 +2434,8 @@ struct parport *parport_pc_probe_port(unsigned long int base,
2349 PAGE_SIZE, 2434 PAGE_SIZE,
2350 &priv->dma_handle, 2435 &priv->dma_handle,
2351 GFP_KERNEL); 2436 GFP_KERNEL);
2352 if (! priv->dma_buf) { 2437 if (!priv->dma_buf) {
2353 printk (KERN_WARNING "%s: " 2438 printk(KERN_WARNING "%s: "
2354 "cannot get buffer for DMA, " 2439 "cannot get buffer for DMA, "
2355 "resorting to PIO operation\n", 2440 "resorting to PIO operation\n",
2356 p->name); 2441 p->name);
@@ -2369,10 +2454,10 @@ struct parport *parport_pc_probe_port(unsigned long int base,
2369 * Put the ECP detected port in PS2 mode. 2454 * Put the ECP detected port in PS2 mode.
2370 * Do this also for ports that have ECR but don't do ECP. 2455 * Do this also for ports that have ECR but don't do ECP.
2371 */ 2456 */
2372 ECR_WRITE (p, 0x34); 2457 ECR_WRITE(p, 0x34);
2373 2458
2374 parport_pc_write_data(p, 0); 2459 parport_pc_write_data(p, 0);
2375 parport_pc_data_forward (p); 2460 parport_pc_data_forward(p);
2376 2461
2377 /* Now that we've told the sharing engine about the port, and 2462 /* Now that we've told the sharing engine about the port, and
2378 found out its characteristics, let the high-level drivers 2463 found out its characteristics, let the high-level drivers
@@ -2380,7 +2465,7 @@ struct parport *parport_pc_probe_port(unsigned long int base,
2380 spin_lock(&ports_lock); 2465 spin_lock(&ports_lock);
2381 list_add(&priv->list, &ports_list); 2466 list_add(&priv->list, &ports_list);
2382 spin_unlock(&ports_lock); 2467 spin_unlock(&ports_lock);
2383 parport_announce_port (p); 2468 parport_announce_port(p);
2384 2469
2385 return p; 2470 return p;
2386 2471
@@ -2393,18 +2478,17 @@ out5:
2393out4: 2478out4:
2394 parport_put_port(p); 2479 parport_put_port(p);
2395out3: 2480out3:
2396 kfree (priv); 2481 kfree(priv);
2397out2: 2482out2:
2398 kfree (ops); 2483 kfree(ops);
2399out1: 2484out1:
2400 if (pdev) 2485 if (pdev)
2401 platform_device_unregister(pdev); 2486 platform_device_unregister(pdev);
2402 return NULL; 2487 return NULL;
2403} 2488}
2489EXPORT_SYMBOL(parport_pc_probe_port);
2404 2490
2405EXPORT_SYMBOL (parport_pc_probe_port); 2491void parport_pc_unregister_port(struct parport *p)
2406
2407void parport_pc_unregister_port (struct parport *p)
2408{ 2492{
2409 struct parport_pc_private *priv = p->private_data; 2493 struct parport_pc_private *priv = p->private_data;
2410 struct parport_operations *ops = p->ops; 2494 struct parport_operations *ops = p->ops;
@@ -2430,17 +2514,16 @@ void parport_pc_unregister_port (struct parport *p)
2430 priv->dma_buf, 2514 priv->dma_buf,
2431 priv->dma_handle); 2515 priv->dma_handle);
2432#endif 2516#endif
2433 kfree (p->private_data); 2517 kfree(p->private_data);
2434 parport_put_port(p); 2518 parport_put_port(p);
2435 kfree (ops); /* hope no-one cached it */ 2519 kfree(ops); /* hope no-one cached it */
2436} 2520}
2437 2521EXPORT_SYMBOL(parport_pc_unregister_port);
2438EXPORT_SYMBOL (parport_pc_unregister_port);
2439 2522
2440#ifdef CONFIG_PCI 2523#ifdef CONFIG_PCI
2441 2524
2442/* ITE support maintained by Rich Liu <richliu@poorman.org> */ 2525/* ITE support maintained by Rich Liu <richliu@poorman.org> */
2443static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq, 2526static int __devinit sio_ite_8872_probe(struct pci_dev *pdev, int autoirq,
2444 int autodma, 2527 int autodma,
2445 const struct parport_pc_via_data *via) 2528 const struct parport_pc_via_data *via)
2446{ 2529{
@@ -2452,73 +2535,74 @@ static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq,
2452 int irq; 2535 int irq;
2453 int i; 2536 int i;
2454 2537
2455 DPRINTK (KERN_DEBUG "sio_ite_8872_probe()\n"); 2538 DPRINTK(KERN_DEBUG "sio_ite_8872_probe()\n");
2456 2539
2457 // make sure which one chip 2540 /* make sure which one chip */
2458 for(i = 0; i < 5; i++) { 2541 for (i = 0; i < 5; i++) {
2459 base_res = request_region(inta_addr[i], 32, "it887x"); 2542 base_res = request_region(inta_addr[i], 32, "it887x");
2460 if (base_res) { 2543 if (base_res) {
2461 int test; 2544 int test;
2462 pci_write_config_dword (pdev, 0x60, 2545 pci_write_config_dword(pdev, 0x60,
2463 0xe5000000 | inta_addr[i]); 2546 0xe5000000 | inta_addr[i]);
2464 pci_write_config_dword (pdev, 0x78, 2547 pci_write_config_dword(pdev, 0x78,
2465 0x00000000 | inta_addr[i]); 2548 0x00000000 | inta_addr[i]);
2466 test = inb (inta_addr[i]); 2549 test = inb(inta_addr[i]);
2467 if (test != 0xff) break; 2550 if (test != 0xff)
2551 break;
2468 release_region(inta_addr[i], 0x8); 2552 release_region(inta_addr[i], 0x8);
2469 } 2553 }
2470 } 2554 }
2471 if(i >= 5) { 2555 if (i >= 5) {
2472 printk (KERN_INFO "parport_pc: cannot find ITE8872 INTA\n"); 2556 printk(KERN_INFO "parport_pc: cannot find ITE8872 INTA\n");
2473 return 0; 2557 return 0;
2474 } 2558 }
2475 2559
2476 type = inb (inta_addr[i] + 0x18); 2560 type = inb(inta_addr[i] + 0x18);
2477 type &= 0x0f; 2561 type &= 0x0f;
2478 2562
2479 switch (type) { 2563 switch (type) {
2480 case 0x2: 2564 case 0x2:
2481 printk (KERN_INFO "parport_pc: ITE8871 found (1P)\n"); 2565 printk(KERN_INFO "parport_pc: ITE8871 found (1P)\n");
2482 ite8872set = 0x64200000; 2566 ite8872set = 0x64200000;
2483 break; 2567 break;
2484 case 0xa: 2568 case 0xa:
2485 printk (KERN_INFO "parport_pc: ITE8875 found (1P)\n"); 2569 printk(KERN_INFO "parport_pc: ITE8875 found (1P)\n");
2486 ite8872set = 0x64200000; 2570 ite8872set = 0x64200000;
2487 break; 2571 break;
2488 case 0xe: 2572 case 0xe:
2489 printk (KERN_INFO "parport_pc: ITE8872 found (2S1P)\n"); 2573 printk(KERN_INFO "parport_pc: ITE8872 found (2S1P)\n");
2490 ite8872set = 0x64e00000; 2574 ite8872set = 0x64e00000;
2491 break; 2575 break;
2492 case 0x6: 2576 case 0x6:
2493 printk (KERN_INFO "parport_pc: ITE8873 found (1S)\n"); 2577 printk(KERN_INFO "parport_pc: ITE8873 found (1S)\n");
2494 return 0; 2578 return 0;
2495 case 0x8: 2579 case 0x8:
2496 DPRINTK (KERN_DEBUG "parport_pc: ITE8874 found (2S)\n"); 2580 DPRINTK(KERN_DEBUG "parport_pc: ITE8874 found (2S)\n");
2497 return 0; 2581 return 0;
2498 default: 2582 default:
2499 printk (KERN_INFO "parport_pc: unknown ITE887x\n"); 2583 printk(KERN_INFO "parport_pc: unknown ITE887x\n");
2500 printk (KERN_INFO "parport_pc: please mail 'lspci -nvv' " 2584 printk(KERN_INFO "parport_pc: please mail 'lspci -nvv' "
2501 "output to Rich.Liu@ite.com.tw\n"); 2585 "output to Rich.Liu@ite.com.tw\n");
2502 return 0; 2586 return 0;
2503 } 2587 }
2504 2588
2505 pci_read_config_byte (pdev, 0x3c, &ite8872_irq); 2589 pci_read_config_byte(pdev, 0x3c, &ite8872_irq);
2506 pci_read_config_dword (pdev, 0x1c, &ite8872_lpt); 2590 pci_read_config_dword(pdev, 0x1c, &ite8872_lpt);
2507 ite8872_lpt &= 0x0000ff00; 2591 ite8872_lpt &= 0x0000ff00;
2508 pci_read_config_dword (pdev, 0x20, &ite8872_lpthi); 2592 pci_read_config_dword(pdev, 0x20, &ite8872_lpthi);
2509 ite8872_lpthi &= 0x0000ff00; 2593 ite8872_lpthi &= 0x0000ff00;
2510 pci_write_config_dword (pdev, 0x6c, 0xe3000000 | ite8872_lpt); 2594 pci_write_config_dword(pdev, 0x6c, 0xe3000000 | ite8872_lpt);
2511 pci_write_config_dword (pdev, 0x70, 0xe3000000 | ite8872_lpthi); 2595 pci_write_config_dword(pdev, 0x70, 0xe3000000 | ite8872_lpthi);
2512 pci_write_config_dword (pdev, 0x80, (ite8872_lpthi<<16) | ite8872_lpt); 2596 pci_write_config_dword(pdev, 0x80, (ite8872_lpthi<<16) | ite8872_lpt);
2513 // SET SPP&EPP , Parallel Port NO DMA , Enable All Function 2597 /* SET SPP&EPP , Parallel Port NO DMA , Enable All Function */
2514 // SET Parallel IRQ 2598 /* SET Parallel IRQ */
2515 pci_write_config_dword (pdev, 0x9c, 2599 pci_write_config_dword(pdev, 0x9c,
2516 ite8872set | (ite8872_irq * 0x11111)); 2600 ite8872set | (ite8872_irq * 0x11111));
2517 2601
2518 DPRINTK (KERN_DEBUG "ITE887x: The IRQ is %d.\n", ite8872_irq); 2602 DPRINTK(KERN_DEBUG "ITE887x: The IRQ is %d.\n", ite8872_irq);
2519 DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O port is 0x%x.\n", 2603 DPRINTK(KERN_DEBUG "ITE887x: The PARALLEL I/O port is 0x%x.\n",
2520 ite8872_lpt); 2604 ite8872_lpt);
2521 DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O porthi is 0x%x.\n", 2605 DPRINTK(KERN_DEBUG "ITE887x: The PARALLEL I/O porthi is 0x%x.\n",
2522 ite8872_lpthi); 2606 ite8872_lpthi);
2523 2607
2524 /* Let the user (or defaults) steer us away from interrupts */ 2608 /* Let the user (or defaults) steer us away from interrupts */
@@ -2530,14 +2614,14 @@ static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq,
2530 * Release the resource so that parport_pc_probe_port can get it. 2614 * Release the resource so that parport_pc_probe_port can get it.
2531 */ 2615 */
2532 release_resource(base_res); 2616 release_resource(base_res);
2533 if (parport_pc_probe_port (ite8872_lpt, ite8872_lpthi, 2617 if (parport_pc_probe_port(ite8872_lpt, ite8872_lpthi,
2534 irq, PARPORT_DMA_NONE, &pdev->dev, 0)) { 2618 irq, PARPORT_DMA_NONE, &pdev->dev, 0)) {
2535 printk (KERN_INFO 2619 printk(KERN_INFO
2536 "parport_pc: ITE 8872 parallel port: io=0x%X", 2620 "parport_pc: ITE 8872 parallel port: io=0x%X",
2537 ite8872_lpt); 2621 ite8872_lpt);
2538 if (irq != PARPORT_IRQ_NONE) 2622 if (irq != PARPORT_IRQ_NONE)
2539 printk (", irq=%d", irq); 2623 printk(", irq=%d", irq);
2540 printk ("\n"); 2624 printk("\n");
2541 return 1; 2625 return 1;
2542 } 2626 }
2543 2627
@@ -2546,7 +2630,7 @@ static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq,
2546 2630
2547/* VIA 8231 support by Pavel Fedin <sonic_amiga@rambler.ru> 2631/* VIA 8231 support by Pavel Fedin <sonic_amiga@rambler.ru>
2548 based on VIA 686a support code by Jeff Garzik <jgarzik@pobox.com> */ 2632 based on VIA 686a support code by Jeff Garzik <jgarzik@pobox.com> */
2549static int __devinitdata parport_init_mode = 0; 2633static int __devinitdata parport_init_mode;
2550 2634
2551/* Data for two known VIA chips */ 2635/* Data for two known VIA chips */
2552static struct parport_pc_via_data via_686a_data __devinitdata = { 2636static struct parport_pc_via_data via_686a_data __devinitdata = {
@@ -2568,7 +2652,7 @@ static struct parport_pc_via_data via_8231_data __devinitdata = {
2568 0xF6 2652 0xF6
2569}; 2653};
2570 2654
2571static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, 2655static int __devinit sio_via_probe(struct pci_dev *pdev, int autoirq,
2572 int autodma, 2656 int autodma,
2573 const struct parport_pc_via_data *via) 2657 const struct parport_pc_via_data *via)
2574{ 2658{
@@ -2580,38 +2664,38 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq,
2580 2664
2581 printk(KERN_DEBUG "parport_pc: VIA 686A/8231 detected\n"); 2665 printk(KERN_DEBUG "parport_pc: VIA 686A/8231 detected\n");
2582 2666
2583 switch(parport_init_mode) 2667 switch (parport_init_mode) {
2584 {
2585 case 1: 2668 case 1:
2586 printk(KERN_DEBUG "parport_pc: setting SPP mode\n"); 2669 printk(KERN_DEBUG "parport_pc: setting SPP mode\n");
2587 siofunc = VIA_FUNCTION_PARPORT_SPP; 2670 siofunc = VIA_FUNCTION_PARPORT_SPP;
2588 break; 2671 break;
2589 case 2: 2672 case 2:
2590 printk(KERN_DEBUG "parport_pc: setting PS/2 mode\n"); 2673 printk(KERN_DEBUG "parport_pc: setting PS/2 mode\n");
2591 siofunc = VIA_FUNCTION_PARPORT_SPP; 2674 siofunc = VIA_FUNCTION_PARPORT_SPP;
2592 ppcontrol = VIA_PARPORT_BIDIR; 2675 ppcontrol = VIA_PARPORT_BIDIR;
2593 break; 2676 break;
2594 case 3: 2677 case 3:
2595 printk(KERN_DEBUG "parport_pc: setting EPP mode\n"); 2678 printk(KERN_DEBUG "parport_pc: setting EPP mode\n");
2596 siofunc = VIA_FUNCTION_PARPORT_EPP; 2679 siofunc = VIA_FUNCTION_PARPORT_EPP;
2597 ppcontrol = VIA_PARPORT_BIDIR; 2680 ppcontrol = VIA_PARPORT_BIDIR;
2598 have_epp = 1; 2681 have_epp = 1;
2599 break; 2682 break;
2600 case 4: 2683 case 4:
2601 printk(KERN_DEBUG "parport_pc: setting ECP mode\n"); 2684 printk(KERN_DEBUG "parport_pc: setting ECP mode\n");
2602 siofunc = VIA_FUNCTION_PARPORT_ECP; 2685 siofunc = VIA_FUNCTION_PARPORT_ECP;
2603 ppcontrol = VIA_PARPORT_BIDIR; 2686 ppcontrol = VIA_PARPORT_BIDIR;
2604 break; 2687 break;
2605 case 5: 2688 case 5:
2606 printk(KERN_DEBUG "parport_pc: setting EPP+ECP mode\n"); 2689 printk(KERN_DEBUG "parport_pc: setting EPP+ECP mode\n");
2607 siofunc = VIA_FUNCTION_PARPORT_ECP; 2690 siofunc = VIA_FUNCTION_PARPORT_ECP;
2608 ppcontrol = VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP; 2691 ppcontrol = VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP;
2609 have_epp = 1; 2692 have_epp = 1;
2610 break; 2693 break;
2611 default: 2694 default:
2612 printk(KERN_DEBUG "parport_pc: probing current configuration\n"); 2695 printk(KERN_DEBUG
2613 siofunc = VIA_FUNCTION_PROBE; 2696 "parport_pc: probing current configuration\n");
2614 break; 2697 siofunc = VIA_FUNCTION_PROBE;
2698 break;
2615 } 2699 }
2616 /* 2700 /*
2617 * unlock super i/o configuration 2701 * unlock super i/o configuration
@@ -2622,38 +2706,36 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq,
2622 2706
2623 /* Bits 1-0: Parallel Port Mode / Enable */ 2707 /* Bits 1-0: Parallel Port Mode / Enable */
2624 outb(via->viacfg_function, VIA_CONFIG_INDEX); 2708 outb(via->viacfg_function, VIA_CONFIG_INDEX);
2625 tmp = inb (VIA_CONFIG_DATA); 2709 tmp = inb(VIA_CONFIG_DATA);
2626 /* Bit 5: EPP+ECP enable; bit 7: PS/2 bidirectional port enable */ 2710 /* Bit 5: EPP+ECP enable; bit 7: PS/2 bidirectional port enable */
2627 outb(via->viacfg_parport_control, VIA_CONFIG_INDEX); 2711 outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
2628 tmp2 = inb (VIA_CONFIG_DATA); 2712 tmp2 = inb(VIA_CONFIG_DATA);
2629 if (siofunc == VIA_FUNCTION_PROBE) 2713 if (siofunc == VIA_FUNCTION_PROBE) {
2630 { 2714 siofunc = tmp & VIA_FUNCTION_PARPORT_DISABLE;
2631 siofunc = tmp & VIA_FUNCTION_PARPORT_DISABLE; 2715 ppcontrol = tmp2;
2632 ppcontrol = tmp2; 2716 } else {
2717 tmp &= ~VIA_FUNCTION_PARPORT_DISABLE;
2718 tmp |= siofunc;
2719 outb(via->viacfg_function, VIA_CONFIG_INDEX);
2720 outb(tmp, VIA_CONFIG_DATA);
2721 tmp2 &= ~(VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP);
2722 tmp2 |= ppcontrol;
2723 outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
2724 outb(tmp2, VIA_CONFIG_DATA);
2633 } 2725 }
2634 else 2726
2635 {
2636 tmp &= ~VIA_FUNCTION_PARPORT_DISABLE;
2637 tmp |= siofunc;
2638 outb(via->viacfg_function, VIA_CONFIG_INDEX);
2639 outb(tmp, VIA_CONFIG_DATA);
2640 tmp2 &= ~(VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP);
2641 tmp2 |= ppcontrol;
2642 outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
2643 outb(tmp2, VIA_CONFIG_DATA);
2644 }
2645
2646 /* Parallel Port I/O Base Address, bits 9-2 */ 2727 /* Parallel Port I/O Base Address, bits 9-2 */
2647 outb(via->viacfg_parport_base, VIA_CONFIG_INDEX); 2728 outb(via->viacfg_parport_base, VIA_CONFIG_INDEX);
2648 port1 = inb(VIA_CONFIG_DATA) << 2; 2729 port1 = inb(VIA_CONFIG_DATA) << 2;
2649 2730
2650 printk (KERN_DEBUG "parport_pc: Current parallel port base: 0x%X\n",port1); 2731 printk(KERN_DEBUG "parport_pc: Current parallel port base: 0x%X\n",
2651 if ((port1 == 0x3BC) && have_epp) 2732 port1);
2652 { 2733 if (port1 == 0x3BC && have_epp) {
2653 outb(via->viacfg_parport_base, VIA_CONFIG_INDEX); 2734 outb(via->viacfg_parport_base, VIA_CONFIG_INDEX);
2654 outb((0x378 >> 2), VIA_CONFIG_DATA); 2735 outb((0x378 >> 2), VIA_CONFIG_DATA);
2655 printk(KERN_DEBUG "parport_pc: Parallel port base changed to 0x378\n"); 2736 printk(KERN_DEBUG
2656 port1 = 0x378; 2737 "parport_pc: Parallel port base changed to 0x378\n");
2738 port1 = 0x378;
2657 } 2739 }
2658 2740
2659 /* 2741 /*
@@ -2667,36 +2749,39 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq,
2667 printk(KERN_INFO "parport_pc: VIA parallel port disabled in BIOS\n"); 2749 printk(KERN_INFO "parport_pc: VIA parallel port disabled in BIOS\n");
2668 return 0; 2750 return 0;
2669 } 2751 }
2670 2752
2671 /* Bits 7-4: PnP Routing for Parallel Port IRQ */ 2753 /* Bits 7-4: PnP Routing for Parallel Port IRQ */
2672 pci_read_config_byte(pdev, via->via_pci_parport_irq_reg, &tmp); 2754 pci_read_config_byte(pdev, via->via_pci_parport_irq_reg, &tmp);
2673 irq = ((tmp & VIA_IRQCONTROL_PARALLEL) >> 4); 2755 irq = ((tmp & VIA_IRQCONTROL_PARALLEL) >> 4);
2674 2756
2675 if (siofunc == VIA_FUNCTION_PARPORT_ECP) 2757 if (siofunc == VIA_FUNCTION_PARPORT_ECP) {
2676 { 2758 /* Bits 3-2: PnP Routing for Parallel Port DMA */
2677 /* Bits 3-2: PnP Routing for Parallel Port DMA */ 2759 pci_read_config_byte(pdev, via->via_pci_parport_dma_reg, &tmp);
2678 pci_read_config_byte(pdev, via->via_pci_parport_dma_reg, &tmp); 2760 dma = ((tmp & VIA_DMACONTROL_PARALLEL) >> 2);
2679 dma = ((tmp & VIA_DMACONTROL_PARALLEL) >> 2); 2761 } else
2680 } 2762 /* if ECP not enabled, DMA is not enabled, assumed
2681 else 2763 bogus 'dma' value */
2682 /* if ECP not enabled, DMA is not enabled, assumed bogus 'dma' value */ 2764 dma = PARPORT_DMA_NONE;
2683 dma = PARPORT_DMA_NONE;
2684 2765
2685 /* Let the user (or defaults) steer us away from interrupts and DMA */ 2766 /* Let the user (or defaults) steer us away from interrupts and DMA */
2686 if (autoirq == PARPORT_IRQ_NONE) { 2767 if (autoirq == PARPORT_IRQ_NONE) {
2687 irq = PARPORT_IRQ_NONE; 2768 irq = PARPORT_IRQ_NONE;
2688 dma = PARPORT_DMA_NONE; 2769 dma = PARPORT_DMA_NONE;
2689 } 2770 }
2690 if (autodma == PARPORT_DMA_NONE) 2771 if (autodma == PARPORT_DMA_NONE)
2691 dma = PARPORT_DMA_NONE; 2772 dma = PARPORT_DMA_NONE;
2692 2773
2693 switch (port1) { 2774 switch (port1) {
2694 case 0x3bc: port2 = 0x7bc; break; 2775 case 0x3bc:
2695 case 0x378: port2 = 0x778; break; 2776 port2 = 0x7bc; break;
2696 case 0x278: port2 = 0x678; break; 2777 case 0x378:
2778 port2 = 0x778; break;
2779 case 0x278:
2780 port2 = 0x678; break;
2697 default: 2781 default:
2698 printk(KERN_INFO "parport_pc: Weird VIA parport base 0x%X, ignoring\n", 2782 printk(KERN_INFO
2699 port1); 2783 "parport_pc: Weird VIA parport base 0x%X, ignoring\n",
2784 port1);
2700 return 0; 2785 return 0;
2701 } 2786 }
2702 2787
@@ -2714,17 +2799,17 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq,
2714 } 2799 }
2715 2800
2716 /* finally, do the probe with values obtained */ 2801 /* finally, do the probe with values obtained */
2717 if (parport_pc_probe_port (port1, port2, irq, dma, &pdev->dev, 0)) { 2802 if (parport_pc_probe_port(port1, port2, irq, dma, &pdev->dev, 0)) {
2718 printk (KERN_INFO 2803 printk(KERN_INFO
2719 "parport_pc: VIA parallel port: io=0x%X", port1); 2804 "parport_pc: VIA parallel port: io=0x%X", port1);
2720 if (irq != PARPORT_IRQ_NONE) 2805 if (irq != PARPORT_IRQ_NONE)
2721 printk (", irq=%d", irq); 2806 printk(", irq=%d", irq);
2722 if (dma != PARPORT_DMA_NONE) 2807 if (dma != PARPORT_DMA_NONE)
2723 printk (", dma=%d", dma); 2808 printk(", dma=%d", dma);
2724 printk ("\n"); 2809 printk("\n");
2725 return 1; 2810 return 1;
2726 } 2811 }
2727 2812
2728 printk(KERN_WARNING "parport_pc: Strange, can't probe VIA parallel port: io=0x%X, irq=%d, dma=%d\n", 2813 printk(KERN_WARNING "parport_pc: Strange, can't probe VIA parallel port: io=0x%X, irq=%d, dma=%d\n",
2729 port1, irq, dma); 2814 port1, irq, dma);
2730 return 0; 2815 return 0;
@@ -2732,8 +2817,8 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq,
2732 2817
2733 2818
2734enum parport_pc_sio_types { 2819enum parport_pc_sio_types {
2735 sio_via_686a = 0, /* Via VT82C686A motherboard Super I/O */ 2820 sio_via_686a = 0, /* Via VT82C686A motherboard Super I/O */
2736 sio_via_8231, /* Via VT8231 south bridge integrated Super IO */ 2821 sio_via_8231, /* Via VT8231 south bridge integrated Super IO */
2737 sio_ite_8872, 2822 sio_ite_8872,
2738 last_sio 2823 last_sio
2739}; 2824};
@@ -2804,15 +2889,15 @@ enum parport_pc_pci_cards {
2804}; 2889};
2805 2890
2806 2891
2807/* each element directly indexed from enum list, above 2892/* each element directly indexed from enum list, above
2808 * (but offset by last_sio) */ 2893 * (but offset by last_sio) */
2809static struct parport_pc_pci { 2894static struct parport_pc_pci {
2810 int numports; 2895 int numports;
2811 struct { /* BAR (base address registers) numbers in the config 2896 struct { /* BAR (base address registers) numbers in the config
2812 space header */ 2897 space header */
2813 int lo; 2898 int lo;
2814 int hi; /* -1 if not there, >6 for offset-method (max 2899 int hi;
2815 BAR is 6) */ 2900 /* -1 if not there, >6 for offset-method (max BAR is 6) */
2816 } addr[4]; 2901 } addr[4];
2817 2902
2818 /* If set, this is called immediately after pci_enable_device. 2903 /* If set, this is called immediately after pci_enable_device.
@@ -2857,7 +2942,7 @@ static struct parport_pc_pci {
2857 /* timedia_4018 */ { 2, { { 0, 1 }, { 2, 3 }, } }, 2942 /* timedia_4018 */ { 2, { { 0, 1 }, { 2, 3 }, } },
2858 /* timedia_9018a */ { 2, { { 0, 1 }, { 2, 3 }, } }, 2943 /* timedia_9018a */ { 2, { { 0, 1 }, { 2, 3 }, } },
2859 /* SYBA uses fixed offsets in 2944 /* SYBA uses fixed offsets in
2860 a 1K io window */ 2945 a 1K io window */
2861 /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } }, 2946 /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } },
2862 /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } }, 2947 /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } },
2863 /* titan_010l */ { 1, { { 3, -1 }, } }, 2948 /* titan_010l */ { 1, { { 3, -1 }, } },
@@ -2873,11 +2958,14 @@ static struct parport_pc_pci {
2873 /* oxsemi_pcie_pport */ { 1, { { 0, 1 }, } }, 2958 /* oxsemi_pcie_pport */ { 1, { { 0, 1 }, } },
2874 /* aks_0100 */ { 1, { { 0, -1 }, } }, 2959 /* aks_0100 */ { 1, { { 0, -1 }, } },
2875 /* mobility_pp */ { 1, { { 0, 1 }, } }, 2960 /* mobility_pp */ { 1, { { 0, 1 }, } },
2876 /* netmos_9705 */ { 1, { { 0, -1 }, } }, /* untested */ 2961
2877 /* netmos_9715 */ { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */ 2962 /* The netmos entries below are untested */
2878 /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */ 2963 /* netmos_9705 */ { 1, { { 0, -1 }, } },
2879 /* netmos_9805 */ { 1, { { 0, -1 }, } }, /* untested */ 2964 /* netmos_9715 */ { 2, { { 0, 1 }, { 2, 3 },} },
2880 /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } }, /* untested */ 2965 /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} },
2966 /* netmos_9805 */ { 1, { { 0, -1 }, } },
2967 /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } },
2968
2881 /* quatech_sppxp100 */ { 1, { { 0, 1 }, } }, 2969 /* quatech_sppxp100 */ { 1, { { 0, 1 }, } },
2882}; 2970};
2883 2971
@@ -2906,7 +2994,7 @@ static const struct pci_device_id parport_pc_pci_tbl[] = {
2906 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR, 2994 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR,
2907 PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar }, 2995 PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar },
2908 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, 2996 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
2909 PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0,0, plx_9050 }, 2997 PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0, 0, plx_9050 },
2910 /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/ 2998 /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/
2911 { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a }, 2999 { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a },
2912 { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h }, 3000 { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h },
@@ -2940,7 +3028,8 @@ static const struct pci_device_id parport_pc_pci_tbl[] = {
2940 { 0x9710, 0x9805, 0x1000, 0x0010, 0, 0, titan_1284p1 }, 3028 { 0x9710, 0x9805, 0x1000, 0x0010, 0, 0, titan_1284p1 },
2941 { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 }, 3029 { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 },
2942 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/ 3030 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
2943 { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p}, /* AFAVLAB_TK9902 */ 3031 /* AFAVLAB_TK9902 */
3032 { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p},
2944 { 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p}, 3033 { 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p},
2945 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952PP, 3034 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952PP,
2946 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_952 }, 3035 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_952 },
@@ -2983,14 +3072,14 @@ static const struct pci_device_id parport_pc_pci_tbl[] = {
2983 PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 }, 3072 PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 },
2984 { 0, } /* terminate list */ 3073 { 0, } /* terminate list */
2985}; 3074};
2986MODULE_DEVICE_TABLE(pci,parport_pc_pci_tbl); 3075MODULE_DEVICE_TABLE(pci, parport_pc_pci_tbl);
2987 3076
2988struct pci_parport_data { 3077struct pci_parport_data {
2989 int num; 3078 int num;
2990 struct parport *ports[2]; 3079 struct parport *ports[2];
2991}; 3080};
2992 3081
2993static int parport_pc_pci_probe (struct pci_dev *dev, 3082static int parport_pc_pci_probe(struct pci_dev *dev,
2994 const struct pci_device_id *id) 3083 const struct pci_device_id *id)
2995{ 3084{
2996 int err, count, n, i = id->driver_data; 3085 int err, count, n, i = id->driver_data;
@@ -3003,7 +3092,8 @@ static int parport_pc_pci_probe (struct pci_dev *dev,
3003 /* This is a PCI card */ 3092 /* This is a PCI card */
3004 i -= last_sio; 3093 i -= last_sio;
3005 count = 0; 3094 count = 0;
3006 if ((err = pci_enable_device (dev)) != 0) 3095 err = pci_enable_device(dev);
3096 if (err)
3007 return err; 3097 return err;
3008 3098
3009 data = kmalloc(sizeof(struct pci_parport_data), GFP_KERNEL); 3099 data = kmalloc(sizeof(struct pci_parport_data), GFP_KERNEL);
@@ -3011,7 +3101,7 @@ static int parport_pc_pci_probe (struct pci_dev *dev,
3011 return -ENOMEM; 3101 return -ENOMEM;
3012 3102
3013 if (cards[i].preinit_hook && 3103 if (cards[i].preinit_hook &&
3014 cards[i].preinit_hook (dev, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) { 3104 cards[i].preinit_hook(dev, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) {
3015 kfree(data); 3105 kfree(data);
3016 return -ENODEV; 3106 return -ENODEV;
3017 } 3107 }
@@ -3021,25 +3111,25 @@ static int parport_pc_pci_probe (struct pci_dev *dev,
3021 int hi = cards[i].addr[n].hi; 3111 int hi = cards[i].addr[n].hi;
3022 int irq; 3112 int irq;
3023 unsigned long io_lo, io_hi; 3113 unsigned long io_lo, io_hi;
3024 io_lo = pci_resource_start (dev, lo); 3114 io_lo = pci_resource_start(dev, lo);
3025 io_hi = 0; 3115 io_hi = 0;
3026 if ((hi >= 0) && (hi <= 6)) 3116 if ((hi >= 0) && (hi <= 6))
3027 io_hi = pci_resource_start (dev, hi); 3117 io_hi = pci_resource_start(dev, hi);
3028 else if (hi > 6) 3118 else if (hi > 6)
3029 io_lo += hi; /* Reinterpret the meaning of 3119 io_lo += hi; /* Reinterpret the meaning of
3030 "hi" as an offset (see SYBA 3120 "hi" as an offset (see SYBA
3031 def.) */ 3121 def.) */
3032 /* TODO: test if sharing interrupts works */ 3122 /* TODO: test if sharing interrupts works */
3033 irq = dev->irq; 3123 irq = dev->irq;
3034 if (irq == IRQ_NONE) { 3124 if (irq == IRQ_NONE) {
3035 printk (KERN_DEBUG 3125 printk(KERN_DEBUG
3036 "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx)\n", 3126 "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx)\n",
3037 parport_pc_pci_tbl[i + last_sio].vendor, 3127 parport_pc_pci_tbl[i + last_sio].vendor,
3038 parport_pc_pci_tbl[i + last_sio].device, 3128 parport_pc_pci_tbl[i + last_sio].device,
3039 io_lo, io_hi); 3129 io_lo, io_hi);
3040 irq = PARPORT_IRQ_NONE; 3130 irq = PARPORT_IRQ_NONE;
3041 } else { 3131 } else {
3042 printk (KERN_DEBUG 3132 printk(KERN_DEBUG
3043 "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx), IRQ %d\n", 3133 "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx), IRQ %d\n",
3044 parport_pc_pci_tbl[i + last_sio].vendor, 3134 parport_pc_pci_tbl[i + last_sio].vendor,
3045 parport_pc_pci_tbl[i + last_sio].device, 3135 parport_pc_pci_tbl[i + last_sio].device,
@@ -3056,7 +3146,7 @@ static int parport_pc_pci_probe (struct pci_dev *dev,
3056 data->num = count; 3146 data->num = count;
3057 3147
3058 if (cards[i].postinit_hook) 3148 if (cards[i].postinit_hook)
3059 cards[i].postinit_hook (dev, count == 0); 3149 cards[i].postinit_hook(dev, count == 0);
3060 3150
3061 if (count) { 3151 if (count) {
3062 pci_set_drvdata(dev, data); 3152 pci_set_drvdata(dev, data);
@@ -3090,7 +3180,7 @@ static struct pci_driver parport_pc_pci_driver = {
3090 .remove = __devexit_p(parport_pc_pci_remove), 3180 .remove = __devexit_p(parport_pc_pci_remove),
3091}; 3181};
3092 3182
3093static int __init parport_pc_init_superio (int autoirq, int autodma) 3183static int __init parport_pc_init_superio(int autoirq, int autodma)
3094{ 3184{
3095 const struct pci_device_id *id; 3185 const struct pci_device_id *id;
3096 struct pci_dev *pdev = NULL; 3186 struct pci_dev *pdev = NULL;
@@ -3101,8 +3191,9 @@ static int __init parport_pc_init_superio (int autoirq, int autodma)
3101 if (id == NULL || id->driver_data >= last_sio) 3191 if (id == NULL || id->driver_data >= last_sio)
3102 continue; 3192 continue;
3103 3193
3104 if (parport_pc_superio_info[id->driver_data].probe 3194 if (parport_pc_superio_info[id->driver_data].probe(
3105 (pdev, autoirq, autodma,parport_pc_superio_info[id->driver_data].via)) { 3195 pdev, autoirq, autodma,
3196 parport_pc_superio_info[id->driver_data].via)) {
3106 ret++; 3197 ret++;
3107 } 3198 }
3108 } 3199 }
@@ -3111,7 +3202,10 @@ static int __init parport_pc_init_superio (int autoirq, int autodma)
3111} 3202}
3112#else 3203#else
3113static struct pci_driver parport_pc_pci_driver; 3204static struct pci_driver parport_pc_pci_driver;
3114static int __init parport_pc_init_superio(int autoirq, int autodma) {return 0;} 3205static int __init parport_pc_init_superio(int autoirq, int autodma)
3206{
3207 return 0;
3208}
3115#endif /* CONFIG_PCI */ 3209#endif /* CONFIG_PCI */
3116 3210
3117#ifdef CONFIG_PNP 3211#ifdef CONFIG_PNP
@@ -3124,44 +3218,45 @@ static const struct pnp_device_id parport_pc_pnp_tbl[] = {
3124 { } 3218 { }
3125}; 3219};
3126 3220
3127MODULE_DEVICE_TABLE(pnp,parport_pc_pnp_tbl); 3221MODULE_DEVICE_TABLE(pnp, parport_pc_pnp_tbl);
3128 3222
3129static int parport_pc_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *id) 3223static int parport_pc_pnp_probe(struct pnp_dev *dev,
3224 const struct pnp_device_id *id)
3130{ 3225{
3131 struct parport *pdata; 3226 struct parport *pdata;
3132 unsigned long io_lo, io_hi; 3227 unsigned long io_lo, io_hi;
3133 int dma, irq; 3228 int dma, irq;
3134 3229
3135 if (pnp_port_valid(dev,0) && 3230 if (pnp_port_valid(dev, 0) &&
3136 !(pnp_port_flags(dev,0) & IORESOURCE_DISABLED)) { 3231 !(pnp_port_flags(dev, 0) & IORESOURCE_DISABLED)) {
3137 io_lo = pnp_port_start(dev,0); 3232 io_lo = pnp_port_start(dev, 0);
3138 } else 3233 } else
3139 return -EINVAL; 3234 return -EINVAL;
3140 3235
3141 if (pnp_port_valid(dev,1) && 3236 if (pnp_port_valid(dev, 1) &&
3142 !(pnp_port_flags(dev,1) & IORESOURCE_DISABLED)) { 3237 !(pnp_port_flags(dev, 1) & IORESOURCE_DISABLED)) {
3143 io_hi = pnp_port_start(dev,1); 3238 io_hi = pnp_port_start(dev, 1);
3144 } else 3239 } else
3145 io_hi = 0; 3240 io_hi = 0;
3146 3241
3147 if (pnp_irq_valid(dev,0) && 3242 if (pnp_irq_valid(dev, 0) &&
3148 !(pnp_irq_flags(dev,0) & IORESOURCE_DISABLED)) { 3243 !(pnp_irq_flags(dev, 0) & IORESOURCE_DISABLED)) {
3149 irq = pnp_irq(dev,0); 3244 irq = pnp_irq(dev, 0);
3150 } else 3245 } else
3151 irq = PARPORT_IRQ_NONE; 3246 irq = PARPORT_IRQ_NONE;
3152 3247
3153 if (pnp_dma_valid(dev,0) && 3248 if (pnp_dma_valid(dev, 0) &&
3154 !(pnp_dma_flags(dev,0) & IORESOURCE_DISABLED)) { 3249 !(pnp_dma_flags(dev, 0) & IORESOURCE_DISABLED)) {
3155 dma = pnp_dma(dev,0); 3250 dma = pnp_dma(dev, 0);
3156 } else 3251 } else
3157 dma = PARPORT_DMA_NONE; 3252 dma = PARPORT_DMA_NONE;
3158 3253
3159 dev_info(&dev->dev, "reported by %s\n", dev->protocol->name); 3254 dev_info(&dev->dev, "reported by %s\n", dev->protocol->name);
3160 if (!(pdata = parport_pc_probe_port(io_lo, io_hi, 3255 pdata = parport_pc_probe_port(io_lo, io_hi, irq, dma, &dev->dev, 0);
3161 irq, dma, &dev->dev, 0))) 3256 if (pdata == NULL)
3162 return -ENODEV; 3257 return -ENODEV;
3163 3258
3164 pnp_set_drvdata(dev,pdata); 3259 pnp_set_drvdata(dev, pdata);
3165 return 0; 3260 return 0;
3166} 3261}
3167 3262
@@ -3203,7 +3298,7 @@ static struct platform_driver parport_pc_platform_driver = {
3203 3298
3204/* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */ 3299/* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */
3205static int __devinit __attribute__((unused)) 3300static int __devinit __attribute__((unused))
3206parport_pc_find_isa_ports (int autoirq, int autodma) 3301parport_pc_find_isa_ports(int autoirq, int autodma)
3207{ 3302{
3208 int count = 0; 3303 int count = 0;
3209 3304
@@ -3227,7 +3322,7 @@ parport_pc_find_isa_ports (int autoirq, int autodma)
3227 * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY 3322 * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY
3228 * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO 3323 * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO
3229 */ 3324 */
3230static void __init parport_pc_find_ports (int autoirq, int autodma) 3325static void __init parport_pc_find_ports(int autoirq, int autodma)
3231{ 3326{
3232 int count = 0, err; 3327 int count = 0, err;
3233 3328
@@ -3261,11 +3356,18 @@ static void __init parport_pc_find_ports (int autoirq, int autodma)
3261 * syntax and keep in mind that code below is a cleaned up version. 3356 * syntax and keep in mind that code below is a cleaned up version.
3262 */ 3357 */
3263 3358
3264static int __initdata io[PARPORT_PC_MAX_PORTS+1] = { [0 ... PARPORT_PC_MAX_PORTS] = 0 }; 3359static int __initdata io[PARPORT_PC_MAX_PORTS+1] = {
3265static int __initdata io_hi[PARPORT_PC_MAX_PORTS+1] = 3360 [0 ... PARPORT_PC_MAX_PORTS] = 0
3266 { [0 ... PARPORT_PC_MAX_PORTS] = PARPORT_IOHI_AUTO }; 3361};
3267static int __initdata dmaval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_NONE }; 3362static int __initdata io_hi[PARPORT_PC_MAX_PORTS+1] = {
3268static int __initdata irqval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY }; 3363 [0 ... PARPORT_PC_MAX_PORTS] = PARPORT_IOHI_AUTO
3364};
3365static int __initdata dmaval[PARPORT_PC_MAX_PORTS] = {
3366 [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_NONE
3367};
3368static int __initdata irqval[PARPORT_PC_MAX_PORTS] = {
3369 [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY
3370};
3269 3371
3270static int __init parport_parse_param(const char *s, int *val, 3372static int __init parport_parse_param(const char *s, int *val,
3271 int automatic, int none, int nofifo) 3373 int automatic, int none, int nofifo)
@@ -3306,18 +3408,19 @@ static int __init parport_parse_dma(const char *dmastr, int *val)
3306#ifdef CONFIG_PCI 3408#ifdef CONFIG_PCI
3307static int __init parport_init_mode_setup(char *str) 3409static int __init parport_init_mode_setup(char *str)
3308{ 3410{
3309 printk(KERN_DEBUG "parport_pc.c: Specified parameter parport_init_mode=%s\n", str); 3411 printk(KERN_DEBUG
3310 3412 "parport_pc.c: Specified parameter parport_init_mode=%s\n", str);
3311 if (!strcmp (str, "spp")) 3413
3312 parport_init_mode=1; 3414 if (!strcmp(str, "spp"))
3313 if (!strcmp (str, "ps2")) 3415 parport_init_mode = 1;
3314 parport_init_mode=2; 3416 if (!strcmp(str, "ps2"))
3315 if (!strcmp (str, "epp")) 3417 parport_init_mode = 2;
3316 parport_init_mode=3; 3418 if (!strcmp(str, "epp"))
3317 if (!strcmp (str, "ecp")) 3419 parport_init_mode = 3;
3318 parport_init_mode=4; 3420 if (!strcmp(str, "ecp"))
3319 if (!strcmp (str, "ecpepp")) 3421 parport_init_mode = 4;
3320 parport_init_mode=5; 3422 if (!strcmp(str, "ecpepp"))
3423 parport_init_mode = 5;
3321 return 1; 3424 return 1;
3322} 3425}
3323#endif 3426#endif
@@ -3341,7 +3444,8 @@ module_param(verbose_probing, int, 0644);
3341#endif 3444#endif
3342#ifdef CONFIG_PCI 3445#ifdef CONFIG_PCI
3343static char *init_mode; 3446static char *init_mode;
3344MODULE_PARM_DESC(init_mode, "Initialise mode for VIA VT8231 port (spp, ps2, epp, ecp or ecpepp)"); 3447MODULE_PARM_DESC(init_mode,
3448 "Initialise mode for VIA VT8231 port (spp, ps2, epp, ecp or ecpepp)");
3345module_param(init_mode, charp, 0); 3449module_param(init_mode, charp, 0);
3346#endif 3450#endif
3347 3451
@@ -3372,7 +3476,7 @@ static int __init parse_parport_params(void)
3372 irqval[0] = val; 3476 irqval[0] = val;
3373 break; 3477 break;
3374 default: 3478 default:
3375 printk (KERN_WARNING 3479 printk(KERN_WARNING
3376 "parport_pc: irq specified " 3480 "parport_pc: irq specified "
3377 "without base address. Use 'io=' " 3481 "without base address. Use 'io=' "
3378 "to specify one\n"); 3482 "to specify one\n");
@@ -3385,7 +3489,7 @@ static int __init parse_parport_params(void)
3385 dmaval[0] = val; 3489 dmaval[0] = val;
3386 break; 3490 break;
3387 default: 3491 default:
3388 printk (KERN_WARNING 3492 printk(KERN_WARNING
3389 "parport_pc: dma specified " 3493 "parport_pc: dma specified "
3390 "without base address. Use 'io=' " 3494 "without base address. Use 'io=' "
3391 "to specify one\n"); 3495 "to specify one\n");
@@ -3396,7 +3500,7 @@ static int __init parse_parport_params(void)
3396 3500
3397#else 3501#else
3398 3502
3399static int parport_setup_ptr __initdata = 0; 3503static int parport_setup_ptr __initdata;
3400 3504
3401/* 3505/*
3402 * Acceptable parameters: 3506 * Acceptable parameters:
@@ -3407,7 +3511,7 @@ static int parport_setup_ptr __initdata = 0;
3407 * 3511 *
3408 * IRQ/DMA may be numeric or 'auto' or 'none' 3512 * IRQ/DMA may be numeric or 'auto' or 'none'
3409 */ 3513 */
3410static int __init parport_setup (char *str) 3514static int __init parport_setup(char *str)
3411{ 3515{
3412 char *endptr; 3516 char *endptr;
3413 char *sep; 3517 char *sep;
@@ -3419,15 +3523,15 @@ static int __init parport_setup (char *str)
3419 return 1; 3523 return 1;
3420 } 3524 }
3421 3525
3422 if (!strncmp (str, "auto", 4)) { 3526 if (!strncmp(str, "auto", 4)) {
3423 irqval[0] = PARPORT_IRQ_AUTO; 3527 irqval[0] = PARPORT_IRQ_AUTO;
3424 dmaval[0] = PARPORT_DMA_AUTO; 3528 dmaval[0] = PARPORT_DMA_AUTO;
3425 return 1; 3529 return 1;
3426 } 3530 }
3427 3531
3428 val = simple_strtoul (str, &endptr, 0); 3532 val = simple_strtoul(str, &endptr, 0);
3429 if (endptr == str) { 3533 if (endptr == str) {
3430 printk (KERN_WARNING "parport=%s not understood\n", str); 3534 printk(KERN_WARNING "parport=%s not understood\n", str);
3431 return 1; 3535 return 1;
3432 } 3536 }
3433 3537
@@ -3461,7 +3565,7 @@ static int __init parse_parport_params(void)
3461 return io[0] == PARPORT_DISABLE; 3565 return io[0] == PARPORT_DISABLE;
3462} 3566}
3463 3567
3464__setup ("parport=", parport_setup); 3568__setup("parport=", parport_setup);
3465 3569
3466/* 3570/*
3467 * Acceptable parameters: 3571 * Acceptable parameters:
@@ -3469,7 +3573,7 @@ __setup ("parport=", parport_setup);
3469 * parport_init_mode=[spp|ps2|epp|ecp|ecpepp] 3573 * parport_init_mode=[spp|ps2|epp|ecp|ecpepp]
3470 */ 3574 */
3471#ifdef CONFIG_PCI 3575#ifdef CONFIG_PCI
3472__setup("parport_init_mode=",parport_init_mode_setup); 3576__setup("parport_init_mode=", parport_init_mode_setup);
3473#endif 3577#endif
3474#endif 3578#endif
3475 3579
@@ -3493,13 +3597,13 @@ static int __init parport_pc_init(void)
3493 for (i = 0; i < PARPORT_PC_MAX_PORTS; i++) { 3597 for (i = 0; i < PARPORT_PC_MAX_PORTS; i++) {
3494 if (!io[i]) 3598 if (!io[i])
3495 break; 3599 break;
3496 if ((io_hi[i]) == PARPORT_IOHI_AUTO) 3600 if (io_hi[i] == PARPORT_IOHI_AUTO)
3497 io_hi[i] = 0x400 + io[i]; 3601 io_hi[i] = 0x400 + io[i];
3498 parport_pc_probe_port(io[i], io_hi[i], 3602 parport_pc_probe_port(io[i], io_hi[i],
3499 irqval[i], dmaval[i], NULL, 0); 3603 irqval[i], dmaval[i], NULL, 0);
3500 } 3604 }
3501 } else 3605 } else
3502 parport_pc_find_ports (irqval[0], dmaval[0]); 3606 parport_pc_find_ports(irqval[0], dmaval[0]);
3503 3607
3504 return 0; 3608 return 0;
3505} 3609}
@@ -3507,9 +3611,9 @@ static int __init parport_pc_init(void)
3507static void __exit parport_pc_exit(void) 3611static void __exit parport_pc_exit(void)
3508{ 3612{
3509 if (pci_registered_parport) 3613 if (pci_registered_parport)
3510 pci_unregister_driver (&parport_pc_pci_driver); 3614 pci_unregister_driver(&parport_pc_pci_driver);
3511 if (pnp_registered_parport) 3615 if (pnp_registered_parport)
3512 pnp_unregister_driver (&parport_pc_pnp_driver); 3616 pnp_unregister_driver(&parport_pc_pnp_driver);
3513 platform_driver_unregister(&parport_pc_platform_driver); 3617 platform_driver_unregister(&parport_pc_platform_driver);
3514 3618
3515 while (!list_empty(&ports_list)) { 3619 while (!list_empty(&ports_list)) {
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 4e9851fc1746..277d35d232fa 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -692,7 +692,7 @@ config RTC_DRV_GENERIC
692 tristate "Generic RTC support" 692 tristate "Generic RTC support"
693 # Please consider writing a new RTC driver instead of using the generic 693 # Please consider writing a new RTC driver instead of using the generic
694 # RTC abstraction 694 # RTC abstraction
695 depends on PARISC || M68K || PPC 695 depends on PARISC || M68K || PPC || SUPERH32
696 help 696 help
697 Say Y or M here to enable RTC support on systems using the generic 697 Say Y or M here to enable RTC support on systems using the generic
698 RTC abstraction. If you do not know what you are doing, you should 698 RTC abstraction. If you do not know what you are doing, you should
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index d1815272c435..27a1be0cd4d4 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -603,7 +603,7 @@ static void dasd_profile_end(struct dasd_block *block,
603 if (dasd_profile_level != DASD_PROFILE_ON) 603 if (dasd_profile_level != DASD_PROFILE_ON)
604 return; 604 return;
605 605
606 sectors = req->nr_sectors; 606 sectors = blk_rq_sectors(req);
607 if (!cqr->buildclk || !cqr->startclk || 607 if (!cqr->buildclk || !cqr->startclk ||
608 !cqr->stopclk || !cqr->endclk || 608 !cqr->stopclk || !cqr->endclk ||
609 !sectors) 609 !sectors)
@@ -1614,15 +1614,6 @@ void dasd_block_clear_timer(struct dasd_block *block)
1614} 1614}
1615 1615
1616/* 1616/*
1617 * posts the buffer_cache about a finalized request
1618 */
1619static inline void dasd_end_request(struct request *req, int error)
1620{
1621 if (__blk_end_request(req, error, blk_rq_bytes(req)))
1622 BUG();
1623}
1624
1625/*
1626 * Process finished error recovery ccw. 1617 * Process finished error recovery ccw.
1627 */ 1618 */
1628static inline void __dasd_block_process_erp(struct dasd_block *block, 1619static inline void __dasd_block_process_erp(struct dasd_block *block,
@@ -1665,18 +1656,14 @@ static void __dasd_process_request_queue(struct dasd_block *block)
1665 if (basedev->state < DASD_STATE_READY) 1656 if (basedev->state < DASD_STATE_READY)
1666 return; 1657 return;
1667 /* Now we try to fetch requests from the request queue */ 1658 /* Now we try to fetch requests from the request queue */
1668 while (!blk_queue_plugged(queue) && 1659 while (!blk_queue_plugged(queue) && (req = blk_peek_request(queue))) {
1669 elv_next_request(queue)) {
1670
1671 req = elv_next_request(queue);
1672
1673 if (basedev->features & DASD_FEATURE_READONLY && 1660 if (basedev->features & DASD_FEATURE_READONLY &&
1674 rq_data_dir(req) == WRITE) { 1661 rq_data_dir(req) == WRITE) {
1675 DBF_DEV_EVENT(DBF_ERR, basedev, 1662 DBF_DEV_EVENT(DBF_ERR, basedev,
1676 "Rejecting write request %p", 1663 "Rejecting write request %p",
1677 req); 1664 req);
1678 blkdev_dequeue_request(req); 1665 blk_start_request(req);
1679 dasd_end_request(req, -EIO); 1666 __blk_end_request_all(req, -EIO);
1680 continue; 1667 continue;
1681 } 1668 }
1682 cqr = basedev->discipline->build_cp(basedev, block, req); 1669 cqr = basedev->discipline->build_cp(basedev, block, req);
@@ -1704,8 +1691,8 @@ static void __dasd_process_request_queue(struct dasd_block *block)
1704 "CCW creation failed (rc=%ld) " 1691 "CCW creation failed (rc=%ld) "
1705 "on request %p", 1692 "on request %p",
1706 PTR_ERR(cqr), req); 1693 PTR_ERR(cqr), req);
1707 blkdev_dequeue_request(req); 1694 blk_start_request(req);
1708 dasd_end_request(req, -EIO); 1695 __blk_end_request_all(req, -EIO);
1709 continue; 1696 continue;
1710 } 1697 }
1711 /* 1698 /*
@@ -1714,7 +1701,7 @@ static void __dasd_process_request_queue(struct dasd_block *block)
1714 */ 1701 */
1715 cqr->callback_data = (void *) req; 1702 cqr->callback_data = (void *) req;
1716 cqr->status = DASD_CQR_FILLED; 1703 cqr->status = DASD_CQR_FILLED;
1717 blkdev_dequeue_request(req); 1704 blk_start_request(req);
1718 list_add_tail(&cqr->blocklist, &block->ccw_queue); 1705 list_add_tail(&cqr->blocklist, &block->ccw_queue);
1719 dasd_profile_start(block, cqr, req); 1706 dasd_profile_start(block, cqr, req);
1720 } 1707 }
@@ -1731,7 +1718,7 @@ static void __dasd_cleanup_cqr(struct dasd_ccw_req *cqr)
1731 status = cqr->block->base->discipline->free_cp(cqr, req); 1718 status = cqr->block->base->discipline->free_cp(cqr, req);
1732 if (status <= 0) 1719 if (status <= 0)
1733 error = status ? status : -EIO; 1720 error = status ? status : -EIO;
1734 dasd_end_request(req, error); 1721 __blk_end_request_all(req, error);
1735} 1722}
1736 1723
1737/* 1724/*
@@ -2003,7 +1990,7 @@ static void dasd_setup_queue(struct dasd_block *block)
2003{ 1990{
2004 int max; 1991 int max;
2005 1992
2006 blk_queue_hardsect_size(block->request_queue, block->bp_block); 1993 blk_queue_logical_block_size(block->request_queue, block->bp_block);
2007 max = block->base->discipline->max_blocks << block->s2b_shift; 1994 max = block->base->discipline->max_blocks << block->s2b_shift;
2008 blk_queue_max_sectors(block->request_queue, max); 1995 blk_queue_max_sectors(block->request_queue, max);
2009 blk_queue_max_phys_segments(block->request_queue, -1L); 1996 blk_queue_max_phys_segments(block->request_queue, -1L);
@@ -2038,10 +2025,8 @@ static void dasd_flush_request_queue(struct dasd_block *block)
2038 return; 2025 return;
2039 2026
2040 spin_lock_irq(&block->request_queue_lock); 2027 spin_lock_irq(&block->request_queue_lock);
2041 while ((req = elv_next_request(block->request_queue))) { 2028 while ((req = blk_fetch_request(block->request_queue)))
2042 blkdev_dequeue_request(req); 2029 __blk_end_request_all(req, -EIO);
2043 dasd_end_request(req, -EIO);
2044 }
2045 spin_unlock_irq(&block->request_queue_lock); 2030 spin_unlock_irq(&block->request_queue_lock);
2046} 2031}
2047 2032
diff --git a/drivers/s390/block/dasd_diag.c b/drivers/s390/block/dasd_diag.c
index b9a7f7733446..2efaddfae560 100644
--- a/drivers/s390/block/dasd_diag.c
+++ b/drivers/s390/block/dasd_diag.c
@@ -505,8 +505,9 @@ static struct dasd_ccw_req *dasd_diag_build_cp(struct dasd_device *memdev,
505 return ERR_PTR(-EINVAL); 505 return ERR_PTR(-EINVAL);
506 blksize = block->bp_block; 506 blksize = block->bp_block;
507 /* Calculate record id of first and last block. */ 507 /* Calculate record id of first and last block. */
508 first_rec = req->sector >> block->s2b_shift; 508 first_rec = blk_rq_pos(req) >> block->s2b_shift;
509 last_rec = (req->sector + req->nr_sectors - 1) >> block->s2b_shift; 509 last_rec =
510 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
510 /* Check struct bio and count the number of blocks for the request. */ 511 /* Check struct bio and count the number of blocks for the request. */
511 count = 0; 512 count = 0;
512 rq_for_each_segment(bv, req, iter) { 513 rq_for_each_segment(bv, req, iter) {
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index cb52da033f06..a41c94053e64 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -2354,10 +2354,10 @@ static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
2354 blksize = block->bp_block; 2354 blksize = block->bp_block;
2355 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); 2355 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
2356 /* Calculate record id of first and last block. */ 2356 /* Calculate record id of first and last block. */
2357 first_rec = first_trk = req->sector >> block->s2b_shift; 2357 first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
2358 first_offs = sector_div(first_trk, blk_per_trk); 2358 first_offs = sector_div(first_trk, blk_per_trk);
2359 last_rec = last_trk = 2359 last_rec = last_trk =
2360 (req->sector + req->nr_sectors - 1) >> block->s2b_shift; 2360 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
2361 last_offs = sector_div(last_trk, blk_per_trk); 2361 last_offs = sector_div(last_trk, blk_per_trk);
2362 cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk); 2362 cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
2363 2363
@@ -2420,7 +2420,7 @@ dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
2420 private = (struct dasd_eckd_private *) cqr->block->base->private; 2420 private = (struct dasd_eckd_private *) cqr->block->base->private;
2421 blksize = cqr->block->bp_block; 2421 blksize = cqr->block->bp_block;
2422 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize); 2422 blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
2423 recid = req->sector >> cqr->block->s2b_shift; 2423 recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
2424 ccw = cqr->cpaddr; 2424 ccw = cqr->cpaddr;
2425 /* Skip over define extent & locate record. */ 2425 /* Skip over define extent & locate record. */
2426 ccw++; 2426 ccw++;
diff --git a/drivers/s390/block/dasd_fba.c b/drivers/s390/block/dasd_fba.c
index a3eb6fd14673..8912358daa2f 100644
--- a/drivers/s390/block/dasd_fba.c
+++ b/drivers/s390/block/dasd_fba.c
@@ -270,8 +270,9 @@ static struct dasd_ccw_req *dasd_fba_build_cp(struct dasd_device * memdev,
270 return ERR_PTR(-EINVAL); 270 return ERR_PTR(-EINVAL);
271 blksize = block->bp_block; 271 blksize = block->bp_block;
272 /* Calculate record id of first and last block. */ 272 /* Calculate record id of first and last block. */
273 first_rec = req->sector >> block->s2b_shift; 273 first_rec = blk_rq_pos(req) >> block->s2b_shift;
274 last_rec = (req->sector + req->nr_sectors - 1) >> block->s2b_shift; 274 last_rec =
275 (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
275 /* Check struct bio and count the number of blocks for the request. */ 276 /* Check struct bio and count the number of blocks for the request. */
276 count = 0; 277 count = 0;
277 cidaw = 0; 278 cidaw = 0;
@@ -309,7 +310,7 @@ static struct dasd_ccw_req *dasd_fba_build_cp(struct dasd_device * memdev,
309 ccw = cqr->cpaddr; 310 ccw = cqr->cpaddr;
310 /* First ccw is define extent. */ 311 /* First ccw is define extent. */
311 define_extent(ccw++, cqr->data, rq_data_dir(req), 312 define_extent(ccw++, cqr->data, rq_data_dir(req),
312 block->bp_block, req->sector, req->nr_sectors); 313 block->bp_block, blk_rq_pos(req), blk_rq_sectors(req));
313 /* Build locate_record + read/write ccws. */ 314 /* Build locate_record + read/write ccws. */
314 idaws = (unsigned long *) (cqr->data + sizeof(struct DE_fba_data)); 315 idaws = (unsigned long *) (cqr->data + sizeof(struct DE_fba_data));
315 LO_data = (struct LO_fba_data *) (idaws + cidaw); 316 LO_data = (struct LO_fba_data *) (idaws + cidaw);
diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c
index cfdcf1aed33c..a4c7ffcd9987 100644
--- a/drivers/s390/block/dcssblk.c
+++ b/drivers/s390/block/dcssblk.c
@@ -602,7 +602,7 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
602 dev_info->gd->private_data = dev_info; 602 dev_info->gd->private_data = dev_info;
603 dev_info->gd->driverfs_dev = &dev_info->dev; 603 dev_info->gd->driverfs_dev = &dev_info->dev;
604 blk_queue_make_request(dev_info->dcssblk_queue, dcssblk_make_request); 604 blk_queue_make_request(dev_info->dcssblk_queue, dcssblk_make_request);
605 blk_queue_hardsect_size(dev_info->dcssblk_queue, 4096); 605 blk_queue_logical_block_size(dev_info->dcssblk_queue, 4096);
606 606
607 seg_byte_size = (dev_info->end - dev_info->start + 1); 607 seg_byte_size = (dev_info->end - dev_info->start + 1);
608 set_capacity(dev_info->gd, seg_byte_size >> 9); // size in sectors 608 set_capacity(dev_info->gd, seg_byte_size >> 9); // size in sectors
diff --git a/drivers/s390/block/xpram.c b/drivers/s390/block/xpram.c
index 76814f3e898a..0ae0c83ef879 100644
--- a/drivers/s390/block/xpram.c
+++ b/drivers/s390/block/xpram.c
@@ -343,7 +343,7 @@ static int __init xpram_setup_blkdev(void)
343 goto out; 343 goto out;
344 } 344 }
345 blk_queue_make_request(xpram_queues[i], xpram_make_request); 345 blk_queue_make_request(xpram_queues[i], xpram_make_request);
346 blk_queue_hardsect_size(xpram_queues[i], 4096); 346 blk_queue_logical_block_size(xpram_queues[i], 4096);
347 } 347 }
348 348
349 /* 349 /*
diff --git a/drivers/s390/char/tape_34xx.c b/drivers/s390/char/tape_34xx.c
index 5f8e8ef43dd3..2d00a383a475 100644
--- a/drivers/s390/char/tape_34xx.c
+++ b/drivers/s390/char/tape_34xx.c
@@ -1134,7 +1134,7 @@ tape_34xx_bread(struct tape_device *device, struct request *req)
1134 /* Setup ccws. */ 1134 /* Setup ccws. */
1135 request->op = TO_BLOCK; 1135 request->op = TO_BLOCK;
1136 start_block = (struct tape_34xx_block_id *) request->cpdata; 1136 start_block = (struct tape_34xx_block_id *) request->cpdata;
1137 start_block->block = req->sector >> TAPEBLOCK_HSEC_S2B; 1137 start_block->block = blk_rq_pos(req) >> TAPEBLOCK_HSEC_S2B;
1138 DBF_EVENT(6, "start_block = %i\n", start_block->block); 1138 DBF_EVENT(6, "start_block = %i\n", start_block->block);
1139 1139
1140 ccw = request->cpaddr; 1140 ccw = request->cpaddr;
diff --git a/drivers/s390/char/tape_3590.c b/drivers/s390/char/tape_3590.c
index 823b05bd0dd7..c453b2f3e9f4 100644
--- a/drivers/s390/char/tape_3590.c
+++ b/drivers/s390/char/tape_3590.c
@@ -633,7 +633,7 @@ tape_3590_bread(struct tape_device *device, struct request *req)
633 struct req_iterator iter; 633 struct req_iterator iter;
634 634
635 DBF_EVENT(6, "xBREDid:"); 635 DBF_EVENT(6, "xBREDid:");
636 start_block = req->sector >> TAPEBLOCK_HSEC_S2B; 636 start_block = blk_rq_pos(req) >> TAPEBLOCK_HSEC_S2B;
637 DBF_EVENT(6, "start_block = %i\n", start_block); 637 DBF_EVENT(6, "start_block = %i\n", start_block);
638 638
639 rq_for_each_segment(bv, req, iter) 639 rq_for_each_segment(bv, req, iter)
diff --git a/drivers/s390/char/tape_block.c b/drivers/s390/char/tape_block.c
index f32e89e7c4f2..47ff695255ea 100644
--- a/drivers/s390/char/tape_block.c
+++ b/drivers/s390/char/tape_block.c
@@ -74,13 +74,6 @@ tapeblock_trigger_requeue(struct tape_device *device)
74 * Post finished request. 74 * Post finished request.
75 */ 75 */
76static void 76static void
77tapeblock_end_request(struct request *req, int error)
78{
79 if (blk_end_request(req, error, blk_rq_bytes(req)))
80 BUG();
81}
82
83static void
84__tapeblock_end_request(struct tape_request *ccw_req, void *data) 77__tapeblock_end_request(struct tape_request *ccw_req, void *data)
85{ 78{
86 struct tape_device *device; 79 struct tape_device *device;
@@ -90,17 +83,17 @@ __tapeblock_end_request(struct tape_request *ccw_req, void *data)
90 83
91 device = ccw_req->device; 84 device = ccw_req->device;
92 req = (struct request *) data; 85 req = (struct request *) data;
93 tapeblock_end_request(req, (ccw_req->rc == 0) ? 0 : -EIO); 86 blk_end_request_all(req, (ccw_req->rc == 0) ? 0 : -EIO);
94 if (ccw_req->rc == 0) 87 if (ccw_req->rc == 0)
95 /* Update position. */ 88 /* Update position. */
96 device->blk_data.block_position = 89 device->blk_data.block_position =
97 (req->sector + req->nr_sectors) >> TAPEBLOCK_HSEC_S2B; 90 (blk_rq_pos(req) + blk_rq_sectors(req)) >> TAPEBLOCK_HSEC_S2B;
98 else 91 else
99 /* We lost the position information due to an error. */ 92 /* We lost the position information due to an error. */
100 device->blk_data.block_position = -1; 93 device->blk_data.block_position = -1;
101 device->discipline->free_bread(ccw_req); 94 device->discipline->free_bread(ccw_req);
102 if (!list_empty(&device->req_queue) || 95 if (!list_empty(&device->req_queue) ||
103 elv_next_request(device->blk_data.request_queue)) 96 blk_peek_request(device->blk_data.request_queue))
104 tapeblock_trigger_requeue(device); 97 tapeblock_trigger_requeue(device);
105} 98}
106 99
@@ -118,7 +111,7 @@ tapeblock_start_request(struct tape_device *device, struct request *req)
118 ccw_req = device->discipline->bread(device, req); 111 ccw_req = device->discipline->bread(device, req);
119 if (IS_ERR(ccw_req)) { 112 if (IS_ERR(ccw_req)) {
120 DBF_EVENT(1, "TBLOCK: bread failed\n"); 113 DBF_EVENT(1, "TBLOCK: bread failed\n");
121 tapeblock_end_request(req, -EIO); 114 blk_end_request_all(req, -EIO);
122 return PTR_ERR(ccw_req); 115 return PTR_ERR(ccw_req);
123 } 116 }
124 ccw_req->callback = __tapeblock_end_request; 117 ccw_req->callback = __tapeblock_end_request;
@@ -131,7 +124,7 @@ tapeblock_start_request(struct tape_device *device, struct request *req)
131 * Start/enqueueing failed. No retries in 124 * Start/enqueueing failed. No retries in
132 * this case. 125 * this case.
133 */ 126 */
134 tapeblock_end_request(req, -EIO); 127 blk_end_request_all(req, -EIO);
135 device->discipline->free_bread(ccw_req); 128 device->discipline->free_bread(ccw_req);
136 } 129 }
137 130
@@ -169,19 +162,16 @@ tapeblock_requeue(struct work_struct *work) {
169 spin_lock_irq(&device->blk_data.request_queue_lock); 162 spin_lock_irq(&device->blk_data.request_queue_lock);
170 while ( 163 while (
171 !blk_queue_plugged(queue) && 164 !blk_queue_plugged(queue) &&
172 elv_next_request(queue) && 165 (req = blk_fetch_request(queue)) &&
173 nr_queued < TAPEBLOCK_MIN_REQUEUE 166 nr_queued < TAPEBLOCK_MIN_REQUEUE
174 ) { 167 ) {
175 req = elv_next_request(queue);
176 if (rq_data_dir(req) == WRITE) { 168 if (rq_data_dir(req) == WRITE) {
177 DBF_EVENT(1, "TBLOCK: Rejecting write request\n"); 169 DBF_EVENT(1, "TBLOCK: Rejecting write request\n");
178 blkdev_dequeue_request(req);
179 spin_unlock_irq(&device->blk_data.request_queue_lock); 170 spin_unlock_irq(&device->blk_data.request_queue_lock);
180 tapeblock_end_request(req, -EIO); 171 blk_end_request_all(req, -EIO);
181 spin_lock_irq(&device->blk_data.request_queue_lock); 172 spin_lock_irq(&device->blk_data.request_queue_lock);
182 continue; 173 continue;
183 } 174 }
184 blkdev_dequeue_request(req);
185 nr_queued++; 175 nr_queued++;
186 spin_unlock_irq(&device->blk_data.request_queue_lock); 176 spin_unlock_irq(&device->blk_data.request_queue_lock);
187 rc = tapeblock_start_request(device, req); 177 rc = tapeblock_start_request(device, req);
@@ -232,7 +222,7 @@ tapeblock_setup_device(struct tape_device * device)
232 if (rc) 222 if (rc)
233 goto cleanup_queue; 223 goto cleanup_queue;
234 224
235 blk_queue_hardsect_size(blkdat->request_queue, TAPEBLOCK_HSEC_SIZE); 225 blk_queue_logical_block_size(blkdat->request_queue, TAPEBLOCK_HSEC_SIZE);
236 blk_queue_max_sectors(blkdat->request_queue, TAPEBLOCK_MAX_SEC); 226 blk_queue_max_sectors(blkdat->request_queue, TAPEBLOCK_MAX_SEC);
237 blk_queue_max_phys_segments(blkdat->request_queue, -1L); 227 blk_queue_max_phys_segments(blkdat->request_queue, -1L);
238 blk_queue_max_hw_segments(blkdat->request_queue, -1L); 228 blk_queue_max_hw_segments(blkdat->request_queue, -1L);
diff --git a/drivers/sbus/char/jsflash.c b/drivers/sbus/char/jsflash.c
index a85ad05e8548..6d4651684688 100644
--- a/drivers/sbus/char/jsflash.c
+++ b/drivers/sbus/char/jsflash.c
@@ -186,31 +186,31 @@ static void jsfd_do_request(struct request_queue *q)
186{ 186{
187 struct request *req; 187 struct request *req;
188 188
189 while ((req = elv_next_request(q)) != NULL) { 189 req = blk_fetch_request(q);
190 while (req) {
190 struct jsfd_part *jdp = req->rq_disk->private_data; 191 struct jsfd_part *jdp = req->rq_disk->private_data;
191 unsigned long offset = req->sector << 9; 192 unsigned long offset = blk_rq_pos(req) << 9;
192 size_t len = req->current_nr_sectors << 9; 193 size_t len = blk_rq_cur_bytes(req);
194 int err = -EIO;
193 195
194 if ((offset + len) > jdp->dsize) { 196 if ((offset + len) > jdp->dsize)
195 end_request(req, 0); 197 goto end;
196 continue;
197 }
198 198
199 if (rq_data_dir(req) != READ) { 199 if (rq_data_dir(req) != READ) {
200 printk(KERN_ERR "jsfd: write\n"); 200 printk(KERN_ERR "jsfd: write\n");
201 end_request(req, 0); 201 goto end;
202 continue;
203 } 202 }
204 203
205 if ((jdp->dbase & 0xff000000) != 0x20000000) { 204 if ((jdp->dbase & 0xff000000) != 0x20000000) {
206 printk(KERN_ERR "jsfd: bad base %x\n", (int)jdp->dbase); 205 printk(KERN_ERR "jsfd: bad base %x\n", (int)jdp->dbase);
207 end_request(req, 0); 206 goto end;
208 continue;
209 } 207 }
210 208
211 jsfd_read(req->buffer, jdp->dbase + offset, len); 209 jsfd_read(req->buffer, jdp->dbase + offset, len);
212 210 err = 0;
213 end_request(req, 1); 211 end:
212 if (!__blk_end_request_cur(req, err))
213 req = blk_fetch_request(q);
214 } 214 }
215} 215}
216 216
diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
index be5099dd94b5..c7076ce25e21 100644
--- a/drivers/scsi/eata.c
+++ b/drivers/scsi/eata.c
@@ -1825,7 +1825,7 @@ static int eata2x_queuecommand(struct scsi_cmnd *SCpnt,
1825 if (linked_comm && SCpnt->device->queue_depth > 2 1825 if (linked_comm && SCpnt->device->queue_depth > 2
1826 && TLDEV(SCpnt->device->type)) { 1826 && TLDEV(SCpnt->device->type)) {
1827 ha->cp_stat[i] = READY; 1827 ha->cp_stat[i] = READY;
1828 flush_dev(SCpnt->device, SCpnt->request->sector, ha, 0); 1828 flush_dev(SCpnt->device, blk_rq_pos(SCpnt->request), ha, 0);
1829 return 0; 1829 return 0;
1830 } 1830 }
1831 1831
@@ -2144,13 +2144,13 @@ static int reorder(struct hostdata *ha, unsigned long cursec,
2144 if (!cpp->din) 2144 if (!cpp->din)
2145 input_only = 0; 2145 input_only = 0;
2146 2146
2147 if (SCpnt->request->sector < minsec) 2147 if (blk_rq_pos(SCpnt->request) < minsec)
2148 minsec = SCpnt->request->sector; 2148 minsec = blk_rq_pos(SCpnt->request);
2149 if (SCpnt->request->sector > maxsec) 2149 if (blk_rq_pos(SCpnt->request) > maxsec)
2150 maxsec = SCpnt->request->sector; 2150 maxsec = blk_rq_pos(SCpnt->request);
2151 2151
2152 sl[n] = SCpnt->request->sector; 2152 sl[n] = blk_rq_pos(SCpnt->request);
2153 ioseek += SCpnt->request->nr_sectors; 2153 ioseek += blk_rq_sectors(SCpnt->request);
2154 2154
2155 if (!n) 2155 if (!n)
2156 continue; 2156 continue;
@@ -2190,7 +2190,7 @@ static int reorder(struct hostdata *ha, unsigned long cursec,
2190 k = il[n]; 2190 k = il[n];
2191 cpp = &ha->cp[k]; 2191 cpp = &ha->cp[k];
2192 SCpnt = cpp->SCpnt; 2192 SCpnt = cpp->SCpnt;
2193 ll[n] = SCpnt->request->nr_sectors; 2193 ll[n] = blk_rq_sectors(SCpnt->request);
2194 pl[n] = SCpnt->serial_number; 2194 pl[n] = SCpnt->serial_number;
2195 2195
2196 if (!n) 2196 if (!n)
@@ -2236,12 +2236,12 @@ static int reorder(struct hostdata *ha, unsigned long cursec,
2236 cpp = &ha->cp[k]; 2236 cpp = &ha->cp[k];
2237 SCpnt = cpp->SCpnt; 2237 SCpnt = cpp->SCpnt;
2238 scmd_printk(KERN_INFO, SCpnt, 2238 scmd_printk(KERN_INFO, SCpnt,
2239 "%s pid %ld mb %d fc %d nr %d sec %ld ns %ld" 2239 "%s pid %ld mb %d fc %d nr %d sec %ld ns %u"
2240 " cur %ld s:%c r:%c rev:%c in:%c ov:%c xd %d.\n", 2240 " cur %ld s:%c r:%c rev:%c in:%c ov:%c xd %d.\n",
2241 (ihdlr ? "ihdlr" : "qcomm"), 2241 (ihdlr ? "ihdlr" : "qcomm"),
2242 SCpnt->serial_number, k, flushcount, 2242 SCpnt->serial_number, k, flushcount,
2243 n_ready, SCpnt->request->sector, 2243 n_ready, blk_rq_pos(SCpnt->request),
2244 SCpnt->request->nr_sectors, cursec, YESNO(s), 2244 blk_rq_sectors(SCpnt->request), cursec, YESNO(s),
2245 YESNO(r), YESNO(rev), YESNO(input_only), 2245 YESNO(r), YESNO(rev), YESNO(input_only),
2246 YESNO(overlap), cpp->din); 2246 YESNO(overlap), cpp->din);
2247 } 2247 }
@@ -2408,7 +2408,7 @@ static irqreturn_t ihdlr(struct Scsi_Host *shost)
2408 2408
2409 if (linked_comm && SCpnt->device->queue_depth > 2 2409 if (linked_comm && SCpnt->device->queue_depth > 2
2410 && TLDEV(SCpnt->device->type)) 2410 && TLDEV(SCpnt->device->type))
2411 flush_dev(SCpnt->device, SCpnt->request->sector, ha, 1); 2411 flush_dev(SCpnt->device, blk_rq_pos(SCpnt->request), ha, 1);
2412 2412
2413 tstatus = status_byte(spp->target_status); 2413 tstatus = status_byte(spp->target_status);
2414 2414
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index 3da02e436788..54fa1e42dc4d 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -1927,21 +1927,21 @@ int sas_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1927 /* do we need to support multiple segments? */ 1927 /* do we need to support multiple segments? */
1928 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) { 1928 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
1929 printk("%s: multiple segments req %u %u, rsp %u %u\n", 1929 printk("%s: multiple segments req %u %u, rsp %u %u\n",
1930 __func__, req->bio->bi_vcnt, req->data_len, 1930 __func__, req->bio->bi_vcnt, blk_rq_bytes(req),
1931 rsp->bio->bi_vcnt, rsp->data_len); 1931 rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
1932 return -EINVAL; 1932 return -EINVAL;
1933 } 1933 }
1934 1934
1935 ret = smp_execute_task(dev, bio_data(req->bio), req->data_len, 1935 ret = smp_execute_task(dev, bio_data(req->bio), blk_rq_bytes(req),
1936 bio_data(rsp->bio), rsp->data_len); 1936 bio_data(rsp->bio), blk_rq_bytes(rsp));
1937 if (ret > 0) { 1937 if (ret > 0) {
1938 /* positive number is the untransferred residual */ 1938 /* positive number is the untransferred residual */
1939 rsp->data_len = ret; 1939 rsp->resid_len = ret;
1940 req->data_len = 0; 1940 req->resid_len = 0;
1941 ret = 0; 1941 ret = 0;
1942 } else if (ret == 0) { 1942 } else if (ret == 0) {
1943 rsp->data_len = 0; 1943 rsp->resid_len = 0;
1944 req->data_len = 0; 1944 req->resid_len = 0;
1945 } 1945 }
1946 1946
1947 return ret; 1947 return ret;
diff --git a/drivers/scsi/libsas/sas_host_smp.c b/drivers/scsi/libsas/sas_host_smp.c
index d110a366c48a..1bc3b7567994 100644
--- a/drivers/scsi/libsas/sas_host_smp.c
+++ b/drivers/scsi/libsas/sas_host_smp.c
@@ -134,24 +134,24 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
134{ 134{
135 u8 *req_data = NULL, *resp_data = NULL, *buf; 135 u8 *req_data = NULL, *resp_data = NULL, *buf;
136 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost); 136 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
137 int error = -EINVAL, resp_data_len = rsp->data_len; 137 int error = -EINVAL;
138 138
139 /* eight is the minimum size for request and response frames */ 139 /* eight is the minimum size for request and response frames */
140 if (req->data_len < 8 || rsp->data_len < 8) 140 if (blk_rq_bytes(req) < 8 || blk_rq_bytes(rsp) < 8)
141 goto out; 141 goto out;
142 142
143 if (bio_offset(req->bio) + req->data_len > PAGE_SIZE || 143 if (bio_offset(req->bio) + blk_rq_bytes(req) > PAGE_SIZE ||
144 bio_offset(rsp->bio) + rsp->data_len > PAGE_SIZE) { 144 bio_offset(rsp->bio) + blk_rq_bytes(rsp) > PAGE_SIZE) {
145 shost_printk(KERN_ERR, shost, 145 shost_printk(KERN_ERR, shost,
146 "SMP request/response frame crosses page boundary"); 146 "SMP request/response frame crosses page boundary");
147 goto out; 147 goto out;
148 } 148 }
149 149
150 req_data = kzalloc(req->data_len, GFP_KERNEL); 150 req_data = kzalloc(blk_rq_bytes(req), GFP_KERNEL);
151 151
152 /* make sure frame can always be built ... we copy 152 /* make sure frame can always be built ... we copy
153 * back only the requested length */ 153 * back only the requested length */
154 resp_data = kzalloc(max(rsp->data_len, 128U), GFP_KERNEL); 154 resp_data = kzalloc(max(blk_rq_bytes(rsp), 128U), GFP_KERNEL);
155 155
156 if (!req_data || !resp_data) { 156 if (!req_data || !resp_data) {
157 error = -ENOMEM; 157 error = -ENOMEM;
@@ -160,7 +160,7 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
160 160
161 local_irq_disable(); 161 local_irq_disable();
162 buf = kmap_atomic(bio_page(req->bio), KM_USER0) + bio_offset(req->bio); 162 buf = kmap_atomic(bio_page(req->bio), KM_USER0) + bio_offset(req->bio);
163 memcpy(req_data, buf, req->data_len); 163 memcpy(req_data, buf, blk_rq_bytes(req));
164 kunmap_atomic(buf - bio_offset(req->bio), KM_USER0); 164 kunmap_atomic(buf - bio_offset(req->bio), KM_USER0);
165 local_irq_enable(); 165 local_irq_enable();
166 166
@@ -178,15 +178,15 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
178 178
179 switch (req_data[1]) { 179 switch (req_data[1]) {
180 case SMP_REPORT_GENERAL: 180 case SMP_REPORT_GENERAL:
181 req->data_len -= 8; 181 req->resid_len -= 8;
182 resp_data_len -= 32; 182 rsp->resid_len -= 32;
183 resp_data[2] = SMP_RESP_FUNC_ACC; 183 resp_data[2] = SMP_RESP_FUNC_ACC;
184 resp_data[9] = sas_ha->num_phys; 184 resp_data[9] = sas_ha->num_phys;
185 break; 185 break;
186 186
187 case SMP_REPORT_MANUF_INFO: 187 case SMP_REPORT_MANUF_INFO:
188 req->data_len -= 8; 188 req->resid_len -= 8;
189 resp_data_len -= 64; 189 rsp->resid_len -= 64;
190 resp_data[2] = SMP_RESP_FUNC_ACC; 190 resp_data[2] = SMP_RESP_FUNC_ACC;
191 memcpy(resp_data + 12, shost->hostt->name, 191 memcpy(resp_data + 12, shost->hostt->name,
192 SAS_EXPANDER_VENDOR_ID_LEN); 192 SAS_EXPANDER_VENDOR_ID_LEN);
@@ -199,13 +199,13 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
199 break; 199 break;
200 200
201 case SMP_DISCOVER: 201 case SMP_DISCOVER:
202 req->data_len -= 16; 202 req->resid_len -= 16;
203 if ((int)req->data_len < 0) { 203 if ((int)req->resid_len < 0) {
204 req->data_len = 0; 204 req->resid_len = 0;
205 error = -EINVAL; 205 error = -EINVAL;
206 goto out; 206 goto out;
207 } 207 }
208 resp_data_len -= 56; 208 rsp->resid_len -= 56;
209 sas_host_smp_discover(sas_ha, resp_data, req_data[9]); 209 sas_host_smp_discover(sas_ha, resp_data, req_data[9]);
210 break; 210 break;
211 211
@@ -215,13 +215,13 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
215 break; 215 break;
216 216
217 case SMP_REPORT_PHY_SATA: 217 case SMP_REPORT_PHY_SATA:
218 req->data_len -= 16; 218 req->resid_len -= 16;
219 if ((int)req->data_len < 0) { 219 if ((int)req->resid_len < 0) {
220 req->data_len = 0; 220 req->resid_len = 0;
221 error = -EINVAL; 221 error = -EINVAL;
222 goto out; 222 goto out;
223 } 223 }
224 resp_data_len -= 60; 224 rsp->resid_len -= 60;
225 sas_report_phy_sata(sas_ha, resp_data, req_data[9]); 225 sas_report_phy_sata(sas_ha, resp_data, req_data[9]);
226 break; 226 break;
227 227
@@ -238,13 +238,13 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
238 break; 238 break;
239 239
240 case SMP_PHY_CONTROL: 240 case SMP_PHY_CONTROL:
241 req->data_len -= 44; 241 req->resid_len -= 44;
242 if ((int)req->data_len < 0) { 242 if ((int)req->resid_len < 0) {
243 req->data_len = 0; 243 req->resid_len = 0;
244 error = -EINVAL; 244 error = -EINVAL;
245 goto out; 245 goto out;
246 } 246 }
247 resp_data_len -= 8; 247 rsp->resid_len -= 8;
248 sas_phy_control(sas_ha, req_data[9], req_data[10], 248 sas_phy_control(sas_ha, req_data[9], req_data[10],
249 req_data[32] >> 4, req_data[33] >> 4, 249 req_data[32] >> 4, req_data[33] >> 4,
250 resp_data); 250 resp_data);
@@ -261,11 +261,10 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
261 261
262 local_irq_disable(); 262 local_irq_disable();
263 buf = kmap_atomic(bio_page(rsp->bio), KM_USER0) + bio_offset(rsp->bio); 263 buf = kmap_atomic(bio_page(rsp->bio), KM_USER0) + bio_offset(rsp->bio);
264 memcpy(buf, resp_data, rsp->data_len); 264 memcpy(buf, resp_data, blk_rq_bytes(rsp));
265 flush_kernel_dcache_page(bio_page(rsp->bio)); 265 flush_kernel_dcache_page(bio_page(rsp->bio));
266 kunmap_atomic(buf - bio_offset(rsp->bio), KM_USER0); 266 kunmap_atomic(buf - bio_offset(rsp->bio), KM_USER0);
267 local_irq_enable(); 267 local_irq_enable();
268 rsp->data_len = resp_data_len;
269 268
270 out: 269 out:
271 kfree(req_data); 270 kfree(req_data);
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index 167b66dd34c7..8032c5adb6a9 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -1312,10 +1312,10 @@ lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd,
1312 uint32_t bgstat = bgf->bgstat; 1312 uint32_t bgstat = bgf->bgstat;
1313 uint64_t failing_sector = 0; 1313 uint64_t failing_sector = 0;
1314 1314
1315 printk(KERN_ERR "BG ERROR in cmd 0x%x lba 0x%llx blk cnt 0x%lx " 1315 printk(KERN_ERR "BG ERROR in cmd 0x%x lba 0x%llx blk cnt 0x%x "
1316 "bgstat=0x%x bghm=0x%x\n", 1316 "bgstat=0x%x bghm=0x%x\n",
1317 cmd->cmnd[0], (unsigned long long)scsi_get_lba(cmd), 1317 cmd->cmnd[0], (unsigned long long)scsi_get_lba(cmd),
1318 cmd->request->nr_sectors, bgstat, bghm); 1318 blk_rq_sectors(cmd->request), bgstat, bghm);
1319 1319
1320 spin_lock(&_dump_buf_lock); 1320 spin_lock(&_dump_buf_lock);
1321 if (!_dump_buf_done) { 1321 if (!_dump_buf_done) {
@@ -2378,15 +2378,15 @@ lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
2378 if (cmnd->cmnd[0] == READ_10) 2378 if (cmnd->cmnd[0] == READ_10)
2379 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, 2379 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
2380 "9035 BLKGRD: READ @ sector %llu, " 2380 "9035 BLKGRD: READ @ sector %llu, "
2381 "count %lu\n", 2381 "count %u\n",
2382 (unsigned long long)scsi_get_lba(cmnd), 2382 (unsigned long long)scsi_get_lba(cmnd),
2383 cmnd->request->nr_sectors); 2383 blk_rq_sectors(cmnd->request));
2384 else if (cmnd->cmnd[0] == WRITE_10) 2384 else if (cmnd->cmnd[0] == WRITE_10)
2385 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, 2385 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
2386 "9036 BLKGRD: WRITE @ sector %llu, " 2386 "9036 BLKGRD: WRITE @ sector %llu, "
2387 "count %lu cmd=%p\n", 2387 "count %u cmd=%p\n",
2388 (unsigned long long)scsi_get_lba(cmnd), 2388 (unsigned long long)scsi_get_lba(cmnd),
2389 cmnd->request->nr_sectors, 2389 blk_rq_sectors(cmnd->request),
2390 cmnd); 2390 cmnd);
2391 2391
2392 err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd); 2392 err = lpfc_bg_scsi_prep_dma_buf(phba, lpfc_cmd);
@@ -2406,15 +2406,15 @@ lpfc_queuecommand(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd *))
2406 if (cmnd->cmnd[0] == READ_10) 2406 if (cmnd->cmnd[0] == READ_10)
2407 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, 2407 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
2408 "9040 dbg: READ @ sector %llu, " 2408 "9040 dbg: READ @ sector %llu, "
2409 "count %lu\n", 2409 "count %u\n",
2410 (unsigned long long)scsi_get_lba(cmnd), 2410 (unsigned long long)scsi_get_lba(cmnd),
2411 cmnd->request->nr_sectors); 2411 blk_rq_sectors(cmnd->request));
2412 else if (cmnd->cmnd[0] == WRITE_10) 2412 else if (cmnd->cmnd[0] == WRITE_10)
2413 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, 2413 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
2414 "9041 dbg: WRITE @ sector %llu, " 2414 "9041 dbg: WRITE @ sector %llu, "
2415 "count %lu cmd=%p\n", 2415 "count %u cmd=%p\n",
2416 (unsigned long long)scsi_get_lba(cmnd), 2416 (unsigned long long)scsi_get_lba(cmnd),
2417 cmnd->request->nr_sectors, cmnd); 2417 blk_rq_sectors(cmnd->request), cmnd);
2418 else 2418 else
2419 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG, 2419 lpfc_printf_vlog(vport, KERN_WARNING, LOG_BG,
2420 "9042 dbg: parser not implemented\n"); 2420 "9042 dbg: parser not implemented\n");
diff --git a/drivers/scsi/mpt2sas/mpt2sas_transport.c b/drivers/scsi/mpt2sas/mpt2sas_transport.c
index e03dc0b1e1a0..5c65da519e39 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_transport.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_transport.c
@@ -1041,7 +1041,7 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1041 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) { 1041 if (req->bio->bi_vcnt > 1 || rsp->bio->bi_vcnt > 1) {
1042 printk(MPT2SAS_ERR_FMT "%s: multiple segments req %u %u, " 1042 printk(MPT2SAS_ERR_FMT "%s: multiple segments req %u %u, "
1043 "rsp %u %u\n", ioc->name, __func__, req->bio->bi_vcnt, 1043 "rsp %u %u\n", ioc->name, __func__, req->bio->bi_vcnt,
1044 req->data_len, rsp->bio->bi_vcnt, rsp->data_len); 1044 blk_rq_bytes(req), rsp->bio->bi_vcnt, blk_rq_bytes(rsp));
1045 return -EINVAL; 1045 return -EINVAL;
1046 } 1046 }
1047 1047
@@ -1104,7 +1104,7 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1104 *((u64 *)&mpi_request->SASAddress) = (rphy) ? 1104 *((u64 *)&mpi_request->SASAddress) = (rphy) ?
1105 cpu_to_le64(rphy->identify.sas_address) : 1105 cpu_to_le64(rphy->identify.sas_address) :
1106 cpu_to_le64(ioc->sas_hba.sas_address); 1106 cpu_to_le64(ioc->sas_hba.sas_address);
1107 mpi_request->RequestDataLength = cpu_to_le16(req->data_len - 4); 1107 mpi_request->RequestDataLength = cpu_to_le16(blk_rq_bytes(req) - 4);
1108 psge = &mpi_request->SGL; 1108 psge = &mpi_request->SGL;
1109 1109
1110 /* WRITE sgel first */ 1110 /* WRITE sgel first */
@@ -1112,13 +1112,13 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1112 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC); 1112 MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_HOST_TO_IOC);
1113 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; 1113 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1114 dma_addr_out = pci_map_single(ioc->pdev, bio_data(req->bio), 1114 dma_addr_out = pci_map_single(ioc->pdev, bio_data(req->bio),
1115 req->data_len, PCI_DMA_BIDIRECTIONAL); 1115 blk_rq_bytes(req), PCI_DMA_BIDIRECTIONAL);
1116 if (!dma_addr_out) { 1116 if (!dma_addr_out) {
1117 mpt2sas_base_free_smid(ioc, le16_to_cpu(smid)); 1117 mpt2sas_base_free_smid(ioc, le16_to_cpu(smid));
1118 goto unmap; 1118 goto unmap;
1119 } 1119 }
1120 1120
1121 ioc->base_add_sg_single(psge, sgl_flags | (req->data_len - 4), 1121 ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(req) - 4),
1122 dma_addr_out); 1122 dma_addr_out);
1123 1123
1124 /* incr sgel */ 1124 /* incr sgel */
@@ -1129,14 +1129,14 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1129 MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER | 1129 MPI2_SGE_FLAGS_LAST_ELEMENT | MPI2_SGE_FLAGS_END_OF_BUFFER |
1130 MPI2_SGE_FLAGS_END_OF_LIST); 1130 MPI2_SGE_FLAGS_END_OF_LIST);
1131 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT; 1131 sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
1132 dma_addr_in = pci_map_single(ioc->pdev, bio_data(rsp->bio), 1132 dma_addr_in = pci_map_single(ioc->pdev, bio_data(rsp->bio),
1133 rsp->data_len, PCI_DMA_BIDIRECTIONAL); 1133 blk_rq_bytes(rsp), PCI_DMA_BIDIRECTIONAL);
1134 if (!dma_addr_in) { 1134 if (!dma_addr_in) {
1135 mpt2sas_base_free_smid(ioc, le16_to_cpu(smid)); 1135 mpt2sas_base_free_smid(ioc, le16_to_cpu(smid));
1136 goto unmap; 1136 goto unmap;
1137 } 1137 }
1138 1138
1139 ioc->base_add_sg_single(psge, sgl_flags | (rsp->data_len + 4), 1139 ioc->base_add_sg_single(psge, sgl_flags | (blk_rq_bytes(rsp) + 4),
1140 dma_addr_in); 1140 dma_addr_in);
1141 1141
1142 dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s - " 1142 dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s - "
@@ -1170,9 +1170,8 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1170 1170
1171 memcpy(req->sense, mpi_reply, sizeof(*mpi_reply)); 1171 memcpy(req->sense, mpi_reply, sizeof(*mpi_reply));
1172 req->sense_len = sizeof(*mpi_reply); 1172 req->sense_len = sizeof(*mpi_reply);
1173 req->data_len = 0; 1173 req->resid_len = 0;
1174 rsp->data_len -= mpi_reply->ResponseDataLength; 1174 rsp->resid_len -= mpi_reply->ResponseDataLength;
1175
1176 } else { 1175 } else {
1177 dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT 1176 dtransportprintk(ioc, printk(MPT2SAS_DEBUG_FMT
1178 "%s - no reply\n", ioc->name, __func__)); 1177 "%s - no reply\n", ioc->name, __func__));
@@ -1188,10 +1187,10 @@ transport_smp_handler(struct Scsi_Host *shost, struct sas_rphy *rphy,
1188 1187
1189 unmap: 1188 unmap:
1190 if (dma_addr_out) 1189 if (dma_addr_out)
1191 pci_unmap_single(ioc->pdev, dma_addr_out, req->data_len, 1190 pci_unmap_single(ioc->pdev, dma_addr_out, blk_rq_bytes(req),
1192 PCI_DMA_BIDIRECTIONAL); 1191 PCI_DMA_BIDIRECTIONAL);
1193 if (dma_addr_in) 1192 if (dma_addr_in)
1194 pci_unmap_single(ioc->pdev, dma_addr_in, rsp->data_len, 1193 pci_unmap_single(ioc->pdev, dma_addr_in, blk_rq_bytes(rsp),
1195 PCI_DMA_BIDIRECTIONAL); 1194 PCI_DMA_BIDIRECTIONAL);
1196 1195
1197 out: 1196 out:
diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c
index 1ce6b24abab2..5776b2ab6b12 100644
--- a/drivers/scsi/osd/osd_initiator.c
+++ b/drivers/scsi/osd/osd_initiator.c
@@ -889,26 +889,6 @@ int osd_req_add_set_attr_list(struct osd_request *or,
889} 889}
890EXPORT_SYMBOL(osd_req_add_set_attr_list); 890EXPORT_SYMBOL(osd_req_add_set_attr_list);
891 891
892static int _append_map_kern(struct request *req,
893 void *buff, unsigned len, gfp_t flags)
894{
895 struct bio *bio;
896 int ret;
897
898 bio = bio_map_kern(req->q, buff, len, flags);
899 if (IS_ERR(bio)) {
900 OSD_ERR("Failed bio_map_kern(%p, %d) => %ld\n", buff, len,
901 PTR_ERR(bio));
902 return PTR_ERR(bio);
903 }
904 ret = blk_rq_append_bio(req->q, req, bio);
905 if (ret) {
906 OSD_ERR("Failed blk_rq_append_bio(%p) => %d\n", bio, ret);
907 bio_put(bio);
908 }
909 return ret;
910}
911
912static int _req_append_segment(struct osd_request *or, 892static int _req_append_segment(struct osd_request *or,
913 unsigned padding, struct _osd_req_data_segment *seg, 893 unsigned padding, struct _osd_req_data_segment *seg,
914 struct _osd_req_data_segment *last_seg, struct _osd_io_info *io) 894 struct _osd_req_data_segment *last_seg, struct _osd_io_info *io)
@@ -924,14 +904,14 @@ static int _req_append_segment(struct osd_request *or,
924 else 904 else
925 pad_buff = io->pad_buff; 905 pad_buff = io->pad_buff;
926 906
927 ret = _append_map_kern(io->req, pad_buff, padding, 907 ret = blk_rq_map_kern(io->req->q, io->req, pad_buff, padding,
928 or->alloc_flags); 908 or->alloc_flags);
929 if (ret) 909 if (ret)
930 return ret; 910 return ret;
931 io->total_bytes += padding; 911 io->total_bytes += padding;
932 } 912 }
933 913
934 ret = _append_map_kern(io->req, seg->buff, seg->total_bytes, 914 ret = blk_rq_map_kern(io->req->q, io->req, seg->buff, seg->total_bytes,
935 or->alloc_flags); 915 or->alloc_flags);
936 if (ret) 916 if (ret)
937 return ret; 917 return ret;
@@ -1293,6 +1273,21 @@ static int _osd_req_finalize_data_integrity(struct osd_request *or,
1293/* 1273/*
1294 * osd_finalize_request and helpers 1274 * osd_finalize_request and helpers
1295 */ 1275 */
1276static struct request *_make_request(struct request_queue *q, bool has_write,
1277 struct _osd_io_info *oii, gfp_t flags)
1278{
1279 if (oii->bio)
1280 return blk_make_request(q, oii->bio, flags);
1281 else {
1282 struct request *req;
1283
1284 req = blk_get_request(q, has_write ? WRITE : READ, flags);
1285 if (unlikely(!req))
1286 return ERR_PTR(-ENOMEM);
1287
1288 return req;
1289 }
1290}
1296 1291
1297static int _init_blk_request(struct osd_request *or, 1292static int _init_blk_request(struct osd_request *or,
1298 bool has_in, bool has_out) 1293 bool has_in, bool has_out)
@@ -1301,11 +1296,13 @@ static int _init_blk_request(struct osd_request *or,
1301 struct scsi_device *scsi_device = or->osd_dev->scsi_device; 1296 struct scsi_device *scsi_device = or->osd_dev->scsi_device;
1302 struct request_queue *q = scsi_device->request_queue; 1297 struct request_queue *q = scsi_device->request_queue;
1303 struct request *req; 1298 struct request *req;
1304 int ret = -ENOMEM; 1299 int ret;
1305 1300
1306 req = blk_get_request(q, has_out, flags); 1301 req = _make_request(q, has_out, has_out ? &or->out : &or->in, flags);
1307 if (!req) 1302 if (IS_ERR(req)) {
1303 ret = PTR_ERR(req);
1308 goto out; 1304 goto out;
1305 }
1309 1306
1310 or->request = req; 1307 or->request = req;
1311 req->cmd_type = REQ_TYPE_BLOCK_PC; 1308 req->cmd_type = REQ_TYPE_BLOCK_PC;
@@ -1318,9 +1315,10 @@ static int _init_blk_request(struct osd_request *or,
1318 or->out.req = req; 1315 or->out.req = req;
1319 if (has_in) { 1316 if (has_in) {
1320 /* allocate bidi request */ 1317 /* allocate bidi request */
1321 req = blk_get_request(q, READ, flags); 1318 req = _make_request(q, false, &or->in, flags);
1322 if (!req) { 1319 if (IS_ERR(req)) {
1323 OSD_DEBUG("blk_get_request for bidi failed\n"); 1320 OSD_DEBUG("blk_get_request for bidi failed\n");
1321 ret = PTR_ERR(req);
1324 goto out; 1322 goto out;
1325 } 1323 }
1326 req->cmd_type = REQ_TYPE_BLOCK_PC; 1324 req->cmd_type = REQ_TYPE_BLOCK_PC;
@@ -1364,26 +1362,6 @@ int osd_finalize_request(struct osd_request *or,
1364 return ret; 1362 return ret;
1365 } 1363 }
1366 1364
1367 if (or->out.bio) {
1368 ret = blk_rq_append_bio(or->request->q, or->out.req,
1369 or->out.bio);
1370 if (ret) {
1371 OSD_DEBUG("blk_rq_append_bio out failed\n");
1372 return ret;
1373 }
1374 OSD_DEBUG("out bytes=%llu (bytes_req=%u)\n",
1375 _LLU(or->out.total_bytes), or->out.req->data_len);
1376 }
1377 if (or->in.bio) {
1378 ret = blk_rq_append_bio(or->request->q, or->in.req, or->in.bio);
1379 if (ret) {
1380 OSD_DEBUG("blk_rq_append_bio in failed\n");
1381 return ret;
1382 }
1383 OSD_DEBUG("in bytes=%llu (bytes_req=%u)\n",
1384 _LLU(or->in.total_bytes), or->in.req->data_len);
1385 }
1386
1387 or->out.pad_buff = sg_out_pad_buffer; 1365 or->out.pad_buff = sg_out_pad_buffer;
1388 or->in.pad_buff = sg_in_pad_buffer; 1366 or->in.pad_buff = sg_in_pad_buffer;
1389 1367
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index bb218c8b6e98..dd3f9d2b99fd 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -240,11 +240,11 @@ int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
240 * is invalid. Prevent the garbage from being misinterpreted 240 * is invalid. Prevent the garbage from being misinterpreted
241 * and prevent security leaks by zeroing out the excess data. 241 * and prevent security leaks by zeroing out the excess data.
242 */ 242 */
243 if (unlikely(req->data_len > 0 && req->data_len <= bufflen)) 243 if (unlikely(req->resid_len > 0 && req->resid_len <= bufflen))
244 memset(buffer + (bufflen - req->data_len), 0, req->data_len); 244 memset(buffer + (bufflen - req->resid_len), 0, req->resid_len);
245 245
246 if (resid) 246 if (resid)
247 *resid = req->data_len; 247 *resid = req->resid_len;
248 ret = req->errors; 248 ret = req->errors;
249 out: 249 out:
250 blk_put_request(req); 250 blk_put_request(req);
@@ -546,14 +546,9 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error,
546 * to queue the remainder of them. 546 * to queue the remainder of them.
547 */ 547 */
548 if (blk_end_request(req, error, bytes)) { 548 if (blk_end_request(req, error, bytes)) {
549 int leftover = (req->hard_nr_sectors << 9);
550
551 if (blk_pc_request(req))
552 leftover = req->data_len;
553
554 /* kill remainder if no retrys */ 549 /* kill remainder if no retrys */
555 if (error && scsi_noretry_cmd(cmd)) 550 if (error && scsi_noretry_cmd(cmd))
556 blk_end_request(req, error, leftover); 551 blk_end_request_all(req, error);
557 else { 552 else {
558 if (requeue) { 553 if (requeue) {
559 /* 554 /*
@@ -673,34 +668,6 @@ void scsi_release_buffers(struct scsi_cmnd *cmd)
673EXPORT_SYMBOL(scsi_release_buffers); 668EXPORT_SYMBOL(scsi_release_buffers);
674 669
675/* 670/*
676 * Bidi commands Must be complete as a whole, both sides at once.
677 * If part of the bytes were written and lld returned
678 * scsi_in()->resid and/or scsi_out()->resid this information will be left
679 * in req->data_len and req->next_rq->data_len. The upper-layer driver can
680 * decide what to do with this information.
681 */
682static void scsi_end_bidi_request(struct scsi_cmnd *cmd)
683{
684 struct request *req = cmd->request;
685 unsigned int dlen = req->data_len;
686 unsigned int next_dlen = req->next_rq->data_len;
687
688 req->data_len = scsi_out(cmd)->resid;
689 req->next_rq->data_len = scsi_in(cmd)->resid;
690
691 /* The req and req->next_rq have not been completed */
692 BUG_ON(blk_end_bidi_request(req, 0, dlen, next_dlen));
693
694 scsi_release_buffers(cmd);
695
696 /*
697 * This will goose the queue request function at the end, so we don't
698 * need to worry about launching another command.
699 */
700 scsi_next_command(cmd);
701}
702
703/*
704 * Function: scsi_io_completion() 671 * Function: scsi_io_completion()
705 * 672 *
706 * Purpose: Completion processing for block device I/O requests. 673 * Purpose: Completion processing for block device I/O requests.
@@ -739,7 +706,6 @@ static void scsi_end_bidi_request(struct scsi_cmnd *cmd)
739void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) 706void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
740{ 707{
741 int result = cmd->result; 708 int result = cmd->result;
742 int this_count;
743 struct request_queue *q = cmd->device->request_queue; 709 struct request_queue *q = cmd->device->request_queue;
744 struct request *req = cmd->request; 710 struct request *req = cmd->request;
745 int error = 0; 711 int error = 0;
@@ -773,12 +739,22 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
773 if (!sense_deferred) 739 if (!sense_deferred)
774 error = -EIO; 740 error = -EIO;
775 } 741 }
742
743 req->resid_len = scsi_get_resid(cmd);
744
776 if (scsi_bidi_cmnd(cmd)) { 745 if (scsi_bidi_cmnd(cmd)) {
777 /* will also release_buffers */ 746 /*
778 scsi_end_bidi_request(cmd); 747 * Bidi commands Must be complete as a whole,
748 * both sides at once.
749 */
750 req->next_rq->resid_len = scsi_in(cmd)->resid;
751
752 blk_end_request_all(req, 0);
753
754 scsi_release_buffers(cmd);
755 scsi_next_command(cmd);
779 return; 756 return;
780 } 757 }
781 req->data_len = scsi_get_resid(cmd);
782 } 758 }
783 759
784 BUG_ON(blk_bidi_rq(req)); /* bidi not support for !blk_pc_request yet */ 760 BUG_ON(blk_bidi_rq(req)); /* bidi not support for !blk_pc_request yet */
@@ -787,9 +763,9 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
787 * Next deal with any sectors which we were able to correctly 763 * Next deal with any sectors which we were able to correctly
788 * handle. 764 * handle.
789 */ 765 */
790 SCSI_LOG_HLCOMPLETE(1, printk("%ld sectors total, " 766 SCSI_LOG_HLCOMPLETE(1, printk("%u sectors total, "
791 "%d bytes done.\n", 767 "%d bytes done.\n",
792 req->nr_sectors, good_bytes)); 768 blk_rq_sectors(req), good_bytes));
793 769
794 /* 770 /*
795 * Recovered errors need reporting, but they're always treated 771 * Recovered errors need reporting, but they're always treated
@@ -812,7 +788,6 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
812 */ 788 */
813 if (scsi_end_request(cmd, error, good_bytes, result == 0) == NULL) 789 if (scsi_end_request(cmd, error, good_bytes, result == 0) == NULL)
814 return; 790 return;
815 this_count = blk_rq_bytes(req);
816 791
817 error = -EIO; 792 error = -EIO;
818 793
@@ -922,7 +897,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
922 if (driver_byte(result) & DRIVER_SENSE) 897 if (driver_byte(result) & DRIVER_SENSE)
923 scsi_print_sense("", cmd); 898 scsi_print_sense("", cmd);
924 } 899 }
925 blk_end_request(req, -EIO, blk_rq_bytes(req)); 900 blk_end_request_all(req, -EIO);
926 scsi_next_command(cmd); 901 scsi_next_command(cmd);
927 break; 902 break;
928 case ACTION_REPREP: 903 case ACTION_REPREP:
@@ -965,10 +940,7 @@ static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,
965 count = blk_rq_map_sg(req->q, req, sdb->table.sgl); 940 count = blk_rq_map_sg(req->q, req, sdb->table.sgl);
966 BUG_ON(count > sdb->table.nents); 941 BUG_ON(count > sdb->table.nents);
967 sdb->table.nents = count; 942 sdb->table.nents = count;
968 if (blk_pc_request(req)) 943 sdb->length = blk_rq_bytes(req);
969 sdb->length = req->data_len;
970 else
971 sdb->length = req->nr_sectors << 9;
972 return BLKPREP_OK; 944 return BLKPREP_OK;
973} 945}
974 946
@@ -1087,22 +1059,21 @@ int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req)
1087 if (unlikely(ret)) 1059 if (unlikely(ret))
1088 return ret; 1060 return ret;
1089 } else { 1061 } else {
1090 BUG_ON(req->data_len); 1062 BUG_ON(blk_rq_bytes(req));
1091 BUG_ON(req->data);
1092 1063
1093 memset(&cmd->sdb, 0, sizeof(cmd->sdb)); 1064 memset(&cmd->sdb, 0, sizeof(cmd->sdb));
1094 req->buffer = NULL; 1065 req->buffer = NULL;
1095 } 1066 }
1096 1067
1097 cmd->cmd_len = req->cmd_len; 1068 cmd->cmd_len = req->cmd_len;
1098 if (!req->data_len) 1069 if (!blk_rq_bytes(req))
1099 cmd->sc_data_direction = DMA_NONE; 1070 cmd->sc_data_direction = DMA_NONE;
1100 else if (rq_data_dir(req) == WRITE) 1071 else if (rq_data_dir(req) == WRITE)
1101 cmd->sc_data_direction = DMA_TO_DEVICE; 1072 cmd->sc_data_direction = DMA_TO_DEVICE;
1102 else 1073 else
1103 cmd->sc_data_direction = DMA_FROM_DEVICE; 1074 cmd->sc_data_direction = DMA_FROM_DEVICE;
1104 1075
1105 cmd->transfersize = req->data_len; 1076 cmd->transfersize = blk_rq_bytes(req);
1106 cmd->allowed = req->retries; 1077 cmd->allowed = req->retries;
1107 return BLKPREP_OK; 1078 return BLKPREP_OK;
1108} 1079}
@@ -1212,7 +1183,7 @@ int scsi_prep_return(struct request_queue *q, struct request *req, int ret)
1212 break; 1183 break;
1213 case BLKPREP_DEFER: 1184 case BLKPREP_DEFER:
1214 /* 1185 /*
1215 * If we defer, the elv_next_request() returns NULL, but the 1186 * If we defer, the blk_peek_request() returns NULL, but the
1216 * queue must be restarted, so we plug here if no returning 1187 * queue must be restarted, so we plug here if no returning
1217 * command will automatically do that. 1188 * command will automatically do that.
1218 */ 1189 */
@@ -1388,7 +1359,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
1388 struct scsi_target *starget = scsi_target(sdev); 1359 struct scsi_target *starget = scsi_target(sdev);
1389 struct Scsi_Host *shost = sdev->host; 1360 struct Scsi_Host *shost = sdev->host;
1390 1361
1391 blkdev_dequeue_request(req); 1362 blk_start_request(req);
1392 1363
1393 if (unlikely(cmd == NULL)) { 1364 if (unlikely(cmd == NULL)) {
1394 printk(KERN_CRIT "impossible request in %s.\n", 1365 printk(KERN_CRIT "impossible request in %s.\n",
@@ -1480,7 +1451,7 @@ static void scsi_request_fn(struct request_queue *q)
1480 1451
1481 if (!sdev) { 1452 if (!sdev) {
1482 printk("scsi: killing requests for dead queue\n"); 1453 printk("scsi: killing requests for dead queue\n");
1483 while ((req = elv_next_request(q)) != NULL) 1454 while ((req = blk_peek_request(q)) != NULL)
1484 scsi_kill_request(req, q); 1455 scsi_kill_request(req, q);
1485 return; 1456 return;
1486 } 1457 }
@@ -1501,7 +1472,7 @@ static void scsi_request_fn(struct request_queue *q)
1501 * that the request is fully prepared even if we cannot 1472 * that the request is fully prepared even if we cannot
1502 * accept it. 1473 * accept it.
1503 */ 1474 */
1504 req = elv_next_request(q); 1475 req = blk_peek_request(q);
1505 if (!req || !scsi_dev_queue_ready(q, sdev)) 1476 if (!req || !scsi_dev_queue_ready(q, sdev))
1506 break; 1477 break;
1507 1478
@@ -1517,7 +1488,7 @@ static void scsi_request_fn(struct request_queue *q)
1517 * Remove the request from the request list. 1488 * Remove the request from the request list.
1518 */ 1489 */
1519 if (!(blk_queue_tagged(q) && !blk_queue_start_tag(q, req))) 1490 if (!(blk_queue_tagged(q) && !blk_queue_start_tag(q, req)))
1520 blkdev_dequeue_request(req); 1491 blk_start_request(req);
1521 sdev->device_busy++; 1492 sdev->device_busy++;
1522 1493
1523 spin_unlock(q->queue_lock); 1494 spin_unlock(q->queue_lock);
diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
index 48ba413f7f6a..10303272ba45 100644
--- a/drivers/scsi/scsi_tgt_lib.c
+++ b/drivers/scsi/scsi_tgt_lib.c
@@ -387,7 +387,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
387 * we use REQ_TYPE_BLOCK_PC so scsi_init_io doesn't set the 387 * we use REQ_TYPE_BLOCK_PC so scsi_init_io doesn't set the
388 * length for us. 388 * length for us.
389 */ 389 */
390 cmd->sdb.length = rq->data_len; 390 cmd->sdb.length = blk_rq_bytes(rq);
391 391
392 return 0; 392 return 0;
393 393
diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index 50988cbf7b2d..d606452297cf 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -163,12 +163,10 @@ static void sas_smp_request(struct request_queue *q, struct Scsi_Host *shost,
163 int (*handler)(struct Scsi_Host *, struct sas_rphy *, struct request *); 163 int (*handler)(struct Scsi_Host *, struct sas_rphy *, struct request *);
164 164
165 while (!blk_queue_plugged(q)) { 165 while (!blk_queue_plugged(q)) {
166 req = elv_next_request(q); 166 req = blk_fetch_request(q);
167 if (!req) 167 if (!req)
168 break; 168 break;
169 169
170 blkdev_dequeue_request(req);
171
172 spin_unlock_irq(q->queue_lock); 170 spin_unlock_irq(q->queue_lock);
173 171
174 handler = to_sas_internal(shost->transportt)->f->smp_handler; 172 handler = to_sas_internal(shost->transportt)->f->smp_handler;
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 84044233b637..bcf3bd40bbd5 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -384,9 +384,9 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
384 struct scsi_device *sdp = q->queuedata; 384 struct scsi_device *sdp = q->queuedata;
385 struct gendisk *disk = rq->rq_disk; 385 struct gendisk *disk = rq->rq_disk;
386 struct scsi_disk *sdkp; 386 struct scsi_disk *sdkp;
387 sector_t block = rq->sector; 387 sector_t block = blk_rq_pos(rq);
388 sector_t threshold; 388 sector_t threshold;
389 unsigned int this_count = rq->nr_sectors; 389 unsigned int this_count = blk_rq_sectors(rq);
390 int ret, host_dif; 390 int ret, host_dif;
391 391
392 if (rq->cmd_type == REQ_TYPE_BLOCK_PC) { 392 if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
@@ -413,10 +413,10 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
413 this_count)); 413 this_count));
414 414
415 if (!sdp || !scsi_device_online(sdp) || 415 if (!sdp || !scsi_device_online(sdp) ||
416 block + rq->nr_sectors > get_capacity(disk)) { 416 block + blk_rq_sectors(rq) > get_capacity(disk)) {
417 SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, 417 SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
418 "Finishing %ld sectors\n", 418 "Finishing %u sectors\n",
419 rq->nr_sectors)); 419 blk_rq_sectors(rq)));
420 SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, 420 SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
421 "Retry with 0x%p\n", SCpnt)); 421 "Retry with 0x%p\n", SCpnt));
422 goto out; 422 goto out;
@@ -463,7 +463,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
463 * for this. 463 * for this.
464 */ 464 */
465 if (sdp->sector_size == 1024) { 465 if (sdp->sector_size == 1024) {
466 if ((block & 1) || (rq->nr_sectors & 1)) { 466 if ((block & 1) || (blk_rq_sectors(rq) & 1)) {
467 scmd_printk(KERN_ERR, SCpnt, 467 scmd_printk(KERN_ERR, SCpnt,
468 "Bad block number requested\n"); 468 "Bad block number requested\n");
469 goto out; 469 goto out;
@@ -473,7 +473,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
473 } 473 }
474 } 474 }
475 if (sdp->sector_size == 2048) { 475 if (sdp->sector_size == 2048) {
476 if ((block & 3) || (rq->nr_sectors & 3)) { 476 if ((block & 3) || (blk_rq_sectors(rq) & 3)) {
477 scmd_printk(KERN_ERR, SCpnt, 477 scmd_printk(KERN_ERR, SCpnt,
478 "Bad block number requested\n"); 478 "Bad block number requested\n");
479 goto out; 479 goto out;
@@ -483,7 +483,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
483 } 483 }
484 } 484 }
485 if (sdp->sector_size == 4096) { 485 if (sdp->sector_size == 4096) {
486 if ((block & 7) || (rq->nr_sectors & 7)) { 486 if ((block & 7) || (blk_rq_sectors(rq) & 7)) {
487 scmd_printk(KERN_ERR, SCpnt, 487 scmd_printk(KERN_ERR, SCpnt,
488 "Bad block number requested\n"); 488 "Bad block number requested\n");
489 goto out; 489 goto out;
@@ -512,10 +512,10 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
512 } 512 }
513 513
514 SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, 514 SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
515 "%s %d/%ld 512 byte blocks.\n", 515 "%s %d/%u 512 byte blocks.\n",
516 (rq_data_dir(rq) == WRITE) ? 516 (rq_data_dir(rq) == WRITE) ?
517 "writing" : "reading", this_count, 517 "writing" : "reading", this_count,
518 rq->nr_sectors)); 518 blk_rq_sectors(rq)));
519 519
520 /* Set RDPROTECT/WRPROTECT if disk is formatted with DIF */ 520 /* Set RDPROTECT/WRPROTECT if disk is formatted with DIF */
521 host_dif = scsi_host_dif_capable(sdp->host, sdkp->protection_type); 521 host_dif = scsi_host_dif_capable(sdp->host, sdkp->protection_type);
@@ -971,8 +971,8 @@ static struct block_device_operations sd_fops = {
971 971
972static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd) 972static unsigned int sd_completed_bytes(struct scsi_cmnd *scmd)
973{ 973{
974 u64 start_lba = scmd->request->sector; 974 u64 start_lba = blk_rq_pos(scmd->request);
975 u64 end_lba = scmd->request->sector + (scsi_bufflen(scmd) / 512); 975 u64 end_lba = blk_rq_pos(scmd->request) + (scsi_bufflen(scmd) / 512);
976 u64 bad_lba; 976 u64 bad_lba;
977 int info_valid; 977 int info_valid;
978 978
@@ -1510,7 +1510,7 @@ got_data:
1510 */ 1510 */
1511 sector_size = 512; 1511 sector_size = 512;
1512 } 1512 }
1513 blk_queue_hardsect_size(sdp->request_queue, sector_size); 1513 blk_queue_logical_block_size(sdp->request_queue, sector_size);
1514 1514
1515 { 1515 {
1516 char cap_str_2[10], cap_str_10[10]; 1516 char cap_str_2[10], cap_str_10[10];
diff --git a/drivers/scsi/sd_dif.c b/drivers/scsi/sd_dif.c
index 184dff492797..82f14a9482d0 100644
--- a/drivers/scsi/sd_dif.c
+++ b/drivers/scsi/sd_dif.c
@@ -507,7 +507,7 @@ void sd_dif_complete(struct scsi_cmnd *scmd, unsigned int good_bytes)
507 sector_sz = scmd->device->sector_size; 507 sector_sz = scmd->device->sector_size;
508 sectors = good_bytes / sector_sz; 508 sectors = good_bytes / sector_sz;
509 509
510 phys = scmd->request->sector & 0xffffffff; 510 phys = blk_rq_pos(scmd->request) & 0xffffffff;
511 if (sector_sz == 4096) 511 if (sector_sz == 4096)
512 phys >>= 3; 512 phys >>= 3;
513 513
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 91e316fe6522..8201387b4daa 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -289,8 +289,8 @@ sg_open(struct inode *inode, struct file *filp)
289 if (list_empty(&sdp->sfds)) { /* no existing opens on this device */ 289 if (list_empty(&sdp->sfds)) { /* no existing opens on this device */
290 sdp->sgdebug = 0; 290 sdp->sgdebug = 0;
291 q = sdp->device->request_queue; 291 q = sdp->device->request_queue;
292 sdp->sg_tablesize = min(q->max_hw_segments, 292 sdp->sg_tablesize = min(queue_max_hw_segments(q),
293 q->max_phys_segments); 293 queue_max_phys_segments(q));
294 } 294 }
295 if ((sfp = sg_add_sfp(sdp, dev))) 295 if ((sfp = sg_add_sfp(sdp, dev)))
296 filp->private_data = sfp; 296 filp->private_data = sfp;
@@ -909,7 +909,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
909 if (val < 0) 909 if (val < 0)
910 return -EINVAL; 910 return -EINVAL;
911 val = min_t(int, val, 911 val = min_t(int, val,
912 sdp->device->request_queue->max_sectors * 512); 912 queue_max_sectors(sdp->device->request_queue) * 512);
913 if (val != sfp->reserve.bufflen) { 913 if (val != sfp->reserve.bufflen) {
914 if (sg_res_in_use(sfp) || sfp->mmap_called) 914 if (sg_res_in_use(sfp) || sfp->mmap_called)
915 return -EBUSY; 915 return -EBUSY;
@@ -919,7 +919,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
919 return 0; 919 return 0;
920 case SG_GET_RESERVED_SIZE: 920 case SG_GET_RESERVED_SIZE:
921 val = min_t(int, sfp->reserve.bufflen, 921 val = min_t(int, sfp->reserve.bufflen,
922 sdp->device->request_queue->max_sectors * 512); 922 queue_max_sectors(sdp->device->request_queue) * 512);
923 return put_user(val, ip); 923 return put_user(val, ip);
924 case SG_SET_COMMAND_Q: 924 case SG_SET_COMMAND_Q:
925 result = get_user(val, ip); 925 result = get_user(val, ip);
@@ -1059,7 +1059,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
1059 return -ENODEV; 1059 return -ENODEV;
1060 return scsi_ioctl(sdp->device, cmd_in, p); 1060 return scsi_ioctl(sdp->device, cmd_in, p);
1061 case BLKSECTGET: 1061 case BLKSECTGET:
1062 return put_user(sdp->device->request_queue->max_sectors * 512, 1062 return put_user(queue_max_sectors(sdp->device->request_queue) * 512,
1063 ip); 1063 ip);
1064 case BLKTRACESETUP: 1064 case BLKTRACESETUP:
1065 return blk_trace_setup(sdp->device->request_queue, 1065 return blk_trace_setup(sdp->device->request_queue,
@@ -1261,7 +1261,7 @@ static void sg_rq_end_io(struct request *rq, int uptodate)
1261 1261
1262 sense = rq->sense; 1262 sense = rq->sense;
1263 result = rq->errors; 1263 result = rq->errors;
1264 resid = rq->data_len; 1264 resid = rq->resid_len;
1265 1265
1266 SCSI_LOG_TIMEOUT(4, printk("sg_cmd_done: %s, pack_id=%d, res=0x%x\n", 1266 SCSI_LOG_TIMEOUT(4, printk("sg_cmd_done: %s, pack_id=%d, res=0x%x\n",
1267 sdp->disk->disk_name, srp->header.pack_id, result)); 1267 sdp->disk->disk_name, srp->header.pack_id, result));
@@ -1378,7 +1378,8 @@ static Sg_device *sg_alloc(struct gendisk *disk, struct scsi_device *scsidp)
1378 sdp->device = scsidp; 1378 sdp->device = scsidp;
1379 INIT_LIST_HEAD(&sdp->sfds); 1379 INIT_LIST_HEAD(&sdp->sfds);
1380 init_waitqueue_head(&sdp->o_excl_wait); 1380 init_waitqueue_head(&sdp->o_excl_wait);
1381 sdp->sg_tablesize = min(q->max_hw_segments, q->max_phys_segments); 1381 sdp->sg_tablesize = min(queue_max_hw_segments(q),
1382 queue_max_phys_segments(q));
1382 sdp->index = k; 1383 sdp->index = k;
1383 kref_init(&sdp->d_ref); 1384 kref_init(&sdp->d_ref);
1384 1385
@@ -2056,7 +2057,7 @@ sg_add_sfp(Sg_device * sdp, int dev)
2056 sg_big_buff = def_reserved_size; 2057 sg_big_buff = def_reserved_size;
2057 2058
2058 bufflen = min_t(int, sg_big_buff, 2059 bufflen = min_t(int, sg_big_buff,
2059 sdp->device->request_queue->max_sectors * 512); 2060 queue_max_sectors(sdp->device->request_queue) * 512);
2060 sg_build_reserve(sfp, bufflen); 2061 sg_build_reserve(sfp, bufflen);
2061 SCSI_LOG_TIMEOUT(3, printk("sg_add_sfp: bufflen=%d, k_use_sg=%d\n", 2062 SCSI_LOG_TIMEOUT(3, printk("sg_add_sfp: bufflen=%d, k_use_sg=%d\n",
2062 sfp->reserve.bufflen, sfp->reserve.k_use_sg)); 2063 sfp->reserve.bufflen, sfp->reserve.k_use_sg));
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 0e1a0f2d2ad5..cd350dfc1216 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -292,7 +292,8 @@ static int sr_done(struct scsi_cmnd *SCpnt)
292 if (cd->device->sector_size == 2048) 292 if (cd->device->sector_size == 2048)
293 error_sector <<= 2; 293 error_sector <<= 2;
294 error_sector &= ~(block_sectors - 1); 294 error_sector &= ~(block_sectors - 1);
295 good_bytes = (error_sector - SCpnt->request->sector) << 9; 295 good_bytes = (error_sector -
296 blk_rq_pos(SCpnt->request)) << 9;
296 if (good_bytes < 0 || good_bytes >= this_count) 297 if (good_bytes < 0 || good_bytes >= this_count)
297 good_bytes = 0; 298 good_bytes = 0;
298 /* 299 /*
@@ -349,8 +350,8 @@ static int sr_prep_fn(struct request_queue *q, struct request *rq)
349 cd->disk->disk_name, block)); 350 cd->disk->disk_name, block));
350 351
351 if (!cd->device || !scsi_device_online(cd->device)) { 352 if (!cd->device || !scsi_device_online(cd->device)) {
352 SCSI_LOG_HLQUEUE(2, printk("Finishing %ld sectors\n", 353 SCSI_LOG_HLQUEUE(2, printk("Finishing %u sectors\n",
353 rq->nr_sectors)); 354 blk_rq_sectors(rq)));
354 SCSI_LOG_HLQUEUE(2, printk("Retry with 0x%p\n", SCpnt)); 355 SCSI_LOG_HLQUEUE(2, printk("Retry with 0x%p\n", SCpnt));
355 goto out; 356 goto out;
356 } 357 }
@@ -413,7 +414,7 @@ static int sr_prep_fn(struct request_queue *q, struct request *rq)
413 /* 414 /*
414 * request doesn't start on hw block boundary, add scatter pads 415 * request doesn't start on hw block boundary, add scatter pads
415 */ 416 */
416 if (((unsigned int)rq->sector % (s_size >> 9)) || 417 if (((unsigned int)blk_rq_pos(rq) % (s_size >> 9)) ||
417 (scsi_bufflen(SCpnt) % s_size)) { 418 (scsi_bufflen(SCpnt) % s_size)) {
418 scmd_printk(KERN_NOTICE, SCpnt, "unaligned transfer\n"); 419 scmd_printk(KERN_NOTICE, SCpnt, "unaligned transfer\n");
419 goto out; 420 goto out;
@@ -422,14 +423,14 @@ static int sr_prep_fn(struct request_queue *q, struct request *rq)
422 this_count = (scsi_bufflen(SCpnt) >> 9) / (s_size >> 9); 423 this_count = (scsi_bufflen(SCpnt) >> 9) / (s_size >> 9);
423 424
424 425
425 SCSI_LOG_HLQUEUE(2, printk("%s : %s %d/%ld 512 byte blocks.\n", 426 SCSI_LOG_HLQUEUE(2, printk("%s : %s %d/%u 512 byte blocks.\n",
426 cd->cdi.name, 427 cd->cdi.name,
427 (rq_data_dir(rq) == WRITE) ? 428 (rq_data_dir(rq) == WRITE) ?
428 "writing" : "reading", 429 "writing" : "reading",
429 this_count, rq->nr_sectors)); 430 this_count, blk_rq_sectors(rq)));
430 431
431 SCpnt->cmnd[1] = 0; 432 SCpnt->cmnd[1] = 0;
432 block = (unsigned int)rq->sector / (s_size >> 9); 433 block = (unsigned int)blk_rq_pos(rq) / (s_size >> 9);
433 434
434 if (this_count > 0xffff) { 435 if (this_count > 0xffff) {
435 this_count = 0xffff; 436 this_count = 0xffff;
@@ -726,7 +727,7 @@ static void get_sectorsize(struct scsi_cd *cd)
726 } 727 }
727 728
728 queue = cd->device->request_queue; 729 queue = cd->device->request_queue;
729 blk_queue_hardsect_size(queue, sector_size); 730 blk_queue_logical_block_size(queue, sector_size);
730 731
731 return; 732 return;
732} 733}
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index eb24efea8f14..89bd438e1fe3 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -463,7 +463,7 @@ static void st_scsi_execute_end(struct request *req, int uptodate)
463 struct scsi_tape *STp = SRpnt->stp; 463 struct scsi_tape *STp = SRpnt->stp;
464 464
465 STp->buffer->cmdstat.midlevel_result = SRpnt->result = req->errors; 465 STp->buffer->cmdstat.midlevel_result = SRpnt->result = req->errors;
466 STp->buffer->cmdstat.residual = req->data_len; 466 STp->buffer->cmdstat.residual = req->resid_len;
467 467
468 if (SRpnt->waiting) 468 if (SRpnt->waiting)
469 complete(SRpnt->waiting); 469 complete(SRpnt->waiting);
@@ -3983,8 +3983,8 @@ static int st_probe(struct device *dev)
3983 return -ENODEV; 3983 return -ENODEV;
3984 } 3984 }
3985 3985
3986 i = min(SDp->request_queue->max_hw_segments, 3986 i = min(queue_max_hw_segments(SDp->request_queue),
3987 SDp->request_queue->max_phys_segments); 3987 queue_max_phys_segments(SDp->request_queue));
3988 if (st_max_sg_segs < i) 3988 if (st_max_sg_segs < i)
3989 i = st_max_sg_segs; 3989 i = st_max_sg_segs;
3990 buffer = new_tape_buffer((SDp->host)->unchecked_isa_dma, i); 3990 buffer = new_tape_buffer((SDp->host)->unchecked_isa_dma, i);
diff --git a/drivers/scsi/u14-34f.c b/drivers/scsi/u14-34f.c
index 601e95141cbe..54023d41fd15 100644
--- a/drivers/scsi/u14-34f.c
+++ b/drivers/scsi/u14-34f.c
@@ -1306,7 +1306,7 @@ static int u14_34f_queuecommand(struct scsi_cmnd *SCpnt, void (*done)(struct scs
1306 if (linked_comm && SCpnt->device->queue_depth > 2 1306 if (linked_comm && SCpnt->device->queue_depth > 2
1307 && TLDEV(SCpnt->device->type)) { 1307 && TLDEV(SCpnt->device->type)) {
1308 HD(j)->cp_stat[i] = READY; 1308 HD(j)->cp_stat[i] = READY;
1309 flush_dev(SCpnt->device, SCpnt->request->sector, j, FALSE); 1309 flush_dev(SCpnt->device, blk_rq_pos(SCpnt->request), j, FALSE);
1310 return 0; 1310 return 0;
1311 } 1311 }
1312 1312
@@ -1610,11 +1610,13 @@ static int reorder(unsigned int j, unsigned long cursec,
1610 1610
1611 if (!(cpp->xdir == DTD_IN)) input_only = FALSE; 1611 if (!(cpp->xdir == DTD_IN)) input_only = FALSE;
1612 1612
1613 if (SCpnt->request->sector < minsec) minsec = SCpnt->request->sector; 1613 if (blk_rq_pos(SCpnt->request) < minsec)
1614 if (SCpnt->request->sector > maxsec) maxsec = SCpnt->request->sector; 1614 minsec = blk_rq_pos(SCpnt->request);
1615 if (blk_rq_pos(SCpnt->request) > maxsec)
1616 maxsec = blk_rq_pos(SCpnt->request);
1615 1617
1616 sl[n] = SCpnt->request->sector; 1618 sl[n] = blk_rq_pos(SCpnt->request);
1617 ioseek += SCpnt->request->nr_sectors; 1619 ioseek += blk_rq_sectors(SCpnt->request);
1618 1620
1619 if (!n) continue; 1621 if (!n) continue;
1620 1622
@@ -1642,7 +1644,7 @@ static int reorder(unsigned int j, unsigned long cursec,
1642 1644
1643 if (!input_only) for (n = 0; n < n_ready; n++) { 1645 if (!input_only) for (n = 0; n < n_ready; n++) {
1644 k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt; 1646 k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
1645 ll[n] = SCpnt->request->nr_sectors; pl[n] = SCpnt->serial_number; 1647 ll[n] = blk_rq_sectors(SCpnt->request); pl[n] = SCpnt->serial_number;
1646 1648
1647 if (!n) continue; 1649 if (!n) continue;
1648 1650
@@ -1666,12 +1668,12 @@ static int reorder(unsigned int j, unsigned long cursec,
1666 if (link_statistics && (overlap || !(flushcount % link_statistics))) 1668 if (link_statistics && (overlap || !(flushcount % link_statistics)))
1667 for (n = 0; n < n_ready; n++) { 1669 for (n = 0; n < n_ready; n++) {
1668 k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt; 1670 k = il[n]; cpp = &HD(j)->cp[k]; SCpnt = cpp->SCpnt;
1669 printk("%s %d.%d:%d pid %ld mb %d fc %d nr %d sec %ld ns %ld"\ 1671 printk("%s %d.%d:%d pid %ld mb %d fc %d nr %d sec %ld ns %u"\
1670 " cur %ld s:%c r:%c rev:%c in:%c ov:%c xd %d.\n", 1672 " cur %ld s:%c r:%c rev:%c in:%c ov:%c xd %d.\n",
1671 (ihdlr ? "ihdlr" : "qcomm"), SCpnt->channel, SCpnt->target, 1673 (ihdlr ? "ihdlr" : "qcomm"), SCpnt->channel, SCpnt->target,
1672 SCpnt->lun, SCpnt->serial_number, k, flushcount, n_ready, 1674 SCpnt->lun, SCpnt->serial_number, k, flushcount, n_ready,
1673 SCpnt->request->sector, SCpnt->request->nr_sectors, cursec, 1675 blk_rq_pos(SCpnt->request), blk_rq_sectors(SCpnt->request),
1674 YESNO(s), YESNO(r), YESNO(rev), YESNO(input_only), 1676 cursec, YESNO(s), YESNO(r), YESNO(rev), YESNO(input_only),
1675 YESNO(overlap), cpp->xdir); 1677 YESNO(overlap), cpp->xdir);
1676 } 1678 }
1677#endif 1679#endif
@@ -1799,7 +1801,7 @@ static irqreturn_t ihdlr(unsigned int j)
1799 1801
1800 if (linked_comm && SCpnt->device->queue_depth > 2 1802 if (linked_comm && SCpnt->device->queue_depth > 2
1801 && TLDEV(SCpnt->device->type)) 1803 && TLDEV(SCpnt->device->type))
1802 flush_dev(SCpnt->device, SCpnt->request->sector, j, TRUE); 1804 flush_dev(SCpnt->device, blk_rq_pos(SCpnt->request), j, TRUE);
1803 1805
1804 tstatus = status_byte(spp->target_status); 1806 tstatus = status_byte(spp->target_status);
1805 1807
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index a0127e93ade0..fb867a9f55e9 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -287,6 +287,13 @@ static const struct serial8250_config uart_config[] = {
287 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10, 287 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
288 .flags = UART_CAP_FIFO, 288 .flags = UART_CAP_FIFO,
289 }, 289 },
290 [PORT_AR7] = {
291 .name = "AR7",
292 .fifo_size = 16,
293 .tx_loadsz = 16,
294 .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_00,
295 .flags = UART_CAP_FIFO | UART_CAP_AFE,
296 },
290}; 297};
291 298
292#if defined (CONFIG_SERIAL_8250_AU1X00) 299#if defined (CONFIG_SERIAL_8250_AU1X00)
diff --git a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
index 938bc1b6c3fa..e371a9c15341 100644
--- a/drivers/serial/8250_pci.c
+++ b/drivers/serial/8250_pci.c
@@ -2776,6 +2776,9 @@ static struct pci_device_id serial_pci_tbl[] = {
2776 { PCI_VENDOR_ID_OXSEMI, 0x950a, 2776 { PCI_VENDOR_ID_OXSEMI, 0x950a,
2777 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2777 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
2778 pbn_b0_2_1130000 }, 2778 pbn_b0_2_1130000 },
2779 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_C950,
2780 PCI_VENDOR_ID_OXSEMI, PCI_SUBDEVICE_ID_OXSEMI_C950, 0, 0,
2781 pbn_b0_1_921600 },
2779 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954, 2782 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954,
2780 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2783 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
2781 pbn_b0_4_115200 }, 2784 pbn_b0_4_115200 },
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 343e3a35b6a3..641e800ed693 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -833,6 +833,7 @@ config SERIAL_IMX
833 bool "IMX serial port support" 833 bool "IMX serial port support"
834 depends on ARM && (ARCH_IMX || ARCH_MXC) 834 depends on ARM && (ARCH_IMX || ARCH_MXC)
835 select SERIAL_CORE 835 select SERIAL_CORE
836 select RATIONAL
836 help 837 help
837 If you have a machine based on a Motorola IMX CPU you 838 If you have a machine based on a Motorola IMX CPU you
838 can enable its onboard serial port by enabling this option. 839 can enable its onboard serial port by enabling this option.
@@ -1433,4 +1434,11 @@ config SPORT_BAUD_RATE
1433 default 19200 if (SERIAL_SPORT_BAUD_RATE_19200) 1434 default 19200 if (SERIAL_SPORT_BAUD_RATE_19200)
1434 default 9600 if (SERIAL_SPORT_BAUD_RATE_9600) 1435 default 9600 if (SERIAL_SPORT_BAUD_RATE_9600)
1435 1436
1437config SERIAL_TIMBERDALE
1438 tristate "Support for timberdale UART"
1439 depends on MFD_TIMBERDALE
1440 select SERIAL_CORE
1441 ---help---
1442 Add support for UART controller on timberdale.
1443
1436endmenu 1444endmenu
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index d438eb2a73de..45a8658f54d5 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -77,3 +77,4 @@ obj-$(CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL) += nwpserial.o
77obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o 77obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o
78obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o 78obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o
79obj-$(CONFIG_SERIAL_QE) += ucc_uart.o 79obj-$(CONFIG_SERIAL_QE) += ucc_uart.o
80obj-$(CONFIG_SERIAL_TIMBERDALE) += timbuart.o
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index d86123e03391..e2f6b1bfac98 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -330,6 +330,11 @@ static void bfin_serial_tx_chars(struct bfin_serial_port *uart)
330 /* Clear TFI bit */ 330 /* Clear TFI bit */
331 UART_PUT_LSR(uart, TFI); 331 UART_PUT_LSR(uart, TFI);
332#endif 332#endif
333 /* Anomaly notes:
334 * 05000215 - we always clear ETBEI within last UART TX
335 * interrupt to end a string. It is always set
336 * when start a new tx.
337 */
333 UART_CLEAR_IER(uart, ETBEI); 338 UART_CLEAR_IER(uart, ETBEI);
334 return; 339 return;
335 } 340 }
@@ -415,6 +420,7 @@ static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart)
415 set_dma_start_addr(uart->tx_dma_channel, (unsigned long)(xmit->buf+xmit->tail)); 420 set_dma_start_addr(uart->tx_dma_channel, (unsigned long)(xmit->buf+xmit->tail));
416 set_dma_x_count(uart->tx_dma_channel, uart->tx_count); 421 set_dma_x_count(uart->tx_dma_channel, uart->tx_count);
417 set_dma_x_modify(uart->tx_dma_channel, 1); 422 set_dma_x_modify(uart->tx_dma_channel, 1);
423 SSYNC();
418 enable_dma(uart->tx_dma_channel); 424 enable_dma(uart->tx_dma_channel);
419 425
420 UART_SET_IER(uart, ETBEI); 426 UART_SET_IER(uart, ETBEI);
@@ -473,27 +479,41 @@ static void bfin_serial_dma_rx_chars(struct bfin_serial_port *uart)
473void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart) 479void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart)
474{ 480{
475 int x_pos, pos; 481 int x_pos, pos;
476 unsigned long flags;
477
478 spin_lock_irqsave(&uart->port.lock, flags);
479 482
483 dma_disable_irq(uart->rx_dma_channel);
484 spin_lock_bh(&uart->port.lock);
485
486 /* 2D DMA RX buffer ring is used. Because curr_y_count and
487 * curr_x_count can't be read as an atomic operation,
488 * curr_y_count should be read before curr_x_count. When
489 * curr_x_count is read, curr_y_count may already indicate
490 * next buffer line. But, the position calculated here is
491 * still indicate the old line. The wrong position data may
492 * be smaller than current buffer tail, which cause garbages
493 * are received if it is not prohibit.
494 */
480 uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel); 495 uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel);
481 x_pos = get_dma_curr_xcount(uart->rx_dma_channel); 496 x_pos = get_dma_curr_xcount(uart->rx_dma_channel);
482 uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows; 497 uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows;
483 if (uart->rx_dma_nrows == DMA_RX_YCOUNT) 498 if (uart->rx_dma_nrows == DMA_RX_YCOUNT || x_pos == 0)
484 uart->rx_dma_nrows = 0; 499 uart->rx_dma_nrows = 0;
485 x_pos = DMA_RX_XCOUNT - x_pos; 500 x_pos = DMA_RX_XCOUNT - x_pos;
486 if (x_pos == DMA_RX_XCOUNT) 501 if (x_pos == DMA_RX_XCOUNT)
487 x_pos = 0; 502 x_pos = 0;
488 503
489 pos = uart->rx_dma_nrows * DMA_RX_XCOUNT + x_pos; 504 pos = uart->rx_dma_nrows * DMA_RX_XCOUNT + x_pos;
490 if (pos != uart->rx_dma_buf.tail) { 505 /* Ignore receiving data if new position is in the same line of
506 * current buffer tail and small.
507 */
508 if (pos > uart->rx_dma_buf.tail ||
509 uart->rx_dma_nrows < (uart->rx_dma_buf.tail/DMA_RX_XCOUNT)) {
491 uart->rx_dma_buf.head = pos; 510 uart->rx_dma_buf.head = pos;
492 bfin_serial_dma_rx_chars(uart); 511 bfin_serial_dma_rx_chars(uart);
493 uart->rx_dma_buf.tail = uart->rx_dma_buf.head; 512 uart->rx_dma_buf.tail = uart->rx_dma_buf.head;
494 } 513 }
495 514
496 spin_unlock_irqrestore(&uart->port.lock, flags); 515 spin_unlock_bh(&uart->port.lock);
516 dma_enable_irq(uart->rx_dma_channel);
497 517
498 mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES); 518 mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES);
499} 519}
@@ -514,6 +534,11 @@ static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id)
514 if (!(get_dma_curr_irqstat(uart->tx_dma_channel)&DMA_RUN)) { 534 if (!(get_dma_curr_irqstat(uart->tx_dma_channel)&DMA_RUN)) {
515 disable_dma(uart->tx_dma_channel); 535 disable_dma(uart->tx_dma_channel);
516 clear_dma_irqstat(uart->tx_dma_channel); 536 clear_dma_irqstat(uart->tx_dma_channel);
537 /* Anomaly notes:
538 * 05000215 - we always clear ETBEI within last UART TX
539 * interrupt to end a string. It is always set
540 * when start a new tx.
541 */
517 UART_CLEAR_IER(uart, ETBEI); 542 UART_CLEAR_IER(uart, ETBEI);
518 xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1); 543 xmit->tail = (xmit->tail + uart->tx_count) & (UART_XMIT_SIZE - 1);
519 uart->port.icount.tx += uart->tx_count; 544 uart->port.icount.tx += uart->tx_count;
@@ -532,11 +557,26 @@ static irqreturn_t bfin_serial_dma_rx_int(int irq, void *dev_id)
532{ 557{
533 struct bfin_serial_port *uart = dev_id; 558 struct bfin_serial_port *uart = dev_id;
534 unsigned short irqstat; 559 unsigned short irqstat;
560 int x_pos, pos;
535 561
536 spin_lock(&uart->port.lock); 562 spin_lock(&uart->port.lock);
537 irqstat = get_dma_curr_irqstat(uart->rx_dma_channel); 563 irqstat = get_dma_curr_irqstat(uart->rx_dma_channel);
538 clear_dma_irqstat(uart->rx_dma_channel); 564 clear_dma_irqstat(uart->rx_dma_channel);
539 bfin_serial_dma_rx_chars(uart); 565
566 uart->rx_dma_nrows = get_dma_curr_ycount(uart->rx_dma_channel);
567 x_pos = get_dma_curr_xcount(uart->rx_dma_channel);
568 uart->rx_dma_nrows = DMA_RX_YCOUNT - uart->rx_dma_nrows;
569 if (uart->rx_dma_nrows == DMA_RX_YCOUNT || x_pos == 0)
570 uart->rx_dma_nrows = 0;
571
572 pos = uart->rx_dma_nrows * DMA_RX_XCOUNT;
573 if (pos > uart->rx_dma_buf.tail ||
574 uart->rx_dma_nrows < (uart->rx_dma_buf.tail/DMA_RX_XCOUNT)) {
575 uart->rx_dma_buf.head = pos;
576 bfin_serial_dma_rx_chars(uart);
577 uart->rx_dma_buf.tail = uart->rx_dma_buf.head;
578 }
579
540 spin_unlock(&uart->port.lock); 580 spin_unlock(&uart->port.lock);
541 581
542 return IRQ_HANDLED; 582 return IRQ_HANDLED;
@@ -789,8 +829,16 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
789 __func__); 829 __func__);
790 } 830 }
791 831
792 if (termios->c_cflag & CSTOPB) 832 /* Anomaly notes:
793 lcr |= STB; 833 * 05000231 - STOP bit is always set to 1 whatever the user is set.
834 */
835 if (termios->c_cflag & CSTOPB) {
836 if (ANOMALY_05000231)
837 printk(KERN_WARNING "STOP bits other than 1 is not "
838 "supported in case of anomaly 05000231.\n");
839 else
840 lcr |= STB;
841 }
794 if (termios->c_cflag & PARENB) 842 if (termios->c_cflag & PARENB)
795 lcr |= PEN; 843 lcr |= PEN;
796 if (!(termios->c_cflag & PARODD)) 844 if (!(termios->c_cflag & PARODD))
@@ -940,6 +988,10 @@ static void bfin_serial_reset_irda(struct uart_port *port)
940} 988}
941 989
942#ifdef CONFIG_CONSOLE_POLL 990#ifdef CONFIG_CONSOLE_POLL
991/* Anomaly notes:
992 * 05000099 - Because we only use THRE in poll_put and DR in poll_get,
993 * losing other bits of UART_LSR is not a problem here.
994 */
943static void bfin_serial_poll_put_char(struct uart_port *port, unsigned char chr) 995static void bfin_serial_poll_put_char(struct uart_port *port, unsigned char chr)
944{ 996{
945 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 997 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
@@ -1245,12 +1297,17 @@ static __init void early_serial_write(struct console *con, const char *s,
1245 } 1297 }
1246} 1298}
1247 1299
1300/*
1301 * This should have a .setup or .early_setup in it, but then things get called
1302 * without the command line options, and the baud rate gets messed up - so
1303 * don't let the common infrastructure play with things. (see calls to setup
1304 * & earlysetup in ./kernel/printk.c:register_console()
1305 */
1248static struct __initdata console bfin_early_serial_console = { 1306static struct __initdata console bfin_early_serial_console = {
1249 .name = "early_BFuart", 1307 .name = "early_BFuart",
1250 .write = early_serial_write, 1308 .write = early_serial_write,
1251 .device = uart_console_device, 1309 .device = uart_console_device,
1252 .flags = CON_PRINTBUFFER, 1310 .flags = CON_PRINTBUFFER,
1253 .setup = bfin_serial_console_setup,
1254 .index = -1, 1311 .index = -1,
1255 .data = &bfin_serial_reg, 1312 .data = &bfin_serial_reg,
1256}; 1313};
diff --git a/drivers/serial/bfin_sport_uart.c b/drivers/serial/bfin_sport_uart.c
index 529c0ff7952c..34b4ae0fe760 100644
--- a/drivers/serial/bfin_sport_uart.c
+++ b/drivers/serial/bfin_sport_uart.c
@@ -101,15 +101,16 @@ static inline void tx_one_byte(struct sport_uart_port *up, unsigned int value)
101{ 101{
102 pr_debug("%s value:%x\n", __func__, value); 102 pr_debug("%s value:%x\n", __func__, value);
103 /* Place a Start and Stop bit */ 103 /* Place a Start and Stop bit */
104 __asm__ volatile ( 104 __asm__ __volatile__ (
105 "R2 = b#01111111100;\n\t" 105 "R2 = b#01111111100;"
106 "R3 = b#10000000001;\n\t" 106 "R3 = b#10000000001;"
107 "%0 <<= 2;\n\t" 107 "%0 <<= 2;"
108 "%0 = %0 & R2;\n\t" 108 "%0 = %0 & R2;"
109 "%0 = %0 | R3;\n\t" 109 "%0 = %0 | R3;"
110 :"=r"(value) 110 : "=d"(value)
111 :"0"(value) 111 : "d"(value)
112 :"R2", "R3"); 112 : "ASTAT", "R2", "R3"
113 );
113 pr_debug("%s value:%x\n", __func__, value); 114 pr_debug("%s value:%x\n", __func__, value);
114 115
115 SPORT_PUT_TX(up, value); 116 SPORT_PUT_TX(up, value);
@@ -118,27 +119,30 @@ static inline void tx_one_byte(struct sport_uart_port *up, unsigned int value)
118static inline unsigned int rx_one_byte(struct sport_uart_port *up) 119static inline unsigned int rx_one_byte(struct sport_uart_port *up)
119{ 120{
120 unsigned int value, extract; 121 unsigned int value, extract;
122 u32 tmp_mask1, tmp_mask2, tmp_shift, tmp;
121 123
122 value = SPORT_GET_RX32(up); 124 value = SPORT_GET_RX32(up);
123 pr_debug("%s value:%x\n", __func__, value); 125 pr_debug("%s value:%x\n", __func__, value);
124 126
125 /* Extract 8 bits data */ 127 /* Extract 8 bits data */
126 __asm__ volatile ( 128 __asm__ __volatile__ (
127 "R5 = 0;\n\t" 129 "%[extr] = 0;"
128 "P0 = 8;\n\t" 130 "%[mask1] = 0x1801(Z);"
129 "R1 = 0x1801(Z);\n\t" 131 "%[mask2] = 0x0300(Z);"
130 "R3 = 0x0300(Z);\n\t" 132 "%[shift] = 0;"
131 "R4 = 0;\n\t" 133 "LSETUP(.Lloop_s, .Lloop_e) LC0 = %[lc];"
132 "LSETUP(loop_s, loop_e) LC0 = P0;\nloop_s:\t" 134 ".Lloop_s:"
133 "R2 = extract(%1, R1.L)(Z);\n\t" 135 "%[tmp] = extract(%[val], %[mask1].L)(Z);"
134 "R2 <<= R4;\n\t" 136 "%[tmp] <<= %[shift];"
135 "R5 = R5 | R2;\n\t" 137 "%[extr] = %[extr] | %[tmp];"
136 "R1 = R1 - R3;\nloop_e:\t" 138 "%[mask1] = %[mask1] - %[mask2];"
137 "R4 += 1;\n\t" 139 ".Lloop_e:"
138 "%0 = R5;\n\t" 140 "%[shift] += 1;"
139 :"=r"(extract) 141 : [val]"=d"(value), [extr]"=d"(extract), [shift]"=d"(tmp_shift), [tmp]"=d"(tmp),
140 :"r"(value) 142 [mask1]"=d"(tmp_mask1), [mask2]"=d"(tmp_mask2)
141 :"P0", "R1", "R2","R3","R4", "R5"); 143 : "d"(value), [lc]"a"(8)
144 : "ASTAT", "LB0", "LC0", "LT0"
145 );
142 146
143 pr_debug(" extract:%x\n", extract); 147 pr_debug(" extract:%x\n", extract);
144 return extract; 148 return extract;
@@ -149,7 +153,7 @@ static int sport_uart_setup(struct sport_uart_port *up, int sclk, int baud_rate)
149 int tclkdiv, tfsdiv, rclkdiv; 153 int tclkdiv, tfsdiv, rclkdiv;
150 154
151 /* Set TCR1 and TCR2 */ 155 /* Set TCR1 and TCR2 */
152 SPORT_PUT_TCR1(up, (LTFS | ITFS | TFSR | TLSBIT | ITCLK)); 156 SPORT_PUT_TCR1(up, (LATFS | ITFS | TFSR | TLSBIT | ITCLK));
153 SPORT_PUT_TCR2(up, 10); 157 SPORT_PUT_TCR2(up, 10);
154 pr_debug("%s TCR1:%x, TCR2:%x\n", __func__, SPORT_GET_TCR1(up), SPORT_GET_TCR2(up)); 158 pr_debug("%s TCR1:%x, TCR2:%x\n", __func__, SPORT_GET_TCR1(up), SPORT_GET_TCR2(up));
155 159
@@ -419,7 +423,7 @@ static void sport_shutdown(struct uart_port *port)
419} 423}
420 424
421static void sport_set_termios(struct uart_port *port, 425static void sport_set_termios(struct uart_port *port,
422 struct termios *termios, struct termios *old) 426 struct ktermios *termios, struct ktermios *old)
423{ 427{
424 pr_debug("%s enter, c_cflag:%08x\n", __func__, termios->c_cflag); 428 pr_debug("%s enter, c_cflag:%08x\n", __func__, termios->c_cflag);
425 uart_update_timeout(port, CS8 ,port->uartclk); 429 uart_update_timeout(port, CS8 ,port->uartclk);
diff --git a/drivers/serial/icom.c b/drivers/serial/icom.c
index a461b3b2c72d..9f2891c2c4a2 100644
--- a/drivers/serial/icom.c
+++ b/drivers/serial/icom.c
@@ -137,7 +137,12 @@ static LIST_HEAD(icom_adapter_head);
137static spinlock_t icom_lock; 137static spinlock_t icom_lock;
138 138
139#ifdef ICOM_TRACE 139#ifdef ICOM_TRACE
140static inline void trace(struct icom_port *, char *, unsigned long) {}; 140static inline void trace(struct icom_port *icom_port, char *trace_pt,
141 unsigned long trace_data)
142{
143 dev_info(&icom_port->adapter->pci_dev->dev, ":%d:%s - %lx\n",
144 icom_port->port, trace_pt, trace_data);
145}
141#else 146#else
142static inline void trace(struct icom_port *icom_port, char *trace_pt, unsigned long trace_data) {}; 147static inline void trace(struct icom_port *icom_port, char *trace_pt, unsigned long trace_data) {};
143#endif 148#endif
@@ -408,7 +413,7 @@ static void load_code(struct icom_port *icom_port)
408 release_firmware(fw); 413 release_firmware(fw);
409 414
410 /* Set Hardware level */ 415 /* Set Hardware level */
411 if ((icom_port->adapter->version | ADAPTER_V2) == ADAPTER_V2) 416 if (icom_port->adapter->version == ADAPTER_V2)
412 writeb(V2_HARDWARE, &(icom_port->dram->misc_flags)); 417 writeb(V2_HARDWARE, &(icom_port->dram->misc_flags));
413 418
414 /* Start the processor in Adapter */ 419 /* Start the processor in Adapter */
@@ -861,7 +866,7 @@ static irqreturn_t icom_interrupt(int irq, void *dev_id)
861 /* find icom_port for this interrupt */ 866 /* find icom_port for this interrupt */
862 icom_adapter = (struct icom_adapter *) dev_id; 867 icom_adapter = (struct icom_adapter *) dev_id;
863 868
864 if ((icom_adapter->version | ADAPTER_V2) == ADAPTER_V2) { 869 if (icom_adapter->version == ADAPTER_V2) {
865 int_reg = icom_adapter->base_addr + 0x8024; 870 int_reg = icom_adapter->base_addr + 0x8024;
866 871
867 adapter_interrupts = readl(int_reg); 872 adapter_interrupts = readl(int_reg);
@@ -1647,15 +1652,6 @@ static void __exit icom_exit(void)
1647module_init(icom_init); 1652module_init(icom_init);
1648module_exit(icom_exit); 1653module_exit(icom_exit);
1649 1654
1650#ifdef ICOM_TRACE
1651static inline void trace(struct icom_port *icom_port, char *trace_pt,
1652 unsigned long trace_data)
1653{
1654 dev_info(&icom_port->adapter->pci_dev->dev, ":%d:%s - %lx\n",
1655 icom_port->port, trace_pt, trace_data);
1656}
1657#endif
1658
1659MODULE_AUTHOR("Michael Anderson <mjanders@us.ibm.com>"); 1655MODULE_AUTHOR("Michael Anderson <mjanders@us.ibm.com>");
1660MODULE_DESCRIPTION("IBM iSeries Serial IOA driver"); 1656MODULE_DESCRIPTION("IBM iSeries Serial IOA driver");
1661MODULE_SUPPORTED_DEVICE 1657MODULE_SUPPORTED_DEVICE
diff --git a/drivers/serial/imx.c b/drivers/serial/imx.c
index 5f0be40dfdab..7b5d1de9cfe3 100644
--- a/drivers/serial/imx.c
+++ b/drivers/serial/imx.c
@@ -8,6 +8,9 @@
8 * Author: Sascha Hauer <sascha@saschahauer.de> 8 * Author: Sascha Hauer <sascha@saschahauer.de>
9 * Copyright (C) 2004 Pengutronix 9 * Copyright (C) 2004 Pengutronix
10 * 10 *
11 * Copyright (C) 2009 emlix GmbH
12 * Author: Fabian Godehardt (added IrDA support for iMX)
13 *
11 * This program is free software; you can redistribute it and/or modify 14 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 15 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or 16 * the Free Software Foundation; either version 2 of the License, or
@@ -41,6 +44,8 @@
41#include <linux/serial_core.h> 44#include <linux/serial_core.h>
42#include <linux/serial.h> 45#include <linux/serial.h>
43#include <linux/clk.h> 46#include <linux/clk.h>
47#include <linux/delay.h>
48#include <linux/rational.h>
44 49
45#include <asm/io.h> 50#include <asm/io.h>
46#include <asm/irq.h> 51#include <asm/irq.h>
@@ -148,6 +153,7 @@
148#define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */ 153#define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */
149#define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */ 154#define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */
150#define UFCR_RFDIV (7<<7) /* Reference freq divider mask */ 155#define UFCR_RFDIV (7<<7) /* Reference freq divider mask */
156#define UFCR_RFDIV_REG(x) (((x) < 7 ? 6 - (x) : 6) << 7)
151#define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */ 157#define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */
152#define USR1_PARITYERR (1<<15) /* Parity error interrupt flag */ 158#define USR1_PARITYERR (1<<15) /* Parity error interrupt flag */
153#define USR1_RTSS (1<<14) /* RTS pin status */ 159#define USR1_RTSS (1<<14) /* RTS pin status */
@@ -211,10 +217,20 @@ struct imx_port {
211 struct timer_list timer; 217 struct timer_list timer;
212 unsigned int old_status; 218 unsigned int old_status;
213 int txirq,rxirq,rtsirq; 219 int txirq,rxirq,rtsirq;
214 int have_rtscts:1; 220 unsigned int have_rtscts:1;
221 unsigned int use_irda:1;
222 unsigned int irda_inv_rx:1;
223 unsigned int irda_inv_tx:1;
224 unsigned short trcv_delay; /* transceiver delay */
215 struct clk *clk; 225 struct clk *clk;
216}; 226};
217 227
228#ifdef CONFIG_IRDA
229#define USE_IRDA(sport) ((sport)->use_irda)
230#else
231#define USE_IRDA(sport) (0)
232#endif
233
218/* 234/*
219 * Handle any change of modem status signal since we were last called. 235 * Handle any change of modem status signal since we were last called.
220 */ 236 */
@@ -268,6 +284,48 @@ static void imx_stop_tx(struct uart_port *port)
268 struct imx_port *sport = (struct imx_port *)port; 284 struct imx_port *sport = (struct imx_port *)port;
269 unsigned long temp; 285 unsigned long temp;
270 286
287 if (USE_IRDA(sport)) {
288 /* half duplex - wait for end of transmission */
289 int n = 256;
290 while ((--n > 0) &&
291 !(readl(sport->port.membase + USR2) & USR2_TXDC)) {
292 udelay(5);
293 barrier();
294 }
295 /*
296 * irda transceiver - wait a bit more to avoid
297 * cutoff, hardware dependent
298 */
299 udelay(sport->trcv_delay);
300
301 /*
302 * half duplex - reactivate receive mode,
303 * flush receive pipe echo crap
304 */
305 if (readl(sport->port.membase + USR2) & USR2_TXDC) {
306 temp = readl(sport->port.membase + UCR1);
307 temp &= ~(UCR1_TXMPTYEN | UCR1_TRDYEN);
308 writel(temp, sport->port.membase + UCR1);
309
310 temp = readl(sport->port.membase + UCR4);
311 temp &= ~(UCR4_TCEN);
312 writel(temp, sport->port.membase + UCR4);
313
314 while (readl(sport->port.membase + URXD0) &
315 URXD_CHARRDY)
316 barrier();
317
318 temp = readl(sport->port.membase + UCR1);
319 temp |= UCR1_RRDYEN;
320 writel(temp, sport->port.membase + UCR1);
321
322 temp = readl(sport->port.membase + UCR4);
323 temp |= UCR4_DREN;
324 writel(temp, sport->port.membase + UCR4);
325 }
326 return;
327 }
328
271 temp = readl(sport->port.membase + UCR1); 329 temp = readl(sport->port.membase + UCR1);
272 writel(temp & ~UCR1_TXMPTYEN, sport->port.membase + UCR1); 330 writel(temp & ~UCR1_TXMPTYEN, sport->port.membase + UCR1);
273} 331}
@@ -302,13 +360,15 @@ static inline void imx_transmit_buffer(struct imx_port *sport)
302 /* send xmit->buf[xmit->tail] 360 /* send xmit->buf[xmit->tail]
303 * out the port here */ 361 * out the port here */
304 writel(xmit->buf[xmit->tail], sport->port.membase + URTX0); 362 writel(xmit->buf[xmit->tail], sport->port.membase + URTX0);
305 xmit->tail = (xmit->tail + 1) & 363 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
306 (UART_XMIT_SIZE - 1);
307 sport->port.icount.tx++; 364 sport->port.icount.tx++;
308 if (uart_circ_empty(xmit)) 365 if (uart_circ_empty(xmit))
309 break; 366 break;
310 } 367 }
311 368
369 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
370 uart_write_wakeup(&sport->port);
371
312 if (uart_circ_empty(xmit)) 372 if (uart_circ_empty(xmit))
313 imx_stop_tx(&sport->port); 373 imx_stop_tx(&sport->port);
314} 374}
@@ -321,9 +381,30 @@ static void imx_start_tx(struct uart_port *port)
321 struct imx_port *sport = (struct imx_port *)port; 381 struct imx_port *sport = (struct imx_port *)port;
322 unsigned long temp; 382 unsigned long temp;
323 383
384 if (USE_IRDA(sport)) {
385 /* half duplex in IrDA mode; have to disable receive mode */
386 temp = readl(sport->port.membase + UCR4);
387 temp &= ~(UCR4_DREN);
388 writel(temp, sport->port.membase + UCR4);
389
390 temp = readl(sport->port.membase + UCR1);
391 temp &= ~(UCR1_RRDYEN);
392 writel(temp, sport->port.membase + UCR1);
393 }
394
324 temp = readl(sport->port.membase + UCR1); 395 temp = readl(sport->port.membase + UCR1);
325 writel(temp | UCR1_TXMPTYEN, sport->port.membase + UCR1); 396 writel(temp | UCR1_TXMPTYEN, sport->port.membase + UCR1);
326 397
398 if (USE_IRDA(sport)) {
399 temp = readl(sport->port.membase + UCR1);
400 temp |= UCR1_TRDYEN;
401 writel(temp, sport->port.membase + UCR1);
402
403 temp = readl(sport->port.membase + UCR4);
404 temp |= UCR4_TCEN;
405 writel(temp, sport->port.membase + UCR4);
406 }
407
327 if (readl(sport->port.membase + UTS) & UTS_TXEMPTY) 408 if (readl(sport->port.membase + UTS) & UTS_TXEMPTY)
328 imx_transmit_buffer(sport); 409 imx_transmit_buffer(sport);
329} 410}
@@ -395,8 +476,7 @@ static irqreturn_t imx_rxint(int irq, void *dev_id)
395 continue; 476 continue;
396 } 477 }
397 478
398 if (uart_handle_sysrq_char 479 if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx))
399 (&sport->port, (unsigned char)rx))
400 continue; 480 continue;
401 481
402 if (rx & (URXD_PRERR | URXD_OVRRUN | URXD_FRMERR) ) { 482 if (rx & (URXD_PRERR | URXD_OVRRUN | URXD_FRMERR) ) {
@@ -471,26 +551,26 @@ static unsigned int imx_tx_empty(struct uart_port *port)
471 */ 551 */
472static unsigned int imx_get_mctrl(struct uart_port *port) 552static unsigned int imx_get_mctrl(struct uart_port *port)
473{ 553{
474 struct imx_port *sport = (struct imx_port *)port; 554 struct imx_port *sport = (struct imx_port *)port;
475 unsigned int tmp = TIOCM_DSR | TIOCM_CAR; 555 unsigned int tmp = TIOCM_DSR | TIOCM_CAR;
476 556
477 if (readl(sport->port.membase + USR1) & USR1_RTSS) 557 if (readl(sport->port.membase + USR1) & USR1_RTSS)
478 tmp |= TIOCM_CTS; 558 tmp |= TIOCM_CTS;
479 559
480 if (readl(sport->port.membase + UCR2) & UCR2_CTS) 560 if (readl(sport->port.membase + UCR2) & UCR2_CTS)
481 tmp |= TIOCM_RTS; 561 tmp |= TIOCM_RTS;
482 562
483 return tmp; 563 return tmp;
484} 564}
485 565
486static void imx_set_mctrl(struct uart_port *port, unsigned int mctrl) 566static void imx_set_mctrl(struct uart_port *port, unsigned int mctrl)
487{ 567{
488 struct imx_port *sport = (struct imx_port *)port; 568 struct imx_port *sport = (struct imx_port *)port;
489 unsigned long temp; 569 unsigned long temp;
490 570
491 temp = readl(sport->port.membase + UCR2) & ~UCR2_CTS; 571 temp = readl(sport->port.membase + UCR2) & ~UCR2_CTS;
492 572
493 if (mctrl & TIOCM_RTS) 573 if (mctrl & TIOCM_RTS)
494 temp |= UCR2_CTS; 574 temp |= UCR2_CTS;
495 575
496 writel(temp, sport->port.membase + UCR2); 576 writel(temp, sport->port.membase + UCR2);
@@ -534,12 +614,7 @@ static int imx_setup_ufcr(struct imx_port *sport, unsigned int mode)
534 if(!ufcr_rfdiv) 614 if(!ufcr_rfdiv)
535 ufcr_rfdiv = 1; 615 ufcr_rfdiv = 1;
536 616
537 if(ufcr_rfdiv >= 7) 617 val |= UFCR_RFDIV_REG(ufcr_rfdiv);
538 ufcr_rfdiv = 6;
539 else
540 ufcr_rfdiv = 6 - ufcr_rfdiv;
541
542 val |= UFCR_RFDIV & (ufcr_rfdiv << 7);
543 618
544 writel(val, sport->port.membase + UFCR); 619 writel(val, sport->port.membase + UFCR);
545 620
@@ -558,8 +633,24 @@ static int imx_startup(struct uart_port *port)
558 * requesting IRQs 633 * requesting IRQs
559 */ 634 */
560 temp = readl(sport->port.membase + UCR4); 635 temp = readl(sport->port.membase + UCR4);
636
637 if (USE_IRDA(sport))
638 temp |= UCR4_IRSC;
639
561 writel(temp & ~UCR4_DREN, sport->port.membase + UCR4); 640 writel(temp & ~UCR4_DREN, sport->port.membase + UCR4);
562 641
642 if (USE_IRDA(sport)) {
643 /* reset fifo's and state machines */
644 int i = 100;
645 temp = readl(sport->port.membase + UCR2);
646 temp &= ~UCR2_SRST;
647 writel(temp, sport->port.membase + UCR2);
648 while (!(readl(sport->port.membase + UCR2) & UCR2_SRST) &&
649 (--i > 0)) {
650 udelay(1);
651 }
652 }
653
563 /* 654 /*
564 * Allocate the IRQ(s) i.MX1 has three interrupts whereas later 655 * Allocate the IRQ(s) i.MX1 has three interrupts whereas later
565 * chips only have one interrupt. 656 * chips only have one interrupt.
@@ -575,12 +666,16 @@ static int imx_startup(struct uart_port *port)
575 if (retval) 666 if (retval)
576 goto error_out2; 667 goto error_out2;
577 668
578 retval = request_irq(sport->rtsirq, imx_rtsint, 669 /* do not use RTS IRQ on IrDA */
579 (sport->rtsirq < MAX_INTERNAL_IRQ) ? 0 : 670 if (!USE_IRDA(sport)) {
580 IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING, 671 retval = request_irq(sport->rtsirq, imx_rtsint,
581 DRIVER_NAME, sport); 672 (sport->rtsirq < MAX_INTERNAL_IRQ) ? 0 :
582 if (retval) 673 IRQF_TRIGGER_FALLING |
583 goto error_out3; 674 IRQF_TRIGGER_RISING,
675 DRIVER_NAME, sport);
676 if (retval)
677 goto error_out3;
678 }
584 } else { 679 } else {
585 retval = request_irq(sport->port.irq, imx_int, 0, 680 retval = request_irq(sport->port.irq, imx_int, 0,
586 DRIVER_NAME, sport); 681 DRIVER_NAME, sport);
@@ -597,18 +692,49 @@ static int imx_startup(struct uart_port *port)
597 692
598 temp = readl(sport->port.membase + UCR1); 693 temp = readl(sport->port.membase + UCR1);
599 temp |= UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN; 694 temp |= UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN;
695
696 if (USE_IRDA(sport)) {
697 temp |= UCR1_IREN;
698 temp &= ~(UCR1_RTSDEN);
699 }
700
600 writel(temp, sport->port.membase + UCR1); 701 writel(temp, sport->port.membase + UCR1);
601 702
602 temp = readl(sport->port.membase + UCR2); 703 temp = readl(sport->port.membase + UCR2);
603 temp |= (UCR2_RXEN | UCR2_TXEN); 704 temp |= (UCR2_RXEN | UCR2_TXEN);
604 writel(temp, sport->port.membase + UCR2); 705 writel(temp, sport->port.membase + UCR2);
605 706
707 if (USE_IRDA(sport)) {
708 /* clear RX-FIFO */
709 int i = 64;
710 while ((--i > 0) &&
711 (readl(sport->port.membase + URXD0) & URXD_CHARRDY)) {
712 barrier();
713 }
714 }
715
606#if defined CONFIG_ARCH_MX2 || defined CONFIG_ARCH_MX3 716#if defined CONFIG_ARCH_MX2 || defined CONFIG_ARCH_MX3
607 temp = readl(sport->port.membase + UCR3); 717 temp = readl(sport->port.membase + UCR3);
608 temp |= UCR3_RXDMUXSEL; 718 temp |= UCR3_RXDMUXSEL;
609 writel(temp, sport->port.membase + UCR3); 719 writel(temp, sport->port.membase + UCR3);
610#endif 720#endif
611 721
722 if (USE_IRDA(sport)) {
723 temp = readl(sport->port.membase + UCR4);
724 if (sport->irda_inv_rx)
725 temp |= UCR4_INVR;
726 else
727 temp &= ~(UCR4_INVR);
728 writel(temp | UCR4_DREN, sport->port.membase + UCR4);
729
730 temp = readl(sport->port.membase + UCR3);
731 if (sport->irda_inv_tx)
732 temp |= UCR3_INVT;
733 else
734 temp &= ~(UCR3_INVT);
735 writel(temp, sport->port.membase + UCR3);
736 }
737
612 /* 738 /*
613 * Enable modem status interrupts 739 * Enable modem status interrupts
614 */ 740 */
@@ -616,6 +742,16 @@ static int imx_startup(struct uart_port *port)
616 imx_enable_ms(&sport->port); 742 imx_enable_ms(&sport->port);
617 spin_unlock_irqrestore(&sport->port.lock,flags); 743 spin_unlock_irqrestore(&sport->port.lock,flags);
618 744
745 if (USE_IRDA(sport)) {
746 struct imxuart_platform_data *pdata;
747 pdata = sport->port.dev->platform_data;
748 sport->irda_inv_rx = pdata->irda_inv_rx;
749 sport->irda_inv_tx = pdata->irda_inv_tx;
750 sport->trcv_delay = pdata->transceiver_delay;
751 if (pdata->irda_enable)
752 pdata->irda_enable(1);
753 }
754
619 return 0; 755 return 0;
620 756
621error_out3: 757error_out3:
@@ -633,6 +769,17 @@ static void imx_shutdown(struct uart_port *port)
633 struct imx_port *sport = (struct imx_port *)port; 769 struct imx_port *sport = (struct imx_port *)port;
634 unsigned long temp; 770 unsigned long temp;
635 771
772 temp = readl(sport->port.membase + UCR2);
773 temp &= ~(UCR2_TXEN);
774 writel(temp, sport->port.membase + UCR2);
775
776 if (USE_IRDA(sport)) {
777 struct imxuart_platform_data *pdata;
778 pdata = sport->port.dev->platform_data;
779 if (pdata->irda_enable)
780 pdata->irda_enable(0);
781 }
782
636 /* 783 /*
637 * Stop our timer. 784 * Stop our timer.
638 */ 785 */
@@ -642,7 +789,8 @@ static void imx_shutdown(struct uart_port *port)
642 * Free the interrupts 789 * Free the interrupts
643 */ 790 */
644 if (sport->txirq > 0) { 791 if (sport->txirq > 0) {
645 free_irq(sport->rtsirq, sport); 792 if (!USE_IRDA(sport))
793 free_irq(sport->rtsirq, sport);
646 free_irq(sport->txirq, sport); 794 free_irq(sport->txirq, sport);
647 free_irq(sport->rxirq, sport); 795 free_irq(sport->rxirq, sport);
648 } else 796 } else
@@ -654,6 +802,9 @@ static void imx_shutdown(struct uart_port *port)
654 802
655 temp = readl(sport->port.membase + UCR1); 803 temp = readl(sport->port.membase + UCR1);
656 temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN); 804 temp &= ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN);
805 if (USE_IRDA(sport))
806 temp &= ~(UCR1_IREN);
807
657 writel(temp, sport->port.membase + UCR1); 808 writel(temp, sport->port.membase + UCR1);
658} 809}
659 810
@@ -665,7 +816,9 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
665 unsigned long flags; 816 unsigned long flags;
666 unsigned int ucr2, old_ucr1, old_txrxen, baud, quot; 817 unsigned int ucr2, old_ucr1, old_txrxen, baud, quot;
667 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8; 818 unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
668 unsigned int div, num, denom, ufcr; 819 unsigned int div, ufcr;
820 unsigned long num, denom;
821 uint64_t tdiv64;
669 822
670 /* 823 /*
671 * If we don't support modem control lines, don't allow 824 * If we don't support modem control lines, don't allow
@@ -761,38 +914,39 @@ imx_set_termios(struct uart_port *port, struct ktermios *termios,
761 sport->port.membase + UCR2); 914 sport->port.membase + UCR2);
762 old_txrxen &= (UCR2_TXEN | UCR2_RXEN); 915 old_txrxen &= (UCR2_TXEN | UCR2_RXEN);
763 916
764 div = sport->port.uartclk / (baud * 16); 917 if (USE_IRDA(sport)) {
765 if (div > 7) 918 /*
766 div = 7; 919 * use maximum available submodule frequency to
767 if (!div) 920 * avoid missing short pulses due to low sampling rate
921 */
768 div = 1; 922 div = 1;
769 923 } else {
770 num = baud; 924 div = sport->port.uartclk / (baud * 16);
771 denom = port->uartclk / div / 16; 925 if (div > 7)
772 926 div = 7;
773 /* shift num and denom right until they fit into 16 bits */ 927 if (!div)
774 while (num > 0x10000 || denom > 0x10000) { 928 div = 1;
775 num >>= 1;
776 denom >>= 1;
777 } 929 }
778 if (num > 0)
779 num -= 1;
780 if (denom > 0)
781 denom -= 1;
782 930
783 writel(num, sport->port.membase + UBIR); 931 rational_best_approximation(16 * div * baud, sport->port.uartclk,
784 writel(denom, sport->port.membase + UBMR); 932 1 << 16, 1 << 16, &num, &denom);
785 933
786 if (div == 7) 934 tdiv64 = sport->port.uartclk;
787 div = 6; /* 6 in RFDIV means divide by 7 */ 935 tdiv64 *= num;
788 else 936 do_div(tdiv64, denom * 16 * div);
789 div = 6 - div; 937 tty_encode_baud_rate(sport->port.info->port.tty,
938 (speed_t)tdiv64, (speed_t)tdiv64);
939
940 num -= 1;
941 denom -= 1;
790 942
791 ufcr = readl(sport->port.membase + UFCR); 943 ufcr = readl(sport->port.membase + UFCR);
792 ufcr = (ufcr & (~UFCR_RFDIV)) | 944 ufcr = (ufcr & (~UFCR_RFDIV)) | UFCR_RFDIV_REG(div);
793 (div << 7);
794 writel(ufcr, sport->port.membase + UFCR); 945 writel(ufcr, sport->port.membase + UFCR);
795 946
947 writel(num, sport->port.membase + UBIR);
948 writel(denom, sport->port.membase + UBMR);
949
796#ifdef ONEMS 950#ifdef ONEMS
797 writel(sport->port.uartclk / div / 1000, sport->port.membase + ONEMS); 951 writel(sport->port.uartclk / div / 1000, sport->port.membase + ONEMS);
798#endif 952#endif
@@ -1072,22 +1226,22 @@ static struct uart_driver imx_reg = {
1072 1226
1073static int serial_imx_suspend(struct platform_device *dev, pm_message_t state) 1227static int serial_imx_suspend(struct platform_device *dev, pm_message_t state)
1074{ 1228{
1075 struct imx_port *sport = platform_get_drvdata(dev); 1229 struct imx_port *sport = platform_get_drvdata(dev);
1076 1230
1077 if (sport) 1231 if (sport)
1078 uart_suspend_port(&imx_reg, &sport->port); 1232 uart_suspend_port(&imx_reg, &sport->port);
1079 1233
1080 return 0; 1234 return 0;
1081} 1235}
1082 1236
1083static int serial_imx_resume(struct platform_device *dev) 1237static int serial_imx_resume(struct platform_device *dev)
1084{ 1238{
1085 struct imx_port *sport = platform_get_drvdata(dev); 1239 struct imx_port *sport = platform_get_drvdata(dev);
1086 1240
1087 if (sport) 1241 if (sport)
1088 uart_resume_port(&imx_reg, &sport->port); 1242 uart_resume_port(&imx_reg, &sport->port);
1089 1243
1090 return 0; 1244 return 0;
1091} 1245}
1092 1246
1093static int serial_imx_probe(struct platform_device *pdev) 1247static int serial_imx_probe(struct platform_device *pdev)
@@ -1143,19 +1297,29 @@ static int serial_imx_probe(struct platform_device *pdev)
1143 imx_ports[pdev->id] = sport; 1297 imx_ports[pdev->id] = sport;
1144 1298
1145 pdata = pdev->dev.platform_data; 1299 pdata = pdev->dev.platform_data;
1146 if(pdata && (pdata->flags & IMXUART_HAVE_RTSCTS)) 1300 if (pdata && (pdata->flags & IMXUART_HAVE_RTSCTS))
1147 sport->have_rtscts = 1; 1301 sport->have_rtscts = 1;
1148 1302
1303#ifdef CONFIG_IRDA
1304 if (pdata && (pdata->flags & IMXUART_IRDA))
1305 sport->use_irda = 1;
1306#endif
1307
1149 if (pdata->init) { 1308 if (pdata->init) {
1150 ret = pdata->init(pdev); 1309 ret = pdata->init(pdev);
1151 if (ret) 1310 if (ret)
1152 goto clkput; 1311 goto clkput;
1153 } 1312 }
1154 1313
1155 uart_add_one_port(&imx_reg, &sport->port); 1314 ret = uart_add_one_port(&imx_reg, &sport->port);
1315 if (ret)
1316 goto deinit;
1156 platform_set_drvdata(pdev, &sport->port); 1317 platform_set_drvdata(pdev, &sport->port);
1157 1318
1158 return 0; 1319 return 0;
1320deinit:
1321 if (pdata->exit)
1322 pdata->exit(pdev);
1159clkput: 1323clkput:
1160 clk_put(sport->clk); 1324 clk_put(sport->clk);
1161 clk_disable(sport->clk); 1325 clk_disable(sport->clk);
@@ -1193,13 +1357,13 @@ static int serial_imx_remove(struct platform_device *pdev)
1193} 1357}
1194 1358
1195static struct platform_driver serial_imx_driver = { 1359static struct platform_driver serial_imx_driver = {
1196 .probe = serial_imx_probe, 1360 .probe = serial_imx_probe,
1197 .remove = serial_imx_remove, 1361 .remove = serial_imx_remove,
1198 1362
1199 .suspend = serial_imx_suspend, 1363 .suspend = serial_imx_suspend,
1200 .resume = serial_imx_resume, 1364 .resume = serial_imx_resume,
1201 .driver = { 1365 .driver = {
1202 .name = "imx-uart", 1366 .name = "imx-uart",
1203 .owner = THIS_MODULE, 1367 .owner = THIS_MODULE,
1204 }, 1368 },
1205}; 1369};
diff --git a/drivers/serial/jsm/jsm.h b/drivers/serial/jsm/jsm.h
index c0a3e2734e24..4e5f3bde0461 100644
--- a/drivers/serial/jsm/jsm.h
+++ b/drivers/serial/jsm/jsm.h
@@ -61,6 +61,7 @@ enum {
61 if ((DBG_##nlevel & jsm_debug)) \ 61 if ((DBG_##nlevel & jsm_debug)) \
62 dev_printk(KERN_##klevel, pdev->dev, fmt, ## args) 62 dev_printk(KERN_##klevel, pdev->dev, fmt, ## args)
63 63
64#define MAXLINES 256
64#define MAXPORTS 8 65#define MAXPORTS 8
65#define MAX_STOPS_SENT 5 66#define MAX_STOPS_SENT 5
66 67
diff --git a/drivers/serial/jsm/jsm_tty.c b/drivers/serial/jsm/jsm_tty.c
index 31496dc0a0d1..107ce2e187b8 100644
--- a/drivers/serial/jsm/jsm_tty.c
+++ b/drivers/serial/jsm/jsm_tty.c
@@ -33,6 +33,8 @@
33 33
34#include "jsm.h" 34#include "jsm.h"
35 35
36static DECLARE_BITMAP(linemap, MAXLINES);
37
36static void jsm_carrier(struct jsm_channel *ch); 38static void jsm_carrier(struct jsm_channel *ch);
37 39
38static inline int jsm_get_mstat(struct jsm_channel *ch) 40static inline int jsm_get_mstat(struct jsm_channel *ch)
@@ -433,6 +435,7 @@ int __devinit jsm_tty_init(struct jsm_board *brd)
433int __devinit jsm_uart_port_init(struct jsm_board *brd) 435int __devinit jsm_uart_port_init(struct jsm_board *brd)
434{ 436{
435 int i; 437 int i;
438 unsigned int line;
436 struct jsm_channel *ch; 439 struct jsm_channel *ch;
437 440
438 if (!brd) 441 if (!brd)
@@ -459,9 +462,15 @@ int __devinit jsm_uart_port_init(struct jsm_board *brd)
459 brd->channels[i]->uart_port.membase = brd->re_map_membase; 462 brd->channels[i]->uart_port.membase = brd->re_map_membase;
460 brd->channels[i]->uart_port.fifosize = 16; 463 brd->channels[i]->uart_port.fifosize = 16;
461 brd->channels[i]->uart_port.ops = &jsm_ops; 464 brd->channels[i]->uart_port.ops = &jsm_ops;
462 brd->channels[i]->uart_port.line = brd->channels[i]->ch_portnum + brd->boardnum * 2; 465 line = find_first_zero_bit(linemap, MAXLINES);
466 if (line >= MAXLINES) {
467 printk(KERN_INFO "jsm: linemap is full, added device failed\n");
468 continue;
469 } else
470 set_bit((int)line, linemap);
471 brd->channels[i]->uart_port.line = line;
463 if (uart_add_one_port (&jsm_uart_driver, &brd->channels[i]->uart_port)) 472 if (uart_add_one_port (&jsm_uart_driver, &brd->channels[i]->uart_port))
464 printk(KERN_INFO "Added device failed\n"); 473 printk(KERN_INFO "jsm: add device failed\n");
465 else 474 else
466 printk(KERN_INFO "Added device \n"); 475 printk(KERN_INFO "Added device \n");
467 } 476 }
@@ -494,6 +503,7 @@ int jsm_remove_uart_port(struct jsm_board *brd)
494 503
495 ch = brd->channels[i]; 504 ch = brd->channels[i];
496 505
506 clear_bit((int)(ch->uart_port.line), linemap);
497 uart_remove_one_port(&jsm_uart_driver, &brd->channels[i]->uart_port); 507 uart_remove_one_port(&jsm_uart_driver, &brd->channels[i]->uart_port);
498 } 508 }
499 509
diff --git a/drivers/serial/sh-sci.c b/drivers/serial/sh-sci.c
index dbf5357a77b3..a4cf1079b312 100644
--- a/drivers/serial/sh-sci.c
+++ b/drivers/serial/sh-sci.c
@@ -47,12 +47,17 @@
47#include <linux/clk.h> 47#include <linux/clk.h>
48#include <linux/ctype.h> 48#include <linux/ctype.h>
49#include <linux/err.h> 49#include <linux/err.h>
50#include <linux/list.h>
50 51
51#ifdef CONFIG_SUPERH 52#ifdef CONFIG_SUPERH
52#include <asm/clock.h> 53#include <asm/clock.h>
53#include <asm/sh_bios.h> 54#include <asm/sh_bios.h>
54#endif 55#endif
55 56
57#ifdef CONFIG_H8300
58#include <asm/gpio.h>
59#endif
60
56#include "sh-sci.h" 61#include "sh-sci.h"
57 62
58struct sci_port { 63struct sci_port {
@@ -75,14 +80,22 @@ struct sci_port {
75 int break_flag; 80 int break_flag;
76 81
77#ifdef CONFIG_HAVE_CLK 82#ifdef CONFIG_HAVE_CLK
78 /* Port clock */ 83 /* Interface clock */
79 struct clk *clk; 84 struct clk *iclk;
85 /* Data clock */
86 struct clk *dclk;
80#endif 87#endif
88 struct list_head node;
81}; 89};
82 90
83#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE 91struct sh_sci_priv {
84static struct sci_port *serial_console_port; 92 spinlock_t lock;
93 struct list_head ports;
94
95#ifdef CONFIG_HAVE_CLK
96 struct notifier_block clk_nb;
85#endif 97#endif
98};
86 99
87/* Function prototypes */ 100/* Function prototypes */
88static void sci_stop_tx(struct uart_port *port); 101static void sci_stop_tx(struct uart_port *port);
@@ -138,9 +151,8 @@ static void sci_poll_put_char(struct uart_port *port, unsigned char c)
138 status = sci_in(port, SCxSR); 151 status = sci_in(port, SCxSR);
139 } while (!(status & SCxSR_TDxE(port))); 152 } while (!(status & SCxSR_TDxE(port)));
140 153
141 sci_in(port, SCxSR); /* Dummy read */
142 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port));
143 sci_out(port, SCxTDR, c); 154 sci_out(port, SCxTDR, c);
155 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port));
144} 156}
145#endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */ 157#endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */
146 158
@@ -159,12 +171,12 @@ static void h8300_sci_config(struct uart_port *port, unsigned int ctrl)
159 *mstpcrl &= ~mask; 171 *mstpcrl &= ~mask;
160} 172}
161 173
162static inline void h8300_sci_enable(struct uart_port *port) 174static void h8300_sci_enable(struct uart_port *port)
163{ 175{
164 h8300_sci_config(port, sci_enable); 176 h8300_sci_config(port, sci_enable);
165} 177}
166 178
167static inline void h8300_sci_disable(struct uart_port *port) 179static void h8300_sci_disable(struct uart_port *port)
168{ 180{
169 h8300_sci_config(port, sci_disable); 181 h8300_sci_config(port, sci_disable);
170} 182}
@@ -611,7 +623,7 @@ static inline int sci_handle_breaks(struct uart_port *port)
611 int copied = 0; 623 int copied = 0;
612 unsigned short status = sci_in(port, SCxSR); 624 unsigned short status = sci_in(port, SCxSR);
613 struct tty_struct *tty = port->info->port.tty; 625 struct tty_struct *tty = port->info->port.tty;
614 struct sci_port *s = &sci_ports[port->line]; 626 struct sci_port *s = to_sci_port(port);
615 627
616 if (uart_handle_break(port)) 628 if (uart_handle_break(port))
617 return 0; 629 return 0;
@@ -726,19 +738,43 @@ static irqreturn_t sci_mpxed_interrupt(int irq, void *ptr)
726static int sci_notifier(struct notifier_block *self, 738static int sci_notifier(struct notifier_block *self,
727 unsigned long phase, void *p) 739 unsigned long phase, void *p)
728{ 740{
729 int i; 741 struct sh_sci_priv *priv = container_of(self,
742 struct sh_sci_priv, clk_nb);
743 struct sci_port *sci_port;
744 unsigned long flags;
730 745
731 if ((phase == CPUFREQ_POSTCHANGE) || 746 if ((phase == CPUFREQ_POSTCHANGE) ||
732 (phase == CPUFREQ_RESUMECHANGE)) 747 (phase == CPUFREQ_RESUMECHANGE)) {
733 for (i = 0; i < SCI_NPORTS; i++) { 748 spin_lock_irqsave(&priv->lock, flags);
734 struct sci_port *s = &sci_ports[i]; 749 list_for_each_entry(sci_port, &priv->ports, node)
735 s->port.uartclk = clk_get_rate(s->clk); 750 sci_port->port.uartclk = clk_get_rate(sci_port->dclk);
736 } 751
752 spin_unlock_irqrestore(&priv->lock, flags);
753 }
737 754
738 return NOTIFY_OK; 755 return NOTIFY_OK;
739} 756}
740 757
741static struct notifier_block sci_nb = { &sci_notifier, NULL, 0 }; 758static void sci_clk_enable(struct uart_port *port)
759{
760 struct sci_port *sci_port = to_sci_port(port);
761
762 clk_enable(sci_port->dclk);
763 sci_port->port.uartclk = clk_get_rate(sci_port->dclk);
764
765 if (sci_port->iclk)
766 clk_enable(sci_port->iclk);
767}
768
769static void sci_clk_disable(struct uart_port *port)
770{
771 struct sci_port *sci_port = to_sci_port(port);
772
773 if (sci_port->iclk)
774 clk_disable(sci_port->iclk);
775
776 clk_disable(sci_port->dclk);
777}
742#endif 778#endif
743 779
744static int sci_request_irq(struct sci_port *port) 780static int sci_request_irq(struct sci_port *port)
@@ -865,15 +901,11 @@ static void sci_break_ctl(struct uart_port *port, int break_state)
865 901
866static int sci_startup(struct uart_port *port) 902static int sci_startup(struct uart_port *port)
867{ 903{
868 struct sci_port *s = &sci_ports[port->line]; 904 struct sci_port *s = to_sci_port(port);
869 905
870 if (s->enable) 906 if (s->enable)
871 s->enable(port); 907 s->enable(port);
872 908
873#ifdef CONFIG_HAVE_CLK
874 s->clk = clk_get(NULL, "module_clk");
875#endif
876
877 sci_request_irq(s); 909 sci_request_irq(s);
878 sci_start_tx(port); 910 sci_start_tx(port);
879 sci_start_rx(port, 1); 911 sci_start_rx(port, 1);
@@ -883,7 +915,7 @@ static int sci_startup(struct uart_port *port)
883 915
884static void sci_shutdown(struct uart_port *port) 916static void sci_shutdown(struct uart_port *port)
885{ 917{
886 struct sci_port *s = &sci_ports[port->line]; 918 struct sci_port *s = to_sci_port(port);
887 919
888 sci_stop_rx(port); 920 sci_stop_rx(port);
889 sci_stop_tx(port); 921 sci_stop_tx(port);
@@ -891,11 +923,6 @@ static void sci_shutdown(struct uart_port *port)
891 923
892 if (s->disable) 924 if (s->disable)
893 s->disable(port); 925 s->disable(port);
894
895#ifdef CONFIG_HAVE_CLK
896 clk_put(s->clk);
897 s->clk = NULL;
898#endif
899} 926}
900 927
901static void sci_set_termios(struct uart_port *port, struct ktermios *termios, 928static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
@@ -980,25 +1007,31 @@ static int sci_request_port(struct uart_port *port)
980 1007
981static void sci_config_port(struct uart_port *port, int flags) 1008static void sci_config_port(struct uart_port *port, int flags)
982{ 1009{
983 struct sci_port *s = &sci_ports[port->line]; 1010 struct sci_port *s = to_sci_port(port);
984 1011
985 port->type = s->type; 1012 port->type = s->type;
986 1013
987 if (port->flags & UPF_IOREMAP && !port->membase) { 1014 if (port->membase)
988#if defined(CONFIG_SUPERH64) 1015 return;
989 port->mapbase = onchip_remap(SCIF_ADDR_SH5, 1024, "SCIF"); 1016
990 port->membase = (void __iomem *)port->mapbase; 1017 if (port->flags & UPF_IOREMAP) {
991#else
992 port->membase = ioremap_nocache(port->mapbase, 0x40); 1018 port->membase = ioremap_nocache(port->mapbase, 0x40);
993#endif
994 1019
995 dev_err(port->dev, "can't remap port#%d\n", port->line); 1020 if (IS_ERR(port->membase))
1021 dev_err(port->dev, "can't remap port#%d\n", port->line);
1022 } else {
1023 /*
1024 * For the simple (and majority of) cases where we don't
1025 * need to do any remapping, just cast the cookie
1026 * directly.
1027 */
1028 port->membase = (void __iomem *)port->mapbase;
996 } 1029 }
997} 1030}
998 1031
999static int sci_verify_port(struct uart_port *port, struct serial_struct *ser) 1032static int sci_verify_port(struct uart_port *port, struct serial_struct *ser)
1000{ 1033{
1001 struct sci_port *s = &sci_ports[port->line]; 1034 struct sci_port *s = to_sci_port(port);
1002 1035
1003 if (ser->irq != s->irqs[SCIx_TXI_IRQ] || ser->irq > nr_irqs) 1036 if (ser->irq != s->irqs[SCIx_TXI_IRQ] || ser->irq > nr_irqs)
1004 return -EINVAL; 1037 return -EINVAL;
@@ -1032,63 +1065,60 @@ static struct uart_ops sci_uart_ops = {
1032#endif 1065#endif
1033}; 1066};
1034 1067
1035static void __init sci_init_ports(void) 1068static void __devinit sci_init_single(struct platform_device *dev,
1069 struct sci_port *sci_port,
1070 unsigned int index,
1071 struct plat_sci_port *p)
1036{ 1072{
1037 static int first = 1; 1073 sci_port->port.ops = &sci_uart_ops;
1038 int i; 1074 sci_port->port.iotype = UPIO_MEM;
1039 1075 sci_port->port.line = index;
1040 if (!first) 1076 sci_port->port.fifosize = 1;
1041 return;
1042
1043 first = 0;
1044
1045 for (i = 0; i < SCI_NPORTS; i++) {
1046 sci_ports[i].port.ops = &sci_uart_ops;
1047 sci_ports[i].port.iotype = UPIO_MEM;
1048 sci_ports[i].port.line = i;
1049 sci_ports[i].port.fifosize = 1;
1050 1077
1051#if defined(__H8300H__) || defined(__H8300S__) 1078#if defined(__H8300H__) || defined(__H8300S__)
1052#ifdef __H8300S__ 1079#ifdef __H8300S__
1053 sci_ports[i].enable = h8300_sci_enable; 1080 sci_port->enable = h8300_sci_enable;
1054 sci_ports[i].disable = h8300_sci_disable; 1081 sci_port->disable = h8300_sci_disable;
1055#endif 1082#endif
1056 sci_ports[i].port.uartclk = CONFIG_CPU_CLOCK; 1083 sci_port->port.uartclk = CONFIG_CPU_CLOCK;
1057#elif defined(CONFIG_HAVE_CLK) 1084#elif defined(CONFIG_HAVE_CLK)
1058 /* 1085 sci_port->iclk = p->clk ? clk_get(&dev->dev, p->clk) : NULL;
1059 * XXX: We should use a proper SCI/SCIF clock 1086 sci_port->dclk = clk_get(&dev->dev, "peripheral_clk");
1060 */ 1087 sci_port->enable = sci_clk_enable;
1061 { 1088 sci_port->disable = sci_clk_disable;
1062 struct clk *clk = clk_get(NULL, "module_clk");
1063 sci_ports[i].port.uartclk = clk_get_rate(clk);
1064 clk_put(clk);
1065 }
1066#else 1089#else
1067#error "Need a valid uartclk" 1090#error "Need a valid uartclk"
1068#endif 1091#endif
1069 1092
1070 sci_ports[i].break_timer.data = (unsigned long)&sci_ports[i]; 1093 sci_port->break_timer.data = (unsigned long)sci_port;
1071 sci_ports[i].break_timer.function = sci_break_timer; 1094 sci_port->break_timer.function = sci_break_timer;
1095 init_timer(&sci_port->break_timer);
1072 1096
1073 init_timer(&sci_ports[i].break_timer); 1097 sci_port->port.mapbase = p->mapbase;
1074 } 1098 sci_port->port.membase = p->membase;
1075}
1076
1077int __init early_sci_setup(struct uart_port *port)
1078{
1079 if (unlikely(port->line > SCI_NPORTS))
1080 return -ENODEV;
1081 1099
1082 sci_init_ports(); 1100 sci_port->port.irq = p->irqs[SCIx_TXI_IRQ];
1101 sci_port->port.flags = p->flags;
1102 sci_port->port.dev = &dev->dev;
1103 sci_port->type = sci_port->port.type = p->type;
1083 1104
1084 sci_ports[port->line].port.membase = port->membase; 1105 memcpy(&sci_port->irqs, &p->irqs, sizeof(p->irqs));
1085 sci_ports[port->line].port.mapbase = port->mapbase;
1086 sci_ports[port->line].port.type = port->type;
1087 1106
1088 return 0;
1089} 1107}
1090 1108
1091#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE 1109#ifdef CONFIG_SERIAL_SH_SCI_CONSOLE
1110static struct tty_driver *serial_console_device(struct console *co, int *index)
1111{
1112 struct uart_driver *p = &sci_uart_driver;
1113 *index = co->index;
1114 return p->tty_driver;
1115}
1116
1117static void serial_console_putchar(struct uart_port *port, int ch)
1118{
1119 sci_poll_put_char(port, ch);
1120}
1121
1092/* 1122/*
1093 * Print a string to the serial port trying not to disturb 1123 * Print a string to the serial port trying not to disturb
1094 * any possible real use of the port... 1124 * any possible real use of the port...
@@ -1096,25 +1126,27 @@ int __init early_sci_setup(struct uart_port *port)
1096static void serial_console_write(struct console *co, const char *s, 1126static void serial_console_write(struct console *co, const char *s,
1097 unsigned count) 1127 unsigned count)
1098{ 1128{
1099 struct uart_port *port = &serial_console_port->port; 1129 struct uart_port *port = co->data;
1130 struct sci_port *sci_port = to_sci_port(port);
1100 unsigned short bits; 1131 unsigned short bits;
1101 int i;
1102 1132
1103 for (i = 0; i < count; i++) { 1133 if (sci_port->enable)
1104 if (*s == 10) 1134 sci_port->enable(port);
1105 sci_poll_put_char(port, '\r');
1106 1135
1107 sci_poll_put_char(port, *s++); 1136 uart_console_write(port, s, count, serial_console_putchar);
1108 }
1109 1137
1110 /* wait until fifo is empty and last bit has been transmitted */ 1138 /* wait until fifo is empty and last bit has been transmitted */
1111 bits = SCxSR_TDxE(port) | SCxSR_TEND(port); 1139 bits = SCxSR_TDxE(port) | SCxSR_TEND(port);
1112 while ((sci_in(port, SCxSR) & bits) != bits) 1140 while ((sci_in(port, SCxSR) & bits) != bits)
1113 cpu_relax(); 1141 cpu_relax();
1142
1143 if (sci_port->disable);
1144 sci_port->disable(port);
1114} 1145}
1115 1146
1116static int __init serial_console_setup(struct console *co, char *options) 1147static int __init serial_console_setup(struct console *co, char *options)
1117{ 1148{
1149 struct sci_port *sci_port;
1118 struct uart_port *port; 1150 struct uart_port *port;
1119 int baud = 115200; 1151 int baud = 115200;
1120 int bits = 8; 1152 int bits = 8;
@@ -1130,8 +1162,9 @@ static int __init serial_console_setup(struct console *co, char *options)
1130 if (co->index >= SCI_NPORTS) 1162 if (co->index >= SCI_NPORTS)
1131 co->index = 0; 1163 co->index = 0;
1132 1164
1133 serial_console_port = &sci_ports[co->index]; 1165 sci_port = &sci_ports[co->index];
1134 port = &serial_console_port->port; 1166 port = &sci_port->port;
1167 co->data = port;
1135 1168
1136 /* 1169 /*
1137 * Also need to check port->type, we don't actually have any 1170 * Also need to check port->type, we don't actually have any
@@ -1141,21 +1174,11 @@ static int __init serial_console_setup(struct console *co, char *options)
1141 */ 1174 */
1142 if (!port->type) 1175 if (!port->type)
1143 return -ENODEV; 1176 return -ENODEV;
1144 if (!port->membase || !port->mapbase)
1145 return -ENODEV;
1146
1147 port->type = serial_console_port->type;
1148
1149#ifdef CONFIG_HAVE_CLK
1150 if (!serial_console_port->clk)
1151 serial_console_port->clk = clk_get(NULL, "module_clk");
1152#endif
1153 1177
1154 if (port->flags & UPF_IOREMAP) 1178 sci_config_port(port, 0);
1155 sci_config_port(port, 0);
1156 1179
1157 if (serial_console_port->enable) 1180 if (sci_port->enable)
1158 serial_console_port->enable(port); 1181 sci_port->enable(port);
1159 1182
1160 if (options) 1183 if (options)
1161 uart_parse_options(options, &baud, &parity, &bits, &flow); 1184 uart_parse_options(options, &baud, &parity, &bits, &flow);
@@ -1166,22 +1189,21 @@ static int __init serial_console_setup(struct console *co, char *options)
1166 if (ret == 0) 1189 if (ret == 0)
1167 sci_stop_rx(port); 1190 sci_stop_rx(port);
1168#endif 1191#endif
1192 /* TODO: disable clock */
1169 return ret; 1193 return ret;
1170} 1194}
1171 1195
1172static struct console serial_console = { 1196static struct console serial_console = {
1173 .name = "ttySC", 1197 .name = "ttySC",
1174 .device = uart_console_device, 1198 .device = serial_console_device,
1175 .write = serial_console_write, 1199 .write = serial_console_write,
1176 .setup = serial_console_setup, 1200 .setup = serial_console_setup,
1177 .flags = CON_PRINTBUFFER, 1201 .flags = CON_PRINTBUFFER,
1178 .index = -1, 1202 .index = -1,
1179 .data = &sci_uart_driver,
1180}; 1203};
1181 1204
1182static int __init sci_console_init(void) 1205static int __init sci_console_init(void)
1183{ 1206{
1184 sci_init_ports();
1185 register_console(&serial_console); 1207 register_console(&serial_console);
1186 return 0; 1208 return 0;
1187} 1209}
@@ -1207,6 +1229,61 @@ static struct uart_driver sci_uart_driver = {
1207 .cons = SCI_CONSOLE, 1229 .cons = SCI_CONSOLE,
1208}; 1230};
1209 1231
1232
1233static int sci_remove(struct platform_device *dev)
1234{
1235 struct sh_sci_priv *priv = platform_get_drvdata(dev);
1236 struct sci_port *p;
1237 unsigned long flags;
1238
1239#ifdef CONFIG_HAVE_CLK
1240 cpufreq_unregister_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER);
1241#endif
1242
1243 spin_lock_irqsave(&priv->lock, flags);
1244 list_for_each_entry(p, &priv->ports, node)
1245 uart_remove_one_port(&sci_uart_driver, &p->port);
1246
1247 spin_unlock_irqrestore(&priv->lock, flags);
1248
1249 kfree(priv);
1250 return 0;
1251}
1252
1253static int __devinit sci_probe_single(struct platform_device *dev,
1254 unsigned int index,
1255 struct plat_sci_port *p,
1256 struct sci_port *sciport)
1257{
1258 struct sh_sci_priv *priv = platform_get_drvdata(dev);
1259 unsigned long flags;
1260 int ret;
1261
1262 /* Sanity check */
1263 if (unlikely(index >= SCI_NPORTS)) {
1264 dev_notice(&dev->dev, "Attempting to register port "
1265 "%d when only %d are available.\n",
1266 index+1, SCI_NPORTS);
1267 dev_notice(&dev->dev, "Consider bumping "
1268 "CONFIG_SERIAL_SH_SCI_NR_UARTS!\n");
1269 return 0;
1270 }
1271
1272 sci_init_single(dev, sciport, index, p);
1273
1274 ret = uart_add_one_port(&sci_uart_driver, &sciport->port);
1275 if (ret)
1276 return ret;
1277
1278 INIT_LIST_HEAD(&sciport->node);
1279
1280 spin_lock_irqsave(&priv->lock, flags);
1281 list_add(&sciport->node, &priv->ports);
1282 spin_unlock_irqrestore(&priv->lock, flags);
1283
1284 return 0;
1285}
1286
1210/* 1287/*
1211 * Register a set of serial devices attached to a platform device. The 1288 * Register a set of serial devices attached to a platform device. The
1212 * list is terminated with a zero flags entry, which means we expect 1289 * list is terminated with a zero flags entry, which means we expect
@@ -1216,57 +1293,34 @@ static struct uart_driver sci_uart_driver = {
1216static int __devinit sci_probe(struct platform_device *dev) 1293static int __devinit sci_probe(struct platform_device *dev)
1217{ 1294{
1218 struct plat_sci_port *p = dev->dev.platform_data; 1295 struct plat_sci_port *p = dev->dev.platform_data;
1296 struct sh_sci_priv *priv;
1219 int i, ret = -EINVAL; 1297 int i, ret = -EINVAL;
1220 1298
1221 for (i = 0; p && p->flags != 0; p++, i++) { 1299 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1222 struct sci_port *sciport = &sci_ports[i]; 1300 if (!priv)
1301 return -ENOMEM;
1223 1302
1224 /* Sanity check */ 1303 INIT_LIST_HEAD(&priv->ports);
1225 if (unlikely(i == SCI_NPORTS)) { 1304 spin_lock_init(&priv->lock);
1226 dev_notice(&dev->dev, "Attempting to register port " 1305 platform_set_drvdata(dev, priv);
1227 "%d when only %d are available.\n",
1228 i+1, SCI_NPORTS);
1229 dev_notice(&dev->dev, "Consider bumping "
1230 "CONFIG_SERIAL_SH_SCI_NR_UARTS!\n");
1231 break;
1232 }
1233 1306
1234 sciport->port.mapbase = p->mapbase; 1307#ifdef CONFIG_HAVE_CLK
1308 priv->clk_nb.notifier_call = sci_notifier;
1309 cpufreq_register_notifier(&priv->clk_nb, CPUFREQ_TRANSITION_NOTIFIER);
1310#endif
1235 1311
1236 if (p->mapbase && !p->membase) { 1312 if (dev->id != -1) {
1237 if (p->flags & UPF_IOREMAP) { 1313 ret = sci_probe_single(dev, dev->id, p, &sci_ports[dev->id]);
1238 p->membase = ioremap_nocache(p->mapbase, 0x40); 1314 if (ret)
1239 if (IS_ERR(p->membase)) { 1315 goto err_unreg;
1240 ret = PTR_ERR(p->membase); 1316 } else {
1241 goto err_unreg; 1317 for (i = 0; p && p->flags != 0; p++, i++) {
1242 } 1318 ret = sci_probe_single(dev, i, p, &sci_ports[i]);
1243 } else { 1319 if (ret)
1244 /* 1320 goto err_unreg;
1245 * For the simple (and majority of) cases
1246 * where we don't need to do any remapping,
1247 * just cast the cookie directly.
1248 */
1249 p->membase = (void __iomem *)p->mapbase;
1250 }
1251 } 1321 }
1252
1253 sciport->port.membase = p->membase;
1254
1255 sciport->port.irq = p->irqs[SCIx_TXI_IRQ];
1256 sciport->port.flags = p->flags;
1257 sciport->port.dev = &dev->dev;
1258
1259 sciport->type = sciport->port.type = p->type;
1260
1261 memcpy(&sciport->irqs, &p->irqs, sizeof(p->irqs));
1262
1263 uart_add_one_port(&sci_uart_driver, &sciport->port);
1264 } 1322 }
1265 1323
1266#ifdef CONFIG_HAVE_CLK
1267 cpufreq_register_notifier(&sci_nb, CPUFREQ_TRANSITION_NOTIFIER);
1268#endif
1269
1270#ifdef CONFIG_SH_STANDARD_BIOS 1324#ifdef CONFIG_SH_STANDARD_BIOS
1271 sh_bios_gdb_detach(); 1325 sh_bios_gdb_detach();
1272#endif 1326#endif
@@ -1274,50 +1328,36 @@ static int __devinit sci_probe(struct platform_device *dev)
1274 return 0; 1328 return 0;
1275 1329
1276err_unreg: 1330err_unreg:
1277 for (i = i - 1; i >= 0; i--) 1331 sci_remove(dev);
1278 uart_remove_one_port(&sci_uart_driver, &sci_ports[i].port);
1279
1280 return ret; 1332 return ret;
1281} 1333}
1282 1334
1283static int __devexit sci_remove(struct platform_device *dev)
1284{
1285 int i;
1286
1287#ifdef CONFIG_HAVE_CLK
1288 cpufreq_unregister_notifier(&sci_nb, CPUFREQ_TRANSITION_NOTIFIER);
1289#endif
1290
1291 for (i = 0; i < SCI_NPORTS; i++)
1292 uart_remove_one_port(&sci_uart_driver, &sci_ports[i].port);
1293
1294 return 0;
1295}
1296
1297static int sci_suspend(struct platform_device *dev, pm_message_t state) 1335static int sci_suspend(struct platform_device *dev, pm_message_t state)
1298{ 1336{
1299 int i; 1337 struct sh_sci_priv *priv = platform_get_drvdata(dev);
1338 struct sci_port *p;
1339 unsigned long flags;
1300 1340
1301 for (i = 0; i < SCI_NPORTS; i++) { 1341 spin_lock_irqsave(&priv->lock, flags);
1302 struct sci_port *p = &sci_ports[i]; 1342 list_for_each_entry(p, &priv->ports, node)
1343 uart_suspend_port(&sci_uart_driver, &p->port);
1303 1344
1304 if (p->type != PORT_UNKNOWN && p->port.dev == &dev->dev) 1345 spin_unlock_irqrestore(&priv->lock, flags);
1305 uart_suspend_port(&sci_uart_driver, &p->port);
1306 }
1307 1346
1308 return 0; 1347 return 0;
1309} 1348}
1310 1349
1311static int sci_resume(struct platform_device *dev) 1350static int sci_resume(struct platform_device *dev)
1312{ 1351{
1313 int i; 1352 struct sh_sci_priv *priv = platform_get_drvdata(dev);
1353 struct sci_port *p;
1354 unsigned long flags;
1314 1355
1315 for (i = 0; i < SCI_NPORTS; i++) { 1356 spin_lock_irqsave(&priv->lock, flags);
1316 struct sci_port *p = &sci_ports[i]; 1357 list_for_each_entry(p, &priv->ports, node)
1358 uart_resume_port(&sci_uart_driver, &p->port);
1317 1359
1318 if (p->type != PORT_UNKNOWN && p->port.dev == &dev->dev) 1360 spin_unlock_irqrestore(&priv->lock, flags);
1319 uart_resume_port(&sci_uart_driver, &p->port);
1320 }
1321 1361
1322 return 0; 1362 return 0;
1323} 1363}
@@ -1339,8 +1379,6 @@ static int __init sci_init(void)
1339 1379
1340 printk(banner); 1380 printk(banner);
1341 1381
1342 sci_init_ports();
1343
1344 ret = uart_register_driver(&sci_uart_driver); 1382 ret = uart_register_driver(&sci_uart_driver);
1345 if (likely(ret == 0)) { 1383 if (likely(ret == 0)) {
1346 ret = platform_driver_register(&sci_driver); 1384 ret = platform_driver_register(&sci_driver);
diff --git a/drivers/serial/sh-sci.h b/drivers/serial/sh-sci.h
index d0aa82d7fce0..38072c15b845 100644
--- a/drivers/serial/sh-sci.h
+++ b/drivers/serial/sh-sci.h
@@ -91,6 +91,9 @@
91# define SCSPTR5 0xa4050128 91# define SCSPTR5 0xa4050128
92# define SCIF_ORER 0x0001 /* overrun error bit */ 92# define SCIF_ORER 0x0001 /* overrun error bit */
93# define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */ 93# define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
94#elif defined(CONFIG_CPU_SUBTYPE_SH7724)
95# define SCIF_ORER 0x0001 /* overrun error bit */
96# define SCSCR_INIT(port) 0x0038 /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
94#elif defined(CONFIG_CPU_SUBTYPE_SH4_202) 97#elif defined(CONFIG_CPU_SUBTYPE_SH4_202)
95# define SCSPTR2 0xffe80020 /* 16 bit SCIF */ 98# define SCSPTR2 0xffe80020 /* 16 bit SCIF */
96# define SCIF_ORER 0x0001 /* overrun error bit */ 99# define SCIF_ORER 0x0001 /* overrun error bit */
@@ -314,7 +317,18 @@
314 } \ 317 } \
315 } 318 }
316 319
317#define CPU_SCIF_FNS(name, scif_offset, scif_size) \ 320#ifdef CONFIG_H8300
321/* h8300 don't have SCIF */
322#define CPU_SCIF_FNS(name) \
323 static inline unsigned int sci_##name##_in(struct uart_port *port) \
324 { \
325 return 0; \
326 } \
327 static inline void sci_##name##_out(struct uart_port *port, unsigned int value) \
328 { \
329 }
330#else
331#define CPU_SCIF_FNS(name, scif_offset, scif_size) \
318 static inline unsigned int sci_##name##_in(struct uart_port *port) \ 332 static inline unsigned int sci_##name##_in(struct uart_port *port) \
319 { \ 333 { \
320 SCI_IN(scif_size, scif_offset); \ 334 SCI_IN(scif_size, scif_offset); \
@@ -323,6 +337,7 @@
323 { \ 337 { \
324 SCI_OUT(scif_size, scif_offset, value); \ 338 SCI_OUT(scif_size, scif_offset, value); \
325 } 339 }
340#endif
326 341
327#define CPU_SCI_FNS(name, sci_offset, sci_size) \ 342#define CPU_SCI_FNS(name, sci_offset, sci_size) \
328 static inline unsigned int sci_##name##_in(struct uart_port* port) \ 343 static inline unsigned int sci_##name##_in(struct uart_port* port) \
@@ -360,8 +375,10 @@
360 sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \ 375 sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size, \
361 h8_sci_offset, h8_sci_size) \ 376 h8_sci_offset, h8_sci_size) \
362 CPU_SCI_FNS(name, h8_sci_offset, h8_sci_size) 377 CPU_SCI_FNS(name, h8_sci_offset, h8_sci_size)
363#define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) 378#define SCIF_FNS(name, sh3_scif_offset, sh3_scif_size, sh4_scif_offset, sh4_scif_size) \
364#elif defined(CONFIG_CPU_SUBTYPE_SH7723) 379 CPU_SCIF_FNS(name)
380#elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\
381 defined(CONFIG_CPU_SUBTYPE_SH7724)
365 #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size) \ 382 #define SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size) \
366 CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size) 383 CPU_SCIx_FNS(name, sh4_scifa_offset, sh4_scifa_size, sh4_scif_offset, sh4_scif_size)
367 #define SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) \ 384 #define SCIF_FNS(name, sh4_scif_offset, sh4_scif_size) \
@@ -390,7 +407,8 @@ SCIF_FNS(SCFDR, 0x1c, 16)
390SCIF_FNS(SCxTDR, 0x20, 8) 407SCIF_FNS(SCxTDR, 0x20, 8)
391SCIF_FNS(SCxRDR, 0x24, 8) 408SCIF_FNS(SCxRDR, 0x24, 8)
392SCIF_FNS(SCLSR, 0x24, 16) 409SCIF_FNS(SCLSR, 0x24, 16)
393#elif defined(CONFIG_CPU_SUBTYPE_SH7723) 410#elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\
411 defined(CONFIG_CPU_SUBTYPE_SH7724)
394SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16) 412SCIx_FNS(SCSMR, 0x00, 16, 0x00, 16)
395SCIx_FNS(SCBRR, 0x04, 8, 0x04, 8) 413SCIx_FNS(SCBRR, 0x04, 8, 0x04, 8)
396SCIx_FNS(SCSCR, 0x08, 16, 0x08, 16) 414SCIx_FNS(SCSCR, 0x08, 16, 0x08, 16)
@@ -604,10 +622,21 @@ static inline int sci_rxd_in(struct uart_port *port)
604 return ctrl_inb(SCSPTR5) & 0x0008 ? 1 : 0; /* SCIF5 */ 622 return ctrl_inb(SCSPTR5) & 0x0008 ? 1 : 0; /* SCIF5 */
605 return 1; 623 return 1;
606} 624}
625#elif defined(CONFIG_CPU_SUBTYPE_SH7724)
626# define SCFSR 0x0010
627# define SCASSR 0x0014
628static inline int sci_rxd_in(struct uart_port *port)
629{
630 if (port->type == PORT_SCIF)
631 return ctrl_inw((port->mapbase + SCFSR)) & SCIF_BRK ? 1 : 0;
632 if (port->type == PORT_SCIFA)
633 return ctrl_inw((port->mapbase + SCASSR)) & SCIF_BRK ? 1 : 0;
634 return 1;
635}
607#elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103) 636#elif defined(CONFIG_CPU_SUBTYPE_SH5_101) || defined(CONFIG_CPU_SUBTYPE_SH5_103)
608static inline int sci_rxd_in(struct uart_port *port) 637static inline int sci_rxd_in(struct uart_port *port)
609{ 638{
610 return sci_in(port, SCSPTR2)&0x0001 ? 1 : 0; /* SCIF */ 639 return sci_in(port, SCSPTR)&0x0001 ? 1 : 0; /* SCIF */
611} 640}
612#elif defined(__H8300H__) || defined(__H8300S__) 641#elif defined(__H8300H__) || defined(__H8300S__)
613static inline int sci_rxd_in(struct uart_port *port) 642static inline int sci_rxd_in(struct uart_port *port)
@@ -757,7 +786,8 @@ static inline int sci_rxd_in(struct uart_port *port)
757 defined(CONFIG_CPU_SUBTYPE_SH7720) || \ 786 defined(CONFIG_CPU_SUBTYPE_SH7720) || \
758 defined(CONFIG_CPU_SUBTYPE_SH7721) 787 defined(CONFIG_CPU_SUBTYPE_SH7721)
759#define SCBRR_VALUE(bps, clk) (((clk*2)+16*bps)/(32*bps)-1) 788#define SCBRR_VALUE(bps, clk) (((clk*2)+16*bps)/(32*bps)-1)
760#elif defined(CONFIG_CPU_SUBTYPE_SH7723) 789#elif defined(CONFIG_CPU_SUBTYPE_SH7723) ||\
790 defined(CONFIG_CPU_SUBTYPE_SH7724)
761static inline int scbrr_calc(struct uart_port *port, int bps, int clk) 791static inline int scbrr_calc(struct uart_port *port, int bps, int clk)
762{ 792{
763 if (port->type == PORT_SCIF) 793 if (port->type == PORT_SCIF)
diff --git a/drivers/serial/timbuart.c b/drivers/serial/timbuart.c
new file mode 100644
index 000000000000..ac9e5d5f742e
--- /dev/null
+++ b/drivers/serial/timbuart.c
@@ -0,0 +1,526 @@
1/*
2 * timbuart.c timberdale FPGA UART driver
3 * Copyright (c) 2009 Intel Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19/* Supports:
20 * Timberdale FPGA UART
21 */
22
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25#include <linux/serial_core.h>
26#include <linux/kernel.h>
27#include <linux/platform_device.h>
28#include <linux/ioport.h>
29
30#include "timbuart.h"
31
32struct timbuart_port {
33 struct uart_port port;
34 struct tasklet_struct tasklet;
35 int usedma;
36 u8 last_ier;
37 struct platform_device *dev;
38};
39
40static int baudrates[] = {9600, 19200, 38400, 57600, 115200, 230400, 460800,
41 921600, 1843200, 3250000};
42
43static void timbuart_mctrl_check(struct uart_port *port, u8 isr, u8 *ier);
44
45static irqreturn_t timbuart_handleinterrupt(int irq, void *devid);
46
47static void timbuart_stop_rx(struct uart_port *port)
48{
49 /* spin lock held by upper layer, disable all RX interrupts */
50 u8 ier = ioread8(port->membase + TIMBUART_IER) & ~RXFLAGS;
51 iowrite8(ier, port->membase + TIMBUART_IER);
52}
53
54static void timbuart_stop_tx(struct uart_port *port)
55{
56 /* spinlock held by upper layer, disable TX interrupt */
57 u8 ier = ioread8(port->membase + TIMBUART_IER) & ~TXBAE;
58 iowrite8(ier, port->membase + TIMBUART_IER);
59}
60
61static void timbuart_start_tx(struct uart_port *port)
62{
63 struct timbuart_port *uart =
64 container_of(port, struct timbuart_port, port);
65
66 /* do not transfer anything here -> fire off the tasklet */
67 tasklet_schedule(&uart->tasklet);
68}
69
70static void timbuart_flush_buffer(struct uart_port *port)
71{
72 u8 ctl = ioread8(port->membase + TIMBUART_CTRL) | TIMBUART_CTRL_FLSHTX;
73
74 iowrite8(ctl, port->membase + TIMBUART_CTRL);
75 iowrite8(TXBF, port->membase + TIMBUART_ISR);
76}
77
78static void timbuart_rx_chars(struct uart_port *port)
79{
80 struct tty_struct *tty = port->info->port.tty;
81
82 while (ioread8(port->membase + TIMBUART_ISR) & RXDP) {
83 u8 ch = ioread8(port->membase + TIMBUART_RXFIFO);
84 port->icount.rx++;
85 tty_insert_flip_char(tty, ch, TTY_NORMAL);
86 }
87
88 spin_unlock(&port->lock);
89 tty_flip_buffer_push(port->info->port.tty);
90 spin_lock(&port->lock);
91
92 dev_dbg(port->dev, "%s - total read %d bytes\n",
93 __func__, port->icount.rx);
94}
95
96static void timbuart_tx_chars(struct uart_port *port)
97{
98 struct circ_buf *xmit = &port->info->xmit;
99
100 while (!(ioread8(port->membase + TIMBUART_ISR) & TXBF) &&
101 !uart_circ_empty(xmit)) {
102 iowrite8(xmit->buf[xmit->tail],
103 port->membase + TIMBUART_TXFIFO);
104 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
105 port->icount.tx++;
106 }
107
108 dev_dbg(port->dev,
109 "%s - total written %d bytes, CTL: %x, RTS: %x, baud: %x\n",
110 __func__,
111 port->icount.tx,
112 ioread8(port->membase + TIMBUART_CTRL),
113 port->mctrl & TIOCM_RTS,
114 ioread8(port->membase + TIMBUART_BAUDRATE));
115}
116
117static void timbuart_handle_tx_port(struct uart_port *port, u8 isr, u8 *ier)
118{
119 struct timbuart_port *uart =
120 container_of(port, struct timbuart_port, port);
121 struct circ_buf *xmit = &port->info->xmit;
122
123 if (uart_circ_empty(xmit) || uart_tx_stopped(port))
124 return;
125
126 if (port->x_char)
127 return;
128
129 if (isr & TXFLAGS) {
130 timbuart_tx_chars(port);
131 /* clear all TX interrupts */
132 iowrite8(TXFLAGS, port->membase + TIMBUART_ISR);
133
134 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
135 uart_write_wakeup(port);
136 } else
137 /* Re-enable any tx interrupt */
138 *ier |= uart->last_ier & TXFLAGS;
139
140 /* enable interrupts if there are chars in the transmit buffer,
141 * Or if we delivered some bytes and want the almost empty interrupt
142 * we wake up the upper layer later when we got the interrupt
143 * to give it some time to go out...
144 */
145 if (!uart_circ_empty(xmit))
146 *ier |= TXBAE;
147
148 dev_dbg(port->dev, "%s - leaving\n", __func__);
149}
150
151void timbuart_handle_rx_port(struct uart_port *port, u8 isr, u8 *ier)
152{
153 if (isr & RXFLAGS) {
154 /* Some RX status is set */
155 if (isr & RXBF) {
156 u8 ctl = ioread8(port->membase + TIMBUART_CTRL) |
157 TIMBUART_CTRL_FLSHRX;
158 iowrite8(ctl, port->membase + TIMBUART_CTRL);
159 port->icount.overrun++;
160 } else if (isr & (RXDP))
161 timbuart_rx_chars(port);
162
163 /* ack all RX interrupts */
164 iowrite8(RXFLAGS, port->membase + TIMBUART_ISR);
165 }
166
167 /* always have the RX interrupts enabled */
168 *ier |= RXBAF | RXBF | RXTT;
169
170 dev_dbg(port->dev, "%s - leaving\n", __func__);
171}
172
173void timbuart_tasklet(unsigned long arg)
174{
175 struct timbuart_port *uart = (struct timbuart_port *)arg;
176 u8 isr, ier = 0;
177
178 spin_lock(&uart->port.lock);
179
180 isr = ioread8(uart->port.membase + TIMBUART_ISR);
181 dev_dbg(uart->port.dev, "%s ISR: %x\n", __func__, isr);
182
183 if (!uart->usedma)
184 timbuart_handle_tx_port(&uart->port, isr, &ier);
185
186 timbuart_mctrl_check(&uart->port, isr, &ier);
187
188 if (!uart->usedma)
189 timbuart_handle_rx_port(&uart->port, isr, &ier);
190
191 iowrite8(ier, uart->port.membase + TIMBUART_IER);
192
193 spin_unlock(&uart->port.lock);
194 dev_dbg(uart->port.dev, "%s leaving\n", __func__);
195}
196
197static unsigned int timbuart_tx_empty(struct uart_port *port)
198{
199 u8 isr = ioread8(port->membase + TIMBUART_ISR);
200
201 return (isr & TXBAE) ? TIOCSER_TEMT : 0;
202}
203
204static unsigned int timbuart_get_mctrl(struct uart_port *port)
205{
206 u8 cts = ioread8(port->membase + TIMBUART_CTRL);
207 dev_dbg(port->dev, "%s - cts %x\n", __func__, cts);
208
209 if (cts & TIMBUART_CTRL_CTS)
210 return TIOCM_CTS | TIOCM_DSR | TIOCM_CAR;
211 else
212 return TIOCM_DSR | TIOCM_CAR;
213}
214
215static void timbuart_set_mctrl(struct uart_port *port, unsigned int mctrl)
216{
217 dev_dbg(port->dev, "%s - %x\n", __func__, mctrl);
218
219 if (mctrl & TIOCM_RTS)
220 iowrite8(TIMBUART_CTRL_RTS, port->membase + TIMBUART_CTRL);
221 else
222 iowrite8(TIMBUART_CTRL_RTS, port->membase + TIMBUART_CTRL);
223}
224
225static void timbuart_mctrl_check(struct uart_port *port, u8 isr, u8 *ier)
226{
227 unsigned int cts;
228
229 if (isr & CTS_DELTA) {
230 /* ack */
231 iowrite8(CTS_DELTA, port->membase + TIMBUART_ISR);
232 cts = timbuart_get_mctrl(port);
233 uart_handle_cts_change(port, cts & TIOCM_CTS);
234 wake_up_interruptible(&port->info->delta_msr_wait);
235 }
236
237 *ier |= CTS_DELTA;
238}
239
240static void timbuart_enable_ms(struct uart_port *port)
241{
242 /* N/A */
243}
244
245static void timbuart_break_ctl(struct uart_port *port, int ctl)
246{
247 /* N/A */
248}
249
250static int timbuart_startup(struct uart_port *port)
251{
252 struct timbuart_port *uart =
253 container_of(port, struct timbuart_port, port);
254
255 dev_dbg(port->dev, "%s\n", __func__);
256
257 iowrite8(TIMBUART_CTRL_FLSHRX, port->membase + TIMBUART_CTRL);
258 iowrite8(0xff, port->membase + TIMBUART_ISR);
259 /* Enable all but TX interrupts */
260 iowrite8(RXBAF | RXBF | RXTT | CTS_DELTA,
261 port->membase + TIMBUART_IER);
262
263 return request_irq(port->irq, timbuart_handleinterrupt, IRQF_SHARED,
264 "timb-uart", uart);
265}
266
267static void timbuart_shutdown(struct uart_port *port)
268{
269 struct timbuart_port *uart =
270 container_of(port, struct timbuart_port, port);
271 dev_dbg(port->dev, "%s\n", __func__);
272 free_irq(port->irq, uart);
273 iowrite8(0, port->membase + TIMBUART_IER);
274}
275
276static int get_bindex(int baud)
277{
278 int i;
279
280 for (i = 0; i < ARRAY_SIZE(baudrates); i++)
281 if (baud <= baudrates[i])
282 return i;
283
284 return -1;
285}
286
287static void timbuart_set_termios(struct uart_port *port,
288 struct ktermios *termios,
289 struct ktermios *old)
290{
291 unsigned int baud;
292 short bindex;
293 unsigned long flags;
294
295 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
296 bindex = get_bindex(baud);
297 dev_dbg(port->dev, "%s - bindex %d\n", __func__, bindex);
298
299 if (bindex < 0)
300 bindex = 0;
301 baud = baudrates[bindex];
302
303 /* The serial layer calls into this once with old = NULL when setting
304 up initially */
305 if (old)
306 tty_termios_copy_hw(termios, old);
307 tty_termios_encode_baud_rate(termios, baud, baud);
308
309 spin_lock_irqsave(&port->lock, flags);
310 iowrite8((u8)bindex, port->membase + TIMBUART_BAUDRATE);
311 uart_update_timeout(port, termios->c_cflag, baud);
312 spin_unlock_irqrestore(&port->lock, flags);
313}
314
315static const char *timbuart_type(struct uart_port *port)
316{
317 return port->type == PORT_UNKNOWN ? "timbuart" : NULL;
318}
319
320/* We do not request/release mappings of the registers here,
321 * currently it's done in the proble function.
322 */
323static void timbuart_release_port(struct uart_port *port)
324{
325 struct platform_device *pdev = to_platform_device(port->dev);
326 int size =
327 resource_size(platform_get_resource(pdev, IORESOURCE_MEM, 0));
328
329 if (port->flags & UPF_IOREMAP) {
330 iounmap(port->membase);
331 port->membase = NULL;
332 }
333
334 release_mem_region(port->mapbase, size);
335}
336
337static int timbuart_request_port(struct uart_port *port)
338{
339 struct platform_device *pdev = to_platform_device(port->dev);
340 int size =
341 resource_size(platform_get_resource(pdev, IORESOURCE_MEM, 0));
342
343 if (!request_mem_region(port->mapbase, size, "timb-uart"))
344 return -EBUSY;
345
346 if (port->flags & UPF_IOREMAP) {
347 port->membase = ioremap(port->mapbase, size);
348 if (port->membase == NULL) {
349 release_mem_region(port->mapbase, size);
350 return -ENOMEM;
351 }
352 }
353
354 return 0;
355}
356
357static irqreturn_t timbuart_handleinterrupt(int irq, void *devid)
358{
359 struct timbuart_port *uart = (struct timbuart_port *)devid;
360
361 if (ioread8(uart->port.membase + TIMBUART_IPR)) {
362 uart->last_ier = ioread8(uart->port.membase + TIMBUART_IER);
363
364 /* disable interrupts, the tasklet enables them again */
365 iowrite8(0, uart->port.membase + TIMBUART_IER);
366
367 /* fire off bottom half */
368 tasklet_schedule(&uart->tasklet);
369
370 return IRQ_HANDLED;
371 } else
372 return IRQ_NONE;
373}
374
375/*
376 * Configure/autoconfigure the port.
377 */
378static void timbuart_config_port(struct uart_port *port, int flags)
379{
380 if (flags & UART_CONFIG_TYPE) {
381 port->type = PORT_TIMBUART;
382 timbuart_request_port(port);
383 }
384}
385
386static int timbuart_verify_port(struct uart_port *port,
387 struct serial_struct *ser)
388{
389 /* we don't want the core code to modify any port params */
390 return -EINVAL;
391}
392
393static struct uart_ops timbuart_ops = {
394 .tx_empty = timbuart_tx_empty,
395 .set_mctrl = timbuart_set_mctrl,
396 .get_mctrl = timbuart_get_mctrl,
397 .stop_tx = timbuart_stop_tx,
398 .start_tx = timbuart_start_tx,
399 .flush_buffer = timbuart_flush_buffer,
400 .stop_rx = timbuart_stop_rx,
401 .enable_ms = timbuart_enable_ms,
402 .break_ctl = timbuart_break_ctl,
403 .startup = timbuart_startup,
404 .shutdown = timbuart_shutdown,
405 .set_termios = timbuart_set_termios,
406 .type = timbuart_type,
407 .release_port = timbuart_release_port,
408 .request_port = timbuart_request_port,
409 .config_port = timbuart_config_port,
410 .verify_port = timbuart_verify_port
411};
412
413static struct uart_driver timbuart_driver = {
414 .owner = THIS_MODULE,
415 .driver_name = "timberdale_uart",
416 .dev_name = "ttyTU",
417 .major = TIMBUART_MAJOR,
418 .minor = TIMBUART_MINOR,
419 .nr = 1
420};
421
422static int timbuart_probe(struct platform_device *dev)
423{
424 int err;
425 struct timbuart_port *uart;
426 struct resource *iomem;
427
428 dev_dbg(&dev->dev, "%s\n", __func__);
429
430 uart = kzalloc(sizeof(*uart), GFP_KERNEL);
431 if (!uart) {
432 err = -EINVAL;
433 goto err_mem;
434 }
435
436 uart->usedma = 0;
437
438 uart->port.uartclk = 3250000 * 16;
439 uart->port.fifosize = TIMBUART_FIFO_SIZE;
440 uart->port.regshift = 2;
441 uart->port.iotype = UPIO_MEM;
442 uart->port.ops = &timbuart_ops;
443 uart->port.irq = 0;
444 uart->port.flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP;
445 uart->port.line = 0;
446 uart->port.dev = &dev->dev;
447
448 iomem = platform_get_resource(dev, IORESOURCE_MEM, 0);
449 if (!iomem) {
450 err = -ENOMEM;
451 goto err_register;
452 }
453 uart->port.mapbase = iomem->start;
454 uart->port.membase = NULL;
455
456 uart->port.irq = platform_get_irq(dev, 0);
457 if (uart->port.irq < 0) {
458 err = -EINVAL;
459 goto err_register;
460 }
461
462 tasklet_init(&uart->tasklet, timbuart_tasklet, (unsigned long)uart);
463
464 err = uart_register_driver(&timbuart_driver);
465 if (err)
466 goto err_register;
467
468 err = uart_add_one_port(&timbuart_driver, &uart->port);
469 if (err)
470 goto err_add_port;
471
472 platform_set_drvdata(dev, uart);
473
474 return 0;
475
476err_add_port:
477 uart_unregister_driver(&timbuart_driver);
478err_register:
479 kfree(uart);
480err_mem:
481 printk(KERN_ERR "timberdale: Failed to register Timberdale UART: %d\n",
482 err);
483
484 return err;
485}
486
487static int timbuart_remove(struct platform_device *dev)
488{
489 struct timbuart_port *uart = platform_get_drvdata(dev);
490
491 tasklet_kill(&uart->tasklet);
492 uart_remove_one_port(&timbuart_driver, &uart->port);
493 uart_unregister_driver(&timbuart_driver);
494 kfree(uart);
495
496 return 0;
497}
498
499static struct platform_driver timbuart_platform_driver = {
500 .driver = {
501 .name = "timb-uart",
502 .owner = THIS_MODULE,
503 },
504 .probe = timbuart_probe,
505 .remove = timbuart_remove,
506};
507
508/*--------------------------------------------------------------------------*/
509
510static int __init timbuart_init(void)
511{
512 return platform_driver_register(&timbuart_platform_driver);
513}
514
515static void __exit timbuart_exit(void)
516{
517 platform_driver_unregister(&timbuart_platform_driver);
518}
519
520module_init(timbuart_init);
521module_exit(timbuart_exit);
522
523MODULE_DESCRIPTION("Timberdale UART driver");
524MODULE_LICENSE("GPL v2");
525MODULE_ALIAS("platform:timb-uart");
526
diff --git a/drivers/serial/timbuart.h b/drivers/serial/timbuart.h
new file mode 100644
index 000000000000..7e566766bc43
--- /dev/null
+++ b/drivers/serial/timbuart.h
@@ -0,0 +1,58 @@
1/*
2 * timbuart.c timberdale FPGA GPIO driver
3 * Copyright (c) 2009 Intel Corporation
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19/* Supports:
20 * Timberdale FPGA UART
21 */
22
23#ifndef _TIMBUART_H
24#define _TIMBUART_H
25
26#define TIMBUART_FIFO_SIZE 2048
27
28#define TIMBUART_RXFIFO 0x08
29#define TIMBUART_TXFIFO 0x0c
30#define TIMBUART_IER 0x10
31#define TIMBUART_IPR 0x14
32#define TIMBUART_ISR 0x18
33#define TIMBUART_CTRL 0x1c
34#define TIMBUART_BAUDRATE 0x20
35
36#define TIMBUART_CTRL_RTS 0x01
37#define TIMBUART_CTRL_CTS 0x02
38#define TIMBUART_CTRL_FLSHTX 0x40
39#define TIMBUART_CTRL_FLSHRX 0x80
40
41#define TXBF 0x01
42#define TXBAE 0x02
43#define CTS_DELTA 0x04
44#define RXDP 0x08
45#define RXBAF 0x10
46#define RXBF 0x20
47#define RXTT 0x40
48#define RXBNAE 0x80
49#define TXBE 0x100
50
51#define RXFLAGS (RXDP | RXBAF | RXBF | RXTT | RXBNAE)
52#define TXFLAGS (TXBF | TXBAE)
53
54#define TIMBUART_MAJOR 204
55#define TIMBUART_MINOR 192
56
57#endif /* _TIMBUART_H */
58
diff --git a/drivers/sh/intc.c b/drivers/sh/intc.c
index 12d13d99b6f0..d687a9b93d03 100644
--- a/drivers/sh/intc.c
+++ b/drivers/sh/intc.c
@@ -24,6 +24,7 @@
24#include <linux/sh_intc.h> 24#include <linux/sh_intc.h>
25#include <linux/sysdev.h> 25#include <linux/sysdev.h>
26#include <linux/list.h> 26#include <linux/list.h>
27#include <linux/topology.h>
27 28
28#define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \ 29#define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \
29 ((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \ 30 ((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \
@@ -770,11 +771,19 @@ void __init register_intc_controller(struct intc_desc *desc)
770 /* register the vectors one by one */ 771 /* register the vectors one by one */
771 for (i = 0; i < desc->nr_vectors; i++) { 772 for (i = 0; i < desc->nr_vectors; i++) {
772 struct intc_vect *vect = desc->vectors + i; 773 struct intc_vect *vect = desc->vectors + i;
774 unsigned int irq = evt2irq(vect->vect);
775 struct irq_desc *irq_desc;
773 776
774 if (!vect->enum_id) 777 if (!vect->enum_id)
775 continue; 778 continue;
776 779
777 intc_register_irq(desc, d, vect->enum_id, evt2irq(vect->vect)); 780 irq_desc = irq_to_desc_alloc_node(irq, numa_node_id());
781 if (unlikely(!irq_desc)) {
782 printk(KERN_INFO "can not get irq_desc for %d\n", irq);
783 continue;
784 }
785
786 intc_register_irq(desc, d, vect->enum_id, irq);
778 } 787 }
779} 788}
780 789
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 7a1164dd1d37..ddeb69192537 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -16,7 +16,8 @@
16 * v0.9 - thorough cleaning, URBification, almost a rewrite 16 * v0.9 - thorough cleaning, URBification, almost a rewrite
17 * v0.10 - some more cleanups 17 * v0.10 - some more cleanups
18 * v0.11 - fixed flow control, read error doesn't stop reads 18 * v0.11 - fixed flow control, read error doesn't stop reads
19 * v0.12 - added TIOCM ioctls, added break handling, made struct acm kmalloced 19 * v0.12 - added TIOCM ioctls, added break handling, made struct acm
20 * kmalloced
20 * v0.13 - added termios, added hangup 21 * v0.13 - added termios, added hangup
21 * v0.14 - sized down struct acm 22 * v0.14 - sized down struct acm
22 * v0.15 - fixed flow control again - characters could be lost 23 * v0.15 - fixed flow control again - characters could be lost
@@ -62,7 +63,7 @@
62#include <linux/tty_flip.h> 63#include <linux/tty_flip.h>
63#include <linux/module.h> 64#include <linux/module.h>
64#include <linux/mutex.h> 65#include <linux/mutex.h>
65#include <asm/uaccess.h> 66#include <linux/uaccess.h>
66#include <linux/usb.h> 67#include <linux/usb.h>
67#include <linux/usb/cdc.h> 68#include <linux/usb/cdc.h>
68#include <asm/byteorder.h> 69#include <asm/byteorder.h>
@@ -87,7 +88,10 @@ static struct acm *acm_table[ACM_TTY_MINORS];
87 88
88static DEFINE_MUTEX(open_mutex); 89static DEFINE_MUTEX(open_mutex);
89 90
90#define ACM_READY(acm) (acm && acm->dev && acm->used) 91#define ACM_READY(acm) (acm && acm->dev && acm->port.count)
92
93static const struct tty_port_operations acm_port_ops = {
94};
91 95
92#ifdef VERBOSE_DEBUG 96#ifdef VERBOSE_DEBUG
93#define verbose 1 97#define verbose 1
@@ -99,13 +103,15 @@ static DEFINE_MUTEX(open_mutex);
99 * Functions for ACM control messages. 103 * Functions for ACM control messages.
100 */ 104 */
101 105
102static int acm_ctrl_msg(struct acm *acm, int request, int value, void *buf, int len) 106static int acm_ctrl_msg(struct acm *acm, int request, int value,
107 void *buf, int len)
103{ 108{
104 int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0), 109 int retval = usb_control_msg(acm->dev, usb_sndctrlpipe(acm->dev, 0),
105 request, USB_RT_ACM, value, 110 request, USB_RT_ACM, value,
106 acm->control->altsetting[0].desc.bInterfaceNumber, 111 acm->control->altsetting[0].desc.bInterfaceNumber,
107 buf, len, 5000); 112 buf, len, 5000);
108 dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d", request, value, len, retval); 113 dbg("acm_control_msg: rq: 0x%02x val: %#x len: %#x result: %d",
114 request, value, len, retval);
109 return retval < 0 ? retval : 0; 115 return retval < 0 ? retval : 0;
110} 116}
111 117
@@ -150,9 +156,8 @@ static int acm_wb_is_avail(struct acm *acm)
150 156
151 n = ACM_NW; 157 n = ACM_NW;
152 spin_lock_irqsave(&acm->write_lock, flags); 158 spin_lock_irqsave(&acm->write_lock, flags);
153 for (i = 0; i < ACM_NW; i++) { 159 for (i = 0; i < ACM_NW; i++)
154 n -= acm->wb[i].use; 160 n -= acm->wb[i].use;
155 }
156 spin_unlock_irqrestore(&acm->write_lock, flags); 161 spin_unlock_irqrestore(&acm->write_lock, flags);
157 return n; 162 return n;
158} 163}
@@ -183,7 +188,8 @@ static int acm_start_wb(struct acm *acm, struct acm_wb *wb)
183 wb->urb->transfer_buffer_length = wb->len; 188 wb->urb->transfer_buffer_length = wb->len;
184 wb->urb->dev = acm->dev; 189 wb->urb->dev = acm->dev;
185 190
186 if ((rc = usb_submit_urb(wb->urb, GFP_ATOMIC)) < 0) { 191 rc = usb_submit_urb(wb->urb, GFP_ATOMIC);
192 if (rc < 0) {
187 dbg("usb_submit_urb(write bulk) failed: %d", rc); 193 dbg("usb_submit_urb(write bulk) failed: %d", rc);
188 acm_write_done(acm, wb); 194 acm_write_done(acm, wb);
189 } 195 }
@@ -262,6 +268,7 @@ static void acm_ctrl_irq(struct urb *urb)
262{ 268{
263 struct acm *acm = urb->context; 269 struct acm *acm = urb->context;
264 struct usb_cdc_notification *dr = urb->transfer_buffer; 270 struct usb_cdc_notification *dr = urb->transfer_buffer;
271 struct tty_struct *tty;
265 unsigned char *data; 272 unsigned char *data;
266 int newctrl; 273 int newctrl;
267 int retval; 274 int retval;
@@ -287,40 +294,45 @@ static void acm_ctrl_irq(struct urb *urb)
287 294
288 data = (unsigned char *)(dr + 1); 295 data = (unsigned char *)(dr + 1);
289 switch (dr->bNotificationType) { 296 switch (dr->bNotificationType) {
297 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
298 dbg("%s network", dr->wValue ?
299 "connected to" : "disconnected from");
300 break;
290 301
291 case USB_CDC_NOTIFY_NETWORK_CONNECTION: 302 case USB_CDC_NOTIFY_SERIAL_STATE:
292 303 tty = tty_port_tty_get(&acm->port);
293 dbg("%s network", dr->wValue ? "connected to" : "disconnected from"); 304 newctrl = get_unaligned_le16(data);
294 break;
295
296 case USB_CDC_NOTIFY_SERIAL_STATE:
297
298 newctrl = get_unaligned_le16(data);
299 305
300 if (acm->tty && !acm->clocal && (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) { 306 if (tty) {
307 if (!acm->clocal &&
308 (acm->ctrlin & ~newctrl & ACM_CTRL_DCD)) {
301 dbg("calling hangup"); 309 dbg("calling hangup");
302 tty_hangup(acm->tty); 310 tty_hangup(tty);
303 } 311 }
312 tty_kref_put(tty);
313 }
304 314
305 acm->ctrlin = newctrl; 315 acm->ctrlin = newctrl;
306
307 dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c",
308 acm->ctrlin & ACM_CTRL_DCD ? '+' : '-', acm->ctrlin & ACM_CTRL_DSR ? '+' : '-',
309 acm->ctrlin & ACM_CTRL_BRK ? '+' : '-', acm->ctrlin & ACM_CTRL_RI ? '+' : '-',
310 acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-', acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-',
311 acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-');
312 316
317 dbg("input control lines: dcd%c dsr%c break%c ring%c framing%c parity%c overrun%c",
318 acm->ctrlin & ACM_CTRL_DCD ? '+' : '-',
319 acm->ctrlin & ACM_CTRL_DSR ? '+' : '-',
320 acm->ctrlin & ACM_CTRL_BRK ? '+' : '-',
321 acm->ctrlin & ACM_CTRL_RI ? '+' : '-',
322 acm->ctrlin & ACM_CTRL_FRAMING ? '+' : '-',
323 acm->ctrlin & ACM_CTRL_PARITY ? '+' : '-',
324 acm->ctrlin & ACM_CTRL_OVERRUN ? '+' : '-');
313 break; 325 break;
314 326
315 default: 327 default:
316 dbg("unknown notification %d received: index %d len %d data0 %d data1 %d", 328 dbg("unknown notification %d received: index %d len %d data0 %d data1 %d",
317 dr->bNotificationType, dr->wIndex, 329 dr->bNotificationType, dr->wIndex,
318 dr->wLength, data[0], data[1]); 330 dr->wLength, data[0], data[1]);
319 break; 331 break;
320 } 332 }
321exit: 333exit:
322 usb_mark_last_busy(acm->dev); 334 usb_mark_last_busy(acm->dev);
323 retval = usb_submit_urb (urb, GFP_ATOMIC); 335 retval = usb_submit_urb(urb, GFP_ATOMIC);
324 if (retval) 336 if (retval)
325 dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with " 337 dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with "
326 "result %d", __func__, retval); 338 "result %d", __func__, retval);
@@ -371,15 +383,14 @@ static void acm_rx_tasklet(unsigned long _acm)
371{ 383{
372 struct acm *acm = (void *)_acm; 384 struct acm *acm = (void *)_acm;
373 struct acm_rb *buf; 385 struct acm_rb *buf;
374 struct tty_struct *tty = acm->tty; 386 struct tty_struct *tty;
375 struct acm_ru *rcv; 387 struct acm_ru *rcv;
376 unsigned long flags; 388 unsigned long flags;
377 unsigned char throttled; 389 unsigned char throttled;
378 390
379 dbg("Entering acm_rx_tasklet"); 391 dbg("Entering acm_rx_tasklet");
380 392
381 if (!ACM_READY(acm)) 393 if (!ACM_READY(acm)) {
382 {
383 dbg("acm_rx_tasklet: ACM not ready"); 394 dbg("acm_rx_tasklet: ACM not ready");
384 return; 395 return;
385 } 396 }
@@ -387,12 +398,13 @@ static void acm_rx_tasklet(unsigned long _acm)
387 spin_lock_irqsave(&acm->throttle_lock, flags); 398 spin_lock_irqsave(&acm->throttle_lock, flags);
388 throttled = acm->throttle; 399 throttled = acm->throttle;
389 spin_unlock_irqrestore(&acm->throttle_lock, flags); 400 spin_unlock_irqrestore(&acm->throttle_lock, flags);
390 if (throttled) 401 if (throttled) {
391 {
392 dbg("acm_rx_tasklet: throttled"); 402 dbg("acm_rx_tasklet: throttled");
393 return; 403 return;
394 } 404 }
395 405
406 tty = tty_port_tty_get(&acm->port);
407
396next_buffer: 408next_buffer:
397 spin_lock_irqsave(&acm->read_lock, flags); 409 spin_lock_irqsave(&acm->read_lock, flags);
398 if (list_empty(&acm->filled_read_bufs)) { 410 if (list_empty(&acm->filled_read_bufs)) {
@@ -406,20 +418,22 @@ next_buffer:
406 418
407 dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size); 419 dbg("acm_rx_tasklet: procesing buf 0x%p, size = %d", buf, buf->size);
408 420
409 tty_buffer_request_room(tty, buf->size); 421 if (tty) {
410 spin_lock_irqsave(&acm->throttle_lock, flags); 422 spin_lock_irqsave(&acm->throttle_lock, flags);
411 throttled = acm->throttle; 423 throttled = acm->throttle;
412 spin_unlock_irqrestore(&acm->throttle_lock, flags); 424 spin_unlock_irqrestore(&acm->throttle_lock, flags);
413 if (!throttled) 425 if (!throttled) {
414 tty_insert_flip_string(tty, buf->base, buf->size); 426 tty_buffer_request_room(tty, buf->size);
415 tty_flip_buffer_push(tty); 427 tty_insert_flip_string(tty, buf->base, buf->size);
416 428 tty_flip_buffer_push(tty);
417 if (throttled) { 429 } else {
418 dbg("Throttling noticed"); 430 tty_kref_put(tty);
419 spin_lock_irqsave(&acm->read_lock, flags); 431 dbg("Throttling noticed");
420 list_add(&buf->list, &acm->filled_read_bufs); 432 spin_lock_irqsave(&acm->read_lock, flags);
421 spin_unlock_irqrestore(&acm->read_lock, flags); 433 list_add(&buf->list, &acm->filled_read_bufs);
422 return; 434 spin_unlock_irqrestore(&acm->read_lock, flags);
435 return;
436 }
423 } 437 }
424 438
425 spin_lock_irqsave(&acm->read_lock, flags); 439 spin_lock_irqsave(&acm->read_lock, flags);
@@ -428,6 +442,8 @@ next_buffer:
428 goto next_buffer; 442 goto next_buffer;
429 443
430urbs: 444urbs:
445 tty_kref_put(tty);
446
431 while (!list_empty(&acm->spare_read_bufs)) { 447 while (!list_empty(&acm->spare_read_bufs)) {
432 spin_lock_irqsave(&acm->read_lock, flags); 448 spin_lock_irqsave(&acm->read_lock, flags);
433 if (list_empty(&acm->spare_read_urbs)) { 449 if (list_empty(&acm->spare_read_urbs)) {
@@ -454,10 +470,11 @@ urbs:
454 rcv->urb->transfer_dma = buf->dma; 470 rcv->urb->transfer_dma = buf->dma;
455 rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 471 rcv->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
456 472
457 /* This shouldn't kill the driver as unsuccessful URBs are returned to the 473 /* This shouldn't kill the driver as unsuccessful URBs are
458 free-urbs-pool and resubmited ASAP */ 474 returned to the free-urbs-pool and resubmited ASAP */
459 spin_lock_irqsave(&acm->read_lock, flags); 475 spin_lock_irqsave(&acm->read_lock, flags);
460 if (acm->susp_count || usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) { 476 if (acm->susp_count ||
477 usb_submit_urb(rcv->urb, GFP_ATOMIC) < 0) {
461 list_add(&buf->list, &acm->spare_read_bufs); 478 list_add(&buf->list, &acm->spare_read_bufs);
462 list_add(&rcv->list, &acm->spare_read_urbs); 479 list_add(&rcv->list, &acm->spare_read_urbs);
463 acm->processing = 0; 480 acm->processing = 0;
@@ -499,11 +516,14 @@ static void acm_write_bulk(struct urb *urb)
499static void acm_softint(struct work_struct *work) 516static void acm_softint(struct work_struct *work)
500{ 517{
501 struct acm *acm = container_of(work, struct acm, work); 518 struct acm *acm = container_of(work, struct acm, work);
519 struct tty_struct *tty;
502 520
503 dev_vdbg(&acm->data->dev, "tx work\n"); 521 dev_vdbg(&acm->data->dev, "tx work\n");
504 if (!ACM_READY(acm)) 522 if (!ACM_READY(acm))
505 return; 523 return;
506 tty_wakeup(acm->tty); 524 tty = tty_port_tty_get(&acm->port);
525 tty_wakeup(tty);
526 tty_kref_put(tty);
507} 527}
508 528
509static void acm_waker(struct work_struct *waker) 529static void acm_waker(struct work_struct *waker)
@@ -543,8 +563,9 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
543 rv = 0; 563 rv = 0;
544 564
545 set_bit(TTY_NO_WRITE_SPLIT, &tty->flags); 565 set_bit(TTY_NO_WRITE_SPLIT, &tty->flags);
566
546 tty->driver_data = acm; 567 tty->driver_data = acm;
547 acm->tty = tty; 568 tty_port_tty_set(&acm->port, tty);
548 569
549 if (usb_autopm_get_interface(acm->control) < 0) 570 if (usb_autopm_get_interface(acm->control) < 0)
550 goto early_bail; 571 goto early_bail;
@@ -552,11 +573,10 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
552 acm->control->needs_remote_wakeup = 1; 573 acm->control->needs_remote_wakeup = 1;
553 574
554 mutex_lock(&acm->mutex); 575 mutex_lock(&acm->mutex);
555 if (acm->used++) { 576 if (acm->port.count++) {
556 usb_autopm_put_interface(acm->control); 577 usb_autopm_put_interface(acm->control);
557 goto done; 578 goto done;
558 } 579 }
559
560 580
561 acm->ctrlurb->dev = acm->dev; 581 acm->ctrlurb->dev = acm->dev;
562 if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) { 582 if (usb_submit_urb(acm->ctrlurb, GFP_KERNEL)) {
@@ -567,22 +587,22 @@ static int acm_tty_open(struct tty_struct *tty, struct file *filp)
567 if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) && 587 if (0 > acm_set_control(acm, acm->ctrlout = ACM_CTRL_DTR | ACM_CTRL_RTS) &&
568 (acm->ctrl_caps & USB_CDC_CAP_LINE)) 588 (acm->ctrl_caps & USB_CDC_CAP_LINE))
569 goto full_bailout; 589 goto full_bailout;
590
570 usb_autopm_put_interface(acm->control); 591 usb_autopm_put_interface(acm->control);
571 592
572 INIT_LIST_HEAD(&acm->spare_read_urbs); 593 INIT_LIST_HEAD(&acm->spare_read_urbs);
573 INIT_LIST_HEAD(&acm->spare_read_bufs); 594 INIT_LIST_HEAD(&acm->spare_read_bufs);
574 INIT_LIST_HEAD(&acm->filled_read_bufs); 595 INIT_LIST_HEAD(&acm->filled_read_bufs);
575 for (i = 0; i < acm->rx_buflimit; i++) { 596
597 for (i = 0; i < acm->rx_buflimit; i++)
576 list_add(&(acm->ru[i].list), &acm->spare_read_urbs); 598 list_add(&(acm->ru[i].list), &acm->spare_read_urbs);
577 } 599 for (i = 0; i < acm->rx_buflimit; i++)
578 for (i = 0; i < acm->rx_buflimit; i++) {
579 list_add(&(acm->rb[i].list), &acm->spare_read_bufs); 600 list_add(&(acm->rb[i].list), &acm->spare_read_bufs);
580 }
581 601
582 acm->throttle = 0; 602 acm->throttle = 0;
583 603
584 tasklet_schedule(&acm->urb_task); 604 tasklet_schedule(&acm->urb_task);
585 605 rv = tty_port_block_til_ready(&acm->port, tty, filp);
586done: 606done:
587 mutex_unlock(&acm->mutex); 607 mutex_unlock(&acm->mutex);
588err_out: 608err_out:
@@ -593,16 +613,17 @@ full_bailout:
593 usb_kill_urb(acm->ctrlurb); 613 usb_kill_urb(acm->ctrlurb);
594bail_out: 614bail_out:
595 usb_autopm_put_interface(acm->control); 615 usb_autopm_put_interface(acm->control);
596 acm->used--; 616 acm->port.count--;
597 mutex_unlock(&acm->mutex); 617 mutex_unlock(&acm->mutex);
598early_bail: 618early_bail:
599 mutex_unlock(&open_mutex); 619 mutex_unlock(&open_mutex);
620 tty_port_tty_set(&acm->port, NULL);
600 return -EIO; 621 return -EIO;
601} 622}
602 623
603static void acm_tty_unregister(struct acm *acm) 624static void acm_tty_unregister(struct acm *acm)
604{ 625{
605 int i,nr; 626 int i, nr;
606 627
607 nr = acm->rx_buflimit; 628 nr = acm->rx_buflimit;
608 tty_unregister_device(acm_tty_driver, acm->minor); 629 tty_unregister_device(acm_tty_driver, acm->minor);
@@ -619,41 +640,56 @@ static void acm_tty_unregister(struct acm *acm)
619 640
620static int acm_tty_chars_in_buffer(struct tty_struct *tty); 641static int acm_tty_chars_in_buffer(struct tty_struct *tty);
621 642
643static void acm_port_down(struct acm *acm, int drain)
644{
645 int i, nr = acm->rx_buflimit;
646 mutex_lock(&open_mutex);
647 if (acm->dev) {
648 usb_autopm_get_interface(acm->control);
649 acm_set_control(acm, acm->ctrlout = 0);
650 /* try letting the last writes drain naturally */
651 if (drain) {
652 wait_event_interruptible_timeout(acm->drain_wait,
653 (ACM_NW == acm_wb_is_avail(acm)) || !acm->dev,
654 ACM_CLOSE_TIMEOUT * HZ);
655 }
656 usb_kill_urb(acm->ctrlurb);
657 for (i = 0; i < ACM_NW; i++)
658 usb_kill_urb(acm->wb[i].urb);
659 for (i = 0; i < nr; i++)
660 usb_kill_urb(acm->ru[i].urb);
661 acm->control->needs_remote_wakeup = 0;
662 usb_autopm_put_interface(acm->control);
663 }
664 mutex_unlock(&open_mutex);
665}
666
667static void acm_tty_hangup(struct tty_struct *tty)
668{
669 struct acm *acm = tty->driver_data;
670 tty_port_hangup(&acm->port);
671 acm_port_down(acm, 0);
672}
673
622static void acm_tty_close(struct tty_struct *tty, struct file *filp) 674static void acm_tty_close(struct tty_struct *tty, struct file *filp)
623{ 675{
624 struct acm *acm = tty->driver_data; 676 struct acm *acm = tty->driver_data;
625 int i,nr;
626 677
627 if (!acm || !acm->used) 678 /* Perform the closing process and see if we need to do the hardware
679 shutdown */
680 if (tty_port_close_start(&acm->port, tty, filp) == 0)
628 return; 681 return;
629 682 acm_port_down(acm, 0);
630 nr = acm->rx_buflimit; 683 tty_port_close_end(&acm->port, tty);
631 mutex_lock(&open_mutex); 684 mutex_lock(&open_mutex);
632 if (!--acm->used) { 685 tty_port_tty_set(&acm->port, NULL);
633 if (acm->dev) { 686 if (!acm->dev)
634 usb_autopm_get_interface(acm->control); 687 acm_tty_unregister(acm);
635 acm_set_control(acm, acm->ctrlout = 0);
636
637 /* try letting the last writes drain naturally */
638 wait_event_interruptible_timeout(acm->drain_wait,
639 (ACM_NW == acm_wb_is_avail(acm))
640 || !acm->dev,
641 ACM_CLOSE_TIMEOUT * HZ);
642
643 usb_kill_urb(acm->ctrlurb);
644 for (i = 0; i < ACM_NW; i++)
645 usb_kill_urb(acm->wb[i].urb);
646 for (i = 0; i < nr; i++)
647 usb_kill_urb(acm->ru[i].urb);
648 acm->control->needs_remote_wakeup = 0;
649 usb_autopm_put_interface(acm->control);
650 } else
651 acm_tty_unregister(acm);
652 }
653 mutex_unlock(&open_mutex); 688 mutex_unlock(&open_mutex);
654} 689}
655 690
656static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count) 691static int acm_tty_write(struct tty_struct *tty,
692 const unsigned char *buf, int count)
657{ 693{
658 struct acm *acm = tty->driver_data; 694 struct acm *acm = tty->driver_data;
659 int stat; 695 int stat;
@@ -669,7 +705,8 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c
669 return 0; 705 return 0;
670 706
671 spin_lock_irqsave(&acm->write_lock, flags); 707 spin_lock_irqsave(&acm->write_lock, flags);
672 if ((wbn = acm_wb_alloc(acm)) < 0) { 708 wbn = acm_wb_alloc(acm);
709 if (wbn < 0) {
673 spin_unlock_irqrestore(&acm->write_lock, flags); 710 spin_unlock_irqrestore(&acm->write_lock, flags);
674 return 0; 711 return 0;
675 } 712 }
@@ -681,7 +718,8 @@ static int acm_tty_write(struct tty_struct *tty, const unsigned char *buf, int c
681 wb->len = count; 718 wb->len = count;
682 spin_unlock_irqrestore(&acm->write_lock, flags); 719 spin_unlock_irqrestore(&acm->write_lock, flags);
683 720
684 if ((stat = acm_write_start(acm, wbn)) < 0) 721 stat = acm_write_start(acm, wbn);
722 if (stat < 0)
685 return stat; 723 return stat;
686 return count; 724 return count;
687} 725}
@@ -767,8 +805,10 @@ static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file,
767 return -EINVAL; 805 return -EINVAL;
768 806
769 newctrl = acm->ctrlout; 807 newctrl = acm->ctrlout;
770 set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (set & TIOCM_RTS ? ACM_CTRL_RTS : 0); 808 set = (set & TIOCM_DTR ? ACM_CTRL_DTR : 0) |
771 clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) | (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0); 809 (set & TIOCM_RTS ? ACM_CTRL_RTS : 0);
810 clear = (clear & TIOCM_DTR ? ACM_CTRL_DTR : 0) |
811 (clear & TIOCM_RTS ? ACM_CTRL_RTS : 0);
772 812
773 newctrl = (newctrl & ~clear) | set; 813 newctrl = (newctrl & ~clear) | set;
774 814
@@ -777,7 +817,8 @@ static int acm_tty_tiocmset(struct tty_struct *tty, struct file *file,
777 return acm_set_control(acm, acm->ctrlout = newctrl); 817 return acm_set_control(acm, acm->ctrlout = newctrl);
778} 818}
779 819
780static int acm_tty_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) 820static int acm_tty_ioctl(struct tty_struct *tty, struct file *file,
821 unsigned int cmd, unsigned long arg)
781{ 822{
782 struct acm *acm = tty->driver_data; 823 struct acm *acm = tty->driver_data;
783 824
@@ -799,7 +840,8 @@ static const __u8 acm_tty_size[] = {
799 5, 6, 7, 8 840 5, 6, 7, 8
800}; 841};
801 842
802static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios_old) 843static void acm_tty_set_termios(struct tty_struct *tty,
844 struct ktermios *termios_old)
803{ 845{
804 struct acm *acm = tty->driver_data; 846 struct acm *acm = tty->driver_data;
805 struct ktermios *termios = tty->termios; 847 struct ktermios *termios = tty->termios;
@@ -809,19 +851,23 @@ static void acm_tty_set_termios(struct tty_struct *tty, struct ktermios *termios
809 if (!ACM_READY(acm)) 851 if (!ACM_READY(acm))
810 return; 852 return;
811 853
854 /* FIXME: Needs to support the tty_baud interface */
855 /* FIXME: Broken on sparc */
812 newline.dwDTERate = cpu_to_le32p(acm_tty_speed + 856 newline.dwDTERate = cpu_to_le32p(acm_tty_speed +
813 (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0)); 857 (termios->c_cflag & CBAUD & ~CBAUDEX) + (termios->c_cflag & CBAUDEX ? 15 : 0));
814 newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0; 858 newline.bCharFormat = termios->c_cflag & CSTOPB ? 2 : 0;
815 newline.bParityType = termios->c_cflag & PARENB ? 859 newline.bParityType = termios->c_cflag & PARENB ?
816 (termios->c_cflag & PARODD ? 1 : 2) + (termios->c_cflag & CMSPAR ? 2 : 0) : 0; 860 (termios->c_cflag & PARODD ? 1 : 2) +
861 (termios->c_cflag & CMSPAR ? 2 : 0) : 0;
817 newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4]; 862 newline.bDataBits = acm_tty_size[(termios->c_cflag & CSIZE) >> 4];
818 863 /* FIXME: Needs to clear unsupported bits in the termios */
819 acm->clocal = ((termios->c_cflag & CLOCAL) != 0); 864 acm->clocal = ((termios->c_cflag & CLOCAL) != 0);
820 865
821 if (!newline.dwDTERate) { 866 if (!newline.dwDTERate) {
822 newline.dwDTERate = acm->line.dwDTERate; 867 newline.dwDTERate = acm->line.dwDTERate;
823 newctrl &= ~ACM_CTRL_DTR; 868 newctrl &= ~ACM_CTRL_DTR;
824 } else newctrl |= ACM_CTRL_DTR; 869 } else
870 newctrl |= ACM_CTRL_DTR;
825 871
826 if (newctrl != acm->ctrlout) 872 if (newctrl != acm->ctrlout)
827 acm_set_control(acm, acm->ctrlout = newctrl); 873 acm_set_control(acm, acm->ctrlout = newctrl);
@@ -846,9 +892,8 @@ static void acm_write_buffers_free(struct acm *acm)
846 struct acm_wb *wb; 892 struct acm_wb *wb;
847 struct usb_device *usb_dev = interface_to_usbdev(acm->control); 893 struct usb_device *usb_dev = interface_to_usbdev(acm->control);
848 894
849 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { 895 for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++)
850 usb_buffer_free(usb_dev, acm->writesize, wb->buf, wb->dmah); 896 usb_buffer_free(usb_dev, acm->writesize, wb->buf, wb->dmah);
851 }
852} 897}
853 898
854static void acm_read_buffers_free(struct acm *acm) 899static void acm_read_buffers_free(struct acm *acm)
@@ -857,7 +902,8 @@ static void acm_read_buffers_free(struct acm *acm)
857 int i, n = acm->rx_buflimit; 902 int i, n = acm->rx_buflimit;
858 903
859 for (i = 0; i < n; i++) 904 for (i = 0; i < n; i++)
860 usb_buffer_free(usb_dev, acm->readsize, acm->rb[i].base, acm->rb[i].dma); 905 usb_buffer_free(usb_dev, acm->readsize,
906 acm->rb[i].base, acm->rb[i].dma);
861} 907}
862 908
863/* Little helper: write buffers allocate */ 909/* Little helper: write buffers allocate */
@@ -882,8 +928,8 @@ static int acm_write_buffers_alloc(struct acm *acm)
882 return 0; 928 return 0;
883} 929}
884 930
885static int acm_probe (struct usb_interface *intf, 931static int acm_probe(struct usb_interface *intf,
886 const struct usb_device_id *id) 932 const struct usb_device_id *id)
887{ 933{
888 struct usb_cdc_union_desc *union_header = NULL; 934 struct usb_cdc_union_desc *union_header = NULL;
889 struct usb_cdc_country_functional_desc *cfd = NULL; 935 struct usb_cdc_country_functional_desc *cfd = NULL;
@@ -897,7 +943,7 @@ static int acm_probe (struct usb_interface *intf,
897 struct usb_device *usb_dev = interface_to_usbdev(intf); 943 struct usb_device *usb_dev = interface_to_usbdev(intf);
898 struct acm *acm; 944 struct acm *acm;
899 int minor; 945 int minor;
900 int ctrlsize,readsize; 946 int ctrlsize, readsize;
901 u8 *buf; 947 u8 *buf;
902 u8 ac_management_function = 0; 948 u8 ac_management_function = 0;
903 u8 call_management_function = 0; 949 u8 call_management_function = 0;
@@ -917,7 +963,7 @@ static int acm_probe (struct usb_interface *intf,
917 control_interface = usb_ifnum_to_if(usb_dev, 0); 963 control_interface = usb_ifnum_to_if(usb_dev, 0);
918 goto skip_normal_probe; 964 goto skip_normal_probe;
919 } 965 }
920 966
921 /* normal probing*/ 967 /* normal probing*/
922 if (!buffer) { 968 if (!buffer) {
923 dev_err(&intf->dev, "Weird descriptor references\n"); 969 dev_err(&intf->dev, "Weird descriptor references\n");
@@ -925,8 +971,10 @@ static int acm_probe (struct usb_interface *intf,
925 } 971 }
926 972
927 if (!buflen) { 973 if (!buflen) {
928 if (intf->cur_altsetting->endpoint->extralen && intf->cur_altsetting->endpoint->extra) { 974 if (intf->cur_altsetting->endpoint->extralen &&
929 dev_dbg(&intf->dev,"Seeking extra descriptors on endpoint\n"); 975 intf->cur_altsetting->endpoint->extra) {
976 dev_dbg(&intf->dev,
977 "Seeking extra descriptors on endpoint\n");
930 buflen = intf->cur_altsetting->endpoint->extralen; 978 buflen = intf->cur_altsetting->endpoint->extralen;
931 buffer = intf->cur_altsetting->endpoint->extra; 979 buffer = intf->cur_altsetting->endpoint->extra;
932 } else { 980 } else {
@@ -937,47 +985,43 @@ static int acm_probe (struct usb_interface *intf,
937 } 985 }
938 986
939 while (buflen > 0) { 987 while (buflen > 0) {
940 if (buffer [1] != USB_DT_CS_INTERFACE) { 988 if (buffer[1] != USB_DT_CS_INTERFACE) {
941 dev_err(&intf->dev, "skipping garbage\n"); 989 dev_err(&intf->dev, "skipping garbage\n");
942 goto next_desc; 990 goto next_desc;
943 } 991 }
944 992
945 switch (buffer [2]) { 993 switch (buffer[2]) {
946 case USB_CDC_UNION_TYPE: /* we've found it */ 994 case USB_CDC_UNION_TYPE: /* we've found it */
947 if (union_header) { 995 if (union_header) {
948 dev_err(&intf->dev, "More than one " 996 dev_err(&intf->dev, "More than one "
949 "union descriptor, " 997 "union descriptor, skipping ...\n");
950 "skipping ...\n"); 998 goto next_desc;
951 goto next_desc;
952 }
953 union_header = (struct usb_cdc_union_desc *)
954 buffer;
955 break;
956 case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/
957 cfd = (struct usb_cdc_country_functional_desc *)buffer;
958 break;
959 case USB_CDC_HEADER_TYPE: /* maybe check version */
960 break; /* for now we ignore it */
961 case USB_CDC_ACM_TYPE:
962 ac_management_function = buffer[3];
963 break;
964 case USB_CDC_CALL_MANAGEMENT_TYPE:
965 call_management_function = buffer[3];
966 call_interface_num = buffer[4];
967 if ((call_management_function & 3) != 3)
968 dev_err(&intf->dev, "This device "
969 "cannot do calls on its own. "
970 "It is no modem.\n");
971 break;
972 default:
973 /* there are LOTS more CDC descriptors that
974 * could legitimately be found here.
975 */
976 dev_dbg(&intf->dev, "Ignoring descriptor: "
977 "type %02x, length %d\n",
978 buffer[2], buffer[0]);
979 break;
980 } 999 }
1000 union_header = (struct usb_cdc_union_desc *)buffer;
1001 break;
1002 case USB_CDC_COUNTRY_TYPE: /* export through sysfs*/
1003 cfd = (struct usb_cdc_country_functional_desc *)buffer;
1004 break;
1005 case USB_CDC_HEADER_TYPE: /* maybe check version */
1006 break; /* for now we ignore it */
1007 case USB_CDC_ACM_TYPE:
1008 ac_management_function = buffer[3];
1009 break;
1010 case USB_CDC_CALL_MANAGEMENT_TYPE:
1011 call_management_function = buffer[3];
1012 call_interface_num = buffer[4];
1013 if ((call_management_function & 3) != 3)
1014 dev_err(&intf->dev, "This device cannot do calls on its own. It is not a modem.\n");
1015 break;
1016 default:
1017 /* there are LOTS more CDC descriptors that
1018 * could legitimately be found here.
1019 */
1020 dev_dbg(&intf->dev, "Ignoring descriptor: "
1021 "type %02x, length %d\n",
1022 buffer[2], buffer[0]);
1023 break;
1024 }
981next_desc: 1025next_desc:
982 buflen -= buffer[0]; 1026 buflen -= buffer[0];
983 buffer += buffer[0]; 1027 buffer += buffer[0];
@@ -985,33 +1029,36 @@ next_desc:
985 1029
986 if (!union_header) { 1030 if (!union_header) {
987 if (call_interface_num > 0) { 1031 if (call_interface_num > 0) {
988 dev_dbg(&intf->dev,"No union descriptor, using call management descriptor\n"); 1032 dev_dbg(&intf->dev, "No union descriptor, using call management descriptor\n");
989 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num)); 1033 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = call_interface_num));
990 control_interface = intf; 1034 control_interface = intf;
991 } else { 1035 } else {
992 dev_dbg(&intf->dev,"No union descriptor, giving up\n"); 1036 dev_dbg(&intf->dev,
1037 "No union descriptor, giving up\n");
993 return -ENODEV; 1038 return -ENODEV;
994 } 1039 }
995 } else { 1040 } else {
996 control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0); 1041 control_interface = usb_ifnum_to_if(usb_dev, union_header->bMasterInterface0);
997 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0)); 1042 data_interface = usb_ifnum_to_if(usb_dev, (data_interface_num = union_header->bSlaveInterface0));
998 if (!control_interface || !data_interface) { 1043 if (!control_interface || !data_interface) {
999 dev_dbg(&intf->dev,"no interfaces\n"); 1044 dev_dbg(&intf->dev, "no interfaces\n");
1000 return -ENODEV; 1045 return -ENODEV;
1001 } 1046 }
1002 } 1047 }
1003 1048
1004 if (data_interface_num != call_interface_num) 1049 if (data_interface_num != call_interface_num)
1005 dev_dbg(&intf->dev,"Separate call control interface. That is not fully supported.\n"); 1050 dev_dbg(&intf->dev, "Separate call control interface. That is not fully supported.\n");
1006 1051
1007skip_normal_probe: 1052skip_normal_probe:
1008 1053
1009 /*workaround for switched interfaces */ 1054 /*workaround for switched interfaces */
1010 if (data_interface->cur_altsetting->desc.bInterfaceClass != CDC_DATA_INTERFACE_TYPE) { 1055 if (data_interface->cur_altsetting->desc.bInterfaceClass
1011 if (control_interface->cur_altsetting->desc.bInterfaceClass == CDC_DATA_INTERFACE_TYPE) { 1056 != CDC_DATA_INTERFACE_TYPE) {
1057 if (control_interface->cur_altsetting->desc.bInterfaceClass
1058 == CDC_DATA_INTERFACE_TYPE) {
1012 struct usb_interface *t; 1059 struct usb_interface *t;
1013 dev_dbg(&intf->dev,"Your device has switched interfaces.\n"); 1060 dev_dbg(&intf->dev,
1014 1061 "Your device has switched interfaces.\n");
1015 t = control_interface; 1062 t = control_interface;
1016 control_interface = data_interface; 1063 control_interface = data_interface;
1017 data_interface = t; 1064 data_interface = t;
@@ -1023,9 +1070,9 @@ skip_normal_probe:
1023 /* Accept probe requests only for the control interface */ 1070 /* Accept probe requests only for the control interface */
1024 if (intf != control_interface) 1071 if (intf != control_interface)
1025 return -ENODEV; 1072 return -ENODEV;
1026 1073
1027 if (usb_interface_claimed(data_interface)) { /* valid in this context */ 1074 if (usb_interface_claimed(data_interface)) { /* valid in this context */
1028 dev_dbg(&intf->dev,"The data interface isn't available\n"); 1075 dev_dbg(&intf->dev, "The data interface isn't available\n");
1029 return -EBUSY; 1076 return -EBUSY;
1030 } 1077 }
1031 1078
@@ -1042,8 +1089,8 @@ skip_normal_probe:
1042 if (!usb_endpoint_dir_in(epread)) { 1089 if (!usb_endpoint_dir_in(epread)) {
1043 /* descriptors are swapped */ 1090 /* descriptors are swapped */
1044 struct usb_endpoint_descriptor *t; 1091 struct usb_endpoint_descriptor *t;
1045 dev_dbg(&intf->dev,"The data interface has switched endpoints\n"); 1092 dev_dbg(&intf->dev,
1046 1093 "The data interface has switched endpoints\n");
1047 t = epread; 1094 t = epread;
1048 epread = epwrite; 1095 epread = epwrite;
1049 epwrite = t; 1096 epwrite = t;
@@ -1056,13 +1103,15 @@ skip_normal_probe:
1056 return -ENODEV; 1103 return -ENODEV;
1057 } 1104 }
1058 1105
1059 if (!(acm = kzalloc(sizeof(struct acm), GFP_KERNEL))) { 1106 acm = kzalloc(sizeof(struct acm), GFP_KERNEL);
1107 if (acm == NULL) {
1060 dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n"); 1108 dev_dbg(&intf->dev, "out of memory (acm kzalloc)\n");
1061 goto alloc_fail; 1109 goto alloc_fail;
1062 } 1110 }
1063 1111
1064 ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize); 1112 ctrlsize = le16_to_cpu(epctrl->wMaxPacketSize);
1065 readsize = le16_to_cpu(epread->wMaxPacketSize)* ( quirks == SINGLE_RX_URB ? 1 : 2); 1113 readsize = le16_to_cpu(epread->wMaxPacketSize) *
1114 (quirks == SINGLE_RX_URB ? 1 : 2);
1066 acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20; 1115 acm->writesize = le16_to_cpu(epwrite->wMaxPacketSize) * 20;
1067 acm->control = control_interface; 1116 acm->control = control_interface;
1068 acm->data = data_interface; 1117 acm->data = data_interface;
@@ -1082,6 +1131,8 @@ skip_normal_probe:
1082 spin_lock_init(&acm->read_lock); 1131 spin_lock_init(&acm->read_lock);
1083 mutex_init(&acm->mutex); 1132 mutex_init(&acm->mutex);
1084 acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress); 1133 acm->rx_endpoint = usb_rcvbulkpipe(usb_dev, epread->bEndpointAddress);
1134 tty_port_init(&acm->port);
1135 acm->port.ops = &acm_port_ops;
1085 1136
1086 buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma); 1137 buf = usb_buffer_alloc(usb_dev, ctrlsize, GFP_KERNEL, &acm->ctrl_dma);
1087 if (!buf) { 1138 if (!buf) {
@@ -1103,8 +1154,10 @@ skip_normal_probe:
1103 for (i = 0; i < num_rx_buf; i++) { 1154 for (i = 0; i < num_rx_buf; i++) {
1104 struct acm_ru *rcv = &(acm->ru[i]); 1155 struct acm_ru *rcv = &(acm->ru[i]);
1105 1156
1106 if (!(rcv->urb = usb_alloc_urb(0, GFP_KERNEL))) { 1157 rcv->urb = usb_alloc_urb(0, GFP_KERNEL);
1107 dev_dbg(&intf->dev, "out of memory (read urbs usb_alloc_urb)\n"); 1158 if (rcv->urb == NULL) {
1159 dev_dbg(&intf->dev,
1160 "out of memory (read urbs usb_alloc_urb)\n");
1108 goto alloc_fail7; 1161 goto alloc_fail7;
1109 } 1162 }
1110 1163
@@ -1117,26 +1170,29 @@ skip_normal_probe:
1117 rb->base = usb_buffer_alloc(acm->dev, readsize, 1170 rb->base = usb_buffer_alloc(acm->dev, readsize,
1118 GFP_KERNEL, &rb->dma); 1171 GFP_KERNEL, &rb->dma);
1119 if (!rb->base) { 1172 if (!rb->base) {
1120 dev_dbg(&intf->dev, "out of memory (read bufs usb_buffer_alloc)\n"); 1173 dev_dbg(&intf->dev,
1174 "out of memory (read bufs usb_buffer_alloc)\n");
1121 goto alloc_fail7; 1175 goto alloc_fail7;
1122 } 1176 }
1123 } 1177 }
1124 for(i = 0; i < ACM_NW; i++) 1178 for (i = 0; i < ACM_NW; i++) {
1125 {
1126 struct acm_wb *snd = &(acm->wb[i]); 1179 struct acm_wb *snd = &(acm->wb[i]);
1127 1180
1128 if (!(snd->urb = usb_alloc_urb(0, GFP_KERNEL))) { 1181 snd->urb = usb_alloc_urb(0, GFP_KERNEL);
1129 dev_dbg(&intf->dev, "out of memory (write urbs usb_alloc_urb)"); 1182 if (snd->urb == NULL) {
1183 dev_dbg(&intf->dev,
1184 "out of memory (write urbs usb_alloc_urb)");
1130 goto alloc_fail7; 1185 goto alloc_fail7;
1131 } 1186 }
1132 1187
1133 usb_fill_bulk_urb(snd->urb, usb_dev, usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress), 1188 usb_fill_bulk_urb(snd->urb, usb_dev,
1134 NULL, acm->writesize, acm_write_bulk, snd); 1189 usb_sndbulkpipe(usb_dev, epwrite->bEndpointAddress),
1190 NULL, acm->writesize, acm_write_bulk, snd);
1135 snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1191 snd->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1136 snd->instance = acm; 1192 snd->instance = acm;
1137 } 1193 }
1138 1194
1139 usb_set_intfdata (intf, acm); 1195 usb_set_intfdata(intf, acm);
1140 1196
1141 i = device_create_file(&intf->dev, &dev_attr_bmCapabilities); 1197 i = device_create_file(&intf->dev, &dev_attr_bmCapabilities);
1142 if (i < 0) 1198 if (i < 0)
@@ -1147,7 +1203,8 @@ skip_normal_probe:
1147 if (!acm->country_codes) 1203 if (!acm->country_codes)
1148 goto skip_countries; 1204 goto skip_countries;
1149 acm->country_code_size = cfd->bLength - 4; 1205 acm->country_code_size = cfd->bLength - 4;
1150 memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0, cfd->bLength - 4); 1206 memcpy(acm->country_codes, (u8 *)&cfd->wCountyCode0,
1207 cfd->bLength - 4);
1151 acm->country_rel_date = cfd->iCountryCodeRelDate; 1208 acm->country_rel_date = cfd->iCountryCodeRelDate;
1152 1209
1153 i = device_create_file(&intf->dev, &dev_attr_wCountryCodes); 1210 i = device_create_file(&intf->dev, &dev_attr_wCountryCodes);
@@ -1156,7 +1213,8 @@ skip_normal_probe:
1156 goto skip_countries; 1213 goto skip_countries;
1157 } 1214 }
1158 1215
1159 i = device_create_file(&intf->dev, &dev_attr_iCountryCodeRelDate); 1216 i = device_create_file(&intf->dev,
1217 &dev_attr_iCountryCodeRelDate);
1160 if (i < 0) { 1218 if (i < 0) {
1161 kfree(acm->country_codes); 1219 kfree(acm->country_codes);
1162 goto skip_countries; 1220 goto skip_countries;
@@ -1164,8 +1222,10 @@ skip_normal_probe:
1164 } 1222 }
1165 1223
1166skip_countries: 1224skip_countries:
1167 usb_fill_int_urb(acm->ctrlurb, usb_dev, usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress), 1225 usb_fill_int_urb(acm->ctrlurb, usb_dev,
1168 acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm, epctrl->bInterval); 1226 usb_rcvintpipe(usb_dev, epctrl->bEndpointAddress),
1227 acm->ctrl_buffer, ctrlsize, acm_ctrl_irq, acm,
1228 epctrl->bInterval);
1169 acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1229 acm->ctrlurb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1170 acm->ctrlurb->transfer_dma = acm->ctrl_dma; 1230 acm->ctrlurb->transfer_dma = acm->ctrl_dma;
1171 1231
@@ -1212,7 +1272,7 @@ static void stop_data_traffic(struct acm *acm)
1212 tasklet_disable(&acm->urb_task); 1272 tasklet_disable(&acm->urb_task);
1213 1273
1214 usb_kill_urb(acm->ctrlurb); 1274 usb_kill_urb(acm->ctrlurb);
1215 for(i = 0; i < ACM_NW; i++) 1275 for (i = 0; i < ACM_NW; i++)
1216 usb_kill_urb(acm->wb[i].urb); 1276 usb_kill_urb(acm->wb[i].urb);
1217 for (i = 0; i < acm->rx_buflimit; i++) 1277 for (i = 0; i < acm->rx_buflimit; i++)
1218 usb_kill_urb(acm->ru[i].urb); 1278 usb_kill_urb(acm->ru[i].urb);
@@ -1227,13 +1287,14 @@ static void acm_disconnect(struct usb_interface *intf)
1227{ 1287{
1228 struct acm *acm = usb_get_intfdata(intf); 1288 struct acm *acm = usb_get_intfdata(intf);
1229 struct usb_device *usb_dev = interface_to_usbdev(intf); 1289 struct usb_device *usb_dev = interface_to_usbdev(intf);
1290 struct tty_struct *tty;
1230 1291
1231 /* sibling interface is already cleaning up */ 1292 /* sibling interface is already cleaning up */
1232 if (!acm) 1293 if (!acm)
1233 return; 1294 return;
1234 1295
1235 mutex_lock(&open_mutex); 1296 mutex_lock(&open_mutex);
1236 if (acm->country_codes){ 1297 if (acm->country_codes) {
1237 device_remove_file(&acm->control->dev, 1298 device_remove_file(&acm->control->dev,
1238 &dev_attr_wCountryCodes); 1299 &dev_attr_wCountryCodes);
1239 device_remove_file(&acm->control->dev, 1300 device_remove_file(&acm->control->dev,
@@ -1247,22 +1308,25 @@ static void acm_disconnect(struct usb_interface *intf)
1247 stop_data_traffic(acm); 1308 stop_data_traffic(acm);
1248 1309
1249 acm_write_buffers_free(acm); 1310 acm_write_buffers_free(acm);
1250 usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer, acm->ctrl_dma); 1311 usb_buffer_free(usb_dev, acm->ctrlsize, acm->ctrl_buffer,
1312 acm->ctrl_dma);
1251 acm_read_buffers_free(acm); 1313 acm_read_buffers_free(acm);
1252 1314
1253 usb_driver_release_interface(&acm_driver, intf == acm->control ? 1315 usb_driver_release_interface(&acm_driver, intf == acm->control ?
1254 acm->data : acm->control); 1316 acm->data : acm->control);
1255 1317
1256 if (!acm->used) { 1318 if (acm->port.count == 0) {
1257 acm_tty_unregister(acm); 1319 acm_tty_unregister(acm);
1258 mutex_unlock(&open_mutex); 1320 mutex_unlock(&open_mutex);
1259 return; 1321 return;
1260 } 1322 }
1261 1323
1262 mutex_unlock(&open_mutex); 1324 mutex_unlock(&open_mutex);
1263 1325 tty = tty_port_tty_get(&acm->port);
1264 if (acm->tty) 1326 if (tty) {
1265 tty_hangup(acm->tty); 1327 tty_hangup(tty);
1328 tty_kref_put(tty);
1329 }
1266} 1330}
1267 1331
1268#ifdef CONFIG_PM 1332#ifdef CONFIG_PM
@@ -1297,7 +1361,7 @@ static int acm_suspend(struct usb_interface *intf, pm_message_t message)
1297 */ 1361 */
1298 mutex_lock(&acm->mutex); 1362 mutex_lock(&acm->mutex);
1299 1363
1300 if (acm->used) 1364 if (acm->port.count)
1301 stop_data_traffic(acm); 1365 stop_data_traffic(acm);
1302 1366
1303 mutex_unlock(&acm->mutex); 1367 mutex_unlock(&acm->mutex);
@@ -1319,7 +1383,7 @@ static int acm_resume(struct usb_interface *intf)
1319 return 0; 1383 return 0;
1320 1384
1321 mutex_lock(&acm->mutex); 1385 mutex_lock(&acm->mutex);
1322 if (acm->used) { 1386 if (acm->port.count) {
1323 rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO); 1387 rv = usb_submit_urb(acm->ctrlurb, GFP_NOIO);
1324 if (rv < 0) 1388 if (rv < 0)
1325 goto err_out; 1389 goto err_out;
@@ -1398,7 +1462,7 @@ static struct usb_device_id acm_ids[] = {
1398 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 1462 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1399 USB_CDC_ACM_PROTO_AT_GSM) }, 1463 USB_CDC_ACM_PROTO_AT_GSM) },
1400 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 1464 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1401 USB_CDC_ACM_PROTO_AT_3G ) }, 1465 USB_CDC_ACM_PROTO_AT_3G) },
1402 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM, 1466 { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_ACM,
1403 USB_CDC_ACM_PROTO_AT_CDMA) }, 1467 USB_CDC_ACM_PROTO_AT_CDMA) },
1404 1468
@@ -1406,7 +1470,7 @@ static struct usb_device_id acm_ids[] = {
1406 { } 1470 { }
1407}; 1471};
1408 1472
1409MODULE_DEVICE_TABLE (usb, acm_ids); 1473MODULE_DEVICE_TABLE(usb, acm_ids);
1410 1474
1411static struct usb_driver acm_driver = { 1475static struct usb_driver acm_driver = {
1412 .name = "cdc_acm", 1476 .name = "cdc_acm",
@@ -1429,6 +1493,7 @@ static struct usb_driver acm_driver = {
1429static const struct tty_operations acm_ops = { 1493static const struct tty_operations acm_ops = {
1430 .open = acm_tty_open, 1494 .open = acm_tty_open,
1431 .close = acm_tty_close, 1495 .close = acm_tty_close,
1496 .hangup = acm_tty_hangup,
1432 .write = acm_tty_write, 1497 .write = acm_tty_write,
1433 .write_room = acm_tty_write_room, 1498 .write_room = acm_tty_write_room,
1434 .ioctl = acm_tty_ioctl, 1499 .ioctl = acm_tty_ioctl,
@@ -1460,7 +1525,8 @@ static int __init acm_init(void)
1460 acm_tty_driver->subtype = SERIAL_TYPE_NORMAL, 1525 acm_tty_driver->subtype = SERIAL_TYPE_NORMAL,
1461 acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 1526 acm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
1462 acm_tty_driver->init_termios = tty_std_termios; 1527 acm_tty_driver->init_termios = tty_std_termios;
1463 acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; 1528 acm_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD |
1529 HUPCL | CLOCAL;
1464 tty_set_operations(acm_tty_driver, &acm_ops); 1530 tty_set_operations(acm_tty_driver, &acm_ops);
1465 1531
1466 retval = tty_register_driver(acm_tty_driver); 1532 retval = tty_register_driver(acm_tty_driver);
@@ -1492,7 +1558,7 @@ static void __exit acm_exit(void)
1492module_init(acm_init); 1558module_init(acm_init);
1493module_exit(acm_exit); 1559module_exit(acm_exit);
1494 1560
1495MODULE_AUTHOR( DRIVER_AUTHOR ); 1561MODULE_AUTHOR(DRIVER_AUTHOR);
1496MODULE_DESCRIPTION( DRIVER_DESC ); 1562MODULE_DESCRIPTION(DRIVER_DESC);
1497MODULE_LICENSE("GPL"); 1563MODULE_LICENSE("GPL");
1498MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR); 1564MODULE_ALIAS_CHARDEV_MAJOR(ACM_TTY_MAJOR);
diff --git a/drivers/usb/class/cdc-acm.h b/drivers/usb/class/cdc-acm.h
index 1f95e7aa1b66..4c3856420add 100644
--- a/drivers/usb/class/cdc-acm.h
+++ b/drivers/usb/class/cdc-acm.h
@@ -89,8 +89,8 @@ struct acm {
89 struct usb_device *dev; /* the corresponding usb device */ 89 struct usb_device *dev; /* the corresponding usb device */
90 struct usb_interface *control; /* control interface */ 90 struct usb_interface *control; /* control interface */
91 struct usb_interface *data; /* data interface */ 91 struct usb_interface *data; /* data interface */
92 struct tty_struct *tty; /* the corresponding tty */ 92 struct tty_port port; /* our tty port data */
93 struct urb *ctrlurb; /* urbs */ 93 struct urb *ctrlurb; /* urbs */
94 u8 *ctrl_buffer; /* buffers of urbs */ 94 u8 *ctrl_buffer; /* buffers of urbs */
95 dma_addr_t ctrl_dma; /* dma handles of buffers */ 95 dma_addr_t ctrl_dma; /* dma handles of buffers */
96 u8 *country_codes; /* country codes from device */ 96 u8 *country_codes; /* country codes from device */
@@ -120,7 +120,6 @@ struct acm {
120 unsigned int ctrlout; /* output control lines (DTR, RTS) */ 120 unsigned int ctrlout; /* output control lines (DTR, RTS) */
121 unsigned int writesize; /* max packet size for the output bulk endpoint */ 121 unsigned int writesize; /* max packet size for the output bulk endpoint */
122 unsigned int readsize,ctrlsize; /* buffer sizes for freeing */ 122 unsigned int readsize,ctrlsize; /* buffer sizes for freeing */
123 unsigned int used; /* someone has this acm's device open */
124 unsigned int minor; /* acm minor number */ 123 unsigned int minor; /* acm minor number */
125 unsigned char throttle; /* throttled by tty layer */ 124 unsigned char throttle; /* throttled by tty layer */
126 unsigned char clocal; /* termios CLOCAL */ 125 unsigned char clocal; /* termios CLOCAL */
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index b7eacad4d48c..2bfd6dd85b5a 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -93,8 +93,7 @@ static int belkin_sa_startup(struct usb_serial *serial);
93static void belkin_sa_shutdown(struct usb_serial *serial); 93static void belkin_sa_shutdown(struct usb_serial *serial);
94static int belkin_sa_open(struct tty_struct *tty, 94static int belkin_sa_open(struct tty_struct *tty,
95 struct usb_serial_port *port, struct file *filp); 95 struct usb_serial_port *port, struct file *filp);
96static void belkin_sa_close(struct tty_struct *tty, 96static void belkin_sa_close(struct usb_serial_port *port);
97 struct usb_serial_port *port, struct file *filp);
98static void belkin_sa_read_int_callback(struct urb *urb); 97static void belkin_sa_read_int_callback(struct urb *urb);
99static void belkin_sa_set_termios(struct tty_struct *tty, 98static void belkin_sa_set_termios(struct tty_struct *tty,
100 struct usb_serial_port *port, struct ktermios * old); 99 struct usb_serial_port *port, struct ktermios * old);
@@ -244,8 +243,7 @@ exit:
244} /* belkin_sa_open */ 243} /* belkin_sa_open */
245 244
246 245
247static void belkin_sa_close(struct tty_struct *tty, 246static void belkin_sa_close(struct usb_serial_port *port)
248 struct usb_serial_port *port, struct file *filp)
249{ 247{
250 dbg("%s port %d", __func__, port->number); 248 dbg("%s port %d", __func__, port->number);
251 249
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index ab4cc277aa65..2830766f5b39 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -262,32 +262,40 @@ error: kfree(priv);
262 return r; 262 return r;
263} 263}
264 264
265static void ch341_close(struct tty_struct *tty, struct usb_serial_port *port, 265static int ch341_carrier_raised(struct usb_serial_port *port)
266 struct file *filp) 266{
267 struct ch341_private *priv = usb_get_serial_port_data(port);
268 if (priv->line_status & CH341_BIT_DCD)
269 return 1;
270 return 0;
271}
272
273static void ch341_dtr_rts(struct usb_serial_port *port, int on)
267{ 274{
268 struct ch341_private *priv = usb_get_serial_port_data(port); 275 struct ch341_private *priv = usb_get_serial_port_data(port);
269 unsigned long flags; 276 unsigned long flags;
270 unsigned int c_cflag;
271 277
272 dbg("%s - port %d", __func__, port->number); 278 dbg("%s - port %d", __func__, port->number);
279 /* drop DTR and RTS */
280 spin_lock_irqsave(&priv->lock, flags);
281 if (on)
282 priv->line_control |= CH341_BIT_RTS | CH341_BIT_DTR;
283 else
284 priv->line_control &= ~(CH341_BIT_RTS | CH341_BIT_DTR);
285 spin_unlock_irqrestore(&priv->lock, flags);
286 ch341_set_handshake(port->serial->dev, priv->line_control);
287 wake_up_interruptible(&priv->delta_msr_wait);
288}
289
290static void ch341_close(struct usb_serial_port *port)
291{
292 dbg("%s - port %d", __func__, port->number);
273 293
274 /* shutdown our urbs */ 294 /* shutdown our urbs */
275 dbg("%s - shutting down urbs", __func__); 295 dbg("%s - shutting down urbs", __func__);
276 usb_kill_urb(port->write_urb); 296 usb_kill_urb(port->write_urb);
277 usb_kill_urb(port->read_urb); 297 usb_kill_urb(port->read_urb);
278 usb_kill_urb(port->interrupt_in_urb); 298 usb_kill_urb(port->interrupt_in_urb);
279
280 if (tty) {
281 c_cflag = tty->termios->c_cflag;
282 if (c_cflag & HUPCL) {
283 /* drop DTR and RTS */
284 spin_lock_irqsave(&priv->lock, flags);
285 priv->line_control = 0;
286 spin_unlock_irqrestore(&priv->lock, flags);
287 ch341_set_handshake(port->serial->dev, 0);
288 }
289 }
290 wake_up_interruptible(&priv->delta_msr_wait);
291} 299}
292 300
293 301
@@ -302,7 +310,6 @@ static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port,
302 dbg("ch341_open()"); 310 dbg("ch341_open()");
303 311
304 priv->baud_rate = DEFAULT_BAUD_RATE; 312 priv->baud_rate = DEFAULT_BAUD_RATE;
305 priv->line_control = CH341_BIT_RTS | CH341_BIT_DTR;
306 313
307 r = ch341_configure(serial->dev, priv); 314 r = ch341_configure(serial->dev, priv);
308 if (r) 315 if (r)
@@ -322,7 +329,7 @@ static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port,
322 if (r) { 329 if (r) {
323 dev_err(&port->dev, "%s - failed submitting interrupt urb," 330 dev_err(&port->dev, "%s - failed submitting interrupt urb,"
324 " error %d\n", __func__, r); 331 " error %d\n", __func__, r);
325 ch341_close(tty, port, NULL); 332 ch341_close(port);
326 return -EPROTO; 333 return -EPROTO;
327 } 334 }
328 335
@@ -343,9 +350,6 @@ static void ch341_set_termios(struct tty_struct *tty,
343 350
344 dbg("ch341_set_termios()"); 351 dbg("ch341_set_termios()");
345 352
346 if (!tty || !tty->termios)
347 return;
348
349 baud_rate = tty_get_baud_rate(tty); 353 baud_rate = tty_get_baud_rate(tty);
350 354
351 priv->baud_rate = baud_rate; 355 priv->baud_rate = baud_rate;
@@ -568,6 +572,8 @@ static struct usb_serial_driver ch341_device = {
568 .usb_driver = &ch341_driver, 572 .usb_driver = &ch341_driver,
569 .num_ports = 1, 573 .num_ports = 1,
570 .open = ch341_open, 574 .open = ch341_open,
575 .dtr_rts = ch341_dtr_rts,
576 .carrier_raised = ch341_carrier_raised,
571 .close = ch341_close, 577 .close = ch341_close,
572 .ioctl = ch341_ioctl, 578 .ioctl = ch341_ioctl,
573 .set_termios = ch341_set_termios, 579 .set_termios = ch341_set_termios,
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index 19e24045b137..247b61bfb7f4 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -169,7 +169,9 @@ static int usb_console_setup(struct console *co, char *options)
169 kfree(tty); 169 kfree(tty);
170 } 170 }
171 } 171 }
172 172 /* So we know not to kill the hardware on a hangup on this
173 port. We have also bumped the use count by one so it won't go
174 idle */
173 port->console = 1; 175 port->console = 1;
174 retval = 0; 176 retval = 0;
175 177
@@ -182,7 +184,7 @@ free_tty:
182 kfree(tty); 184 kfree(tty);
183reset_open_count: 185reset_open_count:
184 port->port.count = 0; 186 port->port.count = 0;
185goto out; 187 goto out;
186} 188}
187 189
188static void usb_console_write(struct console *co, 190static void usb_console_write(struct console *co,
diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index e8d5133ce9c8..16a154d3b2fe 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Silicon Laboratories CP2101/CP2102 USB to RS232 serial adaptor driver 2 * Silicon Laboratories CP210x USB to RS232 serial adaptor driver
3 * 3 *
4 * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk) 4 * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk)
5 * 5 *
@@ -27,44 +27,46 @@
27/* 27/*
28 * Version Information 28 * Version Information
29 */ 29 */
30#define DRIVER_VERSION "v0.08" 30#define DRIVER_VERSION "v0.09"
31#define DRIVER_DESC "Silicon Labs CP2101/CP2102 RS232 serial adaptor driver" 31#define DRIVER_DESC "Silicon Labs CP210x RS232 serial adaptor driver"
32 32
33/* 33/*
34 * Function Prototypes 34 * Function Prototypes
35 */ 35 */
36static int cp2101_open(struct tty_struct *, struct usb_serial_port *, 36static int cp210x_open(struct tty_struct *, struct usb_serial_port *,
37 struct file *); 37 struct file *);
38static void cp2101_cleanup(struct usb_serial_port *); 38static void cp210x_cleanup(struct usb_serial_port *);
39static void cp2101_close(struct tty_struct *, struct usb_serial_port *, 39static void cp210x_close(struct usb_serial_port *);
40 struct file*); 40static void cp210x_get_termios(struct tty_struct *,
41static void cp2101_get_termios(struct tty_struct *,
42 struct usb_serial_port *port); 41 struct usb_serial_port *port);
43static void cp2101_get_termios_port(struct usb_serial_port *port, 42static void cp210x_get_termios_port(struct usb_serial_port *port,
44 unsigned int *cflagp, unsigned int *baudp); 43 unsigned int *cflagp, unsigned int *baudp);
45static void cp2101_set_termios(struct tty_struct *, struct usb_serial_port *, 44static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *,
46 struct ktermios*); 45 struct ktermios*);
47static int cp2101_tiocmget(struct tty_struct *, struct file *); 46static int cp210x_tiocmget(struct tty_struct *, struct file *);
48static int cp2101_tiocmset(struct tty_struct *, struct file *, 47static int cp210x_tiocmset(struct tty_struct *, struct file *,
49 unsigned int, unsigned int); 48 unsigned int, unsigned int);
50static int cp2101_tiocmset_port(struct usb_serial_port *port, struct file *, 49static int cp210x_tiocmset_port(struct usb_serial_port *port, struct file *,
51 unsigned int, unsigned int); 50 unsigned int, unsigned int);
52static void cp2101_break_ctl(struct tty_struct *, int); 51static void cp210x_break_ctl(struct tty_struct *, int);
53static int cp2101_startup(struct usb_serial *); 52static int cp210x_startup(struct usb_serial *);
54static void cp2101_shutdown(struct usb_serial *); 53static void cp210x_shutdown(struct usb_serial *);
55 54
56static int debug; 55static int debug;
57 56
58static struct usb_device_id id_table [] = { 57static struct usb_device_id id_table [] = {
59 { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */ 58 { USB_DEVICE(0x0471, 0x066A) }, /* AKTAKOM ACE-1001 cable */
60 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */ 59 { USB_DEVICE(0x0489, 0xE000) }, /* Pirelli Broadband S.p.A, DP-L10 SIP/GSM Mobile */
60 { USB_DEVICE(0x0745, 0x1000) }, /* CipherLab USB CCD Barcode Scanner 1000 */
61 { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */ 61 { USB_DEVICE(0x08e6, 0x5501) }, /* Gemalto Prox-PU/CU contactless smartcard reader */
62 { USB_DEVICE(0x08FD, 0x000A) }, /* Digianswer A/S , ZigBee/802.15.4 MAC Device */
62 { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */ 63 { USB_DEVICE(0x0FCF, 0x1003) }, /* Dynastream ANT development board */
63 { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */ 64 { USB_DEVICE(0x0FCF, 0x1004) }, /* Dynastream ANT2USB */
64 { USB_DEVICE(0x0FCF, 0x1006) }, /* Dynastream ANT development board */ 65 { USB_DEVICE(0x0FCF, 0x1006) }, /* Dynastream ANT development board */
65 { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */ 66 { USB_DEVICE(0x10A6, 0xAA26) }, /* Knock-off DCU-11 cable */
66 { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */ 67 { USB_DEVICE(0x10AB, 0x10C5) }, /* Siemens MC60 Cable */
67 { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */ 68 { USB_DEVICE(0x10B5, 0xAC70) }, /* Nokia CA-42 USB */
69 { USB_DEVICE(0x10C4, 0x0F91) }, /* Vstabi */
68 { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */ 70 { USB_DEVICE(0x10C4, 0x800A) }, /* SPORTident BSM7-D-USB main station */
69 { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */ 71 { USB_DEVICE(0x10C4, 0x803B) }, /* Pololu USB-serial converter */
70 { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */ 72 { USB_DEVICE(0x10C4, 0x8053) }, /* Enfora EDG1228 */
@@ -85,10 +87,12 @@ static struct usb_device_id id_table [] = {
85 { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */ 87 { USB_DEVICE(0x10C4, 0x81C8) }, /* Lipowsky Industrie Elektronik GmbH, Baby-JTAG */
86 { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */ 88 { USB_DEVICE(0x10C4, 0x81E2) }, /* Lipowsky Industrie Elektronik GmbH, Baby-LIN */
87 { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */ 89 { USB_DEVICE(0x10C4, 0x81E7) }, /* Aerocomm Radio */
90 { USB_DEVICE(0x10C4, 0x81F2) }, /* C1007 HF band RFID controller */
88 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */ 91 { USB_DEVICE(0x10C4, 0x8218) }, /* Lipowsky Industrie Elektronik GmbH, HARP-1 */
89 { USB_DEVICE(0x10C4, 0x822B) }, /* Modem EDGE(GSM) Comander 2 */ 92 { USB_DEVICE(0x10C4, 0x822B) }, /* Modem EDGE(GSM) Comander 2 */
90 { USB_DEVICE(0x10C4, 0x826B) }, /* Cygnal Integrated Products, Inc., Fasttrax GPS demostration module */ 93 { USB_DEVICE(0x10C4, 0x826B) }, /* Cygnal Integrated Products, Inc., Fasttrax GPS demostration module */
91 { USB_DEVICE(0x10c4, 0x8293) }, /* Telegesys ETRX2USB */ 94 { USB_DEVICE(0x10c4, 0x8293) }, /* Telegesys ETRX2USB */
95 { USB_DEVICE(0x10C4, 0x82F9) }, /* Procyon AVS */
92 { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */ 96 { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */
93 { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */ 97 { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */
94 { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */ 98 { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */
@@ -99,7 +103,9 @@ static struct usb_device_id id_table [] = {
99 { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */ 103 { USB_DEVICE(0x10C4, 0xF003) }, /* Elan Digital Systems USBpulse100 */
100 { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */ 104 { USB_DEVICE(0x10C4, 0xF004) }, /* Elan Digital Systems USBcount50 */
101 { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */ 105 { USB_DEVICE(0x10C5, 0xEA61) }, /* Silicon Labs MobiData GPRS USB Modem */
106 { USB_DEVICE(0x10CE, 0xEA6A) }, /* Silicon Labs MobiData GPRS USB Modem 100EU */
102 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */ 107 { USB_DEVICE(0x13AD, 0x9999) }, /* Baltech card reader */
108 { USB_DEVICE(0x1555, 0x0004) }, /* Owen AC4 USB-RS485 Converter */
103 { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */ 109 { USB_DEVICE(0x166A, 0x0303) }, /* Clipsal 5500PCU C-Bus USB interface */
104 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */ 110 { USB_DEVICE(0x16D6, 0x0001) }, /* Jablotron serial interface */
105 { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */ 111 { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */
@@ -108,53 +114,70 @@ static struct usb_device_id id_table [] = {
108 114
109MODULE_DEVICE_TABLE(usb, id_table); 115MODULE_DEVICE_TABLE(usb, id_table);
110 116
111static struct usb_driver cp2101_driver = { 117static struct usb_driver cp210x_driver = {
112 .name = "cp2101", 118 .name = "cp210x",
113 .probe = usb_serial_probe, 119 .probe = usb_serial_probe,
114 .disconnect = usb_serial_disconnect, 120 .disconnect = usb_serial_disconnect,
115 .id_table = id_table, 121 .id_table = id_table,
116 .no_dynamic_id = 1, 122 .no_dynamic_id = 1,
117}; 123};
118 124
119static struct usb_serial_driver cp2101_device = { 125static struct usb_serial_driver cp210x_device = {
120 .driver = { 126 .driver = {
121 .owner = THIS_MODULE, 127 .owner = THIS_MODULE,
122 .name = "cp2101", 128 .name = "cp210x",
123 }, 129 },
124 .usb_driver = &cp2101_driver, 130 .usb_driver = &cp210x_driver,
125 .id_table = id_table, 131 .id_table = id_table,
126 .num_ports = 1, 132 .num_ports = 1,
127 .open = cp2101_open, 133 .open = cp210x_open,
128 .close = cp2101_close, 134 .close = cp210x_close,
129 .break_ctl = cp2101_break_ctl, 135 .break_ctl = cp210x_break_ctl,
130 .set_termios = cp2101_set_termios, 136 .set_termios = cp210x_set_termios,
131 .tiocmget = cp2101_tiocmget, 137 .tiocmget = cp210x_tiocmget,
132 .tiocmset = cp2101_tiocmset, 138 .tiocmset = cp210x_tiocmset,
133 .attach = cp2101_startup, 139 .attach = cp210x_startup,
134 .shutdown = cp2101_shutdown, 140 .shutdown = cp210x_shutdown,
135}; 141};
136 142
137/* Config request types */ 143/* Config request types */
138#define REQTYPE_HOST_TO_DEVICE 0x41 144#define REQTYPE_HOST_TO_DEVICE 0x41
139#define REQTYPE_DEVICE_TO_HOST 0xc1 145#define REQTYPE_DEVICE_TO_HOST 0xc1
140 146
141/* Config SET requests. To GET, add 1 to the request number */ 147/* Config request codes */
142#define CP2101_UART 0x00 /* Enable / Disable */ 148#define CP210X_IFC_ENABLE 0x00
143#define CP2101_BAUDRATE 0x01 /* (BAUD_RATE_GEN_FREQ / baudrate) */ 149#define CP210X_SET_BAUDDIV 0x01
144#define CP2101_BITS 0x03 /* 0x(0)(databits)(parity)(stopbits) */ 150#define CP210X_GET_BAUDDIV 0x02
145#define CP2101_BREAK 0x05 /* On / Off */ 151#define CP210X_SET_LINE_CTL 0x03
146#define CP2101_CONTROL 0x07 /* Flow control line states */ 152#define CP210X_GET_LINE_CTL 0x04
147#define CP2101_MODEMCTL 0x13 /* Modem controls */ 153#define CP210X_SET_BREAK 0x05
148#define CP2101_CONFIG_6 0x19 /* 6 bytes of config data ??? */ 154#define CP210X_IMM_CHAR 0x06
149 155#define CP210X_SET_MHS 0x07
150/* CP2101_UART */ 156#define CP210X_GET_MDMSTS 0x08
157#define CP210X_SET_XON 0x09
158#define CP210X_SET_XOFF 0x0A
159#define CP210X_SET_EVENTMASK 0x0B
160#define CP210X_GET_EVENTMASK 0x0C
161#define CP210X_SET_CHAR 0x0D
162#define CP210X_GET_CHARS 0x0E
163#define CP210X_GET_PROPS 0x0F
164#define CP210X_GET_COMM_STATUS 0x10
165#define CP210X_RESET 0x11
166#define CP210X_PURGE 0x12
167#define CP210X_SET_FLOW 0x13
168#define CP210X_GET_FLOW 0x14
169#define CP210X_EMBED_EVENTS 0x15
170#define CP210X_GET_EVENTSTATE 0x16
171#define CP210X_SET_CHARS 0x19
172
173/* CP210X_IFC_ENABLE */
151#define UART_ENABLE 0x0001 174#define UART_ENABLE 0x0001
152#define UART_DISABLE 0x0000 175#define UART_DISABLE 0x0000
153 176
154/* CP2101_BAUDRATE */ 177/* CP210X_(SET|GET)_BAUDDIV */
155#define BAUD_RATE_GEN_FREQ 0x384000 178#define BAUD_RATE_GEN_FREQ 0x384000
156 179
157/* CP2101_BITS */ 180/* CP210X_(SET|GET)_LINE_CTL */
158#define BITS_DATA_MASK 0X0f00 181#define BITS_DATA_MASK 0X0f00
159#define BITS_DATA_5 0X0500 182#define BITS_DATA_5 0X0500
160#define BITS_DATA_6 0X0600 183#define BITS_DATA_6 0X0600
@@ -174,11 +197,11 @@ static struct usb_serial_driver cp2101_device = {
174#define BITS_STOP_1_5 0x0001 197#define BITS_STOP_1_5 0x0001
175#define BITS_STOP_2 0x0002 198#define BITS_STOP_2 0x0002
176 199
177/* CP2101_BREAK */ 200/* CP210X_SET_BREAK */
178#define BREAK_ON 0x0000 201#define BREAK_ON 0x0000
179#define BREAK_OFF 0x0001 202#define BREAK_OFF 0x0001
180 203
181/* CP2101_CONTROL */ 204/* CP210X_(SET_MHS|GET_MDMSTS) */
182#define CONTROL_DTR 0x0001 205#define CONTROL_DTR 0x0001
183#define CONTROL_RTS 0x0002 206#define CONTROL_RTS 0x0002
184#define CONTROL_CTS 0x0010 207#define CONTROL_CTS 0x0010
@@ -189,13 +212,13 @@ static struct usb_serial_driver cp2101_device = {
189#define CONTROL_WRITE_RTS 0x0200 212#define CONTROL_WRITE_RTS 0x0200
190 213
191/* 214/*
192 * cp2101_get_config 215 * cp210x_get_config
193 * Reads from the CP2101 configuration registers 216 * Reads from the CP210x configuration registers
194 * 'size' is specified in bytes. 217 * 'size' is specified in bytes.
195 * 'data' is a pointer to a pre-allocated array of integers large 218 * 'data' is a pointer to a pre-allocated array of integers large
196 * enough to hold 'size' bytes (with 4 bytes to each integer) 219 * enough to hold 'size' bytes (with 4 bytes to each integer)
197 */ 220 */
198static int cp2101_get_config(struct usb_serial_port *port, u8 request, 221static int cp210x_get_config(struct usb_serial_port *port, u8 request,
199 unsigned int *data, int size) 222 unsigned int *data, int size)
200{ 223{
201 struct usb_serial *serial = port->serial; 224 struct usb_serial *serial = port->serial;
@@ -211,9 +234,6 @@ static int cp2101_get_config(struct usb_serial_port *port, u8 request,
211 return -ENOMEM; 234 return -ENOMEM;
212 } 235 }
213 236
214 /* For get requests, the request number must be incremented */
215 request++;
216
217 /* Issue the request, attempting to read 'size' bytes */ 237 /* Issue the request, attempting to read 'size' bytes */
218 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 238 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
219 request, REQTYPE_DEVICE_TO_HOST, 0x0000, 239 request, REQTYPE_DEVICE_TO_HOST, 0x0000,
@@ -236,12 +256,12 @@ static int cp2101_get_config(struct usb_serial_port *port, u8 request,
236} 256}
237 257
238/* 258/*
239 * cp2101_set_config 259 * cp210x_set_config
240 * Writes to the CP2101 configuration registers 260 * Writes to the CP210x configuration registers
241 * Values less than 16 bits wide are sent directly 261 * Values less than 16 bits wide are sent directly
242 * 'size' is specified in bytes. 262 * 'size' is specified in bytes.
243 */ 263 */
244static int cp2101_set_config(struct usb_serial_port *port, u8 request, 264static int cp210x_set_config(struct usb_serial_port *port, u8 request,
245 unsigned int *data, int size) 265 unsigned int *data, int size)
246{ 266{
247 struct usb_serial *serial = port->serial; 267 struct usb_serial *serial = port->serial;
@@ -292,21 +312,21 @@ static int cp2101_set_config(struct usb_serial_port *port, u8 request,
292} 312}
293 313
294/* 314/*
295 * cp2101_set_config_single 315 * cp210x_set_config_single
296 * Convenience function for calling cp2101_set_config on single data values 316 * Convenience function for calling cp210x_set_config on single data values
297 * without requiring an integer pointer 317 * without requiring an integer pointer
298 */ 318 */
299static inline int cp2101_set_config_single(struct usb_serial_port *port, 319static inline int cp210x_set_config_single(struct usb_serial_port *port,
300 u8 request, unsigned int data) 320 u8 request, unsigned int data)
301{ 321{
302 return cp2101_set_config(port, request, &data, 2); 322 return cp210x_set_config(port, request, &data, 2);
303} 323}
304 324
305/* 325/*
306 * cp2101_quantise_baudrate 326 * cp210x_quantise_baudrate
307 * Quantises the baud rate as per AN205 Table 1 327 * Quantises the baud rate as per AN205 Table 1
308 */ 328 */
309static unsigned int cp2101_quantise_baudrate(unsigned int baud) { 329static unsigned int cp210x_quantise_baudrate(unsigned int baud) {
310 if (baud <= 56) baud = 0; 330 if (baud <= 56) baud = 0;
311 else if (baud <= 300) baud = 300; 331 else if (baud <= 300) baud = 300;
312 else if (baud <= 600) baud = 600; 332 else if (baud <= 600) baud = 600;
@@ -343,7 +363,7 @@ static unsigned int cp2101_quantise_baudrate(unsigned int baud) {
343 return baud; 363 return baud;
344} 364}
345 365
346static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port, 366static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port,
347 struct file *filp) 367 struct file *filp)
348{ 368{
349 struct usb_serial *serial = port->serial; 369 struct usb_serial *serial = port->serial;
@@ -351,7 +371,7 @@ static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port,
351 371
352 dbg("%s - port %d", __func__, port->number); 372 dbg("%s - port %d", __func__, port->number);
353 373
354 if (cp2101_set_config_single(port, CP2101_UART, UART_ENABLE)) { 374 if (cp210x_set_config_single(port, CP210X_IFC_ENABLE, UART_ENABLE)) {
355 dev_err(&port->dev, "%s - Unable to enable UART\n", 375 dev_err(&port->dev, "%s - Unable to enable UART\n",
356 __func__); 376 __func__);
357 return -EPROTO; 377 return -EPROTO;
@@ -373,17 +393,17 @@ static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port,
373 } 393 }
374 394
375 /* Configure the termios structure */ 395 /* Configure the termios structure */
376 cp2101_get_termios(tty, port); 396 cp210x_get_termios(tty, port);
377 397
378 /* Set the DTR and RTS pins low */ 398 /* Set the DTR and RTS pins low */
379 cp2101_tiocmset_port(tty ? (struct usb_serial_port *) tty->driver_data 399 cp210x_tiocmset_port(tty ? (struct usb_serial_port *) tty->driver_data
380 : port, 400 : port,
381 NULL, TIOCM_DTR | TIOCM_RTS, 0); 401 NULL, TIOCM_DTR | TIOCM_RTS, 0);
382 402
383 return 0; 403 return 0;
384} 404}
385 405
386static void cp2101_cleanup(struct usb_serial_port *port) 406static void cp210x_cleanup(struct usb_serial_port *port)
387{ 407{
388 struct usb_serial *serial = port->serial; 408 struct usb_serial *serial = port->serial;
389 409
@@ -398,8 +418,7 @@ static void cp2101_cleanup(struct usb_serial_port *port)
398 } 418 }
399} 419}
400 420
401static void cp2101_close(struct tty_struct *tty, struct usb_serial_port *port, 421static void cp210x_close(struct usb_serial_port *port)
402 struct file *filp)
403{ 422{
404 dbg("%s - port %d", __func__, port->number); 423 dbg("%s - port %d", __func__, port->number);
405 424
@@ -410,23 +429,23 @@ static void cp2101_close(struct tty_struct *tty, struct usb_serial_port *port,
410 429
411 mutex_lock(&port->serial->disc_mutex); 430 mutex_lock(&port->serial->disc_mutex);
412 if (!port->serial->disconnected) 431 if (!port->serial->disconnected)
413 cp2101_set_config_single(port, CP2101_UART, UART_DISABLE); 432 cp210x_set_config_single(port, CP210X_IFC_ENABLE, UART_DISABLE);
414 mutex_unlock(&port->serial->disc_mutex); 433 mutex_unlock(&port->serial->disc_mutex);
415} 434}
416 435
417/* 436/*
418 * cp2101_get_termios 437 * cp210x_get_termios
419 * Reads the baud rate, data bits, parity, stop bits and flow control mode 438 * Reads the baud rate, data bits, parity, stop bits and flow control mode
420 * from the device, corrects any unsupported values, and configures the 439 * from the device, corrects any unsupported values, and configures the
421 * termios structure to reflect the state of the device 440 * termios structure to reflect the state of the device
422 */ 441 */
423static void cp2101_get_termios(struct tty_struct *tty, 442static void cp210x_get_termios(struct tty_struct *tty,
424 struct usb_serial_port *port) 443 struct usb_serial_port *port)
425{ 444{
426 unsigned int baud; 445 unsigned int baud;
427 446
428 if (tty) { 447 if (tty) {
429 cp2101_get_termios_port(tty->driver_data, 448 cp210x_get_termios_port(tty->driver_data,
430 &tty->termios->c_cflag, &baud); 449 &tty->termios->c_cflag, &baud);
431 tty_encode_baud_rate(tty, baud, baud); 450 tty_encode_baud_rate(tty, baud, baud);
432 } 451 }
@@ -434,15 +453,15 @@ static void cp2101_get_termios(struct tty_struct *tty,
434 else { 453 else {
435 unsigned int cflag; 454 unsigned int cflag;
436 cflag = 0; 455 cflag = 0;
437 cp2101_get_termios_port(port, &cflag, &baud); 456 cp210x_get_termios_port(port, &cflag, &baud);
438 } 457 }
439} 458}
440 459
441/* 460/*
442 * cp2101_get_termios_port 461 * cp210x_get_termios_port
443 * This is the heart of cp2101_get_termios which always uses a &usb_serial_port. 462 * This is the heart of cp210x_get_termios which always uses a &usb_serial_port.
444 */ 463 */
445static void cp2101_get_termios_port(struct usb_serial_port *port, 464static void cp210x_get_termios_port(struct usb_serial_port *port,
446 unsigned int *cflagp, unsigned int *baudp) 465 unsigned int *cflagp, unsigned int *baudp)
447{ 466{
448 unsigned int cflag, modem_ctl[4]; 467 unsigned int cflag, modem_ctl[4];
@@ -451,17 +470,17 @@ static void cp2101_get_termios_port(struct usb_serial_port *port,
451 470
452 dbg("%s - port %d", __func__, port->number); 471 dbg("%s - port %d", __func__, port->number);
453 472
454 cp2101_get_config(port, CP2101_BAUDRATE, &baud, 2); 473 cp210x_get_config(port, CP210X_GET_BAUDDIV, &baud, 2);
455 /* Convert to baudrate */ 474 /* Convert to baudrate */
456 if (baud) 475 if (baud)
457 baud = cp2101_quantise_baudrate((BAUD_RATE_GEN_FREQ + baud/2)/ baud); 476 baud = cp210x_quantise_baudrate((BAUD_RATE_GEN_FREQ + baud/2)/ baud);
458 477
459 dbg("%s - baud rate = %d", __func__, baud); 478 dbg("%s - baud rate = %d", __func__, baud);
460 *baudp = baud; 479 *baudp = baud;
461 480
462 cflag = *cflagp; 481 cflag = *cflagp;
463 482
464 cp2101_get_config(port, CP2101_BITS, &bits, 2); 483 cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2);
465 cflag &= ~CSIZE; 484 cflag &= ~CSIZE;
466 switch (bits & BITS_DATA_MASK) { 485 switch (bits & BITS_DATA_MASK) {
467 case BITS_DATA_5: 486 case BITS_DATA_5:
@@ -486,14 +505,14 @@ static void cp2101_get_termios_port(struct usb_serial_port *port,
486 cflag |= CS8; 505 cflag |= CS8;
487 bits &= ~BITS_DATA_MASK; 506 bits &= ~BITS_DATA_MASK;
488 bits |= BITS_DATA_8; 507 bits |= BITS_DATA_8;
489 cp2101_set_config(port, CP2101_BITS, &bits, 2); 508 cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2);
490 break; 509 break;
491 default: 510 default:
492 dbg("%s - Unknown number of data bits, using 8", __func__); 511 dbg("%s - Unknown number of data bits, using 8", __func__);
493 cflag |= CS8; 512 cflag |= CS8;
494 bits &= ~BITS_DATA_MASK; 513 bits &= ~BITS_DATA_MASK;
495 bits |= BITS_DATA_8; 514 bits |= BITS_DATA_8;
496 cp2101_set_config(port, CP2101_BITS, &bits, 2); 515 cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2);
497 break; 516 break;
498 } 517 }
499 518
@@ -516,20 +535,20 @@ static void cp2101_get_termios_port(struct usb_serial_port *port,
516 __func__); 535 __func__);
517 cflag &= ~PARENB; 536 cflag &= ~PARENB;
518 bits &= ~BITS_PARITY_MASK; 537 bits &= ~BITS_PARITY_MASK;
519 cp2101_set_config(port, CP2101_BITS, &bits, 2); 538 cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2);
520 break; 539 break;
521 case BITS_PARITY_SPACE: 540 case BITS_PARITY_SPACE:
522 dbg("%s - parity = SPACE (not supported, disabling parity)", 541 dbg("%s - parity = SPACE (not supported, disabling parity)",
523 __func__); 542 __func__);
524 cflag &= ~PARENB; 543 cflag &= ~PARENB;
525 bits &= ~BITS_PARITY_MASK; 544 bits &= ~BITS_PARITY_MASK;
526 cp2101_set_config(port, CP2101_BITS, &bits, 2); 545 cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2);
527 break; 546 break;
528 default: 547 default:
529 dbg("%s - Unknown parity mode, disabling parity", __func__); 548 dbg("%s - Unknown parity mode, disabling parity", __func__);
530 cflag &= ~PARENB; 549 cflag &= ~PARENB;
531 bits &= ~BITS_PARITY_MASK; 550 bits &= ~BITS_PARITY_MASK;
532 cp2101_set_config(port, CP2101_BITS, &bits, 2); 551 cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2);
533 break; 552 break;
534 } 553 }
535 554
@@ -542,7 +561,7 @@ static void cp2101_get_termios_port(struct usb_serial_port *port,
542 dbg("%s - stop bits = 1.5 (not supported, using 1 stop bit)", 561 dbg("%s - stop bits = 1.5 (not supported, using 1 stop bit)",
543 __func__); 562 __func__);
544 bits &= ~BITS_STOP_MASK; 563 bits &= ~BITS_STOP_MASK;
545 cp2101_set_config(port, CP2101_BITS, &bits, 2); 564 cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2);
546 break; 565 break;
547 case BITS_STOP_2: 566 case BITS_STOP_2:
548 dbg("%s - stop bits = 2", __func__); 567 dbg("%s - stop bits = 2", __func__);
@@ -552,11 +571,11 @@ static void cp2101_get_termios_port(struct usb_serial_port *port,
552 dbg("%s - Unknown number of stop bits, using 1 stop bit", 571 dbg("%s - Unknown number of stop bits, using 1 stop bit",
553 __func__); 572 __func__);
554 bits &= ~BITS_STOP_MASK; 573 bits &= ~BITS_STOP_MASK;
555 cp2101_set_config(port, CP2101_BITS, &bits, 2); 574 cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2);
556 break; 575 break;
557 } 576 }
558 577
559 cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); 578 cp210x_get_config(port, CP210X_GET_FLOW, modem_ctl, 16);
560 if (modem_ctl[0] & 0x0008) { 579 if (modem_ctl[0] & 0x0008) {
561 dbg("%s - flow control = CRTSCTS", __func__); 580 dbg("%s - flow control = CRTSCTS", __func__);
562 cflag |= CRTSCTS; 581 cflag |= CRTSCTS;
@@ -568,7 +587,7 @@ static void cp2101_get_termios_port(struct usb_serial_port *port,
568 *cflagp = cflag; 587 *cflagp = cflag;
569} 588}
570 589
571static void cp2101_set_termios(struct tty_struct *tty, 590static void cp210x_set_termios(struct tty_struct *tty,
572 struct usb_serial_port *port, struct ktermios *old_termios) 591 struct usb_serial_port *port, struct ktermios *old_termios)
573{ 592{
574 unsigned int cflag, old_cflag; 593 unsigned int cflag, old_cflag;
@@ -583,13 +602,13 @@ static void cp2101_set_termios(struct tty_struct *tty,
583 tty->termios->c_cflag &= ~CMSPAR; 602 tty->termios->c_cflag &= ~CMSPAR;
584 cflag = tty->termios->c_cflag; 603 cflag = tty->termios->c_cflag;
585 old_cflag = old_termios->c_cflag; 604 old_cflag = old_termios->c_cflag;
586 baud = cp2101_quantise_baudrate(tty_get_baud_rate(tty)); 605 baud = cp210x_quantise_baudrate(tty_get_baud_rate(tty));
587 606
588 /* If the baud rate is to be updated*/ 607 /* If the baud rate is to be updated*/
589 if (baud != tty_termios_baud_rate(old_termios) && baud != 0) { 608 if (baud != tty_termios_baud_rate(old_termios) && baud != 0) {
590 dbg("%s - Setting baud rate to %d baud", __func__, 609 dbg("%s - Setting baud rate to %d baud", __func__,
591 baud); 610 baud);
592 if (cp2101_set_config_single(port, CP2101_BAUDRATE, 611 if (cp210x_set_config_single(port, CP210X_SET_BAUDDIV,
593 ((BAUD_RATE_GEN_FREQ + baud/2) / baud))) { 612 ((BAUD_RATE_GEN_FREQ + baud/2) / baud))) {
594 dbg("Baud rate requested not supported by device\n"); 613 dbg("Baud rate requested not supported by device\n");
595 baud = tty_termios_baud_rate(old_termios); 614 baud = tty_termios_baud_rate(old_termios);
@@ -600,7 +619,7 @@ static void cp2101_set_termios(struct tty_struct *tty,
600 619
601 /* If the number of data bits is to be updated */ 620 /* If the number of data bits is to be updated */
602 if ((cflag & CSIZE) != (old_cflag & CSIZE)) { 621 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
603 cp2101_get_config(port, CP2101_BITS, &bits, 2); 622 cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2);
604 bits &= ~BITS_DATA_MASK; 623 bits &= ~BITS_DATA_MASK;
605 switch (cflag & CSIZE) { 624 switch (cflag & CSIZE) {
606 case CS5: 625 case CS5:
@@ -624,19 +643,19 @@ static void cp2101_set_termios(struct tty_struct *tty,
624 dbg("%s - data bits = 9", __func__); 643 dbg("%s - data bits = 9", __func__);
625 break;*/ 644 break;*/
626 default: 645 default:
627 dbg("cp2101 driver does not " 646 dbg("cp210x driver does not "
628 "support the number of bits requested," 647 "support the number of bits requested,"
629 " using 8 bit mode\n"); 648 " using 8 bit mode\n");
630 bits |= BITS_DATA_8; 649 bits |= BITS_DATA_8;
631 break; 650 break;
632 } 651 }
633 if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) 652 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2))
634 dbg("Number of data bits requested " 653 dbg("Number of data bits requested "
635 "not supported by device\n"); 654 "not supported by device\n");
636 } 655 }
637 656
638 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))) { 657 if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))) {
639 cp2101_get_config(port, CP2101_BITS, &bits, 2); 658 cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2);
640 bits &= ~BITS_PARITY_MASK; 659 bits &= ~BITS_PARITY_MASK;
641 if (cflag & PARENB) { 660 if (cflag & PARENB) {
642 if (cflag & PARODD) { 661 if (cflag & PARODD) {
@@ -647,13 +666,13 @@ static void cp2101_set_termios(struct tty_struct *tty,
647 dbg("%s - parity = EVEN", __func__); 666 dbg("%s - parity = EVEN", __func__);
648 } 667 }
649 } 668 }
650 if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) 669 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2))
651 dbg("Parity mode not supported " 670 dbg("Parity mode not supported "
652 "by device\n"); 671 "by device\n");
653 } 672 }
654 673
655 if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) { 674 if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) {
656 cp2101_get_config(port, CP2101_BITS, &bits, 2); 675 cp210x_get_config(port, CP210X_GET_LINE_CTL, &bits, 2);
657 bits &= ~BITS_STOP_MASK; 676 bits &= ~BITS_STOP_MASK;
658 if (cflag & CSTOPB) { 677 if (cflag & CSTOPB) {
659 bits |= BITS_STOP_2; 678 bits |= BITS_STOP_2;
@@ -662,13 +681,13 @@ static void cp2101_set_termios(struct tty_struct *tty,
662 bits |= BITS_STOP_1; 681 bits |= BITS_STOP_1;
663 dbg("%s - stop bits = 1", __func__); 682 dbg("%s - stop bits = 1", __func__);
664 } 683 }
665 if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) 684 if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2))
666 dbg("Number of stop bits requested " 685 dbg("Number of stop bits requested "
667 "not supported by device\n"); 686 "not supported by device\n");
668 } 687 }
669 688
670 if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) { 689 if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
671 cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); 690 cp210x_get_config(port, CP210X_GET_FLOW, modem_ctl, 16);
672 dbg("%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", 691 dbg("%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x",
673 __func__, modem_ctl[0], modem_ctl[1], 692 __func__, modem_ctl[0], modem_ctl[1],
674 modem_ctl[2], modem_ctl[3]); 693 modem_ctl[2], modem_ctl[3]);
@@ -688,19 +707,19 @@ static void cp2101_set_termios(struct tty_struct *tty,
688 dbg("%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x", 707 dbg("%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x",
689 __func__, modem_ctl[0], modem_ctl[1], 708 __func__, modem_ctl[0], modem_ctl[1],
690 modem_ctl[2], modem_ctl[3]); 709 modem_ctl[2], modem_ctl[3]);
691 cp2101_set_config(port, CP2101_MODEMCTL, modem_ctl, 16); 710 cp210x_set_config(port, CP210X_SET_FLOW, modem_ctl, 16);
692 } 711 }
693 712
694} 713}
695 714
696static int cp2101_tiocmset (struct tty_struct *tty, struct file *file, 715static int cp210x_tiocmset (struct tty_struct *tty, struct file *file,
697 unsigned int set, unsigned int clear) 716 unsigned int set, unsigned int clear)
698{ 717{
699 struct usb_serial_port *port = tty->driver_data; 718 struct usb_serial_port *port = tty->driver_data;
700 return cp2101_tiocmset_port(port, file, set, clear); 719 return cp210x_tiocmset_port(port, file, set, clear);
701} 720}
702 721
703static int cp2101_tiocmset_port(struct usb_serial_port *port, struct file *file, 722static int cp210x_tiocmset_port(struct usb_serial_port *port, struct file *file,
704 unsigned int set, unsigned int clear) 723 unsigned int set, unsigned int clear)
705{ 724{
706 unsigned int control = 0; 725 unsigned int control = 0;
@@ -726,10 +745,10 @@ static int cp2101_tiocmset_port(struct usb_serial_port *port, struct file *file,
726 745
727 dbg("%s - control = 0x%.4x", __func__, control); 746 dbg("%s - control = 0x%.4x", __func__, control);
728 747
729 return cp2101_set_config(port, CP2101_CONTROL, &control, 2); 748 return cp210x_set_config(port, CP210X_SET_MHS, &control, 2);
730} 749}
731 750
732static int cp2101_tiocmget (struct tty_struct *tty, struct file *file) 751static int cp210x_tiocmget (struct tty_struct *tty, struct file *file)
733{ 752{
734 struct usb_serial_port *port = tty->driver_data; 753 struct usb_serial_port *port = tty->driver_data;
735 unsigned int control; 754 unsigned int control;
@@ -737,7 +756,7 @@ static int cp2101_tiocmget (struct tty_struct *tty, struct file *file)
737 756
738 dbg("%s - port %d", __func__, port->number); 757 dbg("%s - port %d", __func__, port->number);
739 758
740 cp2101_get_config(port, CP2101_CONTROL, &control, 1); 759 cp210x_get_config(port, CP210X_GET_MDMSTS, &control, 1);
741 760
742 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0) 761 result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0)
743 |((control & CONTROL_RTS) ? TIOCM_RTS : 0) 762 |((control & CONTROL_RTS) ? TIOCM_RTS : 0)
@@ -751,7 +770,7 @@ static int cp2101_tiocmget (struct tty_struct *tty, struct file *file)
751 return result; 770 return result;
752} 771}
753 772
754static void cp2101_break_ctl (struct tty_struct *tty, int break_state) 773static void cp210x_break_ctl (struct tty_struct *tty, int break_state)
755{ 774{
756 struct usb_serial_port *port = tty->driver_data; 775 struct usb_serial_port *port = tty->driver_data;
757 unsigned int state; 776 unsigned int state;
@@ -763,17 +782,17 @@ static void cp2101_break_ctl (struct tty_struct *tty, int break_state)
763 state = BREAK_ON; 782 state = BREAK_ON;
764 dbg("%s - turning break %s", __func__, 783 dbg("%s - turning break %s", __func__,
765 state == BREAK_OFF ? "off" : "on"); 784 state == BREAK_OFF ? "off" : "on");
766 cp2101_set_config(port, CP2101_BREAK, &state, 2); 785 cp210x_set_config(port, CP210X_SET_BREAK, &state, 2);
767} 786}
768 787
769static int cp2101_startup(struct usb_serial *serial) 788static int cp210x_startup(struct usb_serial *serial)
770{ 789{
771 /* CP2101 buffers behave strangely unless device is reset */ 790 /* cp210x buffers behave strangely unless device is reset */
772 usb_reset_device(serial->dev); 791 usb_reset_device(serial->dev);
773 return 0; 792 return 0;
774} 793}
775 794
776static void cp2101_shutdown(struct usb_serial *serial) 795static void cp210x_shutdown(struct usb_serial *serial)
777{ 796{
778 int i; 797 int i;
779 798
@@ -781,21 +800,21 @@ static void cp2101_shutdown(struct usb_serial *serial)
781 800
782 /* Stop reads and writes on all ports */ 801 /* Stop reads and writes on all ports */
783 for (i = 0; i < serial->num_ports; ++i) 802 for (i = 0; i < serial->num_ports; ++i)
784 cp2101_cleanup(serial->port[i]); 803 cp210x_cleanup(serial->port[i]);
785} 804}
786 805
787static int __init cp2101_init(void) 806static int __init cp210x_init(void)
788{ 807{
789 int retval; 808 int retval;
790 809
791 retval = usb_serial_register(&cp2101_device); 810 retval = usb_serial_register(&cp210x_device);
792 if (retval) 811 if (retval)
793 return retval; /* Failed to register */ 812 return retval; /* Failed to register */
794 813
795 retval = usb_register(&cp2101_driver); 814 retval = usb_register(&cp210x_driver);
796 if (retval) { 815 if (retval) {
797 /* Failed to register */ 816 /* Failed to register */
798 usb_serial_deregister(&cp2101_device); 817 usb_serial_deregister(&cp210x_device);
799 return retval; 818 return retval;
800 } 819 }
801 820
@@ -805,14 +824,14 @@ static int __init cp2101_init(void)
805 return 0; 824 return 0;
806} 825}
807 826
808static void __exit cp2101_exit(void) 827static void __exit cp210x_exit(void)
809{ 828{
810 usb_deregister(&cp2101_driver); 829 usb_deregister(&cp210x_driver);
811 usb_serial_deregister(&cp2101_device); 830 usb_serial_deregister(&cp210x_device);
812} 831}
813 832
814module_init(cp2101_init); 833module_init(cp210x_init);
815module_exit(cp2101_exit); 834module_exit(cp210x_exit);
816 835
817MODULE_DESCRIPTION(DRIVER_DESC); 836MODULE_DESCRIPTION(DRIVER_DESC);
818MODULE_VERSION(DRIVER_VERSION); 837MODULE_VERSION(DRIVER_VERSION);
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index dd501bb63ed6..933ba913e66c 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -61,8 +61,7 @@ static int cyberjack_startup(struct usb_serial *serial);
61static void cyberjack_shutdown(struct usb_serial *serial); 61static void cyberjack_shutdown(struct usb_serial *serial);
62static int cyberjack_open(struct tty_struct *tty, 62static int cyberjack_open(struct tty_struct *tty,
63 struct usb_serial_port *port, struct file *filp); 63 struct usb_serial_port *port, struct file *filp);
64static void cyberjack_close(struct tty_struct *tty, 64static void cyberjack_close(struct usb_serial_port *port);
65 struct usb_serial_port *port, struct file *filp);
66static int cyberjack_write(struct tty_struct *tty, 65static int cyberjack_write(struct tty_struct *tty,
67 struct usb_serial_port *port, const unsigned char *buf, int count); 66 struct usb_serial_port *port, const unsigned char *buf, int count);
68static int cyberjack_write_room(struct tty_struct *tty); 67static int cyberjack_write_room(struct tty_struct *tty);
@@ -185,8 +184,7 @@ static int cyberjack_open(struct tty_struct *tty,
185 return result; 184 return result;
186} 185}
187 186
188static void cyberjack_close(struct tty_struct *tty, 187static void cyberjack_close(struct usb_serial_port *port)
189 struct usb_serial_port *port, struct file *filp)
190{ 188{
191 dbg("%s - port %d", __func__, port->number); 189 dbg("%s - port %d", __func__, port->number);
192 190
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index e568710b263f..669f93848539 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -174,8 +174,8 @@ static int cypress_ca42v2_startup(struct usb_serial *serial);
174static void cypress_shutdown(struct usb_serial *serial); 174static void cypress_shutdown(struct usb_serial *serial);
175static int cypress_open(struct tty_struct *tty, 175static int cypress_open(struct tty_struct *tty,
176 struct usb_serial_port *port, struct file *filp); 176 struct usb_serial_port *port, struct file *filp);
177static void cypress_close(struct tty_struct *tty, 177static void cypress_close(struct usb_serial_port *port);
178 struct usb_serial_port *port, struct file *filp); 178static void cypress_dtr_rts(struct usb_serial_port *port, int on);
179static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port, 179static int cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
180 const unsigned char *buf, int count); 180 const unsigned char *buf, int count);
181static void cypress_send(struct usb_serial_port *port); 181static void cypress_send(struct usb_serial_port *port);
@@ -218,6 +218,7 @@ static struct usb_serial_driver cypress_earthmate_device = {
218 .shutdown = cypress_shutdown, 218 .shutdown = cypress_shutdown,
219 .open = cypress_open, 219 .open = cypress_open,
220 .close = cypress_close, 220 .close = cypress_close,
221 .dtr_rts = cypress_dtr_rts,
221 .write = cypress_write, 222 .write = cypress_write,
222 .write_room = cypress_write_room, 223 .write_room = cypress_write_room,
223 .ioctl = cypress_ioctl, 224 .ioctl = cypress_ioctl,
@@ -244,6 +245,7 @@ static struct usb_serial_driver cypress_hidcom_device = {
244 .shutdown = cypress_shutdown, 245 .shutdown = cypress_shutdown,
245 .open = cypress_open, 246 .open = cypress_open,
246 .close = cypress_close, 247 .close = cypress_close,
248 .dtr_rts = cypress_dtr_rts,
247 .write = cypress_write, 249 .write = cypress_write,
248 .write_room = cypress_write_room, 250 .write_room = cypress_write_room,
249 .ioctl = cypress_ioctl, 251 .ioctl = cypress_ioctl,
@@ -270,6 +272,7 @@ static struct usb_serial_driver cypress_ca42v2_device = {
270 .shutdown = cypress_shutdown, 272 .shutdown = cypress_shutdown,
271 .open = cypress_open, 273 .open = cypress_open,
272 .close = cypress_close, 274 .close = cypress_close,
275 .dtr_rts = cypress_dtr_rts,
273 .write = cypress_write, 276 .write = cypress_write,
274 .write_room = cypress_write_room, 277 .write_room = cypress_write_room,
275 .ioctl = cypress_ioctl, 278 .ioctl = cypress_ioctl,
@@ -656,11 +659,7 @@ static int cypress_open(struct tty_struct *tty,
656 priv->rx_flags = 0; 659 priv->rx_flags = 0;
657 spin_unlock_irqrestore(&priv->lock, flags); 660 spin_unlock_irqrestore(&priv->lock, flags);
658 661
659 /* raise both lines and set termios */ 662 /* Set termios */
660 spin_lock_irqsave(&priv->lock, flags);
661 priv->line_control = CONTROL_DTR | CONTROL_RTS;
662 priv->cmd_ctrl = 1;
663 spin_unlock_irqrestore(&priv->lock, flags);
664 result = cypress_write(tty, port, NULL, 0); 663 result = cypress_write(tty, port, NULL, 0);
665 664
666 if (result) { 665 if (result) {
@@ -694,76 +693,42 @@ static int cypress_open(struct tty_struct *tty,
694 __func__, result); 693 __func__, result);
695 cypress_set_dead(port); 694 cypress_set_dead(port);
696 } 695 }
697 696 port->port.drain_delay = 256;
698 return result; 697 return result;
699} /* cypress_open */ 698} /* cypress_open */
700 699
700static void cypress_dtr_rts(struct usb_serial_port *port, int on)
701{
702 struct cypress_private *priv = usb_get_serial_port_data(port);
703 /* drop dtr and rts */
704 priv = usb_get_serial_port_data(port);
705 spin_lock_irq(&priv->lock);
706 if (on == 0)
707 priv->line_control = 0;
708 else
709 priv->line_control = CONTROL_DTR | CONTROL_RTS;
710 priv->cmd_ctrl = 1;
711 spin_unlock_irq(&priv->lock);
712 cypress_write(NULL, port, NULL, 0);
713}
701 714
702static void cypress_close(struct tty_struct *tty, 715static void cypress_close(struct usb_serial_port *port)
703 struct usb_serial_port *port, struct file *filp)
704{ 716{
705 struct cypress_private *priv = usb_get_serial_port_data(port); 717 struct cypress_private *priv = usb_get_serial_port_data(port);
706 unsigned int c_cflag;
707 int bps;
708 long timeout;
709 wait_queue_t wait;
710 718
711 dbg("%s - port %d", __func__, port->number); 719 dbg("%s - port %d", __func__, port->number);
712 720
713 /* wait for data to drain from buffer */
714 spin_lock_irq(&priv->lock);
715 timeout = CYPRESS_CLOSING_WAIT;
716 init_waitqueue_entry(&wait, current);
717 add_wait_queue(&tty->write_wait, &wait);
718 for (;;) {
719 set_current_state(TASK_INTERRUPTIBLE);
720 if (cypress_buf_data_avail(priv->buf) == 0
721 || timeout == 0 || signal_pending(current)
722 /* without mutex, allowed due to harmless failure mode */
723 || port->serial->disconnected)
724 break;
725 spin_unlock_irq(&priv->lock);
726 timeout = schedule_timeout(timeout);
727 spin_lock_irq(&priv->lock);
728 }
729 set_current_state(TASK_RUNNING);
730 remove_wait_queue(&tty->write_wait, &wait);
731 /* clear out any remaining data in the buffer */
732 cypress_buf_clear(priv->buf);
733 spin_unlock_irq(&priv->lock);
734
735 /* writing is potentially harmful, lock must be taken */ 721 /* writing is potentially harmful, lock must be taken */
736 mutex_lock(&port->serial->disc_mutex); 722 mutex_lock(&port->serial->disc_mutex);
737 if (port->serial->disconnected) { 723 if (port->serial->disconnected) {
738 mutex_unlock(&port->serial->disc_mutex); 724 mutex_unlock(&port->serial->disc_mutex);
739 return; 725 return;
740 } 726 }
741 /* wait for characters to drain from device */ 727 cypress_buf_clear(priv->buf);
742 if (tty) {
743 bps = tty_get_baud_rate(tty);
744 if (bps > 1200)
745 timeout = max((HZ * 2560) / bps, HZ / 10);
746 else
747 timeout = 2 * HZ;
748 schedule_timeout_interruptible(timeout);
749 }
750
751 dbg("%s - stopping urbs", __func__); 728 dbg("%s - stopping urbs", __func__);
752 usb_kill_urb(port->interrupt_in_urb); 729 usb_kill_urb(port->interrupt_in_urb);
753 usb_kill_urb(port->interrupt_out_urb); 730 usb_kill_urb(port->interrupt_out_urb);
754 731
755 if (tty) {
756 c_cflag = tty->termios->c_cflag;
757 if (c_cflag & HUPCL) {
758 /* drop dtr and rts */
759 priv = usb_get_serial_port_data(port);
760 spin_lock_irq(&priv->lock);
761 priv->line_control = 0;
762 priv->cmd_ctrl = 1;
763 spin_unlock_irq(&priv->lock);
764 cypress_write(tty, port, NULL, 0);
765 }
766 }
767 732
768 if (stats) 733 if (stats)
769 dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n", 734 dev_info(&port->dev, "Statistics: %d Bytes In | %d Bytes Out | %d Commands Issued\n",
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 38ba4ea8b6bf..30f5140eff03 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -422,7 +422,6 @@ struct digi_port {
422 int dp_throttled; 422 int dp_throttled;
423 int dp_throttle_restart; 423 int dp_throttle_restart;
424 wait_queue_head_t dp_flush_wait; 424 wait_queue_head_t dp_flush_wait;
425 int dp_in_close; /* close in progress */
426 wait_queue_head_t dp_close_wait; /* wait queue for close */ 425 wait_queue_head_t dp_close_wait; /* wait queue for close */
427 struct work_struct dp_wakeup_work; 426 struct work_struct dp_wakeup_work;
428 struct usb_serial_port *dp_port; 427 struct usb_serial_port *dp_port;
@@ -456,8 +455,9 @@ static int digi_write_room(struct tty_struct *tty);
456static int digi_chars_in_buffer(struct tty_struct *tty); 455static int digi_chars_in_buffer(struct tty_struct *tty);
457static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, 456static int digi_open(struct tty_struct *tty, struct usb_serial_port *port,
458 struct file *filp); 457 struct file *filp);
459static void digi_close(struct tty_struct *tty, struct usb_serial_port *port, 458static void digi_close(struct usb_serial_port *port);
460 struct file *filp); 459static int digi_carrier_raised(struct usb_serial_port *port);
460static void digi_dtr_rts(struct usb_serial_port *port, int on);
461static int digi_startup_device(struct usb_serial *serial); 461static int digi_startup_device(struct usb_serial *serial);
462static int digi_startup(struct usb_serial *serial); 462static int digi_startup(struct usb_serial *serial);
463static void digi_shutdown(struct usb_serial *serial); 463static void digi_shutdown(struct usb_serial *serial);
@@ -510,6 +510,8 @@ static struct usb_serial_driver digi_acceleport_2_device = {
510 .num_ports = 3, 510 .num_ports = 3,
511 .open = digi_open, 511 .open = digi_open,
512 .close = digi_close, 512 .close = digi_close,
513 .dtr_rts = digi_dtr_rts,
514 .carrier_raised = digi_carrier_raised,
513 .write = digi_write, 515 .write = digi_write,
514 .write_room = digi_write_room, 516 .write_room = digi_write_room,
515 .write_bulk_callback = digi_write_bulk_callback, 517 .write_bulk_callback = digi_write_bulk_callback,
@@ -1328,6 +1330,19 @@ static int digi_chars_in_buffer(struct tty_struct *tty)
1328 1330
1329} 1331}
1330 1332
1333static void digi_dtr_rts(struct usb_serial_port *port, int on)
1334{
1335 /* Adjust DTR and RTS */
1336 digi_set_modem_signals(port, on * (TIOCM_DTR|TIOCM_RTS), 1);
1337}
1338
1339static int digi_carrier_raised(struct usb_serial_port *port)
1340{
1341 struct digi_port *priv = usb_get_serial_port_data(port);
1342 if (priv->dp_modem_signals & TIOCM_CD)
1343 return 1;
1344 return 0;
1345}
1331 1346
1332static int digi_open(struct tty_struct *tty, struct usb_serial_port *port, 1347static int digi_open(struct tty_struct *tty, struct usb_serial_port *port,
1333 struct file *filp) 1348 struct file *filp)
@@ -1336,7 +1351,6 @@ static int digi_open(struct tty_struct *tty, struct usb_serial_port *port,
1336 unsigned char buf[32]; 1351 unsigned char buf[32];
1337 struct digi_port *priv = usb_get_serial_port_data(port); 1352 struct digi_port *priv = usb_get_serial_port_data(port);
1338 struct ktermios not_termios; 1353 struct ktermios not_termios;
1339 unsigned long flags = 0;
1340 1354
1341 dbg("digi_open: TOP: port=%d, open_count=%d", 1355 dbg("digi_open: TOP: port=%d, open_count=%d",
1342 priv->dp_port_num, port->port.count); 1356 priv->dp_port_num, port->port.count);
@@ -1345,26 +1359,6 @@ static int digi_open(struct tty_struct *tty, struct usb_serial_port *port,
1345 if (digi_startup_device(port->serial) != 0) 1359 if (digi_startup_device(port->serial) != 0)
1346 return -ENXIO; 1360 return -ENXIO;
1347 1361
1348 spin_lock_irqsave(&priv->dp_port_lock, flags);
1349
1350 /* don't wait on a close in progress for non-blocking opens */
1351 if (priv->dp_in_close && (filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0) {
1352 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1353 return -EAGAIN;
1354 }
1355
1356 /* wait for a close in progress to finish */
1357 while (priv->dp_in_close) {
1358 cond_wait_interruptible_timeout_irqrestore(
1359 &priv->dp_close_wait, DIGI_RETRY_TIMEOUT,
1360 &priv->dp_port_lock, flags);
1361 if (signal_pending(current))
1362 return -EINTR;
1363 spin_lock_irqsave(&priv->dp_port_lock, flags);
1364 }
1365
1366 spin_unlock_irqrestore(&priv->dp_port_lock, flags);
1367
1368 /* read modem signals automatically whenever they change */ 1362 /* read modem signals automatically whenever they change */
1369 buf[0] = DIGI_CMD_READ_INPUT_SIGNALS; 1363 buf[0] = DIGI_CMD_READ_INPUT_SIGNALS;
1370 buf[1] = priv->dp_port_num; 1364 buf[1] = priv->dp_port_num;
@@ -1387,16 +1381,11 @@ static int digi_open(struct tty_struct *tty, struct usb_serial_port *port,
1387 not_termios.c_iflag = ~tty->termios->c_iflag; 1381 not_termios.c_iflag = ~tty->termios->c_iflag;
1388 digi_set_termios(tty, port, &not_termios); 1382 digi_set_termios(tty, port, &not_termios);
1389 } 1383 }
1390
1391 /* set DTR and RTS */
1392 digi_set_modem_signals(port, TIOCM_DTR|TIOCM_RTS, 1);
1393
1394 return 0; 1384 return 0;
1395} 1385}
1396 1386
1397 1387
1398static void digi_close(struct tty_struct *tty, struct usb_serial_port *port, 1388static void digi_close(struct usb_serial_port *port)
1399 struct file *filp)
1400{ 1389{
1401 DEFINE_WAIT(wait); 1390 DEFINE_WAIT(wait);
1402 int ret; 1391 int ret;
@@ -1411,28 +1400,9 @@ static void digi_close(struct tty_struct *tty, struct usb_serial_port *port,
1411 if (port->serial->disconnected) 1400 if (port->serial->disconnected)
1412 goto exit; 1401 goto exit;
1413 1402
1414 /* do cleanup only after final close on this port */
1415 spin_lock_irq(&priv->dp_port_lock);
1416 priv->dp_in_close = 1;
1417 spin_unlock_irq(&priv->dp_port_lock);
1418
1419 /* tell line discipline to process only XON/XOFF */
1420 tty->closing = 1;
1421
1422 /* wait for output to drain */
1423 if ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0)
1424 tty_wait_until_sent(tty, DIGI_CLOSE_TIMEOUT);
1425
1426 /* flush driver and line discipline buffers */
1427 tty_driver_flush_buffer(tty);
1428 tty_ldisc_flush(tty);
1429
1430 if (port->serial->dev) { 1403 if (port->serial->dev) {
1431 /* wait for transmit idle */ 1404 /* FIXME: Transmit idle belongs in the wait_unti_sent path */
1432 if ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) == 0) 1405 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT);
1433 digi_transmit_idle(port, DIGI_CLOSE_TIMEOUT);
1434 /* drop DTR and RTS */
1435 digi_set_modem_signals(port, 0, 0);
1436 1406
1437 /* disable input flow control */ 1407 /* disable input flow control */
1438 buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL; 1408 buf[0] = DIGI_CMD_SET_INPUT_FLOW_CONTROL;
@@ -1477,11 +1447,9 @@ static void digi_close(struct tty_struct *tty, struct usb_serial_port *port,
1477 /* shutdown any outstanding bulk writes */ 1447 /* shutdown any outstanding bulk writes */
1478 usb_kill_urb(port->write_urb); 1448 usb_kill_urb(port->write_urb);
1479 } 1449 }
1480 tty->closing = 0;
1481exit: 1450exit:
1482 spin_lock_irq(&priv->dp_port_lock); 1451 spin_lock_irq(&priv->dp_port_lock);
1483 priv->dp_write_urb_in_use = 0; 1452 priv->dp_write_urb_in_use = 0;
1484 priv->dp_in_close = 0;
1485 wake_up_interruptible(&priv->dp_close_wait); 1453 wake_up_interruptible(&priv->dp_close_wait);
1486 spin_unlock_irq(&priv->dp_port_lock); 1454 spin_unlock_irq(&priv->dp_port_lock);
1487 mutex_unlock(&port->serial->disc_mutex); 1455 mutex_unlock(&port->serial->disc_mutex);
@@ -1560,7 +1528,6 @@ static int digi_startup(struct usb_serial *serial)
1560 priv->dp_throttled = 0; 1528 priv->dp_throttled = 0;
1561 priv->dp_throttle_restart = 0; 1529 priv->dp_throttle_restart = 0;
1562 init_waitqueue_head(&priv->dp_flush_wait); 1530 init_waitqueue_head(&priv->dp_flush_wait);
1563 priv->dp_in_close = 0;
1564 init_waitqueue_head(&priv->dp_close_wait); 1531 init_waitqueue_head(&priv->dp_close_wait);
1565 INIT_WORK(&priv->dp_wakeup_work, digi_wakeup_write_lock); 1532 INIT_WORK(&priv->dp_wakeup_work, digi_wakeup_write_lock);
1566 priv->dp_port = serial->port[i]; 1533 priv->dp_port = serial->port[i];
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c
index c709ec474a80..2b141ccb0cd9 100644
--- a/drivers/usb/serial/empeg.c
+++ b/drivers/usb/serial/empeg.c
@@ -81,8 +81,7 @@ static int debug;
81/* function prototypes for an empeg-car player */ 81/* function prototypes for an empeg-car player */
82static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port, 82static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port,
83 struct file *filp); 83 struct file *filp);
84static void empeg_close(struct tty_struct *tty, struct usb_serial_port *port, 84static void empeg_close(struct usb_serial_port *port);
85 struct file *filp);
86static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port, 85static int empeg_write(struct tty_struct *tty, struct usb_serial_port *port,
87 const unsigned char *buf, 86 const unsigned char *buf,
88 int count); 87 int count);
@@ -181,8 +180,7 @@ static int empeg_open(struct tty_struct *tty, struct usb_serial_port *port,
181} 180}
182 181
183 182
184static void empeg_close(struct tty_struct *tty, struct usb_serial_port *port, 183static void empeg_close(struct usb_serial_port *port)
185 struct file *filp)
186{ 184{
187 dbg("%s - port %d", __func__, port->number); 185 dbg("%s - port %d", __func__, port->number);
188 186
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index d9fcdaedf389..683304d60615 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -89,6 +89,7 @@ struct ftdi_private {
89 int force_rtscts; /* if non-zero, force RTS-CTS to always 89 int force_rtscts; /* if non-zero, force RTS-CTS to always
90 be enabled */ 90 be enabled */
91 91
92 unsigned int latency; /* latency setting in use */
92 spinlock_t tx_lock; /* spinlock for transmit state */ 93 spinlock_t tx_lock; /* spinlock for transmit state */
93 unsigned long tx_bytes; 94 unsigned long tx_bytes;
94 unsigned long tx_outstanding_bytes; 95 unsigned long tx_outstanding_bytes;
@@ -719,8 +720,8 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port);
719static int ftdi_sio_port_remove(struct usb_serial_port *port); 720static int ftdi_sio_port_remove(struct usb_serial_port *port);
720static int ftdi_open(struct tty_struct *tty, 721static int ftdi_open(struct tty_struct *tty,
721 struct usb_serial_port *port, struct file *filp); 722 struct usb_serial_port *port, struct file *filp);
722static void ftdi_close(struct tty_struct *tty, 723static void ftdi_close(struct usb_serial_port *port);
723 struct usb_serial_port *port, struct file *filp); 724static void ftdi_dtr_rts(struct usb_serial_port *port, int on);
724static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port, 725static int ftdi_write(struct tty_struct *tty, struct usb_serial_port *port,
725 const unsigned char *buf, int count); 726 const unsigned char *buf, int count);
726static int ftdi_write_room(struct tty_struct *tty); 727static int ftdi_write_room(struct tty_struct *tty);
@@ -758,6 +759,7 @@ static struct usb_serial_driver ftdi_sio_device = {
758 .port_remove = ftdi_sio_port_remove, 759 .port_remove = ftdi_sio_port_remove,
759 .open = ftdi_open, 760 .open = ftdi_open,
760 .close = ftdi_close, 761 .close = ftdi_close,
762 .dtr_rts = ftdi_dtr_rts,
761 .throttle = ftdi_throttle, 763 .throttle = ftdi_throttle,
762 .unthrottle = ftdi_unthrottle, 764 .unthrottle = ftdi_unthrottle,
763 .write = ftdi_write, 765 .write = ftdi_write,
@@ -1037,7 +1039,54 @@ static int change_speed(struct tty_struct *tty, struct usb_serial_port *port)
1037 return rv; 1039 return rv;
1038} 1040}
1039 1041
1042static int write_latency_timer(struct usb_serial_port *port)
1043{
1044 struct ftdi_private *priv = usb_get_serial_port_data(port);
1045 struct usb_device *udev = port->serial->dev;
1046 char buf[1];
1047 int rv = 0;
1048 int l = priv->latency;
1049
1050 if (priv->flags & ASYNC_LOW_LATENCY)
1051 l = 1;
1052
1053 dbg("%s: setting latency timer = %i", __func__, l);
1054
1055 rv = usb_control_msg(udev,
1056 usb_sndctrlpipe(udev, 0),
1057 FTDI_SIO_SET_LATENCY_TIMER_REQUEST,
1058 FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE,
1059 l, priv->interface,
1060 buf, 0, WDR_TIMEOUT);
1061
1062 if (rv < 0)
1063 dev_err(&port->dev, "Unable to write latency timer: %i\n", rv);
1064 return rv;
1065}
1066
1067static int read_latency_timer(struct usb_serial_port *port)
1068{
1069 struct ftdi_private *priv = usb_get_serial_port_data(port);
1070 struct usb_device *udev = port->serial->dev;
1071 unsigned short latency = 0;
1072 int rv = 0;
1073
1040 1074
1075 dbg("%s", __func__);
1076
1077 rv = usb_control_msg(udev,
1078 usb_rcvctrlpipe(udev, 0),
1079 FTDI_SIO_GET_LATENCY_TIMER_REQUEST,
1080 FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE,
1081 0, priv->interface,
1082 (char *) &latency, 1, WDR_TIMEOUT);
1083
1084 if (rv < 0) {
1085 dev_err(&port->dev, "Unable to read latency timer: %i\n", rv);
1086 return -EIO;
1087 }
1088 return latency;
1089}
1041 1090
1042static int get_serial_info(struct usb_serial_port *port, 1091static int get_serial_info(struct usb_serial_port *port,
1043 struct serial_struct __user *retinfo) 1092 struct serial_struct __user *retinfo)
@@ -1097,6 +1146,7 @@ static int set_serial_info(struct tty_struct *tty,
1097 priv->custom_divisor = new_serial.custom_divisor; 1146 priv->custom_divisor = new_serial.custom_divisor;
1098 1147
1099 tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1148 tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1149 write_latency_timer(port);
1100 1150
1101check_and_exit: 1151check_and_exit:
1102 if ((old_priv.flags & ASYNC_SPD_MASK) != 1152 if ((old_priv.flags & ASYNC_SPD_MASK) !=
@@ -1192,27 +1242,13 @@ static ssize_t show_latency_timer(struct device *dev,
1192{ 1242{
1193 struct usb_serial_port *port = to_usb_serial_port(dev); 1243 struct usb_serial_port *port = to_usb_serial_port(dev);
1194 struct ftdi_private *priv = usb_get_serial_port_data(port); 1244 struct ftdi_private *priv = usb_get_serial_port_data(port);
1195 struct usb_device *udev = port->serial->dev; 1245 if (priv->flags & ASYNC_LOW_LATENCY)
1196 unsigned short latency = 0; 1246 return sprintf(buf, "1\n");
1197 int rv = 0; 1247 else
1198 1248 return sprintf(buf, "%i\n", priv->latency);
1199
1200 dbg("%s", __func__);
1201
1202 rv = usb_control_msg(udev,
1203 usb_rcvctrlpipe(udev, 0),
1204 FTDI_SIO_GET_LATENCY_TIMER_REQUEST,
1205 FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE,
1206 0, priv->interface,
1207 (char *) &latency, 1, WDR_TIMEOUT);
1208
1209 if (rv < 0) {
1210 dev_err(dev, "Unable to read latency timer: %i\n", rv);
1211 return -EIO;
1212 }
1213 return sprintf(buf, "%i\n", latency);
1214} 1249}
1215 1250
1251
1216/* Write a new value of the latency timer, in units of milliseconds. */ 1252/* Write a new value of the latency timer, in units of milliseconds. */
1217static ssize_t store_latency_timer(struct device *dev, 1253static ssize_t store_latency_timer(struct device *dev,
1218 struct device_attribute *attr, const char *valbuf, 1254 struct device_attribute *attr, const char *valbuf,
@@ -1220,25 +1256,13 @@ static ssize_t store_latency_timer(struct device *dev,
1220{ 1256{
1221 struct usb_serial_port *port = to_usb_serial_port(dev); 1257 struct usb_serial_port *port = to_usb_serial_port(dev);
1222 struct ftdi_private *priv = usb_get_serial_port_data(port); 1258 struct ftdi_private *priv = usb_get_serial_port_data(port);
1223 struct usb_device *udev = port->serial->dev;
1224 char buf[1];
1225 int v = simple_strtoul(valbuf, NULL, 10); 1259 int v = simple_strtoul(valbuf, NULL, 10);
1226 int rv = 0; 1260 int rv = 0;
1227 1261
1228 dbg("%s: setting latency timer = %i", __func__, v); 1262 priv->latency = v;
1229 1263 rv = write_latency_timer(port);
1230 rv = usb_control_msg(udev, 1264 if (rv < 0)
1231 usb_sndctrlpipe(udev, 0),
1232 FTDI_SIO_SET_LATENCY_TIMER_REQUEST,
1233 FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE,
1234 v, priv->interface,
1235 buf, 0, WDR_TIMEOUT);
1236
1237 if (rv < 0) {
1238 dev_err(dev, "Unable to write latency timer: %i\n", rv);
1239 return -EIO; 1265 return -EIO;
1240 }
1241
1242 return count; 1266 return count;
1243} 1267}
1244 1268
@@ -1392,6 +1416,7 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
1392 usb_set_serial_port_data(port, priv); 1416 usb_set_serial_port_data(port, priv);
1393 1417
1394 ftdi_determine_type(port); 1418 ftdi_determine_type(port);
1419 read_latency_timer(port);
1395 create_sysfs_attrs(port); 1420 create_sysfs_attrs(port);
1396 return 0; 1421 return 0;
1397} 1422}
@@ -1514,6 +1539,8 @@ static int ftdi_open(struct tty_struct *tty,
1514 if (tty) 1539 if (tty)
1515 tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1540 tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1516 1541
1542 write_latency_timer(port);
1543
1517 /* No error checking for this (will get errors later anyway) */ 1544 /* No error checking for this (will get errors later anyway) */
1518 /* See ftdi_sio.h for description of what is reset */ 1545 /* See ftdi_sio.h for description of what is reset */
1519 usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 1546 usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
@@ -1529,11 +1556,6 @@ static int ftdi_open(struct tty_struct *tty,
1529 if (tty) 1556 if (tty)
1530 ftdi_set_termios(tty, port, tty->termios); 1557 ftdi_set_termios(tty, port, tty->termios);
1531 1558
1532 /* FIXME: Flow control might be enabled, so it should be checked -
1533 we have no control of defaults! */
1534 /* Turn on RTS and DTR since we are not flow controlling by default */
1535 set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1536
1537 /* Not throttled */ 1559 /* Not throttled */
1538 spin_lock_irqsave(&priv->rx_lock, flags); 1560 spin_lock_irqsave(&priv->rx_lock, flags);
1539 priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED); 1561 priv->rx_flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
@@ -1558,6 +1580,30 @@ static int ftdi_open(struct tty_struct *tty,
1558} /* ftdi_open */ 1580} /* ftdi_open */
1559 1581
1560 1582
1583static void ftdi_dtr_rts(struct usb_serial_port *port, int on)
1584{
1585 struct ftdi_private *priv = usb_get_serial_port_data(port);
1586 char buf[1];
1587
1588 mutex_lock(&port->serial->disc_mutex);
1589 if (!port->serial->disconnected) {
1590 /* Disable flow control */
1591 if (!on && usb_control_msg(port->serial->dev,
1592 usb_sndctrlpipe(port->serial->dev, 0),
1593 FTDI_SIO_SET_FLOW_CTRL_REQUEST,
1594 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
1595 0, priv->interface, buf, 0,
1596 WDR_TIMEOUT) < 0) {
1597 dev_err(&port->dev, "error from flowcontrol urb\n");
1598 }
1599 /* drop RTS and DTR */
1600 if (on)
1601 set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1602 else
1603 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1604 }
1605 mutex_unlock(&port->serial->disc_mutex);
1606}
1561 1607
1562/* 1608/*
1563 * usbserial:__serial_close only calls ftdi_close if the point is open 1609 * usbserial:__serial_close only calls ftdi_close if the point is open
@@ -1567,31 +1613,12 @@ static int ftdi_open(struct tty_struct *tty,
1567 * 1613 *
1568 */ 1614 */
1569 1615
1570static void ftdi_close(struct tty_struct *tty, 1616static void ftdi_close(struct usb_serial_port *port)
1571 struct usb_serial_port *port, struct file *filp)
1572{ /* ftdi_close */ 1617{ /* ftdi_close */
1573 unsigned int c_cflag = tty->termios->c_cflag;
1574 struct ftdi_private *priv = usb_get_serial_port_data(port); 1618 struct ftdi_private *priv = usb_get_serial_port_data(port);
1575 char buf[1];
1576 1619
1577 dbg("%s", __func__); 1620 dbg("%s", __func__);
1578 1621
1579 mutex_lock(&port->serial->disc_mutex);
1580 if (c_cflag & HUPCL && !port->serial->disconnected) {
1581 /* Disable flow control */
1582 if (usb_control_msg(port->serial->dev,
1583 usb_sndctrlpipe(port->serial->dev, 0),
1584 FTDI_SIO_SET_FLOW_CTRL_REQUEST,
1585 FTDI_SIO_SET_FLOW_CTRL_REQUEST_TYPE,
1586 0, priv->interface, buf, 0,
1587 WDR_TIMEOUT) < 0) {
1588 dev_err(&port->dev, "error from flowcontrol urb\n");
1589 }
1590
1591 /* drop RTS and DTR */
1592 clear_mctrl(port, TIOCM_DTR | TIOCM_RTS);
1593 } /* Note change no line if hupcl is off */
1594 mutex_unlock(&port->serial->disc_mutex);
1595 1622
1596 /* cancel any scheduled reading */ 1623 /* cancel any scheduled reading */
1597 cancel_delayed_work_sync(&priv->rx_work); 1624 cancel_delayed_work_sync(&priv->rx_work);
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 586d30ff450b..ee25a3fe3b09 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -993,8 +993,7 @@ static int garmin_open(struct tty_struct *tty,
993} 993}
994 994
995 995
996static void garmin_close(struct tty_struct *tty, 996static void garmin_close(struct usb_serial_port *port)
997 struct usb_serial_port *port, struct file *filp)
998{ 997{
999 struct usb_serial *serial = port->serial; 998 struct usb_serial *serial = port->serial;
1000 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port); 999 struct garmin_data *garmin_data_p = usb_get_serial_port_data(port);
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 4cec9906ccf3..be82ea956720 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -184,8 +184,7 @@ int usb_serial_generic_resume(struct usb_serial *serial)
184} 184}
185EXPORT_SYMBOL_GPL(usb_serial_generic_resume); 185EXPORT_SYMBOL_GPL(usb_serial_generic_resume);
186 186
187void usb_serial_generic_close(struct tty_struct *tty, 187void usb_serial_generic_close(struct usb_serial_port *port)
188 struct usb_serial_port *port, struct file *filp)
189{ 188{
190 dbg("%s - port %d", __func__, port->number); 189 dbg("%s - port %d", __func__, port->number);
191 generic_cleanup(port); 190 generic_cleanup(port);
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index fb4a73d090f6..53ef5996e33d 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -207,8 +207,7 @@ static void edge_bulk_out_cmd_callback(struct urb *urb);
207/* function prototypes for the usbserial callbacks */ 207/* function prototypes for the usbserial callbacks */
208static int edge_open(struct tty_struct *tty, struct usb_serial_port *port, 208static int edge_open(struct tty_struct *tty, struct usb_serial_port *port,
209 struct file *filp); 209 struct file *filp);
210static void edge_close(struct tty_struct *tty, struct usb_serial_port *port, 210static void edge_close(struct usb_serial_port *port);
211 struct file *filp);
212static int edge_write(struct tty_struct *tty, struct usb_serial_port *port, 211static int edge_write(struct tty_struct *tty, struct usb_serial_port *port,
213 const unsigned char *buf, int count); 212 const unsigned char *buf, int count);
214static int edge_write_room(struct tty_struct *tty); 213static int edge_write_room(struct tty_struct *tty);
@@ -965,7 +964,7 @@ static int edge_open(struct tty_struct *tty,
965 964
966 if (!edge_port->txfifo.fifo) { 965 if (!edge_port->txfifo.fifo) {
967 dbg("%s - no memory", __func__); 966 dbg("%s - no memory", __func__);
968 edge_close(tty, port, filp); 967 edge_close(port);
969 return -ENOMEM; 968 return -ENOMEM;
970 } 969 }
971 970
@@ -975,7 +974,7 @@ static int edge_open(struct tty_struct *tty,
975 974
976 if (!edge_port->write_urb) { 975 if (!edge_port->write_urb) {
977 dbg("%s - no memory", __func__); 976 dbg("%s - no memory", __func__);
978 edge_close(tty, port, filp); 977 edge_close(port);
979 return -ENOMEM; 978 return -ENOMEM;
980 } 979 }
981 980
@@ -1099,8 +1098,7 @@ static void block_until_tx_empty(struct edgeport_port *edge_port)
1099 * edge_close 1098 * edge_close
1100 * this function is called by the tty driver when a port is closed 1099 * this function is called by the tty driver when a port is closed
1101 *****************************************************************************/ 1100 *****************************************************************************/
1102static void edge_close(struct tty_struct *tty, 1101static void edge_close(struct usb_serial_port *port)
1103 struct usb_serial_port *port, struct file *filp)
1104{ 1102{
1105 struct edgeport_serial *edge_serial; 1103 struct edgeport_serial *edge_serial;
1106 struct edgeport_port *edge_port; 1104 struct edgeport_port *edge_port;
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 513b25e044c1..eabf20eeb370 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -2009,8 +2009,7 @@ release_es_lock:
2009 return status; 2009 return status;
2010} 2010}
2011 2011
2012static void edge_close(struct tty_struct *tty, 2012static void edge_close(struct usb_serial_port *port)
2013 struct usb_serial_port *port, struct file *filp)
2014{ 2013{
2015 struct edgeport_serial *edge_serial; 2014 struct edgeport_serial *edge_serial;
2016 struct edgeport_port *edge_port; 2015 struct edgeport_port *edge_port;
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index cd62825a9ac3..c610a99fa477 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -76,8 +76,7 @@ static int initial_wait;
76/* Function prototypes for an ipaq */ 76/* Function prototypes for an ipaq */
77static int ipaq_open(struct tty_struct *tty, 77static int ipaq_open(struct tty_struct *tty,
78 struct usb_serial_port *port, struct file *filp); 78 struct usb_serial_port *port, struct file *filp);
79static void ipaq_close(struct tty_struct *tty, 79static void ipaq_close(struct usb_serial_port *port);
80 struct usb_serial_port *port, struct file *filp);
81static int ipaq_calc_num_ports(struct usb_serial *serial); 80static int ipaq_calc_num_ports(struct usb_serial *serial);
82static int ipaq_startup(struct usb_serial *serial); 81static int ipaq_startup(struct usb_serial *serial);
83static void ipaq_shutdown(struct usb_serial *serial); 82static void ipaq_shutdown(struct usb_serial *serial);
@@ -714,8 +713,7 @@ error:
714} 713}
715 714
716 715
717static void ipaq_close(struct tty_struct *tty, 716static void ipaq_close(struct usb_serial_port *port)
718 struct usb_serial_port *port, struct file *filp)
719{ 717{
720 struct ipaq_private *priv = usb_get_serial_port_data(port); 718 struct ipaq_private *priv = usb_get_serial_port_data(port);
721 719
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index da2a2b46644a..29ad038b9c8d 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -302,23 +302,17 @@ static int ipw_open(struct tty_struct *tty,
302 return 0; 302 return 0;
303} 303}
304 304
305static void ipw_close(struct tty_struct *tty, 305static void ipw_dtr_rts(struct usb_serial_port *port, int on)
306 struct usb_serial_port *port, struct file *filp)
307{ 306{
308 struct usb_device *dev = port->serial->dev; 307 struct usb_device *dev = port->serial->dev;
309 int result; 308 int result;
310 309
311 if (tty_hung_up_p(filp)) {
312 dbg("%s: tty_hung_up_p ...", __func__);
313 return;
314 }
315
316 /*--1: drop the dtr */ 310 /*--1: drop the dtr */
317 dbg("%s:dropping dtr", __func__); 311 dbg("%s:dropping dtr", __func__);
318 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 312 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
319 IPW_SIO_SET_PIN, 313 IPW_SIO_SET_PIN,
320 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 314 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
321 IPW_PIN_CLRDTR, 315 on ? IPW_PIN_SETDTR : IPW_PIN_CLRDTR,
322 0, 316 0,
323 NULL, 317 NULL,
324 0, 318 0,
@@ -332,7 +326,7 @@ static void ipw_close(struct tty_struct *tty,
332 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 326 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
333 IPW_SIO_SET_PIN, USB_TYPE_VENDOR | 327 IPW_SIO_SET_PIN, USB_TYPE_VENDOR |
334 USB_RECIP_INTERFACE | USB_DIR_OUT, 328 USB_RECIP_INTERFACE | USB_DIR_OUT,
335 IPW_PIN_CLRRTS, 329 on ? IPW_PIN_SETRTS : IPW_PIN_CLRRTS,
336 0, 330 0,
337 NULL, 331 NULL,
338 0, 332 0,
@@ -340,7 +334,12 @@ static void ipw_close(struct tty_struct *tty,
340 if (result < 0) 334 if (result < 0)
341 dev_err(&port->dev, 335 dev_err(&port->dev,
342 "dropping rts failed (error = %d)\n", result); 336 "dropping rts failed (error = %d)\n", result);
337}
343 338
339static void ipw_close(struct usb_serial_port *port)
340{
341 struct usb_device *dev = port->serial->dev;
342 int result;
344 343
345 /*--3: purge */ 344 /*--3: purge */
346 dbg("%s:sending purge", __func__); 345 dbg("%s:sending purge", __func__);
@@ -461,6 +460,7 @@ static struct usb_serial_driver ipw_device = {
461 .num_ports = 1, 460 .num_ports = 1,
462 .open = ipw_open, 461 .open = ipw_open,
463 .close = ipw_close, 462 .close = ipw_close,
463 .dtr_rts = ipw_dtr_rts,
464 .port_probe = ipw_probe, 464 .port_probe = ipw_probe,
465 .port_remove = ipw_disconnect, 465 .port_remove = ipw_disconnect,
466 .write = ipw_write, 466 .write = ipw_write,
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 4e2cda93da59..66009b6b763a 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -88,8 +88,7 @@ static int xbof = -1;
88static int ir_startup (struct usb_serial *serial); 88static int ir_startup (struct usb_serial *serial);
89static int ir_open(struct tty_struct *tty, struct usb_serial_port *port, 89static int ir_open(struct tty_struct *tty, struct usb_serial_port *port,
90 struct file *filep); 90 struct file *filep);
91static void ir_close(struct tty_struct *tty, struct usb_serial_port *port, 91static void ir_close(struct usb_serial_port *port);
92 struct file *filep);
93static int ir_write(struct tty_struct *tty, struct usb_serial_port *port, 92static int ir_write(struct tty_struct *tty, struct usb_serial_port *port,
94 const unsigned char *buf, int count); 93 const unsigned char *buf, int count);
95static void ir_write_bulk_callback (struct urb *urb); 94static void ir_write_bulk_callback (struct urb *urb);
@@ -346,8 +345,7 @@ static int ir_open(struct tty_struct *tty,
346 return result; 345 return result;
347} 346}
348 347
349static void ir_close(struct tty_struct *tty, 348static void ir_close(struct usb_serial_port *port)
350 struct usb_serial_port *port, struct file * filp)
351{ 349{
352 dbg("%s - port %d", __func__, port->number); 350 dbg("%s - port %d", __func__, port->number);
353 351
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index 4473d442b2aa..76a3cc327bb9 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -40,7 +40,7 @@ static int debug;
40/* 40/*
41 * Version Information 41 * Version Information
42 */ 42 */
43#define DRIVER_VERSION "v0.5" 43#define DRIVER_VERSION "v0.10"
44#define DRIVER_DESC "Infinity USB Unlimited Phoenix driver" 44#define DRIVER_DESC "Infinity USB Unlimited Phoenix driver"
45 45
46static struct usb_device_id id_table[] = { 46static struct usb_device_id id_table[] = {
@@ -70,7 +70,6 @@ static void read_rxcmd_callback(struct urb *urb);
70struct iuu_private { 70struct iuu_private {
71 spinlock_t lock; /* store irq state */ 71 spinlock_t lock; /* store irq state */
72 wait_queue_head_t delta_msr_wait; 72 wait_queue_head_t delta_msr_wait;
73 u8 line_control;
74 u8 line_status; 73 u8 line_status;
75 u8 termios_initialized; 74 u8 termios_initialized;
76 int tiostatus; /* store IUART SIGNAL for tiocmget call */ 75 int tiostatus; /* store IUART SIGNAL for tiocmget call */
@@ -651,32 +650,33 @@ static int iuu_bulk_write(struct usb_serial_port *port)
651 unsigned long flags; 650 unsigned long flags;
652 int result; 651 int result;
653 int i; 652 int i;
653 int buf_len;
654 char *buf_ptr = port->write_urb->transfer_buffer; 654 char *buf_ptr = port->write_urb->transfer_buffer;
655 dbg("%s - enter", __func__); 655 dbg("%s - enter", __func__);
656 656
657 spin_lock_irqsave(&priv->lock, flags);
657 *buf_ptr++ = IUU_UART_ESC; 658 *buf_ptr++ = IUU_UART_ESC;
658 *buf_ptr++ = IUU_UART_TX; 659 *buf_ptr++ = IUU_UART_TX;
659 *buf_ptr++ = priv->writelen; 660 *buf_ptr++ = priv->writelen;
660 661
661 memcpy(buf_ptr, priv->writebuf, 662 memcpy(buf_ptr, priv->writebuf, priv->writelen);
662 priv->writelen); 663 buf_len = priv->writelen;
664 priv->writelen = 0;
665 spin_unlock_irqrestore(&priv->lock, flags);
663 if (debug == 1) { 666 if (debug == 1) {
664 for (i = 0; i < priv->writelen; i++) 667 for (i = 0; i < buf_len; i++)
665 sprintf(priv->dbgbuf + i*2 , 668 sprintf(priv->dbgbuf + i*2 ,
666 "%02X", priv->writebuf[i]); 669 "%02X", priv->writebuf[i]);
667 priv->dbgbuf[priv->writelen+i*2] = 0; 670 priv->dbgbuf[buf_len+i*2] = 0;
668 dbg("%s - writing %i chars : %s", __func__, 671 dbg("%s - writing %i chars : %s", __func__,
669 priv->writelen, priv->dbgbuf); 672 buf_len, priv->dbgbuf);
670 } 673 }
671 usb_fill_bulk_urb(port->write_urb, port->serial->dev, 674 usb_fill_bulk_urb(port->write_urb, port->serial->dev,
672 usb_sndbulkpipe(port->serial->dev, 675 usb_sndbulkpipe(port->serial->dev,
673 port->bulk_out_endpointAddress), 676 port->bulk_out_endpointAddress),
674 port->write_urb->transfer_buffer, priv->writelen + 3, 677 port->write_urb->transfer_buffer, buf_len + 3,
675 iuu_rxcmd, port); 678 iuu_rxcmd, port);
676 result = usb_submit_urb(port->write_urb, GFP_ATOMIC); 679 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
677 spin_lock_irqsave(&priv->lock, flags);
678 priv->writelen = 0;
679 spin_unlock_irqrestore(&priv->lock, flags);
680 usb_serial_port_softint(port); 680 usb_serial_port_softint(port);
681 return result; 681 return result;
682} 682}
@@ -770,14 +770,10 @@ static int iuu_uart_write(struct tty_struct *tty, struct usb_serial_port *port,
770 return -ENOMEM; 770 return -ENOMEM;
771 771
772 spin_lock_irqsave(&priv->lock, flags); 772 spin_lock_irqsave(&priv->lock, flags);
773 if (priv->writelen > 0) { 773
774 /* buffer already filled but not commited */
775 spin_unlock_irqrestore(&priv->lock, flags);
776 return 0;
777 }
778 /* fill the buffer */ 774 /* fill the buffer */
779 memcpy(priv->writebuf, buf, count); 775 memcpy(priv->writebuf + priv->writelen, buf, count);
780 priv->writelen = count; 776 priv->writelen += count;
781 spin_unlock_irqrestore(&priv->lock, flags); 777 spin_unlock_irqrestore(&priv->lock, flags);
782 778
783 return count; 779 return count;
@@ -819,7 +815,7 @@ static int iuu_uart_on(struct usb_serial_port *port)
819 buf[0] = IUU_UART_ENABLE; 815 buf[0] = IUU_UART_ENABLE;
820 buf[1] = (u8) ((IUU_BAUD_9600 >> 8) & 0x00FF); 816 buf[1] = (u8) ((IUU_BAUD_9600 >> 8) & 0x00FF);
821 buf[2] = (u8) (0x00FF & IUU_BAUD_9600); 817 buf[2] = (u8) (0x00FF & IUU_BAUD_9600);
822 buf[3] = (u8) (0x0F0 & IUU_TWO_STOP_BITS) | (0x07 & IUU_PARITY_EVEN); 818 buf[3] = (u8) (0x0F0 & IUU_ONE_STOP_BIT) | (0x07 & IUU_PARITY_EVEN);
823 819
824 status = bulk_immediate(port, buf, 4); 820 status = bulk_immediate(port, buf, 4);
825 if (status != IUU_OPERATION_OK) { 821 if (status != IUU_OPERATION_OK) {
@@ -946,19 +942,59 @@ static int iuu_uart_baud(struct usb_serial_port *port, u32 baud,
946 return status; 942 return status;
947} 943}
948 944
949static int set_control_lines(struct usb_device *dev, u8 value) 945static void iuu_set_termios(struct tty_struct *tty,
946 struct usb_serial_port *port, struct ktermios *old_termios)
950{ 947{
951 return 0; 948 const u32 supported_mask = CMSPAR|PARENB|PARODD;
949
950 unsigned int cflag = tty->termios->c_cflag;
951 int status;
952 u32 actual;
953 u32 parity;
954 int csize = CS7;
955 int baud = 9600; /* Fixed for the moment */
956 u32 newval = cflag & supported_mask;
957
958 /* compute the parity parameter */
959 parity = 0;
960 if (cflag & CMSPAR) { /* Using mark space */
961 if (cflag & PARODD)
962 parity |= IUU_PARITY_SPACE;
963 else
964 parity |= IUU_PARITY_MARK;
965 } else if (!(cflag & PARENB)) {
966 parity |= IUU_PARITY_NONE;
967 csize = CS8;
968 } else if (cflag & PARODD)
969 parity |= IUU_PARITY_ODD;
970 else
971 parity |= IUU_PARITY_EVEN;
972
973 parity |= (cflag & CSTOPB ? IUU_TWO_STOP_BITS : IUU_ONE_STOP_BIT);
974
975 /* set it */
976 status = iuu_uart_baud(port,
977 (clockmode == 2) ? 16457 : 9600 * boost / 100,
978 &actual, parity);
979
980 /* set the termios value to the real one, so the user now what has
981 * changed. We support few fields so its easies to copy the old hw
982 * settings back over and then adjust them
983 */
984 if (old_termios)
985 tty_termios_copy_hw(tty->termios, old_termios);
986 if (status != 0) /* Set failed - return old bits */
987 return;
988 /* Re-encode speed, parity and csize */
989 tty_encode_baud_rate(tty, baud, baud);
990 tty->termios->c_cflag &= ~(supported_mask|CSIZE);
991 tty->termios->c_cflag |= newval | csize;
952} 992}
953 993
954static void iuu_close(struct tty_struct *tty, 994static void iuu_close(struct usb_serial_port *port)
955 struct usb_serial_port *port, struct file *filp)
956{ 995{
957 /* iuu_led (port,255,0,0,0); */ 996 /* iuu_led (port,255,0,0,0); */
958 struct usb_serial *serial; 997 struct usb_serial *serial;
959 struct iuu_private *priv = usb_get_serial_port_data(port);
960 unsigned long flags;
961 unsigned int c_cflag;
962 998
963 serial = port->serial; 999 serial = port->serial;
964 if (!serial) 1000 if (!serial)
@@ -968,17 +1004,6 @@ static void iuu_close(struct tty_struct *tty,
968 1004
969 iuu_uart_off(port); 1005 iuu_uart_off(port);
970 if (serial->dev) { 1006 if (serial->dev) {
971 if (tty) {
972 c_cflag = tty->termios->c_cflag;
973 if (c_cflag & HUPCL) {
974 /* drop DTR and RTS */
975 priv = usb_get_serial_port_data(port);
976 spin_lock_irqsave(&priv->lock, flags);
977 priv->line_control = 0;
978 spin_unlock_irqrestore(&priv->lock, flags);
979 set_control_lines(port->serial->dev, 0);
980 }
981 }
982 /* free writebuf */ 1007 /* free writebuf */
983 /* shutdown our urbs */ 1008 /* shutdown our urbs */
984 dbg("%s - shutting down urbs", __func__); 1009 dbg("%s - shutting down urbs", __func__);
@@ -1154,7 +1179,7 @@ static int iuu_open(struct tty_struct *tty,
1154 if (result) { 1179 if (result) {
1155 dev_err(&port->dev, "%s - failed submitting read urb," 1180 dev_err(&port->dev, "%s - failed submitting read urb,"
1156 " error %d\n", __func__, result); 1181 " error %d\n", __func__, result);
1157 iuu_close(tty, port, NULL); 1182 iuu_close(port);
1158 return -EPROTO; 1183 return -EPROTO;
1159 } else { 1184 } else {
1160 dbg("%s - rxcmd OK", __func__); 1185 dbg("%s - rxcmd OK", __func__);
@@ -1175,6 +1200,7 @@ static struct usb_serial_driver iuu_device = {
1175 .read_bulk_callback = iuu_uart_read_callback, 1200 .read_bulk_callback = iuu_uart_read_callback,
1176 .tiocmget = iuu_tiocmget, 1201 .tiocmget = iuu_tiocmget,
1177 .tiocmset = iuu_tiocmset, 1202 .tiocmset = iuu_tiocmset,
1203 .set_termios = iuu_set_termios,
1178 .attach = iuu_startup, 1204 .attach = iuu_startup,
1179 .shutdown = iuu_shutdown, 1205 .shutdown = iuu_shutdown,
1180}; 1206};
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 00daa8f7759a..f1195a98f316 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -1298,8 +1298,16 @@ static inline void stop_urb(struct urb *urb)
1298 usb_kill_urb(urb); 1298 usb_kill_urb(urb);
1299} 1299}
1300 1300
1301static void keyspan_close(struct tty_struct *tty, 1301static void keyspan_dtr_rts(struct usb_serial_port *port, int on)
1302 struct usb_serial_port *port, struct file *filp) 1302{
1303 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
1304
1305 p_priv->rts_state = on;
1306 p_priv->dtr_state = on;
1307 keyspan_send_setup(port, 0);
1308}
1309
1310static void keyspan_close(struct usb_serial_port *port)
1303{ 1311{
1304 int i; 1312 int i;
1305 struct usb_serial *serial = port->serial; 1313 struct usb_serial *serial = port->serial;
@@ -1336,7 +1344,6 @@ static void keyspan_close(struct tty_struct *tty,
1336 stop_urb(p_priv->out_urbs[i]); 1344 stop_urb(p_priv->out_urbs[i]);
1337 } 1345 }
1338 } 1346 }
1339 tty_port_tty_set(&port->port, NULL);
1340} 1347}
1341 1348
1342/* download the firmware to a pre-renumeration device */ 1349/* download the firmware to a pre-renumeration device */
diff --git a/drivers/usb/serial/keyspan.h b/drivers/usb/serial/keyspan.h
index 38b4582e0734..0d4569b60768 100644
--- a/drivers/usb/serial/keyspan.h
+++ b/drivers/usb/serial/keyspan.h
@@ -38,9 +38,8 @@
38static int keyspan_open (struct tty_struct *tty, 38static int keyspan_open (struct tty_struct *tty,
39 struct usb_serial_port *port, 39 struct usb_serial_port *port,
40 struct file *filp); 40 struct file *filp);
41static void keyspan_close (struct tty_struct *tty, 41static void keyspan_close (struct usb_serial_port *port);
42 struct usb_serial_port *port, 42static void keyspan_dtr_rts (struct usb_serial_port *port, int on);
43 struct file *filp);
44static int keyspan_startup (struct usb_serial *serial); 43static int keyspan_startup (struct usb_serial *serial);
45static void keyspan_shutdown (struct usb_serial *serial); 44static void keyspan_shutdown (struct usb_serial *serial);
46static int keyspan_write_room (struct tty_struct *tty); 45static int keyspan_write_room (struct tty_struct *tty);
@@ -562,6 +561,7 @@ static struct usb_serial_driver keyspan_1port_device = {
562 .num_ports = 1, 561 .num_ports = 1,
563 .open = keyspan_open, 562 .open = keyspan_open,
564 .close = keyspan_close, 563 .close = keyspan_close,
564 .dtr_rts = keyspan_dtr_rts,
565 .write = keyspan_write, 565 .write = keyspan_write,
566 .write_room = keyspan_write_room, 566 .write_room = keyspan_write_room,
567 .set_termios = keyspan_set_termios, 567 .set_termios = keyspan_set_termios,
@@ -582,6 +582,7 @@ static struct usb_serial_driver keyspan_2port_device = {
582 .num_ports = 2, 582 .num_ports = 2,
583 .open = keyspan_open, 583 .open = keyspan_open,
584 .close = keyspan_close, 584 .close = keyspan_close,
585 .dtr_rts = keyspan_dtr_rts,
585 .write = keyspan_write, 586 .write = keyspan_write,
586 .write_room = keyspan_write_room, 587 .write_room = keyspan_write_room,
587 .set_termios = keyspan_set_termios, 588 .set_termios = keyspan_set_termios,
@@ -602,6 +603,7 @@ static struct usb_serial_driver keyspan_4port_device = {
602 .num_ports = 4, 603 .num_ports = 4,
603 .open = keyspan_open, 604 .open = keyspan_open,
604 .close = keyspan_close, 605 .close = keyspan_close,
606 .dtr_rts = keyspan_dtr_rts,
605 .write = keyspan_write, 607 .write = keyspan_write,
606 .write_room = keyspan_write_room, 608 .write_room = keyspan_write_room,
607 .set_termios = keyspan_set_termios, 609 .set_termios = keyspan_set_termios,
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index bf1ae247da66..ab769dbea1b3 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -651,6 +651,35 @@ static int keyspan_pda_chars_in_buffer(struct tty_struct *tty)
651} 651}
652 652
653 653
654static void keyspan_pda_dtr_rts(struct usb_serial_port *port, int on)
655{
656 struct usb_serial *serial = port->serial;
657
658 if (serial->dev) {
659 if (on)
660 keyspan_pda_set_modem_info(serial, (1<<7) | (1<< 2));
661 else
662 keyspan_pda_set_modem_info(serial, 0);
663 }
664}
665
666static int keyspan_pda_carrier_raised(struct usb_serial_port *port)
667{
668 struct usb_serial *serial = port->serial;
669 unsigned char modembits;
670
671 /* If we can read the modem status and the DCD is low then
672 carrier is not raised yet */
673 if (keyspan_pda_get_modem_info(serial, &modembits) >= 0) {
674 if (!(modembits & (1>>6)))
675 return 0;
676 }
677 /* Carrier raised, or we failed (eg disconnected) so
678 progress accordingly */
679 return 1;
680}
681
682
654static int keyspan_pda_open(struct tty_struct *tty, 683static int keyspan_pda_open(struct tty_struct *tty,
655 struct usb_serial_port *port, struct file *filp) 684 struct usb_serial_port *port, struct file *filp)
656{ 685{
@@ -682,13 +711,6 @@ static int keyspan_pda_open(struct tty_struct *tty,
682 priv->tx_room = room; 711 priv->tx_room = room;
683 priv->tx_throttled = room ? 0 : 1; 712 priv->tx_throttled = room ? 0 : 1;
684 713
685 /* the normal serial device seems to always turn on DTR and RTS here,
686 so do the same */
687 if (tty && (tty->termios->c_cflag & CBAUD))
688 keyspan_pda_set_modem_info(serial, (1<<7) | (1<<2));
689 else
690 keyspan_pda_set_modem_info(serial, 0);
691
692 /*Start reading from the device*/ 714 /*Start reading from the device*/
693 port->interrupt_in_urb->dev = serial->dev; 715 port->interrupt_in_urb->dev = serial->dev;
694 rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 716 rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
@@ -700,19 +722,11 @@ static int keyspan_pda_open(struct tty_struct *tty,
700error: 722error:
701 return rc; 723 return rc;
702} 724}
703 725static void keyspan_pda_close(struct usb_serial_port *port)
704
705static void keyspan_pda_close(struct tty_struct *tty,
706 struct usb_serial_port *port, struct file *filp)
707{ 726{
708 struct usb_serial *serial = port->serial; 727 struct usb_serial *serial = port->serial;
709 728
710 if (serial->dev) { 729 if (serial->dev) {
711 /* the normal serial device seems to always shut
712 off DTR and RTS now */
713 if (tty->termios->c_cflag & HUPCL)
714 keyspan_pda_set_modem_info(serial, 0);
715
716 /* shutdown our bulk reads and writes */ 730 /* shutdown our bulk reads and writes */
717 usb_kill_urb(port->write_urb); 731 usb_kill_urb(port->write_urb);
718 usb_kill_urb(port->interrupt_in_urb); 732 usb_kill_urb(port->interrupt_in_urb);
@@ -839,6 +853,8 @@ static struct usb_serial_driver keyspan_pda_device = {
839 .usb_driver = &keyspan_pda_driver, 853 .usb_driver = &keyspan_pda_driver,
840 .id_table = id_table_std, 854 .id_table = id_table_std,
841 .num_ports = 1, 855 .num_ports = 1,
856 .dtr_rts = keyspan_pda_dtr_rts,
857 .carrier_raised = keyspan_pda_carrier_raised,
842 .open = keyspan_pda_open, 858 .open = keyspan_pda_open,
843 .close = keyspan_pda_close, 859 .close = keyspan_pda_close,
844 .write = keyspan_pda_write, 860 .write = keyspan_pda_write,
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index fcd9082f3e7f..fa817c66b3e8 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -76,8 +76,7 @@ static int klsi_105_startup(struct usb_serial *serial);
76static void klsi_105_shutdown(struct usb_serial *serial); 76static void klsi_105_shutdown(struct usb_serial *serial);
77static int klsi_105_open(struct tty_struct *tty, 77static int klsi_105_open(struct tty_struct *tty,
78 struct usb_serial_port *port, struct file *filp); 78 struct usb_serial_port *port, struct file *filp);
79static void klsi_105_close(struct tty_struct *tty, 79static void klsi_105_close(struct usb_serial_port *port);
80 struct usb_serial_port *port, struct file *filp);
81static int klsi_105_write(struct tty_struct *tty, 80static int klsi_105_write(struct tty_struct *tty,
82 struct usb_serial_port *port, const unsigned char *buf, int count); 81 struct usb_serial_port *port, const unsigned char *buf, int count);
83static void klsi_105_write_bulk_callback(struct urb *urb); 82static void klsi_105_write_bulk_callback(struct urb *urb);
@@ -447,8 +446,7 @@ exit:
447} /* klsi_105_open */ 446} /* klsi_105_open */
448 447
449 448
450static void klsi_105_close(struct tty_struct *tty, 449static void klsi_105_close(struct usb_serial_port *port)
451 struct usb_serial_port *port, struct file *filp)
452{ 450{
453 struct klsi_105_private *priv = usb_get_serial_port_data(port); 451 struct klsi_105_private *priv = usb_get_serial_port_data(port);
454 int rc; 452 int rc;
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index c148544953b3..6b570498287f 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -72,8 +72,7 @@ static int kobil_startup(struct usb_serial *serial);
72static void kobil_shutdown(struct usb_serial *serial); 72static void kobil_shutdown(struct usb_serial *serial);
73static int kobil_open(struct tty_struct *tty, 73static int kobil_open(struct tty_struct *tty,
74 struct usb_serial_port *port, struct file *filp); 74 struct usb_serial_port *port, struct file *filp);
75static void kobil_close(struct tty_struct *tty, struct usb_serial_port *port, 75static void kobil_close(struct usb_serial_port *port);
76 struct file *filp);
77static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, 76static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
78 const unsigned char *buf, int count); 77 const unsigned char *buf, int count);
79static int kobil_write_room(struct tty_struct *tty); 78static int kobil_write_room(struct tty_struct *tty);
@@ -209,7 +208,7 @@ static void kobil_shutdown(struct usb_serial *serial)
209 208
210 for (i = 0; i < serial->num_ports; ++i) { 209 for (i = 0; i < serial->num_ports; ++i) {
211 while (serial->port[i]->port.count > 0) 210 while (serial->port[i]->port.count > 0)
212 kobil_close(NULL, serial->port[i], NULL); 211 kobil_close(serial->port[i]);
213 kfree(usb_get_serial_port_data(serial->port[i])); 212 kfree(usb_get_serial_port_data(serial->port[i]));
214 usb_set_serial_port_data(serial->port[i], NULL); 213 usb_set_serial_port_data(serial->port[i], NULL);
215 } 214 }
@@ -346,11 +345,11 @@ static int kobil_open(struct tty_struct *tty,
346} 345}
347 346
348 347
349static void kobil_close(struct tty_struct *tty, 348static void kobil_close(struct usb_serial_port *port)
350 struct usb_serial_port *port, struct file *filp)
351{ 349{
352 dbg("%s - port %d", __func__, port->number); 350 dbg("%s - port %d", __func__, port->number);
353 351
352 /* FIXME: Add rts/dtr methods */
354 if (port->write_urb) { 353 if (port->write_urb) {
355 usb_kill_urb(port->write_urb); 354 usb_kill_urb(port->write_urb);
356 usb_free_urb(port->write_urb); 355 usb_free_urb(port->write_urb);
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index 82930a7d5093..873795548fc0 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -95,8 +95,8 @@ static int mct_u232_startup(struct usb_serial *serial);
95static void mct_u232_shutdown(struct usb_serial *serial); 95static void mct_u232_shutdown(struct usb_serial *serial);
96static int mct_u232_open(struct tty_struct *tty, 96static int mct_u232_open(struct tty_struct *tty,
97 struct usb_serial_port *port, struct file *filp); 97 struct usb_serial_port *port, struct file *filp);
98static void mct_u232_close(struct tty_struct *tty, 98static void mct_u232_close(struct usb_serial_port *port);
99 struct usb_serial_port *port, struct file *filp); 99static void mct_u232_dtr_rts(struct usb_serial_port *port, int on);
100static void mct_u232_read_int_callback(struct urb *urb); 100static void mct_u232_read_int_callback(struct urb *urb);
101static void mct_u232_set_termios(struct tty_struct *tty, 101static void mct_u232_set_termios(struct tty_struct *tty,
102 struct usb_serial_port *port, struct ktermios *old); 102 struct usb_serial_port *port, struct ktermios *old);
@@ -140,6 +140,7 @@ static struct usb_serial_driver mct_u232_device = {
140 .num_ports = 1, 140 .num_ports = 1,
141 .open = mct_u232_open, 141 .open = mct_u232_open,
142 .close = mct_u232_close, 142 .close = mct_u232_close,
143 .dtr_rts = mct_u232_dtr_rts,
143 .throttle = mct_u232_throttle, 144 .throttle = mct_u232_throttle,
144 .unthrottle = mct_u232_unthrottle, 145 .unthrottle = mct_u232_unthrottle,
145 .read_int_callback = mct_u232_read_int_callback, 146 .read_int_callback = mct_u232_read_int_callback,
@@ -496,29 +497,29 @@ error:
496 return retval; 497 return retval;
497} /* mct_u232_open */ 498} /* mct_u232_open */
498 499
499 500static void mct_u232_dtr_rts(struct usb_serial_port *port, int on)
500static void mct_u232_close(struct tty_struct *tty,
501 struct usb_serial_port *port, struct file *filp)
502{ 501{
503 unsigned int c_cflag;
504 unsigned int control_state; 502 unsigned int control_state;
505 struct mct_u232_private *priv = usb_get_serial_port_data(port); 503 struct mct_u232_private *priv = usb_get_serial_port_data(port);
506 dbg("%s port %d", __func__, port->number);
507 504
508 if (tty) { 505 mutex_lock(&port->serial->disc_mutex);
509 c_cflag = tty->termios->c_cflag; 506 if (!port->serial->disconnected) {
510 mutex_lock(&port->serial->disc_mutex); 507 /* drop DTR and RTS */
511 if (c_cflag & HUPCL && !port->serial->disconnected) { 508 spin_lock_irq(&priv->lock);
512 /* drop DTR and RTS */ 509 if (on)
513 spin_lock_irq(&priv->lock); 510 priv->control_state |= TIOCM_DTR | TIOCM_RTS;
511 else
514 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); 512 priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
515 control_state = priv->control_state; 513 control_state = priv->control_state;
516 spin_unlock_irq(&priv->lock); 514 spin_unlock_irq(&priv->lock);
517 mct_u232_set_modem_ctrl(port->serial, control_state); 515 mct_u232_set_modem_ctrl(port->serial, control_state);
518 }
519 mutex_unlock(&port->serial->disc_mutex);
520 } 516 }
517 mutex_unlock(&port->serial->disc_mutex);
518}
521 519
520static void mct_u232_close(struct usb_serial_port *port)
521{
522 dbg("%s port %d", __func__, port->number);
522 523
523 if (port->serial->dev) { 524 if (port->serial->dev) {
524 /* shutdown our urbs */ 525 /* shutdown our urbs */
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 24e3b5d4b4d4..9e1a013ee7f6 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -533,8 +533,7 @@ static int mos7720_chars_in_buffer(struct tty_struct *tty)
533 return chars; 533 return chars;
534} 534}
535 535
536static void mos7720_close(struct tty_struct *tty, 536static void mos7720_close(struct usb_serial_port *port)
537 struct usb_serial_port *port, struct file *filp)
538{ 537{
539 struct usb_serial *serial; 538 struct usb_serial *serial;
540 struct moschip_port *mos7720_port; 539 struct moschip_port *mos7720_port;
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 84fb1dcd30dc..10b78a37214f 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -1135,54 +1135,12 @@ static int mos7840_chars_in_buffer(struct tty_struct *tty)
1135 1135
1136} 1136}
1137 1137
1138/************************************************************************
1139 *
1140 * mos7840_block_until_tx_empty
1141 *
1142 * This function will block the close until one of the following:
1143 * 1. TX count are 0
1144 * 2. The mos7840 has stopped
1145 * 3. A timeout of 3 seconds without activity has expired
1146 *
1147 ************************************************************************/
1148static void mos7840_block_until_tx_empty(struct tty_struct *tty,
1149 struct moschip_port *mos7840_port)
1150{
1151 int timeout = HZ / 10;
1152 int wait = 30;
1153 int count;
1154
1155 while (1) {
1156
1157 count = mos7840_chars_in_buffer(tty);
1158
1159 /* Check for Buffer status */
1160 if (count <= 0)
1161 return;
1162
1163 /* Block the thread for a while */
1164 interruptible_sleep_on_timeout(&mos7840_port->wait_chase,
1165 timeout);
1166
1167 /* No activity.. count down section */
1168 wait--;
1169 if (wait == 0) {
1170 dbg("%s - TIMEOUT", __func__);
1171 return;
1172 } else {
1173 /* Reset timeout value back to seconds */
1174 wait = 30;
1175 }
1176 }
1177}
1178
1179/***************************************************************************** 1138/*****************************************************************************
1180 * mos7840_close 1139 * mos7840_close
1181 * this function is called by the tty driver when a port is closed 1140 * this function is called by the tty driver when a port is closed
1182 *****************************************************************************/ 1141 *****************************************************************************/
1183 1142
1184static void mos7840_close(struct tty_struct *tty, 1143static void mos7840_close(struct usb_serial_port *port)
1185 struct usb_serial_port *port, struct file *filp)
1186{ 1144{
1187 struct usb_serial *serial; 1145 struct usb_serial *serial;
1188 struct moschip_port *mos7840_port; 1146 struct moschip_port *mos7840_port;
@@ -1223,10 +1181,6 @@ static void mos7840_close(struct tty_struct *tty,
1223 } 1181 }
1224 } 1182 }
1225 1183
1226 if (serial->dev)
1227 /* flush and block until tx is empty */
1228 mos7840_block_until_tx_empty(tty, mos7840_port);
1229
1230 /* While closing port, shutdown all bulk read, write * 1184 /* While closing port, shutdown all bulk read, write *
1231 * and interrupt read if they exists */ 1185 * and interrupt read if they exists */
1232 if (serial->dev) { 1186 if (serial->dev) {
diff --git a/drivers/usb/serial/navman.c b/drivers/usb/serial/navman.c
index bcdcbb822705..f5f3751a888c 100644
--- a/drivers/usb/serial/navman.c
+++ b/drivers/usb/serial/navman.c
@@ -98,8 +98,7 @@ static int navman_open(struct tty_struct *tty,
98 return result; 98 return result;
99} 99}
100 100
101static void navman_close(struct tty_struct *tty, 101static void navman_close(struct usb_serial_port *port)
102 struct usb_serial_port *port, struct file *filp)
103{ 102{
104 dbg("%s - port %d", __func__, port->number); 103 dbg("%s - port %d", __func__, port->number);
105 104
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index df6539712726..1104617334f5 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -66,8 +66,7 @@ static int debug;
66/* function prototypes */ 66/* function prototypes */
67static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port, 67static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port,
68 struct file *filp); 68 struct file *filp);
69static void omninet_close(struct tty_struct *tty, struct usb_serial_port *port, 69static void omninet_close(struct usb_serial_port *port);
70 struct file *filp);
71static void omninet_read_bulk_callback(struct urb *urb); 70static void omninet_read_bulk_callback(struct urb *urb);
72static void omninet_write_bulk_callback(struct urb *urb); 71static void omninet_write_bulk_callback(struct urb *urb);
73static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port, 72static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
@@ -189,8 +188,7 @@ static int omninet_open(struct tty_struct *tty,
189 return result; 188 return result;
190} 189}
191 190
192static void omninet_close(struct tty_struct *tty, 191static void omninet_close(struct usb_serial_port *port)
193 struct usb_serial_port *port, struct file *filp)
194{ 192{
195 dbg("%s - port %d", __func__, port->number); 193 dbg("%s - port %d", __func__, port->number);
196 usb_kill_urb(port->read_urb); 194 usb_kill_urb(port->read_urb);
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
index b500ad10b758..c20480aa9755 100644
--- a/drivers/usb/serial/opticon.c
+++ b/drivers/usb/serial/opticon.c
@@ -173,8 +173,7 @@ static int opticon_open(struct tty_struct *tty, struct usb_serial_port *port,
173 return result; 173 return result;
174} 174}
175 175
176static void opticon_close(struct tty_struct *tty, struct usb_serial_port *port, 176static void opticon_close(struct usb_serial_port *port)
177 struct file *filp)
178{ 177{
179 struct opticon_private *priv = usb_get_serial_data(port->serial); 178 struct opticon_private *priv = usb_get_serial_data(port->serial);
180 179
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 7817b82889ca..a16d69fadba1 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -45,8 +45,9 @@
45/* Function prototypes */ 45/* Function prototypes */
46static int option_open(struct tty_struct *tty, struct usb_serial_port *port, 46static int option_open(struct tty_struct *tty, struct usb_serial_port *port,
47 struct file *filp); 47 struct file *filp);
48static void option_close(struct tty_struct *tty, struct usb_serial_port *port, 48static void option_close(struct usb_serial_port *port);
49 struct file *filp); 49static void option_dtr_rts(struct usb_serial_port *port, int on);
50
50static int option_startup(struct usb_serial *serial); 51static int option_startup(struct usb_serial *serial);
51static void option_shutdown(struct usb_serial *serial); 52static void option_shutdown(struct usb_serial *serial);
52static int option_write_room(struct tty_struct *tty); 53static int option_write_room(struct tty_struct *tty);
@@ -61,7 +62,7 @@ static void option_set_termios(struct tty_struct *tty,
61static int option_tiocmget(struct tty_struct *tty, struct file *file); 62static int option_tiocmget(struct tty_struct *tty, struct file *file);
62static int option_tiocmset(struct tty_struct *tty, struct file *file, 63static int option_tiocmset(struct tty_struct *tty, struct file *file,
63 unsigned int set, unsigned int clear); 64 unsigned int set, unsigned int clear);
64static int option_send_setup(struct tty_struct *tty, struct usb_serial_port *port); 65static int option_send_setup(struct usb_serial_port *port);
65static int option_suspend(struct usb_serial *serial, pm_message_t message); 66static int option_suspend(struct usb_serial *serial, pm_message_t message);
66static int option_resume(struct usb_serial *serial); 67static int option_resume(struct usb_serial *serial);
67 68
@@ -551,6 +552,7 @@ static struct usb_serial_driver option_1port_device = {
551 .num_ports = 1, 552 .num_ports = 1,
552 .open = option_open, 553 .open = option_open,
553 .close = option_close, 554 .close = option_close,
555 .dtr_rts = option_dtr_rts,
554 .write = option_write, 556 .write = option_write,
555 .write_room = option_write_room, 557 .write_room = option_write_room,
556 .chars_in_buffer = option_chars_in_buffer, 558 .chars_in_buffer = option_chars_in_buffer,
@@ -630,7 +632,7 @@ static void option_set_termios(struct tty_struct *tty,
630 dbg("%s", __func__); 632 dbg("%s", __func__);
631 /* Doesn't support option setting */ 633 /* Doesn't support option setting */
632 tty_termios_copy_hw(tty->termios, old_termios); 634 tty_termios_copy_hw(tty->termios, old_termios);
633 option_send_setup(tty, port); 635 option_send_setup(port);
634} 636}
635 637
636static int option_tiocmget(struct tty_struct *tty, struct file *file) 638static int option_tiocmget(struct tty_struct *tty, struct file *file)
@@ -669,7 +671,7 @@ static int option_tiocmset(struct tty_struct *tty, struct file *file,
669 portdata->rts_state = 0; 671 portdata->rts_state = 0;
670 if (clear & TIOCM_DTR) 672 if (clear & TIOCM_DTR)
671 portdata->dtr_state = 0; 673 portdata->dtr_state = 0;
672 return option_send_setup(tty, port); 674 return option_send_setup(port);
673} 675}
674 676
675/* Write */ 677/* Write */
@@ -897,10 +899,6 @@ static int option_open(struct tty_struct *tty,
897 899
898 dbg("%s", __func__); 900 dbg("%s", __func__);
899 901
900 /* Set some sane defaults */
901 portdata->rts_state = 1;
902 portdata->dtr_state = 1;
903
904 /* Reset low level data toggle and start reading from endpoints */ 902 /* Reset low level data toggle and start reading from endpoints */
905 for (i = 0; i < N_IN_URB; i++) { 903 for (i = 0; i < N_IN_URB; i++) {
906 urb = portdata->in_urbs[i]; 904 urb = portdata->in_urbs[i];
@@ -936,37 +934,43 @@ static int option_open(struct tty_struct *tty,
936 usb_pipeout(urb->pipe), 0); */ 934 usb_pipeout(urb->pipe), 0); */
937 } 935 }
938 936
939 option_send_setup(tty, port); 937 option_send_setup(port);
940 938
941 return 0; 939 return 0;
942} 940}
943 941
944static void option_close(struct tty_struct *tty, 942static void option_dtr_rts(struct usb_serial_port *port, int on)
945 struct usb_serial_port *port, struct file *filp)
946{ 943{
947 int i;
948 struct usb_serial *serial = port->serial; 944 struct usb_serial *serial = port->serial;
949 struct option_port_private *portdata; 945 struct option_port_private *portdata;
950 946
951 dbg("%s", __func__); 947 dbg("%s", __func__);
952 portdata = usb_get_serial_port_data(port); 948 portdata = usb_get_serial_port_data(port);
949 mutex_lock(&serial->disc_mutex);
950 portdata->rts_state = on;
951 portdata->dtr_state = on;
952 if (serial->dev)
953 option_send_setup(port);
954 mutex_unlock(&serial->disc_mutex);
955}
953 956
954 portdata->rts_state = 0;
955 portdata->dtr_state = 0;
956 957
957 if (serial->dev) { 958static void option_close(struct usb_serial_port *port)
958 mutex_lock(&serial->disc_mutex); 959{
959 if (!serial->disconnected) 960 int i;
960 option_send_setup(tty, port); 961 struct usb_serial *serial = port->serial;
961 mutex_unlock(&serial->disc_mutex); 962 struct option_port_private *portdata;
963
964 dbg("%s", __func__);
965 portdata = usb_get_serial_port_data(port);
962 966
967 if (serial->dev) {
963 /* Stop reading/writing urbs */ 968 /* Stop reading/writing urbs */
964 for (i = 0; i < N_IN_URB; i++) 969 for (i = 0; i < N_IN_URB; i++)
965 usb_kill_urb(portdata->in_urbs[i]); 970 usb_kill_urb(portdata->in_urbs[i]);
966 for (i = 0; i < N_OUT_URB; i++) 971 for (i = 0; i < N_OUT_URB; i++)
967 usb_kill_urb(portdata->out_urbs[i]); 972 usb_kill_urb(portdata->out_urbs[i]);
968 } 973 }
969 tty_port_tty_set(&port->port, NULL);
970} 974}
971 975
972/* Helper functions used by option_setup_urbs */ 976/* Helper functions used by option_setup_urbs */
@@ -1032,28 +1036,24 @@ static void option_setup_urbs(struct usb_serial *serial)
1032 * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN 1036 * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN
1033 * CDC. 1037 * CDC.
1034*/ 1038*/
1035static int option_send_setup(struct tty_struct *tty, 1039static int option_send_setup(struct usb_serial_port *port)
1036 struct usb_serial_port *port)
1037{ 1040{
1038 struct usb_serial *serial = port->serial; 1041 struct usb_serial *serial = port->serial;
1039 struct option_port_private *portdata; 1042 struct option_port_private *portdata;
1040 int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber; 1043 int ifNum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
1044 int val = 0;
1041 dbg("%s", __func__); 1045 dbg("%s", __func__);
1042 1046
1043 portdata = usb_get_serial_port_data(port); 1047 portdata = usb_get_serial_port_data(port);
1044 1048
1045 if (tty) { 1049 if (portdata->dtr_state)
1046 int val = 0; 1050 val |= 0x01;
1047 if (portdata->dtr_state) 1051 if (portdata->rts_state)
1048 val |= 0x01; 1052 val |= 0x02;
1049 if (portdata->rts_state)
1050 val |= 0x02;
1051 1053
1052 return usb_control_msg(serial->dev, 1054 return usb_control_msg(serial->dev,
1053 usb_rcvctrlpipe(serial->dev, 0), 1055 usb_rcvctrlpipe(serial->dev, 0),
1054 0x22, 0x21, val, ifNum, NULL, 0, USB_CTRL_SET_TIMEOUT); 1056 0x22, 0x21, val, ifNum, NULL, 0, USB_CTRL_SET_TIMEOUT);
1055 }
1056 return 0;
1057} 1057}
1058 1058
1059static int option_startup(struct usb_serial *serial) 1059static int option_startup(struct usb_serial *serial)
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index ba551f00f16f..7de54781fe61 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -143,8 +143,7 @@ struct oti6858_control_pkt {
143/* function prototypes */ 143/* function prototypes */
144static int oti6858_open(struct tty_struct *tty, 144static int oti6858_open(struct tty_struct *tty,
145 struct usb_serial_port *port, struct file *filp); 145 struct usb_serial_port *port, struct file *filp);
146static void oti6858_close(struct tty_struct *tty, 146static void oti6858_close(struct usb_serial_port *port);
147 struct usb_serial_port *port, struct file *filp);
148static void oti6858_set_termios(struct tty_struct *tty, 147static void oti6858_set_termios(struct tty_struct *tty,
149 struct usb_serial_port *port, struct ktermios *old); 148 struct usb_serial_port *port, struct ktermios *old);
150static int oti6858_ioctl(struct tty_struct *tty, struct file *file, 149static int oti6858_ioctl(struct tty_struct *tty, struct file *file,
@@ -622,67 +621,30 @@ static int oti6858_open(struct tty_struct *tty,
622 if (result != 0) { 621 if (result != 0) {
623 dev_err(&port->dev, "%s(): usb_submit_urb() failed" 622 dev_err(&port->dev, "%s(): usb_submit_urb() failed"
624 " with error %d\n", __func__, result); 623 " with error %d\n", __func__, result);
625 oti6858_close(tty, port, NULL); 624 oti6858_close(port);
626 return -EPROTO; 625 return -EPROTO;
627 } 626 }
628 627
629 /* setup termios */ 628 /* setup termios */
630 if (tty) 629 if (tty)
631 oti6858_set_termios(tty, port, &tmp_termios); 630 oti6858_set_termios(tty, port, &tmp_termios);
632 631 port->port.drain_delay = 256; /* FIXME: check the FIFO length */
633 return 0; 632 return 0;
634} 633}
635 634
636static void oti6858_close(struct tty_struct *tty, 635static void oti6858_close(struct usb_serial_port *port)
637 struct usb_serial_port *port, struct file *filp)
638{ 636{
639 struct oti6858_private *priv = usb_get_serial_port_data(port); 637 struct oti6858_private *priv = usb_get_serial_port_data(port);
640 unsigned long flags; 638 unsigned long flags;
641 long timeout;
642 wait_queue_t wait;
643 639
644 dbg("%s(port = %d)", __func__, port->number); 640 dbg("%s(port = %d)", __func__, port->number);
645 641
646 /* wait for data to drain from the buffer */
647 spin_lock_irqsave(&priv->lock, flags); 642 spin_lock_irqsave(&priv->lock, flags);
648 timeout = 30 * HZ; /* PL2303_CLOSING_WAIT */
649 init_waitqueue_entry(&wait, current);
650 add_wait_queue(&tty->write_wait, &wait);
651 dbg("%s(): entering wait loop", __func__);
652 for (;;) {
653 set_current_state(TASK_INTERRUPTIBLE);
654 if (oti6858_buf_data_avail(priv->buf) == 0
655 || timeout == 0 || signal_pending(current)
656 || port->serial->disconnected)
657 break;
658 spin_unlock_irqrestore(&priv->lock, flags);
659 timeout = schedule_timeout(timeout);
660 spin_lock_irqsave(&priv->lock, flags);
661 }
662 set_current_state(TASK_RUNNING);
663 remove_wait_queue(&tty->write_wait, &wait);
664 dbg("%s(): after wait loop", __func__);
665
666 /* clear out any remaining data in the buffer */ 643 /* clear out any remaining data in the buffer */
667 oti6858_buf_clear(priv->buf); 644 oti6858_buf_clear(priv->buf);
668 spin_unlock_irqrestore(&priv->lock, flags); 645 spin_unlock_irqrestore(&priv->lock, flags);
669 646
670 /* wait for characters to drain from the device */ 647 dbg("%s(): after buf_clear()", __func__);
671 /* (this is long enough for the entire 256 byte */
672 /* pl2303 hardware buffer to drain with no flow */
673 /* control for data rates of 1200 bps or more, */
674 /* for lower rates we should really know how much */
675 /* data is in the buffer to compute a delay */
676 /* that is not unnecessarily long) */
677 /* FIXME
678 bps = tty_get_baud_rate(tty);
679 if (bps > 1200)
680 timeout = max((HZ*2560)/bps,HZ/10);
681 else
682 */
683 timeout = 2*HZ;
684 schedule_timeout_interruptible(timeout);
685 dbg("%s(): after schedule_timeout_interruptible()", __func__);
686 648
687 /* cancel scheduled setup */ 649 /* cancel scheduled setup */
688 cancel_delayed_work(&priv->delayed_setup_work); 650 cancel_delayed_work(&priv->delayed_setup_work);
@@ -694,15 +656,6 @@ static void oti6858_close(struct tty_struct *tty,
694 usb_kill_urb(port->write_urb); 656 usb_kill_urb(port->write_urb);
695 usb_kill_urb(port->read_urb); 657 usb_kill_urb(port->read_urb);
696 usb_kill_urb(port->interrupt_in_urb); 658 usb_kill_urb(port->interrupt_in_urb);
697
698 /*
699 if (tty && (tty->termios->c_cflag) & HUPCL) {
700 // drop DTR and RTS
701 spin_lock_irqsave(&priv->lock, flags);
702 priv->pending_setup.control &= ~CONTROL_MASK;
703 spin_unlock_irqrestore(&priv->lock, flags);
704 }
705 */
706} 659}
707 660
708static int oti6858_tiocmset(struct tty_struct *tty, struct file *file, 661static int oti6858_tiocmset(struct tty_struct *tty, struct file *file,
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 751a533a4347..e02dc3d643c7 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -652,69 +652,41 @@ static void pl2303_set_termios(struct tty_struct *tty,
652 kfree(buf); 652 kfree(buf);
653} 653}
654 654
655static void pl2303_close(struct tty_struct *tty, 655static void pl2303_dtr_rts(struct usb_serial_port *port, int on)
656 struct usb_serial_port *port, struct file *filp) 656{
657 struct pl2303_private *priv = usb_get_serial_port_data(port);
658 unsigned long flags;
659 u8 control;
660
661 spin_lock_irqsave(&priv->lock, flags);
662 /* Change DTR and RTS */
663 if (on)
664 priv->line_control |= (CONTROL_DTR | CONTROL_RTS);
665 else
666 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
667 control = priv->line_control;
668 spin_unlock_irqrestore(&priv->lock, flags);
669 set_control_lines(port->serial->dev, control);
670}
671
672static void pl2303_close(struct usb_serial_port *port)
657{ 673{
658 struct pl2303_private *priv = usb_get_serial_port_data(port); 674 struct pl2303_private *priv = usb_get_serial_port_data(port);
659 unsigned long flags; 675 unsigned long flags;
660 unsigned int c_cflag;
661 int bps;
662 long timeout;
663 wait_queue_t wait;
664 676
665 dbg("%s - port %d", __func__, port->number); 677 dbg("%s - port %d", __func__, port->number);
666 678
667 /* wait for data to drain from the buffer */
668 spin_lock_irqsave(&priv->lock, flags); 679 spin_lock_irqsave(&priv->lock, flags);
669 timeout = PL2303_CLOSING_WAIT;
670 init_waitqueue_entry(&wait, current);
671 add_wait_queue(&tty->write_wait, &wait);
672 for (;;) {
673 set_current_state(TASK_INTERRUPTIBLE);
674 if (pl2303_buf_data_avail(priv->buf) == 0 ||
675 timeout == 0 || signal_pending(current) ||
676 port->serial->disconnected)
677 break;
678 spin_unlock_irqrestore(&priv->lock, flags);
679 timeout = schedule_timeout(timeout);
680 spin_lock_irqsave(&priv->lock, flags);
681 }
682 set_current_state(TASK_RUNNING);
683 remove_wait_queue(&tty->write_wait, &wait);
684 /* clear out any remaining data in the buffer */ 680 /* clear out any remaining data in the buffer */
685 pl2303_buf_clear(priv->buf); 681 pl2303_buf_clear(priv->buf);
686 spin_unlock_irqrestore(&priv->lock, flags); 682 spin_unlock_irqrestore(&priv->lock, flags);
687 683
688 /* wait for characters to drain from the device */
689 /* (this is long enough for the entire 256 byte */
690 /* pl2303 hardware buffer to drain with no flow */
691 /* control for data rates of 1200 bps or more, */
692 /* for lower rates we should really know how much */
693 /* data is in the buffer to compute a delay */
694 /* that is not unnecessarily long) */
695 bps = tty_get_baud_rate(tty);
696 if (bps > 1200)
697 timeout = max((HZ*2560)/bps, HZ/10);
698 else
699 timeout = 2*HZ;
700 schedule_timeout_interruptible(timeout);
701
702 /* shutdown our urbs */ 684 /* shutdown our urbs */
703 dbg("%s - shutting down urbs", __func__); 685 dbg("%s - shutting down urbs", __func__);
704 usb_kill_urb(port->write_urb); 686 usb_kill_urb(port->write_urb);
705 usb_kill_urb(port->read_urb); 687 usb_kill_urb(port->read_urb);
706 usb_kill_urb(port->interrupt_in_urb); 688 usb_kill_urb(port->interrupt_in_urb);
707 689
708 if (tty) {
709 c_cflag = tty->termios->c_cflag;
710 if (c_cflag & HUPCL) {
711 /* drop DTR and RTS */
712 spin_lock_irqsave(&priv->lock, flags);
713 priv->line_control = 0;
714 spin_unlock_irqrestore(&priv->lock, flags);
715 set_control_lines(port->serial->dev, 0);
716 }
717 }
718} 690}
719 691
720static int pl2303_open(struct tty_struct *tty, 692static int pl2303_open(struct tty_struct *tty,
@@ -748,7 +720,7 @@ static int pl2303_open(struct tty_struct *tty,
748 if (result) { 720 if (result) {
749 dev_err(&port->dev, "%s - failed submitting read urb," 721 dev_err(&port->dev, "%s - failed submitting read urb,"
750 " error %d\n", __func__, result); 722 " error %d\n", __func__, result);
751 pl2303_close(tty, port, NULL); 723 pl2303_close(port);
752 return -EPROTO; 724 return -EPROTO;
753 } 725 }
754 726
@@ -758,9 +730,10 @@ static int pl2303_open(struct tty_struct *tty,
758 if (result) { 730 if (result) {
759 dev_err(&port->dev, "%s - failed submitting interrupt urb," 731 dev_err(&port->dev, "%s - failed submitting interrupt urb,"
760 " error %d\n", __func__, result); 732 " error %d\n", __func__, result);
761 pl2303_close(tty, port, NULL); 733 pl2303_close(port);
762 return -EPROTO; 734 return -EPROTO;
763 } 735 }
736 port->port.drain_delay = 256;
764 return 0; 737 return 0;
765} 738}
766 739
@@ -821,6 +794,14 @@ static int pl2303_tiocmget(struct tty_struct *tty, struct file *file)
821 return result; 794 return result;
822} 795}
823 796
797static int pl2303_carrier_raised(struct usb_serial_port *port)
798{
799 struct pl2303_private *priv = usb_get_serial_port_data(port);
800 if (priv->line_status & UART_DCD)
801 return 1;
802 return 0;
803}
804
824static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) 805static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
825{ 806{
826 struct pl2303_private *priv = usb_get_serial_port_data(port); 807 struct pl2303_private *priv = usb_get_serial_port_data(port);
@@ -1125,6 +1106,8 @@ static struct usb_serial_driver pl2303_device = {
1125 .num_ports = 1, 1106 .num_ports = 1,
1126 .open = pl2303_open, 1107 .open = pl2303_open,
1127 .close = pl2303_close, 1108 .close = pl2303_close,
1109 .dtr_rts = pl2303_dtr_rts,
1110 .carrier_raised = pl2303_carrier_raised,
1128 .write = pl2303_write, 1111 .write = pl2303_write,
1129 .ioctl = pl2303_ioctl, 1112 .ioctl = pl2303_ioctl,
1130 .break_ctl = pl2303_break_ctl, 1113 .break_ctl = pl2303_break_ctl,
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index 913225c61610..17ac34f4d668 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -26,12 +26,10 @@
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include <linux/usb/serial.h> 28#include <linux/usb/serial.h>
29#include <linux/usb/ch9.h>
30 29
31#define SWIMS_USB_REQUEST_SetPower 0x00 30#define SWIMS_USB_REQUEST_SetPower 0x00
32#define SWIMS_USB_REQUEST_SetNmea 0x07 31#define SWIMS_USB_REQUEST_SetNmea 0x07
33 32
34/* per port private data */
35#define N_IN_URB 4 33#define N_IN_URB 4
36#define N_OUT_URB 4 34#define N_OUT_URB 4
37#define IN_BUFLEN 4096 35#define IN_BUFLEN 4096
@@ -39,6 +37,12 @@
39static int debug; 37static int debug;
40static int nmea; 38static int nmea;
41 39
40/* Used in interface blacklisting */
41struct sierra_iface_info {
42 const u32 infolen; /* number of interface numbers on blacklist */
43 const u8 *ifaceinfo; /* pointer to the array holding the numbers */
44};
45
42static int sierra_set_power_state(struct usb_device *udev, __u16 swiState) 46static int sierra_set_power_state(struct usb_device *udev, __u16 swiState)
43{ 47{
44 int result; 48 int result;
@@ -85,6 +89,23 @@ static int sierra_calc_num_ports(struct usb_serial *serial)
85 return result; 89 return result;
86} 90}
87 91
92static int is_blacklisted(const u8 ifnum,
93 const struct sierra_iface_info *blacklist)
94{
95 const u8 *info;
96 int i;
97
98 if (blacklist) {
99 info = blacklist->ifaceinfo;
100
101 for (i = 0; i < blacklist->infolen; i++) {
102 if (info[i] == ifnum)
103 return 1;
104 }
105 }
106 return 0;
107}
108
88static int sierra_calc_interface(struct usb_serial *serial) 109static int sierra_calc_interface(struct usb_serial *serial)
89{ 110{
90 int interface; 111 int interface;
@@ -153,9 +174,25 @@ static int sierra_probe(struct usb_serial *serial,
153 */ 174 */
154 usb_set_serial_data(serial, (void *)num_ports); 175 usb_set_serial_data(serial, (void *)num_ports);
155 176
177 /* ifnum could have changed - by calling usb_set_interface */
178 ifnum = sierra_calc_interface(serial);
179
180 if (is_blacklisted(ifnum,
181 (struct sierra_iface_info *)id->driver_info)) {
182 dev_dbg(&serial->dev->dev,
183 "Ignoring blacklisted interface #%d\n", ifnum);
184 return -ENODEV;
185 }
186
156 return result; 187 return result;
157} 188}
158 189
190static const u8 direct_ip_non_serial_ifaces[] = { 7, 8, 9, 10, 11 };
191static const struct sierra_iface_info direct_ip_interface_blacklist = {
192 .infolen = ARRAY_SIZE(direct_ip_non_serial_ifaces),
193 .ifaceinfo = direct_ip_non_serial_ifaces,
194};
195
159static struct usb_device_id id_table [] = { 196static struct usb_device_id id_table [] = {
160 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */ 197 { USB_DEVICE(0x1199, 0x0017) }, /* Sierra Wireless EM5625 */
161 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */ 198 { USB_DEVICE(0x1199, 0x0018) }, /* Sierra Wireless MC5720 */
@@ -188,9 +225,11 @@ static struct usb_device_id id_table [] = {
188 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781 */ 225 { USB_DEVICE(0x1199, 0x6833) }, /* Sierra Wireless MC8781 */
189 { USB_DEVICE(0x1199, 0x683A) }, /* Sierra Wireless MC8785 */ 226 { USB_DEVICE(0x1199, 0x683A) }, /* Sierra Wireless MC8785 */
190 { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite */ 227 { USB_DEVICE(0x1199, 0x683B) }, /* Sierra Wireless MC8785 Composite */
191 { USB_DEVICE(0x1199, 0x683C) }, /* Sierra Wireless MC8790 */ 228 /* Sierra Wireless MC8790, MC8791, MC8792 Composite */
192 { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8790 */ 229 { USB_DEVICE(0x1199, 0x683C) },
193 { USB_DEVICE(0x1199, 0x683E) }, /* Sierra Wireless MC8790 */ 230 { USB_DEVICE(0x1199, 0x683D) }, /* Sierra Wireless MC8791 Composite */
231 /* Sierra Wireless MC8790, MC8791, MC8792 */
232 { USB_DEVICE(0x1199, 0x683E) },
194 { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */ 233 { USB_DEVICE(0x1199, 0x6850) }, /* Sierra Wireless AirCard 880 */
195 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */ 234 { USB_DEVICE(0x1199, 0x6851) }, /* Sierra Wireless AirCard 881 */
196 { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */ 235 { USB_DEVICE(0x1199, 0x6852) }, /* Sierra Wireless AirCard 880 E */
@@ -211,6 +250,10 @@ static struct usb_device_id id_table [] = {
211 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */ 250 { USB_DEVICE(0x1199, 0x0112) }, /* Sierra Wireless AirCard 580 */
212 { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */ 251 { USB_DEVICE(0x0F3D, 0x0112) }, /* Airprime/Sierra PC 5220 */
213 252
253 { USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless Direct IP modems */
254 .driver_info = (kernel_ulong_t)&direct_ip_interface_blacklist
255 },
256
214 { } 257 { }
215}; 258};
216MODULE_DEVICE_TABLE(usb, id_table); 259MODULE_DEVICE_TABLE(usb, id_table);
@@ -229,7 +272,6 @@ struct sierra_port_private {
229 272
230 /* Input endpoints and buffers for this port */ 273 /* Input endpoints and buffers for this port */
231 struct urb *in_urbs[N_IN_URB]; 274 struct urb *in_urbs[N_IN_URB];
232 char *in_buffer[N_IN_URB];
233 275
234 /* Settings for the port */ 276 /* Settings for the port */
235 int rts_state; /* Handshaking pins (outputs) */ 277 int rts_state; /* Handshaking pins (outputs) */
@@ -240,57 +282,50 @@ struct sierra_port_private {
240 int ri_state; 282 int ri_state;
241}; 283};
242 284
243static int sierra_send_setup(struct tty_struct *tty, 285static int sierra_send_setup(struct usb_serial_port *port)
244 struct usb_serial_port *port)
245{ 286{
246 struct usb_serial *serial = port->serial; 287 struct usb_serial *serial = port->serial;
247 struct sierra_port_private *portdata; 288 struct sierra_port_private *portdata;
248 __u16 interface = 0; 289 __u16 interface = 0;
290 int val = 0;
249 291
250 dev_dbg(&port->dev, "%s", __func__); 292 dev_dbg(&port->dev, "%s", __func__);
251 293
252 portdata = usb_get_serial_port_data(port); 294 portdata = usb_get_serial_port_data(port);
253 295
254 if (tty) { 296 if (portdata->dtr_state)
255 int val = 0; 297 val |= 0x01;
256 if (portdata->dtr_state) 298 if (portdata->rts_state)
257 val |= 0x01; 299 val |= 0x02;
258 if (portdata->rts_state)
259 val |= 0x02;
260
261 /* If composite device then properly report interface */
262 if (serial->num_ports == 1) {
263 interface = sierra_calc_interface(serial);
264
265 /* Control message is sent only to interfaces with
266 * interrupt_in endpoints
267 */
268 if (port->interrupt_in_urb) {
269 /* send control message */
270 return usb_control_msg(serial->dev,
271 usb_rcvctrlpipe(serial->dev, 0),
272 0x22, 0x21, val, interface,
273 NULL, 0, USB_CTRL_SET_TIMEOUT);
274 }
275 }
276
277 /* Otherwise the need to do non-composite mapping */
278 else {
279 if (port->bulk_out_endpointAddress == 2)
280 interface = 0;
281 else if (port->bulk_out_endpointAddress == 4)
282 interface = 1;
283 else if (port->bulk_out_endpointAddress == 5)
284 interface = 2;
285 300
301 /* If composite device then properly report interface */
302 if (serial->num_ports == 1) {
303 interface = sierra_calc_interface(serial);
304 /* Control message is sent only to interfaces with
305 * interrupt_in endpoints
306 */
307 if (port->interrupt_in_urb) {
308 /* send control message */
286 return usb_control_msg(serial->dev, 309 return usb_control_msg(serial->dev,
287 usb_rcvctrlpipe(serial->dev, 0), 310 usb_rcvctrlpipe(serial->dev, 0),
288 0x22, 0x21, val, interface, 311 0x22, 0x21, val, interface,
289 NULL, 0, USB_CTRL_SET_TIMEOUT); 312 NULL, 0, USB_CTRL_SET_TIMEOUT);
290
291 } 313 }
292 } 314 }
293 315
316 /* Otherwise the need to do non-composite mapping */
317 else {
318 if (port->bulk_out_endpointAddress == 2)
319 interface = 0;
320 else if (port->bulk_out_endpointAddress == 4)
321 interface = 1;
322 else if (port->bulk_out_endpointAddress == 5)
323 interface = 2;
324 return usb_control_msg(serial->dev,
325 usb_rcvctrlpipe(serial->dev, 0),
326 0x22, 0x21, val, interface,
327 NULL, 0, USB_CTRL_SET_TIMEOUT);
328 }
294 return 0; 329 return 0;
295} 330}
296 331
@@ -299,7 +334,7 @@ static void sierra_set_termios(struct tty_struct *tty,
299{ 334{
300 dev_dbg(&port->dev, "%s", __func__); 335 dev_dbg(&port->dev, "%s", __func__);
301 tty_termios_copy_hw(tty->termios, old_termios); 336 tty_termios_copy_hw(tty->termios, old_termios);
302 sierra_send_setup(tty, port); 337 sierra_send_setup(port);
303} 338}
304 339
305static int sierra_tiocmget(struct tty_struct *tty, struct file *file) 340static int sierra_tiocmget(struct tty_struct *tty, struct file *file)
@@ -338,7 +373,18 @@ static int sierra_tiocmset(struct tty_struct *tty, struct file *file,
338 portdata->rts_state = 0; 373 portdata->rts_state = 0;
339 if (clear & TIOCM_DTR) 374 if (clear & TIOCM_DTR)
340 portdata->dtr_state = 0; 375 portdata->dtr_state = 0;
341 return sierra_send_setup(tty, port); 376 return sierra_send_setup(port);
377}
378
379static void sierra_release_urb(struct urb *urb)
380{
381 struct usb_serial_port *port;
382 if (urb) {
383 port = urb->context;
384 dev_dbg(&port->dev, "%s: %p\n", __func__, urb);
385 kfree(urb->transfer_buffer);
386 usb_free_urb(urb);
387 }
342} 388}
343 389
344static void sierra_outdat_callback(struct urb *urb) 390static void sierra_outdat_callback(struct urb *urb)
@@ -465,7 +511,7 @@ static void sierra_indat_callback(struct urb *urb)
465 " received", __func__); 511 " received", __func__);
466 512
467 /* Resubmit urb so we continue receiving */ 513 /* Resubmit urb so we continue receiving */
468 if (port->port.count && status != -ESHUTDOWN) { 514 if (port->port.count && status != -ESHUTDOWN && status != -EPERM) {
469 err = usb_submit_urb(urb, GFP_ATOMIC); 515 err = usb_submit_urb(urb, GFP_ATOMIC);
470 if (err) 516 if (err)
471 dev_err(&port->dev, "resubmit read urb failed." 517 dev_err(&port->dev, "resubmit read urb failed."
@@ -557,67 +603,99 @@ static int sierra_write_room(struct tty_struct *tty)
557 return 2048; 603 return 2048;
558} 604}
559 605
560static int sierra_open(struct tty_struct *tty, 606static void sierra_stop_rx_urbs(struct usb_serial_port *port)
561 struct usb_serial_port *port, struct file *filp)
562{ 607{
563 struct sierra_port_private *portdata;
564 struct usb_serial *serial = port->serial;
565 int i; 608 int i;
566 struct urb *urb; 609 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
567 int result;
568 610
569 portdata = usb_get_serial_port_data(port); 611 for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++)
612 usb_kill_urb(portdata->in_urbs[i]);
570 613
571 dev_dbg(&port->dev, "%s", __func__); 614 usb_kill_urb(port->interrupt_in_urb);
615}
572 616
573 /* Set some sane defaults */ 617static int sierra_submit_rx_urbs(struct usb_serial_port *port, gfp_t mem_flags)
574 portdata->rts_state = 1; 618{
575 portdata->dtr_state = 1; 619 int ok_cnt;
620 int err = -EINVAL;
621 int i;
622 struct urb *urb;
623 struct sierra_port_private *portdata = usb_get_serial_port_data(port);
576 624
577 /* Reset low level data toggle and start reading from endpoints */ 625 ok_cnt = 0;
578 for (i = 0; i < N_IN_URB; i++) { 626 for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) {
579 urb = portdata->in_urbs[i]; 627 urb = portdata->in_urbs[i];
580 if (!urb) 628 if (!urb)
581 continue; 629 continue;
582 if (urb->dev != serial->dev) { 630 err = usb_submit_urb(urb, mem_flags);
583 dev_dbg(&port->dev, "%s: dev %p != %p", 631 if (err) {
584 __func__, urb->dev, serial->dev); 632 dev_err(&port->dev, "%s: submit urb failed: %d\n",
585 continue; 633 __func__, err);
634 } else {
635 ok_cnt++;
586 } 636 }
637 }
587 638
588 /* 639 if (ok_cnt && port->interrupt_in_urb) {
589 * make sure endpoint data toggle is synchronized with the 640 err = usb_submit_urb(port->interrupt_in_urb, mem_flags);
590 * device 641 if (err) {
591 */ 642 dev_err(&port->dev, "%s: submit intr urb failed: %d\n",
592 usb_clear_halt(urb->dev, urb->pipe); 643 __func__, err);
593
594 result = usb_submit_urb(urb, GFP_KERNEL);
595 if (result) {
596 dev_err(&port->dev, "submit urb %d failed (%d) %d\n",
597 i, result, urb->transfer_buffer_length);
598 } 644 }
599 } 645 }
600 646
601 sierra_send_setup(tty, port); 647 if (ok_cnt > 0) /* at least one rx urb submitted */
648 return 0;
649 else
650 return err;
651}
652
653static struct urb *sierra_setup_urb(struct usb_serial *serial, int endpoint,
654 int dir, void *ctx, int len,
655 gfp_t mem_flags,
656 usb_complete_t callback)
657{
658 struct urb *urb;
659 u8 *buf;
660
661 if (endpoint == -1)
662 return NULL;
602 663
603 /* start up the interrupt endpoint if we have one */ 664 urb = usb_alloc_urb(0, mem_flags);
604 if (port->interrupt_in_urb) { 665 if (urb == NULL) {
605 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 666 dev_dbg(&serial->dev->dev, "%s: alloc for endpoint %d failed\n",
606 if (result) 667 __func__, endpoint);
607 dev_err(&port->dev, "submit irq_in urb failed %d\n", 668 return NULL;
608 result);
609 } 669 }
610 return 0; 670
671 buf = kmalloc(len, mem_flags);
672 if (buf) {
673 /* Fill URB using supplied data */
674 usb_fill_bulk_urb(urb, serial->dev,
675 usb_sndbulkpipe(serial->dev, endpoint) | dir,
676 buf, len, callback, ctx);
677
678 /* debug */
679 dev_dbg(&serial->dev->dev, "%s %c u : %p d:%p\n", __func__,
680 dir == USB_DIR_IN ? 'i' : 'o', urb, buf);
681 } else {
682 dev_dbg(&serial->dev->dev, "%s %c u:%p d:%p\n", __func__,
683 dir == USB_DIR_IN ? 'i' : 'o', urb, buf);
684
685 sierra_release_urb(urb);
686 urb = NULL;
687 }
688
689 return urb;
611} 690}
612 691
613static void sierra_close(struct tty_struct *tty, 692static void sierra_close(struct usb_serial_port *port)
614 struct usb_serial_port *port, struct file *filp)
615{ 693{
616 int i; 694 int i;
617 struct usb_serial *serial = port->serial; 695 struct usb_serial *serial = port->serial;
618 struct sierra_port_private *portdata; 696 struct sierra_port_private *portdata;
619 697
620 dev_dbg(&port->dev, "%s", __func__); 698 dev_dbg(&port->dev, "%s\n", __func__);
621 portdata = usb_get_serial_port_data(port); 699 portdata = usb_get_serial_port_data(port);
622 700
623 portdata->rts_state = 0; 701 portdata->rts_state = 0;
@@ -626,25 +704,83 @@ static void sierra_close(struct tty_struct *tty,
626 if (serial->dev) { 704 if (serial->dev) {
627 mutex_lock(&serial->disc_mutex); 705 mutex_lock(&serial->disc_mutex);
628 if (!serial->disconnected) 706 if (!serial->disconnected)
629 sierra_send_setup(tty, port); 707 sierra_send_setup(port);
630 mutex_unlock(&serial->disc_mutex); 708 mutex_unlock(&serial->disc_mutex);
631 709
632 /* Stop reading/writing urbs */ 710 /* Stop reading urbs */
633 for (i = 0; i < N_IN_URB; i++) 711 sierra_stop_rx_urbs(port);
634 usb_kill_urb(portdata->in_urbs[i]); 712 /* .. and release them */
713 for (i = 0; i < N_IN_URB; i++) {
714 sierra_release_urb(portdata->in_urbs[i]);
715 portdata->in_urbs[i] = NULL;
716 }
635 } 717 }
718}
636 719
637 usb_kill_urb(port->interrupt_in_urb); 720static int sierra_open(struct tty_struct *tty,
638 tty_port_tty_set(&port->port, NULL); 721 struct usb_serial_port *port, struct file *filp)
722{
723 struct sierra_port_private *portdata;
724 struct usb_serial *serial = port->serial;
725 int i;
726 int err;
727 int endpoint;
728 struct urb *urb;
729
730 portdata = usb_get_serial_port_data(port);
731
732 dev_dbg(&port->dev, "%s", __func__);
733
734 /* Set some sane defaults */
735 portdata->rts_state = 1;
736 portdata->dtr_state = 1;
737
738
739 endpoint = port->bulk_in_endpointAddress;
740 for (i = 0; i < ARRAY_SIZE(portdata->in_urbs); i++) {
741 urb = sierra_setup_urb(serial, endpoint, USB_DIR_IN, port,
742 IN_BUFLEN, GFP_KERNEL,
743 sierra_indat_callback);
744 portdata->in_urbs[i] = urb;
745 }
746 /* clear halt condition */
747 usb_clear_halt(serial->dev,
748 usb_sndbulkpipe(serial->dev, endpoint) | USB_DIR_IN);
749
750 err = sierra_submit_rx_urbs(port, GFP_KERNEL);
751 if (err) {
752 /* get rid of everything as in close */
753 sierra_close(port);
754 return err;
755 }
756 sierra_send_setup(port);
757
758 return 0;
759}
760
761
762static void sierra_dtr_rts(struct usb_serial_port *port, int on)
763{
764 struct usb_serial *serial = port->serial;
765 struct sierra_port_private *portdata;
766
767 portdata = usb_get_serial_port_data(port);
768 portdata->rts_state = on;
769 portdata->dtr_state = on;
770
771 if (serial->dev) {
772 mutex_lock(&serial->disc_mutex);
773 if (!serial->disconnected)
774 sierra_send_setup(port);
775 mutex_unlock(&serial->disc_mutex);
776 }
639} 777}
640 778
641static int sierra_startup(struct usb_serial *serial) 779static int sierra_startup(struct usb_serial *serial)
642{ 780{
643 struct usb_serial_port *port; 781 struct usb_serial_port *port;
644 struct sierra_port_private *portdata; 782 struct sierra_port_private *portdata;
645 struct urb *urb;
646 int i; 783 int i;
647 int j;
648 784
649 dev_dbg(&serial->dev->dev, "%s", __func__); 785 dev_dbg(&serial->dev->dev, "%s", __func__);
650 786
@@ -666,34 +802,8 @@ static int sierra_startup(struct usb_serial *serial)
666 return -ENOMEM; 802 return -ENOMEM;
667 } 803 }
668 spin_lock_init(&portdata->lock); 804 spin_lock_init(&portdata->lock);
669 for (j = 0; j < N_IN_URB; j++) { 805 /* Set the port private data pointer */
670 portdata->in_buffer[j] = kmalloc(IN_BUFLEN, GFP_KERNEL);
671 if (!portdata->in_buffer[j]) {
672 for (--j; j >= 0; j--)
673 kfree(portdata->in_buffer[j]);
674 kfree(portdata);
675 return -ENOMEM;
676 }
677 }
678
679 usb_set_serial_port_data(port, portdata); 806 usb_set_serial_port_data(port, portdata);
680
681 /* initialize the in urbs */
682 for (j = 0; j < N_IN_URB; ++j) {
683 urb = usb_alloc_urb(0, GFP_KERNEL);
684 if (urb == NULL) {
685 dev_dbg(&port->dev, "%s: alloc for in "
686 "port failed.", __func__);
687 continue;
688 }
689 /* Fill URB using supplied data. */
690 usb_fill_bulk_urb(urb, serial->dev,
691 usb_rcvbulkpipe(serial->dev,
692 port->bulk_in_endpointAddress),
693 portdata->in_buffer[j], IN_BUFLEN,
694 sierra_indat_callback, port);
695 portdata->in_urbs[j] = urb;
696 }
697 } 807 }
698 808
699 return 0; 809 return 0;
@@ -701,7 +811,7 @@ static int sierra_startup(struct usb_serial *serial)
701 811
702static void sierra_shutdown(struct usb_serial *serial) 812static void sierra_shutdown(struct usb_serial *serial)
703{ 813{
704 int i, j; 814 int i;
705 struct usb_serial_port *port; 815 struct usb_serial_port *port;
706 struct sierra_port_private *portdata; 816 struct sierra_port_private *portdata;
707 817
@@ -714,12 +824,6 @@ static void sierra_shutdown(struct usb_serial *serial)
714 portdata = usb_get_serial_port_data(port); 824 portdata = usb_get_serial_port_data(port);
715 if (!portdata) 825 if (!portdata)
716 continue; 826 continue;
717
718 for (j = 0; j < N_IN_URB; j++) {
719 usb_kill_urb(portdata->in_urbs[j]);
720 usb_free_urb(portdata->in_urbs[j]);
721 kfree(portdata->in_buffer[j]);
722 }
723 kfree(portdata); 827 kfree(portdata);
724 usb_set_serial_port_data(port, NULL); 828 usb_set_serial_port_data(port, NULL);
725 } 829 }
@@ -737,6 +841,7 @@ static struct usb_serial_driver sierra_device = {
737 .probe = sierra_probe, 841 .probe = sierra_probe,
738 .open = sierra_open, 842 .open = sierra_open,
739 .close = sierra_close, 843 .close = sierra_close,
844 .dtr_rts = sierra_dtr_rts,
740 .write = sierra_write, 845 .write = sierra_write,
741 .write_room = sierra_write_room, 846 .write_room = sierra_write_room,
742 .set_termios = sierra_set_termios, 847 .set_termios = sierra_set_termios,
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
index 5e7528cc81a8..8f7ed8f13996 100644
--- a/drivers/usb/serial/spcp8x5.c
+++ b/drivers/usb/serial/spcp8x5.c
@@ -446,66 +446,47 @@ static void spcp8x5_set_workMode(struct usb_device *dev, u16 value,
446 "RTSCTS usb_control_msg(enable flowctrl) = %d\n", ret); 446 "RTSCTS usb_control_msg(enable flowctrl) = %d\n", ret);
447} 447}
448 448
449static int spcp8x5_carrier_raised(struct usb_serial_port *port)
450{
451 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
452 if (priv->line_status & MSR_STATUS_LINE_DCD)
453 return 1;
454 return 0;
455}
456
457static void spcp8x5_dtr_rts(struct usb_serial_port *port, int on)
458{
459 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
460 unsigned long flags;
461 u8 control;
462
463 spin_lock_irqsave(&priv->lock, flags);
464 if (on)
465 priv->line_control = MCR_CONTROL_LINE_DTR
466 | MCR_CONTROL_LINE_RTS;
467 else
468 priv->line_control &= ~ (MCR_CONTROL_LINE_DTR
469 | MCR_CONTROL_LINE_RTS);
470 control = priv->line_control;
471 spin_unlock_irqrestore(&priv->lock, flags);
472 spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type);
473}
474
449/* close the serial port. We should wait for data sending to device 1st and 475/* close the serial port. We should wait for data sending to device 1st and
450 * then kill all urb. */ 476 * then kill all urb. */
451static void spcp8x5_close(struct tty_struct *tty, 477static void spcp8x5_close(struct usb_serial_port *port)
452 struct usb_serial_port *port, struct file *filp)
453{ 478{
454 struct spcp8x5_private *priv = usb_get_serial_port_data(port); 479 struct spcp8x5_private *priv = usb_get_serial_port_data(port);
455 unsigned long flags; 480 unsigned long flags;
456 unsigned int c_cflag;
457 int bps;
458 long timeout;
459 wait_queue_t wait;
460 int result; 481 int result;
461 482
462 dbg("%s - port %d", __func__, port->number); 483 dbg("%s - port %d", __func__, port->number);
463 484
464 /* wait for data to drain from the buffer */
465 spin_lock_irqsave(&priv->lock, flags); 485 spin_lock_irqsave(&priv->lock, flags);
466 timeout = SPCP8x5_CLOSING_WAIT;
467 init_waitqueue_entry(&wait, current);
468 add_wait_queue(&tty->write_wait, &wait);
469 for (;;) {
470 set_current_state(TASK_INTERRUPTIBLE);
471 if (ringbuf_avail_data(priv->buf) == 0 ||
472 timeout == 0 || signal_pending(current))
473 break;
474 spin_unlock_irqrestore(&priv->lock, flags);
475 timeout = schedule_timeout(timeout);
476 spin_lock_irqsave(&priv->lock, flags);
477 }
478 set_current_state(TASK_RUNNING);
479 remove_wait_queue(&tty->write_wait, &wait);
480
481 /* clear out any remaining data in the buffer */ 486 /* clear out any remaining data in the buffer */
482 clear_ringbuf(priv->buf); 487 clear_ringbuf(priv->buf);
483 spin_unlock_irqrestore(&priv->lock, flags); 488 spin_unlock_irqrestore(&priv->lock, flags);
484 489
485 /* wait for characters to drain from the device (this is long enough
486 * for the entire all byte spcp8x5 hardware buffer to drain with no
487 * flow control for data rates of 1200 bps or more, for lower rates we
488 * should really know how much data is in the buffer to compute a delay
489 * that is not unnecessarily long) */
490 bps = tty_get_baud_rate(tty);
491 if (bps > 1200)
492 timeout = max((HZ*2560) / bps, HZ/10);
493 else
494 timeout = 2*HZ;
495 set_current_state(TASK_INTERRUPTIBLE);
496 schedule_timeout(timeout);
497
498 /* clear control lines */
499 if (tty) {
500 c_cflag = tty->termios->c_cflag;
501 if (c_cflag & HUPCL) {
502 spin_lock_irqsave(&priv->lock, flags);
503 priv->line_control = 0;
504 spin_unlock_irqrestore(&priv->lock, flags);
505 spcp8x5_set_ctrlLine(port->serial->dev, 0 , priv->type);
506 }
507 }
508
509 /* kill urb */ 490 /* kill urb */
510 if (port->write_urb != NULL) { 491 if (port->write_urb != NULL) {
511 result = usb_unlink_urb(port->write_urb); 492 result = usb_unlink_urb(port->write_urb);
@@ -665,13 +646,6 @@ static int spcp8x5_open(struct tty_struct *tty,
665 if (ret) 646 if (ret)
666 return ret; 647 return ret;
667 648
668 spin_lock_irqsave(&priv->lock, flags);
669 if (tty && (tty->termios->c_cflag & CBAUD))
670 priv->line_control = MCR_DTR | MCR_RTS;
671 else
672 priv->line_control = 0;
673 spin_unlock_irqrestore(&priv->lock, flags);
674
675 spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type); 649 spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type);
676 650
677 /* Setup termios */ 651 /* Setup termios */
@@ -691,9 +665,10 @@ static int spcp8x5_open(struct tty_struct *tty,
691 port->read_urb->dev = serial->dev; 665 port->read_urb->dev = serial->dev;
692 ret = usb_submit_urb(port->read_urb, GFP_KERNEL); 666 ret = usb_submit_urb(port->read_urb, GFP_KERNEL);
693 if (ret) { 667 if (ret) {
694 spcp8x5_close(tty, port, NULL); 668 spcp8x5_close(port);
695 return -EPROTO; 669 return -EPROTO;
696 } 670 }
671 port->port.drain_delay = 256;
697 return 0; 672 return 0;
698} 673}
699 674
@@ -1033,6 +1008,8 @@ static struct usb_serial_driver spcp8x5_device = {
1033 .num_ports = 1, 1008 .num_ports = 1,
1034 .open = spcp8x5_open, 1009 .open = spcp8x5_open,
1035 .close = spcp8x5_close, 1010 .close = spcp8x5_close,
1011 .dtr_rts = spcp8x5_dtr_rts,
1012 .carrier_raised = spcp8x5_carrier_raised,
1036 .write = spcp8x5_write, 1013 .write = spcp8x5_write,
1037 .set_termios = spcp8x5_set_termios, 1014 .set_termios = spcp8x5_set_termios,
1038 .ioctl = spcp8x5_ioctl, 1015 .ioctl = spcp8x5_ioctl,
diff --git a/drivers/usb/serial/symbolserial.c b/drivers/usb/serial/symbolserial.c
index 69879e437940..8b07ebc6baeb 100644
--- a/drivers/usb/serial/symbolserial.c
+++ b/drivers/usb/serial/symbolserial.c
@@ -152,8 +152,7 @@ static int symbol_open(struct tty_struct *tty, struct usb_serial_port *port,
152 return result; 152 return result;
153} 153}
154 154
155static void symbol_close(struct tty_struct *tty, struct usb_serial_port *port, 155static void symbol_close(struct usb_serial_port *port)
156 struct file *filp)
157{ 156{
158 struct symbol_private *priv = usb_get_serial_data(port->serial); 157 struct symbol_private *priv = usb_get_serial_data(port->serial);
159 158
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 0a64bac306ee..42cb04c403be 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -100,8 +100,7 @@ static int ti_startup(struct usb_serial *serial);
100static void ti_shutdown(struct usb_serial *serial); 100static void ti_shutdown(struct usb_serial *serial);
101static int ti_open(struct tty_struct *tty, struct usb_serial_port *port, 101static int ti_open(struct tty_struct *tty, struct usb_serial_port *port,
102 struct file *file); 102 struct file *file);
103static void ti_close(struct tty_struct *tty, struct usb_serial_port *port, 103static void ti_close(struct usb_serial_port *port);
104 struct file *file);
105static int ti_write(struct tty_struct *tty, struct usb_serial_port *port, 104static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
106 const unsigned char *data, int count); 105 const unsigned char *data, int count);
107static int ti_write_room(struct tty_struct *tty); 106static int ti_write_room(struct tty_struct *tty);
@@ -647,8 +646,7 @@ release_lock:
647} 646}
648 647
649 648
650static void ti_close(struct tty_struct *tty, struct usb_serial_port *port, 649static void ti_close(struct usb_serial_port *port)
651 struct file *file)
652{ 650{
653 struct ti_device *tdev; 651 struct ti_device *tdev;
654 struct ti_port *tport; 652 struct ti_port *tport;
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index f331e2bde88a..1967a7edc10c 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -238,9 +238,11 @@ static int serial_open (struct tty_struct *tty, struct file *filp)
238 goto bailout_interface_put; 238 goto bailout_interface_put;
239 mutex_unlock(&serial->disc_mutex); 239 mutex_unlock(&serial->disc_mutex);
240 } 240 }
241
242 mutex_unlock(&port->mutex); 241 mutex_unlock(&port->mutex);
243 return 0; 242 /* Now do the correct tty layer semantics */
243 retval = tty_port_block_til_ready(&port->port, tty, filp);
244 if (retval == 0)
245 return 0;
244 246
245bailout_interface_put: 247bailout_interface_put:
246 usb_autopm_put_interface(serial->interface); 248 usb_autopm_put_interface(serial->interface);
@@ -259,64 +261,89 @@ bailout_serial_put:
259 return retval; 261 return retval;
260} 262}
261 263
262static void serial_close(struct tty_struct *tty, struct file *filp) 264/**
265 * serial_do_down - shut down hardware
266 * @port: port to shut down
267 *
268 * Shut down a USB port unless it is the console. We never shut down the
269 * console hardware as it will always be in use.
270 *
271 * Don't free any resources at this point
272 */
273static void serial_do_down(struct usb_serial_port *port)
263{ 274{
264 struct usb_serial_port *port = tty->driver_data; 275 struct usb_serial_driver *drv = port->serial->type;
265 struct usb_serial *serial; 276 struct usb_serial *serial;
266 struct module *owner; 277 struct module *owner;
267 int count;
268 278
269 if (!port) 279 /* The console is magical, do not hang up the console hardware
280 or there will be tears */
281 if (port->console)
270 return; 282 return;
271 283
272 dbg("%s - port %d", __func__, port->number);
273
274 mutex_lock(&port->mutex); 284 mutex_lock(&port->mutex);
275 serial = port->serial; 285 serial = port->serial;
276 owner = serial->type->driver.owner; 286 owner = serial->type->driver.owner;
277 287
278 if (port->port.count == 0) { 288 if (drv->close)
279 mutex_unlock(&port->mutex); 289 drv->close(port);
280 return;
281 }
282
283 if (port->port.count == 1)
284 /* only call the device specific close if this
285 * port is being closed by the last owner. Ensure we do
286 * this before we drop the port count. The call is protected
287 * by the port mutex
288 */
289 serial->type->close(tty, port, filp);
290
291 if (port->port.count == (port->console ? 2 : 1)) {
292 struct tty_struct *tty = tty_port_tty_get(&port->port);
293 if (tty) {
294 /* We must do this before we drop the port count to
295 zero. */
296 if (tty->driver_data)
297 tty->driver_data = NULL;
298 tty_port_tty_set(&port->port, NULL);
299 tty_kref_put(tty);
300 }
301 }
302 290
303 --port->port.count;
304 count = port->port.count;
305 mutex_unlock(&port->mutex); 291 mutex_unlock(&port->mutex);
306 put_device(&port->dev); 292}
293
294/**
295 * serial_do_free - free resources post close/hangup
296 * @port: port to free up
297 *
298 * Do the resource freeing and refcount dropping for the port. We must
299 * be careful about ordering and we must avoid freeing up the console.
300 */
307 301
302static void serial_do_free(struct usb_serial_port *port)
303{
304 struct usb_serial *serial;
305 struct module *owner;
306
307 /* The console is magical, do not hang up the console hardware
308 or there will be tears */
309 if (port->console)
310 return;
311
312 serial = port->serial;
313 owner = serial->type->driver.owner;
314 put_device(&port->dev);
308 /* Mustn't dereference port any more */ 315 /* Mustn't dereference port any more */
309 if (count == 0) { 316 mutex_lock(&serial->disc_mutex);
310 mutex_lock(&serial->disc_mutex); 317 if (!serial->disconnected)
311 if (!serial->disconnected) 318 usb_autopm_put_interface(serial->interface);
312 usb_autopm_put_interface(serial->interface); 319 mutex_unlock(&serial->disc_mutex);
313 mutex_unlock(&serial->disc_mutex);
314 }
315 usb_serial_put(serial); 320 usb_serial_put(serial);
316
317 /* Mustn't dereference serial any more */ 321 /* Mustn't dereference serial any more */
318 if (count == 0) 322 module_put(owner);
319 module_put(owner); 323}
324
325static void serial_close(struct tty_struct *tty, struct file *filp)
326{
327 struct usb_serial_port *port = tty->driver_data;
328
329 dbg("%s - port %d", __func__, port->number);
330
331
332 if (tty_port_close_start(&port->port, tty, filp) == 0)
333 return;
334
335 serial_do_down(port);
336 tty_port_close_end(&port->port, tty);
337 tty_port_tty_set(&port->port, NULL);
338 serial_do_free(port);
339}
340
341static void serial_hangup(struct tty_struct *tty)
342{
343 struct usb_serial_port *port = tty->driver_data;
344 serial_do_down(port);
345 tty_port_hangup(&port->port);
346 serial_do_free(port);
320} 347}
321 348
322static int serial_write(struct tty_struct *tty, const unsigned char *buf, 349static int serial_write(struct tty_struct *tty, const unsigned char *buf,
@@ -648,6 +675,29 @@ static struct usb_serial_driver *search_serial_device(
648 return NULL; 675 return NULL;
649} 676}
650 677
678static int serial_carrier_raised(struct tty_port *port)
679{
680 struct usb_serial_port *p = container_of(port, struct usb_serial_port, port);
681 struct usb_serial_driver *drv = p->serial->type;
682 if (drv->carrier_raised)
683 return drv->carrier_raised(p);
684 /* No carrier control - don't block */
685 return 1;
686}
687
688static void serial_dtr_rts(struct tty_port *port, int on)
689{
690 struct usb_serial_port *p = container_of(port, struct usb_serial_port, port);
691 struct usb_serial_driver *drv = p->serial->type;
692 if (drv->dtr_rts)
693 drv->dtr_rts(p, on);
694}
695
696static const struct tty_port_operations serial_port_ops = {
697 .carrier_raised = serial_carrier_raised,
698 .dtr_rts = serial_dtr_rts,
699};
700
651int usb_serial_probe(struct usb_interface *interface, 701int usb_serial_probe(struct usb_interface *interface,
652 const struct usb_device_id *id) 702 const struct usb_device_id *id)
653{ 703{
@@ -841,6 +891,7 @@ int usb_serial_probe(struct usb_interface *interface,
841 if (!port) 891 if (!port)
842 goto probe_error; 892 goto probe_error;
843 tty_port_init(&port->port); 893 tty_port_init(&port->port);
894 port->port.ops = &serial_port_ops;
844 port->serial = serial; 895 port->serial = serial;
845 spin_lock_init(&port->lock); 896 spin_lock_init(&port->lock);
846 mutex_init(&port->mutex); 897 mutex_init(&port->mutex);
@@ -1071,6 +1122,9 @@ void usb_serial_disconnect(struct usb_interface *interface)
1071 if (port) { 1122 if (port) {
1072 struct tty_struct *tty = tty_port_tty_get(&port->port); 1123 struct tty_struct *tty = tty_port_tty_get(&port->port);
1073 if (tty) { 1124 if (tty) {
1125 /* The hangup will occur asynchronously but
1126 the object refcounts will sort out all the
1127 cleanup */
1074 tty_hangup(tty); 1128 tty_hangup(tty);
1075 tty_kref_put(tty); 1129 tty_kref_put(tty);
1076 } 1130 }
@@ -1135,6 +1189,7 @@ static const struct tty_operations serial_ops = {
1135 .open = serial_open, 1189 .open = serial_open,
1136 .close = serial_close, 1190 .close = serial_close,
1137 .write = serial_write, 1191 .write = serial_write,
1192 .hangup = serial_hangup,
1138 .write_room = serial_write_room, 1193 .write_room = serial_write_room,
1139 .ioctl = serial_ioctl, 1194 .ioctl = serial_ioctl,
1140 .set_termios = serial_set_termios, 1195 .set_termios = serial_set_termios,
@@ -1147,6 +1202,7 @@ static const struct tty_operations serial_ops = {
1147 .proc_fops = &serial_proc_fops, 1202 .proc_fops = &serial_proc_fops,
1148}; 1203};
1149 1204
1205
1150struct tty_driver *usb_serial_tty_driver; 1206struct tty_driver *usb_serial_tty_driver;
1151 1207
1152static int __init usb_serial_init(void) 1208static int __init usb_serial_init(void)
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index 5ac414bda718..b15f1c0e1d4a 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -38,8 +38,7 @@
38/* function prototypes for a handspring visor */ 38/* function prototypes for a handspring visor */
39static int visor_open(struct tty_struct *tty, struct usb_serial_port *port, 39static int visor_open(struct tty_struct *tty, struct usb_serial_port *port,
40 struct file *filp); 40 struct file *filp);
41static void visor_close(struct tty_struct *tty, struct usb_serial_port *port, 41static void visor_close(struct usb_serial_port *port);
42 struct file *filp);
43static int visor_write(struct tty_struct *tty, struct usb_serial_port *port, 42static int visor_write(struct tty_struct *tty, struct usb_serial_port *port,
44 const unsigned char *buf, int count); 43 const unsigned char *buf, int count);
45static int visor_write_room(struct tty_struct *tty); 44static int visor_write_room(struct tty_struct *tty);
@@ -324,8 +323,7 @@ exit:
324} 323}
325 324
326 325
327static void visor_close(struct tty_struct *tty, 326static void visor_close(struct usb_serial_port *port)
328 struct usb_serial_port *port, struct file *filp)
329{ 327{
330 struct visor_private *priv = usb_get_serial_port_data(port); 328 struct visor_private *priv = usb_get_serial_port_data(port);
331 unsigned char *transfer_buffer; 329 unsigned char *transfer_buffer;
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index 5335d3211c07..7c7295d09f34 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -147,8 +147,7 @@ static int whiteheat_attach(struct usb_serial *serial);
147static void whiteheat_shutdown(struct usb_serial *serial); 147static void whiteheat_shutdown(struct usb_serial *serial);
148static int whiteheat_open(struct tty_struct *tty, 148static int whiteheat_open(struct tty_struct *tty,
149 struct usb_serial_port *port, struct file *filp); 149 struct usb_serial_port *port, struct file *filp);
150static void whiteheat_close(struct tty_struct *tty, 150static void whiteheat_close(struct usb_serial_port *port);
151 struct usb_serial_port *port, struct file *filp);
152static int whiteheat_write(struct tty_struct *tty, 151static int whiteheat_write(struct tty_struct *tty,
153 struct usb_serial_port *port, 152 struct usb_serial_port *port,
154 const unsigned char *buf, int count); 153 const unsigned char *buf, int count);
@@ -712,8 +711,7 @@ exit:
712} 711}
713 712
714 713
715static void whiteheat_close(struct tty_struct *tty, 714static void whiteheat_close(struct usb_serial_port *port)
716 struct usb_serial_port *port, struct file *filp)
717{ 715{
718 struct whiteheat_private *info = usb_get_serial_port_data(port); 716 struct whiteheat_private *info = usb_get_serial_port_data(port);
719 struct whiteheat_urb_wrap *wrap; 717 struct whiteheat_urb_wrap *wrap;
@@ -723,31 +721,7 @@ static void whiteheat_close(struct tty_struct *tty,
723 721
724 dbg("%s - port %d", __func__, port->number); 722 dbg("%s - port %d", __func__, port->number);
725 723
726 mutex_lock(&port->serial->disc_mutex);
727 /* filp is NULL when called from usb_serial_disconnect */
728 if ((filp && (tty_hung_up_p(filp))) || port->serial->disconnected) {
729 mutex_unlock(&port->serial->disc_mutex);
730 return;
731 }
732 mutex_unlock(&port->serial->disc_mutex);
733
734 tty->closing = 1;
735
736/*
737 * Not currently in use; tty_wait_until_sent() calls
738 * serial_chars_in_buffer() which deadlocks on the second semaphore
739 * acquisition. This should be fixed at some point. Greg's been
740 * notified.
741 if ((filp->f_flags & (O_NDELAY | O_NONBLOCK)) == 0) {
742 tty_wait_until_sent(tty, CLOSING_DELAY);
743 }
744*/
745
746 tty_driver_flush_buffer(tty);
747 tty_ldisc_flush(tty);
748
749 firm_report_tx_done(port); 724 firm_report_tx_done(port);
750
751 firm_close(port); 725 firm_close(port);
752 726
753 /* shutdown our bulk reads and writes */ 727 /* shutdown our bulk reads and writes */
@@ -775,10 +749,7 @@ static void whiteheat_close(struct tty_struct *tty,
775 } 749 }
776 spin_unlock_irq(&info->lock); 750 spin_unlock_irq(&info->lock);
777 mutex_unlock(&info->deathwarrant); 751 mutex_unlock(&info->deathwarrant);
778
779 stop_command_port(port->serial); 752 stop_command_port(port->serial);
780
781 tty->closing = 0;
782} 753}
783 754
784 755
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 4ca3b5860643..cfa26d56ce60 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -132,7 +132,7 @@ static int slave_configure(struct scsi_device *sdev)
132 132
133 if (us->fflags & US_FL_MAX_SECTORS_MIN) 133 if (us->fflags & US_FL_MAX_SECTORS_MIN)
134 max_sectors = PAGE_CACHE_SIZE >> 9; 134 max_sectors = PAGE_CACHE_SIZE >> 9;
135 if (sdev->request_queue->max_sectors > max_sectors) 135 if (queue_max_sectors(sdev->request_queue) > max_sectors)
136 blk_queue_max_sectors(sdev->request_queue, 136 blk_queue_max_sectors(sdev->request_queue,
137 max_sectors); 137 max_sectors);
138 } else if (sdev->type == TYPE_TAPE) { 138 } else if (sdev->type == TYPE_TAPE) {
@@ -483,7 +483,7 @@ static ssize_t show_max_sectors(struct device *dev, struct device_attribute *att
483{ 483{
484 struct scsi_device *sdev = to_scsi_device(dev); 484 struct scsi_device *sdev = to_scsi_device(dev);
485 485
486 return sprintf(buf, "%u\n", sdev->request_queue->max_sectors); 486 return sprintf(buf, "%u\n", queue_max_sectors(sdev->request_queue));
487} 487}
488 488
489/* Input routine for the sysfs max_sectors file */ 489/* Input routine for the sysfs max_sectors file */
diff --git a/drivers/video/hitfb.c b/drivers/video/hitfb.c
index e6467cf9f19f..020db7fc9153 100644
--- a/drivers/video/hitfb.c
+++ b/drivers/video/hitfb.c
@@ -335,9 +335,9 @@ static int __init hitfb_probe(struct platform_device *dev)
335 if (fb_get_options("hitfb", NULL)) 335 if (fb_get_options("hitfb", NULL))
336 return -ENODEV; 336 return -ENODEV;
337 337
338 hitfb_fix.mmio_start = CONFIG_HD64461_IOBASE+0x1000; 338 hitfb_fix.mmio_start = HD64461_IO_OFFSET(0x1000);
339 hitfb_fix.mmio_len = 0x1000; 339 hitfb_fix.mmio_len = 0x1000;
340 hitfb_fix.smem_start = CONFIG_HD64461_IOBASE + 0x02000000; 340 hitfb_fix.smem_start = HD64461_IO_OFFSET(0x02000000);
341 hitfb_fix.smem_len = 512 * 1024; 341 hitfb_fix.smem_len = 512 * 1024;
342 342
343 lcdclor = fb_readw(HD64461_LCDCLOR); 343 lcdclor = fb_readw(HD64461_LCDCLOR);
diff --git a/fs/bio.c b/fs/bio.c
index 740699c4f90c..59000215e59b 100644
--- a/fs/bio.c
+++ b/fs/bio.c
@@ -498,11 +498,11 @@ int bio_get_nr_vecs(struct block_device *bdev)
498 struct request_queue *q = bdev_get_queue(bdev); 498 struct request_queue *q = bdev_get_queue(bdev);
499 int nr_pages; 499 int nr_pages;
500 500
501 nr_pages = ((q->max_sectors << 9) + PAGE_SIZE - 1) >> PAGE_SHIFT; 501 nr_pages = ((queue_max_sectors(q) << 9) + PAGE_SIZE - 1) >> PAGE_SHIFT;
502 if (nr_pages > q->max_phys_segments) 502 if (nr_pages > queue_max_phys_segments(q))
503 nr_pages = q->max_phys_segments; 503 nr_pages = queue_max_phys_segments(q);
504 if (nr_pages > q->max_hw_segments) 504 if (nr_pages > queue_max_hw_segments(q))
505 nr_pages = q->max_hw_segments; 505 nr_pages = queue_max_hw_segments(q);
506 506
507 return nr_pages; 507 return nr_pages;
508} 508}
@@ -561,8 +561,8 @@ static int __bio_add_page(struct request_queue *q, struct bio *bio, struct page
561 * make this too complex. 561 * make this too complex.
562 */ 562 */
563 563
564 while (bio->bi_phys_segments >= q->max_phys_segments 564 while (bio->bi_phys_segments >= queue_max_phys_segments(q)
565 || bio->bi_phys_segments >= q->max_hw_segments) { 565 || bio->bi_phys_segments >= queue_max_hw_segments(q)) {
566 566
567 if (retried_segments) 567 if (retried_segments)
568 return 0; 568 return 0;
@@ -633,7 +633,8 @@ static int __bio_add_page(struct request_queue *q, struct bio *bio, struct page
633int bio_add_pc_page(struct request_queue *q, struct bio *bio, struct page *page, 633int bio_add_pc_page(struct request_queue *q, struct bio *bio, struct page *page,
634 unsigned int len, unsigned int offset) 634 unsigned int len, unsigned int offset)
635{ 635{
636 return __bio_add_page(q, bio, page, len, offset, q->max_hw_sectors); 636 return __bio_add_page(q, bio, page, len, offset,
637 queue_max_hw_sectors(q));
637} 638}
638 639
639/** 640/**
@@ -653,7 +654,7 @@ int bio_add_page(struct bio *bio, struct page *page, unsigned int len,
653 unsigned int offset) 654 unsigned int offset)
654{ 655{
655 struct request_queue *q = bdev_get_queue(bio->bi_bdev); 656 struct request_queue *q = bdev_get_queue(bio->bi_bdev);
656 return __bio_add_page(q, bio, page, len, offset, q->max_sectors); 657 return __bio_add_page(q, bio, page, len, offset, queue_max_sectors(q));
657} 658}
658 659
659struct bio_map_data { 660struct bio_map_data {
@@ -720,7 +721,7 @@ static int __bio_copy_iov(struct bio *bio, struct bio_vec *iovecs,
720 721
721 while (bv_len && iov_idx < iov_count) { 722 while (bv_len && iov_idx < iov_count) {
722 unsigned int bytes; 723 unsigned int bytes;
723 char *iov_addr; 724 char __user *iov_addr;
724 725
725 bytes = min_t(unsigned int, 726 bytes = min_t(unsigned int,
726 iov[iov_idx].iov_len - iov_off, bv_len); 727 iov[iov_idx].iov_len - iov_off, bv_len);
@@ -1200,7 +1201,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
1200 char *addr = page_address(bvec->bv_page); 1201 char *addr = page_address(bvec->bv_page);
1201 int len = bmd->iovecs[i].bv_len; 1202 int len = bmd->iovecs[i].bv_len;
1202 1203
1203 if (read && !err) 1204 if (read)
1204 memcpy(p, addr, len); 1205 memcpy(p, addr, len);
1205 1206
1206 __free_page(bvec->bv_page); 1207 __free_page(bvec->bv_page);
@@ -1489,11 +1490,12 @@ struct bio_pair *bio_split(struct bio *bi, int first_sectors)
1489sector_t bio_sector_offset(struct bio *bio, unsigned short index, 1490sector_t bio_sector_offset(struct bio *bio, unsigned short index,
1490 unsigned int offset) 1491 unsigned int offset)
1491{ 1492{
1492 unsigned int sector_sz = queue_hardsect_size(bio->bi_bdev->bd_disk->queue); 1493 unsigned int sector_sz;
1493 struct bio_vec *bv; 1494 struct bio_vec *bv;
1494 sector_t sectors; 1495 sector_t sectors;
1495 int i; 1496 int i;
1496 1497
1498 sector_sz = queue_logical_block_size(bio->bi_bdev->bd_disk->queue);
1497 sectors = 0; 1499 sectors = 0;
1498 1500
1499 if (index >= bio->bi_idx) 1501 if (index >= bio->bi_idx)
diff --git a/fs/block_dev.c b/fs/block_dev.c
index f45dbc18dd17..2dfc6cdcebbe 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -76,7 +76,7 @@ int set_blocksize(struct block_device *bdev, int size)
76 return -EINVAL; 76 return -EINVAL;
77 77
78 /* Size cannot be smaller than the size supported by the device */ 78 /* Size cannot be smaller than the size supported by the device */
79 if (size < bdev_hardsect_size(bdev)) 79 if (size < bdev_logical_block_size(bdev))
80 return -EINVAL; 80 return -EINVAL;
81 81
82 /* Don't change the size if it is same as current */ 82 /* Don't change the size if it is same as current */
@@ -106,7 +106,7 @@ EXPORT_SYMBOL(sb_set_blocksize);
106 106
107int sb_min_blocksize(struct super_block *sb, int size) 107int sb_min_blocksize(struct super_block *sb, int size)
108{ 108{
109 int minsize = bdev_hardsect_size(sb->s_bdev); 109 int minsize = bdev_logical_block_size(sb->s_bdev);
110 if (size < minsize) 110 if (size < minsize)
111 size = minsize; 111 size = minsize;
112 return sb_set_blocksize(sb, size); 112 return sb_set_blocksize(sb, size);
@@ -1111,7 +1111,7 @@ EXPORT_SYMBOL(check_disk_change);
1111 1111
1112void bd_set_size(struct block_device *bdev, loff_t size) 1112void bd_set_size(struct block_device *bdev, loff_t size)
1113{ 1113{
1114 unsigned bsize = bdev_hardsect_size(bdev); 1114 unsigned bsize = bdev_logical_block_size(bdev);
1115 1115
1116 bdev->bd_inode->i_size = size; 1116 bdev->bd_inode->i_size = size;
1117 while (bsize < PAGE_CACHE_SIZE) { 1117 while (bsize < PAGE_CACHE_SIZE) {
diff --git a/fs/buffer.c b/fs/buffer.c
index 49106127a4aa..a3ef091a45bd 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1085,12 +1085,12 @@ static struct buffer_head *
1085__getblk_slow(struct block_device *bdev, sector_t block, int size) 1085__getblk_slow(struct block_device *bdev, sector_t block, int size)
1086{ 1086{
1087 /* Size must be multiple of hard sectorsize */ 1087 /* Size must be multiple of hard sectorsize */
1088 if (unlikely(size & (bdev_hardsect_size(bdev)-1) || 1088 if (unlikely(size & (bdev_logical_block_size(bdev)-1) ||
1089 (size < 512 || size > PAGE_SIZE))) { 1089 (size < 512 || size > PAGE_SIZE))) {
1090 printk(KERN_ERR "getblk(): invalid block size %d requested\n", 1090 printk(KERN_ERR "getblk(): invalid block size %d requested\n",
1091 size); 1091 size);
1092 printk(KERN_ERR "hardsect size: %d\n", 1092 printk(KERN_ERR "logical block size: %d\n",
1093 bdev_hardsect_size(bdev)); 1093 bdev_logical_block_size(bdev));
1094 1094
1095 dump_stack(); 1095 dump_stack();
1096 return NULL; 1096 return NULL;
@@ -2935,6 +2935,8 @@ int submit_bh(int rw, struct buffer_head * bh)
2935 BUG_ON(!buffer_locked(bh)); 2935 BUG_ON(!buffer_locked(bh));
2936 BUG_ON(!buffer_mapped(bh)); 2936 BUG_ON(!buffer_mapped(bh));
2937 BUG_ON(!bh->b_end_io); 2937 BUG_ON(!bh->b_end_io);
2938 BUG_ON(buffer_delay(bh));
2939 BUG_ON(buffer_unwritten(bh));
2938 2940
2939 /* 2941 /*
2940 * Mask in barrier bit for a write (could be either a WRITE or a 2942 * Mask in barrier bit for a write (could be either a WRITE or a
diff --git a/fs/cifs/CHANGES b/fs/cifs/CHANGES
index f20c4069c220..b48689839428 100644
--- a/fs/cifs/CHANGES
+++ b/fs/cifs/CHANGES
@@ -1,3 +1,12 @@
1Version 1.59
2------------
3Client uses server inode numbers (which are persistent) rather than
4client generated ones by default (mount option "serverino" turned
5on by default if server supports it). Add forceuid and forcegid
6mount options (so that when negotiating unix extensions specifying
7which uid mounted does not immediately force the server's reported
8uids to be overridden).
9
1Version 1.58 10Version 1.58
2------------ 11------------
3Guard against buffer overruns in various UCS-2 to UTF-8 string conversions 12Guard against buffer overruns in various UCS-2 to UTF-8 string conversions
@@ -10,6 +19,8 @@ we converted from). Fix endianness of the vcnum field used during
10session setup to distinguish multiple mounts to same server from different 19session setup to distinguish multiple mounts to same server from different
11userids. Raw NTLMSSP fixed (it requires /proc/fs/cifs/experimental 20userids. Raw NTLMSSP fixed (it requires /proc/fs/cifs/experimental
12flag to be set to 2, and mount must enable krb5 to turn on extended security). 21flag to be set to 2, and mount must enable krb5 to turn on extended security).
22Performance of file create to Samba improved (posix create on lookup
23removes 1 of 2 network requests sent on file create)
13 24
14Version 1.57 25Version 1.57
15------------ 26------------
diff --git a/fs/cifs/README b/fs/cifs/README
index db208ddb9899..ad92921dbde4 100644
--- a/fs/cifs/README
+++ b/fs/cifs/README
@@ -262,7 +262,8 @@ A partial list of the supported mount options follows:
262 mount. 262 mount.
263 domain Set the SMB/CIFS workgroup name prepended to the 263 domain Set the SMB/CIFS workgroup name prepended to the
264 username during CIFS session establishment 264 username during CIFS session establishment
265 uid Set the default uid for inodes. For mounts to servers 265 forceuid Set the default uid for inodes based on the uid
266 passed in. For mounts to servers
266 which do support the CIFS Unix extensions, such as a 267 which do support the CIFS Unix extensions, such as a
267 properly configured Samba server, the server provides 268 properly configured Samba server, the server provides
268 the uid, gid and mode so this parameter should not be 269 the uid, gid and mode so this parameter should not be
@@ -292,6 +293,12 @@ A partial list of the supported mount options follows:
292 the client. Note that the mount.cifs helper must be 293 the client. Note that the mount.cifs helper must be
293 at version 1.10 or higher to support specifying the uid 294 at version 1.10 or higher to support specifying the uid
294 (or gid) in non-numeric form. 295 (or gid) in non-numeric form.
296 forcegid (similar to above but for the groupid instead of uid)
297 uid Set the default uid for inodes, and indicate to the
298 cifs kernel driver which local user mounted . If the server
299 supports the unix extensions the default uid is
300 not used to fill in the owner fields of inodes (files)
301 unless the "forceuid" parameter is specified.
295 gid Set the default gid for inodes (similar to above). 302 gid Set the default gid for inodes (similar to above).
296 file_mode If CIFS Unix extensions are not supported by the server 303 file_mode If CIFS Unix extensions are not supported by the server
297 this overrides the default mode for file inodes. 304 this overrides the default mode for file inodes.
@@ -388,8 +395,13 @@ A partial list of the supported mount options follows:
388 or the CIFS Unix Extensions equivalent and for those 395 or the CIFS Unix Extensions equivalent and for those
389 this mount option will have no effect. Exporting cifs mounts 396 this mount option will have no effect. Exporting cifs mounts
390 under nfsd requires this mount option on the cifs mount. 397 under nfsd requires this mount option on the cifs mount.
398 This is now the default if server supports the
399 required network operation.
391 noserverino Client generates inode numbers (rather than using the actual one 400 noserverino Client generates inode numbers (rather than using the actual one
392 from the server) by default. 401 from the server). These inode numbers will vary after
402 unmount or reboot which can confuse some applications,
403 but not all server filesystems support unique inode
404 numbers.
393 setuids If the CIFS Unix extensions are negotiated with the server 405 setuids If the CIFS Unix extensions are negotiated with the server
394 the client will attempt to set the effective uid and gid of 406 the client will attempt to set the effective uid and gid of
395 the local process on newly created files, directories, and 407 the local process on newly created files, directories, and
diff --git a/fs/cifs/cifs_spnego.c b/fs/cifs/cifs_spnego.c
index 67bf93a40d2e..4a4581cb2b5e 100644
--- a/fs/cifs/cifs_spnego.c
+++ b/fs/cifs/cifs_spnego.c
@@ -23,6 +23,7 @@
23#include <linux/string.h> 23#include <linux/string.h>
24#include <keys/user-type.h> 24#include <keys/user-type.h>
25#include <linux/key-type.h> 25#include <linux/key-type.h>
26#include <linux/inet.h>
26#include "cifsglob.h" 27#include "cifsglob.h"
27#include "cifs_spnego.h" 28#include "cifs_spnego.h"
28#include "cifs_debug.h" 29#include "cifs_debug.h"
@@ -73,9 +74,6 @@ struct key_type cifs_spnego_key_type = {
73 * strlen(";sec=ntlmsspi") */ 74 * strlen(";sec=ntlmsspi") */
74#define MAX_MECH_STR_LEN 13 75#define MAX_MECH_STR_LEN 13
75 76
76/* max possible addr len eg FEDC:BA98:7654:3210:FEDC:BA98:7654:3210/128 */
77#define MAX_IPV6_ADDR_LEN 43
78
79/* strlen of "host=" */ 77/* strlen of "host=" */
80#define HOST_KEY_LEN 5 78#define HOST_KEY_LEN 5
81 79
@@ -102,7 +100,7 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
102 host=hostname sec=mechanism uid=0xFF user=username */ 100 host=hostname sec=mechanism uid=0xFF user=username */
103 desc_len = MAX_VER_STR_LEN + 101 desc_len = MAX_VER_STR_LEN +
104 HOST_KEY_LEN + strlen(hostname) + 102 HOST_KEY_LEN + strlen(hostname) +
105 IP_KEY_LEN + MAX_IPV6_ADDR_LEN + 103 IP_KEY_LEN + INET6_ADDRSTRLEN +
106 MAX_MECH_STR_LEN + 104 MAX_MECH_STR_LEN +
107 UID_KEY_LEN + (sizeof(uid_t) * 2) + 105 UID_KEY_LEN + (sizeof(uid_t) * 2) +
108 USER_KEY_LEN + strlen(sesInfo->userName) + 1; 106 USER_KEY_LEN + strlen(sesInfo->userName) + 1;
diff --git a/fs/cifs/cifsacl.c b/fs/cifs/cifsacl.c
index 57ecdc83c26f..1403b5d86a73 100644
--- a/fs/cifs/cifsacl.c
+++ b/fs/cifs/cifsacl.c
@@ -552,130 +552,138 @@ static int build_sec_desc(struct cifs_ntsd *pntsd, struct cifs_ntsd *pnntsd,
552 return rc; 552 return rc;
553} 553}
554 554
555 555static struct cifs_ntsd *get_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb,
556/* Retrieve an ACL from the server */ 556 __u16 fid, u32 *pacllen)
557static struct cifs_ntsd *get_cifs_acl(u32 *pacllen, struct inode *inode,
558 const char *path, const __u16 *pfid)
559{ 557{
560 struct cifsFileInfo *open_file = NULL;
561 bool unlock_file = false;
562 int xid;
563 int rc = -EIO;
564 __u16 fid;
565 struct super_block *sb;
566 struct cifs_sb_info *cifs_sb;
567 struct cifs_ntsd *pntsd = NULL; 558 struct cifs_ntsd *pntsd = NULL;
559 int xid, rc;
560
561 xid = GetXid();
562 rc = CIFSSMBGetCIFSACL(xid, cifs_sb->tcon, fid, &pntsd, pacllen);
563 FreeXid(xid);
568 564
569 cFYI(1, ("get mode from ACL for %s", path));
570 565
571 if (inode == NULL) 566 cFYI(1, ("GetCIFSACL rc = %d ACL len %d", rc, *pacllen));
572 return NULL; 567 return pntsd;
568}
569
570static struct cifs_ntsd *get_cifs_acl_by_path(struct cifs_sb_info *cifs_sb,
571 const char *path, u32 *pacllen)
572{
573 struct cifs_ntsd *pntsd = NULL;
574 int oplock = 0;
575 int xid, rc;
576 __u16 fid;
573 577
574 xid = GetXid(); 578 xid = GetXid();
575 if (pfid == NULL)
576 open_file = find_readable_file(CIFS_I(inode));
577 else
578 fid = *pfid;
579 579
580 sb = inode->i_sb; 580 rc = CIFSSMBOpen(xid, cifs_sb->tcon, path, FILE_OPEN, READ_CONTROL, 0,
581 if (sb == NULL) { 581 &fid, &oplock, NULL, cifs_sb->local_nls,
582 FreeXid(xid); 582 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
583 return NULL; 583 if (rc) {
584 } 584 cERROR(1, ("Unable to open file to get ACL"));
585 cifs_sb = CIFS_SB(sb); 585 goto out;
586
587 if (open_file) {
588 unlock_file = true;
589 fid = open_file->netfid;
590 } else if (pfid == NULL) {
591 int oplock = 0;
592 /* open file */
593 rc = CIFSSMBOpen(xid, cifs_sb->tcon, path, FILE_OPEN,
594 READ_CONTROL, 0, &fid, &oplock, NULL,
595 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags &
596 CIFS_MOUNT_MAP_SPECIAL_CHR);
597 if (rc != 0) {
598 cERROR(1, ("Unable to open file to get ACL"));
599 FreeXid(xid);
600 return NULL;
601 }
602 } 586 }
603 587
604 rc = CIFSSMBGetCIFSACL(xid, cifs_sb->tcon, fid, &pntsd, pacllen); 588 rc = CIFSSMBGetCIFSACL(xid, cifs_sb->tcon, fid, &pntsd, pacllen);
605 cFYI(1, ("GetCIFSACL rc = %d ACL len %d", rc, *pacllen)); 589 cFYI(1, ("GetCIFSACL rc = %d ACL len %d", rc, *pacllen));
606 if (unlock_file == true) /* find_readable_file increments ref count */
607 atomic_dec(&open_file->wrtPending);
608 else if (pfid == NULL) /* if opened above we have to close the handle */
609 CIFSSMBClose(xid, cifs_sb->tcon, fid);
610 /* else handle was passed in by caller */
611 590
591 CIFSSMBClose(xid, cifs_sb->tcon, fid);
592 out:
612 FreeXid(xid); 593 FreeXid(xid);
613 return pntsd; 594 return pntsd;
614} 595}
615 596
616/* Set an ACL on the server */ 597/* Retrieve an ACL from the server */
617static int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen, 598static struct cifs_ntsd *get_cifs_acl(struct cifs_sb_info *cifs_sb,
618 struct inode *inode, const char *path) 599 struct inode *inode, const char *path,
600 u32 *pacllen)
619{ 601{
620 struct cifsFileInfo *open_file; 602 struct cifs_ntsd *pntsd = NULL;
621 bool unlock_file = false; 603 struct cifsFileInfo *open_file = NULL;
622 int xid;
623 int rc = -EIO;
624 __u16 fid;
625 struct super_block *sb;
626 struct cifs_sb_info *cifs_sb;
627 604
628 cFYI(DBG2, ("set ACL for %s from mode 0x%x", path, inode->i_mode)); 605 if (inode)
606 open_file = find_readable_file(CIFS_I(inode));
607 if (!open_file)
608 return get_cifs_acl_by_path(cifs_sb, path, pacllen);
629 609
630 if (!inode) 610 pntsd = get_cifs_acl_by_fid(cifs_sb, open_file->netfid, pacllen);
631 return rc; 611 atomic_dec(&open_file->wrtPending);
612 return pntsd;
613}
632 614
633 sb = inode->i_sb; 615static int set_cifs_acl_by_fid(struct cifs_sb_info *cifs_sb, __u16 fid,
634 if (sb == NULL) 616 struct cifs_ntsd *pnntsd, u32 acllen)
635 return rc; 617{
618 int xid, rc;
636 619
637 cifs_sb = CIFS_SB(sb);
638 xid = GetXid(); 620 xid = GetXid();
621 rc = CIFSSMBSetCIFSACL(xid, cifs_sb->tcon, fid, pnntsd, acllen);
622 FreeXid(xid);
639 623
640 open_file = find_readable_file(CIFS_I(inode)); 624 cFYI(DBG2, ("SetCIFSACL rc = %d", rc));
641 if (open_file) { 625 return rc;
642 unlock_file = true; 626}
643 fid = open_file->netfid; 627
644 } else { 628static int set_cifs_acl_by_path(struct cifs_sb_info *cifs_sb, const char *path,
645 int oplock = 0; 629 struct cifs_ntsd *pnntsd, u32 acllen)
646 /* open file */ 630{
647 rc = CIFSSMBOpen(xid, cifs_sb->tcon, path, FILE_OPEN, 631 int oplock = 0;
648 WRITE_DAC, 0, &fid, &oplock, NULL, 632 int xid, rc;
649 cifs_sb->local_nls, cifs_sb->mnt_cifs_flags & 633 __u16 fid;
650 CIFS_MOUNT_MAP_SPECIAL_CHR); 634
651 if (rc != 0) { 635 xid = GetXid();
652 cERROR(1, ("Unable to open file to set ACL")); 636
653 FreeXid(xid); 637 rc = CIFSSMBOpen(xid, cifs_sb->tcon, path, FILE_OPEN, WRITE_DAC, 0,
654 return rc; 638 &fid, &oplock, NULL, cifs_sb->local_nls,
655 } 639 cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR);
640 if (rc) {
641 cERROR(1, ("Unable to open file to set ACL"));
642 goto out;
656 } 643 }
657 644
658 rc = CIFSSMBSetCIFSACL(xid, cifs_sb->tcon, fid, pnntsd, acllen); 645 rc = CIFSSMBSetCIFSACL(xid, cifs_sb->tcon, fid, pnntsd, acllen);
659 cFYI(DBG2, ("SetCIFSACL rc = %d", rc)); 646 cFYI(DBG2, ("SetCIFSACL rc = %d", rc));
660 if (unlock_file)
661 atomic_dec(&open_file->wrtPending);
662 else
663 CIFSSMBClose(xid, cifs_sb->tcon, fid);
664 647
648 CIFSSMBClose(xid, cifs_sb->tcon, fid);
649 out:
665 FreeXid(xid); 650 FreeXid(xid);
651 return rc;
652}
666 653
654/* Set an ACL on the server */
655static int set_cifs_acl(struct cifs_ntsd *pnntsd, __u32 acllen,
656 struct inode *inode, const char *path)
657{
658 struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
659 struct cifsFileInfo *open_file;
660 int rc;
661
662 cFYI(DBG2, ("set ACL for %s from mode 0x%x", path, inode->i_mode));
663
664 open_file = find_readable_file(CIFS_I(inode));
665 if (!open_file)
666 return set_cifs_acl_by_path(cifs_sb, path, pnntsd, acllen);
667
668 rc = set_cifs_acl_by_fid(cifs_sb, open_file->netfid, pnntsd, acllen);
669 atomic_dec(&open_file->wrtPending);
667 return rc; 670 return rc;
668} 671}
669 672
670/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */ 673/* Translate the CIFS ACL (simlar to NTFS ACL) for a file into mode bits */
671void acl_to_uid_mode(struct inode *inode, const char *path, const __u16 *pfid) 674void acl_to_uid_mode(struct cifs_sb_info *cifs_sb, struct inode *inode,
675 const char *path, const __u16 *pfid)
672{ 676{
673 struct cifs_ntsd *pntsd = NULL; 677 struct cifs_ntsd *pntsd = NULL;
674 u32 acllen = 0; 678 u32 acllen = 0;
675 int rc = 0; 679 int rc = 0;
676 680
677 cFYI(DBG2, ("converting ACL to mode for %s", path)); 681 cFYI(DBG2, ("converting ACL to mode for %s", path));
678 pntsd = get_cifs_acl(&acllen, inode, path, pfid); 682
683 if (pfid)
684 pntsd = get_cifs_acl_by_fid(cifs_sb, *pfid, &acllen);
685 else
686 pntsd = get_cifs_acl(cifs_sb, inode, path, &acllen);
679 687
680 /* if we can retrieve the ACL, now parse Access Control Entries, ACEs */ 688 /* if we can retrieve the ACL, now parse Access Control Entries, ACEs */
681 if (pntsd) 689 if (pntsd)
@@ -698,7 +706,7 @@ int mode_to_acl(struct inode *inode, const char *path, __u64 nmode)
698 cFYI(DBG2, ("set ACL from mode for %s", path)); 706 cFYI(DBG2, ("set ACL from mode for %s", path));
699 707
700 /* Get the security descriptor */ 708 /* Get the security descriptor */
701 pntsd = get_cifs_acl(&secdesclen, inode, path, NULL); 709 pntsd = get_cifs_acl(CIFS_SB(inode->i_sb), inode, path, &secdesclen);
702 710
703 /* Add three ACEs for owner, group, everyone getting rid of 711 /* Add three ACEs for owner, group, everyone getting rid of
704 other ACEs as chmod disables ACEs and set the security descriptor */ 712 other ACEs as chmod disables ACEs and set the security descriptor */
diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
index 5e6d35804d73..0a10a59b6392 100644
--- a/fs/cifs/cifsfs.c
+++ b/fs/cifs/cifsfs.c
@@ -146,7 +146,7 @@ cifs_read_super(struct super_block *sb, void *data,
146#endif 146#endif
147 sb->s_blocksize = CIFS_MAX_MSGSIZE; 147 sb->s_blocksize = CIFS_MAX_MSGSIZE;
148 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */ 148 sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
149 inode = cifs_iget(sb, ROOT_I); 149 inode = cifs_root_iget(sb, ROOT_I);
150 150
151 if (IS_ERR(inode)) { 151 if (IS_ERR(inode)) {
152 rc = PTR_ERR(inode); 152 rc = PTR_ERR(inode);
diff --git a/fs/cifs/cifsfs.h b/fs/cifs/cifsfs.h
index 051b71cfdea9..9570a0e8023f 100644
--- a/fs/cifs/cifsfs.h
+++ b/fs/cifs/cifsfs.h
@@ -36,7 +36,7 @@ extern void cifs_read_inode(struct inode *);
36 36
37/* Functions related to inodes */ 37/* Functions related to inodes */
38extern const struct inode_operations cifs_dir_inode_ops; 38extern const struct inode_operations cifs_dir_inode_ops;
39extern struct inode *cifs_iget(struct super_block *, unsigned long); 39extern struct inode *cifs_root_iget(struct super_block *, unsigned long);
40extern int cifs_create(struct inode *, struct dentry *, int, 40extern int cifs_create(struct inode *, struct dentry *, int,
41 struct nameidata *); 41 struct nameidata *);
42extern struct dentry *cifs_lookup(struct inode *, struct dentry *, 42extern struct dentry *cifs_lookup(struct inode *, struct dentry *,
@@ -100,5 +100,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
100extern const struct export_operations cifs_export_ops; 100extern const struct export_operations cifs_export_ops;
101#endif /* EXPERIMENTAL */ 101#endif /* EXPERIMENTAL */
102 102
103#define CIFS_VERSION "1.58" 103#define CIFS_VERSION "1.59"
104#endif /* _CIFSFS_H */ 104#endif /* _CIFSFS_H */
diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
index fae083930eee..f9452329bcce 100644
--- a/fs/cifs/cifsproto.h
+++ b/fs/cifs/cifsproto.h
@@ -90,10 +90,10 @@ extern struct oplock_q_entry *AllocOplockQEntry(struct inode *, u16,
90 struct cifsTconInfo *); 90 struct cifsTconInfo *);
91extern void DeleteOplockQEntry(struct oplock_q_entry *); 91extern void DeleteOplockQEntry(struct oplock_q_entry *);
92extern void DeleteTconOplockQEntries(struct cifsTconInfo *); 92extern void DeleteTconOplockQEntries(struct cifsTconInfo *);
93extern struct timespec cifs_NTtimeToUnix(u64 utc_nanoseconds_since_1601); 93extern struct timespec cifs_NTtimeToUnix(__le64 utc_nanoseconds_since_1601);
94extern u64 cifs_UnixTimeToNT(struct timespec); 94extern u64 cifs_UnixTimeToNT(struct timespec);
95extern __le64 cnvrtDosCifsTm(__u16 date, __u16 time); 95extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time,
96extern struct timespec cnvrtDosUnixTm(__u16 date, __u16 time); 96 int offset);
97 97
98extern int cifs_posix_open(char *full_path, struct inode **pinode, 98extern int cifs_posix_open(char *full_path, struct inode **pinode,
99 struct super_block *sb, int mode, int oflags, 99 struct super_block *sb, int mode, int oflags,
@@ -108,8 +108,8 @@ extern int cifs_get_inode_info(struct inode **pinode,
108extern int cifs_get_inode_info_unix(struct inode **pinode, 108extern int cifs_get_inode_info_unix(struct inode **pinode,
109 const unsigned char *search_path, 109 const unsigned char *search_path,
110 struct super_block *sb, int xid); 110 struct super_block *sb, int xid);
111extern void acl_to_uid_mode(struct inode *inode, const char *path, 111extern void acl_to_uid_mode(struct cifs_sb_info *cifs_sb, struct inode *inode,
112 const __u16 *pfid); 112 const char *path, const __u16 *pfid);
113extern int mode_to_acl(struct inode *inode, const char *path, __u64); 113extern int mode_to_acl(struct inode *inode, const char *path, __u64);
114 114
115extern int cifs_mount(struct super_block *, struct cifs_sb_info *, char *, 115extern int cifs_mount(struct super_block *, struct cifs_sb_info *, char *,
diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c
index d06260251c30..b84c61d5bca4 100644
--- a/fs/cifs/cifssmb.c
+++ b/fs/cifs/cifssmb.c
@@ -524,8 +524,8 @@ CIFSSMBNegotiate(unsigned int xid, struct cifsSesInfo *ses)
524 int val, seconds, remain, result; 524 int val, seconds, remain, result;
525 struct timespec ts, utc; 525 struct timespec ts, utc;
526 utc = CURRENT_TIME; 526 utc = CURRENT_TIME;
527 ts = cnvrtDosUnixTm(le16_to_cpu(rsp->SrvTime.Date), 527 ts = cnvrtDosUnixTm(rsp->SrvTime.Date,
528 le16_to_cpu(rsp->SrvTime.Time)); 528 rsp->SrvTime.Time, 0);
529 cFYI(1, ("SrvTime %d sec since 1970 (utc: %d) diff: %d", 529 cFYI(1, ("SrvTime %d sec since 1970 (utc: %d) diff: %d",
530 (int)ts.tv_sec, (int)utc.tv_sec, 530 (int)ts.tv_sec, (int)utc.tv_sec,
531 (int)(utc.tv_sec - ts.tv_sec))); 531 (int)(utc.tv_sec - ts.tv_sec)));
@@ -2427,8 +2427,7 @@ querySymLinkRetry:
2427 params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ; 2427 params = 2 /* level */ + 4 /* rsrvd */ + name_len /* incl null */ ;
2428 pSMB->TotalDataCount = 0; 2428 pSMB->TotalDataCount = 0;
2429 pSMB->MaxParameterCount = cpu_to_le16(2); 2429 pSMB->MaxParameterCount = cpu_to_le16(2);
2430 /* BB find exact max data count below from sess structure BB */ 2430 pSMB->MaxDataCount = cpu_to_le16(CIFSMaxBufSize);
2431 pSMB->MaxDataCount = cpu_to_le16(4000);
2432 pSMB->MaxSetupCount = 0; 2431 pSMB->MaxSetupCount = 0;
2433 pSMB->Reserved = 0; 2432 pSMB->Reserved = 0;
2434 pSMB->Flags = 0; 2433 pSMB->Flags = 0;
diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index 4aa81a507b74..97f4311b9a8e 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -35,6 +35,7 @@
35#include <linux/namei.h> 35#include <linux/namei.h>
36#include <asm/uaccess.h> 36#include <asm/uaccess.h>
37#include <asm/processor.h> 37#include <asm/processor.h>
38#include <linux/inet.h>
38#include <net/ipv6.h> 39#include <net/ipv6.h>
39#include "cifspdu.h" 40#include "cifspdu.h"
40#include "cifsglob.h" 41#include "cifsglob.h"
@@ -61,7 +62,6 @@ struct smb_vol {
61 char *domainname; 62 char *domainname;
62 char *UNC; 63 char *UNC;
63 char *UNCip; 64 char *UNCip;
64 char *in6_addr; /* ipv6 address as human readable form of in6_addr */
65 char *iocharset; /* local code page for mapping to and from Unicode */ 65 char *iocharset; /* local code page for mapping to and from Unicode */
66 char source_rfc1001_name[16]; /* netbios name of client */ 66 char source_rfc1001_name[16]; /* netbios name of client */
67 char target_rfc1001_name[16]; /* netbios name of server for Win9x/ME */ 67 char target_rfc1001_name[16]; /* netbios name of server for Win9x/ME */
@@ -827,14 +827,16 @@ cifs_parse_mount_options(char *options, const char *devname,
827 vol->target_rfc1001_name[0] = 0; 827 vol->target_rfc1001_name[0] = 0;
828 vol->linux_uid = current_uid(); /* use current_euid() instead? */ 828 vol->linux_uid = current_uid(); /* use current_euid() instead? */
829 vol->linux_gid = current_gid(); 829 vol->linux_gid = current_gid();
830 vol->dir_mode = S_IRWXUGO; 830
831 /* 2767 perms indicate mandatory locking support */ 831 /* default to only allowing write access to owner of the mount */
832 vol->file_mode = (S_IRWXUGO | S_ISGID) & (~S_IXGRP); 832 vol->dir_mode = vol->file_mode = S_IRUGO | S_IXUGO | S_IWUSR;
833 833
834 /* vol->retry default is 0 (i.e. "soft" limited retry not hard retry) */ 834 /* vol->retry default is 0 (i.e. "soft" limited retry not hard retry) */
835 vol->rw = true; 835 vol->rw = true;
836 /* default is always to request posix paths. */ 836 /* default is always to request posix paths. */
837 vol->posix_paths = 1; 837 vol->posix_paths = 1;
838 /* default to using server inode numbers where available */
839 vol->server_ino = 1;
838 840
839 if (!options) 841 if (!options)
840 return 1; 842 return 1;
@@ -955,10 +957,12 @@ cifs_parse_mount_options(char *options, const char *devname,
955 } 957 }
956 strcpy(vol->password, value); 958 strcpy(vol->password, value);
957 } 959 }
958 } else if (strnicmp(data, "ip", 2) == 0) { 960 } else if (!strnicmp(data, "ip", 2) ||
961 !strnicmp(data, "addr", 4)) {
959 if (!value || !*value) { 962 if (!value || !*value) {
960 vol->UNCip = NULL; 963 vol->UNCip = NULL;
961 } else if (strnlen(value, 35) < 35) { 964 } else if (strnlen(value, INET6_ADDRSTRLEN) <
965 INET6_ADDRSTRLEN) {
962 vol->UNCip = value; 966 vol->UNCip = value;
963 } else { 967 } else {
964 printk(KERN_WARNING "CIFS: ip address " 968 printk(KERN_WARNING "CIFS: ip address "
@@ -1092,17 +1096,17 @@ cifs_parse_mount_options(char *options, const char *devname,
1092 return 1; 1096 return 1;
1093 } 1097 }
1094 } else if (strnicmp(data, "uid", 3) == 0) { 1098 } else if (strnicmp(data, "uid", 3) == 0) {
1095 if (value && *value) { 1099 if (value && *value)
1096 vol->linux_uid = 1100 vol->linux_uid =
1097 simple_strtoul(value, &value, 0); 1101 simple_strtoul(value, &value, 0);
1102 } else if (strnicmp(data, "forceuid", 8) == 0) {
1098 vol->override_uid = 1; 1103 vol->override_uid = 1;
1099 }
1100 } else if (strnicmp(data, "gid", 3) == 0) { 1104 } else if (strnicmp(data, "gid", 3) == 0) {
1101 if (value && *value) { 1105 if (value && *value)
1102 vol->linux_gid = 1106 vol->linux_gid =
1103 simple_strtoul(value, &value, 0); 1107 simple_strtoul(value, &value, 0);
1108 } else if (strnicmp(data, "forcegid", 8) == 0) {
1104 vol->override_gid = 1; 1109 vol->override_gid = 1;
1105 }
1106 } else if (strnicmp(data, "file_mode", 4) == 0) { 1110 } else if (strnicmp(data, "file_mode", 4) == 0) {
1107 if (value && *value) { 1111 if (value && *value) {
1108 vol->file_mode = 1112 vol->file_mode =
@@ -1315,16 +1319,6 @@ cifs_parse_mount_options(char *options, const char *devname,
1315 vol->direct_io = 1; 1319 vol->direct_io = 1;
1316 } else if (strnicmp(data, "forcedirectio", 13) == 0) { 1320 } else if (strnicmp(data, "forcedirectio", 13) == 0) {
1317 vol->direct_io = 1; 1321 vol->direct_io = 1;
1318 } else if (strnicmp(data, "in6_addr", 8) == 0) {
1319 if (!value || !*value) {
1320 vol->in6_addr = NULL;
1321 } else if (strnlen(value, 49) == 48) {
1322 vol->in6_addr = value;
1323 } else {
1324 printk(KERN_WARNING "CIFS: ip v6 address not "
1325 "48 characters long\n");
1326 return 1;
1327 }
1328 } else if (strnicmp(data, "noac", 4) == 0) { 1322 } else if (strnicmp(data, "noac", 4) == 0) {
1329 printk(KERN_WARNING "CIFS: Mount option noac not " 1323 printk(KERN_WARNING "CIFS: Mount option noac not "
1330 "supported. Instead set " 1324 "supported. Instead set "
diff --git a/fs/cifs/file.c b/fs/cifs/file.c
index 302ea15f02e6..06866841b97f 100644
--- a/fs/cifs/file.c
+++ b/fs/cifs/file.c
@@ -241,7 +241,7 @@ static inline int cifs_open_inode_helper(struct inode *inode, struct file *file,
241 /* BB need same check in cifs_create too? */ 241 /* BB need same check in cifs_create too? */
242 /* if not oplocked, invalidate inode pages if mtime or file 242 /* if not oplocked, invalidate inode pages if mtime or file
243 size changed */ 243 size changed */
244 temp = cifs_NTtimeToUnix(le64_to_cpu(buf->LastWriteTime)); 244 temp = cifs_NTtimeToUnix(buf->LastWriteTime);
245 if (timespec_equal(&file->f_path.dentry->d_inode->i_mtime, &temp) && 245 if (timespec_equal(&file->f_path.dentry->d_inode->i_mtime, &temp) &&
246 (file->f_path.dentry->d_inode->i_size == 246 (file->f_path.dentry->d_inode->i_size ==
247 (loff_t)le64_to_cpu(buf->EndOfFile))) { 247 (loff_t)le64_to_cpu(buf->EndOfFile))) {
diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c
index 9c869a6dcba1..fad882b075ba 100644
--- a/fs/cifs/inode.c
+++ b/fs/cifs/inode.c
@@ -85,10 +85,10 @@ static void cifs_unix_info_to_inode(struct inode *inode,
85 __u64 num_of_bytes = le64_to_cpu(info->NumOfBytes); 85 __u64 num_of_bytes = le64_to_cpu(info->NumOfBytes);
86 __u64 end_of_file = le64_to_cpu(info->EndOfFile); 86 __u64 end_of_file = le64_to_cpu(info->EndOfFile);
87 87
88 inode->i_atime = cifs_NTtimeToUnix(le64_to_cpu(info->LastAccessTime)); 88 inode->i_atime = cifs_NTtimeToUnix(info->LastAccessTime);
89 inode->i_mtime = 89 inode->i_mtime =
90 cifs_NTtimeToUnix(le64_to_cpu(info->LastModificationTime)); 90 cifs_NTtimeToUnix(info->LastModificationTime);
91 inode->i_ctime = cifs_NTtimeToUnix(le64_to_cpu(info->LastStatusChange)); 91 inode->i_ctime = cifs_NTtimeToUnix(info->LastStatusChange);
92 inode->i_mode = le64_to_cpu(info->Permissions); 92 inode->i_mode = le64_to_cpu(info->Permissions);
93 93
94 /* 94 /*
@@ -554,14 +554,11 @@ int cifs_get_inode_info(struct inode **pinode,
554 554
555 /* Linux can not store file creation time so ignore it */ 555 /* Linux can not store file creation time so ignore it */
556 if (pfindData->LastAccessTime) 556 if (pfindData->LastAccessTime)
557 inode->i_atime = cifs_NTtimeToUnix 557 inode->i_atime = cifs_NTtimeToUnix(pfindData->LastAccessTime);
558 (le64_to_cpu(pfindData->LastAccessTime));
559 else /* do not need to use current_fs_time - time not stored */ 558 else /* do not need to use current_fs_time - time not stored */
560 inode->i_atime = CURRENT_TIME; 559 inode->i_atime = CURRENT_TIME;
561 inode->i_mtime = 560 inode->i_mtime = cifs_NTtimeToUnix(pfindData->LastWriteTime);
562 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastWriteTime)); 561 inode->i_ctime = cifs_NTtimeToUnix(pfindData->ChangeTime);
563 inode->i_ctime =
564 cifs_NTtimeToUnix(le64_to_cpu(pfindData->ChangeTime));
565 cFYI(DBG2, ("Attributes came in as 0x%x", attr)); 562 cFYI(DBG2, ("Attributes came in as 0x%x", attr));
566 if (adjustTZ && (pTcon->ses) && (pTcon->ses->server)) { 563 if (adjustTZ && (pTcon->ses) && (pTcon->ses->server)) {
567 inode->i_ctime.tv_sec += pTcon->ses->server->timeAdj; 564 inode->i_ctime.tv_sec += pTcon->ses->server->timeAdj;
@@ -629,7 +626,7 @@ int cifs_get_inode_info(struct inode **pinode,
629 /* fill in 0777 bits from ACL */ 626 /* fill in 0777 bits from ACL */
630 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) { 627 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
631 cFYI(1, ("Getting mode bits from ACL")); 628 cFYI(1, ("Getting mode bits from ACL"));
632 acl_to_uid_mode(inode, full_path, pfid); 629 acl_to_uid_mode(cifs_sb, inode, full_path, pfid);
633 } 630 }
634#endif 631#endif
635 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) { 632 if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
@@ -699,7 +696,7 @@ char *cifs_build_path_to_root(struct cifs_sb_info *cifs_sb)
699} 696}
700 697
701/* gets root inode */ 698/* gets root inode */
702struct inode *cifs_iget(struct super_block *sb, unsigned long ino) 699struct inode *cifs_root_iget(struct super_block *sb, unsigned long ino)
703{ 700{
704 int xid; 701 int xid;
705 struct cifs_sb_info *cifs_sb; 702 struct cifs_sb_info *cifs_sb;
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index e2fe998989a3..32d6baa0a54f 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -853,12 +853,12 @@ smbCalcSize_LE(struct smb_hdr *ptr)
853 853
854#define NTFS_TIME_OFFSET ((u64)(369*365 + 89) * 24 * 3600 * 10000000) 854#define NTFS_TIME_OFFSET ((u64)(369*365 + 89) * 24 * 3600 * 10000000)
855 855
856 /* 856/*
857 * Convert the NT UTC (based 1601-01-01, in hundred nanosecond units) 857 * Convert the NT UTC (based 1601-01-01, in hundred nanosecond units)
858 * into Unix UTC (based 1970-01-01, in seconds). 858 * into Unix UTC (based 1970-01-01, in seconds).
859 */ 859 */
860struct timespec 860struct timespec
861cifs_NTtimeToUnix(u64 ntutc) 861cifs_NTtimeToUnix(__le64 ntutc)
862{ 862{
863 struct timespec ts; 863 struct timespec ts;
864 /* BB what about the timezone? BB */ 864 /* BB what about the timezone? BB */
@@ -866,7 +866,7 @@ cifs_NTtimeToUnix(u64 ntutc)
866 /* Subtract the NTFS time offset, then convert to 1s intervals. */ 866 /* Subtract the NTFS time offset, then convert to 1s intervals. */
867 u64 t; 867 u64 t;
868 868
869 t = ntutc - NTFS_TIME_OFFSET; 869 t = le64_to_cpu(ntutc) - NTFS_TIME_OFFSET;
870 ts.tv_nsec = do_div(t, 10000000) * 100; 870 ts.tv_nsec = do_div(t, 10000000) * 100;
871 ts.tv_sec = t; 871 ts.tv_sec = t;
872 return ts; 872 return ts;
@@ -883,16 +883,12 @@ cifs_UnixTimeToNT(struct timespec t)
883static int total_days_of_prev_months[] = 883static int total_days_of_prev_months[] =
884{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; 884{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
885 885
886 886struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time, int offset)
887__le64 cnvrtDosCifsTm(__u16 date, __u16 time)
888{
889 return cpu_to_le64(cifs_UnixTimeToNT(cnvrtDosUnixTm(date, time)));
890}
891
892struct timespec cnvrtDosUnixTm(__u16 date, __u16 time)
893{ 887{
894 struct timespec ts; 888 struct timespec ts;
895 int sec, min, days, month, year; 889 int sec, min, days, month, year;
890 u16 date = le16_to_cpu(le_date);
891 u16 time = le16_to_cpu(le_time);
896 SMB_TIME *st = (SMB_TIME *)&time; 892 SMB_TIME *st = (SMB_TIME *)&time;
897 SMB_DATE *sd = (SMB_DATE *)&date; 893 SMB_DATE *sd = (SMB_DATE *)&date;
898 894
@@ -933,7 +929,7 @@ struct timespec cnvrtDosUnixTm(__u16 date, __u16 time)
933 days -= ((year & 0x03) == 0) && (month < 2 ? 1 : 0); 929 days -= ((year & 0x03) == 0) && (month < 2 ? 1 : 0);
934 sec += 24 * 60 * 60 * days; 930 sec += 24 * 60 * 60 * days;
935 931
936 ts.tv_sec = sec; 932 ts.tv_sec = sec + offset;
937 933
938 /* cFYI(1,("sec after cnvrt dos to unix time %d",sec)); */ 934 /* cFYI(1,("sec after cnvrt dos to unix time %d",sec)); */
939 935
diff --git a/fs/cifs/readdir.c b/fs/cifs/readdir.c
index 964e097c8203..86d0055dc529 100644
--- a/fs/cifs/readdir.c
+++ b/fs/cifs/readdir.c
@@ -115,17 +115,6 @@ construct_dentry(struct qstr *qstring, struct file *file,
115 return rc; 115 return rc;
116} 116}
117 117
118static void AdjustForTZ(struct cifsTconInfo *tcon, struct inode *inode)
119{
120 if ((tcon) && (tcon->ses) && (tcon->ses->server)) {
121 inode->i_ctime.tv_sec += tcon->ses->server->timeAdj;
122 inode->i_mtime.tv_sec += tcon->ses->server->timeAdj;
123 inode->i_atime.tv_sec += tcon->ses->server->timeAdj;
124 }
125 return;
126}
127
128
129static void fill_in_inode(struct inode *tmp_inode, int new_buf_type, 118static void fill_in_inode(struct inode *tmp_inode, int new_buf_type,
130 char *buf, unsigned int *pobject_type, int isNewInode) 119 char *buf, unsigned int *pobject_type, int isNewInode)
131{ 120{
@@ -150,26 +139,25 @@ static void fill_in_inode(struct inode *tmp_inode, int new_buf_type,
150 allocation_size = le64_to_cpu(pfindData->AllocationSize); 139 allocation_size = le64_to_cpu(pfindData->AllocationSize);
151 end_of_file = le64_to_cpu(pfindData->EndOfFile); 140 end_of_file = le64_to_cpu(pfindData->EndOfFile);
152 tmp_inode->i_atime = 141 tmp_inode->i_atime =
153 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastAccessTime)); 142 cifs_NTtimeToUnix(pfindData->LastAccessTime);
154 tmp_inode->i_mtime = 143 tmp_inode->i_mtime =
155 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastWriteTime)); 144 cifs_NTtimeToUnix(pfindData->LastWriteTime);
156 tmp_inode->i_ctime = 145 tmp_inode->i_ctime =
157 cifs_NTtimeToUnix(le64_to_cpu(pfindData->ChangeTime)); 146 cifs_NTtimeToUnix(pfindData->ChangeTime);
158 } else { /* legacy, OS2 and DOS style */ 147 } else { /* legacy, OS2 and DOS style */
159/* struct timespec ts;*/ 148 int offset = cifs_sb->tcon->ses->server->timeAdj;
160 FIND_FILE_STANDARD_INFO *pfindData = 149 FIND_FILE_STANDARD_INFO *pfindData =
161 (FIND_FILE_STANDARD_INFO *)buf; 150 (FIND_FILE_STANDARD_INFO *)buf;
162 151
163 tmp_inode->i_mtime = cnvrtDosUnixTm( 152 tmp_inode->i_mtime = cnvrtDosUnixTm(pfindData->LastWriteDate,
164 le16_to_cpu(pfindData->LastWriteDate), 153 pfindData->LastWriteTime,
165 le16_to_cpu(pfindData->LastWriteTime)); 154 offset);
166 tmp_inode->i_atime = cnvrtDosUnixTm( 155 tmp_inode->i_atime = cnvrtDosUnixTm(pfindData->LastAccessDate,
167 le16_to_cpu(pfindData->LastAccessDate), 156 pfindData->LastAccessTime,
168 le16_to_cpu(pfindData->LastAccessTime)); 157 offset);
169 tmp_inode->i_ctime = cnvrtDosUnixTm( 158 tmp_inode->i_ctime = cnvrtDosUnixTm(pfindData->LastWriteDate,
170 le16_to_cpu(pfindData->LastWriteDate), 159 pfindData->LastWriteTime,
171 le16_to_cpu(pfindData->LastWriteTime)); 160 offset);
172 AdjustForTZ(cifs_sb->tcon, tmp_inode);
173 attr = le16_to_cpu(pfindData->Attributes); 161 attr = le16_to_cpu(pfindData->Attributes);
174 allocation_size = le32_to_cpu(pfindData->AllocationSize); 162 allocation_size = le32_to_cpu(pfindData->AllocationSize);
175 end_of_file = le32_to_cpu(pfindData->DataSize); 163 end_of_file = le32_to_cpu(pfindData->DataSize);
@@ -331,11 +319,11 @@ static void unix_fill_in_inode(struct inode *tmp_inode,
331 local_size = tmp_inode->i_size; 319 local_size = tmp_inode->i_size;
332 320
333 tmp_inode->i_atime = 321 tmp_inode->i_atime =
334 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastAccessTime)); 322 cifs_NTtimeToUnix(pfindData->LastAccessTime);
335 tmp_inode->i_mtime = 323 tmp_inode->i_mtime =
336 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastModificationTime)); 324 cifs_NTtimeToUnix(pfindData->LastModificationTime);
337 tmp_inode->i_ctime = 325 tmp_inode->i_ctime =
338 cifs_NTtimeToUnix(le64_to_cpu(pfindData->LastStatusChange)); 326 cifs_NTtimeToUnix(pfindData->LastStatusChange);
339 327
340 tmp_inode->i_mode = le64_to_cpu(pfindData->Permissions); 328 tmp_inode->i_mode = le64_to_cpu(pfindData->Permissions);
341 /* since we set the inode type below we need to mask off type 329 /* since we set the inode type below we need to mask off type
diff --git a/fs/coda/file.c b/fs/coda/file.c
index 6a347fbc998a..ffd42815fda1 100644
--- a/fs/coda/file.c
+++ b/fs/coda/file.c
@@ -47,6 +47,8 @@ coda_file_splice_read(struct file *coda_file, loff_t *ppos,
47 struct pipe_inode_info *pipe, size_t count, 47 struct pipe_inode_info *pipe, size_t count,
48 unsigned int flags) 48 unsigned int flags)
49{ 49{
50 ssize_t (*splice_read)(struct file *, loff_t *,
51 struct pipe_inode_info *, size_t, unsigned int);
50 struct coda_file_info *cfi; 52 struct coda_file_info *cfi;
51 struct file *host_file; 53 struct file *host_file;
52 54
@@ -54,10 +56,11 @@ coda_file_splice_read(struct file *coda_file, loff_t *ppos,
54 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); 56 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
55 host_file = cfi->cfi_container; 57 host_file = cfi->cfi_container;
56 58
57 if (!host_file->f_op || !host_file->f_op->splice_read) 59 splice_read = host_file->f_op->splice_read;
58 return -EINVAL; 60 if (!splice_read)
61 splice_read = default_file_splice_read;
59 62
60 return host_file->f_op->splice_read(host_file, ppos, pipe, count,flags); 63 return splice_read(host_file, ppos, pipe, count, flags);
61} 64}
62 65
63static ssize_t 66static ssize_t
diff --git a/fs/compat.c b/fs/compat.c
index 681ed81e6be0..bb2a9b2e8173 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -1488,7 +1488,7 @@ int compat_do_execve(char * filename,
1488 if (!bprm) 1488 if (!bprm)
1489 goto out_files; 1489 goto out_files;
1490 1490
1491 retval = mutex_lock_interruptible(&current->cred_exec_mutex); 1491 retval = mutex_lock_interruptible(&current->cred_guard_mutex);
1492 if (retval < 0) 1492 if (retval < 0)
1493 goto out_free; 1493 goto out_free;
1494 current->in_execve = 1; 1494 current->in_execve = 1;
@@ -1550,7 +1550,7 @@ int compat_do_execve(char * filename,
1550 /* execve succeeded */ 1550 /* execve succeeded */
1551 current->fs->in_exec = 0; 1551 current->fs->in_exec = 0;
1552 current->in_execve = 0; 1552 current->in_execve = 0;
1553 mutex_unlock(&current->cred_exec_mutex); 1553 mutex_unlock(&current->cred_guard_mutex);
1554 acct_update_integrals(current); 1554 acct_update_integrals(current);
1555 free_bprm(bprm); 1555 free_bprm(bprm);
1556 if (displaced) 1556 if (displaced)
@@ -1573,7 +1573,7 @@ out_unmark:
1573 1573
1574out_unlock: 1574out_unlock:
1575 current->in_execve = 0; 1575 current->in_execve = 0;
1576 mutex_unlock(&current->cred_exec_mutex); 1576 mutex_unlock(&current->cred_guard_mutex);
1577 1577
1578out_free: 1578out_free:
1579 free_bprm(bprm); 1579 free_bprm(bprm);
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c
index c68edb969441..9b1d285f9fe6 100644
--- a/fs/devpts/inode.c
+++ b/fs/devpts/inode.c
@@ -557,8 +557,10 @@ static int __init init_devpts_fs(void)
557 int err = register_filesystem(&devpts_fs_type); 557 int err = register_filesystem(&devpts_fs_type);
558 if (!err) { 558 if (!err) {
559 devpts_mnt = kern_mount(&devpts_fs_type); 559 devpts_mnt = kern_mount(&devpts_fs_type);
560 if (IS_ERR(devpts_mnt)) 560 if (IS_ERR(devpts_mnt)) {
561 err = PTR_ERR(devpts_mnt); 561 err = PTR_ERR(devpts_mnt);
562 unregister_filesystem(&devpts_fs_type);
563 }
562 } 564 }
563 return err; 565 return err;
564} 566}
diff --git a/fs/direct-io.c b/fs/direct-io.c
index 05763bbc2050..8b10b87dc01a 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -1127,7 +1127,7 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
1127 rw = WRITE_ODIRECT; 1127 rw = WRITE_ODIRECT;
1128 1128
1129 if (bdev) 1129 if (bdev)
1130 bdev_blkbits = blksize_bits(bdev_hardsect_size(bdev)); 1130 bdev_blkbits = blksize_bits(bdev_logical_block_size(bdev));
1131 1131
1132 if (offset & blocksize_mask) { 1132 if (offset & blocksize_mask) {
1133 if (bdev) 1133 if (bdev)
diff --git a/fs/exec.c b/fs/exec.c
index 895823d0149d..a7fcd975c6b2 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1016,7 +1016,7 @@ void install_exec_creds(struct linux_binprm *bprm)
1016 commit_creds(bprm->cred); 1016 commit_creds(bprm->cred);
1017 bprm->cred = NULL; 1017 bprm->cred = NULL;
1018 1018
1019 /* cred_exec_mutex must be held at least to this point to prevent 1019 /* cred_guard_mutex must be held at least to this point to prevent
1020 * ptrace_attach() from altering our determination of the task's 1020 * ptrace_attach() from altering our determination of the task's
1021 * credentials; any time after this it may be unlocked */ 1021 * credentials; any time after this it may be unlocked */
1022 1022
@@ -1026,7 +1026,7 @@ EXPORT_SYMBOL(install_exec_creds);
1026 1026
1027/* 1027/*
1028 * determine how safe it is to execute the proposed program 1028 * determine how safe it is to execute the proposed program
1029 * - the caller must hold current->cred_exec_mutex to protect against 1029 * - the caller must hold current->cred_guard_mutex to protect against
1030 * PTRACE_ATTACH 1030 * PTRACE_ATTACH
1031 */ 1031 */
1032int check_unsafe_exec(struct linux_binprm *bprm) 1032int check_unsafe_exec(struct linux_binprm *bprm)
@@ -1268,7 +1268,7 @@ int do_execve(char * filename,
1268 if (!bprm) 1268 if (!bprm)
1269 goto out_files; 1269 goto out_files;
1270 1270
1271 retval = mutex_lock_interruptible(&current->cred_exec_mutex); 1271 retval = mutex_lock_interruptible(&current->cred_guard_mutex);
1272 if (retval < 0) 1272 if (retval < 0)
1273 goto out_free; 1273 goto out_free;
1274 current->in_execve = 1; 1274 current->in_execve = 1;
@@ -1331,7 +1331,7 @@ int do_execve(char * filename,
1331 /* execve succeeded */ 1331 /* execve succeeded */
1332 current->fs->in_exec = 0; 1332 current->fs->in_exec = 0;
1333 current->in_execve = 0; 1333 current->in_execve = 0;
1334 mutex_unlock(&current->cred_exec_mutex); 1334 mutex_unlock(&current->cred_guard_mutex);
1335 acct_update_integrals(current); 1335 acct_update_integrals(current);
1336 free_bprm(bprm); 1336 free_bprm(bprm);
1337 if (displaced) 1337 if (displaced)
@@ -1354,7 +1354,7 @@ out_unmark:
1354 1354
1355out_unlock: 1355out_unlock:
1356 current->in_execve = 0; 1356 current->in_execve = 0;
1357 mutex_unlock(&current->cred_exec_mutex); 1357 mutex_unlock(&current->cred_guard_mutex);
1358 1358
1359out_free: 1359out_free:
1360 free_bprm(bprm); 1360 free_bprm(bprm);
diff --git a/fs/exofs/osd.c b/fs/exofs/osd.c
index b249ae97fb15..06ca92672eb5 100644
--- a/fs/exofs/osd.c
+++ b/fs/exofs/osd.c
@@ -50,10 +50,10 @@ int exofs_check_ok_resid(struct osd_request *or, u64 *in_resid, u64 *out_resid)
50 50
51 /* FIXME: should be include in osd_sense_info */ 51 /* FIXME: should be include in osd_sense_info */
52 if (in_resid) 52 if (in_resid)
53 *in_resid = or->in.req ? or->in.req->data_len : 0; 53 *in_resid = or->in.req ? or->in.req->resid_len : 0;
54 54
55 if (out_resid) 55 if (out_resid)
56 *out_resid = or->out.req ? or->out.req->data_len : 0; 56 *out_resid = or->out.req ? or->out.req->resid_len : 0;
57 57
58 return ret; 58 return ret;
59} 59}
diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index 5c4afe652245..e3c748faf2db 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -1093,6 +1093,7 @@ failed_mount:
1093 brelse(bh); 1093 brelse(bh);
1094failed_sbi: 1094failed_sbi:
1095 sb->s_fs_info = NULL; 1095 sb->s_fs_info = NULL;
1096 kfree(sbi->s_blockgroup_lock);
1096 kfree(sbi); 1097 kfree(sbi);
1097 return ret; 1098 return ret;
1098} 1099}
diff --git a/fs/ext3/super.c b/fs/ext3/super.c
index 599dbfe504c3..3c70d52afb10 100644
--- a/fs/ext3/super.c
+++ b/fs/ext3/super.c
@@ -1696,7 +1696,7 @@ static int ext3_fill_super (struct super_block *sb, void *data, int silent)
1696 goto failed_mount; 1696 goto failed_mount;
1697 } 1697 }
1698 1698
1699 hblock = bdev_hardsect_size(sb->s_bdev); 1699 hblock = bdev_logical_block_size(sb->s_bdev);
1700 if (sb->s_blocksize != blocksize) { 1700 if (sb->s_blocksize != blocksize) {
1701 /* 1701 /*
1702 * Make sure the blocksize for the filesystem is larger 1702 * Make sure the blocksize for the filesystem is larger
@@ -2021,6 +2021,7 @@ failed_mount:
2021 brelse(bh); 2021 brelse(bh);
2022out_fail: 2022out_fail:
2023 sb->s_fs_info = NULL; 2023 sb->s_fs_info = NULL;
2024 kfree(sbi->s_blockgroup_lock);
2024 kfree(sbi); 2025 kfree(sbi);
2025 lock_kernel(); 2026 lock_kernel();
2026 return ret; 2027 return ret;
@@ -2119,7 +2120,7 @@ static journal_t *ext3_get_dev_journal(struct super_block *sb,
2119 } 2120 }
2120 2121
2121 blocksize = sb->s_blocksize; 2122 blocksize = sb->s_blocksize;
2122 hblock = bdev_hardsect_size(bdev); 2123 hblock = bdev_logical_block_size(bdev);
2123 if (blocksize < hblock) { 2124 if (blocksize < hblock) {
2124 printk(KERN_ERR 2125 printk(KERN_ERR
2125 "EXT3-fs: blocksize too small for journal device.\n"); 2126 "EXT3-fs: blocksize too small for journal device.\n");
diff --git a/fs/ext4/Makefile b/fs/ext4/Makefile
index a8ff003a00f7..8a34710ecf40 100644
--- a/fs/ext4/Makefile
+++ b/fs/ext4/Makefile
@@ -5,8 +5,8 @@
5obj-$(CONFIG_EXT4_FS) += ext4.o 5obj-$(CONFIG_EXT4_FS) += ext4.o
6 6
7ext4-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \ 7ext4-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \
8 ioctl.o namei.o super.o symlink.o hash.o resize.o extents.o \ 8 ioctl.o namei.o super.o symlink.o hash.o resize.o extents.o \
9 ext4_jbd2.o migrate.o mballoc.o 9 ext4_jbd2.o migrate.o mballoc.o block_validity.o
10 10
11ext4-$(CONFIG_EXT4_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o 11ext4-$(CONFIG_EXT4_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o
12ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o 12ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 53c72ad85877..e2126d70dff5 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -19,7 +19,6 @@
19#include <linux/buffer_head.h> 19#include <linux/buffer_head.h>
20#include "ext4.h" 20#include "ext4.h"
21#include "ext4_jbd2.h" 21#include "ext4_jbd2.h"
22#include "group.h"
23#include "mballoc.h" 22#include "mballoc.h"
24 23
25/* 24/*
@@ -88,6 +87,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
88 ext4_group_t block_group, struct ext4_group_desc *gdp) 87 ext4_group_t block_group, struct ext4_group_desc *gdp)
89{ 88{
90 int bit, bit_max; 89 int bit, bit_max;
90 ext4_group_t ngroups = ext4_get_groups_count(sb);
91 unsigned free_blocks, group_blocks; 91 unsigned free_blocks, group_blocks;
92 struct ext4_sb_info *sbi = EXT4_SB(sb); 92 struct ext4_sb_info *sbi = EXT4_SB(sb);
93 93
@@ -123,7 +123,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
123 bit_max += ext4_bg_num_gdb(sb, block_group); 123 bit_max += ext4_bg_num_gdb(sb, block_group);
124 } 124 }
125 125
126 if (block_group == sbi->s_groups_count - 1) { 126 if (block_group == ngroups - 1) {
127 /* 127 /*
128 * Even though mke2fs always initialize first and last group 128 * Even though mke2fs always initialize first and last group
129 * if some other tool enabled the EXT4_BG_BLOCK_UNINIT we need 129 * if some other tool enabled the EXT4_BG_BLOCK_UNINIT we need
@@ -131,7 +131,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
131 */ 131 */
132 group_blocks = ext4_blocks_count(sbi->s_es) - 132 group_blocks = ext4_blocks_count(sbi->s_es) -
133 le32_to_cpu(sbi->s_es->s_first_data_block) - 133 le32_to_cpu(sbi->s_es->s_first_data_block) -
134 (EXT4_BLOCKS_PER_GROUP(sb) * (sbi->s_groups_count - 1)); 134 (EXT4_BLOCKS_PER_GROUP(sb) * (ngroups - 1));
135 } else { 135 } else {
136 group_blocks = EXT4_BLOCKS_PER_GROUP(sb); 136 group_blocks = EXT4_BLOCKS_PER_GROUP(sb);
137 } 137 }
@@ -205,18 +205,18 @@ struct ext4_group_desc * ext4_get_group_desc(struct super_block *sb,
205{ 205{
206 unsigned int group_desc; 206 unsigned int group_desc;
207 unsigned int offset; 207 unsigned int offset;
208 ext4_group_t ngroups = ext4_get_groups_count(sb);
208 struct ext4_group_desc *desc; 209 struct ext4_group_desc *desc;
209 struct ext4_sb_info *sbi = EXT4_SB(sb); 210 struct ext4_sb_info *sbi = EXT4_SB(sb);
210 211
211 if (block_group >= sbi->s_groups_count) { 212 if (block_group >= ngroups) {
212 ext4_error(sb, "ext4_get_group_desc", 213 ext4_error(sb, "ext4_get_group_desc",
213 "block_group >= groups_count - " 214 "block_group >= groups_count - "
214 "block_group = %u, groups_count = %u", 215 "block_group = %u, groups_count = %u",
215 block_group, sbi->s_groups_count); 216 block_group, ngroups);
216 217
217 return NULL; 218 return NULL;
218 } 219 }
219 smp_rmb();
220 220
221 group_desc = block_group >> EXT4_DESC_PER_BLOCK_BITS(sb); 221 group_desc = block_group >> EXT4_DESC_PER_BLOCK_BITS(sb);
222 offset = block_group & (EXT4_DESC_PER_BLOCK(sb) - 1); 222 offset = block_group & (EXT4_DESC_PER_BLOCK(sb) - 1);
@@ -326,16 +326,16 @@ ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group)
326 unlock_buffer(bh); 326 unlock_buffer(bh);
327 return bh; 327 return bh;
328 } 328 }
329 spin_lock(sb_bgl_lock(EXT4_SB(sb), block_group)); 329 ext4_lock_group(sb, block_group);
330 if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { 330 if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
331 ext4_init_block_bitmap(sb, bh, block_group, desc); 331 ext4_init_block_bitmap(sb, bh, block_group, desc);
332 set_bitmap_uptodate(bh); 332 set_bitmap_uptodate(bh);
333 set_buffer_uptodate(bh); 333 set_buffer_uptodate(bh);
334 spin_unlock(sb_bgl_lock(EXT4_SB(sb), block_group)); 334 ext4_unlock_group(sb, block_group);
335 unlock_buffer(bh); 335 unlock_buffer(bh);
336 return bh; 336 return bh;
337 } 337 }
338 spin_unlock(sb_bgl_lock(EXT4_SB(sb), block_group)); 338 ext4_unlock_group(sb, block_group);
339 if (buffer_uptodate(bh)) { 339 if (buffer_uptodate(bh)) {
340 /* 340 /*
341 * if not uninit if bh is uptodate, 341 * if not uninit if bh is uptodate,
@@ -451,7 +451,7 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb,
451 down_write(&grp->alloc_sem); 451 down_write(&grp->alloc_sem);
452 for (i = 0, blocks_freed = 0; i < count; i++) { 452 for (i = 0, blocks_freed = 0; i < count; i++) {
453 BUFFER_TRACE(bitmap_bh, "clear bit"); 453 BUFFER_TRACE(bitmap_bh, "clear bit");
454 if (!ext4_clear_bit_atomic(sb_bgl_lock(sbi, block_group), 454 if (!ext4_clear_bit_atomic(ext4_group_lock_ptr(sb, block_group),
455 bit + i, bitmap_bh->b_data)) { 455 bit + i, bitmap_bh->b_data)) {
456 ext4_error(sb, __func__, 456 ext4_error(sb, __func__,
457 "bit already cleared for block %llu", 457 "bit already cleared for block %llu",
@@ -461,11 +461,11 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb,
461 blocks_freed++; 461 blocks_freed++;
462 } 462 }
463 } 463 }
464 spin_lock(sb_bgl_lock(sbi, block_group)); 464 ext4_lock_group(sb, block_group);
465 blk_free_count = blocks_freed + ext4_free_blks_count(sb, desc); 465 blk_free_count = blocks_freed + ext4_free_blks_count(sb, desc);
466 ext4_free_blks_set(sb, desc, blk_free_count); 466 ext4_free_blks_set(sb, desc, blk_free_count);
467 desc->bg_checksum = ext4_group_desc_csum(sbi, block_group, desc); 467 desc->bg_checksum = ext4_group_desc_csum(sbi, block_group, desc);
468 spin_unlock(sb_bgl_lock(sbi, block_group)); 468 ext4_unlock_group(sb, block_group);
469 percpu_counter_add(&sbi->s_freeblocks_counter, blocks_freed); 469 percpu_counter_add(&sbi->s_freeblocks_counter, blocks_freed);
470 470
471 if (sbi->s_log_groups_per_flex) { 471 if (sbi->s_log_groups_per_flex) {
@@ -665,7 +665,7 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)
665 ext4_fsblk_t desc_count; 665 ext4_fsblk_t desc_count;
666 struct ext4_group_desc *gdp; 666 struct ext4_group_desc *gdp;
667 ext4_group_t i; 667 ext4_group_t i;
668 ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count; 668 ext4_group_t ngroups = ext4_get_groups_count(sb);
669#ifdef EXT4FS_DEBUG 669#ifdef EXT4FS_DEBUG
670 struct ext4_super_block *es; 670 struct ext4_super_block *es;
671 ext4_fsblk_t bitmap_count; 671 ext4_fsblk_t bitmap_count;
@@ -677,7 +677,6 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)
677 bitmap_count = 0; 677 bitmap_count = 0;
678 gdp = NULL; 678 gdp = NULL;
679 679
680 smp_rmb();
681 for (i = 0; i < ngroups; i++) { 680 for (i = 0; i < ngroups; i++) {
682 gdp = ext4_get_group_desc(sb, i, NULL); 681 gdp = ext4_get_group_desc(sb, i, NULL);
683 if (!gdp) 682 if (!gdp)
@@ -700,7 +699,6 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)
700 return bitmap_count; 699 return bitmap_count;
701#else 700#else
702 desc_count = 0; 701 desc_count = 0;
703 smp_rmb();
704 for (i = 0; i < ngroups; i++) { 702 for (i = 0; i < ngroups; i++) {
705 gdp = ext4_get_group_desc(sb, i, NULL); 703 gdp = ext4_get_group_desc(sb, i, NULL);
706 if (!gdp) 704 if (!gdp)
diff --git a/fs/ext4/block_validity.c b/fs/ext4/block_validity.c
new file mode 100644
index 000000000000..50784ef07563
--- /dev/null
+++ b/fs/ext4/block_validity.c
@@ -0,0 +1,244 @@
1/*
2 * linux/fs/ext4/block_validity.c
3 *
4 * Copyright (C) 2009
5 * Theodore Ts'o (tytso@mit.edu)
6 *
7 * Track which blocks in the filesystem are metadata blocks that
8 * should never be used as data blocks by files or directories.
9 */
10
11#include <linux/time.h>
12#include <linux/fs.h>
13#include <linux/namei.h>
14#include <linux/quotaops.h>
15#include <linux/buffer_head.h>
16#include <linux/module.h>
17#include <linux/swap.h>
18#include <linux/pagemap.h>
19#include <linux/version.h>
20#include <linux/blkdev.h>
21#include <linux/mutex.h>
22#include "ext4.h"
23
24struct ext4_system_zone {
25 struct rb_node node;
26 ext4_fsblk_t start_blk;
27 unsigned int count;
28};
29
30static struct kmem_cache *ext4_system_zone_cachep;
31
32int __init init_ext4_system_zone(void)
33{
34 ext4_system_zone_cachep = KMEM_CACHE(ext4_system_zone,
35 SLAB_RECLAIM_ACCOUNT);
36 if (ext4_system_zone_cachep == NULL)
37 return -ENOMEM;
38 return 0;
39}
40
41void exit_ext4_system_zone(void)
42{
43 kmem_cache_destroy(ext4_system_zone_cachep);
44}
45
46static inline int can_merge(struct ext4_system_zone *entry1,
47 struct ext4_system_zone *entry2)
48{
49 if ((entry1->start_blk + entry1->count) == entry2->start_blk)
50 return 1;
51 return 0;
52}
53
54/*
55 * Mark a range of blocks as belonging to the "system zone" --- that
56 * is, filesystem metadata blocks which should never be used by
57 * inodes.
58 */
59static int add_system_zone(struct ext4_sb_info *sbi,
60 ext4_fsblk_t start_blk,
61 unsigned int count)
62{
63 struct ext4_system_zone *new_entry = NULL, *entry;
64 struct rb_node **n = &sbi->system_blks.rb_node, *node;
65 struct rb_node *parent = NULL, *new_node = NULL;
66
67 while (*n) {
68 parent = *n;
69 entry = rb_entry(parent, struct ext4_system_zone, node);
70 if (start_blk < entry->start_blk)
71 n = &(*n)->rb_left;
72 else if (start_blk >= (entry->start_blk + entry->count))
73 n = &(*n)->rb_right;
74 else {
75 if (start_blk + count > (entry->start_blk +
76 entry->count))
77 entry->count = (start_blk + count -
78 entry->start_blk);
79 new_node = *n;
80 new_entry = rb_entry(new_node, struct ext4_system_zone,
81 node);
82 break;
83 }
84 }
85
86 if (!new_entry) {
87 new_entry = kmem_cache_alloc(ext4_system_zone_cachep,
88 GFP_KERNEL);
89 if (!new_entry)
90 return -ENOMEM;
91 new_entry->start_blk = start_blk;
92 new_entry->count = count;
93 new_node = &new_entry->node;
94
95 rb_link_node(new_node, parent, n);
96 rb_insert_color(new_node, &sbi->system_blks);
97 }
98
99 /* Can we merge to the left? */
100 node = rb_prev(new_node);
101 if (node) {
102 entry = rb_entry(node, struct ext4_system_zone, node);
103 if (can_merge(entry, new_entry)) {
104 new_entry->start_blk = entry->start_blk;
105 new_entry->count += entry->count;
106 rb_erase(node, &sbi->system_blks);
107 kmem_cache_free(ext4_system_zone_cachep, entry);
108 }
109 }
110
111 /* Can we merge to the right? */
112 node = rb_next(new_node);
113 if (node) {
114 entry = rb_entry(node, struct ext4_system_zone, node);
115 if (can_merge(new_entry, entry)) {
116 new_entry->count += entry->count;
117 rb_erase(node, &sbi->system_blks);
118 kmem_cache_free(ext4_system_zone_cachep, entry);
119 }
120 }
121 return 0;
122}
123
124static void debug_print_tree(struct ext4_sb_info *sbi)
125{
126 struct rb_node *node;
127 struct ext4_system_zone *entry;
128 int first = 1;
129
130 printk(KERN_INFO "System zones: ");
131 node = rb_first(&sbi->system_blks);
132 while (node) {
133 entry = rb_entry(node, struct ext4_system_zone, node);
134 printk("%s%llu-%llu", first ? "" : ", ",
135 entry->start_blk, entry->start_blk + entry->count - 1);
136 first = 0;
137 node = rb_next(node);
138 }
139 printk("\n");
140}
141
142int ext4_setup_system_zone(struct super_block *sb)
143{
144 ext4_group_t ngroups = ext4_get_groups_count(sb);
145 struct ext4_sb_info *sbi = EXT4_SB(sb);
146 struct ext4_group_desc *gdp;
147 ext4_group_t i;
148 int flex_size = ext4_flex_bg_size(sbi);
149 int ret;
150
151 if (!test_opt(sb, BLOCK_VALIDITY)) {
152 if (EXT4_SB(sb)->system_blks.rb_node)
153 ext4_release_system_zone(sb);
154 return 0;
155 }
156 if (EXT4_SB(sb)->system_blks.rb_node)
157 return 0;
158
159 for (i=0; i < ngroups; i++) {
160 if (ext4_bg_has_super(sb, i) &&
161 ((i < 5) || ((i % flex_size) == 0)))
162 add_system_zone(sbi, ext4_group_first_block_no(sb, i),
163 sbi->s_gdb_count + 1);
164 gdp = ext4_get_group_desc(sb, i, NULL);
165 ret = add_system_zone(sbi, ext4_block_bitmap(sb, gdp), 1);
166 if (ret)
167 return ret;
168 ret = add_system_zone(sbi, ext4_inode_bitmap(sb, gdp), 1);
169 if (ret)
170 return ret;
171 ret = add_system_zone(sbi, ext4_inode_table(sb, gdp),
172 sbi->s_itb_per_group);
173 if (ret)
174 return ret;
175 }
176
177 if (test_opt(sb, DEBUG))
178 debug_print_tree(EXT4_SB(sb));
179 return 0;
180}
181
182/* Called when the filesystem is unmounted */
183void ext4_release_system_zone(struct super_block *sb)
184{
185 struct rb_node *n = EXT4_SB(sb)->system_blks.rb_node;
186 struct rb_node *parent;
187 struct ext4_system_zone *entry;
188
189 while (n) {
190 /* Do the node's children first */
191 if (n->rb_left) {
192 n = n->rb_left;
193 continue;
194 }
195 if (n->rb_right) {
196 n = n->rb_right;
197 continue;
198 }
199 /*
200 * The node has no children; free it, and then zero
201 * out parent's link to it. Finally go to the
202 * beginning of the loop and try to free the parent
203 * node.
204 */
205 parent = rb_parent(n);
206 entry = rb_entry(n, struct ext4_system_zone, node);
207 kmem_cache_free(ext4_system_zone_cachep, entry);
208 if (!parent)
209 EXT4_SB(sb)->system_blks.rb_node = NULL;
210 else if (parent->rb_left == n)
211 parent->rb_left = NULL;
212 else if (parent->rb_right == n)
213 parent->rb_right = NULL;
214 n = parent;
215 }
216 EXT4_SB(sb)->system_blks.rb_node = NULL;
217}
218
219/*
220 * Returns 1 if the passed-in block region (start_blk,
221 * start_blk+count) is valid; 0 if some part of the block region
222 * overlaps with filesystem metadata blocks.
223 */
224int ext4_data_block_valid(struct ext4_sb_info *sbi, ext4_fsblk_t start_blk,
225 unsigned int count)
226{
227 struct ext4_system_zone *entry;
228 struct rb_node *n = sbi->system_blks.rb_node;
229
230 if ((start_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
231 (start_blk + count > ext4_blocks_count(sbi->s_es)))
232 return 0;
233 while (n) {
234 entry = rb_entry(n, struct ext4_system_zone, node);
235 if (start_blk + count - 1 < entry->start_blk)
236 n = n->rb_left;
237 else if (start_blk >= (entry->start_blk + entry->count))
238 n = n->rb_right;
239 else
240 return 0;
241 }
242 return 1;
243}
244
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index b64789929a65..9dc93168e262 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -131,8 +131,7 @@ static int ext4_readdir(struct file *filp,
131 struct buffer_head *bh = NULL; 131 struct buffer_head *bh = NULL;
132 132
133 map_bh.b_state = 0; 133 map_bh.b_state = 0;
134 err = ext4_get_blocks_wrap(NULL, inode, blk, 1, &map_bh, 134 err = ext4_get_blocks(NULL, inode, blk, 1, &map_bh, 0);
135 0, 0, 0);
136 if (err > 0) { 135 if (err > 0) {
137 pgoff_t index = map_bh.b_blocknr >> 136 pgoff_t index = map_bh.b_blocknr >>
138 (PAGE_CACHE_SHIFT - inode->i_blkbits); 137 (PAGE_CACHE_SHIFT - inode->i_blkbits);
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index d0f15ef56de1..cc7d5edc38c9 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -21,7 +21,14 @@
21#include <linux/magic.h> 21#include <linux/magic.h>
22#include <linux/jbd2.h> 22#include <linux/jbd2.h>
23#include <linux/quota.h> 23#include <linux/quota.h>
24#include "ext4_i.h" 24#include <linux/rwsem.h>
25#include <linux/rbtree.h>
26#include <linux/seqlock.h>
27#include <linux/mutex.h>
28#include <linux/timer.h>
29#include <linux/wait.h>
30#include <linux/blockgroup_lock.h>
31#include <linux/percpu_counter.h>
25 32
26/* 33/*
27 * The fourth extended filesystem constants/structures 34 * The fourth extended filesystem constants/structures
@@ -46,6 +53,19 @@
46#define ext4_debug(f, a...) do {} while (0) 53#define ext4_debug(f, a...) do {} while (0)
47#endif 54#endif
48 55
56/* data type for block offset of block group */
57typedef int ext4_grpblk_t;
58
59/* data type for filesystem-wide blocks number */
60typedef unsigned long long ext4_fsblk_t;
61
62/* data type for file logical block number */
63typedef __u32 ext4_lblk_t;
64
65/* data type for block group number */
66typedef unsigned int ext4_group_t;
67
68
49/* prefer goal again. length */ 69/* prefer goal again. length */
50#define EXT4_MB_HINT_MERGE 1 70#define EXT4_MB_HINT_MERGE 1
51/* blocks already reserved */ 71/* blocks already reserved */
@@ -179,9 +199,6 @@ struct flex_groups {
179#define EXT4_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */ 199#define EXT4_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */
180#define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */ 200#define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */
181 201
182#ifdef __KERNEL__
183#include "ext4_sb.h"
184#endif
185/* 202/*
186 * Macro-instructions used to manage group descriptors 203 * Macro-instructions used to manage group descriptors
187 */ 204 */
@@ -297,10 +314,23 @@ struct ext4_new_group_data {
297}; 314};
298 315
299/* 316/*
300 * Following is used by preallocation code to tell get_blocks() that we 317 * Flags used by ext4_get_blocks()
301 * want uninitialzed extents.
302 */ 318 */
303#define EXT4_CREATE_UNINITIALIZED_EXT 2 319 /* Allocate any needed blocks and/or convert an unitialized
320 extent to be an initialized ext4 */
321#define EXT4_GET_BLOCKS_CREATE 0x0001
322 /* Request the creation of an unitialized extent */
323#define EXT4_GET_BLOCKS_UNINIT_EXT 0x0002
324#define EXT4_GET_BLOCKS_CREATE_UNINIT_EXT (EXT4_GET_BLOCKS_UNINIT_EXT|\
325 EXT4_GET_BLOCKS_CREATE)
326 /* Caller is from the delayed allocation writeout path,
327 so set the magic i_delalloc_reserve_flag after taking the
328 inode allocation semaphore for */
329#define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0004
330 /* Call ext4_da_update_reserve_space() after successfully
331 allocating the blocks */
332#define EXT4_GET_BLOCKS_UPDATE_RESERVE_SPACE 0x0008
333
304 334
305/* 335/*
306 * ioctl commands 336 * ioctl commands
@@ -516,6 +546,110 @@ do { \
516#endif /* defined(__KERNEL__) || defined(__linux__) */ 546#endif /* defined(__KERNEL__) || defined(__linux__) */
517 547
518/* 548/*
549 * storage for cached extent
550 */
551struct ext4_ext_cache {
552 ext4_fsblk_t ec_start;
553 ext4_lblk_t ec_block;
554 __u32 ec_len; /* must be 32bit to return holes */
555 __u32 ec_type;
556};
557
558/*
559 * fourth extended file system inode data in memory
560 */
561struct ext4_inode_info {
562 __le32 i_data[15]; /* unconverted */
563 __u32 i_flags;
564 ext4_fsblk_t i_file_acl;
565 __u32 i_dtime;
566
567 /*
568 * i_block_group is the number of the block group which contains
569 * this file's inode. Constant across the lifetime of the inode,
570 * it is ued for making block allocation decisions - we try to
571 * place a file's data blocks near its inode block, and new inodes
572 * near to their parent directory's inode.
573 */
574 ext4_group_t i_block_group;
575 __u32 i_state; /* Dynamic state flags for ext4 */
576
577 ext4_lblk_t i_dir_start_lookup;
578#ifdef CONFIG_EXT4_FS_XATTR
579 /*
580 * Extended attributes can be read independently of the main file
581 * data. Taking i_mutex even when reading would cause contention
582 * between readers of EAs and writers of regular file data, so
583 * instead we synchronize on xattr_sem when reading or changing
584 * EAs.
585 */
586 struct rw_semaphore xattr_sem;
587#endif
588#ifdef CONFIG_EXT4_FS_POSIX_ACL
589 struct posix_acl *i_acl;
590 struct posix_acl *i_default_acl;
591#endif
592
593 struct list_head i_orphan; /* unlinked but open inodes */
594
595 /*
596 * i_disksize keeps track of what the inode size is ON DISK, not
597 * in memory. During truncate, i_size is set to the new size by
598 * the VFS prior to calling ext4_truncate(), but the filesystem won't
599 * set i_disksize to 0 until the truncate is actually under way.
600 *
601 * The intent is that i_disksize always represents the blocks which
602 * are used by this file. This allows recovery to restart truncate
603 * on orphans if we crash during truncate. We actually write i_disksize
604 * into the on-disk inode when writing inodes out, instead of i_size.
605 *
606 * The only time when i_disksize and i_size may be different is when
607 * a truncate is in progress. The only things which change i_disksize
608 * are ext4_get_block (growth) and ext4_truncate (shrinkth).
609 */
610 loff_t i_disksize;
611
612 /*
613 * i_data_sem is for serialising ext4_truncate() against
614 * ext4_getblock(). In the 2.4 ext2 design, great chunks of inode's
615 * data tree are chopped off during truncate. We can't do that in
616 * ext4 because whenever we perform intermediate commits during
617 * truncate, the inode and all the metadata blocks *must* be in a
618 * consistent state which allows truncation of the orphans to restart
619 * during recovery. Hence we must fix the get_block-vs-truncate race
620 * by other means, so we have i_data_sem.
621 */
622 struct rw_semaphore i_data_sem;
623 struct inode vfs_inode;
624 struct jbd2_inode jinode;
625
626 struct ext4_ext_cache i_cached_extent;
627 /*
628 * File creation time. Its function is same as that of
629 * struct timespec i_{a,c,m}time in the generic inode.
630 */
631 struct timespec i_crtime;
632
633 /* mballoc */
634 struct list_head i_prealloc_list;
635 spinlock_t i_prealloc_lock;
636
637 /* ialloc */
638 ext4_group_t i_last_alloc_group;
639
640 /* allocation reservation info for delalloc */
641 unsigned int i_reserved_data_blocks;
642 unsigned int i_reserved_meta_blocks;
643 unsigned int i_allocated_meta_blocks;
644 unsigned short i_delalloc_reserved_flag;
645
646 /* on-disk additional length */
647 __u16 i_extra_isize;
648
649 spinlock_t i_block_reservation_lock;
650};
651
652/*
519 * File system states 653 * File system states
520 */ 654 */
521#define EXT4_VALID_FS 0x0001 /* Unmounted cleanly */ 655#define EXT4_VALID_FS 0x0001 /* Unmounted cleanly */
@@ -560,6 +694,7 @@ do { \
560#define EXT4_MOUNT_I_VERSION 0x2000000 /* i_version support */ 694#define EXT4_MOUNT_I_VERSION 0x2000000 /* i_version support */
561#define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */ 695#define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */
562#define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */ 696#define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */
697#define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000 /* Block validity checking */
563 698
564/* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */ 699/* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */
565#ifndef _LINUX_EXT2_FS_H 700#ifndef _LINUX_EXT2_FS_H
@@ -689,6 +824,137 @@ struct ext4_super_block {
689}; 824};
690 825
691#ifdef __KERNEL__ 826#ifdef __KERNEL__
827/*
828 * fourth extended-fs super-block data in memory
829 */
830struct ext4_sb_info {
831 unsigned long s_desc_size; /* Size of a group descriptor in bytes */
832 unsigned long s_inodes_per_block;/* Number of inodes per block */
833 unsigned long s_blocks_per_group;/* Number of blocks in a group */
834 unsigned long s_inodes_per_group;/* Number of inodes in a group */
835 unsigned long s_itb_per_group; /* Number of inode table blocks per group */
836 unsigned long s_gdb_count; /* Number of group descriptor blocks */
837 unsigned long s_desc_per_block; /* Number of group descriptors per block */
838 ext4_group_t s_groups_count; /* Number of groups in the fs */
839 unsigned long s_overhead_last; /* Last calculated overhead */
840 unsigned long s_blocks_last; /* Last seen block count */
841 loff_t s_bitmap_maxbytes; /* max bytes for bitmap files */
842 struct buffer_head * s_sbh; /* Buffer containing the super block */
843 struct ext4_super_block *s_es; /* Pointer to the super block in the buffer */
844 struct buffer_head **s_group_desc;
845 unsigned long s_mount_opt;
846 ext4_fsblk_t s_sb_block;
847 uid_t s_resuid;
848 gid_t s_resgid;
849 unsigned short s_mount_state;
850 unsigned short s_pad;
851 int s_addr_per_block_bits;
852 int s_desc_per_block_bits;
853 int s_inode_size;
854 int s_first_ino;
855 unsigned int s_inode_readahead_blks;
856 spinlock_t s_next_gen_lock;
857 u32 s_next_generation;
858 u32 s_hash_seed[4];
859 int s_def_hash_version;
860 int s_hash_unsigned; /* 3 if hash should be signed, 0 if not */
861 struct percpu_counter s_freeblocks_counter;
862 struct percpu_counter s_freeinodes_counter;
863 struct percpu_counter s_dirs_counter;
864 struct percpu_counter s_dirtyblocks_counter;
865 struct blockgroup_lock *s_blockgroup_lock;
866 struct proc_dir_entry *s_proc;
867 struct kobject s_kobj;
868 struct completion s_kobj_unregister;
869
870 /* Journaling */
871 struct inode *s_journal_inode;
872 struct journal_s *s_journal;
873 struct list_head s_orphan;
874 struct mutex s_orphan_lock;
875 struct mutex s_resize_lock;
876 unsigned long s_commit_interval;
877 u32 s_max_batch_time;
878 u32 s_min_batch_time;
879 struct block_device *journal_bdev;
880#ifdef CONFIG_JBD2_DEBUG
881 struct timer_list turn_ro_timer; /* For turning read-only (crash simulation) */
882 wait_queue_head_t ro_wait_queue; /* For people waiting for the fs to go read-only */
883#endif
884#ifdef CONFIG_QUOTA
885 char *s_qf_names[MAXQUOTAS]; /* Names of quota files with journalled quota */
886 int s_jquota_fmt; /* Format of quota to use */
887#endif
888 unsigned int s_want_extra_isize; /* New inodes should reserve # bytes */
889 struct rb_root system_blks;
890
891#ifdef EXTENTS_STATS
892 /* ext4 extents stats */
893 unsigned long s_ext_min;
894 unsigned long s_ext_max;
895 unsigned long s_depth_max;
896 spinlock_t s_ext_stats_lock;
897 unsigned long s_ext_blocks;
898 unsigned long s_ext_extents;
899#endif
900
901 /* for buddy allocator */
902 struct ext4_group_info ***s_group_info;
903 struct inode *s_buddy_cache;
904 long s_blocks_reserved;
905 spinlock_t s_reserve_lock;
906 spinlock_t s_md_lock;
907 tid_t s_last_transaction;
908 unsigned short *s_mb_offsets;
909 unsigned int *s_mb_maxs;
910
911 /* tunables */
912 unsigned long s_stripe;
913 unsigned int s_mb_stream_request;
914 unsigned int s_mb_max_to_scan;
915 unsigned int s_mb_min_to_scan;
916 unsigned int s_mb_stats;
917 unsigned int s_mb_order2_reqs;
918 unsigned int s_mb_group_prealloc;
919 /* where last allocation was done - for stream allocation */
920 unsigned long s_mb_last_group;
921 unsigned long s_mb_last_start;
922
923 /* history to debug policy */
924 struct ext4_mb_history *s_mb_history;
925 int s_mb_history_cur;
926 int s_mb_history_max;
927 int s_mb_history_num;
928 spinlock_t s_mb_history_lock;
929 int s_mb_history_filter;
930
931 /* stats for buddy allocator */
932 spinlock_t s_mb_pa_lock;
933 atomic_t s_bal_reqs; /* number of reqs with len > 1 */
934 atomic_t s_bal_success; /* we found long enough chunks */
935 atomic_t s_bal_allocated; /* in blocks */
936 atomic_t s_bal_ex_scanned; /* total extents scanned */
937 atomic_t s_bal_goals; /* goal hits */
938 atomic_t s_bal_breaks; /* too long searches */
939 atomic_t s_bal_2orders; /* 2^order hits */
940 spinlock_t s_bal_lock;
941 unsigned long s_mb_buddies_generated;
942 unsigned long long s_mb_generation_time;
943 atomic_t s_mb_lost_chunks;
944 atomic_t s_mb_preallocated;
945 atomic_t s_mb_discarded;
946
947 /* locality groups */
948 struct ext4_locality_group *s_locality_groups;
949
950 /* for write statistics */
951 unsigned long s_sectors_written_start;
952 u64 s_kbytes_written;
953
954 unsigned int s_log_groups_per_flex;
955 struct flex_groups *s_flex_groups;
956};
957
692static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb) 958static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
693{ 959{
694 return sb->s_fs_info; 960 return sb->s_fs_info;
@@ -704,7 +970,6 @@ static inline struct timespec ext4_current_time(struct inode *inode)
704 current_fs_time(inode->i_sb) : CURRENT_TIME_SEC; 970 current_fs_time(inode->i_sb) : CURRENT_TIME_SEC;
705} 971}
706 972
707
708static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino) 973static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
709{ 974{
710 return ino == EXT4_ROOT_INO || 975 return ino == EXT4_ROOT_INO ||
@@ -1014,6 +1279,14 @@ extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,
1014 ext4_group_t block_group, 1279 ext4_group_t block_group,
1015 struct buffer_head ** bh); 1280 struct buffer_head ** bh);
1016extern int ext4_should_retry_alloc(struct super_block *sb, int *retries); 1281extern int ext4_should_retry_alloc(struct super_block *sb, int *retries);
1282struct buffer_head *ext4_read_block_bitmap(struct super_block *sb,
1283 ext4_group_t block_group);
1284extern unsigned ext4_init_block_bitmap(struct super_block *sb,
1285 struct buffer_head *bh,
1286 ext4_group_t group,
1287 struct ext4_group_desc *desc);
1288#define ext4_free_blocks_after_init(sb, group, desc) \
1289 ext4_init_block_bitmap(sb, NULL, group, desc)
1017 1290
1018/* dir.c */ 1291/* dir.c */
1019extern int ext4_check_dir_entry(const char *, struct inode *, 1292extern int ext4_check_dir_entry(const char *, struct inode *,
@@ -1038,6 +1311,11 @@ extern struct inode * ext4_orphan_get(struct super_block *, unsigned long);
1038extern unsigned long ext4_count_free_inodes(struct super_block *); 1311extern unsigned long ext4_count_free_inodes(struct super_block *);
1039extern unsigned long ext4_count_dirs(struct super_block *); 1312extern unsigned long ext4_count_dirs(struct super_block *);
1040extern void ext4_check_inodes_bitmap(struct super_block *); 1313extern void ext4_check_inodes_bitmap(struct super_block *);
1314extern unsigned ext4_init_inode_bitmap(struct super_block *sb,
1315 struct buffer_head *bh,
1316 ext4_group_t group,
1317 struct ext4_group_desc *desc);
1318extern void mark_bitmap_end(int start_bit, int end_bit, char *bitmap);
1041 1319
1042/* mballoc.c */ 1320/* mballoc.c */
1043extern long ext4_mb_stats; 1321extern long ext4_mb_stats;
@@ -1123,6 +1401,8 @@ extern void ext4_abort(struct super_block *, const char *, const char *, ...)
1123 __attribute__ ((format (printf, 3, 4))); 1401 __attribute__ ((format (printf, 3, 4)));
1124extern void ext4_warning(struct super_block *, const char *, const char *, ...) 1402extern void ext4_warning(struct super_block *, const char *, const char *, ...)
1125 __attribute__ ((format (printf, 3, 4))); 1403 __attribute__ ((format (printf, 3, 4)));
1404extern void ext4_msg(struct super_block *, const char *, const char *, ...)
1405 __attribute__ ((format (printf, 3, 4)));
1126extern void ext4_grp_locked_error(struct super_block *, ext4_group_t, 1406extern void ext4_grp_locked_error(struct super_block *, ext4_group_t,
1127 const char *, const char *, ...) 1407 const char *, const char *, ...)
1128 __attribute__ ((format (printf, 4, 5))); 1408 __attribute__ ((format (printf, 4, 5)));
@@ -1161,6 +1441,10 @@ extern void ext4_used_dirs_set(struct super_block *sb,
1161 struct ext4_group_desc *bg, __u32 count); 1441 struct ext4_group_desc *bg, __u32 count);
1162extern void ext4_itable_unused_set(struct super_block *sb, 1442extern void ext4_itable_unused_set(struct super_block *sb,
1163 struct ext4_group_desc *bg, __u32 count); 1443 struct ext4_group_desc *bg, __u32 count);
1444extern __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 group,
1445 struct ext4_group_desc *gdp);
1446extern int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 group,
1447 struct ext4_group_desc *gdp);
1164 1448
1165static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es) 1449static inline ext4_fsblk_t ext4_blocks_count(struct ext4_super_block *es)
1166{ 1450{
@@ -1228,6 +1512,18 @@ struct ext4_group_info *ext4_get_group_info(struct super_block *sb,
1228 return grp_info[indexv][indexh]; 1512 return grp_info[indexv][indexh];
1229} 1513}
1230 1514
1515/*
1516 * Reading s_groups_count requires using smp_rmb() afterwards. See
1517 * the locking protocol documented in the comments of ext4_group_add()
1518 * in resize.c
1519 */
1520static inline ext4_group_t ext4_get_groups_count(struct super_block *sb)
1521{
1522 ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count;
1523
1524 smp_rmb();
1525 return ngroups;
1526}
1231 1527
1232static inline ext4_group_t ext4_flex_group(struct ext4_sb_info *sbi, 1528static inline ext4_group_t ext4_flex_group(struct ext4_sb_info *sbi,
1233 ext4_group_t block_group) 1529 ext4_group_t block_group)
@@ -1283,33 +1579,25 @@ struct ext4_group_info {
1283}; 1579};
1284 1580
1285#define EXT4_GROUP_INFO_NEED_INIT_BIT 0 1581#define EXT4_GROUP_INFO_NEED_INIT_BIT 0
1286#define EXT4_GROUP_INFO_LOCKED_BIT 1
1287 1582
1288#define EXT4_MB_GRP_NEED_INIT(grp) \ 1583#define EXT4_MB_GRP_NEED_INIT(grp) \
1289 (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state))) 1584 (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state)))
1290 1585
1291static inline void ext4_lock_group(struct super_block *sb, ext4_group_t group) 1586static inline spinlock_t *ext4_group_lock_ptr(struct super_block *sb,
1587 ext4_group_t group)
1292{ 1588{
1293 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group); 1589 return bgl_lock_ptr(EXT4_SB(sb)->s_blockgroup_lock, group);
1294
1295 bit_spin_lock(EXT4_GROUP_INFO_LOCKED_BIT, &(grinfo->bb_state));
1296} 1590}
1297 1591
1298static inline void ext4_unlock_group(struct super_block *sb, 1592static inline void ext4_lock_group(struct super_block *sb, ext4_group_t group)
1299 ext4_group_t group)
1300{ 1593{
1301 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group); 1594 spin_lock(ext4_group_lock_ptr(sb, group));
1302
1303 bit_spin_unlock(EXT4_GROUP_INFO_LOCKED_BIT, &(grinfo->bb_state));
1304} 1595}
1305 1596
1306static inline int ext4_is_group_locked(struct super_block *sb, 1597static inline void ext4_unlock_group(struct super_block *sb,
1307 ext4_group_t group) 1598 ext4_group_t group)
1308{ 1599{
1309 struct ext4_group_info *grinfo = ext4_get_group_info(sb, group); 1600 spin_unlock(ext4_group_lock_ptr(sb, group));
1310
1311 return bit_spin_is_locked(EXT4_GROUP_INFO_LOCKED_BIT,
1312 &(grinfo->bb_state));
1313} 1601}
1314 1602
1315/* 1603/*
@@ -1326,11 +1614,21 @@ extern const struct file_operations ext4_file_operations;
1326/* namei.c */ 1614/* namei.c */
1327extern const struct inode_operations ext4_dir_inode_operations; 1615extern const struct inode_operations ext4_dir_inode_operations;
1328extern const struct inode_operations ext4_special_inode_operations; 1616extern const struct inode_operations ext4_special_inode_operations;
1617extern struct dentry *ext4_get_parent(struct dentry *child);
1329 1618
1330/* symlink.c */ 1619/* symlink.c */
1331extern const struct inode_operations ext4_symlink_inode_operations; 1620extern const struct inode_operations ext4_symlink_inode_operations;
1332extern const struct inode_operations ext4_fast_symlink_inode_operations; 1621extern const struct inode_operations ext4_fast_symlink_inode_operations;
1333 1622
1623/* block_validity */
1624extern void ext4_release_system_zone(struct super_block *sb);
1625extern int ext4_setup_system_zone(struct super_block *sb);
1626extern int __init init_ext4_system_zone(void);
1627extern void exit_ext4_system_zone(void);
1628extern int ext4_data_block_valid(struct ext4_sb_info *sbi,
1629 ext4_fsblk_t start_blk,
1630 unsigned int count);
1631
1334/* extents.c */ 1632/* extents.c */
1335extern int ext4_ext_tree_init(handle_t *handle, struct inode *); 1633extern int ext4_ext_tree_init(handle_t *handle, struct inode *);
1336extern int ext4_ext_writepage_trans_blocks(struct inode *, int); 1634extern int ext4_ext_writepage_trans_blocks(struct inode *, int);
@@ -1338,17 +1636,15 @@ extern int ext4_ext_index_trans_blocks(struct inode *inode, int nrblocks,
1338 int chunk); 1636 int chunk);
1339extern int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, 1637extern int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
1340 ext4_lblk_t iblock, unsigned int max_blocks, 1638 ext4_lblk_t iblock, unsigned int max_blocks,
1341 struct buffer_head *bh_result, 1639 struct buffer_head *bh_result, int flags);
1342 int create, int extend_disksize);
1343extern void ext4_ext_truncate(struct inode *); 1640extern void ext4_ext_truncate(struct inode *);
1344extern void ext4_ext_init(struct super_block *); 1641extern void ext4_ext_init(struct super_block *);
1345extern void ext4_ext_release(struct super_block *); 1642extern void ext4_ext_release(struct super_block *);
1346extern long ext4_fallocate(struct inode *inode, int mode, loff_t offset, 1643extern long ext4_fallocate(struct inode *inode, int mode, loff_t offset,
1347 loff_t len); 1644 loff_t len);
1348extern int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, 1645extern int ext4_get_blocks(handle_t *handle, struct inode *inode,
1349 sector_t block, unsigned int max_blocks, 1646 sector_t block, unsigned int max_blocks,
1350 struct buffer_head *bh, int create, 1647 struct buffer_head *bh, int flags);
1351 int extend_disksize, int flag);
1352extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 1648extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
1353 __u64 start, __u64 len); 1649 __u64 start, __u64 len);
1354 1650
diff --git a/fs/ext4/ext4_i.h b/fs/ext4/ext4_i.h
deleted file mode 100644
index 4ce2187123aa..000000000000
--- a/fs/ext4/ext4_i.h
+++ /dev/null
@@ -1,140 +0,0 @@
1/*
2 * ext4_i.h
3 *
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
8 *
9 * from
10 *
11 * linux/include/linux/minix_fs_i.h
12 *
13 * Copyright (C) 1991, 1992 Linus Torvalds
14 */
15
16#ifndef _EXT4_I
17#define _EXT4_I
18
19#include <linux/rwsem.h>
20#include <linux/rbtree.h>
21#include <linux/seqlock.h>
22#include <linux/mutex.h>
23
24/* data type for block offset of block group */
25typedef int ext4_grpblk_t;
26
27/* data type for filesystem-wide blocks number */
28typedef unsigned long long ext4_fsblk_t;
29
30/* data type for file logical block number */
31typedef __u32 ext4_lblk_t;
32
33/* data type for block group number */
34typedef unsigned int ext4_group_t;
35
36/*
37 * storage for cached extent
38 */
39struct ext4_ext_cache {
40 ext4_fsblk_t ec_start;
41 ext4_lblk_t ec_block;
42 __u32 ec_len; /* must be 32bit to return holes */
43 __u32 ec_type;
44};
45
46/*
47 * fourth extended file system inode data in memory
48 */
49struct ext4_inode_info {
50 __le32 i_data[15]; /* unconverted */
51 __u32 i_flags;
52 ext4_fsblk_t i_file_acl;
53 __u32 i_dtime;
54
55 /*
56 * i_block_group is the number of the block group which contains
57 * this file's inode. Constant across the lifetime of the inode,
58 * it is ued for making block allocation decisions - we try to
59 * place a file's data blocks near its inode block, and new inodes
60 * near to their parent directory's inode.
61 */
62 ext4_group_t i_block_group;
63 __u32 i_state; /* Dynamic state flags for ext4 */
64
65 ext4_lblk_t i_dir_start_lookup;
66#ifdef CONFIG_EXT4_FS_XATTR
67 /*
68 * Extended attributes can be read independently of the main file
69 * data. Taking i_mutex even when reading would cause contention
70 * between readers of EAs and writers of regular file data, so
71 * instead we synchronize on xattr_sem when reading or changing
72 * EAs.
73 */
74 struct rw_semaphore xattr_sem;
75#endif
76#ifdef CONFIG_EXT4_FS_POSIX_ACL
77 struct posix_acl *i_acl;
78 struct posix_acl *i_default_acl;
79#endif
80
81 struct list_head i_orphan; /* unlinked but open inodes */
82
83 /*
84 * i_disksize keeps track of what the inode size is ON DISK, not
85 * in memory. During truncate, i_size is set to the new size by
86 * the VFS prior to calling ext4_truncate(), but the filesystem won't
87 * set i_disksize to 0 until the truncate is actually under way.
88 *
89 * The intent is that i_disksize always represents the blocks which
90 * are used by this file. This allows recovery to restart truncate
91 * on orphans if we crash during truncate. We actually write i_disksize
92 * into the on-disk inode when writing inodes out, instead of i_size.
93 *
94 * The only time when i_disksize and i_size may be different is when
95 * a truncate is in progress. The only things which change i_disksize
96 * are ext4_get_block (growth) and ext4_truncate (shrinkth).
97 */
98 loff_t i_disksize;
99
100 /*
101 * i_data_sem is for serialising ext4_truncate() against
102 * ext4_getblock(). In the 2.4 ext2 design, great chunks of inode's
103 * data tree are chopped off during truncate. We can't do that in
104 * ext4 because whenever we perform intermediate commits during
105 * truncate, the inode and all the metadata blocks *must* be in a
106 * consistent state which allows truncation of the orphans to restart
107 * during recovery. Hence we must fix the get_block-vs-truncate race
108 * by other means, so we have i_data_sem.
109 */
110 struct rw_semaphore i_data_sem;
111 struct inode vfs_inode;
112 struct jbd2_inode jinode;
113
114 struct ext4_ext_cache i_cached_extent;
115 /*
116 * File creation time. Its function is same as that of
117 * struct timespec i_{a,c,m}time in the generic inode.
118 */
119 struct timespec i_crtime;
120
121 /* mballoc */
122 struct list_head i_prealloc_list;
123 spinlock_t i_prealloc_lock;
124
125 /* ialloc */
126 ext4_group_t i_last_alloc_group;
127
128 /* allocation reservation info for delalloc */
129 unsigned int i_reserved_data_blocks;
130 unsigned int i_reserved_meta_blocks;
131 unsigned int i_allocated_meta_blocks;
132 unsigned short i_delalloc_reserved_flag;
133
134 /* on-disk additional length */
135 __u16 i_extra_isize;
136
137 spinlock_t i_block_reservation_lock;
138};
139
140#endif /* _EXT4_I */
diff --git a/fs/ext4/ext4_sb.h b/fs/ext4/ext4_sb.h
deleted file mode 100644
index 57b71fefbccf..000000000000
--- a/fs/ext4/ext4_sb.h
+++ /dev/null
@@ -1,161 +0,0 @@
1/*
2 * ext4_sb.h
3 *
4 * Copyright (C) 1992, 1993, 1994, 1995
5 * Remy Card (card@masi.ibp.fr)
6 * Laboratoire MASI - Institut Blaise Pascal
7 * Universite Pierre et Marie Curie (Paris VI)
8 *
9 * from
10 *
11 * linux/include/linux/minix_fs_sb.h
12 *
13 * Copyright (C) 1991, 1992 Linus Torvalds
14 */
15
16#ifndef _EXT4_SB
17#define _EXT4_SB
18
19#ifdef __KERNEL__
20#include <linux/timer.h>
21#include <linux/wait.h>
22#include <linux/blockgroup_lock.h>
23#include <linux/percpu_counter.h>
24#endif
25#include <linux/rbtree.h>
26
27/*
28 * fourth extended-fs super-block data in memory
29 */
30struct ext4_sb_info {
31 unsigned long s_desc_size; /* Size of a group descriptor in bytes */
32 unsigned long s_inodes_per_block;/* Number of inodes per block */
33 unsigned long s_blocks_per_group;/* Number of blocks in a group */
34 unsigned long s_inodes_per_group;/* Number of inodes in a group */
35 unsigned long s_itb_per_group; /* Number of inode table blocks per group */
36 unsigned long s_gdb_count; /* Number of group descriptor blocks */
37 unsigned long s_desc_per_block; /* Number of group descriptors per block */
38 ext4_group_t s_groups_count; /* Number of groups in the fs */
39 unsigned long s_overhead_last; /* Last calculated overhead */
40 unsigned long s_blocks_last; /* Last seen block count */
41 loff_t s_bitmap_maxbytes; /* max bytes for bitmap files */
42 struct buffer_head * s_sbh; /* Buffer containing the super block */
43 struct ext4_super_block *s_es; /* Pointer to the super block in the buffer */
44 struct buffer_head **s_group_desc;
45 unsigned long s_mount_opt;
46 ext4_fsblk_t s_sb_block;
47 uid_t s_resuid;
48 gid_t s_resgid;
49 unsigned short s_mount_state;
50 unsigned short s_pad;
51 int s_addr_per_block_bits;
52 int s_desc_per_block_bits;
53 int s_inode_size;
54 int s_first_ino;
55 unsigned int s_inode_readahead_blks;
56 spinlock_t s_next_gen_lock;
57 u32 s_next_generation;
58 u32 s_hash_seed[4];
59 int s_def_hash_version;
60 int s_hash_unsigned; /* 3 if hash should be signed, 0 if not */
61 struct percpu_counter s_freeblocks_counter;
62 struct percpu_counter s_freeinodes_counter;
63 struct percpu_counter s_dirs_counter;
64 struct percpu_counter s_dirtyblocks_counter;
65 struct blockgroup_lock *s_blockgroup_lock;
66 struct proc_dir_entry *s_proc;
67 struct kobject s_kobj;
68 struct completion s_kobj_unregister;
69
70 /* Journaling */
71 struct inode *s_journal_inode;
72 struct journal_s *s_journal;
73 struct list_head s_orphan;
74 unsigned long s_commit_interval;
75 u32 s_max_batch_time;
76 u32 s_min_batch_time;
77 struct block_device *journal_bdev;
78#ifdef CONFIG_JBD2_DEBUG
79 struct timer_list turn_ro_timer; /* For turning read-only (crash simulation) */
80 wait_queue_head_t ro_wait_queue; /* For people waiting for the fs to go read-only */
81#endif
82#ifdef CONFIG_QUOTA
83 char *s_qf_names[MAXQUOTAS]; /* Names of quota files with journalled quota */
84 int s_jquota_fmt; /* Format of quota to use */
85#endif
86 unsigned int s_want_extra_isize; /* New inodes should reserve # bytes */
87
88#ifdef EXTENTS_STATS
89 /* ext4 extents stats */
90 unsigned long s_ext_min;
91 unsigned long s_ext_max;
92 unsigned long s_depth_max;
93 spinlock_t s_ext_stats_lock;
94 unsigned long s_ext_blocks;
95 unsigned long s_ext_extents;
96#endif
97
98 /* for buddy allocator */
99 struct ext4_group_info ***s_group_info;
100 struct inode *s_buddy_cache;
101 long s_blocks_reserved;
102 spinlock_t s_reserve_lock;
103 spinlock_t s_md_lock;
104 tid_t s_last_transaction;
105 unsigned short *s_mb_offsets;
106 unsigned int *s_mb_maxs;
107
108 /* tunables */
109 unsigned long s_stripe;
110 unsigned int s_mb_stream_request;
111 unsigned int s_mb_max_to_scan;
112 unsigned int s_mb_min_to_scan;
113 unsigned int s_mb_stats;
114 unsigned int s_mb_order2_reqs;
115 unsigned int s_mb_group_prealloc;
116 /* where last allocation was done - for stream allocation */
117 unsigned long s_mb_last_group;
118 unsigned long s_mb_last_start;
119
120 /* history to debug policy */
121 struct ext4_mb_history *s_mb_history;
122 int s_mb_history_cur;
123 int s_mb_history_max;
124 int s_mb_history_num;
125 spinlock_t s_mb_history_lock;
126 int s_mb_history_filter;
127
128 /* stats for buddy allocator */
129 spinlock_t s_mb_pa_lock;
130 atomic_t s_bal_reqs; /* number of reqs with len > 1 */
131 atomic_t s_bal_success; /* we found long enough chunks */
132 atomic_t s_bal_allocated; /* in blocks */
133 atomic_t s_bal_ex_scanned; /* total extents scanned */
134 atomic_t s_bal_goals; /* goal hits */
135 atomic_t s_bal_breaks; /* too long searches */
136 atomic_t s_bal_2orders; /* 2^order hits */
137 spinlock_t s_bal_lock;
138 unsigned long s_mb_buddies_generated;
139 unsigned long long s_mb_generation_time;
140 atomic_t s_mb_lost_chunks;
141 atomic_t s_mb_preallocated;
142 atomic_t s_mb_discarded;
143
144 /* locality groups */
145 struct ext4_locality_group *s_locality_groups;
146
147 /* for write statistics */
148 unsigned long s_sectors_written_start;
149 u64 s_kbytes_written;
150
151 unsigned int s_log_groups_per_flex;
152 struct flex_groups *s_flex_groups;
153};
154
155static inline spinlock_t *
156sb_bgl_lock(struct ext4_sb_info *sbi, unsigned int block_group)
157{
158 return bgl_lock_ptr(sbi->s_blockgroup_lock, block_group);
159}
160
161#endif /* _EXT4_SB */
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index e3a55eb8b26a..2593f748c3a4 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -326,32 +326,18 @@ ext4_ext_max_entries(struct inode *inode, int depth)
326 326
327static int ext4_valid_extent(struct inode *inode, struct ext4_extent *ext) 327static int ext4_valid_extent(struct inode *inode, struct ext4_extent *ext)
328{ 328{
329 ext4_fsblk_t block = ext_pblock(ext), valid_block; 329 ext4_fsblk_t block = ext_pblock(ext);
330 int len = ext4_ext_get_actual_len(ext); 330 int len = ext4_ext_get_actual_len(ext);
331 struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es;
332 331
333 valid_block = le32_to_cpu(es->s_first_data_block) + 332 return ext4_data_block_valid(EXT4_SB(inode->i_sb), block, len);
334 EXT4_SB(inode->i_sb)->s_gdb_count;
335 if (unlikely(block <= valid_block ||
336 ((block + len) > ext4_blocks_count(es))))
337 return 0;
338 else
339 return 1;
340} 333}
341 334
342static int ext4_valid_extent_idx(struct inode *inode, 335static int ext4_valid_extent_idx(struct inode *inode,
343 struct ext4_extent_idx *ext_idx) 336 struct ext4_extent_idx *ext_idx)
344{ 337{
345 ext4_fsblk_t block = idx_pblock(ext_idx), valid_block; 338 ext4_fsblk_t block = idx_pblock(ext_idx);
346 struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es;
347 339
348 valid_block = le32_to_cpu(es->s_first_data_block) + 340 return ext4_data_block_valid(EXT4_SB(inode->i_sb), block, 1);
349 EXT4_SB(inode->i_sb)->s_gdb_count;
350 if (unlikely(block <= valid_block ||
351 (block >= ext4_blocks_count(es))))
352 return 0;
353 else
354 return 1;
355} 341}
356 342
357static int ext4_valid_extent_entries(struct inode *inode, 343static int ext4_valid_extent_entries(struct inode *inode,
@@ -2097,12 +2083,16 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
2097 ex = EXT_LAST_EXTENT(eh); 2083 ex = EXT_LAST_EXTENT(eh);
2098 2084
2099 ex_ee_block = le32_to_cpu(ex->ee_block); 2085 ex_ee_block = le32_to_cpu(ex->ee_block);
2100 if (ext4_ext_is_uninitialized(ex))
2101 uninitialized = 1;
2102 ex_ee_len = ext4_ext_get_actual_len(ex); 2086 ex_ee_len = ext4_ext_get_actual_len(ex);
2103 2087
2104 while (ex >= EXT_FIRST_EXTENT(eh) && 2088 while (ex >= EXT_FIRST_EXTENT(eh) &&
2105 ex_ee_block + ex_ee_len > start) { 2089 ex_ee_block + ex_ee_len > start) {
2090
2091 if (ext4_ext_is_uninitialized(ex))
2092 uninitialized = 1;
2093 else
2094 uninitialized = 0;
2095
2106 ext_debug("remove ext %lu:%u\n", ex_ee_block, ex_ee_len); 2096 ext_debug("remove ext %lu:%u\n", ex_ee_block, ex_ee_len);
2107 path[depth].p_ext = ex; 2097 path[depth].p_ext = ex;
2108 2098
@@ -2784,7 +2774,7 @@ fix_extent_len:
2784int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, 2774int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
2785 ext4_lblk_t iblock, 2775 ext4_lblk_t iblock,
2786 unsigned int max_blocks, struct buffer_head *bh_result, 2776 unsigned int max_blocks, struct buffer_head *bh_result,
2787 int create, int extend_disksize) 2777 int flags)
2788{ 2778{
2789 struct ext4_ext_path *path = NULL; 2779 struct ext4_ext_path *path = NULL;
2790 struct ext4_extent_header *eh; 2780 struct ext4_extent_header *eh;
@@ -2793,7 +2783,6 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
2793 int err = 0, depth, ret, cache_type; 2783 int err = 0, depth, ret, cache_type;
2794 unsigned int allocated = 0; 2784 unsigned int allocated = 0;
2795 struct ext4_allocation_request ar; 2785 struct ext4_allocation_request ar;
2796 loff_t disksize;
2797 2786
2798 __clear_bit(BH_New, &bh_result->b_state); 2787 __clear_bit(BH_New, &bh_result->b_state);
2799 ext_debug("blocks %u/%u requested for inode %u\n", 2788 ext_debug("blocks %u/%u requested for inode %u\n",
@@ -2803,7 +2792,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
2803 cache_type = ext4_ext_in_cache(inode, iblock, &newex); 2792 cache_type = ext4_ext_in_cache(inode, iblock, &newex);
2804 if (cache_type) { 2793 if (cache_type) {
2805 if (cache_type == EXT4_EXT_CACHE_GAP) { 2794 if (cache_type == EXT4_EXT_CACHE_GAP) {
2806 if (!create) { 2795 if ((flags & EXT4_GET_BLOCKS_CREATE) == 0) {
2807 /* 2796 /*
2808 * block isn't allocated yet and 2797 * block isn't allocated yet and
2809 * user doesn't want to allocate it 2798 * user doesn't want to allocate it
@@ -2869,9 +2858,11 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
2869 EXT4_EXT_CACHE_EXTENT); 2858 EXT4_EXT_CACHE_EXTENT);
2870 goto out; 2859 goto out;
2871 } 2860 }
2872 if (create == EXT4_CREATE_UNINITIALIZED_EXT) 2861 if (flags & EXT4_GET_BLOCKS_UNINIT_EXT)
2873 goto out; 2862 goto out;
2874 if (!create) { 2863 if ((flags & EXT4_GET_BLOCKS_CREATE) == 0) {
2864 if (allocated > max_blocks)
2865 allocated = max_blocks;
2875 /* 2866 /*
2876 * We have blocks reserved already. We 2867 * We have blocks reserved already. We
2877 * return allocated blocks so that delalloc 2868 * return allocated blocks so that delalloc
@@ -2879,8 +2870,6 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
2879 * the buffer head will be unmapped so that 2870 * the buffer head will be unmapped so that
2880 * a read from the block returns 0s. 2871 * a read from the block returns 0s.
2881 */ 2872 */
2882 if (allocated > max_blocks)
2883 allocated = max_blocks;
2884 set_buffer_unwritten(bh_result); 2873 set_buffer_unwritten(bh_result);
2885 bh_result->b_bdev = inode->i_sb->s_bdev; 2874 bh_result->b_bdev = inode->i_sb->s_bdev;
2886 bh_result->b_blocknr = newblock; 2875 bh_result->b_blocknr = newblock;
@@ -2903,7 +2892,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
2903 * requested block isn't allocated yet; 2892 * requested block isn't allocated yet;
2904 * we couldn't try to create block if create flag is zero 2893 * we couldn't try to create block if create flag is zero
2905 */ 2894 */
2906 if (!create) { 2895 if ((flags & EXT4_GET_BLOCKS_CREATE) == 0) {
2907 /* 2896 /*
2908 * put just found gap into cache to speed up 2897 * put just found gap into cache to speed up
2909 * subsequent requests 2898 * subsequent requests
@@ -2932,10 +2921,10 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
2932 * EXT_UNINIT_MAX_LEN. 2921 * EXT_UNINIT_MAX_LEN.
2933 */ 2922 */
2934 if (max_blocks > EXT_INIT_MAX_LEN && 2923 if (max_blocks > EXT_INIT_MAX_LEN &&
2935 create != EXT4_CREATE_UNINITIALIZED_EXT) 2924 !(flags & EXT4_GET_BLOCKS_UNINIT_EXT))
2936 max_blocks = EXT_INIT_MAX_LEN; 2925 max_blocks = EXT_INIT_MAX_LEN;
2937 else if (max_blocks > EXT_UNINIT_MAX_LEN && 2926 else if (max_blocks > EXT_UNINIT_MAX_LEN &&
2938 create == EXT4_CREATE_UNINITIALIZED_EXT) 2927 (flags & EXT4_GET_BLOCKS_UNINIT_EXT))
2939 max_blocks = EXT_UNINIT_MAX_LEN; 2928 max_blocks = EXT_UNINIT_MAX_LEN;
2940 2929
2941 /* Check if we can really insert (iblock)::(iblock+max_blocks) extent */ 2930 /* Check if we can really insert (iblock)::(iblock+max_blocks) extent */
@@ -2966,7 +2955,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
2966 /* try to insert new extent into found leaf and return */ 2955 /* try to insert new extent into found leaf and return */
2967 ext4_ext_store_pblock(&newex, newblock); 2956 ext4_ext_store_pblock(&newex, newblock);
2968 newex.ee_len = cpu_to_le16(ar.len); 2957 newex.ee_len = cpu_to_le16(ar.len);
2969 if (create == EXT4_CREATE_UNINITIALIZED_EXT) /* Mark uninitialized */ 2958 if (flags & EXT4_GET_BLOCKS_UNINIT_EXT) /* Mark uninitialized */
2970 ext4_ext_mark_uninitialized(&newex); 2959 ext4_ext_mark_uninitialized(&newex);
2971 err = ext4_ext_insert_extent(handle, inode, path, &newex); 2960 err = ext4_ext_insert_extent(handle, inode, path, &newex);
2972 if (err) { 2961 if (err) {
@@ -2983,18 +2972,10 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
2983 newblock = ext_pblock(&newex); 2972 newblock = ext_pblock(&newex);
2984 allocated = ext4_ext_get_actual_len(&newex); 2973 allocated = ext4_ext_get_actual_len(&newex);
2985outnew: 2974outnew:
2986 if (extend_disksize) {
2987 disksize = ((loff_t) iblock + ar.len) << inode->i_blkbits;
2988 if (disksize > i_size_read(inode))
2989 disksize = i_size_read(inode);
2990 if (disksize > EXT4_I(inode)->i_disksize)
2991 EXT4_I(inode)->i_disksize = disksize;
2992 }
2993
2994 set_buffer_new(bh_result); 2975 set_buffer_new(bh_result);
2995 2976
2996 /* Cache only when it is _not_ an uninitialized extent */ 2977 /* Cache only when it is _not_ an uninitialized extent */
2997 if (create != EXT4_CREATE_UNINITIALIZED_EXT) 2978 if ((flags & EXT4_GET_BLOCKS_UNINIT_EXT) == 0)
2998 ext4_ext_put_in_cache(inode, iblock, allocated, newblock, 2979 ext4_ext_put_in_cache(inode, iblock, allocated, newblock,
2999 EXT4_EXT_CACHE_EXTENT); 2980 EXT4_EXT_CACHE_EXTENT);
3000out: 2981out:
@@ -3150,9 +3131,10 @@ retry:
3150 ret = PTR_ERR(handle); 3131 ret = PTR_ERR(handle);
3151 break; 3132 break;
3152 } 3133 }
3153 ret = ext4_get_blocks_wrap(handle, inode, block, 3134 map_bh.b_state = 0;
3154 max_blocks, &map_bh, 3135 ret = ext4_get_blocks(handle, inode, block,
3155 EXT4_CREATE_UNINITIALIZED_EXT, 0, 0); 3136 max_blocks, &map_bh,
3137 EXT4_GET_BLOCKS_CREATE_UNINIT_EXT);
3156 if (ret <= 0) { 3138 if (ret <= 0) {
3157#ifdef EXT4FS_DEBUG 3139#ifdef EXT4FS_DEBUG
3158 WARN_ON(ret <= 0); 3140 WARN_ON(ret <= 0);
@@ -3195,7 +3177,7 @@ static int ext4_ext_fiemap_cb(struct inode *inode, struct ext4_ext_path *path,
3195 void *data) 3177 void *data)
3196{ 3178{
3197 struct fiemap_extent_info *fieinfo = data; 3179 struct fiemap_extent_info *fieinfo = data;
3198 unsigned long blksize_bits = inode->i_sb->s_blocksize_bits; 3180 unsigned char blksize_bits = inode->i_sb->s_blocksize_bits;
3199 __u64 logical; 3181 __u64 logical;
3200 __u64 physical; 3182 __u64 physical;
3201 __u64 length; 3183 __u64 length;
@@ -3242,9 +3224,16 @@ static int ext4_ext_fiemap_cb(struct inode *inode, struct ext4_ext_path *path,
3242 * 3224 *
3243 * XXX this might miss a single-block extent at EXT_MAX_BLOCK 3225 * XXX this might miss a single-block extent at EXT_MAX_BLOCK
3244 */ 3226 */
3245 if (logical + length - 1 == EXT_MAX_BLOCK || 3227 if (ext4_ext_next_allocated_block(path) == EXT_MAX_BLOCK ||
3246 ext4_ext_next_allocated_block(path) == EXT_MAX_BLOCK) 3228 newex->ec_block + newex->ec_len - 1 == EXT_MAX_BLOCK) {
3229 loff_t size = i_size_read(inode);
3230 loff_t bs = EXT4_BLOCK_SIZE(inode->i_sb);
3231
3247 flags |= FIEMAP_EXTENT_LAST; 3232 flags |= FIEMAP_EXTENT_LAST;
3233 if ((flags & FIEMAP_EXTENT_DELALLOC) &&
3234 logical+length > size)
3235 length = (size - logical + bs - 1) & ~(bs-1);
3236 }
3248 3237
3249 error = fiemap_fill_next_extent(fieinfo, logical, physical, 3238 error = fiemap_fill_next_extent(fieinfo, logical, physical,
3250 length, flags); 3239 length, flags);
@@ -3318,10 +3307,10 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
3318 * Walk the extent tree gathering extent information. 3307 * Walk the extent tree gathering extent information.
3319 * ext4_ext_fiemap_cb will push extents back to user. 3308 * ext4_ext_fiemap_cb will push extents back to user.
3320 */ 3309 */
3321 down_write(&EXT4_I(inode)->i_data_sem); 3310 down_read(&EXT4_I(inode)->i_data_sem);
3322 error = ext4_ext_walk_space(inode, start_blk, len_blks, 3311 error = ext4_ext_walk_space(inode, start_blk, len_blks,
3323 ext4_ext_fiemap_cb, fieinfo); 3312 ext4_ext_fiemap_cb, fieinfo);
3324 up_write(&EXT4_I(inode)->i_data_sem); 3313 up_read(&EXT4_I(inode)->i_data_sem);
3325 } 3314 }
3326 3315
3327 return error; 3316 return error;
diff --git a/fs/ext4/group.h b/fs/ext4/group.h
deleted file mode 100644
index c2c0a8d06d0e..000000000000
--- a/fs/ext4/group.h
+++ /dev/null
@@ -1,29 +0,0 @@
1/*
2 * linux/fs/ext4/group.h
3 *
4 * Copyright (C) 2007 Cluster File Systems, Inc
5 *
6 * Author: Andreas Dilger <adilger@clusterfs.com>
7 */
8
9#ifndef _LINUX_EXT4_GROUP_H
10#define _LINUX_EXT4_GROUP_H
11
12extern __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 group,
13 struct ext4_group_desc *gdp);
14extern int ext4_group_desc_csum_verify(struct ext4_sb_info *sbi, __u32 group,
15 struct ext4_group_desc *gdp);
16struct buffer_head *ext4_read_block_bitmap(struct super_block *sb,
17 ext4_group_t block_group);
18extern unsigned ext4_init_block_bitmap(struct super_block *sb,
19 struct buffer_head *bh,
20 ext4_group_t group,
21 struct ext4_group_desc *desc);
22#define ext4_free_blocks_after_init(sb, group, desc) \
23 ext4_init_block_bitmap(sb, NULL, group, desc)
24extern unsigned ext4_init_inode_bitmap(struct super_block *sb,
25 struct buffer_head *bh,
26 ext4_group_t group,
27 struct ext4_group_desc *desc);
28extern void mark_bitmap_end(int start_bit, int end_bit, char *bitmap);
29#endif /* _LINUX_EXT4_GROUP_H */
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index f18e0a08a6b5..3743bd849bce 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -27,7 +27,6 @@
27#include "ext4_jbd2.h" 27#include "ext4_jbd2.h"
28#include "xattr.h" 28#include "xattr.h"
29#include "acl.h" 29#include "acl.h"
30#include "group.h"
31 30
32/* 31/*
33 * ialloc.c contains the inodes allocation and deallocation routines 32 * ialloc.c contains the inodes allocation and deallocation routines
@@ -123,16 +122,16 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)
123 unlock_buffer(bh); 122 unlock_buffer(bh);
124 return bh; 123 return bh;
125 } 124 }
126 spin_lock(sb_bgl_lock(EXT4_SB(sb), block_group)); 125 ext4_lock_group(sb, block_group);
127 if (desc->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) { 126 if (desc->bg_flags & cpu_to_le16(EXT4_BG_INODE_UNINIT)) {
128 ext4_init_inode_bitmap(sb, bh, block_group, desc); 127 ext4_init_inode_bitmap(sb, bh, block_group, desc);
129 set_bitmap_uptodate(bh); 128 set_bitmap_uptodate(bh);
130 set_buffer_uptodate(bh); 129 set_buffer_uptodate(bh);
131 spin_unlock(sb_bgl_lock(EXT4_SB(sb), block_group)); 130 ext4_unlock_group(sb, block_group);
132 unlock_buffer(bh); 131 unlock_buffer(bh);
133 return bh; 132 return bh;
134 } 133 }
135 spin_unlock(sb_bgl_lock(EXT4_SB(sb), block_group)); 134 ext4_unlock_group(sb, block_group);
136 if (buffer_uptodate(bh)) { 135 if (buffer_uptodate(bh)) {
137 /* 136 /*
138 * if not uninit if bh is uptodate, 137 * if not uninit if bh is uptodate,
@@ -247,9 +246,8 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)
247 goto error_return; 246 goto error_return;
248 247
249 /* Ok, now we can actually update the inode bitmaps.. */ 248 /* Ok, now we can actually update the inode bitmaps.. */
250 spin_lock(sb_bgl_lock(sbi, block_group)); 249 cleared = ext4_clear_bit_atomic(ext4_group_lock_ptr(sb, block_group),
251 cleared = ext4_clear_bit(bit, bitmap_bh->b_data); 250 bit, bitmap_bh->b_data);
252 spin_unlock(sb_bgl_lock(sbi, block_group));
253 if (!cleared) 251 if (!cleared)
254 ext4_error(sb, "ext4_free_inode", 252 ext4_error(sb, "ext4_free_inode",
255 "bit already cleared for inode %lu", ino); 253 "bit already cleared for inode %lu", ino);
@@ -261,7 +259,7 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)
261 if (fatal) goto error_return; 259 if (fatal) goto error_return;
262 260
263 if (gdp) { 261 if (gdp) {
264 spin_lock(sb_bgl_lock(sbi, block_group)); 262 ext4_lock_group(sb, block_group);
265 count = ext4_free_inodes_count(sb, gdp) + 1; 263 count = ext4_free_inodes_count(sb, gdp) + 1;
266 ext4_free_inodes_set(sb, gdp, count); 264 ext4_free_inodes_set(sb, gdp, count);
267 if (is_directory) { 265 if (is_directory) {
@@ -277,7 +275,7 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)
277 } 275 }
278 gdp->bg_checksum = ext4_group_desc_csum(sbi, 276 gdp->bg_checksum = ext4_group_desc_csum(sbi,
279 block_group, gdp); 277 block_group, gdp);
280 spin_unlock(sb_bgl_lock(sbi, block_group)); 278 ext4_unlock_group(sb, block_group);
281 percpu_counter_inc(&sbi->s_freeinodes_counter); 279 percpu_counter_inc(&sbi->s_freeinodes_counter);
282 if (is_directory) 280 if (is_directory)
283 percpu_counter_dec(&sbi->s_dirs_counter); 281 percpu_counter_dec(&sbi->s_dirs_counter);
@@ -316,7 +314,7 @@ error_return:
316static int find_group_dir(struct super_block *sb, struct inode *parent, 314static int find_group_dir(struct super_block *sb, struct inode *parent,
317 ext4_group_t *best_group) 315 ext4_group_t *best_group)
318{ 316{
319 ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count; 317 ext4_group_t ngroups = ext4_get_groups_count(sb);
320 unsigned int freei, avefreei; 318 unsigned int freei, avefreei;
321 struct ext4_group_desc *desc, *best_desc = NULL; 319 struct ext4_group_desc *desc, *best_desc = NULL;
322 ext4_group_t group; 320 ext4_group_t group;
@@ -349,11 +347,10 @@ static int find_group_flex(struct super_block *sb, struct inode *parent,
349{ 347{
350 struct ext4_sb_info *sbi = EXT4_SB(sb); 348 struct ext4_sb_info *sbi = EXT4_SB(sb);
351 struct ext4_group_desc *desc; 349 struct ext4_group_desc *desc;
352 struct buffer_head *bh;
353 struct flex_groups *flex_group = sbi->s_flex_groups; 350 struct flex_groups *flex_group = sbi->s_flex_groups;
354 ext4_group_t parent_group = EXT4_I(parent)->i_block_group; 351 ext4_group_t parent_group = EXT4_I(parent)->i_block_group;
355 ext4_group_t parent_fbg_group = ext4_flex_group(sbi, parent_group); 352 ext4_group_t parent_fbg_group = ext4_flex_group(sbi, parent_group);
356 ext4_group_t ngroups = sbi->s_groups_count; 353 ext4_group_t ngroups = ext4_get_groups_count(sb);
357 int flex_size = ext4_flex_bg_size(sbi); 354 int flex_size = ext4_flex_bg_size(sbi);
358 ext4_group_t best_flex = parent_fbg_group; 355 ext4_group_t best_flex = parent_fbg_group;
359 int blocks_per_flex = sbi->s_blocks_per_group * flex_size; 356 int blocks_per_flex = sbi->s_blocks_per_group * flex_size;
@@ -362,7 +359,7 @@ static int find_group_flex(struct super_block *sb, struct inode *parent,
362 ext4_group_t n_fbg_groups; 359 ext4_group_t n_fbg_groups;
363 ext4_group_t i; 360 ext4_group_t i;
364 361
365 n_fbg_groups = (sbi->s_groups_count + flex_size - 1) >> 362 n_fbg_groups = (ngroups + flex_size - 1) >>
366 sbi->s_log_groups_per_flex; 363 sbi->s_log_groups_per_flex;
367 364
368find_close_to_parent: 365find_close_to_parent:
@@ -404,7 +401,7 @@ find_close_to_parent:
404found_flexbg: 401found_flexbg:
405 for (i = best_flex * flex_size; i < ngroups && 402 for (i = best_flex * flex_size; i < ngroups &&
406 i < (best_flex + 1) * flex_size; i++) { 403 i < (best_flex + 1) * flex_size; i++) {
407 desc = ext4_get_group_desc(sb, i, &bh); 404 desc = ext4_get_group_desc(sb, i, NULL);
408 if (ext4_free_inodes_count(sb, desc)) { 405 if (ext4_free_inodes_count(sb, desc)) {
409 *best_group = i; 406 *best_group = i;
410 goto out; 407 goto out;
@@ -478,20 +475,21 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
478{ 475{
479 ext4_group_t parent_group = EXT4_I(parent)->i_block_group; 476 ext4_group_t parent_group = EXT4_I(parent)->i_block_group;
480 struct ext4_sb_info *sbi = EXT4_SB(sb); 477 struct ext4_sb_info *sbi = EXT4_SB(sb);
481 ext4_group_t ngroups = sbi->s_groups_count; 478 ext4_group_t real_ngroups = ext4_get_groups_count(sb);
482 int inodes_per_group = EXT4_INODES_PER_GROUP(sb); 479 int inodes_per_group = EXT4_INODES_PER_GROUP(sb);
483 unsigned int freei, avefreei; 480 unsigned int freei, avefreei;
484 ext4_fsblk_t freeb, avefreeb; 481 ext4_fsblk_t freeb, avefreeb;
485 unsigned int ndirs; 482 unsigned int ndirs;
486 int max_dirs, min_inodes; 483 int max_dirs, min_inodes;
487 ext4_grpblk_t min_blocks; 484 ext4_grpblk_t min_blocks;
488 ext4_group_t i, grp, g; 485 ext4_group_t i, grp, g, ngroups;
489 struct ext4_group_desc *desc; 486 struct ext4_group_desc *desc;
490 struct orlov_stats stats; 487 struct orlov_stats stats;
491 int flex_size = ext4_flex_bg_size(sbi); 488 int flex_size = ext4_flex_bg_size(sbi);
492 489
490 ngroups = real_ngroups;
493 if (flex_size > 1) { 491 if (flex_size > 1) {
494 ngroups = (ngroups + flex_size - 1) >> 492 ngroups = (real_ngroups + flex_size - 1) >>
495 sbi->s_log_groups_per_flex; 493 sbi->s_log_groups_per_flex;
496 parent_group >>= sbi->s_log_groups_per_flex; 494 parent_group >>= sbi->s_log_groups_per_flex;
497 } 495 }
@@ -543,7 +541,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
543 */ 541 */
544 grp *= flex_size; 542 grp *= flex_size;
545 for (i = 0; i < flex_size; i++) { 543 for (i = 0; i < flex_size; i++) {
546 if (grp+i >= sbi->s_groups_count) 544 if (grp+i >= real_ngroups)
547 break; 545 break;
548 desc = ext4_get_group_desc(sb, grp+i, NULL); 546 desc = ext4_get_group_desc(sb, grp+i, NULL);
549 if (desc && ext4_free_inodes_count(sb, desc)) { 547 if (desc && ext4_free_inodes_count(sb, desc)) {
@@ -583,7 +581,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
583 } 581 }
584 582
585fallback: 583fallback:
586 ngroups = sbi->s_groups_count; 584 ngroups = real_ngroups;
587 avefreei = freei / ngroups; 585 avefreei = freei / ngroups;
588fallback_retry: 586fallback_retry:
589 parent_group = EXT4_I(parent)->i_block_group; 587 parent_group = EXT4_I(parent)->i_block_group;
@@ -613,9 +611,8 @@ static int find_group_other(struct super_block *sb, struct inode *parent,
613 ext4_group_t *group, int mode) 611 ext4_group_t *group, int mode)
614{ 612{
615 ext4_group_t parent_group = EXT4_I(parent)->i_block_group; 613 ext4_group_t parent_group = EXT4_I(parent)->i_block_group;
616 ext4_group_t ngroups = EXT4_SB(sb)->s_groups_count; 614 ext4_group_t i, last, ngroups = ext4_get_groups_count(sb);
617 struct ext4_group_desc *desc; 615 struct ext4_group_desc *desc;
618 ext4_group_t i, last;
619 int flex_size = ext4_flex_bg_size(EXT4_SB(sb)); 616 int flex_size = ext4_flex_bg_size(EXT4_SB(sb));
620 617
621 /* 618 /*
@@ -708,10 +705,10 @@ static int find_group_other(struct super_block *sb, struct inode *parent,
708 705
709/* 706/*
710 * claim the inode from the inode bitmap. If the group 707 * claim the inode from the inode bitmap. If the group
711 * is uninit we need to take the groups's sb_bgl_lock 708 * is uninit we need to take the groups's ext4_group_lock
712 * and clear the uninit flag. The inode bitmap update 709 * and clear the uninit flag. The inode bitmap update
713 * and group desc uninit flag clear should be done 710 * and group desc uninit flag clear should be done
714 * after holding sb_bgl_lock so that ext4_read_inode_bitmap 711 * after holding ext4_group_lock so that ext4_read_inode_bitmap
715 * doesn't race with the ext4_claim_inode 712 * doesn't race with the ext4_claim_inode
716 */ 713 */
717static int ext4_claim_inode(struct super_block *sb, 714static int ext4_claim_inode(struct super_block *sb,
@@ -722,7 +719,7 @@ static int ext4_claim_inode(struct super_block *sb,
722 struct ext4_sb_info *sbi = EXT4_SB(sb); 719 struct ext4_sb_info *sbi = EXT4_SB(sb);
723 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, group, NULL); 720 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, group, NULL);
724 721
725 spin_lock(sb_bgl_lock(sbi, group)); 722 ext4_lock_group(sb, group);
726 if (ext4_set_bit(ino, inode_bitmap_bh->b_data)) { 723 if (ext4_set_bit(ino, inode_bitmap_bh->b_data)) {
727 /* not a free inode */ 724 /* not a free inode */
728 retval = 1; 725 retval = 1;
@@ -731,7 +728,7 @@ static int ext4_claim_inode(struct super_block *sb,
731 ino++; 728 ino++;
732 if ((group == 0 && ino < EXT4_FIRST_INO(sb)) || 729 if ((group == 0 && ino < EXT4_FIRST_INO(sb)) ||
733 ino > EXT4_INODES_PER_GROUP(sb)) { 730 ino > EXT4_INODES_PER_GROUP(sb)) {
734 spin_unlock(sb_bgl_lock(sbi, group)); 731 ext4_unlock_group(sb, group);
735 ext4_error(sb, __func__, 732 ext4_error(sb, __func__,
736 "reserved inode or inode > inodes count - " 733 "reserved inode or inode > inodes count - "
737 "block_group = %u, inode=%lu", group, 734 "block_group = %u, inode=%lu", group,
@@ -780,7 +777,7 @@ static int ext4_claim_inode(struct super_block *sb,
780 } 777 }
781 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp); 778 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, gdp);
782err_ret: 779err_ret:
783 spin_unlock(sb_bgl_lock(sbi, group)); 780 ext4_unlock_group(sb, group);
784 return retval; 781 return retval;
785} 782}
786 783
@@ -799,11 +796,10 @@ struct inode *ext4_new_inode(handle_t *handle, struct inode *dir, int mode)
799 struct super_block *sb; 796 struct super_block *sb;
800 struct buffer_head *inode_bitmap_bh = NULL; 797 struct buffer_head *inode_bitmap_bh = NULL;
801 struct buffer_head *group_desc_bh; 798 struct buffer_head *group_desc_bh;
802 ext4_group_t group = 0; 799 ext4_group_t ngroups, group = 0;
803 unsigned long ino = 0; 800 unsigned long ino = 0;
804 struct inode *inode; 801 struct inode *inode;
805 struct ext4_group_desc *gdp = NULL; 802 struct ext4_group_desc *gdp = NULL;
806 struct ext4_super_block *es;
807 struct ext4_inode_info *ei; 803 struct ext4_inode_info *ei;
808 struct ext4_sb_info *sbi; 804 struct ext4_sb_info *sbi;
809 int ret2, err = 0; 805 int ret2, err = 0;
@@ -818,15 +814,14 @@ struct inode *ext4_new_inode(handle_t *handle, struct inode *dir, int mode)
818 return ERR_PTR(-EPERM); 814 return ERR_PTR(-EPERM);
819 815
820 sb = dir->i_sb; 816 sb = dir->i_sb;
817 ngroups = ext4_get_groups_count(sb);
821 trace_mark(ext4_request_inode, "dev %s dir %lu mode %d", sb->s_id, 818 trace_mark(ext4_request_inode, "dev %s dir %lu mode %d", sb->s_id,
822 dir->i_ino, mode); 819 dir->i_ino, mode);
823 inode = new_inode(sb); 820 inode = new_inode(sb);
824 if (!inode) 821 if (!inode)
825 return ERR_PTR(-ENOMEM); 822 return ERR_PTR(-ENOMEM);
826 ei = EXT4_I(inode); 823 ei = EXT4_I(inode);
827
828 sbi = EXT4_SB(sb); 824 sbi = EXT4_SB(sb);
829 es = sbi->s_es;
830 825
831 if (sbi->s_log_groups_per_flex && test_opt(sb, OLDALLOC)) { 826 if (sbi->s_log_groups_per_flex && test_opt(sb, OLDALLOC)) {
832 ret2 = find_group_flex(sb, dir, &group); 827 ret2 = find_group_flex(sb, dir, &group);
@@ -856,7 +851,7 @@ got_group:
856 if (ret2 == -1) 851 if (ret2 == -1)
857 goto out; 852 goto out;
858 853
859 for (i = 0; i < sbi->s_groups_count; i++) { 854 for (i = 0; i < ngroups; i++) {
860 err = -EIO; 855 err = -EIO;
861 856
862 gdp = ext4_get_group_desc(sb, group, &group_desc_bh); 857 gdp = ext4_get_group_desc(sb, group, &group_desc_bh);
@@ -917,7 +912,7 @@ repeat_in_this_group:
917 * group descriptor metadata has not yet been updated. 912 * group descriptor metadata has not yet been updated.
918 * So we just go onto the next blockgroup. 913 * So we just go onto the next blockgroup.
919 */ 914 */
920 if (++group == sbi->s_groups_count) 915 if (++group == ngroups)
921 group = 0; 916 group = 0;
922 } 917 }
923 err = -ENOSPC; 918 err = -ENOSPC;
@@ -938,7 +933,7 @@ got:
938 } 933 }
939 934
940 free = 0; 935 free = 0;
941 spin_lock(sb_bgl_lock(sbi, group)); 936 ext4_lock_group(sb, group);
942 /* recheck and clear flag under lock if we still need to */ 937 /* recheck and clear flag under lock if we still need to */
943 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { 938 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
944 free = ext4_free_blocks_after_init(sb, group, gdp); 939 free = ext4_free_blocks_after_init(sb, group, gdp);
@@ -947,7 +942,7 @@ got:
947 gdp->bg_checksum = ext4_group_desc_csum(sbi, group, 942 gdp->bg_checksum = ext4_group_desc_csum(sbi, group,
948 gdp); 943 gdp);
949 } 944 }
950 spin_unlock(sb_bgl_lock(sbi, group)); 945 ext4_unlock_group(sb, group);
951 946
952 /* Don't need to dirty bitmap block if we didn't change it */ 947 /* Don't need to dirty bitmap block if we didn't change it */
953 if (free) { 948 if (free) {
@@ -1158,7 +1153,7 @@ unsigned long ext4_count_free_inodes(struct super_block *sb)
1158{ 1153{
1159 unsigned long desc_count; 1154 unsigned long desc_count;
1160 struct ext4_group_desc *gdp; 1155 struct ext4_group_desc *gdp;
1161 ext4_group_t i; 1156 ext4_group_t i, ngroups = ext4_get_groups_count(sb);
1162#ifdef EXT4FS_DEBUG 1157#ifdef EXT4FS_DEBUG
1163 struct ext4_super_block *es; 1158 struct ext4_super_block *es;
1164 unsigned long bitmap_count, x; 1159 unsigned long bitmap_count, x;
@@ -1168,7 +1163,7 @@ unsigned long ext4_count_free_inodes(struct super_block *sb)
1168 desc_count = 0; 1163 desc_count = 0;
1169 bitmap_count = 0; 1164 bitmap_count = 0;
1170 gdp = NULL; 1165 gdp = NULL;
1171 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) { 1166 for (i = 0; i < ngroups; i++) {
1172 gdp = ext4_get_group_desc(sb, i, NULL); 1167 gdp = ext4_get_group_desc(sb, i, NULL);
1173 if (!gdp) 1168 if (!gdp)
1174 continue; 1169 continue;
@@ -1190,7 +1185,7 @@ unsigned long ext4_count_free_inodes(struct super_block *sb)
1190 return desc_count; 1185 return desc_count;
1191#else 1186#else
1192 desc_count = 0; 1187 desc_count = 0;
1193 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) { 1188 for (i = 0; i < ngroups; i++) {
1194 gdp = ext4_get_group_desc(sb, i, NULL); 1189 gdp = ext4_get_group_desc(sb, i, NULL);
1195 if (!gdp) 1190 if (!gdp)
1196 continue; 1191 continue;
@@ -1205,9 +1200,9 @@ unsigned long ext4_count_free_inodes(struct super_block *sb)
1205unsigned long ext4_count_dirs(struct super_block * sb) 1200unsigned long ext4_count_dirs(struct super_block * sb)
1206{ 1201{
1207 unsigned long count = 0; 1202 unsigned long count = 0;
1208 ext4_group_t i; 1203 ext4_group_t i, ngroups = ext4_get_groups_count(sb);
1209 1204
1210 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) { 1205 for (i = 0; i < ngroups; i++) {
1211 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL); 1206 struct ext4_group_desc *gdp = ext4_get_group_desc(sb, i, NULL);
1212 if (!gdp) 1207 if (!gdp)
1213 continue; 1208 continue;
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 2a9ffd528dd1..875db944b22f 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -372,20 +372,21 @@ static int ext4_block_to_path(struct inode *inode,
372} 372}
373 373
374static int __ext4_check_blockref(const char *function, struct inode *inode, 374static int __ext4_check_blockref(const char *function, struct inode *inode,
375 __le32 *p, unsigned int max) { 375 __le32 *p, unsigned int max)
376 376{
377 unsigned int maxblocks = ext4_blocks_count(EXT4_SB(inode->i_sb)->s_es);
378 __le32 *bref = p; 377 __le32 *bref = p;
378 unsigned int blk;
379
379 while (bref < p+max) { 380 while (bref < p+max) {
380 if (unlikely(le32_to_cpu(*bref) >= maxblocks)) { 381 blk = le32_to_cpu(*bref++);
382 if (blk &&
383 unlikely(!ext4_data_block_valid(EXT4_SB(inode->i_sb),
384 blk, 1))) {
381 ext4_error(inode->i_sb, function, 385 ext4_error(inode->i_sb, function,
382 "block reference %u >= max (%u) " 386 "invalid block reference %u "
383 "in inode #%lu, offset=%d", 387 "in inode #%lu", blk, inode->i_ino);
384 le32_to_cpu(*bref), maxblocks,
385 inode->i_ino, (int)(bref-p));
386 return -EIO; 388 return -EIO;
387 } 389 }
388 bref++;
389 } 390 }
390 return 0; 391 return 0;
391} 392}
@@ -892,6 +893,10 @@ err_out:
892} 893}
893 894
894/* 895/*
896 * The ext4_ind_get_blocks() function handles non-extents inodes
897 * (i.e., using the traditional indirect/double-indirect i_blocks
898 * scheme) for ext4_get_blocks().
899 *
895 * Allocation strategy is simple: if we have to allocate something, we will 900 * Allocation strategy is simple: if we have to allocate something, we will
896 * have to go the whole way to leaf. So let's do it before attaching anything 901 * have to go the whole way to leaf. So let's do it before attaching anything
897 * to tree, set linkage between the newborn blocks, write them if sync is 902 * to tree, set linkage between the newborn blocks, write them if sync is
@@ -909,15 +914,16 @@ err_out:
909 * return = 0, if plain lookup failed. 914 * return = 0, if plain lookup failed.
910 * return < 0, error case. 915 * return < 0, error case.
911 * 916 *
912 * 917 * The ext4_ind_get_blocks() function should be called with
913 * Need to be called with 918 * down_write(&EXT4_I(inode)->i_data_sem) if allocating filesystem
914 * down_read(&EXT4_I(inode)->i_data_sem) if not allocating file system block 919 * blocks (i.e., flags has EXT4_GET_BLOCKS_CREATE set) or
915 * (ie, create is zero). Otherwise down_write(&EXT4_I(inode)->i_data_sem) 920 * down_read(&EXT4_I(inode)->i_data_sem) if not allocating file system
921 * blocks.
916 */ 922 */
917static int ext4_get_blocks_handle(handle_t *handle, struct inode *inode, 923static int ext4_ind_get_blocks(handle_t *handle, struct inode *inode,
918 ext4_lblk_t iblock, unsigned int maxblocks, 924 ext4_lblk_t iblock, unsigned int maxblocks,
919 struct buffer_head *bh_result, 925 struct buffer_head *bh_result,
920 int create, int extend_disksize) 926 int flags)
921{ 927{
922 int err = -EIO; 928 int err = -EIO;
923 ext4_lblk_t offsets[4]; 929 ext4_lblk_t offsets[4];
@@ -927,14 +933,11 @@ static int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
927 int indirect_blks; 933 int indirect_blks;
928 int blocks_to_boundary = 0; 934 int blocks_to_boundary = 0;
929 int depth; 935 int depth;
930 struct ext4_inode_info *ei = EXT4_I(inode);
931 int count = 0; 936 int count = 0;
932 ext4_fsblk_t first_block = 0; 937 ext4_fsblk_t first_block = 0;
933 loff_t disksize;
934
935 938
936 J_ASSERT(!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL)); 939 J_ASSERT(!(EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL));
937 J_ASSERT(handle != NULL || create == 0); 940 J_ASSERT(handle != NULL || (flags & EXT4_GET_BLOCKS_CREATE) == 0);
938 depth = ext4_block_to_path(inode, iblock, offsets, 941 depth = ext4_block_to_path(inode, iblock, offsets,
939 &blocks_to_boundary); 942 &blocks_to_boundary);
940 943
@@ -963,7 +966,7 @@ static int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
963 } 966 }
964 967
965 /* Next simple case - plain lookup or failed read of indirect block */ 968 /* Next simple case - plain lookup or failed read of indirect block */
966 if (!create || err == -EIO) 969 if ((flags & EXT4_GET_BLOCKS_CREATE) == 0 || err == -EIO)
967 goto cleanup; 970 goto cleanup;
968 971
969 /* 972 /*
@@ -997,19 +1000,7 @@ static int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,
997 if (!err) 1000 if (!err)
998 err = ext4_splice_branch(handle, inode, iblock, 1001 err = ext4_splice_branch(handle, inode, iblock,
999 partial, indirect_blks, count); 1002 partial, indirect_blks, count);
1000 /* 1003 else
1001 * i_disksize growing is protected by i_data_sem. Don't forget to
1002 * protect it if you're about to implement concurrent
1003 * ext4_get_block() -bzzz
1004 */
1005 if (!err && extend_disksize) {
1006 disksize = ((loff_t) iblock + count) << inode->i_blkbits;
1007 if (disksize > i_size_read(inode))
1008 disksize = i_size_read(inode);
1009 if (disksize > ei->i_disksize)
1010 ei->i_disksize = disksize;
1011 }
1012 if (err)
1013 goto cleanup; 1004 goto cleanup;
1014 1005
1015 set_buffer_new(bh_result); 1006 set_buffer_new(bh_result);
@@ -1120,8 +1111,23 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used)
1120 ext4_discard_preallocations(inode); 1111 ext4_discard_preallocations(inode);
1121} 1112}
1122 1113
1114static int check_block_validity(struct inode *inode, sector_t logical,
1115 sector_t phys, int len)
1116{
1117 if (!ext4_data_block_valid(EXT4_SB(inode->i_sb), phys, len)) {
1118 ext4_error(inode->i_sb, "check_block_validity",
1119 "inode #%lu logical block %llu mapped to %llu "
1120 "(size %d)", inode->i_ino,
1121 (unsigned long long) logical,
1122 (unsigned long long) phys, len);
1123 WARN_ON(1);
1124 return -EIO;
1125 }
1126 return 0;
1127}
1128
1123/* 1129/*
1124 * The ext4_get_blocks_wrap() function try to look up the requested blocks, 1130 * The ext4_get_blocks() function tries to look up the requested blocks,
1125 * and returns if the blocks are already mapped. 1131 * and returns if the blocks are already mapped.
1126 * 1132 *
1127 * Otherwise it takes the write lock of the i_data_sem and allocate blocks 1133 * Otherwise it takes the write lock of the i_data_sem and allocate blocks
@@ -1129,7 +1135,7 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used)
1129 * mapped. 1135 * mapped.
1130 * 1136 *
1131 * If file type is extents based, it will call ext4_ext_get_blocks(), 1137 * If file type is extents based, it will call ext4_ext_get_blocks(),
1132 * Otherwise, call with ext4_get_blocks_handle() to handle indirect mapping 1138 * Otherwise, call with ext4_ind_get_blocks() to handle indirect mapping
1133 * based files 1139 * based files
1134 * 1140 *
1135 * On success, it returns the number of blocks being mapped or allocate. 1141 * On success, it returns the number of blocks being mapped or allocate.
@@ -1142,9 +1148,9 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used)
1142 * 1148 *
1143 * It returns the error in case of allocation failure. 1149 * It returns the error in case of allocation failure.
1144 */ 1150 */
1145int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, 1151int ext4_get_blocks(handle_t *handle, struct inode *inode, sector_t block,
1146 unsigned int max_blocks, struct buffer_head *bh, 1152 unsigned int max_blocks, struct buffer_head *bh,
1147 int create, int extend_disksize, int flag) 1153 int flags)
1148{ 1154{
1149 int retval; 1155 int retval;
1150 1156
@@ -1152,21 +1158,28 @@ int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block,
1152 clear_buffer_unwritten(bh); 1158 clear_buffer_unwritten(bh);
1153 1159
1154 /* 1160 /*
1155 * Try to see if we can get the block without requesting 1161 * Try to see if we can get the block without requesting a new
1156 * for new file system block. 1162 * file system block.
1157 */ 1163 */
1158 down_read((&EXT4_I(inode)->i_data_sem)); 1164 down_read((&EXT4_I(inode)->i_data_sem));
1159 if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) { 1165 if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) {
1160 retval = ext4_ext_get_blocks(handle, inode, block, max_blocks, 1166 retval = ext4_ext_get_blocks(handle, inode, block, max_blocks,
1161 bh, 0, 0); 1167 bh, 0);
1162 } else { 1168 } else {
1163 retval = ext4_get_blocks_handle(handle, 1169 retval = ext4_ind_get_blocks(handle, inode, block, max_blocks,
1164 inode, block, max_blocks, bh, 0, 0); 1170 bh, 0);
1165 } 1171 }
1166 up_read((&EXT4_I(inode)->i_data_sem)); 1172 up_read((&EXT4_I(inode)->i_data_sem));
1167 1173
1174 if (retval > 0 && buffer_mapped(bh)) {
1175 int ret = check_block_validity(inode, block,
1176 bh->b_blocknr, retval);
1177 if (ret != 0)
1178 return ret;
1179 }
1180
1168 /* If it is only a block(s) look up */ 1181 /* If it is only a block(s) look up */
1169 if (!create) 1182 if ((flags & EXT4_GET_BLOCKS_CREATE) == 0)
1170 return retval; 1183 return retval;
1171 1184
1172 /* 1185 /*
@@ -1205,7 +1218,7 @@ int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block,
1205 * let the underlying get_block() function know to 1218 * let the underlying get_block() function know to
1206 * avoid double accounting 1219 * avoid double accounting
1207 */ 1220 */
1208 if (flag) 1221 if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE)
1209 EXT4_I(inode)->i_delalloc_reserved_flag = 1; 1222 EXT4_I(inode)->i_delalloc_reserved_flag = 1;
1210 /* 1223 /*
1211 * We need to check for EXT4 here because migrate 1224 * We need to check for EXT4 here because migrate
@@ -1213,10 +1226,10 @@ int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block,
1213 */ 1226 */
1214 if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) { 1227 if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) {
1215 retval = ext4_ext_get_blocks(handle, inode, block, max_blocks, 1228 retval = ext4_ext_get_blocks(handle, inode, block, max_blocks,
1216 bh, create, extend_disksize); 1229 bh, flags);
1217 } else { 1230 } else {
1218 retval = ext4_get_blocks_handle(handle, inode, block, 1231 retval = ext4_ind_get_blocks(handle, inode, block,
1219 max_blocks, bh, create, extend_disksize); 1232 max_blocks, bh, flags);
1220 1233
1221 if (retval > 0 && buffer_new(bh)) { 1234 if (retval > 0 && buffer_new(bh)) {
1222 /* 1235 /*
@@ -1229,18 +1242,23 @@ int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block,
1229 } 1242 }
1230 } 1243 }
1231 1244
1232 if (flag) { 1245 if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE)
1233 EXT4_I(inode)->i_delalloc_reserved_flag = 0; 1246 EXT4_I(inode)->i_delalloc_reserved_flag = 0;
1234 /* 1247
1235 * Update reserved blocks/metadata blocks 1248 /*
1236 * after successful block allocation 1249 * Update reserved blocks/metadata blocks after successful
1237 * which were deferred till now 1250 * block allocation which had been deferred till now.
1238 */ 1251 */
1239 if ((retval > 0) && buffer_delay(bh)) 1252 if ((retval > 0) && (flags & EXT4_GET_BLOCKS_UPDATE_RESERVE_SPACE))
1240 ext4_da_update_reserve_space(inode, retval); 1253 ext4_da_update_reserve_space(inode, retval);
1241 }
1242 1254
1243 up_write((&EXT4_I(inode)->i_data_sem)); 1255 up_write((&EXT4_I(inode)->i_data_sem));
1256 if (retval > 0 && buffer_mapped(bh)) {
1257 int ret = check_block_validity(inode, block,
1258 bh->b_blocknr, retval);
1259 if (ret != 0)
1260 return ret;
1261 }
1244 return retval; 1262 return retval;
1245} 1263}
1246 1264
@@ -1268,8 +1286,8 @@ int ext4_get_block(struct inode *inode, sector_t iblock,
1268 started = 1; 1286 started = 1;
1269 } 1287 }
1270 1288
1271 ret = ext4_get_blocks_wrap(handle, inode, iblock, 1289 ret = ext4_get_blocks(handle, inode, iblock, max_blocks, bh_result,
1272 max_blocks, bh_result, create, 0, 0); 1290 create ? EXT4_GET_BLOCKS_CREATE : 0);
1273 if (ret > 0) { 1291 if (ret > 0) {
1274 bh_result->b_size = (ret << inode->i_blkbits); 1292 bh_result->b_size = (ret << inode->i_blkbits);
1275 ret = 0; 1293 ret = 0;
@@ -1288,17 +1306,19 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
1288{ 1306{
1289 struct buffer_head dummy; 1307 struct buffer_head dummy;
1290 int fatal = 0, err; 1308 int fatal = 0, err;
1309 int flags = 0;
1291 1310
1292 J_ASSERT(handle != NULL || create == 0); 1311 J_ASSERT(handle != NULL || create == 0);
1293 1312
1294 dummy.b_state = 0; 1313 dummy.b_state = 0;
1295 dummy.b_blocknr = -1000; 1314 dummy.b_blocknr = -1000;
1296 buffer_trace_init(&dummy.b_history); 1315 buffer_trace_init(&dummy.b_history);
1297 err = ext4_get_blocks_wrap(handle, inode, block, 1, 1316 if (create)
1298 &dummy, create, 1, 0); 1317 flags |= EXT4_GET_BLOCKS_CREATE;
1318 err = ext4_get_blocks(handle, inode, block, 1, &dummy, flags);
1299 /* 1319 /*
1300 * ext4_get_blocks_handle() returns number of blocks 1320 * ext4_get_blocks() returns number of blocks mapped. 0 in
1301 * mapped. 0 in case of a HOLE. 1321 * case of a HOLE.
1302 */ 1322 */
1303 if (err > 0) { 1323 if (err > 0) {
1304 if (err > 1) 1324 if (err > 1)
@@ -1439,7 +1459,7 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
1439 struct page **pagep, void **fsdata) 1459 struct page **pagep, void **fsdata)
1440{ 1460{
1441 struct inode *inode = mapping->host; 1461 struct inode *inode = mapping->host;
1442 int ret, needed_blocks = ext4_writepage_trans_blocks(inode); 1462 int ret, needed_blocks;
1443 handle_t *handle; 1463 handle_t *handle;
1444 int retries = 0; 1464 int retries = 0;
1445 struct page *page; 1465 struct page *page;
@@ -1450,6 +1470,11 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
1450 "dev %s ino %lu pos %llu len %u flags %u", 1470 "dev %s ino %lu pos %llu len %u flags %u",
1451 inode->i_sb->s_id, inode->i_ino, 1471 inode->i_sb->s_id, inode->i_ino,
1452 (unsigned long long) pos, len, flags); 1472 (unsigned long long) pos, len, flags);
1473 /*
1474 * Reserve one block more for addition to orphan list in case
1475 * we allocate blocks but write fails for some reason
1476 */
1477 needed_blocks = ext4_writepage_trans_blocks(inode) + 1;
1453 index = pos >> PAGE_CACHE_SHIFT; 1478 index = pos >> PAGE_CACHE_SHIFT;
1454 from = pos & (PAGE_CACHE_SIZE - 1); 1479 from = pos & (PAGE_CACHE_SIZE - 1);
1455 to = from + len; 1480 to = from + len;
@@ -1483,15 +1508,30 @@ retry:
1483 1508
1484 if (ret) { 1509 if (ret) {
1485 unlock_page(page); 1510 unlock_page(page);
1486 ext4_journal_stop(handle);
1487 page_cache_release(page); 1511 page_cache_release(page);
1488 /* 1512 /*
1489 * block_write_begin may have instantiated a few blocks 1513 * block_write_begin may have instantiated a few blocks
1490 * outside i_size. Trim these off again. Don't need 1514 * outside i_size. Trim these off again. Don't need
1491 * i_size_read because we hold i_mutex. 1515 * i_size_read because we hold i_mutex.
1516 *
1517 * Add inode to orphan list in case we crash before
1518 * truncate finishes
1492 */ 1519 */
1493 if (pos + len > inode->i_size) 1520 if (pos + len > inode->i_size)
1521 ext4_orphan_add(handle, inode);
1522
1523 ext4_journal_stop(handle);
1524 if (pos + len > inode->i_size) {
1494 vmtruncate(inode, inode->i_size); 1525 vmtruncate(inode, inode->i_size);
1526 /*
1527 * If vmtruncate failed early the inode might
1528 * still be on the orphan list; we need to
1529 * make sure the inode is removed from the
1530 * orphan list in that case.
1531 */
1532 if (inode->i_nlink)
1533 ext4_orphan_del(NULL, inode);
1534 }
1495 } 1535 }
1496 1536
1497 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) 1537 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
@@ -1509,6 +1549,52 @@ static int write_end_fn(handle_t *handle, struct buffer_head *bh)
1509 return ext4_handle_dirty_metadata(handle, NULL, bh); 1549 return ext4_handle_dirty_metadata(handle, NULL, bh);
1510} 1550}
1511 1551
1552static int ext4_generic_write_end(struct file *file,
1553 struct address_space *mapping,
1554 loff_t pos, unsigned len, unsigned copied,
1555 struct page *page, void *fsdata)
1556{
1557 int i_size_changed = 0;
1558 struct inode *inode = mapping->host;
1559 handle_t *handle = ext4_journal_current_handle();
1560
1561 copied = block_write_end(file, mapping, pos, len, copied, page, fsdata);
1562
1563 /*
1564 * No need to use i_size_read() here, the i_size
1565 * cannot change under us because we hold i_mutex.
1566 *
1567 * But it's important to update i_size while still holding page lock:
1568 * page writeout could otherwise come in and zero beyond i_size.
1569 */
1570 if (pos + copied > inode->i_size) {
1571 i_size_write(inode, pos + copied);
1572 i_size_changed = 1;
1573 }
1574
1575 if (pos + copied > EXT4_I(inode)->i_disksize) {
1576 /* We need to mark inode dirty even if
1577 * new_i_size is less that inode->i_size
1578 * bu greater than i_disksize.(hint delalloc)
1579 */
1580 ext4_update_i_disksize(inode, (pos + copied));
1581 i_size_changed = 1;
1582 }
1583 unlock_page(page);
1584 page_cache_release(page);
1585
1586 /*
1587 * Don't mark the inode dirty under page lock. First, it unnecessarily
1588 * makes the holding time of page lock longer. Second, it forces lock
1589 * ordering of page lock and transaction start for journaling
1590 * filesystems.
1591 */
1592 if (i_size_changed)
1593 ext4_mark_inode_dirty(handle, inode);
1594
1595 return copied;
1596}
1597
1512/* 1598/*
1513 * We need to pick up the new inode size which generic_commit_write gave us 1599 * We need to pick up the new inode size which generic_commit_write gave us
1514 * `file' can be NULL - eg, when called from page_symlink(). 1600 * `file' can be NULL - eg, when called from page_symlink().
@@ -1532,21 +1618,15 @@ static int ext4_ordered_write_end(struct file *file,
1532 ret = ext4_jbd2_file_inode(handle, inode); 1618 ret = ext4_jbd2_file_inode(handle, inode);
1533 1619
1534 if (ret == 0) { 1620 if (ret == 0) {
1535 loff_t new_i_size; 1621 ret2 = ext4_generic_write_end(file, mapping, pos, len, copied,
1536
1537 new_i_size = pos + copied;
1538 if (new_i_size > EXT4_I(inode)->i_disksize) {
1539 ext4_update_i_disksize(inode, new_i_size);
1540 /* We need to mark inode dirty even if
1541 * new_i_size is less that inode->i_size
1542 * bu greater than i_disksize.(hint delalloc)
1543 */
1544 ext4_mark_inode_dirty(handle, inode);
1545 }
1546
1547 ret2 = generic_write_end(file, mapping, pos, len, copied,
1548 page, fsdata); 1622 page, fsdata);
1549 copied = ret2; 1623 copied = ret2;
1624 if (pos + len > inode->i_size)
1625 /* if we have allocated more blocks and copied
1626 * less. We will have blocks allocated outside
1627 * inode->i_size. So truncate them
1628 */
1629 ext4_orphan_add(handle, inode);
1550 if (ret2 < 0) 1630 if (ret2 < 0)
1551 ret = ret2; 1631 ret = ret2;
1552 } 1632 }
@@ -1554,6 +1634,18 @@ static int ext4_ordered_write_end(struct file *file,
1554 if (!ret) 1634 if (!ret)
1555 ret = ret2; 1635 ret = ret2;
1556 1636
1637 if (pos + len > inode->i_size) {
1638 vmtruncate(inode, inode->i_size);
1639 /*
1640 * If vmtruncate failed early the inode might still be
1641 * on the orphan list; we need to make sure the inode
1642 * is removed from the orphan list in that case.
1643 */
1644 if (inode->i_nlink)
1645 ext4_orphan_del(NULL, inode);
1646 }
1647
1648
1557 return ret ? ret : copied; 1649 return ret ? ret : copied;
1558} 1650}
1559 1651
@@ -1565,25 +1657,21 @@ static int ext4_writeback_write_end(struct file *file,
1565 handle_t *handle = ext4_journal_current_handle(); 1657 handle_t *handle = ext4_journal_current_handle();
1566 struct inode *inode = mapping->host; 1658 struct inode *inode = mapping->host;
1567 int ret = 0, ret2; 1659 int ret = 0, ret2;
1568 loff_t new_i_size;
1569 1660
1570 trace_mark(ext4_writeback_write_end, 1661 trace_mark(ext4_writeback_write_end,
1571 "dev %s ino %lu pos %llu len %u copied %u", 1662 "dev %s ino %lu pos %llu len %u copied %u",
1572 inode->i_sb->s_id, inode->i_ino, 1663 inode->i_sb->s_id, inode->i_ino,
1573 (unsigned long long) pos, len, copied); 1664 (unsigned long long) pos, len, copied);
1574 new_i_size = pos + copied; 1665 ret2 = ext4_generic_write_end(file, mapping, pos, len, copied,
1575 if (new_i_size > EXT4_I(inode)->i_disksize) {
1576 ext4_update_i_disksize(inode, new_i_size);
1577 /* We need to mark inode dirty even if
1578 * new_i_size is less that inode->i_size
1579 * bu greater than i_disksize.(hint delalloc)
1580 */
1581 ext4_mark_inode_dirty(handle, inode);
1582 }
1583
1584 ret2 = generic_write_end(file, mapping, pos, len, copied,
1585 page, fsdata); 1666 page, fsdata);
1586 copied = ret2; 1667 copied = ret2;
1668 if (pos + len > inode->i_size)
1669 /* if we have allocated more blocks and copied
1670 * less. We will have blocks allocated outside
1671 * inode->i_size. So truncate them
1672 */
1673 ext4_orphan_add(handle, inode);
1674
1587 if (ret2 < 0) 1675 if (ret2 < 0)
1588 ret = ret2; 1676 ret = ret2;
1589 1677
@@ -1591,6 +1679,17 @@ static int ext4_writeback_write_end(struct file *file,
1591 if (!ret) 1679 if (!ret)
1592 ret = ret2; 1680 ret = ret2;
1593 1681
1682 if (pos + len > inode->i_size) {
1683 vmtruncate(inode, inode->i_size);
1684 /*
1685 * If vmtruncate failed early the inode might still be
1686 * on the orphan list; we need to make sure the inode
1687 * is removed from the orphan list in that case.
1688 */
1689 if (inode->i_nlink)
1690 ext4_orphan_del(NULL, inode);
1691 }
1692
1594 return ret ? ret : copied; 1693 return ret ? ret : copied;
1595} 1694}
1596 1695
@@ -1635,10 +1734,27 @@ static int ext4_journalled_write_end(struct file *file,
1635 } 1734 }
1636 1735
1637 unlock_page(page); 1736 unlock_page(page);
1737 page_cache_release(page);
1738 if (pos + len > inode->i_size)
1739 /* if we have allocated more blocks and copied
1740 * less. We will have blocks allocated outside
1741 * inode->i_size. So truncate them
1742 */
1743 ext4_orphan_add(handle, inode);
1744
1638 ret2 = ext4_journal_stop(handle); 1745 ret2 = ext4_journal_stop(handle);
1639 if (!ret) 1746 if (!ret)
1640 ret = ret2; 1747 ret = ret2;
1641 page_cache_release(page); 1748 if (pos + len > inode->i_size) {
1749 vmtruncate(inode, inode->i_size);
1750 /*
1751 * If vmtruncate failed early the inode might still be
1752 * on the orphan list; we need to make sure the inode
1753 * is removed from the orphan list in that case.
1754 */
1755 if (inode->i_nlink)
1756 ext4_orphan_del(NULL, inode);
1757 }
1642 1758
1643 return ret ? ret : copied; 1759 return ret ? ret : copied;
1644} 1760}
@@ -1852,7 +1968,7 @@ static int mpage_da_submit_io(struct mpage_da_data *mpd)
1852 * @logical - first logical block to start assignment with 1968 * @logical - first logical block to start assignment with
1853 * 1969 *
1854 * the function goes through all passed space and put actual disk 1970 * the function goes through all passed space and put actual disk
1855 * block numbers into buffer heads, dropping BH_Delay 1971 * block numbers into buffer heads, dropping BH_Delay and BH_Unwritten
1856 */ 1972 */
1857static void mpage_put_bnr_to_bhs(struct mpage_da_data *mpd, sector_t logical, 1973static void mpage_put_bnr_to_bhs(struct mpage_da_data *mpd, sector_t logical,
1858 struct buffer_head *exbh) 1974 struct buffer_head *exbh)
@@ -1902,16 +2018,24 @@ static void mpage_put_bnr_to_bhs(struct mpage_da_data *mpd, sector_t logical,
1902 do { 2018 do {
1903 if (cur_logical >= logical + blocks) 2019 if (cur_logical >= logical + blocks)
1904 break; 2020 break;
1905 if (buffer_delay(bh)) { 2021
1906 bh->b_blocknr = pblock; 2022 if (buffer_delay(bh) ||
1907 clear_buffer_delay(bh); 2023 buffer_unwritten(bh)) {
1908 bh->b_bdev = inode->i_sb->s_bdev; 2024
1909 } else if (buffer_unwritten(bh)) { 2025 BUG_ON(bh->b_bdev != inode->i_sb->s_bdev);
1910 bh->b_blocknr = pblock; 2026
1911 clear_buffer_unwritten(bh); 2027 if (buffer_delay(bh)) {
1912 set_buffer_mapped(bh); 2028 clear_buffer_delay(bh);
1913 set_buffer_new(bh); 2029 bh->b_blocknr = pblock;
1914 bh->b_bdev = inode->i_sb->s_bdev; 2030 } else {
2031 /*
2032 * unwritten already should have
2033 * blocknr assigned. Verify that
2034 */
2035 clear_buffer_unwritten(bh);
2036 BUG_ON(bh->b_blocknr != pblock);
2037 }
2038
1915 } else if (buffer_mapped(bh)) 2039 } else if (buffer_mapped(bh))
1916 BUG_ON(bh->b_blocknr != pblock); 2040 BUG_ON(bh->b_blocknr != pblock);
1917 2041
@@ -1990,51 +2114,6 @@ static void ext4_print_free_blocks(struct inode *inode)
1990 return; 2114 return;
1991} 2115}
1992 2116
1993#define EXT4_DELALLOC_RSVED 1
1994static int ext4_da_get_block_write(struct inode *inode, sector_t iblock,
1995 struct buffer_head *bh_result, int create)
1996{
1997 int ret;
1998 unsigned max_blocks = bh_result->b_size >> inode->i_blkbits;
1999 loff_t disksize = EXT4_I(inode)->i_disksize;
2000 handle_t *handle = NULL;
2001
2002 handle = ext4_journal_current_handle();
2003 BUG_ON(!handle);
2004 ret = ext4_get_blocks_wrap(handle, inode, iblock, max_blocks,
2005 bh_result, create, 0, EXT4_DELALLOC_RSVED);
2006 if (ret <= 0)
2007 return ret;
2008
2009 bh_result->b_size = (ret << inode->i_blkbits);
2010
2011 if (ext4_should_order_data(inode)) {
2012 int retval;
2013 retval = ext4_jbd2_file_inode(handle, inode);
2014 if (retval)
2015 /*
2016 * Failed to add inode for ordered mode. Don't
2017 * update file size
2018 */
2019 return retval;
2020 }
2021
2022 /*
2023 * Update on-disk size along with block allocation we don't
2024 * use 'extend_disksize' as size may change within already
2025 * allocated block -bzzz
2026 */
2027 disksize = ((loff_t) iblock + ret) << inode->i_blkbits;
2028 if (disksize > i_size_read(inode))
2029 disksize = i_size_read(inode);
2030 if (disksize > EXT4_I(inode)->i_disksize) {
2031 ext4_update_i_disksize(inode, disksize);
2032 ret = ext4_mark_inode_dirty(handle, inode);
2033 return ret;
2034 }
2035 return 0;
2036}
2037
2038/* 2117/*
2039 * mpage_da_map_blocks - go through given space 2118 * mpage_da_map_blocks - go through given space
2040 * 2119 *
@@ -2045,29 +2124,57 @@ static int ext4_da_get_block_write(struct inode *inode, sector_t iblock,
2045 */ 2124 */
2046static int mpage_da_map_blocks(struct mpage_da_data *mpd) 2125static int mpage_da_map_blocks(struct mpage_da_data *mpd)
2047{ 2126{
2048 int err = 0; 2127 int err, blks, get_blocks_flags;
2049 struct buffer_head new; 2128 struct buffer_head new;
2050 sector_t next; 2129 sector_t next = mpd->b_blocknr;
2130 unsigned max_blocks = mpd->b_size >> mpd->inode->i_blkbits;
2131 loff_t disksize = EXT4_I(mpd->inode)->i_disksize;
2132 handle_t *handle = NULL;
2051 2133
2052 /* 2134 /*
2053 * We consider only non-mapped and non-allocated blocks 2135 * We consider only non-mapped and non-allocated blocks
2054 */ 2136 */
2055 if ((mpd->b_state & (1 << BH_Mapped)) && 2137 if ((mpd->b_state & (1 << BH_Mapped)) &&
2056 !(mpd->b_state & (1 << BH_Delay))) 2138 !(mpd->b_state & (1 << BH_Delay)) &&
2139 !(mpd->b_state & (1 << BH_Unwritten)))
2057 return 0; 2140 return 0;
2058 new.b_state = mpd->b_state; 2141
2059 new.b_blocknr = 0;
2060 new.b_size = mpd->b_size;
2061 next = mpd->b_blocknr;
2062 /* 2142 /*
2063 * If we didn't accumulate anything 2143 * If we didn't accumulate anything to write simply return
2064 * to write simply return
2065 */ 2144 */
2066 if (!new.b_size) 2145 if (!mpd->b_size)
2067 return 0; 2146 return 0;
2068 2147
2069 err = ext4_da_get_block_write(mpd->inode, next, &new, 1); 2148 handle = ext4_journal_current_handle();
2070 if (err) { 2149 BUG_ON(!handle);
2150
2151 /*
2152 * Call ext4_get_blocks() to allocate any delayed allocation
2153 * blocks, or to convert an uninitialized extent to be
2154 * initialized (in the case where we have written into
2155 * one or more preallocated blocks).
2156 *
2157 * We pass in the magic EXT4_GET_BLOCKS_DELALLOC_RESERVE to
2158 * indicate that we are on the delayed allocation path. This
2159 * affects functions in many different parts of the allocation
2160 * call path. This flag exists primarily because we don't
2161 * want to change *many* call functions, so ext4_get_blocks()
2162 * will set the magic i_delalloc_reserved_flag once the
2163 * inode's allocation semaphore is taken.
2164 *
2165 * If the blocks in questions were delalloc blocks, set
2166 * EXT4_GET_BLOCKS_DELALLOC_RESERVE so the delalloc accounting
2167 * variables are updated after the blocks have been allocated.
2168 */
2169 new.b_state = 0;
2170 get_blocks_flags = (EXT4_GET_BLOCKS_CREATE |
2171 EXT4_GET_BLOCKS_DELALLOC_RESERVE);
2172 if (mpd->b_state & (1 << BH_Delay))
2173 get_blocks_flags |= EXT4_GET_BLOCKS_UPDATE_RESERVE_SPACE;
2174 blks = ext4_get_blocks(handle, mpd->inode, next, max_blocks,
2175 &new, get_blocks_flags);
2176 if (blks < 0) {
2177 err = blks;
2071 /* 2178 /*
2072 * If get block returns with error we simply 2179 * If get block returns with error we simply
2073 * return. Later writepage will redirty the page and 2180 * return. Later writepage will redirty the page and
@@ -2100,12 +2207,14 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd)
2100 if (err == -ENOSPC) { 2207 if (err == -ENOSPC) {
2101 ext4_print_free_blocks(mpd->inode); 2208 ext4_print_free_blocks(mpd->inode);
2102 } 2209 }
2103 /* invlaidate all the pages */ 2210 /* invalidate all the pages */
2104 ext4_da_block_invalidatepages(mpd, next, 2211 ext4_da_block_invalidatepages(mpd, next,
2105 mpd->b_size >> mpd->inode->i_blkbits); 2212 mpd->b_size >> mpd->inode->i_blkbits);
2106 return err; 2213 return err;
2107 } 2214 }
2108 BUG_ON(new.b_size == 0); 2215 BUG_ON(blks == 0);
2216
2217 new.b_size = (blks << mpd->inode->i_blkbits);
2109 2218
2110 if (buffer_new(&new)) 2219 if (buffer_new(&new))
2111 __unmap_underlying_blocks(mpd->inode, &new); 2220 __unmap_underlying_blocks(mpd->inode, &new);
@@ -2118,6 +2227,23 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd)
2118 (mpd->b_state & (1 << BH_Unwritten))) 2227 (mpd->b_state & (1 << BH_Unwritten)))
2119 mpage_put_bnr_to_bhs(mpd, next, &new); 2228 mpage_put_bnr_to_bhs(mpd, next, &new);
2120 2229
2230 if (ext4_should_order_data(mpd->inode)) {
2231 err = ext4_jbd2_file_inode(handle, mpd->inode);
2232 if (err)
2233 return err;
2234 }
2235
2236 /*
2237 * Update on-disk size along with block allocation.
2238 */
2239 disksize = ((loff_t) next + blks) << mpd->inode->i_blkbits;
2240 if (disksize > i_size_read(mpd->inode))
2241 disksize = i_size_read(mpd->inode);
2242 if (disksize > EXT4_I(mpd->inode)->i_disksize) {
2243 ext4_update_i_disksize(mpd->inode, disksize);
2244 return ext4_mark_inode_dirty(handle, mpd->inode);
2245 }
2246
2121 return 0; 2247 return 0;
2122} 2248}
2123 2249
@@ -2192,6 +2318,17 @@ flush_it:
2192 return; 2318 return;
2193} 2319}
2194 2320
2321static int ext4_bh_unmapped_or_delay(handle_t *handle, struct buffer_head *bh)
2322{
2323 /*
2324 * unmapped buffer is possible for holes.
2325 * delay buffer is possible with delayed allocation.
2326 * We also need to consider unwritten buffer as unmapped.
2327 */
2328 return (!buffer_mapped(bh) || buffer_delay(bh) ||
2329 buffer_unwritten(bh)) && buffer_dirty(bh);
2330}
2331
2195/* 2332/*
2196 * __mpage_da_writepage - finds extent of pages and blocks 2333 * __mpage_da_writepage - finds extent of pages and blocks
2197 * 2334 *
@@ -2276,8 +2413,7 @@ static int __mpage_da_writepage(struct page *page,
2276 * Otherwise we won't make progress 2413 * Otherwise we won't make progress
2277 * with the page in ext4_da_writepage 2414 * with the page in ext4_da_writepage
2278 */ 2415 */
2279 if (buffer_dirty(bh) && 2416 if (ext4_bh_unmapped_or_delay(NULL, bh)) {
2280 (!buffer_mapped(bh) || buffer_delay(bh))) {
2281 mpage_add_bh_to_extent(mpd, logical, 2417 mpage_add_bh_to_extent(mpd, logical,
2282 bh->b_size, 2418 bh->b_size,
2283 bh->b_state); 2419 bh->b_state);
@@ -2303,8 +2439,16 @@ static int __mpage_da_writepage(struct page *page,
2303} 2439}
2304 2440
2305/* 2441/*
2306 * this is a special callback for ->write_begin() only 2442 * This is a special get_blocks_t callback which is used by
2307 * it's intention is to return mapped block or reserve space 2443 * ext4_da_write_begin(). It will either return mapped block or
2444 * reserve space for a single block.
2445 *
2446 * For delayed buffer_head we have BH_Mapped, BH_New, BH_Delay set.
2447 * We also have b_blocknr = -1 and b_bdev initialized properly
2448 *
2449 * For unwritten buffer_head we have BH_Mapped, BH_New, BH_Unwritten set.
2450 * We also have b_blocknr = physicalblock mapping unwritten extent and b_bdev
2451 * initialized properly.
2308 */ 2452 */
2309static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, 2453static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,
2310 struct buffer_head *bh_result, int create) 2454 struct buffer_head *bh_result, int create)
@@ -2323,7 +2467,7 @@ static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,
2323 * preallocated blocks are unmapped but should treated 2467 * preallocated blocks are unmapped but should treated
2324 * the same as allocated blocks. 2468 * the same as allocated blocks.
2325 */ 2469 */
2326 ret = ext4_get_blocks_wrap(NULL, inode, iblock, 1, bh_result, 0, 0, 0); 2470 ret = ext4_get_blocks(NULL, inode, iblock, 1, bh_result, 0);
2327 if ((ret == 0) && !buffer_delay(bh_result)) { 2471 if ((ret == 0) && !buffer_delay(bh_result)) {
2328 /* the block isn't (pre)allocated yet, let's reserve space */ 2472 /* the block isn't (pre)allocated yet, let's reserve space */
2329 /* 2473 /*
@@ -2340,40 +2484,53 @@ static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,
2340 set_buffer_delay(bh_result); 2484 set_buffer_delay(bh_result);
2341 } else if (ret > 0) { 2485 } else if (ret > 0) {
2342 bh_result->b_size = (ret << inode->i_blkbits); 2486 bh_result->b_size = (ret << inode->i_blkbits);
2343 /* 2487 if (buffer_unwritten(bh_result)) {
2344 * With sub-block writes into unwritten extents 2488 /* A delayed write to unwritten bh should
2345 * we also need to mark the buffer as new so that 2489 * be marked new and mapped. Mapped ensures
2346 * the unwritten parts of the buffer gets correctly zeroed. 2490 * that we don't do get_block multiple times
2347 */ 2491 * when we write to the same offset and new
2348 if (buffer_unwritten(bh_result)) 2492 * ensures that we do proper zero out for
2493 * partial write.
2494 */
2349 set_buffer_new(bh_result); 2495 set_buffer_new(bh_result);
2496 set_buffer_mapped(bh_result);
2497 }
2350 ret = 0; 2498 ret = 0;
2351 } 2499 }
2352 2500
2353 return ret; 2501 return ret;
2354} 2502}
2355 2503
2356static int ext4_bh_unmapped_or_delay(handle_t *handle, struct buffer_head *bh) 2504/*
2357{ 2505 * This function is used as a standard get_block_t calback function
2358 /* 2506 * when there is no desire to allocate any blocks. It is used as a
2359 * unmapped buffer is possible for holes. 2507 * callback function for block_prepare_write(), nobh_writepage(), and
2360 * delay buffer is possible with delayed allocation 2508 * block_write_full_page(). These functions should only try to map a
2361 */ 2509 * single block at a time.
2362 return ((!buffer_mapped(bh) || buffer_delay(bh)) && buffer_dirty(bh)); 2510 *
2363} 2511 * Since this function doesn't do block allocations even if the caller
2364 2512 * requests it by passing in create=1, it is critically important that
2365static int ext4_normal_get_block_write(struct inode *inode, sector_t iblock, 2513 * any caller checks to make sure that any buffer heads are returned
2514 * by this function are either all already mapped or marked for
2515 * delayed allocation before calling nobh_writepage() or
2516 * block_write_full_page(). Otherwise, b_blocknr could be left
2517 * unitialized, and the page write functions will be taken by
2518 * surprise.
2519 */
2520static int noalloc_get_block_write(struct inode *inode, sector_t iblock,
2366 struct buffer_head *bh_result, int create) 2521 struct buffer_head *bh_result, int create)
2367{ 2522{
2368 int ret = 0; 2523 int ret = 0;
2369 unsigned max_blocks = bh_result->b_size >> inode->i_blkbits; 2524 unsigned max_blocks = bh_result->b_size >> inode->i_blkbits;
2370 2525
2526 BUG_ON(bh_result->b_size != inode->i_sb->s_blocksize);
2527
2371 /* 2528 /*
2372 * we don't want to do block allocation in writepage 2529 * we don't want to do block allocation in writepage
2373 * so call get_block_wrap with create = 0 2530 * so call get_block_wrap with create = 0
2374 */ 2531 */
2375 ret = ext4_get_blocks_wrap(NULL, inode, iblock, max_blocks, 2532 ret = ext4_get_blocks(NULL, inode, iblock, max_blocks, bh_result, 0);
2376 bh_result, 0, 0, 0); 2533 BUG_ON(create && ret == 0);
2377 if (ret > 0) { 2534 if (ret > 0) {
2378 bh_result->b_size = (ret << inode->i_blkbits); 2535 bh_result->b_size = (ret << inode->i_blkbits);
2379 ret = 0; 2536 ret = 0;
@@ -2382,10 +2539,11 @@ static int ext4_normal_get_block_write(struct inode *inode, sector_t iblock,
2382} 2539}
2383 2540
2384/* 2541/*
2385 * get called vi ext4_da_writepages after taking page lock (have journal handle) 2542 * This function can get called via...
2386 * get called via journal_submit_inode_data_buffers (no journal handle) 2543 * - ext4_da_writepages after taking page lock (have journal handle)
2387 * get called via shrink_page_list via pdflush (no journal handle) 2544 * - journal_submit_inode_data_buffers (no journal handle)
2388 * or grab_page_cache when doing write_begin (have journal handle) 2545 * - shrink_page_list via pdflush (no journal handle)
2546 * - grab_page_cache when doing write_begin (have journal handle)
2389 */ 2547 */
2390static int ext4_da_writepage(struct page *page, 2548static int ext4_da_writepage(struct page *page,
2391 struct writeback_control *wbc) 2549 struct writeback_control *wbc)
@@ -2436,7 +2594,7 @@ static int ext4_da_writepage(struct page *page,
2436 * do block allocation here. 2594 * do block allocation here.
2437 */ 2595 */
2438 ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE, 2596 ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE,
2439 ext4_normal_get_block_write); 2597 noalloc_get_block_write);
2440 if (!ret) { 2598 if (!ret) {
2441 page_bufs = page_buffers(page); 2599 page_bufs = page_buffers(page);
2442 /* check whether all are mapped and non delay */ 2600 /* check whether all are mapped and non delay */
@@ -2461,11 +2619,10 @@ static int ext4_da_writepage(struct page *page,
2461 } 2619 }
2462 2620
2463 if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode)) 2621 if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode))
2464 ret = nobh_writepage(page, ext4_normal_get_block_write, wbc); 2622 ret = nobh_writepage(page, noalloc_get_block_write, wbc);
2465 else 2623 else
2466 ret = block_write_full_page(page, 2624 ret = block_write_full_page(page, noalloc_get_block_write,
2467 ext4_normal_get_block_write, 2625 wbc);
2468 wbc);
2469 2626
2470 return ret; 2627 return ret;
2471} 2628}
@@ -2777,7 +2934,7 @@ retry:
2777 *pagep = page; 2934 *pagep = page;
2778 2935
2779 ret = block_write_begin(file, mapping, pos, len, flags, pagep, fsdata, 2936 ret = block_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
2780 ext4_da_get_block_prep); 2937 ext4_da_get_block_prep);
2781 if (ret < 0) { 2938 if (ret < 0) {
2782 unlock_page(page); 2939 unlock_page(page);
2783 ext4_journal_stop(handle); 2940 ext4_journal_stop(handle);
@@ -2815,7 +2972,7 @@ static int ext4_da_should_update_i_disksize(struct page *page,
2815 for (i = 0; i < idx; i++) 2972 for (i = 0; i < idx; i++)
2816 bh = bh->b_this_page; 2973 bh = bh->b_this_page;
2817 2974
2818 if (!buffer_mapped(bh) || (buffer_delay(bh))) 2975 if (!buffer_mapped(bh) || (buffer_delay(bh)) || buffer_unwritten(bh))
2819 return 0; 2976 return 0;
2820 return 1; 2977 return 1;
2821} 2978}
@@ -3085,12 +3242,10 @@ static int __ext4_normal_writepage(struct page *page,
3085 struct inode *inode = page->mapping->host; 3242 struct inode *inode = page->mapping->host;
3086 3243
3087 if (test_opt(inode->i_sb, NOBH)) 3244 if (test_opt(inode->i_sb, NOBH))
3088 return nobh_writepage(page, 3245 return nobh_writepage(page, noalloc_get_block_write, wbc);
3089 ext4_normal_get_block_write, wbc);
3090 else 3246 else
3091 return block_write_full_page(page, 3247 return block_write_full_page(page, noalloc_get_block_write,
3092 ext4_normal_get_block_write, 3248 wbc);
3093 wbc);
3094} 3249}
3095 3250
3096static int ext4_normal_writepage(struct page *page, 3251static int ext4_normal_writepage(struct page *page,
@@ -3142,7 +3297,7 @@ static int __ext4_journalled_writepage(struct page *page,
3142 int err; 3297 int err;
3143 3298
3144 ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE, 3299 ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE,
3145 ext4_normal_get_block_write); 3300 noalloc_get_block_write);
3146 if (ret != 0) 3301 if (ret != 0)
3147 goto out_unlock; 3302 goto out_unlock;
3148 3303
@@ -3227,9 +3382,8 @@ static int ext4_journalled_writepage(struct page *page,
3227 * really know unless we go poke around in the buffer_heads. 3382 * really know unless we go poke around in the buffer_heads.
3228 * But block_write_full_page will do the right thing. 3383 * But block_write_full_page will do the right thing.
3229 */ 3384 */
3230 return block_write_full_page(page, 3385 return block_write_full_page(page, noalloc_get_block_write,
3231 ext4_normal_get_block_write, 3386 wbc);
3232 wbc);
3233 } 3387 }
3234no_write: 3388no_write:
3235 redirty_page_for_writepage(wbc, page); 3389 redirty_page_for_writepage(wbc, page);
@@ -3973,7 +4127,8 @@ void ext4_truncate(struct inode *inode)
3973 if (!ext4_can_truncate(inode)) 4127 if (!ext4_can_truncate(inode))
3974 return; 4128 return;
3975 4129
3976 if (inode->i_size == 0 && !test_opt(inode->i_sb, NO_AUTO_DA_ALLOC)) 4130 if (ei->i_disksize && inode->i_size == 0 &&
4131 !test_opt(inode->i_sb, NO_AUTO_DA_ALLOC))
3977 ei->i_state |= EXT4_STATE_DA_ALLOC_CLOSE; 4132 ei->i_state |= EXT4_STATE_DA_ALLOC_CLOSE;
3978 4133
3979 if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) { 4134 if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) {
@@ -4715,25 +4870,6 @@ int ext4_write_inode(struct inode *inode, int wait)
4715 return ext4_force_commit(inode->i_sb); 4870 return ext4_force_commit(inode->i_sb);
4716} 4871}
4717 4872
4718int __ext4_write_dirty_metadata(struct inode *inode, struct buffer_head *bh)
4719{
4720 int err = 0;
4721
4722 mark_buffer_dirty(bh);
4723 if (inode && inode_needs_sync(inode)) {
4724 sync_dirty_buffer(bh);
4725 if (buffer_req(bh) && !buffer_uptodate(bh)) {
4726 ext4_error(inode->i_sb, __func__,
4727 "IO error syncing inode, "
4728 "inode=%lu, block=%llu",
4729 inode->i_ino,
4730 (unsigned long long)bh->b_blocknr);
4731 err = -EIO;
4732 }
4733 }
4734 return err;
4735}
4736
4737/* 4873/*
4738 * ext4_setattr() 4874 * ext4_setattr()
4739 * 4875 *
@@ -4930,7 +5066,8 @@ static int ext4_index_trans_blocks(struct inode *inode, int nrblocks, int chunk)
4930 */ 5066 */
4931int ext4_meta_trans_blocks(struct inode *inode, int nrblocks, int chunk) 5067int ext4_meta_trans_blocks(struct inode *inode, int nrblocks, int chunk)
4932{ 5068{
4933 int groups, gdpblocks; 5069 ext4_group_t groups, ngroups = ext4_get_groups_count(inode->i_sb);
5070 int gdpblocks;
4934 int idxblocks; 5071 int idxblocks;
4935 int ret = 0; 5072 int ret = 0;
4936 5073
@@ -4957,8 +5094,8 @@ int ext4_meta_trans_blocks(struct inode *inode, int nrblocks, int chunk)
4957 groups += nrblocks; 5094 groups += nrblocks;
4958 5095
4959 gdpblocks = groups; 5096 gdpblocks = groups;
4960 if (groups > EXT4_SB(inode->i_sb)->s_groups_count) 5097 if (groups > ngroups)
4961 groups = EXT4_SB(inode->i_sb)->s_groups_count; 5098 groups = ngroups;
4962 if (groups > EXT4_SB(inode->i_sb)->s_gdb_count) 5099 if (groups > EXT4_SB(inode->i_sb)->s_gdb_count)
4963 gdpblocks = EXT4_SB(inode->i_sb)->s_gdb_count; 5100 gdpblocks = EXT4_SB(inode->i_sb)->s_gdb_count;
4964 5101
@@ -4998,7 +5135,7 @@ int ext4_writepage_trans_blocks(struct inode *inode)
4998 * Calculate the journal credits for a chunk of data modification. 5135 * Calculate the journal credits for a chunk of data modification.
4999 * 5136 *
5000 * This is called from DIO, fallocate or whoever calling 5137 * This is called from DIO, fallocate or whoever calling
5001 * ext4_get_blocks_wrap() to map/allocate a chunk of contigous disk blocks. 5138 * ext4_get_blocks() to map/allocate a chunk of contigous disk blocks.
5002 * 5139 *
5003 * journal buffers for data blocks are not included here, as DIO 5140 * journal buffers for data blocks are not included here, as DIO
5004 * and fallocate do no need to journal data buffers. 5141 * and fallocate do no need to journal data buffers.
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index f871677a7984..ed8482e22c0e 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -372,24 +372,12 @@ static inline void mb_set_bit(int bit, void *addr)
372 ext4_set_bit(bit, addr); 372 ext4_set_bit(bit, addr);
373} 373}
374 374
375static inline void mb_set_bit_atomic(spinlock_t *lock, int bit, void *addr)
376{
377 addr = mb_correct_addr_and_bit(&bit, addr);
378 ext4_set_bit_atomic(lock, bit, addr);
379}
380
381static inline void mb_clear_bit(int bit, void *addr) 375static inline void mb_clear_bit(int bit, void *addr)
382{ 376{
383 addr = mb_correct_addr_and_bit(&bit, addr); 377 addr = mb_correct_addr_and_bit(&bit, addr);
384 ext4_clear_bit(bit, addr); 378 ext4_clear_bit(bit, addr);
385} 379}
386 380
387static inline void mb_clear_bit_atomic(spinlock_t *lock, int bit, void *addr)
388{
389 addr = mb_correct_addr_and_bit(&bit, addr);
390 ext4_clear_bit_atomic(lock, bit, addr);
391}
392
393static inline int mb_find_next_zero_bit(void *addr, int max, int start) 381static inline int mb_find_next_zero_bit(void *addr, int max, int start)
394{ 382{
395 int fix = 0, ret, tmpmax; 383 int fix = 0, ret, tmpmax;
@@ -448,7 +436,7 @@ static void mb_free_blocks_double(struct inode *inode, struct ext4_buddy *e4b,
448 436
449 if (unlikely(e4b->bd_info->bb_bitmap == NULL)) 437 if (unlikely(e4b->bd_info->bb_bitmap == NULL))
450 return; 438 return;
451 BUG_ON(!ext4_is_group_locked(sb, e4b->bd_group)); 439 assert_spin_locked(ext4_group_lock_ptr(sb, e4b->bd_group));
452 for (i = 0; i < count; i++) { 440 for (i = 0; i < count; i++) {
453 if (!mb_test_bit(first + i, e4b->bd_info->bb_bitmap)) { 441 if (!mb_test_bit(first + i, e4b->bd_info->bb_bitmap)) {
454 ext4_fsblk_t blocknr; 442 ext4_fsblk_t blocknr;
@@ -472,7 +460,7 @@ static void mb_mark_used_double(struct ext4_buddy *e4b, int first, int count)
472 460
473 if (unlikely(e4b->bd_info->bb_bitmap == NULL)) 461 if (unlikely(e4b->bd_info->bb_bitmap == NULL))
474 return; 462 return;
475 BUG_ON(!ext4_is_group_locked(e4b->bd_sb, e4b->bd_group)); 463 assert_spin_locked(ext4_group_lock_ptr(e4b->bd_sb, e4b->bd_group));
476 for (i = 0; i < count; i++) { 464 for (i = 0; i < count; i++) {
477 BUG_ON(mb_test_bit(first + i, e4b->bd_info->bb_bitmap)); 465 BUG_ON(mb_test_bit(first + i, e4b->bd_info->bb_bitmap));
478 mb_set_bit(first + i, e4b->bd_info->bb_bitmap); 466 mb_set_bit(first + i, e4b->bd_info->bb_bitmap);
@@ -739,6 +727,7 @@ static void ext4_mb_generate_buddy(struct super_block *sb,
739 727
740static int ext4_mb_init_cache(struct page *page, char *incore) 728static int ext4_mb_init_cache(struct page *page, char *incore)
741{ 729{
730 ext4_group_t ngroups;
742 int blocksize; 731 int blocksize;
743 int blocks_per_page; 732 int blocks_per_page;
744 int groups_per_page; 733 int groups_per_page;
@@ -757,6 +746,7 @@ static int ext4_mb_init_cache(struct page *page, char *incore)
757 746
758 inode = page->mapping->host; 747 inode = page->mapping->host;
759 sb = inode->i_sb; 748 sb = inode->i_sb;
749 ngroups = ext4_get_groups_count(sb);
760 blocksize = 1 << inode->i_blkbits; 750 blocksize = 1 << inode->i_blkbits;
761 blocks_per_page = PAGE_CACHE_SIZE / blocksize; 751 blocks_per_page = PAGE_CACHE_SIZE / blocksize;
762 752
@@ -780,7 +770,7 @@ static int ext4_mb_init_cache(struct page *page, char *incore)
780 for (i = 0; i < groups_per_page; i++) { 770 for (i = 0; i < groups_per_page; i++) {
781 struct ext4_group_desc *desc; 771 struct ext4_group_desc *desc;
782 772
783 if (first_group + i >= EXT4_SB(sb)->s_groups_count) 773 if (first_group + i >= ngroups)
784 break; 774 break;
785 775
786 err = -EIO; 776 err = -EIO;
@@ -801,17 +791,17 @@ static int ext4_mb_init_cache(struct page *page, char *incore)
801 unlock_buffer(bh[i]); 791 unlock_buffer(bh[i]);
802 continue; 792 continue;
803 } 793 }
804 spin_lock(sb_bgl_lock(EXT4_SB(sb), first_group + i)); 794 ext4_lock_group(sb, first_group + i);
805 if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { 795 if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
806 ext4_init_block_bitmap(sb, bh[i], 796 ext4_init_block_bitmap(sb, bh[i],
807 first_group + i, desc); 797 first_group + i, desc);
808 set_bitmap_uptodate(bh[i]); 798 set_bitmap_uptodate(bh[i]);
809 set_buffer_uptodate(bh[i]); 799 set_buffer_uptodate(bh[i]);
810 spin_unlock(sb_bgl_lock(EXT4_SB(sb), first_group + i)); 800 ext4_unlock_group(sb, first_group + i);
811 unlock_buffer(bh[i]); 801 unlock_buffer(bh[i]);
812 continue; 802 continue;
813 } 803 }
814 spin_unlock(sb_bgl_lock(EXT4_SB(sb), first_group + i)); 804 ext4_unlock_group(sb, first_group + i);
815 if (buffer_uptodate(bh[i])) { 805 if (buffer_uptodate(bh[i])) {
816 /* 806 /*
817 * if not uninit if bh is uptodate, 807 * if not uninit if bh is uptodate,
@@ -852,7 +842,7 @@ static int ext4_mb_init_cache(struct page *page, char *incore)
852 struct ext4_group_info *grinfo; 842 struct ext4_group_info *grinfo;
853 843
854 group = (first_block + i) >> 1; 844 group = (first_block + i) >> 1;
855 if (group >= EXT4_SB(sb)->s_groups_count) 845 if (group >= ngroups)
856 break; 846 break;
857 847
858 /* 848 /*
@@ -1078,7 +1068,7 @@ static int mb_find_order_for_block(struct ext4_buddy *e4b, int block)
1078 return 0; 1068 return 0;
1079} 1069}
1080 1070
1081static void mb_clear_bits(spinlock_t *lock, void *bm, int cur, int len) 1071static void mb_clear_bits(void *bm, int cur, int len)
1082{ 1072{
1083 __u32 *addr; 1073 __u32 *addr;
1084 1074
@@ -1091,15 +1081,12 @@ static void mb_clear_bits(spinlock_t *lock, void *bm, int cur, int len)
1091 cur += 32; 1081 cur += 32;
1092 continue; 1082 continue;
1093 } 1083 }
1094 if (lock) 1084 mb_clear_bit(cur, bm);
1095 mb_clear_bit_atomic(lock, cur, bm);
1096 else
1097 mb_clear_bit(cur, bm);
1098 cur++; 1085 cur++;
1099 } 1086 }
1100} 1087}
1101 1088
1102static void mb_set_bits(spinlock_t *lock, void *bm, int cur, int len) 1089static void mb_set_bits(void *bm, int cur, int len)
1103{ 1090{
1104 __u32 *addr; 1091 __u32 *addr;
1105 1092
@@ -1112,10 +1099,7 @@ static void mb_set_bits(spinlock_t *lock, void *bm, int cur, int len)
1112 cur += 32; 1099 cur += 32;
1113 continue; 1100 continue;
1114 } 1101 }
1115 if (lock) 1102 mb_set_bit(cur, bm);
1116 mb_set_bit_atomic(lock, cur, bm);
1117 else
1118 mb_set_bit(cur, bm);
1119 cur++; 1103 cur++;
1120 } 1104 }
1121} 1105}
@@ -1131,7 +1115,7 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,
1131 struct super_block *sb = e4b->bd_sb; 1115 struct super_block *sb = e4b->bd_sb;
1132 1116
1133 BUG_ON(first + count > (sb->s_blocksize << 3)); 1117 BUG_ON(first + count > (sb->s_blocksize << 3));
1134 BUG_ON(!ext4_is_group_locked(sb, e4b->bd_group)); 1118 assert_spin_locked(ext4_group_lock_ptr(sb, e4b->bd_group));
1135 mb_check_buddy(e4b); 1119 mb_check_buddy(e4b);
1136 mb_free_blocks_double(inode, e4b, first, count); 1120 mb_free_blocks_double(inode, e4b, first, count);
1137 1121
@@ -1212,7 +1196,7 @@ static int mb_find_extent(struct ext4_buddy *e4b, int order, int block,
1212 int ord; 1196 int ord;
1213 void *buddy; 1197 void *buddy;
1214 1198
1215 BUG_ON(!ext4_is_group_locked(e4b->bd_sb, e4b->bd_group)); 1199 assert_spin_locked(ext4_group_lock_ptr(e4b->bd_sb, e4b->bd_group));
1216 BUG_ON(ex == NULL); 1200 BUG_ON(ex == NULL);
1217 1201
1218 buddy = mb_find_buddy(e4b, order, &max); 1202 buddy = mb_find_buddy(e4b, order, &max);
@@ -1276,7 +1260,7 @@ static int mb_mark_used(struct ext4_buddy *e4b, struct ext4_free_extent *ex)
1276 1260
1277 BUG_ON(start + len > (e4b->bd_sb->s_blocksize << 3)); 1261 BUG_ON(start + len > (e4b->bd_sb->s_blocksize << 3));
1278 BUG_ON(e4b->bd_group != ex->fe_group); 1262 BUG_ON(e4b->bd_group != ex->fe_group);
1279 BUG_ON(!ext4_is_group_locked(e4b->bd_sb, e4b->bd_group)); 1263 assert_spin_locked(ext4_group_lock_ptr(e4b->bd_sb, e4b->bd_group));
1280 mb_check_buddy(e4b); 1264 mb_check_buddy(e4b);
1281 mb_mark_used_double(e4b, start, len); 1265 mb_mark_used_double(e4b, start, len);
1282 1266
@@ -1330,8 +1314,7 @@ static int mb_mark_used(struct ext4_buddy *e4b, struct ext4_free_extent *ex)
1330 e4b->bd_info->bb_counters[ord]++; 1314 e4b->bd_info->bb_counters[ord]++;
1331 } 1315 }
1332 1316
1333 mb_set_bits(sb_bgl_lock(EXT4_SB(e4b->bd_sb), ex->fe_group), 1317 mb_set_bits(EXT4_MB_BITMAP(e4b), ex->fe_start, len0);
1334 EXT4_MB_BITMAP(e4b), ex->fe_start, len0);
1335 mb_check_buddy(e4b); 1318 mb_check_buddy(e4b);
1336 1319
1337 return ret; 1320 return ret;
@@ -1726,7 +1709,6 @@ static int ext4_mb_good_group(struct ext4_allocation_context *ac,
1726 unsigned free, fragments; 1709 unsigned free, fragments;
1727 unsigned i, bits; 1710 unsigned i, bits;
1728 int flex_size = ext4_flex_bg_size(EXT4_SB(ac->ac_sb)); 1711 int flex_size = ext4_flex_bg_size(EXT4_SB(ac->ac_sb));
1729 struct ext4_group_desc *desc;
1730 struct ext4_group_info *grp = ext4_get_group_info(ac->ac_sb, group); 1712 struct ext4_group_info *grp = ext4_get_group_info(ac->ac_sb, group);
1731 1713
1732 BUG_ON(cr < 0 || cr >= 4); 1714 BUG_ON(cr < 0 || cr >= 4);
@@ -1742,10 +1724,6 @@ static int ext4_mb_good_group(struct ext4_allocation_context *ac,
1742 switch (cr) { 1724 switch (cr) {
1743 case 0: 1725 case 0:
1744 BUG_ON(ac->ac_2order == 0); 1726 BUG_ON(ac->ac_2order == 0);
1745 /* If this group is uninitialized, skip it initially */
1746 desc = ext4_get_group_desc(ac->ac_sb, group, NULL);
1747 if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))
1748 return 0;
1749 1727
1750 /* Avoid using the first bg of a flexgroup for data files */ 1728 /* Avoid using the first bg of a flexgroup for data files */
1751 if ((ac->ac_flags & EXT4_MB_HINT_DATA) && 1729 if ((ac->ac_flags & EXT4_MB_HINT_DATA) &&
@@ -1788,6 +1766,7 @@ int ext4_mb_get_buddy_cache_lock(struct super_block *sb, ext4_group_t group)
1788 int block, pnum; 1766 int block, pnum;
1789 int blocks_per_page; 1767 int blocks_per_page;
1790 int groups_per_page; 1768 int groups_per_page;
1769 ext4_group_t ngroups = ext4_get_groups_count(sb);
1791 ext4_group_t first_group; 1770 ext4_group_t first_group;
1792 struct ext4_group_info *grp; 1771 struct ext4_group_info *grp;
1793 1772
@@ -1807,7 +1786,7 @@ int ext4_mb_get_buddy_cache_lock(struct super_block *sb, ext4_group_t group)
1807 /* read all groups the page covers into the cache */ 1786 /* read all groups the page covers into the cache */
1808 for (i = 0; i < groups_per_page; i++) { 1787 for (i = 0; i < groups_per_page; i++) {
1809 1788
1810 if ((first_group + i) >= EXT4_SB(sb)->s_groups_count) 1789 if ((first_group + i) >= ngroups)
1811 break; 1790 break;
1812 grp = ext4_get_group_info(sb, first_group + i); 1791 grp = ext4_get_group_info(sb, first_group + i);
1813 /* take all groups write allocation 1792 /* take all groups write allocation
@@ -1945,8 +1924,7 @@ err:
1945static noinline_for_stack int 1924static noinline_for_stack int
1946ext4_mb_regular_allocator(struct ext4_allocation_context *ac) 1925ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
1947{ 1926{
1948 ext4_group_t group; 1927 ext4_group_t ngroups, group, i;
1949 ext4_group_t i;
1950 int cr; 1928 int cr;
1951 int err = 0; 1929 int err = 0;
1952 int bsbits; 1930 int bsbits;
@@ -1957,6 +1935,7 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
1957 1935
1958 sb = ac->ac_sb; 1936 sb = ac->ac_sb;
1959 sbi = EXT4_SB(sb); 1937 sbi = EXT4_SB(sb);
1938 ngroups = ext4_get_groups_count(sb);
1960 BUG_ON(ac->ac_status == AC_STATUS_FOUND); 1939 BUG_ON(ac->ac_status == AC_STATUS_FOUND);
1961 1940
1962 /* first, try the goal */ 1941 /* first, try the goal */
@@ -2017,11 +1996,11 @@ repeat:
2017 */ 1996 */
2018 group = ac->ac_g_ex.fe_group; 1997 group = ac->ac_g_ex.fe_group;
2019 1998
2020 for (i = 0; i < EXT4_SB(sb)->s_groups_count; group++, i++) { 1999 for (i = 0; i < ngroups; group++, i++) {
2021 struct ext4_group_info *grp; 2000 struct ext4_group_info *grp;
2022 struct ext4_group_desc *desc; 2001 struct ext4_group_desc *desc;
2023 2002
2024 if (group == EXT4_SB(sb)->s_groups_count) 2003 if (group == ngroups)
2025 group = 0; 2004 group = 0;
2026 2005
2027 /* quick check to skip empty groups */ 2006 /* quick check to skip empty groups */
@@ -2064,9 +2043,7 @@ repeat:
2064 2043
2065 ac->ac_groups_scanned++; 2044 ac->ac_groups_scanned++;
2066 desc = ext4_get_group_desc(sb, group, NULL); 2045 desc = ext4_get_group_desc(sb, group, NULL);
2067 if (cr == 0 || (desc->bg_flags & 2046 if (cr == 0)
2068 cpu_to_le16(EXT4_BG_BLOCK_UNINIT) &&
2069 ac->ac_2order != 0))
2070 ext4_mb_simple_scan_group(ac, &e4b); 2047 ext4_mb_simple_scan_group(ac, &e4b);
2071 else if (cr == 1 && 2048 else if (cr == 1 &&
2072 ac->ac_g_ex.fe_len == sbi->s_stripe) 2049 ac->ac_g_ex.fe_len == sbi->s_stripe)
@@ -2315,12 +2292,10 @@ static struct file_operations ext4_mb_seq_history_fops = {
2315static void *ext4_mb_seq_groups_start(struct seq_file *seq, loff_t *pos) 2292static void *ext4_mb_seq_groups_start(struct seq_file *seq, loff_t *pos)
2316{ 2293{
2317 struct super_block *sb = seq->private; 2294 struct super_block *sb = seq->private;
2318 struct ext4_sb_info *sbi = EXT4_SB(sb);
2319 ext4_group_t group; 2295 ext4_group_t group;
2320 2296
2321 if (*pos < 0 || *pos >= sbi->s_groups_count) 2297 if (*pos < 0 || *pos >= ext4_get_groups_count(sb))
2322 return NULL; 2298 return NULL;
2323
2324 group = *pos + 1; 2299 group = *pos + 1;
2325 return (void *) ((unsigned long) group); 2300 return (void *) ((unsigned long) group);
2326} 2301}
@@ -2328,11 +2303,10 @@ static void *ext4_mb_seq_groups_start(struct seq_file *seq, loff_t *pos)
2328static void *ext4_mb_seq_groups_next(struct seq_file *seq, void *v, loff_t *pos) 2303static void *ext4_mb_seq_groups_next(struct seq_file *seq, void *v, loff_t *pos)
2329{ 2304{
2330 struct super_block *sb = seq->private; 2305 struct super_block *sb = seq->private;
2331 struct ext4_sb_info *sbi = EXT4_SB(sb);
2332 ext4_group_t group; 2306 ext4_group_t group;
2333 2307
2334 ++*pos; 2308 ++*pos;
2335 if (*pos < 0 || *pos >= sbi->s_groups_count) 2309 if (*pos < 0 || *pos >= ext4_get_groups_count(sb))
2336 return NULL; 2310 return NULL;
2337 group = *pos + 1; 2311 group = *pos + 1;
2338 return (void *) ((unsigned long) group); 2312 return (void *) ((unsigned long) group);
@@ -2420,7 +2394,8 @@ static void ext4_mb_history_release(struct super_block *sb)
2420 2394
2421 if (sbi->s_proc != NULL) { 2395 if (sbi->s_proc != NULL) {
2422 remove_proc_entry("mb_groups", sbi->s_proc); 2396 remove_proc_entry("mb_groups", sbi->s_proc);
2423 remove_proc_entry("mb_history", sbi->s_proc); 2397 if (sbi->s_mb_history_max)
2398 remove_proc_entry("mb_history", sbi->s_proc);
2424 } 2399 }
2425 kfree(sbi->s_mb_history); 2400 kfree(sbi->s_mb_history);
2426} 2401}
@@ -2431,17 +2406,17 @@ static void ext4_mb_history_init(struct super_block *sb)
2431 int i; 2406 int i;
2432 2407
2433 if (sbi->s_proc != NULL) { 2408 if (sbi->s_proc != NULL) {
2434 proc_create_data("mb_history", S_IRUGO, sbi->s_proc, 2409 if (sbi->s_mb_history_max)
2435 &ext4_mb_seq_history_fops, sb); 2410 proc_create_data("mb_history", S_IRUGO, sbi->s_proc,
2411 &ext4_mb_seq_history_fops, sb);
2436 proc_create_data("mb_groups", S_IRUGO, sbi->s_proc, 2412 proc_create_data("mb_groups", S_IRUGO, sbi->s_proc,
2437 &ext4_mb_seq_groups_fops, sb); 2413 &ext4_mb_seq_groups_fops, sb);
2438 } 2414 }
2439 2415
2440 sbi->s_mb_history_max = 1000;
2441 sbi->s_mb_history_cur = 0; 2416 sbi->s_mb_history_cur = 0;
2442 spin_lock_init(&sbi->s_mb_history_lock); 2417 spin_lock_init(&sbi->s_mb_history_lock);
2443 i = sbi->s_mb_history_max * sizeof(struct ext4_mb_history); 2418 i = sbi->s_mb_history_max * sizeof(struct ext4_mb_history);
2444 sbi->s_mb_history = kzalloc(i, GFP_KERNEL); 2419 sbi->s_mb_history = i ? kzalloc(i, GFP_KERNEL) : NULL;
2445 /* if we can't allocate history, then we simple won't use it */ 2420 /* if we can't allocate history, then we simple won't use it */
2446} 2421}
2447 2422
@@ -2451,7 +2426,7 @@ ext4_mb_store_history(struct ext4_allocation_context *ac)
2451 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb); 2426 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
2452 struct ext4_mb_history h; 2427 struct ext4_mb_history h;
2453 2428
2454 if (unlikely(sbi->s_mb_history == NULL)) 2429 if (sbi->s_mb_history == NULL)
2455 return; 2430 return;
2456 2431
2457 if (!(ac->ac_op & sbi->s_mb_history_filter)) 2432 if (!(ac->ac_op & sbi->s_mb_history_filter))
@@ -2587,6 +2562,7 @@ void ext4_mb_update_group_info(struct ext4_group_info *grp, ext4_grpblk_t add)
2587 2562
2588static int ext4_mb_init_backend(struct super_block *sb) 2563static int ext4_mb_init_backend(struct super_block *sb)
2589{ 2564{
2565 ext4_group_t ngroups = ext4_get_groups_count(sb);
2590 ext4_group_t i; 2566 ext4_group_t i;
2591 int metalen; 2567 int metalen;
2592 struct ext4_sb_info *sbi = EXT4_SB(sb); 2568 struct ext4_sb_info *sbi = EXT4_SB(sb);
@@ -2598,7 +2574,7 @@ static int ext4_mb_init_backend(struct super_block *sb)
2598 struct ext4_group_desc *desc; 2574 struct ext4_group_desc *desc;
2599 2575
2600 /* This is the number of blocks used by GDT */ 2576 /* This is the number of blocks used by GDT */
2601 num_meta_group_infos = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 2577 num_meta_group_infos = (ngroups + EXT4_DESC_PER_BLOCK(sb) -
2602 1) >> EXT4_DESC_PER_BLOCK_BITS(sb); 2578 1) >> EXT4_DESC_PER_BLOCK_BITS(sb);
2603 2579
2604 /* 2580 /*
@@ -2644,7 +2620,7 @@ static int ext4_mb_init_backend(struct super_block *sb)
2644 for (i = 0; i < num_meta_group_infos; i++) { 2620 for (i = 0; i < num_meta_group_infos; i++) {
2645 if ((i + 1) == num_meta_group_infos) 2621 if ((i + 1) == num_meta_group_infos)
2646 metalen = sizeof(*meta_group_info) * 2622 metalen = sizeof(*meta_group_info) *
2647 (sbi->s_groups_count - 2623 (ngroups -
2648 (i << EXT4_DESC_PER_BLOCK_BITS(sb))); 2624 (i << EXT4_DESC_PER_BLOCK_BITS(sb)));
2649 meta_group_info = kmalloc(metalen, GFP_KERNEL); 2625 meta_group_info = kmalloc(metalen, GFP_KERNEL);
2650 if (meta_group_info == NULL) { 2626 if (meta_group_info == NULL) {
@@ -2655,7 +2631,7 @@ static int ext4_mb_init_backend(struct super_block *sb)
2655 sbi->s_group_info[i] = meta_group_info; 2631 sbi->s_group_info[i] = meta_group_info;
2656 } 2632 }
2657 2633
2658 for (i = 0; i < sbi->s_groups_count; i++) { 2634 for (i = 0; i < ngroups; i++) {
2659 desc = ext4_get_group_desc(sb, i, NULL); 2635 desc = ext4_get_group_desc(sb, i, NULL);
2660 if (desc == NULL) { 2636 if (desc == NULL) {
2661 printk(KERN_ERR 2637 printk(KERN_ERR
@@ -2761,7 +2737,7 @@ int ext4_mb_init(struct super_block *sb, int needs_recovery)
2761 return 0; 2737 return 0;
2762} 2738}
2763 2739
2764/* need to called with ext4 group lock (ext4_lock_group) */ 2740/* need to called with the ext4 group lock held */
2765static void ext4_mb_cleanup_pa(struct ext4_group_info *grp) 2741static void ext4_mb_cleanup_pa(struct ext4_group_info *grp)
2766{ 2742{
2767 struct ext4_prealloc_space *pa; 2743 struct ext4_prealloc_space *pa;
@@ -2781,13 +2757,14 @@ static void ext4_mb_cleanup_pa(struct ext4_group_info *grp)
2781 2757
2782int ext4_mb_release(struct super_block *sb) 2758int ext4_mb_release(struct super_block *sb)
2783{ 2759{
2760 ext4_group_t ngroups = ext4_get_groups_count(sb);
2784 ext4_group_t i; 2761 ext4_group_t i;
2785 int num_meta_group_infos; 2762 int num_meta_group_infos;
2786 struct ext4_group_info *grinfo; 2763 struct ext4_group_info *grinfo;
2787 struct ext4_sb_info *sbi = EXT4_SB(sb); 2764 struct ext4_sb_info *sbi = EXT4_SB(sb);
2788 2765
2789 if (sbi->s_group_info) { 2766 if (sbi->s_group_info) {
2790 for (i = 0; i < sbi->s_groups_count; i++) { 2767 for (i = 0; i < ngroups; i++) {
2791 grinfo = ext4_get_group_info(sb, i); 2768 grinfo = ext4_get_group_info(sb, i);
2792#ifdef DOUBLE_CHECK 2769#ifdef DOUBLE_CHECK
2793 kfree(grinfo->bb_bitmap); 2770 kfree(grinfo->bb_bitmap);
@@ -2797,7 +2774,7 @@ int ext4_mb_release(struct super_block *sb)
2797 ext4_unlock_group(sb, i); 2774 ext4_unlock_group(sb, i);
2798 kfree(grinfo); 2775 kfree(grinfo);
2799 } 2776 }
2800 num_meta_group_infos = (sbi->s_groups_count + 2777 num_meta_group_infos = (ngroups +
2801 EXT4_DESC_PER_BLOCK(sb) - 1) >> 2778 EXT4_DESC_PER_BLOCK(sb) - 1) >>
2802 EXT4_DESC_PER_BLOCK_BITS(sb); 2779 EXT4_DESC_PER_BLOCK_BITS(sb);
2803 for (i = 0; i < num_meta_group_infos; i++) 2780 for (i = 0; i < num_meta_group_infos; i++)
@@ -2984,27 +2961,25 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
2984 + le32_to_cpu(es->s_first_data_block); 2961 + le32_to_cpu(es->s_first_data_block);
2985 2962
2986 len = ac->ac_b_ex.fe_len; 2963 len = ac->ac_b_ex.fe_len;
2987 if (in_range(ext4_block_bitmap(sb, gdp), block, len) || 2964 if (!ext4_data_block_valid(sbi, block, len)) {
2988 in_range(ext4_inode_bitmap(sb, gdp), block, len) ||
2989 in_range(block, ext4_inode_table(sb, gdp),
2990 EXT4_SB(sb)->s_itb_per_group) ||
2991 in_range(block + len - 1, ext4_inode_table(sb, gdp),
2992 EXT4_SB(sb)->s_itb_per_group)) {
2993 ext4_error(sb, __func__, 2965 ext4_error(sb, __func__,
2994 "Allocating block %llu in system zone of %d group\n", 2966 "Allocating blocks %llu-%llu which overlap "
2995 block, ac->ac_b_ex.fe_group); 2967 "fs metadata\n", block, block+len);
2996 /* File system mounted not to panic on error 2968 /* File system mounted not to panic on error
2997 * Fix the bitmap and repeat the block allocation 2969 * Fix the bitmap and repeat the block allocation
2998 * We leak some of the blocks here. 2970 * We leak some of the blocks here.
2999 */ 2971 */
3000 mb_set_bits(sb_bgl_lock(sbi, ac->ac_b_ex.fe_group), 2972 ext4_lock_group(sb, ac->ac_b_ex.fe_group);
3001 bitmap_bh->b_data, ac->ac_b_ex.fe_start, 2973 mb_set_bits(bitmap_bh->b_data, ac->ac_b_ex.fe_start,
3002 ac->ac_b_ex.fe_len); 2974 ac->ac_b_ex.fe_len);
2975 ext4_unlock_group(sb, ac->ac_b_ex.fe_group);
3003 err = ext4_handle_dirty_metadata(handle, NULL, bitmap_bh); 2976 err = ext4_handle_dirty_metadata(handle, NULL, bitmap_bh);
3004 if (!err) 2977 if (!err)
3005 err = -EAGAIN; 2978 err = -EAGAIN;
3006 goto out_err; 2979 goto out_err;
3007 } 2980 }
2981
2982 ext4_lock_group(sb, ac->ac_b_ex.fe_group);
3008#ifdef AGGRESSIVE_CHECK 2983#ifdef AGGRESSIVE_CHECK
3009 { 2984 {
3010 int i; 2985 int i;
@@ -3014,9 +2989,7 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
3014 } 2989 }
3015 } 2990 }
3016#endif 2991#endif
3017 spin_lock(sb_bgl_lock(sbi, ac->ac_b_ex.fe_group)); 2992 mb_set_bits(bitmap_bh->b_data, ac->ac_b_ex.fe_start,ac->ac_b_ex.fe_len);
3018 mb_set_bits(NULL, bitmap_bh->b_data,
3019 ac->ac_b_ex.fe_start, ac->ac_b_ex.fe_len);
3020 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) { 2993 if (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
3021 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT); 2994 gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT);
3022 ext4_free_blks_set(sb, gdp, 2995 ext4_free_blks_set(sb, gdp,
@@ -3026,7 +2999,8 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
3026 len = ext4_free_blks_count(sb, gdp) - ac->ac_b_ex.fe_len; 2999 len = ext4_free_blks_count(sb, gdp) - ac->ac_b_ex.fe_len;
3027 ext4_free_blks_set(sb, gdp, len); 3000 ext4_free_blks_set(sb, gdp, len);
3028 gdp->bg_checksum = ext4_group_desc_csum(sbi, ac->ac_b_ex.fe_group, gdp); 3001 gdp->bg_checksum = ext4_group_desc_csum(sbi, ac->ac_b_ex.fe_group, gdp);
3029 spin_unlock(sb_bgl_lock(sbi, ac->ac_b_ex.fe_group)); 3002
3003 ext4_unlock_group(sb, ac->ac_b_ex.fe_group);
3030 percpu_counter_sub(&sbi->s_freeblocks_counter, ac->ac_b_ex.fe_len); 3004 percpu_counter_sub(&sbi->s_freeblocks_counter, ac->ac_b_ex.fe_len);
3031 /* 3005 /*
3032 * Now reduce the dirty block count also. Should not go negative 3006 * Now reduce the dirty block count also. Should not go negative
@@ -3459,7 +3433,7 @@ ext4_mb_use_preallocated(struct ext4_allocation_context *ac)
3459 * the function goes through all block freed in the group 3433 * the function goes through all block freed in the group
3460 * but not yet committed and marks them used in in-core bitmap. 3434 * but not yet committed and marks them used in in-core bitmap.
3461 * buddy must be generated from this bitmap 3435 * buddy must be generated from this bitmap
3462 * Need to be called with ext4 group lock (ext4_lock_group) 3436 * Need to be called with the ext4 group lock held
3463 */ 3437 */
3464static void ext4_mb_generate_from_freelist(struct super_block *sb, void *bitmap, 3438static void ext4_mb_generate_from_freelist(struct super_block *sb, void *bitmap,
3465 ext4_group_t group) 3439 ext4_group_t group)
@@ -3473,9 +3447,7 @@ static void ext4_mb_generate_from_freelist(struct super_block *sb, void *bitmap,
3473 3447
3474 while (n) { 3448 while (n) {
3475 entry = rb_entry(n, struct ext4_free_data, node); 3449 entry = rb_entry(n, struct ext4_free_data, node);
3476 mb_set_bits(sb_bgl_lock(EXT4_SB(sb), group), 3450 mb_set_bits(bitmap, entry->start_blk, entry->count);
3477 bitmap, entry->start_blk,
3478 entry->count);
3479 n = rb_next(n); 3451 n = rb_next(n);
3480 } 3452 }
3481 return; 3453 return;
@@ -3484,7 +3456,7 @@ static void ext4_mb_generate_from_freelist(struct super_block *sb, void *bitmap,
3484/* 3456/*
3485 * the function goes through all preallocation in this group and marks them 3457 * the function goes through all preallocation in this group and marks them
3486 * used in in-core bitmap. buddy must be generated from this bitmap 3458 * used in in-core bitmap. buddy must be generated from this bitmap
3487 * Need to be called with ext4 group lock (ext4_lock_group) 3459 * Need to be called with ext4 group lock held
3488 */ 3460 */
3489static void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap, 3461static void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
3490 ext4_group_t group) 3462 ext4_group_t group)
@@ -3516,8 +3488,7 @@ static void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap,
3516 if (unlikely(len == 0)) 3488 if (unlikely(len == 0))
3517 continue; 3489 continue;
3518 BUG_ON(groupnr != group); 3490 BUG_ON(groupnr != group);
3519 mb_set_bits(sb_bgl_lock(EXT4_SB(sb), group), 3491 mb_set_bits(bitmap, start, len);
3520 bitmap, start, len);
3521 preallocated += len; 3492 preallocated += len;
3522 count++; 3493 count++;
3523 } 3494 }
@@ -4121,7 +4092,7 @@ static void ext4_mb_return_to_preallocation(struct inode *inode,
4121static void ext4_mb_show_ac(struct ext4_allocation_context *ac) 4092static void ext4_mb_show_ac(struct ext4_allocation_context *ac)
4122{ 4093{
4123 struct super_block *sb = ac->ac_sb; 4094 struct super_block *sb = ac->ac_sb;
4124 ext4_group_t i; 4095 ext4_group_t ngroups, i;
4125 4096
4126 printk(KERN_ERR "EXT4-fs: Can't allocate:" 4097 printk(KERN_ERR "EXT4-fs: Can't allocate:"
4127 " Allocation context details:\n"); 4098 " Allocation context details:\n");
@@ -4145,7 +4116,8 @@ static void ext4_mb_show_ac(struct ext4_allocation_context *ac)
4145 printk(KERN_ERR "EXT4-fs: %lu scanned, %d found\n", ac->ac_ex_scanned, 4116 printk(KERN_ERR "EXT4-fs: %lu scanned, %d found\n", ac->ac_ex_scanned,
4146 ac->ac_found); 4117 ac->ac_found);
4147 printk(KERN_ERR "EXT4-fs: groups: \n"); 4118 printk(KERN_ERR "EXT4-fs: groups: \n");
4148 for (i = 0; i < EXT4_SB(sb)->s_groups_count; i++) { 4119 ngroups = ext4_get_groups_count(sb);
4120 for (i = 0; i < ngroups; i++) {
4149 struct ext4_group_info *grp = ext4_get_group_info(sb, i); 4121 struct ext4_group_info *grp = ext4_get_group_info(sb, i);
4150 struct ext4_prealloc_space *pa; 4122 struct ext4_prealloc_space *pa;
4151 ext4_grpblk_t start; 4123 ext4_grpblk_t start;
@@ -4469,13 +4441,13 @@ static int ext4_mb_release_context(struct ext4_allocation_context *ac)
4469 4441
4470static int ext4_mb_discard_preallocations(struct super_block *sb, int needed) 4442static int ext4_mb_discard_preallocations(struct super_block *sb, int needed)
4471{ 4443{
4472 ext4_group_t i; 4444 ext4_group_t i, ngroups = ext4_get_groups_count(sb);
4473 int ret; 4445 int ret;
4474 int freed = 0; 4446 int freed = 0;
4475 4447
4476 trace_mark(ext4_mb_discard_preallocations, "dev %s needed %d", 4448 trace_mark(ext4_mb_discard_preallocations, "dev %s needed %d",
4477 sb->s_id, needed); 4449 sb->s_id, needed);
4478 for (i = 0; i < EXT4_SB(sb)->s_groups_count && needed > 0; i++) { 4450 for (i = 0; i < ngroups && needed > 0; i++) {
4479 ret = ext4_mb_discard_group_preallocations(sb, i, needed); 4451 ret = ext4_mb_discard_group_preallocations(sb, i, needed);
4480 freed += ret; 4452 freed += ret;
4481 needed -= ret; 4453 needed -= ret;
@@ -4859,29 +4831,25 @@ do_more:
4859 new_entry->group = block_group; 4831 new_entry->group = block_group;
4860 new_entry->count = count; 4832 new_entry->count = count;
4861 new_entry->t_tid = handle->h_transaction->t_tid; 4833 new_entry->t_tid = handle->h_transaction->t_tid;
4834
4862 ext4_lock_group(sb, block_group); 4835 ext4_lock_group(sb, block_group);
4863 mb_clear_bits(sb_bgl_lock(sbi, block_group), bitmap_bh->b_data, 4836 mb_clear_bits(bitmap_bh->b_data, bit, count);
4864 bit, count);
4865 ext4_mb_free_metadata(handle, &e4b, new_entry); 4837 ext4_mb_free_metadata(handle, &e4b, new_entry);
4866 ext4_unlock_group(sb, block_group);
4867 } else { 4838 } else {
4868 ext4_lock_group(sb, block_group);
4869 /* need to update group_info->bb_free and bitmap 4839 /* need to update group_info->bb_free and bitmap
4870 * with group lock held. generate_buddy look at 4840 * with group lock held. generate_buddy look at
4871 * them with group lock_held 4841 * them with group lock_held
4872 */ 4842 */
4873 mb_clear_bits(sb_bgl_lock(sbi, block_group), bitmap_bh->b_data, 4843 ext4_lock_group(sb, block_group);
4874 bit, count); 4844 mb_clear_bits(bitmap_bh->b_data, bit, count);
4875 mb_free_blocks(inode, &e4b, bit, count); 4845 mb_free_blocks(inode, &e4b, bit, count);
4876 ext4_mb_return_to_preallocation(inode, &e4b, block, count); 4846 ext4_mb_return_to_preallocation(inode, &e4b, block, count);
4877 ext4_unlock_group(sb, block_group);
4878 } 4847 }
4879 4848
4880 spin_lock(sb_bgl_lock(sbi, block_group));
4881 ret = ext4_free_blks_count(sb, gdp) + count; 4849 ret = ext4_free_blks_count(sb, gdp) + count;
4882 ext4_free_blks_set(sb, gdp, ret); 4850 ext4_free_blks_set(sb, gdp, ret);
4883 gdp->bg_checksum = ext4_group_desc_csum(sbi, block_group, gdp); 4851 gdp->bg_checksum = ext4_group_desc_csum(sbi, block_group, gdp);
4884 spin_unlock(sb_bgl_lock(sbi, block_group)); 4852 ext4_unlock_group(sb, block_group);
4885 percpu_counter_add(&sbi->s_freeblocks_counter, count); 4853 percpu_counter_add(&sbi->s_freeblocks_counter, count);
4886 4854
4887 if (sbi->s_log_groups_per_flex) { 4855 if (sbi->s_log_groups_per_flex) {
diff --git a/fs/ext4/mballoc.h b/fs/ext4/mballoc.h
index dd9e6cd5f6cf..75e34f69215b 100644
--- a/fs/ext4/mballoc.h
+++ b/fs/ext4/mballoc.h
@@ -23,7 +23,6 @@
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include "ext4_jbd2.h" 24#include "ext4_jbd2.h"
25#include "ext4.h" 25#include "ext4.h"
26#include "group.h"
27 26
28/* 27/*
29 * with AGGRESSIVE_CHECK allocator runs consistency checks over 28 * with AGGRESSIVE_CHECK allocator runs consistency checks over
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 22098e1cd085..07eb6649e4fa 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -37,7 +37,6 @@
37#include "ext4.h" 37#include "ext4.h"
38#include "ext4_jbd2.h" 38#include "ext4_jbd2.h"
39 39
40#include "namei.h"
41#include "xattr.h" 40#include "xattr.h"
42#include "acl.h" 41#include "acl.h"
43 42
@@ -750,7 +749,7 @@ static int dx_make_map(struct ext4_dir_entry_2 *de, unsigned blocksize,
750 ext4fs_dirhash(de->name, de->name_len, &h); 749 ext4fs_dirhash(de->name, de->name_len, &h);
751 map_tail--; 750 map_tail--;
752 map_tail->hash = h.hash; 751 map_tail->hash = h.hash;
753 map_tail->offs = (u16) ((char *) de - base); 752 map_tail->offs = ((char *) de - base)>>2;
754 map_tail->size = le16_to_cpu(de->rec_len); 753 map_tail->size = le16_to_cpu(de->rec_len);
755 count++; 754 count++;
756 cond_resched(); 755 cond_resched();
@@ -1148,7 +1147,8 @@ dx_move_dirents(char *from, char *to, struct dx_map_entry *map, int count,
1148 unsigned rec_len = 0; 1147 unsigned rec_len = 0;
1149 1148
1150 while (count--) { 1149 while (count--) {
1151 struct ext4_dir_entry_2 *de = (struct ext4_dir_entry_2 *) (from + map->offs); 1150 struct ext4_dir_entry_2 *de = (struct ext4_dir_entry_2 *)
1151 (from + (map->offs<<2));
1152 rec_len = EXT4_DIR_REC_LEN(de->name_len); 1152 rec_len = EXT4_DIR_REC_LEN(de->name_len);
1153 memcpy (to, de, rec_len); 1153 memcpy (to, de, rec_len);
1154 ((struct ext4_dir_entry_2 *) to)->rec_len = 1154 ((struct ext4_dir_entry_2 *) to)->rec_len =
@@ -1997,7 +1997,7 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)
1997 if (!ext4_handle_valid(handle)) 1997 if (!ext4_handle_valid(handle))
1998 return 0; 1998 return 0;
1999 1999
2000 lock_super(sb); 2000 mutex_lock(&EXT4_SB(sb)->s_orphan_lock);
2001 if (!list_empty(&EXT4_I(inode)->i_orphan)) 2001 if (!list_empty(&EXT4_I(inode)->i_orphan))
2002 goto out_unlock; 2002 goto out_unlock;
2003 2003
@@ -2006,9 +2006,13 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)
2006 2006
2007 /* @@@ FIXME: Observation from aviro: 2007 /* @@@ FIXME: Observation from aviro:
2008 * I think I can trigger J_ASSERT in ext4_orphan_add(). We block 2008 * I think I can trigger J_ASSERT in ext4_orphan_add(). We block
2009 * here (on lock_super()), so race with ext4_link() which might bump 2009 * here (on s_orphan_lock), so race with ext4_link() which might bump
2010 * ->i_nlink. For, say it, character device. Not a regular file, 2010 * ->i_nlink. For, say it, character device. Not a regular file,
2011 * not a directory, not a symlink and ->i_nlink > 0. 2011 * not a directory, not a symlink and ->i_nlink > 0.
2012 *
2013 * tytso, 4/25/2009: I'm not sure how that could happen;
2014 * shouldn't the fs core protect us from these sort of
2015 * unlink()/link() races?
2012 */ 2016 */
2013 J_ASSERT((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || 2017 J_ASSERT((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
2014 S_ISLNK(inode->i_mode)) || inode->i_nlink == 0); 2018 S_ISLNK(inode->i_mode)) || inode->i_nlink == 0);
@@ -2045,7 +2049,7 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)
2045 jbd_debug(4, "orphan inode %lu will point to %d\n", 2049 jbd_debug(4, "orphan inode %lu will point to %d\n",
2046 inode->i_ino, NEXT_ORPHAN(inode)); 2050 inode->i_ino, NEXT_ORPHAN(inode));
2047out_unlock: 2051out_unlock:
2048 unlock_super(sb); 2052 mutex_unlock(&EXT4_SB(sb)->s_orphan_lock);
2049 ext4_std_error(inode->i_sb, err); 2053 ext4_std_error(inode->i_sb, err);
2050 return err; 2054 return err;
2051} 2055}
@@ -2066,11 +2070,9 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode)
2066 if (!ext4_handle_valid(handle)) 2070 if (!ext4_handle_valid(handle))
2067 return 0; 2071 return 0;
2068 2072
2069 lock_super(inode->i_sb); 2073 mutex_lock(&EXT4_SB(inode->i_sb)->s_orphan_lock);
2070 if (list_empty(&ei->i_orphan)) { 2074 if (list_empty(&ei->i_orphan))
2071 unlock_super(inode->i_sb); 2075 goto out;
2072 return 0;
2073 }
2074 2076
2075 ino_next = NEXT_ORPHAN(inode); 2077 ino_next = NEXT_ORPHAN(inode);
2076 prev = ei->i_orphan.prev; 2078 prev = ei->i_orphan.prev;
@@ -2120,7 +2122,7 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode)
2120out_err: 2122out_err:
2121 ext4_std_error(inode->i_sb, err); 2123 ext4_std_error(inode->i_sb, err);
2122out: 2124out:
2123 unlock_super(inode->i_sb); 2125 mutex_unlock(&EXT4_SB(inode->i_sb)->s_orphan_lock);
2124 return err; 2126 return err;
2125 2127
2126out_brelse: 2128out_brelse:
@@ -2533,6 +2535,7 @@ const struct inode_operations ext4_dir_inode_operations = {
2533 .removexattr = generic_removexattr, 2535 .removexattr = generic_removexattr,
2534#endif 2536#endif
2535 .permission = ext4_permission, 2537 .permission = ext4_permission,
2538 .fiemap = ext4_fiemap,
2536}; 2539};
2537 2540
2538const struct inode_operations ext4_special_inode_operations = { 2541const struct inode_operations ext4_special_inode_operations = {
diff --git a/fs/ext4/namei.h b/fs/ext4/namei.h
deleted file mode 100644
index 5e4dfff36a00..000000000000
--- a/fs/ext4/namei.h
+++ /dev/null
@@ -1,8 +0,0 @@
1/* linux/fs/ext4/namei.h
2 *
3 * Copyright (C) 2005 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 *
6*/
7
8extern struct dentry *ext4_get_parent(struct dentry *child);
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 546c7dd869e1..27eb289eea37 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -15,7 +15,6 @@
15#include <linux/slab.h> 15#include <linux/slab.h>
16 16
17#include "ext4_jbd2.h" 17#include "ext4_jbd2.h"
18#include "group.h"
19 18
20#define outside(b, first, last) ((b) < (first) || (b) >= (last)) 19#define outside(b, first, last) ((b) < (first) || (b) >= (last))
21#define inside(b, first, last) ((b) >= (first) && (b) < (last)) 20#define inside(b, first, last) ((b) >= (first) && (b) < (last))
@@ -193,7 +192,7 @@ static int setup_new_group_blocks(struct super_block *sb,
193 if (IS_ERR(handle)) 192 if (IS_ERR(handle))
194 return PTR_ERR(handle); 193 return PTR_ERR(handle);
195 194
196 lock_super(sb); 195 mutex_lock(&sbi->s_resize_lock);
197 if (input->group != sbi->s_groups_count) { 196 if (input->group != sbi->s_groups_count) {
198 err = -EBUSY; 197 err = -EBUSY;
199 goto exit_journal; 198 goto exit_journal;
@@ -302,7 +301,7 @@ exit_bh:
302 brelse(bh); 301 brelse(bh);
303 302
304exit_journal: 303exit_journal:
305 unlock_super(sb); 304 mutex_unlock(&sbi->s_resize_lock);
306 if ((err2 = ext4_journal_stop(handle)) && !err) 305 if ((err2 = ext4_journal_stop(handle)) && !err)
307 err = err2; 306 err = err2;
308 307
@@ -643,11 +642,12 @@ exit_free:
643 * important part is that the new block and inode counts are in the backup 642 * important part is that the new block and inode counts are in the backup
644 * superblocks, and the location of the new group metadata in the GDT backups. 643 * superblocks, and the location of the new group metadata in the GDT backups.
645 * 644 *
646 * We do not need lock_super() for this, because these blocks are not 645 * We do not need take the s_resize_lock for this, because these
647 * otherwise touched by the filesystem code when it is mounted. We don't 646 * blocks are not otherwise touched by the filesystem code when it is
648 * need to worry about last changing from sbi->s_groups_count, because the 647 * mounted. We don't need to worry about last changing from
649 * worst that can happen is that we do not copy the full number of backups 648 * sbi->s_groups_count, because the worst that can happen is that we
650 * at this time. The resize which changed s_groups_count will backup again. 649 * do not copy the full number of backups at this time. The resize
650 * which changed s_groups_count will backup again.
651 */ 651 */
652static void update_backups(struct super_block *sb, 652static void update_backups(struct super_block *sb,
653 int blk_off, char *data, int size) 653 int blk_off, char *data, int size)
@@ -809,7 +809,7 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
809 goto exit_put; 809 goto exit_put;
810 } 810 }
811 811
812 lock_super(sb); 812 mutex_lock(&sbi->s_resize_lock);
813 if (input->group != sbi->s_groups_count) { 813 if (input->group != sbi->s_groups_count) {
814 ext4_warning(sb, __func__, 814 ext4_warning(sb, __func__,
815 "multiple resizers run on filesystem!"); 815 "multiple resizers run on filesystem!");
@@ -840,7 +840,7 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
840 /* 840 /*
841 * OK, now we've set up the new group. Time to make it active. 841 * OK, now we've set up the new group. Time to make it active.
842 * 842 *
843 * Current kernels don't lock all allocations via lock_super(), 843 * We do not lock all allocations via s_resize_lock
844 * so we have to be safe wrt. concurrent accesses the group 844 * so we have to be safe wrt. concurrent accesses the group
845 * data. So we need to be careful to set all of the relevant 845 * data. So we need to be careful to set all of the relevant
846 * group descriptor data etc. *before* we enable the group. 846 * group descriptor data etc. *before* we enable the group.
@@ -900,12 +900,12 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
900 * 900 *
901 * The precise rules we use are: 901 * The precise rules we use are:
902 * 902 *
903 * * Writers of s_groups_count *must* hold lock_super 903 * * Writers of s_groups_count *must* hold s_resize_lock
904 * AND 904 * AND
905 * * Writers must perform a smp_wmb() after updating all dependent 905 * * Writers must perform a smp_wmb() after updating all dependent
906 * data and before modifying the groups count 906 * data and before modifying the groups count
907 * 907 *
908 * * Readers must hold lock_super() over the access 908 * * Readers must hold s_resize_lock over the access
909 * OR 909 * OR
910 * * Readers must perform an smp_rmb() after reading the groups count 910 * * Readers must perform an smp_rmb() after reading the groups count
911 * and before reading any dependent data. 911 * and before reading any dependent data.
@@ -948,7 +948,7 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
948 sb->s_dirt = 1; 948 sb->s_dirt = 1;
949 949
950exit_journal: 950exit_journal:
951 unlock_super(sb); 951 mutex_unlock(&sbi->s_resize_lock);
952 if ((err2 = ext4_journal_stop(handle)) && !err) 952 if ((err2 = ext4_journal_stop(handle)) && !err)
953 err = err2; 953 err = err2;
954 if (!err) { 954 if (!err) {
@@ -986,7 +986,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
986 986
987 /* We don't need to worry about locking wrt other resizers just 987 /* We don't need to worry about locking wrt other resizers just
988 * yet: we're going to revalidate es->s_blocks_count after 988 * yet: we're going to revalidate es->s_blocks_count after
989 * taking lock_super() below. */ 989 * taking the s_resize_lock below. */
990 o_blocks_count = ext4_blocks_count(es); 990 o_blocks_count = ext4_blocks_count(es);
991 o_groups_count = EXT4_SB(sb)->s_groups_count; 991 o_groups_count = EXT4_SB(sb)->s_groups_count;
992 992
@@ -1056,11 +1056,11 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
1056 goto exit_put; 1056 goto exit_put;
1057 } 1057 }
1058 1058
1059 lock_super(sb); 1059 mutex_lock(&EXT4_SB(sb)->s_resize_lock);
1060 if (o_blocks_count != ext4_blocks_count(es)) { 1060 if (o_blocks_count != ext4_blocks_count(es)) {
1061 ext4_warning(sb, __func__, 1061 ext4_warning(sb, __func__,
1062 "multiple resizers run on filesystem!"); 1062 "multiple resizers run on filesystem!");
1063 unlock_super(sb); 1063 mutex_unlock(&EXT4_SB(sb)->s_resize_lock);
1064 ext4_journal_stop(handle); 1064 ext4_journal_stop(handle);
1065 err = -EBUSY; 1065 err = -EBUSY;
1066 goto exit_put; 1066 goto exit_put;
@@ -1070,14 +1070,14 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
1070 EXT4_SB(sb)->s_sbh))) { 1070 EXT4_SB(sb)->s_sbh))) {
1071 ext4_warning(sb, __func__, 1071 ext4_warning(sb, __func__,
1072 "error %d on journal write access", err); 1072 "error %d on journal write access", err);
1073 unlock_super(sb); 1073 mutex_unlock(&EXT4_SB(sb)->s_resize_lock);
1074 ext4_journal_stop(handle); 1074 ext4_journal_stop(handle);
1075 goto exit_put; 1075 goto exit_put;
1076 } 1076 }
1077 ext4_blocks_count_set(es, o_blocks_count + add); 1077 ext4_blocks_count_set(es, o_blocks_count + add);
1078 ext4_handle_dirty_metadata(handle, NULL, EXT4_SB(sb)->s_sbh); 1078 ext4_handle_dirty_metadata(handle, NULL, EXT4_SB(sb)->s_sbh);
1079 sb->s_dirt = 1; 1079 sb->s_dirt = 1;
1080 unlock_super(sb); 1080 mutex_unlock(&EXT4_SB(sb)->s_resize_lock);
1081 ext4_debug("freeing blocks %llu through %llu\n", o_blocks_count, 1081 ext4_debug("freeing blocks %llu through %llu\n", o_blocks_count,
1082 o_blocks_count + add); 1082 o_blocks_count + add);
1083 /* We add the blocks to the bitmap and set the group need init bit */ 1083 /* We add the blocks to the bitmap and set the group need init bit */
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 2958f4e6f222..f016707597a7 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -20,6 +20,7 @@
20#include <linux/string.h> 20#include <linux/string.h>
21#include <linux/fs.h> 21#include <linux/fs.h>
22#include <linux/time.h> 22#include <linux/time.h>
23#include <linux/vmalloc.h>
23#include <linux/jbd2.h> 24#include <linux/jbd2.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
25#include <linux/init.h> 26#include <linux/init.h>
@@ -45,16 +46,20 @@
45#include "ext4_jbd2.h" 46#include "ext4_jbd2.h"
46#include "xattr.h" 47#include "xattr.h"
47#include "acl.h" 48#include "acl.h"
48#include "namei.h" 49
49#include "group.h" 50static int default_mb_history_length = 1000;
51
52module_param_named(default_mb_history_length, default_mb_history_length,
53 int, 0644);
54MODULE_PARM_DESC(default_mb_history_length,
55 "Default number of entries saved for mb_history");
50 56
51struct proc_dir_entry *ext4_proc_root; 57struct proc_dir_entry *ext4_proc_root;
52static struct kset *ext4_kset; 58static struct kset *ext4_kset;
53 59
54static int ext4_load_journal(struct super_block *, struct ext4_super_block *, 60static int ext4_load_journal(struct super_block *, struct ext4_super_block *,
55 unsigned long journal_devnum); 61 unsigned long journal_devnum);
56static int ext4_commit_super(struct super_block *sb, 62static int ext4_commit_super(struct super_block *sb, int sync);
57 struct ext4_super_block *es, int sync);
58static void ext4_mark_recovery_complete(struct super_block *sb, 63static void ext4_mark_recovery_complete(struct super_block *sb,
59 struct ext4_super_block *es); 64 struct ext4_super_block *es);
60static void ext4_clear_journal_err(struct super_block *sb, 65static void ext4_clear_journal_err(struct super_block *sb,
@@ -74,7 +79,7 @@ ext4_fsblk_t ext4_block_bitmap(struct super_block *sb,
74{ 79{
75 return le32_to_cpu(bg->bg_block_bitmap_lo) | 80 return le32_to_cpu(bg->bg_block_bitmap_lo) |
76 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 81 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
77 (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0); 82 (ext4_fsblk_t)le32_to_cpu(bg->bg_block_bitmap_hi) << 32 : 0);
78} 83}
79 84
80ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, 85ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
@@ -82,7 +87,7 @@ ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
82{ 87{
83 return le32_to_cpu(bg->bg_inode_bitmap_lo) | 88 return le32_to_cpu(bg->bg_inode_bitmap_lo) |
84 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 89 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
85 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0); 90 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_bitmap_hi) << 32 : 0);
86} 91}
87 92
88ext4_fsblk_t ext4_inode_table(struct super_block *sb, 93ext4_fsblk_t ext4_inode_table(struct super_block *sb,
@@ -90,7 +95,7 @@ ext4_fsblk_t ext4_inode_table(struct super_block *sb,
90{ 95{
91 return le32_to_cpu(bg->bg_inode_table_lo) | 96 return le32_to_cpu(bg->bg_inode_table_lo) |
92 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 97 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
93 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0); 98 (ext4_fsblk_t)le32_to_cpu(bg->bg_inode_table_hi) << 32 : 0);
94} 99}
95 100
96__u32 ext4_free_blks_count(struct super_block *sb, 101__u32 ext4_free_blks_count(struct super_block *sb,
@@ -98,7 +103,7 @@ __u32 ext4_free_blks_count(struct super_block *sb,
98{ 103{
99 return le16_to_cpu(bg->bg_free_blocks_count_lo) | 104 return le16_to_cpu(bg->bg_free_blocks_count_lo) |
100 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 105 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
101 (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0); 106 (__u32)le16_to_cpu(bg->bg_free_blocks_count_hi) << 16 : 0);
102} 107}
103 108
104__u32 ext4_free_inodes_count(struct super_block *sb, 109__u32 ext4_free_inodes_count(struct super_block *sb,
@@ -106,7 +111,7 @@ __u32 ext4_free_inodes_count(struct super_block *sb,
106{ 111{
107 return le16_to_cpu(bg->bg_free_inodes_count_lo) | 112 return le16_to_cpu(bg->bg_free_inodes_count_lo) |
108 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 113 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
109 (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0); 114 (__u32)le16_to_cpu(bg->bg_free_inodes_count_hi) << 16 : 0);
110} 115}
111 116
112__u32 ext4_used_dirs_count(struct super_block *sb, 117__u32 ext4_used_dirs_count(struct super_block *sb,
@@ -114,7 +119,7 @@ __u32 ext4_used_dirs_count(struct super_block *sb,
114{ 119{
115 return le16_to_cpu(bg->bg_used_dirs_count_lo) | 120 return le16_to_cpu(bg->bg_used_dirs_count_lo) |
116 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 121 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
117 (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0); 122 (__u32)le16_to_cpu(bg->bg_used_dirs_count_hi) << 16 : 0);
118} 123}
119 124
120__u32 ext4_itable_unused_count(struct super_block *sb, 125__u32 ext4_itable_unused_count(struct super_block *sb,
@@ -122,7 +127,7 @@ __u32 ext4_itable_unused_count(struct super_block *sb,
122{ 127{
123 return le16_to_cpu(bg->bg_itable_unused_lo) | 128 return le16_to_cpu(bg->bg_itable_unused_lo) |
124 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ? 129 (EXT4_DESC_SIZE(sb) >= EXT4_MIN_DESC_SIZE_64BIT ?
125 (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0); 130 (__u32)le16_to_cpu(bg->bg_itable_unused_hi) << 16 : 0);
126} 131}
127 132
128void ext4_block_bitmap_set(struct super_block *sb, 133void ext4_block_bitmap_set(struct super_block *sb,
@@ -202,8 +207,7 @@ handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
202 journal = EXT4_SB(sb)->s_journal; 207 journal = EXT4_SB(sb)->s_journal;
203 if (journal) { 208 if (journal) {
204 if (is_journal_aborted(journal)) { 209 if (is_journal_aborted(journal)) {
205 ext4_abort(sb, __func__, 210 ext4_abort(sb, __func__, "Detected aborted journal");
206 "Detected aborted journal");
207 return ERR_PTR(-EROFS); 211 return ERR_PTR(-EROFS);
208 } 212 }
209 return jbd2_journal_start(journal, nblocks); 213 return jbd2_journal_start(journal, nblocks);
@@ -302,10 +306,10 @@ static void ext4_handle_error(struct super_block *sb)
302 jbd2_journal_abort(journal, -EIO); 306 jbd2_journal_abort(journal, -EIO);
303 } 307 }
304 if (test_opt(sb, ERRORS_RO)) { 308 if (test_opt(sb, ERRORS_RO)) {
305 printk(KERN_CRIT "Remounting filesystem read-only\n"); 309 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
306 sb->s_flags |= MS_RDONLY; 310 sb->s_flags |= MS_RDONLY;
307 } 311 }
308 ext4_commit_super(sb, es, 1); 312 ext4_commit_super(sb, 1);
309 if (test_opt(sb, ERRORS_PANIC)) 313 if (test_opt(sb, ERRORS_PANIC))
310 panic("EXT4-fs (device %s): panic forced after error\n", 314 panic("EXT4-fs (device %s): panic forced after error\n",
311 sb->s_id); 315 sb->s_id);
@@ -395,8 +399,6 @@ void ext4_abort(struct super_block *sb, const char *function,
395{ 399{
396 va_list args; 400 va_list args;
397 401
398 printk(KERN_CRIT "ext4_abort called.\n");
399
400 va_start(args, fmt); 402 va_start(args, fmt);
401 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); 403 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function);
402 vprintk(fmt, args); 404 vprintk(fmt, args);
@@ -409,7 +411,7 @@ void ext4_abort(struct super_block *sb, const char *function,
409 if (sb->s_flags & MS_RDONLY) 411 if (sb->s_flags & MS_RDONLY)
410 return; 412 return;
411 413
412 printk(KERN_CRIT "Remounting filesystem read-only\n"); 414 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
413 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 415 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
414 sb->s_flags |= MS_RDONLY; 416 sb->s_flags |= MS_RDONLY;
415 EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT; 417 EXT4_SB(sb)->s_mount_opt |= EXT4_MOUNT_ABORT;
@@ -417,6 +419,18 @@ void ext4_abort(struct super_block *sb, const char *function,
417 jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO); 419 jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
418} 420}
419 421
422void ext4_msg (struct super_block * sb, const char *prefix,
423 const char *fmt, ...)
424{
425 va_list args;
426
427 va_start(args, fmt);
428 printk("%sEXT4-fs (%s): ", prefix, sb->s_id);
429 vprintk(fmt, args);
430 printk("\n");
431 va_end(args);
432}
433
420void ext4_warning(struct super_block *sb, const char *function, 434void ext4_warning(struct super_block *sb, const char *function,
421 const char *fmt, ...) 435 const char *fmt, ...)
422{ 436{
@@ -431,7 +445,7 @@ void ext4_warning(struct super_block *sb, const char *function,
431} 445}
432 446
433void ext4_grp_locked_error(struct super_block *sb, ext4_group_t grp, 447void ext4_grp_locked_error(struct super_block *sb, ext4_group_t grp,
434 const char *function, const char *fmt, ...) 448 const char *function, const char *fmt, ...)
435__releases(bitlock) 449__releases(bitlock)
436__acquires(bitlock) 450__acquires(bitlock)
437{ 451{
@@ -447,7 +461,7 @@ __acquires(bitlock)
447 if (test_opt(sb, ERRORS_CONT)) { 461 if (test_opt(sb, ERRORS_CONT)) {
448 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 462 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
449 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 463 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
450 ext4_commit_super(sb, es, 0); 464 ext4_commit_super(sb, 0);
451 return; 465 return;
452 } 466 }
453 ext4_unlock_group(sb, grp); 467 ext4_unlock_group(sb, grp);
@@ -467,7 +481,6 @@ __acquires(bitlock)
467 return; 481 return;
468} 482}
469 483
470
471void ext4_update_dynamic_rev(struct super_block *sb) 484void ext4_update_dynamic_rev(struct super_block *sb)
472{ 485{
473 struct ext4_super_block *es = EXT4_SB(sb)->s_es; 486 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
@@ -496,7 +509,7 @@ void ext4_update_dynamic_rev(struct super_block *sb)
496/* 509/*
497 * Open the external journal device 510 * Open the external journal device
498 */ 511 */
499static struct block_device *ext4_blkdev_get(dev_t dev) 512static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)
500{ 513{
501 struct block_device *bdev; 514 struct block_device *bdev;
502 char b[BDEVNAME_SIZE]; 515 char b[BDEVNAME_SIZE];
@@ -507,7 +520,7 @@ static struct block_device *ext4_blkdev_get(dev_t dev)
507 return bdev; 520 return bdev;
508 521
509fail: 522fail:
510 printk(KERN_ERR "EXT4-fs: failed to open journal device %s: %ld\n", 523 ext4_msg(sb, KERN_ERR, "failed to open journal device %s: %ld",
511 __bdevname(dev, b), PTR_ERR(bdev)); 524 __bdevname(dev, b), PTR_ERR(bdev));
512 return NULL; 525 return NULL;
513} 526}
@@ -543,8 +556,8 @@ static void dump_orphan_list(struct super_block *sb, struct ext4_sb_info *sbi)
543{ 556{
544 struct list_head *l; 557 struct list_head *l;
545 558
546 printk(KERN_ERR "sb orphan head is %d\n", 559 ext4_msg(sb, KERN_ERR, "sb orphan head is %d",
547 le32_to_cpu(sbi->s_es->s_last_orphan)); 560 le32_to_cpu(sbi->s_es->s_last_orphan));
548 561
549 printk(KERN_ERR "sb_info orphan list:\n"); 562 printk(KERN_ERR "sb_info orphan list:\n");
550 list_for_each(l, &sbi->s_orphan) { 563 list_for_each(l, &sbi->s_orphan) {
@@ -563,6 +576,7 @@ static void ext4_put_super(struct super_block *sb)
563 struct ext4_super_block *es = sbi->s_es; 576 struct ext4_super_block *es = sbi->s_es;
564 int i, err; 577 int i, err;
565 578
579 ext4_release_system_zone(sb);
566 ext4_mb_release(sb); 580 ext4_mb_release(sb);
567 ext4_ext_release(sb); 581 ext4_ext_release(sb);
568 ext4_xattr_put_super(sb); 582 ext4_xattr_put_super(sb);
@@ -576,7 +590,7 @@ static void ext4_put_super(struct super_block *sb)
576 if (!(sb->s_flags & MS_RDONLY)) { 590 if (!(sb->s_flags & MS_RDONLY)) {
577 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 591 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
578 es->s_state = cpu_to_le16(sbi->s_mount_state); 592 es->s_state = cpu_to_le16(sbi->s_mount_state);
579 ext4_commit_super(sb, es, 1); 593 ext4_commit_super(sb, 1);
580 } 594 }
581 if (sbi->s_proc) { 595 if (sbi->s_proc) {
582 remove_proc_entry(sb->s_id, ext4_proc_root); 596 remove_proc_entry(sb->s_id, ext4_proc_root);
@@ -586,7 +600,10 @@ static void ext4_put_super(struct super_block *sb)
586 for (i = 0; i < sbi->s_gdb_count; i++) 600 for (i = 0; i < sbi->s_gdb_count; i++)
587 brelse(sbi->s_group_desc[i]); 601 brelse(sbi->s_group_desc[i]);
588 kfree(sbi->s_group_desc); 602 kfree(sbi->s_group_desc);
589 kfree(sbi->s_flex_groups); 603 if (is_vmalloc_addr(sbi->s_flex_groups))
604 vfree(sbi->s_flex_groups);
605 else
606 kfree(sbi->s_flex_groups);
590 percpu_counter_destroy(&sbi->s_freeblocks_counter); 607 percpu_counter_destroy(&sbi->s_freeblocks_counter);
591 percpu_counter_destroy(&sbi->s_freeinodes_counter); 608 percpu_counter_destroy(&sbi->s_freeinodes_counter);
592 percpu_counter_destroy(&sbi->s_dirs_counter); 609 percpu_counter_destroy(&sbi->s_dirs_counter);
@@ -629,7 +646,6 @@ static void ext4_put_super(struct super_block *sb)
629 lock_kernel(); 646 lock_kernel();
630 kfree(sbi->s_blockgroup_lock); 647 kfree(sbi->s_blockgroup_lock);
631 kfree(sbi); 648 kfree(sbi);
632 return;
633} 649}
634 650
635static struct kmem_cache *ext4_inode_cachep; 651static struct kmem_cache *ext4_inode_cachep;
@@ -644,6 +660,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
644 ei = kmem_cache_alloc(ext4_inode_cachep, GFP_NOFS); 660 ei = kmem_cache_alloc(ext4_inode_cachep, GFP_NOFS);
645 if (!ei) 661 if (!ei)
646 return NULL; 662 return NULL;
663
647#ifdef CONFIG_EXT4_FS_POSIX_ACL 664#ifdef CONFIG_EXT4_FS_POSIX_ACL
648 ei->i_acl = EXT4_ACL_NOT_CACHED; 665 ei->i_acl = EXT4_ACL_NOT_CACHED;
649 ei->i_default_acl = EXT4_ACL_NOT_CACHED; 666 ei->i_default_acl = EXT4_ACL_NOT_CACHED;
@@ -664,14 +681,16 @@ static struct inode *ext4_alloc_inode(struct super_block *sb)
664 ei->i_allocated_meta_blocks = 0; 681 ei->i_allocated_meta_blocks = 0;
665 ei->i_delalloc_reserved_flag = 0; 682 ei->i_delalloc_reserved_flag = 0;
666 spin_lock_init(&(ei->i_block_reservation_lock)); 683 spin_lock_init(&(ei->i_block_reservation_lock));
684
667 return &ei->vfs_inode; 685 return &ei->vfs_inode;
668} 686}
669 687
670static void ext4_destroy_inode(struct inode *inode) 688static void ext4_destroy_inode(struct inode *inode)
671{ 689{
672 if (!list_empty(&(EXT4_I(inode)->i_orphan))) { 690 if (!list_empty(&(EXT4_I(inode)->i_orphan))) {
673 printk("EXT4 Inode %p: orphan list check failed!\n", 691 ext4_msg(inode->i_sb, KERN_ERR,
674 EXT4_I(inode)); 692 "Inode %lu (%p): orphan list check failed!",
693 inode->i_ino, EXT4_I(inode));
675 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4, 694 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_ADDRESS, 16, 4,
676 EXT4_I(inode), sizeof(struct ext4_inode_info), 695 EXT4_I(inode), sizeof(struct ext4_inode_info),
677 true); 696 true);
@@ -870,12 +889,12 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
870 seq_puts(seq, ",noauto_da_alloc"); 889 seq_puts(seq, ",noauto_da_alloc");
871 890
872 ext4_show_quota_options(seq, sb); 891 ext4_show_quota_options(seq, sb);
892
873 return 0; 893 return 0;
874} 894}
875 895
876
877static struct inode *ext4_nfs_get_inode(struct super_block *sb, 896static struct inode *ext4_nfs_get_inode(struct super_block *sb,
878 u64 ino, u32 generation) 897 u64 ino, u32 generation)
879{ 898{
880 struct inode *inode; 899 struct inode *inode;
881 900
@@ -904,14 +923,14 @@ static struct inode *ext4_nfs_get_inode(struct super_block *sb,
904} 923}
905 924
906static struct dentry *ext4_fh_to_dentry(struct super_block *sb, struct fid *fid, 925static struct dentry *ext4_fh_to_dentry(struct super_block *sb, struct fid *fid,
907 int fh_len, int fh_type) 926 int fh_len, int fh_type)
908{ 927{
909 return generic_fh_to_dentry(sb, fid, fh_len, fh_type, 928 return generic_fh_to_dentry(sb, fid, fh_len, fh_type,
910 ext4_nfs_get_inode); 929 ext4_nfs_get_inode);
911} 930}
912 931
913static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid, 932static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid,
914 int fh_len, int fh_type) 933 int fh_len, int fh_type)
915{ 934{
916 return generic_fh_to_parent(sb, fid, fh_len, fh_type, 935 return generic_fh_to_parent(sb, fid, fh_len, fh_type,
917 ext4_nfs_get_inode); 936 ext4_nfs_get_inode);
@@ -923,7 +942,8 @@ static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid,
923 * which would prevent try_to_free_buffers() from freeing them, we must use 942 * which would prevent try_to_free_buffers() from freeing them, we must use
924 * jbd2 layer's try_to_free_buffers() function to release them. 943 * jbd2 layer's try_to_free_buffers() function to release them.
925 */ 944 */
926static int bdev_try_to_free_page(struct super_block *sb, struct page *page, gfp_t wait) 945static int bdev_try_to_free_page(struct super_block *sb, struct page *page,
946 gfp_t wait)
927{ 947{
928 journal_t *journal = EXT4_SB(sb)->s_journal; 948 journal_t *journal = EXT4_SB(sb)->s_journal;
929 949
@@ -992,7 +1012,6 @@ static const struct super_operations ext4_sops = {
992 .dirty_inode = ext4_dirty_inode, 1012 .dirty_inode = ext4_dirty_inode,
993 .delete_inode = ext4_delete_inode, 1013 .delete_inode = ext4_delete_inode,
994 .put_super = ext4_put_super, 1014 .put_super = ext4_put_super,
995 .write_super = ext4_write_super,
996 .sync_fs = ext4_sync_fs, 1015 .sync_fs = ext4_sync_fs,
997 .freeze_fs = ext4_freeze, 1016 .freeze_fs = ext4_freeze,
998 .unfreeze_fs = ext4_unfreeze, 1017 .unfreeze_fs = ext4_unfreeze,
@@ -1007,6 +1026,25 @@ static const struct super_operations ext4_sops = {
1007 .bdev_try_to_free_page = bdev_try_to_free_page, 1026 .bdev_try_to_free_page = bdev_try_to_free_page,
1008}; 1027};
1009 1028
1029static const struct super_operations ext4_nojournal_sops = {
1030 .alloc_inode = ext4_alloc_inode,
1031 .destroy_inode = ext4_destroy_inode,
1032 .write_inode = ext4_write_inode,
1033 .dirty_inode = ext4_dirty_inode,
1034 .delete_inode = ext4_delete_inode,
1035 .write_super = ext4_write_super,
1036 .put_super = ext4_put_super,
1037 .statfs = ext4_statfs,
1038 .remount_fs = ext4_remount,
1039 .clear_inode = ext4_clear_inode,
1040 .show_options = ext4_show_options,
1041#ifdef CONFIG_QUOTA
1042 .quota_read = ext4_quota_read,
1043 .quota_write = ext4_quota_write,
1044#endif
1045 .bdev_try_to_free_page = bdev_try_to_free_page,
1046};
1047
1010static const struct export_operations ext4_export_ops = { 1048static const struct export_operations ext4_export_ops = {
1011 .fh_to_dentry = ext4_fh_to_dentry, 1049 .fh_to_dentry = ext4_fh_to_dentry,
1012 .fh_to_parent = ext4_fh_to_parent, 1050 .fh_to_parent = ext4_fh_to_parent,
@@ -1023,12 +1061,13 @@ enum {
1023 Opt_journal_update, Opt_journal_dev, 1061 Opt_journal_update, Opt_journal_dev,
1024 Opt_journal_checksum, Opt_journal_async_commit, 1062 Opt_journal_checksum, Opt_journal_async_commit,
1025 Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, 1063 Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
1026 Opt_data_err_abort, Opt_data_err_ignore, 1064 Opt_data_err_abort, Opt_data_err_ignore, Opt_mb_history_length,
1027 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, 1065 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
1028 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota, 1066 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
1029 Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err, Opt_resize, 1067 Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err, Opt_resize,
1030 Opt_usrquota, Opt_grpquota, Opt_i_version, 1068 Opt_usrquota, Opt_grpquota, Opt_i_version,
1031 Opt_stripe, Opt_delalloc, Opt_nodelalloc, 1069 Opt_stripe, Opt_delalloc, Opt_nodelalloc,
1070 Opt_block_validity, Opt_noblock_validity,
1032 Opt_inode_readahead_blks, Opt_journal_ioprio 1071 Opt_inode_readahead_blks, Opt_journal_ioprio
1033}; 1072};
1034 1073
@@ -1069,6 +1108,7 @@ static const match_table_t tokens = {
1069 {Opt_data_writeback, "data=writeback"}, 1108 {Opt_data_writeback, "data=writeback"},
1070 {Opt_data_err_abort, "data_err=abort"}, 1109 {Opt_data_err_abort, "data_err=abort"},
1071 {Opt_data_err_ignore, "data_err=ignore"}, 1110 {Opt_data_err_ignore, "data_err=ignore"},
1111 {Opt_mb_history_length, "mb_history_length=%u"},
1072 {Opt_offusrjquota, "usrjquota="}, 1112 {Opt_offusrjquota, "usrjquota="},
1073 {Opt_usrjquota, "usrjquota=%s"}, 1113 {Opt_usrjquota, "usrjquota=%s"},
1074 {Opt_offgrpjquota, "grpjquota="}, 1114 {Opt_offgrpjquota, "grpjquota="},
@@ -1087,6 +1127,8 @@ static const match_table_t tokens = {
1087 {Opt_resize, "resize"}, 1127 {Opt_resize, "resize"},
1088 {Opt_delalloc, "delalloc"}, 1128 {Opt_delalloc, "delalloc"},
1089 {Opt_nodelalloc, "nodelalloc"}, 1129 {Opt_nodelalloc, "nodelalloc"},
1130 {Opt_block_validity, "block_validity"},
1131 {Opt_noblock_validity, "noblock_validity"},
1090 {Opt_inode_readahead_blks, "inode_readahead_blks=%u"}, 1132 {Opt_inode_readahead_blks, "inode_readahead_blks=%u"},
1091 {Opt_journal_ioprio, "journal_ioprio=%u"}, 1133 {Opt_journal_ioprio, "journal_ioprio=%u"},
1092 {Opt_auto_da_alloc, "auto_da_alloc=%u"}, 1134 {Opt_auto_da_alloc, "auto_da_alloc=%u"},
@@ -1102,8 +1144,9 @@ static ext4_fsblk_t get_sb_block(void **data)
1102 1144
1103 if (!options || strncmp(options, "sb=", 3) != 0) 1145 if (!options || strncmp(options, "sb=", 3) != 0)
1104 return 1; /* Default location */ 1146 return 1; /* Default location */
1147
1105 options += 3; 1148 options += 3;
1106 /*todo: use simple_strtoll with >32bit ext4 */ 1149 /* TODO: use simple_strtoll with >32bit ext4 */
1107 sb_block = simple_strtoul(options, &options, 0); 1150 sb_block = simple_strtoul(options, &options, 0);
1108 if (*options && *options != ',') { 1151 if (*options && *options != ',') {
1109 printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n", 1152 printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n",
@@ -1113,6 +1156,7 @@ static ext4_fsblk_t get_sb_block(void **data)
1113 if (*options == ',') 1156 if (*options == ',')
1114 options++; 1157 options++;
1115 *data = (void *) options; 1158 *data = (void *) options;
1159
1116 return sb_block; 1160 return sb_block;
1117} 1161}
1118 1162
@@ -1206,8 +1250,7 @@ static int parse_options(char *options, struct super_block *sb,
1206#else 1250#else
1207 case Opt_user_xattr: 1251 case Opt_user_xattr:
1208 case Opt_nouser_xattr: 1252 case Opt_nouser_xattr:
1209 printk(KERN_ERR "EXT4 (no)user_xattr options " 1253 ext4_msg(sb, KERN_ERR, "(no)user_xattr options not supported");
1210 "not supported\n");
1211 break; 1254 break;
1212#endif 1255#endif
1213#ifdef CONFIG_EXT4_FS_POSIX_ACL 1256#ifdef CONFIG_EXT4_FS_POSIX_ACL
@@ -1220,8 +1263,7 @@ static int parse_options(char *options, struct super_block *sb,
1220#else 1263#else
1221 case Opt_acl: 1264 case Opt_acl:
1222 case Opt_noacl: 1265 case Opt_noacl:
1223 printk(KERN_ERR "EXT4 (no)acl options " 1266 ext4_msg(sb, KERN_ERR, "(no)acl options not supported");
1224 "not supported\n");
1225 break; 1267 break;
1226#endif 1268#endif
1227 case Opt_journal_update: 1269 case Opt_journal_update:
@@ -1231,16 +1273,16 @@ static int parse_options(char *options, struct super_block *sb,
1231 user to specify an existing inode to be the 1273 user to specify an existing inode to be the
1232 journal file. */ 1274 journal file. */
1233 if (is_remount) { 1275 if (is_remount) {
1234 printk(KERN_ERR "EXT4-fs: cannot specify " 1276 ext4_msg(sb, KERN_ERR,
1235 "journal on remount\n"); 1277 "Cannot specify journal on remount");
1236 return 0; 1278 return 0;
1237 } 1279 }
1238 set_opt(sbi->s_mount_opt, UPDATE_JOURNAL); 1280 set_opt(sbi->s_mount_opt, UPDATE_JOURNAL);
1239 break; 1281 break;
1240 case Opt_journal_dev: 1282 case Opt_journal_dev:
1241 if (is_remount) { 1283 if (is_remount) {
1242 printk(KERN_ERR "EXT4-fs: cannot specify " 1284 ext4_msg(sb, KERN_ERR,
1243 "journal on remount\n"); 1285 "Cannot specify journal on remount");
1244 return 0; 1286 return 0;
1245 } 1287 }
1246 if (match_int(&args[0], &option)) 1288 if (match_int(&args[0], &option))
@@ -1294,9 +1336,8 @@ static int parse_options(char *options, struct super_block *sb,
1294 if (is_remount) { 1336 if (is_remount) {
1295 if ((sbi->s_mount_opt & EXT4_MOUNT_DATA_FLAGS) 1337 if ((sbi->s_mount_opt & EXT4_MOUNT_DATA_FLAGS)
1296 != data_opt) { 1338 != data_opt) {
1297 printk(KERN_ERR 1339 ext4_msg(sb, KERN_ERR,
1298 "EXT4-fs: cannot change data " 1340 "Cannot change data mode on remount");
1299 "mode on remount\n");
1300 return 0; 1341 return 0;
1301 } 1342 }
1302 } else { 1343 } else {
@@ -1310,6 +1351,13 @@ static int parse_options(char *options, struct super_block *sb,
1310 case Opt_data_err_ignore: 1351 case Opt_data_err_ignore:
1311 clear_opt(sbi->s_mount_opt, DATA_ERR_ABORT); 1352 clear_opt(sbi->s_mount_opt, DATA_ERR_ABORT);
1312 break; 1353 break;
1354 case Opt_mb_history_length:
1355 if (match_int(&args[0], &option))
1356 return 0;
1357 if (option < 0)
1358 return 0;
1359 sbi->s_mb_history_max = option;
1360 break;
1313#ifdef CONFIG_QUOTA 1361#ifdef CONFIG_QUOTA
1314 case Opt_usrjquota: 1362 case Opt_usrjquota:
1315 qtype = USRQUOTA; 1363 qtype = USRQUOTA;
@@ -1319,31 +1367,31 @@ static int parse_options(char *options, struct super_block *sb,
1319set_qf_name: 1367set_qf_name:
1320 if (sb_any_quota_loaded(sb) && 1368 if (sb_any_quota_loaded(sb) &&
1321 !sbi->s_qf_names[qtype]) { 1369 !sbi->s_qf_names[qtype]) {
1322 printk(KERN_ERR 1370 ext4_msg(sb, KERN_ERR,
1323 "EXT4-fs: Cannot change journaled " 1371 "Cannot change journaled "
1324 "quota options when quota turned on.\n"); 1372 "quota options when quota turned on");
1325 return 0; 1373 return 0;
1326 } 1374 }
1327 qname = match_strdup(&args[0]); 1375 qname = match_strdup(&args[0]);
1328 if (!qname) { 1376 if (!qname) {
1329 printk(KERN_ERR 1377 ext4_msg(sb, KERN_ERR,
1330 "EXT4-fs: not enough memory for " 1378 "Not enough memory for "
1331 "storing quotafile name.\n"); 1379 "storing quotafile name");
1332 return 0; 1380 return 0;
1333 } 1381 }
1334 if (sbi->s_qf_names[qtype] && 1382 if (sbi->s_qf_names[qtype] &&
1335 strcmp(sbi->s_qf_names[qtype], qname)) { 1383 strcmp(sbi->s_qf_names[qtype], qname)) {
1336 printk(KERN_ERR 1384 ext4_msg(sb, KERN_ERR,
1337 "EXT4-fs: %s quota file already " 1385 "%s quota file already "
1338 "specified.\n", QTYPE2NAME(qtype)); 1386 "specified", QTYPE2NAME(qtype));
1339 kfree(qname); 1387 kfree(qname);
1340 return 0; 1388 return 0;
1341 } 1389 }
1342 sbi->s_qf_names[qtype] = qname; 1390 sbi->s_qf_names[qtype] = qname;
1343 if (strchr(sbi->s_qf_names[qtype], '/')) { 1391 if (strchr(sbi->s_qf_names[qtype], '/')) {
1344 printk(KERN_ERR 1392 ext4_msg(sb, KERN_ERR,
1345 "EXT4-fs: quotafile must be on " 1393 "quotafile must be on "
1346 "filesystem root.\n"); 1394 "filesystem root");
1347 kfree(sbi->s_qf_names[qtype]); 1395 kfree(sbi->s_qf_names[qtype]);
1348 sbi->s_qf_names[qtype] = NULL; 1396 sbi->s_qf_names[qtype] = NULL;
1349 return 0; 1397 return 0;
@@ -1358,9 +1406,9 @@ set_qf_name:
1358clear_qf_name: 1406clear_qf_name:
1359 if (sb_any_quota_loaded(sb) && 1407 if (sb_any_quota_loaded(sb) &&
1360 sbi->s_qf_names[qtype]) { 1408 sbi->s_qf_names[qtype]) {
1361 printk(KERN_ERR "EXT4-fs: Cannot change " 1409 ext4_msg(sb, KERN_ERR, "Cannot change "
1362 "journaled quota options when " 1410 "journaled quota options when "
1363 "quota turned on.\n"); 1411 "quota turned on");
1364 return 0; 1412 return 0;
1365 } 1413 }
1366 /* 1414 /*
@@ -1377,9 +1425,9 @@ clear_qf_name:
1377set_qf_format: 1425set_qf_format:
1378 if (sb_any_quota_loaded(sb) && 1426 if (sb_any_quota_loaded(sb) &&
1379 sbi->s_jquota_fmt != qfmt) { 1427 sbi->s_jquota_fmt != qfmt) {
1380 printk(KERN_ERR "EXT4-fs: Cannot change " 1428 ext4_msg(sb, KERN_ERR, "Cannot change "
1381 "journaled quota options when " 1429 "journaled quota options when "
1382 "quota turned on.\n"); 1430 "quota turned on");
1383 return 0; 1431 return 0;
1384 } 1432 }
1385 sbi->s_jquota_fmt = qfmt; 1433 sbi->s_jquota_fmt = qfmt;
@@ -1395,8 +1443,8 @@ set_qf_format:
1395 break; 1443 break;
1396 case Opt_noquota: 1444 case Opt_noquota:
1397 if (sb_any_quota_loaded(sb)) { 1445 if (sb_any_quota_loaded(sb)) {
1398 printk(KERN_ERR "EXT4-fs: Cannot change quota " 1446 ext4_msg(sb, KERN_ERR, "Cannot change quota "
1399 "options when quota turned on.\n"); 1447 "options when quota turned on");
1400 return 0; 1448 return 0;
1401 } 1449 }
1402 clear_opt(sbi->s_mount_opt, QUOTA); 1450 clear_opt(sbi->s_mount_opt, QUOTA);
@@ -1407,8 +1455,8 @@ set_qf_format:
1407 case Opt_quota: 1455 case Opt_quota:
1408 case Opt_usrquota: 1456 case Opt_usrquota:
1409 case Opt_grpquota: 1457 case Opt_grpquota:
1410 printk(KERN_ERR 1458 ext4_msg(sb, KERN_ERR,
1411 "EXT4-fs: quota options not supported.\n"); 1459 "quota options not supported");
1412 break; 1460 break;
1413 case Opt_usrjquota: 1461 case Opt_usrjquota:
1414 case Opt_grpjquota: 1462 case Opt_grpjquota:
@@ -1416,9 +1464,8 @@ set_qf_format:
1416 case Opt_offgrpjquota: 1464 case Opt_offgrpjquota:
1417 case Opt_jqfmt_vfsold: 1465 case Opt_jqfmt_vfsold:
1418 case Opt_jqfmt_vfsv0: 1466 case Opt_jqfmt_vfsv0:
1419 printk(KERN_ERR 1467 ext4_msg(sb, KERN_ERR,
1420 "EXT4-fs: journaled quota options not " 1468 "journaled quota options not supported");
1421 "supported.\n");
1422 break; 1469 break;
1423 case Opt_noquota: 1470 case Opt_noquota:
1424 break; 1471 break;
@@ -1443,8 +1490,9 @@ set_qf_format:
1443 break; 1490 break;
1444 case Opt_resize: 1491 case Opt_resize:
1445 if (!is_remount) { 1492 if (!is_remount) {
1446 printk("EXT4-fs: resize option only available " 1493 ext4_msg(sb, KERN_ERR,
1447 "for remount\n"); 1494 "resize option only available "
1495 "for remount");
1448 return 0; 1496 return 0;
1449 } 1497 }
1450 if (match_int(&args[0], &option) != 0) 1498 if (match_int(&args[0], &option) != 0)
@@ -1474,14 +1522,21 @@ set_qf_format:
1474 case Opt_delalloc: 1522 case Opt_delalloc:
1475 set_opt(sbi->s_mount_opt, DELALLOC); 1523 set_opt(sbi->s_mount_opt, DELALLOC);
1476 break; 1524 break;
1525 case Opt_block_validity:
1526 set_opt(sbi->s_mount_opt, BLOCK_VALIDITY);
1527 break;
1528 case Opt_noblock_validity:
1529 clear_opt(sbi->s_mount_opt, BLOCK_VALIDITY);
1530 break;
1477 case Opt_inode_readahead_blks: 1531 case Opt_inode_readahead_blks:
1478 if (match_int(&args[0], &option)) 1532 if (match_int(&args[0], &option))
1479 return 0; 1533 return 0;
1480 if (option < 0 || option > (1 << 30)) 1534 if (option < 0 || option > (1 << 30))
1481 return 0; 1535 return 0;
1482 if (option & (option - 1)) { 1536 if (!is_power_of_2(option)) {
1483 printk(KERN_ERR "EXT4-fs: inode_readahead_blks" 1537 ext4_msg(sb, KERN_ERR,
1484 " must be a power of 2\n"); 1538 "EXT4-fs: inode_readahead_blks"
1539 " must be a power of 2");
1485 return 0; 1540 return 0;
1486 } 1541 }
1487 sbi->s_inode_readahead_blks = option; 1542 sbi->s_inode_readahead_blks = option;
@@ -1508,9 +1563,9 @@ set_qf_format:
1508 set_opt(sbi->s_mount_opt,NO_AUTO_DA_ALLOC); 1563 set_opt(sbi->s_mount_opt,NO_AUTO_DA_ALLOC);
1509 break; 1564 break;
1510 default: 1565 default:
1511 printk(KERN_ERR 1566 ext4_msg(sb, KERN_ERR,
1512 "EXT4-fs: Unrecognized mount option \"%s\" " 1567 "Unrecognized mount option \"%s\" "
1513 "or missing value\n", p); 1568 "or missing value", p);
1514 return 0; 1569 return 0;
1515 } 1570 }
1516 } 1571 }
@@ -1528,21 +1583,21 @@ set_qf_format:
1528 (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)) || 1583 (sbi->s_mount_opt & EXT4_MOUNT_GRPQUOTA)) ||
1529 (sbi->s_qf_names[GRPQUOTA] && 1584 (sbi->s_qf_names[GRPQUOTA] &&
1530 (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA))) { 1585 (sbi->s_mount_opt & EXT4_MOUNT_USRQUOTA))) {
1531 printk(KERN_ERR "EXT4-fs: old and new quota " 1586 ext4_msg(sb, KERN_ERR, "old and new quota "
1532 "format mixing.\n"); 1587 "format mixing");
1533 return 0; 1588 return 0;
1534 } 1589 }
1535 1590
1536 if (!sbi->s_jquota_fmt) { 1591 if (!sbi->s_jquota_fmt) {
1537 printk(KERN_ERR "EXT4-fs: journaled quota format " 1592 ext4_msg(sb, KERN_ERR, "journaled quota format "
1538 "not specified.\n"); 1593 "not specified");
1539 return 0; 1594 return 0;
1540 } 1595 }
1541 } else { 1596 } else {
1542 if (sbi->s_jquota_fmt) { 1597 if (sbi->s_jquota_fmt) {
1543 printk(KERN_ERR "EXT4-fs: journaled quota format " 1598 ext4_msg(sb, KERN_ERR, "journaled quota format "
1544 "specified with no journaling " 1599 "specified with no journaling "
1545 "enabled.\n"); 1600 "enabled");
1546 return 0; 1601 return 0;
1547 } 1602 }
1548 } 1603 }
@@ -1557,32 +1612,32 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
1557 int res = 0; 1612 int res = 0;
1558 1613
1559 if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) { 1614 if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) {
1560 printk(KERN_ERR "EXT4-fs warning: revision level too high, " 1615 ext4_msg(sb, KERN_ERR, "revision level too high, "
1561 "forcing read-only mode\n"); 1616 "forcing read-only mode");
1562 res = MS_RDONLY; 1617 res = MS_RDONLY;
1563 } 1618 }
1564 if (read_only) 1619 if (read_only)
1565 return res; 1620 return res;
1566 if (!(sbi->s_mount_state & EXT4_VALID_FS)) 1621 if (!(sbi->s_mount_state & EXT4_VALID_FS))
1567 printk(KERN_WARNING "EXT4-fs warning: mounting unchecked fs, " 1622 ext4_msg(sb, KERN_WARNING, "warning: mounting unchecked fs, "
1568 "running e2fsck is recommended\n"); 1623 "running e2fsck is recommended");
1569 else if ((sbi->s_mount_state & EXT4_ERROR_FS)) 1624 else if ((sbi->s_mount_state & EXT4_ERROR_FS))
1570 printk(KERN_WARNING 1625 ext4_msg(sb, KERN_WARNING,
1571 "EXT4-fs warning: mounting fs with errors, " 1626 "warning: mounting fs with errors, "
1572 "running e2fsck is recommended\n"); 1627 "running e2fsck is recommended");
1573 else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 && 1628 else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 &&
1574 le16_to_cpu(es->s_mnt_count) >= 1629 le16_to_cpu(es->s_mnt_count) >=
1575 (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count)) 1630 (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
1576 printk(KERN_WARNING 1631 ext4_msg(sb, KERN_WARNING,
1577 "EXT4-fs warning: maximal mount count reached, " 1632 "warning: maximal mount count reached, "
1578 "running e2fsck is recommended\n"); 1633 "running e2fsck is recommended");
1579 else if (le32_to_cpu(es->s_checkinterval) && 1634 else if (le32_to_cpu(es->s_checkinterval) &&
1580 (le32_to_cpu(es->s_lastcheck) + 1635 (le32_to_cpu(es->s_lastcheck) +
1581 le32_to_cpu(es->s_checkinterval) <= get_seconds())) 1636 le32_to_cpu(es->s_checkinterval) <= get_seconds()))
1582 printk(KERN_WARNING 1637 ext4_msg(sb, KERN_WARNING,
1583 "EXT4-fs warning: checktime reached, " 1638 "warning: checktime reached, "
1584 "running e2fsck is recommended\n"); 1639 "running e2fsck is recommended");
1585 if (!sbi->s_journal) 1640 if (!sbi->s_journal)
1586 es->s_state &= cpu_to_le16(~EXT4_VALID_FS); 1641 es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
1587 if (!(__s16) le16_to_cpu(es->s_max_mnt_count)) 1642 if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
1588 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT); 1643 es->s_max_mnt_count = cpu_to_le16(EXT4_DFL_MAX_MNT_COUNT);
@@ -1592,7 +1647,7 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
1592 if (sbi->s_journal) 1647 if (sbi->s_journal)
1593 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 1648 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
1594 1649
1595 ext4_commit_super(sb, es, 1); 1650 ext4_commit_super(sb, 1);
1596 if (test_opt(sb, DEBUG)) 1651 if (test_opt(sb, DEBUG))
1597 printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, " 1652 printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, "
1598 "bpg=%lu, ipg=%lu, mo=%04lx]\n", 1653 "bpg=%lu, ipg=%lu, mo=%04lx]\n",
@@ -1603,11 +1658,11 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
1603 sbi->s_mount_opt); 1658 sbi->s_mount_opt);
1604 1659
1605 if (EXT4_SB(sb)->s_journal) { 1660 if (EXT4_SB(sb)->s_journal) {
1606 printk(KERN_INFO "EXT4 FS on %s, %s journal on %s\n", 1661 ext4_msg(sb, KERN_INFO, "%s journal on %s",
1607 sb->s_id, EXT4_SB(sb)->s_journal->j_inode ? "internal" : 1662 EXT4_SB(sb)->s_journal->j_inode ? "internal" :
1608 "external", EXT4_SB(sb)->s_journal->j_devname); 1663 "external", EXT4_SB(sb)->s_journal->j_devname);
1609 } else { 1664 } else {
1610 printk(KERN_INFO "EXT4 FS on %s, no journal\n", sb->s_id); 1665 ext4_msg(sb, KERN_INFO, "no journal");
1611 } 1666 }
1612 return res; 1667 return res;
1613} 1668}
@@ -1616,10 +1671,10 @@ static int ext4_fill_flex_info(struct super_block *sb)
1616{ 1671{
1617 struct ext4_sb_info *sbi = EXT4_SB(sb); 1672 struct ext4_sb_info *sbi = EXT4_SB(sb);
1618 struct ext4_group_desc *gdp = NULL; 1673 struct ext4_group_desc *gdp = NULL;
1619 struct buffer_head *bh;
1620 ext4_group_t flex_group_count; 1674 ext4_group_t flex_group_count;
1621 ext4_group_t flex_group; 1675 ext4_group_t flex_group;
1622 int groups_per_flex = 0; 1676 int groups_per_flex = 0;
1677 size_t size;
1623 int i; 1678 int i;
1624 1679
1625 if (!sbi->s_es->s_log_groups_per_flex) { 1680 if (!sbi->s_es->s_log_groups_per_flex) {
@@ -1634,16 +1689,21 @@ static int ext4_fill_flex_info(struct super_block *sb)
1634 flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) + 1689 flex_group_count = ((sbi->s_groups_count + groups_per_flex - 1) +
1635 ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) << 1690 ((le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) + 1) <<
1636 EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex; 1691 EXT4_DESC_PER_BLOCK_BITS(sb))) / groups_per_flex;
1637 sbi->s_flex_groups = kzalloc(flex_group_count * 1692 size = flex_group_count * sizeof(struct flex_groups);
1638 sizeof(struct flex_groups), GFP_KERNEL); 1693 sbi->s_flex_groups = kzalloc(size, GFP_KERNEL);
1694 if (sbi->s_flex_groups == NULL) {
1695 sbi->s_flex_groups = vmalloc(size);
1696 if (sbi->s_flex_groups)
1697 memset(sbi->s_flex_groups, 0, size);
1698 }
1639 if (sbi->s_flex_groups == NULL) { 1699 if (sbi->s_flex_groups == NULL) {
1640 printk(KERN_ERR "EXT4-fs: not enough memory for " 1700 ext4_msg(sb, KERN_ERR, "not enough memory for "
1641 "%u flex groups\n", flex_group_count); 1701 "%u flex groups", flex_group_count);
1642 goto failed; 1702 goto failed;
1643 } 1703 }
1644 1704
1645 for (i = 0; i < sbi->s_groups_count; i++) { 1705 for (i = 0; i < sbi->s_groups_count; i++) {
1646 gdp = ext4_get_group_desc(sb, i, &bh); 1706 gdp = ext4_get_group_desc(sb, i, NULL);
1647 1707
1648 flex_group = ext4_flex_group(sbi, i); 1708 flex_group = ext4_flex_group(sbi, i);
1649 atomic_set(&sbi->s_flex_groups[flex_group].free_inodes, 1709 atomic_set(&sbi->s_flex_groups[flex_group].free_inodes,
@@ -1724,44 +1784,44 @@ static int ext4_check_descriptors(struct super_block *sb)
1724 1784
1725 block_bitmap = ext4_block_bitmap(sb, gdp); 1785 block_bitmap = ext4_block_bitmap(sb, gdp);
1726 if (block_bitmap < first_block || block_bitmap > last_block) { 1786 if (block_bitmap < first_block || block_bitmap > last_block) {
1727 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1787 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
1728 "Block bitmap for group %u not in group " 1788 "Block bitmap for group %u not in group "
1729 "(block %llu)!\n", i, block_bitmap); 1789 "(block %llu)!", i, block_bitmap);
1730 return 0; 1790 return 0;
1731 } 1791 }
1732 inode_bitmap = ext4_inode_bitmap(sb, gdp); 1792 inode_bitmap = ext4_inode_bitmap(sb, gdp);
1733 if (inode_bitmap < first_block || inode_bitmap > last_block) { 1793 if (inode_bitmap < first_block || inode_bitmap > last_block) {
1734 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1794 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
1735 "Inode bitmap for group %u not in group " 1795 "Inode bitmap for group %u not in group "
1736 "(block %llu)!\n", i, inode_bitmap); 1796 "(block %llu)!", i, inode_bitmap);
1737 return 0; 1797 return 0;
1738 } 1798 }
1739 inode_table = ext4_inode_table(sb, gdp); 1799 inode_table = ext4_inode_table(sb, gdp);
1740 if (inode_table < first_block || 1800 if (inode_table < first_block ||
1741 inode_table + sbi->s_itb_per_group - 1 > last_block) { 1801 inode_table + sbi->s_itb_per_group - 1 > last_block) {
1742 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1802 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
1743 "Inode table for group %u not in group " 1803 "Inode table for group %u not in group "
1744 "(block %llu)!\n", i, inode_table); 1804 "(block %llu)!", i, inode_table);
1745 return 0; 1805 return 0;
1746 } 1806 }
1747 spin_lock(sb_bgl_lock(sbi, i)); 1807 ext4_lock_group(sb, i);
1748 if (!ext4_group_desc_csum_verify(sbi, i, gdp)) { 1808 if (!ext4_group_desc_csum_verify(sbi, i, gdp)) {
1749 printk(KERN_ERR "EXT4-fs: ext4_check_descriptors: " 1809 ext4_msg(sb, KERN_ERR, "ext4_check_descriptors: "
1750 "Checksum for group %u failed (%u!=%u)\n", 1810 "Checksum for group %u failed (%u!=%u)",
1751 i, le16_to_cpu(ext4_group_desc_csum(sbi, i, 1811 i, le16_to_cpu(ext4_group_desc_csum(sbi, i,
1752 gdp)), le16_to_cpu(gdp->bg_checksum)); 1812 gdp)), le16_to_cpu(gdp->bg_checksum));
1753 if (!(sb->s_flags & MS_RDONLY)) { 1813 if (!(sb->s_flags & MS_RDONLY)) {
1754 spin_unlock(sb_bgl_lock(sbi, i)); 1814 ext4_unlock_group(sb, i);
1755 return 0; 1815 return 0;
1756 } 1816 }
1757 } 1817 }
1758 spin_unlock(sb_bgl_lock(sbi, i)); 1818 ext4_unlock_group(sb, i);
1759 if (!flexbg_flag) 1819 if (!flexbg_flag)
1760 first_block += EXT4_BLOCKS_PER_GROUP(sb); 1820 first_block += EXT4_BLOCKS_PER_GROUP(sb);
1761 } 1821 }
1762 1822
1763 ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb)); 1823 ext4_free_blocks_count_set(sbi->s_es, ext4_count_free_blocks(sb));
1764 sbi->s_es->s_free_inodes_count = cpu_to_le32(ext4_count_free_inodes(sb)); 1824 sbi->s_es->s_free_inodes_count =cpu_to_le32(ext4_count_free_inodes(sb));
1765 return 1; 1825 return 1;
1766} 1826}
1767 1827
@@ -1796,8 +1856,8 @@ static void ext4_orphan_cleanup(struct super_block *sb,
1796 } 1856 }
1797 1857
1798 if (bdev_read_only(sb->s_bdev)) { 1858 if (bdev_read_only(sb->s_bdev)) {
1799 printk(KERN_ERR "EXT4-fs: write access " 1859 ext4_msg(sb, KERN_ERR, "write access "
1800 "unavailable, skipping orphan cleanup.\n"); 1860 "unavailable, skipping orphan cleanup");
1801 return; 1861 return;
1802 } 1862 }
1803 1863
@@ -1811,8 +1871,7 @@ static void ext4_orphan_cleanup(struct super_block *sb,
1811 } 1871 }
1812 1872
1813 if (s_flags & MS_RDONLY) { 1873 if (s_flags & MS_RDONLY) {
1814 printk(KERN_INFO "EXT4-fs: %s: orphan cleanup on readonly fs\n", 1874 ext4_msg(sb, KERN_INFO, "orphan cleanup on readonly fs");
1815 sb->s_id);
1816 sb->s_flags &= ~MS_RDONLY; 1875 sb->s_flags &= ~MS_RDONLY;
1817 } 1876 }
1818#ifdef CONFIG_QUOTA 1877#ifdef CONFIG_QUOTA
@@ -1823,9 +1882,9 @@ static void ext4_orphan_cleanup(struct super_block *sb,
1823 if (EXT4_SB(sb)->s_qf_names[i]) { 1882 if (EXT4_SB(sb)->s_qf_names[i]) {
1824 int ret = ext4_quota_on_mount(sb, i); 1883 int ret = ext4_quota_on_mount(sb, i);
1825 if (ret < 0) 1884 if (ret < 0)
1826 printk(KERN_ERR 1885 ext4_msg(sb, KERN_ERR,
1827 "EXT4-fs: Cannot turn on journaled " 1886 "Cannot turn on journaled "
1828 "quota: error %d\n", ret); 1887 "quota: error %d", ret);
1829 } 1888 }
1830 } 1889 }
1831#endif 1890#endif
@@ -1842,16 +1901,16 @@ static void ext4_orphan_cleanup(struct super_block *sb,
1842 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan); 1901 list_add(&EXT4_I(inode)->i_orphan, &EXT4_SB(sb)->s_orphan);
1843 vfs_dq_init(inode); 1902 vfs_dq_init(inode);
1844 if (inode->i_nlink) { 1903 if (inode->i_nlink) {
1845 printk(KERN_DEBUG 1904 ext4_msg(sb, KERN_DEBUG,
1846 "%s: truncating inode %lu to %lld bytes\n", 1905 "%s: truncating inode %lu to %lld bytes",
1847 __func__, inode->i_ino, inode->i_size); 1906 __func__, inode->i_ino, inode->i_size);
1848 jbd_debug(2, "truncating inode %lu to %lld bytes\n", 1907 jbd_debug(2, "truncating inode %lu to %lld bytes\n",
1849 inode->i_ino, inode->i_size); 1908 inode->i_ino, inode->i_size);
1850 ext4_truncate(inode); 1909 ext4_truncate(inode);
1851 nr_truncates++; 1910 nr_truncates++;
1852 } else { 1911 } else {
1853 printk(KERN_DEBUG 1912 ext4_msg(sb, KERN_DEBUG,
1854 "%s: deleting unreferenced inode %lu\n", 1913 "%s: deleting unreferenced inode %lu",
1855 __func__, inode->i_ino); 1914 __func__, inode->i_ino);
1856 jbd_debug(2, "deleting unreferenced inode %lu\n", 1915 jbd_debug(2, "deleting unreferenced inode %lu\n",
1857 inode->i_ino); 1916 inode->i_ino);
@@ -1863,11 +1922,11 @@ static void ext4_orphan_cleanup(struct super_block *sb,
1863#define PLURAL(x) (x), ((x) == 1) ? "" : "s" 1922#define PLURAL(x) (x), ((x) == 1) ? "" : "s"
1864 1923
1865 if (nr_orphans) 1924 if (nr_orphans)
1866 printk(KERN_INFO "EXT4-fs: %s: %d orphan inode%s deleted\n", 1925 ext4_msg(sb, KERN_INFO, "%d orphan inode%s deleted",
1867 sb->s_id, PLURAL(nr_orphans)); 1926 PLURAL(nr_orphans));
1868 if (nr_truncates) 1927 if (nr_truncates)
1869 printk(KERN_INFO "EXT4-fs: %s: %d truncate%s cleaned up\n", 1928 ext4_msg(sb, KERN_INFO, "%d truncate%s cleaned up",
1870 sb->s_id, PLURAL(nr_truncates)); 1929 PLURAL(nr_truncates));
1871#ifdef CONFIG_QUOTA 1930#ifdef CONFIG_QUOTA
1872 /* Turn quotas off */ 1931 /* Turn quotas off */
1873 for (i = 0; i < MAXQUOTAS; i++) { 1932 for (i = 0; i < MAXQUOTAS; i++) {
@@ -1877,6 +1936,7 @@ static void ext4_orphan_cleanup(struct super_block *sb,
1877#endif 1936#endif
1878 sb->s_flags = s_flags; /* Restore MS_RDONLY status */ 1937 sb->s_flags = s_flags; /* Restore MS_RDONLY status */
1879} 1938}
1939
1880/* 1940/*
1881 * Maximal extent format file size. 1941 * Maximal extent format file size.
1882 * Resulting logical blkno at s_maxbytes must fit in our on-disk 1942 * Resulting logical blkno at s_maxbytes must fit in our on-disk
@@ -1927,19 +1987,19 @@ static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
1927 loff_t res = EXT4_NDIR_BLOCKS; 1987 loff_t res = EXT4_NDIR_BLOCKS;
1928 int meta_blocks; 1988 int meta_blocks;
1929 loff_t upper_limit; 1989 loff_t upper_limit;
1930 /* This is calculated to be the largest file size for a 1990 /* This is calculated to be the largest file size for a dense, block
1931 * dense, bitmapped file such that the total number of 1991 * mapped file such that the file's total number of 512-byte sectors,
1932 * sectors in the file, including data and all indirect blocks, 1992 * including data and all indirect blocks, does not exceed (2^48 - 1).
1933 * does not exceed 2^48 -1 1993 *
1934 * __u32 i_blocks_lo and _u16 i_blocks_high representing the 1994 * __u32 i_blocks_lo and _u16 i_blocks_high represent the total
1935 * total number of 512 bytes blocks of the file 1995 * number of 512-byte sectors of the file.
1936 */ 1996 */
1937 1997
1938 if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) { 1998 if (!has_huge_files || sizeof(blkcnt_t) < sizeof(u64)) {
1939 /* 1999 /*
1940 * !has_huge_files or CONFIG_LBD is not enabled 2000 * !has_huge_files or CONFIG_LBD not enabled implies that
1941 * implies the inode i_block represent total blocks in 2001 * the inode i_block field represents total file blocks in
1942 * 512 bytes 32 == size of vfs inode i_blocks * 8 2002 * 2^32 512-byte sectors == size of vfs inode i_blocks * 8
1943 */ 2003 */
1944 upper_limit = (1LL << 32) - 1; 2004 upper_limit = (1LL << 32) - 1;
1945 2005
@@ -1981,7 +2041,7 @@ static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
1981} 2041}
1982 2042
1983static ext4_fsblk_t descriptor_loc(struct super_block *sb, 2043static ext4_fsblk_t descriptor_loc(struct super_block *sb,
1984 ext4_fsblk_t logical_sb_block, int nr) 2044 ext4_fsblk_t logical_sb_block, int nr)
1985{ 2045{
1986 struct ext4_sb_info *sbi = EXT4_SB(sb); 2046 struct ext4_sb_info *sbi = EXT4_SB(sb);
1987 ext4_group_t bg, first_meta_bg; 2047 ext4_group_t bg, first_meta_bg;
@@ -1995,6 +2055,7 @@ static ext4_fsblk_t descriptor_loc(struct super_block *sb,
1995 bg = sbi->s_desc_per_block * nr; 2055 bg = sbi->s_desc_per_block * nr;
1996 if (ext4_bg_has_super(sb, bg)) 2056 if (ext4_bg_has_super(sb, bg))
1997 has_super = 1; 2057 has_super = 1;
2058
1998 return (has_super + ext4_group_first_block_no(sb, bg)); 2059 return (has_super + ext4_group_first_block_no(sb, bg));
1999} 2060}
2000 2061
@@ -2091,8 +2152,7 @@ static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
2091 if (parse_strtoul(buf, 0x40000000, &t)) 2152 if (parse_strtoul(buf, 0x40000000, &t))
2092 return -EINVAL; 2153 return -EINVAL;
2093 2154
2094 /* inode_readahead_blks must be a power of 2 */ 2155 if (!is_power_of_2(t))
2095 if (t & (t-1))
2096 return -EINVAL; 2156 return -EINVAL;
2097 2157
2098 sbi->s_inode_readahead_blks = t; 2158 sbi->s_inode_readahead_blks = t;
@@ -2100,7 +2160,7 @@ static ssize_t inode_readahead_blks_store(struct ext4_attr *a,
2100} 2160}
2101 2161
2102static ssize_t sbi_ui_show(struct ext4_attr *a, 2162static ssize_t sbi_ui_show(struct ext4_attr *a,
2103 struct ext4_sb_info *sbi, char *buf) 2163 struct ext4_sb_info *sbi, char *buf)
2104{ 2164{
2105 unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset); 2165 unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset);
2106 2166
@@ -2205,7 +2265,6 @@ static struct kobj_type ext4_ktype = {
2205static int ext4_fill_super(struct super_block *sb, void *data, int silent) 2265static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2206 __releases(kernel_lock) 2266 __releases(kernel_lock)
2207 __acquires(kernel_lock) 2267 __acquires(kernel_lock)
2208
2209{ 2268{
2210 struct buffer_head *bh; 2269 struct buffer_head *bh;
2211 struct ext4_super_block *es = NULL; 2270 struct ext4_super_block *es = NULL;
@@ -2256,7 +2315,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2256 2315
2257 blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE); 2316 blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
2258 if (!blocksize) { 2317 if (!blocksize) {
2259 printk(KERN_ERR "EXT4-fs: unable to set blocksize\n"); 2318 ext4_msg(sb, KERN_ERR, "unable to set blocksize");
2260 goto out_fail; 2319 goto out_fail;
2261 } 2320 }
2262 2321
@@ -2272,7 +2331,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2272 } 2331 }
2273 2332
2274 if (!(bh = sb_bread(sb, logical_sb_block))) { 2333 if (!(bh = sb_bread(sb, logical_sb_block))) {
2275 printk(KERN_ERR "EXT4-fs: unable to read superblock\n"); 2334 ext4_msg(sb, KERN_ERR, "unable to read superblock");
2276 goto out_fail; 2335 goto out_fail;
2277 } 2336 }
2278 /* 2337 /*
@@ -2321,6 +2380,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2321 sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ; 2380 sbi->s_commit_interval = JBD2_DEFAULT_MAX_COMMIT_AGE * HZ;
2322 sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME; 2381 sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;
2323 sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME; 2382 sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;
2383 sbi->s_mb_history_max = default_mb_history_length;
2324 2384
2325 set_opt(sbi->s_mount_opt, BARRIER); 2385 set_opt(sbi->s_mount_opt, BARRIER);
2326 2386
@@ -2330,7 +2390,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2330 */ 2390 */
2331 set_opt(sbi->s_mount_opt, DELALLOC); 2391 set_opt(sbi->s_mount_opt, DELALLOC);
2332 2392
2333
2334 if (!parse_options((char *) data, sb, &journal_devnum, 2393 if (!parse_options((char *) data, sb, &journal_devnum,
2335 &journal_ioprio, NULL, 0)) 2394 &journal_ioprio, NULL, 0))
2336 goto failed_mount; 2395 goto failed_mount;
@@ -2342,9 +2401,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2342 (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) || 2401 (EXT4_HAS_COMPAT_FEATURE(sb, ~0U) ||
2343 EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) || 2402 EXT4_HAS_RO_COMPAT_FEATURE(sb, ~0U) ||
2344 EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U))) 2403 EXT4_HAS_INCOMPAT_FEATURE(sb, ~0U)))
2345 printk(KERN_WARNING 2404 ext4_msg(sb, KERN_WARNING,
2346 "EXT4-fs warning: feature flags set on rev 0 fs, " 2405 "feature flags set on rev 0 fs, "
2347 "running e2fsck is recommended\n"); 2406 "running e2fsck is recommended");
2348 2407
2349 /* 2408 /*
2350 * Check feature flags regardless of the revision level, since we 2409 * Check feature flags regardless of the revision level, since we
@@ -2353,16 +2412,18 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2353 */ 2412 */
2354 features = EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP); 2413 features = EXT4_HAS_INCOMPAT_FEATURE(sb, ~EXT4_FEATURE_INCOMPAT_SUPP);
2355 if (features) { 2414 if (features) {
2356 printk(KERN_ERR "EXT4-fs: %s: couldn't mount because of " 2415 ext4_msg(sb, KERN_ERR,
2357 "unsupported optional features (%x).\n", sb->s_id, 2416 "Couldn't mount because of "
2417 "unsupported optional features (%x)",
2358 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) & 2418 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_incompat) &
2359 ~EXT4_FEATURE_INCOMPAT_SUPP)); 2419 ~EXT4_FEATURE_INCOMPAT_SUPP));
2360 goto failed_mount; 2420 goto failed_mount;
2361 } 2421 }
2362 features = EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP); 2422 features = EXT4_HAS_RO_COMPAT_FEATURE(sb, ~EXT4_FEATURE_RO_COMPAT_SUPP);
2363 if (!(sb->s_flags & MS_RDONLY) && features) { 2423 if (!(sb->s_flags & MS_RDONLY) && features) {
2364 printk(KERN_ERR "EXT4-fs: %s: couldn't mount RDWR because of " 2424 ext4_msg(sb, KERN_ERR,
2365 "unsupported optional features (%x).\n", sb->s_id, 2425 "Couldn't mount RDWR because of "
2426 "unsupported optional features (%x)",
2366 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) & 2427 (le32_to_cpu(EXT4_SB(sb)->s_es->s_feature_ro_compat) &
2367 ~EXT4_FEATURE_RO_COMPAT_SUPP)); 2428 ~EXT4_FEATURE_RO_COMPAT_SUPP));
2368 goto failed_mount; 2429 goto failed_mount;
@@ -2376,9 +2437,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2376 */ 2437 */
2377 if (sizeof(root->i_blocks) < sizeof(u64) && 2438 if (sizeof(root->i_blocks) < sizeof(u64) &&
2378 !(sb->s_flags & MS_RDONLY)) { 2439 !(sb->s_flags & MS_RDONLY)) {
2379 printk(KERN_ERR "EXT4-fs: %s: Filesystem with huge " 2440 ext4_msg(sb, KERN_ERR, "Filesystem with huge "
2380 "files cannot be mounted read-write " 2441 "files cannot be mounted read-write "
2381 "without CONFIG_LBD.\n", sb->s_id); 2442 "without CONFIG_LBD");
2382 goto failed_mount; 2443 goto failed_mount;
2383 } 2444 }
2384 } 2445 }
@@ -2386,17 +2447,15 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2386 2447
2387 if (blocksize < EXT4_MIN_BLOCK_SIZE || 2448 if (blocksize < EXT4_MIN_BLOCK_SIZE ||
2388 blocksize > EXT4_MAX_BLOCK_SIZE) { 2449 blocksize > EXT4_MAX_BLOCK_SIZE) {
2389 printk(KERN_ERR 2450 ext4_msg(sb, KERN_ERR,
2390 "EXT4-fs: Unsupported filesystem blocksize %d on %s.\n", 2451 "Unsupported filesystem blocksize %d", blocksize);
2391 blocksize, sb->s_id);
2392 goto failed_mount; 2452 goto failed_mount;
2393 } 2453 }
2394 2454
2395 if (sb->s_blocksize != blocksize) { 2455 if (sb->s_blocksize != blocksize) {
2396
2397 /* Validate the filesystem blocksize */ 2456 /* Validate the filesystem blocksize */
2398 if (!sb_set_blocksize(sb, blocksize)) { 2457 if (!sb_set_blocksize(sb, blocksize)) {
2399 printk(KERN_ERR "EXT4-fs: bad block size %d.\n", 2458 ext4_msg(sb, KERN_ERR, "bad block size %d",
2400 blocksize); 2459 blocksize);
2401 goto failed_mount; 2460 goto failed_mount;
2402 } 2461 }
@@ -2406,15 +2465,15 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2406 offset = do_div(logical_sb_block, blocksize); 2465 offset = do_div(logical_sb_block, blocksize);
2407 bh = sb_bread(sb, logical_sb_block); 2466 bh = sb_bread(sb, logical_sb_block);
2408 if (!bh) { 2467 if (!bh) {
2409 printk(KERN_ERR 2468 ext4_msg(sb, KERN_ERR,
2410 "EXT4-fs: Can't read superblock on 2nd try.\n"); 2469 "Can't read superblock on 2nd try");
2411 goto failed_mount; 2470 goto failed_mount;
2412 } 2471 }
2413 es = (struct ext4_super_block *)(((char *)bh->b_data) + offset); 2472 es = (struct ext4_super_block *)(((char *)bh->b_data) + offset);
2414 sbi->s_es = es; 2473 sbi->s_es = es;
2415 if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) { 2474 if (es->s_magic != cpu_to_le16(EXT4_SUPER_MAGIC)) {
2416 printk(KERN_ERR 2475 ext4_msg(sb, KERN_ERR,
2417 "EXT4-fs: Magic mismatch, very weird !\n"); 2476 "Magic mismatch, very weird!");
2418 goto failed_mount; 2477 goto failed_mount;
2419 } 2478 }
2420 } 2479 }
@@ -2432,30 +2491,33 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2432 if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) || 2491 if ((sbi->s_inode_size < EXT4_GOOD_OLD_INODE_SIZE) ||
2433 (!is_power_of_2(sbi->s_inode_size)) || 2492 (!is_power_of_2(sbi->s_inode_size)) ||
2434 (sbi->s_inode_size > blocksize)) { 2493 (sbi->s_inode_size > blocksize)) {
2435 printk(KERN_ERR 2494 ext4_msg(sb, KERN_ERR,
2436 "EXT4-fs: unsupported inode size: %d\n", 2495 "unsupported inode size: %d",
2437 sbi->s_inode_size); 2496 sbi->s_inode_size);
2438 goto failed_mount; 2497 goto failed_mount;
2439 } 2498 }
2440 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) 2499 if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE)
2441 sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2); 2500 sb->s_time_gran = 1 << (EXT4_EPOCH_BITS - 2);
2442 } 2501 }
2502
2443 sbi->s_desc_size = le16_to_cpu(es->s_desc_size); 2503 sbi->s_desc_size = le16_to_cpu(es->s_desc_size);
2444 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) { 2504 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_64BIT)) {
2445 if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT || 2505 if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT ||
2446 sbi->s_desc_size > EXT4_MAX_DESC_SIZE || 2506 sbi->s_desc_size > EXT4_MAX_DESC_SIZE ||
2447 !is_power_of_2(sbi->s_desc_size)) { 2507 !is_power_of_2(sbi->s_desc_size)) {
2448 printk(KERN_ERR 2508 ext4_msg(sb, KERN_ERR,
2449 "EXT4-fs: unsupported descriptor size %lu\n", 2509 "unsupported descriptor size %lu",
2450 sbi->s_desc_size); 2510 sbi->s_desc_size);
2451 goto failed_mount; 2511 goto failed_mount;
2452 } 2512 }
2453 } else 2513 } else
2454 sbi->s_desc_size = EXT4_MIN_DESC_SIZE; 2514 sbi->s_desc_size = EXT4_MIN_DESC_SIZE;
2515
2455 sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group); 2516 sbi->s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
2456 sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group); 2517 sbi->s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
2457 if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0) 2518 if (EXT4_INODE_SIZE(sb) == 0 || EXT4_INODES_PER_GROUP(sb) == 0)
2458 goto cantfind_ext4; 2519 goto cantfind_ext4;
2520
2459 sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb); 2521 sbi->s_inodes_per_block = blocksize / EXT4_INODE_SIZE(sb);
2460 if (sbi->s_inodes_per_block == 0) 2522 if (sbi->s_inodes_per_block == 0)
2461 goto cantfind_ext4; 2523 goto cantfind_ext4;
@@ -2466,6 +2528,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2466 sbi->s_mount_state = le16_to_cpu(es->s_state); 2528 sbi->s_mount_state = le16_to_cpu(es->s_state);
2467 sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb)); 2529 sbi->s_addr_per_block_bits = ilog2(EXT4_ADDR_PER_BLOCK(sb));
2468 sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb)); 2530 sbi->s_desc_per_block_bits = ilog2(EXT4_DESC_PER_BLOCK(sb));
2531
2469 for (i = 0; i < 4; i++) 2532 for (i = 0; i < 4; i++)
2470 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]); 2533 sbi->s_hash_seed[i] = le32_to_cpu(es->s_hash_seed[i]);
2471 sbi->s_def_hash_version = es->s_def_hash_version; 2534 sbi->s_def_hash_version = es->s_def_hash_version;
@@ -2483,25 +2546,24 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2483 } 2546 }
2484 2547
2485 if (sbi->s_blocks_per_group > blocksize * 8) { 2548 if (sbi->s_blocks_per_group > blocksize * 8) {
2486 printk(KERN_ERR 2549 ext4_msg(sb, KERN_ERR,
2487 "EXT4-fs: #blocks per group too big: %lu\n", 2550 "#blocks per group too big: %lu",
2488 sbi->s_blocks_per_group); 2551 sbi->s_blocks_per_group);
2489 goto failed_mount; 2552 goto failed_mount;
2490 } 2553 }
2491 if (sbi->s_inodes_per_group > blocksize * 8) { 2554 if (sbi->s_inodes_per_group > blocksize * 8) {
2492 printk(KERN_ERR 2555 ext4_msg(sb, KERN_ERR,
2493 "EXT4-fs: #inodes per group too big: %lu\n", 2556 "#inodes per group too big: %lu",
2494 sbi->s_inodes_per_group); 2557 sbi->s_inodes_per_group);
2495 goto failed_mount; 2558 goto failed_mount;
2496 } 2559 }
2497 2560
2498 if (ext4_blocks_count(es) > 2561 if (ext4_blocks_count(es) >
2499 (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) { 2562 (sector_t)(~0ULL) >> (sb->s_blocksize_bits - 9)) {
2500 printk(KERN_ERR "EXT4-fs: filesystem on %s:" 2563 ext4_msg(sb, KERN_ERR, "filesystem"
2501 " too large to mount safely\n", sb->s_id); 2564 " too large to mount safely");
2502 if (sizeof(sector_t) < 8) 2565 if (sizeof(sector_t) < 8)
2503 printk(KERN_WARNING "EXT4-fs: CONFIG_LBD not " 2566 ext4_msg(sb, KERN_WARNING, "CONFIG_LBD not enabled");
2504 "enabled\n");
2505 goto failed_mount; 2567 goto failed_mount;
2506 } 2568 }
2507 2569
@@ -2511,21 +2573,21 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2511 /* check blocks count against device size */ 2573 /* check blocks count against device size */
2512 blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits; 2574 blocks_count = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits;
2513 if (blocks_count && ext4_blocks_count(es) > blocks_count) { 2575 if (blocks_count && ext4_blocks_count(es) > blocks_count) {
2514 printk(KERN_WARNING "EXT4-fs: bad geometry: block count %llu " 2576 ext4_msg(sb, KERN_WARNING, "bad geometry: block count %llu "
2515 "exceeds size of device (%llu blocks)\n", 2577 "exceeds size of device (%llu blocks)",
2516 ext4_blocks_count(es), blocks_count); 2578 ext4_blocks_count(es), blocks_count);
2517 goto failed_mount; 2579 goto failed_mount;
2518 } 2580 }
2519 2581
2520 /* 2582 /*
2521 * It makes no sense for the first data block to be beyond the end 2583 * It makes no sense for the first data block to be beyond the end
2522 * of the filesystem. 2584 * of the filesystem.
2523 */ 2585 */
2524 if (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) { 2586 if (le32_to_cpu(es->s_first_data_block) >= ext4_blocks_count(es)) {
2525 printk(KERN_WARNING "EXT4-fs: bad geometry: first data" 2587 ext4_msg(sb, KERN_WARNING, "bad geometry: first data"
2526 "block %u is beyond end of filesystem (%llu)\n", 2588 "block %u is beyond end of filesystem (%llu)",
2527 le32_to_cpu(es->s_first_data_block), 2589 le32_to_cpu(es->s_first_data_block),
2528 ext4_blocks_count(es)); 2590 ext4_blocks_count(es));
2529 goto failed_mount; 2591 goto failed_mount;
2530 } 2592 }
2531 blocks_count = (ext4_blocks_count(es) - 2593 blocks_count = (ext4_blocks_count(es) -
@@ -2533,9 +2595,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2533 EXT4_BLOCKS_PER_GROUP(sb) - 1); 2595 EXT4_BLOCKS_PER_GROUP(sb) - 1);
2534 do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb)); 2596 do_div(blocks_count, EXT4_BLOCKS_PER_GROUP(sb));
2535 if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) { 2597 if (blocks_count > ((uint64_t)1<<32) - EXT4_DESC_PER_BLOCK(sb)) {
2536 printk(KERN_WARNING "EXT4-fs: groups count too large: %u " 2598 ext4_msg(sb, KERN_WARNING, "groups count too large: %u "
2537 "(block count %llu, first data block %u, " 2599 "(block count %llu, first data block %u, "
2538 "blocks per group %lu)\n", sbi->s_groups_count, 2600 "blocks per group %lu)", sbi->s_groups_count,
2539 ext4_blocks_count(es), 2601 ext4_blocks_count(es),
2540 le32_to_cpu(es->s_first_data_block), 2602 le32_to_cpu(es->s_first_data_block),
2541 EXT4_BLOCKS_PER_GROUP(sb)); 2603 EXT4_BLOCKS_PER_GROUP(sb));
@@ -2547,7 +2609,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2547 sbi->s_group_desc = kmalloc(db_count * sizeof(struct buffer_head *), 2609 sbi->s_group_desc = kmalloc(db_count * sizeof(struct buffer_head *),
2548 GFP_KERNEL); 2610 GFP_KERNEL);
2549 if (sbi->s_group_desc == NULL) { 2611 if (sbi->s_group_desc == NULL) {
2550 printk(KERN_ERR "EXT4-fs: not enough memory\n"); 2612 ext4_msg(sb, KERN_ERR, "not enough memory");
2551 goto failed_mount; 2613 goto failed_mount;
2552 } 2614 }
2553 2615
@@ -2562,21 +2624,21 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2562 block = descriptor_loc(sb, logical_sb_block, i); 2624 block = descriptor_loc(sb, logical_sb_block, i);
2563 sbi->s_group_desc[i] = sb_bread(sb, block); 2625 sbi->s_group_desc[i] = sb_bread(sb, block);
2564 if (!sbi->s_group_desc[i]) { 2626 if (!sbi->s_group_desc[i]) {
2565 printk(KERN_ERR "EXT4-fs: " 2627 ext4_msg(sb, KERN_ERR,
2566 "can't read group descriptor %d\n", i); 2628 "can't read group descriptor %d", i);
2567 db_count = i; 2629 db_count = i;
2568 goto failed_mount2; 2630 goto failed_mount2;
2569 } 2631 }
2570 } 2632 }
2571 if (!ext4_check_descriptors(sb)) { 2633 if (!ext4_check_descriptors(sb)) {
2572 printk(KERN_ERR "EXT4-fs: group descriptors corrupted!\n"); 2634 ext4_msg(sb, KERN_ERR, "group descriptors corrupted!");
2573 goto failed_mount2; 2635 goto failed_mount2;
2574 } 2636 }
2575 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG)) 2637 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
2576 if (!ext4_fill_flex_info(sb)) { 2638 if (!ext4_fill_flex_info(sb)) {
2577 printk(KERN_ERR 2639 ext4_msg(sb, KERN_ERR,
2578 "EXT4-fs: unable to initialize " 2640 "unable to initialize "
2579 "flex_bg meta info!\n"); 2641 "flex_bg meta info!");
2580 goto failed_mount2; 2642 goto failed_mount2;
2581 } 2643 }
2582 2644
@@ -2598,7 +2660,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2598 err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0); 2660 err = percpu_counter_init(&sbi->s_dirtyblocks_counter, 0);
2599 } 2661 }
2600 if (err) { 2662 if (err) {
2601 printk(KERN_ERR "EXT4-fs: insufficient memory\n"); 2663 ext4_msg(sb, KERN_ERR, "insufficient memory");
2602 goto failed_mount3; 2664 goto failed_mount3;
2603 } 2665 }
2604 2666
@@ -2607,7 +2669,11 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2607 /* 2669 /*
2608 * set up enough so that it can read an inode 2670 * set up enough so that it can read an inode
2609 */ 2671 */
2610 sb->s_op = &ext4_sops; 2672 if (!test_opt(sb, NOLOAD) &&
2673 EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL))
2674 sb->s_op = &ext4_sops;
2675 else
2676 sb->s_op = &ext4_nojournal_sops;
2611 sb->s_export_op = &ext4_export_ops; 2677 sb->s_export_op = &ext4_export_ops;
2612 sb->s_xattr = ext4_xattr_handlers; 2678 sb->s_xattr = ext4_xattr_handlers;
2613#ifdef CONFIG_QUOTA 2679#ifdef CONFIG_QUOTA
@@ -2615,6 +2681,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2615 sb->dq_op = &ext4_quota_operations; 2681 sb->dq_op = &ext4_quota_operations;
2616#endif 2682#endif
2617 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */ 2683 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
2684 mutex_init(&sbi->s_orphan_lock);
2685 mutex_init(&sbi->s_resize_lock);
2618 2686
2619 sb->s_root = NULL; 2687 sb->s_root = NULL;
2620 2688
@@ -2632,13 +2700,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2632 goto failed_mount3; 2700 goto failed_mount3;
2633 if (!(sb->s_flags & MS_RDONLY) && 2701 if (!(sb->s_flags & MS_RDONLY) &&
2634 EXT4_SB(sb)->s_journal->j_failed_commit) { 2702 EXT4_SB(sb)->s_journal->j_failed_commit) {
2635 printk(KERN_CRIT "EXT4-fs error (device %s): " 2703 ext4_msg(sb, KERN_CRIT, "error: "
2636 "ext4_fill_super: Journal transaction " 2704 "ext4_fill_super: Journal transaction "
2637 "%u is corrupt\n", sb->s_id, 2705 "%u is corrupt",
2638 EXT4_SB(sb)->s_journal->j_failed_commit); 2706 EXT4_SB(sb)->s_journal->j_failed_commit);
2639 if (test_opt(sb, ERRORS_RO)) { 2707 if (test_opt(sb, ERRORS_RO)) {
2640 printk(KERN_CRIT 2708 ext4_msg(sb, KERN_CRIT,
2641 "Mounting filesystem read-only\n"); 2709 "Mounting filesystem read-only");
2642 sb->s_flags |= MS_RDONLY; 2710 sb->s_flags |= MS_RDONLY;
2643 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 2711 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
2644 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 2712 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
@@ -2646,14 +2714,14 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2646 if (test_opt(sb, ERRORS_PANIC)) { 2714 if (test_opt(sb, ERRORS_PANIC)) {
2647 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 2715 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
2648 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 2716 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
2649 ext4_commit_super(sb, es, 1); 2717 ext4_commit_super(sb, 1);
2650 goto failed_mount4; 2718 goto failed_mount4;
2651 } 2719 }
2652 } 2720 }
2653 } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) && 2721 } else if (test_opt(sb, NOLOAD) && !(sb->s_flags & MS_RDONLY) &&
2654 EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) { 2722 EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
2655 printk(KERN_ERR "EXT4-fs: required journal recovery " 2723 ext4_msg(sb, KERN_ERR, "required journal recovery "
2656 "suppressed and not mounted read-only\n"); 2724 "suppressed and not mounted read-only");
2657 goto failed_mount4; 2725 goto failed_mount4;
2658 } else { 2726 } else {
2659 clear_opt(sbi->s_mount_opt, DATA_FLAGS); 2727 clear_opt(sbi->s_mount_opt, DATA_FLAGS);
@@ -2666,7 +2734,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2666 if (ext4_blocks_count(es) > 0xffffffffULL && 2734 if (ext4_blocks_count(es) > 0xffffffffULL &&
2667 !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0, 2735 !jbd2_journal_set_features(EXT4_SB(sb)->s_journal, 0, 0,
2668 JBD2_FEATURE_INCOMPAT_64BIT)) { 2736 JBD2_FEATURE_INCOMPAT_64BIT)) {
2669 printk(KERN_ERR "EXT4-fs: Failed to set 64-bit journal feature\n"); 2737 ext4_msg(sb, KERN_ERR, "Failed to set 64-bit journal feature");
2670 goto failed_mount4; 2738 goto failed_mount4;
2671 } 2739 }
2672 2740
@@ -2704,8 +2772,8 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2704 case EXT4_MOUNT_WRITEBACK_DATA: 2772 case EXT4_MOUNT_WRITEBACK_DATA:
2705 if (!jbd2_journal_check_available_features 2773 if (!jbd2_journal_check_available_features
2706 (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) { 2774 (sbi->s_journal, 0, 0, JBD2_FEATURE_INCOMPAT_REVOKE)) {
2707 printk(KERN_ERR "EXT4-fs: Journal does not support " 2775 ext4_msg(sb, KERN_ERR, "Journal does not support "
2708 "requested data journaling mode\n"); 2776 "requested data journaling mode");
2709 goto failed_mount4; 2777 goto failed_mount4;
2710 } 2778 }
2711 default: 2779 default:
@@ -2717,8 +2785,8 @@ no_journal:
2717 2785
2718 if (test_opt(sb, NOBH)) { 2786 if (test_opt(sb, NOBH)) {
2719 if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) { 2787 if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) {
2720 printk(KERN_WARNING "EXT4-fs: Ignoring nobh option - " 2788 ext4_msg(sb, KERN_WARNING, "Ignoring nobh option - "
2721 "its supported only with writeback mode\n"); 2789 "its supported only with writeback mode");
2722 clear_opt(sbi->s_mount_opt, NOBH); 2790 clear_opt(sbi->s_mount_opt, NOBH);
2723 } 2791 }
2724 } 2792 }
@@ -2729,18 +2797,18 @@ no_journal:
2729 2797
2730 root = ext4_iget(sb, EXT4_ROOT_INO); 2798 root = ext4_iget(sb, EXT4_ROOT_INO);
2731 if (IS_ERR(root)) { 2799 if (IS_ERR(root)) {
2732 printk(KERN_ERR "EXT4-fs: get root inode failed\n"); 2800 ext4_msg(sb, KERN_ERR, "get root inode failed");
2733 ret = PTR_ERR(root); 2801 ret = PTR_ERR(root);
2734 goto failed_mount4; 2802 goto failed_mount4;
2735 } 2803 }
2736 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) { 2804 if (!S_ISDIR(root->i_mode) || !root->i_blocks || !root->i_size) {
2737 iput(root); 2805 iput(root);
2738 printk(KERN_ERR "EXT4-fs: corrupt root inode, run e2fsck\n"); 2806 ext4_msg(sb, KERN_ERR, "corrupt root inode, run e2fsck");
2739 goto failed_mount4; 2807 goto failed_mount4;
2740 } 2808 }
2741 sb->s_root = d_alloc_root(root); 2809 sb->s_root = d_alloc_root(root);
2742 if (!sb->s_root) { 2810 if (!sb->s_root) {
2743 printk(KERN_ERR "EXT4-fs: get root dentry failed\n"); 2811 ext4_msg(sb, KERN_ERR, "get root dentry failed");
2744 iput(root); 2812 iput(root);
2745 ret = -ENOMEM; 2813 ret = -ENOMEM;
2746 goto failed_mount4; 2814 goto failed_mount4;
@@ -2769,22 +2837,29 @@ no_journal:
2769 sbi->s_inode_size) { 2837 sbi->s_inode_size) {
2770 sbi->s_want_extra_isize = sizeof(struct ext4_inode) - 2838 sbi->s_want_extra_isize = sizeof(struct ext4_inode) -
2771 EXT4_GOOD_OLD_INODE_SIZE; 2839 EXT4_GOOD_OLD_INODE_SIZE;
2772 printk(KERN_INFO "EXT4-fs: required extra inode space not" 2840 ext4_msg(sb, KERN_INFO, "required extra inode space not"
2773 "available.\n"); 2841 "available");
2774 } 2842 }
2775 2843
2776 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) { 2844 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
2777 printk(KERN_WARNING "EXT4-fs: Ignoring delalloc option - " 2845 ext4_msg(sb, KERN_WARNING, "Ignoring delalloc option - "
2778 "requested data journaling mode\n"); 2846 "requested data journaling mode");
2779 clear_opt(sbi->s_mount_opt, DELALLOC); 2847 clear_opt(sbi->s_mount_opt, DELALLOC);
2780 } else if (test_opt(sb, DELALLOC)) 2848 } else if (test_opt(sb, DELALLOC))
2781 printk(KERN_INFO "EXT4-fs: delayed allocation enabled\n"); 2849 ext4_msg(sb, KERN_INFO, "delayed allocation enabled");
2850
2851 err = ext4_setup_system_zone(sb);
2852 if (err) {
2853 ext4_msg(sb, KERN_ERR, "failed to initialize system "
2854 "zone (%d)\n", err);
2855 goto failed_mount4;
2856 }
2782 2857
2783 ext4_ext_init(sb); 2858 ext4_ext_init(sb);
2784 err = ext4_mb_init(sb, needs_recovery); 2859 err = ext4_mb_init(sb, needs_recovery);
2785 if (err) { 2860 if (err) {
2786 printk(KERN_ERR "EXT4-fs: failed to initalize mballoc (%d)\n", 2861 ext4_msg(sb, KERN_ERR, "failed to initalize mballoc (%d)",
2787 err); 2862 err);
2788 goto failed_mount4; 2863 goto failed_mount4;
2789 } 2864 }
2790 2865
@@ -2798,19 +2873,11 @@ no_journal:
2798 goto failed_mount4; 2873 goto failed_mount4;
2799 }; 2874 };
2800 2875
2801 /*
2802 * akpm: core read_super() calls in here with the superblock locked.
2803 * That deadlocks, because orphan cleanup needs to lock the superblock
2804 * in numerous places. Here we just pop the lock - it's relatively
2805 * harmless, because we are now ready to accept write_super() requests,
2806 * and aviro says that's the only reason for hanging onto the
2807 * superblock lock.
2808 */
2809 EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS; 2876 EXT4_SB(sb)->s_mount_state |= EXT4_ORPHAN_FS;
2810 ext4_orphan_cleanup(sb, es); 2877 ext4_orphan_cleanup(sb, es);
2811 EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS; 2878 EXT4_SB(sb)->s_mount_state &= ~EXT4_ORPHAN_FS;
2812 if (needs_recovery) { 2879 if (needs_recovery) {
2813 printk(KERN_INFO "EXT4-fs: recovery complete.\n"); 2880 ext4_msg(sb, KERN_INFO, "recovery complete");
2814 ext4_mark_recovery_complete(sb, es); 2881 ext4_mark_recovery_complete(sb, es);
2815 } 2882 }
2816 if (EXT4_SB(sb)->s_journal) { 2883 if (EXT4_SB(sb)->s_journal) {
@@ -2823,25 +2890,30 @@ no_journal:
2823 } else 2890 } else
2824 descr = "out journal"; 2891 descr = "out journal";
2825 2892
2826 printk(KERN_INFO "EXT4-fs: mounted filesystem %s with%s\n", 2893 ext4_msg(sb, KERN_INFO, "mounted filesystem with%s", descr);
2827 sb->s_id, descr);
2828 2894
2829 lock_kernel(); 2895 lock_kernel();
2830 return 0; 2896 return 0;
2831 2897
2832cantfind_ext4: 2898cantfind_ext4:
2833 if (!silent) 2899 if (!silent)
2834 printk(KERN_ERR "VFS: Can't find ext4 filesystem on dev %s.\n", 2900 ext4_msg(sb, KERN_ERR, "VFS: Can't find ext4 filesystem");
2835 sb->s_id);
2836 goto failed_mount; 2901 goto failed_mount;
2837 2902
2838failed_mount4: 2903failed_mount4:
2839 printk(KERN_ERR "EXT4-fs (device %s): mount failed\n", sb->s_id); 2904 ext4_msg(sb, KERN_ERR, "mount failed");
2905 ext4_release_system_zone(sb);
2840 if (sbi->s_journal) { 2906 if (sbi->s_journal) {
2841 jbd2_journal_destroy(sbi->s_journal); 2907 jbd2_journal_destroy(sbi->s_journal);
2842 sbi->s_journal = NULL; 2908 sbi->s_journal = NULL;
2843 } 2909 }
2844failed_mount3: 2910failed_mount3:
2911 if (sbi->s_flex_groups) {
2912 if (is_vmalloc_addr(sbi->s_flex_groups))
2913 vfree(sbi->s_flex_groups);
2914 else
2915 kfree(sbi->s_flex_groups);
2916 }
2845 percpu_counter_destroy(&sbi->s_freeblocks_counter); 2917 percpu_counter_destroy(&sbi->s_freeblocks_counter);
2846 percpu_counter_destroy(&sbi->s_freeinodes_counter); 2918 percpu_counter_destroy(&sbi->s_freeinodes_counter);
2847 percpu_counter_destroy(&sbi->s_dirs_counter); 2919 percpu_counter_destroy(&sbi->s_dirs_counter);
@@ -2862,6 +2934,7 @@ failed_mount:
2862 brelse(bh); 2934 brelse(bh);
2863out_fail: 2935out_fail:
2864 sb->s_fs_info = NULL; 2936 sb->s_fs_info = NULL;
2937 kfree(sbi->s_blockgroup_lock);
2865 kfree(sbi); 2938 kfree(sbi);
2866 lock_kernel(); 2939 lock_kernel();
2867 return ret; 2940 return ret;
@@ -2906,27 +2979,27 @@ static journal_t *ext4_get_journal(struct super_block *sb,
2906 2979
2907 journal_inode = ext4_iget(sb, journal_inum); 2980 journal_inode = ext4_iget(sb, journal_inum);
2908 if (IS_ERR(journal_inode)) { 2981 if (IS_ERR(journal_inode)) {
2909 printk(KERN_ERR "EXT4-fs: no journal found.\n"); 2982 ext4_msg(sb, KERN_ERR, "no journal found");
2910 return NULL; 2983 return NULL;
2911 } 2984 }
2912 if (!journal_inode->i_nlink) { 2985 if (!journal_inode->i_nlink) {
2913 make_bad_inode(journal_inode); 2986 make_bad_inode(journal_inode);
2914 iput(journal_inode); 2987 iput(journal_inode);
2915 printk(KERN_ERR "EXT4-fs: journal inode is deleted.\n"); 2988 ext4_msg(sb, KERN_ERR, "journal inode is deleted");
2916 return NULL; 2989 return NULL;
2917 } 2990 }
2918 2991
2919 jbd_debug(2, "Journal inode found at %p: %lld bytes\n", 2992 jbd_debug(2, "Journal inode found at %p: %lld bytes\n",
2920 journal_inode, journal_inode->i_size); 2993 journal_inode, journal_inode->i_size);
2921 if (!S_ISREG(journal_inode->i_mode)) { 2994 if (!S_ISREG(journal_inode->i_mode)) {
2922 printk(KERN_ERR "EXT4-fs: invalid journal inode.\n"); 2995 ext4_msg(sb, KERN_ERR, "invalid journal inode");
2923 iput(journal_inode); 2996 iput(journal_inode);
2924 return NULL; 2997 return NULL;
2925 } 2998 }
2926 2999
2927 journal = jbd2_journal_init_inode(journal_inode); 3000 journal = jbd2_journal_init_inode(journal_inode);
2928 if (!journal) { 3001 if (!journal) {
2929 printk(KERN_ERR "EXT4-fs: Could not load journal inode\n"); 3002 ext4_msg(sb, KERN_ERR, "Could not load journal inode");
2930 iput(journal_inode); 3003 iput(journal_inode);
2931 return NULL; 3004 return NULL;
2932 } 3005 }
@@ -2950,22 +3023,22 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
2950 3023
2951 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL)); 3024 BUG_ON(!EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_HAS_JOURNAL));
2952 3025
2953 bdev = ext4_blkdev_get(j_dev); 3026 bdev = ext4_blkdev_get(j_dev, sb);
2954 if (bdev == NULL) 3027 if (bdev == NULL)
2955 return NULL; 3028 return NULL;
2956 3029
2957 if (bd_claim(bdev, sb)) { 3030 if (bd_claim(bdev, sb)) {
2958 printk(KERN_ERR 3031 ext4_msg(sb, KERN_ERR,
2959 "EXT4-fs: failed to claim external journal device.\n"); 3032 "failed to claim external journal device");
2960 blkdev_put(bdev, FMODE_READ|FMODE_WRITE); 3033 blkdev_put(bdev, FMODE_READ|FMODE_WRITE);
2961 return NULL; 3034 return NULL;
2962 } 3035 }
2963 3036
2964 blocksize = sb->s_blocksize; 3037 blocksize = sb->s_blocksize;
2965 hblock = bdev_hardsect_size(bdev); 3038 hblock = bdev_logical_block_size(bdev);
2966 if (blocksize < hblock) { 3039 if (blocksize < hblock) {
2967 printk(KERN_ERR 3040 ext4_msg(sb, KERN_ERR,
2968 "EXT4-fs: blocksize too small for journal device.\n"); 3041 "blocksize too small for journal device");
2969 goto out_bdev; 3042 goto out_bdev;
2970 } 3043 }
2971 3044
@@ -2973,8 +3046,8 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
2973 offset = EXT4_MIN_BLOCK_SIZE % blocksize; 3046 offset = EXT4_MIN_BLOCK_SIZE % blocksize;
2974 set_blocksize(bdev, blocksize); 3047 set_blocksize(bdev, blocksize);
2975 if (!(bh = __bread(bdev, sb_block, blocksize))) { 3048 if (!(bh = __bread(bdev, sb_block, blocksize))) {
2976 printk(KERN_ERR "EXT4-fs: couldn't read superblock of " 3049 ext4_msg(sb, KERN_ERR, "couldn't read superblock of "
2977 "external journal\n"); 3050 "external journal");
2978 goto out_bdev; 3051 goto out_bdev;
2979 } 3052 }
2980 3053
@@ -2982,14 +3055,14 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
2982 if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) || 3055 if ((le16_to_cpu(es->s_magic) != EXT4_SUPER_MAGIC) ||
2983 !(le32_to_cpu(es->s_feature_incompat) & 3056 !(le32_to_cpu(es->s_feature_incompat) &
2984 EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) { 3057 EXT4_FEATURE_INCOMPAT_JOURNAL_DEV)) {
2985 printk(KERN_ERR "EXT4-fs: external journal has " 3058 ext4_msg(sb, KERN_ERR, "external journal has "
2986 "bad superblock\n"); 3059 "bad superblock");
2987 brelse(bh); 3060 brelse(bh);
2988 goto out_bdev; 3061 goto out_bdev;
2989 } 3062 }
2990 3063
2991 if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) { 3064 if (memcmp(EXT4_SB(sb)->s_es->s_journal_uuid, es->s_uuid, 16)) {
2992 printk(KERN_ERR "EXT4-fs: journal UUID does not match\n"); 3065 ext4_msg(sb, KERN_ERR, "journal UUID does not match");
2993 brelse(bh); 3066 brelse(bh);
2994 goto out_bdev; 3067 goto out_bdev;
2995 } 3068 }
@@ -3001,25 +3074,26 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,
3001 journal = jbd2_journal_init_dev(bdev, sb->s_bdev, 3074 journal = jbd2_journal_init_dev(bdev, sb->s_bdev,
3002 start, len, blocksize); 3075 start, len, blocksize);
3003 if (!journal) { 3076 if (!journal) {
3004 printk(KERN_ERR "EXT4-fs: failed to create device journal\n"); 3077 ext4_msg(sb, KERN_ERR, "failed to create device journal");
3005 goto out_bdev; 3078 goto out_bdev;
3006 } 3079 }
3007 journal->j_private = sb; 3080 journal->j_private = sb;
3008 ll_rw_block(READ, 1, &journal->j_sb_buffer); 3081 ll_rw_block(READ, 1, &journal->j_sb_buffer);
3009 wait_on_buffer(journal->j_sb_buffer); 3082 wait_on_buffer(journal->j_sb_buffer);
3010 if (!buffer_uptodate(journal->j_sb_buffer)) { 3083 if (!buffer_uptodate(journal->j_sb_buffer)) {
3011 printk(KERN_ERR "EXT4-fs: I/O error on journal device\n"); 3084 ext4_msg(sb, KERN_ERR, "I/O error on journal device");
3012 goto out_journal; 3085 goto out_journal;
3013 } 3086 }
3014 if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) { 3087 if (be32_to_cpu(journal->j_superblock->s_nr_users) != 1) {
3015 printk(KERN_ERR "EXT4-fs: External journal has more than one " 3088 ext4_msg(sb, KERN_ERR, "External journal has more than one "
3016 "user (unsupported) - %d\n", 3089 "user (unsupported) - %d",
3017 be32_to_cpu(journal->j_superblock->s_nr_users)); 3090 be32_to_cpu(journal->j_superblock->s_nr_users));
3018 goto out_journal; 3091 goto out_journal;
3019 } 3092 }
3020 EXT4_SB(sb)->journal_bdev = bdev; 3093 EXT4_SB(sb)->journal_bdev = bdev;
3021 ext4_init_journal_params(sb, journal); 3094 ext4_init_journal_params(sb, journal);
3022 return journal; 3095 return journal;
3096
3023out_journal: 3097out_journal:
3024 jbd2_journal_destroy(journal); 3098 jbd2_journal_destroy(journal);
3025out_bdev: 3099out_bdev:
@@ -3041,8 +3115,8 @@ static int ext4_load_journal(struct super_block *sb,
3041 3115
3042 if (journal_devnum && 3116 if (journal_devnum &&
3043 journal_devnum != le32_to_cpu(es->s_journal_dev)) { 3117 journal_devnum != le32_to_cpu(es->s_journal_dev)) {
3044 printk(KERN_INFO "EXT4-fs: external journal device major/minor " 3118 ext4_msg(sb, KERN_INFO, "external journal device major/minor "
3045 "numbers have changed\n"); 3119 "numbers have changed");
3046 journal_dev = new_decode_dev(journal_devnum); 3120 journal_dev = new_decode_dev(journal_devnum);
3047 } else 3121 } else
3048 journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev)); 3122 journal_dev = new_decode_dev(le32_to_cpu(es->s_journal_dev));
@@ -3054,24 +3128,23 @@ static int ext4_load_journal(struct super_block *sb,
3054 * crash? For recovery, we need to check in advance whether we 3128 * crash? For recovery, we need to check in advance whether we
3055 * can get read-write access to the device. 3129 * can get read-write access to the device.
3056 */ 3130 */
3057
3058 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) { 3131 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) {
3059 if (sb->s_flags & MS_RDONLY) { 3132 if (sb->s_flags & MS_RDONLY) {
3060 printk(KERN_INFO "EXT4-fs: INFO: recovery " 3133 ext4_msg(sb, KERN_INFO, "INFO: recovery "
3061 "required on readonly filesystem.\n"); 3134 "required on readonly filesystem");
3062 if (really_read_only) { 3135 if (really_read_only) {
3063 printk(KERN_ERR "EXT4-fs: write access " 3136 ext4_msg(sb, KERN_ERR, "write access "
3064 "unavailable, cannot proceed.\n"); 3137 "unavailable, cannot proceed");
3065 return -EROFS; 3138 return -EROFS;
3066 } 3139 }
3067 printk(KERN_INFO "EXT4-fs: write access will " 3140 ext4_msg(sb, KERN_INFO, "write access will "
3068 "be enabled during recovery.\n"); 3141 "be enabled during recovery");
3069 } 3142 }
3070 } 3143 }
3071 3144
3072 if (journal_inum && journal_dev) { 3145 if (journal_inum && journal_dev) {
3073 printk(KERN_ERR "EXT4-fs: filesystem has both journal " 3146 ext4_msg(sb, KERN_ERR, "filesystem has both journal "
3074 "and inode journals!\n"); 3147 "and inode journals!");
3075 return -EINVAL; 3148 return -EINVAL;
3076 } 3149 }
3077 3150
@@ -3084,14 +3157,14 @@ static int ext4_load_journal(struct super_block *sb,
3084 } 3157 }
3085 3158
3086 if (journal->j_flags & JBD2_BARRIER) 3159 if (journal->j_flags & JBD2_BARRIER)
3087 printk(KERN_INFO "EXT4-fs: barriers enabled\n"); 3160 ext4_msg(sb, KERN_INFO, "barriers enabled");
3088 else 3161 else
3089 printk(KERN_INFO "EXT4-fs: barriers disabled\n"); 3162 ext4_msg(sb, KERN_INFO, "barriers disabled");
3090 3163
3091 if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) { 3164 if (!really_read_only && test_opt(sb, UPDATE_JOURNAL)) {
3092 err = jbd2_journal_update_format(journal); 3165 err = jbd2_journal_update_format(journal);
3093 if (err) { 3166 if (err) {
3094 printk(KERN_ERR "EXT4-fs: error updating journal.\n"); 3167 ext4_msg(sb, KERN_ERR, "error updating journal");
3095 jbd2_journal_destroy(journal); 3168 jbd2_journal_destroy(journal);
3096 return err; 3169 return err;
3097 } 3170 }
@@ -3103,7 +3176,7 @@ static int ext4_load_journal(struct super_block *sb,
3103 err = jbd2_journal_load(journal); 3176 err = jbd2_journal_load(journal);
3104 3177
3105 if (err) { 3178 if (err) {
3106 printk(KERN_ERR "EXT4-fs: error loading journal.\n"); 3179 ext4_msg(sb, KERN_ERR, "error loading journal");
3107 jbd2_journal_destroy(journal); 3180 jbd2_journal_destroy(journal);
3108 return err; 3181 return err;
3109 } 3182 }
@@ -3114,18 +3187,17 @@ static int ext4_load_journal(struct super_block *sb,
3114 if (journal_devnum && 3187 if (journal_devnum &&
3115 journal_devnum != le32_to_cpu(es->s_journal_dev)) { 3188 journal_devnum != le32_to_cpu(es->s_journal_dev)) {
3116 es->s_journal_dev = cpu_to_le32(journal_devnum); 3189 es->s_journal_dev = cpu_to_le32(journal_devnum);
3117 sb->s_dirt = 1;
3118 3190
3119 /* Make sure we flush the recovery flag to disk. */ 3191 /* Make sure we flush the recovery flag to disk. */
3120 ext4_commit_super(sb, es, 1); 3192 ext4_commit_super(sb, 1);
3121 } 3193 }
3122 3194
3123 return 0; 3195 return 0;
3124} 3196}
3125 3197
3126static int ext4_commit_super(struct super_block *sb, 3198static int ext4_commit_super(struct super_block *sb, int sync)
3127 struct ext4_super_block *es, int sync)
3128{ 3199{
3200 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
3129 struct buffer_head *sbh = EXT4_SB(sb)->s_sbh; 3201 struct buffer_head *sbh = EXT4_SB(sb)->s_sbh;
3130 int error = 0; 3202 int error = 0;
3131 3203
@@ -3140,8 +3212,8 @@ static int ext4_commit_super(struct super_block *sb,
3140 * be remapped. Nothing we can do but to retry the 3212 * be remapped. Nothing we can do but to retry the
3141 * write and hope for the best. 3213 * write and hope for the best.
3142 */ 3214 */
3143 printk(KERN_ERR "EXT4-fs: previous I/O error to " 3215 ext4_msg(sb, KERN_ERR, "previous I/O error to "
3144 "superblock detected for %s.\n", sb->s_id); 3216 "superblock detected");
3145 clear_buffer_write_io_error(sbh); 3217 clear_buffer_write_io_error(sbh);
3146 set_buffer_uptodate(sbh); 3218 set_buffer_uptodate(sbh);
3147 } 3219 }
@@ -3154,7 +3226,7 @@ static int ext4_commit_super(struct super_block *sb,
3154 &EXT4_SB(sb)->s_freeblocks_counter)); 3226 &EXT4_SB(sb)->s_freeblocks_counter));
3155 es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive( 3227 es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive(
3156 &EXT4_SB(sb)->s_freeinodes_counter)); 3228 &EXT4_SB(sb)->s_freeinodes_counter));
3157 3229 sb->s_dirt = 0;
3158 BUFFER_TRACE(sbh, "marking dirty"); 3230 BUFFER_TRACE(sbh, "marking dirty");
3159 mark_buffer_dirty(sbh); 3231 mark_buffer_dirty(sbh);
3160 if (sync) { 3232 if (sync) {
@@ -3164,8 +3236,8 @@ static int ext4_commit_super(struct super_block *sb,
3164 3236
3165 error = buffer_write_io_error(sbh); 3237 error = buffer_write_io_error(sbh);
3166 if (error) { 3238 if (error) {
3167 printk(KERN_ERR "EXT4-fs: I/O error while writing " 3239 ext4_msg(sb, KERN_ERR, "I/O error while writing "
3168 "superblock for %s.\n", sb->s_id); 3240 "superblock");
3169 clear_buffer_write_io_error(sbh); 3241 clear_buffer_write_io_error(sbh);
3170 set_buffer_uptodate(sbh); 3242 set_buffer_uptodate(sbh);
3171 } 3243 }
@@ -3173,7 +3245,6 @@ static int ext4_commit_super(struct super_block *sb,
3173 return error; 3245 return error;
3174} 3246}
3175 3247
3176
3177/* 3248/*
3178 * Have we just finished recovery? If so, and if we are mounting (or 3249 * Have we just finished recovery? If so, and if we are mounting (or
3179 * remounting) the filesystem readonly, then we will end up with a 3250 * remounting) the filesystem readonly, then we will end up with a
@@ -3192,14 +3263,11 @@ static void ext4_mark_recovery_complete(struct super_block *sb,
3192 if (jbd2_journal_flush(journal) < 0) 3263 if (jbd2_journal_flush(journal) < 0)
3193 goto out; 3264 goto out;
3194 3265
3195 lock_super(sb);
3196 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) && 3266 if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER) &&
3197 sb->s_flags & MS_RDONLY) { 3267 sb->s_flags & MS_RDONLY) {
3198 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3268 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
3199 sb->s_dirt = 0; 3269 ext4_commit_super(sb, 1);
3200 ext4_commit_super(sb, es, 1);
3201 } 3270 }
3202 unlock_super(sb);
3203 3271
3204out: 3272out:
3205 jbd2_journal_unlock_updates(journal); 3273 jbd2_journal_unlock_updates(journal);
@@ -3238,7 +3306,7 @@ static void ext4_clear_journal_err(struct super_block *sb,
3238 3306
3239 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS; 3307 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
3240 es->s_state |= cpu_to_le16(EXT4_ERROR_FS); 3308 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
3241 ext4_commit_super(sb, es, 1); 3309 ext4_commit_super(sb, 1);
3242 3310
3243 jbd2_journal_clear_err(journal); 3311 jbd2_journal_clear_err(journal);
3244 } 3312 }
@@ -3257,29 +3325,15 @@ int ext4_force_commit(struct super_block *sb)
3257 return 0; 3325 return 0;
3258 3326
3259 journal = EXT4_SB(sb)->s_journal; 3327 journal = EXT4_SB(sb)->s_journal;
3260 if (journal) { 3328 if (journal)
3261 sb->s_dirt = 0;
3262 ret = ext4_journal_force_commit(journal); 3329 ret = ext4_journal_force_commit(journal);
3263 }
3264 3330
3265 return ret; 3331 return ret;
3266} 3332}
3267 3333
3268/*
3269 * Ext4 always journals updates to the superblock itself, so we don't
3270 * have to propagate any other updates to the superblock on disk at this
3271 * point. (We can probably nuke this function altogether, and remove
3272 * any mention to sb->s_dirt in all of fs/ext4; eventual cleanup...)
3273 */
3274static void ext4_write_super(struct super_block *sb) 3334static void ext4_write_super(struct super_block *sb)
3275{ 3335{
3276 if (EXT4_SB(sb)->s_journal) { 3336 ext4_commit_super(sb, 1);
3277 if (mutex_trylock(&sb->s_lock) != 0)
3278 BUG();
3279 sb->s_dirt = 0;
3280 } else {
3281 ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1);
3282 }
3283} 3337}
3284 3338
3285static int ext4_sync_fs(struct super_block *sb, int wait) 3339static int ext4_sync_fs(struct super_block *sb, int wait)
@@ -3288,16 +3342,9 @@ static int ext4_sync_fs(struct super_block *sb, int wait)
3288 tid_t target; 3342 tid_t target;
3289 3343
3290 trace_mark(ext4_sync_fs, "dev %s wait %d", sb->s_id, wait); 3344 trace_mark(ext4_sync_fs, "dev %s wait %d", sb->s_id, wait);
3291 sb->s_dirt = 0; 3345 if (jbd2_journal_start_commit(EXT4_SB(sb)->s_journal, &target)) {
3292 if (EXT4_SB(sb)->s_journal) { 3346 if (wait)
3293 if (jbd2_journal_start_commit(EXT4_SB(sb)->s_journal, 3347 jbd2_log_wait_commit(EXT4_SB(sb)->s_journal, target);
3294 &target)) {
3295 if (wait)
3296 jbd2_log_wait_commit(EXT4_SB(sb)->s_journal,
3297 target);
3298 }
3299 } else {
3300 ext4_commit_super(sb, EXT4_SB(sb)->s_es, wait);
3301 } 3348 }
3302 return ret; 3349 return ret;
3303} 3350}
@@ -3310,34 +3357,32 @@ static int ext4_freeze(struct super_block *sb)
3310{ 3357{
3311 int error = 0; 3358 int error = 0;
3312 journal_t *journal; 3359 journal_t *journal;
3313 sb->s_dirt = 0;
3314 3360
3315 if (!(sb->s_flags & MS_RDONLY)) { 3361 if (sb->s_flags & MS_RDONLY)
3316 journal = EXT4_SB(sb)->s_journal; 3362 return 0;
3317 3363
3318 if (journal) { 3364 journal = EXT4_SB(sb)->s_journal;
3319 /* Now we set up the journal barrier. */
3320 jbd2_journal_lock_updates(journal);
3321 3365
3322 /* 3366 /* Now we set up the journal barrier. */
3323 * We don't want to clear needs_recovery flag when we 3367 jbd2_journal_lock_updates(journal);
3324 * failed to flush the journal.
3325 */
3326 error = jbd2_journal_flush(journal);
3327 if (error < 0)
3328 goto out;
3329 }
3330 3368
3331 /* Journal blocked and flushed, clear needs_recovery flag. */ 3369 /*
3332 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3370 * Don't clear the needs_recovery flag if we failed to flush
3333 error = ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1); 3371 * the journal.
3334 if (error) 3372 */
3335 goto out; 3373 error = jbd2_journal_flush(journal);
3374 if (error < 0) {
3375 out:
3376 jbd2_journal_unlock_updates(journal);
3377 return error;
3336 } 3378 }
3379
3380 /* Journal blocked and flushed, clear needs_recovery flag. */
3381 EXT4_CLEAR_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
3382 error = ext4_commit_super(sb, 1);
3383 if (error)
3384 goto out;
3337 return 0; 3385 return 0;
3338out:
3339 jbd2_journal_unlock_updates(journal);
3340 return error;
3341} 3386}
3342 3387
3343/* 3388/*
@@ -3346,14 +3391,15 @@ out:
3346 */ 3391 */
3347static int ext4_unfreeze(struct super_block *sb) 3392static int ext4_unfreeze(struct super_block *sb)
3348{ 3393{
3349 if (EXT4_SB(sb)->s_journal && !(sb->s_flags & MS_RDONLY)) { 3394 if (sb->s_flags & MS_RDONLY)
3350 lock_super(sb); 3395 return 0;
3351 /* Reser the needs_recovery flag before the fs is unlocked. */ 3396
3352 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER); 3397 lock_super(sb);
3353 ext4_commit_super(sb, EXT4_SB(sb)->s_es, 1); 3398 /* Reset the needs_recovery flag before the fs is unlocked. */
3354 unlock_super(sb); 3399 EXT4_SET_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER);
3355 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal); 3400 ext4_commit_super(sb, 1);
3356 } 3401 unlock_super(sb);
3402 jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
3357 return 0; 3403 return 0;
3358} 3404}
3359 3405
@@ -3432,22 +3478,15 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3432 (sbi->s_mount_state & EXT4_VALID_FS)) 3478 (sbi->s_mount_state & EXT4_VALID_FS))
3433 es->s_state = cpu_to_le16(sbi->s_mount_state); 3479 es->s_state = cpu_to_le16(sbi->s_mount_state);
3434 3480
3435 /* 3481 if (sbi->s_journal)
3436 * We have to unlock super so that we can wait for
3437 * transactions.
3438 */
3439 if (sbi->s_journal) {
3440 unlock_super(sb);
3441 ext4_mark_recovery_complete(sb, es); 3482 ext4_mark_recovery_complete(sb, es);
3442 lock_super(sb);
3443 }
3444 } else { 3483 } else {
3445 int ret; 3484 int ret;
3446 if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb, 3485 if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb,
3447 ~EXT4_FEATURE_RO_COMPAT_SUPP))) { 3486 ~EXT4_FEATURE_RO_COMPAT_SUPP))) {
3448 printk(KERN_WARNING "EXT4-fs: %s: couldn't " 3487 ext4_msg(sb, KERN_WARNING, "couldn't "
3449 "remount RDWR because of unsupported " 3488 "remount RDWR because of unsupported "
3450 "optional features (%x).\n", sb->s_id, 3489 "optional features (%x)",
3451 (le32_to_cpu(sbi->s_es->s_feature_ro_compat) & 3490 (le32_to_cpu(sbi->s_es->s_feature_ro_compat) &
3452 ~EXT4_FEATURE_RO_COMPAT_SUPP)); 3491 ~EXT4_FEATURE_RO_COMPAT_SUPP));
3453 err = -EROFS; 3492 err = -EROFS;
@@ -3456,17 +3495,15 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3456 3495
3457 /* 3496 /*
3458 * Make sure the group descriptor checksums 3497 * Make sure the group descriptor checksums
3459 * are sane. If they aren't, refuse to 3498 * are sane. If they aren't, refuse to remount r/w.
3460 * remount r/w.
3461 */ 3499 */
3462 for (g = 0; g < sbi->s_groups_count; g++) { 3500 for (g = 0; g < sbi->s_groups_count; g++) {
3463 struct ext4_group_desc *gdp = 3501 struct ext4_group_desc *gdp =
3464 ext4_get_group_desc(sb, g, NULL); 3502 ext4_get_group_desc(sb, g, NULL);
3465 3503
3466 if (!ext4_group_desc_csum_verify(sbi, g, gdp)) { 3504 if (!ext4_group_desc_csum_verify(sbi, g, gdp)) {
3467 printk(KERN_ERR 3505 ext4_msg(sb, KERN_ERR,
3468 "EXT4-fs: ext4_remount: " 3506 "ext4_remount: Checksum for group %u failed (%u!=%u)",
3469 "Checksum for group %u failed (%u!=%u)\n",
3470 g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)), 3507 g, le16_to_cpu(ext4_group_desc_csum(sbi, g, gdp)),
3471 le16_to_cpu(gdp->bg_checksum)); 3508 le16_to_cpu(gdp->bg_checksum));
3472 err = -EINVAL; 3509 err = -EINVAL;
@@ -3480,11 +3517,10 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3480 * require a full umount/remount for now. 3517 * require a full umount/remount for now.
3481 */ 3518 */
3482 if (es->s_last_orphan) { 3519 if (es->s_last_orphan) {
3483 printk(KERN_WARNING "EXT4-fs: %s: couldn't " 3520 ext4_msg(sb, KERN_WARNING, "Couldn't "
3484 "remount RDWR because of unprocessed " 3521 "remount RDWR because of unprocessed "
3485 "orphan inode list. Please " 3522 "orphan inode list. Please "
3486 "umount/remount instead.\n", 3523 "umount/remount instead");
3487 sb->s_id);
3488 err = -EINVAL; 3524 err = -EINVAL;
3489 goto restore_opts; 3525 goto restore_opts;
3490 } 3526 }
@@ -3504,8 +3540,9 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3504 sb->s_flags &= ~MS_RDONLY; 3540 sb->s_flags &= ~MS_RDONLY;
3505 } 3541 }
3506 } 3542 }
3543 ext4_setup_system_zone(sb);
3507 if (sbi->s_journal == NULL) 3544 if (sbi->s_journal == NULL)
3508 ext4_commit_super(sb, es, 1); 3545 ext4_commit_super(sb, 1);
3509 3546
3510#ifdef CONFIG_QUOTA 3547#ifdef CONFIG_QUOTA
3511 /* Release old quota file names */ 3548 /* Release old quota file names */
@@ -3515,6 +3552,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3515 kfree(old_opts.s_qf_names[i]); 3552 kfree(old_opts.s_qf_names[i]);
3516#endif 3553#endif
3517 return 0; 3554 return 0;
3555
3518restore_opts: 3556restore_opts:
3519 sb->s_flags = old_sb_flags; 3557 sb->s_flags = old_sb_flags;
3520 sbi->s_mount_opt = old_opts.s_mount_opt; 3558 sbi->s_mount_opt = old_opts.s_mount_opt;
@@ -3545,9 +3583,8 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
3545 if (test_opt(sb, MINIX_DF)) { 3583 if (test_opt(sb, MINIX_DF)) {
3546 sbi->s_overhead_last = 0; 3584 sbi->s_overhead_last = 0;
3547 } else if (sbi->s_blocks_last != ext4_blocks_count(es)) { 3585 } else if (sbi->s_blocks_last != ext4_blocks_count(es)) {
3548 ext4_group_t ngroups = sbi->s_groups_count, i; 3586 ext4_group_t i, ngroups = ext4_get_groups_count(sb);
3549 ext4_fsblk_t overhead = 0; 3587 ext4_fsblk_t overhead = 0;
3550 smp_rmb();
3551 3588
3552 /* 3589 /*
3553 * Compute the overhead (FS structures). This is constant 3590 * Compute the overhead (FS structures). This is constant
@@ -3599,11 +3636,12 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
3599 le64_to_cpup((void *)es->s_uuid + sizeof(u64)); 3636 le64_to_cpup((void *)es->s_uuid + sizeof(u64));
3600 buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL; 3637 buf->f_fsid.val[0] = fsid & 0xFFFFFFFFUL;
3601 buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL; 3638 buf->f_fsid.val[1] = (fsid >> 32) & 0xFFFFFFFFUL;
3639
3602 return 0; 3640 return 0;
3603} 3641}
3604 3642
3605/* Helper function for writing quotas on sync - we need to start transaction before quota file 3643/* Helper function for writing quotas on sync - we need to start transaction
3606 * is locked for write. Otherwise the are possible deadlocks: 3644 * before quota file is locked for write. Otherwise the are possible deadlocks:
3607 * Process 1 Process 2 3645 * Process 1 Process 2
3608 * ext4_create() quota_sync() 3646 * ext4_create() quota_sync()
3609 * jbd2_journal_start() write_dquot() 3647 * jbd2_journal_start() write_dquot()
@@ -3627,7 +3665,7 @@ static int ext4_write_dquot(struct dquot *dquot)
3627 3665
3628 inode = dquot_to_inode(dquot); 3666 inode = dquot_to_inode(dquot);
3629 handle = ext4_journal_start(inode, 3667 handle = ext4_journal_start(inode,
3630 EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb)); 3668 EXT4_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
3631 if (IS_ERR(handle)) 3669 if (IS_ERR(handle))
3632 return PTR_ERR(handle); 3670 return PTR_ERR(handle);
3633 ret = dquot_commit(dquot); 3671 ret = dquot_commit(dquot);
@@ -3643,7 +3681,7 @@ static int ext4_acquire_dquot(struct dquot *dquot)
3643 handle_t *handle; 3681 handle_t *handle;
3644 3682
3645 handle = ext4_journal_start(dquot_to_inode(dquot), 3683 handle = ext4_journal_start(dquot_to_inode(dquot),
3646 EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb)); 3684 EXT4_QUOTA_INIT_BLOCKS(dquot->dq_sb));
3647 if (IS_ERR(handle)) 3685 if (IS_ERR(handle))
3648 return PTR_ERR(handle); 3686 return PTR_ERR(handle);
3649 ret = dquot_acquire(dquot); 3687 ret = dquot_acquire(dquot);
@@ -3659,7 +3697,7 @@ static int ext4_release_dquot(struct dquot *dquot)
3659 handle_t *handle; 3697 handle_t *handle;
3660 3698
3661 handle = ext4_journal_start(dquot_to_inode(dquot), 3699 handle = ext4_journal_start(dquot_to_inode(dquot),
3662 EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb)); 3700 EXT4_QUOTA_DEL_BLOCKS(dquot->dq_sb));
3663 if (IS_ERR(handle)) { 3701 if (IS_ERR(handle)) {
3664 /* Release dquot anyway to avoid endless cycle in dqput() */ 3702 /* Release dquot anyway to avoid endless cycle in dqput() */
3665 dquot_release(dquot); 3703 dquot_release(dquot);
@@ -3707,7 +3745,7 @@ static int ext4_write_info(struct super_block *sb, int type)
3707static int ext4_quota_on_mount(struct super_block *sb, int type) 3745static int ext4_quota_on_mount(struct super_block *sb, int type)
3708{ 3746{
3709 return vfs_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type], 3747 return vfs_quota_on_mount(sb, EXT4_SB(sb)->s_qf_names[type],
3710 EXT4_SB(sb)->s_jquota_fmt, type); 3748 EXT4_SB(sb)->s_jquota_fmt, type);
3711} 3749}
3712 3750
3713/* 3751/*
@@ -3738,9 +3776,9 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
3738 if (EXT4_SB(sb)->s_qf_names[type]) { 3776 if (EXT4_SB(sb)->s_qf_names[type]) {
3739 /* Quotafile not in fs root? */ 3777 /* Quotafile not in fs root? */
3740 if (path.dentry->d_parent != sb->s_root) 3778 if (path.dentry->d_parent != sb->s_root)
3741 printk(KERN_WARNING 3779 ext4_msg(sb, KERN_WARNING,
3742 "EXT4-fs: Quota file not on filesystem root. " 3780 "Quota file not on filesystem root. "
3743 "Journaled quota will not work.\n"); 3781 "Journaled quota will not work");
3744 } 3782 }
3745 3783
3746 /* 3784 /*
@@ -3823,8 +3861,8 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
3823 handle_t *handle = journal_current_handle(); 3861 handle_t *handle = journal_current_handle();
3824 3862
3825 if (EXT4_SB(sb)->s_journal && !handle) { 3863 if (EXT4_SB(sb)->s_journal && !handle) {
3826 printk(KERN_WARNING "EXT4-fs: Quota write (off=%llu, len=%llu)" 3864 ext4_msg(sb, KERN_WARNING, "Quota write (off=%llu, len=%llu)"
3827 " cancelled because transaction is not started.\n", 3865 " cancelled because transaction is not started",
3828 (unsigned long long)off, (unsigned long long)len); 3866 (unsigned long long)off, (unsigned long long)len);
3829 return -EIO; 3867 return -EIO;
3830 } 3868 }
@@ -3878,10 +3916,10 @@ out:
3878 3916
3879#endif 3917#endif
3880 3918
3881static int ext4_get_sb(struct file_system_type *fs_type, 3919static int ext4_get_sb(struct file_system_type *fs_type, int flags,
3882 int flags, const char *dev_name, void *data, struct vfsmount *mnt) 3920 const char *dev_name, void *data, struct vfsmount *mnt)
3883{ 3921{
3884 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt); 3922 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super,mnt);
3885} 3923}
3886 3924
3887static struct file_system_type ext4_fs_type = { 3925static struct file_system_type ext4_fs_type = {
@@ -3893,14 +3931,14 @@ static struct file_system_type ext4_fs_type = {
3893}; 3931};
3894 3932
3895#ifdef CONFIG_EXT4DEV_COMPAT 3933#ifdef CONFIG_EXT4DEV_COMPAT
3896static int ext4dev_get_sb(struct file_system_type *fs_type, 3934static int ext4dev_get_sb(struct file_system_type *fs_type, int flags,
3897 int flags, const char *dev_name, void *data, struct vfsmount *mnt) 3935 const char *dev_name, void *data,struct vfsmount *mnt)
3898{ 3936{
3899 printk(KERN_WARNING "EXT4-fs: Update your userspace programs " 3937 printk(KERN_WARNING "EXT4-fs (%s): Update your userspace programs "
3900 "to mount using ext4\n"); 3938 "to mount using ext4\n", dev_name);
3901 printk(KERN_WARNING "EXT4-fs: ext4dev backwards compatibility " 3939 printk(KERN_WARNING "EXT4-fs (%s): ext4dev backwards compatibility "
3902 "will go away by 2.6.31\n"); 3940 "will go away by 2.6.31\n", dev_name);
3903 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super, mnt); 3941 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super,mnt);
3904} 3942}
3905 3943
3906static struct file_system_type ext4dev_fs_type = { 3944static struct file_system_type ext4dev_fs_type = {
@@ -3917,13 +3955,16 @@ static int __init init_ext4_fs(void)
3917{ 3955{
3918 int err; 3956 int err;
3919 3957
3958 err = init_ext4_system_zone();
3959 if (err)
3960 return err;
3920 ext4_kset = kset_create_and_add("ext4", NULL, fs_kobj); 3961 ext4_kset = kset_create_and_add("ext4", NULL, fs_kobj);
3921 if (!ext4_kset) 3962 if (!ext4_kset)
3922 return -ENOMEM; 3963 goto out4;
3923 ext4_proc_root = proc_mkdir("fs/ext4", NULL); 3964 ext4_proc_root = proc_mkdir("fs/ext4", NULL);
3924 err = init_ext4_mballoc(); 3965 err = init_ext4_mballoc();
3925 if (err) 3966 if (err)
3926 return err; 3967 goto out3;
3927 3968
3928 err = init_ext4_xattr(); 3969 err = init_ext4_xattr();
3929 if (err) 3970 if (err)
@@ -3948,6 +3989,11 @@ out1:
3948 exit_ext4_xattr(); 3989 exit_ext4_xattr();
3949out2: 3990out2:
3950 exit_ext4_mballoc(); 3991 exit_ext4_mballoc();
3992out3:
3993 remove_proc_entry("fs/ext4", NULL);
3994 kset_unregister(ext4_kset);
3995out4:
3996 exit_ext4_system_zone();
3951 return err; 3997 return err;
3952} 3998}
3953 3999
@@ -3962,6 +4008,7 @@ static void __exit exit_ext4_fs(void)
3962 exit_ext4_mballoc(); 4008 exit_ext4_mballoc();
3963 remove_proc_entry("fs/ext4", NULL); 4009 remove_proc_entry("fs/ext4", NULL);
3964 kset_unregister(ext4_kset); 4010 kset_unregister(ext4_kset);
4011 exit_ext4_system_zone();
3965} 4012}
3966 4013
3967MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others"); 4014MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
diff --git a/fs/gfs2/Kconfig b/fs/gfs2/Kconfig
index 3a981b7f64ca..cad957cdb1e5 100644
--- a/fs/gfs2/Kconfig
+++ b/fs/gfs2/Kconfig
@@ -7,6 +7,7 @@ config GFS2_FS
7 select IP_SCTP if DLM_SCTP 7 select IP_SCTP if DLM_SCTP
8 select FS_POSIX_ACL 8 select FS_POSIX_ACL
9 select CRC32 9 select CRC32
10 select SLOW_WORK
10 help 11 help
11 A cluster filesystem. 12 A cluster filesystem.
12 13
diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile
index a851ea4bdf70..d53a9bea1c2f 100644
--- a/fs/gfs2/Makefile
+++ b/fs/gfs2/Makefile
@@ -1,8 +1,8 @@
1obj-$(CONFIG_GFS2_FS) += gfs2.o 1obj-$(CONFIG_GFS2_FS) += gfs2.o
2gfs2-y := acl.o bmap.o dir.o eaops.o eattr.o glock.o \ 2gfs2-y := acl.o bmap.o dir.o eaops.o eattr.o glock.o \
3 glops.o inode.o log.o lops.o main.o meta_io.o \ 3 glops.o inode.o log.o lops.o main.o meta_io.o \
4 mount.o ops_address.o ops_dentry.o ops_export.o ops_file.o \ 4 aops.o dentry.o export.o file.o \
5 ops_fstype.o ops_inode.o ops_super.o quota.o \ 5 ops_fstype.o ops_inode.o quota.o \
6 recovery.o rgrp.o super.o sys.o trans.o util.o 6 recovery.o rgrp.o super.o sys.o trans.o util.o
7 7
8gfs2-$(CONFIG_GFS2_FS_LOCKING_DLM) += lock_dlm.o 8gfs2-$(CONFIG_GFS2_FS_LOCKING_DLM) += lock_dlm.o
diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/aops.c
index a6dde1751e17..03ebb439ace0 100644
--- a/fs/gfs2/ops_address.c
+++ b/fs/gfs2/aops.c
@@ -28,7 +28,6 @@
28#include "inode.h" 28#include "inode.h"
29#include "log.h" 29#include "log.h"
30#include "meta_io.h" 30#include "meta_io.h"
31#include "ops_address.h"
32#include "quota.h" 31#include "quota.h"
33#include "trans.h" 32#include "trans.h"
34#include "rgrp.h" 33#include "rgrp.h"
@@ -781,10 +780,12 @@ static int gfs2_stuffed_write_end(struct inode *inode, struct buffer_head *dibh,
781 unlock_page(page); 780 unlock_page(page);
782 page_cache_release(page); 781 page_cache_release(page);
783 782
784 if (inode->i_size < to) { 783 if (copied) {
785 i_size_write(inode, to); 784 if (inode->i_size < to) {
786 ip->i_disksize = inode->i_size; 785 i_size_write(inode, to);
787 di->di_size = cpu_to_be64(inode->i_size); 786 ip->i_disksize = inode->i_size;
787 }
788 gfs2_dinode_out(ip, di);
788 mark_inode_dirty(inode); 789 mark_inode_dirty(inode);
789 } 790 }
790 791
@@ -824,7 +825,6 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
824 struct gfs2_sbd *sdp = GFS2_SB(inode); 825 struct gfs2_sbd *sdp = GFS2_SB(inode);
825 struct buffer_head *dibh; 826 struct buffer_head *dibh;
826 struct gfs2_alloc *al = ip->i_alloc; 827 struct gfs2_alloc *al = ip->i_alloc;
827 struct gfs2_dinode *di;
828 unsigned int from = pos & (PAGE_CACHE_SIZE - 1); 828 unsigned int from = pos & (PAGE_CACHE_SIZE - 1);
829 unsigned int to = from + len; 829 unsigned int to = from + len;
830 int ret; 830 int ret;
@@ -847,11 +847,10 @@ static int gfs2_write_end(struct file *file, struct address_space *mapping,
847 gfs2_page_add_databufs(ip, page, from, to); 847 gfs2_page_add_databufs(ip, page, from, to);
848 848
849 ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata); 849 ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata);
850 850 if (ret > 0) {
851 if (likely(ret >= 0) && (inode->i_size > ip->i_disksize)) { 851 if (inode->i_size > ip->i_disksize)
852 di = (struct gfs2_dinode *)dibh->b_data; 852 ip->i_disksize = inode->i_size;
853 ip->i_disksize = inode->i_size; 853 gfs2_dinode_out(ip, dibh->b_data);
854 di->di_size = cpu_to_be64(inode->i_size);
855 mark_inode_dirty(inode); 854 mark_inode_dirty(inode);
856 } 855 }
857 856
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 3a5d3f883e10..329763530dc0 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -25,7 +25,6 @@
25#include "trans.h" 25#include "trans.h"
26#include "dir.h" 26#include "dir.h"
27#include "util.h" 27#include "util.h"
28#include "ops_address.h"
29 28
30/* This doesn't need to be that large as max 64 bit pointers in a 4k 29/* This doesn't need to be that large as max 64 bit pointers in a 4k
31 * block is 512, so __u16 is fine for that. It saves stack space to 30 * block is 512, so __u16 is fine for that. It saves stack space to
@@ -136,7 +135,9 @@ int gfs2_unstuff_dinode(struct gfs2_inode *ip, struct page *page)
136 and write it out to disk */ 135 and write it out to disk */
137 136
138 unsigned int n = 1; 137 unsigned int n = 1;
139 block = gfs2_alloc_block(ip, &n); 138 error = gfs2_alloc_block(ip, &block, &n);
139 if (error)
140 goto out_brelse;
140 if (isdir) { 141 if (isdir) {
141 gfs2_trans_add_unrevoke(GFS2_SB(&ip->i_inode), block, 1); 142 gfs2_trans_add_unrevoke(GFS2_SB(&ip->i_inode), block, 1);
142 error = gfs2_dir_get_new_buffer(ip, block, &bh); 143 error = gfs2_dir_get_new_buffer(ip, block, &bh);
@@ -476,8 +477,11 @@ static int gfs2_bmap_alloc(struct inode *inode, const sector_t lblock,
476 blks = dblks + iblks; 477 blks = dblks + iblks;
477 i = sheight; 478 i = sheight;
478 do { 479 do {
480 int error;
479 n = blks - alloced; 481 n = blks - alloced;
480 bn = gfs2_alloc_block(ip, &n); 482 error = gfs2_alloc_block(ip, &bn, &n);
483 if (error)
484 return error;
481 alloced += n; 485 alloced += n;
482 if (state != ALLOC_DATA || gfs2_is_jdata(ip)) 486 if (state != ALLOC_DATA || gfs2_is_jdata(ip))
483 gfs2_trans_add_unrevoke(sdp, bn, n); 487 gfs2_trans_add_unrevoke(sdp, bn, n);
@@ -1008,7 +1012,7 @@ static int gfs2_block_truncate_page(struct address_space *mapping)
1008 gfs2_trans_add_bh(ip->i_gl, bh, 0); 1012 gfs2_trans_add_bh(ip->i_gl, bh, 0);
1009 1013
1010 zero_user(page, offset, length); 1014 zero_user(page, offset, length);
1011 1015 mark_buffer_dirty(bh);
1012unlock: 1016unlock:
1013 unlock_page(page); 1017 unlock_page(page);
1014 page_cache_release(page); 1018 page_cache_release(page);
diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/dentry.c
index 022c66cd5606..022c66cd5606 100644
--- a/fs/gfs2/ops_dentry.c
+++ b/fs/gfs2/dentry.c
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index aef4d0c06748..297d7e5cebad 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -803,13 +803,20 @@ static struct gfs2_leaf *new_leaf(struct inode *inode, struct buffer_head **pbh,
803{ 803{
804 struct gfs2_inode *ip = GFS2_I(inode); 804 struct gfs2_inode *ip = GFS2_I(inode);
805 unsigned int n = 1; 805 unsigned int n = 1;
806 u64 bn = gfs2_alloc_block(ip, &n); 806 u64 bn;
807 struct buffer_head *bh = gfs2_meta_new(ip->i_gl, bn); 807 int error;
808 struct buffer_head *bh;
808 struct gfs2_leaf *leaf; 809 struct gfs2_leaf *leaf;
809 struct gfs2_dirent *dent; 810 struct gfs2_dirent *dent;
810 struct qstr name = { .name = "", .len = 0, .hash = 0 }; 811 struct qstr name = { .name = "", .len = 0, .hash = 0 };
812
813 error = gfs2_alloc_block(ip, &bn, &n);
814 if (error)
815 return NULL;
816 bh = gfs2_meta_new(ip->i_gl, bn);
811 if (!bh) 817 if (!bh)
812 return NULL; 818 return NULL;
819
813 gfs2_trans_add_unrevoke(GFS2_SB(inode), bn, 1); 820 gfs2_trans_add_unrevoke(GFS2_SB(inode), bn, 1);
814 gfs2_trans_add_bh(ip->i_gl, bh, 1); 821 gfs2_trans_add_bh(ip->i_gl, bh, 1);
815 gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF); 822 gfs2_metatype_set(bh, GFS2_METATYPE_LF, GFS2_FORMAT_LF);
diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c
index 899763aed217..07ea9529adda 100644
--- a/fs/gfs2/eattr.c
+++ b/fs/gfs2/eattr.c
@@ -582,8 +582,11 @@ static int ea_alloc_blk(struct gfs2_inode *ip, struct buffer_head **bhp)
582 struct gfs2_ea_header *ea; 582 struct gfs2_ea_header *ea;
583 unsigned int n = 1; 583 unsigned int n = 1;
584 u64 block; 584 u64 block;
585 int error;
585 586
586 block = gfs2_alloc_block(ip, &n); 587 error = gfs2_alloc_block(ip, &block, &n);
588 if (error)
589 return error;
587 gfs2_trans_add_unrevoke(sdp, block, 1); 590 gfs2_trans_add_unrevoke(sdp, block, 1);
588 *bhp = gfs2_meta_new(ip->i_gl, block); 591 *bhp = gfs2_meta_new(ip->i_gl, block);
589 gfs2_trans_add_bh(ip->i_gl, *bhp, 1); 592 gfs2_trans_add_bh(ip->i_gl, *bhp, 1);
@@ -617,6 +620,7 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
617 struct gfs2_ea_request *er) 620 struct gfs2_ea_request *er)
618{ 621{
619 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 622 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
623 int error;
620 624
621 ea->ea_data_len = cpu_to_be32(er->er_data_len); 625 ea->ea_data_len = cpu_to_be32(er->er_data_len);
622 ea->ea_name_len = er->er_name_len; 626 ea->ea_name_len = er->er_name_len;
@@ -642,7 +646,9 @@ static int ea_write(struct gfs2_inode *ip, struct gfs2_ea_header *ea,
642 int mh_size = sizeof(struct gfs2_meta_header); 646 int mh_size = sizeof(struct gfs2_meta_header);
643 unsigned int n = 1; 647 unsigned int n = 1;
644 648
645 block = gfs2_alloc_block(ip, &n); 649 error = gfs2_alloc_block(ip, &block, &n);
650 if (error)
651 return error;
646 gfs2_trans_add_unrevoke(sdp, block, 1); 652 gfs2_trans_add_unrevoke(sdp, block, 1);
647 bh = gfs2_meta_new(ip->i_gl, block); 653 bh = gfs2_meta_new(ip->i_gl, block);
648 gfs2_trans_add_bh(ip->i_gl, bh, 1); 654 gfs2_trans_add_bh(ip->i_gl, bh, 1);
@@ -963,7 +969,9 @@ static int ea_set_block(struct gfs2_inode *ip, struct gfs2_ea_request *er,
963 } else { 969 } else {
964 u64 blk; 970 u64 blk;
965 unsigned int n = 1; 971 unsigned int n = 1;
966 blk = gfs2_alloc_block(ip, &n); 972 error = gfs2_alloc_block(ip, &blk, &n);
973 if (error)
974 return error;
967 gfs2_trans_add_unrevoke(sdp, blk, 1); 975 gfs2_trans_add_unrevoke(sdp, blk, 1);
968 indbh = gfs2_meta_new(ip->i_gl, blk); 976 indbh = gfs2_meta_new(ip->i_gl, blk);
969 gfs2_trans_add_bh(ip->i_gl, indbh, 1); 977 gfs2_trans_add_bh(ip->i_gl, indbh, 1);
diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/export.c
index 9200ef221716..9200ef221716 100644
--- a/fs/gfs2/ops_export.c
+++ b/fs/gfs2/export.c
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/file.c
index 5d82e91887e3..73318a3ce6f1 100644
--- a/fs/gfs2/ops_file.c
+++ b/fs/gfs2/file.c
@@ -39,7 +39,6 @@
39#include "trans.h" 39#include "trans.h"
40#include "util.h" 40#include "util.h"
41#include "eaops.h" 41#include "eaops.h"
42#include "ops_address.h"
43 42
44/** 43/**
45 * gfs2_llseek - seek to a location in a file 44 * gfs2_llseek - seek to a location in a file
@@ -425,33 +424,36 @@ static struct vm_operations_struct gfs2_vm_ops = {
425 .page_mkwrite = gfs2_page_mkwrite, 424 .page_mkwrite = gfs2_page_mkwrite,
426}; 425};
427 426
428
429/** 427/**
430 * gfs2_mmap - 428 * gfs2_mmap -
431 * @file: The file to map 429 * @file: The file to map
432 * @vma: The VMA which described the mapping 430 * @vma: The VMA which described the mapping
433 * 431 *
434 * Returns: 0 or error code 432 * There is no need to get a lock here unless we should be updating
433 * atime. We ignore any locking errors since the only consequence is
434 * a missed atime update (which will just be deferred until later).
435 *
436 * Returns: 0
435 */ 437 */
436 438
437static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) 439static int gfs2_mmap(struct file *file, struct vm_area_struct *vma)
438{ 440{
439 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); 441 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
440 struct gfs2_holder i_gh;
441 int error;
442 442
443 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh); 443 if (!(file->f_flags & O_NOATIME)) {
444 error = gfs2_glock_nq(&i_gh); 444 struct gfs2_holder i_gh;
445 if (error) { 445 int error;
446 gfs2_holder_uninit(&i_gh);
447 return error;
448 }
449 446
447 gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh);
448 error = gfs2_glock_nq(&i_gh);
449 file_accessed(file);
450 if (error == 0)
451 gfs2_glock_dq_uninit(&i_gh);
452 }
450 vma->vm_ops = &gfs2_vm_ops; 453 vma->vm_ops = &gfs2_vm_ops;
454 vma->vm_flags |= VM_CAN_NONLINEAR;
451 455
452 gfs2_glock_dq_uninit(&i_gh); 456 return 0;
453
454 return error;
455} 457}
456 458
457/** 459/**
@@ -692,12 +694,10 @@ static void do_unflock(struct file *file, struct file_lock *fl)
692 694
693static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl) 695static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl)
694{ 696{
695 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
696
697 if (!(fl->fl_flags & FL_FLOCK)) 697 if (!(fl->fl_flags & FL_FLOCK))
698 return -ENOLCK; 698 return -ENOLCK;
699 if (__mandatory_lock(&ip->i_inode)) 699 if (fl->fl_type & LOCK_MAND)
700 return -ENOLCK; 700 return -EOPNOTSUPP;
701 701
702 if (fl->fl_type == F_UNLCK) { 702 if (fl->fl_type == F_UNLCK) {
703 do_unflock(file, fl); 703 do_unflock(file, fl);
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index ff4981090489..2bf62bcc5181 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -796,22 +796,37 @@ void gfs2_holder_uninit(struct gfs2_holder *gh)
796 gh->gh_ip = 0; 796 gh->gh_ip = 0;
797} 797}
798 798
799static int just_schedule(void *word) 799/**
800 * gfs2_glock_holder_wait
801 * @word: unused
802 *
803 * This function and gfs2_glock_demote_wait both show up in the WCHAN
804 * field. Thus I've separated these otherwise identical functions in
805 * order to be more informative to the user.
806 */
807
808static int gfs2_glock_holder_wait(void *word)
800{ 809{
801 schedule(); 810 schedule();
802 return 0; 811 return 0;
803} 812}
804 813
814static int gfs2_glock_demote_wait(void *word)
815{
816 schedule();
817 return 0;
818}
819
805static void wait_on_holder(struct gfs2_holder *gh) 820static void wait_on_holder(struct gfs2_holder *gh)
806{ 821{
807 might_sleep(); 822 might_sleep();
808 wait_on_bit(&gh->gh_iflags, HIF_WAIT, just_schedule, TASK_UNINTERRUPTIBLE); 823 wait_on_bit(&gh->gh_iflags, HIF_WAIT, gfs2_glock_holder_wait, TASK_UNINTERRUPTIBLE);
809} 824}
810 825
811static void wait_on_demote(struct gfs2_glock *gl) 826static void wait_on_demote(struct gfs2_glock *gl)
812{ 827{
813 might_sleep(); 828 might_sleep();
814 wait_on_bit(&gl->gl_flags, GLF_DEMOTE, just_schedule, TASK_UNINTERRUPTIBLE); 829 wait_on_bit(&gl->gl_flags, GLF_DEMOTE, gfs2_glock_demote_wait, TASK_UNINTERRUPTIBLE);
815} 830}
816 831
817/** 832/**
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c
index 70f87f43afa2..d5e4ab155ca0 100644
--- a/fs/gfs2/glops.c
+++ b/fs/gfs2/glops.c
@@ -310,24 +310,6 @@ static void rgrp_go_unlock(struct gfs2_holder *gh)
310} 310}
311 311
312/** 312/**
313 * rgrp_go_dump - print out an rgrp
314 * @seq: The iterator
315 * @gl: The glock in question
316 *
317 */
318
319static int rgrp_go_dump(struct seq_file *seq, const struct gfs2_glock *gl)
320{
321 const struct gfs2_rgrpd *rgd = gl->gl_object;
322 if (rgd == NULL)
323 return 0;
324 gfs2_print_dbg(seq, " R: n:%llu f:%02x b:%u/%u i:%u\n",
325 (unsigned long long)rgd->rd_addr, rgd->rd_flags,
326 rgd->rd_free, rgd->rd_free_clone, rgd->rd_dinodes);
327 return 0;
328}
329
330/**
331 * trans_go_sync - promote/demote the transaction glock 313 * trans_go_sync - promote/demote the transaction glock
332 * @gl: the glock 314 * @gl: the glock
333 * @state: the requested state 315 * @state: the requested state
@@ -410,7 +392,7 @@ const struct gfs2_glock_operations gfs2_rgrp_glops = {
410 .go_demote_ok = rgrp_go_demote_ok, 392 .go_demote_ok = rgrp_go_demote_ok,
411 .go_lock = rgrp_go_lock, 393 .go_lock = rgrp_go_lock,
412 .go_unlock = rgrp_go_unlock, 394 .go_unlock = rgrp_go_unlock,
413 .go_dump = rgrp_go_dump, 395 .go_dump = gfs2_rgrp_dump,
414 .go_type = LM_TYPE_RGRP, 396 .go_type = LM_TYPE_RGRP,
415 .go_min_hold_time = HZ / 5, 397 .go_min_hold_time = HZ / 5,
416}; 398};
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 399d1b978049..225347fbff3c 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -12,6 +12,7 @@
12 12
13#include <linux/fs.h> 13#include <linux/fs.h>
14#include <linux/workqueue.h> 14#include <linux/workqueue.h>
15#include <linux/slow-work.h>
15#include <linux/dlm.h> 16#include <linux/dlm.h>
16#include <linux/buffer_head.h> 17#include <linux/buffer_head.h>
17 18
@@ -63,9 +64,12 @@ struct gfs2_log_element {
63 const struct gfs2_log_operations *le_ops; 64 const struct gfs2_log_operations *le_ops;
64}; 65};
65 66
67#define GBF_FULL 1
68
66struct gfs2_bitmap { 69struct gfs2_bitmap {
67 struct buffer_head *bi_bh; 70 struct buffer_head *bi_bh;
68 char *bi_clone; 71 char *bi_clone;
72 unsigned long bi_flags;
69 u32 bi_offset; 73 u32 bi_offset;
70 u32 bi_start; 74 u32 bi_start;
71 u32 bi_len; 75 u32 bi_len;
@@ -90,10 +94,11 @@ struct gfs2_rgrpd {
90 struct gfs2_sbd *rd_sbd; 94 struct gfs2_sbd *rd_sbd;
91 unsigned int rd_bh_count; 95 unsigned int rd_bh_count;
92 u32 rd_last_alloc; 96 u32 rd_last_alloc;
93 unsigned char rd_flags; 97 u32 rd_flags;
94#define GFS2_RDF_CHECK 0x01 /* Need to check for unlinked inodes */ 98#define GFS2_RDF_CHECK 0x10000000 /* check for unlinked inodes */
95#define GFS2_RDF_NOALLOC 0x02 /* rg prohibits allocation */ 99#define GFS2_RDF_UPTODATE 0x20000000 /* rg is up to date */
96#define GFS2_RDF_UPTODATE 0x04 /* rg is up to date */ 100#define GFS2_RDF_ERROR 0x40000000 /* error in rg */
101#define GFS2_RDF_MASK 0xf0000000 /* mask for internal flags */
97}; 102};
98 103
99enum gfs2_state_bits { 104enum gfs2_state_bits {
@@ -376,11 +381,11 @@ struct gfs2_journal_extent {
376struct gfs2_jdesc { 381struct gfs2_jdesc {
377 struct list_head jd_list; 382 struct list_head jd_list;
378 struct list_head extent_list; 383 struct list_head extent_list;
379 384 struct slow_work jd_work;
380 struct inode *jd_inode; 385 struct inode *jd_inode;
386 unsigned long jd_flags;
387#define JDF_RECOVERY 1
381 unsigned int jd_jid; 388 unsigned int jd_jid;
382 int jd_dirty;
383
384 unsigned int jd_blocks; 389 unsigned int jd_blocks;
385}; 390};
386 391
@@ -390,9 +395,6 @@ struct gfs2_statfs_change_host {
390 s64 sc_dinodes; 395 s64 sc_dinodes;
391}; 396};
392 397
393#define GFS2_GLOCKD_DEFAULT 1
394#define GFS2_GLOCKD_MAX 16
395
396#define GFS2_QUOTA_DEFAULT GFS2_QUOTA_OFF 398#define GFS2_QUOTA_DEFAULT GFS2_QUOTA_OFF
397#define GFS2_QUOTA_OFF 0 399#define GFS2_QUOTA_OFF 0
398#define GFS2_QUOTA_ACCOUNT 1 400#define GFS2_QUOTA_ACCOUNT 1
@@ -418,6 +420,7 @@ struct gfs2_args {
418 unsigned int ar_data:2; /* ordered/writeback */ 420 unsigned int ar_data:2; /* ordered/writeback */
419 unsigned int ar_meta:1; /* mount metafs */ 421 unsigned int ar_meta:1; /* mount metafs */
420 unsigned int ar_discard:1; /* discard requests */ 422 unsigned int ar_discard:1; /* discard requests */
423 int ar_commit; /* Commit interval */
421}; 424};
422 425
423struct gfs2_tune { 426struct gfs2_tune {
@@ -426,7 +429,6 @@ struct gfs2_tune {
426 unsigned int gt_incore_log_blocks; 429 unsigned int gt_incore_log_blocks;
427 unsigned int gt_log_flush_secs; 430 unsigned int gt_log_flush_secs;
428 431
429 unsigned int gt_recoverd_secs;
430 unsigned int gt_logd_secs; 432 unsigned int gt_logd_secs;
431 433
432 unsigned int gt_quota_simul_sync; /* Max quotavals to sync at once */ 434 unsigned int gt_quota_simul_sync; /* Max quotavals to sync at once */
@@ -447,6 +449,7 @@ enum {
447 SDF_JOURNAL_LIVE = 1, 449 SDF_JOURNAL_LIVE = 1,
448 SDF_SHUTDOWN = 2, 450 SDF_SHUTDOWN = 2,
449 SDF_NOBARRIERS = 3, 451 SDF_NOBARRIERS = 3,
452 SDF_NORECOVERY = 4,
450}; 453};
451 454
452#define GFS2_FSNAME_LEN 256 455#define GFS2_FSNAME_LEN 256
@@ -493,7 +496,6 @@ struct lm_lockstruct {
493 unsigned long ls_flags; 496 unsigned long ls_flags;
494 dlm_lockspace_t *ls_dlm; 497 dlm_lockspace_t *ls_dlm;
495 498
496 int ls_recover_jid;
497 int ls_recover_jid_done; 499 int ls_recover_jid_done;
498 int ls_recover_jid_status; 500 int ls_recover_jid_status;
499}; 501};
@@ -582,7 +584,6 @@ struct gfs2_sbd {
582 584
583 /* Daemon stuff */ 585 /* Daemon stuff */
584 586
585 struct task_struct *sd_recoverd_process;
586 struct task_struct *sd_logd_process; 587 struct task_struct *sd_logd_process;
587 struct task_struct *sd_quotad_process; 588 struct task_struct *sd_quotad_process;
588 589
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 5a31d426116f..2f94bd723698 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -30,7 +30,6 @@
30#include "inode.h" 30#include "inode.h"
31#include "log.h" 31#include "log.h"
32#include "meta_io.h" 32#include "meta_io.h"
33#include "ops_address.h"
34#include "quota.h" 33#include "quota.h"
35#include "rgrp.h" 34#include "rgrp.h"
36#include "trans.h" 35#include "trans.h"
@@ -1047,154 +1046,7 @@ fail:
1047 return ERR_PTR(error); 1046 return ERR_PTR(error);
1048} 1047}
1049 1048
1050/** 1049static int __gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
1051 * gfs2_rmdiri - Remove a directory
1052 * @dip: The parent directory of the directory to be removed
1053 * @name: The name of the directory to be removed
1054 * @ip: The GFS2 inode of the directory to be removed
1055 *
1056 * Assumes Glocks on dip and ip are held
1057 *
1058 * Returns: errno
1059 */
1060
1061int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name,
1062 struct gfs2_inode *ip)
1063{
1064 struct qstr dotname;
1065 int error;
1066
1067 if (ip->i_entries != 2) {
1068 if (gfs2_consist_inode(ip))
1069 gfs2_dinode_print(ip);
1070 return -EIO;
1071 }
1072
1073 error = gfs2_dir_del(dip, name);
1074 if (error)
1075 return error;
1076
1077 error = gfs2_change_nlink(dip, -1);
1078 if (error)
1079 return error;
1080
1081 gfs2_str2qstr(&dotname, ".");
1082 error = gfs2_dir_del(ip, &dotname);
1083 if (error)
1084 return error;
1085
1086 gfs2_str2qstr(&dotname, "..");
1087 error = gfs2_dir_del(ip, &dotname);
1088 if (error)
1089 return error;
1090
1091 /* It looks odd, but it really should be done twice */
1092 error = gfs2_change_nlink(ip, -1);
1093 if (error)
1094 return error;
1095
1096 error = gfs2_change_nlink(ip, -1);
1097 if (error)
1098 return error;
1099
1100 return error;
1101}
1102
1103/*
1104 * gfs2_unlink_ok - check to see that a inode is still in a directory
1105 * @dip: the directory
1106 * @name: the name of the file
1107 * @ip: the inode
1108 *
1109 * Assumes that the lock on (at least) @dip is held.
1110 *
1111 * Returns: 0 if the parent/child relationship is correct, errno if it isn't
1112 */
1113
1114int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,
1115 const struct gfs2_inode *ip)
1116{
1117 int error;
1118
1119 if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode))
1120 return -EPERM;
1121
1122 if ((dip->i_inode.i_mode & S_ISVTX) &&
1123 dip->i_inode.i_uid != current_fsuid() &&
1124 ip->i_inode.i_uid != current_fsuid() && !capable(CAP_FOWNER))
1125 return -EPERM;
1126
1127 if (IS_APPEND(&dip->i_inode))
1128 return -EPERM;
1129
1130 error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC);
1131 if (error)
1132 return error;
1133
1134 error = gfs2_dir_check(&dip->i_inode, name, ip);
1135 if (error)
1136 return error;
1137
1138 return 0;
1139}
1140
1141/**
1142 * gfs2_readlinki - return the contents of a symlink
1143 * @ip: the symlink's inode
1144 * @buf: a pointer to the buffer to be filled
1145 * @len: a pointer to the length of @buf
1146 *
1147 * If @buf is too small, a piece of memory is kmalloc()ed and needs
1148 * to be freed by the caller.
1149 *
1150 * Returns: errno
1151 */
1152
1153int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len)
1154{
1155 struct gfs2_holder i_gh;
1156 struct buffer_head *dibh;
1157 unsigned int x;
1158 int error;
1159
1160 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh);
1161 error = gfs2_glock_nq(&i_gh);
1162 if (error) {
1163 gfs2_holder_uninit(&i_gh);
1164 return error;
1165 }
1166
1167 if (!ip->i_disksize) {
1168 gfs2_consist_inode(ip);
1169 error = -EIO;
1170 goto out;
1171 }
1172
1173 error = gfs2_meta_inode_buffer(ip, &dibh);
1174 if (error)
1175 goto out;
1176
1177 x = ip->i_disksize + 1;
1178 if (x > *len) {
1179 *buf = kmalloc(x, GFP_NOFS);
1180 if (!*buf) {
1181 error = -ENOMEM;
1182 goto out_brelse;
1183 }
1184 }
1185
1186 memcpy(*buf, dibh->b_data + sizeof(struct gfs2_dinode), x);
1187 *len = x;
1188
1189out_brelse:
1190 brelse(dibh);
1191out:
1192 gfs2_glock_dq_uninit(&i_gh);
1193 return error;
1194}
1195
1196static int
1197__gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr)
1198{ 1050{
1199 struct buffer_head *dibh; 1051 struct buffer_head *dibh;
1200 int error; 1052 int error;
diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h
index c30be2b66580..c341aaf67adb 100644
--- a/fs/gfs2/inode.h
+++ b/fs/gfs2/inode.h
@@ -11,8 +11,16 @@
11#define __INODE_DOT_H__ 11#define __INODE_DOT_H__
12 12
13#include <linux/fs.h> 13#include <linux/fs.h>
14#include <linux/buffer_head.h>
15#include <linux/mm.h>
14#include "util.h" 16#include "util.h"
15 17
18extern int gfs2_releasepage(struct page *page, gfp_t gfp_mask);
19extern int gfs2_internal_read(struct gfs2_inode *ip,
20 struct file_ra_state *ra_state,
21 char *buf, loff_t *pos, unsigned size);
22extern void gfs2_set_aops(struct inode *inode);
23
16static inline int gfs2_is_stuffed(const struct gfs2_inode *ip) 24static inline int gfs2_is_stuffed(const struct gfs2_inode *ip)
17{ 25{
18 return !ip->i_height; 26 return !ip->i_height;
@@ -73,30 +81,26 @@ static inline void gfs2_inum_out(const struct gfs2_inode *ip,
73} 81}
74 82
75 83
76void gfs2_set_iop(struct inode *inode); 84extern void gfs2_set_iop(struct inode *inode);
77struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned type, 85extern struct inode *gfs2_inode_lookup(struct super_block *sb, unsigned type,
78 u64 no_addr, u64 no_formal_ino, 86 u64 no_addr, u64 no_formal_ino,
79 int skip_freeing); 87 int skip_freeing);
80struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr); 88extern struct inode *gfs2_ilookup(struct super_block *sb, u64 no_addr);
81 89
82int gfs2_inode_refresh(struct gfs2_inode *ip); 90extern int gfs2_inode_refresh(struct gfs2_inode *ip);
83 91
84int gfs2_dinode_dealloc(struct gfs2_inode *inode); 92extern int gfs2_dinode_dealloc(struct gfs2_inode *inode);
85int gfs2_change_nlink(struct gfs2_inode *ip, int diff); 93extern int gfs2_change_nlink(struct gfs2_inode *ip, int diff);
86struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name, 94extern struct inode *gfs2_lookupi(struct inode *dir, const struct qstr *name,
87 int is_root); 95 int is_root);
88struct inode *gfs2_createi(struct gfs2_holder *ghs, const struct qstr *name, 96extern struct inode *gfs2_createi(struct gfs2_holder *ghs,
89 unsigned int mode, dev_t dev); 97 const struct qstr *name,
90int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name, 98 unsigned int mode, dev_t dev);
91 struct gfs2_inode *ip); 99extern int gfs2_permission(struct inode *inode, int mask);
92int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name, 100extern int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr);
93 const struct gfs2_inode *ip); 101extern struct inode *gfs2_lookup_simple(struct inode *dip, const char *name);
94int gfs2_permission(struct inode *inode, int mask); 102extern void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf);
95int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len); 103extern void gfs2_dinode_print(const struct gfs2_inode *ip);
96int gfs2_setattr_simple(struct gfs2_inode *ip, struct iattr *attr);
97struct inode *gfs2_lookup_simple(struct inode *dip, const char *name);
98void gfs2_dinode_out(const struct gfs2_inode *ip, void *buf);
99void gfs2_dinode_print(const struct gfs2_inode *ip);
100 104
101extern const struct inode_operations gfs2_file_iops; 105extern const struct inode_operations gfs2_file_iops;
102extern const struct inode_operations gfs2_dir_iops; 106extern const struct inode_operations gfs2_dir_iops;
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index 98918a756410..aa62cf5976e8 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -120,7 +120,7 @@ __acquires(&sdp->sd_log_lock)
120 lock_buffer(bh); 120 lock_buffer(bh);
121 if (test_clear_buffer_dirty(bh)) { 121 if (test_clear_buffer_dirty(bh)) {
122 bh->b_end_io = end_buffer_write_sync; 122 bh->b_end_io = end_buffer_write_sync;
123 submit_bh(WRITE, bh); 123 submit_bh(WRITE_SYNC_PLUG, bh);
124 } else { 124 } else {
125 unlock_buffer(bh); 125 unlock_buffer(bh);
126 brelse(bh); 126 brelse(bh);
@@ -604,7 +604,7 @@ static void log_write_header(struct gfs2_sbd *sdp, u32 flags, int pull)
604 if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags)) 604 if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags))
605 goto skip_barrier; 605 goto skip_barrier;
606 get_bh(bh); 606 get_bh(bh);
607 submit_bh(WRITE_BARRIER | (1 << BIO_RW_META), bh); 607 submit_bh(WRITE_SYNC | (1 << BIO_RW_BARRIER) | (1 << BIO_RW_META), bh);
608 wait_on_buffer(bh); 608 wait_on_buffer(bh);
609 if (buffer_eopnotsupp(bh)) { 609 if (buffer_eopnotsupp(bh)) {
610 clear_buffer_eopnotsupp(bh); 610 clear_buffer_eopnotsupp(bh);
@@ -664,7 +664,7 @@ static void gfs2_ordered_write(struct gfs2_sbd *sdp)
664 lock_buffer(bh); 664 lock_buffer(bh);
665 if (buffer_mapped(bh) && test_clear_buffer_dirty(bh)) { 665 if (buffer_mapped(bh) && test_clear_buffer_dirty(bh)) {
666 bh->b_end_io = end_buffer_write_sync; 666 bh->b_end_io = end_buffer_write_sync;
667 submit_bh(WRITE, bh); 667 submit_bh(WRITE_SYNC_PLUG, bh);
668 } else { 668 } else {
669 unlock_buffer(bh); 669 unlock_buffer(bh);
670 brelse(bh); 670 brelse(bh);
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 80e4f5f898bb..00315f50fa46 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -13,6 +13,8 @@
13#include <linux/completion.h> 13#include <linux/completion.h>
14#include <linux/buffer_head.h> 14#include <linux/buffer_head.h>
15#include <linux/gfs2_ondisk.h> 15#include <linux/gfs2_ondisk.h>
16#include <linux/bio.h>
17#include <linux/fs.h>
16 18
17#include "gfs2.h" 19#include "gfs2.h"
18#include "incore.h" 20#include "incore.h"
@@ -189,7 +191,7 @@ static void buf_lo_before_commit(struct gfs2_sbd *sdp)
189 } 191 }
190 192
191 gfs2_log_unlock(sdp); 193 gfs2_log_unlock(sdp);
192 submit_bh(WRITE, bh); 194 submit_bh(WRITE_SYNC_PLUG, bh);
193 gfs2_log_lock(sdp); 195 gfs2_log_lock(sdp);
194 196
195 n = 0; 197 n = 0;
@@ -199,7 +201,7 @@ static void buf_lo_before_commit(struct gfs2_sbd *sdp)
199 gfs2_log_unlock(sdp); 201 gfs2_log_unlock(sdp);
200 lock_buffer(bd2->bd_bh); 202 lock_buffer(bd2->bd_bh);
201 bh = gfs2_log_fake_buf(sdp, bd2->bd_bh); 203 bh = gfs2_log_fake_buf(sdp, bd2->bd_bh);
202 submit_bh(WRITE, bh); 204 submit_bh(WRITE_SYNC_PLUG, bh);
203 gfs2_log_lock(sdp); 205 gfs2_log_lock(sdp);
204 if (++n >= num) 206 if (++n >= num)
205 break; 207 break;
@@ -341,7 +343,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp)
341 sdp->sd_log_num_revoke--; 343 sdp->sd_log_num_revoke--;
342 344
343 if (offset + sizeof(u64) > sdp->sd_sb.sb_bsize) { 345 if (offset + sizeof(u64) > sdp->sd_sb.sb_bsize) {
344 submit_bh(WRITE, bh); 346 submit_bh(WRITE_SYNC_PLUG, bh);
345 347
346 bh = gfs2_log_get_buf(sdp); 348 bh = gfs2_log_get_buf(sdp);
347 mh = (struct gfs2_meta_header *)bh->b_data; 349 mh = (struct gfs2_meta_header *)bh->b_data;
@@ -358,7 +360,7 @@ static void revoke_lo_before_commit(struct gfs2_sbd *sdp)
358 } 360 }
359 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke); 361 gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke);
360 362
361 submit_bh(WRITE, bh); 363 submit_bh(WRITE_SYNC_PLUG, bh);
362} 364}
363 365
364static void revoke_lo_before_scan(struct gfs2_jdesc *jd, 366static void revoke_lo_before_scan(struct gfs2_jdesc *jd,
@@ -560,7 +562,7 @@ static void gfs2_write_blocks(struct gfs2_sbd *sdp, struct buffer_head *bh,
560 ptr = bh_log_ptr(bh); 562 ptr = bh_log_ptr(bh);
561 563
562 get_bh(bh); 564 get_bh(bh);
563 submit_bh(WRITE, bh); 565 submit_bh(WRITE_SYNC_PLUG, bh);
564 gfs2_log_lock(sdp); 566 gfs2_log_lock(sdp);
565 while(!list_empty(list)) { 567 while(!list_empty(list)) {
566 bd = list_entry(list->next, struct gfs2_bufdata, bd_le.le_list); 568 bd = list_entry(list->next, struct gfs2_bufdata, bd_le.le_list);
@@ -586,7 +588,7 @@ static void gfs2_write_blocks(struct gfs2_sbd *sdp, struct buffer_head *bh,
586 } else { 588 } else {
587 bh1 = gfs2_log_fake_buf(sdp, bd->bd_bh); 589 bh1 = gfs2_log_fake_buf(sdp, bd->bd_bh);
588 } 590 }
589 submit_bh(WRITE, bh1); 591 submit_bh(WRITE_SYNC_PLUG, bh1);
590 gfs2_log_lock(sdp); 592 gfs2_log_lock(sdp);
591 ptr += 2; 593 ptr += 2;
592 } 594 }
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index a6892ed0840a..eacd78a5d082 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -15,6 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/gfs2_ondisk.h> 16#include <linux/gfs2_ondisk.h>
17#include <asm/atomic.h> 17#include <asm/atomic.h>
18#include <linux/slow-work.h>
18 19
19#include "gfs2.h" 20#include "gfs2.h"
20#include "incore.h" 21#include "incore.h"
@@ -113,12 +114,18 @@ static int __init init_gfs2_fs(void)
113 if (error) 114 if (error)
114 goto fail_unregister; 115 goto fail_unregister;
115 116
117 error = slow_work_register_user();
118 if (error)
119 goto fail_slow;
120
116 gfs2_register_debugfs(); 121 gfs2_register_debugfs();
117 122
118 printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__); 123 printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__);
119 124
120 return 0; 125 return 0;
121 126
127fail_slow:
128 unregister_filesystem(&gfs2meta_fs_type);
122fail_unregister: 129fail_unregister:
123 unregister_filesystem(&gfs2_fs_type); 130 unregister_filesystem(&gfs2_fs_type);
124fail: 131fail:
@@ -156,6 +163,7 @@ static void __exit exit_gfs2_fs(void)
156 gfs2_unregister_debugfs(); 163 gfs2_unregister_debugfs();
157 unregister_filesystem(&gfs2_fs_type); 164 unregister_filesystem(&gfs2_fs_type);
158 unregister_filesystem(&gfs2meta_fs_type); 165 unregister_filesystem(&gfs2meta_fs_type);
166 slow_work_unregister_user();
159 167
160 kmem_cache_destroy(gfs2_quotad_cachep); 168 kmem_cache_destroy(gfs2_quotad_cachep);
161 kmem_cache_destroy(gfs2_rgrpd_cachep); 169 kmem_cache_destroy(gfs2_rgrpd_cachep);
diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c
index 8d6f13256b26..cb8d7a93d5ec 100644
--- a/fs/gfs2/meta_io.c
+++ b/fs/gfs2/meta_io.c
@@ -31,19 +31,66 @@
31#include "rgrp.h" 31#include "rgrp.h"
32#include "trans.h" 32#include "trans.h"
33#include "util.h" 33#include "util.h"
34#include "ops_address.h"
35 34
36static int aspace_get_block(struct inode *inode, sector_t lblock, 35static int gfs2_aspace_writepage(struct page *page, struct writeback_control *wbc)
37 struct buffer_head *bh_result, int create)
38{ 36{
39 gfs2_assert_warn(inode->i_sb->s_fs_info, 0); 37 int err;
40 return -EOPNOTSUPP; 38 struct buffer_head *bh, *head;
41} 39 int nr_underway = 0;
40 int write_op = (1 << BIO_RW_META) | ((wbc->sync_mode == WB_SYNC_ALL ?
41 WRITE_SYNC_PLUG : WRITE));
42
43 BUG_ON(!PageLocked(page));
44 BUG_ON(!page_has_buffers(page));
45
46 head = page_buffers(page);
47 bh = head;
48
49 do {
50 if (!buffer_mapped(bh))
51 continue;
52 /*
53 * If it's a fully non-blocking write attempt and we cannot
54 * lock the buffer then redirty the page. Note that this can
55 * potentially cause a busy-wait loop from pdflush and kswapd
56 * activity, but those code paths have their own higher-level
57 * throttling.
58 */
59 if (wbc->sync_mode != WB_SYNC_NONE || !wbc->nonblocking) {
60 lock_buffer(bh);
61 } else if (!trylock_buffer(bh)) {
62 redirty_page_for_writepage(wbc, page);
63 continue;
64 }
65 if (test_clear_buffer_dirty(bh)) {
66 mark_buffer_async_write(bh);
67 } else {
68 unlock_buffer(bh);
69 }
70 } while ((bh = bh->b_this_page) != head);
71
72 /*
73 * The page and its buffers are protected by PageWriteback(), so we can
74 * drop the bh refcounts early.
75 */
76 BUG_ON(PageWriteback(page));
77 set_page_writeback(page);
78
79 do {
80 struct buffer_head *next = bh->b_this_page;
81 if (buffer_async_write(bh)) {
82 submit_bh(write_op, bh);
83 nr_underway++;
84 }
85 bh = next;
86 } while (bh != head);
87 unlock_page(page);
42 88
43static int gfs2_aspace_writepage(struct page *page, 89 err = 0;
44 struct writeback_control *wbc) 90 if (nr_underway == 0)
45{ 91 end_page_writeback(page);
46 return block_write_full_page(page, aspace_get_block, wbc); 92
93 return err;
47} 94}
48 95
49static const struct address_space_operations aspace_aops = { 96static const struct address_space_operations aspace_aops = {
@@ -201,16 +248,32 @@ struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno)
201int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags, 248int gfs2_meta_read(struct gfs2_glock *gl, u64 blkno, int flags,
202 struct buffer_head **bhp) 249 struct buffer_head **bhp)
203{ 250{
204 *bhp = gfs2_getbuf(gl, blkno, CREATE); 251 struct gfs2_sbd *sdp = gl->gl_sbd;
205 if (!buffer_uptodate(*bhp)) { 252 struct buffer_head *bh;
206 ll_rw_block(READ_META, 1, bhp); 253
207 if (flags & DIO_WAIT) { 254 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
208 int error = gfs2_meta_wait(gl->gl_sbd, *bhp); 255 return -EIO;
209 if (error) { 256
210 brelse(*bhp); 257 *bhp = bh = gfs2_getbuf(gl, blkno, CREATE);
211 return error; 258
212 } 259 lock_buffer(bh);
213 } 260 if (buffer_uptodate(bh)) {
261 unlock_buffer(bh);
262 return 0;
263 }
264 bh->b_end_io = end_buffer_read_sync;
265 get_bh(bh);
266 submit_bh(READ_SYNC | (1 << BIO_RW_META), bh);
267 if (!(flags & DIO_WAIT))
268 return 0;
269
270 wait_on_buffer(bh);
271 if (unlikely(!buffer_uptodate(bh))) {
272 struct gfs2_trans *tr = current->journal_info;
273 if (tr && tr->tr_touched)
274 gfs2_io_error_bh(sdp, bh);
275 brelse(bh);
276 return -EIO;
214 } 277 }
215 278
216 return 0; 279 return 0;
@@ -404,7 +467,7 @@ struct buffer_head *gfs2_meta_ra(struct gfs2_glock *gl, u64 dblock, u32 extlen)
404 if (buffer_uptodate(first_bh)) 467 if (buffer_uptodate(first_bh))
405 goto out; 468 goto out;
406 if (!buffer_locked(first_bh)) 469 if (!buffer_locked(first_bh))
407 ll_rw_block(READ_META, 1, &first_bh); 470 ll_rw_block(READ_SYNC | (1 << BIO_RW_META), 1, &first_bh);
408 471
409 dblock++; 472 dblock++;
410 extlen--; 473 extlen--;
diff --git a/fs/gfs2/mount.c b/fs/gfs2/mount.c
deleted file mode 100644
index f7e8527a21e0..000000000000
--- a/fs/gfs2/mount.c
+++ /dev/null
@@ -1,185 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include <linux/slab.h>
11#include <linux/spinlock.h>
12#include <linux/completion.h>
13#include <linux/buffer_head.h>
14#include <linux/gfs2_ondisk.h>
15#include <linux/parser.h>
16
17#include "gfs2.h"
18#include "incore.h"
19#include "super.h"
20#include "sys.h"
21#include "util.h"
22
23enum {
24 Opt_lockproto,
25 Opt_locktable,
26 Opt_hostdata,
27 Opt_spectator,
28 Opt_ignore_local_fs,
29 Opt_localflocks,
30 Opt_localcaching,
31 Opt_debug,
32 Opt_nodebug,
33 Opt_upgrade,
34 Opt_acl,
35 Opt_noacl,
36 Opt_quota_off,
37 Opt_quota_account,
38 Opt_quota_on,
39 Opt_quota,
40 Opt_noquota,
41 Opt_suiddir,
42 Opt_nosuiddir,
43 Opt_data_writeback,
44 Opt_data_ordered,
45 Opt_meta,
46 Opt_discard,
47 Opt_nodiscard,
48 Opt_err,
49};
50
51static const match_table_t tokens = {
52 {Opt_lockproto, "lockproto=%s"},
53 {Opt_locktable, "locktable=%s"},
54 {Opt_hostdata, "hostdata=%s"},
55 {Opt_spectator, "spectator"},
56 {Opt_ignore_local_fs, "ignore_local_fs"},
57 {Opt_localflocks, "localflocks"},
58 {Opt_localcaching, "localcaching"},
59 {Opt_debug, "debug"},
60 {Opt_nodebug, "nodebug"},
61 {Opt_upgrade, "upgrade"},
62 {Opt_acl, "acl"},
63 {Opt_noacl, "noacl"},
64 {Opt_quota_off, "quota=off"},
65 {Opt_quota_account, "quota=account"},
66 {Opt_quota_on, "quota=on"},
67 {Opt_quota, "quota"},
68 {Opt_noquota, "noquota"},
69 {Opt_suiddir, "suiddir"},
70 {Opt_nosuiddir, "nosuiddir"},
71 {Opt_data_writeback, "data=writeback"},
72 {Opt_data_ordered, "data=ordered"},
73 {Opt_meta, "meta"},
74 {Opt_discard, "discard"},
75 {Opt_nodiscard, "nodiscard"},
76 {Opt_err, NULL}
77};
78
79/**
80 * gfs2_mount_args - Parse mount options
81 * @sdp:
82 * @data:
83 *
84 * Return: errno
85 */
86
87int gfs2_mount_args(struct gfs2_sbd *sdp, struct gfs2_args *args, char *options)
88{
89 char *o;
90 int token;
91 substring_t tmp[MAX_OPT_ARGS];
92
93 /* Split the options into tokens with the "," character and
94 process them */
95
96 while (1) {
97 o = strsep(&options, ",");
98 if (o == NULL)
99 break;
100 if (*o == '\0')
101 continue;
102
103 token = match_token(o, tokens, tmp);
104 switch (token) {
105 case Opt_lockproto:
106 match_strlcpy(args->ar_lockproto, &tmp[0],
107 GFS2_LOCKNAME_LEN);
108 break;
109 case Opt_locktable:
110 match_strlcpy(args->ar_locktable, &tmp[0],
111 GFS2_LOCKNAME_LEN);
112 break;
113 case Opt_hostdata:
114 match_strlcpy(args->ar_hostdata, &tmp[0],
115 GFS2_LOCKNAME_LEN);
116 break;
117 case Opt_spectator:
118 args->ar_spectator = 1;
119 break;
120 case Opt_ignore_local_fs:
121 args->ar_ignore_local_fs = 1;
122 break;
123 case Opt_localflocks:
124 args->ar_localflocks = 1;
125 break;
126 case Opt_localcaching:
127 args->ar_localcaching = 1;
128 break;
129 case Opt_debug:
130 args->ar_debug = 1;
131 break;
132 case Opt_nodebug:
133 args->ar_debug = 0;
134 break;
135 case Opt_upgrade:
136 args->ar_upgrade = 1;
137 break;
138 case Opt_acl:
139 args->ar_posix_acl = 1;
140 break;
141 case Opt_noacl:
142 args->ar_posix_acl = 0;
143 break;
144 case Opt_quota_off:
145 case Opt_noquota:
146 args->ar_quota = GFS2_QUOTA_OFF;
147 break;
148 case Opt_quota_account:
149 args->ar_quota = GFS2_QUOTA_ACCOUNT;
150 break;
151 case Opt_quota_on:
152 case Opt_quota:
153 args->ar_quota = GFS2_QUOTA_ON;
154 break;
155 case Opt_suiddir:
156 args->ar_suiddir = 1;
157 break;
158 case Opt_nosuiddir:
159 args->ar_suiddir = 0;
160 break;
161 case Opt_data_writeback:
162 args->ar_data = GFS2_DATA_WRITEBACK;
163 break;
164 case Opt_data_ordered:
165 args->ar_data = GFS2_DATA_ORDERED;
166 break;
167 case Opt_meta:
168 args->ar_meta = 1;
169 break;
170 case Opt_discard:
171 args->ar_discard = 1;
172 break;
173 case Opt_nodiscard:
174 args->ar_discard = 0;
175 break;
176 case Opt_err:
177 default:
178 fs_info(sdp, "invalid mount option: %s\n", o);
179 return -EINVAL;
180 }
181 }
182
183 return 0;
184}
185
diff --git a/fs/gfs2/ops_address.h b/fs/gfs2/ops_address.h
deleted file mode 100644
index 5da21285bba4..000000000000
--- a/fs/gfs2/ops_address.h
+++ /dev/null
@@ -1,23 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#ifndef __OPS_ADDRESS_DOT_H__
11#define __OPS_ADDRESS_DOT_H__
12
13#include <linux/fs.h>
14#include <linux/buffer_head.h>
15#include <linux/mm.h>
16
17extern int gfs2_releasepage(struct page *page, gfp_t gfp_mask);
18extern int gfs2_internal_read(struct gfs2_inode *ip,
19 struct file_ra_state *ra_state,
20 char *buf, loff_t *pos, unsigned size);
21extern void gfs2_set_aops(struct inode *inode);
22
23#endif /* __OPS_ADDRESS_DOT_H__ */
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index 1ff9473ea753..cc34f271b3e7 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -17,6 +17,7 @@
17#include <linux/namei.h> 17#include <linux/namei.h>
18#include <linux/mount.h> 18#include <linux/mount.h>
19#include <linux/gfs2_ondisk.h> 19#include <linux/gfs2_ondisk.h>
20#include <linux/slow-work.h>
20 21
21#include "gfs2.h" 22#include "gfs2.h"
22#include "incore.h" 23#include "incore.h"
@@ -55,8 +56,6 @@ static void gfs2_tune_init(struct gfs2_tune *gt)
55 spin_lock_init(&gt->gt_spin); 56 spin_lock_init(&gt->gt_spin);
56 57
57 gt->gt_incore_log_blocks = 1024; 58 gt->gt_incore_log_blocks = 1024;
58 gt->gt_log_flush_secs = 60;
59 gt->gt_recoverd_secs = 60;
60 gt->gt_logd_secs = 1; 59 gt->gt_logd_secs = 1;
61 gt->gt_quota_simul_sync = 64; 60 gt->gt_quota_simul_sync = 64;
62 gt->gt_quota_warn_period = 10; 61 gt->gt_quota_warn_period = 10;
@@ -526,11 +525,11 @@ static int init_sb(struct gfs2_sbd *sdp, int silent)
526 } 525 }
527 526
528 /* Set up the buffer cache and SB for real */ 527 /* Set up the buffer cache and SB for real */
529 if (sdp->sd_sb.sb_bsize < bdev_hardsect_size(sb->s_bdev)) { 528 if (sdp->sd_sb.sb_bsize < bdev_logical_block_size(sb->s_bdev)) {
530 ret = -EINVAL; 529 ret = -EINVAL;
531 fs_err(sdp, "FS block size (%u) is too small for device " 530 fs_err(sdp, "FS block size (%u) is too small for device "
532 "block size (%u)\n", 531 "block size (%u)\n",
533 sdp->sd_sb.sb_bsize, bdev_hardsect_size(sb->s_bdev)); 532 sdp->sd_sb.sb_bsize, bdev_logical_block_size(sb->s_bdev));
534 goto out; 533 goto out;
535 } 534 }
536 if (sdp->sd_sb.sb_bsize > PAGE_SIZE) { 535 if (sdp->sd_sb.sb_bsize > PAGE_SIZE) {
@@ -676,6 +675,7 @@ static int gfs2_jindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ji_gh)
676 break; 675 break;
677 676
678 INIT_LIST_HEAD(&jd->extent_list); 677 INIT_LIST_HEAD(&jd->extent_list);
678 slow_work_init(&jd->jd_work, &gfs2_recover_ops);
679 jd->jd_inode = gfs2_lookupi(sdp->sd_jindex, &name, 1); 679 jd->jd_inode = gfs2_lookupi(sdp->sd_jindex, &name, 1);
680 if (!jd->jd_inode || IS_ERR(jd->jd_inode)) { 680 if (!jd->jd_inode || IS_ERR(jd->jd_inode)) {
681 if (!jd->jd_inode) 681 if (!jd->jd_inode)
@@ -701,14 +701,13 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
701{ 701{
702 struct inode *master = sdp->sd_master_dir->d_inode; 702 struct inode *master = sdp->sd_master_dir->d_inode;
703 struct gfs2_holder ji_gh; 703 struct gfs2_holder ji_gh;
704 struct task_struct *p;
705 struct gfs2_inode *ip; 704 struct gfs2_inode *ip;
706 int jindex = 1; 705 int jindex = 1;
707 int error = 0; 706 int error = 0;
708 707
709 if (undo) { 708 if (undo) {
710 jindex = 0; 709 jindex = 0;
711 goto fail_recoverd; 710 goto fail_jinode_gh;
712 } 711 }
713 712
714 sdp->sd_jindex = gfs2_lookup_simple(master, "jindex"); 713 sdp->sd_jindex = gfs2_lookup_simple(master, "jindex");
@@ -801,18 +800,8 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
801 gfs2_glock_dq_uninit(&ji_gh); 800 gfs2_glock_dq_uninit(&ji_gh);
802 jindex = 0; 801 jindex = 0;
803 802
804 p = kthread_run(gfs2_recoverd, sdp, "gfs2_recoverd");
805 error = IS_ERR(p);
806 if (error) {
807 fs_err(sdp, "can't start recoverd thread: %d\n", error);
808 goto fail_jinode_gh;
809 }
810 sdp->sd_recoverd_process = p;
811
812 return 0; 803 return 0;
813 804
814fail_recoverd:
815 kthread_stop(sdp->sd_recoverd_process);
816fail_jinode_gh: 805fail_jinode_gh:
817 if (!sdp->sd_args.ar_spectator) 806 if (!sdp->sd_args.ar_spectator)
818 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh); 807 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
@@ -1165,6 +1154,7 @@ static int fill_super(struct super_block *sb, void *data, int silent)
1165 1154
1166 sdp->sd_args.ar_quota = GFS2_QUOTA_DEFAULT; 1155 sdp->sd_args.ar_quota = GFS2_QUOTA_DEFAULT;
1167 sdp->sd_args.ar_data = GFS2_DATA_DEFAULT; 1156 sdp->sd_args.ar_data = GFS2_DATA_DEFAULT;
1157 sdp->sd_args.ar_commit = 60;
1168 1158
1169 error = gfs2_mount_args(sdp, &sdp->sd_args, data); 1159 error = gfs2_mount_args(sdp, &sdp->sd_args, data);
1170 if (error) { 1160 if (error) {
@@ -1172,8 +1162,10 @@ static int fill_super(struct super_block *sb, void *data, int silent)
1172 goto fail; 1162 goto fail;
1173 } 1163 }
1174 1164
1175 if (sdp->sd_args.ar_spectator) 1165 if (sdp->sd_args.ar_spectator) {
1176 sb->s_flags |= MS_RDONLY; 1166 sb->s_flags |= MS_RDONLY;
1167 set_bit(SDF_NORECOVERY, &sdp->sd_flags);
1168 }
1177 if (sdp->sd_args.ar_posix_acl) 1169 if (sdp->sd_args.ar_posix_acl)
1178 sb->s_flags |= MS_POSIXACL; 1170 sb->s_flags |= MS_POSIXACL;
1179 1171
@@ -1191,6 +1183,8 @@ static int fill_super(struct super_block *sb, void *data, int silent)
1191 GFS2_BASIC_BLOCK_SHIFT; 1183 GFS2_BASIC_BLOCK_SHIFT;
1192 sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift; 1184 sdp->sd_fsb2bb = 1 << sdp->sd_fsb2bb_shift;
1193 1185
1186 sdp->sd_tune.gt_log_flush_secs = sdp->sd_args.ar_commit;
1187
1194 error = init_names(sdp, silent); 1188 error = init_names(sdp, silent);
1195 if (error) 1189 if (error)
1196 goto fail; 1190 goto fail;
@@ -1279,9 +1273,22 @@ static int gfs2_get_sb(struct file_system_type *fs_type, int flags,
1279 return get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt); 1273 return get_sb_bdev(fs_type, flags, dev_name, data, fill_super, mnt);
1280} 1274}
1281 1275
1282static struct super_block *get_gfs2_sb(const char *dev_name) 1276static int test_meta_super(struct super_block *s, void *ptr)
1277{
1278 struct block_device *bdev = ptr;
1279 return (bdev == s->s_bdev);
1280}
1281
1282static int set_meta_super(struct super_block *s, void *ptr)
1283{ 1283{
1284 struct super_block *sb; 1284 return -EINVAL;
1285}
1286
1287static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags,
1288 const char *dev_name, void *data, struct vfsmount *mnt)
1289{
1290 struct super_block *s;
1291 struct gfs2_sbd *sdp;
1285 struct path path; 1292 struct path path;
1286 int error; 1293 int error;
1287 1294
@@ -1289,30 +1296,17 @@ static struct super_block *get_gfs2_sb(const char *dev_name)
1289 if (error) { 1296 if (error) {
1290 printk(KERN_WARNING "GFS2: path_lookup on %s returned error %d\n", 1297 printk(KERN_WARNING "GFS2: path_lookup on %s returned error %d\n",
1291 dev_name, error); 1298 dev_name, error);
1292 return NULL; 1299 return error;
1293 } 1300 }
1294 sb = path.dentry->d_inode->i_sb; 1301 s = sget(&gfs2_fs_type, test_meta_super, set_meta_super,
1295 if (sb && (sb->s_type == &gfs2_fs_type)) 1302 path.dentry->d_inode->i_sb->s_bdev);
1296 atomic_inc(&sb->s_active);
1297 else
1298 sb = NULL;
1299 path_put(&path); 1303 path_put(&path);
1300 return sb; 1304 if (IS_ERR(s)) {
1301}
1302
1303static int gfs2_get_sb_meta(struct file_system_type *fs_type, int flags,
1304 const char *dev_name, void *data, struct vfsmount *mnt)
1305{
1306 struct super_block *sb = NULL;
1307 struct gfs2_sbd *sdp;
1308
1309 sb = get_gfs2_sb(dev_name);
1310 if (!sb) {
1311 printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n"); 1305 printk(KERN_WARNING "GFS2: gfs2 mount does not exist\n");
1312 return -ENOENT; 1306 return PTR_ERR(s);
1313 } 1307 }
1314 sdp = sb->s_fs_info; 1308 sdp = s->s_fs_info;
1315 mnt->mnt_sb = sb; 1309 mnt->mnt_sb = s;
1316 mnt->mnt_root = dget(sdp->sd_master_dir); 1310 mnt->mnt_root = dget(sdp->sd_master_dir);
1317 return 0; 1311 return 0;
1318} 1312}
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
index 1c70fa5168d6..f8bd20baf99c 100644
--- a/fs/gfs2/ops_inode.c
+++ b/fs/gfs2/ops_inode.c
@@ -262,6 +262,44 @@ out_parent:
262 return error; 262 return error;
263} 263}
264 264
265/*
266 * gfs2_unlink_ok - check to see that a inode is still in a directory
267 * @dip: the directory
268 * @name: the name of the file
269 * @ip: the inode
270 *
271 * Assumes that the lock on (at least) @dip is held.
272 *
273 * Returns: 0 if the parent/child relationship is correct, errno if it isn't
274 */
275
276static int gfs2_unlink_ok(struct gfs2_inode *dip, const struct qstr *name,
277 const struct gfs2_inode *ip)
278{
279 int error;
280
281 if (IS_IMMUTABLE(&ip->i_inode) || IS_APPEND(&ip->i_inode))
282 return -EPERM;
283
284 if ((dip->i_inode.i_mode & S_ISVTX) &&
285 dip->i_inode.i_uid != current_fsuid() &&
286 ip->i_inode.i_uid != current_fsuid() && !capable(CAP_FOWNER))
287 return -EPERM;
288
289 if (IS_APPEND(&dip->i_inode))
290 return -EPERM;
291
292 error = gfs2_permission(&dip->i_inode, MAY_WRITE | MAY_EXEC);
293 if (error)
294 return error;
295
296 error = gfs2_dir_check(&dip->i_inode, name, ip);
297 if (error)
298 return error;
299
300 return 0;
301}
302
265/** 303/**
266 * gfs2_unlink - Unlink a file 304 * gfs2_unlink - Unlink a file
267 * @dir: The inode of the directory containing the file to unlink 305 * @dir: The inode of the directory containing the file to unlink
@@ -473,6 +511,59 @@ static int gfs2_mkdir(struct inode *dir, struct dentry *dentry, int mode)
473} 511}
474 512
475/** 513/**
514 * gfs2_rmdiri - Remove a directory
515 * @dip: The parent directory of the directory to be removed
516 * @name: The name of the directory to be removed
517 * @ip: The GFS2 inode of the directory to be removed
518 *
519 * Assumes Glocks on dip and ip are held
520 *
521 * Returns: errno
522 */
523
524static int gfs2_rmdiri(struct gfs2_inode *dip, const struct qstr *name,
525 struct gfs2_inode *ip)
526{
527 struct qstr dotname;
528 int error;
529
530 if (ip->i_entries != 2) {
531 if (gfs2_consist_inode(ip))
532 gfs2_dinode_print(ip);
533 return -EIO;
534 }
535
536 error = gfs2_dir_del(dip, name);
537 if (error)
538 return error;
539
540 error = gfs2_change_nlink(dip, -1);
541 if (error)
542 return error;
543
544 gfs2_str2qstr(&dotname, ".");
545 error = gfs2_dir_del(ip, &dotname);
546 if (error)
547 return error;
548
549 gfs2_str2qstr(&dotname, "..");
550 error = gfs2_dir_del(ip, &dotname);
551 if (error)
552 return error;
553
554 /* It looks odd, but it really should be done twice */
555 error = gfs2_change_nlink(ip, -1);
556 if (error)
557 return error;
558
559 error = gfs2_change_nlink(ip, -1);
560 if (error)
561 return error;
562
563 return error;
564}
565
566/**
476 * gfs2_rmdir - Remove a directory 567 * gfs2_rmdir - Remove a directory
477 * @dir: The parent directory of the directory to be removed 568 * @dir: The parent directory of the directory to be removed
478 * @dentry: The dentry of the directory to remove 569 * @dentry: The dentry of the directory to remove
@@ -885,6 +976,61 @@ out:
885} 976}
886 977
887/** 978/**
979 * gfs2_readlinki - return the contents of a symlink
980 * @ip: the symlink's inode
981 * @buf: a pointer to the buffer to be filled
982 * @len: a pointer to the length of @buf
983 *
984 * If @buf is too small, a piece of memory is kmalloc()ed and needs
985 * to be freed by the caller.
986 *
987 * Returns: errno
988 */
989
990static int gfs2_readlinki(struct gfs2_inode *ip, char **buf, unsigned int *len)
991{
992 struct gfs2_holder i_gh;
993 struct buffer_head *dibh;
994 unsigned int x;
995 int error;
996
997 gfs2_holder_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh);
998 error = gfs2_glock_nq(&i_gh);
999 if (error) {
1000 gfs2_holder_uninit(&i_gh);
1001 return error;
1002 }
1003
1004 if (!ip->i_disksize) {
1005 gfs2_consist_inode(ip);
1006 error = -EIO;
1007 goto out;
1008 }
1009
1010 error = gfs2_meta_inode_buffer(ip, &dibh);
1011 if (error)
1012 goto out;
1013
1014 x = ip->i_disksize + 1;
1015 if (x > *len) {
1016 *buf = kmalloc(x, GFP_NOFS);
1017 if (!*buf) {
1018 error = -ENOMEM;
1019 goto out_brelse;
1020 }
1021 }
1022
1023 memcpy(*buf, dibh->b_data + sizeof(struct gfs2_dinode), x);
1024 *len = x;
1025
1026out_brelse:
1027 brelse(dibh);
1028out:
1029 gfs2_glock_dq_uninit(&i_gh);
1030 return error;
1031}
1032
1033/**
888 * gfs2_readlink - Read the value of a symlink 1034 * gfs2_readlink - Read the value of a symlink
889 * @dentry: the symlink 1035 * @dentry: the symlink
890 * @buf: the buffer to read the symlink data into 1036 * @buf: the buffer to read the symlink data into
diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c
deleted file mode 100644
index 458019569dcb..000000000000
--- a/fs/gfs2/ops_super.c
+++ /dev/null
@@ -1,723 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include <linux/sched.h>
11#include <linux/slab.h>
12#include <linux/spinlock.h>
13#include <linux/completion.h>
14#include <linux/buffer_head.h>
15#include <linux/statfs.h>
16#include <linux/seq_file.h>
17#include <linux/mount.h>
18#include <linux/kthread.h>
19#include <linux/delay.h>
20#include <linux/gfs2_ondisk.h>
21#include <linux/crc32.h>
22#include <linux/time.h>
23
24#include "gfs2.h"
25#include "incore.h"
26#include "glock.h"
27#include "inode.h"
28#include "log.h"
29#include "quota.h"
30#include "recovery.h"
31#include "rgrp.h"
32#include "super.h"
33#include "sys.h"
34#include "util.h"
35#include "trans.h"
36#include "dir.h"
37#include "eattr.h"
38#include "bmap.h"
39#include "meta_io.h"
40
41#define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)
42
43/**
44 * gfs2_write_inode - Make sure the inode is stable on the disk
45 * @inode: The inode
46 * @sync: synchronous write flag
47 *
48 * Returns: errno
49 */
50
51static int gfs2_write_inode(struct inode *inode, int sync)
52{
53 struct gfs2_inode *ip = GFS2_I(inode);
54 struct gfs2_sbd *sdp = GFS2_SB(inode);
55 struct gfs2_holder gh;
56 struct buffer_head *bh;
57 struct timespec atime;
58 struct gfs2_dinode *di;
59 int ret = 0;
60
61 /* Check this is a "normal" inode, etc */
62 if (!test_bit(GIF_USER, &ip->i_flags) ||
63 (current->flags & PF_MEMALLOC))
64 return 0;
65 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
66 if (ret)
67 goto do_flush;
68 ret = gfs2_trans_begin(sdp, RES_DINODE, 0);
69 if (ret)
70 goto do_unlock;
71 ret = gfs2_meta_inode_buffer(ip, &bh);
72 if (ret == 0) {
73 di = (struct gfs2_dinode *)bh->b_data;
74 atime.tv_sec = be64_to_cpu(di->di_atime);
75 atime.tv_nsec = be32_to_cpu(di->di_atime_nsec);
76 if (timespec_compare(&inode->i_atime, &atime) > 0) {
77 gfs2_trans_add_bh(ip->i_gl, bh, 1);
78 gfs2_dinode_out(ip, bh->b_data);
79 }
80 brelse(bh);
81 }
82 gfs2_trans_end(sdp);
83do_unlock:
84 gfs2_glock_dq_uninit(&gh);
85do_flush:
86 if (sync != 0)
87 gfs2_log_flush(GFS2_SB(inode), ip->i_gl);
88 return ret;
89}
90
91/**
92 * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one
93 * @sdp: the filesystem
94 *
95 * Returns: errno
96 */
97
98static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
99{
100 struct gfs2_holder t_gh;
101 int error;
102
103 gfs2_quota_sync(sdp);
104 gfs2_statfs_sync(sdp);
105
106 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE,
107 &t_gh);
108 if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
109 return error;
110
111 gfs2_meta_syncfs(sdp);
112 gfs2_log_shutdown(sdp);
113
114 clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
115
116 if (t_gh.gh_gl)
117 gfs2_glock_dq_uninit(&t_gh);
118
119 gfs2_quota_cleanup(sdp);
120
121 return error;
122}
123
124/**
125 * gfs2_put_super - Unmount the filesystem
126 * @sb: The VFS superblock
127 *
128 */
129
130static void gfs2_put_super(struct super_block *sb)
131{
132 struct gfs2_sbd *sdp = sb->s_fs_info;
133 int error;
134
135 /* Unfreeze the filesystem, if we need to */
136
137 mutex_lock(&sdp->sd_freeze_lock);
138 if (sdp->sd_freeze_count)
139 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
140 mutex_unlock(&sdp->sd_freeze_lock);
141
142 kthread_stop(sdp->sd_quotad_process);
143 kthread_stop(sdp->sd_logd_process);
144 kthread_stop(sdp->sd_recoverd_process);
145
146 if (!(sb->s_flags & MS_RDONLY)) {
147 error = gfs2_make_fs_ro(sdp);
148 if (error)
149 gfs2_io_error(sdp);
150 }
151 /* At this point, we're through modifying the disk */
152
153 /* Release stuff */
154
155 iput(sdp->sd_jindex);
156 iput(sdp->sd_inum_inode);
157 iput(sdp->sd_statfs_inode);
158 iput(sdp->sd_rindex);
159 iput(sdp->sd_quota_inode);
160
161 gfs2_glock_put(sdp->sd_rename_gl);
162 gfs2_glock_put(sdp->sd_trans_gl);
163
164 if (!sdp->sd_args.ar_spectator) {
165 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
166 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
167 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
168 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
169 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
170 iput(sdp->sd_ir_inode);
171 iput(sdp->sd_sc_inode);
172 iput(sdp->sd_qc_inode);
173 }
174
175 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
176 gfs2_clear_rgrpd(sdp);
177 gfs2_jindex_free(sdp);
178 /* Take apart glock structures and buffer lists */
179 gfs2_gl_hash_clear(sdp);
180 /* Unmount the locking protocol */
181 gfs2_lm_unmount(sdp);
182
183 /* At this point, we're through participating in the lockspace */
184 gfs2_sys_fs_del(sdp);
185}
186
187/**
188 * gfs2_write_super
189 * @sb: the superblock
190 *
191 */
192
193static void gfs2_write_super(struct super_block *sb)
194{
195 sb->s_dirt = 0;
196}
197
198/**
199 * gfs2_sync_fs - sync the filesystem
200 * @sb: the superblock
201 *
202 * Flushes the log to disk.
203 */
204
205static int gfs2_sync_fs(struct super_block *sb, int wait)
206{
207 sb->s_dirt = 0;
208 if (wait && sb->s_fs_info)
209 gfs2_log_flush(sb->s_fs_info, NULL);
210 return 0;
211}
212
213/**
214 * gfs2_freeze - prevent further writes to the filesystem
215 * @sb: the VFS structure for the filesystem
216 *
217 */
218
219static int gfs2_freeze(struct super_block *sb)
220{
221 struct gfs2_sbd *sdp = sb->s_fs_info;
222 int error;
223
224 if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
225 return -EINVAL;
226
227 for (;;) {
228 error = gfs2_freeze_fs(sdp);
229 if (!error)
230 break;
231
232 switch (error) {
233 case -EBUSY:
234 fs_err(sdp, "waiting for recovery before freeze\n");
235 break;
236
237 default:
238 fs_err(sdp, "error freezing FS: %d\n", error);
239 break;
240 }
241
242 fs_err(sdp, "retrying...\n");
243 msleep(1000);
244 }
245 return 0;
246}
247
248/**
249 * gfs2_unfreeze - reallow writes to the filesystem
250 * @sb: the VFS structure for the filesystem
251 *
252 */
253
254static int gfs2_unfreeze(struct super_block *sb)
255{
256 gfs2_unfreeze_fs(sb->s_fs_info);
257 return 0;
258}
259
260/**
261 * statfs_fill - fill in the sg for a given RG
262 * @rgd: the RG
263 * @sc: the sc structure
264 *
265 * Returns: 0 on success, -ESTALE if the LVB is invalid
266 */
267
268static int statfs_slow_fill(struct gfs2_rgrpd *rgd,
269 struct gfs2_statfs_change_host *sc)
270{
271 gfs2_rgrp_verify(rgd);
272 sc->sc_total += rgd->rd_data;
273 sc->sc_free += rgd->rd_free;
274 sc->sc_dinodes += rgd->rd_dinodes;
275 return 0;
276}
277
278/**
279 * gfs2_statfs_slow - Stat a filesystem using asynchronous locking
280 * @sdp: the filesystem
281 * @sc: the sc info that will be returned
282 *
283 * Any error (other than a signal) will cause this routine to fall back
284 * to the synchronous version.
285 *
286 * FIXME: This really shouldn't busy wait like this.
287 *
288 * Returns: errno
289 */
290
291static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
292{
293 struct gfs2_holder ri_gh;
294 struct gfs2_rgrpd *rgd_next;
295 struct gfs2_holder *gha, *gh;
296 unsigned int slots = 64;
297 unsigned int x;
298 int done;
299 int error = 0, err;
300
301 memset(sc, 0, sizeof(struct gfs2_statfs_change_host));
302 gha = kcalloc(slots, sizeof(struct gfs2_holder), GFP_KERNEL);
303 if (!gha)
304 return -ENOMEM;
305
306 error = gfs2_rindex_hold(sdp, &ri_gh);
307 if (error)
308 goto out;
309
310 rgd_next = gfs2_rgrpd_get_first(sdp);
311
312 for (;;) {
313 done = 1;
314
315 for (x = 0; x < slots; x++) {
316 gh = gha + x;
317
318 if (gh->gh_gl && gfs2_glock_poll(gh)) {
319 err = gfs2_glock_wait(gh);
320 if (err) {
321 gfs2_holder_uninit(gh);
322 error = err;
323 } else {
324 if (!error)
325 error = statfs_slow_fill(
326 gh->gh_gl->gl_object, sc);
327 gfs2_glock_dq_uninit(gh);
328 }
329 }
330
331 if (gh->gh_gl)
332 done = 0;
333 else if (rgd_next && !error) {
334 error = gfs2_glock_nq_init(rgd_next->rd_gl,
335 LM_ST_SHARED,
336 GL_ASYNC,
337 gh);
338 rgd_next = gfs2_rgrpd_get_next(rgd_next);
339 done = 0;
340 }
341
342 if (signal_pending(current))
343 error = -ERESTARTSYS;
344 }
345
346 if (done)
347 break;
348
349 yield();
350 }
351
352 gfs2_glock_dq_uninit(&ri_gh);
353
354out:
355 kfree(gha);
356 return error;
357}
358
359/**
360 * gfs2_statfs_i - Do a statfs
361 * @sdp: the filesystem
362 * @sg: the sg structure
363 *
364 * Returns: errno
365 */
366
367static int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
368{
369 struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
370 struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
371
372 spin_lock(&sdp->sd_statfs_spin);
373
374 *sc = *m_sc;
375 sc->sc_total += l_sc->sc_total;
376 sc->sc_free += l_sc->sc_free;
377 sc->sc_dinodes += l_sc->sc_dinodes;
378
379 spin_unlock(&sdp->sd_statfs_spin);
380
381 if (sc->sc_free < 0)
382 sc->sc_free = 0;
383 if (sc->sc_free > sc->sc_total)
384 sc->sc_free = sc->sc_total;
385 if (sc->sc_dinodes < 0)
386 sc->sc_dinodes = 0;
387
388 return 0;
389}
390
391/**
392 * gfs2_statfs - Gather and return stats about the filesystem
393 * @sb: The superblock
394 * @statfsbuf: The buffer
395 *
396 * Returns: 0 on success or error code
397 */
398
399static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
400{
401 struct super_block *sb = dentry->d_inode->i_sb;
402 struct gfs2_sbd *sdp = sb->s_fs_info;
403 struct gfs2_statfs_change_host sc;
404 int error;
405
406 if (gfs2_tune_get(sdp, gt_statfs_slow))
407 error = gfs2_statfs_slow(sdp, &sc);
408 else
409 error = gfs2_statfs_i(sdp, &sc);
410
411 if (error)
412 return error;
413
414 buf->f_type = GFS2_MAGIC;
415 buf->f_bsize = sdp->sd_sb.sb_bsize;
416 buf->f_blocks = sc.sc_total;
417 buf->f_bfree = sc.sc_free;
418 buf->f_bavail = sc.sc_free;
419 buf->f_files = sc.sc_dinodes + sc.sc_free;
420 buf->f_ffree = sc.sc_free;
421 buf->f_namelen = GFS2_FNAMESIZE;
422
423 return 0;
424}
425
426/**
427 * gfs2_remount_fs - called when the FS is remounted
428 * @sb: the filesystem
429 * @flags: the remount flags
430 * @data: extra data passed in (not used right now)
431 *
432 * Returns: errno
433 */
434
435static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
436{
437 struct gfs2_sbd *sdp = sb->s_fs_info;
438 struct gfs2_args args = sdp->sd_args; /* Default to current settings */
439 int error;
440
441 error = gfs2_mount_args(sdp, &args, data);
442 if (error)
443 return error;
444
445 /* Not allowed to change locking details */
446 if (strcmp(args.ar_lockproto, sdp->sd_args.ar_lockproto) ||
447 strcmp(args.ar_locktable, sdp->sd_args.ar_locktable) ||
448 strcmp(args.ar_hostdata, sdp->sd_args.ar_hostdata))
449 return -EINVAL;
450
451 /* Some flags must not be changed */
452 if (args_neq(&args, &sdp->sd_args, spectator) ||
453 args_neq(&args, &sdp->sd_args, ignore_local_fs) ||
454 args_neq(&args, &sdp->sd_args, localflocks) ||
455 args_neq(&args, &sdp->sd_args, localcaching) ||
456 args_neq(&args, &sdp->sd_args, meta))
457 return -EINVAL;
458
459 if (sdp->sd_args.ar_spectator)
460 *flags |= MS_RDONLY;
461
462 if ((sb->s_flags ^ *flags) & MS_RDONLY) {
463 if (*flags & MS_RDONLY)
464 error = gfs2_make_fs_ro(sdp);
465 else
466 error = gfs2_make_fs_rw(sdp);
467 if (error)
468 return error;
469 }
470
471 sdp->sd_args = args;
472 if (sdp->sd_args.ar_posix_acl)
473 sb->s_flags |= MS_POSIXACL;
474 else
475 sb->s_flags &= ~MS_POSIXACL;
476 return 0;
477}
478
479/**
480 * gfs2_drop_inode - Drop an inode (test for remote unlink)
481 * @inode: The inode to drop
482 *
483 * If we've received a callback on an iopen lock then its because a
484 * remote node tried to deallocate the inode but failed due to this node
485 * still having the inode open. Here we mark the link count zero
486 * since we know that it must have reached zero if the GLF_DEMOTE flag
487 * is set on the iopen glock. If we didn't do a disk read since the
488 * remote node removed the final link then we might otherwise miss
489 * this event. This check ensures that this node will deallocate the
490 * inode's blocks, or alternatively pass the baton on to another
491 * node for later deallocation.
492 */
493
494static void gfs2_drop_inode(struct inode *inode)
495{
496 struct gfs2_inode *ip = GFS2_I(inode);
497
498 if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) {
499 struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
500 if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags))
501 clear_nlink(inode);
502 }
503 generic_drop_inode(inode);
504}
505
506/**
507 * gfs2_clear_inode - Deallocate an inode when VFS is done with it
508 * @inode: The VFS inode
509 *
510 */
511
512static void gfs2_clear_inode(struct inode *inode)
513{
514 struct gfs2_inode *ip = GFS2_I(inode);
515
516 /* This tells us its a "real" inode and not one which only
517 * serves to contain an address space (see rgrp.c, meta_io.c)
518 * which therefore doesn't have its own glocks.
519 */
520 if (test_bit(GIF_USER, &ip->i_flags)) {
521 ip->i_gl->gl_object = NULL;
522 gfs2_glock_put(ip->i_gl);
523 ip->i_gl = NULL;
524 if (ip->i_iopen_gh.gh_gl) {
525 ip->i_iopen_gh.gh_gl->gl_object = NULL;
526 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
527 }
528 }
529}
530
531static int is_ancestor(const struct dentry *d1, const struct dentry *d2)
532{
533 do {
534 if (d1 == d2)
535 return 1;
536 d1 = d1->d_parent;
537 } while (!IS_ROOT(d1));
538 return 0;
539}
540
541/**
542 * gfs2_show_options - Show mount options for /proc/mounts
543 * @s: seq_file structure
544 * @mnt: vfsmount
545 *
546 * Returns: 0 on success or error code
547 */
548
549static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
550{
551 struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
552 struct gfs2_args *args = &sdp->sd_args;
553
554 if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir))
555 seq_printf(s, ",meta");
556 if (args->ar_lockproto[0])
557 seq_printf(s, ",lockproto=%s", args->ar_lockproto);
558 if (args->ar_locktable[0])
559 seq_printf(s, ",locktable=%s", args->ar_locktable);
560 if (args->ar_hostdata[0])
561 seq_printf(s, ",hostdata=%s", args->ar_hostdata);
562 if (args->ar_spectator)
563 seq_printf(s, ",spectator");
564 if (args->ar_ignore_local_fs)
565 seq_printf(s, ",ignore_local_fs");
566 if (args->ar_localflocks)
567 seq_printf(s, ",localflocks");
568 if (args->ar_localcaching)
569 seq_printf(s, ",localcaching");
570 if (args->ar_debug)
571 seq_printf(s, ",debug");
572 if (args->ar_upgrade)
573 seq_printf(s, ",upgrade");
574 if (args->ar_posix_acl)
575 seq_printf(s, ",acl");
576 if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
577 char *state;
578 switch (args->ar_quota) {
579 case GFS2_QUOTA_OFF:
580 state = "off";
581 break;
582 case GFS2_QUOTA_ACCOUNT:
583 state = "account";
584 break;
585 case GFS2_QUOTA_ON:
586 state = "on";
587 break;
588 default:
589 state = "unknown";
590 break;
591 }
592 seq_printf(s, ",quota=%s", state);
593 }
594 if (args->ar_suiddir)
595 seq_printf(s, ",suiddir");
596 if (args->ar_data != GFS2_DATA_DEFAULT) {
597 char *state;
598 switch (args->ar_data) {
599 case GFS2_DATA_WRITEBACK:
600 state = "writeback";
601 break;
602 case GFS2_DATA_ORDERED:
603 state = "ordered";
604 break;
605 default:
606 state = "unknown";
607 break;
608 }
609 seq_printf(s, ",data=%s", state);
610 }
611 if (args->ar_discard)
612 seq_printf(s, ",discard");
613
614 return 0;
615}
616
617/*
618 * We have to (at the moment) hold the inodes main lock to cover
619 * the gap between unlocking the shared lock on the iopen lock and
620 * taking the exclusive lock. I'd rather do a shared -> exclusive
621 * conversion on the iopen lock, but we can change that later. This
622 * is safe, just less efficient.
623 */
624
625static void gfs2_delete_inode(struct inode *inode)
626{
627 struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
628 struct gfs2_inode *ip = GFS2_I(inode);
629 struct gfs2_holder gh;
630 int error;
631
632 if (!test_bit(GIF_USER, &ip->i_flags))
633 goto out;
634
635 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
636 if (unlikely(error)) {
637 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
638 goto out;
639 }
640
641 gfs2_glock_dq_wait(&ip->i_iopen_gh);
642 gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh);
643 error = gfs2_glock_nq(&ip->i_iopen_gh);
644 if (error)
645 goto out_truncate;
646
647 if (S_ISDIR(inode->i_mode) &&
648 (ip->i_diskflags & GFS2_DIF_EXHASH)) {
649 error = gfs2_dir_exhash_dealloc(ip);
650 if (error)
651 goto out_unlock;
652 }
653
654 if (ip->i_eattr) {
655 error = gfs2_ea_dealloc(ip);
656 if (error)
657 goto out_unlock;
658 }
659
660 if (!gfs2_is_stuffed(ip)) {
661 error = gfs2_file_dealloc(ip);
662 if (error)
663 goto out_unlock;
664 }
665
666 error = gfs2_dinode_dealloc(ip);
667 if (error)
668 goto out_unlock;
669
670out_truncate:
671 error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
672 if (error)
673 goto out_unlock;
674 /* Needs to be done before glock release & also in a transaction */
675 truncate_inode_pages(&inode->i_data, 0);
676 gfs2_trans_end(sdp);
677
678out_unlock:
679 if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags))
680 gfs2_glock_dq(&ip->i_iopen_gh);
681 gfs2_holder_uninit(&ip->i_iopen_gh);
682 gfs2_glock_dq_uninit(&gh);
683 if (error && error != GLR_TRYFAILED)
684 fs_warn(sdp, "gfs2_delete_inode: %d\n", error);
685out:
686 truncate_inode_pages(&inode->i_data, 0);
687 clear_inode(inode);
688}
689
690static struct inode *gfs2_alloc_inode(struct super_block *sb)
691{
692 struct gfs2_inode *ip;
693
694 ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
695 if (ip) {
696 ip->i_flags = 0;
697 ip->i_gl = NULL;
698 }
699 return &ip->i_inode;
700}
701
702static void gfs2_destroy_inode(struct inode *inode)
703{
704 kmem_cache_free(gfs2_inode_cachep, inode);
705}
706
707const struct super_operations gfs2_super_ops = {
708 .alloc_inode = gfs2_alloc_inode,
709 .destroy_inode = gfs2_destroy_inode,
710 .write_inode = gfs2_write_inode,
711 .delete_inode = gfs2_delete_inode,
712 .put_super = gfs2_put_super,
713 .write_super = gfs2_write_super,
714 .sync_fs = gfs2_sync_fs,
715 .freeze_fs = gfs2_freeze,
716 .unfreeze_fs = gfs2_unfreeze,
717 .statfs = gfs2_statfs,
718 .remount_fs = gfs2_remount_fs,
719 .clear_inode = gfs2_clear_inode,
720 .drop_inode = gfs2_drop_inode,
721 .show_options = gfs2_show_options,
722};
723
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index 152e6c4a0dca..2e9b9326bfc9 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -60,7 +60,6 @@
60#include "super.h" 60#include "super.h"
61#include "trans.h" 61#include "trans.h"
62#include "inode.h" 62#include "inode.h"
63#include "ops_address.h"
64#include "util.h" 63#include "util.h"
65 64
66#define QUOTA_USER 1 65#define QUOTA_USER 1
diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c
index 247e8f7d6b3d..59d2695509d3 100644
--- a/fs/gfs2/recovery.c
+++ b/fs/gfs2/recovery.c
@@ -13,8 +13,7 @@
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/gfs2_ondisk.h> 14#include <linux/gfs2_ondisk.h>
15#include <linux/crc32.h> 15#include <linux/crc32.h>
16#include <linux/kthread.h> 16#include <linux/slow-work.h>
17#include <linux/freezer.h>
18 17
19#include "gfs2.h" 18#include "gfs2.h"
20#include "incore.h" 19#include "incore.h"
@@ -441,18 +440,25 @@ static void gfs2_recovery_done(struct gfs2_sbd *sdp, unsigned int jid,
441 kobject_uevent_env(&sdp->sd_kobj, KOBJ_CHANGE, envp); 440 kobject_uevent_env(&sdp->sd_kobj, KOBJ_CHANGE, envp);
442} 441}
443 442
444/** 443static int gfs2_recover_get_ref(struct slow_work *work)
445 * gfs2_recover_journal - recover a given journal 444{
446 * @jd: the struct gfs2_jdesc describing the journal 445 struct gfs2_jdesc *jd = container_of(work, struct gfs2_jdesc, jd_work);
447 * 446 if (test_and_set_bit(JDF_RECOVERY, &jd->jd_flags))
448 * Acquire the journal's lock, check to see if the journal is clean, and 447 return -EBUSY;
449 * do recovery if necessary. 448 return 0;
450 * 449}
451 * Returns: errno
452 */
453 450
454int gfs2_recover_journal(struct gfs2_jdesc *jd) 451static void gfs2_recover_put_ref(struct slow_work *work)
452{
453 struct gfs2_jdesc *jd = container_of(work, struct gfs2_jdesc, jd_work);
454 clear_bit(JDF_RECOVERY, &jd->jd_flags);
455 smp_mb__after_clear_bit();
456 wake_up_bit(&jd->jd_flags, JDF_RECOVERY);
457}
458
459static void gfs2_recover_work(struct slow_work *work)
455{ 460{
461 struct gfs2_jdesc *jd = container_of(work, struct gfs2_jdesc, jd_work);
456 struct gfs2_inode *ip = GFS2_I(jd->jd_inode); 462 struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
457 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); 463 struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
458 struct gfs2_log_header_host head; 464 struct gfs2_log_header_host head;
@@ -569,7 +575,7 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd)
569 gfs2_glock_dq_uninit(&j_gh); 575 gfs2_glock_dq_uninit(&j_gh);
570 576
571 fs_info(sdp, "jid=%u: Done\n", jd->jd_jid); 577 fs_info(sdp, "jid=%u: Done\n", jd->jd_jid);
572 return 0; 578 return;
573 579
574fail_gunlock_tr: 580fail_gunlock_tr:
575 gfs2_glock_dq_uninit(&t_gh); 581 gfs2_glock_dq_uninit(&t_gh);
@@ -584,70 +590,28 @@ fail_gunlock_j:
584 590
585fail: 591fail:
586 gfs2_recovery_done(sdp, jd->jd_jid, LM_RD_GAVEUP); 592 gfs2_recovery_done(sdp, jd->jd_jid, LM_RD_GAVEUP);
587 return error;
588} 593}
589 594
590static struct gfs2_jdesc *gfs2_jdesc_find_dirty(struct gfs2_sbd *sdp) 595struct slow_work_ops gfs2_recover_ops = {
591{ 596 .get_ref = gfs2_recover_get_ref,
592 struct gfs2_jdesc *jd; 597 .put_ref = gfs2_recover_put_ref,
593 int found = 0; 598 .execute = gfs2_recover_work,
594 599};
595 spin_lock(&sdp->sd_jindex_spin);
596 600
597 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
598 if (jd->jd_dirty) {
599 jd->jd_dirty = 0;
600 found = 1;
601 break;
602 }
603 }
604 spin_unlock(&sdp->sd_jindex_spin);
605
606 if (!found)
607 jd = NULL;
608 601
609 return jd; 602static int gfs2_recovery_wait(void *word)
610}
611
612/**
613 * gfs2_check_journals - Recover any dirty journals
614 * @sdp: the filesystem
615 *
616 */
617
618static void gfs2_check_journals(struct gfs2_sbd *sdp)
619{ 603{
620 struct gfs2_jdesc *jd; 604 schedule();
621 605 return 0;
622 for (;;) {
623 jd = gfs2_jdesc_find_dirty(sdp);
624 if (!jd)
625 break;
626
627 if (jd != sdp->sd_jdesc)
628 gfs2_recover_journal(jd);
629 }
630} 606}
631 607
632/** 608int gfs2_recover_journal(struct gfs2_jdesc *jd)
633 * gfs2_recoverd - Recover dead machine's journals
634 * @sdp: Pointer to GFS2 superblock
635 *
636 */
637
638int gfs2_recoverd(void *data)
639{ 609{
640 struct gfs2_sbd *sdp = data; 610 int rv;
641 unsigned long t; 611 rv = slow_work_enqueue(&jd->jd_work);
642 612 if (rv)
643 while (!kthread_should_stop()) { 613 return rv;
644 gfs2_check_journals(sdp); 614 wait_on_bit(&jd->jd_flags, JDF_RECOVERY, gfs2_recovery_wait, TASK_UNINTERRUPTIBLE);
645 t = gfs2_tune_get(sdp, gt_recoverd_secs) * HZ;
646 if (freezing(current))
647 refrigerator();
648 schedule_timeout_interruptible(t);
649 }
650
651 return 0; 615 return 0;
652} 616}
653 617
diff --git a/fs/gfs2/recovery.h b/fs/gfs2/recovery.h
index a8218ea15b57..1616ac22569a 100644
--- a/fs/gfs2/recovery.h
+++ b/fs/gfs2/recovery.h
@@ -28,7 +28,7 @@ extern void gfs2_revoke_clean(struct gfs2_sbd *sdp);
28extern int gfs2_find_jhead(struct gfs2_jdesc *jd, 28extern int gfs2_find_jhead(struct gfs2_jdesc *jd,
29 struct gfs2_log_header_host *head); 29 struct gfs2_log_header_host *head);
30extern int gfs2_recover_journal(struct gfs2_jdesc *gfs2_jd); 30extern int gfs2_recover_journal(struct gfs2_jdesc *gfs2_jd);
31extern int gfs2_recoverd(void *data); 31extern struct slow_work_ops gfs2_recover_ops;
32 32
33#endif /* __RECOVERY_DOT_H__ */ 33#endif /* __RECOVERY_DOT_H__ */
34 34
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 565038243fa2..de3239731db8 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -29,7 +29,6 @@
29#include "util.h" 29#include "util.h"
30#include "log.h" 30#include "log.h"
31#include "inode.h" 31#include "inode.h"
32#include "ops_address.h"
33 32
34#define BFITNOENT ((u32)~0) 33#define BFITNOENT ((u32)~0)
35#define NO_BLOCK ((u64)~0) 34#define NO_BLOCK ((u64)~0)
@@ -442,6 +441,7 @@ static int compute_bitstructs(struct gfs2_rgrpd *rgd)
442 for (x = 0; x < length; x++) { 441 for (x = 0; x < length; x++) {
443 bi = rgd->rd_bits + x; 442 bi = rgd->rd_bits + x;
444 443
444 bi->bi_flags = 0;
445 /* small rgrp; bitmap stored completely in header block */ 445 /* small rgrp; bitmap stored completely in header block */
446 if (length == 1) { 446 if (length == 1) {
447 bytes = bytes_left; 447 bytes = bytes_left;
@@ -580,7 +580,6 @@ static int read_rindex_entry(struct gfs2_inode *ip,
580 580
581 rgd->rd_gl->gl_object = rgd; 581 rgd->rd_gl->gl_object = rgd;
582 rgd->rd_flags &= ~GFS2_RDF_UPTODATE; 582 rgd->rd_flags &= ~GFS2_RDF_UPTODATE;
583 rgd->rd_flags |= GFS2_RDF_CHECK;
584 return error; 583 return error;
585} 584}
586 585
@@ -701,10 +700,9 @@ static void gfs2_rgrp_in(struct gfs2_rgrpd *rgd, const void *buf)
701 u32 rg_flags; 700 u32 rg_flags;
702 701
703 rg_flags = be32_to_cpu(str->rg_flags); 702 rg_flags = be32_to_cpu(str->rg_flags);
704 if (rg_flags & GFS2_RGF_NOALLOC) 703 rg_flags &= ~GFS2_RDF_MASK;
705 rgd->rd_flags |= GFS2_RDF_NOALLOC; 704 rgd->rd_flags &= GFS2_RDF_MASK;
706 else 705 rgd->rd_flags |= rg_flags;
707 rgd->rd_flags &= ~GFS2_RDF_NOALLOC;
708 rgd->rd_free = be32_to_cpu(str->rg_free); 706 rgd->rd_free = be32_to_cpu(str->rg_free);
709 rgd->rd_dinodes = be32_to_cpu(str->rg_dinodes); 707 rgd->rd_dinodes = be32_to_cpu(str->rg_dinodes);
710 rgd->rd_igeneration = be64_to_cpu(str->rg_igeneration); 708 rgd->rd_igeneration = be64_to_cpu(str->rg_igeneration);
@@ -713,11 +711,8 @@ static void gfs2_rgrp_in(struct gfs2_rgrpd *rgd, const void *buf)
713static void gfs2_rgrp_out(struct gfs2_rgrpd *rgd, void *buf) 711static void gfs2_rgrp_out(struct gfs2_rgrpd *rgd, void *buf)
714{ 712{
715 struct gfs2_rgrp *str = buf; 713 struct gfs2_rgrp *str = buf;
716 u32 rg_flags = 0;
717 714
718 if (rgd->rd_flags & GFS2_RDF_NOALLOC) 715 str->rg_flags = cpu_to_be32(rgd->rd_flags & ~GFS2_RDF_MASK);
719 rg_flags |= GFS2_RGF_NOALLOC;
720 str->rg_flags = cpu_to_be32(rg_flags);
721 str->rg_free = cpu_to_be32(rgd->rd_free); 716 str->rg_free = cpu_to_be32(rgd->rd_free);
722 str->rg_dinodes = cpu_to_be32(rgd->rd_dinodes); 717 str->rg_dinodes = cpu_to_be32(rgd->rd_dinodes);
723 str->__pad = cpu_to_be32(0); 718 str->__pad = cpu_to_be32(0);
@@ -775,8 +770,10 @@ int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd)
775 } 770 }
776 771
777 if (!(rgd->rd_flags & GFS2_RDF_UPTODATE)) { 772 if (!(rgd->rd_flags & GFS2_RDF_UPTODATE)) {
773 for (x = 0; x < length; x++)
774 clear_bit(GBF_FULL, &rgd->rd_bits[x].bi_flags);
778 gfs2_rgrp_in(rgd, (rgd->rd_bits[0].bi_bh)->b_data); 775 gfs2_rgrp_in(rgd, (rgd->rd_bits[0].bi_bh)->b_data);
779 rgd->rd_flags |= GFS2_RDF_UPTODATE; 776 rgd->rd_flags |= (GFS2_RDF_UPTODATE | GFS2_RDF_CHECK);
780 } 777 }
781 778
782 spin_lock(&sdp->sd_rindex_spin); 779 spin_lock(&sdp->sd_rindex_spin);
@@ -845,7 +842,7 @@ static void gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
845 struct super_block *sb = sdp->sd_vfs; 842 struct super_block *sb = sdp->sd_vfs;
846 struct block_device *bdev = sb->s_bdev; 843 struct block_device *bdev = sb->s_bdev;
847 const unsigned int sects_per_blk = sdp->sd_sb.sb_bsize / 844 const unsigned int sects_per_blk = sdp->sd_sb.sb_bsize /
848 bdev_hardsect_size(sb->s_bdev); 845 bdev_logical_block_size(sb->s_bdev);
849 u64 blk; 846 u64 blk;
850 sector_t start = 0; 847 sector_t start = 0;
851 sector_t nr_sects = 0; 848 sector_t nr_sects = 0;
@@ -903,6 +900,7 @@ void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd)
903 continue; 900 continue;
904 if (sdp->sd_args.ar_discard) 901 if (sdp->sd_args.ar_discard)
905 gfs2_rgrp_send_discards(sdp, rgd->rd_data0, bi); 902 gfs2_rgrp_send_discards(sdp, rgd->rd_data0, bi);
903 clear_bit(GBF_FULL, &bi->bi_flags);
906 memcpy(bi->bi_clone + bi->bi_offset, 904 memcpy(bi->bi_clone + bi->bi_offset,
907 bi->bi_bh->b_data + bi->bi_offset, bi->bi_len); 905 bi->bi_bh->b_data + bi->bi_offset, bi->bi_len);
908 } 906 }
@@ -942,7 +940,7 @@ static int try_rgrp_fit(struct gfs2_rgrpd *rgd, struct gfs2_alloc *al)
942 struct gfs2_sbd *sdp = rgd->rd_sbd; 940 struct gfs2_sbd *sdp = rgd->rd_sbd;
943 int ret = 0; 941 int ret = 0;
944 942
945 if (rgd->rd_flags & GFS2_RDF_NOALLOC) 943 if (rgd->rd_flags & (GFS2_RGF_NOALLOC | GFS2_RDF_ERROR))
946 return 0; 944 return 0;
947 945
948 spin_lock(&sdp->sd_rindex_spin); 946 spin_lock(&sdp->sd_rindex_spin);
@@ -1315,30 +1313,37 @@ static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
1315{ 1313{
1316 struct gfs2_bitmap *bi = NULL; 1314 struct gfs2_bitmap *bi = NULL;
1317 const u32 length = rgd->rd_length; 1315 const u32 length = rgd->rd_length;
1318 u32 blk = 0; 1316 u32 blk = BFITNOENT;
1319 unsigned int buf, x; 1317 unsigned int buf, x;
1320 const unsigned int elen = *n; 1318 const unsigned int elen = *n;
1321 const u8 *buffer; 1319 const u8 *buffer = NULL;
1322 1320
1323 *n = 0; 1321 *n = 0;
1324 /* Find bitmap block that contains bits for goal block */ 1322 /* Find bitmap block that contains bits for goal block */
1325 for (buf = 0; buf < length; buf++) { 1323 for (buf = 0; buf < length; buf++) {
1326 bi = rgd->rd_bits + buf; 1324 bi = rgd->rd_bits + buf;
1327 if (goal < (bi->bi_start + bi->bi_len) * GFS2_NBBY) 1325 /* Convert scope of "goal" from rgrp-wide to within found bit block */
1328 break; 1326 if (goal < (bi->bi_start + bi->bi_len) * GFS2_NBBY) {
1327 goal -= bi->bi_start * GFS2_NBBY;
1328 goto do_search;
1329 }
1329 } 1330 }
1331 buf = 0;
1332 goal = 0;
1330 1333
1331 gfs2_assert(rgd->rd_sbd, buf < length); 1334do_search:
1332
1333 /* Convert scope of "goal" from rgrp-wide to within found bit block */
1334 goal -= bi->bi_start * GFS2_NBBY;
1335
1336 /* Search (up to entire) bitmap in this rgrp for allocatable block. 1335 /* Search (up to entire) bitmap in this rgrp for allocatable block.
1337 "x <= length", instead of "x < length", because we typically start 1336 "x <= length", instead of "x < length", because we typically start
1338 the search in the middle of a bit block, but if we can't find an 1337 the search in the middle of a bit block, but if we can't find an
1339 allocatable block anywhere else, we want to be able wrap around and 1338 allocatable block anywhere else, we want to be able wrap around and
1340 search in the first part of our first-searched bit block. */ 1339 search in the first part of our first-searched bit block. */
1341 for (x = 0; x <= length; x++) { 1340 for (x = 0; x <= length; x++) {
1341 bi = rgd->rd_bits + buf;
1342
1343 if (test_bit(GBF_FULL, &bi->bi_flags) &&
1344 (old_state == GFS2_BLKST_FREE))
1345 goto skip;
1346
1342 /* The GFS2_BLKST_UNLINKED state doesn't apply to the clone 1347 /* The GFS2_BLKST_UNLINKED state doesn't apply to the clone
1343 bitmaps, so we must search the originals for that. */ 1348 bitmaps, so we must search the originals for that. */
1344 buffer = bi->bi_bh->b_data + bi->bi_offset; 1349 buffer = bi->bi_bh->b_data + bi->bi_offset;
@@ -1349,33 +1354,39 @@ static u32 rgblk_search(struct gfs2_rgrpd *rgd, u32 goal,
1349 if (blk != BFITNOENT) 1354 if (blk != BFITNOENT)
1350 break; 1355 break;
1351 1356
1357 if ((goal == 0) && (old_state == GFS2_BLKST_FREE))
1358 set_bit(GBF_FULL, &bi->bi_flags);
1359
1352 /* Try next bitmap block (wrap back to rgrp header if at end) */ 1360 /* Try next bitmap block (wrap back to rgrp header if at end) */
1353 buf = (buf + 1) % length; 1361skip:
1354 bi = rgd->rd_bits + buf; 1362 buf++;
1363 buf %= length;
1355 goal = 0; 1364 goal = 0;
1356 } 1365 }
1357 1366
1358 if (blk != BFITNOENT && old_state != new_state) { 1367 if (blk == BFITNOENT)
1359 *n = 1; 1368 return blk;
1360 gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1); 1369 *n = 1;
1370 if (old_state == new_state)
1371 goto out;
1372
1373 gfs2_trans_add_bh(rgd->rd_gl, bi->bi_bh, 1);
1374 gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset,
1375 bi->bi_len, blk, new_state);
1376 goal = blk;
1377 while (*n < elen) {
1378 goal++;
1379 if (goal >= (bi->bi_len * GFS2_NBBY))
1380 break;
1381 if (gfs2_testbit(rgd, buffer, bi->bi_len, goal) !=
1382 GFS2_BLKST_FREE)
1383 break;
1361 gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset, 1384 gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone, bi->bi_offset,
1362 bi->bi_len, blk, new_state); 1385 bi->bi_len, goal, new_state);
1363 goal = blk; 1386 (*n)++;
1364 while (*n < elen) {
1365 goal++;
1366 if (goal >= (bi->bi_len * GFS2_NBBY))
1367 break;
1368 if (gfs2_testbit(rgd, buffer, bi->bi_len, goal) !=
1369 GFS2_BLKST_FREE)
1370 break;
1371 gfs2_setbit(rgd, bi->bi_bh->b_data, bi->bi_clone,
1372 bi->bi_offset, bi->bi_len, goal,
1373 new_state);
1374 (*n)++;
1375 }
1376 } 1387 }
1377 1388out:
1378 return (blk == BFITNOENT) ? blk : (bi->bi_start * GFS2_NBBY) + blk; 1389 return (bi->bi_start * GFS2_NBBY) + blk;
1379} 1390}
1380 1391
1381/** 1392/**
@@ -1435,13 +1446,33 @@ static struct gfs2_rgrpd *rgblk_free(struct gfs2_sbd *sdp, u64 bstart,
1435} 1446}
1436 1447
1437/** 1448/**
1438 * gfs2_alloc_block - Allocate a block 1449 * gfs2_rgrp_dump - print out an rgrp
1450 * @seq: The iterator
1451 * @gl: The glock in question
1452 *
1453 */
1454
1455int gfs2_rgrp_dump(struct seq_file *seq, const struct gfs2_glock *gl)
1456{
1457 const struct gfs2_rgrpd *rgd = gl->gl_object;
1458 if (rgd == NULL)
1459 return 0;
1460 gfs2_print_dbg(seq, " R: n:%llu f:%02x b:%u/%u i:%u\n",
1461 (unsigned long long)rgd->rd_addr, rgd->rd_flags,
1462 rgd->rd_free, rgd->rd_free_clone, rgd->rd_dinodes);
1463 return 0;
1464}
1465
1466/**
1467 * gfs2_alloc_block - Allocate one or more blocks
1439 * @ip: the inode to allocate the block for 1468 * @ip: the inode to allocate the block for
1469 * @bn: Used to return the starting block number
1470 * @n: requested number of blocks/extent length (value/result)
1440 * 1471 *
1441 * Returns: the allocated block 1472 * Returns: 0 or error
1442 */ 1473 */
1443 1474
1444u64 gfs2_alloc_block(struct gfs2_inode *ip, unsigned int *n) 1475int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n)
1445{ 1476{
1446 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 1477 struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
1447 struct buffer_head *dibh; 1478 struct buffer_head *dibh;
@@ -1457,7 +1488,10 @@ u64 gfs2_alloc_block(struct gfs2_inode *ip, unsigned int *n)
1457 goal = rgd->rd_last_alloc; 1488 goal = rgd->rd_last_alloc;
1458 1489
1459 blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, GFS2_BLKST_USED, n); 1490 blk = rgblk_search(rgd, goal, GFS2_BLKST_FREE, GFS2_BLKST_USED, n);
1460 BUG_ON(blk == BFITNOENT); 1491
1492 /* Since all blocks are reserved in advance, this shouldn't happen */
1493 if (blk == BFITNOENT)
1494 goto rgrp_error;
1461 1495
1462 rgd->rd_last_alloc = blk; 1496 rgd->rd_last_alloc = blk;
1463 block = rgd->rd_data0 + blk; 1497 block = rgd->rd_data0 + blk;
@@ -1469,7 +1503,9 @@ u64 gfs2_alloc_block(struct gfs2_inode *ip, unsigned int *n)
1469 di->di_goal_meta = di->di_goal_data = cpu_to_be64(ip->i_goal); 1503 di->di_goal_meta = di->di_goal_data = cpu_to_be64(ip->i_goal);
1470 brelse(dibh); 1504 brelse(dibh);
1471 } 1505 }
1472 gfs2_assert_withdraw(sdp, rgd->rd_free >= *n); 1506 if (rgd->rd_free < *n)
1507 goto rgrp_error;
1508
1473 rgd->rd_free -= *n; 1509 rgd->rd_free -= *n;
1474 1510
1475 gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1); 1511 gfs2_trans_add_bh(rgd->rd_gl, rgd->rd_bits[0].bi_bh, 1);
@@ -1484,7 +1520,16 @@ u64 gfs2_alloc_block(struct gfs2_inode *ip, unsigned int *n)
1484 rgd->rd_free_clone -= *n; 1520 rgd->rd_free_clone -= *n;
1485 spin_unlock(&sdp->sd_rindex_spin); 1521 spin_unlock(&sdp->sd_rindex_spin);
1486 1522
1487 return block; 1523 *bn = block;
1524 return 0;
1525
1526rgrp_error:
1527 fs_warn(sdp, "rgrp %llu has an error, marking it readonly until umount\n",
1528 (unsigned long long)rgd->rd_addr);
1529 fs_warn(sdp, "umount on all nodes and run fsck.gfs2 to fix the error\n");
1530 gfs2_rgrp_dump(NULL, rgd->rd_gl);
1531 rgd->rd_flags |= GFS2_RDF_ERROR;
1532 return -EIO;
1488} 1533}
1489 1534
1490/** 1535/**
diff --git a/fs/gfs2/rgrp.h b/fs/gfs2/rgrp.h
index 3181c7e624bf..1e76ff0f3e00 100644
--- a/fs/gfs2/rgrp.h
+++ b/fs/gfs2/rgrp.h
@@ -14,22 +14,22 @@ struct gfs2_rgrpd;
14struct gfs2_sbd; 14struct gfs2_sbd;
15struct gfs2_holder; 15struct gfs2_holder;
16 16
17void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd); 17extern void gfs2_rgrp_verify(struct gfs2_rgrpd *rgd);
18 18
19struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, u64 blk); 19struct gfs2_rgrpd *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, u64 blk);
20struct gfs2_rgrpd *gfs2_rgrpd_get_first(struct gfs2_sbd *sdp); 20struct gfs2_rgrpd *gfs2_rgrpd_get_first(struct gfs2_sbd *sdp);
21struct gfs2_rgrpd *gfs2_rgrpd_get_next(struct gfs2_rgrpd *rgd); 21struct gfs2_rgrpd *gfs2_rgrpd_get_next(struct gfs2_rgrpd *rgd);
22 22
23void gfs2_clear_rgrpd(struct gfs2_sbd *sdp); 23extern void gfs2_clear_rgrpd(struct gfs2_sbd *sdp);
24int gfs2_rindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ri_gh); 24extern int gfs2_rindex_hold(struct gfs2_sbd *sdp, struct gfs2_holder *ri_gh);
25 25
26int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd); 26extern int gfs2_rgrp_bh_get(struct gfs2_rgrpd *rgd);
27void gfs2_rgrp_bh_hold(struct gfs2_rgrpd *rgd); 27extern void gfs2_rgrp_bh_hold(struct gfs2_rgrpd *rgd);
28void gfs2_rgrp_bh_put(struct gfs2_rgrpd *rgd); 28extern void gfs2_rgrp_bh_put(struct gfs2_rgrpd *rgd);
29 29
30void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd); 30extern void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd);
31 31
32struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip); 32extern struct gfs2_alloc *gfs2_alloc_get(struct gfs2_inode *ip);
33static inline void gfs2_alloc_put(struct gfs2_inode *ip) 33static inline void gfs2_alloc_put(struct gfs2_inode *ip)
34{ 34{
35 BUG_ON(ip->i_alloc == NULL); 35 BUG_ON(ip->i_alloc == NULL);
@@ -37,22 +37,22 @@ static inline void gfs2_alloc_put(struct gfs2_inode *ip)
37 ip->i_alloc = NULL; 37 ip->i_alloc = NULL;
38} 38}
39 39
40int gfs2_inplace_reserve_i(struct gfs2_inode *ip, 40extern int gfs2_inplace_reserve_i(struct gfs2_inode *ip, char *file,
41 char *file, unsigned int line); 41 unsigned int line);
42#define gfs2_inplace_reserve(ip) \ 42#define gfs2_inplace_reserve(ip) \
43gfs2_inplace_reserve_i((ip), __FILE__, __LINE__) 43gfs2_inplace_reserve_i((ip), __FILE__, __LINE__)
44 44
45void gfs2_inplace_release(struct gfs2_inode *ip); 45extern void gfs2_inplace_release(struct gfs2_inode *ip);
46 46
47unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block); 47extern unsigned char gfs2_get_block_type(struct gfs2_rgrpd *rgd, u64 block);
48 48
49u64 gfs2_alloc_block(struct gfs2_inode *ip, unsigned int *n); 49extern int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n);
50u64 gfs2_alloc_di(struct gfs2_inode *ip, u64 *generation); 50extern u64 gfs2_alloc_di(struct gfs2_inode *ip, u64 *generation);
51 51
52void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen); 52extern void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen);
53void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen); 53extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen);
54void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip); 54extern void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip);
55void gfs2_unlink_di(struct inode *inode); 55extern void gfs2_unlink_di(struct inode *inode);
56 56
57struct gfs2_rgrp_list { 57struct gfs2_rgrp_list {
58 unsigned int rl_rgrps; 58 unsigned int rl_rgrps;
@@ -61,10 +61,11 @@ struct gfs2_rgrp_list {
61 struct gfs2_holder *rl_ghs; 61 struct gfs2_holder *rl_ghs;
62}; 62};
63 63
64void gfs2_rlist_add(struct gfs2_sbd *sdp, struct gfs2_rgrp_list *rlist, 64extern void gfs2_rlist_add(struct gfs2_sbd *sdp, struct gfs2_rgrp_list *rlist,
65 u64 block); 65 u64 block);
66void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist, unsigned int state); 66extern void gfs2_rlist_alloc(struct gfs2_rgrp_list *rlist, unsigned int state);
67void gfs2_rlist_free(struct gfs2_rgrp_list *rlist); 67extern void gfs2_rlist_free(struct gfs2_rgrp_list *rlist);
68u64 gfs2_ri_total(struct gfs2_sbd *sdp); 68extern u64 gfs2_ri_total(struct gfs2_sbd *sdp);
69extern int gfs2_rgrp_dump(struct seq_file *seq, const struct gfs2_glock *gl);
69 70
70#endif /* __RGRP_DOT_H__ */ 71#endif /* __RGRP_DOT_H__ */
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 601913e0a482..40bcc37e5a70 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -7,14 +7,20 @@
7 * of the GNU General Public License version 2. 7 * of the GNU General Public License version 2.
8 */ 8 */
9 9
10#include <linux/bio.h>
10#include <linux/sched.h> 11#include <linux/sched.h>
11#include <linux/slab.h> 12#include <linux/slab.h>
12#include <linux/spinlock.h> 13#include <linux/spinlock.h>
13#include <linux/completion.h> 14#include <linux/completion.h>
14#include <linux/buffer_head.h> 15#include <linux/buffer_head.h>
15#include <linux/crc32.h> 16#include <linux/statfs.h>
17#include <linux/seq_file.h>
18#include <linux/mount.h>
19#include <linux/kthread.h>
20#include <linux/delay.h>
16#include <linux/gfs2_ondisk.h> 21#include <linux/gfs2_ondisk.h>
17#include <linux/bio.h> 22#include <linux/crc32.h>
23#include <linux/time.h>
18 24
19#include "gfs2.h" 25#include "gfs2.h"
20#include "incore.h" 26#include "incore.h"
@@ -31,6 +37,183 @@
31#include "super.h" 37#include "super.h"
32#include "trans.h" 38#include "trans.h"
33#include "util.h" 39#include "util.h"
40#include "sys.h"
41#include "eattr.h"
42
43#define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)
44
45enum {
46 Opt_lockproto,
47 Opt_locktable,
48 Opt_hostdata,
49 Opt_spectator,
50 Opt_ignore_local_fs,
51 Opt_localflocks,
52 Opt_localcaching,
53 Opt_debug,
54 Opt_nodebug,
55 Opt_upgrade,
56 Opt_acl,
57 Opt_noacl,
58 Opt_quota_off,
59 Opt_quota_account,
60 Opt_quota_on,
61 Opt_quota,
62 Opt_noquota,
63 Opt_suiddir,
64 Opt_nosuiddir,
65 Opt_data_writeback,
66 Opt_data_ordered,
67 Opt_meta,
68 Opt_discard,
69 Opt_nodiscard,
70 Opt_commit,
71 Opt_error,
72};
73
74static const match_table_t tokens = {
75 {Opt_lockproto, "lockproto=%s"},
76 {Opt_locktable, "locktable=%s"},
77 {Opt_hostdata, "hostdata=%s"},
78 {Opt_spectator, "spectator"},
79 {Opt_ignore_local_fs, "ignore_local_fs"},
80 {Opt_localflocks, "localflocks"},
81 {Opt_localcaching, "localcaching"},
82 {Opt_debug, "debug"},
83 {Opt_nodebug, "nodebug"},
84 {Opt_upgrade, "upgrade"},
85 {Opt_acl, "acl"},
86 {Opt_noacl, "noacl"},
87 {Opt_quota_off, "quota=off"},
88 {Opt_quota_account, "quota=account"},
89 {Opt_quota_on, "quota=on"},
90 {Opt_quota, "quota"},
91 {Opt_noquota, "noquota"},
92 {Opt_suiddir, "suiddir"},
93 {Opt_nosuiddir, "nosuiddir"},
94 {Opt_data_writeback, "data=writeback"},
95 {Opt_data_ordered, "data=ordered"},
96 {Opt_meta, "meta"},
97 {Opt_discard, "discard"},
98 {Opt_nodiscard, "nodiscard"},
99 {Opt_commit, "commit=%d"},
100 {Opt_error, NULL}
101};
102
103/**
104 * gfs2_mount_args - Parse mount options
105 * @sdp:
106 * @data:
107 *
108 * Return: errno
109 */
110
111int gfs2_mount_args(struct gfs2_sbd *sdp, struct gfs2_args *args, char *options)
112{
113 char *o;
114 int token;
115 substring_t tmp[MAX_OPT_ARGS];
116 int rv;
117
118 /* Split the options into tokens with the "," character and
119 process them */
120
121 while (1) {
122 o = strsep(&options, ",");
123 if (o == NULL)
124 break;
125 if (*o == '\0')
126 continue;
127
128 token = match_token(o, tokens, tmp);
129 switch (token) {
130 case Opt_lockproto:
131 match_strlcpy(args->ar_lockproto, &tmp[0],
132 GFS2_LOCKNAME_LEN);
133 break;
134 case Opt_locktable:
135 match_strlcpy(args->ar_locktable, &tmp[0],
136 GFS2_LOCKNAME_LEN);
137 break;
138 case Opt_hostdata:
139 match_strlcpy(args->ar_hostdata, &tmp[0],
140 GFS2_LOCKNAME_LEN);
141 break;
142 case Opt_spectator:
143 args->ar_spectator = 1;
144 break;
145 case Opt_ignore_local_fs:
146 args->ar_ignore_local_fs = 1;
147 break;
148 case Opt_localflocks:
149 args->ar_localflocks = 1;
150 break;
151 case Opt_localcaching:
152 args->ar_localcaching = 1;
153 break;
154 case Opt_debug:
155 args->ar_debug = 1;
156 break;
157 case Opt_nodebug:
158 args->ar_debug = 0;
159 break;
160 case Opt_upgrade:
161 args->ar_upgrade = 1;
162 break;
163 case Opt_acl:
164 args->ar_posix_acl = 1;
165 break;
166 case Opt_noacl:
167 args->ar_posix_acl = 0;
168 break;
169 case Opt_quota_off:
170 case Opt_noquota:
171 args->ar_quota = GFS2_QUOTA_OFF;
172 break;
173 case Opt_quota_account:
174 args->ar_quota = GFS2_QUOTA_ACCOUNT;
175 break;
176 case Opt_quota_on:
177 case Opt_quota:
178 args->ar_quota = GFS2_QUOTA_ON;
179 break;
180 case Opt_suiddir:
181 args->ar_suiddir = 1;
182 break;
183 case Opt_nosuiddir:
184 args->ar_suiddir = 0;
185 break;
186 case Opt_data_writeback:
187 args->ar_data = GFS2_DATA_WRITEBACK;
188 break;
189 case Opt_data_ordered:
190 args->ar_data = GFS2_DATA_ORDERED;
191 break;
192 case Opt_meta:
193 args->ar_meta = 1;
194 break;
195 case Opt_discard:
196 args->ar_discard = 1;
197 break;
198 case Opt_nodiscard:
199 args->ar_discard = 0;
200 break;
201 case Opt_commit:
202 rv = match_int(&tmp[0], &args->ar_commit);
203 if (rv || args->ar_commit <= 0) {
204 fs_info(sdp, "commit mount option requires a positive numeric argument\n");
205 return rv ? rv : -EINVAL;
206 }
207 break;
208 case Opt_error:
209 default:
210 fs_info(sdp, "invalid mount option: %s\n", o);
211 return -EINVAL;
212 }
213 }
214
215 return 0;
216}
34 217
35/** 218/**
36 * gfs2_jindex_free - Clear all the journal index information 219 * gfs2_jindex_free - Clear all the journal index information
@@ -436,3 +619,719 @@ void gfs2_unfreeze_fs(struct gfs2_sbd *sdp)
436 mutex_unlock(&sdp->sd_freeze_lock); 619 mutex_unlock(&sdp->sd_freeze_lock);
437} 620}
438 621
622
623/**
624 * gfs2_write_inode - Make sure the inode is stable on the disk
625 * @inode: The inode
626 * @sync: synchronous write flag
627 *
628 * Returns: errno
629 */
630
631static int gfs2_write_inode(struct inode *inode, int sync)
632{
633 struct gfs2_inode *ip = GFS2_I(inode);
634 struct gfs2_sbd *sdp = GFS2_SB(inode);
635 struct gfs2_holder gh;
636 struct buffer_head *bh;
637 struct timespec atime;
638 struct gfs2_dinode *di;
639 int ret = 0;
640
641 /* Check this is a "normal" inode, etc */
642 if (!test_bit(GIF_USER, &ip->i_flags) ||
643 (current->flags & PF_MEMALLOC))
644 return 0;
645 ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
646 if (ret)
647 goto do_flush;
648 ret = gfs2_trans_begin(sdp, RES_DINODE, 0);
649 if (ret)
650 goto do_unlock;
651 ret = gfs2_meta_inode_buffer(ip, &bh);
652 if (ret == 0) {
653 di = (struct gfs2_dinode *)bh->b_data;
654 atime.tv_sec = be64_to_cpu(di->di_atime);
655 atime.tv_nsec = be32_to_cpu(di->di_atime_nsec);
656 if (timespec_compare(&inode->i_atime, &atime) > 0) {
657 gfs2_trans_add_bh(ip->i_gl, bh, 1);
658 gfs2_dinode_out(ip, bh->b_data);
659 }
660 brelse(bh);
661 }
662 gfs2_trans_end(sdp);
663do_unlock:
664 gfs2_glock_dq_uninit(&gh);
665do_flush:
666 if (sync != 0)
667 gfs2_log_flush(GFS2_SB(inode), ip->i_gl);
668 return ret;
669}
670
671/**
672 * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one
673 * @sdp: the filesystem
674 *
675 * Returns: errno
676 */
677
678static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
679{
680 struct gfs2_holder t_gh;
681 int error;
682
683 gfs2_quota_sync(sdp);
684 gfs2_statfs_sync(sdp);
685
686 error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE,
687 &t_gh);
688 if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
689 return error;
690
691 gfs2_meta_syncfs(sdp);
692 gfs2_log_shutdown(sdp);
693
694 clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
695
696 if (t_gh.gh_gl)
697 gfs2_glock_dq_uninit(&t_gh);
698
699 gfs2_quota_cleanup(sdp);
700
701 return error;
702}
703
704static int gfs2_umount_recovery_wait(void *word)
705{
706 schedule();
707 return 0;
708}
709
710/**
711 * gfs2_put_super - Unmount the filesystem
712 * @sb: The VFS superblock
713 *
714 */
715
716static void gfs2_put_super(struct super_block *sb)
717{
718 struct gfs2_sbd *sdp = sb->s_fs_info;
719 int error;
720 struct gfs2_jdesc *jd;
721
722 /* Unfreeze the filesystem, if we need to */
723
724 mutex_lock(&sdp->sd_freeze_lock);
725 if (sdp->sd_freeze_count)
726 gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
727 mutex_unlock(&sdp->sd_freeze_lock);
728
729 /* No more recovery requests */
730 set_bit(SDF_NORECOVERY, &sdp->sd_flags);
731 smp_mb();
732
733 /* Wait on outstanding recovery */
734restart:
735 spin_lock(&sdp->sd_jindex_spin);
736 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
737 if (!test_bit(JDF_RECOVERY, &jd->jd_flags))
738 continue;
739 spin_unlock(&sdp->sd_jindex_spin);
740 wait_on_bit(&jd->jd_flags, JDF_RECOVERY,
741 gfs2_umount_recovery_wait, TASK_UNINTERRUPTIBLE);
742 goto restart;
743 }
744 spin_unlock(&sdp->sd_jindex_spin);
745
746 kthread_stop(sdp->sd_quotad_process);
747 kthread_stop(sdp->sd_logd_process);
748
749 if (!(sb->s_flags & MS_RDONLY)) {
750 error = gfs2_make_fs_ro(sdp);
751 if (error)
752 gfs2_io_error(sdp);
753 }
754 /* At this point, we're through modifying the disk */
755
756 /* Release stuff */
757
758 iput(sdp->sd_jindex);
759 iput(sdp->sd_inum_inode);
760 iput(sdp->sd_statfs_inode);
761 iput(sdp->sd_rindex);
762 iput(sdp->sd_quota_inode);
763
764 gfs2_glock_put(sdp->sd_rename_gl);
765 gfs2_glock_put(sdp->sd_trans_gl);
766
767 if (!sdp->sd_args.ar_spectator) {
768 gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
769 gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
770 gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
771 gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
772 gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
773 iput(sdp->sd_ir_inode);
774 iput(sdp->sd_sc_inode);
775 iput(sdp->sd_qc_inode);
776 }
777
778 gfs2_glock_dq_uninit(&sdp->sd_live_gh);
779 gfs2_clear_rgrpd(sdp);
780 gfs2_jindex_free(sdp);
781 /* Take apart glock structures and buffer lists */
782 gfs2_gl_hash_clear(sdp);
783 /* Unmount the locking protocol */
784 gfs2_lm_unmount(sdp);
785
786 /* At this point, we're through participating in the lockspace */
787 gfs2_sys_fs_del(sdp);
788}
789
790/**
791 * gfs2_write_super
792 * @sb: the superblock
793 *
794 */
795
796static void gfs2_write_super(struct super_block *sb)
797{
798 sb->s_dirt = 0;
799}
800
801/**
802 * gfs2_sync_fs - sync the filesystem
803 * @sb: the superblock
804 *
805 * Flushes the log to disk.
806 */
807
808static int gfs2_sync_fs(struct super_block *sb, int wait)
809{
810 sb->s_dirt = 0;
811 if (wait && sb->s_fs_info)
812 gfs2_log_flush(sb->s_fs_info, NULL);
813 return 0;
814}
815
816/**
817 * gfs2_freeze - prevent further writes to the filesystem
818 * @sb: the VFS structure for the filesystem
819 *
820 */
821
822static int gfs2_freeze(struct super_block *sb)
823{
824 struct gfs2_sbd *sdp = sb->s_fs_info;
825 int error;
826
827 if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
828 return -EINVAL;
829
830 for (;;) {
831 error = gfs2_freeze_fs(sdp);
832 if (!error)
833 break;
834
835 switch (error) {
836 case -EBUSY:
837 fs_err(sdp, "waiting for recovery before freeze\n");
838 break;
839
840 default:
841 fs_err(sdp, "error freezing FS: %d\n", error);
842 break;
843 }
844
845 fs_err(sdp, "retrying...\n");
846 msleep(1000);
847 }
848 return 0;
849}
850
851/**
852 * gfs2_unfreeze - reallow writes to the filesystem
853 * @sb: the VFS structure for the filesystem
854 *
855 */
856
857static int gfs2_unfreeze(struct super_block *sb)
858{
859 gfs2_unfreeze_fs(sb->s_fs_info);
860 return 0;
861}
862
863/**
864 * statfs_fill - fill in the sg for a given RG
865 * @rgd: the RG
866 * @sc: the sc structure
867 *
868 * Returns: 0 on success, -ESTALE if the LVB is invalid
869 */
870
871static int statfs_slow_fill(struct gfs2_rgrpd *rgd,
872 struct gfs2_statfs_change_host *sc)
873{
874 gfs2_rgrp_verify(rgd);
875 sc->sc_total += rgd->rd_data;
876 sc->sc_free += rgd->rd_free;
877 sc->sc_dinodes += rgd->rd_dinodes;
878 return 0;
879}
880
881/**
882 * gfs2_statfs_slow - Stat a filesystem using asynchronous locking
883 * @sdp: the filesystem
884 * @sc: the sc info that will be returned
885 *
886 * Any error (other than a signal) will cause this routine to fall back
887 * to the synchronous version.
888 *
889 * FIXME: This really shouldn't busy wait like this.
890 *
891 * Returns: errno
892 */
893
894static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
895{
896 struct gfs2_holder ri_gh;
897 struct gfs2_rgrpd *rgd_next;
898 struct gfs2_holder *gha, *gh;
899 unsigned int slots = 64;
900 unsigned int x;
901 int done;
902 int error = 0, err;
903
904 memset(sc, 0, sizeof(struct gfs2_statfs_change_host));
905 gha = kcalloc(slots, sizeof(struct gfs2_holder), GFP_KERNEL);
906 if (!gha)
907 return -ENOMEM;
908
909 error = gfs2_rindex_hold(sdp, &ri_gh);
910 if (error)
911 goto out;
912
913 rgd_next = gfs2_rgrpd_get_first(sdp);
914
915 for (;;) {
916 done = 1;
917
918 for (x = 0; x < slots; x++) {
919 gh = gha + x;
920
921 if (gh->gh_gl && gfs2_glock_poll(gh)) {
922 err = gfs2_glock_wait(gh);
923 if (err) {
924 gfs2_holder_uninit(gh);
925 error = err;
926 } else {
927 if (!error)
928 error = statfs_slow_fill(
929 gh->gh_gl->gl_object, sc);
930 gfs2_glock_dq_uninit(gh);
931 }
932 }
933
934 if (gh->gh_gl)
935 done = 0;
936 else if (rgd_next && !error) {
937 error = gfs2_glock_nq_init(rgd_next->rd_gl,
938 LM_ST_SHARED,
939 GL_ASYNC,
940 gh);
941 rgd_next = gfs2_rgrpd_get_next(rgd_next);
942 done = 0;
943 }
944
945 if (signal_pending(current))
946 error = -ERESTARTSYS;
947 }
948
949 if (done)
950 break;
951
952 yield();
953 }
954
955 gfs2_glock_dq_uninit(&ri_gh);
956
957out:
958 kfree(gha);
959 return error;
960}
961
962/**
963 * gfs2_statfs_i - Do a statfs
964 * @sdp: the filesystem
965 * @sg: the sg structure
966 *
967 * Returns: errno
968 */
969
970static int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
971{
972 struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
973 struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
974
975 spin_lock(&sdp->sd_statfs_spin);
976
977 *sc = *m_sc;
978 sc->sc_total += l_sc->sc_total;
979 sc->sc_free += l_sc->sc_free;
980 sc->sc_dinodes += l_sc->sc_dinodes;
981
982 spin_unlock(&sdp->sd_statfs_spin);
983
984 if (sc->sc_free < 0)
985 sc->sc_free = 0;
986 if (sc->sc_free > sc->sc_total)
987 sc->sc_free = sc->sc_total;
988 if (sc->sc_dinodes < 0)
989 sc->sc_dinodes = 0;
990
991 return 0;
992}
993
994/**
995 * gfs2_statfs - Gather and return stats about the filesystem
996 * @sb: The superblock
997 * @statfsbuf: The buffer
998 *
999 * Returns: 0 on success or error code
1000 */
1001
1002static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
1003{
1004 struct super_block *sb = dentry->d_inode->i_sb;
1005 struct gfs2_sbd *sdp = sb->s_fs_info;
1006 struct gfs2_statfs_change_host sc;
1007 int error;
1008
1009 if (gfs2_tune_get(sdp, gt_statfs_slow))
1010 error = gfs2_statfs_slow(sdp, &sc);
1011 else
1012 error = gfs2_statfs_i(sdp, &sc);
1013
1014 if (error)
1015 return error;
1016
1017 buf->f_type = GFS2_MAGIC;
1018 buf->f_bsize = sdp->sd_sb.sb_bsize;
1019 buf->f_blocks = sc.sc_total;
1020 buf->f_bfree = sc.sc_free;
1021 buf->f_bavail = sc.sc_free;
1022 buf->f_files = sc.sc_dinodes + sc.sc_free;
1023 buf->f_ffree = sc.sc_free;
1024 buf->f_namelen = GFS2_FNAMESIZE;
1025
1026 return 0;
1027}
1028
1029/**
1030 * gfs2_remount_fs - called when the FS is remounted
1031 * @sb: the filesystem
1032 * @flags: the remount flags
1033 * @data: extra data passed in (not used right now)
1034 *
1035 * Returns: errno
1036 */
1037
1038static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
1039{
1040 struct gfs2_sbd *sdp = sb->s_fs_info;
1041 struct gfs2_args args = sdp->sd_args; /* Default to current settings */
1042 struct gfs2_tune *gt = &sdp->sd_tune;
1043 int error;
1044
1045 spin_lock(&gt->gt_spin);
1046 args.ar_commit = gt->gt_log_flush_secs;
1047 spin_unlock(&gt->gt_spin);
1048 error = gfs2_mount_args(sdp, &args, data);
1049 if (error)
1050 return error;
1051
1052 /* Not allowed to change locking details */
1053 if (strcmp(args.ar_lockproto, sdp->sd_args.ar_lockproto) ||
1054 strcmp(args.ar_locktable, sdp->sd_args.ar_locktable) ||
1055 strcmp(args.ar_hostdata, sdp->sd_args.ar_hostdata))
1056 return -EINVAL;
1057
1058 /* Some flags must not be changed */
1059 if (args_neq(&args, &sdp->sd_args, spectator) ||
1060 args_neq(&args, &sdp->sd_args, ignore_local_fs) ||
1061 args_neq(&args, &sdp->sd_args, localflocks) ||
1062 args_neq(&args, &sdp->sd_args, localcaching) ||
1063 args_neq(&args, &sdp->sd_args, meta))
1064 return -EINVAL;
1065
1066 if (sdp->sd_args.ar_spectator)
1067 *flags |= MS_RDONLY;
1068
1069 if ((sb->s_flags ^ *flags) & MS_RDONLY) {
1070 if (*flags & MS_RDONLY)
1071 error = gfs2_make_fs_ro(sdp);
1072 else
1073 error = gfs2_make_fs_rw(sdp);
1074 if (error)
1075 return error;
1076 }
1077
1078 sdp->sd_args = args;
1079 if (sdp->sd_args.ar_posix_acl)
1080 sb->s_flags |= MS_POSIXACL;
1081 else
1082 sb->s_flags &= ~MS_POSIXACL;
1083 spin_lock(&gt->gt_spin);
1084 gt->gt_log_flush_secs = args.ar_commit;
1085 spin_unlock(&gt->gt_spin);
1086
1087 return 0;
1088}
1089
1090/**
1091 * gfs2_drop_inode - Drop an inode (test for remote unlink)
1092 * @inode: The inode to drop
1093 *
1094 * If we've received a callback on an iopen lock then its because a
1095 * remote node tried to deallocate the inode but failed due to this node
1096 * still having the inode open. Here we mark the link count zero
1097 * since we know that it must have reached zero if the GLF_DEMOTE flag
1098 * is set on the iopen glock. If we didn't do a disk read since the
1099 * remote node removed the final link then we might otherwise miss
1100 * this event. This check ensures that this node will deallocate the
1101 * inode's blocks, or alternatively pass the baton on to another
1102 * node for later deallocation.
1103 */
1104
1105static void gfs2_drop_inode(struct inode *inode)
1106{
1107 struct gfs2_inode *ip = GFS2_I(inode);
1108
1109 if (test_bit(GIF_USER, &ip->i_flags) && inode->i_nlink) {
1110 struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
1111 if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags))
1112 clear_nlink(inode);
1113 }
1114 generic_drop_inode(inode);
1115}
1116
1117/**
1118 * gfs2_clear_inode - Deallocate an inode when VFS is done with it
1119 * @inode: The VFS inode
1120 *
1121 */
1122
1123static void gfs2_clear_inode(struct inode *inode)
1124{
1125 struct gfs2_inode *ip = GFS2_I(inode);
1126
1127 /* This tells us its a "real" inode and not one which only
1128 * serves to contain an address space (see rgrp.c, meta_io.c)
1129 * which therefore doesn't have its own glocks.
1130 */
1131 if (test_bit(GIF_USER, &ip->i_flags)) {
1132 ip->i_gl->gl_object = NULL;
1133 gfs2_glock_put(ip->i_gl);
1134 ip->i_gl = NULL;
1135 if (ip->i_iopen_gh.gh_gl) {
1136 ip->i_iopen_gh.gh_gl->gl_object = NULL;
1137 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
1138 }
1139 }
1140}
1141
1142static int is_ancestor(const struct dentry *d1, const struct dentry *d2)
1143{
1144 do {
1145 if (d1 == d2)
1146 return 1;
1147 d1 = d1->d_parent;
1148 } while (!IS_ROOT(d1));
1149 return 0;
1150}
1151
1152/**
1153 * gfs2_show_options - Show mount options for /proc/mounts
1154 * @s: seq_file structure
1155 * @mnt: vfsmount
1156 *
1157 * Returns: 0 on success or error code
1158 */
1159
1160static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
1161{
1162 struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
1163 struct gfs2_args *args = &sdp->sd_args;
1164 int lfsecs;
1165
1166 if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir))
1167 seq_printf(s, ",meta");
1168 if (args->ar_lockproto[0])
1169 seq_printf(s, ",lockproto=%s", args->ar_lockproto);
1170 if (args->ar_locktable[0])
1171 seq_printf(s, ",locktable=%s", args->ar_locktable);
1172 if (args->ar_hostdata[0])
1173 seq_printf(s, ",hostdata=%s", args->ar_hostdata);
1174 if (args->ar_spectator)
1175 seq_printf(s, ",spectator");
1176 if (args->ar_ignore_local_fs)
1177 seq_printf(s, ",ignore_local_fs");
1178 if (args->ar_localflocks)
1179 seq_printf(s, ",localflocks");
1180 if (args->ar_localcaching)
1181 seq_printf(s, ",localcaching");
1182 if (args->ar_debug)
1183 seq_printf(s, ",debug");
1184 if (args->ar_upgrade)
1185 seq_printf(s, ",upgrade");
1186 if (args->ar_posix_acl)
1187 seq_printf(s, ",acl");
1188 if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
1189 char *state;
1190 switch (args->ar_quota) {
1191 case GFS2_QUOTA_OFF:
1192 state = "off";
1193 break;
1194 case GFS2_QUOTA_ACCOUNT:
1195 state = "account";
1196 break;
1197 case GFS2_QUOTA_ON:
1198 state = "on";
1199 break;
1200 default:
1201 state = "unknown";
1202 break;
1203 }
1204 seq_printf(s, ",quota=%s", state);
1205 }
1206 if (args->ar_suiddir)
1207 seq_printf(s, ",suiddir");
1208 if (args->ar_data != GFS2_DATA_DEFAULT) {
1209 char *state;
1210 switch (args->ar_data) {
1211 case GFS2_DATA_WRITEBACK:
1212 state = "writeback";
1213 break;
1214 case GFS2_DATA_ORDERED:
1215 state = "ordered";
1216 break;
1217 default:
1218 state = "unknown";
1219 break;
1220 }
1221 seq_printf(s, ",data=%s", state);
1222 }
1223 if (args->ar_discard)
1224 seq_printf(s, ",discard");
1225 lfsecs = sdp->sd_tune.gt_log_flush_secs;
1226 if (lfsecs != 60)
1227 seq_printf(s, ",commit=%d", lfsecs);
1228 return 0;
1229}
1230
1231/*
1232 * We have to (at the moment) hold the inodes main lock to cover
1233 * the gap between unlocking the shared lock on the iopen lock and
1234 * taking the exclusive lock. I'd rather do a shared -> exclusive
1235 * conversion on the iopen lock, but we can change that later. This
1236 * is safe, just less efficient.
1237 */
1238
1239static void gfs2_delete_inode(struct inode *inode)
1240{
1241 struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
1242 struct gfs2_inode *ip = GFS2_I(inode);
1243 struct gfs2_holder gh;
1244 int error;
1245
1246 if (!test_bit(GIF_USER, &ip->i_flags))
1247 goto out;
1248
1249 error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
1250 if (unlikely(error)) {
1251 gfs2_glock_dq_uninit(&ip->i_iopen_gh);
1252 goto out;
1253 }
1254
1255 gfs2_glock_dq_wait(&ip->i_iopen_gh);
1256 gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh);
1257 error = gfs2_glock_nq(&ip->i_iopen_gh);
1258 if (error)
1259 goto out_truncate;
1260
1261 if (S_ISDIR(inode->i_mode) &&
1262 (ip->i_diskflags & GFS2_DIF_EXHASH)) {
1263 error = gfs2_dir_exhash_dealloc(ip);
1264 if (error)
1265 goto out_unlock;
1266 }
1267
1268 if (ip->i_eattr) {
1269 error = gfs2_ea_dealloc(ip);
1270 if (error)
1271 goto out_unlock;
1272 }
1273
1274 if (!gfs2_is_stuffed(ip)) {
1275 error = gfs2_file_dealloc(ip);
1276 if (error)
1277 goto out_unlock;
1278 }
1279
1280 error = gfs2_dinode_dealloc(ip);
1281 if (error)
1282 goto out_unlock;
1283
1284out_truncate:
1285 error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
1286 if (error)
1287 goto out_unlock;
1288 /* Needs to be done before glock release & also in a transaction */
1289 truncate_inode_pages(&inode->i_data, 0);
1290 gfs2_trans_end(sdp);
1291
1292out_unlock:
1293 if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags))
1294 gfs2_glock_dq(&ip->i_iopen_gh);
1295 gfs2_holder_uninit(&ip->i_iopen_gh);
1296 gfs2_glock_dq_uninit(&gh);
1297 if (error && error != GLR_TRYFAILED && error != -EROFS)
1298 fs_warn(sdp, "gfs2_delete_inode: %d\n", error);
1299out:
1300 truncate_inode_pages(&inode->i_data, 0);
1301 clear_inode(inode);
1302}
1303
1304static struct inode *gfs2_alloc_inode(struct super_block *sb)
1305{
1306 struct gfs2_inode *ip;
1307
1308 ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
1309 if (ip) {
1310 ip->i_flags = 0;
1311 ip->i_gl = NULL;
1312 }
1313 return &ip->i_inode;
1314}
1315
1316static void gfs2_destroy_inode(struct inode *inode)
1317{
1318 kmem_cache_free(gfs2_inode_cachep, inode);
1319}
1320
1321const struct super_operations gfs2_super_ops = {
1322 .alloc_inode = gfs2_alloc_inode,
1323 .destroy_inode = gfs2_destroy_inode,
1324 .write_inode = gfs2_write_inode,
1325 .delete_inode = gfs2_delete_inode,
1326 .put_super = gfs2_put_super,
1327 .write_super = gfs2_write_super,
1328 .sync_fs = gfs2_sync_fs,
1329 .freeze_fs = gfs2_freeze,
1330 .unfreeze_fs = gfs2_unfreeze,
1331 .statfs = gfs2_statfs,
1332 .remount_fs = gfs2_remount_fs,
1333 .clear_inode = gfs2_clear_inode,
1334 .drop_inode = gfs2_drop_inode,
1335 .show_options = gfs2_show_options,
1336};
1337
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index 7655f5025fec..23419dc3027b 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -26,6 +26,36 @@
26#include "util.h" 26#include "util.h"
27#include "glops.h" 27#include "glops.h"
28 28
29struct gfs2_attr {
30 struct attribute attr;
31 ssize_t (*show)(struct gfs2_sbd *, char *);
32 ssize_t (*store)(struct gfs2_sbd *, const char *, size_t);
33};
34
35static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr,
36 char *buf)
37{
38 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
39 struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr);
40 return a->show ? a->show(sdp, buf) : 0;
41}
42
43static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr,
44 const char *buf, size_t len)
45{
46 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
47 struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr);
48 return a->store ? a->store(sdp, buf, len) : len;
49}
50
51static struct sysfs_ops gfs2_attr_ops = {
52 .show = gfs2_attr_show,
53 .store = gfs2_attr_store,
54};
55
56
57static struct kset *gfs2_kset;
58
29static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) 59static ssize_t id_show(struct gfs2_sbd *sdp, char *buf)
30{ 60{
31 return snprintf(buf, PAGE_SIZE, "%u:%u\n", 61 return snprintf(buf, PAGE_SIZE, "%u:%u\n",
@@ -212,11 +242,6 @@ static ssize_t demote_rq_store(struct gfs2_sbd *sdp, const char *buf, size_t len
212 return len; 242 return len;
213} 243}
214 244
215struct gfs2_attr {
216 struct attribute attr;
217 ssize_t (*show)(struct gfs2_sbd *, char *);
218 ssize_t (*store)(struct gfs2_sbd *, const char *, size_t);
219};
220 245
221#define GFS2_ATTR(name, mode, show, store) \ 246#define GFS2_ATTR(name, mode, show, store) \
222static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store) 247static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store)
@@ -246,58 +271,11 @@ static struct attribute *gfs2_attrs[] = {
246 NULL, 271 NULL,
247}; 272};
248 273
249static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr,
250 char *buf)
251{
252 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
253 struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr);
254 return a->show ? a->show(sdp, buf) : 0;
255}
256
257static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr,
258 const char *buf, size_t len)
259{
260 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
261 struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr);
262 return a->store ? a->store(sdp, buf, len) : len;
263}
264
265static struct sysfs_ops gfs2_attr_ops = {
266 .show = gfs2_attr_show,
267 .store = gfs2_attr_store,
268};
269
270static struct kobj_type gfs2_ktype = { 274static struct kobj_type gfs2_ktype = {
271 .default_attrs = gfs2_attrs, 275 .default_attrs = gfs2_attrs,
272 .sysfs_ops = &gfs2_attr_ops, 276 .sysfs_ops = &gfs2_attr_ops,
273}; 277};
274 278
275static struct kset *gfs2_kset;
276
277/*
278 * display struct lm_lockstruct fields
279 */
280
281struct lockstruct_attr {
282 struct attribute attr;
283 ssize_t (*show)(struct gfs2_sbd *, char *);
284};
285
286#define LOCKSTRUCT_ATTR(name, fmt) \
287static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
288{ \
289 return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_lockstruct.ls_##name); \
290} \
291static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name)
292
293LOCKSTRUCT_ATTR(jid, "%u\n");
294LOCKSTRUCT_ATTR(first, "%u\n");
295
296static struct attribute *lockstruct_attrs[] = {
297 &lockstruct_attr_jid.attr,
298 &lockstruct_attr_first.attr,
299 NULL,
300};
301 279
302/* 280/*
303 * lock_module. Originally from lock_dlm 281 * lock_module. Originally from lock_dlm
@@ -359,34 +337,33 @@ static ssize_t first_done_show(struct gfs2_sbd *sdp, char *buf)
359 return sprintf(buf, "%d\n", ls->ls_first_done); 337 return sprintf(buf, "%d\n", ls->ls_first_done);
360} 338}
361 339
362static ssize_t recover_show(struct gfs2_sbd *sdp, char *buf) 340static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
363{
364 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
365 return sprintf(buf, "%d\n", ls->ls_recover_jid);
366}
367
368static void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid)
369{ 341{
342 unsigned jid;
370 struct gfs2_jdesc *jd; 343 struct gfs2_jdesc *jd;
344 int rv;
345
346 rv = sscanf(buf, "%u", &jid);
347 if (rv != 1)
348 return -EINVAL;
371 349
350 rv = -ESHUTDOWN;
372 spin_lock(&sdp->sd_jindex_spin); 351 spin_lock(&sdp->sd_jindex_spin);
352 if (test_bit(SDF_NORECOVERY, &sdp->sd_flags))
353 goto out;
354 rv = -EBUSY;
355 if (sdp->sd_jdesc->jd_jid == jid)
356 goto out;
357 rv = -ENOENT;
373 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { 358 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
374 if (jd->jd_jid != jid) 359 if (jd->jd_jid != jid)
375 continue; 360 continue;
376 jd->jd_dirty = 1; 361 rv = slow_work_enqueue(&jd->jd_work);
377 break; 362 break;
378 } 363 }
364out:
379 spin_unlock(&sdp->sd_jindex_spin); 365 spin_unlock(&sdp->sd_jindex_spin);
380} 366 return rv ? rv : len;
381
382static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
383{
384 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
385 ls->ls_recover_jid = simple_strtol(buf, NULL, 0);
386 gfs2_jdesc_make_dirty(sdp, ls->ls_recover_jid);
387 if (sdp->sd_recoverd_process)
388 wake_up_process(sdp->sd_recoverd_process);
389 return len;
390} 367}
391 368
392static ssize_t recover_done_show(struct gfs2_sbd *sdp, char *buf) 369static ssize_t recover_done_show(struct gfs2_sbd *sdp, char *buf)
@@ -401,31 +378,31 @@ static ssize_t recover_status_show(struct gfs2_sbd *sdp, char *buf)
401 return sprintf(buf, "%d\n", ls->ls_recover_jid_status); 378 return sprintf(buf, "%d\n", ls->ls_recover_jid_status);
402} 379}
403 380
404struct gdlm_attr { 381static ssize_t jid_show(struct gfs2_sbd *sdp, char *buf)
405 struct attribute attr; 382{
406 ssize_t (*show)(struct gfs2_sbd *sdp, char *); 383 return sprintf(buf, "%u\n", sdp->sd_lockstruct.ls_jid);
407 ssize_t (*store)(struct gfs2_sbd *sdp, const char *, size_t); 384}
408};
409 385
410#define GDLM_ATTR(_name,_mode,_show,_store) \ 386#define GDLM_ATTR(_name,_mode,_show,_store) \
411static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store) 387static struct gfs2_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
412 388
413GDLM_ATTR(proto_name, 0444, proto_name_show, NULL); 389GDLM_ATTR(proto_name, 0444, proto_name_show, NULL);
414GDLM_ATTR(block, 0644, block_show, block_store); 390GDLM_ATTR(block, 0644, block_show, block_store);
415GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store); 391GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
416GDLM_ATTR(id, 0444, lkid_show, NULL); 392GDLM_ATTR(id, 0444, lkid_show, NULL);
417GDLM_ATTR(first, 0444, lkfirst_show, NULL); 393GDLM_ATTR(jid, 0444, jid_show, NULL);
418GDLM_ATTR(first_done, 0444, first_done_show, NULL); 394GDLM_ATTR(first, 0444, lkfirst_show, NULL);
419GDLM_ATTR(recover, 0644, recover_show, recover_store); 395GDLM_ATTR(first_done, 0444, first_done_show, NULL);
420GDLM_ATTR(recover_done, 0444, recover_done_show, NULL); 396GDLM_ATTR(recover, 0200, NULL, recover_store);
421GDLM_ATTR(recover_status, 0444, recover_status_show, NULL); 397GDLM_ATTR(recover_done, 0444, recover_done_show, NULL);
398GDLM_ATTR(recover_status, 0444, recover_status_show, NULL);
422 399
423static struct attribute *lock_module_attrs[] = { 400static struct attribute *lock_module_attrs[] = {
424 &gdlm_attr_proto_name.attr, 401 &gdlm_attr_proto_name.attr,
425 &gdlm_attr_block.attr, 402 &gdlm_attr_block.attr,
426 &gdlm_attr_withdraw.attr, 403 &gdlm_attr_withdraw.attr,
427 &gdlm_attr_id.attr, 404 &gdlm_attr_id.attr,
428 &lockstruct_attr_jid.attr, 405 &gdlm_attr_jid.attr,
429 &gdlm_attr_first.attr, 406 &gdlm_attr_first.attr,
430 &gdlm_attr_first_done.attr, 407 &gdlm_attr_first_done.attr,
431 &gdlm_attr_recover.attr, 408 &gdlm_attr_recover.attr,
@@ -435,53 +412,6 @@ static struct attribute *lock_module_attrs[] = {
435}; 412};
436 413
437/* 414/*
438 * display struct gfs2_args fields
439 */
440
441struct args_attr {
442 struct attribute attr;
443 ssize_t (*show)(struct gfs2_sbd *, char *);
444};
445
446#define ARGS_ATTR(name, fmt) \
447static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
448{ \
449 return snprintf(buf, PAGE_SIZE, fmt, sdp->sd_args.ar_##name); \
450} \
451static struct args_attr args_attr_##name = __ATTR_RO(name)
452
453ARGS_ATTR(lockproto, "%s\n");
454ARGS_ATTR(locktable, "%s\n");
455ARGS_ATTR(hostdata, "%s\n");
456ARGS_ATTR(spectator, "%d\n");
457ARGS_ATTR(ignore_local_fs, "%d\n");
458ARGS_ATTR(localcaching, "%d\n");
459ARGS_ATTR(localflocks, "%d\n");
460ARGS_ATTR(debug, "%d\n");
461ARGS_ATTR(upgrade, "%d\n");
462ARGS_ATTR(posix_acl, "%d\n");
463ARGS_ATTR(quota, "%u\n");
464ARGS_ATTR(suiddir, "%d\n");
465ARGS_ATTR(data, "%d\n");
466
467static struct attribute *args_attrs[] = {
468 &args_attr_lockproto.attr,
469 &args_attr_locktable.attr,
470 &args_attr_hostdata.attr,
471 &args_attr_spectator.attr,
472 &args_attr_ignore_local_fs.attr,
473 &args_attr_localcaching.attr,
474 &args_attr_localflocks.attr,
475 &args_attr_debug.attr,
476 &args_attr_upgrade.attr,
477 &args_attr_posix_acl.attr,
478 &args_attr_quota.attr,
479 &args_attr_suiddir.attr,
480 &args_attr_data.attr,
481 NULL,
482};
483
484/*
485 * get and set struct gfs2_tune fields 415 * get and set struct gfs2_tune fields
486 */ 416 */
487 417
@@ -531,14 +461,8 @@ static ssize_t tune_set(struct gfs2_sbd *sdp, unsigned int *field,
531 return len; 461 return len;
532} 462}
533 463
534struct tune_attr {
535 struct attribute attr;
536 ssize_t (*show)(struct gfs2_sbd *, char *);
537 ssize_t (*store)(struct gfs2_sbd *, const char *, size_t);
538};
539
540#define TUNE_ATTR_3(name, show, store) \ 464#define TUNE_ATTR_3(name, show, store) \
541static struct tune_attr tune_attr_##name = __ATTR(name, 0644, show, store) 465static struct gfs2_attr tune_attr_##name = __ATTR(name, 0644, show, store)
542 466
543#define TUNE_ATTR_2(name, store) \ 467#define TUNE_ATTR_2(name, store) \
544static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ 468static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
@@ -554,15 +478,6 @@ static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\
554} \ 478} \
555TUNE_ATTR_2(name, name##_store) 479TUNE_ATTR_2(name, name##_store)
556 480
557#define TUNE_ATTR_DAEMON(name, process) \
558static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\
559{ \
560 ssize_t r = tune_set(sdp, &sdp->sd_tune.gt_##name, 1, buf, len); \
561 wake_up_process(sdp->sd_##process); \
562 return r; \
563} \
564TUNE_ATTR_2(name, name##_store)
565
566TUNE_ATTR(incore_log_blocks, 0); 481TUNE_ATTR(incore_log_blocks, 0);
567TUNE_ATTR(log_flush_secs, 0); 482TUNE_ATTR(log_flush_secs, 0);
568TUNE_ATTR(quota_warn_period, 0); 483TUNE_ATTR(quota_warn_period, 0);
@@ -574,8 +489,6 @@ TUNE_ATTR(new_files_jdata, 0);
574TUNE_ATTR(quota_simul_sync, 1); 489TUNE_ATTR(quota_simul_sync, 1);
575TUNE_ATTR(stall_secs, 1); 490TUNE_ATTR(stall_secs, 1);
576TUNE_ATTR(statfs_quantum, 1); 491TUNE_ATTR(statfs_quantum, 1);
577TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process);
578TUNE_ATTR_DAEMON(logd_secs, logd_process);
579TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store); 492TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store);
580 493
581static struct attribute *tune_attrs[] = { 494static struct attribute *tune_attrs[] = {
@@ -589,23 +502,11 @@ static struct attribute *tune_attrs[] = {
589 &tune_attr_quota_simul_sync.attr, 502 &tune_attr_quota_simul_sync.attr,
590 &tune_attr_stall_secs.attr, 503 &tune_attr_stall_secs.attr,
591 &tune_attr_statfs_quantum.attr, 504 &tune_attr_statfs_quantum.attr,
592 &tune_attr_recoverd_secs.attr,
593 &tune_attr_logd_secs.attr,
594 &tune_attr_quota_scale.attr, 505 &tune_attr_quota_scale.attr,
595 &tune_attr_new_files_jdata.attr, 506 &tune_attr_new_files_jdata.attr,
596 NULL, 507 NULL,
597}; 508};
598 509
599static struct attribute_group lockstruct_group = {
600 .name = "lockstruct",
601 .attrs = lockstruct_attrs,
602};
603
604static struct attribute_group args_group = {
605 .name = "args",
606 .attrs = args_attrs,
607};
608
609static struct attribute_group tune_group = { 510static struct attribute_group tune_group = {
610 .name = "tune", 511 .name = "tune",
611 .attrs = tune_attrs, 512 .attrs = tune_attrs,
@@ -626,17 +527,9 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
626 if (error) 527 if (error)
627 goto fail; 528 goto fail;
628 529
629 error = sysfs_create_group(&sdp->sd_kobj, &lockstruct_group);
630 if (error)
631 goto fail_reg;
632
633 error = sysfs_create_group(&sdp->sd_kobj, &args_group);
634 if (error)
635 goto fail_lockstruct;
636
637 error = sysfs_create_group(&sdp->sd_kobj, &tune_group); 530 error = sysfs_create_group(&sdp->sd_kobj, &tune_group);
638 if (error) 531 if (error)
639 goto fail_args; 532 goto fail_reg;
640 533
641 error = sysfs_create_group(&sdp->sd_kobj, &lock_module_group); 534 error = sysfs_create_group(&sdp->sd_kobj, &lock_module_group);
642 if (error) 535 if (error)
@@ -647,10 +540,6 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
647 540
648fail_tune: 541fail_tune:
649 sysfs_remove_group(&sdp->sd_kobj, &tune_group); 542 sysfs_remove_group(&sdp->sd_kobj, &tune_group);
650fail_args:
651 sysfs_remove_group(&sdp->sd_kobj, &args_group);
652fail_lockstruct:
653 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
654fail_reg: 543fail_reg:
655 kobject_put(&sdp->sd_kobj); 544 kobject_put(&sdp->sd_kobj);
656fail: 545fail:
@@ -661,8 +550,6 @@ fail:
661void gfs2_sys_fs_del(struct gfs2_sbd *sdp) 550void gfs2_sys_fs_del(struct gfs2_sbd *sdp)
662{ 551{
663 sysfs_remove_group(&sdp->sd_kobj, &tune_group); 552 sysfs_remove_group(&sdp->sd_kobj, &tune_group);
664 sysfs_remove_group(&sdp->sd_kobj, &args_group);
665 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
666 sysfs_remove_group(&sdp->sd_kobj, &lock_module_group); 553 sysfs_remove_group(&sdp->sd_kobj, &lock_module_group);
667 kobject_put(&sdp->sd_kobj); 554 kobject_put(&sdp->sd_kobj);
668} 555}
diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c
index 053752d4b27f..4ef0e9fa3549 100644
--- a/fs/gfs2/trans.c
+++ b/fs/gfs2/trans.c
@@ -33,6 +33,9 @@ int gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks,
33 BUG_ON(current->journal_info); 33 BUG_ON(current->journal_info);
34 BUG_ON(blocks == 0 && revokes == 0); 34 BUG_ON(blocks == 0 && revokes == 0);
35 35
36 if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags))
37 return -EROFS;
38
36 tr = kzalloc(sizeof(struct gfs2_trans), GFP_NOFS); 39 tr = kzalloc(sizeof(struct gfs2_trans), GFP_NOFS);
37 if (!tr) 40 if (!tr)
38 return -ENOMEM; 41 return -ENOMEM;
@@ -54,12 +57,6 @@ int gfs2_trans_begin(struct gfs2_sbd *sdp, unsigned int blocks,
54 if (error) 57 if (error)
55 goto fail_holder_uninit; 58 goto fail_holder_uninit;
56 59
57 if (!test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) {
58 tr->tr_t_gh.gh_flags |= GL_NOCACHE;
59 error = -EROFS;
60 goto fail_gunlock;
61 }
62
63 error = gfs2_log_reserve(sdp, tr->tr_reserved); 60 error = gfs2_log_reserve(sdp, tr->tr_reserved);
64 if (error) 61 if (error)
65 goto fail_gunlock; 62 goto fail_gunlock;
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index c1462d43e721..941c8425c10b 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -30,6 +30,7 @@
30#include <linux/dnotify.h> 30#include <linux/dnotify.h>
31#include <linux/statfs.h> 31#include <linux/statfs.h>
32#include <linux/security.h> 32#include <linux/security.h>
33#include <linux/ima.h>
33 34
34#include <asm/uaccess.h> 35#include <asm/uaccess.h>
35 36
@@ -986,6 +987,7 @@ struct file *hugetlb_file_setup(const char *name, size_t size, int acctflag)
986 &hugetlbfs_file_operations); 987 &hugetlbfs_file_operations);
987 if (!file) 988 if (!file)
988 goto out_dentry; /* inode is already attached */ 989 goto out_dentry; /* inode is already attached */
990 ima_counts_get(file);
989 991
990 return file; 992 return file;
991 993
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 82d9c42b8bac..286f38dfc6c0 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -414,10 +414,6 @@ static int file_ioctl(struct file *filp, unsigned int cmd,
414 switch (cmd) { 414 switch (cmd) {
415 case FIBMAP: 415 case FIBMAP:
416 return ioctl_fibmap(filp, p); 416 return ioctl_fibmap(filp, p);
417 case FS_IOC_FIEMAP:
418 return ioctl_fiemap(filp, arg);
419 case FIGETBSZ:
420 return put_user(inode->i_sb->s_blocksize, p);
421 case FIONREAD: 417 case FIONREAD:
422 return put_user(i_size_read(inode) - filp->f_pos, p); 418 return put_user(i_size_read(inode) - filp->f_pos, p);
423 } 419 }
@@ -557,6 +553,16 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
557 error = ioctl_fsthaw(filp); 553 error = ioctl_fsthaw(filp);
558 break; 554 break;
559 555
556 case FS_IOC_FIEMAP:
557 return ioctl_fiemap(filp, arg);
558
559 case FIGETBSZ:
560 {
561 struct inode *inode = filp->f_path.dentry->d_inode;
562 int __user *p = (int __user *)arg;
563 return put_user(inode->i_sb->s_blocksize, p);
564 }
565
560 default: 566 default:
561 if (S_ISREG(filp->f_path.dentry->d_inode->i_mode)) 567 if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
562 error = file_ioctl(filp, cmd, arg); 568 error = file_ioctl(filp, cmd, arg);
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 58144102bf25..62be7d294ec2 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1781,7 +1781,7 @@ int jbd2_journal_wipe(journal_t *journal, int write)
1781 * Journal abort has very specific semantics, which we describe 1781 * Journal abort has very specific semantics, which we describe
1782 * for journal abort. 1782 * for journal abort.
1783 * 1783 *
1784 * Two internal function, which provide abort to te jbd layer 1784 * Two internal functions, which provide abort to the jbd layer
1785 * itself are here. 1785 * itself are here.
1786 */ 1786 */
1787 1787
@@ -1879,7 +1879,7 @@ void jbd2_journal_abort(journal_t *journal, int errno)
1879 * int jbd2_journal_errno () - returns the journal's error state. 1879 * int jbd2_journal_errno () - returns the journal's error state.
1880 * @journal: journal to examine. 1880 * @journal: journal to examine.
1881 * 1881 *
1882 * This is the errno numbet set with jbd2_journal_abort(), the last 1882 * This is the errno number set with jbd2_journal_abort(), the last
1883 * time the journal was mounted - if the journal was stopped 1883 * time the journal was mounted - if the journal was stopped
1884 * without calling abort this will be 0. 1884 * without calling abort this will be 0.
1885 * 1885 *
@@ -1903,7 +1903,7 @@ int jbd2_journal_errno(journal_t *journal)
1903 * int jbd2_journal_clear_err () - clears the journal's error state 1903 * int jbd2_journal_clear_err () - clears the journal's error state
1904 * @journal: journal to act on. 1904 * @journal: journal to act on.
1905 * 1905 *
1906 * An error must be cleared or Acked to take a FS out of readonly 1906 * An error must be cleared or acked to take a FS out of readonly
1907 * mode. 1907 * mode.
1908 */ 1908 */
1909int jbd2_journal_clear_err(journal_t *journal) 1909int jbd2_journal_clear_err(journal_t *journal)
@@ -1923,7 +1923,7 @@ int jbd2_journal_clear_err(journal_t *journal)
1923 * void jbd2_journal_ack_err() - Ack journal err. 1923 * void jbd2_journal_ack_err() - Ack journal err.
1924 * @journal: journal to act on. 1924 * @journal: journal to act on.
1925 * 1925 *
1926 * An error must be cleared or Acked to take a FS out of readonly 1926 * An error must be cleared or acked to take a FS out of readonly
1927 * mode. 1927 * mode.
1928 */ 1928 */
1929void jbd2_journal_ack_err(journal_t *journal) 1929void jbd2_journal_ack_err(journal_t *journal)
diff --git a/fs/mpage.c b/fs/mpage.c
index 680ba60863ff..42381bd6543b 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -379,7 +379,8 @@ mpage_readpages(struct address_space *mapping, struct list_head *pages,
379 struct buffer_head map_bh; 379 struct buffer_head map_bh;
380 unsigned long first_logical_block = 0; 380 unsigned long first_logical_block = 0;
381 381
382 clear_buffer_mapped(&map_bh); 382 map_bh.b_state = 0;
383 map_bh.b_size = 0;
383 for (page_idx = 0; page_idx < nr_pages; page_idx++) { 384 for (page_idx = 0; page_idx < nr_pages; page_idx++) {
384 struct page *page = list_entry(pages->prev, struct page, lru); 385 struct page *page = list_entry(pages->prev, struct page, lru);
385 386
@@ -412,7 +413,8 @@ int mpage_readpage(struct page *page, get_block_t get_block)
412 struct buffer_head map_bh; 413 struct buffer_head map_bh;
413 unsigned long first_logical_block = 0; 414 unsigned long first_logical_block = 0;
414 415
415 clear_buffer_mapped(&map_bh); 416 map_bh.b_state = 0;
417 map_bh.b_size = 0;
416 bio = do_mpage_readpage(bio, page, 1, &last_block_in_bio, 418 bio = do_mpage_readpage(bio, page, 1, &last_block_in_bio,
417 &map_bh, &first_logical_block, get_block); 419 &map_bh, &first_logical_block, get_block);
418 if (bio) 420 if (bio)
diff --git a/fs/namei.c b/fs/namei.c
index 967c3db92724..c82805d088e1 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -853,7 +853,8 @@ static int __link_path_walk(const char *name, struct nameidata *nd)
853 err = inode_permission(nd->path.dentry->d_inode, 853 err = inode_permission(nd->path.dentry->d_inode,
854 MAY_EXEC); 854 MAY_EXEC);
855 if (!err) 855 if (!err)
856 err = ima_path_check(&nd->path, MAY_EXEC); 856 err = ima_path_check(&nd->path, MAY_EXEC,
857 IMA_COUNT_UPDATE);
857 if (err) 858 if (err)
858 break; 859 break;
859 860
@@ -1515,7 +1516,8 @@ int may_open(struct path *path, int acc_mode, int flag)
1515 return error; 1516 return error;
1516 1517
1517 error = ima_path_check(path, 1518 error = ima_path_check(path,
1518 acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC)); 1519 acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC),
1520 IMA_COUNT_UPDATE);
1519 if (error) 1521 if (error)
1520 return error; 1522 return error;
1521 /* 1523 /*
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index b660435978d2..bd584bcf1d9f 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -55,6 +55,7 @@
55#include <linux/security.h> 55#include <linux/security.h>
56#endif /* CONFIG_NFSD_V4 */ 56#endif /* CONFIG_NFSD_V4 */
57#include <linux/jhash.h> 57#include <linux/jhash.h>
58#include <linux/ima.h>
58 59
59#include <asm/uaccess.h> 60#include <asm/uaccess.h>
60 61
@@ -735,6 +736,8 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
735 flags, cred); 736 flags, cred);
736 if (IS_ERR(*filp)) 737 if (IS_ERR(*filp))
737 host_err = PTR_ERR(*filp); 738 host_err = PTR_ERR(*filp);
739 else
740 ima_counts_get(*filp);
738out_nfserr: 741out_nfserr:
739 err = nfserrno(host_err); 742 err = nfserrno(host_err);
740out: 743out:
@@ -2024,6 +2027,7 @@ nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp,
2024 struct dentry *dentry, int acc) 2027 struct dentry *dentry, int acc)
2025{ 2028{
2026 struct inode *inode = dentry->d_inode; 2029 struct inode *inode = dentry->d_inode;
2030 struct path path;
2027 int err; 2031 int err;
2028 2032
2029 if (acc == NFSD_MAY_NOP) 2033 if (acc == NFSD_MAY_NOP)
@@ -2096,7 +2100,17 @@ nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp,
2096 if (err == -EACCES && S_ISREG(inode->i_mode) && 2100 if (err == -EACCES && S_ISREG(inode->i_mode) &&
2097 acc == (NFSD_MAY_READ | NFSD_MAY_OWNER_OVERRIDE)) 2101 acc == (NFSD_MAY_READ | NFSD_MAY_OWNER_OVERRIDE))
2098 err = inode_permission(inode, MAY_EXEC); 2102 err = inode_permission(inode, MAY_EXEC);
2103 if (err)
2104 goto nfsd_out;
2099 2105
2106 /* Do integrity (permission) checking now, but defer incrementing
2107 * IMA counts to the actual file open.
2108 */
2109 path.mnt = exp->ex_path.mnt;
2110 path.dentry = dentry;
2111 err = ima_path_check(&path, acc & (MAY_READ | MAY_WRITE | MAY_EXEC),
2112 IMA_COUNT_LEAVE);
2113nfsd_out:
2100 return err? nfserrno(err) : 0; 2114 return err? nfserrno(err) : 0;
2101} 2115}
2102 2116
diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c
index 7f65b3be4aa9..a91f15b8673c 100644
--- a/fs/nilfs2/the_nilfs.c
+++ b/fs/nilfs2/the_nilfs.c
@@ -515,7 +515,7 @@ int init_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi, char *data)
515 515
516 blocksize = BLOCK_SIZE << le32_to_cpu(sbp->s_log_block_size); 516 blocksize = BLOCK_SIZE << le32_to_cpu(sbp->s_log_block_size);
517 if (sb->s_blocksize != blocksize) { 517 if (sb->s_blocksize != blocksize) {
518 int hw_blocksize = bdev_hardsect_size(sb->s_bdev); 518 int hw_blocksize = bdev_logical_block_size(sb->s_bdev);
519 519
520 if (blocksize < hw_blocksize) { 520 if (blocksize < hw_blocksize) {
521 printk(KERN_ERR 521 printk(KERN_ERR
diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
index f76951dcd4a6..6aa7c4713536 100644
--- a/fs/ntfs/super.c
+++ b/fs/ntfs/super.c
@@ -25,7 +25,7 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/string.h> 26#include <linux/string.h>
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <linux/blkdev.h> /* For bdev_hardsect_size(). */ 28#include <linux/blkdev.h> /* For bdev_logical_block_size(). */
29#include <linux/backing-dev.h> 29#include <linux/backing-dev.h>
30#include <linux/buffer_head.h> 30#include <linux/buffer_head.h>
31#include <linux/vfs.h> 31#include <linux/vfs.h>
@@ -2785,13 +2785,13 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent)
2785 goto err_out_now; 2785 goto err_out_now;
2786 2786
2787 /* We support sector sizes up to the PAGE_CACHE_SIZE. */ 2787 /* We support sector sizes up to the PAGE_CACHE_SIZE. */
2788 if (bdev_hardsect_size(sb->s_bdev) > PAGE_CACHE_SIZE) { 2788 if (bdev_logical_block_size(sb->s_bdev) > PAGE_CACHE_SIZE) {
2789 if (!silent) 2789 if (!silent)
2790 ntfs_error(sb, "Device has unsupported sector size " 2790 ntfs_error(sb, "Device has unsupported sector size "
2791 "(%i). The maximum supported sector " 2791 "(%i). The maximum supported sector "
2792 "size on this architecture is %lu " 2792 "size on this architecture is %lu "
2793 "bytes.", 2793 "bytes.",
2794 bdev_hardsect_size(sb->s_bdev), 2794 bdev_logical_block_size(sb->s_bdev),
2795 PAGE_CACHE_SIZE); 2795 PAGE_CACHE_SIZE);
2796 goto err_out_now; 2796 goto err_out_now;
2797 } 2797 }
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 4f85eceab376..09cc25d04611 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -1371,7 +1371,7 @@ static ssize_t o2hb_region_dev_write(struct o2hb_region *reg,
1371 1371
1372 bdevname(reg->hr_bdev, reg->hr_dev_name); 1372 bdevname(reg->hr_bdev, reg->hr_dev_name);
1373 1373
1374 sectsize = bdev_hardsect_size(reg->hr_bdev); 1374 sectsize = bdev_logical_block_size(reg->hr_bdev);
1375 if (sectsize != reg->hr_block_bytes) { 1375 if (sectsize != reg->hr_block_bytes) {
1376 mlog(ML_ERROR, 1376 mlog(ML_ERROR,
1377 "blocksize %u incorrect for device, expected %d", 1377 "blocksize %u incorrect for device, expected %d",
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
index 79ff8d9d37e0..5c6163f55039 100644
--- a/fs/ocfs2/super.c
+++ b/fs/ocfs2/super.c
@@ -713,7 +713,7 @@ static int ocfs2_sb_probe(struct super_block *sb,
713 *bh = NULL; 713 *bh = NULL;
714 714
715 /* may be > 512 */ 715 /* may be > 512 */
716 *sector_size = bdev_hardsect_size(sb->s_bdev); 716 *sector_size = bdev_logical_block_size(sb->s_bdev);
717 if (*sector_size > OCFS2_MAX_BLOCKSIZE) { 717 if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
718 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n", 718 mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
719 *sector_size, OCFS2_MAX_BLOCKSIZE); 719 *sector_size, OCFS2_MAX_BLOCKSIZE);
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 99e33ef40be4..0af36085eb28 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -219,6 +219,13 @@ ssize_t part_size_show(struct device *dev,
219 return sprintf(buf, "%llu\n",(unsigned long long)p->nr_sects); 219 return sprintf(buf, "%llu\n",(unsigned long long)p->nr_sects);
220} 220}
221 221
222ssize_t part_alignment_offset_show(struct device *dev,
223 struct device_attribute *attr, char *buf)
224{
225 struct hd_struct *p = dev_to_part(dev);
226 return sprintf(buf, "%llu\n", (unsigned long long)p->alignment_offset);
227}
228
222ssize_t part_stat_show(struct device *dev, 229ssize_t part_stat_show(struct device *dev,
223 struct device_attribute *attr, char *buf) 230 struct device_attribute *attr, char *buf)
224{ 231{
@@ -272,6 +279,7 @@ ssize_t part_fail_store(struct device *dev,
272static DEVICE_ATTR(partition, S_IRUGO, part_partition_show, NULL); 279static DEVICE_ATTR(partition, S_IRUGO, part_partition_show, NULL);
273static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL); 280static DEVICE_ATTR(start, S_IRUGO, part_start_show, NULL);
274static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL); 281static DEVICE_ATTR(size, S_IRUGO, part_size_show, NULL);
282static DEVICE_ATTR(alignment_offset, S_IRUGO, part_alignment_offset_show, NULL);
275static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL); 283static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL);
276#ifdef CONFIG_FAIL_MAKE_REQUEST 284#ifdef CONFIG_FAIL_MAKE_REQUEST
277static struct device_attribute dev_attr_fail = 285static struct device_attribute dev_attr_fail =
@@ -282,6 +290,7 @@ static struct attribute *part_attrs[] = {
282 &dev_attr_partition.attr, 290 &dev_attr_partition.attr,
283 &dev_attr_start.attr, 291 &dev_attr_start.attr,
284 &dev_attr_size.attr, 292 &dev_attr_size.attr,
293 &dev_attr_alignment_offset.attr,
285 &dev_attr_stat.attr, 294 &dev_attr_stat.attr,
286#ifdef CONFIG_FAIL_MAKE_REQUEST 295#ifdef CONFIG_FAIL_MAKE_REQUEST
287 &dev_attr_fail.attr, 296 &dev_attr_fail.attr,
@@ -383,6 +392,7 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
383 pdev = part_to_dev(p); 392 pdev = part_to_dev(p);
384 393
385 p->start_sect = start; 394 p->start_sect = start;
395 p->alignment_offset = queue_sector_alignment_offset(disk->queue, start);
386 p->nr_sects = len; 396 p->nr_sects = len;
387 p->partno = partno; 397 p->partno = partno;
388 p->policy = get_disk_ro(disk); 398 p->policy = get_disk_ro(disk);
diff --git a/fs/partitions/ibm.c b/fs/partitions/ibm.c
index 46297683cd34..fc71aab08460 100644
--- a/fs/partitions/ibm.c
+++ b/fs/partitions/ibm.c
@@ -76,7 +76,7 @@ ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
76 Sector sect; 76 Sector sect;
77 77
78 res = 0; 78 res = 0;
79 blocksize = bdev_hardsect_size(bdev); 79 blocksize = bdev_logical_block_size(bdev);
80 if (blocksize <= 0) 80 if (blocksize <= 0)
81 goto out_exit; 81 goto out_exit;
82 i_size = i_size_read(bdev->bd_inode); 82 i_size = i_size_read(bdev->bd_inode);
diff --git a/fs/partitions/msdos.c b/fs/partitions/msdos.c
index 796511886f28..0028d2ef0662 100644
--- a/fs/partitions/msdos.c
+++ b/fs/partitions/msdos.c
@@ -110,7 +110,7 @@ parse_extended(struct parsed_partitions *state, struct block_device *bdev,
110 Sector sect; 110 Sector sect;
111 unsigned char *data; 111 unsigned char *data;
112 u32 this_sector, this_size; 112 u32 this_sector, this_size;
113 int sector_size = bdev_hardsect_size(bdev) / 512; 113 int sector_size = bdev_logical_block_size(bdev) / 512;
114 int loopct = 0; /* number of links followed 114 int loopct = 0; /* number of links followed
115 without finding a data partition */ 115 without finding a data partition */
116 int i; 116 int i;
@@ -415,7 +415,7 @@ static struct {
415 415
416int msdos_partition(struct parsed_partitions *state, struct block_device *bdev) 416int msdos_partition(struct parsed_partitions *state, struct block_device *bdev)
417{ 417{
418 int sector_size = bdev_hardsect_size(bdev) / 512; 418 int sector_size = bdev_logical_block_size(bdev) / 512;
419 Sector sect; 419 Sector sect;
420 unsigned char *data; 420 unsigned char *data;
421 struct partition *p; 421 struct partition *p;
diff --git a/fs/pipe.c b/fs/pipe.c
index 13414ec45b8d..f7dd21ad85a6 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -302,6 +302,20 @@ int generic_pipe_buf_confirm(struct pipe_inode_info *info,
302 return 0; 302 return 0;
303} 303}
304 304
305/**
306 * generic_pipe_buf_release - put a reference to a &struct pipe_buffer
307 * @pipe: the pipe that the buffer belongs to
308 * @buf: the buffer to put a reference to
309 *
310 * Description:
311 * This function releases a reference to @buf.
312 */
313void generic_pipe_buf_release(struct pipe_inode_info *pipe,
314 struct pipe_buffer *buf)
315{
316 page_cache_release(buf->page);
317}
318
305static const struct pipe_buf_operations anon_pipe_buf_ops = { 319static const struct pipe_buf_operations anon_pipe_buf_ops = {
306 .can_merge = 1, 320 .can_merge = 1,
307 .map = generic_pipe_buf_map, 321 .map = generic_pipe_buf_map,
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 3326bbf9ab95..1539e630c47d 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2128,9 +2128,15 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf,
2128 if (copy_from_user(page, buf, count)) 2128 if (copy_from_user(page, buf, count))
2129 goto out_free; 2129 goto out_free;
2130 2130
2131 /* Guard against adverse ptrace interaction */
2132 length = mutex_lock_interruptible(&task->cred_guard_mutex);
2133 if (length < 0)
2134 goto out_free;
2135
2131 length = security_setprocattr(task, 2136 length = security_setprocattr(task,
2132 (char*)file->f_path.dentry->d_name.name, 2137 (char*)file->f_path.dentry->d_name.name,
2133 (void*)page, count); 2138 (void*)page, count);
2139 mutex_unlock(&task->cred_guard_mutex);
2134out_free: 2140out_free:
2135 free_page((unsigned long) page); 2141 free_page((unsigned long) page);
2136out: 2142out:
diff --git a/fs/read_write.c b/fs/read_write.c
index 9d1e76bb9ee1..6c8c55dec2bc 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -805,12 +805,6 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
805 goto out; 805 goto out;
806 if (!(in_file->f_mode & FMODE_READ)) 806 if (!(in_file->f_mode & FMODE_READ))
807 goto fput_in; 807 goto fput_in;
808 retval = -EINVAL;
809 in_inode = in_file->f_path.dentry->d_inode;
810 if (!in_inode)
811 goto fput_in;
812 if (!in_file->f_op || !in_file->f_op->splice_read)
813 goto fput_in;
814 retval = -ESPIPE; 808 retval = -ESPIPE;
815 if (!ppos) 809 if (!ppos)
816 ppos = &in_file->f_pos; 810 ppos = &in_file->f_pos;
@@ -834,6 +828,7 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos,
834 retval = -EINVAL; 828 retval = -EINVAL;
835 if (!out_file->f_op || !out_file->f_op->sendpage) 829 if (!out_file->f_op || !out_file->f_op->sendpage)
836 goto fput_out; 830 goto fput_out;
831 in_inode = in_file->f_path.dentry->d_inode;
837 out_inode = out_file->f_path.dentry->d_inode; 832 out_inode = out_file->f_path.dentry->d_inode;
838 retval = rw_verify_area(WRITE, out_file, &out_file->f_pos, count); 833 retval = rw_verify_area(WRITE, out_file, &out_file->f_pos, count);
839 if (retval < 0) 834 if (retval < 0)
diff --git a/fs/splice.c b/fs/splice.c
index 666953d59a35..73766d24f97b 100644
--- a/fs/splice.c
+++ b/fs/splice.c
@@ -507,9 +507,131 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos,
507 507
508 return ret; 508 return ret;
509} 509}
510
511EXPORT_SYMBOL(generic_file_splice_read); 510EXPORT_SYMBOL(generic_file_splice_read);
512 511
512static const struct pipe_buf_operations default_pipe_buf_ops = {
513 .can_merge = 0,
514 .map = generic_pipe_buf_map,
515 .unmap = generic_pipe_buf_unmap,
516 .confirm = generic_pipe_buf_confirm,
517 .release = generic_pipe_buf_release,
518 .steal = generic_pipe_buf_steal,
519 .get = generic_pipe_buf_get,
520};
521
522static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
523 unsigned long vlen, loff_t offset)
524{
525 mm_segment_t old_fs;
526 loff_t pos = offset;
527 ssize_t res;
528
529 old_fs = get_fs();
530 set_fs(get_ds());
531 /* The cast to a user pointer is valid due to the set_fs() */
532 res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
533 set_fs(old_fs);
534
535 return res;
536}
537
538static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
539 loff_t pos)
540{
541 mm_segment_t old_fs;
542 ssize_t res;
543
544 old_fs = get_fs();
545 set_fs(get_ds());
546 /* The cast to a user pointer is valid due to the set_fs() */
547 res = vfs_write(file, (const char __user *)buf, count, &pos);
548 set_fs(old_fs);
549
550 return res;
551}
552
553ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
554 struct pipe_inode_info *pipe, size_t len,
555 unsigned int flags)
556{
557 unsigned int nr_pages;
558 unsigned int nr_freed;
559 size_t offset;
560 struct page *pages[PIPE_BUFFERS];
561 struct partial_page partial[PIPE_BUFFERS];
562 struct iovec vec[PIPE_BUFFERS];
563 pgoff_t index;
564 ssize_t res;
565 size_t this_len;
566 int error;
567 int i;
568 struct splice_pipe_desc spd = {
569 .pages = pages,
570 .partial = partial,
571 .flags = flags,
572 .ops = &default_pipe_buf_ops,
573 .spd_release = spd_release_page,
574 };
575
576 index = *ppos >> PAGE_CACHE_SHIFT;
577 offset = *ppos & ~PAGE_CACHE_MASK;
578 nr_pages = (len + offset + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT;
579
580 for (i = 0; i < nr_pages && i < PIPE_BUFFERS && len; i++) {
581 struct page *page;
582
583 page = alloc_page(GFP_USER);
584 error = -ENOMEM;
585 if (!page)
586 goto err;
587
588 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
589 vec[i].iov_base = (void __user *) page_address(page);
590 vec[i].iov_len = this_len;
591 pages[i] = page;
592 spd.nr_pages++;
593 len -= this_len;
594 offset = 0;
595 }
596
597 res = kernel_readv(in, vec, spd.nr_pages, *ppos);
598 if (res < 0) {
599 error = res;
600 goto err;
601 }
602
603 error = 0;
604 if (!res)
605 goto err;
606
607 nr_freed = 0;
608 for (i = 0; i < spd.nr_pages; i++) {
609 this_len = min_t(size_t, vec[i].iov_len, res);
610 partial[i].offset = 0;
611 partial[i].len = this_len;
612 if (!this_len) {
613 __free_page(pages[i]);
614 pages[i] = NULL;
615 nr_freed++;
616 }
617 res -= this_len;
618 }
619 spd.nr_pages -= nr_freed;
620
621 res = splice_to_pipe(pipe, &spd);
622 if (res > 0)
623 *ppos += res;
624
625 return res;
626
627err:
628 for (i = 0; i < spd.nr_pages; i++)
629 __free_page(pages[i]);
630
631 return error;
632}
633EXPORT_SYMBOL(default_file_splice_read);
634
513/* 635/*
514 * Send 'sd->len' bytes to socket from 'sd->file' at position 'sd->pos' 636 * Send 'sd->len' bytes to socket from 'sd->file' at position 'sd->pos'
515 * using sendpage(). Return the number of bytes sent. 637 * using sendpage(). Return the number of bytes sent.
@@ -881,6 +1003,36 @@ generic_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
881 1003
882EXPORT_SYMBOL(generic_file_splice_write); 1004EXPORT_SYMBOL(generic_file_splice_write);
883 1005
1006static int write_pipe_buf(struct pipe_inode_info *pipe, struct pipe_buffer *buf,
1007 struct splice_desc *sd)
1008{
1009 int ret;
1010 void *data;
1011
1012 ret = buf->ops->confirm(pipe, buf);
1013 if (ret)
1014 return ret;
1015
1016 data = buf->ops->map(pipe, buf, 0);
1017 ret = kernel_write(sd->u.file, data + buf->offset, sd->len, sd->pos);
1018 buf->ops->unmap(pipe, buf, data);
1019
1020 return ret;
1021}
1022
1023static ssize_t default_file_splice_write(struct pipe_inode_info *pipe,
1024 struct file *out, loff_t *ppos,
1025 size_t len, unsigned int flags)
1026{
1027 ssize_t ret;
1028
1029 ret = splice_from_pipe(pipe, out, ppos, len, flags, write_pipe_buf);
1030 if (ret > 0)
1031 *ppos += ret;
1032
1033 return ret;
1034}
1035
884/** 1036/**
885 * generic_splice_sendpage - splice data from a pipe to a socket 1037 * generic_splice_sendpage - splice data from a pipe to a socket
886 * @pipe: pipe to splice from 1038 * @pipe: pipe to splice from
@@ -908,11 +1060,10 @@ EXPORT_SYMBOL(generic_splice_sendpage);
908static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, 1060static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
909 loff_t *ppos, size_t len, unsigned int flags) 1061 loff_t *ppos, size_t len, unsigned int flags)
910{ 1062{
1063 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
1064 loff_t *, size_t, unsigned int);
911 int ret; 1065 int ret;
912 1066
913 if (unlikely(!out->f_op || !out->f_op->splice_write))
914 return -EINVAL;
915
916 if (unlikely(!(out->f_mode & FMODE_WRITE))) 1067 if (unlikely(!(out->f_mode & FMODE_WRITE)))
917 return -EBADF; 1068 return -EBADF;
918 1069
@@ -923,7 +1074,11 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
923 if (unlikely(ret < 0)) 1074 if (unlikely(ret < 0))
924 return ret; 1075 return ret;
925 1076
926 return out->f_op->splice_write(pipe, out, ppos, len, flags); 1077 splice_write = out->f_op->splice_write;
1078 if (!splice_write)
1079 splice_write = default_file_splice_write;
1080
1081 return splice_write(pipe, out, ppos, len, flags);
927} 1082}
928 1083
929/* 1084/*
@@ -933,11 +1088,10 @@ static long do_splice_to(struct file *in, loff_t *ppos,
933 struct pipe_inode_info *pipe, size_t len, 1088 struct pipe_inode_info *pipe, size_t len,
934 unsigned int flags) 1089 unsigned int flags)
935{ 1090{
1091 ssize_t (*splice_read)(struct file *, loff_t *,
1092 struct pipe_inode_info *, size_t, unsigned int);
936 int ret; 1093 int ret;
937 1094
938 if (unlikely(!in->f_op || !in->f_op->splice_read))
939 return -EINVAL;
940
941 if (unlikely(!(in->f_mode & FMODE_READ))) 1095 if (unlikely(!(in->f_mode & FMODE_READ)))
942 return -EBADF; 1096 return -EBADF;
943 1097
@@ -945,7 +1099,11 @@ static long do_splice_to(struct file *in, loff_t *ppos,
945 if (unlikely(ret < 0)) 1099 if (unlikely(ret < 0))
946 return ret; 1100 return ret;
947 1101
948 return in->f_op->splice_read(in, ppos, pipe, len, flags); 1102 splice_read = in->f_op->splice_read;
1103 if (!splice_read)
1104 splice_read = default_file_splice_read;
1105
1106 return splice_read(in, ppos, pipe, len, flags);
949} 1107}
950 1108
951/** 1109/**
@@ -1112,6 +1270,9 @@ long do_splice_direct(struct file *in, loff_t *ppos, struct file *out,
1112 return ret; 1270 return ret;
1113} 1271}
1114 1272
1273static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe,
1274 struct pipe_inode_info *opipe,
1275 size_t len, unsigned int flags);
1115/* 1276/*
1116 * After the inode slimming patch, i_pipe/i_bdev/i_cdev share the same 1277 * After the inode slimming patch, i_pipe/i_bdev/i_cdev share the same
1117 * location, so checking ->i_pipe is not enough to verify that this is a 1278 * location, so checking ->i_pipe is not enough to verify that this is a
@@ -1132,12 +1293,32 @@ static long do_splice(struct file *in, loff_t __user *off_in,
1132 struct file *out, loff_t __user *off_out, 1293 struct file *out, loff_t __user *off_out,
1133 size_t len, unsigned int flags) 1294 size_t len, unsigned int flags)
1134{ 1295{
1135 struct pipe_inode_info *pipe; 1296 struct pipe_inode_info *ipipe;
1297 struct pipe_inode_info *opipe;
1136 loff_t offset, *off; 1298 loff_t offset, *off;
1137 long ret; 1299 long ret;
1138 1300
1139 pipe = pipe_info(in->f_path.dentry->d_inode); 1301 ipipe = pipe_info(in->f_path.dentry->d_inode);
1140 if (pipe) { 1302 opipe = pipe_info(out->f_path.dentry->d_inode);
1303
1304 if (ipipe && opipe) {
1305 if (off_in || off_out)
1306 return -ESPIPE;
1307
1308 if (!(in->f_mode & FMODE_READ))
1309 return -EBADF;
1310
1311 if (!(out->f_mode & FMODE_WRITE))
1312 return -EBADF;
1313
1314 /* Splicing to self would be fun, but... */
1315 if (ipipe == opipe)
1316 return -EINVAL;
1317
1318 return splice_pipe_to_pipe(ipipe, opipe, len, flags);
1319 }
1320
1321 if (ipipe) {
1141 if (off_in) 1322 if (off_in)
1142 return -ESPIPE; 1323 return -ESPIPE;
1143 if (off_out) { 1324 if (off_out) {
@@ -1149,7 +1330,7 @@ static long do_splice(struct file *in, loff_t __user *off_in,
1149 } else 1330 } else
1150 off = &out->f_pos; 1331 off = &out->f_pos;
1151 1332
1152 ret = do_splice_from(pipe, out, off, len, flags); 1333 ret = do_splice_from(ipipe, out, off, len, flags);
1153 1334
1154 if (off_out && copy_to_user(off_out, off, sizeof(loff_t))) 1335 if (off_out && copy_to_user(off_out, off, sizeof(loff_t)))
1155 ret = -EFAULT; 1336 ret = -EFAULT;
@@ -1157,8 +1338,7 @@ static long do_splice(struct file *in, loff_t __user *off_in,
1157 return ret; 1338 return ret;
1158 } 1339 }
1159 1340
1160 pipe = pipe_info(out->f_path.dentry->d_inode); 1341 if (opipe) {
1161 if (pipe) {
1162 if (off_out) 1342 if (off_out)
1163 return -ESPIPE; 1343 return -ESPIPE;
1164 if (off_in) { 1344 if (off_in) {
@@ -1170,7 +1350,7 @@ static long do_splice(struct file *in, loff_t __user *off_in,
1170 } else 1350 } else
1171 off = &in->f_pos; 1351 off = &in->f_pos;
1172 1352
1173 ret = do_splice_to(in, off, pipe, len, flags); 1353 ret = do_splice_to(in, off, opipe, len, flags);
1174 1354
1175 if (off_in && copy_to_user(off_in, off, sizeof(loff_t))) 1355 if (off_in && copy_to_user(off_in, off, sizeof(loff_t)))
1176 ret = -EFAULT; 1356 ret = -EFAULT;
@@ -1511,7 +1691,7 @@ SYSCALL_DEFINE6(splice, int, fd_in, loff_t __user *, off_in,
1511 * Make sure there's data to read. Wait for input if we can, otherwise 1691 * Make sure there's data to read. Wait for input if we can, otherwise
1512 * return an appropriate error. 1692 * return an appropriate error.
1513 */ 1693 */
1514static int link_ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags) 1694static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
1515{ 1695{
1516 int ret; 1696 int ret;
1517 1697
@@ -1549,7 +1729,7 @@ static int link_ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
1549 * Make sure there's writeable room. Wait for room if we can, otherwise 1729 * Make sure there's writeable room. Wait for room if we can, otherwise
1550 * return an appropriate error. 1730 * return an appropriate error.
1551 */ 1731 */
1552static int link_opipe_prep(struct pipe_inode_info *pipe, unsigned int flags) 1732static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
1553{ 1733{
1554 int ret; 1734 int ret;
1555 1735
@@ -1587,6 +1767,124 @@ static int link_opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
1587} 1767}
1588 1768
1589/* 1769/*
1770 * Splice contents of ipipe to opipe.
1771 */
1772static int splice_pipe_to_pipe(struct pipe_inode_info *ipipe,
1773 struct pipe_inode_info *opipe,
1774 size_t len, unsigned int flags)
1775{
1776 struct pipe_buffer *ibuf, *obuf;
1777 int ret = 0, nbuf;
1778 bool input_wakeup = false;
1779
1780
1781retry:
1782 ret = ipipe_prep(ipipe, flags);
1783 if (ret)
1784 return ret;
1785
1786 ret = opipe_prep(opipe, flags);
1787 if (ret)
1788 return ret;
1789
1790 /*
1791 * Potential ABBA deadlock, work around it by ordering lock
1792 * grabbing by pipe info address. Otherwise two different processes
1793 * could deadlock (one doing tee from A -> B, the other from B -> A).
1794 */
1795 pipe_double_lock(ipipe, opipe);
1796
1797 do {
1798 if (!opipe->readers) {
1799 send_sig(SIGPIPE, current, 0);
1800 if (!ret)
1801 ret = -EPIPE;
1802 break;
1803 }
1804
1805 if (!ipipe->nrbufs && !ipipe->writers)
1806 break;
1807
1808 /*
1809 * Cannot make any progress, because either the input
1810 * pipe is empty or the output pipe is full.
1811 */
1812 if (!ipipe->nrbufs || opipe->nrbufs >= PIPE_BUFFERS) {
1813 /* Already processed some buffers, break */
1814 if (ret)
1815 break;
1816
1817 if (flags & SPLICE_F_NONBLOCK) {
1818 ret = -EAGAIN;
1819 break;
1820 }
1821
1822 /*
1823 * We raced with another reader/writer and haven't
1824 * managed to process any buffers. A zero return
1825 * value means EOF, so retry instead.
1826 */
1827 pipe_unlock(ipipe);
1828 pipe_unlock(opipe);
1829 goto retry;
1830 }
1831
1832 ibuf = ipipe->bufs + ipipe->curbuf;
1833 nbuf = (opipe->curbuf + opipe->nrbufs) % PIPE_BUFFERS;
1834 obuf = opipe->bufs + nbuf;
1835
1836 if (len >= ibuf->len) {
1837 /*
1838 * Simply move the whole buffer from ipipe to opipe
1839 */
1840 *obuf = *ibuf;
1841 ibuf->ops = NULL;
1842 opipe->nrbufs++;
1843 ipipe->curbuf = (ipipe->curbuf + 1) % PIPE_BUFFERS;
1844 ipipe->nrbufs--;
1845 input_wakeup = true;
1846 } else {
1847 /*
1848 * Get a reference to this pipe buffer,
1849 * so we can copy the contents over.
1850 */
1851 ibuf->ops->get(ipipe, ibuf);
1852 *obuf = *ibuf;
1853
1854 /*
1855 * Don't inherit the gift flag, we need to
1856 * prevent multiple steals of this page.
1857 */
1858 obuf->flags &= ~PIPE_BUF_FLAG_GIFT;
1859
1860 obuf->len = len;
1861 opipe->nrbufs++;
1862 ibuf->offset += obuf->len;
1863 ibuf->len -= obuf->len;
1864 }
1865 ret += obuf->len;
1866 len -= obuf->len;
1867 } while (len);
1868
1869 pipe_unlock(ipipe);
1870 pipe_unlock(opipe);
1871
1872 /*
1873 * If we put data in the output pipe, wakeup any potential readers.
1874 */
1875 if (ret > 0) {
1876 smp_mb();
1877 if (waitqueue_active(&opipe->wait))
1878 wake_up_interruptible(&opipe->wait);
1879 kill_fasync(&opipe->fasync_readers, SIGIO, POLL_IN);
1880 }
1881 if (input_wakeup)
1882 wakeup_pipe_writers(ipipe);
1883
1884 return ret;
1885}
1886
1887/*
1590 * Link contents of ipipe to opipe. 1888 * Link contents of ipipe to opipe.
1591 */ 1889 */
1592static int link_pipe(struct pipe_inode_info *ipipe, 1890static int link_pipe(struct pipe_inode_info *ipipe,
@@ -1690,9 +1988,9 @@ static long do_tee(struct file *in, struct file *out, size_t len,
1690 * Keep going, unless we encounter an error. The ipipe/opipe 1988 * Keep going, unless we encounter an error. The ipipe/opipe
1691 * ordering doesn't really matter. 1989 * ordering doesn't really matter.
1692 */ 1990 */
1693 ret = link_ipipe_prep(ipipe, flags); 1991 ret = ipipe_prep(ipipe, flags);
1694 if (!ret) { 1992 if (!ret) {
1695 ret = link_opipe_prep(opipe, flags); 1993 ret = opipe_prep(opipe, flags);
1696 if (!ret) 1994 if (!ret)
1697 ret = link_pipe(ipipe, opipe, len, flags); 1995 ret = link_pipe(ipipe, opipe, len, flags);
1698 } 1996 }
diff --git a/fs/udf/super.c b/fs/udf/super.c
index 72348cc855a4..0ba44107d8f1 100644
--- a/fs/udf/super.c
+++ b/fs/udf/super.c
@@ -1915,7 +1915,7 @@ static int udf_fill_super(struct super_block *sb, void *options, int silent)
1915 if (uopt.flags & (1 << UDF_FLAG_BLOCKSIZE_SET)) { 1915 if (uopt.flags & (1 << UDF_FLAG_BLOCKSIZE_SET)) {
1916 ret = udf_load_vrs(sb, &uopt, silent, &fileset); 1916 ret = udf_load_vrs(sb, &uopt, silent, &fileset);
1917 } else { 1917 } else {
1918 uopt.blocksize = bdev_hardsect_size(sb->s_bdev); 1918 uopt.blocksize = bdev_logical_block_size(sb->s_bdev);
1919 ret = udf_load_vrs(sb, &uopt, silent, &fileset); 1919 ret = udf_load_vrs(sb, &uopt, silent, &fileset);
1920 if (!ret && uopt.blocksize != UDF_DEFAULT_BLOCKSIZE) { 1920 if (!ret && uopt.blocksize != UDF_DEFAULT_BLOCKSIZE) {
1921 if (!silent) 1921 if (!silent)
diff --git a/fs/xfs/linux-2.6/xfs_buf.c b/fs/xfs/linux-2.6/xfs_buf.c
index e28800a9f2b5..1418b916fc27 100644
--- a/fs/xfs/linux-2.6/xfs_buf.c
+++ b/fs/xfs/linux-2.6/xfs_buf.c
@@ -1501,7 +1501,7 @@ xfs_setsize_buftarg_early(
1501 struct block_device *bdev) 1501 struct block_device *bdev)
1502{ 1502{
1503 return xfs_setsize_buftarg_flags(btp, 1503 return xfs_setsize_buftarg_flags(btp,
1504 PAGE_CACHE_SIZE, bdev_hardsect_size(bdev), 0); 1504 PAGE_CACHE_SIZE, bdev_logical_block_size(bdev), 0);
1505} 1505}
1506 1506
1507int 1507int
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 7b214fd672a2..12737be58601 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -218,12 +218,12 @@ struct bio {
218#define bio_sectors(bio) ((bio)->bi_size >> 9) 218#define bio_sectors(bio) ((bio)->bi_size >> 9)
219#define bio_empty_barrier(bio) (bio_barrier(bio) && !bio_has_data(bio) && !bio_discard(bio)) 219#define bio_empty_barrier(bio) (bio_barrier(bio) && !bio_has_data(bio) && !bio_discard(bio))
220 220
221static inline unsigned int bio_cur_sectors(struct bio *bio) 221static inline unsigned int bio_cur_bytes(struct bio *bio)
222{ 222{
223 if (bio->bi_vcnt) 223 if (bio->bi_vcnt)
224 return bio_iovec(bio)->bv_len >> 9; 224 return bio_iovec(bio)->bv_len;
225 else /* dataless requests such as discard */ 225 else /* dataless requests such as discard */
226 return bio->bi_size >> 9; 226 return bio->bi_size;
227} 227}
228 228
229static inline void *bio_data(struct bio *bio) 229static inline void *bio_data(struct bio *bio)
@@ -279,7 +279,7 @@ static inline int bio_has_allocated_vec(struct bio *bio)
279#define __BIO_SEG_BOUNDARY(addr1, addr2, mask) \ 279#define __BIO_SEG_BOUNDARY(addr1, addr2, mask) \
280 (((addr1) | (mask)) == (((addr2) - 1) | (mask))) 280 (((addr1) | (mask)) == (((addr2) - 1) | (mask)))
281#define BIOVEC_SEG_BOUNDARY(q, b1, b2) \ 281#define BIOVEC_SEG_BOUNDARY(q, b1, b2) \
282 __BIO_SEG_BOUNDARY(bvec_to_phys((b1)), bvec_to_phys((b2)) + (b2)->bv_len, (q)->seg_boundary_mask) 282 __BIO_SEG_BOUNDARY(bvec_to_phys((b1)), bvec_to_phys((b2)) + (b2)->bv_len, queue_segment_boundary((q)))
283#define BIO_SEG_BOUNDARY(q, b1, b2) \ 283#define BIO_SEG_BOUNDARY(q, b1, b2) \
284 BIOVEC_SEG_BOUNDARY((q), __BVEC_END((b1)), __BVEC_START((b2))) 284 BIOVEC_SEG_BOUNDARY((q), __BVEC_END((b1)), __BVEC_START((b2)))
285 285
@@ -506,7 +506,7 @@ static inline int bio_has_data(struct bio *bio)
506} 506}
507 507
508/* 508/*
509 * BIO list managment for use by remapping drivers (e.g. DM or MD). 509 * BIO list management for use by remapping drivers (e.g. DM or MD) and loop.
510 * 510 *
511 * A bio_list anchors a singly-linked list of bios chained through the bi_next 511 * A bio_list anchors a singly-linked list of bios chained through the bi_next
512 * member of the bio. The bio_list also caches the last list member to allow 512 * member of the bio. The bio_list also caches the last list member to allow
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index b4f71f1a4af7..ebdfde8fe556 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -166,19 +166,9 @@ struct request {
166 enum rq_cmd_type_bits cmd_type; 166 enum rq_cmd_type_bits cmd_type;
167 unsigned long atomic_flags; 167 unsigned long atomic_flags;
168 168
169 /* Maintain bio traversal state for part by part I/O submission. 169 /* the following two fields are internal, NEVER access directly */
170 * hard_* are block layer internals, no driver should touch them! 170 sector_t __sector; /* sector cursor */
171 */ 171 unsigned int __data_len; /* total data len */
172
173 sector_t sector; /* next sector to submit */
174 sector_t hard_sector; /* next sector to complete */
175 unsigned long nr_sectors; /* no. of sectors left to submit */
176 unsigned long hard_nr_sectors; /* no. of sectors left to complete */
177 /* no. of sectors left to submit in the current segment */
178 unsigned int current_nr_sectors;
179
180 /* no. of sectors left to complete in the current segment */
181 unsigned int hard_cur_sectors;
182 172
183 struct bio *bio; 173 struct bio *bio;
184 struct bio *biotail; 174 struct bio *biotail;
@@ -211,8 +201,8 @@ struct request {
211 201
212 unsigned short ioprio; 202 unsigned short ioprio;
213 203
214 void *special; 204 void *special; /* opaque pointer available for LLD use */
215 char *buffer; 205 char *buffer; /* kaddr of the current segment if available */
216 206
217 int tag; 207 int tag;
218 int errors; 208 int errors;
@@ -226,10 +216,9 @@ struct request {
226 unsigned char __cmd[BLK_MAX_CDB]; 216 unsigned char __cmd[BLK_MAX_CDB];
227 unsigned char *cmd; 217 unsigned char *cmd;
228 218
229 unsigned int data_len;
230 unsigned int extra_len; /* length of alignment and padding */ 219 unsigned int extra_len; /* length of alignment and padding */
231 unsigned int sense_len; 220 unsigned int sense_len;
232 void *data; 221 unsigned int resid_len; /* residual count */
233 void *sense; 222 void *sense;
234 223
235 unsigned long deadline; 224 unsigned long deadline;
@@ -318,6 +307,26 @@ struct blk_cmd_filter {
318 struct kobject kobj; 307 struct kobject kobj;
319}; 308};
320 309
310struct queue_limits {
311 unsigned long bounce_pfn;
312 unsigned long seg_boundary_mask;
313
314 unsigned int max_hw_sectors;
315 unsigned int max_sectors;
316 unsigned int max_segment_size;
317 unsigned int physical_block_size;
318 unsigned int alignment_offset;
319 unsigned int io_min;
320 unsigned int io_opt;
321
322 unsigned short logical_block_size;
323 unsigned short max_hw_segments;
324 unsigned short max_phys_segments;
325
326 unsigned char misaligned;
327 unsigned char no_cluster;
328};
329
321struct request_queue 330struct request_queue
322{ 331{
323 /* 332 /*
@@ -369,7 +378,6 @@ struct request_queue
369 /* 378 /*
370 * queue needs bounce pages for pages above this limit 379 * queue needs bounce pages for pages above this limit
371 */ 380 */
372 unsigned long bounce_pfn;
373 gfp_t bounce_gfp; 381 gfp_t bounce_gfp;
374 382
375 /* 383 /*
@@ -398,14 +406,6 @@ struct request_queue
398 unsigned int nr_congestion_off; 406 unsigned int nr_congestion_off;
399 unsigned int nr_batching; 407 unsigned int nr_batching;
400 408
401 unsigned int max_sectors;
402 unsigned int max_hw_sectors;
403 unsigned short max_phys_segments;
404 unsigned short max_hw_segments;
405 unsigned short hardsect_size;
406 unsigned int max_segment_size;
407
408 unsigned long seg_boundary_mask;
409 void *dma_drain_buffer; 409 void *dma_drain_buffer;
410 unsigned int dma_drain_size; 410 unsigned int dma_drain_size;
411 unsigned int dma_pad_mask; 411 unsigned int dma_pad_mask;
@@ -415,12 +415,14 @@ struct request_queue
415 struct list_head tag_busy_list; 415 struct list_head tag_busy_list;
416 416
417 unsigned int nr_sorted; 417 unsigned int nr_sorted;
418 unsigned int in_flight; 418 unsigned int in_flight[2];
419 419
420 unsigned int rq_timeout; 420 unsigned int rq_timeout;
421 struct timer_list timeout; 421 struct timer_list timeout;
422 struct list_head timeout_list; 422 struct list_head timeout_list;
423 423
424 struct queue_limits limits;
425
424 /* 426 /*
425 * sg stuff 427 * sg stuff
426 */ 428 */
@@ -522,6 +524,11 @@ static inline void queue_flag_clear_unlocked(unsigned int flag,
522 __clear_bit(flag, &q->queue_flags); 524 __clear_bit(flag, &q->queue_flags);
523} 525}
524 526
527static inline int queue_in_flight(struct request_queue *q)
528{
529 return q->in_flight[0] + q->in_flight[1];
530}
531
525static inline void queue_flag_clear(unsigned int flag, struct request_queue *q) 532static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
526{ 533{
527 WARN_ON_ONCE(!queue_is_locked(q)); 534 WARN_ON_ONCE(!queue_is_locked(q));
@@ -752,10 +759,17 @@ extern void blk_rq_init(struct request_queue *q, struct request *rq);
752extern void blk_put_request(struct request *); 759extern void blk_put_request(struct request *);
753extern void __blk_put_request(struct request_queue *, struct request *); 760extern void __blk_put_request(struct request_queue *, struct request *);
754extern struct request *blk_get_request(struct request_queue *, int, gfp_t); 761extern struct request *blk_get_request(struct request_queue *, int, gfp_t);
762extern struct request *blk_make_request(struct request_queue *, struct bio *,
763 gfp_t);
755extern void blk_insert_request(struct request_queue *, struct request *, int, void *); 764extern void blk_insert_request(struct request_queue *, struct request *, int, void *);
756extern void blk_requeue_request(struct request_queue *, struct request *); 765extern void blk_requeue_request(struct request_queue *, struct request *);
757extern int blk_rq_check_limits(struct request_queue *q, struct request *rq); 766extern int blk_rq_check_limits(struct request_queue *q, struct request *rq);
758extern int blk_lld_busy(struct request_queue *q); 767extern int blk_lld_busy(struct request_queue *q);
768extern int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
769 struct bio_set *bs, gfp_t gfp_mask,
770 int (*bio_ctr)(struct bio *, struct bio *, void *),
771 void *data);
772extern void blk_rq_unprep_clone(struct request *rq);
759extern int blk_insert_cloned_request(struct request_queue *q, 773extern int blk_insert_cloned_request(struct request_queue *q,
760 struct request *rq); 774 struct request *rq);
761extern void blk_plug_device(struct request_queue *); 775extern void blk_plug_device(struct request_queue *);
@@ -768,12 +782,6 @@ extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t,
768 struct scsi_ioctl_command __user *); 782 struct scsi_ioctl_command __user *);
769 783
770/* 784/*
771 * Temporary export, until SCSI gets fixed up.
772 */
773extern int blk_rq_append_bio(struct request_queue *q, struct request *rq,
774 struct bio *bio);
775
776/*
777 * A queue has just exitted congestion. Note this in the global counter of 785 * A queue has just exitted congestion. Note this in the global counter of
778 * congested queues, and wake up anyone who was waiting for requests to be 786 * congested queues, and wake up anyone who was waiting for requests to be
779 * put back. 787 * put back.
@@ -798,7 +806,6 @@ extern void blk_sync_queue(struct request_queue *q);
798extern void __blk_stop_queue(struct request_queue *q); 806extern void __blk_stop_queue(struct request_queue *q);
799extern void __blk_run_queue(struct request_queue *); 807extern void __blk_run_queue(struct request_queue *);
800extern void blk_run_queue(struct request_queue *); 808extern void blk_run_queue(struct request_queue *);
801extern void blk_start_queueing(struct request_queue *);
802extern int blk_rq_map_user(struct request_queue *, struct request *, 809extern int blk_rq_map_user(struct request_queue *, struct request *,
803 struct rq_map_data *, void __user *, unsigned long, 810 struct rq_map_data *, void __user *, unsigned long,
804 gfp_t); 811 gfp_t);
@@ -831,41 +838,73 @@ static inline void blk_run_address_space(struct address_space *mapping)
831 blk_run_backing_dev(mapping->backing_dev_info, NULL); 838 blk_run_backing_dev(mapping->backing_dev_info, NULL);
832} 839}
833 840
834extern void blkdev_dequeue_request(struct request *req); 841/*
842 * blk_rq_pos() : the current sector
843 * blk_rq_bytes() : bytes left in the entire request
844 * blk_rq_cur_bytes() : bytes left in the current segment
845 * blk_rq_sectors() : sectors left in the entire request
846 * blk_rq_cur_sectors() : sectors left in the current segment
847 */
848static inline sector_t blk_rq_pos(const struct request *rq)
849{
850 return rq->__sector;
851}
852
853static inline unsigned int blk_rq_bytes(const struct request *rq)
854{
855 return rq->__data_len;
856}
857
858static inline int blk_rq_cur_bytes(const struct request *rq)
859{
860 return rq->bio ? bio_cur_bytes(rq->bio) : 0;
861}
862
863static inline unsigned int blk_rq_sectors(const struct request *rq)
864{
865 return blk_rq_bytes(rq) >> 9;
866}
867
868static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
869{
870 return blk_rq_cur_bytes(rq) >> 9;
871}
872
873/*
874 * Request issue related functions.
875 */
876extern struct request *blk_peek_request(struct request_queue *q);
877extern void blk_start_request(struct request *rq);
878extern struct request *blk_fetch_request(struct request_queue *q);
835 879
836/* 880/*
837 * blk_end_request() and friends. 881 * Request completion related functions.
838 * __blk_end_request() and end_request() must be called with 882 *
839 * the request queue spinlock acquired. 883 * blk_update_request() completes given number of bytes and updates
884 * the request without completing it.
885 *
886 * blk_end_request() and friends. __blk_end_request() must be called
887 * with the request queue spinlock acquired.
840 * 888 *
841 * Several drivers define their own end_request and call 889 * Several drivers define their own end_request and call
842 * blk_end_request() for parts of the original function. 890 * blk_end_request() for parts of the original function.
843 * This prevents code duplication in drivers. 891 * This prevents code duplication in drivers.
844 */ 892 */
845extern int blk_end_request(struct request *rq, int error, 893extern bool blk_update_request(struct request *rq, int error,
846 unsigned int nr_bytes); 894 unsigned int nr_bytes);
847extern int __blk_end_request(struct request *rq, int error, 895extern bool blk_end_request(struct request *rq, int error,
848 unsigned int nr_bytes); 896 unsigned int nr_bytes);
849extern int blk_end_bidi_request(struct request *rq, int error, 897extern void blk_end_request_all(struct request *rq, int error);
850 unsigned int nr_bytes, unsigned int bidi_bytes); 898extern bool blk_end_request_cur(struct request *rq, int error);
851extern void end_request(struct request *, int); 899extern bool __blk_end_request(struct request *rq, int error,
852extern int blk_end_request_callback(struct request *rq, int error, 900 unsigned int nr_bytes);
853 unsigned int nr_bytes, 901extern void __blk_end_request_all(struct request *rq, int error);
854 int (drv_callback)(struct request *)); 902extern bool __blk_end_request_cur(struct request *rq, int error);
903
855extern void blk_complete_request(struct request *); 904extern void blk_complete_request(struct request *);
856extern void __blk_complete_request(struct request *); 905extern void __blk_complete_request(struct request *);
857extern void blk_abort_request(struct request *); 906extern void blk_abort_request(struct request *);
858extern void blk_abort_queue(struct request_queue *); 907extern void blk_abort_queue(struct request_queue *);
859extern void blk_update_request(struct request *rq, int error,
860 unsigned int nr_bytes);
861
862/*
863 * blk_end_request() takes bytes instead of sectors as a complete size.
864 * blk_rq_bytes() returns bytes left to complete in the entire request.
865 * blk_rq_cur_bytes() returns bytes left to complete in the current segment.
866 */
867extern unsigned int blk_rq_bytes(struct request *rq);
868extern unsigned int blk_rq_cur_bytes(struct request *rq);
869 908
870/* 909/*
871 * Access functions for manipulating queue properties 910 * Access functions for manipulating queue properties
@@ -877,10 +916,20 @@ extern void blk_cleanup_queue(struct request_queue *);
877extern void blk_queue_make_request(struct request_queue *, make_request_fn *); 916extern void blk_queue_make_request(struct request_queue *, make_request_fn *);
878extern void blk_queue_bounce_limit(struct request_queue *, u64); 917extern void blk_queue_bounce_limit(struct request_queue *, u64);
879extern void blk_queue_max_sectors(struct request_queue *, unsigned int); 918extern void blk_queue_max_sectors(struct request_queue *, unsigned int);
919extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int);
880extern void blk_queue_max_phys_segments(struct request_queue *, unsigned short); 920extern void blk_queue_max_phys_segments(struct request_queue *, unsigned short);
881extern void blk_queue_max_hw_segments(struct request_queue *, unsigned short); 921extern void blk_queue_max_hw_segments(struct request_queue *, unsigned short);
882extern void blk_queue_max_segment_size(struct request_queue *, unsigned int); 922extern void blk_queue_max_segment_size(struct request_queue *, unsigned int);
883extern void blk_queue_hardsect_size(struct request_queue *, unsigned short); 923extern void blk_queue_logical_block_size(struct request_queue *, unsigned short);
924extern void blk_queue_physical_block_size(struct request_queue *, unsigned short);
925extern void blk_queue_alignment_offset(struct request_queue *q,
926 unsigned int alignment);
927extern void blk_queue_io_min(struct request_queue *q, unsigned int min);
928extern void blk_queue_io_opt(struct request_queue *q, unsigned int opt);
929extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
930 sector_t offset);
931extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
932 sector_t offset);
884extern void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b); 933extern void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b);
885extern void blk_queue_dma_pad(struct request_queue *, unsigned int); 934extern void blk_queue_dma_pad(struct request_queue *, unsigned int);
886extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int); 935extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int);
@@ -967,19 +1016,87 @@ extern void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter);
967 1016
968#define blkdev_entry_to_request(entry) list_entry((entry), struct request, queuelist) 1017#define blkdev_entry_to_request(entry) list_entry((entry), struct request, queuelist)
969 1018
970static inline int queue_hardsect_size(struct request_queue *q) 1019static inline unsigned long queue_bounce_pfn(struct request_queue *q)
1020{
1021 return q->limits.bounce_pfn;
1022}
1023
1024static inline unsigned long queue_segment_boundary(struct request_queue *q)
1025{
1026 return q->limits.seg_boundary_mask;
1027}
1028
1029static inline unsigned int queue_max_sectors(struct request_queue *q)
1030{
1031 return q->limits.max_sectors;
1032}
1033
1034static inline unsigned int queue_max_hw_sectors(struct request_queue *q)
1035{
1036 return q->limits.max_hw_sectors;
1037}
1038
1039static inline unsigned short queue_max_hw_segments(struct request_queue *q)
1040{
1041 return q->limits.max_hw_segments;
1042}
1043
1044static inline unsigned short queue_max_phys_segments(struct request_queue *q)
1045{
1046 return q->limits.max_phys_segments;
1047}
1048
1049static inline unsigned int queue_max_segment_size(struct request_queue *q)
1050{
1051 return q->limits.max_segment_size;
1052}
1053
1054static inline unsigned short queue_logical_block_size(struct request_queue *q)
971{ 1055{
972 int retval = 512; 1056 int retval = 512;
973 1057
974 if (q && q->hardsect_size) 1058 if (q && q->limits.logical_block_size)
975 retval = q->hardsect_size; 1059 retval = q->limits.logical_block_size;
976 1060
977 return retval; 1061 return retval;
978} 1062}
979 1063
980static inline int bdev_hardsect_size(struct block_device *bdev) 1064static inline unsigned short bdev_logical_block_size(struct block_device *bdev)
1065{
1066 return queue_logical_block_size(bdev_get_queue(bdev));
1067}
1068
1069static inline unsigned int queue_physical_block_size(struct request_queue *q)
1070{
1071 return q->limits.physical_block_size;
1072}
1073
1074static inline unsigned int queue_io_min(struct request_queue *q)
1075{
1076 return q->limits.io_min;
1077}
1078
1079static inline unsigned int queue_io_opt(struct request_queue *q)
1080{
1081 return q->limits.io_opt;
1082}
1083
1084static inline int queue_alignment_offset(struct request_queue *q)
1085{
1086 if (q && q->limits.misaligned)
1087 return -1;
1088
1089 if (q && q->limits.alignment_offset)
1090 return q->limits.alignment_offset;
1091
1092 return 0;
1093}
1094
1095static inline int queue_sector_alignment_offset(struct request_queue *q,
1096 sector_t sector)
981{ 1097{
982 return queue_hardsect_size(bdev_get_queue(bdev)); 1098 return ((sector << 9) - q->limits.alignment_offset)
1099 & (q->limits.io_min - 1);
983} 1100}
984 1101
985static inline int queue_dma_alignment(struct request_queue *q) 1102static inline int queue_dma_alignment(struct request_queue *q)
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 5a40d14daa9f..c56457c8334e 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -288,7 +288,15 @@ static inline cycle_t clocksource_read(struct clocksource *cs)
288 */ 288 */
289static inline int clocksource_enable(struct clocksource *cs) 289static inline int clocksource_enable(struct clocksource *cs)
290{ 290{
291 return cs->enable ? cs->enable(cs) : 0; 291 int ret = 0;
292
293 if (cs->enable)
294 ret = cs->enable(cs);
295
296 /* save mult_orig on enable */
297 cs->mult_orig = cs->mult;
298
299 return ret;
292} 300}
293 301
294/** 302/**
diff --git a/include/linux/cyclades.h b/include/linux/cyclades.h
index 788850ba4e75..1fbdea4f08eb 100644
--- a/include/linux/cyclades.h
+++ b/include/linux/cyclades.h
@@ -142,19 +142,6 @@ struct CYZ_BOOT_CTRL {
142 142
143 143
144#ifndef DP_WINDOW_SIZE 144#ifndef DP_WINDOW_SIZE
145/* #include "cyclomz.h" */
146/****************** ****************** *******************/
147/*
148 * The data types defined below are used in all ZFIRM interface
149 * data structures. They accomodate differences between HW
150 * architectures and compilers.
151 */
152
153typedef __u64 ucdouble; /* 64 bits, unsigned */
154typedef __u32 uclong; /* 32 bits, unsigned */
155typedef __u16 ucshort; /* 16 bits, unsigned */
156typedef __u8 ucchar; /* 8 bits, unsigned */
157
158/* 145/*
159 * Memory Window Sizes 146 * Memory Window Sizes
160 */ 147 */
@@ -507,16 +494,20 @@ struct ZFW_CTRL {
507 494
508/* Per card data structure */ 495/* Per card data structure */
509struct cyclades_card { 496struct cyclades_card {
510 void __iomem *base_addr; 497 void __iomem *base_addr;
511 void __iomem *ctl_addr; 498 union {
512 int irq; 499 void __iomem *p9050;
513 unsigned int num_chips; /* 0 if card absent, -1 if Z/PCI, else Y */ 500 struct RUNTIME_9060 __iomem *p9060;
514 unsigned int first_line; /* minor number of first channel on card */ 501 } ctl_addr;
515 unsigned int nports; /* Number of ports in the card */ 502 int irq;
516 int bus_index; /* address shift - 0 for ISA, 1 for PCI */ 503 unsigned int num_chips; /* 0 if card absent, -1 if Z/PCI, else Y */
517 int intr_enabled; /* FW Interrupt flag - 0 disabled, 1 enabled */ 504 unsigned int first_line; /* minor number of first channel on card */
518 spinlock_t card_lock; 505 unsigned int nports; /* Number of ports in the card */
519 struct cyclades_port *ports; 506 int bus_index; /* address shift - 0 for ISA, 1 for PCI */
507 int intr_enabled; /* FW Interrupt flag - 0 disabled, 1 enabled */
508 u32 hw_ver;
509 spinlock_t card_lock;
510 struct cyclades_port *ports;
520}; 511};
521 512
522/*************************************** 513/***************************************
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index ded2d7c42668..49c2362977fd 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -149,7 +149,7 @@ struct io_restrictions {
149 unsigned max_hw_sectors; 149 unsigned max_hw_sectors;
150 unsigned max_sectors; 150 unsigned max_sectors;
151 unsigned max_segment_size; 151 unsigned max_segment_size;
152 unsigned short hardsect_size; 152 unsigned short logical_block_size;
153 unsigned short max_hw_segments; 153 unsigned short max_hw_segments;
154 unsigned short max_phys_segments; 154 unsigned short max_phys_segments;
155 unsigned char no_cluster; /* inverted so that 0 is default */ 155 unsigned char no_cluster; /* inverted so that 0 is default */
diff --git a/include/linux/elevator.h b/include/linux/elevator.h
index c59b769f62b0..1cb3372e65d8 100644
--- a/include/linux/elevator.h
+++ b/include/linux/elevator.h
@@ -103,10 +103,8 @@ extern int elv_merge(struct request_queue *, struct request **, struct bio *);
103extern void elv_merge_requests(struct request_queue *, struct request *, 103extern void elv_merge_requests(struct request_queue *, struct request *,
104 struct request *); 104 struct request *);
105extern void elv_merged_request(struct request_queue *, struct request *, int); 105extern void elv_merged_request(struct request_queue *, struct request *, int);
106extern void elv_dequeue_request(struct request_queue *, struct request *);
107extern void elv_requeue_request(struct request_queue *, struct request *); 106extern void elv_requeue_request(struct request_queue *, struct request *);
108extern int elv_queue_empty(struct request_queue *); 107extern int elv_queue_empty(struct request_queue *);
109extern struct request *elv_next_request(struct request_queue *q);
110extern struct request *elv_former_request(struct request_queue *, struct request *); 108extern struct request *elv_former_request(struct request_queue *, struct request *);
111extern struct request *elv_latter_request(struct request_queue *, struct request *); 109extern struct request *elv_latter_request(struct request_queue *, struct request *);
112extern int elv_register_queue(struct request_queue *q); 110extern int elv_register_queue(struct request_queue *q);
@@ -171,7 +169,7 @@ enum {
171 ELV_MQUEUE_MUST, 169 ELV_MQUEUE_MUST,
172}; 170};
173 171
174#define rq_end_sector(rq) ((rq)->sector + (rq)->nr_sectors) 172#define rq_end_sector(rq) (blk_rq_pos(rq) + blk_rq_sectors(rq))
175#define rb_entry_rq(node) rb_entry((node), struct request, rb_node) 173#define rb_entry_rq(node) rb_entry((node), struct request, rb_node)
176 174
177/* 175/*
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 3b534e527e09..83d6b4397245 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2205,6 +2205,8 @@ extern int generic_segment_checks(const struct iovec *iov,
2205/* fs/splice.c */ 2205/* fs/splice.c */
2206extern ssize_t generic_file_splice_read(struct file *, loff_t *, 2206extern ssize_t generic_file_splice_read(struct file *, loff_t *,
2207 struct pipe_inode_info *, size_t, unsigned int); 2207 struct pipe_inode_info *, size_t, unsigned int);
2208extern ssize_t default_file_splice_read(struct file *, loff_t *,
2209 struct pipe_inode_info *, size_t, unsigned int);
2208extern ssize_t generic_file_splice_write(struct pipe_inode_info *, 2210extern ssize_t generic_file_splice_write(struct pipe_inode_info *,
2209 struct file *, loff_t *, size_t, unsigned int); 2211 struct file *, loff_t *, size_t, unsigned int);
2210extern ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe, 2212extern ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe,
diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index a1a28caed23d..149fda264c86 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -90,6 +90,7 @@ struct disk_stats {
90struct hd_struct { 90struct hd_struct {
91 sector_t start_sect; 91 sector_t start_sect;
92 sector_t nr_sects; 92 sector_t nr_sects;
93 sector_t alignment_offset;
93 struct device __dev; 94 struct device __dev;
94 struct kobject *holder_dir; 95 struct kobject *holder_dir;
95 int policy, partno; 96 int policy, partno;
diff --git a/include/linux/ide.h b/include/linux/ide.h
index 9fed365a598b..867cb68d8461 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -26,6 +26,9 @@
26#include <asm/io.h> 26#include <asm/io.h>
27#include <asm/mutex.h> 27#include <asm/mutex.h>
28 28
29/* for request_sense */
30#include <linux/cdrom.h>
31
29#if defined(CONFIG_CRIS) || defined(CONFIG_FRV) || defined(CONFIG_MN10300) 32#if defined(CONFIG_CRIS) || defined(CONFIG_FRV) || defined(CONFIG_MN10300)
30# define SUPPORT_VLB_SYNC 0 33# define SUPPORT_VLB_SYNC 0
31#else 34#else
@@ -324,7 +327,6 @@ struct ide_cmd {
324 unsigned int cursg_ofs; 327 unsigned int cursg_ofs;
325 328
326 struct request *rq; /* copy of request */ 329 struct request *rq; /* copy of request */
327 void *special; /* valid_t generally */
328}; 330};
329 331
330/* ATAPI packet command flags */ 332/* ATAPI packet command flags */
@@ -360,11 +362,7 @@ struct ide_atapi_pc {
360 362
361 /* data buffer */ 363 /* data buffer */
362 u8 *buf; 364 u8 *buf;
363 /* current buffer position */
364 u8 *cur_pos;
365 int buf_size; 365 int buf_size;
366 /* missing/available data on the current buffer */
367 int b_count;
368 366
369 /* the corresponding request */ 367 /* the corresponding request */
370 struct request *rq; 368 struct request *rq;
@@ -377,10 +375,6 @@ struct ide_atapi_pc {
377 */ 375 */
378 u8 pc_buf[IDE_PC_BUFFER_SIZE]; 376 u8 pc_buf[IDE_PC_BUFFER_SIZE];
379 377
380 /* idetape only */
381 struct idetape_bh *bh;
382 char *b_data;
383
384 unsigned long timeout; 378 unsigned long timeout;
385}; 379};
386 380
@@ -593,16 +587,16 @@ struct ide_drive_s {
593 /* callback for packet commands */ 587 /* callback for packet commands */
594 int (*pc_callback)(struct ide_drive_s *, int); 588 int (*pc_callback)(struct ide_drive_s *, int);
595 589
596 void (*pc_update_buffers)(struct ide_drive_s *, struct ide_atapi_pc *);
597 int (*pc_io_buffers)(struct ide_drive_s *, struct ide_atapi_pc *,
598 unsigned int, int);
599
600 ide_startstop_t (*irq_handler)(struct ide_drive_s *); 590 ide_startstop_t (*irq_handler)(struct ide_drive_s *);
601 591
602 unsigned long atapi_flags; 592 unsigned long atapi_flags;
603 593
604 struct ide_atapi_pc request_sense_pc; 594 struct ide_atapi_pc request_sense_pc;
605 struct request request_sense_rq; 595
596 /* current sense rq and buffer */
597 bool sense_rq_armed;
598 struct request sense_rq;
599 struct request_sense sense_data;
606}; 600};
607 601
608typedef struct ide_drive_s ide_drive_t; 602typedef struct ide_drive_s ide_drive_t;
@@ -1174,7 +1168,10 @@ int ide_do_test_unit_ready(ide_drive_t *, struct gendisk *);
1174int ide_do_start_stop(ide_drive_t *, struct gendisk *, int); 1168int ide_do_start_stop(ide_drive_t *, struct gendisk *, int);
1175int ide_set_media_lock(ide_drive_t *, struct gendisk *, int); 1169int ide_set_media_lock(ide_drive_t *, struct gendisk *, int);
1176void ide_create_request_sense_cmd(ide_drive_t *, struct ide_atapi_pc *); 1170void ide_create_request_sense_cmd(ide_drive_t *, struct ide_atapi_pc *);
1177void ide_retry_pc(ide_drive_t *, struct gendisk *); 1171void ide_retry_pc(ide_drive_t *drive);
1172
1173void ide_prep_sense(ide_drive_t *drive, struct request *rq);
1174int ide_queue_sense_rq(ide_drive_t *drive, void *special);
1178 1175
1179int ide_cd_expiry(ide_drive_t *); 1176int ide_cd_expiry(ide_drive_t *);
1180 1177
diff --git a/include/linux/ima.h b/include/linux/ima.h
index 0e2aa45cb0ce..b1b827d091a9 100644
--- a/include/linux/ima.h
+++ b/include/linux/ima.h
@@ -13,14 +13,17 @@
13#include <linux/fs.h> 13#include <linux/fs.h>
14struct linux_binprm; 14struct linux_binprm;
15 15
16#define IMA_COUNT_UPDATE 1
17#define IMA_COUNT_LEAVE 0
18
16#ifdef CONFIG_IMA 19#ifdef CONFIG_IMA
17extern int ima_bprm_check(struct linux_binprm *bprm); 20extern int ima_bprm_check(struct linux_binprm *bprm);
18extern int ima_inode_alloc(struct inode *inode); 21extern int ima_inode_alloc(struct inode *inode);
19extern void ima_inode_free(struct inode *inode); 22extern void ima_inode_free(struct inode *inode);
20extern int ima_path_check(struct path *path, int mask); 23extern int ima_path_check(struct path *path, int mask, int update_counts);
21extern void ima_file_free(struct file *file); 24extern void ima_file_free(struct file *file);
22extern int ima_file_mmap(struct file *file, unsigned long prot); 25extern int ima_file_mmap(struct file *file, unsigned long prot);
23extern void ima_shm_check(struct file *file); 26extern void ima_counts_get(struct file *file);
24 27
25#else 28#else
26static inline int ima_bprm_check(struct linux_binprm *bprm) 29static inline int ima_bprm_check(struct linux_binprm *bprm)
@@ -38,7 +41,7 @@ static inline void ima_inode_free(struct inode *inode)
38 return; 41 return;
39} 42}
40 43
41static inline int ima_path_check(struct path *path, int mask) 44static inline int ima_path_check(struct path *path, int mask, int update_counts)
42{ 45{
43 return 0; 46 return 0;
44} 47}
@@ -53,7 +56,7 @@ static inline int ima_file_mmap(struct file *file, unsigned long prot)
53 return 0; 56 return 0;
54} 57}
55 58
56static inline void ima_shm_check(struct file *file) 59static inline void ima_counts_get(struct file *file)
57{ 60{
58 return; 61 return;
59} 62}
diff --git a/include/linux/init_task.h b/include/linux/init_task.h
index 889bf99eca6d..6646bfc7b892 100644
--- a/include/linux/init_task.h
+++ b/include/linux/init_task.h
@@ -145,8 +145,8 @@ extern struct cred init_cred;
145 .group_leader = &tsk, \ 145 .group_leader = &tsk, \
146 .real_cred = &init_cred, \ 146 .real_cred = &init_cred, \
147 .cred = &init_cred, \ 147 .cred = &init_cred, \
148 .cred_exec_mutex = \ 148 .cred_guard_mutex = \
149 __MUTEX_INITIALIZER(tsk.cred_exec_mutex), \ 149 __MUTEX_INITIALIZER(tsk.cred_guard_mutex), \
150 .comm = "swapper", \ 150 .comm = "swapper", \
151 .thread = INIT_THREAD, \ 151 .thread = INIT_THREAD, \
152 .fs = &init_fs, \ 152 .fs = &init_fs, \
diff --git a/include/linux/iocontext.h b/include/linux/iocontext.h
index 08b987bccf89..dd05434fa45f 100644
--- a/include/linux/iocontext.h
+++ b/include/linux/iocontext.h
@@ -64,7 +64,7 @@ struct cfq_io_context {
64 * and kmalloc'ed. These could be shared between processes. 64 * and kmalloc'ed. These could be shared between processes.
65 */ 65 */
66struct io_context { 66struct io_context {
67 atomic_t refcount; 67 atomic_long_t refcount;
68 atomic_t nr_tasks; 68 atomic_t nr_tasks;
69 69
70 /* all the fields below are protected by this lock */ 70 /* all the fields below are protected by this lock */
@@ -91,8 +91,8 @@ static inline struct io_context *ioc_task_link(struct io_context *ioc)
91 * if ref count is zero, don't allow sharing (ioc is going away, it's 91 * if ref count is zero, don't allow sharing (ioc is going away, it's
92 * a race). 92 * a race).
93 */ 93 */
94 if (ioc && atomic_inc_not_zero(&ioc->refcount)) { 94 if (ioc && atomic_long_inc_not_zero(&ioc->refcount)) {
95 atomic_inc(&ioc->nr_tasks); 95 atomic_long_inc(&ioc->refcount);
96 return ioc; 96 return ioc;
97 } 97 }
98 98
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 8cc137911b34..3db5d8d37485 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -119,7 +119,7 @@ struct kvm_run {
119 __u32 error_code; 119 __u32 error_code;
120 } ex; 120 } ex;
121 /* KVM_EXIT_IO */ 121 /* KVM_EXIT_IO */
122 struct kvm_io { 122 struct {
123#define KVM_EXIT_IO_IN 0 123#define KVM_EXIT_IO_IN 0
124#define KVM_EXIT_IO_OUT 1 124#define KVM_EXIT_IO_OUT 1
125 __u8 direction; 125 __u8 direction;
@@ -224,10 +224,10 @@ struct kvm_interrupt {
224/* for KVM_GET_DIRTY_LOG */ 224/* for KVM_GET_DIRTY_LOG */
225struct kvm_dirty_log { 225struct kvm_dirty_log {
226 __u32 slot; 226 __u32 slot;
227 __u32 padding; 227 __u32 padding1;
228 union { 228 union {
229 void __user *dirty_bitmap; /* one bit per page */ 229 void __user *dirty_bitmap; /* one bit per page */
230 __u64 padding; 230 __u64 padding2;
231 }; 231 };
232}; 232};
233 233
@@ -409,6 +409,10 @@ struct kvm_trace_rec {
409#ifdef __KVM_HAVE_DEVICE_ASSIGNMENT 409#ifdef __KVM_HAVE_DEVICE_ASSIGNMENT
410#define KVM_CAP_DEVICE_DEASSIGNMENT 27 410#define KVM_CAP_DEVICE_DEASSIGNMENT 27
411#endif 411#endif
412#ifdef __KVM_HAVE_MSIX
413#define KVM_CAP_DEVICE_MSIX 28
414#endif
415#define KVM_CAP_ASSIGN_DEV_IRQ 29
412/* Another bug in KVM_SET_USER_MEMORY_REGION fixed: */ 416/* Another bug in KVM_SET_USER_MEMORY_REGION fixed: */
413#define KVM_CAP_JOIN_MEMORY_REGIONS_WORKS 30 417#define KVM_CAP_JOIN_MEMORY_REGIONS_WORKS 30
414 418
@@ -482,11 +486,18 @@ struct kvm_irq_routing {
482#define KVM_ASSIGN_PCI_DEVICE _IOR(KVMIO, 0x69, \ 486#define KVM_ASSIGN_PCI_DEVICE _IOR(KVMIO, 0x69, \
483 struct kvm_assigned_pci_dev) 487 struct kvm_assigned_pci_dev)
484#define KVM_SET_GSI_ROUTING _IOW(KVMIO, 0x6a, struct kvm_irq_routing) 488#define KVM_SET_GSI_ROUTING _IOW(KVMIO, 0x6a, struct kvm_irq_routing)
489/* deprecated, replaced by KVM_ASSIGN_DEV_IRQ */
485#define KVM_ASSIGN_IRQ _IOR(KVMIO, 0x70, \ 490#define KVM_ASSIGN_IRQ _IOR(KVMIO, 0x70, \
486 struct kvm_assigned_irq) 491 struct kvm_assigned_irq)
492#define KVM_ASSIGN_DEV_IRQ _IOW(KVMIO, 0x70, struct kvm_assigned_irq)
487#define KVM_REINJECT_CONTROL _IO(KVMIO, 0x71) 493#define KVM_REINJECT_CONTROL _IO(KVMIO, 0x71)
488#define KVM_DEASSIGN_PCI_DEVICE _IOW(KVMIO, 0x72, \ 494#define KVM_DEASSIGN_PCI_DEVICE _IOW(KVMIO, 0x72, \
489 struct kvm_assigned_pci_dev) 495 struct kvm_assigned_pci_dev)
496#define KVM_ASSIGN_SET_MSIX_NR \
497 _IOW(KVMIO, 0x73, struct kvm_assigned_msix_nr)
498#define KVM_ASSIGN_SET_MSIX_ENTRY \
499 _IOW(KVMIO, 0x74, struct kvm_assigned_msix_entry)
500#define KVM_DEASSIGN_DEV_IRQ _IOW(KVMIO, 0x75, struct kvm_assigned_irq)
490 501
491/* 502/*
492 * ioctls for vcpu fds 503 * ioctls for vcpu fds
@@ -577,6 +588,8 @@ struct kvm_debug_guest {
577#define KVM_TRC_STLB_INVAL (KVM_TRC_HANDLER + 0x18) 588#define KVM_TRC_STLB_INVAL (KVM_TRC_HANDLER + 0x18)
578#define KVM_TRC_PPC_INSTR (KVM_TRC_HANDLER + 0x19) 589#define KVM_TRC_PPC_INSTR (KVM_TRC_HANDLER + 0x19)
579 590
591#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
592
580struct kvm_assigned_pci_dev { 593struct kvm_assigned_pci_dev {
581 __u32 assigned_dev_id; 594 __u32 assigned_dev_id;
582 __u32 busnr; 595 __u32 busnr;
@@ -587,6 +600,17 @@ struct kvm_assigned_pci_dev {
587 }; 600 };
588}; 601};
589 602
603#define KVM_DEV_IRQ_HOST_INTX (1 << 0)
604#define KVM_DEV_IRQ_HOST_MSI (1 << 1)
605#define KVM_DEV_IRQ_HOST_MSIX (1 << 2)
606
607#define KVM_DEV_IRQ_GUEST_INTX (1 << 8)
608#define KVM_DEV_IRQ_GUEST_MSI (1 << 9)
609#define KVM_DEV_IRQ_GUEST_MSIX (1 << 10)
610
611#define KVM_DEV_IRQ_HOST_MASK 0x00ff
612#define KVM_DEV_IRQ_GUEST_MASK 0xff00
613
590struct kvm_assigned_irq { 614struct kvm_assigned_irq {
591 __u32 assigned_dev_id; 615 __u32 assigned_dev_id;
592 __u32 host_irq; 616 __u32 host_irq;
@@ -602,9 +626,19 @@ struct kvm_assigned_irq {
602 }; 626 };
603}; 627};
604 628
605#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
606 629
607#define KVM_DEV_IRQ_ASSIGN_MSI_ACTION KVM_DEV_IRQ_ASSIGN_ENABLE_MSI 630struct kvm_assigned_msix_nr {
608#define KVM_DEV_IRQ_ASSIGN_ENABLE_MSI (1 << 0) 631 __u32 assigned_dev_id;
632 __u16 entry_nr;
633 __u16 padding;
634};
635
636#define KVM_MAX_MSIX_PER_DEV 512
637struct kvm_assigned_msix_entry {
638 __u32 assigned_dev_id;
639 __u32 gsi;
640 __u16 entry; /* The index of entry in the MSI-X table */
641 __u16 padding[3];
642};
609 643
610#endif 644#endif
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index 894a56e365e8..aacc5449f586 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -38,6 +38,7 @@
38#define KVM_REQ_UNHALT 6 38#define KVM_REQ_UNHALT 6
39#define KVM_REQ_MMU_SYNC 7 39#define KVM_REQ_MMU_SYNC 7
40#define KVM_REQ_KVMCLOCK_UPDATE 8 40#define KVM_REQ_KVMCLOCK_UPDATE 8
41#define KVM_REQ_KICK 9
41 42
42#define KVM_USERSPACE_IRQ_SOURCE_ID 0 43#define KVM_USERSPACE_IRQ_SOURCE_ID 0
43 44
@@ -72,7 +73,6 @@ struct kvm_vcpu {
72 struct mutex mutex; 73 struct mutex mutex;
73 int cpu; 74 int cpu;
74 struct kvm_run *run; 75 struct kvm_run *run;
75 int guest_mode;
76 unsigned long requests; 76 unsigned long requests;
77 unsigned long guest_debug; 77 unsigned long guest_debug;
78 int fpu_active; 78 int fpu_active;
@@ -298,6 +298,7 @@ int kvm_arch_hardware_setup(void);
298void kvm_arch_hardware_unsetup(void); 298void kvm_arch_hardware_unsetup(void);
299void kvm_arch_check_processor_compat(void *rtn); 299void kvm_arch_check_processor_compat(void *rtn);
300int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu); 300int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu);
301int kvm_arch_interrupt_allowed(struct kvm_vcpu *vcpu);
301 302
302void kvm_free_physmem(struct kvm *kvm); 303void kvm_free_physmem(struct kvm *kvm);
303 304
@@ -319,6 +320,13 @@ struct kvm_irq_ack_notifier {
319 void (*irq_acked)(struct kvm_irq_ack_notifier *kian); 320 void (*irq_acked)(struct kvm_irq_ack_notifier *kian);
320}; 321};
321 322
323#define KVM_ASSIGNED_MSIX_PENDING 0x1
324struct kvm_guest_msix_entry {
325 u32 vector;
326 u16 entry;
327 u16 flags;
328};
329
322struct kvm_assigned_dev_kernel { 330struct kvm_assigned_dev_kernel {
323 struct kvm_irq_ack_notifier ack_notifier; 331 struct kvm_irq_ack_notifier ack_notifier;
324 struct work_struct interrupt_work; 332 struct work_struct interrupt_work;
@@ -326,18 +334,18 @@ struct kvm_assigned_dev_kernel {
326 int assigned_dev_id; 334 int assigned_dev_id;
327 int host_busnr; 335 int host_busnr;
328 int host_devfn; 336 int host_devfn;
337 unsigned int entries_nr;
329 int host_irq; 338 int host_irq;
330 bool host_irq_disabled; 339 bool host_irq_disabled;
340 struct msix_entry *host_msix_entries;
331 int guest_irq; 341 int guest_irq;
332#define KVM_ASSIGNED_DEV_GUEST_INTX (1 << 0) 342 struct kvm_guest_msix_entry *guest_msix_entries;
333#define KVM_ASSIGNED_DEV_GUEST_MSI (1 << 1)
334#define KVM_ASSIGNED_DEV_HOST_INTX (1 << 8)
335#define KVM_ASSIGNED_DEV_HOST_MSI (1 << 9)
336 unsigned long irq_requested_type; 343 unsigned long irq_requested_type;
337 int irq_source_id; 344 int irq_source_id;
338 int flags; 345 int flags;
339 struct pci_dev *dev; 346 struct pci_dev *dev;
340 struct kvm *kvm; 347 struct kvm *kvm;
348 spinlock_t assigned_dev_lock;
341}; 349};
342 350
343struct kvm_irq_mask_notifier { 351struct kvm_irq_mask_notifier {
@@ -360,6 +368,9 @@ void kvm_unregister_irq_ack_notifier(struct kvm_irq_ack_notifier *kian);
360int kvm_request_irq_source_id(struct kvm *kvm); 368int kvm_request_irq_source_id(struct kvm *kvm);
361void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id); 369void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
362 370
371/* For vcpu->arch.iommu_flags */
372#define KVM_IOMMU_CACHE_COHERENCY 0x1
373
363#ifdef CONFIG_IOMMU_API 374#ifdef CONFIG_IOMMU_API
364int kvm_iommu_map_pages(struct kvm *kvm, gfn_t base_gfn, 375int kvm_iommu_map_pages(struct kvm *kvm, gfn_t base_gfn,
365 unsigned long npages); 376 unsigned long npages);
diff --git a/include/linux/kvm_types.h b/include/linux/kvm_types.h
index 2b8318c83e53..fb46efbeabec 100644
--- a/include/linux/kvm_types.h
+++ b/include/linux/kvm_types.h
@@ -40,4 +40,31 @@ typedef unsigned long hfn_t;
40 40
41typedef hfn_t pfn_t; 41typedef hfn_t pfn_t;
42 42
43union kvm_ioapic_redirect_entry {
44 u64 bits;
45 struct {
46 u8 vector;
47 u8 delivery_mode:3;
48 u8 dest_mode:1;
49 u8 delivery_status:1;
50 u8 polarity:1;
51 u8 remote_irr:1;
52 u8 trig_mode:1;
53 u8 mask:1;
54 u8 reserve:7;
55 u8 reserved[4];
56 u8 dest_id;
57 } fields;
58};
59
60struct kvm_lapic_irq {
61 u32 vector;
62 u32 delivery_mode;
63 u32 dest_mode;
64 u32 level;
65 u32 trig_mode;
66 u32 shorthand;
67 u32 dest_id;
68};
69
43#endif /* __KVM_TYPES_H__ */ 70#endif /* __KVM_TYPES_H__ */
diff --git a/include/linux/loop.h b/include/linux/loop.h
index 40725447f5e0..66c194e2d9b9 100644
--- a/include/linux/loop.h
+++ b/include/linux/loop.h
@@ -56,8 +56,7 @@ struct loop_device {
56 gfp_t old_gfp_mask; 56 gfp_t old_gfp_mask;
57 57
58 spinlock_t lo_lock; 58 spinlock_t lo_lock;
59 struct bio *lo_bio; 59 struct bio_list lo_bio_list;
60 struct bio *lo_biotail;
61 int lo_state; 60 int lo_state;
62 struct mutex lo_ctl_mutex; 61 struct mutex lo_ctl_mutex;
63 struct task_struct *lo_thread; 62 struct task_struct *lo_thread;
diff --git a/include/linux/lsm_audit.h b/include/linux/lsm_audit.h
new file mode 100644
index 000000000000..e461b2c3d711
--- /dev/null
+++ b/include/linux/lsm_audit.h
@@ -0,0 +1,111 @@
1/*
2 * Common LSM logging functions
3 * Heavily borrowed from selinux/avc.h
4 *
5 * Author : Etienne BASSET <etienne.basset@ensta.org>
6 *
7 * All credits to : Stephen Smalley, <sds@epoch.ncsc.mil>
8 * All BUGS to : Etienne BASSET <etienne.basset@ensta.org>
9 */
10#ifndef _LSM_COMMON_LOGGING_
11#define _LSM_COMMON_LOGGING_
12
13#include <linux/stddef.h>
14#include <linux/errno.h>
15#include <linux/kernel.h>
16#include <linux/kdev_t.h>
17#include <linux/spinlock.h>
18#include <linux/init.h>
19#include <linux/audit.h>
20#include <linux/in6.h>
21#include <linux/path.h>
22#include <linux/key.h>
23#include <linux/skbuff.h>
24#include <asm/system.h>
25
26
27/* Auxiliary data to use in generating the audit record. */
28struct common_audit_data {
29 char type;
30#define LSM_AUDIT_DATA_FS 1
31#define LSM_AUDIT_DATA_NET 2
32#define LSM_AUDIT_DATA_CAP 3
33#define LSM_AUDIT_DATA_IPC 4
34#define LSM_AUDIT_DATA_TASK 5
35#define LSM_AUDIT_DATA_KEY 6
36 struct task_struct *tsk;
37 union {
38 struct {
39 struct path path;
40 struct inode *inode;
41 } fs;
42 struct {
43 int netif;
44 struct sock *sk;
45 u16 family;
46 __be16 dport;
47 __be16 sport;
48 union {
49 struct {
50 __be32 daddr;
51 __be32 saddr;
52 } v4;
53 struct {
54 struct in6_addr daddr;
55 struct in6_addr saddr;
56 } v6;
57 } fam;
58 } net;
59 int cap;
60 int ipc_id;
61 struct task_struct *tsk;
62#ifdef CONFIG_KEYS
63 struct {
64 key_serial_t key;
65 char *key_desc;
66 } key_struct;
67#endif
68 } u;
69 const char *function;
70 /* this union contains LSM specific data */
71 union {
72 /* SMACK data */
73 struct smack_audit_data {
74 char *subject;
75 char *object;
76 char *request;
77 int result;
78 } smack_audit_data;
79 /* SELinux data */
80 struct {
81 u32 ssid;
82 u32 tsid;
83 u16 tclass;
84 u32 requested;
85 u32 audited;
86 struct av_decision *avd;
87 int result;
88 } selinux_audit_data;
89 } lsm_priv;
90 /* these callback will be implemented by a specific LSM */
91 void (*lsm_pre_audit)(struct audit_buffer *, void *);
92 void (*lsm_post_audit)(struct audit_buffer *, void *);
93};
94
95#define v4info fam.v4
96#define v6info fam.v6
97
98int ipv4_skb_to_auditdata(struct sk_buff *skb,
99 struct common_audit_data *ad, u8 *proto);
100
101int ipv6_skb_to_auditdata(struct sk_buff *skb,
102 struct common_audit_data *ad, u8 *proto);
103
104/* Initialize an LSM audit data structure. */
105#define COMMON_AUDIT_DATA_INIT(_d, _t) \
106 { memset((_d), 0, sizeof(struct common_audit_data)); \
107 (_d)->type = LSM_AUDIT_DATA_##_t; (_d)->function = __func__; }
108
109void common_lsm_audit(struct common_audit_data *a);
110
111#endif
diff --git a/include/linux/magic.h b/include/linux/magic.h
index 5b4e28bcb788..927138cf3050 100644
--- a/include/linux/magic.h
+++ b/include/linux/magic.h
@@ -9,6 +9,7 @@
9#define DEBUGFS_MAGIC 0x64626720 9#define DEBUGFS_MAGIC 0x64626720
10#define SYSFS_MAGIC 0x62656572 10#define SYSFS_MAGIC 0x62656572
11#define SECURITYFS_MAGIC 0x73636673 11#define SECURITYFS_MAGIC 0x73636673
12#define SELINUX_MAGIC 0xf97cff8c
12#define TMPFS_MAGIC 0x01021994 13#define TMPFS_MAGIC 0x01021994
13#define SQUASHFS_MAGIC 0x73717368 14#define SQUASHFS_MAGIC 0x73717368
14#define EFS_SUPER_MAGIC 0x414A53 15#define EFS_SUPER_MAGIC 0x414A53
diff --git a/include/linux/mg_disk.h b/include/linux/mg_disk.h
deleted file mode 100644
index 1f76b1ebf627..000000000000
--- a/include/linux/mg_disk.h
+++ /dev/null
@@ -1,206 +0,0 @@
1/*
2 * include/linux/mg_disk.c
3 *
4 * Support for the mGine m[g]flash IO mode.
5 * Based on legacy hd.c
6 *
7 * (c) 2008 mGine Co.,LTD
8 * (c) 2008 unsik Kim <donari75@gmail.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#ifndef __MG_DISK_H__
16#define __MG_DISK_H__
17
18#include <linux/blkdev.h>
19#include <linux/ata.h>
20
21/* name for block device */
22#define MG_DISK_NAME "mgd"
23/* name for platform device */
24#define MG_DEV_NAME "mg_disk"
25
26#define MG_DISK_MAJ 0
27#define MG_DISK_MAX_PART 16
28#define MG_SECTOR_SIZE 512
29#define MG_MAX_SECTS 256
30
31/* Register offsets */
32#define MG_BUFF_OFFSET 0x8000
33#define MG_STORAGE_BUFFER_SIZE 0x200
34#define MG_REG_OFFSET 0xC000
35#define MG_REG_FEATURE (MG_REG_OFFSET + 2) /* write case */
36#define MG_REG_ERROR (MG_REG_OFFSET + 2) /* read case */
37#define MG_REG_SECT_CNT (MG_REG_OFFSET + 4)
38#define MG_REG_SECT_NUM (MG_REG_OFFSET + 6)
39#define MG_REG_CYL_LOW (MG_REG_OFFSET + 8)
40#define MG_REG_CYL_HIGH (MG_REG_OFFSET + 0xA)
41#define MG_REG_DRV_HEAD (MG_REG_OFFSET + 0xC)
42#define MG_REG_COMMAND (MG_REG_OFFSET + 0xE) /* write case */
43#define MG_REG_STATUS (MG_REG_OFFSET + 0xE) /* read case */
44#define MG_REG_DRV_CTRL (MG_REG_OFFSET + 0x10)
45#define MG_REG_BURST_CTRL (MG_REG_OFFSET + 0x12)
46
47/* "Drive Select/Head Register" bit values */
48#define MG_REG_HEAD_MUST_BE_ON 0xA0 /* These 2 bits are always on */
49#define MG_REG_HEAD_DRIVE_MASTER (0x00 | MG_REG_HEAD_MUST_BE_ON)
50#define MG_REG_HEAD_DRIVE_SLAVE (0x10 | MG_REG_HEAD_MUST_BE_ON)
51#define MG_REG_HEAD_LBA_MODE (0x40 | MG_REG_HEAD_MUST_BE_ON)
52
53
54/* "Device Control Register" bit values */
55#define MG_REG_CTRL_INTR_ENABLE 0x0
56#define MG_REG_CTRL_INTR_DISABLE (0x1<<1)
57#define MG_REG_CTRL_RESET (0x1<<2)
58#define MG_REG_CTRL_INTR_POLA_ACTIVE_HIGH 0x0
59#define MG_REG_CTRL_INTR_POLA_ACTIVE_LOW (0x1<<4)
60#define MG_REG_CTRL_DPD_POLA_ACTIVE_LOW 0x0
61#define MG_REG_CTRL_DPD_POLA_ACTIVE_HIGH (0x1<<5)
62#define MG_REG_CTRL_DPD_DISABLE 0x0
63#define MG_REG_CTRL_DPD_ENABLE (0x1<<6)
64
65/* Status register bit */
66/* error bit in status register */
67#define MG_REG_STATUS_BIT_ERROR 0x01
68/* corrected error in status register */
69#define MG_REG_STATUS_BIT_CORRECTED_ERROR 0x04
70/* data request bit in status register */
71#define MG_REG_STATUS_BIT_DATA_REQ 0x08
72/* DSC - Drive Seek Complete */
73#define MG_REG_STATUS_BIT_SEEK_DONE 0x10
74/* DWF - Drive Write Fault */
75#define MG_REG_STATUS_BIT_WRITE_FAULT 0x20
76#define MG_REG_STATUS_BIT_READY 0x40
77#define MG_REG_STATUS_BIT_BUSY 0x80
78
79/* handy status */
80#define MG_STAT_READY (MG_REG_STATUS_BIT_READY | MG_REG_STATUS_BIT_SEEK_DONE)
81#define MG_READY_OK(s) (((s) & (MG_STAT_READY | \
82 (MG_REG_STATUS_BIT_BUSY | \
83 MG_REG_STATUS_BIT_WRITE_FAULT | \
84 MG_REG_STATUS_BIT_ERROR))) == MG_STAT_READY)
85
86/* Error register */
87#define MG_REG_ERR_AMNF 0x01
88#define MG_REG_ERR_ABRT 0x04
89#define MG_REG_ERR_IDNF 0x10
90#define MG_REG_ERR_UNC 0x40
91#define MG_REG_ERR_BBK 0x80
92
93/* error code for others */
94#define MG_ERR_NONE 0
95#define MG_ERR_TIMEOUT 0x100
96#define MG_ERR_INIT_STAT 0x101
97#define MG_ERR_TRANSLATION 0x102
98#define MG_ERR_CTRL_RST 0x103
99#define MG_ERR_INV_STAT 0x104
100#define MG_ERR_RSTOUT 0x105
101
102#define MG_MAX_ERRORS 6 /* Max read/write errors */
103
104/* command */
105#define MG_CMD_RD 0x20
106#define MG_CMD_WR 0x30
107#define MG_CMD_SLEEP 0x99
108#define MG_CMD_WAKEUP 0xC3
109#define MG_CMD_ID 0xEC
110#define MG_CMD_WR_CONF 0x3C
111#define MG_CMD_RD_CONF 0x40
112
113/* operation mode */
114#define MG_OP_CASCADE (1 << 0)
115#define MG_OP_CASCADE_SYNC_RD (1 << 1)
116#define MG_OP_CASCADE_SYNC_WR (1 << 2)
117#define MG_OP_INTERLEAVE (1 << 3)
118
119/* synchronous */
120#define MG_BURST_LAT_4 (3 << 4)
121#define MG_BURST_LAT_5 (4 << 4)
122#define MG_BURST_LAT_6 (5 << 4)
123#define MG_BURST_LAT_7 (6 << 4)
124#define MG_BURST_LAT_8 (7 << 4)
125#define MG_BURST_LEN_4 (1 << 1)
126#define MG_BURST_LEN_8 (2 << 1)
127#define MG_BURST_LEN_16 (3 << 1)
128#define MG_BURST_LEN_32 (4 << 1)
129#define MG_BURST_LEN_CONT (0 << 1)
130
131/* timeout value (unit: ms) */
132#define MG_TMAX_CONF_TO_CMD 1
133#define MG_TMAX_WAIT_RD_DRQ 10
134#define MG_TMAX_WAIT_WR_DRQ 500
135#define MG_TMAX_RST_TO_BUSY 10
136#define MG_TMAX_HDRST_TO_RDY 500
137#define MG_TMAX_SWRST_TO_RDY 500
138#define MG_TMAX_RSTOUT 3000
139
140/* device attribution */
141/* use mflash as boot device */
142#define MG_BOOT_DEV (1 << 0)
143/* use mflash as storage device */
144#define MG_STORAGE_DEV (1 << 1)
145/* same as MG_STORAGE_DEV, but bootloader already done reset sequence */
146#define MG_STORAGE_DEV_SKIP_RST (1 << 2)
147
148#define MG_DEV_MASK (MG_BOOT_DEV | MG_STORAGE_DEV | MG_STORAGE_DEV_SKIP_RST)
149
150/* names of GPIO resource */
151#define MG_RST_PIN "mg_rst"
152/* except MG_BOOT_DEV, reset-out pin should be assigned */
153#define MG_RSTOUT_PIN "mg_rstout"
154
155/* private driver data */
156struct mg_drv_data {
157 /* disk resource */
158 u32 use_polling;
159
160 /* device attribution */
161 u32 dev_attr;
162
163 /* internally used */
164 struct mg_host *host;
165};
166
167/* main structure for mflash driver */
168struct mg_host {
169 struct device *dev;
170
171 struct request_queue *breq;
172 spinlock_t lock;
173 struct gendisk *gd;
174
175 struct timer_list timer;
176 void (*mg_do_intr) (struct mg_host *);
177
178 u16 id[ATA_ID_WORDS];
179
180 u16 cyls;
181 u16 heads;
182 u16 sectors;
183 u32 n_sectors;
184 u32 nres_sectors;
185
186 void __iomem *dev_base;
187 unsigned int irq;
188 unsigned int rst;
189 unsigned int rstout;
190
191 u32 major;
192 u32 error;
193};
194
195/*
196 * Debugging macro and defines
197 */
198#undef DO_MG_DEBUG
199#ifdef DO_MG_DEBUG
200# define MG_DBG(fmt, args...) \
201 printk(KERN_DEBUG "%s:%d "fmt, __func__, __LINE__, ##args)
202#else /* CONFIG_MG_DEBUG */
203# define MG_DBG(fmt, args...) do { } while (0)
204#endif /* CONFIG_MG_DEBUG */
205
206#endif
diff --git a/include/linux/mm.h b/include/linux/mm.h
index 9772d6cbfc82..ad613ed66ab0 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -581,12 +581,10 @@ static inline void set_page_links(struct page *page, enum zone_type zone,
581 */ 581 */
582static inline unsigned long round_hint_to_min(unsigned long hint) 582static inline unsigned long round_hint_to_min(unsigned long hint)
583{ 583{
584#ifdef CONFIG_SECURITY
585 hint &= PAGE_MASK; 584 hint &= PAGE_MASK;
586 if (((void *)hint != NULL) && 585 if (((void *)hint != NULL) &&
587 (hint < mmap_min_addr)) 586 (hint < mmap_min_addr))
588 return PAGE_ALIGN(mmap_min_addr); 587 return PAGE_ALIGN(mmap_min_addr);
589#endif
590 return hint; 588 return hint;
591} 589}
592 590
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index 0f71812d67d3..d7d1c41a0b17 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -1996,10 +1996,12 @@
1996#define PCI_DEVICE_ID_OXSEMI_PCIe952_1_U 0xC118 1996#define PCI_DEVICE_ID_OXSEMI_PCIe952_1_U 0xC118
1997#define PCI_DEVICE_ID_OXSEMI_PCIe952_1_GU 0xC11C 1997#define PCI_DEVICE_ID_OXSEMI_PCIe952_1_GU 0xC11C
1998#define PCI_DEVICE_ID_OXSEMI_16PCI954 0x9501 1998#define PCI_DEVICE_ID_OXSEMI_16PCI954 0x9501
1999#define PCI_DEVICE_ID_OXSEMI_C950 0x950B
1999#define PCI_DEVICE_ID_OXSEMI_16PCI95N 0x9511 2000#define PCI_DEVICE_ID_OXSEMI_16PCI95N 0x9511
2000#define PCI_DEVICE_ID_OXSEMI_16PCI954PP 0x9513 2001#define PCI_DEVICE_ID_OXSEMI_16PCI954PP 0x9513
2001#define PCI_DEVICE_ID_OXSEMI_16PCI952 0x9521 2002#define PCI_DEVICE_ID_OXSEMI_16PCI952 0x9521
2002#define PCI_DEVICE_ID_OXSEMI_16PCI952PP 0x9523 2003#define PCI_DEVICE_ID_OXSEMI_16PCI952PP 0x9523
2004#define PCI_SUBDEVICE_ID_OXSEMI_C950 0x0001
2003 2005
2004#define PCI_VENDOR_ID_CHELSIO 0x1425 2006#define PCI_VENDOR_ID_CHELSIO 0x1425
2005 2007
diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
index c8f038554e80..b43a9e039059 100644
--- a/include/linux/pipe_fs_i.h
+++ b/include/linux/pipe_fs_i.h
@@ -152,5 +152,6 @@ void generic_pipe_buf_unmap(struct pipe_inode_info *, struct pipe_buffer *, void
152void generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *); 152void generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *);
153int generic_pipe_buf_confirm(struct pipe_inode_info *, struct pipe_buffer *); 153int generic_pipe_buf_confirm(struct pipe_inode_info *, struct pipe_buffer *);
154int generic_pipe_buf_steal(struct pipe_inode_info *, struct pipe_buffer *); 154int generic_pipe_buf_steal(struct pipe_inode_info *, struct pipe_buffer *);
155void generic_pipe_buf_release(struct pipe_inode_info *, struct pipe_buffer *);
155 156
156#endif 157#endif
diff --git a/include/linux/rational.h b/include/linux/rational.h
new file mode 100644
index 000000000000..4f532fcd9eea
--- /dev/null
+++ b/include/linux/rational.h
@@ -0,0 +1,19 @@
1/*
2 * rational fractions
3 *
4 * Copyright (C) 2009 emlix GmbH, Oskar Schirmer <os@emlix.com>
5 *
6 * helper functions when coping with rational numbers,
7 * e.g. when calculating optimum numerator/denominator pairs for
8 * pll configuration taking into account restricted register size
9 */
10
11#ifndef _LINUX_RATIONAL_H
12#define _LINUX_RATIONAL_H
13
14void rational_best_approximation(
15 unsigned long given_numerator, unsigned long given_denominator,
16 unsigned long max_numerator, unsigned long max_denominator,
17 unsigned long *best_numerator, unsigned long *best_denominator);
18
19#endif /* _LINUX_RATIONAL_H */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index d1399660b776..42bf2766111e 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1261,7 +1261,9 @@ struct task_struct {
1261 * credentials (COW) */ 1261 * credentials (COW) */
1262 const struct cred *cred; /* effective (overridable) subjective task 1262 const struct cred *cred; /* effective (overridable) subjective task
1263 * credentials (COW) */ 1263 * credentials (COW) */
1264 struct mutex cred_exec_mutex; /* execve vs ptrace cred calculation mutex */ 1264 struct mutex cred_guard_mutex; /* guard against foreign influences on
1265 * credential calculations
1266 * (notably. ptrace) */
1265 1267
1266 char comm[TASK_COMM_LEN]; /* executable name excluding path 1268 char comm[TASK_COMM_LEN]; /* executable name excluding path
1267 - access with [gs]et_task_comm (which lock 1269 - access with [gs]et_task_comm (which lock
@@ -1901,6 +1903,7 @@ extern void sched_dead(struct task_struct *p);
1901 1903
1902extern void proc_caches_init(void); 1904extern void proc_caches_init(void);
1903extern void flush_signals(struct task_struct *); 1905extern void flush_signals(struct task_struct *);
1906extern void __flush_signals(struct task_struct *);
1904extern void ignore_signals(struct task_struct *); 1907extern void ignore_signals(struct task_struct *);
1905extern void flush_signal_handlers(struct task_struct *, int force_default); 1908extern void flush_signal_handlers(struct task_struct *, int force_default);
1906extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info); 1909extern int dequeue_signal(struct task_struct *tsk, sigset_t *mask, siginfo_t *info);
diff --git a/include/linux/security.h b/include/linux/security.h
index d5fd6163606f..5eff459b3833 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -2197,6 +2197,8 @@ static inline int security_file_mmap(struct file *file, unsigned long reqprot,
2197 unsigned long addr, 2197 unsigned long addr,
2198 unsigned long addr_only) 2198 unsigned long addr_only)
2199{ 2199{
2200 if ((addr < mmap_min_addr) && !capable(CAP_SYS_RAWIO))
2201 return -EACCES;
2200 return 0; 2202 return 0;
2201} 2203}
2202 2204
diff --git a/include/linux/serial.h b/include/linux/serial.h
index 9136cc5608c3..e5bb75a63802 100644
--- a/include/linux/serial.h
+++ b/include/linux/serial.h
@@ -96,54 +96,76 @@ struct serial_uart_config {
96 96
97/* 97/*
98 * Definitions for async_struct (and serial_struct) flags field 98 * Definitions for async_struct (and serial_struct) flags field
99 *
100 * Define ASYNCB_* for convenient use with {test,set,clear}_bit.
99 */ 101 */
100#define ASYNC_HUP_NOTIFY 0x0001 /* Notify getty on hangups and closes 102#define ASYNCB_HUP_NOTIFY 0 /* Notify getty on hangups and closes
101 on the callout port */ 103 * on the callout port */
102#define ASYNC_FOURPORT 0x0002 /* Set OU1, OUT2 per AST Fourport settings */ 104#define ASYNCB_FOURPORT 1 /* Set OU1, OUT2 per AST Fourport settings */
103#define ASYNC_SAK 0x0004 /* Secure Attention Key (Orange book) */ 105#define ASYNCB_SAK 2 /* Secure Attention Key (Orange book) */
104#define ASYNC_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */ 106#define ASYNCB_SPLIT_TERMIOS 3 /* Separate termios for dialin/callout */
105 107#define ASYNCB_SPD_HI 4 /* Use 56000 instead of 38400 bps */
106#define ASYNC_SPD_MASK 0x1030 108#define ASYNCB_SPD_VHI 5 /* Use 115200 instead of 38400 bps */
107#define ASYNC_SPD_HI 0x0010 /* Use 56000 instead of 38400 bps */ 109#define ASYNCB_SKIP_TEST 6 /* Skip UART test during autoconfiguration */
108 110#define ASYNCB_AUTO_IRQ 7 /* Do automatic IRQ during
109#define ASYNC_SPD_VHI 0x0020 /* Use 115200 instead of 38400 bps */ 111 * autoconfiguration */
110#define ASYNC_SPD_CUST 0x0030 /* Use user-specified divisor */ 112#define ASYNCB_SESSION_LOCKOUT 8 /* Lock out cua opens based on session */
111 113#define ASYNCB_PGRP_LOCKOUT 9 /* Lock out cua opens based on pgrp */
112#define ASYNC_SKIP_TEST 0x0040 /* Skip UART test during autoconfiguration */ 114#define ASYNCB_CALLOUT_NOHUP 10 /* Don't do hangups for cua device */
113#define ASYNC_AUTO_IRQ 0x0080 /* Do automatic IRQ during autoconfiguration */ 115#define ASYNCB_HARDPPS_CD 11 /* Call hardpps when CD goes high */
114#define ASYNC_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */ 116#define ASYNCB_SPD_SHI 12 /* Use 230400 instead of 38400 bps */
115#define ASYNC_PGRP_LOCKOUT 0x0200 /* Lock out cua opens based on pgrp */ 117#define ASYNCB_LOW_LATENCY 13 /* Request low latency behaviour */
116#define ASYNC_CALLOUT_NOHUP 0x0400 /* Don't do hangups for cua device */ 118#define ASYNCB_BUGGY_UART 14 /* This is a buggy UART, skip some safety
117 119 * checks. Note: can be dangerous! */
118#define ASYNC_HARDPPS_CD 0x0800 /* Call hardpps when CD goes high */ 120#define ASYNCB_AUTOPROBE 15 /* Port was autoprobed by PCI or PNP code */
119 121#define ASYNCB_LAST_USER 15
120#define ASYNC_SPD_SHI 0x1000 /* Use 230400 instead of 38400 bps */ 122
121#define ASYNC_SPD_WARP 0x1010 /* Use 460800 instead of 38400 bps */ 123/* Internal flags used only by kernel */
122 124#define ASYNCB_INITIALIZED 31 /* Serial port was initialized */
123#define ASYNC_LOW_LATENCY 0x2000 /* Request low latency behaviour */ 125#define ASYNCB_NORMAL_ACTIVE 29 /* Normal device is active */
124 126#define ASYNCB_BOOT_AUTOCONF 28 /* Autoconfigure port on bootup */
125#define ASYNC_BUGGY_UART 0x4000 /* This is a buggy UART, skip some safety 127#define ASYNCB_CLOSING 27 /* Serial port is closing */
126 * checks. Note: can be dangerous! */ 128#define ASYNCB_CTS_FLOW 26 /* Do CTS flow control */
127 129#define ASYNCB_CHECK_CD 25 /* i.e., CLOCAL */
128#define ASYNC_AUTOPROBE 0x8000 /* Port was autoprobed by PCI or PNP code */ 130#define ASYNCB_SHARE_IRQ 24 /* for multifunction cards, no longer used */
129 131#define ASYNCB_CONS_FLOW 23 /* flow control for console */
130#define ASYNC_FLAGS 0x7FFF /* Possible legal async flags */ 132#define ASYNCB_BOOT_ONLYMCA 22 /* Probe only if MCA bus */
131#define ASYNC_USR_MASK 0x3430 /* Legal flags that non-privileged 133#define ASYNCB_FIRST_KERNEL 22
132 * users can set or reset */ 134
133 135#define ASYNC_HUP_NOTIFY (1U << ASYNCB_HUP_NOTIFY)
134/* Internal flags used only by kernel/chr_drv/serial.c */ 136#define ASYNC_FOURPORT (1U << ASYNCB_FOURPORT)
135#define ASYNC_INITIALIZED 0x80000000 /* Serial port was initialized */ 137#define ASYNC_SAK (1U << ASYNCB_SAK)
136#define ASYNC_NORMAL_ACTIVE 0x20000000 /* Normal device is active */ 138#define ASYNC_SPLIT_TERMIOS (1U << ASYNCB_SPLIT_TERMIOS)
137#define ASYNC_BOOT_AUTOCONF 0x10000000 /* Autoconfigure port on bootup */ 139#define ASYNC_SPD_HI (1U << ASYNCB_SPD_HI)
138#define ASYNC_CLOSING 0x08000000 /* Serial port is closing */ 140#define ASYNC_SPD_VHI (1U << ASYNCB_SPD_VHI)
139#define ASYNC_CTS_FLOW 0x04000000 /* Do CTS flow control */ 141#define ASYNC_SKIP_TEST (1U << ASYNCB_SKIP_TEST)
140#define ASYNC_CHECK_CD 0x02000000 /* i.e., CLOCAL */ 142#define ASYNC_AUTO_IRQ (1U << ASYNCB_AUTO_IRQ)
141#define ASYNC_SHARE_IRQ 0x01000000 /* for multifunction cards 143#define ASYNC_SESSION_LOCKOUT (1U << ASYNCB_SESSION_LOCKOUT)
142 --- no longer used */ 144#define ASYNC_PGRP_LOCKOUT (1U << ASYNCB_PGRP_LOCKOUT)
143#define ASYNC_CONS_FLOW 0x00800000 /* flow control for console */ 145#define ASYNC_CALLOUT_NOHUP (1U << ASYNCB_CALLOUT_NOHUP)
144 146#define ASYNC_HARDPPS_CD (1U << ASYNCB_HARDPPS_CD)
145#define ASYNC_BOOT_ONLYMCA 0x00400000 /* Probe only if MCA bus */ 147#define ASYNC_SPD_SHI (1U << ASYNCB_SPD_SHI)
146#define ASYNC_INTERNAL_FLAGS 0xFFC00000 /* Internal flags */ 148#define ASYNC_LOW_LATENCY (1U << ASYNCB_LOW_LATENCY)
149#define ASYNC_BUGGY_UART (1U << ASYNCB_BUGGY_UART)
150#define ASYNC_AUTOPROBE (1U << ASYNCB_AUTOPROBE)
151
152#define ASYNC_FLAGS ((1U << ASYNCB_LAST_USER) - 1)
153#define ASYNC_USR_MASK (ASYNC_SPD_HI|ASYNC_SPD_VHI| \
154 ASYNC_CALLOUT_NOHUP|ASYNC_SPD_SHI|ASYNC_LOW_LATENCY)
155#define ASYNC_SPD_CUST (ASYNC_SPD_HI|ASYNC_SPD_VHI)
156#define ASYNC_SPD_WARP (ASYNC_SPD_HI|ASYNC_SPD_SHI)
157#define ASYNC_SPD_MASK (ASYNC_SPD_HI|ASYNC_SPD_VHI|ASYNC_SPD_SHI)
158
159#define ASYNC_INITIALIZED (1U << ASYNCB_INITIALIZED)
160#define ASYNC_NORMAL_ACTIVE (1U << ASYNCB_NORMAL_ACTIVE)
161#define ASYNC_BOOT_AUTOCONF (1U << ASYNCB_BOOT_AUTOCONF)
162#define ASYNC_CLOSING (1U << ASYNCB_CLOSING)
163#define ASYNC_CTS_FLOW (1U << ASYNCB_CTS_FLOW)
164#define ASYNC_CHECK_CD (1U << ASYNCB_CHECK_CD)
165#define ASYNC_SHARE_IRQ (1U << ASYNCB_SHARE_IRQ)
166#define ASYNC_CONS_FLOW (1U << ASYNCB_CONS_FLOW)
167#define ASYNC_BOOT_ONLYMCA (1U << ASYNCB_BOOT_ONLYMCA)
168#define ASYNC_INTERNAL_FLAGS (~((1U << ASYNCB_FIRST_KERNEL) - 1))
147 169
148/* 170/*
149 * Multiport serial configuration structure --- external structure 171 * Multiport serial configuration structure --- external structure
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 57a97e52e58d..6fd80c4243f1 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -41,7 +41,8 @@
41#define PORT_XSCALE 15 41#define PORT_XSCALE 15
42#define PORT_RM9000 16 /* PMC-Sierra RM9xxx internal UART */ 42#define PORT_RM9000 16 /* PMC-Sierra RM9xxx internal UART */
43#define PORT_OCTEON 17 /* Cavium OCTEON internal UART */ 43#define PORT_OCTEON 17 /* Cavium OCTEON internal UART */
44#define PORT_MAX_8250 17 /* max port ID */ 44#define PORT_AR7 18 /* Texas Instruments AR7 internal UART */
45#define PORT_MAX_8250 18 /* max port ID */
45 46
46/* 47/*
47 * ARM specific type numbers. These are not currently guaranteed 48 * ARM specific type numbers. These are not currently guaranteed
@@ -167,6 +168,9 @@
167/* MAX3100 */ 168/* MAX3100 */
168#define PORT_MAX3100 86 169#define PORT_MAX3100 86
169 170
171/* Timberdale UART */
172#define PORT_TIMBUART 87
173
170#ifdef __KERNEL__ 174#ifdef __KERNEL__
171 175
172#include <linux/compiler.h> 176#include <linux/compiler.h>
diff --git a/include/linux/serial_sci.h b/include/linux/serial_sci.h
index 893cc53486bc..1c297ddc9d5a 100644
--- a/include/linux/serial_sci.h
+++ b/include/linux/serial_sci.h
@@ -25,8 +25,7 @@ struct plat_sci_port {
25 unsigned int irqs[SCIx_NR_IRQS]; /* ERI, RXI, TXI, BRI */ 25 unsigned int irqs[SCIx_NR_IRQS]; /* ERI, RXI, TXI, BRI */
26 unsigned int type; /* SCI / SCIF / IRDA */ 26 unsigned int type; /* SCI / SCIF / IRDA */
27 upf_t flags; /* UPF_* flags */ 27 upf_t flags; /* UPF_* flags */
28 char *clk; /* clock string */
28}; 29};
29 30
30int early_sci_setup(struct uart_port *port);
31
32#endif /* __LINUX_SERIAL_SCI_H */ 31#endif /* __LINUX_SERIAL_SCI_H */
diff --git a/include/linux/sh_cmt.h b/include/linux/sh_cmt.h
deleted file mode 100644
index 68cacde5954f..000000000000
--- a/include/linux/sh_cmt.h
+++ /dev/null
@@ -1,13 +0,0 @@
1#ifndef __SH_CMT_H__
2#define __SH_CMT_H__
3
4struct sh_cmt_config {
5 char *name;
6 unsigned long channel_offset;
7 int timer_bit;
8 char *clk;
9 unsigned long clockevent_rating;
10 unsigned long clocksource_rating;
11};
12
13#endif /* __SH_CMT_H__ */
diff --git a/include/linux/sh_timer.h b/include/linux/sh_timer.h
new file mode 100644
index 000000000000..864bd56bd3b0
--- /dev/null
+++ b/include/linux/sh_timer.h
@@ -0,0 +1,13 @@
1#ifndef __SH_TIMER_H__
2#define __SH_TIMER_H__
3
4struct sh_timer_config {
5 char *name;
6 long channel_offset;
7 int timer_bit;
8 char *clk;
9 unsigned long clockevent_rating;
10 unsigned long clocksource_rating;
11};
12
13#endif /* __SH_TIMER_H__ */
diff --git a/include/linux/splice.h b/include/linux/splice.h
index 5f3faa9d15ae..18e7c7c0cae6 100644
--- a/include/linux/splice.h
+++ b/include/linux/splice.h
@@ -11,8 +11,7 @@
11#include <linux/pipe_fs_i.h> 11#include <linux/pipe_fs_i.h>
12 12
13/* 13/*
14 * splice is tied to pipes as a transport (at least for now), so we'll just 14 * Flags passed in from splice/tee/vmsplice
15 * add the splice flags here.
16 */ 15 */
17#define SPLICE_F_MOVE (0x01) /* move pages instead of copying */ 16#define SPLICE_F_MOVE (0x01) /* move pages instead of copying */
18#define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */ 17#define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */
diff --git a/include/linux/time.h b/include/linux/time.h
index 242f62499bb7..ea16c1a01d51 100644
--- a/include/linux/time.h
+++ b/include/linux/time.h
@@ -113,6 +113,21 @@ struct timespec current_kernel_time(void);
113#define CURRENT_TIME (current_kernel_time()) 113#define CURRENT_TIME (current_kernel_time())
114#define CURRENT_TIME_SEC ((struct timespec) { get_seconds(), 0 }) 114#define CURRENT_TIME_SEC ((struct timespec) { get_seconds(), 0 })
115 115
116/* Some architectures do not supply their own clocksource.
117 * This is mainly the case in architectures that get their
118 * inter-tick times by reading the counter on their interval
119 * timer. Since these timers wrap every tick, they're not really
120 * useful as clocksources. Wrapping them to act like one is possible
121 * but not very efficient. So we provide a callout these arches
122 * can implement for use with the jiffies clocksource to provide
123 * finer then tick granular time.
124 */
125#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
126extern u32 arch_gettimeoffset(void);
127#else
128static inline u32 arch_gettimeoffset(void) { return 0; }
129#endif
130
116extern void do_gettimeofday(struct timeval *tv); 131extern void do_gettimeofday(struct timeval *tv);
117extern int do_settimeofday(struct timespec *tv); 132extern int do_settimeofday(struct timespec *tv);
118extern int do_sys_settimeofday(struct timespec *tv, struct timezone *tz); 133extern int do_sys_settimeofday(struct timespec *tv, struct timezone *tz);
diff --git a/include/linux/tty.h b/include/linux/tty.h
index fc39db95499f..1488d8c81aac 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -185,7 +185,7 @@ struct tty_port;
185struct tty_port_operations { 185struct tty_port_operations {
186 /* Return 1 if the carrier is raised */ 186 /* Return 1 if the carrier is raised */
187 int (*carrier_raised)(struct tty_port *port); 187 int (*carrier_raised)(struct tty_port *port);
188 void (*raise_dtr_rts)(struct tty_port *port); 188 void (*dtr_rts)(struct tty_port *port, int raise);
189}; 189};
190 190
191struct tty_port { 191struct tty_port {
@@ -201,6 +201,9 @@ struct tty_port {
201 unsigned char *xmit_buf; /* Optional buffer */ 201 unsigned char *xmit_buf; /* Optional buffer */
202 int close_delay; /* Close port delay */ 202 int close_delay; /* Close port delay */
203 int closing_wait; /* Delay for output */ 203 int closing_wait; /* Delay for output */
204 int drain_delay; /* Set to zero if no pure time
205 based drain is needed else
206 set to size of fifo */
204}; 207};
205 208
206/* 209/*
@@ -223,8 +226,11 @@ struct tty_struct {
223 struct tty_driver *driver; 226 struct tty_driver *driver;
224 const struct tty_operations *ops; 227 const struct tty_operations *ops;
225 int index; 228 int index;
226 /* The ldisc objects are protected by tty_ldisc_lock at the moment */ 229
227 struct tty_ldisc ldisc; 230 /* Protects ldisc changes: Lock tty not pty */
231 struct mutex ldisc_mutex;
232 struct tty_ldisc *ldisc;
233
228 struct mutex termios_mutex; 234 struct mutex termios_mutex;
229 spinlock_t ctrl_lock; 235 spinlock_t ctrl_lock;
230 /* Termios values are protected by the termios mutex */ 236 /* Termios values are protected by the termios mutex */
@@ -311,6 +317,7 @@ struct tty_struct {
311#define TTY_CLOSING 7 /* ->close() in progress */ 317#define TTY_CLOSING 7 /* ->close() in progress */
312#define TTY_LDISC 9 /* Line discipline attached */ 318#define TTY_LDISC 9 /* Line discipline attached */
313#define TTY_LDISC_CHANGING 10 /* Line discipline changing */ 319#define TTY_LDISC_CHANGING 10 /* Line discipline changing */
320#define TTY_LDISC_OPEN 11 /* Line discipline is open */
314#define TTY_HW_COOK_OUT 14 /* Hardware can do output cooking */ 321#define TTY_HW_COOK_OUT 14 /* Hardware can do output cooking */
315#define TTY_HW_COOK_IN 15 /* Hardware can do input cooking */ 322#define TTY_HW_COOK_IN 15 /* Hardware can do input cooking */
316#define TTY_PTY_LOCK 16 /* pty private */ 323#define TTY_PTY_LOCK 16 /* pty private */
@@ -403,6 +410,7 @@ extern int tty_termios_hw_change(struct ktermios *a, struct ktermios *b);
403extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *); 410extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *);
404extern void tty_ldisc_deref(struct tty_ldisc *); 411extern void tty_ldisc_deref(struct tty_ldisc *);
405extern struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *); 412extern struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *);
413extern void tty_ldisc_hangup(struct tty_struct *tty);
406extern const struct file_operations tty_ldiscs_proc_fops; 414extern const struct file_operations tty_ldiscs_proc_fops;
407 415
408extern void tty_wakeup(struct tty_struct *tty); 416extern void tty_wakeup(struct tty_struct *tty);
@@ -425,6 +433,9 @@ extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
425extern void tty_release_dev(struct file *filp); 433extern void tty_release_dev(struct file *filp);
426extern int tty_init_termios(struct tty_struct *tty); 434extern int tty_init_termios(struct tty_struct *tty);
427 435
436extern struct tty_struct *tty_pair_get_tty(struct tty_struct *tty);
437extern struct tty_struct *tty_pair_get_pty(struct tty_struct *tty);
438
428extern struct mutex tty_mutex; 439extern struct mutex tty_mutex;
429 440
430extern void tty_write_unlock(struct tty_struct *tty); 441extern void tty_write_unlock(struct tty_struct *tty);
@@ -438,6 +449,7 @@ extern struct tty_struct *tty_port_tty_get(struct tty_port *port);
438extern void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty); 449extern void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty);
439extern int tty_port_carrier_raised(struct tty_port *port); 450extern int tty_port_carrier_raised(struct tty_port *port);
440extern void tty_port_raise_dtr_rts(struct tty_port *port); 451extern void tty_port_raise_dtr_rts(struct tty_port *port);
452extern void tty_port_lower_dtr_rts(struct tty_port *port);
441extern void tty_port_hangup(struct tty_port *port); 453extern void tty_port_hangup(struct tty_port *port);
442extern int tty_port_block_til_ready(struct tty_port *port, 454extern int tty_port_block_til_ready(struct tty_port *port,
443 struct tty_struct *tty, struct file *filp); 455 struct tty_struct *tty, struct file *filp);
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index bcba84ea2d86..3566129384a4 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -127,7 +127,8 @@
127 * the line discipline are close to full, and it should somehow 127 * the line discipline are close to full, and it should somehow
128 * signal that no more characters should be sent to the tty. 128 * signal that no more characters should be sent to the tty.
129 * 129 *
130 * Optional: Always invoke via tty_throttle(); 130 * Optional: Always invoke via tty_throttle(), called under the
131 * termios lock.
131 * 132 *
132 * void (*unthrottle)(struct tty_struct * tty); 133 * void (*unthrottle)(struct tty_struct * tty);
133 * 134 *
@@ -135,7 +136,8 @@
135 * that characters can now be sent to the tty without fear of 136 * that characters can now be sent to the tty without fear of
136 * overrunning the input buffers of the line disciplines. 137 * overrunning the input buffers of the line disciplines.
137 * 138 *
138 * Optional: Always invoke via tty_unthrottle(); 139 * Optional: Always invoke via tty_unthrottle(), called under the
140 * termios lock.
139 * 141 *
140 * void (*stop)(struct tty_struct *tty); 142 * void (*stop)(struct tty_struct *tty);
141 * 143 *
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 625e9e4639c6..8cdfed738fe4 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -224,8 +224,7 @@ struct usb_serial_driver {
224 /* Called by console with tty = NULL and by tty */ 224 /* Called by console with tty = NULL and by tty */
225 int (*open)(struct tty_struct *tty, 225 int (*open)(struct tty_struct *tty,
226 struct usb_serial_port *port, struct file *filp); 226 struct usb_serial_port *port, struct file *filp);
227 void (*close)(struct tty_struct *tty, 227 void (*close)(struct usb_serial_port *port);
228 struct usb_serial_port *port, struct file *filp);
229 int (*write)(struct tty_struct *tty, struct usb_serial_port *port, 228 int (*write)(struct tty_struct *tty, struct usb_serial_port *port,
230 const unsigned char *buf, int count); 229 const unsigned char *buf, int count);
231 /* Called only by the tty layer */ 230 /* Called only by the tty layer */
@@ -241,6 +240,10 @@ struct usb_serial_driver {
241 int (*tiocmget)(struct tty_struct *tty, struct file *file); 240 int (*tiocmget)(struct tty_struct *tty, struct file *file);
242 int (*tiocmset)(struct tty_struct *tty, struct file *file, 241 int (*tiocmset)(struct tty_struct *tty, struct file *file,
243 unsigned int set, unsigned int clear); 242 unsigned int set, unsigned int clear);
243 /* Called by the tty layer for port level work. There may or may not
244 be an attached tty at this point */
245 void (*dtr_rts)(struct usb_serial_port *port, int on);
246 int (*carrier_raised)(struct usb_serial_port *port);
244 /* USB events */ 247 /* USB events */
245 void (*read_int_callback)(struct urb *urb); 248 void (*read_int_callback)(struct urb *urb);
246 void (*write_int_callback)(struct urb *urb); 249 void (*write_int_callback)(struct urb *urb);
@@ -283,8 +286,7 @@ extern int usb_serial_generic_open(struct tty_struct *tty,
283 struct usb_serial_port *port, struct file *filp); 286 struct usb_serial_port *port, struct file *filp);
284extern int usb_serial_generic_write(struct tty_struct *tty, 287extern int usb_serial_generic_write(struct tty_struct *tty,
285 struct usb_serial_port *port, const unsigned char *buf, int count); 288 struct usb_serial_port *port, const unsigned char *buf, int count);
286extern void usb_serial_generic_close(struct tty_struct *tty, 289extern void usb_serial_generic_close(struct usb_serial_port *port);
287 struct usb_serial_port *port, struct file *filp);
288extern int usb_serial_generic_resume(struct usb_serial *serial); 290extern int usb_serial_generic_resume(struct usb_serial *serial);
289extern int usb_serial_generic_write_room(struct tty_struct *tty); 291extern int usb_serial_generic_write_room(struct tty_struct *tty);
290extern int usb_serial_generic_chars_in_buffer(struct tty_struct *tty); 292extern int usb_serial_generic_chars_in_buffer(struct tty_struct *tty);
diff --git a/include/linux/virtio_blk.h b/include/linux/virtio_blk.h
index 94c56d29869d..be7d255fc7cf 100644
--- a/include/linux/virtio_blk.h
+++ b/include/linux/virtio_blk.h
@@ -15,6 +15,10 @@
15#define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */ 15#define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */
16#define VIRTIO_BLK_F_RO 5 /* Disk is read-only */ 16#define VIRTIO_BLK_F_RO 5 /* Disk is read-only */
17#define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/ 17#define VIRTIO_BLK_F_BLK_SIZE 6 /* Block size of disk is available*/
18#define VIRTIO_BLK_F_SCSI 7 /* Supports scsi command passthru */
19#define VIRTIO_BLK_F_IDENTIFY 8 /* ATA IDENTIFY supported */
20
21#define VIRTIO_BLK_ID_BYTES (sizeof(__u16[256])) /* IDENTIFY DATA */
18 22
19struct virtio_blk_config 23struct virtio_blk_config
20{ 24{
@@ -32,6 +36,7 @@ struct virtio_blk_config
32 } geometry; 36 } geometry;
33 /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */ 37 /* block size of device (if VIRTIO_BLK_F_BLK_SIZE) */
34 __u32 blk_size; 38 __u32 blk_size;
39 __u8 identify[VIRTIO_BLK_ID_BYTES];
35} __attribute__((packed)); 40} __attribute__((packed));
36 41
37/* These two define direction. */ 42/* These two define direction. */
@@ -55,6 +60,13 @@ struct virtio_blk_outhdr
55 __u64 sector; 60 __u64 sector;
56}; 61};
57 62
63struct virtio_scsi_inhdr {
64 __u32 errors;
65 __u32 data_len;
66 __u32 sense_len;
67 __u32 residual;
68};
69
58/* And this is the final byte of the write scatter-gather list. */ 70/* And this is the final byte of the write scatter-gather list. */
59#define VIRTIO_BLK_S_OK 0 71#define VIRTIO_BLK_S_OK 0
60#define VIRTIO_BLK_S_IOERR 1 72#define VIRTIO_BLK_S_IOERR 1
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 43b50d36925c..3878d1dc7f59 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -270,7 +270,7 @@ static inline unsigned char scsi_get_prot_type(struct scsi_cmnd *scmd)
270 270
271static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd) 271static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd)
272{ 272{
273 return scmd->request->sector; 273 return blk_rq_pos(scmd->request);
274} 274}
275 275
276static inline unsigned scsi_prot_sg_count(struct scsi_cmnd *cmd) 276static inline unsigned scsi_prot_sg_count(struct scsi_cmnd *cmd)
diff --git a/include/trace/events/block.h b/include/trace/events/block.h
index 53effd496a50..d6b05f42dd44 100644
--- a/include/trace/events/block.h
+++ b/include/trace/events/block.h
@@ -25,9 +25,8 @@ TRACE_EVENT(block_rq_abort,
25 25
26 TP_fast_assign( 26 TP_fast_assign(
27 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0; 27 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0;
28 __entry->sector = blk_pc_request(rq) ? 0 : rq->hard_sector; 28 __entry->sector = blk_pc_request(rq) ? 0 : blk_rq_pos(rq);
29 __entry->nr_sector = blk_pc_request(rq) ? 29 __entry->nr_sector = blk_pc_request(rq) ? 0 : blk_rq_sectors(rq);
30 0 : rq->hard_nr_sectors;
31 __entry->errors = rq->errors; 30 __entry->errors = rq->errors;
32 31
33 blk_fill_rwbs_rq(__entry->rwbs, rq); 32 blk_fill_rwbs_rq(__entry->rwbs, rq);
@@ -59,10 +58,9 @@ TRACE_EVENT(block_rq_insert,
59 58
60 TP_fast_assign( 59 TP_fast_assign(
61 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0; 60 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0;
62 __entry->sector = blk_pc_request(rq) ? 0 : rq->hard_sector; 61 __entry->sector = blk_pc_request(rq) ? 0 : blk_rq_pos(rq);
63 __entry->nr_sector = blk_pc_request(rq) ? 62 __entry->nr_sector = blk_pc_request(rq) ? 0 : blk_rq_sectors(rq);
64 0 : rq->hard_nr_sectors; 63 __entry->bytes = blk_pc_request(rq) ? blk_rq_bytes(rq) : 0;
65 __entry->bytes = blk_pc_request(rq) ? rq->data_len : 0;
66 64
67 blk_fill_rwbs_rq(__entry->rwbs, rq); 65 blk_fill_rwbs_rq(__entry->rwbs, rq);
68 blk_dump_cmd(__get_str(cmd), rq); 66 blk_dump_cmd(__get_str(cmd), rq);
@@ -94,10 +92,9 @@ TRACE_EVENT(block_rq_issue,
94 92
95 TP_fast_assign( 93 TP_fast_assign(
96 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0; 94 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0;
97 __entry->sector = blk_pc_request(rq) ? 0 : rq->hard_sector; 95 __entry->sector = blk_pc_request(rq) ? 0 : blk_rq_pos(rq);
98 __entry->nr_sector = blk_pc_request(rq) ? 96 __entry->nr_sector = blk_pc_request(rq) ? 0 : blk_rq_sectors(rq);
99 0 : rq->hard_nr_sectors; 97 __entry->bytes = blk_pc_request(rq) ? blk_rq_bytes(rq) : 0;
100 __entry->bytes = blk_pc_request(rq) ? rq->data_len : 0;
101 98
102 blk_fill_rwbs_rq(__entry->rwbs, rq); 99 blk_fill_rwbs_rq(__entry->rwbs, rq);
103 blk_dump_cmd(__get_str(cmd), rq); 100 blk_dump_cmd(__get_str(cmd), rq);
@@ -128,9 +125,8 @@ TRACE_EVENT(block_rq_requeue,
128 125
129 TP_fast_assign( 126 TP_fast_assign(
130 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0; 127 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0;
131 __entry->sector = blk_pc_request(rq) ? 0 : rq->hard_sector; 128 __entry->sector = blk_pc_request(rq) ? 0 : blk_rq_pos(rq);
132 __entry->nr_sector = blk_pc_request(rq) ? 129 __entry->nr_sector = blk_pc_request(rq) ? 0 : blk_rq_sectors(rq);
133 0 : rq->hard_nr_sectors;
134 __entry->errors = rq->errors; 130 __entry->errors = rq->errors;
135 131
136 blk_fill_rwbs_rq(__entry->rwbs, rq); 132 blk_fill_rwbs_rq(__entry->rwbs, rq);
@@ -161,9 +157,8 @@ TRACE_EVENT(block_rq_complete,
161 157
162 TP_fast_assign( 158 TP_fast_assign(
163 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0; 159 __entry->dev = rq->rq_disk ? disk_devt(rq->rq_disk) : 0;
164 __entry->sector = blk_pc_request(rq) ? 0 : rq->hard_sector; 160 __entry->sector = blk_pc_request(rq) ? 0 : blk_rq_pos(rq);
165 __entry->nr_sector = blk_pc_request(rq) ? 161 __entry->nr_sector = blk_pc_request(rq) ? 0 : blk_rq_sectors(rq);
166 0 : rq->hard_nr_sectors;
167 __entry->errors = rq->errors; 162 __entry->errors = rq->errors;
168 163
169 blk_fill_rwbs_rq(__entry->rwbs, rq); 164 blk_fill_rwbs_rq(__entry->rwbs, rq);
diff --git a/ipc/shm.c b/ipc/shm.c
index 425971600485..15dd238e5338 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -384,7 +384,6 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
384 error = PTR_ERR(file); 384 error = PTR_ERR(file);
385 if (IS_ERR(file)) 385 if (IS_ERR(file))
386 goto no_file; 386 goto no_file;
387 ima_shm_check(file);
388 387
389 id = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni); 388 id = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni);
390 if (id < 0) { 389 if (id < 0) {
@@ -891,7 +890,7 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
891 file = alloc_file(path.mnt, path.dentry, f_mode, &shm_file_operations); 890 file = alloc_file(path.mnt, path.dentry, f_mode, &shm_file_operations);
892 if (!file) 891 if (!file)
893 goto out_free; 892 goto out_free;
894 ima_shm_check(file); 893 ima_counts_get(file);
895 894
896 file->private_data = sfd; 895 file->private_data = sfd;
897 file->f_mapping = shp->shm_file->f_mapping; 896 file->f_mapping = shp->shm_file->f_mapping;
diff --git a/kernel/cred.c b/kernel/cred.c
index 3a039189d707..1bb4d7e5d616 100644
--- a/kernel/cred.c
+++ b/kernel/cred.c
@@ -167,7 +167,7 @@ EXPORT_SYMBOL(prepare_creds);
167 167
168/* 168/*
169 * Prepare credentials for current to perform an execve() 169 * Prepare credentials for current to perform an execve()
170 * - The caller must hold current->cred_exec_mutex 170 * - The caller must hold current->cred_guard_mutex
171 */ 171 */
172struct cred *prepare_exec_creds(void) 172struct cred *prepare_exec_creds(void)
173{ 173{
@@ -276,7 +276,7 @@ int copy_creds(struct task_struct *p, unsigned long clone_flags)
276 struct cred *new; 276 struct cred *new;
277 int ret; 277 int ret;
278 278
279 mutex_init(&p->cred_exec_mutex); 279 mutex_init(&p->cred_guard_mutex);
280 280
281 if ( 281 if (
282#ifdef CONFIG_KEYS 282#ifdef CONFIG_KEYS
diff --git a/kernel/exit.c b/kernel/exit.c
index cab535c427b8..51d1fe3fb7ad 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -1472,6 +1472,7 @@ static int wait_consider_task(struct task_struct *parent, int ptrace,
1472 */ 1472 */
1473 if (*notask_error) 1473 if (*notask_error)
1474 *notask_error = ret; 1474 *notask_error = ret;
1475 return 0;
1475 } 1476 }
1476 1477
1477 if (likely(!ptrace) && unlikely(p->ptrace)) { 1478 if (likely(!ptrace) && unlikely(p->ptrace)) {
diff --git a/kernel/module.c b/kernel/module.c
index 2383e60fcf3f..278e9b6762bb 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -73,6 +73,9 @@ DEFINE_MUTEX(module_mutex);
73EXPORT_SYMBOL_GPL(module_mutex); 73EXPORT_SYMBOL_GPL(module_mutex);
74static LIST_HEAD(modules); 74static LIST_HEAD(modules);
75 75
76/* Block module loading/unloading? */
77int modules_disabled = 0;
78
76/* Waiting for a module to finish initializing? */ 79/* Waiting for a module to finish initializing? */
77static DECLARE_WAIT_QUEUE_HEAD(module_wq); 80static DECLARE_WAIT_QUEUE_HEAD(module_wq);
78 81
@@ -778,7 +781,7 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
778 char name[MODULE_NAME_LEN]; 781 char name[MODULE_NAME_LEN];
779 int ret, forced = 0; 782 int ret, forced = 0;
780 783
781 if (!capable(CAP_SYS_MODULE)) 784 if (!capable(CAP_SYS_MODULE) || modules_disabled)
782 return -EPERM; 785 return -EPERM;
783 786
784 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0) 787 if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
@@ -2338,7 +2341,7 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
2338 int ret = 0; 2341 int ret = 0;
2339 2342
2340 /* Must have permission */ 2343 /* Must have permission */
2341 if (!capable(CAP_SYS_MODULE)) 2344 if (!capable(CAP_SYS_MODULE) || modules_disabled)
2342 return -EPERM; 2345 return -EPERM;
2343 2346
2344 /* Only one module load at a time, please */ 2347 /* Only one module load at a time, please */
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 2442d140bd9a..f6d8b8cb5e34 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -175,10 +175,11 @@ int ptrace_attach(struct task_struct *task)
175 if (same_thread_group(task, current)) 175 if (same_thread_group(task, current))
176 goto out; 176 goto out;
177 177
178 /* Protect exec's credential calculations against our interference; 178 /* Protect the target's credential calculations against our
179 * SUID, SGID and LSM creds get determined differently under ptrace. 179 * interference; SUID, SGID and LSM creds get determined differently
180 * under ptrace.
180 */ 181 */
181 retval = mutex_lock_interruptible(&task->cred_exec_mutex); 182 retval = mutex_lock_interruptible(&task->cred_guard_mutex);
182 if (retval < 0) 183 if (retval < 0)
183 goto out; 184 goto out;
184 185
@@ -222,7 +223,7 @@ repeat:
222bad: 223bad:
223 write_unlock_irqrestore(&tasklist_lock, flags); 224 write_unlock_irqrestore(&tasklist_lock, flags);
224 task_unlock(task); 225 task_unlock(task);
225 mutex_unlock(&task->cred_exec_mutex); 226 mutex_unlock(&task->cred_guard_mutex);
226out: 227out:
227 return retval; 228 return retval;
228} 229}
diff --git a/kernel/signal.c b/kernel/signal.c
index dba6ae99978a..809a228019ad 100644
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -247,14 +247,19 @@ void flush_sigqueue(struct sigpending *queue)
247/* 247/*
248 * Flush all pending signals for a task. 248 * Flush all pending signals for a task.
249 */ 249 */
250void __flush_signals(struct task_struct *t)
251{
252 clear_tsk_thread_flag(t, TIF_SIGPENDING);
253 flush_sigqueue(&t->pending);
254 flush_sigqueue(&t->signal->shared_pending);
255}
256
250void flush_signals(struct task_struct *t) 257void flush_signals(struct task_struct *t)
251{ 258{
252 unsigned long flags; 259 unsigned long flags;
253 260
254 spin_lock_irqsave(&t->sighand->siglock, flags); 261 spin_lock_irqsave(&t->sighand->siglock, flags);
255 clear_tsk_thread_flag(t, TIF_SIGPENDING); 262 __flush_signals(t);
256 flush_sigqueue(&t->pending);
257 flush_sigqueue(&t->signal->shared_pending);
258 spin_unlock_irqrestore(&t->sighand->siglock, flags); 263 spin_unlock_irqrestore(&t->sighand->siglock, flags);
259} 264}
260 265
diff --git a/kernel/slow-work.c b/kernel/slow-work.c
index b28d19135f43..521ed2004d63 100644
--- a/kernel/slow-work.c
+++ b/kernel/slow-work.c
@@ -372,8 +372,8 @@ static int slow_work_thread(void *_data)
372 vsmax *= atomic_read(&slow_work_thread_count); 372 vsmax *= atomic_read(&slow_work_thread_count);
373 vsmax /= 100; 373 vsmax /= 100;
374 374
375 prepare_to_wait(&slow_work_thread_wq, &wait, 375 prepare_to_wait_exclusive(&slow_work_thread_wq, &wait,
376 TASK_INTERRUPTIBLE); 376 TASK_INTERRUPTIBLE);
377 if (!freezing(current) && 377 if (!freezing(current) &&
378 !slow_work_threads_should_exit && 378 !slow_work_threads_should_exit &&
379 !slow_work_available(vsmax) && 379 !slow_work_available(vsmax) &&
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 6a463716ecbf..944ba03cae19 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -114,6 +114,7 @@ static int ngroups_max = NGROUPS_MAX;
114 114
115#ifdef CONFIG_MODULES 115#ifdef CONFIG_MODULES
116extern char modprobe_path[]; 116extern char modprobe_path[];
117extern int modules_disabled;
117#endif 118#endif
118#ifdef CONFIG_CHR_DEV_SG 119#ifdef CONFIG_CHR_DEV_SG
119extern int sg_big_buff; 120extern int sg_big_buff;
@@ -534,6 +535,17 @@ static struct ctl_table kern_table[] = {
534 .proc_handler = &proc_dostring, 535 .proc_handler = &proc_dostring,
535 .strategy = &sysctl_string, 536 .strategy = &sysctl_string,
536 }, 537 },
538 {
539 .ctl_name = CTL_UNNUMBERED,
540 .procname = "modules_disabled",
541 .data = &modules_disabled,
542 .maxlen = sizeof(int),
543 .mode = 0644,
544 /* only handle a transition from default "0" to "1" */
545 .proc_handler = &proc_dointvec_minmax,
546 .extra1 = &one,
547 .extra2 = &one,
548 },
537#endif 549#endif
538#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) 550#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
539 { 551 {
@@ -1233,7 +1245,6 @@ static struct ctl_table vm_table[] = {
1233 .strategy = &sysctl_jiffies, 1245 .strategy = &sysctl_jiffies,
1234 }, 1246 },
1235#endif 1247#endif
1236#ifdef CONFIG_SECURITY
1237 { 1248 {
1238 .ctl_name = CTL_UNNUMBERED, 1249 .ctl_name = CTL_UNNUMBERED,
1239 .procname = "mmap_min_addr", 1250 .procname = "mmap_min_addr",
@@ -1242,7 +1253,6 @@ static struct ctl_table vm_table[] = {
1242 .mode = 0644, 1253 .mode = 0644,
1243 .proc_handler = &proc_doulongvec_minmax, 1254 .proc_handler = &proc_doulongvec_minmax,
1244 }, 1255 },
1245#endif
1246#ifdef CONFIG_NUMA 1256#ifdef CONFIG_NUMA
1247 { 1257 {
1248 .ctl_name = CTL_UNNUMBERED, 1258 .ctl_name = CTL_UNNUMBERED,
diff --git a/kernel/time/clocksource.c b/kernel/time/clocksource.c
index ecfd7b5187e0..80189f6f1c5a 100644
--- a/kernel/time/clocksource.c
+++ b/kernel/time/clocksource.c
@@ -402,9 +402,6 @@ int clocksource_register(struct clocksource *c)
402 unsigned long flags; 402 unsigned long flags;
403 int ret; 403 int ret;
404 404
405 /* save mult_orig on registration */
406 c->mult_orig = c->mult;
407
408 spin_lock_irqsave(&clocksource_lock, flags); 405 spin_lock_irqsave(&clocksource_lock, flags);
409 ret = clocksource_enqueue(c); 406 ret = clocksource_enqueue(c);
410 if (!ret) 407 if (!ret)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 52a8bf8931f3..e8c77d9c633a 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -77,6 +77,10 @@ static void clocksource_forward_now(void)
77 clock->cycle_last = cycle_now; 77 clock->cycle_last = cycle_now;
78 78
79 nsec = cyc2ns(clock, cycle_delta); 79 nsec = cyc2ns(clock, cycle_delta);
80
81 /* If arch requires, add in gettimeoffset() */
82 nsec += arch_gettimeoffset();
83
80 timespec_add_ns(&xtime, nsec); 84 timespec_add_ns(&xtime, nsec);
81 85
82 nsec = ((s64)cycle_delta * clock->mult_orig) >> clock->shift; 86 nsec = ((s64)cycle_delta * clock->mult_orig) >> clock->shift;
@@ -111,6 +115,9 @@ void getnstimeofday(struct timespec *ts)
111 /* convert to nanoseconds: */ 115 /* convert to nanoseconds: */
112 nsecs = cyc2ns(clock, cycle_delta); 116 nsecs = cyc2ns(clock, cycle_delta);
113 117
118 /* If arch requires, add in gettimeoffset() */
119 nsecs += arch_gettimeoffset();
120
114 } while (read_seqretry(&xtime_lock, seq)); 121 } while (read_seqretry(&xtime_lock, seq));
115 122
116 timespec_add_ns(ts, nsecs); 123 timespec_add_ns(ts, nsecs);
diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
index 7bd6a9893c24..39af8af6fc30 100644
--- a/kernel/trace/blktrace.c
+++ b/kernel/trace/blktrace.c
@@ -669,12 +669,12 @@ static void blk_add_trace_rq(struct request_queue *q, struct request *rq,
669 669
670 if (blk_pc_request(rq)) { 670 if (blk_pc_request(rq)) {
671 what |= BLK_TC_ACT(BLK_TC_PC); 671 what |= BLK_TC_ACT(BLK_TC_PC);
672 __blk_add_trace(bt, 0, rq->data_len, rw, what, rq->errors, 672 __blk_add_trace(bt, 0, blk_rq_bytes(rq), rw,
673 rq->cmd_len, rq->cmd); 673 what, rq->errors, rq->cmd_len, rq->cmd);
674 } else { 674 } else {
675 what |= BLK_TC_ACT(BLK_TC_FS); 675 what |= BLK_TC_ACT(BLK_TC_FS);
676 __blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9, 676 __blk_add_trace(bt, blk_rq_pos(rq), blk_rq_bytes(rq), rw,
677 rw, what, rq->errors, 0, NULL); 677 what, rq->errors, 0, NULL);
678 } 678 }
679} 679}
680 680
@@ -881,11 +881,11 @@ void blk_add_driver_data(struct request_queue *q,
881 return; 881 return;
882 882
883 if (blk_pc_request(rq)) 883 if (blk_pc_request(rq))
884 __blk_add_trace(bt, 0, rq->data_len, 0, BLK_TA_DRV_DATA, 884 __blk_add_trace(bt, 0, blk_rq_bytes(rq), 0,
885 rq->errors, len, data); 885 BLK_TA_DRV_DATA, rq->errors, len, data);
886 else 886 else
887 __blk_add_trace(bt, rq->hard_sector, rq->hard_nr_sectors << 9, 887 __blk_add_trace(bt, blk_rq_pos(rq), blk_rq_bytes(rq), 0,
888 0, BLK_TA_DRV_DATA, rq->errors, len, data); 888 BLK_TA_DRV_DATA, rq->errors, len, data);
889} 889}
890EXPORT_SYMBOL_GPL(blk_add_driver_data); 890EXPORT_SYMBOL_GPL(blk_add_driver_data);
891 891
@@ -1724,10 +1724,7 @@ void blk_fill_rwbs_rq(char *rwbs, struct request *rq)
1724 if (blk_discard_rq(rq)) 1724 if (blk_discard_rq(rq))
1725 rw |= (1 << BIO_RW_DISCARD); 1725 rw |= (1 << BIO_RW_DISCARD);
1726 1726
1727 if (blk_pc_request(rq)) 1727 bytes = blk_rq_bytes(rq);
1728 bytes = rq->data_len;
1729 else
1730 bytes = rq->hard_nr_sectors << 9;
1731 1728
1732 blk_fill_rwbs(rwbs, rw, bytes); 1729 blk_fill_rwbs(rwbs, rw, bytes);
1733} 1730}
diff --git a/lib/Kconfig b/lib/Kconfig
index 8ade0a7a91e0..9960be04cbbe 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -10,6 +10,9 @@ menu "Library routines"
10config BITREVERSE 10config BITREVERSE
11 tristate 11 tristate
12 12
13config RATIONAL
14 boolean
15
13config GENERIC_FIND_FIRST_BIT 16config GENERIC_FIND_FIRST_BIT
14 bool 17 bool
15 18
diff --git a/lib/Makefile b/lib/Makefile
index 33a40e40e3ee..1f6edefebffe 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -50,6 +50,7 @@ ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
50endif 50endif
51 51
52obj-$(CONFIG_BITREVERSE) += bitrev.o 52obj-$(CONFIG_BITREVERSE) += bitrev.o
53obj-$(CONFIG_RATIONAL) += rational.o
53obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o 54obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o
54obj-$(CONFIG_CRC16) += crc16.o 55obj-$(CONFIG_CRC16) += crc16.o
55obj-$(CONFIG_CRC_T10DIF)+= crc-t10dif.o 56obj-$(CONFIG_CRC_T10DIF)+= crc-t10dif.o
diff --git a/lib/rational.c b/lib/rational.c
new file mode 100644
index 000000000000..b3c099b5478e
--- /dev/null
+++ b/lib/rational.c
@@ -0,0 +1,62 @@
1/*
2 * rational fractions
3 *
4 * Copyright (C) 2009 emlix GmbH, Oskar Schirmer <os@emlix.com>
5 *
6 * helper functions when coping with rational numbers
7 */
8
9#include <linux/rational.h>
10
11/*
12 * calculate best rational approximation for a given fraction
13 * taking into account restricted register size, e.g. to find
14 * appropriate values for a pll with 5 bit denominator and
15 * 8 bit numerator register fields, trying to set up with a
16 * frequency ratio of 3.1415, one would say:
17 *
18 * rational_best_approximation(31415, 10000,
19 * (1 << 8) - 1, (1 << 5) - 1, &n, &d);
20 *
21 * you may look at given_numerator as a fixed point number,
22 * with the fractional part size described in given_denominator.
23 *
24 * for theoretical background, see:
25 * http://en.wikipedia.org/wiki/Continued_fraction
26 */
27
28void rational_best_approximation(
29 unsigned long given_numerator, unsigned long given_denominator,
30 unsigned long max_numerator, unsigned long max_denominator,
31 unsigned long *best_numerator, unsigned long *best_denominator)
32{
33 unsigned long n, d, n0, d0, n1, d1;
34 n = given_numerator;
35 d = given_denominator;
36 n0 = d1 = 0;
37 n1 = d0 = 1;
38 for (;;) {
39 unsigned long t, a;
40 if ((n1 > max_numerator) || (d1 > max_denominator)) {
41 n1 = n0;
42 d1 = d0;
43 break;
44 }
45 if (d == 0)
46 break;
47 t = d;
48 a = n / d;
49 d = n % d;
50 n = t;
51 t = n0 + a * n1;
52 n0 = n1;
53 n1 = t;
54 t = d0 + a * d1;
55 d0 = d1;
56 d1 = t;
57 }
58 *best_numerator = n1;
59 *best_denominator = d1;
60}
61
62EXPORT_SYMBOL(rational_best_approximation);
diff --git a/mm/Kconfig b/mm/Kconfig
index c2b57d81e153..71830ba7b986 100644
--- a/mm/Kconfig
+++ b/mm/Kconfig
@@ -226,6 +226,25 @@ config HAVE_MLOCKED_PAGE_BIT
226config MMU_NOTIFIER 226config MMU_NOTIFIER
227 bool 227 bool
228 228
229config DEFAULT_MMAP_MIN_ADDR
230 int "Low address space to protect from user allocation"
231 default 4096
232 help
233 This is the portion of low virtual memory which should be protected
234 from userspace allocation. Keeping a user from writing to low pages
235 can help reduce the impact of kernel NULL pointer bugs.
236
237 For most ia64, ppc64 and x86 users with lots of address space
238 a value of 65536 is reasonable and should cause no problems.
239 On arm and other archs it should not be higher than 32768.
240 Programs which use vm86 functionality would either need additional
241 permissions from either the LSM or the capabilities module or have
242 this protection disabled.
243
244 This value can be changed after boot using the
245 /proc/sys/vm/mmap_min_addr tunable.
246
247
229config NOMMU_INITIAL_TRIM_EXCESS 248config NOMMU_INITIAL_TRIM_EXCESS
230 int "Turn on mmap() excess space trimming before booting" 249 int "Turn on mmap() excess space trimming before booting"
231 depends on !MMU 250 depends on !MMU
diff --git a/mm/bounce.c b/mm/bounce.c
index 65f5e17e411a..4ebe3ea83795 100644
--- a/mm/bounce.c
+++ b/mm/bounce.c
@@ -191,7 +191,7 @@ static void __blk_queue_bounce(struct request_queue *q, struct bio **bio_orig,
191 /* 191 /*
192 * is destination page below bounce pfn? 192 * is destination page below bounce pfn?
193 */ 193 */
194 if (page_to_pfn(page) <= q->bounce_pfn) 194 if (page_to_pfn(page) <= queue_bounce_pfn(q))
195 continue; 195 continue;
196 196
197 /* 197 /*
@@ -283,7 +283,7 @@ void blk_queue_bounce(struct request_queue *q, struct bio **bio_orig)
283 * don't waste time iterating over bio segments 283 * don't waste time iterating over bio segments
284 */ 284 */
285 if (!(q->bounce_gfp & GFP_DMA)) { 285 if (!(q->bounce_gfp & GFP_DMA)) {
286 if (q->bounce_pfn >= blk_max_pfn) 286 if (queue_bounce_pfn(q) >= blk_max_pfn)
287 return; 287 return;
288 pool = page_pool; 288 pool = page_pool;
289 } else { 289 } else {
diff --git a/mm/mmap.c b/mm/mmap.c
index 6b7b1a95944b..2b43fa1aa3c8 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -87,6 +87,9 @@ int sysctl_overcommit_ratio = 50; /* default is 50% */
87int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT; 87int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
88struct percpu_counter vm_committed_as; 88struct percpu_counter vm_committed_as;
89 89
90/* amount of vm to protect from userspace access */
91unsigned long mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
92
90/* 93/*
91 * Check that a process has enough memory to allocate a new virtual 94 * Check that a process has enough memory to allocate a new virtual
92 * mapping. 0 means there is enough memory for the allocation to 95 * mapping. 0 means there is enough memory for the allocation to
diff --git a/mm/nommu.c b/mm/nommu.c
index b571ef707428..2fd2ad5da98e 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -69,6 +69,9 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
69int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS; 69int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
70int heap_stack_gap = 0; 70int heap_stack_gap = 0;
71 71
72/* amount of vm to protect from userspace access */
73unsigned long mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
74
72atomic_long_t mmap_pages_allocated; 75atomic_long_t mmap_pages_allocated;
73 76
74EXPORT_SYMBOL(mem_map); 77EXPORT_SYMBOL(mem_map);
diff --git a/mm/shmem.c b/mm/shmem.c
index b25f95ce3db7..0132fbd45a23 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2659,6 +2659,7 @@ struct file *shmem_file_setup(char *name, loff_t size, unsigned long flags)
2659 if (error) 2659 if (error)
2660 goto close_file; 2660 goto close_file;
2661#endif 2661#endif
2662 ima_counts_get(file);
2662 return file; 2663 return file;
2663 2664
2664close_file: 2665close_file:
@@ -2684,7 +2685,6 @@ int shmem_zero_setup(struct vm_area_struct *vma)
2684 if (IS_ERR(file)) 2685 if (IS_ERR(file))
2685 return PTR_ERR(file); 2686 return PTR_ERR(file);
2686 2687
2687 ima_shm_check(file);
2688 if (vma->vm_file) 2688 if (vma->vm_file)
2689 fput(vma->vm_file); 2689 fput(vma->vm_file);
2690 vma->vm_file = file; 2690 vma->vm_file = file;
diff --git a/security/Kconfig b/security/Kconfig
index bb244774e9d7..d23c839038f0 100644
--- a/security/Kconfig
+++ b/security/Kconfig
@@ -110,28 +110,8 @@ config SECURITY_ROOTPLUG
110 110
111 See <http://www.linuxjournal.com/article.php?sid=6279> for 111 See <http://www.linuxjournal.com/article.php?sid=6279> for
112 more information about this module. 112 more information about this module.
113
114 If you are unsure how to answer this question, answer N.
115
116config SECURITY_DEFAULT_MMAP_MIN_ADDR
117 int "Low address space to protect from user allocation"
118 depends on SECURITY
119 default 0
120 help
121 This is the portion of low virtual memory which should be protected
122 from userspace allocation. Keeping a user from writing to low pages
123 can help reduce the impact of kernel NULL pointer bugs.
124
125 For most ia64, ppc64 and x86 users with lots of address space
126 a value of 65536 is reasonable and should cause no problems.
127 On arm and other archs it should not be higher than 32768.
128 Programs which use vm86 functionality would either need additional
129 permissions from either the LSM or the capabilities module or have
130 this protection disabled.
131
132 This value can be changed after boot using the
133 /proc/sys/vm/mmap_min_addr tunable.
134 113
114 If you are unsure how to answer this question, answer N.
135 115
136source security/selinux/Kconfig 116source security/selinux/Kconfig
137source security/smack/Kconfig 117source security/smack/Kconfig
diff --git a/security/Makefile b/security/Makefile
index fa77021d9778..c67557cdaa85 100644
--- a/security/Makefile
+++ b/security/Makefile
@@ -16,6 +16,9 @@ obj-$(CONFIG_SECURITYFS) += inode.o
16# Must precede capability.o in order to stack properly. 16# Must precede capability.o in order to stack properly.
17obj-$(CONFIG_SECURITY_SELINUX) += selinux/built-in.o 17obj-$(CONFIG_SECURITY_SELINUX) += selinux/built-in.o
18obj-$(CONFIG_SECURITY_SMACK) += smack/built-in.o 18obj-$(CONFIG_SECURITY_SMACK) += smack/built-in.o
19ifeq ($(CONFIG_AUDIT),y)
20obj-$(CONFIG_SECURITY_SMACK) += lsm_audit.o
21endif
19obj-$(CONFIG_SECURITY_TOMOYO) += tomoyo/built-in.o 22obj-$(CONFIG_SECURITY_TOMOYO) += tomoyo/built-in.o
20obj-$(CONFIG_SECURITY_ROOTPLUG) += root_plug.o 23obj-$(CONFIG_SECURITY_ROOTPLUG) += root_plug.o
21obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o 24obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o
diff --git a/security/commoncap.c b/security/commoncap.c
index beac0258c2a8..48b7e0228fa3 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -28,6 +28,28 @@
28#include <linux/prctl.h> 28#include <linux/prctl.h>
29#include <linux/securebits.h> 29#include <linux/securebits.h>
30 30
31/*
32 * If a non-root user executes a setuid-root binary in
33 * !secure(SECURE_NOROOT) mode, then we raise capabilities.
34 * However if fE is also set, then the intent is for only
35 * the file capabilities to be applied, and the setuid-root
36 * bit is left on either to change the uid (plausible) or
37 * to get full privilege on a kernel without file capabilities
38 * support. So in that case we do not raise capabilities.
39 *
40 * Warn if that happens, once per boot.
41 */
42static void warn_setuid_and_fcaps_mixed(char *fname)
43{
44 static int warned;
45 if (!warned) {
46 printk(KERN_INFO "warning: `%s' has both setuid-root and"
47 " effective capabilities. Therefore not raising all"
48 " capabilities.\n", fname);
49 warned = 1;
50 }
51}
52
31int cap_netlink_send(struct sock *sk, struct sk_buff *skb) 53int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
32{ 54{
33 NETLINK_CB(skb).eff_cap = current_cap(); 55 NETLINK_CB(skb).eff_cap = current_cap();
@@ -464,6 +486,15 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)
464 486
465 if (!issecure(SECURE_NOROOT)) { 487 if (!issecure(SECURE_NOROOT)) {
466 /* 488 /*
489 * If the legacy file capability is set, then don't set privs
490 * for a setuid root binary run by a non-root user. Do set it
491 * for a root user just to cause least surprise to an admin.
492 */
493 if (effective && new->uid != 0 && new->euid == 0) {
494 warn_setuid_and_fcaps_mixed(bprm->filename);
495 goto skip;
496 }
497 /*
467 * To support inheritance of root-permissions and suid-root 498 * To support inheritance of root-permissions and suid-root
468 * executables under compatibility mode, we override the 499 * executables under compatibility mode, we override the
469 * capability sets for the file. 500 * capability sets for the file.
@@ -478,6 +509,7 @@ int cap_bprm_set_creds(struct linux_binprm *bprm)
478 if (new->euid == 0) 509 if (new->euid == 0)
479 effective = true; 510 effective = true;
480 } 511 }
512skip:
481 513
482 /* Don't let someone trace a set[ug]id/setpcap binary with the revised 514 /* Don't let someone trace a set[ug]id/setpcap binary with the revised
483 * credentials unless they have the appropriate permit 515 * credentials unless they have the appropriate permit
diff --git a/security/inode.c b/security/inode.c
index f3b91bfbe4cb..f7496c6a022b 100644
--- a/security/inode.c
+++ b/security/inode.c
@@ -287,7 +287,7 @@ void securityfs_remove(struct dentry *dentry)
287{ 287{
288 struct dentry *parent; 288 struct dentry *parent;
289 289
290 if (!dentry) 290 if (!dentry || IS_ERR(dentry))
291 return; 291 return;
292 292
293 parent = dentry->d_parent; 293 parent = dentry->d_parent;
diff --git a/security/integrity/ima/ima_audit.c b/security/integrity/ima/ima_audit.c
index 1e082bb987be..ff513ff737f5 100644
--- a/security/integrity/ima/ima_audit.c
+++ b/security/integrity/ima/ima_audit.c
@@ -22,18 +22,9 @@ static int ima_audit;
22static int __init ima_audit_setup(char *str) 22static int __init ima_audit_setup(char *str)
23{ 23{
24 unsigned long audit; 24 unsigned long audit;
25 int rc, result = 0;
26 char *op = "ima_audit";
27 char *cause;
28 25
29 rc = strict_strtoul(str, 0, &audit); 26 if (!strict_strtoul(str, 0, &audit))
30 if (rc || audit > 1) 27 ima_audit = audit ? 1 : 0;
31 result = 1;
32 else
33 ima_audit = audit;
34 cause = ima_audit ? "enabled" : "not_enabled";
35 integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL, NULL,
36 op, cause, result, 0);
37 return 1; 28 return 1;
38} 29}
39__setup("ima_audit=", ima_audit_setup); 30__setup("ima_audit=", ima_audit_setup);
@@ -50,23 +41,14 @@ void integrity_audit_msg(int audit_msgno, struct inode *inode,
50 41
51 ab = audit_log_start(current->audit_context, GFP_KERNEL, audit_msgno); 42 ab = audit_log_start(current->audit_context, GFP_KERNEL, audit_msgno);
52 audit_log_format(ab, "integrity: pid=%d uid=%u auid=%u ses=%u", 43 audit_log_format(ab, "integrity: pid=%d uid=%u auid=%u ses=%u",
53 current->pid, current->cred->uid, 44 current->pid, current_cred()->uid,
54 audit_get_loginuid(current), 45 audit_get_loginuid(current),
55 audit_get_sessionid(current)); 46 audit_get_sessionid(current));
56 audit_log_task_context(ab); 47 audit_log_task_context(ab);
57 switch (audit_msgno) { 48 audit_log_format(ab, " op=");
58 case AUDIT_INTEGRITY_DATA: 49 audit_log_string(ab, op);
59 case AUDIT_INTEGRITY_METADATA: 50 audit_log_format(ab, " cause=");
60 case AUDIT_INTEGRITY_PCR: 51 audit_log_string(ab, cause);
61 case AUDIT_INTEGRITY_STATUS:
62 audit_log_format(ab, " op=%s cause=%s", op, cause);
63 break;
64 case AUDIT_INTEGRITY_HASH:
65 audit_log_format(ab, " op=%s hash=%s", op, cause);
66 break;
67 default:
68 audit_log_format(ab, " op=%s", op);
69 }
70 audit_log_format(ab, " comm="); 52 audit_log_format(ab, " comm=");
71 audit_log_untrustedstring(ab, current->comm); 53 audit_log_untrustedstring(ab, current->comm);
72 if (fname) { 54 if (fname) {
diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c
index 50d572b74caf..63003a63aaee 100644
--- a/security/integrity/ima/ima_crypto.c
+++ b/security/integrity/ima/ima_crypto.c
@@ -103,7 +103,7 @@ int ima_calc_template_hash(int template_len, void *template, char *digest)
103 return rc; 103 return rc;
104} 104}
105 105
106static void ima_pcrread(int idx, u8 *pcr) 106static void __init ima_pcrread(int idx, u8 *pcr)
107{ 107{
108 if (!ima_used_chip) 108 if (!ima_used_chip)
109 return; 109 return;
@@ -115,7 +115,7 @@ static void ima_pcrread(int idx, u8 *pcr)
115/* 115/*
116 * Calculate the boot aggregate hash 116 * Calculate the boot aggregate hash
117 */ 117 */
118int ima_calc_boot_aggregate(char *digest) 118int __init ima_calc_boot_aggregate(char *digest)
119{ 119{
120 struct hash_desc desc; 120 struct hash_desc desc;
121 struct scatterlist sg; 121 struct scatterlist sg;
diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
index 510186f0b72e..6bfc7eaebfda 100644
--- a/security/integrity/ima/ima_fs.c
+++ b/security/integrity/ima/ima_fs.c
@@ -15,6 +15,7 @@
15 * implemenents security file system for reporting 15 * implemenents security file system for reporting
16 * current measurement list and IMA statistics 16 * current measurement list and IMA statistics
17 */ 17 */
18#include <linux/fcntl.h>
18#include <linux/module.h> 19#include <linux/module.h>
19#include <linux/seq_file.h> 20#include <linux/seq_file.h>
20#include <linux/rculist.h> 21#include <linux/rculist.h>
@@ -283,6 +284,9 @@ static atomic_t policy_opencount = ATOMIC_INIT(1);
283 */ 284 */
284int ima_open_policy(struct inode * inode, struct file * filp) 285int ima_open_policy(struct inode * inode, struct file * filp)
285{ 286{
287 /* No point in being allowed to open it if you aren't going to write */
288 if (!(filp->f_flags & O_WRONLY))
289 return -EACCES;
286 if (atomic_dec_and_test(&policy_opencount)) 290 if (atomic_dec_and_test(&policy_opencount))
287 return 0; 291 return 0;
288 return -EBUSY; 292 return -EBUSY;
@@ -315,7 +319,7 @@ static struct file_operations ima_measure_policy_ops = {
315 .release = ima_release_policy 319 .release = ima_release_policy
316}; 320};
317 321
318int ima_fs_init(void) 322int __init ima_fs_init(void)
319{ 323{
320 ima_dir = securityfs_create_dir("ima", NULL); 324 ima_dir = securityfs_create_dir("ima", NULL);
321 if (IS_ERR(ima_dir)) 325 if (IS_ERR(ima_dir))
@@ -349,7 +353,7 @@ int ima_fs_init(void)
349 goto out; 353 goto out;
350 354
351 ima_policy = securityfs_create_file("policy", 355 ima_policy = securityfs_create_file("policy",
352 S_IRUSR | S_IRGRP | S_IWUSR, 356 S_IWUSR,
353 ima_dir, NULL, 357 ima_dir, NULL,
354 &ima_measure_policy_ops); 358 &ima_measure_policy_ops);
355 if (IS_ERR(ima_policy)) 359 if (IS_ERR(ima_policy))
diff --git a/security/integrity/ima/ima_iint.c b/security/integrity/ima/ima_iint.c
index ec79f1ee992c..b8dd693f8790 100644
--- a/security/integrity/ima/ima_iint.c
+++ b/security/integrity/ima/ima_iint.c
@@ -196,7 +196,7 @@ static void init_once(void *foo)
196 kref_set(&iint->refcount, 1); 196 kref_set(&iint->refcount, 1);
197} 197}
198 198
199void ima_iintcache_init(void) 199void __init ima_iintcache_init(void)
200{ 200{
201 iint_cache = 201 iint_cache =
202 kmem_cache_create("iint_cache", sizeof(struct ima_iint_cache), 0, 202 kmem_cache_create("iint_cache", sizeof(struct ima_iint_cache), 0,
diff --git a/security/integrity/ima/ima_init.c b/security/integrity/ima/ima_init.c
index 0b0bb8c978cc..a40da7ae5900 100644
--- a/security/integrity/ima/ima_init.c
+++ b/security/integrity/ima/ima_init.c
@@ -38,7 +38,7 @@ int ima_used_chip;
38 * a different value.) Violations add a zero entry to the measurement 38 * a different value.) Violations add a zero entry to the measurement
39 * list and extend the aggregate PCR value with ff...ff's. 39 * list and extend the aggregate PCR value with ff...ff's.
40 */ 40 */
41static void ima_add_boot_aggregate(void) 41static void __init ima_add_boot_aggregate(void)
42{ 42{
43 struct ima_template_entry *entry; 43 struct ima_template_entry *entry;
44 const char *op = "add_boot_aggregate"; 44 const char *op = "add_boot_aggregate";
@@ -71,7 +71,7 @@ err_out:
71 audit_cause, result, 0); 71 audit_cause, result, 0);
72} 72}
73 73
74int ima_init(void) 74int __init ima_init(void)
75{ 75{
76 u8 pcr_i[IMA_DIGEST_SIZE]; 76 u8 pcr_i[IMA_DIGEST_SIZE];
77 int rc; 77 int rc;
diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
index f4e7266f5aee..6f611874d10e 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -29,20 +29,8 @@ int ima_initialized;
29char *ima_hash = "sha1"; 29char *ima_hash = "sha1";
30static int __init hash_setup(char *str) 30static int __init hash_setup(char *str)
31{ 31{
32 const char *op = "hash_setup"; 32 if (strncmp(str, "md5", 3) == 0)
33 const char *hash = "sha1"; 33 ima_hash = "md5";
34 int result = 0;
35 int audit_info = 0;
36
37 if (strncmp(str, "md5", 3) == 0) {
38 hash = "md5";
39 ima_hash = str;
40 } else if (strncmp(str, "sha1", 4) != 0) {
41 hash = "invalid_hash_type";
42 result = 1;
43 }
44 integrity_audit_msg(AUDIT_INTEGRITY_HASH, NULL, NULL, op, hash,
45 result, audit_info);
46 return 1; 34 return 1;
47} 35}
48__setup("ima_hash=", hash_setup); 36__setup("ima_hash=", hash_setup);
@@ -128,10 +116,6 @@ static int get_path_measurement(struct ima_iint_cache *iint, struct file *file,
128{ 116{
129 int rc = 0; 117 int rc = 0;
130 118
131 if (IS_ERR(file)) {
132 pr_info("%s dentry_open failed\n", filename);
133 return rc;
134 }
135 iint->opencount++; 119 iint->opencount++;
136 iint->readcount++; 120 iint->readcount++;
137 121
@@ -141,6 +125,15 @@ static int get_path_measurement(struct ima_iint_cache *iint, struct file *file,
141 return rc; 125 return rc;
142} 126}
143 127
128static void ima_update_counts(struct ima_iint_cache *iint, int mask)
129{
130 iint->opencount++;
131 if ((mask & MAY_WRITE) || (mask == 0))
132 iint->writecount++;
133 else if (mask & (MAY_READ | MAY_EXEC))
134 iint->readcount++;
135}
136
144/** 137/**
145 * ima_path_check - based on policy, collect/store measurement. 138 * ima_path_check - based on policy, collect/store measurement.
146 * @path: contains a pointer to the path to be measured 139 * @path: contains a pointer to the path to be measured
@@ -156,10 +149,10 @@ static int get_path_measurement(struct ima_iint_cache *iint, struct file *file,
156 * - Opening a file for read when already open for write, 149 * - Opening a file for read when already open for write,
157 * could result in a file measurement error. 150 * could result in a file measurement error.
158 * 151 *
159 * Return 0 on success, an error code on failure. 152 * Always return 0 and audit dentry_open failures.
160 * (Based on the results of appraise_measurement().) 153 * (Return code will be based upon measurement appraisal.)
161 */ 154 */
162int ima_path_check(struct path *path, int mask) 155int ima_path_check(struct path *path, int mask, int update_counts)
163{ 156{
164 struct inode *inode = path->dentry->d_inode; 157 struct inode *inode = path->dentry->d_inode;
165 struct ima_iint_cache *iint; 158 struct ima_iint_cache *iint;
@@ -173,11 +166,8 @@ int ima_path_check(struct path *path, int mask)
173 return 0; 166 return 0;
174 167
175 mutex_lock(&iint->mutex); 168 mutex_lock(&iint->mutex);
176 iint->opencount++; 169 if (update_counts)
177 if ((mask & MAY_WRITE) || (mask == 0)) 170 ima_update_counts(iint, mask);
178 iint->writecount++;
179 else if (mask & (MAY_READ | MAY_EXEC))
180 iint->readcount++;
181 171
182 rc = ima_must_measure(iint, inode, MAY_READ, PATH_CHECK); 172 rc = ima_must_measure(iint, inode, MAY_READ, PATH_CHECK);
183 if (rc < 0) 173 if (rc < 0)
@@ -196,7 +186,19 @@ int ima_path_check(struct path *path, int mask)
196 struct dentry *dentry = dget(path->dentry); 186 struct dentry *dentry = dget(path->dentry);
197 struct vfsmount *mnt = mntget(path->mnt); 187 struct vfsmount *mnt = mntget(path->mnt);
198 188
199 file = dentry_open(dentry, mnt, O_RDONLY, current->cred); 189 file = dentry_open(dentry, mnt, O_RDONLY | O_LARGEFILE,
190 current_cred());
191 if (IS_ERR(file)) {
192 int audit_info = 0;
193
194 integrity_audit_msg(AUDIT_INTEGRITY_PCR, inode,
195 dentry->d_name.name,
196 "add_measurement",
197 "dentry_open failed",
198 1, audit_info);
199 file = NULL;
200 goto out;
201 }
200 rc = get_path_measurement(iint, file, dentry->d_name.name); 202 rc = get_path_measurement(iint, file, dentry->d_name.name);
201 } 203 }
202out: 204out:
@@ -206,6 +208,7 @@ out:
206 kref_put(&iint->refcount, iint_free); 208 kref_put(&iint->refcount, iint_free);
207 return 0; 209 return 0;
208} 210}
211EXPORT_SYMBOL_GPL(ima_path_check);
209 212
210static int process_measurement(struct file *file, const unsigned char *filename, 213static int process_measurement(struct file *file, const unsigned char *filename,
211 int mask, int function) 214 int mask, int function)
@@ -234,7 +237,16 @@ out:
234 return rc; 237 return rc;
235} 238}
236 239
237static void opencount_get(struct file *file) 240/*
241 * ima_opens_get - increment file counts
242 *
243 * - for IPC shm and shmat file.
244 * - for nfsd exported files.
245 *
246 * Increment the counts for these files to prevent unnecessary
247 * imbalance messages.
248 */
249void ima_counts_get(struct file *file)
238{ 250{
239 struct inode *inode = file->f_dentry->d_inode; 251 struct inode *inode = file->f_dentry->d_inode;
240 struct ima_iint_cache *iint; 252 struct ima_iint_cache *iint;
@@ -246,8 +258,14 @@ static void opencount_get(struct file *file)
246 return; 258 return;
247 mutex_lock(&iint->mutex); 259 mutex_lock(&iint->mutex);
248 iint->opencount++; 260 iint->opencount++;
261 if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
262 iint->readcount++;
263
264 if (file->f_mode & FMODE_WRITE)
265 iint->writecount++;
249 mutex_unlock(&iint->mutex); 266 mutex_unlock(&iint->mutex);
250} 267}
268EXPORT_SYMBOL_GPL(ima_counts_get);
251 269
252/** 270/**
253 * ima_file_mmap - based on policy, collect/store measurement. 271 * ima_file_mmap - based on policy, collect/store measurement.
@@ -272,18 +290,6 @@ int ima_file_mmap(struct file *file, unsigned long prot)
272 return 0; 290 return 0;
273} 291}
274 292
275/*
276 * ima_shm_check - IPC shm and shmat create/fput a file
277 *
278 * Maintain the opencount for these files to prevent unnecessary
279 * imbalance messages.
280 */
281void ima_shm_check(struct file *file)
282{
283 opencount_get(file);
284 return;
285}
286
287/** 293/**
288 * ima_bprm_check - based on policy, collect/store measurement. 294 * ima_bprm_check - based on policy, collect/store measurement.
289 * @bprm: contains the linux_binprm structure 295 * @bprm: contains the linux_binprm structure
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
index b5291ad5ef56..e1278399b345 100644
--- a/security/integrity/ima/ima_policy.c
+++ b/security/integrity/ima/ima_policy.c
@@ -45,24 +45,30 @@ struct ima_measure_rule_entry {
45 } lsm[MAX_LSM_RULES]; 45 } lsm[MAX_LSM_RULES];
46}; 46};
47 47
48/* Without LSM specific knowledge, the default policy can only be 48/*
49 * Without LSM specific knowledge, the default policy can only be
49 * written in terms of .action, .func, .mask, .fsmagic, and .uid 50 * written in terms of .action, .func, .mask, .fsmagic, and .uid
50 */ 51 */
52
53/*
54 * The minimum rule set to allow for full TCB coverage. Measures all files
55 * opened or mmap for exec and everything read by root. Dangerous because
56 * normal users can easily run the machine out of memory simply building
57 * and running executables.
58 */
51static struct ima_measure_rule_entry default_rules[] = { 59static struct ima_measure_rule_entry default_rules[] = {
52 {.action = DONT_MEASURE,.fsmagic = PROC_SUPER_MAGIC, 60 {.action = DONT_MEASURE,.fsmagic = PROC_SUPER_MAGIC,.flags = IMA_FSMAGIC},
53 .flags = IMA_FSMAGIC},
54 {.action = DONT_MEASURE,.fsmagic = SYSFS_MAGIC,.flags = IMA_FSMAGIC}, 61 {.action = DONT_MEASURE,.fsmagic = SYSFS_MAGIC,.flags = IMA_FSMAGIC},
55 {.action = DONT_MEASURE,.fsmagic = DEBUGFS_MAGIC,.flags = IMA_FSMAGIC}, 62 {.action = DONT_MEASURE,.fsmagic = DEBUGFS_MAGIC,.flags = IMA_FSMAGIC},
56 {.action = DONT_MEASURE,.fsmagic = TMPFS_MAGIC,.flags = IMA_FSMAGIC}, 63 {.action = DONT_MEASURE,.fsmagic = TMPFS_MAGIC,.flags = IMA_FSMAGIC},
57 {.action = DONT_MEASURE,.fsmagic = SECURITYFS_MAGIC, 64 {.action = DONT_MEASURE,.fsmagic = SECURITYFS_MAGIC,.flags = IMA_FSMAGIC},
58 .flags = IMA_FSMAGIC}, 65 {.action = DONT_MEASURE,.fsmagic = SELINUX_MAGIC,.flags = IMA_FSMAGIC},
59 {.action = DONT_MEASURE,.fsmagic = 0xF97CFF8C,.flags = IMA_FSMAGIC},
60 {.action = MEASURE,.func = FILE_MMAP,.mask = MAY_EXEC, 66 {.action = MEASURE,.func = FILE_MMAP,.mask = MAY_EXEC,
61 .flags = IMA_FUNC | IMA_MASK}, 67 .flags = IMA_FUNC | IMA_MASK},
62 {.action = MEASURE,.func = BPRM_CHECK,.mask = MAY_EXEC, 68 {.action = MEASURE,.func = BPRM_CHECK,.mask = MAY_EXEC,
63 .flags = IMA_FUNC | IMA_MASK}, 69 .flags = IMA_FUNC | IMA_MASK},
64 {.action = MEASURE,.func = PATH_CHECK,.mask = MAY_READ,.uid = 0, 70 {.action = MEASURE,.func = PATH_CHECK,.mask = MAY_READ,.uid = 0,
65 .flags = IMA_FUNC | IMA_MASK | IMA_UID} 71 .flags = IMA_FUNC | IMA_MASK | IMA_UID},
66}; 72};
67 73
68static LIST_HEAD(measure_default_rules); 74static LIST_HEAD(measure_default_rules);
@@ -71,6 +77,14 @@ static struct list_head *ima_measure;
71 77
72static DEFINE_MUTEX(ima_measure_mutex); 78static DEFINE_MUTEX(ima_measure_mutex);
73 79
80static bool ima_use_tcb __initdata;
81static int __init default_policy_setup(char *str)
82{
83 ima_use_tcb = 1;
84 return 1;
85}
86__setup("ima_tcb", default_policy_setup);
87
74/** 88/**
75 * ima_match_rules - determine whether an inode matches the measure rule. 89 * ima_match_rules - determine whether an inode matches the measure rule.
76 * @rule: a pointer to a rule 90 * @rule: a pointer to a rule
@@ -96,7 +110,7 @@ static bool ima_match_rules(struct ima_measure_rule_entry *rule,
96 if ((rule->flags & IMA_UID) && rule->uid != tsk->cred->uid) 110 if ((rule->flags & IMA_UID) && rule->uid != tsk->cred->uid)
97 return false; 111 return false;
98 for (i = 0; i < MAX_LSM_RULES; i++) { 112 for (i = 0; i < MAX_LSM_RULES; i++) {
99 int rc; 113 int rc = 0;
100 u32 osid, sid; 114 u32 osid, sid;
101 115
102 if (!rule->lsm[i].rule) 116 if (!rule->lsm[i].rule)
@@ -109,7 +123,7 @@ static bool ima_match_rules(struct ima_measure_rule_entry *rule,
109 security_inode_getsecid(inode, &osid); 123 security_inode_getsecid(inode, &osid);
110 rc = security_filter_rule_match(osid, 124 rc = security_filter_rule_match(osid,
111 rule->lsm[i].type, 125 rule->lsm[i].type,
112 AUDIT_EQUAL, 126 Audit_equal,
113 rule->lsm[i].rule, 127 rule->lsm[i].rule,
114 NULL); 128 NULL);
115 break; 129 break;
@@ -119,7 +133,7 @@ static bool ima_match_rules(struct ima_measure_rule_entry *rule,
119 security_task_getsecid(tsk, &sid); 133 security_task_getsecid(tsk, &sid);
120 rc = security_filter_rule_match(sid, 134 rc = security_filter_rule_match(sid,
121 rule->lsm[i].type, 135 rule->lsm[i].type,
122 AUDIT_EQUAL, 136 Audit_equal,
123 rule->lsm[i].rule, 137 rule->lsm[i].rule,
124 NULL); 138 NULL);
125 default: 139 default:
@@ -164,11 +178,17 @@ int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask)
164 * ima_measure points to either the measure_default_rules or the 178 * ima_measure points to either the measure_default_rules or the
165 * the new measure_policy_rules. 179 * the new measure_policy_rules.
166 */ 180 */
167void ima_init_policy(void) 181void __init ima_init_policy(void)
168{ 182{
169 int i; 183 int i, entries;
184
185 /* if !ima_use_tcb set entries = 0 so we load NO default rules */
186 if (ima_use_tcb)
187 entries = ARRAY_SIZE(default_rules);
188 else
189 entries = 0;
170 190
171 for (i = 0; i < ARRAY_SIZE(default_rules); i++) 191 for (i = 0; i < entries; i++)
172 list_add_tail(&default_rules[i].list, &measure_default_rules); 192 list_add_tail(&default_rules[i].list, &measure_default_rules);
173 ima_measure = &measure_default_rules; 193 ima_measure = &measure_default_rules;
174} 194}
@@ -227,7 +247,7 @@ static int ima_lsm_rule_init(struct ima_measure_rule_entry *entry,
227 247
228 entry->lsm[lsm_rule].type = audit_type; 248 entry->lsm[lsm_rule].type = audit_type;
229 result = security_filter_rule_init(entry->lsm[lsm_rule].type, 249 result = security_filter_rule_init(entry->lsm[lsm_rule].type,
230 AUDIT_EQUAL, args, 250 Audit_equal, args,
231 &entry->lsm[lsm_rule].rule); 251 &entry->lsm[lsm_rule].rule);
232 return result; 252 return result;
233} 253}
diff --git a/security/lsm_audit.c b/security/lsm_audit.c
new file mode 100644
index 000000000000..94b868494b31
--- /dev/null
+++ b/security/lsm_audit.c
@@ -0,0 +1,386 @@
1/*
2 * common LSM auditing functions
3 *
4 * Based on code written for SELinux by :
5 * Stephen Smalley, <sds@epoch.ncsc.mil>
6 * James Morris <jmorris@redhat.com>
7 * Author : Etienne Basset, <etienne.basset@ensta.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2,
11 * as published by the Free Software Foundation.
12 */
13
14#include <linux/types.h>
15#include <linux/stddef.h>
16#include <linux/kernel.h>
17#include <linux/fs.h>
18#include <linux/init.h>
19#include <net/sock.h>
20#include <linux/un.h>
21#include <net/af_unix.h>
22#include <linux/audit.h>
23#include <linux/ipv6.h>
24#include <linux/ip.h>
25#include <net/ip.h>
26#include <net/ipv6.h>
27#include <linux/tcp.h>
28#include <linux/udp.h>
29#include <linux/dccp.h>
30#include <linux/sctp.h>
31#include <linux/lsm_audit.h>
32
33/**
34 * ipv4_skb_to_auditdata : fill auditdata from skb
35 * @skb : the skb
36 * @ad : the audit data to fill
37 * @proto : the layer 4 protocol
38 *
39 * return 0 on success
40 */
41int ipv4_skb_to_auditdata(struct sk_buff *skb,
42 struct common_audit_data *ad, u8 *proto)
43{
44 int ret = 0;
45 struct iphdr *ih;
46
47 ih = ip_hdr(skb);
48 if (ih == NULL)
49 return -EINVAL;
50
51 ad->u.net.v4info.saddr = ih->saddr;
52 ad->u.net.v4info.daddr = ih->daddr;
53
54 if (proto)
55 *proto = ih->protocol;
56 /* non initial fragment */
57 if (ntohs(ih->frag_off) & IP_OFFSET)
58 return 0;
59
60 switch (ih->protocol) {
61 case IPPROTO_TCP: {
62 struct tcphdr *th = tcp_hdr(skb);
63 if (th == NULL)
64 break;
65
66 ad->u.net.sport = th->source;
67 ad->u.net.dport = th->dest;
68 break;
69 }
70 case IPPROTO_UDP: {
71 struct udphdr *uh = udp_hdr(skb);
72 if (uh == NULL)
73 break;
74
75 ad->u.net.sport = uh->source;
76 ad->u.net.dport = uh->dest;
77 break;
78 }
79 case IPPROTO_DCCP: {
80 struct dccp_hdr *dh = dccp_hdr(skb);
81 if (dh == NULL)
82 break;
83
84 ad->u.net.sport = dh->dccph_sport;
85 ad->u.net.dport = dh->dccph_dport;
86 break;
87 }
88 case IPPROTO_SCTP: {
89 struct sctphdr *sh = sctp_hdr(skb);
90 if (sh == NULL)
91 break;
92 ad->u.net.sport = sh->source;
93 ad->u.net.dport = sh->dest;
94 break;
95 }
96 default:
97 ret = -EINVAL;
98 }
99 return ret;
100}
101#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
102/**
103 * ipv6_skb_to_auditdata : fill auditdata from skb
104 * @skb : the skb
105 * @ad : the audit data to fill
106 * @proto : the layer 4 protocol
107 *
108 * return 0 on success
109 */
110int ipv6_skb_to_auditdata(struct sk_buff *skb,
111 struct common_audit_data *ad, u8 *proto)
112{
113 int offset, ret = 0;
114 struct ipv6hdr *ip6;
115 u8 nexthdr;
116
117 ip6 = ipv6_hdr(skb);
118 if (ip6 == NULL)
119 return -EINVAL;
120 ipv6_addr_copy(&ad->u.net.v6info.saddr, &ip6->saddr);
121 ipv6_addr_copy(&ad->u.net.v6info.daddr, &ip6->daddr);
122 ret = 0;
123 /* IPv6 can have several extension header before the Transport header
124 * skip them */
125 offset = skb_network_offset(skb);
126 offset += sizeof(*ip6);
127 nexthdr = ip6->nexthdr;
128 offset = ipv6_skip_exthdr(skb, offset, &nexthdr);
129 if (offset < 0)
130 return 0;
131 if (proto)
132 *proto = nexthdr;
133 switch (nexthdr) {
134 case IPPROTO_TCP: {
135 struct tcphdr _tcph, *th;
136
137 th = skb_header_pointer(skb, offset, sizeof(_tcph), &_tcph);
138 if (th == NULL)
139 break;
140
141 ad->u.net.sport = th->source;
142 ad->u.net.dport = th->dest;
143 break;
144 }
145 case IPPROTO_UDP: {
146 struct udphdr _udph, *uh;
147
148 uh = skb_header_pointer(skb, offset, sizeof(_udph), &_udph);
149 if (uh == NULL)
150 break;
151
152 ad->u.net.sport = uh->source;
153 ad->u.net.dport = uh->dest;
154 break;
155 }
156 case IPPROTO_DCCP: {
157 struct dccp_hdr _dccph, *dh;
158
159 dh = skb_header_pointer(skb, offset, sizeof(_dccph), &_dccph);
160 if (dh == NULL)
161 break;
162
163 ad->u.net.sport = dh->dccph_sport;
164 ad->u.net.dport = dh->dccph_dport;
165 break;
166 }
167 case IPPROTO_SCTP: {
168 struct sctphdr _sctph, *sh;
169
170 sh = skb_header_pointer(skb, offset, sizeof(_sctph), &_sctph);
171 if (sh == NULL)
172 break;
173 ad->u.net.sport = sh->source;
174 ad->u.net.dport = sh->dest;
175 break;
176 }
177 default:
178 ret = -EINVAL;
179 }
180 return ret;
181}
182#endif
183
184
185static inline void print_ipv6_addr(struct audit_buffer *ab,
186 struct in6_addr *addr, __be16 port,
187 char *name1, char *name2)
188{
189 if (!ipv6_addr_any(addr))
190 audit_log_format(ab, " %s=%pI6", name1, addr);
191 if (port)
192 audit_log_format(ab, " %s=%d", name2, ntohs(port));
193}
194
195static inline void print_ipv4_addr(struct audit_buffer *ab, __be32 addr,
196 __be16 port, char *name1, char *name2)
197{
198 if (addr)
199 audit_log_format(ab, " %s=%pI4", name1, &addr);
200 if (port)
201 audit_log_format(ab, " %s=%d", name2, ntohs(port));
202}
203
204/**
205 * dump_common_audit_data - helper to dump common audit data
206 * @a : common audit data
207 *
208 */
209static void dump_common_audit_data(struct audit_buffer *ab,
210 struct common_audit_data *a)
211{
212 struct inode *inode = NULL;
213 struct task_struct *tsk = current;
214
215 if (a->tsk)
216 tsk = a->tsk;
217 if (tsk && tsk->pid) {
218 audit_log_format(ab, " pid=%d comm=", tsk->pid);
219 audit_log_untrustedstring(ab, tsk->comm);
220 }
221
222 switch (a->type) {
223 case LSM_AUDIT_DATA_IPC:
224 audit_log_format(ab, " key=%d ", a->u.ipc_id);
225 break;
226 case LSM_AUDIT_DATA_CAP:
227 audit_log_format(ab, " capability=%d ", a->u.cap);
228 break;
229 case LSM_AUDIT_DATA_FS:
230 if (a->u.fs.path.dentry) {
231 struct dentry *dentry = a->u.fs.path.dentry;
232 if (a->u.fs.path.mnt) {
233 audit_log_d_path(ab, "path=", &a->u.fs.path);
234 } else {
235 audit_log_format(ab, " name=");
236 audit_log_untrustedstring(ab,
237 dentry->d_name.name);
238 }
239 inode = dentry->d_inode;
240 } else if (a->u.fs.inode) {
241 struct dentry *dentry;
242 inode = a->u.fs.inode;
243 dentry = d_find_alias(inode);
244 if (dentry) {
245 audit_log_format(ab, " name=");
246 audit_log_untrustedstring(ab,
247 dentry->d_name.name);
248 dput(dentry);
249 }
250 }
251 if (inode)
252 audit_log_format(ab, " dev=%s ino=%lu",
253 inode->i_sb->s_id,
254 inode->i_ino);
255 break;
256 case LSM_AUDIT_DATA_TASK:
257 tsk = a->u.tsk;
258 if (tsk && tsk->pid) {
259 audit_log_format(ab, " pid=%d comm=", tsk->pid);
260 audit_log_untrustedstring(ab, tsk->comm);
261 }
262 break;
263 case LSM_AUDIT_DATA_NET:
264 if (a->u.net.sk) {
265 struct sock *sk = a->u.net.sk;
266 struct unix_sock *u;
267 int len = 0;
268 char *p = NULL;
269
270 switch (sk->sk_family) {
271 case AF_INET: {
272 struct inet_sock *inet = inet_sk(sk);
273
274 print_ipv4_addr(ab, inet->rcv_saddr,
275 inet->sport,
276 "laddr", "lport");
277 print_ipv4_addr(ab, inet->daddr,
278 inet->dport,
279 "faddr", "fport");
280 break;
281 }
282 case AF_INET6: {
283 struct inet_sock *inet = inet_sk(sk);
284 struct ipv6_pinfo *inet6 = inet6_sk(sk);
285
286 print_ipv6_addr(ab, &inet6->rcv_saddr,
287 inet->sport,
288 "laddr", "lport");
289 print_ipv6_addr(ab, &inet6->daddr,
290 inet->dport,
291 "faddr", "fport");
292 break;
293 }
294 case AF_UNIX:
295 u = unix_sk(sk);
296 if (u->dentry) {
297 struct path path = {
298 .dentry = u->dentry,
299 .mnt = u->mnt
300 };
301 audit_log_d_path(ab, "path=", &path);
302 break;
303 }
304 if (!u->addr)
305 break;
306 len = u->addr->len-sizeof(short);
307 p = &u->addr->name->sun_path[0];
308 audit_log_format(ab, " path=");
309 if (*p)
310 audit_log_untrustedstring(ab, p);
311 else
312 audit_log_n_hex(ab, p, len);
313 break;
314 }
315 }
316
317 switch (a->u.net.family) {
318 case AF_INET:
319 print_ipv4_addr(ab, a->u.net.v4info.saddr,
320 a->u.net.sport,
321 "saddr", "src");
322 print_ipv4_addr(ab, a->u.net.v4info.daddr,
323 a->u.net.dport,
324 "daddr", "dest");
325 break;
326 case AF_INET6:
327 print_ipv6_addr(ab, &a->u.net.v6info.saddr,
328 a->u.net.sport,
329 "saddr", "src");
330 print_ipv6_addr(ab, &a->u.net.v6info.daddr,
331 a->u.net.dport,
332 "daddr", "dest");
333 break;
334 }
335 if (a->u.net.netif > 0) {
336 struct net_device *dev;
337
338 /* NOTE: we always use init's namespace */
339 dev = dev_get_by_index(&init_net, a->u.net.netif);
340 if (dev) {
341 audit_log_format(ab, " netif=%s", dev->name);
342 dev_put(dev);
343 }
344 }
345 break;
346#ifdef CONFIG_KEYS
347 case LSM_AUDIT_DATA_KEY:
348 audit_log_format(ab, " key_serial=%u", a->u.key_struct.key);
349 if (a->u.key_struct.key_desc) {
350 audit_log_format(ab, " key_desc=");
351 audit_log_untrustedstring(ab, a->u.key_struct.key_desc);
352 }
353 break;
354#endif
355 } /* switch (a->type) */
356}
357
358/**
359 * common_lsm_audit - generic LSM auditing function
360 * @a: auxiliary audit data
361 *
362 * setup the audit buffer for common security information
363 * uses callback to print LSM specific information
364 */
365void common_lsm_audit(struct common_audit_data *a)
366{
367 struct audit_buffer *ab;
368
369 if (a == NULL)
370 return;
371 /* we use GFP_ATOMIC so we won't sleep */
372 ab = audit_log_start(current->audit_context, GFP_ATOMIC, AUDIT_AVC);
373
374 if (ab == NULL)
375 return;
376
377 if (a->lsm_pre_audit)
378 a->lsm_pre_audit(ab, a);
379
380 dump_common_audit_data(ab, a);
381
382 if (a->lsm_post_audit)
383 a->lsm_post_audit(ab, a);
384
385 audit_log_end(ab);
386}
diff --git a/security/root_plug.c b/security/root_plug.c
index 40fb4f15e27b..2f7ffa67c4d2 100644
--- a/security/root_plug.c
+++ b/security/root_plug.c
@@ -71,18 +71,6 @@ static int rootplug_bprm_check_security (struct linux_binprm *bprm)
71} 71}
72 72
73static struct security_operations rootplug_security_ops = { 73static struct security_operations rootplug_security_ops = {
74 /* Use the capability functions for some of the hooks */
75 .ptrace_may_access = cap_ptrace_may_access,
76 .ptrace_traceme = cap_ptrace_traceme,
77 .capget = cap_capget,
78 .capset = cap_capset,
79 .capable = cap_capable,
80
81 .bprm_set_creds = cap_bprm_set_creds,
82
83 .task_fix_setuid = cap_task_fix_setuid,
84 .task_prctl = cap_task_prctl,
85
86 .bprm_check_security = rootplug_bprm_check_security, 74 .bprm_check_security = rootplug_bprm_check_security,
87}; 75};
88 76
diff --git a/security/security.c b/security/security.c
index 5284255c5cdf..dc7674fbfc7a 100644
--- a/security/security.c
+++ b/security/security.c
@@ -26,9 +26,6 @@ extern void security_fixup_ops(struct security_operations *ops);
26 26
27struct security_operations *security_ops; /* Initialized to NULL */ 27struct security_operations *security_ops; /* Initialized to NULL */
28 28
29/* amount of vm to protect from userspace access */
30unsigned long mmap_min_addr = CONFIG_SECURITY_DEFAULT_MMAP_MIN_ADDR;
31
32static inline int verify(struct security_operations *ops) 29static inline int verify(struct security_operations *ops)
33{ 30{
34 /* verify the security_operations structure exists */ 31 /* verify the security_operations structure exists */
diff --git a/security/selinux/avc.c b/security/selinux/avc.c
index 7f9b5fac8779..b2ab60859832 100644
--- a/security/selinux/avc.c
+++ b/security/selinux/avc.c
@@ -927,7 +927,7 @@ int avc_has_perm_noaudit(u32 ssid, u32 tsid,
927 if (denied) { 927 if (denied) {
928 if (flags & AVC_STRICT) 928 if (flags & AVC_STRICT)
929 rc = -EACCES; 929 rc = -EACCES;
930 else if (!selinux_enforcing || security_permissive_sid(ssid)) 930 else if (!selinux_enforcing || (avd->flags & AVD_FLAGS_PERMISSIVE))
931 avc_update_node(AVC_CALLBACK_GRANT, requested, ssid, 931 avc_update_node(AVC_CALLBACK_GRANT, requested, ssid,
932 tsid, tclass, avd->seqno); 932 tsid, tclass, avd->seqno);
933 else 933 else
diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 2fcad7c33eaf..195906bce266 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -1980,10 +1980,6 @@ static int selinux_sysctl(ctl_table *table, int op)
1980 u32 tsid, sid; 1980 u32 tsid, sid;
1981 int rc; 1981 int rc;
1982 1982
1983 rc = secondary_ops->sysctl(table, op);
1984 if (rc)
1985 return rc;
1986
1987 sid = current_sid(); 1983 sid = current_sid();
1988 1984
1989 rc = selinux_sysctl_get_sid(table, (op == 0001) ? 1985 rc = selinux_sysctl_get_sid(table, (op == 0001) ?
@@ -2375,10 +2371,8 @@ static void selinux_bprm_committed_creds(struct linux_binprm *bprm)
2375{ 2371{
2376 const struct task_security_struct *tsec = current_security(); 2372 const struct task_security_struct *tsec = current_security();
2377 struct itimerval itimer; 2373 struct itimerval itimer;
2378 struct sighand_struct *psig;
2379 u32 osid, sid; 2374 u32 osid, sid;
2380 int rc, i; 2375 int rc, i;
2381 unsigned long flags;
2382 2376
2383 osid = tsec->osid; 2377 osid = tsec->osid;
2384 sid = tsec->sid; 2378 sid = tsec->sid;
@@ -2398,22 +2392,20 @@ static void selinux_bprm_committed_creds(struct linux_binprm *bprm)
2398 memset(&itimer, 0, sizeof itimer); 2392 memset(&itimer, 0, sizeof itimer);
2399 for (i = 0; i < 3; i++) 2393 for (i = 0; i < 3; i++)
2400 do_setitimer(i, &itimer, NULL); 2394 do_setitimer(i, &itimer, NULL);
2401 flush_signals(current);
2402 spin_lock_irq(&current->sighand->siglock); 2395 spin_lock_irq(&current->sighand->siglock);
2403 flush_signal_handlers(current, 1); 2396 if (!(current->signal->flags & SIGNAL_GROUP_EXIT)) {
2404 sigemptyset(&current->blocked); 2397 __flush_signals(current);
2405 recalc_sigpending(); 2398 flush_signal_handlers(current, 1);
2399 sigemptyset(&current->blocked);
2400 }
2406 spin_unlock_irq(&current->sighand->siglock); 2401 spin_unlock_irq(&current->sighand->siglock);
2407 } 2402 }
2408 2403
2409 /* Wake up the parent if it is waiting so that it can recheck 2404 /* Wake up the parent if it is waiting so that it can recheck
2410 * wait permission to the new task SID. */ 2405 * wait permission to the new task SID. */
2411 read_lock_irq(&tasklist_lock); 2406 read_lock(&tasklist_lock);
2412 psig = current->parent->sighand; 2407 wake_up_interruptible(&current->real_parent->signal->wait_chldexit);
2413 spin_lock_irqsave(&psig->siglock, flags); 2408 read_unlock(&tasklist_lock);
2414 wake_up_interruptible(&current->parent->signal->wait_chldexit);
2415 spin_unlock_irqrestore(&psig->siglock, flags);
2416 read_unlock_irq(&tasklist_lock);
2417} 2409}
2418 2410
2419/* superblock security operations */ 2411/* superblock security operations */
diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h
index 5c3434f7626f..ca835795a8b3 100644
--- a/security/selinux/include/security.h
+++ b/security/selinux/include/security.h
@@ -8,14 +8,13 @@
8#ifndef _SELINUX_SECURITY_H_ 8#ifndef _SELINUX_SECURITY_H_
9#define _SELINUX_SECURITY_H_ 9#define _SELINUX_SECURITY_H_
10 10
11#include <linux/magic.h>
11#include "flask.h" 12#include "flask.h"
12 13
13#define SECSID_NULL 0x00000000 /* unspecified SID */ 14#define SECSID_NULL 0x00000000 /* unspecified SID */
14#define SECSID_WILD 0xffffffff /* wildcard SID */ 15#define SECSID_WILD 0xffffffff /* wildcard SID */
15#define SECCLASS_NULL 0x0000 /* no class */ 16#define SECCLASS_NULL 0x0000 /* no class */
16 17
17#define SELINUX_MAGIC 0xf97cff8c
18
19/* Identify specific policy version changes */ 18/* Identify specific policy version changes */
20#define POLICYDB_VERSION_BASE 15 19#define POLICYDB_VERSION_BASE 15
21#define POLICYDB_VERSION_BOOL 16 20#define POLICYDB_VERSION_BOOL 16
@@ -91,9 +90,11 @@ struct av_decision {
91 u32 auditallow; 90 u32 auditallow;
92 u32 auditdeny; 91 u32 auditdeny;
93 u32 seqno; 92 u32 seqno;
93 u32 flags;
94}; 94};
95 95
96int security_permissive_sid(u32 sid); 96/* definitions of av_decision.flags */
97#define AVD_FLAGS_PERMISSIVE 0x0001
97 98
98int security_compute_av(u32 ssid, u32 tsid, 99int security_compute_av(u32 ssid, u32 tsid,
99 u16 tclass, u32 requested, 100 u16 tclass, u32 requested,
diff --git a/security/selinux/nlmsgtab.c b/security/selinux/nlmsgtab.c
index c6875fd3b9d6..dd7cc6de77f9 100644
--- a/security/selinux/nlmsgtab.c
+++ b/security/selinux/nlmsgtab.c
@@ -112,6 +112,8 @@ static struct nlmsg_perm nlmsg_audit_perms[] =
112 { AUDIT_DEL_RULE, NETLINK_AUDIT_SOCKET__NLMSG_WRITE }, 112 { AUDIT_DEL_RULE, NETLINK_AUDIT_SOCKET__NLMSG_WRITE },
113 { AUDIT_USER, NETLINK_AUDIT_SOCKET__NLMSG_RELAY }, 113 { AUDIT_USER, NETLINK_AUDIT_SOCKET__NLMSG_RELAY },
114 { AUDIT_SIGNAL_INFO, NETLINK_AUDIT_SOCKET__NLMSG_READ }, 114 { AUDIT_SIGNAL_INFO, NETLINK_AUDIT_SOCKET__NLMSG_READ },
115 { AUDIT_TRIM, NETLINK_AUDIT_SOCKET__NLMSG_WRITE },
116 { AUDIT_MAKE_EQUIV, NETLINK_AUDIT_SOCKET__NLMSG_WRITE },
115 { AUDIT_TTY_GET, NETLINK_AUDIT_SOCKET__NLMSG_READ }, 117 { AUDIT_TTY_GET, NETLINK_AUDIT_SOCKET__NLMSG_READ },
116 { AUDIT_TTY_SET, NETLINK_AUDIT_SOCKET__NLMSG_TTY_AUDIT }, 118 { AUDIT_TTY_SET, NETLINK_AUDIT_SOCKET__NLMSG_TTY_AUDIT },
117}; 119};
diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index 2d5136ec3d54..b4fc506e7a87 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -527,10 +527,10 @@ static ssize_t sel_write_access(struct file *file, char *buf, size_t size)
527 goto out2; 527 goto out2;
528 528
529 length = scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, 529 length = scnprintf(buf, SIMPLE_TRANSACTION_LIMIT,
530 "%x %x %x %x %u", 530 "%x %x %x %x %u %x",
531 avd.allowed, 0xffffffff, 531 avd.allowed, 0xffffffff,
532 avd.auditallow, avd.auditdeny, 532 avd.auditallow, avd.auditdeny,
533 avd.seqno); 533 avd.seqno, avd.flags);
534out2: 534out2:
535 kfree(tcon); 535 kfree(tcon);
536out: 536out:
@@ -803,10 +803,6 @@ static ssize_t sel_read_bool(struct file *filep, char __user *buf,
803 goto out; 803 goto out;
804 } 804 }
805 805
806 if (count > PAGE_SIZE) {
807 ret = -EINVAL;
808 goto out;
809 }
810 page = (char *)get_zeroed_page(GFP_KERNEL); 806 page = (char *)get_zeroed_page(GFP_KERNEL);
811 if (!page) { 807 if (!page) {
812 ret = -ENOMEM; 808 ret = -ENOMEM;
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index deeec6c013ae..500e6f78e115 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -410,6 +410,7 @@ static int context_struct_compute_av(struct context *scontext,
410 avd->auditallow = 0; 410 avd->auditallow = 0;
411 avd->auditdeny = 0xffffffff; 411 avd->auditdeny = 0xffffffff;
412 avd->seqno = latest_granting; 412 avd->seqno = latest_granting;
413 avd->flags = 0;
413 414
414 /* 415 /*
415 * Check for all the invalid cases. 416 * Check for all the invalid cases.
@@ -528,31 +529,6 @@ inval_class:
528 return 0; 529 return 0;
529} 530}
530 531
531/*
532 * Given a sid find if the type has the permissive flag set
533 */
534int security_permissive_sid(u32 sid)
535{
536 struct context *context;
537 u32 type;
538 int rc;
539
540 read_lock(&policy_rwlock);
541
542 context = sidtab_search(&sidtab, sid);
543 BUG_ON(!context);
544
545 type = context->type;
546 /*
547 * we are intentionally using type here, not type-1, the 0th bit may
548 * someday indicate that we are globally setting permissive in policy.
549 */
550 rc = ebitmap_get_bit(&policydb.permissive_map, type);
551
552 read_unlock(&policy_rwlock);
553 return rc;
554}
555
556static int security_validtrans_handle_fail(struct context *ocontext, 532static int security_validtrans_handle_fail(struct context *ocontext,
557 struct context *ncontext, 533 struct context *ncontext,
558 struct context *tcontext, 534 struct context *tcontext,
@@ -767,6 +743,10 @@ int security_compute_av(u32 ssid,
767 743
768 rc = context_struct_compute_av(scontext, tcontext, tclass, 744 rc = context_struct_compute_av(scontext, tcontext, tclass,
769 requested, avd); 745 requested, avd);
746
747 /* permissive domain? */
748 if (ebitmap_get_bit(&policydb.permissive_map, scontext->type))
749 avd->flags |= AVD_FLAGS_PERMISSIVE;
770out: 750out:
771 read_unlock(&policy_rwlock); 751 read_unlock(&policy_rwlock);
772 return rc; 752 return rc;
diff --git a/security/smack/smack.h b/security/smack/smack.h
index 42ef313f9856..243bec175be0 100644
--- a/security/smack/smack.h
+++ b/security/smack/smack.h
@@ -20,6 +20,7 @@
20#include <net/netlabel.h> 20#include <net/netlabel.h>
21#include <linux/list.h> 21#include <linux/list.h>
22#include <linux/rculist.h> 22#include <linux/rculist.h>
23#include <linux/lsm_audit.h>
23 24
24/* 25/*
25 * Why 23? CIPSO is constrained to 30, so a 32 byte buffer is 26 * Why 23? CIPSO is constrained to 30, so a 32 byte buffer is
@@ -179,6 +180,20 @@ struct smack_known {
179#define MAY_NOT 0 180#define MAY_NOT 0
180 181
181/* 182/*
183 * Number of access types used by Smack (rwxa)
184 */
185#define SMK_NUM_ACCESS_TYPE 4
186
187/*
188 * Smack audit data; is empty if CONFIG_AUDIT not set
189 * to save some stack
190 */
191struct smk_audit_info {
192#ifdef CONFIG_AUDIT
193 struct common_audit_data a;
194#endif
195};
196/*
182 * These functions are in smack_lsm.c 197 * These functions are in smack_lsm.c
183 */ 198 */
184struct inode_smack *new_inode_smack(char *); 199struct inode_smack *new_inode_smack(char *);
@@ -186,8 +201,8 @@ struct inode_smack *new_inode_smack(char *);
186/* 201/*
187 * These functions are in smack_access.c 202 * These functions are in smack_access.c
188 */ 203 */
189int smk_access(char *, char *, int); 204int smk_access(char *, char *, int, struct smk_audit_info *);
190int smk_curacc(char *, u32); 205int smk_curacc(char *, u32, struct smk_audit_info *);
191int smack_to_cipso(const char *, struct smack_cipso *); 206int smack_to_cipso(const char *, struct smack_cipso *);
192void smack_from_cipso(u32, char *, char *); 207void smack_from_cipso(u32, char *, char *);
193char *smack_from_secid(const u32); 208char *smack_from_secid(const u32);
@@ -237,4 +252,93 @@ static inline char *smk_of_inode(const struct inode *isp)
237 return sip->smk_inode; 252 return sip->smk_inode;
238} 253}
239 254
255/*
256 * logging functions
257 */
258#define SMACK_AUDIT_DENIED 0x1
259#define SMACK_AUDIT_ACCEPT 0x2
260extern int log_policy;
261
262void smack_log(char *subject_label, char *object_label,
263 int request,
264 int result, struct smk_audit_info *auditdata);
265
266#ifdef CONFIG_AUDIT
267
268/*
269 * some inline functions to set up audit data
270 * they do nothing if CONFIG_AUDIT is not set
271 *
272 */
273static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
274 char type)
275{
276 memset(a, 0, sizeof(*a));
277 a->a.type = type;
278 a->a.function = func;
279}
280
281static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
282 struct task_struct *t)
283{
284 a->a.u.tsk = t;
285}
286static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
287 struct dentry *d)
288{
289 a->a.u.fs.path.dentry = d;
290}
291static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
292 struct vfsmount *m)
293{
294 a->a.u.fs.path.mnt = m;
295}
296static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
297 struct inode *i)
298{
299 a->a.u.fs.inode = i;
300}
301static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
302 struct path p)
303{
304 a->a.u.fs.path = p;
305}
306static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
307 struct sock *sk)
308{
309 a->a.u.net.sk = sk;
310}
311
312#else /* no AUDIT */
313
314static inline void smk_ad_init(struct smk_audit_info *a, const char *func,
315 char type)
316{
317}
318static inline void smk_ad_setfield_u_tsk(struct smk_audit_info *a,
319 struct task_struct *t)
320{
321}
322static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
323 struct dentry *d)
324{
325}
326static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
327 struct vfsmount *m)
328{
329}
330static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
331 struct inode *i)
332{
333}
334static inline void smk_ad_setfield_u_fs_path(struct smk_audit_info *a,
335 struct path p)
336{
337}
338static inline void smk_ad_setfield_u_net_sk(struct smk_audit_info *a,
339 struct sock *sk)
340{
341}
342#endif
343
240#endif /* _SECURITY_SMACK_H */ 344#endif /* _SECURITY_SMACK_H */
diff --git a/security/smack/smack_access.c b/security/smack/smack_access.c
index ac0a2707f6d4..513dc1aa16dd 100644
--- a/security/smack/smack_access.c
+++ b/security/smack/smack_access.c
@@ -59,11 +59,18 @@ LIST_HEAD(smack_known_list);
59 */ 59 */
60static u32 smack_next_secid = 10; 60static u32 smack_next_secid = 10;
61 61
62/*
63 * what events do we log
64 * can be overwritten at run-time by /smack/logging
65 */
66int log_policy = SMACK_AUDIT_DENIED;
67
62/** 68/**
63 * smk_access - determine if a subject has a specific access to an object 69 * smk_access - determine if a subject has a specific access to an object
64 * @subject_label: a pointer to the subject's Smack label 70 * @subject_label: a pointer to the subject's Smack label
65 * @object_label: a pointer to the object's Smack label 71 * @object_label: a pointer to the object's Smack label
66 * @request: the access requested, in "MAY" format 72 * @request: the access requested, in "MAY" format
73 * @a : a pointer to the audit data
67 * 74 *
68 * This function looks up the subject/object pair in the 75 * This function looks up the subject/object pair in the
69 * access rule list and returns 0 if the access is permitted, 76 * access rule list and returns 0 if the access is permitted,
@@ -78,10 +85,12 @@ static u32 smack_next_secid = 10;
78 * will be on the list, so checking the pointers may be a worthwhile 85 * will be on the list, so checking the pointers may be a worthwhile
79 * optimization. 86 * optimization.
80 */ 87 */
81int smk_access(char *subject_label, char *object_label, int request) 88int smk_access(char *subject_label, char *object_label, int request,
89 struct smk_audit_info *a)
82{ 90{
83 u32 may = MAY_NOT; 91 u32 may = MAY_NOT;
84 struct smack_rule *srp; 92 struct smack_rule *srp;
93 int rc = 0;
85 94
86 /* 95 /*
87 * Hardcoded comparisons. 96 * Hardcoded comparisons.
@@ -89,8 +98,10 @@ int smk_access(char *subject_label, char *object_label, int request)
89 * A star subject can't access any object. 98 * A star subject can't access any object.
90 */ 99 */
91 if (subject_label == smack_known_star.smk_known || 100 if (subject_label == smack_known_star.smk_known ||
92 strcmp(subject_label, smack_known_star.smk_known) == 0) 101 strcmp(subject_label, smack_known_star.smk_known) == 0) {
93 return -EACCES; 102 rc = -EACCES;
103 goto out_audit;
104 }
94 /* 105 /*
95 * An internet object can be accessed by any subject. 106 * An internet object can be accessed by any subject.
96 * Tasks cannot be assigned the internet label. 107 * Tasks cannot be assigned the internet label.
@@ -100,20 +111,20 @@ int smk_access(char *subject_label, char *object_label, int request)
100 subject_label == smack_known_web.smk_known || 111 subject_label == smack_known_web.smk_known ||
101 strcmp(object_label, smack_known_web.smk_known) == 0 || 112 strcmp(object_label, smack_known_web.smk_known) == 0 ||
102 strcmp(subject_label, smack_known_web.smk_known) == 0) 113 strcmp(subject_label, smack_known_web.smk_known) == 0)
103 return 0; 114 goto out_audit;
104 /* 115 /*
105 * A star object can be accessed by any subject. 116 * A star object can be accessed by any subject.
106 */ 117 */
107 if (object_label == smack_known_star.smk_known || 118 if (object_label == smack_known_star.smk_known ||
108 strcmp(object_label, smack_known_star.smk_known) == 0) 119 strcmp(object_label, smack_known_star.smk_known) == 0)
109 return 0; 120 goto out_audit;
110 /* 121 /*
111 * An object can be accessed in any way by a subject 122 * An object can be accessed in any way by a subject
112 * with the same label. 123 * with the same label.
113 */ 124 */
114 if (subject_label == object_label || 125 if (subject_label == object_label ||
115 strcmp(subject_label, object_label) == 0) 126 strcmp(subject_label, object_label) == 0)
116 return 0; 127 goto out_audit;
117 /* 128 /*
118 * A hat subject can read any object. 129 * A hat subject can read any object.
119 * A floor object can be read by any subject. 130 * A floor object can be read by any subject.
@@ -121,10 +132,10 @@ int smk_access(char *subject_label, char *object_label, int request)
121 if ((request & MAY_ANYREAD) == request) { 132 if ((request & MAY_ANYREAD) == request) {
122 if (object_label == smack_known_floor.smk_known || 133 if (object_label == smack_known_floor.smk_known ||
123 strcmp(object_label, smack_known_floor.smk_known) == 0) 134 strcmp(object_label, smack_known_floor.smk_known) == 0)
124 return 0; 135 goto out_audit;
125 if (subject_label == smack_known_hat.smk_known || 136 if (subject_label == smack_known_hat.smk_known ||
126 strcmp(subject_label, smack_known_hat.smk_known) == 0) 137 strcmp(subject_label, smack_known_hat.smk_known) == 0)
127 return 0; 138 goto out_audit;
128 } 139 }
129 /* 140 /*
130 * Beyond here an explicit relationship is required. 141 * Beyond here an explicit relationship is required.
@@ -148,28 +159,36 @@ int smk_access(char *subject_label, char *object_label, int request)
148 * This is a bit map operation. 159 * This is a bit map operation.
149 */ 160 */
150 if ((request & may) == request) 161 if ((request & may) == request)
151 return 0; 162 goto out_audit;
152 163
153 return -EACCES; 164 rc = -EACCES;
165out_audit:
166#ifdef CONFIG_AUDIT
167 if (a)
168 smack_log(subject_label, object_label, request, rc, a);
169#endif
170 return rc;
154} 171}
155 172
156/** 173/**
157 * smk_curacc - determine if current has a specific access to an object 174 * smk_curacc - determine if current has a specific access to an object
158 * @obj_label: a pointer to the object's Smack label 175 * @obj_label: a pointer to the object's Smack label
159 * @mode: the access requested, in "MAY" format 176 * @mode: the access requested, in "MAY" format
177 * @a : common audit data
160 * 178 *
161 * This function checks the current subject label/object label pair 179 * This function checks the current subject label/object label pair
162 * in the access rule list and returns 0 if the access is permitted, 180 * in the access rule list and returns 0 if the access is permitted,
163 * non zero otherwise. It allows that current may have the capability 181 * non zero otherwise. It allows that current may have the capability
164 * to override the rules. 182 * to override the rules.
165 */ 183 */
166int smk_curacc(char *obj_label, u32 mode) 184int smk_curacc(char *obj_label, u32 mode, struct smk_audit_info *a)
167{ 185{
168 int rc; 186 int rc;
187 char *sp = current_security();
169 188
170 rc = smk_access(current_security(), obj_label, mode); 189 rc = smk_access(sp, obj_label, mode, NULL);
171 if (rc == 0) 190 if (rc == 0)
172 return 0; 191 goto out_audit;
173 192
174 /* 193 /*
175 * Return if a specific label has been designated as the 194 * Return if a specific label has been designated as the
@@ -177,14 +196,105 @@ int smk_curacc(char *obj_label, u32 mode)
177 * have that label. 196 * have that label.
178 */ 197 */
179 if (smack_onlycap != NULL && smack_onlycap != current->cred->security) 198 if (smack_onlycap != NULL && smack_onlycap != current->cred->security)
180 return rc; 199 goto out_audit;
181 200
182 if (capable(CAP_MAC_OVERRIDE)) 201 if (capable(CAP_MAC_OVERRIDE))
183 return 0; 202 return 0;
184 203
204out_audit:
205#ifdef CONFIG_AUDIT
206 if (a)
207 smack_log(sp, obj_label, mode, rc, a);
208#endif
185 return rc; 209 return rc;
186} 210}
187 211
212#ifdef CONFIG_AUDIT
213/**
214 * smack_str_from_perm : helper to transalate an int to a
215 * readable string
216 * @string : the string to fill
217 * @access : the int
218 *
219 */
220static inline void smack_str_from_perm(char *string, int access)
221{
222 int i = 0;
223 if (access & MAY_READ)
224 string[i++] = 'r';
225 if (access & MAY_WRITE)
226 string[i++] = 'w';
227 if (access & MAY_EXEC)
228 string[i++] = 'x';
229 if (access & MAY_APPEND)
230 string[i++] = 'a';
231 string[i] = '\0';
232}
233/**
234 * smack_log_callback - SMACK specific information
235 * will be called by generic audit code
236 * @ab : the audit_buffer
237 * @a : audit_data
238 *
239 */
240static void smack_log_callback(struct audit_buffer *ab, void *a)
241{
242 struct common_audit_data *ad = a;
243 struct smack_audit_data *sad = &ad->lsm_priv.smack_audit_data;
244 audit_log_format(ab, "lsm=SMACK fn=%s action=%s", ad->function,
245 sad->result ? "denied" : "granted");
246 audit_log_format(ab, " subject=");
247 audit_log_untrustedstring(ab, sad->subject);
248 audit_log_format(ab, " object=");
249 audit_log_untrustedstring(ab, sad->object);
250 audit_log_format(ab, " requested=%s", sad->request);
251}
252
253/**
254 * smack_log - Audit the granting or denial of permissions.
255 * @subject_label : smack label of the requester
256 * @object_label : smack label of the object being accessed
257 * @request: requested permissions
258 * @result: result from smk_access
259 * @a: auxiliary audit data
260 *
261 * Audit the granting or denial of permissions in accordance
262 * with the policy.
263 */
264void smack_log(char *subject_label, char *object_label, int request,
265 int result, struct smk_audit_info *ad)
266{
267 char request_buffer[SMK_NUM_ACCESS_TYPE + 1];
268 struct smack_audit_data *sad;
269 struct common_audit_data *a = &ad->a;
270
271 /* check if we have to log the current event */
272 if (result != 0 && (log_policy & SMACK_AUDIT_DENIED) == 0)
273 return;
274 if (result == 0 && (log_policy & SMACK_AUDIT_ACCEPT) == 0)
275 return;
276
277 if (a->function == NULL)
278 a->function = "unknown";
279
280 /* end preparing the audit data */
281 sad = &a->lsm_priv.smack_audit_data;
282 smack_str_from_perm(request_buffer, request);
283 sad->subject = subject_label;
284 sad->object = object_label;
285 sad->request = request_buffer;
286 sad->result = result;
287 a->lsm_pre_audit = smack_log_callback;
288
289 common_lsm_audit(a);
290}
291#else /* #ifdef CONFIG_AUDIT */
292void smack_log(char *subject_label, char *object_label, int request,
293 int result, struct smk_audit_info *ad)
294{
295}
296#endif
297
188static DEFINE_MUTEX(smack_known_lock); 298static DEFINE_MUTEX(smack_known_lock);
189 299
190/** 300/**
@@ -209,7 +319,8 @@ struct smack_known *smk_import_entry(const char *string, int len)
209 if (found) 319 if (found)
210 smack[i] = '\0'; 320 smack[i] = '\0';
211 else if (i >= len || string[i] > '~' || string[i] <= ' ' || 321 else if (i >= len || string[i] > '~' || string[i] <= ' ' ||
212 string[i] == '/') { 322 string[i] == '/' || string[i] == '"' ||
323 string[i] == '\\' || string[i] == '\'') {
213 smack[i] = '\0'; 324 smack[i] = '\0';
214 found = 1; 325 found = 1;
215 } else 326 } else
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 98b3195347ab..0023182078c7 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -30,7 +30,6 @@
30#include <net/netlabel.h> 30#include <net/netlabel.h>
31#include <net/cipso_ipv4.h> 31#include <net/cipso_ipv4.h>
32#include <linux/audit.h> 32#include <linux/audit.h>
33
34#include "smack.h" 33#include "smack.h"
35 34
36#define task_security(task) (task_cred_xxx((task), security)) 35#define task_security(task) (task_cred_xxx((task), security))
@@ -103,14 +102,24 @@ struct inode_smack *new_inode_smack(char *smack)
103static int smack_ptrace_may_access(struct task_struct *ctp, unsigned int mode) 102static int smack_ptrace_may_access(struct task_struct *ctp, unsigned int mode)
104{ 103{
105 int rc; 104 int rc;
105 struct smk_audit_info ad;
106 char *sp, *tsp;
106 107
107 rc = cap_ptrace_may_access(ctp, mode); 108 rc = cap_ptrace_may_access(ctp, mode);
108 if (rc != 0) 109 if (rc != 0)
109 return rc; 110 return rc;
110 111
111 rc = smk_access(current_security(), task_security(ctp), MAY_READWRITE); 112 sp = current_security();
113 tsp = task_security(ctp);
114 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
115 smk_ad_setfield_u_tsk(&ad, ctp);
116
117 /* we won't log here, because rc can be overriden */
118 rc = smk_access(sp, tsp, MAY_READWRITE, NULL);
112 if (rc != 0 && capable(CAP_MAC_OVERRIDE)) 119 if (rc != 0 && capable(CAP_MAC_OVERRIDE))
113 return 0; 120 rc = 0;
121
122 smack_log(sp, tsp, MAY_READWRITE, rc, &ad);
114 return rc; 123 return rc;
115} 124}
116 125
@@ -125,14 +134,24 @@ static int smack_ptrace_may_access(struct task_struct *ctp, unsigned int mode)
125static int smack_ptrace_traceme(struct task_struct *ptp) 134static int smack_ptrace_traceme(struct task_struct *ptp)
126{ 135{
127 int rc; 136 int rc;
137 struct smk_audit_info ad;
138 char *sp, *tsp;
128 139
129 rc = cap_ptrace_traceme(ptp); 140 rc = cap_ptrace_traceme(ptp);
130 if (rc != 0) 141 if (rc != 0)
131 return rc; 142 return rc;
132 143
133 rc = smk_access(task_security(ptp), current_security(), MAY_READWRITE); 144 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
145 smk_ad_setfield_u_tsk(&ad, ptp);
146
147 sp = current_security();
148 tsp = task_security(ptp);
149 /* we won't log here, because rc can be overriden */
150 rc = smk_access(tsp, sp, MAY_READWRITE, NULL);
134 if (rc != 0 && has_capability(ptp, CAP_MAC_OVERRIDE)) 151 if (rc != 0 && has_capability(ptp, CAP_MAC_OVERRIDE))
135 return 0; 152 rc = 0;
153
154 smack_log(tsp, sp, MAY_READWRITE, rc, &ad);
136 return rc; 155 return rc;
137} 156}
138 157
@@ -327,8 +346,14 @@ static int smack_sb_kern_mount(struct super_block *sb, int flags, void *data)
327static int smack_sb_statfs(struct dentry *dentry) 346static int smack_sb_statfs(struct dentry *dentry)
328{ 347{
329 struct superblock_smack *sbp = dentry->d_sb->s_security; 348 struct superblock_smack *sbp = dentry->d_sb->s_security;
349 int rc;
350 struct smk_audit_info ad;
351
352 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
353 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
330 354
331 return smk_curacc(sbp->smk_floor, MAY_READ); 355 rc = smk_curacc(sbp->smk_floor, MAY_READ, &ad);
356 return rc;
332} 357}
333 358
334/** 359/**
@@ -346,8 +371,12 @@ static int smack_sb_mount(char *dev_name, struct path *path,
346 char *type, unsigned long flags, void *data) 371 char *type, unsigned long flags, void *data)
347{ 372{
348 struct superblock_smack *sbp = path->mnt->mnt_sb->s_security; 373 struct superblock_smack *sbp = path->mnt->mnt_sb->s_security;
374 struct smk_audit_info ad;
375
376 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
377 smk_ad_setfield_u_fs_path(&ad, *path);
349 378
350 return smk_curacc(sbp->smk_floor, MAY_WRITE); 379 return smk_curacc(sbp->smk_floor, MAY_WRITE, &ad);
351} 380}
352 381
353/** 382/**
@@ -361,10 +390,14 @@ static int smack_sb_mount(char *dev_name, struct path *path,
361static int smack_sb_umount(struct vfsmount *mnt, int flags) 390static int smack_sb_umount(struct vfsmount *mnt, int flags)
362{ 391{
363 struct superblock_smack *sbp; 392 struct superblock_smack *sbp;
393 struct smk_audit_info ad;
364 394
365 sbp = mnt->mnt_sb->s_security; 395 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
396 smk_ad_setfield_u_fs_path_dentry(&ad, mnt->mnt_mountpoint);
397 smk_ad_setfield_u_fs_path_mnt(&ad, mnt);
366 398
367 return smk_curacc(sbp->smk_floor, MAY_WRITE); 399 sbp = mnt->mnt_sb->s_security;
400 return smk_curacc(sbp->smk_floor, MAY_WRITE, &ad);
368} 401}
369 402
370/* 403/*
@@ -441,15 +474,20 @@ static int smack_inode_init_security(struct inode *inode, struct inode *dir,
441static int smack_inode_link(struct dentry *old_dentry, struct inode *dir, 474static int smack_inode_link(struct dentry *old_dentry, struct inode *dir,
442 struct dentry *new_dentry) 475 struct dentry *new_dentry)
443{ 476{
444 int rc;
445 char *isp; 477 char *isp;
478 struct smk_audit_info ad;
479 int rc;
480
481 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
482 smk_ad_setfield_u_fs_path_dentry(&ad, old_dentry);
446 483
447 isp = smk_of_inode(old_dentry->d_inode); 484 isp = smk_of_inode(old_dentry->d_inode);
448 rc = smk_curacc(isp, MAY_WRITE); 485 rc = smk_curacc(isp, MAY_WRITE, &ad);
449 486
450 if (rc == 0 && new_dentry->d_inode != NULL) { 487 if (rc == 0 && new_dentry->d_inode != NULL) {
451 isp = smk_of_inode(new_dentry->d_inode); 488 isp = smk_of_inode(new_dentry->d_inode);
452 rc = smk_curacc(isp, MAY_WRITE); 489 smk_ad_setfield_u_fs_path_dentry(&ad, new_dentry);
490 rc = smk_curacc(isp, MAY_WRITE, &ad);
453 } 491 }
454 492
455 return rc; 493 return rc;
@@ -466,18 +504,24 @@ static int smack_inode_link(struct dentry *old_dentry, struct inode *dir,
466static int smack_inode_unlink(struct inode *dir, struct dentry *dentry) 504static int smack_inode_unlink(struct inode *dir, struct dentry *dentry)
467{ 505{
468 struct inode *ip = dentry->d_inode; 506 struct inode *ip = dentry->d_inode;
507 struct smk_audit_info ad;
469 int rc; 508 int rc;
470 509
510 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
511 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
512
471 /* 513 /*
472 * You need write access to the thing you're unlinking 514 * You need write access to the thing you're unlinking
473 */ 515 */
474 rc = smk_curacc(smk_of_inode(ip), MAY_WRITE); 516 rc = smk_curacc(smk_of_inode(ip), MAY_WRITE, &ad);
475 if (rc == 0) 517 if (rc == 0) {
476 /* 518 /*
477 * You also need write access to the containing directory 519 * You also need write access to the containing directory
478 */ 520 */
479 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE); 521 smk_ad_setfield_u_fs_path_dentry(&ad, NULL);
480 522 smk_ad_setfield_u_fs_inode(&ad, dir);
523 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE, &ad);
524 }
481 return rc; 525 return rc;
482} 526}
483 527
@@ -491,17 +535,24 @@ static int smack_inode_unlink(struct inode *dir, struct dentry *dentry)
491 */ 535 */
492static int smack_inode_rmdir(struct inode *dir, struct dentry *dentry) 536static int smack_inode_rmdir(struct inode *dir, struct dentry *dentry)
493{ 537{
538 struct smk_audit_info ad;
494 int rc; 539 int rc;
495 540
541 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
542 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
543
496 /* 544 /*
497 * You need write access to the thing you're removing 545 * You need write access to the thing you're removing
498 */ 546 */
499 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE); 547 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
500 if (rc == 0) 548 if (rc == 0) {
501 /* 549 /*
502 * You also need write access to the containing directory 550 * You also need write access to the containing directory
503 */ 551 */
504 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE); 552 smk_ad_setfield_u_fs_path_dentry(&ad, NULL);
553 smk_ad_setfield_u_fs_inode(&ad, dir);
554 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE, &ad);
555 }
505 556
506 return rc; 557 return rc;
507} 558}
@@ -525,15 +576,19 @@ static int smack_inode_rename(struct inode *old_inode,
525{ 576{
526 int rc; 577 int rc;
527 char *isp; 578 char *isp;
579 struct smk_audit_info ad;
580
581 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
582 smk_ad_setfield_u_fs_path_dentry(&ad, old_dentry);
528 583
529 isp = smk_of_inode(old_dentry->d_inode); 584 isp = smk_of_inode(old_dentry->d_inode);
530 rc = smk_curacc(isp, MAY_READWRITE); 585 rc = smk_curacc(isp, MAY_READWRITE, &ad);
531 586
532 if (rc == 0 && new_dentry->d_inode != NULL) { 587 if (rc == 0 && new_dentry->d_inode != NULL) {
533 isp = smk_of_inode(new_dentry->d_inode); 588 isp = smk_of_inode(new_dentry->d_inode);
534 rc = smk_curacc(isp, MAY_READWRITE); 589 smk_ad_setfield_u_fs_path_dentry(&ad, new_dentry);
590 rc = smk_curacc(isp, MAY_READWRITE, &ad);
535 } 591 }
536
537 return rc; 592 return rc;
538} 593}
539 594
@@ -548,13 +603,15 @@ static int smack_inode_rename(struct inode *old_inode,
548 */ 603 */
549static int smack_inode_permission(struct inode *inode, int mask) 604static int smack_inode_permission(struct inode *inode, int mask)
550{ 605{
606 struct smk_audit_info ad;
551 /* 607 /*
552 * No permission to check. Existence test. Yup, it's there. 608 * No permission to check. Existence test. Yup, it's there.
553 */ 609 */
554 if (mask == 0) 610 if (mask == 0)
555 return 0; 611 return 0;
556 612 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
557 return smk_curacc(smk_of_inode(inode), mask); 613 smk_ad_setfield_u_fs_inode(&ad, inode);
614 return smk_curacc(smk_of_inode(inode), mask, &ad);
558} 615}
559 616
560/** 617/**
@@ -566,13 +623,16 @@ static int smack_inode_permission(struct inode *inode, int mask)
566 */ 623 */
567static int smack_inode_setattr(struct dentry *dentry, struct iattr *iattr) 624static int smack_inode_setattr(struct dentry *dentry, struct iattr *iattr)
568{ 625{
626 struct smk_audit_info ad;
569 /* 627 /*
570 * Need to allow for clearing the setuid bit. 628 * Need to allow for clearing the setuid bit.
571 */ 629 */
572 if (iattr->ia_valid & ATTR_FORCE) 630 if (iattr->ia_valid & ATTR_FORCE)
573 return 0; 631 return 0;
632 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
633 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
574 634
575 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE); 635 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
576} 636}
577 637
578/** 638/**
@@ -584,7 +644,12 @@ static int smack_inode_setattr(struct dentry *dentry, struct iattr *iattr)
584 */ 644 */
585static int smack_inode_getattr(struct vfsmount *mnt, struct dentry *dentry) 645static int smack_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
586{ 646{
587 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ); 647 struct smk_audit_info ad;
648
649 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
650 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
651 smk_ad_setfield_u_fs_path_mnt(&ad, mnt);
652 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ, &ad);
588} 653}
589 654
590/** 655/**
@@ -602,6 +667,7 @@ static int smack_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
602static int smack_inode_setxattr(struct dentry *dentry, const char *name, 667static int smack_inode_setxattr(struct dentry *dentry, const char *name,
603 const void *value, size_t size, int flags) 668 const void *value, size_t size, int flags)
604{ 669{
670 struct smk_audit_info ad;
605 int rc = 0; 671 int rc = 0;
606 672
607 if (strcmp(name, XATTR_NAME_SMACK) == 0 || 673 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
@@ -619,8 +685,11 @@ static int smack_inode_setxattr(struct dentry *dentry, const char *name,
619 } else 685 } else
620 rc = cap_inode_setxattr(dentry, name, value, size, flags); 686 rc = cap_inode_setxattr(dentry, name, value, size, flags);
621 687
688 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
689 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
690
622 if (rc == 0) 691 if (rc == 0)
623 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE); 692 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
624 693
625 return rc; 694 return rc;
626} 695}
@@ -672,7 +741,12 @@ static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
672 */ 741 */
673static int smack_inode_getxattr(struct dentry *dentry, const char *name) 742static int smack_inode_getxattr(struct dentry *dentry, const char *name)
674{ 743{
675 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ); 744 struct smk_audit_info ad;
745
746 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
747 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
748
749 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ, &ad);
676} 750}
677 751
678/* 752/*
@@ -686,6 +760,7 @@ static int smack_inode_getxattr(struct dentry *dentry, const char *name)
686 */ 760 */
687static int smack_inode_removexattr(struct dentry *dentry, const char *name) 761static int smack_inode_removexattr(struct dentry *dentry, const char *name)
688{ 762{
763 struct smk_audit_info ad;
689 int rc = 0; 764 int rc = 0;
690 765
691 if (strcmp(name, XATTR_NAME_SMACK) == 0 || 766 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
@@ -696,8 +771,10 @@ static int smack_inode_removexattr(struct dentry *dentry, const char *name)
696 } else 771 } else
697 rc = cap_inode_removexattr(dentry, name); 772 rc = cap_inode_removexattr(dentry, name);
698 773
774 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
775 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
699 if (rc == 0) 776 if (rc == 0)
700 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE); 777 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
701 778
702 return rc; 779 return rc;
703} 780}
@@ -856,12 +933,16 @@ static int smack_file_ioctl(struct file *file, unsigned int cmd,
856 unsigned long arg) 933 unsigned long arg)
857{ 934{
858 int rc = 0; 935 int rc = 0;
936 struct smk_audit_info ad;
937
938 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
939 smk_ad_setfield_u_fs_path(&ad, file->f_path);
859 940
860 if (_IOC_DIR(cmd) & _IOC_WRITE) 941 if (_IOC_DIR(cmd) & _IOC_WRITE)
861 rc = smk_curacc(file->f_security, MAY_WRITE); 942 rc = smk_curacc(file->f_security, MAY_WRITE, &ad);
862 943
863 if (rc == 0 && (_IOC_DIR(cmd) & _IOC_READ)) 944 if (rc == 0 && (_IOC_DIR(cmd) & _IOC_READ))
864 rc = smk_curacc(file->f_security, MAY_READ); 945 rc = smk_curacc(file->f_security, MAY_READ, &ad);
865 946
866 return rc; 947 return rc;
867} 948}
@@ -875,7 +956,11 @@ static int smack_file_ioctl(struct file *file, unsigned int cmd,
875 */ 956 */
876static int smack_file_lock(struct file *file, unsigned int cmd) 957static int smack_file_lock(struct file *file, unsigned int cmd)
877{ 958{
878 return smk_curacc(file->f_security, MAY_WRITE); 959 struct smk_audit_info ad;
960
961 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
962 smk_ad_setfield_u_fs_path_dentry(&ad, file->f_path.dentry);
963 return smk_curacc(file->f_security, MAY_WRITE, &ad);
879} 964}
880 965
881/** 966/**
@@ -889,8 +974,12 @@ static int smack_file_lock(struct file *file, unsigned int cmd)
889static int smack_file_fcntl(struct file *file, unsigned int cmd, 974static int smack_file_fcntl(struct file *file, unsigned int cmd,
890 unsigned long arg) 975 unsigned long arg)
891{ 976{
977 struct smk_audit_info ad;
892 int rc; 978 int rc;
893 979
980 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
981 smk_ad_setfield_u_fs_path(&ad, file->f_path);
982
894 switch (cmd) { 983 switch (cmd) {
895 case F_DUPFD: 984 case F_DUPFD:
896 case F_GETFD: 985 case F_GETFD:
@@ -898,7 +987,7 @@ static int smack_file_fcntl(struct file *file, unsigned int cmd,
898 case F_GETLK: 987 case F_GETLK:
899 case F_GETOWN: 988 case F_GETOWN:
900 case F_GETSIG: 989 case F_GETSIG:
901 rc = smk_curacc(file->f_security, MAY_READ); 990 rc = smk_curacc(file->f_security, MAY_READ, &ad);
902 break; 991 break;
903 case F_SETFD: 992 case F_SETFD:
904 case F_SETFL: 993 case F_SETFL:
@@ -906,10 +995,10 @@ static int smack_file_fcntl(struct file *file, unsigned int cmd,
906 case F_SETLKW: 995 case F_SETLKW:
907 case F_SETOWN: 996 case F_SETOWN:
908 case F_SETSIG: 997 case F_SETSIG:
909 rc = smk_curacc(file->f_security, MAY_WRITE); 998 rc = smk_curacc(file->f_security, MAY_WRITE, &ad);
910 break; 999 break;
911 default: 1000 default:
912 rc = smk_curacc(file->f_security, MAY_READWRITE); 1001 rc = smk_curacc(file->f_security, MAY_READWRITE, &ad);
913 } 1002 }
914 1003
915 return rc; 1004 return rc;
@@ -944,14 +1033,21 @@ static int smack_file_send_sigiotask(struct task_struct *tsk,
944{ 1033{
945 struct file *file; 1034 struct file *file;
946 int rc; 1035 int rc;
1036 char *tsp = tsk->cred->security;
1037 struct smk_audit_info ad;
947 1038
948 /* 1039 /*
949 * struct fown_struct is never outside the context of a struct file 1040 * struct fown_struct is never outside the context of a struct file
950 */ 1041 */
951 file = container_of(fown, struct file, f_owner); 1042 file = container_of(fown, struct file, f_owner);
952 rc = smk_access(file->f_security, tsk->cred->security, MAY_WRITE); 1043 /* we don't log here as rc can be overriden */
1044 rc = smk_access(file->f_security, tsp, MAY_WRITE, NULL);
953 if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE)) 1045 if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE))
954 return 0; 1046 rc = 0;
1047
1048 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1049 smk_ad_setfield_u_tsk(&ad, tsk);
1050 smack_log(file->f_security, tsp, MAY_WRITE, rc, &ad);
955 return rc; 1051 return rc;
956} 1052}
957 1053
@@ -964,7 +1060,10 @@ static int smack_file_send_sigiotask(struct task_struct *tsk,
964static int smack_file_receive(struct file *file) 1060static int smack_file_receive(struct file *file)
965{ 1061{
966 int may = 0; 1062 int may = 0;
1063 struct smk_audit_info ad;
967 1064
1065 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1066 smk_ad_setfield_u_fs_path(&ad, file->f_path);
968 /* 1067 /*
969 * This code relies on bitmasks. 1068 * This code relies on bitmasks.
970 */ 1069 */
@@ -973,7 +1072,7 @@ static int smack_file_receive(struct file *file)
973 if (file->f_mode & FMODE_WRITE) 1072 if (file->f_mode & FMODE_WRITE)
974 may |= MAY_WRITE; 1073 may |= MAY_WRITE;
975 1074
976 return smk_curacc(file->f_security, may); 1075 return smk_curacc(file->f_security, may, &ad);
977} 1076}
978 1077
979/* 1078/*
@@ -1053,6 +1152,22 @@ static int smack_kernel_create_files_as(struct cred *new,
1053} 1152}
1054 1153
1055/** 1154/**
1155 * smk_curacc_on_task - helper to log task related access
1156 * @p: the task object
1157 * @access : the access requested
1158 *
1159 * Return 0 if access is permitted
1160 */
1161static int smk_curacc_on_task(struct task_struct *p, int access)
1162{
1163 struct smk_audit_info ad;
1164
1165 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1166 smk_ad_setfield_u_tsk(&ad, p);
1167 return smk_curacc(task_security(p), access, &ad);
1168}
1169
1170/**
1056 * smack_task_setpgid - Smack check on setting pgid 1171 * smack_task_setpgid - Smack check on setting pgid
1057 * @p: the task object 1172 * @p: the task object
1058 * @pgid: unused 1173 * @pgid: unused
@@ -1061,7 +1176,7 @@ static int smack_kernel_create_files_as(struct cred *new,
1061 */ 1176 */
1062static int smack_task_setpgid(struct task_struct *p, pid_t pgid) 1177static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
1063{ 1178{
1064 return smk_curacc(task_security(p), MAY_WRITE); 1179 return smk_curacc_on_task(p, MAY_WRITE);
1065} 1180}
1066 1181
1067/** 1182/**
@@ -1072,7 +1187,7 @@ static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
1072 */ 1187 */
1073static int smack_task_getpgid(struct task_struct *p) 1188static int smack_task_getpgid(struct task_struct *p)
1074{ 1189{
1075 return smk_curacc(task_security(p), MAY_READ); 1190 return smk_curacc_on_task(p, MAY_READ);
1076} 1191}
1077 1192
1078/** 1193/**
@@ -1083,7 +1198,7 @@ static int smack_task_getpgid(struct task_struct *p)
1083 */ 1198 */
1084static int smack_task_getsid(struct task_struct *p) 1199static int smack_task_getsid(struct task_struct *p)
1085{ 1200{
1086 return smk_curacc(task_security(p), MAY_READ); 1201 return smk_curacc_on_task(p, MAY_READ);
1087} 1202}
1088 1203
1089/** 1204/**
@@ -1111,7 +1226,7 @@ static int smack_task_setnice(struct task_struct *p, int nice)
1111 1226
1112 rc = cap_task_setnice(p, nice); 1227 rc = cap_task_setnice(p, nice);
1113 if (rc == 0) 1228 if (rc == 0)
1114 rc = smk_curacc(task_security(p), MAY_WRITE); 1229 rc = smk_curacc_on_task(p, MAY_WRITE);
1115 return rc; 1230 return rc;
1116} 1231}
1117 1232
@@ -1128,7 +1243,7 @@ static int smack_task_setioprio(struct task_struct *p, int ioprio)
1128 1243
1129 rc = cap_task_setioprio(p, ioprio); 1244 rc = cap_task_setioprio(p, ioprio);
1130 if (rc == 0) 1245 if (rc == 0)
1131 rc = smk_curacc(task_security(p), MAY_WRITE); 1246 rc = smk_curacc_on_task(p, MAY_WRITE);
1132 return rc; 1247 return rc;
1133} 1248}
1134 1249
@@ -1140,7 +1255,7 @@ static int smack_task_setioprio(struct task_struct *p, int ioprio)
1140 */ 1255 */
1141static int smack_task_getioprio(struct task_struct *p) 1256static int smack_task_getioprio(struct task_struct *p)
1142{ 1257{
1143 return smk_curacc(task_security(p), MAY_READ); 1258 return smk_curacc_on_task(p, MAY_READ);
1144} 1259}
1145 1260
1146/** 1261/**
@@ -1158,7 +1273,7 @@ static int smack_task_setscheduler(struct task_struct *p, int policy,
1158 1273
1159 rc = cap_task_setscheduler(p, policy, lp); 1274 rc = cap_task_setscheduler(p, policy, lp);
1160 if (rc == 0) 1275 if (rc == 0)
1161 rc = smk_curacc(task_security(p), MAY_WRITE); 1276 rc = smk_curacc_on_task(p, MAY_WRITE);
1162 return rc; 1277 return rc;
1163} 1278}
1164 1279
@@ -1170,7 +1285,7 @@ static int smack_task_setscheduler(struct task_struct *p, int policy,
1170 */ 1285 */
1171static int smack_task_getscheduler(struct task_struct *p) 1286static int smack_task_getscheduler(struct task_struct *p)
1172{ 1287{
1173 return smk_curacc(task_security(p), MAY_READ); 1288 return smk_curacc_on_task(p, MAY_READ);
1174} 1289}
1175 1290
1176/** 1291/**
@@ -1181,7 +1296,7 @@ static int smack_task_getscheduler(struct task_struct *p)
1181 */ 1296 */
1182static int smack_task_movememory(struct task_struct *p) 1297static int smack_task_movememory(struct task_struct *p)
1183{ 1298{
1184 return smk_curacc(task_security(p), MAY_WRITE); 1299 return smk_curacc_on_task(p, MAY_WRITE);
1185} 1300}
1186 1301
1187/** 1302/**
@@ -1199,18 +1314,23 @@ static int smack_task_movememory(struct task_struct *p)
1199static int smack_task_kill(struct task_struct *p, struct siginfo *info, 1314static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1200 int sig, u32 secid) 1315 int sig, u32 secid)
1201{ 1316{
1317 struct smk_audit_info ad;
1318
1319 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1320 smk_ad_setfield_u_tsk(&ad, p);
1202 /* 1321 /*
1203 * Sending a signal requires that the sender 1322 * Sending a signal requires that the sender
1204 * can write the receiver. 1323 * can write the receiver.
1205 */ 1324 */
1206 if (secid == 0) 1325 if (secid == 0)
1207 return smk_curacc(task_security(p), MAY_WRITE); 1326 return smk_curacc(task_security(p), MAY_WRITE, &ad);
1208 /* 1327 /*
1209 * If the secid isn't 0 we're dealing with some USB IO 1328 * If the secid isn't 0 we're dealing with some USB IO
1210 * specific behavior. This is not clean. For one thing 1329 * specific behavior. This is not clean. For one thing
1211 * we can't take privilege into account. 1330 * we can't take privilege into account.
1212 */ 1331 */
1213 return smk_access(smack_from_secid(secid), task_security(p), MAY_WRITE); 1332 return smk_access(smack_from_secid(secid), task_security(p),
1333 MAY_WRITE, &ad);
1214} 1334}
1215 1335
1216/** 1336/**
@@ -1221,11 +1341,15 @@ static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1221 */ 1341 */
1222static int smack_task_wait(struct task_struct *p) 1342static int smack_task_wait(struct task_struct *p)
1223{ 1343{
1344 struct smk_audit_info ad;
1345 char *sp = current_security();
1346 char *tsp = task_security(p);
1224 int rc; 1347 int rc;
1225 1348
1226 rc = smk_access(current_security(), task_security(p), MAY_WRITE); 1349 /* we don't log here, we can be overriden */
1350 rc = smk_access(sp, tsp, MAY_WRITE, NULL);
1227 if (rc == 0) 1351 if (rc == 0)
1228 return 0; 1352 goto out_log;
1229 1353
1230 /* 1354 /*
1231 * Allow the operation to succeed if either task 1355 * Allow the operation to succeed if either task
@@ -1239,8 +1363,12 @@ static int smack_task_wait(struct task_struct *p)
1239 * the smack value. 1363 * the smack value.
1240 */ 1364 */
1241 if (capable(CAP_MAC_OVERRIDE) || has_capability(p, CAP_MAC_OVERRIDE)) 1365 if (capable(CAP_MAC_OVERRIDE) || has_capability(p, CAP_MAC_OVERRIDE))
1242 return 0; 1366 rc = 0;
1243 1367 /* we log only if we didn't get overriden */
1368 out_log:
1369 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1370 smk_ad_setfield_u_tsk(&ad, p);
1371 smack_log(sp, tsp, MAY_WRITE, rc, &ad);
1244 return rc; 1372 return rc;
1245} 1373}
1246 1374
@@ -1456,12 +1584,19 @@ static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
1456 int sk_lbl; 1584 int sk_lbl;
1457 char *hostsp; 1585 char *hostsp;
1458 struct socket_smack *ssp = sk->sk_security; 1586 struct socket_smack *ssp = sk->sk_security;
1587 struct smk_audit_info ad;
1459 1588
1460 rcu_read_lock(); 1589 rcu_read_lock();
1461 hostsp = smack_host_label(sap); 1590 hostsp = smack_host_label(sap);
1462 if (hostsp != NULL) { 1591 if (hostsp != NULL) {
1463 sk_lbl = SMACK_UNLABELED_SOCKET; 1592 sk_lbl = SMACK_UNLABELED_SOCKET;
1464 rc = smk_access(ssp->smk_out, hostsp, MAY_WRITE); 1593#ifdef CONFIG_AUDIT
1594 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
1595 ad.a.u.net.family = sap->sin_family;
1596 ad.a.u.net.dport = sap->sin_port;
1597 ad.a.u.net.v4info.daddr = sap->sin_addr.s_addr;
1598#endif
1599 rc = smk_access(ssp->smk_out, hostsp, MAY_WRITE, &ad);
1465 } else { 1600 } else {
1466 sk_lbl = SMACK_CIPSO_SOCKET; 1601 sk_lbl = SMACK_CIPSO_SOCKET;
1467 rc = 0; 1602 rc = 0;
@@ -1657,6 +1792,25 @@ static void smack_shm_free_security(struct shmid_kernel *shp)
1657} 1792}
1658 1793
1659/** 1794/**
1795 * smk_curacc_shm : check if current has access on shm
1796 * @shp : the object
1797 * @access : access requested
1798 *
1799 * Returns 0 if current has the requested access, error code otherwise
1800 */
1801static int smk_curacc_shm(struct shmid_kernel *shp, int access)
1802{
1803 char *ssp = smack_of_shm(shp);
1804 struct smk_audit_info ad;
1805
1806#ifdef CONFIG_AUDIT
1807 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
1808 ad.a.u.ipc_id = shp->shm_perm.id;
1809#endif
1810 return smk_curacc(ssp, access, &ad);
1811}
1812
1813/**
1660 * smack_shm_associate - Smack access check for shm 1814 * smack_shm_associate - Smack access check for shm
1661 * @shp: the object 1815 * @shp: the object
1662 * @shmflg: access requested 1816 * @shmflg: access requested
@@ -1665,11 +1819,10 @@ static void smack_shm_free_security(struct shmid_kernel *shp)
1665 */ 1819 */
1666static int smack_shm_associate(struct shmid_kernel *shp, int shmflg) 1820static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
1667{ 1821{
1668 char *ssp = smack_of_shm(shp);
1669 int may; 1822 int may;
1670 1823
1671 may = smack_flags_to_may(shmflg); 1824 may = smack_flags_to_may(shmflg);
1672 return smk_curacc(ssp, may); 1825 return smk_curacc_shm(shp, may);
1673} 1826}
1674 1827
1675/** 1828/**
@@ -1681,7 +1834,6 @@ static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
1681 */ 1834 */
1682static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd) 1835static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
1683{ 1836{
1684 char *ssp;
1685 int may; 1837 int may;
1686 1838
1687 switch (cmd) { 1839 switch (cmd) {
@@ -1704,9 +1856,7 @@ static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
1704 default: 1856 default:
1705 return -EINVAL; 1857 return -EINVAL;
1706 } 1858 }
1707 1859 return smk_curacc_shm(shp, may);
1708 ssp = smack_of_shm(shp);
1709 return smk_curacc(ssp, may);
1710} 1860}
1711 1861
1712/** 1862/**
@@ -1720,11 +1870,10 @@ static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
1720static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr, 1870static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr,
1721 int shmflg) 1871 int shmflg)
1722{ 1872{
1723 char *ssp = smack_of_shm(shp);
1724 int may; 1873 int may;
1725 1874
1726 may = smack_flags_to_may(shmflg); 1875 may = smack_flags_to_may(shmflg);
1727 return smk_curacc(ssp, may); 1876 return smk_curacc_shm(shp, may);
1728} 1877}
1729 1878
1730/** 1879/**
@@ -1766,6 +1915,25 @@ static void smack_sem_free_security(struct sem_array *sma)
1766} 1915}
1767 1916
1768/** 1917/**
1918 * smk_curacc_sem : check if current has access on sem
1919 * @sma : the object
1920 * @access : access requested
1921 *
1922 * Returns 0 if current has the requested access, error code otherwise
1923 */
1924static int smk_curacc_sem(struct sem_array *sma, int access)
1925{
1926 char *ssp = smack_of_sem(sma);
1927 struct smk_audit_info ad;
1928
1929#ifdef CONFIG_AUDIT
1930 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
1931 ad.a.u.ipc_id = sma->sem_perm.id;
1932#endif
1933 return smk_curacc(ssp, access, &ad);
1934}
1935
1936/**
1769 * smack_sem_associate - Smack access check for sem 1937 * smack_sem_associate - Smack access check for sem
1770 * @sma: the object 1938 * @sma: the object
1771 * @semflg: access requested 1939 * @semflg: access requested
@@ -1774,11 +1942,10 @@ static void smack_sem_free_security(struct sem_array *sma)
1774 */ 1942 */
1775static int smack_sem_associate(struct sem_array *sma, int semflg) 1943static int smack_sem_associate(struct sem_array *sma, int semflg)
1776{ 1944{
1777 char *ssp = smack_of_sem(sma);
1778 int may; 1945 int may;
1779 1946
1780 may = smack_flags_to_may(semflg); 1947 may = smack_flags_to_may(semflg);
1781 return smk_curacc(ssp, may); 1948 return smk_curacc_sem(sma, may);
1782} 1949}
1783 1950
1784/** 1951/**
@@ -1790,7 +1957,6 @@ static int smack_sem_associate(struct sem_array *sma, int semflg)
1790 */ 1957 */
1791static int smack_sem_semctl(struct sem_array *sma, int cmd) 1958static int smack_sem_semctl(struct sem_array *sma, int cmd)
1792{ 1959{
1793 char *ssp;
1794 int may; 1960 int may;
1795 1961
1796 switch (cmd) { 1962 switch (cmd) {
@@ -1819,8 +1985,7 @@ static int smack_sem_semctl(struct sem_array *sma, int cmd)
1819 return -EINVAL; 1985 return -EINVAL;
1820 } 1986 }
1821 1987
1822 ssp = smack_of_sem(sma); 1988 return smk_curacc_sem(sma, may);
1823 return smk_curacc(ssp, may);
1824} 1989}
1825 1990
1826/** 1991/**
@@ -1837,9 +2002,7 @@ static int smack_sem_semctl(struct sem_array *sma, int cmd)
1837static int smack_sem_semop(struct sem_array *sma, struct sembuf *sops, 2002static int smack_sem_semop(struct sem_array *sma, struct sembuf *sops,
1838 unsigned nsops, int alter) 2003 unsigned nsops, int alter)
1839{ 2004{
1840 char *ssp = smack_of_sem(sma); 2005 return smk_curacc_sem(sma, MAY_READWRITE);
1841
1842 return smk_curacc(ssp, MAY_READWRITE);
1843} 2006}
1844 2007
1845/** 2008/**
@@ -1881,6 +2044,25 @@ static char *smack_of_msq(struct msg_queue *msq)
1881} 2044}
1882 2045
1883/** 2046/**
2047 * smk_curacc_msq : helper to check if current has access on msq
2048 * @msq : the msq
2049 * @access : access requested
2050 *
2051 * return 0 if current has access, error otherwise
2052 */
2053static int smk_curacc_msq(struct msg_queue *msq, int access)
2054{
2055 char *msp = smack_of_msq(msq);
2056 struct smk_audit_info ad;
2057
2058#ifdef CONFIG_AUDIT
2059 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2060 ad.a.u.ipc_id = msq->q_perm.id;
2061#endif
2062 return smk_curacc(msp, access, &ad);
2063}
2064
2065/**
1884 * smack_msg_queue_associate - Smack access check for msg_queue 2066 * smack_msg_queue_associate - Smack access check for msg_queue
1885 * @msq: the object 2067 * @msq: the object
1886 * @msqflg: access requested 2068 * @msqflg: access requested
@@ -1889,11 +2071,10 @@ static char *smack_of_msq(struct msg_queue *msq)
1889 */ 2071 */
1890static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg) 2072static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg)
1891{ 2073{
1892 char *msp = smack_of_msq(msq);
1893 int may; 2074 int may;
1894 2075
1895 may = smack_flags_to_may(msqflg); 2076 may = smack_flags_to_may(msqflg);
1896 return smk_curacc(msp, may); 2077 return smk_curacc_msq(msq, may);
1897} 2078}
1898 2079
1899/** 2080/**
@@ -1905,7 +2086,6 @@ static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg)
1905 */ 2086 */
1906static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd) 2087static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
1907{ 2088{
1908 char *msp;
1909 int may; 2089 int may;
1910 2090
1911 switch (cmd) { 2091 switch (cmd) {
@@ -1927,8 +2107,7 @@ static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
1927 return -EINVAL; 2107 return -EINVAL;
1928 } 2108 }
1929 2109
1930 msp = smack_of_msq(msq); 2110 return smk_curacc_msq(msq, may);
1931 return smk_curacc(msp, may);
1932} 2111}
1933 2112
1934/** 2113/**
@@ -1942,11 +2121,10 @@ static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
1942static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg, 2121static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
1943 int msqflg) 2122 int msqflg)
1944{ 2123{
1945 char *msp = smack_of_msq(msq); 2124 int may;
1946 int rc;
1947 2125
1948 rc = smack_flags_to_may(msqflg); 2126 may = smack_flags_to_may(msqflg);
1949 return smk_curacc(msp, rc); 2127 return smk_curacc_msq(msq, may);
1950} 2128}
1951 2129
1952/** 2130/**
@@ -1962,9 +2140,7 @@ static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
1962static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg, 2140static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
1963 struct task_struct *target, long type, int mode) 2141 struct task_struct *target, long type, int mode)
1964{ 2142{
1965 char *msp = smack_of_msq(msq); 2143 return smk_curacc_msq(msq, MAY_READWRITE);
1966
1967 return smk_curacc(msp, MAY_READWRITE);
1968} 2144}
1969 2145
1970/** 2146/**
@@ -1977,10 +2153,14 @@ static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
1977static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag) 2153static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
1978{ 2154{
1979 char *isp = ipp->security; 2155 char *isp = ipp->security;
1980 int may; 2156 int may = smack_flags_to_may(flag);
2157 struct smk_audit_info ad;
1981 2158
1982 may = smack_flags_to_may(flag); 2159#ifdef CONFIG_AUDIT
1983 return smk_curacc(isp, may); 2160 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2161 ad.a.u.ipc_id = ipp->id;
2162#endif
2163 return smk_curacc(isp, may, &ad);
1984} 2164}
1985 2165
1986/** 2166/**
@@ -2239,8 +2419,12 @@ static int smack_unix_stream_connect(struct socket *sock,
2239{ 2419{
2240 struct inode *sp = SOCK_INODE(sock); 2420 struct inode *sp = SOCK_INODE(sock);
2241 struct inode *op = SOCK_INODE(other); 2421 struct inode *op = SOCK_INODE(other);
2422 struct smk_audit_info ad;
2242 2423
2243 return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_READWRITE); 2424 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2425 smk_ad_setfield_u_net_sk(&ad, other->sk);
2426 return smk_access(smk_of_inode(sp), smk_of_inode(op),
2427 MAY_READWRITE, &ad);
2244} 2428}
2245 2429
2246/** 2430/**
@@ -2255,8 +2439,11 @@ static int smack_unix_may_send(struct socket *sock, struct socket *other)
2255{ 2439{
2256 struct inode *sp = SOCK_INODE(sock); 2440 struct inode *sp = SOCK_INODE(sock);
2257 struct inode *op = SOCK_INODE(other); 2441 struct inode *op = SOCK_INODE(other);
2442 struct smk_audit_info ad;
2258 2443
2259 return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_WRITE); 2444 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2445 smk_ad_setfield_u_net_sk(&ad, other->sk);
2446 return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_WRITE, &ad);
2260} 2447}
2261 2448
2262/** 2449/**
@@ -2371,7 +2558,7 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
2371 char smack[SMK_LABELLEN]; 2558 char smack[SMK_LABELLEN];
2372 char *csp; 2559 char *csp;
2373 int rc; 2560 int rc;
2374 2561 struct smk_audit_info ad;
2375 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6) 2562 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2376 return 0; 2563 return 0;
2377 2564
@@ -2389,13 +2576,19 @@ static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
2389 2576
2390 netlbl_secattr_destroy(&secattr); 2577 netlbl_secattr_destroy(&secattr);
2391 2578
2579#ifdef CONFIG_AUDIT
2580 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2581 ad.a.u.net.family = sk->sk_family;
2582 ad.a.u.net.netif = skb->iif;
2583 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
2584#endif
2392 /* 2585 /*
2393 * Receiving a packet requires that the other end 2586 * Receiving a packet requires that the other end
2394 * be able to write here. Read access is not required. 2587 * be able to write here. Read access is not required.
2395 * This is the simplist possible security model 2588 * This is the simplist possible security model
2396 * for networking. 2589 * for networking.
2397 */ 2590 */
2398 rc = smk_access(csp, ssp->smk_in, MAY_WRITE); 2591 rc = smk_access(csp, ssp->smk_in, MAY_WRITE, &ad);
2399 if (rc != 0) 2592 if (rc != 0)
2400 netlbl_skbuff_err(skb, rc, 0); 2593 netlbl_skbuff_err(skb, rc, 0);
2401 return rc; 2594 return rc;
@@ -2524,6 +2717,7 @@ static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
2524 struct iphdr *hdr; 2717 struct iphdr *hdr;
2525 char smack[SMK_LABELLEN]; 2718 char smack[SMK_LABELLEN];
2526 int rc; 2719 int rc;
2720 struct smk_audit_info ad;
2527 2721
2528 /* handle mapped IPv4 packets arriving via IPv6 sockets */ 2722 /* handle mapped IPv4 packets arriving via IPv6 sockets */
2529 if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP)) 2723 if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
@@ -2537,11 +2731,17 @@ static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
2537 strncpy(smack, smack_known_huh.smk_known, SMK_MAXLEN); 2731 strncpy(smack, smack_known_huh.smk_known, SMK_MAXLEN);
2538 netlbl_secattr_destroy(&secattr); 2732 netlbl_secattr_destroy(&secattr);
2539 2733
2734#ifdef CONFIG_AUDIT
2735 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2736 ad.a.u.net.family = family;
2737 ad.a.u.net.netif = skb->iif;
2738 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
2739#endif
2540 /* 2740 /*
2541 * Receiving a packet requires that the other end be able to write 2741 * Receiving a packet requires that the other end be able to write
2542 * here. Read access is not required. 2742 * here. Read access is not required.
2543 */ 2743 */
2544 rc = smk_access(smack, ssp->smk_in, MAY_WRITE); 2744 rc = smk_access(smack, ssp->smk_in, MAY_WRITE, &ad);
2545 if (rc != 0) 2745 if (rc != 0)
2546 return rc; 2746 return rc;
2547 2747
@@ -2643,6 +2843,7 @@ static int smack_key_permission(key_ref_t key_ref,
2643 const struct cred *cred, key_perm_t perm) 2843 const struct cred *cred, key_perm_t perm)
2644{ 2844{
2645 struct key *keyp; 2845 struct key *keyp;
2846 struct smk_audit_info ad;
2646 2847
2647 keyp = key_ref_to_ptr(key_ref); 2848 keyp = key_ref_to_ptr(key_ref);
2648 if (keyp == NULL) 2849 if (keyp == NULL)
@@ -2658,8 +2859,13 @@ static int smack_key_permission(key_ref_t key_ref,
2658 */ 2859 */
2659 if (cred->security == NULL) 2860 if (cred->security == NULL)
2660 return -EACCES; 2861 return -EACCES;
2661 2862#ifdef CONFIG_AUDIT
2662 return smk_access(cred->security, keyp->security, MAY_READWRITE); 2863 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_KEY);
2864 ad.a.u.key_struct.key = keyp->serial;
2865 ad.a.u.key_struct.key_desc = keyp->description;
2866#endif
2867 return smk_access(cred->security, keyp->security,
2868 MAY_READWRITE, &ad);
2663} 2869}
2664#endif /* CONFIG_KEYS */ 2870#endif /* CONFIG_KEYS */
2665 2871
@@ -2828,15 +3034,7 @@ struct security_operations smack_ops = {
2828 3034
2829 .ptrace_may_access = smack_ptrace_may_access, 3035 .ptrace_may_access = smack_ptrace_may_access,
2830 .ptrace_traceme = smack_ptrace_traceme, 3036 .ptrace_traceme = smack_ptrace_traceme,
2831 .capget = cap_capget,
2832 .capset = cap_capset,
2833 .capable = cap_capable,
2834 .syslog = smack_syslog, 3037 .syslog = smack_syslog,
2835 .settime = cap_settime,
2836 .vm_enough_memory = cap_vm_enough_memory,
2837
2838 .bprm_set_creds = cap_bprm_set_creds,
2839 .bprm_secureexec = cap_bprm_secureexec,
2840 3038
2841 .sb_alloc_security = smack_sb_alloc_security, 3039 .sb_alloc_security = smack_sb_alloc_security,
2842 .sb_free_security = smack_sb_free_security, 3040 .sb_free_security = smack_sb_free_security,
@@ -2860,8 +3058,6 @@ struct security_operations smack_ops = {
2860 .inode_post_setxattr = smack_inode_post_setxattr, 3058 .inode_post_setxattr = smack_inode_post_setxattr,
2861 .inode_getxattr = smack_inode_getxattr, 3059 .inode_getxattr = smack_inode_getxattr,
2862 .inode_removexattr = smack_inode_removexattr, 3060 .inode_removexattr = smack_inode_removexattr,
2863 .inode_need_killpriv = cap_inode_need_killpriv,
2864 .inode_killpriv = cap_inode_killpriv,
2865 .inode_getsecurity = smack_inode_getsecurity, 3061 .inode_getsecurity = smack_inode_getsecurity,
2866 .inode_setsecurity = smack_inode_setsecurity, 3062 .inode_setsecurity = smack_inode_setsecurity,
2867 .inode_listsecurity = smack_inode_listsecurity, 3063 .inode_listsecurity = smack_inode_listsecurity,
@@ -2882,7 +3078,6 @@ struct security_operations smack_ops = {
2882 .cred_commit = smack_cred_commit, 3078 .cred_commit = smack_cred_commit,
2883 .kernel_act_as = smack_kernel_act_as, 3079 .kernel_act_as = smack_kernel_act_as,
2884 .kernel_create_files_as = smack_kernel_create_files_as, 3080 .kernel_create_files_as = smack_kernel_create_files_as,
2885 .task_fix_setuid = cap_task_fix_setuid,
2886 .task_setpgid = smack_task_setpgid, 3081 .task_setpgid = smack_task_setpgid,
2887 .task_getpgid = smack_task_getpgid, 3082 .task_getpgid = smack_task_getpgid,
2888 .task_getsid = smack_task_getsid, 3083 .task_getsid = smack_task_getsid,
@@ -2896,7 +3091,6 @@ struct security_operations smack_ops = {
2896 .task_kill = smack_task_kill, 3091 .task_kill = smack_task_kill,
2897 .task_wait = smack_task_wait, 3092 .task_wait = smack_task_wait,
2898 .task_to_inode = smack_task_to_inode, 3093 .task_to_inode = smack_task_to_inode,
2899 .task_prctl = cap_task_prctl,
2900 3094
2901 .ipc_permission = smack_ipc_permission, 3095 .ipc_permission = smack_ipc_permission,
2902 .ipc_getsecid = smack_ipc_getsecid, 3096 .ipc_getsecid = smack_ipc_getsecid,
@@ -2923,9 +3117,6 @@ struct security_operations smack_ops = {
2923 .sem_semctl = smack_sem_semctl, 3117 .sem_semctl = smack_sem_semctl,
2924 .sem_semop = smack_sem_semop, 3118 .sem_semop = smack_sem_semop,
2925 3119
2926 .netlink_send = cap_netlink_send,
2927 .netlink_recv = cap_netlink_recv,
2928
2929 .d_instantiate = smack_d_instantiate, 3120 .d_instantiate = smack_d_instantiate,
2930 3121
2931 .getprocattr = smack_getprocattr, 3122 .getprocattr = smack_getprocattr,
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 11d2cb19d7a6..f83a80980726 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -41,6 +41,7 @@ enum smk_inos {
41 SMK_AMBIENT = 7, /* internet ambient label */ 41 SMK_AMBIENT = 7, /* internet ambient label */
42 SMK_NETLBLADDR = 8, /* single label hosts */ 42 SMK_NETLBLADDR = 8, /* single label hosts */
43 SMK_ONLYCAP = 9, /* the only "capable" label */ 43 SMK_ONLYCAP = 9, /* the only "capable" label */
44 SMK_LOGGING = 10, /* logging */
44}; 45};
45 46
46/* 47/*
@@ -775,7 +776,7 @@ static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf,
775 struct sockaddr_in newname; 776 struct sockaddr_in newname;
776 char smack[SMK_LABELLEN]; 777 char smack[SMK_LABELLEN];
777 char *sp; 778 char *sp;
778 char data[SMK_NETLBLADDRMAX]; 779 char data[SMK_NETLBLADDRMAX + 1];
779 char *host = (char *)&newname.sin_addr.s_addr; 780 char *host = (char *)&newname.sin_addr.s_addr;
780 int rc; 781 int rc;
781 struct netlbl_audit audit_info; 782 struct netlbl_audit audit_info;
@@ -1192,6 +1193,69 @@ static const struct file_operations smk_onlycap_ops = {
1192}; 1193};
1193 1194
1194/** 1195/**
1196 * smk_read_logging - read() for /smack/logging
1197 * @filp: file pointer, not actually used
1198 * @buf: where to put the result
1199 * @cn: maximum to send along
1200 * @ppos: where to start
1201 *
1202 * Returns number of bytes read or error code, as appropriate
1203 */
1204static ssize_t smk_read_logging(struct file *filp, char __user *buf,
1205 size_t count, loff_t *ppos)
1206{
1207 char temp[32];
1208 ssize_t rc;
1209
1210 if (*ppos != 0)
1211 return 0;
1212
1213 sprintf(temp, "%d\n", log_policy);
1214 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
1215 return rc;
1216}
1217
1218/**
1219 * smk_write_logging - write() for /smack/logging
1220 * @file: file pointer, not actually used
1221 * @buf: where to get the data from
1222 * @count: bytes sent
1223 * @ppos: where to start
1224 *
1225 * Returns number of bytes written or error code, as appropriate
1226 */
1227static ssize_t smk_write_logging(struct file *file, const char __user *buf,
1228 size_t count, loff_t *ppos)
1229{
1230 char temp[32];
1231 int i;
1232
1233 if (!capable(CAP_MAC_ADMIN))
1234 return -EPERM;
1235
1236 if (count >= sizeof(temp) || count == 0)
1237 return -EINVAL;
1238
1239 if (copy_from_user(temp, buf, count) != 0)
1240 return -EFAULT;
1241
1242 temp[count] = '\0';
1243
1244 if (sscanf(temp, "%d", &i) != 1)
1245 return -EINVAL;
1246 if (i < 0 || i > 3)
1247 return -EINVAL;
1248 log_policy = i;
1249 return count;
1250}
1251
1252
1253
1254static const struct file_operations smk_logging_ops = {
1255 .read = smk_read_logging,
1256 .write = smk_write_logging,
1257};
1258/**
1195 * smk_fill_super - fill the /smackfs superblock 1259 * smk_fill_super - fill the /smackfs superblock
1196 * @sb: the empty superblock 1260 * @sb: the empty superblock
1197 * @data: unused 1261 * @data: unused
@@ -1221,6 +1285,8 @@ static int smk_fill_super(struct super_block *sb, void *data, int silent)
1221 {"netlabel", &smk_netlbladdr_ops, S_IRUGO|S_IWUSR}, 1285 {"netlabel", &smk_netlbladdr_ops, S_IRUGO|S_IWUSR},
1222 [SMK_ONLYCAP] = 1286 [SMK_ONLYCAP] =
1223 {"onlycap", &smk_onlycap_ops, S_IRUGO|S_IWUSR}, 1287 {"onlycap", &smk_onlycap_ops, S_IRUGO|S_IWUSR},
1288 [SMK_LOGGING] =
1289 {"logging", &smk_logging_ops, S_IRUGO|S_IWUSR},
1224 /* last one */ {""} 1290 /* last one */ {""}
1225 }; 1291 };
1226 1292
diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c
index ddfb9cccf468..fdd1f4b8c448 100644
--- a/security/tomoyo/common.c
+++ b/security/tomoyo/common.c
@@ -28,7 +28,13 @@ static const char *tomoyo_mode_2[4] = {
28 "disabled", "enabled", "enabled", "enabled" 28 "disabled", "enabled", "enabled", "enabled"
29}; 29};
30 30
31/* Table for profile. */ 31/*
32 * tomoyo_control_array is a static data which contains
33 *
34 * (1) functionality name used by /sys/kernel/security/tomoyo/profile .
35 * (2) initial values for "struct tomoyo_profile".
36 * (3) max values for "struct tomoyo_profile".
37 */
32static struct { 38static struct {
33 const char *keyword; 39 const char *keyword;
34 unsigned int current_value; 40 unsigned int current_value;
@@ -39,7 +45,13 @@ static struct {
39 [TOMOYO_VERBOSE] = { "TOMOYO_VERBOSE", 1, 1 }, 45 [TOMOYO_VERBOSE] = { "TOMOYO_VERBOSE", 1, 1 },
40}; 46};
41 47
42/* Profile table. Memory is allocated as needed. */ 48/*
49 * tomoyo_profile is a structure which is used for holding the mode of access
50 * controls. TOMOYO has 4 modes: disabled, learning, permissive, enforcing.
51 * An administrator can define up to 256 profiles.
52 * The ->profile of "struct tomoyo_domain_info" is used for remembering
53 * the profile's number (0 - 255) assigned to that domain.
54 */
43static struct tomoyo_profile { 55static struct tomoyo_profile {
44 unsigned int value[TOMOYO_MAX_CONTROL_INDEX]; 56 unsigned int value[TOMOYO_MAX_CONTROL_INDEX];
45 const struct tomoyo_path_info *comment; 57 const struct tomoyo_path_info *comment;
@@ -428,7 +440,6 @@ void tomoyo_fill_path_info(struct tomoyo_path_info *ptr)
428 const char *name = ptr->name; 440 const char *name = ptr->name;
429 const int len = strlen(name); 441 const int len = strlen(name);
430 442
431 ptr->total_len = len;
432 ptr->const_len = tomoyo_const_part_length(name); 443 ptr->const_len = tomoyo_const_part_length(name);
433 ptr->is_dir = len && (name[len - 1] == '/'); 444 ptr->is_dir = len && (name[len - 1] == '/');
434 ptr->is_patterned = (ptr->const_len < len); 445 ptr->is_patterned = (ptr->const_len < len);
@@ -866,7 +877,6 @@ static struct tomoyo_profile *tomoyo_find_or_assign_new_profile(const unsigned
866 877
867 if (profile >= TOMOYO_MAX_PROFILES) 878 if (profile >= TOMOYO_MAX_PROFILES)
868 return NULL; 879 return NULL;
869 /***** EXCLUSIVE SECTION START *****/
870 mutex_lock(&lock); 880 mutex_lock(&lock);
871 ptr = tomoyo_profile_ptr[profile]; 881 ptr = tomoyo_profile_ptr[profile];
872 if (ptr) 882 if (ptr)
@@ -880,7 +890,6 @@ static struct tomoyo_profile *tomoyo_find_or_assign_new_profile(const unsigned
880 tomoyo_profile_ptr[profile] = ptr; 890 tomoyo_profile_ptr[profile] = ptr;
881 ok: 891 ok:
882 mutex_unlock(&lock); 892 mutex_unlock(&lock);
883 /***** EXCLUSIVE SECTION END *****/
884 return ptr; 893 return ptr;
885} 894}
886 895
@@ -1009,7 +1018,19 @@ static int tomoyo_read_profile(struct tomoyo_io_buffer *head)
1009 return 0; 1018 return 0;
1010} 1019}
1011 1020
1012/* Structure for policy manager. */ 1021/*
1022 * tomoyo_policy_manager_entry is a structure which is used for holding list of
1023 * domainnames or programs which are permitted to modify configuration via
1024 * /sys/kernel/security/tomoyo/ interface.
1025 * It has following fields.
1026 *
1027 * (1) "list" which is linked to tomoyo_policy_manager_list .
1028 * (2) "manager" is a domainname or a program's pathname.
1029 * (3) "is_domain" is a bool which is true if "manager" is a domainname, false
1030 * otherwise.
1031 * (4) "is_deleted" is a bool which is true if marked as deleted, false
1032 * otherwise.
1033 */
1013struct tomoyo_policy_manager_entry { 1034struct tomoyo_policy_manager_entry {
1014 struct list_head list; 1035 struct list_head list;
1015 /* A path to program or a domainname. */ 1036 /* A path to program or a domainname. */
@@ -1018,7 +1039,36 @@ struct tomoyo_policy_manager_entry {
1018 bool is_deleted; /* True if this entry is deleted. */ 1039 bool is_deleted; /* True if this entry is deleted. */
1019}; 1040};
1020 1041
1021/* The list for "struct tomoyo_policy_manager_entry". */ 1042/*
1043 * tomoyo_policy_manager_list is used for holding list of domainnames or
1044 * programs which are permitted to modify configuration via
1045 * /sys/kernel/security/tomoyo/ interface.
1046 *
1047 * An entry is added by
1048 *
1049 * # echo '<kernel> /sbin/mingetty /bin/login /bin/bash' > \
1050 * /sys/kernel/security/tomoyo/manager
1051 * (if you want to specify by a domainname)
1052 *
1053 * or
1054 *
1055 * # echo '/usr/lib/ccs/editpolicy' > /sys/kernel/security/tomoyo/manager
1056 * (if you want to specify by a program's location)
1057 *
1058 * and is deleted by
1059 *
1060 * # echo 'delete <kernel> /sbin/mingetty /bin/login /bin/bash' > \
1061 * /sys/kernel/security/tomoyo/manager
1062 *
1063 * or
1064 *
1065 * # echo 'delete /usr/lib/ccs/editpolicy' > \
1066 * /sys/kernel/security/tomoyo/manager
1067 *
1068 * and all entries are retrieved by
1069 *
1070 * # cat /sys/kernel/security/tomoyo/manager
1071 */
1022static LIST_HEAD(tomoyo_policy_manager_list); 1072static LIST_HEAD(tomoyo_policy_manager_list);
1023static DECLARE_RWSEM(tomoyo_policy_manager_list_lock); 1073static DECLARE_RWSEM(tomoyo_policy_manager_list_lock);
1024 1074
@@ -1050,7 +1100,6 @@ static int tomoyo_update_manager_entry(const char *manager,
1050 saved_manager = tomoyo_save_name(manager); 1100 saved_manager = tomoyo_save_name(manager);
1051 if (!saved_manager) 1101 if (!saved_manager)
1052 return -ENOMEM; 1102 return -ENOMEM;
1053 /***** EXCLUSIVE SECTION START *****/
1054 down_write(&tomoyo_policy_manager_list_lock); 1103 down_write(&tomoyo_policy_manager_list_lock);
1055 list_for_each_entry(ptr, &tomoyo_policy_manager_list, list) { 1104 list_for_each_entry(ptr, &tomoyo_policy_manager_list, list) {
1056 if (ptr->manager != saved_manager) 1105 if (ptr->manager != saved_manager)
@@ -1072,7 +1121,6 @@ static int tomoyo_update_manager_entry(const char *manager,
1072 error = 0; 1121 error = 0;
1073 out: 1122 out:
1074 up_write(&tomoyo_policy_manager_list_lock); 1123 up_write(&tomoyo_policy_manager_list_lock);
1075 /***** EXCLUSIVE SECTION END *****/
1076 return error; 1124 return error;
1077} 1125}
1078 1126
@@ -1117,10 +1165,9 @@ static int tomoyo_read_manager_policy(struct tomoyo_io_buffer *head)
1117 list); 1165 list);
1118 if (ptr->is_deleted) 1166 if (ptr->is_deleted)
1119 continue; 1167 continue;
1120 if (!tomoyo_io_printf(head, "%s\n", ptr->manager->name)) { 1168 done = tomoyo_io_printf(head, "%s\n", ptr->manager->name);
1121 done = false; 1169 if (!done)
1122 break; 1170 break;
1123 }
1124 } 1171 }
1125 up_read(&tomoyo_policy_manager_list_lock); 1172 up_read(&tomoyo_policy_manager_list_lock);
1126 head->read_eof = done; 1173 head->read_eof = done;
@@ -1197,13 +1244,11 @@ static bool tomoyo_is_select_one(struct tomoyo_io_buffer *head,
1197 1244
1198 if (sscanf(data, "pid=%u", &pid) == 1) { 1245 if (sscanf(data, "pid=%u", &pid) == 1) {
1199 struct task_struct *p; 1246 struct task_struct *p;
1200 /***** CRITICAL SECTION START *****/
1201 read_lock(&tasklist_lock); 1247 read_lock(&tasklist_lock);
1202 p = find_task_by_vpid(pid); 1248 p = find_task_by_vpid(pid);
1203 if (p) 1249 if (p)
1204 domain = tomoyo_real_domain(p); 1250 domain = tomoyo_real_domain(p);
1205 read_unlock(&tasklist_lock); 1251 read_unlock(&tasklist_lock);
1206 /***** CRITICAL SECTION END *****/
1207 } else if (!strncmp(data, "domain=", 7)) { 1252 } else if (!strncmp(data, "domain=", 7)) {
1208 if (tomoyo_is_domain_def(data + 7)) { 1253 if (tomoyo_is_domain_def(data + 7)) {
1209 down_read(&tomoyo_domain_list_lock); 1254 down_read(&tomoyo_domain_list_lock);
@@ -1447,15 +1492,14 @@ static int tomoyo_read_domain_policy(struct tomoyo_io_buffer *head)
1447 TOMOYO_DOMAIN_FLAGS_IGNORE_GLOBAL_ALLOW_READ) 1492 TOMOYO_DOMAIN_FLAGS_IGNORE_GLOBAL_ALLOW_READ)
1448 ignore_global_allow_read 1493 ignore_global_allow_read
1449 = TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "\n"; 1494 = TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "\n";
1450 if (!tomoyo_io_printf(head, 1495 done = tomoyo_io_printf(head, "%s\n" TOMOYO_KEYWORD_USE_PROFILE
1451 "%s\n" TOMOYO_KEYWORD_USE_PROFILE "%u\n" 1496 "%u\n%s%s%s\n",
1452 "%s%s%s\n", domain->domainname->name, 1497 domain->domainname->name,
1453 domain->profile, quota_exceeded, 1498 domain->profile, quota_exceeded,
1454 transition_failed, 1499 transition_failed,
1455 ignore_global_allow_read)) { 1500 ignore_global_allow_read);
1456 done = false; 1501 if (!done)
1457 break; 1502 break;
1458 }
1459 head->read_step = 2; 1503 head->read_step = 2;
1460acl_loop: 1504acl_loop:
1461 if (head->read_step == 3) 1505 if (head->read_step == 3)
@@ -1463,24 +1507,22 @@ acl_loop:
1463 /* Print ACL entries in the domain. */ 1507 /* Print ACL entries in the domain. */
1464 down_read(&tomoyo_domain_acl_info_list_lock); 1508 down_read(&tomoyo_domain_acl_info_list_lock);
1465 list_for_each_cookie(apos, head->read_var2, 1509 list_for_each_cookie(apos, head->read_var2,
1466 &domain->acl_info_list) { 1510 &domain->acl_info_list) {
1467 struct tomoyo_acl_info *ptr 1511 struct tomoyo_acl_info *ptr
1468 = list_entry(apos, struct tomoyo_acl_info, 1512 = list_entry(apos, struct tomoyo_acl_info,
1469 list); 1513 list);
1470 if (!tomoyo_print_entry(head, ptr)) { 1514 done = tomoyo_print_entry(head, ptr);
1471 done = false; 1515 if (!done)
1472 break; 1516 break;
1473 }
1474 } 1517 }
1475 up_read(&tomoyo_domain_acl_info_list_lock); 1518 up_read(&tomoyo_domain_acl_info_list_lock);
1476 if (!done) 1519 if (!done)
1477 break; 1520 break;
1478 head->read_step = 3; 1521 head->read_step = 3;
1479tail_mark: 1522tail_mark:
1480 if (!tomoyo_io_printf(head, "\n")) { 1523 done = tomoyo_io_printf(head, "\n");
1481 done = false; 1524 if (!done)
1482 break; 1525 break;
1483 }
1484 head->read_step = 1; 1526 head->read_step = 1;
1485 if (head->read_single_domain) 1527 if (head->read_single_domain)
1486 break; 1528 break;
@@ -1550,11 +1592,10 @@ static int tomoyo_read_domain_profile(struct tomoyo_io_buffer *head)
1550 domain = list_entry(pos, struct tomoyo_domain_info, list); 1592 domain = list_entry(pos, struct tomoyo_domain_info, list);
1551 if (domain->is_deleted) 1593 if (domain->is_deleted)
1552 continue; 1594 continue;
1553 if (!tomoyo_io_printf(head, "%u %s\n", domain->profile, 1595 done = tomoyo_io_printf(head, "%u %s\n", domain->profile,
1554 domain->domainname->name)) { 1596 domain->domainname->name);
1555 done = false; 1597 if (!done)
1556 break; 1598 break;
1557 }
1558 } 1599 }
1559 up_read(&tomoyo_domain_list_lock); 1600 up_read(&tomoyo_domain_list_lock);
1560 head->read_eof = done; 1601 head->read_eof = done;
@@ -1594,13 +1635,11 @@ static int tomoyo_read_pid(struct tomoyo_io_buffer *head)
1594 const int pid = head->read_step; 1635 const int pid = head->read_step;
1595 struct task_struct *p; 1636 struct task_struct *p;
1596 struct tomoyo_domain_info *domain = NULL; 1637 struct tomoyo_domain_info *domain = NULL;
1597 /***** CRITICAL SECTION START *****/
1598 read_lock(&tasklist_lock); 1638 read_lock(&tasklist_lock);
1599 p = find_task_by_vpid(pid); 1639 p = find_task_by_vpid(pid);
1600 if (p) 1640 if (p)
1601 domain = tomoyo_real_domain(p); 1641 domain = tomoyo_real_domain(p);
1602 read_unlock(&tasklist_lock); 1642 read_unlock(&tasklist_lock);
1603 /***** CRITICAL SECTION END *****/
1604 if (domain) 1643 if (domain)
1605 tomoyo_io_printf(head, "%d %u %s", pid, domain->profile, 1644 tomoyo_io_printf(head, "%d %u %s", pid, domain->profile,
1606 domain->domainname->name); 1645 domain->domainname->name);
@@ -2138,7 +2177,13 @@ static ssize_t tomoyo_write(struct file *file, const char __user *buf,
2138 return tomoyo_write_control(file, buf, count); 2177 return tomoyo_write_control(file, buf, count);
2139} 2178}
2140 2179
2141/* Operations for /sys/kernel/security/tomoyo/ interface. */ 2180/*
2181 * tomoyo_operations is a "struct file_operations" which is used for handling
2182 * /sys/kernel/security/tomoyo/ interface.
2183 *
2184 * Some files under /sys/kernel/security/tomoyo/ directory accept open(O_RDWR).
2185 * See tomoyo_io_buffer for internals.
2186 */
2142static const struct file_operations tomoyo_operations = { 2187static const struct file_operations tomoyo_operations = {
2143 .open = tomoyo_open, 2188 .open = tomoyo_open,
2144 .release = tomoyo_release, 2189 .release = tomoyo_release,
diff --git a/security/tomoyo/common.h b/security/tomoyo/common.h
index 678f4ff16aa4..6d6ba09af457 100644
--- a/security/tomoyo/common.h
+++ b/security/tomoyo/common.h
@@ -26,16 +26,43 @@
26struct dentry; 26struct dentry;
27struct vfsmount; 27struct vfsmount;
28 28
29/* Temporary buffer for holding pathnames. */ 29/*
30 * tomoyo_page_buffer is a structure which is used for holding a pathname
31 * obtained from "struct dentry" and "struct vfsmount" pair.
32 * As of now, it is 4096 bytes. If users complain that 4096 bytes is too small
33 * (because TOMOYO escapes non ASCII printable characters using \ooo format),
34 * we will make the buffer larger.
35 */
30struct tomoyo_page_buffer { 36struct tomoyo_page_buffer {
31 char buffer[4096]; 37 char buffer[4096];
32}; 38};
33 39
34/* Structure for holding a token. */ 40/*
41 * tomoyo_path_info is a structure which is used for holding a string data
42 * used by TOMOYO.
43 * This structure has several fields for supporting pattern matching.
44 *
45 * (1) "name" is the '\0' terminated string data.
46 * (2) "hash" is full_name_hash(name, strlen(name)).
47 * This allows tomoyo_pathcmp() to compare by hash before actually compare
48 * using strcmp().
49 * (3) "const_len" is the length of the initial segment of "name" which
50 * consists entirely of non wildcard characters. In other words, the length
51 * which we can compare two strings using strncmp().
52 * (4) "is_dir" is a bool which is true if "name" ends with "/",
53 * false otherwise.
54 * TOMOYO distinguishes directory and non-directory. A directory ends with
55 * "/" and non-directory does not end with "/".
56 * (5) "is_patterned" is a bool which is true if "name" contains wildcard
57 * characters, false otherwise. This allows TOMOYO to use "hash" and
58 * strcmp() for string comparison if "is_patterned" is false.
59 * (6) "depth" is calculated using the number of "/" characters in "name".
60 * This allows TOMOYO to avoid comparing two pathnames which never match
61 * (e.g. whether "/var/www/html/index.html" matches "/tmp/sh-thd-\$").
62 */
35struct tomoyo_path_info { 63struct tomoyo_path_info {
36 const char *name; 64 const char *name;
37 u32 hash; /* = full_name_hash(name, strlen(name)) */ 65 u32 hash; /* = full_name_hash(name, strlen(name)) */
38 u16 total_len; /* = strlen(name) */
39 u16 const_len; /* = tomoyo_const_part_length(name) */ 66 u16 const_len; /* = tomoyo_const_part_length(name) */
40 bool is_dir; /* = tomoyo_strendswith(name, "/") */ 67 bool is_dir; /* = tomoyo_strendswith(name, "/") */
41 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */ 68 bool is_patterned; /* = tomoyo_path_contains_pattern(name) */
@@ -51,7 +78,20 @@ struct tomoyo_path_info {
51 */ 78 */
52#define TOMOYO_MAX_PATHNAME_LEN 4000 79#define TOMOYO_MAX_PATHNAME_LEN 4000
53 80
54/* Structure for holding requested pathname. */ 81/*
82 * tomoyo_path_info_with_data is a structure which is used for holding a
83 * pathname obtained from "struct dentry" and "struct vfsmount" pair.
84 *
85 * "struct tomoyo_path_info_with_data" consists of "struct tomoyo_path_info"
86 * and buffer for the pathname, while "struct tomoyo_page_buffer" consists of
87 * buffer for the pathname only.
88 *
89 * "struct tomoyo_path_info_with_data" is intended to allow TOMOYO to release
90 * both "struct tomoyo_path_info" and buffer for the pathname by single kfree()
91 * so that we don't need to return two pointers to the caller. If the caller
92 * puts "struct tomoyo_path_info" on stack memory, we will be able to remove
93 * "struct tomoyo_path_info_with_data".
94 */
55struct tomoyo_path_info_with_data { 95struct tomoyo_path_info_with_data {
56 /* Keep "head" first, for this pointer is passed to tomoyo_free(). */ 96 /* Keep "head" first, for this pointer is passed to tomoyo_free(). */
57 struct tomoyo_path_info head; 97 struct tomoyo_path_info head;
@@ -61,7 +101,15 @@ struct tomoyo_path_info_with_data {
61}; 101};
62 102
63/* 103/*
64 * Common header for holding ACL entries. 104 * tomoyo_acl_info is a structure which is used for holding
105 *
106 * (1) "list" which is linked to the ->acl_info_list of
107 * "struct tomoyo_domain_info"
108 * (2) "type" which tells
109 * (a) type & 0x7F : type of the entry (either
110 * "struct tomoyo_single_path_acl_record" or
111 * "struct tomoyo_double_path_acl_record")
112 * (b) type & 0x80 : whether the entry is marked as "deleted".
65 * 113 *
66 * Packing "struct tomoyo_acl_info" allows 114 * Packing "struct tomoyo_acl_info" allows
67 * "struct tomoyo_single_path_acl_record" to embed "u16" and 115 * "struct tomoyo_single_path_acl_record" to embed "u16" and
@@ -81,7 +129,28 @@ struct tomoyo_acl_info {
81/* This ACL entry is deleted. */ 129/* This ACL entry is deleted. */
82#define TOMOYO_ACL_DELETED 0x80 130#define TOMOYO_ACL_DELETED 0x80
83 131
84/* Structure for domain information. */ 132/*
133 * tomoyo_domain_info is a structure which is used for holding permissions
134 * (e.g. "allow_read /lib/libc-2.5.so") given to each domain.
135 * It has following fields.
136 *
137 * (1) "list" which is linked to tomoyo_domain_list .
138 * (2) "acl_info_list" which is linked to "struct tomoyo_acl_info".
139 * (3) "domainname" which holds the name of the domain.
140 * (4) "profile" which remembers profile number assigned to this domain.
141 * (5) "is_deleted" is a bool which is true if this domain is marked as
142 * "deleted", false otherwise.
143 * (6) "quota_warned" is a bool which is used for suppressing warning message
144 * when learning mode learned too much entries.
145 * (7) "flags" which remembers this domain's attributes.
146 *
147 * A domain's lifecycle is an analogy of files on / directory.
148 * Multiple domains with the same domainname cannot be created (as with
149 * creating files with the same filename fails with -EEXIST).
150 * If a process reached a domain, that process can reside in that domain after
151 * that domain is marked as "deleted" (as with a process can access an already
152 * open()ed file after that file was unlink()ed).
153 */
85struct tomoyo_domain_info { 154struct tomoyo_domain_info {
86 struct list_head list; 155 struct list_head list;
87 struct list_head acl_info_list; 156 struct list_head acl_info_list;
@@ -108,10 +177,18 @@ struct tomoyo_domain_info {
108#define TOMOYO_DOMAIN_FLAGS_TRANSITION_FAILED 2 177#define TOMOYO_DOMAIN_FLAGS_TRANSITION_FAILED 2
109 178
110/* 179/*
111 * Structure for "allow_read/write", "allow_execute", "allow_read", 180 * tomoyo_single_path_acl_record is a structure which is used for holding an
112 * "allow_write", "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir", 181 * entry with one pathname operation (e.g. open(), mkdir()).
113 * "allow_mkfifo", "allow_mksock", "allow_mkblock", "allow_mkchar", 182 * It has following fields.
114 * "allow_truncate", "allow_symlink" and "allow_rewrite" directive. 183 *
184 * (1) "head" which is a "struct tomoyo_acl_info".
185 * (2) "perm" which is a bitmask of permitted operations.
186 * (3) "filename" is the pathname.
187 *
188 * Directives held by this structure are "allow_read/write", "allow_execute",
189 * "allow_read", "allow_write", "allow_create", "allow_unlink", "allow_mkdir",
190 * "allow_rmdir", "allow_mkfifo", "allow_mksock", "allow_mkblock",
191 * "allow_mkchar", "allow_truncate", "allow_symlink" and "allow_rewrite".
115 */ 192 */
116struct tomoyo_single_path_acl_record { 193struct tomoyo_single_path_acl_record {
117 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_SINGLE_PATH_ACL */ 194 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_SINGLE_PATH_ACL */
@@ -120,7 +197,18 @@ struct tomoyo_single_path_acl_record {
120 const struct tomoyo_path_info *filename; 197 const struct tomoyo_path_info *filename;
121}; 198};
122 199
123/* Structure for "allow_rename" and "allow_link" directive. */ 200/*
201 * tomoyo_double_path_acl_record is a structure which is used for holding an
202 * entry with two pathnames operation (i.e. link() and rename()).
203 * It has following fields.
204 *
205 * (1) "head" which is a "struct tomoyo_acl_info".
206 * (2) "perm" which is a bitmask of permitted operations.
207 * (3) "filename1" is the source/old pathname.
208 * (4) "filename2" is the destination/new pathname.
209 *
210 * Directives held by this structure are "allow_rename" and "allow_link".
211 */
124struct tomoyo_double_path_acl_record { 212struct tomoyo_double_path_acl_record {
125 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_DOUBLE_PATH_ACL */ 213 struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_DOUBLE_PATH_ACL */
126 u8 perm; 214 u8 perm;
@@ -153,7 +241,29 @@ struct tomoyo_double_path_acl_record {
153#define TOMOYO_VERBOSE 2 241#define TOMOYO_VERBOSE 2
154#define TOMOYO_MAX_CONTROL_INDEX 3 242#define TOMOYO_MAX_CONTROL_INDEX 3
155 243
156/* Structure for reading/writing policy via securityfs interfaces. */ 244/*
245 * tomoyo_io_buffer is a structure which is used for reading and modifying
246 * configuration via /sys/kernel/security/tomoyo/ interface.
247 * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as
248 * cursors.
249 *
250 * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of
251 * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info"
252 * entry has a list of "struct tomoyo_acl_info", we need two cursors when
253 * reading (one is for traversing tomoyo_domain_list and the other is for
254 * traversing "struct tomoyo_acl_info"->acl_info_list ).
255 *
256 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
257 * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the
258 * domain with the domainname specified by the rest of that line (NULL is set
259 * if seek failed).
260 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
261 * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that
262 * line (->write_var1 is set to NULL if a domain was deleted).
263 * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
264 * neither "select " nor "delete ", an entry or a domain specified by that line
265 * is appended.
266 */
157struct tomoyo_io_buffer { 267struct tomoyo_io_buffer {
158 int (*read) (struct tomoyo_io_buffer *); 268 int (*read) (struct tomoyo_io_buffer *);
159 int (*write) (struct tomoyo_io_buffer *); 269 int (*write) (struct tomoyo_io_buffer *);
diff --git a/security/tomoyo/domain.c b/security/tomoyo/domain.c
index 2d6748741a26..1d8b16960576 100644
--- a/security/tomoyo/domain.c
+++ b/security/tomoyo/domain.c
@@ -19,11 +19,63 @@
19/* The initial domain. */ 19/* The initial domain. */
20struct tomoyo_domain_info tomoyo_kernel_domain; 20struct tomoyo_domain_info tomoyo_kernel_domain;
21 21
22/* The list for "struct tomoyo_domain_info". */ 22/*
23 * tomoyo_domain_list is used for holding list of domains.
24 * The ->acl_info_list of "struct tomoyo_domain_info" is used for holding
25 * permissions (e.g. "allow_read /lib/libc-2.5.so") given to each domain.
26 *
27 * An entry is added by
28 *
29 * # ( echo "<kernel>"; echo "allow_execute /sbin/init" ) > \
30 * /sys/kernel/security/tomoyo/domain_policy
31 *
32 * and is deleted by
33 *
34 * # ( echo "<kernel>"; echo "delete allow_execute /sbin/init" ) > \
35 * /sys/kernel/security/tomoyo/domain_policy
36 *
37 * and all entries are retrieved by
38 *
39 * # cat /sys/kernel/security/tomoyo/domain_policy
40 *
41 * A domain is added by
42 *
43 * # echo "<kernel>" > /sys/kernel/security/tomoyo/domain_policy
44 *
45 * and is deleted by
46 *
47 * # echo "delete <kernel>" > /sys/kernel/security/tomoyo/domain_policy
48 *
49 * and all domains are retrieved by
50 *
51 * # grep '^<kernel>' /sys/kernel/security/tomoyo/domain_policy
52 *
53 * Normally, a domainname is monotonically getting longer because a domainname
54 * which the process will belong to if an execve() operation succeeds is
55 * defined as a concatenation of "current domainname" + "pathname passed to
56 * execve()".
57 * See tomoyo_domain_initializer_list and tomoyo_domain_keeper_list for
58 * exceptions.
59 */
23LIST_HEAD(tomoyo_domain_list); 60LIST_HEAD(tomoyo_domain_list);
24DECLARE_RWSEM(tomoyo_domain_list_lock); 61DECLARE_RWSEM(tomoyo_domain_list_lock);
25 62
26/* Structure for "initialize_domain" and "no_initialize_domain" keyword. */ 63/*
64 * tomoyo_domain_initializer_entry is a structure which is used for holding
65 * "initialize_domain" and "no_initialize_domain" entries.
66 * It has following fields.
67 *
68 * (1) "list" which is linked to tomoyo_domain_initializer_list .
69 * (2) "domainname" which is "a domainname" or "the last component of a
70 * domainname". This field is NULL if "from" clause is not specified.
71 * (3) "program" which is a program's pathname.
72 * (4) "is_deleted" is a bool which is true if marked as deleted, false
73 * otherwise.
74 * (5) "is_not" is a bool which is true if "no_initialize_domain", false
75 * otherwise.
76 * (6) "is_last_name" is a bool which is true if "domainname" is "the last
77 * component of a domainname", false otherwise.
78 */
27struct tomoyo_domain_initializer_entry { 79struct tomoyo_domain_initializer_entry {
28 struct list_head list; 80 struct list_head list;
29 const struct tomoyo_path_info *domainname; /* This may be NULL */ 81 const struct tomoyo_path_info *domainname; /* This may be NULL */
@@ -34,7 +86,23 @@ struct tomoyo_domain_initializer_entry {
34 bool is_last_name; 86 bool is_last_name;
35}; 87};
36 88
37/* Structure for "keep_domain" and "no_keep_domain" keyword. */ 89/*
90 * tomoyo_domain_keeper_entry is a structure which is used for holding
91 * "keep_domain" and "no_keep_domain" entries.
92 * It has following fields.
93 *
94 * (1) "list" which is linked to tomoyo_domain_keeper_list .
95 * (2) "domainname" which is "a domainname" or "the last component of a
96 * domainname".
97 * (3) "program" which is a program's pathname.
98 * This field is NULL if "from" clause is not specified.
99 * (4) "is_deleted" is a bool which is true if marked as deleted, false
100 * otherwise.
101 * (5) "is_not" is a bool which is true if "no_initialize_domain", false
102 * otherwise.
103 * (6) "is_last_name" is a bool which is true if "domainname" is "the last
104 * component of a domainname", false otherwise.
105 */
38struct tomoyo_domain_keeper_entry { 106struct tomoyo_domain_keeper_entry {
39 struct list_head list; 107 struct list_head list;
40 const struct tomoyo_path_info *domainname; 108 const struct tomoyo_path_info *domainname;
@@ -45,7 +113,16 @@ struct tomoyo_domain_keeper_entry {
45 bool is_last_name; 113 bool is_last_name;
46}; 114};
47 115
48/* Structure for "alias" keyword. */ 116/*
117 * tomoyo_alias_entry is a structure which is used for holding "alias" entries.
118 * It has following fields.
119 *
120 * (1) "list" which is linked to tomoyo_alias_list .
121 * (2) "original_name" which is a dereferenced pathname.
122 * (3) "aliased_name" which is a symlink's pathname.
123 * (4) "is_deleted" is a bool which is true if marked as deleted, false
124 * otherwise.
125 */
49struct tomoyo_alias_entry { 126struct tomoyo_alias_entry {
50 struct list_head list; 127 struct list_head list;
51 const struct tomoyo_path_info *original_name; 128 const struct tomoyo_path_info *original_name;
@@ -67,14 +144,12 @@ void tomoyo_set_domain_flag(struct tomoyo_domain_info *domain,
67{ 144{
68 /* We need to serialize because this is bitfield operation. */ 145 /* We need to serialize because this is bitfield operation. */
69 static DEFINE_SPINLOCK(lock); 146 static DEFINE_SPINLOCK(lock);
70 /***** CRITICAL SECTION START *****/
71 spin_lock(&lock); 147 spin_lock(&lock);
72 if (!is_delete) 148 if (!is_delete)
73 domain->flags |= flags; 149 domain->flags |= flags;
74 else 150 else
75 domain->flags &= ~flags; 151 domain->flags &= ~flags;
76 spin_unlock(&lock); 152 spin_unlock(&lock);
77 /***** CRITICAL SECTION END *****/
78} 153}
79 154
80/** 155/**
@@ -94,7 +169,42 @@ const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain)
94 return cp0; 169 return cp0;
95} 170}
96 171
97/* The list for "struct tomoyo_domain_initializer_entry". */ 172/*
173 * tomoyo_domain_initializer_list is used for holding list of programs which
174 * triggers reinitialization of domainname. Normally, a domainname is
175 * monotonically getting longer. But sometimes, we restart daemon programs.
176 * It would be convenient for us that "a daemon started upon system boot" and
177 * "the daemon restarted from console" belong to the same domain. Thus, TOMOYO
178 * provides a way to shorten domainnames.
179 *
180 * An entry is added by
181 *
182 * # echo 'initialize_domain /usr/sbin/httpd' > \
183 * /sys/kernel/security/tomoyo/exception_policy
184 *
185 * and is deleted by
186 *
187 * # echo 'delete initialize_domain /usr/sbin/httpd' > \
188 * /sys/kernel/security/tomoyo/exception_policy
189 *
190 * and all entries are retrieved by
191 *
192 * # grep ^initialize_domain /sys/kernel/security/tomoyo/exception_policy
193 *
194 * In the example above, /usr/sbin/httpd will belong to
195 * "<kernel> /usr/sbin/httpd" domain.
196 *
197 * You may specify a domainname using "from" keyword.
198 * "initialize_domain /usr/sbin/httpd from <kernel> /etc/rc.d/init.d/httpd"
199 * will cause "/usr/sbin/httpd" executed from "<kernel> /etc/rc.d/init.d/httpd"
200 * domain to belong to "<kernel> /usr/sbin/httpd" domain.
201 *
202 * You may add "no_" prefix to "initialize_domain".
203 * "initialize_domain /usr/sbin/httpd" and
204 * "no_initialize_domain /usr/sbin/httpd from <kernel> /etc/rc.d/init.d/httpd"
205 * will cause "/usr/sbin/httpd" to belong to "<kernel> /usr/sbin/httpd" domain
206 * unless executed from "<kernel> /etc/rc.d/init.d/httpd" domain.
207 */
98static LIST_HEAD(tomoyo_domain_initializer_list); 208static LIST_HEAD(tomoyo_domain_initializer_list);
99static DECLARE_RWSEM(tomoyo_domain_initializer_list_lock); 209static DECLARE_RWSEM(tomoyo_domain_initializer_list_lock);
100 210
@@ -135,7 +245,6 @@ static int tomoyo_update_domain_initializer_entry(const char *domainname,
135 saved_program = tomoyo_save_name(program); 245 saved_program = tomoyo_save_name(program);
136 if (!saved_program) 246 if (!saved_program)
137 return -ENOMEM; 247 return -ENOMEM;
138 /***** EXCLUSIVE SECTION START *****/
139 down_write(&tomoyo_domain_initializer_list_lock); 248 down_write(&tomoyo_domain_initializer_list_lock);
140 list_for_each_entry(ptr, &tomoyo_domain_initializer_list, list) { 249 list_for_each_entry(ptr, &tomoyo_domain_initializer_list, list) {
141 if (ptr->is_not != is_not || 250 if (ptr->is_not != is_not ||
@@ -161,7 +270,6 @@ static int tomoyo_update_domain_initializer_entry(const char *domainname,
161 error = 0; 270 error = 0;
162 out: 271 out:
163 up_write(&tomoyo_domain_initializer_list_lock); 272 up_write(&tomoyo_domain_initializer_list_lock);
164 /***** EXCLUSIVE SECTION END *****/
165 return error; 273 return error;
166} 274}
167 275
@@ -193,13 +301,12 @@ bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head)
193 from = " from "; 301 from = " from ";
194 domain = ptr->domainname->name; 302 domain = ptr->domainname->name;
195 } 303 }
196 if (!tomoyo_io_printf(head, 304 done = tomoyo_io_printf(head,
197 "%s" TOMOYO_KEYWORD_INITIALIZE_DOMAIN 305 "%s" TOMOYO_KEYWORD_INITIALIZE_DOMAIN
198 "%s%s%s\n", no, ptr->program->name, from, 306 "%s%s%s\n", no, ptr->program->name,
199 domain)) { 307 from, domain);
200 done = false; 308 if (!done)
201 break; 309 break;
202 }
203 } 310 }
204 up_read(&tomoyo_domain_initializer_list_lock); 311 up_read(&tomoyo_domain_initializer_list_lock);
205 return done; 312 return done;
@@ -273,7 +380,44 @@ static bool tomoyo_is_domain_initializer(const struct tomoyo_path_info *
273 return flag; 380 return flag;
274} 381}
275 382
276/* The list for "struct tomoyo_domain_keeper_entry". */ 383/*
384 * tomoyo_domain_keeper_list is used for holding list of domainnames which
385 * suppresses domain transition. Normally, a domainname is monotonically
386 * getting longer. But sometimes, we want to suppress domain transition.
387 * It would be convenient for us that programs executed from a login session
388 * belong to the same domain. Thus, TOMOYO provides a way to suppress domain
389 * transition.
390 *
391 * An entry is added by
392 *
393 * # echo 'keep_domain <kernel> /usr/sbin/sshd /bin/bash' > \
394 * /sys/kernel/security/tomoyo/exception_policy
395 *
396 * and is deleted by
397 *
398 * # echo 'delete keep_domain <kernel> /usr/sbin/sshd /bin/bash' > \
399 * /sys/kernel/security/tomoyo/exception_policy
400 *
401 * and all entries are retrieved by
402 *
403 * # grep ^keep_domain /sys/kernel/security/tomoyo/exception_policy
404 *
405 * In the example above, any process which belongs to
406 * "<kernel> /usr/sbin/sshd /bin/bash" domain will remain in that domain,
407 * unless explicitly specified by "initialize_domain" or "no_keep_domain".
408 *
409 * You may specify a program using "from" keyword.
410 * "keep_domain /bin/pwd from <kernel> /usr/sbin/sshd /bin/bash"
411 * will cause "/bin/pwd" executed from "<kernel> /usr/sbin/sshd /bin/bash"
412 * domain to remain in "<kernel> /usr/sbin/sshd /bin/bash" domain.
413 *
414 * You may add "no_" prefix to "keep_domain".
415 * "keep_domain <kernel> /usr/sbin/sshd /bin/bash" and
416 * "no_keep_domain /usr/bin/passwd from <kernel> /usr/sbin/sshd /bin/bash" will
417 * cause "/usr/bin/passwd" to belong to
418 * "<kernel> /usr/sbin/sshd /bin/bash /usr/bin/passwd" domain, unless
419 * explicitly specified by "initialize_domain".
420 */
277static LIST_HEAD(tomoyo_domain_keeper_list); 421static LIST_HEAD(tomoyo_domain_keeper_list);
278static DECLARE_RWSEM(tomoyo_domain_keeper_list_lock); 422static DECLARE_RWSEM(tomoyo_domain_keeper_list_lock);
279 423
@@ -296,7 +440,6 @@ static int tomoyo_update_domain_keeper_entry(const char *domainname,
296 struct tomoyo_domain_keeper_entry *ptr; 440 struct tomoyo_domain_keeper_entry *ptr;
297 const struct tomoyo_path_info *saved_domainname; 441 const struct tomoyo_path_info *saved_domainname;
298 const struct tomoyo_path_info *saved_program = NULL; 442 const struct tomoyo_path_info *saved_program = NULL;
299 static DEFINE_MUTEX(lock);
300 int error = -ENOMEM; 443 int error = -ENOMEM;
301 bool is_last_name = false; 444 bool is_last_name = false;
302 445
@@ -315,7 +458,6 @@ static int tomoyo_update_domain_keeper_entry(const char *domainname,
315 saved_domainname = tomoyo_save_name(domainname); 458 saved_domainname = tomoyo_save_name(domainname);
316 if (!saved_domainname) 459 if (!saved_domainname)
317 return -ENOMEM; 460 return -ENOMEM;
318 /***** EXCLUSIVE SECTION START *****/
319 down_write(&tomoyo_domain_keeper_list_lock); 461 down_write(&tomoyo_domain_keeper_list_lock);
320 list_for_each_entry(ptr, &tomoyo_domain_keeper_list, list) { 462 list_for_each_entry(ptr, &tomoyo_domain_keeper_list, list) {
321 if (ptr->is_not != is_not || 463 if (ptr->is_not != is_not ||
@@ -341,7 +483,6 @@ static int tomoyo_update_domain_keeper_entry(const char *domainname,
341 error = 0; 483 error = 0;
342 out: 484 out:
343 up_write(&tomoyo_domain_keeper_list_lock); 485 up_write(&tomoyo_domain_keeper_list_lock);
344 /***** EXCLUSIVE SECTION END *****/
345 return error; 486 return error;
346} 487}
347 488
@@ -394,13 +535,12 @@ bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head)
394 from = " from "; 535 from = " from ";
395 program = ptr->program->name; 536 program = ptr->program->name;
396 } 537 }
397 if (!tomoyo_io_printf(head, 538 done = tomoyo_io_printf(head,
398 "%s" TOMOYO_KEYWORD_KEEP_DOMAIN 539 "%s" TOMOYO_KEYWORD_KEEP_DOMAIN
399 "%s%s%s\n", no, program, from, 540 "%s%s%s\n", no, program, from,
400 ptr->domainname->name)) { 541 ptr->domainname->name);
401 done = false; 542 if (!done)
402 break; 543 break;
403 }
404 } 544 }
405 up_read(&tomoyo_domain_keeper_list_lock); 545 up_read(&tomoyo_domain_keeper_list_lock);
406 return done; 546 return done;
@@ -446,7 +586,36 @@ static bool tomoyo_is_domain_keeper(const struct tomoyo_path_info *domainname,
446 return flag; 586 return flag;
447} 587}
448 588
449/* The list for "struct tomoyo_alias_entry". */ 589/*
590 * tomoyo_alias_list is used for holding list of symlink's pathnames which are
591 * allowed to be passed to an execve() request. Normally, the domainname which
592 * the current process will belong to after execve() succeeds is calculated
593 * using dereferenced pathnames. But some programs behave differently depending
594 * on the name passed to argv[0]. For busybox, calculating domainname using
595 * dereferenced pathnames will cause all programs in the busybox to belong to
596 * the same domain. Thus, TOMOYO provides a way to allow use of symlink's
597 * pathname for checking execve()'s permission and calculating domainname which
598 * the current process will belong to after execve() succeeds.
599 *
600 * An entry is added by
601 *
602 * # echo 'alias /bin/busybox /bin/cat' > \
603 * /sys/kernel/security/tomoyo/exception_policy
604 *
605 * and is deleted by
606 *
607 * # echo 'delete alias /bin/busybox /bin/cat' > \
608 * /sys/kernel/security/tomoyo/exception_policy
609 *
610 * and all entries are retrieved by
611 *
612 * # grep ^alias /sys/kernel/security/tomoyo/exception_policy
613 *
614 * In the example above, if /bin/cat is a symlink to /bin/busybox and execution
615 * of /bin/cat is requested, permission is checked for /bin/cat rather than
616 * /bin/busybox and domainname which the current process will belong to after
617 * execve() succeeds is calculated using /bin/cat rather than /bin/busybox .
618 */
450static LIST_HEAD(tomoyo_alias_list); 619static LIST_HEAD(tomoyo_alias_list);
451static DECLARE_RWSEM(tomoyo_alias_list_lock); 620static DECLARE_RWSEM(tomoyo_alias_list_lock);
452 621
@@ -476,7 +645,6 @@ static int tomoyo_update_alias_entry(const char *original_name,
476 saved_aliased_name = tomoyo_save_name(aliased_name); 645 saved_aliased_name = tomoyo_save_name(aliased_name);
477 if (!saved_original_name || !saved_aliased_name) 646 if (!saved_original_name || !saved_aliased_name)
478 return -ENOMEM; 647 return -ENOMEM;
479 /***** EXCLUSIVE SECTION START *****/
480 down_write(&tomoyo_alias_list_lock); 648 down_write(&tomoyo_alias_list_lock);
481 list_for_each_entry(ptr, &tomoyo_alias_list, list) { 649 list_for_each_entry(ptr, &tomoyo_alias_list, list) {
482 if (ptr->original_name != saved_original_name || 650 if (ptr->original_name != saved_original_name ||
@@ -499,7 +667,6 @@ static int tomoyo_update_alias_entry(const char *original_name,
499 error = 0; 667 error = 0;
500 out: 668 out:
501 up_write(&tomoyo_alias_list_lock); 669 up_write(&tomoyo_alias_list_lock);
502 /***** EXCLUSIVE SECTION END *****/
503 return error; 670 return error;
504} 671}
505 672
@@ -522,12 +689,11 @@ bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head)
522 ptr = list_entry(pos, struct tomoyo_alias_entry, list); 689 ptr = list_entry(pos, struct tomoyo_alias_entry, list);
523 if (ptr->is_deleted) 690 if (ptr->is_deleted)
524 continue; 691 continue;
525 if (!tomoyo_io_printf(head, TOMOYO_KEYWORD_ALIAS "%s %s\n", 692 done = tomoyo_io_printf(head, TOMOYO_KEYWORD_ALIAS "%s %s\n",
526 ptr->original_name->name, 693 ptr->original_name->name,
527 ptr->aliased_name->name)) { 694 ptr->aliased_name->name);
528 done = false; 695 if (!done)
529 break; 696 break;
530 }
531 } 697 }
532 up_read(&tomoyo_alias_list_lock); 698 up_read(&tomoyo_alias_list_lock);
533 return done; 699 return done;
@@ -567,7 +733,6 @@ int tomoyo_delete_domain(char *domainname)
567 733
568 name.name = domainname; 734 name.name = domainname;
569 tomoyo_fill_path_info(&name); 735 tomoyo_fill_path_info(&name);
570 /***** EXCLUSIVE SECTION START *****/
571 down_write(&tomoyo_domain_list_lock); 736 down_write(&tomoyo_domain_list_lock);
572 /* Is there an active domain? */ 737 /* Is there an active domain? */
573 list_for_each_entry(domain, &tomoyo_domain_list, list) { 738 list_for_each_entry(domain, &tomoyo_domain_list, list) {
@@ -581,7 +746,6 @@ int tomoyo_delete_domain(char *domainname)
581 break; 746 break;
582 } 747 }
583 up_write(&tomoyo_domain_list_lock); 748 up_write(&tomoyo_domain_list_lock);
584 /***** EXCLUSIVE SECTION END *****/
585 return 0; 749 return 0;
586} 750}
587 751
@@ -600,7 +764,6 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
600 struct tomoyo_domain_info *domain = NULL; 764 struct tomoyo_domain_info *domain = NULL;
601 const struct tomoyo_path_info *saved_domainname; 765 const struct tomoyo_path_info *saved_domainname;
602 766
603 /***** EXCLUSIVE SECTION START *****/
604 down_write(&tomoyo_domain_list_lock); 767 down_write(&tomoyo_domain_list_lock);
605 domain = tomoyo_find_domain(domainname); 768 domain = tomoyo_find_domain(domainname);
606 if (domain) 769 if (domain)
@@ -619,7 +782,6 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
619 domain->domainname != saved_domainname) 782 domain->domainname != saved_domainname)
620 continue; 783 continue;
621 flag = false; 784 flag = false;
622 /***** CRITICAL SECTION START *****/
623 read_lock(&tasklist_lock); 785 read_lock(&tasklist_lock);
624 for_each_process(p) { 786 for_each_process(p) {
625 if (tomoyo_real_domain(p) != domain) 787 if (tomoyo_real_domain(p) != domain)
@@ -628,7 +790,6 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
628 break; 790 break;
629 } 791 }
630 read_unlock(&tasklist_lock); 792 read_unlock(&tasklist_lock);
631 /***** CRITICAL SECTION END *****/
632 if (flag) 793 if (flag)
633 continue; 794 continue;
634 list_for_each_entry(ptr, &domain->acl_info_list, list) { 795 list_for_each_entry(ptr, &domain->acl_info_list, list) {
@@ -651,7 +812,6 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
651 } 812 }
652 out: 813 out:
653 up_write(&tomoyo_domain_list_lock); 814 up_write(&tomoyo_domain_list_lock);
654 /***** EXCLUSIVE SECTION END *****/
655 return domain; 815 return domain;
656} 816}
657 817
@@ -739,7 +899,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm,
739 } 899 }
740 900
741 /* Check execute permission. */ 901 /* Check execute permission. */
742 retval = tomoyo_check_exec_perm(old_domain, &r, tmp); 902 retval = tomoyo_check_exec_perm(old_domain, &r);
743 if (retval < 0) 903 if (retval < 0)
744 goto out; 904 goto out;
745 905
diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
index 2316da8ec5bc..5ae3a571559f 100644
--- a/security/tomoyo/file.c
+++ b/security/tomoyo/file.c
@@ -14,21 +14,50 @@
14#include "realpath.h" 14#include "realpath.h"
15#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) 15#define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
16 16
17/* Structure for "allow_read" keyword. */ 17/*
18 * tomoyo_globally_readable_file_entry is a structure which is used for holding
19 * "allow_read" entries.
20 * It has following fields.
21 *
22 * (1) "list" which is linked to tomoyo_globally_readable_list .
23 * (2) "filename" is a pathname which is allowed to open(O_RDONLY).
24 * (3) "is_deleted" is a bool which is true if marked as deleted, false
25 * otherwise.
26 */
18struct tomoyo_globally_readable_file_entry { 27struct tomoyo_globally_readable_file_entry {
19 struct list_head list; 28 struct list_head list;
20 const struct tomoyo_path_info *filename; 29 const struct tomoyo_path_info *filename;
21 bool is_deleted; 30 bool is_deleted;
22}; 31};
23 32
24/* Structure for "file_pattern" keyword. */ 33/*
34 * tomoyo_pattern_entry is a structure which is used for holding
35 * "tomoyo_pattern_list" entries.
36 * It has following fields.
37 *
38 * (1) "list" which is linked to tomoyo_pattern_list .
39 * (2) "pattern" is a pathname pattern which is used for converting pathnames
40 * to pathname patterns during learning mode.
41 * (3) "is_deleted" is a bool which is true if marked as deleted, false
42 * otherwise.
43 */
25struct tomoyo_pattern_entry { 44struct tomoyo_pattern_entry {
26 struct list_head list; 45 struct list_head list;
27 const struct tomoyo_path_info *pattern; 46 const struct tomoyo_path_info *pattern;
28 bool is_deleted; 47 bool is_deleted;
29}; 48};
30 49
31/* Structure for "deny_rewrite" keyword. */ 50/*
51 * tomoyo_no_rewrite_entry is a structure which is used for holding
52 * "deny_rewrite" entries.
53 * It has following fields.
54 *
55 * (1) "list" which is linked to tomoyo_no_rewrite_list .
56 * (2) "pattern" is a pathname which is by default not permitted to modify
57 * already existing content.
58 * (3) "is_deleted" is a bool which is true if marked as deleted, false
59 * otherwise.
60 */
32struct tomoyo_no_rewrite_entry { 61struct tomoyo_no_rewrite_entry {
33 struct list_head list; 62 struct list_head list;
34 const struct tomoyo_path_info *pattern; 63 const struct tomoyo_path_info *pattern;
@@ -141,7 +170,31 @@ static int tomoyo_update_single_path_acl(const u8 type, const char *filename,
141 struct tomoyo_domain_info * 170 struct tomoyo_domain_info *
142 const domain, const bool is_delete); 171 const domain, const bool is_delete);
143 172
144/* The list for "struct tomoyo_globally_readable_file_entry". */ 173/*
174 * tomoyo_globally_readable_list is used for holding list of pathnames which
175 * are by default allowed to be open()ed for reading by any process.
176 *
177 * An entry is added by
178 *
179 * # echo 'allow_read /lib/libc-2.5.so' > \
180 * /sys/kernel/security/tomoyo/exception_policy
181 *
182 * and is deleted by
183 *
184 * # echo 'delete allow_read /lib/libc-2.5.so' > \
185 * /sys/kernel/security/tomoyo/exception_policy
186 *
187 * and all entries are retrieved by
188 *
189 * # grep ^allow_read /sys/kernel/security/tomoyo/exception_policy
190 *
191 * In the example above, any process is allowed to
192 * open("/lib/libc-2.5.so", O_RDONLY).
193 * One exception is, if the domain which current process belongs to is marked
194 * as "ignore_global_allow_read", current process can't do so unless explicitly
195 * given "allow_read /lib/libc-2.5.so" to the domain which current process
196 * belongs to.
197 */
145static LIST_HEAD(tomoyo_globally_readable_list); 198static LIST_HEAD(tomoyo_globally_readable_list);
146static DECLARE_RWSEM(tomoyo_globally_readable_list_lock); 199static DECLARE_RWSEM(tomoyo_globally_readable_list_lock);
147 200
@@ -166,7 +219,6 @@ static int tomoyo_update_globally_readable_entry(const char *filename,
166 saved_filename = tomoyo_save_name(filename); 219 saved_filename = tomoyo_save_name(filename);
167 if (!saved_filename) 220 if (!saved_filename)
168 return -ENOMEM; 221 return -ENOMEM;
169 /***** EXCLUSIVE SECTION START *****/
170 down_write(&tomoyo_globally_readable_list_lock); 222 down_write(&tomoyo_globally_readable_list_lock);
171 list_for_each_entry(ptr, &tomoyo_globally_readable_list, list) { 223 list_for_each_entry(ptr, &tomoyo_globally_readable_list, list) {
172 if (ptr->filename != saved_filename) 224 if (ptr->filename != saved_filename)
@@ -187,7 +239,6 @@ static int tomoyo_update_globally_readable_entry(const char *filename,
187 error = 0; 239 error = 0;
188 out: 240 out:
189 up_write(&tomoyo_globally_readable_list_lock); 241 up_write(&tomoyo_globally_readable_list_lock);
190 /***** EXCLUSIVE SECTION END *****/
191 return error; 242 return error;
192} 243}
193 244
@@ -249,17 +300,44 @@ bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head)
249 list); 300 list);
250 if (ptr->is_deleted) 301 if (ptr->is_deleted)
251 continue; 302 continue;
252 if (!tomoyo_io_printf(head, TOMOYO_KEYWORD_ALLOW_READ "%s\n", 303 done = tomoyo_io_printf(head, TOMOYO_KEYWORD_ALLOW_READ "%s\n",
253 ptr->filename->name)) { 304 ptr->filename->name);
254 done = false; 305 if (!done)
255 break; 306 break;
256 }
257 } 307 }
258 up_read(&tomoyo_globally_readable_list_lock); 308 up_read(&tomoyo_globally_readable_list_lock);
259 return done; 309 return done;
260} 310}
261 311
262/* The list for "struct tomoyo_pattern_entry". */ 312/* tomoyo_pattern_list is used for holding list of pathnames which are used for
313 * converting pathnames to pathname patterns during learning mode.
314 *
315 * An entry is added by
316 *
317 * # echo 'file_pattern /proc/\$/mounts' > \
318 * /sys/kernel/security/tomoyo/exception_policy
319 *
320 * and is deleted by
321 *
322 * # echo 'delete file_pattern /proc/\$/mounts' > \
323 * /sys/kernel/security/tomoyo/exception_policy
324 *
325 * and all entries are retrieved by
326 *
327 * # grep ^file_pattern /sys/kernel/security/tomoyo/exception_policy
328 *
329 * In the example above, if a process which belongs to a domain which is in
330 * learning mode requested open("/proc/1/mounts", O_RDONLY),
331 * "allow_read /proc/\$/mounts" is automatically added to the domain which that
332 * process belongs to.
333 *
334 * It is not a desirable behavior that we have to use /proc/\$/ instead of
335 * /proc/self/ when current process needs to access only current process's
336 * information. As of now, LSM version of TOMOYO is using __d_path() for
337 * calculating pathname. Non LSM version of TOMOYO is using its own function
338 * which pretends as if /proc/self/ is not a symlink; so that we can forbid
339 * current process from accessing other process's information.
340 */
263static LIST_HEAD(tomoyo_pattern_list); 341static LIST_HEAD(tomoyo_pattern_list);
264static DECLARE_RWSEM(tomoyo_pattern_list_lock); 342static DECLARE_RWSEM(tomoyo_pattern_list_lock);
265 343
@@ -284,7 +362,6 @@ static int tomoyo_update_file_pattern_entry(const char *pattern,
284 saved_pattern = tomoyo_save_name(pattern); 362 saved_pattern = tomoyo_save_name(pattern);
285 if (!saved_pattern) 363 if (!saved_pattern)
286 return -ENOMEM; 364 return -ENOMEM;
287 /***** EXCLUSIVE SECTION START *****/
288 down_write(&tomoyo_pattern_list_lock); 365 down_write(&tomoyo_pattern_list_lock);
289 list_for_each_entry(ptr, &tomoyo_pattern_list, list) { 366 list_for_each_entry(ptr, &tomoyo_pattern_list, list) {
290 if (saved_pattern != ptr->pattern) 367 if (saved_pattern != ptr->pattern)
@@ -305,7 +382,6 @@ static int tomoyo_update_file_pattern_entry(const char *pattern,
305 error = 0; 382 error = 0;
306 out: 383 out:
307 up_write(&tomoyo_pattern_list_lock); 384 up_write(&tomoyo_pattern_list_lock);
308 /***** EXCLUSIVE SECTION END *****/
309 return error; 385 return error;
310} 386}
311 387
@@ -373,17 +449,44 @@ bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head)
373 ptr = list_entry(pos, struct tomoyo_pattern_entry, list); 449 ptr = list_entry(pos, struct tomoyo_pattern_entry, list);
374 if (ptr->is_deleted) 450 if (ptr->is_deleted)
375 continue; 451 continue;
376 if (!tomoyo_io_printf(head, TOMOYO_KEYWORD_FILE_PATTERN "%s\n", 452 done = tomoyo_io_printf(head, TOMOYO_KEYWORD_FILE_PATTERN
377 ptr->pattern->name)) { 453 "%s\n", ptr->pattern->name);
378 done = false; 454 if (!done)
379 break; 455 break;
380 }
381 } 456 }
382 up_read(&tomoyo_pattern_list_lock); 457 up_read(&tomoyo_pattern_list_lock);
383 return done; 458 return done;
384} 459}
385 460
386/* The list for "struct tomoyo_no_rewrite_entry". */ 461/*
462 * tomoyo_no_rewrite_list is used for holding list of pathnames which are by
463 * default forbidden to modify already written content of a file.
464 *
465 * An entry is added by
466 *
467 * # echo 'deny_rewrite /var/log/messages' > \
468 * /sys/kernel/security/tomoyo/exception_policy
469 *
470 * and is deleted by
471 *
472 * # echo 'delete deny_rewrite /var/log/messages' > \
473 * /sys/kernel/security/tomoyo/exception_policy
474 *
475 * and all entries are retrieved by
476 *
477 * # grep ^deny_rewrite /sys/kernel/security/tomoyo/exception_policy
478 *
479 * In the example above, if a process requested to rewrite /var/log/messages ,
480 * the process can't rewrite unless the domain which that process belongs to
481 * has "allow_rewrite /var/log/messages" entry.
482 *
483 * It is not a desirable behavior that we have to add "\040(deleted)" suffix
484 * when we want to allow rewriting already unlink()ed file. As of now,
485 * LSM version of TOMOYO is using __d_path() for calculating pathname.
486 * Non LSM version of TOMOYO is using its own function which doesn't append
487 * " (deleted)" suffix if the file is already unlink()ed; so that we don't
488 * need to worry whether the file is already unlink()ed or not.
489 */
387static LIST_HEAD(tomoyo_no_rewrite_list); 490static LIST_HEAD(tomoyo_no_rewrite_list);
388static DECLARE_RWSEM(tomoyo_no_rewrite_list_lock); 491static DECLARE_RWSEM(tomoyo_no_rewrite_list_lock);
389 492
@@ -407,7 +510,6 @@ static int tomoyo_update_no_rewrite_entry(const char *pattern,
407 saved_pattern = tomoyo_save_name(pattern); 510 saved_pattern = tomoyo_save_name(pattern);
408 if (!saved_pattern) 511 if (!saved_pattern)
409 return -ENOMEM; 512 return -ENOMEM;
410 /***** EXCLUSIVE SECTION START *****/
411 down_write(&tomoyo_no_rewrite_list_lock); 513 down_write(&tomoyo_no_rewrite_list_lock);
412 list_for_each_entry(ptr, &tomoyo_no_rewrite_list, list) { 514 list_for_each_entry(ptr, &tomoyo_no_rewrite_list, list) {
413 if (ptr->pattern != saved_pattern) 515 if (ptr->pattern != saved_pattern)
@@ -428,7 +530,6 @@ static int tomoyo_update_no_rewrite_entry(const char *pattern,
428 error = 0; 530 error = 0;
429 out: 531 out:
430 up_write(&tomoyo_no_rewrite_list_lock); 532 up_write(&tomoyo_no_rewrite_list_lock);
431 /***** EXCLUSIVE SECTION END *****/
432 return error; 533 return error;
433} 534}
434 535
@@ -489,11 +590,10 @@ bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head)
489 ptr = list_entry(pos, struct tomoyo_no_rewrite_entry, list); 590 ptr = list_entry(pos, struct tomoyo_no_rewrite_entry, list);
490 if (ptr->is_deleted) 591 if (ptr->is_deleted)
491 continue; 592 continue;
492 if (!tomoyo_io_printf(head, TOMOYO_KEYWORD_DENY_REWRITE "%s\n", 593 done = tomoyo_io_printf(head, TOMOYO_KEYWORD_DENY_REWRITE
493 ptr->pattern->name)) { 594 "%s\n", ptr->pattern->name);
494 done = false; 595 if (!done)
495 break; 596 break;
496 }
497 } 597 }
498 up_read(&tomoyo_no_rewrite_list_lock); 598 up_read(&tomoyo_no_rewrite_list_lock);
499 return done; 599 return done;
@@ -745,7 +845,6 @@ static int tomoyo_update_single_path_acl(const u8 type, const char *filename,
745 saved_filename = tomoyo_save_name(filename); 845 saved_filename = tomoyo_save_name(filename);
746 if (!saved_filename) 846 if (!saved_filename)
747 return -ENOMEM; 847 return -ENOMEM;
748 /***** EXCLUSIVE SECTION START *****/
749 down_write(&tomoyo_domain_acl_info_list_lock); 848 down_write(&tomoyo_domain_acl_info_list_lock);
750 if (is_delete) 849 if (is_delete)
751 goto delete; 850 goto delete;
@@ -800,7 +899,6 @@ static int tomoyo_update_single_path_acl(const u8 type, const char *filename,
800 } 899 }
801 out: 900 out:
802 up_write(&tomoyo_domain_acl_info_list_lock); 901 up_write(&tomoyo_domain_acl_info_list_lock);
803 /***** EXCLUSIVE SECTION END *****/
804 return error; 902 return error;
805} 903}
806 904
@@ -836,7 +934,6 @@ static int tomoyo_update_double_path_acl(const u8 type, const char *filename1,
836 saved_filename2 = tomoyo_save_name(filename2); 934 saved_filename2 = tomoyo_save_name(filename2);
837 if (!saved_filename1 || !saved_filename2) 935 if (!saved_filename1 || !saved_filename2)
838 return -ENOMEM; 936 return -ENOMEM;
839 /***** EXCLUSIVE SECTION START *****/
840 down_write(&tomoyo_domain_acl_info_list_lock); 937 down_write(&tomoyo_domain_acl_info_list_lock);
841 if (is_delete) 938 if (is_delete)
842 goto delete; 939 goto delete;
@@ -884,7 +981,6 @@ static int tomoyo_update_double_path_acl(const u8 type, const char *filename1,
884 } 981 }
885 out: 982 out:
886 up_write(&tomoyo_domain_acl_info_list_lock); 983 up_write(&tomoyo_domain_acl_info_list_lock);
887 /***** EXCLUSIVE SECTION END *****/
888 return error; 984 return error;
889} 985}
890 986
@@ -1025,13 +1121,11 @@ int tomoyo_check_file_perm(struct tomoyo_domain_info *domain,
1025 * 1121 *
1026 * @domain: Pointer to "struct tomoyo_domain_info". 1122 * @domain: Pointer to "struct tomoyo_domain_info".
1027 * @filename: Check permission for "execute". 1123 * @filename: Check permission for "execute".
1028 * @tmp: Buffer for temporary use.
1029 * 1124 *
1030 * Returns 0 on success, negativevalue otherwise. 1125 * Returns 0 on success, negativevalue otherwise.
1031 */ 1126 */
1032int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain, 1127int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain,
1033 const struct tomoyo_path_info *filename, 1128 const struct tomoyo_path_info *filename)
1034 struct tomoyo_page_buffer *tmp)
1035{ 1129{
1036 const u8 mode = tomoyo_check_flags(domain, TOMOYO_MAC_FOR_FILE); 1130 const u8 mode = tomoyo_check_flags(domain, TOMOYO_MAC_FOR_FILE);
1037 1131
diff --git a/security/tomoyo/realpath.c b/security/tomoyo/realpath.c
index 40927a84cb6e..5f2e33263371 100644
--- a/security/tomoyo/realpath.c
+++ b/security/tomoyo/realpath.c
@@ -220,7 +220,6 @@ void *tomoyo_alloc_element(const unsigned int size)
220 = roundup(size, max(sizeof(void *), sizeof(long))); 220 = roundup(size, max(sizeof(void *), sizeof(long)));
221 if (word_aligned_size > PATH_MAX) 221 if (word_aligned_size > PATH_MAX)
222 return NULL; 222 return NULL;
223 /***** EXCLUSIVE SECTION START *****/
224 mutex_lock(&lock); 223 mutex_lock(&lock);
225 if (buf_used_len + word_aligned_size > PATH_MAX) { 224 if (buf_used_len + word_aligned_size > PATH_MAX) {
226 if (!tomoyo_quota_for_elements || 225 if (!tomoyo_quota_for_elements ||
@@ -251,7 +250,6 @@ void *tomoyo_alloc_element(const unsigned int size)
251 } 250 }
252 } 251 }
253 mutex_unlock(&lock); 252 mutex_unlock(&lock);
254 /***** EXCLUSIVE SECTION END *****/
255 return ptr; 253 return ptr;
256} 254}
257 255
@@ -267,7 +265,16 @@ static unsigned int tomoyo_quota_for_savename;
267 */ 265 */
268#define TOMOYO_MAX_HASH 256 266#define TOMOYO_MAX_HASH 256
269 267
270/* Structure for string data. */ 268/*
269 * tomoyo_name_entry is a structure which is used for linking
270 * "struct tomoyo_path_info" into tomoyo_name_list .
271 *
272 * Since tomoyo_name_list manages a list of strings which are shared by
273 * multiple processes (whereas "struct tomoyo_path_info" inside
274 * "struct tomoyo_path_info_with_data" is not shared), a reference counter will
275 * be added to "struct tomoyo_name_entry" rather than "struct tomoyo_path_info"
276 * when TOMOYO starts supporting garbage collector.
277 */
271struct tomoyo_name_entry { 278struct tomoyo_name_entry {
272 struct list_head list; 279 struct list_head list;
273 struct tomoyo_path_info entry; 280 struct tomoyo_path_info entry;
@@ -281,10 +288,10 @@ struct tomoyo_free_memory_block_list {
281}; 288};
282 289
283/* 290/*
284 * The list for "struct tomoyo_name_entry". 291 * tomoyo_name_list is used for holding string data used by TOMOYO.
285 * 292 * Since same string data is likely used for multiple times (e.g.
286 * This list is updated only inside tomoyo_save_name(), thus 293 * "/lib/libc-2.5.so"), TOMOYO shares string data in the form of
287 * no global mutex exists. 294 * "const struct tomoyo_path_info *".
288 */ 295 */
289static struct list_head tomoyo_name_list[TOMOYO_MAX_HASH]; 296static struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
290 297
@@ -318,7 +325,6 @@ const struct tomoyo_path_info *tomoyo_save_name(const char *name)
318 return NULL; 325 return NULL;
319 } 326 }
320 hash = full_name_hash((const unsigned char *) name, len - 1); 327 hash = full_name_hash((const unsigned char *) name, len - 1);
321 /***** EXCLUSIVE SECTION START *****/
322 mutex_lock(&lock); 328 mutex_lock(&lock);
323 list_for_each_entry(ptr, &tomoyo_name_list[hash % TOMOYO_MAX_HASH], 329 list_for_each_entry(ptr, &tomoyo_name_list[hash % TOMOYO_MAX_HASH],
324 list) { 330 list) {
@@ -366,7 +372,6 @@ const struct tomoyo_path_info *tomoyo_save_name(const char *name)
366 } 372 }
367 out: 373 out:
368 mutex_unlock(&lock); 374 mutex_unlock(&lock);
369 /***** EXCLUSIVE SECTION END *****/
370 return ptr ? &ptr->entry : NULL; 375 return ptr ? &ptr->entry : NULL;
371} 376}
372 377
diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
index e42be5c4f055..3194d09fe0f4 100644
--- a/security/tomoyo/tomoyo.c
+++ b/security/tomoyo/tomoyo.c
@@ -262,6 +262,10 @@ static int tomoyo_dentry_open(struct file *f, const struct cred *cred)
262 return tomoyo_check_open_permission(tomoyo_domain(), &f->f_path, flags); 262 return tomoyo_check_open_permission(tomoyo_domain(), &f->f_path, flags);
263} 263}
264 264
265/*
266 * tomoyo_security_ops is a "struct security_operations" which is used for
267 * registering TOMOYO.
268 */
265static struct security_operations tomoyo_security_ops = { 269static struct security_operations tomoyo_security_ops = {
266 .name = "tomoyo", 270 .name = "tomoyo",
267 .cred_prepare = tomoyo_cred_prepare, 271 .cred_prepare = tomoyo_cred_prepare,
diff --git a/security/tomoyo/tomoyo.h b/security/tomoyo/tomoyo.h
index 41c6ebafb9c5..0fd588a629cf 100644
--- a/security/tomoyo/tomoyo.h
+++ b/security/tomoyo/tomoyo.h
@@ -17,13 +17,11 @@ struct path;
17struct inode; 17struct inode;
18struct linux_binprm; 18struct linux_binprm;
19struct pt_regs; 19struct pt_regs;
20struct tomoyo_page_buffer;
21 20
22int tomoyo_check_file_perm(struct tomoyo_domain_info *domain, 21int tomoyo_check_file_perm(struct tomoyo_domain_info *domain,
23 const char *filename, const u8 perm); 22 const char *filename, const u8 perm);
24int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain, 23int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain,
25 const struct tomoyo_path_info *filename, 24 const struct tomoyo_path_info *filename);
26 struct tomoyo_page_buffer *buf);
27int tomoyo_check_open_permission(struct tomoyo_domain_info *domain, 25int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
28 struct path *path, const int flag); 26 struct path *path, const int flag);
29int tomoyo_check_1path_perm(struct tomoyo_domain_info *domain, 27int tomoyo_check_1path_perm(struct tomoyo_domain_info *domain,
@@ -90,17 +88,10 @@ static inline struct tomoyo_domain_info *tomoyo_domain(void)
90 return current_cred()->security; 88 return current_cred()->security;
91} 89}
92 90
93/* Caller holds tasklist_lock spinlock. */
94static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct 91static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
95 *task) 92 *task)
96{ 93{
97 /***** CRITICAL SECTION START *****/ 94 return task_cred_xxx(task, security);
98 const struct cred *cred = get_task_cred(task);
99 struct tomoyo_domain_info *domain = cred->security;
100
101 put_cred(cred);
102 return domain;
103 /***** CRITICAL SECTION END *****/
104} 95}
105 96
106#endif /* !defined(_SECURITY_TOMOYO_TOMOYO_H) */ 97#endif /* !defined(_SECURITY_TOMOYO_TOMOYO_H) */
diff --git a/sound/oss/Kconfig b/sound/oss/Kconfig
index 1ca7427c4b6d..bcf2a0698d54 100644
--- a/sound/oss/Kconfig
+++ b/sound/oss/Kconfig
@@ -561,7 +561,7 @@ endif # SOUND_OSS
561 561
562config SOUND_SH_DAC_AUDIO 562config SOUND_SH_DAC_AUDIO
563 tristate "SuperH DAC audio support" 563 tristate "SuperH DAC audio support"
564 depends on CPU_SH3 564 depends on CPU_SH3 && HIGH_RES_TIMERS
565 565
566config SOUND_SH_DAC_AUDIO_CHANNEL 566config SOUND_SH_DAC_AUDIO_CHANNEL
567 int "DAC channel" 567 int "DAC channel"
diff --git a/sound/oss/sh_dac_audio.c b/sound/oss/sh_dac_audio.c
index 78cfb66e4c59..b2ed8757542a 100644
--- a/sound/oss/sh_dac_audio.c
+++ b/sound/oss/sh_dac_audio.c
@@ -18,47 +18,36 @@
18#include <linux/sound.h> 18#include <linux/sound.h>
19#include <linux/soundcard.h> 19#include <linux/soundcard.h>
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/hrtimer.h>
21#include <asm/io.h> 22#include <asm/io.h>
22#include <asm/uaccess.h> 23#include <asm/uaccess.h>
23#include <asm/irq.h> 24#include <asm/irq.h>
24#include <asm/delay.h> 25#include <asm/delay.h>
25#include <asm/clock.h> 26#include <asm/clock.h>
26#include <asm/cpu/dac.h> 27#include <cpu/dac.h>
27#include <asm/cpu/timer.h>
28#include <asm/machvec.h> 28#include <asm/machvec.h>
29#include <mach/hp6xx.h> 29#include <mach/hp6xx.h>
30#include <asm/hd64461.h> 30#include <asm/hd64461.h>
31 31
32#define MODNAME "sh_dac_audio" 32#define MODNAME "sh_dac_audio"
33 33
34#define TMU_TOCR_INIT 0x00
35
36#define TMU1_TCR_INIT 0x0020 /* Clock/4, rising edge; interrupt on */
37#define TMU1_TSTR_INIT 0x02 /* Bit to turn on TMU1 */
38
39#define BUFFER_SIZE 48000 34#define BUFFER_SIZE 48000
40 35
41static int rate; 36static int rate;
42static int empty; 37static int empty;
43static char *data_buffer, *buffer_begin, *buffer_end; 38static char *data_buffer, *buffer_begin, *buffer_end;
44static int in_use, device_major; 39static int in_use, device_major;
40static struct hrtimer hrtimer;
41static ktime_t wakeups_per_second;
45 42
46static void dac_audio_start_timer(void) 43static void dac_audio_start_timer(void)
47{ 44{
48 u8 tstr; 45 hrtimer_start(&hrtimer, wakeups_per_second, HRTIMER_MODE_REL);
49
50 tstr = ctrl_inb(TMU_TSTR);
51 tstr |= TMU1_TSTR_INIT;
52 ctrl_outb(tstr, TMU_TSTR);
53} 46}
54 47
55static void dac_audio_stop_timer(void) 48static void dac_audio_stop_timer(void)
56{ 49{
57 u8 tstr; 50 hrtimer_cancel(&hrtimer);
58
59 tstr = ctrl_inb(TMU_TSTR);
60 tstr &= ~TMU1_TSTR_INIT;
61 ctrl_outb(tstr, TMU_TSTR);
62} 51}
63 52
64static void dac_audio_reset(void) 53static void dac_audio_reset(void)
@@ -77,38 +66,30 @@ static void dac_audio_sync(void)
77static void dac_audio_start(void) 66static void dac_audio_start(void)
78{ 67{
79 if (mach_is_hp6xx()) { 68 if (mach_is_hp6xx()) {
80 u16 v = inw(HD64461_GPADR); 69 u16 v = __raw_readw(HD64461_GPADR);
81 v &= ~HD64461_GPADR_SPEAKER; 70 v &= ~HD64461_GPADR_SPEAKER;
82 outw(v, HD64461_GPADR); 71 __raw_writew(v, HD64461_GPADR);
83 } 72 }
84 73
85 sh_dac_enable(CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL); 74 sh_dac_enable(CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL);
86 ctrl_outw(TMU1_TCR_INIT, TMU1_TCR);
87} 75}
88static void dac_audio_stop(void) 76static void dac_audio_stop(void)
89{ 77{
90 dac_audio_stop_timer(); 78 dac_audio_stop_timer();
91 79
92 if (mach_is_hp6xx()) { 80 if (mach_is_hp6xx()) {
93 u16 v = inw(HD64461_GPADR); 81 u16 v = __raw_readw(HD64461_GPADR);
94 v |= HD64461_GPADR_SPEAKER; 82 v |= HD64461_GPADR_SPEAKER;
95 outw(v, HD64461_GPADR); 83 __raw_writew(v, HD64461_GPADR);
96 } 84 }
97 85
98 sh_dac_output(0, CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL); 86 sh_dac_output(0, CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL);
99 sh_dac_disable(CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL); 87 sh_dac_disable(CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL);
100} 88}
101 89
102static void dac_audio_set_rate(void) 90static void dac_audio_set_rate(void)
103{ 91{
104 unsigned long interval; 92 wakeups_per_second = ktime_set(0, 1000000000 / rate);
105 struct clk *clk;
106
107 clk = clk_get(NULL, "module_clk");
108 interval = (clk_get_rate(clk) / 4) / rate;
109 clk_put(clk);
110 ctrl_outl(interval, TMU1_TCOR);
111 ctrl_outl(interval, TMU1_TCNT);
112} 93}
113 94
114static int dac_audio_ioctl(struct inode *inode, struct file *file, 95static int dac_audio_ioctl(struct inode *inode, struct file *file,
@@ -265,32 +246,26 @@ const struct file_operations dac_audio_fops = {
265 .release = dac_audio_release, 246 .release = dac_audio_release,
266}; 247};
267 248
268static irqreturn_t timer1_interrupt(int irq, void *dev) 249static enum hrtimer_restart sh_dac_audio_timer(struct hrtimer *handle)
269{ 250{
270 unsigned long timer_status;
271
272 timer_status = ctrl_inw(TMU1_TCR);
273 timer_status &= ~0x100;
274 ctrl_outw(timer_status, TMU1_TCR);
275
276 if (!empty) { 251 if (!empty) {
277 sh_dac_output(*buffer_begin, CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL); 252 sh_dac_output(*buffer_begin, CONFIG_SOUND_SH_DAC_AUDIO_CHANNEL);
278 buffer_begin++; 253 buffer_begin++;
279 254
280 if (buffer_begin == data_buffer + BUFFER_SIZE) 255 if (buffer_begin == data_buffer + BUFFER_SIZE)
281 buffer_begin = data_buffer; 256 buffer_begin = data_buffer;
282 if (buffer_begin == buffer_end) { 257 if (buffer_begin == buffer_end)
283 empty = 1; 258 empty = 1;
284 dac_audio_stop_timer();
285 }
286 } 259 }
287 return IRQ_HANDLED; 260
261 if (!empty)
262 hrtimer_start(&hrtimer, wakeups_per_second, HRTIMER_MODE_REL);
263
264 return HRTIMER_NORESTART;
288} 265}
289 266
290static int __init dac_audio_init(void) 267static int __init dac_audio_init(void)
291{ 268{
292 int retval;
293
294 if ((device_major = register_sound_dsp(&dac_audio_fops, -1)) < 0) { 269 if ((device_major = register_sound_dsp(&dac_audio_fops, -1)) < 0) {
295 printk(KERN_ERR "Cannot register dsp device"); 270 printk(KERN_ERR "Cannot register dsp device");
296 return device_major; 271 return device_major;
@@ -306,21 +281,25 @@ static int __init dac_audio_init(void)
306 rate = 8000; 281 rate = 8000;
307 dac_audio_set_rate(); 282 dac_audio_set_rate();
308 283
309 retval = 284 /* Today: High Resolution Timer driven DAC playback.
310 request_irq(TIMER1_IRQ, timer1_interrupt, IRQF_DISABLED, MODNAME, 0); 285 * The timer callback gets called once per sample. Ouch.
311 if (retval < 0) { 286 *
312 printk(KERN_ERR "sh_dac_audio: IRQ %d request failed\n", 287 * Future: A much better approach would be to use the
313 TIMER1_IRQ); 288 * SH7720 CMT+DMAC+DAC hardware combination like this:
314 return retval; 289 * - Program sample rate using CMT0 or CMT1
315 } 290 * - Program DMAC to use CMT for timing and output to DAC
291 * - Play sound using DMAC, let CPU sleep.
292 * - While at it, rewrite this driver to use ALSA.
293 */
294
295 hrtimer_init(&hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
296 hrtimer.function = sh_dac_audio_timer;
316 297
317 return 0; 298 return 0;
318} 299}
319 300
320static void __exit dac_audio_exit(void) 301static void __exit dac_audio_exit(void)
321{ 302{
322 free_irq(TIMER1_IRQ, 0);
323
324 unregister_sound_dsp(device_major); 303 unregister_sound_dsp(device_major);
325 kfree((void *)data_buffer); 304 kfree((void *)data_buffer);
326} 305}
diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c
index c3b99def9cbc..1eddae94bab3 100644
--- a/virt/kvm/ioapic.c
+++ b/virt/kvm/ioapic.c
@@ -85,7 +85,7 @@ static unsigned long ioapic_read_indirect(struct kvm_ioapic *ioapic,
85 85
86static int ioapic_service(struct kvm_ioapic *ioapic, unsigned int idx) 86static int ioapic_service(struct kvm_ioapic *ioapic, unsigned int idx)
87{ 87{
88 union ioapic_redir_entry *pent; 88 union kvm_ioapic_redirect_entry *pent;
89 int injected = -1; 89 int injected = -1;
90 90
91 pent = &ioapic->redirtbl[idx]; 91 pent = &ioapic->redirtbl[idx];
@@ -142,149 +142,40 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val)
142 } 142 }
143} 143}
144 144
145static int ioapic_inj_irq(struct kvm_ioapic *ioapic,
146 struct kvm_vcpu *vcpu,
147 u8 vector, u8 trig_mode, u8 delivery_mode)
148{
149 ioapic_debug("irq %d trig %d deliv %d\n", vector, trig_mode,
150 delivery_mode);
151
152 ASSERT((delivery_mode == IOAPIC_FIXED) ||
153 (delivery_mode == IOAPIC_LOWEST_PRIORITY));
154
155 return kvm_apic_set_irq(vcpu, vector, trig_mode);
156}
157
158static void ioapic_inj_nmi(struct kvm_vcpu *vcpu)
159{
160 kvm_inject_nmi(vcpu);
161 kvm_vcpu_kick(vcpu);
162}
163
164u32 kvm_ioapic_get_delivery_bitmask(struct kvm_ioapic *ioapic, u8 dest,
165 u8 dest_mode)
166{
167 u32 mask = 0;
168 int i;
169 struct kvm *kvm = ioapic->kvm;
170 struct kvm_vcpu *vcpu;
171
172 ioapic_debug("dest %d dest_mode %d\n", dest, dest_mode);
173
174 if (dest_mode == 0) { /* Physical mode. */
175 if (dest == 0xFF) { /* Broadcast. */
176 for (i = 0; i < KVM_MAX_VCPUS; ++i)
177 if (kvm->vcpus[i] && kvm->vcpus[i]->arch.apic)
178 mask |= 1 << i;
179 return mask;
180 }
181 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
182 vcpu = kvm->vcpus[i];
183 if (!vcpu)
184 continue;
185 if (kvm_apic_match_physical_addr(vcpu->arch.apic, dest)) {
186 if (vcpu->arch.apic)
187 mask = 1 << i;
188 break;
189 }
190 }
191 } else if (dest != 0) /* Logical mode, MDA non-zero. */
192 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
193 vcpu = kvm->vcpus[i];
194 if (!vcpu)
195 continue;
196 if (vcpu->arch.apic &&
197 kvm_apic_match_logical_addr(vcpu->arch.apic, dest))
198 mask |= 1 << vcpu->vcpu_id;
199 }
200 ioapic_debug("mask %x\n", mask);
201 return mask;
202}
203
204static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) 145static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq)
205{ 146{
206 u8 dest = ioapic->redirtbl[irq].fields.dest_id; 147 union kvm_ioapic_redirect_entry *entry = &ioapic->redirtbl[irq];
207 u8 dest_mode = ioapic->redirtbl[irq].fields.dest_mode; 148 struct kvm_lapic_irq irqe;
208 u8 delivery_mode = ioapic->redirtbl[irq].fields.delivery_mode;
209 u8 vector = ioapic->redirtbl[irq].fields.vector;
210 u8 trig_mode = ioapic->redirtbl[irq].fields.trig_mode;
211 u32 deliver_bitmask;
212 struct kvm_vcpu *vcpu;
213 int vcpu_id, r = -1;
214 149
215 ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " 150 ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x "
216 "vector=%x trig_mode=%x\n", 151 "vector=%x trig_mode=%x\n",
217 dest, dest_mode, delivery_mode, vector, trig_mode); 152 entry->fields.dest, entry->fields.dest_mode,
218 153 entry->fields.delivery_mode, entry->fields.vector,
219 deliver_bitmask = kvm_ioapic_get_delivery_bitmask(ioapic, dest, 154 entry->fields.trig_mode);
220 dest_mode); 155
221 if (!deliver_bitmask) { 156 irqe.dest_id = entry->fields.dest_id;
222 ioapic_debug("no target on destination\n"); 157 irqe.vector = entry->fields.vector;
223 return 0; 158 irqe.dest_mode = entry->fields.dest_mode;
224 } 159 irqe.trig_mode = entry->fields.trig_mode;
160 irqe.delivery_mode = entry->fields.delivery_mode << 8;
161 irqe.level = 1;
162 irqe.shorthand = 0;
225 163
226 switch (delivery_mode) {
227 case IOAPIC_LOWEST_PRIORITY:
228 vcpu = kvm_get_lowest_prio_vcpu(ioapic->kvm, vector,
229 deliver_bitmask);
230#ifdef CONFIG_X86 164#ifdef CONFIG_X86
231 if (irq == 0) 165 /* Always delivery PIT interrupt to vcpu 0 */
232 vcpu = ioapic->kvm->vcpus[0]; 166 if (irq == 0) {
233#endif 167 irqe.dest_mode = 0; /* Physical mode. */
234 if (vcpu != NULL) 168 irqe.dest_id = ioapic->kvm->vcpus[0]->vcpu_id;
235 r = ioapic_inj_irq(ioapic, vcpu, vector,
236 trig_mode, delivery_mode);
237 else
238 ioapic_debug("null lowest prio vcpu: "
239 "mask=%x vector=%x delivery_mode=%x\n",
240 deliver_bitmask, vector, IOAPIC_LOWEST_PRIORITY);
241 break;
242 case IOAPIC_FIXED:
243#ifdef CONFIG_X86
244 if (irq == 0)
245 deliver_bitmask = 1;
246#endif
247 for (vcpu_id = 0; deliver_bitmask != 0; vcpu_id++) {
248 if (!(deliver_bitmask & (1 << vcpu_id)))
249 continue;
250 deliver_bitmask &= ~(1 << vcpu_id);
251 vcpu = ioapic->kvm->vcpus[vcpu_id];
252 if (vcpu) {
253 if (r < 0)
254 r = 0;
255 r += ioapic_inj_irq(ioapic, vcpu, vector,
256 trig_mode, delivery_mode);
257 }
258 }
259 break;
260 case IOAPIC_NMI:
261 for (vcpu_id = 0; deliver_bitmask != 0; vcpu_id++) {
262 if (!(deliver_bitmask & (1 << vcpu_id)))
263 continue;
264 deliver_bitmask &= ~(1 << vcpu_id);
265 vcpu = ioapic->kvm->vcpus[vcpu_id];
266 if (vcpu) {
267 ioapic_inj_nmi(vcpu);
268 r = 1;
269 }
270 else
271 ioapic_debug("NMI to vcpu %d failed\n",
272 vcpu->vcpu_id);
273 }
274 break;
275 default:
276 printk(KERN_WARNING "Unsupported delivery mode %d\n",
277 delivery_mode);
278 break;
279 } 169 }
280 return r; 170#endif
171 return kvm_irq_delivery_to_apic(ioapic->kvm, NULL, &irqe);
281} 172}
282 173
283int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level) 174int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level)
284{ 175{
285 u32 old_irr = ioapic->irr; 176 u32 old_irr = ioapic->irr;
286 u32 mask = 1 << irq; 177 u32 mask = 1 << irq;
287 union ioapic_redir_entry entry; 178 union kvm_ioapic_redirect_entry entry;
288 int ret = 1; 179 int ret = 1;
289 180
290 if (irq >= 0 && irq < IOAPIC_NUM_PINS) { 181 if (irq >= 0 && irq < IOAPIC_NUM_PINS) {
@@ -305,7 +196,7 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level)
305static void __kvm_ioapic_update_eoi(struct kvm_ioapic *ioapic, int pin, 196static void __kvm_ioapic_update_eoi(struct kvm_ioapic *ioapic, int pin,
306 int trigger_mode) 197 int trigger_mode)
307{ 198{
308 union ioapic_redir_entry *ent; 199 union kvm_ioapic_redirect_entry *ent;
309 200
310 ent = &ioapic->redirtbl[pin]; 201 ent = &ioapic->redirtbl[pin];
311 202
diff --git a/virt/kvm/ioapic.h b/virt/kvm/ioapic.h
index a34bd5e6436b..7080b713c160 100644
--- a/virt/kvm/ioapic.h
+++ b/virt/kvm/ioapic.h
@@ -40,22 +40,7 @@ struct kvm_ioapic {
40 u32 id; 40 u32 id;
41 u32 irr; 41 u32 irr;
42 u32 pad; 42 u32 pad;
43 union ioapic_redir_entry { 43 union kvm_ioapic_redirect_entry redirtbl[IOAPIC_NUM_PINS];
44 u64 bits;
45 struct {
46 u8 vector;
47 u8 delivery_mode:3;
48 u8 dest_mode:1;
49 u8 delivery_status:1;
50 u8 polarity:1;
51 u8 remote_irr:1;
52 u8 trig_mode:1;
53 u8 mask:1;
54 u8 reserve:7;
55 u8 reserved[4];
56 u8 dest_id;
57 } fields;
58 } redirtbl[IOAPIC_NUM_PINS];
59 struct kvm_io_device dev; 44 struct kvm_io_device dev;
60 struct kvm *kvm; 45 struct kvm *kvm;
61 void (*ack_notifier)(void *opaque, int irq); 46 void (*ack_notifier)(void *opaque, int irq);
@@ -79,13 +64,13 @@ static inline struct kvm_ioapic *ioapic_irqchip(struct kvm *kvm)
79 return kvm->arch.vioapic; 64 return kvm->arch.vioapic;
80} 65}
81 66
82struct kvm_vcpu *kvm_get_lowest_prio_vcpu(struct kvm *kvm, u8 vector, 67int kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source,
83 unsigned long bitmap); 68 int short_hand, int dest, int dest_mode);
69int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2);
84void kvm_ioapic_update_eoi(struct kvm *kvm, int vector, int trigger_mode); 70void kvm_ioapic_update_eoi(struct kvm *kvm, int vector, int trigger_mode);
85int kvm_ioapic_init(struct kvm *kvm); 71int kvm_ioapic_init(struct kvm *kvm);
86int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level); 72int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int level);
87void kvm_ioapic_reset(struct kvm_ioapic *ioapic); 73void kvm_ioapic_reset(struct kvm_ioapic *ioapic);
88u32 kvm_ioapic_get_delivery_bitmask(struct kvm_ioapic *ioapic, u8 dest, 74int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
89 u8 dest_mode); 75 struct kvm_lapic_irq *irq);
90
91#endif 76#endif
diff --git a/virt/kvm/iommu.c b/virt/kvm/iommu.c
index 4c4037503600..15147583abd1 100644
--- a/virt/kvm/iommu.c
+++ b/virt/kvm/iommu.c
@@ -39,11 +39,16 @@ int kvm_iommu_map_pages(struct kvm *kvm,
39 pfn_t pfn; 39 pfn_t pfn;
40 int i, r = 0; 40 int i, r = 0;
41 struct iommu_domain *domain = kvm->arch.iommu_domain; 41 struct iommu_domain *domain = kvm->arch.iommu_domain;
42 int flags;
42 43
43 /* check if iommu exists and in use */ 44 /* check if iommu exists and in use */
44 if (!domain) 45 if (!domain)
45 return 0; 46 return 0;
46 47
48 flags = IOMMU_READ | IOMMU_WRITE;
49 if (kvm->arch.iommu_flags & KVM_IOMMU_CACHE_COHERENCY)
50 flags |= IOMMU_CACHE;
51
47 for (i = 0; i < npages; i++) { 52 for (i = 0; i < npages; i++) {
48 /* check if already mapped */ 53 /* check if already mapped */
49 if (iommu_iova_to_phys(domain, gfn_to_gpa(gfn))) 54 if (iommu_iova_to_phys(domain, gfn_to_gpa(gfn)))
@@ -53,8 +58,7 @@ int kvm_iommu_map_pages(struct kvm *kvm,
53 r = iommu_map_range(domain, 58 r = iommu_map_range(domain,
54 gfn_to_gpa(gfn), 59 gfn_to_gpa(gfn),
55 pfn_to_hpa(pfn), 60 pfn_to_hpa(pfn),
56 PAGE_SIZE, 61 PAGE_SIZE, flags);
57 IOMMU_READ | IOMMU_WRITE);
58 if (r) { 62 if (r) {
59 printk(KERN_ERR "kvm_iommu_map_address:" 63 printk(KERN_ERR "kvm_iommu_map_address:"
60 "iommu failed to map pfn=%lx\n", pfn); 64 "iommu failed to map pfn=%lx\n", pfn);
@@ -88,7 +92,7 @@ int kvm_assign_device(struct kvm *kvm,
88{ 92{
89 struct pci_dev *pdev = NULL; 93 struct pci_dev *pdev = NULL;
90 struct iommu_domain *domain = kvm->arch.iommu_domain; 94 struct iommu_domain *domain = kvm->arch.iommu_domain;
91 int r; 95 int r, last_flags;
92 96
93 /* check if iommu exists and in use */ 97 /* check if iommu exists and in use */
94 if (!domain) 98 if (!domain)
@@ -107,12 +111,29 @@ int kvm_assign_device(struct kvm *kvm,
107 return r; 111 return r;
108 } 112 }
109 113
114 last_flags = kvm->arch.iommu_flags;
115 if (iommu_domain_has_cap(kvm->arch.iommu_domain,
116 IOMMU_CAP_CACHE_COHERENCY))
117 kvm->arch.iommu_flags |= KVM_IOMMU_CACHE_COHERENCY;
118
119 /* Check if need to update IOMMU page table for guest memory */
120 if ((last_flags ^ kvm->arch.iommu_flags) ==
121 KVM_IOMMU_CACHE_COHERENCY) {
122 kvm_iommu_unmap_memslots(kvm);
123 r = kvm_iommu_map_memslots(kvm);
124 if (r)
125 goto out_unmap;
126 }
127
110 printk(KERN_DEBUG "assign device: host bdf = %x:%x:%x\n", 128 printk(KERN_DEBUG "assign device: host bdf = %x:%x:%x\n",
111 assigned_dev->host_busnr, 129 assigned_dev->host_busnr,
112 PCI_SLOT(assigned_dev->host_devfn), 130 PCI_SLOT(assigned_dev->host_devfn),
113 PCI_FUNC(assigned_dev->host_devfn)); 131 PCI_FUNC(assigned_dev->host_devfn));
114 132
115 return 0; 133 return 0;
134out_unmap:
135 kvm_iommu_unmap_memslots(kvm);
136 return r;
116} 137}
117 138
118int kvm_deassign_device(struct kvm *kvm, 139int kvm_deassign_device(struct kvm *kvm,
diff --git a/virt/kvm/irq_comm.c b/virt/kvm/irq_comm.c
index 864ac5483baa..a8bd466d00cc 100644
--- a/virt/kvm/irq_comm.c
+++ b/virt/kvm/irq_comm.c
@@ -22,6 +22,9 @@
22#include <linux/kvm_host.h> 22#include <linux/kvm_host.h>
23 23
24#include <asm/msidef.h> 24#include <asm/msidef.h>
25#ifdef CONFIG_IA64
26#include <asm/iosapic.h>
27#endif
25 28
26#include "irq.h" 29#include "irq.h"
27 30
@@ -43,57 +46,73 @@ static int kvm_set_ioapic_irq(struct kvm_kernel_irq_routing_entry *e,
43 return kvm_ioapic_set_irq(kvm->arch.vioapic, e->irqchip.pin, level); 46 return kvm_ioapic_set_irq(kvm->arch.vioapic, e->irqchip.pin, level);
44} 47}
45 48
46static int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, 49inline static bool kvm_is_dm_lowest_prio(struct kvm_lapic_irq *irq)
47 struct kvm *kvm, int level)
48{ 50{
49 int vcpu_id, r = -1; 51#ifdef CONFIG_IA64
50 struct kvm_vcpu *vcpu; 52 return irq->delivery_mode ==
51 struct kvm_ioapic *ioapic = ioapic_irqchip(kvm); 53 (IOSAPIC_LOWEST_PRIORITY << IOSAPIC_DELIVERY_SHIFT);
52 int dest_id = (e->msi.address_lo & MSI_ADDR_DEST_ID_MASK) 54#else
53 >> MSI_ADDR_DEST_ID_SHIFT; 55 return irq->delivery_mode == APIC_DM_LOWEST;
54 int vector = (e->msi.data & MSI_DATA_VECTOR_MASK) 56#endif
55 >> MSI_DATA_VECTOR_SHIFT; 57}
56 int dest_mode = test_bit(MSI_ADDR_DEST_MODE_SHIFT, 58
57 (unsigned long *)&e->msi.address_lo); 59int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src,
58 int trig_mode = test_bit(MSI_DATA_TRIGGER_SHIFT, 60 struct kvm_lapic_irq *irq)
59 (unsigned long *)&e->msi.data); 61{
60 int delivery_mode = test_bit(MSI_DATA_DELIVERY_MODE_SHIFT, 62 int i, r = -1;
61 (unsigned long *)&e->msi.data); 63 struct kvm_vcpu *vcpu, *lowest = NULL;
62 u32 deliver_bitmask; 64
63 65 if (irq->dest_mode == 0 && irq->dest_id == 0xff &&
64 BUG_ON(!ioapic); 66 kvm_is_dm_lowest_prio(irq))
65 67 printk(KERN_INFO "kvm: apic: phys broadcast and lowest prio\n");
66 deliver_bitmask = kvm_ioapic_get_delivery_bitmask(ioapic, 68
67 dest_id, dest_mode); 69 for (i = 0; i < KVM_MAX_VCPUS; i++) {
68 /* IOAPIC delivery mode value is the same as MSI here */ 70 vcpu = kvm->vcpus[i];
69 switch (delivery_mode) { 71
70 case IOAPIC_LOWEST_PRIORITY: 72 if (!vcpu || !kvm_apic_present(vcpu))
71 vcpu = kvm_get_lowest_prio_vcpu(ioapic->kvm, vector, 73 continue;
72 deliver_bitmask); 74
73 if (vcpu != NULL) 75 if (!kvm_apic_match_dest(vcpu, src, irq->shorthand,
74 r = kvm_apic_set_irq(vcpu, vector, trig_mode); 76 irq->dest_id, irq->dest_mode))
75 else 77 continue;
76 printk(KERN_INFO "kvm: null lowest priority vcpu!\n"); 78
77 break; 79 if (!kvm_is_dm_lowest_prio(irq)) {
78 case IOAPIC_FIXED: 80 if (r < 0)
79 for (vcpu_id = 0; deliver_bitmask != 0; vcpu_id++) { 81 r = 0;
80 if (!(deliver_bitmask & (1 << vcpu_id))) 82 r += kvm_apic_set_irq(vcpu, irq);
81 continue; 83 } else {
82 deliver_bitmask &= ~(1 << vcpu_id); 84 if (!lowest)
83 vcpu = ioapic->kvm->vcpus[vcpu_id]; 85 lowest = vcpu;
84 if (vcpu) { 86 else if (kvm_apic_compare_prio(vcpu, lowest) < 0)
85 if (r < 0) 87 lowest = vcpu;
86 r = 0;
87 r += kvm_apic_set_irq(vcpu, vector, trig_mode);
88 }
89 } 88 }
90 break;
91 default:
92 break;
93 } 89 }
90
91 if (lowest)
92 r = kvm_apic_set_irq(lowest, irq);
93
94 return r; 94 return r;
95} 95}
96 96
97static int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,
98 struct kvm *kvm, int level)
99{
100 struct kvm_lapic_irq irq;
101
102 irq.dest_id = (e->msi.address_lo &
103 MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT;
104 irq.vector = (e->msi.data &
105 MSI_DATA_VECTOR_MASK) >> MSI_DATA_VECTOR_SHIFT;
106 irq.dest_mode = (1 << MSI_ADDR_DEST_MODE_SHIFT) & e->msi.address_lo;
107 irq.trig_mode = (1 << MSI_DATA_TRIGGER_SHIFT) & e->msi.data;
108 irq.delivery_mode = e->msi.data & 0x700;
109 irq.level = 1;
110 irq.shorthand = 0;
111
112 /* TODO Deal with RH bit of MSI message address */
113 return kvm_irq_delivery_to_apic(kvm, NULL, &irq);
114}
115
97/* This should be called with the kvm->lock mutex held 116/* This should be called with the kvm->lock mutex held
98 * Return value: 117 * Return value:
99 * < 0 Interrupt was ignored (masked or not delivered for other reasons) 118 * < 0 Interrupt was ignored (masked or not delivered for other reasons)
@@ -252,7 +271,7 @@ static int setup_routing_entry(struct kvm_kernel_irq_routing_entry *e,
252 delta = 8; 271 delta = 8;
253 break; 272 break;
254 case KVM_IRQCHIP_IOAPIC: 273 case KVM_IRQCHIP_IOAPIC:
255 e->set = kvm_set_ioapic_irq; 274 e->set = kvm_set_ioapic_irq;
256 break; 275 break;
257 default: 276 default:
258 goto out; 277 goto out;
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 4d0dd390aa50..e21194566b71 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -41,6 +41,8 @@
41#include <linux/pagemap.h> 41#include <linux/pagemap.h>
42#include <linux/mman.h> 42#include <linux/mman.h>
43#include <linux/swap.h> 43#include <linux/swap.h>
44#include <linux/bitops.h>
45#include <linux/spinlock.h>
44 46
45#include <asm/processor.h> 47#include <asm/processor.h>
46#include <asm/io.h> 48#include <asm/io.h>
@@ -60,9 +62,6 @@
60MODULE_AUTHOR("Qumranet"); 62MODULE_AUTHOR("Qumranet");
61MODULE_LICENSE("GPL"); 63MODULE_LICENSE("GPL");
62 64
63static int msi2intx = 1;
64module_param(msi2intx, bool, 0);
65
66DEFINE_SPINLOCK(kvm_lock); 65DEFINE_SPINLOCK(kvm_lock);
67LIST_HEAD(vm_list); 66LIST_HEAD(vm_list);
68 67
@@ -95,38 +94,96 @@ static struct kvm_assigned_dev_kernel *kvm_find_assigned_dev(struct list_head *h
95 return NULL; 94 return NULL;
96} 95}
97 96
97static int find_index_from_host_irq(struct kvm_assigned_dev_kernel
98 *assigned_dev, int irq)
99{
100 int i, index;
101 struct msix_entry *host_msix_entries;
102
103 host_msix_entries = assigned_dev->host_msix_entries;
104
105 index = -1;
106 for (i = 0; i < assigned_dev->entries_nr; i++)
107 if (irq == host_msix_entries[i].vector) {
108 index = i;
109 break;
110 }
111 if (index < 0) {
112 printk(KERN_WARNING "Fail to find correlated MSI-X entry!\n");
113 return 0;
114 }
115
116 return index;
117}
118
98static void kvm_assigned_dev_interrupt_work_handler(struct work_struct *work) 119static void kvm_assigned_dev_interrupt_work_handler(struct work_struct *work)
99{ 120{
100 struct kvm_assigned_dev_kernel *assigned_dev; 121 struct kvm_assigned_dev_kernel *assigned_dev;
122 struct kvm *kvm;
123 int irq, i;
101 124
102 assigned_dev = container_of(work, struct kvm_assigned_dev_kernel, 125 assigned_dev = container_of(work, struct kvm_assigned_dev_kernel,
103 interrupt_work); 126 interrupt_work);
127 kvm = assigned_dev->kvm;
104 128
105 /* This is taken to safely inject irq inside the guest. When 129 /* This is taken to safely inject irq inside the guest. When
106 * the interrupt injection (or the ioapic code) uses a 130 * the interrupt injection (or the ioapic code) uses a
107 * finer-grained lock, update this 131 * finer-grained lock, update this
108 */ 132 */
109 mutex_lock(&assigned_dev->kvm->lock); 133 mutex_lock(&kvm->lock);
110 kvm_set_irq(assigned_dev->kvm, assigned_dev->irq_source_id, 134 spin_lock_irq(&assigned_dev->assigned_dev_lock);
111 assigned_dev->guest_irq, 1); 135 if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSIX) {
112 136 struct kvm_guest_msix_entry *guest_entries =
113 if (assigned_dev->irq_requested_type & KVM_ASSIGNED_DEV_GUEST_MSI) { 137 assigned_dev->guest_msix_entries;
114 enable_irq(assigned_dev->host_irq); 138 for (i = 0; i < assigned_dev->entries_nr; i++) {
115 assigned_dev->host_irq_disabled = false; 139 if (!(guest_entries[i].flags &
140 KVM_ASSIGNED_MSIX_PENDING))
141 continue;
142 guest_entries[i].flags &= ~KVM_ASSIGNED_MSIX_PENDING;
143 kvm_set_irq(assigned_dev->kvm,
144 assigned_dev->irq_source_id,
145 guest_entries[i].vector, 1);
146 irq = assigned_dev->host_msix_entries[i].vector;
147 if (irq != 0)
148 enable_irq(irq);
149 assigned_dev->host_irq_disabled = false;
150 }
151 } else {
152 kvm_set_irq(assigned_dev->kvm, assigned_dev->irq_source_id,
153 assigned_dev->guest_irq, 1);
154 if (assigned_dev->irq_requested_type &
155 KVM_DEV_IRQ_GUEST_MSI) {
156 enable_irq(assigned_dev->host_irq);
157 assigned_dev->host_irq_disabled = false;
158 }
116 } 159 }
160
161 spin_unlock_irq(&assigned_dev->assigned_dev_lock);
117 mutex_unlock(&assigned_dev->kvm->lock); 162 mutex_unlock(&assigned_dev->kvm->lock);
118} 163}
119 164
120static irqreturn_t kvm_assigned_dev_intr(int irq, void *dev_id) 165static irqreturn_t kvm_assigned_dev_intr(int irq, void *dev_id)
121{ 166{
167 unsigned long flags;
122 struct kvm_assigned_dev_kernel *assigned_dev = 168 struct kvm_assigned_dev_kernel *assigned_dev =
123 (struct kvm_assigned_dev_kernel *) dev_id; 169 (struct kvm_assigned_dev_kernel *) dev_id;
124 170
171 spin_lock_irqsave(&assigned_dev->assigned_dev_lock, flags);
172 if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSIX) {
173 int index = find_index_from_host_irq(assigned_dev, irq);
174 if (index < 0)
175 goto out;
176 assigned_dev->guest_msix_entries[index].flags |=
177 KVM_ASSIGNED_MSIX_PENDING;
178 }
179
125 schedule_work(&assigned_dev->interrupt_work); 180 schedule_work(&assigned_dev->interrupt_work);
126 181
127 disable_irq_nosync(irq); 182 disable_irq_nosync(irq);
128 assigned_dev->host_irq_disabled = true; 183 assigned_dev->host_irq_disabled = true;
129 184
185out:
186 spin_unlock_irqrestore(&assigned_dev->assigned_dev_lock, flags);
130 return IRQ_HANDLED; 187 return IRQ_HANDLED;
131} 188}
132 189
@@ -134,6 +191,7 @@ static irqreturn_t kvm_assigned_dev_intr(int irq, void *dev_id)
134static void kvm_assigned_dev_ack_irq(struct kvm_irq_ack_notifier *kian) 191static void kvm_assigned_dev_ack_irq(struct kvm_irq_ack_notifier *kian)
135{ 192{
136 struct kvm_assigned_dev_kernel *dev; 193 struct kvm_assigned_dev_kernel *dev;
194 unsigned long flags;
137 195
138 if (kian->gsi == -1) 196 if (kian->gsi == -1)
139 return; 197 return;
@@ -146,28 +204,30 @@ static void kvm_assigned_dev_ack_irq(struct kvm_irq_ack_notifier *kian)
146 /* The guest irq may be shared so this ack may be 204 /* The guest irq may be shared so this ack may be
147 * from another device. 205 * from another device.
148 */ 206 */
207 spin_lock_irqsave(&dev->assigned_dev_lock, flags);
149 if (dev->host_irq_disabled) { 208 if (dev->host_irq_disabled) {
150 enable_irq(dev->host_irq); 209 enable_irq(dev->host_irq);
151 dev->host_irq_disabled = false; 210 dev->host_irq_disabled = false;
152 } 211 }
212 spin_unlock_irqrestore(&dev->assigned_dev_lock, flags);
153} 213}
154 214
155/* The function implicit hold kvm->lock mutex due to cancel_work_sync() */ 215static void deassign_guest_irq(struct kvm *kvm,
156static void kvm_free_assigned_irq(struct kvm *kvm, 216 struct kvm_assigned_dev_kernel *assigned_dev)
157 struct kvm_assigned_dev_kernel *assigned_dev)
158{ 217{
159 if (!irqchip_in_kernel(kvm))
160 return;
161
162 kvm_unregister_irq_ack_notifier(&assigned_dev->ack_notifier); 218 kvm_unregister_irq_ack_notifier(&assigned_dev->ack_notifier);
219 assigned_dev->ack_notifier.gsi = -1;
163 220
164 if (assigned_dev->irq_source_id != -1) 221 if (assigned_dev->irq_source_id != -1)
165 kvm_free_irq_source_id(kvm, assigned_dev->irq_source_id); 222 kvm_free_irq_source_id(kvm, assigned_dev->irq_source_id);
166 assigned_dev->irq_source_id = -1; 223 assigned_dev->irq_source_id = -1;
224 assigned_dev->irq_requested_type &= ~(KVM_DEV_IRQ_GUEST_MASK);
225}
167 226
168 if (!assigned_dev->irq_requested_type) 227/* The function implicit hold kvm->lock mutex due to cancel_work_sync() */
169 return; 228static void deassign_host_irq(struct kvm *kvm,
170 229 struct kvm_assigned_dev_kernel *assigned_dev)
230{
171 /* 231 /*
172 * In kvm_free_device_irq, cancel_work_sync return true if: 232 * In kvm_free_device_irq, cancel_work_sync return true if:
173 * 1. work is scheduled, and then cancelled. 233 * 1. work is scheduled, and then cancelled.
@@ -184,17 +244,64 @@ static void kvm_free_assigned_irq(struct kvm *kvm,
184 * now, the kvm state is still legal for probably we also have to wait 244 * now, the kvm state is still legal for probably we also have to wait
185 * interrupt_work done. 245 * interrupt_work done.
186 */ 246 */
187 disable_irq_nosync(assigned_dev->host_irq); 247 if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSIX) {
188 cancel_work_sync(&assigned_dev->interrupt_work); 248 int i;
249 for (i = 0; i < assigned_dev->entries_nr; i++)
250 disable_irq_nosync(assigned_dev->
251 host_msix_entries[i].vector);
252
253 cancel_work_sync(&assigned_dev->interrupt_work);
254
255 for (i = 0; i < assigned_dev->entries_nr; i++)
256 free_irq(assigned_dev->host_msix_entries[i].vector,
257 (void *)assigned_dev);
258
259 assigned_dev->entries_nr = 0;
260 kfree(assigned_dev->host_msix_entries);
261 kfree(assigned_dev->guest_msix_entries);
262 pci_disable_msix(assigned_dev->dev);
263 } else {
264 /* Deal with MSI and INTx */
265 disable_irq_nosync(assigned_dev->host_irq);
266 cancel_work_sync(&assigned_dev->interrupt_work);
189 267
190 free_irq(assigned_dev->host_irq, (void *)assigned_dev); 268 free_irq(assigned_dev->host_irq, (void *)assigned_dev);
191 269
192 if (assigned_dev->irq_requested_type & KVM_ASSIGNED_DEV_HOST_MSI) 270 if (assigned_dev->irq_requested_type & KVM_DEV_IRQ_HOST_MSI)
193 pci_disable_msi(assigned_dev->dev); 271 pci_disable_msi(assigned_dev->dev);
272 }
194 273
195 assigned_dev->irq_requested_type = 0; 274 assigned_dev->irq_requested_type &= ~(KVM_DEV_IRQ_HOST_MASK);
196} 275}
197 276
277static int kvm_deassign_irq(struct kvm *kvm,
278 struct kvm_assigned_dev_kernel *assigned_dev,
279 unsigned long irq_requested_type)
280{
281 unsigned long guest_irq_type, host_irq_type;
282
283 if (!irqchip_in_kernel(kvm))
284 return -EINVAL;
285 /* no irq assignment to deassign */
286 if (!assigned_dev->irq_requested_type)
287 return -ENXIO;
288
289 host_irq_type = irq_requested_type & KVM_DEV_IRQ_HOST_MASK;
290 guest_irq_type = irq_requested_type & KVM_DEV_IRQ_GUEST_MASK;
291
292 if (host_irq_type)
293 deassign_host_irq(kvm, assigned_dev);
294 if (guest_irq_type)
295 deassign_guest_irq(kvm, assigned_dev);
296
297 return 0;
298}
299
300static void kvm_free_assigned_irq(struct kvm *kvm,
301 struct kvm_assigned_dev_kernel *assigned_dev)
302{
303 kvm_deassign_irq(kvm, assigned_dev, assigned_dev->irq_requested_type);
304}
198 305
199static void kvm_free_assigned_device(struct kvm *kvm, 306static void kvm_free_assigned_device(struct kvm *kvm,
200 struct kvm_assigned_dev_kernel 307 struct kvm_assigned_dev_kernel
@@ -226,190 +333,244 @@ void kvm_free_all_assigned_devices(struct kvm *kvm)
226 } 333 }
227} 334}
228 335
229static int assigned_device_update_intx(struct kvm *kvm, 336static int assigned_device_enable_host_intx(struct kvm *kvm,
230 struct kvm_assigned_dev_kernel *adev, 337 struct kvm_assigned_dev_kernel *dev)
231 struct kvm_assigned_irq *airq)
232{ 338{
233 adev->guest_irq = airq->guest_irq; 339 dev->host_irq = dev->dev->irq;
234 adev->ack_notifier.gsi = airq->guest_irq; 340 /* Even though this is PCI, we don't want to use shared
341 * interrupts. Sharing host devices with guest-assigned devices
342 * on the same interrupt line is not a happy situation: there
343 * are going to be long delays in accepting, acking, etc.
344 */
345 if (request_irq(dev->host_irq, kvm_assigned_dev_intr,
346 0, "kvm_assigned_intx_device", (void *)dev))
347 return -EIO;
348 return 0;
349}
235 350
236 if (adev->irq_requested_type & KVM_ASSIGNED_DEV_HOST_INTX) 351#ifdef __KVM_HAVE_MSI
237 return 0; 352static int assigned_device_enable_host_msi(struct kvm *kvm,
353 struct kvm_assigned_dev_kernel *dev)
354{
355 int r;
238 356
239 if (irqchip_in_kernel(kvm)) { 357 if (!dev->dev->msi_enabled) {
240 if (!msi2intx && 358 r = pci_enable_msi(dev->dev);
241 (adev->irq_requested_type & KVM_ASSIGNED_DEV_HOST_MSI)) { 359 if (r)
242 free_irq(adev->host_irq, (void *)adev); 360 return r;
243 pci_disable_msi(adev->dev); 361 }
244 }
245 362
246 if (!capable(CAP_SYS_RAWIO)) 363 dev->host_irq = dev->dev->irq;
247 return -EPERM; 364 if (request_irq(dev->host_irq, kvm_assigned_dev_intr, 0,
365 "kvm_assigned_msi_device", (void *)dev)) {
366 pci_disable_msi(dev->dev);
367 return -EIO;
368 }
248 369
249 if (airq->host_irq) 370 return 0;
250 adev->host_irq = airq->host_irq; 371}
251 else 372#endif
252 adev->host_irq = adev->dev->irq;
253 373
254 /* Even though this is PCI, we don't want to use shared 374#ifdef __KVM_HAVE_MSIX
255 * interrupts. Sharing host devices with guest-assigned devices 375static int assigned_device_enable_host_msix(struct kvm *kvm,
256 * on the same interrupt line is not a happy situation: there 376 struct kvm_assigned_dev_kernel *dev)
257 * are going to be long delays in accepting, acking, etc. 377{
258 */ 378 int i, r = -EINVAL;
259 if (request_irq(adev->host_irq, kvm_assigned_dev_intr, 379
260 0, "kvm_assigned_intx_device", (void *)adev)) 380 /* host_msix_entries and guest_msix_entries should have been
261 return -EIO; 381 * initialized */
382 if (dev->entries_nr == 0)
383 return r;
384
385 r = pci_enable_msix(dev->dev, dev->host_msix_entries, dev->entries_nr);
386 if (r)
387 return r;
388
389 for (i = 0; i < dev->entries_nr; i++) {
390 r = request_irq(dev->host_msix_entries[i].vector,
391 kvm_assigned_dev_intr, 0,
392 "kvm_assigned_msix_device",
393 (void *)dev);
394 /* FIXME: free requested_irq's on failure */
395 if (r)
396 return r;
262 } 397 }
263 398
264 adev->irq_requested_type = KVM_ASSIGNED_DEV_GUEST_INTX |
265 KVM_ASSIGNED_DEV_HOST_INTX;
266 return 0; 399 return 0;
267} 400}
268 401
269#ifdef CONFIG_X86 402#endif
270static int assigned_device_update_msi(struct kvm *kvm, 403
271 struct kvm_assigned_dev_kernel *adev, 404static int assigned_device_enable_guest_intx(struct kvm *kvm,
272 struct kvm_assigned_irq *airq) 405 struct kvm_assigned_dev_kernel *dev,
406 struct kvm_assigned_irq *irq)
273{ 407{
274 int r; 408 dev->guest_irq = irq->guest_irq;
409 dev->ack_notifier.gsi = irq->guest_irq;
410 return 0;
411}
275 412
276 adev->guest_irq = airq->guest_irq; 413#ifdef __KVM_HAVE_MSI
277 if (airq->flags & KVM_DEV_IRQ_ASSIGN_ENABLE_MSI) { 414static int assigned_device_enable_guest_msi(struct kvm *kvm,
278 /* x86 don't care upper address of guest msi message addr */ 415 struct kvm_assigned_dev_kernel *dev,
279 adev->irq_requested_type |= KVM_ASSIGNED_DEV_GUEST_MSI; 416 struct kvm_assigned_irq *irq)
280 adev->irq_requested_type &= ~KVM_ASSIGNED_DEV_GUEST_INTX; 417{
281 adev->ack_notifier.gsi = -1; 418 dev->guest_irq = irq->guest_irq;
282 } else if (msi2intx) { 419 dev->ack_notifier.gsi = -1;
283 adev->irq_requested_type |= KVM_ASSIGNED_DEV_GUEST_INTX; 420 return 0;
284 adev->irq_requested_type &= ~KVM_ASSIGNED_DEV_GUEST_MSI; 421}
285 adev->ack_notifier.gsi = airq->guest_irq; 422#endif
286 } else { 423#ifdef __KVM_HAVE_MSIX
287 /* 424static int assigned_device_enable_guest_msix(struct kvm *kvm,
288 * Guest require to disable device MSI, we disable MSI and 425 struct kvm_assigned_dev_kernel *dev,
289 * re-enable INTx by default again. Notice it's only for 426 struct kvm_assigned_irq *irq)
290 * non-msi2intx. 427{
291 */ 428 dev->guest_irq = irq->guest_irq;
292 assigned_device_update_intx(kvm, adev, airq); 429 dev->ack_notifier.gsi = -1;
293 return 0; 430 return 0;
431}
432#endif
433
434static int assign_host_irq(struct kvm *kvm,
435 struct kvm_assigned_dev_kernel *dev,
436 __u32 host_irq_type)
437{
438 int r = -EEXIST;
439
440 if (dev->irq_requested_type & KVM_DEV_IRQ_HOST_MASK)
441 return r;
442
443 switch (host_irq_type) {
444 case KVM_DEV_IRQ_HOST_INTX:
445 r = assigned_device_enable_host_intx(kvm, dev);
446 break;
447#ifdef __KVM_HAVE_MSI
448 case KVM_DEV_IRQ_HOST_MSI:
449 r = assigned_device_enable_host_msi(kvm, dev);
450 break;
451#endif
452#ifdef __KVM_HAVE_MSIX
453 case KVM_DEV_IRQ_HOST_MSIX:
454 r = assigned_device_enable_host_msix(kvm, dev);
455 break;
456#endif
457 default:
458 r = -EINVAL;
294 } 459 }
295 460
296 if (adev->irq_requested_type & KVM_ASSIGNED_DEV_HOST_MSI) 461 if (!r)
297 return 0; 462 dev->irq_requested_type |= host_irq_type;
298 463
299 if (irqchip_in_kernel(kvm)) { 464 return r;
300 if (!msi2intx) { 465}
301 if (adev->irq_requested_type &
302 KVM_ASSIGNED_DEV_HOST_INTX)
303 free_irq(adev->host_irq, (void *)adev);
304 466
305 r = pci_enable_msi(adev->dev); 467static int assign_guest_irq(struct kvm *kvm,
306 if (r) 468 struct kvm_assigned_dev_kernel *dev,
307 return r; 469 struct kvm_assigned_irq *irq,
308 } 470 unsigned long guest_irq_type)
471{
472 int id;
473 int r = -EEXIST;
474
475 if (dev->irq_requested_type & KVM_DEV_IRQ_GUEST_MASK)
476 return r;
309 477
310 adev->host_irq = adev->dev->irq; 478 id = kvm_request_irq_source_id(kvm);
311 if (request_irq(adev->host_irq, kvm_assigned_dev_intr, 0, 479 if (id < 0)
312 "kvm_assigned_msi_device", (void *)adev)) 480 return id;
313 return -EIO; 481
482 dev->irq_source_id = id;
483
484 switch (guest_irq_type) {
485 case KVM_DEV_IRQ_GUEST_INTX:
486 r = assigned_device_enable_guest_intx(kvm, dev, irq);
487 break;
488#ifdef __KVM_HAVE_MSI
489 case KVM_DEV_IRQ_GUEST_MSI:
490 r = assigned_device_enable_guest_msi(kvm, dev, irq);
491 break;
492#endif
493#ifdef __KVM_HAVE_MSIX
494 case KVM_DEV_IRQ_GUEST_MSIX:
495 r = assigned_device_enable_guest_msix(kvm, dev, irq);
496 break;
497#endif
498 default:
499 r = -EINVAL;
314 } 500 }
315 501
316 if (!msi2intx) 502 if (!r) {
317 adev->irq_requested_type = KVM_ASSIGNED_DEV_GUEST_MSI; 503 dev->irq_requested_type |= guest_irq_type;
504 kvm_register_irq_ack_notifier(kvm, &dev->ack_notifier);
505 } else
506 kvm_free_irq_source_id(kvm, dev->irq_source_id);
318 507
319 adev->irq_requested_type |= KVM_ASSIGNED_DEV_HOST_MSI; 508 return r;
320 return 0;
321} 509}
322#endif
323 510
511/* TODO Deal with KVM_DEV_IRQ_ASSIGNED_MASK_MSIX */
324static int kvm_vm_ioctl_assign_irq(struct kvm *kvm, 512static int kvm_vm_ioctl_assign_irq(struct kvm *kvm,
325 struct kvm_assigned_irq 513 struct kvm_assigned_irq *assigned_irq)
326 *assigned_irq)
327{ 514{
328 int r = 0; 515 int r = -EINVAL;
329 struct kvm_assigned_dev_kernel *match; 516 struct kvm_assigned_dev_kernel *match;
330 u32 current_flags = 0, changed_flags; 517 unsigned long host_irq_type, guest_irq_type;
331 518
332 mutex_lock(&kvm->lock); 519 if (!capable(CAP_SYS_RAWIO))
520 return -EPERM;
333 521
522 if (!irqchip_in_kernel(kvm))
523 return r;
524
525 mutex_lock(&kvm->lock);
526 r = -ENODEV;
334 match = kvm_find_assigned_dev(&kvm->arch.assigned_dev_head, 527 match = kvm_find_assigned_dev(&kvm->arch.assigned_dev_head,
335 assigned_irq->assigned_dev_id); 528 assigned_irq->assigned_dev_id);
336 if (!match) { 529 if (!match)
337 mutex_unlock(&kvm->lock); 530 goto out;
338 return -EINVAL;
339 }
340
341 if (!match->irq_requested_type) {
342 INIT_WORK(&match->interrupt_work,
343 kvm_assigned_dev_interrupt_work_handler);
344 if (irqchip_in_kernel(kvm)) {
345 /* Register ack nofitier */
346 match->ack_notifier.gsi = -1;
347 match->ack_notifier.irq_acked =
348 kvm_assigned_dev_ack_irq;
349 kvm_register_irq_ack_notifier(kvm,
350 &match->ack_notifier);
351
352 /* Request IRQ source ID */
353 r = kvm_request_irq_source_id(kvm);
354 if (r < 0)
355 goto out_release;
356 else
357 match->irq_source_id = r;
358
359#ifdef CONFIG_X86
360 /* Determine host device irq type, we can know the
361 * result from dev->msi_enabled */
362 if (msi2intx)
363 pci_enable_msi(match->dev);
364#endif
365 }
366 }
367 531
368 if ((match->irq_requested_type & KVM_ASSIGNED_DEV_HOST_MSI) && 532 host_irq_type = (assigned_irq->flags & KVM_DEV_IRQ_HOST_MASK);
369 (match->irq_requested_type & KVM_ASSIGNED_DEV_GUEST_MSI)) 533 guest_irq_type = (assigned_irq->flags & KVM_DEV_IRQ_GUEST_MASK);
370 current_flags |= KVM_DEV_IRQ_ASSIGN_ENABLE_MSI;
371 534
372 changed_flags = assigned_irq->flags ^ current_flags; 535 r = -EINVAL;
536 /* can only assign one type at a time */
537 if (hweight_long(host_irq_type) > 1)
538 goto out;
539 if (hweight_long(guest_irq_type) > 1)
540 goto out;
541 if (host_irq_type == 0 && guest_irq_type == 0)
542 goto out;
373 543
374 if ((changed_flags & KVM_DEV_IRQ_ASSIGN_MSI_ACTION) || 544 r = 0;
375 (msi2intx && match->dev->msi_enabled)) { 545 if (host_irq_type)
376#ifdef CONFIG_X86 546 r = assign_host_irq(kvm, match, host_irq_type);
377 r = assigned_device_update_msi(kvm, match, assigned_irq); 547 if (r)
378 if (r) { 548 goto out;
379 printk(KERN_WARNING "kvm: failed to enable "
380 "MSI device!\n");
381 goto out_release;
382 }
383#else
384 r = -ENOTTY;
385#endif
386 } else if (assigned_irq->host_irq == 0 && match->dev->irq == 0) {
387 /* Host device IRQ 0 means don't support INTx */
388 if (!msi2intx) {
389 printk(KERN_WARNING
390 "kvm: wait device to enable MSI!\n");
391 r = 0;
392 } else {
393 printk(KERN_WARNING
394 "kvm: failed to enable MSI device!\n");
395 r = -ENOTTY;
396 goto out_release;
397 }
398 } else {
399 /* Non-sharing INTx mode */
400 r = assigned_device_update_intx(kvm, match, assigned_irq);
401 if (r) {
402 printk(KERN_WARNING "kvm: failed to enable "
403 "INTx device!\n");
404 goto out_release;
405 }
406 }
407 549
550 if (guest_irq_type)
551 r = assign_guest_irq(kvm, match, assigned_irq, guest_irq_type);
552out:
408 mutex_unlock(&kvm->lock); 553 mutex_unlock(&kvm->lock);
409 return r; 554 return r;
410out_release: 555}
556
557static int kvm_vm_ioctl_deassign_dev_irq(struct kvm *kvm,
558 struct kvm_assigned_irq
559 *assigned_irq)
560{
561 int r = -ENODEV;
562 struct kvm_assigned_dev_kernel *match;
563
564 mutex_lock(&kvm->lock);
565
566 match = kvm_find_assigned_dev(&kvm->arch.assigned_dev_head,
567 assigned_irq->assigned_dev_id);
568 if (!match)
569 goto out;
570
571 r = kvm_deassign_irq(kvm, match, assigned_irq->flags);
572out:
411 mutex_unlock(&kvm->lock); 573 mutex_unlock(&kvm->lock);
412 kvm_free_assigned_device(kvm, match);
413 return r; 574 return r;
414} 575}
415 576
@@ -427,7 +588,7 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
427 assigned_dev->assigned_dev_id); 588 assigned_dev->assigned_dev_id);
428 if (match) { 589 if (match) {
429 /* device already assigned */ 590 /* device already assigned */
430 r = -EINVAL; 591 r = -EEXIST;
431 goto out; 592 goto out;
432 } 593 }
433 594
@@ -464,8 +625,12 @@ static int kvm_vm_ioctl_assign_device(struct kvm *kvm,
464 match->host_devfn = assigned_dev->devfn; 625 match->host_devfn = assigned_dev->devfn;
465 match->flags = assigned_dev->flags; 626 match->flags = assigned_dev->flags;
466 match->dev = dev; 627 match->dev = dev;
628 spin_lock_init(&match->assigned_dev_lock);
467 match->irq_source_id = -1; 629 match->irq_source_id = -1;
468 match->kvm = kvm; 630 match->kvm = kvm;
631 match->ack_notifier.irq_acked = kvm_assigned_dev_ack_irq;
632 INIT_WORK(&match->interrupt_work,
633 kvm_assigned_dev_interrupt_work_handler);
469 634
470 list_add(&match->list, &kvm->arch.assigned_dev_head); 635 list_add(&match->list, &kvm->arch.assigned_dev_head);
471 636
@@ -878,6 +1043,8 @@ static void kvm_destroy_vm(struct kvm *kvm)
878#endif 1043#endif
879#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER) 1044#if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
880 mmu_notifier_unregister(&kvm->mmu_notifier, kvm->mm); 1045 mmu_notifier_unregister(&kvm->mmu_notifier, kvm->mm);
1046#else
1047 kvm_arch_flush_shadow(kvm);
881#endif 1048#endif
882 kvm_arch_destroy_vm(kvm); 1049 kvm_arch_destroy_vm(kvm);
883 mmdrop(mm); 1050 mmdrop(mm);
@@ -919,9 +1086,8 @@ int __kvm_set_memory_region(struct kvm *kvm,
919{ 1086{
920 int r; 1087 int r;
921 gfn_t base_gfn; 1088 gfn_t base_gfn;
922 unsigned long npages; 1089 unsigned long npages, ugfn;
923 int largepages; 1090 unsigned long largepages, i;
924 unsigned long i;
925 struct kvm_memory_slot *memslot; 1091 struct kvm_memory_slot *memslot;
926 struct kvm_memory_slot old, new; 1092 struct kvm_memory_slot old, new;
927 1093
@@ -1010,6 +1176,14 @@ int __kvm_set_memory_region(struct kvm *kvm,
1010 new.lpage_info[0].write_count = 1; 1176 new.lpage_info[0].write_count = 1;
1011 if ((base_gfn+npages) % KVM_PAGES_PER_HPAGE) 1177 if ((base_gfn+npages) % KVM_PAGES_PER_HPAGE)
1012 new.lpage_info[largepages-1].write_count = 1; 1178 new.lpage_info[largepages-1].write_count = 1;
1179 ugfn = new.userspace_addr >> PAGE_SHIFT;
1180 /*
1181 * If the gfn and userspace address are not aligned wrt each
1182 * other, disable large page support for this slot
1183 */
1184 if ((base_gfn ^ ugfn) & (KVM_PAGES_PER_HPAGE - 1))
1185 for (i = 0; i < largepages; ++i)
1186 new.lpage_info[i].write_count = 1;
1013 } 1187 }
1014 1188
1015 /* Allocate page dirty bitmap if needed */ 1189 /* Allocate page dirty bitmap if needed */
@@ -1043,8 +1217,10 @@ int __kvm_set_memory_region(struct kvm *kvm,
1043 1217
1044 kvm_free_physmem_slot(&old, npages ? &new : NULL); 1218 kvm_free_physmem_slot(&old, npages ? &new : NULL);
1045 /* Slot deletion case: we have to update the current slot */ 1219 /* Slot deletion case: we have to update the current slot */
1220 spin_lock(&kvm->mmu_lock);
1046 if (!npages) 1221 if (!npages)
1047 *memslot = old; 1222 *memslot = old;
1223 spin_unlock(&kvm->mmu_lock);
1048#ifdef CONFIG_DMAR 1224#ifdef CONFIG_DMAR
1049 /* map the pages in iommu page table */ 1225 /* map the pages in iommu page table */
1050 r = kvm_iommu_map_pages(kvm, base_gfn, npages); 1226 r = kvm_iommu_map_pages(kvm, base_gfn, npages);
@@ -1454,12 +1630,14 @@ void kvm_vcpu_block(struct kvm_vcpu *vcpu)
1454 for (;;) { 1630 for (;;) {
1455 prepare_to_wait(&vcpu->wq, &wait, TASK_INTERRUPTIBLE); 1631 prepare_to_wait(&vcpu->wq, &wait, TASK_INTERRUPTIBLE);
1456 1632
1457 if (kvm_cpu_has_interrupt(vcpu) || 1633 if ((kvm_arch_interrupt_allowed(vcpu) &&
1458 kvm_cpu_has_pending_timer(vcpu) || 1634 kvm_cpu_has_interrupt(vcpu)) ||
1459 kvm_arch_vcpu_runnable(vcpu)) { 1635 kvm_arch_vcpu_runnable(vcpu)) {
1460 set_bit(KVM_REQ_UNHALT, &vcpu->requests); 1636 set_bit(KVM_REQ_UNHALT, &vcpu->requests);
1461 break; 1637 break;
1462 } 1638 }
1639 if (kvm_cpu_has_pending_timer(vcpu))
1640 break;
1463 if (signal_pending(current)) 1641 if (signal_pending(current))
1464 break; 1642 break;
1465 1643
@@ -1593,6 +1771,88 @@ static int kvm_vcpu_ioctl_set_sigmask(struct kvm_vcpu *vcpu, sigset_t *sigset)
1593 return 0; 1771 return 0;
1594} 1772}
1595 1773
1774#ifdef __KVM_HAVE_MSIX
1775static int kvm_vm_ioctl_set_msix_nr(struct kvm *kvm,
1776 struct kvm_assigned_msix_nr *entry_nr)
1777{
1778 int r = 0;
1779 struct kvm_assigned_dev_kernel *adev;
1780
1781 mutex_lock(&kvm->lock);
1782
1783 adev = kvm_find_assigned_dev(&kvm->arch.assigned_dev_head,
1784 entry_nr->assigned_dev_id);
1785 if (!adev) {
1786 r = -EINVAL;
1787 goto msix_nr_out;
1788 }
1789
1790 if (adev->entries_nr == 0) {
1791 adev->entries_nr = entry_nr->entry_nr;
1792 if (adev->entries_nr == 0 ||
1793 adev->entries_nr >= KVM_MAX_MSIX_PER_DEV) {
1794 r = -EINVAL;
1795 goto msix_nr_out;
1796 }
1797
1798 adev->host_msix_entries = kzalloc(sizeof(struct msix_entry) *
1799 entry_nr->entry_nr,
1800 GFP_KERNEL);
1801 if (!adev->host_msix_entries) {
1802 r = -ENOMEM;
1803 goto msix_nr_out;
1804 }
1805 adev->guest_msix_entries = kzalloc(
1806 sizeof(struct kvm_guest_msix_entry) *
1807 entry_nr->entry_nr, GFP_KERNEL);
1808 if (!adev->guest_msix_entries) {
1809 kfree(adev->host_msix_entries);
1810 r = -ENOMEM;
1811 goto msix_nr_out;
1812 }
1813 } else /* Not allowed set MSI-X number twice */
1814 r = -EINVAL;
1815msix_nr_out:
1816 mutex_unlock(&kvm->lock);
1817 return r;
1818}
1819
1820static int kvm_vm_ioctl_set_msix_entry(struct kvm *kvm,
1821 struct kvm_assigned_msix_entry *entry)
1822{
1823 int r = 0, i;
1824 struct kvm_assigned_dev_kernel *adev;
1825
1826 mutex_lock(&kvm->lock);
1827
1828 adev = kvm_find_assigned_dev(&kvm->arch.assigned_dev_head,
1829 entry->assigned_dev_id);
1830
1831 if (!adev) {
1832 r = -EINVAL;
1833 goto msix_entry_out;
1834 }
1835
1836 for (i = 0; i < adev->entries_nr; i++)
1837 if (adev->guest_msix_entries[i].vector == 0 ||
1838 adev->guest_msix_entries[i].entry == entry->entry) {
1839 adev->guest_msix_entries[i].entry = entry->entry;
1840 adev->guest_msix_entries[i].vector = entry->gsi;
1841 adev->host_msix_entries[i].entry = entry->entry;
1842 break;
1843 }
1844 if (i == adev->entries_nr) {
1845 r = -ENOSPC;
1846 goto msix_entry_out;
1847 }
1848
1849msix_entry_out:
1850 mutex_unlock(&kvm->lock);
1851
1852 return r;
1853}
1854#endif
1855
1596static long kvm_vcpu_ioctl(struct file *filp, 1856static long kvm_vcpu_ioctl(struct file *filp,
1597 unsigned int ioctl, unsigned long arg) 1857 unsigned int ioctl, unsigned long arg)
1598{ 1858{
@@ -1864,6 +2124,11 @@ static long kvm_vm_ioctl(struct file *filp,
1864 break; 2124 break;
1865 } 2125 }
1866 case KVM_ASSIGN_IRQ: { 2126 case KVM_ASSIGN_IRQ: {
2127 r = -EOPNOTSUPP;
2128 break;
2129 }
2130#ifdef KVM_CAP_ASSIGN_DEV_IRQ
2131 case KVM_ASSIGN_DEV_IRQ: {
1867 struct kvm_assigned_irq assigned_irq; 2132 struct kvm_assigned_irq assigned_irq;
1868 2133
1869 r = -EFAULT; 2134 r = -EFAULT;
@@ -1874,6 +2139,18 @@ static long kvm_vm_ioctl(struct file *filp,
1874 goto out; 2139 goto out;
1875 break; 2140 break;
1876 } 2141 }
2142 case KVM_DEASSIGN_DEV_IRQ: {
2143 struct kvm_assigned_irq assigned_irq;
2144
2145 r = -EFAULT;
2146 if (copy_from_user(&assigned_irq, argp, sizeof assigned_irq))
2147 goto out;
2148 r = kvm_vm_ioctl_deassign_dev_irq(kvm, &assigned_irq);
2149 if (r)
2150 goto out;
2151 break;
2152 }
2153#endif
1877#endif 2154#endif
1878#ifdef KVM_CAP_DEVICE_DEASSIGNMENT 2155#ifdef KVM_CAP_DEVICE_DEASSIGNMENT
1879 case KVM_DEASSIGN_PCI_DEVICE: { 2156 case KVM_DEASSIGN_PCI_DEVICE: {
@@ -1917,7 +2194,29 @@ static long kvm_vm_ioctl(struct file *filp,
1917 vfree(entries); 2194 vfree(entries);
1918 break; 2195 break;
1919 } 2196 }
2197#ifdef __KVM_HAVE_MSIX
2198 case KVM_ASSIGN_SET_MSIX_NR: {
2199 struct kvm_assigned_msix_nr entry_nr;
2200 r = -EFAULT;
2201 if (copy_from_user(&entry_nr, argp, sizeof entry_nr))
2202 goto out;
2203 r = kvm_vm_ioctl_set_msix_nr(kvm, &entry_nr);
2204 if (r)
2205 goto out;
2206 break;
2207 }
2208 case KVM_ASSIGN_SET_MSIX_ENTRY: {
2209 struct kvm_assigned_msix_entry entry;
2210 r = -EFAULT;
2211 if (copy_from_user(&entry, argp, sizeof entry))
2212 goto out;
2213 r = kvm_vm_ioctl_set_msix_entry(kvm, &entry);
2214 if (r)
2215 goto out;
2216 break;
2217 }
1920#endif 2218#endif
2219#endif /* KVM_CAP_IRQ_ROUTING */
1921 default: 2220 default:
1922 r = kvm_arch_vm_ioctl(filp, ioctl, arg); 2221 r = kvm_arch_vm_ioctl(filp, ioctl, arg);
1923 } 2222 }
@@ -2112,15 +2411,15 @@ EXPORT_SYMBOL_GPL(kvm_handle_fault_on_reboot);
2112static int kvm_reboot(struct notifier_block *notifier, unsigned long val, 2411static int kvm_reboot(struct notifier_block *notifier, unsigned long val,
2113 void *v) 2412 void *v)
2114{ 2413{
2115 if (val == SYS_RESTART) { 2414 /*
2116 /* 2415 * Some (well, at least mine) BIOSes hang on reboot if
2117 * Some (well, at least mine) BIOSes hang on reboot if 2416 * in vmx root mode.
2118 * in vmx root mode. 2417 *
2119 */ 2418 * And Intel TXT required VMX off for all cpu when system shutdown.
2120 printk(KERN_INFO "kvm: exiting hardware virtualization\n"); 2419 */
2121 kvm_rebooting = true; 2420 printk(KERN_INFO "kvm: exiting hardware virtualization\n");
2122 on_each_cpu(hardware_disable, NULL, 1); 2421 kvm_rebooting = true;
2123 } 2422 on_each_cpu(hardware_disable, NULL, 1);
2124 return NOTIFY_OK; 2423 return NOTIFY_OK;
2125} 2424}
2126 2425
@@ -2354,9 +2653,6 @@ int kvm_init(void *opaque, unsigned int vcpu_size,
2354 2653
2355 kvm_preempt_ops.sched_in = kvm_sched_in; 2654 kvm_preempt_ops.sched_in = kvm_sched_in;
2356 kvm_preempt_ops.sched_out = kvm_sched_out; 2655 kvm_preempt_ops.sched_out = kvm_sched_out;
2357#ifndef CONFIG_X86
2358 msi2intx = 0;
2359#endif
2360 2656
2361 return 0; 2657 return 0;
2362 2658